@tscircuit/runframe 0.0.1765 → 0.0.1767

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5149,7 +5149,7 @@ ${a.join(`
5149
5149
  ${Q}polygon: ${C.polygon.vertices}
5150
5150
  `:a+=`
5151
5151
  `,C.children.length>0&&c.push(C.children)}return a}};A.exports=s}}),fSe=at({"node_modules/@jscad/modeling/src/operations/booleans/trees/Tree.js"(e,A){var t=ESe(),i=pSe(),n=class{constructor(o){this.polygonTree=new i,this.rootnode=new t(null),o&&this.addPolygons(o)}invert(){this.polygonTree.invert(),this.rootnode.invert()}clipTo(o,s=!1){this.rootnode.clipTo(o,s)}allPolygons(){const o=[];return this.polygonTree.getPolygons(o),o}addPolygons(o){const s=new Array(o.length);for(let r=0;r<o.length;r++)s[r]=this.polygonTree.addChild(o[r]);this.rootnode.addPolygonTreeNodes(s)}clear(){this.polygonTree.clear()}toString(){return"Tree: "+this.polygonTree.toString("")}};A.exports=n}}),ZEA=at({"node_modules/@jscad/modeling/src/operations/booleans/trees/index.js"(e,A){A.exports={Tree:fSe()}}}),ySe=at({"node_modules/@jscad/modeling/src/operations/booleans/intersectGeom3Sub.js"(e,A){var t=ts(),i=WEA(),{Tree:n}=ZEA(),o=(s,r)=>{if(!i(s,r))return t.create();const a=new n(t.toPolygons(s)),g=new n(t.toPolygons(r));a.invert(),g.clipTo(a),g.invert(),a.clipTo(g),g.clipTo(a),a.addPolygons(g.allPolygons()),a.invert();const c=a.allPolygons();return t.create(c)};A.exports=o}}),Ytt=at({"node_modules/@jscad/modeling/src/operations/booleans/intersectGeom3.js"(e,A){var t=vo(),i=Y8(),n=ySe(),o=(...s)=>{s=t(s);let r=s.shift();return s.forEach(a=>{r=n(r,a)}),r=i(r),r};A.exports=o}}),mSe=at({"node_modules/@jscad/modeling/src/operations/booleans/intersectGeom2.js"(e,A){var t=vo(),i=ts(),n=sb(),o=qEA(),s=OEA(),r=Ytt(),a=(...g)=>{g=t(g);const c=g.map(B=>s({z0:-1,z1:1},B)),I=r(c),l=n(I);return o(l,i.toPolygons(I))};A.exports=a}}),wSe=at({"node_modules/@jscad/modeling/src/operations/booleans/intersect.js"(e,A){var t=vo(),i=H8(),n=ss(),o=ts(),s=mSe(),r=Ytt(),a=(...g)=>{if(g=t(g),g.length===0)throw new Error("wrong number of arguments");if(!i(g))throw new Error("only intersect of the types are supported");const c=g[0];return n.isA(c)?s(g):o.isA(c)?r(g):c};A.exports=a}}),VEA=at({"node_modules/@jscad/modeling/src/operations/hulls/hullPoints3.js"(e,A){var t=tr(),i=qAt(),n=o=>i(o,{skipTriangulation:!0}).map(a=>{const g=a.map(c=>o[c]);return t.create(g)});A.exports=n}}),Jtt=at({"node_modules/@jscad/modeling/src/operations/booleans/unionGeom3Sub.js"(e,A){var t=ts(),i=WEA(),{Tree:n}=ZEA(),o=(r,a)=>{if(!i(r,a))return s(r,a);const g=new n(t.toPolygons(r)),c=new n(t.toPolygons(a));g.clipTo(c,!1),c.clipTo(g),c.invert(),c.clipTo(g),c.invert();const I=g.allPolygons().concat(c.allPolygons());return t.create(I)},s=(r,a)=>{let g=t.toPolygons(r);return g=g.concat(t.toPolygons(a)),t.create(g)};A.exports=o}}),jEA=at({"node_modules/@jscad/modeling/src/operations/booleans/unionGeom3.js"(e,A){var t=vo(),i=Y8(),n=Jtt(),o=(...s)=>{s=t(s);let r;for(r=1;r<s.length;r+=2)s.push(n(s[r-1],s[r]));let a=s[r-1];return a=i(a),a};A.exports=o}}),Ttt=at({"node_modules/@jscad/modeling/src/operations/minkowski/minkowskiSum.js"(e,A){var t=vo(),i=ts(),n=tr(),o=VEA(),s=jEA(),r=(...B)=>{if(B=t(B),B.length!==2)throw new Error("minkowskiSum requires exactly two geometries");const[C,Q]=B;if(!i.isA(C)||!i.isA(Q))throw new Error("minkowskiSum requires geom3 geometries");const h=i.isConvex(C),E=i.isConvex(Q);if(h&&E)return I(C,Q);if(!h&&E)return a(C,Q);if(h&&!E)return a(Q,C);throw new Error("minkowskiSum of two non-convex geometries is not yet supported")},a=(B,C)=>{const Q=g(B);if(Q.length===0)return i.create();const h=Q.map(E=>I(E,C));return h.length===1?h[0]:s(h)},g=B=>{const C=i.toPolygons(B);if(C.length===0)return[];const Q=[];for(let h=0;h<C.length;h++){const E=C[h],u=E.vertices;let d=0,f=0,m=0;for(let F=0;F<u.length;F++)d+=u[F][0],f+=u[F][1],m+=u[F][2];d/=u.length,f/=u.length,m/=u.length;const w=n.plane(E),D=w[0],x=w[1],_=w[2],b=.1,R=[d-D*b,f-x*b,m-_*b];for(let F=1;F<u.length-1;F++){const H=u[0],Y=u[F],J=u[F+1],O=c(R,H,Y,J);Q.push(i.create(O))}}return Q},c=(B,C,Q,h)=>[n.create([B,Q,C]),n.create([B,C,h]),n.create([C,Q,h]),n.create([Q,B,h])],I=(B,C)=>{const Q=l(B),h=l(C);if(Q.length===0||h.length===0)return i.create();const E=[];for(let d=0;d<Q.length;d++){const f=Q[d];for(let m=0;m<h.length;m++){const w=h[m];E.push([f[0]+w[0],f[1]+w[1],f[2]+w[2]])}}const u=o(E);return i.create(u)},l=B=>{const C=new Set,Q=[],h=i.toPolygons(B);for(let E=0;E<h.length;E++){const u=h[E].vertices;for(let d=0;d<u.length;d++){const f=u[d],m=`${f[0]},${f[1]},${f[2]}`;C.has(m)||(C.add(m),Q.push(f))}}return Q};A.exports=r}}),DSe=at({"node_modules/@jscad/modeling/src/operations/booleans/scissionGeom3.js"(e,A){var t=Sn(),i=sb(),n=ts(),o=g=>g.sort((c,I)=>c-I).filter((c,I,l)=>!I||c!==l[I-1]),s=(g,c,I)=>{const l=`${c}`,B=g.get(l);B===void 0?g.set(l,[I]):B.push(I)},r=(g,c)=>{const I=`${c}`;return g.get(I)},a=g=>{const c=i(g),I=n.toPolygons(g),l=I.length,B=new Map,C=t.create();I.forEach((d,f)=>{d.vertices.forEach(m=>{s(B,t.snap(C,m,c),f)})});const Q=I.map(d=>{let f=[];return d.vertices.forEach(m=>{f=f.concat(r(B,t.snap(C,m,c)))}),{e:1,d:o(f)}});B.clear();let h=0;const E=Q.length;for(let d=0;d<E;d++){const f=Q[d];if(f.e>0){const m=new Array(l);m[d]=!0;do h=0,m.forEach((w,D)=>{const x=Q[D];if(x.e>0){x.e=-1;for(let _=0;_<x.d.length;_++)m[x.d[_]]=!0;h++}});while(h>0);f.indexes=m}}const u=[];for(let d=0;d<E;d++)if(Q[d].indexes){const f=[];Q[d].indexes.forEach((m,w)=>f.push(I[w])),u.push(n.create(f))}return u};A.exports=a}}),xSe=at({"node_modules/@jscad/modeling/src/operations/booleans/scission.js"(e,A){var t=vo(),i=ts(),n=DSe(),o=(...s)=>{if(s=t(s),s.length===0)throw new Error("wrong number of arguments");const r=s.map(a=>i.isA(a)?n(a):a);return r.length===1?r[0]:r};A.exports=o}}),SSe=at({"node_modules/@jscad/modeling/src/operations/booleans/subtractGeom3Sub.js"(e,A){var t=ts(),i=WEA(),{Tree:n}=ZEA(),o=(s,r)=>{if(!i(s,r))return t.clone(s);const a=new n(t.toPolygons(s)),g=new n(t.toPolygons(r));a.invert(),a.clipTo(g),g.clipTo(a,!0),a.addPolygons(g.allPolygons()),a.invert();const c=a.allPolygons();return t.create(c)};A.exports=o}}),Ptt=at({"node_modules/@jscad/modeling/src/operations/booleans/subtractGeom3.js"(e,A){var t=vo(),i=Y8(),n=SSe(),o=(...s)=>{s=t(s);let r=s.shift();return s.forEach(a=>{r=n(r,a)}),r=i(r),r};A.exports=o}}),bSe=at({"node_modules/@jscad/modeling/src/operations/booleans/subtractGeom2.js"(e,A){var t=vo(),i=ts(),n=sb(),o=qEA(),s=OEA(),r=Ptt(),a=(...g)=>{g=t(g);const c=g.map(B=>s({z0:-1,z1:1},B)),I=r(c),l=n(I);return o(l,i.toPolygons(I))};A.exports=a}}),_Se=at({"node_modules/@jscad/modeling/src/operations/booleans/subtract.js"(e,A){var t=vo(),i=H8(),n=ss(),o=ts(),s=bSe(),r=Ptt(),a=(...g)=>{if(g=t(g),g.length===0)throw new Error("wrong number of arguments");if(!i(g))throw new Error("only subtract of the types are supported");const c=g[0];return n.isA(c)?s(g):o.isA(c)?r(g):c};A.exports=a}}),Ktt=at({"node_modules/@jscad/modeling/src/operations/booleans/unionGeom2.js"(e,A){var t=vo(),i=ts(),n=sb(),o=qEA(),s=OEA(),r=jEA(),a=(...g)=>{g=t(g);const c=g.map(B=>s({z0:-1,z1:1},B)),I=r(c),l=n(I);return o(l,i.toPolygons(I))};A.exports=a}}),zEA=at({"node_modules/@jscad/modeling/src/operations/booleans/union.js"(e,A){var t=vo(),i=H8(),n=ss(),o=ts(),s=Ktt(),r=jEA(),a=(...g)=>{if(g=t(g),g.length===0)throw new Error("wrong number of arguments");if(!i(g))throw new Error("only unions of the same type are supported");const c=g[0];return n.isA(c)?s(g):o.isA(c)?r(g):c};A.exports=a}}),J8=at({"node_modules/@jscad/modeling/src/operations/booleans/index.js"(e,A){A.exports={intersect:wSe(),minkowski:Ttt(),scission:xSe(),subtract:_Se(),union:zEA()}}}),oO=at({"node_modules/@jscad/modeling/src/operations/expansions/offsetFromPoints.js"(e,A){var{EPS:t,TAU:i}=Qr(),n=dtt(),o=YEA(),s=_s(),r=eO(),a=(g,c)=>{const I={delta:1,corners:"edge",closed:!1,segments:16};let{delta:l,corners:B,closed:C,segments:Q}=Object.assign({},I,g);if(Math.abs(l)<t)return c;let h=g.closed?r(c):1;h===0&&(h=1);const E=h>0&&l>=0||h<0&&l<0;l=Math.abs(l);let u=null,d=[];const f=[],m=s.create(),w=c.length;for(let D=0;D<w;D++){const x=(D+1)%w,_=c[D],b=c[x];E?s.subtract(m,_,b):s.subtract(m,b,_),s.normal(m,m),s.normalize(m,m),s.scale(m,m,l);const R=s.add(s.create(),_,m),F=s.add(s.create(),b,m),H=[R,F];if(u!=null&&(C||!C&&x!==0)){const Y=n(u[0],u[1],H[0],H[1]);Y?(d.pop(),H[0]=Y):f.push({c:_,s0:u,s1:H})}u=[R,F],!(x===0&&!C)&&(d.push(H[0]),d.push(H[1]))}if(C&&u!=null){const D=d[0],x=d[1],_=n(u[0],u[1],D,x);if(_)d[0]=_,d.pop();else{const b=c[0],R=[D,x];f.push({c:b,s0:u,s1:R})}}if(B==="edge"){const D=new Map;d.forEach((b,R)=>D.set(b,R));const x=o.create(),_=o.create();f.forEach(b=>{o.fromPoints(x,b.s0[0],b.s0[1]),o.fromPoints(_,b.s1[0],b.s1[1]);const R=o.intersectPointOfLines(x,_);if(Number.isFinite(R[0])&&Number.isFinite(R[1])){const F=b.s0[1],H=D.get(F);d[H]=R,d[(H+1)%d.length]=void 0}else{const F=b.s1[0],H=D.get(F);d[H]=void 0}}),d=d.filter(b=>b!==void 0)}if(B==="round"){let D=Math.floor(Q/4);const x=s.create();f.forEach(_=>{let b=s.angle(s.subtract(x,_.s1[0],_.c));if(b-=s.angle(s.subtract(x,_.s0[1],_.c)),E&&b<0&&(b=b+Math.PI,b<0&&(b=b+Math.PI)),!E&&b>0&&(b=b-Math.PI,b>0&&(b=b-Math.PI)),b!==0){D=Math.floor(Q*(Math.abs(b)/i));const R=b/D,F=s.angle(s.subtract(x,_.s0[1],_.c)),H=[];for(let Y=1;Y<D;Y++){const J=F+R*Y,O=s.fromAngleRadians(s.create(),J);s.scale(O,O,l),s.add(O,O,_.c),H.push(O)}if(H.length>0){const Y=_.s0[1];let J=d.findIndex(O=>s.equals(Y,O));J=(J+1)%d.length,d.splice(J,0,...H)}}else{const R=_.s1[0],F=d.findIndex(H=>s.equals(R,H));d.splice(F,1)}})}return d};A.exports=a}}),kSe=at({"node_modules/@jscad/modeling/src/operations/expansions/expandGeom2.js"(e,A){var t=ss(),i=oO(),n=(o,s)=>{const r={delta:1,corners:"edge",segments:16},{delta:a,corners:g,segments:c}=Object.assign({},r,o);if(!(g==="edge"||g==="chamfer"||g==="round"))throw new Error('corners must be "edge", "chamfer", or "round"');const B=t.toOutlines(s).map(C=>(o={delta:a,corners:g,closed:!0,segments:c},i(o,C))).reduce((C,Q)=>C.concat(t.toSides(t.fromPoints(Q))),[]);return t.create(B)};A.exports=n}}),vSe=at({"node_modules/@jscad/modeling/src/operations/expansions/extrudePolygon.js"(e,A){var t=Ac(),i=Sn(),n=ts(),o=tr(),s=(r,a)=>{i.dot(o.plane(a),r)>0&&(a=o.invert(a));const c=[a],I=o.transform(t.fromTranslation(t.create(),r),a),l=a.vertices.length;for(let B=0;B<l;B++){const C=B<l-1?B+1:0,Q=o.create([a.vertices[B],I.vertices[B],I.vertices[C],a.vertices[C]]);c.push(Q)}return c.push(o.invert(I)),n.create(c)};A.exports=s}}),FSe=at({"node_modules/@jscad/modeling/src/operations/expansions/expandShell.js"(e,A){var{EPS:t,TAU:i}=Qr(),n=Ac(),o=Sn(),s=Utt(),r=ts(),a=tr(),g=vtt(),c=Y8(),I=Jtt(),l=vSe(),B=(E,u,d)=>{const f=u.toString();if(E.has(f))E.get(f)[1].push(d);else{const m=[u,[d]];E.set(f,m)}},C=(E,u,d)=>{const f=u[0].toString(),m=u[1].toString(),w=f<m?`${f},${m}`:`${m},${f}`;if(E.has(w))E.get(w)[1].push(d);else{const D=[u,[d]];E.set(w,D)}},Q=(E,u)=>{E.findIndex(f=>f===u)<0&&E.push(u)},h=(E,u)=>{const d={delta:1,segments:12},{delta:f,segments:m}=Object.assign({},d,E);let w=r.create();const D=new Map,x=new Map,_=o.create(),b=o.create();return r.toPolygons(u).forEach((F,H)=>{const Y=o.scale(o.create(),a.plane(F),2*f),J=a.transform(n.fromTranslation(n.create(),o.scale(o.create(),Y,-.5)),F),O=l(Y,J);w=I(w,O);const W=F.vertices;for(let z=0;z<W.length;z++){B(D,W[z],a.plane(F));const tA=(z+1)%W.length,aA=[W[z],W[tA]];C(x,aA,a.plane(F))}}),x.forEach(F=>{const H=F[0],Y=F[1],J=H[0],O=H[1],W=o.subtract(o.create(),O,J);o.normalize(W,W);const z=Y[0],tA=o.cross(o.create(),z,W);let aA=[];for(let JA=0;JA<m;JA++)Q(aA,JA*i/m);for(let JA=0,EA=Y.length;JA<EA;JA++){const bA=Y[JA],dA=o.dot(tA,bA),WA=o.dot(z,bA);let jA=Math.atan2(dA,WA);jA<0&&(jA+=i),Q(aA,jA),jA=Math.atan2(-dA,-WA),jA<0&&(jA+=i),Q(aA,jA)}aA=aA.sort(s);const eA=aA.length;let oA,rA;const lA=[],pA=[],kA=[];for(let JA=-1;JA<eA;JA++){const EA=aA[JA<0?JA+eA:JA],bA=Math.sin(EA),dA=Math.cos(EA);o.scale(_,z,dA*f),o.scale(b,tA,bA*f),o.add(_,_,b);const WA=o.add(o.create(),J,_),jA=o.add(o.create(),O,_);let It=!1;if(JA>=0&&o.distance(WA,oA)<t&&(It=!0),!It){if(JA>=0){lA.push(WA),pA.push(jA);const mA=[rA,jA,WA,oA],gt=a.create(mA);kA.push(gt)}oA=WA,rA=jA}}pA.reverse(),kA.push(a.create(lA)),kA.push(a.create(pA));const MA=r.create(kA);w=I(w,MA)}),D.forEach(F=>{const H=F[0],Y=F[1],J=Y[0];let O=null,W=0;for(let eA=1;eA<Y.length;eA++){const oA=Y[eA],rA=o.cross(_,J,oA),lA=o.length(rA);lA>.05&&lA>W&&(W=lA,O=oA)}O||(O=o.orthogonal(_,J));const z=o.cross(_,J,O);o.normalize(z,z);const tA=o.cross(b,z,J),aA=g({center:[H[0],H[1],H[2]],radius:f,segments:m,axes:[J,z,tA]});w=I(w,aA)}),c(w)};A.exports=h}}),MSe=at({"node_modules/@jscad/modeling/src/operations/expansions/expandGeom3.js"(e,A){var t=ts(),i=zEA(),n=FSe(),o=(s,r)=>{const a={delta:1,corners:"round",segments:12},{delta:g,corners:c,segments:I}=Object.assign({},a,s);if(c!=="round")throw new Error('corners must be "round" for 3D geometries');if(t.toPolygons(r).length===0)throw new Error("the given geometry cannot be empty");s={delta:g,corners:c,segments:I};const B=n(s,r);return i(r,B)};A.exports=o}}),GSe=at({"node_modules/@jscad/modeling/src/operations/expansions/expandPath2.js"(e,A){var t=eO(),i=_s(),n=ss(),o=Mg(),s=oO(),r=c=>{let{external:I,internal:l}=c;t(I)<0?I=I.reverse():l=l.reverse();const B=o.fromPoints({closed:!0},I),C=o.fromPoints({closed:!0},l),Q=n.toSides(n.fromPoints(o.toPoints(B))),h=n.toSides(n.fromPoints(o.toPoints(C)));return Q.push(...h),n.create(Q)},a=(c,I,l,B)=>{const{points:C,external:Q,internal:h}=c,E=Math.floor(I/2),u=[],d=[];if(l==="round"&&E>0){const m=Math.PI/E,w=C[C.length-1],D=i.angle(i.subtract(i.create(),Q[Q.length-1],w)),x=C[0],_=i.angle(i.subtract(i.create(),h[0],x));for(let b=1;b<E;b++){let R=D+m*b,F=i.fromAngleRadians(i.create(),R);i.scale(F,F,B),i.add(F,F,w),u.push(F),R=_+m*b,F=i.fromAngleRadians(i.create(),R),i.scale(F,F,B),i.add(F,F,x),d.push(F)}}const f=[];return f.push(...Q,...u,...h.reverse(),...d),n.fromPoints(f)},g=(c,I)=>{c=Object.assign({},{delta:1,corners:"edge",segments:16},c);const{delta:B,corners:C,segments:Q}=c;if(B<=0)throw new Error("the given delta must be positive for paths");if(!(C==="edge"||C==="chamfer"||C==="round"))throw new Error('corners must be "edge", "chamfer", or "round"');const h=I.isClosed,E=o.toPoints(I);if(E.length===0)throw new Error("the given geometry cannot be empty");const u={points:E,external:s({delta:B,corners:C,segments:Q,closed:h},E),internal:s({delta:-B,corners:C,segments:Q,closed:h},E)};return I.isClosed?r(u):a(u,Q,C,B)};A.exports=g}}),XEA=at({"node_modules/@jscad/modeling/src/operations/expansions/expand.js"(e,A){var t=vo(),i=ss(),n=ts(),o=Mg(),s=kSe(),r=MSe(),a=GSe(),g=(c,...I)=>{if(I=t(I),I.length===0)throw new Error("wrong number of arguments");const l=I.map(B=>o.isA(B)?a(c,B):i.isA(B)?s(c,B):n.isA(B)?r(c,B):B);return l.length===1?l[0]:l};A.exports=g}}),RSe=at({"node_modules/@jscad/modeling/src/operations/expansions/offsetGeom2.js"(e,A){var t=ss(),i=REA(),n=oO(),o=(s,r)=>{const a={delta:1,corners:"edge",segments:0},{delta:g,corners:c,segments:I}=Object.assign({},a,s);if(!(c==="edge"||c==="chamfer"||c==="round"))throw new Error('corners must be "edge", "chamfer", or "round"');const l=t.toOutlines(r),C=l.map(Q=>(s={delta:l.reduce((u,d)=>u+i.arePointsInside(Q,i.create(d)),0)%2===0?g:-g,corners:c,closed:!0,segments:I},n(s,Q))).reduce((Q,h)=>Q.concat(t.toSides(t.fromPoints(h))),[]);return t.create(C)};A.exports=o}}),NSe=at({"node_modules/@jscad/modeling/src/operations/expansions/offsetPath2.js"(e,A){var t=Mg(),i=oO(),n=(o,s)=>{const r={delta:1,corners:"edge",closed:s.isClosed,segments:16},{delta:a,corners:g,closed:c,segments:I}=Object.assign({},r,o);if(!(g==="edge"||g==="chamfer"||g==="round"))throw new Error('corners must be "edge", "chamfer", or "round"');o={delta:a,corners:g,closed:c,segments:I};const l=i(o,t.toPoints(s));return t.fromPoints({closed:c},l)};A.exports=n}}),LSe=at({"node_modules/@jscad/modeling/src/operations/expansions/offset.js"(e,A){var t=vo(),i=ss(),n=Mg(),o=RSe(),s=NSe(),r=(a,...g)=>{if(g=t(g),g.length===0)throw new Error("wrong number of arguments");const c=g.map(I=>n.isA(I)?s(a,I):i.isA(I)?o(a,I):I);return c.length===1?c[0]:c};A.exports=r}}),qtt=at({"node_modules/@jscad/modeling/src/operations/expansions/index.js"(e,A){A.exports={expand:XEA(),offset:LSe()}}}),sO=at({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeLinearGeom2.js"(e,A){var t=Ac(),i=Sn(),n=ss(),o=BF(),s=nO(),r=(a,g)=>{const c={offset:[0,0,1],twistAngle:0,twistSteps:12,repair:!0};let{offset:I,twistAngle:l,twistSteps:B,repair:C}=Object.assign({},c,a);if(B<1)throw new Error("twistSteps must be 1 or more");l===0&&(B=1);const Q=i.clone(I),h=n.toSides(g);if(h.length===0)throw new Error("the given geometry cannot be empty");const E=o.fromSides(h);Q[2]<0&&o.reverse(E,E);const u=t.create(),d=(f,m,w)=>{const D=m/B*l,x=i.scale(i.create(),Q,m/B);return t.multiply(u,t.fromZRotation(u,D),t.fromTranslation(t.create(),x)),o.transform(u,w)};return a={numberOfSlices:B+1,capStart:!0,capEnd:!0,repair:C,callback:d},s(a,E)};A.exports=r}}),USe=at({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeLinearPath2.js"(e,A){var t=ss(),i=Mg(),n=sO(),o=(s,r)=>{if(!r.isClosed)throw new Error("extruded path must be closed");const a=i.toPoints(r),g=t.fromPoints(a);return n(s,g)};A.exports=o}}),HSe=at({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeLinear.js"(e,A){var t=vo(),i=ss(),n=Mg(),o=sO(),s=USe(),r=(a,...g)=>{const c={height:1,twistAngle:0,twistSteps:1,repair:!0},{height:I,twistAngle:l,twistSteps:B,repair:C}=Object.assign({},c,a);if(g=t(g),g.length===0)throw new Error("wrong number of arguments");a={offset:[0,0,I],twistAngle:l,twistSteps:B,repair:C};const Q=g.map(h=>n.isA(h)?s(a,h):i.isA(h)?o(a,h):h);return Q.length===1?Q[0]:Q};A.exports=r}}),YSe=at({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeRectangularPath2.js"(e,A){var t=Mg(),i=XEA(),n=sO(),o=(s,r)=>{const a={size:1,height:1},{size:g,height:c}=Object.assign({},a,s);if(s.delta=g,s.offset=[0,0,c],t.toPoints(r).length===0)throw new Error("the given geometry cannot be empty");const l=i(s,r);return n(s,l)};A.exports=o}}),JSe=at({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeRectangularGeom2.js"(e,A){var{area:t}=R8(),i=ss(),n=Mg(),o=XEA(),s=sO(),r=(a,g)=>{const c={size:1,height:1},{size:I,height:l}=Object.assign({},c,a);a.delta=I,a.offset=[0,0,l];const B=i.toOutlines(g);if(B.length===0)throw new Error("the given geometry cannot be empty");const Q=B.map(E=>(t(E)<0&&E.reverse(),o(a,n.fromPoints({closed:!0},E)))).reduce((E,u)=>E.concat(i.toSides(u)),[]),h=i.create(Q);return s(a,h)};A.exports=r}}),TSe=at({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeRectangular.js"(e,A){var t=vo(),i=ss(),n=Mg(),o=YSe(),s=JSe(),r=(a,...g)=>{const c={size:1,height:1},{size:I,height:l}=Object.assign({},c,a);if(g=t(g),g.length===0)throw new Error("wrong number of arguments");if(I<=0)throw new Error("size must be positive");if(l<=0)throw new Error("height must be positive");const B=g.map(C=>n.isA(C)?o(a,C):i.isA(C)?s(a,C):C);return B.length===1?B[0]:B};A.exports=r}}),PSe=at({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeHelical.js"(e,A){var{TAU:t}=Qr(),i=Ac(),n=ss(),o=nO(),s=BF(),r=(a,g)=>{const c={angle:t,startAngle:0,pitch:10,height:0,endOffset:0,segmentsPerRotation:32};let{angle:I,startAngle:l,pitch:B,height:C,endOffset:Q,segmentsPerRotation:h}=Object.assign({},c,a);if(C!=0&&(B=C/(I/t)),h<3)throw new Error("The number of segments per rotation needs to be at least 3.");const u=n.toSides(g);if(u.length===0)throw new Error("The given geometry cannot be empty");const d=u.filter(b=>b[0][0]>=0);let f=s.fromSides(u);d.length===0&&(f=s.reverse(f));const m=Math.round(h/t*Math.abs(I)),w=m>=2?m:2,D=i.create(),x=i.create(),_=(b,R,F)=>{const H=l+I/w*R,Y=Q/w*R,J=(H-l)/t*B;return i.multiply(D,i.fromTranslation(i.create(),[Y,0,J*Math.sign(I)]),i.fromXRotation(i.create(),-t/4*Math.sign(I))),i.multiply(x,i.fromZRotation(i.create(),H),D),s.transform(x,F)};return o({numberOfSlices:w+1,callback:_},f)};A.exports=r}}),KSe=at({"node_modules/@jscad/modeling/src/operations/extrusions/project.js"(e,A){var t=vo(),i=HEA(),n=YD(),o=Ac(),s=ss(),r=ts(),a=tr(),g=sb(),c=Ktt(),I=(B,C)=>{const Q=n.fromNormalAndPoint(n.create(),B.axis,B.origin);if(Number.isNaN(Q[0])||Number.isNaN(Q[1])||Number.isNaN(Q[2])||Number.isNaN(Q[3]))throw new Error("project: invalid axis or origin");const h=g(C),E=h*h*Math.sqrt(3)/4;if(h===0)return s.create();const u=r.toPolygons(C);let d=[];for(let m=0;m<u.length;m++){const w=u[m].vertices.map(_=>n.projectionOfPoint(Q,_)),D=a.create(w),x=a.plane(D);i(Q,x)&&(a.measureArea(D)<E||d.push(D))}if(!i(Q,[0,0,1])){const m=o.fromVectorRotation(o.create(),Q,[0,0,1]);d=d.map(w=>a.transform(m,w))}d=d.sort((m,w)=>a.measureArea(w)-a.measureArea(m));const f=d.map(m=>s.fromPoints(m.vertices));return c(f)},l=(B,...C)=>{const Q={axis:[0,0,1],origin:[0,0,0]},{axis:h,origin:E}=Object.assign({},Q,B);if(C=t(C),C.length===0)throw new Error("wrong number of arguments");B={axis:h,origin:E};const u=C.map(d=>r.isA(d)?I(B,d):d);return u.length===1?u[0]:u};A.exports=l}}),T8=at({"node_modules/@jscad/modeling/src/operations/extrusions/index.js"(e,A){A.exports={extrudeFromSlices:nO(),extrudeLinear:HSe(),extrudeRectangular:TSe(),extrudeRotate:Rtt(),extrudeHelical:PSe(),project:KSe(),slice:BF()}}}),$EA=at({"node_modules/@jscad/modeling/src/operations/hulls/hullPoints2.js"(e,A){var t=_s(),i=s=>{let r=t.fromValues(1/0,1/0);s.forEach(c=>{(c[1]<r[1]||c[1]===r[1]&&c[0]<r[0])&&(r=c)});const a=[];s.forEach(c=>{const I=o(c[1]-r[1],c[0]-r[0]),l=t.squaredDistance(c,r);a.push({point:c,angle:I,distSq:l})}),a.sort((c,I)=>c.angle!==I.angle?c.angle-I.angle:c.distSq-I.distSq);const g=[];return a.forEach(c=>{let I=g.length;for(;I>1&&n(g[I-2],g[I-1],c.point)<=Number.EPSILON;)g.pop(),I=g.length;g.push(c.point)}),g},n=(s,r,a)=>(r[0]-s[0])*(a[1]-s[1])-(r[1]-s[1])*(a[0]-s[0]),o=(s,r)=>s===0&&r===0?-1/0:-r/s;A.exports=i}}),AuA=at({"node_modules/@jscad/modeling/src/operations/hulls/toUniquePoints.js"(e,A){var t=ss(),i=ts(),n=Mg(),o=s=>{const r=new Set,a=[],g=c=>{const I=c.toString();r.has(I)||(a.push(c),r.add(I))};return s.forEach(c=>{t.isA(c)?t.toPoints(c).forEach(g):i.isA(c)?i.toPoints(c).forEach(I=>I.forEach(g)):n.isA(c)&&n.toPoints(c).forEach(g)}),a};A.exports=o}}),qSe=at({"node_modules/@jscad/modeling/src/operations/hulls/hullPath2.js"(e,A){var t=vo(),i=Mg(),n=$EA(),o=AuA(),s=(...r)=>{r=t(r);const a=o(r),g=n(a);return i.fromPoints({closed:!0},g)};A.exports=s}}),OSe=at({"node_modules/@jscad/modeling/src/operations/hulls/hullGeom2.js"(e,A){var t=vo(),i=ss(),n=$EA(),o=AuA(),s=(...r)=>{r=t(r);const a=o(r),g=n(a);return g.length<3?i.create():i.fromPoints(g)};A.exports=s}}),WSe=at({"node_modules/@jscad/modeling/src/operations/hulls/hullGeom3.js"(e,A){var t=vo(),i=ts(),n=AuA(),o=VEA(),s=(...r)=>{r=t(r);const a=n(r);return a.length===0?i.create():i.create(o(a))};A.exports=s}}),Ott=at({"node_modules/@jscad/modeling/src/operations/hulls/hull.js"(e,A){var t=vo(),i=H8(),n=ss(),o=ts(),s=Mg(),r=qSe(),a=OSe(),g=WSe(),c=(...I)=>{if(I=t(I),I.length===0)throw new Error("wrong number of arguments");if(!i(I))throw new Error("only hulls of the same type are supported");const l=I[0];return s.isA(l)?r(I):n.isA(l)?a(I):o.isA(l)?g(I):l};A.exports=c}}),ZSe=at({"node_modules/@jscad/modeling/src/operations/hulls/hullChain.js"(e,A){var t=vo(),i=zEA(),n=Ott(),o=(...s)=>{if(s=t(s),s.length<2)throw new Error("wrong number of arguments");const r=[];for(let a=1;a<s.length;a++)r.push(n(s[a-1],s[a]));return i(r)};A.exports=o}}),VSe=at({"node_modules/@jscad/modeling/src/operations/hulls/index.js"(e,A){A.exports={hull:Ott(),hullChain:ZSe(),hullPoints2:$EA(),hullPoints3:VEA()}}}),jSe=at({"node_modules/@jscad/modeling/src/operations/minkowski/index.js"(e,A){A.exports={minkowskiSum:Ttt()}}}),Wtt=at({"node_modules/@jscad/modeling/src/operations/modifiers/snapPolygons.js"(e,A){var t=Sn(),i=tr(),n=(s,r)=>{const a=Math.abs(i.measureArea(r));return Number.isFinite(a)&&a>s},o=(s,r)=>{let a=r.map(c=>{const I=c.vertices.map(C=>t.snap(t.create(),C,s)),l=[];for(let C=0;C<I.length;C++){const Q=(C+1)%I.length;t.equals(I[C],I[Q])||l.push(I[C])}const B=i.create(l);return c.color&&(B.color=c.color),B});const g=s*s*Math.sqrt(3)/4;return a=a.filter(c=>n(g,c)),a};A.exports=o}}),zSe=at({"node_modules/@jscad/modeling/src/operations/modifiers/mergePolygons.js"(e,A){var t=HEA(),i=Sn(),n=tr(),o=E=>{const u=n.toPoints(E),d=[];for(let f=0;f<u.length;f++){const m=(f+1)%u.length,w={v1:u[f],v2:u[m]};d.push(w)}for(let f=0;f<d.length;f++){const m=(f+1)%u.length;d[f].next=d[m],d[m].prev=d[f]}return d},s=(E,u)=>{const d=`${u.v1}:${u.v2}`;E.set(d,u)},r=(E,u)=>{const d=`${u.v1}:${u.v2}`;E.delete(d)},a=(E,u)=>{const d=`${u.v2}:${u.v1}`;return E.get(d)},g=(E,u,d)=>{let f=E.prev.v1,m=E.prev.v2,w=u.next.v2;const D=l(f,m,w,d);f=u.prev.v1,m=u.prev.v2,w=E.next.v2;const x=l(f,m,w,d);return[D,x]},c=i.create(),I=i.create(),l=(E,u,d,f)=>{const m=i.subtract(c,u,E),w=i.subtract(I,d,u);return i.cross(m,m,w),i.dot(m,f)},B=E=>{let u;const d=[];for(;E.next;){const f=E.next;d.push(E.v1),E.v1=null,E.v2=null,E.next=null,E.prev=null,E=f}return d.length>0&&(u=n.create(d)),u},C=E=>{if(E.length<2)return E;const u=E[0].plane,d=E.slice(),f=new Map;for(;d.length>0;){const w=d.shift(),D=o(w);for(let x=0;x<D.length;x++){const _=D[x],b=a(f,_);if(b){const R=g(_,b,u);if(R[0]>=0&&R[1]>=0){const F=b.next,H=_.next;_.prev.next=b.next,_.next.prev=b.prev,b.prev.next=_.next,b.next.prev=_.prev,_.v1=null,_.v2=null,_.next=null,_.prev=null,r(f,b),b.v1=null,b.v2=null,b.next=null,b.prev=null;const Y=(J,O,W)=>{const z={v1:W.v1,v2:O.v2,next:O.next,prev:W.prev};W.prev.next=z,O.next.prev=z,r(J,O),O.v1=null,O.v2=null,O.next=null,O.prev=null,r(J,W),W.v1=null,W.v2=null,W.next=null,W.prev=null};R[0]===0&&Y(f,F,F.prev),R[1]===0&&Y(f,H,H.prev)}}else _.next&&s(f,_)}}const m=[];return f.forEach(w=>{const D=B(w);D&&m.push(D)}),f.clear(),m},Q=(E,u)=>Math.abs(E[3]-u[3])<15e-8?t(E,u):!1,h=(E,u)=>{const d=[];u.forEach(m=>{const w=d.find(D=>Q(D[0],n.plane(m)));w?w[1].push(m):d.push([n.plane(m),[m]])});let f=[];return d.forEach(m=>{const w=m[1],D=C(w);f=f.concat(D)}),f};A.exports=h}}),XSe=at({"node_modules/@jscad/modeling/src/operations/modifiers/insertTjunctions.js"(e,A){var t=Qr(),i=Sn(),n=tr(),o=g=>`${g}`,s=(g,c,I,l,B,C)=>{const Q=o(l),h=o(B),E=`${Q}/${h}`,u=`${h}/${Q}`;if(g.has(u))return r(g,c,I,B,l,null),null;const d={vertex0:l,vertex1:B,polygonindex:C};return g.has(E)?g.get(E).push(d):g.set(E,[d]),c.has(Q)?c.get(Q).push(E):c.set(Q,[E]),I.has(h)?I.get(h).push(E):I.set(h,[E]),E},r=(g,c,I,l,B,C)=>{const Q=o(l),h=o(B),E=`${Q}/${h}`;let u=-1;const d=g.get(E);for(let f=0;f<d.length;f++){const m=d[f];let w=o(m.vertex0);if(w===Q&&(w=o(m.vertex1),w===h&&!(C!==null&&m.polygonindex!==C))){u=f;break}}d.splice(u,1),d.length===0&&g.delete(E),u=c.get(Q).indexOf(E),c.get(Q).splice(u,1),c.get(Q).length===0&&c.delete(Q),u=I.get(h).indexOf(E),I.get(h).splice(u,1),I.get(h).length===0&&I.delete(h)},a=g=>{const c=new Map;for(let I=0;I<g.length;I++){const l=g[I],B=l.vertices.length;if(B>=3){let C=l.vertices[0],Q=o(C);for(let h=0;h<B;h++){let E=h+1;E===B&&(E=0);const u=l.vertices[E],d=o(u),f=`${Q}/${d}`,m=`${d}/${Q}`;if(c.has(m)){const w=c.get(m);w.splice(-1,1),w.length===0&&c.delete(m)}else{const w={vertex0:C,vertex1:u,polygonindex:I};c.has(f)?c.get(f).push(w):c.set(f,[w])}C=u,Q=d}}else console.warn("warning: invalid polygon found during insertTjunctions")}if(c.size>0){const I=new Map,l=new Map,B=new Map;for(const[Q,h]of c)B.set(Q,!0),h.forEach(E=>{const u=o(E.vertex0),d=o(E.vertex1);I.has(u)?I.get(u).push(Q):I.set(u,[Q]),l.has(d)?l.get(d).push(Q):l.set(d,[Q])});const C=g.slice(0);for(;c.size!==0;){for(const h of c.keys())B.set(h,!0);let Q=!1;for(;;){const h=Array.from(B.keys());if(h.length===0)break;const E=h[0];let u=!0;if(c.has(E)){const f=c.get(E)[0];for(let m=0;m<2;m++){const w=m===0?f.vertex0:f.vertex1,D=m===0?f.vertex1:f.vertex0,x=o(w),_=o(D);let b=[];m===0?l.has(x)&&(b=l.get(x)):I.has(x)&&(b=I.get(x));for(let R=0;R<b.length;R++){const F=b[R],H=c.get(F)[0],Y=m===0?H.vertex0:H.vertex1;if(m===0?H.vertex1:H.vertex0,o(Y)===_){r(c,I,l,w,D,null),r(c,I,l,D,w,null),u=!1,m=2,Q=!0;break}else{const O=w,W=D,z=Y,tA=i.subtract(i.create(),z,O),aA=i.dot(i.subtract(i.create(),W,O),tA)/i.dot(tA,tA);if(aA>0&&aA<1){const eA=i.scale(i.create(),tA,aA);if(i.add(eA,eA,O),i.squaredDistance(eA,W)<t.EPS*t.EPS){const rA=H.polygonindex,lA=C[rA],pA=o(H.vertex1);let kA=-1;for(let dA=0;dA<lA.vertices.length;dA++)if(o(lA.vertices[dA])===pA){kA=dA;break}const MA=lA.vertices.slice(0);MA.splice(kA,0,D);const JA=n.create(MA);C[rA]=JA,r(c,I,l,H.vertex0,H.vertex1,rA);const EA=s(c,I,l,H.vertex0,D,rA),bA=s(c,I,l,D,H.vertex1,rA);EA!==null&&B.set(EA,!0),bA!==null&&B.set(bA,!0),u=!1,m=2,Q=!0;break}}}}}}u&&B.delete(E)}if(!Q)break}g=C}return c.clear(),g};A.exports=a}}),$Se=at({"node_modules/@jscad/modeling/src/operations/modifiers/triangulatePolygons.js"(e,A){var t=Sn(),i=tr(),n=(s,r,a)=>{const g=r.vertices.length;if(g>3){if(g>4){const l=[0,0,0];r.vertices.forEach(B=>t.add(l,l,B)),t.snap(l,t.divide(l,l,[g,g,g]),s);for(let B=0;B<g;B++){const C=i.create([l,r.vertices[B],r.vertices[(B+1)%g]]);r.color&&(C.color=r.color),a.push(C)}return}const c=i.create([r.vertices[0],r.vertices[1],r.vertices[2]]),I=i.create([r.vertices[0],r.vertices[2],r.vertices[3]]);r.color&&(c.color=r.color,I.color=r.color),a.push(c,I);return}a.push(r)},o=(s,r)=>{const a=[];return r.forEach(g=>{n(s,g,a)}),a};A.exports=o}}),Abe=at({"node_modules/@jscad/modeling/src/operations/modifiers/generalize.js"(e,A){var t=vo(),i=sb(),n=ss(),o=ts(),s=Mg(),r=Wtt(),a=zSe(),g=XSe(),c=$Se(),I=(Q,h)=>h,l=(Q,h)=>h,B=(Q,h)=>{const E={snap:!1,simplify:!1,triangulate:!1},{snap:u,simplify:d,triangulate:f}=Object.assign({},E,Q),m=i(h);let w=o.toPolygons(h);u&&(w=r(m,w)),d&&(w=a(m,w)),f&&(w=g(w),w=c(m,w));const D=Object.assign({},h);return D.polygons=w,D},C=(Q,...h)=>{if(h=t(h),h.length===0)throw new Error("wrong number of arguments");const E=h.map(u=>{if(s.isA(u))return I(Q,u);if(n.isA(u))return l(Q,u);if(o.isA(u))return B(Q,u);throw new Error("invalid geometry")});return E.length===1?E[0]:E};A.exports=C}}),tbe=at({"node_modules/@jscad/modeling/src/operations/modifiers/snap.js"(e,A){var t=vo(),i=_s(),n=ss(),o=ts(),s=Mg(),r=sb(),a=Wtt(),g=B=>{const C=r(B),h=s.toPoints(B).map(E=>i.snap(i.create(),E,C));return s.create(h)},c=B=>{const C=r(B);let h=n.toSides(B).map(E=>[i.snap(i.create(),E[0],C),i.snap(i.create(),E[1],C)]);return h=h.filter(E=>!i.equals(E[0],E[1])),n.create(h)},I=B=>{const C=r(B),Q=o.toPolygons(B),h=a(C,Q);return o.create(h)},l=(...B)=>{if(B=t(B),B.length===0)throw new Error("wrong number of arguments");const C=B.map(Q=>s.isA(Q)?g(Q):n.isA(Q)?c(Q):o.isA(Q)?I(Q):Q);return C.length===1?C[0]:C};A.exports=l}}),ebe=at({"node_modules/@jscad/modeling/src/operations/modifiers/index.js"(e,A){A.exports={generalize:Abe(),snap:tbe(),retessellate:Y8()}}}),ibe=at({"node_modules/@jscad/modeling/src/utils/padArrayToLength.js"(e,A){var t=(i,n,o)=>{for(i=i.slice();i.length<o;)i.push(n);return i};A.exports=t}}),nbe=at({"node_modules/@jscad/modeling/src/operations/transforms/align.js"(e,A){var t=vo(),i=ibe(),n=JEA(),{translate:o}=K4(),s=c=>{if(!Array.isArray(c.modes)||c.modes.length>3)throw new Error("align(): modes must be an array of length <= 3");if(c.modes=i(c.modes,"none",3),c.modes.filter(I=>["center","max","min","none"].includes(I)).length!==3)throw new Error('align(): all modes must be one of "center", "max" or "min"');if(!Array.isArray(c.relativeTo)||c.relativeTo.length>3)throw new Error("align(): relativeTo must be an array of length <= 3");if(c.relativeTo=i(c.relativeTo,0,3),c.relativeTo.filter(I=>Number.isFinite(I)||I==null).length!==3)throw new Error("align(): all relativeTo values must be a number, or null.");if(typeof c.grouped!="boolean")throw new Error("align(): grouped must be a boolean value.");return c},r=(c,I,l)=>{for(let B=0;B<3;B++)c[B]==null&&(I[B]==="center"?c[B]=(l[0][B]+l[1][B])/2:I[B]==="max"?c[B]=l[1][B]:I[B]==="min"&&(c[B]=l[0][B]));return c},a=(c,I,l)=>{const B=n(c),C=[0,0,0];for(let Q=0;Q<3;Q++)I[Q]==="center"?C[Q]=l[Q]-(B[0][Q]+B[1][Q])/2:I[Q]==="max"?C[Q]=l[Q]-B[1][Q]:I[Q]==="min"&&(C[Q]=l[Q]-B[0][Q]);return o(C,c)},g=(c,...I)=>{c=Object.assign({},{modes:["center","center","min"],relativeTo:[0,0,0],grouped:!1},c),c=s(c);let{modes:B,relativeTo:C,grouped:Q}=c;if(I=t(I),I.length===0)throw new Error("align(): No geometries were provided to act upon");if(C.filter(h=>h==null).length){const h=n(I);C=r(C,B,h)}return Q?I=a(I,B,C):I=I.map(h=>a(h,B,C)),I.length===1?I[0]:I};A.exports=g}}),rO=at({"node_modules/@jscad/modeling/src/operations/transforms/center.js"(e,A){var t=vo(),i=ss(),n=ts(),o=Mg(),s=T4(),{translate:r}=K4(),a=(B,C)=>{const Q={axes:[!0,!0,!0],relativeTo:[0,0,0]},{axes:h,relativeTo:E}=Object.assign({},Q,B),u=s(C),d=[0,0,0];return h[0]&&(d[0]=E[0]-(u[0][0]+(u[1][0]-u[0][0])/2)),h[1]&&(d[1]=E[1]-(u[0][1]+(u[1][1]-u[0][1])/2)),h[2]&&(d[2]=E[2]-(u[0][2]+(u[1][2]-u[0][2])/2)),r(d,C)},g=(B,...C)=>{const Q={axes:[!0,!0,!0],relativeTo:[0,0,0]},{axes:h,relativeTo:E}=Object.assign({},Q,B);if(C=t(C),C.length===0)throw new Error("wrong number of arguments");if(E.length!==3)throw new Error("relativeTo must be an array of length 3");B={axes:h,relativeTo:E};const u=C.map(d=>o.isA(d)||i.isA(d)||n.isA(d)?a(B,d):d);return u.length===1?u[0]:u},c=(...B)=>g({axes:[!0,!1,!1]},B),I=(...B)=>g({axes:[!1,!0,!1]},B),l=(...B)=>g({axes:[!1,!1,!0]},B);A.exports={center:g,centerX:c,centerY:I,centerZ:l}}}),aO=at({"node_modules/@jscad/modeling/src/operations/transforms/scale.js"(e,A){var t=vo(),i=Ac(),n=ss(),o=ts(),s=Mg(),r=(I,...l)=>{if(!Array.isArray(I))throw new Error("factors must be an array");if(l=t(l),l.length===0)throw new Error("wrong number of arguments");for(I=I.slice();I.length<3;)I.push(1);if(I[0]<=0||I[1]<=0||I[2]<=0)throw new Error("factors must be positive");const B=i.fromScaling(i.create(),I),C=l.map(Q=>s.isA(Q)?s.transform(B,Q):n.isA(Q)?n.transform(B,Q):o.isA(Q)?o.transform(B,Q):Q);return C.length===1?C[0]:C},a=(I,...l)=>r([I,1,1],l),g=(I,...l)=>r([1,I,1],l),c=(I,...l)=>r([1,1,I],l);A.exports={scale:r,scaleX:a,scaleY:g,scaleZ:c}}}),obe=at({"node_modules/@jscad/modeling/src/operations/transforms/transform.js"(e,A){var t=vo(),i=ss(),n=ts(),o=Mg(),s=(r,...a)=>{if(a=t(a),a.length===0)throw new Error("wrong number of arguments");const g=a.map(c=>o.isA(c)?o.transform(r,c):i.isA(c)?i.transform(r,c):n.isA(c)?n.transform(r,c):c);return g.length===1?g[0]:g};A.exports=s}}),O4=at({"node_modules/@jscad/modeling/src/operations/transforms/index.js"(e,A){A.exports={align:nbe(),center:rO().center,centerX:rO().centerX,centerY:rO().centerY,centerZ:rO().centerZ,mirror:L8().mirror,mirrorX:L8().mirrorX,mirrorY:L8().mirrorY,mirrorZ:L8().mirrorZ,rotate:U8().rotate,rotateX:U8().rotateX,rotateY:U8().rotateY,rotateZ:U8().rotateZ,scale:aO().scale,scaleX:aO().scaleX,scaleY:aO().scaleY,scaleZ:aO().scaleZ,transform:obe(),translate:K4().translate,translateX:K4().translateX,translateY:K4().translateY,translateZ:K4().translateZ}}}),gO=at({"node_modules/@jscad/modeling/src/index.js"(e,A){A.exports={colors:tO(),curves:$2e(),geometries:NEA(),maths:wxe(),measurements:Fxe(),primitives:q4(),text:cSe(),utils:Htt(),booleans:J8(),expansions:qtt(),extrusions:T8(),hulls:VSe(),minkowski:jSe(),modifiers:ebe(),transforms:O4()}}}),Ztt=at({"node_modules/jscad-planner/dist/index.cjs"(e,A){var t=Object.defineProperty,i=Object.getOwnPropertyDescriptor,n=Object.getOwnPropertyNames,o=Object.prototype.hasOwnProperty,s=(l,B)=>{for(var C in B)t(l,C,{get:B[C],enumerable:!0})},r=(l,B,C,Q)=>{if(B&&typeof B=="object"||typeof B=="function")for(let h of n(B))!o.call(l,h)&&h!==C&&t(l,h,{get:()=>B[h],enumerable:!(Q=i(B,h))||Q.enumerable});return l},a=l=>r(t({},"__esModule",{value:!0}),l),g={};s(g,{executeJscadOperations:()=>I,jscadPlanner:()=>c}),A.exports=a(g);var c={booleans:{intersect:(...l)=>({type:"intersect",shapes:l}),subtract:(...l)=>({type:"subtract",shapes:l}),union:(...l)=>({type:"union",shapes:l})},hulls:{hull:(...l)=>({type:"hull",shapes:l.flat()}),hullChain:(...l)=>({type:"hullChain",shapes:l.flat()})},colors:{colorize:(l,B)=>({type:"colorize",color:l,shape:B})},primitives:{cube:l=>({type:"cube",...l}),sphere:l=>({type:"sphere",...l}),cylinder:l=>({type:"cylinder",...l}),polygon:l=>({type:"polygon",...l}),cuboid:l=>({type:"cuboid",...l}),roundedCuboid:l=>({type:"roundedCuboid",...l})},transforms:{rotate:(l,B)=>({type:"rotate",angles:l,shape:B}),scale:(l,B)=>({type:"scale",factors:l,shape:B}),translate:(l,B)=>({type:"translate",vector:l,shape:B})},extrusions:{extrudeLinear:(l,B)=>({type:"extrudeLinear",options:l,shape:B}),extrudeRotate:(l,B)=>({type:"extrudeRotate",options:l,shape:B})},maths:{vec2:{create:(l,B)=>[l,B],fromValues:(l,B)=>[l,B]},vec3:{create:(l,B,C)=>[l,B,C],fromValues:(l,B,C)=>[l,B,C]}},geometries:{geom2:{create:l=>({type:"createGeom2",points:l})},geom3:{create:l=>({type:"createGeom3",polygons:l})},path2:{create:l=>({type:"createPath2",points:l})}},measurements:{measureBoundingBox:l=>({type:"measureBoundingBox",shape:l}),measureArea:l=>({type:"measureArea",shape:l}),measureVolume:l=>({type:"measureVolume",shape:l})},utils:{degToRad:l=>l*Math.PI/180,radToDeg:l=>l*180/Math.PI}},I=(l,B)=>{if(Array.isArray(B)&&B.length===1)return I(l,B[0]);if(Array.isArray(B))throw new Error("executeJscadOperations currently doesn't support Array<JscadOperation>, try adding a root union or or executing each element individually");const C=E=>I(l,E),{type:Q,...h}=B;switch(Q){case"intersect":return l.booleans.intersect(...B.shapes.map(C));case"subtract":return l.booleans.subtract(...B.shapes.map(C));case"union":return l.booleans.union(...B.shapes.map(C));case"hull":return l.hulls.hull(...B.shapes.map(C));case"hullChain":return l.hulls.hullChain(...B.shapes.map(C));case"colorize":return l.colors.colorize(B.color,C(B.shape));case"cube":return l.primitives.cube(h);case"sphere":return l.primitives.sphere(h);case"cylinder":return l.primitives.cylinder(h);case"polygon":return l.primitives.polygon(h);case"cuboid":return l.primitives.cuboid(h);case"roundedCuboid":return l.primitives.roundedCuboid(h);case"rotate":return l.transforms.rotate(B.angles,C(B.shape));case"scale":return l.transforms.scale(B.factors,C(B.shape));case"translate":return l.transforms.translate(B.vector,C(B.shape));case"extrudeLinear":return l.extrusions.extrudeLinear(B.options,C(B.shape));case"extrudeRotate":return l.extrusions.extrudeRotate(B.options,C(B.shape));case"createGeom2":return l.geometries.geom2.create(B.points);case"createGeom3":return l.geometries.geom3.create(B.polygons);case"createPath2":return l.geometries.path2.create(B.points);case"measureBoundingBox":return l.measurements.measureBoundingBox(C(B.shape));case"measureArea":return l.measurements.measureArea(C(B.shape));case"measureVolume":return l.measurements.measureVolume(C(B.shape));case"degToRad":return l.utils.degToRad(B.degrees);case"radToDeg":return l.utils.radToDeg(B.radians);default:throw B.type===void 0?new Error(`Operation type is undefined. This usually means the operation object is malformed or not properly initialized. Operation: ${JSON.stringify(B,null,2).slice(0,200)}...`):new Error(`Unsupported operation type: ${B.type}. Operation: ${JSON.stringify(B,null,2)}`)}}}}),sbe=at({"node_modules/ms/index.js"(e,A){var t=1e3,i=t*60,n=i*60,o=n*24,s=o*7,r=o*365.25;A.exports=function(l,B){B=B||{};var C=typeof l;if(C==="string"&&l.length>0)return a(l);if(C==="number"&&isFinite(l))return B.long?c(l):g(l);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(l))};function a(l){if(l=String(l),!(l.length>100)){var B=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(l);if(B){var C=parseFloat(B[1]),Q=(B[2]||"ms").toLowerCase();switch(Q){case"years":case"year":case"yrs":case"yr":case"y":return C*r;case"weeks":case"week":case"w":return C*s;case"days":case"day":case"d":return C*o;case"hours":case"hour":case"hrs":case"hr":case"h":return C*n;case"minutes":case"minute":case"mins":case"min":case"m":return C*i;case"seconds":case"second":case"secs":case"sec":case"s":return C*t;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return C;default:return}}}}function g(l){var B=Math.abs(l);return B>=o?Math.round(l/o)+"d":B>=n?Math.round(l/n)+"h":B>=i?Math.round(l/i)+"m":B>=t?Math.round(l/t)+"s":l+"ms"}function c(l){var B=Math.abs(l);return B>=o?I(l,B,o,"day"):B>=n?I(l,B,n,"hour"):B>=i?I(l,B,i,"minute"):B>=t?I(l,B,t,"second"):l+" ms"}function I(l,B,C,Q){var h=B>=C*1.5;return Math.round(l/C)+" "+Q+(h?"s":"")}}}),rbe=at({"node_modules/debug/src/common.js"(e,A){function t(i){o.debug=o,o.default=o,o.coerce=I,o.disable=g,o.enable=r,o.enabled=c,o.humanize=sbe(),o.destroy=l,Object.keys(i).forEach(B=>{o[B]=i[B]}),o.names=[],o.skips=[],o.formatters={};function n(B){let C=0;for(let Q=0;Q<B.length;Q++)C=(C<<5)-C+B.charCodeAt(Q),C|=0;return o.colors[Math.abs(C)%o.colors.length]}o.selectColor=n;function o(B){let C,Q=null,h,E;function u(...d){if(!u.enabled)return;const f=u,m=Number(new Date),w=m-(C||m);f.diff=w,f.prev=C,f.curr=m,C=m,d[0]=o.coerce(d[0]),typeof d[0]!="string"&&d.unshift("%O");let D=0;d[0]=d[0].replace(/%([a-zA-Z%])/g,(_,b)=>{if(_==="%%")return"%";D++;const R=o.formatters[b];if(typeof R=="function"){const F=d[D];_=R.call(f,F),d.splice(D,1),D--}return _}),o.formatArgs.call(f,d),(f.log||o.log).apply(f,d)}return u.namespace=B,u.useColors=o.useColors(),u.color=o.selectColor(B),u.extend=s,u.destroy=o.destroy,Object.defineProperty(u,"enabled",{enumerable:!0,configurable:!1,get:()=>Q!==null?Q:(h!==o.namespaces&&(h=o.namespaces,E=o.enabled(B)),E),set:d=>{Q=d}}),typeof o.init=="function"&&o.init(u),u}function s(B,C){const Q=o(this.namespace+(typeof C>"u"?":":C)+B);return Q.log=this.log,Q}function r(B){o.save(B),o.namespaces=B,o.names=[],o.skips=[];const C=(typeof B=="string"?B:"").trim().replace(/\s+/g,",").split(",").filter(Boolean);for(const Q of C)Q[0]==="-"?o.skips.push(Q.slice(1)):o.names.push(Q)}function a(B,C){let Q=0,h=0,E=-1,u=0;for(;Q<B.length;)if(h<C.length&&(C[h]===B[Q]||C[h]==="*"))C[h]==="*"?(E=h,u=Q,h++):(Q++,h++);else if(E!==-1)h=E+1,u++,Q=u;else return!1;for(;h<C.length&&C[h]==="*";)h++;return h===C.length}function g(){const B=[...o.names,...o.skips.map(C=>"-"+C)].join(",");return o.enable(""),B}function c(B){for(const C of o.skips)if(a(B,C))return!1;for(const C of o.names)if(a(B,C))return!0;return!1}function I(B){return B instanceof Error?B.stack||B.message:B}function l(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return o.enable(o.load()),o}A.exports=t}}),abe=at({"node_modules/debug/src/browser.js"(e,A){e.formatArgs=i,e.save=n,e.load=o,e.useColors=t,e.storage=s(),e.destroy=(()=>{let a=!1;return()=>{a||(a=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),e.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"];function t(){if(typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs))return!0;if(typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))return!1;let a;return typeof document<"u"&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent&&(a=navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/))&&parseInt(a[1],10)>=31||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)}function i(a){if(a[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+a[0]+(this.useColors?"%c ":" ")+"+"+A.exports.humanize(this.diff),!this.useColors)return;const g="color: "+this.color;a.splice(1,0,g,"color: inherit");let c=0,I=0;a[0].replace(/%[a-zA-Z%]/g,l=>{l!=="%%"&&(c++,l==="%c"&&(I=c))}),a.splice(I,0,g)}e.log=console.debug||console.log||(()=>{});function n(a){try{a?e.storage.setItem("debug",a):e.storage.removeItem("debug")}catch{}}function o(){let a;try{a=e.storage.getItem("debug")||e.storage.getItem("DEBUG")}catch{}return!a&&typeof xEA<"u"&&"env"in xEA&&(a=xEA.env.DEBUG),a}function s(){try{return localStorage}catch{}}A.exports=rbe()(e);var{formatters:r}=A.exports;r.j=function(a){try{return JSON.stringify(a)}catch(g){return"[UnexpectedJSONParseError]: "+g.message}}}}),Vtt={boardBody:!0,topCopper:!0,bottomCopper:!0,adhesive:!1,solderPaste:!1,topSilkscreen:!0,bottomSilkscreen:!0,topMask:!0,bottomMask:!0,throughHoleModels:!0,smtModels:!0,translucentModels:!0,modelsNotInPosFile:!1,modelsMarkedDNP:!1,modelBoundingBoxes:!1,threedAxis:!1,pcbNotes:!1,backgroundStart:!0,backgroundEnd:!0},jtt=AA.createContext(void 0),gbe=({children:e})=>{const[A,t]=AA.useState(Vtt),i=AA.useCallback((s,r)=>{t(a=>({...a,[s]:r}))},[]),n=AA.useCallback(()=>{t(Vtt)},[]),o=AA.useMemo(()=>({visibility:A,setLayerVisibility:i,resetToDefaults:n}),[A,i,n]);return Z.jsx(jtt.Provider,{value:o,children:e})},W4=()=>{const e=AA.useContext(jtt);if(!e)throw new Error("useLayerVisibility must be used within a LayerVisibilityProvider");return e},tuA=1.2;function ztt(e){return AA.useMemo(()=>{if(!e)return tuA;try{return yn(e).pcb_board.list()[0]?.thickness??tuA}catch{return tuA}},[e])}var Xtt=AA.createContext(null),od=()=>{const e=AA.useContext(Xtt);if(!e)throw new Error("useThree must be used within a ThreeProvider");return e},P8=(e,A=[])=>{const{addFrameListener:t,removeFrameListener:i}=od();Qn.useEffect(()=>(t(e),()=>i(e)),[t,i,...A])},K8={clickToInteractOverlay:100,htmlElements:95,orientationCube:95,contextMenu:90,appearanceMenu:91},$tt=({children:e,position:A,style:t})=>{const{camera:i,renderer:n}=od(),o=AA.useRef(document.createElement("div")),[s,r]=AA.useState(null);return AA.useEffect(()=>{const a=n?.domElement.parentNode;if(a)return a.style.position!=="relative"&&a.style.position!=="absolute"&&(a.style.position="relative"),a.appendChild(o.current),r(TU.createPortal(e,o.current)),()=>{a.contains(o.current)&&a.removeChild(o.current)}},[n,e]),P8(()=>{if(!i||!o.current||!n)return;const a=new Mt(...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=K8.htmlElements.toString(),t&&Object.assign(o.current.style,t)},[i,n,A,t]),s},Aet={in:25.4,inch:25.4,mil:.0254,mm:1,m:1e3,cm:10,ft:304.8,feet:304.8},cr=e=>{let A=typeof e=="number"?"mm":e.replace(/^[^a-zA-Z]+/g,"").toLowerCase();A||(A="mm");const t=typeof e=="number"?e:Number.parseFloat(e.split(A)[0]);if(A in Aet)return t*Aet[A];throw new Error(`Unsupported unit: ${A}`)},Kl=cr,cbe=Object.defineProperty,Ibe=(e,A)=>{for(var t in A)cbe(e,t,{get:A[t],enumerable:!0})},R2={};Ibe(R2,{axial:()=>R_e,bga:()=>Pbe,breakoutheaders:()=>Z_e,cap:()=>ube,dfn:()=>E_e,diode:()=>Ebe,dip:()=>Cbe,electrolytic:()=>N5e,hc49:()=>j_e,jst:()=>A5e,led:()=>dbe,lqfp:()=>O_e,m2host:()=>ike,melf:()=>g3e,micromelf:()=>B3e,minimelf:()=>t3e,mlp:()=>Xbe,mountedpcbmodule:()=>oke,ms012:()=>m_e,ms013:()=>D_e,msop:()=>c5e,pad:()=>z_e,pinrow:()=>d_e,platedhole:()=>Z5e,potentiometer:()=>M5e,pushbutton:()=>Y_e,qfn:()=>Vbe,qfp:()=>zbe,quad:()=>QF,radial:()=>U_e,res:()=>Ybe,sma:()=>E3e,smb:()=>D3e,smbf:()=>U5e,smc:()=>_3e,smf:()=>f3e,smtpad:()=>O5e,sod110:()=>e5e,sod123:()=>v_e,sod123f:()=>F4e,sod123fl:()=>N4e,sod123w:()=>l4e,sod128:()=>K4e,sod323:()=>h4e,sod323f:()=>b4e,sod323fl:()=>h5e,sod323w:()=>l5e,sod523:()=>e4e,sod723:()=>Y4e,sod80:()=>a4e,sod882:()=>w4e,sod882d:()=>o3e,sod923:()=>p4e,soic:()=>qbe,solderjumper:()=>D5e,son:()=>p5e,sop8:()=>s4e,sot:()=>j5e,sot223:()=>M3e,sot23:()=>c_e,sot23w:()=>T3e,sot25:()=>C_e,sot323:()=>T5e,sot343:()=>$5e,sot363:()=>s_e,sot457:()=>b5e,sot563:()=>f_e,sot723:()=>S_e,sot886:()=>a_e,sot89:()=>j4e,sot963:()=>k5e,ssop:()=>t_e,stampboard:()=>T_e,stampreceiver:()=>q_e,to220:()=>det,to220f:()=>$4e,to92:()=>A4e,to92l:()=>rke,to92s:()=>Z3e,tqfp:()=>jbe,tssop:()=>n_e,vson:()=>y5e,vssop:()=>r5e});var Ui=(e,A,t)=>({type:"pcb_silkscreen_text",pcb_silkscreen_text_id:"silkscreen_text_1",font:"tscircuit2024",font_size:t,pcb_component_id:"pcb_component_1",text:"{REF}",layer:"top",anchor_position:{x:e,y:A},anchor_alignment:"center"}),Gi=At({norefdes:HA().optional().describe("disable reference designator label"),invert:HA().optional().describe("hint to invert the orientation of the 3D model"),faceup:HA().optional().describe("The male pin header should face upwards, out of the top layer"),nosilkscreen:HA().optional().describe("omit all silkscreen elements from the footprint")}),Fo=(e,A,t,i,n)=>({pcb_plated_hole_id:"",type:"pcb_plated_hole",shape:"circle",x:A,y:t,hole_diameter:cr(i),outer_diameter:cr(n),pcb_port_id:"",layers:["top","bottom"],port_hints:[e.toString()]}),lm=e=>{const{pn:A,x:t,y:i,holeDiameter:n,rectPadWidth:o,rectPadHeight:s,holeOffsetX:r=0,holeOffsetY:a=0,rectBorderRadius:g}=e;return{pcb_plated_hole_id:"",type:"pcb_plated_hole",shape:"circular_hole_with_rect_pad",x:t,y:i,hole_diameter:cr(n),hole_shape:"circle",pad_shape:"rect",rect_pad_width:cr(o),rect_pad_height:cr(s),...g!==void 0&&{rect_border_radius:g},pcb_port_id:"",layers:["top","bottom"],port_hints:[A.toString()],hole_offset_x:r,hole_offset_y:a}},cO=Array.from({length:9},(e,A)=>Math.cos(A/8*Math.PI-Math.PI)).map(e=>({x:e,y:-Math.sqrt(1-e**2)}));function rb(e){return typeof e=="string"?e.trim().toLowerCase().endsWith("mil")?parseFloat(e)*.0254:parseFloat(e):Number(e)}var IO=_e([L(),qA()]).transform(e=>rb(e)),lbe=e=>Gi.extend({fn:L(),num_pins:qA().optional().default(6),wide:HA().optional(),narrow:HA().optional(),w:IO.optional(),p:IO.default(e.p??"2.54mm"),id:IO.optional(),od:IO.optional(),nosquareplating:HA().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=rb("0.55mm"),A.od=rb("0.95mm")):(A.id=rb("0.8mm"),A.od=rb("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=rb("600mil"):A.narrow?A.w=rb("300mil"):A.w=rb(e.w??"300mil")),A)),Bbe=lbe({}),tet=(e,A,t,i,n)=>{const o=e/2,s=A<=o,r=o-1,a=i,g=a*r;return s?{x:-t/2,y:g/2-(A-1)*a}:{x:t/2,y:-g/2+(A-o-1)*a}},Cbe=e=>{const A=Bbe.parse(e),t=[];for(let g=0;g<A.num_pins;g++){const{x:c,y:I}=tet(A.num_pins,g+1,A.w,A.p??2.54,A.nosquareplating);if(g===0&&!A.nosquareplating){t.push(lm({pn:g+1,x:c,y:I,holeDiameter:A.id??"0.8mm",rectPadWidth:A.od??"1mm",rectPadHeight:A.od??"1mm"}));continue}t.push(Fo(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},...cO.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}=tet(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=Ui(0,o/2+.5,.4);return{circuitJson:[...t,s,a,...r],parameters:A}},li=(e,A,t,i,n)=>({type:"pcb_smtpad",x:A,y:t,width:i,height:n,layer:"top",shape:"rect",pcb_smtpad_id:"",port_hints:Array.isArray(e)?e.map(o=>o.toString()):[e.toString()]}),eet=[{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}],Qbe=Object.fromEntries(eet.map(e=>[e.metric,e])),hbe=Object.fromEntries(eet.map(e=>[e.imperial,e]));Gi.extend({tht:HA(),p:cA.optional(),pw:cA.optional(),ph:cA.optional(),metric:st.optional(),imperial:st.optional(),w:cA.optional(),h:cA.optional(),textbottom:HA().optional()});var lO=e=>{let{tht:A,p:t,pw:i,ph:n,metric:o,imperial:s,w:r,h:a,textbottom:g}=e;if(typeof r=="string"&&(r=Kl(r)),typeof a=="string"&&(a=Kl(a)),typeof t=="string"&&(t=Kl(t)),typeof i=="string"&&(i=Kl(i)),typeof n=="string"&&(n=Kl(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=Qbe[o]),s&&(c=hbe[s]),c&&(r=c.w_mm_min,a=c.h_mm_min,t=c.p_mm_min,i=c.pw_mm_min,n=c.ph_mm_min),t===void 0||i===void 0||n===void 0)throw new Error("Could not determine required pad dimensions (p, pw, ph)");const I={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:t/2,y:n/2+.4},{x:-t/2-i/2-.2,y:n/2+.4},{x:-t/2-i/2-.2,y:-n/2-.4},{x:t/2,y:-n/2-.4}],stroke_width:.1,pcb_silkscreen_path_id:""},l=g?-n/2-.9:n/2+.9,B=Ui(0,l,.2),C=.25,Q=I.route.map(w=>w.x),h=I.route.map(w=>w.y),E=Math.min(-(r??0)/2,-(t/2+i/2),...Q)-C,u=Math.max((r??0)/2,t/2+i/2,...Q)+C,d=Math.min(-(a??0)/2,-n/2,...h)-C,f=Math.max((a??0)/2,n/2,...h)+C,m={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:(E+u)/2,y:(d+f)/2},width:u-E,height:f-d,layer:"top"};return A?[Fo(1,-t/2,0,i,i*1/.8),Fo(2,t/2,0,i,i*1/.8),I,B,m]:[li(["1","left"],-t/2,0,i,n),li(["2","right"],t/2,0,i,n),I,B,m]},Ebe=e=>({circuitJson:lO(e),parameters:e}),ube=e=>({circuitJson:lO(e),parameters:e}),dbe=e=>({circuitJson:lO(e),parameters:e}),CF=e=>{const{padSpacing:A,padWidth:t,padHeight:i,padPitch:n,numRows:o,textbottom:s}=e,r=[],a=(o-1)*(n/2);for(let x=0;x<o;x++)r.push(a-x*n);const g=[];r.forEach((x,_)=>{g.push(li(_+1,-A/2,x,t,i))}),r.slice().reverse().forEach((x,_)=>{g.push(li(_+o+1,A/2,x,t,i))});const c=Math.max(...r)+i/2+.4,I=Math.min(...r)-i/2-.4,l=-A/2-t/2-.4,B=A/2+t/2+.4,C={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:B*.5,y:c},{x:l*.5,y:c}],stroke_width:.12,pcb_silkscreen_path_id:"silkscreen_top"},Q={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:B*.5,y:I},{x:l*.5,y:I}],stroke_width:.12,pcb_silkscreen_path_id:"silkscreen_bottom"},h=-A/2,E=Math.max(...r),u=.2,d=h-t/2-.1,f=E+i/2+.1,m={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"pin1_marker",route:[{x:d,y:f},{x:d-u,y:f},{x:d,y:f+u},{x:d,y:f}],stroke_width:.1},w=s?I-.9:c+.9,D=Ui(0,w,.2);return[...g,C,Q,m,D]},pbe=Gi.extend({pw:cA.default("0.5mm"),ph:cA.default("0.4mm"),p:cA.default("0.7mm"),textbottom:HA().optional(),convex:HA().optional(),concave:HA().optional()}),fbe=1,ybe=e=>{const A=pbe.parse(e);if(A.concave===!0)return[];const t=Kl(A.pw),i=Kl(A.ph),n=Kl(A.p);return CF({padSpacing:fbe,padWidth:t,padHeight:i,padPitch:n,numRows:2,textbottom:A.textbottom,convex:A.convex,concave:A.concave})},mbe=Gi.extend({pw:cA.default("0.5mm"),ph:cA.default("0.32mm"),p:cA.default("0.5mm"),textbottom:HA().optional(),convex:HA().optional(),concave:HA().optional()}),wbe=1,Dbe=e=>{const A=mbe.parse(e),t=Kl(A.pw),i=Kl(A.ph),n=Kl(A.p);return CF({padSpacing:wbe,padWidth:t,padHeight:i,padPitch:n,numRows:4,textbottom:A.textbottom,convex:A.convex,concave:A.concave})},xbe=Gi.extend({pw:cA.default("0.9mm"),ph:cA.default("0.4mm"),p:cA.default("0.8mm"),textbottom:HA().optional(),convex:HA().optional(),concave:HA().optional()}),Sbe=1.7,bbe=e=>{const A=xbe.parse(e),t=Kl(A.pw),i=Kl(A.ph),n=Kl(A.p);return CF({padSpacing:Sbe,padWidth:t,padHeight:i,padPitch:n,numRows:2,textbottom:A.textbottom,convex:A.convex,concave:A.concave})},_be=Gi.extend({pw:cA.default("0.9mm"),ph:cA.default("0.4mm"),p:cA.default("0.8mm"),textbottom:HA().optional(),convex:HA().optional(),concave:HA().optional()}),kbe=1.7,vbe=e=>{const A=_be.parse(e),t=Kl(A.pw),i=Kl(A.ph),n=Kl(A.p);return CF({padSpacing:kbe,padWidth:t,padHeight:i,padPitch:n,numRows:4,textbottom:A.textbottom,convex:A.convex,concave:A.concave})},Fbe=Gi.extend({pw:cA.default("0.7mm"),ph:cA.default("0.64mm"),p:cA.default("0.94mm"),textbottom:HA().optional(),convex:HA().optional(),concave:HA().optional()}),Mbe=1.4,Gbe=e=>{const A=Fbe.parse(e),t=Kl(A.pw),i=Kl(A.ph),n=Kl(A.p);return CF({padSpacing:Mbe,padWidth:t,padHeight:i,padPitch:n,numRows:2,textbottom:A.textbottom,convex:A.convex,concave:A.concave})},Rbe=Gi.extend({pw:cA.default("0.9mm"),ph:cA.default("0.9mm"),p:cA.default("1.34mm"),textbottom:HA().optional(),convex:HA().optional(),concave:HA().optional()}),Nbe=3,Lbe=e=>{const A=Rbe.parse(e),t=Kl(A.pw),i=Kl(A.ph),n=Kl(A.p);return CF({padSpacing:Nbe,padWidth:t,padHeight:i,padPitch:n,numRows:4,textbottom:A.textbottom,convex:A.convex,concave:A.concave})},Ube=e=>{const A=e.array??e.x;if(typeof A=="number")return Number.isNaN(A)?void 0:A;if(typeof A=="string"){const t=Number.parseInt(A,10);return Number.isNaN(t)?void 0:t}if(typeof e.imperial=="string"){const i=e.imperial.match(/x(2|4)$/)?.[1];if(i)return Number.parseInt(i,10)}},Hbe=e=>e?(typeof e=="number"?`${e}`:e).split(/[_x]/)[0]:void 0,Ybe=e=>{const A=Ube(e),t=Hbe(e.imperial);return A===2&&t==="0402"?{circuitJson:ybe(e),parameters:e}:A===4&&t==="0402"?{circuitJson:Dbe(e),parameters:e}:A===2&&t==="0603"?{circuitJson:bbe(e),parameters:e}:A===4&&t==="0603"?{circuitJson:vbe(e),parameters:e}:A===2&&t==="0606"?{circuitJson:Gbe(e),parameters:e}:A===4&&t==="1206"?{circuitJson:Lbe(e),parameters:e}:{circuitJson:lO(e),parameters:e}},iet=(e,{x:A,y:t,radius:i})=>({type:"pcb_smtpad",x:A,y:t,radius:i,layer:"top",shape:"circle",pcb_smtpad_id:"",port_hints:Array.isArray(e)?e.map(n=>n.toString()):[e.toString()]}),net="ABCDEFGHIJKLMNOPQRSTUVWXYZ",BO=L().transform(e=>{const[A,t]=e.split(/[x ]/);return{x:parseFloat(A??""),y:parseFloat(t??"")}}).pipe(At({x:qA(),y:qA()})),Jbe=L().or(xt(tI())).transform(e=>Array.isArray(e)?e:(e.startsWith("(")&&e.endsWith(")")&&(e=e.slice(1,-1)),e.split(",").map(A=>{const t=Number(A);return isNaN(t)?A:t}))).pipe(xt(L().or(qA()))),Tbe=Gi.extend({fn:L(),num_pins:qA().optional().default(64),grid:BO.optional(),p:st.default("0.8mm"),w:cA.optional(),h:cA.optional(),ball:cA.optional().describe("ball diameter"),pad:cA.optional().describe("pad width/height"),circularpads:HA().optional().describe("use circular pads"),tlorigin:HA().optional(),blorigin:HA().optional(),trorigin:HA().optional(),brorigin:HA().optional(),missing:Jbe.default([])}).transform(e=>{let A="tl";if(e.blorigin&&(A="bl"),e.trorigin&&(A="tr"),e.brorigin&&(A="br"),!e.grid){const i=Math.ceil(Math.sqrt(e.num_pins));e.grid={x:i,y:i}}return e.missing&&(e.missing=e.missing.map(i=>{if(typeof i=="number")return i;if(i==="center")return"center";if(i==="topleft")return"topleft";const n=i.match(/([A-Z]+)(\d+)/);if(!n)return i;const o=net.indexOf(n[1]),s=Number.parseInt(n[2])-1;return o*e.grid.x+s+1})),{...e,origin:A}}),Pbe=e=>{const A=Tbe.parse(e);let{num_pins:t,grid:i,p:n,w:o,h:s,ball:r,pad:a,missing:g}=A;r??=.75/1.27*n,a??=r*.8;const c=[],I=(g??[]).filter(m=>typeof m=="number"),l=i.x*i.y-t;if(g.length===0&&l>0&&(Math.sqrt(l)%1===0?g.push("center"):l===1&&g.push("topleft")),g?.includes("center")){const m=Math.floor(Math.sqrt(l)),w=Math.floor((i.x-m)/2),D=Math.floor((i.y-m)/2);for(let x=D;x<D+m;x++)for(let _=w;_<w+m;_++)I.push(x*i.x+_+1)}g?.includes("topleft")&&I.push(1);const B=new Set(I);let C=0;for(let m=0;m<i.y;m++)for(let w=0;w<i.x;w++){const D=(w-(i.x-1)/2)*n,x=(m-(i.y-1)/2)*n;let _=w,b=m;switch(A.origin){case"bl":_=w,b=i.y-1-m;break;case"br":_=i.x-1-w,b=i.y-1-m;break;case"tr":_=i.x-1-w,b=m;break}let R=b*i.x+_+1;if(B.has(R)){C++;continue}R-=C;const F=[R,`${net[b]}${_+1}`];c.push(A.circularpads?iet(F,{x:D,y:x,radius:a/2}):li(F,D,x,a,a))}const Q=Ui(0,i.y*n/2,.2),h=n/6;let E;const u=i.x*n/2,d=i.y*n/2;switch(A.origin){case"bl":E=[{x:-u,y:-d},{x:-u,y:-d-h},{x:-u-h,y:-d},{x:-u,y:-d}];break;case"br":E=[{x:u,y:-d},{x:u,y:-d-h},{x:u+h,y:-d},{x:u,y:-d}];break;case"tr":E=[{x:u,y:d},{x:u,y:d+h},{x:u+h,y:d},{x:u,y:d}];break;default:E=[{x:-u,y:d},{x:-u,y:d+h},{x:-u-h,y:d},{x:-u,y:d}];break}const f={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"pin1_marker",route:E,stroke_width:.05};return{circuitJson:[...c,Q,f],parameters:A}},CO=(e,A,t,i,n)=>({type:"pcb_smtpad",x:A,y:t,width:i,height:n,radius:n/2,layer:"top",shape:"pill",pcb_smtpad_id:"",port_hints:Array.isArray(e)?e.map(o=>o.toString()):[e.toString()]}),Z4=e=>Gi.extend({fn:L(),num_pins:qA().optional().default(8),w:cA.default(cA.parse(e.w??"5.3mm")),p:cA.default(cA.parse(e.p??"1.27mm")),pw:cA.default(cA.parse(e.pw??"0.6mm")),pl:cA.default(cA.parse(e.pl??"1.0mm")),legsoutside:HA().optional().default(e.legsoutside??!1),pillpads:HA().optional().default(e.pillpads??!1),silkscreen_stroke_width:qA().optional().default(.1)}).transform(A=>(!A.pw&&!A.pl?(A.pw=cA.parse("0.6mm"),A.pl=cA.parse("1.0mm")):A.pw?A.pl||(A.pl=A.pw*(1/.6)):A.pw=A.pl*(.6/1),A)),Kbe=Z4({}),euA=e=>{e.widthincludeslegs!==void 0&&(e.legsoutside=!e.widthincludeslegs);const{num_pins:A,pn:t,w:i,p:n,pl:o,legsoutside:s}=e,r=A/2,a=t<=r,g=r-1,c=n,I=c*g,l=s?o/2:-o/2;return a?{x:-i/2-l,y:I/2-(t-1)*c}:{x:i/2+l,y:-I/2+(t-r-1)*c}},qbe=e=>{const A=Kbe.parse(e);return{circuitJson:q8(A),parameters:A}},q8=e=>{const A=[];for(let r=0;r<e.num_pins;r++){const{x:a,y:g}=euA({num_pins:e.num_pins,pn:r+1,w:e.w,p:e.p,pl:e.pl,legsoutside:e.legsoutside});e.pillpads?A.push(CO(r+1,a,g,e.pl,e.pw)):A.push(li(r+1,a,g,e.pl,e.pw))}const t=Math.min(1,e.p/2),i=e.w-(e.legsoutside?0:e.pl*2)-.2,n=(e.num_pins/2-1)*e.p+e.pw+t,o=Ui(0,n/2+.4,n/12),s={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",stroke_width:e.silkscreen_stroke_width??.1,route:[{x:-i/2,y:-n/2},{x:-i/2,y:n/2},...cO.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]},oet=Vt(["leftside","topside","rightside","bottomside","toppin","bottompin","leftpin","rightpin"]),Obe=({num_pins:e,cw:A,ccw:t,startingpin:i})=>{const n=[],o=e/4;let s=1;const r={};for(const a of i??[])r[a]=!0;!r.leftside&&!r.topside&&!r.rightside&&!r.bottomside&&(r.leftside=!0),!r.bottompin&&!r.leftpin&&!r.rightpin&&!r.toppin&&(r.leftside?r.toppin=!0:r.topside?r.rightpin=!0:r.rightside?r.bottompin=!0:r.bottomside&&(r.leftpin=!0)),r.leftside&&r.toppin?s=1:r.leftside&&r.bottompin?s=o:r.bottomside&&r.leftpin?s=o+1:r.bottomside&&r.rightpin?s=o*2:r.rightside&&r.bottompin?s=o*2+1:r.rightside&&r.toppin?s=o*3:r.topside&&r.rightpin?s=o*3+1:r.topside&&r.leftpin&&(s=o*4),n.push(-1);for(let a=0;a<e;a++)n[s]=a+1,t||!A?(s++,s>e&&(s=1)):(s--,s<1&&(s=e));return n},iuA=Gi.extend({fn:L(),cc:HA().default(!0).optional(),ccw:HA().default(!0).optional(),startingpin:L().or(xt(oet)).transform(e=>typeof e=="string"?e.slice(1,-1).split(","):e).pipe(xt(oet)).optional(),num_pins:qA().optional().default(64),w:cA.optional(),h:cA.optional(),p:cA.default(cA.parse("0.5mm")),pw:cA.optional(),pl:cA.optional(),thermalpad:_e([SA(!0),BO]).optional(),legsoutside:HA().default(!1)}),nuA=e=>{e.w&&!e.h?e.h=e.w:!e.w&&e.h&&(e.w=e.h);const A=e.num_pins/4;if(!e.p&&!e.pw&&!e.pl&&e.w){const t=A+4;e.p=e.w/t}return!e.p&&e.w&&e.h&&e.pw&&e.pl&&(e.p=(e.w-e.pl*2)/(A-1)),!e.w&&!e.h&&e.p&&(e.w=e.p*(A+4),e.h=e.w),e.p&&!e.pw&&!e.pl?(e.pw=e.p/2,e.pl=e.p/2):e.pw?e.pl||(e.pl=e.pw*(1/.6)):e.pw=e.pl*(.6/1),e},set=iuA.transform(nuA),Wbe=["left","bottom","right","top"],Zbe=e=>{const{pin_count:A,pn:t,w:i,h:n,p:o,pl:s,legsoutside:r}=e,a=A/4,g=Wbe[Math.floor((t-1)/a)],c=(t-1)%a,I=o*(a-1),l=o*(a-1),B=r?s/2:-s/2;switch(g){case"left":return{x:-i/2-B+.1,y:l/2-c*o,o:"vert"};case"bottom":return{x:-I/2+c*o,y:-n/2-B+.1,o:"horz"};case"right":return{x:i/2+B-.1,y:-l/2+c*o,o:"vert"};case"top":return{x:I/2-c*o,y:n/2+B-.1,o:"horz"};default:throw new Error("Invalid pin number")}},QF=e=>{const A=set.parse(e),t=[],i=Obe(A),n=A.num_pins/4;for(let r=0;r<A.num_pins;r++){const{x:a,y:g,o:c}=Zbe({pin_count:A.num_pins,pn:r+1,w:A.w,h:A.h,p:A.p??.5,pl:A.pl,legsoutside:A.legsoutside});let I=A.pw,l=A.pl;c==="vert"&&([I,l]=[l,I]);const B=i[r+1];t.push(li(B,a,g,I,l))}if(A.thermalpad)if(typeof A.thermalpad=="boolean"){const r=A.p*(n-1)+A.pw,a=A.p*(n-1)+A.pw;t.push(li(["thermalpad"],0,0,r,a))}else t.push(li(["thermalpad"],0,0,A.thermalpad.x,A.thermalpad.y));const o=[];for(const[r,a,g]of[["top-left",-1,1],["bottom-left",-1,-1],["bottom-right",1,-1],["top-right",1,1]]){const c=A.w/2*a,I=A.h/2*g;let l="none",B=c,C=I;const Q=A.pw*2;i[1]===1&&r==="top-left"?l="in1":i[n*4]===1&&r==="top-left"||i[n*3+1]===1&&r==="top-right"?l="in2":i[n*3]===1&&r==="top-right"||i[n]===1&&r==="bottom-left"?l="in1":i[n+1]===1&&r==="bottom-left"?l="in2":i[n*2]===1&&r==="bottom-right"?l="in1":i[n*2+1]===1&&r==="bottom-right"&&(l="in2");const h=l==="in1"?1:-1;if(A.legsoutside){const E=l==="in1"?A.pl/2:A.pw/2,u=l==="in1"?A.pw/2:A.pl/2;B+=E*a*h,C-=u*g*h}(l==="none"||A.legsoutside)&&o.push({layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:`pcb_silkscreen_path_${r}`,route:[{x:c-Q*a,y:I},{x:c,y:I},{x:c,y:I-Q*g}],type:"pcb_silkscreen_path",stroke_width:.1}),(l==="in1"||l==="in2")&&!A.legsoutside&&o.push({layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:`pcb_silkscreen_path_${r}_1`,route:[{x:c-Q*a,y:I},{x:c-Q*a/2,y:I}],type:"pcb_silkscreen_path",stroke_width:0},{layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:`pcb_silkscreen_path_${r}_2`,route:[{x:c,y:I-Q*g/2},{x:c,y:I-Q*g}],type:"pcb_silkscreen_path",stroke_width:.1}),(l==="in1"||l==="in2")&&o.push({layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:`pcb_silkscreen_path_${r}_3`,route:[{x:B-.2*-a,y:C+.2*h},{x:B,y:C},{x:B+.2*h*-a,y:C+.2},{x:B-.2*-a,y:C+.2*h}],type:"pcb_silkscreen_path",stroke_width:.1})}const s=Ui(0,A.h/2+(A.legsoutside?A.pl*1.2:.5),.3);return{circuitJson:[...t,...o,s],parameters:A}};iuA.extend({}).transform(nuA);var Vbe=e=>(e.legsoutside=!1,e.pl||(e.pl=.875),e.pw||(e.pw=.25),QF(e)),jbe=e=>{if(e.legsoutside=!0,!e.p)switch(e.num_pins){case 32:e.p=.8;break;case 44:case 48:e.p=.5;break;case 64:case 80:case 100:e.p=.5;break;case 144:e.p=.5;break}if(!e.pl)switch(e.num_pins){case 32:case 44:case 48:case 64:case 80:case 100:e.pl=1.475;break;case 144:e.pl=1.6;break}if(!e.pw)switch(e.num_pins){case 32:e.pw=.55;break;case 44:case 48:case 64:case 80:case 100:e.pw=.3;break;case 144:e.pw=.25;break}return QF(e)},zbe=e=>{e.legsoutside=!0;const A=set.parse(e);if(!e.p)switch(e.num_pins){case 44:case 64:e.p=.8;break;case 52:e.w===14?e.p=1:e.p=.65;break;case 208:e.p=.5;break}if(!e.pl)switch(e.num_pins){case 44:case 52:case 64:e.pl=2.25;break;case 208:e.pl=1.65;break;default:e.pl=A.pl*4;break}if(!e.pw)switch(e.num_pins){case 44:case 64:e.pw=.5;break;case 52:e.w===14?e.pw=.45:e.pw=.55;break;case 208:e.pw=.3;break;default:e.pw=A.pw;break}return QF(e)};iuA.extend({}).transform(nuA);var Xbe=e=>(e.legsoutside=!1,e.thermalpad===void 0&&(e.thermalpad=!0),QF(e)),$be=Gi.extend({fn:L(),num_pins:qA().optional().default(8),w:cA.default(cA.parse("3.9mm")),p:cA.default(cA.parse("1.27mm")),pw:cA.optional(),pl:cA.optional(),legsoutside:HA().optional().default(!1),silkscreen_stroke_width:qA().optional().default(.1)}).transform(e=>(e.pw==null&&e.pl==null?(e.pw=cA.parse("0.51mm"),e.pl=cA.parse("1.1mm")):e.pw==null?e.pw=e.pl*(.51/1.1):e.pl==null&&(e.pl=e.pw*(1.1/.51)),e)),A_e=e=>{const{num_pins:A,pn:t,w:i,p:n}=e,o=A/2,s=t<=o,r=o-1,a=n,g=a*r,c=i+cA.parse("0.2mm"),I=(s?-1:1)*(c/2);return s?{x:I,y:g/2-(t-1)*a}:{x:I,y:-g/2+(t-o-1)*a}},t_e=e=>{const A=$be.parse(e),t=[];for(let a=0;a<A.num_pins;a++){const{x:g,y:c}=A_e({num_pins:A.num_pins,pn:a+1,w:A.w,p:A.p,pl:A.pl,legsoutside:A.legsoutside});t.push(li(a+1,g,c,A.pl,A.pw))}const i=Math.min(1,A.p/2),n=A.w-(A.legsoutside?0:A.pl)-.2,o=(A.num_pins/2-1)*A.p+A.pw+i,s=Ui(0,o/2+.4,o/12),r={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",stroke_width:A.silkscreen_stroke_width??.1,route:[{x:-n/2,y:-o/2},{x:-n/2,y:o/2},...cO.map(({x:a,y:g})=>({x:a*n/6,y:g*n/6+o/2})),{x:n/2,y:o/2},{x:n/2,y:-o/2},{x:-n/2,y:-o/2}]};return{circuitJson:[...t,r,s],parameters:A}},e_e=Gi.extend({fn:L(),num_pins:qA().optional().default(8),w:cA.default(cA.parse("3.0mm")),p:cA.default(cA.parse("0.5mm")),pw:cA.default(cA.parse("0.30mm")),pl:cA.default(cA.parse("1.45mm")),legsoutside:HA().optional().default(!0),silkscreen_stroke_width:qA().optional().default(.1)}),i_e=e=>{const{num_pins:A,pn:t,w:i,p:n,pl:o,legsoutside:s}=e,r=A/2,a=t<=r,g=r-1,c=n*g,I=s?o/2:-o/2;return a?{x:-i/2-I,y:c/2-(t-1)*n}:{x:i/2+I,y:-c/2+(t-r-1)*n}},n_e=e=>{const A={...e},t=A.p,i=typeof t=="string"||typeof t=="number"?cA.parse(t):void 0,n=i!=null&&i<=cA.parse("0.5mm"),o=e_e.parse(A),s=[],r=n?o.w-cA.parse("0.15mm"):o.w;for(let B=0;B<o.num_pins;B++){const{x:C,y:Q}=i_e({num_pins:o.num_pins,pn:B+1,w:r,p:o.p,pl:o.pl,legsoutside:o.legsoutside});s.push(li(B+1,C,Q,o.pl,o.pw))}const a=Math.min(1,o.p/2),g=o.w-(o.legsoutside?0:o.pl*2)-.2,c=(o.num_pins/2-1)*o.p+o.pw+a,I=Ui(0,c/2+.4,c/12),l={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",stroke_width:o.silkscreen_stroke_width??.1,route:[{x:-g/2,y:-c/2},{x:-g/2,y:c/2},...cO.map(({x:B,y:C})=>({x:B*g/6,y:C*g/6+c/2})),{x:g/2,y:c/2},{x:g/2,y:-c/2},{x:-g/2,y:-c/2}]};return{circuitJson:[...s,l,I],parameters:o}},o_e=Gi.extend({fn:L(),num_pins:SA(6).default(6),w:L().default("3.1mm"),h:L().default("2.0mm"),p:L().default("0.65mm"),pl:L().default("1.03mm"),pw:L().default("0.35mm"),string:L().optional()}),s_e=e=>{const A=o_e.parse({...e,fn:"sot363"}),t=cA.parse(A.w),i=cA.parse(A.h),n=cA.parse(A.p),o=cA.parse(A.pl),s=cA.parse(A.pw),r=[];for(let B=0;B<6;B++){const{x:C,y:Q}=ret(B+1,t,n);r.push(li(B+1,C,Q,o,s))}const a={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-t/4,y:i/2+.1},{x:t/4,y:i/2+.1}],stroke_width:.05,pcb_silkscreen_path_id:""},g={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-t/4,y:-i/2-.1},{x:t/4,y:-i/2-.1}],stroke_width:.05,pcb_silkscreen_path_id:""},c=ret(1,t,n),I={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"pin_marker_1",route:[{x:c.x-o/2-.3,y:c.y},{x:c.x-o/2-.45,y:c.y+.15},{x:c.x-o/2-.45,y:c.y-.15},{x:c.x-o/2-.3,y:c.y}],stroke_width:.05,pcb_silkscreen_path_id:"pin_marker_1"},l=Ui(0,i/2+.4,.25);return{circuitJson:[...r,a,g,l,I],parameters:A}},ret=(e,A,t,i)=>e<=3?{x:-.84,y:t-(e-1)*t}:{x:.84,y:-t+(e-4)*t},r_e=Gi.extend({fn:L(),num_pins:SA(6).default(6),w:L().default("1.01mm"),h:L().default("1.45mm"),p:L().default("0.5mm"),pl:L().default("0.33mm"),pw:L().default("0.27mm"),string:L().optional()}),a_e=e=>{const A=r_e.parse({...e,fn:"sot886"}),t=cA.parse(A.w),i=cA.parse(A.h),n=cA.parse(A.p),o=cA.parse(A.pl),s=cA.parse(A.pw),r=[];for(let B=0;B<6;B++){const{x:C,y:Q}=aet(B+1,t,n,o);r.push(li(B+1,C,Q,o,s))}const a={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-t/2,y:i/2},{x:t/2,y:i/2}],stroke_width:.05,pcb_silkscreen_path_id:""},g={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-t/2,y:-i/2},{x:t/2,y:-i/2}],stroke_width:.05,pcb_silkscreen_path_id:""},c=aet(1,t,n,o),I={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"pin_marker_1",route:[{x:c.x-o/2-.3,y:c.y},{x:c.x-o/2-.45,y:c.y+.15},{x:c.x-o/2-.45,y:c.y-.15},{x:c.x-o/2-.3,y:c.y}],stroke_width:.05,pcb_silkscreen_path_id:"pin_marker_1"},l=Ui(0,i/2+.4,.25);return{circuitJson:[...r,a,g,l,I],parameters:A}},aet=(e,A,t,i)=>{const n=A/2-i/2;return e<=3?{x:-n,y:t-(e-1)*t}:{x:n,y:-t+(e-4)*t}},get=Gi.extend({fn:L(),num_pins:qA().default(3),w:L().default("1.92mm"),h:L().default("2.74mm"),pl:L().default("1.32mm"),pw:L().default("0.6mm"),p:L().default("0.95mm"),string:L().optional()}),g_e=Z4({p:"0.95mm",w:"1.6mm",legsoutside:!0}),c_e=e=>{const A=e.string?.match(/^sot23_(\d+)/),t=A?Number.parseInt(A[1],10):3;if(t===6||t===8){const n=g_e.parse({...e,num_pins:t});return{circuitJson:q8(n),parameters:n}}const i=get.parse({...e,num_pins:t});if(i.num_pins===3)return{circuitJson:l_e(i),parameters:i};if(i.num_pins===5)return{circuitJson:Iet(i),parameters:i};throw new Error("Invalid number of pins")},I_e=e=>{const{pn:A,p:t}=e;return A===1?{x:-1.155,y:t}:A===2?{x:-1.155,y:-t}:{x:1.15,y:0}},l_e=e=>{const A=[];for(let i=0;i<e.num_pins;i++){const{x:n,y:o}=I_e({num_pins:e.num_pins,pn:i+1,w:Number.parseFloat(e.w),h:Number.parseFloat(e.h),pl:Number.parseFloat(e.pl),p:Number.parseFloat(e.p)});A.push(li(i+1,n,o,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}const t=Ui(0,Number.parseInt(e.h),.3);return[...A,t]},cet=e=>{const{p:A,h:t,pn:i}=e;if(i===1)return{x:-t/2-.5,y:A};if(i===2)return{x:-t/2-.5,y:0};if(i===3)return{x:-t/2-.5,y:-A};if(i===4)return{x:t/2+.5,y:-A};if(i===5)return{x:t/2+.5,y:A};throw new Error("Invalid pin number")},Iet=e=>{const A=[];for(let I=1;I<=e.num_pins;I++){const{x:l,y:B}=cet({h:Number.parseFloat(e.h),p:Number.parseFloat(e.p),pn:I});A.push(li(I,l,B,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}const t=(e.num_pins+1)/2*Number.parseFloat(e.p),i=Number.parseFloat(e.h),n={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-t/3,y:i/2+Number.parseFloat(e.p)/1.3},{x:t/3,y:i/2+Number.parseFloat(e.p)/1.3}],type:"pcb_silkscreen_path",stroke_width:.05},o={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_2",route:[{x:-t/3,y:-i/2-Number.parseFloat(e.p)/1.3},{x:t/3,y:-i/2-Number.parseFloat(e.p)/1.3}],type:"pcb_silkscreen_path",stroke_width:.05},s=Ui(0,i+.3,.3),r=cet({h:Number.parseFloat(e.h),p:Number.parseFloat(e.p),pn:1});r.x=r.x-Number.parseFloat(e.pw)*1.5;const a=.3,g=.4,c={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"pin1_indicator",route:[{x:r.x+a/2,y:r.y},{x:r.x-a/2,y:r.y+g/2},{x:r.x-a/2,y:r.y-g/2},{x:r.x+a/2,y:r.y}],stroke_width:.05};return[...A,s,n,o,c]},B_e=get.extend({}),C_e=e=>{const A=B_e.parse({...e,num_pins:5});return{circuitJson:Iet(A),parameters:A}},Q_e=[{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}],h_e=Z4({}),E_e=e=>{const A=h_e.parse(e),t=[];for(let I=0;I<A.num_pins;I++){const{x:l,y:B}=euA({num_pins:A.num_pins,pn:I+1,w:A.w,p:A.p??1.27,pl:A.pl,widthincludeslegs:!0});t.push(li(I+1,l,B,A.pl??"1mm",A.pw??"0.6mm"))}const i=Math.min(1,A.p/2),n=A.w+i,o=(A.num_pins/2-1)*A.p+A.pw+i,s=[];for(const I of Q_e){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=Ui(0,o/2+.4,o/12);return{circuitJson:[...t,c,...s],parameters:A}},V4=({fs:e,pn:A,anchor_x:t,anchor_y:i,textalign:n="center",orthogonal:o=!1,verticallyinverted:s=!1,layer:r="top"})=>{let a=0;o&&s?a=270:s?a=180:o?a=90:a=0;let g="center";return n==="left"&&(s?g="center_right":g="center_left"),n==="right"&&(s?g="center_left":g="center_right"),r==="bottom"&&(g==="center_left"?g="center_right":g==="center_right"&&(g="center_left")),{type:"pcb_silkscreen_text",pcb_silkscreen_text_id:"silkscreen_text_1",font:"tscircuit2024",font_size:e,pcb_component_id:"pcb_component_1",text:`{PIN${A}}`,layer:r,anchor_position:{x:t,y:i},anchor_alignment:g,ccw_rotation:a}};function Bet({pinlabeltextalignleft:e,pinlabeltextalignright:A,pinlabelorthogonal:t}){let i="top";return t?i="left":i="top",e&&(t?i="bottom":i="right"),A&&(t?i="top":i="left"),i}var u_e=Gi.extend({fn:L(),num_pins:qA().optional().default(6),rows:_e([L(),qA()]).transform(e=>Number(e)).optional().default(1).describe("number of rows"),p:cA.default("0.1in").describe("pitch"),id:cA.default("1.0mm").describe("inner diameter"),od:cA.default("1.5mm").describe("outer diameter"),male:HA().optional().describe("for male pin headers"),female:HA().optional().describe("for female pin headers"),smd:HA().optional().describe("surface mount device"),surfacemount:HA().optional().describe("surface mount device (verbose)"),rightangle:HA().optional().describe("right angle"),pw:cA.optional().default("1.0mm").describe("pad width for SMD"),pl:cA.optional().default("2.0mm").describe("pad length for SMD"),pinlabeltextalignleft:HA().optional().default(!1),pinlabeltextaligncenter:HA().optional().default(!1),pinlabeltextalignright:HA().optional().default(!1),pinlabelverticallyinverted:HA().optional().default(!1),pinlabelorthogonal:HA().optional().default(!1),nosquareplating:HA().optional().default(!1).describe("do not use rectangular pad for pin 1"),nopinlabels:HA().optional().default(!1).describe("omit silkscreen pin labels"),doublesidedpinlabel:HA().optional().default(!1).describe("add silkscreen pins in top and bottom layers"),bottomsidepinlabel:HA().optional().default(!1).describe("place the silkscreen reference text on the bottom layer instead of top")}).transform(e=>{const A=Bet(e);return{...e,pinlabelAnchorSide:A,male:e.male??!e.female,female:e.female??!1,smd:e.smd??e.surfacemount??!1,rightangle:e.rightangle??!1}}).superRefine((e,A)=>{e.male&&e.female&&A.addIssue({code:Xe.custom,message:"'male' and 'female' cannot both be true; it should be male or female.",path:["male","female"]})}),d_e=e=>{const A=u_e.parse(e),{p:t,id:i,od:n,rows:o,num_pins:s,pinlabelAnchorSide:r,pinlabelverticallyinverted:a,pinlabelorthogonal:g,pinlabeltextalignleft:c,pinlabeltextalignright:I,nopinlabels:l,doublesidedpinlabel:B,bottomsidepinlabel:C}=A;let Q="center";c?Q="left":I&&(Q="right");const h=[],E=Math.ceil(s/o),u=-t,d=({xoff:x,yoff:_,od:b,anchorSide:R,smd:F,pw:H,pl:Y})=>{let J=0,O=0;if(F){const W=b/5;switch(R){case"right":J=H/2+W;break;case"top":O=Y/2+W;break;case"bottom":O=-(Y/2+W);break;case"left":J=-(H/2+W);break}}else{const W=b*.75;switch(R){case"right":J=W;break;case"top":O=W;break;case"bottom":O=-W;break;case"left":J=-W;break}}return{anchor_x:x+J,anchor_y:_+O}},f=(x,_,b)=>{A.smd?h.push(li(x,_,b,A.pw,A.pl)):x===1&&!A.nosquareplating?h.push(lm({pn:x,x:_,y:b,holeDiameter:i,rectPadWidth:n,rectPadHeight:n})):h.push(Fo(x,_,b,i,n));const{anchor_x:R,anchor_y:F}=d({xoff:_,yoff:b,od:n,anchorSide:r,smd:A.smd,pw:A.pw,pl:A.pl});l||(C?h.push(V4({fs:n/5,pn:x,anchor_x:R,anchor_y:F,textalign:Q,orthogonal:g,verticallyinverted:a,layer:"bottom"})):h.push(V4({fs:n/5,pn:x,anchor_x:R,anchor_y:F,textalign:Q,orthogonal:g,verticallyinverted:a,layer:"top"})),B&&h.push(V4({fs:n/5,pn:x,anchor_x:R,anchor_y:F,textalign:Q,orthogonal:g,verticallyinverted:a,layer:"bottom"})))},m=new Set,w=o>2&&E>2;if(o===1){const x=-((s-1)/2)*t;for(let _=0;_<s;_++){const b=_+1,R=x+_*t,F=`${R},0`;if(m.has(F))throw new Error(`Overlap at ${F}`);m.add(F),f(b,R,0)}}else if(w){const x=-((E-1)/2)*t;let _=1;for(let b=0;b<o&&_<=s;b++)for(let R=0;R<E&&_<=s;R++){const F=x+R*t,H=b*u,Y=`${F},${H}`;if(m.has(Y))throw new Error(`Overlap at ${Y}`);m.add(Y),f(_++,F,H)}}else{const x=-((E-1)/2)*t;let _=1,b=0,R=o-1,F=0,H=E-1;for(;_<=s&&b<=R&&F<=H;){for(let Y=b;Y<=R&&_<=s;Y++){const J=x+F*t,O=Y*u,W=`${J},${O}`;if(m.has(W))throw new Error(`Overlap at ${W}`);m.add(W),f(_++,J,O)}F++;for(let Y=F;Y<=H&&_<=s;Y++){const J=x+Y*t,O=R*u,W=`${J},${O}`;if(m.has(W))throw new Error(`Overlap at ${W}`);m.add(W),f(_++,J,O)}if(R--,F<=H){for(let Y=R;Y>=b&&_<=s;Y--){const J=x+H*t,O=Y*u,W=`${J},${O}`;if(m.has(W))throw new Error(`Overlap at ${W}`);m.add(W),f(_++,J,O)}H--}if(b<=R){for(let Y=H;Y>=F&&_<=s;Y--){const J=x+Y*t,O=b*u,W=`${J},${O}`;if(m.has(W))throw new Error(`Overlap at ${W}`);m.add(W),f(_++,J,O)}b++}}if(_-1<s)throw new Error(`Missing pins: assigned ${_-1}, expected ${s}`)}const D=Ui(0,t,.5);return{circuitJson:[...h,D],parameters:A}},p_e=Gi.extend({fn:L(),num_pins:SA(6).default(6),w:L().default("2.1mm"),h:L().default("2.45mm"),p:L().default("0.5mm"),pl:L().default("0.675mm"),pw:L().default("0.35mm"),string:L().optional()}),f_e=e=>{const A=p_e.parse({...e,fn:"sot563"}),t=cA.parse(A.w),i=cA.parse(A.h),n=cA.parse(A.p),o=cA.parse(A.pl),s=cA.parse(A.pw),r=[];for(let B=0;B<6;B++){const{x:C,y:Q}=Cet(B+1,t,n,o);r.push(li(B+1,C,Q,o,s))}const a={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-t/2,y:i/2},{x:t/2,y:i/2}],stroke_width:.05,pcb_silkscreen_path_id:""},g={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-t/2,y:-i/2},{x:t/2,y:-i/2}],stroke_width:.05,pcb_silkscreen_path_id:""},c=Cet(1,t,n,o),I={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"pin_marker_1",route:[{x:c.x-o/2-.3,y:c.y},{x:c.x-o/2-.45,y:c.y+.15},{x:c.x-o/2-.45,y:c.y-.15},{x:c.x-o/2-.3,y:c.y}],stroke_width:.05,pcb_silkscreen_path_id:"pin_marker_1"},l=Ui(0,i/2+.4,.25);return{circuitJson:[...r,a,g,l,I],parameters:A}},Cet=(e,A,t,i)=>{const n=A/2-i/2;return e<=3?{x:-n,y:t-(e-1)*t}:{x:n,y:-t+(e-4)*t}},y_e=Z4({p:"1.27mm",w:"3.9mm",legsoutside:!0}),m_e=e=>{const A=y_e.parse({...e,num_pins:8});return{circuitJson:q8(A),parameters:A}},w_e=Z4({p:"1.27mm",w:"7.5mm",legsoutside:!0}),D_e=e=>{const A=w_e.parse({...e,num_pins:16});return{circuitJson:q8(A),parameters:A}},x_e=Gi.extend({fn:L(),num_pins:SA(3).default(3),w:L().default("1.2mm"),h:L().default("1.2mm"),pw:L().default("0.40mm"),pl:L().default("0.45mm"),p:L().default("0.575mm")}),S_e=e=>{const A=x_e.parse(e),t=__e(A),i=Ui(0,cA.parse(A.h),.2);return{circuitJson:[...t,i],parameters:A}},b_e=e=>{const{pn:A,p:t}=e;return A===1?{x:t,y:0}:A===2?{x:-t,y:-.4}:{x:-t,y:.4}},__e=e=>{const A=[];for(let t=0;t<3;t++){const{x:i,y:n}=b_e({num_pins:e.num_pins,pn:t+1,w:Number.parseFloat(e.w),h:Number.parseFloat(e.h),pl:Number.parseFloat(e.pl),p:Number.parseFloat(e.p)});A.push(li(t+1,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},k_e=Gi.extend({fn:L(),num_pins:SA(2).default(2),w:L().default("2.36mm"),h:L().default("1.22mm"),pl:L().default("0.9mm"),pw:L().default("1.2mm"),p:L().default("3.30mm")}),v_e=e=>{const A=k_e.parse(e),t=Ui(0,cA.parse(A.h)/4+.4,.3);return{circuitJson:M_e(A).concat(t),parameters:A}},F_e=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},M_e=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=F_e({pn:t,p:Number.parseFloat(e.p)});A.push(li(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},G_e=Gi.extend({fn:L(),p:cA.optional().default("2.54mm"),id:cA.optional().default("0.7mm"),od:cA.optional().default("1.4mm")}),R_e=e=>{const A=G_e.parse(e),{p:t,id:i,od:n}=A,o=[Fo(1,-t/2,0,i,n),Fo(2,t/2,0,i,n)],s={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-t/2+n+i/2,y:0},{x:t/2-n-i/2,y:0}],stroke_width:.1,pcb_silkscreen_path_id:""},r=Ui(0,1.5,.5);return{circuitJson:[...o,s,r],parameters:A}},N_e=(e,A,t,i,n,o=.1)=>{const s=[],r=[],a=Math.max(1,Math.ceil(Math.PI*t/o)),g=Math.PI/a;for(let c=0;c<=a;c++){const I=c*g,l=e+Math.cos(I)*t,B=A+Math.sin(I)*t;l<e-i&&B>=A-n/2&&B<=A+n/2||s.push({x:l,y:B})}for(let c=0;c<=a;c++){const I=Math.PI+c*g,l=e+Math.cos(I)*t,B=A+Math.sin(I)*t;l<e-i&&B>=A-n/2&&B<=A+n/2||r.push({x:l,y:B})}return{topArc:s,bottomArc:r}},L_e=Gi.extend({fn:L(),p:cA.optional().default("5mm"),id:cA.optional().default("0.8mm"),od:cA.optional().default("1.6mm"),ceramic:HA().optional(),electrolytic:HA().optional(),polarized:HA().optional()}),U_e=e=>{const A=L_e.parse(e),{p:t,id:i,od:n}=A;i===.8&&n===1.6&&(A.id=t===5?.8:t*.25,A.od=t===5?1.6:t*.5);const o=[Fo(1,-t/2,0,A.id,A.od),Fo(2,t/2,0,A.id,A.od)],s=t+.1,{topArc:r,bottomArc:a}=N_e(0,0,s,A.od/2,A.od),g=.02*t,c={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:r,stroke_width:g,pcb_silkscreen_path_id:""},I={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:a,stroke_width:g,pcb_silkscreen_path_id:""},l={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:0,y:s},{x:0,y:-s}],stroke_width:g,pcb_silkscreen_path_id:""},B=.1*t,C=-(t+B+.04*t),Q=s-B-.08*t,h={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:C-B,y:Q},{x:C+B,y:Q}],stroke_width:g,pcb_silkscreen_path_id:""},E={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:C,y:Q-B},{x:C,y:Q+B}],stroke_width:g,pcb_silkscreen_path_id:""},u=Ui(0,s+.12*t,.1*t),d=[...o,c,I,l,u];return(A.electrolytic===!0||A.polarized===!0)&&d.push(h,E),{circuitJson:d,parameters:A}},j4=(e,A={})=>({type:"pcb_silkscreen_path",layer:A.layer||"top",pcb_component_id:A.pcb_component_id||"",pcb_silkscreen_path_id:A.pcb_silkscreen_path_id||"",route:e,stroke_width:A.stroke_width||.1}),H_e=Gi.extend({fn:SA("pushbutton"),w:cA.default(4.5),h:cA.default(6.5),id:cA.default(1),od:cA.default(1.2)}),Y_e=e=>{const A=H_e.parse(e),t=A.w,i=A.h,n=A.id,o=[Fo(1,-t/2,i/2,n,n*1.5),Fo(2,-t/2,-i/2,n,n*1.5),Fo(3,t/2,-i/2,n,n*1.5),Fo(4,t/2,i/2,n,n*1.5)],s=[j4([{x:-t/2,y:-i/2},{x:-t/2,y:i/2}]),j4([{x:t/2,y:-i/2},{x:t/2,y:i/2}]),j4([{x:-t/2,y:0},{x:-t/5,y:0},{x:t/5*1/Math.sqrt(2),y:i/8}]),j4([{x:t/2,y:0},{x:t/5,y:0}])],r=Ui(0,i/2+.4,.5);return{circuitJson:[...o,...s,r],parameters:A}},Qet=Gi.extend({fn:L(),w:cA.default("22.58mm"),h:cA.optional(),left:cA.optional().default(20),right:cA.optional().default(20),top:cA.optional().default(2),bottom:cA.optional().default(2),p:cA.default(cA.parse("2.54mm")),pw:cA.default(cA.parse("1.6mm")),pl:cA.default(cA.parse("2.4mm")),innerhole:HA().default(!1),innerholeedgedistance:cA.default(cA.parse("1.61mm")),silkscreenlabels:HA().default(!1),silkscreenlabelmargin:cA.default(cA.parse("0.1mm"))}),J_e=e=>{const A=Qet.parse(e);return A.left&&A.right?Math.max(A.left,A.right)*A.p:A.left?A.left*A.p:A.right?A.right*A.p:51},QO=(e,A,t)=>{let i=[];return t==="right"&&(i=[{x:e+1/2,y:A},{x:e-1/2,y:A+.6/2},{x:e-1/2,y:A-.6/2},{x:e+1/2,y:A}]),t==="left"&&(i=[{x:e-1/2,y:A},{x:e+1/2,y:A+.6/2},{x:e+1/2,y:A-.6/2},{x:e-1/2,y:A}]),t==="top"&&(i=[{x:e,y:A+1/2},{x:e-.6/2,y:A-1/2},{x:e+.6/2,y:A-1/2},{x:e,y:A+1/2}]),t==="bottom"&&(i=[{x:e,y:A-1/2},{x:e-.6/2,y:A+1/2},{x:e+.6/2,y:A+1/2},{x:e,y:A-1/2}]),i},T_e=e=>{const A=Qet.parse(e),t=A.h??J_e(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=QO(A.w/2-A.pl*1.4,Q+h*A.p,"right")),i.push(li(h+1+A.left+(A.bottom??0),A.w/2-A.pl/2,Q+h*A.p,A.pl,A.pw)),A.silkscreenlabels){const E=h+1+A.left+(A.bottom??0),u=`pin${E}`;o.push({type:"pcb_silkscreen_text",pcb_silkscreen_text_id:`pin_${E}`,pcb_component_id:"1",layer:"top",anchor_position:{x:A.w/2-A.pl-(I+A.silkscreenlabelmargin),y:Q+h*A.p},text:u,font_size:.7,font:"tscircuit2024",anchor_alignment:"center"})}A.innerhole&&(n.push(Fo(h+1+A.left+(A.bottom??0)+g,A.w/2,Q+h*A.p,r,a)),n.push(Fo(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=QO(-A.w/2+A.pl*1.4,Q-h*A.p,"left")),i.push(li(h+1,-A.w/2+A.pl/2,Q-h*A.p,A.pl,A.pw)),A.silkscreenlabels){const E=h+1,u=`pin${E}`;o.push({type:"pcb_silkscreen_text",pcb_silkscreen_text_id:`pin_${E}`,pcb_component_id:"1",layer:"top",anchor_position:{x:-A.w/2+A.pl+(I+A.silkscreenlabelmargin),y:Q-h*A.p},text:u,font_size:.7,font:"tscircuit2024",anchor_alignment:"center"})}A.innerhole&&(n.push(Fo(h+1+g,-A.w/2,Q-h*A.p,r,a)),n.push(Fo(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=QO(Q-h*A.p,t/2-A.pl*1.4,"top")),i.push(li(h+1+A.left+A.right+(A.bottom??0),Q-h*A.p,t/2-A.pl/2,A.pw,A.pl)),A.silkscreenlabels){const E=h+1+A.left+A.right+(A.bottom??0),u=`pin${E}`;o.push({type:"pcb_silkscreen_text",pcb_silkscreen_text_id:`pin_${E}`,pcb_component_id:"1",layer:"top",anchor_position:{x:Q-h*A.p,y:t/2-A.pl-(I+A.silkscreenlabelmargin)},text:u,font_size:.7,font:"tscircuit2024",anchor_alignment:"center",ccw_rotation:270})}A.innerhole&&(n.push(Fo(h+1+A.left+A.right+(A.bottom??0)+g,Q-h*A.p,t/2,r,a)),n.push(Fo(h+1+A.left+A.right+(A.bottom??0)+g*2,Q-h*A.p,t/2-A.innerholeedgedistance,r,a)))}}if(A.bottom){const Q=-((A.bottom-1)/2)*A.p;for(let h=0;h<A.bottom;h++){if(h===0&&!A.left&&!A.silkscreenlabels&&(s=QO(Q+h*A.p,-t/2+A.pl*1.4,"bottom")),i.push(li(h+1+A.left,Q+h*A.p,-t/2+A.pl/2,A.pw,A.pl)),A.silkscreenlabels){const E=h+1+A.left,u=`pin${E}`;o.push({type:"pcb_silkscreen_text",pcb_silkscreen_text_id:`pin_${E}`,pcb_component_id:"1",layer:"top",anchor_position:{x:Q+h*A.p,y:-t/2+A.pl+(I+A.silkscreenlabelmargin)},text:u,font_size:.7,font:"tscircuit2024",anchor_alignment:"center",ccw_rotation:90})}A.innerhole&&(n.push(Fo(h+1+A.left+g,Q+h*A.p,-t/2,r,a)),n.push(Fo(h+1+A.left+g*2,Q+h*A.p,-t/2+A.innerholeedgedistance,r,a)))}}const l={type:"pcb_silkscreen_path",pcb_silkscreen_path_id:"pcb_silkscreen_triangle_1",pcb_component_id:"2",route:s,stroke_width:.1,layer:"top"},B={type:"pcb_silkscreen_path",pcb_silkscreen_path_id:"pcb_silkscreen_path_1",pcb_component_id:"1",route:[{x:-A.w/2,y:t/2},{x:A.w/2,y:t/2},{x:A.w/2,y:-t/2},{x:-A.w/2,y:-t/2},{x:-A.w/2,y:t/2}],stroke_width:.1,layer:"top"},C=Ui(0,t/1.8,t/25);return{circuitJson:[...i,...n,...o,B,...A.silkscreenlabels?[]:[l],C],parameters:A}},het=Gi.extend({fn:L(),w:cA.default("22.58mm"),h:cA.optional(),left:cA.optional().default(20),right:cA.optional().default(20),top:cA.optional().default(2),bottom:cA.optional().default(2),p:cA.default(cA.parse("2.54mm")),pw:cA.default(cA.parse("1.6mm")),pl:cA.default(cA.parse("3.2mm")),innerhole:HA().default(!1),innerholeedgedistance:cA.default(cA.parse("1.61mm"))}),P_e=e=>{const A=het.parse(e);return A.left&&A.right?Math.max(A.left,A.right)*A.p:A.left?A.left*A.p:A.right?A.right*A.p:51},K_e=(e,A,t,i=1,n=.6)=>{const o=i/2,s=n/2;return{left:[{x:e+o,y:A},{x:e-o,y:A+s},{x:e-o,y:A-s},{x:e+o,y:A}],right:[{x:e-o,y:A},{x:e+o,y:A+s},{x:e+o,y:A-s},{x:e-o,y:A}],top:[{x:e,y:A-o},{x:e-s,y:A+o},{x:e+s,y:A+o},{x:e,y:A-o}],bottom:[{x:e,y:A+o},{x:e-s,y:A-o},{x:e+s,y:A-o},{x:e,y:A+o}]}[t]},q_e=e=>{const A=het.parse(e),t=A.h??P_e(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=K_e(-A.w/2-A.pl/2,C-Q*A.p,"left")),i.push(li(c,-A.w/2+A.pl/2,C-Q*A.p,A.pl,A.pw)),n.push({type:"pcb_silkscreen_text",pcb_silkscreen_text_id:`pin_${c}`,pcb_component_id:"1",layer:"top",anchor_position:{x:-A.w/2+A.pl/2-4.5,y:C-Q*A.p},text:`pin${c}`,font_size:.7,font:"tscircuit2024",anchor_alignment:"center"}),c++,A.innerhole&&o.push(Fo(c+a,-A.w/2+A.innerholeedgedistance,C-Q*A.p,s,r))}if(A.bottom){const C=(A.bottom-1)/2*A.p;for(let Q=A.bottom-1;Q>=0;Q--)i.push(li(c,C-Q*A.p,-t/2+A.pl/2,A.pw,A.pl)),n.push({type:"pcb_silkscreen_text",pcb_silkscreen_text_id:`pin_${c}`,pcb_component_id:"1",layer:"top",anchor_position:{x:C-Q*A.p,y:-t/2+A.pl/2-3.2},text:`pin${c}`,font_size:.7,font:"tscircuit2024",anchor_alignment:"center"}),c++,A.innerhole&&o.push(Fo(c+a,C-Q*A.p,-t/2+A.innerholeedgedistance,s,r))}if(A.right){const C=-((A.right-1)/2)*A.p;for(let Q=0;Q<A.right;Q++)i.push(li(c,A.w/2-A.pl/2,C+Q*A.p,A.pl,A.pw)),n.push({type:"pcb_silkscreen_text",pcb_silkscreen_text_id:`pin_${c}`,pcb_component_id:"1",layer:"top",anchor_position:{x:A.w/2-A.pl/2+3.7,y:C+Q*A.p},text:`pin${c}`,font_size:.7,font:"tscircuit2024",anchor_alignment:"center"}),c++,A.innerhole&&o.push(Fo(c+a,A.w/2-A.innerholeedgedistance,C+Q*A.p,s,r))}if(A.top){const C=-((A.top-1)/2)*A.p;for(let Q=A.top-1;Q>=0;Q--)i.push(li(c,C+Q*A.p,t/2-A.pl/2,A.pw,A.pl)),n.push({type:"pcb_silkscreen_text",pcb_silkscreen_text_id:`pin_${c}`,pcb_component_id:"1",layer:"top",anchor_position:{x:C+Q*A.p,y:t/2-A.pl/2+3.2},text:`pin${c}`,font_size:.7,font:"tscircuit2024",anchor_alignment:"center"}),c++,A.innerhole&&o.push(Fo(c+a,C+Q*A.p,t/2-A.innerholeedgedistance,s,r))}const I={type:"pcb_silkscreen_path",pcb_silkscreen_path_id:"1",pcb_component_id:"1",layer:"top",route:g,stroke_width:.1},l={type:"pcb_silkscreen_path",pcb_silkscreen_path_id:"pcb_silkscreen_path_1",pcb_component_id:"1",route:[{x:-A.w/2-A.pl/3,y:t/2+A.pl/3},{x:A.w/2+A.pl/3,y:t/2+A.pl/3},{x:A.w/2+A.pl/3,y:-t/2-A.pl/3},{x:-A.w/2-A.pl/3,y:-t/2-A.pl/3},{x:-A.w/2-A.pl/3,y:t/2+A.pl/3}],stroke_width:.1,layer:"top"},B=Ui(0,t/1.8,t/25);return{circuitJson:[...o,...i,...n,l,I,B],parameters:A}},O_e=e=>(e.legsoutside=!0,e.pl||(e.pl=1.5),e.pw||(e.pw=.3),QF(e)),Eet=Gi.extend({fn:L(),w:cA.default("10mm"),h:cA.optional(),left:cA.optional().default(20),right:cA.optional().default(20),top:cA.optional().default(0),bottom:cA.optional().default(0),p:cA.default(cA.parse("2.54mm")),id:cA.optional().default(cA.parse("1mm")),od:cA.optional().default(cA.parse("1.5mm"))}),W_e=e=>{const A=Eet.parse(e);return A.left&&A.right?Math.max(A.left,A.right)*A.p:A.left?A.left*A.p:A.right?A.right*A.p:51},hO=(e,A,t,i=1,n=.6)=>{const o=i/2,s=n/2;return{left:[{x:e+o,y:A},{x:e-o,y:A+s},{x:e-o,y:A-s},{x:e+o,y:A}],right:[{x:e-o,y:A},{x:e+o,y:A+s},{x:e+o,y:A-s},{x:e-o,y:A}],top:[{x:e,y:A-o},{x:e-s,y:A+o},{x:e+s,y:A+o},{x:e,y:A-o}],bottom:[{x:e,y:A+o},{x:e-s,y:A-o},{x:e+s,y:A-o},{x:e,y:A+o}]}[t]},Z_e=e=>{const A=Eet.parse(e),t=A.h??W_e(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=hO(A.w/2+o*1.4,c+I*A.p,"right")),i.push(Fo(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=hO(-A.w/2-o*1.4,c+I*A.p,"left")),i.push(Fo(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=hO(c+I*A.p,t/2+o*1.4,"top")),i.push(Fo(I+1+A.right+(A.bottom??0)+A.left,c+I*A.p,t/2,n,o))}if(A.bottom){const c=-((A.bottom-1)/2)*A.p;for(let I=0;I<A.bottom;I++)I===0&&!A.left&&(s=hO(c+I*A.p,-t/2-o*1.4,"bottom")),i.push(Fo(I+1+A.left,c+I*A.p,-t/2,n,o))}const r={type:"pcb_silkscreen_path",pcb_silkscreen_path_id:"1",pcb_component_id:"1",layer:"top",route:s,stroke_width:.1},a={type:"pcb_silkscreen_path",pcb_silkscreen_path_id:"pcb_silkscreen_path_1",pcb_component_id:"1",route:[{x:-A.w/2-o,y:t/2+o},{x:A.w/2+o,y:t/2+o},{x:A.w/2+o,y:-t/2-o},{x:-A.w/2-o,y:-t/2-o},{x:-A.w/2-o,y:t/2+o}],stroke_width:.1,layer:"top"},g=Ui(0,t/1.7,t/25);return{circuitJson:[...i,a,g,r],parameters:A}},uet=(e,A,t,i)=>Array.from({length:25},(n,o)=>{const s=o/24*Math.PI-Math.PI/2;return{x:e+(i==="right"?1:-1)*Math.cos(s)*t,y:A+Math.sin(s)*t}}),V_e=Gi.extend({fn:L(),p:cA.optional().default("4.88mm"),id:cA.optional().default("0.8mm"),od:cA.optional().default("1.5mm"),w:cA.optional().default("5.6mm"),h:cA.optional().default("3.5mm")}),j_e=e=>{const A=V_e.parse(e),{p:t,id:i,od:n,w:o,h:s}=A,r=s/2,a=[Fo(1,-t/2,0,i,n),Fo(2,t/2,0,i,n)],g=uet(-o/2,0,r,"left"),c=uet(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=Ui(0,t/4,.5);return{circuitJson:[...a,I,l],parameters:A}};Gi.extend({w:cA,h:cA});var z_e=e=>{const{w:A,h:t}=e,i=cr(A),n=cr(t);return{circuitJson:[li(1,0,0,i,n),Ui(0,n/2+.5,.2)],parameters:e}},z4=(e,A,t,i,n,o)=>({pcb_plated_hole_id:"",type:"pcb_plated_hole",shape:"pill",x:A,y:t,outer_width:cr(n),outer_height:cr(o),hole_width:cr(i),hole_height:cr(i),pcb_port_id:"",layers:["top","bottom"],port_hints:[e.toString()],ccw_rotation:0}),X_e=Gi.extend({fn:L(),num_pins:_e([SA(3),SA(2)]).default(3),p:L().default("1.27mm"),id:L().default("0.72mm"),od:L().default("0.95mm"),w:L().default("4.5mm"),h:L().default("4.5mm"),inline:HA().default(!1),string:L().optional()}),$_e=(e,A,t)=>Array.from({length:25},(i,n)=>{const o=n/24*Math.PI;return{x:e+Math.cos(o)*t,y:A+Math.sin(o)*t}}),A4e=e=>{const A=e.string?.match(/^to92_(\d+)/),t=A?Number.parseInt(A[1],10):3,i=X_e.parse({...e,num_pins:t}),{p:n,id:o,od:s,w:r,h:a,inline:g}=i,c=Number.parseFloat(a)/2,I=Number.parseFloat(n),l=Number.parseFloat(o),B=Number.parseFloat(s),C=B,Q=B*(1.5/1.05);let h=[];if(i.num_pins===3)g?h=[lm({pn:1,x:-I,y:c-I,holeDiameter:l,rectPadWidth:B,rectPadHeight:Q}),z4(2,0,c-I,l,C,Q),z4(3,I,c-I,l,C,Q)]:h=[lm({pn:1,x:-I,y:c-I,holeDiameter:l,rectPadWidth:B,rectPadHeight:B}),Fo(2,0,c,l,B),Fo(3,I,c-I,l,B)];else if(i.num_pins===2)h=[lm({pn:1,x:-I,y:c-I,holeDiameter:l,rectPadWidth:C,rectPadHeight:Q}),z4(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=$_e(0,c,E),d={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[...u,{x:-E,y:0},{x:E,y:0},u[0]],stroke_width:.1,pcb_silkscreen_path_id:""},f=Ui(0,c+1,.5);return{circuitJson:[...h,d,f],parameters:i}},t4e=Gi.extend({fn:L(),num_pins:SA(2).default(2),w:L().default("2.15mm"),h:L().default("1.20mm"),pl:L().default("0.5mm"),pw:L().default("0.6mm"),p:L().default("1.4mm")}),e4e=e=>{const A=t4e.parse(e),t=Ui(0,cA.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:cA.parse(A.p)/2,y:cA.parse(A.h)/2},{x:-cA.parse(A.w)/2-.2,y:cA.parse(A.h)/2},{x:-cA.parse(A.w)/2-.2,y:-cA.parse(A.h)/2},{x:cA.parse(A.p)/2,y:-cA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:n4e(A).concat(i,t),parameters:A}},i4e=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},n4e=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=i4e({pn:t,p:Number.parseFloat(e.p)});A.push(li(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},o4e=Z4({w:"7.05mm",p:"1.27mm",pw:"0.65mm",pl:"1.975mm"}),s4e=e=>{const A=o4e.parse(e),t=[];for(let s=0;s<A.num_pins;s++){const{x:r,y:a}=euA({num_pins:A.num_pins,pn:s+1,w:A.w,p:A.p??1.27,pl:A.pl,widthincludeslegs:!0});t.push(li(s+1,r,a,A.pl??"1.5mm",A.pw??"0.6mm"))}const i=(A.num_pins/2-1)*A.p+A.pw,n=Ui(0,i/2+1,i/12),o={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"",type:"pcb_silkscreen_path",route:[{x:-A.w/3,y:i/2+.4},{x:A.w/3,y:i/2+.4}],stroke_width:.1};return{circuitJson:[...t,n,o],parameters:A}},r4e=Gi.extend({fn:L(),num_pins:SA(2).default(2),w:L().default("5.0mm"),h:L().default("2.30mm"),pl:L().default("1.25mm"),pw:L().default("2mm"),p:L().default("3.75mm")}),a4e=e=>{const A=r4e.parse(e),t=Ui(0,cA.parse(A.h)/2+1,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:cA.parse(A.p)/2+.5,y:cA.parse(A.h)/2+.5},{x:-cA.parse(A.w)/2-.5,y:cA.parse(A.h)/2+.5},{x:-cA.parse(A.w)/2-.5,y:-cA.parse(A.h)/2-.5},{x:cA.parse(A.p)/2+.5,y:-cA.parse(A.h)/2-.5}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:c4e(A).concat(i,t),parameters:A}},g4e=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},c4e=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=g4e({pn:t,p:Number.parseFloat(e.p)});A.push(li(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},I4e=Gi.extend({fn:L(),num_pins:SA(2).default(2),w:L().default("4.4mm"),h:L().default("2.1mm"),pl:L().default("1.2mm"),pw:L().default("1.2mm"),p:L().default("2.9mm")}),l4e=e=>{const A=I4e.parse(e),t=Ui(0,cA.parse(A.h)-.5,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:cA.parse(A.p)/2,y:cA.parse(A.h)/2},{x:-cA.parse(A.w)/2-.2,y:cA.parse(A.h)/2},{x:-cA.parse(A.w)/2-.2,y:-cA.parse(A.h)/2},{x:cA.parse(A.p)/2,y:-cA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:C4e(A).concat(i,t),parameters:A}},B4e=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},C4e=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=B4e({pn:t,p:Number.parseFloat(e.p)});A.push(li(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},Q4e=Gi.extend({fn:L(),num_pins:SA(2).default(2),w:L().default("3.30mm"),h:L().default("1.80mm"),pl:L().default("0.60mm"),pw:L().default("0.45mm"),p:L().default("2.1mm")}),h4e=e=>{const A=Q4e.parse(e),t=Ui(0,cA.parse(A.h)-.5,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:cA.parse(A.p)/2,y:cA.parse(A.h)/2},{x:-cA.parse(A.w)/2,y:cA.parse(A.h)/2},{x:-cA.parse(A.w)/2,y:-cA.parse(A.h)/2},{x:cA.parse(A.p)/2,y:-cA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:u4e(A).concat(i,t),parameters:A}},E4e=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},u4e=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=E4e({pn:t,p:Number.parseFloat(e.p)});A.push(li(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},d4e=Gi.extend({fn:L(),num_pins:SA(2).default(2),w:L().default("1.4mm"),h:L().default("0.9mm"),pl:L().default("0.36mm"),pw:L().default("0.25mm"),p:L().default("0.85mm")}),p4e=e=>{const A=d4e.parse(e),t=Ui(0,cA.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:cA.parse(A.p)/2+.15,y:cA.parse(A.h)/2},{x:-cA.parse(A.w)/2-.15,y:cA.parse(A.h)/2},{x:-cA.parse(A.w)/2-.15,y:-cA.parse(A.h)/2},{x:cA.parse(A.p)/2+.15,y:-cA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:y4e(A).concat(i,t),parameters:A}},f4e=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},y4e=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=f4e({pn:t,p:Number.parseFloat(e.p)});A.push(li(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},m4e=Gi.extend({fn:L(),num_pins:SA(2).default(2),w:L().default("1.3mm"),h:L().default("0.9mm"),pl:L().default("0.4mm"),pw:L().default("0.7mm"),p:L().default("0.7mm")}),w4e=e=>{const A=m4e.parse(e),t=Ui(0,cA.parse(A.h)+.1,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:cA.parse(A.p)/2+.2,y:cA.parse(A.h)/2+.2},{x:-cA.parse(A.w)/2-.2,y:cA.parse(A.h)/2+.2},{x:-cA.parse(A.w)/2-.2,y:-cA.parse(A.h)/2-.2},{x:cA.parse(A.p)/2+.2,y:-cA.parse(A.h)/2-.2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:x4e(A).concat(i,t),parameters:A}},D4e=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},x4e=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=D4e({pn:t,p:Number.parseFloat(e.p)});A.push(li(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},S4e=Gi.extend({fn:L(),num_pins:SA(2).default(2),w:L().default("3,05mm"),h:L().default("1.65mm"),pl:L().default("0.6mm"),pw:L().default("0.6mm"),pad_spacing:L().default("2.2mm")}),b4e=e=>{const A=S4e.parse(e),t=Ui(0,cA.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:cA.parse(A.pad_spacing)/2,y:cA.parse(A.h)/2},{x:-cA.parse(A.w)/2-.2,y:cA.parse(A.h)/2},{x:-cA.parse(A.w)/2-.2,y:-cA.parse(A.h)/2},{x:cA.parse(A.pad_spacing)/2,y:-cA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:k4e(A).concat(i,t),parameters:A}},_4e=e=>{const{pn:A,pad_spacing:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},k4e=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=_4e({pn:t,pad_spacing:Number.parseFloat(e.pad_spacing)});A.push(li(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},v4e=Gi.extend({fn:L(),num_pins:SA(2).default(2),w:L().default("4.4mm"),h:L().default("2.1mm"),pl:L().default("1.10mm"),pw:L().default("1.10mm"),p:L().default("2.8mm")}),F4e=e=>{const A=v4e.parse(e),t=Ui(0,cA.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:cA.parse(A.p)/2,y:cA.parse(A.h)/2},{x:-cA.parse(A.w)/2-.2,y:cA.parse(A.h)/2},{x:-cA.parse(A.w)/2-.2,y:-cA.parse(A.h)/2},{x:cA.parse(A.p)/2,y:-cA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:G4e(A).concat(i,t),parameters:A}},M4e=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},G4e=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=M4e({pn:t,p:Number.parseFloat(e.p)});A.push(li(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},R4e=Gi.extend({fn:L(),num_pins:SA(2).default(2),w:L().default("4.4mm"),h:L().default("2.1mm"),pl:L().default("0.91mm"),pw:L().default("1.22mm"),p:L().default("3.146mm")}),N4e=e=>{const A=R4e.parse(e),t=Ui(0,cA.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:cA.parse(A.p)/2,y:cA.parse(A.h)/2},{x:-cA.parse(A.w)/2-.2,y:cA.parse(A.h)/2},{x:-cA.parse(A.w)/2-.2,y:-cA.parse(A.h)/2},{x:cA.parse(A.p)/2,y:-cA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:U4e(A).concat(i,t),parameters:A}},L4e=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},U4e=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=L4e({pn:t,p:Number.parseFloat(e.p)});A.push(li(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},H4e=Gi.extend({fn:L(),num_pins:SA(2).default(2),w:L().default("1.80mm"),h:L().default("1.00mm"),pl:L().default("0.66mm"),pw:L().default("0.5mm"),p:L().default("0.8mm")}),Y4e=e=>{const A=H4e.parse(e),t=Ui(0,cA.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:cA.parse(A.p)/2,y:cA.parse(A.h)/2},{x:-cA.parse(A.w)/2-.1,y:cA.parse(A.h)/2},{x:-cA.parse(A.w)/2-.1,y:-cA.parse(A.h)/2},{x:cA.parse(A.p)/2,y:-cA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:T4e(A).concat(i,t),parameters:A}},J4e=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},T4e=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=J4e({pn:t,p:Number.parseFloat(e.p)});A.push(li(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},P4e=Gi.extend({fn:L(),num_pins:SA(2).default(2),w:L().default("6.2mm"),h:L().default("3.4mm"),pl:L().default("1.4mm"),pw:L().default("2.1mm"),p:L().default("4.4mm")}),K4e=e=>{const A=P4e.parse(e),t=Ui(0,cA.parse(A.h)/2+.4,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:cA.parse(A.p)/2,y:cA.parse(A.h)/2},{x:-cA.parse(A.w)/2-.2,y:cA.parse(A.h)/2},{x:-cA.parse(A.w)/2-.2,y:-cA.parse(A.h)/2},{x:cA.parse(A.p)/2,y:-cA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:O4e(A).concat(i,t),parameters:A}},q4e=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},O4e=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=q4e({pn:t,p:Number.parseFloat(e.p)});A.push(li(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},W4e=Gi.extend({fn:L(),num_pins:_e([SA(3),SA(5)]).default(3),w:L().default("4.20mm"),h:L().default("4.80mm"),pl:L().default("1.3mm"),pw:L().default("0.9mm"),p:L().default("1.5mm"),string:L().optional()}),Z4e=e=>{const A=[],t=Number.parseFloat(e.p),i=Number.parseFloat(e.pw),n=Number.parseFloat(e.w),o=Number.parseFloat(e.pl),s=.175,r=(o-(o+s))/2;A.push(li(1,-n/2+r,t,o,i),li(2,-n/2,0,o+s,i),li(3,-n/2+r,-t,o,i));const a=Ui(0,0,.3),g=Number.parseFloat(e.w)/2-1,c=Number.parseFloat(e.h)/2,I={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-g,y:c},{x:g,y:c},{x:g,y:c/2+.5}],type:"pcb_silkscreen_path",stroke_width:.1},l={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_2",route:[{x:-g,y:-c},{x:g,y:-c},{x:g,y:-c/2-.5}],type:"pcb_silkscreen_path",stroke_width:.1};return[...A,I,l,a]},V4e=e=>{const A=[];Number.parseFloat(e.p),Number.parseFloat(e.pw),Number.parseFloat(e.w),A.push(li(1,-1.85,-1.5,1.5,.7),li(2,-1.85,1.5,1.5,.7),li(3,0,0,.8,2),li(4,1.85,-1.5,1.5,.7),li(5,1.85,1.5,1.5,.7));const t=Ui(0,Number.parseFloat(e.h)/2+.5,.3),i=Number.parseFloat(e.w)/2-1,n=Number.parseFloat(e.h)/2,o={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-i,y:n},{x:i,y:n}],type:"pcb_silkscreen_path",stroke_width:.1},s={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_2",route:[{x:-i,y:-n},{x:i,y:-n}],type:"pcb_silkscreen_path",stroke_width:.1};return[...A,o,s,t]},j4e=e=>{const A=e.string?.match(/^sot89_(\d+)/),t=A?Number.parseInt(A[1],10):3,i=W4e.parse({...e,num_pins:t});if(i.num_pins===3)return{circuitJson:Z4e(i),parameters:i};if(i.num_pins===5)return{circuitJson:V4e(i),parameters:i};throw new Error("Invalid number of pins for SOT89")},z4e=Gi.extend({fn:L(),p:cA.optional().default("5.0mm"),id:cA.optional().default("1.0mm"),od:cA.optional().default("1.9mm"),w:cA.optional().default("13mm"),h:cA.optional().default("7mm"),num_pins:qA().optional(),string:L().optional()}),det=e=>{const A=z4e.parse(e),{id:t,od:i,w:n,h:o,string:s}=A,r=A.num_pins??Number.parseInt(s?.match(/^to220(?:_|-)(\d+)/i)?.[1]??"3"),a=-1,g=n/2,c=o/2,I=2.5,l=n*.4,B=Math.max(I,l/(r-1)),C=Array.from({length:r},(f,m)=>{const w=r%2===0?(m-r/2+.5)*B:(m-Math.floor(r/2))*B;return Fo(m+1,w,a,t,i)}),Q={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-g,y:-c},{x:g,y:-c},{x:g,y:c},{x:-g,y:c},{x:-g,y:-c}],stroke_width:.1,pcb_silkscreen_path_id:""},h=-c+2*o/3,E={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-g,y:h},{x:g,y:h}],stroke_width:.1,pcb_silkscreen_path_id:""},u=[{type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-n/6,y:h},{x:-n/6,y:c}],stroke_width:.1,pcb_silkscreen_path_id:""},{type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:n/6,y:h},{x:n/6,y:c}],stroke_width:.1,pcb_silkscreen_path_id:""}],d=Ui(0,o/2+.6,.5);return{circuitJson:[...C,Q,E,...u,d],parameters:{...A,p:B}}},ouA=2.54,X4e=Gi.extend({fn:L(),id:cA.optional().default("1.2mm"),od:cA.optional().default("1.905mm"),ph:cA.optional().default("2mm"),w:cA.optional().default("13mm"),h:cA.optional().default("7mm"),num_pins:qA().optional(),string:L().optional()}),$4e=e=>{const A=X4e.parse(e),t=A.num_pins??Number.parseInt(A.string?.match(/^to220f(?:_|-)(\d+)/i)?.[1]??"3"),i=det({...A,fn:"to220",string:A.string?.replace(/^to220f/i,"to220"),num_pins:t}),n=-1,o=Array.from({length:t},(r,a)=>{const g=t%2===0?(a-t/2+.5)*ouA:(a-Math.floor(t/2))*ouA;return a===0?lm({pn:1,x:g,y:n,holeDiameter:A.id,rectPadWidth:A.od,rectPadHeight:A.ph}):z4(a+1,g,n,cr(A.id),cr(A.od),cr(A.ph))}),s=i.circuitJson.filter(r=>r.type!=="pcb_plated_hole");return{circuitJson:[...o,...s],parameters:{...A,p:ouA,num_pins:t}}},A3e=Gi.extend({fn:L(),num_pins:SA(2).default(2),w:L().default("5.40mm"),h:L().default("2.30mm"),pl:L().default("1.30mm"),pw:L().default("1.70mm"),p:L().default("3.5mm")}),t3e=e=>{const A=A3e.parse(e),t=Ui(0,cA.parse(A.h)/2+.4,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:cA.parse(A.p)/2,y:cA.parse(A.h)/2},{x:-cA.parse(A.w)/2,y:cA.parse(A.h)/2},{x:-cA.parse(A.w)/2,y:-cA.parse(A.h)/2},{x:cA.parse(A.p)/2,y:-cA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:i3e(A).concat(i,t),parameters:A}},e3e=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},i3e=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=e3e({pn:t,p:Number.parseFloat(e.p)});A.push(li(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},n3e=Gi.extend({fn:L(),num_pins:SA(2).default(2),w:L().default("1.90mm"),h:L().default("1.33mm"),pl:L().default("0.5mm"),pw:L().default("0.7mm"),p:L().default("0.8mm")}),o3e=e=>{const A=n3e.parse(e),t=Ui(0,cA.parse(A.h)+.1,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:cA.parse(A.p)/2+.1,y:cA.parse(A.h)/2},{x:-cA.parse(A.w)/2,y:cA.parse(A.h)/2},{x:-cA.parse(A.w)/2,y:-cA.parse(A.h)/2},{x:cA.parse(A.p)/2+.1,y:-cA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:r3e(A).concat(i,t),parameters:A}},s3e=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},r3e=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=s3e({pn:t,p:Number.parseFloat(e.p)});A.push(li(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},a3e=Gi.extend({fn:L(),num_pins:SA(2).default(2),w:L().default("7.0mm"),h:L().default("3.35mm"),pl:L().default("1.50mm"),pw:L().default("2.70mm"),p:L().default("4.8mm")}),g3e=e=>{const A=a3e.parse(e),t=Ui(0,cA.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:cA.parse(A.p)/2,y:cA.parse(A.h)/2},{x:-cA.parse(A.w)/2,y:cA.parse(A.h)/2},{x:-cA.parse(A.w)/2,y:-cA.parse(A.h)/2},{x:cA.parse(A.p)/2,y:-cA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:I3e(A).concat(i,t),parameters:A}},c3e=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},I3e=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=c3e({pn:t,p:Number.parseFloat(e.p)});A.push(li(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},l3e=Gi.extend({fn:L(),num_pins:SA(2).default(2),w:L().default("3.0mm"),h:L().default("1.80mm"),pl:L().default("0.80mm"),pw:L().default("1.20mm"),p:L().default("1.6mm")}),B3e=e=>{const A=l3e.parse(e),t=Ui(0,cA.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:cA.parse(A.p)/2,y:cA.parse(A.h)/2},{x:-cA.parse(A.w)/2-.1,y:cA.parse(A.h)/2},{x:-cA.parse(A.w)/2-.1,y:-cA.parse(A.h)/2},{x:cA.parse(A.p)/2,y:-cA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:Q3e(A).concat(i,t),parameters:A}},C3e=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},Q3e=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=C3e({pn:t,p:Number.parseFloat(e.p)});A.push(li(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},h3e=Gi.extend({fn:L(),num_pins:SA(2).default(2),w:L().default("7.10mm"),h:L().default("3.40mm"),pl:L().default("2.45mm"),pw:L().default("1.80mm"),p:L().default("4.05mm")}),E3e=e=>{const A=h3e.parse(e),t=Ui(0,cA.parse(A.h)/2+.5,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:cA.parse(A.p)/2,y:cA.parse(A.h)/2},{x:-cA.parse(A.w)/2-.5,y:cA.parse(A.h)/2},{x:-cA.parse(A.w)/2-.5,y:-cA.parse(A.h)/2},{x:cA.parse(A.p)/2,y:-cA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:d3e(A).concat(i,t),parameters:A}},u3e=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},d3e=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=u3e({pn:t,p:Number.parseFloat(e.p)});A.push(li(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},p3e=Gi.extend({fn:L(),num_pins:SA(2).default(2),w:L().default("4.80mm"),h:L().default("2.10mm"),pl:L().default("1.30mm"),pw:L().default("1.40mm"),p:L().default("2.9mm")}),f3e=e=>{const A=p3e.parse(e),t=Ui(0,cA.parse(A.h)-.5,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:cA.parse(A.p)/2,y:cA.parse(A.h)/2},{x:-cA.parse(A.w)/2,y:cA.parse(A.h)/2},{x:-cA.parse(A.w)/2,y:-cA.parse(A.h)/2},{x:cA.parse(A.p)/2,y:-cA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:m3e(A).concat(i,t),parameters:A}},y3e=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},m3e=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=y3e({pn:t,p:Number.parseFloat(e.p)});A.push(li(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},w3e=Gi.extend({fn:L(),num_pins:SA(2).default(2),w:L().default("7.30mm"),h:L().default("4.40mm"),pl:L().default("2.50mm"),pw:L().default("2.30mm"),p:L().default("4.30mm")}),D3e=e=>{const A=w3e.parse(e),t=Ui(0,cA.parse(A.h)/2+.5,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:cA.parse(A.p)/2,y:cA.parse(A.h)/2},{x:-cA.parse(A.w)/2-.1,y:cA.parse(A.h)/2},{x:-cA.parse(A.w)/2-.1,y:-cA.parse(A.h)/2},{x:cA.parse(A.p)/2,y:-cA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:S3e(A).concat(i,t),parameters:A}},x3e=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},S3e=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=x3e({pn:t,p:Number.parseFloat(e.p)});A.push(li(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},b3e=Gi.extend({fn:L(),num_pins:SA(2).default(2),w:L().default("10.70mm"),h:L().default("6.60mm"),pl:L().default("3.30mm"),pw:L().default("2.50mm"),p:L().default("6.80mm")}),_3e=e=>{const A=b3e.parse(e),t=Ui(0,3,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:cA.parse(A.p)/2,y:cA.parse(A.h)/2-.8},{x:-cA.parse(A.w)/2-.8,y:cA.parse(A.h)/2-.8},{x:-cA.parse(A.w)/2-.8,y:-cA.parse(A.h)/2+.8},{x:cA.parse(A.p)/2,y:-cA.parse(A.h)/2+.8}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:v3e(A).concat(i,t),parameters:A}},k3e=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},v3e=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=k3e({pn:t,p:Number.parseFloat(e.p)});A.push(li(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},F3e=Gi.extend({fn:L(),num_pins:qA().default(4),w:L().default("8.50mm"),h:L().default("6.90mm"),pl:L().default("2mm"),pw:L().default("1.5mm"),p:L().default("2.30mm"),string:L().optional()}),M3e=e=>{const A=e.string?.match(/^sot223_(\d+)/),t=A?Number.parseInt(A[1],10):4;if(t===8){const n=N3e.parse({...e,num_pins:t});return{circuitJson:q8(n),parameters:n}}const i=F3e.parse({...e,num_pins:t});if(i.num_pins===4)return{circuitJson:R3e(i),parameters:i};if(i.num_pins===5)return{circuitJson:U3e(i),parameters:i};if(i.num_pins===6)return{circuitJson:Y3e(i),parameters:i};throw new Error("Invalid number of pins")},G3e=e=>{const{pn:A,w:t,p:i}=e;return A===1?{x:-t/2+1.1,y:i}:A===2?{x:-t/2+1.1,y:0}:A===3?{x:-t/2+1.1,y:-i}:{x:t/2-1.1,y:0}},R3e=e=>{const A=[];for(let r=0;r<e.num_pins;r++){const{x:a,y:g}=G3e({num_pins:e.num_pins,pn:r+1,w:Number.parseFloat(e.w),h:Number.parseFloat(e.h),pl:Number.parseFloat(e.pl),p:Number.parseFloat(e.p)}),c=r===3?3.8:Number.parseFloat(e.pw);A.push(li(r+1,a,g,Number.parseFloat(e.pl),c))}const t=Ui(0,0,.3),i=Number.parseFloat(e.w)/2-2.4,n=Number.parseFloat(e.h)/2,o={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-i,y:n},{x:i,y:n},{x:i,y:n/2+.5}],type:"pcb_silkscreen_path",stroke_width:.1},s={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_2",route:[{x:-i,y:-n},{x:i,y:-n},{x:i,y:-n/2-.5}],type:"pcb_silkscreen_path",stroke_width:.1};return[...A,o,s,t]},N3e=Z4({p:"0.90mm",w:"2.8mm",legsoutside:!0}),L3e=e=>{const{p:A,pn:t,w:i}=e;if(t===1)return{x:-i/2+1.2,y:A/2+A};if(t===2)return{x:-i/2+1.2,y:A/2};if(t===3)return{x:-i/2+1.2,y:-A/2};if(t===4)return{x:-i/2+1.2,y:-A/2-A};if(t===5)return{x:i/2-1,y:0};throw new Error("Invalid pin number")},U3e=e=>{const A=[];for(let r=1;r<=e.num_pins;r++){const{x:a,y:g}=L3e({h:Number.parseFloat(e.h),p:1.5,pn:r,w:Number.parseFloat(e.w)});let c=Number.parseFloat(e.pw),I=Number.parseFloat(e.pl);r===5?(c=3.4,I=1.8):(c=1,I=2.2),A.push(li(r,a,g,I,c))}const t=Number.parseFloat(e.w)/2-2.4,i=Number.parseFloat(e.h)/2,n={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-t,y:i},{x:t,y:i},{x:t,y:i/2+.5}],type:"pcb_silkscreen_path",stroke_width:.1},o={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_2",route:[{x:-t,y:-i},{x:t,y:-i},{x:t,y:-i/2-.5}],type:"pcb_silkscreen_path",stroke_width:.1},s=Ui(0,0,.3);return[...A,n,o,s]},H3e=e=>{const{p:A,pn:t,w:i}=e;if(t===1)return{x:-i/2+1.2,y:2*A};if(t===2)return{x:-i/2+1.2,y:A};if(t===3)return{x:-i/2+1.2,y:0};if(t===4)return{x:-i/2+1.2,y:-A};if(t===5)return{x:-i/2+1.2,y:-2*A};if(t===6)return{x:i/2-1.175,y:0};throw new Error("Invalid pin number")},Y3e=e=>{const A=[];for(let r=1;r<=e.num_pins;r++){const{x:a,y:g}=H3e({h:Number.parseFloat(e.h),p:1.3,pn:r,w:8.7});let c=Number.parseFloat(e.pw),I=Number.parseFloat(e.pl);r===6?(c=3.4,I=2.15):(c=.6,I=2.2),A.push(li(r,a,g,I,c))}const t=Number.parseFloat(e.w)/2-2.4,i=Number.parseFloat(e.h)/2,n={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-t,y:i},{x:t,y:i},{x:t,y:i/2+.5}],type:"pcb_silkscreen_path",stroke_width:.1},o={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_2",route:[{x:-t,y:-i},{x:t,y:-i},{x:t,y:-i/2-.5}],type:"pcb_silkscreen_path",stroke_width:.1},s=Ui(0,0,.3);return[...A,n,o,s]},J3e=Gi.extend({fn:L(),num_pins:qA().default(3),w:L().default("3.40mm"),h:L().default("3.30mm"),pl:L().default("1mm"),pw:L().default("0.7mm"),p:L().default("1.2mm"),string:L().optional()}),T3e=e=>{const A=e.string?.match(/^sot23w_(\d+)/),t=A?Number.parseInt(A[1],3):3,i=J3e.parse({...e,num_pins:t});if(i.num_pins===3)return{circuitJson:K3e(i),parameters:i};throw new Error("Invalid number of pins")},P3e=e=>{const{pn:A,p:t}=e;return A===1?{x:-t,y:.95}:A===2?{x:-t,y:-.95}:{x:t,y:0}},K3e=e=>{const A=[];for(let r=0;r<e.num_pins;r++){const{x:a,y:g}=P3e({num_pins:e.num_pins,pn:r+1,w:Number.parseFloat(e.w),h:Number.parseFloat(e.h),pl:Number.parseFloat(e.pl),p:Number.parseFloat(e.p)});A.push(li(r+1,a,g,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}const t=Ui(0,Number.parseInt(e.h)/2+1,.3),i=Number.parseFloat(e.w)/2-1,n=Number.parseFloat(e.h)/2,o={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-i,y:n},{x:i+.3,y:n},{x:i+.3,y:n/2}],type:"pcb_silkscreen_path",stroke_width:.1},s={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_2",route:[{x:-i,y:-n},{x:i+.3,y:-n},{x:i+.3,y:-n/2}],type:"pcb_silkscreen_path",stroke_width:.1};return[...A,o,s,t]},q3e=Gi.extend({fn:L(),num_pins:_e([SA(3),SA(2)]).default(3),p:L().default("1.27mm"),id:L().default("0.72mm"),od:L().default("0.95mm"),w:L().default("2.5mm"),h:L().default("4.2mm"),string:L().optional()}),O3e=e=>{const{p:A,id:t,od:i,w:n,h:o}=e,s=Number.parseFloat(o)/2,r=Number.parseFloat(A);return[Fo(1,-r,s-r,t,i),Fo(2,0,s-r,t,i),Fo(3,r,s-r,t,i)]},W3e=e=>{const{p:A,id:t,od:i,h:n}=e,o=Number.parseFloat(n)/2,s=Number.parseFloat(A);return[Fo(1,-s,o-s,t,i),Fo(2,s,o-s,t,i)]},Z3e=e=>{const A=e.string?.match(/^to92s_(\d+)/),t=A?Number.parseInt(A[1],10):3,i=q3e.parse({...e,num_pins:t});let n=[];if(i.num_pins===3)n=O3e(i);else if(i.num_pins===2)n=W3e(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=Ui(0,o+1,.5);return{circuitJson:[...n,r,a],parameters:i}},V3e=Gi.extend({fn:L(),p:cA.optional(),id:cA.optional(),pw:cA.optional(),pl:cA.optional(),w:cA.optional(),h:cA.optional(),sh:HA().optional().describe('JST SH (Surface-mount) connector family. SH stands for "Super High-density".'),ph:HA().optional().describe('JST PH (Through-hole) connector family. PH stands for "Pin Header".'),zh:HA().optional().describe("JST ZH (Through-hole) connector family. 1.5mm pitch wire-to-board."),string:L().optional()}),j3e={ph:{p:cA.parse("2.2mm"),id:cA.parse("0.70mm"),pw:cA.parse("1.20mm"),pl:cA.parse("1.20mm"),w:cA.parse("6mm"),h:cA.parse("5mm")},sh:{p:cA.parse("1mm"),pw:cA.parse("0.6mm"),pl:cA.parse("1.55mm"),w:cA.parse("5.8mm"),h:cA.parse("7.8mm")},zh:{p:cA.parse("1.5mm"),id:cA.parse("0.73mm"),pw:cA.parse("1.03mm"),pl:cA.parse("1.73mm"),w:cA.parse("3mm"),h:cA.parse("3.5mm")}};function z3e(e){return e.sh?"sh":e.ph?"ph":e.zh?"zh":"ph"}function X3e(e,A,t,i,n,o){const s=[];if(e==="ph"){const r=-((A-1)/2)*t;for(let a=0;a<A;a++){const g=r+a*t;s.push(lm({pn:a+1,x:g,y:2,holeDiameter:i,rectPadWidth:n,rectPadHeight:o}))}}else if(e==="zh"){const r=-((A-1)/2)*t;for(let a=0;a<A;a++){const g=r+a*t;a===0?s.push(lm({pn:a+1,x:g,y:0,holeDiameter:i,rectPadWidth:n,rectPadHeight:o,rectBorderRadius:.12499977})):s.push(z4(a+1,g,0,i,n,o))}}else{const r=-((A-1)/2)*t;for(let g=0;g<A;g++){const c=r+g*t;s.push(li(g+1,c,-1.325,n,o))}const a=(A-1)/2*t+1.3;s.push(li(A+1,-a,1.22,1.2,1.8)),s.push(li(A+2,a,1.22,1.2,1.8))}return s}function $3e(e,A,t,i,n){if(e==="ph")return{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:""};if(e==="zh"&&i&&n){const o=(i-1)*n,s=-o/2-1.5,r=o/2+1.5,a=-t/2,g=t/2;return{type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:s,y:a},{x:r,y:a},{x:r,y:g},{x:s,y:g},{x:s,y:a}],stroke_width:.1,pcb_silkscreen_path_id:""}}else return{type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[],stroke_width:.1,pcb_silkscreen_path_id:""}}var A5e=e=>{const A=V3e.parse(e),t=z3e(A),i=j3e[t],n=A.p??i.p,o=A.id??i.id,s=A.pw??i.pw,r=A.pl??i.pl,a=A.w??i.w,g=A.h??i.h;let c;const I=e.num_pins;typeof I=="number"&&(c=I);const l=typeof e.string=="string"?e.string:"",B=l.match(/(?:^|_)jst(\d+)(?:_|$)/),C=l.match(/(?:^|_)zh(\d+)(?:_|$)/);if(B&&B[1]){const u=Number.parseInt(B[1],10);Number.isNaN(u)||(c=u)}if(C&&C[1]){const u=Number.parseInt(C[1],10);Number.isNaN(u)||(c=u)}if(typeof c!="number")throw new Error(`JST requires an explicit pin count (e.g. jst6_sh or .jst(6))${A.string?`, from string "${A.string}"`:""}`);const Q=X3e(t,c,n,o,s,r),h=$3e(t,a,g,c,n),E=Ui(0,g/2+1,.5);return{circuitJson:[...Q,h,E],parameters:{...A,p:n,id:o,pw:s,pl:r,w:a,h:g,num_pins:c,sh:t==="sh",ph:t==="ph",zh:t==="zh"}}},t5e=Gi.extend({fn:L(),num_pins:SA(2).default(2),w:L().default("3.30mm"),h:L().default("1.70mm"),pl:L().default("0.80mm"),pw:L().default("1mm"),p:L().default("1.90mm")}),e5e=e=>{const A=t5e.parse(e),t=Ui(0,cA.parse(A.h)/2+.5,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:cA.parse(A.p)/2,y:cA.parse(A.h)/2},{x:-cA.parse(A.w)/2,y:cA.parse(A.h)/2},{x:-cA.parse(A.w)/2,y:-cA.parse(A.h)/2},{x:cA.parse(A.p)/2,y:-cA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:n5e(A).concat(i,t),parameters:A}},i5e=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},n5e=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=i5e({pn:t,p:Number.parseFloat(e.p)});A.push(li(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},o5e=e=>{switch(e){case 8:return{w:"3.06mm",h:"3.14mm",p:"0.65mm",pl:"1.6mm",pw:"0.5mm"};case 10:return{w:"3.10mm",h:"3.33mm",p:"0.5mm",pl:"1.45mm",pw:"0.3mm"};default:return{w:"3.06mm",h:"3.14mm",p:"0.65mm",pl:"1.6mm",pw:"0.5mm"}}},s5e=Gi.extend({fn:L(),num_pins:_e([SA(8),SA(10)]).default(8),w:L().optional(),h:L().optional(),p:L().optional(),pl:L().optional(),pw:L().optional(),string:L().optional()}),r5e=e=>{const A=s5e.parse(e),t=o5e(A.num_pins),i=cA.parse(A.w||t.w),n=cA.parse(A.h||t.h),o=cA.parse(A.p||t.p),s=cA.parse(A.pl||t.pl),r=cA.parse(A.pw||t.pw),a=[],g=A.num_pins/2;for(let u=0;u<A.num_pins;u++){const{x:d,y:f}=pet(A.num_pins,u+1,i,o),m=u<g?u+1:A.num_pins-(u-g);a.push(li(m,d,f,s,r))}const c=i,I=n,l={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-c/2,y:I/2},{x:c/2,y:I/2}],stroke_width:.05,pcb_silkscreen_path_id:""},B={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-c/2,y:-I/2},{x:c/2,y:-I/2}],stroke_width:.05,pcb_silkscreen_path_id:""},C=pet(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=Ui(0,I/2+.5,.3);return{circuitJson:[...a,l,B,E,h],parameters:A}},pet=(e,A,t,i)=>{const n=e/2,o=(A-1)%n,s=A<=n?-1:1,r=(n-1)/2-o;return{x:s*cA.parse(e===8?"1.8mm":"2.2mm"),y:r*i}},a5e=e=>{switch(e){case 10:return{w:"3.10mm",h:"3.32mm",p:"0.5mm",pl:"1.63mm",pw:"0.33mm"};case 12:return{w:"3mm",h:"4mm",p:"0.65mm",pl:"0.88mm",pw:"0.4mm"};case 16:return{w:"3.10mm",h:"4mm",p:"0.5mm",pl:"0.88mm",pw:"0.3mm"};default:return{w:"3.10mm",h:"3.32mm",p:"0.65mm",pl:"1.63mm",pw:"0.4mm"}}},g5e=Gi.extend({fn:L(),num_pins:_e([SA(8),SA(10),SA(12),SA(16)]).default(8),w:L().optional(),h:L().optional(),p:L().optional(),pl:L().optional(),pw:L().optional(),string:L().optional()}),fet=(e,A,t,i)=>{const n=e/2,o=(A-1)%n,s=A<=n?-1:1,r=(n-1)/2-o;return{x:s*cA.parse("2mm"),y:r*i}},c5e=e=>{const A=g5e.parse(e),t=a5e(A.num_pins),i=cA.parse(A.w||t.w),n=cA.parse(A.h||t.h),o=cA.parse(A.p||t.p),s=cA.parse(A.pl||t.pl),r=cA.parse(A.pw||t.pw),a=[];for(let E=0;E<A.num_pins;E++){const{x:u,y:d}=fet(A.num_pins,E+1,i,o);a.push(li(E+1,u,d,s,r))}const g=i,c=n,I={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-g/2,y:c/2},{x:g/2,y:c/2}],stroke_width:.05,pcb_silkscreen_path_id:""},l={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-g/2,y:-c/2},{x:g/2,y:-c/2}],stroke_width:.05,pcb_silkscreen_path_id:""},B=fet(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=Ui(0,c/2+.5,.3);return{circuitJson:[...a,I,l,h,Q],parameters:A}},I5e=Gi.extend({fn:L(),num_pins:SA(2).default(2),w:L().default("3.8mm"),h:L().default("1.65mm"),pl:L().default("1.2mm"),pw:L().default("1.2mm"),pad_spacing:L().default("2.6mm")}),l5e=e=>{const A=I5e.parse(e),t=Ui(0,cA.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:cA.parse(A.pad_spacing)/2,y:cA.parse(A.h)/2},{x:-cA.parse(A.w)/2-.2,y:cA.parse(A.h)/2},{x:-cA.parse(A.w)/2-.2,y:-cA.parse(A.h)/2},{x:cA.parse(A.pad_spacing)/2,y:-cA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:C5e(A).concat(i,t),parameters:A}},B5e=e=>{const{pn:A,pad_spacing:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},C5e=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=B5e({pn:t,pad_spacing:Number.parseFloat(e.pad_spacing)});A.push(li(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},Q5e=Gi.extend({fn:L(),num_pins:SA(2).default(2),w:L().default("3.20mm"),h:L().default("1.65mm"),pl:L().default("0.8mm"),pw:L().default("0.9mm"),pad_spacing:L().default("2.1mm")}),h5e=e=>{const A=Q5e.parse(e),t=Ui(0,cA.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:cA.parse(A.pad_spacing)/2,y:cA.parse(A.h)/2},{x:-cA.parse(A.w)/2-.2,y:cA.parse(A.h)/2},{x:-cA.parse(A.w)/2-.2,y:-cA.parse(A.h)/2},{x:cA.parse(A.pad_spacing)/2,y:-cA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:u5e(A).concat(i,t),parameters:A}},E5e=e=>{const{pn:A,pad_spacing:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},u5e=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=E5e({pn:t,pad_spacing:Number.parseFloat(e.pad_spacing)});A.push(li(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},d5e=Gi.extend({fn:L(),num_pins:_e([SA(6),SA(8)]).default(8),w:L().default("3mm"),h:L().default("3mm"),p:L().default("0.5mm"),pl:L().default("0.52mm"),pw:L().default("0.35mm"),epw:L().default("1.40mm"),eph:L().default("1.60mm"),string:L().optional(),ep:HA().default(!1)}),p5e=e=>{e.string&&e.string.includes("_ep")&&(e.ep=!0);const A=e.string?.match(/^son_(\d+)/),t=A?Number.parseInt(A[1],10):e.num_pins||8,i=d5e.parse({...e,num_pins:t}),n=cA.parse(i.w),o=cA.parse(i.h),s=cA.parse(i.p),r=cA.parse(i.pl),a=cA.parse(i.pw),g=cA.parse(i.epw),c=cA.parse(i.eph),I=[];for(let f=0;f<i.num_pins;f++){const{x:m,y:w}=yet(i.num_pins,f+1,n,s);I.push(li(f+1,m,w,r,a))}i.ep&&I.push(li(i.num_pins+1,0,0,g,c));const l=n,B=o,C={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-l/2,y:B/2},{x:l/2,y:B/2}],stroke_width:.05,pcb_silkscreen_path_id:""},Q={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-l/2,y:-B/2},{x:l/2,y:-B/2}],stroke_width:.05,pcb_silkscreen_path_id:""},h=yet(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=Ui(0,B/2+.5,.3);return{circuitJson:[...I,C,Q,d,u],parameters:i}},yet=(e,A,t,i)=>{const n=e/2,o=(A-1)%n,s=A<=n?-1:1,r=(n-1)/2-o;return{x:s*cA.parse("1.4mm"),y:r*i}},f5e=Gi.extend({fn:L(),num_pins:qA().optional().default(8),p:st.describe("pitch (distance between center of each pin)"),w:cA.describe("width between vertical rows of pins"),grid:BO.describe("width and height of the border of the footprint"),ep:BO.default("0x0mm").describe("width and height of the central exposed thermal pad"),epx:cA.default("0mm").describe("x offset of the center of the central exposed thermal pad"),pinw:cA.describe("width of the pin pads"),pinh:cA.describe("height of the pin pads")}),y5e=e=>{const A=f5e.parse(e),{num_pins:t,p:i,w:n,grid:o,ep:s,epx:r,pinw:a,pinh:g}=A;if(t%2!==0)throw new Error("invalid number of pins");const c=[];for(let B=0;B<t;B++){const{pinX:C,pinY:Q}=m5e({pinCount:t,pinIndex:B,width:n,pitch:i});c.push(li(B+1,C,Q,a,g))}s.x>0&&s.y>0&&c.push(li(A.num_pins+1,r,0,s.x,s.y));const I=w5e(o),l=Ui(0,o.y/2+i,o.y/6);return{circuitJson:[...c,...I,l],parameters:A}},m5e=e=>{let A=0,t=0;const i=(e.pinCount/2-1)*e.pitch/2,n=e.pinCount/2;return e.pinIndex+1<=n?(A=e.pitch*e.pinIndex-i,t=0-e.width/2):(A=e.pitch*(e.pinCount-e.pinIndex-1)-i,t=e.width/2),{pinX:t,pinY:A}},w5e=e=>{const t=e.y/30;return[{layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"",type:"pcb_silkscreen_path",route:[{x:-e.x/2-.1,y:e.y/2+.1-t},{x:-e.x/2-.1,y:e.y/2+.1},{x:e.x/2+.1,y:e.y/2+.1},{x:e.x/2+.1,y:e.y/2+.1-t}],stroke_width:e.y/30},{layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"",type:"pcb_silkscreen_path",route:[{x:-e.x/2-.1,y:-e.y/2-.1+t},{x:-e.x/2-.1,y:-e.y/2-.1},{x:e.x/2+.1,y:-e.y/2-.1},{x:e.x/2+.1,y:-e.y/2-.1+t}],stroke_width:e.y/30}]},D5e=e=>{const{num_pins:A,bridged:t,p:i=2.54,pw:n=1.5,ph:o=1.5}=e,s=cA.parse(i),r=cA.parse(n),a=cA.parse(o),g=Math.min(a/4,.5),c=[];for(let f=0;f<A;f++)c.push(li(f+1,f*s,0,r,a));let I=[];if(t){const f=t.split("").map(Number);if(f.length>1)for(let m=0;m<f.length-1;m++){const w=f[m],D=f[m+1];if(typeof w=="number"&&typeof D=="number"&&!isNaN(w)&&!isNaN(D)){const x=(w-1)*s,_=(D-1)*s,b=Math.sign(_-x),R=x+b*(r/2),F=_-b*(r/2);I.push({type:"pcb_trace",pcb_trace_id:"",route:[{start_pcb_port_id:`{PIN${w}}`,x:R,y:0,width:g,layer:"top",route_type:"wire"},{end_pcb_port_id:`{PIN${D}}`,x:F,y:0,width:g,layer:"top",route_type:"wire"}]})}}}const l=(A-1)*s+r+.7,B=a+1,C=(A-1)*s/2,Q=0,h={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"outline",route:[{x:C-l/2,y:Q-B/2},{x:C+l/2,y:Q-B/2},{x:C+l/2,y:Q+B/2},{x:C-l/2,y:Q+B/2},{x:C-l/2,y:Q-B/2}],stroke_width:.15},u=Q+B/2+.6,d=Ui(C,u,.4);return{circuitJson:[...c,...I,h,d],parameters:e}},met={fn:SA("sot457"),num_pins:SA(6).default(6),pillh:L().default("0.45mm"),pillw:L().default("1.45mm"),pl:L(),pw:L(),p:L(),wave:HA().optional(),reflow:HA().optional()},x5e=Gi.extend({...met,h:L().default("2.5mm"),w:L().default("2.7mm"),pl:L().default("0.8mm"),pw:L().default("0.55mm"),p:L().default("0.95mm")}),S5e=Gi.extend({...met,h:L().default("3mm"),w:L().default("4mm"),pillr:L().default("0.225mm"),pl:L().default("1.45mm"),pw:L().default("1.5mm"),p:L().default("1.475mm")}).transform(e=>({...e,wave:e.wave??(e.reflow===void 0?!0:!e.reflow),reflow:e.reflow??(e.wave===void 0?!1:!e.wave)})),N2=e=>Number.parseFloat(e.replace("mm","")),wet=({pitch:e,width:A,pinNumber:t})=>{const o={1:{x:-A/2-.1,y:e},2:{x:-A/2-.1,y:0},3:{x:-A/2-.1,y:-e},4:{x:A/2+.1,y:-e},5:{x:A/2+.1,y:0},6:{x:A/2+.1,y:e}}[t];if(!o)throw new Error(`Invalid pin number: ${t}`);return o},Det=e=>{const A=[],t=N2(e.p),i=N2(e.pl),n=N2(e.pw),o=N2(e.w),s=N2(e.h);if(e.wave){const C={1:({padWidth:Q,padHeight:h})=>li(1,-t,t,h,Q),2:({padWidth:Q,padHeight:h})=>li(2,-t,-t,h,Q),3:({padWidth:Q,padHeight:h})=>CO(3,-t,0,N2(e.pillw),N2(e.pillh)),4:({padWidth:Q,padHeight:h})=>CO(4,t,0,N2(e.pillw),N2(e.pillh)),5:({padWidth:Q,padHeight:h})=>li(5,t,t,h,Q),6:({padWidth:Q,padHeight:h})=>li(6,t,-t,h,Q)};for(let Q=1;Q<=e.num_pins;Q++){const h=C[Q];h&&A.push(h({padWidth:i,padHeight:n}))}}else for(let C=1;C<=e.num_pins;C++){const{x:Q,y:h}=wet({pitch:t,width:o,pinNumber:C});A.push(li(C,Q,h,i,n))}const r={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-o/3,y:s/2+t/1.3},{x:o/3,y:s/2+t/1.3}],stroke_width:.05},a={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_2",route:[{x:-o/3,y:-s/2-t/1.3},{x:o/3,y:-s/2-t/1.3}],stroke_width:.05},g=Ui(0,s+.5,.3),c=wet({pitch:t,width:o,pinNumber:1}),I=e.wave?1:.5,l=e.wave?.7:.3;c.x-=e.wave?n:n*1.7;const B={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"pin1_indicator",route:[{x:c.x+I/2,y:c.y},{x:c.x-I/2,y:c.y+l/2},{x:c.x-I/2,y:c.y-l/2},{x:c.x+I/2,y:c.y}],stroke_width:.05};return[g,r,a,B,...A]},b5e=e=>{if(e.wave){const t=S5e.parse({...e,fn:"sot457"});return{circuitJson:Det(t),parameters:t}}const A=x5e.parse(e);return{circuitJson:Det(A),parameters:A}},_5e=Gi.extend({fn:L(),num_pins:SA(6).default(6),w:L().default("1.1mm"),h:L().default("1.45mm"),p:L().default("0.35mm"),pl:L().default("0.2mm"),pw:L().default("0.2mm"),string:L().optional()}),k5e=e=>{const A=_5e.parse({...e,fn:"sot963"}),t=cA.parse(A.w),i=cA.parse(A.h),n=cA.parse(A.p),o=cA.parse(A.pl),s=cA.parse(A.pw),r=[];for(let B=0;B<6;B++){const{x:C,y:Q}=xet(B+1,t,n,o);r.push(li(B+1,C,Q,o,s))}const a={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-t/2,y:i/2},{x:t/2,y:i/2}],stroke_width:.05,pcb_silkscreen_path_id:""},g={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-t/2,y:-i/2},{x:t/2,y:-i/2}],stroke_width:.05,pcb_silkscreen_path_id:""},c=xet(1,t,n,o),I={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"pin_marker_1",route:[{x:c.x-o/2-.3,y:c.y},{x:c.x-o/2-.45,y:c.y+.15},{x:c.x-o/2-.45,y:c.y-.15},{x:c.x-o/2-.3,y:c.y}],stroke_width:.05,pcb_silkscreen_path_id:"pin_marker_1"},l=Ui(0,i/2+.4,.25);return{circuitJson:[...r,a,g,l,I],parameters:A}},xet=(e,A,t,i)=>{const n=A/2-i/2;return e<=3?{x:-n,y:t-(e-1)*t}:{x:n,y:-t+(e-4)*t}},v5e=Gi.extend({fn:L(),num_pins:_e([SA(3),SA(2)]).default(3),p:L().default("3.8mm"),id:L().default("1.25mm"),od:L().default("2.35mm"),ca:L().default("14mm").describe("Caliper axis (width or diameter of the potentiometer body or adjustment knob)"),w:L().default("5.35mm"),h:L().default("4mm"),string:L().optional()}),F5e=e=>{const{p:A,id:t,od:i,h:n,ca:o}=e,s=Number.parseFloat(n),r=Number.parseFloat(o);return[Fo(1,0,r/4+.3,t,i),Fo(2,s,0,t,i),Fo(3,0,-r/4-.3,t,i)]},M5e=e=>{const A=e.string?.match(/^potentiometer_(\d+)/),t=A?Number.parseInt(A[1],10):3,i=v5e.parse({...e,num_pins:t});let n=[];i.num_pins===3&&(n=F5e(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=Ui(c,o+1,.5);return{circuitJson:[...n,a,g,I],parameters:i}},G5e=Gi.extend({fn:L(),p:cA.optional().default("7.5mm"),id:cA.optional().default("1mm"),od:cA.optional().default("2mm"),d:cA.optional().default("10.5mm")}),R5e=(e,A,t,i,n)=>{const o=[],s=[];for(let r=0;r<=50;r++){const a=r/50*Math.PI,g=e+Math.cos(a)*t,c=A+Math.sin(a)*t;g<e-i&&c>=A-n/2&&c<=A+n/2||o.push({x:g,y:c})}for(let r=0;r<=50;r++){const a=Math.PI+r/50*Math.PI,g=e+Math.cos(a)*t,c=A+Math.sin(a)*t;g<e-i&&c>=A-n/2&&c<=A+n/2||s.push({x:g,y:c})}return{topArc:o,bottomArc:s}},N5e=e=>{const A=G5e.parse(e),{p:t,id:i,od:n,d:o}=A,s=[Fo(1,-t/2,0,i,n),Fo(2,t/2,0,i,n)],{topArc:r,bottomArc:a}=R5e(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=Ui(0,o/2+1,.5);return{circuitJson:[...s,g,c,I,Q,h,E],parameters:A}},L5e=Gi.extend({fn:L(),num_pins:SA(2).default(2),w:L().default("6.5mm"),h:L().default("3mm"),pl:L().default("1.75mm"),pw:L().default("2.40mm"),p:L().default("4.75mm")}),U5e=e=>{const A=L5e.parse(e),t=Ui(0,cA.parse(A.h)-.5,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:cA.parse(A.p)/2,y:cA.parse(A.h)/2},{x:-cA.parse(A.w)/2-.3,y:cA.parse(A.h)/2},{x:-cA.parse(A.w)/2-.3,y:-cA.parse(A.h)/2},{x:cA.parse(A.p)/2,y:-cA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:Y5e(A).concat(i,t),parameters:A}},H5e=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},Y5e=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=H5e({pn:t,p:Number.parseFloat(e.p)});A.push(li(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},J5e=Gi.extend({fn:L(),num_pins:qA().default(3),w:L().default("2.45mm"),h:L().default("2.40mm"),pl:L().default("0.92mm"),pw:L().default("0.45mm"),p:L().default("0.891mm"),string:L().optional()}),T5e=e=>{const A=e.string?.match(/^sot323_(\d+)/),t=A?Number.parseInt(A[1],3):3,i=J5e.parse({...e,num_pins:t});if(i.num_pins===3)return{circuitJson:K5e(i),parameters:i};throw new Error("Invalid number of pins")},P5e=e=>{const{pn:A,p:t}=e;return A===1?{x:-t,y:.65}:A===2?{x:-t,y:-.65}:{x:t,y:0}},K5e=e=>{const A=[];for(let r=0;r<e.num_pins;r++){const{x:a,y:g}=P5e({num_pins:e.num_pins,pn:r+1,w:Number.parseFloat(e.w),h:Number.parseFloat(e.h),pl:Number.parseFloat(e.pl),p:Number.parseFloat(e.p)});A.push(li(r+1,a,g,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}const t=Ui(0,Number.parseInt(e.h)/2+1,.3),i=Number.parseFloat(e.w)/2-Number.parseFloat(e.pl),n=Number.parseFloat(e.h)/2,o={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-i,y:n+.3},{x:i,y:n+.3},{x:i,y:n/2}],type:"pcb_silkscreen_path",stroke_width:.1},s={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_2",route:[{x:-i,y:-n-.3},{x:i,y:-n-.3},{x:i,y:-n/2}],type:"pcb_silkscreen_path",stroke_width:.1};return[...A,o,s,t]},q5e=Gi.extend({fn:L(),circle:HA().optional(),rect:HA().optional(),square:HA().optional(),pill:HA().optional(),d:cA.optional(),pd:cA.optional(),diameter:cA.optional(),r:cA.optional(),pr:cA.optional(),radius:cA.optional(),w:cA.optional(),pw:cA.optional(),width:cA.optional(),h:cA.optional(),ph:cA.optional(),height:cA.optional(),s:cA.optional(),size:cA.optional(),string:L().optional()}).transform(e=>{let A="rect";e.circle&&(A="circle"),e.square&&(A="square"),e.rect&&(A="rect"),e.pill&&(A="pill");let t,i,n;return A==="circle"?e.r!==void 0?t=cr(e.r):e.pr!==void 0?t=cr(e.pr):e.radius!==void 0?t=cr(e.radius):e.d!==void 0?t=cr(e.d)/2:e.pd!==void 0?t=cr(e.pd)/2:e.diameter!==void 0?t=cr(e.diameter)/2:t=cr("1mm")/2:(e.w!==void 0?i=cr(e.w):e.pw!==void 0?i=cr(e.pw):e.width!==void 0?i=cr(e.width):e.s!==void 0?i=cr(e.s):e.size!==void 0?i=cr(e.size):i=cr("1mm"),e.h!==void 0?n=cr(e.h):e.ph!==void 0?n=cr(e.ph):e.height!==void 0?n=cr(e.height):A==="square"||A==="rect"?n=i:n=cr("1mm")),{fn:e.fn,shape:A,radius:t,width:i,height:n}}),O5e=e=>{const A=q5e.parse(e),{shape:t,radius:i,width:n,height:o}=A;let s,r;return t==="circle"?(s=iet(1,{x:0,y:0,radius:i}),r=i+.5):t==="pill"?(s=CO(1,0,0,n,o),r=Math.max(n,o)/2+.5):(s=li(1,0,0,n,o),r=o/2+.5),{circuitJson:[s,Ui(0,r,.2)],parameters:A}},W5e=Gi.extend({fn:L(),d:cA.optional(),hd:cA.optional(),r:cA.optional(),hr:cA.optional(),pd:cA.optional(),pr:cA.optional(),squarepad:HA().optional().default(!1)}).transform(e=>{let A;e.d!==void 0?A=cr(e.d):e.hd!==void 0?A=cr(e.hd):e.r!==void 0?A=cr(e.r)*2:e.hr!==void 0?A=cr(e.hr)*2:A=cr("1mm");let t;return e.pd!==void 0?t=cr(e.pd):e.pr!==void 0?t=cr(e.pr)*2:t=A*(1.5/1),{fn:e.fn,d:A,pd:t,squarepad:e.squarepad??!1}}),Z5e=e=>{const A=W5e.parse(e),{d:t,pd:i,squarepad:n}=A;return{circuitJson:[n?lm({pn:1,x:0,y:0,holeDiameter:t,rectPadWidth:i,rectPadHeight:i}):Fo(1,0,0,t,i),Ui(0,i/2+.5,.2)],parameters:A}},V5e=Gi.extend({fn:L(),num_pins:SA(6).default(6),h:L().default("1.6mm"),pl:L().default("1mm"),pw:L().default("0.7mm"),p:L().default("0.95mm")}),j5e=e=>{const A=V5e.parse(e);return{circuitJson:z5e(A),parameters:A}},bet=e=>{const{p:A,h:t,pn:i}=e;if(i===1)return{x:-t/2-.5,y:A};if(i===2)return{x:-t/2-.5,y:0};if(i===3)return{x:-t/2-.5,y:-A};if(i===4)return{x:t/2+.5,y:-A};if(i===5)return{x:t/2+.5,y:0};if(i===6)return{x:t/2+.5,y:A};throw new Error("Invalid pin number")},z5e=e=>{const A=[];for(let I=1;I<=e.num_pins;I++){const{x:l,y:B}=bet({h:Number.parseFloat(e.h),p:Number.parseFloat(e.p),pn:I});A.push(li(I,l,B,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}const t=e.num_pins/2*Number.parseFloat(e.p),i=Number.parseFloat(e.h),n={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-t/3,y:i/2+Number.parseFloat(e.p)/1.3},{x:t/3,y:i/2+Number.parseFloat(e.p)/1.3}],type:"pcb_silkscreen_path",stroke_width:.05},o={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_2",route:[{x:-t/3,y:-i/2-Number.parseFloat(e.p)/1.3},{x:t/3,y:-i/2-Number.parseFloat(e.p)/1.3}],type:"pcb_silkscreen_path",stroke_width:.05},s=Ui(0,i+.3,.3),r=bet({h:Number.parseFloat(e.h),p:Number.parseFloat(e.p),pn:1});r.x=r.x-Number.parseFloat(e.pw)*1.5;const a=.7,g=.3,c={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"pin1_indicator",route:[{x:r.x+a/2,y:r.y},{x:r.x-a/2,y:r.y+g/2},{x:r.x-a/2,y:r.y-g/2},{x:r.x+a/2,y:r.y}],stroke_width:.05};return[...A,s,n,o,c]},X5e=Gi.extend({fn:L(),num_pins:qA().default(4),w:L().default("3.2mm"),h:L().default("2.6mm"),pl:L().default("1.05mm"),pw:L().default("0.45mm"),p:L().default("0.55mm"),string:L().optional()}),$5e=e=>{const A=e.string?.match(/^sot343_(\d+)/),t=A?Number.parseInt(A[1],4):4,i=X5e.parse({...e,num_pins:t});if(i.num_pins===4)return{circuitJson:tke(i),parameters:i};throw new Error("Invalid number of pins")},Ake=e=>{const{pn:A,p:t}=e;return A===1?{x:-t*1.92,y:-.65}:A===2?{x:-t*1.92,y:.65}:A===3?{x:t,y:.65}:A===4?{x:t,y:-.65}:{x:0,y:0}},tke=e=>{const A=[],t=Number.parseFloat(e.w),i=Number.parseFloat(e.h),n=Number.parseFloat(e.pl),o=Number.parseFloat(e.pw),s=Number.parseFloat(e.p);let r=1/0,a=-1/0,g=1/0,c=-1/0;for(let d=0;d<e.num_pins;d++){const{x:f,y:m}=Ake({num_pins:e.num_pins,pn:d+1,p:s});A.push(li(d+1,f,m,n,o)),f<r&&(r=f),f>a&&(a=f),m<g&&(g=m),m>c&&(c=m)}const I=(r+a)/2,l=c-g,B=i*.3,C=l/2+B;let Q=t*.8;i<=2.6&&(Q/=2);const h=Ui(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]},eke=Gi.extend({fn:L()}),ike=e=>{const A=eke.parse(e),t=[],i=.5-.15,n=1.5,s=.5/2,r=75,a=-37/2;for(let D=0;D<r;D++){const x=D+1;if(x>=24&&x<=31)continue;const _=a-D*s,b=x%2===0,R=n+(b?.25:0),H=.5-R/2,Y=li(x,H,_,R,i);Y.layer=b?"bottom":"top",t.push(Y)}const g=46*.0254,c=137*.0254,I=261*.0254,l={type:"pcb_cutout",pcb_cutout_id:"",shape:"rect",center:{x:-c/2+n/2,y:a-I},width:c,height:g},B={x:-.5,y:a},C={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"pin_marker_1",route:[{x:B.x-.4,y:B.y},{x:B.x-.7,y:B.y+.3},{x:B.x-.7,y:B.y-.3},{x:B.x-.4,y:B.y}],stroke_width:.05,pcb_silkscreen_path_id:"pin_marker_1"};let Q=1/0,h=-1/0,E=1/0,u=-1/0;const d=(D,x,_=0,b=0)=>{Q=Math.min(Q,D-_/2),h=Math.max(h,D+_/2),E=Math.min(E,x-b/2),u=Math.max(u,x+b/2)};for(const D of t){const x=D;d(x.x,x.y,x.width,x.height)}d(l.center.x,l.center.y,l.width,l.height);for(const D of C.route)d(D.x,D.y);const f=(Q+h)/2,m=(E+u)/2,w=D=>{typeof D.x=="number"&&(D.x-=f),typeof D.y=="number"&&(D.y-=m),D.center&&(D.center.x-=f,D.center.y-=m),Array.isArray(D.route)&&(D.route=D.route.map(x=>({x:x.x-f,y:x.y-m})))};for(const D of t)w(D);return w(l),w(C),{circuitJson:[...t,l,C],parameters:A}},nke=Gi.extend({fn:L(),numPins:qA().optional().default(0),rows:_e([L(),qA()]).transform(e=>Number(e)).optional().default(1).describe("number of rows"),p:cA.default("2.54mm").describe("pitch"),id:cA.default("1.0mm").describe("inner diameter"),od:cA.default("1.5mm").describe("outer diameter"),male:HA().optional().describe("the module uses male headers"),nopin:HA().optional().default(!1).describe("omit pins rendering"),female:HA().optional().describe("the module uses female headers"),smd:HA().optional().describe("surface mount device"),pinlabeltextalignleft:HA().optional().default(!1),pinlabeltextaligncenter:HA().optional().default(!1),pinlabeltextalignright:HA().optional().default(!1),pinlabelverticallyinverted:HA().optional().default(!1),pinlabelorthogonal:HA().optional().default(!1),nopinlabels:HA().optional().default(!1).describe("omit silkscreen pin labels"),doublesidedpinlabel:HA().optional().default(!1).describe("add silkscreen pins in top and bottom layers"),bottomsidepinlabel:HA().optional().default(!1).describe("place the silkscreen reference text on the bottom layer instead of top"),pinRowSide:Vt(["left","right","top","bottom"]).optional().default("left"),pinrowleft:HA().optional().default(!1),pinrowright:HA().optional().default(!1),pinrowtop:HA().optional().default(!1),pinrowbottom:HA().optional().default(!1),pinrowleftpins:_e([L(),qA()]).transform(e=>Number(e)).optional(),pinrowrightpins:_e([L(),qA()]).transform(e=>Number(e)).optional(),pinrowtoppins:_e([L(),qA()]).transform(e=>Number(e)).optional(),pinrowbottompins:_e([L(),qA()]).transform(e=>Number(e)).optional(),width:cA.optional(),height:cA.optional(),pinRowHoleEdgeToEdgeDist:cA.default("2mm"),holes:_e([L(),xt(L())]).optional().transform(e=>!e||Array.isArray(e)?e:e.startsWith("(")&&e.endsWith(")")?e.slice(1,-1).split(",").map(A=>A.trim()):[e]),holeXDist:cA.optional(),holeYDist:cA.optional(),holeInset:cA.default("1mm"),pinrow:_e([L(),qA()]).optional(),usbposition:Vt(["left","right","top","bottom"]).optional().default("left"),usbleft:HA().optional().default(!1),usbtop:HA().optional().default(!1),usbright:HA().optional().default(!1),usbbottom:HA().optional().default(!1),usbtype:Vt(["micro","c"]).optional(),usbmicro:HA().optional().default(!1),usbc:HA().optional().default(!1),screen:HA().optional().default(!1).describe("add silkscreen outline for screen/display area"),screenwidth:cA.optional(),screenheight:cA.optional(),screencenteroffsetx:cA.optional(),screencenteroffsety:cA.optional()}).transform(e=>{const A=Bet(e);let t=e.pinRowSide;e.pinrowleft&&(t="left"),e.pinrowright&&(t="right"),e.pinrowtop&&(t="top"),e.pinrowbottom&&(t="bottom");let i=e.usbposition;e.usbleft&&(i="left"),e.usbtop&&(i="top"),e.usbright&&(i="right"),e.usbbottom&&(i="bottom");let n=e.usbtype;e.usbmicro&&(n="micro"),e.usbc&&(n="c"),e.pinrow!==void 0&&(e.numPins=Number(e.pinrow));const o={left:e.pinrowleftpins,right:e.pinrowrightpins,top:e.pinrowtoppins,bottom:e.pinrowbottompins},s=Object.values(o).some(f=>f!==void 0&&f>0),r=(o.left??0)>0&&(o.right??0)>0,a=(o.top??0)>0&&(o.bottom??0)>0;s&&((o.left??0)>0?t="left":(o.right??0)>0?t="right":(o.top??0)>0?t="top":(o.bottom??0)>0&&(t="bottom"),e.numPins=(o.left??0)+(o.right??0)+(o.top??0)+(o.bottom??0));const g=Math.ceil(e.numPins/e.rows),c=Math.max(o.left??0,o.right??0),I=Math.max(o.top??0,o.bottom??0);let l,B;if(s){const f=r?e.p:0,m=a?e.p:0;l=(I>0?(I-1)*e.p:0)+2*e.pinRowHoleEdgeToEdgeDist+f,B=(c>0?(c-1)*e.p:0)+2*e.pinRowHoleEdgeToEdgeDist+m}else t==="left"||t==="right"?(l=(e.rows-1)*e.p+2*e.pinRowHoleEdgeToEdgeDist,B=(g-1)*e.p+2*e.pinRowHoleEdgeToEdgeDist):(B=(e.rows-1)*e.p+2*e.pinRowHoleEdgeToEdgeDist,l=(g-1)*e.p+2*e.pinRowHoleEdgeToEdgeDist);e.numPins===0&&(l=10,B=10);const C=e.width??l,Q=e.height??B,h=e.screenwidth??C*.95,E=e.screenheight??Q*.95,u=e.screencenteroffsetx??0,d=e.screencenteroffsety??0;return{...e,pinlabelAnchorSide:A,pinRowSide:t,usbposition:i,usbtype:n,male:e.male??!e.female,female:e.female??!1,width:C,height:Q,screenwidth:h,screenheight:E,screencenteroffsetx:u,screencenteroffsety:d,pinrowleftpins:o.left,pinrowrightpins:o.right,pinrowtoppins:o.top,pinrowbottompins:o.bottom}}).superRefine((e,A)=>{e.male&&e.female&&A.addIssue({code:Xe.custom,message:"'male' and 'female' cannot both be true; it should be male or female.",path:["male","female"]})}),oke=e=>{const A=nke.parse(e),{p:t,id:i,od:n,rows:o,numPins:s,pinlabelAnchorSide:r,pinlabelverticallyinverted:a,pinlabelorthogonal:g,pinlabeltextalignleft:c,pinlabeltextalignright:I,nopinlabels:l,doublesidedpinlabel:B,bottomsidepinlabel:C,pinRowSide:Q,width:h,height:E,pinRowHoleEdgeToEdgeDist:u,holes:d,holeXDist:f,holeYDist:m,holeInset:w,pinrowleftpins:D,pinrowrightpins:x,pinrowtoppins:_,pinrowbottompins:b,usbposition:R,usbtype:F,screen:H,screenwidth:Y,screenheight:J,screencenteroffsetx:O,screencenteroffsety:W}=A;let z="center";c?z="left":I&&(z="right");const tA=[],aA={left:D,right:x,top:_,bottom:b},eA=Object.values(aA).some(lA=>lA!==void 0&&lA>0),oA=(lA,pA,kA,MA)=>{if(A.smd?tA.push(li(lA,pA,kA,A.od,A.od)):lA===1?tA.push(lm({pn:lA,x:pA,y:kA,holeDiameter:i,rectPadWidth:n,rectPadHeight:n})):tA.push(Fo(lA,pA,kA,i,n)),!l){const JA=pA+(MA==="left"?-n:MA==="right"?n:0),EA=kA+(MA==="top"?n:MA==="bottom"?-n:0);C||tA.push(V4({fs:n/5,pn:lA,anchor_x:JA,anchor_y:EA,textalign:z,orthogonal:g,verticallyinverted:a,layer:"top"})),(B||C)&&tA.push(V4({fs:n/5,pn:lA,anchor_x:JA,anchor_y:EA,textalign:z,orthogonal:g,verticallyinverted:a,layer:"bottom"}))}};if(eA){const lA=t;let pA=1;const kA=aA.left??0,MA=aA.right??0,JA=aA.top??0,EA=aA.bottom??0,bA=(dA,WA)=>{if(!(WA<=0))if(dA==="left"||dA==="right"){const jA=dA==="left"?-h/2+u:h/2-u,It=(WA-1)/2*lA;for(let mA=0;mA<WA;mA++)oA(pA,jA,It-mA*lA,dA),pA++}else{const jA=dA==="top"?E/2-u:-E/2+u,It=-((WA-1)/2)*lA;for(let mA=0;mA<WA;mA++)oA(pA,It+mA*lA,jA,dA),pA++}};bA("left",kA),bA("right",MA),bA("top",JA),bA("bottom",EA)}else{const lA=t;let pA=0,kA=0,MA=0,JA=0,EA=0,bA=0;const dA=Math.ceil(s/o);Q==="left"||Q==="right"?(pA=Q==="left"?-h/2+u:h/2-u,kA=(dA-1)/2*lA,MA=0,JA=-lA,EA=Q==="left"?lA:-lA,bA=0):(pA=-(dA-1)/2*lA,kA=Q==="top"?E/2-u:-E/2+u,MA=lA,JA=0,EA=0,bA=Q==="top"?-lA:lA);let WA=1;for(let jA=0;jA<o&&WA<=s;jA++)for(let It=0;It<dA&&WA<=s;It++){const mA=pA+It*MA+jA*EA,gt=kA+It*JA+jA*bA;if(A.smd?tA.push(li(WA,mA,gt,A.od,A.od)):WA===1?tA.push(lm({pn:WA,x:mA,y:gt,holeDiameter:i,rectPadWidth:n,rectPadHeight:n})):tA.push(Fo(WA,mA,gt,i,n)),!l){const VA=mA+(Q==="left"?-n:Q==="right"?n:0),TA=gt+(Q==="top"?n:Q==="bottom"?-n:0);C||tA.push(V4({fs:n/5,pn:WA,anchor_x:VA,anchor_y:TA,textalign:z,orthogonal:g,verticallyinverted:a,layer:"top"})),(B||C)&&tA.push(V4({fs:n/5,pn:WA,anchor_x:VA,anchor_y:TA,textalign:z,orthogonal:g,verticallyinverted:a,layer:"bottom"}))}WA++}}if(d)for(const lA of d){let pA=0,kA=0;lA==="topleft"?(pA=-h/2+w,kA=E/2-w):lA==="topright"?(pA=h/2-w,kA=E/2-w):lA==="bottomleft"?(pA=-h/2+w,kA=-E/2+w):lA==="bottomright"?(pA=h/2-w,kA=-E/2+w):lA==="center"&&(pA=0,kA=0),f!==void 0&&(pA+=f),m!==void 0&&(kA+=m),tA.push(Fo(s+d.indexOf(lA)+1,pA,kA,i,n))}if(!A.nosilkscreen){const lA=[{x:-h/2,y:-E/2},{x:h/2,y:-E/2},{x:h/2,y:E/2},{x:-h/2,y:E/2},{x:-h/2,y:-E/2}];tA.push(j4(lA,{stroke_width:.1,layer:"top"}))}const rA=Ui(0,E/2+1,.5);if(tA.push(rA),R&&F){let lA,pA;if(F==="c")lA=8,pA=3;else if(F==="micro")lA=6,pA=2;else return{circuitJson:tA,parameters:A};let kA;if(R==="left")kA=[{x:-h/2,y:-lA/2},{x:-h/2+pA,y:-lA/2},{x:-h/2+pA,y:lA/2},{x:-h/2,y:lA/2},{x:-h/2,y:-lA/2}];else if(R==="right")kA=[{x:h/2-pA,y:-lA/2},{x:h/2,y:-lA/2},{x:h/2,y:lA/2},{x:h/2-pA,y:lA/2},{x:h/2-pA,y:-lA/2}];else if(R==="top")kA=[{x:-lA/2,y:E/2-pA},{x:lA/2,y:E/2-pA},{x:lA/2,y:E/2},{x:-lA/2,y:E/2},{x:-lA/2,y:E/2-pA}];else if(R==="bottom")kA=[{x:-lA/2,y:-E/2},{x:lA/2,y:-E/2},{x:lA/2,y:-E/2+pA},{x:-lA/2,y:-E/2+pA},{x:-lA/2,y:-E/2}];else return{circuitJson:tA,parameters:A};tA.push(j4(kA,{stroke_width:.1,layer:"top"}))}if(H){const lA=Y/2,pA=J/2,kA=O,MA=W,JA=[{x:-lA+kA,y:-pA+MA},{x:lA+kA,y:-pA+MA},{x:lA+kA,y:pA+MA},{x:-lA+kA,y:pA+MA},{x:-lA+kA,y:-pA+MA}];tA.push(j4(JA,{stroke_width:.05,layer:"top"}))}return{circuitJson:tA,parameters:A}},ske=Gi.extend({fn:L(),num_pins:qA().default(3),inline:HA().default(!1),p:L().default("1.27mm"),id:L().default("0.75mm"),od:L().default("1.3mm"),w:L().default("4.8mm"),h:L().default("4.0mm")}),rke=e=>{const A=ske.parse(e),t=Number.parseFloat(A.p),i=Number.parseFloat(A.w),n=Number.parseFloat(A.h),o=A.inline?1.05:Number.parseFloat(A.od),s=A.inline?1.5:o,r=[lm({pn:1,x:0,y:0,holeDiameter:A.id,rectPadWidth:o,rectPadHeight:s}),A.inline?z4(2,t,0,Number.parseFloat(A.id),o,s):Fo(2,t,t,A.id,o),A.inline?z4(3,t*2,0,Number.parseFloat(A.id),o,s):Fo(3,t*2,0,A.id,o)],a=i/2,g=A.inline?t-.09:t,c=.2,I=c+a-n,l=Array.from({length:32},(Q,h)=>{const E=Math.PI*h/31;return{x:g+a*Math.cos(E),y:c+a*Math.sin(E)}}),B={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"",stroke_width:.12,route:[...l,{x:g-a,y:I},{x:g+a,y:I},l[0]]},C=Ui(g,c+a+1,.5);return{circuitJson:[...r,B,C],parameters:A}},ake=(e,A)=>{const t=e.filter(i=>i.type==="pcb_silkscreen_text");if(t.length===0)return e;for(const i of t)A.norefdes&&(i.text="");return e},gke=(e,A)=>A.nosilkscreen?e.filter(t=>t.type!=="pcb_silkscreen_path"&&t.type!=="pcb_silkscreen_text"):e,cke=(e,A)=>{if(!A)return e;const t=e.filter(c=>c.type==="pcb_smtpad"||c.type==="pcb_plated_hole"||c.type==="pcb_thtpad");if(t.length===0)return e;let i=Number.POSITIVE_INFINITY,n=Number.NEGATIVE_INFINITY,o=Number.POSITIVE_INFINITY,s=Number.NEGATIVE_INFINITY;const r=(c,I,l=0,B=0)=>{const C=c-l/2,Q=c+l/2,h=I-B/2,E=I+B/2;i=Math.min(i,C),n=Math.max(n,Q),o=Math.min(o,h),s=Math.max(s,E)};for(const c of t)if(c.type==="pcb_smtpad"){const I=c.shape==="circle"?c.radius*2:c.width,l=c.shape==="circle"?c.radius*2:c.height;r(c.x,c.y,I,l)}else if(c.type==="pcb_plated_hole"){const I=c.outer_diameter??c.hole_diameter;r(c.x,c.y,I,I)}else if(c.type==="pcb_thtpad"){const I=c.diameter;r(c.x,c.y,I,I)}let a=0,g=0;switch(A){case"center":a=(i+n)/2,g=(o+s)/2;break;case"bottomleft":a=i,g=o;break;case"bottomcenter":case"centerbottom":a=(i+n)/2,g=o;break;case"topcenter":case"centertop":a=(i+n)/2,g=s;break;case"leftcenter":case"centerleft":a=i,g=(o+s)/2;break;case"rightcenter":case"centerright":a=n,g=(o+s)/2;break;case"pin1":{const c=t.find(I=>I.port_hints?.[0]==="1")||t[0];a=c.x,g=c.y;break}}if(a===0&&g===0)return e;for(const c of e){if(typeof c.x=="number"&&(c.x-=a),typeof c.y=="number"&&(c.y-=g),c.center&&typeof c.center.x=="number"&&(c.center.x-=a,c.center.y-=g),c.type==="pcb_silkscreen_path")for(const I of c.route)I.x-=a,I.y-=g;c.type==="pcb_silkscreen_text"&&c.anchor_position&&(c.anchor_position.x-=a,c.anchor_position.y-=g)}return e};function Ike(e){return e!=null}var lke=e=>e.trim().replace(/^sot-223-(\d+)(?=_|$)/i,"sot223_$1").replace(/^to-220f-(\d+)(?=_|$)/i,"to220f_$1"),Bke=e=>{let A=EO();const t=lke(e),n=t.replace(/^((?:\d{4}|\d{5}))(?=$|_|x)/,"res$1").replace(/^zh(\d+)(?:$|_)/,"jst$1_zh").split(/_(?!metric)/).map(o=>{const s=o.match(/([a-zA-Z]+)([\(\d\.\+\?].*)?/);if(!s)return null;const[,r,a]=s;if(!r)return null;const g=r.toLowerCase();return a?.includes("?")?null:{fn:g,v:a}}).filter(Ike);for(const{fn:o,v:s}of n)A=A[o](s);return A.setString(t),A},Cke=()=>Object.keys(R2),EO=()=>{const e=new Proxy({},{get:(A,t)=>{if(t==="soup"||t==="circuitJson"){if("fn"in A&&R2[A.fn])return()=>{const{circuitJson:i}=R2[A.fn](A),n=gke(i,A),o=ake(n,A);return cke(o,A.origin)};if(!R2[A.fn])throw new Error(`Invalid footprint function, got "${A.fn}"${A.string?`, from string "${A.string}"`:""}`);return()=>{throw new Error(`No function found for footprinter, make sure to specify .dip, .lr, .p, etc. Got "${t}"`)}}if(t==="json"){if(!R2[A.fn])throw new Error(`Invalid footprint function, got "${A.fn}"${A.string?`, from string "${A.string}"`:""}`);return()=>R2[A.fn](A).parameters}return t==="getFootprintNames"?()=>Object.keys(R2):t==="params"?()=>A:t==="setString"?i=>(A.string=i,e):i=>(Object.keys(A).length===0?`${t}${i}`in R2?(A[`${t}${i}`]=!0,A.fn=`${t}${i}`):(A[t]=!0,A.fn=t,t==="res"||t==="cap"?i&&(typeof i=="string"&&i.includes("_metric")?A.metric=i.split("_metric")[0]:A.imperial=i):A.num_pins=Number.isNaN(Number.parseFloat(i))?void 0:Number.parseFloat(i)):!i&&["w","h","p"].includes(t)||(A[t]=i??!0),e)}});return e};EO.string=Bke,EO.getFootprintNames=Cke;var Qke=EO,_et=Symbol("Fragment");function suA(e,A,...t){const i=t.length?t:A?.children!==void 0?[A.children]:[],n=[],o=(Array.isArray(i)?i:[i]).flat(1/0);for(const s of o)s==null||s===!1||(Array.isArray(s)?n.push(...s):n.push(s));return{type:e,props:(A&&A.children!==void 0?{...A,children:void 0}:A)||{},children:n}}var Qe=Symbol("Cuboid"),ket=Symbol("Cube"),ql=Symbol("Cylinder"),uO=Symbol("Sphere"),O8=Symbol("RoundedCuboid"),Zi=Symbol("Translate"),rC=Symbol("Rotate"),zQ=Symbol("Union"),Bm=Symbol("Subtract"),Sc=Symbol("Hull"),wo=Symbol("Colorize"),W8=Symbol("Polygon"),Z8=Symbol("ExtrudeLinear"),kp=Symbol("RoundedCylinder"),Jn=_et,zA=(e,A,t)=>suA(e,A),qe=(e,A,t)=>suA(e,A),pB=({center:e,width:A,length:t,height:i,heightAboveSurface:n=.15,color:o="#555",taperRatio:s=.12,faceRatio:r=.75,straightHeightRatio:a=.5,includeNotch:g=!0,notchRadius:c,notchPosition:I,notchRotation:l=[0,0,0],notchLength:B=.5,notchWidth:C=.25,chamferSize:Q=0})=>{const h=i*a,E=i-h,u=Math.min(A,t)*s,d=Math.max(A-u,A*r),f=Math.max(t-u,t*r),m=Math.min(A,t)*.12,w=c??m,D={x:0,y:t/2-w*.25,z:i},x=I??D,_=qe(zQ,{children:[qe(Sc,{children:[zA(Zi,{z:.005,children:zA(Qe,{size:[d,f,.01]})}),zA(Zi,{z:h,children:zA(Qe,{size:[A,t,.01]})})]}),qe(Sc,{children:[zA(Zi,{z:h,children:zA(Qe,{size:[A,t,.01]})}),zA(Zi,{z:h+E,children:zA(Qe,{size:[d,f,.01]})})]})]}),b=(F,H)=>zA(Zi,{offset:{x:F,y:H,z:0},children:zA(rC,{rotation:[0,0,Math.PI/4],children:zA(Qe,{size:[Q*Math.SQRT2,Q*Math.SQRT2,i*3]})})});let R=_;if(Q>0){const F=A/2,H=t/2;R=qe(Bm,{children:[_,b(F,H),b(-F,H),b(F,-H),b(-F,-H)]})}return zA(wo,{color:o,children:zA(Zi,{offset:e,children:zA(Zi,{offset:{x:0,y:0,z:n},children:g?qe(Bm,{children:[R,zA(Zi,{offset:x,children:zA(rC,{rotation:l,children:zA(ql,{radius:w,height:C})})})]}):R})})})},hke=e=>Array.from({length:e},(A,t)=>t);function ruA(e,A){if(e.length<2)throw new Error("Stroke must have at least two points");const t=Array.isArray(e[0])?e.map(([c,I])=>({x:c,y:I})):e,i=A/2,n=[],o=[];function s(c,I){const l=I.x-c.x,B=I.y-c.y,C=Math.sqrt(l*l+B*B);return{x:-B/C,y:l/C}}function r(c,I,l){const B={x:c.x+I.x*i*l,y:c.y+I.y*i*l};l>0?n.push(B):o.unshift(B)}const a=s(t[0],t[1]);r(t[0],a,1),r(t[0],a,-1);for(let c=1;c<t.length-1;c++){const I=t[c-1],l=t[c],B=t[c+1],C=s(I,l),Q=s(l,B),h=C.x+Q.x,E=C.y+Q.y,u=Math.sqrt(h*h+E*E);if(u/2>2*i)r(l,C,1),r(l,Q,1),r(l,C,-1),r(l,Q,-1);else{const f=1/u;r(l,{x:h*f,y:E*f},1),r(l,{x:h*f,y:E*f},-1)}}const g=s(t[t.length-2],t[t.length-1]);return r(t[t.length-1],g,1),r(t[t.length-1],g,-1),[...n,...o]}var Eke=e=>{const A=Math.min(...e.map(r=>r.x)),t=Math.max(...e.map(r=>r.x)),i=Math.min(...e.map(r=>r.y)),s=5.47/(Math.max(...e.map(r=>r.y))-i);return e.map(r=>({x:(r.x-A-(t-A)/2)*s,y:(r.y-i)*s}))},uke=Eke([{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}]),vet=5.47,dO=.5,dke=({x:e,y:A,z:t})=>{const i=e>0;return qe(Jn,{children:[zA(Zi,{offset:{x:e+.25/2,y:A,z:t},children:zA(rC,{rotation:["-90deg",0,"90deg"],children:zA(Z8,{height:.25,children:zA(W8,{points:uke.slice().reverse().map(n=>[n.x,n.y])})})})}),zA(Zi,{offset:{x:e,y:A+(i?1:-1),z:t},children:zA(rC,{rotation:["-90deg","90deg",i?"180deg":"0deg"],children:zA(Z8,{height:2,children:zA(W8,{points:ruA([[0,0],[-1,0],[-1,-1]],.25).map(n=>[n.x,n.y])})})})})]})},pke=({numPins:e=8,pitch:A=2.54,bodyWidth:t=6.4,rowSpacing:i})=>{const n=Math.floor(e/2),o=i??(t>=7?t:t+1.22),s=t>=7?o-1.22:t;return qe(Jn,{children:[hke(e).map(r=>{const a=r%n,g=(Math.floor(r/n)-.5)*2;return zA(dke,{x:g*o/2,y:a*A-(n-1)/2*A,z:vet/2+dO})}),zA(pB,{width:s,length:n*A+.5,height:vet-dO,heightAboveSurface:dO,center:{x:0,y:0,z:dO}})]})};function fke(e,{height:A,padContactLength:t,curveLength:i,bodyDistance:n,steepness:o=10}){i||(i=n*.3);let s=n-t-i;s<0&&(i+=s,s=0);const r=t*.75,a=t+i+(n-t-i)*.25;if(e<=r)return 0;if(e>=a)return A;const g=(e-r)/(a-r);return A/(1+Math.exp(-o*(g-.5)))}var no=e=>{const{thickness:A,width:t,padContactLength:i,bodyDistance:n,height:o,rotation:s}=e,r=15,a=Array.from({length:r}).map((c,I)=>I/(r-1)*n).map(c=>[c,fke(c,e)]),g=ruA(a,A);return zA(wo,{color:"#fff",children:zA(Zi,{offset:{z:0,y:0,x:0,...e.position},children:zA(rC,{rotation:["90deg",0,s??0],children:zA(Zi,{offset:{x:0,y:0,z:-t/2},children:zA(Z8,{height:t,children:zA(W8,{points:g.map(c=>[c.x,c.y])})})})})})})},yke=({pinCount:e,leadLength:A,leadWidth:t,pitch:i,bodyWidth:n})=>{const o=Math.ceil(e/2),s=i*e/2+t/2,r=(o-1)*i/2,a=.25;return qe(Jn,{children:[Array.from({length:o}).map((g,c)=>zA(no,{position:{x:-n/2-A,y:c*i-r,z:a/2},width:t,thickness:a,padContactLength:A,bodyDistance:A+1,height:.8})),Array.from({length:o}).map((g,c)=>zA(no,{rotation:Math.PI,position:{x:n/2+A,y:c*i-r,z:a/2},width:t,thickness:a,padContactLength:A,bodyDistance:A+1,height:.8})),zA(pB,{center:{x:0,y:0,z:a/2},width:n-t-1,length:s,height:1.5})]})},mke=({pinCount:e,padContactLength:A=.4,leadWidth:t=.2,pitch:i=.65,bodyWidth:n=3})=>{const o=Math.ceil(e/2),s=(o-1)*i/2,r=.2;return qe(Jn,{children:[Array.from({length:o}).map((a,g)=>zA(no,{position:{x:-n/2-A-.3,y:g*i-s,z:r/2},width:t,thickness:r,padContactLength:A,bodyDistance:A+.4,height:.6})),Array.from({length:o}).map((a,g)=>zA(no,{rotation:Math.PI,position:{x:n/2+A+.3,y:g*i-s,z:r/2},width:t,thickness:r,padContactLength:A,bodyDistance:A+.4,height:.6})),zA(pB,{center:{x:0,y:0,z:r/2},width:n,length:n,height:1.1,notchRadius:.35,heightAboveSurface:.1,taperRatio:.09})]})},auA=1,guA=.5,hF=.5,V8=.2,wke=auA-V8*2,Fet=({color:e="#333"})=>qe(Jn,{children:[zA(Qe,{size:[wke,guA,hF],offset:[0,0,hF/2],color:e}),zA(Qe,{size:[V8,hF,guA],offset:[auA/2-V8/2,0,hF/2],color:"#ccc"}),zA(Qe,{size:[V8,hF,guA],offset:[-auA/2+V8/2,0,hF/2],color:"#ccc"})]}),cuA=1.6,Dke=cuA-.3*2,pO=.3,IuA=.85,EF=.6,Met=({color:e="#333"})=>qe(Jn,{children:[zA(Qe,{size:[Dke,IuA,EF],offset:[0,0,EF/2],color:e}),zA(Qe,{size:[pO,IuA,EF],offset:[cuA/2-pO/2,0,EF/2],color:"#ccc"}),zA(Qe,{size:[pO,IuA,EF],offset:[-cuA/2+pO/2,0,EF/2],color:"#ccc"})]}),luA=2,BuA=1.25,uF=.55,j8=.5,xke=luA-j8*2,Get=({color:e="#333"})=>qe(Jn,{children:[zA(Qe,{size:[xke,BuA,uF],offset:[0,0,uF/2],color:e}),zA(Qe,{size:[j8,BuA,uF],offset:[luA/2-j8/2,0,uF/2],color:"#ccc"}),zA(Qe,{size:[j8,BuA,uF],offset:[-luA/2+j8/2,0,uF/2],color:"#ccc"})]}),Ske=({pinCount:e,pitch:A,leadWidth:t,padContactLength:i,bodyWidth:n})=>{const o=e/4;A||(A=bke(e,n)),i||(i=_ke(e)),t||(t=kke(e,n)),n||(n=A*(o+4));const s=n,r=(o-1)*A/2,a=s+2*i,g=a,c=.8,I=.15,l=(g-n)/2+.5;return qe(Jn,{children:[Array.from({length:o}).map((B,C)=>zA(no,{position:{x:-g/2-.4,y:C*A-r,z:I/2},width:t,thickness:I,padContactLength:i,bodyDistance:l,height:c})),Array.from({length:o}).map((B,C)=>zA(no,{rotation:Math.PI,position:{x:g/2+.4,y:C*A-r,z:I/2},width:t,thickness:I,padContactLength:i,bodyDistance:l,height:c})),Array.from({length:o}).map((B,C)=>zA(no,{rotation:Math.PI/2,position:{x:C*A-r,y:-a/2-.4,z:I/2},width:t,thickness:I,padContactLength:i,bodyDistance:l,height:c})),Array.from({length:o}).map((B,C)=>zA(no,{rotation:-Math.PI/2,position:{x:C*A-r,y:a/2+.4,z:I/2},width:t,thickness:I,padContactLength:i,bodyDistance:l,height:c})),zA(pB,{center:{x:0,y:0,z:0},width:n,length:s,height:1.5,taperRatio:.03,chamferSize:.7,notchPosition:{x:-(s/2-1.5),y:n/2-1.5,z:1.5},notchRadius:1.5/2})]})},bke=(e,A)=>{switch(e){case 44:case 64:return .8;case 52:return A===14?1:.65;case 208:return .5;default:return .5}},_ke=e=>{switch(e){case 32:return .6;case 40:return .6;case 52:case 64:return .65;case 208:return 1.65;default:return .6}},kke=(e,A)=>{switch(e){case 44:case 64:return .5;case 52:return A===14?.45:.55;case 208:return .3;default:return .25}},Ret=({x:e,y:A,pinThickness:t,shortSidePinLength:i,longSidePinLength:n,bodyHeight:o,bodyLength:s=2.54,bodyWidth:r=2.54,flipZ:a,faceup:g,smd:c,rightangle:I})=>qe(Jn,{children:[zA(Zi,{y:I?-3:0,children:zA(Qe,{color:"#222",size:[s,r,o],center:[e,A,a(o/2)]})}),!g&&zA(wo,{color:"gold",children:c?zA(no,{rotation:-Math.PI/2,position:{x:e,y:A+1,z:t/2},thickness:t,width:t,height:t,padContactLength:2,bodyDistance:3}):qe(Sc,{children:[zA(Qe,{color:"gold",size:[t,t,i*.9],center:[e,A,a(o*.9+o/2)]}),zA(Qe,{color:"gold",size:[t/1.8,t/1.8,i],center:[e,A,a(o+o/2)]})]})}),zA(wo,{color:"gold",children:zA(Zi,{y:I?-3.9:0,z:I?1:0,children:zA(rC,{rotation:I?[-Math.PI/2,0,0]:[0,0,0],children:qe(Sc,{children:[zA(Qe,{color:"gold",size:[t,t,n*.9],center:[e,A,a(-n/2*.9)]}),zA(Qe,{color:"gold",size:[t/1.8,t/1.8,n],center:[e,A,a(-n/2)]})]})})})})]}),vke=({numberOfPins:e,pitch:A=2.54,longSidePinLength:t=6,invert:i,faceup:n,rows:o=1,smd:s,rightangle:r})=>{const c=Math.ceil(e/o),I=2.54,l=3,B=-((c-1)/2)*A,C=!s&&!r?-2-1.6:0,Q=h=>(i||n?-h+2:h)+C;return zA(Jn,{children:Array.from({length:e},(h,E)=>{const u=Math.floor(E/c),d=E%c,f=B+d*A,m=-u*I;return zA(Ret,{x:f,y:m,pinThickness:.63,shortSidePinLength:l,longSidePinLength:t,bodyHeight:2,flipZ:Q,faceup:n,smd:s,rightangle:r},E)})})},Fke=e=>{const A=["left","bottom","right","top"],{pin_count:t,pn:i,w:n,h:o,p:s,pl:r}=e,a=t/4,g=A[Math.floor((i-1)/a)],c=(i-1)%a,I=s*(a-1),l=s*(a-1),B=-r/2;switch(g){case"left":return{x:-n/2-B,y:l/2-c*s,o:"vert"};case"bottom":return{x:-I/2+c*s,y:-o/2-B,o:"horz"};case"right":return{x:n/2+B,y:-l/2+c*s,o:"vert"};case"top":return{x:I/2-c*s,y:o/2+B,o:"horz"};default:throw new Error("Invalid pin number")}},Mke=({num_pins:e,cw:A,ccw:t,startingpin:i})=>{const n=[],o=e/4;let s=1;const r={};for(const a of i??[])r[a]=!0;!r.leftside&&!r.topside&&!r.rightside&&!r.bottomside&&(r.leftside=!0),!r.bottompin&&!r.leftpin&&!r.rightpin&&!r.toppin&&(r.leftside?r.toppin=!0:r.topside?r.rightpin=!0:r.rightside?r.bottompin=!0:r.bottomside&&(r.leftpin=!0)),r.leftside&&r.toppin?s=1:r.leftside&&r.bottompin?s=o:r.bottomside&&r.leftpin?s=o+1:r.bottomside&&r.rightpin?s=o*2:r.rightside&&r.bottompin?s=o*2+1:r.rightside&&r.toppin?s=o*3:r.topside&&r.rightpin?s=o*3+1:r.topside&&r.leftpin&&(s=o*4),n.push(-1);for(let a=0;a<e;a++)n[s]=a+1,s++,s>e&&(s=1);return n},Gke=({num_pins:e=16,bodyWidth:A=9,bodyLength:t=9,bodyThickness:i=.8,thermalPadSize:n,padWidth:o=.25,padLength:s=.25,pitch:r=.5,thermalPadThickness:a=.05})=>{const g=Mke({num_pins:e,cw:!0,ccw:!0}),c=[];for(let I=0;I<e;I++){const{x:l,y:B,o:C}=Fke({pin_count:e,pn:I+1,w:A,h:t,p:r,pl:s});let Q=o,h=s;C==="vert"&&([Q,h]=[h,Q]);const E=g[I+1];c.push({pn:E,x:l,y:B,pw:Q,pl:h})}return qe(Jn,{children:[zA(wo,{color:"grey",children:zA(Qe,{center:{x:0,y:0,z:i/2},size:[A,t,i]})}),c.map((I,l)=>zA(Qe,{center:{x:I.x,y:I.y,z:a/2},size:[I.pw,I.pl,a]})),n?.length!==void 0&&n?.width!==void 0&&zA(Qe,{center:{x:0,y:0,z:a/2},size:[n.width,n.length,a]})]})},Rke=Gke,Nke=()=>{const a=1.1999999999999997;return qe(Jn,{children:[zA(no,{rotation:Math.PI,position:{x:2.8/2+a/4,y:-1,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:a,height:.95}),zA(no,{rotation:Math.PI,position:{x:2.8/2+a/4,y:1,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:a,height:.95}),zA(no,{position:{x:-2.8/2-a/4,y:0,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:a,height:.95}),zA(no,{position:{x:-2.8/2-a/4,y:-1,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:a,height:.95}),zA(no,{position:{x:-2.8/2-a/4,y:1,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:a,height:.95}),zA(pB,{center:{x:0,y:0,z:0},width:1.6,length:2.9,height:1.2})]})},Lke=Nke,Uke=({fullWidth:e=2.9,fullLength:A=2.8})=>{const c=(e-1.92)/2+.3;return qe(Jn,{children:[zA(no,{rotation:Math.PI,position:{x:e/2,y:0,z:.075},width:.4,thickness:.15,padContactLength:.25,bodyDistance:c,height:.45}),zA(no,{position:{x:-e/2,y:-.95,z:.075},width:.4,thickness:.15,padContactLength:.25,bodyDistance:c,height:.45}),zA(no,{position:{x:-e/2,y:.95,z:.075},width:.4,thickness:.15,padContactLength:.25,bodyDistance:c,height:.45}),zA(pB,{center:{x:0,y:0,z:0},width:1.92,length:2.9,height:1.1,straightHeightRatio:.45,heightAboveSurface:.05})]})},CuA=.6,QuA=.3,dF=.33,z8=.1,Hke=CuA-z8*2,Net=({color:e="#333"})=>qe(Jn,{children:[zA(Qe,{size:[Hke,QuA,dF],offset:[0,0,dF/2],color:e}),zA(Qe,{size:[z8,QuA,dF],offset:[CuA/2-z8/2,0,dF/2],color:"#ccc"}),zA(Qe,{size:[z8,QuA,dF],offset:[-CuA/2+z8/2,0,dF/2],color:"#ccc"})]}),huA=.4,EuA=.2,pF=.13,X8=.07,Yke=huA-X8*2,Let=({color:e="#333"})=>qe(Jn,{children:[zA(Qe,{size:[Yke,EuA,pF],offset:[0,0,pF/2],color:e}),zA(Qe,{size:[X8,EuA,pF],offset:[huA/2-X8/2,0,pF/2],color:"#ccc"}),zA(Qe,{size:[X8,EuA,pF],offset:[-huA/2+X8/2,0,pF/2],color:"#ccc"})]}),uuA=3.2,duA=1.6,fF=.9,$8=.5,Jke=uuA-$8*2,Uet=({color:e="#333"})=>qe(Jn,{children:[zA(Qe,{size:[Jke,duA,fF],offset:[0,0,fF/2],color:e}),zA(Qe,{size:[$8,duA,fF],offset:[uuA/2-$8/2,0,fF/2],color:"#ccc"}),zA(Qe,{size:[$8,duA,fF],offset:[-uuA/2+$8/2,0,fF/2],color:"#ccc"})]}),puA=3.2,fuA=2.5,yF=1,A9=.6,Tke=puA-A9*2,Het=({color:e="#333"})=>qe(Jn,{children:[zA(Qe,{size:[Tke,fuA,yF],offset:[0,0,yF/2],color:e}),zA(Qe,{size:[A9,fuA,yF],offset:[puA/2-A9/2,0,yF/2],color:"#ccc"}),zA(Qe,{size:[A9,fuA,yF],offset:[-puA/2+A9/2,0,yF/2],color:"#ccc"})]}),yuA=5,muA=2.5,mF=1.4,t9=.6,Pke=yuA-t9*2,Yet=({color:e="#333"})=>qe(Jn,{children:[zA(Qe,{size:[Pke,muA,mF],offset:[0,0,mF/2],color:e}),zA(Qe,{size:[t9,muA,mF],offset:[yuA/2-t9/2,0,mF/2],color:"#ccc"}),zA(Qe,{size:[t9,muA,mF],offset:[-yuA/2+t9/2,0,mF/2],color:"#ccc"})]}),wuA=6.3,DuA=3.2,wF=1.8,e9=.8,Kke=wuA-e9*2,Jet=({color:e="#333"})=>qe(Jn,{children:[zA(Qe,{size:[Kke,DuA,wF],offset:[0,0,wF/2],color:e}),zA(Qe,{size:[e9,DuA,wF],offset:[wuA/2-e9/2,0,wF/2],color:"#ccc"}),zA(Qe,{size:[e9,DuA,wF],offset:[-wuA/2+e9/2,0,wF/2],color:"#ccc"})]}),Tet=({x:e,y:A,z:t=0,pitch:i=2.54,legsLength:n=3,innerDiameter:o=.945,bodyHeight:s=5,bodyLength:r=i,bodyWidth:a=i,flipZ:g})=>{const c=o/1.5,I=c*1.6;return qe(Jn,{children:[zA(wo,{color:"#1a1a1a",children:qe(Bm,{children:[zA(Qe,{color:"#000",size:[r,a,s],center:[e,A,g(t+s/2)]}),o?zA(ql,{height:s+.1,radius:o/2,center:[e,A,g(t+s/2)],color:"#222"}):zA(Qe,{size:[I,I,s],center:[e,A,g(t+s/2)]})]})}),qe(wo,{color:"silver",children:[qe(Sc,{children:[zA(Qe,{color:"silver",size:[c,c,n*.9],center:[e,A,g(t+-n/2*.9)]}),zA(Qe,{color:"silver",size:[c/1.8,c/1.8,n],center:[e,A,g(t+-n/2)]})]}),zA(Qe,{color:"silver",size:[I,I,I*.5],center:[e,A,g(t+I/2*.5)]})]})]})},qke=({numberOfPins:e,pitch:A=2.54,legsLength:t=3,innerDiameter:i=.945,rows:n=1,invert:o})=>{const r=Math.ceil(e/n),a=2.54,g=-((r-1)/2)*A,c=I=>o?-I+5:I;return zA(Jn,{children:Array.from({length:e},(I,l)=>{const B=Math.floor(l/r),C=l%r,Q=g+C*A,h=-B*a;return zA(Tet,{x:Q,y:h,pitch:A,legsLength:t,innerDiameter:i,flipZ:c},l)})})},Oke=({width:e,length:A,innerDiameter:t=1})=>{const i=e,n=A,o=e*.7,s=t/2.5;return qe(Jn,{children:[zA(O8,{color:"#1a1a1f",center:[0,0,o/2],size:[n,n,o],roundRadius:.3}),zA(O8,{color:"#f2f2f2",center:[0,0,o+o*.1/2.5],size:[n,n,o*.1],roundRadius:.14}),zA(ql,{color:"#1a1a1f",height:o*.8,radius:i/3,center:[0,0,o+o*.8/2]}),zA(ql,{color:"#1a1a1f",height:o*.2,radius:t/2,center:[n/3,n/3,o+o*.1/2]}),zA(ql,{color:"#1a1a1f",height:o*.2,radius:t/2,center:[-n/3,-n/3,o+o*.1/2]}),zA(ql,{color:"#1a1a1f",height:o*.2,radius:t/2,center:[-n/3,n/3,o+o*.1/2]}),zA(ql,{color:"#1a1a1f",height:o*.2,radius:t/2,center:[n/3,-n/3,o+o*.1/2]}),zA(fO,{thickness:t/3,width:s,horizontalLength:n*.8,verticalLength:o/2,position:{x:-i/2,y:-n/2,z:-o*1.2}}),zA(fO,{thickness:t/3,width:s,horizontalLength:n*.8,verticalLength:o/2,position:{x:-i/2,y:n/2,z:-o*1.2},rotation:Math.PI}),zA(fO,{thickness:t/3,width:s,horizontalLength:n*.8,verticalLength:o/2,position:{x:i/2,y:n/2,z:-o*1.2},rotation:Math.PI}),zA(fO,{thickness:t/3,width:s,horizontalLength:n*.8,verticalLength:o/2,position:{x:i/2+t/3.6,y:-n/2,z:-o*1.2}})]})},fO=e=>{const{thickness:A,width:t,horizontalLength:i,verticalLength:n,rotation:o=0,position:s}=e,r=[[0,i],[-n/3,i/3],[-n/5,i/4],[0,0]],a=ruA(r,A);return zA(wo,{color:"#f2f2f2",children:zA(Zi,{offset:{x:s?.x||0,y:s?.y||0,z:s?.z||0},children:zA(rC,{rotation:[0,55,o],children:zA(Z8,{height:t,children:zA(W8,{points:a.map(g=>[g.y,g.x])})})})})})},Wke=({pinCount:e,leadLength:A,leadWidth:t,pitch:i,bodyWidth:n})=>{const o=Math.ceil(e/2),s=(o-1)*i/2,r=.25,a=1,g=.8,c=A*0,I=i*(o-1)+t+.2,l=n*.55;return qe(Jn,{children:[Array.from({length:o}).map((B,C)=>zA(no,{position:{x:-n/2-c,y:C*i-s,z:r/2},width:t,thickness:r,padContactLength:A/2,bodyDistance:A+.3,height:g})),Array.from({length:o}).map((B,C)=>zA(no,{rotation:Math.PI,position:{x:n/2+c,y:C*i-s,z:r/2},width:t,thickness:r,padContactLength:A/2,bodyDistance:A+.3,height:g})),zA(pB,{center:{x:0,y:0,z:r/2},width:l,length:I,height:a})]})},Zke=({pinCount:e,pitch:A,leadWidth:t,leadLength:i,bodyWidth:n,bodyLength:o})=>{const s=e===8?{pitch:.65,leadWidth:.3}:{pitch:.5,leadWidth:.225},r=isNaN(parseFloat(A))?s.pitch:parseFloat(A),a=isNaN(parseFloat(t))?s.leadWidth:parseFloat(t)*.8,g=isNaN(parseFloat(n))?2.6:parseFloat(n)*.8,c=isNaN(parseFloat(o))?2+Number(r)*1.4:parseFloat(o),I=e/2,l=(I-1)*r/2,B=.15,C=.8,Q=4.5,h=(Q-g)/2,E=h*.5;return qe(Jn,{children:[Array.from({length:I}).map((u,d)=>zA(no,{position:{x:-Q/2,y:l-d*r,z:B/2},width:a,thickness:B,padContactLength:E+.05,bodyDistance:h+.1,height:C})),Array.from({length:I}).map((u,d)=>zA(no,{rotation:Math.PI,position:{x:Q/2,y:l-d*r,z:B/2},width:a,thickness:B,padContactLength:E+.05,bodyDistance:h+.1,height:C})),zA(pB,{center:{x:0,y:0,z:B/2},width:g,length:c,height:1})]})},Vke=()=>qe(Jn,{children:[zA(Qe,{color:"#ccc",size:[.5,.6,.12],center:[-.725,0,.12/2]}),zA(Qe,{color:"#ccc",size:[.5,.6,.12],center:[.725,0,.12/2]}),zA(wo,{color:"#222",children:qe(zQ,{children:[zA(Zi,{z:.3/2,children:zA(Qe,{size:[1.65,.8,.3]})}),qe(Sc,{children:[zA(Zi,{z:.3,children:zA(Qe,{size:[1.65,.8,.01]})}),zA(Zi,{z:.6,children:zA(Qe,{size:[1.65-.2,.8-.2,.01]})})]})]})})]}),jke=()=>qe(Jn,{children:[zA(Qe,{color:"#ccc",size:[.26,.51,.12],center:[-.325,0,.12/2]}),zA(Qe,{color:"#ccc",size:[.26,.51,.12],center:[.325,0,.12/2]}),zA(wo,{color:"#222",children:zA(Zi,{z:.47/2+.02,children:zA(Qe,{size:[.98,.58,.47]})})}),zA(Qe,{color:"#ccc",size:[.98+.001,.26/2,.26/4],center:[0,.26/2,.47/4]}),zA(Qe,{color:"#ccc",size:[.98+.001,.26/2,.26/4],center:[0,-.26/2,.47/4]}),zA(Qe,{color:"#ccc",size:[.26/1.5,.58+.001,.26/4],center:[.65/2,0,.47/4]}),zA(Qe,{color:"#ccc",size:[.26/1.5,.58+.001,.26/4],center:[-.65/2,0,.47/4]})]}),zke=()=>{const g=zA(wo,{color:"#1a1a1a",children:qe(zQ,{children:[qe(Sc,{children:[zA(Zi,{z:.13,children:zA(Qe,{size:[4,3,.03]})}),zA(Zi,{z:1.15,children:zA(Qe,{size:[4.4,3.4,.01]})})]}),qe(Sc,{children:[zA(Zi,{z:1.15,children:zA(Qe,{size:[4.4,3.4,.01]})}),zA(Zi,{z:2.3,children:zA(Qe,{size:[4,3,.01]})})]})]})}),c=({xDir:I})=>{const C=I*1.78,Q=I*(3.4/2-.2/2+1),h=I*(3.4/2-.2/2),E=Math.abs(h-Q),u=(Q+h)/2;return zA(wo,{color:"#c0c0c0",children:qe(zQ,{children:[zA(Qe,{size:[2.3*.8,1.45,.2],center:[C,0,.2/2]}),zA(Qe,{size:[.2,1.45,1.14],center:[Q,0,1.14/2+.2]}),zA(Qe,{size:[E,1.45,.2],center:[u,0,.2/2+1.14]})]})})};return qe(Jn,{children:[zA(c,{xDir:1}),zA(c,{xDir:-1}),g]})},Xke=()=>{const g=zA(wo,{color:"#1a1a1a",children:qe(zQ,{children:[qe(Sc,{children:[zA(Zi,{z:.13,children:zA(Qe,{size:[4,3,.03]})}),zA(Zi,{z:1.15,children:zA(Qe,{size:[4.4,3.4,.01]})})]}),qe(Sc,{children:[zA(Zi,{z:1.15,children:zA(Qe,{size:[4.4,3.4,.01]})}),zA(Zi,{z:2.3,children:zA(Qe,{size:[4,3,.01]})})]})]})}),c=({xDir:I})=>{const C=I*1.78,Q=I*(3.4/2-.2/2+1),h=I*(3.4/2-.2/2),E=Math.abs(h-Q),u=(Q+h)/2;return zA(wo,{color:"#c0c0c0",children:qe(zQ,{children:[zA(Qe,{size:[2.3*.8,1.45,.2],center:[C,0,.2/2]}),zA(Qe,{size:[.2,1.45,1.14],center:[Q,0,1.14/2+.2]}),zA(Qe,{size:[E,1.45,.2],center:[u,0,.2/2+1.14]})]})})};return qe(Jn,{children:[zA(c,{xDir:1}),zA(c,{xDir:-1}),g]})},$ke=()=>{const g=zA(wo,{color:"#1a1a1a",children:qe(zQ,{children:[qe(Sc,{children:[zA(Zi,{z:.21000000000000002,children:zA(Qe,{size:[6.3999999999999995,5.6,.03]})}),zA(Zi,{z:1.15,children:zA(Qe,{size:[6.8,6,.01]})})]}),qe(Sc,{children:[zA(Zi,{z:1.15,children:zA(Qe,{size:[6.8,6,.01]})}),zA(Zi,{z:2.3,children:zA(Qe,{size:[6.3999999999999995,5.6,.01]})})]})]})}),c=({xDir:I})=>{const C=I*3.08,Q=I*(6/2-.2/2+1),h=I*(6/2-.2/2),E=Math.abs(h-Q),u=(Q+h)/2;return zA(wo,{color:"#c0c0c0",children:qe(zQ,{children:[zA(Qe,{size:[2.3*.8,2.95,.2],center:[C,0,.2/2]}),zA(Qe,{size:[.2,2.95,1.14],center:[Q,0,1.14/2+.2]}),zA(Qe,{size:[E,2.95,.2],center:[u,0,.2/2+1.14]})]})})};return qe(Jn,{children:[zA(c,{xDir:1}),zA(c,{xDir:-1}),g]})},Ave=()=>{const I=zA(wo,{color:"#222",children:qe(zQ,{children:[zA(Zi,{z:.27,children:zA(Qe,{size:[2.9,1.9,.54]})}),qe(Sc,{children:[zA(Zi,{z:.54,children:zA(Qe,{size:[2.9,1.9,.01]})}),zA(Zi,{z:1.08,children:zA(Qe,{size:[2.6999999999999997,1.7,.01]})})]})]})});return qe(Jn,{children:[zA(Qe,{color:"#ccc",size:[1,1.2,.25],center:[-1.3,0,.25/2]}),zA(Qe,{color:"#ccc",size:[1,1.2,.25],center:[1.3,0,.25/2]}),I]})},tve=()=>qe(Jn,{children:[zA(Qe,{color:"#ccc",size:[1,.6,.12],center:[-1.3,0,.12/2]}),zA(Qe,{color:"#ccc",size:[1,.6,.12],center:[1.3,0,.12/2]}),zA(wo,{color:"#222",children:qe(zQ,{children:[zA(Zi,{z:.55/2,children:zA(Qe,{size:[2.7,1.6,.55]})}),qe(Sc,{children:[zA(Zi,{z:.55,children:zA(Qe,{size:[2.7,1.6,.01]})}),zA(Zi,{z:1.1,children:zA(Qe,{size:[2.7-.2,1.6-.2,.01]})})]})]})})]}),eve=()=>qe(Jn,{children:[zA(Qe,{color:"#ccc",size:[1,.9,.2],center:[-1.3,0,.2/2]}),zA(Qe,{color:"#ccc",size:[1,.9,.2],center:[1.3,0,.2/2]}),zA(wo,{color:"#222",children:qe(zQ,{children:[zA(Zi,{z:.2/2,children:zA(Qe,{size:[2.75,1.8,.2]})}),qe(Sc,{children:[zA(Zi,{z:.2,children:zA(Qe,{size:[2.75,1.8,.01]})}),zA(Zi,{z:1,children:zA(Qe,{size:[2.75-.4,1.8-.4,.01]})})]})]})}),zA(Qe,{color:"#777",size:[.2,1.8-.4,.01],center:[-1.3+.4,0,1]})]}),ive=()=>qe(Jn,{children:[zA(Qe,{color:"#ccc",size:[.9,.9,.2],center:[-1.225,0,.2/2]}),zA(Qe,{color:"#ccc",size:[.9,.9,.2],center:[1.225,0,.2/2]}),zA(wo,{color:"#222",children:qe(zQ,{children:[qe(Sc,{children:[zA(Zi,{z:.2,children:zA(Qe,{size:[2.6-.1/2,1.7-.1/2,.01]})}),zA(Zi,{z:.01,children:zA(Qe,{size:[2.6-.1,1.7-.1,.01]})})]}),qe(Sc,{children:[zA(Zi,{z:.2,children:zA(Qe,{size:[2.6,1.7,.01]})}),zA(Zi,{z:1,children:zA(Qe,{size:[2.6-.4,1.7-.4,.01]})})]})]})}),zA(Qe,{color:"#777",size:[.2*2.7,1.7-.4,.02],center:[-1.225+.4,0,1]})]}),nve=()=>qe(Jn,{children:[zA(Qe,{color:"#ccc",size:[.9,1.75,.2],center:[-1.825,0,.2/2]}),zA(Qe,{color:"#ccc",size:[.9,1.75,.2],center:[1.825,0,.2/2]}),zA(wo,{color:"#222",children:qe(zQ,{children:[qe(Sc,{children:[zA(Zi,{z:.2,children:zA(Qe,{size:[3.8-.05/2,2.5-.05/2,.01]})}),zA(Zi,{z:.01,children:zA(Qe,{size:[3.8-.05,2.5-.05,.01]})})]}),qe(Sc,{children:[zA(Zi,{z:.2,children:zA(Qe,{size:[3.8,2.5,.01]})}),zA(Zi,{z:1,children:zA(Qe,{size:[3.8-.4,2.5-.4,.01]})})]})]})}),zA(Qe,{color:"#777",size:[.2*2.7,2.5-.4,.02],center:[-1.825+.4,0,1]})]}),ove=()=>qe(Jn,{children:[zA(Qe,{color:"#ccc",size:[.4,.25,.14],center:[-.4,0,.14/2]}),zA(Qe,{color:"#ccc",size:[.4,.25,.14],center:[.4,0,.14/2]}),zA(wo,{color:"#222",children:qe(zQ,{children:[zA(Zi,{z:.14/2,children:zA(Qe,{size:[.8,.6,.14]})}),qe(Sc,{children:[zA(Zi,{z:.14,children:zA(Qe,{size:[.8,.6,.01]})}),zA(Zi,{z:.37,children:zA(Qe,{size:[.8-.1,.6-.1,.01]})})]})]})})]}),sve=()=>{const c=3.0999999999999996;return qe(Jn,{children:[zA(no,{rotation:Math.PI,position:{x:6.6/2+c/4,y:0,z:.25/2},width:3,thickness:.25,padContactLength:.5,bodyDistance:c,height:.75}),zA(no,{position:{x:-6.6/2-c/4,y:0,z:.25/2},width:.7,thickness:.25,padContactLength:.5,bodyDistance:c,height:.75}),zA(no,{position:{x:-6.6/2-c/4,y:-2.3,z:.25/2},width:.7,thickness:.25,padContactLength:.5,bodyDistance:c,height:.75}),zA(no,{position:{x:-6.6/2-c/4,y:2.3,z:.25/2},width:.7,thickness:.25,padContactLength:.5,bodyDistance:c,height:.75}),zA(pB,{center:{x:0,y:0,z:0},width:3.5,length:6.5,height:1.7,includeNotch:!1,taperRatio:.06,straightHeightRatio:.45})]})},rve=()=>qe(Jn,{children:[Array.from({length:16}).map((B,C)=>zA(no,{position:{x:-10.5/2,y:C*.5-3.75,z:.25/2},width:.2,thickness:.25,padContactLength:.45,bodyDistance:.95,height:.65})),Array.from({length:16}).map((B,C)=>zA(no,{rotation:Math.PI,position:{x:10.5/2,y:C*.5-3.75,z:.25/2},width:.2,thickness:.25,padContactLength:.45,bodyDistance:.95,height:.65})),Array.from({length:16}).map((B,C)=>zA(no,{rotation:Math.PI/2,position:{x:C*.5-3.75,y:-10.5/2,z:.25/2},width:.2,thickness:.25,padContactLength:.45,bodyDistance:.95,height:.65})),Array.from({length:16}).map((B,C)=>zA(no,{rotation:-Math.PI/2,position:{x:C*.5-3.75,y:10.5/2,z:.25/2},width:.2,thickness:.25,padContactLength:.45,bodyDistance:.95,height:.65})),zA(pB,{center:{x:0,y:0,z:0},width:9,length:9,height:1.2,chamferSize:.7,taperRatio:.05,notchPosition:{x:-3.5,y:3.5,z:1.2},notchRadius:1.2/2})]}),ave=rve,gve=()=>{const g=.7999999999999998;return qe(Jn,{children:[zA(no,{rotation:Math.PI,position:{x:2.05/2+g/4,y:0,z:.18/2},width:.3,thickness:.18,padContactLength:.2,bodyDistance:g,height:.65}),zA(no,{position:{x:-2.05/2-g/4,y:-.65,z:.18/2},width:.3,thickness:.18,padContactLength:.2,bodyDistance:g,height:.65}),zA(no,{position:{x:-2.05/2-g/4,y:.65,z:.18/2},width:.3,thickness:.18,padContactLength:.2,bodyDistance:g,height:.65}),zA(pB,{center:{x:0,y:0,z:0},width:1.25,length:2,height:.9,includeNotch:!1,taperRatio:.06,straightHeightRatio:.7,heightAboveSurface:.05})]})},cve=({pinCount:e,pitch:A,leadWidth:t,padContactLength:i,bodyWidth:n})=>{const o=e/4;if(o!==Math.floor(o))throw new Error(`LQFP pinCount must be divisible by 4, got ${e}`);A||(A=.5),i||(i=.6),t||(t=.22),n||(n=A*(o+4));const s=n,r=(o-1)*A/2,a=s+3.3*i,g=a,c=.8,I=.2,l=(g-n)/2+.4;return qe(Jn,{children:[Array.from({length:o}).map((B,C)=>zA(no,{position:{x:-g/2-.36,y:C*A-r,z:I/2},width:t,thickness:I,padContactLength:i,bodyDistance:l,height:c})),Array.from({length:o}).map((B,C)=>zA(no,{rotation:Math.PI,position:{x:g/2+.36,y:C*A-r,z:I/2},width:t,thickness:I,padContactLength:i,bodyDistance:l,height:c})),Array.from({length:o}).map((B,C)=>zA(no,{rotation:Math.PI/2,position:{x:C*A-r,y:-a/2-.36,z:I/2},width:t,thickness:I,padContactLength:i,bodyDistance:l,height:c})),Array.from({length:o}).map((B,C)=>zA(no,{rotation:-Math.PI/2,position:{x:C*A-r,y:a/2+.36,z:I/2},width:t,thickness:I,padContactLength:i,bodyDistance:l,height:c})),zA(pB,{center:{x:0,y:0,z:0},width:n,length:s,height:1.5,heightAboveSurface:.1,taperRatio:.04,chamferSize:.7,notchPosition:{x:-(s/2-1.5),y:s/2-1.5,z:1.5},notchRadius:1.5/2})]})},Ive=()=>{const i=.20900000000000002,n=.1,o=.3,s=.1,r=.2;return qe(Jn,{children:[zA(wo,{color:"#222",children:qe(zQ,{children:[zA(Qe,{size:[.85,1.2,i],center:[0,0,i/2]}),qe(Sc,{children:[zA(Zi,{z:i,children:zA(Qe,{size:[.85,1.2,.01]})}),zA(Zi,{z:.38,children:zA(Qe,{size:[.85-n,1.2-n,.01]})})]})]})}),zA(Qe,{color:"#ccc",size:[o,.25,s],center:[.55,0,s/2]}),zA(Qe,{color:"#ccc",size:[o,r,s],center:[-.55,.4,s/2]}),zA(Qe,{color:"#ccc",size:[o,r,s],center:[-.55,-.4,s/2]})]})},lve=({num_pins:e,bodyWidth:A=5.3,bodyLength:t=5.3,bodyThickness:i=1,thermalPadSize:n,padWidth:o=t/5.3*.6,padLength:s=t/5.3*1,pitch:r=.5,thermalPadThickness:a=.2})=>{const g=[],c=Math.floor(e/2),I=r*(c-1);for(let l=0;l<e;l++){const B=l<c?"left":"right",C=l%c,Q=I/2-C*r,h=s,E=o,u=B==="left"?-A/2+h/2:A/2-h/2,d=l+1;g.push({pinNumber:d,x:u,y:Q,padSizeX:h,padSizeY:E})}return qe(Jn,{children:[zA(pB,{center:{x:0,y:0,z:0},width:A,length:t,height:i,heightAboveSurface:0,color:"grey",chamferSize:.2,taperRatio:0,notchPosition:{x:-(A/2-s),y:t/2-s,z:i}}),g.map((l,B)=>zA(Qe,{center:[l.x,l.y,a/2],size:[l.padSizeX,l.padSizeY,a]})),n?.length!==void 0&&n?.width!==void 0&&zA(Qe,{center:[0,0,a/2],size:[n.width,n.length,a]})]})},Bve=({bodyLength:e=10.2,bodyWidth:A=4.65,bodyHeight:t=13.46,leadSpacing:i=5,leadDiameter:n=.8,leadLength:o=12.7,color:s="#ddd",leadColor:r="#b87333"})=>{const a=e/2,g=A/2,c=a-g,I=i/2,l=.85;return qe(Jn,{children:[qe(wo,{color:s,children:[qe(Sc,{children:[zA(kp,{height:t,roundRadius:.5,radius:g,center:[-c,0,t]}),zA(kp,{height:t,roundRadius:.5,radius:g,center:[c,0,t]})]}),qe(Sc,{children:[zA(kp,{height:l,roundRadius:.1,radius:g+.85,center:[-c,0,t/2+l/2]}),zA(kp,{height:l,roundRadius:.1,radius:g+.85,center:[c,0,t/2+l/2]})]})]}),qe(wo,{color:r,children:[zA(ql,{height:o+t/2,radius:n/2,center:[-I+.06,0,-(o/2)+t/2]}),zA(ql,{height:o+t/2,radius:n/2,center:[I-.06,0,-(o/2)+t/2]})]})]})},Cve=({bodyLength:e=1.4,bodyDiameter:A=1.1,color:t="#3a3a3aff",contactColor:i="#c6c6c6",cathodeIdentification:n="#111"})=>qe(Jn,{children:[zA(wo,{color:t,children:qe(rC,{rotation:[0,"90deg",0],children:[zA(O8,{size:[A,A,e-.2],roundRadius:.2,center:[-A/2,0,.05]}),zA(ql,{height:.2/2,radius:A/2-.2,center:[-A/2,0,-e/2+.2/2]})]})}),zA(wo,{color:n,children:zA(rC,{rotation:[0,"90deg",0],children:zA(O8,{size:[A*1.01,A*1.01,e/3],roundRadius:.2,center:[-A/2,0,-e/4+.1]})})}),zA(wo,{color:i,children:zA(rC,{rotation:[0,"90deg",0],children:zA(kp,{height:.2,radius:A/2,roundRadius:.2/3,center:[-A/2,0,-e/2]})})}),zA(wo,{color:i,children:zA(rC,{rotation:[0,"90deg",0],children:zA(kp,{height:.2,radius:A/2,roundRadius:.2/3,center:[-A/2,0,e/2]})})})]}),Qve=({bodyLength:e=3.5,bodyDiameter:A=1.5,color:t="#3a3a3aff",contactColor:i="#c6c6c6"})=>qe(Jn,{children:[zA(wo,{color:t,children:zA(rC,{rotation:[0,"90deg",0],children:zA(kp,{height:e,radius:A/2,roundRadius:.3,center:[-A/2,0,0]})})}),zA(wo,{color:i,children:zA(rC,{rotation:[0,"90deg",0],children:zA(kp,{height:.5,radius:A/2,roundRadius:.2,center:[-A/2,0,-e/2]})})}),zA(wo,{color:i,children:zA(rC,{rotation:[0,"90deg",0],children:zA(kp,{height:.5,radius:A/2,roundRadius:.2,center:[-A/2,0,e/2]})})})]}),hve=({bodyLength:e=3.9,bodyDiameter:A=2.5,color:t="#3a3a3aff",contactColor:i="#c6c6c6"})=>qe(Jn,{children:[zA(wo,{color:t,children:zA(rC,{rotation:[0,"90deg",0],children:zA(kp,{height:e,radius:A/2,roundRadius:.3,center:[-A/2,0,0]})})}),zA(wo,{color:i,children:zA(rC,{rotation:[0,"90deg",0],children:zA(kp,{height:.55,radius:A/2,roundRadius:.2,center:[-A/2,0,-e/2]})})}),zA(wo,{color:i,children:zA(rC,{rotation:[0,"90deg",0],children:zA(kp,{height:.55,radius:A/2,roundRadius:.2,center:[-A/2,0,e/2]})})})]}),Eve=({pinCount:e,padContactLength:A=.6,leadWidth:t=.41,pitch:i=1.27})=>{if(e%2!==0)throw new Error("MS012 pinCount must be even");const n=e/2,o=4.9,s=3.9,r=(n-1)*i/2,a=.2;return qe(Jn,{children:[Array.from({length:n}).map((g,c)=>zA(no,{position:{x:-s/2-A-.3,y:c*i-r,z:a/2},width:t,thickness:a,padContactLength:A,bodyDistance:A+.4,height:.85})),Array.from({length:n}).map((g,c)=>zA(no,{rotation:Math.PI,position:{x:s/2+A+.3,y:c*i-r,z:a/2},width:t,thickness:a,padContactLength:A,bodyDistance:A+.4,height:.85})),zA(pB,{center:{x:0,y:0,z:a/2},width:s,length:o,height:1.55,notchPosition:{x:-.95,y:o/2-1,z:1.55},heightAboveSurface:.17,taperRatio:.09})]})},uve=({pinCount:e=16,padContactLength:A=.6,leadWidth:t=.41,pitch:i=1.27})=>{if(e!==16)throw new Error("MS013 only supports 16 pins");const n=e/2,o=7.5,s=10.3,r=(n-1)*i/2,a=.2;return qe(Jn,{children:[Array.from({length:n}).map((g,c)=>zA(no,{position:{x:-o/2-A-.3,y:c*i-r,z:a/2},width:t,thickness:a,padContactLength:A,bodyDistance:A+.4,height:.85})),Array.from({length:n}).map((g,c)=>zA(no,{rotation:Math.PI,position:{x:o/2+A+.3,y:c*i-r,z:a/2},width:t,thickness:a,padContactLength:A,bodyDistance:A+.4,height:.85})),zA(pB,{center:{x:0,y:0,z:a/2},width:o,length:s,height:1.1,notchPosition:{x:-2.25,y:s/2-1.5,z:1.1},heightAboveSurface:.17,taperRatio:.05})]})},dve=()=>{const Q=7.050000000000001,h=24.95+6.5/2;return zA(Zi,{center:[0,0,1],children:qe(Jn,{children:[qe(rC,{rotation:[0,55,-55],children:[qe(Bm,{children:[zA(Qe,{color:"#ccc",size:[6.5+.1,9.9,1.3],center:[h,0,1.3-2]}),zA(ql,{color:"black",center:[h,0,1.3-2],radius:3/2,height:1.3*1.2})]}),zA(wo,{color:"#222",children:zA(pB,{width:9.9,length:9.9,height:4.5,center:{x:20,y:0,z:-2.4},includeNotch:!1,straightHeightRatio:.3,taperRatio:.04,heightAboveSurface:1})})]}),zA(rC,{rotation:[0,55,55],children:Array.from({length:3}).map((E,u)=>{const d=Q,f=(u-1)*2.7,m=-.5-.6;return qe(wo,{color:"gold",children:[qe(Sc,{children:[zA(Zi,{center:[15.05-4.5/2+.1,f,m],children:zA(Qe,{size:[4.5,.81+1,.5]})}),zA(Zi,{center:[15.05-4.5/2-1+.1,f,m],children:zA(Qe,{size:[4.5,.81,.5]})})]}),zA(Zi,{center:[d,f,m],children:zA(Qe,{size:[16+.1,.81,.5]})})]},`prong-${u}`)})})]})})},pve=()=>{const g=1.1999999999999997;return qe(Jn,{children:[zA(no,{rotation:Math.PI,position:{x:2.8/2+g/4,y:-.95,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:g,height:.95}),zA(no,{rotation:Math.PI,position:{x:2.8/2+g/4,y:0,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:g,height:.95}),zA(no,{rotation:Math.PI,position:{x:2.8/2+g/4,y:.95,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:g,height:.95}),zA(no,{position:{x:-2.8/2-g/4,y:0,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:g,height:.95}),zA(no,{position:{x:-2.8/2-g/4,y:-.95,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:g,height:.95}),zA(no,{position:{x:-2.8/2-g/4,y:.95,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:g,height:.95}),zA(pB,{center:{x:0,y:0,z:0},width:1.6,length:2.9,height:1.2,straightHeightRatio:.6,notchPosition:{x:-.4,y:1.2/2+.4,z:1.2+.05},notchRadius:.1})]})},fve=()=>qe(Jn,{children:[zA(pB,{center:{x:0,y:0,z:0},width:.8,length:1,height:.37,heightAboveSurface:0,color:"#1a1a1a",taperRatio:.15,straightHeightRatio:0,notchPosition:{x:-.8/4,y:.7/2.2,z:.37+.1}}),[0,1,2].map(g=>{const c=-.35+g*.35;return zA(Qe,{center:[-.8/2+.19/2-.1,c,.12/2],size:[.19,.15,.12]})}),[0,1,2].map(g=>{const c=-.35+g*.35;return zA(Qe,{center:[.8/2-.19/2+.1,c,.12/2],size:[.19,.15,.12]})})]}),yve=()=>{const s="#222",a=[.43,.4,1.32],g=[.43,.4,.25],c=[0,0,-.66],I=[0,0,-1.32],l=[0,1.28,-2.72],B=[0,1.28,-8.9],C=-7.5;return qe(Zi,{center:[0,1,10.5],children:[zA(wo,{color:s,children:qe(Bm,{children:[zA(Zi,{center:[0,0,2.25],children:zA(ql,{radius:2.4,height:4.5})}),zA(Zi,{center:[0,-1.8499999999999999,2.25],children:zA(Qe,{size:[2.4*2,1.1,4.5+.2]})})]})}),zA(Zi,{center:c,children:zA(Qe,{size:a})}),qe(Sc,{children:[zA(Zi,{center:I,children:zA(Qe,{size:g})}),zA(Zi,{center:l,children:zA(Qe,{size:g})})]}),zA(Zi,{center:B,children:zA(Qe,{size:[.43,.4,12.2]})}),zA(Zi,{center:[1.3,0,C],children:zA(Qe,{size:[.43,.4,15]})}),zA(Zi,{center:[-1.3,0,C],children:zA(Qe,{size:[.43,.4,15]})})]})},mve=()=>qe(Jn,{children:[zA(no,{rotation:Math.PI,position:{x:2/2+.75/4,y:-.65,z:.15/2},width:.25,thickness:.15,padContactLength:.3,bodyDistance:.75,height:.85}),zA(no,{rotation:Math.PI,position:{x:2/2+.75/4,y:0,z:.15/2},width:.25,thickness:.15,padContactLength:.3,bodyDistance:.75,height:.85}),zA(no,{rotation:Math.PI,position:{x:2/2+.75/4,y:.65,z:.15/2},width:.25,thickness:.15,padContactLength:.3,bodyDistance:.75,height:.85}),zA(no,{position:{x:-2/2-.75/4,y:0,z:.15/2},width:.25,thickness:.15,padContactLength:.3,bodyDistance:.75,height:.85}),zA(no,{position:{x:-2/2-.75/4,y:-.65,z:.15/2},width:.25,thickness:.15,padContactLength:.3,bodyDistance:.75,height:.85}),zA(no,{position:{x:-2/2-.75/4,y:.65,z:.15/2},width:.25,thickness:.15,padContactLength:.3,bodyDistance:.75,height:.85}),zA(pB,{center:{x:0,y:0,z:0},width:1.25,length:2,height:1.1,straightHeightRatio:.6,notchPosition:{x:-.375,y:1.1/2+.2,z:1.1},heightAboveSurface:.1})]}),wve=mve,Dve=()=>qe(Jn,{children:[zA(pB,{center:{x:0,y:0,z:.05},width:1,length:1.45,height:.5,heightAboveSurface:0,color:"#1a1a1a",taperRatio:0,includeNotch:!1}),[0,1,2].map(r=>{const a=-.5+r*.5;return zA(Qe,{center:[-1/2+.3/2,a,.05/2],size:[.3,.2,.05]})}),[0,1,2].map(r=>{const a=-.5+r*.5;return zA(Qe,{center:[1/2-.3/2,a,.05/2],size:[.3,.2,.05]})})]}),xve=()=>qe(Jn,{children:[zA(no,{position:{x:-2.5/2,y:0,z:.175/2},width:.3,thickness:.175,padContactLength:.3,bodyDistance:.45,height:.7}),zA(no,{rotation:Math.PI,position:{x:2.5/2,y:0,z:.175/2},width:.3,thickness:.175,padContactLength:.3,bodyDistance:.45,height:.7}),zA(wo,{color:"#222",children:zA(pB,{center:{x:0,y:0,z:0},width:1.7,length:1.25,height:.95,includeNotch:!1,taperRatio:.06,straightHeightRatio:.7,heightAboveSurface:.05})}),zA(Qe,{color:"#777",size:[1.7/3,1.25-.075,.02],center:[-.85*2/3+.035,0,.95+.05]})]}),Sve=()=>qe(Jn,{children:[zA(Qe,{color:"#ccc",size:[.4,.325,.175],center:[-1.05,0,.175/2]}),zA(Qe,{color:"#ccc",size:[.4,.325,.175],center:[1.05,0,.175/2]}),zA(wo,{color:"#222",children:qe(zQ,{children:[zA(Zi,{z:.175/2,children:zA(Qe,{size:[1.7,1.25,.175]})}),qe(Sc,{children:[zA(Zi,{z:.175,children:zA(Qe,{size:[1.7,1.25,.01]})}),zA(Zi,{z:.725,children:zA(Qe,{size:[1.7-.2,1.25-.2,.01]})})]})]})}),zA(Qe,{color:"#777",size:[1.7/3,1.25-.2,.02],center:[-1.05+1.7/4.4+.2,0,.725]})]}),bve=()=>{const s=-1.0474999999999999,r=1.775/2+.4/2-.04;return qe(Jn,{children:[zA(Qe,{color:"#ccc",size:[.4,.325,.13],center:[s,0,.13/2]}),zA(Qe,{color:"#ccc",size:[.4,.325,.13],center:[r,0,.13/2]}),zA(wo,{color:"#222",children:zA(pB,{width:1.775,length:1.25,height:.725,center:{x:0,y:0,z:0},heightAboveSurface:0,straightHeightRatio:.7,taperRatio:.06,includeNotch:!1})}),zA(Qe,{color:"#777",size:[1.775/3,1.25-.05,.02],center:[s+1.775/4.4+.2,0,.725]})]})},_ve=({pitch:e=10})=>qe(Jn,{children:[zA(ql,{height:4,radius:.5,center:[-e/2,0,.5]}),zA(uO,{radius:.5,center:[-e/2,0,2.5]}),zA(Zi,{x:-2.5,y:0,z:2.5,children:qe(rC,{rotation:[0,Math.PI/2,0],children:[zA(ql,{height:e,radius:.5,center:[0,0,2.5]}),zA(wo,{color:"#d2b48c",children:zA(ql,{height:5,radius:1.3,center:[0,0,2.5]})})]})}),zA(ql,{height:4,radius:.5,center:[e/2,0,.5]}),zA(uO,{radius:.5,center:[e/2,0,2.5]})]}),kve=({bodyWidth:e=21,boardThickness:A=.5,leadWidth:t=1.6,leadLength:i=2.4,leadsPitch:n=2.54,leadsLeft:o,leadsRight:s,leadsTop:r,leadsBottom:a,innerHoles:g=!0,innerHoleEdgeDistance:c=1.61,innerHoleDiameter:I=1})=>{const l=e/2,B=A/2,C=A*1.05,Q=I/2,h=Math.max(o||0,s||0,r||0,a||0)*n||51,E=[],u=[];if(s){const w=-((s-1)/2)*n;for(let D=0;D<s;D++){const x=w+D*n;E.push({x:l-i/2,y:-x,pl:i,pw:t}),g&&u.push({x:l,y:-x},{x:l-c,y:-x})}}if(o){const w=-((o-1)/2)*n;for(let D=0;D<o;D++){const x=w+D*n;E.push({x:-l+i/2,y:-x,pl:i,pw:t}),g&&u.push({x:-l,y:-x},{x:-l+c,y:-x})}}if(r){const w=-((r-1)/2)*n;for(let D=0;D<r;D++){const x=w+D*n;E.push({x:-x,y:h/2-i/2,pl:t,pw:i}),g&&u.push({x:-x,y:h/2},{x:-x,y:h/2-c})}}if(a){const w=-((a-1)/2)*n;for(let D=0;D<a;D++){const x=w+D*n;E.push({x:-x,y:-h/2+i/2,pl:t,pw:i}),g&&u.push({x:-x,y:-h/2},{x:-x,y:-h/2+c})}}const d=zA(wo,{color:"#008080",children:qe(Bm,{children:[zA(Qe,{center:[0,0,B],size:[e,h,A]}),E.map((w,D)=>zA(Qe,{center:[w.x,w.y,B],size:[w.pl+.01,w.pw+.01,C]},D))]})}),f=g&&u.map((w,D)=>zA(ql,{color:"black",center:[w.x,w.y,B],radius:Q,height:A*1.07})),m=E.map((w,D)=>zA(Qe,{center:[w.x,w.y,B],size:[w.pl+.01,w.pw+.01,C]}));return qe(Jn,{children:[d,zA(wo,{color:"#FFD700",children:g?qe(Bm,{children:[zA(zQ,{children:E.map((w,D)=>zA(Qe,{center:[w.x,w.y,B],size:[w.pl+.01,w.pw+.01,C]},D))}),f]}):m})]})},vve=({width:e=30,height:A=22,thickness:t=1,bezelInset:i=2,bezelDepth:n=1,screenColor:o="#001414",bezelColor:s="#0f1116",screenWidth:r,screenHeight:a,offset:g})=>{const c=e,I=A,l=Math.max(t,.4),B=Math.max(Math.min(n,l),.2),C=Math.max(l-B,0),Q=Math.max(i,0),h=Math.max(r??c-Q*2,2),E=Math.max(a??I-Q*2,2),u=Math.min(Math.max(B*.6,.2),B),d=g?.x??0,f=g?.y??0,m=g?.z??0;return qe(Zi,{offset:{x:d,y:f,z:m},children:[C>0&&zA(wo,{color:s,children:zA(Qe,{size:[c,I,C],offset:[0,0,C/2]})}),zA(wo,{color:s,children:qe(Bm,{children:[zA(Qe,{size:[c,I,B],offset:[0,0,C+B/2]}),zA(Qe,{size:[h,E,B+.02],offset:[0,0,C+B/2]})]})}),zA(wo,{color:o,children:zA(Qe,{size:[h,E,u],offset:[0,0,C+u/2]})})]})},Fve=({numPins:e=5,rows:A=1,p:t=2.54,id:i=1,od:n=1.5,boardThickness:o=1.6,width:s,height:r,pinRowSide:a="left",holes:g=[],holeInset:c=1,pinRowHoleEdgeToEdgeDist:I=2,female:l,nopin:B,screen:C,screenWidth:Q,screenHeight:h,screenCenterOffsetX:E,screenCenterOffsetY:u})=>{const d=C??!1,f=o/2,m=Math.ceil(e/A);let w,D;a==="left"||a==="right"?(w=(A-1)*t+2*I,D=(m-1)*t+2*I):(D=(A-1)*t+2*I,w=(m-1)*t+2*I),e===0&&(w=10,D=10);const x=Number(s??w),_=Number(r??D),b=[];let R=0,F=0,H=0,Y=0,J=0,O=0;a==="left"||a==="right"?(R=a==="left"?-x/2+I:x/2-I,F=-((m-1)/2)*t,H=0,Y=t,J=a==="left"?t:-t,O=0):(R=-((m-1)/2)*t,F=a==="top"?_/2-I:-_/2+I,H=t,Y=0,J=0,O=a==="top"?-t:t);let W=0;for(let EA=0;EA<A&&W<e;EA++)for(let bA=0;bA<m&&W<e;bA++){const dA=R+bA*H+EA*J,WA=F+bA*Y+EA*O;b.push({x:dA,y:WA}),W++}const z=[];if(g)for(const EA of g){let bA=0,dA=0;EA==="topleft"?(bA=-x/2+c,dA=_/2-c):EA==="topright"?(bA=x/2-c,dA=_/2-c):EA==="bottomleft"?(bA=-x/2+c,dA=-_/2+c):EA==="bottomright"?(bA=x/2-c,dA=-_/2+c):EA==="center"&&(bA=0,dA=0),z.push({x:bA,y:dA})}const tA=.63,aA=2,eA=6,oA=3,rA=B||l?0:aA,lA=rA+o,pA=zA(wo,{color:"#008080",children:qe(Bm,{children:[zA(Qe,{center:[0,0,f+rA],size:[x,_,o]}),z.map((EA,bA)=>zA(ql,{center:[EA.x,EA.y,f+rA],radius:n/2,height:o},`hole-${bA}`)),b.map((EA,bA)=>zA(ql,{center:[EA.x,EA.y,f+rA],radius:n/2,height:o},`pin-hole-${bA}`))]})}),kA=b.map((EA,bA)=>zA(wo,{color:"#FFD700",children:qe(Bm,{children:[zA(ql,{center:[EA.x,EA.y,o/2+rA],radius:n/2,height:o}),zA(ql,{center:[EA.x,EA.y,o/2+rA],radius:i/2,height:o})]})})),MA=b.map((EA,bA)=>zA(Ret,{x:EA.x,y:EA.y,pinThickness:tA,shortSidePinLength:oA,longSidePinLength:eA,bodyHeight:aA,flipZ:dA=>dA})),JA=b.map((EA,bA)=>zA(Tet,{x:EA.x,y:EA.y,flipZ:dA=>-dA}));return qe(Jn,{children:[pA,kA,!l&&!B&&MA,l&&JA,d&&zA(vve,{width:Q??x*.8,height:h??_*.6,offset:{x:E??0,y:u??0,z:lA}})]})},Mve=({footprint:e})=>{const A=Qke.string(e).json();switch(A.fn){case"dip":return zA(pke,{numPins:A.num_pins,pitch:A.p,bodyWidth:A.w});case"axial":return zA(_ve,{pitch:A.p});case"tssop":return zA(yke,{pinCount:A.num_pins,leadLength:A.pl,leadWidth:A.pw,pitch:A.p,bodyWidth:A.w});case"msop":return zA(mke,{pinCount:A.num_pins,padContactLength:A.pl,leadWidth:A.pw,pitch:A.p,bodyWidth:A.w});case"vssop":return zA(Zke,{pinCount:A.num_pins,leadLength:A.pl,leadWidth:A.pw,pitch:A.p,bodyWidth:A.w,bodyLength:A.h});case"qfp":return zA(Ske,{pinCount:A.num_pins,pitch:A.p,leadWidth:A.pw,padContactLength:A.pl,bodyWidth:A.w});case"tqfp":return zA(ave,{});case"lqfp":return zA(cve,{pinCount:A.num_pins});case"qfn":{const n=typeof A.thermalpad?.x=="number"&&typeof A.thermalpad?.y=="number";return zA(Rke,{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(lve,{num_pins:A.num_pins,bodyWidth:A.w,bodyLength:A.h,pitch:A.p,padLength:A.pl,padWidth:A.pw,thermalPadSize:n?{width:A.thermalpad.x,length:A.thermalpad.y}:void 0})}case"pinrow":{const n=e.match(/_rows(\d+)/),o=n&&n[1]?parseInt(n[1],10):1;if(A.male)return zA(vke,{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(qke,{numberOfPins:A.num_pins,pitch:A.p,rows:o})}case"cap":switch(A.imperial){case"0402":return zA(Fet,{color:"#856c4d"});case"0603":return zA(Met,{color:"#856c4d"});case"0805":return zA(Get,{color:"#856c4d"});case"0201":return zA(Net,{color:"#856c4d"});case"01005":return zA(Let,{color:"#856c4d"});case"1206":return zA(Uet,{color:"#856c4d"});case"1210":return zA(Het,{color:"#856c4d"});case"2010":return zA(Yet,{color:"#856c4d"});case"2512":return zA(Jet,{color:"#856c4d"})}case"sot235":return zA(Lke,{});case"sot457":return zA(pve,{});case"sot223":return zA(sve,{});case"sot23w":return zA(Uke,{});case"sot323":return zA(gve,{});case"sod323f":return zA(Sve,{});case"sod323fl":return zA(bve,{});case"sot363":return zA(wve,{});case"sot886":return zA(Dve,{});case"sot963":return zA(fve,{});case"pushbutton":return zA(Oke,{width:A.w,length:A.h,innerDiameter:A.id});case"soic":return zA(Wke,{pinCount:A.num_pins,leadLength:A.pl,leadWidth:A.pw,pitch:A.p,bodyWidth:A.w});case"sod523":return zA(Vke,{});case"sod882":return zA(jke,{});case"sma":return zA(zke,{});case"smb":return zA(Xke,{});case"smc":return zA($ke,{});case"smf":return zA(Ave,{});case"sod123f":return zA(tve,{});case"sod123fl":return zA(eve,{});case"sod123w":return zA(ive,{});case"sod128":return zA(nve,{});case"sod323":return zA(xve,{});case"sod923":return zA(ove,{});case"hc49":return zA(Bve,{});case"micromelf":return zA(Cve,{});case"minimelf":return zA(Qve,{});case"melf":return zA(hve,{});case"ms012":return zA(Eve,{pinCount:A.num_pins,padContactLength:A.pl,leadWidth:A.pw,pitch:A.p});case"ms013":return zA(uve,{pinCount:A.num_pins,padContactLength:A.pl,leadWidth:A.pw,pitch:A.p});case"sot723":return zA(Ive,{});case"to220":return zA(dve,{});case"to92":return zA(yve,{});case"stampboard":case"stampreceiver":return zA(kve,{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(Fve,{numPins:g,rows:n,p:A.p,id:A.id,od:A.od,width:r,height:a,pinRowSide:o,holes:I,holeInset:s,pinRowHoleEdgeToEdgeDist:c,nopin:A.nopin,female:A.female,screen:A.screen,screenWidth:A.screenwidth,screenHeight:A.screenheight,screenCenterOffsetX:A.screencenteroffsetx,screenCenterOffsetY:A.screencenteroffsety})}}const t=e.match(/_color\(([^)]+)\)/),i=t?t[1]:void 0;switch(A.imperial){case"0402":return zA(Fet,{color:i});case"0603":return zA(Met,{color:i});case"0805":return zA(Get,{color:i});case"0201":return zA(Net,{color:i});case"01005":return zA(Let,{color:i});case"1206":return zA(Uet,{color:i});case"1210":return zA(Het,{color:i});case"2010":return zA(Yet,{color:i});case"2512":return zA(Jet,{color:i})}return null},Gve=e=>e&&typeof e=="object"&&"type"in e,DF=e=>{if(typeof e=="number")return e;if(typeof e=="string"){const A=/^(-?\d+(?:\.\d+)?)\s*deg$/i.exec(e);if(A)return parseFloat(A[1])*Math.PI/180;const t=Number(e);if(!Number.isNaN(t))return t}return 0},Rve=e=>Array.isArray(e)?[Number(e[0])||0,Number(e[1])||0,Number(e[2])||0]:typeof e=="object"&&e?[Number(e.x)||0,Number(e.y)||0,Number(e.z)||0]:[0,0,0];function JD(e,A,t){const{jscad:{primitives:i,booleans:n,hulls:o,geometries:s,extrusions:r,transforms:a}}=t;if(e==null||e===!1)return[];if(Array.isArray(e))return e.flatMap(l=>JD(l,A,t));if(!Gve(e))return[];const{type:g,props:c,children:I}=e;if(g===_et)return(I??[]).flatMap(l=>JD(l,A,t));if(g===wo){const l=c?.color;return(I??[]).flatMap(B=>JD(B,l??A,t))}if(g===Zi){const l=Rve(c?.offset??c?.center??{x:c?.x,y:c?.y,z:c?.z});return(I??[]).flatMap(C=>JD(C,A,t)).map(({geom:C,color:Q})=>({geom:a.translate(l,C),color:Q??A}))}if(g===rC){const l=Array.isArray(c?.rotation)?[DF(c.rotation[0]),DF(c.rotation[1]),DF(c.rotation[2])]:[DF(c?.x??0),DF(c?.y??0),DF(c?.z??0)];return(I??[]).flatMap(C=>JD(C,A,t)).map(({geom:C,color:Q})=>({geom:a.rotateZ(l[2],a.rotateY(l[1],a.rotateX(l[0],C))),color:Q}))}if(g===zQ||g===Bm||g===Sc){const l=(I??[]).flatMap(C=>JD(C,A,t)).map(C=>C.geom);if(l.length===0)return[];let B;return g===zQ?B=n.union(l):g===Bm?B=n.subtract(l[0],l.slice(1)):B=o.hull(l),[{geom:B,color:A}]}if(g===W8){const l=c?.points??[];return[{geom:s.geom2.fromPoints(l),color:A??c?.color}]}if(g===Z8){const l=(I??[]).flatMap(h=>JD(h,A,t)).map(h=>h.geom);if(l.length===0)return[];const B=l.length>1?n.union(l):l[0],C=c?.height??c?.h??1;let Q=r.extrudeLinear({height:C},B);if(Q.polygons)for(const h of Q.polygons)!h.plane||!h.vertices||h.vertices.length<3||h.vertices.reverse();return[{geom:Q,color:A??c?.color}]}if(g===Qe||g===ket||g===ql||g===uO||g===O8||g===kp){let l;if(g===Qe){const B=c?.size??[1,1,1],C=c?.offset,Q=c?.center??(C?[C[0],C[1],C[2]]:[0,0,0]);l=i.cuboid({size:B,center:Q})}else if(g===ket){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===ql){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===uO){const B=c?.radius??1,C=c?.center??[0,0,0];l=i.sphere({radius:B,center:C})}else if(g===kp){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 JD(l,A,t)}return(I??[]).flatMap(l=>JD(l,A,t))}function Nve(e,A){return{geometries:JD(e,void 0,{jscad:A})}}function Pet(e){if(e.polygons){const A=[],t=[],i=[];let n=0;for(const s of e.polygons){for(const a of s.vertices)a.index=n,A.push(a[0],a[1],a[2]),e.color&&e.color.length>=3?i.push(e.color[0],e.color[1],e.color[2]):i.push(1,1,1),n++;const r=s.vertices[0].index;for(let a=2;a<s.vertices.length;a++){const g=s.vertices[a-1].index,c=s.vertices[a].index;t.push(r,g,c)}}const o=new kg;if(o.setAttribute("position",new wc(new Float32Array(A),3)),o.setIndex(t),i.length>0&&o.setAttribute("color",new wc(new Float32Array(i),3)),e.transforms){const s=new $o;s.fromArray(e.transforms),o.applyMatrix4(s)}return o.computeVertexNormals(),o}if(e.sides){const A=[],t=[];for(const n of e.sides)A.push(n[0][0],n[0][1],0),e.color&&e.color.length>=3?t.push(e.color[0],e.color[1],e.color[2]):t.push(1,1,1);const i=new kg;if(i.setAttribute("position",new wc(new Float32Array(A),3)),t.length>0&&i.setAttribute("color",new wc(new Float32Array(t),3)),e.transforms){const n=new $o;n.fromArray(e.transforms),i.applyMatrix4(n)}return i}return console.error("Invalid CSG object: neither polygons nor sides found"),new kg}function Lve(e,A){const t=suA(Mve,{footprint:e});return Nve(t,A)}var Uve=Xa(gO()),Ket=AA.createContext(null),Hve=()=>{const e=AA.useContext(Ket);if(!e)throw new Error("useHover must be used within a HoverProvider");return e},Yve=({children:e})=>{const{camera:A,renderer:t}=od(),[i,n]=AA.useState([]),o=AA.useMemo(()=>new RGt,[]),s=AA.useMemo(()=>new xn,[]),r=AA.useRef(i);r.current=i;const a=AA.useRef(null),g=AA.useCallback(C=>{n(Q=>[...Q,C])},[]),c=AA.useCallback(C=>{if(a.current){let Q=!1,h=a.current.object;for(;h;){if(h===C){Q=!0;break}h=h.parent}Q&&(a.current.onUnhover(),a.current=null)}n(Q=>Q.filter(h=>h.object!==C))},[]),I=AA.useCallback(C=>{let Q=C;for(;Q;){const h=r.current.find(E=>E.object===Q);if(h)return h;Q=Q.parent}},[]),l=AA.useCallback(C=>{if(!t.domElement)return;const Q=t.domElement.getBoundingClientRect();s.x=(C.clientX-Q.left)/Q.width*2-1,s.y=-((C.clientY-Q.top)/Q.height)*2+1,o.setFromCamera(s,A);const h=r.current.map(u=>u.object);if(h.length===0){a.current&&(a.current.onUnhover(),a.current=null);return}const E=o.intersectObjects(h,!0);if(E.length>0){const u=E[0],d=I(u.object);if(d){const f={mousePosition:[u.point.x,u.point.y,u.point.z]};a.current!==d?(a.current?.onUnhover(),d.onHover(f),a.current=d):d.onHover(f)}else a.current&&(a.current.onUnhover(),a.current=null)}else a.current&&(a.current.onUnhover(),a.current=null)},[A,t,o,s,I]);AA.useEffect(()=>{const C=t.domElement;return C.addEventListener("mousemove",l),()=>{C.removeEventListener("mousemove",l)}},[t,l]);const B=AA.useMemo(()=>({addHoverable:g,removeHoverable:c}),[g,c]);return Z.jsx(Ket.Provider,{value:B,children:e})},Jve=({children:e,object:A,onHover:t,onUnhover:i,isHovered:n})=>{const{addHoverable:o,removeHoverable:s}=Hve();return AA.useEffect(()=>A?(o({object:A,onHover:t,onUnhover:i}),()=>{s(A)}):void 0,[A,t,i,o,s]),Z.jsx(Z.Fragment,{children:e})},i9=Jve,Tve=({positionOffset:e,footprint:A,rotationOffset:t,onHover:i,onUnhover:n,isHovered:o,scale:s,isTranslucent:r=!1})=>{const{rootObject:a}=od(),g=AA.useMemo(()=>{if(!A)return null;const{geometries:c}=Lve(A,Uve),I=new Jh;for(const l of c.flat(1/0)){const B=l.geom;if(!B||!B.polygons&&!B.sides)continue;const C=new An(l.color);C.convertLinearToSRGB();const Q={...B,color:[C.r,C.g,C.b]},h=Pet(Q),E=new K0({vertexColors:!0,side:YQ,transparent:r,opacity:r?.5:1,depthWrite:!r}),u=new ro(h,E);u.renderOrder=r?2:1,I.add(u)}return I},[A,r]);return AA.useEffect(()=>{if(!(!g||!a))return a.add(g),()=>{a.remove(g)}},[a,g]),AA.useEffect(()=>{g&&(e&&g.position.fromArray(e),t&&g.rotation.fromArray(t),s!==void 0&&g.scale.setScalar(s))},[g,e?.[0],e?.[1],e?.[2],t?.[0],t?.[1],t?.[2],s]),AA.useEffect(()=>{g&&g.traverse(c=>{c instanceof ro&&c.material instanceof K0&&(o?(c.material.emissive.setHex(255),c.material.emissiveIntensity=.2):c.material.emissiveIntensity=0)})},[o,g]),g?Z.jsx(i9,{isHovered:o,onHover:i,onUnhover:n,object:g}):null},qet=new WeakMap,Pve=()=>{const e=new AI;return e.name="fallback-environment-map",e.mapping=fH,e},Kve=e=>{if(!e)return null;const A=e,t=qet.get(A);if(t)return t;let i;if(e instanceof $H){const n=new Z$(e);i=n.fromScene(HNt(),.04).texture,n.dispose()}else i=Pve();return qet.set(A,i),i};function qve(e){const A=new Vy;let t=!1;e.updateWorldMatrix(!0,!1);const i=e.parent?e.parent.matrixWorld.clone().invert():new $o;return e.traverse(n=>{if(n.updateWorldMatrix(!0,!1),n instanceof ro&&n.geometry&&(n.geometry.boundingBox||n.geometry.computeBoundingBox(),n.geometry.boundingBox)){const o=n.geometry.boundingBox.clone();o.applyMatrix4(n.matrixWorld),o.applyMatrix4(i),t?A.union(o):(A.copy(o),t=!0)}}),t?A:null}function Ove(e){const A=qve(e);return A?A.getSize(new Mt):new Mt}function Wve(e,A,t="contain_within_bounds"){if(!A)return[1,1,1];const i=Ove(e),n=[i.x>0?A[0]/i.x:1,i.y>0?A[1]/i.y:1,i.z>0?A[2]/i.z:1];if(t==="fill_bounds")return n;const o=Math.min(...n);return[o,o,o]}var xuA=({model:e,position:A,rotation:t,modelOffset:i=[0,0,0],modelRotation:n=[0,0,0],sourceCoordinateTransform:o,modelSize:s,modelFitMode:r="contain_within_bounds",scale:a})=>{const{rootObject:g}=od(),c=AA.useMemo(()=>new Jh,[]),I=AA.useMemo(()=>new Jh,[]),l=AA.useMemo(()=>new Jh,[]),B=AA.useMemo(()=>new Jh,[]);return AA.useEffect(()=>(c.add(I),()=>{c.remove(I)}),[c,I]),AA.useEffect(()=>(I.add(l),()=>{I.remove(l)}),[I,l]),AA.useEffect(()=>(l.add(B),()=>{l.remove(B)}),[l,B]),AA.useEffect(()=>{for(;B.children.length>0;){const C=B.children[0];if(!C)break;B.remove(C)}e&&B.add(e)},[B,e]),AA.useEffect(()=>{if(!o){B.matrixAutoUpdate=!0,B.position.set(0,0,0),B.rotation.set(0,0,0),B.scale.set(1,1,1),B.updateMatrix();return}B.matrixAutoUpdate=!1,B.matrix.copy(o),B.matrixWorldNeedsUpdate=!0},[B,o]),AA.useEffect(()=>{if(g)return g.add(c),()=>{g.remove(c)}},[g,c]),AA.useEffect(()=>{if(A?c.position.fromArray(A):c.position.set(0,0,0),t?c.rotation.fromArray(t):c.rotation.set(0,0,0),l.position.fromArray(i),l.rotation.fromArray(n),l.scale.setScalar(a??1),!e){I.scale.set(1,1,1);return}I.scale.set(1,1,1),I.updateWorldMatrix(!0,!0);const C=Wve(l,s,r);I.scale.set(C[0],C[1],C[2])},[c,I,e,r,i,B,l,n,s,A,t,a]),{boardTransformGroup:c}},Oet=1.25;function Wet({gltfUrl:e,position:A,rotation:t,modelOffset:i=[0,0,0],modelRotation:n=[0,0,0],sourceCoordinateTransform:o,modelSize:s,modelFitMode:r="contain_within_bounds",onHover:a,onUnhover:g,isHovered:c,scale:I,isTranslucent:l=!1}){const{renderer:B}=od(),[C,Q]=AA.useState(null),[h,E]=AA.useState(null),{boardTransformGroup:u}=xuA({model:C,position:A,rotation:t,modelOffset:i,modelRotation:n,sourceCoordinateTransform:o,modelSize:s,modelFitMode:r,scale:I});if(AA.useEffect(()=>{if(!e)return;const d=new JNt;let f=!0;return d.load(e,m=>{if(!f)return;const w=m.scene;w.traverse(D=>{if(D instanceof ro&&D.material){const x=_=>{_.transparent=l,_.opacity=l?.5:1,_.depthWrite=!l,_.needsUpdate=!0};Array.isArray(D.material)?D.material.forEach(x):x(D.material),D.renderOrder=l?2:1}}),Q(w)},void 0,m=>{if(!f)return;console.error(`An error happened loading ${e}`,m);const w=m instanceof Error?m:new Error(`Failed to load glTF model from ${e}`);E(w)}),()=>{f=!1}},[e,l]),AA.useEffect(()=>{if(!C||!B)return;const d=Kve(B);if(!d)return;const f=[],m=w=>{w instanceof K0&&(f.push({material:w,envMap:w.envMap??null,envMapIntensity:w.envMapIntensity??1}),w.envMap=d,(typeof w.envMapIntensity!="number"||w.envMapIntensity<Oet)&&(w.envMapIntensity=Oet),w.needsUpdate=!0)};return C.traverse(w=>{if(!(w instanceof ro))return;const D=w.material;Array.isArray(D)?D.forEach(m):D&&m(D)}),()=>{f.forEach(({material:w,envMap:D,envMapIntensity:x})=>{w.envMap=D,w.envMapIntensity=x,w.needsUpdate=!0})}},[C,B]),AA.useEffect(()=>{C&&C.traverse(d=>{d instanceof ro&&d.material instanceof K0&&(c?(d.material.emissive.setHex(255),d.material.emissiveIntensity=.2):d.material.emissiveIntensity=0)})},[c,C]),h)throw h;return C?Z.jsx(i9,{isHovered:c,onHover:a,onUnhover:g,object:u}):null}var Zve=Xa(Ztt()),Vve=Xa(gO()),jve=({jscadPlan:e,positionOffset:A,rotationOffset:t,modelOffset:i=[0,0,0],modelRotation:n=[0,0,0],sourceCoordinateTransform:o,modelSize:s,modelFitMode:r="contain_within_bounds",onHover:a,onUnhover:g,isHovered:c,scale:I,isTranslucent:l=!1})=>{const{threeGeom:B,material:C}=AA.useMemo(()=>{const E=(0,Zve.executeJscadOperations)(Vve.default,e);if(!E||!E.polygons&&!E.sides)return{threeGeom:null,material:null};const u=Pet(E),d=new K0({vertexColors:!0,side:YQ,transparent:l,opacity:l?.5:1,depthWrite:!l});return{threeGeom:u,material:d}},[e,l]),Q=AA.useMemo(()=>{if(!B)return null;const E=new ro(B,C);return E.renderOrder=l?2:1,E},[B,C,l]),{boardTransformGroup:h}=xuA({model:Q,position:A,rotation:t,modelOffset:i,modelRotation:n,sourceCoordinateTransform:o,modelSize:s,modelFitMode:r,scale:I});return AA.useEffect(()=>{if(C)if(c){const E=new An(C.color.getHex());C.emissive.copy(E),C.emissive.setRGB(0,0,1),C.emissiveIntensity=.2}else C.emissiveIntensity=0},[c,C]),B?Z.jsx(i9,{isHovered:c,onHover:a,onUnhover:g,object:h}):null};function zve(e){return e.replace(/(DEF|USE)\s+([^\s]+)/g,(A,t,i)=>`${t} ${i.replace(/-/g,"_")}`)}async function Xve(e){const A=await fetch(e);if(!A.ok)throw new Error(`Failed to fetch "${e}": ${A.status} ${A.statusText}`);const t=await A.text();return new x8t().parse(zve(t),e)}typeof window<"u"&&!window.TSCIRCUIT_OBJ_LOADER_CACHE&&(window.TSCIRCUIT_OBJ_LOADER_CACHE=new Map);function $ve(e){const[A,t]=AA.useState(null);return AA.useEffect(()=>{if(!e)return;const i=e.replace(/&cachebust_origin=$/,""),n=window.TSCIRCUIT_OBJ_LOADER_CACHE;let o=!1;async function s(){try{if(i.endsWith(".wrl"))return await Xve(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 R8t;if(c?.length){const l=c.join(`
5152
- `).replace(/d 0\./g,"d 1."),B=g.replace(/newmtl[\s\S]*?endmtl/g,"").replace(/^mtllib.*/gm,""),C=new m8t;C.setMaterialOptions({invertTrProperty:!0});const Q=C.parse(l.replace(/Kd\s+([\d.]+)\s+([\d.]+)\s+([\d.]+)/g,"Kd $2 $2 $2"),"embedded.mtl");return I.setMaterials(Q),I.parse(B)}return I.parse(g.replace(/^mtllib.*/gm,""))}catch(a){return a}}function r(){if(n.has(i)){const g=n.get(i);return g.result?Promise.resolve(g.result.clone()):g.promise.then(c=>c instanceof Error?c:c.clone())}const a=s().then(g=>(g instanceof Error||n.set(i,{...n.get(i),result:g}),g));return n.set(i,{promise:a,result:null}),a}return r().then(a=>{o||t(a)}).catch(a=>{console.error(a)}),()=>{o=!0}},[e]),A}function AFe({url:e,position:A,rotation:t,modelOffset:i=[0,0,0],modelRotation:n=[0,0,0],sourceCoordinateTransform:o,modelSize:s,modelFitMode:r="contain_within_bounds",onHover:a,onUnhover:g,isHovered:c,scale:I,isTranslucent:l=!1}){const B=$ve(e),C=AA.useMemo(()=>B&&!(B instanceof Error)?(B.traverse(h=>{if(h instanceof ro&&h.material){const E=u=>{u.transparent=l,u.opacity=l?.5:1,u.depthWrite=!l,u.needsUpdate=!0};Array.isArray(h.material)?h.material.forEach(E):E(h.material),h.renderOrder=l?2:1}}),B):new ro(new nw(.5,.5,.5),new K0({transparent:!0,color:"red",opacity:.25})),[B,l]),{boardTransformGroup:Q}=xuA({model:C,position:Array.isArray(A)?A:A?[A.x,A.y,A.z]:void 0,rotation:Array.isArray(t)?t:t?[t.x,t.y,t.z]:void 0,modelOffset:i,modelRotation:n,sourceCoordinateTransform:o,modelSize:s,modelFitMode:r,scale:I});if(B instanceof Error)throw B;return Z.jsx(i9,{isHovered:c,onHover:a,onUnhover:g,object:Q})}var SuA,tFe="https://cdn.jsdelivr.net/npm/occt-import-js@0.0.23/dist";function eFe(e){if(typeof e=="function")return e;if(e&&typeof e=="object"&&"default"in e&&typeof e.default=="function")return e.default;throw new Error("Unable to resolve occt-import-js factory export")}async function iFe(){if(!SuA){const e=await import("https://cdn.jsdelivr.net/npm/occt-import-js@0.0.23/+esm");SuA=eFe(e)({locateFile:t=>`${tFe}/${t}`})}return SuA}function nFe(e){const A=new Jh;for(const t of e){const i=t.attributes.position?.array??[],n=t.index?.array??[];if(!i.length||!n.length)continue;const o=new kg;o.setAttribute("position",new As(i,3));const s=t.attributes.normal?.array??[];s.length?o.setAttribute("normal",new As(s,3)):o.computeVertexNormals(),o.setIndex(n);const r=new K0({color:t.color?new An(t.color[0],t.color[1],t.color[2]):new An(.82,.82,.82)}),a=new ro(o,r);a.name=t.name,A.add(a)}return A}async function oFe(e){const A=await fetch(e);if(!A.ok)throw new Error(`Failed to fetch STEP file: ${A.statusText}`);const t=await A.arrayBuffer(),n=(await iFe()).ReadStepFile(new Uint8Array(t),null);if(!n.success||!n.meshes.length)throw new Error("occt-import-js failed to convert STEP file");const o=nFe(n.meshes),s=new mtA;return await new Promise((a,g)=>{s.parse(o,c=>{c instanceof ArrayBuffer?a(c):g(new Error("GLTFExporter did not return binary output"))},c=>{g(c)},{binary:!0})})}var Zet="step-glb-cache:";function sFe(e){const A=new Uint8Array(e),t=32768;let i="";for(let n=0;n<A.length;n+=t){const o=A.subarray(n,n+t);i+=String.fromCharCode(...o)}return btoa(i)}function rFe(e){const A=atob(e),t=new Uint8Array(A.length);for(let i=0;i<A.length;i+=1)t[i]=A.charCodeAt(i);return t.buffer}function aFe(e){try{const A=localStorage.getItem(`${Zet}${e}`);return A?rFe(A):null}catch(A){return console.warn("Failed to read STEP GLB cache",A),null}}function Vet(e,A){try{const t=sFe(A);localStorage.setItem(`${Zet}${e}`,t)}catch(t){console.warn("Failed to write STEP GLB cache",t)}}function gFe(){const e=globalThis;return e.stepUrlToGltfModelConversions||(e.stepUrlToGltfModelConversions={inProgress:new Map,completed:new Map}),e.stepUrlToGltfModelConversions}var cFe=({stepUrl:e,position:A,rotation:t,modelOffset:i,modelRotation:n,sourceCoordinateTransform:o,modelSize:s,modelFitMode:r,scale:a,onHover:g,onUnhover:c,isHovered:I,isTranslucent:l})=>{const[B,C]=AA.useState(null);return AA.useEffect(()=>{let Q=!0,h=null,E=!0;const u=gFe(),d=aFe(e);if(d){const w={arrayBuffer:d,blobUrl:URL.createObjectURL(new Blob([d],{type:"model/gltf-binary"}))};return u.completed.set(e,w),h=w.blobUrl,E=!1,C(w.blobUrl),()=>{Q=!1,h&&E&&URL.revokeObjectURL(h)}}const f=u.completed.get(e);if(f)return h=f.blobUrl,E=!1,C(f.blobUrl),Vet(e,f.arrayBuffer),()=>{Q=!1,h&&E&&URL.revokeObjectURL(h)};let m=u.inProgress.get(e);return m||(m=oFe(e).then(w=>{const D={arrayBuffer:w,blobUrl:URL.createObjectURL(new Blob([w],{type:"model/gltf-binary"}))};return u.completed.set(e,D),u.inProgress.delete(e),D}).catch(w=>{throw u.inProgress.delete(e),w}),u.inProgress.set(e,m)),m.then(w=>{Q&&(h=w.blobUrl,E=!1,C(w.blobUrl),Vet(e,w.arrayBuffer))}).catch(w=>{console.error("Failed to convert STEP file to GLB",w),Q&&C(null)}),()=>{Q=!1,h&&E&&URL.revokeObjectURL(h)}},[e]),B?Z.jsx(Wet,{gltfUrl:B,position:A,rotation:t,modelOffset:i,modelRotation:n,sourceCoordinateTransform:o,modelSize:s,modelFitMode:r,scale:a,onHover:g,onUnhover:c,isHovered:I,isTranslucent:l}):null};function yO(e,A){let{x:t,y:i,z:n}=e;if(A.axisMapping){const o={x:t,y:i,z:n};A.axisMapping.x&&(t=buA(o,A.axisMapping.x)),A.axisMapping.y&&(i=buA(o,A.axisMapping.y)),A.axisMapping.z&&(n=buA(o,A.axisMapping.z))}if(t*=A.flipX??1,i*=A.flipY??1,n*=A.flipZ??1,A.rotation){if(A.rotation.x){const o=A.rotation.x*Math.PI/180,s=Math.cos(o),r=Math.sin(o),a=i*s-n*r,g=i*r+n*s;i=a,n=g}if(A.rotation.y){const o=A.rotation.y*Math.PI/180,s=Math.cos(o),r=Math.sin(o),a=t*s+n*r,g=-t*r+n*s;t=a,n=g}if(A.rotation.z){const o=A.rotation.z*Math.PI/180,s=Math.cos(o),r=Math.sin(o),a=t*s-i*r,g=t*r+i*s;t=a,i=g}}return{x:t,y:i,z:n}}function buA(e,A){switch(A){case"x":return e.x;case"y":return e.y;case"z":return e.z;case"-x":return-e.x;case"-y":return-e.y;case"-z":return-e.z;default:return 0}}var _uA={STEP_INVERTED:{axisMapping:{x:"-x",y:"z",z:"-y"}},Z_UP_TO_Y_UP_USB_FIX:{axisMapping:{x:"x",y:"-z",z:"y"},flipZ:-1},FOOTPRINTER_MODEL_TRANSFORM:{axisMapping:{x:"x",y:"-z",z:"y"},flipX:-1,rotation:{x:180,y:180}}};function IFe(e,A){if(A.coordinateTransform)return A.coordinateTransform;if(!A.usingGlbCoordinates){if(A.hasFootprinterModel)return _uA.FOOTPRINTER_MODEL_TRANSFORM;if(!A.usingObjFormat)return A.usingStepFormat?_uA.STEP_INVERTED:_uA.Z_UP_TO_Y_UP_USB_FIX}}function n9(e,A){return IFe(e,{usingGlbCoordinates:A==="gltf"||A==="glb"||A==="jscad",usingObjFormat:A==="obj"||A==="wrl",usingStepFormat:A==="step",hasFootprinterModel:A==="footprinter"})}function mO(e){if(!e)return;const A=yO({x:1,y:0,z:0},e),t=yO({x:0,y:1,z:0},e),i=yO({x:0,y:0,z:1},e);return new $o().makeBasis(new Mt(A.x,A.y,A.z),new Mt(t.x,t.y,t.z),new Mt(i.x,i.y,i.z))}function ab(e){return e*Math.PI/180}function lFe(e){if(e==="z+")return[0,0,0];switch(e){case"x+":return[0,ab(-90),0];case"x-":return[0,ab(90),0];case"y+":return[ab(90),0,0];case"y-":return[ab(-90),0,0];case"z-":return[ab(180),0,0];default:return[0,0,0]}}function BFe(e,A,t){if(!e.position)return;let i=e.position.z;return A==="bottom"&&e.position.z>=0&&(i=-(e.position.z+t)),[e.position.x,e.position.y,i]}function CFe(e,A){return e.rotation?[ab(e.rotation.x),ab(e.rotation.y),ab(e.rotation.z)]:A==="bottom"?[Math.PI,0,0]:[0,0,0]}function QFe(e,A){const t=new Mt(e.x,e.y,e.z),i=new ju(A[0],A[1],A[2],"XYZ");return t.applyEuler(i),[t.x,t.y,t.z]}function hFe(e,A,t){if(!e.model_origin_position)return[0,0,0];const i=A?yO(e.model_origin_position,A):e.model_origin_position;return QFe(i,t)}function EFe(e,A){const t=BFe(e,A.layer,A.pcbThickness),i=CFe(e,A.layer),n=n9(e,A.modelType),o=lFe(e.model_board_normal_direction??"z+"),s=hFe(e,n,o);return{position:t,rotation:i,modelPosition:[-s[0],-s[1],-s[2]],modelRotation:o,scale:e.model_unit_to_mm_scale_factor??void 0,fitMode:e.model_object_fit??"contain_within_bounds",size:e.size?[e.size.x,e.size.y,e.size.z]:void 0}}var uFe=e=>e.model_glb_url||e.model_gltf_url?e.model_glb_url?"glb":"gltf":e.model_step_url?"step":e.model_obj_url||e.model_wrl_url||e.model_stl_url?e.model_wrl_url?"wrl":e.model_stl_url?"stl":"obj":e.model_jscad?"jscad":e.footprinter_string?"footprinter":"unknown",dFe=e=>e==="step"?"glb":e,pFe=(e,A)=>{if(e)return A?A(e):e},fFe=(...e)=>e,kuA=class extends Qn.Component{constructor(e){super(e),this.state={hasError:!1,error:null}}static getDerivedStateFromError(e){return{hasError:!0,error:e}}render(){return this.state.hasError&&this.state.error?this.props.fallback({error:this.state.error}):this.props.children}},yFe=({error:e,onError:A})=>(AA.useEffect(()=>{A(e)},[e,A]),null),jet=({cad_component:e,circuitJson:A,resolveStaticAsset:t})=>{const i=ztt(A),[n,o]=AA.useState(!1),{visibility:s}=W4(),[r,a]=AA.useState(null),g=AA.useCallback(O=>{O?.mousePosition?(o(!0),a(O.mousePosition)):(o(!1),a(null))},[]),c=AA.useCallback(()=>{o(!1),a(null)},[]),I=AA.useMemo(()=>yn(A).source_component.getUsing({source_component_id:e.source_component_id})?.name,[A,e.source_component_id]),l=AA.useMemo(()=>A.filter(W=>W.type==="pcb_plated_hole"&&W.pcb_component_id===e.pcb_component_id).length>0,[A,e.pcb_component_id]),B=AA.useCallback(O=>pFe(O,t),[t]),C=B(e.model_wrl_url??e.model_stl_url??e.model_obj_url),Q=B(e.model_glb_url??e.model_gltf_url),h=B(e.model_step_url),[E,u]=AA.useState(0),[d,f]=AA.useState(null);AA.useEffect(()=>{u(0),f(null)},[e.cad_component_id,C,Q,h]);const w=A.find(O=>O.type==="pcb_component"&&O.source_component_id===e.source_component_id)?.layer??"top",D=uFe(e),x=dFe(D),_=e.model_glb_url?"glb":"gltf",b=e.model_wrl_url?"wrl":e.model_stl_url?"stl":"obj",R=AA.useMemo(()=>EFe(e,{layer:w,pcbThickness:i,modelType:x}),[e,w,i,x]),F=fFe(...R.rotation),H=R.position,Y=AA.useMemo(()=>{const O=[];return Q&&O.push(Z.jsx(Wet,{gltfUrl:Q,position:H,rotation:F,modelOffset:R.modelPosition,modelRotation:R.modelRotation,sourceCoordinateTransform:mO(n9(e,_)),scale:R.scale,modelSize:R.size,modelFitMode:R.fitMode,onHover:g,onUnhover:c,isHovered:n,isTranslucent:e.show_as_translucent_model},`${e.cad_component_id}-gltf-${Q}`)),h&&!e.model_jscad&&!e.footprinter_string&&O.push(Z.jsx(cFe,{stepUrl:h,position:H,rotation:F,modelOffset:R.modelPosition,modelRotation:R.modelRotation,sourceCoordinateTransform:mO(n9(e,x)),scale:R.scale,modelSize:R.size,modelFitMode:R.fitMode,onHover:g,onUnhover:c,isHovered:n,isTranslucent:e.show_as_translucent_model},`${e.cad_component_id}-step-${h}`)),C&&O.push(Z.jsx(AFe,{url:C,position:H,rotation:F,modelOffset:R.modelPosition,modelRotation:R.modelRotation,sourceCoordinateTransform:mO(n9(e,b)),scale:R.scale,modelSize:R.size,modelFitMode:R.fitMode,onHover:g,onUnhover:c,isHovered:n,isTranslucent:e.show_as_translucent_model},`${e.cad_component_id}-mixed-${C}`)),O},[H,e.cad_component_id,e.footprinter_string,e.model_jscad,e.show_as_translucent_model,Q,_,g,c,n,b,R.modelPosition,R.modelRotation,R.scale,R.fitMode,R.size,x,F,h,C]);let J=null;if(Y.length>0){if(E>=Y.length){if(d)throw d;return null}J=Z.jsx(kuA,{fallback:({error:O})=>Z.jsx(yFe,{error:O,onError:W=>{f(W),u(z=>Math.max(z,E+1))}}),children:Y[E]},`${e.cad_component_id}-fallback-${E}`)}else e.model_jscad?J=Z.jsx(jve,{jscadPlan:e.model_jscad,positionOffset:H,rotationOffset:F,modelOffset:R.modelPosition,modelRotation:R.modelRotation,sourceCoordinateTransform:mO(n9(e,"jscad")),scale:R.scale,modelSize:R.size,modelFitMode:R.fitMode,onHover:g,onUnhover:c,isHovered:n,isTranslucent:e.show_as_translucent_model},e.cad_component_id):e.footprinter_string&&(J=Z.jsx(Tve,{positionOffset:H,rotationOffset:F,footprint:e.footprinter_string,scale:R.scale,onHover:g,onUnhover:c,isHovered:n,isTranslucent:e.show_as_translucent_model}));if(e.show_as_translucent_model){if(!s.translucentModels)return null}else if(l&&!s.throughHoleModels||!l&&!s.smtModels)return null;return Z.jsxs(Z.Fragment,{children:[J,n&&r?Z.jsx($tt,{position:r,style:{fontFamily:"sans-serif",transform:"translate3d(1rem, 1rem, 0)",backgroundColor:"white",padding:"5px",borderRadius:"3px",pointerEvents:"none",userSelect:"none",WebkitUserSelect:"none",MozUserSelect:"none",msUserSelect:"none"},children:I??"<unknown>"}):null]})},zet={version:"0.0.544"};function mFe(e){e.querySelectorAll("canvas").forEach(A=>A.remove())}var wFe=e=>{e.outputColorSpace=jm,e.toneMapping=x4A,e.toneMappingExposure=1},Xet="cadViewerCameraStateSession",$et=(e,A)=>{try{const t={position:e.position.toArray(),quaternion:e.quaternion.toArray(),up:e.up.toArray(),fov:e.fov??50,target:A.target.toArray()};sessionStorage.setItem(Xet,JSON.stringify(t))}catch(t){console.warn("Failed to save camera:",t)}},vuA=(e,A)=>{try{const t=sessionStorage.getItem(Xet);if(!t)return!1;const i=JSON.parse(t);if(e.position.fromArray(i.position),e.quaternion.fromArray(i.quaternion),e.up.fromArray(i.up),"fov"in e){const n=e;n.fov=i.fov,n.updateProjectionMatrix?.()}return A.target.fromArray(i.target),A.update(),e.updateMatrixWorld(),!0}catch(t){return console.warn("Failed to restore camera:",t),!1}},Ait=AA.createContext(void 0),DFe=({children:e,defaultTarget:A,initialCameraPosition:t})=>{const i=AA.useRef(null),n=AA.useRef(null),[o,s]=AA.useState(null),[r,a]=AA.useState("perspective"),[g,c]=AA.useState(t??null),[I,l]=AA.useState(new ju(0,0,0)),B=AA.useMemo(()=>{const[E,u,d]=t??[5,-5,5],f=Math.hypot(E-A.x,u-A.y,d-A.z);return f>0?f:5},[t,A]),C=AA.useCallback(E=>{const u=[A.x,A.y,A.z],d=n.current,f=i.current;let m=B;switch(d&&f&&(m=d.position.distanceTo(f.target)),E){case"Top Center Angled":{const w=m/Math.sqrt(2);return{position:[A.x,A.y-w,A.z+w],target:u,up:[0,0,1]}}case"Top Down":return{position:[A.x,A.y,A.z+m],target:u,up:[0,0,1]};case"Top Left Corner":return{position:[A.x-m*.6,A.y-m*.6,A.z+m*.6],target:u,up:[0,0,1]};case"Top Right Corner":return{position:[A.x+m*.6,A.y-m*.6,A.z+m*.6],target:u,up:[0,0,1]};case"Left Sideview":return{position:[A.x-m,A.y,A.z],target:u,up:[0,0,1]};case"Right Sideview":return{position:[A.x+m,A.y,A.z],target:u,up:[0,0,1]};case"Front":return{position:[A.x,A.y-m,A.z],target:u,up:[0,0,1]};default:return null}},[B,A,n,i]),Q=AA.useCallback(E=>{i.current=E},[]),h=AA.useMemo(()=>({controlsRef:i,mainCameraRef:n,defaultTarget:A,baseDistance:B,controller:o,setController:s,getPresetConfig:C,handleControlsChange:Q,cameraType:r,setCameraType:a,cameraPosition:g,setCameraPosition:c,cameraRotation:I,setCameraRotation:l,saveCameraToSession:$et,loadCameraFromSession:vuA}),[A,B,o,C,Q,r,g,I]);return Z.jsx(Ait.Provider,{value:h,children:e})},gb=()=>{const e=AA.useContext(Ait);if(!e)throw new Error("useCameraController must be used within a CameraControllerProvider");return e},xFe=AA.forwardRef(({children:e,scene:A,camera:t,style:i,onCreated:n},o)=>{const{cameraType:s}=gb(),r=AA.useRef(null),[a,g]=AA.useState(null),c=AA.useRef([]),I=AA.useRef(void 0);I.current=n;const l=AA.useRef(null),B=AA.useCallback(E=>{c.current.push(E)},[]),C=AA.useCallback(E=>{c.current=c.current.filter(u=>u!==E)},[]),Q=AA.useMemo(()=>new K_,[]);A?.up&&Q.up.set(A.up.x,A.up.y,A.up.z);const h=AA.useRef(new _g);return AA.useImperativeHandle(o,()=>h.current),AA.useEffect(()=>{if(!r.current)return;mFe(r.current);const E=new $H({antialias:!0,alpha:!0});wFe(E),E.setSize(r.current.clientWidth,r.current.clientHeight),E.setPixelRatio(window.devicePixelRatio),r.current.appendChild(E.domElement);const u=r.current.clientWidth/r.current.clientHeight,d=s==="perspective"?new Yh(75,u,.1,1e3):new IR(-10*u,10*u,10,-10,-1e3,1e3);l.current?(d.position.copy(l.current.position),d.quaternion.copy(l.current.quaternion),d.up.copy(l.current.up)):(t?.up&&d.up.set(t.up[0],t.up[1],t.up[2]),t?.position&&d.position.set(t.position[0],t.position[1],t.position[2]),d.lookAt(0,0,0)),Q.add(h.current),window.__TSCIRCUIT_THREE_OBJECT=h.current,g({scene:Q,camera:d,renderer:E,rootObject:h.current,addFrameListener:B,removeFrameListener:C}),I.current?.({camera:d,renderer:E});let f;const m=new DGt,w=()=>{const x=m.getElapsedTime(),_=m.getDelta();c.current.forEach(b=>b(x,_)),E.render(Q,d),f=requestAnimationFrame(w)};w();const D=()=>{if(r.current){const x=r.current.clientWidth/r.current.clientHeight;d instanceof Yh?d.aspect=x:d instanceof IR&&(d.left=-10*x,d.right=10*x,d.top=10,d.bottom=-10),d.updateProjectionMatrix(),E.setSize(r.current.clientWidth,r.current.clientHeight)}};return window.addEventListener("resize",D),()=>{l.current={position:d.position.clone(),quaternion:d.quaternion.clone(),up:d.up.clone()},window.removeEventListener("resize",D),cancelAnimationFrame(f),r.current&&E.domElement&&r.current.removeChild(E.domElement),E.dispose(),Q.remove(h.current),window.__TSCIRCUIT_THREE_OBJECT===h.current&&(window.__TSCIRCUIT_THREE_OBJECT=void 0)}},[Q,B,C,s]),Z.jsx("div",{ref:r,style:{width:"100%",height:"100%",...i},children:a&&Z.jsx(Xtt.Provider,{value:a,children:Z.jsx(Yve,{children:e})})})}),SFe=({autoRotate:e,autoRotateSpeed:A,onStart:t,panSpeed:i,rotateSpeed:n,zoomSpeed:o,enableDamping:s,dampingFactor:r,target:a,onControlsChange:g})=>{const{camera:c,renderer:I}=od(),l=AA.useMemo(()=>!c||!I?null:new L8t(c,I.domElement),[c,I]);return AA.useEffect(()=>(g?.(l??null),()=>g?.(null)),[l,g]),AA.useEffect(()=>{if(!l)return;const B=()=>{g?.(l)};return l.addEventListener("change",B),()=>{l.removeEventListener("change",B)}},[l,g]),AA.useEffect(()=>{l&&(l.autoRotate=e||!1,l.autoRotateSpeed=A||1,i!==void 0&&(l.panSpeed=i),n!==void 0&&(l.rotateSpeed=n),o!==void 0&&(l.zoomSpeed=o),s!==void 0&&(l.enableDamping=s),r!==void 0&&(l.dampingFactor=r),l.zoomToCursor=!0,l.mouseButtons={LEFT:Kx.ROTATE,MIDDLE:Kx.PAN,RIGHT:null},a&&(l.target.set(a[0],a[1],a[2]),l.update()))},[l,e,A,i,n,o,s,r,a]),AA.useEffect(()=>{if(!(!l||!t))return l.addEventListener("start",t),()=>{l.removeEventListener("start",t)}},[l,t]),AA.useEffect(()=>{if(l)return()=>{l.dispose()}},[l]),P8(()=>{l?.update()},[l]),null},bFe=`
5152
+ `).replace(/d 0\./g,"d 1."),B=g.replace(/newmtl[\s\S]*?endmtl/g,"").replace(/^mtllib.*/gm,""),C=new m8t;C.setMaterialOptions({invertTrProperty:!0});const Q=C.parse(l.replace(/Kd\s+([\d.]+)\s+([\d.]+)\s+([\d.]+)/g,"Kd $2 $2 $2"),"embedded.mtl");return I.setMaterials(Q),I.parse(B)}return I.parse(g.replace(/^mtllib.*/gm,""))}catch(a){return a}}function r(){if(n.has(i)){const g=n.get(i);return g.result?Promise.resolve(g.result.clone()):g.promise.then(c=>c instanceof Error?c:c.clone())}const a=s().then(g=>(g instanceof Error||n.set(i,{...n.get(i),result:g}),g));return n.set(i,{promise:a,result:null}),a}return r().then(a=>{o||t(a)}).catch(a=>{console.error(a)}),()=>{o=!0}},[e]),A}function AFe({url:e,position:A,rotation:t,modelOffset:i=[0,0,0],modelRotation:n=[0,0,0],sourceCoordinateTransform:o,modelSize:s,modelFitMode:r="contain_within_bounds",onHover:a,onUnhover:g,isHovered:c,scale:I,isTranslucent:l=!1}){const B=$ve(e),C=AA.useMemo(()=>B&&!(B instanceof Error)?(B.traverse(h=>{if(h instanceof ro&&h.material){const E=u=>{u.transparent=l,u.opacity=l?.5:1,u.depthWrite=!l,u.needsUpdate=!0};Array.isArray(h.material)?h.material.forEach(E):E(h.material),h.renderOrder=l?2:1}}),B):new ro(new nw(.5,.5,.5),new K0({transparent:!0,color:"red",opacity:.25})),[B,l]),{boardTransformGroup:Q}=xuA({model:C,position:Array.isArray(A)?A:A?[A.x,A.y,A.z]:void 0,rotation:Array.isArray(t)?t:t?[t.x,t.y,t.z]:void 0,modelOffset:i,modelRotation:n,sourceCoordinateTransform:o,modelSize:s,modelFitMode:r,scale:I});if(B instanceof Error)throw B;return Z.jsx(i9,{isHovered:c,onHover:a,onUnhover:g,object:Q})}var SuA,tFe="https://cdn.jsdelivr.net/npm/occt-import-js@0.0.23/dist";function eFe(e){if(typeof e=="function")return e;if(e&&typeof e=="object"&&"default"in e&&typeof e.default=="function")return e.default;throw new Error("Unable to resolve occt-import-js factory export")}async function iFe(){if(!SuA){const e=await import("https://cdn.jsdelivr.net/npm/occt-import-js@0.0.23/+esm");SuA=eFe(e)({locateFile:t=>`${tFe}/${t}`})}return SuA}function nFe(e){const A=new Jh;for(const t of e){const i=t.attributes.position?.array??[],n=t.index?.array??[];if(!i.length||!n.length)continue;const o=new kg;o.setAttribute("position",new As(i,3));const s=t.attributes.normal?.array??[];s.length?o.setAttribute("normal",new As(s,3)):o.computeVertexNormals(),o.setIndex(n);const r=new K0({color:t.color?new An(t.color[0],t.color[1],t.color[2]):new An(.82,.82,.82)}),a=new ro(o,r);a.name=t.name,A.add(a)}return A}async function oFe(e){const A=await fetch(e);if(!A.ok)throw new Error(`Failed to fetch STEP file: ${A.statusText}`);const t=await A.arrayBuffer(),n=(await iFe()).ReadStepFile(new Uint8Array(t),null);if(!n.success||!n.meshes.length)throw new Error("occt-import-js failed to convert STEP file");const o=nFe(n.meshes),s=new mtA;return await new Promise((a,g)=>{s.parse(o,c=>{c instanceof ArrayBuffer?a(c):g(new Error("GLTFExporter did not return binary output"))},c=>{g(c)},{binary:!0})})}var Zet="step-glb-cache:";function sFe(e){const A=new Uint8Array(e),t=32768;let i="";for(let n=0;n<A.length;n+=t){const o=A.subarray(n,n+t);i+=String.fromCharCode(...o)}return btoa(i)}function rFe(e){const A=atob(e),t=new Uint8Array(A.length);for(let i=0;i<A.length;i+=1)t[i]=A.charCodeAt(i);return t.buffer}function aFe(e){try{const A=localStorage.getItem(`${Zet}${e}`);return A?rFe(A):null}catch(A){return console.warn("Failed to read STEP GLB cache",A),null}}function Vet(e,A){try{const t=sFe(A);localStorage.setItem(`${Zet}${e}`,t)}catch(t){console.warn("Failed to write STEP GLB cache",t)}}function gFe(){const e=globalThis;return e.stepUrlToGltfModelConversions||(e.stepUrlToGltfModelConversions={inProgress:new Map,completed:new Map}),e.stepUrlToGltfModelConversions}var cFe=({stepUrl:e,position:A,rotation:t,modelOffset:i,modelRotation:n,sourceCoordinateTransform:o,modelSize:s,modelFitMode:r,scale:a,onHover:g,onUnhover:c,isHovered:I,isTranslucent:l})=>{const[B,C]=AA.useState(null);return AA.useEffect(()=>{let Q=!0,h=null,E=!0;const u=gFe(),d=aFe(e);if(d){const w={arrayBuffer:d,blobUrl:URL.createObjectURL(new Blob([d],{type:"model/gltf-binary"}))};return u.completed.set(e,w),h=w.blobUrl,E=!1,C(w.blobUrl),()=>{Q=!1,h&&E&&URL.revokeObjectURL(h)}}const f=u.completed.get(e);if(f)return h=f.blobUrl,E=!1,C(f.blobUrl),Vet(e,f.arrayBuffer),()=>{Q=!1,h&&E&&URL.revokeObjectURL(h)};let m=u.inProgress.get(e);return m||(m=oFe(e).then(w=>{const D={arrayBuffer:w,blobUrl:URL.createObjectURL(new Blob([w],{type:"model/gltf-binary"}))};return u.completed.set(e,D),u.inProgress.delete(e),D}).catch(w=>{throw u.inProgress.delete(e),w}),u.inProgress.set(e,m)),m.then(w=>{Q&&(h=w.blobUrl,E=!1,C(w.blobUrl),Vet(e,w.arrayBuffer))}).catch(w=>{console.error("Failed to convert STEP file to GLB",w),Q&&C(null)}),()=>{Q=!1,h&&E&&URL.revokeObjectURL(h)}},[e]),B?Z.jsx(Wet,{gltfUrl:B,position:A,rotation:t,modelOffset:i,modelRotation:n,sourceCoordinateTransform:o,modelSize:s,modelFitMode:r,scale:a,onHover:g,onUnhover:c,isHovered:I,isTranslucent:l}):null};function yO(e,A){let{x:t,y:i,z:n}=e;if(A.axisMapping){const o={x:t,y:i,z:n};A.axisMapping.x&&(t=buA(o,A.axisMapping.x)),A.axisMapping.y&&(i=buA(o,A.axisMapping.y)),A.axisMapping.z&&(n=buA(o,A.axisMapping.z))}if(t*=A.flipX??1,i*=A.flipY??1,n*=A.flipZ??1,A.rotation){if(A.rotation.x){const o=A.rotation.x*Math.PI/180,s=Math.cos(o),r=Math.sin(o),a=i*s-n*r,g=i*r+n*s;i=a,n=g}if(A.rotation.y){const o=A.rotation.y*Math.PI/180,s=Math.cos(o),r=Math.sin(o),a=t*s+n*r,g=-t*r+n*s;t=a,n=g}if(A.rotation.z){const o=A.rotation.z*Math.PI/180,s=Math.cos(o),r=Math.sin(o),a=t*s-i*r,g=t*r+i*s;t=a,i=g}}return{x:t,y:i,z:n}}function buA(e,A){switch(A){case"x":return e.x;case"y":return e.y;case"z":return e.z;case"-x":return-e.x;case"-y":return-e.y;case"-z":return-e.z;default:return 0}}var _uA={STEP_INVERTED:{axisMapping:{x:"-x",y:"z",z:"-y"}},Z_UP_TO_Y_UP_USB_FIX:{axisMapping:{x:"x",y:"-z",z:"y"},flipZ:-1},FOOTPRINTER_MODEL_TRANSFORM:{axisMapping:{x:"x",y:"-z",z:"y"},flipX:-1,rotation:{x:180,y:180}}};function IFe(e,A){if(A.coordinateTransform)return A.coordinateTransform;if(!A.usingGlbCoordinates){if(A.hasFootprinterModel)return _uA.FOOTPRINTER_MODEL_TRANSFORM;if(!A.usingObjFormat)return A.usingStepFormat?_uA.STEP_INVERTED:_uA.Z_UP_TO_Y_UP_USB_FIX}}function n9(e,A){return IFe(e,{usingGlbCoordinates:A==="gltf"||A==="glb"||A==="jscad",usingObjFormat:A==="obj"||A==="wrl",usingStepFormat:A==="step",hasFootprinterModel:A==="footprinter"})}function mO(e){if(!e)return;const A=yO({x:1,y:0,z:0},e),t=yO({x:0,y:1,z:0},e),i=yO({x:0,y:0,z:1},e);return new $o().makeBasis(new Mt(A.x,A.y,A.z),new Mt(t.x,t.y,t.z),new Mt(i.x,i.y,i.z))}function ab(e){return e*Math.PI/180}function lFe(e){if(e==="z+")return[0,0,0];switch(e){case"x+":return[0,ab(-90),0];case"x-":return[0,ab(90),0];case"y+":return[ab(90),0,0];case"y-":return[ab(-90),0,0];case"z-":return[ab(180),0,0];default:return[0,0,0]}}function BFe(e,A,t){if(!e.position)return;let i=e.position.z;return A==="bottom"&&e.position.z>=0&&(i=-(e.position.z+t)),[e.position.x,e.position.y,i]}function CFe(e,A){return e.rotation?[ab(e.rotation.x),ab(e.rotation.y),ab(e.rotation.z)]:A==="bottom"?[Math.PI,0,0]:[0,0,0]}function QFe(e,A){const t=new Mt(e.x,e.y,e.z),i=new ju(A[0],A[1],A[2],"XYZ");return t.applyEuler(i),[t.x,t.y,t.z]}function hFe(e,A,t){if(!e.model_origin_position)return[0,0,0];const i=A?yO(e.model_origin_position,A):e.model_origin_position;return QFe(i,t)}function EFe(e,A){const t=BFe(e,A.layer,A.pcbThickness),i=CFe(e,A.layer),n=n9(e,A.modelType),o=lFe(e.model_board_normal_direction??"z+"),s=hFe(e,n,o);return{position:t,rotation:i,modelPosition:[-s[0],-s[1],-s[2]],modelRotation:o,scale:e.model_unit_to_mm_scale_factor??void 0,fitMode:e.model_object_fit??"contain_within_bounds",size:e.size?[e.size.x,e.size.y,e.size.z]:void 0}}var uFe=e=>e.model_glb_url||e.model_gltf_url?e.model_glb_url?"glb":"gltf":e.model_obj_url||e.model_wrl_url||e.model_stl_url?e.model_wrl_url?"wrl":e.model_stl_url?"stl":"obj":e.model_jscad?"jscad":e.footprinter_string?"footprinter":e.model_step_url?"step":"unknown",dFe=e=>e==="step"?"glb":e,pFe=(e,A)=>{if(e)return A?A(e):e},fFe=(...e)=>e,kuA=class extends Qn.Component{constructor(e){super(e),this.state={hasError:!1,error:null}}static getDerivedStateFromError(e){return{hasError:!0,error:e}}render(){return this.state.hasError&&this.state.error?this.props.fallback({error:this.state.error}):this.props.children}},yFe=({error:e,onError:A})=>(AA.useEffect(()=>{A(e)},[e,A]),null),jet=({cad_component:e,circuitJson:A,resolveStaticAsset:t})=>{const i=ztt(A),[n,o]=AA.useState(!1),{visibility:s}=W4(),[r,a]=AA.useState(null),g=AA.useCallback(O=>{O?.mousePosition?(o(!0),a(O.mousePosition)):(o(!1),a(null))},[]),c=AA.useCallback(()=>{o(!1),a(null)},[]),I=AA.useMemo(()=>yn(A).source_component.getUsing({source_component_id:e.source_component_id})?.name,[A,e.source_component_id]),l=AA.useMemo(()=>A.filter(W=>W.type==="pcb_plated_hole"&&W.pcb_component_id===e.pcb_component_id).length>0,[A,e.pcb_component_id]),B=AA.useCallback(O=>pFe(O,t),[t]),C=B(e.model_wrl_url??e.model_stl_url??e.model_obj_url),Q=B(e.model_glb_url??e.model_gltf_url),h=B(e.model_step_url),[E,u]=AA.useState(0),[d,f]=AA.useState(null);AA.useEffect(()=>{u(0),f(null)},[e.cad_component_id,C,Q,h]);const w=A.find(O=>O.type==="pcb_component"&&O.source_component_id===e.source_component_id)?.layer??"top",D=uFe(e),x=dFe(D),_=e.model_glb_url?"glb":"gltf",b=e.model_wrl_url?"wrl":e.model_stl_url?"stl":"obj",R=AA.useMemo(()=>EFe(e,{layer:w,pcbThickness:i,modelType:x}),[e,w,i,x]),F=fFe(...R.rotation),H=R.position,Y=AA.useMemo(()=>{const O=[];return Q&&O.push(Z.jsx(Wet,{gltfUrl:Q,position:H,rotation:F,modelOffset:R.modelPosition,modelRotation:R.modelRotation,sourceCoordinateTransform:mO(n9(e,_)),scale:R.scale,modelSize:R.size,modelFitMode:R.fitMode,onHover:g,onUnhover:c,isHovered:n,isTranslucent:e.show_as_translucent_model},`${e.cad_component_id}-gltf-${Q}`)),C&&O.push(Z.jsx(AFe,{url:C,position:H,rotation:F,modelOffset:R.modelPosition,modelRotation:R.modelRotation,sourceCoordinateTransform:mO(n9(e,b)),scale:R.scale,modelSize:R.size,modelFitMode:R.fitMode,onHover:g,onUnhover:c,isHovered:n,isTranslucent:e.show_as_translucent_model},`${e.cad_component_id}-mixed-${C}`)),h&&!e.model_jscad&&!e.footprinter_string&&O.push(Z.jsx(cFe,{stepUrl:h,position:H,rotation:F,modelOffset:R.modelPosition,modelRotation:R.modelRotation,sourceCoordinateTransform:mO(n9(e,x)),scale:R.scale,modelSize:R.size,modelFitMode:R.fitMode,onHover:g,onUnhover:c,isHovered:n,isTranslucent:e.show_as_translucent_model},`${e.cad_component_id}-step-${h}`)),O},[H,e.cad_component_id,e.footprinter_string,e.model_jscad,e.show_as_translucent_model,Q,_,g,c,n,b,R.modelPosition,R.modelRotation,R.scale,R.fitMode,R.size,x,F,h,C]);let J=null;if(Y.length>0){if(E>=Y.length){if(d)throw d;return null}J=Z.jsx(kuA,{fallback:({error:O})=>Z.jsx(yFe,{error:O,onError:W=>{f(W),u(z=>Math.max(z,E+1))}}),children:Y[E]},`${e.cad_component_id}-fallback-${E}`)}else e.model_jscad?J=Z.jsx(jve,{jscadPlan:e.model_jscad,positionOffset:H,rotationOffset:F,modelOffset:R.modelPosition,modelRotation:R.modelRotation,sourceCoordinateTransform:mO(n9(e,"jscad")),scale:R.scale,modelSize:R.size,modelFitMode:R.fitMode,onHover:g,onUnhover:c,isHovered:n,isTranslucent:e.show_as_translucent_model},e.cad_component_id):e.footprinter_string&&(J=Z.jsx(Tve,{positionOffset:H,rotationOffset:F,footprint:e.footprinter_string,scale:R.scale,onHover:g,onUnhover:c,isHovered:n,isTranslucent:e.show_as_translucent_model}));if(e.show_as_translucent_model){if(!s.translucentModels)return null}else if(l&&!s.throughHoleModels||!l&&!s.smtModels)return null;return Z.jsxs(Z.Fragment,{children:[J,n&&r?Z.jsx($tt,{position:r,style:{fontFamily:"sans-serif",transform:"translate3d(1rem, 1rem, 0)",backgroundColor:"white",padding:"5px",borderRadius:"3px",pointerEvents:"none",userSelect:"none",WebkitUserSelect:"none",MozUserSelect:"none",msUserSelect:"none"},children:I??"<unknown>"}):null]})},zet={version:"0.0.545"};function mFe(e){e.querySelectorAll("canvas").forEach(A=>A.remove())}var wFe=e=>{e.outputColorSpace=jm,e.toneMapping=x4A,e.toneMappingExposure=1},Xet="cadViewerCameraStateSession",$et=(e,A)=>{try{const t={position:e.position.toArray(),quaternion:e.quaternion.toArray(),up:e.up.toArray(),fov:e.fov??50,target:A.target.toArray()};sessionStorage.setItem(Xet,JSON.stringify(t))}catch(t){console.warn("Failed to save camera:",t)}},vuA=(e,A)=>{try{const t=sessionStorage.getItem(Xet);if(!t)return!1;const i=JSON.parse(t);if(e.position.fromArray(i.position),e.quaternion.fromArray(i.quaternion),e.up.fromArray(i.up),"fov"in e){const n=e;n.fov=i.fov,n.updateProjectionMatrix?.()}return A.target.fromArray(i.target),A.update(),e.updateMatrixWorld(),!0}catch(t){return console.warn("Failed to restore camera:",t),!1}},Ait=AA.createContext(void 0),DFe=({children:e,defaultTarget:A,initialCameraPosition:t})=>{const i=AA.useRef(null),n=AA.useRef(null),[o,s]=AA.useState(null),[r,a]=AA.useState("perspective"),[g,c]=AA.useState(t??null),[I,l]=AA.useState(new ju(0,0,0)),B=AA.useMemo(()=>{const[E,u,d]=t??[5,-5,5],f=Math.hypot(E-A.x,u-A.y,d-A.z);return f>0?f:5},[t,A]),C=AA.useCallback(E=>{const u=[A.x,A.y,A.z],d=n.current,f=i.current;let m=B;switch(d&&f&&(m=d.position.distanceTo(f.target)),E){case"Top Center Angled":{const w=m/Math.sqrt(2);return{position:[A.x,A.y-w,A.z+w],target:u,up:[0,0,1]}}case"Top Down":return{position:[A.x,A.y,A.z+m],target:u,up:[0,0,1]};case"Top Left Corner":return{position:[A.x-m*.6,A.y-m*.6,A.z+m*.6],target:u,up:[0,0,1]};case"Top Right Corner":return{position:[A.x+m*.6,A.y-m*.6,A.z+m*.6],target:u,up:[0,0,1]};case"Left Sideview":return{position:[A.x-m,A.y,A.z],target:u,up:[0,0,1]};case"Right Sideview":return{position:[A.x+m,A.y,A.z],target:u,up:[0,0,1]};case"Front":return{position:[A.x,A.y-m,A.z],target:u,up:[0,0,1]};default:return null}},[B,A,n,i]),Q=AA.useCallback(E=>{i.current=E},[]),h=AA.useMemo(()=>({controlsRef:i,mainCameraRef:n,defaultTarget:A,baseDistance:B,controller:o,setController:s,getPresetConfig:C,handleControlsChange:Q,cameraType:r,setCameraType:a,cameraPosition:g,setCameraPosition:c,cameraRotation:I,setCameraRotation:l,saveCameraToSession:$et,loadCameraFromSession:vuA}),[A,B,o,C,Q,r,g,I]);return Z.jsx(Ait.Provider,{value:h,children:e})},gb=()=>{const e=AA.useContext(Ait);if(!e)throw new Error("useCameraController must be used within a CameraControllerProvider");return e},xFe=AA.forwardRef(({children:e,scene:A,camera:t,style:i,onCreated:n},o)=>{const{cameraType:s}=gb(),r=AA.useRef(null),[a,g]=AA.useState(null),c=AA.useRef([]),I=AA.useRef(void 0);I.current=n;const l=AA.useRef(null),B=AA.useCallback(E=>{c.current.push(E)},[]),C=AA.useCallback(E=>{c.current=c.current.filter(u=>u!==E)},[]),Q=AA.useMemo(()=>new K_,[]);A?.up&&Q.up.set(A.up.x,A.up.y,A.up.z);const h=AA.useRef(new _g);return AA.useImperativeHandle(o,()=>h.current),AA.useEffect(()=>{if(!r.current)return;mFe(r.current);const E=new $H({antialias:!0,alpha:!0});wFe(E),E.setSize(r.current.clientWidth,r.current.clientHeight),E.setPixelRatio(window.devicePixelRatio),r.current.appendChild(E.domElement);const u=r.current.clientWidth/r.current.clientHeight,d=s==="perspective"?new Yh(75,u,.1,1e3):new IR(-10*u,10*u,10,-10,-1e3,1e3);l.current?(d.position.copy(l.current.position),d.quaternion.copy(l.current.quaternion),d.up.copy(l.current.up)):(t?.up&&d.up.set(t.up[0],t.up[1],t.up[2]),t?.position&&d.position.set(t.position[0],t.position[1],t.position[2]),d.lookAt(0,0,0)),Q.add(h.current),window.__TSCIRCUIT_THREE_OBJECT=h.current,g({scene:Q,camera:d,renderer:E,rootObject:h.current,addFrameListener:B,removeFrameListener:C}),I.current?.({camera:d,renderer:E});let f;const m=new DGt,w=()=>{const x=m.getElapsedTime(),_=m.getDelta();c.current.forEach(b=>b(x,_)),E.render(Q,d),f=requestAnimationFrame(w)};w();const D=()=>{if(r.current){const x=r.current.clientWidth/r.current.clientHeight;d instanceof Yh?d.aspect=x:d instanceof IR&&(d.left=-10*x,d.right=10*x,d.top=10,d.bottom=-10),d.updateProjectionMatrix(),E.setSize(r.current.clientWidth,r.current.clientHeight)}};return window.addEventListener("resize",D),()=>{l.current={position:d.position.clone(),quaternion:d.quaternion.clone(),up:d.up.clone()},window.removeEventListener("resize",D),cancelAnimationFrame(f),r.current&&E.domElement&&r.current.removeChild(E.domElement),E.dispose(),Q.remove(h.current),window.__TSCIRCUIT_THREE_OBJECT===h.current&&(window.__TSCIRCUIT_THREE_OBJECT=void 0)}},[Q,B,C,s]),Z.jsx("div",{ref:r,style:{width:"100%",height:"100%",...i},children:a&&Z.jsx(Xtt.Provider,{value:a,children:Z.jsx(Yve,{children:e})})})}),SFe=({autoRotate:e,autoRotateSpeed:A,onStart:t,panSpeed:i,rotateSpeed:n,zoomSpeed:o,enableDamping:s,dampingFactor:r,target:a,onControlsChange:g})=>{const{camera:c,renderer:I}=od(),l=AA.useMemo(()=>!c||!I?null:new L8t(c,I.domElement),[c,I]);return AA.useEffect(()=>(g?.(l??null),()=>g?.(null)),[l,g]),AA.useEffect(()=>{if(!l)return;const B=()=>{g?.(l)};return l.addEventListener("change",B),()=>{l.removeEventListener("change",B)}},[l,g]),AA.useEffect(()=>{l&&(l.autoRotate=e||!1,l.autoRotateSpeed=A||1,i!==void 0&&(l.panSpeed=i),n!==void 0&&(l.rotateSpeed=n),o!==void 0&&(l.zoomSpeed=o),s!==void 0&&(l.enableDamping=s),r!==void 0&&(l.dampingFactor=r),l.zoomToCursor=!0,l.mouseButtons={LEFT:Kx.ROTATE,MIDDLE:Kx.PAN,RIGHT:null},a&&(l.target.set(a[0],a[1],a[2]),l.update()))},[l,e,A,i,n,o,s,r,a]),AA.useEffect(()=>{if(!(!l||!t))return l.addEventListener("start",t),()=>{l.removeEventListener("start",t)}},[l,t]),AA.useEffect(()=>{if(l)return()=>{l.dispose()}},[l]),P8(()=>{l?.update()},[l]),null},bFe=`
5153
5153
  varying vec3 worldPosition;
5154
5154
  void main() {
5155
5155
  worldPosition = (modelMatrix * vec4(position, 1.0)).xyz;
@@ -5685,7 +5685,7 @@ test("${g} should solve problem correctly", () => {
5685
5685
  // Add more specific assertions based on expected output
5686
5686
  // expect(solver.netLabelPlacementSolver!.netLabelPlacements).toMatchInlineSnapshot()
5687
5687
  })
5688
- `,I=new Blob([c],{type:"text/plain"}),l=URL.createObjectURL(I),B=document.createElement("a");B.href=l,B.download=`${g}.test.ts`,B.click(),URL.revokeObjectURL(l)}catch(a){alert(`Error generating test.ts for ${e.constructor.name}: ${a instanceof Error?a.message:String(a)}`)}i(!1)};return Z.jsxs("div",{className:`relative ${A}`,ref:n,children:[Z.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>i(!t),title:`Download options for ${e.constructor.name}`,children:e.constructor.name}),t&&Z.jsxs("div",{className:"absolute top-full left-0 mt-1 bg-white border border-gray-300 rounded shadow-lg z-10 min-w-[150px]",children:[Z.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:o,children:"Download JSON"}),Z.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),Z.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:r,children:"Download test.ts"})]})]})},lht=e=>e.activeSubSolver?[e,...lht(e.activeSubSolver)]:[e],Aei=({solver:e})=>{const A=lht(e);return Z.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:A.map((t,i)=>Z.jsxs("div",{className:"flex items-center",children:[i>0&&Z.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),Z.jsx($ti,{solver:t})]},t.constructor.name))})},tei=({solver:e,triggerRender:A,animationSpeed:t=25,onSolverStarted:i,onSolverCompleted:n})=>{const[o,s]=AA.useReducer(Q=>!Q,!1),r=AA.useRef(void 0),a=()=>{!e.solved&&!e.failed&&(e.step(),A())},g=()=>{!e.solved&&!e.failed&&(i&&i(e),e.solve(),A(),n&&n(e))},c=()=>{o?(r.current&&(clearInterval(r.current),r.current=void 0),s()):(s(),r.current=setInterval(()=>{if(e.solved||e.failed){r.current&&(clearInterval(r.current),r.current=void 0),s(),A(),n&&e.solved&&n(e);return}e.step(),A()},t))},I=()=>{const Q=e;if(Q.getCurrentPhase&&!e.solved&&!e.failed){const h=Q.getCurrentPhase();for(;Q.getCurrentPhase()===h&&!e.solved&&!e.failed;)e.step();A()}},l=()=>{if(e.solved||e.failed||o)return;const Q=window.prompt("Step until which iteration?",`${e.iterations}`);if(Q===null)return;const h=Number(Q);if(!Number.isFinite(h)){window.alert("Please enter a valid number for the iteration");return}for(;e.iterations<h&&!e.solved&&!e.failed;)e.step();A(),e.solved&&n&&n(e)};AA.useEffect(()=>()=>{r.current&&clearInterval(r.current)},[]),AA.useEffect(()=>{(e.solved||e.failed)&&o&&(r.current&&(clearInterval(r.current),r.current=void 0),s())},[e.solved,e.failed,o]);const B=e.getCurrentPhase!==void 0,C=B?e.getCurrentPhase():null;return Z.jsxs("div",{className:"space-y-2 p-2 border-b",children:[Z.jsx("div",{className:"flex items-center",children:Z.jsx(Aei,{solver:e})}),Z.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[Z.jsx("button",{onClick:a,disabled:e.solved||e.failed||o,className:"bg-blue-500 hover:bg-blue-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step"}),Z.jsx("button",{onClick:g,disabled:e.solved||e.failed||o,className:"bg-green-500 hover:bg-green-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Solve"}),Z.jsx("button",{onClick:c,disabled:e.solved||e.failed,className:`px-3 py-1 rounded text-white text-sm ${o?"bg-red-500 hover:bg-red-600":"bg-yellow-500 hover:bg-yellow-600"} disabled:bg-gray-300`,children:o?"Stop":"Animate"}),Z.jsx("button",{onClick:l,disabled:e.solved||e.failed||o,className:"bg-orange-500 hover:bg-orange-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step Until Iteration"}),B&&Z.jsx("button",{onClick:I,disabled:e.solved||e.failed||o,className:"bg-purple-500 hover:bg-purple-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Next Stage"}),Z.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",e.iterations]}),e.timeToSolve!==void 0&&Z.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(e.timeToSolve/1e3).toFixed(3),"s"]}),C&&Z.jsxs("div",{className:"text-sm text-gray-600",children:["Phase: ",Z.jsx("span",{className:"font-medium",children:C})]}),e.solved&&Z.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),e.failed&&Z.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),e.error&&Z.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",e.error]})]})},eei=(e,A,t)=>{const i=e.currentPipelineStepIndex;return A<i?"Completed":A===i&&e.activeSubSolver?e.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},iei=(e,A)=>{const i=e.pipelineDef[A].solverName,n=eei(e,A),o=e[i],s=e.firstIterationOfPhase?.[i]??null,r=e.iterations;let a=0;if(n==="Completed"){const l=e.pipelineDef[A+1],B=l?e.firstIterationOfPhase?.[l.solverName]:void 0;B!==void 0&&s!==null?a=B-s:s!==null&&(a=r-s)}else n==="In Progress"&&s!==null&&(a=r-s);const g=e.timeSpentOnPhase?.[i]??0;let c=0;n==="Completed"?c=1:n==="In Progress"&&o&&(c=o.progress??0);const I=o?.stats??null;return{index:A,name:i,status:n,firstIteration:s,iterations:a,progress:c,timeSpent:g,stats:I&&Object.keys(I).length>0?I:null,solverInstance:o??null}},nei=({status:e})=>{const A={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return Z.jsx("span",{className:`font-medium ${A[e]}`,children:e})},oei=({progress:e})=>{if(e===0)return null;const A=Math.round(e*100);return Z.jsxs("div",{className:"flex items-center gap-2",children:[Z.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:Z.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${A}%`}})}),Z.jsxs("span",{className:"text-xs text-gray-500",children:[A,"%"]})]})},sei=e=>Object.entries(e).map(([A,t])=>`${A}: ${t}`).join(", "),rei=({stats:e})=>{if(!e||Object.keys(e).length===0)return Z.jsx("span",{children:"-"});const A=Object.entries(e),t=sei(e);return Z.jsxs("details",{className:"cursor-pointer",children:[Z.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:t}),Z.jsx("div",{className:"mt-1 text-xs",children:A.map(([i,n])=>Z.jsxs("div",{children:[i,": ",String(n)]},i))})]})},RyA=e=>{if(e===null||typeof e!="object")return e;if(Array.isArray(e))return e.map(RyA);const A={};for(const[t,i]of Object.entries(e))t.startsWith("_")||(A[t]=RyA(i));return A},aei=(e,A)=>{try{if(typeof e.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${A}`);return}const t=RyA(e.getConstructorParams()),i=new Blob([JSON.stringify(t,null,2)],{type:"application/json"}),n=URL.createObjectURL(i),o=document.createElement("a");o.href=n,o.download=`${A}_input.json`,o.click(),URL.revokeObjectURL(n)}catch(t){alert(`Error downloading input for ${A}: ${t instanceof Error?t.message:String(t)}`)}},gei=({solver:e,onStepUntilPhase:A,onDownloadInput:t})=>{const i=e.pipelineDef.map((r,a)=>iei(e,a)),n=r=>{A?.(r)},o=r=>{r.solverInstance&&(t?t(r.solverInstance,r.name):aei(r.solverInstance,r.name))},s=r=>`${(r/1e3).toFixed(2)}s`;return Z.jsxs("div",{className:"border-t border-gray-200",children:[Z.jsx("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200",children:Z.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Steps"})}),Z.jsx("div",{className:"overflow-x-auto",children:Z.jsxs("table",{className:"w-full text-sm",children:[Z.jsx("thead",{children:Z.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Step"}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),Z.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",Z.jsx("sub",{children:"0"})]}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),Z.jsx("tbody",{children:i.map(r=>Z.jsxs("tr",{className:`border-b border-gray-100 ${r.status==="In Progress"?"bg-yellow-50":""}`,children:[Z.jsx("td",{className:"px-4 py-2",children:Z.jsxs("div",{className:"flex items-center gap-2",children:[Z.jsx("span",{className:"text-gray-400 w-6",children:String(r.index+1).padStart(2,"0")}),Z.jsx("button",{onClick:()=>n(r.name),disabled:r.status==="Completed"||e.solved||e.failed,className:"text-blue-500 hover:text-blue-700 disabled:text-gray-300 disabled:cursor-not-allowed",title:`Step until ${r.name} completes`,children:Z.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:Z.jsx("path",{fillRule:"evenodd",d:"M4.5 5.653c0-1.426 1.529-2.33 2.779-1.643l11.54 6.348c1.295.712 1.295 2.573 0 3.285L7.28 19.991c-1.25.687-2.779-.217-2.779-1.643V5.653z",clipRule:"evenodd"})})}),Z.jsx("span",{className:"font-medium text-gray-900",children:r.name})]})}),Z.jsx("td",{className:"px-4 py-2",children:Z.jsx(nei,{status:r.status})}),Z.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:r.firstIteration!==null?r.firstIteration:""}),Z.jsx("td",{className:"px-4 py-2 text-gray-600",children:r.iterations}),Z.jsx("td",{className:"px-4 py-2",children:Z.jsx(oei,{progress:r.progress})}),Z.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(r.timeSpent)}),Z.jsx("td",{className:"px-4 py-2 text-gray-500",children:Z.jsx(rei,{stats:r.stats})}),Z.jsx("td",{className:"px-4 py-2",children:r.solverInstance?Z.jsxs("button",{onClick:()=>o(r),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${r.name}`,children:[Z.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:Z.jsx("path",{fillRule:"evenodd",d:"M12 2.25a.75.75 0 01.75.75v11.69l3.22-3.22a.75.75 0 111.06 1.06l-4.5 4.5a.75.75 0 01-1.06 0l-4.5-4.5a.75.75 0 111.06-1.06l3.22 3.22V3a.75.75 0 01.75-.75zm-9 13.5a.75.75 0 01.75.75v2.25a1.5 1.5 0 001.5 1.5h13.5a1.5 1.5 0 001.5-1.5V16.5a.75.75 0 011.5 0v2.25a3 3 0 01-3 3H5.25a3 3 0 01-3-3V16.5a.75.75 0 01.75-.75z",clipRule:"evenodd"})}),Z.jsx("span",{children:"Input"})]}):null})]},r.name))})]})})]})},cei=class extends Qn.Component{constructor(e){super(e),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(e){console.error("InteractiveGraphics render error:",e)}render(){return this.state.hasError?this.props.fallback:this.props.children}};function Iei({graphics:e}){const A=e.points??[],t=e.lines??[],i=e.rects??[],n=e.circles??[],o=e.texts??[];let s=Number.POSITIVE_INFINITY,r=Number.POSITIVE_INFINITY,a=Number.NEGATIVE_INFINITY,g=Number.NEGATIVE_INFINITY;const c=(h,E)=>{typeof h=="number"&&(h<s&&(s=h),h>a&&(a=h)),typeof E=="number"&&(E<r&&(r=E),E>g&&(g=E))};for(const h of A)c(h.x,h.y);for(const h of t){const E=h.points??[];for(const u of E)c(u.x,u.y)}for(const h of i){const E=h.x??0,u=h.y??0,d=h.width??0,f=h.height??0;c(E,u),c(E+d,u+f)}for(const h of n){const E=h.x??0,u=h.y??0,d=h.radius??1;c(E-d,u-d),c(E+d,u+d)}for(const h of o)c(h.x,h.y);(!isFinite(s)||!isFinite(r)||!isFinite(a)||!isFinite(g))&&(s=-20,r=-20,a=20,g=20);const I=10,l=s-I,B=r-I,C=Math.max(1,a-s+2*I),Q=Math.max(1,g-r+2*I);return Z.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${l} ${B} ${C} ${Q}`,role:"img","aria-label":"Graphics fallback",children:[i.map((h,E)=>Z.jsx("rect",{x:h.x??0,y:h.y??0,width:h.width??0,height:h.height??0,fill:"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1},`rect-${E}`)),t.map((h,E)=>Z.jsx("polyline",{fill:"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1,points:(h.points??[]).map(u=>`${u.x??0},${u.y??0}`).join(" ")},`line-${E}`)),n.map((h,E)=>Z.jsx("circle",{cx:h.x??0,cy:h.y??0,r:h.radius??1.5,fill:h.fillColor??"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1},`circle-${E}`)),A.map((h,E)=>Z.jsx("circle",{cx:h.x??0,cy:h.y??0,r:h.radius??1.5,fill:h.color??"black"},`point-${E}`)),o.map((h,E)=>Z.jsx("text",{x:h.x??0,y:h.y??0,fontSize:h.fontSize??10,fill:h.color??"black",children:h.text??""},`text-${E}`))]})}var lei=({solver:e,animationSpeed:A=25,onSolverStarted:t,onSolverCompleted:i})=>{const[n,o]=AA.useReducer(c=>c+1,0),s=AA.useMemo(()=>{try{return e.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(c){return console.error("Visualization error:",c),{points:[],lines:[],rects:[],circles:[]}}},[e,n]),r=AA.useMemo(()=>(s.rects?.length||0)===0&&(s.lines?.length||0)===0&&(s.points?.length||0)===0&&(s.circles?.length||0)===0,[s]);AA.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const c=document.createElement("script");c.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(c)}},[]);const a=e.pipelineDef!==void 0,g=c=>{const I=e;if(!e.solved&&!e.failed){for(;!e.solved&&!e.failed&&I.currentPipelineStepIndex<=I.pipelineDef.findIndex(l=>l.solverName===c);)e.step();o()}};return Z.jsxs("div",{children:[Z.jsx(tei,{solver:e,triggerRender:o,animationSpeed:A,onSolverStarted:t,onSolverCompleted:i}),r?Z.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):Z.jsx(cei,{fallback:Z.jsx(Iei,{graphics:s}),children:Z.jsx(Xti,{graphics:s})}),a&&Z.jsx(gei,{solver:e,onStepUntilPhase:g})]})};const Bei=()=>{AA.useEffect(()=>{const e="tailwind-cdn-script";if(document.getElementById(e)||window.tailwind)return;const A=document.createElement("div");A.className="hidden",document.body.appendChild(A);const t=window.getComputedStyle(A).display==="none";if(document.body.removeChild(A),t)return;const i=document.createElement("script");i.id=e,i.src="https://cdn.tailwindcss.com",document.head.appendChild(i)},[])},Cei=e=>e.toLowerCase().includes("pack")?NLe:e.toLowerCase().includes("rout")?TLe:SLe,Qei=({solverEvents:e=[]})=>{const[A,t]=AA.useState(null);Bei();const i=AA.useMemo(()=>{const r=new Map;for(const a of e){const g=`${a.componentName}-${a.solverName}`;r.set(g,a)}return r},[e]),n=AA.useMemo(()=>Array.from(i.keys()),[i]),o=A?i.get(A):null,s=AA.useMemo(()=>{if(!o)return{instance:null,error:null,classFound:!1};const r=AcA[o.solverName];if(!r)return{instance:null,error:`Solver class "${o.solverName}" not found in SOLVERS registry. Available: ${Object.keys(AcA).join(", ")}`,classFound:!1};try{const a=o.solverParams,g=a?.input!==void 0?a.input:a;return{instance:new r(g),error:null,classFound:!0}}catch(a){const g=a instanceof Error?a.message:String(a);return console.error("Failed to reconstruct solver:",a),{instance:null,error:`Failed to instantiate solver: ${g}`,classFound:!0}}},[o]);return e.length===0?Z.jsx("div",{className:"rf-p-4",children:Z.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:Z.jsxs("div",{className:"rf-p-4",children:[Z.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),Z.jsx("p",{className:"rf-text-sm rf-text-gray-600",children:"Solvers will appear here when the circuit runs. Solvers are used for tasks like component packing and autorouting."})]})})}):Z.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[Z.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[Z.jsxs("div",{className:"rf-text-xs rf-font-semibold rf-text-gray-500 rf-px-3 rf-py-2 rf-bg-gray-50 rf-border-b rf-border-gray-200",children:[n.length," ",n.length===1?"Solver":"Solvers"]}),n.map(r=>{const a=i.get(r),g=A===r;return Z.jsx("div",{className:`rf-px-3 rf-py-2 rf-cursor-pointer rf-border-b rf-border-gray-100 ${g?"rf-bg-blue-50 rf-border-l-2 rf-border-l-blue-500":"hover:rf-bg-gray-50"}`,onClick:()=>t(r),children:(()=>{const c=Cei(a.solverName);return Z.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[Z.jsx(c,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),Z.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[Z.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:a.componentName}),Z.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:a.solverName})]})]})})()},r)})]}),Z.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:o?s.instance?Z.jsx(zD,{fallback:Z.jsx("div",{className:"rf-p-4",children:Z.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[Z.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),Z.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",o.solverName]})]})}),children:Z.jsx(lei,{solver:s.instance})}):Z.jsxs("div",{className:"rf-p-4",children:[Z.jsxs("div",{className:"rf-mb-4",children:[Z.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:o.solverName}),Z.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",o.componentName]})]}),s.error&&Z.jsx("div",{className:`rf-rounded-md rf-border rf-p-4 rf-mb-4 ${s.classFound?"rf-bg-red-50 rf-border-red-200":"rf-bg-yellow-50 rf-border-yellow-200"}`,children:Z.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),Z.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[Z.jsx("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50",children:Z.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"})}),Z.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:Z.jsx("pre",{className:"rf-text-xs rf-font-mono rf-text-gray-600 rf-whitespace-pre-wrap rf-overflow-x-auto",children:JSON.stringify(o.solverParams,null,2)})})]})]}):Z.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:Z.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},Bht=({errorMessage:e,errorStack:A,circuitJsonErrors:t})=>{AA.useEffect(()=>{if(e){const i=new Error(e);A&&(i.stack=A);try{hH.captureException(i)}catch{}}},[e,A]),AA.useEffect(()=>{if(t&&t.length>0)for(const i of t){const n=new Error(i.message||"Circuit JSON Error");i.stack&&(n.stack=i.stack);try{hH.captureException(n,{error_type:i.type})}catch{}}},[t])},Cht="0.0.1764",hei={version:Cht},NyA={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1},LyA=new Map,iV=e=>{const A=LyA.get(e);return A?Object.fromEntries(Object.entries(A.stores).map(([t,i])=>[t,i.getState()])):{}},Eei=(e,A,t)=>{if(e===void 0)return{type:"untracked",connection:A.connect(t)};const i=LyA.get(t.name);if(i)return{type:"tracked",store:e,...i};const n={connection:A.connect(t),stores:{}};return LyA.set(t.name,n),{type:"tracked",store:e,...n}},Qht=(e,A={})=>(t,i,n)=>{const{enabled:o,anonymousActionType:s,store:r,...a}=A;let g;try{g=(o??(NyA?"production":void 0)!=="production")&&window.__REDUX_DEVTOOLS_EXTENSION__}catch{}if(!g)return(NyA?"production":void 0)!=="production"&&o&&console.warn("[zustand devtools middleware] Please install/enable Redux devtools extension"),e(t,i,n);const{connection:c,...I}=Eei(r,g,a);let l=!0;n.setState=(Q,h,E)=>{const u=t(Q,h);if(!l)return u;const d=E===void 0?{type:s||"anonymous"}:typeof E=="string"?{type:E}:E;return r===void 0?(c?.send(d,i()),u):(c?.send({...d,type:`${r}/${d.type}`},{...iV(a.name),[r]:n.getState()}),u)};const B=(...Q)=>{const h=l;l=!1,t(...Q),l=h},C=e(n.setState,i,n);if(I.type==="untracked"?c?.init(C):(I.stores[I.store]=n,c?.init(Object.fromEntries(Object.entries(I.stores).map(([Q,h])=>[Q,Q===I.store?C:h.getState()])))),n.dispatchFromDevtools&&typeof n.dispatch=="function"){let Q=!1;const h=n.dispatch;n.dispatch=(...E)=>{(NyA?"production":void 0)!=="production"&&E[0].type==="__setState"&&!Q&&(console.warn('[zustand devtools middleware] "__setState" action type is reserved to set state from the devtools. Avoid using it.'),Q=!0),h(...E)}}return c.subscribe(Q=>{var h;switch(Q.type){case"ACTION":if(typeof Q.payload!="string"){console.error("[zustand devtools middleware] Unsupported action format");return}return UyA(Q.payload,E=>{if(E.type==="__setState"){if(r===void 0){B(E.state);return}Object.keys(E.state).length!==1&&console.error(`
5688
+ `,I=new Blob([c],{type:"text/plain"}),l=URL.createObjectURL(I),B=document.createElement("a");B.href=l,B.download=`${g}.test.ts`,B.click(),URL.revokeObjectURL(l)}catch(a){alert(`Error generating test.ts for ${e.constructor.name}: ${a instanceof Error?a.message:String(a)}`)}i(!1)};return Z.jsxs("div",{className:`relative ${A}`,ref:n,children:[Z.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>i(!t),title:`Download options for ${e.constructor.name}`,children:e.constructor.name}),t&&Z.jsxs("div",{className:"absolute top-full left-0 mt-1 bg-white border border-gray-300 rounded shadow-lg z-10 min-w-[150px]",children:[Z.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:o,children:"Download JSON"}),Z.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),Z.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:r,children:"Download test.ts"})]})]})},lht=e=>e.activeSubSolver?[e,...lht(e.activeSubSolver)]:[e],Aei=({solver:e})=>{const A=lht(e);return Z.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:A.map((t,i)=>Z.jsxs("div",{className:"flex items-center",children:[i>0&&Z.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),Z.jsx($ti,{solver:t})]},t.constructor.name))})},tei=({solver:e,triggerRender:A,animationSpeed:t=25,onSolverStarted:i,onSolverCompleted:n})=>{const[o,s]=AA.useReducer(Q=>!Q,!1),r=AA.useRef(void 0),a=()=>{!e.solved&&!e.failed&&(e.step(),A())},g=()=>{!e.solved&&!e.failed&&(i&&i(e),e.solve(),A(),n&&n(e))},c=()=>{o?(r.current&&(clearInterval(r.current),r.current=void 0),s()):(s(),r.current=setInterval(()=>{if(e.solved||e.failed){r.current&&(clearInterval(r.current),r.current=void 0),s(),A(),n&&e.solved&&n(e);return}e.step(),A()},t))},I=()=>{const Q=e;if(Q.getCurrentPhase&&!e.solved&&!e.failed){const h=Q.getCurrentPhase();for(;Q.getCurrentPhase()===h&&!e.solved&&!e.failed;)e.step();A()}},l=()=>{if(e.solved||e.failed||o)return;const Q=window.prompt("Step until which iteration?",`${e.iterations}`);if(Q===null)return;const h=Number(Q);if(!Number.isFinite(h)){window.alert("Please enter a valid number for the iteration");return}for(;e.iterations<h&&!e.solved&&!e.failed;)e.step();A(),e.solved&&n&&n(e)};AA.useEffect(()=>()=>{r.current&&clearInterval(r.current)},[]),AA.useEffect(()=>{(e.solved||e.failed)&&o&&(r.current&&(clearInterval(r.current),r.current=void 0),s())},[e.solved,e.failed,o]);const B=e.getCurrentPhase!==void 0,C=B?e.getCurrentPhase():null;return Z.jsxs("div",{className:"space-y-2 p-2 border-b",children:[Z.jsx("div",{className:"flex items-center",children:Z.jsx(Aei,{solver:e})}),Z.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[Z.jsx("button",{onClick:a,disabled:e.solved||e.failed||o,className:"bg-blue-500 hover:bg-blue-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step"}),Z.jsx("button",{onClick:g,disabled:e.solved||e.failed||o,className:"bg-green-500 hover:bg-green-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Solve"}),Z.jsx("button",{onClick:c,disabled:e.solved||e.failed,className:`px-3 py-1 rounded text-white text-sm ${o?"bg-red-500 hover:bg-red-600":"bg-yellow-500 hover:bg-yellow-600"} disabled:bg-gray-300`,children:o?"Stop":"Animate"}),Z.jsx("button",{onClick:l,disabled:e.solved||e.failed||o,className:"bg-orange-500 hover:bg-orange-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step Until Iteration"}),B&&Z.jsx("button",{onClick:I,disabled:e.solved||e.failed||o,className:"bg-purple-500 hover:bg-purple-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Next Stage"}),Z.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",e.iterations]}),e.timeToSolve!==void 0&&Z.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(e.timeToSolve/1e3).toFixed(3),"s"]}),C&&Z.jsxs("div",{className:"text-sm text-gray-600",children:["Phase: ",Z.jsx("span",{className:"font-medium",children:C})]}),e.solved&&Z.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),e.failed&&Z.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),e.error&&Z.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",e.error]})]})},eei=(e,A,t)=>{const i=e.currentPipelineStepIndex;return A<i?"Completed":A===i&&e.activeSubSolver?e.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},iei=(e,A)=>{const i=e.pipelineDef[A].solverName,n=eei(e,A),o=e[i],s=e.firstIterationOfPhase?.[i]??null,r=e.iterations;let a=0;if(n==="Completed"){const l=e.pipelineDef[A+1],B=l?e.firstIterationOfPhase?.[l.solverName]:void 0;B!==void 0&&s!==null?a=B-s:s!==null&&(a=r-s)}else n==="In Progress"&&s!==null&&(a=r-s);const g=e.timeSpentOnPhase?.[i]??0;let c=0;n==="Completed"?c=1:n==="In Progress"&&o&&(c=o.progress??0);const I=o?.stats??null;return{index:A,name:i,status:n,firstIteration:s,iterations:a,progress:c,timeSpent:g,stats:I&&Object.keys(I).length>0?I:null,solverInstance:o??null}},nei=({status:e})=>{const A={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return Z.jsx("span",{className:`font-medium ${A[e]}`,children:e})},oei=({progress:e})=>{if(e===0)return null;const A=Math.round(e*100);return Z.jsxs("div",{className:"flex items-center gap-2",children:[Z.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:Z.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${A}%`}})}),Z.jsxs("span",{className:"text-xs text-gray-500",children:[A,"%"]})]})},sei=e=>Object.entries(e).map(([A,t])=>`${A}: ${t}`).join(", "),rei=({stats:e})=>{if(!e||Object.keys(e).length===0)return Z.jsx("span",{children:"-"});const A=Object.entries(e),t=sei(e);return Z.jsxs("details",{className:"cursor-pointer",children:[Z.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:t}),Z.jsx("div",{className:"mt-1 text-xs",children:A.map(([i,n])=>Z.jsxs("div",{children:[i,": ",String(n)]},i))})]})},RyA=e=>{if(e===null||typeof e!="object")return e;if(Array.isArray(e))return e.map(RyA);const A={};for(const[t,i]of Object.entries(e))t.startsWith("_")||(A[t]=RyA(i));return A},aei=(e,A)=>{try{if(typeof e.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${A}`);return}const t=RyA(e.getConstructorParams()),i=new Blob([JSON.stringify(t,null,2)],{type:"application/json"}),n=URL.createObjectURL(i),o=document.createElement("a");o.href=n,o.download=`${A}_input.json`,o.click(),URL.revokeObjectURL(n)}catch(t){alert(`Error downloading input for ${A}: ${t instanceof Error?t.message:String(t)}`)}},gei=({solver:e,onStepUntilPhase:A,onDownloadInput:t})=>{const i=e.pipelineDef.map((r,a)=>iei(e,a)),n=r=>{A?.(r)},o=r=>{r.solverInstance&&(t?t(r.solverInstance,r.name):aei(r.solverInstance,r.name))},s=r=>`${(r/1e3).toFixed(2)}s`;return Z.jsxs("div",{className:"border-t border-gray-200",children:[Z.jsx("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200",children:Z.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Steps"})}),Z.jsx("div",{className:"overflow-x-auto",children:Z.jsxs("table",{className:"w-full text-sm",children:[Z.jsx("thead",{children:Z.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Step"}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),Z.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",Z.jsx("sub",{children:"0"})]}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),Z.jsx("tbody",{children:i.map(r=>Z.jsxs("tr",{className:`border-b border-gray-100 ${r.status==="In Progress"?"bg-yellow-50":""}`,children:[Z.jsx("td",{className:"px-4 py-2",children:Z.jsxs("div",{className:"flex items-center gap-2",children:[Z.jsx("span",{className:"text-gray-400 w-6",children:String(r.index+1).padStart(2,"0")}),Z.jsx("button",{onClick:()=>n(r.name),disabled:r.status==="Completed"||e.solved||e.failed,className:"text-blue-500 hover:text-blue-700 disabled:text-gray-300 disabled:cursor-not-allowed",title:`Step until ${r.name} completes`,children:Z.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:Z.jsx("path",{fillRule:"evenodd",d:"M4.5 5.653c0-1.426 1.529-2.33 2.779-1.643l11.54 6.348c1.295.712 1.295 2.573 0 3.285L7.28 19.991c-1.25.687-2.779-.217-2.779-1.643V5.653z",clipRule:"evenodd"})})}),Z.jsx("span",{className:"font-medium text-gray-900",children:r.name})]})}),Z.jsx("td",{className:"px-4 py-2",children:Z.jsx(nei,{status:r.status})}),Z.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:r.firstIteration!==null?r.firstIteration:""}),Z.jsx("td",{className:"px-4 py-2 text-gray-600",children:r.iterations}),Z.jsx("td",{className:"px-4 py-2",children:Z.jsx(oei,{progress:r.progress})}),Z.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(r.timeSpent)}),Z.jsx("td",{className:"px-4 py-2 text-gray-500",children:Z.jsx(rei,{stats:r.stats})}),Z.jsx("td",{className:"px-4 py-2",children:r.solverInstance?Z.jsxs("button",{onClick:()=>o(r),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${r.name}`,children:[Z.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:Z.jsx("path",{fillRule:"evenodd",d:"M12 2.25a.75.75 0 01.75.75v11.69l3.22-3.22a.75.75 0 111.06 1.06l-4.5 4.5a.75.75 0 01-1.06 0l-4.5-4.5a.75.75 0 111.06-1.06l3.22 3.22V3a.75.75 0 01.75-.75zm-9 13.5a.75.75 0 01.75.75v2.25a1.5 1.5 0 001.5 1.5h13.5a1.5 1.5 0 001.5-1.5V16.5a.75.75 0 011.5 0v2.25a3 3 0 01-3 3H5.25a3 3 0 01-3-3V16.5a.75.75 0 01.75-.75z",clipRule:"evenodd"})}),Z.jsx("span",{children:"Input"})]}):null})]},r.name))})]})})]})},cei=class extends Qn.Component{constructor(e){super(e),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(e){console.error("InteractiveGraphics render error:",e)}render(){return this.state.hasError?this.props.fallback:this.props.children}};function Iei({graphics:e}){const A=e.points??[],t=e.lines??[],i=e.rects??[],n=e.circles??[],o=e.texts??[];let s=Number.POSITIVE_INFINITY,r=Number.POSITIVE_INFINITY,a=Number.NEGATIVE_INFINITY,g=Number.NEGATIVE_INFINITY;const c=(h,E)=>{typeof h=="number"&&(h<s&&(s=h),h>a&&(a=h)),typeof E=="number"&&(E<r&&(r=E),E>g&&(g=E))};for(const h of A)c(h.x,h.y);for(const h of t){const E=h.points??[];for(const u of E)c(u.x,u.y)}for(const h of i){const E=h.x??0,u=h.y??0,d=h.width??0,f=h.height??0;c(E,u),c(E+d,u+f)}for(const h of n){const E=h.x??0,u=h.y??0,d=h.radius??1;c(E-d,u-d),c(E+d,u+d)}for(const h of o)c(h.x,h.y);(!isFinite(s)||!isFinite(r)||!isFinite(a)||!isFinite(g))&&(s=-20,r=-20,a=20,g=20);const I=10,l=s-I,B=r-I,C=Math.max(1,a-s+2*I),Q=Math.max(1,g-r+2*I);return Z.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${l} ${B} ${C} ${Q}`,role:"img","aria-label":"Graphics fallback",children:[i.map((h,E)=>Z.jsx("rect",{x:h.x??0,y:h.y??0,width:h.width??0,height:h.height??0,fill:"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1},`rect-${E}`)),t.map((h,E)=>Z.jsx("polyline",{fill:"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1,points:(h.points??[]).map(u=>`${u.x??0},${u.y??0}`).join(" ")},`line-${E}`)),n.map((h,E)=>Z.jsx("circle",{cx:h.x??0,cy:h.y??0,r:h.radius??1.5,fill:h.fillColor??"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1},`circle-${E}`)),A.map((h,E)=>Z.jsx("circle",{cx:h.x??0,cy:h.y??0,r:h.radius??1.5,fill:h.color??"black"},`point-${E}`)),o.map((h,E)=>Z.jsx("text",{x:h.x??0,y:h.y??0,fontSize:h.fontSize??10,fill:h.color??"black",children:h.text??""},`text-${E}`))]})}var lei=({solver:e,animationSpeed:A=25,onSolverStarted:t,onSolverCompleted:i})=>{const[n,o]=AA.useReducer(c=>c+1,0),s=AA.useMemo(()=>{try{return e.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(c){return console.error("Visualization error:",c),{points:[],lines:[],rects:[],circles:[]}}},[e,n]),r=AA.useMemo(()=>(s.rects?.length||0)===0&&(s.lines?.length||0)===0&&(s.points?.length||0)===0&&(s.circles?.length||0)===0,[s]);AA.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const c=document.createElement("script");c.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(c)}},[]);const a=e.pipelineDef!==void 0,g=c=>{const I=e;if(!e.solved&&!e.failed){for(;!e.solved&&!e.failed&&I.currentPipelineStepIndex<=I.pipelineDef.findIndex(l=>l.solverName===c);)e.step();o()}};return Z.jsxs("div",{children:[Z.jsx(tei,{solver:e,triggerRender:o,animationSpeed:A,onSolverStarted:t,onSolverCompleted:i}),r?Z.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):Z.jsx(cei,{fallback:Z.jsx(Iei,{graphics:s}),children:Z.jsx(Xti,{graphics:s})}),a&&Z.jsx(gei,{solver:e,onStepUntilPhase:g})]})};const Bei=()=>{AA.useEffect(()=>{const e="tailwind-cdn-script";if(document.getElementById(e)||window.tailwind)return;const A=document.createElement("div");A.className="hidden",document.body.appendChild(A);const t=window.getComputedStyle(A).display==="none";if(document.body.removeChild(A),t)return;const i=document.createElement("script");i.id=e,i.src="https://cdn.tailwindcss.com",document.head.appendChild(i)},[])},Cei=e=>e.toLowerCase().includes("pack")?NLe:e.toLowerCase().includes("rout")?TLe:SLe,Qei=({solverEvents:e=[]})=>{const[A,t]=AA.useState(null);Bei();const i=AA.useMemo(()=>{const r=new Map;for(const a of e){const g=`${a.componentName}-${a.solverName}`;r.set(g,a)}return r},[e]),n=AA.useMemo(()=>Array.from(i.keys()),[i]),o=A?i.get(A):null,s=AA.useMemo(()=>{if(!o)return{instance:null,error:null,classFound:!1};const r=AcA[o.solverName];if(!r)return{instance:null,error:`Solver class "${o.solverName}" not found in SOLVERS registry. Available: ${Object.keys(AcA).join(", ")}`,classFound:!1};try{const a=o.solverParams,g=a?.input!==void 0?a.input:a;return{instance:new r(g),error:null,classFound:!0}}catch(a){const g=a instanceof Error?a.message:String(a);return console.error("Failed to reconstruct solver:",a),{instance:null,error:`Failed to instantiate solver: ${g}`,classFound:!0}}},[o]);return e.length===0?Z.jsx("div",{className:"rf-p-4",children:Z.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:Z.jsxs("div",{className:"rf-p-4",children:[Z.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),Z.jsx("p",{className:"rf-text-sm rf-text-gray-600",children:"Solvers will appear here when the circuit runs. Solvers are used for tasks like component packing and autorouting."})]})})}):Z.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[Z.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[Z.jsxs("div",{className:"rf-text-xs rf-font-semibold rf-text-gray-500 rf-px-3 rf-py-2 rf-bg-gray-50 rf-border-b rf-border-gray-200",children:[n.length," ",n.length===1?"Solver":"Solvers"]}),n.map(r=>{const a=i.get(r),g=A===r;return Z.jsx("div",{className:`rf-px-3 rf-py-2 rf-cursor-pointer rf-border-b rf-border-gray-100 ${g?"rf-bg-blue-50 rf-border-l-2 rf-border-l-blue-500":"hover:rf-bg-gray-50"}`,onClick:()=>t(r),children:(()=>{const c=Cei(a.solverName);return Z.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[Z.jsx(c,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),Z.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[Z.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:a.componentName}),Z.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:a.solverName})]})]})})()},r)})]}),Z.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:o?s.instance?Z.jsx(zD,{fallback:Z.jsx("div",{className:"rf-p-4",children:Z.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[Z.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),Z.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",o.solverName]})]})}),children:Z.jsx(lei,{solver:s.instance})}):Z.jsxs("div",{className:"rf-p-4",children:[Z.jsxs("div",{className:"rf-mb-4",children:[Z.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:o.solverName}),Z.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",o.componentName]})]}),s.error&&Z.jsx("div",{className:`rf-rounded-md rf-border rf-p-4 rf-mb-4 ${s.classFound?"rf-bg-red-50 rf-border-red-200":"rf-bg-yellow-50 rf-border-yellow-200"}`,children:Z.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),Z.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[Z.jsx("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50",children:Z.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"})}),Z.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:Z.jsx("pre",{className:"rf-text-xs rf-font-mono rf-text-gray-600 rf-whitespace-pre-wrap rf-overflow-x-auto",children:JSON.stringify(o.solverParams,null,2)})})]})]}):Z.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:Z.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},Bht=({errorMessage:e,errorStack:A,circuitJsonErrors:t})=>{AA.useEffect(()=>{if(e){const i=new Error(e);A&&(i.stack=A);try{hH.captureException(i)}catch{}}},[e,A]),AA.useEffect(()=>{if(t&&t.length>0)for(const i of t){const n=new Error(i.message||"Circuit JSON Error");i.stack&&(n.stack=i.stack);try{hH.captureException(n,{error_type:i.type})}catch{}}},[t])},Cht="0.0.1766",hei={version:Cht},NyA={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1},LyA=new Map,iV=e=>{const A=LyA.get(e);return A?Object.fromEntries(Object.entries(A.stores).map(([t,i])=>[t,i.getState()])):{}},Eei=(e,A,t)=>{if(e===void 0)return{type:"untracked",connection:A.connect(t)};const i=LyA.get(t.name);if(i)return{type:"tracked",store:e,...i};const n={connection:A.connect(t),stores:{}};return LyA.set(t.name,n),{type:"tracked",store:e,...n}},Qht=(e,A={})=>(t,i,n)=>{const{enabled:o,anonymousActionType:s,store:r,...a}=A;let g;try{g=(o??(NyA?"production":void 0)!=="production")&&window.__REDUX_DEVTOOLS_EXTENSION__}catch{}if(!g)return(NyA?"production":void 0)!=="production"&&o&&console.warn("[zustand devtools middleware] Please install/enable Redux devtools extension"),e(t,i,n);const{connection:c,...I}=Eei(r,g,a);let l=!0;n.setState=(Q,h,E)=>{const u=t(Q,h);if(!l)return u;const d=E===void 0?{type:s||"anonymous"}:typeof E=="string"?{type:E}:E;return r===void 0?(c?.send(d,i()),u):(c?.send({...d,type:`${r}/${d.type}`},{...iV(a.name),[r]:n.getState()}),u)};const B=(...Q)=>{const h=l;l=!1,t(...Q),l=h},C=e(n.setState,i,n);if(I.type==="untracked"?c?.init(C):(I.stores[I.store]=n,c?.init(Object.fromEntries(Object.entries(I.stores).map(([Q,h])=>[Q,Q===I.store?C:h.getState()])))),n.dispatchFromDevtools&&typeof n.dispatch=="function"){let Q=!1;const h=n.dispatch;n.dispatch=(...E)=>{(NyA?"production":void 0)!=="production"&&E[0].type==="__setState"&&!Q&&(console.warn('[zustand devtools middleware] "__setState" action type is reserved to set state from the devtools. Avoid using it.'),Q=!0),h(...E)}}return c.subscribe(Q=>{var h;switch(Q.type){case"ACTION":if(typeof Q.payload!="string"){console.error("[zustand devtools middleware] Unsupported action format");return}return UyA(Q.payload,E=>{if(E.type==="__setState"){if(r===void 0){B(E.state);return}Object.keys(E.state).length!==1&&console.error(`
5689
5689
  [zustand devtools middleware] Unsupported __setState action format.
5690
5690
  When using 'store' option in devtools(), the 'state' should have only one key, which is a value of 'store' that was passed in devtools(),
5691
5691
  and value of this only key should be a state object. Example: { "type": "__setState", "state": { "abc123Store": { "foo": "bar" } } }
@@ -5826,7 +5826,7 @@ ${a.join(`
5826
5826
  `)}};LA.register(GCi);var ift=class ASA extends LA{static token="locked";static parentToken="group";token="locked";value;constructor(A){super(),this.value=A}static fromSexprPrimitives(A){if(A.length===0)return new ASA(!0);const t=Di(A[0]);return new ASA(t==="yes")}getString(){return this.value?"(locked yes)":"(locked no)"}};LA.register(ift);var nft=class cxt extends LA{static token="members";static parentToken="group";token="members";members;constructor(A){super(),this.members=A}static fromSexprPrimitives(A){const t=[];for(const i of A){const n=Di(i);n&&t.push(n)}return new cxt(t)}getString(){return this.members.length===0?"(members)":`(members ${this.members.map(t=>`"${t}"`).join(" ")})`}};LA.register(nft);var S1A=class Ixt extends LA{static token="end";static parentToken="segment";token="end";_x;_y;constructor(A,t){super(),this._x=A,this._y=t}static fromSexprPrimitives(A){const[t,i]=A,n=Ci(t),o=Ci(i);if(n===void 0||o===void 0)throw new Error("end expects two numeric arguments");return new Ixt(n,o)}get x(){return this._x}set x(A){this._x=A}get y(){return this._y}set y(A){this._y=A}toObject(){return{x:this._x,y:this._y}}getChildren(){return[]}getString(){return`(end ${this._x} ${this._y})`}};LA.register(S1A);var RCi=new Set(["true","yes","1"]),oft=class Hz extends Wl{static token="locked";static parentToken="segment";token="locked";constructor(A){super(A)}static fromSexprPrimitives(A){const[t]=A;return typeof t=="boolean"?new Hz(t):typeof t=="string"?new Hz(RCi.has(t.toLowerCase())):new Hz(!1)}getString(){return`(locked ${this.value?"yes":"no"})`}};LA.register(oft);var rj=class lxt extends LA{static token="net";static parentToken="segment";token="net";_id;_name;constructor(A,t){super(),this._id=A,this._name=t}static fromSexprPrimitives(A){const[t,i]=A,n=Ci(t);if(n===void 0)throw new Error("net expects a numeric identifier");const o=i===void 0?void 0:Di(i);return new lxt(n,o??void 0)}get id(){return this._id}set id(A){this._id=A}get name(){return this._name}set name(A){this._name=A===""?void 0:A}toObject(){return this._name===void 0?{id:this._id}:{id:this._id,name:this._name}}getChildren(){return[]}getString(){const A=this._name?` ${mn(this._name)}`:"";return`(net ${this._id}${A})`}};LA.register(rj);var b1A=class Bxt extends LA{static token="start";static parentToken="segment";token="start";_x;_y;constructor(A,t){super(),this._x=A,this._y=t}static fromSexprPrimitives(A){const[t,i]=A,n=Ci(t),o=Ci(i);if(n===void 0||o===void 0)throw new Error("start expects two numeric arguments");return new Bxt(n,o)}get x(){return this._x}set x(A){this._x=A}get y(){return this._y}set y(A){this._y=A}toObject(){return{x:this._x,y:this._y}}getChildren(){return[]}getString(){return`(start ${this._x} ${this._y})`}};LA.register(b1A);var sft=new Set(["start","end","width","layer","net","tstamp","uuid","locked"]),_1A=class Cxt extends LA{static token="segment";token="segment";_sxStart;_sxEnd;_sxWidth;_sxLayer;_sxNet;_sxTstamp;_sxUuid;_sxLocked;constructor(A={}){super(),A.start!==void 0&&(this.start=A.start),A.end!==void 0&&(this.end=A.end),A.width!==void 0&&(this.width=A.width),A.layer!==void 0&&(this.layer=A.layer),A.net!==void 0&&(this.net=A.net),A.tstamp!==void 0&&(this.tstamp=A.tstamp),A.uuid!==void 0&&(this.uuid=A.uuid),A.locked!==void 0&&(this.locked=A.locked)}static fromSexprPrimitives(A){const t=new Cxt,{propertyMap:i,arrayPropertyMap:n}=LA.parsePrimitivesToClassProperties(A,this.token),o=Object.keys(i).filter(r=>!sft.has(r));if(o.length>0)throw new Error(`Unsupported child tokens inside segment expression: ${o.join(", ")}`);for(const[r,a]of Object.entries(n)){if(!sft.has(r))throw new Error(`Unsupported child tokens inside segment expression: ${r}`);if(a.length>1)throw new Error(`Segment does not support repeated child tokens: ${r}`)}t._sxStart=n.start?.[0]??i.start,t._sxEnd=n.end?.[0]??i.end,t._sxWidth=n.width?.[0]??i.width,t._sxLayer=n.layer?.[0]??i.layer,t._sxNet=n.net?.[0]??i.net;const s=n.locked?.[0]??i.locked;return t._sxLocked=s&&s.value?s:void 0,t._sxTstamp=n.tstamp?.[0]??i.tstamp,t._sxUuid=n.uuid?.[0]??i.uuid,t}get start(){return this._sxStart}set start(A){this._sxStart=this.normalizeStart(A)}get end(){return this._sxEnd}set end(A){this._sxEnd=this.normalizeEnd(A)}get startPoint(){return this._sxStart?.toObject()}get endPoint(){return this._sxEnd?.toObject()}get width(){return this._sxWidth?.value}set width(A){if(A===void 0){this._sxWidth=void 0;return}this._sxWidth=A instanceof Jr?A:new Jr(A)}get widthClass(){return this._sxWidth}set widthClass(A){this._sxWidth=A}get layer(){return this._sxLayer}set layer(A){if(A===void 0){this._sxLayer=void 0;return}if(A instanceof kr){this._sxLayer=A;return}const t=Array.isArray(A)?A:[A];this._sxLayer=new kr(t)}get net(){return this._sxNet}set net(A){if(A===void 0){this._sxNet=void 0;return}if(A instanceof rj){this._sxNet=A;return}this._sxNet=new rj(A.id,A.name)}get tstamp(){return this._sxTstamp}set tstamp(A){if(A===void 0){this._sxTstamp=void 0;return}this._sxTstamp=A instanceof sc?A:new sc(A)}get uuid(){return this._sxUuid}set uuid(A){if(A===void 0){this._sxUuid=void 0;return}this._sxUuid=A instanceof qi?A:new qi(A)}get locked(){return this._sxLocked?.value??!1}set locked(A){this._sxLocked=A?new oft(!0):void 0}getChildren(){const A=[];return this._sxStart&&A.push(this._sxStart),this._sxEnd&&A.push(this._sxEnd),this._sxWidth&&A.push(this._sxWidth),this._sxLayer&&A.push(this._sxLayer),this._sxNet&&A.push(this._sxNet),this._sxLocked&&A.push(this._sxLocked),this._sxTstamp&&A.push(this._sxTstamp),this._sxUuid&&A.push(this._sxUuid),A}normalizeStart(A){if(A!==void 0)return A instanceof b1A?A:new b1A(A.x,A.y)}normalizeEnd(A){if(A!==void 0)return A instanceof S1A?A:new S1A(A.x,A.y)}};LA.register(_1A);var rft=class Qxt extends LA{static token="zone";token="zone";_rawChildren=[];static fromSexprPrimitives(A){const t=new Qxt;return t._rawChildren=[...A],t}get rawChildren(){return[...this._rawChildren]}set rawChildren(A){this._rawChildren=[...A]}getChildren(){return[]}getString(){const A=["(zone"];for(const t of this._rawChildren)A.push(` ${A0(t)}`);return A.push(")"),A.join(`
5827
5827
  `)}};LA.register(rft);var aj=class hxt extends LA{static token="layers";token="layers";_names=[];constructor(A=[]){super(),this.names=A}static fromSexprPrimitives(A){const t=A.map(i=>typeof i=="string"||typeof i=="number"?String(i):A0(i));return new hxt(t)}get names(){return[...this._names]}set names(A){this._names=A.map(t=>String(t))}getString(){return`(layers ${this._names.map(t=>/^[^\s()"]+$/u.test(t)&&!["nil","#t","#f"].includes(t)?t:mn(t)).join(" ")})`}};LA.register(aj);var B6=class extends LA{_value;quoteStringValue=!1;constructor(e){super(),this._value=e}static fromSexprPrimitives(e){const[A]=e,t=this.parsePrimitiveValue(A),i=this;return new i(t)}static parsePrimitiveValue(e){const A=Di(e);if(A===void 0)throw new Error(`${this.name} expects a primitive value`);return A}get value(){return this._value}set value(e){this._value=e}getChildren(){return[]}formatValue(){return typeof this._value=="string"?this.quoteStringValue?mn(this._value):this._value:`${this._value}`}getString(){return`(${this.token} ${this.formatValue()})`}},NCi=class extends LA{_values;constructor(e){super(),this._values=e}static fromSexprPrimitives(e){const A=e.map(i=>{const n=Ci(i);if(n===void 0)throw new Error(`${this.name} expects numeric primitives but received ${i}`);return n}),t=this;return new t(A)}get values(){return[...this._values]}set values(e){this._values=[...e]}getChildren(){return[]}getString(){return`(${this.token} ${this._values.join(" ")})`}},LCi=class extends LA{_x;_y;constructor(e,A){super(),this._x=e,this._y=A}static fromSexprPrimitives(e){const[A,t]=e,i=Ci(A),n=Ci(t);if(i===void 0||n===void 0)throw new Error(`${this.name} expects two numeric values`);const o=this;return new o(i,n)}get x(){return this._x}set x(e){this._x=e}get y(){return this._y}set y(e){this._y=e}getChildren(){return[]}getString(){return`(${this.token} ${this._x} ${this._y})`}},vr=class extends B6{static parentToken="pcbplotparams"},Sm=class extends vr{static parsePrimitiveValue(e){const A=Ci(e);if(A===void 0)throw new Error(`pcbplotparams ${this.token} expects a numeric value`);return A}},aft=class extends vr{static token="layerselection";token="layerselection"};LA.register(aft);var gft=class extends vr{static token="plot_on_all_layers_selection";token="plot_on_all_layers_selection"};LA.register(gft);var cft=class extends Sm{static token="dashed_line_dash_ratio";token="dashed_line_dash_ratio"};LA.register(cft);var Ift=class extends Sm{static token="dashed_line_gap_ratio";token="dashed_line_gap_ratio"};LA.register(Ift);var lft=class extends Sm{static token="svgprecision";token="svgprecision"};LA.register(lft);var Bft=class extends Sm{static token="linewidth";token="linewidth"};LA.register(Bft);var Cft=class extends Sm{static token="mode";token="mode"};LA.register(Cft);var Qft=class extends Sm{static token="hpglpennumber";token="hpglpennumber"};LA.register(Qft);var hft=class extends Sm{static token="hpglpenspeed";token="hpglpenspeed"};LA.register(hft);var Eft=class extends Sm{static token="hpglpendiameter";token="hpglpendiameter"};LA.register(Eft);var uft=class extends Sm{static token="hpglpenoverlay";token="hpglpenoverlay"};LA.register(uft);var dft=class extends Sm{static token="outputformat";token="outputformat"};LA.register(dft);var pft=class extends Sm{static token="drillshape";token="drillshape"};LA.register(pft);var fft=class extends Sm{static token="scaleselection";token="scaleselection"};LA.register(fft);var yft=class extends vr{static token="disableapertmacros";token="disableapertmacros"};LA.register(yft);var mft=class extends vr{static token="usegerberextensions";token="usegerberextensions"};LA.register(mft);var wft=class extends vr{static token="usegerberattributes";token="usegerberattributes"};LA.register(wft);var Dft=class extends vr{static token="usegerberadvancedattributes";token="usegerberadvancedattributes"};LA.register(Dft);var xft=class extends vr{static token="creategerberjobfile";token="creategerberjobfile"};LA.register(xft);var Sft=class extends vr{static token="excludeedgelayer";token="excludeedgelayer"};LA.register(Sft);var bft=class extends vr{static token="plotframeref";token="plotframeref"};LA.register(bft);var _ft=class extends vr{static token="viasonmask";token="viasonmask"};LA.register(_ft);var kft=class extends vr{static token="useauxorigin";token="useauxorigin"};LA.register(kft);var vft=class extends vr{static token="pdf_front_fp_property_popups";token="pdf_front_fp_property_popups"};LA.register(vft);var Fft=class extends vr{static token="pdf_back_fp_property_popups";token="pdf_back_fp_property_popups"};LA.register(Fft);var Mft=class extends vr{static token="pdf_metadata";token="pdf_metadata"};LA.register(Mft);var Gft=class extends vr{static token="pdf_single_document";token="pdf_single_document"};LA.register(Gft);var Rft=class extends vr{static token="dxfpolygonmode";token="dxfpolygonmode"};LA.register(Rft);var Nft=class extends vr{static token="dxfimperialunits";token="dxfimperialunits"};LA.register(Nft);var Lft=class extends vr{static token="dxfusepcbnewfont";token="dxfusepcbnewfont"};LA.register(Lft);var Uft=class extends vr{static token="psnegative";token="psnegative"};LA.register(Uft);var Hft=class extends vr{static token="psa4output";token="psa4output"};LA.register(Hft);var Yft=class extends vr{static token="plotreference";token="plotreference"};LA.register(Yft);var Jft=class extends vr{static token="plotvalue";token="plotvalue"};LA.register(Jft);var Tft=class extends vr{static token="plotothertext";token="plotothertext"};LA.register(Tft);var Pft=class extends vr{static token="plotinvisibletext";token="plotinvisibletext"};LA.register(Pft);var Kft=class extends vr{static token="padsonsilk";token="padsonsilk"};LA.register(Kft);var qft=class extends vr{static token="sketchpadsonfab";token="sketchpadsonfab"};LA.register(qft);var Oft=class extends vr{static token="plotpadnumbers";token="plotpadnumbers"};LA.register(Oft);var Wft=class extends vr{static token="hidednponfab";token="hidednponfab"};LA.register(Wft);var Zft=class extends vr{static token="sketchdnponfab";token="sketchdnponfab"};LA.register(Zft);var Vft=class extends vr{static token="crossoutdnponfab";token="crossoutdnponfab"};LA.register(Vft);var jft=class extends vr{static token="subtractmaskfromsilk";token="subtractmaskfromsilk"};LA.register(jft);var zft=class extends vr{static token="plot_black_and_white";token="plot_black_and_white"};LA.register(zft);var Xft=class extends vr{static token="mirror";token="mirror"};LA.register(Xft);var $ft=class extends vr{static token="outputdirectory";token="outputdirectory";quoteStringValue=!0};LA.register($ft);var Ayt=class extends vr{static token="plot_on_all_layers";token="plot_on_all_layers"};LA.register(Ayt);var tyt=class extends vr{static token="plotinvisible";token="plotinvisible"};LA.register(tyt);var UCi={layerselection:"layerselection",plot_on_all_layers_selection:"plot_on_all_layers_selection",disableapertmacros:"disableapertmacros",usegerberextensions:"usegerberextensions",usegerberattributes:"usegerberattributes",usegerberadvancedattributes:"usegerberadvancedattributes",creategerberjobfile:"creategerberjobfile",excludeedgelayer:"excludeedgelayer",dashed_line_dash_ratio:"dashed_line_dash_ratio",dashed_line_gap_ratio:"dashed_line_gap_ratio",svgprecision:"svgprecision",linewidth:"linewidth",plotframeref:"plotframeref",plotreference:"plotreference",plotvalue:"plotvalue",plotothertext:"plotothertext",plotinvisibletext:"plotinvisibletext",padsonsilk:"padsonsilk",sketchpadsonfab:"sketchpadsonfab",plotpadnumbers:"plotpadnumbers",hidednponfab:"hidednponfab",sketchdnponfab:"sketchdnponfab",crossoutdnponfab:"crossoutdnponfab",subtractmaskfromsilk:"subtractmaskfromsilk",plot_black_and_white:"plot_black_and_white",plot_on_all_layers:"plot_on_all_layers",plotinvisible:"plotinvisible",mode:"mode",useauxorigin:"useauxorigin",viasonmask:"viasonmask",hpglpennumber:"hpglpennumber",hpglpenspeed:"hpglpenspeed",hpglpendiameter:"hpglpendiameter",hpglpenoverlay:"hpglpenoverlay",pdf_front_fp_property_popups:"pdf_front_fp_property_popups",pdf_back_fp_property_popups:"pdf_back_fp_property_popups",pdf_metadata:"pdf_metadata",pdf_single_document:"pdf_single_document",dxfpolygonmode:"dxfpolygonmode",dxfimperialunits:"dxfimperialunits",dxfusepcbnewfont:"dxfusepcbnewfont",psnegative:"psnegative",psa4output:"psa4output",mirror:"mirror",outputformat:"outputformat",drillshape:"drillshape",scaleselection:"scaleselection",outputdirectory:"outputdirectory"},HCi=["layerselection","plot_on_all_layers_selection","disableapertmacros","usegerberextensions","usegerberattributes","usegerberadvancedattributes","creategerberjobfile","excludeedgelayer","dashed_line_dash_ratio","dashed_line_gap_ratio","svgprecision","linewidth","plotframeref","plotreference","plotvalue","plotothertext","mode","useauxorigin","viasonmask","hpglpennumber","hpglpenspeed","hpglpendiameter","hpglpenoverlay","pdf_front_fp_property_popups","pdf_back_fp_property_popups","pdf_metadata","pdf_single_document","dxfpolygonmode","dxfimperialunits","dxfusepcbnewfont","psnegative","psa4output","plot_black_and_white","plot_on_all_layers","plotinvisible","plotinvisibletext","padsonsilk","sketchpadsonfab","plotpadnumbers","hidednponfab","sketchdnponfab","crossoutdnponfab","subtractmaskfromsilk","outputformat","mirror","drillshape","scaleselection","outputdirectory"],k1A=class Ext extends LA{static token="pcbplotparams";static parentToken="setup";token="pcbplotparams";_properties={};static fromSexprPrimitives(A){const t=new Ext,{propertyMap:i}=LA.parsePrimitivesToClassProperties(A,this.token);for(const[n,o]of Object.entries(i)){const s=UCi[n];if(!s)throw new Error(`Unsupported pcbplotparams token: ${n}`);t._properties[s]=o}return t}getChildren(){const A=[];for(const t of HCi){const i=this._properties[t];i&&A.push(i)}return A}clearProperty(A){delete this._properties[A]}setStringProperty(A,t,i){if(t===void 0){this.clearProperty(A);return}this._properties[A]=new i(t)}setNumberProperty(A,t,i){if(t===void 0){this.clearProperty(A);return}this._properties[A]=new i(t)}setStringOrNumberProperty(A,t,i){if(t===void 0){this.clearProperty(A);return}this._properties[A]=new i(t)}get layerselection(){return this._properties.layerselection?.value}set layerselection(A){this.setStringOrNumberProperty("layerselection",A,aft)}get plot_on_all_layers_selection(){return this._properties.plot_on_all_layers_selection?.value}set plot_on_all_layers_selection(A){this.setStringOrNumberProperty("plot_on_all_layers_selection",A,gft)}get disableapertmacros(){return this._properties.disableapertmacros?.value}set disableapertmacros(A){this.setStringProperty("disableapertmacros",A,yft)}get usegerberextensions(){return this._properties.usegerberextensions?.value}set usegerberextensions(A){this.setStringProperty("usegerberextensions",A,mft)}get usegerberattributes(){return this._properties.usegerberattributes?.value}set usegerberattributes(A){this.setStringProperty("usegerberattributes",A,wft)}get usegerberadvancedattributes(){return this._properties.usegerberadvancedattributes?.value}set usegerberadvancedattributes(A){this.setStringProperty("usegerberadvancedattributes",A,Dft)}get creategerberjobfile(){return this._properties.creategerberjobfile?.value}set creategerberjobfile(A){this.setStringProperty("creategerberjobfile",A,xft)}get excludeedgelayer(){return this._properties.excludeedgelayer?.value}set excludeedgelayer(A){this.setStringProperty("excludeedgelayer",A,Sft)}get dashed_line_dash_ratio(){return this._properties.dashed_line_dash_ratio?.value}set dashed_line_dash_ratio(A){this.setNumberProperty("dashed_line_dash_ratio",A,cft)}get dashed_line_gap_ratio(){return this._properties.dashed_line_gap_ratio?.value}set dashed_line_gap_ratio(A){this.setNumberProperty("dashed_line_gap_ratio",A,Ift)}get svgprecision(){return this._properties.svgprecision?.value}set svgprecision(A){this.setNumberProperty("svgprecision",A,lft)}get linewidth(){return this._properties.linewidth?.value}set linewidth(A){this.setNumberProperty("linewidth",A,Bft)}get plotframeref(){return this._properties.plotframeref?.value}set plotframeref(A){this.setStringProperty("plotframeref",A,bft)}get plotreference(){return this._properties.plotreference?.value}set plotreference(A){this.setStringProperty("plotreference",A,Yft)}get plotvalue(){return this._properties.plotvalue?.value}set plotvalue(A){this.setStringProperty("plotvalue",A,Jft)}get plotothertext(){return this._properties.plotothertext?.value}set plotothertext(A){this.setStringProperty("plotothertext",A,Tft)}get plotinvisibletext(){return this._properties.plotinvisibletext?.value}set plotinvisibletext(A){this.setStringProperty("plotinvisibletext",A,Pft)}get padsonsilk(){return this._properties.padsonsilk?.value}set padsonsilk(A){this.setStringProperty("padsonsilk",A,Kft)}get plotpadnumbers(){return this._properties.plotpadnumbers?.value}set plotpadnumbers(A){this.setStringProperty("plotpadnumbers",A,Oft)}get sketchpadsonfab(){return this._properties.sketchpadsonfab?.value}set sketchpadsonfab(A){this.setStringProperty("sketchpadsonfab",A,qft)}get hidednponfab(){return this._properties.hidednponfab?.value}set hidednponfab(A){this.setStringProperty("hidednponfab",A,Wft)}get sketchdnponfab(){return this._properties.sketchdnponfab?.value}set sketchdnponfab(A){this.setStringProperty("sketchdnponfab",A,Zft)}get crossoutdnponfab(){return this._properties.crossoutdnponfab?.value}set crossoutdnponfab(A){this.setStringProperty("crossoutdnponfab",A,Vft)}get subtractmaskfromsilk(){return this._properties.subtractmaskfromsilk?.value}set subtractmaskfromsilk(A){this.setStringProperty("subtractmaskfromsilk",A,jft)}get plot_black_and_white(){return this._properties.plot_black_and_white?.value}set plot_black_and_white(A){this.setStringProperty("plot_black_and_white",A,zft)}get plot_on_all_layers(){return this._properties.plot_on_all_layers?.value}set plot_on_all_layers(A){this.setStringProperty("plot_on_all_layers",A,Ayt)}get plotinvisible(){return this._properties.plotinvisible?.value}set plotinvisible(A){this.setStringProperty("plotinvisible",A,tyt)}get mode(){return this._properties.mode?.value}set mode(A){this.setNumberProperty("mode",A,Cft)}get useauxorigin(){return this._properties.useauxorigin?.value}set useauxorigin(A){this.setStringProperty("useauxorigin",A,kft)}get viasonmask(){return this._properties.viasonmask?.value}set viasonmask(A){this.setStringProperty("viasonmask",A,_ft)}get hpglpennumber(){return this._properties.hpglpennumber?.value}set hpglpennumber(A){this.setNumberProperty("hpglpennumber",A,Qft)}get hpglpenspeed(){return this._properties.hpglpenspeed?.value}set hpglpenspeed(A){this.setNumberProperty("hpglpenspeed",A,hft)}get hpglpendiameter(){return this._properties.hpglpendiameter?.value}set hpglpendiameter(A){this.setNumberProperty("hpglpendiameter",A,Eft)}get hpglpenoverlay(){return this._properties.hpglpenoverlay?.value}set hpglpenoverlay(A){this.setNumberProperty("hpglpenoverlay",A,uft)}get pdf_front_fp_property_popups(){return this._properties.pdf_front_fp_property_popups?.value}set pdf_front_fp_property_popups(A){this.setStringProperty("pdf_front_fp_property_popups",A,vft)}get pdf_back_fp_property_popups(){return this._properties.pdf_back_fp_property_popups?.value}set pdf_back_fp_property_popups(A){this.setStringProperty("pdf_back_fp_property_popups",A,Fft)}get pdf_metadata(){return this._properties.pdf_metadata?.value}set pdf_metadata(A){this.setStringProperty("pdf_metadata",A,Mft)}get pdf_single_document(){return this._properties.pdf_single_document?.value}set pdf_single_document(A){this.setStringProperty("pdf_single_document",A,Gft)}get dxfpolygonmode(){return this._properties.dxfpolygonmode?.value}set dxfpolygonmode(A){this.setStringProperty("dxfpolygonmode",A,Rft)}get dxfimperialunits(){return this._properties.dxfimperialunits?.value}set dxfimperialunits(A){this.setStringProperty("dxfimperialunits",A,Nft)}get dxfusepcbnewfont(){return this._properties.dxfusepcbnewfont?.value}set dxfusepcbnewfont(A){this.setStringProperty("dxfusepcbnewfont",A,Lft)}get psnegative(){return this._properties.psnegative?.value}set psnegative(A){this.setStringProperty("psnegative",A,Uft)}get psa4output(){return this._properties.psa4output?.value}set psa4output(A){this.setStringProperty("psa4output",A,Hft)}get mirror(){return this._properties.mirror?.value}set mirror(A){this.setStringProperty("mirror",A,Xft)}get outputformat(){return this._properties.outputformat?.value}set outputformat(A){this.setNumberProperty("outputformat",A,dft)}get drillshape(){return this._properties.drillshape?.value}set drillshape(A){this.setNumberProperty("drillshape",A,pft)}get scaleselection(){return this._properties.scaleselection?.value}set scaleselection(A){this.setNumberProperty("scaleselection",A,fft)}get outputdirectory(){return this._properties.outputdirectory?.value}set outputdirectory(A){this.setStringProperty("outputdirectory",A,$ft)}};LA.register(k1A);var gj=class extends B6{static parentToken="setup"},v1A=class extends gj{static token="zone_45_only";token="zone_45_only"};LA.register(v1A);var F1A=class extends gj{static token="allow_soldermask_bridges_in_footprints";token="allow_soldermask_bridges_in_footprints"};LA.register(F1A);var M1A=class extends gj{static token="visible_elements";token="visible_elements"};LA.register(M1A);var G1A=class extends gj{static token="uvias_allowed";token="uvias_allowed"};LA.register(G1A);var R1A=class uxt extends LA{static token="tenting";static parentToken="setup";token="tenting";_sides=[];constructor(A=[]){super(),this.sides=A}static fromSexprPrimitives(A){const t=A.map(i=>Di(i)).filter(i=>i!==void 0);return new uxt(t)}get sides(){return[...this._sides]}set sides(A){this._sides=A.map(t=>String(t))}getChildren(){return[]}getString(){return this._sides.length===0?"(tenting)":`(tenting ${this._sides.join(" ")})`}};LA.register(R1A);var C6=class extends NCi{static parentToken="setup"},eyt=class extends LCi{static parentToken="setup"},N1A=class extends C6{static token="pcb_text_size";token="pcb_text_size"};LA.register(N1A);var L1A=class extends C6{static token="mod_text_size";token="mod_text_size"};LA.register(L1A);var U1A=class extends C6{static token="pad_size";token="pad_size"};LA.register(U1A);var H1A=class extends C6{static token="pad_to_paste_clearance_values";token="pad_to_paste_clearance_values"};LA.register(H1A);var Y1A=class extends C6{static token="trace_width";token="trace_width"};LA.register(Y1A);var J1A=class extends eyt{static token="aux_axis_origin";token="aux_axis_origin"};LA.register(J1A);var T1A=class extends eyt{static token="grid_origin";token="grid_origin"};LA.register(T1A);var mB=class extends B6{static parentToken="setup";static parsePrimitiveValue(e){const A=Ci(e);if(A===void 0)throw new Error(`${this.name} expects a numeric value`);return A}},P1A=class extends mB{static token="pad_to_mask_clearance";token="pad_to_mask_clearance"};LA.register(P1A);var K1A=class extends mB{static token="solder_mask_min_width";token="solder_mask_min_width"};LA.register(K1A);var q1A=class extends mB{static token="pad_to_paste_clearance";token="pad_to_paste_clearance"};LA.register(q1A);var O1A=class extends mB{static token="pad_to_paste_clearance_ratio";token="pad_to_paste_clearance_ratio"};LA.register(O1A);var W1A=class extends mB{static token="last_trace_width";token="last_trace_width"};LA.register(W1A);var Z1A=class extends mB{static token="trace_clearance";token="trace_clearance"};LA.register(Z1A);var V1A=class extends mB{static token="zone_clearance";token="zone_clearance"};LA.register(V1A);var j1A=class extends mB{static token="trace_min";token="trace_min"};LA.register(j1A);var z1A=class extends mB{static token="segment_width";token="segment_width"};LA.register(z1A);var X1A=class extends mB{static token="edge_width";token="edge_width"};LA.register(X1A);var $1A=class extends mB{static token="via_size";token="via_size"};LA.register($1A);var A2A=class extends mB{static token="via_drill";token="via_drill"};LA.register(A2A);var t2A=class extends mB{static token="via_min_size";token="via_min_size"};LA.register(t2A);var e2A=class extends mB{static token="via_min_drill";token="via_min_drill"};LA.register(e2A);var i2A=class extends mB{static token="uvia_size";token="uvia_size"};LA.register(i2A);var n2A=class extends mB{static token="uvia_drill";token="uvia_drill"};LA.register(n2A);var o2A=class extends mB{static token="uvia_min_size";token="uvia_min_size"};LA.register(o2A);var s2A=class extends mB{static token="uvia_min_drill";token="uvia_min_drill"};LA.register(s2A);var r2A=class extends mB{static token="pcb_text_width";token="pcb_text_width"};LA.register(r2A);var a2A=class extends mB{static token="mod_edge_width";token="mod_edge_width"};LA.register(a2A);var g2A=class extends mB{static token="mod_text_width";token="mod_text_width"};LA.register(g2A);var c2A=class extends mB{static token="pad_drill";token="pad_drill"};LA.register(c2A);var Q6=class extends B6{static parentToken="stackup"},iyt=class extends Q6{static token="copper_finish";token="copper_finish";quoteStringValue=!0};LA.register(iyt);var nyt=class extends Q6{static token="dielectric_constraints";token="dielectric_constraints"};LA.register(nyt);var oyt=class extends Q6{static token="edge_connector";token="edge_connector"};LA.register(oyt);var syt=class extends Q6{static token="castellated_pads";token="castellated_pads"};LA.register(syt);var ryt=class extends Q6{static token="edge_plating";token="edge_plating"};LA.register(ryt);var HM=class extends B6{static parentToken="layer"},I2A=class extends HM{static token="type";token="type";quoteStringValue=!0};LA.register(I2A);var l2A=class extends HM{static token="color";token="color";quoteStringValue=!0};LA.register(l2A);var B2A=class extends HM{static token="thickness";token="thickness";static parsePrimitiveValue(e){const A=Ci(e);if(A===void 0)throw new Error("Stackup layer thickness expects a numeric value");return A}};LA.register(B2A);var C2A=class extends HM{static token="material";token="material";quoteStringValue=!0};LA.register(C2A);var Q2A=class extends HM{static token="epsilon_r";token="epsilon_r";static parsePrimitiveValue(e){const A=Ci(e);if(A===void 0)throw new Error("Stackup layer epsilon_r expects a numeric value");return A}};LA.register(Q2A);var h2A=class extends HM{static token="loss_tangent";token="loss_tangent";static parsePrimitiveValue(e){const A=Ci(e);if(A===void 0)throw new Error("Stackup layer loss_tangent expects a numeric value");return A}};LA.register(h2A);var ayt=class dxt extends LA{static token="layer";static parentToken="stackup";token="layer";_name;_number;_sxType;_sxColor;_sxThickness;_sxMaterial;_sxEpsilonR;_sxLossTangent;constructor(A,t={}){super(),this._name=A,this._number=t.number,this._sxType=t.type,this._sxColor=t.color,this._sxThickness=t.thickness,this._sxMaterial=t.material,this._sxEpsilonR=t.epsilonR,this._sxLossTangent=t.lossTangent}static fromSexprPrimitives(A){if(A.length===0)throw new Error("Stackup layer requires at least a name");const t=Di(A[0]);if(t===void 0)throw new Error("Stackup layer name must be a string");let i=1,n;const o=A[i],s=Ci(o);s!==void 0&&(n=s,i+=1);const r=A.slice(i),{propertyMap:a}=LA.parsePrimitivesToClassProperties(r,this.token);return new dxt(t,{number:n,type:a.type,color:a.color,thickness:a.thickness,material:a.material,epsilonR:a.epsilon_r,lossTangent:a.loss_tangent})}get name(){return this._name}set name(A){const t=Di(A);if(t===void 0)throw new Error("Stackup layer name must be a string");this._name=t}get number(){return this._number}set number(A){if(A===void 0){this._number=void 0;return}const t=Ci(A);if(t===void 0)throw new Error("Stackup layer number must be numeric");this._number=t}get type(){return this._sxType?.value}set type(A){if(A===void 0){this._sxType=void 0;return}this._sxType=A instanceof I2A?A:new I2A(A)}get color(){return this._sxColor?.value}set color(A){if(A===void 0){this._sxColor=void 0;return}this._sxColor=A instanceof l2A?A:new l2A(A)}get thickness(){return this._sxThickness?.value}set thickness(A){if(A===void 0){this._sxThickness=void 0;return}this._sxThickness=A instanceof B2A?A:new B2A(A)}get material(){return this._sxMaterial?.value}set material(A){if(A===void 0){this._sxMaterial=void 0;return}this._sxMaterial=A instanceof C2A?A:new C2A(A)}get epsilonR(){return this._sxEpsilonR?.value}set epsilonR(A){if(A===void 0){this._sxEpsilonR=void 0;return}this._sxEpsilonR=A instanceof Q2A?A:new Q2A(A)}get lossTangent(){return this._sxLossTangent?.value}set lossTangent(A){if(A===void 0){this._sxLossTangent=void 0;return}this._sxLossTangent=A instanceof h2A?A:new h2A(A)}getChildren(){const A=[];return this._sxType&&A.push(this._sxType),this._sxColor&&A.push(this._sxColor),this._sxThickness&&A.push(this._sxThickness),this._sxMaterial&&A.push(this._sxMaterial),this._sxEpsilonR&&A.push(this._sxEpsilonR),this._sxLossTangent&&A.push(this._sxLossTangent),A}getString(){const A=`(layer ${mn(this._name)}${this._number!==void 0?` ${this._number}`:""}`,t=this.getChildren();if(t.length===0)return`${A})`;const i=[A];for(const n of t)i.push(n.getStringIndented());return i.push(")"),i.join(`
5828
5828
  `)}};LA.register(ayt);var E2A=class pxt extends LA{static token="stackup";static parentToken="setup";token="stackup";_layers=[];_sxCopperFinish;_sxDielectricConstraints;_sxEdgeConnector;_sxCastellatedPads;_sxEdgePlating;constructor(A={}){super(),this.layers=A.layers??[],this._sxCopperFinish=A.copperFinish,this._sxDielectricConstraints=A.dielectricConstraints,this._sxEdgeConnector=A.edgeConnector,this._sxCastellatedPads=A.castellatedPads,this._sxEdgePlating=A.edgePlating}static fromSexprPrimitives(A){const{propertyMap:t,arrayPropertyMap:i}=LA.parsePrimitivesToClassProperties(A,this.token);return new pxt({layers:i.layer??[],copperFinish:t.copper_finish,dielectricConstraints:t.dielectric_constraints,edgeConnector:t.edge_connector,castellatedPads:t.castellated_pads,edgePlating:t.edge_plating})}get layers(){return[...this._layers]}set layers(A){this._layers=A.map(t=>{if(!(t instanceof ayt))throw new Error("Stackup layers must be StackupLayer instances");return t})}get copperFinish(){return this._sxCopperFinish?.value}set copperFinish(A){this._sxCopperFinish=A?new iyt(A):void 0}get dielectricConstraints(){return this._sxDielectricConstraints?.value}set dielectricConstraints(A){this._sxDielectricConstraints=A?new nyt(A):void 0}get edgeConnector(){return this._sxEdgeConnector?.value}set edgeConnector(A){this._sxEdgeConnector=A?new oyt(A):void 0}get castellatedPads(){return this._sxCastellatedPads?.value}set castellatedPads(A){this._sxCastellatedPads=A?new syt(A):void 0}get edgePlating(){return this._sxEdgePlating?.value}set edgePlating(A){this._sxEdgePlating=A?new ryt(A):void 0}getChildren(){const A=[...this._layers],t=[this._sxCopperFinish,this._sxDielectricConstraints,this._sxEdgeConnector,this._sxCastellatedPads,this._sxEdgePlating];for(const i of t)i&&A.push(i);return A}};LA.register(E2A);var YCi={stackup:"stackup",pcbplotparams:"pcbPlotParams",pad_to_mask_clearance:"padToMaskClearance",solder_mask_min_width:"solderMaskMinWidth",pad_to_paste_clearance:"padToPasteClearance",pad_to_paste_clearance_ratio:"padToPasteClearanceRatio",last_trace_width:"lastTraceWidth",trace_clearance:"traceClearance",zone_clearance:"zoneClearance",zone_45_only:"zone45Only",trace_min:"traceMin",segment_width:"segmentWidth",edge_width:"edgeWidth",via_size:"viaSize",via_drill:"viaDrill",via_min_size:"viaMinSize",via_min_drill:"viaMinDrill",uvias_allowed:"uviasAllowed",uvia_size:"uviaSize",uvia_drill:"uviaDrill",uvia_min_size:"uviaMinSize",uvia_min_drill:"uviaMinDrill",pcb_text_width:"pcbTextWidth",pcb_text_size:"pcbTextSize",mod_edge_width:"modEdgeWidth",mod_text_size:"modTextSize",mod_text_width:"modTextWidth",pad_size:"padSize",pad_drill:"padDrill",allow_soldermask_bridges_in_footprints:"allowSoldermaskBridgesInFootprints",tenting:"tenting",aux_axis_origin:"auxAxisOrigin",grid_origin:"gridOrigin",visible_elements:"visibleElements",pad_to_paste_clearance_values:"padToPasteClearanceValues",trace_width:"traceWidth"},JCi=["stackup","padToMaskClearance","solderMaskMinWidth","padToPasteClearance","padToPasteClearanceRatio","lastTraceWidth","traceClearance","zoneClearance","zone45Only","traceMin","segmentWidth","edgeWidth","viaSize","viaDrill","viaMinSize","viaMinDrill","uviaSize","uviaDrill","uviasAllowed","uviaMinSize","uviaMinDrill","pcbTextWidth","pcbTextSize","modEdgeWidth","modTextSize","modTextWidth","padSize","padDrill","allowSoldermaskBridgesInFootprints","tenting","auxAxisOrigin","gridOrigin","visibleElements","padToPasteClearanceValues","traceWidth","pcbPlotParams"],u2A=class fxt extends LA{static token="setup";token="setup";_properties={};static fromSexprPrimitives(A){const t=new fxt,{propertyMap:i}=LA.parsePrimitivesToClassProperties(A,this.token);for(const[n,o]of Object.entries(i)){const s=YCi[n];if(!s)throw new Error(`Unsupported setup property token: ${n}`);t._properties[s]=o}return t}getChildren(){const A=[];for(const t of JCi){const i=this._properties[t];i&&A.push(i)}return A}setProperty(A,t){if(t){this._properties[A]=t;return}delete this._properties[A]}setNumberProperty(A,t,i){if(t===void 0){delete this._properties[A];return}this._properties[A]=new i(t)}getPropertyInstance(A,t){const i=this._properties[A];return i instanceof t?i:void 0}get stackup(){return this.getPropertyInstance("stackup",E2A)}set stackup(A){if(A!==void 0&&!(A instanceof E2A))throw new Error("stackup must be a Stackup instance");this.setProperty("stackup",A)}get pcbPlotParams(){return this.getPropertyInstance("pcbPlotParams",k1A)}set pcbPlotParams(A){if(A!==void 0&&!(A instanceof k1A))throw new Error("pcbPlotParams must be a PcbPlotParams instance");this.setProperty("pcbPlotParams",A)}get padToMaskClearance(){return this.getPropertyInstance("padToMaskClearance",P1A)?.value}set padToMaskClearance(A){this.setNumberProperty("padToMaskClearance",A,P1A)}get solderMaskMinWidth(){return this.getPropertyInstance("solderMaskMinWidth",K1A)?.value}set solderMaskMinWidth(A){this.setNumberProperty("solderMaskMinWidth",A,K1A)}get padToPasteClearance(){return this.getPropertyInstance("padToPasteClearance",q1A)?.value}set padToPasteClearance(A){this.setNumberProperty("padToPasteClearance",A,q1A)}get padToPasteClearanceRatio(){return this.getPropertyInstance("padToPasteClearanceRatio",O1A)?.value}set padToPasteClearanceRatio(A){this.setNumberProperty("padToPasteClearanceRatio",A,O1A)}get lastTraceWidth(){return this.getPropertyInstance("lastTraceWidth",W1A)?.value}set lastTraceWidth(A){this.setNumberProperty("lastTraceWidth",A,W1A)}get traceClearance(){return this.getPropertyInstance("traceClearance",Z1A)?.value}set traceClearance(A){this.setNumberProperty("traceClearance",A,Z1A)}get zoneClearance(){return this.getPropertyInstance("zoneClearance",V1A)?.value}set zoneClearance(A){this.setNumberProperty("zoneClearance",A,V1A)}get zone45Only(){return this.getPropertyInstance("zone45Only",v1A)?.value}set zone45Only(A){this.setProperty("zone45Only",A===void 0?void 0:new v1A(A))}get traceMin(){return this.getPropertyInstance("traceMin",j1A)?.value}set traceMin(A){this.setNumberProperty("traceMin",A,j1A)}get segmentWidth(){return this.getPropertyInstance("segmentWidth",z1A)?.value}set segmentWidth(A){this.setNumberProperty("segmentWidth",A,z1A)}get edgeWidth(){return this.getPropertyInstance("edgeWidth",X1A)?.value}set edgeWidth(A){this.setNumberProperty("edgeWidth",A,X1A)}get viaSize(){return this.getPropertyInstance("viaSize",$1A)?.value}set viaSize(A){this.setNumberProperty("viaSize",A,$1A)}get viaDrill(){return this.getPropertyInstance("viaDrill",A2A)?.value}set viaDrill(A){this.setNumberProperty("viaDrill",A,A2A)}get viaMinSize(){return this.getPropertyInstance("viaMinSize",t2A)?.value}set viaMinSize(A){this.setNumberProperty("viaMinSize",A,t2A)}get viaMinDrill(){return this.getPropertyInstance("viaMinDrill",e2A)?.value}set viaMinDrill(A){this.setNumberProperty("viaMinDrill",A,e2A)}get uviasAllowed(){return this.getPropertyInstance("uviasAllowed",G1A)?.value}set uviasAllowed(A){this.setProperty("uviasAllowed",A===void 0?void 0:new G1A(A))}get uviaSize(){return this.getPropertyInstance("uviaSize",i2A)?.value}set uviaSize(A){this.setNumberProperty("uviaSize",A,i2A)}get uviaDrill(){return this.getPropertyInstance("uviaDrill",n2A)?.value}set uviaDrill(A){this.setNumberProperty("uviaDrill",A,n2A)}get uviaMinSize(){return this.getPropertyInstance("uviaMinSize",o2A)?.value}set uviaMinSize(A){this.setNumberProperty("uviaMinSize",A,o2A)}get uviaMinDrill(){return this.getPropertyInstance("uviaMinDrill",s2A)?.value}set uviaMinDrill(A){this.setNumberProperty("uviaMinDrill",A,s2A)}get pcbTextWidth(){return this.getPropertyInstance("pcbTextWidth",r2A)?.value}set pcbTextWidth(A){this.setNumberProperty("pcbTextWidth",A,r2A)}get pcbTextSize(){return this.getPropertyInstance("pcbTextSize",N1A)?.values}set pcbTextSize(A){if(A===void 0){delete this._properties.pcbTextSize;return}this.setProperty("pcbTextSize",new N1A(A))}get modEdgeWidth(){return this.getPropertyInstance("modEdgeWidth",a2A)?.value}set modEdgeWidth(A){this.setNumberProperty("modEdgeWidth",A,a2A)}get modTextSize(){return this.getPropertyInstance("modTextSize",L1A)?.values}set modTextSize(A){if(A===void 0){delete this._properties.modTextSize;return}this.setProperty("modTextSize",new L1A(A))}get modTextWidth(){return this.getPropertyInstance("modTextWidth",g2A)?.value}set modTextWidth(A){this.setNumberProperty("modTextWidth",A,g2A)}get padSize(){return this.getPropertyInstance("padSize",U1A)?.values}set padSize(A){if(A===void 0){delete this._properties.padSize;return}this.setProperty("padSize",new U1A(A))}get padDrill(){return this.getPropertyInstance("padDrill",c2A)?.value}set padDrill(A){this.setNumberProperty("padDrill",A,c2A)}get allowSoldermaskBridgesInFootprints(){return this.getPropertyInstance("allowSoldermaskBridgesInFootprints",F1A)?.value}set allowSoldermaskBridgesInFootprints(A){this.setProperty("allowSoldermaskBridgesInFootprints",A===void 0?void 0:new F1A(A))}get tenting(){return this.getPropertyInstance("tenting",R1A)?.sides}set tenting(A){if(A===void 0){delete this._properties.tenting;return}this.setProperty("tenting",new R1A(A))}get auxAxisOrigin(){const A=this.getPropertyInstance("auxAxisOrigin",J1A);if(A)return{x:A.x,y:A.y}}set auxAxisOrigin(A){if(!A){delete this._properties.auxAxisOrigin;return}this.setProperty("auxAxisOrigin",new J1A(A.x,A.y))}get gridOrigin(){const A=this.getPropertyInstance("gridOrigin",T1A);if(A)return{x:A.x,y:A.y}}set gridOrigin(A){if(!A){delete this._properties.gridOrigin;return}this.setProperty("gridOrigin",new T1A(A.x,A.y))}get visibleElements(){return this.getPropertyInstance("visibleElements",M1A)?.value}set visibleElements(A){this.setProperty("visibleElements",A===void 0?void 0:new M1A(A))}get padToPasteClearanceValues(){return this.getPropertyInstance("padToPasteClearanceValues",H1A)?.values}set padToPasteClearanceValues(A){if(A===void 0){delete this._properties.padToPasteClearanceValues;return}this.setProperty("padToPasteClearanceValues",new H1A(A))}get traceWidth(){return this.getPropertyInstance("traceWidth",Y1A)?.values}set traceWidth(A){if(A===void 0){delete this._properties.traceWidth;return}this.setProperty("traceWidth",new Y1A(A))}};LA.register(u2A);var gyt=class extends ha{static token="thickness";static parentToken="general";token="thickness"};LA.register(gyt);var cyt=class yxt extends LA{static token="legacy_teardrops";static parentToken="general";token="legacy_teardrops";_enabled;constructor(A){super(),this._enabled=A}static fromSexprPrimitives(A){const t=Di(A[0]);if(t===void 0)throw new Error("legacy_teardrops expects a string value");const i=/^(yes|true)$/iu.test(t);return new yxt(i)}get enabled(){return this._enabled}set enabled(A){this._enabled=A}getChildren(){return[]}getString(){return`(legacy_teardrops ${this._enabled?"yes":"no"})`}};LA.register(cyt);var Iyt=new Set(["thickness","legacy_teardrops"]),d2A=class mxt extends LA{static token="general";static parentToken="kicad_pcb";token="general";_sxThickness;_sxLegacyTeardrops;static fromSexprPrimitives(A){const t=new mxt,{propertyMap:i,arrayPropertyMap:n}=LA.parsePrimitivesToClassProperties(A,this.token);for(const o of Object.keys(i))if(!Iyt.has(o))throw new Error(`general encountered unsupported child token "${o}"`);for(const[o,s]of Object.entries(n)){if(!Iyt.has(o))throw new Error(`general encountered unsupported child token "${o}"`);if(s.length>1)throw new Error(`general encountered repeated child token "${o}"`)}return t._sxThickness=n.thickness?.[0]??i.thickness,t._sxLegacyTeardrops=n.legacy_teardrops?.[0]??i.legacy_teardrops,t}get thickness(){return this._sxThickness?.value}set thickness(A){this._sxThickness=A===void 0?void 0:new gyt(A)}get legacyTeardrops(){return this._sxLegacyTeardrops?.enabled}set legacyTeardrops(A){if(A===void 0){this._sxLegacyTeardrops=void 0;return}this._sxLegacyTeardrops=new cyt(A)}getChildren(){const A=[];return this._sxThickness&&A.push(this._sxThickness),this._sxLegacyTeardrops&&A.push(this._sxLegacyTeardrops),A}};LA.register(d2A);var Zl=class wxt extends LA{static token="__pcb_layer_definition__";static parentToken="layers";token="__pcb_layer_definition__";_index;_name;_type;_userName;constructor(A){super(),this._index=A.index,this._name=A.name,this._type=A.type,this._userName=A.userName}static fromPrimitive(A){if(!Array.isArray(A)||A.length<3)throw new Error(`layers entry must be an array with at least index, name, and type: ${JSON.stringify(A)}`);const[t,i,n,o]=A,s=Ci(t),r=Di(i),a=Di(n),g=o===void 0?void 0:Di(o);if(s===void 0||r===void 0||a===void 0)throw new Error(`layers entry is missing required values: ${JSON.stringify(A)}`);return new wxt({index:s,name:r,type:a,userName:g})}get index(){return this._index}set index(A){this._index=A}get name(){return this._name}set name(A){this._name=A}get type(){return this._type}set type(A){this._type=A}get userName(){return this._userName}set userName(A){this._userName=A}getChildren(){return[]}getString(){if(this._index===void 0||this._name===void 0||this._type===void 0)return"()";const A=[String(this._index),mn(this._name),this._type];return this._userName!==void 0&&A.push(mn(this._userName)),`(${A.join(" ")})`}};LA.register(Zl);var p2A=class Dxt extends LA{static token="layers";static parentToken="kicad_pcb";token="layers";_definitions=[];static fromSexprPrimitives(A){const t=new Dxt;return t._definitions=A.map(i=>Zl.fromPrimitive(i)),t}get definitions(){return[...this._definitions]}set definitions(A){this._definitions=[...A]}getChildren(){return[...this._definitions]}};LA.register(p2A);var cj=class xxt extends LA{static token="net";static parentToken="kicad_pcb";token="net";_id;_name;constructor(A,t){super(),this._id=A,this._name=t}static fromSexprPrimitives(A){const t=Ci(A[0]),i=Di(A[1]);if(t===void 0||i===void 0)throw new Error("net requires numeric id and string name");return new xxt(t,i)}get id(){return this._id}set id(A){this._id=A}get name(){return this._name}set name(A){this._name=A}getChildren(){return[]}getString(){return`(net ${this._id} ${mn(this._name)})`}};LA.register(cj);var f2A=class extends ha{static token="version";static parentToken="kicad_pcb";token="version"};LA.register(f2A);var TCi=e=>/^[A-Za-z0-9._-]+$/.test(e),y2A=class extends xm{static token="generator";static parentToken="kicad_pcb";token="generator";getString(){return`(generator ${TCi(this.value)?this.value:mn(this.value)})`}};LA.register(y2A);var PCi=e=>/^[A-Za-z0-9._-]+$/.test(e),m2A=class extends xm{static token="generator_version";static parentToken="kicad_pcb";token="generator_version";getString(){return`(generator_version ${PCi(this.value)?this.value:mn(this.value)})`}};LA.register(m2A);var w2A=class Sxt extends LA{static token="net";static parentToken="via";token="net";_id;_name;constructor(A,t){super(),this._id=A,this._name=t}static fromSexprPrimitives(A){const t=Ci(A[0]);if(t===void 0)throw new Error("via net requires a numeric id");const i=A.length>1?Di(A[1]):void 0;return new Sxt(t,i)}get id(){return this._id}set id(A){this._id=A}get name(){return this._name}set name(A){this._name=A}getChildren(){return[]}getString(){return this._name!==void 0?`(net ${this._id} ${mn(this._name)})`:`(net ${this._id})`}};LA.register(w2A);var KCi=new Set(["locked","free","remove_unused_layers","keep_end_layers"]),D2A=class bxt extends LA{static token="via";token="via";_type;_locked=!1;_free=!1;_removeUnusedLayers=!1;_keepEndLayers=!1;_sxAt;_size;_drill;_sxLayers;_sxNet;_sxUuid;_sxTstamp;_sxTeardrops;constructor(A={}){super(),A.type!==void 0&&(this.type=A.type),A.locked!==void 0&&(this.locked=A.locked),A.free!==void 0&&(this.free=A.free),A.removeUnusedLayers!==void 0&&(this.removeUnusedLayers=A.removeUnusedLayers),A.keepEndLayers!==void 0&&(this.keepEndLayers=A.keepEndLayers),A.at!==void 0&&(this.at=A.at),A.size!==void 0&&(this.size=A.size),A.drill!==void 0&&(this.drill=A.drill),A.layers!==void 0&&(this.layers=A.layers),A.net!==void 0&&(this.net=A.net),A.uuid!==void 0&&(this.uuid=A.uuid),A.tstamp!==void 0&&(this.tstamp=A.tstamp),A.teardrops!==void 0&&(this.teardrops=A.teardrops)}static fromSexprPrimitives(A){const t=new bxt;for(const i of A){if(typeof i=="string"){t.consumeBareToken(i);continue}if(!Array.isArray(i)||i.length===0)throw new Error(`via encountered unsupported primitive child: ${JSON.stringify(i)}`);const[n,...o]=i;if(typeof n!="string")throw new Error(`via encountered child with non-string token: ${JSON.stringify(i)}`);t.consumeNode(n,o)}return t}consumeBareToken(A){if(A==="blind"||A==="micro"){this._type=A;return}if(!KCi.has(A))throw new Error(`via encountered unsupported flag "${A}"`);switch(A){case"locked":this._locked=!0;break;case"free":this._free=!0;break;case"remove_unused_layers":this._removeUnusedLayers=!0;break;case"keep_end_layers":this._keepEndLayers=!0;break}}consumeNode(A,t){switch(A){case"type":{const i=Di(t[0]);if(i===void 0)throw new Error("via type expects a string value");this._type=i;return}case"locked":this._locked=this.parseYesNo(t);return;case"free":this._free=this.parseYesNo(t);return;case"remove_unused_layers":this._removeUnusedLayers=this.parseYesNo(t);return;case"keep_end_layers":this._keepEndLayers=this.parseYesNo(t);return;case"at":{const i=LA.parsePrimitiveSexpr(["at",...t],{parentToken:this.token});if(!(i instanceof oc))throw new Error("via failed to parse at child");this._sxAt=i;return}case"size":{const i=Ci(t[0]);if(i===void 0)throw new Error("via size expects a numeric value");this._size=i;return}case"drill":{const i=Ci(t[0]);if(i===void 0)throw new Error("via drill expects a numeric value");this._drill=i;return}case"layers":{this._sxLayers=aj.fromSexprPrimitives(t);return}case"net":{this._sxNet=w2A.fromSexprPrimitives(t);return}case"teardrops":{this._sxTeardrops=Gpt.fromSexprPrimitives(t);return}case"uuid":{const i=Di(t[0]);if(i===void 0)throw new Error("via uuid expects a string value");this._sxUuid=new qi(i);return}case"tstamp":{const i=Di(t[0]);if(i===void 0)throw new Error("via tstamp expects a string value");this._sxTstamp=new sc(i);return}default:throw new Error(`via encountered unsupported child token "${A}"`)}}parseYesNo(A){if(A.length===0)return!0;const t=Di(A[0]);if(t===void 0)throw new Error("Expected string when parsing via boolean child");return/^(yes|true)$/iu.test(t)}get type(){return this._type}set type(A){this._type=A}get locked(){return this._locked}set locked(A){this._locked=A}get free(){return this._free}set free(A){this._free=A}get removeUnusedLayers(){return this._removeUnusedLayers}set removeUnusedLayers(A){this._removeUnusedLayers=A}get keepEndLayers(){return this._keepEndLayers}set keepEndLayers(A){this._keepEndLayers=A}get at(){return this._sxAt}set at(A){this._sxAt=A!==void 0?oc.from(A):void 0}get size(){return this._size}set size(A){this._size=A}get drill(){return this._drill}set drill(A){this._drill=A}get layers(){return this._sxLayers}set layers(A){if(A===void 0){this._sxLayers=void 0;return}this._sxLayers=A instanceof aj?A:new aj(A)}get net(){return this._sxNet}set net(A){this._sxNet=A}get uuid(){return this._sxUuid}set uuid(A){if(A===void 0){this._sxUuid=void 0;return}this._sxUuid=A instanceof qi?A:new qi(A)}get teardrops(){return this._sxTeardrops}set teardrops(A){this._sxTeardrops=A}get tstamp(){return this._sxTstamp}set tstamp(A){if(A===void 0){this._sxTstamp=void 0;return}this._sxTstamp=A instanceof sc?A:new sc(A)}getChildren(){const A=[];return this._sxAt&&A.push(this._sxAt),this._sxLayers&&A.push(this._sxLayers),this._sxNet&&A.push(this._sxNet),this._sxUuid&&A.push(this._sxUuid),this._sxTstamp&&A.push(this._sxTstamp),this._sxTeardrops&&A.push(this._sxTeardrops),A}getString(){const A=["(via"];return this._type!==void 0&&A.push(` (type ${this._type})`),this._locked&&A.push(" (locked)"),this._free&&A.push(" (free)"),this._removeUnusedLayers&&A.push(" (remove_unused_layers)"),this._keepEndLayers&&A.push(" (keep_end_layers)"),this._sxAt&&A.push(this._sxAt.getStringIndented()),this._size!==void 0&&A.push(` (size ${this._size})`),this._drill!==void 0&&A.push(` (drill ${this._drill})`),this._sxLayers&&A.push(this._sxLayers.getStringIndented()),this._sxNet&&A.push(this._sxNet.getStringIndented()),this._sxUuid&&A.push(this._sxUuid.getStringIndented()),this._sxTstamp&&A.push(this._sxTstamp.getStringIndented()),this._sxTeardrops&&A.push(this._sxTeardrops.getStringIndented()),A.push(")"),A.join(`
5829
- `)}};LA.register(D2A);var x2A=class _xt extends LA{static token="kicad_pcb";token="kicad_pcb";_sxVersion;_sxGenerator;_sxGeneratorVersion;_sxGeneral;_sxPaper;_sxTitleBlock;_sxLayers;_sxSetup;_properties=[];_nets=[];_footprints=[];_images=[];_segments=[];_grLines=[];_grTexts=[];_grPolys=[];_grRects=[];_vias=[];_zones=[];_otherChildren=[];constructor(A={}){super(),A.version!==void 0&&(this.version=A.version),A.generator!==void 0&&(this.generator=A.generator),A.generatorVersion!==void 0&&(this.generatorVersion=A.generatorVersion),A.general!==void 0&&(this.general=A.general),A.paper!==void 0&&(this.paper=A.paper),A.titleBlock!==void 0&&(this.titleBlock=A.titleBlock),A.layers!==void 0&&(this.layers=A.layers),A.setup!==void 0&&(this.setup=A.setup),A.properties!==void 0&&(this.properties=A.properties),A.nets!==void 0&&(this.nets=A.nets),A.footprints!==void 0&&(this.footprints=A.footprints),A.images!==void 0&&(this.images=A.images),A.segments!==void 0&&(this.segments=A.segments),A.graphicLines!==void 0&&(this.graphicLines=A.graphicLines),A.graphicTexts!==void 0&&(this.graphicTexts=A.graphicTexts),A.graphicPolys!==void 0&&(this.graphicPolys=A.graphicPolys),A.graphicRects!==void 0&&(this.graphicRects=A.graphicRects),A.vias!==void 0&&(this.vias=A.vias),A.zones!==void 0&&(this.zones=A.zones),A.otherChildren!==void 0&&(this.otherChildren=A.otherChildren)}static fromSexprPrimitives(A){const t=new _xt;for(const i of A){if(!Array.isArray(i)||i.length===0)throw new Error(`kicad_pcb encountered unsupported primitive child: ${JSON.stringify(i)}`);const n=LA.parsePrimitiveSexpr(i,{parentToken:this.token});if(!(n instanceof LA))throw new Error(`kicad_pcb expected SxClass child, received ${JSON.stringify(i)}`);t.consumeChild(n)}return t}consumeChild(A){if(A instanceof f2A){this._sxVersion=A;return}if(A instanceof y2A){this._sxGenerator=A;return}if(A instanceof m2A){this._sxGeneratorVersion=A;return}if(A instanceof d2A){this._sxGeneral=A;return}if(A instanceof OV){this._sxPaper=A;return}if(A instanceof cdt){this._sxTitleBlock=A;return}if(A instanceof p2A){this._sxLayers=A;return}if(A instanceof u2A){this._sxSetup=A;return}if(A instanceof y1){this._properties.push(A);return}if(A instanceof cj){this._nets.push(A);return}if(A instanceof nj){this._footprints.push(A);return}if(A instanceof ldt){this._images.push(A);return}if(A instanceof _1A){this._segments.push(A);return}if(A instanceof oj){this._grLines.push(A);return}if(A instanceof sj){this._grTexts.push(A);return}if(A instanceof tft){this._grPolys.push(A);return}if(A instanceof Xpt){this._grRects.push(A);return}if(A instanceof D2A){this._vias.push(A);return}if(A instanceof rft){this._zones.push(A);return}this._otherChildren.push(A)}get version(){return this._sxVersion?.value}set version(A){this._sxVersion=A===void 0?void 0:new f2A(A)}get generator(){return this._sxGenerator?.value}set generator(A){this._sxGenerator=A===void 0?void 0:new y2A(A)}get generatorVersion(){return this._sxGeneratorVersion?.value}set generatorVersion(A){this._sxGeneratorVersion=A===void 0?void 0:new m2A(A)}get general(){return this._sxGeneral}set general(A){this._sxGeneral=A}get paper(){return this._sxPaper}set paper(A){this._sxPaper=A}get titleBlock(){return this._sxTitleBlock}set titleBlock(A){this._sxTitleBlock=A}get layers(){return this._sxLayers}set layers(A){this._sxLayers=A}get setup(){return this._sxSetup}set setup(A){this._sxSetup=A}get properties(){return[...this._properties]}set properties(A){this._properties=[...A]}get nets(){return[...this._nets]}set nets(A){this._nets=[...A]}get footprints(){return[...this._footprints]}set footprints(A){this._footprints=[...A]}get images(){return[...this._images]}set images(A){this._images=[...A]}get segments(){return[...this._segments]}set segments(A){this._segments=[...A]}get graphicLines(){return[...this._grLines]}set graphicLines(A){this._grLines=[...A]}get graphicTexts(){return[...this._grTexts]}set graphicTexts(A){this._grTexts=[...A]}get graphicPolys(){return[...this._grPolys]}set graphicPolys(A){this._grPolys=[...A]}get graphicRects(){return[...this._grRects]}set graphicRects(A){this._grRects=[...A]}get vias(){return[...this._vias]}set vias(A){this._vias=[...A]}get zones(){return[...this._zones]}set zones(A){this._zones=[...A]}get otherChildren(){return[...this._otherChildren]}set otherChildren(A){this._otherChildren=[...A]}getChildren(){const A=[];return this._sxVersion&&A.push(this._sxVersion),this._sxGenerator&&A.push(this._sxGenerator),this._sxGeneratorVersion&&A.push(this._sxGeneratorVersion),this._sxGeneral&&A.push(this._sxGeneral),this._sxPaper&&A.push(this._sxPaper),this._sxTitleBlock&&A.push(this._sxTitleBlock),this._sxLayers&&A.push(this._sxLayers),this._sxSetup&&A.push(this._sxSetup),A.push(...this._properties),A.push(...this._nets),A.push(...this._footprints),A.push(...this._images),A.push(...this._segments),A.push(...this._grLines),A.push(...this._grTexts),A.push(...this._grPolys),A.push(...this._grRects),A.push(...this._vias),A.push(...this._zones),A.push(...this._otherChildren),A}};LA.register(x2A);var lyt=e=>LA.parse(e),t0=class{MAX_ITERATIONS=1e3;iteration=0;finished=!1;input;ctx;constructor(e,A){this.input=e,this.ctx=A}step(){if(this.iteration++,this.iteration>this.MAX_ITERATIONS)throw new Error("Max iterations reached");this._step()}_step(){throw new Error("Not implemented")}runUntilFinished(){for(;!this.finished;)this.step()}getOutput(){throw new Error("Not implemented")}},qCi=class extends t0{_step(){const{kicadSch:e,schematicPaperSize:A}=this.ctx;if(!e)throw new Error("KicadSch instance not initialized in context");e.version=20250114;const t=new OV;t.size=A?.name??"A4",e.paper=t,e.uuid=new qi(crypto.randomUUID()),this.finished=!0}getOutput(){return this.ctx.kicadSch}};function U3(e,A){if(e.manufacturer_part_number)return S2A(e.manufacturer_part_number);const t=OCi(e.ftype),i=A?.footprinter_string;return S2A(i?`${t}_${i}`:t)}function OCi(e){if(!e)return"component";let A=e.replace(/^simple_/,"");return A||"component"}function S2A(e){return e.replace(/[\\\/:\s]+/g,"_").replace(/_+/g,"_").replace(/^_|_$/g,"").trim()||"component"}function Byt(e){return e?e.match(/^([A-Za-z]+)/)?.[1]?.toUpperCase()??"U":"U"}var Cyt={simple_resistor:"R",simple_capacitor:"C",simple_inductor:"L",simple_diode:"D",simple_led:"D",simple_chip:"U",simple_transistor:"Q",simple_mosfet:"Q",simple_fuse:"F",simple_switch:"SW",simple_push_button:"SW",simple_potentiometer:"RV",simple_crystal:"Y",simple_resonator:"Y",simple_pin_header:"J",simple_pinout:"J",simple_test_point:"TP",simple_battery:"BT"},WCi=/^[A-Za-z]+\d+$/;function Qyt(e){return e?WCi.test(e.trim()):!1}function Ij(e){const A=e?.ftype;if(A&&Cyt[A])return Cyt[A];const t=e?.name;return Qyt(t),Byt(t)}function ZCi(e){const A=e?.name;return Qyt(A)?A.trim():`${Ij(e)}?`}function hyt(e){return e in qQ}function Eyt(e,A,t,i){if(i)return`Custom:${i}`;if(e.type!=="source_component")return A.symbol_name?hyt(A.symbol_name)?`Device:${A.symbol_name}`:`Custom:${A.symbol_name}`:"Device:Component";if(A.symbol_name)return hyt(A.symbol_name)?`Device:${A.symbol_name}`:`Custom:${A.symbol_name}`;const n=U3(e,t);return`Device:${Ij(e)}_${n}`}function VCi(e){const{circuitJson:A,schematicSymbolId:t,schematicSymbol:i,schematicComponentId:n}=e,o=A.filter(Q=>Q.type==="schematic_circle"&&Q.schematic_symbol_id===t),s=A.filter(Q=>Q.type==="schematic_line"&&Q.schematic_symbol_id===t),r=n?A.filter(Q=>Q.type==="schematic_line"&&Q.schematic_component_id===n&&!Q.schematic_symbol_id):[],a=[...s,...r],g=A.filter(Q=>Q.type==="schematic_path"&&Q.schematic_symbol_id===t),c=A.filter(Q=>Q.type==="schematic_text"&&Q.schematic_symbol_id===t);let I=A.filter(Q=>Q.type==="schematic_port"&&"schematic_symbol_id"in Q&&Q.schematic_symbol_id===t);if(I.length===0&&n){const Q=A.filter(E=>E.type==="schematic_port"&&E.schematic_component_id===n&&E.display_pin_label!==void 0),h=new Map;for(const E of Q)E.display_pin_label&&h.set(E.display_pin_label,E);if(I=h.size>0?Array.from(h.values()):Q,I.length===0){const E=A.filter(d=>d.type==="schematic_port"&&d.schematic_component_id===n),u=new Set;I=E.filter(d=>{const f=d.pin_number;if(f!==void 0){if(u.has(f))return!1;u.add(f)}return!0})}}const l=[];for(const Q of o)l.push({type:"circle",x:Q.center?.x??0,y:Q.center?.y??0,radius:Q.radius??.5,fill:Q.is_filled??!1,fillColor:Q.fill_color});for(const Q of a)l.push({type:"path",points:[{x:Q.x1??0,y:Q.y1??0},{x:Q.x2??0,y:Q.y2??0}]});for(const Q of g)Q.points&&Q.points.length>0&&l.push({type:"path",points:Q.points,fill:Q.is_filled??!1,fillColor:Q.fill_color});const B=c.map(Q=>({text:Q.text??"",x:Q.position?.x??0,y:Q.position?.y??0,fontSize:Q.font_size??.2,anchor:Q.anchor??"center"})),C=I.map((Q,h)=>({x:Q.center?.x??0,y:Q.center?.y??0,labels:[Q.display_pin_label||`${Q.pin_number||h+1}`],pinNumber:Q.pin_number||h+1,facingDirection:Q.facing_direction}));return C.sort((Q,h)=>Q.pinNumber-h.pinNumber),{center:i.center||{x:0,y:0},size:i.size||{width:1,height:1},primitives:l,texts:B,ports:C}}function jCi({points:e,transform:A,fillType:t}){const i=new Cdt,n=e.map(a=>{const g=Ct(A,a);return new oh(g.x,g.y)}),o=new oQ(n);i.points=o;const s=new f1;s.width=.254,s.type="default",i.stroke=s;const r=new fdt;return r.type=t,i.fill=r,i}function zCi({primitive:e,transform:A,scale:t}){const i=new wdt,n=Ct(A,{x:e.x,y:e.y}),o=i;o._sxCenter=new ddt(n.x,n.y),o._sxRadius=new pdt(e.radius*t);const s=new f1;s.width=.254,s.type="default",o._sxStroke=s;const r=new ydt;return r.type=e.fill?"background":"none",o._sxFill=r,i}function XCi({schText:e,transform:A,scale:t}){const i=new Ddt,n=Ct(A,{x:e.x,y:e.y});i.value=e.text,i.at=[n.x,n.y,0];const o=e.fontSize*t,s=new Tp;return s.size={height:o,width:o},i.effects=new Jp({font:s}),i}function $Ci({libId:e,symbolData:A,isChip:t,c2kMatSchScale:i}){const n=new NM({libraryId:`${e.split(":")[1]}_0_1`}),o=i,s=A.center?.x??0,r=A.center?.y??0,a=tn(za(o,o),sn(-s,-r));for(const c of A.primitives||[])if(c.type==="path"&&c.points){const I=t||c.fill?"background":"none",l=jCi({points:c.points,transform:a,fillType:I});n.polylines.push(l)}else if(c.type==="circle"){const I=zCi({primitive:c,transform:a,scale:o});n.circles.push(I)}const g=Array.isArray(A.texts)?A.texts:[];for(const c of g){const I=XCi({schText:c,transform:a,scale:o});n.texts.push(I)}return n}function AQi(e,A){const t=A.schematic_port.list().filter(r=>r.schematic_component_id===e.schematic_component_id).sort((r,a)=>(r.pin_number||0)-(a.pin_number||0)),i=e.size?.width||1.5,n=e.size?.height||1,o={type:"path",points:[{x:-i/2,y:-n/2},{x:i/2,y:-n/2},{x:i/2,y:n/2},{x:-i/2,y:n/2},{x:-i/2,y:-n/2}]},s=t.map(r=>{const a=r.center.x-e.center.x,g=r.center.y-e.center.y;return{x:a,y:g,labels:[r.display_pin_label||`${r.pin_number||1}`],pinNumber:r.pin_number||1}});return{center:{x:0,y:0},primitives:[o],ports:s,size:{width:i,height:n}}}function tQi(e,A){const t=new Tp;return t.size={height:e,width:e},new Jp({font:t,hiddenText:A})}function eQi({symbol:e,libId:A,description:t,keywords:i,fpFilters:n,footprintRef:o="",referencePrefix:s}){const r=s||A.split(":")[1]?.[0]||"U",a=[{key:"Reference",value:r,id:0,at:[2.032,0,90],hide:!1},{key:"Value",value:r,id:1,at:[0,0,90],hide:!1},{key:"Footprint",value:o,id:2,at:[-1.778,0,90],hide:!0},{key:"Datasheet",value:"~",id:3,at:[0,0,0],hide:!0},{key:"Description",value:t,id:4,at:[0,0,0],hide:!0},{key:"ki_keywords",value:i,id:5,at:[0,0,0],hide:!0},{key:"ki_fp_filters",value:n,id:6,at:[0,0,0],hide:!0}];for(const g of a)e.properties.push(new Pp({key:g.key,value:g.value,id:g.id,at:g.at,effects:tQi(1.27,g.hide)}))}function iQi({port:e,center:A,size:t,isChip:i,portIndex:n,schematicComponent:o,schematicPorts:s,c2kMatSchScale:r}){const a=r;let g=e.x??0,c=e.y??0,I=!1;if(i&&n!==void 0&&o){const m=s.filter(w=>w.schematic_component_id===o.schematic_component_id).sort((w,D)=>(w.pin_number||0)-(D.pin_number||0));if(m[n]){const w=m[n];g=w.center.x-o.center.x,c=w.center.y-o.center.y,I=!0}}let l,B;if(I)l=g,B=c;else{const m=A?.x??0,w=A?.y??0;l=g-m,B=c-w}const C=za(a,a),Q=Ct(C,{x:l,y:B});let h;if(i&&t){const m=t.width/2,w=t.height/2,D=Math.abs(l)/m,x=Math.abs(B)/w;h=D>x}else h=Math.abs(l)>Math.abs(B);let E=Q.x,u=Q.y;const d=6;if(i&&t){const m=t.width/2*a,w=t.height/2*a;h?(E=l>0?m:-m,u=B*a):(E=l*a,u=B>0?w:-w)}let f=0;return h?l>0?(f=180,i&&(E=E+d)):(f=0,i&&(E=E-d)):B>0?(f=270,i&&(u=u+d)):(f=90,i&&(u=u-d)),{x:E,y:u,angle:f}}function nQi({libId:e,symbolData:A,isChip:t,schematicComponent:i,schematicPorts:n,c2kMatSchScale:o}){const s=new NM({libraryId:`${e.split(":")[1]}_1_1`}),r=6,a=2.54;for(let g=0;g<(A.ports?.length||0);g++){const c=A.ports[g],I=new jV;I.pinElectricalType="passive",I.pinGraphicStyle="line";const{x:l,y:B,angle:C}=iQi({port:c,center:A.center,size:A.size,isChip:t,portIndex:g,schematicComponent:i,schematicPorts:n,c2kMatSchScale:o});I.at=[l,B,C],I.length=t?r:a;const Q=new Tp;Q.size={height:1.27,width:1.27};const h=new Jp({font:Q}),E=c.labels?.[0]||"~";I._sxName=new rDA({value:E,effects:h});const u=new Tp;u.size={height:1.27,width:1.27};const d=new Jp({font:u}),f=c.pinNumber?.toString()||`${g+1}`;I._sxNumber=new Sdt({value:f,effects:d}),s.pins.push(I)}return s}var oQi=class extends t0{processedSymbolNames=new Set;_step(){const{kicadSch:e,db:A}=this.ctx,t=new Gdt,i=[];this.processedSymbolNames=new Set;const n=A.schematic_component.list();for(const s of n){const r=this.createLibrarySymbolForComponent(s);r&&i.push(r)}const o=A.schematic_net_label?.list?.()||[];for(const s of o)if(s.symbol_name){const r=s.source_net_id?A.source_net.get(s.source_net_id)?.is_power:!1,a=s.source_net_id?A.source_net.get(s.source_net_id)?.is_ground:!1;if(r||a){const c=this.createLibrarySymbolForNetLabel({netLabel:s,isPower:r??!1,isGround:a??!1});c&&i.push(c)}}t.symbols=i,e&&(e.libSymbols=t),this.finished=!0}createLibrarySymbolForComponent(e){const{db:A}=this.ctx,t=e.source_component_id?A.source_component.get(e.source_component_id):null;if(!t)return null;const i=A.cad_component?.list()?.find(c=>c.source_component_id===t.source_component_id);let n=e.schematic_symbol_id;if(!n){const c=this.ctx.circuitJson.find(I=>(I.type==="schematic_line"||I.type==="schematic_circle"||I.type==="schematic_path")&&I.schematic_component_id===e.schematic_component_id&&I.schematic_symbol_id);c&&(n=c.schematic_symbol_id)}if(n)return this.createLibrarySymbolFromSchematicSymbol(e,t,i,n);const o=e.symbol_name||(t.ftype==="simple_chip"?`generic_chip_${e.source_component_id}`:null);if(!o)return null;const s=this.getSymbolData(o,e);if(!s)return null;const r=Eyt(t,e,i),a=t.ftype==="simple_chip",g=U3(t,i);return this.createLibrarySymbol({libId:r,symbolData:s,isChip:a,schematicComponent:e,description:this.getDescription(t),keywords:this.getKeywords(t),fpFilters:this.getFpFilters(t),footprintRef:g?`tscircuit:${g}`:"",referencePrefix:Ij(t)})}createLibrarySymbolFromSchematicSymbol(e,A,t,i){const{db:n}=this.ctx,o=this.ctx.circuitJson.find(c=>c.type==="schematic_symbol"&&c.schematic_symbol_id===i);if(!o)return null;let s;if(o.name)s=o.name;else{const c=U3(A,t);c?s=c:s=`custom_${A.ftype||"component"}_${i}`}const r=`Custom:${s}`;if(this.processedSymbolNames.has(r))return null;this.processedSymbolNames.add(r);const a=VCi({circuitJson:this.ctx.circuitJson,schematicSymbolId:i,schematicSymbol:o,schematicComponentId:e.schematic_component_id}),g=U3(A,t);return this.createLibrarySymbol({libId:r,symbolData:a,isChip:!1,schematicComponent:e,description:this.getDescription(A),keywords:this.getKeywords(A),fpFilters:this.getFpFilters(A,o.name),footprintRef:g?`tscircuit:${g}`:"",referencePrefix:Ij(A),symbolScale:1})}createLibrarySymbolForNetLabel({netLabel:e,isPower:A,isGround:t}){const i=e.symbol_name;if(!i)return null;const n=qQ[i];if(!n)return null;const o=`Custom:${i}`;return this.createLibrarySymbol({libId:o,symbolData:n,isChip:!1,schematicComponent:void 0,description:A?"Power net label":t?"Ground net label":"Net symbol",keywords:A?"power net":t?"ground net":"net",fpFilters:"",referencePrefix:o.split(":")[1]?.[0]||"U"})}getSymbolData(e,A){return e.startsWith("generic_chip_")?AQi(A,this.ctx.db):qQ[e]||null}createLibrarySymbol({libId:e,symbolData:A,isChip:t,schematicComponent:i,description:n,keywords:o,fpFilters:s,footprintRef:r="",referencePrefix:a,symbolScale:g}){const I=g??this.ctx.c2kMatSch?.a??15,l=new NM({libraryId:e,excludeFromSim:!1,inBom:!0,onBoard:!0}),B=new nDA;B.hide=!t,l._sxPinNumbers=B;const C=new sDA;C.offset=t?1.27:0,l._sxPinNames=C,eQi({symbol:l,libId:e,description:n,keywords:o,fpFilters:s,footprintRef:r,referencePrefix:a});const Q=$Ci({libId:e,symbolData:A,isChip:t,c2kMatSchScale:I});l.subSymbols.push(Q);const h=nQi({libId:e,symbolData:A,isChip:t,schematicComponent:i,schematicPorts:this.ctx.db.schematic_port.list(),c2kMatSchScale:I});return l.subSymbols.push(h),l._sxEmbeddedFonts=new GM(!1),l}getDescription(e){return e?.ftype==="simple_resistor"?"Resistor":e?.ftype==="simple_capacitor"?"Capacitor":e?.ftype==="simple_chip"?"Integrated Circuit":"Component"}getKeywords(e){return e?.ftype==="simple_resistor"?"R res resistor":e?.ftype==="simple_capacitor"?"C cap capacitor":e?.ftype==="simple_chip"?"U IC chip":""}getFpFilters(e,A){return A?`${A}*`:e?.ftype==="simple_resistor"?"R_*":e?.ftype==="simple_capacitor"?"C_*":(e?.ftype==="simple_chip","*")}getOutput(){if(!this.ctx.kicadSch)throw new Error("kicadSch is not initialized");return this.ctx.kicadSch}},sQi=class extends t0{_step(){const{kicadSch:e,db:A}=this.ctx,t=A.schematic_component.list();if(t.length===0){this.finished=!0;return}const i=[];for(const n of t){const o=n.source_component_id?A.source_component.get(n.source_component_id):null;if(!o||!this.ctx.c2kMatSch)continue;const{x:s,y:r}=Ct(this.ctx.c2kMatSch,{x:n.center.x,y:n.center.y}),a=crypto.randomUUID(),g=new NM({at:[s,r,0],unit:1,excludeFromSim:!1,inBom:!0,onBoard:!0,dnp:!1,uuid:a,fieldsAutoplaced:!0}),c=A.cad_component?.list()?.find(oA=>oA.source_component_id===o.source_component_id);let I,l=n.schematic_symbol_id;if(!l){const oA=this.ctx.circuitJson.find(rA=>(rA.type==="schematic_line"||rA.type==="schematic_circle"||rA.type==="schematic_path")&&rA.schematic_component_id===n.schematic_component_id&&rA.schematic_symbol_id);oA&&(l=oA.schematic_symbol_id)}if(l){const oA=this.ctx.circuitJson.find(rA=>rA.type==="schematic_symbol"&&rA.schematic_symbol_id===l);if(oA?.name)I=oA.name;else{const rA=U3(o,c);rA?I=rA:I=`custom_${o.ftype||"component"}_${l}`}}const B=Eyt(o,n,c,I),C=new eDA(B);g._sxLibId=C;const{reference:Q,value:h,description:E}=this.getComponentMetadata(o),{refTextPos:u,valTextPos:d}=this.getTextPositions(n,{x:s,y:r});let f;if(l){const oA=this.ctx.circuitJson.find(rA=>rA.type==="schematic_symbol"&&rA.schematic_symbol_id===l);oA&&oA.type==="schematic_symbol"&&(f=oA.metadata?.kicad_symbol)}const m=f?.properties?.Reference,w=new Pp({key:"Reference",value:m?.value??Q,id:0,at:[u.x,u.y,0],effects:this.createTextEffects(Number(m?.effects?.font?.size?.x??1.27),m?.effects?.hide??!1)}),D=o.ftype==="simple_chip",x=f?.properties?.Value,_=new Pp({key:"Value",value:x?.value??h,id:1,at:[d.x,d.y,0],effects:this.createTextEffects(Number(x?.effects?.font?.size?.x??1.27),x?.effects?.hide??D)}),b=f?.properties?.Footprint,R=new Pp({key:"Footprint",value:b?.value??"",id:2,at:[s-1.778,r,90],effects:this.createTextEffects(1.27,b?.effects?.hide??!0)}),F=f?.properties?.Datasheet,H=new Pp({key:"Datasheet",value:F?.value??"~",id:3,at:[s,r,0],effects:this.createTextEffects(1.27,F?.effects?.hide??!0)}),Y=f?.properties?.Description,J=new Pp({key:"Description",value:Y?.value??E,id:4,at:[s,r,0],effects:this.createTextEffects(1.27,Y?.effects?.hide??!0)});g.properties.push(w,_,R,H,J);const O=f?.properties?.ki_keywords;if(O?.value){const oA=new Pp({key:"ki_keywords",value:O.value,id:5,at:[s,r,0],effects:this.createTextEffects(1.27,O.effects?.hide??!0)});g.properties.push(oA)}const W=f?.properties?.ki_fp_filters;if(W?.value){const oA=new Pp({key:"ki_fp_filters",value:W.value,id:6,at:[s,r,0],effects:this.createTextEffects(1.27,W.effects?.hide??!0)});g.properties.push(oA)}if(f){if(f.inBom!==void 0&&(g.inBom=f.inBom),f.onBoard!==void 0&&(g.onBoard=f.onBoard),f.excludeFromSim!==void 0&&(g.excludeFromSim=f.excludeFromSim),f.pinNames){const oA=new sDA;f.pinNames.offset!==void 0&&(oA.offset=Number(f.pinNames.offset)),f.pinNames.hide!==void 0&&(oA.hide=f.pinNames.hide),g.pinNames=oA}if(f.pinNumbers){const oA=new nDA;f.pinNumbers.hide!==void 0&&(oA.hide=f.pinNumbers.hide),g.pinNumbers=oA}f.embeddedFonts!==void 0&&(g._sxEmbeddedFonts=new GM(f.embeddedFonts))}let z=A.schematic_port.list().filter(oA=>oA.schematic_component_id===n.schematic_component_id);if(l){const oA=z.filter(rA=>rA.display_pin_label);oA.length>0&&(z=oA)}z.sort((oA,rA)=>(oA.pin_number||0)-(rA.pin_number||0));for(let oA=0;oA<z.length;oA++){const rA=z[oA];if(!rA)continue;const lA=new jV;lA.numberString=`${rA.pin_number||oA+1}`,lA.uuid=crypto.randomUUID(),g.pins.push(lA)}const tA=new aDA,aA=new cDA(""),eA=new IDA(`/${e?.uuid?.value||""}`);eA.reference=Q,eA.unit=1,aA.paths.push(eA),tA.projects.push(aA),g._sxInstances=tA,i.push(g)}e&&(e.symbols=i),this.finished=!0}getTextPositions(e,A){const i=(this.ctx.db.schematic_text?.list?.()?.filter(B=>B.schematic_component_id===e.schematic_component_id)||[]).find(B=>B.text&&B.text.length>0);if(i&&this.ctx.c2kMatSch){const B=Ct(this.ctx.c2kMatSch,{x:i.position.x,y:i.position.y}),C={x:A.x,y:A.y+6};return{refTextPos:B,valTextPos:C}}const n=e.symbol_name,o=qQ[n];if(!o)return{refTextPos:{x:A.x,y:A.y-6},valTextPos:{x:A.x,y:A.y+6}};let s=null,r=null;for(const B of o.primitives)B.type==="text"&&(B.text==="{REF}"?s=B:B.text==="{VAL}"&&(r=B));const a=o.center||{x:0,y:0},c=n.includes("_down")||n.includes("_up")?.15:0,I=s&&this.ctx.c2kMatSch?Ct(this.ctx.c2kMatSch,{x:e.center.x+(s.x-a.x)+c,y:e.center.y+(s.y-a.y)}):{x:A.x,y:A.y-6},l=r&&this.ctx.c2kMatSch?Ct(this.ctx.c2kMatSch,{x:e.center.x+(r.x-a.x)+c,y:e.center.y+(r.y-a.y)}):{x:A.x,y:A.y+6};return{refTextPos:I,valTextPos:l}}getComponentMetadata(e){const A=e.name||"?",t=ZCi(e);return e.ftype==="simple_resistor"?{reference:t,value:e.display_resistance||"R",description:"Resistor"}:e.ftype==="simple_capacitor"?{reference:t,value:e.display_capacitance||"C",description:"Capacitor"}:e.ftype==="simple_inductor"?{reference:t,value:e.display_inductance||"L",description:"Inductor"}:e.ftype==="simple_diode"?{reference:t,value:"D",description:"Diode"}:e.ftype==="simple_chip"?{reference:t,value:A,description:"Integrated Circuit"}:e.ftype==="simple_led"?{reference:t,value:e.manufacturer_part_number||"",description:"LED"}:e.ftype==="simple_switch"?{reference:t,value:e.manufacturer_part_number||"",description:"Switch"}:e.ftype==="simple_potentiometer"?{reference:t,value:e.display_max_resistance||"",description:"Potentiometer"}:{reference:t,value:A,description:"Component"}}createTextEffects(e,A=!1,t){const i=new Tp;i.size={height:e,width:e};const n=t?new a6({horizontal:t}):void 0;return new Jp({font:i,hiddenText:A,justify:n})}getOutput(){if(!this.ctx.kicadSch)throw new Error("kicadSch is not initialized");return this.ctx.kicadSch}},rQi=class extends t0{_step(){const{kicadSch:e,db:A}=this.ctx,t=A.schematic_net_label?.list?.()||[];if(t.length===0){this.finished=!0;return}if(!this.ctx.c2kMatSch){this.finished=!0;return}const i=[],n=[];for(const o of t){const s=o.text||"",r=o.symbol_name;if(r){const a=this.createSymbolFromNetLabel(o,s,r);a&&i.push(a)}else{const a=this.createGlobalLabel(o,s);a&&n.push(a)}}if(e&&i.length>0){const o=e.symbols||[];e.symbols=[...o,...i]}e&&n.length>0&&(e.globalLabels=[...e.globalLabels||[],...n]),this.finished=!0}createSymbolFromNetLabel(e,A,t){if(!this.ctx.c2kMatSch)return null;const{x:i,y:n}=Ct(this.ctx.c2kMatSch,{x:e.anchor_position?.x??e.center?.x??0,y:e.anchor_position?.y??e.center?.y??0}),o=crypto.randomUUID(),s=new NM({at:[i,n,0],unit:1,excludeFromSim:!1,inBom:!0,onBoard:!0,dnp:!1,uuid:o,fieldsAutoplaced:!0}),r=`Custom:${t}`,a=new eDA(r);s._sxLibId=a;const g=t.includes("_up")||t.toLowerCase().includes("vcc"),c=g?-4:4,I=g?-6:6,l=new Pp({key:"Reference",value:A,id:0,at:[i,n+c,0],effects:this.createTextEffects(1.27,!1)}),B=new Pp({key:"Value",value:A,id:1,at:[i,n+I,0],effects:this.createTextEffects(1.27,!0)}),C=new Pp({key:"Footprint",value:"",id:2,at:[i-1.778,n,90],effects:this.createTextEffects(1.27,!0)}),Q=new Pp({key:"Datasheet",value:"~",id:3,at:[i,n,0],effects:this.createTextEffects(1.27,!0)}),h=new Pp({key:"Description",value:`Power/Net symbol: ${A}`,id:4,at:[i,n,0],effects:this.createTextEffects(1.27,!0)});s.properties.push(l,B,C,Q,h);const E=new jV;E.numberString="1",E.uuid=crypto.randomUUID(),s.pins.push(E);const{kicadSch:u}=this.ctx,d=new aDA,f=new cDA(""),m=new IDA(`/${u?.uuid?.value||""}`);return m.reference=A,m.unit=1,f.paths.push(m),d.projects.push(f),s._sxInstances=d,s}createGlobalLabel(e,A){if(!this.ctx.c2kMatSch||!this.ctx.kicadSch)return null;const{x:t,y:i}=Ct(this.ctx.c2kMatSch,{x:e.anchor_position?.x??e.center?.x??0,y:e.anchor_position?.y??e.center?.y??0}),n=e.anchor_side||"left",s={left:0,right:180,top:270,bottom:90}[n]||0,a={left:{horizontal:"left"},right:{horizontal:"right"},top:{vertical:"top"},bottom:{vertical:"bottom"}}[n]||{},g=this.createTextEffects(1.27,!1);return Object.keys(a).length>0&&(g.justify=new a6(a)),new Pdt({value:A,at:[t,i,s],effects:g,uuid:crypto.randomUUID(),fieldsAutoplaced:!0})}createTextEffects(e,A=!1){const t=new Tp;return t.size={height:e,width:e},new Jp({font:t,hiddenText:A})}getOutput(){if(!this.ctx.kicadSch)throw new Error("kicadSch is not initialized");return this.ctx.kicadSch}},aQi=class extends t0{_step(){const{kicadSch:e,db:A}=this.ctx;if(!e)throw new Error("KicadSch instance not initialized in context");const t=A.schematic_trace.list();if(t.length===0){this.finished=!0;return}const i=[],n=[];for(const o of t){for(const s of o.edges){const r=this.createWireFromEdge(s);i.push(r)}for(const s of o.junctions){const r=this.createJunction(s);n.push(r)}}e.wires=i,e.junctions=n,this.finished=!0}createWireFromEdge(e){const A=new Ndt;if(!this.ctx.c2kMatSch)throw new Error("Schematic transformation matrix not initialized in context");const t=Ct(this.ctx.c2kMatSch,{x:e.from.x,y:e.from.y}),i=Ct(this.ctx.c2kMatSch,{x:e.to.x,y:e.to.y}),n=t.x,o=t.y,s=i.x,r=i.y,a=new oQ([new oh(n,o),new oh(s,r)]);A.points=a;const g=new f1;return g.width=0,g.type="default",A.stroke=g,A.uuid=crypto.randomUUID(),A}createJunction(e){if(!this.ctx.c2kMatSch)throw new Error("Schematic transformation matrix not initialized in context");const{x:A,y:t}=Ct(this.ctx.c2kMatSch,{x:e.x,y:e.y}),i=new Ldt({at:[A,t],diameter:0});return i.uuid=crypto.randomUUID(),i}getOutput(){return this.ctx.kicadSch}},gQi=class extends t0{_step(){const{kicadSch:e}=this.ctx;if(!e)throw new Error("KicadSch instance not initialized in context");const A=new QDA,t=new Odt;t.value="/";const i=new Wdt("1");t.pages=[i],A.paths=[t],e.sheetInstances=A,e.embeddedFonts=new GM(!1),this.finished=!0}getOutput(){return this.ctx.kicadSch}};function cQi(e){const A=e.schematic_component.list(),t=e.schematic_trace.list();let i=1/0,n=1/0,o=-1/0,s=-1/0;for(const g of A){const c=g.size?.width??0,I=g.size?.height??0;i=Math.min(i,g.center.x-c/2),n=Math.min(n,g.center.y-I/2),o=Math.max(o,g.center.x+c/2),s=Math.max(s,g.center.y+I/2)}for(const g of t)for(const c of g.edges)i=Math.min(i,c.from.x,c.to.x),n=Math.min(n,c.from.y,c.to.y),o=Math.max(o,c.from.x,c.to.x),s=Math.max(s,c.from.y,c.to.y);i===1/0&&(i=0,n=0,o=0,s=0);const r=(i+o)/2,a=(n+s)/2;return{center:{x:r,y:a},bounds:{minX:i,minY:n,maxX:o,maxY:s}}}var lj=[{name:"A4",width:297,height:210},{name:"A3",width:420,height:297},{name:"A2",width:594,height:420},{name:"A1",width:841,height:594},{name:"A0",width:1189,height:841}];function IQi(e,A,t=20){const i=e+2*t,n=A+2*t;for(let o=0;o<lj.length;o++){const s=lj[o];if(i<=s.width&&n<=s.height)return s}return lj[lj.length-1]}var uyt=class{ctx;pipeline;currentStageIndex=0;finished=!1;get currentStage(){return this.pipeline[this.currentStageIndex]}constructor(e){const t=Na(e),{center:i,bounds:n}=cQi(t),o=(n.maxX-n.minX)*15,s=(n.maxY-n.minY)*15,r=IQi(o,s),a=r.width/2,g=r.height/2;this.ctx={db:t,circuitJson:e,kicadSch:new EDA({generator:"circuit-json-to-kicad",generatorVersion:"0.0.1"}),schematicPaperSize:r,c2kMatSch:tn(sn(a,g),za(15,-15),sn(-i.x,-i.y))},this.pipeline=[new qCi(e,this.ctx),new oQi(e,this.ctx),new sQi(e,this.ctx),new rQi(e,this.ctx),new aQi(e,this.ctx),new gQi(e,this.ctx)]}step(){if(!this.currentStage){this.finished=!0;return}this.currentStage.step(),this.currentStage.finished&&this.currentStageIndex++}runUntilFinished(){for(;!this.finished;)this.step()}getOutput(){return this.ctx.kicadSch}getOutputString(){return this.ctx.kicadSch.getString()}},lQi=class extends t0{_step(){const{kicadPcb:e,db:A}=this.ctx;if(!e)throw new Error("KicadPcb instance not initialized in context");const i=A.pcb_board?.list()?.[0]?.num_layers??2;this.ctx.numLayers=i,e.version=20241229;const n=new OV;n.size="A4",e.paper=n;const o=new d2A;o.thickness=1.6,e.general=o;const s=new u2A;s.padToMaskClearance=0,e.setup=s;const r=new p2A,a=[new Zl({index:0,name:"F.Cu",type:"signal"})];for(let g=1;g<i-1;g++)a.push(new Zl({index:g,name:`In${g}.Cu`,type:"signal"}));a.push(new Zl({index:31,name:"B.Cu",type:"signal"})),a.push(new Zl({index:32,name:"B.Adhes",type:"user"}),new Zl({index:33,name:"F.Adhes",type:"user"}),new Zl({index:34,name:"B.Paste",type:"user"}),new Zl({index:35,name:"F.Paste",type:"user"}),new Zl({index:36,name:"B.SilkS",type:"user"}),new Zl({index:37,name:"F.SilkS",type:"user"}),new Zl({index:38,name:"B.Mask",type:"user"}),new Zl({index:39,name:"F.Mask",type:"user"}),new Zl({index:40,name:"Dwgs.User",type:"user"}),new Zl({index:41,name:"Cmts.User",type:"user"}),new Zl({index:42,name:"Eco1.User",type:"user"}),new Zl({index:43,name:"Eco2.User",type:"user"}),new Zl({index:44,name:"Edge.Cuts",type:"user"}),new Zl({index:45,name:"Margin",type:"user"}),new Zl({index:46,name:"B.CrtYd",type:"user"}),new Zl({index:47,name:"F.CrtYd",type:"user"}),new Zl({index:48,name:"B.Fab",type:"user"}),new Zl({index:49,name:"F.Fab",type:"user"})),r.definitions=a,e.layers=r,this.finished=!0}getOutput(){return this.ctx.kicadPcb}},BQi=class extends t0{_step(){const{kicadPcb:e}=this.ctx;if(!e)throw new Error("KicadPcb instance not initialized in context");this.ctx.pcbNetMap=new Map;const A=new Map,t=this.ctx.db.source_net?.list()??[];for(const r of t){const a=r.subcircuit_connectivity_map_key||r.source_net_id;if(!a)continue;const g=r.name||r.source_net_id||"",c=g&&g.trim().length>0?g:a;A.set(a,c)}const i=this.ctx.db.source_trace?.list()??[];for(const r of i){let a=r.subcircuit_connectivity_map_key;if(!a&&r.connected_source_net_ids?.length)for(const g of r.connected_source_net_ids){const c=this.ctx.db.source_net?.get(g);if(c?.subcircuit_connectivity_map_key&&c.subcircuit_connectivity_map_key.length>0){a=c.subcircuit_connectivity_map_key;break}}if(a&&!A.has(a)){const g=r.display_name||r.source_trace_id||"",c=g&&g.trim().length>0?g:a;A.set(a,c)}}const n=Array.from(A.entries()).sort((r,a)=>r[0].localeCompare(a[0])),o=[];o.push(new cj(0,""));let s=1;for(const[r,a]of n){const g=new cj(s,a);o.push(g);const c={id:s,name:a};this.ctx.pcbNetMap.set(r,c),s++}e.nets=o,this.finished=!0}getOutput(){return this.ctx.kicadPcb}};function CQi(e){let A=0;for(let i=0;i<e.length;i++){const n=e.charCodeAt(i);A=(A<<5)-A+n,A=A&A}let t="";for(let i=0;i<4;i++){let n=A;for(let o=0;o<e.length;o++)n=(n<<5)-n+e.charCodeAt(o)+i*31,n=n&n;t+=Math.abs(n).toString(16).padStart(8,"0")}return t}function cd(e){const A=CQi(e);return`${A.slice(0,8)}-${A.slice(8,12)}-${A.slice(12,16)}-${A.slice(16,20)}-${A.slice(20,32)}`}var dyt="https://modelcdn.tscircuit.com/jscad_models",QQi=20240108,hQi="pcbnew",EQi="8.0";function b2A(e){const A=e.split(/[/\\]/),t=A[A.length-1]||e;return t.split("?")[0]||t}var uQi=class extends t0{classifyFootprints(){const e=new Set,A=new Map,t=this.ctx.db.cad_component?.list()??[],i=this.ctx.db.source_component;for(const n of t){const o=n.source_component_id?i?.get(n.source_component_id):null;if(!o)continue;const s=U3(o,n);if(n.footprinter_string)A.set(s,n.footprinter_string);else{e.add(s);const r=this.ctx.circuitJson.find(a=>a.type==="pcb_component"&&a.source_component_id===n.source_component_id);r&&r.type==="pcb_component"&&r.metadata?.kicad_footprint?.footprintName&&e.add(r.metadata.kicad_footprint.footprintName)}}return{customFootprintNames:e,footprinterStrings:A}}_step(){const e=this.ctx.kicadPcbString,A=this.ctx.fpLibraryName??"tscircuit";if(!e)throw new Error("PCB content not available. Run GenerateKicadSchAndPcbStage first.");const{customFootprintNames:t,footprinterStrings:i}=this.classifyFootprints(),n=new Map;try{const s=lyt(e).find(a=>a instanceof x2A);if(!s){this.ctx.footprintEntries=[],this.finished=!0;return}const r=s.footprints??[];for(const a of r){const g=this.sanitizeFootprint({footprint:a,fpLibraryName:A,customFootprintNames:t,footprinterStrings:i});n.has(g.footprintName)||n.set(g.footprintName,g)}}catch(o){console.warn("Failed to parse PCB for footprint extraction:",o)}this.ctx.footprintEntries=Array.from(n.values()),this.finished=!0}sanitizeFootprint({footprint:e,fpLibraryName:A,customFootprintNames:t,footprinterStrings:i}){const o=(e.libraryLink??"footprint").split(":"),s=(o.length>1?o[1]:o[0])?.replace(/[\\\/]/g,"-").trim()||"footprint",r=!t.has(s);if(e.libraryLink=s,e.position=oc.from([0,0,0]),e.locked=!1,e.placed=!1,e.version=QQi,e.generator=hQi,e.generatorVersion=EQi,e.descr||(e.descr=""),e.tags||(e.tags=""),e.embeddedFonts||(e.embeddedFonts=new GM(!1)),!e.attr){const f=new uDA,m=(e.fpPads??[]).map(w=>w.padType);m.some(w=>w.includes("thru_hole"))?f.type="through_hole":m.some(w=>w.includes("smd"))&&(f.type="smd"),e.attr=f}e.uuid=void 0,e.path=void 0,e.sheetfile=void 0,e.sheetname=void 0;const a=new Tp;a.size={width:1.27,height:1.27},a.thickness=.15;const g=new Jp({font:a}),c=e.fpPads??[];let I=0,l=0;for(const f of c){const m=f.at,w=f.size;if(m&&w){const D=m.y??0,x=w.height??0,_=D-x/2,b=D+x/2;I=Math.min(I,_),l=Math.max(l,b)}}const B=I-.5,C=l+.5;e.properties=[new y1({key:"Reference",value:"REF**",position:[0,B,0],layer:"F.SilkS",uuid:cd(`${s}-property-Reference`),effects:g}),new y1({key:"Value",value:"Val**",position:[0,C,0],layer:"F.Fab",uuid:cd(`${s}-property-Value`),effects:g}),new y1({key:"Datasheet",value:"",position:[0,0,0],layer:"F.Fab",hidden:!0,uuid:cd(`${s}-property-Datasheet`),effects:g}),new y1({key:"Description",value:"",position:[0,0,0],layer:"F.Fab",hidden:!0,uuid:cd(`${s}-property-Description`),effects:g})];const Q=e.fpTexts??[];for(const f of Q)f.uuid=void 0,f.type==="reference"?f.text="REF**":f.type==="value"&&f.text.trim().length===0&&(f.text=s);e.fpTexts=Q;const h=e.fpPads??[];for(let f=0;f<h.length;f++){const m=h[f];m&&(m.uuid=cd(`${s}-pad-${m.number??f}`),m.net=void 0)}e.fpPads=h;const E=e.models??[],u=[],d=[];for(const f of E)if(f.path){const m=b2A(f.path),x=`../../3dmodels/${f.path.startsWith("http://modelcdn.tscircuit.com")||f.path.startsWith("https://modelcdn.tscircuit.com")?"tscircuit_builtin":A}.3dshapes/${m}`,_=new L3(x);f.offset&&(_.offset=f.offset),f.scale&&(_.scale=f.scale),f.rotate&&(_.rotate=f.rotate),u.push(_),d.push(f.path.split("?")[0]??f.path)}if(u.length===0){const f=i.get(s);if(f){const m=`${dyt}/${f}.step`,D=`../../3dmodels/tscircuit_builtin.3dshapes/${b2A(m)}`;u.push(new L3(D)),d.push(m)}}return e.models=u,{footprintName:s,kicadModString:e.getString(),model3dSourcePaths:d,isBuiltin:r}}getOutput(){return this.ctx.libraryOutput}};function Bj(e){const A=new Tp;return e?.font?.size?A.size={width:Number(e.font.size.x),height:Number(e.font.size.y)}:A.size={width:1.27,height:1.27},e?.font?.thickness!==void 0?A.thickness=Number(e.font.thickness):A.thickness=.15,new Jp({font:A})}function dQi(e,A,t){if(A.properties){const i=[],n=A.properties.Reference;i.push(new y1({key:"Reference",value:n?.value??t,position:n?.at?[Number(n.at.x),Number(n.at.y),Number(n.at.rotation??0)]:[0,-3,0],layer:n?.layer??"F.SilkS",uuid:cd(`${t}-property-Reference`),effects:Bj(n?.effects),hidden:n?.hide}));const o=A.properties.Value,s=o?.value??A.footprintName??"";i.push(new y1({key:"Value",value:s,position:o?.at?[Number(o.at.x),Number(o.at.y),Number(o.at.rotation??0)]:[0,3,0],layer:o?.layer??"F.Fab",uuid:cd(`${t}-property-Value`),effects:Bj(o?.effects),hidden:o?.hide}));const r=A.properties.Datasheet;i.push(new y1({key:"Datasheet",value:r?.value??"",position:r?.at?[Number(r.at.x),Number(r.at.y),Number(r.at.rotation??0)]:[0,0,0],layer:r?.layer??"F.Fab",uuid:cd(`${t}-property-Datasheet`),effects:Bj(r?.effects),hidden:r?.hide??!0}));const a=A.properties.Description;i.push(new y1({key:"Description",value:a?.value??"",position:a?.at?[Number(a.at.x),Number(a.at.y),Number(a.at.rotation??0)]:[0,0,0],layer:a?.layer??"F.Fab",uuid:cd(`${t}-property-Description`),effects:Bj(a?.effects),hidden:a?.hide??!0})),e.properties=i}if(A.attributes&&(e.attr||(e.attr=new uDA),A.attributes.through_hole?e.attr.type="through_hole":A.attributes.smd&&(e.attr.type="smd"),A.attributes.exclude_from_pos_files!==void 0&&(e.attr.excludeFromPosFiles=A.attributes.exclude_from_pos_files),A.attributes.exclude_from_bom!==void 0&&(e.attr.excludeFromBom=A.attributes.exclude_from_bom)),A.footprintName&&(e.libraryLink=A.footprintName),A.layer&&(e.layer=A.layer),A.embeddedFonts!==void 0&&(e.embeddedFonts=new GM(A.embeddedFonts)),A.model){const i=new L3(A.model.path);A.model.offset&&(i.offset={x:Number(A.model.offset.x),y:Number(A.model.offset.y),z:Number(A.model.offset.z)}),A.model.scale&&(i.scale={x:Number(A.model.scale.x),y:Number(A.model.scale.y),z:Number(A.model.scale.z)}),A.model.rotate&&(i.rotate={x:Number(A.model.rotate.x),y:Number(A.model.rotate.y),z:Number(A.model.rotate.z)});const n=e.models||[];e.models=[i,...n]}}function pQi(e,A){const t=[];for(const i of e){const n=i.center.x-A.x,o=-(i.center.y-A.y),r={top:"F.SilkS",bottom:"B.SilkS"}[i.layer]||i.layer||"F.SilkS",a=new t1A({center:{x:n,y:o},end:{x:n+i.radius,y:o},layer:r,stroke:new f1,fill:!1});a.stroke&&(a.stroke.width=i.stroke_width||.05,a.stroke.type="default"),t.push(a)}return t}function fQi(e,A){const t=[];for(const i of e){const n=i.center.x-A.x,o=-(i.center.y-A.y),r={top:"F.CrtYd",bottom:"B.CrtYd"}[i.layer]||"F.CrtYd",a=new t1A({center:{x:n,y:o},end:{x:n+i.radius,y:o},layer:r,stroke:new f1,fill:!1});a.stroke&&(a.stroke.width=.05,a.stroke.type="default"),t.push(a)}return t}function yQi(e,A){const t=[];for(const i of e){const n=i.center.x-A.x,o=-(i.center.y-A.y),s=i.width/2,r=i.height/2,g={top:"F.Fab",bottom:"B.Fab"}[i.layer]||i.layer||"F.Fab",c=new Aj({start:{x:n-s,y:o-r},end:{x:n+s,y:o+r},layer:g,stroke:new f1,fill:!1});c.stroke&&(c.stroke.width=i.stroke_width||.1,c.stroke.type="default"),t.push(c)}return t}function mQi(e,A){const t=[];for(const i of e){const n=i.center.x-A.x,o=-(i.center.y-A.y),s=i.width/2,r=i.height/2,a="F.Fab",g=new Aj({start:{x:n-s,y:o-r},end:{x:n+s,y:o+r},layer:a,stroke:new f1,fill:!1});g.stroke&&(g.stroke.width=i.stroke_width||.1,g.stroke.type="default"),t.push(g)}return t}function wQi(e,A){const t=[];for(const i of e){const n=i.center.x-A.x,o=-(i.center.y-A.y),s=i.width/2,r=i.height/2,g={top:"F.CrtYd",bottom:"B.CrtYd"}[i.layer]||"F.CrtYd",c=new Aj({start:{x:n-s,y:o-r},end:{x:n+s,y:o+r},layer:g,stroke:new f1,fill:!1});c.stroke&&(c.stroke.width=.05,c.stroke.type="default"),t.push(c)}return t}function DQi(e,A){const t=[];for(const i of e){if(!i.outline||i.outline.length<2)continue;const o={top:"F.CrtYd",bottom:"B.CrtYd"}[i.layer]||"F.CrtYd",s=i.outline.map(g=>{const c=g.x-A.x,I=-(g.y-A.y);return new oh(c,I)}),r=new Hpt;r.points=new oQ(s),r.layer=o,r.fill=!1;const a=new f1;a.width=.05,a.type="default",r.stroke=a,t.push(r)}return t}function xQi({textElement:e,componentCenter:A,componentRotation:t=0}){if(!e.text||!e.anchor_position)return null;const i=e.anchor_position.x-A.x,n=-(e.anchor_position.y-A.y),o=t!==0?Jl(t*Math.PI/180):Sa(),s=Ct(o,{x:i,y:n}),r={x:s.x,y:s.y},g={top:"F.SilkS",bottom:"B.SilkS"}[e.layer]||e.layer||"F.SilkS",c=(e.font_size||1)/1.5,I=new Tp;I.size={width:c,height:c};const l=new Jp({font:I}),B=e.ccw_rotation||0;return new qDA({type:"user",text:e.text,position:{x:r.x,y:r.y,angle:B},layer:g,effects:l})}function SQi(e,A,t,i){const n=[];for(const o of e){const s=xQi({textElement:o,componentCenter:A,componentRotation:t});s&&(i&&o.text===i&&(s.type="reference"),n.push(s))}return n}function bQi(e,A,t){const i=[];for(const n of e){const o=n.anchor_position.x-A.x,s=-(n.anchor_position.y-A.y),r=t!==0?Jl(t*Math.PI/180):Sa(),a=Ct(r,{x:o,y:s}),g=n.font_size||1,c=new Tp;c.size={width:g,height:g};const I=new Jp({font:c}),l=new qDA({type:"user",text:n.text,position:{x:a.x,y:a.y,angle:0},layer:"F.Fab",effects:I});i.push(l)}return i}function _Qi(e,A,t){const i=[],n=e.model_step_url||e.model_wrl_url;if(!n)return i;const o=new L3(n);if(e.position){const s=t?.boardLayerZOffset??0;o.offset={x:(e.position.x||0)-A.x,y:(e.position.y||0)-A.y,z:(e.position.z||0)-s}}if(e.rotation&&(o.rotate={x:e.rotation.x||0,y:e.rotation.y||0,z:e.rotation.z||0}),e.model_unit_to_mm_scale_factor){const s=e.model_unit_to_mm_scale_factor;o.scale={x:s,y:s,z:s}}return i.push(o),i}function kQi({pcbPad:e,componentCenter:A,padNumber:t,componentRotation:i=0,netInfo:n,componentId:o}){let s,r;if("x"in e&&"y"in e)s=e.x,r=e.y;else if("points"in e&&Array.isArray(e.points)){const u=e.points;s=u.reduce((d,f)=>d+f.x,0)/u.length,r=u.reduce((d,f)=>d+f.y,0)/u.length}else throw new Error("Pad must have either x/y coordinates or points array");const a=tn(i!==0?Jl(i*Math.PI/180):{a:1,b:0,c:0,d:1,e:0,f:0},za(1,-1),sn(-A.x,-A.y)),g=Ct(a,{x:s,y:r}),I={top:"F.Cu",bottom:"B.Cu"}[e.layer]||"F.Cu";let l,B,C,Q;if(e.shape==="circle")l="circle",B=["radius"in e?e.radius*2:.5,"radius"in e?e.radius*2:.5];else if(e.shape==="polygon"&&"points"in e){const u=e.points,d=tn(za(1,-1),sn(-s,-r)),f=u.map(w=>{const D=Ct(d,{x:w.x,y:w.y});return new oh(D.x,D.y)}),m=new YDA;m.contours=[new oQ(f)],m.width=0,m.filled=!0,Q=new ypt,Q.addGraphic(m),l="custom",C=new opt,C.anchor="circle",B=[.2,.2]}else l="rect",B=["width"in e?e.width:.5,"height"in e?e.height:.5];const h=`pad:${o}:${t}:${g.x},${g.y}`,E=new $V({number:String(t),padType:"smd",shape:l,at:[g.x,g.y,0],size:B,layers:[`${I}`,`${I==="F.Cu"?"F":"B"}.Paste`,`${I==="F.Cu"?"F":"B"}.Mask`],uuid:cd(h)});return C&&(E.options=C),Q&&(E.primitives=Q),n&&(E.net=new GDA(n.id,n.name)),E}function vQi(e,A,t,i,n,o){const s=[];let r=n;for(const a of e){const g=o(a.pcb_port_id),c=kQi({pcbPad:a,componentCenter:A,padNumber:r,componentRotation:t,netInfo:g,componentId:i});s.push(c),r++}return{pads:s,nextPadNumber:r}}function FQi({platedHole:e,componentCenter:A,padNumber:t,componentRotation:i=0,netInfo:n,componentId:o}){if(!("x"in e&&"y"in e))return null;const s=e.x-A.x,r=-(e.y-A.y),a=i!==0?Jl(i*Math.PI/180):Sa(),g=Ct(a,{x:s,y:r});let c="circle",I,l,B=0;const C="hole_offset_x"in e||"hole_offset_y"in e;let Q;if(C){const u={x:e.hole_offset_x??0,y:e.hole_offset_y??0};(u.x!==0||u.y!==0)&&(Q=Ct(a,{x:-u.x,y:u.y}))}e.shape==="circle"?(c="circle",I=[e.outer_diameter,e.outer_diameter],l=new m1({diameter:e.hole_diameter,offset:Q})):e.shape==="pill"||e.shape==="oval"?(c="oval",I=[e.outer_width,e.outer_height],l=new m1({oval:!0,diameter:e.hole_width,width:e.hole_height,offset:Q})):e.shape==="pill_hole_with_rect_pad"?(c="rect",I=[e.rect_pad_width,e.rect_pad_height],l=new m1({oval:!0,diameter:e.hole_width,width:e.hole_height,offset:Q})):e.shape==="circular_hole_with_rect_pad"?(c="rect",I=[e.rect_pad_width,e.rect_pad_height],l=new m1({diameter:e.hole_diameter,offset:Q})):e.shape==="rotated_pill_hole_with_rect_pad"?(c="rect",I=[e.rect_pad_width,e.rect_pad_height],l=new m1({oval:!0,diameter:e.hole_width,width:e.hole_height,offset:Q}),B=e.rect_ccw_rotation||0):(c="circle",I=[1.6,1.6],l=new m1({diameter:.8,offset:Q}));const h=`thruhole:${o}:${t}:${g.x},${g.y}`,E=new $V({number:String(t),padType:"thru_hole",shape:c,at:[g.x,g.y,B],size:I,drill:l,layers:["*.Cu","*.Mask"],removeUnusedLayers:!1,uuid:cd(h)});return n&&(E.net=new GDA(n.id,n.name)),E}function MQi(e,A,t,i,n,o){const s=[];let r=n;for(const a of e){const g=o(a.pcb_port_id),c=FQi({platedHole:a,componentCenter:A,padNumber:r,componentRotation:t,netInfo:g,componentId:i});c&&(s.push(c),r++)}return{pads:s,nextPadNumber:r}}function GQi({pcbHole:e,componentCenter:A,componentRotation:t=0}){if(!("x"in e&&"y"in e))return null;const i=e.x-A.x,n=-(e.y-A.y),o=t!==0?Jl(t*Math.PI/180):Sa(),s=Ct(o,{x:i,y:n});let r="circle",a,g;if(e.hole_shape==="circle"){r="circle";const c=e.hole_diameter;a=[c,c],g=new m1({diameter:c})}else if(e.hole_shape==="oval"){r="oval";const c=e.hole_width,I=e.hole_height;a=[c,I],g=new m1({oval:!0,diameter:c,width:I})}else{r="circle";const c="hole_diameter"in e?e.hole_diameter:1;a=[c,c],g=new m1({diameter:c})}return new $V({number:"",padType:"np_thru_hole",shape:r,at:[s.x,s.y,0],size:a,drill:g,layers:["*.Cu","*.Mask"],removeUnusedLayers:!1,uuid:crypto.randomUUID()})}function pyt(e,A,t){const i=[];for(const n of e){const o=GQi({pcbHole:n,componentCenter:A,componentRotation:t});o&&i.push(o)}return i}var RQi=class extends t0{componentsProcessed=0;pcbComponents=[];includeBuiltin3dModels;getNetInfoForPcbPort(e){if(!e)return;const A=this.ctx.db.pcb_port?.get(e);if(!A)return;const t=A.source_port_id;if(!t)return;const i=this.ctx.db.source_port?.get(t);if(!i)return;const n=i.subcircuit_connectivity_map_key;if(n)return this.ctx.pcbNetMap?.get(n)}getCadComponentForPcbComponent(e){return(this.ctx.db.cad_component?.list()||[]).find(t=>t.pcb_component_id===e)}constructor(e,A,t){super(e,A),this.pcbComponents=this.ctx.db.pcb_component.list(),this.includeBuiltin3dModels=t?.includeBuiltin3dModels??!1}_step(){const{kicadPcb:e,c2kMatPcb:A}=this.ctx;if(!e)throw new Error("KicadPcb instance not initialized in context");if(!A)throw new Error("PCB transformation matrix not initialized in context");if(this.componentsProcessed>=this.pcbComponents.length){this.finished=!0;return}const t=this.pcbComponents[this.componentsProcessed],i=t.source_component_id?this.ctx.db.source_component.get(t.source_component_id):null,n=this.getCadComponentForPcbComponent(t.pcb_component_id),o=i?U3(i,n):"Unknown",s=Ct(A,{x:t.center.x,y:t.center.y}),r=`footprint:${t.pcb_component_id}:${s.x},${s.y}`,a=new nj({libraryLink:`tscircuit:${o}`,layer:"F.Cu",at:[s.x,s.y,t.rotation||0],uuid:cd(r)}),g=a.fpTexts,c=this.ctx.db.pcb_silkscreen_text?.list().filter(O=>O.pcb_component_id===t.pcb_component_id)||[];g.push(...SQi(c,t.center,t.rotation||0,i?.name));const I=this.ctx.db.pcb_note_text?.list().filter(O=>O.pcb_component_id===t.pcb_component_id)||[];g.push(...bQi(I,t.center,t.rotation||0)),a.fpTexts=g;const l=a.fpPads,B=O=>this.getNetInfoForPcbPort(O),C=this.ctx.db.pcb_smtpad?.list().filter(O=>O.pcb_component_id===t.pcb_component_id)||[],{pads:Q,nextPadNumber:h}=vQi(C,t.center,t.rotation||0,t.pcb_component_id,1,B);l.push(...Q);const E=this.ctx.db.pcb_plated_hole?.list().filter(O=>O.pcb_component_id===t.pcb_component_id)||[],{pads:u}=MQi(E,t.center,t.rotation||0,t.pcb_component_id,h,B);l.push(...u);const d=this.ctx.db.pcb_hole?.list().filter(O=>O.pcb_component_id===t.pcb_component_id)||[],f=pyt(d,t.center,t.rotation||0);l.push(...f),a.fpPads=l;const m=this.ctx.db.pcb_silkscreen_circle?.list().filter(O=>O.pcb_component_id===t.pcb_component_id)||[],w=a.fpCircles??[];w.push(...pQi(m,t.center));const D=this.ctx.db.pcb_courtyard_circle?.list().filter(O=>O.pcb_component_id===t.pcb_component_id)||[];w.push(...fQi(D,t.center)),a.fpCircles=w;const x=this.ctx.db.pcb_fabrication_note_rect?.list().filter(O=>O.pcb_component_id===t.pcb_component_id)||[],_=a.fpRects??[];_.push(...yQi(x,t.center));const b=this.ctx.db.pcb_note_rect?.list().filter(O=>O.pcb_component_id===t.pcb_component_id)||[];_.push(...mQi(b,t.center));const R=this.ctx.db.pcb_courtyard_rect?.list().filter(O=>O.pcb_component_id===t.pcb_component_id)||[];_.push(...wQi(R,t.center)),a.fpRects=_;const F=this.ctx.db.pcb_courtyard_outline?.list().filter(O=>O.pcb_component_id===t.pcb_component_id)||[],H=DQi(F,t.center);if(H.length>0&&(a.fpPolys=H),n){const W=this.ctx.db.pcb_board?.list()[0]?.thickness??0,z=t.layer==="bottom"?-(W/2):W/2,tA=_Qi(n,t.center,{boardLayerZOffset:z}),aA="${KIPRJMOD}/3dmodels";if(tA.length>0)this.includeBuiltin3dModels?a.models=tA.map(eA=>{if(!eA.path)return eA;const oA=b2A(eA.path),lA=eA.path.startsWith("http://modelcdn.tscircuit.com")||eA.path.startsWith("https://modelcdn.tscircuit.com")?"tscircuit_builtin":this.ctx.projectName??oA.replace(/\.[^.]+$/,""),pA=new L3(`${aA}/${lA}.3dshapes/${oA}`);eA.offset&&(pA.offset=eA.offset),eA.scale&&(pA.scale=eA.scale),eA.rotate&&(pA.rotate=eA.rotate);const kA=eA.path?.split("?")[0];return kA&&!this.ctx.pcbModel3dSourcePaths?.includes(kA)&&this.ctx.pcbModel3dSourcePaths?.push(kA),pA}):a.models=tA;else if(n.footprinter_string&&this.includeBuiltin3dModels){const{footprinter_string:eA}=n,oA=`${aA}/tscircuit_builtin.3dshapes/${eA}.step`;a.models=[new L3(oA)];const rA=`${dyt}/${eA}.step`;this.ctx.pcbModel3dSourcePaths?.includes(rA)||this.ctx.pcbModel3dSourcePaths?.push(rA)}}const Y=t.metadata?.kicad_footprint;Y&&i?.name&&dQi(a,Y,i.name);const J=e.footprints;J.push(a),e.footprints=J,this.componentsProcessed++}getOutput(){return this.ctx.kicadPcb}},NQi={top:"F.Cu",bottom:"B.Cu",inner1:"In1.Cu",inner2:"In2.Cu",inner3:"In3.Cu",inner4:"In4.Cu",inner5:"In5.Cu",inner6:"In6.Cu"};function LQi(e){return e&&(NQi[e]||e)||"F.Cu"}function UQi(e){const A=["F.Cu"];for(let t=1;t<e-1;t++)A.push(`In${t}.Cu`);return A.push("B.Cu"),A}var HQi=class extends t0{tracesProcessed=0;pcbTraces=[];constructor(e,A){super(e,A),this.pcbTraces=this.ctx.db.pcb_trace.list()}_step(){const{kicadPcb:e,c2kMatPcb:A,pcbNetMap:t}=this.ctx;if(!e)throw new Error("KicadPcb instance not initialized in context");if(!A)throw new Error("PCB transformation matrix not initialized in context");if(this.tracesProcessed>=this.pcbTraces.length){this.finished=!0;return}const i=this.pcbTraces[this.tracesProcessed];if(!i.route||i.route.length<2){this.tracesProcessed++;return}let n=i.route[0]?.layer;for(let o=0;o<i.route.length-1;o++){const s=i.route[o],r=i.route[o+1],a=Ct(A,{x:s.x,y:s.y}),g=Ct(A,{x:r.x,y:r.y});let c;if(t){let h=i.subcircuit_connectivity_map_key;if(!h&&i.source_trace_id){const E=this.ctx.db.source_trace?.get(i.source_trace_id);if(E&&(h=E.subcircuit_connectivity_map_key,!h&&E.connected_source_net_ids?.length))for(const u of E.connected_source_net_ids){const d=this.ctx.db.source_net?.get(u);if(d?.subcircuit_connectivity_map_key){h=d.subcircuit_connectivity_map_key;break}}}if(!h&&typeof i.connection_name=="string"){const E=this.ctx.db.source_net?.get(i.connection_name);E?.subcircuit_connectivity_map_key&&(h=E.subcircuit_connectivity_map_key)}h&&(c=t.get(h))}const I=s.layer??r.layer??n,l=LQi(I),B=`segment:${a.x},${a.y}:${g.x},${g.y}:${l}:${c?.id??0}`,C=new _1A({start:{x:a.x,y:a.y},end:{x:g.x,y:g.y},layer:l,width:i.width||.25,net:new rj(c?.id??0),uuid:cd(B)}),Q=e.segments;Q.push(C),e.segments=Q,s.layer&&(n=s.layer),r.layer&&(n=r.layer)}this.tracesProcessed++}getOutput(){return this.ctx.kicadPcb}},YQi=class extends t0{viasProcessed=0;pcbVias=[];constructor(e,A){super(e,A),this.pcbVias=this.ctx.db.pcb_via?.list()||[]}_step(){const{kicadPcb:e,c2kMatPcb:A,pcbNetMap:t}=this.ctx;if(!e)throw new Error("KicadPcb instance not initialized in context");if(!A)throw new Error("PCB transformation matrix not initialized in context");if(this.viasProcessed>=this.pcbVias.length){this.finished=!0;return}const i=this.pcbVias[this.viasProcessed],n=Ct(A,{x:i.x,y:i.y});let o;if(t){let I=i.subcircuit_connectivity_map_key;if(!I&&i.pcb_trace_id){const l=this.ctx.db.pcb_trace?.get(i.pcb_trace_id);if(l&&("subcircuit_connectivity_map_key"in l&&(I=l.subcircuit_connectivity_map_key),!I&&l.source_trace_id)){const B=this.ctx.db.source_trace?.get(l.source_trace_id);if(B&&("subcircuit_connectivity_map_key"in B&&(I=B.subcircuit_connectivity_map_key),!I&&B.connected_source_net_ids?.length))for(const C of B.connected_source_net_ids){const Q=this.ctx.db.source_net?.get(C);if(Q?.subcircuit_connectivity_map_key){I=Q.subcircuit_connectivity_map_key;break}}}}if(!I&&i.connection_name){const l=this.ctx.db.source_net?.get(i.connection_name);l?.subcircuit_connectivity_map_key&&(I=l.subcircuit_connectivity_map_key)}I&&(o=t.get(I))}const s=this.ctx.numLayers??2,r=i.layers?i.layers.map(I=>I==="top"?"F.Cu":I==="bottom"?"B.Cu":`In${I.replace("inner","")}.Cu`):UQi(s),a=`via:${n.x},${n.y}:${i.outer_diameter||.8}:${i.hole_diameter||.4}:${o?.id??0}`,g=new D2A({at:[n.x,n.y],size:i.outer_diameter||.8,drill:i.hole_diameter||.4,layers:r,net:new w2A(o?.id??0),uuid:cd(a)}),c=e.vias;c.push(g),e.vias=c,this.viasProcessed++}getOutput(){return this.ctx.kicadPcb}},JQi=class extends t0{holesProcessed=0;standaloneHoles=[];constructor(e,A){super(e,A),this.standaloneHoles=this.ctx.db.pcb_hole.list().filter(t=>!t.pcb_component_id)}_step(){const{kicadPcb:e,c2kMatPcb:A}=this.ctx;if(!e)throw new Error("KicadPcb instance not initialized in context");if(!A)throw new Error("PCB transformation matrix not initialized in context");if(this.holesProcessed>=this.standaloneHoles.length){this.finished=!0;return}const t=this.standaloneHoles[this.holesProcessed];if(!t){this.holesProcessed++;return}const i=Ct(A,{x:0,y:0}),n=`standalone_hole:${t.pcb_hole_id}:${t.x},${t.y}`,o=new nj({libraryLink:"tscircuit:MountingHole",layer:"F.Cu",at:[i.x,i.y,0],uuid:cd(n)}),r=pyt([t],{x:0,y:0},0);if(r.length>0){o.fpPads=r;const a=e.footprints;a.push(o),e.footprints=a}this.holesProcessed++}getOutput(){return this.ctx.kicadPcb}};function TQi({textElement:e,c2kMatPcb:A}){if(!e.text||!e.anchor_position)return null;const t=Ct(A,{x:e.anchor_position.x,y:e.anchor_position.y}),n={top:"F.Fab",bottom:"B.Fab"}[e.layer]||e.layer||"F.Fab",o=(e.font_size||1)/1.5,s=new Tp;s.size={width:o,height:o};const r=new a6,a=e.anchor_alignment||"center";switch(a){case"top_left":r.horizontal="left",r.vertical="top";break;case"top_right":r.horizontal="right",r.vertical="top";break;case"bottom_left":r.horizontal="left",r.vertical="bottom";break;case"bottom_right":r.horizontal="right",r.vertical="bottom";break}const g=new Jp({font:s});a!=="center"&&(g.justify=r);const c=new oc([t.x,t.y,0]),I=new sj({text:e.text,layer:n,effects:g});return I.position=c,I}function PQi({textElement:e,c2kMatPcb:A}){if(!e.text||!e.anchor_position)return null;const t=Ct(A,{x:e.anchor_position.x,y:e.anchor_position.y}),n={top:"F.SilkS",bottom:"B.SilkS"}[e.layer]||e.layer||"F.SilkS",o=(e.font_size||1)/1.5,s=new Tp;s.size={width:o,height:o};const r=new a6,a=e.anchor_alignment||"center";switch(a){case"top_left":r.horizontal="left",r.vertical="top";break;case"top_right":r.horizontal="right",r.vertical="top";break;case"bottom_left":r.horizontal="left",r.vertical="bottom";break;case"bottom_right":r.horizontal="right",r.vertical="bottom";break}const g=new Jp({font:s});a!=="center"&&(g.justify=r);const c=e.ccw_rotation||0,I=new oc([t.x,t.y,c]),l=new sj({text:e.text,layer:n,effects:g});return l.position=I,l}var KQi=class extends t0{_step(){const{kicadPcb:e,c2kMatPcb:A}=this.ctx;if(!e)throw new Error("KicadPcb instance not initialized in context");if(!A)throw new Error("PCB transformation matrix not initialized in context");const t=this.ctx.db.pcb_silkscreen_path?.list()||[];for(const s of t)if(!(!s.route||s.route.length<2))for(let r=0;r<s.route.length-1;r++){const a=s.route[r],g=s.route[r+1];if(!a||!g)continue;const c=Ct(A,{x:a.x,y:a.y}),I=Ct(A,{x:g.x,y:g.y}),B={top:"F.SilkS",bottom:"B.SilkS"}[s.layer]||s.layer||"F.SilkS",C=new oj({start:{x:c.x,y:c.y},end:{x:I.x,y:I.y},layer:B,width:s.stroke_width||.15}),Q=e.graphicLines;Q.push(C),e.graphicLines=Q}const i=this.ctx.db.pcb_silkscreen_text?.list().filter(s=>!s.pcb_component_id)||[];for(const s of i){const r=PQi({textElement:s,c2kMatPcb:A});if(r){const a=e.graphicTexts;a.push(r),e.graphicTexts=a}}const n=this.ctx.db.pcb_fabrication_note_text?.list()||[];for(const s of n){const r=TQi({textElement:s,c2kMatPcb:A});if(r){const a=e.graphicTexts;a.push(r),e.graphicTexts=a}}const o=this.ctx.db.pcb_board?.list()||[];if(o.length>0){const s=o[0];if(!s){this.finished=!0;return}let r;if(s.outline&&s.outline.length>0)r=s.outline;else{const g=s.width?s.width/2:0,c=s.height?s.height/2:0;r=[{x:s.center.x-g,y:s.center.y-c},{x:s.center.x+g,y:s.center.y-c},{x:s.center.x+g,y:s.center.y+c},{x:s.center.x-g,y:s.center.y+c}]}const a=r.map(g=>Ct(A,g));for(let g=0;g<a.length;g++){const c=a[g],I=a[(g+1)%a.length];if(!c||!I)continue;const l=new oj({start:{x:c.x,y:c.y},end:{x:I.x,y:I.y},layer:"Edge.Cuts",width:.1}),B=e.graphicLines;B.push(l),e.graphicLines=B}}this.finished=!0}getOutput(){return this.ctx.kicadPcb}},fyt=class{ctx;pipeline;currentStageIndex=0;finished=!1;get currentStage(){return this.pipeline[this.currentStageIndex]}constructor(e,A){this.ctx={db:Na(e),circuitJson:e,kicadPcb:new x2A({generator:"circuit-json-to-kicad",generatorVersion:"0.0.1"}),c2kMatPcb:tn(sn(100,100),za(1,-1)),projectName:A?.projectName,pcbModel3dSourcePaths:[]},this.pipeline=[new lQi(e,this.ctx),new BQi(e,this.ctx),new RQi(e,this.ctx,{includeBuiltin3dModels:A?.includeBuiltin3dModels}),new HQi(e,this.ctx),new YQi(e,this.ctx),new JQi(e,this.ctx),new KQi(e,this.ctx)]}step(){if(!this.currentStage){this.finished=!0;return}this.currentStage.step(),this.currentStage.finished&&this.currentStageIndex++}runUntilFinished(){for(;!this.finished;)this.step()}getOutput(){return this.ctx.kicadPcb}getOutputString(){return this.ctx.kicadPcb.getString()}getModel3dSourcePaths(){return this.ctx.pcbModel3dSourcePaths??[]}},qQi=class{ctx;project;constructor(e,A={}){const t=A.projectName??e?.project?.name??"circuit-json-project",i=A.schematicFilename??`${t}.kicad_sch`,n=A.pcbFilename??`${t}.kicad_pcb`,o=new Date().toISOString();this.ctx={db:Na(e),circuitJson:e},this.project={version:1,head:{generator:"circuit-json-to-kicad",generator_version:"0.0.1",project_name:t,created:o,modified:o},meta:{version:1},text_variables:{},libraries:{pinned_symbol_libs:[],pinned_footprint_libs:[]},boards:[],cvpcb:{meta:{version:0}},erc:{meta:{version:0},erc_exclusions:[]},net_settings:{meta:{version:1},last_net_id:0,classes:[]},pcbnew:{page_layout_descr_file:"",last_paths:{}},schematic:{meta:{version:1},page_layout_descr_file:"",last_opened_files:[i]},board:{meta:{version:1},last_opened_board:n},sheets:[[Math.random().toString(36).substring(2,15),"Root"]]}}runUntilFinished(){}getOutput(){return this.project}getOutputString(){return`${JSON.stringify(this.project,null,2)}
5829
+ `)}};LA.register(D2A);var x2A=class _xt extends LA{static token="kicad_pcb";token="kicad_pcb";_sxVersion;_sxGenerator;_sxGeneratorVersion;_sxGeneral;_sxPaper;_sxTitleBlock;_sxLayers;_sxSetup;_properties=[];_nets=[];_footprints=[];_images=[];_segments=[];_grLines=[];_grTexts=[];_grPolys=[];_grRects=[];_vias=[];_zones=[];_otherChildren=[];constructor(A={}){super(),A.version!==void 0&&(this.version=A.version),A.generator!==void 0&&(this.generator=A.generator),A.generatorVersion!==void 0&&(this.generatorVersion=A.generatorVersion),A.general!==void 0&&(this.general=A.general),A.paper!==void 0&&(this.paper=A.paper),A.titleBlock!==void 0&&(this.titleBlock=A.titleBlock),A.layers!==void 0&&(this.layers=A.layers),A.setup!==void 0&&(this.setup=A.setup),A.properties!==void 0&&(this.properties=A.properties),A.nets!==void 0&&(this.nets=A.nets),A.footprints!==void 0&&(this.footprints=A.footprints),A.images!==void 0&&(this.images=A.images),A.segments!==void 0&&(this.segments=A.segments),A.graphicLines!==void 0&&(this.graphicLines=A.graphicLines),A.graphicTexts!==void 0&&(this.graphicTexts=A.graphicTexts),A.graphicPolys!==void 0&&(this.graphicPolys=A.graphicPolys),A.graphicRects!==void 0&&(this.graphicRects=A.graphicRects),A.vias!==void 0&&(this.vias=A.vias),A.zones!==void 0&&(this.zones=A.zones),A.otherChildren!==void 0&&(this.otherChildren=A.otherChildren)}static fromSexprPrimitives(A){const t=new _xt;for(const i of A){if(!Array.isArray(i)||i.length===0)throw new Error(`kicad_pcb encountered unsupported primitive child: ${JSON.stringify(i)}`);const n=LA.parsePrimitiveSexpr(i,{parentToken:this.token});if(!(n instanceof LA))throw new Error(`kicad_pcb expected SxClass child, received ${JSON.stringify(i)}`);t.consumeChild(n)}return t}consumeChild(A){if(A instanceof f2A){this._sxVersion=A;return}if(A instanceof y2A){this._sxGenerator=A;return}if(A instanceof m2A){this._sxGeneratorVersion=A;return}if(A instanceof d2A){this._sxGeneral=A;return}if(A instanceof OV){this._sxPaper=A;return}if(A instanceof cdt){this._sxTitleBlock=A;return}if(A instanceof p2A){this._sxLayers=A;return}if(A instanceof u2A){this._sxSetup=A;return}if(A instanceof y1){this._properties.push(A);return}if(A instanceof cj){this._nets.push(A);return}if(A instanceof nj){this._footprints.push(A);return}if(A instanceof ldt){this._images.push(A);return}if(A instanceof _1A){this._segments.push(A);return}if(A instanceof oj){this._grLines.push(A);return}if(A instanceof sj){this._grTexts.push(A);return}if(A instanceof tft){this._grPolys.push(A);return}if(A instanceof Xpt){this._grRects.push(A);return}if(A instanceof D2A){this._vias.push(A);return}if(A instanceof rft){this._zones.push(A);return}this._otherChildren.push(A)}get version(){return this._sxVersion?.value}set version(A){this._sxVersion=A===void 0?void 0:new f2A(A)}get generator(){return this._sxGenerator?.value}set generator(A){this._sxGenerator=A===void 0?void 0:new y2A(A)}get generatorVersion(){return this._sxGeneratorVersion?.value}set generatorVersion(A){this._sxGeneratorVersion=A===void 0?void 0:new m2A(A)}get general(){return this._sxGeneral}set general(A){this._sxGeneral=A}get paper(){return this._sxPaper}set paper(A){this._sxPaper=A}get titleBlock(){return this._sxTitleBlock}set titleBlock(A){this._sxTitleBlock=A}get layers(){return this._sxLayers}set layers(A){this._sxLayers=A}get setup(){return this._sxSetup}set setup(A){this._sxSetup=A}get properties(){return[...this._properties]}set properties(A){this._properties=[...A]}get nets(){return[...this._nets]}set nets(A){this._nets=[...A]}get footprints(){return[...this._footprints]}set footprints(A){this._footprints=[...A]}get images(){return[...this._images]}set images(A){this._images=[...A]}get segments(){return[...this._segments]}set segments(A){this._segments=[...A]}get graphicLines(){return[...this._grLines]}set graphicLines(A){this._grLines=[...A]}get graphicTexts(){return[...this._grTexts]}set graphicTexts(A){this._grTexts=[...A]}get graphicPolys(){return[...this._grPolys]}set graphicPolys(A){this._grPolys=[...A]}get graphicRects(){return[...this._grRects]}set graphicRects(A){this._grRects=[...A]}get vias(){return[...this._vias]}set vias(A){this._vias=[...A]}get zones(){return[...this._zones]}set zones(A){this._zones=[...A]}get otherChildren(){return[...this._otherChildren]}set otherChildren(A){this._otherChildren=[...A]}getChildren(){const A=[];return this._sxVersion&&A.push(this._sxVersion),this._sxGenerator&&A.push(this._sxGenerator),this._sxGeneratorVersion&&A.push(this._sxGeneratorVersion),this._sxGeneral&&A.push(this._sxGeneral),this._sxPaper&&A.push(this._sxPaper),this._sxTitleBlock&&A.push(this._sxTitleBlock),this._sxLayers&&A.push(this._sxLayers),this._sxSetup&&A.push(this._sxSetup),A.push(...this._properties),A.push(...this._nets),A.push(...this._footprints),A.push(...this._images),A.push(...this._segments),A.push(...this._grLines),A.push(...this._grTexts),A.push(...this._grPolys),A.push(...this._grRects),A.push(...this._vias),A.push(...this._zones),A.push(...this._otherChildren),A}};LA.register(x2A);var lyt=e=>LA.parse(e),t0=class{MAX_ITERATIONS=1e3;iteration=0;finished=!1;input;ctx;constructor(e,A){this.input=e,this.ctx=A}step(){if(this.iteration++,this.iteration>this.MAX_ITERATIONS)throw new Error("Max iterations reached");this._step()}_step(){throw new Error("Not implemented")}runUntilFinished(){for(;!this.finished;)this.step()}getOutput(){throw new Error("Not implemented")}},qCi=class extends t0{_step(){const{kicadSch:e,schematicPaperSize:A}=this.ctx;if(!e)throw new Error("KicadSch instance not initialized in context");e.version=20250114;const t=new OV;t.size=A?.name??"A4",e.paper=t,e.uuid=new qi(crypto.randomUUID()),this.finished=!0}getOutput(){return this.ctx.kicadSch}};function U3(e,A){if(e.manufacturer_part_number)return S2A(e.manufacturer_part_number);const t=OCi(e.ftype),i=A?.footprinter_string;return S2A(i?`${t}_${i}`:t)}function OCi(e){if(!e)return"component";let A=e.replace(/^simple_/,"");return A||"component"}function S2A(e){return e.replace(/[\\\/:\s]+/g,"_").replace(/_+/g,"_").replace(/^_|_$/g,"").trim()||"component"}function Byt(e){return e?e.match(/^([A-Za-z]+)/)?.[1]?.toUpperCase()??"U":"U"}var Cyt={simple_resistor:"R",simple_capacitor:"C",simple_inductor:"L",simple_diode:"D",simple_led:"D",simple_chip:"U",simple_transistor:"Q",simple_mosfet:"Q",simple_fuse:"F",simple_switch:"SW",simple_push_button:"SW",simple_potentiometer:"RV",simple_crystal:"Y",simple_resonator:"Y",simple_pin_header:"J",simple_pinout:"J",simple_test_point:"TP",simple_battery:"BT"},WCi=/^[A-Za-z]+\d+$/;function Qyt(e){return e?WCi.test(e.trim()):!1}function Ij(e){const A=e?.ftype;if(A&&Cyt[A])return Cyt[A];const t=e?.name;return Qyt(t),Byt(t)}function ZCi(e){const A=e?.name;return Qyt(A)?A.trim():`${Ij(e)}?`}function hyt(e){return e in qQ}function Eyt(e,A,t,i){if(i)return`Custom:${i}`;if(e.type!=="source_component")return A.symbol_name?hyt(A.symbol_name)?`Device:${A.symbol_name}`:`Custom:${A.symbol_name}`:"Device:Component";if(A.symbol_name)return hyt(A.symbol_name)?`Device:${A.symbol_name}`:`Custom:${A.symbol_name}`;const n=U3(e,t);return`Device:${Ij(e)}_${n}`}function VCi(e){const{circuitJson:A,schematicSymbolId:t,schematicSymbol:i,schematicComponentId:n}=e,o=A.filter(Q=>Q.type==="schematic_circle"&&Q.schematic_symbol_id===t),s=A.filter(Q=>Q.type==="schematic_line"&&Q.schematic_symbol_id===t),r=n?A.filter(Q=>Q.type==="schematic_line"&&Q.schematic_component_id===n&&!Q.schematic_symbol_id):[],a=[...s,...r],g=A.filter(Q=>Q.type==="schematic_path"&&Q.schematic_symbol_id===t),c=A.filter(Q=>Q.type==="schematic_text"&&Q.schematic_symbol_id===t);let I=A.filter(Q=>Q.type==="schematic_port"&&"schematic_symbol_id"in Q&&Q.schematic_symbol_id===t);if(I.length===0&&n){const Q=A.filter(E=>E.type==="schematic_port"&&E.schematic_component_id===n&&E.display_pin_label!==void 0),h=new Map;for(const E of Q)E.display_pin_label&&h.set(E.display_pin_label,E);if(I=h.size>0?Array.from(h.values()):Q,I.length===0){const E=A.filter(d=>d.type==="schematic_port"&&d.schematic_component_id===n),u=new Set;I=E.filter(d=>{const f=d.pin_number;if(f!==void 0){if(u.has(f))return!1;u.add(f)}return!0})}}const l=[];for(const Q of o)l.push({type:"circle",x:Q.center?.x??0,y:Q.center?.y??0,radius:Q.radius??.5,fill:Q.is_filled??!1,fillColor:Q.fill_color});for(const Q of a)l.push({type:"path",points:[{x:Q.x1??0,y:Q.y1??0},{x:Q.x2??0,y:Q.y2??0}]});for(const Q of g)Q.points&&Q.points.length>0&&l.push({type:"path",points:Q.points,fill:Q.is_filled??!1,fillColor:Q.fill_color});const B=c.map(Q=>({text:Q.text??"",x:Q.position?.x??0,y:Q.position?.y??0,fontSize:Q.font_size??.2,anchor:Q.anchor??"center"})),C=I.map((Q,h)=>({x:Q.center?.x??0,y:Q.center?.y??0,labels:[Q.display_pin_label||`${Q.pin_number||h+1}`],pinNumber:Q.pin_number||h+1,facingDirection:Q.facing_direction}));return C.sort((Q,h)=>Q.pinNumber-h.pinNumber),{center:i.center||{x:0,y:0},size:i.size||{width:1,height:1},primitives:l,texts:B,ports:C}}function jCi({points:e,transform:A,fillType:t}){const i=new Cdt,n=e.map(a=>{const g=Ct(A,a);return new oh(g.x,g.y)}),o=new oQ(n);i.points=o;const s=new f1;s.width=.254,s.type="default",i.stroke=s;const r=new fdt;return r.type=t,i.fill=r,i}function zCi({primitive:e,transform:A,scale:t}){const i=new wdt,n=Ct(A,{x:e.x,y:e.y}),o=i;o._sxCenter=new ddt(n.x,n.y),o._sxRadius=new pdt(e.radius*t);const s=new f1;s.width=.254,s.type="default",o._sxStroke=s;const r=new ydt;return r.type=e.fill?"background":"none",o._sxFill=r,i}function XCi({schText:e,transform:A,scale:t}){const i=new Ddt,n=Ct(A,{x:e.x,y:e.y});i.value=e.text,i.at=[n.x,n.y,0];const o=e.fontSize*t,s=new Tp;return s.size={height:o,width:o},i.effects=new Jp({font:s}),i}function $Ci({libId:e,symbolData:A,isChip:t,c2kMatSchScale:i}){const n=new NM({libraryId:`${e.split(":")[1]}_0_1`}),o=i,s=A.center?.x??0,r=A.center?.y??0,a=tn(za(o,o),sn(-s,-r));for(const c of A.primitives||[])if(c.type==="path"&&c.points){const I=t||c.fill?"background":"none",l=jCi({points:c.points,transform:a,fillType:I});n.polylines.push(l)}else if(c.type==="circle"){const I=zCi({primitive:c,transform:a,scale:o});n.circles.push(I)}const g=Array.isArray(A.texts)?A.texts:[];for(const c of g){const I=XCi({schText:c,transform:a,scale:o});n.texts.push(I)}return n}function AQi(e,A){const t=A.schematic_port.list().filter(r=>r.schematic_component_id===e.schematic_component_id).sort((r,a)=>(r.pin_number||0)-(a.pin_number||0)),i=e.size?.width||1.5,n=e.size?.height||1,o={type:"path",points:[{x:-i/2,y:-n/2},{x:i/2,y:-n/2},{x:i/2,y:n/2},{x:-i/2,y:n/2},{x:-i/2,y:-n/2}]},s=t.map(r=>{const a=r.center.x-e.center.x,g=r.center.y-e.center.y;return{x:a,y:g,labels:[r.display_pin_label||`${r.pin_number||1}`],pinNumber:r.pin_number||1}});return{center:{x:0,y:0},primitives:[o],ports:s,size:{width:i,height:n}}}function tQi(e,A){const t=new Tp;return t.size={height:e,width:e},new Jp({font:t,hiddenText:A})}function eQi({symbol:e,libId:A,description:t,keywords:i,fpFilters:n,footprintRef:o="",referencePrefix:s}){const r=s||A.split(":")[1]?.[0]||"U",a=[{key:"Reference",value:r,id:0,at:[2.032,0,90],hide:!1},{key:"Value",value:r,id:1,at:[0,0,90],hide:!1},{key:"Footprint",value:o,id:2,at:[-1.778,0,90],hide:!0},{key:"Datasheet",value:"~",id:3,at:[0,0,0],hide:!0},{key:"Description",value:t,id:4,at:[0,0,0],hide:!0},{key:"ki_keywords",value:i,id:5,at:[0,0,0],hide:!0},{key:"ki_fp_filters",value:n,id:6,at:[0,0,0],hide:!0}];for(const g of a)e.properties.push(new Pp({key:g.key,value:g.value,id:g.id,at:g.at,effects:tQi(1.27,g.hide)}))}function iQi({port:e,center:A,size:t,isChip:i,portIndex:n,schematicComponent:o,schematicPorts:s,c2kMatSchScale:r}){const a=r;let g=e.x??0,c=e.y??0,I=!1;if(i&&n!==void 0&&o){const m=s.filter(w=>w.schematic_component_id===o.schematic_component_id).sort((w,D)=>(w.pin_number||0)-(D.pin_number||0));if(m[n]){const w=m[n];g=w.center.x-o.center.x,c=w.center.y-o.center.y,I=!0}}let l,B;if(I)l=g,B=c;else{const m=A?.x??0,w=A?.y??0;l=g-m,B=c-w}const C=za(a,a),Q=Ct(C,{x:l,y:B});let h;if(i&&t){const m=t.width/2,w=t.height/2,D=Math.abs(l)/m,x=Math.abs(B)/w;h=D>x}else h=Math.abs(l)>Math.abs(B);let E=Q.x,u=Q.y;const d=6;if(i&&t){const m=t.width/2*a,w=t.height/2*a;h?(E=l>0?m:-m,u=B*a):(E=l*a,u=B>0?w:-w)}let f=0;return h?l>0?(f=180,i&&(E=E+d)):(f=0,i&&(E=E-d)):B>0?(f=270,i&&(u=u+d)):(f=90,i&&(u=u-d)),{x:E,y:u,angle:f}}function nQi({libId:e,symbolData:A,isChip:t,schematicComponent:i,schematicPorts:n,c2kMatSchScale:o}){const s=new NM({libraryId:`${e.split(":")[1]}_1_1`}),r=6,a=2.54;for(let g=0;g<(A.ports?.length||0);g++){const c=A.ports[g],I=new jV;I.pinElectricalType="passive",I.pinGraphicStyle="line";const{x:l,y:B,angle:C}=iQi({port:c,center:A.center,size:A.size,isChip:t,portIndex:g,schematicComponent:i,schematicPorts:n,c2kMatSchScale:o});I.at=[l,B,C],I.length=t?r:a;const Q=new Tp;Q.size={height:1.27,width:1.27};const h=new Jp({font:Q}),E=c.labels?.[0]||"~";I._sxName=new rDA({value:E,effects:h});const u=new Tp;u.size={height:1.27,width:1.27};const d=new Jp({font:u}),f=c.pinNumber?.toString()||`${g+1}`;I._sxNumber=new Sdt({value:f,effects:d}),s.pins.push(I)}return s}var oQi=class extends t0{processedSymbolNames=new Set;_step(){const{kicadSch:e,db:A}=this.ctx,t=new Gdt,i=[];this.processedSymbolNames=new Set;const n=A.schematic_component.list();for(const s of n){const r=this.createLibrarySymbolForComponent(s);r&&i.push(r)}const o=A.schematic_net_label?.list?.()||[];for(const s of o)if(s.symbol_name){const r=s.source_net_id?A.source_net.get(s.source_net_id)?.is_power:!1,a=s.source_net_id?A.source_net.get(s.source_net_id)?.is_ground:!1;if(r||a){const c=this.createLibrarySymbolForNetLabel({netLabel:s,isPower:r??!1,isGround:a??!1});c&&i.push(c)}}t.symbols=i,e&&(e.libSymbols=t),this.finished=!0}createLibrarySymbolForComponent(e){const{db:A}=this.ctx,t=e.source_component_id?A.source_component.get(e.source_component_id):null;if(!t)return null;const i=A.cad_component?.list()?.find(c=>c.source_component_id===t.source_component_id);let n=e.schematic_symbol_id;if(!n){const c=this.ctx.circuitJson.find(I=>(I.type==="schematic_line"||I.type==="schematic_circle"||I.type==="schematic_path")&&I.schematic_component_id===e.schematic_component_id&&I.schematic_symbol_id);c&&(n=c.schematic_symbol_id)}if(n)return this.createLibrarySymbolFromSchematicSymbol(e,t,i,n);const o=e.symbol_name||(t.ftype==="simple_chip"?`generic_chip_${e.source_component_id}`:null);if(!o)return null;const s=this.getSymbolData(o,e);if(!s)return null;const r=Eyt(t,e,i),a=t.ftype==="simple_chip",g=U3(t,i);return this.createLibrarySymbol({libId:r,symbolData:s,isChip:a,schematicComponent:e,description:this.getDescription(t),keywords:this.getKeywords(t),fpFilters:this.getFpFilters(t),footprintRef:g?`tscircuit:${g}`:"",referencePrefix:Ij(t)})}createLibrarySymbolFromSchematicSymbol(e,A,t,i){const{db:n}=this.ctx,o=this.ctx.circuitJson.find(c=>c.type==="schematic_symbol"&&c.schematic_symbol_id===i);if(!o)return null;let s;if(o.name)s=o.name;else{const c=U3(A,t);c?s=c:s=`custom_${A.ftype||"component"}_${i}`}const r=`Custom:${s}`;if(this.processedSymbolNames.has(r))return null;this.processedSymbolNames.add(r);const a=VCi({circuitJson:this.ctx.circuitJson,schematicSymbolId:i,schematicSymbol:o,schematicComponentId:e.schematic_component_id}),g=U3(A,t);return this.createLibrarySymbol({libId:r,symbolData:a,isChip:!1,schematicComponent:e,description:this.getDescription(A),keywords:this.getKeywords(A),fpFilters:this.getFpFilters(A,o.name),footprintRef:g?`tscircuit:${g}`:"",referencePrefix:Ij(A),symbolScale:1})}createLibrarySymbolForNetLabel({netLabel:e,isPower:A,isGround:t}){const i=e.symbol_name;if(!i)return null;const n=qQ[i];if(!n)return null;const o=`Custom:${i}`;return this.createLibrarySymbol({libId:o,symbolData:n,isChip:!1,schematicComponent:void 0,description:A?"Power net label":t?"Ground net label":"Net symbol",keywords:A?"power net":t?"ground net":"net",fpFilters:"",referencePrefix:o.split(":")[1]?.[0]||"U"})}getSymbolData(e,A){return e.startsWith("generic_chip_")?AQi(A,this.ctx.db):qQ[e]||null}createLibrarySymbol({libId:e,symbolData:A,isChip:t,schematicComponent:i,description:n,keywords:o,fpFilters:s,footprintRef:r="",referencePrefix:a,symbolScale:g}){const I=g??this.ctx.c2kMatSch?.a??15,l=new NM({libraryId:e,excludeFromSim:!1,inBom:!0,onBoard:!0}),B=new nDA;B.hide=!t,l._sxPinNumbers=B;const C=new sDA;C.offset=t?1.27:0,l._sxPinNames=C,eQi({symbol:l,libId:e,description:n,keywords:o,fpFilters:s,footprintRef:r,referencePrefix:a});const Q=$Ci({libId:e,symbolData:A,isChip:t,c2kMatSchScale:I});l.subSymbols.push(Q);const h=nQi({libId:e,symbolData:A,isChip:t,schematicComponent:i,schematicPorts:this.ctx.db.schematic_port.list(),c2kMatSchScale:I});return l.subSymbols.push(h),l._sxEmbeddedFonts=new GM(!1),l}getDescription(e){return e?.ftype==="simple_resistor"?"Resistor":e?.ftype==="simple_capacitor"?"Capacitor":e?.ftype==="simple_chip"?"Integrated Circuit":"Component"}getKeywords(e){return e?.ftype==="simple_resistor"?"R res resistor":e?.ftype==="simple_capacitor"?"C cap capacitor":e?.ftype==="simple_chip"?"U IC chip":""}getFpFilters(e,A){return A?`${A}*`:e?.ftype==="simple_resistor"?"R_*":e?.ftype==="simple_capacitor"?"C_*":(e?.ftype==="simple_chip","*")}getOutput(){if(!this.ctx.kicadSch)throw new Error("kicadSch is not initialized");return this.ctx.kicadSch}},sQi=class extends t0{_step(){const{kicadSch:e,db:A}=this.ctx,t=A.schematic_component.list();if(t.length===0){this.finished=!0;return}const i=[];for(const n of t){const o=n.source_component_id?A.source_component.get(n.source_component_id):null;if(!o||!this.ctx.c2kMatSch)continue;const{x:s,y:r}=Ct(this.ctx.c2kMatSch,{x:n.center.x,y:n.center.y}),a=crypto.randomUUID(),g=new NM({at:[s,r,0],unit:1,excludeFromSim:!1,inBom:!0,onBoard:!0,dnp:!1,uuid:a,fieldsAutoplaced:!0}),c=A.cad_component?.list()?.find(oA=>oA.source_component_id===o.source_component_id);let I,l=n.schematic_symbol_id;if(!l){const oA=this.ctx.circuitJson.find(rA=>(rA.type==="schematic_line"||rA.type==="schematic_circle"||rA.type==="schematic_path")&&rA.schematic_component_id===n.schematic_component_id&&rA.schematic_symbol_id);oA&&(l=oA.schematic_symbol_id)}if(l){const oA=this.ctx.circuitJson.find(rA=>rA.type==="schematic_symbol"&&rA.schematic_symbol_id===l);if(oA?.name)I=oA.name;else{const rA=U3(o,c);rA?I=rA:I=`custom_${o.ftype||"component"}_${l}`}}const B=Eyt(o,n,c,I),C=new eDA(B);g._sxLibId=C;const{reference:Q,value:h,description:E}=this.getComponentMetadata(o),{refTextPos:u,valTextPos:d}=this.getTextPositions(n,{x:s,y:r});let f;if(l){const oA=this.ctx.circuitJson.find(rA=>rA.type==="schematic_symbol"&&rA.schematic_symbol_id===l);oA&&oA.type==="schematic_symbol"&&(f=oA.metadata?.kicad_symbol)}const m=f?.properties?.Reference,w=new Pp({key:"Reference",value:m?.value??Q,id:0,at:[u.x,u.y,0],effects:this.createTextEffects(Number(m?.effects?.font?.size?.x??1.27),m?.effects?.hide??!1)}),D=o.ftype==="simple_chip",x=f?.properties?.Value,_=new Pp({key:"Value",value:x?.value??h,id:1,at:[d.x,d.y,0],effects:this.createTextEffects(Number(x?.effects?.font?.size?.x??1.27),x?.effects?.hide??D)}),b=f?.properties?.Footprint,R=new Pp({key:"Footprint",value:b?.value??"",id:2,at:[s-1.778,r,90],effects:this.createTextEffects(1.27,b?.effects?.hide??!0)}),F=f?.properties?.Datasheet,H=new Pp({key:"Datasheet",value:F?.value??"~",id:3,at:[s,r,0],effects:this.createTextEffects(1.27,F?.effects?.hide??!0)}),Y=f?.properties?.Description,J=new Pp({key:"Description",value:Y?.value??E,id:4,at:[s,r,0],effects:this.createTextEffects(1.27,Y?.effects?.hide??!0)});g.properties.push(w,_,R,H,J);const O=f?.properties?.ki_keywords;if(O?.value){const oA=new Pp({key:"ki_keywords",value:O.value,id:5,at:[s,r,0],effects:this.createTextEffects(1.27,O.effects?.hide??!0)});g.properties.push(oA)}const W=f?.properties?.ki_fp_filters;if(W?.value){const oA=new Pp({key:"ki_fp_filters",value:W.value,id:6,at:[s,r,0],effects:this.createTextEffects(1.27,W.effects?.hide??!0)});g.properties.push(oA)}if(f){if(f.inBom!==void 0&&(g.inBom=f.inBom),f.onBoard!==void 0&&(g.onBoard=f.onBoard),f.excludeFromSim!==void 0&&(g.excludeFromSim=f.excludeFromSim),f.pinNames){const oA=new sDA;f.pinNames.offset!==void 0&&(oA.offset=Number(f.pinNames.offset)),f.pinNames.hide!==void 0&&(oA.hide=f.pinNames.hide),g.pinNames=oA}if(f.pinNumbers){const oA=new nDA;f.pinNumbers.hide!==void 0&&(oA.hide=f.pinNumbers.hide),g.pinNumbers=oA}f.embeddedFonts!==void 0&&(g._sxEmbeddedFonts=new GM(f.embeddedFonts))}let z=A.schematic_port.list().filter(oA=>oA.schematic_component_id===n.schematic_component_id);if(l){const oA=z.filter(rA=>rA.display_pin_label);oA.length>0&&(z=oA)}z.sort((oA,rA)=>(oA.pin_number||0)-(rA.pin_number||0));for(let oA=0;oA<z.length;oA++){const rA=z[oA];if(!rA)continue;const lA=new jV;lA.numberString=`${rA.pin_number||oA+1}`,lA.uuid=crypto.randomUUID(),g.pins.push(lA)}const tA=new aDA,aA=new cDA(""),eA=new IDA(`/${e?.uuid?.value||""}`);eA.reference=Q,eA.unit=1,aA.paths.push(eA),tA.projects.push(aA),g._sxInstances=tA,i.push(g)}e&&(e.symbols=i),this.finished=!0}getTextPositions(e,A){const i=(this.ctx.db.schematic_text?.list?.()?.filter(B=>B.schematic_component_id===e.schematic_component_id)||[]).find(B=>B.text&&B.text.length>0);if(i&&this.ctx.c2kMatSch){const B=Ct(this.ctx.c2kMatSch,{x:i.position.x,y:i.position.y}),C={x:A.x,y:A.y+6};return{refTextPos:B,valTextPos:C}}const n=e.symbol_name,o=qQ[n];if(!o)return{refTextPos:{x:A.x,y:A.y-6},valTextPos:{x:A.x,y:A.y+6}};let s=null,r=null;for(const B of o.primitives)B.type==="text"&&(B.text==="{REF}"?s=B:B.text==="{VAL}"&&(r=B));const a=o.center||{x:0,y:0},c=n.includes("_down")||n.includes("_up")?.15:0,I=s&&this.ctx.c2kMatSch?Ct(this.ctx.c2kMatSch,{x:e.center.x+(s.x-a.x)+c,y:e.center.y+(s.y-a.y)}):{x:A.x,y:A.y-6},l=r&&this.ctx.c2kMatSch?Ct(this.ctx.c2kMatSch,{x:e.center.x+(r.x-a.x)+c,y:e.center.y+(r.y-a.y)}):{x:A.x,y:A.y+6};return{refTextPos:I,valTextPos:l}}getComponentMetadata(e){const A=e.name||"?",t=ZCi(e);return e.ftype==="simple_resistor"?{reference:t,value:e.display_resistance||"R",description:"Resistor"}:e.ftype==="simple_capacitor"?{reference:t,value:e.display_capacitance||"C",description:"Capacitor"}:e.ftype==="simple_inductor"?{reference:t,value:e.display_inductance||"L",description:"Inductor"}:e.ftype==="simple_diode"?{reference:t,value:"D",description:"Diode"}:e.ftype==="simple_chip"?{reference:t,value:A,description:"Integrated Circuit"}:e.ftype==="simple_led"?{reference:t,value:e.manufacturer_part_number||"",description:"LED"}:e.ftype==="simple_switch"?{reference:t,value:e.manufacturer_part_number||"",description:"Switch"}:e.ftype==="simple_potentiometer"?{reference:t,value:e.display_max_resistance||"",description:"Potentiometer"}:{reference:t,value:A,description:"Component"}}createTextEffects(e,A=!1,t){const i=new Tp;i.size={height:e,width:e};const n=t?new a6({horizontal:t}):void 0;return new Jp({font:i,hiddenText:A,justify:n})}getOutput(){if(!this.ctx.kicadSch)throw new Error("kicadSch is not initialized");return this.ctx.kicadSch}},rQi=class extends t0{_step(){const{kicadSch:e,db:A}=this.ctx,t=A.schematic_net_label?.list?.()||[];if(t.length===0){this.finished=!0;return}if(!this.ctx.c2kMatSch){this.finished=!0;return}const i=[],n=[];for(const o of t){const s=o.text||"",r=o.symbol_name;if(r){const a=this.createSymbolFromNetLabel(o,s,r);a&&i.push(a)}else{const a=this.createGlobalLabel(o,s);a&&n.push(a)}}if(e&&i.length>0){const o=e.symbols||[];e.symbols=[...o,...i]}e&&n.length>0&&(e.globalLabels=[...e.globalLabels||[],...n]),this.finished=!0}createSymbolFromNetLabel(e,A,t){if(!this.ctx.c2kMatSch)return null;const{x:i,y:n}=Ct(this.ctx.c2kMatSch,{x:e.anchor_position?.x??e.center?.x??0,y:e.anchor_position?.y??e.center?.y??0}),o=crypto.randomUUID(),s=new NM({at:[i,n,0],unit:1,excludeFromSim:!1,inBom:!0,onBoard:!0,dnp:!1,uuid:o,fieldsAutoplaced:!0}),r=`Custom:${t}`,a=new eDA(r);s._sxLibId=a;const g=t.includes("_up")||t.toLowerCase().includes("vcc"),c=g?-4:4,I=g?-6:6,l=new Pp({key:"Reference",value:A,id:0,at:[i,n+c,0],effects:this.createTextEffects(1.27,!1)}),B=new Pp({key:"Value",value:A,id:1,at:[i,n+I,0],effects:this.createTextEffects(1.27,!0)}),C=new Pp({key:"Footprint",value:"",id:2,at:[i-1.778,n,90],effects:this.createTextEffects(1.27,!0)}),Q=new Pp({key:"Datasheet",value:"~",id:3,at:[i,n,0],effects:this.createTextEffects(1.27,!0)}),h=new Pp({key:"Description",value:`Power/Net symbol: ${A}`,id:4,at:[i,n,0],effects:this.createTextEffects(1.27,!0)});s.properties.push(l,B,C,Q,h);const E=new jV;E.numberString="1",E.uuid=crypto.randomUUID(),s.pins.push(E);const{kicadSch:u}=this.ctx,d=new aDA,f=new cDA(""),m=new IDA(`/${u?.uuid?.value||""}`);return m.reference=A,m.unit=1,f.paths.push(m),d.projects.push(f),s._sxInstances=d,s}createGlobalLabel(e,A){if(!this.ctx.c2kMatSch||!this.ctx.kicadSch)return null;const{x:t,y:i}=Ct(this.ctx.c2kMatSch,{x:e.anchor_position?.x??e.center?.x??0,y:e.anchor_position?.y??e.center?.y??0}),n=e.anchor_side||"left",s={left:0,right:180,top:270,bottom:90}[n]||0,a={left:{horizontal:"left"},right:{horizontal:"right"},top:{vertical:"top"},bottom:{vertical:"bottom"}}[n]||{},g=this.createTextEffects(1.27,!1);return Object.keys(a).length>0&&(g.justify=new a6(a)),new Pdt({value:A,at:[t,i,s],effects:g,uuid:crypto.randomUUID(),fieldsAutoplaced:!0})}createTextEffects(e,A=!1){const t=new Tp;return t.size={height:e,width:e},new Jp({font:t,hiddenText:A})}getOutput(){if(!this.ctx.kicadSch)throw new Error("kicadSch is not initialized");return this.ctx.kicadSch}},aQi=class extends t0{_step(){const{kicadSch:e,db:A}=this.ctx;if(!e)throw new Error("KicadSch instance not initialized in context");const t=A.schematic_trace.list();if(t.length===0){this.finished=!0;return}const i=[],n=[];for(const o of t){for(const s of o.edges){const r=this.createWireFromEdge(s);i.push(r)}for(const s of o.junctions){const r=this.createJunction(s);n.push(r)}}e.wires=i,e.junctions=n,this.finished=!0}createWireFromEdge(e){const A=new Ndt;if(!this.ctx.c2kMatSch)throw new Error("Schematic transformation matrix not initialized in context");const t=Ct(this.ctx.c2kMatSch,{x:e.from.x,y:e.from.y}),i=Ct(this.ctx.c2kMatSch,{x:e.to.x,y:e.to.y}),n=t.x,o=t.y,s=i.x,r=i.y,a=new oQ([new oh(n,o),new oh(s,r)]);A.points=a;const g=new f1;return g.width=0,g.type="default",A.stroke=g,A.uuid=crypto.randomUUID(),A}createJunction(e){if(!this.ctx.c2kMatSch)throw new Error("Schematic transformation matrix not initialized in context");const{x:A,y:t}=Ct(this.ctx.c2kMatSch,{x:e.x,y:e.y}),i=new Ldt({at:[A,t],diameter:0});return i.uuid=crypto.randomUUID(),i}getOutput(){return this.ctx.kicadSch}},gQi=class extends t0{_step(){const{kicadSch:e}=this.ctx;if(!e)throw new Error("KicadSch instance not initialized in context");const A=new QDA,t=new Odt;t.value="/";const i=new Wdt("1");t.pages=[i],A.paths=[t],e.sheetInstances=A,e.embeddedFonts=new GM(!1),this.finished=!0}getOutput(){return this.ctx.kicadSch}};function cQi(e){const A=e.schematic_component.list(),t=e.schematic_trace.list();let i=1/0,n=1/0,o=-1/0,s=-1/0;for(const g of A){const c=g.size?.width??0,I=g.size?.height??0;i=Math.min(i,g.center.x-c/2),n=Math.min(n,g.center.y-I/2),o=Math.max(o,g.center.x+c/2),s=Math.max(s,g.center.y+I/2)}for(const g of t)for(const c of g.edges)i=Math.min(i,c.from.x,c.to.x),n=Math.min(n,c.from.y,c.to.y),o=Math.max(o,c.from.x,c.to.x),s=Math.max(s,c.from.y,c.to.y);i===1/0&&(i=0,n=0,o=0,s=0);const r=(i+o)/2,a=(n+s)/2;return{center:{x:r,y:a},bounds:{minX:i,minY:n,maxX:o,maxY:s}}}var lj=[{name:"A4",width:297,height:210},{name:"A3",width:420,height:297},{name:"A2",width:594,height:420},{name:"A1",width:841,height:594},{name:"A0",width:1189,height:841}];function IQi(e,A,t=20){const i=e+2*t,n=A+2*t;for(let o=0;o<lj.length;o++){const s=lj[o];if(i<=s.width&&n<=s.height)return s}return lj[lj.length-1]}var uyt=class{ctx;pipeline;currentStageIndex=0;finished=!1;get currentStage(){return this.pipeline[this.currentStageIndex]}constructor(e){const t=Na(e),{center:i,bounds:n}=cQi(t),o=(n.maxX-n.minX)*15,s=(n.maxY-n.minY)*15,r=IQi(o,s),a=r.width/2,g=r.height/2;this.ctx={db:t,circuitJson:e,kicadSch:new EDA({generator:"circuit-json-to-kicad",generatorVersion:"0.0.1"}),schematicPaperSize:r,c2kMatSch:tn(sn(a,g),za(15,-15),sn(-i.x,-i.y))},this.pipeline=[new qCi(e,this.ctx),new oQi(e,this.ctx),new sQi(e,this.ctx),new rQi(e,this.ctx),new aQi(e,this.ctx),new gQi(e,this.ctx)]}step(){if(!this.currentStage){this.finished=!0;return}this.currentStage.step(),this.currentStage.finished&&this.currentStageIndex++}runUntilFinished(){for(;!this.finished;)this.step()}getOutput(){return this.ctx.kicadSch}getOutputString(){return this.ctx.kicadSch.getString()}},lQi=class extends t0{_step(){const{kicadPcb:e,db:A}=this.ctx;if(!e)throw new Error("KicadPcb instance not initialized in context");const i=A.pcb_board?.list()?.[0]?.num_layers??2;this.ctx.numLayers=i,e.version=20241229;const n=new OV;n.size="A4",e.paper=n;const o=new d2A;o.thickness=1.6,e.general=o;const s=new u2A;s.padToMaskClearance=0,e.setup=s;const r=new p2A,a=[new Zl({index:0,name:"F.Cu",type:"signal"})];for(let g=1;g<i-1;g++)a.push(new Zl({index:g,name:`In${g}.Cu`,type:"signal"}));a.push(new Zl({index:31,name:"B.Cu",type:"signal"})),a.push(new Zl({index:32,name:"B.Adhes",type:"user"}),new Zl({index:33,name:"F.Adhes",type:"user"}),new Zl({index:34,name:"B.Paste",type:"user"}),new Zl({index:35,name:"F.Paste",type:"user"}),new Zl({index:36,name:"B.SilkS",type:"user"}),new Zl({index:37,name:"F.SilkS",type:"user"}),new Zl({index:38,name:"B.Mask",type:"user"}),new Zl({index:39,name:"F.Mask",type:"user"}),new Zl({index:40,name:"Dwgs.User",type:"user"}),new Zl({index:41,name:"Cmts.User",type:"user"}),new Zl({index:42,name:"Eco1.User",type:"user"}),new Zl({index:43,name:"Eco2.User",type:"user"}),new Zl({index:44,name:"Edge.Cuts",type:"user"}),new Zl({index:45,name:"Margin",type:"user"}),new Zl({index:46,name:"B.CrtYd",type:"user"}),new Zl({index:47,name:"F.CrtYd",type:"user"}),new Zl({index:48,name:"B.Fab",type:"user"}),new Zl({index:49,name:"F.Fab",type:"user"})),r.definitions=a,e.layers=r,this.finished=!0}getOutput(){return this.ctx.kicadPcb}},BQi=class extends t0{_step(){const{kicadPcb:e}=this.ctx;if(!e)throw new Error("KicadPcb instance not initialized in context");this.ctx.pcbNetMap=new Map;const A=new Map,t=this.ctx.db.source_net?.list()??[];for(const r of t){const a=r.subcircuit_connectivity_map_key||r.source_net_id;if(!a)continue;const g=r.name||r.source_net_id||"",c=g&&g.trim().length>0?g:a;A.set(a,c)}const i=this.ctx.db.source_trace?.list()??[];for(const r of i){let a=r.subcircuit_connectivity_map_key;if(!a&&r.connected_source_net_ids?.length)for(const g of r.connected_source_net_ids){const c=this.ctx.db.source_net?.get(g);if(c?.subcircuit_connectivity_map_key&&c.subcircuit_connectivity_map_key.length>0){a=c.subcircuit_connectivity_map_key;break}}if(a&&!A.has(a)){const g=r.display_name||r.source_trace_id||"",c=g&&g.trim().length>0?g:a;A.set(a,c)}}const n=Array.from(A.entries()).sort((r,a)=>r[0].localeCompare(a[0])),o=[];o.push(new cj(0,""));let s=1;for(const[r,a]of n){const g=new cj(s,a);o.push(g);const c={id:s,name:a};this.ctx.pcbNetMap.set(r,c),s++}e.nets=o,this.finished=!0}getOutput(){return this.ctx.kicadPcb}};function CQi(e){let A=0;for(let i=0;i<e.length;i++){const n=e.charCodeAt(i);A=(A<<5)-A+n,A=A&A}let t="";for(let i=0;i<4;i++){let n=A;for(let o=0;o<e.length;o++)n=(n<<5)-n+e.charCodeAt(o)+i*31,n=n&n;t+=Math.abs(n).toString(16).padStart(8,"0")}return t}function cd(e){const A=CQi(e);return`${A.slice(0,8)}-${A.slice(8,12)}-${A.slice(12,16)}-${A.slice(16,20)}-${A.slice(20,32)}`}var dyt="https://modelcdn.tscircuit.com/jscad_models",QQi=20240108,hQi="pcbnew",EQi="8.0";function b2A(e){const A=e.split(/[/\\]/),t=A[A.length-1]||e;return t.split("?")[0]||t}var uQi=class extends t0{classifyFootprints(){const e=new Set,A=new Map,t=this.ctx.db.cad_component?.list()??[],i=this.ctx.db.source_component;for(const n of t){const o=n.source_component_id?i?.get(n.source_component_id):null;if(!o)continue;const s=U3(o,n);if(n.footprinter_string)A.set(s,n.footprinter_string);else{e.add(s);const r=this.ctx.circuitJson.find(a=>a.type==="pcb_component"&&a.source_component_id===n.source_component_id);r&&r.type==="pcb_component"&&r.metadata?.kicad_footprint?.footprintName&&e.add(r.metadata.kicad_footprint.footprintName)}}return{customFootprintNames:e,footprinterStrings:A}}_step(){const e=this.ctx.kicadPcbString,A=this.ctx.fpLibraryName??"tscircuit";if(!e)throw new Error("PCB content not available. Run GenerateKicadSchAndPcbStage first.");const{customFootprintNames:t,footprinterStrings:i}=this.classifyFootprints(),n=new Map;try{const s=lyt(e).find(a=>a instanceof x2A);if(!s){this.ctx.footprintEntries=[],this.finished=!0;return}const r=s.footprints??[];for(const a of r){const g=this.sanitizeFootprint({footprint:a,fpLibraryName:A,customFootprintNames:t,footprinterStrings:i});n.has(g.footprintName)||n.set(g.footprintName,g)}}catch(o){console.warn("Failed to parse PCB for footprint extraction:",o)}this.ctx.footprintEntries=Array.from(n.values()),this.finished=!0}sanitizeFootprint({footprint:e,fpLibraryName:A,customFootprintNames:t,footprinterStrings:i}){const o=(e.libraryLink??"footprint").split(":"),s=(o.length>1?o[1]:o[0])?.replace(/[\\\/]/g,"-").trim()||"footprint",r=!t.has(s);if(e.libraryLink=s,e.position=oc.from([0,0,0]),e.locked=!1,e.placed=!1,e.version=QQi,e.generator=hQi,e.generatorVersion=EQi,e.descr||(e.descr=""),e.tags||(e.tags=""),e.embeddedFonts||(e.embeddedFonts=new GM(!1)),!e.attr){const f=new uDA,m=(e.fpPads??[]).map(w=>w.padType);m.some(w=>w.includes("thru_hole"))?f.type="through_hole":m.some(w=>w.includes("smd"))&&(f.type="smd"),e.attr=f}e.uuid=void 0,e.path=void 0,e.sheetfile=void 0,e.sheetname=void 0;const a=new Tp;a.size={width:1.27,height:1.27},a.thickness=.15;const g=new Jp({font:a}),c=e.fpPads??[];let I=0,l=0;for(const f of c){const m=f.at,w=f.size;if(m&&w){const D=m.y??0,x=w.height??0,_=D-x/2,b=D+x/2;I=Math.min(I,_),l=Math.max(l,b)}}const B=I-.5,C=l+.5;e.properties=[new y1({key:"Reference",value:"REF**",position:[0,B,0],layer:"F.SilkS",uuid:cd(`${s}-property-Reference`),effects:g}),new y1({key:"Value",value:"Val**",position:[0,C,0],layer:"F.Fab",uuid:cd(`${s}-property-Value`),effects:g}),new y1({key:"Datasheet",value:"",position:[0,0,0],layer:"F.Fab",hidden:!0,uuid:cd(`${s}-property-Datasheet`),effects:g}),new y1({key:"Description",value:"",position:[0,0,0],layer:"F.Fab",hidden:!0,uuid:cd(`${s}-property-Description`),effects:g})];const Q=e.fpTexts??[];for(const f of Q)f.uuid=void 0,f.type==="reference"?f.text="REF**":f.type==="value"&&f.text.trim().length===0&&(f.text=s);e.fpTexts=Q;const h=e.fpPads??[];for(let f=0;f<h.length;f++){const m=h[f];m&&(m.uuid=cd(`${s}-pad-${m.number??f}`),m.net=void 0)}e.fpPads=h;const E=e.models??[],u=[],d=[];for(const f of E)if(f.path){const m=b2A(f.path),x=`../../3dmodels/${f.path.startsWith("http://modelcdn.tscircuit.com")||f.path.startsWith("https://modelcdn.tscircuit.com")?"tscircuit_builtin":A}.3dshapes/${m}`,_=new L3(x);f.offset&&(_.offset=f.offset),f.scale&&(_.scale=f.scale),f.rotate&&(_.rotate=f.rotate),u.push(_),d.push(f.path.split("?")[0]??f.path)}if(u.length===0){const f=i.get(s);if(f){const m=`${dyt}/${f}.step`,D=`../../3dmodels/tscircuit_builtin.3dshapes/${b2A(m)}`;u.push(new L3(D)),d.push(m)}}return e.models=u,{footprintName:s,kicadModString:e.getString(),model3dSourcePaths:d,isBuiltin:r}}getOutput(){return this.ctx.libraryOutput}};function Bj(e){const A=new Tp;return e?.font?.size?A.size={width:Number(e.font.size.x),height:Number(e.font.size.y)}:A.size={width:1.27,height:1.27},e?.font?.thickness!==void 0?A.thickness=Number(e.font.thickness):A.thickness=.15,new Jp({font:A})}function dQi(e,A,t){if(A.properties){const i=[],n=A.properties.Reference;i.push(new y1({key:"Reference",value:n?.value??t,position:n?.at?[Number(n.at.x),Number(n.at.y),Number(n.at.rotation??0)]:[0,-3,0],layer:n?.layer??"F.SilkS",uuid:cd(`${t}-property-Reference`),effects:Bj(n?.effects),hidden:n?.hide}));const o=A.properties.Value,s=o?.value??A.footprintName??"";i.push(new y1({key:"Value",value:s,position:o?.at?[Number(o.at.x),Number(o.at.y),Number(o.at.rotation??0)]:[0,3,0],layer:o?.layer??"F.Fab",uuid:cd(`${t}-property-Value`),effects:Bj(o?.effects),hidden:o?.hide}));const r=A.properties.Datasheet;i.push(new y1({key:"Datasheet",value:r?.value??"",position:r?.at?[Number(r.at.x),Number(r.at.y),Number(r.at.rotation??0)]:[0,0,0],layer:r?.layer??"F.Fab",uuid:cd(`${t}-property-Datasheet`),effects:Bj(r?.effects),hidden:r?.hide??!0}));const a=A.properties.Description;i.push(new y1({key:"Description",value:a?.value??"",position:a?.at?[Number(a.at.x),Number(a.at.y),Number(a.at.rotation??0)]:[0,0,0],layer:a?.layer??"F.Fab",uuid:cd(`${t}-property-Description`),effects:Bj(a?.effects),hidden:a?.hide??!0})),e.properties=i}if(A.attributes&&(e.attr||(e.attr=new uDA),A.attributes.through_hole?e.attr.type="through_hole":A.attributes.smd&&(e.attr.type="smd"),A.attributes.exclude_from_pos_files!==void 0&&(e.attr.excludeFromPosFiles=A.attributes.exclude_from_pos_files),A.attributes.exclude_from_bom!==void 0&&(e.attr.excludeFromBom=A.attributes.exclude_from_bom)),A.footprintName&&(e.libraryLink=A.footprintName),A.layer&&(e.layer=A.layer),A.embeddedFonts!==void 0&&(e.embeddedFonts=new GM(A.embeddedFonts)),A.model){const i=new L3(A.model.path);A.model.offset&&(i.offset={x:Number(A.model.offset.x),y:Number(A.model.offset.y),z:Number(A.model.offset.z)}),A.model.scale&&(i.scale={x:Number(A.model.scale.x),y:Number(A.model.scale.y),z:Number(A.model.scale.z)}),A.model.rotate&&(i.rotate={x:Number(A.model.rotate.x),y:Number(A.model.rotate.y),z:Number(A.model.rotate.z)});const n=e.models||[];e.models=[i,...n]}}function pQi(e,A){const t=[];for(const i of e){const n=i.center.x-A.x,o=-(i.center.y-A.y),r={top:"F.SilkS",bottom:"B.SilkS"}[i.layer]||i.layer||"F.SilkS",a=new t1A({center:{x:n,y:o},end:{x:n+i.radius,y:o},layer:r,stroke:new f1,fill:!1});a.stroke&&(a.stroke.width=i.stroke_width||.05,a.stroke.type="default"),t.push(a)}return t}function fQi(e,A){const t=[];for(const i of e){const n=i.center.x-A.x,o=-(i.center.y-A.y),r={top:"F.CrtYd",bottom:"B.CrtYd"}[i.layer]||"F.CrtYd",a=new t1A({center:{x:n,y:o},end:{x:n+i.radius,y:o},layer:r,stroke:new f1,fill:!1});a.stroke&&(a.stroke.width=.05,a.stroke.type="default"),t.push(a)}return t}function yQi(e,A){const t=[];for(const i of e){const n=i.center.x-A.x,o=-(i.center.y-A.y),s=i.width/2,r=i.height/2,g={top:"F.Fab",bottom:"B.Fab"}[i.layer]||i.layer||"F.Fab",c=new Aj({start:{x:n-s,y:o-r},end:{x:n+s,y:o+r},layer:g,stroke:new f1,fill:!1});c.stroke&&(c.stroke.width=i.stroke_width||.1,c.stroke.type="default"),t.push(c)}return t}function mQi(e,A){const t=[];for(const i of e){const n=i.center.x-A.x,o=-(i.center.y-A.y),s=i.width/2,r=i.height/2,a="F.Fab",g=new Aj({start:{x:n-s,y:o-r},end:{x:n+s,y:o+r},layer:a,stroke:new f1,fill:!1});g.stroke&&(g.stroke.width=i.stroke_width||.1,g.stroke.type="default"),t.push(g)}return t}function wQi(e,A){const t=[];for(const i of e){const n=i.center.x-A.x,o=-(i.center.y-A.y),s=i.width/2,r=i.height/2,g={top:"F.CrtYd",bottom:"B.CrtYd"}[i.layer]||"F.CrtYd",c=new Aj({start:{x:n-s,y:o-r},end:{x:n+s,y:o+r},layer:g,stroke:new f1,fill:!1});c.stroke&&(c.stroke.width=.05,c.stroke.type="default"),t.push(c)}return t}function DQi(e,A){const t=[];for(const i of e){if(!i.outline||i.outline.length<2)continue;const o={top:"F.CrtYd",bottom:"B.CrtYd"}[i.layer]||"F.CrtYd",s=i.outline.map(g=>{const c=g.x-A.x,I=-(g.y-A.y);return new oh(c,I)}),r=new Hpt;r.points=new oQ(s),r.layer=o,r.fill=!1;const a=new f1;a.width=.05,a.type="default",r.stroke=a,t.push(r)}return t}function xQi({textElement:e,componentCenter:A,componentRotation:t=0}){if(!e.text||!e.anchor_position)return null;const i=e.anchor_position.x-A.x,n=-(e.anchor_position.y-A.y),o=t!==0?Jl(t*Math.PI/180):Sa(),s=Ct(o,{x:i,y:n}),r={x:s.x,y:s.y},g={top:"F.SilkS",bottom:"B.SilkS"}[e.layer]||e.layer||"F.SilkS",c=(e.font_size||1)/1.5,I=new Tp;I.size={width:c,height:c};const l=new Jp({font:I}),B=e.ccw_rotation||0;return new qDA({type:"user",text:e.text,position:{x:r.x,y:r.y,angle:B},layer:g,effects:l})}function SQi(e,A,t,i){const n=[];for(const o of e){const s=xQi({textElement:o,componentCenter:A,componentRotation:t});s&&(i&&o.text===i&&(s.type="reference"),n.push(s))}return n}function bQi(e,A,t){const i=[];for(const n of e){const o=n.anchor_position.x-A.x,s=-(n.anchor_position.y-A.y),r=t!==0?Jl(t*Math.PI/180):Sa(),a=Ct(r,{x:o,y:s}),g=n.font_size||1,c=new Tp;c.size={width:g,height:g};const I=new Jp({font:c}),l=new qDA({type:"user",text:n.text,position:{x:a.x,y:a.y,angle:0},layer:"F.Fab",effects:I});i.push(l)}return i}function _Qi(e,A,t){const i=[],n=e.model_step_url||e.model_wrl_url;if(!n)return i;const o=new L3(n);if(e.position){const s=t?.boardLayerZOffset??0;o.offset={x:(e.position.x||0)-A.x,y:(e.position.y||0)-A.y,z:(e.position.z||0)-s}}if(e.rotation&&(o.rotate={x:e.rotation.x||0,y:e.rotation.y||0,z:e.rotation.z||0}),e.model_unit_to_mm_scale_factor){const s=e.model_unit_to_mm_scale_factor;o.scale={x:s,y:s,z:s}}return i.push(o),i}function kQi({pcbPad:e,componentCenter:A,padNumber:t,componentRotation:i=0,netInfo:n,componentId:o}){let s,r;if("x"in e&&"y"in e)s=e.x,r=e.y;else if("points"in e&&Array.isArray(e.points)){const u=e.points;s=u.reduce((d,f)=>d+f.x,0)/u.length,r=u.reduce((d,f)=>d+f.y,0)/u.length}else throw new Error("Pad must have either x/y coordinates or points array");const a=tn(i!==0?Jl(i*Math.PI/180):{a:1,b:0,c:0,d:1,e:0,f:0},za(1,-1),sn(-A.x,-A.y)),g=Ct(a,{x:s,y:r}),I={top:"F.Cu",bottom:"B.Cu"}[e.layer]||"F.Cu";let l,B,C,Q;if(e.shape==="circle")l="circle",B=["radius"in e?e.radius*2:.5,"radius"in e?e.radius*2:.5];else if(e.shape==="polygon"&&"points"in e){const u=e.points,d=tn(za(1,-1),sn(-s,-r)),f=u.map(w=>{const D=Ct(d,{x:w.x,y:w.y});return new oh(D.x,D.y)}),m=new YDA;m.contours=[new oQ(f)],m.width=0,m.filled=!0,Q=new ypt,Q.addGraphic(m),l="custom",C=new opt,C.anchor="circle",B=[.2,.2]}else l="rect",B=["width"in e?e.width:.5,"height"in e?e.height:.5];const h=`pad:${o}:${t}:${g.x},${g.y}`,E=new $V({number:String(t),padType:"smd",shape:l,at:[g.x,g.y,0],size:B,layers:[`${I}`,`${I==="F.Cu"?"F":"B"}.Paste`,`${I==="F.Cu"?"F":"B"}.Mask`],uuid:cd(h)});return C&&(E.options=C),Q&&(E.primitives=Q),n&&(E.net=new GDA(n.id,n.name)),E}function vQi(e,A,t,i,n,o){const s=[];let r=n;for(const a of e){const g=o(a.pcb_port_id),c=kQi({pcbPad:a,componentCenter:A,padNumber:r,componentRotation:t,netInfo:g,componentId:i});s.push(c),r++}return{pads:s,nextPadNumber:r}}function FQi({platedHole:e,componentCenter:A,padNumber:t,componentRotation:i=0,netInfo:n,componentId:o}){if(!("x"in e&&"y"in e))return null;const s=e.x-A.x,r=-(e.y-A.y),a=i!==0?Jl(i*Math.PI/180):Sa(),g=Ct(a,{x:s,y:r});let c="circle",I,l,B=0;const C="hole_offset_x"in e||"hole_offset_y"in e;let Q;if(C){const u={x:e.hole_offset_x??0,y:e.hole_offset_y??0};(u.x!==0||u.y!==0)&&(Q=Ct(a,{x:-u.x,y:u.y}))}e.shape==="circle"?(c="circle",I=[e.outer_diameter,e.outer_diameter],l=new m1({diameter:e.hole_diameter,offset:Q})):e.shape==="pill"||e.shape==="oval"?(c="oval",I=[e.outer_width,e.outer_height],l=new m1({oval:!0,diameter:e.hole_width,width:e.hole_height,offset:Q})):e.shape==="pill_hole_with_rect_pad"?(c="rect",I=[e.rect_pad_width,e.rect_pad_height],l=new m1({oval:!0,diameter:e.hole_width,width:e.hole_height,offset:Q})):e.shape==="circular_hole_with_rect_pad"?(c="rect",I=[e.rect_pad_width,e.rect_pad_height],l=new m1({diameter:e.hole_diameter,offset:Q})):e.shape==="rotated_pill_hole_with_rect_pad"?(c="rect",I=[e.rect_pad_width,e.rect_pad_height],l=new m1({oval:!0,diameter:e.hole_width,width:e.hole_height,offset:Q}),B=e.rect_ccw_rotation||0):(c="circle",I=[1.6,1.6],l=new m1({diameter:.8,offset:Q}));const h=`thruhole:${o}:${t}:${g.x},${g.y}`,E=new $V({number:String(t),padType:"thru_hole",shape:c,at:[g.x,g.y,B],size:I,drill:l,layers:["*.Cu","*.Mask"],removeUnusedLayers:!1,uuid:cd(h)});return n&&(E.net=new GDA(n.id,n.name)),E}function MQi(e,A,t,i,n,o){const s=[];let r=n;for(const a of e){const g=o(a.pcb_port_id),c=FQi({platedHole:a,componentCenter:A,padNumber:r,componentRotation:t,netInfo:g,componentId:i});c&&(s.push(c),r++)}return{pads:s,nextPadNumber:r}}function GQi({pcbHole:e,componentCenter:A,componentRotation:t=0}){if(!("x"in e&&"y"in e))return null;const i=e.x-A.x,n=-(e.y-A.y),o=t!==0?Jl(t*Math.PI/180):Sa(),s=Ct(o,{x:i,y:n});let r="circle",a,g;if(e.hole_shape==="circle"){r="circle";const c=e.hole_diameter;a=[c,c],g=new m1({diameter:c})}else if(e.hole_shape==="oval"||e.hole_shape==="pill"){r="oval";const c=e.hole_width,I=e.hole_height;a=[c,I],g=new m1({oval:!0,diameter:c,width:I})}else{r="circle";const c="hole_diameter"in e?e.hole_diameter:1;a=[c,c],g=new m1({diameter:c})}return new $V({number:"",padType:"np_thru_hole",shape:r,at:[s.x,s.y,0],size:a,drill:g,layers:["*.Cu","*.Mask"],removeUnusedLayers:!1,uuid:crypto.randomUUID()})}function pyt(e,A,t){const i=[];for(const n of e){const o=GQi({pcbHole:n,componentCenter:A,componentRotation:t});o&&i.push(o)}return i}var RQi=class extends t0{componentsProcessed=0;pcbComponents=[];includeBuiltin3dModels;getNetInfoForPcbPort(e){if(!e)return;const A=this.ctx.db.pcb_port?.get(e);if(!A)return;const t=A.source_port_id;if(!t)return;const i=this.ctx.db.source_port?.get(t);if(!i)return;const n=i.subcircuit_connectivity_map_key;if(n)return this.ctx.pcbNetMap?.get(n)}getCadComponentForPcbComponent(e){return(this.ctx.db.cad_component?.list()||[]).find(t=>t.pcb_component_id===e)}constructor(e,A,t){super(e,A),this.pcbComponents=this.ctx.db.pcb_component.list(),this.includeBuiltin3dModels=t?.includeBuiltin3dModels??!1}_step(){const{kicadPcb:e,c2kMatPcb:A}=this.ctx;if(!e)throw new Error("KicadPcb instance not initialized in context");if(!A)throw new Error("PCB transformation matrix not initialized in context");if(this.componentsProcessed>=this.pcbComponents.length){this.finished=!0;return}const t=this.pcbComponents[this.componentsProcessed],i=t.source_component_id?this.ctx.db.source_component.get(t.source_component_id):null,n=this.getCadComponentForPcbComponent(t.pcb_component_id),o=i?U3(i,n):"Unknown",s=Ct(A,{x:t.center.x,y:t.center.y}),r=`footprint:${t.pcb_component_id}:${s.x},${s.y}`,a=new nj({libraryLink:`tscircuit:${o}`,layer:"F.Cu",at:[s.x,s.y,t.rotation||0],uuid:cd(r)}),g=a.fpTexts,c=this.ctx.db.pcb_silkscreen_text?.list().filter(O=>O.pcb_component_id===t.pcb_component_id)||[];g.push(...SQi(c,t.center,t.rotation||0,i?.name));const I=this.ctx.db.pcb_note_text?.list().filter(O=>O.pcb_component_id===t.pcb_component_id)||[];g.push(...bQi(I,t.center,t.rotation||0)),a.fpTexts=g;const l=a.fpPads,B=O=>this.getNetInfoForPcbPort(O),C=this.ctx.db.pcb_smtpad?.list().filter(O=>O.pcb_component_id===t.pcb_component_id)||[],{pads:Q,nextPadNumber:h}=vQi(C,t.center,t.rotation||0,t.pcb_component_id,1,B);l.push(...Q);const E=this.ctx.db.pcb_plated_hole?.list().filter(O=>O.pcb_component_id===t.pcb_component_id)||[],{pads:u}=MQi(E,t.center,t.rotation||0,t.pcb_component_id,h,B);l.push(...u);const d=this.ctx.db.pcb_hole?.list().filter(O=>O.pcb_component_id===t.pcb_component_id)||[],f=pyt(d,t.center,t.rotation||0);l.push(...f),a.fpPads=l;const m=this.ctx.db.pcb_silkscreen_circle?.list().filter(O=>O.pcb_component_id===t.pcb_component_id)||[],w=a.fpCircles??[];w.push(...pQi(m,t.center));const D=this.ctx.db.pcb_courtyard_circle?.list().filter(O=>O.pcb_component_id===t.pcb_component_id)||[];w.push(...fQi(D,t.center)),a.fpCircles=w;const x=this.ctx.db.pcb_fabrication_note_rect?.list().filter(O=>O.pcb_component_id===t.pcb_component_id)||[],_=a.fpRects??[];_.push(...yQi(x,t.center));const b=this.ctx.db.pcb_note_rect?.list().filter(O=>O.pcb_component_id===t.pcb_component_id)||[];_.push(...mQi(b,t.center));const R=this.ctx.db.pcb_courtyard_rect?.list().filter(O=>O.pcb_component_id===t.pcb_component_id)||[];_.push(...wQi(R,t.center)),a.fpRects=_;const F=this.ctx.db.pcb_courtyard_outline?.list().filter(O=>O.pcb_component_id===t.pcb_component_id)||[],H=DQi(F,t.center);if(H.length>0&&(a.fpPolys=H),n){const W=this.ctx.db.pcb_board?.list()[0]?.thickness??0,z=t.layer==="bottom"?-(W/2):W/2,tA=_Qi(n,t.center,{boardLayerZOffset:z}),aA="${KIPRJMOD}/3dmodels";if(tA.length>0)this.includeBuiltin3dModels?a.models=tA.map(eA=>{if(!eA.path)return eA;const oA=b2A(eA.path),lA=eA.path.startsWith("http://modelcdn.tscircuit.com")||eA.path.startsWith("https://modelcdn.tscircuit.com")?"tscircuit_builtin":this.ctx.projectName??oA.replace(/\.[^.]+$/,""),pA=new L3(`${aA}/${lA}.3dshapes/${oA}`);eA.offset&&(pA.offset=eA.offset),eA.scale&&(pA.scale=eA.scale),eA.rotate&&(pA.rotate=eA.rotate);const kA=eA.path?.split("?")[0];return kA&&!this.ctx.pcbModel3dSourcePaths?.includes(kA)&&this.ctx.pcbModel3dSourcePaths?.push(kA),pA}):a.models=tA;else if(n.footprinter_string&&this.includeBuiltin3dModels){const{footprinter_string:eA}=n,oA=`${aA}/tscircuit_builtin.3dshapes/${eA}.step`;a.models=[new L3(oA)];const rA=`${dyt}/${eA}.step`;this.ctx.pcbModel3dSourcePaths?.includes(rA)||this.ctx.pcbModel3dSourcePaths?.push(rA)}}const Y=t.metadata?.kicad_footprint;Y&&i?.name&&dQi(a,Y,i.name);const J=e.footprints;J.push(a),e.footprints=J,this.componentsProcessed++}getOutput(){return this.ctx.kicadPcb}},NQi={top:"F.Cu",bottom:"B.Cu",inner1:"In1.Cu",inner2:"In2.Cu",inner3:"In3.Cu",inner4:"In4.Cu",inner5:"In5.Cu",inner6:"In6.Cu"};function LQi(e){return e&&(NQi[e]||e)||"F.Cu"}function UQi(e){const A=["F.Cu"];for(let t=1;t<e-1;t++)A.push(`In${t}.Cu`);return A.push("B.Cu"),A}var HQi=class extends t0{tracesProcessed=0;pcbTraces=[];constructor(e,A){super(e,A),this.pcbTraces=this.ctx.db.pcb_trace.list()}_step(){const{kicadPcb:e,c2kMatPcb:A,pcbNetMap:t}=this.ctx;if(!e)throw new Error("KicadPcb instance not initialized in context");if(!A)throw new Error("PCB transformation matrix not initialized in context");if(this.tracesProcessed>=this.pcbTraces.length){this.finished=!0;return}const i=this.pcbTraces[this.tracesProcessed];if(!i.route||i.route.length<2){this.tracesProcessed++;return}let n=i.route[0]?.layer;for(let o=0;o<i.route.length-1;o++){const s=i.route[o],r=i.route[o+1],a=Ct(A,{x:s.x,y:s.y}),g=Ct(A,{x:r.x,y:r.y});let c;if(t){let h=i.subcircuit_connectivity_map_key;if(!h&&i.source_trace_id){const E=this.ctx.db.source_trace?.get(i.source_trace_id);if(E&&(h=E.subcircuit_connectivity_map_key,!h&&E.connected_source_net_ids?.length))for(const u of E.connected_source_net_ids){const d=this.ctx.db.source_net?.get(u);if(d?.subcircuit_connectivity_map_key){h=d.subcircuit_connectivity_map_key;break}}}if(!h&&typeof i.connection_name=="string"){const E=this.ctx.db.source_net?.get(i.connection_name);E?.subcircuit_connectivity_map_key&&(h=E.subcircuit_connectivity_map_key)}h&&(c=t.get(h))}const I=s.layer??r.layer??n,l=LQi(I),B=`segment:${a.x},${a.y}:${g.x},${g.y}:${l}:${c?.id??0}`,C=new _1A({start:{x:a.x,y:a.y},end:{x:g.x,y:g.y},layer:l,width:i.width||.25,net:new rj(c?.id??0),uuid:cd(B)}),Q=e.segments;Q.push(C),e.segments=Q,s.layer&&(n=s.layer),r.layer&&(n=r.layer)}this.tracesProcessed++}getOutput(){return this.ctx.kicadPcb}},YQi=class extends t0{viasProcessed=0;pcbVias=[];constructor(e,A){super(e,A),this.pcbVias=this.ctx.db.pcb_via?.list()||[]}_step(){const{kicadPcb:e,c2kMatPcb:A,pcbNetMap:t}=this.ctx;if(!e)throw new Error("KicadPcb instance not initialized in context");if(!A)throw new Error("PCB transformation matrix not initialized in context");if(this.viasProcessed>=this.pcbVias.length){this.finished=!0;return}const i=this.pcbVias[this.viasProcessed],n=Ct(A,{x:i.x,y:i.y});let o;if(t){let I=i.subcircuit_connectivity_map_key;if(!I&&i.pcb_trace_id){const l=this.ctx.db.pcb_trace?.get(i.pcb_trace_id);if(l&&("subcircuit_connectivity_map_key"in l&&(I=l.subcircuit_connectivity_map_key),!I&&l.source_trace_id)){const B=this.ctx.db.source_trace?.get(l.source_trace_id);if(B&&("subcircuit_connectivity_map_key"in B&&(I=B.subcircuit_connectivity_map_key),!I&&B.connected_source_net_ids?.length))for(const C of B.connected_source_net_ids){const Q=this.ctx.db.source_net?.get(C);if(Q?.subcircuit_connectivity_map_key){I=Q.subcircuit_connectivity_map_key;break}}}}if(!I&&i.connection_name){const l=this.ctx.db.source_net?.get(i.connection_name);l?.subcircuit_connectivity_map_key&&(I=l.subcircuit_connectivity_map_key)}I&&(o=t.get(I))}const s=this.ctx.numLayers??2,r=i.layers?i.layers.map(I=>I==="top"?"F.Cu":I==="bottom"?"B.Cu":`In${I.replace("inner","")}.Cu`):UQi(s),a=`via:${n.x},${n.y}:${i.outer_diameter||.8}:${i.hole_diameter||.4}:${o?.id??0}`,g=new D2A({at:[n.x,n.y],size:i.outer_diameter||.8,drill:i.hole_diameter||.4,layers:r,net:new w2A(o?.id??0),uuid:cd(a)}),c=e.vias;c.push(g),e.vias=c,this.viasProcessed++}getOutput(){return this.ctx.kicadPcb}},JQi=class extends t0{holesProcessed=0;standaloneHoles=[];constructor(e,A){super(e,A),this.standaloneHoles=this.ctx.db.pcb_hole.list().filter(t=>!t.pcb_component_id)}_step(){const{kicadPcb:e,c2kMatPcb:A}=this.ctx;if(!e)throw new Error("KicadPcb instance not initialized in context");if(!A)throw new Error("PCB transformation matrix not initialized in context");if(this.holesProcessed>=this.standaloneHoles.length){this.finished=!0;return}const t=this.standaloneHoles[this.holesProcessed];if(!t){this.holesProcessed++;return}const i=Ct(A,{x:0,y:0}),n=`standalone_hole:${t.pcb_hole_id}:${t.x},${t.y}`,o=new nj({libraryLink:"tscircuit:MountingHole",layer:"F.Cu",at:[i.x,i.y,0],uuid:cd(n)}),r=pyt([t],{x:0,y:0},0);if(r.length>0){o.fpPads=r;const a=e.footprints;a.push(o),e.footprints=a}this.holesProcessed++}getOutput(){return this.ctx.kicadPcb}};function TQi({textElement:e,c2kMatPcb:A}){if(!e.text||!e.anchor_position)return null;const t=Ct(A,{x:e.anchor_position.x,y:e.anchor_position.y}),n={top:"F.Fab",bottom:"B.Fab"}[e.layer]||e.layer||"F.Fab",o=(e.font_size||1)/1.5,s=new Tp;s.size={width:o,height:o};const r=new a6,a=e.anchor_alignment||"center";switch(a){case"top_left":r.horizontal="left",r.vertical="top";break;case"top_right":r.horizontal="right",r.vertical="top";break;case"bottom_left":r.horizontal="left",r.vertical="bottom";break;case"bottom_right":r.horizontal="right",r.vertical="bottom";break}const g=new Jp({font:s});a!=="center"&&(g.justify=r);const c=new oc([t.x,t.y,0]),I=new sj({text:e.text,layer:n,effects:g});return I.position=c,I}function PQi({textElement:e,c2kMatPcb:A}){if(!e.text||!e.anchor_position)return null;const t=Ct(A,{x:e.anchor_position.x,y:e.anchor_position.y}),n={top:"F.SilkS",bottom:"B.SilkS"}[e.layer]||e.layer||"F.SilkS",o=(e.font_size||1)/1.5,s=new Tp;s.size={width:o,height:o};const r=new a6,a=e.anchor_alignment||"center";switch(a){case"top_left":r.horizontal="left",r.vertical="top";break;case"top_right":r.horizontal="right",r.vertical="top";break;case"bottom_left":r.horizontal="left",r.vertical="bottom";break;case"bottom_right":r.horizontal="right",r.vertical="bottom";break}const g=new Jp({font:s});a!=="center"&&(g.justify=r);const c=e.ccw_rotation||0,I=new oc([t.x,t.y,c]),l=new sj({text:e.text,layer:n,effects:g});return l.position=I,l}var KQi=class extends t0{_step(){const{kicadPcb:e,c2kMatPcb:A}=this.ctx;if(!e)throw new Error("KicadPcb instance not initialized in context");if(!A)throw new Error("PCB transformation matrix not initialized in context");const t=this.ctx.db.pcb_silkscreen_path?.list()||[];for(const s of t)if(!(!s.route||s.route.length<2))for(let r=0;r<s.route.length-1;r++){const a=s.route[r],g=s.route[r+1];if(!a||!g)continue;const c=Ct(A,{x:a.x,y:a.y}),I=Ct(A,{x:g.x,y:g.y}),B={top:"F.SilkS",bottom:"B.SilkS"}[s.layer]||s.layer||"F.SilkS",C=new oj({start:{x:c.x,y:c.y},end:{x:I.x,y:I.y},layer:B,width:s.stroke_width||.15}),Q=e.graphicLines;Q.push(C),e.graphicLines=Q}const i=this.ctx.db.pcb_silkscreen_text?.list().filter(s=>!s.pcb_component_id)||[];for(const s of i){const r=PQi({textElement:s,c2kMatPcb:A});if(r){const a=e.graphicTexts;a.push(r),e.graphicTexts=a}}const n=this.ctx.db.pcb_fabrication_note_text?.list()||[];for(const s of n){const r=TQi({textElement:s,c2kMatPcb:A});if(r){const a=e.graphicTexts;a.push(r),e.graphicTexts=a}}const o=this.ctx.db.pcb_board?.list()||[];if(o.length>0){const s=o[0];if(!s){this.finished=!0;return}let r;if(s.outline&&s.outline.length>0)r=s.outline;else{const g=s.width?s.width/2:0,c=s.height?s.height/2:0;r=[{x:s.center.x-g,y:s.center.y-c},{x:s.center.x+g,y:s.center.y-c},{x:s.center.x+g,y:s.center.y+c},{x:s.center.x-g,y:s.center.y+c}]}const a=r.map(g=>Ct(A,g));for(let g=0;g<a.length;g++){const c=a[g],I=a[(g+1)%a.length];if(!c||!I)continue;const l=new oj({start:{x:c.x,y:c.y},end:{x:I.x,y:I.y},layer:"Edge.Cuts",width:.1}),B=e.graphicLines;B.push(l),e.graphicLines=B}}this.finished=!0}getOutput(){return this.ctx.kicadPcb}},fyt=class{ctx;pipeline;currentStageIndex=0;finished=!1;get currentStage(){return this.pipeline[this.currentStageIndex]}constructor(e,A){this.ctx={db:Na(e),circuitJson:e,kicadPcb:new x2A({generator:"circuit-json-to-kicad",generatorVersion:"0.0.1"}),c2kMatPcb:tn(sn(100,100),za(1,-1)),projectName:A?.projectName,pcbModel3dSourcePaths:[]},this.pipeline=[new lQi(e,this.ctx),new BQi(e,this.ctx),new RQi(e,this.ctx,{includeBuiltin3dModels:A?.includeBuiltin3dModels}),new HQi(e,this.ctx),new YQi(e,this.ctx),new JQi(e,this.ctx),new KQi(e,this.ctx)]}step(){if(!this.currentStage){this.finished=!0;return}this.currentStage.step(),this.currentStage.finished&&this.currentStageIndex++}runUntilFinished(){for(;!this.finished;)this.step()}getOutput(){return this.ctx.kicadPcb}getOutputString(){return this.ctx.kicadPcb.getString()}getModel3dSourcePaths(){return this.ctx.pcbModel3dSourcePaths??[]}},qQi=class{ctx;project;constructor(e,A={}){const t=A.projectName??e?.project?.name??"circuit-json-project",i=A.schematicFilename??`${t}.kicad_sch`,n=A.pcbFilename??`${t}.kicad_pcb`,o=new Date().toISOString();this.ctx={db:Na(e),circuitJson:e},this.project={version:1,head:{generator:"circuit-json-to-kicad",generator_version:"0.0.1",project_name:t,created:o,modified:o},meta:{version:1},text_variables:{},libraries:{pinned_symbol_libs:[],pinned_footprint_libs:[]},boards:[],cvpcb:{meta:{version:0}},erc:{meta:{version:0},erc_exclusions:[]},net_settings:{meta:{version:1},last_net_id:0,classes:[]},pcbnew:{page_layout_descr_file:"",last_paths:{}},schematic:{meta:{version:1},page_layout_descr_file:"",last_opened_files:[i]},board:{meta:{version:1},last_opened_board:n},sheets:[[Math.random().toString(36).substring(2,15),"Root"]]}}runUntilFinished(){}getOutput(){return this.project}getOutputString(){return`${JSON.stringify(this.project,null,2)}
5830
5830
  `}},OQi=class extends t0{_step(){const e=new uyt(this.ctx.circuitJson);e.runUntilFinished(),this.ctx.kicadSchString=e.getOutputString();const A=new fyt(this.ctx.circuitJson);A.runUntilFinished(),this.ctx.kicadPcbString=A.getOutputString(),this.finished=!0}getOutput(){return this.ctx.libraryOutput}},WQi=class extends t0{isCustomSymbol(e){return e?.startsWith("Custom:")??!1}_step(){const e=this.ctx.kicadSchString,A=this.ctx.fpLibraryName??"tscircuit";if(!e)throw new Error("Schematic content not available. Run GenerateKicadSchAndPcbStage first.");const t=new Map;try{const n=lyt(e).find(r=>r instanceof EDA);if(!n){this.ctx.symbolEntries=[],this.finished=!0;return}const o=n.libSymbols;if(!o){this.ctx.symbolEntries=[],this.finished=!0;return}const s=o.symbols??[];for(const r of s){const a=this.isCustomSymbol(r.libraryId),g=this.sanitizeSymbolName(r.libraryId);t.has(g)||(r.libraryId=g,this.updateFootprintProperty(r,A),a||this.snapPinPositionsToGrid(r),t.set(g,{symbolName:g,symbol:r,isBuiltin:!a}))}}catch(i){console.warn("Failed to parse schematic for symbol extraction:",i)}this.ctx.symbolEntries=Array.from(t.values()),this.finished=!0}updateFootprintProperty(e,A){const t=e.properties??[];for(const i of t)if(i.key==="Footprint"&&i.value){const n=i.value.split(":");n.length>1?i.value=`${A}:${n[1]}`:i.value.trim()&&(i.value=`${A}:${i.value}`)}}sanitizeSymbolName(e){if(!e)return"symbol";const A=e.split(":");return(A.length>1?A[1]:A[0])?.replace(/[\\\/]/g,"-").trim()||"symbol"}snapPinPositionsToGrid(e){for(const t of e.subSymbols??[]){for(const i of t.pins??[])i.at&&(i.at.x=Math.round(i.at.x/1.27)*1.27,i.at.y=Math.round(i.at.y/1.27)*1.27);for(const i of t.polylines??[])if(i.points?.points)for(const n of i.points.points)"x"in n&&"y"in n&&(n.x=Math.round(n.x/1.27)*1.27,n.y=Math.round(n.y/1.27)*1.27)}}getOutput(){return this.ctx.libraryOutput}},ZQi=20211014,VQi="circuit-json-to-kicad",jQi=class extends t0{_step(){const e=this.ctx.symbolEntries??[],A=this.generateSymbolLibrary(e);this.ctx.libraryOutput||(this.ctx.libraryOutput={kicadSymString:"",symbols:[],footprints:[],fpLibTableString:"",symLibTableString:"",model3dSourcePaths:[]}),this.ctx.libraryOutput.kicadSymString=A,this.finished=!0}generateSymbolLibrary(e){return new Fdt({version:ZQi,generator:VQi,symbols:e.map(t=>t.symbol)}).getString()}getOutput(){return this.ctx.libraryOutput}},zQi=class extends t0{_step(){const e=this.ctx.libraryName??"tscircuit",A=this.ctx.fpLibraryName??"tscircuit",t=this.ctx.footprintEntries??[],i=this.ctx.symbolEntries??[],n=new Set;for(const r of t)for(const a of r.model3dSourcePaths)n.add(a);const o=this.generateFpLibTable(A),s=this.generateSymLibTable(e);this.ctx.libraryOutput||(this.ctx.libraryOutput={kicadSymString:"",symbols:[],footprints:[],fpLibTableString:"",symLibTableString:"",model3dSourcePaths:[]}),this.ctx.libraryOutput.symbols=i,this.ctx.libraryOutput.footprints=t,this.ctx.libraryOutput.fpLibTableString=o,this.ctx.libraryOutput.symLibTableString=s,this.ctx.libraryOutput.model3dSourcePaths=Array.from(n),this.finished=!0}generateFpLibTable(e){return`(fp_lib_table
5831
5831
  (version 7)
5832
5832
  (lib (name "${e}") (type "KiCad") (uri "\${KIPRJMOD}/${e}.pretty") (options "") (descr "Generated by circuit-json-to-kicad"))