@tscircuit/runframe 0.0.1589 → 0.0.1591

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5135,7 +5135,7 @@ ${a.join(`
5135
5135
  ${Q}polygon: ${C.polygon.vertices}
5136
5136
  `:a+=`
5137
5137
  `,C.children.length>0&&c.push(C.children)}return a}};A.exports=s}}),Afe=st({"node_modules/@jscad/modeling/src/operations/booleans/trees/Tree.js"(e,A){var t=jpe(),i=$pe(),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}}),oEA=st({"node_modules/@jscad/modeling/src/operations/booleans/trees/index.js"(e,A){A.exports={Tree:Afe()}}}),tfe=st({"node_modules/@jscad/modeling/src/operations/booleans/intersectGeom3Sub.js"(e,A){var t=zo(),i=nEA(),{Tree:n}=oEA(),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}}),TXA=st({"node_modules/@jscad/modeling/src/operations/booleans/intersectGeom3.js"(e,A){var t=vo(),i=mH(),n=tfe(),o=(...s)=>{s=t(s);let r=s.shift();return s.forEach(a=>{r=n(r,a)}),r=i(r),r};A.exports=o}}),efe=st({"node_modules/@jscad/modeling/src/operations/booleans/intersectGeom2.js"(e,A){var t=vo(),i=zo(),n=y_(),o=eEA(),s=iEA(),r=TXA(),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}}),ife=st({"node_modules/@jscad/modeling/src/operations/booleans/intersect.js"(e,A){var t=vo(),i=yH(),n=jo(),o=zo(),s=efe(),r=TXA(),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}}),nfe=st({"node_modules/@jscad/modeling/src/operations/booleans/scissionGeom3.js"(e,A){var t=wn(),i=y_(),n=zo(),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,p)=>{d.vertices.forEach(m=>{s(B,t.snap(C,m,c),p)})});const Q=I.map(d=>{let p=[];return d.vertices.forEach(m=>{p=p.concat(r(B,t.snap(C,m,c)))}),{e:1,d:o(p)}});B.clear();let h=0;const E=Q.length;for(let d=0;d<E;d++){const p=Q[d];if(p.e>0){const m=new Array(l);m[d]=!0;do h=0,m.forEach((w,D)=>{const S=Q[D];if(S.e>0){S.e=-1;for(let k=0;k<S.d.length;k++)m[S.d[k]]=!0;h++}});while(h>0);p.indexes=m}}const u=[];for(let d=0;d<E;d++)if(Q[d].indexes){const p=[];Q[d].indexes.forEach((m,w)=>p.push(I[w])),u.push(n.create(p))}return u};A.exports=a}}),ofe=st({"node_modules/@jscad/modeling/src/operations/booleans/scission.js"(e,A){var t=vo(),i=zo(),n=nfe(),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}}),sfe=st({"node_modules/@jscad/modeling/src/operations/booleans/subtractGeom3Sub.js"(e,A){var t=zo(),i=nEA(),{Tree:n}=oEA(),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}}),KXA=st({"node_modules/@jscad/modeling/src/operations/booleans/subtractGeom3.js"(e,A){var t=vo(),i=mH(),n=sfe(),o=(...s)=>{s=t(s);let r=s.shift();return s.forEach(a=>{r=n(r,a)}),r=i(r),r};A.exports=o}}),rfe=st({"node_modules/@jscad/modeling/src/operations/booleans/subtractGeom2.js"(e,A){var t=vo(),i=zo(),n=y_(),o=eEA(),s=iEA(),r=KXA(),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}}),afe=st({"node_modules/@jscad/modeling/src/operations/booleans/subtract.js"(e,A){var t=vo(),i=yH(),n=jo(),o=zo(),s=rfe(),r=KXA(),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}}),PXA=st({"node_modules/@jscad/modeling/src/operations/booleans/unionGeom3Sub.js"(e,A){var t=zo(),i=nEA(),{Tree:n}=oEA(),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}}),qXA=st({"node_modules/@jscad/modeling/src/operations/booleans/unionGeom3.js"(e,A){var t=vo(),i=mH(),n=PXA(),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}}),OXA=st({"node_modules/@jscad/modeling/src/operations/booleans/unionGeom2.js"(e,A){var t=vo(),i=zo(),n=y_(),o=eEA(),s=iEA(),r=qXA(),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}}),sEA=st({"node_modules/@jscad/modeling/src/operations/booleans/union.js"(e,A){var t=vo(),i=yH(),n=jo(),o=zo(),s=OXA(),r=qXA(),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}}),nv=st({"node_modules/@jscad/modeling/src/operations/booleans/index.js"(e,A){A.exports={intersect:ife(),scission:ofe(),subtract:afe(),union:sEA()}}}),GW=st({"node_modules/@jscad/modeling/src/operations/expansions/offsetFromPoints.js"(e,A){var{EPS:t,TAU:i}=fr(),n=fXA(),o=jhA(),s=fs(),r=_W(),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 p=[],m=s.create(),w=c.length;for(let D=0;D<w;D++){const S=(D+1)%w,k=c[D],x=c[S];E?s.subtract(m,k,x):s.subtract(m,x,k),s.normal(m,m),s.normalize(m,m),s.scale(m,m,l);const N=s.add(s.create(),k,m),M=s.add(s.create(),x,m),L=[N,M];if(u!=null&&(C||!C&&S!==0)){const Y=n(u[0],u[1],L[0],L[1]);Y?(d.pop(),L[0]=Y):p.push({c:k,s0:u,s1:L})}u=[N,M],!(S===0&&!C)&&(d.push(L[0]),d.push(L[1]))}if(C&&u!=null){const D=d[0],S=d[1],k=n(u[0],u[1],D,S);if(k)d[0]=k,d.pop();else{const x=c[0],N=[D,S];p.push({c:x,s0:u,s1:N})}}if(B==="edge"){const D=new Map;d.forEach((x,N)=>D.set(x,N));const S=o.create(),k=o.create();p.forEach(x=>{o.fromPoints(S,x.s0[0],x.s0[1]),o.fromPoints(k,x.s1[0],x.s1[1]);const N=o.intersectPointOfLines(S,k);if(Number.isFinite(N[0])&&Number.isFinite(N[1])){const M=x.s0[1],L=D.get(M);d[L]=N,d[(L+1)%d.length]=void 0}else{const M=x.s1[0],L=D.get(M);d[L]=void 0}}),d=d.filter(x=>x!==void 0)}if(B==="round"){let D=Math.floor(Q/4);const S=s.create();p.forEach(k=>{let x=s.angle(s.subtract(S,k.s1[0],k.c));if(x-=s.angle(s.subtract(S,k.s0[1],k.c)),E&&x<0&&(x=x+Math.PI,x<0&&(x=x+Math.PI)),!E&&x>0&&(x=x-Math.PI,x>0&&(x=x-Math.PI)),x!==0){D=Math.floor(Q*(Math.abs(x)/i));const N=x/D,M=s.angle(s.subtract(S,k.s0[1],k.c)),L=[];for(let Y=1;Y<D;Y++){const H=M+N*Y,O=s.fromAngleRadians(s.create(),H);s.scale(O,O,l),s.add(O,O,k.c),L.push(O)}if(L.length>0){const Y=k.s0[1];let H=d.findIndex(O=>s.equals(Y,O));H=(H+1)%d.length,d.splice(H,0,...L)}}else{const N=k.s1[0],M=d.findIndex(L=>s.equals(N,L));d.splice(M,1)}})}return d};A.exports=a}}),gfe=st({"node_modules/@jscad/modeling/src/operations/expansions/expandGeom2.js"(e,A){var t=jo(),i=GW(),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}}),cfe=st({"node_modules/@jscad/modeling/src/operations/expansions/extrudePolygon.js"(e,A){var t=jg(),i=wn(),n=zo(),o=or(),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}}),Ife=st({"node_modules/@jscad/modeling/src/operations/expansions/expandShell.js"(e,A){var{EPS:t,TAU:i}=fr(),n=jg(),o=wn(),s=YXA(),r=zo(),a=or(),g=RXA(),c=mH(),I=PXA(),l=cfe(),B=(E,u,d)=>{const p=u.toString();if(E.has(p))E.get(p)[1].push(d);else{const m=[u,[d]];E.set(p,m)}},C=(E,u,d)=>{const p=u[0].toString(),m=u[1].toString(),w=p<m?`${p},${m}`:`${m},${p}`;if(E.has(w))E.get(w)[1].push(d);else{const D=[u,[d]];E.set(w,D)}},Q=(E,u)=>{E.findIndex(p=>p===u)<0&&E.push(u)},h=(E,u)=>{const d={delta:1,segments:12},{delta:p,segments:m}=Object.assign({},d,E);let w=r.create();const D=new Map,S=new Map,k=o.create(),x=o.create();return r.toPolygons(u).forEach((M,L)=>{const Y=o.scale(o.create(),a.plane(M),2*p),H=a.transform(n.fromTranslation(n.create(),o.scale(o.create(),Y,-.5)),M),O=l(Y,H);w=I(w,O);const Z=M.vertices;for(let $=0;$<Z.length;$++){B(D,Z[$],a.plane(M));const eA=($+1)%Z.length,aA=[Z[$],Z[eA]];C(S,aA,a.plane(M))}}),S.forEach(M=>{const L=M[0],Y=M[1],H=L[0],O=L[1],Z=o.subtract(o.create(),O,H);o.normalize(Z,Z);const $=Y[0],eA=o.cross(o.create(),$,Z);let aA=[];for(let YA=0;YA<m;YA++)Q(aA,YA*i/m);for(let YA=0,QA=Y.length;YA<QA;YA++){const _A=Y[YA],dA=o.dot(eA,_A),PA=o.dot($,_A);let JA=Math.atan2(dA,PA);JA<0&&(JA+=i),Q(aA,JA),JA=Math.atan2(-dA,-PA),JA<0&&(JA+=i),Q(aA,JA)}aA=aA.sort(s);const tA=aA.length;let nA,rA;const lA=[],fA=[],bA=[];for(let YA=-1;YA<tA;YA++){const QA=aA[YA<0?YA+tA:YA],_A=Math.sin(QA),dA=Math.cos(QA);o.scale(k,$,dA*p),o.scale(x,eA,_A*p),o.add(k,k,x);const PA=o.add(o.create(),H,k),JA=o.add(o.create(),O,k);let it=!1;if(YA>=0&&o.distance(PA,nA)<t&&(it=!0),!it){if(YA>=0){lA.push(PA),fA.push(JA);const pA=[rA,JA,PA,nA],tt=a.create(pA);bA.push(tt)}nA=PA,rA=JA}}fA.reverse(),bA.push(a.create(lA)),bA.push(a.create(fA));const GA=r.create(bA);w=I(w,GA)}),D.forEach(M=>{const L=M[0],Y=M[1],H=Y[0];let O=null,Z=0;for(let tA=1;tA<Y.length;tA++){const nA=Y[tA],rA=o.cross(k,H,nA),lA=o.length(rA);lA>.05&&lA>Z&&(Z=lA,O=nA)}O||(O=o.orthogonal(k,H));const $=o.cross(k,H,O);o.normalize($,$);const eA=o.cross(x,$,H),aA=g({center:[L[0],L[1],L[2]],radius:p,segments:m,axes:[H,$,eA]});w=I(w,aA)}),c(w)};A.exports=h}}),lfe=st({"node_modules/@jscad/modeling/src/operations/expansions/expandGeom3.js"(e,A){var t=zo(),i=sEA(),n=Ife(),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}}),Bfe=st({"node_modules/@jscad/modeling/src/operations/expansions/expandPath2.js"(e,A){var t=_W(),i=fs(),n=jo(),o=_g(),s=GW(),r=c=>{let{external:I,internal:l}=c;t(I)<0?I=I.reverse():l=l.reverse();const B=o.fromPoints({closed:!0},I),C=o.fromPoints({closed:!0},l),Q=n.toSides(n.fromPoints(o.toPoints(B))),h=n.toSides(n.fromPoints(o.toPoints(C)));return Q.push(...h),n.create(Q)},a=(c,I,l,B)=>{const{points:C,external:Q,internal:h}=c,E=Math.floor(I/2),u=[],d=[];if(l==="round"&&E>0){const m=Math.PI/E,w=C[C.length-1],D=i.angle(i.subtract(i.create(),Q[Q.length-1],w)),S=C[0],k=i.angle(i.subtract(i.create(),h[0],S));for(let x=1;x<E;x++){let N=D+m*x,M=i.fromAngleRadians(i.create(),N);i.scale(M,M,B),i.add(M,M,w),u.push(M),N=k+m*x,M=i.fromAngleRadians(i.create(),N),i.scale(M,M,B),i.add(M,M,S),d.push(M)}}const p=[];return p.push(...Q,...u,...h.reverse(),...d),n.fromPoints(p)},g=(c,I)=>{c=Object.assign({},{delta:1,corners:"edge",segments:16},c);const{delta:B,corners:C,segments:Q}=c;if(B<=0)throw new Error("the given delta must be positive for paths");if(!(C==="edge"||C==="chamfer"||C==="round"))throw new Error('corners must be "edge", "chamfer", or "round"');const h=I.isClosed,E=o.toPoints(I);if(E.length===0)throw new Error("the given geometry cannot be empty");const u={points:E,external:s({delta:B,corners:C,segments:Q,closed:h},E),internal:s({delta:-B,corners:C,segments:Q,closed:h},E)};return I.isClosed?r(u):a(u,Q,C,B)};A.exports=g}}),rEA=st({"node_modules/@jscad/modeling/src/operations/expansions/expand.js"(e,A){var t=vo(),i=jo(),n=zo(),o=_g(),s=gfe(),r=lfe(),a=Bfe(),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}}),Cfe=st({"node_modules/@jscad/modeling/src/operations/expansions/offsetGeom2.js"(e,A){var t=jo(),i=qhA(),n=GW(),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}}),Qfe=st({"node_modules/@jscad/modeling/src/operations/expansions/offsetPath2.js"(e,A){var t=_g(),i=GW(),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}}),hfe=st({"node_modules/@jscad/modeling/src/operations/expansions/offset.js"(e,A){var t=vo(),i=jo(),n=_g(),o=Cfe(),s=Qfe(),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}}),WXA=st({"node_modules/@jscad/modeling/src/operations/expansions/index.js"(e,A){A.exports={expand:rEA(),offset:hfe()}}}),RW=st({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeLinearGeom2.js"(e,A){var t=jg(),i=wn(),n=jo(),o=iv(),s=FW(),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=(p,m,w)=>{const D=m/B*l,S=i.scale(i.create(),Q,m/B);return t.multiply(u,t.fromZRotation(u,D),t.fromTranslation(t.create(),S)),o.transform(u,w)};return a={numberOfSlices:B+1,capStart:!0,capEnd:!0,repair:C,callback:d},s(a,E)};A.exports=r}}),Efe=st({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeLinearPath2.js"(e,A){var t=jo(),i=_g(),n=RW(),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}}),ufe=st({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeLinear.js"(e,A){var t=vo(),i=jo(),n=_g(),o=RW(),s=Efe(),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}}),dfe=st({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeRectangularPath2.js"(e,A){var t=_g(),i=rEA(),n=RW(),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}}),pfe=st({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeRectangularGeom2.js"(e,A){var{area:t}=uH(),i=jo(),n=_g(),o=rEA(),s=RW(),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}}),ffe=st({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeRectangular.js"(e,A){var t=vo(),i=jo(),n=_g(),o=dfe(),s=pfe(),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}}),yfe=st({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeHelical.js"(e,A){var{TAU:t}=fr(),i=jg(),n=jo(),o=FW(),s=iv(),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(x=>x[0][0]>=0);let p=s.fromSides(u);d.length===0&&(p=s.reverse(p));const m=Math.round(h/t*Math.abs(I)),w=m>=2?m:2,D=i.create(),S=i.create(),k=(x,N,M)=>{const L=l+I/w*N,Y=Q/w*N,H=(L-l)/t*B;return i.multiply(D,i.fromTranslation(i.create(),[Y,0,H*Math.sign(I)]),i.fromXRotation(i.create(),-t/4*Math.sign(I))),i.multiply(S,i.fromZRotation(i.create(),L),D),s.transform(S,M)};return o({numberOfSlices:w+1,callback:k},p)};A.exports=r}}),mfe=st({"node_modules/@jscad/modeling/src/operations/extrusions/project.js"(e,A){var t=vo(),i=VhA(),n=pD(),o=jg(),s=jo(),r=zo(),a=or(),g=y_(),c=OXA(),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(k=>n.projectionOfPoint(Q,k)),D=a.create(w),S=a.plane(D);i(Q,S)&&(a.measureArea(D)<E||d.push(D))}if(!i(Q,[0,0,1])){const m=o.fromVectorRotation(o.create(),Q,[0,0,1]);d=d.map(w=>a.transform(m,w))}d=d.sort((m,w)=>a.measureArea(w)-a.measureArea(m));const p=d.map(m=>s.fromPoints(m.vertices));return c(p)},l=(B,...C)=>{const Q={axis:[0,0,1],origin:[0,0,0]},{axis:h,origin:E}=Object.assign({},Q,B);if(C=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}}),wH=st({"node_modules/@jscad/modeling/src/operations/extrusions/index.js"(e,A){A.exports={extrudeFromSlices:FW(),extrudeLinear:ufe(),extrudeRectangular:ffe(),extrudeRotate:LXA(),extrudeHelical:yfe(),project:mfe(),slice:iv()}}}),aEA=st({"node_modules/@jscad/modeling/src/operations/hulls/hullPoints2.js"(e,A){var t=fs(),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}}),gEA=st({"node_modules/@jscad/modeling/src/operations/hulls/toUniquePoints.js"(e,A){var t=jo(),i=zo(),n=_g(),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}}),wfe=st({"node_modules/@jscad/modeling/src/operations/hulls/hullPath2.js"(e,A){var t=vo(),i=_g(),n=aEA(),o=gEA(),s=(...r)=>{r=t(r);const a=o(r),g=n(a);return i.fromPoints({closed:!0},g)};A.exports=s}}),Dfe=st({"node_modules/@jscad/modeling/src/operations/hulls/hullGeom2.js"(e,A){var t=vo(),i=jo(),n=aEA(),o=gEA(),s=(...r)=>{r=t(r);const a=o(r),g=n(a);return g.length<3?i.create():i.fromPoints(g)};A.exports=s}}),ZXA=st({"node_modules/@jscad/modeling/src/operations/hulls/hullPoints3.js"(e,A){var t=or(),i=OzA(),n=o=>i(o,{skipTriangulation:!0}).map(a=>{const g=a.map(c=>o[c]);return t.create(g)});A.exports=n}}),Sfe=st({"node_modules/@jscad/modeling/src/operations/hulls/hullGeom3.js"(e,A){var t=vo(),i=zo(),n=gEA(),o=ZXA(),s=(...r)=>{r=t(r);const a=n(r);return a.length===0?i.create():i.create(o(a))};A.exports=s}}),VXA=st({"node_modules/@jscad/modeling/src/operations/hulls/hull.js"(e,A){var t=vo(),i=yH(),n=jo(),o=zo(),s=_g(),r=wfe(),a=Dfe(),g=Sfe(),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}}),bfe=st({"node_modules/@jscad/modeling/src/operations/hulls/hullChain.js"(e,A){var t=vo(),i=sEA(),n=VXA(),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}}),xfe=st({"node_modules/@jscad/modeling/src/operations/hulls/index.js"(e,A){A.exports={hull:VXA(),hullChain:bfe(),hullPoints2:aEA(),hullPoints3:ZXA()}}}),jXA=st({"node_modules/@jscad/modeling/src/operations/modifiers/snapPolygons.js"(e,A){var t=wn(),i=or(),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}}),_fe=st({"node_modules/@jscad/modeling/src/operations/modifiers/mergePolygons.js"(e,A){var t=VhA(),i=wn(),n=or(),o=E=>{const u=n.toPoints(E),d=[];for(let p=0;p<u.length;p++){const m=(p+1)%u.length,w={v1:u[p],v2:u[m]};d.push(w)}for(let p=0;p<d.length;p++){const m=(p+1)%u.length;d[p].next=d[m],d[m].prev=d[p]}return d},s=(E,u)=>{const d=`${u.v1}:${u.v2}`;E.set(d,u)},r=(E,u)=>{const d=`${u.v1}:${u.v2}`;E.delete(d)},a=(E,u)=>{const d=`${u.v2}:${u.v1}`;return E.get(d)},g=(E,u,d)=>{let p=E.prev.v1,m=E.prev.v2,w=u.next.v2;const D=l(p,m,w,d);p=u.prev.v1,m=u.prev.v2,w=E.next.v2;const S=l(p,m,w,d);return[D,S]},c=i.create(),I=i.create(),l=(E,u,d,p)=>{const m=i.subtract(c,u,E),w=i.subtract(I,d,u);return i.cross(m,m,w),i.dot(m,p)},B=E=>{let u;const d=[];for(;E.next;){const p=E.next;d.push(E.v1),E.v1=null,E.v2=null,E.next=null,E.prev=null,E=p}return d.length>0&&(u=n.create(d)),u},C=E=>{if(E.length<2)return E;const u=E[0].plane,d=E.slice(),p=new Map;for(;d.length>0;){const w=d.shift(),D=o(w);for(let S=0;S<D.length;S++){const k=D[S],x=a(p,k);if(x){const N=g(k,x,u);if(N[0]>=0&&N[1]>=0){const M=x.next,L=k.next;k.prev.next=x.next,k.next.prev=x.prev,x.prev.next=k.next,x.next.prev=k.prev,k.v1=null,k.v2=null,k.next=null,k.prev=null,r(p,x),x.v1=null,x.v2=null,x.next=null,x.prev=null;const Y=(H,O,Z)=>{const $={v1:Z.v1,v2:O.v2,next:O.next,prev:Z.prev};Z.prev.next=$,O.next.prev=$,r(H,O),O.v1=null,O.v2=null,O.next=null,O.prev=null,r(H,Z),Z.v1=null,Z.v2=null,Z.next=null,Z.prev=null};N[0]===0&&Y(p,M,M.prev),N[1]===0&&Y(p,L,L.prev)}}else k.next&&s(p,k)}}const m=[];return p.forEach(w=>{const D=B(w);D&&m.push(D)}),p.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 p=[];return d.forEach(m=>{const w=m[1],D=C(w);p=p.concat(D)}),p};A.exports=h}}),kfe=st({"node_modules/@jscad/modeling/src/operations/modifiers/insertTjunctions.js"(e,A){var t=fr(),i=wn(),n=or(),o=g=>`${g}`,s=(g,c,I,l,B,C)=>{const Q=o(l),h=o(B),E=`${Q}/${h}`,u=`${h}/${Q}`;if(g.has(u))return r(g,c,I,B,l,null),null;const d={vertex0:l,vertex1:B,polygonindex:C};return g.has(E)?g.get(E).push(d):g.set(E,[d]),c.has(Q)?c.get(Q).push(E):c.set(Q,[E]),I.has(h)?I.get(h).push(E):I.set(h,[E]),E},r=(g,c,I,l,B,C)=>{const Q=o(l),h=o(B),E=`${Q}/${h}`;let u=-1;const d=g.get(E);for(let p=0;p<d.length;p++){const m=d[p];let w=o(m.vertex0);if(w===Q&&(w=o(m.vertex1),w===h&&!(C!==null&&m.polygonindex!==C))){u=p;break}}d.splice(u,1),d.length===0&&g.delete(E),u=c.get(Q).indexOf(E),c.get(Q).splice(u,1),c.get(Q).length===0&&c.delete(Q),u=I.get(h).indexOf(E),I.get(h).splice(u,1),I.get(h).length===0&&I.delete(h)},a=g=>{const c=new Map;for(let I=0;I<g.length;I++){const l=g[I],B=l.vertices.length;if(B>=3){let C=l.vertices[0],Q=o(C);for(let h=0;h<B;h++){let E=h+1;E===B&&(E=0);const u=l.vertices[E],d=o(u),p=`${Q}/${d}`,m=`${d}/${Q}`;if(c.has(m)){const 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(p)?c.get(p).push(w):c.set(p,[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 p=c.get(E)[0];for(let m=0;m<2;m++){const w=m===0?p.vertex0:p.vertex1,D=m===0?p.vertex1:p.vertex0,S=o(w),k=o(D);let x=[];m===0?l.has(S)&&(x=l.get(S)):I.has(S)&&(x=I.get(S));for(let N=0;N<x.length;N++){const M=x[N],L=c.get(M)[0],Y=m===0?L.vertex0:L.vertex1;if(m===0?L.vertex1:L.vertex0,o(Y)===k){r(c,I,l,w,D,null),r(c,I,l,D,w,null),u=!1,m=2,Q=!0;break}else{const O=w,Z=D,$=Y,eA=i.subtract(i.create(),$,O),aA=i.dot(i.subtract(i.create(),Z,O),eA)/i.dot(eA,eA);if(aA>0&&aA<1){const tA=i.scale(i.create(),eA,aA);if(i.add(tA,tA,O),i.squaredDistance(tA,Z)<t.EPS*t.EPS){const rA=L.polygonindex,lA=C[rA],fA=o(L.vertex1);let bA=-1;for(let dA=0;dA<lA.vertices.length;dA++)if(o(lA.vertices[dA])===fA){bA=dA;break}const GA=lA.vertices.slice(0);GA.splice(bA,0,D);const YA=n.create(GA);C[rA]=YA,r(c,I,l,L.vertex0,L.vertex1,rA);const QA=s(c,I,l,L.vertex0,D,rA),_A=s(c,I,l,D,L.vertex1,rA);QA!==null&&B.set(QA,!0),_A!==null&&B.set(_A,!0),u=!1,m=2,Q=!0;break}}}}}}u&&B.delete(E)}if(!Q)break}g=C}return c.clear(),g};A.exports=a}}),Ffe=st({"node_modules/@jscad/modeling/src/operations/modifiers/triangulatePolygons.js"(e,A){var t=wn(),i=or(),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}}),Gfe=st({"node_modules/@jscad/modeling/src/operations/modifiers/generalize.js"(e,A){var t=vo(),i=y_(),n=jo(),o=zo(),s=_g(),r=jXA(),a=_fe(),g=kfe(),c=Ffe(),I=(Q,h)=>h,l=(Q,h)=>h,B=(Q,h)=>{const E={snap:!1,simplify:!1,triangulate:!1},{snap:u,simplify:d,triangulate:p}=Object.assign({},E,Q),m=i(h);let w=o.toPolygons(h);u&&(w=r(m,w)),d&&(w=a(m,w)),p&&(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}}),Rfe=st({"node_modules/@jscad/modeling/src/operations/modifiers/snap.js"(e,A){var t=vo(),i=fs(),n=jo(),o=zo(),s=_g(),r=y_(),a=jXA(),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}}),Mfe=st({"node_modules/@jscad/modeling/src/operations/modifiers/index.js"(e,A){A.exports={generalize:Gfe(),snap:Rfe(),retessellate:mH()}}}),Nfe=st({"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}}),vfe=st({"node_modules/@jscad/modeling/src/operations/transforms/align.js"(e,A){var t=vo(),i=Nfe(),n=zhA(),{translate:o}=nG(),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}}),MW=st({"node_modules/@jscad/modeling/src/operations/transforms/center.js"(e,A){var t=vo(),i=jo(),n=zo(),o=_g(),s=eG(),{translate:r}=nG(),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}}}),NW=st({"node_modules/@jscad/modeling/src/operations/transforms/scale.js"(e,A){var t=vo(),i=jg(),n=jo(),o=zo(),s=_g(),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}}}),Lfe=st({"node_modules/@jscad/modeling/src/operations/transforms/transform.js"(e,A){var t=vo(),i=jo(),n=zo(),o=_g(),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}}),oG=st({"node_modules/@jscad/modeling/src/operations/transforms/index.js"(e,A){A.exports={align:vfe(),center:MW().center,centerX:MW().centerX,centerY:MW().centerY,centerZ:MW().centerZ,mirror:pH().mirror,mirrorX:pH().mirrorX,mirrorY:pH().mirrorY,mirrorZ:pH().mirrorZ,rotate:fH().rotate,rotateX:fH().rotateX,rotateY:fH().rotateY,rotateZ:fH().rotateZ,scale:NW().scale,scaleX:NW().scaleX,scaleY:NW().scaleY,scaleZ:NW().scaleZ,transform:Lfe(),translate:nG().translate,translateX:nG().translateX,translateY:nG().translateY,translateZ:nG().translateZ}}}),vW=st({"node_modules/@jscad/modeling/src/index.js"(e,A){A.exports={colors:xW(),curves:Rde(),geometries:OhA(),maths:npe(),measurements:lpe(),primitives:m_(),text:tEA(),utils:JXA(),booleans:nv(),expansions:WXA(),extrusions:wH(),hulls:xfe(),modifiers:Mfe(),transforms:oG()}}}),zXA=st({"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)}`)}}}}),Ufe=st({"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":"")}}}),Hfe=st({"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=Ufe(),o.destroy=l,Object.keys(i).forEach(B=>{o[B]=i[B]}),o.names=[],o.skips=[],o.formatters={};function n(B){let C=0;for(let Q=0;Q<B.length;Q++)C=(C<<5)-C+B.charCodeAt(Q),C|=0;return o.colors[Math.abs(C)%o.colors.length]}o.selectColor=n;function o(B){let C,Q=null,h,E;function u(...d){if(!u.enabled)return;const p=u,m=Number(new Date),w=m-(C||m);p.diff=w,p.prev=C,p.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,(k,x)=>{if(k==="%%")return"%";D++;const N=o.formatters[x];if(typeof N=="function"){const M=d[D];k=N.call(p,M),d.splice(D,1),D--}return k}),o.formatArgs.call(p,d),(p.log||o.log).apply(p,d)}return u.namespace=B,u.useColors=o.useColors(),u.color=o.selectColor(B),u.extend=s,u.destroy=o.destroy,Object.defineProperty(u,"enabled",{enumerable:!0,configurable:!1,get:()=>Q!==null?Q:(h!==o.namespaces&&(h=o.namespaces,E=o.enabled(B)),E),set:d=>{Q=d}}),typeof o.init=="function"&&o.init(u),u}function s(B,C){const Q=o(this.namespace+(typeof C>"u"?":":C)+B);return Q.log=this.log,Q}function r(B){o.save(B),o.namespaces=B,o.names=[],o.skips=[];const C=(typeof B=="string"?B:"").trim().replace(/\s+/g,",").split(",").filter(Boolean);for(const Q of C)Q[0]==="-"?o.skips.push(Q.slice(1)):o.names.push(Q)}function a(B,C){let Q=0,h=0,E=-1,u=0;for(;Q<B.length;)if(h<C.length&&(C[h]===B[Q]||C[h]==="*"))C[h]==="*"?(E=h,u=Q,h++):(Q++,h++);else if(E!==-1)h=E+1,u++,Q=u;else return!1;for(;h<C.length&&C[h]==="*";)h++;return h===C.length}function g(){const B=[...o.names,...o.skips.map(C=>"-"+C)].join(",");return o.enable(""),B}function c(B){for(const C of o.skips)if(a(B,C))return!1;for(const C of o.names)if(a(B,C))return!0;return!1}function I(B){return B instanceof Error?B.stack||B.message:B}function l(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return o.enable(o.load()),o}A.exports=t}}),Yfe=st({"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 LhA<"u"&&"env"in LhA&&(a=LhA.env.DEBUG),a}function s(){try{return localStorage}catch{}}A.exports=Hfe()(e);var{formatters:r}=A.exports;r.j=function(a){try{return JSON.stringify(a)}catch(g){return"[UnexpectedJSONParseError]: "+g.message}}}}),XXA={boardBody:!0,topCopper:!0,bottomCopper:!0,adhesive:!1,solderPaste:!1,topSilkscreen:!0,bottomSilkscreen:!0,topMask:!0,bottomMask:!0,throughHoleModels:!0,smtModels:!0,translucentModels:!0,modelsNotInPosFile:!1,modelsMarkedDNP:!1,modelBoundingBoxes:!1,threedAxis:!1,backgroundStart:!0,backgroundEnd:!0},$XA=V.createContext(void 0),Jfe=({children:e})=>{const[A,t]=V.useState(XXA),i=V.useCallback((s,r)=>{t(a=>({...a,[s]:r}))},[]),n=V.useCallback(()=>{t(XXA)},[]),o=V.useMemo(()=>({visibility:A,setLayerVisibility:i,resetToDefaults:n}),[A,i,n]);return W.jsx($XA.Provider,{value:o,children:e})},ov=()=>{const e=V.useContext($XA);if(!e)throw new Error("useLayerVisibility must be used within a LayerVisibilityProvider");return e},cEA=1.2;function A6A(e){return V.useMemo(()=>{if(!e)return cEA;try{return Di(e).pcb_board.list()[0]?.thickness??cEA}catch{return cEA}},[e])}var t6A=V.createContext(null),Ou=()=>{const e=V.useContext(t6A);if(!e)throw new Error("useThree must be used within a ThreeProvider");return e},DH=(e,A=[])=>{const{addFrameListener:t,removeFrameListener:i}=Ou();en.useEffect(()=>(t(e),()=>i(e)),[t,i,...A])},SH={clickToInteractOverlay:100,htmlElements:95,orientationCube:95,contextMenu:90,appearanceMenu:91},e6A=({children:e,position:A,style:t})=>{const{camera:i,renderer:n}=Ou(),o=V.useRef(document.createElement("div")),[s,r]=V.useState(null);return V.useEffect(()=>{const a=n?.domElement.parentNode;if(a)return a.style.position!=="relative"&&a.style.position!=="absolute"&&(a.style.position="relative"),a.appendChild(o.current),r(l5.createPortal(e,o.current)),()=>{a.contains(o.current)&&a.removeChild(o.current)}},[n,e]),DH(()=>{if(!i||!o.current||!n)return;const a=new Rt(...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=SH.htmlElements.toString(),t&&Object.assign(o.current.style,t)},[i,n,A,t]),s},i6A={in:25.4,inch:25.4,mil:.0254,mm:1,m:1e3,cm:10,ft:304.8,feet:304.8},Fr=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 i6A)return t*i6A[A];throw new Error(`Unsupported unit: ${A}`)},Gl=Fr,Tfe=Object.defineProperty,Kfe=(e,A)=>{for(var t in A)Tfe(e,t,{get:A[t],enumerable:!0})},Ib={};Kfe(Ib,{axial:()=>lye,bga:()=>f0e,breakoutheaders:()=>Dye,cap:()=>jfe,dfn:()=>W0e,diode:()=>Vfe,dip:()=>Ofe,electrolytic:()=>aDe,hc49:()=>bye,jst:()=>kwe,led:()=>zfe,lqfp:()=>mye,m2host:()=>_De,melf:()=>Hme,micromelf:()=>Kme,minimelf:()=>Fme,mlp:()=>k0e,ms012:()=>Aye,ms013:()=>eye,msop:()=>Ywe,pad:()=>xye,pinrow:()=>j0e,platedhole:()=>pDe,potentiometer:()=>oDe,pushbutton:()=>Eye,qfn:()=>b0e,qfp:()=>_0e,quad:()=>rv,radial:()=>Qye,res:()=>u0e,sma:()=>Wme,smb:()=>twe,smbf:()=>cDe,smc:()=>owe,smf:()=>zme,smtpad:()=>uDe,sod110:()=>Gwe,sod123:()=>aye,sod123f:()=>gme,sod123fl:()=>Bme,sod123w:()=>Kye,sod128:()=>fme,sod323:()=>Wye,sod323f:()=>ome,sod323fl:()=>Owe,sod323w:()=>Twe,sod523:()=>Rye,sod723:()=>Eme,sod80:()=>Hye,sod882:()=>tme,sod882d:()=>Nme,sod923:()=>zye,soic:()=>m0e,solderjumper:()=>zwe,son:()=>jwe,sop8:()=>Lye,sot:()=>yDe,sot223:()=>gwe,sot23:()=>Y0e,sot23w:()=>uwe,sot25:()=>P0e,sot323:()=>CDe,sot343:()=>DDe,sot363:()=>v0e,sot457:()=>ADe,sot563:()=>X0e,sot723:()=>nye,sot886:()=>U0e,sot89:()=>bme,sot963:()=>eDe,ssop:()=>G0e,stampboard:()=>dye,stampreceiver:()=>yye,to220:()=>_me,to92:()=>Fye,to92l:()=>FDe,to92s:()=>wwe,tqfp:()=>x0e,tssop:()=>M0e,vssop:()=>Lwe});var Oi=(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"}),Wi=jA({norefdes:gt().optional().describe("disable reference designator label"),invert:gt().optional().describe("hint to invert the orientation of the 3D model"),faceup:gt().optional().describe("The male pin header should face upwards, out of the top layer"),nosilkscreen:gt().optional().describe("omit all silkscreen elements from the footprint")}),Xo=(e,A,t,i,n)=>({pcb_plated_hole_id:"",type:"pcb_plated_hole",shape:"circle",x:A,y:t,hole_diameter:Fr(i),outer_diameter:Fr(n),pcb_port_id:"",layers:["top","bottom"],port_hints:[e.toString()]}),lb=(e,A,t,i,n,o,s,r)=>({pcb_plated_hole_id:"",type:"pcb_plated_hole",shape:"circular_hole_with_rect_pad",x:A,y:t,hole_diameter:Fr(i),hole_shape:"circle",pad_shape:"rect",rect_pad_width:Fr(n),rect_pad_height:Fr(o),pcb_port_id:"",layers:["top","bottom"],port_hints:[e.toString()],hole_offset_x:s,hole_offset_y:r}),n6A=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 w_(e){return typeof e=="string"?e.trim().toLowerCase().endsWith("mil")?parseFloat(e)*.0254:parseFloat(e):Number(e)}var LW=Ze([J(),WA()]).transform(e=>w_(e)),Pfe=e=>Wi.extend({fn:J(),num_pins:WA().optional().default(6),wide:gt().optional(),narrow:gt().optional(),w:LW.optional(),p:LW.default(e.p??"2.54mm"),id:LW.optional(),od:LW.optional(),nosquareplating:gt().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=w_("0.55mm"),A.od=w_("0.95mm")):(A.id=w_("0.8mm"),A.od=w_("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=w_("600mil"):A.narrow?A.w=w_("300mil"):A.w=w_(e.w??"300mil")),A)),qfe=Pfe({}),o6A=(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}},Ofe=e=>{const A=qfe.parse(e),t=[];for(let g=0;g<A.num_pins;g++){const{x:c,y:I}=o6A(A.num_pins,g+1,A.w,A.p??2.54,A.nosquareplating);if(g===0&&!A.nosquareplating){t.push(lb(g+1,c,I,A.id??"0.8mm",A.od??"1mm",A.od??"1mm"));continue}t.push(Xo(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},...n6A.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}=o6A(A.num_pins,g+1,A.w,A.p??2.54,A.nosquareplating),B=c?-A.w/2-A.od/2-I:A.w/2+A.od/2+I,C=l;r.push({type:"pcb_fabrication_note_text",pcb_fabrication_note_text_id:`pin_${g+1}`,layer:"top",pcb_component_id:`pin_${g+1}`,text:`{pin${g+1}}`,anchor_position:{x:B,y:C},font_size:.3,font:"tscircuit2024",anchor_alignment:"top_left"})}const a=Oi(0,o/2+.5,.4);return{circuitJson:[...t,s,a,...r],parameters:A}},di=(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()]}),s6A=[{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}],Wfe=Object.fromEntries(s6A.map(e=>[e.metric,e])),Zfe=Object.fromEntries(s6A.map(e=>[e.imperial,e]));Wi.extend({tht:gt(),p:hA.optional(),pw:hA.optional(),ph:hA.optional(),metric:at.optional(),imperial:at.optional(),w:hA.optional(),h:hA.optional(),textbottom:gt().optional()});var UW=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=Gl(r)),typeof a=="string"&&(a=Gl(a)),typeof t=="string"&&(t=Gl(t)),typeof i=="string"&&(i=Gl(i)),typeof n=="string"&&(n=Gl(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=Wfe[o]),s&&(c=Zfe[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=Oi(0,l,.2);return A?[Xo(1,-t/2,0,i,i*1/.8),Xo(2,t/2,0,i,i*1/.8),I,B]:[di(["1","left"],-t/2,0,i,n),di(["2","right"],t/2,0,i,n),I,B]},Vfe=e=>({circuitJson:UW(e),parameters:e}),jfe=e=>({circuitJson:UW(e),parameters:e}),zfe=e=>({circuitJson:UW(e),parameters:e}),sv=e=>{const{padSpacing:A,padWidth:t,padHeight:i,padPitch:n,numRows:o,textbottom:s}=e,r=[],a=(o-1)*(n/2);for(let S=0;S<o;S++)r.push(a-S*n);const g=[];r.forEach((S,k)=>{g.push(di(k+1,-A/2,S,t,i))}),r.slice().reverse().forEach((S,k)=>{g.push(di(k+o+1,A/2,S,t,i))});const c=Math.max(...r)+i/2+.4,I=Math.min(...r)-i/2-.4,l=-A/2-t/2-.4,B=A/2+t/2+.4,C={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:B*.5,y:c},{x:l*.5,y:c}],stroke_width:.12,pcb_silkscreen_path_id:"silkscreen_top"},Q={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:B*.5,y:I},{x:l*.5,y:I}],stroke_width:.12,pcb_silkscreen_path_id:"silkscreen_bottom"},h=-A/2,E=Math.max(...r),u=.2,d=h-t/2-.1,p=E+i/2+.1,m={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"pin1_marker",route:[{x:d,y:p},{x:d-u,y:p},{x:d,y:p+u},{x:d,y:p}],stroke_width:.1},w=s?I-.9:c+.9,D=Oi(0,w,.2);return[...g,C,Q,m,D]},Xfe=Wi.extend({pw:J().default("0.5mm"),ph:J().default("0.4mm"),p:J().default("0.7mm"),textbottom:gt().optional()}),$fe=1,A0e=e=>{const A=Xfe.parse(e),t=Gl(A.pw),i=Gl(A.ph),n=Gl(A.p);return sv({padSpacing:$fe,padWidth:t,padHeight:i,padPitch:n,numRows:2,textbottom:A.textbottom})},t0e=Wi.extend({pw:J().default("0.5mm"),ph:J().default("0.32mm"),p:J().default("0.5mm"),textbottom:gt().optional()}),e0e=1,i0e=e=>{const A=t0e.parse(e),t=Gl(A.pw),i=Gl(A.ph),n=Gl(A.p);return sv({padSpacing:e0e,padWidth:t,padHeight:i,padPitch:n,numRows:4,textbottom:A.textbottom})},n0e=Wi.extend({pw:J().default("0.9mm"),ph:J().default("0.4mm"),p:J().default("0.8mm"),textbottom:gt().optional()}),o0e=1.7,s0e=e=>{const A=n0e.parse(e),t=Gl(A.pw),i=Gl(A.ph),n=Gl(A.p);return sv({padSpacing:o0e,padWidth:t,padHeight:i,padPitch:n,numRows:2,textbottom:A.textbottom})},r0e=Wi.extend({pw:J().default("0.9mm"),ph:J().default("0.4mm"),p:J().default("0.8mm"),textbottom:gt().optional()}),a0e=1.7,g0e=e=>{const A=r0e.parse(e),t=Gl(A.pw),i=Gl(A.ph),n=Gl(A.p);return sv({padSpacing:a0e,padWidth:t,padHeight:i,padPitch:n,numRows:4,textbottom:A.textbottom})},c0e=Wi.extend({pw:J().default("0.7mm"),ph:J().default("0.64mm"),p:J().default("0.94mm"),textbottom:gt().optional()}),I0e=1.4,l0e=e=>{const A=c0e.parse(e),t=Gl(A.pw),i=Gl(A.ph),n=Gl(A.p);return sv({padSpacing:I0e,padWidth:t,padHeight:i,padPitch:n,numRows:2,textbottom:A.textbottom})},B0e=Wi.extend({pw:J().default("0.9mm"),ph:J().default("0.9mm"),p:J().default("1.34mm"),textbottom:gt().optional()}),C0e=3,Q0e=e=>{const A=B0e.parse(e),t=Gl(A.pw),i=Gl(A.ph),n=Gl(A.p);return sv({padSpacing:C0e,padWidth:t,padHeight:i,padPitch:n,numRows:4,textbottom:A.textbottom})},h0e=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(/(?:array|x)(2|4)$/)?.[1];if(i)return Number.parseInt(i,10)}},E0e=e=>e?(typeof e=="number"?`${e}`:e).split("_")[0]:void 0,u0e=e=>{const A=h0e(e),t=E0e(e.imperial);return A===2&&t==="0402"?{circuitJson:A0e(e),parameters:e}:A===4&&t==="0402"?{circuitJson:i0e(e),parameters:e}:A===2&&t==="0603"?{circuitJson:s0e(e),parameters:e}:A===4&&t==="0603"?{circuitJson:g0e(e),parameters:e}:A===2&&t==="0606"?{circuitJson:l0e(e),parameters:e}:A===4&&t==="1206"?{circuitJson:Q0e(e),parameters:e}:{circuitJson:UW(e),parameters:e}},r6A=(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()]}),a6A="ABCDEFGHIJKLMNOPQRSTUVWXYZ",g6A=J().transform(e=>{const[A,t]=e.split(/[x ]/);return{x:parseFloat(A),y:parseFloat(t)}}).pipe(jA({x:WA(),y:WA()})),d0e=J().or(St(Pc())).transform(e=>Array.isArray(e)?e:(e.startsWith("(")&&e.endsWith(")")&&(e=e.slice(1,-1)),e.split(",").map(A=>{const t=Number(A);return isNaN(t)?A:t}))).pipe(St(J().or(WA()))),p0e=Wi.extend({fn:J(),num_pins:WA().optional().default(64),grid:g6A.optional(),p:at.default("0.8mm"),w:hA.optional(),h:hA.optional(),ball:hA.optional().describe("ball diameter"),pad:hA.optional().describe("pad width/height"),circularpads:gt().optional().describe("use circular pads"),tlorigin:gt().optional(),blorigin:gt().optional(),trorigin:gt().optional(),brorigin:gt().optional(),missing:d0e.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=a6A.indexOf(n[1]),s=Number.parseInt(n[2])-1;return o*e.grid.x+s+1})),{...e,origin:A}}),f0e=e=>{const A=p0e.parse(e);let{num_pins:t,grid:i,p:n,w:o,h:s,ball:r,pad:a,missing:g}=A;r??=.75/1.27*n,a??=r*.8;const c=[],I=(g??[]).filter(m=>typeof m=="number"),l=i.x*i.y-t;if(g.length===0&&l>0&&(Math.sqrt(l)%1===0?g.push("center"):l===1&&g.push("topleft")),g?.includes("center")){const m=Math.floor(Math.sqrt(l)),w=Math.floor((i.x-m)/2),D=Math.floor((i.y-m)/2);for(let S=D;S<D+m;S++)for(let k=w;k<w+m;k++)I.push(S*i.x+k+1)}g?.includes("topleft")&&I.push(1);const B=new Set(I);let C=0;for(let m=0;m<i.y;m++)for(let w=0;w<i.x;w++){const D=(w-(i.x-1)/2)*n,S=(m-(i.y-1)/2)*n;let k=w,x=m;switch(A.origin){case"bl":k=w,x=i.y-1-m;break;case"br":k=i.x-1-w,x=i.y-1-m;break;case"tr":k=i.x-1-w,x=m;break}let N=x*i.x+k+1;if(B.has(N)){C++;continue}N-=C;const M=[N,`${a6A[x]}${k+1}`];c.push(A.circularpads?r6A(M,{x:D,y:S,radius:a/2}):di(M,D,S,a,a))}const Q=Oi(0,i.y*n/2,.2),h=n/6;let E;const u=i.x*n/2,d=i.y*n/2;switch(A.origin){case"bl":E=[{x:-u,y:-d},{x:-u,y:-d-h},{x:-u-h,y:-d},{x:-u,y:-d}];break;case"br":E=[{x:u,y:-d},{x:u,y:-d-h},{x:u+h,y:-d},{x:u,y:-d}];break;case"tr":E=[{x:u,y:d},{x:u,y:d+h},{x:u+h,y:d},{x:u,y:d}];break;default:E=[{x:-u,y:d},{x:-u,y:d+h},{x:-u-h,y:d},{x:-u,y:d}];break}const p={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"pin1_marker",route:E,stroke_width:.05};return{circuitJson:[...c,Q,p],parameters:A}},HW=(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()]}),fD=e=>Wi.extend({fn:J(),num_pins:WA().optional().default(8),w:hA.default(hA.parse(e.w??"5.3mm")),p:hA.default(hA.parse(e.p??"1.27mm")),pw:hA.default(hA.parse(e.pw??"0.6mm")),pl:hA.default(hA.parse(e.pl??"1.0mm")),legsoutside:gt().optional().default(e.legsoutside??!1),pillpads:gt().optional().default(e.pillpads??!1),silkscreen_stroke_width:WA().optional().default(.1)}).transform(A=>(!A.pw&&!A.pl?(A.pw=hA.parse("0.6mm"),A.pl=hA.parse("1.0mm")):A.pw?A.pl||(A.pl=A.pw*(1/.6)):A.pw=A.pl*(.6/1),A)),y0e=fD({}),IEA=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}},m0e=e=>{const A=y0e.parse(e);return{circuitJson:D_(A),parameters:A}},D_=e=>{const A=[];for(let r=0;r<e.num_pins;r++){const{x:a,y:g}=IEA({num_pins:e.num_pins,pn:r+1,w:e.w,p:e.p,pl:e.pl,legsoutside:e.legsoutside});e.pillpads?A.push(HW(r+1,a,g,e.pl,e.pw)):A.push(di(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=Oi(0,n/2+.4,n/12),s={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",stroke_width:e.silkscreen_stroke_width??.1,route:[{x:-i/2,y:-n/2},{x:-i/2,y:n/2},...n6A.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]},c6A=se(["leftside","topside","rightside","bottomside","toppin","bottompin","leftpin","rightpin"]),w0e=({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},lEA=Wi.extend({fn:J(),cc:gt().default(!0).optional(),ccw:gt().default(!0).optional(),startingpin:J().or(St(c6A)).transform(e=>typeof e=="string"?e.slice(1,-1).split(","):e).pipe(St(c6A)).optional(),num_pins:WA().optional().default(64),w:hA.optional(),h:hA.optional(),p:hA.default(hA.parse("0.5mm")),pw:hA.optional(),pl:hA.optional(),thermalpad:Ze([kA(!0),g6A]).optional(),legsoutside:gt().default(!1)}),BEA=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},I6A=lEA.transform(BEA),D0e=["left","bottom","right","top"],S0e=e=>{const{pin_count:A,pn:t,w:i,h:n,p:o,pl:s,legsoutside:r}=e,a=A/4,g=D0e[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")}},rv=e=>{const A=I6A.parse(e),t=[],i=w0e(A),n=A.num_pins/4;for(let r=0;r<A.num_pins;r++){const{x:a,y:g,o:c}=S0e({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(di(B,a,g,I,l))}if(A.thermalpad)if(typeof A.thermalpad=="boolean"){const r=A.p*(n-1)+A.pw,a=A.p*(n-1)+A.pw;t.push(di(["thermalpad"],0,0,r,a))}else t.push(di(["thermalpad"],0,0,A.thermalpad.x,A.thermalpad.y));const o=[];for(const[r,a,g]of[["top-left",-1,1],["bottom-left",-1,-1],["bottom-right",1,-1],["top-right",1,1]]){const c=A.w/2*a,I=A.h/2*g;let l="none",B=c,C=I;const Q=A.pw*2;i[1]===1&&r==="top-left"?l="in1":i[n*4]===1&&r==="top-left"||i[n*3+1]===1&&r==="top-right"?l="in2":i[n*3]===1&&r==="top-right"||i[n]===1&&r==="bottom-left"?l="in1":i[n+1]===1&&r==="bottom-left"?l="in2":i[n*2]===1&&r==="bottom-right"?l="in1":i[n*2+1]===1&&r==="bottom-right"&&(l="in2");const h=l==="in1"?1:-1;if(A.legsoutside){const E=l==="in1"?A.pl/2:A.pw/2,u=l==="in1"?A.pw/2:A.pl/2;B+=E*a*h,C-=u*g*h}(l==="none"||A.legsoutside)&&o.push({layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:`pcb_silkscreen_path_${r}`,route:[{x:c-Q*a,y:I},{x:c,y:I},{x:c,y:I-Q*g}],type:"pcb_silkscreen_path",stroke_width:.1}),(l==="in1"||l==="in2")&&!A.legsoutside&&o.push({layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:`pcb_silkscreen_path_${r}_1`,route:[{x:c-Q*a,y:I},{x:c-Q*a/2,y:I}],type:"pcb_silkscreen_path",stroke_width:0},{layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:`pcb_silkscreen_path_${r}_2`,route:[{x:c,y:I-Q*g/2},{x:c,y:I-Q*g}],type:"pcb_silkscreen_path",stroke_width:.1}),(l==="in1"||l==="in2")&&o.push({layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:`pcb_silkscreen_path_${r}_3`,route:[{x:B-.2*-a,y:C+.2*h},{x:B,y:C},{x:B+.2*h*-a,y:C+.2},{x:B-.2*-a,y:C+.2*h}],type:"pcb_silkscreen_path",stroke_width:.1})}const s=Oi(0,A.h/2+(A.legsoutside?A.pl*1.2:.5),.3);return{circuitJson:[...t,...o,s],parameters:A}};lEA.extend({}).transform(BEA);var b0e=e=>(e.legsoutside=!1,e.pl||(e.pl=.875),e.pw||(e.pw=.25),rv(e)),x0e=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 rv(e)},_0e=e=>{e.legsoutside=!0;const A=I6A.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 rv(e)};lEA.extend({}).transform(BEA);var k0e=e=>(e.legsoutside=!1,e.thermalpad===void 0&&(e.thermalpad=!0),rv(e)),F0e=fD({w:"3.9mm",p:"1.27mm"}),G0e=e=>{const A=F0e.parse(e);return{circuitJson:D_(A),parameters:A}},R0e=fD({w:"7.1mm",p:"0.65mm",pl:"1.35mm",pw:"0.40mm",legsoutside:!0}),M0e=e=>{const A=R0e.parse(e);return{circuitJson:D_(A),parameters:A}},N0e=fD({}),v0e=e=>{const A=N0e.parse({fn:"sot363",num_pins:6,w:2.56,p:.65,pw:.4,pl:.65,legoutside:!0});return{circuitJson:D_(A),parameters:A}},L0e=Wi.extend({fn:J(),num_pins:kA(6).default(6),w:J().default("1.01mm"),h:J().default("1.45mm"),p:J().default("0.5mm"),pl:J().default("0.33mm"),pw:J().default("0.27mm"),string:J().optional()}),U0e=e=>{const A=L0e.parse({fn:"sot886",...e}),t=hA.parse(A.w),i=hA.parse(A.h),n=hA.parse(A.p),o=hA.parse(A.pl),s=hA.parse(A.pw),r=[];for(let B=0;B<6;B++){const{x:C,y:Q}=l6A(B+1,t,n,o);r.push(di(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=l6A(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=Oi(0,i/2+.4,.25);return{circuitJson:[...r,a,g,l,I],parameters:A}},l6A=(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}},B6A=Wi.extend({fn:J(),num_pins:WA().default(3),w:J().default("1.92mm"),h:J().default("2.74mm"),pl:J().default("1.32mm"),pw:J().default("0.6mm"),p:J().default("0.95mm"),string:J().optional()}),H0e=fD({p:"0.95mm",w:"1.6mm",legsoutside:!0}),Y0e=e=>{const A=e.string?.match(/^sot23_(\d+)/),t=A?Number.parseInt(A[1],10):3;if(t===6||t===8){const n=H0e.parse({...e,num_pins:t});return{circuitJson:D_(n),parameters:n}}const i=B6A.parse({...e,num_pins:t});if(i.num_pins===3)return{circuitJson:T0e(i),parameters:i};if(i.num_pins===5)return{circuitJson:Q6A(i),parameters:i};throw new Error("Invalid number of pins")},J0e=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}},T0e=e=>{const A=[];for(let i=0;i<e.num_pins;i++){const{x:n,y:o}=J0e({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(di(i+1,n,o,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}const t=Oi(0,Number.parseInt(e.h),.3);return[...A,t]},C6A=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")},Q6A=e=>{const A=[];for(let I=1;I<=e.num_pins;I++){const{x:l,y:B}=C6A({h:Number.parseFloat(e.h),p:Number.parseFloat(e.p),pn:I});A.push(di(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=Oi(0,i+.3,.3),r=C6A({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]},K0e=B6A.extend({}),P0e=e=>{const A=K0e.parse({...e,num_pins:5});return{circuitJson:Q6A(A),parameters:A}},q0e=[{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}],O0e=fD({}),W0e=e=>{const A=O0e.parse(e),t=[];for(let I=0;I<A.num_pins;I++){const{x:l,y:B}=IEA({num_pins:A.num_pins,pn:I+1,w:A.w,p:A.p??1.27,pl:A.pl,widthincludeslegs:!0});t.push(di(I+1,l,B,A.pl??"1mm",A.pw??"0.6mm"))}const i=Math.min(1,A.p/2),n=A.w+i,o=(A.num_pins/2-1)*A.p+A.pw+i,s=[];for(const I of q0e){const{dx:l,dy:B}=I;s.push({layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"",route:[{x:l*n/2-l*A.p,y:B*o/2},{x:l*n/2,y:B*o/2},{x:l*n/2,y:B*o/2-B*A.p}],type:"pcb_silkscreen_path",stroke_width:.1})}const r=A.p/4,a=-n/2-r/2,g=o/2-A.p/2;s.push({layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"",type:"pcb_silkscreen_path",route:[{x:a,y:g},{x:a-r,y:g+r},{x:a-r,y:g-r},{x:a,y:g}],stroke_width:.1});const c=Oi(0,o/2+.4,o/12);return{circuitJson:[...t,c,...s],parameters:A}},CEA=({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 Z0e({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 V0e=Wi.extend({fn:J(),num_pins:WA().optional().default(6),rows:Ze([J(),WA()]).transform(e=>Number(e)).optional().default(1).describe("number of rows"),p:hA.default("0.1in").describe("pitch"),id:hA.default("1.0mm").describe("inner diameter"),od:hA.default("1.5mm").describe("outer diameter"),male:gt().optional().describe("for male pin headers"),female:gt().optional().describe("for female pin headers"),smd:gt().optional().describe("surface mount device"),surfacemount:gt().optional().describe("surface mount device (verbose)"),rightangle:gt().optional().describe("right angle"),pw:hA.optional().default("1.0mm").describe("pad width for SMD"),pl:hA.optional().default("2.0mm").describe("pad length for SMD"),pinlabeltextalignleft:gt().optional().default(!1),pinlabeltextaligncenter:gt().optional().default(!1),pinlabeltextalignright:gt().optional().default(!1),pinlabelverticallyinverted:gt().optional().default(!1),pinlabelorthogonal:gt().optional().default(!1),nosquareplating:gt().optional().default(!1).describe("do not use rectangular pad for pin 1"),nopinlabels:gt().optional().default(!1).describe("omit silkscreen pin labels"),doublesidedpinlabel:gt().optional().default(!1).describe("add silkscreen pins in top and bottom layers"),bottomsidepinlabel:gt().optional().default(!1).describe("place the silkscreen reference text on the bottom layer instead of top")}).transform(e=>{const A=Z0e(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:Oe.custom,message:"'male' and 'female' cannot both be true; it should be male or female.",path:["male","female"]})}),j0e=e=>{const A=V0e.parse(e),{p:t,id:i,od:n,rows:o,num_pins:s,pinlabelAnchorSide:r,pinlabelverticallyinverted:a,pinlabelorthogonal:g,pinlabeltextalignleft:c,pinlabeltextalignright:I,nopinlabels:l,doublesidedpinlabel:B,bottomsidepinlabel:C}=A;let Q="center";c?Q="left":I&&(Q="right");const h=[],E=Math.ceil(s/o),u=-t,d=({xoff:S,yoff:k,od:x,anchorSide:N,smd:M,pw:L,pl:Y})=>{let H=0,O=0;if(M){const Z=x/5;switch(N){case"right":H=L/2+Z;break;case"top":O=Y/2+Z;break;case"bottom":O=-(Y/2+Z);break;case"left":H=-(L/2+Z);break}}else{const Z=x*.75;switch(N){case"right":H=Z;break;case"top":O=Z;break;case"bottom":O=-Z;break;case"left":H=-Z;break}}return{anchor_x:S+H,anchor_y:k+O}},p=(S,k,x)=>{A.smd?h.push(di(S,k,x,A.pw,A.pl)):S===1&&!A.nosquareplating?h.push(lb(S,k,x,i,n,n,0,0)):h.push(Xo(S,k,x,i,n));const{anchor_x:N,anchor_y:M}=d({xoff:k,yoff:x,od:n,anchorSide:r,smd:A.smd,pw:A.pw,pl:A.pl});l||(C?h.push(CEA({fs:n/5,pn:S,anchor_x:N,anchor_y:M,textalign:Q,orthogonal:g,verticallyinverted:a,layer:"bottom"})):h.push(CEA({fs:n/5,pn:S,anchor_x:N,anchor_y:M,textalign:Q,orthogonal:g,verticallyinverted:a,layer:"top"})),B&&h.push(CEA({fs:n/5,pn:S,anchor_x:N,anchor_y:M,textalign:Q,orthogonal:g,verticallyinverted:a,layer:"bottom"})))},m=new Set,w=o>2&&E>2;if(o===1){const S=-((s-1)/2)*t;for(let k=0;k<s;k++){const x=k+1,N=S+k*t,M=`${N},0`;if(m.has(M))throw new Error(`Overlap at ${M}`);m.add(M),p(x,N,0)}}else if(w){const S=-((E-1)/2)*t;let k=1;for(let x=0;x<o&&k<=s;x++)for(let N=0;N<E&&k<=s;N++){const M=S+N*t,L=x*u,Y=`${M},${L}`;if(m.has(Y))throw new Error(`Overlap at ${Y}`);m.add(Y),p(k++,M,L)}}else{const S=-((E-1)/2)*t;let k=1,x=0,N=o-1,M=0,L=E-1;for(;k<=s&&x<=N&&M<=L;){for(let Y=x;Y<=N&&k<=s;Y++){const H=S+M*t,O=Y*u,Z=`${H},${O}`;if(m.has(Z))throw new Error(`Overlap at ${Z}`);m.add(Z),p(k++,H,O)}M++;for(let Y=M;Y<=L&&k<=s;Y++){const H=S+Y*t,O=N*u,Z=`${H},${O}`;if(m.has(Z))throw new Error(`Overlap at ${Z}`);m.add(Z),p(k++,H,O)}if(N--,M<=L){for(let Y=N;Y>=x&&k<=s;Y--){const H=S+L*t,O=Y*u,Z=`${H},${O}`;if(m.has(Z))throw new Error(`Overlap at ${Z}`);m.add(Z),p(k++,H,O)}L--}if(x<=N){for(let Y=L;Y>=M&&k<=s;Y--){const H=S+Y*t,O=x*u,Z=`${H},${O}`;if(m.has(Z))throw new Error(`Overlap at ${Z}`);m.add(Z),p(k++,H,O)}x++}}if(k-1<s)throw new Error(`Missing pins: assigned ${k-1}, expected ${s}`)}const D=Oi(0,t,.5);return{circuitJson:[...h,D],parameters:A}},z0e=Wi.extend({fn:J(),num_pins:kA(6).default(6),w:J().default("2.1mm"),h:J().default("2.45mm"),p:J().default("0.5mm"),pl:J().default("0.675mm"),pw:J().default("0.35mm"),string:J().optional()}),X0e=e=>{const A=z0e.parse({...e,fn:"sot563"}),t=hA.parse(A.w),i=hA.parse(A.h),n=hA.parse(A.p),o=hA.parse(A.pl),s=hA.parse(A.pw),r=[];for(let B=0;B<6;B++){const{x:C,y:Q}=h6A(B+1,t,n,o);r.push(di(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=h6A(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=Oi(0,i/2+.4,.25);return{circuitJson:[...r,a,g,l,I],parameters:A}},h6A=(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}},$0e=fD({p:"1.27mm",w:"3.9mm",legsoutside:!0}),Aye=e=>{const A=$0e.parse({...e,num_pins:8});return{circuitJson:D_(A),parameters:A}},tye=fD({p:"1.27mm",w:"7.5mm",legsoutside:!0}),eye=e=>{const A=tye.parse({...e,num_pins:16});return{circuitJson:D_(A),parameters:A}},iye=Wi.extend({fn:J(),num_pins:kA(3).default(3),w:J().default("1.2mm"),h:J().default("1.2mm"),pw:J().default("0.40mm"),pl:J().default("0.45mm"),p:J().default("0.575mm")}),nye=e=>{const A=iye.parse(e),t=sye(A),i=Oi(0,hA.parse(A.h),.2);return{circuitJson:[...t,i],parameters:A}},oye=e=>{const{pn:A,p:t}=e;return A===1?{x:t,y:0}:A===2?{x:-t,y:-.4}:{x:-t,y:.4}},sye=e=>{const A=[];for(let t=0;t<3;t++){const{x:i,y:n}=oye({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(di(t+1,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},rye=Wi.extend({fn:J(),num_pins:kA(2).default(2),w:J().default("2.36mm"),h:J().default("1.22mm"),pl:J().default("0.9mm"),pw:J().default("1.2mm"),p:J().default("3.30mm")}),aye=e=>{const A=rye.parse(e),t=Oi(0,hA.parse(A.h)/4+.4,.3);return{circuitJson:cye(A).concat(t),parameters:A}},gye=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},cye=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=gye({pn:t,p:Number.parseFloat(e.p)});A.push(di(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},Iye=Wi.extend({fn:J(),p:hA.optional().default("2.54mm"),id:hA.optional().default("0.7mm"),od:hA.optional().default("1.4mm")}),lye=e=>{const A=Iye.parse(e),{p:t,id:i,od:n}=A,o=[Xo(1,-t/2,0,i,n),Xo(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=Oi(0,1.5,.5);return{circuitJson:[...o,s,r],parameters:A}},Bye=(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}},Cye=Wi.extend({fn:J(),p:hA.optional().default("5mm"),id:hA.optional().default("0.8mm"),od:hA.optional().default("1.6mm"),ceramic:gt().optional(),electrolytic:gt().optional(),polarized:gt().optional()}),Qye=e=>{const A=Cye.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=[Xo(1,-t/2,0,A.id,A.od),Xo(2,t/2,0,A.id,A.od)],s=t+.1,{topArc:r,bottomArc:a}=Bye(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=Oi(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}},YW=(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}),hye=Wi.extend({fn:kA("pushbutton"),w:hA.default(4.5),h:hA.default(6.5),id:hA.default(1),od:hA.default(1.2)}),Eye=e=>{const A=hye.parse(e),t=A.w,i=A.h,n=A.id,o=[Xo(1,-t/2,i/2,n,n*1.5),Xo(2,-t/2,-i/2,n,n*1.5),Xo(3,t/2,-i/2,n,n*1.5),Xo(4,t/2,i/2,n,n*1.5)],s=[YW([{x:-t/2,y:-i/2},{x:-t/2,y:i/2}]),YW([{x:t/2,y:-i/2},{x:t/2,y:i/2}]),YW([{x:-t/2,y:0},{x:-t/5,y:0},{x:t/5*1/Math.sqrt(2),y:i/8}]),YW([{x:t/2,y:0},{x:t/5,y:0}])],r=Oi(0,i/2+.4,.5);return{circuitJson:[...o,...s,r],parameters:A}},E6A=Wi.extend({fn:J(),w:hA.default("22.58mm"),h:hA.optional(),left:hA.optional().default(20),right:hA.optional().default(20),top:hA.optional().default(2),bottom:hA.optional().default(2),p:hA.default(hA.parse("2.54mm")),pw:hA.default(hA.parse("1.6mm")),pl:hA.default(hA.parse("2.4mm")),innerhole:gt().default(!1),innerholeedgedistance:hA.default(hA.parse("1.61mm")),silkscreenlabels:gt().default(!1),silkscreenlabelmargin:hA.default(hA.parse("0.1mm"))}),uye=e=>{const A=E6A.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},JW=(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},dye=e=>{const A=E6A.parse(e),t=A.h??uye(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=JW(A.w/2-A.pl*1.4,Q+h*A.p,"right")),i.push(di(h+1+A.left+(A.bottom??0),A.w/2-A.pl/2,Q+h*A.p,A.pl,A.pw)),A.silkscreenlabels){const E=h+1+A.left+(A.bottom??0),u=`pin${E}`;o.push({type:"pcb_silkscreen_text",pcb_silkscreen_text_id:`pin_${E}`,pcb_component_id:"1",layer:"top",anchor_position:{x:A.w/2-A.pl-(I+A.silkscreenlabelmargin),y:Q+h*A.p},text:u,font_size:.7,font:"tscircuit2024",anchor_alignment:"center"})}A.innerhole&&(n.push(Xo(h+1+A.left+(A.bottom??0)+g,A.w/2,Q+h*A.p,r,a)),n.push(Xo(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=JW(-A.w/2+A.pl*1.4,Q-h*A.p,"left")),i.push(di(h+1,-A.w/2+A.pl/2,Q-h*A.p,A.pl,A.pw)),A.silkscreenlabels){const E=h+1,u=`pin${E}`;o.push({type:"pcb_silkscreen_text",pcb_silkscreen_text_id:`pin_${E}`,pcb_component_id:"1",layer:"top",anchor_position:{x:-A.w/2+A.pl+(I+A.silkscreenlabelmargin),y:Q-h*A.p},text:u,font_size:.7,font:"tscircuit2024",anchor_alignment:"center"})}A.innerhole&&(n.push(Xo(h+1+g,-A.w/2,Q-h*A.p,r,a)),n.push(Xo(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=JW(Q-h*A.p,t/2-A.pl*1.4,"top")),i.push(di(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(Xo(h+1+A.left+A.right+(A.bottom??0)+g,Q-h*A.p,t/2,r,a)),n.push(Xo(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=JW(Q+h*A.p,-t/2+A.pl*1.4,"bottom")),i.push(di(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(Xo(h+1+A.left+g,Q+h*A.p,-t/2,r,a)),n.push(Xo(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=Oi(0,t/1.8,t/25);return{circuitJson:[...i,...n,...o,B,...A.silkscreenlabels?[]:[l],C],parameters:A}},u6A=Wi.extend({fn:J(),w:hA.default("22.58mm"),h:hA.optional(),left:hA.optional().default(20),right:hA.optional().default(20),top:hA.optional().default(2),bottom:hA.optional().default(2),p:hA.default(hA.parse("2.54mm")),pw:hA.default(hA.parse("1.6mm")),pl:hA.default(hA.parse("3.2mm")),innerhole:gt().default(!1),innerholeedgedistance:hA.default(hA.parse("1.61mm"))}),pye=e=>{const A=u6A.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},fye=(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]},yye=e=>{const A=u6A.parse(e),t=A.h??pye(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=fye(-A.w/2-A.pl/2,C-Q*A.p,"left")),i.push(di(c,-A.w/2+A.pl/2,C-Q*A.p,A.pl,A.pw)),n.push({type:"pcb_silkscreen_text",pcb_silkscreen_text_id:`pin_${c}`,pcb_component_id:"1",layer:"top",anchor_position:{x:-A.w/2+A.pl/2-4.5,y:C-Q*A.p},text:`pin${c}`,font_size:.7,font:"tscircuit2024",anchor_alignment:"center"}),c++,A.innerhole&&o.push(Xo(c+a,-A.w/2+A.innerholeedgedistance,C-Q*A.p,s,r))}if(A.bottom){const C=(A.bottom-1)/2*A.p;for(let Q=A.bottom-1;Q>=0;Q--)i.push(di(c,C-Q*A.p,-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(Xo(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(di(c,A.w/2-A.pl/2,C+Q*A.p,A.pl,A.pw)),n.push({type:"pcb_silkscreen_text",pcb_silkscreen_text_id:`pin_${c}`,pcb_component_id:"1",layer:"top",anchor_position:{x:A.w/2-A.pl/2+3.7,y:C+Q*A.p},text:`pin${c}`,font_size:.7,font:"tscircuit2024",anchor_alignment:"center"}),c++,A.innerhole&&o.push(Xo(c+a,A.w/2-A.innerholeedgedistance,C+Q*A.p,s,r))}if(A.top){const C=-((A.top-1)/2)*A.p;for(let Q=A.top-1;Q>=0;Q--)i.push(di(c,C+Q*A.p,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(Xo(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=Oi(0,t/1.8,t/25);return{circuitJson:[...o,...i,...n,l,I,B],parameters:A}},mye=e=>(e.legsoutside=!0,e.pl||(e.pl=1.5),e.pw||(e.pw=.3),rv(e)),d6A=Wi.extend({fn:J(),w:hA.default("10mm"),h:hA.optional(),left:hA.optional().default(20),right:hA.optional().default(20),top:hA.optional().default(0),bottom:hA.optional().default(0),p:hA.default(hA.parse("2.54mm")),id:hA.optional().default(hA.parse("1mm")),od:hA.optional().default(hA.parse("1.5mm"))}),wye=e=>{const A=d6A.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},TW=(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]},Dye=e=>{const A=d6A.parse(e),t=A.h??wye(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=TW(A.w/2+o*1.4,c+I*A.p,"right")),i.push(Xo(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=TW(-A.w/2-o*1.4,c+I*A.p,"left")),i.push(Xo(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=TW(c+I*A.p,t/2+o*1.4,"top")),i.push(Xo(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=TW(c+I*A.p,-t/2-o*1.4,"bottom")),i.push(Xo(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=Oi(0,t/1.7,t/25);return{circuitJson:[...i,a,g,r],parameters:A}},p6A=(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}}),Sye=Wi.extend({fn:J(),p:hA.optional().default("4.88mm"),id:hA.optional().default("0.8mm"),od:hA.optional().default("1.5mm"),w:hA.optional().default("5.6mm"),h:hA.optional().default("3.5mm")}),bye=e=>{const A=Sye.parse(e),{p:t,id:i,od:n,w:o,h:s}=A,r=s/2,a=[Xo(1,-t/2,0,i,n),Xo(2,t/2,0,i,n)],g=p6A(-o/2,0,r,"left"),c=p6A(o/2,0,r,"right"),I={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[...g,...g.slice(1).reverse(),{x:-o/2,y:-s/2},{x:o/2,y:-s/2},...c,{x:o/2,y:s/2},{x:-o/2,y:s/2}],stroke_width:.1,pcb_silkscreen_path_id:""},l=Oi(0,t/4,.5);return{circuitJson:[...a,I,l],parameters:A}};Wi.extend({w:hA,h:hA});var xye=e=>{const{w:A,h:t}=e,i=Fr(A),n=Fr(t);return{circuitJson:[di(1,0,0,i,n),Oi(0,n/2+.5,.2)],parameters:e}},bH=(e,A,t,i,n,o)=>({pcb_plated_hole_id:"",type:"pcb_plated_hole",shape:"pill",x:A,y:t,outer_width:Fr(n),outer_height:Fr(o),hole_width:Fr(i),hole_height:Fr(i),pcb_port_id:"",layers:["top","bottom"],port_hints:[e.toString()],ccw_rotation:0}),_ye=Wi.extend({fn:J(),num_pins:Ze([kA(3),kA(2)]).default(3),p:J().default("1.27mm"),id:J().default("0.72mm"),od:J().default("0.95mm"),w:J().default("4.5mm"),h:J().default("4.5mm"),inline:gt().default(!1),string:J().optional()}),kye=(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}}),Fye=e=>{const A=e.string?.match(/^to92_(\d+)/),t=A?Number.parseInt(A[1],10):3,i=_ye.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=[lb(1,-I,c-I,l,B,Q,0,0),bH(2,0,c-I,l,C,Q),bH(3,I,c-I,l,C,Q)]:h=[lb(1,-I,c-I,l,B,B,0,0),Xo(2,0,c,l,B),Xo(3,I,c-I,l,B)];else if(i.num_pins===2)h=[lb(1,-I,c-I,l,C,Q,0,0),bH(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=kye(0,c,E),d={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[...u,{x:-E,y:0},{x:E,y:0},u[0]],stroke_width:.1,pcb_silkscreen_path_id:""},p=Oi(0,c+1,.5);return{circuitJson:[...h,d,p],parameters:i}},Gye=Wi.extend({fn:J(),num_pins:kA(2).default(2),w:J().default("2.15mm"),h:J().default("1.20mm"),pl:J().default("0.5mm"),pw:J().default("0.6mm"),p:J().default("1.4mm")}),Rye=e=>{const A=Gye.parse(e),t=Oi(0,hA.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:hA.parse(A.p)/2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2-.2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2-.2,y:-hA.parse(A.h)/2},{x:hA.parse(A.p)/2,y:-hA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:Nye(A).concat(i,t),parameters:A}},Mye=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},Nye=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=Mye({pn:t,p:Number.parseFloat(e.p)});A.push(di(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},vye=fD({}),Lye=e=>{const A=vye.parse(e),t=[];for(let s=0;s<A.num_pins;s++){const{x:r,y:a}=IEA({num_pins:A.num_pins,pn:s+1,w:A.w,p:A.p??1.27,pl:A.pl,widthincludeslegs:!0});t.push(di(s+1,r,a,A.pl??"1.5mm",A.pw??"0.6mm"))}const i=(A.num_pins/2-1)*A.p+A.pw,n=Oi(0,i/2-.5,i/12),o={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"",type:"pcb_silkscreen_path",route:[{x:-A.w/3,y:i/2+.2},{x:A.w/3,y:i/2+.2}],stroke_width:.1};return{circuitJson:[...t,n,o],parameters:A}},Uye=Wi.extend({fn:J(),num_pins:kA(2).default(2),w:J().default("5.0mm"),h:J().default("2.30mm"),pl:J().default("1.25mm"),pw:J().default("2mm"),p:J().default("3.75mm")}),Hye=e=>{const A=Uye.parse(e),t=Oi(0,hA.parse(A.h)/2+1,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:hA.parse(A.p)/2+.5,y:hA.parse(A.h)/2+.5},{x:-hA.parse(A.w)/2-.5,y:hA.parse(A.h)/2+.5},{x:-hA.parse(A.w)/2-.5,y:-hA.parse(A.h)/2-.5},{x:hA.parse(A.p)/2+.5,y:-hA.parse(A.h)/2-.5}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:Jye(A).concat(i,t),parameters:A}},Yye=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},Jye=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=Yye({pn:t,p:Number.parseFloat(e.p)});A.push(di(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},Tye=Wi.extend({fn:J(),num_pins:kA(2).default(2),w:J().default("4.4mm"),h:J().default("2.1mm"),pl:J().default("1.2mm"),pw:J().default("1.2mm"),p:J().default("2.9mm")}),Kye=e=>{const A=Tye.parse(e),t=Oi(0,hA.parse(A.h)-.5,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:hA.parse(A.p)/2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2-.2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2-.2,y:-hA.parse(A.h)/2},{x:hA.parse(A.p)/2,y:-hA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:qye(A).concat(i,t),parameters:A}},Pye=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},qye=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=Pye({pn:t,p:Number.parseFloat(e.p)});A.push(di(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},Oye=Wi.extend({fn:J(),num_pins:kA(2).default(2),w:J().default("3.30mm"),h:J().default("1.80mm"),pl:J().default("0.60mm"),pw:J().default("0.45mm"),p:J().default("2.1mm")}),Wye=e=>{const A=Oye.parse(e),t=Oi(0,hA.parse(A.h)-.5,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:hA.parse(A.p)/2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2,y:-hA.parse(A.h)/2},{x:hA.parse(A.p)/2,y:-hA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:Vye(A).concat(i,t),parameters:A}},Zye=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},Vye=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=Zye({pn:t,p:Number.parseFloat(e.p)});A.push(di(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},jye=Wi.extend({fn:J(),num_pins:kA(2).default(2),w:J().default("1.4mm"),h:J().default("0.9mm"),pl:J().default("0.36mm"),pw:J().default("0.25mm"),p:J().default("0.85mm")}),zye=e=>{const A=jye.parse(e),t=Oi(0,hA.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:hA.parse(A.p)/2+.15,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2-.15,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2-.15,y:-hA.parse(A.h)/2},{x:hA.parse(A.p)/2+.15,y:-hA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:$ye(A).concat(i,t),parameters:A}},Xye=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},$ye=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=Xye({pn:t,p:Number.parseFloat(e.p)});A.push(di(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},Ame=Wi.extend({fn:J(),num_pins:kA(2).default(2),w:J().default("1.3mm"),h:J().default("0.9mm"),pl:J().default("0.4mm"),pw:J().default("0.7mm"),p:J().default("0.7mm")}),tme=e=>{const A=Ame.parse(e),t=Oi(0,hA.parse(A.h)+.1,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:hA.parse(A.p)/2+.2,y:hA.parse(A.h)/2+.2},{x:-hA.parse(A.w)/2-.2,y:hA.parse(A.h)/2+.2},{x:-hA.parse(A.w)/2-.2,y:-hA.parse(A.h)/2-.2},{x:hA.parse(A.p)/2+.2,y:-hA.parse(A.h)/2-.2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:ime(A).concat(i,t),parameters:A}},eme=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},ime=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=eme({pn:t,p:Number.parseFloat(e.p)});A.push(di(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},nme=Wi.extend({fn:J(),num_pins:kA(2).default(2),w:J().default("3,05mm"),h:J().default("1.65mm"),pl:J().default("0.6mm"),pw:J().default("0.6mm"),pad_spacing:J().default("2.2mm")}),ome=e=>{const A=nme.parse(e),t=Oi(0,hA.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:hA.parse(A.pad_spacing)/2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2-.2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2-.2,y:-hA.parse(A.h)/2},{x:hA.parse(A.pad_spacing)/2,y:-hA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:rme(A).concat(i,t),parameters:A}},sme=e=>{const{pn:A,pad_spacing:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},rme=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=sme({pn:t,pad_spacing:Number.parseFloat(e.pad_spacing)});A.push(di(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},ame=Wi.extend({fn:J(),num_pins:kA(2).default(2),w:J().default("4.4mm"),h:J().default("2.1mm"),pl:J().default("1.2mm"),pw:J().default("1.2mm"),p:J().default("2.9mm")}),gme=e=>{const A=ame.parse(e),t=Oi(0,hA.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:hA.parse(A.p)/2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2-.2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2-.2,y:-hA.parse(A.h)/2},{x:hA.parse(A.p)/2,y:-hA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:Ime(A).concat(i,t),parameters:A}},cme=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},Ime=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=cme({pn:t,p:Number.parseFloat(e.p)});A.push(di(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},lme=Wi.extend({fn:J(),num_pins:kA(2).default(2),w:J().default("4.4mm"),h:J().default("2.1mm"),pl:J().default("0.91mm"),pw:J().default("1.22mm"),p:J().default("3.146mm")}),Bme=e=>{const A=lme.parse(e),t=Oi(0,hA.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:hA.parse(A.p)/2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2-.2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2-.2,y:-hA.parse(A.h)/2},{x:hA.parse(A.p)/2,y:-hA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:Qme(A).concat(i,t),parameters:A}},Cme=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},Qme=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=Cme({pn:t,p:Number.parseFloat(e.p)});A.push(di(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},hme=Wi.extend({fn:J(),num_pins:kA(2).default(2),w:J().default("1.80mm"),h:J().default("1.00mm"),pl:J().default("0.66mm"),pw:J().default("0.5mm"),p:J().default("0.8mm")}),Eme=e=>{const A=hme.parse(e),t=Oi(0,hA.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:hA.parse(A.p)/2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2-.1,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2-.1,y:-hA.parse(A.h)/2},{x:hA.parse(A.p)/2,y:-hA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:dme(A).concat(i,t),parameters:A}},ume=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},dme=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=ume({pn:t,p:Number.parseFloat(e.p)});A.push(di(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},pme=Wi.extend({fn:J(),num_pins:kA(2).default(2),w:J().default("6.2mm"),h:J().default("3.4mm"),pl:J().default("1.4mm"),pw:J().default("2.1mm"),p:J().default("4.4mm")}),fme=e=>{const A=pme.parse(e),t=Oi(0,hA.parse(A.h)/2+.4,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:hA.parse(A.p)/2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2-.2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2-.2,y:-hA.parse(A.h)/2},{x:hA.parse(A.p)/2,y:-hA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:mme(A).concat(i,t),parameters:A}},yme=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},mme=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=yme({pn:t,p:Number.parseFloat(e.p)});A.push(di(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},wme=Wi.extend({fn:J(),num_pins:Ze([kA(3),kA(5)]).default(3),w:J().default("4.20mm"),h:J().default("4.80mm"),pl:J().default("1.3mm"),pw:J().default("0.9mm"),p:J().default("1.5mm"),string:J().optional()}),Dme=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(di(1,-n/2+r,t,o,i),di(2,-n/2,0,o+s,i),di(3,-n/2+r,-t,o,i));const a=Oi(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]},Sme=e=>{const A=[];Number.parseFloat(e.p),Number.parseFloat(e.pw),Number.parseFloat(e.w),A.push(di(1,-1.85,-1.5,1.5,.7),di(2,-1.85,1.5,1.5,.7),di(3,0,0,.8,2),di(4,1.85,-1.5,1.5,.7),di(5,1.85,1.5,1.5,.7));const t=Oi(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]},bme=e=>{const A=e.string?.match(/^sot89_(\d+)/),t=A?Number.parseInt(A[1],10):3,i=wme.parse({...e,num_pins:t});if(i.num_pins===3)return{circuitJson:Dme(i),parameters:i};if(i.num_pins===5)return{circuitJson:Sme(i),parameters:i};throw new Error("Invalid number of pins for SOT89")},xme=Wi.extend({fn:J(),p:hA.optional().default("5.0mm"),id:hA.optional().default("1.0mm"),od:hA.optional().default("1.9mm"),w:hA.optional().default("13mm"),h:hA.optional().default("7mm"),num_pins:WA().optional(),string:J().optional()}),_me=e=>{const A=xme.parse(e),{fn:t,id:i,od:n,w:o,h:s,string:r}=A,a=Number.parseInt(r?.split("_")[1]??"3"),g=-1,c=o/2,I=s/2,l=2.5,B=o*.4,C=Math.max(l,B/(a-1)),Q=Array.from({length:a},(m,w)=>{const D=a%2===0?(w-a/2+.5)*C:(w-Math.floor(a/2))*C;return Xo(w+1,D,g,i,n)}),h={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-c,y:-I},{x:c,y:-I},{x:c,y:I},{x:-c,y:I},{x:-c,y:-I}],stroke_width:.1,pcb_silkscreen_path_id:""},E=-I+2*s/3,u={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-c,y:E},{x:c,y:E}],stroke_width:.1,pcb_silkscreen_path_id:""},d=[{type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-o/6,y:E},{x:-o/6,y:I}],stroke_width:.1,pcb_silkscreen_path_id:""},{type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:o/6,y:E},{x:o/6,y:I}],stroke_width:.1,pcb_silkscreen_path_id:""}],p=Oi(0,s/2+.6,.5);return{circuitJson:[...Q,h,u,...d,p],parameters:{...A,p:C}}},kme=Wi.extend({fn:J(),num_pins:kA(2).default(2),w:J().default("5.40mm"),h:J().default("2.30mm"),pl:J().default("1.30mm"),pw:J().default("1.70mm"),p:J().default("3.5mm")}),Fme=e=>{const A=kme.parse(e),t=Oi(0,hA.parse(A.h)/2+.4,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:hA.parse(A.p)/2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2,y:-hA.parse(A.h)/2},{x:hA.parse(A.p)/2,y:-hA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:Rme(A).concat(i,t),parameters:A}},Gme=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},Rme=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=Gme({pn:t,p:Number.parseFloat(e.p)});A.push(di(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},Mme=Wi.extend({fn:J(),num_pins:kA(2).default(2),w:J().default("1.90mm"),h:J().default("1.33mm"),pl:J().default("0.5mm"),pw:J().default("0.7mm"),p:J().default("0.8mm")}),Nme=e=>{const A=Mme.parse(e),t=Oi(0,hA.parse(A.h)+.1,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:hA.parse(A.p)/2+.1,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2,y:-hA.parse(A.h)/2},{x:hA.parse(A.p)/2+.1,y:-hA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:Lme(A).concat(i,t),parameters:A}},vme=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},Lme=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=vme({pn:t,p:Number.parseFloat(e.p)});A.push(di(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},Ume=Wi.extend({fn:J(),num_pins:kA(2).default(2),w:J().default("7.0mm"),h:J().default("3.35mm"),pl:J().default("1.50mm"),pw:J().default("2.70mm"),p:J().default("4.8mm")}),Hme=e=>{const A=Ume.parse(e),t=Oi(0,hA.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:hA.parse(A.p)/2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2,y:-hA.parse(A.h)/2},{x:hA.parse(A.p)/2,y:-hA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:Jme(A).concat(i,t),parameters:A}},Yme=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},Jme=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=Yme({pn:t,p:Number.parseFloat(e.p)});A.push(di(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},Tme=Wi.extend({fn:J(),num_pins:kA(2).default(2),w:J().default("3.0mm"),h:J().default("1.80mm"),pl:J().default("0.80mm"),pw:J().default("1.20mm"),p:J().default("1.6mm")}),Kme=e=>{const A=Tme.parse(e),t=Oi(0,hA.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:hA.parse(A.p)/2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2-.1,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2-.1,y:-hA.parse(A.h)/2},{x:hA.parse(A.p)/2,y:-hA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:qme(A).concat(i,t),parameters:A}},Pme=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},qme=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=Pme({pn:t,p:Number.parseFloat(e.p)});A.push(di(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},Ome=Wi.extend({fn:J(),num_pins:kA(2).default(2),w:J().default("7.10mm"),h:J().default("3.40mm"),pl:J().default("2.45mm"),pw:J().default("1.80mm"),p:J().default("4.05mm")}),Wme=e=>{const A=Ome.parse(e),t=Oi(0,hA.parse(A.h)/2+.5,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:hA.parse(A.p)/2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2-.5,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2-.5,y:-hA.parse(A.h)/2},{x:hA.parse(A.p)/2,y:-hA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:Vme(A).concat(i,t),parameters:A}},Zme=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},Vme=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=Zme({pn:t,p:Number.parseFloat(e.p)});A.push(di(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},jme=Wi.extend({fn:J(),num_pins:kA(2).default(2),w:J().default("4.80mm"),h:J().default("2.10mm"),pl:J().default("1.30mm"),pw:J().default("1.40mm"),p:J().default("2.9mm")}),zme=e=>{const A=jme.parse(e),t=Oi(0,hA.parse(A.h)-.5,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:hA.parse(A.p)/2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2,y:-hA.parse(A.h)/2},{x:hA.parse(A.p)/2,y:-hA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:$me(A).concat(i,t),parameters:A}},Xme=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},$me=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=Xme({pn:t,p:Number.parseFloat(e.p)});A.push(di(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},Awe=Wi.extend({fn:J(),num_pins:kA(2).default(2),w:J().default("7.30mm"),h:J().default("4.40mm"),pl:J().default("2.50mm"),pw:J().default("2.30mm"),p:J().default("4.30mm")}),twe=e=>{const A=Awe.parse(e),t=Oi(0,hA.parse(A.h)/2+.5,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:hA.parse(A.p)/2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2-.1,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2-.1,y:-hA.parse(A.h)/2},{x:hA.parse(A.p)/2,y:-hA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:iwe(A).concat(i,t),parameters:A}},ewe=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},iwe=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=ewe({pn:t,p:Number.parseFloat(e.p)});A.push(di(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},nwe=Wi.extend({fn:J(),num_pins:kA(2).default(2),w:J().default("10.70mm"),h:J().default("6.60mm"),pl:J().default("3.30mm"),pw:J().default("2.50mm"),p:J().default("6.80mm")}),owe=e=>{const A=nwe.parse(e),t=Oi(0,3,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:hA.parse(A.p)/2,y:hA.parse(A.h)/2-.8},{x:-hA.parse(A.w)/2-.8,y:hA.parse(A.h)/2-.8},{x:-hA.parse(A.w)/2-.8,y:-hA.parse(A.h)/2+.8},{x:hA.parse(A.p)/2,y:-hA.parse(A.h)/2+.8}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:rwe(A).concat(i,t),parameters:A}},swe=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},rwe=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=swe({pn:t,p:Number.parseFloat(e.p)});A.push(di(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},awe=Wi.extend({fn:J(),num_pins:WA().default(4),w:J().default("8.50mm"),h:J().default("6.90mm"),pl:J().default("2mm"),pw:J().default("1.5mm"),p:J().default("2.30mm"),string:J().optional()}),gwe=e=>{const A=e.string?.match(/^sot223_(\d+)/),t=A?Number.parseInt(A[1],10):4;if(t===8){const n=lwe.parse({...e,num_pins:t});return{circuitJson:D_(n),parameters:n}}const i=awe.parse({...e,num_pins:t});if(i.num_pins===4)return{circuitJson:Iwe(i),parameters:i};if(i.num_pins===5)return{circuitJson:Cwe(i),parameters:i};if(i.num_pins===6)return{circuitJson:hwe(i),parameters:i};throw new Error("Invalid number of pins")},cwe=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}},Iwe=e=>{const A=[];for(let r=0;r<e.num_pins;r++){const{x:a,y:g}=cwe({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(di(r+1,a,g,Number.parseFloat(e.pl),c))}const t=Oi(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]},lwe=fD({p:"0.90mm",w:"2.8mm",legsoutside:!0}),Bwe=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")},Cwe=e=>{const A=[];for(let r=1;r<=e.num_pins;r++){const{x:a,y:g}=Bwe({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(di(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=Oi(0,0,.3);return[...A,n,o,s]},Qwe=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")},hwe=e=>{const A=[];for(let r=1;r<=e.num_pins;r++){const{x:a,y:g}=Qwe({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(di(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=Oi(0,0,.3);return[...A,n,o,s]},Ewe=Wi.extend({fn:J(),num_pins:WA().default(3),w:J().default("3.40mm"),h:J().default("3.30mm"),pl:J().default("1mm"),pw:J().default("0.7mm"),p:J().default("1.2mm"),string:J().optional()}),uwe=e=>{const A=e.string?.match(/^sot23w_(\d+)/),t=A?Number.parseInt(A[1],3):3,i=Ewe.parse({...e,num_pins:t});if(i.num_pins===3)return{circuitJson:pwe(i),parameters:i};throw new Error("Invalid number of pins")},dwe=e=>{const{pn:A,p:t}=e;return A===1?{x:-t,y:.95}:A===2?{x:-t,y:-.95}:{x:t,y:0}},pwe=e=>{const A=[];for(let r=0;r<e.num_pins;r++){const{x:a,y:g}=dwe({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(di(r+1,a,g,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}const t=Oi(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]},fwe=Wi.extend({fn:J(),num_pins:Ze([kA(3),kA(2)]).default(3),p:J().default("1.27mm"),id:J().default("0.72mm"),od:J().default("0.95mm"),w:J().default("2.5mm"),h:J().default("4.2mm"),string:J().optional()}),ywe=e=>{const{p:A,id:t,od:i,w:n,h:o}=e,s=Number.parseFloat(o)/2,r=Number.parseFloat(A);return[Xo(1,-r,s-r,t,i),Xo(2,0,s-r,t,i),Xo(3,r,s-r,t,i)]},mwe=e=>{const{p:A,id:t,od:i,h:n}=e,o=Number.parseFloat(n)/2,s=Number.parseFloat(A);return[Xo(1,-s,o-s,t,i),Xo(2,s,o-s,t,i)]},wwe=e=>{const A=e.string?.match(/^to92s_(\d+)/),t=A?Number.parseInt(A[1],10):3,i=fwe.parse({...e,num_pins:t});let n=[];if(i.num_pins===3)n=ywe(i);else if(i.num_pins===2)n=mwe(i);else throw new Error("Invalid number of pins for TO-92");const o=Number.parseFloat(i.h)/2,s=Number.parseFloat(i.p),r={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-o,y:o-s},{x:-1.9,y:0},{x:1.9,y:0},{x:o,y:o-s},{x:1.5,y:Number.parseFloat(i.h)/2+.5},{x:-1.5,y:Number.parseFloat(i.h)/2+.5},{x:-o,y:o-s}],stroke_width:.1,pcb_silkscreen_path_id:""},a=Oi(0,o+1,.5);return{circuitJson:[...n,r,a],parameters:i}},Dwe=Wi.extend({fn:J(),p:hA.optional(),id:hA.optional(),pw:hA.optional(),pl:hA.optional(),w:hA.optional(),h:hA.optional(),sh:Ze([gt(),J(),WA()]).optional().transform(e=>{if(typeof e=="string"){const A=Number(e);return Number.isNaN(A)?!0:A}return e}).describe('JST SH (Surface-mount) connector family. SH stands for "Super High-density".'),ph:gt().optional().describe('JST PH (Through-hole) connector family. PH stands for "Pin Header".'),string:J().optional()}),Swe={ph:{p:hA.parse("2.2mm"),id:hA.parse("0.70mm"),pw:hA.parse("1.20mm"),pl:hA.parse("1.20mm"),w:hA.parse("6mm"),h:hA.parse("5mm")},sh:{p:hA.parse("1mm"),pw:hA.parse("0.6mm"),pl:hA.parse("1.55mm"),w:hA.parse("5.8mm"),h:hA.parse("7.8mm")}};function bwe(e){return e.sh?"sh":(e.ph,"ph")}function xwe(e,A,t,i,n,o){const s=[];if(e==="ph"){const r=t/2;s.push(lb(1,-r,2,i,n,o)),s.push(lb(2,r,2,i,n,o))}else{const r=-((A-1)/2)*t;for(let g=0;g<A;g++){const c=r+g*t;console.log("x si",c),s.push(di(g+1,c,-1.325,n,o))}const a=(A-1)/2*t+1.3;console.log("offset",a),s.push(di(A+1,-a,1.22,1.2,1.8)),s.push(di(A+2,a,1.22,1.2,1.8))}return s}function _we(e,A,t){return e==="ph"?{type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-3,y:3},{x:3,y:3},{x:3,y:-2},{x:-3,y:-2},{x:-3,y:3}],stroke_width:.1,pcb_silkscreen_path_id:""}:{type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[],stroke_width:.1,pcb_silkscreen_path_id:""}}var kwe=e=>{const A=Dwe.parse(e),t=bwe(A),i=Swe[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=t==="sh"?4:2;if(t==="sh"){const Q=(typeof e.string=="string"?e.string:"").match(/sh(\d+)/);if(Q&&Q[1]){const h=parseInt(Q[1],10);Number.isNaN(h)||(c=h)}else typeof A.sh=="number"&&(c=A.sh)}const I=xwe(t,c,n,o,s,r),l=_we(t),B=Oi(0,g/2+1,.5);return{circuitJson:[...I,l,B],parameters:{...A,p:n,id:o,pw:s,pl:r,w:a,h:g,num_pins:c,sh:t==="sh",ph:t==="ph"}}},Fwe=Wi.extend({fn:J(),num_pins:kA(2).default(2),w:J().default("3.30mm"),h:J().default("1.70mm"),pl:J().default("0.80mm"),pw:J().default("1mm"),p:J().default("1.90mm")}),Gwe=e=>{const A=Fwe.parse(e),t=Oi(0,hA.parse(A.h)/2+.5,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:hA.parse(A.p)/2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2,y:-hA.parse(A.h)/2},{x:hA.parse(A.p)/2,y:-hA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:Mwe(A).concat(i,t),parameters:A}},Rwe=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},Mwe=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=Rwe({pn:t,p:Number.parseFloat(e.p)});A.push(di(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},Nwe=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"}}},vwe=Wi.extend({fn:J(),num_pins:Ze([kA(8),kA(10)]).default(8),w:J().optional(),h:J().optional(),p:J().optional(),pl:J().optional(),pw:J().optional(),string:J().optional()}),Lwe=e=>{const A=vwe.parse(e),t=Nwe(A.num_pins),i=hA.parse(A.w||t.w),n=hA.parse(A.h||t.h),o=hA.parse(A.p||t.p),s=hA.parse(A.pl||t.pl),r=hA.parse(A.pw||t.pw),a=[],g=A.num_pins/2;for(let u=0;u<A.num_pins;u++){const{x:d,y:p}=f6A(A.num_pins,u+1,i,o),m=u<g?u+1:A.num_pins-(u-g);a.push(di(m,d,p,s,r))}const c=i,I=n,l={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-c/2,y:I/2},{x:c/2,y:I/2}],stroke_width:.05,pcb_silkscreen_path_id:""},B={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-c/2,y:-I/2},{x:c/2,y:-I/2}],stroke_width:.05,pcb_silkscreen_path_id:""},C=f6A(A.num_pins,1,c,o),Q={x:C.x-.8,y:C.y},h={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"pin_marker_1",route:[{x:Q.x-.4,y:Q.y},{x:Q.x-.7,y:Q.y+.3},{x:Q.x-.7,y:Q.y-.3},{x:Q.x-.4,y:Q.y}],stroke_width:.05,pcb_silkscreen_path_id:"pin_marker_1"},E=Oi(0,I/2+.5,.3);return{circuitJson:[...a,l,B,E,h],parameters:A}},f6A=(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*hA.parse(e===8?"1.8mm":"2.2mm"),y:r*i}},Uwe=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"}}},Hwe=Wi.extend({fn:J(),num_pins:Ze([kA(8),kA(10),kA(12),kA(16)]).default(8),w:J().optional(),h:J().optional(),p:J().optional(),pl:J().optional(),pw:J().optional(),string:J().optional()}),y6A=(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*hA.parse("2mm"),y:r*i}},Ywe=e=>{const A=Hwe.parse(e),t=Uwe(A.num_pins),i=hA.parse(A.w||t.w),n=hA.parse(A.h||t.h),o=hA.parse(A.p||t.p),s=hA.parse(A.pl||t.pl),r=hA.parse(A.pw||t.pw),a=[];for(let E=0;E<A.num_pins;E++){const{x:u,y:d}=y6A(A.num_pins,E+1,i,o);a.push(di(E+1,u,d,s,r))}const g=i,c=n,I={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-g/2,y:c/2},{x:g/2,y:c/2}],stroke_width:.05,pcb_silkscreen_path_id:""},l={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-g/2,y:-c/2},{x:g/2,y:-c/2}],stroke_width:.05,pcb_silkscreen_path_id:""},B=y6A(A.num_pins,1,g,o),C={x:B.x-.8,y:B.y},Q={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"pin_marker_1",route:[{x:C.x-.4,y:C.y},{x:C.x-.7,y:C.y+.3},{x:C.x-.7,y:C.y-.3},{x:C.x-.4,y:C.y}],stroke_width:.05,pcb_silkscreen_path_id:"pin_marker_1"},h=Oi(0,c/2+.5,.3);return{circuitJson:[...a,I,l,h,Q],parameters:A}},Jwe=Wi.extend({fn:J(),num_pins:kA(2).default(2),w:J().default("3.8mm"),h:J().default("1.65mm"),pl:J().default("1.2mm"),pw:J().default("1.2mm"),pad_spacing:J().default("2.6mm")}),Twe=e=>{const A=Jwe.parse(e),t=Oi(0,hA.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:hA.parse(A.pad_spacing)/2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2-.2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2-.2,y:-hA.parse(A.h)/2},{x:hA.parse(A.pad_spacing)/2,y:-hA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:Pwe(A).concat(i,t),parameters:A}},Kwe=e=>{const{pn:A,pad_spacing:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},Pwe=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=Kwe({pn:t,pad_spacing:Number.parseFloat(e.pad_spacing)});A.push(di(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},qwe=Wi.extend({fn:J(),num_pins:kA(2).default(2),w:J().default("3.20mm"),h:J().default("1.65mm"),pl:J().default("0.8mm"),pw:J().default("0.9mm"),pad_spacing:J().default("2.1mm")}),Owe=e=>{const A=qwe.parse(e),t=Oi(0,hA.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:hA.parse(A.pad_spacing)/2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2-.2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2-.2,y:-hA.parse(A.h)/2},{x:hA.parse(A.pad_spacing)/2,y:-hA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:Zwe(A).concat(i,t),parameters:A}},Wwe=e=>{const{pn:A,pad_spacing:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},Zwe=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=Wwe({pn:t,pad_spacing:Number.parseFloat(e.pad_spacing)});A.push(di(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},Vwe=Wi.extend({fn:J(),num_pins:Ze([kA(6),kA(8)]).default(8),w:J().default("3mm"),h:J().default("3mm"),p:J().default("0.5mm"),pl:J().default("0.52mm"),pw:J().default("0.35mm"),epw:J().default("1.40mm"),eph:J().default("1.60mm"),string:J().optional(),ep:gt().default(!1)}),jwe=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=Vwe.parse({...e,num_pins:t}),n=hA.parse(i.w),o=hA.parse(i.h),s=hA.parse(i.p),r=hA.parse(i.pl),a=hA.parse(i.pw),g=hA.parse(i.epw),c=hA.parse(i.eph),I=[];for(let p=0;p<i.num_pins;p++){const{x:m,y:w}=m6A(i.num_pins,p+1,n,s);I.push(di(p+1,m,w,r,a))}i.ep&&I.push(di(i.num_pins+1,0,0,g,c));const l=n,B=o,C={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-l/2,y:B/2},{x:l/2,y:B/2}],stroke_width:.05,pcb_silkscreen_path_id:""},Q={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-l/2,y:-B/2},{x:l/2,y:-B/2}],stroke_width:.05,pcb_silkscreen_path_id:""},h=m6A(i.num_pins,1,l,s),E={x:h.x-.4,y:h.y},u={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"pin_marker_1",route:[{x:E.x-.4,y:E.y},{x:E.x-.7,y:E.y+.3},{x:E.x-.7,y:E.y-.3},{x:E.x-.4,y:E.y}],stroke_width:.05,pcb_silkscreen_path_id:"pin_marker_1"},d=Oi(0,B/2+.5,.3);return{circuitJson:[...I,C,Q,d,u],parameters:i}},m6A=(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*hA.parse("1.4mm"),y:r*i}},zwe=e=>{const{num_pins:A,bridged:t,p:i=2.54,pw:n=1.5,ph:o=1.5}=e,s=hA.parse(i),r=hA.parse(n),a=hA.parse(o),g=Math.min(a/4,.5),c=[];for(let p=0;p<A;p++)c.push(di(p+1,p*s,0,r,a));let I=[];if(t){const p=t.split("").map(Number);if(p.length>1)for(let m=0;m<p.length-1;m++){const w=p[m],D=p[m+1];if(typeof w=="number"&&typeof D=="number"&&!isNaN(w)&&!isNaN(D)){const S=(w-1)*s,k=(D-1)*s,x=Math.sign(k-S),N=S+x*(r/2),M=k-x*(r/2);I.push({type:"pcb_trace",pcb_trace_id:"",route:[{start_pcb_port_id:`{PIN${w}}`,x:N,y:0,width:g,layer:"top",route_type:"wire"},{end_pcb_port_id:`{PIN${D}}`,x:M,y:0,width:g,layer:"top",route_type:"wire"}]})}}}const l=(A-1)*s+r+.7,B=a+1,C=(A-1)*s/2,Q=0,h={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"outline",route:[{x:C-l/2,y:Q-B/2},{x:C+l/2,y:Q-B/2},{x:C+l/2,y:Q+B/2},{x:C-l/2,y:Q+B/2},{x:C-l/2,y:Q-B/2}],stroke_width:.15},u=Q+B/2+.6,d=Oi(C,u,.4);return{circuitJson:[...c,...I,h,d],parameters:e}},w6A={fn:kA("sot457"),num_pins:kA(6).default(6),pillh:J().default("0.45mm"),pillw:J().default("1.45mm"),pl:J(),pw:J(),p:J(),wave:gt().optional(),reflow:gt().optional()},Xwe=Wi.extend({...w6A,h:J().default("2.5mm"),w:J().default("2.7mm"),pl:J().default("0.8mm"),pw:J().default("0.55mm"),p:J().default("0.95mm")}),$we=Wi.extend({...w6A,h:J().default("3mm"),w:J().default("4mm"),pillr:J().default("0.225mm"),pl:J().default("1.45mm"),pw:J().default("1.5mm"),p:J().default("1.475mm")}).transform(e=>({...e,wave:e.wave??(e.reflow===void 0?!0:!e.reflow),reflow:e.reflow??(e.wave===void 0?!1:!e.wave)})),Bb=e=>Number.parseFloat(e.replace("mm","")),D6A=({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},S6A=e=>{const A=[],t=Bb(e.p),i=Bb(e.pl),n=Bb(e.pw),o=Bb(e.w),s=Bb(e.h);if(e.wave){const C={1:({padWidth:Q,padHeight:h})=>di(1,-t,t,h,Q),2:({padWidth:Q,padHeight:h})=>di(2,-t,-t,h,Q),3:({padWidth:Q,padHeight:h})=>HW(3,-t,0,Bb(e.pillw),Bb(e.pillh)),4:({padWidth:Q,padHeight:h})=>HW(4,t,0,Bb(e.pillw),Bb(e.pillh)),5:({padWidth:Q,padHeight:h})=>di(5,t,t,h,Q),6:({padWidth:Q,padHeight:h})=>di(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}=D6A({pitch:t,width:o,pinNumber:C});A.push(di(C,Q,h,i,n))}const r={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-o/3,y:s/2+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=Oi(0,s+.5,.3),c=D6A({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]},ADe=e=>{if(e.wave){const t=$we.parse({...e,fn:"sot457"});return{circuitJson:S6A(t),parameters:t}}const A=Xwe.parse(e);return{circuitJson:S6A(A),parameters:A}},tDe=Wi.extend({fn:J(),num_pins:kA(6).default(6),w:J().default("1.1mm"),h:J().default("1.45mm"),p:J().default("0.35mm"),pl:J().default("0.2mm"),pw:J().default("0.2mm"),string:J().optional()}),eDe=e=>{const A=tDe.parse({...e,fn:"sot963"}),t=hA.parse(A.w),i=hA.parse(A.h),n=hA.parse(A.p),o=hA.parse(A.pl),s=hA.parse(A.pw),r=[];for(let B=0;B<6;B++){const{x:C,y:Q}=b6A(B+1,t,n,o);r.push(di(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=b6A(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=Oi(0,i/2+.4,.25);return{circuitJson:[...r,a,g,l,I],parameters:A}},b6A=(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}},iDe=Wi.extend({fn:J(),num_pins:Ze([kA(3),kA(2)]).default(3),p:J().default("3.8mm"),id:J().default("1.25mm"),od:J().default("2.35mm"),ca:J().default("14mm").describe("Caliper axis (width or diameter of the potentiometer body or adjustment knob)"),w:J().default("5.35mm"),h:J().default("4mm"),string:J().optional()}),nDe=e=>{const{p:A,id:t,od:i,h:n,ca:o}=e,s=Number.parseFloat(n),r=Number.parseFloat(o);return[Xo(1,0,r/4+.3,t,i),Xo(2,s,0,t,i),Xo(3,0,-r/4-.3,t,i)]},oDe=e=>{const A=e.string?.match(/^potentiometer_(\d+)/),t=A?Number.parseInt(A[1],10):3,i=iDe.parse({...e,num_pins:t});let n=[];i.num_pins===3&&(n=nDe(i));const o=Number.parseFloat(i.ca)/2+.15,s=Number.parseFloat(i.w),r=Number.parseFloat(i.od)/2+.35,a={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:0,y:o-1.75},{x:0,y:o},{x:s,y:o},{x:s,y:r}],stroke_width:.1,pcb_silkscreen_path_id:""},g={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:s,y:-r},{x:s,y:-o},{x:0,y:-o},{x:0,y:-o+1.75}],stroke_width:.1,pcb_silkscreen_path_id:""},c=Number.parseFloat(i.w)/2,I=Oi(c,o+1,.5);return{circuitJson:[...n,a,g,I],parameters:i}},sDe=Wi.extend({fn:J(),p:hA.optional().default("7.5mm"),id:hA.optional().default("1mm"),od:hA.optional().default("2mm"),d:hA.optional().default("10.5mm")}),rDe=(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}},aDe=e=>{const A=sDe.parse(e),{p:t,id:i,od:n,d:o}=A,s=[Xo(1,-t/2,0,i,n),Xo(2,t/2,0,i,n)],{topArc:r,bottomArc:a}=rDe(0,0,o/2+.1,n/2,n),g={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:r,stroke_width:.1,pcb_silkscreen_path_id:""},c={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:a,stroke_width:.1,pcb_silkscreen_path_id:""},I={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:0,y:o/2+.1},{x:0,y:-(o/2+.1)}],stroke_width:.1,pcb_silkscreen_path_id:""},l=-(o/2+.5),B=n/2+1.5,C=.5,Q={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:l-C,y:B},{x:l+C,y:B}],stroke_width:.1,pcb_silkscreen_path_id:""},h={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:l,y:B-C},{x:l,y:B+C}],stroke_width:.1,pcb_silkscreen_path_id:""},E=Oi(0,o/2+1,.5);return{circuitJson:[...s,g,c,I,Q,h,E],parameters:A}},gDe=Wi.extend({fn:J(),num_pins:kA(2).default(2),w:J().default("6.5mm"),h:J().default("3mm"),pl:J().default("1.75mm"),pw:J().default("2.40mm"),p:J().default("4.75mm")}),cDe=e=>{const A=gDe.parse(e),t=Oi(0,hA.parse(A.h)-.5,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:hA.parse(A.p)/2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2-.3,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2-.3,y:-hA.parse(A.h)/2},{x:hA.parse(A.p)/2,y:-hA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:lDe(A).concat(i,t),parameters:A}},IDe=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},lDe=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=IDe({pn:t,p:Number.parseFloat(e.p)});A.push(di(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},BDe=Wi.extend({fn:J(),num_pins:WA().default(3),w:J().default("2.45mm"),h:J().default("2.40mm"),pl:J().default("1.225mm"),pw:J().default("0.5mm"),p:J().default("0.95mm"),string:J().optional()}),CDe=e=>{const A=e.string?.match(/^sot323_(\d+)/),t=A?Number.parseInt(A[1],3):3,i=BDe.parse({...e,num_pins:t});if(i.num_pins===3)return{circuitJson:hDe(i),parameters:i};throw new Error("Invalid number of pins")},QDe=e=>{const{pn:A,p:t}=e;return A===1?{x:-t,y:.65}:A===2?{x:-t,y:-.65}:{x:t,y:0}},hDe=e=>{const A=[];for(let r=0;r<e.num_pins;r++){const{x:a,y:g}=QDe({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(di(r+1,a,g,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}const t=Oi(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]},EDe=Wi.extend({fn:J(),circle:gt().optional(),rect:gt().optional(),square:gt().optional(),pill:gt().optional(),d:hA.optional(),pd:hA.optional(),diameter:hA.optional(),r:hA.optional(),pr:hA.optional(),radius:hA.optional(),w:hA.optional(),pw:hA.optional(),width:hA.optional(),h:hA.optional(),ph:hA.optional(),height:hA.optional(),s:hA.optional(),size:hA.optional(),string:J().optional()}).transform(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=Fr(e.r):e.pr!==void 0?t=Fr(e.pr):e.radius!==void 0?t=Fr(e.radius):e.d!==void 0?t=Fr(e.d)/2:e.pd!==void 0?t=Fr(e.pd)/2:e.diameter!==void 0?t=Fr(e.diameter)/2:t=Fr("1mm")/2:(e.w!==void 0?i=Fr(e.w):e.pw!==void 0?i=Fr(e.pw):e.width!==void 0?i=Fr(e.width):e.s!==void 0?i=Fr(e.s):e.size!==void 0?i=Fr(e.size):i=Fr("1mm"),e.h!==void 0?n=Fr(e.h):e.ph!==void 0?n=Fr(e.ph):e.height!==void 0?n=Fr(e.height):A==="square"||A==="rect"?n=i:n=Fr("1mm")),{fn:e.fn,shape:A,radius:t,width:i,height:n}}),uDe=e=>{const A=EDe.parse(e),{shape:t,radius:i,width:n,height:o}=A;let s,r;return t==="circle"?(s=r6A(1,{x:0,y:0,radius:i}),r=i+.5):t==="pill"?(s=HW(1,0,0,n,o),r=Math.max(n,o)/2+.5):(s=di(1,0,0,n,o),r=o/2+.5),{circuitJson:[s,Oi(0,r,.2)],parameters:A}},dDe=Wi.extend({fn:J(),d:hA.optional(),hd:hA.optional(),r:hA.optional(),hr:hA.optional(),pd:hA.optional(),pr:hA.optional(),squarepad:gt().optional().default(!1)}).transform(e=>{let A;e.d!==void 0?A=Fr(e.d):e.hd!==void 0?A=Fr(e.hd):e.r!==void 0?A=Fr(e.r)*2:e.hr!==void 0?A=Fr(e.hr)*2:A=Fr("1mm");let t;return e.pd!==void 0?t=Fr(e.pd):e.pr!==void 0?t=Fr(e.pr)*2:t=A*(1.5/1),{fn:e.fn,d:A,pd:t,squarepad:e.squarepad??!1}}),pDe=e=>{const A=dDe.parse(e),{d:t,pd:i,squarepad:n}=A;return{circuitJson:[n?lb(1,0,0,t,i,i):Xo(1,0,0,t,i),Oi(0,i/2+.5,.2)],parameters:A}},fDe=Wi.extend({fn:J(),num_pins:kA(6).default(6),h:J().default("1.6mm"),pl:J().default("1mm"),pw:J().default("0.7mm"),p:J().default("0.95mm")}),yDe=e=>{const A=fDe.parse(e);return{circuitJson:mDe(A),parameters:A}},x6A=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")},mDe=e=>{const A=[];for(let I=1;I<=e.num_pins;I++){const{x:l,y:B}=x6A({h:Number.parseFloat(e.h),p:Number.parseFloat(e.p),pn:I});A.push(di(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=Oi(0,i+.3,.3),r=x6A({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]},wDe=Wi.extend({fn:J(),num_pins:WA().default(4),w:J().default("3.2mm"),h:J().default("2.6mm"),pl:J().default("1.35mm"),pw:J().default("0.50mm"),p:J().default("0.6mm"),string:J().optional()}),DDe=e=>{const A=e.string?.match(/^sot343_(\d+)/),t=A?Number.parseInt(A[1],4):4,i=wDe.parse({...e,num_pins:t});if(i.num_pins===4)return{circuitJson:bDe(i),parameters:i};throw new Error("Invalid number of pins")},SDe=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}},bDe=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:p,y:m}=SDe({num_pins:e.num_pins,pn:d+1,p:s});A.push(di(d+1,p,m,n,o)),p<r&&(r=p),p>a&&(a=p),m<g&&(g=m),m>c&&(c=m)}const I=(r+a)/2,l=c-g,B=i*.3,C=l/2+B;let Q=t*.8;i<=2.6&&(Q/=2);const h=Oi(I,C+.5,.3),E={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_top",route:[{x:I-Q/2,y:C},{x:I+Q/2,y:C}],type:"pcb_silkscreen_path",stroke_width:.1},u={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_bottom",route:[{x:I-Q/2,y:-C},{x:I+Q/2,y:-C}],type:"pcb_silkscreen_path",stroke_width:.1};return[...A,E,u,h]},xDe=Wi.extend({fn:J()}),_De=e=>{const A=xDe.parse(e),t=[],i=.5-.15,n=1.5,s=.5/2,r=75,a=-37/2;for(let D=0;D<r;D++){const S=D+1;if(S>=24&&S<=31)continue;const k=a-D*s,x=S%2===0,N=n+(x?.25:0),L=.5-N/2,Y=di(S,L,k,N,i);Y.layer=x?"bottom":"top",t.push(Y)}const g=46*.0254,c=137*.0254,I=261*.0254,l={type:"pcb_cutout",pcb_cutout_id:"",shape:"rect",center:{x:-c/2+n/2,y:a-I},width:c,height:g},B={x:-.5,y:a},C={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"pin_marker_1",route:[{x:B.x-.4,y:B.y},{x:B.x-.7,y:B.y+.3},{x:B.x-.7,y:B.y-.3},{x:B.x-.4,y:B.y}],stroke_width:.05,pcb_silkscreen_path_id:"pin_marker_1"};let Q=1/0,h=-1/0,E=1/0,u=-1/0;const d=(D,S,k=0,x=0)=>{Q=Math.min(Q,D-k/2),h=Math.max(h,D+k/2),E=Math.min(E,S-x/2),u=Math.max(u,S+x/2)};for(const D of t)d(D.x,D.y,D.width,D.height);d(l.center.x,l.center.y,l.width,l.height);for(const D of C.route)d(D.x,D.y);const p=(Q+h)/2,m=(E+u)/2,w=D=>{typeof D.x=="number"&&(D.x-=p),typeof D.y=="number"&&(D.y-=m),D.center&&(D.center.x-=p,D.center.y-=m),Array.isArray(D.route)&&(D.route=D.route.map(S=>({x:S.x-p,y:S.y-m})))};for(const D of t)w(D);return w(l),w(C),{circuitJson:[...t,l,C],parameters:A}},kDe=Wi.extend({fn:J(),num_pins:WA().default(3),inline:gt().default(!1),p:J().default("1.27mm"),id:J().default("0.75mm"),od:J().default("1.3mm"),w:J().default("4.8mm"),h:J().default("4.0mm")}),FDe=e=>{const A=kDe.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=[lb(1,0,0,A.id,o,s,0,0),A.inline?bH(2,t,0,A.id,o,s):Xo(2,t,t,A.id,o),A.inline?bH(3,t*2,0,A.id,o,s):Xo(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=Oi(g,c+a+1,.5);return{circuitJson:[...r,B,C],parameters:A}};function GDe(e){return e!=null}var RDe=(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=1/0,n=-1/0,o=1/0,s=-1/0;const r=(c,I,l=0,B=0)=>{const C=c-l/2,Q=c+l/2,h=I-B/2,E=I+B/2;i=Math.min(i,C),n=Math.max(n,Q),o=Math.min(o,h),s=Math.max(s,E)};for(const c of 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},MDe=(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},NDe=(e,A)=>A.nosilkscreen?e.filter(t=>t.type!=="pcb_silkscreen_path"&&t.type!=="pcb_silkscreen_text"):e,vDe=e=>{let A=KW();const i=e.replace(/^((?:\d{4}|\d{5}))(?=$|_)/,"res$1").split(/_(?!metric)/).map(n=>{const o=n.match(/([a-zA-Z]+)([\(\d\.\+\?].*)?/);if(!o)return null;const[,s,r]=o;if(!s)return null;const a=s.toLowerCase();return r?.includes("?")?null:{fn:a,v:r}}).filter(GDe);for(const{fn:n,v:o}of i)A=A[n](o);return A.setString(e),A},LDe=()=>Object.keys(Ib),KW=()=>{const e=new Proxy({},{get:(A,t)=>{if(t==="soup"||t==="circuitJson"){if("fn"in A&&Ib[A.fn])return()=>{const{circuitJson:i}=Ib[A.fn](A),n=NDe(i,A),o=MDe(n,A);return RDe(o,A.origin)};if(!Ib[A.fn])throw new Error(`Invalid footprint function, got "${A.fn}"${A.string?`, from string "${A.string}"`:""}`);return()=>{throw new Error(`No function found for footprinter, make sure to specify .dip, .lr, .p, etc. Got "${t}"`)}}if(t==="json"){if(!Ib[A.fn])throw new Error(`Invalid footprint function, got "${A.fn}"${A.string?`, from string "${A.string}"`:""}`);return()=>Ib[A.fn](A).parameters}return t==="getFootprintNames"?()=>Object.keys(Ib):t==="params"?()=>A:t==="setString"?i=>(A.string=i,e):i=>(Object.keys(A).length===0?`${t}${i}`in Ib?(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};KW.string=vDe,KW.getFootprintNames=LDe;var UDe=KW,_6A=Symbol("Fragment");function QEA(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"),k6A=Symbol("Cube"),Rl=Symbol("Cylinder"),PW=Symbol("Sphere"),xH=Symbol("RoundedCuboid"),Pi=Symbol("Translate"),$B=Symbol("Rotate"),vQ=Symbol("Union"),gw=Symbol("Subtract"),pc=Symbol("Hull"),Po=Symbol("Colorize"),_H=Symbol("Polygon"),kH=Symbol("ExtrudeLinear"),pf=Symbol("RoundedCylinder"),Mn=_6A,zA=(e,A,t)=>QEA(e,A),Je=(e,A,t)=>QEA(e,A),IB=({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),p=Math.max(t-u,t*r),m=Math.min(A,t)*.12,w=c??m,D={x:0,y:t/2-w*.25,z:i},S=I??D,k=Je(vQ,{children:[Je(pc,{children:[zA(Pi,{z:.005,children:zA(Qe,{size:[d,p,.01]})}),zA(Pi,{z:h,children:zA(Qe,{size:[A,t,.01]})})]}),Je(pc,{children:[zA(Pi,{z:h,children:zA(Qe,{size:[A,t,.01]})}),zA(Pi,{z:h+E,children:zA(Qe,{size:[d,p,.01]})})]})]}),x=(M,L)=>zA(Pi,{offset:{x:M,y:L,z:0},children:zA($B,{rotation:[0,0,Math.PI/4],children:zA(Qe,{size:[Q*Math.SQRT2,Q*Math.SQRT2,i*3]})})});let N=k;if(Q>0){const M=A/2,L=t/2;N=Je(gw,{children:[k,x(M,L),x(-M,L),x(M,-L),x(-M,-L)]})}return zA(Po,{color:o,children:zA(Pi,{offset:e,children:zA(Pi,{offset:{x:0,y:0,z:n},children:g?Je(gw,{children:[N,zA(Pi,{offset:S,children:zA($B,{rotation:l,children:zA(Rl,{radius:w,height:C})})})]}):N})})})},HDe=e=>Array.from({length:e},(A,t)=>t);function hEA(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 p=1/u;r(l,{x:h*p,y:E*p},1),r(l,{x:h*p,y:E*p},-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 YDe=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}))},JDe=YDe([{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}]),F6A=5.47,qW=.5,TDe=({x:e,y:A,z:t})=>{const i=e>0;return Je(Mn,{children:[zA(Pi,{offset:{x:e+.25/2,y:A,z:t},children:zA($B,{rotation:["-90deg",0,"90deg"],children:zA(kH,{height:.25,children:zA(_H,{points:JDe.slice().reverse().map(n=>[n.x,n.y])})})})}),zA(Pi,{offset:{x:e,y:A+(i?1:-1),z:t},children:zA($B,{rotation:["-90deg","90deg",i?"180deg":"0deg"],children:zA(kH,{height:2,children:zA(_H,{points:hEA([[0,0],[-1,0],[-1,-1]],.25).map(n=>[n.x,n.y])})})})})]})},KDe=({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 Je(Mn,{children:[HDe(e).map(r=>{const a=r%n,g=(Math.floor(r/n)-.5)*2;return zA(TDe,{x:g*o/2,y:a*A-(n-1)/2*A,z:F6A/2+qW})}),zA(IB,{width:s,length:n*A+.5,height:F6A-qW,heightAboveSurface:qW,center:{x:0,y:0,z:qW}})]})};function PDe(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 zn=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,PDe(c,e)]),g=hEA(a,A);return zA(Po,{color:"#fff",children:zA(Pi,{offset:{z:0,y:0,x:0,...e.position},children:zA($B,{rotation:["90deg",0,s??0],children:zA(Pi,{offset:{x:0,y:0,z:-t/2},children:zA(kH,{height:t,children:zA(_H,{points:g.map(c=>[c.x,c.y])})})})})})})},qDe=({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 Je(Mn,{children:[Array.from({length:o}).map((g,c)=>zA(zn,{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(zn,{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(IB,{center:{x:0,y:0,z:a/2},width:n-t-1,length:s,height:1.5})]})},ODe=({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 Je(Mn,{children:[Array.from({length:o}).map((a,g)=>zA(zn,{position:{x:-n/2-A-.3,y:g*i-s,z:r/2},width:t,thickness:r,padContactLength:A,bodyDistance:A+.4,height:.6})),Array.from({length:o}).map((a,g)=>zA(zn,{rotation:Math.PI,position:{x:n/2+A+.3,y:g*i-s,z:r/2},width:t,thickness:r,padContactLength:A,bodyDistance:A+.4,height:.6})),zA(IB,{center:{x:0,y:0,z:r/2},width:n,length:n,height:1.1,notchRadius:.35,heightAboveSurface:.1,taperRatio:.09})]})},EEA=1,uEA=.5,av=.5,FH=.2,WDe=EEA-FH*2,G6A=({color:e="#333"})=>Je(Mn,{children:[zA(Qe,{size:[WDe,uEA,av],offset:[0,0,av/2],color:e}),zA(Qe,{size:[FH,av,uEA],offset:[EEA/2-FH/2,0,av/2],color:"#ccc"}),zA(Qe,{size:[FH,av,uEA],offset:[-EEA/2+FH/2,0,av/2],color:"#ccc"})]}),dEA=1.6,ZDe=dEA-.3*2,OW=.3,pEA=.85,gv=.6,R6A=({color:e="#333"})=>Je(Mn,{children:[zA(Qe,{size:[ZDe,pEA,gv],offset:[0,0,gv/2],color:e}),zA(Qe,{size:[OW,pEA,gv],offset:[dEA/2-OW/2,0,gv/2],color:"#ccc"}),zA(Qe,{size:[OW,pEA,gv],offset:[-dEA/2+OW/2,0,gv/2],color:"#ccc"})]}),fEA=2,yEA=1.25,cv=.55,GH=.5,VDe=fEA-GH*2,M6A=({color:e="#333"})=>Je(Mn,{children:[zA(Qe,{size:[VDe,yEA,cv],offset:[0,0,cv/2],color:e}),zA(Qe,{size:[GH,yEA,cv],offset:[fEA/2-GH/2,0,cv/2],color:"#ccc"}),zA(Qe,{size:[GH,yEA,cv],offset:[-fEA/2+GH/2,0,cv/2],color:"#ccc"})]}),jDe=({pinCount:e,pitch:A,leadWidth:t,padContactLength:i,bodyWidth:n})=>{const o=e/4;A||(A=zDe(e,n)),i||(i=XDe(e)),t||(t=$De(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 Je(Mn,{children:[Array.from({length:o}).map((B,C)=>zA(zn,{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(zn,{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(zn,{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(zn,{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(IB,{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})]})},zDe=(e,A)=>{switch(e){case 44:case 64:return .8;case 52:return A===14?1:.65;case 208:return .5;default:return .5}},XDe=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}},$De=(e,A)=>{switch(e){case 44:case 64:return .5;case 52:return A===14?.45:.55;case 208:return .3;default:return .25}},N6A=({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})=>Je(Mn,{children:[zA(Pi,{y:I?-3:0,children:zA(Qe,{color:"#222",size:[s,r,o],center:[e,A,a(o/2)]})}),!g&&zA(Po,{color:"gold",children:c?zA(zn,{rotation:-Math.PI/2,position:{x:e,y:A+1,z:t/2},thickness:t,width:t,height:t,padContactLength:2,bodyDistance:3}):Je(pc,{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(Po,{color:"gold",children:zA(Pi,{y:I?-3.9:0,z:I?1:0,children:zA($B,{rotation:I?[-Math.PI/2,0,0]:[0,0,0],children:Je(pc,{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)]})]})})})})]}),ASe=({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(Mn,{children:Array.from({length:e},(h,E)=>{const u=Math.floor(E/c),d=E%c,p=B+d*A,m=-u*I;return zA(N6A,{x:p,y:m,pinThickness:.63,shortSidePinLength:l,longSidePinLength:t,bodyHeight:2,flipZ:Q,faceup:n,smd:s,rightangle:r},E)})})},tSe=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")}},eSe=({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},iSe=({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=eSe({num_pins:e,cw:!0,ccw:!0}),c=[];for(let I=0;I<e;I++){const{x:l,y:B,o:C}=tSe({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 Je(Mn,{children:[zA(Po,{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]})]})},nSe=iSe,oSe=()=>{const a=1.1999999999999997;return Je(Mn,{children:[zA(zn,{rotation:Math.PI,position:{x:2.8/2+a/4,y:-1,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:a,height:.95}),zA(zn,{rotation:Math.PI,position:{x:2.8/2+a/4,y:1,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:a,height:.95}),zA(zn,{position:{x:-2.8/2-a/4,y:0,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:a,height:.95}),zA(zn,{position:{x:-2.8/2-a/4,y:-1,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:a,height:.95}),zA(zn,{position:{x:-2.8/2-a/4,y:1,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:a,height:.95}),zA(IB,{center:{x:0,y:0,z:0},width:1.6,length:2.9,height:1.2})]})},sSe=oSe,rSe=({fullWidth:e=2.9,fullLength:A=2.8})=>{const c=(e-1.92)/2+.3;return Je(Mn,{children:[zA(zn,{rotation:Math.PI,position:{x:e/2,y:0,z:.075},width:.4,thickness:.15,padContactLength:.25,bodyDistance:c,height:.45}),zA(zn,{position:{x:-e/2,y:-.95,z:.075},width:.4,thickness:.15,padContactLength:.25,bodyDistance:c,height:.45}),zA(zn,{position:{x:-e/2,y:.95,z:.075},width:.4,thickness:.15,padContactLength:.25,bodyDistance:c,height:.45}),zA(IB,{center:{x:0,y:0,z:0},width:1.92,length:2.9,height:1.1,straightHeightRatio:.45,heightAboveSurface:.05})]})},mEA=.6,wEA=.3,Iv=.33,RH=.1,aSe=mEA-RH*2,v6A=({color:e="#333"})=>Je(Mn,{children:[zA(Qe,{size:[aSe,wEA,Iv],offset:[0,0,Iv/2],color:e}),zA(Qe,{size:[RH,wEA,Iv],offset:[mEA/2-RH/2,0,Iv/2],color:"#ccc"}),zA(Qe,{size:[RH,wEA,Iv],offset:[-mEA/2+RH/2,0,Iv/2],color:"#ccc"})]}),DEA=.4,SEA=.2,lv=.13,MH=.07,gSe=DEA-MH*2,L6A=({color:e="#333"})=>Je(Mn,{children:[zA(Qe,{size:[gSe,SEA,lv],offset:[0,0,lv/2],color:e}),zA(Qe,{size:[MH,SEA,lv],offset:[DEA/2-MH/2,0,lv/2],color:"#ccc"}),zA(Qe,{size:[MH,SEA,lv],offset:[-DEA/2+MH/2,0,lv/2],color:"#ccc"})]}),bEA=3.2,xEA=1.6,Bv=.9,NH=.5,cSe=bEA-NH*2,U6A=({color:e="#333"})=>Je(Mn,{children:[zA(Qe,{size:[cSe,xEA,Bv],offset:[0,0,Bv/2],color:e}),zA(Qe,{size:[NH,xEA,Bv],offset:[bEA/2-NH/2,0,Bv/2],color:"#ccc"}),zA(Qe,{size:[NH,xEA,Bv],offset:[-bEA/2+NH/2,0,Bv/2],color:"#ccc"})]}),_EA=3.2,kEA=2.5,Cv=1,vH=.6,ISe=_EA-vH*2,H6A=({color:e="#333"})=>Je(Mn,{children:[zA(Qe,{size:[ISe,kEA,Cv],offset:[0,0,Cv/2],color:e}),zA(Qe,{size:[vH,kEA,Cv],offset:[_EA/2-vH/2,0,Cv/2],color:"#ccc"}),zA(Qe,{size:[vH,kEA,Cv],offset:[-_EA/2+vH/2,0,Cv/2],color:"#ccc"})]}),FEA=5,GEA=2.5,Qv=1.4,LH=.6,lSe=FEA-LH*2,Y6A=({color:e="#333"})=>Je(Mn,{children:[zA(Qe,{size:[lSe,GEA,Qv],offset:[0,0,Qv/2],color:e}),zA(Qe,{size:[LH,GEA,Qv],offset:[FEA/2-LH/2,0,Qv/2],color:"#ccc"}),zA(Qe,{size:[LH,GEA,Qv],offset:[-FEA/2+LH/2,0,Qv/2],color:"#ccc"})]}),REA=6.3,MEA=3.2,hv=1.8,UH=.8,BSe=REA-UH*2,J6A=({color:e="#333"})=>Je(Mn,{children:[zA(Qe,{size:[BSe,MEA,hv],offset:[0,0,hv/2],color:e}),zA(Qe,{size:[UH,MEA,hv],offset:[REA/2-UH/2,0,hv/2],color:"#ccc"}),zA(Qe,{size:[UH,MEA,hv],offset:[-REA/2+UH/2,0,hv/2],color:"#ccc"})]}),CSe=({x:e,y:A,pitch:t=2.54,legsLength:i=3,innerDiameter:n=.945,bodyHeight:o=5,bodyLength:s=t,bodyWidth:r=t,flipZ:a})=>{const g=n/1.5,c=g*1.6;return Je(Mn,{children:[zA(Po,{color:"#1a1a1a",children:Je(gw,{children:[zA(Qe,{color:"#000",size:[s,r,o],center:[e,A,a(o/2)]}),n?zA(Rl,{height:o+.1,radius:n/2,center:[e,A,a(o/2)],color:"#222"}):zA(Qe,{size:[c,c,o],center:[e,A,a(o/2)]})]})}),Je(Po,{color:"silver",children:[Je(pc,{children:[zA(Qe,{color:"silver",size:[g,g,i*.9],center:[e,A,a(-i/2*.9)]}),zA(Qe,{color:"silver",size:[g/1.8,g/1.8,i],center:[e,A,a(-i/2)]})]}),zA(Qe,{color:"silver",size:[c,c,c*.5],center:[e,A,a(c/2*.5)]})]})]})},QSe=({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(Mn,{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(CSe,{x:Q,y:h,pitch:A,legsLength:t,innerDiameter:i,flipZ:c},l)})})},hSe=({width:e,length:A,innerDiameter:t=1})=>{const i=e,n=A,o=e*.7,s=t/2.5;return Je(Mn,{children:[zA(xH,{color:"#1a1a1f",center:[0,0,o/2],size:[n,n,o],roundRadius:.3}),zA(xH,{color:"#f2f2f2",center:[0,0,o+o*.1/2.5],size:[n,n,o*.1],roundRadius:.14}),zA(Rl,{color:"#1a1a1f",height:o*.8,radius:i/3,center:[0,0,o+o*.8/2]}),zA(Rl,{color:"#1a1a1f",height:o*.2,radius:t/2,center:[n/3,n/3,o+o*.1/2]}),zA(Rl,{color:"#1a1a1f",height:o*.2,radius:t/2,center:[-n/3,-n/3,o+o*.1/2]}),zA(Rl,{color:"#1a1a1f",height:o*.2,radius:t/2,center:[-n/3,n/3,o+o*.1/2]}),zA(Rl,{color:"#1a1a1f",height:o*.2,radius:t/2,center:[n/3,-n/3,o+o*.1/2]}),zA(WW,{thickness:t/3,width:s,horizontalLength:n*.8,verticalLength:o/2,position:{x:-i/2,y:-n/2,z:-o*1.2}}),zA(WW,{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(WW,{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(WW,{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}})]})},WW=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=hEA(r,A);return zA(Po,{color:"#f2f2f2",children:zA(Pi,{offset:{x:s?.x||0,y:s?.y||0,z:s?.z||0},children:zA($B,{rotation:[0,55,o],children:zA(kH,{height:t,children:zA(_H,{points:a.map(g=>[g.y,g.x])})})})})})},ESe=({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 Je(Mn,{children:[Array.from({length:o}).map((B,C)=>zA(zn,{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(zn,{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(IB,{center:{x:0,y:0,z:r/2},width:l,length:I,height:a})]})},uSe=({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 Je(Mn,{children:[Array.from({length:I}).map((u,d)=>zA(zn,{position:{x:-Q/2,y:l-d*r,z:B/2},width:a,thickness:B,padContactLength:E+.05,bodyDistance:h+.1,height:C})),Array.from({length:I}).map((u,d)=>zA(zn,{rotation:Math.PI,position:{x:Q/2,y:l-d*r,z:B/2},width:a,thickness:B,padContactLength:E+.05,bodyDistance:h+.1,height:C})),zA(IB,{center:{x:0,y:0,z:B/2},width:g,length:c,height:1})]})},dSe=()=>Je(Mn,{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(Po,{color:"#222",children:Je(vQ,{children:[zA(Pi,{z:.3/2,children:zA(Qe,{size:[1.65,.8,.3]})}),Je(pc,{children:[zA(Pi,{z:.3,children:zA(Qe,{size:[1.65,.8,.01]})}),zA(Pi,{z:.6,children:zA(Qe,{size:[1.65-.2,.8-.2,.01]})})]})]})})]}),pSe=()=>Je(Mn,{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(Po,{color:"#222",children:zA(Pi,{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]})]}),fSe=()=>{const g=zA(Po,{color:"#1a1a1a",children:Je(vQ,{children:[Je(pc,{children:[zA(Pi,{z:.13,children:zA(Qe,{size:[4,3,.03]})}),zA(Pi,{z:1.15,children:zA(Qe,{size:[4.4,3.4,.01]})})]}),Je(pc,{children:[zA(Pi,{z:1.15,children:zA(Qe,{size:[4.4,3.4,.01]})}),zA(Pi,{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(Po,{color:"#c0c0c0",children:Je(vQ,{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 Je(Mn,{children:[zA(c,{xDir:1}),zA(c,{xDir:-1}),g]})},ySe=()=>{const g=zA(Po,{color:"#1a1a1a",children:Je(vQ,{children:[Je(pc,{children:[zA(Pi,{z:.13,children:zA(Qe,{size:[4,3,.03]})}),zA(Pi,{z:1.15,children:zA(Qe,{size:[4.4,3.4,.01]})})]}),Je(pc,{children:[zA(Pi,{z:1.15,children:zA(Qe,{size:[4.4,3.4,.01]})}),zA(Pi,{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(Po,{color:"#c0c0c0",children:Je(vQ,{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 Je(Mn,{children:[zA(c,{xDir:1}),zA(c,{xDir:-1}),g]})},mSe=()=>{const g=zA(Po,{color:"#1a1a1a",children:Je(vQ,{children:[Je(pc,{children:[zA(Pi,{z:.21000000000000002,children:zA(Qe,{size:[6.3999999999999995,5.6,.03]})}),zA(Pi,{z:1.15,children:zA(Qe,{size:[6.8,6,.01]})})]}),Je(pc,{children:[zA(Pi,{z:1.15,children:zA(Qe,{size:[6.8,6,.01]})}),zA(Pi,{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(Po,{color:"#c0c0c0",children:Je(vQ,{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 Je(Mn,{children:[zA(c,{xDir:1}),zA(c,{xDir:-1}),g]})},wSe=()=>{const I=zA(Po,{color:"#222",children:Je(vQ,{children:[zA(Pi,{z:.27,children:zA(Qe,{size:[2.9,1.9,.54]})}),Je(pc,{children:[zA(Pi,{z:.54,children:zA(Qe,{size:[2.9,1.9,.01]})}),zA(Pi,{z:1.08,children:zA(Qe,{size:[2.6999999999999997,1.7,.01]})})]})]})});return Je(Mn,{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]})},DSe=()=>Je(Mn,{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(Po,{color:"#222",children:Je(vQ,{children:[zA(Pi,{z:.55/2,children:zA(Qe,{size:[2.7,1.6,.55]})}),Je(pc,{children:[zA(Pi,{z:.55,children:zA(Qe,{size:[2.7,1.6,.01]})}),zA(Pi,{z:1.1,children:zA(Qe,{size:[2.7-.2,1.6-.2,.01]})})]})]})})]}),SSe=()=>Je(Mn,{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(Po,{color:"#222",children:Je(vQ,{children:[zA(Pi,{z:.2/2,children:zA(Qe,{size:[2.75,1.8,.2]})}),Je(pc,{children:[zA(Pi,{z:.2,children:zA(Qe,{size:[2.75,1.8,.01]})}),zA(Pi,{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]})]}),bSe=()=>Je(Mn,{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(Po,{color:"#222",children:Je(vQ,{children:[Je(pc,{children:[zA(Pi,{z:.2,children:zA(Qe,{size:[2.6-.1/2,1.7-.1/2,.01]})}),zA(Pi,{z:.01,children:zA(Qe,{size:[2.6-.1,1.7-.1,.01]})})]}),Je(pc,{children:[zA(Pi,{z:.2,children:zA(Qe,{size:[2.6,1.7,.01]})}),zA(Pi,{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]})]}),xSe=()=>Je(Mn,{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(Po,{color:"#222",children:Je(vQ,{children:[Je(pc,{children:[zA(Pi,{z:.2,children:zA(Qe,{size:[3.8-.05/2,2.5-.05/2,.01]})}),zA(Pi,{z:.01,children:zA(Qe,{size:[3.8-.05,2.5-.05,.01]})})]}),Je(pc,{children:[zA(Pi,{z:.2,children:zA(Qe,{size:[3.8,2.5,.01]})}),zA(Pi,{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]})]}),_Se=()=>Je(Mn,{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(Po,{color:"#222",children:Je(vQ,{children:[zA(Pi,{z:.14/2,children:zA(Qe,{size:[.8,.6,.14]})}),Je(pc,{children:[zA(Pi,{z:.14,children:zA(Qe,{size:[.8,.6,.01]})}),zA(Pi,{z:.37,children:zA(Qe,{size:[.8-.1,.6-.1,.01]})})]})]})})]}),kSe=()=>{const c=3.0999999999999996;return Je(Mn,{children:[zA(zn,{rotation:Math.PI,position:{x:6.6/2+c/4,y:0,z:.25/2},width:3,thickness:.25,padContactLength:.5,bodyDistance:c,height:.75}),zA(zn,{position:{x:-6.6/2-c/4,y:0,z:.25/2},width:.7,thickness:.25,padContactLength:.5,bodyDistance:c,height:.75}),zA(zn,{position:{x:-6.6/2-c/4,y:-2.3,z:.25/2},width:.7,thickness:.25,padContactLength:.5,bodyDistance:c,height:.75}),zA(zn,{position:{x:-6.6/2-c/4,y:2.3,z:.25/2},width:.7,thickness:.25,padContactLength:.5,bodyDistance:c,height:.75}),zA(IB,{center:{x:0,y:0,z:0},width:3.5,length:6.5,height:1.7,includeNotch:!1,taperRatio:.06,straightHeightRatio:.45})]})},FSe=()=>Je(Mn,{children:[Array.from({length:16}).map((B,C)=>zA(zn,{position:{x:-10.5/2,y:C*.5-3.75,z:.25/2},width:.2,thickness:.25,padContactLength:.45,bodyDistance:.95,height:.65})),Array.from({length:16}).map((B,C)=>zA(zn,{rotation:Math.PI,position:{x:10.5/2,y:C*.5-3.75,z:.25/2},width:.2,thickness:.25,padContactLength:.45,bodyDistance:.95,height:.65})),Array.from({length:16}).map((B,C)=>zA(zn,{rotation:Math.PI/2,position:{x:C*.5-3.75,y:-10.5/2,z:.25/2},width:.2,thickness:.25,padContactLength:.45,bodyDistance:.95,height:.65})),Array.from({length:16}).map((B,C)=>zA(zn,{rotation:-Math.PI/2,position:{x:C*.5-3.75,y:10.5/2,z:.25/2},width:.2,thickness:.25,padContactLength:.45,bodyDistance:.95,height:.65})),zA(IB,{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})]}),GSe=FSe,RSe=()=>{const g=.7999999999999998;return Je(Mn,{children:[zA(zn,{rotation:Math.PI,position:{x:2.05/2+g/4,y:0,z:.18/2},width:.3,thickness:.18,padContactLength:.2,bodyDistance:g,height:.65}),zA(zn,{position:{x:-2.05/2-g/4,y:-.65,z:.18/2},width:.3,thickness:.18,padContactLength:.2,bodyDistance:g,height:.65}),zA(zn,{position:{x:-2.05/2-g/4,y:.65,z:.18/2},width:.3,thickness:.18,padContactLength:.2,bodyDistance:g,height:.65}),zA(IB,{center:{x:0,y:0,z:0},width:1.25,length:2,height:.9,includeNotch:!1,taperRatio:.06,straightHeightRatio:.7,heightAboveSurface:.05})]})},MSe=({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 Je(Mn,{children:[Array.from({length:o}).map((B,C)=>zA(zn,{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(zn,{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(zn,{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(zn,{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(IB,{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})]})},NSe=()=>{const i=.20900000000000002,n=.1,o=.3,s=.1,r=.2;return Je(Mn,{children:[zA(Po,{color:"#222",children:Je(vQ,{children:[zA(Qe,{size:[.85,1.2,i],center:[0,0,i/2]}),Je(pc,{children:[zA(Pi,{z:i,children:zA(Qe,{size:[.85,1.2,.01]})}),zA(Pi,{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]})]})},vSe=({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 Je(Mn,{children:[zA(IB,{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]})]})},LSe=({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 Je(Mn,{children:[Je(Po,{color:s,children:[Je(pc,{children:[zA(pf,{height:t,roundRadius:.5,radius:g,center:[-c,0,t]}),zA(pf,{height:t,roundRadius:.5,radius:g,center:[c,0,t]})]}),Je(pc,{children:[zA(pf,{height:l,roundRadius:.1,radius:g+.85,center:[-c,0,t/2+l/2]}),zA(pf,{height:l,roundRadius:.1,radius:g+.85,center:[c,0,t/2+l/2]})]})]}),Je(Po,{color:r,children:[zA(Rl,{height:o+t/2,radius:n/2,center:[-I+.06,0,-(o/2)+t/2]}),zA(Rl,{height:o+t/2,radius:n/2,center:[I-.06,0,-(o/2)+t/2]})]})]})},USe=({bodyLength:e=1.4,bodyDiameter:A=1.1,color:t="#3a3a3aff",contactColor:i="#c6c6c6",cathodeIdentification:n="#111"})=>Je(Mn,{children:[zA(Po,{color:t,children:Je($B,{rotation:[0,"90deg",0],children:[zA(xH,{size:[A,A,e-.2],roundRadius:.2,center:[-A/2,0,.05]}),zA(Rl,{height:.2/2,radius:A/2-.2,center:[-A/2,0,-e/2+.2/2]})]})}),zA(Po,{color:n,children:zA($B,{rotation:[0,"90deg",0],children:zA(xH,{size:[A*1.01,A*1.01,e/3],roundRadius:.2,center:[-A/2,0,-e/4+.1]})})}),zA(Po,{color:i,children:zA($B,{rotation:[0,"90deg",0],children:zA(pf,{height:.2,radius:A/2,roundRadius:.2/3,center:[-A/2,0,-e/2]})})}),zA(Po,{color:i,children:zA($B,{rotation:[0,"90deg",0],children:zA(pf,{height:.2,radius:A/2,roundRadius:.2/3,center:[-A/2,0,e/2]})})})]}),HSe=({bodyLength:e=3.5,bodyDiameter:A=1.5,color:t="#3a3a3aff",contactColor:i="#c6c6c6"})=>Je(Mn,{children:[zA(Po,{color:t,children:zA($B,{rotation:[0,"90deg",0],children:zA(pf,{height:e,radius:A/2,roundRadius:.3,center:[-A/2,0,0]})})}),zA(Po,{color:i,children:zA($B,{rotation:[0,"90deg",0],children:zA(pf,{height:.5,radius:A/2,roundRadius:.2,center:[-A/2,0,-e/2]})})}),zA(Po,{color:i,children:zA($B,{rotation:[0,"90deg",0],children:zA(pf,{height:.5,radius:A/2,roundRadius:.2,center:[-A/2,0,e/2]})})})]}),YSe=({bodyLength:e=3.9,bodyDiameter:A=2.5,color:t="#3a3a3aff",contactColor:i="#c6c6c6"})=>Je(Mn,{children:[zA(Po,{color:t,children:zA($B,{rotation:[0,"90deg",0],children:zA(pf,{height:e,radius:A/2,roundRadius:.3,center:[-A/2,0,0]})})}),zA(Po,{color:i,children:zA($B,{rotation:[0,"90deg",0],children:zA(pf,{height:.55,radius:A/2,roundRadius:.2,center:[-A/2,0,-e/2]})})}),zA(Po,{color:i,children:zA($B,{rotation:[0,"90deg",0],children:zA(pf,{height:.55,radius:A/2,roundRadius:.2,center:[-A/2,0,e/2]})})})]}),JSe=({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 Je(Mn,{children:[Array.from({length:n}).map((g,c)=>zA(zn,{position:{x:-s/2-A-.3,y:c*i-r,z:a/2},width:t,thickness:a,padContactLength:A,bodyDistance:A+.4,height:.85})),Array.from({length:n}).map((g,c)=>zA(zn,{rotation:Math.PI,position:{x:s/2+A+.3,y:c*i-r,z:a/2},width:t,thickness:a,padContactLength:A,bodyDistance:A+.4,height:.85})),zA(IB,{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})]})},TSe=({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 Je(Mn,{children:[Array.from({length:n}).map((g,c)=>zA(zn,{position:{x:-o/2-A-.3,y:c*i-r,z:a/2},width:t,thickness:a,padContactLength:A,bodyDistance:A+.4,height:.85})),Array.from({length:n}).map((g,c)=>zA(zn,{rotation:Math.PI,position:{x:o/2+A+.3,y:c*i-r,z:a/2},width:t,thickness:a,padContactLength:A,bodyDistance:A+.4,height:.85})),zA(IB,{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})]})},KSe=()=>{const Q=7.050000000000001,h=24.95+6.5/2;return zA(Pi,{center:[0,0,1],children:Je(Mn,{children:[Je($B,{rotation:[0,55,-55],children:[Je(gw,{children:[zA(Qe,{color:"#ccc",size:[6.5+.1,9.9,1.3],center:[h,0,1.3-2]}),zA(Rl,{color:"black",center:[h,0,1.3-2],radius:3/2,height:1.3*1.2})]}),zA(Po,{color:"#222",children:zA(IB,{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($B,{rotation:[0,55,55],children:Array.from({length:3}).map((E,u)=>{const d=Q,p=(u-1)*2.7,m=-.5-.6;return Je(Po,{color:"gold",children:[Je(pc,{children:[zA(Pi,{center:[15.05-4.5/2+.1,p,m],children:zA(Qe,{size:[4.5,.81+1,.5]})}),zA(Pi,{center:[15.05-4.5/2-1+.1,p,m],children:zA(Qe,{size:[4.5,.81,.5]})})]}),zA(Pi,{center:[d,p,m],children:zA(Qe,{size:[16+.1,.81,.5]})})]},`prong-${u}`)})})]})})},PSe=()=>{const g=1.1999999999999997;return Je(Mn,{children:[zA(zn,{rotation:Math.PI,position:{x:2.8/2+g/4,y:-.95,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:g,height:.95}),zA(zn,{rotation:Math.PI,position:{x:2.8/2+g/4,y:0,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:g,height:.95}),zA(zn,{rotation:Math.PI,position:{x:2.8/2+g/4,y:.95,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:g,height:.95}),zA(zn,{position:{x:-2.8/2-g/4,y:0,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:g,height:.95}),zA(zn,{position:{x:-2.8/2-g/4,y:-.95,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:g,height:.95}),zA(zn,{position:{x:-2.8/2-g/4,y:.95,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:g,height:.95}),zA(IB,{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})]})},qSe=()=>Je(Mn,{children:[zA(IB,{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]})})]}),OSe=()=>{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 Je(Pi,{center:[0,1,10.5],children:[zA(Po,{color:s,children:Je(gw,{children:[zA(Pi,{center:[0,0,2.25],children:zA(Rl,{radius:2.4,height:4.5})}),zA(Pi,{center:[0,-1.8499999999999999,2.25],children:zA(Qe,{size:[2.4*2,1.1,4.5+.2]})})]})}),zA(Pi,{center:c,children:zA(Qe,{size:a})}),Je(pc,{children:[zA(Pi,{center:I,children:zA(Qe,{size:g})}),zA(Pi,{center:l,children:zA(Qe,{size:g})})]}),zA(Pi,{center:B,children:zA(Qe,{size:[.43,.4,12.2]})}),zA(Pi,{center:[1.3,0,C],children:zA(Qe,{size:[.43,.4,15]})}),zA(Pi,{center:[-1.3,0,C],children:zA(Qe,{size:[.43,.4,15]})})]})},WSe=()=>Je(Mn,{children:[zA(zn,{rotation:Math.PI,position:{x:2/2+.75/4,y:-.65,z:.15/2},width:.25,thickness:.15,padContactLength:.3,bodyDistance:.75,height:.85}),zA(zn,{rotation:Math.PI,position:{x:2/2+.75/4,y:0,z:.15/2},width:.25,thickness:.15,padContactLength:.3,bodyDistance:.75,height:.85}),zA(zn,{rotation:Math.PI,position:{x:2/2+.75/4,y:.65,z:.15/2},width:.25,thickness:.15,padContactLength:.3,bodyDistance:.75,height:.85}),zA(zn,{position:{x:-2/2-.75/4,y:0,z:.15/2},width:.25,thickness:.15,padContactLength:.3,bodyDistance:.75,height:.85}),zA(zn,{position:{x:-2/2-.75/4,y:-.65,z:.15/2},width:.25,thickness:.15,padContactLength:.3,bodyDistance:.75,height:.85}),zA(zn,{position:{x:-2/2-.75/4,y:.65,z:.15/2},width:.25,thickness:.15,padContactLength:.3,bodyDistance:.75,height:.85}),zA(IB,{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})]}),ZSe=WSe,VSe=()=>Je(Mn,{children:[zA(IB,{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]})})]}),jSe=()=>Je(Mn,{children:[zA(zn,{position:{x:-2.5/2,y:0,z:.175/2},width:.3,thickness:.175,padContactLength:.3,bodyDistance:.45,height:.7}),zA(zn,{rotation:Math.PI,position:{x:2.5/2,y:0,z:.175/2},width:.3,thickness:.175,padContactLength:.3,bodyDistance:.45,height:.7}),zA(Po,{color:"#222",children:zA(IB,{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]})]}),zSe=()=>Je(Mn,{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(Po,{color:"#222",children:Je(vQ,{children:[zA(Pi,{z:.175/2,children:zA(Qe,{size:[1.7,1.25,.175]})}),Je(pc,{children:[zA(Pi,{z:.175,children:zA(Qe,{size:[1.7,1.25,.01]})}),zA(Pi,{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]})]}),XSe=()=>{const s=-1.0474999999999999,r=1.775/2+.4/2-.04;return Je(Mn,{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(Po,{color:"#222",children:zA(IB,{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]})]})},$Se=({pitch:e=10})=>Je(Mn,{children:[zA(Rl,{height:4,radius:.5,center:[-e/2,0,.5]}),zA(PW,{radius:.5,center:[-e/2,0,2.5]}),zA(Pi,{x:-2.5,y:0,z:2.5,children:Je($B,{rotation:[0,Math.PI/2,0],children:[zA(Rl,{height:e,radius:.5,center:[0,0,2.5]}),zA(Po,{color:"#d2b48c",children:zA(Rl,{height:5,radius:1.3,center:[0,0,2.5]})})]})}),zA(Rl,{height:4,radius:.5,center:[e/2,0,.5]}),zA(PW,{radius:.5,center:[e/2,0,2.5]})]}),Abe=({bodyWidth:e=21,boardThickness:A=.5,leadWidth:t=1.6,leadLength:i=2.4,leadsPitch:n=2.54,leadsLeft:o,leadsRight:s,leadsTop:r,leadsBottom:a,innerHoles:g=!0,innerHoleEdgeDistance:c=1.61,innerHoleDiameter:I=1})=>{const l=e/2,B=A/2,C=A*1.05,Q=I/2,h=Math.max(o||0,s||0,r||0,a||0)*n||51,E=[],u=[];if(s){const w=-((s-1)/2)*n;for(let D=0;D<s;D++){const S=w+D*n;E.push({x:-l+i/2,y:-S,pl:i,pw:t}),g&&u.push({x:-l,y:-S},{x:-l+c,y:-S})}}if(o){const w=-((o-1)/2)*n;for(let D=0;D<o;D++){const S=w+D*n;E.push({x:l-i/2,y:-S,pl:i,pw:t}),g&&u.push({x:l,y:-S},{x:l-c,y:-S})}}if(r){const w=-((r-1)/2)*n;for(let D=0;D<r;D++){const S=w+D*n;E.push({x:-S,y:-h/2+i/2,pl:t,pw:i}),g&&u.push({x:-S,y:-h/2},{x:-S,y:-h/2+c})}}if(a){const w=-((a-1)/2)*n;for(let D=0;D<a;D++){const S=w+D*n;E.push({x:-S,y:h/2-i/2,pl:t,pw:i}),g&&u.push({x:-S,y:h/2},{x:-S,y:h/2-c})}}const d=zA(Po,{color:"#008080",children:Je(gw,{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))]})}),p=g&&u.map((w,D)=>zA(Rl,{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 Je(Mn,{children:[d,zA(Po,{color:"#FFD700",children:g?Je(gw,{children:[zA(vQ,{children:E.map((w,D)=>zA(Qe,{center:[w.x,w.y,B],size:[w.pl+.01,w.pw+.01,C]},D))}),p]}):m})]})},tbe=({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,nopin:l})=>{const B=o/2,C=Math.ceil(e/A);let Q,h;a==="left"||a==="right"?(Q=(A-1)*t+2*I,h=(C-1)*t+2*I):(h=(A-1)*t+2*I,Q=(C-1)*t+2*I),e===0&&(Q=10,h=10);const E=Number(s??Q),u=Number(r??h),d=[];let p=0,m=0,w=0,D=0,S=0,k=0;a==="left"||a==="right"?(p=a==="left"?-E/2+I:E/2-I,m=-((C-1)/2)*t,w=0,D=t,S=a==="left"?t:-t,k=0):(p=-((C-1)/2)*t,m=a==="top"?u/2-I:-u/2+I,w=t,D=0,S=0,k=a==="top"?-t:t);let x=0;for(let aA=0;aA<A&&x<e;aA++)for(let tA=0;tA<C&&x<e;tA++){const nA=p+tA*w+aA*S,rA=m+tA*D+aA*k;d.push({x:nA,y:rA}),x++}const N=[];if(g)for(const aA of g){let tA=0,nA=0;aA==="topleft"?(tA=-E/2+c,nA=u/2-c):aA==="topright"?(tA=E/2-c,nA=u/2-c):aA==="bottomleft"?(tA=-E/2+c,nA=-u/2+c):aA==="bottomright"?(tA=E/2-c,nA=-u/2+c):aA==="center"&&(tA=0,nA=0),N.push({x:tA,y:nA})}const M=.63,L=2,Y=6,H=3,O=l?0:L,Z=zA(Po,{color:"#008080",children:Je(gw,{children:[zA(Qe,{center:[0,0,B+O],size:[E,u,o]}),N.map((aA,tA)=>zA(Rl,{center:[aA.x,aA.y,B+O],radius:n/2,height:o},`hole-${tA}`)),d.map((aA,tA)=>zA(Rl,{center:[aA.x,aA.y,B+O],radius:n/2,height:o},`pin-hole-${tA}`))]})}),$=d.map((aA,tA)=>zA(Po,{color:"#FFD700",children:Je(gw,{children:[zA(Rl,{center:[aA.x,aA.y,o/2+O],radius:n/2,height:o}),zA(Rl,{center:[aA.x,aA.y,o/2+O],radius:i/2,height:o})]})})),eA=d.map((aA,tA)=>zA(N6A,{x:aA.x,y:aA.y,pinThickness:M,shortSidePinLength:H,longSidePinLength:Y,bodyHeight:L,flipZ:nA=>nA}));return Je(Mn,{children:[Z,$,!l&&eA]})},ebe=({footprint:e})=>{const A=UDe.string(e).json();switch(A.fn){case"dip":return zA(KDe,{numPins:A.num_pins,pitch:A.p,bodyWidth:A.w});case"axial":return zA($Se,{pitch:A.p});case"tssop":return zA(qDe,{pinCount:A.num_pins,leadLength:A.pl,leadWidth:A.pw,pitch:A.p,bodyWidth:A.w});case"msop":return zA(ODe,{pinCount:A.num_pins,padContactLength:A.pl,leadWidth:A.pw,pitch:A.p,bodyWidth:A.w});case"vssop":return zA(uSe,{pinCount:A.num_pins,leadLength:A.pl,leadWidth:A.pw,pitch:A.p,bodyWidth:A.w,bodyLength:A.h});case"qfp":return zA(jDe,{pinCount:A.num_pins,pitch:A.p,leadWidth:A.pw,padContactLength:A.pl,bodyWidth:A.w});case"tqfp":return zA(GSe,{});case"lqfp":return zA(MSe,{pinCount:A.num_pins});case"qfn":{const n=typeof A.thermalpad?.x=="number"&&typeof A.thermalpad?.y=="number";return zA(nSe,{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(vSe,{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(ASe,{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(QSe,{numberOfPins:A.num_pins,pitch:A.p,rows:o})}case"cap":switch(A.imperial){case"0402":return zA(G6A,{color:"#856c4d"});case"0603":return zA(R6A,{color:"#856c4d"});case"0805":return zA(M6A,{color:"#856c4d"});case"0201":return zA(v6A,{color:"#856c4d"});case"01005":return zA(L6A,{color:"#856c4d"});case"1206":return zA(U6A,{color:"#856c4d"});case"1210":return zA(H6A,{color:"#856c4d"});case"2010":return zA(Y6A,{color:"#856c4d"});case"2512":return zA(J6A,{color:"#856c4d"})}case"sot235":return zA(sSe,{});case"sot457":return zA(PSe,{});case"sot223":return zA(kSe,{});case"sot23w":return zA(rSe,{});case"sot323":return zA(RSe,{});case"sod323f":return zA(zSe,{});case"sod323fl":return zA(XSe,{});case"sot363":return zA(ZSe,{});case"sot886":return zA(VSe,{});case"sot963":return zA(qSe,{});case"pushbutton":return zA(hSe,{width:A.w,length:A.h,innerDiameter:A.id});case"soic":return zA(ESe,{pinCount:A.num_pins,leadLength:A.pl,leadWidth:A.pw,pitch:A.p,bodyWidth:A.w});case"sod523":return zA(dSe,{});case"sod882":return zA(pSe,{});case"sma":return zA(fSe,{});case"smb":return zA(ySe,{});case"smc":return zA(mSe,{});case"smf":return zA(wSe,{});case"sod123f":return zA(DSe,{});case"sod123fl":return zA(SSe,{});case"sod123w":return zA(bSe,{});case"sod128":return zA(xSe,{});case"sod323":return zA(jSe,{});case"sod923":return zA(_Se,{});case"hc49":return zA(LSe,{});case"micromelf":return zA(USe,{});case"minimelf":return zA(HSe,{});case"melf":return zA(YSe,{});case"ms012":return zA(JSe,{pinCount:A.num_pins,padContactLength:A.pl,leadWidth:A.pw,pitch:A.p});case"ms013":return zA(TSe,{pinCount:A.num_pins,padContactLength:A.pl,leadWidth:A.pw,pitch:A.p});case"sot723":return zA(NSe,{});case"to220":return zA(KSe,{});case"to92":return zA(OSe,{});case"stampboard":case"stampreceiver":return zA(Abe,{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(tbe,{numPins:g,rows:n,p:A.p,id:A.id,od:A.od,width:r,height:a,pinRowSide:o,holes:I,holeInset:s,pinRowHoleEdgeToEdgeDist:c,nopin:A.nopin})}}const t=e.match(/_color\(([^)]+)\)/),i=t?t[1]:void 0;switch(A.imperial){case"0402":return zA(G6A,{color:i});case"0603":return zA(R6A,{color:i});case"0805":return zA(M6A,{color:i});case"0201":return zA(v6A,{color:i});case"01005":return zA(L6A,{color:i});case"1206":return zA(U6A,{color:i});case"1210":return zA(H6A,{color:i});case"2010":return zA(Y6A,{color:i});case"2512":return zA(J6A,{color:i})}return null},ibe=e=>e&&typeof e=="object"&&"type"in e,Ev=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},nbe=e=>Array.isArray(e)?[Number(e[0])||0,Number(e[1])||0,Number(e[2])||0]:typeof e=="object"&&e?[Number(e.x)||0,Number(e.y)||0,Number(e.z)||0]:[0,0,0];function yD(e,A,t){const{jscad:{primitives:i,booleans:n,hulls:o,geometries:s,extrusions:r,transforms:a}}=t;if(e==null||e===!1)return[];if(Array.isArray(e))return e.flatMap(l=>yD(l,A,t));if(!ibe(e))return[];const{type:g,props:c,children:I}=e;if(g===_6A)return(I??[]).flatMap(l=>yD(l,A,t));if(g===Po){const l=c?.color;return(I??[]).flatMap(B=>yD(B,l??A,t))}if(g===Pi){const l=nbe(c?.offset??c?.center??{x:c?.x,y:c?.y,z:c?.z});return(I??[]).flatMap(C=>yD(C,A,t)).map(({geom:C,color:Q})=>({geom:a.translate(l,C),color:Q??A}))}if(g===$B){const l=Array.isArray(c?.rotation)?[Ev(c.rotation[0]),Ev(c.rotation[1]),Ev(c.rotation[2])]:[Ev(c?.x??0),Ev(c?.y??0),Ev(c?.z??0)];return(I??[]).flatMap(C=>yD(C,A,t)).map(({geom:C,color:Q})=>({geom:a.rotateZ(l[2],a.rotateY(l[1],a.rotateX(l[0],C))),color:Q}))}if(g===vQ||g===gw||g===pc){const l=(I??[]).flatMap(C=>yD(C,A,t)).map(C=>C.geom);if(l.length===0)return[];let B;return g===vQ?B=n.union(l):g===gw?B=n.subtract(l[0],l.slice(1)):B=o.hull(l),[{geom:B,color:A}]}if(g===_H){const l=c?.points??[];return[{geom:s.geom2.fromPoints(l),color:A??c?.color}]}if(g===kH){const l=(I??[]).flatMap(h=>yD(h,A,t)).map(h=>h.geom);if(l.length===0)return[];const B=l.length>1?n.union(l):l[0],C=c?.height??c?.h??1;let Q=r.extrudeLinear({height:C},B);if(Q.polygons)for(const h of Q.polygons)!h.plane||!h.vertices||h.vertices.length<3||h.vertices.reverse();return[{geom:Q,color:A??c?.color}]}if(g===Qe||g===k6A||g===Rl||g===PW||g===xH||g===pf){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===k6A){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===Rl){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===PW){const B=c?.radius??1,C=c?.center??[0,0,0];l=i.sphere({radius:B,center:C})}else if(g===pf){const B=c?.height??1,C=c?.radius??1,Q=c?.roundRadius??.1,h=c?.center??[0,0,0];l=i.roundedCylinder({height:B,radius:C,roundRadius:Q,center:h})}else{const B=c?.size??[1,1,1],C=c?.roundRadius??.1,Q=c?.center??[0,0,0];l=i.roundedCuboid({size:B,roundRadius:C,center:Q})}return[{geom:l,color:A??c?.color}]}if(typeof g=="function"){const l=g(c??{});return yD(l,A,t)}return(I??[]).flatMap(l=>yD(l,A,t))}function obe(e,A){return{geometries:yD(e,void 0,{jscad:A})}}function T6A(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 bg;if(o.setAttribute("position",new uc(new Float32Array(A),3)),o.setIndex(t),i.length>0&&o.setAttribute("color",new uc(new Float32Array(i),3)),e.transforms){const s=new as;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 bg;if(i.setAttribute("position",new uc(new Float32Array(A),3)),t.length>0&&i.setAttribute("color",new uc(new Float32Array(t),3)),e.transforms){const n=new as;n.fromArray(e.transforms),i.applyMatrix4(n)}return i}return console.error("Invalid CSG object: neither polygons nor sides found"),new bg}function sbe(e,A){const t=QEA(ebe,{footprint:e});return obe(t,A)}var rbe=Kr(vW()),K6A=V.createContext(null),abe=()=>{const e=V.useContext(K6A);if(!e)throw new Error("useHover must be used within a HoverProvider");return e},gbe=({children:e})=>{const{camera:A,renderer:t}=Ou(),[i,n]=V.useState([]),o=V.useMemo(()=>new Jre,[]),s=V.useMemo(()=>new In,[]),r=V.useRef(i);r.current=i;const a=V.useRef(null),g=V.useCallback(C=>{n(Q=>[...Q,C])},[]),c=V.useCallback(C=>{if(a.current){let Q=!1,h=a.current.object;for(;h;){if(h===C){Q=!0;break}h=h.parent}Q&&(a.current.onUnhover(),a.current=null)}n(Q=>Q.filter(h=>h.object!==C))},[]),I=V.useCallback(C=>{let Q=C;for(;Q;){const h=r.current.find(E=>E.object===Q);if(h)return h;Q=Q.parent}},[]),l=V.useCallback(C=>{if(!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 p={mousePosition:[u.point.x,u.point.y,u.point.z]};a.current!==d?(a.current?.onUnhover(),d.onHover(p),a.current=d):d.onHover(p)}else a.current&&(a.current.onUnhover(),a.current=null)}else a.current&&(a.current.onUnhover(),a.current=null)},[A,t,o,s,I]);V.useEffect(()=>{const C=t.domElement;return C.addEventListener("mousemove",l),()=>{C.removeEventListener("mousemove",l)}},[t,l]);const B=V.useMemo(()=>({addHoverable:g,removeHoverable:c}),[g,c]);return W.jsx(K6A.Provider,{value:B,children:e})},cbe=({children:e,object:A,onHover:t,onUnhover:i,isHovered:n})=>{const{addHoverable:o,removeHoverable:s}=abe();return V.useEffect(()=>A?(o({object:A,onHover:t,onUnhover:i}),()=>{s(A)}):void 0,[A,t,i,o,s]),W.jsx(W.Fragment,{children:e})},HH=cbe,Ibe=({positionOffset:e,footprint:A,rotationOffset:t,onHover:i,onUnhover:n,isHovered:o,scale:s,isTranslucent:r=!1})=>{const{rootObject:a}=Ou(),g=V.useMemo(()=>{if(!A)return null;const{geometries:c}=sbe(A,rbe),I=new df;for(const l of c.flat(1/0)){const B=l.geom;if(!B||!B.polygons&&!B.sides)continue;const C=new Ki(l.color);C.convertLinearToSRGB();const Q={...B,color:[C.r,C.g,C.b]},h=T6A(Q),E=new ME({vertexColors:!0,side:zB,transparent:r,opacity:r?.5:1,depthWrite:!r}),u=new io(h,E);I.add(u)}return I},[A,r]);return V.useEffect(()=>{if(!(!g||!a))return a.add(g),()=>{a.remove(g)}},[a,g]),V.useEffect(()=>{g&&(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]),V.useEffect(()=>{g&&g.traverse(c=>{c instanceof io&&c.material instanceof ME&&(o?(c.material.emissive.setHex(255),c.material.emissiveIntensity=.2):c.material.emissiveIntensity=0)})},[o,g]),g?W.jsx(HH,{isHovered:o,onHover:i,onUnhover:n,object:g}):null},P6A=new WeakMap,lbe=()=>{const e=new jI;return e.name="fallback-environment-map",e.mapping=O5,e},Bbe=e=>{if(!e)return null;const A=e,t=P6A.get(A);if(t)return t;let i;if(e instanceof w8){const n=new yrA(e);i=n.fromScene(Iae(),.04).texture,n.dispose()}else i=lbe();return P6A.set(A,i),i},q6A=1.25;function O6A({gltfUrl:e,position:A,rotation:t,onHover:i,onUnhover:n,isHovered:o,scale:s,isTranslucent:r=!1}){const{renderer:a,rootObject:g}=Ou(),[c,I]=V.useState(null),[l,B]=V.useState(null);if(V.useEffect(()=>{if(!e)return;const C=new Bae;let Q=!0;return C.load(e,h=>{if(!Q)return;const E=h.scene;E.traverse(u=>{if(u instanceof io&&u.material){const d=p=>{p.transparent=r,p.opacity=r?.5:1,p.depthWrite=!r,p.needsUpdate=!0};Array.isArray(u.material)?u.material.forEach(d):d(u.material)}}),I(E)},void 0,h=>{if(!Q)return;console.error(`An error happened loading ${e}`,h);const E=h instanceof Error?h:new Error(`Failed to load glTF model from ${e}`);B(E)}),()=>{Q=!1}},[e,r]),V.useEffect(()=>{c&&(A&&c.position.fromArray(A),t&&c.rotation.fromArray(t),s!==void 0&&c.scale.setScalar(s))},[c,A?.[0],A?.[1],A?.[2],t?.[0],t?.[1],t?.[2],s]),V.useEffect(()=>{if(!(!g||!c))return g.add(c),()=>{g.remove(c)}},[g,c]),V.useEffect(()=>{if(!c||!a)return;const C=Bbe(a);if(!C)return;const Q=[],h=E=>{E instanceof ME&&(Q.push({material:E,envMap:E.envMap??null,envMapIntensity:E.envMapIntensity??1}),E.envMap=C,(typeof E.envMapIntensity!="number"||E.envMapIntensity<q6A)&&(E.envMapIntensity=q6A),E.needsUpdate=!0)};return c.traverse(E=>{if(!(E instanceof io))return;const u=E.material;Array.isArray(u)?u.forEach(h):u&&h(u)}),()=>{Q.forEach(({material:E,envMap:u,envMapIntensity:d})=>{E.envMap=u,E.envMapIntensity=d,E.needsUpdate=!0})}},[c,a]),V.useEffect(()=>{c&&c.traverse(C=>{C instanceof io&&C.material instanceof ME&&(o?(C.material.emissive.setHex(255),C.material.emissiveIntensity=.2):C.material.emissiveIntensity=0)})},[o,c]),l)throw l;return c?W.jsx(HH,{isHovered:o,onHover:i,onUnhover:n,object:c}):null}var Cbe=Kr(zXA()),Qbe=Kr(vW()),hbe=({jscadPlan:e,positionOffset:A,rotationOffset:t,onHover:i,onUnhover:n,isHovered:o,scale:s,isTranslucent:r=!1})=>{const{rootObject:a}=Ou(),{threeGeom:g,material:c}=V.useMemo(()=>{const l=(0,Cbe.executeJscadOperations)(Qbe.default,e);if(!l||!l.polygons&&!l.sides)return{threeGeom:null,material:null};const B=T6A(l),C=new ME({vertexColors:!0,side:zB,transparent:r,opacity:r?.5:1,depthWrite:!r});return{threeGeom:B,material:C}},[e,r]),I=V.useMemo(()=>g?new io(g,c):null,[g,c]);return V.useEffect(()=>{if(!(!I||!a))return a.add(I),()=>{a.remove(I)}},[a,I]),V.useEffect(()=>{I&&(A&&I.position.fromArray(A),t&&I.rotation.fromArray(t),s!==void 0&&I.scale.setScalar(s))},[I,A?.[0],A?.[1],A?.[2],t?.[0],t?.[1],t?.[2],s]),V.useMemo(()=>{if(c)if(o){const l=new Ki(c.color.getHex());c.emissive.copy(l),c.emissive.setRGB(0,0,1),c.emissiveIntensity=.2}else c.emissiveIntensity=0},[o,c]),g?W.jsx(HH,{isHovered:o,onHover:i,onUnhover:n,object:I}):null};function Ebe(e){return e.replace(/(DEF|USE)\s+([^\s]+)/g,(A,t,i)=>`${t} ${i.replace(/-/g,"_")}`)}async function ube(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 Xae().parse(Ebe(t),e)}typeof window<"u"&&!window.TSCIRCUIT_OBJ_LOADER_CACHE&&(window.TSCIRCUIT_OBJ_LOADER_CACHE=new Map);function dbe(e){const[A,t]=V.useState(null);return V.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 ube(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 rge;if(c?.length){const l=c.join(`
5138
- `).replace(/d 0\./g,"d 1."),B=g.replace(/newmtl[\s\S]*?endmtl/g,"").replace(/^mtllib.*/gm,""),C=new Vae;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 pbe({url:e,position:A,rotation:t,onHover:i,onUnhover:n,isHovered:o,scale:s,isTranslucent:r=!1}){const a=dbe(e),{rootObject:g}=Ou(),c=V.useMemo(()=>a&&!(a instanceof Error)?(a.traverse(I=>{if(I instanceof io&&I.material){const l=B=>{B.transparent=r,B.opacity=r?.5:1,B.depthWrite=!r,B.needsUpdate=!0};Array.isArray(I.material)?I.material.forEach(l):l(I.material)}}),a):new io(new ow(.5,.5,.5),new ME({transparent:!0,color:"red",opacity:.25})),[a,r]);if(V.useEffect(()=>{if(!(!g||!c))return g.add(c),()=>{g.remove(c)}},[g,c]),V.useEffect(()=>{c&&(A&&(Array.isArray(A)?c.position.fromArray(A):c.position.copy(A)),t&&(Array.isArray(t)?c.rotation.fromArray(t):c.rotation.copy(t)),s!==void 0&&c.scale.setScalar(s))},[c,Array.isArray(A)?A[0]:A?.x,Array.isArray(A)?A[1]:A?.y,Array.isArray(A)?A[2]:A?.z,Array.isArray(t)?t[0]:t?.x,Array.isArray(t)?t[1]:t?.y,Array.isArray(t)?t[2]:t?.z,s]),a instanceof Error)throw a;return W.jsx(HH,{isHovered:o,onHover:i,onUnhover:n,object:c})}var NEA,fbe="https://cdn.jsdelivr.net/npm/occt-import-js@0.0.23/dist";function ybe(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 mbe(){if(!NEA){const e=await import("https://cdn.jsdelivr.net/npm/occt-import-js@0.0.23/+esm");NEA=ybe(e)({locateFile:t=>`${fbe}/${t}`})}return NEA}function wbe(e){const A=new df;for(const t of e){const i=t.attributes.position?.array??[],n=t.index?.array??[];if(!i.length||!n.length)continue;const o=new bg;o.setAttribute("position",new Ko(i,3));const s=t.attributes.normal?.array??[];s.length?o.setAttribute("normal",new Ko(s,3)):o.computeVertexNormals(),o.setIndex(n);const r=new ME({color:t.color?new Ki(t.color[0],t.color[1],t.color[2]):new Ki(.82,.82,.82)}),a=new io(o,r);a.name=t.name,A.add(a)}return A}async function Dbe(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 mbe()).ReadStepFile(new Uint8Array(t),null);if(!n.success||!n.meshes.length)throw new Error("occt-import-js failed to convert STEP file");const o=wbe(n.meshes),s=new $rA;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 W6A="step-glb-cache:";function Sbe(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 bbe(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 xbe(e){try{const A=localStorage.getItem(`${W6A}${e}`);return A?bbe(A):null}catch(A){return console.warn("Failed to read STEP GLB cache",A),null}}function Z6A(e,A){try{const t=Sbe(A);localStorage.setItem(`${W6A}${e}`,t)}catch(t){console.warn("Failed to write STEP GLB cache",t)}}function _be(){const e=globalThis;return e.stepUrlToGltfModelConversions||(e.stepUrlToGltfModelConversions={inProgress:new Map,completed:new Map}),e.stepUrlToGltfModelConversions}var kbe=({stepUrl:e,position:A,rotation:t,scale:i,onHover:n,onUnhover:o,isHovered:s,isTranslucent:r})=>{const[a,g]=V.useState(null);return V.useEffect(()=>{let c=!0,I=null,l=!0;const B=_be(),C=xbe(e);if(C){const E={arrayBuffer:C,blobUrl:URL.createObjectURL(new Blob([C],{type:"model/gltf-binary"}))};return B.completed.set(e,E),I=E.blobUrl,l=!1,g(E.blobUrl),()=>{c=!1,I&&l&&URL.revokeObjectURL(I)}}const Q=B.completed.get(e);if(Q)return I=Q.blobUrl,l=!1,g(Q.blobUrl),Z6A(e,Q.arrayBuffer),()=>{c=!1,I&&l&&URL.revokeObjectURL(I)};let h=B.inProgress.get(e);return h||(h=Dbe(e).then(E=>{const u={arrayBuffer:E,blobUrl:URL.createObjectURL(new Blob([E],{type:"model/gltf-binary"}))};return B.completed.set(e,u),B.inProgress.delete(e),u}).catch(E=>{throw B.inProgress.delete(e),E}),B.inProgress.set(e,h)),h.then(E=>{c&&(I=E.blobUrl,l=!1,g(E.blobUrl),Z6A(e,E.arrayBuffer))}).catch(E=>{console.error("Failed to convert STEP file to GLB",E),c&&g(null)}),()=>{c=!1,I&&l&&URL.revokeObjectURL(I)}},[e]),a?W.jsx(O6A,{gltfUrl:a,position:A,rotation:t,scale:i,onHover:n,onUnhover:o,isHovered:s,isTranslucent:r}):null},Fbe=(e,A)=>{if(e)return A?A(e):e},V6A=(...e)=>e,j6A=({cad_component:e,circuitJson:A,resolveStaticAsset:t})=>{const i=A6A(A),[n,o]=V.useState(!1),{visibility:s}=ov(),[r,a]=V.useState(null),g=V.useCallback(w=>{w?.mousePosition?(o(!0),a(w.mousePosition)):(o(!1),a(null))},[]),c=V.useCallback(()=>{o(!1),a(null)},[]),I=V.useMemo(()=>Di(A).source_component.getUsing({source_component_id:e.source_component_id})?.name,[A,e.source_component_id]),l=V.useMemo(()=>A.filter(D=>D.type==="pcb_plated_hole"&&D.pcb_component_id===e.pcb_component_id).length>0,[A,e.pcb_component_id]),B=V.useCallback(w=>Fbe(w,t),[t]),C=B(e.model_obj_url??e.model_wrl_url??e.model_stl_url),Q=B(e.model_glb_url??e.model_gltf_url),h=B(e.model_step_url),u=A.find(w=>w.type==="pcb_component"&&w.source_component_id===e.source_component_id)?.layer??"top",d=V.useMemo(()=>e.rotation?V6A(e.rotation.x*Math.PI/180,e.rotation.y*Math.PI/180,e.rotation.z*Math.PI/180):V6A(0,0,0),[e.rotation,u]),p=V.useMemo(()=>{if(!e.position)return;let w;return u==="top"?w=i/2:u==="bottom"?w=-(i/2):w=e.position.z,[e.position.x,e.position.y,w]},[e.position,u,i]);let m=null;if(C?m=W.jsx(pbe,{url:C,position:p,rotation:d,scale:e.model_unit_to_mm_scale_factor,onHover:g,onUnhover:c,isHovered:n,isTranslucent:e.show_as_translucent_model},e.cad_component_id):Q?m=W.jsx(O6A,{gltfUrl:Q,position:p,rotation:d,scale:e.model_unit_to_mm_scale_factor,onHover:g,onUnhover:c,isHovered:n,isTranslucent:e.show_as_translucent_model},e.cad_component_id):h&&!e.model_jscad&&!e.footprinter_string?m=W.jsx(kbe,{stepUrl:h,position:p,rotation:d,scale:e.model_unit_to_mm_scale_factor,onHover:g,onUnhover:c,isHovered:n,isTranslucent:e.show_as_translucent_model}):e.model_jscad?m=W.jsx(hbe,{jscadPlan:e.model_jscad,positionOffset:p,rotationOffset:d,scale:e.model_unit_to_mm_scale_factor,onHover:g,onUnhover:c,isHovered:n,isTranslucent:e.show_as_translucent_model},e.cad_component_id):e.footprinter_string&&(m=W.jsx(Ibe,{positionOffset:p,rotationOffset:d,footprint:e.footprinter_string,scale:e.model_unit_to_mm_scale_factor,onHover:g,onUnhover:c,isHovered:n,isTranslucent:e.show_as_translucent_model})),e.show_as_translucent_model){if(!s.translucentModels)return null}else if(l&&!s.throughHoleModels||!l&&!s.smtModels)return null;return W.jsxs(W.Fragment,{children:[m,n&&r?W.jsx(e6A,{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]})},z6A={version:"0.0.510"};function Gbe(e){e.querySelectorAll("canvas").forEach(A=>A.remove())}var Rbe=e=>{e.outputColorSpace=jm,e.toneMapping=UKA,e.toneMappingExposure=1},X6A="cadViewerCameraStateSession",$6A=(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(X6A,JSON.stringify(t))}catch(t){console.warn("Failed to save camera:",t)}},vEA=(e,A)=>{try{const t=sessionStorage.getItem(X6A);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}},A7A=V.createContext(void 0),Mbe=({children:e,defaultTarget:A,initialCameraPosition:t})=>{const i=V.useRef(null),n=V.useRef(null),[o,s]=V.useState(null),[r,a]=V.useState("perspective"),[g,c]=V.useState(t??null),[I,l]=V.useState(new Ef(0,0,0)),B=V.useMemo(()=>{const[E,u,d]=t??[5,-5,5],p=Math.hypot(E-A.x,u-A.y,d-A.z);return p>0?p:5},[t,A]),C=V.useCallback(E=>{const u=[A.x,A.y,A.z],d=n.current,p=i.current;let m=B;switch(d&&p&&(m=d.position.distanceTo(p.target)),E){case"Top Center Angled":{const 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=V.useCallback(E=>{i.current=E},[]),h=V.useMemo(()=>({controlsRef:i,mainCameraRef:n,defaultTarget:A,baseDistance:B,controller:o,setController:s,getPresetConfig:C,handleControlsChange:Q,cameraType:r,setCameraType:a,cameraPosition:g,setCameraPosition:c,cameraRotation:I,setCameraRotation:l,saveCameraToSession:$6A,loadCameraFromSession:vEA}),[A,B,o,C,Q,r,g,I]);return W.jsx(A7A.Provider,{value:h,children:e})},S_=()=>{const e=V.useContext(A7A);if(!e)throw new Error("useCameraController must be used within a CameraControllerProvider");return e},Nbe=V.forwardRef(({children:e,scene:A,camera:t,style:i,onCreated:n},o)=>{const{cameraType:s}=S_(),r=V.useRef(null),[a,g]=V.useState(null),c=V.useRef([]),I=V.useRef(void 0);I.current=n;const l=V.useRef(null),B=V.useCallback(E=>{c.current.push(E)},[]),C=V.useCallback(E=>{c.current=c.current.filter(u=>u!==E)},[]),Q=V.useMemo(()=>new KF,[]);A?.up&&Q.up.set(A.up.x,A.up.y,A.up.z);const h=V.useRef(new Sg);return V.useImperativeHandle(o,()=>h.current),V.useEffect(()=>{if(!r.current)return;Gbe(r.current);const E=new w8({antialias:!0,alpha:!0});Rbe(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 kh(75,u,.1,1e3):new vU(-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 p;const m=new Fre,w=()=>{const S=m.getElapsedTime(),k=m.getDelta();c.current.forEach(x=>x(S,k)),E.render(Q,d),p=requestAnimationFrame(w)};w();const D=()=>{if(r.current){const S=r.current.clientWidth/r.current.clientHeight;d instanceof kh?d.aspect=S:d instanceof vU&&(d.left=-10*S,d.right=10*S,d.top=10,d.bottom=-10),d.updateProjectionMatrix(),E.setSize(r.current.clientWidth,r.current.clientHeight)}};return window.addEventListener("resize",D),()=>{l.current={position:d.position.clone(),quaternion:d.quaternion.clone(),up:d.up.clone()},window.removeEventListener("resize",D),cancelAnimationFrame(p),r.current&&E.domElement&&r.current.removeChild(E.domElement),E.dispose(),Q.remove(h.current),window.__TSCIRCUIT_THREE_OBJECT===h.current&&(window.__TSCIRCUIT_THREE_OBJECT=void 0)}},[Q,B,C,s]),W.jsx("div",{ref:r,style:{width:"100%",height:"100%",...i},children:a&&W.jsx(t6A.Provider,{value:a,children:W.jsx(gbe,{children:e})})})}),vbe=({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}=Ou(),l=V.useMemo(()=>!c||!I?null:new gge(c,I.domElement),[c,I]);return V.useEffect(()=>(g?.(l??null),()=>g?.(null)),[l,g]),V.useEffect(()=>{if(!l)return;const B=()=>{g?.(l)};return l.addEventListener("change",B),()=>{l.removeEventListener("change",B)}},[l,g]),V.useEffect(()=>{l&&(l.autoRotate=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:e_.ROTATE,MIDDLE:e_.PAN,RIGHT:null},a&&(l.target.set(a[0],a[1],a[2]),l.update()))},[l,e,A,i,n,o,s,r,a]),V.useEffect(()=>{if(!(!l||!t))return l.addEventListener("start",t),()=>{l.removeEventListener("start",t)}},[l,t]),V.useEffect(()=>{if(l)return()=>{l.dispose()}},[l]),DH(()=>{l?.update()},[l]),null},Lbe=`
5138
+ `).replace(/d 0\./g,"d 1."),B=g.replace(/newmtl[\s\S]*?endmtl/g,"").replace(/^mtllib.*/gm,""),C=new Vae;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 pbe({url:e,position:A,rotation:t,onHover:i,onUnhover:n,isHovered:o,scale:s,isTranslucent:r=!1}){const a=dbe(e),{rootObject:g}=Ou(),c=V.useMemo(()=>a&&!(a instanceof Error)?(a.traverse(I=>{if(I instanceof io&&I.material){const l=B=>{B.transparent=r,B.opacity=r?.5:1,B.depthWrite=!r,B.needsUpdate=!0};Array.isArray(I.material)?I.material.forEach(l):l(I.material)}}),a):new io(new ow(.5,.5,.5),new ME({transparent:!0,color:"red",opacity:.25})),[a,r]);if(V.useEffect(()=>{if(!(!g||!c))return g.add(c),()=>{g.remove(c)}},[g,c]),V.useEffect(()=>{c&&(A&&(Array.isArray(A)?c.position.fromArray(A):c.position.copy(A)),t&&(Array.isArray(t)?c.rotation.fromArray(t):c.rotation.copy(t)),s!==void 0&&c.scale.setScalar(s))},[c,Array.isArray(A)?A[0]:A?.x,Array.isArray(A)?A[1]:A?.y,Array.isArray(A)?A[2]:A?.z,Array.isArray(t)?t[0]:t?.x,Array.isArray(t)?t[1]:t?.y,Array.isArray(t)?t[2]:t?.z,s]),a instanceof Error)throw a;return W.jsx(HH,{isHovered:o,onHover:i,onUnhover:n,object:c})}var NEA,fbe="https://cdn.jsdelivr.net/npm/occt-import-js@0.0.23/dist";function ybe(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 mbe(){if(!NEA){const e=await import("https://cdn.jsdelivr.net/npm/occt-import-js@0.0.23/+esm");NEA=ybe(e)({locateFile:t=>`${fbe}/${t}`})}return NEA}function wbe(e){const A=new df;for(const t of e){const i=t.attributes.position?.array??[],n=t.index?.array??[];if(!i.length||!n.length)continue;const o=new bg;o.setAttribute("position",new Ko(i,3));const s=t.attributes.normal?.array??[];s.length?o.setAttribute("normal",new Ko(s,3)):o.computeVertexNormals(),o.setIndex(n);const r=new ME({color:t.color?new Ki(t.color[0],t.color[1],t.color[2]):new Ki(.82,.82,.82)}),a=new io(o,r);a.name=t.name,A.add(a)}return A}async function Dbe(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 mbe()).ReadStepFile(new Uint8Array(t),null);if(!n.success||!n.meshes.length)throw new Error("occt-import-js failed to convert STEP file");const o=wbe(n.meshes),s=new $rA;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 W6A="step-glb-cache:";function Sbe(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 bbe(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 xbe(e){try{const A=localStorage.getItem(`${W6A}${e}`);return A?bbe(A):null}catch(A){return console.warn("Failed to read STEP GLB cache",A),null}}function Z6A(e,A){try{const t=Sbe(A);localStorage.setItem(`${W6A}${e}`,t)}catch(t){console.warn("Failed to write STEP GLB cache",t)}}function _be(){const e=globalThis;return e.stepUrlToGltfModelConversions||(e.stepUrlToGltfModelConversions={inProgress:new Map,completed:new Map}),e.stepUrlToGltfModelConversions}var kbe=({stepUrl:e,position:A,rotation:t,scale:i,onHover:n,onUnhover:o,isHovered:s,isTranslucent:r})=>{const[a,g]=V.useState(null);return V.useEffect(()=>{let c=!0,I=null,l=!0;const B=_be(),C=xbe(e);if(C){const E={arrayBuffer:C,blobUrl:URL.createObjectURL(new Blob([C],{type:"model/gltf-binary"}))};return B.completed.set(e,E),I=E.blobUrl,l=!1,g(E.blobUrl),()=>{c=!1,I&&l&&URL.revokeObjectURL(I)}}const Q=B.completed.get(e);if(Q)return I=Q.blobUrl,l=!1,g(Q.blobUrl),Z6A(e,Q.arrayBuffer),()=>{c=!1,I&&l&&URL.revokeObjectURL(I)};let h=B.inProgress.get(e);return h||(h=Dbe(e).then(E=>{const u={arrayBuffer:E,blobUrl:URL.createObjectURL(new Blob([E],{type:"model/gltf-binary"}))};return B.completed.set(e,u),B.inProgress.delete(e),u}).catch(E=>{throw B.inProgress.delete(e),E}),B.inProgress.set(e,h)),h.then(E=>{c&&(I=E.blobUrl,l=!1,g(E.blobUrl),Z6A(e,E.arrayBuffer))}).catch(E=>{console.error("Failed to convert STEP file to GLB",E),c&&g(null)}),()=>{c=!1,I&&l&&URL.revokeObjectURL(I)}},[e]),a?W.jsx(O6A,{gltfUrl:a,position:A,rotation:t,scale:i,onHover:n,onUnhover:o,isHovered:s,isTranslucent:r}):null},Fbe=(e,A)=>{if(e)return A?A(e):e},V6A=(...e)=>e,j6A=({cad_component:e,circuitJson:A,resolveStaticAsset:t})=>{const i=A6A(A),[n,o]=V.useState(!1),{visibility:s}=ov(),[r,a]=V.useState(null),g=V.useCallback(w=>{w?.mousePosition?(o(!0),a(w.mousePosition)):(o(!1),a(null))},[]),c=V.useCallback(()=>{o(!1),a(null)},[]),I=V.useMemo(()=>Di(A).source_component.getUsing({source_component_id:e.source_component_id})?.name,[A,e.source_component_id]),l=V.useMemo(()=>A.filter(D=>D.type==="pcb_plated_hole"&&D.pcb_component_id===e.pcb_component_id).length>0,[A,e.pcb_component_id]),B=V.useCallback(w=>Fbe(w,t),[t]),C=B(e.model_obj_url??e.model_wrl_url??e.model_stl_url),Q=B(e.model_glb_url??e.model_gltf_url),h=B(e.model_step_url),u=A.find(w=>w.type==="pcb_component"&&w.source_component_id===e.source_component_id)?.layer??"top",d=V.useMemo(()=>e.rotation?V6A(e.rotation.x*Math.PI/180,e.rotation.y*Math.PI/180,e.rotation.z*Math.PI/180):V6A(0,0,0),[e.rotation,u]),p=V.useMemo(()=>{if(!e.position)return;let w;return u==="top"?w=e.position.z:u==="bottom"?w=-(e.position.z+i):w=e.position.z,[e.position.x,e.position.y,w]},[e.position,u,i]);let m=null;if(C?m=W.jsx(pbe,{url:C,position:p,rotation:d,scale:e.model_unit_to_mm_scale_factor,onHover:g,onUnhover:c,isHovered:n,isTranslucent:e.show_as_translucent_model},e.cad_component_id):Q?m=W.jsx(O6A,{gltfUrl:Q,position:p,rotation:d,scale:e.model_unit_to_mm_scale_factor,onHover:g,onUnhover:c,isHovered:n,isTranslucent:e.show_as_translucent_model},e.cad_component_id):h&&!e.model_jscad&&!e.footprinter_string?m=W.jsx(kbe,{stepUrl:h,position:p,rotation:d,scale:e.model_unit_to_mm_scale_factor,onHover:g,onUnhover:c,isHovered:n,isTranslucent:e.show_as_translucent_model}):e.model_jscad?m=W.jsx(hbe,{jscadPlan:e.model_jscad,positionOffset:p,rotationOffset:d,scale:e.model_unit_to_mm_scale_factor,onHover:g,onUnhover:c,isHovered:n,isTranslucent:e.show_as_translucent_model},e.cad_component_id):e.footprinter_string&&(m=W.jsx(Ibe,{positionOffset:p,rotationOffset:d,footprint:e.footprinter_string,scale:e.model_unit_to_mm_scale_factor,onHover:g,onUnhover:c,isHovered:n,isTranslucent:e.show_as_translucent_model})),e.show_as_translucent_model){if(!s.translucentModels)return null}else if(l&&!s.throughHoleModels||!l&&!s.smtModels)return null;return W.jsxs(W.Fragment,{children:[m,n&&r?W.jsx(e6A,{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]})},z6A={version:"0.0.511"};function Gbe(e){e.querySelectorAll("canvas").forEach(A=>A.remove())}var Rbe=e=>{e.outputColorSpace=jm,e.toneMapping=UKA,e.toneMappingExposure=1},X6A="cadViewerCameraStateSession",$6A=(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(X6A,JSON.stringify(t))}catch(t){console.warn("Failed to save camera:",t)}},vEA=(e,A)=>{try{const t=sessionStorage.getItem(X6A);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}},A7A=V.createContext(void 0),Mbe=({children:e,defaultTarget:A,initialCameraPosition:t})=>{const i=V.useRef(null),n=V.useRef(null),[o,s]=V.useState(null),[r,a]=V.useState("perspective"),[g,c]=V.useState(t??null),[I,l]=V.useState(new Ef(0,0,0)),B=V.useMemo(()=>{const[E,u,d]=t??[5,-5,5],p=Math.hypot(E-A.x,u-A.y,d-A.z);return p>0?p:5},[t,A]),C=V.useCallback(E=>{const u=[A.x,A.y,A.z],d=n.current,p=i.current;let m=B;switch(d&&p&&(m=d.position.distanceTo(p.target)),E){case"Top Center Angled":{const 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=V.useCallback(E=>{i.current=E},[]),h=V.useMemo(()=>({controlsRef:i,mainCameraRef:n,defaultTarget:A,baseDistance:B,controller:o,setController:s,getPresetConfig:C,handleControlsChange:Q,cameraType:r,setCameraType:a,cameraPosition:g,setCameraPosition:c,cameraRotation:I,setCameraRotation:l,saveCameraToSession:$6A,loadCameraFromSession:vEA}),[A,B,o,C,Q,r,g,I]);return W.jsx(A7A.Provider,{value:h,children:e})},S_=()=>{const e=V.useContext(A7A);if(!e)throw new Error("useCameraController must be used within a CameraControllerProvider");return e},Nbe=V.forwardRef(({children:e,scene:A,camera:t,style:i,onCreated:n},o)=>{const{cameraType:s}=S_(),r=V.useRef(null),[a,g]=V.useState(null),c=V.useRef([]),I=V.useRef(void 0);I.current=n;const l=V.useRef(null),B=V.useCallback(E=>{c.current.push(E)},[]),C=V.useCallback(E=>{c.current=c.current.filter(u=>u!==E)},[]),Q=V.useMemo(()=>new KF,[]);A?.up&&Q.up.set(A.up.x,A.up.y,A.up.z);const h=V.useRef(new Sg);return V.useImperativeHandle(o,()=>h.current),V.useEffect(()=>{if(!r.current)return;Gbe(r.current);const E=new w8({antialias:!0,alpha:!0});Rbe(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 kh(75,u,.1,1e3):new vU(-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 p;const m=new Fre,w=()=>{const S=m.getElapsedTime(),k=m.getDelta();c.current.forEach(x=>x(S,k)),E.render(Q,d),p=requestAnimationFrame(w)};w();const D=()=>{if(r.current){const S=r.current.clientWidth/r.current.clientHeight;d instanceof kh?d.aspect=S:d instanceof vU&&(d.left=-10*S,d.right=10*S,d.top=10,d.bottom=-10),d.updateProjectionMatrix(),E.setSize(r.current.clientWidth,r.current.clientHeight)}};return window.addEventListener("resize",D),()=>{l.current={position:d.position.clone(),quaternion:d.quaternion.clone(),up:d.up.clone()},window.removeEventListener("resize",D),cancelAnimationFrame(p),r.current&&E.domElement&&r.current.removeChild(E.domElement),E.dispose(),Q.remove(h.current),window.__TSCIRCUIT_THREE_OBJECT===h.current&&(window.__TSCIRCUIT_THREE_OBJECT=void 0)}},[Q,B,C,s]),W.jsx("div",{ref:r,style:{width:"100%",height:"100%",...i},children:a&&W.jsx(t6A.Provider,{value:a,children:W.jsx(gbe,{children:e})})})}),vbe=({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}=Ou(),l=V.useMemo(()=>!c||!I?null:new gge(c,I.domElement),[c,I]);return V.useEffect(()=>(g?.(l??null),()=>g?.(null)),[l,g]),V.useEffect(()=>{if(!l)return;const B=()=>{g?.(l)};return l.addEventListener("change",B),()=>{l.removeEventListener("change",B)}},[l,g]),V.useEffect(()=>{l&&(l.autoRotate=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:e_.ROTATE,MIDDLE:e_.PAN,RIGHT:null},a&&(l.target.set(a[0],a[1],a[2]),l.update()))},[l,e,A,i,n,o,s,r,a]),V.useEffect(()=>{if(!(!l||!t))return l.addEventListener("start",t),()=>{l.removeEventListener("start",t)}},[l,t]),V.useEffect(()=>{if(l)return()=>{l.dispose()}},[l]),DH(()=>{l?.update()},[l]),null},Lbe=`
5139
5139
  varying vec3 worldPosition;
5140
5140
  void main() {
5141
5141
  worldPosition = (modelMatrix * vec4(position, 1.0)).xyz;
@@ -5686,7 +5686,7 @@ test("${g} should solve problem correctly", () => {
5686
5686
  // Add more specific assertions based on expected output
5687
5687
  // expect(solver.netLabelPlacementSolver!.netLabelPlacements).toMatchInlineSnapshot()
5688
5688
  })
5689
- `,I=new Blob([c],{type:"text/plain"}),l=URL.createObjectURL(I),B=document.createElement("a");B.href=l,B.download=`${g}.test.ts`,B.click(),URL.revokeObjectURL(l)}catch(a){alert(`Error generating test.ts for ${e.constructor.name}: ${a instanceof Error?a.message:String(a)}`)}i(!1)};return W.jsxs("div",{className:`relative ${A}`,ref:n,children:[W.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>i(!t),title:`Download options for ${e.constructor.name}`,children:e.constructor.name}),t&&W.jsxs("div",{className:"absolute top-full left-0 mt-1 bg-white border border-gray-300 rounded shadow-lg z-10 min-w-[150px]",children:[W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:o,children:"Download JSON"}),W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:r,children:"Download test.ts"})]})]})},lIt=e=>e.activeSubSolver?[e,...lIt(e.activeSubSolver)]:[e],c9e=({solver:e})=>{const A=lIt(e);return W.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:A.map((t,i)=>W.jsxs("div",{className:"flex items-center",children:[i>0&&W.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),W.jsx(g9e,{solver:t})]},t.constructor.name))})},I9e=({solver:e,triggerRender:A,animationSpeed:t=25,onSolverStarted:i,onSolverCompleted:n})=>{const[o,s]=V.useReducer(Q=>!Q,!1),r=V.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)};V.useEffect(()=>()=>{r.current&&clearInterval(r.current)},[]),V.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 W.jsxs("div",{className:"space-y-2 p-2 border-b",children:[W.jsx("div",{className:"flex items-center",children:W.jsx(c9e,{solver:e})}),W.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[W.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"}),W.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"}),W.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"}),W.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&&W.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"}),W.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",e.iterations]}),e.timeToSolve!==void 0&&W.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(e.timeToSolve/1e3).toFixed(3),"s"]}),C&&W.jsxs("div",{className:"text-sm text-gray-600",children:["Phase: ",W.jsx("span",{className:"font-medium",children:C})]}),e.solved&&W.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),e.failed&&W.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),e.error&&W.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",e.error]})]})},l9e=(e,A,t)=>{const i=e.currentPipelineStepIndex;return A<i?"Completed":A===i&&e.activeSubSolver?e.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},B9e=(e,A)=>{const i=e.pipelineDef[A].solverName,n=l9e(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}},C9e=({status:e})=>{const A={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return W.jsx("span",{className:`font-medium ${A[e]}`,children:e})},Q9e=({progress:e})=>{if(e===0)return null;const A=Math.round(e*100);return W.jsxs("div",{className:"flex items-center gap-2",children:[W.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:W.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${A}%`}})}),W.jsxs("span",{className:"text-xs text-gray-500",children:[A,"%"]})]})},h9e=e=>Object.entries(e).map(([A,t])=>`${A}: ${t}`).join(", "),E9e=({stats:e})=>{if(!e||Object.keys(e).length===0)return W.jsx("span",{children:"-"});const A=Object.entries(e),t=h9e(e);return W.jsxs("details",{className:"cursor-pointer",children:[W.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:t}),W.jsx("div",{className:"mt-1 text-xs",children:A.map(([i,n])=>W.jsxs("div",{children:[i,": ",String(n)]},i))})]})},jfA=e=>{if(e===null||typeof e!="object")return e;if(Array.isArray(e))return e.map(jfA);const A={};for(const[t,i]of Object.entries(e))t.startsWith("_")||(A[t]=jfA(i));return A},u9e=(e,A)=>{try{if(typeof e.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${A}`);return}const t=jfA(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)}`)}},d9e=({solver:e,onStepUntilPhase:A,onDownloadInput:t})=>{const i=e.pipelineDef.map((r,a)=>B9e(e,a)),n=r=>{A?.(r)},o=r=>{r.solverInstance&&(t?t(r.solverInstance,r.name):u9e(r.solverInstance,r.name))},s=r=>`${(r/1e3).toFixed(2)}s`;return W.jsxs("div",{className:"border-t border-gray-200",children:[W.jsx("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200",children:W.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Steps"})}),W.jsx("div",{className:"overflow-x-auto",children:W.jsxs("table",{className:"w-full text-sm",children:[W.jsx("thead",{children:W.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Step"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),W.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",W.jsx("sub",{children:"0"})]}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),W.jsx("tbody",{children:i.map(r=>W.jsxs("tr",{className:`border-b border-gray-100 ${r.status==="In Progress"?"bg-yellow-50":""}`,children:[W.jsx("td",{className:"px-4 py-2",children:W.jsxs("div",{className:"flex items-center gap-2",children:[W.jsx("span",{className:"text-gray-400 w-6",children:String(r.index+1).padStart(2,"0")}),W.jsx("button",{onClick:()=>n(r.name),disabled:r.status==="Completed"||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:W.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:W.jsx("path",{fillRule:"evenodd",d:"M4.5 5.653c0-1.426 1.529-2.33 2.779-1.643l11.54 6.348c1.295.712 1.295 2.573 0 3.285L7.28 19.991c-1.25.687-2.779-.217-2.779-1.643V5.653z",clipRule:"evenodd"})})}),W.jsx("span",{className:"font-medium text-gray-900",children:r.name})]})}),W.jsx("td",{className:"px-4 py-2",children:W.jsx(C9e,{status:r.status})}),W.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:r.firstIteration!==null?r.firstIteration:""}),W.jsx("td",{className:"px-4 py-2 text-gray-600",children:r.iterations}),W.jsx("td",{className:"px-4 py-2",children:W.jsx(Q9e,{progress:r.progress})}),W.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(r.timeSpent)}),W.jsx("td",{className:"px-4 py-2 text-gray-500",children:W.jsx(E9e,{stats:r.stats})}),W.jsx("td",{className:"px-4 py-2",children:r.solverInstance?W.jsxs("button",{onClick:()=>o(r),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${r.name}`,children:[W.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:W.jsx("path",{fillRule:"evenodd",d:"M12 2.25a.75.75 0 01.75.75v11.69l3.22-3.22a.75.75 0 111.06 1.06l-4.5 4.5a.75.75 0 01-1.06 0l-4.5-4.5a.75.75 0 111.06-1.06l3.22 3.22V3a.75.75 0 01.75-.75zm-9 13.5a.75.75 0 01.75.75v2.25a1.5 1.5 0 001.5 1.5h13.5a1.5 1.5 0 001.5-1.5V16.5a.75.75 0 011.5 0v2.25a3 3 0 01-3 3H5.25a3 3 0 01-3-3V16.5a.75.75 0 01.75-.75z",clipRule:"evenodd"})}),W.jsx("span",{children:"Input"})]}):null})]},r.name))})]})})]})},p9e=class extends en.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 f9e({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,p=h.height??0;c(E,u),c(E+d,u+p)}for(const h of n){const E=h.x??0,u=h.y??0,d=h.radius??1;c(E-d,u-d),c(E+d,u+d)}for(const h of o)c(h.x,h.y);(!isFinite(s)||!isFinite(r)||!isFinite(a)||!isFinite(g))&&(s=-20,r=-20,a=20,g=20);const I=10,l=s-I,B=r-I,C=Math.max(1,a-s+2*I),Q=Math.max(1,g-r+2*I);return W.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${l} ${B} ${C} ${Q}`,role:"img","aria-label":"Graphics fallback",children:[i.map((h,E)=>W.jsx("rect",{x:h.x??0,y:h.y??0,width:h.width??0,height:h.height??0,fill:"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1},`rect-${E}`)),t.map((h,E)=>W.jsx("polyline",{fill:"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1,points:(h.points??[]).map(u=>`${u.x??0},${u.y??0}`).join(" ")},`line-${E}`)),n.map((h,E)=>W.jsx("circle",{cx:h.x??0,cy:h.y??0,r:h.radius??1.5,fill:h.fillColor??"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1},`circle-${E}`)),A.map((h,E)=>W.jsx("circle",{cx:h.x??0,cy:h.y??0,r:h.radius??1.5,fill:h.color??"black"},`point-${E}`)),o.map((h,E)=>W.jsx("text",{x:h.x??0,y:h.y??0,fontSize:h.fontSize??10,fill:h.color??"black",children:h.text??""},`text-${E}`))]})}var y9e=({solver:e,animationSpeed:A=25,onSolverStarted:t,onSolverCompleted:i})=>{const[n,o]=V.useReducer(c=>c+1,0),s=V.useMemo(()=>{try{return e.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(c){return console.error("Visualization error:",c),{points:[],lines:[],rects:[],circles:[]}}},[e,n]),r=V.useMemo(()=>(s.rects?.length||0)===0&&(s.lines?.length||0)===0&&(s.points?.length||0)===0&&(s.circles?.length||0)===0,[s]);V.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const c=document.createElement("script");c.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(c)}},[]);const a=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 W.jsxs("div",{children:[W.jsx(I9e,{solver:e,triggerRender:o,animationSpeed:A,onSolverStarted:t,onSolverCompleted:i}),r?W.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):W.jsx(p9e,{fallback:W.jsx(f9e,{graphics:s}),children:W.jsx(a9e,{graphics:s})}),a&&W.jsx(d9e,{solver:e,onStepUntilPhase:g})]})};const m9e=()=>{V.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)},[])},w9e=e=>e.toLowerCase().includes("pack")?NMe:e.toLowerCase().includes("rout")?YMe:pMe,D9e=({solverEvents:e=[]})=>{const[A,t]=V.useState(null);m9e();const i=V.useMemo(()=>{const r=new Map;for(const a of e){const g=`${a.componentName}-${a.solverName}`;r.set(g,a)}return r},[e]),n=V.useMemo(()=>Array.from(i.keys()),[i]),o=A?i.get(A):null,s=V.useMemo(()=>{if(!o)return{instance:null,error:null,classFound:!1};const r=AoA[o.solverName];if(!r)return{instance:null,error:`Solver class "${o.solverName}" not found in SOLVERS registry. Available: ${Object.keys(AoA).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?W.jsx("div",{className:"rf-p-4",children:W.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:W.jsxs("div",{className:"rf-p-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),W.jsx("p",{className:"rf-text-sm rf-text-gray-600",children:"Solvers will appear here when the circuit runs. Solvers are used for tasks like component packing and autorouting."})]})})}):W.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[W.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[W.jsxs("div",{className:"rf-text-xs rf-font-semibold rf-text-gray-500 rf-px-3 rf-py-2 rf-bg-gray-50 rf-border-b rf-border-gray-200",children:[n.length," ",n.length===1?"Solver":"Solvers"]}),n.map(r=>{const a=i.get(r),g=A===r;return W.jsx("div",{className:`rf-px-3 rf-py-2 rf-cursor-pointer rf-border-b rf-border-gray-100 ${g?"rf-bg-blue-50 rf-border-l-2 rf-border-l-blue-500":"hover:rf-bg-gray-50"}`,onClick:()=>t(r),children:(()=>{const c=w9e(a.solverName);return W.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[W.jsx(c,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),W.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[W.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:a.componentName}),W.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:a.solverName})]})]})})()},r)})]}),W.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:o?s.instance?W.jsx(qy,{fallback:W.jsx("div",{className:"rf-p-4",children:W.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),W.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",o.solverName]})]})}),children:W.jsx(y9e,{solver:s.instance})}):W.jsxs("div",{className:"rf-p-4",children:[W.jsxs("div",{className:"rf-mb-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:o.solverName}),W.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",o.componentName]})]}),s.error&&W.jsx("div",{className:`rf-rounded-md rf-border rf-p-4 rf-mb-4 ${s.classFound?"rf-bg-red-50 rf-border-red-200":"rf-bg-yellow-50 rf-border-yellow-200"}`,children:W.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),W.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[W.jsx("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50",children:W.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"})}),W.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:W.jsx("pre",{className:"rf-text-xs rf-font-mono rf-text-gray-600 rf-whitespace-pre-wrap rf-overflow-x-auto",children:JSON.stringify(o.solverParams,null,2)})})]})]}):W.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:W.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},BIt=({errorMessage:e,errorStack:A,circuitJsonErrors:t})=>{V.useEffect(()=>{if(e){const i=new Error(e);A&&(i.stack=A);try{J5.captureException(i)}catch{}}},[e,A]),V.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{J5.captureException(n,{error_type:i.type})}catch{}}},[t])},CIt="0.0.1588",S9e={version:CIt},z9=xYA()(_YA(e=>({lastRunEvalVersion:void 0,setLastRunEvalVersion:A=>{e({lastRunEvalVersion:A})}}),{name:"runframe-runner-store"})),b9e=e=>{const[A,t]=V.useState([]),[i,n]=V.useState(null),[o,s]=V.useState(""),[r,a]=c1("eval-version-selection",null),g=z9(B=>B.setLastRunEvalVersion),c=z9(B=>B.lastRunEvalVersion);return V.useEffect(()=>{e&&fetch("https://data.jsdelivr.com/v1/package/npm/@tscircuit/eval").then(B=>B.json()).then(B=>{if(Array.isArray(B?.versions)){let C=[...B.versions];B.tags?.latest&&(n(B.tags.latest),C=C.filter(Q=>Q!==B.tags.latest)),t(C)}}).catch(()=>{})},[e]),V.useEffect(()=>{e&&(r?(window.TSCIRCUIT_LATEST_EVAL_VERSION=r,g(r)):i&&(window.TSCIRCUIT_LATEST_EVAL_VERSION=i,g(i)))},[e,r,i]),{versions:V.useMemo(()=>A.filter(B=>B.includes(o)).slice(0,50),[A,o]),latestVersion:i,lastRunEvalVersion:c,search:o,setSearch:s,selectVersion:B=>{a(B),s("")}}},x9e=({snippetNames:e,onSelect:A,onCancel:t,isOpen:i})=>{const[n,o]=V.useState(""),[s,r]=V.useState("");if(!i)return null;const a=e.filter(I=>I.toLowerCase().includes(s.toLowerCase())),g=s&&!e.includes(s),c=I=>{I.key==="Enter"&&(a.length===1?o(a[0]):g&&o(s))};return W.jsx("div",{className:"rf-fixed rf-inset-0 rf-bg-black rf-bg-opacity-50 rf-flex rf-items-center rf-justify-center rf-z-[100]",children:W.jsxs("div",{className:"rf-bg-white rf-rounded-lg rf-p-6 rf-w-96",children:[W.jsx("h2",{className:"rf-text-lg rf-font-semibold rf-mb-4",children:"Select Snippet"}),W.jsx("input",{type:"text",className:"rf-w-full rf-px-4 rf-py-2 rf-border rf-rounded rf-mb-4",placeholder:"Search snippets or new snippet name...",value:s,onChange:I=>r(I.target.value),onKeyDown:c}),W.jsxs("div",{className:"rf-h-60 rf-overflow-y-auto",children:[a.map(I=>W.jsx("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 ${n===I?"bg-blue-50":""}`,onClick:()=>o(I),children:I},I)),g&&W.jsxs("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 text-blue-500 ${n===s?"bg-blue-50":""}`,onClick:()=>o(s),children:['Create new "',s,'"']})]}),W.jsxs("div",{className:"rf-mt-4 rf-flex rf-justify-end rf-gap-2",children:[W.jsx("button",{type:"button",className:"rf-px-4 rf-py-2 rf-text-gray-600 rf-hover:text-gray-800",onClick:t,children:"Cancel"}),W.jsx("button",{type:"button",className:"rf-px-4 rf-py-2 rf-bg-blue-500 rf-text-white rf-rounded rf-hover:bg-blue-600 rf-disabled:opacity-50",onClick:()=>n&&A(n),disabled:!n,children:n===s?`Create "${n}"`:`Save to ${n}`})]})]})})},_9e=e=>{const A=V.useRef(null),t=VI(i=>i.recentEvents);V.useEffect(()=>{if(t.length===0)return;const i=t[0];i.event_id!==A.current&&(e(i),A.current=i.event_id)},[t,e])};function k9e(e){const A=F9e(e),t=V.forwardRef((i,n)=>{const{children:o,...s}=i,r=V.Children.toArray(o),a=r.find(R9e);if(a){const g=a.props.children,c=r.map(I=>I===a?V.Children.count(g)>1?V.Children.only(null):V.isValidElement(g)?g.props.children:null:I);return W.jsx(A,{...s,ref:n,children:V.isValidElement(g)?V.cloneElement(g,void 0,c):null})}return W.jsx(A,{...s,ref:n,children:o})});return t.displayName=`${e}.Slot`,t}function F9e(e){const A=V.forwardRef((t,i)=>{const{children:n,...o}=t;if(V.isValidElement(n)){const s=N9e(n),r=M9e(o,n.props);return n.type!==V.Fragment&&(r.ref=i?Bf(i,s):s),V.cloneElement(n,r)}return V.Children.count(n)>1?V.Children.only(null):null});return A.displayName=`${e}.SlotClone`,A}var G9e=Symbol("radix.slottable");function R9e(e){return V.isValidElement(e)&&typeof e.type=="function"&&"__radixId"in e.type&&e.type.__radixId===G9e}function M9e(e,A){const t={...A};for(const i in A){const n=e[i],o=A[i];/^on[A-Z]/.test(i)?n&&o?t[i]=(...r)=>{const a=o(...r);return n(...r),a}:n&&(t[i]=n):i==="style"?t[i]={...n,...o}:i==="className"&&(t[i]=[n,o].filter(Boolean).join(" "))}return{...e,...t}}function N9e(e){let A=Object.getOwnPropertyDescriptor(e.props,"ref")?.get,t=A&&"isReactWarning"in A&&A.isReactWarning;return t?e.ref:(A=Object.getOwnPropertyDescriptor(e,"ref")?.get,t=A&&"isReactWarning"in A&&A.isReactWarning,t?e.props.ref:e.props.ref||e.ref)}var X9="Dialog",[QIt,hIt]=Om(X9),[v9e,pw]=QIt(X9),EIt=e=>{const{__scopeDialog:A,children:t,open:i,defaultOpen:n,onOpenChange:o,modal:s=!0}=e,r=V.useRef(null),a=V.useRef(null),[g,c]=qx({prop:i,defaultProp:n??!1,onChange:o,caller:X9});return W.jsx(v9e,{scope:A,triggerRef:r,contentRef:a,contentId:_E(),titleId:_E(),descriptionId:_E(),open:g,onOpenChange:c,onOpenToggle:V.useCallback(()=>c(I=>!I),[c]),modal:s,children:t})};EIt.displayName=X9;var uIt="DialogTrigger",dIt=V.forwardRef((e,A)=>{const{__scopeDialog:t,...i}=e,n=pw(uIt,t),o=fI(A,n.triggerRef);return W.jsx(Wa.button,{type:"button","aria-haspopup":"dialog","aria-expanded":n.open,"aria-controls":n.contentId,"data-state":$fA(n.open),...i,ref:o,onClick:Hn(e.onClick,n.onOpenToggle)})});dIt.displayName=uIt;var zfA="DialogPortal",[L9e,pIt]=QIt(zfA,{forceMount:void 0}),fIt=e=>{const{__scopeDialog:A,forceMount:t,children:i,container:n}=e,o=pw(zfA,A);return W.jsx(L9e,{scope:A,forceMount:t,children:V.Children.map(i,s=>W.jsx(w0,{present:t||o.open,children:W.jsx(VZ,{asChild:!0,container:n,children:s})}))})};fIt.displayName=zfA;var $9="DialogOverlay",yIt=V.forwardRef((e,A)=>{const t=pIt($9,e.__scopeDialog),{forceMount:i=t.forceMount,...n}=e,o=pw($9,e.__scopeDialog);return o.modal?W.jsx(w0,{present:i||o.open,children:W.jsx(H9e,{...n,ref:A})}):null});yIt.displayName=$9;var U9e=k9e("DialogOverlay.RemoveScroll"),H9e=V.forwardRef((e,A)=>{const{__scopeDialog:t,...i}=e,n=pw($9,t);return W.jsx(iV,{as:U9e,allowPinchZoom:!0,shards:[n.contentRef],children:W.jsx(Wa.div,{"data-state":$fA(n.open),...i,ref:A,style:{pointerEvents:"auto",...i.style}})})}),UG="DialogContent",mIt=V.forwardRef((e,A)=>{const t=pIt(UG,e.__scopeDialog),{forceMount:i=t.forceMount,...n}=e,o=pw(UG,e.__scopeDialog);return W.jsx(w0,{present:i||o.open,children:o.modal?W.jsx(Y9e,{...n,ref:A}):W.jsx(J9e,{...n,ref:A})})});mIt.displayName=UG;var Y9e=V.forwardRef((e,A)=>{const t=pw(UG,e.__scopeDialog),i=V.useRef(null),n=fI(A,t.contentRef,i);return V.useEffect(()=>{const o=i.current;if(o)return zuA(o)},[]),W.jsx(wIt,{...e,ref:n,trapFocus:t.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:Hn(e.onCloseAutoFocus,o=>{o.preventDefault(),t.triggerRef.current?.focus()}),onPointerDownOutside:Hn(e.onPointerDownOutside,o=>{const s=o.detail.originalEvent,r=s.button===0&&s.ctrlKey===!0;(s.button===2||r)&&o.preventDefault()}),onFocusOutside:Hn(e.onFocusOutside,o=>o.preventDefault())})}),J9e=V.forwardRef((e,A)=>{const t=pw(UG,e.__scopeDialog),i=V.useRef(!1),n=V.useRef(!1);return W.jsx(wIt,{...e,ref:A,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:o=>{e.onCloseAutoFocus?.(o),o.defaultPrevented||(i.current||t.triggerRef.current?.focus(),o.preventDefault()),i.current=!1,n.current=!1},onInteractOutside:o=>{e.onInteractOutside?.(o),o.defaultPrevented||(i.current=!0,o.detail.originalEvent.type==="pointerdown"&&(n.current=!0));const s=o.target;t.triggerRef.current?.contains(s)&&o.preventDefault(),o.detail.originalEvent.type==="focusin"&&n.current&&o.preventDefault()}})}),wIt=V.forwardRef((e,A)=>{const{__scopeDialog:t,trapFocus:i,onOpenAutoFocus:n,onCloseAutoFocus:o,...s}=e,r=pw(UG,t),a=V.useRef(null),g=fI(A,a);return GuA(),W.jsxs(W.Fragment,{children:[W.jsx(vZ,{asChild:!0,loop:!0,trapped:i,onMountAutoFocus:n,onUnmountAutoFocus:o,children:W.jsx(sY,{role:"dialog",id:r.contentId,"aria-describedby":r.descriptionId,"aria-labelledby":r.titleId,"data-state":$fA(r.open),...s,ref:g,onDismiss:()=>r.onOpenChange(!1)})}),W.jsxs(W.Fragment,{children:[W.jsx(K9e,{titleId:r.titleId}),W.jsx(q9e,{contentRef:a,descriptionId:r.descriptionId})]})]})}),XfA="DialogTitle",DIt=V.forwardRef((e,A)=>{const{__scopeDialog:t,...i}=e,n=pw(XfA,t);return W.jsx(Wa.h2,{id:n.titleId,...i,ref:A})});DIt.displayName=XfA;var SIt="DialogDescription",bIt=V.forwardRef((e,A)=>{const{__scopeDialog:t,...i}=e,n=pw(SIt,t);return W.jsx(Wa.p,{id:n.descriptionId,...i,ref:A})});bIt.displayName=SIt;var xIt="DialogClose",_It=V.forwardRef((e,A)=>{const{__scopeDialog:t,...i}=e,n=pw(xIt,t);return W.jsx(Wa.button,{type:"button",...i,ref:A,onClick:Hn(e.onClick,()=>n.onOpenChange(!1))})});_It.displayName=xIt;function $fA(e){return e?"open":"closed"}var kIt="DialogTitleWarning",[T9e,FIt]=r6t(kIt,{contentName:UG,titleName:XfA,docsSlug:"dialog"}),K9e=({titleId:e})=>{const A=FIt(kIt),t=`\`${A.contentName}\` requires a \`${A.titleName}\` for the component to be accessible for screen reader users.
5689
+ `,I=new Blob([c],{type:"text/plain"}),l=URL.createObjectURL(I),B=document.createElement("a");B.href=l,B.download=`${g}.test.ts`,B.click(),URL.revokeObjectURL(l)}catch(a){alert(`Error generating test.ts for ${e.constructor.name}: ${a instanceof Error?a.message:String(a)}`)}i(!1)};return W.jsxs("div",{className:`relative ${A}`,ref:n,children:[W.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>i(!t),title:`Download options for ${e.constructor.name}`,children:e.constructor.name}),t&&W.jsxs("div",{className:"absolute top-full left-0 mt-1 bg-white border border-gray-300 rounded shadow-lg z-10 min-w-[150px]",children:[W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:o,children:"Download JSON"}),W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:r,children:"Download test.ts"})]})]})},lIt=e=>e.activeSubSolver?[e,...lIt(e.activeSubSolver)]:[e],c9e=({solver:e})=>{const A=lIt(e);return W.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:A.map((t,i)=>W.jsxs("div",{className:"flex items-center",children:[i>0&&W.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),W.jsx(g9e,{solver:t})]},t.constructor.name))})},I9e=({solver:e,triggerRender:A,animationSpeed:t=25,onSolverStarted:i,onSolverCompleted:n})=>{const[o,s]=V.useReducer(Q=>!Q,!1),r=V.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)};V.useEffect(()=>()=>{r.current&&clearInterval(r.current)},[]),V.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 W.jsxs("div",{className:"space-y-2 p-2 border-b",children:[W.jsx("div",{className:"flex items-center",children:W.jsx(c9e,{solver:e})}),W.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[W.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"}),W.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"}),W.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"}),W.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&&W.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"}),W.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",e.iterations]}),e.timeToSolve!==void 0&&W.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(e.timeToSolve/1e3).toFixed(3),"s"]}),C&&W.jsxs("div",{className:"text-sm text-gray-600",children:["Phase: ",W.jsx("span",{className:"font-medium",children:C})]}),e.solved&&W.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),e.failed&&W.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),e.error&&W.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",e.error]})]})},l9e=(e,A,t)=>{const i=e.currentPipelineStepIndex;return A<i?"Completed":A===i&&e.activeSubSolver?e.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},B9e=(e,A)=>{const i=e.pipelineDef[A].solverName,n=l9e(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}},C9e=({status:e})=>{const A={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return W.jsx("span",{className:`font-medium ${A[e]}`,children:e})},Q9e=({progress:e})=>{if(e===0)return null;const A=Math.round(e*100);return W.jsxs("div",{className:"flex items-center gap-2",children:[W.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:W.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${A}%`}})}),W.jsxs("span",{className:"text-xs text-gray-500",children:[A,"%"]})]})},h9e=e=>Object.entries(e).map(([A,t])=>`${A}: ${t}`).join(", "),E9e=({stats:e})=>{if(!e||Object.keys(e).length===0)return W.jsx("span",{children:"-"});const A=Object.entries(e),t=h9e(e);return W.jsxs("details",{className:"cursor-pointer",children:[W.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:t}),W.jsx("div",{className:"mt-1 text-xs",children:A.map(([i,n])=>W.jsxs("div",{children:[i,": ",String(n)]},i))})]})},jfA=e=>{if(e===null||typeof e!="object")return e;if(Array.isArray(e))return e.map(jfA);const A={};for(const[t,i]of Object.entries(e))t.startsWith("_")||(A[t]=jfA(i));return A},u9e=(e,A)=>{try{if(typeof e.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${A}`);return}const t=jfA(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)}`)}},d9e=({solver:e,onStepUntilPhase:A,onDownloadInput:t})=>{const i=e.pipelineDef.map((r,a)=>B9e(e,a)),n=r=>{A?.(r)},o=r=>{r.solverInstance&&(t?t(r.solverInstance,r.name):u9e(r.solverInstance,r.name))},s=r=>`${(r/1e3).toFixed(2)}s`;return W.jsxs("div",{className:"border-t border-gray-200",children:[W.jsx("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200",children:W.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Steps"})}),W.jsx("div",{className:"overflow-x-auto",children:W.jsxs("table",{className:"w-full text-sm",children:[W.jsx("thead",{children:W.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Step"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),W.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",W.jsx("sub",{children:"0"})]}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),W.jsx("tbody",{children:i.map(r=>W.jsxs("tr",{className:`border-b border-gray-100 ${r.status==="In Progress"?"bg-yellow-50":""}`,children:[W.jsx("td",{className:"px-4 py-2",children:W.jsxs("div",{className:"flex items-center gap-2",children:[W.jsx("span",{className:"text-gray-400 w-6",children:String(r.index+1).padStart(2,"0")}),W.jsx("button",{onClick:()=>n(r.name),disabled:r.status==="Completed"||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:W.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:W.jsx("path",{fillRule:"evenodd",d:"M4.5 5.653c0-1.426 1.529-2.33 2.779-1.643l11.54 6.348c1.295.712 1.295 2.573 0 3.285L7.28 19.991c-1.25.687-2.779-.217-2.779-1.643V5.653z",clipRule:"evenodd"})})}),W.jsx("span",{className:"font-medium text-gray-900",children:r.name})]})}),W.jsx("td",{className:"px-4 py-2",children:W.jsx(C9e,{status:r.status})}),W.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:r.firstIteration!==null?r.firstIteration:""}),W.jsx("td",{className:"px-4 py-2 text-gray-600",children:r.iterations}),W.jsx("td",{className:"px-4 py-2",children:W.jsx(Q9e,{progress:r.progress})}),W.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(r.timeSpent)}),W.jsx("td",{className:"px-4 py-2 text-gray-500",children:W.jsx(E9e,{stats:r.stats})}),W.jsx("td",{className:"px-4 py-2",children:r.solverInstance?W.jsxs("button",{onClick:()=>o(r),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${r.name}`,children:[W.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:W.jsx("path",{fillRule:"evenodd",d:"M12 2.25a.75.75 0 01.75.75v11.69l3.22-3.22a.75.75 0 111.06 1.06l-4.5 4.5a.75.75 0 01-1.06 0l-4.5-4.5a.75.75 0 111.06-1.06l3.22 3.22V3a.75.75 0 01.75-.75zm-9 13.5a.75.75 0 01.75.75v2.25a1.5 1.5 0 001.5 1.5h13.5a1.5 1.5 0 001.5-1.5V16.5a.75.75 0 011.5 0v2.25a3 3 0 01-3 3H5.25a3 3 0 01-3-3V16.5a.75.75 0 01.75-.75z",clipRule:"evenodd"})}),W.jsx("span",{children:"Input"})]}):null})]},r.name))})]})})]})},p9e=class extends en.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 f9e({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,p=h.height??0;c(E,u),c(E+d,u+p)}for(const h of n){const E=h.x??0,u=h.y??0,d=h.radius??1;c(E-d,u-d),c(E+d,u+d)}for(const h of o)c(h.x,h.y);(!isFinite(s)||!isFinite(r)||!isFinite(a)||!isFinite(g))&&(s=-20,r=-20,a=20,g=20);const I=10,l=s-I,B=r-I,C=Math.max(1,a-s+2*I),Q=Math.max(1,g-r+2*I);return W.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${l} ${B} ${C} ${Q}`,role:"img","aria-label":"Graphics fallback",children:[i.map((h,E)=>W.jsx("rect",{x:h.x??0,y:h.y??0,width:h.width??0,height:h.height??0,fill:"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1},`rect-${E}`)),t.map((h,E)=>W.jsx("polyline",{fill:"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1,points:(h.points??[]).map(u=>`${u.x??0},${u.y??0}`).join(" ")},`line-${E}`)),n.map((h,E)=>W.jsx("circle",{cx:h.x??0,cy:h.y??0,r:h.radius??1.5,fill:h.fillColor??"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1},`circle-${E}`)),A.map((h,E)=>W.jsx("circle",{cx:h.x??0,cy:h.y??0,r:h.radius??1.5,fill:h.color??"black"},`point-${E}`)),o.map((h,E)=>W.jsx("text",{x:h.x??0,y:h.y??0,fontSize:h.fontSize??10,fill:h.color??"black",children:h.text??""},`text-${E}`))]})}var y9e=({solver:e,animationSpeed:A=25,onSolverStarted:t,onSolverCompleted:i})=>{const[n,o]=V.useReducer(c=>c+1,0),s=V.useMemo(()=>{try{return e.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(c){return console.error("Visualization error:",c),{points:[],lines:[],rects:[],circles:[]}}},[e,n]),r=V.useMemo(()=>(s.rects?.length||0)===0&&(s.lines?.length||0)===0&&(s.points?.length||0)===0&&(s.circles?.length||0)===0,[s]);V.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const c=document.createElement("script");c.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(c)}},[]);const a=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 W.jsxs("div",{children:[W.jsx(I9e,{solver:e,triggerRender:o,animationSpeed:A,onSolverStarted:t,onSolverCompleted:i}),r?W.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):W.jsx(p9e,{fallback:W.jsx(f9e,{graphics:s}),children:W.jsx(a9e,{graphics:s})}),a&&W.jsx(d9e,{solver:e,onStepUntilPhase:g})]})};const m9e=()=>{V.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)},[])},w9e=e=>e.toLowerCase().includes("pack")?NMe:e.toLowerCase().includes("rout")?YMe:pMe,D9e=({solverEvents:e=[]})=>{const[A,t]=V.useState(null);m9e();const i=V.useMemo(()=>{const r=new Map;for(const a of e){const g=`${a.componentName}-${a.solverName}`;r.set(g,a)}return r},[e]),n=V.useMemo(()=>Array.from(i.keys()),[i]),o=A?i.get(A):null,s=V.useMemo(()=>{if(!o)return{instance:null,error:null,classFound:!1};const r=AoA[o.solverName];if(!r)return{instance:null,error:`Solver class "${o.solverName}" not found in SOLVERS registry. Available: ${Object.keys(AoA).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?W.jsx("div",{className:"rf-p-4",children:W.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:W.jsxs("div",{className:"rf-p-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),W.jsx("p",{className:"rf-text-sm rf-text-gray-600",children:"Solvers will appear here when the circuit runs. Solvers are used for tasks like component packing and autorouting."})]})})}):W.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[W.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[W.jsxs("div",{className:"rf-text-xs rf-font-semibold rf-text-gray-500 rf-px-3 rf-py-2 rf-bg-gray-50 rf-border-b rf-border-gray-200",children:[n.length," ",n.length===1?"Solver":"Solvers"]}),n.map(r=>{const a=i.get(r),g=A===r;return W.jsx("div",{className:`rf-px-3 rf-py-2 rf-cursor-pointer rf-border-b rf-border-gray-100 ${g?"rf-bg-blue-50 rf-border-l-2 rf-border-l-blue-500":"hover:rf-bg-gray-50"}`,onClick:()=>t(r),children:(()=>{const c=w9e(a.solverName);return W.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[W.jsx(c,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),W.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[W.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:a.componentName}),W.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:a.solverName})]})]})})()},r)})]}),W.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:o?s.instance?W.jsx(qy,{fallback:W.jsx("div",{className:"rf-p-4",children:W.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),W.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",o.solverName]})]})}),children:W.jsx(y9e,{solver:s.instance})}):W.jsxs("div",{className:"rf-p-4",children:[W.jsxs("div",{className:"rf-mb-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:o.solverName}),W.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",o.componentName]})]}),s.error&&W.jsx("div",{className:`rf-rounded-md rf-border rf-p-4 rf-mb-4 ${s.classFound?"rf-bg-red-50 rf-border-red-200":"rf-bg-yellow-50 rf-border-yellow-200"}`,children:W.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),W.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[W.jsx("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50",children:W.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"})}),W.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:W.jsx("pre",{className:"rf-text-xs rf-font-mono rf-text-gray-600 rf-whitespace-pre-wrap rf-overflow-x-auto",children:JSON.stringify(o.solverParams,null,2)})})]})]}):W.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:W.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},BIt=({errorMessage:e,errorStack:A,circuitJsonErrors:t})=>{V.useEffect(()=>{if(e){const i=new Error(e);A&&(i.stack=A);try{J5.captureException(i)}catch{}}},[e,A]),V.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{J5.captureException(n,{error_type:i.type})}catch{}}},[t])},CIt="0.0.1590",S9e={version:CIt},z9=xYA()(_YA(e=>({lastRunEvalVersion:void 0,setLastRunEvalVersion:A=>{e({lastRunEvalVersion:A})}}),{name:"runframe-runner-store"})),b9e=e=>{const[A,t]=V.useState([]),[i,n]=V.useState(null),[o,s]=V.useState(""),[r,a]=c1("eval-version-selection",null),g=z9(B=>B.setLastRunEvalVersion),c=z9(B=>B.lastRunEvalVersion);return V.useEffect(()=>{e&&fetch("https://data.jsdelivr.com/v1/package/npm/@tscircuit/eval").then(B=>B.json()).then(B=>{if(Array.isArray(B?.versions)){let C=[...B.versions];B.tags?.latest&&(n(B.tags.latest),C=C.filter(Q=>Q!==B.tags.latest)),t(C)}}).catch(()=>{})},[e]),V.useEffect(()=>{e&&(r?(window.TSCIRCUIT_LATEST_EVAL_VERSION=r,g(r)):i&&(window.TSCIRCUIT_LATEST_EVAL_VERSION=i,g(i)))},[e,r,i]),{versions:V.useMemo(()=>A.filter(B=>B.includes(o)).slice(0,50),[A,o]),latestVersion:i,lastRunEvalVersion:c,search:o,setSearch:s,selectVersion:B=>{a(B),s("")}}},x9e=({snippetNames:e,onSelect:A,onCancel:t,isOpen:i})=>{const[n,o]=V.useState(""),[s,r]=V.useState("");if(!i)return null;const a=e.filter(I=>I.toLowerCase().includes(s.toLowerCase())),g=s&&!e.includes(s),c=I=>{I.key==="Enter"&&(a.length===1?o(a[0]):g&&o(s))};return W.jsx("div",{className:"rf-fixed rf-inset-0 rf-bg-black rf-bg-opacity-50 rf-flex rf-items-center rf-justify-center rf-z-[100]",children:W.jsxs("div",{className:"rf-bg-white rf-rounded-lg rf-p-6 rf-w-96",children:[W.jsx("h2",{className:"rf-text-lg rf-font-semibold rf-mb-4",children:"Select Snippet"}),W.jsx("input",{type:"text",className:"rf-w-full rf-px-4 rf-py-2 rf-border rf-rounded rf-mb-4",placeholder:"Search snippets or new snippet name...",value:s,onChange:I=>r(I.target.value),onKeyDown:c}),W.jsxs("div",{className:"rf-h-60 rf-overflow-y-auto",children:[a.map(I=>W.jsx("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 ${n===I?"bg-blue-50":""}`,onClick:()=>o(I),children:I},I)),g&&W.jsxs("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 text-blue-500 ${n===s?"bg-blue-50":""}`,onClick:()=>o(s),children:['Create new "',s,'"']})]}),W.jsxs("div",{className:"rf-mt-4 rf-flex rf-justify-end rf-gap-2",children:[W.jsx("button",{type:"button",className:"rf-px-4 rf-py-2 rf-text-gray-600 rf-hover:text-gray-800",onClick:t,children:"Cancel"}),W.jsx("button",{type:"button",className:"rf-px-4 rf-py-2 rf-bg-blue-500 rf-text-white rf-rounded rf-hover:bg-blue-600 rf-disabled:opacity-50",onClick:()=>n&&A(n),disabled:!n,children:n===s?`Create "${n}"`:`Save to ${n}`})]})]})})},_9e=e=>{const A=V.useRef(null),t=VI(i=>i.recentEvents);V.useEffect(()=>{if(t.length===0)return;const i=t[0];i.event_id!==A.current&&(e(i),A.current=i.event_id)},[t,e])};function k9e(e){const A=F9e(e),t=V.forwardRef((i,n)=>{const{children:o,...s}=i,r=V.Children.toArray(o),a=r.find(R9e);if(a){const g=a.props.children,c=r.map(I=>I===a?V.Children.count(g)>1?V.Children.only(null):V.isValidElement(g)?g.props.children:null:I);return W.jsx(A,{...s,ref:n,children:V.isValidElement(g)?V.cloneElement(g,void 0,c):null})}return W.jsx(A,{...s,ref:n,children:o})});return t.displayName=`${e}.Slot`,t}function F9e(e){const A=V.forwardRef((t,i)=>{const{children:n,...o}=t;if(V.isValidElement(n)){const s=N9e(n),r=M9e(o,n.props);return n.type!==V.Fragment&&(r.ref=i?Bf(i,s):s),V.cloneElement(n,r)}return V.Children.count(n)>1?V.Children.only(null):null});return A.displayName=`${e}.SlotClone`,A}var G9e=Symbol("radix.slottable");function R9e(e){return V.isValidElement(e)&&typeof e.type=="function"&&"__radixId"in e.type&&e.type.__radixId===G9e}function M9e(e,A){const t={...A};for(const i in A){const n=e[i],o=A[i];/^on[A-Z]/.test(i)?n&&o?t[i]=(...r)=>{const a=o(...r);return n(...r),a}:n&&(t[i]=n):i==="style"?t[i]={...n,...o}:i==="className"&&(t[i]=[n,o].filter(Boolean).join(" "))}return{...e,...t}}function N9e(e){let A=Object.getOwnPropertyDescriptor(e.props,"ref")?.get,t=A&&"isReactWarning"in A&&A.isReactWarning;return t?e.ref:(A=Object.getOwnPropertyDescriptor(e,"ref")?.get,t=A&&"isReactWarning"in A&&A.isReactWarning,t?e.props.ref:e.props.ref||e.ref)}var X9="Dialog",[QIt,hIt]=Om(X9),[v9e,pw]=QIt(X9),EIt=e=>{const{__scopeDialog:A,children:t,open:i,defaultOpen:n,onOpenChange:o,modal:s=!0}=e,r=V.useRef(null),a=V.useRef(null),[g,c]=qx({prop:i,defaultProp:n??!1,onChange:o,caller:X9});return W.jsx(v9e,{scope:A,triggerRef:r,contentRef:a,contentId:_E(),titleId:_E(),descriptionId:_E(),open:g,onOpenChange:c,onOpenToggle:V.useCallback(()=>c(I=>!I),[c]),modal:s,children:t})};EIt.displayName=X9;var uIt="DialogTrigger",dIt=V.forwardRef((e,A)=>{const{__scopeDialog:t,...i}=e,n=pw(uIt,t),o=fI(A,n.triggerRef);return W.jsx(Wa.button,{type:"button","aria-haspopup":"dialog","aria-expanded":n.open,"aria-controls":n.contentId,"data-state":$fA(n.open),...i,ref:o,onClick:Hn(e.onClick,n.onOpenToggle)})});dIt.displayName=uIt;var zfA="DialogPortal",[L9e,pIt]=QIt(zfA,{forceMount:void 0}),fIt=e=>{const{__scopeDialog:A,forceMount:t,children:i,container:n}=e,o=pw(zfA,A);return W.jsx(L9e,{scope:A,forceMount:t,children:V.Children.map(i,s=>W.jsx(w0,{present:t||o.open,children:W.jsx(VZ,{asChild:!0,container:n,children:s})}))})};fIt.displayName=zfA;var $9="DialogOverlay",yIt=V.forwardRef((e,A)=>{const t=pIt($9,e.__scopeDialog),{forceMount:i=t.forceMount,...n}=e,o=pw($9,e.__scopeDialog);return o.modal?W.jsx(w0,{present:i||o.open,children:W.jsx(H9e,{...n,ref:A})}):null});yIt.displayName=$9;var U9e=k9e("DialogOverlay.RemoveScroll"),H9e=V.forwardRef((e,A)=>{const{__scopeDialog:t,...i}=e,n=pw($9,t);return W.jsx(iV,{as:U9e,allowPinchZoom:!0,shards:[n.contentRef],children:W.jsx(Wa.div,{"data-state":$fA(n.open),...i,ref:A,style:{pointerEvents:"auto",...i.style}})})}),UG="DialogContent",mIt=V.forwardRef((e,A)=>{const t=pIt(UG,e.__scopeDialog),{forceMount:i=t.forceMount,...n}=e,o=pw(UG,e.__scopeDialog);return W.jsx(w0,{present:i||o.open,children:o.modal?W.jsx(Y9e,{...n,ref:A}):W.jsx(J9e,{...n,ref:A})})});mIt.displayName=UG;var Y9e=V.forwardRef((e,A)=>{const t=pw(UG,e.__scopeDialog),i=V.useRef(null),n=fI(A,t.contentRef,i);return V.useEffect(()=>{const o=i.current;if(o)return zuA(o)},[]),W.jsx(wIt,{...e,ref:n,trapFocus:t.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:Hn(e.onCloseAutoFocus,o=>{o.preventDefault(),t.triggerRef.current?.focus()}),onPointerDownOutside:Hn(e.onPointerDownOutside,o=>{const s=o.detail.originalEvent,r=s.button===0&&s.ctrlKey===!0;(s.button===2||r)&&o.preventDefault()}),onFocusOutside:Hn(e.onFocusOutside,o=>o.preventDefault())})}),J9e=V.forwardRef((e,A)=>{const t=pw(UG,e.__scopeDialog),i=V.useRef(!1),n=V.useRef(!1);return W.jsx(wIt,{...e,ref:A,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:o=>{e.onCloseAutoFocus?.(o),o.defaultPrevented||(i.current||t.triggerRef.current?.focus(),o.preventDefault()),i.current=!1,n.current=!1},onInteractOutside:o=>{e.onInteractOutside?.(o),o.defaultPrevented||(i.current=!0,o.detail.originalEvent.type==="pointerdown"&&(n.current=!0));const s=o.target;t.triggerRef.current?.contains(s)&&o.preventDefault(),o.detail.originalEvent.type==="focusin"&&n.current&&o.preventDefault()}})}),wIt=V.forwardRef((e,A)=>{const{__scopeDialog:t,trapFocus:i,onOpenAutoFocus:n,onCloseAutoFocus:o,...s}=e,r=pw(UG,t),a=V.useRef(null),g=fI(A,a);return GuA(),W.jsxs(W.Fragment,{children:[W.jsx(vZ,{asChild:!0,loop:!0,trapped:i,onMountAutoFocus:n,onUnmountAutoFocus:o,children:W.jsx(sY,{role:"dialog",id:r.contentId,"aria-describedby":r.descriptionId,"aria-labelledby":r.titleId,"data-state":$fA(r.open),...s,ref:g,onDismiss:()=>r.onOpenChange(!1)})}),W.jsxs(W.Fragment,{children:[W.jsx(K9e,{titleId:r.titleId}),W.jsx(q9e,{contentRef:a,descriptionId:r.descriptionId})]})]})}),XfA="DialogTitle",DIt=V.forwardRef((e,A)=>{const{__scopeDialog:t,...i}=e,n=pw(XfA,t);return W.jsx(Wa.h2,{id:n.titleId,...i,ref:A})});DIt.displayName=XfA;var SIt="DialogDescription",bIt=V.forwardRef((e,A)=>{const{__scopeDialog:t,...i}=e,n=pw(SIt,t);return W.jsx(Wa.p,{id:n.descriptionId,...i,ref:A})});bIt.displayName=SIt;var xIt="DialogClose",_It=V.forwardRef((e,A)=>{const{__scopeDialog:t,...i}=e,n=pw(xIt,t);return W.jsx(Wa.button,{type:"button",...i,ref:A,onClick:Hn(e.onClick,()=>n.onOpenChange(!1))})});_It.displayName=xIt;function $fA(e){return e?"open":"closed"}var kIt="DialogTitleWarning",[T9e,FIt]=r6t(kIt,{contentName:UG,titleName:XfA,docsSlug:"dialog"}),K9e=({titleId:e})=>{const A=FIt(kIt),t=`\`${A.contentName}\` requires a \`${A.titleName}\` for the component to be accessible for screen reader users.
5690
5690
 
5691
5691
  If you want to hide the \`${A.titleName}\`, you can wrap it with our VisuallyHidden component.
5692
5692
 
@@ -5823,7 +5823,7 @@ ${a.join(`
5823
5823
  `)}};vA.register(toi);var Xht=class xbA extends vA{static token="locked";static parentToken="group";token="locked";value;constructor(A){super(),this.value=A}static fromSexprPrimitives(A){if(A.length===0)return new xbA(!0);const t=pi(A[0]);return new xbA(t==="yes")}getString(){return this.value?"(locked yes)":"(locked no)"}};vA.register(Xht);var $ht=class pwt extends vA{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=pi(i);n&&t.push(n)}return new pwt(t)}getString(){return this.members.length===0?"(members)":`(members ${this.members.map(t=>`"${t}"`).join(" ")})`}};vA.register($ht);var MwA=class fwt extends vA{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=ai(t),o=ai(i);if(n===void 0||o===void 0)throw new Error("end expects two numeric arguments");return new fwt(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})`}};vA.register(MwA);var eoi=new Set(["true","yes","1"]),AEt=class PX extends vl{static token="locked";static parentToken="segment";token="locked";constructor(A){super(A)}static fromSexprPrimitives(A){const[t]=A;return typeof t=="boolean"?new PX(t):typeof t=="string"?new PX(eoi.has(t.toLowerCase())):new PX(!1)}getString(){return`(locked ${this.value?"yes":"no"})`}};vA.register(AEt);var nz=class ywt extends vA{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=ai(t);if(n===void 0)throw new Error("net expects a numeric identifier");const o=i===void 0?void 0:pi(i);return new ywt(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?` ${Qn(this._name)}`:"";return`(net ${this._id}${A})`}};vA.register(nz);var NwA=class mwt extends vA{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=ai(t),o=ai(i);if(n===void 0||o===void 0)throw new Error("start expects two numeric arguments");return new mwt(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})`}};vA.register(NwA);var tEt=new Set(["start","end","width","layer","net","tstamp","uuid","locked"]),vwA=class wwt extends vA{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 wwt,{propertyMap:i,arrayPropertyMap:n}=vA.parsePrimitivesToClassProperties(A,this.token),o=Object.keys(i).filter(r=>!tEt.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(!tEt.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 Rr?A:new Rr(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 mr){this._sxLayer=A;return}const t=Array.isArray(A)?A:[A];this._sxLayer=new mr(t)}get net(){return this._sxNet}set net(A){if(A===void 0){this._sxNet=void 0;return}if(A instanceof nz){this._sxNet=A;return}this._sxNet=new nz(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 tc?A:new tc(A)}get uuid(){return this._sxUuid}set uuid(A){if(A===void 0){this._sxUuid=void 0;return}this._sxUuid=A instanceof Li?A:new Li(A)}get locked(){return this._sxLocked?.value??!1}set locked(A){this._sxLocked=A?new AEt(!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 NwA?A:new NwA(A.x,A.y)}normalizeEnd(A){if(A!==void 0)return A instanceof MwA?A:new MwA(A.x,A.y)}};vA.register(vwA);var eEt=class Dwt extends vA{static token="zone";token="zone";_rawChildren=[];static fromSexprPrimitives(A){const t=new Dwt;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(` ${vh(t)}`);return A.push(")"),A.join(`
5824
5824
  `)}};vA.register(eEt);var oz=class Swt extends vA{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):vh(i));return new Swt(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:Qn(t)).join(" ")})`}};vA.register(oz);var nT=class extends vA{_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=pi(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?Qn(this._value):this._value:`${this._value}`}getString(){return`(${this.token} ${this.formatValue()})`}},ioi=class extends vA{_values;constructor(e){super(),this._values=e}static fromSexprPrimitives(e){const A=e.map(i=>{const n=ai(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(" ")})`}},noi=class extends vA{_x;_y;constructor(e,A){super(),this._x=e,this._y=A}static fromSexprPrimitives(e){const[A,t]=e,i=ai(A),n=ai(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})`}},wr=class extends nT{static parentToken="pcbplotparams"},cm=class extends wr{static parsePrimitiveValue(e){const A=ai(e);if(A===void 0)throw new Error(`pcbplotparams ${this.token} expects a numeric value`);return A}},iEt=class extends wr{static token="layerselection";token="layerselection"};vA.register(iEt);var nEt=class extends wr{static token="plot_on_all_layers_selection";token="plot_on_all_layers_selection"};vA.register(nEt);var oEt=class extends cm{static token="dashed_line_dash_ratio";token="dashed_line_dash_ratio"};vA.register(oEt);var sEt=class extends cm{static token="dashed_line_gap_ratio";token="dashed_line_gap_ratio"};vA.register(sEt);var rEt=class extends cm{static token="svgprecision";token="svgprecision"};vA.register(rEt);var aEt=class extends cm{static token="linewidth";token="linewidth"};vA.register(aEt);var gEt=class extends cm{static token="mode";token="mode"};vA.register(gEt);var cEt=class extends cm{static token="hpglpennumber";token="hpglpennumber"};vA.register(cEt);var IEt=class extends cm{static token="hpglpenspeed";token="hpglpenspeed"};vA.register(IEt);var lEt=class extends cm{static token="hpglpendiameter";token="hpglpendiameter"};vA.register(lEt);var BEt=class extends cm{static token="hpglpenoverlay";token="hpglpenoverlay"};vA.register(BEt);var CEt=class extends cm{static token="outputformat";token="outputformat"};vA.register(CEt);var QEt=class extends cm{static token="drillshape";token="drillshape"};vA.register(QEt);var hEt=class extends cm{static token="scaleselection";token="scaleselection"};vA.register(hEt);var EEt=class extends wr{static token="disableapertmacros";token="disableapertmacros"};vA.register(EEt);var uEt=class extends wr{static token="usegerberextensions";token="usegerberextensions"};vA.register(uEt);var dEt=class extends wr{static token="usegerberattributes";token="usegerberattributes"};vA.register(dEt);var pEt=class extends wr{static token="usegerberadvancedattributes";token="usegerberadvancedattributes"};vA.register(pEt);var fEt=class extends wr{static token="creategerberjobfile";token="creategerberjobfile"};vA.register(fEt);var yEt=class extends wr{static token="excludeedgelayer";token="excludeedgelayer"};vA.register(yEt);var mEt=class extends wr{static token="plotframeref";token="plotframeref"};vA.register(mEt);var wEt=class extends wr{static token="viasonmask";token="viasonmask"};vA.register(wEt);var DEt=class extends wr{static token="useauxorigin";token="useauxorigin"};vA.register(DEt);var SEt=class extends wr{static token="pdf_front_fp_property_popups";token="pdf_front_fp_property_popups"};vA.register(SEt);var bEt=class extends wr{static token="pdf_back_fp_property_popups";token="pdf_back_fp_property_popups"};vA.register(bEt);var xEt=class extends wr{static token="pdf_metadata";token="pdf_metadata"};vA.register(xEt);var _Et=class extends wr{static token="pdf_single_document";token="pdf_single_document"};vA.register(_Et);var kEt=class extends wr{static token="dxfpolygonmode";token="dxfpolygonmode"};vA.register(kEt);var FEt=class extends wr{static token="dxfimperialunits";token="dxfimperialunits"};vA.register(FEt);var GEt=class extends wr{static token="dxfusepcbnewfont";token="dxfusepcbnewfont"};vA.register(GEt);var REt=class extends wr{static token="psnegative";token="psnegative"};vA.register(REt);var MEt=class extends wr{static token="psa4output";token="psa4output"};vA.register(MEt);var NEt=class extends wr{static token="plotreference";token="plotreference"};vA.register(NEt);var vEt=class extends wr{static token="plotvalue";token="plotvalue"};vA.register(vEt);var LEt=class extends wr{static token="plotothertext";token="plotothertext"};vA.register(LEt);var UEt=class extends wr{static token="plotinvisibletext";token="plotinvisibletext"};vA.register(UEt);var HEt=class extends wr{static token="padsonsilk";token="padsonsilk"};vA.register(HEt);var YEt=class extends wr{static token="sketchpadsonfab";token="sketchpadsonfab"};vA.register(YEt);var JEt=class extends wr{static token="plotpadnumbers";token="plotpadnumbers"};vA.register(JEt);var TEt=class extends wr{static token="hidednponfab";token="hidednponfab"};vA.register(TEt);var KEt=class extends wr{static token="sketchdnponfab";token="sketchdnponfab"};vA.register(KEt);var PEt=class extends wr{static token="crossoutdnponfab";token="crossoutdnponfab"};vA.register(PEt);var qEt=class extends wr{static token="subtractmaskfromsilk";token="subtractmaskfromsilk"};vA.register(qEt);var OEt=class extends wr{static token="plot_black_and_white";token="plot_black_and_white"};vA.register(OEt);var WEt=class extends wr{static token="mirror";token="mirror"};vA.register(WEt);var ZEt=class extends wr{static token="outputdirectory";token="outputdirectory";quoteStringValue=!0};vA.register(ZEt);var VEt=class extends wr{static token="plot_on_all_layers";token="plot_on_all_layers"};vA.register(VEt);var jEt=class extends wr{static token="plotinvisible";token="plotinvisible"};vA.register(jEt);var ooi={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"},soi=["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"],LwA=class bwt extends vA{static token="pcbplotparams";static parentToken="setup";token="pcbplotparams";_properties={};static fromSexprPrimitives(A){const t=new bwt,{propertyMap:i}=vA.parsePrimitivesToClassProperties(A,this.token);for(const[n,o]of Object.entries(i)){const s=ooi[n];if(!s)throw new Error(`Unsupported pcbplotparams token: ${n}`);t._properties[s]=o}return t}getChildren(){const A=[];for(const t of soi){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,iEt)}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,nEt)}get disableapertmacros(){return this._properties.disableapertmacros?.value}set disableapertmacros(A){this.setStringProperty("disableapertmacros",A,EEt)}get usegerberextensions(){return this._properties.usegerberextensions?.value}set usegerberextensions(A){this.setStringProperty("usegerberextensions",A,uEt)}get usegerberattributes(){return this._properties.usegerberattributes?.value}set usegerberattributes(A){this.setStringProperty("usegerberattributes",A,dEt)}get usegerberadvancedattributes(){return this._properties.usegerberadvancedattributes?.value}set usegerberadvancedattributes(A){this.setStringProperty("usegerberadvancedattributes",A,pEt)}get creategerberjobfile(){return this._properties.creategerberjobfile?.value}set creategerberjobfile(A){this.setStringProperty("creategerberjobfile",A,fEt)}get excludeedgelayer(){return this._properties.excludeedgelayer?.value}set excludeedgelayer(A){this.setStringProperty("excludeedgelayer",A,yEt)}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,oEt)}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,sEt)}get svgprecision(){return this._properties.svgprecision?.value}set svgprecision(A){this.setNumberProperty("svgprecision",A,rEt)}get linewidth(){return this._properties.linewidth?.value}set linewidth(A){this.setNumberProperty("linewidth",A,aEt)}get plotframeref(){return this._properties.plotframeref?.value}set plotframeref(A){this.setStringProperty("plotframeref",A,mEt)}get plotreference(){return this._properties.plotreference?.value}set plotreference(A){this.setStringProperty("plotreference",A,NEt)}get plotvalue(){return this._properties.plotvalue?.value}set plotvalue(A){this.setStringProperty("plotvalue",A,vEt)}get plotothertext(){return this._properties.plotothertext?.value}set plotothertext(A){this.setStringProperty("plotothertext",A,LEt)}get plotinvisibletext(){return this._properties.plotinvisibletext?.value}set plotinvisibletext(A){this.setStringProperty("plotinvisibletext",A,UEt)}get padsonsilk(){return this._properties.padsonsilk?.value}set padsonsilk(A){this.setStringProperty("padsonsilk",A,HEt)}get plotpadnumbers(){return this._properties.plotpadnumbers?.value}set plotpadnumbers(A){this.setStringProperty("plotpadnumbers",A,JEt)}get sketchpadsonfab(){return this._properties.sketchpadsonfab?.value}set sketchpadsonfab(A){this.setStringProperty("sketchpadsonfab",A,YEt)}get hidednponfab(){return this._properties.hidednponfab?.value}set hidednponfab(A){this.setStringProperty("hidednponfab",A,TEt)}get sketchdnponfab(){return this._properties.sketchdnponfab?.value}set sketchdnponfab(A){this.setStringProperty("sketchdnponfab",A,KEt)}get crossoutdnponfab(){return this._properties.crossoutdnponfab?.value}set crossoutdnponfab(A){this.setStringProperty("crossoutdnponfab",A,PEt)}get subtractmaskfromsilk(){return this._properties.subtractmaskfromsilk?.value}set subtractmaskfromsilk(A){this.setStringProperty("subtractmaskfromsilk",A,qEt)}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,OEt)}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,VEt)}get plotinvisible(){return this._properties.plotinvisible?.value}set plotinvisible(A){this.setStringProperty("plotinvisible",A,jEt)}get mode(){return this._properties.mode?.value}set mode(A){this.setNumberProperty("mode",A,gEt)}get useauxorigin(){return this._properties.useauxorigin?.value}set useauxorigin(A){this.setStringProperty("useauxorigin",A,DEt)}get viasonmask(){return this._properties.viasonmask?.value}set viasonmask(A){this.setStringProperty("viasonmask",A,wEt)}get hpglpennumber(){return this._properties.hpglpennumber?.value}set hpglpennumber(A){this.setNumberProperty("hpglpennumber",A,cEt)}get hpglpenspeed(){return this._properties.hpglpenspeed?.value}set hpglpenspeed(A){this.setNumberProperty("hpglpenspeed",A,IEt)}get hpglpendiameter(){return this._properties.hpglpendiameter?.value}set hpglpendiameter(A){this.setNumberProperty("hpglpendiameter",A,lEt)}get hpglpenoverlay(){return this._properties.hpglpenoverlay?.value}set hpglpenoverlay(A){this.setNumberProperty("hpglpenoverlay",A,BEt)}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,SEt)}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,bEt)}get pdf_metadata(){return this._properties.pdf_metadata?.value}set pdf_metadata(A){this.setStringProperty("pdf_metadata",A,xEt)}get pdf_single_document(){return this._properties.pdf_single_document?.value}set pdf_single_document(A){this.setStringProperty("pdf_single_document",A,_Et)}get dxfpolygonmode(){return this._properties.dxfpolygonmode?.value}set dxfpolygonmode(A){this.setStringProperty("dxfpolygonmode",A,kEt)}get dxfimperialunits(){return this._properties.dxfimperialunits?.value}set dxfimperialunits(A){this.setStringProperty("dxfimperialunits",A,FEt)}get dxfusepcbnewfont(){return this._properties.dxfusepcbnewfont?.value}set dxfusepcbnewfont(A){this.setStringProperty("dxfusepcbnewfont",A,GEt)}get psnegative(){return this._properties.psnegative?.value}set psnegative(A){this.setStringProperty("psnegative",A,REt)}get psa4output(){return this._properties.psa4output?.value}set psa4output(A){this.setStringProperty("psa4output",A,MEt)}get mirror(){return this._properties.mirror?.value}set mirror(A){this.setStringProperty("mirror",A,WEt)}get outputformat(){return this._properties.outputformat?.value}set outputformat(A){this.setNumberProperty("outputformat",A,CEt)}get drillshape(){return this._properties.drillshape?.value}set drillshape(A){this.setNumberProperty("drillshape",A,QEt)}get scaleselection(){return this._properties.scaleselection?.value}set scaleselection(A){this.setNumberProperty("scaleselection",A,hEt)}get outputdirectory(){return this._properties.outputdirectory?.value}set outputdirectory(A){this.setStringProperty("outputdirectory",A,ZEt)}};vA.register(LwA);var sz=class extends nT{static parentToken="setup"},UwA=class extends sz{static token="zone_45_only";token="zone_45_only"};vA.register(UwA);var HwA=class extends sz{static token="allow_soldermask_bridges_in_footprints";token="allow_soldermask_bridges_in_footprints"};vA.register(HwA);var YwA=class extends sz{static token="visible_elements";token="visible_elements"};vA.register(YwA);var JwA=class extends sz{static token="uvias_allowed";token="uvias_allowed"};vA.register(JwA);var TwA=class xwt extends vA{static token="tenting";static parentToken="setup";token="tenting";_sides=[];constructor(A=[]){super(),this.sides=A}static fromSexprPrimitives(A){const t=A.map(i=>pi(i)).filter(i=>i!==void 0);return new xwt(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(" ")})`}};vA.register(TwA);var oT=class extends ioi{static parentToken="setup"},zEt=class extends noi{static parentToken="setup"},KwA=class extends oT{static token="pcb_text_size";token="pcb_text_size"};vA.register(KwA);var PwA=class extends oT{static token="mod_text_size";token="mod_text_size"};vA.register(PwA);var qwA=class extends oT{static token="pad_size";token="pad_size"};vA.register(qwA);var OwA=class extends oT{static token="pad_to_paste_clearance_values";token="pad_to_paste_clearance_values"};vA.register(OwA);var WwA=class extends oT{static token="trace_width";token="trace_width"};vA.register(WwA);var ZwA=class extends zEt{static token="aux_axis_origin";token="aux_axis_origin"};vA.register(ZwA);var VwA=class extends zEt{static token="grid_origin";token="grid_origin"};vA.register(VwA);var CB=class extends nT{static parentToken="setup";static parsePrimitiveValue(e){const A=ai(e);if(A===void 0)throw new Error(`${this.name} expects a numeric value`);return A}},jwA=class extends CB{static token="pad_to_mask_clearance";token="pad_to_mask_clearance"};vA.register(jwA);var zwA=class extends CB{static token="solder_mask_min_width";token="solder_mask_min_width"};vA.register(zwA);var XwA=class extends CB{static token="pad_to_paste_clearance";token="pad_to_paste_clearance"};vA.register(XwA);var $wA=class extends CB{static token="pad_to_paste_clearance_ratio";token="pad_to_paste_clearance_ratio"};vA.register($wA);var ADA=class extends CB{static token="last_trace_width";token="last_trace_width"};vA.register(ADA);var tDA=class extends CB{static token="trace_clearance";token="trace_clearance"};vA.register(tDA);var eDA=class extends CB{static token="zone_clearance";token="zone_clearance"};vA.register(eDA);var iDA=class extends CB{static token="trace_min";token="trace_min"};vA.register(iDA);var nDA=class extends CB{static token="segment_width";token="segment_width"};vA.register(nDA);var oDA=class extends CB{static token="edge_width";token="edge_width"};vA.register(oDA);var sDA=class extends CB{static token="via_size";token="via_size"};vA.register(sDA);var rDA=class extends CB{static token="via_drill";token="via_drill"};vA.register(rDA);var aDA=class extends CB{static token="via_min_size";token="via_min_size"};vA.register(aDA);var gDA=class extends CB{static token="via_min_drill";token="via_min_drill"};vA.register(gDA);var cDA=class extends CB{static token="uvia_size";token="uvia_size"};vA.register(cDA);var IDA=class extends CB{static token="uvia_drill";token="uvia_drill"};vA.register(IDA);var lDA=class extends CB{static token="uvia_min_size";token="uvia_min_size"};vA.register(lDA);var BDA=class extends CB{static token="uvia_min_drill";token="uvia_min_drill"};vA.register(BDA);var CDA=class extends CB{static token="pcb_text_width";token="pcb_text_width"};vA.register(CDA);var QDA=class extends CB{static token="mod_edge_width";token="mod_edge_width"};vA.register(QDA);var hDA=class extends CB{static token="mod_text_width";token="mod_text_width"};vA.register(hDA);var EDA=class extends CB{static token="pad_drill";token="pad_drill"};vA.register(EDA);var sT=class extends nT{static parentToken="stackup"},XEt=class extends sT{static token="copper_finish";token="copper_finish";quoteStringValue=!0};vA.register(XEt);var $Et=class extends sT{static token="dielectric_constraints";token="dielectric_constraints"};vA.register($Et);var Aut=class extends sT{static token="edge_connector";token="edge_connector"};vA.register(Aut);var tut=class extends sT{static token="castellated_pads";token="castellated_pads"};vA.register(tut);var eut=class extends sT{static token="edge_plating";token="edge_plating"};vA.register(eut);var H1=class extends nT{static parentToken="layer"},uDA=class extends H1{static token="type";token="type";quoteStringValue=!0};vA.register(uDA);var dDA=class extends H1{static token="color";token="color";quoteStringValue=!0};vA.register(dDA);var pDA=class extends H1{static token="thickness";token="thickness";static parsePrimitiveValue(e){const A=ai(e);if(A===void 0)throw new Error("Stackup layer thickness expects a numeric value");return A}};vA.register(pDA);var fDA=class extends H1{static token="material";token="material";quoteStringValue=!0};vA.register(fDA);var yDA=class extends H1{static token="epsilon_r";token="epsilon_r";static parsePrimitiveValue(e){const A=ai(e);if(A===void 0)throw new Error("Stackup layer epsilon_r expects a numeric value");return A}};vA.register(yDA);var mDA=class extends H1{static token="loss_tangent";token="loss_tangent";static parsePrimitiveValue(e){const A=ai(e);if(A===void 0)throw new Error("Stackup layer loss_tangent expects a numeric value");return A}};vA.register(mDA);var iut=class _wt extends vA{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=pi(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=ai(o);s!==void 0&&(n=s,i+=1);const r=A.slice(i),{propertyMap:a}=vA.parsePrimitivesToClassProperties(r,this.token);return new _wt(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=pi(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=ai(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 uDA?A:new uDA(A)}get color(){return this._sxColor?.value}set color(A){if(A===void 0){this._sxColor=void 0;return}this._sxColor=A instanceof dDA?A:new dDA(A)}get thickness(){return this._sxThickness?.value}set thickness(A){if(A===void 0){this._sxThickness=void 0;return}this._sxThickness=A instanceof pDA?A:new pDA(A)}get material(){return this._sxMaterial?.value}set material(A){if(A===void 0){this._sxMaterial=void 0;return}this._sxMaterial=A instanceof fDA?A:new fDA(A)}get epsilonR(){return this._sxEpsilonR?.value}set epsilonR(A){if(A===void 0){this._sxEpsilonR=void 0;return}this._sxEpsilonR=A instanceof yDA?A:new yDA(A)}get lossTangent(){return this._sxLossTangent?.value}set lossTangent(A){if(A===void 0){this._sxLossTangent=void 0;return}this._sxLossTangent=A instanceof mDA?A:new mDA(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 ${Qn(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(`
5825
5825
  `)}};vA.register(iut);var wDA=class kwt extends vA{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}=vA.parsePrimitivesToClassProperties(A,this.token);return new kwt({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 iut))throw new Error("Stackup layers must be StackupLayer instances");return t})}get copperFinish(){return this._sxCopperFinish?.value}set copperFinish(A){this._sxCopperFinish=A?new XEt(A):void 0}get dielectricConstraints(){return this._sxDielectricConstraints?.value}set dielectricConstraints(A){this._sxDielectricConstraints=A?new $Et(A):void 0}get edgeConnector(){return this._sxEdgeConnector?.value}set edgeConnector(A){this._sxEdgeConnector=A?new Aut(A):void 0}get castellatedPads(){return this._sxCastellatedPads?.value}set castellatedPads(A){this._sxCastellatedPads=A?new tut(A):void 0}get edgePlating(){return this._sxEdgePlating?.value}set edgePlating(A){this._sxEdgePlating=A?new eut(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}};vA.register(wDA);var roi={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"},aoi=["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"],DDA=class Fwt extends vA{static token="setup";token="setup";_properties={};static fromSexprPrimitives(A){const t=new Fwt,{propertyMap:i}=vA.parsePrimitivesToClassProperties(A,this.token);for(const[n,o]of Object.entries(i)){const s=roi[n];if(!s)throw new Error(`Unsupported setup property token: ${n}`);t._properties[s]=o}return t}getChildren(){const A=[];for(const t of aoi){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",wDA)}set stackup(A){if(A!==void 0&&!(A instanceof wDA))throw new Error("stackup must be a Stackup instance");this.setProperty("stackup",A)}get pcbPlotParams(){return this.getPropertyInstance("pcbPlotParams",LwA)}set pcbPlotParams(A){if(A!==void 0&&!(A instanceof LwA))throw new Error("pcbPlotParams must be a PcbPlotParams instance");this.setProperty("pcbPlotParams",A)}get padToMaskClearance(){return this.getPropertyInstance("padToMaskClearance",jwA)?.value}set padToMaskClearance(A){this.setNumberProperty("padToMaskClearance",A,jwA)}get solderMaskMinWidth(){return this.getPropertyInstance("solderMaskMinWidth",zwA)?.value}set solderMaskMinWidth(A){this.setNumberProperty("solderMaskMinWidth",A,zwA)}get padToPasteClearance(){return this.getPropertyInstance("padToPasteClearance",XwA)?.value}set padToPasteClearance(A){this.setNumberProperty("padToPasteClearance",A,XwA)}get padToPasteClearanceRatio(){return this.getPropertyInstance("padToPasteClearanceRatio",$wA)?.value}set padToPasteClearanceRatio(A){this.setNumberProperty("padToPasteClearanceRatio",A,$wA)}get lastTraceWidth(){return this.getPropertyInstance("lastTraceWidth",ADA)?.value}set lastTraceWidth(A){this.setNumberProperty("lastTraceWidth",A,ADA)}get traceClearance(){return this.getPropertyInstance("traceClearance",tDA)?.value}set traceClearance(A){this.setNumberProperty("traceClearance",A,tDA)}get zoneClearance(){return this.getPropertyInstance("zoneClearance",eDA)?.value}set zoneClearance(A){this.setNumberProperty("zoneClearance",A,eDA)}get zone45Only(){return this.getPropertyInstance("zone45Only",UwA)?.value}set zone45Only(A){this.setProperty("zone45Only",A===void 0?void 0:new UwA(A))}get traceMin(){return this.getPropertyInstance("traceMin",iDA)?.value}set traceMin(A){this.setNumberProperty("traceMin",A,iDA)}get segmentWidth(){return this.getPropertyInstance("segmentWidth",nDA)?.value}set segmentWidth(A){this.setNumberProperty("segmentWidth",A,nDA)}get edgeWidth(){return this.getPropertyInstance("edgeWidth",oDA)?.value}set edgeWidth(A){this.setNumberProperty("edgeWidth",A,oDA)}get viaSize(){return this.getPropertyInstance("viaSize",sDA)?.value}set viaSize(A){this.setNumberProperty("viaSize",A,sDA)}get viaDrill(){return this.getPropertyInstance("viaDrill",rDA)?.value}set viaDrill(A){this.setNumberProperty("viaDrill",A,rDA)}get viaMinSize(){return this.getPropertyInstance("viaMinSize",aDA)?.value}set viaMinSize(A){this.setNumberProperty("viaMinSize",A,aDA)}get viaMinDrill(){return this.getPropertyInstance("viaMinDrill",gDA)?.value}set viaMinDrill(A){this.setNumberProperty("viaMinDrill",A,gDA)}get uviasAllowed(){return this.getPropertyInstance("uviasAllowed",JwA)?.value}set uviasAllowed(A){this.setProperty("uviasAllowed",A===void 0?void 0:new JwA(A))}get uviaSize(){return this.getPropertyInstance("uviaSize",cDA)?.value}set uviaSize(A){this.setNumberProperty("uviaSize",A,cDA)}get uviaDrill(){return this.getPropertyInstance("uviaDrill",IDA)?.value}set uviaDrill(A){this.setNumberProperty("uviaDrill",A,IDA)}get uviaMinSize(){return this.getPropertyInstance("uviaMinSize",lDA)?.value}set uviaMinSize(A){this.setNumberProperty("uviaMinSize",A,lDA)}get uviaMinDrill(){return this.getPropertyInstance("uviaMinDrill",BDA)?.value}set uviaMinDrill(A){this.setNumberProperty("uviaMinDrill",A,BDA)}get pcbTextWidth(){return this.getPropertyInstance("pcbTextWidth",CDA)?.value}set pcbTextWidth(A){this.setNumberProperty("pcbTextWidth",A,CDA)}get pcbTextSize(){return this.getPropertyInstance("pcbTextSize",KwA)?.values}set pcbTextSize(A){if(A===void 0){delete this._properties.pcbTextSize;return}this.setProperty("pcbTextSize",new KwA(A))}get modEdgeWidth(){return this.getPropertyInstance("modEdgeWidth",QDA)?.value}set modEdgeWidth(A){this.setNumberProperty("modEdgeWidth",A,QDA)}get modTextSize(){return this.getPropertyInstance("modTextSize",PwA)?.values}set modTextSize(A){if(A===void 0){delete this._properties.modTextSize;return}this.setProperty("modTextSize",new PwA(A))}get modTextWidth(){return this.getPropertyInstance("modTextWidth",hDA)?.value}set modTextWidth(A){this.setNumberProperty("modTextWidth",A,hDA)}get padSize(){return this.getPropertyInstance("padSize",qwA)?.values}set padSize(A){if(A===void 0){delete this._properties.padSize;return}this.setProperty("padSize",new qwA(A))}get padDrill(){return this.getPropertyInstance("padDrill",EDA)?.value}set padDrill(A){this.setNumberProperty("padDrill",A,EDA)}get allowSoldermaskBridgesInFootprints(){return this.getPropertyInstance("allowSoldermaskBridgesInFootprints",HwA)?.value}set allowSoldermaskBridgesInFootprints(A){this.setProperty("allowSoldermaskBridgesInFootprints",A===void 0?void 0:new HwA(A))}get tenting(){return this.getPropertyInstance("tenting",TwA)?.sides}set tenting(A){if(A===void 0){delete this._properties.tenting;return}this.setProperty("tenting",new TwA(A))}get auxAxisOrigin(){const A=this.getPropertyInstance("auxAxisOrigin",ZwA);if(A)return{x:A.x,y:A.y}}set auxAxisOrigin(A){if(!A){delete this._properties.auxAxisOrigin;return}this.setProperty("auxAxisOrigin",new ZwA(A.x,A.y))}get gridOrigin(){const A=this.getPropertyInstance("gridOrigin",VwA);if(A)return{x:A.x,y:A.y}}set gridOrigin(A){if(!A){delete this._properties.gridOrigin;return}this.setProperty("gridOrigin",new VwA(A.x,A.y))}get visibleElements(){return this.getPropertyInstance("visibleElements",YwA)?.value}set visibleElements(A){this.setProperty("visibleElements",A===void 0?void 0:new YwA(A))}get padToPasteClearanceValues(){return this.getPropertyInstance("padToPasteClearanceValues",OwA)?.values}set padToPasteClearanceValues(A){if(A===void 0){delete this._properties.padToPasteClearanceValues;return}this.setProperty("padToPasteClearanceValues",new OwA(A))}get traceWidth(){return this.getPropertyInstance("traceWidth",WwA)?.values}set traceWidth(A){if(A===void 0){delete this._properties.traceWidth;return}this.setProperty("traceWidth",new WwA(A))}};vA.register(DDA);var nut=class extends ga{static token="thickness";static parentToken="general";token="thickness"};vA.register(nut);var out=class Gwt extends vA{static token="legacy_teardrops";static parentToken="general";token="legacy_teardrops";_enabled;constructor(A){super(),this._enabled=A}static fromSexprPrimitives(A){const t=pi(A[0]);if(t===void 0)throw new Error("legacy_teardrops expects a string value");const i=/^(yes|true)$/iu.test(t);return new Gwt(i)}get enabled(){return this._enabled}set enabled(A){this._enabled=A}getChildren(){return[]}getString(){return`(legacy_teardrops ${this._enabled?"yes":"no"})`}};vA.register(out);var sut=new Set(["thickness","legacy_teardrops"]),SDA=class Rwt extends vA{static token="general";static parentToken="kicad_pcb";token="general";_sxThickness;_sxLegacyTeardrops;static fromSexprPrimitives(A){const t=new Rwt,{propertyMap:i,arrayPropertyMap:n}=vA.parsePrimitivesToClassProperties(A,this.token);for(const o of Object.keys(i))if(!sut.has(o))throw new Error(`general encountered unsupported child token "${o}"`);for(const[o,s]of Object.entries(n)){if(!sut.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 nut(A)}get legacyTeardrops(){return this._sxLegacyTeardrops?.enabled}set legacyTeardrops(A){if(A===void 0){this._sxLegacyTeardrops=void 0;return}this._sxLegacyTeardrops=new out(A)}getChildren(){const A=[];return this._sxThickness&&A.push(this._sxThickness),this._sxLegacyTeardrops&&A.push(this._sxLegacyTeardrops),A}};vA.register(SDA);var Ll=class Mwt extends vA{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=ai(t),r=pi(i),a=pi(n),g=o===void 0?void 0:pi(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 Mwt({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),Qn(this._name),this._type];return this._userName!==void 0&&A.push(Qn(this._userName)),`(${A.join(" ")})`}};vA.register(Ll);var bDA=class Nwt extends vA{static token="layers";static parentToken="kicad_pcb";token="layers";_definitions=[];static fromSexprPrimitives(A){const t=new Nwt;return t._definitions=A.map(i=>Ll.fromPrimitive(i)),t}get definitions(){return[...this._definitions]}set definitions(A){this._definitions=[...A]}getChildren(){return[...this._definitions]}};vA.register(bDA);var rz=class vwt extends vA{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=ai(A[0]),i=pi(A[1]);if(t===void 0||i===void 0)throw new Error("net requires numeric id and string name");return new vwt(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} ${Qn(this._name)})`}};vA.register(rz);var xDA=class extends ga{static token="version";static parentToken="kicad_pcb";token="version"};vA.register(xDA);var goi=e=>/^[A-Za-z0-9._-]+$/.test(e),_DA=class extends sm{static token="generator";static parentToken="kicad_pcb";token="generator";getString(){return`(generator ${goi(this.value)?this.value:Qn(this.value)})`}};vA.register(_DA);var coi=e=>/^[A-Za-z0-9._-]+$/.test(e),kDA=class extends sm{static token="generator_version";static parentToken="kicad_pcb";token="generator_version";getString(){return`(generator_version ${coi(this.value)?this.value:Qn(this.value)})`}};vA.register(kDA);var FDA=class Lwt extends vA{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=ai(A[0]);if(t===void 0)throw new Error("via net requires a numeric id");const i=A.length>1?pi(A[1]):void 0;return new Lwt(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} ${Qn(this._name)})`:`(net ${this._id})`}};vA.register(FDA);var Ioi=new Set(["locked","free","remove_unused_layers","keep_end_layers"]),GDA=class Uwt extends vA{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 Uwt;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(!Ioi.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=pi(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=vA.parsePrimitiveSexpr(["at",...t],{parentToken:this.token});if(!(i instanceof Ac))throw new Error("via failed to parse at child");this._sxAt=i;return}case"size":{const i=ai(t[0]);if(i===void 0)throw new Error("via size expects a numeric value");this._size=i;return}case"drill":{const i=ai(t[0]);if(i===void 0)throw new Error("via drill expects a numeric value");this._drill=i;return}case"layers":{this._sxLayers=oz.fromSexprPrimitives(t);return}case"net":{this._sxNet=FDA.fromSexprPrimitives(t);return}case"teardrops":{this._sxTeardrops=_ht.fromSexprPrimitives(t);return}case"uuid":{const i=pi(t[0]);if(i===void 0)throw new Error("via uuid expects a string value");this._sxUuid=new Li(i);return}case"tstamp":{const i=pi(t[0]);if(i===void 0)throw new Error("via tstamp expects a string value");this._sxTstamp=new tc(i);return}default:throw new Error(`via encountered unsupported child token "${A}"`)}}parseYesNo(A){if(A.length===0)return!0;const t=pi(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?Ac.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 oz?A:new oz(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 Li?A:new Li(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 tc?A:new tc(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(`
5826
- `)}};vA.register(GDA);var RDA=class Hwt extends vA{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 Hwt;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=vA.parsePrimitiveSexpr(i,{parentToken:this.token});if(!(n instanceof vA))throw new Error(`kicad_pcb expected SxClass child, received ${JSON.stringify(i)}`);t.consumeChild(n)}return t}consumeChild(A){if(A instanceof xDA){this._sxVersion=A;return}if(A instanceof _DA){this._sxGenerator=A;return}if(A instanceof kDA){this._sxGeneratorVersion=A;return}if(A instanceof SDA){this._sxGeneral=A;return}if(A instanceof Kj){this._sxPaper=A;return}if(A instanceof iQt){this._sxTitleBlock=A;return}if(A instanceof bDA){this._sxLayers=A;return}if(A instanceof DDA){this._sxSetup=A;return}if(A instanceof v1){this._properties.push(A);return}if(A instanceof rz){this._nets.push(A);return}if(A instanceof mwA){this._footprints.push(A);return}if(A instanceof oQt){this._images.push(A);return}if(A instanceof vwA){this._segments.push(A);return}if(A instanceof ez){this._grLines.push(A);return}if(A instanceof iz){this._grTexts.push(A);return}if(A instanceof jht){this._grPolys.push(A);return}if(A instanceof Wht){this._grRects.push(A);return}if(A instanceof GDA){this._vias.push(A);return}if(A instanceof eEt){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 xDA(A)}get generator(){return this._sxGenerator?.value}set generator(A){this._sxGenerator=A===void 0?void 0:new _DA(A)}get generatorVersion(){return this._sxGeneratorVersion?.value}set generatorVersion(A){this._sxGeneratorVersion=A===void 0?void 0:new kDA(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}};vA.register(RDA);var rut=e=>vA.parse(e),JE=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")}},loi=class extends JE{_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 Kj;t.size=A?.name??"A4",e.paper=t,e.uuid=new Li(crypto.randomUUID()),this.finished=!0}getOutput(){return this.ctx.kicadSch}};function WG(e,A){if(e.manufacturer_part_number)return MDA(e.manufacturer_part_number);const t=Boi(e.ftype),i=A?.footprinter_string;return MDA(i?`${t}_${i}`:t)}function Boi(e){if(!e)return"component";let A=e.replace(/^simple_/,"");return A||"component"}function MDA(e){return e.replace(/[\\\/:\s]+/g,"_").replace(/_+/g,"_").replace(/^_|_$/g,"").trim()||"component"}function aut(e){return e?e.match(/^([A-Za-z]+)/)?.[1]?.toUpperCase()??"U":"U"}var gut={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"},Coi=/^[A-Za-z]+\d+$/;function cut(e){return e?Coi.test(e.trim()):!1}function az(e){const A=e?.ftype;if(A&&gut[A])return gut[A];const t=e?.name;return cut(t),aut(t)}function Qoi(e){const A=e?.name;return cut(A)?A.trim():`${az(e)}?`}function Iut(e){return e in SQ}function lut(e,A,t,i){if(i)return`Custom:${i}`;if(e.type!=="source_component")return A.symbol_name?Iut(A.symbol_name)?`Device:${A.symbol_name}`:`Custom:${A.symbol_name}`:"Device:Component";if(A.symbol_name)return Iut(A.symbol_name)?`Device:${A.symbol_name}`:`Custom:${A.symbol_name}`;const n=WG(e,t);return`Device:${az(e)}_${n}`}var hoi=class extends JE{processedSymbolNames=new Set;_step(){const{kicadSch:e,db:A}=this.ctx,t=new xQt,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=lut(t,e,i),a=t.ftype==="simple_chip",g=WG(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:az(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=WG(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=this.buildSymbolDataFromSchematicPrimitives(i,o,e.schematic_component_id),g=WG(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),footprintRef:g?`tscircuit:${g}`:"",referencePrefix:az(A)})}buildSymbolDataFromSchematicPrimitives(e,A,t){const{circuitJson:i}=this.ctx,n=i.filter(c=>c.type==="schematic_circle"&&c.schematic_symbol_id===e),o=i.filter(c=>c.type==="schematic_line"&&c.schematic_symbol_id===e),s=i.filter(c=>c.type==="schematic_path"&&c.schematic_symbol_id===e);let r=i.filter(c=>c.type==="schematic_port"&&"schematic_symbol_id"in c&&c.schematic_symbol_id===e);if(r.length===0&&t&&(r=i.filter(c=>c.type==="schematic_port"&&c.schematic_component_id===t&&c.display_pin_label!==void 0),r.length===0)){const c=i.filter(l=>l.type==="schematic_port"&&l.schematic_component_id===t),I=new Set;r=c.filter(l=>{const B=l.pin_number;if(B!==void 0){if(I.has(B))return!1;I.add(B)}return!0})}const a=[];for(const c of n)a.push({type:"circle",x:c.center?.x??0,y:c.center?.y??0,radius:c.radius??.5,fill:c.is_filled??!1,fillColor:c.fill_color});for(const c of o)a.push({type:"path",points:[{x:c.x1??0,y:c.y1??0},{x:c.x2??0,y:c.y2??0}]});for(const c of s)c.points&&c.points.length>0&&a.push({type:"path",points:c.points,fill:c.is_filled??!1,fillColor:c.fill_color});const g=r.map((c,I)=>({x:c.center?.x??0,y:c.center?.y??0,labels:[c.display_pin_label||`${c.pin_number||I+1}`],pinNumber:c.pin_number||I+1,facingDirection:c.facing_direction}));return g.sort((c,I)=>c.pinNumber-I.pinNumber),{center:A.center||{x:0,y:0},size:A.size||{width:1,height:1},primitives:a,ports:g}}createLibrarySymbolForNetLabel({netLabel:e,isPower:A,isGround:t}){const i=e.symbol_name;if(!i)return null;const n=SQ[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_")?this.createGenericChipSymbolData(A,this.ctx.db):SQ[e]||null}createGenericChipSymbolData(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}}}createLibrarySymbol({libId:e,symbolData:A,isChip:t,schematicComponent:i,description:n,keywords:o,fpFilters:s,footprintRef:r="",referencePrefix:a}){const g=new N1({libraryId:e,excludeFromSim:!1,inBom:!0,onBoard:!0}),c=new cQt;c.hide=!t,g._sxPinNumbers=c;const I=new IQt;I.offset=t?1.27:0,g._sxPinNames=I,this.addSymbolProperties({symbol:g,libId:e,description:n,keywords:o,fpFilters:s,footprintRef:r,referencePrefix:a});const l=this.createDrawingSubsymbol({libId:e,symbolData:A,isChip:t});g.subSymbols.push(l);const B=this.createPinSubsymbol({libId:e,symbolData:A,isChip:t,schematicComponent:i});return g.subSymbols.push(B),g._sxEmbeddedFonts=new qj(!1),g}addSymbolProperties({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 gm({key:g.key,value:g.value,id:g.id,at:g.at,effects:this.createTextEffects(1.27,g.hide)}))}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){return e?.ftype==="simple_resistor"?"R_*":e?.ftype==="simple_capacitor"?"C_*":(e?.ftype==="simple_chip","*")}createDrawingSubsymbol({libId:e,symbolData:A,isChip:t}){const i=new N1({libraryId:`${e.split(":")[1]}_0_1`}),n=15.24,o=this.ctx.c2kMatSch?.a||15,s=t?o:n;for(const r of A.primitives||[])if(r.type==="path"&&r.points){const a=t||r.fill?"background":"none",g=this.createPolylineFromPoints({points:r.points,scale:s,center:A.center,fillType:a});i.polylines.push(g)}else if(r.type==="circle"){const a=this.createCircleFromPrimitive({primitive:r,scale:s,center:A.center});i.circles.push(a)}return i}createPolylineFromPoints({points:e,scale:A,center:t,fillType:i}){const n=new rQt,o=t?.x??0,s=t?.y??0,r=mh(A,A),a=e.map(l=>{const B=Pe(r,{x:l.x-o,y:l.y-s});return new KQ(B.x,B.y)}),g=new OC(a);n.points=g;const c=new AS;c.width=.254,c.type="default",n.stroke=c;const I=new hQt;return I.type=i,n.fill=I,n}createCircleFromPrimitive({primitive:e,scale:A,center:t}){const i=new dQt,n=t?.x??0,o=t?.y??0,s=mh(A,A),r=Pe(s,{x:e.x-n,y:e.y-o}),a=i;a._sxCenter=new CQt(r.x,r.y),a._sxRadius=new QQt(e.radius*A);const g=new AS;g.width=.254,g.type="default",a._sxStroke=g;const c=new EQt;return c.type=e.fill?"background":"none",a._sxFill=c,i}createPinSubsymbol({libId:e,symbolData:A,isChip:t,schematicComponent:i}){const n=new N1({libraryId:`${e.split(":")[1]}_1_1`});for(let o=0;o<(A.ports?.length||0);o++){const s=A.ports[o],r=new Zj;r.pinElectricalType="passive",r.pinGraphicStyle="line";const{x:a,y:g,angle:c}=this.calculatePinPosition(s,A.center,A.size,t,o,i);r.at=[a,g,c];const I=6,l=2.54;r.length=t?I:l;const B=new am;B.size={height:1.27,width:1.27};const C=new rm({font:B}),Q=s.labels?.[0]||"~";r._sxName=new BmA({value:Q,effects:C});const h=new am;h.size={height:1.27,width:1.27};const E=new rm({font:h}),u=s.pinNumber?.toString()||`${o+1}`;r._sxNumber=new fQt({value:u,effects:E}),n.pins.push(r)}return n}calculatePinPosition(e,A,t,i,n,o){const r=this.ctx.c2kMatSch?.a||15,a=i?r:15.24;let g=e.x??0,c=e.y??0,I=!1;if(i&&n!==void 0&&o){const m=this.ctx.db.schematic_port.list().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=mh(a,a),Q=Pe(C,{x:l,y:B});let h;if(i&&t){const m=t.width/2,w=t.height/2,D=Math.abs(l)/m,S=Math.abs(B)/w;h=D>S}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 p=0;return h?l>0?(p=180,i&&(E=E+d)):(p=0,i&&(E=E-d)):B>0?(p=270,i&&(u=u+d)):(p=90,i&&(u=u-d)),{x:E,y:u,angle:p}}createTextEffects(e,A){const t=new am;return t.size={height:e,width:e},new rm({font:t,hiddenText:A})}getOutput(){if(!this.ctx.kicadSch)throw new Error("kicadSch is not initialized");return this.ctx.kicadSch}},Eoi=class extends JE{_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}=Pe(this.ctx.c2kMatSch,{x:n.center.x,y:n.center.y}),a=crypto.randomUUID(),g=new N1({at:[s,r,0],unit:1,excludeFromSim:!1,inBom:!0,onBoard:!0,dnp:!1,uuid:a,fieldsAutoplaced:!0}),c=A.cad_component?.list()?.find(Y=>Y.source_component_id===o.source_component_id);let I,l=n.schematic_symbol_id;if(!l){const Y=this.ctx.circuitJson.find(H=>(H.type==="schematic_line"||H.type==="schematic_circle"||H.type==="schematic_path")&&H.schematic_component_id===n.schematic_component_id&&H.schematic_symbol_id);Y&&(l=Y.schematic_symbol_id)}if(l){const Y=this.ctx.circuitJson.find(H=>H.type==="schematic_symbol"&&H.schematic_symbol_id===l);if(Y?.name)I=Y.name;else{const H=WG(o,c);H?I=H:I=`custom_${o.ftype||"component"}_${l}`}}const B=lut(o,n,c,I),C=new cmA(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}),p=new gm({key:"Reference",value:Q,id:0,at:[u.x,u.y,0],effects:this.createTextEffects(1.27,!1)}),m=o.ftype==="simple_chip",w=new gm({key:"Value",value:h,id:1,at:[d.x,d.y,0],effects:this.createTextEffects(1.27,m)}),D=new gm({key:"Footprint",value:"",id:2,at:[s-1.778,r,90],effects:this.createTextEffects(1.27,!0)}),S=new gm({key:"Datasheet",value:"~",id:3,at:[s,r,0],effects:this.createTextEffects(1.27,!0)}),k=new gm({key:"Description",value:E,id:4,at:[s,r,0],effects:this.createTextEffects(1.27,!0)});g.properties.push(p,w,D,S,k);let x=A.schematic_port.list().filter(Y=>Y.schematic_component_id===n.schematic_component_id);if(l){const Y=x.filter(H=>H.display_pin_label);Y.length>0&&(x=Y)}x.sort((Y,H)=>(Y.pin_number||0)-(H.pin_number||0));for(let Y=0;Y<x.length;Y++){const H=x[Y];if(!H)continue;const O=new Zj;O.numberString=`${H.pin_number||Y+1}`,O.uuid=crypto.randomUUID(),g.pins.push(O)}const N=new CmA,M=new hmA(""),L=new EmA(`/${e?.uuid?.value||""}`);L.reference=Q,L.unit=1,M.paths.push(L),N.projects.push(M),g._sxInstances=N,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=Pe(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=SQ[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?Pe(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?Pe(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=Qoi(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"}:{reference:t,value:A,description:"Component"}}createTextEffects(e,A=!1,t){const i=new am;i.size={height:e,width:e};const n=t?new $J({horizontal:t}):void 0;return new rm({font:i,hiddenText:A,justify:n})}getOutput(){if(!this.ctx.kicadSch)throw new Error("kicadSch is not initialized");return this.ctx.kicadSch}},uoi=class extends JE{_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}=Pe(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 N1({at:[i,n,0],unit:1,excludeFromSim:!1,inBom:!0,onBoard:!0,dnp:!1,uuid:o,fieldsAutoplaced:!0}),r=`Custom:${t}`,a=new cmA(r);s._sxLibId=a;const g=t.includes("_up")||t.toLowerCase().includes("vcc"),c=g?-4:4,I=g?-6:6,l=new gm({key:"Reference",value:A,id:0,at:[i,n+c,0],effects:this.createTextEffects(1.27,!1)}),B=new gm({key:"Value",value:A,id:1,at:[i,n+I,0],effects:this.createTextEffects(1.27,!0)}),C=new gm({key:"Footprint",value:"",id:2,at:[i-1.778,n,90],effects:this.createTextEffects(1.27,!0)}),Q=new gm({key:"Datasheet",value:"~",id:3,at:[i,n,0],effects:this.createTextEffects(1.27,!0)}),h=new gm({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 Zj;E.numberString="1",E.uuid=crypto.randomUUID(),s.pins.push(E);const{kicadSch:u}=this.ctx,d=new CmA,p=new hmA(""),m=new EmA(`/${u?.uuid?.value||""}`);return m.reference=A,m.unit=1,p.paths.push(m),d.projects.push(p),s._sxInstances=d,s}createGlobalLabel(e,A){if(!this.ctx.c2kMatSch||!this.ctx.kicadSch)return null;const{x:t,y:i}=Pe(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 $J(a)),new LQt({value:A,at:[t,i,s],effects:g,uuid:crypto.randomUUID(),fieldsAutoplaced:!0})}createTextEffects(e,A=!1){const t=new am;return t.size={height:e,width:e},new rm({font:t,hiddenText:A})}getOutput(){if(!this.ctx.kicadSch)throw new Error("kicadSch is not initialized");return this.ctx.kicadSch}},doi=class extends JE{_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 kQt;if(!this.ctx.c2kMatSch)throw new Error("Schematic transformation matrix not initialized in context");const t=Pe(this.ctx.c2kMatSch,{x:e.from.x,y:e.from.y}),i=Pe(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 OC([new KQ(n,o),new KQ(s,r)]);A.points=a;const g=new AS;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}=Pe(this.ctx.c2kMatSch,{x:e.x,y:e.y}),i=new FQt({at:[A,t],diameter:0});return i.uuid=crypto.randomUUID(),i}getOutput(){return this.ctx.kicadSch}},poi=class extends JE{_step(){const{kicadSch:e}=this.ctx;if(!e)throw new Error("KicadSch instance not initialized in context");const A=new fmA,t=new YQt;t.value="/";const i=new JQt("1");t.pages=[i],A.paths=[t],e.sheetInstances=A,e.embeddedFonts=new qj(!1),this.finished=!0}getOutput(){return this.ctx.kicadSch}};function foi(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 gz=[{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 yoi(e,A,t=20){const i=e+2*t,n=A+2*t;for(let o=0;o<gz.length;o++){const s=gz[o];if(i<=s.width&&n<=s.height)return s}return gz[gz.length-1]}var But=class{ctx;pipeline;currentStageIndex=0;finished=!1;get currentStage(){return this.pipeline[this.currentStageIndex]}constructor(e){const t=Fa(e),{center:i,bounds:n}=foi(t),o=(n.maxX-n.minX)*15,s=(n.maxY-n.minY)*15,r=yoi(o,s),a=r.width/2,g=r.height/2;this.ctx={db:t,circuitJson:e,kicadSch:new mmA({generator:"circuit-json-to-kicad",generatorVersion:"0.0.1"}),schematicPaperSize:r,c2kMatSch:rB(hr(a,g),mh(15,-15),hr(-i.x,-i.y))},this.pipeline=[new loi(e,this.ctx),new hoi(e,this.ctx),new Eoi(e,this.ctx),new uoi(e,this.ctx),new doi(e,this.ctx),new poi(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()}},moi=class extends JE{_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 Kj;n.size="A4",e.paper=n;const o=new SDA;o.thickness=1.6,e.general=o;const s=new DDA;s.padToMaskClearance=0,e.setup=s;const r=new bDA,a=[new Ll({index:0,name:"F.Cu",type:"signal"})];for(let g=1;g<i-1;g++)a.push(new Ll({index:g,name:`In${g}.Cu`,type:"signal"}));a.push(new Ll({index:31,name:"B.Cu",type:"signal"})),a.push(new Ll({index:32,name:"B.Adhes",type:"user"}),new Ll({index:33,name:"F.Adhes",type:"user"}),new Ll({index:34,name:"B.Paste",type:"user"}),new Ll({index:35,name:"F.Paste",type:"user"}),new Ll({index:36,name:"B.SilkS",type:"user"}),new Ll({index:37,name:"F.SilkS",type:"user"}),new Ll({index:38,name:"B.Mask",type:"user"}),new Ll({index:39,name:"F.Mask",type:"user"}),new Ll({index:40,name:"Dwgs.User",type:"user"}),new Ll({index:41,name:"Cmts.User",type:"user"}),new Ll({index:42,name:"Eco1.User",type:"user"}),new Ll({index:43,name:"Eco2.User",type:"user"}),new Ll({index:44,name:"Edge.Cuts",type:"user"}),new Ll({index:45,name:"Margin",type:"user"}),new Ll({index:46,name:"B.CrtYd",type:"user"}),new Ll({index:47,name:"F.CrtYd",type:"user"}),new Ll({index:48,name:"B.Fab",type:"user"}),new Ll({index:49,name:"F.Fab",type:"user"})),r.definitions=a,e.layers=r,this.finished=!0}getOutput(){return this.ctx.kicadPcb}},woi=class extends JE{_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 rz(0,""));let s=1;for(const[r,a]of n){const g=new rz(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 Doi(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 eS(e){const A=Doi(e);return`${A.slice(0,8)}-${A.slice(8,12)}-${A.slice(12,16)}-${A.slice(16,20)}-${A.slice(20,32)}`}function Soi(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 swA({center:{x:n,y:o},end:{x:n+i.radius,y:o},layer:r,stroke:new AS,fill:!1});a.stroke&&(a.stroke.width=i.stroke_width||.05,a.stroke.type="default"),t.push(a)}return t}function boi(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 swA({center:{x:n,y:o},end:{x:n+i.radius,y:o},layer:r,stroke:new AS,fill:!1});a.stroke&&(a.stroke.width=.05,a.stroke.type="default"),t.push(a)}return t}function xoi(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 Xj({start:{x:n-s,y:o-r},end:{x:n+s,y:o+r},layer:g,stroke:new AS,fill:!1});c.stroke&&(c.stroke.width=i.stroke_width||.1,c.stroke.type="default"),t.push(c)}return t}function _oi(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 Xj({start:{x:n-s,y:o-r},end:{x:n+s,y:o+r},layer:a,stroke:new AS,fill:!1});g.stroke&&(g.stroke.width=i.stroke_width||.1,g.stroke.type="default"),t.push(g)}return t}function koi(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 Xj({start:{x:n-s,y:o-r},end:{x:n+s,y:o+r},layer:g,stroke:new AS,fill:!1});c.stroke&&(c.stroke.width=.05,c.stroke.type="default"),t.push(c)}return t}function Foi(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 KQ(c,I)}),r=new Mht;r.points=new OC(s),r.layer=o,r.fill=!1;const a=new AS;a.width=.05,a.type="default",r.stroke=a,t.push(r)}return t}function Goi({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?Lm(t*Math.PI/180):vu(),s=Pe(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 am;I.size={width:c,height:c};const l=new rm({font:I}),B=e.ccw_rotation||0;return new jmA({type:"user",text:e.text,position:{x:r.x,y:r.y,angle:B},layer:g,effects:l})}function Roi(e,A,t,i){const n=[];for(const o of e){const s=Goi({textElement:o,componentCenter:A,componentRotation:t});s&&(i&&o.text===i&&(s.type="reference"),n.push(s))}return n}function Moi(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?Lm(t*Math.PI/180):vu(),a=Pe(r,{x:o,y:s}),g=n.font_size||1,c=new am;c.size={width:g,height:g};const I=new rm({font:c}),l=new jmA({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 Noi(e,A){const t=[],i=e.model_step_url||e.model_wrl_url;if(!i)return t;const n=new pwA(i);if(e.position&&(n.offset={x:(e.position.x||0)-A.x,y:-((e.position.y||0)-A.y),z:e.position.z||0}),e.rotation&&(n.rotate={x:e.rotation.x||0,y:e.rotation.y||0,z:e.rotation.z||0}),e.model_unit_to_mm_scale_factor){const o=e.model_unit_to_mm_scale_factor;n.scale={x:o,y:o,z:o}}return t.push(n),t}function voi({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,p)=>d+p.x,0)/u.length,r=u.reduce((d,p)=>d+p.y,0)/u.length}else throw new Error("Pad must have either x/y coordinates or points array");const a=rB(i!==0?Lm(i*Math.PI/180):{a:1,b:0,c:0,d:1,e:0,f:0},mh(1,-1),hr(-A.x,-A.y)),g=Pe(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=rB(mh(1,-1),hr(-s,-r)),p=u.map(w=>{const D=Pe(d,{x:w.x,y:w.y});return new KQ(D.x,D.y)}),m=new qmA;m.contours=[new OC(p)],m.width=0,m.filled=!0,Q=new Eht,Q.addGraphic(m),l="custom",C=new Aht,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 zj({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:eS(h)});return C&&(E.options=C),Q&&(E.primitives=Q),n&&(E.net=new HmA(n.id,n.name)),E}function Loi(e,A,t,i,n,o){const s=[];let r=n;for(const a of e){const g=o(a.pcb_port_id),c=voi({pcbPad:a,componentCenter:A,padNumber:r,componentRotation:t,netInfo:g,componentId:i});s.push(c),r++}return{pads:s,nextPadNumber:r}}function Uoi({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?Lm(i*Math.PI/180):vu(),g=Pe(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=Pe(a,{x:-u.x,y:u.y}))}e.shape==="circle"?(c="circle",I=[e.outer_diameter,e.outer_diameter],l=new tS({diameter:e.hole_diameter,offset:Q})):e.shape==="pill"||e.shape==="oval"?(c="oval",I=[e.outer_width,e.outer_height],l=new tS({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 tS({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 tS({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 tS({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 tS({diameter:.8,offset:Q}));const h=`thruhole:${o}:${t}:${g.x},${g.y}`,E=new zj({number:String(t),padType:"thru_hole",shape:c,at:[g.x,g.y,B],size:I,drill:l,layers:["*.Cu","*.Mask"],removeUnusedLayers:!1,uuid:eS(h)});return n&&(E.net=new HmA(n.id,n.name)),E}function Hoi(e,A,t,i,n,o){const s=[];let r=n;for(const a of e){const g=o(a.pcb_port_id),c=Uoi({platedHole:a,componentCenter:A,padNumber:r,componentRotation:t,netInfo:g,componentId:i});c&&(s.push(c),r++)}return{pads:s,nextPadNumber:r}}function Yoi({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?Lm(t*Math.PI/180):vu(),s=Pe(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 tS({diameter:c})}else if(e.hole_shape==="oval"){r="oval";const c=e.hole_width,I=e.hole_height;a=[c,I],g=new tS({oval:!0,diameter:c,width:I})}else{r="circle";const c="hole_diameter"in e?e.hole_diameter:1;a=[c,c],g=new tS({diameter:c})}return new zj({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 Joi(e,A,t){const i=[];for(const n of e){const o=Yoi({pcbHole:n,componentCenter:A,componentRotation:t});o&&i.push(o)}return i}var Toi=class extends JE{componentsProcessed=0;pcbComponents=[];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){super(e,A),this.pcbComponents=this.ctx.db.pcb_component.list()}_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?WG(i,n):"Unknown",s=Pe(A,{x:t.center.x,y:t.center.y}),r=`footprint:${t.pcb_component_id}:${s.x},${s.y}`,a=new mwA({libraryLink:`tscircuit:${o}`,layer:"F.Cu",at:[s.x,s.y,t.rotation||0],uuid:eS(r)}),g=a.fpTexts,c=this.ctx.db.pcb_silkscreen_text?.list().filter(H=>H.pcb_component_id===t.pcb_component_id)||[];g.push(...Roi(c,t.center,t.rotation||0,i?.name));const I=this.ctx.db.pcb_note_text?.list().filter(H=>H.pcb_component_id===t.pcb_component_id)||[];g.push(...Moi(I,t.center,t.rotation||0)),a.fpTexts=g;const l=a.fpPads,B=H=>this.getNetInfoForPcbPort(H),C=this.ctx.db.pcb_smtpad?.list().filter(H=>H.pcb_component_id===t.pcb_component_id)||[],{pads:Q,nextPadNumber:h}=Loi(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(H=>H.pcb_component_id===t.pcb_component_id)||[],{pads:u}=Hoi(E,t.center,t.rotation||0,t.pcb_component_id,h,B);l.push(...u);const d=this.ctx.db.pcb_hole?.list().filter(H=>H.subcircuit_id===t.subcircuit_id)||[],p=Joi(d,t.center,t.rotation||0);l.push(...p),a.fpPads=l;const m=this.ctx.db.pcb_silkscreen_circle?.list().filter(H=>H.pcb_component_id===t.pcb_component_id)||[],w=a.fpCircles??[];w.push(...Soi(m,t.center));const D=this.ctx.db.pcb_courtyard_circle?.list().filter(H=>H.pcb_component_id===t.pcb_component_id)||[];w.push(...boi(D,t.center)),a.fpCircles=w;const S=this.ctx.db.pcb_fabrication_note_rect?.list().filter(H=>H.pcb_component_id===t.pcb_component_id)||[],k=a.fpRects??[];k.push(...xoi(S,t.center));const x=this.ctx.db.pcb_note_rect?.list().filter(H=>H.pcb_component_id===t.pcb_component_id)||[];k.push(..._oi(x,t.center));const N=this.ctx.db.pcb_courtyard_rect?.list().filter(H=>H.pcb_component_id===t.pcb_component_id)||[];k.push(...koi(N,t.center)),a.fpRects=k;const M=this.ctx.db.pcb_courtyard_outline?.list().filter(H=>H.pcb_component_id===t.pcb_component_id)||[],L=Foi(M,t.center);if(L.length>0&&(a.fpPolys=L),n){const H=Noi(n,t.center);H.length>0&&(a.models=H)}const Y=e.footprints;Y.push(a),e.footprints=Y,this.componentsProcessed++}getOutput(){return this.ctx.kicadPcb}},Koi={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 Poi(e){return e&&(Koi[e]||e)||"F.Cu"}function qoi(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 Ooi=class extends JE{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=Pe(A,{x:s.x,y:s.y}),g=Pe(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=Poi(I),B=`segment:${a.x},${a.y}:${g.x},${g.y}:${l}:${c?.id??0}`,C=new vwA({start:{x:a.x,y:a.y},end:{x:g.x,y:g.y},layer:l,width:i.width||.25,net:new nz(c?.id??0),uuid:eS(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}},Woi=class extends JE{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=Pe(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`):qoi(s),a=`via:${n.x},${n.y}:${i.outer_diameter||.8}:${i.hole_diameter||.4}:${o?.id??0}`,g=new GDA({at:[n.x,n.y],size:i.outer_diameter||.8,drill:i.hole_diameter||.4,layers:r,net:new FDA(o?.id??0),uuid:eS(a)}),c=e.vias;c.push(g),e.vias=c,this.viasProcessed++}getOutput(){return this.ctx.kicadPcb}};function Zoi({textElement:e,c2kMatPcb:A}){if(!e.text||!e.anchor_position)return null;const t=Pe(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 am;s.size={width:o,height:o};const r=new $J,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 rm({font:s});a!=="center"&&(g.justify=r);const c=new Ac([t.x,t.y,0]),I=new iz({text:e.text,layer:n,effects:g});return I.position=c,I}function Voi({textElement:e,c2kMatPcb:A}){if(!e.text||!e.anchor_position)return null;const t=Pe(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 am;s.size={width:o,height:o};const r=new $J,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 rm({font:s});a!=="center"&&(g.justify=r);const c=e.ccw_rotation||0,I=new Ac([t.x,t.y,c]),l=new iz({text:e.text,layer:n,effects:g});return l.position=I,l}var joi=class extends JE{_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=Pe(A,{x:a.x,y:a.y}),I=Pe(A,{x:g.x,y:g.y}),B={top:"F.SilkS",bottom:"B.SilkS"}[s.layer]||s.layer||"F.SilkS",C=new ez({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=Voi({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=Zoi({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=>Pe(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 ez({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}},Cut=class{ctx;pipeline;currentStageIndex=0;finished=!1;get currentStage(){return this.pipeline[this.currentStageIndex]}constructor(e){this.ctx={db:Fa(e),circuitJson:e,kicadPcb:new RDA({generator:"circuit-json-to-kicad",generatorVersion:"0.0.1"}),c2kMatPcb:rB(hr(100,100),mh(1,-1))},this.pipeline=[new moi(e,this.ctx),new woi(e,this.ctx),new Toi(e,this.ctx),new Ooi(e,this.ctx),new Woi(e,this.ctx),new joi(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()}},zoi=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:Fa(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)}
5826
+ `)}};vA.register(GDA);var RDA=class Hwt extends vA{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 Hwt;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=vA.parsePrimitiveSexpr(i,{parentToken:this.token});if(!(n instanceof vA))throw new Error(`kicad_pcb expected SxClass child, received ${JSON.stringify(i)}`);t.consumeChild(n)}return t}consumeChild(A){if(A instanceof xDA){this._sxVersion=A;return}if(A instanceof _DA){this._sxGenerator=A;return}if(A instanceof kDA){this._sxGeneratorVersion=A;return}if(A instanceof SDA){this._sxGeneral=A;return}if(A instanceof Kj){this._sxPaper=A;return}if(A instanceof iQt){this._sxTitleBlock=A;return}if(A instanceof bDA){this._sxLayers=A;return}if(A instanceof DDA){this._sxSetup=A;return}if(A instanceof v1){this._properties.push(A);return}if(A instanceof rz){this._nets.push(A);return}if(A instanceof mwA){this._footprints.push(A);return}if(A instanceof oQt){this._images.push(A);return}if(A instanceof vwA){this._segments.push(A);return}if(A instanceof ez){this._grLines.push(A);return}if(A instanceof iz){this._grTexts.push(A);return}if(A instanceof jht){this._grPolys.push(A);return}if(A instanceof Wht){this._grRects.push(A);return}if(A instanceof GDA){this._vias.push(A);return}if(A instanceof eEt){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 xDA(A)}get generator(){return this._sxGenerator?.value}set generator(A){this._sxGenerator=A===void 0?void 0:new _DA(A)}get generatorVersion(){return this._sxGeneratorVersion?.value}set generatorVersion(A){this._sxGeneratorVersion=A===void 0?void 0:new kDA(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}};vA.register(RDA);var rut=e=>vA.parse(e),JE=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")}},loi=class extends JE{_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 Kj;t.size=A?.name??"A4",e.paper=t,e.uuid=new Li(crypto.randomUUID()),this.finished=!0}getOutput(){return this.ctx.kicadSch}};function WG(e,A){if(e.manufacturer_part_number)return MDA(e.manufacturer_part_number);const t=Boi(e.ftype),i=A?.footprinter_string;return MDA(i?`${t}_${i}`:t)}function Boi(e){if(!e)return"component";let A=e.replace(/^simple_/,"");return A||"component"}function MDA(e){return e.replace(/[\\\/:\s]+/g,"_").replace(/_+/g,"_").replace(/^_|_$/g,"").trim()||"component"}function aut(e){return e?e.match(/^([A-Za-z]+)/)?.[1]?.toUpperCase()??"U":"U"}var gut={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"},Coi=/^[A-Za-z]+\d+$/;function cut(e){return e?Coi.test(e.trim()):!1}function az(e){const A=e?.ftype;if(A&&gut[A])return gut[A];const t=e?.name;return cut(t),aut(t)}function Qoi(e){const A=e?.name;return cut(A)?A.trim():`${az(e)}?`}function Iut(e){return e in SQ}function lut(e,A,t,i){if(i)return`Custom:${i}`;if(e.type!=="source_component")return A.symbol_name?Iut(A.symbol_name)?`Device:${A.symbol_name}`:`Custom:${A.symbol_name}`:"Device:Component";if(A.symbol_name)return Iut(A.symbol_name)?`Device:${A.symbol_name}`:`Custom:${A.symbol_name}`;const n=WG(e,t);return`Device:${az(e)}_${n}`}var hoi=class extends JE{processedSymbolNames=new Set;_step(){const{kicadSch:e,db:A}=this.ctx,t=new xQt,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=lut(t,e,i),a=t.ftype==="simple_chip",g=WG(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:az(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=WG(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=this.buildSymbolDataFromSchematicPrimitives(i,o,e.schematic_component_id),g=WG(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:az(A)})}buildSymbolDataFromSchematicPrimitives(e,A,t){const{circuitJson:i}=this.ctx,n=i.filter(c=>c.type==="schematic_circle"&&c.schematic_symbol_id===e),o=i.filter(c=>c.type==="schematic_line"&&c.schematic_symbol_id===e),s=i.filter(c=>c.type==="schematic_path"&&c.schematic_symbol_id===e);let r=i.filter(c=>c.type==="schematic_port"&&"schematic_symbol_id"in c&&c.schematic_symbol_id===e);if(r.length===0&&t&&(r=i.filter(c=>c.type==="schematic_port"&&c.schematic_component_id===t&&c.display_pin_label!==void 0),r.length===0)){const c=i.filter(l=>l.type==="schematic_port"&&l.schematic_component_id===t),I=new Set;r=c.filter(l=>{const B=l.pin_number;if(B!==void 0){if(I.has(B))return!1;I.add(B)}return!0})}const a=[];for(const c of n)a.push({type:"circle",x:c.center?.x??0,y:c.center?.y??0,radius:c.radius??.5,fill:c.is_filled??!1,fillColor:c.fill_color});for(const c of o)a.push({type:"path",points:[{x:c.x1??0,y:c.y1??0},{x:c.x2??0,y:c.y2??0}]});for(const c of s)c.points&&c.points.length>0&&a.push({type:"path",points:c.points,fill:c.is_filled??!1,fillColor:c.fill_color});const g=r.map((c,I)=>({x:c.center?.x??0,y:c.center?.y??0,labels:[c.display_pin_label||`${c.pin_number||I+1}`],pinNumber:c.pin_number||I+1,facingDirection:c.facing_direction}));return g.sort((c,I)=>c.pinNumber-I.pinNumber),{center:A.center||{x:0,y:0},size:A.size||{width:1,height:1},primitives:a,ports:g}}createLibrarySymbolForNetLabel({netLabel:e,isPower:A,isGround:t}){const i=e.symbol_name;if(!i)return null;const n=SQ[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_")?this.createGenericChipSymbolData(A,this.ctx.db):SQ[e]||null}createGenericChipSymbolData(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}}}createLibrarySymbol({libId:e,symbolData:A,isChip:t,schematicComponent:i,description:n,keywords:o,fpFilters:s,footprintRef:r="",referencePrefix:a}){const g=new N1({libraryId:e,excludeFromSim:!1,inBom:!0,onBoard:!0}),c=new cQt;c.hide=!t,g._sxPinNumbers=c;const I=new IQt;I.offset=t?1.27:0,g._sxPinNames=I,this.addSymbolProperties({symbol:g,libId:e,description:n,keywords:o,fpFilters:s,footprintRef:r,referencePrefix:a});const l=this.createDrawingSubsymbol({libId:e,symbolData:A,isChip:t});g.subSymbols.push(l);const B=this.createPinSubsymbol({libId:e,symbolData:A,isChip:t,schematicComponent:i});return g.subSymbols.push(B),g._sxEmbeddedFonts=new qj(!1),g}addSymbolProperties({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 gm({key:g.key,value:g.value,id:g.id,at:g.at,effects:this.createTextEffects(1.27,g.hide)}))}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","*")}createDrawingSubsymbol({libId:e,symbolData:A,isChip:t}){const i=new N1({libraryId:`${e.split(":")[1]}_0_1`}),n=15.24,o=this.ctx.c2kMatSch?.a||15,s=t?o:n;for(const r of A.primitives||[])if(r.type==="path"&&r.points){const a=t||r.fill?"background":"none",g=this.createPolylineFromPoints({points:r.points,scale:s,center:A.center,fillType:a});i.polylines.push(g)}else if(r.type==="circle"){const a=this.createCircleFromPrimitive({primitive:r,scale:s,center:A.center});i.circles.push(a)}return i}createPolylineFromPoints({points:e,scale:A,center:t,fillType:i}){const n=new rQt,o=t?.x??0,s=t?.y??0,r=mh(A,A),a=e.map(l=>{const B=Pe(r,{x:l.x-o,y:l.y-s});return new KQ(B.x,B.y)}),g=new OC(a);n.points=g;const c=new AS;c.width=.254,c.type="default",n.stroke=c;const I=new hQt;return I.type=i,n.fill=I,n}createCircleFromPrimitive({primitive:e,scale:A,center:t}){const i=new dQt,n=t?.x??0,o=t?.y??0,s=mh(A,A),r=Pe(s,{x:e.x-n,y:e.y-o}),a=i;a._sxCenter=new CQt(r.x,r.y),a._sxRadius=new QQt(e.radius*A);const g=new AS;g.width=.254,g.type="default",a._sxStroke=g;const c=new EQt;return c.type=e.fill?"background":"none",a._sxFill=c,i}createPinSubsymbol({libId:e,symbolData:A,isChip:t,schematicComponent:i}){const n=new N1({libraryId:`${e.split(":")[1]}_1_1`});for(let o=0;o<(A.ports?.length||0);o++){const s=A.ports[o],r=new Zj;r.pinElectricalType="passive",r.pinGraphicStyle="line";const{x:a,y:g,angle:c}=this.calculatePinPosition(s,A.center,A.size,t,o,i);r.at=[a,g,c];const I=6,l=2.54;r.length=t?I:l;const B=new am;B.size={height:1.27,width:1.27};const C=new rm({font:B}),Q=s.labels?.[0]||"~";r._sxName=new BmA({value:Q,effects:C});const h=new am;h.size={height:1.27,width:1.27};const E=new rm({font:h}),u=s.pinNumber?.toString()||`${o+1}`;r._sxNumber=new fQt({value:u,effects:E}),n.pins.push(r)}return n}calculatePinPosition(e,A,t,i,n,o){const r=this.ctx.c2kMatSch?.a||15,a=i?r:15.24;let g=e.x??0,c=e.y??0,I=!1;if(i&&n!==void 0&&o){const m=this.ctx.db.schematic_port.list().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=mh(a,a),Q=Pe(C,{x:l,y:B});let h;if(i&&t){const m=t.width/2,w=t.height/2,D=Math.abs(l)/m,S=Math.abs(B)/w;h=D>S}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 p=0;return h?l>0?(p=180,i&&(E=E+d)):(p=0,i&&(E=E-d)):B>0?(p=270,i&&(u=u+d)):(p=90,i&&(u=u-d)),{x:E,y:u,angle:p}}createTextEffects(e,A){const t=new am;return t.size={height:e,width:e},new rm({font:t,hiddenText:A})}getOutput(){if(!this.ctx.kicadSch)throw new Error("kicadSch is not initialized");return this.ctx.kicadSch}},Eoi=class extends JE{_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}=Pe(this.ctx.c2kMatSch,{x:n.center.x,y:n.center.y}),a=crypto.randomUUID(),g=new N1({at:[s,r,0],unit:1,excludeFromSim:!1,inBom:!0,onBoard:!0,dnp:!1,uuid:a,fieldsAutoplaced:!0}),c=A.cad_component?.list()?.find(Y=>Y.source_component_id===o.source_component_id);let I,l=n.schematic_symbol_id;if(!l){const Y=this.ctx.circuitJson.find(H=>(H.type==="schematic_line"||H.type==="schematic_circle"||H.type==="schematic_path")&&H.schematic_component_id===n.schematic_component_id&&H.schematic_symbol_id);Y&&(l=Y.schematic_symbol_id)}if(l){const Y=this.ctx.circuitJson.find(H=>H.type==="schematic_symbol"&&H.schematic_symbol_id===l);if(Y?.name)I=Y.name;else{const H=WG(o,c);H?I=H:I=`custom_${o.ftype||"component"}_${l}`}}const B=lut(o,n,c,I),C=new cmA(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}),p=new gm({key:"Reference",value:Q,id:0,at:[u.x,u.y,0],effects:this.createTextEffects(1.27,!1)}),m=o.ftype==="simple_chip",w=new gm({key:"Value",value:h,id:1,at:[d.x,d.y,0],effects:this.createTextEffects(1.27,m)}),D=new gm({key:"Footprint",value:"",id:2,at:[s-1.778,r,90],effects:this.createTextEffects(1.27,!0)}),S=new gm({key:"Datasheet",value:"~",id:3,at:[s,r,0],effects:this.createTextEffects(1.27,!0)}),k=new gm({key:"Description",value:E,id:4,at:[s,r,0],effects:this.createTextEffects(1.27,!0)});g.properties.push(p,w,D,S,k);let x=A.schematic_port.list().filter(Y=>Y.schematic_component_id===n.schematic_component_id);if(l){const Y=x.filter(H=>H.display_pin_label);Y.length>0&&(x=Y)}x.sort((Y,H)=>(Y.pin_number||0)-(H.pin_number||0));for(let Y=0;Y<x.length;Y++){const H=x[Y];if(!H)continue;const O=new Zj;O.numberString=`${H.pin_number||Y+1}`,O.uuid=crypto.randomUUID(),g.pins.push(O)}const N=new CmA,M=new hmA(""),L=new EmA(`/${e?.uuid?.value||""}`);L.reference=Q,L.unit=1,M.paths.push(L),N.projects.push(M),g._sxInstances=N,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=Pe(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=SQ[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?Pe(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?Pe(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=Qoi(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 am;i.size={height:e,width:e};const n=t?new $J({horizontal:t}):void 0;return new rm({font:i,hiddenText:A,justify:n})}getOutput(){if(!this.ctx.kicadSch)throw new Error("kicadSch is not initialized");return this.ctx.kicadSch}},uoi=class extends JE{_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}=Pe(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 N1({at:[i,n,0],unit:1,excludeFromSim:!1,inBom:!0,onBoard:!0,dnp:!1,uuid:o,fieldsAutoplaced:!0}),r=`Custom:${t}`,a=new cmA(r);s._sxLibId=a;const g=t.includes("_up")||t.toLowerCase().includes("vcc"),c=g?-4:4,I=g?-6:6,l=new gm({key:"Reference",value:A,id:0,at:[i,n+c,0],effects:this.createTextEffects(1.27,!1)}),B=new gm({key:"Value",value:A,id:1,at:[i,n+I,0],effects:this.createTextEffects(1.27,!0)}),C=new gm({key:"Footprint",value:"",id:2,at:[i-1.778,n,90],effects:this.createTextEffects(1.27,!0)}),Q=new gm({key:"Datasheet",value:"~",id:3,at:[i,n,0],effects:this.createTextEffects(1.27,!0)}),h=new gm({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 Zj;E.numberString="1",E.uuid=crypto.randomUUID(),s.pins.push(E);const{kicadSch:u}=this.ctx,d=new CmA,p=new hmA(""),m=new EmA(`/${u?.uuid?.value||""}`);return m.reference=A,m.unit=1,p.paths.push(m),d.projects.push(p),s._sxInstances=d,s}createGlobalLabel(e,A){if(!this.ctx.c2kMatSch||!this.ctx.kicadSch)return null;const{x:t,y:i}=Pe(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 $J(a)),new LQt({value:A,at:[t,i,s],effects:g,uuid:crypto.randomUUID(),fieldsAutoplaced:!0})}createTextEffects(e,A=!1){const t=new am;return t.size={height:e,width:e},new rm({font:t,hiddenText:A})}getOutput(){if(!this.ctx.kicadSch)throw new Error("kicadSch is not initialized");return this.ctx.kicadSch}},doi=class extends JE{_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 kQt;if(!this.ctx.c2kMatSch)throw new Error("Schematic transformation matrix not initialized in context");const t=Pe(this.ctx.c2kMatSch,{x:e.from.x,y:e.from.y}),i=Pe(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 OC([new KQ(n,o),new KQ(s,r)]);A.points=a;const g=new AS;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}=Pe(this.ctx.c2kMatSch,{x:e.x,y:e.y}),i=new FQt({at:[A,t],diameter:0});return i.uuid=crypto.randomUUID(),i}getOutput(){return this.ctx.kicadSch}},poi=class extends JE{_step(){const{kicadSch:e}=this.ctx;if(!e)throw new Error("KicadSch instance not initialized in context");const A=new fmA,t=new YQt;t.value="/";const i=new JQt("1");t.pages=[i],A.paths=[t],e.sheetInstances=A,e.embeddedFonts=new qj(!1),this.finished=!0}getOutput(){return this.ctx.kicadSch}};function foi(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 gz=[{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 yoi(e,A,t=20){const i=e+2*t,n=A+2*t;for(let o=0;o<gz.length;o++){const s=gz[o];if(i<=s.width&&n<=s.height)return s}return gz[gz.length-1]}var But=class{ctx;pipeline;currentStageIndex=0;finished=!1;get currentStage(){return this.pipeline[this.currentStageIndex]}constructor(e){const t=Fa(e),{center:i,bounds:n}=foi(t),o=(n.maxX-n.minX)*15,s=(n.maxY-n.minY)*15,r=yoi(o,s),a=r.width/2,g=r.height/2;this.ctx={db:t,circuitJson:e,kicadSch:new mmA({generator:"circuit-json-to-kicad",generatorVersion:"0.0.1"}),schematicPaperSize:r,c2kMatSch:rB(hr(a,g),mh(15,-15),hr(-i.x,-i.y))},this.pipeline=[new loi(e,this.ctx),new hoi(e,this.ctx),new Eoi(e,this.ctx),new uoi(e,this.ctx),new doi(e,this.ctx),new poi(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()}},moi=class extends JE{_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 Kj;n.size="A4",e.paper=n;const o=new SDA;o.thickness=1.6,e.general=o;const s=new DDA;s.padToMaskClearance=0,e.setup=s;const r=new bDA,a=[new Ll({index:0,name:"F.Cu",type:"signal"})];for(let g=1;g<i-1;g++)a.push(new Ll({index:g,name:`In${g}.Cu`,type:"signal"}));a.push(new Ll({index:31,name:"B.Cu",type:"signal"})),a.push(new Ll({index:32,name:"B.Adhes",type:"user"}),new Ll({index:33,name:"F.Adhes",type:"user"}),new Ll({index:34,name:"B.Paste",type:"user"}),new Ll({index:35,name:"F.Paste",type:"user"}),new Ll({index:36,name:"B.SilkS",type:"user"}),new Ll({index:37,name:"F.SilkS",type:"user"}),new Ll({index:38,name:"B.Mask",type:"user"}),new Ll({index:39,name:"F.Mask",type:"user"}),new Ll({index:40,name:"Dwgs.User",type:"user"}),new Ll({index:41,name:"Cmts.User",type:"user"}),new Ll({index:42,name:"Eco1.User",type:"user"}),new Ll({index:43,name:"Eco2.User",type:"user"}),new Ll({index:44,name:"Edge.Cuts",type:"user"}),new Ll({index:45,name:"Margin",type:"user"}),new Ll({index:46,name:"B.CrtYd",type:"user"}),new Ll({index:47,name:"F.CrtYd",type:"user"}),new Ll({index:48,name:"B.Fab",type:"user"}),new Ll({index:49,name:"F.Fab",type:"user"})),r.definitions=a,e.layers=r,this.finished=!0}getOutput(){return this.ctx.kicadPcb}},woi=class extends JE{_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 rz(0,""));let s=1;for(const[r,a]of n){const g=new rz(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 Doi(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 eS(e){const A=Doi(e);return`${A.slice(0,8)}-${A.slice(8,12)}-${A.slice(12,16)}-${A.slice(16,20)}-${A.slice(20,32)}`}function Soi(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 swA({center:{x:n,y:o},end:{x:n+i.radius,y:o},layer:r,stroke:new AS,fill:!1});a.stroke&&(a.stroke.width=i.stroke_width||.05,a.stroke.type="default"),t.push(a)}return t}function boi(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 swA({center:{x:n,y:o},end:{x:n+i.radius,y:o},layer:r,stroke:new AS,fill:!1});a.stroke&&(a.stroke.width=.05,a.stroke.type="default"),t.push(a)}return t}function xoi(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 Xj({start:{x:n-s,y:o-r},end:{x:n+s,y:o+r},layer:g,stroke:new AS,fill:!1});c.stroke&&(c.stroke.width=i.stroke_width||.1,c.stroke.type="default"),t.push(c)}return t}function _oi(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 Xj({start:{x:n-s,y:o-r},end:{x:n+s,y:o+r},layer:a,stroke:new AS,fill:!1});g.stroke&&(g.stroke.width=i.stroke_width||.1,g.stroke.type="default"),t.push(g)}return t}function koi(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 Xj({start:{x:n-s,y:o-r},end:{x:n+s,y:o+r},layer:g,stroke:new AS,fill:!1});c.stroke&&(c.stroke.width=.05,c.stroke.type="default"),t.push(c)}return t}function Foi(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 KQ(c,I)}),r=new Mht;r.points=new OC(s),r.layer=o,r.fill=!1;const a=new AS;a.width=.05,a.type="default",r.stroke=a,t.push(r)}return t}function Goi({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?Lm(t*Math.PI/180):vu(),s=Pe(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 am;I.size={width:c,height:c};const l=new rm({font:I}),B=e.ccw_rotation||0;return new jmA({type:"user",text:e.text,position:{x:r.x,y:r.y,angle:B},layer:g,effects:l})}function Roi(e,A,t,i){const n=[];for(const o of e){const s=Goi({textElement:o,componentCenter:A,componentRotation:t});s&&(i&&o.text===i&&(s.type="reference"),n.push(s))}return n}function Moi(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?Lm(t*Math.PI/180):vu(),a=Pe(r,{x:o,y:s}),g=n.font_size||1,c=new am;c.size={width:g,height:g};const I=new rm({font:c}),l=new jmA({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 Noi(e,A){const t=[],i=e.model_step_url||e.model_wrl_url;if(!i)return t;const n=new pwA(i);if(e.position&&(n.offset={x:(e.position.x||0)-A.x,y:-((e.position.y||0)-A.y),z:e.position.z||0}),e.rotation&&(n.rotate={x:e.rotation.x||0,y:e.rotation.y||0,z:e.rotation.z||0}),e.model_unit_to_mm_scale_factor){const o=e.model_unit_to_mm_scale_factor;n.scale={x:o,y:o,z:o}}return t.push(n),t}function voi({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,p)=>d+p.x,0)/u.length,r=u.reduce((d,p)=>d+p.y,0)/u.length}else throw new Error("Pad must have either x/y coordinates or points array");const a=rB(i!==0?Lm(i*Math.PI/180):{a:1,b:0,c:0,d:1,e:0,f:0},mh(1,-1),hr(-A.x,-A.y)),g=Pe(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=rB(mh(1,-1),hr(-s,-r)),p=u.map(w=>{const D=Pe(d,{x:w.x,y:w.y});return new KQ(D.x,D.y)}),m=new qmA;m.contours=[new OC(p)],m.width=0,m.filled=!0,Q=new Eht,Q.addGraphic(m),l="custom",C=new Aht,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 zj({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:eS(h)});return C&&(E.options=C),Q&&(E.primitives=Q),n&&(E.net=new HmA(n.id,n.name)),E}function Loi(e,A,t,i,n,o){const s=[];let r=n;for(const a of e){const g=o(a.pcb_port_id),c=voi({pcbPad:a,componentCenter:A,padNumber:r,componentRotation:t,netInfo:g,componentId:i});s.push(c),r++}return{pads:s,nextPadNumber:r}}function Uoi({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?Lm(i*Math.PI/180):vu(),g=Pe(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=Pe(a,{x:-u.x,y:u.y}))}e.shape==="circle"?(c="circle",I=[e.outer_diameter,e.outer_diameter],l=new tS({diameter:e.hole_diameter,offset:Q})):e.shape==="pill"||e.shape==="oval"?(c="oval",I=[e.outer_width,e.outer_height],l=new tS({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 tS({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 tS({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 tS({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 tS({diameter:.8,offset:Q}));const h=`thruhole:${o}:${t}:${g.x},${g.y}`,E=new zj({number:String(t),padType:"thru_hole",shape:c,at:[g.x,g.y,B],size:I,drill:l,layers:["*.Cu","*.Mask"],removeUnusedLayers:!1,uuid:eS(h)});return n&&(E.net=new HmA(n.id,n.name)),E}function Hoi(e,A,t,i,n,o){const s=[];let r=n;for(const a of e){const g=o(a.pcb_port_id),c=Uoi({platedHole:a,componentCenter:A,padNumber:r,componentRotation:t,netInfo:g,componentId:i});c&&(s.push(c),r++)}return{pads:s,nextPadNumber:r}}function Yoi({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?Lm(t*Math.PI/180):vu(),s=Pe(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 tS({diameter:c})}else if(e.hole_shape==="oval"){r="oval";const c=e.hole_width,I=e.hole_height;a=[c,I],g=new tS({oval:!0,diameter:c,width:I})}else{r="circle";const c="hole_diameter"in e?e.hole_diameter:1;a=[c,c],g=new tS({diameter:c})}return new zj({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 Joi(e,A,t){const i=[];for(const n of e){const o=Yoi({pcbHole:n,componentCenter:A,componentRotation:t});o&&i.push(o)}return i}var Toi=class extends JE{componentsProcessed=0;pcbComponents=[];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){super(e,A),this.pcbComponents=this.ctx.db.pcb_component.list()}_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?WG(i,n):"Unknown",s=Pe(A,{x:t.center.x,y:t.center.y}),r=`footprint:${t.pcb_component_id}:${s.x},${s.y}`,a=new mwA({libraryLink:`tscircuit:${o}`,layer:"F.Cu",at:[s.x,s.y,t.rotation||0],uuid:eS(r)}),g=a.fpTexts,c=this.ctx.db.pcb_silkscreen_text?.list().filter(H=>H.pcb_component_id===t.pcb_component_id)||[];g.push(...Roi(c,t.center,t.rotation||0,i?.name));const I=this.ctx.db.pcb_note_text?.list().filter(H=>H.pcb_component_id===t.pcb_component_id)||[];g.push(...Moi(I,t.center,t.rotation||0)),a.fpTexts=g;const l=a.fpPads,B=H=>this.getNetInfoForPcbPort(H),C=this.ctx.db.pcb_smtpad?.list().filter(H=>H.pcb_component_id===t.pcb_component_id)||[],{pads:Q,nextPadNumber:h}=Loi(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(H=>H.pcb_component_id===t.pcb_component_id)||[],{pads:u}=Hoi(E,t.center,t.rotation||0,t.pcb_component_id,h,B);l.push(...u);const d=this.ctx.db.pcb_hole?.list().filter(H=>H.subcircuit_id===t.subcircuit_id)||[],p=Joi(d,t.center,t.rotation||0);l.push(...p),a.fpPads=l;const m=this.ctx.db.pcb_silkscreen_circle?.list().filter(H=>H.pcb_component_id===t.pcb_component_id)||[],w=a.fpCircles??[];w.push(...Soi(m,t.center));const D=this.ctx.db.pcb_courtyard_circle?.list().filter(H=>H.pcb_component_id===t.pcb_component_id)||[];w.push(...boi(D,t.center)),a.fpCircles=w;const S=this.ctx.db.pcb_fabrication_note_rect?.list().filter(H=>H.pcb_component_id===t.pcb_component_id)||[],k=a.fpRects??[];k.push(...xoi(S,t.center));const x=this.ctx.db.pcb_note_rect?.list().filter(H=>H.pcb_component_id===t.pcb_component_id)||[];k.push(..._oi(x,t.center));const N=this.ctx.db.pcb_courtyard_rect?.list().filter(H=>H.pcb_component_id===t.pcb_component_id)||[];k.push(...koi(N,t.center)),a.fpRects=k;const M=this.ctx.db.pcb_courtyard_outline?.list().filter(H=>H.pcb_component_id===t.pcb_component_id)||[],L=Foi(M,t.center);if(L.length>0&&(a.fpPolys=L),n){const H=Noi(n,t.center);H.length>0&&(a.models=H)}const Y=e.footprints;Y.push(a),e.footprints=Y,this.componentsProcessed++}getOutput(){return this.ctx.kicadPcb}},Koi={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 Poi(e){return e&&(Koi[e]||e)||"F.Cu"}function qoi(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 Ooi=class extends JE{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=Pe(A,{x:s.x,y:s.y}),g=Pe(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=Poi(I),B=`segment:${a.x},${a.y}:${g.x},${g.y}:${l}:${c?.id??0}`,C=new vwA({start:{x:a.x,y:a.y},end:{x:g.x,y:g.y},layer:l,width:i.width||.25,net:new nz(c?.id??0),uuid:eS(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}},Woi=class extends JE{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=Pe(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`):qoi(s),a=`via:${n.x},${n.y}:${i.outer_diameter||.8}:${i.hole_diameter||.4}:${o?.id??0}`,g=new GDA({at:[n.x,n.y],size:i.outer_diameter||.8,drill:i.hole_diameter||.4,layers:r,net:new FDA(o?.id??0),uuid:eS(a)}),c=e.vias;c.push(g),e.vias=c,this.viasProcessed++}getOutput(){return this.ctx.kicadPcb}};function Zoi({textElement:e,c2kMatPcb:A}){if(!e.text||!e.anchor_position)return null;const t=Pe(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 am;s.size={width:o,height:o};const r=new $J,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 rm({font:s});a!=="center"&&(g.justify=r);const c=new Ac([t.x,t.y,0]),I=new iz({text:e.text,layer:n,effects:g});return I.position=c,I}function Voi({textElement:e,c2kMatPcb:A}){if(!e.text||!e.anchor_position)return null;const t=Pe(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 am;s.size={width:o,height:o};const r=new $J,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 rm({font:s});a!=="center"&&(g.justify=r);const c=e.ccw_rotation||0,I=new Ac([t.x,t.y,c]),l=new iz({text:e.text,layer:n,effects:g});return l.position=I,l}var joi=class extends JE{_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=Pe(A,{x:a.x,y:a.y}),I=Pe(A,{x:g.x,y:g.y}),B={top:"F.SilkS",bottom:"B.SilkS"}[s.layer]||s.layer||"F.SilkS",C=new ez({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=Voi({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=Zoi({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=>Pe(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 ez({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}},Cut=class{ctx;pipeline;currentStageIndex=0;finished=!1;get currentStage(){return this.pipeline[this.currentStageIndex]}constructor(e){this.ctx={db:Fa(e),circuitJson:e,kicadPcb:new RDA({generator:"circuit-json-to-kicad",generatorVersion:"0.0.1"}),c2kMatPcb:rB(hr(100,100),mh(1,-1))},this.pipeline=[new moi(e,this.ctx),new woi(e,this.ctx),new Toi(e,this.ctx),new Ooi(e,this.ctx),new Woi(e,this.ctx),new joi(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()}},zoi=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:Fa(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)}
5827
5827
  `}},Xoi=class extends JE{_step(){const e=new But(this.ctx.circuitJson);e.runUntilFinished(),this.ctx.kicadSchString=e.getOutputString();const A=new Cut(this.ctx.circuitJson);A.runUntilFinished(),this.ctx.kicadPcbString=A.getOutputString(),this.finished=!0}getOutput(){return this.ctx.libraryOutput}},$oi=class extends JE{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=rut(e).find(r=>r instanceof mmA);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}},Asi=20240108,tsi="pcbnew",esi="8.0";function isi(e){const A=e.split(/[/\\]/);return A[A.length-1]||e}var nsi=class extends JE{findCustomFootprintNames(){const e=new Set,A=this.ctx.db.cad_component?.list()??[],t=this.ctx.db.source_component;for(const i of A)if(!i.footprinter_string){const n=i.source_component_id?t?.get(i.source_component_id):null;if(n){const o=WG(n,i);e.add(o)}}return e}_step(){const e=this.ctx.kicadPcbString,A=this.ctx.fpLibraryName??"tscircuit";if(!e)throw new Error("PCB content not available. Run GenerateKicadSchAndPcbStage first.");const t=this.findCustomFootprintNames(),i=new Map;try{const o=rut(e).find(r=>r instanceof RDA);if(!o){this.ctx.footprintEntries=[],this.finished=!0;return}const s=o.footprints??[];for(const r of s){const a=this.sanitizeFootprint({footprint:r,fpLibraryName:A,customFootprintNames:t});i.has(a.footprintName)||i.set(a.footprintName,a)}}catch(n){console.warn("Failed to parse PCB for footprint extraction:",n)}this.ctx.footprintEntries=Array.from(i.values()),this.finished=!0}sanitizeFootprint({footprint:e,fpLibraryName:A,customFootprintNames:t}){const n=(e.libraryLink??"footprint").split(":"),o=(n.length>1?n[1]:n[0])?.replace(/[\\\/]/g,"-").trim()||"footprint",s=!t.has(o);if(e.libraryLink=o,e.position=Ac.from([0,0,0]),e.locked=!1,e.placed=!1,e.version=Asi,e.generator=tsi,e.generatorVersion=esi,e.descr||(e.descr=""),e.tags||(e.tags=""),e.embeddedFonts||(e.embeddedFonts=new qj(!1)),!e.attr){const d=new WQt,p=(e.fpPads??[]).map(m=>m.padType);p.some(m=>m.includes("thru_hole"))?d.type="through_hole":p.some(m=>m.includes("smd"))&&(d.type="smd"),e.attr=d}e.uuid=void 0,e.path=void 0,e.sheetfile=void 0,e.sheetname=void 0;const r=new am;r.size={width:1.27,height:1.27},r.thickness=.15;const a=new rm({font:r}),g=e.fpPads??[];let c=0,I=0;for(const d of g){const p=d.at,m=d.size;if(p&&m){const w=p.y??0,D=m.height??0,S=w-D/2,k=w+D/2;c=Math.min(c,S),I=Math.max(I,k)}}const l=c-.5,B=I+.5;e.properties=[new v1({key:"Reference",value:"REF**",position:[0,l,0],layer:"F.SilkS",uuid:eS(`${o}-property-Reference`),effects:a}),new v1({key:"Value",value:"Val**",position:[0,B,0],layer:"F.Fab",uuid:eS(`${o}-property-Value`),effects:a}),new v1({key:"Datasheet",value:"",position:[0,0,0],layer:"F.Fab",hidden:!0,uuid:eS(`${o}-property-Datasheet`),effects:a}),new v1({key:"Description",value:"",position:[0,0,0],layer:"F.Fab",hidden:!0,uuid:eS(`${o}-property-Description`),effects:a})];const C=e.fpTexts??[];for(const d of C)d.uuid=void 0,d.type==="reference"?d.text="REF**":d.type==="value"&&d.text.trim().length===0&&(d.text=o);e.fpTexts=C;const Q=e.fpPads??[];for(let d=0;d<Q.length;d++){const p=Q[d];p&&(p.uuid=eS(`${o}-pad-${p.number??d}`),p.net=void 0)}e.fpPads=Q;const h=e.models??[],E=[],u=[];for(const d of h)if(d.path){const p=isi(d.path),m=`../../3dmodels/${A}.3dshapes/${p}`,w=new pwA(m);d.offset&&(w.offset=d.offset),d.scale&&(w.scale=d.scale),d.rotate&&(w.rotate=d.rotate),E.push(w),u.push(d.path)}return e.models=E,{footprintName:o,kicadModString:e.getString(),model3dSourcePaths:u,isBuiltin:s}}getOutput(){return this.ctx.libraryOutput}},osi=20211014,ssi="circuit-json-to-kicad",rsi=class extends JE{_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 SQt({version:osi,generator:ssi,symbols:e.map(t=>t.symbol)}).getString()}getOutput(){return this.ctx.libraryOutput}},asi=class extends JE{_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
5828
5828
  (version 7)
5829
5829
  (lib (name "${e}") (type "KiCad") (uri "\${KIPRJMOD}/${e}.pretty") (options "") (descr "Generated by circuit-json-to-kicad"))