@tscircuit/runframe 0.0.2779 → 0.0.2781

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.
@@ -5300,7 +5300,7 @@ ${A.join(`
5300
5300
  ${m}polygon: ${d.polygon.vertices}
5301
5301
  `:A+=`
5302
5302
  `,d.children.length>0&&l.push(d.children)}return A}};e.exports=s}}),Vri=yt({"node_modules/@jscad/modeling/src/operations/booleans/trees/Tree.js"(t,e){var n=Gri(),o=Kri(),i=class{constructor(r){this.polygonTree=new o,this.rootnode=new n(null),r&&this.addPolygons(r)}invert(){this.polygonTree.invert(),this.rootnode.invert()}clipTo(r,s=!1){this.rootnode.clipTo(r,s)}allPolygons(){const r=[];return this.polygonTree.getPolygons(r),r}addPolygons(r){const s=new Array(r.length);for(let a=0;a<r.length;a++)s[a]=this.polygonTree.addChild(r[a]);this.rootnode.addPolygonTreeNodes(s)}clear(){this.polygonTree.clear()}toString(){return"Tree: "+this.polygonTree.toString("")}};e.exports=i}}),tYe=yt({"node_modules/@jscad/modeling/src/operations/booleans/trees/index.js"(t,e){e.exports={Tree:Vri()}}}),zri=yt({"node_modules/@jscad/modeling/src/operations/booleans/intersectGeom3Sub.js"(t,e){var n=va(),o=eYe(),{Tree:i}=tYe(),r=(s,a)=>{if(!o(s,a))return n.create();const A=new i(n.toPolygons(s)),c=new i(n.toPolygons(a));A.invert(),c.clipTo(A),c.invert(),A.clipTo(c),c.clipTo(A),A.addPolygons(c.allPolygons()),A.invert();const l=A.allPolygons();return n.create(l)};e.exports=r}}),IZt=yt({"node_modules/@jscad/modeling/src/operations/booleans/intersectGeom3.js"(t,e){var n=ra(),o=FX(),i=zri(),r=(...s)=>{s=n(s);let a=s.shift();return s.forEach(A=>{a=i(a,A)}),a=o(a),a};e.exports=r}}),Jri=yt({"node_modules/@jscad/modeling/src/operations/booleans/intersectGeom2.js"(t,e){var n=ra(),o=va(),i=_P(),r=$Ge(),s=ZGe(),a=IZt(),A=(...c)=>{c=n(c);const l=c.map(h=>s({z0:-1,z1:1},h)),g=a(l),u=i(g);return r(u,o.toPolygons(g))};e.exports=A}}),Wri=yt({"node_modules/@jscad/modeling/src/operations/booleans/intersect.js"(t,e){var n=ra(),o=kX(),i=Ta(),r=va(),s=Jri(),a=IZt(),A=(...c)=>{if(c=n(c),c.length===0)throw new Error("wrong number of arguments");if(!o(c))throw new Error("only intersect of the types are supported");const l=c[0];return i.isA(l)?s(c):r.isA(l)?a(c):l};e.exports=A}}),nYe=yt({"node_modules/@jscad/modeling/src/operations/hulls/hullPoints3.js"(t,e){var n=UA(),o=B$t(),i=r=>o(r,{skipTriangulation:!0}).map(A=>{const c=A.map(l=>r[l]);return n.create(c)});e.exports=i}}),CZt=yt({"node_modules/@jscad/modeling/src/operations/booleans/unionGeom3Sub.js"(t,e){var n=va(),o=eYe(),{Tree:i}=tYe(),r=(a,A)=>{if(!o(a,A))return s(a,A);const c=new i(n.toPolygons(a)),l=new i(n.toPolygons(A));c.clipTo(l,!1),l.clipTo(c),l.invert(),l.clipTo(c),l.invert();const g=c.allPolygons().concat(l.allPolygons());return n.create(g)},s=(a,A)=>{let c=n.toPolygons(a);return c=c.concat(n.toPolygons(A)),n.create(c)};e.exports=r}}),oYe=yt({"node_modules/@jscad/modeling/src/operations/booleans/unionGeom3.js"(t,e){var n=ra(),o=FX(),i=CZt(),r=(...s)=>{s=n(s);let a;for(a=1;a<s.length;a+=2)s.push(i(s[a-1],s[a]));let A=s[a-1];return A=o(A),A};e.exports=r}}),yZt=yt({"node_modules/@jscad/modeling/src/operations/minkowski/minkowskiSum.js"(t,e){var n=ra(),o=va(),i=UA(),r=nYe(),s=oYe(),a=(...h)=>{if(h=n(h),h.length!==2)throw new Error("minkowskiSum requires exactly two geometries");const[d,m]=h;if(!o.isA(d)||!o.isA(m))throw new Error("minkowskiSum requires geom3 geometries");const p=o.isConvex(d),_=o.isConvex(m);if(p&&_)return g(d,m);if(!p&&_)return A(d,m);if(p&&!_)return A(m,d);throw new Error("minkowskiSum of two non-convex geometries is not yet supported")},A=(h,d)=>{const m=c(h);if(m.length===0)return o.create();const p=m.map(_=>g(_,d));return p.length===1?p[0]:s(p)},c=h=>{const d=o.toPolygons(h);if(d.length===0)return[];const m=[];for(let p=0;p<d.length;p++){const _=d[p],f=_.vertices;let I=0,C=0,y=0;for(let D=0;D<f.length;D++)I+=f[D][0],C+=f[D][1],y+=f[D][2];I/=f.length,C/=f.length,y/=f.length;const x=i.plane(_),E=x[0],B=x[1],b=x[2],Q=.1,w=[I-E*Q,C-B*Q,y-b*Q];for(let D=1;D<f.length-1;D++){const k=f[0],T=f[D],H=f[D+1],G=l(w,k,T,H);m.push(o.create(G))}}return m},l=(h,d,m,p)=>[i.create([h,m,d]),i.create([h,d,p]),i.create([d,m,p]),i.create([m,h,p])],g=(h,d)=>{const m=u(h),p=u(d);if(m.length===0||p.length===0)return o.create();const _=[];for(let I=0;I<m.length;I++){const C=m[I];for(let y=0;y<p.length;y++){const x=p[y];_.push([C[0]+x[0],C[1]+x[1],C[2]+x[2]])}}const f=r(_);return o.create(f)},u=h=>{const d=new Set,m=[],p=o.toPolygons(h);for(let _=0;_<p.length;_++){const f=p[_].vertices;for(let I=0;I<f.length;I++){const C=f[I],y=`${C[0]},${C[1]},${C[2]}`;d.has(y)||(d.add(y),m.push(C))}}return m};e.exports=a}}),jri=yt({"node_modules/@jscad/modeling/src/operations/booleans/scissionGeom3.js"(t,e){var n=Jr(),o=_P(),i=va(),r=c=>c.sort((l,g)=>l-g).filter((l,g,u)=>!g||l!==u[g-1]),s=(c,l,g)=>{const u=`${l}`,h=c.get(u);h===void 0?c.set(u,[g]):h.push(g)},a=(c,l)=>{const g=`${l}`;return c.get(g)},A=c=>{const l=o(c),g=i.toPolygons(c),u=g.length,h=new Map,d=n.create();g.forEach((I,C)=>{I.vertices.forEach(y=>{s(h,n.snap(d,y,l),C)})});const m=g.map(I=>{let C=[];return I.vertices.forEach(y=>{C=C.concat(a(h,n.snap(d,y,l)))}),{e:1,d:r(C)}});h.clear();let p=0;const _=m.length;for(let I=0;I<_;I++){const C=m[I];if(C.e>0){const y=new Array(u);y[I]=!0;do p=0,y.forEach((x,E)=>{const B=m[E];if(B.e>0){B.e=-1;for(let b=0;b<B.d.length;b++)y[B.d[b]]=!0;p++}});while(p>0);C.indexes=y}}const f=[];for(let I=0;I<_;I++)if(m[I].indexes){const C=[];m[I].indexes.forEach((y,x)=>C.push(g[x])),f.push(i.create(C))}return f};e.exports=A}}),Xri=yt({"node_modules/@jscad/modeling/src/operations/booleans/scission.js"(t,e){var n=ra(),o=va(),i=jri(),r=(...s)=>{if(s=n(s),s.length===0)throw new Error("wrong number of arguments");const a=s.map(A=>o.isA(A)?i(A):A);return a.length===1?a[0]:a};e.exports=r}}),qri=yt({"node_modules/@jscad/modeling/src/operations/booleans/subtractGeom3Sub.js"(t,e){var n=va(),o=eYe(),{Tree:i}=tYe(),r=(s,a)=>{if(!o(s,a))return n.clone(s);const A=new i(n.toPolygons(s)),c=new i(n.toPolygons(a));A.invert(),A.clipTo(c),c.clipTo(A,!0),A.addPolygons(c.allPolygons()),A.invert();const l=A.allPolygons();return n.create(l)};e.exports=r}}),xZt=yt({"node_modules/@jscad/modeling/src/operations/booleans/subtractGeom3.js"(t,e){var n=ra(),o=FX(),i=qri(),r=(...s)=>{s=n(s);let a=s.shift();return s.forEach(A=>{a=i(a,A)}),a=o(a),a};e.exports=r}}),$ri=yt({"node_modules/@jscad/modeling/src/operations/booleans/subtractGeom2.js"(t,e){var n=ra(),o=va(),i=_P(),r=$Ge(),s=ZGe(),a=xZt(),A=(...c)=>{c=n(c);const l=c.map(h=>s({z0:-1,z1:1},h)),g=a(l),u=i(g);return r(u,o.toPolygons(g))};e.exports=A}}),Zri=yt({"node_modules/@jscad/modeling/src/operations/booleans/subtract.js"(t,e){var n=ra(),o=kX(),i=Ta(),r=va(),s=$ri(),a=xZt(),A=(...c)=>{if(c=n(c),c.length===0)throw new Error("wrong number of arguments");if(!o(c))throw new Error("only subtract of the types are supported");const l=c[0];return i.isA(l)?s(c):r.isA(l)?a(c):l};e.exports=A}}),EZt=yt({"node_modules/@jscad/modeling/src/operations/booleans/unionGeom2.js"(t,e){var n=ra(),o=va(),i=_P(),r=$Ge(),s=ZGe(),a=oYe(),A=(...c)=>{c=n(c);const l=c.map(h=>s({z0:-1,z1:1},h)),g=a(l),u=i(g);return r(u,o.toPolygons(g))};e.exports=A}}),iYe=yt({"node_modules/@jscad/modeling/src/operations/booleans/union.js"(t,e){var n=ra(),o=kX(),i=Ta(),r=va(),s=EZt(),a=oYe(),A=(...c)=>{if(c=n(c),c.length===0)throw new Error("wrong number of arguments");if(!o(c))throw new Error("only unions of the same type are supported");const l=c[0];return i.isA(l)?s(c):r.isA(l)?a(c):l};e.exports=A}}),LX=yt({"node_modules/@jscad/modeling/src/operations/booleans/index.js"(t,e){e.exports={intersect:Wri(),minkowski:yZt(),scission:Xri(),subtract:Zri(),union:iYe()}}}),xue=yt({"node_modules/@jscad/modeling/src/operations/expansions/offsetFromPoints.js"(t,e){var{EPS:n,TAU:o}=sc(),i=$$t(),r=JGe(),s=lA(),a=Iue(),A=(c,l)=>{const g={delta:1,corners:"edge",closed:!1,segments:16};let{delta:u,corners:h,closed:d,segments:m}=Object.assign({},g,c);if(Math.abs(u)<n)return l;let p=c.closed?a(l):1;p===0&&(p=1);const _=p>0&&u>=0||p<0&&u<0;u=Math.abs(u);let f=null,I=[];const C=[],y=s.create(),x=l.length;for(let E=0;E<x;E++){const B=(E+1)%x,b=l[E],Q=l[B];_?s.subtract(y,b,Q):s.subtract(y,Q,b),s.normal(y,y),s.normalize(y,y),s.scale(y,y,u);const w=s.add(s.create(),b,y),D=s.add(s.create(),Q,y),k=[w,D];if(f!=null&&(d||!d&&B!==0)){const T=i(f[0],f[1],k[0],k[1]);T?(I.pop(),k[0]=T):C.push({c:b,s0:f,s1:k})}f=[w,D],!(B===0&&!d)&&(I.push(k[0]),I.push(k[1]))}if(d&&f!=null){const E=I[0],B=I[1],b=i(f[0],f[1],E,B);if(b)I[0]=b,I.pop();else{const Q=l[0],w=[E,B];C.push({c:Q,s0:f,s1:w})}}if(h==="edge"){const E=new Map;I.forEach((Q,w)=>E.set(Q,w));const B=r.create(),b=r.create();C.forEach(Q=>{r.fromPoints(B,Q.s0[0],Q.s0[1]),r.fromPoints(b,Q.s1[0],Q.s1[1]);const w=r.intersectPointOfLines(B,b);if(Number.isFinite(w[0])&&Number.isFinite(w[1])){const D=Q.s0[1],k=E.get(D);I[k]=w,I[(k+1)%I.length]=void 0}else{const D=Q.s1[0],k=E.get(D);I[k]=void 0}}),I=I.filter(Q=>Q!==void 0)}if(h==="round"){let E=Math.floor(m/4);const B=s.create();C.forEach(b=>{let Q=s.angle(s.subtract(B,b.s1[0],b.c));if(Q-=s.angle(s.subtract(B,b.s0[1],b.c)),_&&Q<0&&(Q=Q+Math.PI,Q<0&&(Q=Q+Math.PI)),!_&&Q>0&&(Q=Q-Math.PI,Q>0&&(Q=Q-Math.PI)),Q!==0){E=Math.floor(m*(Math.abs(Q)/o));const w=Q/E,D=s.angle(s.subtract(B,b.s0[1],b.c)),k=[];for(let T=1;T<E;T++){const H=D+w*T,G=s.fromAngleRadians(s.create(),H);s.scale(G,G,u),s.add(G,G,b.c),k.push(G)}if(k.length>0){const T=b.s0[1];let H=I.findIndex(G=>s.equals(T,G));H=(H+1)%I.length,I.splice(H,0,...k)}}else{const w=b.s1[0],D=I.findIndex(k=>s.equals(w,k));I.splice(D,1)}})}return I};e.exports=A}}),esi=yt({"node_modules/@jscad/modeling/src/operations/expansions/expandGeom2.js"(t,e){var n=Ta(),o=xue(),i=(r,s)=>{const a={delta:1,corners:"edge",segments:16},{delta:A,corners:c,segments:l}=Object.assign({},a,r);if(!(c==="edge"||c==="chamfer"||c==="round"))throw new Error('corners must be "edge", "chamfer", or "round"');const h=n.toOutlines(s).map(d=>(r={delta:A,corners:c,closed:!0,segments:l},o(r,d))).reduce((d,m)=>d.concat(n.toSides(n.fromPoints(m))),[]);return n.create(h)};e.exports=i}}),tsi=yt({"node_modules/@jscad/modeling/src/operations/expansions/extrudePolygon.js"(t,e){var n=Ig(),o=Jr(),i=va(),r=UA(),s=(a,A)=>{o.dot(r.plane(A),a)>0&&(A=r.invert(A));const l=[A],g=r.transform(n.fromTranslation(n.create(),a),A),u=A.vertices.length;for(let h=0;h<u;h++){const d=h<u-1?h+1:0,m=r.create([A.vertices[h],g.vertices[h],g.vertices[d],A.vertices[d]]);l.push(m)}return l.push(r.invert(g)),i.create(l)};e.exports=s}}),nsi=yt({"node_modules/@jscad/modeling/src/operations/expansions/expandShell.js"(t,e){var{EPS:n,TAU:o}=sc(),i=Ig(),r=Jr(),s=_Zt(),a=va(),A=UA(),c=lZt(),l=FX(),g=CZt(),u=tsi(),h=(_,f,I)=>{const C=f.toString();if(_.has(C))_.get(C)[1].push(I);else{const y=[f,[I]];_.set(C,y)}},d=(_,f,I)=>{const C=f[0].toString(),y=f[1].toString(),x=C<y?`${C},${y}`:`${y},${C}`;if(_.has(x))_.get(x)[1].push(I);else{const E=[f,[I]];_.set(x,E)}},m=(_,f)=>{_.findIndex(C=>C===f)<0&&_.push(f)},p=(_,f)=>{const I={delta:1,segments:12},{delta:C,segments:y}=Object.assign({},I,_);let x=a.create();const E=new Map,B=new Map,b=r.create(),Q=r.create();return a.toPolygons(f).forEach((D,k)=>{const T=r.scale(r.create(),A.plane(D),2*C),H=A.transform(i.fromTranslation(i.create(),r.scale(r.create(),T,-.5)),D),G=u(T,H);x=g(x,G);const U=D.vertices;for(let Y=0;Y<U.length;Y++){h(E,U[Y],A.plane(D));const j=(Y+1)%U.length,ee=[U[Y],U[j]];d(B,ee,A.plane(D))}}),B.forEach(D=>{const k=D[0],T=D[1],H=k[0],G=k[1],U=r.subtract(r.create(),G,H);r.normalize(U,U);const Y=T[0],j=r.cross(r.create(),Y,U);let ee=[];for(let Ie=0;Ie<y;Ie++)m(ee,Ie*o/y);for(let Ie=0,ce=T.length;Ie<ce;Ie++){const fe=T[Ie],de=r.dot(j,fe),Ce=r.dot(Y,fe);let Qe=Math.atan2(de,Ce);Qe<0&&(Qe+=o),m(ee,Qe),Qe=Math.atan2(-de,-Ce),Qe<0&&(Qe+=o),m(ee,Qe)}ee=ee.sort(s);const W=ee.length;let Z,ie;const se=[],ne=[],le=[];for(let Ie=-1;Ie<W;Ie++){const ce=ee[Ie<0?Ie+W:Ie],fe=Math.sin(ce),de=Math.cos(ce);r.scale(b,Y,de*C),r.scale(Q,j,fe*C),r.add(b,b,Q);const Ce=r.add(r.create(),H,b),Qe=r.add(r.create(),G,b);let Pe=!1;if(Ie>=0&&r.distance(Ce,Z)<n&&(Pe=!0),!Pe){if(Ie>=0){se.push(Ce),ne.push(Qe);const pe=[ie,Qe,Ce,Z],ve=A.create(pe);le.push(ve)}Z=Ce,ie=Qe}}ne.reverse(),le.push(A.create(se)),le.push(A.create(ne));const he=a.create(le);x=g(x,he)}),E.forEach(D=>{const k=D[0],T=D[1],H=T[0];let G=null,U=0;for(let W=1;W<T.length;W++){const Z=T[W],ie=r.cross(b,H,Z),se=r.length(ie);se>.05&&se>U&&(U=se,G=Z)}G||(G=r.orthogonal(b,H));const Y=r.cross(b,H,G);r.normalize(Y,Y);const j=r.cross(Q,Y,H),ee=c({center:[k[0],k[1],k[2]],radius:C,segments:y,axes:[H,Y,j]});x=g(x,ee)}),l(x)};e.exports=p}}),osi=yt({"node_modules/@jscad/modeling/src/operations/expansions/expandGeom3.js"(t,e){var n=va(),o=iYe(),i=nsi(),r=(s,a)=>{const A={delta:1,corners:"round",segments:12},{delta:c,corners:l,segments:g}=Object.assign({},A,s);if(l!=="round")throw new Error('corners must be "round" for 3D geometries');if(n.toPolygons(a).length===0)throw new Error("the given geometry cannot be empty");s={delta:c,corners:l,segments:g};const h=i(s,a);return o(a,h)};e.exports=r}}),isi=yt({"node_modules/@jscad/modeling/src/operations/expansions/expandPath2.js"(t,e){var n=Iue(),o=lA(),i=Ta(),r=W0(),s=xue(),a=l=>{let{external:g,internal:u}=l;n(g)<0?g=g.reverse():u=u.reverse();const h=r.fromPoints({closed:!0},g),d=r.fromPoints({closed:!0},u),m=i.toSides(i.fromPoints(r.toPoints(h))),p=i.toSides(i.fromPoints(r.toPoints(d)));return m.push(...p),i.create(m)},A=(l,g,u,h)=>{const{points:d,external:m,internal:p}=l,_=Math.floor(g/2),f=[],I=[];if(u==="round"&&_>0){const y=Math.PI/_,x=d[d.length-1],E=o.angle(o.subtract(o.create(),m[m.length-1],x)),B=d[0],b=o.angle(o.subtract(o.create(),p[0],B));for(let Q=1;Q<_;Q++){let w=E+y*Q,D=o.fromAngleRadians(o.create(),w);o.scale(D,D,h),o.add(D,D,x),f.push(D),w=b+y*Q,D=o.fromAngleRadians(o.create(),w),o.scale(D,D,h),o.add(D,D,B),I.push(D)}}const C=[];return C.push(...m,...f,...p.reverse(),...I),i.fromPoints(C)},c=(l,g)=>{l=Object.assign({},{delta:1,corners:"edge",segments:16},l);const{delta:h,corners:d,segments:m}=l;if(h<=0)throw new Error("the given delta must be positive for paths");if(!(d==="edge"||d==="chamfer"||d==="round"))throw new Error('corners must be "edge", "chamfer", or "round"');const p=g.isClosed,_=r.toPoints(g);if(_.length===0)throw new Error("the given geometry cannot be empty");const f={points:_,external:s({delta:h,corners:d,segments:m,closed:p},_),internal:s({delta:-h,corners:d,segments:m,closed:p},_)};return g.isClosed?a(f):A(f,m,d,h)};e.exports=c}}),rYe=yt({"node_modules/@jscad/modeling/src/operations/expansions/expand.js"(t,e){var n=ra(),o=Ta(),i=va(),r=W0(),s=esi(),a=osi(),A=isi(),c=(l,...g)=>{if(g=n(g),g.length===0)throw new Error("wrong number of arguments");const u=g.map(h=>r.isA(h)?A(l,h):o.isA(h)?s(l,h):i.isA(h)?a(l,h):h);return u.length===1?u[0]:u};e.exports=c}}),rsi=yt({"node_modules/@jscad/modeling/src/operations/expansions/offsetGeom2.js"(t,e){var n=Ta(),o=YGe(),i=xue(),r=(s,a)=>{const A={delta:1,corners:"edge",segments:0},{delta:c,corners:l,segments:g}=Object.assign({},A,s);if(!(l==="edge"||l==="chamfer"||l==="round"))throw new Error('corners must be "edge", "chamfer", or "round"');const u=n.toOutlines(a),d=u.map(m=>(s={delta:u.reduce((f,I)=>f+o.arePointsInside(m,o.create(I)),0)%2===0?c:-c,corners:l,closed:!0,segments:g},i(s,m))).reduce((m,p)=>m.concat(n.toSides(n.fromPoints(p))),[]);return n.create(d)};e.exports=r}}),ssi=yt({"node_modules/@jscad/modeling/src/operations/expansions/offsetPath2.js"(t,e){var n=W0(),o=xue(),i=(r,s)=>{const a={delta:1,corners:"edge",closed:s.isClosed,segments:16},{delta:A,corners:c,closed:l,segments:g}=Object.assign({},a,r);if(!(c==="edge"||c==="chamfer"||c==="round"))throw new Error('corners must be "edge", "chamfer", or "round"');r={delta:A,corners:c,closed:l,segments:g};const u=o(r,n.toPoints(s));return n.fromPoints({closed:l},u)};e.exports=i}}),asi=yt({"node_modules/@jscad/modeling/src/operations/expansions/offset.js"(t,e){var n=ra(),o=Ta(),i=W0(),r=rsi(),s=ssi(),a=(A,...c)=>{if(c=n(c),c.length===0)throw new Error("wrong number of arguments");const l=c.map(g=>i.isA(g)?s(A,g):o.isA(g)?r(A,g):g);return l.length===1?l[0]:l};e.exports=a}}),BZt=yt({"node_modules/@jscad/modeling/src/operations/expansions/index.js"(t,e){e.exports={expand:rYe(),offset:asi()}}}),Eue=yt({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeLinearGeom2.js"(t,e){var n=Ig(),o=Jr(),i=Ta(),r=dG(),s=yue(),a=(A,c)=>{const l={offset:[0,0,1],twistAngle:0,twistSteps:12,repair:!0};let{offset:g,twistAngle:u,twistSteps:h,repair:d}=Object.assign({},l,A);if(h<1)throw new Error("twistSteps must be 1 or more");u===0&&(h=1);const m=o.clone(g),p=i.toSides(c);if(p.length===0)throw new Error("the given geometry cannot be empty");const _=r.fromSides(p);m[2]<0&&r.reverse(_,_);const f=n.create(),I=(C,y,x)=>{const E=y/h*u,B=o.scale(o.create(),m,y/h);return n.multiply(f,n.fromZRotation(f,E),n.fromTranslation(n.create(),B)),r.transform(f,x)};return A={numberOfSlices:h+1,capStart:!0,capEnd:!0,repair:d,callback:I},s(A,_)};e.exports=a}}),Asi=yt({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeLinearPath2.js"(t,e){var n=Ta(),o=W0(),i=Eue(),r=(s,a)=>{if(!a.isClosed)throw new Error("extruded path must be closed");const A=o.toPoints(a),c=n.fromPoints(A);return i(s,c)};e.exports=r}}),csi=yt({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeLinear.js"(t,e){var n=ra(),o=Ta(),i=W0(),r=Eue(),s=Asi(),a=(A,...c)=>{const l={height:1,twistAngle:0,twistSteps:1,repair:!0},{height:g,twistAngle:u,twistSteps:h,repair:d}=Object.assign({},l,A);if(c=n(c),c.length===0)throw new Error("wrong number of arguments");A={offset:[0,0,g],twistAngle:u,twistSteps:h,repair:d};const m=c.map(p=>i.isA(p)?s(A,p):o.isA(p)?r(A,p):p);return m.length===1?m[0]:m};e.exports=a}}),lsi=yt({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeRectangularPath2.js"(t,e){var n=W0(),o=rYe(),i=Eue(),r=(s,a)=>{const A={size:1,height:1},{size:c,height:l}=Object.assign({},A,s);if(s.delta=c,s.offset=[0,0,l],n.toPoints(a).length===0)throw new Error("the given geometry cannot be empty");const u=o(s,a);return i(s,u)};e.exports=r}}),gsi=yt({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeRectangularGeom2.js"(t,e){var{area:n}=DX(),o=Ta(),i=W0(),r=rYe(),s=Eue(),a=(A,c)=>{const l={size:1,height:1},{size:g,height:u}=Object.assign({},l,A);A.delta=g,A.offset=[0,0,u];const h=o.toOutlines(c);if(h.length===0)throw new Error("the given geometry cannot be empty");const m=h.map(_=>(n(_)<0&&_.reverse(),r(A,i.fromPoints({closed:!0},_)))).reduce((_,f)=>_.concat(o.toSides(f)),[]),p=o.create(m);return s(A,p)};e.exports=a}}),usi=yt({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeRectangular.js"(t,e){var n=ra(),o=Ta(),i=W0(),r=lsi(),s=gsi(),a=(A,...c)=>{const l={size:1,height:1},{size:g,height:u}=Object.assign({},l,A);if(c=n(c),c.length===0)throw new Error("wrong number of arguments");if(g<=0)throw new Error("size must be positive");if(u<=0)throw new Error("height must be positive");const h=c.map(d=>i.isA(d)?r(A,d):o.isA(d)?s(A,d):d);return h.length===1?h[0]:h};e.exports=a}}),dsi=yt({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeHelical.js"(t,e){var{TAU:n}=sc(),o=Ig(),i=Ta(),r=yue(),s=dG(),a=(A,c)=>{const l={angle:n,startAngle:0,pitch:10,height:0,endOffset:0,segmentsPerRotation:32};let{angle:g,startAngle:u,pitch:h,height:d,endOffset:m,segmentsPerRotation:p}=Object.assign({},l,A);if(d!=0&&(h=d/(g/n)),p<3)throw new Error("The number of segments per rotation needs to be at least 3.");const f=i.toSides(c);if(f.length===0)throw new Error("The given geometry cannot be empty");const I=f.filter(Q=>Q[0][0]>=0);let C=s.fromSides(f);I.length===0&&(C=s.reverse(C));const y=Math.round(p/n*Math.abs(g)),x=y>=2?y:2,E=o.create(),B=o.create(),b=(Q,w,D)=>{const k=u+g/x*w,T=m/x*w,H=(k-u)/n*h;return o.multiply(E,o.fromTranslation(o.create(),[T,0,H*Math.sign(g)]),o.fromXRotation(o.create(),-n/4*Math.sign(g))),o.multiply(B,o.fromZRotation(o.create(),k),E),s.transform(B,D)};return r({numberOfSlices:x+1,callback:b},C)};e.exports=a}}),hsi=yt({"node_modules/@jscad/modeling/src/operations/extrusions/project.js"(t,e){var n=ra(),o=zGe(),i=z6(),r=Ig(),s=Ta(),a=va(),A=UA(),c=_P(),l=EZt(),g=(h,d)=>{const m=i.fromNormalAndPoint(i.create(),h.axis,h.origin);if(Number.isNaN(m[0])||Number.isNaN(m[1])||Number.isNaN(m[2])||Number.isNaN(m[3]))throw new Error("project: invalid axis or origin");const p=c(d),_=p*p*Math.sqrt(3)/4;if(p===0)return s.create();const f=a.toPolygons(d);let I=[];for(let y=0;y<f.length;y++){const x=f[y].vertices.map(b=>i.projectionOfPoint(m,b)),E=A.create(x),B=A.plane(E);o(m,B)&&(A.measureArea(E)<_||I.push(E))}if(!o(m,[0,0,1])){const y=r.fromVectorRotation(r.create(),m,[0,0,1]);I=I.map(x=>A.transform(y,x))}I=I.sort((y,x)=>A.measureArea(x)-A.measureArea(y));const C=I.map(y=>s.fromPoints(y.vertices));return l(C)},u=(h,...d)=>{const m={axis:[0,0,1],origin:[0,0,0]},{axis:p,origin:_}=Object.assign({},m,h);if(d=n(d),d.length===0)throw new Error("wrong number of arguments");h={axis:p,origin:_};const f=d.map(I=>a.isA(I)?g(h,I):I);return f.length===1?f[0]:f};e.exports=u}}),HX=yt({"node_modules/@jscad/modeling/src/operations/extrusions/index.js"(t,e){e.exports={extrudeFromSlices:yue(),extrudeLinear:csi(),extrudeRectangular:usi(),extrudeRotate:hZt(),extrudeHelical:dsi(),project:hsi(),slice:dG()}}}),sYe=yt({"node_modules/@jscad/modeling/src/operations/hulls/hullPoints2.js"(t,e){var n=lA(),o=s=>{let a=n.fromValues(1/0,1/0);s.forEach(l=>{(l[1]<a[1]||l[1]===a[1]&&l[0]<a[0])&&(a=l)});const A=[];s.forEach(l=>{const g=r(l[1]-a[1],l[0]-a[0]),u=n.squaredDistance(l,a);A.push({point:l,angle:g,distSq:u})}),A.sort((l,g)=>l.angle!==g.angle?l.angle-g.angle:l.distSq-g.distSq);const c=[];return A.forEach(l=>{let g=c.length;for(;g>1&&i(c[g-2],c[g-1],l.point)<=Number.EPSILON;)c.pop(),g=c.length;c.push(l.point)}),c},i=(s,a,A)=>(a[0]-s[0])*(A[1]-s[1])-(a[1]-s[1])*(A[0]-s[0]),r=(s,a)=>s===0&&a===0?-1/0:-a/s;e.exports=o}}),aYe=yt({"node_modules/@jscad/modeling/src/operations/hulls/toUniquePoints.js"(t,e){var n=Ta(),o=va(),i=W0(),r=s=>{const a=new Set,A=[],c=l=>{const g=l.toString();a.has(g)||(A.push(l),a.add(g))};return s.forEach(l=>{n.isA(l)?n.toPoints(l).forEach(c):o.isA(l)?o.toPoints(l).forEach(g=>g.forEach(c)):i.isA(l)&&i.toPoints(l).forEach(c)}),A};e.exports=r}}),msi=yt({"node_modules/@jscad/modeling/src/operations/hulls/hullPath2.js"(t,e){var n=ra(),o=W0(),i=sYe(),r=aYe(),s=(...a)=>{a=n(a);const A=r(a),c=i(A);return o.fromPoints({closed:!0},c)};e.exports=s}}),psi=yt({"node_modules/@jscad/modeling/src/operations/hulls/hullGeom2.js"(t,e){var n=ra(),o=Ta(),i=sYe(),r=aYe(),s=(...a)=>{a=n(a);const A=r(a),c=i(A);return c.length<3?o.create():o.fromPoints(c)};e.exports=s}}),_si=yt({"node_modules/@jscad/modeling/src/operations/hulls/hullGeom3.js"(t,e){var n=ra(),o=va(),i=aYe(),r=nYe(),s=(...a)=>{a=n(a);const A=i(a);return A.length===0?o.create():o.create(r(A))};e.exports=s}}),SZt=yt({"node_modules/@jscad/modeling/src/operations/hulls/hull.js"(t,e){var n=ra(),o=kX(),i=Ta(),r=va(),s=W0(),a=msi(),A=psi(),c=_si(),l=(...g)=>{if(g=n(g),g.length===0)throw new Error("wrong number of arguments");if(!o(g))throw new Error("only hulls of the same type are supported");const u=g[0];return s.isA(u)?a(g):i.isA(u)?A(g):r.isA(u)?c(g):u};e.exports=l}}),fsi=yt({"node_modules/@jscad/modeling/src/operations/hulls/hullChain.js"(t,e){var n=ra(),o=iYe(),i=SZt(),r=(...s)=>{if(s=n(s),s.length<2)throw new Error("wrong number of arguments");const a=[];for(let A=1;A<s.length;A++)a.push(i(s[A-1],s[A]));return o(a)};e.exports=r}}),Isi=yt({"node_modules/@jscad/modeling/src/operations/hulls/index.js"(t,e){e.exports={hull:SZt(),hullChain:fsi(),hullPoints2:sYe(),hullPoints3:nYe()}}}),Csi=yt({"node_modules/@jscad/modeling/src/operations/minkowski/index.js"(t,e){e.exports={minkowskiSum:yZt()}}}),bZt=yt({"node_modules/@jscad/modeling/src/operations/modifiers/snapPolygons.js"(t,e){var n=Jr(),o=UA(),i=(s,a)=>{const A=Math.abs(o.measureArea(a));return Number.isFinite(A)&&A>s},r=(s,a)=>{let A=a.map(l=>{const g=l.vertices.map(d=>n.snap(n.create(),d,s)),u=[];for(let d=0;d<g.length;d++){const m=(d+1)%g.length;n.equals(g[d],g[m])||u.push(g[d])}const h=o.create(u);return l.color&&(h.color=l.color),h});const c=s*s*Math.sqrt(3)/4;return A=A.filter(l=>i(c,l)),A};e.exports=r}}),ysi=yt({"node_modules/@jscad/modeling/src/operations/modifiers/mergePolygons.js"(t,e){var n=zGe(),o=Jr(),i=UA(),r=_=>{const f=i.toPoints(_),I=[];for(let C=0;C<f.length;C++){const y=(C+1)%f.length,x={v1:f[C],v2:f[y]};I.push(x)}for(let C=0;C<I.length;C++){const y=(C+1)%f.length;I[C].next=I[y],I[y].prev=I[C]}return I},s=(_,f)=>{const I=`${f.v1}:${f.v2}`;_.set(I,f)},a=(_,f)=>{const I=`${f.v1}:${f.v2}`;_.delete(I)},A=(_,f)=>{const I=`${f.v2}:${f.v1}`;return _.get(I)},c=(_,f,I)=>{let C=_.prev.v1,y=_.prev.v2,x=f.next.v2;const E=u(C,y,x,I);C=f.prev.v1,y=f.prev.v2,x=_.next.v2;const B=u(C,y,x,I);return[E,B]},l=o.create(),g=o.create(),u=(_,f,I,C)=>{const y=o.subtract(l,f,_),x=o.subtract(g,I,f);return o.cross(y,y,x),o.dot(y,C)},h=_=>{let f;const I=[];for(;_.next;){const C=_.next;I.push(_.v1),_.v1=null,_.v2=null,_.next=null,_.prev=null,_=C}return I.length>0&&(f=i.create(I)),f},d=_=>{if(_.length<2)return _;const f=_[0].plane,I=_.slice(),C=new Map;for(;I.length>0;){const x=I.shift(),E=r(x);for(let B=0;B<E.length;B++){const b=E[B],Q=A(C,b);if(Q){const w=c(b,Q,f);if(w[0]>=0&&w[1]>=0){const D=Q.next,k=b.next;b.prev.next=Q.next,b.next.prev=Q.prev,Q.prev.next=b.next,Q.next.prev=b.prev,b.v1=null,b.v2=null,b.next=null,b.prev=null,a(C,Q),Q.v1=null,Q.v2=null,Q.next=null,Q.prev=null;const T=(H,G,U)=>{const Y={v1:U.v1,v2:G.v2,next:G.next,prev:U.prev};U.prev.next=Y,G.next.prev=Y,a(H,G),G.v1=null,G.v2=null,G.next=null,G.prev=null,a(H,U),U.v1=null,U.v2=null,U.next=null,U.prev=null};w[0]===0&&T(C,D,D.prev),w[1]===0&&T(C,k,k.prev)}}else b.next&&s(C,b)}}const y=[];return C.forEach(x=>{const E=h(x);E&&y.push(E)}),C.clear(),y},m=(_,f)=>Math.abs(_[3]-f[3])<15e-8?n(_,f):!1,p=(_,f)=>{const I=[];f.forEach(y=>{const x=I.find(E=>m(E[0],i.plane(y)));x?x[1].push(y):I.push([i.plane(y),[y]])});let C=[];return I.forEach(y=>{const x=y[1],E=d(x);C=C.concat(E)}),C};e.exports=p}}),xsi=yt({"node_modules/@jscad/modeling/src/operations/modifiers/insertTjunctions.js"(t,e){var n=sc(),o=Jr(),i=UA(),r=c=>`${c}`,s=(c,l,g,u,h,d)=>{const m=r(u),p=r(h),_=`${m}/${p}`,f=`${p}/${m}`;if(c.has(f))return a(c,l,g,h,u,null),null;const I={vertex0:u,vertex1:h,polygonindex:d};return c.has(_)?c.get(_).push(I):c.set(_,[I]),l.has(m)?l.get(m).push(_):l.set(m,[_]),g.has(p)?g.get(p).push(_):g.set(p,[_]),_},a=(c,l,g,u,h,d)=>{const m=r(u),p=r(h),_=`${m}/${p}`;let f=-1;const I=c.get(_);for(let C=0;C<I.length;C++){const y=I[C];let x=r(y.vertex0);if(x===m&&(x=r(y.vertex1),x===p&&!(d!==null&&y.polygonindex!==d))){f=C;break}}I.splice(f,1),I.length===0&&c.delete(_),f=l.get(m).indexOf(_),l.get(m).splice(f,1),l.get(m).length===0&&l.delete(m),f=g.get(p).indexOf(_),g.get(p).splice(f,1),g.get(p).length===0&&g.delete(p)},A=c=>{const l=new Map;for(let g=0;g<c.length;g++){const u=c[g],h=u.vertices.length;if(h>=3){let d=u.vertices[0],m=r(d);for(let p=0;p<h;p++){let _=p+1;_===h&&(_=0);const f=u.vertices[_],I=r(f),C=`${m}/${I}`,y=`${I}/${m}`;if(l.has(y)){const x=l.get(y);x.splice(-1,1),x.length===0&&l.delete(y)}else{const x={vertex0:d,vertex1:f,polygonindex:g};l.has(C)?l.get(C).push(x):l.set(C,[x])}d=f,m=I}}else console.warn("warning: invalid polygon found during insertTjunctions")}if(l.size>0){const g=new Map,u=new Map,h=new Map;for(const[m,p]of l)h.set(m,!0),p.forEach(_=>{const f=r(_.vertex0),I=r(_.vertex1);g.has(f)?g.get(f).push(m):g.set(f,[m]),u.has(I)?u.get(I).push(m):u.set(I,[m])});const d=c.slice(0);for(;l.size!==0;){for(const p of l.keys())h.set(p,!0);let m=!1;for(;;){const p=Array.from(h.keys());if(p.length===0)break;const _=p[0];let f=!0;if(l.has(_)){const C=l.get(_)[0];for(let y=0;y<2;y++){const x=y===0?C.vertex0:C.vertex1,E=y===0?C.vertex1:C.vertex0,B=r(x),b=r(E);let Q=[];y===0?u.has(B)&&(Q=u.get(B)):g.has(B)&&(Q=g.get(B));for(let w=0;w<Q.length;w++){const D=Q[w],k=l.get(D)[0],T=y===0?k.vertex0:k.vertex1;if(y===0?k.vertex1:k.vertex0,r(T)===b){a(l,g,u,x,E,null),a(l,g,u,E,x,null),f=!1,y=2,m=!0;break}else{const G=x,U=E,Y=T,j=o.subtract(o.create(),Y,G),ee=o.dot(o.subtract(o.create(),U,G),j)/o.dot(j,j);if(ee>0&&ee<1){const W=o.scale(o.create(),j,ee);if(o.add(W,W,G),o.squaredDistance(W,U)<n.EPS*n.EPS){const ie=k.polygonindex,se=d[ie],ne=r(k.vertex1);let le=-1;for(let de=0;de<se.vertices.length;de++)if(r(se.vertices[de])===ne){le=de;break}const he=se.vertices.slice(0);he.splice(le,0,E);const Ie=i.create(he);d[ie]=Ie,a(l,g,u,k.vertex0,k.vertex1,ie);const ce=s(l,g,u,k.vertex0,E,ie),fe=s(l,g,u,E,k.vertex1,ie);ce!==null&&h.set(ce,!0),fe!==null&&h.set(fe,!0),f=!1,y=2,m=!0;break}}}}}}f&&h.delete(_)}if(!m)break}c=d}return l.clear(),c};e.exports=A}}),Esi=yt({"node_modules/@jscad/modeling/src/operations/modifiers/triangulatePolygons.js"(t,e){var n=Jr(),o=UA(),i=(s,a,A)=>{const c=a.vertices.length;if(c>3){if(c>4){const u=[0,0,0];a.vertices.forEach(h=>n.add(u,u,h)),n.snap(u,n.divide(u,u,[c,c,c]),s);for(let h=0;h<c;h++){const d=o.create([u,a.vertices[h],a.vertices[(h+1)%c]]);a.color&&(d.color=a.color),A.push(d)}return}const l=o.create([a.vertices[0],a.vertices[1],a.vertices[2]]),g=o.create([a.vertices[0],a.vertices[2],a.vertices[3]]);a.color&&(l.color=a.color,g.color=a.color),A.push(l,g);return}A.push(a)},r=(s,a)=>{const A=[];return a.forEach(c=>{i(s,c,A)}),A};e.exports=r}}),Bsi=yt({"node_modules/@jscad/modeling/src/operations/modifiers/generalize.js"(t,e){var n=ra(),o=_P(),i=Ta(),r=va(),s=W0(),a=bZt(),A=ysi(),c=xsi(),l=Esi(),g=(m,p)=>p,u=(m,p)=>p,h=(m,p)=>{const _={snap:!1,simplify:!1,triangulate:!1},{snap:f,simplify:I,triangulate:C}=Object.assign({},_,m),y=o(p);let x=r.toPolygons(p);f&&(x=a(y,x)),I&&(x=A(y,x)),C&&(x=c(x),x=l(y,x));const E=Object.assign({},p);return E.polygons=x,E},d=(m,...p)=>{if(p=n(p),p.length===0)throw new Error("wrong number of arguments");const _=p.map(f=>{if(s.isA(f))return g(m,f);if(i.isA(f))return u(m,f);if(r.isA(f))return h(m,f);throw new Error("invalid geometry")});return _.length===1?_[0]:_};e.exports=d}}),Ssi=yt({"node_modules/@jscad/modeling/src/operations/modifiers/snap.js"(t,e){var n=ra(),o=lA(),i=Ta(),r=va(),s=W0(),a=_P(),A=bZt(),c=h=>{const d=a(h),p=s.toPoints(h).map(_=>o.snap(o.create(),_,d));return s.create(p)},l=h=>{const d=a(h);let p=i.toSides(h).map(_=>[o.snap(o.create(),_[0],d),o.snap(o.create(),_[1],d)]);return p=p.filter(_=>!o.equals(_[0],_[1])),i.create(p)},g=h=>{const d=a(h),m=r.toPolygons(h),p=A(d,m);return r.create(p)},u=(...h)=>{if(h=n(h),h.length===0)throw new Error("wrong number of arguments");const d=h.map(m=>s.isA(m)?c(m):i.isA(m)?l(m):r.isA(m)?g(m):m);return d.length===1?d[0]:d};e.exports=u}}),bsi=yt({"node_modules/@jscad/modeling/src/operations/modifiers/index.js"(t,e){e.exports={generalize:Bsi(),snap:Ssi(),retessellate:FX()}}}),Qsi=yt({"node_modules/@jscad/modeling/src/utils/padArrayToLength.js"(t,e){var n=(o,i,r)=>{for(o=o.slice();o.length<r;)o.push(i);return o};e.exports=n}}),vsi=yt({"node_modules/@jscad/modeling/src/operations/transforms/align.js"(t,e){var n=ra(),o=Qsi(),i=WGe(),{translate:r}=tR(),s=l=>{if(!Array.isArray(l.modes)||l.modes.length>3)throw new Error("align(): modes must be an array of length <= 3");if(l.modes=o(l.modes,"none",3),l.modes.filter(g=>["center","max","min","none"].includes(g)).length!==3)throw new Error('align(): all modes must be one of "center", "max" or "min"');if(!Array.isArray(l.relativeTo)||l.relativeTo.length>3)throw new Error("align(): relativeTo must be an array of length <= 3");if(l.relativeTo=o(l.relativeTo,0,3),l.relativeTo.filter(g=>Number.isFinite(g)||g==null).length!==3)throw new Error("align(): all relativeTo values must be a number, or null.");if(typeof l.grouped!="boolean")throw new Error("align(): grouped must be a boolean value.");return l},a=(l,g,u)=>{for(let h=0;h<3;h++)l[h]==null&&(g[h]==="center"?l[h]=(u[0][h]+u[1][h])/2:g[h]==="max"?l[h]=u[1][h]:g[h]==="min"&&(l[h]=u[0][h]));return l},A=(l,g,u)=>{const h=i(l),d=[0,0,0];for(let m=0;m<3;m++)g[m]==="center"?d[m]=u[m]-(h[0][m]+h[1][m])/2:g[m]==="max"?d[m]=u[m]-h[1][m]:g[m]==="min"&&(d[m]=u[m]-h[0][m]);return r(d,l)},c=(l,...g)=>{l=Object.assign({},{modes:["center","center","min"],relativeTo:[0,0,0],grouped:!1},l),l=s(l);let{modes:h,relativeTo:d,grouped:m}=l;if(g=n(g),g.length===0)throw new Error("align(): No geometries were provided to act upon");if(d.filter(p=>p==null).length){const p=i(g);d=a(d,h,p)}return m?g=A(g,h,d):g=g.map(p=>A(p,h,d)),g.length===1?g[0]:g};e.exports=c}}),Bue=yt({"node_modules/@jscad/modeling/src/operations/transforms/center.js"(t,e){var n=ra(),o=Ta(),i=va(),r=W0(),s=ZN(),{translate:a}=tR(),A=(h,d)=>{const m={axes:[!0,!0,!0],relativeTo:[0,0,0]},{axes:p,relativeTo:_}=Object.assign({},m,h),f=s(d),I=[0,0,0];return p[0]&&(I[0]=_[0]-(f[0][0]+(f[1][0]-f[0][0])/2)),p[1]&&(I[1]=_[1]-(f[0][1]+(f[1][1]-f[0][1])/2)),p[2]&&(I[2]=_[2]-(f[0][2]+(f[1][2]-f[0][2])/2)),a(I,d)},c=(h,...d)=>{const m={axes:[!0,!0,!0],relativeTo:[0,0,0]},{axes:p,relativeTo:_}=Object.assign({},m,h);if(d=n(d),d.length===0)throw new Error("wrong number of arguments");if(_.length!==3)throw new Error("relativeTo must be an array of length 3");h={axes:p,relativeTo:_};const f=d.map(I=>r.isA(I)||o.isA(I)||i.isA(I)?A(h,I):I);return f.length===1?f[0]:f},l=(...h)=>c({axes:[!0,!1,!1]},h),g=(...h)=>c({axes:[!1,!0,!1]},h),u=(...h)=>c({axes:[!1,!1,!0]},h);e.exports={center:c,centerX:l,centerY:g,centerZ:u}}}),Sue=yt({"node_modules/@jscad/modeling/src/operations/transforms/scale.js"(t,e){var n=ra(),o=Ig(),i=Ta(),r=va(),s=W0(),a=(g,...u)=>{if(!Array.isArray(g))throw new Error("factors must be an array");if(u=n(u),u.length===0)throw new Error("wrong number of arguments");for(g=g.slice();g.length<3;)g.push(1);if(g[0]<=0||g[1]<=0||g[2]<=0)throw new Error("factors must be positive");const h=o.fromScaling(o.create(),g),d=u.map(m=>s.isA(m)?s.transform(h,m):i.isA(m)?i.transform(h,m):r.isA(m)?r.transform(h,m):m);return d.length===1?d[0]:d},A=(g,...u)=>a([g,1,1],u),c=(g,...u)=>a([1,g,1],u),l=(g,...u)=>a([1,1,g],u);e.exports={scale:a,scaleX:A,scaleY:c,scaleZ:l}}}),Psi=yt({"node_modules/@jscad/modeling/src/operations/transforms/transform.js"(t,e){var n=ra(),o=Ta(),i=va(),r=W0(),s=(a,...A)=>{if(A=n(A),A.length===0)throw new Error("wrong number of arguments");const c=A.map(l=>r.isA(l)?r.transform(a,l):o.isA(l)?o.transform(a,l):i.isA(l)?i.transform(a,l):l);return c.length===1?c[0]:c};e.exports=s}}),oR=yt({"node_modules/@jscad/modeling/src/operations/transforms/index.js"(t,e){e.exports={align:vsi(),center:Bue().center,centerX:Bue().centerX,centerY:Bue().centerY,centerZ:Bue().centerZ,mirror:RX().mirror,mirrorX:RX().mirrorX,mirrorY:RX().mirrorY,mirrorZ:RX().mirrorZ,rotate:TX().rotate,rotateX:TX().rotateX,rotateY:TX().rotateY,rotateZ:TX().rotateZ,scale:Sue().scale,scaleX:Sue().scaleX,scaleY:Sue().scaleY,scaleZ:Sue().scaleZ,transform:Psi(),translate:tR().translate,translateX:tR().translateX,translateY:tR().translateY,translateZ:tR().translateZ}}}),bue=yt({"node_modules/@jscad/modeling/src/index.js"(t,e){e.exports={colors:fue(),curves:Eii(),geometries:UGe(),maths:Wii(),measurements:nri(),primitives:nR(),text:Rri(),utils:fZt(),booleans:LX(),expansions:BZt(),extrusions:HX(),hulls:Isi(),minkowski:Csi(),modifiers:bsi(),transforms:oR()}}}),QZt=yt({"node_modules/jscad-planner/dist/index.cjs"(t,e){var n=Object.defineProperty,o=Object.getOwnPropertyDescriptor,i=Object.getOwnPropertyNames,r=Object.prototype.hasOwnProperty,s=(u,h)=>{for(var d in h)n(u,d,{get:h[d],enumerable:!0})},a=(u,h,d,m)=>{if(h&&typeof h=="object"||typeof h=="function")for(let p of i(h))!r.call(u,p)&&p!==d&&n(u,p,{get:()=>h[p],enumerable:!(m=o(h,p))||m.enumerable});return u},A=u=>a(n({},"__esModule",{value:!0}),u),c={};s(c,{executeJscadOperations:()=>g,jscadPlanner:()=>l}),e.exports=A(c);var l={booleans:{intersect:(...u)=>({type:"intersect",shapes:u}),subtract:(...u)=>({type:"subtract",shapes:u}),union:(...u)=>({type:"union",shapes:u})},hulls:{hull:(...u)=>({type:"hull",shapes:u.flat()}),hullChain:(...u)=>({type:"hullChain",shapes:u.flat()})},colors:{colorize:(u,h)=>({type:"colorize",color:u,shape:h})},primitives:{cube:u=>({type:"cube",...u}),sphere:u=>({type:"sphere",...u}),cylinder:u=>({type:"cylinder",...u}),polygon:u=>({type:"polygon",...u}),cuboid:u=>({type:"cuboid",...u}),roundedCuboid:u=>({type:"roundedCuboid",...u})},transforms:{rotate:(u,h)=>({type:"rotate",angles:u,shape:h}),scale:(u,h)=>({type:"scale",factors:u,shape:h}),translate:(u,h)=>({type:"translate",vector:u,shape:h})},extrusions:{extrudeLinear:(u,h)=>({type:"extrudeLinear",options:u,shape:h}),extrudeRotate:(u,h)=>({type:"extrudeRotate",options:u,shape:h})},maths:{vec2:{create:(u,h)=>[u,h],fromValues:(u,h)=>[u,h]},vec3:{create:(u,h,d)=>[u,h,d],fromValues:(u,h,d)=>[u,h,d]}},geometries:{geom2:{create:u=>({type:"createGeom2",points:u})},geom3:{create:u=>({type:"createGeom3",polygons:u})},path2:{create:u=>({type:"createPath2",points:u})}},measurements:{measureBoundingBox:u=>({type:"measureBoundingBox",shape:u}),measureArea:u=>({type:"measureArea",shape:u}),measureVolume:u=>({type:"measureVolume",shape:u})},utils:{degToRad:u=>u*Math.PI/180,radToDeg:u=>u*180/Math.PI}},g=(u,h)=>{if(Array.isArray(h)&&h.length===1)return g(u,h[0]);if(Array.isArray(h))throw new Error("executeJscadOperations currently doesn't support Array<JscadOperation>, try adding a root union or or executing each element individually");const d=_=>g(u,_),{type:m,...p}=h;switch(m){case"intersect":return u.booleans.intersect(...h.shapes.map(d));case"subtract":return u.booleans.subtract(...h.shapes.map(d));case"union":return u.booleans.union(...h.shapes.map(d));case"hull":return u.hulls.hull(...h.shapes.map(d));case"hullChain":return u.hulls.hullChain(...h.shapes.map(d));case"colorize":return u.colors.colorize(h.color,d(h.shape));case"cube":return u.primitives.cube(p);case"sphere":return u.primitives.sphere(p);case"cylinder":return u.primitives.cylinder(p);case"polygon":return u.primitives.polygon(p);case"cuboid":return u.primitives.cuboid(p);case"roundedCuboid":return u.primitives.roundedCuboid(p);case"rotate":return u.transforms.rotate(h.angles,d(h.shape));case"scale":return u.transforms.scale(h.factors,d(h.shape));case"translate":return u.transforms.translate(h.vector,d(h.shape));case"extrudeLinear":return u.extrusions.extrudeLinear(h.options,d(h.shape));case"extrudeRotate":return u.extrusions.extrudeRotate(h.options,d(h.shape));case"createGeom2":return u.geometries.geom2.create(h.points);case"createGeom3":return u.geometries.geom3.create(h.polygons);case"createPath2":return u.geometries.path2.create(h.points);case"measureBoundingBox":return u.measurements.measureBoundingBox(d(h.shape));case"measureArea":return u.measurements.measureArea(d(h.shape));case"measureVolume":return u.measurements.measureVolume(d(h.shape));case"degToRad":return u.utils.degToRad(h.degrees);case"radToDeg":return u.utils.radToDeg(h.radians);default:throw h.type===void 0?new Error(`Operation type is undefined. This usually means the operation object is malformed or not properly initialized. Operation: ${JSON.stringify(h,null,2).slice(0,200)}...`):new Error(`Unsupported operation type: ${h.type}. Operation: ${JSON.stringify(h,null,2)}`)}}}}),wsi=yt({"node_modules/ms/index.js"(t,e){var n=1e3,o=n*60,i=o*60,r=i*24,s=r*7,a=r*365.25;e.exports=function(u,h){h=h||{};var d=typeof u;if(d==="string"&&u.length>0)return A(u);if(d==="number"&&isFinite(u))return h.long?l(u):c(u);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(u))};function A(u){if(u=String(u),!(u.length>100)){var h=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(u);if(h){var d=parseFloat(h[1]),m=(h[2]||"ms").toLowerCase();switch(m){case"years":case"year":case"yrs":case"yr":case"y":return d*a;case"weeks":case"week":case"w":return d*s;case"days":case"day":case"d":return d*r;case"hours":case"hour":case"hrs":case"hr":case"h":return d*i;case"minutes":case"minute":case"mins":case"min":case"m":return d*o;case"seconds":case"second":case"secs":case"sec":case"s":return d*n;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return d;default:return}}}}function c(u){var h=Math.abs(u);return h>=r?Math.round(u/r)+"d":h>=i?Math.round(u/i)+"h":h>=o?Math.round(u/o)+"m":h>=n?Math.round(u/n)+"s":u+"ms"}function l(u){var h=Math.abs(u);return h>=r?g(u,h,r,"day"):h>=i?g(u,h,i,"hour"):h>=o?g(u,h,o,"minute"):h>=n?g(u,h,n,"second"):u+" ms"}function g(u,h,d,m){var p=h>=d*1.5;return Math.round(u/d)+" "+m+(p?"s":"")}}}),Msi=yt({"node_modules/debug/src/common.js"(t,e){function n(o){r.debug=r,r.default=r,r.coerce=g,r.disable=c,r.enable=a,r.enabled=l,r.humanize=wsi(),r.destroy=u,Object.keys(o).forEach(h=>{r[h]=o[h]}),r.names=[],r.skips=[],r.formatters={};function i(h){let d=0;for(let m=0;m<h.length;m++)d=(d<<5)-d+h.charCodeAt(m),d|=0;return r.colors[Math.abs(d)%r.colors.length]}r.selectColor=i;function r(h){let d,m=null,p,_;function f(...I){if(!f.enabled)return;const C=f,y=Number(new Date),x=y-(d||y);C.diff=x,C.prev=d,C.curr=y,d=y,I[0]=r.coerce(I[0]),typeof I[0]!="string"&&I.unshift("%O");let E=0;I[0]=I[0].replace(/%([a-zA-Z%])/g,(b,Q)=>{if(b==="%%")return"%";E++;const w=r.formatters[Q];if(typeof w=="function"){const D=I[E];b=w.call(C,D),I.splice(E,1),E--}return b}),r.formatArgs.call(C,I),(C.log||r.log).apply(C,I)}return f.namespace=h,f.useColors=r.useColors(),f.color=r.selectColor(h),f.extend=s,f.destroy=r.destroy,Object.defineProperty(f,"enabled",{enumerable:!0,configurable:!1,get:()=>m!==null?m:(p!==r.namespaces&&(p=r.namespaces,_=r.enabled(h)),_),set:I=>{m=I}}),typeof r.init=="function"&&r.init(f),f}function s(h,d){const m=r(this.namespace+(typeof d>"u"?":":d)+h);return m.log=this.log,m}function a(h){r.save(h),r.namespaces=h,r.names=[],r.skips=[];const d=(typeof h=="string"?h:"").trim().replace(/\s+/g,",").split(",").filter(Boolean);for(const m of d)m[0]==="-"?r.skips.push(m.slice(1)):r.names.push(m)}function A(h,d){let m=0,p=0,_=-1,f=0;for(;m<h.length;)if(p<d.length&&(d[p]===h[m]||d[p]==="*"))d[p]==="*"?(_=p,f=m,p++):(m++,p++);else if(_!==-1)p=_+1,f++,m=f;else return!1;for(;p<d.length&&d[p]==="*";)p++;return p===d.length}function c(){const h=[...r.names,...r.skips.map(d=>"-"+d)].join(",");return r.enable(""),h}function l(h){for(const d of r.skips)if(A(h,d))return!1;for(const d of r.names)if(A(h,d))return!0;return!1}function g(h){return h instanceof Error?h.stack||h.message:h}function u(){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 r.enable(r.load()),r}e.exports=n}}),Dsi=yt({"node_modules/debug/src/browser.js"(t,e){t.formatArgs=o,t.save=i,t.load=r,t.useColors=n,t.storage=s(),t.destroy=(()=>{let A=!1;return()=>{A||(A=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),t.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"];function n(){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 o(A){if(A[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+A[0]+(this.useColors?"%c ":" ")+"+"+e.exports.humanize(this.diff),!this.useColors)return;const c="color: "+this.color;A.splice(1,0,c,"color: inherit");let l=0,g=0;A[0].replace(/%[a-zA-Z%]/g,u=>{u!=="%%"&&(l++,u==="%c"&&(g=l))}),A.splice(g,0,c)}t.log=console.debug||console.log||(()=>{});function i(A){try{A?t.storage.setItem("debug",A):t.storage.removeItem("debug")}catch{}}function r(){let A;try{A=t.storage.getItem("debug")||t.storage.getItem("DEBUG")}catch{}return!A&&typeof NGe<"u"&&"env"in NGe&&(A=NGe.env.DEBUG),A}function s(){try{return localStorage}catch{}}e.exports=Msi()(t);var{formatters:a}=e.exports;a.j=function(A){try{return JSON.stringify(A)}catch(c){return"[UnexpectedJSONParseError]: "+c.message}}}}),AYe=["translucent","opaque","hidden"],Nsi=t=>AYe[(AYe.indexOf(t)+1)%AYe.length],vZt={boardBody:!0,topCopper:!0,bottomCopper:!0,keepout:!0,adhesive:!1,solderPaste:!1,topSilkscreen:!0,bottomSilkscreen:!0,topMask:!0,bottomMask:!0,throughHoleModels:!0,smtModels:!0,translucentModels:!0,modelsNotInPosFile:!1,modelsMarkedDNP:!1,modelBoundingBoxes:!1,threedAxis:!1,pcbNotes:!1,backgroundStart:!0,backgroundEnd:!0,enclosure:"translucent"},PZt=te.createContext(void 0),Rsi=({children:t})=>{const[e,n]=te.useState(vZt),o=te.useCallback((s,a)=>{n(A=>({...A,[s]:a}))},[]),i=te.useCallback(()=>{n(vZt)},[]),r=te.useMemo(()=>({visibility:e,setLayerVisibility:o,resetToDefaults:i}),[e,o,i]);return z.jsx(PZt.Provider,{value:r,children:t})},iR=()=>{const t=te.useContext(PZt);if(!t)throw new Error("useLayerVisibility must be used within a LayerVisibilityProvider");return t},cYe=1.2;function wZt(t){return te.useMemo(()=>{if(!t)return cYe;try{return Ir(t).pcb_board.list()[0]?.thickness??cYe}catch{return cYe}},[t])}var MZt=te.createContext(null),J1=()=>{const t=te.useContext(MZt);if(!t)throw new Error("useThree must be used within a ThreeProvider");return t},OX=(t,e=[])=>{const{addFrameListener:n,removeFrameListener:o}=J1();ws.useEffect(()=>(n(t),()=>o(t)),[n,o,...e])},GX={clickToInteractOverlay:100,htmlElements:95,orientationCube:95,contextMenu:90,appearanceMenu:91},DZt=({children:t,position:e,style:n})=>{const{camera:o,renderer:i}=J1(),r=te.useRef(document.createElement("div")),[s,a]=te.useState(null);return te.useEffect(()=>{const A=i?.domElement.parentNode;if(A)return A.style.position!=="relative"&&A.style.position!=="absolute"&&(A.style.position="relative"),A.appendChild(r.current),a(Net.createPortal(t,r.current)),()=>{A.contains(r.current)&&A.removeChild(r.current)}},[i,t]),OX(()=>{if(!o||!r.current||!i)return;const A=new jt(...e);A.project(o);const c=i.domElement.getBoundingClientRect(),l=Math.round((A.x+1)/2*c.width),g=Math.round((-A.y+1)/2*c.height);r.current.style.position="absolute",r.current.style.left=`${l}px`,r.current.style.top=`${g}px`,r.current.style.pointerEvents="none",r.current.style.zIndex=GX.htmlElements.toString(),n&&Object.assign(r.current.style,n)},[o,i,e,n]),s},NZt={in:25.4,inch:25.4,mil:.0254,mm:1,m:1e3,cm:10,ft:304.8,feet:304.8},za=t=>{let e=typeof t=="number"?"mm":t.replace(/^[^a-zA-Z]+/g,"").toLowerCase();e||(e="mm");const n=typeof t=="number"?t:Number.parseFloat(t.split(e)[0]);if(e in NZt)return n*NZt[e];throw new Error(`Unsupported unit: ${e}`)},Dh=za,Tsi=Object.defineProperty,ksi=(t,e)=>{for(var n in e)Tsi(t,n,{get:e[n],enumerable:!0})},BS={};ksi(BS,{axial:()=>dAi,bga:()=>mai,breakoutheaders:()=>bAi,cap:()=>Ksi,dfn:()=>Jai,diode:()=>Usi,dip:()=>Hsi,electrolytic:()=>x0i,hc49:()=>PAi,jst:()=>Hli,led:()=>Vsi,lqfp:()=>BAi,m2host:()=>V0i,melf:()=>Jci,micromelf:()=>qci,minimelf:()=>Hci,mlp:()=>Bai,mountedpcbmodule:()=>J0i,ms012:()=>eAi,ms013:()=>nAi,msop:()=>jli,pad:()=>wAi,pinrow:()=>jai,platedhole:()=>T0i,potentiometer:()=>I0i,pushbutton:()=>fAi,qfn:()=>yai,qfp:()=>Eai,quad:()=>mG,radial:()=>pAi,res:()=>uai,sma:()=>tli,smb:()=>cli,smbf:()=>B0i,smc:()=>dli,smf:()=>rli,smtpad:()=>N0i,sod110:()=>Gli,sod123:()=>cAi,sod123f:()=>uci,sod123fl:()=>pci,sod123w:()=>zAi,sod128:()=>Bci,sod323:()=>XAi,sod323f:()=>Aci,sod323fl:()=>t0i,sod323w:()=>qli,sod523:()=>kAi,sod723:()=>Cci,sod80:()=>YAi,sod882:()=>ici,sod882d:()=>Uci,sod923:()=>eci,soic:()=>_ai,solderjumper:()=>l0i,son:()=>r0i,sop8:()=>OAi,sot:()=>F0i,sot223:()=>_li,sot23:()=>Oai,sot23w:()=>bli,sot25:()=>Kai,sot323:()=>P0i,sot343:()=>G0i,sot363:()=>Nai,sot457:()=>d0i,sot563:()=>$ai,sot723:()=>iAi,sot886:()=>kai,sot89:()=>Rci,sot963:()=>p0i,ssop:()=>Qai,stampboard:()=>CAi,stampreceiver:()=>EAi,to220:()=>$Zt,to220f:()=>Fci,to92:()=>RAi,to92l:()=>q0i,to92s:()=>Dli,tqfp:()=>xai,tssop:()=>wai,vson:()=>a0i,vssop:()=>zli});var tr=(t,e,n)=>({type:"pcb_silkscreen_text",pcb_silkscreen_text_id:"silkscreen_text_1",font:"tscircuit2024",font_size:n,pcb_component_id:"pcb_component_1",text:"{REF}",layer:"top",anchor_position:{x:t,y:e},anchor_alignment:"center"}),Xi=Pt({norefdes:We().optional().describe("disable reference designator label"),invert:We().optional().describe("hint to invert the orientation of the 3D model"),faceup:We().optional().describe("The male pin header should face upwards, out of the top layer"),nosilkscreen:We().optional().describe("omit all silkscreen elements from the footprint")}),ka=(t,e,n,o,i)=>({pcb_plated_hole_id:"",type:"pcb_plated_hole",shape:"circle",x:e,y:n,hole_diameter:za(o),outer_diameter:za(i),pcb_port_id:"",layers:["top","bottom"],port_hints:[t.toString()]}),px=t=>{const{pn:e,x:n,y:o,holeDiameter:i,rectPadWidth:r,rectPadHeight:s,holeOffsetX:a=0,holeOffsetY:A=0,rectBorderRadius:c}=t;return{pcb_plated_hole_id:"",type:"pcb_plated_hole",shape:"circular_hole_with_rect_pad",x:n,y:o,hole_diameter:za(i),hole_shape:"circle",pad_shape:"rect",rect_pad_width:za(r),rect_pad_height:za(s),...c!==void 0&&{rect_border_radius:c},pcb_port_id:"",layers:["top","bottom"],port_hints:[e.toString()],hole_offset_x:a,hole_offset_y:A}},Que=Array.from({length:9},(t,e)=>Math.cos(e/8*Math.PI-Math.PI)).map(t=>({x:t,y:-Math.sqrt(1-t**2)})),Dy=t=>{if(t.length<2)throw new Error("Rect union outline requires at least two bounds");for(const c of t)if(c.minX>=c.maxX||c.minY>=c.maxY)throw new Error("Each rectangle bound must have min < max on both axes");for(let c=1;c<t.length;c++){const l=t[c-1],g=t[c];if(g.minX<l.minX||g.maxX>l.maxX||g.minY>l.minY||g.maxY<l.maxY)throw new Error("Bounds must be ordered outer-to-inner with tighter X and larger Y span")}const e=()=>{const c=[];let l=t.length-1;for(c.push({x:t[l].minX,y:t[l].maxY});l>0;){const g=t[l],u=t[l-1];c.push({x:g.minX,y:u.maxY}),c.push({x:u.minX,y:u.maxY}),l-=1}return c},n=()=>{const c=[];let l=t.length-1;for(c.push({x:t[l].maxX,y:t[l].maxY});l>0;){const g=t[l],u=t[l-1];c.push({x:g.maxX,y:u.maxY}),c.push({x:u.maxX,y:u.maxY}),l-=1}return c},o=()=>{const c=[];let l=t.length-1;for(c.push({x:t[l].maxX,y:t[l].minY});l>0;){const g=t[l],u=t[l-1];c.push({x:g.maxX,y:u.minY}),c.push({x:u.maxX,y:u.minY}),l-=1}return c},i=()=>{const c=[];let l=t.length-1;for(c.push({x:t[l].minX,y:t[l].minY});l>0;){const g=t[l],u=t[l-1];c.push({x:g.minX,y:u.minY}),c.push({x:u.minX,y:u.minY}),l-=1}return c},r=e(),s=n(),a=o(),A=i();return[...r.reverse(),...s,...a.reverse(),...A]};function fP(t){return typeof t=="string"?t.trim().toLowerCase().endsWith("mil")?parseFloat(t)*.0254:parseFloat(t):Number(t)}var vue=Eo([$(),ft()]).transform(t=>fP(t)),Fsi=t=>Xi.extend({fn:$(),num_pins:ft().optional().default(6),wide:We().optional(),narrow:We().optional(),w:vue.optional(),p:vue.default(t.p??"2.54mm"),id:vue.optional(),od:vue.optional(),nosquareplating:We().optional().default(!1).describe("do not use rectangular pad for pin 1")}).transform(e=>(!e.id&&!e.od?Math.abs(e.p-1.27)<.01?(e.id=fP("0.55mm"),e.od=fP("0.95mm")):(e.id=fP("0.8mm"),e.od=fP("1.6mm")):e.id?e.od||(e.od=e.id*(1.5/1)):e.id=e.od*(1/1.5),e.w||(e.wide?e.w=fP("600mil"):e.narrow?e.w=fP("300mil"):e.w=fP(t.w??"300mil")),e)),Lsi=Fsi({}),RZt=(t,e,n,o,i)=>{const r=t/2,s=e<=r,a=r-1,A=o,c=A*a;return s?{x:-n/2,y:c/2-(e-1)*A}:{x:n/2,y:-c/2+(e-r-1)*A}},Hsi=t=>{const e=Lsi.parse(t),n=[];for(let _=0;_<e.num_pins;_++){const{x:f,y:I}=RZt(e.num_pins,_+1,e.w,e.p??2.54,e.nosquareplating);if(_===0&&!e.nosquareplating){n.push(px({pn:_+1,x:f,y:I,holeDiameter:e.id??"0.8mm",rectPadWidth:e.od??"1mm",rectPadHeight:e.od??"1mm"}));continue}n.push(ka(_+1,f,I,e.id??"0.8mm",e.od??"1mm"))}const o=(e.num_pins/2-1)*e.p+e.od,r=e.w-e.od-1,s=(e.num_pins/2-1)*e.p+e.od+.4,a={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-r/2,y:-s/2},{x:-r/2,y:s/2},...Que.map(({x:_,y:f})=>({x:_*r/6,y:f*r/6+s/2})),{x:r/2,y:s/2},{x:r/2,y:-s/2},{x:-r/2,y:-s/2}],type:"pcb_silkscreen_path",stroke_width:.1},A=[];for(let _=0;_<e.num_pins;_++){const f=_<e.num_pins/2,I=.6,{y:C}=RZt(e.num_pins,_+1,e.w,e.p??2.54,e.nosquareplating),y=f?-e.w/2-e.od/2-I:e.w/2+e.od/2+I,x=C;A.push({type:"pcb_fabrication_note_text",pcb_fabrication_note_text_id:`pin_${_+1}`,layer:"top",pcb_component_id:`pin_${_+1}`,text:`{pin${_+1}}`,anchor_position:{x:y,y:x},font_size:.3,font:"tscircuit2024",anchor_alignment:"top_left"})}const c=tr(0,s/2+.5,.4),l=e.w+e.od,g=o,u=l/2+.25,h=u,d=g/2+.72,m=d,p={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",outline:Dy([{minX:-u,maxX:u,minY:-m,maxY:m},{minX:-h,maxX:h,minY:-d,maxY:d}]),layer:"top"};return{circuitJson:[...n,a,c,...A,p],parameters:e}},yi=(t,e,n,o,i,r)=>({type:"pcb_smtpad",x:e,y:n,width:o,height:i,layer:"top",shape:"rect",...r!==void 0&&{corner_radius:r},pcb_smtpad_id:"",port_hints:Array.isArray(t)?t.map(s=>s.toString()):[t.toString()]}),TZt=[{imperial:"01005",metric:"0402",p_mm_min:.5,pw_mm_min:.4,ph_mm_min:.3,w_mm_min:.58,h_mm_min:.21,courtyard_width_mm:1.2,courtyard_height_mm:.6},{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,courtyard_width_mm:5.9,courtyard_height_mm:3.9,nonpolarizedSilkscreen:{line_half_length_mm:1.386252,line_y_mm:1.71,stroke_width_mm:.12}},{imperial:"0201",metric:"0603",p_mm_min:.66,pw_mm_min:.46,ph_mm_min:.4,w_mm_min:.9,h_mm_min:.3,courtyard_width_mm:1.4,courtyard_height_mm:.7},{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,courtyard_width_mm:1.86,courtyard_height_mm:.94,nonpolarizedSilkscreen:{line_half_length_mm:.153641,line_y_mm:.38,stroke_width_mm:.12}},{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,courtyard_width_mm:2.96,courtyard_height_mm:1.46,nonpolarizedSilkscreen:{line_half_length_mm:.237258,line_y_mm:.5225,stroke_width_mm:.12}},{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,courtyard_width_mm:3.36,courtyard_height_mm:1.9,nonpolarizedSilkscreen:{line_half_length_mm:.227064,line_y_mm:.735,stroke_width_mm:.12}},{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,courtyard_width_mm:4.56,courtyard_height_mm:2.26,nonpolarizedSilkscreen:{line_half_length_mm:.727064,line_y_mm:.91,stroke_width_mm:.12}},{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,courtyard_width_mm:4.56,courtyard_height_mm:3.16,nonpolarizedSilkscreen:{line_half_length_mm:.723737,line_y_mm:1.355,stroke_width_mm:.12}},{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,courtyard_width_mm:6.36,courtyard_height_mm:3.16,nonpolarizedSilkscreen:{line_half_length_mm:1.527064,line_y_mm:1.36,stroke_width_mm:.12}},{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,courtyard_width_mm:7.66,courtyard_height_mm:3.86,nonpolarizedSilkscreen:{line_half_length_mm:2.177064,line_y_mm:1.71,stroke_width_mm:.12}}],Osi=Object.fromEntries(TZt.map(t=>[t.metric,t])),Gsi=Object.fromEntries(TZt.map(t=>[t.imperial,t])),Ysi=(t,e)=>({type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:0,y:0},width:t,height:e,layer:"top"});Xi.extend({fn:$().optional(),string:$().optional(),tht:We(),p:ue.optional(),pw:ue.optional(),ph:ue.optional(),metric:ct.optional(),imperial:ct.optional(),w:ue.optional(),h:ue.optional(),nonpolarized:We().optional(),textbottom:We().optional(),roundedPads:We().optional()});var Pue=t=>{let{fn:e,tht:n,p:o,pw:i,ph:r,metric:s,imperial:a,w:A,h:c,nonpolarized:l,textbottom:g,roundedPads:u,string:h}=t;if(typeof A=="string"&&(A=Dh(A)),typeof c=="string"&&(c=Dh(c)),typeof o=="string"&&(o=Dh(o)),typeof i=="string"&&(i=Dh(i)),typeof r=="string"&&(r=Dh(r)),c!==void 0&&A!==void 0&&c>A)throw new Error("height cannot be greater than width (rotated footprint not yet implemented)");let d;if(s&&(d=Osi[s]),a&&(d=Gsi[a]),d&&(A=d.w_mm_min,c=d.h_mm_min,o=d.p_mm_min,i=d.pw_mm_min,r=d.ph_mm_min),o===void 0||i===void 0||r===void 0)throw new Error("Could not determine required pad dimensions (p, pw, ph)");let m=[];const p=e==="res"&&(l===!0||typeof h!="string"||/^res(?:\d{4}|\d{5})(?:_|$)/i.test(h))?d?.nonpolarizedSilkscreen:void 0;if(p?.stroke_width_mm){const{line_half_length_mm:y=0,line_y_mm:x=0,stroke_width_mm:E}=p;m=[{type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-y,y:x},{x:y,y:x}],stroke_width:E,pcb_silkscreen_path_id:""},{type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-y,y:-x},{x:y,y:-x}],stroke_width:E,pcb_silkscreen_path_id:""}]}else m=[{type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:o/2,y:r/2+.4},{x:-o/2-i/2-.2,y:r/2+.4},{x:-o/2-i/2-.2,y:-r/2-.4},{x:o/2,y:-r/2-.4}],stroke_width:.1,pcb_silkscreen_path_id:""}];const _=g?-r/2-.9:r/2+.9,f=tr(0,_,.2),I=d?.courtyard_width_mm&&d.courtyard_height_mm?Ysi(d.courtyard_width_mm,d.courtyard_height_mm):null,C=u?Math.min(.125,Math.min(i,r)/8):void 0;return n?[ka(1,-o/2,0,i,i*1/.8),ka(2,o/2,0,i,i*1/.8),...m,f,...I?[I]:[]]:[yi(["1","left"],-o/2,0,i,r,C),yi(["2","right"],o/2,0,i,r,C),...m,f,...I?[I]:[]]},Usi=t=>({circuitJson:Pue({...t,roundedPads:!0}),parameters:t}),Ksi=t=>({circuitJson:Pue(t),parameters:t}),Vsi=t=>({circuitJson:Pue(t).map(n=>n.type!=="pcb_silkscreen_path"?n:{...n,route:n.route.map(o=>({...o,x:-o.x}))}),parameters:t}),hG=t=>{const{padSpacing:e,padWidth:n,padHeight:o,padPitch:i,numRows:r,textbottom:s,courtyardOutline:a}=t,A=[],c=(r-1)*(i/2);for(let Q=0;Q<r;Q++)A.push(c-Q*i);const l=[];A.forEach((Q,w)=>{l.push(yi(w+1,-e/2,Q,n,o))}),A.slice().reverse().forEach((Q,w)=>{l.push(yi(w+r+1,e/2,Q,n,o))});const g=Math.max(...A)+o/2+.4,u=Math.min(...A)-o/2-.4,h=-e/2-n/2-.4,d=e/2+n/2+.4,m={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:d*.5,y:g},{x:h*.5,y:g}],stroke_width:.12,pcb_silkscreen_path_id:"silkscreen_top"},p={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:d*.5,y:u},{x:h*.5,y:u}],stroke_width:.12,pcb_silkscreen_path_id:"silkscreen_bottom"},_=-e/2,f=Math.max(...A),I=.2,C=_-n/2-.1,y=f+o/2+.1,x={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"pin1_marker",route:[{x:C,y},{x:C-I,y},{x:C,y:y+I},{x:C,y}],stroke_width:.1},E=s?u-.9:g+.9,B=tr(0,E,.2),b=a?{type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",layer:"top",outline:a}:null;return[...l,m,p,x,B,...b?[b]:[]]},zsi=Xi.extend({pw:ue.default("0.5mm"),ph:ue.default("0.4mm"),p:ue.default("0.7mm"),textbottom:We().optional(),convex:We().optional(),concave:We().optional()}),Jsi=1,Wsi=t=>{const e=zsi.parse(t);if(e.concave===!0)return[];const n=Dh(e.pw),o=Dh(e.ph),i=Dh(e.p);return hG({padSpacing:Jsi,padWidth:n,padHeight:o,padPitch:i,numRows:2,textbottom:e.textbottom,convex:e.convex,concave:e.concave,courtyardOutline:[{x:-1,y:.95},{x:-1,y:-.95},{x:1,y:-.95},{x:1,y:.95}]})},jsi=Xi.extend({pw:ue.default("0.5mm"),ph:ue.default("0.32mm"),p:ue.default("0.5mm"),textbottom:We().optional(),convex:We().optional(),concave:We().optional()}),Xsi=1,qsi=t=>{const e=jsi.parse(t),n=Dh(e.pw),o=Dh(e.ph),i=Dh(e.p);return hG({padSpacing:Xsi,padWidth:n,padHeight:o,padPitch:i,numRows:4,textbottom:e.textbottom,convex:e.convex,concave:e.concave,courtyardOutline:[{x:-1,y:1.25},{x:-1,y:-1.25},{x:1,y:-1.25},{x:1,y:1.25}]})},$si=Xi.extend({pw:ue.default("0.9mm"),ph:ue.default("0.4mm"),p:ue.default("0.8mm"),textbottom:We().optional(),convex:We().optional(),concave:We().optional()}),Zsi=1.7,eai=t=>{const e=$si.parse(t),n=Dh(e.pw),o=Dh(e.ph),i=Dh(e.p);return hG({padSpacing:Zsi,padWidth:n,padHeight:o,padPitch:i,numRows:2,textbottom:e.textbottom,convex:e.convex,concave:e.concave,courtyardOutline:[{x:-1.55,y:1.05},{x:-1.55,y:-1.05},{x:1.55,y:-1.05},{x:1.55,y:1.05}]})},tai=Xi.extend({pw:ue.default("0.9mm"),ph:ue.default("0.4mm"),p:ue.default("0.8mm"),textbottom:We().optional(),convex:We().optional(),concave:We().optional()}),nai=1.7,oai=t=>{const e=tai.parse(t),n=Dh(e.pw),o=Dh(e.ph),i=Dh(e.p);return hG({padSpacing:nai,padWidth:n,padHeight:o,padPitch:i,numRows:4,textbottom:e.textbottom,convex:e.convex,concave:e.concave,courtyardOutline:[{x:-1.55,y:1.88},{x:-1.55,y:-1.87},{x:1.55,y:-1.87},{x:1.55,y:1.88}]})},iai=Xi.extend({pw:ue.default("0.7mm"),ph:ue.default("0.64mm"),p:ue.default("0.94mm"),textbottom:We().optional(),convex:We().optional(),concave:We().optional()}),rai=1.4,sai=t=>{const e=iai.parse(t),n=Dh(e.pw),o=Dh(e.ph),i=Dh(e.p);return hG({padSpacing:rai,padWidth:n,padHeight:o,padPitch:i,numRows:2,textbottom:e.textbottom,convex:e.convex,concave:e.concave,courtyardOutline:[{x:-1.3,y:1.05},{x:-1.3,y:-1.05},{x:1.3,y:-1.05},{x:1.3,y:1.05}]})},aai=Xi.extend({pw:ue.default("0.9mm"),ph:ue.default("0.9mm"),p:ue.default("1.34mm"),textbottom:We().optional(),convex:We().optional(),concave:We().optional()}),Aai=3,cai=t=>{const e=aai.parse(t),n=Dh(e.pw),o=Dh(e.ph),i=Dh(e.p);return hG({padSpacing:Aai,padWidth:n,padHeight:o,padPitch:i,numRows:4,textbottom:e.textbottom,convex:e.convex,concave:e.concave,courtyardOutline:[{x:-2.21,y:2.85},{x:-2.21,y:-2.85},{x:2.2,y:-2.85},{x:2.2,y:2.85}]})},lai=t=>{const e=t.array??t.x;if(typeof e=="number")return Number.isNaN(e)?void 0:e;if(typeof e=="string"){const n=Number.parseInt(e,10);return Number.isNaN(n)?void 0:n}if(typeof t.imperial=="string"){const o=t.imperial.match(/x(2|4)$/)?.[1];if(o)return Number.parseInt(o,10)}},gai=t=>t?(typeof t=="number"?`${t}`:t).split(/[_x]/)[0]:void 0,uai=t=>{const e=lai(t),n=gai(t.imperial);return e===2&&n==="0402"?{circuitJson:Wsi(t),parameters:t}:e===4&&n==="0402"?{circuitJson:qsi(t),parameters:t}:e===2&&n==="0603"?{circuitJson:eai(t),parameters:t}:e===4&&n==="0603"?{circuitJson:oai(t),parameters:t}:e===2&&n==="0606"?{circuitJson:sai(t),parameters:t}:e===4&&n==="1206"?{circuitJson:cai(t),parameters:t}:{circuitJson:Pue(t),parameters:t}},kZt=(t,{x:e,y:n,radius:o})=>({type:"pcb_smtpad",x:e,y:n,radius:o,layer:"top",shape:"circle",pcb_smtpad_id:"",port_hints:Array.isArray(t)?t.map(i=>i.toString()):[t.toString()]}),FZt="ABCDEFGHIJKLMNOPQRSTUVWXYZ",wue=$().transform(t=>{const[e,n]=t.split(/[x ]/);return{x:parseFloat(e??""),y:parseFloat(n??"")}}).pipe(Pt({x:ft(),y:ft()})),dai=$().or(dn($u())).transform(t=>Array.isArray(t)?t:(t.startsWith("(")&&t.endsWith(")")&&(t=t.slice(1,-1)),t.split(",").map(e=>{const n=Number(e);return isNaN(n)?e:n}))).pipe(dn($().or(ft()))),hai=Xi.extend({fn:$(),num_pins:ft().optional().default(64),grid:wue.optional(),p:ct.default("0.8mm"),w:ue.optional(),h:ue.optional(),ball:ue.optional().describe("ball diameter"),pad:ue.optional().describe("pad width/height"),circularpads:We().optional().describe("use circular pads"),tlorigin:We().optional(),blorigin:We().optional(),trorigin:We().optional(),brorigin:We().optional(),missing:dai.default([])}).transform(t=>{let e="tl";if(t.blorigin&&(e="bl"),t.trorigin&&(e="tr"),t.brorigin&&(e="br"),!t.grid){const o=Math.ceil(Math.sqrt(t.num_pins));t.grid={x:o,y:o}}return t.missing&&(t.missing=t.missing.map(o=>{if(typeof o=="number")return o;if(o==="center")return"center";if(o==="topleft")return"topleft";const i=o.match(/([A-Z]+)(\d+)/);if(!i)return o;const r=FZt.indexOf(i[1]),s=Number.parseInt(i[2])-1;return r*t.grid.x+s+1})),{...t,origin:e}}),mai=t=>{const e=hai.parse(t);let{num_pins:n,grid:o,p:i,w:r,h:s,ball:a,pad:A,missing:c}=e;a??=.75/1.27*i,A??=a*.8;const l=[],g=(c??[]).filter(Y=>typeof Y=="number"),u=o.x*o.y-n;if(c.length===0&&u>0&&(Math.sqrt(u)%1===0?c.push("center"):u===1&&c.push("topleft")),c?.includes("center")){const Y=Math.floor(Math.sqrt(u)),j=Math.floor((o.x-Y)/2),ee=Math.floor((o.y-Y)/2);for(let W=ee;W<ee+Y;W++)for(let Z=j;Z<j+Y;Z++)g.push(W*o.x+Z+1)}c?.includes("topleft")&&g.push(1);const h=new Set(g);let d=0;for(let Y=0;Y<o.y;Y++)for(let j=0;j<o.x;j++){const ee=(j-(o.x-1)/2)*i,W=(Y-(o.y-1)/2)*i;let Z=j,ie=Y;switch(e.origin){case"bl":Z=j,ie=o.y-1-Y;break;case"br":Z=o.x-1-j,ie=o.y-1-Y;break;case"tr":Z=o.x-1-j,ie=Y;break}let se=ie*o.x+Z+1;if(h.has(se)){d++;continue}se-=d;const ne=[se,`${FZt[ie]}${Z+1}`];l.push(e.circularpads?kZt(ne,{x:ee,y:W,radius:A/2}):yi(ne,ee,W,A,A))}const m=tr(0,o.y*i/2,.2),p=i/6;let _;const f=o.x*i/2,I=o.y*i/2;switch(e.origin){case"bl":_=[{x:-f,y:-I},{x:-f,y:-I-p},{x:-f-p,y:-I},{x:-f,y:-I}];break;case"br":_=[{x:f,y:-I},{x:f,y:-I-p},{x:f+p,y:-I},{x:f,y:-I}];break;case"tr":_=[{x:f,y:I},{x:f,y:I+p},{x:f+p,y:I},{x:f,y:I}];break;default:_=[{x:-f,y:I},{x:-f,y:I+p},{x:-f-p,y:I},{x:-f,y:I}];break}const C={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"pin1_marker",route:_,stroke_width:.05},y=(o.x-1)*i+A,x=(o.y-1)*i+A,E=r??y,B=s??x,b=Math.max(y/2,E/2),Q=Math.max(x/2,B/2),w=1.715,D=1.765,k=b+w,T=k,H=Q+D,G=H,U={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",outline:Dy([{minX:-k,maxX:k,minY:-G,maxY:G},{minX:-T,maxX:T,minY:-H,maxY:H}]),layer:"top"};return{circuitJson:[...l,m,C,U],parameters:e}},Mue=(t,e,n,o,i)=>({type:"pcb_smtpad",x:e,y:n,width:o,height:i,radius:i/2,layer:"top",shape:"pill",pcb_smtpad_id:"",port_hints:Array.isArray(t)?t.map(r=>r.toString()):[t.toString()]}),rR=t=>Xi.extend({fn:$(),num_pins:ft().optional().default(8),w:ue.default(ue.parse(t.w??"5.3mm")),p:ue.default(ue.parse(t.p??"1.27mm")),pw:ue.default(ue.parse(t.pw??"0.6mm")),pl:ue.default(ue.parse(t.pl??"1.0mm")),legsoutside:We().optional().default(t.legsoutside??!1),pillpads:We().optional().default(t.pillpads??!1),silkscreen_stroke_width:ft().optional().default(.1)}).transform(e=>(!e.pw&&!e.pl?(e.pw=ue.parse("0.6mm"),e.pl=ue.parse("1.0mm")):e.pw?e.pl||(e.pl=e.pw*(1/.6)):e.pw=e.pl*(.6/1),e)),pai=rR({}),lYe=t=>{t.widthincludeslegs!==void 0&&(t.legsoutside=!t.widthincludeslegs);const{num_pins:e,pn:n,w:o,p:i,pl:r,legsoutside:s}=t,a=e/2,A=n<=a,c=a-1,l=i,g=l*c,u=s?r/2:-r/2;return A?{x:-o/2-u,y:g/2-(n-1)*l}:{x:o/2+u,y:-g/2+(n-a-1)*l}},_ai=t=>{const e=pai.parse(t);return{circuitJson:YX(e),parameters:e}},YX=t=>{const e=[];let n=0,o=0;for(let p=0;p<t.num_pins;p++){const{x:_,y:f}=lYe({num_pins:t.num_pins,pn:p+1,w:t.w,p:t.p,pl:t.pl,legsoutside:t.legsoutside});n=Math.max(n,Math.abs(_)+t.pl/2),o=Math.max(o,Math.abs(f)+t.pw/2),t.pillpads?e.push(Mue(p+1,_,f,t.pl,t.pw)):e.push(yi(p+1,_,f,t.pl,t.pw))}const i=Math.min(1,t.p/2),r=t.w-(t.legsoutside?0:t.pl*2)-.2,s=(t.num_pins/2-1)*t.p+t.pw+i,a=tr(0,s/2+.4,s/12),A={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",stroke_width:t.silkscreen_stroke_width??.1,route:[{x:-r/2,y:-s/2},{x:-r/2,y:s/2},...Que.map(({x:p,y:_})=>({x:p*r/6,y:_*r/6+s/2})),{x:r/2,y:s/2},{x:r/2,y:-s/2},{x:-r/2,y:-s/2}]},c=t.w/2,l=s/2,g=Math.max(n,c)+.25,u=Math.min(o,l)+.25,h=Math.min(n,c)+.25,d=Math.max(o,l)+.25,m={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",layer:"top",outline:Dy([{minX:-g,maxX:g,minY:-u,maxY:u},{minX:-h,maxX:h,minY:-d,maxY:d}])};return[...e,A,a,m]},LZt=zn(["leftside","topside","rightside","bottomside","toppin","bottompin","leftpin","rightpin"]),fai=({num_pins:t,cw:e,ccw:n,startingpin:o})=>{const i=[],r=t/4;let s=1;const a={};for(const A of o??[])a[A]=!0;!a.leftside&&!a.topside&&!a.rightside&&!a.bottomside&&(a.leftside=!0),!a.bottompin&&!a.leftpin&&!a.rightpin&&!a.toppin&&(a.leftside?a.toppin=!0:a.topside?a.rightpin=!0:a.rightside?a.bottompin=!0:a.bottomside&&(a.leftpin=!0)),a.leftside&&a.toppin?s=1:a.leftside&&a.bottompin?s=r:a.bottomside&&a.leftpin?s=r+1:a.bottomside&&a.rightpin?s=r*2:a.rightside&&a.bottompin?s=r*2+1:a.rightside&&a.toppin?s=r*3:a.topside&&a.rightpin?s=r*3+1:a.topside&&a.leftpin&&(s=r*4),i.push(-1);for(let A=0;A<t;A++)i[s]=A+1,n||!e?(s++,s>t&&(s=1)):(s--,s<1&&(s=t));return i},gYe=Xi.extend({fn:$(),cc:We().default(!0).optional(),ccw:We().default(!0).optional(),startingpin:$().or(dn(LZt)).transform(t=>typeof t=="string"?t.slice(1,-1).split(","):t).pipe(dn(LZt)).optional(),num_pins:ft().optional().default(64),w:ue.optional(),h:ue.optional(),p:ue.default(ue.parse("0.5mm")),pw:ue.optional(),pl:ue.optional(),thermalpad:Eo([je(!0),wue]).optional(),legsoutside:We().default(!1)}),uYe=t=>{t.w&&!t.h?t.h=t.w:!t.w&&t.h&&(t.w=t.h);const e=t.num_pins/4;if(!t.p&&!t.pw&&!t.pl&&t.w){const n=e+4;t.p=t.w/n}return!t.p&&t.w&&t.h&&t.pw&&t.pl&&(t.p=(t.w-t.pl*2)/(e-1)),!t.w&&!t.h&&t.p&&(t.w=t.p*(e+4),t.h=t.w),t.p&&!t.pw&&!t.pl?(t.pw=t.p/2,t.pl=t.p/2):t.pw?t.pl||(t.pl=t.pw*(1/.6)):t.pw=t.pl*(.6/1),t},HZt=gYe.transform(uYe),Iai=["left","bottom","right","top"],Cai=t=>{const{pin_count:e,pn:n,w:o,h:i,p:r,pl:s,legsoutside:a}=t,A=e/4,c=Iai[Math.floor((n-1)/A)],l=(n-1)%A,g=r*(A-1),u=r*(A-1),h=a?s/2:-s/2;switch(c){case"left":return{x:-o/2-h+.1,y:u/2-l*r,o:"vert"};case"bottom":return{x:-g/2+l*r,y:-i/2-h+.1,o:"horz"};case"right":return{x:o/2+h-.1,y:-u/2+l*r,o:"vert"};case"top":return{x:g/2-l*r,y:i/2+h-.1,o:"horz"};default:throw new Error("Invalid pin number")}},mG=t=>{const e=HZt.parse(t),n=[];let o=0,i=0;const r=fai(e),s=e.num_pins/4;for(let I=0;I<e.num_pins;I++){const{x:C,y,o:x}=Cai({pin_count:e.num_pins,pn:I+1,w:e.w,h:e.h,p:e.p??.5,pl:e.pl,legsoutside:e.legsoutside});let E=e.pw,B=e.pl;x==="vert"&&([E,B]=[B,E]);const b=r[I+1];o=Math.max(o,Math.abs(C)+E/2),i=Math.max(i,Math.abs(y)+B/2),n.push(yi(b,C,y,E,B))}if(e.thermalpad)if(typeof e.thermalpad=="boolean"){const I=e.p*(s-1)+e.pw,C=e.p*(s-1)+e.pw;o=Math.max(o,I/2),i=Math.max(i,C/2),n.push(yi(["thermalpad"],0,0,I,C))}else o=Math.max(o,e.thermalpad.x/2),i=Math.max(i,e.thermalpad.y/2),n.push(yi(["thermalpad"],0,0,e.thermalpad.x,e.thermalpad.y));const a=[];for(const[I,C,y]of[["top-left",-1,1],["bottom-left",-1,-1],["bottom-right",1,-1],["top-right",1,1]]){const x=e.w/2*C,E=e.h/2*y;let B="none",b=x,Q=E;const w=e.pw*2;r[1]===1&&I==="top-left"?B="in1":r[s*4]===1&&I==="top-left"||r[s*3+1]===1&&I==="top-right"?B="in2":r[s*3]===1&&I==="top-right"||r[s]===1&&I==="bottom-left"?B="in1":r[s+1]===1&&I==="bottom-left"?B="in2":r[s*2]===1&&I==="bottom-right"?B="in1":r[s*2+1]===1&&I==="bottom-right"&&(B="in2");const D=B==="in1"?1:-1;if(e.legsoutside){const k=B==="in1"?e.pl/2:e.pw/2,T=B==="in1"?e.pw/2:e.pl/2;b+=k*C*D,Q-=T*y*D}(B==="none"||e.legsoutside)&&a.push({layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:`pcb_silkscreen_path_${I}`,route:[{x:x-w*C,y:E},{x,y:E},{x,y:E-w*y}],type:"pcb_silkscreen_path",stroke_width:.1}),(B==="in1"||B==="in2")&&!e.legsoutside&&a.push({layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:`pcb_silkscreen_path_${I}_1`,route:[{x:x-w*C,y:E},{x:x-w*C/2,y:E}],type:"pcb_silkscreen_path",stroke_width:0},{layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:`pcb_silkscreen_path_${I}_2`,route:[{x,y:E-w*y/2},{x,y:E-w*y}],type:"pcb_silkscreen_path",stroke_width:.1}),(B==="in1"||B==="in2")&&a.push({layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:`pcb_silkscreen_path_${I}_3`,route:[{x:b-.2*-C,y:Q+.2*D},{x:b,y:Q},{x:b+.2*D*-C,y:Q+.2},{x:b-.2*-C,y:Q+.2*D}],type:"pcb_silkscreen_path",stroke_width:.1})}const A=tr(0,e.h/2+(e.legsoutside?e.pl*1.2:.5),.3),c=I=>Math.ceil(I/.05)*.05,l=(s-1)*e.p+e.pw,g=(s-1)*e.p+e.pw,u=l/2+.25,h=g/2+.25,d=e.w/2+.25,m=e.h/2+.25,p=Math.max(d,c(o+.25)),_=Math.max(m,c(i+.25)),f={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",layer:"top",outline:Dy([{minX:-p,maxX:p,minY:-h,maxY:h},{minX:-d,maxX:d,minY:-m,maxY:m},{minX:-u,maxX:u,minY:-_,maxY:_}])};return{circuitJson:[...n,...a,A,f],parameters:e}};gYe.extend({}).transform(uYe);var yai=t=>(t.legsoutside=!1,t.pl||(t.pl=.875),t.pw||(t.pw=.25),mG(t)),xai=t=>{if(t.legsoutside=!0,!t.p)switch(t.num_pins){case 32:t.p=.8;break;case 44:case 48:t.p=.5;break;case 64:case 80:case 100:t.p=.5;break;case 144:t.p=.5;break}if(!t.pl)switch(t.num_pins){case 32:case 44:case 48:case 64:case 80:case 100:t.pl=1.475;break;case 144:t.pl=1.6;break}if(!t.pw)switch(t.num_pins){case 32:t.pw=.55;break;case 44:case 48:case 64:case 80:case 100:t.pw=.3;break;case 144:t.pw=.25;break}return mG(t)},Eai=t=>{t.legsoutside=!0;const e=HZt.parse(t);if(!t.p)switch(t.num_pins){case 44:case 64:t.p=.8;break;case 52:t.w===14?t.p=1:t.p=.65;break;case 208:t.p=.5;break}if(!t.pl)switch(t.num_pins){case 44:case 52:case 64:t.pl=2.25;break;case 208:t.pl=1.65;break;default:t.pl=e.pl*4;break}if(!t.pw)switch(t.num_pins){case 44:case 64:t.pw=.5;break;case 52:t.w===14?t.pw=.45:t.pw=.55;break;case 208:t.pw=.3;break;default:t.pw=e.pw;break}return mG(t)};gYe.extend({}).transform(uYe);var Bai=t=>(t.legsoutside=!1,t.thermalpad===void 0&&(t.thermalpad=!0),mG(t)),Sai=Xi.extend({fn:$(),num_pins:ft().optional().default(8),w:ue.default(ue.parse("3.9mm")),p:ue.default(ue.parse("1.27mm")),pw:ue.optional(),pl:ue.optional(),legsoutside:We().optional().default(!1),silkscreen_stroke_width:ft().optional().default(.1)}).transform(t=>(t.pw==null&&t.pl==null?(t.pw=ue.parse("0.51mm"),t.pl=ue.parse("1.1mm")):t.pw==null?t.pw=t.pl*(.51/1.1):t.pl==null&&(t.pl=t.pw*(1.1/.51)),t)),bai=t=>{const{num_pins:e,pn:n,w:o,p:i}=t,r=e/2,s=n<=r,a=r-1,A=i,c=A*a,l=o+ue.parse("0.2mm"),g=(s?-1:1)*(l/2);return s?{x:g,y:c/2-(n-1)*A}:{x:g,y:-c/2+(n-r-1)*A}},Qai=t=>{const e=Sai.parse(t),n=[];for(let p=0;p<e.num_pins;p++){const{x:_,y:f}=bai({num_pins:e.num_pins,pn:p+1,w:e.w,p:e.p,pl:e.pl,legsoutside:e.legsoutside});n.push(yi(p+1,_,f,e.pl,e.pw))}const o=Math.min(1,e.p/2),i=e.w-(e.legsoutside?0:e.pl)-.2,r=(e.num_pins/2-1)*e.p+e.pw+o,s=tr(0,r/2+.4,r/12),a={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:-r/2},{x:-i/2,y:r/2},...Que.map(({x:p,y:_})=>({x:p*i/6,y:_*i/6+r/2})),{x:i/2,y:r/2},{x:i/2,y:-r/2},{x:-i/2,y:-r/2}]},A=(e.num_pins/2-1)*e.p+e.pw,c=e.legsoutside?e.w/2+e.pl:(e.w+.2)/2+e.pl/2,l=A/2,g=c+.25,u=g,h=l+.445,d=h,m={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",outline:Dy([{minX:-g,maxX:g,minY:-d,maxY:d},{minX:-u,maxX:u,minY:-h,maxY:h}]),layer:"top"};return{circuitJson:[...n,a,s,m],parameters:e}},vai=Xi.extend({fn:$(),num_pins:ft().optional().default(8),w:ue.default(ue.parse("3.0mm")),p:ue.default(ue.parse("0.5mm")),pw:ue.default(ue.parse("0.30mm")),pl:ue.default(ue.parse("1.45mm")),legsoutside:We().optional().default(!0),silkscreen_stroke_width:ft().optional().default(.1)}),Pai=t=>{const{num_pins:e,pn:n,w:o,p:i,pl:r,legsoutside:s}=t,a=e/2,A=n<=a,c=a-1,l=i*c,g=s?r/2:-r/2;return A?{x:-o/2-g,y:l/2-(n-1)*i}:{x:o/2+g,y:-l/2+(n-a-1)*i}},wai=t=>{const e={...t},n=e.p,o=typeof n=="string"||typeof n=="number"?ue.parse(n):void 0,i=o!=null&&o<=ue.parse("0.5mm"),r=vai.parse(e),s=[],a=i?r.w-ue.parse("0.15mm"):r.w;for(let C=0;C<r.num_pins;C++){const{x:y,y:x}=Pai({num_pins:r.num_pins,pn:C+1,w:a,p:r.p,pl:r.pl,legsoutside:r.legsoutside});s.push(yi(C+1,y,x,r.pl,r.pw))}const A=Math.min(1,r.p/2),c=r.w-(r.legsoutside?0:r.pl*2)-.2,l=(r.num_pins/2-1)*r.p+r.pw+A,g=tr(0,l/2+.4,l/12),u={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",stroke_width:r.silkscreen_stroke_width??.1,route:[{x:-c/2,y:-l/2},{x:-c/2,y:l/2},...Que.map(({x:C,y})=>({x:C*c/6,y:y*c/6+l/2})),{x:c/2,y:l/2},{x:c/2,y:-l/2},{x:-c/2,y:-l/2}]},h=(r.num_pins/2-1)*r.p+r.pw,d=r.w/2+(r.legsoutside?r.pl:0),m=r.w/2+.25,p=d+.18,_=h/2+.25,f=_+.35,I={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",layer:"top",outline:Dy([{minX:-p,maxX:p,minY:-_,maxY:_},{minX:-m,maxX:m,minY:-f,maxY:f}])};return{circuitJson:[...s,u,g,I],parameters:r}},Mai=[{x:-1.45,y:.93},{x:-.73,y:.93},{x:-.73,y:1.1},{x:.73,y:1.1},{x:.73,y:.93},{x:1.45,y:.93},{x:1.45,y:-.93},{x:.73,y:-.93},{x:.73,y:-1.1},{x:-.73,y:-1.1},{x:-.73,y:-.93},{x:-1.45,y:-.93}],Dai=Xi.extend({fn:$(),num_pins:je(6).default(6),w:$().default("3.1mm"),h:$().default("2.0mm"),p:$().default("0.65mm"),pl:$().default("1.03mm"),pw:$().default("0.35mm"),string:$().optional()}),Nai=t=>{const e=Dai.parse({...t,fn:"sot363"}),n=ue.parse(e.w),o=ue.parse(e.h),i=ue.parse(e.p),r=ue.parse(e.pl),s=ue.parse(e.pw),a=[];for(let d=0;d<6;d++){const{x:m,y:p}=OZt(d+1,n,i);a.push(yi(d+1,m,p,r,s))}const A={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-n/4,y:o/2+.1},{x:n/4,y:o/2+.1}],stroke_width:.05,pcb_silkscreen_path_id:""},c={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-n/4,y:-o/2-.1},{x:n/4,y:-o/2-.1}],stroke_width:.05,pcb_silkscreen_path_id:""},l=OZt(1,n,i),g={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"pin_marker_1",route:[{x:l.x-r/2-.3,y:l.y},{x:l.x-r/2-.45,y:l.y+.15},{x:l.x-r/2-.45,y:l.y-.15},{x:l.x-r/2-.3,y:l.y}],stroke_width:.05,pcb_silkscreen_path_id:"pin_marker_1"},u=tr(0,o/2+.4,.25),h={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",outline:Mai,layer:"top"};return{circuitJson:[...a,A,c,u,g,h],parameters:e}},OZt=(t,e,n,o)=>t<=3?{x:-.84,y:n-(t-1)*n}:{x:.84,y:-n+(t-4)*n},Rai=[{x:-.75,y:1},{x:-.75,y:-1},{x:.75,y:-1},{x:.75,y:1}],Tai=Xi.extend({fn:$(),num_pins:je(6).default(6),w:$().default("1.01mm"),h:$().default("1.45mm"),p:$().default("0.5mm"),pl:$().default("0.33mm"),pw:$().default("0.27mm"),string:$().optional()}),kai=t=>{const e=Tai.parse({...t,fn:"sot886"}),n=ue.parse(e.w),o=ue.parse(e.h),i=ue.parse(e.p),r=ue.parse(e.pl),s=ue.parse(e.pw),a=[];for(let d=0;d<6;d++){const{x:m,y:p}=GZt(d+1,n,i,r);a.push(yi(d+1,m,p,r,s))}const A={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-n/2,y:o/2},{x:n/2,y:o/2}],stroke_width:.05,pcb_silkscreen_path_id:""},c={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-n/2,y:-o/2},{x:n/2,y:-o/2}],stroke_width:.05,pcb_silkscreen_path_id:""},l=GZt(1,n,i,r),g={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"pin_marker_1",route:[{x:l.x-r/2-.3,y:l.y},{x:l.x-r/2-.45,y:l.y+.15},{x:l.x-r/2-.45,y:l.y-.15},{x:l.x-r/2-.3,y:l.y}],stroke_width:.05,pcb_silkscreen_path_id:"pin_marker_1"},u=tr(0,o/2+.4,.25),h={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",outline:Rai,layer:"top"};return{circuitJson:[...a,A,c,u,g,h],parameters:e}},GZt=(t,e,n,o)=>{const i=e/2-o/2;return t<=3?{x:-i,y:n-(t-1)*n}:{x:i,y:-n+(t-4)*n}},Fai=[{x:-2.05,y:1.5},{x:-1.05,y:1.5},{x:-1.05,y:1.7},{x:1.05,y:1.7},{x:1.05,y:.55},{x:2.05,y:.55},{x:2.05,y:-.55},{x:1.05,y:-.55},{x:1.05,y:-1.7},{x:-1.05,y:-1.7},{x:-1.05,y:-1.5},{x:-2.05,y:-1.5},{x:-2.05,y:-.39},{x:-1.05,y:-.39},{x:-1.05,y:.39},{x:-2.05,y:.39}],Lai=[{x:-2.05,y:1.5},{x:-1.05,y:1.5},{x:-1.05,y:1.7},{x:1.05,y:1.7},{x:1.05,y:1.5},{x:2.05,y:1.5},{x:2.05,y:.39},{x:1.05,y:.39},{x:1.05,y:-.39},{x:2.05,y:-.39},{x:2.05,y:-1.5},{x:1.05,y:-1.5},{x:1.05,y:-1.7},{x:-1.05,y:-1.7},{x:-1.05,y:-1.5},{x:-2.05,y:-1.5}],YZt=Xi.extend({fn:$(),num_pins:ft().default(3),w:$().default("1.92mm"),h:$().default("2.74mm"),pl:$().default("1.325mm"),pw:$().default("0.6mm"),p:$().default("0.95mm"),string:$().optional()}),Hai=rR({p:"0.95mm",w:"1.6mm",legsoutside:!0}),Oai=t=>{const e=t.string?.match(/^sot23_(\d+)/),n=e?Number.parseInt(e[1],10):3;if(n===6||n===8){const i=Hai.parse({...t,num_pins:n});return{circuitJson:YX(i),parameters:i}}const o=YZt.parse({...t,num_pins:n});if(o.num_pins===3)return{circuitJson:Yai(o),parameters:o};if(o.num_pins===5)return{circuitJson:KZt(o),parameters:o};throw new Error("Invalid number of pins")},Gai=t=>{const{pn:e,p:n}=t;return e===1?{x:-1.1375,y:n}:e===2?{x:-1.1375,y:-n}:{x:1.1375,y:0}},Yai=t=>{const e=[];for(let i=0;i<t.num_pins;i++){const{x:r,y:s}=Gai({num_pins:t.num_pins,pn:i+1,w:Number.parseFloat(t.w),h:Number.parseFloat(t.h),pl:Number.parseFloat(t.pl),p:Number.parseFloat(t.p)});e.push(yi(i+1,r,s,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}const n=tr(0,Number.parseInt(t.h),.3),o={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",outline:Fai,layer:"top"};return[...e,n,o]},UZt=t=>{const{p:e,h:n,pn:o}=t;if(o===1)return{x:-1.1375,y:e};if(o===2)return{x:-1.1375,y:0};if(o===3)return{x:-1.1375,y:-e};if(o===4)return{x:1.1375,y:-e};if(o===5)return{x:1.1375,y:e};throw new Error("Invalid pin number")},KZt=t=>{const e=[];for(let u=1;u<=t.num_pins;u++){const{x:h,y:d}=UZt({h:Number.parseFloat(t.h),p:Number.parseFloat(t.p),pn:u});e.push(yi(u,h,d,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}const n=(t.num_pins+1)/2*Number.parseFloat(t.p),o=Number.parseFloat(t.h),i={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-n/3,y:o/2+Number.parseFloat(t.p)/1.3},{x:n/3,y:o/2+Number.parseFloat(t.p)/1.3}],type:"pcb_silkscreen_path",stroke_width:.05},r={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_2",route:[{x:-n/3,y:-o/2-Number.parseFloat(t.p)/1.3},{x:n/3,y:-o/2-Number.parseFloat(t.p)/1.3}],type:"pcb_silkscreen_path",stroke_width:.05},s=tr(0,o+.3,.3),a=UZt({h:Number.parseFloat(t.h),p:Number.parseFloat(t.p),pn:1});a.x=a.x-Number.parseFloat(t.pw)*1.5;const A=.3,c=.4,l={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"pin1_indicator",route:[{x:a.x+A/2,y:a.y},{x:a.x-A/2,y:a.y+c/2},{x:a.x-A/2,y:a.y-c/2},{x:a.x+A/2,y:a.y}],stroke_width:.05},g={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",outline:Lai,layer:"top"};return[...e,s,i,r,l,g]},Uai=YZt.extend({}),Kai=t=>{const e=Uai.parse({...t,num_pins:5});return{circuitJson:KZt(e),parameters:e}},Vai=[{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}],zai=rR({}),Jai=t=>{const e=zai.parse(t),n=[];for(let p=0;p<e.num_pins;p++){const{x:_,y:f}=lYe({num_pins:e.num_pins,pn:p+1,w:e.w,p:e.p??1.27,pl:e.pl,widthincludeslegs:!0});n.push(yi(p+1,_,f,e.pl??"1mm",e.pw??"0.6mm"))}const o=Math.min(1,e.p/2),i=e.w+o,r=(e.num_pins/2-1)*e.p+e.pw+o,s=[];for(const p of Vai){const{dx:_,dy:f}=p;s.push({layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"",route:[{x:_*i/2-_*e.p,y:f*r/2},{x:_*i/2,y:f*r/2},{x:_*i/2,y:f*r/2-f*e.p}],type:"pcb_silkscreen_path",stroke_width:.1})}const a=e.p/4,A=-i/2-a/2,c=r/2-e.p/2;s.push({layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"",type:"pcb_silkscreen_path",route:[{x:A,y:c},{x:A-a,y:c+a},{x:A-a,y:c-a},{x:A,y:c}],stroke_width:.1});const l=tr(0,r/2+.4,r/12),g=p=>Math.ceil(p/.05)*.05,u=(e.num_pins/2-1)*e.p+e.pw,h=g(e.w/2+.25),d=g(u/2+.45),m={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:0,y:0},width:h*2,height:d*2,layer:"top"};return{circuitJson:[...n,l,...s,m],parameters:e}},sR=({fs:t,pn:e,anchor_x:n,anchor_y:o,textalign:i="center",orthogonal:r=!1,verticallyinverted:s=!1,layer:a="top"})=>{let A=0;r&&s?A=270:s?A=180:r?A=90:A=0;let c="center";return i==="left"&&(s?c="center_right":c="center_left"),i==="right"&&(s?c="center_left":c="center_right"),a==="bottom"&&(c==="center_left"?c="center_right":c==="center_right"&&(c="center_left")),{type:"pcb_silkscreen_text",pcb_silkscreen_text_id:"silkscreen_text_1",font:"tscircuit2024",font_size:t,pcb_component_id:"pcb_component_1",text:`{PIN${e}}`,layer:a,anchor_position:{x:n,y:o},anchor_alignment:c,ccw_rotation:A}};function VZt({pinlabeltextalignleft:t,pinlabeltextalignright:e,pinlabelorthogonal:n}){let o="top";return n?o="left":o="top",t&&(n?o="bottom":o="right"),e&&(n?o="top":o="left"),o}var Wai=Xi.extend({fn:$(),num_pins:ft().optional().default(6),rows:Eo([$(),ft()]).transform(t=>Number(t)).optional().default(1).describe("number of rows"),p:ue.default("0.1in").describe("pitch"),id:ue.default("1.0mm").describe("inner diameter"),od:ue.default("1.5mm").describe("outer diameter"),male:We().optional().describe("for male pin headers"),female:We().optional().describe("for female pin headers"),smd:We().optional().describe("surface mount device"),surfacemount:We().optional().describe("surface mount device (verbose)"),rightangle:We().optional().describe("right angle"),pw:ue.optional().default("1.0mm").describe("pad width for SMD"),pl:ue.optional().default("2.0mm").describe("pad length for SMD"),pinlabeltextalignleft:We().optional().default(!1),pinlabeltextaligncenter:We().optional().default(!1),pinlabeltextalignright:We().optional().default(!1),pinlabelverticallyinverted:We().optional().default(!1),pinlabelorthogonal:We().optional().default(!1),nosquareplating:We().optional().default(!1).describe("do not use rectangular pad for pin 1"),nopinlabels:We().optional().default(!1).describe("omit silkscreen pin labels"),doublesidedpinlabel:We().optional().default(!1).describe("add silkscreen pins in top and bottom layers"),bottomsidepinlabel:We().optional().default(!1).describe("place the silkscreen reference text on the bottom layer instead of top")}).transform(t=>{const e=VZt(t);return{...t,pinlabelAnchorSide:e,male:t.male??!t.female,female:t.female??!1,smd:t.smd??t.surfacemount??!1,rightangle:t.rightangle??!1}}).superRefine((t,e)=>{t.male&&t.female&&e.addIssue({code:Ao.custom,message:"'male' and 'female' cannot both be true; it should be male or female.",path:["male","female"]})}),jai=t=>{const e=Wai.parse(t),{p:n,id:o,od:i,rows:r,num_pins:s,pinlabelAnchorSide:a,pinlabelverticallyinverted:A,pinlabelorthogonal:c,pinlabeltextalignleft:l,pinlabeltextalignright:g,nopinlabels:u,doublesidedpinlabel:h,bottomsidepinlabel:d}=e;let m="center";l?m="left":g&&(m="right");const p=[],_=Math.ceil(s/r),f=(r-1)*n,I=f/2,C=-n,y=({xoff:ee,yoff:W,od:Z,anchorSide:ie,smd:se,pw:ne,pl:le})=>{let he=0,Ie=0;if(se){const ce=Z/5;switch(ie){case"right":he=ne/2+ce;break;case"top":Ie=le/2+ce;break;case"bottom":Ie=-(le/2+ce);break;case"left":he=-(ne/2+ce);break}}else{const ce=Z*.75;switch(ie){case"right":he=ce;break;case"top":Ie=ce;break;case"bottom":Ie=-ce;break;case"left":he=-ce;break}}return{anchor_x:ee+he,anchor_y:W+Ie}},x=(ee,W,Z)=>{e.smd?p.push(yi(ee,W,Z,e.pw,e.pl)):ee===1&&!e.nosquareplating?p.push(px({pn:ee,x:W,y:Z,holeDiameter:o,rectPadWidth:i,rectPadHeight:i})):p.push(ka(ee,W,Z,o,i));const{anchor_x:ie,anchor_y:se}=y({xoff:W,yoff:Z,od:i,anchorSide:a,smd:e.smd,pw:e.pw,pl:e.pl});u||(d?p.push(sR({fs:i/5,pn:ee,anchor_x:ie,anchor_y:se,textalign:m,orthogonal:c,verticallyinverted:A,layer:"bottom"})):p.push(sR({fs:i/5,pn:ee,anchor_x:ie,anchor_y:se,textalign:m,orthogonal:c,verticallyinverted:A,layer:"top"})),h&&p.push(sR({fs:i/5,pn:ee,anchor_x:ie,anchor_y:se,textalign:m,orthogonal:c,verticallyinverted:A,layer:"bottom"})))},E=new Set,B=r>2&&_>2;if(r===1){const ee=-((s-1)/2)*n;for(let W=0;W<s;W++){const Z=W+1,ie=ee+W*n,se=`${ie},0`;if(E.has(se))throw new Error(`Overlap at ${se}`);E.add(se),x(Z,ie,0)}}else if(B){const ee=-((_-1)/2)*n;let W=1;for(let Z=0;Z<r&&W<=s;Z++)for(let ie=0;ie<_&&W<=s;ie++){const se=ee+ie*n,ne=I+Z*C,le=`${se},${ne}`;if(E.has(le))throw new Error(`Overlap at ${le}`);E.add(le),x(W++,se,ne)}}else{const ee=-((_-1)/2)*n;let W=1,Z=0,ie=r-1,se=0,ne=_-1;for(;W<=s&&Z<=ie&&se<=ne;){for(let le=Z;le<=ie&&W<=s;le++){const he=ee+se*n,Ie=I+le*C,ce=`${he},${Ie}`;if(E.has(ce))throw new Error(`Overlap at ${ce}`);E.add(ce),x(W++,he,Ie)}se++;for(let le=se;le<=ne&&W<=s;le++){const he=ee+le*n,Ie=I+ie*C,ce=`${he},${Ie}`;if(E.has(ce))throw new Error(`Overlap at ${ce}`);E.add(ce),x(W++,he,Ie)}if(ie--,se<=ne){for(let le=ie;le>=Z&&W<=s;le--){const he=ee+ne*n,Ie=I+le*C,ce=`${he},${Ie}`;if(E.has(ce))throw new Error(`Overlap at ${ce}`);E.add(ce),x(W++,he,Ie)}ne--}if(Z<=ie){for(let le=ne;le>=se&&W<=s;le--){const he=ee+le*n,Ie=I+Z*C,ce=`${he},${Ie}`;if(E.has(ce))throw new Error(`Overlap at ${ce}`);E.add(ce),x(W++,he,Ie)}Z++}}if(W-1<s)throw new Error(`Missing pins: assigned ${W-1}, expected ${s}`)}const b=tr(0,f/2+n,.5),Q=e.smd?e.pw/2:i/2,w=e.smd?e.pl/2:i/2,D=(_-1)*n,k=D/2+Q,T=f/2+w,H=D/2+n/2,G=f/2+n/2,U=Math.max(k+.25,H+.5),Y=Math.max(T+.25,G+.5),j={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:0,y:0},width:2*U,height:2*Y,layer:"top"};return{circuitJson:[...p,b,j],parameters:e}},Xai=[{x:-1.2,y:.83},{x:-.75,y:.83},{x:-.75,y:.95},{x:.75,y:.95},{x:.75,y:.83},{x:1.2,y:.83},{x:1.2,y:-.83},{x:.75,y:-.83},{x:.75,y:-.95},{x:-.75,y:-.95},{x:-.75,y:-.83},{x:-1.2,y:-.83}],qai=Xi.extend({fn:$(),num_pins:je(6).default(6),w:$().default("2.1mm"),h:$().default("2.45mm"),p:$().default("0.5mm"),pl:$().default("0.675mm"),pw:$().default("0.35mm"),string:$().optional()}),$ai=t=>{const e=qai.parse({...t,fn:"sot563"}),n=ue.parse(e.w),o=ue.parse(e.h),i=ue.parse(e.p),r=ue.parse(e.pl),s=ue.parse(e.pw),a=[];for(let d=0;d<6;d++){const{x:m,y:p}=zZt(d+1,n,i,r);a.push(yi(d+1,m,p,r,s))}const A={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-n/2,y:o/2},{x:n/2,y:o/2}],stroke_width:.05,pcb_silkscreen_path_id:""},c={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-n/2,y:-o/2},{x:n/2,y:-o/2}],stroke_width:.05,pcb_silkscreen_path_id:""},l=zZt(1,n,i,r),g={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"pin_marker_1",route:[{x:l.x-r/2-.3,y:l.y},{x:l.x-r/2-.45,y:l.y+.15},{x:l.x-r/2-.45,y:l.y-.15},{x:l.x-r/2-.3,y:l.y}],stroke_width:.05,pcb_silkscreen_path_id:"pin_marker_1"},u=tr(0,o/2+.4,.25),h={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",outline:Xai,layer:"top"};return{circuitJson:[...a,A,c,u,g,h],parameters:e}},zZt=(t,e,n,o)=>{const i=e/2-o/2;return t<=3?{x:-i,y:n-(t-1)*n}:{x:i,y:-n+(t-4)*n}},Zai=rR({p:"1.27mm",w:"3.9mm",legsoutside:!0}),eAi=t=>{const e=Zai.parse({...t,num_pins:8});return{circuitJson:YX(e),parameters:e}},tAi=rR({p:"1.27mm",w:"7.5mm",legsoutside:!0}),nAi=t=>{const e=tAi.parse({...t,num_pins:16});return{circuitJson:YX(e),parameters:e}},oAi=Xi.extend({fn:$(),num_pins:je(3).default(3),w:$().default("1.2mm"),h:$().default("1.2mm"),pw:$().default("0.40mm"),pl:$().default("0.45mm"),p:$().default("0.575mm")}),iAi=t=>{const e=oAi.parse(t),n=sAi(e),o=tr(0,ue.parse(e.h),.2),i=1.8,r=1.8,s={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",outline:[{x:-i/2,y:r/2},{x:i/2,y:r/2},{x:i/2,y:-r/2},{x:-i/2,y:-r/2}],layer:"top"};return{circuitJson:[...n,o,s],parameters:e}},rAi=t=>{const{pn:e,p:n}=t;return e===1?{x:n,y:0}:e===2?{x:-n,y:-.4}:{x:-n,y:.4}},sAi=t=>{const e=[];for(let n=0;n<3;n++){const{x:o,y:i}=rAi({num_pins:t.num_pins,pn:n+1,w:Number.parseFloat(t.w),h:Number.parseFloat(t.h),pl:Number.parseFloat(t.pl),p:Number.parseFloat(t.p)});e.push(yi(n+1,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return e},AC=t=>{const e=t.p??t.pad_spacing;if(e===void 0||t.pl===void 0||t.pw===void 0)throw new Error("Diode fabrication note requires p or pad_spacing, pl, and pw");const n=ue.parse(e),o=ue.parse(t.pl),i=ue.parse(t.pw);return aAi({minX:-n/2-o/2,maxX:n/2+o/2,minY:-i/2,maxY:i/2})},aAi=t=>{const e=[],n=t.maxX-t.minX,o=t.maxY-t.minY,i=(t.minX+t.maxX)/2,r=(t.minY+t.maxY)/2,s=o*.28,a=s*2,A=n*.2,l=Math.min(A,a*1.25),g=i-l/2,u=i+l/2,h=l*.18,d=g+h,m=u-h,p=Math.max(Math.min(n,o)*.035,.01),_=Math.max(Math.min(n,o)*.25,.1);return e.push({type:"pcb_fabrication_note_path",pcb_fabrication_note_path_id:"diode_fabrication_note_anode_leg",pcb_component_id:"",layer:"top",stroke_width:p,route:[{x:g,y:r},{x:d,y:r}]},{type:"pcb_fabrication_note_path",pcb_fabrication_note_path_id:"diode_fabrication_note_triangle",pcb_component_id:"",layer:"top",stroke_width:p,route:[{x:d,y:r+s},{x:m,y:r},{x:d,y:r-s},{x:d,y:r+s}]},{type:"pcb_fabrication_note_path",pcb_fabrication_note_path_id:"diode_fabrication_note_cathode",pcb_component_id:"",layer:"top",stroke_width:p,route:[{x:m,y:r+s},{x:m,y:r-s}]},{type:"pcb_fabrication_note_path",pcb_fabrication_note_path_id:"diode_fabrication_note_cathode_leg",pcb_component_id:"",layer:"top",stroke_width:p,route:[{x:m,y:r},{x:u,y:r}]},{type:"pcb_fabrication_note_text",pcb_fabrication_note_text_id:"diode_fabrication_note_positive",pcb_component_id:"",layer:"top",font:"tscircuit2024",font_size:_,text:"+",anchor_position:{x:t.minX+n*.125,y:r},anchor_alignment:"center"},{type:"pcb_fabrication_note_text",pcb_fabrication_note_text_id:"diode_fabrication_note_negative",pcb_component_id:"",layer:"top",font:"tscircuit2024",font_size:_,text:"-",anchor_position:{x:t.maxX-n*.125,y:r},anchor_alignment:"center"}),e},AAi=Xi.extend({fn:$(),num_pins:je(2).default(2),w:$().default("2.36mm"),h:$().default("1.22mm"),pl:$().default("0.9mm"),pw:$().default("1.2mm"),p:$().default("3.30mm")}),cAi=t=>{const e=AAi.parse(t),n=ue.parse(e.h),o=tr(0,n/4+.4,.3),s={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:0,y:0},width:4.7,height:2.3,layer:"top"};return{circuitJson:gAi(e).concat(...AC(e),o,s),parameters:e}},lAi=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},gAi=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=lAi({pn:n,p:Number.parseFloat(t.p)});e.push(yi(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw),.1125))}return e},uAi=Xi.extend({fn:$(),p:ue.optional().default("2.54mm"),id:ue.optional().default("0.7mm"),od:ue.optional().default("1.4mm")}),dAi=t=>{const e=uAi.parse(t),{p:n,id:o,od:i}=e,r=[ka(1,-n/2,0,o,i),ka(2,n/2,0,o,i)],s={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-n/2+i+o/2,y:0},{x:n/2-i-o/2,y:0}],stroke_width:.1,pcb_silkscreen_path_id:""},a=tr(0,1.5,.5),A=-n/2,c=n/2,l=i/2,g=i/2,u=A-l-.35,h=c+l+.26,d=g+.35,m=u,p=h,_=d,f={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",outline:Dy([{minX:u,maxX:h,minY:-_,maxY:_},{minX:m,maxX:p,minY:-d,maxY:d}]),layer:"top"};return{circuitJson:[...r,s,a,f],parameters:e}},hAi=(t,e,n,o,i,r=.1)=>{const s=[],a=[],A=Math.max(1,Math.ceil(Math.PI*n/r)),c=Math.PI/A;for(let l=0;l<=A;l++){const g=l*c,u=t+Math.cos(g)*n,h=e+Math.sin(g)*n;u<t-o&&h>=e-i/2&&h<=e+i/2||s.push({x:u,y:h})}for(let l=0;l<=A;l++){const g=Math.PI+l*c,u=t+Math.cos(g)*n,h=e+Math.sin(g)*n;u<t-o&&h>=e-i/2&&h<=e+i/2||a.push({x:u,y:h})}return{topArc:s,bottomArc:a}},mAi=Xi.extend({fn:$(),p:ue.optional().default("5mm"),id:ue.optional().default("0.8mm"),od:ue.optional().default("1.6mm"),ceramic:We().optional(),electrolytic:We().optional(),polarized:We().optional()}),pAi=t=>{const e=mAi.parse(t),{p:n,id:o,od:i}=e;o===.8&&i===1.6&&(e.id=n===5?.8:n*.25,e.od=n===5?1.6:n*.5);const r=[ka(1,-n/2,0,e.id,e.od),ka(2,n/2,0,e.id,e.od)],s=n+.1,{topArc:a,bottomArc:A}=hAi(0,0,s,e.od/2,e.od),c=.02*n,l={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:a,stroke_width:c,pcb_silkscreen_path_id:""},g={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:A,stroke_width:c,pcb_silkscreen_path_id:""},u={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:0,y:s},{x:0,y:-s}],stroke_width:c,pcb_silkscreen_path_id:""},h=.1*n,d=-(n+h+.04*n),m=s-h-.08*n,p={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:d-h,y:m},{x:d+h,y:m}],stroke_width:c,pcb_silkscreen_path_id:""},_={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:d,y:m-h},{x:d,y:m+h}],stroke_width:c,pcb_silkscreen_path_id:""},f=tr(0,s+.12*n,.1*n),I=[...r,l,g,u,f];(e.electrolytic===!0||e.polarized===!0)&&I.push(p,_);const y=n+.25,x={type:"pcb_courtyard_circle",pcb_courtyard_circle_id:"",pcb_component_id:"",center:{x:0,y:0},radius:y,layer:"top"};return I.push(x),{circuitJson:I,parameters:e}},aR=(t,e={})=>({type:"pcb_silkscreen_path",layer:e.layer||"top",pcb_component_id:e.pcb_component_id||"",pcb_silkscreen_path_id:e.pcb_silkscreen_path_id||"",route:t,stroke_width:e.stroke_width||.1}),_Ai=Xi.extend({fn:je("pushbutton"),w:ue.default(4.5),h:ue.default(6.5),id:ue.default(1),od:ue.default(1.2)}),fAi=t=>{const e=_Ai.parse(t),n=e.w,o=e.h,i=e.id,r=[ka(1,-n/2,o/2,i,i*1.5),ka(2,-n/2,-o/2,i,i*1.5),ka(3,n/2,-o/2,i,i*1.5),ka(4,n/2,o/2,i,i*1.5)],s=[aR([{x:-n/2,y:-o/2},{x:-n/2,y:o/2}]),aR([{x:n/2,y:-o/2},{x:n/2,y:o/2}]),aR([{x:-n/2,y:0},{x:-n/5,y:0},{x:n/5*1/Math.sqrt(2),y:o/8}]),aR([{x:n/2,y:0},{x:n/5,y:0}])],a=tr(0,o/2+.4,.5),A=i*1.5/2,c=n,l=o,g=c/2+A,u=l/2+A,h=g+.5,d=u+.5,m={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:0,y:0},width:2*h,height:2*d,layer:"top"};return{circuitJson:[...r,...s,a,m],parameters:e}},JZt=Xi.extend({fn:$(),w:ue.default("22.58mm"),h:ue.optional(),left:ue.optional().default(20),right:ue.optional().default(20),top:ue.optional().default(2),bottom:ue.optional().default(2),p:ue.default(ue.parse("2.54mm")),pw:ue.default(ue.parse("1.6mm")),pl:ue.default(ue.parse("2.4mm")),innerhole:We().default(!1),innerholeedgedistance:ue.default(ue.parse("1.61mm")),silkscreenlabels:We().default(!1),silkscreenlabelmargin:ue.default(ue.parse("0.1mm"))}),IAi=t=>{const e=JZt.parse(t);return e.left&&e.right?Math.max(e.left,e.right)*e.p:e.left?e.left*e.p:e.right?e.right*e.p:51},Due=(t,e,n)=>{let o=[];return n==="right"&&(o=[{x:t+1/2,y:e},{x:t-1/2,y:e+.6/2},{x:t-1/2,y:e-.6/2},{x:t+1/2,y:e}]),n==="left"&&(o=[{x:t-1/2,y:e},{x:t+1/2,y:e+.6/2},{x:t+1/2,y:e-.6/2},{x:t-1/2,y:e}]),n==="top"&&(o=[{x:t,y:e+1/2},{x:t-.6/2,y:e-1/2},{x:t+.6/2,y:e-1/2},{x:t,y:e+1/2}]),n==="bottom"&&(o=[{x:t,y:e-1/2},{x:t-.6/2,y:e+1/2},{x:t+.6/2,y:e+1/2},{x:t,y:e-1/2}]),o},CAi=t=>{const e=JZt.parse(t),n=e.h??IAi(e),o=[],i=[],r=[];let s=[];const a=1,A=a,c=e.left+e.right+(e.bottom??0)+(e.top??0),g=`pin${c}`.length*.7/2;if(e.right){const m=-((e.right-1)/2)*e.p;for(let p=0;p<e.right;p++){if(p===0&&!e.left&&!e.bottom&&!e.silkscreenlabels&&(s=Due(e.w/2-e.pl*1.4,m+p*e.p,"right")),o.push(yi(p+1+e.left+(e.bottom??0),e.w/2-e.pl/2,m+p*e.p,e.pl,e.pw)),e.silkscreenlabels){const _=p+1+e.left+(e.bottom??0),f=`pin${_}`;r.push({type:"pcb_silkscreen_text",pcb_silkscreen_text_id:`pin_${_}`,pcb_component_id:"1",layer:"top",anchor_position:{x:e.w/2-e.pl-(g+e.silkscreenlabelmargin),y:m+p*e.p},text:f,font_size:.7,font:"tscircuit2024",anchor_alignment:"center"})}e.innerhole&&(i.push(ka(p+1+e.left+(e.bottom??0)+c,e.w/2,m+p*e.p,a,A)),i.push(ka(p+1+e.left+(e.bottom??0)+c*2,e.w/2-e.innerholeedgedistance,m+p*e.p,a,A)))}}if(e.left){const m=(e.left-1)/2*e.p;for(let p=0;p<e.left;p++){if(p===0&&!e.silkscreenlabels&&(s=Due(-e.w/2+e.pl*1.4,m-p*e.p,"left")),o.push(yi(p+1,-e.w/2+e.pl/2,m-p*e.p,e.pl,e.pw)),e.silkscreenlabels){const _=p+1,f=`pin${_}`;r.push({type:"pcb_silkscreen_text",pcb_silkscreen_text_id:`pin_${_}`,pcb_component_id:"1",layer:"top",anchor_position:{x:-e.w/2+e.pl+(g+e.silkscreenlabelmargin),y:m-p*e.p},text:f,font_size:.7,font:"tscircuit2024",anchor_alignment:"center"})}e.innerhole&&(i.push(ka(p+1+c,-e.w/2,m-p*e.p,a,A)),i.push(ka(p+1+c*2,-e.w/2+e.innerholeedgedistance,m-p*e.p,a,A)))}}if(e.top){const m=(e.top-1)/2*e.p;for(let p=0;p<e.top;p++){if(p===0&&!e.left&&!e.bottom&&!e.right&&!e.silkscreenlabels&&(s=Due(m-p*e.p,n/2-e.pl*1.4,"top")),o.push(yi(p+1+e.left+e.right+(e.bottom??0),m-p*e.p,n/2-e.pl/2,e.pw,e.pl)),e.silkscreenlabels){const _=p+1+e.left+e.right+(e.bottom??0),f=`pin${_}`;r.push({type:"pcb_silkscreen_text",pcb_silkscreen_text_id:`pin_${_}`,pcb_component_id:"1",layer:"top",anchor_position:{x:m-p*e.p,y:n/2-e.pl-(g+e.silkscreenlabelmargin)},text:f,font_size:.7,font:"tscircuit2024",anchor_alignment:"center",ccw_rotation:270})}e.innerhole&&(i.push(ka(p+1+e.left+e.right+(e.bottom??0)+c,m-p*e.p,n/2,a,A)),i.push(ka(p+1+e.left+e.right+(e.bottom??0)+c*2,m-p*e.p,n/2-e.innerholeedgedistance,a,A)))}}if(e.bottom){const m=-((e.bottom-1)/2)*e.p;for(let p=0;p<e.bottom;p++){if(p===0&&!e.left&&!e.silkscreenlabels&&(s=Due(m+p*e.p,-n/2+e.pl*1.4,"bottom")),o.push(yi(p+1+e.left,m+p*e.p,-n/2+e.pl/2,e.pw,e.pl)),e.silkscreenlabels){const _=p+1+e.left,f=`pin${_}`;r.push({type:"pcb_silkscreen_text",pcb_silkscreen_text_id:`pin_${_}`,pcb_component_id:"1",layer:"top",anchor_position:{x:m+p*e.p,y:-n/2+e.pl+(g+e.silkscreenlabelmargin)},text:f,font_size:.7,font:"tscircuit2024",anchor_alignment:"center",ccw_rotation:90})}e.innerhole&&(i.push(ka(p+1+e.left+c,m+p*e.p,-n/2,a,A)),i.push(ka(p+1+e.left+c*2,m+p*e.p,-n/2+e.innerholeedgedistance,a,A)))}}const u={type:"pcb_silkscreen_path",pcb_silkscreen_path_id:"pcb_silkscreen_triangle_1",pcb_component_id:"2",route:s,stroke_width:.1,layer:"top"},h={type:"pcb_silkscreen_path",pcb_silkscreen_path_id:"pcb_silkscreen_path_1",pcb_component_id:"1",route:[{x:-e.w/2,y:n/2},{x:e.w/2,y:n/2},{x:e.w/2,y:-n/2},{x:-e.w/2,y:-n/2},{x:-e.w/2,y:n/2}],stroke_width:.1,layer:"top"},d=tr(0,n/1.8,n/25);return{circuitJson:[...o,...i,...r,h,...e.silkscreenlabels?[]:[u],d],parameters:e}},WZt=Xi.extend({fn:$(),w:ue.default("22.58mm"),h:ue.optional(),left:ue.optional().default(20),right:ue.optional().default(20),top:ue.optional().default(2),bottom:ue.optional().default(2),p:ue.default(ue.parse("2.54mm")),pw:ue.default(ue.parse("1.6mm")),pl:ue.default(ue.parse("3.2mm")),innerhole:We().default(!1),innerholeedgedistance:ue.default(ue.parse("1.61mm"))}),yAi=t=>{const e=WZt.parse(t);return e.left&&e.right?Math.max(e.left,e.right)*e.p:e.left?e.left*e.p:e.right?e.right*e.p:51},xAi=(t,e,n,o=1,i=.6)=>{const r=o/2,s=i/2;return{left:[{x:t+r,y:e},{x:t-r,y:e+s},{x:t-r,y:e-s},{x:t+r,y:e}],right:[{x:t-r,y:e},{x:t+r,y:e+s},{x:t+r,y:e-s},{x:t-r,y:e}],top:[{x:t,y:e-r},{x:t-s,y:e+r},{x:t+s,y:e+r},{x:t,y:e-r}],bottom:[{x:t,y:e+r},{x:t-s,y:e-r},{x:t+s,y:e-r},{x:t,y:e+r}]}[n]},EAi=t=>{const e=WZt.parse(t),n=e.h??yAi(e),o=[],i=[],r=[],s=1,a=1.2,A=e.left+e.right+(e.bottom??0)+(e.top??0);let c=[],l=1;if(e.left){const d=(e.left-1)/2*e.p;for(let m=0;m<e.left;m++)m===0&&(c=xAi(-e.w/2-e.pl/2,d-m*e.p,"left")),o.push(yi(l,-e.w/2+e.pl/2,d-m*e.p,e.pl,e.pw)),i.push({type:"pcb_silkscreen_text",pcb_silkscreen_text_id:`pin_${l}`,pcb_component_id:"1",layer:"top",anchor_position:{x:-e.w/2+e.pl/2-4.5,y:d-m*e.p},text:`pin${l}`,font_size:.7,font:"tscircuit2024",anchor_alignment:"center"}),l++,e.innerhole&&r.push(ka(l+A,-e.w/2+e.innerholeedgedistance,d-m*e.p,s,a))}if(e.bottom){const d=(e.bottom-1)/2*e.p;for(let m=e.bottom-1;m>=0;m--)o.push(yi(l,d-m*e.p,-n/2+e.pl/2,e.pw,e.pl)),i.push({type:"pcb_silkscreen_text",pcb_silkscreen_text_id:`pin_${l}`,pcb_component_id:"1",layer:"top",anchor_position:{x:d-m*e.p,y:-n/2+e.pl/2-3.2},text:`pin${l}`,font_size:.7,font:"tscircuit2024",anchor_alignment:"center"}),l++,e.innerhole&&r.push(ka(l+A,d-m*e.p,-n/2+e.innerholeedgedistance,s,a))}if(e.right){const d=-((e.right-1)/2)*e.p;for(let m=0;m<e.right;m++)o.push(yi(l,e.w/2-e.pl/2,d+m*e.p,e.pl,e.pw)),i.push({type:"pcb_silkscreen_text",pcb_silkscreen_text_id:`pin_${l}`,pcb_component_id:"1",layer:"top",anchor_position:{x:e.w/2-e.pl/2+3.7,y:d+m*e.p},text:`pin${l}`,font_size:.7,font:"tscircuit2024",anchor_alignment:"center"}),l++,e.innerhole&&r.push(ka(l+A,e.w/2-e.innerholeedgedistance,d+m*e.p,s,a))}if(e.top){const d=-((e.top-1)/2)*e.p;for(let m=e.top-1;m>=0;m--)o.push(yi(l,d+m*e.p,n/2-e.pl/2,e.pw,e.pl)),i.push({type:"pcb_silkscreen_text",pcb_silkscreen_text_id:`pin_${l}`,pcb_component_id:"1",layer:"top",anchor_position:{x:d+m*e.p,y:n/2-e.pl/2+3.2},text:`pin${l}`,font_size:.7,font:"tscircuit2024",anchor_alignment:"center"}),l++,e.innerhole&&r.push(ka(l+A,d+m*e.p,n/2-e.innerholeedgedistance,s,a))}const g={type:"pcb_silkscreen_path",pcb_silkscreen_path_id:"1",pcb_component_id:"1",layer:"top",route:c,stroke_width:.1},u={type:"pcb_silkscreen_path",pcb_silkscreen_path_id:"pcb_silkscreen_path_1",pcb_component_id:"1",route:[{x:-e.w/2-e.pl/3,y:n/2+e.pl/3},{x:e.w/2+e.pl/3,y:n/2+e.pl/3},{x:e.w/2+e.pl/3,y:-n/2-e.pl/3},{x:-e.w/2-e.pl/3,y:-n/2-e.pl/3},{x:-e.w/2-e.pl/3,y:n/2+e.pl/3}],stroke_width:.1,layer:"top"},h=tr(0,n/1.8,n/25);return{circuitJson:[...r,...o,...i,u,g,h],parameters:e}},BAi=t=>(t.legsoutside=!0,t.pl||(t.pl=1.5),t.pw||(t.pw=.3),mG(t)),jZt=Xi.extend({fn:$(),w:ue.default("10mm"),h:ue.optional(),left:ue.optional().default(20),right:ue.optional().default(20),top:ue.optional().default(0),bottom:ue.optional().default(0),p:ue.default(ue.parse("2.54mm")),id:ue.optional().default(ue.parse("1mm")),od:ue.optional().default(ue.parse("1.5mm"))}),SAi=t=>{const e=jZt.parse(t);return e.left&&e.right?Math.max(e.left,e.right)*e.p:e.left?e.left*e.p:e.right?e.right*e.p:51},Nue=(t,e,n,o=1,i=.6)=>{const r=o/2,s=i/2;return{left:[{x:t+r,y:e},{x:t-r,y:e+s},{x:t-r,y:e-s},{x:t+r,y:e}],right:[{x:t-r,y:e},{x:t+r,y:e+s},{x:t+r,y:e-s},{x:t-r,y:e}],top:[{x:t,y:e-r},{x:t-s,y:e+r},{x:t+s,y:e+r},{x:t,y:e-r}],bottom:[{x:t,y:e+r},{x:t-s,y:e-r},{x:t+s,y:e-r},{x:t,y:e+r}]}[n]},bAi=t=>{const e=jZt.parse(t),n=e.h??SAi(e),o=[],i=e.id,r=e.od;let s=[];if(e.right){const l=-((e.right-1)/2)*e.p;for(let g=0;g<e.right;g++)g===0&&!e.left&&!e.bottom&&(s=Nue(e.w/2+r*1.4,l+g*e.p,"right")),o.push(ka(g+1+e.left+(e.bottom??0),e.w/2,l+g*e.p,i,r))}if(e.left){const l=-((e.left-1)/2)*e.p;for(let g=0;g<e.left;g++)g===e.left-1&&(s=Nue(-e.w/2-r*1.4,l+g*e.p,"left")),o.push(ka(g+1,-e.w/2,l+g*e.p,i,r))}if(e.top){const l=-((e.top-1)/2)*e.p;for(let g=0;g<e.top;g++)g===e.top-1&&!e.left&&!e.bottom&&!e.right&&(s=Nue(l+g*e.p,n/2+r*1.4,"top")),o.push(ka(g+1+e.right+(e.bottom??0)+e.left,l+g*e.p,n/2,i,r))}if(e.bottom){const l=-((e.bottom-1)/2)*e.p;for(let g=0;g<e.bottom;g++)g===0&&!e.left&&(s=Nue(l+g*e.p,-n/2-r*1.4,"bottom")),o.push(ka(g+1+e.left,l+g*e.p,-n/2,i,r))}const a={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:-e.w/2-r,y:n/2+r},{x:e.w/2+r,y:n/2+r},{x:e.w/2+r,y:-n/2-r},{x:-e.w/2-r,y:-n/2-r},{x:-e.w/2-r,y:n/2+r}],stroke_width:.1,layer:"top"},c=tr(0,n/1.7,n/25);return{circuitJson:[...o,A,c,a],parameters:e}},QAi=t=>{const{centerX:e,centerY:n,straightHalfLength:o,radius:i,arcSegmentCount:r=9,orientation:s="horizontal"}=t;if(o<0)throw new Error("Capsule straightHalfLength must be non-negative");if(i<=0)throw new Error("Capsule radius must be positive");if(r<2)throw new Error("Capsule arcSegmentCount must be at least 2");if(s==="horizontal"){const g=e-o,u=e+o,h=Array.from({length:r+1},(m,p)=>{const _=Math.PI/2-p*Math.PI/r;return{x:u+Math.cos(_)*i,y:n+Math.sin(_)*i}}),d=Array.from({length:r+1},(m,p)=>{const _=-Math.PI/2+p*Math.PI/r;return{x:g-Math.cos(_)*i,y:n+Math.sin(_)*i}});return[{x:g,y:n+i},{x:u,y:n+i},...h.slice(1,-1),{x:u,y:n-i},{x:g,y:n-i},...d.slice(1,-1)]}const a=n-o,A=n+o,c=Array.from({length:r+1},(g,u)=>{const h=Math.PI-u*Math.PI/r;return{x:e+Math.cos(h)*i,y:A+Math.sin(h)*i}}),l=Array.from({length:r+1},(g,u)=>{const h=u*Math.PI/r;return{x:e+Math.cos(h)*i,y:a-Math.sin(h)*i}});return[{x:e-i,y:a},{x:e-i,y:A},...c.slice(1,-1),{x:e+i,y:A},{x:e+i,y:a},...l.slice(1,-1)]},XZt=(t,e,n,o)=>Array.from({length:25},(i,r)=>{const s=r/24*Math.PI-Math.PI/2;return{x:t+(o==="right"?1:-1)*Math.cos(s)*n,y:e+Math.sin(s)*n}}),vAi=Xi.extend({fn:$(),p:ue.optional().default("4.88mm"),id:ue.optional().default("0.8mm"),od:ue.optional().default("1.5mm"),w:ue.optional().default("5.6mm"),h:ue.optional().default("3.5mm")}),PAi=t=>{const e=vAi.parse(t),{p:n,id:o,od:i,w:r,h:s}=e,a=s/2,A=[ka(1,-n/2,0,o,i),ka(2,n/2,0,o,i)],c=XZt(-r/2,0,a,"left"),l=XZt(r/2,0,a,"right"),g={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[...c,...c.slice(1).reverse(),{x:-r/2,y:-s/2},{x:r/2,y:-s/2},...l,{x:r/2,y:s/2},{x:-r/2,y:s/2}],stroke_width:.1,pcb_silkscreen_path_id:""},u=tr(0,n/4,.5),d=n/2+i/2,m=Math.max(s/2+.25,r/2+.03),p={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",outline:QAi({centerX:0,centerY:0,straightHalfLength:d,radius:m,arcSegmentCount:9}),layer:"top"};return{circuitJson:[...A,g,u,p],parameters:e}};Xi.extend({w:ue,h:ue});var wAi=t=>{const{w:e,h:n}=t,o=za(e),i=za(n);return{circuitJson:[yi(1,0,0,o,i),tr(0,i/2+.5,.2)],parameters:t}},IP=(t,e,n,o,i,r)=>({pcb_plated_hole_id:"",type:"pcb_plated_hole",shape:"pill",x:e,y:n,outer_width:za(i),outer_height:za(r),hole_width:za(o),hole_height:za(o),pcb_port_id:"",layers:["top","bottom"],port_hints:[t.toString()],ccw_rotation:0}),MAi=[{x:-2.73,y:3.71},{x:-2.73,y:-1.03},{x:2.73,y:-1.03},{x:2.73,y:3.71}],DAi=Xi.extend({fn:$(),num_pins:Eo([je(3),je(2)]).default(3),p:$().default("1.27mm"),id:$().default("0.72mm"),od:$().default("0.95mm"),w:$().default("4.5mm"),h:$().default("4.5mm"),inline:We().default(!1),string:$().optional()}),NAi=(t,e,n)=>Array.from({length:25},(o,i)=>{const r=i/24*Math.PI;return{x:t+Math.cos(r)*n,y:e+Math.sin(r)*n}}),RAi=t=>{const e=t.string?.match(/^to92_(\d+)/),n=e?Number.parseInt(e[1],10):3,o=DAi.parse({...t,num_pins:n}),{p:i,id:r,od:s,w:a,h:A,inline:c}=o,l=Number.parseFloat(A)/2,g=Number.parseFloat(i),u=Number.parseFloat(r),h=Number.parseFloat(s),d=h,m=h*(1.5/1.05);let p=[];if(o.num_pins===3)c?p=[px({pn:1,x:-g,y:l-g,holeDiameter:u,rectPadWidth:h,rectPadHeight:m}),IP(2,0,l-g,u,d,m),IP(3,g,l-g,u,d,m)]:p=[px({pn:1,x:-g,y:l-g,holeDiameter:u,rectPadWidth:h,rectPadHeight:h}),ka(2,0,l,u,h),ka(3,g,l-g,u,h)];else if(o.num_pins===2)p=[px({pn:1,x:-g,y:l-g,holeDiameter:u,rectPadWidth:d,rectPadHeight:m}),IP(2,g,l-g,u,d,m)];else throw new Error("Invalid number of pins for TO-92");const _=Number.parseFloat(a)/2,f=NAi(0,l,_),I={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[...f,{x:-_,y:0},{x:_,y:0},f[0]],stroke_width:.1,pcb_silkscreen_path_id:""},C=tr(0,l+1,.5),y={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",outline:MAi,layer:"top"};return{circuitJson:[...p,I,C,y],parameters:o}},TAi=Xi.extend({fn:$(),num_pins:je(2).default(2),w:$().default("2.15mm"),h:$().default("0.7mm"),pl:$().default("0.6mm"),pw:$().default("0.7mm"),p:$().default("1.4mm")}),kAi=t=>{const e=TAi.parse(t),n=tr(0,ue.parse(e.h),.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:ue.parse(e.p)/2,y:ue.parse(e.h)/2+.2},{x:-ue.parse(e.w)/2-.2,y:ue.parse(e.h)/2+.2},{x:-ue.parse(e.w)/2-.2,y:-ue.parse(e.h)/2-.2},{x:ue.parse(e.p)/2,y:-ue.parse(e.h)/2-.2}],stroke_width:.1,pcb_silkscreen_path_id:""},s={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:0,y:0},width:2.5,height:1.4,layer:"top"};return{circuitJson:LAi(e).concat(...AC(e),o,n,s),parameters:e}},FAi=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},LAi=t=>{const e=[],n=ue.parse(t.p),o=ue.parse(t.pl),i=ue.parse(t.pw),r=.075;for(let s=1;s<=t.num_pins;s++){const{x:a,y:A}=FAi({pn:s,p:n});e.push(yi(s,a,A,o,i,r))}return e},HAi=rR({w:"7.05mm",p:"1.27mm",pw:"0.65mm",pl:"1.975mm"}),OAi=t=>{const e=HAi.parse(t),n=[];for(let u=0;u<e.num_pins;u++){const{x:h,y:d}=lYe({num_pins:e.num_pins,pn:u+1,w:e.w,p:e.p??1.27,pl:e.pl,widthincludeslegs:!0});n.push(yi(u+1,h,d,e.pl??"1.5mm",e.pw??"0.6mm"))}const o=(e.num_pins/2-1)*e.p+e.pw,i=tr(0,o/2+1,o/12),r={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"",type:"pcb_silkscreen_path",route:[{x:-e.w/3,y:o/2+.4},{x:e.w/3,y:o/2+.4}],stroke_width:.1},s=(e.num_pins/2-1)*e.p+e.pw,a=e.w/2-1.395,A=e.w/2+.255,c=s/2+.25,l=s/2+.5,g={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",layer:"top",outline:Dy([{minX:-A,maxX:A,minY:-c,maxY:c},{minX:-a,maxX:a,minY:-l,maxY:l}])};return{circuitJson:[...n,i,r,g],parameters:e}},GAi=Xi.extend({fn:$(),num_pins:je(2).default(2),w:$().default("5.0mm"),h:$().default("2.30mm"),pl:$().default("1.25mm"),pw:$().default("2mm"),p:$().default("3.75mm")}),YAi=t=>{const e=GAi.parse(t),n=tr(0,ue.parse(e.h)/2+1,.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:ue.parse(e.p)/2+.5,y:ue.parse(e.h)/2+.5},{x:-ue.parse(e.w)/2-.5,y:ue.parse(e.h)/2+.5},{x:-ue.parse(e.w)/2-.5,y:-ue.parse(e.h)/2-.5},{x:ue.parse(e.p)/2+.5,y:-ue.parse(e.h)/2-.5}],stroke_width:.1,pcb_silkscreen_path_id:""},s={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:0,y:0},width:5.1,height:2.8,layer:"top"};return{circuitJson:KAi(e).concat(...AC(e),o,n,s),parameters:e}},UAi=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},KAi=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=UAi({pn:n,p:Number.parseFloat(t.p)});e.push(yi(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return e},VAi=Xi.extend({fn:$(),num_pins:je(2).default(2),w:$().default("4.4mm"),h:$().default("1.7mm"),pl:$().default("1.2mm"),pw:$().default("1.2mm"),p:$().default("2.8mm")}),zAi=t=>{const e=VAi.parse(t),n=tr(0,ue.parse(e.h)-.5,.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:ue.parse(e.p)/2,y:ue.parse(e.h)/2},{x:-ue.parse(e.w)/2-.2,y:ue.parse(e.h)/2},{x:-ue.parse(e.w)/2-.2,y:-ue.parse(e.h)/2},{x:ue.parse(e.p)/2,y:-ue.parse(e.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""},s={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:0,y:0},width:4.5,height:2.2,layer:"top"};return{circuitJson:WAi(e).concat(...AC(e),o,n,s),parameters:e}},JAi=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},WAi=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=JAi({pn:n,p:Number.parseFloat(t.p)});e.push(yi(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return e},jAi=Xi.extend({fn:$(),num_pins:je(2).default(2),w:$().default("3.30mm"),h:$().default("1.80mm"),pl:$().default("0.60mm"),pw:$().default("0.45mm"),p:$().default("2.1mm")}),XAi=t=>{const e=jAi.parse(t),n=tr(0,ue.parse(e.h)-.5,.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:ue.parse(e.p)/2,y:ue.parse(e.h)/2},{x:-ue.parse(e.w)/2,y:ue.parse(e.h)/2},{x:-ue.parse(e.w)/2,y:-ue.parse(e.h)/2},{x:ue.parse(e.p)/2,y:-ue.parse(e.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""},s={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:0,y:0},width:3.2,height:1.9,layer:"top"};return{circuitJson:$Ai(e).concat(...AC(e),o,n,s),parameters:e}},qAi=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},$Ai=t=>{const e=[],n=ue.parse(t.p),o=ue.parse(t.pl),i=ue.parse(t.pw),r=.05625;for(let s=1;s<=t.num_pins;s++){const{x:a,y:A}=qAi({pn:s,p:n});e.push(yi(s,a,A,o,i,r))}return e},ZAi=Xi.extend({fn:$(),num_pins:je(2).default(2),w:$().default("1.4mm"),h:$().default("0.9mm"),pl:$().default("0.36mm"),pw:$().default("0.25mm"),p:$().default("0.85mm")}),eci=t=>{const e=ZAi.parse(t),n=ue.parse(e.w),o=ue.parse(e.h),i=ue.parse(e.pl),r=ue.parse(e.pw),s=ue.parse(e.p),a=tr(0,o,.3),A={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:s/2+.15,y:o/2},{x:-n/2-.15,y:o/2},{x:-n/2-.15,y:-o/2},{x:s/2+.15,y:-o/2}],stroke_width:.1,pcb_silkscreen_path_id:""},c=s+i,l=r,g=n/2,u=o/2,h=c/2,d=l/2,m=Math.max(g,h),p=Math.max(u,d),_=Math.min(g,h),f=Math.min(u,d),I=m+.05,C=_-.055,y=p,x=f+.155,E={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",outline:Dy([{minX:-I,maxX:I,minY:-x,maxY:x},{minX:-C,maxX:C,minY:-y,maxY:y}]),layer:"top"};return{circuitJson:nci(e).concat(...AC(e),A,a,E),parameters:e}},tci=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},nci=t=>{const e=[],n=ue.parse(t.p),o=ue.parse(t.pl),i=ue.parse(t.pw),r=.03125;for(let s=1;s<=t.num_pins;s++){const{x:a,y:A}=tci({pn:s,p:n});e.push(yi(s,a,A,o,i,r))}return e},oci=Xi.extend({fn:$(),num_pins:je(2).default(2),w:$().default("1.3mm"),h:$().default("0.9mm"),pl:$().default("0.4mm"),pw:$().default("0.7mm"),p:$().default("0.7mm")}),ici=t=>{const e=oci.parse(t),n=tr(0,ue.parse(e.h)+.1,.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:ue.parse(e.p)/2+.2,y:ue.parse(e.h)/2+.2},{x:-ue.parse(e.w)/2-.2,y:ue.parse(e.h)/2+.2},{x:-ue.parse(e.w)/2-.2,y:-ue.parse(e.h)/2-.2},{x:ue.parse(e.p)/2+.2,y:-ue.parse(e.h)/2-.2}],stroke_width:.1,pcb_silkscreen_path_id:""},s={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:0,y:0},width:1.6,height:1.2,layer:"top"};return{circuitJson:sci(e).concat(...AC(e),o,n,s),parameters:e}},rci=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},sci=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=rci({pn:n,p:Number.parseFloat(t.p)});e.push(yi(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw),.025))}return e},aci=Xi.extend({fn:$(),num_pins:je(2).default(2),w:$().default("3.05mm"),h:$().default("1.4mm"),pl:$().default("0.5mm"),pw:$().default("0.5mm"),pad_spacing:$().default("2.2mm")}),Aci=t=>{const e=aci.parse(t),n=tr(0,ue.parse(e.h),.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:ue.parse(e.pad_spacing)/2,y:ue.parse(e.h)/2},{x:-ue.parse(e.w)/2-.2,y:ue.parse(e.h)/2},{x:-ue.parse(e.w)/2-.2,y:-ue.parse(e.h)/2},{x:ue.parse(e.pad_spacing)/2,y:-ue.parse(e.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""},s={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:0,y:0},width:3.2,height:1.9,layer:"top"};return{circuitJson:lci(e).concat(...AC(e),o,n,s),parameters:e}},cci=t=>{const{pn:e,pad_spacing:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},lci=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=cci({pn:n,pad_spacing:Number.parseFloat(t.pad_spacing)});e.push(yi(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw),.0625))}return e},gci=Xi.extend({fn:$(),num_pins:je(2).default(2),w:$().default("4.4mm"),h:$().default("2.1mm"),pl:$().default("1.10mm"),pw:$().default("1.10mm"),p:$().default("2.8mm")}),uci=t=>{const e=gci.parse(t),n=tr(0,ue.parse(e.h),.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:ue.parse(e.p)/2,y:ue.parse(e.h)/2},{x:-ue.parse(e.w)/2-.2,y:ue.parse(e.h)/2},{x:-ue.parse(e.w)/2-.2,y:-ue.parse(e.h)/2},{x:ue.parse(e.p)/2,y:-ue.parse(e.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""},s={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:0,y:0},width:4.4,height:2.3,layer:"top"};return{circuitJson:hci(e).concat(...AC(e),o,n,s),parameters:e}},dci=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},hci=t=>{const e=[],n=ue.parse(t.p),o=ue.parse(t.pl),i=ue.parse(t.pw),r=.125;for(let s=1;s<=t.num_pins;s++){const{x:a,y:A}=dci({pn:s,p:n});e.push(yi(s,a,A,o,i,r))}return e},mci=Xi.extend({fn:$(),num_pins:je(2).default(2),w:$().default("4.4mm"),h:$().default("2.1mm"),pl:$().default("0.91mm"),pw:$().default("1.22mm"),p:$().default("3.146mm")}),pci=t=>{const e=mci.parse(t),n=tr(0,ue.parse(e.h),.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:ue.parse(e.p)/2,y:ue.parse(e.h)/2},{x:-ue.parse(e.w)/2-.2,y:ue.parse(e.h)/2},{x:-ue.parse(e.w)/2-.2,y:-ue.parse(e.h)/2},{x:ue.parse(e.p)/2,y:-ue.parse(e.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""},s={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:0,y:0},width:4.9,height:2.7,layer:"top"};return{circuitJson:fci(e).concat(...AC(e),o,n,s),parameters:e}},_ci=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},fci=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=_ci({pn:n,p:Number.parseFloat(t.p)});e.push(yi(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return e},Ici=Xi.extend({fn:$(),num_pins:je(2).default(2),w:$().default("1.80mm"),h:$().default("1.00mm"),pl:$().default("0.66mm"),pw:$().default("0.5mm"),p:$().default("0.8mm")}),Cci=t=>{const e=Ici.parse(t),n=tr(0,ue.parse(e.h),.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:ue.parse(e.p)/2,y:ue.parse(e.h)/2},{x:-ue.parse(e.w)/2-.1,y:ue.parse(e.h)/2},{x:-ue.parse(e.w)/2-.1,y:-ue.parse(e.h)/2},{x:ue.parse(e.p)/2,y:-ue.parse(e.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""},s={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:0,y:0},width:2.3,height:1.5,layer:"top"};return{circuitJson:xci(e).concat(...AC(e),o,n,s),parameters:e}},yci=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},xci=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=yci({pn:n,p:Number.parseFloat(t.p)});e.push(yi(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return e},Eci=Xi.extend({fn:$(),num_pins:je(2).default(2),w:$().default("6.2mm"),h:$().default("3.4mm"),pl:$().default("1.4mm"),pw:$().default("2.1mm"),p:$().default("4.4mm")}),Bci=t=>{const e=Eci.parse(t),n=tr(0,ue.parse(e.h)/2+.4,.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:ue.parse(e.p)/2,y:ue.parse(e.h)/2},{x:-ue.parse(e.w)/2-.2,y:ue.parse(e.h)/2},{x:-ue.parse(e.w)/2-.2,y:-ue.parse(e.h)/2},{x:ue.parse(e.p)/2,y:-ue.parse(e.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""},s={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:0,y:0},width:6.3,height:3,layer:"top"};return{circuitJson:bci(e).concat(...AC(e),o,n,s),parameters:e}},Sci=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},bci=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=Sci({pn:n,p:Number.parseFloat(t.p)});e.push(yi(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw),.125))}return e},qZt=(t,e)=>({type:"pcb_smtpad",points:e,layer:"top",shape:"polygon",pcb_smtpad_id:"",port_hints:Array.isArray(t)?t.map(n=>n.toString()):[t.toString()]}),Qci=[{x:-2.85,y:-2.5},{x:-2.85,y:2.5},{x:2.25,y:2.5},{x:2.25,y:-2.5}],vci=[{x:-2.85,y:-2.5},{x:-2.85,y:2.5},{x:2.85,y:2.5},{x:2.85,y:-2.5}],Pci=[{x:.9,y:.5},{x:2.6,y:.5},{x:2.6,y:-.5},{x:.9,y:-.5},{x:.4,y:-1},{x:-.4,y:-1},{x:-.9,y:-.5},{x:-2.6,y:-.5},{x:-2.6,y:.5},{x:-.9,y:.5},{x:-.4,y:1},{x:.4,y:1}],wci=[{x:2,y:-.8665},{x:-1.125,y:-.8665},{x:-1.125,y:-.45},{x:-2.6,y:-.45},{x:-2.6,y:.45},{x:-1.125,y:.45},{x:-1.125,y:.8665},{x:2,y:.8665}],Mci=Xi.extend({fn:$(),num_pins:Eo([je(3),je(5)]).default(3),w:$().default("4.20mm"),h:$().default("4.80mm"),pl:$().default("1.3mm"),pw:$().default("0.9mm"),p:$().default("1.5mm"),string:$().optional()}),Dci=t=>{const e=Number.parseFloat(t.p),n=Number.parseFloat(t.pw),o=Number.parseFloat(t.w),i=Number.parseFloat(t.pl),r=-o/2+.15,s=o/2-1,a=Number.parseFloat(t.h)/2,A=[yi(1,r,e,i,n),qZt(2,wci),yi(3,r,-e,i,n)],c=tr(0,a+.5,.3),l={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-s,y:a},{x:s,y:a},{x:s,y:a/2+.5}],type:"pcb_silkscreen_path",stroke_width:.1},g={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_2",route:[{x:-s,y:-a},{x:s,y:-a},{x:s,y:-a/2-.5}],type:"pcb_silkscreen_path",stroke_width:.1},u={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",outline:Qci,layer:"top"};return[...A,l,g,c,u]},Nci=t=>{const e=[yi(1,-1.85,-1.5,1.5,.7),yi(2,-1.85,1.5,1.5,.7),qZt(3,Pci),yi(4,1.85,-1.5,1.5,.7),yi(5,1.85,1.5,1.5,.7)],n=Number.parseFloat(t.w)/2-1,o=Number.parseFloat(t.h)/2,i=tr(0,o+.5,.3),r={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-n,y:o},{x:n,y:o}],type:"pcb_silkscreen_path",stroke_width:.1},s={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_2",route:[{x:-n,y:-o},{x:n,y:-o}],type:"pcb_silkscreen_path",stroke_width:.1},a={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",outline:vci,layer:"top"};return[...e,r,s,i,a]},Rci=t=>{const e=t.string?.match(/^sot89_(\d+)/),n=e?Number.parseInt(e[1],10):3,o=Mci.parse({...t,num_pins:n});if(o.num_pins===3)return{circuitJson:Dci(o),parameters:o};if(o.num_pins===5)return{circuitJson:Nci(o),parameters:o};throw new Error("Invalid number of pins for SOT89")},Tci=Xi.extend({fn:$(),p:ue.optional().default("5.0mm"),id:ue.optional().default("1.0mm"),od:ue.optional().default("1.9mm"),w:ue.optional().default("13mm"),h:ue.optional().default("7mm"),num_pins:ft().optional(),string:$().optional()}),$Zt=t=>{const e=Tci.parse(t),{id:n,od:o,w:i,h:r,string:s}=e,a=e.num_pins??Number.parseInt(s?.match(/^to220(?:_|-)(\d+)/i)?.[1]??"3"),A=-1,c=i/2,l=r/2,g=2.5,u=i*.4,h=Math.max(g,u/(a-1)),d=Array.from({length:a},(H,G)=>{const U=a%2===0?(G-a/2+.5)*h:(G-Math.floor(a/2))*h;return ka(G+1,U,A,n,o)}),m={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-c,y:-l},{x:c,y:-l},{x:c,y:l},{x:-c,y:l},{x:-c,y:-l}],stroke_width:.1,pcb_silkscreen_path_id:""},p=-l+2*r/3,_={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-c,y:p},{x:c,y:p}],stroke_width:.1,pcb_silkscreen_path_id:""},f=[{type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-i/6,y:p},{x:-i/6,y:l}],stroke_width:.1,pcb_silkscreen_path_id:""},{type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:i/6,y:p},{x:i/6,y:l}],stroke_width:.1,pcb_silkscreen_path_id:""}],I=tr(0,r/2+.6,.5),C=Math.max(...d.map(H=>Math.abs(H.x)))+o/2,y=A+o/2,x=A-o/2,E=Math.max(C+.25,c-o*.59),B=l-o*.63,b=x-(o/2+.01),Q=-E,w=E,D=Math.min(b,x-.25),k=Math.max(B,y+.25),T={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:(Q+w)/2,y:(D+k)/2},width:w-Q,height:k-D,layer:"top"};return{circuitJson:[...d,m,_,...f,I,T],parameters:{...e,p:h}}},dYe=2.54,kci=Xi.extend({fn:$(),id:ue.optional().default("1.2mm"),od:ue.optional().default("1.905mm"),ph:ue.optional().default("2mm"),w:ue.optional().default("13mm"),h:ue.optional().default("7mm"),num_pins:ft().optional(),string:$().optional()}),Fci=t=>{const e=kci.parse(t),n=e.num_pins??Number.parseInt(e.string?.match(/^to220f(?:_|-)(\d+)/i)?.[1]??"3"),o=$Zt({...e,fn:"to220",string:e.string?.replace(/^to220f/i,"to220"),num_pins:n}),i=-1,r=Array.from({length:n},(a,A)=>{const c=n%2===0?(A-n/2+.5)*dYe:(A-Math.floor(n/2))*dYe;return A===0?px({pn:1,x:c,y:i,holeDiameter:e.id,rectPadWidth:e.od,rectPadHeight:e.ph}):IP(A+1,c,i,za(e.id),za(e.od),za(e.ph))}),s=o.circuitJson.filter(a=>a.type!=="pcb_plated_hole");return{circuitJson:[...r,...s],parameters:{...e,p:dYe,num_pins:n}}},Lci=Xi.extend({fn:$(),num_pins:je(2).default(2),w:$().default("5.40mm"),h:$().default("2.30mm"),pl:$().default("1.30mm"),pw:$().default("1.70mm"),p:$().default("3.5mm")}),Hci=t=>{const e=Lci.parse(t),n=tr(0,ue.parse(e.h)/2+.4,.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:ue.parse(e.p)/2,y:ue.parse(e.h)/2},{x:-ue.parse(e.w)/2,y:ue.parse(e.h)/2},{x:-ue.parse(e.w)/2,y:-ue.parse(e.h)/2},{x:ue.parse(e.p)/2,y:-ue.parse(e.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""},s={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:0,y:0},width:5.3,height:2.2,layer:"top"};return{circuitJson:Gci(e).concat(o,n,s),parameters:e}},Oci=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},Gci=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=Oci({pn:n,p:Number.parseFloat(t.p)});e.push(yi(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw),.125))}return e},Yci=Xi.extend({fn:$(),num_pins:je(2).default(2),w:$().default("1.90mm"),h:$().default("1.33mm"),pl:$().default("0.5mm"),pw:$().default("0.7mm"),p:$().default("0.8mm")}),Uci=t=>{const e=Yci.parse(t),n=tr(0,ue.parse(e.h)+.1,.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:ue.parse(e.p)/2+.1,y:ue.parse(e.h)/2},{x:-ue.parse(e.w)/2,y:ue.parse(e.h)/2},{x:-ue.parse(e.w)/2,y:-ue.parse(e.h)/2},{x:ue.parse(e.p)/2+.1,y:-ue.parse(e.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""},s={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:0,y:0},width:1.8,height:1.2,layer:"top"};return{circuitJson:Vci(e).concat(...AC(e),o,n,s),parameters:e}},Kci=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},Vci=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=Kci({pn:n,p:Number.parseFloat(t.p)});e.push(yi(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw),.0625))}return e},zci=Xi.extend({fn:$(),num_pins:je(2).default(2),w:$().default("7.0mm"),h:$().default("3.35mm"),pl:$().default("1.50mm"),pw:$().default("2.70mm"),p:$().default("4.8mm")}),Jci=t=>{const e=zci.parse(t),n=tr(0,ue.parse(e.h),.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:ue.parse(e.p)/2,y:ue.parse(e.h)/2},{x:-ue.parse(e.w)/2,y:ue.parse(e.h)/2},{x:-ue.parse(e.w)/2,y:-ue.parse(e.h)/2},{x:ue.parse(e.p)/2,y:-ue.parse(e.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""},s={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:0,y:0},width:6.8,height:3.2,layer:"top"};return{circuitJson:jci(e).concat(o,n,s),parameters:e}},Wci=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},jci=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=Wci({pn:n,p:Number.parseFloat(t.p)});e.push(yi(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw),.125))}return e},Xci=Xi.extend({fn:$(),num_pins:je(2).default(2),w:$().default("3.0mm"),h:$().default("1.80mm"),pl:$().default("0.80mm"),pw:$().default("1.20mm"),p:$().default("1.6mm")}),qci=t=>{const e=Xci.parse(t),n=tr(0,ue.parse(e.h),.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:ue.parse(e.p)/2,y:ue.parse(e.h)/2},{x:-ue.parse(e.w)/2-.1,y:ue.parse(e.h)/2},{x:-ue.parse(e.w)/2-.1,y:-ue.parse(e.h)/2},{x:ue.parse(e.p)/2,y:-ue.parse(e.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""},s={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:0,y:0},width:2.9,height:1.7,layer:"top"};return{circuitJson:Zci(e).concat(o,n,s),parameters:e}},$ci=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},Zci=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=$ci({pn:n,p:Number.parseFloat(t.p)});e.push(yi(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw),.1))}return e},eli=Xi.extend({fn:$(),num_pins:je(2).default(2),w:$().default("7.10mm"),h:$().default("3.40mm"),pl:$().default("2.50mm"),pw:$().default("1.80mm"),p:$().default("4.00mm")}),tli=t=>{const e=eli.parse(t),n=tr(0,ue.parse(e.h)/2+.5,.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:ue.parse(e.p)/2,y:ue.parse(e.h)/2},{x:-ue.parse(e.w)/2-.5,y:ue.parse(e.h)/2},{x:-ue.parse(e.w)/2-.5,y:-ue.parse(e.h)/2},{x:ue.parse(e.p)/2,y:-ue.parse(e.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""},s={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:0,y:0},width:7,height:3.5,layer:"top"};return{circuitJson:oli(e).concat(o,n,s),parameters:e}},nli=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},oli=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=nli({pn:n,p:Number.parseFloat(t.p)});e.push(yi(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw),.125))}return e},ili=Xi.extend({fn:$(),num_pins:je(2).default(2),w:$().default("4.80mm"),h:$().default("2.10mm"),pl:$().default("1.30mm"),pw:$().default("1.40mm"),p:$().default("2.9mm")}),rli=t=>{const e=ili.parse(t),n=tr(0,ue.parse(e.h)-.5,.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:ue.parse(e.p)/2,y:ue.parse(e.h)/2},{x:-ue.parse(e.w)/2,y:ue.parse(e.h)/2},{x:-ue.parse(e.w)/2,y:-ue.parse(e.h)/2},{x:ue.parse(e.p)/2,y:-ue.parse(e.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""},s={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:0,y:0},width:4.7,height:2.3,layer:"top"};return{circuitJson:ali(e).concat(o,n,s),parameters:e}},sli=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},ali=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=sli({pn:n,p:Number.parseFloat(t.p)});e.push(yi(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw),.125))}return e},Ali=Xi.extend({fn:$(),num_pins:je(2).default(2),w:$().default("7.30mm"),h:$().default("4.40mm"),pl:$().default("2.50mm"),pw:$().default("2.30mm"),p:$().default("4.30mm")}),cli=t=>{const e=Ali.parse(t),n=tr(0,ue.parse(e.h)/2+.5,.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:ue.parse(e.p)/2,y:ue.parse(e.h)/2},{x:-ue.parse(e.w)/2-.1,y:ue.parse(e.h)/2},{x:-ue.parse(e.w)/2-.1,y:-ue.parse(e.h)/2},{x:ue.parse(e.p)/2,y:-ue.parse(e.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""},s={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:0,y:0},width:7.3,height:4.5,layer:"top"};return{circuitJson:gli(e).concat(o,n,s),parameters:e}},lli=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},gli=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=lli({pn:n,p:Number.parseFloat(t.p)});e.push(yi(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw),.125))}return e},uli=Xi.extend({fn:$(),num_pins:je(2).default(2),w:$().default("10.70mm"),h:$().default("6.60mm"),pl:$().default("2.50mm"),pw:$().default("3.30mm"),p:$().default("6.80mm")}),dli=t=>{const e=uli.parse(t),n=tr(0,3,.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:ue.parse(e.p)/2,y:ue.parse(e.h)/2-.8},{x:-ue.parse(e.w)/2-.8,y:ue.parse(e.h)/2-.8},{x:-ue.parse(e.w)/2-.8,y:-ue.parse(e.h)/2+.8},{x:ue.parse(e.p)/2,y:-ue.parse(e.h)/2+.8}],stroke_width:.1,pcb_silkscreen_path_id:""},s={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:0,y:0},width:9.8,height:6.7,layer:"top"};return{circuitJson:mli(e).concat(o,n,s),parameters:e}},hli=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},mli=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=hli({pn:n,p:Number.parseFloat(t.p)});e.push(yi(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw),.125))}return e},pli=Xi.extend({fn:$(),num_pins:ft().default(4),w:$().default("8.50mm"),h:$().default("6.90mm"),pl:$().default("2mm"),pw:$().default("1.5mm"),p:$().default("2.30mm"),string:$().optional()}),_li=t=>{const e=t.string?.match(/^sot223_(\d+)/),n=e?Number.parseInt(e[1],10):4;if(n===8){const i=Cli.parse({...t,num_pins:n});return{circuitJson:YX(i),parameters:i}}const o=pli.parse({...t,num_pins:n});if(o.num_pins===4)return{circuitJson:Ili(o),parameters:o};if(o.num_pins===5)return{circuitJson:xli(o),parameters:o};if(o.num_pins===6)return{circuitJson:Bli(o),parameters:o};throw new Error("Invalid number of pins")},fli=t=>{const{pn:e,w:n,p:o}=t;return e===1?{x:-n/2+1.1,y:o}:e===2?{x:-n/2+1.1,y:0}:e===3?{x:-n/2+1.1,y:-o}:{x:n/2-1.1,y:0}},Ili=t=>{const e=[];let n=0,o=0;for(let d=0;d<t.num_pins;d++){const{x:m,y:p}=fli({num_pins:t.num_pins,pn:d+1,w:Number.parseFloat(t.w),h:Number.parseFloat(t.h),pl:Number.parseFloat(t.pl),p:Number.parseFloat(t.p)}),_=d===3?3.8:Number.parseFloat(t.pw),f=Number.parseFloat(t.pl);n=Math.max(n,Math.abs(m)+f/2),o=Math.max(o,Math.abs(p)+_/2),e.push(yi(d+1,m,p,f,_))}const i=tr(0,0,.3),r=Number.parseFloat(t.w)/2-2.4,s=Number.parseFloat(t.h)/2,a={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-r,y:s},{x:r,y:s},{x:r,y:s/2+.5}],type:"pcb_silkscreen_path",stroke_width:.1},A={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_2",route:[{x:-r,y:-s},{x:r,y:-s},{x:r,y:-s/2-.5}],type:"pcb_silkscreen_path",stroke_width:.1},c=Number.parseFloat(t.w)/2,l=Number.parseFloat(t.h)/2,g=Math.max(n+.25,c+.15),u=Math.max(o+.25,l+.15),h={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:0,y:0},width:2*g,height:2*u,layer:"top"};return[...e,a,A,i,h]},Cli=rR({p:"0.90mm",w:"2.8mm",legsoutside:!0}),yli=t=>{const{p:e,pn:n,w:o}=t;if(n===1)return{x:-o/2+1.2,y:e/2+e};if(n===2)return{x:-o/2+1.2,y:e/2};if(n===3)return{x:-o/2+1.2,y:-e/2};if(n===4)return{x:-o/2+1.2,y:-e/2-e};if(n===5)return{x:o/2-1,y:0};throw new Error("Invalid pin number")},xli=t=>{const e=[];let n=0,o=0;for(let d=1;d<=t.num_pins;d++){const{x:m,y:p}=yli({h:Number.parseFloat(t.h),p:1.5,pn:d,w:Number.parseFloat(t.w)});let _=Number.parseFloat(t.pw),f=Number.parseFloat(t.pl);d===5?(_=3.4,f=1.8):(_=1,f=2.2),n=Math.max(n,Math.abs(m)+f/2),o=Math.max(o,Math.abs(p)+_/2),e.push(yi(d,m,p,f,_))}const i=Number.parseFloat(t.w)/2-2.4,r=Number.parseFloat(t.h)/2,s={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-i,y:r},{x:i,y:r},{x:i,y:r/2+.5}],type:"pcb_silkscreen_path",stroke_width:.1},a={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_2",route:[{x:-i,y:-r},{x:i,y:-r},{x:i,y:-r/2-.5}],type:"pcb_silkscreen_path",stroke_width:.1},A=tr(0,0,.3),c=Number.parseFloat(t.w)/2,l=Number.parseFloat(t.h)/2,g=Math.max(n+.25,c+.15),u=Math.max(o+.25,l+.15),h={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:0,y:0},width:2*g,height:2*u,layer:"top"};return[...e,s,a,A,h]},Eli=t=>{const{p:e,pn:n,w:o}=t;if(n===1)return{x:-o/2+1.2,y:2*e};if(n===2)return{x:-o/2+1.2,y:e};if(n===3)return{x:-o/2+1.2,y:0};if(n===4)return{x:-o/2+1.2,y:-e};if(n===5)return{x:-o/2+1.2,y:-2*e};if(n===6)return{x:o/2-1.175,y:0};throw new Error("Invalid pin number")},Bli=t=>{const e=[];let n=0,o=0;for(let d=1;d<=t.num_pins;d++){const{x:m,y:p}=Eli({h:Number.parseFloat(t.h),p:1.3,pn:d,w:8.7});let _=Number.parseFloat(t.pw),f=Number.parseFloat(t.pl);d===6?(_=3.4,f=2.15):(_=.6,f=2.2),n=Math.max(n,Math.abs(m)+f/2),o=Math.max(o,Math.abs(p)+_/2),e.push(yi(d,m,p,f,_))}const i=Number.parseFloat(t.w)/2-2.4,r=Number.parseFloat(t.h)/2,s={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-i,y:r},{x:i,y:r},{x:i,y:r/2+.5}],type:"pcb_silkscreen_path",stroke_width:.1},a={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_2",route:[{x:-i,y:-r},{x:i,y:-r},{x:i,y:-r/2-.5}],type:"pcb_silkscreen_path",stroke_width:.1},A=tr(0,0,.3),c=Number.parseFloat(t.w)/2,l=Number.parseFloat(t.h)/2,g=Math.max(n+.25,c+.15),u=Math.max(o+.25,l+.15),h={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:0,y:0},width:2*g,height:2*u,layer:"top"};return[...e,s,a,A,h]},Sli=Xi.extend({fn:$(),num_pins:ft().default(3),w:$().default("3.40mm"),h:$().default("3.30mm"),pl:$().default("1mm"),pw:$().default("0.7mm"),p:$().default("1.2mm"),string:$().optional()}),bli=t=>{const e=t.string?.match(/^sot23w_(\d+)/),n=e?Number.parseInt(e[1],3):3,o=Sli.parse({...t,num_pins:n});if(o.num_pins===3)return{circuitJson:vli(o),parameters:o};throw new Error("Invalid number of pins")},Qli=t=>{const{pn:e,p:n}=t;return e===1?{x:-n,y:.95}:e===2?{x:-n,y:-.95}:{x:n,y:0}},vli=t=>{const e=[];for(let _=0;_<t.num_pins;_++){const{x:f,y:I}=Qli({num_pins:t.num_pins,pn:_+1,w:Number.parseFloat(t.w),h:Number.parseFloat(t.h),pl:Number.parseFloat(t.pl),p:Number.parseFloat(t.p)});e.push(yi(_+1,f,I,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}const n=tr(0,Number.parseInt(t.h)/2+1,.3),o=Number.parseFloat(t.w)/2-1,i=Number.parseFloat(t.h)/2,r={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-o,y:i},{x:o+.3,y:i},{x:o+.3,y:i/2}],type:"pcb_silkscreen_path",stroke_width:.1},s={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_2",route:[{x:-o,y:-i},{x:o+.3,y:-i},{x:o+.3,y:-i/2}],type:"pcb_silkscreen_path",stroke_width:.1},a=Number.parseFloat(t.p),A=Number.parseFloat(t.pl),c=Number.parseFloat(t.pw),l=Number.parseFloat(t.h),g=a+A/2,u=.95+c/2,h=l/2,d=g+.25,m=Math.max(u+.25,h+.09),p={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:0,y:0},width:2*d,height:2*m,layer:"top"};return[...e,r,s,n,p]},Pli=Xi.extend({fn:$(),num_pins:Eo([je(3),je(2)]).default(3),p:$().default("1.27mm"),id:$().default("0.72mm"),od:$().default("0.95mm"),w:$().default("2.5mm"),h:$().default("4.2mm"),string:$().optional()}),wli=t=>{const{p:e,id:n,od:o,w:i,h:r}=t,s=Number.parseFloat(r)/2,a=Number.parseFloat(e);return[ka(1,-a,s-a,n,o),ka(2,0,s-a,n,o),ka(3,a,s-a,n,o)]},Mli=t=>{const{p:e,id:n,od:o,h:i}=t,r=Number.parseFloat(i)/2,s=Number.parseFloat(e),a=Number.parseFloat(n),A=Number.parseFloat(o),c=A*(1.5/1.05);return[px({pn:1,x:-s,y:r-s,holeDiameter:a,rectPadWidth:A,rectPadHeight:c}),IP(2,s,r-s,a,A,c)]},Dli=t=>{const e=t.string?.match(/^to92s_(\d+)/),n=e?Number.parseInt(e[1],10):3,o=Pli.parse({...t,num_pins:n});let i=[];if(o.num_pins===3)i=wli(o);else if(o.num_pins===2)i=Mli(o);else throw new Error("Invalid number of pins for TO-92");const r=Number.parseFloat(o.h)/2,s=Number.parseFloat(o.p),a={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-r,y:r-s},{x:-1.9,y:0},{x:1.9,y:0},{x:r,y:r-s},{x:1.5,y:Number.parseFloat(o.h)/2+.5},{x:-1.5,y:Number.parseFloat(o.h)/2+.5},{x:-r,y:r-s}],stroke_width:.1,pcb_silkscreen_path_id:""},A=tr(0,r+1,.5),c=Number.parseFloat(o.od),l=r-s,g=-s-c/2,u=s+c/2,h=l-c/2,d=l+c/2,m=-r,p=r,_=0,f=r+.5,I=Math.min(g,m)-.27,C=Math.max(u,p)+.13,y=Math.min(h,_)-.42,x=Math.max(d,f)+.08,E={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:(I+C)/2,y:(y+x)/2},width:C-I,height:x-y,layer:"top"};return{circuitJson:[...i,a,A,E],parameters:o}},Nli=Xi.extend({fn:$(),p:ue.optional(),id:ue.optional(),pw:ue.optional(),pl:ue.optional(),w:ue.optional(),h:ue.optional(),sh:We().optional().describe('JST SH (Surface-mount) connector family. SH stands for "Super High-density".'),ph:We().optional().describe('JST PH (Through-hole) connector family. PH stands for "Pin Header".'),zh:We().optional().describe("JST ZH (Through-hole) connector family. 1.5mm pitch wire-to-board."),string:$().optional()}),Rli=()=>({minX:Number.POSITIVE_INFINITY,maxX:Number.NEGATIVE_INFINITY,minY:Number.POSITIVE_INFINITY,maxY:Number.NEGATIVE_INFINITY}),UX=({bounds:t,centerX:e,centerY:n,width:o,height:i})=>{const r=o/2,s=i/2;t.minX=Math.min(t.minX,e-r),t.maxX=Math.max(t.maxX,e+r),t.minY=Math.min(t.minY,n-s),t.maxY=Math.max(t.maxY,n+s)},Tli={ph:{p:ue.parse("2.2mm"),id:ue.parse("0.70mm"),pw:ue.parse("1.20mm"),pl:ue.parse("1.20mm"),w:ue.parse("6mm"),h:ue.parse("5mm")},sh:{p:ue.parse("1mm"),pw:ue.parse("0.6mm"),pl:ue.parse("1.55mm"),w:ue.parse("5.8mm"),h:ue.parse("7.8mm")},zh:{p:ue.parse("1.5mm"),id:ue.parse("0.73mm"),pw:ue.parse("1.03mm"),pl:ue.parse("1.73mm"),w:ue.parse("3mm"),h:ue.parse("3.5mm")}};function kli(t){return t.sh?"sh":t.ph?"ph":t.zh?"zh":"ph"}function Fli({variant:t,numPins:e,p:n,id:o,pw:i,pl:r}){const s=[],a=Rli();let A=0;if(t==="ph"){const c=-((e-1)/2)*n;for(let l=0;l<e;l++){const g=c+l*n;s.push(px({pn:l+1,x:g,y:2,holeDiameter:o,rectPadWidth:i,rectPadHeight:r})),UX({bounds:a,centerX:g,centerY:2,width:i,height:r}),A=Math.max(A,r/2)}}else if(t==="zh"){const c=-((e-1)/2)*n;for(let l=0;l<e;l++){const g=c+l*n;l===0?s.push(px({pn:l+1,x:g,y:0,holeDiameter:o,rectPadWidth:i,rectPadHeight:r,rectBorderRadius:.12499977})):s.push(IP(l+1,g,0,o,i,r)),UX({bounds:a,centerX:g,centerY:0,width:i,height:r}),A=Math.max(A,r/2)}}else{const c=-((e-1)/2)*n;for(let g=0;g<e;g++){const u=c+g*n;s.push(yi(g+1,u,-1.325,i,r)),UX({bounds:a,centerX:u,centerY:-1.325,width:i,height:r}),A=Math.max(A,r/2)}const l=(e-1)/2*n+1.3;s.push(yi(e+1,-l,1.22,1.2,1.8)),s.push(yi(e+2,l,1.22,1.2,1.8)),UX({bounds:a,centerX:-l,centerY:1.22,width:1.2,height:1.8}),UX({bounds:a,centerX:l,centerY:1.22,width:1.2,height:1.8}),A=Math.max(A,.9)}return{pads:s,padBounds:a,maxPadHalfY:A}}function Lli({variant:t,w:e,h:n,numPins:o,p:i}){if(t==="ph")return{type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-3,y:3},{x:3,y:3},{x:3,y:-2},{x:-3,y:-2},{x:-3,y:3}],stroke_width:.1,pcb_silkscreen_path_id:""};if(t==="zh"&&o&&i){const r=(o-1)*i,s=-r/2-1.5,a=r/2+1.5,A=-n/2,c=n/2;return{type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:s,y:A},{x:a,y:A},{x:a,y:c},{x:s,y:c},{x:s,y:A}],stroke_width:.1,pcb_silkscreen_path_id:""}}else return{type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[],stroke_width:.1,pcb_silkscreen_path_id:""}}var Hli=t=>{const e=Nli.parse(t),n=kli(e),o=Tli[n],i=e.p??o.p,r=e.id??o.id,s=e.pw??o.pw,a=e.pl??o.pl,A=e.w??o.w,c=e.h??o.h;let l;const g=t.num_pins;typeof g=="number"&&(l=g);const u=typeof t.string=="string"?t.string:"",h=u.match(/(?:^|_)jst(\d+)(?:_|$)/),d=u.match(/(?:^|_)zh(\d+)(?:_|$)/);if(h&&h[1]){const ee=Number.parseInt(h[1],10);Number.isNaN(ee)||(l=ee)}if(d&&d[1]){const ee=Number.parseInt(d[1],10);Number.isNaN(ee)||(l=ee)}if(typeof l!="number")throw new Error(`JST requires an explicit pin count (e.g. jst6_sh or .jst(6))${e.string?`, from string "${e.string}"`:""}`);const m=Fli({variant:n,numPins:l,p:i,id:r,pw:s,pl:a}),{pads:p,padBounds:_,maxPadHalfY:f}=m,I=Lli({variant:n,w:A,h:c,numPins:l,p:i}),C=tr(0,c/2+1,.5),y=I.route.map(ee=>ee.x),x=I.route.map(ee=>ee.y),E=y.length>0&&x.length>0,B=E?Math.min(_.minX,Math.min(...y)):_.minX,b=E?Math.max(_.maxX,Math.max(...y)):_.maxX,Q=E?Math.min(_.minY,Math.min(...x)):_.minY,w=E?Math.max(_.maxY,Math.max(...x)):_.maxY,D=.5,k=.05,T=f+.085,H=B-D,G=b+D,U=Q-T,Y=w+k,j={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:(H+G)/2,y:(U+Y)/2},width:G-H,height:Y-U,layer:"top"};return{circuitJson:[...p,I,C,j],parameters:{...e,p:i,id:r,pw:s,pl:a,w:A,h:c,num_pins:l,sh:n==="sh",ph:n==="ph",zh:n==="zh"}}},Oli=Xi.extend({fn:$(),num_pins:je(2).default(2),w:$().default("3.30mm"),h:$().default("1.70mm"),pl:$().default("0.80mm"),pw:$().default("1mm"),p:$().default("1.90mm")}),Gli=t=>{const e=Oli.parse(t),n=tr(0,ue.parse(e.h)/2+.5,.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:ue.parse(e.p)/2,y:ue.parse(e.h)/2},{x:-ue.parse(e.w)/2,y:ue.parse(e.h)/2},{x:-ue.parse(e.w)/2,y:-ue.parse(e.h)/2},{x:ue.parse(e.p)/2,y:-ue.parse(e.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""},s={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:0,y:0},width:3.2,height:2,layer:"top"};return{circuitJson:Uli(e).concat(...AC(e),o,n,s),parameters:e}},Yli=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},Uli=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=Yli({pn:n,p:Number.parseFloat(t.p)});e.push(yi(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw),.1))}return e},Kli=t=>{switch(t){case 8:return{w:"3.06mm",h:"3.14mm",p:"0.65mm",pl:"1.6mm",pw:"0.5mm"};case 10:return{w:"3.10mm",h:"3.33mm",p:"0.5mm",pl:"1.45mm",pw:"0.3mm"};default:return{w:"3.06mm",h:"3.14mm",p:"0.65mm",pl:"1.6mm",pw:"0.5mm"}}},Vli=Xi.extend({fn:$(),num_pins:Eo([je(8),je(10)]).default(8),w:$().optional(),h:$().optional(),p:$().optional(),pl:$().optional(),pw:$().optional(),string:$().optional()}),zli=t=>{const e=Vli.parse(t),n=Kli(e.num_pins),o=ue.parse(e.w||n.w),i=ue.parse(e.h||n.h),r=ue.parse(e.p||n.p),s=ue.parse(e.pl||n.pl),a=ue.parse(e.pw||n.pw),A=[],c=e.num_pins/2;for(let B=0;B<e.num_pins;B++){const{x:b,y:Q}=ZZt(e.num_pins,B+1,o,r),w=B<c?B+1:e.num_pins-(B-c);A.push(yi(w,b,Q,s,a))}const l=o,g=i,u={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-l/2,y:g/2},{x:l/2,y:g/2}],stroke_width:.05,pcb_silkscreen_path_id:""},h={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-l/2,y:-g/2},{x:l/2,y:-g/2}],stroke_width:.05,pcb_silkscreen_path_id:""},d=ZZt(e.num_pins,1,l,r),m={x:d.x-.8,y:d.y},p={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"pin_marker_1",route:[{x:m.x-.4,y:m.y},{x:m.x-.7,y:m.y+.3},{x:m.x-.7,y:m.y-.3},{x:m.x-.4,y:m.y}],stroke_width:.05,pcb_silkscreen_path_id:"pin_marker_1"},_=tr(0,g/2+.5,.3),f=(e.num_pins/2-1)*r+a,I=o/2+.25,C=I+1.43,y=f/2+.255,x=i/2+.25,E={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",layer:"top",outline:Dy([{minX:-C,maxX:C,minY:-y,maxY:y},{minX:-I,maxX:I,minY:-x,maxY:x}])};return{circuitJson:[...A,u,h,_,p,E],parameters:e}},ZZt=(t,e,n,o)=>{const i=t/2,r=(e-1)%i,s=e<=i?-1:1,a=(i-1)/2-r;return{x:s*2.11,y:a*o}},Jli=t=>{switch(t){case 10:return{w:"3.10mm",h:"3.32mm",p:"0.5mm",pl:"1.63mm",pw:"0.33mm"};case 12:return{w:"3mm",h:"4mm",p:"0.65mm",pl:"0.88mm",pw:"0.4mm"};case 16:return{w:"3.10mm",h:"4mm",p:"0.5mm",pl:"0.88mm",pw:"0.3mm"};default:return{w:"3.10mm",h:"3.32mm",p:"0.65mm",pl:"1.63mm",pw:"0.4mm"}}},Wli=Xi.extend({fn:$(),num_pins:Eo([je(8),je(10),je(12),je(16)]).default(8),w:$().optional(),h:$().optional(),p:$().optional(),pl:$().optional(),pw:$().optional(),string:$().optional()}),een=(t,e,n,o,i)=>{const r=t/2,s=(e-1)%r,a=e<=r?-1:1,A=(r-1)/2-s,c=ue.parse("0.2mm");return{x:a*(n/2+i/2-c),y:A*o}},jli=t=>{const e=Wli.parse(t),n=Jli(e.num_pins),o=ue.parse(e.w||n.w),i=ue.parse(e.h||n.h),r=ue.parse(e.p||n.p),s=ue.parse(e.pl||n.pl),a=ue.parse(e.pw||n.pw),A=[];for(let E=0;E<e.num_pins;E++){const{x:B,y:b}=een(e.num_pins,E+1,o,r,s);A.push(yi(E+1,B,b,s,a))}const c=o,l=i,g={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-c/2,y:l/2},{x:c/2,y:l/2}],stroke_width:.05,pcb_silkscreen_path_id:""},u={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-c/2,y:-l/2},{x:c/2,y:-l/2}],stroke_width:.05,pcb_silkscreen_path_id:""},h=een(e.num_pins,1,c,r,s),d={x:h.x-.8,y:h.y},m={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"pin_marker_1",route:[{x:d.x-.4,y:d.y},{x:d.x-.7,y:d.y+.3},{x:d.x-.7,y:d.y-.3},{x:d.x-.4,y:d.y}],stroke_width:.05,pcb_silkscreen_path_id:"pin_marker_1"},p=tr(0,l/2+.5,.3),_=(e.num_pins/2-1)*r+a,f=o/2+.25,I=f+1.43,C=_/2+.255,y=i/2+.25,x={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",layer:"top",outline:Dy([{minX:-I,maxX:I,minY:-C,maxY:C},{minX:-f,maxX:f,minY:-y,maxY:y}])};return{circuitJson:[...A,g,u,p,m,x],parameters:e}},Xli=Xi.extend({fn:$(),num_pins:je(2).default(2),w:$().default("3.8mm"),h:$().default("1.65mm"),pl:$().default("1.2mm"),pw:$().default("1.2mm"),pad_spacing:$().default("2.6mm")}),qli=t=>{const e=Xli.parse(t),n=tr(0,ue.parse(e.h),.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:ue.parse(e.pad_spacing)/2,y:ue.parse(e.h)/2},{x:-ue.parse(e.w)/2-.2,y:ue.parse(e.h)/2},{x:-ue.parse(e.w)/2-.2,y:-ue.parse(e.h)/2},{x:ue.parse(e.pad_spacing)/2,y:-ue.parse(e.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""},s={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:0,y:0},width:4.3,height:2.15,layer:"top"};return{circuitJson:Zli(e).concat(...AC(e),o,n,s),parameters:e}},$li=t=>{const{pn:e,pad_spacing:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},Zli=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=$li({pn:n,pad_spacing:Number.parseFloat(t.pad_spacing)});e.push(yi(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return e},e0i=Xi.extend({fn:$(),num_pins:je(2).default(2),w:$().default("3.20mm"),h:$().default("1.65mm"),pl:$().default("0.8mm"),pw:$().default("0.9mm"),pad_spacing:$().default("2.1mm")}),t0i=t=>{const e=e0i.parse(t),n=tr(0,ue.parse(e.h),.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:ue.parse(e.pad_spacing)/2,y:ue.parse(e.h)/2},{x:-ue.parse(e.w)/2-.2,y:ue.parse(e.h)/2},{x:-ue.parse(e.w)/2-.2,y:-ue.parse(e.h)/2},{x:ue.parse(e.pad_spacing)/2,y:-ue.parse(e.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""},s={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:0,y:0},width:3.7,height:2.15,layer:"top"};return{circuitJson:o0i(e).concat(...AC(e),o,n,s),parameters:e}},n0i=t=>{const{pn:e,pad_spacing:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},o0i=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=n0i({pn:n,pad_spacing:Number.parseFloat(t.pad_spacing)});e.push(yi(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return e},i0i=Xi.extend({fn:$(),num_pins:Eo([je(6),je(8)]).default(8),w:$().default("3mm"),h:$().default("3mm"),p:$().default("0.5mm"),pl:$().default("0.52mm"),pw:$().default("0.35mm"),epw:$().default("1.40mm"),eph:$().default("1.60mm"),string:$().optional(),ep:We().default(!1)}),r0i=t=>{t.string&&t.string.includes("_ep")&&(t.ep=!0);const e=t.string?.match(/^son_(\d+)/),n=e?Number.parseInt(e[1],10):t.num_pins||8,o=i0i.parse({...t,num_pins:n}),i=ue.parse(o.w),r=ue.parse(o.h),s=ue.parse(o.p),a=ue.parse(o.pl),A=ue.parse(o.pw),c=ue.parse(o.epw),l=ue.parse(o.eph),g=[];for(let D=0;D<o.num_pins;D++){const{x:k,y:T}=hYe(o.num_pins,D+1,i,s);g.push(yi(D+1,k,T,a,A))}o.ep&&g.push(yi(o.num_pins+1,0,0,c,l));const u=i,h=r,d={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-u/2,y:h/2},{x:u/2,y:h/2}],stroke_width:.05,pcb_silkscreen_path_id:""},m={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-u/2,y:-h/2},{x:u/2,y:-h/2}],stroke_width:.05,pcb_silkscreen_path_id:""},p=hYe(o.num_pins,1,u,s),_={x:p.x-.4,y:p.y},f={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"pin_marker_1",route:[{x:_.x-.4,y:_.y},{x:_.x-.7,y:_.y+.3},{x:_.x-.7,y:_.y-.3},{x:_.x-.4,y:_.y}],stroke_width:.05,pcb_silkscreen_path_id:"pin_marker_1"},I=tr(0,h/2+.5,.3),C=Math.abs(hYe(o.num_pins,1,i,s).x),y=(o.num_pins/2-1)*s+A,x=C*2+a,E=i/2+.25,B=x/2+.25,b=y/2+.25,Q=r/2+.25,w={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",layer:"top",outline:Dy([{minX:-B,maxX:B,minY:-b,maxY:b},{minX:-E,maxX:E,minY:-Q,maxY:Q}])};return{circuitJson:[...g,d,m,I,f,w],parameters:o}},hYe=(t,e,n,o)=>{const i=t/2,r=(e-1)%i,s=e<=i?-1:1,a=(i-1)/2-r;return{x:s*ue.parse("1.4mm"),y:a*o}},s0i=Xi.extend({fn:$(),num_pins:ft().optional().default(8),p:ct.describe("pitch (distance between center of each pin)"),w:ue.describe("width between vertical rows of pins"),grid:wue.describe("width and height of the border of the footprint"),ep:wue.default("0x0mm").describe("width and height of the central exposed thermal pad"),epx:ue.default("0mm").describe("x offset of the center of the central exposed thermal pad"),pinw:ue.describe("width of the pin pads"),pinh:ue.describe("height of the pin pads")}),a0i=t=>{const e=s0i.parse(t),{num_pins:n,p:o,w:i,grid:r,ep:s,epx:a,pinw:A,pinh:c}=e;if(n%2!==0)throw new Error("invalid number of pins");const l=[];for(let E=0;E<n;E++){const{pinX:B,pinY:b}=A0i({pinCount:n,pinIndex:E,width:i,pitch:o});l.push(yi(E+1,B,b,A,c))}s.x>0&&s.y>0&&l.push(yi(e.num_pins+1,a,0,s.x,s.y));const g=c0i(r),u=tr(0,r.y/2+o,r.y/6),h=(n/2-1)*o+c,d=i+A,m=r.x/2+.25,p=d/2+.25,_=h/2+.25,f=h/2+.45+Math.max(0,.8-o),I=Math.min(r.y/2+.25,f),C=Math.max(0,.37-Math.max(0,p-m-.38)*1.4),y=Math.max(_,I-C),x={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",layer:"top",outline:Dy([{minX:-p,maxX:p,minY:-y,maxY:y},{minX:-m,maxX:m,minY:-I,maxY:I}])};return{circuitJson:[...l,...g,u,x],parameters:e}},A0i=t=>{let e=0,n=0;const o=(t.pinCount/2-1)*t.pitch/2,i=t.pinCount/2;return t.pinIndex+1<=i?(e=t.pitch*t.pinIndex-o,n=0-t.width/2):(e=t.pitch*(t.pinCount-t.pinIndex-1)-o,n=t.width/2),{pinX:n,pinY:e}},c0i=t=>{const n=t.y/30;return[{layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"",type:"pcb_silkscreen_path",route:[{x:-t.x/2-.1,y:t.y/2+.1-n},{x:-t.x/2-.1,y:t.y/2+.1},{x:t.x/2+.1,y:t.y/2+.1},{x:t.x/2+.1,y:t.y/2+.1-n}],stroke_width:t.y/30},{layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"",type:"pcb_silkscreen_path",route:[{x:-t.x/2-.1,y:-t.y/2-.1+n},{x:-t.x/2-.1,y:-t.y/2-.1},{x:t.x/2+.1,y:-t.y/2-.1},{x:t.x/2+.1,y:-t.y/2-.1+n}],stroke_width:t.y/30}]},l0i=t=>{const{num_pins:e,bridged:n,p:o=2.54,pw:i=1.5,ph:r=1.5}=t,s=ue.parse(o),a=ue.parse(i),A=ue.parse(r),c=Math.min(A/4,.5),l=[];for(let Q=0;Q<e;Q++)l.push(yi(Q+1,Q*s,0,a,A));let g=[];if(n){const Q=n.split("").map(Number);if(Q.length>1)for(let w=0;w<Q.length-1;w++){const D=Q[w],k=Q[w+1];if(typeof D=="number"&&typeof k=="number"&&!isNaN(D)&&!isNaN(k)){const T=(D-1)*s,H=(k-1)*s,G=Math.sign(H-T),U=T+G*(a/2),Y=H-G*(a/2);g.push({type:"pcb_trace",pcb_trace_id:"",route:[{start_pcb_port_id:`{PIN${D}}`,x:U,y:0,width:c,layer:"top",route_type:"wire"},{end_pcb_port_id:`{PIN${k}}`,x:Y,y:0,width:c,layer:"top",route_type:"wire"}]})}}}const u=(e-1)*s+a+.7,h=A+1,d=(e-1)*s/2,m=0,p={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"outline",route:[{x:d-u/2,y:m-h/2},{x:d+u/2,y:m-h/2},{x:d+u/2,y:m+h/2},{x:d-u/2,y:m+h/2},{x:d-u/2,y:m-h/2}],stroke_width:.15},f=m+h/2+.6,I=tr(d,f,.4),C=(e-1)*s,y=C/2+a/2,x=A/2,E=y+.5,B=x+.5,b={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:C/2,y:0},width:2*E,height:2*B,layer:"top"};return{circuitJson:[...l,...g,p,I,b],parameters:t}},ten={fn:je("sot457"),num_pins:je(6).default(6),pillh:$().default("0.45mm"),pillw:$().default("1.45mm"),pl:$(),pw:$(),p:$(),wave:We().optional(),reflow:We().optional()},g0i=Xi.extend({...ten,h:$().default("2.5mm"),w:$().default("2.7mm"),pl:$().default("0.8mm"),pw:$().default("0.55mm"),p:$().default("0.95mm")}),u0i=Xi.extend({...ten,h:$().default("3mm"),w:$().default("4mm"),pillr:$().default("0.225mm"),pl:$().default("1.45mm"),pw:$().default("1.5mm"),p:$().default("1.475mm")}).transform(t=>({...t,wave:t.wave??(t.reflow===void 0?!0:!t.reflow),reflow:t.reflow??(t.wave===void 0?!1:!t.wave)})),SS=t=>Number.parseFloat(t.replace("mm","")),nen=({pitch:t,width:e,pinNumber:n})=>{const r={1:{x:-e/2-.1,y:t},2:{x:-e/2-.1,y:0},3:{x:-e/2-.1,y:-t},4:{x:e/2+.1,y:-t},5:{x:e/2+.1,y:0},6:{x:e/2+.1,y:t}}[n];if(!r)throw new Error(`Invalid pin number: ${n}`);return r},oen=t=>{const e=[],n=SS(t.p),o=SS(t.pl),i=SS(t.pw),r=SS(t.w),s=SS(t.h);if(t.wave){const m={1:({padWidth:p,padHeight:_})=>yi(1,-n,n,_,p),2:({padWidth:p,padHeight:_})=>yi(2,-n,-n,_,p),3:({padWidth:p,padHeight:_})=>Mue(3,-n,0,SS(t.pillw),SS(t.pillh)),4:({padWidth:p,padHeight:_})=>Mue(4,n,0,SS(t.pillw),SS(t.pillh)),5:({padWidth:p,padHeight:_})=>yi(5,n,n,_,p),6:({padWidth:p,padHeight:_})=>yi(6,n,-n,_,p)};for(let p=1;p<=t.num_pins;p++){const _=m[p];_&&e.push(_({padWidth:o,padHeight:i}))}}else for(let m=1;m<=t.num_pins;m++){const{x:p,y:_}=nen({pitch:n,width:r,pinNumber:m});e.push(yi(m,p,_,o,i))}const a={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-r/3,y:s/2+n/1.3},{x:r/3,y:s/2+n/1.3}],stroke_width:.05},A={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_2",route:[{x:-r/3,y:-s/2-n/1.3},{x:r/3,y:-s/2-n/1.3}],stroke_width:.05},c=tr(0,s+.5,.3),l=nen({pitch:n,width:r,pinNumber:1}),g=t.wave?1:.5,u=t.wave?.7:.3;l.x-=t.wave?i:i*1.7;const h={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"pin1_indicator",route:[{x:l.x+g/2,y:l.y},{x:l.x-g/2,y:l.y+u/2},{x:l.x-g/2,y:l.y-u/2},{x:l.x+g/2,y:l.y}],stroke_width:.05};let d;if(t.wave){const m=2*n,p=2*n,_=m/2+i/2,f=p/2+o/2,I=_+.25,C=f+.25;d={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:0,y:0},width:2*I,height:2*C,layer:"top"}}else{const p=r/2+.1+o/2,_=n+i/2,f=r/2,I=s/2,C=p+.25,y=f+.08,x=_+.25,E=Math.max(I+.45,x);d={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",outline:Dy([{minX:-C,maxX:C,minY:-x,maxY:x},{minX:-y,maxX:y,minY:-E,maxY:E}]),layer:"top"}}return[c,a,A,h,...e,d]},d0i=t=>{if(t.wave){const n=u0i.parse({...t,fn:"sot457"});return{circuitJson:oen(n),parameters:n}}const e=g0i.parse(t);return{circuitJson:oen(e),parameters:e}},h0i=[{x:-.8,y:.75},{x:.8,y:.75},{x:.8,y:-.75},{x:-.8,y:-.75}],m0i=Xi.extend({fn:$(),num_pins:je(6).default(6),w:$().default("1.1mm"),h:$().default("1.45mm"),p:$().default("0.35mm"),pl:$().default("0.2mm"),pw:$().default("0.2mm"),string:$().optional()}),p0i=t=>{const e=m0i.parse({...t,fn:"sot963"}),n=ue.parse(e.w),o=ue.parse(e.h),i=ue.parse(e.p),r=ue.parse(e.pl),s=ue.parse(e.pw),a=[];for(let d=0;d<6;d++){const{x:m,y:p}=ien(d+1,n,i,r);a.push(yi(d+1,m,p,r,s))}const A={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-n/2,y:o/2},{x:n/2,y:o/2}],stroke_width:.05,pcb_silkscreen_path_id:""},c={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-n/2,y:-o/2},{x:n/2,y:-o/2}],stroke_width:.05,pcb_silkscreen_path_id:""},l=ien(1,n,i,r),g={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"pin_marker_1",route:[{x:l.x-r/2-.3,y:l.y},{x:l.x-r/2-.45,y:l.y+.15},{x:l.x-r/2-.45,y:l.y-.15},{x:l.x-r/2-.3,y:l.y}],stroke_width:.05,pcb_silkscreen_path_id:"pin_marker_1"},u=tr(0,o/2+.4,.25),h={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",outline:h0i,layer:"top"};return{circuitJson:[...a,A,c,u,g,h],parameters:e}},ien=(t,e,n,o)=>{const i=e/2-o/2;return t<=3?{x:-i,y:n-(t-1)*n}:{x:i,y:-n+(t-4)*n}},_0i=Xi.extend({fn:$(),num_pins:Eo([je(3),je(2)]).default(3),p:$().default("5mm"),id:$().default("1.25mm"),od:$().default("2.35mm"),ca:$().default("14mm").describe("Caliper axis (width or diameter of the potentiometer body or adjustment knob)"),w:$().default("5.35mm"),h:$().default("4mm"),string:$().optional()}),f0i=t=>{const{p:e,id:n,od:o,h:i}=t,r=Number.parseFloat(i),s=Number.parseFloat(e);return[ka(1,0,s,n,o),ka(2,r,0,n,o),ka(3,0,-s,n,o)]},I0i=t=>{const e=t.string?.match(/^potentiometer_(\d+)/),n=e?Number.parseInt(e[1],10):3,o=_0i.parse({...t,num_pins:n});let i=[];o.num_pins===3&&(i=f0i(o));const r=Number.parseFloat(o.ca)/2+.15,s=Number.parseFloat(o.w),a=Number.parseFloat(o.od)/2+.35,A={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:0,y:r-1.75},{x:0,y:r},{x:s,y:r},{x:s,y:a}],stroke_width:.1,pcb_silkscreen_path_id:""},c={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:s,y:-a},{x:s,y:-r},{x:0,y:-r},{x:0,y:-r+1.75}],stroke_width:.1,pcb_silkscreen_path_id:""},l=Number.parseFloat(o.w)/2,g=tr(l,r+1,.5),u=Number.parseFloat(o.od)/2,h=Number.parseFloat(o.h),d=Number.parseFloat(o.ca)/2,m=-(u+.25),p=h+u+.25,_=d+.25,f={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:(m+p)/2,y:0},width:p-m,height:2*_,layer:"top"};return{circuitJson:[...i,A,c,g,f],parameters:o}},C0i=Xi.extend({fn:$(),p:ue.optional().default("7.5mm"),id:ue.optional().default("1mm"),od:ue.optional().default("2mm"),d:ue.optional().default("10.5mm")}),y0i=(t,e,n,o,i)=>{const r=[],s=[];for(let a=0;a<=50;a++){const A=a/50*Math.PI,c=t+Math.cos(A)*n,l=e+Math.sin(A)*n;c<t-o&&l>=e-i/2&&l<=e+i/2||r.push({x:c,y:l})}for(let a=0;a<=50;a++){const A=Math.PI+a/50*Math.PI,c=t+Math.cos(A)*n,l=e+Math.sin(A)*n;c<t-o&&l>=e-i/2&&l<=e+i/2||s.push({x:c,y:l})}return{topArc:r,bottomArc:s}},x0i=t=>{const e=C0i.parse(t),{p:n,id:o,od:i,d:r}=e,s=[px({pn:1,x:-n/2,y:0,holeDiameter:o,rectPadWidth:i,rectPadHeight:i}),ka(2,n/2,0,o,i)],{topArc:a,bottomArc:A}=y0i(0,0,r/2+.1,i/2,i),c={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:a,stroke_width:.1,pcb_silkscreen_path_id:""},l={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:A,stroke_width:.1,pcb_silkscreen_path_id:""},g={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:0,y:r/2+.1},{x:0,y:-(r/2+.1)}],stroke_width:.1,pcb_silkscreen_path_id:""},u=-(r/2+.5),h=i/2+1.5,d=.5,m={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:u-d,y:h},{x:u+d,y:h}],stroke_width:.1,pcb_silkscreen_path_id:""},p={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:u,y:h-d},{x:u,y:h+d}],stroke_width:.1,pcb_silkscreen_path_id:""},_=tr(0,r/2+1,.5),f=r/2,I=n/2+i/2,y=Math.max(f,I)+.25,x={type:"pcb_courtyard_circle",pcb_courtyard_circle_id:"",pcb_component_id:"",center:{x:0,y:0},radius:y,layer:"top"};return{circuitJson:[...s,c,l,g,m,p,_,x],parameters:e}},E0i=Xi.extend({fn:$(),num_pins:je(2).default(2),w:$().default("6.5mm"),h:$().default("3mm"),pl:$().default("1.75mm"),pw:$().default("2.40mm"),p:$().default("4.75mm")}),B0i=t=>{const e=E0i.parse(t),n=tr(0,ue.parse(e.h)-.5,.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:ue.parse(e.p)/2,y:ue.parse(e.h)/2},{x:-ue.parse(e.w)/2-.3,y:ue.parse(e.h)/2},{x:-ue.parse(e.w)/2-.3,y:-ue.parse(e.h)/2},{x:ue.parse(e.p)/2,y:-ue.parse(e.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""},s={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:0,y:0},width:7,height:3.5,layer:"top"};return{circuitJson:b0i(e).concat(o,n,s),parameters:e}},S0i=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},b0i=t=>{const e=[],n=ue.parse(t.p),o=ue.parse(t.pl),i=ue.parse(t.pw),r=.125;for(let s=1;s<=t.num_pins;s++){const{x:a,y:A}=S0i({pn:s,p:n});e.push(yi(s,a,A,o,i,r))}return e},Q0i=[{x:-1.45,y:.98},{x:-.73,y:.98},{x:-.73,y:1.1},{x:.73,y:1.1},{x:.73,y:.33},{x:1.45,y:.33},{x:1.45,y:-.33},{x:.73,y:-.33},{x:.73,y:-1.1},{x:-.73,y:-1.1},{x:-.73,y:-.98},{x:-1.45,y:-.98},{x:-1.45,y:-.32},{x:-.73,y:-.32},{x:-.73,y:.32},{x:-1.45,y:.32}],v0i=Xi.extend({fn:$(),num_pins:ft().default(3),w:$().default("2.45mm"),h:$().default("2.40mm"),pl:$().default("0.92mm"),pw:$().default("0.45mm"),p:$().default("0.891mm"),string:$().optional()}),P0i=t=>{const e=t.string?.match(/^sot323_(\d+)/),n=e?Number.parseInt(e[1],3):3,o=v0i.parse({...t,num_pins:n});if(o.num_pins===3)return{circuitJson:M0i(o),parameters:o};throw new Error("Invalid number of pins")},w0i=t=>{const{pn:e,p:n}=t;return e===1?{x:-n,y:.65}:e===2?{x:-n,y:-.65}:{x:n,y:0}},M0i=t=>{const e=[];for(let A=0;A<t.num_pins;A++){const{x:c,y:l}=w0i({num_pins:t.num_pins,pn:A+1,w:Number.parseFloat(t.w),h:Number.parseFloat(t.h),pl:Number.parseFloat(t.pl),p:Number.parseFloat(t.p)});e.push(yi(A+1,c,l,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}const n=tr(0,Number.parseInt(t.h)/2+1,.3),o=Number.parseFloat(t.w)/2-Number.parseFloat(t.pl),i=Number.parseFloat(t.h)/2,r={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-o,y:i+.3},{x:o,y:i+.3},{x:o,y:i/2}],type:"pcb_silkscreen_path",stroke_width:.1},s={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_2",route:[{x:-o,y:-i-.3},{x:o,y:-i-.3},{x:o,y:-i/2}],type:"pcb_silkscreen_path",stroke_width:.1},a={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",outline:Q0i,layer:"top"};return[...e,r,s,n,a]},D0i=Xi.extend({fn:$(),circle:We().optional(),rect:We().optional(),square:We().optional(),pill:We().optional(),d:ue.optional(),pd:ue.optional(),diameter:ue.optional(),r:ue.optional(),pr:ue.optional(),radius:ue.optional(),w:ue.optional(),pw:ue.optional(),width:ue.optional(),h:ue.optional(),ph:ue.optional(),height:ue.optional(),s:ue.optional(),size:ue.optional(),string:$().optional()}).transform(t=>{let e="rect";t.circle&&(e="circle"),t.square&&(e="square"),t.rect&&(e="rect"),t.pill&&(e="pill");let n,o,i;return e==="circle"?t.r!==void 0?n=za(t.r):t.pr!==void 0?n=za(t.pr):t.radius!==void 0?n=za(t.radius):t.d!==void 0?n=za(t.d)/2:t.pd!==void 0?n=za(t.pd)/2:t.diameter!==void 0?n=za(t.diameter)/2:n=za("1mm")/2:(t.w!==void 0?o=za(t.w):t.pw!==void 0?o=za(t.pw):t.width!==void 0?o=za(t.width):t.s!==void 0?o=za(t.s):t.size!==void 0?o=za(t.size):o=za("1mm"),t.h!==void 0?i=za(t.h):t.ph!==void 0?i=za(t.ph):t.height!==void 0?i=za(t.height):e==="square"||e==="rect"?i=o:i=za("1mm")),{fn:t.fn,shape:e,radius:n,width:o,height:i}}),N0i=t=>{const e=D0i.parse(t),{shape:n,radius:o,width:i,height:r}=e;let s,a;return n==="circle"?(s=kZt(1,{x:0,y:0,radius:o}),a=o+.5):n==="pill"?(s=Mue(1,0,0,i,r),a=Math.max(i,r)/2+.5):(s=yi(1,0,0,i,r),a=r/2+.5),{circuitJson:[s,tr(0,a,.2)],parameters:e}},R0i=Xi.extend({fn:$(),d:ue.optional(),hd:ue.optional(),r:ue.optional(),hr:ue.optional(),pd:ue.optional(),pr:ue.optional(),squarepad:We().optional().default(!1)}).transform(t=>{let e;t.d!==void 0?e=za(t.d):t.hd!==void 0?e=za(t.hd):t.r!==void 0?e=za(t.r)*2:t.hr!==void 0?e=za(t.hr)*2:e=za("1mm");let n;return t.pd!==void 0?n=za(t.pd):t.pr!==void 0?n=za(t.pr)*2:n=e*(1.5/1),{fn:t.fn,d:e,pd:n,squarepad:t.squarepad??!1}}),T0i=t=>{const e=R0i.parse(t),{d:n,pd:o,squarepad:i}=e;return{circuitJson:[i?px({pn:1,x:0,y:0,holeDiameter:n,rectPadWidth:o,rectPadHeight:o}):ka(1,0,0,n,o),tr(0,o/2+.5,.2)],parameters:e}},k0i=Xi.extend({fn:$(),num_pins:je(6).default(6),h:$().default("1.3mm"),pl:$().default("1.325mm"),pw:$().default("0.6mm"),p:$().default("0.95mm")}),F0i=t=>{const e=k0i.parse(t);return{circuitJson:L0i(e),parameters:e}},ren=t=>{const{p:e,h:n,pn:o}=t;if(o===1)return{x:-n/2-.4875,y:e};if(o===2)return{x:-n/2-.4875,y:0};if(o===3)return{x:-n/2-.4875,y:-e};if(o===4)return{x:n/2+.4875,y:-e};if(o===5)return{x:n/2+.4875,y:0};if(o===6)return{x:n/2+.4875,y:e};throw new Error("Invalid pin number")},L0i=t=>{const e=[];for(let E=1;E<=t.num_pins;E++){const{x:B,y:b}=ren({h:Number.parseFloat(t.h),p:Number.parseFloat(t.p),pn:E});e.push(yi(E,B,b,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}const n=t.num_pins/2*Number.parseFloat(t.p),o=Number.parseFloat(t.h),i={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-n/3,y:o/2+Number.parseFloat(t.p)/1.3},{x:n/3,y:o/2+Number.parseFloat(t.p)/1.3}],type:"pcb_silkscreen_path",stroke_width:.05},r={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_2",route:[{x:-n/3,y:-o/2-Number.parseFloat(t.p)/1.3},{x:n/3,y:-o/2-Number.parseFloat(t.p)/1.3}],type:"pcb_silkscreen_path",stroke_width:.05},s=tr(0,o+.3,.3),a=ren({h:Number.parseFloat(t.h),p:Number.parseFloat(t.p),pn:1});a.x=a.x-Number.parseFloat(t.pw)*1.5;const A=.7,c=.3,l={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"pin1_indicator",route:[{x:a.x+A/2-.2,y:a.y},{x:a.x-A/2,y:a.y+c/2},{x:a.x-A/2,y:a.y-c/2},{x:a.x+A/2-.2,y:a.y}],stroke_width:.05},g=Number.parseFloat(t.h),u=Number.parseFloat(t.p),h=Number.parseFloat(t.pl),d=Number.parseFloat(t.pw),m=g/2+.4875,p=u*2+d,_=m+h/2,f=g/2+.4,I=_+.25,C=p/2+.25,y=C+.2,x={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",layer:"top",outline:Dy([{minX:-I,maxX:I,minY:-C,maxY:C},{minX:-f,maxX:f,minY:-y,maxY:y}])};return[...e,s,i,r,l,x]},H0i=[{x:-1.703,y:.98},{x:-.983,y:.98},{x:-.983,y:1.1},{x:.477,y:1.1},{x:.477,y:.98},{x:1.197,y:.98},{x:1.197,y:-.98},{x:.477,y:-.98},{x:.477,y:-1.1},{x:-.983,y:-1.1},{x:-.983,y:-.98},{x:-1.703,y:-.98}],O0i=Xi.extend({fn:$(),num_pins:ft().default(4),w:$().default("3.2mm"),h:$().default("2.6mm"),pl:$().default("1.05mm"),pw:$().default("0.45mm"),p:$().default("0.55mm"),string:$().optional()}),G0i=t=>{const e=t.string?.match(/^sot343_(\d+)/),n=e?Number.parseInt(e[1],4):4,o=O0i.parse({...t,num_pins:n});if(o.num_pins===4)return{circuitJson:U0i(o),parameters:o};throw new Error("Invalid number of pins")},Y0i=t=>{const{pn:e,p:n}=t;return e===1?{x:-n*1.92,y:-.65}:e===2?{x:-n*1.92,y:.65}:e===3?{x:n,y:.65}:e===4?{x:n,y:-.65}:{x:0,y:0}},U0i=t=>{const e=[],n=Number.parseFloat(t.w),o=Number.parseFloat(t.h),i=Number.parseFloat(t.pl),r=Number.parseFloat(t.pw),s=Number.parseFloat(t.p);let a=1/0,A=-1/0,c=1/0,l=-1/0;for(let C=0;C<t.num_pins;C++){const{x:y,y:x}=Y0i({num_pins:t.num_pins,pn:C+1,p:s});e.push(yi(C+1,y,x,i,r)),y<a&&(a=y),y>A&&(A=y),x<c&&(c=x),x>l&&(l=x)}const g=(a+A)/2,u=l-c,h=o*.3,d=u/2+h;let m=n*.8;o<=2.6&&(m/=2);const p=tr(g,d+.5,.3),_={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_top",route:[{x:g-m/2,y:d},{x:g+m/2,y:d}],type:"pcb_silkscreen_path",stroke_width:.1},f={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_bottom",route:[{x:g-m/2,y:-d},{x:g+m/2,y:-d}],type:"pcb_silkscreen_path",stroke_width:.1},I={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",outline:H0i,layer:"top"};return[...e,_,f,p,I]},K0i=Xi.extend({fn:$()}),V0i=t=>{const e=K0i.parse(t),n=[],o=.5-.15,i=1.5,s=.5/2,a=75,A=-37/2;for(let E=0;E<a;E++){const B=E+1;if(B>=24&&B<=31)continue;const b=A-E*s,Q=B%2===0,w=i+(Q?.25:0),k=.5-w/2,T=yi(B,k,b,w,o);T.layer=Q?"bottom":"top",n.push(T)}const c=46*.0254,l=137*.0254,g=261*.0254,u={type:"pcb_cutout",pcb_cutout_id:"",shape:"rect",center:{x:-l/2+i/2,y:A-g},width:l,height:c},h={x:-.5,y:A},d={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"pin_marker_1",route:[{x:h.x-.4,y:h.y},{x:h.x-.7,y:h.y+.3},{x:h.x-.7,y:h.y-.3},{x:h.x-.4,y:h.y}],stroke_width:.05,pcb_silkscreen_path_id:"pin_marker_1"};let m=1/0,p=-1/0,_=1/0,f=-1/0;const I=(E,B,b=0,Q=0)=>{m=Math.min(m,E-b/2),p=Math.max(p,E+b/2),_=Math.min(_,B-Q/2),f=Math.max(f,B+Q/2)};for(const E of n){const B=E;I(B.x,B.y,B.width,B.height)}I(u.center.x,u.center.y,u.width,u.height);for(const E of d.route)I(E.x,E.y);const C=(m+p)/2,y=(_+f)/2,x=E=>{typeof E.x=="number"&&(E.x-=C),typeof E.y=="number"&&(E.y-=y),E.center&&(E.center.x-=C,E.center.y-=y),Array.isArray(E.route)&&(E.route=E.route.map(B=>({x:B.x-C,y:B.y-y})))};for(const E of n)x(E);return x(u),x(d),{circuitJson:[...n,u,d],parameters:e}},z0i=Xi.extend({fn:$(),numPins:ft().optional().default(0),rows:Eo([$(),ft()]).transform(t=>Number(t)).optional().default(1).describe("number of rows"),p:ue.default("2.54mm").describe("pitch"),id:ue.default("1.0mm").describe("inner diameter"),od:ue.default("1.5mm").describe("outer diameter"),male:We().optional().describe("the module uses male headers"),nopin:We().optional().default(!1).describe("omit pins rendering"),female:We().optional().describe("the module uses female headers"),smd:We().optional().describe("surface mount device"),pinlabeltextalignleft:We().optional().default(!1),pinlabeltextaligncenter:We().optional().default(!1),pinlabeltextalignright:We().optional().default(!1),pinlabelverticallyinverted:We().optional().default(!1),pinlabelorthogonal:We().optional().default(!1),nopinlabels:We().optional().default(!1).describe("omit silkscreen pin labels"),doublesidedpinlabel:We().optional().default(!1).describe("add silkscreen pins in top and bottom layers"),bottomsidepinlabel:We().optional().default(!1).describe("place the silkscreen reference text on the bottom layer instead of top"),pinRowSide:zn(["left","right","top","bottom"]).optional().default("left"),pinrowleft:We().optional().default(!1),pinrowright:We().optional().default(!1),pinrowtop:We().optional().default(!1),pinrowbottom:We().optional().default(!1),pinrowleftpins:Eo([$(),ft()]).transform(t=>Number(t)).optional(),pinrowrightpins:Eo([$(),ft()]).transform(t=>Number(t)).optional(),pinrowtoppins:Eo([$(),ft()]).transform(t=>Number(t)).optional(),pinrowbottompins:Eo([$(),ft()]).transform(t=>Number(t)).optional(),width:ue.optional(),height:ue.optional(),pinRowHoleEdgeToEdgeDist:ue.default("2mm"),holes:Eo([$(),dn($())]).optional().transform(t=>!t||Array.isArray(t)?t:t.startsWith("(")&&t.endsWith(")")?t.slice(1,-1).split(",").map(e=>e.trim()):[t]),holeXDist:ue.optional(),holeYDist:ue.optional(),holeInset:ue.default("1mm"),pinrow:Eo([$(),ft()]).optional(),usbposition:zn(["left","right","top","bottom"]).optional().default("left"),usbleft:We().optional().default(!1),usbtop:We().optional().default(!1),usbright:We().optional().default(!1),usbbottom:We().optional().default(!1),usbtype:zn(["micro","c"]).optional(),usbmicro:We().optional().default(!1),usbc:We().optional().default(!1),screen:We().optional().default(!1).describe("add silkscreen outline for screen/display area"),screenwidth:ue.optional(),screenheight:ue.optional(),screencenteroffsetx:ue.optional(),screencenteroffsety:ue.optional()}).transform(t=>{const e=VZt(t);let n=t.pinRowSide;t.pinrowleft&&(n="left"),t.pinrowright&&(n="right"),t.pinrowtop&&(n="top"),t.pinrowbottom&&(n="bottom");let o=t.usbposition;t.usbleft&&(o="left"),t.usbtop&&(o="top"),t.usbright&&(o="right"),t.usbbottom&&(o="bottom");let i=t.usbtype;t.usbmicro&&(i="micro"),t.usbc&&(i="c"),t.pinrow!==void 0&&(t.numPins=Number(t.pinrow));const r={left:t.pinrowleftpins,right:t.pinrowrightpins,top:t.pinrowtoppins,bottom:t.pinrowbottompins},s=Object.values(r).some(C=>C!==void 0&&C>0),a=(r.left??0)>0&&(r.right??0)>0,A=(r.top??0)>0&&(r.bottom??0)>0;s&&((r.left??0)>0?n="left":(r.right??0)>0?n="right":(r.top??0)>0?n="top":(r.bottom??0)>0&&(n="bottom"),t.numPins=(r.left??0)+(r.right??0)+(r.top??0)+(r.bottom??0));const c=Math.ceil(t.numPins/t.rows),l=Math.max(r.left??0,r.right??0),g=Math.max(r.top??0,r.bottom??0);let u,h;if(s){const C=a?t.p:0,y=A?t.p:0;u=(g>0?(g-1)*t.p:0)+2*t.pinRowHoleEdgeToEdgeDist+C,h=(l>0?(l-1)*t.p:0)+2*t.pinRowHoleEdgeToEdgeDist+y}else n==="left"||n==="right"?(u=(t.rows-1)*t.p+2*t.pinRowHoleEdgeToEdgeDist,h=(c-1)*t.p+2*t.pinRowHoleEdgeToEdgeDist):(h=(t.rows-1)*t.p+2*t.pinRowHoleEdgeToEdgeDist,u=(c-1)*t.p+2*t.pinRowHoleEdgeToEdgeDist);t.numPins===0&&(u=10,h=10);const d=t.width??u,m=t.height??h,p=t.screenwidth??d*.95,_=t.screenheight??m*.95,f=t.screencenteroffsetx??0,I=t.screencenteroffsety??0;return{...t,pinlabelAnchorSide:e,pinRowSide:n,usbposition:o,usbtype:i,male:t.male??!t.female,female:t.female??!1,width:d,height:m,screenwidth:p,screenheight:_,screencenteroffsetx:f,screencenteroffsety:I,pinrowleftpins:r.left,pinrowrightpins:r.right,pinrowtoppins:r.top,pinrowbottompins:r.bottom}}).superRefine((t,e)=>{t.male&&t.female&&e.addIssue({code:Ao.custom,message:"'male' and 'female' cannot both be true; it should be male or female.",path:["male","female"]})}),J0i=t=>{const e=z0i.parse(t),{p:n,id:o,od:i,rows:r,numPins:s,pinlabelAnchorSide:a,pinlabelverticallyinverted:A,pinlabelorthogonal:c,pinlabeltextalignleft:l,pinlabeltextalignright:g,nopinlabels:u,doublesidedpinlabel:h,bottomsidepinlabel:d,pinRowSide:m,width:p,height:_,pinRowHoleEdgeToEdgeDist:f,holes:I,holeXDist:C,holeYDist:y,holeInset:x,pinrowleftpins:E,pinrowrightpins:B,pinrowtoppins:b,pinrowbottompins:Q,usbposition:w,usbtype:D,screen:k,screenwidth:T,screenheight:H,screencenteroffsetx:G,screencenteroffsety:U}=e;let Y="center";l?Y="left":g&&(Y="right");const j=[],ee={left:E,right:B,top:b,bottom:Q},W=Object.values(ee).some(se=>se!==void 0&&se>0),Z=(se,ne,le,he)=>{if(e.smd?j.push(yi(se,ne,le,e.od,e.od)):se===1?j.push(px({pn:se,x:ne,y:le,holeDiameter:o,rectPadWidth:i,rectPadHeight:i})):j.push(ka(se,ne,le,o,i)),!u){const Ie=ne+(he==="left"?-i:he==="right"?i:0),ce=le+(he==="top"?i:he==="bottom"?-i:0);d||j.push(sR({fs:i/5,pn:se,anchor_x:Ie,anchor_y:ce,textalign:Y,orthogonal:c,verticallyinverted:A,layer:"top"})),(h||d)&&j.push(sR({fs:i/5,pn:se,anchor_x:Ie,anchor_y:ce,textalign:Y,orthogonal:c,verticallyinverted:A,layer:"bottom"}))}};if(W){const se=n;let ne=1;const le=ee.left??0,he=ee.right??0,Ie=ee.top??0,ce=ee.bottom??0,fe=(de,Ce)=>{if(!(Ce<=0))if(de==="left"||de==="right"){const Qe=de==="left"?-p/2+f:p/2-f,Pe=(Ce-1)/2*se;for(let pe=0;pe<Ce;pe++)Z(ne,Qe,Pe-pe*se,de),ne++}else{const Qe=de==="top"?_/2-f:-_/2+f,Pe=-((Ce-1)/2)*se;for(let pe=0;pe<Ce;pe++)Z(ne,Pe+pe*se,Qe,de),ne++}};fe("left",le),fe("right",he),fe("top",Ie),fe("bottom",ce)}else{const se=n;let ne=0,le=0,he=0,Ie=0,ce=0,fe=0;const de=Math.ceil(s/r);m==="left"||m==="right"?(ne=m==="left"?-p/2+f:p/2-f,le=(de-1)/2*se,he=0,Ie=-se,ce=m==="left"?se:-se,fe=0):(ne=-(de-1)/2*se,le=m==="top"?_/2-f:-_/2+f,he=se,Ie=0,ce=0,fe=m==="top"?-se:se);let Ce=1;for(let Qe=0;Qe<r&&Ce<=s;Qe++)for(let Pe=0;Pe<de&&Ce<=s;Pe++){const pe=ne+Pe*he+Qe*ce,ve=le+Pe*Ie+Qe*fe;if(e.smd?j.push(yi(Ce,pe,ve,e.od,e.od)):Ce===1?j.push(px({pn:Ce,x:pe,y:ve,holeDiameter:o,rectPadWidth:i,rectPadHeight:i})):j.push(ka(Ce,pe,ve,o,i)),!u){const we=pe+(m==="left"?-i:m==="right"?i:0),Me=ve+(m==="top"?i:m==="bottom"?-i:0);d||j.push(sR({fs:i/5,pn:Ce,anchor_x:we,anchor_y:Me,textalign:Y,orthogonal:c,verticallyinverted:A,layer:"top"})),(h||d)&&j.push(sR({fs:i/5,pn:Ce,anchor_x:we,anchor_y:Me,textalign:Y,orthogonal:c,verticallyinverted:A,layer:"bottom"}))}Ce++}}if(I)for(const se of I){let ne=0,le=0;se==="topleft"?(ne=-p/2+x,le=_/2-x):se==="topright"?(ne=p/2-x,le=_/2-x):se==="bottomleft"?(ne=-p/2+x,le=-_/2+x):se==="bottomright"?(ne=p/2-x,le=-_/2+x):se==="center"&&(ne=0,le=0),C!==void 0&&(ne+=C),y!==void 0&&(le+=y),j.push(ka(s+I.indexOf(se)+1,ne,le,o,i))}if(!e.nosilkscreen){const se=[{x:-p/2,y:-_/2},{x:p/2,y:-_/2},{x:p/2,y:_/2},{x:-p/2,y:_/2},{x:-p/2,y:-_/2}];j.push(aR(se,{stroke_width:.1,layer:"top"}))}const ie=tr(0,_/2+1,.5);if(j.push(ie),w&&D){let se,ne;if(D==="c")se=8,ne=3;else if(D==="micro")se=6,ne=2;else return{circuitJson:j,parameters:e};let le;if(w==="left")le=[{x:-p/2,y:-se/2},{x:-p/2+ne,y:-se/2},{x:-p/2+ne,y:se/2},{x:-p/2,y:se/2},{x:-p/2,y:-se/2}];else if(w==="right")le=[{x:p/2-ne,y:-se/2},{x:p/2,y:-se/2},{x:p/2,y:se/2},{x:p/2-ne,y:se/2},{x:p/2-ne,y:-se/2}];else if(w==="top")le=[{x:-se/2,y:_/2-ne},{x:se/2,y:_/2-ne},{x:se/2,y:_/2},{x:-se/2,y:_/2},{x:-se/2,y:_/2-ne}];else if(w==="bottom")le=[{x:-se/2,y:-_/2},{x:se/2,y:-_/2},{x:se/2,y:-_/2+ne},{x:-se/2,y:-_/2+ne},{x:-se/2,y:-_/2}];else return{circuitJson:j,parameters:e};j.push(aR(le,{stroke_width:.1,layer:"top"}))}if(k){const se=T/2,ne=H/2,le=G,he=U,Ie=[{x:-se+le,y:-ne+he},{x:se+le,y:-ne+he},{x:se+le,y:ne+he},{x:-se+le,y:ne+he},{x:-se+le,y:-ne+he}];j.push(aR(Ie,{stroke_width:.05,layer:"top"}))}return{circuitJson:j,parameters:e}},W0i=[{x:-1.45,y:2.75},{x:-1.45,y:-1.85},{x:4.05,y:-1.85},{x:4.05,y:2.75}],j0i=[{x:-1.55,y:2.75},{x:-1.55,y:-1.85},{x:3.95,y:-1.85},{x:3.95,y:2.75}],X0i=Xi.extend({fn:$(),num_pins:ft().default(3),inline:We().default(!1),p:$().default("1.27mm"),id:$().default("0.75mm"),od:$().default("1.3mm"),w:$().default("4.8mm"),h:$().default("4.0mm")}),q0i=t=>{const e=X0i.parse(t),n=Number.parseFloat(e.p),o=Number.parseFloat(e.w),i=Number.parseFloat(e.h),r=e.inline?1.05:Number.parseFloat(e.od),s=e.inline?1.5:r,a=[px({pn:1,x:0,y:0,holeDiameter:e.id,rectPadWidth:r,rectPadHeight:s}),e.inline?IP(2,n,0,Number.parseFloat(e.id),r,s):ka(2,n,n,e.id,r),e.inline?IP(3,n*2,0,Number.parseFloat(e.id),r,s):ka(3,n*2,0,e.id,r)],A=o/2,c=e.inline?n-.09:n,l=.2,g=l+A-i,u=Array.from({length:32},(p,_)=>{const f=Math.PI*_/31;return{x:c+A*Math.cos(f),y:l+A*Math.sin(f)}}),h={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"",stroke_width:.12,route:[...u,{x:c-A,y:g},{x:c+A,y:g},u[0]]},d=tr(c,l+A+1,.5),m={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",outline:e.inline?j0i:W0i,layer:"top"};return{circuitJson:[...a,h,d,m],parameters:e}},$0i=(t,e)=>{const n=t.filter(o=>o.type==="pcb_silkscreen_text");if(n.length===0)return t;for(const o of n)e.norefdes&&(o.text="");return t},Z0i=(t,e)=>e.nosilkscreen?t.filter(n=>n.type!=="pcb_silkscreen_path"&&n.type!=="pcb_silkscreen_text"):t,egi=(t,e)=>{if(!e)return t;const n=t.filter(l=>l.type==="pcb_smtpad"||l.type==="pcb_plated_hole");if(n.length===0)return t;let o=Number.POSITIVE_INFINITY,i=Number.NEGATIVE_INFINITY,r=Number.POSITIVE_INFINITY,s=Number.NEGATIVE_INFINITY;const a=(l,g,u=0,h=0)=>{const d=l-u/2,m=l+u/2,p=g-h/2,_=g+h/2;o=Math.min(o,d),i=Math.max(i,m),r=Math.min(r,p),s=Math.max(s,_)};for(const l of n)if(l.type==="pcb_smtpad"){const g=l.shape==="circle"?l.radius*2:l.width,u=l.shape==="circle"?l.radius*2:l.height;a(l.x,l.y,g,u)}else if(l.type==="pcb_plated_hole"){const g=l.outer_diameter??l.hole_diameter;a(l.x,l.y,g,g)}let A=0,c=0;switch(e){case"center":A=(o+i)/2,c=(r+s)/2;break;case"bottomleft":A=o,c=r;break;case"bottomcenter":case"centerbottom":A=(o+i)/2,c=r;break;case"topcenter":case"centertop":A=(o+i)/2,c=s;break;case"leftcenter":case"centerleft":A=o,c=(r+s)/2;break;case"rightcenter":case"centerright":A=i,c=(r+s)/2;break;case"pin1":{const l=n.find(g=>g.port_hints?.[0]==="1")||n[0];A=l.x,c=l.y;break}}if(A===0&&c===0)return t;for(const l of t){if(typeof l.x=="number"&&(l.x-=A),typeof l.y=="number"&&(l.y-=c),l.center&&typeof l.center.x=="number"&&(l.center.x-=A,l.center.y-=c),l.type==="pcb_silkscreen_path")for(const g of l.route)g.x-=A,g.y-=c;l.type==="pcb_silkscreen_text"&&l.anchor_position&&(l.anchor_position.x-=A,l.anchor_position.y-=c)}return t};function tgi(t){return t!=null}var ngi=t=>t.trim().replace(/^pinheader(?=[\d_]|$)/i,"pinrow").replace(/^sot23-(\d+)(?=_|$)/i,"sot23_$1").replace(/^sot-223-(\d+)(?=_|$)/i,"sot223_$1").replace(/^to-220f-(\d+)(?=_|$)/i,"to220f_$1").replace(/^jst_(ph|sh|zh)_(\d+)(?=_|$)/i,"jst$2_$1"),ogi=t=>{let e=Rue();const n=ngi(t),i=n.replace(/^((?:\d{4}|\d{5}))(?=$|_|x)/,"res$1").replace(/^zh(\d+)(?:$|_)/,"jst$1_zh").split(/_(?!metric)/).map(r=>{const s=r.match(/([a-zA-Z]+)([\(\d\.\+\?].*)?/);if(!s)return null;const[,a,A]=s;if(!a)return null;const c=a.toLowerCase();return A?.includes("?")?null:{fn:c,v:A}}).filter(tgi);for(const{fn:r,v:s}of i)e=e[r](s);return e.setString(n),e},igi=()=>Object.keys(BS),Rue=()=>{const t=new Proxy({},{get:(e,n)=>{if(n==="soup"||n==="circuitJson"){if("fn"in e&&BS[e.fn])return()=>{const{circuitJson:o}=BS[e.fn](e),i=Z0i(o,e),r=$0i(i,e);return egi(r,e.origin)};if(!BS[e.fn])throw new Error(`Invalid footprint function, got "${e.fn}"${e.string?`, from string "${e.string}"`:""}`);return()=>{throw new Error(`No function found for footprinter, make sure to specify .dip, .lr, .p, etc. Got "${n}"`)}}if(n==="json"){if(!BS[e.fn])throw new Error(`Invalid footprint function, got "${e.fn}"${e.string?`, from string "${e.string}"`:""}`);return()=>BS[e.fn](e).parameters}return n==="getFootprintNames"?()=>Object.keys(BS):n==="params"?()=>e:n==="setString"?o=>(e.string=o,t):o=>(Object.keys(e).length===0?`${n}${o}`in BS?(e[`${n}${o}`]=!0,e.fn=`${n}${o}`):(e[n]=!0,e.fn=n,n==="res"||n==="cap"||n==="led"||n==="diode"?o&&(typeof o=="string"&&o.includes("_metric")?e.metric=o.split("_metric")[0]:e.imperial=o):e.num_pins=Number.isNaN(Number.parseFloat(o))?void 0:Number.parseFloat(o)):!o&&["w","h","p"].includes(n)||(e[n]=o??!0),t)}});return t};Rue.string=ogi,Rue.getFootprintNames=igi;var W1=Rue,sen={in:25.4,inch:25.4,mil:.0254,mm:1,m:1e3,cm:10,ft:304.8,feet:304.8},rgi=t=>{let e=typeof t=="number"?"mm":t.replace(/^[^a-zA-Z]+/g,"").toLowerCase();e||(e="mm");const n=typeof t=="number"?t:Number.parseFloat(t.split(e)[0]);if(e in sen)return n*sen[e];throw new Error(`Unsupported unit: ${e}`)},J6=Eo([ft(),$()]).transform((t,e)=>{try{const n=rgi(t);if(!Number.isFinite(n))throw new Error("Length is not finite");return n}catch{return e.addIssue({code:"custom",message:`Invalid model length: ${String(t)}`}),J3n}}),Of=J6.refine(t=>t>0,"Length must be greater than zero"),W6=J6.refine(t=>t>=0,"Length cannot be negative"),sgi=zn(["sitsFlat","sitsFlatBelowBoard","foldedToFaceAboveBoard","foldedToFaceBelowBoard","foldedToRightAngleAboveBoard","foldedToRightAngleBelowBoard"]),mYe=ft().finite().positive(),agi=$().refine(t=>{const e=t.split(":");if(e.length!==2)return!1;const n=Number(e[0]),o=Number(e[1]);return Number.isFinite(n)&&Number.isFinite(o)&&n>0&&o>0},'Aspect ratio must look like "16:9"').transform(t=>t),aen=Eo([mYe,agi,XT([mYe,mYe])]),Aen=Pt({x:J6.optional(),y:J6.optional(),z:J6.optional()}).strict(),pYe=Eo([ft().finite(),$().min(1)]),cen=XT([pYe,pYe,pYe]),Agi=["sitsFlat","sitsFlatBelowBoard","foldedToFaceAboveBoard","foldedToFaceBelowBoard","foldsAboveBoard","foldsBelowBoard","foldedToRightAngleAboveBoard","foldedToRightAngleBelowBoard"],len={width:Of.optional(),height:Of.optional(),diagonal:Of.optional(),aspectRatio:aen.optional(),ratio:aen.optional(),defaultDiagonal:Of.optional(),orientation:sgi.optional(),sitsFlat:We().optional(),sitsFlatBelowBoard:We().optional(),foldedToFaceAboveBoard:We().optional(),foldedToFaceBelowBoard:We().optional(),foldsAboveBoard:We().optional(),foldsBelowBoard:We().optional(),foldedToRightAngleAboveBoard:We().optional(),foldedToRightAngleBelowBoard:We().optional(),screenThickness:Of.optional(),bezelInset:W6.optional(),bezelDepth:Of.optional(),activeAreaWidth:Of.optional(),activeAreaHeight:Of.optional(),screenColor:$().min(1).optional(),bezelColor:$().min(1).optional(),showScreen:We().optional(),flexCableLength:Of.optional(),flexCableWidth:Of.optional(),flexCableThickness:Of.optional(),flexCableColor:$().min(1).optional(),conductorCount:ft().int().positive().optional(),conductorPitch:Of.optional(),conductorWidth:Of.optional(),conductorThickness:Of.optional(),conductorColor:$().min(1).optional(),cableEdgeMargin:W6.optional(),exposedContactLength:W6.optional(),showConductors:We().optional(),showFlexCable:We().optional(),showStiffeners:We().optional(),stiffenerLength:W6.optional(),stiffenerThickness:Of.optional(),stiffenerColor:$().min(1).optional(),bendRadius:Of.optional(),bendSegments:ft().int().min(2).optional(),rightAngleVerticalLead:W6.optional(),distanceAboveBoard:W6.optional(),distanceBelowBoard:W6.optional(),foldDistanceFromConnector:W6.optional(),foldOutset:Of.optional(),foldSegments:ft().int().min(4).optional(),screenGap:W6.optional(),boardTopZ:J6.optional(),boardThickness:Of.optional(),boardClearance:W6.optional(),cableStartX:J6.optional(),cableStartY:J6.optional(),cableStartZ:J6.optional(),cableLateralOffset:J6.optional(),screenOffset:Aen.optional(),screenRotation:cen.optional(),rotation:cen.optional(),offset:Aen.optional()},gen=(t,e)=>{const n=Agi.filter(o=>t[o]===!0);n.length>1&&e(n[1])};Pt(len).strict().superRefine((t,e)=>{gen(t,n=>{e.addIssue({code:"custom",message:"Only one FlexScreen orientation shortcut can be true",path:[n]})})});var cgi=Pt({fn:je("flexscreen"),...len}).strict().superRefine((t,e)=>{gen(t,n=>{e.addIssue({code:"custom",message:"Only one FlexScreen orientation shortcut can be true",path:[n]})})}),uen=t=>{const e=t.match(/^([a-zA-Z]+)([\(\d\.\+\-].*)?$/);if(e?.[1])return{fn:e[1].toLowerCase(),value:e[2]}},lgi=t=>{const e=t.trim();if(!e)throw new Error("Model string cannot be empty");const n=e.split("_"),o=n[0],i=uen(o),r={},s=i?.fn??o.toLowerCase();if(r[s]=!0,r.fn=s,i?.value){const a=Number.parseFloat(i.value);Number.isFinite(a)&&(r.num_pins=a)}for(const a of n.slice(1)){if(!a)throw new Error("Model strings cannot contain empty tokens");const A=uen(a);if(!A)throw new Error(`Invalid model string token "${a}"`);r[A.fn]=A.value??!0}return r.string=e,r},ggi={sitsflat:"sitsFlat",sitsflatbelow:"sitsFlatBelowBoard",sitsflatbelowboard:"sitsFlatBelowBoard",foldsabove:"foldedToFaceAboveBoard",foldsaboveboard:"foldedToFaceAboveBoard",foldedtofaceaboveboard:"foldedToFaceAboveBoard",foldsbelow:"foldedToFaceBelowBoard",foldsbelowboard:"foldedToFaceBelowBoard",foldedtofacebelowboard:"foldedToFaceBelowBoard",rightangleabove:"foldedToRightAngleAboveBoard",rightangleaboveboard:"foldedToRightAngleAboveBoard",foldedtorightangleaboveboard:"foldedToRightAngleAboveBoard",rightanglebelow:"foldedToRightAngleBelowBoard",rightanglebelowboard:"foldedToRightAngleBelowBoard",foldedtorightanglebelowboard:"foldedToRightAngleBelowBoard"},ugi={width:["width","w"],height:["height","h"],diagonal:["diagonal","diag","d"],defaultDiagonal:["defaultdiagonal","defaultdiag"],screenThickness:["screenthickness"],bezelInset:["bezelinset"],bezelDepth:["bezeldepth"],activeAreaWidth:["activeareawidth","activew"],activeAreaHeight:["activeareaheight","activeh"],flexCableLength:["flexcablelength","flexlength","flex"],flexCableWidth:["flexcablewidth","flexwidth"],flexCableThickness:["flexcablethickness","flexthickness"],conductorPitch:["conductorpitch"],conductorWidth:["conductorwidth"],conductorThickness:["conductorthickness"],cableEdgeMargin:["cableedgemargin","edgemargin"],exposedContactLength:["exposedcontactlength","contactlength"],stiffenerLength:["stiffenerlength"],stiffenerThickness:["stiffenerthickness"],bendRadius:["bendradius"],rightAngleVerticalLead:["rightangleverticallead","verticallead"],distanceAboveBoard:["distanceaboveboard","distanceabove"],distanceBelowBoard:["distancebelowboard","distancebelow"],foldDistanceFromConnector:["folddistancefromconnector","folddistance","foldstart"],foldOutset:["foldoutset","outset"],screenGap:["screengap"],boardTopZ:["boardtopz"],boardThickness:["boardthickness"],boardClearance:["boardclearance"],cableStartX:["cablestartx"],cableStartY:["cablestarty"],cableStartZ:["cablestartz"],cableLateralOffset:["cablelateraloffset","lateraloffset"]},dgi=Object.fromEntries(Object.entries(ugi).flatMap(([t,e])=>e.map(n=>[n,t]))),hgi={conductorcount:"conductorCount",conductors:"conductorCount",bendsegments:"bendSegments",foldsegments:"foldSegments"},den={showscreen:["showScreen",!0],hidescreen:["showScreen",!1],showflex:["showFlexCable",!0],hideflex:["showFlexCable",!1],showconductors:["showConductors",!0],hideconductors:["showConductors",!1],showstiffeners:["showStiffeners",!0],hidestiffeners:["showStiffeners",!1]},mgi={screencolor:"screenColor",bezelcolor:"bezelColor",flexcolor:"flexCableColor",conductorcolor:"conductorColor",stiffenercolor:"stiffenerColor"},pgi=t=>{const e=String(t).toLowerCase().replace("x",":");if(e.includes(":")){const[o,i,r]=e.split(":"),s=Number(o),a=Number(i);if(r!==void 0||!Number.isFinite(s)||!Number.isFinite(a)||s<=0||a<=0)throw new Error(`Invalid FlexScreen aspect ratio "${String(t)}"`);return`${s}:${a}`}const n=Number(e);if(!Number.isFinite(n)||n<=0)throw new Error(`Invalid FlexScreen aspect ratio "${String(t)}"`);return n},_gi=(t,e)=>{if(typeof t!="string"||!/^\(.+\)$/.test(t))throw new Error(`FlexScreen token "${e}" requires a value in (...)`);return t.slice(1,-1)},hen=(t,e)=>{if(t!==!0)throw new Error(`FlexScreen token "${e}" does not accept a value`)},fgi=t=>{if(t.fn!=="flexscreen")throw new Error(`Expected FlexScreen params, got "${t.fn}"`);const e={};let n,o;for(const[i,r]of Object.entries(t)){if(i==="fn"||i==="string"||i==="flexscreen")continue;const s=ggi[i];if(s){if(hen(r,i),n&&n!==s)throw new Error("A FlexScreen model string can only set one orientation");n=s,e.orientation=s;continue}if(i in den){hen(r,i);const[l,g]=den[i];e[l]=g;continue}const a=mgi[i];if(a){e[a]=_gi(r,i);continue}if(i==="ratio"){e.aspectRatio=pgi(r);continue}const A=dgi[i];if(A){e[A]=r;continue}if(i==="distance"){o=r;continue}const c=hgi[i];if(c){const l=Number(r);if(!Number.isInteger(l)||l<1)throw new Error(`Invalid positive integer in FlexScreen token "${i}${String(r)}"`);e[c]=l;continue}throw new Error(`Unknown FlexScreen model token "${i}${String(r)}"`)}if(o!==void 0)if(n==="foldedToFaceAboveBoard")e.distanceAboveBoard=o;else if(n==="foldedToFaceBelowBoard")e.distanceBelowBoard=o;else throw new Error('The "distance" token requires foldsabove or foldsbelow; use distanceabove or distancebelow for an explicit side');return cgi.parse({fn:"flexscreen",...e})},men={flexscreen:fgi},Igi=t=>{const e=men[t.fn];if(e)return e(t);throw new Error(`Unsupported modelprinter function "${t.fn}"`)},Cgi=t=>{const e=lgi(t);return{params:()=>e,json:()=>Igi(e)}},ygi={string:Cgi,getModelNames:()=>Object.keys(men)},_Ye=ygi,pen=Symbol("Fragment");function fYe(t,e,...n){const o=n.length?n:e?.children!==void 0?[e.children]:[],i=[],r=(Array.isArray(o)?o:[o]).flat(1/0);for(const s of r)s==null||s===!1||(Array.isArray(s)?i.push(...s):i.push(s));return{type:t,props:(e&&e.children!==void 0?{...e,children:void 0}:e)||{},children:i}}var Xt=Symbol("Cuboid"),_en=Symbol("Cube"),Qs=Symbol("Cylinder"),pG=Symbol("Sphere"),Gf=Symbol("RoundedCuboid"),Fo=Symbol("Translate"),$A=Symbol("Rotate"),zd=Symbol("Union"),Hl=Symbol("Subtract"),KA=Symbol("Hull"),zo=Symbol("Colorize"),_G=Symbol("Polygon"),fG=Symbol("ExtrudeLinear"),Ny=Symbol("RoundedCylinder"),fi=pen,De=(t,e,n)=>fYe(t,e),Bn=(t,e,n)=>fYe(t,e),IYe=({hole:t,isPin1:e})=>{const n=e?"#00ff00":"#b87333";if(t.shape==="circle")return De(zo,{color:n,children:De(Fo,{offset:[t.x,t.y,-.005],children:Bn(Hl,{children:[De(Qs,{radius:t.outer_diameter/2,height:.01}),De(Qs,{radius:t.hole_diameter/2,height:.01})]})})});if(t.shape==="circular_hole_with_rect_pad")return De(zo,{color:n,children:De(Fo,{offset:[t.x,t.y,0],children:Bn(Hl,{children:[De(Xt,{size:[t.rect_pad_width,t.rect_pad_height,.01],center:[0,0,0]}),De(Qs,{radius:t.hole_diameter/2,height:.01})]})})});if(t.shape==="pill"){const o=t.outer_width,i=t.outer_height,r=Math.min(o,i)/2,s=o>i,a=t.hole_width??.8,A=t.hole_height??.8;return De(zo,{color:n,children:De(Fo,{offset:[t.x,t.y,0],children:Bn(Hl,{children:[Bn(KA,{children:[De(Qs,{radius:r,height:.01,center:[s?-(o/2-r):0,s?0:-(i/2-r),0]}),De(Qs,{radius:r,height:.01,center:[s?o/2-r:0,s?0:i/2-r,0]})]}),a===A?De(Qs,{radius:a/2,height:.01}):Bn(KA,{children:[De(Qs,{radius:Math.min(a,A)/2,height:.01,center:[a>A?-(a/2-A/2):0,a>A?0:-(A/2-a/2),0]}),De(Qs,{radius:Math.min(a,A)/2,height:.01,center:[a>A?a/2-A/2:0,a>A?0:A/2-a/2,0]})]})]})})})}throw new Error("Shape not supported: "+t.shape)};function xgi(t){for(const o of["bodyWidth","bodyLength","bodyHeight","pitch","landWidth","landLength","landThickness"])if(!Number.isFinite(t[o])||t[o]<=0)throw new Error(`${o} must be finite and positive`);for(const o of["landsPerSideX","landsPerSideY"])if(!Number.isInteger(t[o])||t[o]<0)throw new Error(`${o} must be a nonnegative integer`);if(!Number.isFinite(t.edgeInset)||t.edgeInset<0||t.landThickness>=t.bodyHeight||t.landWidth>=t.pitch||t.landsPerSideX+t.landsPerSideY<1)throw new Error("Invalid land layout or thickness");const e=[{count:t.landsPerSideX,across:t.bodyWidth,along:t.bodyLength,horizontal:!0},{count:t.landsPerSideY,across:t.bodyLength,along:t.bodyWidth,horizontal:!1}];for(const o of e){if(o.count===0)continue;const i=(o.count-1)*t.pitch+t.landWidth;if(i>=o.along-2*t.edgeInset||2*(t.edgeInset+t.landLength)>=o.across)throw new Error("Lands must fit below the body without opposite-row overlap");const r=o.horizontal?t.landsPerSideY:t.landsPerSideX;if(r>0&&i>=o.along-2*(t.edgeInset+t.landLength)&&(r-1)*t.pitch+t.landWidth>=o.across-2*(t.edgeInset+t.landLength))throw new Error("Adjacent land rows overlap at corners")}const n=Math.min(t.bodyWidth,t.bodyLength)*.035;return Bn(fi,{children:[De(zo,{color:"#353535",children:Bn(Hl,{children:[De(Fo,{z:(t.bodyHeight+t.landThickness/2)/2,children:De(Xt,{size:[t.bodyWidth,t.bodyLength,t.bodyHeight-t.landThickness/2]})}),De(Fo,{offset:[-t.bodyWidth/2+2*n,t.bodyLength/2-2*n,t.bodyHeight],children:De(Qs,{radius:n,height:Math.min(.04,t.bodyHeight/10)})})]})}),De(zo,{color:"#c5b987",children:e.flatMap(o=>[-1,1].flatMap(i=>Array.from({length:o.count},(r,s)=>{const a=i*(o.across/2-t.edgeInset-t.landLength/2),A=((o.count-1)/2-s)*t.pitch;return De(Fo,{offset:[o.horizontal?a:A,o.horizontal?A:a,t.landThickness/2],children:De(Xt,{size:o.horizontal?[t.landLength,t.landWidth,t.landThickness]:[t.landWidth,t.landLength,t.landThickness]})},`${o.horizontal}-${i}-${s}`)})))})]})}function Tue(t){const{pinCount:e,pitch:n,bodyWidth:o,bodyLength:i,bodyHeight:r,standoff:s,leadSpan:a,leadWidth:A,leadThickness:c,contactLength:l,taperInset:g,exposedPadWidth:u=0,exposedPadLength:h=0}=t;for(const E of["pitch","bodyWidth","bodyLength","bodyHeight","leadSpan","leadWidth","leadThickness","contactLength"])if(!Number.isFinite(t[E])||t[E]<=0)throw new Error(`${E} must be finite and positive`);for(const[E,B]of Object.entries({standoff:s,taperInset:g,exposedPadWidth:u,exposedPadLength:h}))if(!Number.isFinite(B)||B<0)throw new Error(`${E} must be finite and nonnegative`);if(!Number.isInteger(e)||e<4||e%2)throw new Error("pinCount must be even and at least 4");const d=r-s,m=(a-o)/2,p=(e/2-1)*n+A;if(d<=c*2||A>=n||p>=i-2*g||g*2>=Math.min(o,i)||l>=m)throw new Error("Invalid mold, lead spacing, or terminal reach");if(u===0!=(h===0)||u>=o-2*g||h>=i-2*g)throw new Error("Exposed pad must fit inside the bottom mold face");const _=s+d/2,f=Math.min(.002,d/100),I=Bn(KA,{children:[De(Fo,{z:s+f/2,children:De(Xt,{size:[o-2*g,i-2*g,f]})}),De(Fo,{z:_,children:De(Xt,{size:[o,i,f]})}),De(Fo,{z:r-f/2,children:De(Xt,{size:[o-2*g,i-2*g,f]})})]}),C=Math.min(o,i)*.045,y=Math.min(.04,d/10),x=(E,B)=>{const b=a/2,Q=o/2-Math.min(o/8,.15),w=b-l,D=o/2+Math.min(.08,(m-l)/4),k=[[b-f/2,c/2],[w,c/2]];for(let H=1;H<=12;H++){const G=H/12;k.push([w+(D-w)*G,c/2+(_-c/2)*G*G*(3-2*G)])}k.push([Q,_]);const T=([H,G])=>De(Fo,{offset:{x:E*H,y:B,z:G},children:De(Xt,{size:[f,A,c]})});return De(zd,{children:k.slice(1).map((H,G)=>Bn(KA,{children:[T(k[G]),T(H)]}))})};return Bn(fi,{children:[De(zo,{color:"#353535",children:Bn(Hl,{children:[I,De(Fo,{offset:{x:-o/2+g+C*2,y:i/2-g-C*2,z:r},children:De(Qs,{radius:C,height:y*2})})]})}),De(zo,{color:"#bfc1c4",children:Array.from({length:e},(E,B)=>x(B<e/2?-1:1,((e/2-1)/2-B%(e/2))*n))}),u>0&&De(zo,{color:"#bfc1c4",children:De(Fo,{z:(s+c)/2,children:De(Xt,{size:[u,h,s+c]})})})]})}var Egi=t=>Tue(t);function Bgi(t){if(t.bodywidth===void 0&&t.bodyheight===void 0&&t.bodythickness===void 0)return null;if(t.fn==="ssop"){const e=t.bodywidth??t.w*.55,n=t.bodyheight??(t.num_pins/2-1)*t.p+t.pw+.4,o=t.bodythickness??1,i=Math.min(t.pw,t.p*.5),r=(t.num_pins/2-1)*t.p+i;if(n<=r)throw new Error("SSOP bodyheight must contain the lead row");const s=Math.max(t.w+.2+t.pl/2,e+t.p),a=Math.min(.1,o/10);return De(Egi,{pinCount:t.num_pins,pitch:t.p,bodyWidth:e,bodyLength:n,bodyHeight:o+a,standoff:a,leadSpan:s,leadWidth:i,leadThickness:Math.min(.15,o/4),contactLength:Math.min(t.pl/2,(s-e)/4),taperInset:Math.min(.12,(n-r)/4,e/8)})}if(t.fn==="lga"){const e=t.bodywidth??t.w,n=t.bodyheight??t.h,o=t.bodythickness??1,i=t.grid,r=Math.min(t.pw,t.p/2),s=e-((i.y-1)*t.p+r),a=n-((i.x-1)*t.p+r),A=Math.min(t.pl/2,e/8,n/8,s/4,a/4);return De(xgi,{bodyWidth:e,bodyLength:n,bodyHeight:o,landsPerSideX:i.x,landsPerSideY:i.y,pitch:t.p,landWidth:r,landLength:A,edgeInset:0,landThickness:Math.min(.015,o/10)})}return null}var Kg=({center:t,width:e,length:n,height:o,heightAboveSurface:i=.15,color:r="#555",taperRatio:s=.12,faceRatio:a=.75,straightHeightRatio:A=.5,includeNotch:c=!0,notchRadius:l,notchPosition:g,notchRotation:u=[0,0,0],notchLength:h=.5,notchWidth:d=.25,chamferSize:m=0})=>{const p=o*A,_=o-p,f=Math.min(e,n)*s,I=Math.max(e-f,e*a),C=Math.max(n-f,n*a),y=Math.min(e,n)*.12,x=l??y,E={x:0,y:n/2-x*.25,z:o},B=g??E,b=Bn(zd,{children:[Bn(KA,{children:[De(Fo,{z:.005,children:De(Xt,{size:[I,C,.01]})}),De(Fo,{z:p,children:De(Xt,{size:[e,n,.01]})})]}),Bn(KA,{children:[De(Fo,{z:p,children:De(Xt,{size:[e,n,.01]})}),De(Fo,{z:p+_,children:De(Xt,{size:[I,C,.01]})})]})]}),Q=(D,k)=>De(Fo,{offset:{x:D,y:k,z:0},children:De($A,{rotation:[0,0,Math.PI/4],children:De(Xt,{size:[m*Math.SQRT2,m*Math.SQRT2,o*3]})})});let w=b;if(m>0){const D=e/2,k=n/2;w=Bn(Hl,{children:[b,Q(D,k),Q(-D,k),Q(D,-k),Q(-D,-k)]})}return De(zo,{color:r,children:De(Fo,{offset:t,children:De(Fo,{offset:{x:0,y:0,z:i},children:c?Bn(Hl,{children:[w,De(Fo,{offset:B,children:De($A,{rotation:u,children:De(Qs,{radius:x,height:d})})})]}):w})})})},Sgi=t=>Array.from({length:t},(e,n)=>n);function CYe(t,e){if(t.length<2)throw new Error("Stroke must have at least two points");const n=Array.isArray(t[0])?t.map(([l,g])=>({x:l,y:g})):t,o=e/2,i=[],r=[];function s(l,g){const u=g.x-l.x,h=g.y-l.y,d=Math.sqrt(u*u+h*h);return{x:-h/d,y:u/d}}function a(l,g,u){const h={x:l.x+g.x*o*u,y:l.y+g.y*o*u};u>0?i.push(h):r.unshift(h)}const A=s(n[0],n[1]);a(n[0],A,1),a(n[0],A,-1);for(let l=1;l<n.length-1;l++){const g=n[l-1],u=n[l],h=n[l+1],d=s(g,u),m=s(u,h),p=d.x+m.x,_=d.y+m.y,f=Math.sqrt(p*p+_*_);if(f/2>2*o)a(u,d,1),a(u,m,1),a(u,d,-1),a(u,m,-1);else{const C=1/f;a(u,{x:p*C,y:_*C},1),a(u,{x:p*C,y:_*C},-1)}}const c=s(n[n.length-2],n[n.length-1]);return a(n[n.length-1],c,1),a(n[n.length-1],c,-1),[...i,...r]}var bgi=t=>{const e=Math.min(...t.map(a=>a.x)),n=Math.max(...t.map(a=>a.x)),o=Math.min(...t.map(a=>a.y)),s=5.47/(Math.max(...t.map(a=>a.y))-o);return t.map(a=>({x:(a.x-e-(n-e)/2)*s,y:(a.y-o)*s}))},Qgi=bgi([{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}]),fen=5.47,kue=.5,vgi=({x:t,y:e,z:n})=>{const o=t>0;return Bn(fi,{children:[De(Fo,{offset:{x:t+.25/2,y:e,z:n},children:De($A,{rotation:["-90deg",0,"90deg"],children:De(fG,{height:.25,children:De(_G,{points:Qgi.slice().reverse().map(i=>[i.x,i.y])})})})}),De(Fo,{offset:{x:t,y:e+(o?1:-1),z:n},children:De($A,{rotation:["-90deg","90deg",o?"180deg":"0deg"],children:De(fG,{height:2,children:De(_G,{points:CYe([[0,0],[-1,0],[-1,-1]],.25).map(i=>[i.x,i.y])})})})})]})},Pgi=({numPins:t=8,pitch:e=2.54,bodyWidth:n=6.4,rowSpacing:o})=>{const i=Math.floor(t/2),r=o??(n>=7?n:n+1.22),s=n>=7?r-1.22:n;return Bn(fi,{children:[Sgi(t).map(a=>{const A=a%i,c=(Math.floor(a/i)-.5)*2;return De(vgi,{x:c*r/2,y:A*e-(i-1)/2*e,z:fen/2+kue})}),De(Kg,{width:s,length:i*e+.5,height:fen-kue,heightAboveSurface:kue,center:{x:0,y:0,z:kue}})]})};function wgi(t,{height:e,padContactLength:n,curveLength:o,bodyDistance:i,steepness:r=10}){o||(o=i*.3);let s=i-n-o;s<0&&(o+=s,s=0);const a=n*.75,A=n+o+(i-n-o)*.25;if(t<=a)return 0;if(t>=A)return e;const c=(t-a)/(A-a);return e/(1+Math.exp(-r*(c-.5)))}var $r=t=>{const{thickness:e,width:n,padContactLength:o,bodyDistance:i,height:r,rotation:s}=t,a=15,A=Array.from({length:a}).map((l,g)=>g/(a-1)*i).map(l=>[l,wgi(l,t)]),c=CYe(A,e);return De(zo,{color:"#fff",children:De(Fo,{offset:{z:0,y:0,x:0,...t.position},children:De($A,{rotation:["90deg",0,s??0],children:De(Fo,{offset:{x:0,y:0,z:-n/2},children:De(fG,{height:n,children:De(_G,{points:c.map(l=>[l.x,l.y])})})})})})})},Mgi=({pinCount:t,leadLength:e,leadWidth:n,pitch:o,bodyWidth:i})=>{const r=Math.ceil(t/2),s=r<=4,a=(r-1)*o/2,A=o*Math.max(r-1,0)+(s?1.5:1.15),c=i-(s?.66:.58),l=.15,g=.8,u=1.22,h=e*.5,d=h+Math.max(.22,Math.min(.4,e*.65)),m=i/2+e/2,p=d*.1,_=Math.min(Math.min(c,A)*.18,1),f=Math.min(Math.min(c,A)*.12,.45);return Bn(fi,{children:[Array.from({length:r}).map((I,C)=>De($r,{position:{x:-m,y:C*o-a,z:l/2},width:n,thickness:l,padContactLength:h,bodyDistance:d,curveLength:p,height:g})),Array.from({length:r}).map((I,C)=>De($r,{rotation:Math.PI,position:{x:m,y:C*o-a,z:l/2},width:n,thickness:l,padContactLength:h,bodyDistance:d,curveLength:p,height:g})),De(Kg,{center:{x:0,y:0,z:0},width:c,length:A,height:u,notchPosition:{x:-(c/2-_-.2),y:A/2-_-.2,z:u},notchRadius:f})]})},Dgi=t=>"leadSpan"in t?Tue(t):Mgi(t),Ngi=({pinCount:t,padContactLength:e=.4,leadWidth:n=.2,pitch:o=.65,bodyWidth:i=3})=>{const r=Math.ceil(t/2),s=(r-1)*o/2,a=.2;return Bn(fi,{children:[Array.from({length:r}).map((A,c)=>De($r,{position:{x:-i/2-e-.3,y:c*o-s,z:a/2},width:n,thickness:a,padContactLength:e,bodyDistance:e+.4,height:.6})),Array.from({length:r}).map((A,c)=>De($r,{rotation:Math.PI,position:{x:i/2+e+.3,y:c*o-s,z:a/2},width:n,thickness:a,padContactLength:e,bodyDistance:e+.4,height:.6})),De(Kg,{center:{x:0,y:0,z:a/2},width:i,length:i,height:1.1,notchRadius:.35,heightAboveSurface:.1,taperRatio:.09})]})},Rgi=t=>"leadSpan"in t?Tue(t):Ngi(t),yYe=1,xYe=.5,IG=.5,KX=.2,Tgi=yYe-KX*2,Ien=({color:t="#333"})=>Bn(fi,{children:[De(Xt,{size:[Tgi,xYe,IG],offset:[0,0,IG/2],color:t}),De(Xt,{size:[KX,IG,xYe],offset:[yYe/2-KX/2,0,IG/2],color:"#ccc"}),De(Xt,{size:[KX,IG,xYe],offset:[-yYe/2+KX/2,0,IG/2],color:"#ccc"})]}),EYe=1.6,kgi=EYe-.3*2,Fue=.3,BYe=.85,CG=.6,Cen=({color:t="#333"})=>Bn(fi,{children:[De(Xt,{size:[kgi,BYe,CG],offset:[0,0,CG/2],color:t}),De(Xt,{size:[Fue,BYe,CG],offset:[EYe/2-Fue/2,0,CG/2],color:"#ccc"}),De(Xt,{size:[Fue,BYe,CG],offset:[-EYe/2+Fue/2,0,CG/2],color:"#ccc"})]}),SYe=2,bYe=1.25,yG=.55,VX=.5,Fgi=SYe-VX*2,yen=({color:t="#333"})=>Bn(fi,{children:[De(Xt,{size:[Fgi,bYe,yG],offset:[0,0,yG/2],color:t}),De(Xt,{size:[VX,bYe,yG],offset:[SYe/2-VX/2,0,yG/2],color:"#ccc"}),De(Xt,{size:[VX,bYe,yG],offset:[-SYe/2+VX/2,0,yG/2],color:"#ccc"})]}),xen=({pinCount:t,pitch:e,leadWidth:n,padContactLength:o,bodyWidth:i})=>{const r=t/4;e||(e=Lgi(t,i)),o||(o=Hgi(t)),n||(n=Ogi(t,i)),i||(i=e*(r+4));const s=o,a=i,A=(r-1)*e/2,c=s*.5,l=a+2*c,g=l,u=.8,h=.15,d=c,m=c*.5,p=c*.18;return Bn(fi,{children:[Array.from({length:r}).map((_,f)=>De($r,{position:{x:-g/2,y:f*e-A,z:h/2},width:n,thickness:h,padContactLength:m,bodyDistance:d,curveLength:p,height:u})),Array.from({length:r}).map((_,f)=>De($r,{rotation:Math.PI,position:{x:g/2,y:f*e-A,z:h/2},width:n,thickness:h,padContactLength:m,bodyDistance:d,curveLength:p,height:u})),Array.from({length:r}).map((_,f)=>De($r,{rotation:Math.PI/2,position:{x:f*e-A,y:-l/2,z:h/2},width:n,thickness:h,padContactLength:m,bodyDistance:d,curveLength:p,height:u})),Array.from({length:r}).map((_,f)=>De($r,{rotation:-Math.PI/2,position:{x:f*e-A,y:l/2,z:h/2},width:n,thickness:h,padContactLength:m,bodyDistance:d,curveLength:p,height:u})),De(Kg,{center:{x:0,y:0,z:0},width:i,length:a,height:1.5,taperRatio:.03,chamferSize:.7,notchPosition:{x:-(a/2-1.5),y:i/2-1.5,z:1.5},notchRadius:1.5/2})]})},Lgi=(t,e)=>{switch(t){case 44:case 64:return .8;case 52:return e===14?1:.65;case 208:return .5;default:return .5}},Hgi=t=>{switch(t){case 32:return .6;case 40:return .6;case 52:case 64:return .65;case 208:return 1.65;default:return .6}},Ogi=(t,e)=>{switch(t){case 44:case 64:return .5;case 52:return e===14?.45:.55;case 208:return .3;default:return .25}},xG="#c0c0c0",Een=({x:t,y:e,pinThickness:n,shortSidePinLength:o,longSidePinLength:i,bodyHeight:r,bodyLength:s=2.54,bodyWidth:a=2.54,flipZ:A,smd:c,rightangle:l})=>Bn(fi,{children:[De(Fo,{y:l?-3:0,children:De(Xt,{color:"#222",size:[s,a,r],center:[t,e,A(r/2)]})}),De(zo,{color:xG,children:c?De($r,{rotation:-Math.PI/2,position:{x:t,y:e+1,z:n/2},thickness:n,width:n,height:n,padContactLength:2,bodyDistance:3}):Bn(KA,{children:[De(Xt,{color:xG,size:[n,n,o*.9],center:[t,e,A(r*.9+r/2)]}),De(Xt,{color:xG,size:[n/1.8,n/1.8,o],center:[t,e,A(r+r/2)]})]})}),De(zo,{color:xG,children:De(Fo,{y:l?-3.9:0,z:l?1:0,children:De($A,{rotation:l?[-Math.PI/2,0,0]:[0,0,0],children:Bn(KA,{children:[De(Xt,{color:xG,size:[n,n,i*.9],center:[t,e,A(-i/2*.9)]}),De(Xt,{color:xG,size:[n/1.8,n/1.8,i],center:[t,e,A(-i/2)]})]})})})})]}),Ben=({numberOfPins:t,pitch:e=2.54,longSidePinLength:n=6,invert:o,rows:i=1,smd:r,rightangle:s})=>{const c=Math.ceil(t/i),l=2.54,g=3,u=-((c-1)/2)*e,d=!r&&!s?!o:!!o,m=p=>d?-p+2:p;return De(fi,{children:Array.from({length:t},(p,_)=>{const f=Math.floor(_/c),I=_%c,C=u+I*e,y=((i-1)/2-f)*l;return De(Een,{x:C,y,pinThickness:.63,shortSidePinLength:g,longSidePinLength:n,bodyHeight:2,flipZ:m,smd:r,rightangle:s},_)})})};function Ggi(t){const{num_pins:e,bodyWidth:n,bodyLength:o,bodyHeight:i,standoff:r,terminalSpanX:s,terminalSpanY:a,terminalThickness:A,padWidth:c,padLength:l,pitch:g,exposedPadWidth:u,exposedPadLength:h}=t;for(const _ of["bodyWidth","bodyLength","bodyHeight","terminalSpanX","terminalSpanY","terminalThickness","padWidth","padLength","pitch","exposedPadWidth","exposedPadLength"])if(!Number.isFinite(t[_])||t[_]<=0)throw new Error(`${_} must be finite and positive`);if(!Number.isInteger(e)||e<8||e%4)throw new Error("num_pins must be divisible by four and at least eight");if(!Number.isFinite(r)||r<0)throw new Error("standoff must be finite and nonnegative");const d=(e/4-1)*g+c;if(A<=r||A>=i||c>=g||d>=Math.min(n,o))throw new Error("Invalid mold, terminal thickness or spacing");if(s<n||a<o||s/2-l>=n/2||a/2-l>=o/2||u>=Math.min(n,s-2*l)||h>=Math.min(o,a-2*l)||d>=Math.min(s,a)-2*l)throw new Error("Terminals must enter the mold and clear the exposed pad and corners");const m=De(Fo,{z:(i+r)/2,children:De(Xt,{size:[n,o,i-r]})}),p=Math.min(n,o)*.035;return Bn(fi,{children:[De(zo,{color:"#353535",children:Bn(Hl,{children:[m,De(Fo,{offset:{x:-n/2+p*2,y:o/2-p*2,z:i},children:De(Qs,{radius:p,height:Math.min(.06,(i-r)/5)})})]})}),De(zo,{color:"#bfc1c4",children:Array.from({length:e},(_,f)=>{const I=Math.floor(f/(e/4)),C=((e/4-1)/2-f%(e/4))*g,y=I%2===0,x=I<2?-1:1,E=((y?s:a)-l)/2*x;return De(Fo,{offset:{x:y?E:C,y:y?C:E,z:A/2},children:De(Xt,{size:y?[l,c,A]:[c,l,A]})},f)})}),De(zo,{color:"#bfc1c4",children:De(Fo,{z:A/2,children:De(Xt,{size:[u,h,A]})})})]})}var Ygi=t=>{const e=["left","bottom","right","top"],{pin_count:n,pn:o,w:i,h:r,p:s,pl:a}=t,A=n/4,c=e[Math.floor((o-1)/A)],l=(o-1)%A,g=s*(A-1),u=s*(A-1),h=-a/2;switch(c){case"left":return{x:-i/2-h,y:u/2-l*s,o:"vert"};case"bottom":return{x:-g/2+l*s,y:-r/2-h,o:"horz"};case"right":return{x:i/2+h,y:-u/2+l*s,o:"vert"};case"top":return{x:g/2-l*s,y:r/2+h,o:"horz"};default:throw new Error("Invalid pin number")}},Ugi=({num_pins:t,cw:e,ccw:n,startingpin:o})=>{const i=[],r=t/4;let s=1;const a={};for(const A of o??[])a[A]=!0;!a.leftside&&!a.topside&&!a.rightside&&!a.bottomside&&(a.leftside=!0),!a.bottompin&&!a.leftpin&&!a.rightpin&&!a.toppin&&(a.leftside?a.toppin=!0:a.topside?a.rightpin=!0:a.rightside?a.bottompin=!0:a.bottomside&&(a.leftpin=!0)),a.leftside&&a.toppin?s=1:a.leftside&&a.bottompin?s=r:a.bottomside&&a.leftpin?s=r+1:a.bottomside&&a.rightpin?s=r*2:a.rightside&&a.bottompin?s=r*2+1:a.rightside&&a.toppin?s=r*3:a.topside&&a.rightpin?s=r*3+1:a.topside&&a.leftpin&&(s=r*4),i.push(-1);for(let A=0;A<t;A++)i[s]=A+1,s++,s>t&&(s=1);return i},Kgi=({num_pins:t=16,bodyWidth:e=9,bodyLength:n=9,bodyThickness:o=.8,thermalPadSize:i,padWidth:r=.25,padLength:s=.25,pitch:a=.5,thermalPadThickness:A=.05})=>{const c=Ugi({num_pins:t,cw:!0,ccw:!0}),l=[];for(let g=0;g<t;g++){const{x:u,y:h,o:d}=Ygi({pin_count:t,pn:g+1,w:e,h:n,p:a,pl:s});let m=r,p=s;d==="vert"&&([m,p]=[p,m]);const _=c[g+1];l.push({pn:_,x:u,y:h,pw:m,pl:p})}return Bn(fi,{children:[De(zo,{color:"grey",children:De(Xt,{center:[0,0,o/2],size:[e,n,o]})}),l.map((g,u)=>De(Xt,{center:[g.x,g.y,A/2],size:[g.pw,g.pl,A]})),i?.length!==void 0&&i?.width!==void 0&&De(Xt,{center:[0,0,A/2],size:[i.width,i.length,A]})]})},Vgi=t=>"bodyHeight"in t?Ggi(t):Kgi(t),Sen=Vgi,zgi=()=>{const A=1.1999999999999997;return Bn(fi,{children:[De($r,{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}),De($r,{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}),De($r,{position:{x:-2.8/2-A/4,y:0,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:A,height:.95}),De($r,{position:{x:-2.8/2-A/4,y:-1,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:A,height:.95}),De($r,{position:{x:-2.8/2-A/4,y:1,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:A,height:.95}),De(Kg,{center:{x:0,y:0,z:0},width:1.6,length:2.9,height:1.2})]})},ben=zgi,Jgi=({fullWidth:t=2.9,fullLength:e=2.8,color:n}={})=>{const g=(t-1.3)/2+.3;return Bn(fi,{children:[De($r,{position:{x:-t/2,y:.95,z:.075},width:.4,thickness:.15,padContactLength:.4,bodyDistance:g,height:.95}),De($r,{position:{x:-t/2,y:-.95,z:.075},width:.4,thickness:.15,padContactLength:.4,bodyDistance:g,height:.95}),De($r,{rotation:Math.PI,position:{x:t/2,y:0,z:.075},width:.4,thickness:.15,padContactLength:.4,bodyDistance:g,height:.95}),De(Kg,{center:{x:0,y:0,z:0},width:1.3,length:2.9,height:1.1,color:n})]})},Wgi=({fullWidth:t=2.9,fullLength:e=2.8})=>{const l=(t-1.92)/2+.3;return Bn(fi,{children:[De($r,{rotation:Math.PI,position:{x:t/2,y:0,z:.075},width:.4,thickness:.15,padContactLength:.25,bodyDistance:l,height:.45}),De($r,{position:{x:-t/2,y:-.95,z:.075},width:.4,thickness:.15,padContactLength:.25,bodyDistance:l,height:.45}),De($r,{position:{x:-t/2,y:.95,z:.075},width:.4,thickness:.15,padContactLength:.25,bodyDistance:l,height:.45}),De(Kg,{center:{x:0,y:0,z:0},width:1.92,length:2.9,height:1.1,straightHeightRatio:.45,heightAboveSurface:.05})]})},QYe=.6,vYe=.3,EG=.33,zX=.1,jgi=QYe-zX*2,Qen=({color:t="#333"})=>Bn(fi,{children:[De(Xt,{size:[jgi,vYe,EG],offset:[0,0,EG/2],color:t}),De(Xt,{size:[zX,vYe,EG],offset:[QYe/2-zX/2,0,EG/2],color:"#ccc"}),De(Xt,{size:[zX,vYe,EG],offset:[-QYe/2+zX/2,0,EG/2],color:"#ccc"})]}),PYe=.4,wYe=.2,BG=.13,JX=.07,Xgi=PYe-JX*2,ven=({color:t="#333"})=>Bn(fi,{children:[De(Xt,{size:[Xgi,wYe,BG],offset:[0,0,BG/2],color:t}),De(Xt,{size:[JX,wYe,BG],offset:[PYe/2-JX/2,0,BG/2],color:"#ccc"}),De(Xt,{size:[JX,wYe,BG],offset:[-PYe/2+JX/2,0,BG/2],color:"#ccc"})]}),MYe=3.2,DYe=1.6,SG=.9,WX=.5,qgi=MYe-WX*2,Pen=({color:t="#333"})=>Bn(fi,{children:[De(Xt,{size:[qgi,DYe,SG],offset:[0,0,SG/2],color:t}),De(Xt,{size:[WX,DYe,SG],offset:[MYe/2-WX/2,0,SG/2],color:"#ccc"}),De(Xt,{size:[WX,DYe,SG],offset:[-MYe/2+WX/2,0,SG/2],color:"#ccc"})]}),NYe=3.2,RYe=2.5,bG=1,jX=.6,$gi=NYe-jX*2,wen=({color:t="#333"})=>Bn(fi,{children:[De(Xt,{size:[$gi,RYe,bG],offset:[0,0,bG/2],color:t}),De(Xt,{size:[jX,RYe,bG],offset:[NYe/2-jX/2,0,bG/2],color:"#ccc"}),De(Xt,{size:[jX,RYe,bG],offset:[-NYe/2+jX/2,0,bG/2],color:"#ccc"})]}),TYe=5,kYe=2.5,QG=1.4,XX=.6,Zgi=TYe-XX*2,Men=({color:t="#333"})=>Bn(fi,{children:[De(Xt,{size:[Zgi,kYe,QG],offset:[0,0,QG/2],color:t}),De(Xt,{size:[XX,kYe,QG],offset:[TYe/2-XX/2,0,QG/2],color:"#ccc"}),De(Xt,{size:[XX,kYe,QG],offset:[-TYe/2+XX/2,0,QG/2],color:"#ccc"})]}),FYe=6.3,LYe=3.2,vG=1.8,qX=.8,eui=FYe-qX*2,Den=({color:t="#333"})=>Bn(fi,{children:[De(Xt,{size:[eui,LYe,vG],offset:[0,0,vG/2],color:t}),De(Xt,{size:[qX,LYe,vG],offset:[FYe/2-qX/2,0,vG/2],color:"#ccc"}),De(Xt,{size:[qX,LYe,vG],offset:[-FYe/2+qX/2,0,vG/2],color:"#ccc"})]}),Nen=({x:t,y:e,z:n=0,pitch:o=2.54,legsLength:i=3,innerDiameter:r=.945,bodyHeight:s=5,bodyLength:a=o,bodyWidth:A=o,flipZ:c})=>{const l=r||.945,g=l/1.5,u=l,h=u*1.8,d=Math.min(s*.18,o*.24),m=s+.1,p=c(n+m/2),_=n+s-d,f=g*1.6;return Bn(fi,{children:[De(zo,{color:"#1a1a1a",children:Bn(Hl,{children:[De(Xt,{color:"#000",size:[a,A,s],center:[t,e,c(n+s/2)]}),De(Xt,{size:[u,u,m],center:[t,e,p]}),Bn(KA,{children:[De(Xt,{size:[u,u,.01],center:[t,e,c(_)]}),De(Xt,{size:[h,h,.01],center:[t,e,c(n+s)]})]})]})}),Bn(zo,{color:"silver",children:[Bn(KA,{children:[De(Xt,{color:"silver",size:[g,g,i*.9],center:[t,e,c(n+-i/2*.9)]}),De(Xt,{color:"silver",size:[g/1.8,g/1.8,i],center:[t,e,c(n+-i/2)]})]}),De(Xt,{color:"silver",size:[f,f,f*.5],center:[t,e,c(n+f/2*.5)]})]})]})},tui=({numberOfPins:t,pitch:e=2.54,legsLength:n=3,innerDiameter:o=.945,rows:i=1,invert:r})=>{const a=Math.ceil(t/i),A=2.54,c=-((a-1)/2)*e,l=g=>r?-g+5:g;return De(fi,{children:Array.from({length:t},(g,u)=>{const h=Math.floor(u/a),d=u%a,m=c+d*e,p=((i-1)/2-h)*A;return De(Nen,{x:m,y:p,pitch:e,legsLength:n,innerDiameter:o,flipZ:l},u)})})},nui=({width:t,length:e,innerDiameter:n=1})=>{const o=t,i=e,r=t*.7,s=n/2.5;return Bn(fi,{children:[De(Gf,{color:"#1a1a1f",center:[0,0,r/2],size:[i,i,r],roundRadius:.3}),De(Gf,{color:"#f2f2f2",center:[0,0,r+r*.1/2.5],size:[i,i,r*.1],roundRadius:.14}),De(Qs,{color:"#1a1a1f",height:r*.8,radius:o/3,center:[0,0,r+r*.8/2]}),De(Qs,{color:"#1a1a1f",height:r*.2,radius:n/2,center:[i/3,i/3,r+r*.1/2]}),De(Qs,{color:"#1a1a1f",height:r*.2,radius:n/2,center:[-i/3,-i/3,r+r*.1/2]}),De(Qs,{color:"#1a1a1f",height:r*.2,radius:n/2,center:[-i/3,i/3,r+r*.1/2]}),De(Qs,{color:"#1a1a1f",height:r*.2,radius:n/2,center:[i/3,-i/3,r+r*.1/2]}),De(Lue,{thickness:n/3,width:s,horizontalLength:i*.8,verticalLength:r/2,position:{x:-o/2,y:-i/2,z:-r*1.2}}),De(Lue,{thickness:n/3,width:s,horizontalLength:i*.8,verticalLength:r/2,position:{x:-o/2,y:i/2,z:-r*1.2},rotation:Math.PI}),De(Lue,{thickness:n/3,width:s,horizontalLength:i*.8,verticalLength:r/2,position:{x:o/2,y:i/2,z:-r*1.2},rotation:Math.PI}),De(Lue,{thickness:n/3,width:s,horizontalLength:i*.8,verticalLength:r/2,position:{x:o/2+n/3.6,y:-i/2,z:-r*1.2}})]})},Lue=t=>{const{thickness:e,width:n,horizontalLength:o,verticalLength:i,rotation:r=0,position:s}=t,a=[[0,o],[-i/3,o/3],[-i/5,o/4],[0,0]],A=CYe(a,e);return De(zo,{color:"#f2f2f2",children:De(Fo,{offset:{x:s?.x||0,y:s?.y||0,z:s?.z||0},children:De($A,{rotation:[0,55,r],children:De(fG,{height:n,children:De(_G,{points:A.map(c=>[c.y,c.x])})})})})})},oui=({pinCount:t,leadLength:e,leadWidth:n,pitch:o,bodyWidth:i})=>{const r=Math.ceil(t/2),s=(r-1)*o/2,a=.25,A=1,c=.8,l=e*0,g=o*(r-1)+n+.2,u=i*.55;return Bn(fi,{children:[Array.from({length:r}).map((h,d)=>De($r,{position:{x:-i/2-l,y:d*o-s,z:a/2},width:n,thickness:a,padContactLength:e/2,bodyDistance:e+.3,height:c})),Array.from({length:r}).map((h,d)=>De($r,{rotation:Math.PI,position:{x:i/2+l,y:d*o-s,z:a/2},width:n,thickness:a,padContactLength:e/2,bodyDistance:e+.3,height:c})),De(Kg,{center:{x:0,y:0,z:a/2},width:u,length:g,height:A})]})},iui=t=>"leadSpan"in t?Tue(t):oui(t),rui=({pinCount:t,pitch:e,leadWidth:n,leadLength:o,bodyWidth:i,bodyLength:r})=>{const s=t===8?{pitch:.65,leadWidth:.3}:{pitch:.5,leadWidth:.225},a=isNaN(parseFloat(e))?s.pitch:parseFloat(e),A=isNaN(parseFloat(n))?s.leadWidth:parseFloat(n)*.8,c=isNaN(parseFloat(i))?2.6:parseFloat(i)*.8,l=isNaN(parseFloat(r))?2+Number(a)*1.4:parseFloat(r),g=t/2,u=(g-1)*a/2,h=.15,d=.8,m=4.5,p=(m-c)/2,_=p*.5;return Bn(fi,{children:[Array.from({length:g}).map((f,I)=>De($r,{position:{x:-m/2,y:u-I*a,z:h/2},width:A,thickness:h,padContactLength:_+.05,bodyDistance:p+.1,height:d})),Array.from({length:g}).map((f,I)=>De($r,{rotation:Math.PI,position:{x:m/2,y:u-I*a,z:h/2},width:A,thickness:h,padContactLength:_+.05,bodyDistance:p+.1,height:d})),De(Kg,{center:{x:0,y:0,z:h/2},width:c,length:l,height:1})]})},sui=()=>Bn(fi,{children:[De(Xt,{color:"#ccc",size:[.5,.6,.12],center:[-.725,0,.12/2]}),De(Xt,{color:"#ccc",size:[.5,.6,.12],center:[.725,0,.12/2]}),De(zo,{color:"#222",children:Bn(zd,{children:[De(Fo,{z:.3/2,children:De(Xt,{size:[1.65,.8,.3]})}),Bn(KA,{children:[De(Fo,{z:.3,children:De(Xt,{size:[1.65,.8,.01]})}),De(Fo,{z:.6,children:De(Xt,{size:[1.65-.2,.8-.2,.01]})})]})]})})]}),Ren=()=>Bn(fi,{children:[De(Xt,{color:"#ccc",size:[.26,.51,.12],center:[-.325,0,.12/2]}),De(Xt,{color:"#ccc",size:[.26,.51,.12],center:[.325,0,.12/2]}),De(zo,{color:"#222",children:De(Fo,{z:.47/2+.02,children:De(Xt,{size:[.98,.58,.47]})})}),De(Xt,{color:"#ccc",size:[.98+.001,.26/2,.26/4],center:[0,.26/2,.47/4]}),De(Xt,{color:"#ccc",size:[.98+.001,.26/2,.26/4],center:[0,-.26/2,.47/4]}),De(Xt,{color:"#ccc",size:[.26/1.5,.58+.001,.26/4],center:[.65/2,0,.47/4]}),De(Xt,{color:"#ccc",size:[.26/1.5,.58+.001,.26/4],center:[-.65/2,0,.47/4]})]}),aui=()=>{const c=De(zo,{color:"#1a1a1a",children:Bn(zd,{children:[Bn(KA,{children:[De(Fo,{z:.13,children:De(Xt,{size:[4,3,.03]})}),De(Fo,{z:1.15,children:De(Xt,{size:[4.4,3.4,.01]})})]}),Bn(KA,{children:[De(Fo,{z:1.15,children:De(Xt,{size:[4.4,3.4,.01]})}),De(Fo,{z:2.3,children:De(Xt,{size:[4,3,.01]})})]})]})}),l=({xDir:g})=>{const d=g*1.78,m=g*(3.4/2-.2/2+1),p=g*(3.4/2-.2/2),_=Math.abs(p-m),f=(m+p)/2;return De(zo,{color:"#c0c0c0",children:Bn(zd,{children:[De(Xt,{size:[2.3*.8,1.45,.2],center:[d,0,.2/2]}),De(Xt,{size:[.2,1.45,1.14],center:[m,0,1.14/2+.2]}),De(Xt,{size:[_,1.45,.2],center:[f,0,.2/2+1.14]})]})})};return Bn(fi,{children:[De(l,{xDir:1}),De(l,{xDir:-1}),c]})},Ten=()=>{const c=De(zo,{color:"#1a1a1a",children:Bn(zd,{children:[Bn(KA,{children:[De(Fo,{z:.13,children:De(Xt,{size:[4.199999999999999,3.6,.03]})}),De(Fo,{z:1.15,children:De(Xt,{size:[4.6,4,.01]})})]}),Bn(KA,{children:[De(Fo,{z:1.15,children:De(Xt,{size:[4.6,4,.01]})}),De(Fo,{z:2.3,children:De(Xt,{size:[4.199999999999999,3.6,.01]})})]})]})}),l=({xDir:g})=>{const d=g*2.08,m=g*(4/2-.2/2+1),p=g*(4/2-.2/2),_=Math.abs(p-m),f=(m+p)/2;return De(zo,{color:"#c0c0c0",children:Bn(zd,{children:[De(Xt,{size:[2.3*.8,1.45,.2],center:[d,0,.2/2]}),De(Xt,{size:[.2,1.45,1.14],center:[m,0,1.14/2+.2]}),De(Xt,{size:[_,1.45,.2],center:[f,0,.2/2+1.14]})]})})};return Bn(fi,{children:[De(l,{xDir:1}),De(l,{xDir:-1}),c]})},Aui=()=>{const c=De(zo,{color:"#1a1a1a",children:Bn(zd,{children:[Bn(KA,{children:[De(Fo,{z:.21000000000000002,children:De(Xt,{size:[6.3999999999999995,5.6,.03]})}),De(Fo,{z:1.15,children:De(Xt,{size:[6.8,6,.01]})})]}),Bn(KA,{children:[De(Fo,{z:1.15,children:De(Xt,{size:[6.8,6,.01]})}),De(Fo,{z:2.3,children:De(Xt,{size:[6.3999999999999995,5.6,.01]})})]})]})}),l=({xDir:g})=>{const d=g*3.08,m=g*(6/2-.2/2+1),p=g*(6/2-.2/2),_=Math.abs(p-m),f=(m+p)/2;return De(zo,{color:"#c0c0c0",children:Bn(zd,{children:[De(Xt,{size:[2.3*.8,2.95,.2],center:[d,0,.2/2]}),De(Xt,{size:[.2,2.95,1.14],center:[m,0,1.14/2+.2]}),De(Xt,{size:[_,2.95,.2],center:[f,0,.2/2+1.14]})]})})};return Bn(fi,{children:[De(l,{xDir:1}),De(l,{xDir:-1}),c]})},cui=()=>{const g=De(zo,{color:"#222",children:Bn(zd,{children:[De(Fo,{z:.27,children:De(Xt,{size:[2.9,1.9,.54]})}),Bn(KA,{children:[De(Fo,{z:.54,children:De(Xt,{size:[2.9,1.9,.01]})}),De(Fo,{z:1.08,children:De(Xt,{size:[2.6999999999999997,1.7,.01]})})]})]})});return Bn(fi,{children:[De(Xt,{color:"#ccc",size:[1,1.2,.25],center:[-1.3,0,.25/2]}),De(Xt,{color:"#ccc",size:[1,1.2,.25],center:[1.3,0,.25/2]}),g]})},lui=()=>Bn(fi,{children:[De(Xt,{color:"#ccc",size:[1,.6,.12],center:[-1.3,0,.12/2]}),De(Xt,{color:"#ccc",size:[1,.6,.12],center:[1.3,0,.12/2]}),De(zo,{color:"#222",children:Bn(zd,{children:[De(Fo,{z:.55/2,children:De(Xt,{size:[2.7,1.6,.55]})}),Bn(KA,{children:[De(Fo,{z:.55,children:De(Xt,{size:[2.7,1.6,.01]})}),De(Fo,{z:1.1,children:De(Xt,{size:[2.7-.2,1.6-.2,.01]})})]})]})})]}),gui=()=>Bn(fi,{children:[De(Xt,{color:"#ccc",size:[1,.9,.2],center:[-1.3,0,.2/2]}),De(Xt,{color:"#ccc",size:[1,.9,.2],center:[1.3,0,.2/2]}),De(zo,{color:"#222",children:Bn(zd,{children:[De(Fo,{z:.2/2,children:De(Xt,{size:[2.75,1.8,.2]})}),Bn(KA,{children:[De(Fo,{z:.2,children:De(Xt,{size:[2.75,1.8,.01]})}),De(Fo,{z:1,children:De(Xt,{size:[2.75-.4,1.8-.4,.01]})})]})]})}),De(Xt,{color:"#777",size:[.2,1.8-.4,.01],center:[-1.3+.4,0,1]})]}),ken=({bodyWidth:t=2.6,bodyLength:e=1.7,bodyHeight:n=1}={})=>{const o=t,i=e*.53,r=t*.35,s=.2,a=-(o/2-.075),A=o/2-.075,c=.4,l=.1,g=n*.2;return Bn(fi,{children:[De(Xt,{color:"#ccc",size:[r,i,s],center:[a,0,s/2]}),De(Xt,{color:"#ccc",size:[r,i,s],center:[A,0,s/2]}),De(zo,{color:"#222",children:Bn(zd,{children:[Bn(KA,{children:[De(Fo,{z:g,children:De(Xt,{size:[o-l/2,e-l/2,.01]})}),De(Fo,{z:.01,children:De(Xt,{size:[o-l,e-l,.01]})})]}),Bn(KA,{children:[De(Fo,{z:g,children:De(Xt,{size:[o,e,.01]})}),De(Fo,{z:n,children:De(Xt,{size:[o-c,e-c,.01]})})]})]})}),De(Xt,{color:"#777",size:[s*2.7,e-c,.02],center:[a+c,0,n]})]})},uui=({fullWidth:t=3.7,fullLength:e=1.55}={})=>{const n=t-1,o=e,i=1.175,r=.1,s=i-r,a=.55,A=.12,c=.35,l=(t-n)/2,g=.25,u=.2;return Bn(fi,{children:[De($r,{position:{x:-t/2,y:0,z:A/2},width:a,thickness:A,padContactLength:g,bodyDistance:l,curveLength:u,height:c}),De($r,{rotation:Math.PI,position:{x:t/2,y:0,z:A/2},width:a,thickness:A,padContactLength:g,bodyDistance:l,curveLength:u,height:c}),De(Kg,{center:{x:0,y:0,z:0},width:n,length:o,height:s,heightAboveSurface:r,includeNotch:!1,color:"#222",taperRatio:.06,straightHeightRatio:.6}),De(Xt,{color:"#777",size:[.45,o-.15,.02],center:[-n/4,0,i]})]})},dui=()=>Bn(fi,{children:[De(Xt,{color:"#ccc",size:[.9,1.75,.2],center:[-1.825,0,.2/2]}),De(Xt,{color:"#ccc",size:[.9,1.75,.2],center:[1.825,0,.2/2]}),De(zo,{color:"#222",children:Bn(zd,{children:[Bn(KA,{children:[De(Fo,{z:.2,children:De(Xt,{size:[3.8-.05/2,2.5-.05/2,.01]})}),De(Fo,{z:.01,children:De(Xt,{size:[3.8-.05,2.5-.05,.01]})})]}),Bn(KA,{children:[De(Fo,{z:.2,children:De(Xt,{size:[3.8,2.5,.01]})}),De(Fo,{z:1,children:De(Xt,{size:[3.8-.4,2.5-.4,.01]})})]})]})}),De(Xt,{color:"#777",size:[.2*2.7,2.5-.4,.02],center:[-1.825+.4,0,1]})]}),hui=()=>Bn(fi,{children:[De(Xt,{color:"#ccc",size:[.4,.25,.14],center:[-.4,0,.14/2]}),De(Xt,{color:"#ccc",size:[.4,.25,.14],center:[.4,0,.14/2]}),De(zo,{color:"#222",children:Bn(zd,{children:[De(Fo,{z:.14/2,children:De(Xt,{size:[.8,.6,.14]})}),Bn(KA,{children:[De(Fo,{z:.14,children:De(Xt,{size:[.8,.6,.01]})}),De(Fo,{z:.37,children:De(Xt,{size:[.8-.1,.6-.1,.01]})})]})]})})]}),Fen=({fullWidth:t=6.6,bodyWidth:e=3.5,bodyLength:n=6.5,bodyHeight:o=1.7,leadWidth:i=.7,tabLeadWidth:r=3,padPitch:s=2.3,leadHeight:a=.75}={})=>{const A=r,c=.25,l=.5,g=t-e;return Bn(fi,{children:[De($r,{rotation:Math.PI,position:{x:t/2+g/4,y:0,z:c/2},width:A,thickness:c,padContactLength:l,bodyDistance:g,height:a}),De($r,{position:{x:-t/2-g/4,y:0,z:c/2},width:i,thickness:c,padContactLength:l,bodyDistance:g,height:a}),De($r,{position:{x:-t/2-g/4,y:-s,z:c/2},width:i,thickness:c,padContactLength:l,bodyDistance:g,height:a}),De($r,{position:{x:-t/2-g/4,y:s,z:c/2},width:i,thickness:c,padContactLength:l,bodyDistance:g,height:a}),De(Kg,{center:{x:0,y:0,z:0},width:e,length:n,height:o,includeNotch:!1,taperRatio:.06,straightHeightRatio:.45})]})},mui=()=>Bn(fi,{children:[Array.from({length:16}).map((h,d)=>De($r,{position:{x:-10.5/2,y:d*.5-3.75,z:.25/2},width:.2,thickness:.25,padContactLength:.45,bodyDistance:.95,height:.65})),Array.from({length:16}).map((h,d)=>De($r,{rotation:Math.PI,position:{x:10.5/2,y:d*.5-3.75,z:.25/2},width:.2,thickness:.25,padContactLength:.45,bodyDistance:.95,height:.65})),Array.from({length:16}).map((h,d)=>De($r,{rotation:Math.PI/2,position:{x:d*.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((h,d)=>De($r,{rotation:-Math.PI/2,position:{x:d*.5-3.75,y:10.5/2,z:.25/2},width:.2,thickness:.25,padContactLength:.45,bodyDistance:.95,height:.65})),De(Kg,{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})]}),pui=mui,_ui=()=>{const c=.7999999999999998;return Bn(fi,{children:[De($r,{rotation:Math.PI,position:{x:2.05/2+c/4,y:0,z:.18/2},width:.3,thickness:.18,padContactLength:.2,bodyDistance:c,height:.65}),De($r,{position:{x:-2.05/2-c/4,y:-.65,z:.18/2},width:.3,thickness:.18,padContactLength:.2,bodyDistance:c,height:.65}),De($r,{position:{x:-2.05/2-c/4,y:.65,z:.18/2},width:.3,thickness:.18,padContactLength:.2,bodyDistance:c,height:.65}),De(Kg,{center:{x:0,y:0,z:0},width:1.25,length:2,height:.9,includeNotch:!1,taperRatio:.06,straightHeightRatio:.7,heightAboveSurface:.05})]})};function fui(t){const{pinCount:e,pitch:n,bodyWidth:o,bodyLength:i,bodyHeight:r,standoff:s,leadSpanX:a,leadSpanY:A,leadWidth:c,leadThickness:l,contactLength:g,taperInset:u}=t;for(const x of["pitch","bodyWidth","bodyLength","bodyHeight","leadSpanX","leadSpanY","leadWidth","leadThickness","contactLength"])if(!Number.isFinite(t[x])||t[x]<=0)throw new Error(`${x} must be finite and positive`);for(const[x,E]of Object.entries({standoff:s,taperInset:u}))if(!Number.isFinite(E)||E<0)throw new Error(`${x} must be finite and nonnegative`);if(!Number.isInteger(e)||e<8||e%4)throw new Error("pinCount must be divisible by four and at least eight");const h=r-s,d=Math.min(a-o,A-i)/2,m=(e/4-1)*n+c;if(h<=l*2||c>=n||m>=Math.min(o,i)-2*u||u*2>=Math.min(o,i)||g>=d)throw new Error("Invalid mold, lead spacing, or terminal reach");const p=s+h/2,_=Math.min(.002,h/100),f=Bn(KA,{children:[De(Fo,{z:s+_/2,children:De(Xt,{size:[o-2*u,i-2*u,_]})}),De(Fo,{z:p,children:De(Xt,{size:[o,i,_]})}),De(Fo,{z:r-_/2,children:De(Xt,{size:[o-2*u,i-2*u,_]})})]}),I=Math.min(o,i)*.045,C=Math.min(.04,h/10),y=(x,E)=>{const B=x%2===0,b=x<2?-1:1,Q=B?o:i,w=(B?a:A)/2,D=Q/2-Math.min(Q/8,.15),k=w-g,T=Q/2+Math.min(.08,(d-g)/4),H=[[w-_/2,l/2],[k,l/2]];for(let U=1;U<=12;U++){const Y=U/12;H.push([k+(T-k)*Y,l/2+(p-l/2)*Y*Y*(3-2*Y)])}H.push([D,p]);const G=([U,Y])=>De(Fo,{offset:{x:B?b*U:E,y:B?E:b*U,z:Y},children:De(Xt,{size:B?[_,c,l]:[c,_,l]})});return De(zd,{children:H.slice(1).map((U,Y)=>Bn(KA,{children:[G(H[Y]),G(U)]}))})};return Bn(fi,{children:[De(zo,{color:"#353535",children:Bn(Hl,{children:[f,De(Fo,{offset:{x:-o/2+u+I*2,y:i/2-u-I*2,z:r},children:De(Qs,{radius:I,height:C*2})})]})}),De(zo,{color:"#bfc1c4",children:Array.from({length:e},(x,E)=>y(Math.floor(E/(e/4)),((e/4-1)/2-E%(e/4))*n))})]})}var Iui=({pinCount:t,pitch:e,leadWidth:n,padContactLength:o,bodyWidth:i})=>{const r=t/4;if(r!==Math.floor(r))throw new Error(`LQFP pinCount must be divisible by 4, got ${t}`);e||(e=.5),o||(o=.6),n||(n=.22),i||(i=e*(r+4));const s=i,a=(r-1)*e/2,A=s+3.3*o,c=A,l=.8,g=.2,u=(c-i)/2+.4;return Bn(fi,{children:[Array.from({length:r}).map((h,d)=>De($r,{position:{x:-c/2-.36,y:d*e-a,z:g/2},width:n,thickness:g,padContactLength:o,bodyDistance:u,height:l})),Array.from({length:r}).map((h,d)=>De($r,{rotation:Math.PI,position:{x:c/2+.36,y:d*e-a,z:g/2},width:n,thickness:g,padContactLength:o,bodyDistance:u,height:l})),Array.from({length:r}).map((h,d)=>De($r,{rotation:Math.PI/2,position:{x:d*e-a,y:-A/2-.36,z:g/2},width:n,thickness:g,padContactLength:o,bodyDistance:u,height:l})),Array.from({length:r}).map((h,d)=>De($r,{rotation:-Math.PI/2,position:{x:d*e-a,y:A/2+.36,z:g/2},width:n,thickness:g,padContactLength:o,bodyDistance:u,height:l})),De(Kg,{center:{x:0,y:0,z:0},width:i,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})]})},Cui=t=>"leadSpanX"in t?fui(t):Iui(t),yui=()=>{const o=.20900000000000002,i=.1,r=.3,s=.1,a=.2;return Bn(fi,{children:[De(zo,{color:"#222",children:Bn(zd,{children:[De(Xt,{size:[.85,1.2,o],center:[0,0,o/2]}),Bn(KA,{children:[De(Fo,{z:o,children:De(Xt,{size:[.85,1.2,.01]})}),De(Fo,{z:.38,children:De(Xt,{size:[.85-i,1.2-i,.01]})})]})]})}),De(Xt,{color:"#ccc",size:[r,.25,s],center:[.55,0,s/2]}),De(Xt,{color:"#ccc",size:[r,a,s],center:[-.55,.4,s/2]}),De(Xt,{color:"#ccc",size:[r,a,s],center:[-.55,-.4,s/2]})]})},Len=({num_pins:t,bodyWidth:e=5.3,bodyLength:n=5.3,bodyThickness:o=1,thermalPadSize:i,padWidth:r=n/5.3*.6,padLength:s=n/5.3*1,pitch:a=.5,thermalPadThickness:A=.2,bodyStyle:c="chamfered",standoff:l=0,terminalInset:g=0,terminalThickness:u=A,pin1TerminalChamfer:h=0,pin1MarkWidth:d=0})=>{if(c==="rectangular"){if(!Number.isInteger(t)||t<2||t%2!==0)throw new Error("DFN requires an even pin count of at least two");for(const f of[e,n,o,r,s,a,u])if(!Number.isFinite(f)||f<=0)throw new Error("DFN dimensions must be finite and positive");for(const f of[l,g,h,d])if(!Number.isFinite(f)||f<0)throw new Error("DFN offsets must be finite and nonnegative");if(u<=l||u>l+o||g+s>=e/2||(t/2-1)*a+r>n||t>2&&r>=a||h>=Math.min(s,r/2)||d>=e/4)throw new Error("DFN dimensions leave disconnected or overlapping terminals")}const m=[],p=Math.floor(t/2),_=a*(p-1);for(let f=0;f<t;f++){const I=f<p?"left":"right",C=f%p,y=_/2-C*a,x=s,E=r,B=I==="left"?-e/2+x/2+g:e/2-x/2-g,b=f+1;m.push({pinNumber:b,x:B,y,padSizeX:x,padSizeY:E})}if(c==="rectangular"){const f=l+o,I=Math.min(o,n)/100,C=De(Xt,{size:[d,n*.8,I],center:[-e/2+d*1.5,0,f-I/2]}),y=De(Xt,{size:[e,n,o],center:[0,0,l+o/2]});return Bn(fi,{children:[De(zo,{color:"#25272a",children:d>0?Bn(Hl,{children:[y,C]}):y}),De(zo,{color:"#c7c9cd",children:m.map(x=>x.pinNumber===1&&h>0?Bn(KA,{children:[De(Xt,{size:[s-h,r,u],center:[x.x+h/2,x.y,u/2]}),De(Xt,{size:[s,r-2*h,u],center:[x.x,x.y,u/2]})]},x.pinNumber):De(Xt,{size:[x.padSizeX,x.padSizeY,u],center:[x.x,x.y,u/2]},x.pinNumber))}),i&&De(Xt,{color:"#c7c9cd",size:[i.width,i.length,A],center:[0,0,A/2]}),d>0&&De(zo,{color:"#969997",children:C})]})}return Bn(fi,{children:[De(Kg,{center:{x:0,y:0,z:0},width:e,length:n,height:o,heightAboveSurface:0,color:"grey",chamferSize:.2,taperRatio:0,notchPosition:{x:-(e/2-s),y:n/2-s,z:o}}),m.map((f,I)=>De(Xt,{center:[f.x,f.y,A/2],size:[f.padSizeX,f.padSizeY,A]})),i?.length!==void 0&&i?.width!==void 0&&De(Xt,{center:[0,0,A/2],size:[i.width,i.length,A]})]})},xui=({bodyLength:t=10.2,bodyWidth:e=4.65,bodyHeight:n=13.46,leadSpacing:o=5,leadDiameter:i=.8,leadLength:r=12.7,color:s="#ddd",leadColor:a="#b87333"})=>{const A=t/2,c=e/2,l=A-c,g=o/2,u=.85;return Bn(fi,{children:[Bn(zo,{color:s,children:[Bn(KA,{children:[De(Ny,{height:n,roundRadius:.5,radius:c,center:[-l,0,n]}),De(Ny,{height:n,roundRadius:.5,radius:c,center:[l,0,n]})]}),Bn(KA,{children:[De(Ny,{height:u,roundRadius:.1,radius:c+.85,center:[-l,0,n/2+u/2]}),De(Ny,{height:u,roundRadius:.1,radius:c+.85,center:[l,0,n/2+u/2]})]})]}),Bn(zo,{color:a,children:[De(Qs,{height:r+n/2,radius:i/2,center:[-g+.06,0,-(r/2)+n/2]}),De(Qs,{height:r+n/2,radius:i/2,center:[g-.06,0,-(r/2)+n/2]})]})]})},Eui=({bodyLength:t=1.4,bodyDiameter:e=1.1,color:n="#3a3a3aff",contactColor:o="#c6c6c6",cathodeIdentification:i="#111"})=>Bn(fi,{children:[De(zo,{color:n,children:Bn($A,{rotation:[0,"90deg",0],children:[De(Gf,{size:[e,e,t-.2],roundRadius:.2,center:[-e/2,0,.05]}),De(Qs,{height:.2/2,radius:e/2-.2,center:[-e/2,0,-t/2+.2/2]})]})}),De(zo,{color:i,children:De($A,{rotation:[0,"90deg",0],children:De(Gf,{size:[e*1.01,e*1.01,t/3],roundRadius:.2,center:[-e/2,0,-t/4+.1]})})}),De(zo,{color:o,children:De($A,{rotation:[0,"90deg",0],children:De(Ny,{height:.2,radius:e/2,roundRadius:.2/3,center:[-e/2,0,-t/2]})})}),De(zo,{color:o,children:De($A,{rotation:[0,"90deg",0],children:De(Ny,{height:.2,radius:e/2,roundRadius:.2/3,center:[-e/2,0,t/2]})})})]}),Hen=({bodyLength:t=3.5,bodyDiameter:e=1.5,color:n="#202020",contactColor:o="#c6c6c6",bandColor:i="#f2f2f2"})=>{const s=t-.8+.04,a=(t-.4)/2,A=e/2+.02,c=.14,l=-t/2+.4+.35;return Bn(fi,{children:[De(zo,{color:n,children:De($A,{rotation:[0,"90deg",0],children:De(Ny,{height:s,radius:e/2,roundRadius:.05,center:[-e/2,0,0]})})}),De(zo,{color:i,children:De($A,{rotation:[0,"90deg",0],children:De(Qs,{height:c,radius:e/2+.002,center:[-e/2,0,l]})})}),De(zo,{color:o,children:De($A,{rotation:[0,"90deg",0],children:De(Ny,{height:.4,radius:A,roundRadius:.04,center:[-e/2,0,-a]})})}),De(zo,{color:o,children:De($A,{rotation:[0,"90deg",0],children:De(Ny,{height:.4,radius:A,roundRadius:.04,center:[-e/2,0,a]})})})]})},Bui=({bodyLength:t=3.9,bodyDiameter:e=2.5,color:n="#3a3a3aff",contactColor:o="#c6c6c6"})=>Bn(fi,{children:[De(zo,{color:n,children:De($A,{rotation:[0,"90deg",0],children:De(Ny,{height:t,radius:e/2,roundRadius:.3,center:[-e/2,0,0]})})}),De(zo,{color:o,children:De($A,{rotation:[0,"90deg",0],children:De(Ny,{height:.55,radius:e/2,roundRadius:.2,center:[-e/2,0,-t/2]})})}),De(zo,{color:o,children:De($A,{rotation:[0,"90deg",0],children:De(Ny,{height:.55,radius:e/2,roundRadius:.2,center:[-e/2,0,t/2]})})})]}),Sui=({pinCount:t,padContactLength:e=.6,leadWidth:n=.41,pitch:o=1.27})=>{if(t%2!==0)throw new Error("MS012 pinCount must be even");const i=t/2,r=4.9,s=3.9,a=(i-1)*o/2,A=.2;return Bn(fi,{children:[Array.from({length:i}).map((c,l)=>De($r,{position:{x:-s/2-e-.3,y:l*o-a,z:A/2},width:n,thickness:A,padContactLength:e,bodyDistance:e+.4,height:.85})),Array.from({length:i}).map((c,l)=>De($r,{rotation:Math.PI,position:{x:s/2+e+.3,y:l*o-a,z:A/2},width:n,thickness:A,padContactLength:e,bodyDistance:e+.4,height:.85})),De(Kg,{center:{x:0,y:0,z:A/2},width:s,length:r,height:1.55,notchPosition:{x:-.95,y:r/2-1,z:1.55},heightAboveSurface:.17,taperRatio:.09})]})},bui=({pinCount:t=16,padContactLength:e=.6,leadWidth:n=.41,pitch:o=1.27})=>{if(t!==16)throw new Error("MS013 only supports 16 pins");const i=t/2,r=7.5,s=10.3,a=(i-1)*o/2,A=.2;return Bn(fi,{children:[Array.from({length:i}).map((c,l)=>De($r,{position:{x:-r/2-e-.3,y:l*o-a,z:A/2},width:n,thickness:A,padContactLength:e,bodyDistance:e+.4,height:.85})),Array.from({length:i}).map((c,l)=>De($r,{rotation:Math.PI,position:{x:r/2+e+.3,y:l*o-a,z:A/2},width:n,thickness:A,padContactLength:e,bodyDistance:e+.4,height:.85})),De(Kg,{center:{x:0,y:0,z:A/2},width:r,length:s,height:1.1,notchPosition:{x:-2.25,y:s/2-1.5,z:1.1},heightAboveSurface:.17,taperRatio:.05})]})},Qui=[{x:-2.54,y:-1},{x:0,y:-1},{x:2.54,y:-1}],Oen=({mouldedTab:t=!1,leads:e=Qui,bodyWidth:n=10,bodyThickness:o=4.5,bodyHeight:i=9.2,tabHeight:r=6.4,tabThickness:s=1.4,mountingHoleDiameter:a=3.6,standoff:A=3,leadLength:c=3,bodyColor:l="#222",tabColor:g="#ccc",leadColor:u="#d4b106"}={})=>{const h=e.reduce((x,E)=>x+E.x,0)/e.length,d=e.reduce((x,E)=>x+E.y,0)/e.length,m=A,p=m+i,_=p+r,f=d+(o-s)/2,I=_-Math.max(a*.8,2.6),C=.8,y=.5;return Bn(fi,{children:[De(zo,{color:l,children:De(Xt,{size:[n,o,i],center:[h,d,m+i/2]})}),De(zo,{color:t?l:g,children:Bn(Hl,{children:[De(Xt,{size:[n,s,r],center:[h,f,p+r/2]}),De($A,{rotation:["90deg",0,0],children:De(Fo,{center:[h,I,-f],children:De(Qs,{radius:a/2,height:s*3})})})]})}),e.map(x=>De(zo,{color:u,children:De(Xt,{size:[C,y,A+c],center:[x.x,x.y,(A-c)/2]})},`lead-${x.x}-${x.y}`))]})},vui=()=>{const c=1.1999999999999997;return Bn(fi,{children:[De($r,{rotation:Math.PI,position:{x:2.8/2+c/4,y:-.95,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:c,height:.95}),De($r,{rotation:Math.PI,position:{x:2.8/2+c/4,y:0,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:c,height:.95}),De($r,{rotation:Math.PI,position:{x:2.8/2+c/4,y:.95,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:c,height:.95}),De($r,{position:{x:-2.8/2-c/4,y:0,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:c,height:.95}),De($r,{position:{x:-2.8/2-c/4,y:-.95,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:c,height:.95}),De($r,{position:{x:-2.8/2-c/4,y:.95,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:c,height:.95}),De(Kg,{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})]})},Pui=()=>Bn(fi,{children:[De(Kg,{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(c=>{const l=-.35+c*.35;return De(Xt,{center:[-.8/2+.19/2-.1,l,.12/2],size:[.19,.15,.12]})}),[0,1,2].map(c=>{const l=-.35+c*.35;return De(Xt,{center:[.8/2-.19/2+.1,l,.12/2],size:[.19,.15,.12]})})]}),wui=[{x:-1.27,y:.98},{x:0,y:2.25},{x:1.27,y:.98}],Mui=t=>{let e=[t[0],t[t.length-1]],n=-1;for(let o=0;o<t.length;o++)for(let i=o+1;i<t.length;i++){const r=Math.hypot(t[o].x-t[i].x,t[o].y-t[i].y);r>n&&(n=r,e=[t[o],t[i]])}return{outer:e,separation:n}},Gen=({bodyDiameter:t=4.8,bodyHeight:e=4.5,flatCut:n=1.1,leads:o=wui,standoff:i=1.5,leadLength:r=3,bodyColor:s="#222"}={})=>{const a=t/2,A=.4,c=.25,{outer:l,separation:g}=Mui(o),[u,h]=l,d={x:(u.x+h.x)/2,y:(u.y+h.y)/2},m=Math.max(g,.001),p={x:(h.x-u.x)/m,y:(h.y-u.y)/m},_=g/2,f=C=>{const y=(C-(o.length-1)/2)*_;return{x:d.x+p.x*y,y:d.y+p.y*y}},I=[c,A,c];return Bn(fi,{children:[De(zo,{color:s,children:Bn(Hl,{children:[De(Fo,{center:[d.x,d.y,i+e/2],children:De(Qs,{radius:a,height:e})}),De(Fo,{center:[d.x,d.y-(a-n/2),i+e/2],children:De(Xt,{size:[a*2,n,e+.2]})})]})}),o.map((C,y)=>{const x=f(y);return Bn(Fo,{center:[0,0,0],children:[Bn(KA,{children:[De(Fo,{center:[C.x,C.y,0],children:De(Xt,{size:I})}),De(Fo,{center:[x.x,x.y,i],children:De(Xt,{size:I})})]}),De(Fo,{center:[C.x,C.y,-r/2],children:De(Xt,{size:[c,A,r]})})]},`lead-${C.x}-${C.y}`)})]})},Dui=()=>Bn(fi,{children:[De($r,{rotation:Math.PI,position:{x:2/2+.75/4,y:-.65,z:.15/2},width:.25,thickness:.15,padContactLength:.3,bodyDistance:.75,height:.85}),De($r,{rotation:Math.PI,position:{x:2/2+.75/4,y:0,z:.15/2},width:.25,thickness:.15,padContactLength:.3,bodyDistance:.75,height:.85}),De($r,{rotation:Math.PI,position:{x:2/2+.75/4,y:.65,z:.15/2},width:.25,thickness:.15,padContactLength:.3,bodyDistance:.75,height:.85}),De($r,{position:{x:-2/2-.75/4,y:0,z:.15/2},width:.25,thickness:.15,padContactLength:.3,bodyDistance:.75,height:.85}),De($r,{position:{x:-2/2-.75/4,y:-.65,z:.15/2},width:.25,thickness:.15,padContactLength:.3,bodyDistance:.75,height:.85}),De($r,{position:{x:-2/2-.75/4,y:.65,z:.15/2},width:.25,thickness:.15,padContactLength:.3,bodyDistance:.75,height:.85}),De(Kg,{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})]}),Nui=Dui,Rui=()=>Bn(fi,{children:[De(Kg,{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(a=>{const A=-.5+a*.5;return De(Xt,{center:[-1/2+.3/2,A,.05/2],size:[.3,.2,.05]})}),[0,1,2].map(a=>{const A=-.5+a*.5;return De(Xt,{center:[1/2-.3/2,A,.05/2],size:[.3,.2,.05]})})]}),Yen=()=>Bn(fi,{children:[De($r,{position:{x:-2.5/2,y:0,z:.175/2},width:.3,thickness:.175,padContactLength:.3,bodyDistance:.45,height:.7}),De($r,{rotation:Math.PI,position:{x:2.5/2,y:0,z:.175/2},width:.3,thickness:.175,padContactLength:.3,bodyDistance:.45,height:.7}),De(zo,{color:"#222",children:De(Kg,{center:{x:0,y:0,z:0},width:1.8,length:1.4,height:.95,includeNotch:!1,taperRatio:.06,straightHeightRatio:.7,heightAboveSurface:.05})}),De(Xt,{color:"#777",size:[1.8/3,1.4-.075,.02],center:[-.9*2/3+.035,0,.95+.05]})]}),Tui=()=>Bn(fi,{children:[De(Xt,{color:"#ccc",size:[.4,.325,.175],center:[-1.05,0,.175/2]}),De(Xt,{color:"#ccc",size:[.4,.325,.175],center:[1.05,0,.175/2]}),De(zo,{color:"#222",children:Bn(zd,{children:[De(Fo,{z:.175/2,children:De(Xt,{size:[1.7,1.25,.175]})}),Bn(KA,{children:[De(Fo,{z:.175,children:De(Xt,{size:[1.7,1.25,.01]})}),De(Fo,{z:.725,children:De(Xt,{size:[1.7-.2,1.25-.2,.01]})})]})]})}),De(Xt,{color:"#777",size:[1.7/3,1.25-.2,.02],center:[-1.05+1.7/4.4+.2,0,.725]})]}),kui=()=>{const s=-1.0474999999999999,a=1.775/2+.4/2-.04;return Bn(fi,{children:[De(Xt,{color:"#ccc",size:[.4,.325,.13],center:[s,0,.13/2]}),De(Xt,{color:"#ccc",size:[.4,.325,.13],center:[a,0,.13/2]}),De(zo,{color:"#222",children:De(Kg,{width:1.775,length:1.25,height:.725,center:{x:0,y:0,z:0},heightAboveSurface:0,straightHeightRatio:.7,taperRatio:.06,includeNotch:!1})}),De(Xt,{color:"#777",size:[1.775/3,1.25-.05,.02],center:[s+1.775/4.4+.2,0,.725]})]})},Fui=({pitch:t=10})=>Bn(fi,{children:[De(Qs,{height:4,radius:.5,center:[-t/2,0,.5]}),De(pG,{radius:.5,center:[-t/2,0,2.5]}),De(Fo,{x:-2.5,y:0,z:2.5,children:Bn($A,{rotation:[0,Math.PI/2,0],children:[De(Qs,{height:t,radius:.5,center:[0,0,2.5]}),De(zo,{color:"#d2b48c",children:De(Qs,{height:5,radius:1.3,center:[0,0,2.5]})})]})}),De(Qs,{height:4,radius:.5,center:[t/2,0,.5]}),De(pG,{radius:.5,center:[t/2,0,2.5]})]}),Lui=({bodyWidth:t=21,boardThickness:e=.5,leadWidth:n=1.6,leadLength:o=2.4,leadsPitch:i=2.54,leadsLeft:r,leadsRight:s,leadsTop:a,leadsBottom:A,innerHoles:c=!0,innerHoleEdgeDistance:l=1.61,innerHoleDiameter:g=1})=>{const u=t/2,h=e/2,d=e*1.05,m=g/2,p=Math.max(r||0,s||0,a||0,A||0)*i||51,_=[],f=[];if(s){const x=-((s-1)/2)*i;for(let E=0;E<s;E++){const B=x+E*i;_.push({x:u-o/2,y:-B,pl:o,pw:n}),c&&f.push({x:u,y:-B},{x:u-l,y:-B})}}if(r){const x=-((r-1)/2)*i;for(let E=0;E<r;E++){const B=x+E*i;_.push({x:-u+o/2,y:-B,pl:o,pw:n}),c&&f.push({x:-u,y:-B},{x:-u+l,y:-B})}}if(a){const x=-((a-1)/2)*i;for(let E=0;E<a;E++){const B=x+E*i;_.push({x:-B,y:p/2-o/2,pl:n,pw:o}),c&&f.push({x:-B,y:p/2},{x:-B,y:p/2-l})}}if(A){const x=-((A-1)/2)*i;for(let E=0;E<A;E++){const B=x+E*i;_.push({x:-B,y:-p/2+o/2,pl:n,pw:o}),c&&f.push({x:-B,y:-p/2},{x:-B,y:-p/2+l})}}const I=De(zo,{color:"#051a0a",children:Bn(Hl,{children:[De(Xt,{center:[0,0,h],size:[t,p,e]}),_.map((x,E)=>De(Xt,{center:[x.x,x.y,h],size:[x.pl+.01,x.pw+.01,d]},E))]})}),C=c&&f.map((x,E)=>De(Qs,{color:"black",center:[x.x,x.y,h],radius:m,height:e*1.07})),y=_.map((x,E)=>De(Xt,{center:[x.x,x.y,h],size:[x.pl+.01,x.pw+.01,d]}));return Bn(fi,{children:[I,De(zo,{color:"#FFD700",children:c?Bn(Hl,{children:[De(zd,{children:_.map((x,E)=>De(Xt,{center:[x.x,x.y,h],size:[x.pl+.01,x.pw+.01,d]},E))}),C]}):y})]})},Uen=({width:t=30,height:e=22,thickness:n=1,bezelInset:o=2,bezelDepth:i=1,screenColor:r="#001414",bezelColor:s="#0f1116",screenWidth:a,screenHeight:A,offset:c})=>{const l=t,g=e,u=Math.max(n,.4),h=Math.max(Math.min(i,u),.2),d=Math.max(u-h,0),m=Math.max(o,0),p=Math.max(a??l-m*2,2),_=Math.max(A??g-m*2,2),f=Math.min(Math.max(h*.6,.2),h),I=c?.x??0,C=c?.y??0,y=c?.z??0;return Bn(Fo,{offset:{x:I,y:C,z:y},children:[d>0&&De(zo,{color:s,children:De(Xt,{size:[l,g,d],offset:[0,0,d/2]})}),De(zo,{color:s,children:Bn(Hl,{children:[De(Xt,{size:[l,g,h],offset:[0,0,d+h/2]}),De(Xt,{size:[p,_,h+.02],offset:[0,0,d+h/2]})]})}),De(zo,{color:r,children:De(Xt,{size:[p,_,f],offset:[0,0,d+f/2]})})]})},Hui=({numPins:t=5,rows:e=1,p:n=2.54,id:o=1,od:i=1.5,boardThickness:r=1.6,width:s,height:a,pinRowSide:A="left",holes:c=[],holeInset:l=1,pinRowHoleEdgeToEdgeDist:g=2,female:u,nopin:h,screen:d,screenWidth:m,screenHeight:p,screenCenterOffsetX:_,screenCenterOffsetY:f})=>{const I=d??!1,C=r/2,y=Math.ceil(t/e);let x,E;A==="left"||A==="right"?(x=(e-1)*n+2*g,E=(y-1)*n+2*g):(E=(e-1)*n+2*g,x=(y-1)*n+2*g),t===0&&(x=10,E=10);const B=Number(s??x),b=Number(a??E),Q=[];let w=0,D=0,k=0,T=0,H=0,G=0;A==="left"||A==="right"?(w=A==="left"?-B/2+g:B/2-g,D=-((y-1)/2)*n,k=0,T=n,H=A==="left"?n:-n,G=0):(w=-((y-1)/2)*n,D=A==="top"?b/2-g:-b/2+g,k=n,T=0,H=0,G=A==="top"?-n:n);let U=0;for(let ce=0;ce<e&&U<t;ce++)for(let fe=0;fe<y&&U<t;fe++){const de=w+fe*k+ce*H,Ce=D+fe*T+ce*G;Q.push({x:de,y:Ce}),U++}const Y=[];if(c)for(const ce of c){let fe=0,de=0;ce==="topleft"?(fe=-B/2+l,de=b/2-l):ce==="topright"?(fe=B/2-l,de=b/2-l):ce==="bottomleft"?(fe=-B/2+l,de=-b/2+l):ce==="bottomright"?(fe=B/2-l,de=-b/2+l):ce==="center"&&(fe=0,de=0),Y.push({x:fe,y:de})}const j=.63,ee=2,W=6,Z=3,ie=h||u?0:ee,se=ie+r,ne=De(zo,{color:"#008080",children:Bn(Hl,{children:[De(Xt,{center:[0,0,C+ie],size:[B,b,r]}),Y.map((ce,fe)=>De(Qs,{center:[ce.x,ce.y,C+ie],radius:i/2,height:r},`hole-${fe}`)),Q.map((ce,fe)=>De(Qs,{center:[ce.x,ce.y,C+ie],radius:i/2,height:r},`pin-hole-${fe}`))]})}),le=Q.map((ce,fe)=>De(zo,{color:"#FFD700",children:Bn(Hl,{children:[De(Qs,{center:[ce.x,ce.y,r/2+ie],radius:i/2,height:r}),De(Qs,{center:[ce.x,ce.y,r/2+ie],radius:o/2,height:r})]})})),he=Q.map((ce,fe)=>De(Een,{x:ce.x,y:ce.y,pinThickness:j,shortSidePinLength:Z,longSidePinLength:W,bodyHeight:ee,flipZ:de=>de})),Ie=Q.map((ce,fe)=>De(Nen,{x:ce.x,y:ce.y,flipZ:de=>-de}));return Bn(fi,{children:[ne,le,!u&&!h&&he,u&&Ie,I&&De(Uen,{width:m??B*.8,height:p??b*.6,offset:{x:_??0,y:f??0,z:se}})]})},Oui=()=>{const s=.8999999999999999,a=-s/2+.5/2-.15,A=s/2-.5/2+.15,c=.2,l=.5*.24;return Bn(fi,{children:[De(Xt,{color:"#ccc",size:[.5,.28,.12],center:[a,0,.12/2]}),De(Xt,{color:"#ccc",size:[.5,.28,.12],center:[A,0,.12/2]}),De(zo,{color:"#222",children:Bn(zd,{children:[De(Fo,{z:l/2,children:De(Xt,{size:[s,.6,l]})}),Bn(KA,{children:[De(Fo,{z:l,children:De(Xt,{size:[s,.6,.01]})}),De(Fo,{z:.5,children:De(Xt,{size:[s-c,.6-c,.01]})})]})]})}),De(Xt,{color:"#777",size:[1.4/6,.6-c,.02],center:[-s/4,0,.5]})]})},Gui=Oui,Yui=({numPins:t=7,showPins:e=!0,showFootprint:n=!0,bodyColor:o="#f5f5f5",pinColor:i="#635959"})=>{const c=3.5999999999999996,l=6,g=(t-1)*1.5+4,u=-((t-1)*1.5)/2;return Bn(fi,{children:[De(Fo,{offset:[0,0,6],children:De($A,{angles:[Math.PI,0,0],children:De(zo,{color:o,children:Bn(Hl,{children:[De(Xt,{size:[g,3.5,6],center:[0,0,6/2]}),De(Xt,{size:[g-.5*2,3.5-.5*2,c],center:[0,0,c/2]}),De(Xt,{size:[g,3.5/3,c],center:[0,0,c/6]}),De(Xt,{size:[g-.5*2,.5/2,c],center:[0,3.5/2-.5/4,c/2]}),De(Xt,{size:[g-.5*2,.5/2,c],center:[0,-3.5/2+.5/4,c/2]}),De(Xt,{size:[1,.5+2,1],center:[-g/4,3.5/2,6/2]}),De(Xt,{size:[1,.5+3,1],center:[g/4,3.5/2,6/2]}),De(Xt,{size:[1,.5+2,1],center:[-g/4,-3.5/2,6/2]}),De(Xt,{size:[1,.5+3,1],center:[g/4,-3.5/2,6/2]})]})})})}),e&&Array.from({length:t}).map((h,d)=>De(zo,{color:i,children:De(Qs,{height:l,radius:.35,center:[u+d*1.5,0,2.5]})})),n&&Array.from({length:t}).map((h,d)=>{const m=d===0,p=m?{type:"pcb_plated_hole",pcb_plated_hole_id:`jstzh_${d}`,shape:"circular_hole_with_rect_pad",x:u+d*1.5,y:0,hole_diameter:.73,rect_pad_width:1.03,rect_pad_height:1.73,hole_shape:"circle",pad_shape:"rect",layers:["top","bottom"],port_hints:[`${d+1}`]}:{type:"pcb_plated_hole",pcb_plated_hole_id:`jstzh_${d}`,shape:"pill",x:u+d*1.5,y:0,hole_height:.73,hole_width:.73,outer_height:1.73,outer_width:1.03,layers:["top","bottom"],port_hints:[`${d+1}`]};return De(IYe,{hole:p,isPin1:m})})]})},Uui=({numPins:t=2,showPins:e=!0,showFootprint:n=!0,bodyColor:o="#f5f5f5",pinColor:i="#635959"})=>{const c=3.5999999999999996,l=3.4,g=5.5,u=.5,h=l+g,d=(t-1)*2+3.9,m=-((t-1)*2)/2,p=1,_=1.8,f=.7,I=.8,C=.65;return Bn(fi,{children:[De(Fo,{offset:[0,0,6],children:De($A,{angles:[Math.PI,0,0],children:De(zo,{color:o,children:Bn(Hl,{children:[De(Xt,{size:[d,4.5,6],center:[0,0,6/2]}),De(Xt,{size:[d-.5*2,4.5-.5*2,c],center:[0,0,c/2]}),De(Xt,{size:[d,4.5/3,c],center:[0,0,c/6]}),De(Xt,{size:[d-.5*2,.5/2,c],center:[0,4.5/2-.5/4,c/2]}),De(Xt,{size:[d-.5*2,.5/2,c],center:[0,-4.5/2+.5/4,c/2]}),De(Xt,{size:[p,4.5+.5,_],center:[-d/2+f,0,6/2]}),De(Xt,{size:[p,4.5+.5,_],center:[d/2-f,0,6/2]}),De(Xt,{size:[.5*3,I,C],center:[-d/2,0,C/2]}),De(Fo,{offset:[-d/2,0,C],children:De($A,{angles:[0,Math.PI/2,0],children:De(Qs,{height:.5*3,radius:I/2})})}),De(Xt,{size:[.5*3,I,C],center:[d/2,0,C/2]}),De(Fo,{offset:[d/2,0,C],children:De($A,{angles:[0,Math.PI/2,0],children:De(Qs,{height:.5*3,radius:I/2})})})]})})})}),e&&Array.from({length:t}).map((y,x)=>De(zo,{color:i,children:De(Xt,{size:[u,u,h],center:[m+x*2,0,(g-l)/2]})})),n&&Array.from({length:t}).map((y,x)=>{const E=x===0,B=E?{type:"pcb_plated_hole",pcb_plated_hole_id:`jstph_${x}`,shape:"circular_hole_with_rect_pad",x:m+x*2,y:0,hole_diameter:.73,rect_pad_width:1.2,rect_pad_height:1.2,hole_shape:"circle",pad_shape:"rect",layers:["top","bottom"],port_hints:[`${x+1}`]}:{type:"pcb_plated_hole",pcb_plated_hole_id:`jstph_${x}`,shape:"pill",x:m+x*2,y:0,hole_height:.73,hole_width:.73,outer_height:1.2,outer_width:1.2,layers:["top","bottom"],port_hints:[`${x+1}`]};return De(IYe,{hole:B,isPin1:E})})]})},Kui=({numPins:t=4,showPins:e=!0,showFootprint:n=!0,bodyColor:o="#f8fafc",pinColor:i="#635959"})=>{const u=(t-1)*2.5+4.9,h=-((t-1)*2.5)/2,d=.8,m=.85+.2,p=3.5,_=u/2-1.3,f=Math.min(u-3.4,Math.max(3,(t-1)*2.5*.4+2.2)),I=2.4;return Bn(fi,{children:[De(Fo,{offset:[0,0,7/2],children:De(zo,{color:o,children:Bn(Hl,{children:[De(Xt,{size:[u,5.75,7]}),De(Fo,{offset:[0,0,(7-5.35)/2+.1],children:De(Xt,{size:[u-.85*2,5.75-.85*2,5.35+.2]})}),De(Fo,{offset:[0,-5.75/2+.85/2,7/2-I/2+.1],children:De(Xt,{size:[f,.85+.2,I+.2]})}),De(Fo,{offset:[-_,-5.75/2+.85/2,7/2-p/2+.1],children:De(Xt,{size:[d,m,p+.2]})}),De(Fo,{offset:[_,-5.75/2+.85/2,7/2-p/2+.1],children:De(Xt,{size:[d,m,p+.2]})}),Array.from({length:t}).map((C,y)=>De(Fo,{offset:[h+y*2.5,-5.75/2+.3,-7/2+.25],children:De(Xt,{size:[1,.8,.5]})},`vent_${y}`))]})})}),e&&Array.from({length:t}).map((C,y)=>De(zo,{color:i,children:De(Fo,{offset:[h+y*2.5,0,8.75/2-3.4],children:De(Xt,{size:[.64,.64,8.75]})})})),n&&(()=>{try{return W1.string(`jst${t}_xh`).circuitJson().filter(x=>x.type==="pcb_plated_hole").map((x,E)=>De(IYe,{hole:x,isPin1:E===0},`footprint_${E}`))}catch{return null}})()]})};function Ken(t){const e=W1.string(t).json();return e.fn!=="jst"?!1:!!(e.sh||e.smd&&Math.abs(za(e.p)-1)<.01&&Math.abs(za(e.mpx??0)-(e.num_pins-1+2.6))<.15&&Math.abs(za(e.mpy??0)-2.525)<.15)}var Vui=({footprint:t="jst6_sh"})=>{if(!Ken(t))throw new Error("JstSh requires a named SH or matching 1mm SH top-entry footprint");const e=t.replace(/_pin1location\([^)]*\)/g,""),n=W1.string(e).json(),o=W1.string(e).circuitJson().filter(_=>_.type==="pcb_smtpad"&&_.shape==="rect"),i=W1.string(t).circuitJson().filter(_=>_.type==="pcb_smtpad"&&(_.shape==="rect"||_.shape==="rotated_rect")),r=n.num_pins;if(!Number.isInteger(r)||r<2||r>20||o.length!==r+2)throw new Error("JstSh requires 2–20 contacts and two hold-down pads");const s=o.slice(0,r),a=o.slice(r),A=Math.atan2(i[1].y-i[0].y,i[1].x-i[0].x)-Math.atan2(o[1].y-o[0].y,o[1].x-o[0].x),c=s.reduce((_,f)=>_+f.x,0)/r,l=s[0].y,g=a[0].y>l?1:-1,u=l+g*1.8,h=r+2,d=2.9,m=4.2,p=u-g*.25;return Bn($A,{rotation:[0,0,A],children:[De(zo,{color:"#e4e1d6",children:Bn(Hl,{children:[De(Xt,{size:[h,d,m],center:[c,u,m/2+.05]}),De(Xt,{size:[h-1.3,1.8,m],center:[c,u,m/2+.8]}),a.map((_,f)=>De(Xt,{size:[.7,_.height*.8,1.5],center:[_.x,_.y,.75]},`recess-${f}`)),[-1,1].map(_=>De(Xt,{size:[.55,.6,1],center:[c+_*(h/2-.9),u+g*d/2,4]},_))]})}),Bn(zo,{color:"#c6c7c9",children:[s.map((_,f)=>{const I=_.y-g*_.height*.4;return Bn(zd,{children:[De(Xt,{size:[.2,Math.abs(p-I)+.1,.2],center:[_.x,(p+I)/2,.1]}),De(Xt,{size:[.2,.2,3.45],center:[_.x,p,1.725]})]},f)}),a.map((_,f)=>Bn(zd,{children:[De(Xt,{size:[.7,_.height*.75,.2],center:[_.x,_.y,.1]}),De(Xt,{size:[.2,_.height*.6,1.35],center:[_.x,_.y,.675]})]},`mount-${f}`))]})]})},zui=([t,e],n,o,i,r)=>{const s=Math.sign(t),a=Math.sign(e),A=n/2,c=o/2,l=r?Math.min(.32,o*.36):0,g=Math.min(i,A,c),u=[[-A,-c],[A,-c],[A,c-g],[A-g,c],[-A,c]];l&&(u[0]=[-A+l,-c],u.push([-A,-c+l]));const h=u.map(([d,m])=>[t+d*s,e+m*a]);return s*a<0?h.reverse():h},HYe=({width:t,length:e,radius:n,height:o,z:i})=>{const r=t/2-n,s=e/2-n;return[[-r,-s],[r,-s],[r,s],[-r,s]].map(([a,A],c)=>De(Qs,{center:[a,A,i+o/2],height:o,radius:n}))},Jui=({horizontalPadPitch:t=2.2,verticalPadPitch:e=1.7,padWidth:n=1.4,padHeight:o=1.2,bodyHeight:i=.7})=>{const r=t+n*.7142857142857143,s=e+o*(2/3),a=Math.min(.01,i*.02),A=n*(5/7),c=o*.75,l=i*(5/7),g=l-a,u=i*(2/35),h=r*.95,d=s*.94,m=r*.905,p=s*.9,_=r*.83,f=s*.82,I=l+u,C=Math.min(.01,i*.015),y=Math.min(.12,s*.05),x=(r-A)/2,E=(s-c)/2,B=[[-x,-E],[x,-E],[x,E],[-x,E]],b=HYe({width:h,length:d,radius:Math.min(.13,d*.08),height:u,z:l}),Q=[...HYe({width:m,length:p,radius:Math.min(.14,p*.08),height:C,z:I}),...HYe({width:_,length:f,radius:Math.min(.15,f*.09),height:C,z:i-C})];return Bn(fi,{children:[B.map((w,D)=>De(zo,{color:"#d6a258",children:De(fG,{height:a,children:De(_G,{points:zui(w,A,c,y,D===0)})})})),De(Kg,{center:{x:0,y:0,z:a},width:r,length:s,height:g-.005,heightAboveSurface:0,color:"#34343d",taperRatio:0,straightHeightRatio:1,includeNotch:!1,chamferSize:y}),De(zo,{color:"#d2a057",children:De(KA,{children:b})}),De(zo,{color:"#b9bec2",children:De(KA,{children:Q})})]})},Wui="#303339",Hue="#1f2227",Ven="#eee8d8",zen="#f8f3e7",OYe="#b7bdc2",jui="#d2d6d9",Xui="#767d82",qui="#9ba1a5",$ui=({pinCount:t=12,pitch:e=.5,padWidth:n=.3,padLength:o=1.25,staggered:i=!1,reverse:r=!1,rowPitch:s=2.4,topPadLength:a=o,bottomPadLength:A=o,mountPadPitchX:c,mountPadOffsetY:l=2.575,mountTop:g=!1,mountPadWidth:u=2,mountPadLength:h=2.5})=>{const d=Math.max((t-1)*e,e),m=-d/2,p=c??d+(i?3.5:3.38),_=l===0?0:(g?1:-1)*l,f=Array.from({length:t},(ye,Fe)=>{const Ye=i&&Fe%2===1!==r,qe=i?Ye?s/2:-s/2:0,st=Ye?a:A;return{index:Fe,x:m+Fe*e,y:qe,length:st}}),I=Math.max(...f.map(ye=>ye.y+ye.length/2)),C=Math.min(...f.map(ye=>ye.y-ye.length/2)),y=_-h/2,x=_+h/2,E=g?C:I,B=g?Math.max(x,I)+.67:Math.min(y,C)-.67,b=g?-1:1,Q=E-b*Math.max(o*.86,1.05),w=B+b*.22,D=Math.abs(Q-w),k=(Q+w)/2,T=w-b*.01,H=Math.max(d+4.9,p+u*.76),G=Math.min(H-2.3,d+1.1),U=.3,Y=1.42,j=2,ee=Math.min(.92,D*.28),W=T+b*(ee/2-.04),Z=1.6,ie=1.1,se=Math.max(D-.78,1.5),ne=T+b*(se/2+.68),le=H-.72,he=.34,Ie=j-he/2,ce=T+b*Math.min(.68,D*.22),fe=1.48,de=Math.max(n*.82,.15),Ce=E,Qe=Math.abs(Ce-Q),Pe=(Ce+Q)/2,pe=Math.max(ee*.8,.5),ve=T+b*(pe/2+.08),we=p/2,Me=.75,Oe=H/2-.04,ke=H/2-.23,be=H/2-.32,He=.68;return Bn(fi,{children:[[-1,1].map(ye=>De(Xt,{color:OYe,center:[ye*we,_,.07],size:[u,h,.14]})),f.map(ye=>De(Xt,{color:OYe,center:[ye.x,Pe,.065],size:[de,Qe,.13]},`terminal:${ye.index}`)),De(Gf,{color:Hue,center:[0,k,U/2],size:[H,D,U],roundRadius:.1}),De(zo,{color:Wui,children:Bn(Hl,{children:[De(Gf,{center:[0,k,U+Y/2],size:[H-.2,D-.12,Y],roundRadius:.14}),De(Xt,{center:[0,W,ie],size:[G,ee,Z]}),De(Xt,{center:[0,ne,j-he*.72],size:[le-.32,se-.16,he]})]})}),f.map(ye=>De(Gf,{color:jui,center:[ye.x,ve,U+.82],size:[de*.82,pe,.14],roundRadius:.035},`spring:${ye.index}`)),f.map(ye=>De(Xt,{color:OYe,center:[ye.x,Q-b*.03,U+.32],size:[de,.13,.62]},`terminal-rise:${ye.index}`)),De(Xt,{color:Hue,center:[0,T+b*.1,U+.71],size:[G+.18,.16,.8]}),De(Gf,{color:Ven,center:[0,ne,Ie],size:[le,se,he],roundRadius:.11}),De(Xt,{color:zen,center:[0,ne-b*(se/2-.12),j-.035],size:[le-.36,.24,.07]}),[-1,1].map(ye=>De(Gf,{color:Ven,center:[ye*be,ce,fe],size:[He,.92,.72],roundRadius:.1})),[-1,1].map(ye=>De(Fo,{x:ye*be,y:ce,z:fe,children:De($A,{rotation:[0,Math.PI/2,0],children:De(Qs,{color:zen,height:He+.12,radius:.24})})})),[-1,1].map(ye=>De(Gf,{color:Xui,center:[ye*Oe,_,Me/2],size:[.17,Math.min(h*.3,.7),Me],roundRadius:.04})),[-1,1].map(ye=>De(Gf,{color:qui,center:[ye*ke,_,Me-.05],size:[.42,Math.min(h*.3,.7),.1],roundRadius:.035})),De(Xt,{color:Hue,center:[0,k,.025],size:[G+.7,D*.58,.05]}),De(Xt,{color:Hue,center:[0,Q-b*.06,U+.82],size:[G+.4,.15,.92]})]})},Zui=({numberOfPins:t,pitch:e=2.54,pinThickness:n=.64,bodyWidth:o=2.5,bodyHeight:i=2.54,standoffHeight:r=1.27,matingPinLength:s=5.8,tailSpan:a=5.08})=>{const A=-((t-1)*e)/2,c=r+i,l=a/2,g=n*.35;return De(fi,{children:Array.from({length:t},(u,h)=>{const d=A+h*e,m=h%2===0?1:-1,p=s-g,_=r-n/2;return Bn(Fo,{x:d,children:[De(Xt,{color:"#222",size:[e,o,i],center:[0,0,r+i/2]}),Bn(zo,{color:"#d4af37",children:[De(Xt,{size:[n,l,n],center:[0,m*(l/2),n/2]}),De(Xt,{size:[n,n,_],center:[0,0,n/2+_/2]}),De(Xt,{size:[n,n,p],center:[0,0,c+p/2]}),Bn(KA,{children:[De(Xt,{size:[n,n,.01],center:[0,0,c+p]}),De(Xt,{size:[n*.65,n*.65,.01],center:[0,0,c+s]})]})]})]})})})},$X=t=>W1.string(t).circuitJson().filter(n=>n.type==="pcb_plated_hole"&&Number.isFinite(n.x)&&Number.isFinite(n.y)).map(n=>({x:n.x,y:n.y,pin:n.port_hints?.[0]})),Jen=t=>W1.string(t).circuitJson().filter(n=>n.type==="pcb_smtpad"&&n.shape==="rect"&&Number.isFinite(n.x)&&Number.isFinite(n.y)).map(n=>({x:n.x,y:n.y,width:n.width??.4,height:n.height??.4,pin:n.port_hints?.[0]})),edi=({bodyWidth:t,bodyLength:e,bodyHeight:n=1,pads:o,leadThickness:i=.15,leadHeightRatio:r=.75})=>{const s=o.reduce((c,l)=>c+l.x,0)/(o.length||1),a=o.reduce((c,l)=>c+l.y,0)/(o.length||1),A=n*r;return Bn(fi,{children:[De(Kg,{center:{x:s,y:a,z:0},width:t,length:e,height:n}),o.map(c=>{const l=c.width??.4,g=c.height??.4,u=c.x>=s?1:-1,h=c.x+u*l/2,d=Math.max(Math.abs(h-s)-t/2,.1),m=Math.min(.15,t*.15);return De($r,{rotation:u>0?Math.PI:0,position:{x:h,y:c.y,z:i/2},width:g,thickness:i,padContactLength:l*.6,bodyDistance:d+m,height:A},`lead-${c.x}-${c.y}`)})]})},tdi=({padPitch:t,padHeight:e,color:n="#333"})=>{const o=t,i=e*.85,r=i,s=o*.2,a=o-s*2;return Bn(fi,{children:[De(Xt,{size:[a,i,r],offset:[0,0,r/2],color:n}),De(Xt,{size:[s,r,i],offset:[o/2-s/2,0,r/2],color:"#ccc"}),De(Xt,{size:[s,r,i],offset:[-o/2+s/2,0,r/2],color:"#ccc"})]})},ndi=({color:t="#ffff00",bodyColor:e="#ffffff",leadColor:n="#dedede"})=>{const p=[-1.7,0,1.7],_=[-1,1];return Bn(fi,{children:[p.flatMap(f=>_.map(I=>De(Xt,{color:n,size:[1.4,1,.2],center:[I*2,f,.2/2]}))),De(zo,{color:e,children:Bn(Hl,{children:[De(Kg,{width:5,length:5,height:1.3,heightAboveSurface:.2,center:{x:0,y:0,z:0},color:e,taperRatio:.036,straightHeightRatio:.01,includeNotch:!1}),De(Qs,{radius:2,height:.25,center:[0,0,1.5-.25/2]}),De(Fo,{offset:[-5/2,5/2,1.5-.3/2+.005],children:De($A,{rotation:[0,0,Math.PI/4],children:De(Xt,{size:[.9,.9,.3+.01]})})})]})}),De(Qs,{color:t,radius:2,height:.25,center:[0,0,1.55-.25/2]})]})},odi=({bodyWidth:t=3.5,bodyLength:e=2.8,bodyHeight:n=.8,color:o="#ffe08a",bodyColor:i="#f2f2f2",padColor:r="#cccccc",pad1X:s=-.9,pad1Width:a=2.2,pad2X:A=1.375,pad2Width:c=1.25,padLength:l=2.2}={})=>{const h=(s+A)/2,d=t*.55,m=e*.55;return Bn(fi,{children:[[{x:s,w:a,key:"pad-1"},{x:A,w:c,key:"pad-2"}].map(({x:p,w:_,key:f})=>De(zo,{color:r,children:De(Xt,{size:[_,l,.1],center:[p,0,.1/2]})})),De(zo,{color:i,children:De(Xt,{size:[t,e,n],center:[h,0,.1+n/2]})}),De(zo,{color:o,children:De(Xt,{size:[d,m,.15],center:[h,0,.1+n+.15/2-.05]})})]})},Wen=t=>Array.from({length:t},(e,n)=>n),idi=({bodyWidth:t=16.26,bodyDepth:e=15.88,bodyHeight:n=13.5,bodyCenterY:o=-.96,ledPins:i=!1,firstPinLeft:r=!1,firstPinTop:s=!1,signalPitch:a=1.02,signalRowPitch:A=1.78,signalHoleDiameter:c=.9144,shieldPinX:l=8.13,shieldPinY:g=.13,shieldHoleDiameter:u=1.8,locatorHoleX:h=6.35,locatorHoleY:d=-3.43,locatorHoleDiameter:m=3.25,ledPinX:p=4.57,ledPinPitch:_=2.29,ledPinY:f=5.7,openingDirection:I,shellColor:C="#b7bdc2",housingColor:y="#20242a",contactColor:x="#d6a928"})=>{const E=I??(o>0?1:-1),B=o+E*e/2,b=Math.min(.38,t*.024),Q=Math.max(t-2.5,t*.72),w=Math.min(n-2.4,9.6),D=1.3+w/2,k=Math.min(4.4,e*.34),T=B-E*k/2,H=B-E*(k+b*.7),G=Math.max(.22,Math.min(c*.36,.38)),U=Wen(8).map(ie=>{const se=(3.5-ie)*a,ne=ie%2===0?-A/2:A/2;return{x:r?-se:se,y:s?-ne:ne}}),Y=[-p-_,-p,p,p+_],j=Q/10,ee=B-E*Math.max(k*.48,1.2),W=D+w*.18,Z=B+E*b*.2;return Bn(fi,{children:[Bn(zo,{color:C,children:[Bn(Hl,{children:[De(Xt,{center:[0,o,n/2],size:[t,e,n]}),De(Xt,{center:[0,T,D],size:[Q,k+b*2,w]})]}),De(Xt,{center:[0,Z,.72],size:[Q+.5,b*1.25,1.05]}),[-1,1].map(ie=>De(Xt,{center:[ie*l,g,.25],size:[Math.max(u*.46,.65),Math.max(u*.72,1.1),3.4]})),[-1,1].map(ie=>De(Xt,{center:[ie*t*.24,o-E*e*.08,n+.04],size:[t*.22,e*.42,.1]}))]}),Bn(zo,{color:y,children:[Bn(Hl,{children:[De(Gf,{center:[0,T,D],size:[Q-.2,k+b*.5,w-.2],roundRadius:.22}),De(Xt,{center:[0,T-E*b*.2,D-.05],size:[Q-1.25,k+b,w-1.35]})]}),De(Xt,{center:[0,H,D],size:[Q-1.15,b,w-1.25]}),De(Gf,{center:[0,B-E*k*.28,1.55],size:[Q-2.6,k*.5,1.15],roundRadius:.16}),[-1,1].map(ie=>De(Qs,{center:[ie*h,d,-.25],radius:Math.max(m*.41,.65),height:2.7}))]}),Bn(zo,{color:x,children:[U.map(({x:ie,y:se},ne)=>De(Qs,{center:[ie,se,.15],radius:G,height:3.1})),Wen(8).map(ie=>De(Fo,{offset:[(ie-3.5)*j,ee,W+(ie%2===0?.03:-.03)],children:De($A,{rotation:[E*.2,0,0],children:De(Gf,{size:[Math.max(j*.28,.28),3.25,.16],roundRadius:.05})})})),i&&Y.map((ie,se)=>De(Qs,{center:[ie,f,.15],radius:G,height:3.1}))]}),i&&Bn(fi,{children:[De(Gf,{color:"#73b744",center:[-t/2+2.05,B+E*b*.35,n-2.05],size:[2.15,b*1.55,1.45],roundRadius:.18}),De(Gf,{color:"#e0aa35",center:[t/2-2.05,B+E*b*.35,n-2.05],size:[2.15,b*1.55,1.45],roundRadius:.18})]})]})},rdi=({bodyWidth:t=6.1,bodyLength:e=6.5,bodyHeight:n=2.3,tabWidth:o=6.2,tabLength:i=5.8,span:r=6.85,pitch:s=2.29,leadWidth:a=.9,leadContactLength:A=1.5,color:c="#222",tabColor:l="#cccccc",leadColor:g="#cccccc"})=>{const h=r/2,d=-r/2,m=h+(o-t)/2,p=m-t/2,_=.5/2,f=.4;return Bn(fi,{children:[De(zo,{color:l,children:De(Xt,{size:[o,i,.5],center:[h,0,.5/2]})}),De(zo,{color:c,children:De(Xt,{size:[t,e,n],center:[m,0,.5+n/2]})}),[-1,1].map(I=>Bn(zo,{color:g,children:[De(Xt,{size:[A,a,f],center:[d+A/2,I*s,f/2]}),Bn(KA,{children:[De(Xt,{size:[.1,a,f],center:[d+A,I*s,f/2]}),De(Xt,{size:[.1,a,f],center:[p,I*s,_+.5/2]})]})]},`lead-${I}`))]})},sdi=({diameter:t=6.3,heightToDiameterRatio:e=1.4,height:n=t*e,leadPitch:o=2.5,leadDiameter:i=.6,leadLength:r=3,sleeveColor:s="#1b2a6b",baseColor:a="#1a1a1a"})=>{const A=t/2,c=Math.min(1,t*.12),l=Math.max(n-c,.1),g=c,u=g+l,h=Math.max(t*.06,.2),d=.3;return Bn(fi,{children:[De(zo,{color:a,children:De(Qs,{radius:A-.05,height:c,center:[0,0,c/2]})}),De(zo,{color:s,children:Bn(Hl,{children:[De(Ny,{radius:A,height:l,roundRadius:Math.min(.3,A*.15),center:[0,0,g+l/2]}),De(Xt,{size:[t,h,d*2],center:[0,0,u]}),De(Xt,{size:[h,t,d*2],center:[0,0,u]})]})}),[-1,1].map(m=>De(zo,{color:"#c0c0c0",children:De(Qs,{radius:i/2,height:r+c,center:[m*o/2,0,(c-r)/2]})}))]})},adi=({bodyWidth:t=5.35,bodyLength:e=14,bodyHeight:n=4,bodyCenterX:o=t/2,adjusterDiameter:i=Math.min(t,e)*.55,shaftDiameter:r=0,shaftHeight:s=0,leads:a=[],leadDiameter:A=.6,leadLength:c=3,bodyColor:l="#1f4fa3",adjusterColor:g="#d8d8d8"})=>{const h=n+.4,d=Math.max(i*.16,.3);return Bn(fi,{children:[De(zo,{color:l,children:De(Xt,{size:[t,e,n],center:[o,0,n/2]})}),De(zo,{color:g,children:Bn(Hl,{children:[De(Qs,{radius:i/2,height:.8,center:[o,0,h]}),De(Xt,{size:[i,d,.8*.6],center:[o,0,h+.8/2]})]})}),s>0&&r>0?De(zo,{color:g,children:De(Qs,{radius:r/2,height:s,center:[o,0,n+s/2]})}):null,a.map(m=>De(zo,{color:"#c0c0c0",children:De(Qs,{radius:A/2,height:n/2+c,center:[m.x,m.y,(n/2-c)/2]})},`lead-${m.x}-${m.y}`))]})},Adi=({bodyWidth:t=2.9,bodyLength:e=3,bodyHeight:n=1.4,actuatorDiameter:o=1.5,actuatorHeight:i=.5,padSpanX:r=4.2,padSpanY:s=2.15,padWidth:a=1.05,padLength:A=.7,bodyColor:c="#2b2b2b",actuatorColor:l="#d9d9d9",leadColor:g="#cccccc"})=>Bn(fi,{children:[De(zo,{color:c,children:De(Xt,{size:[t,e,n],center:[0,0,n/2]})}),De(zo,{color:l,children:De(Qs,{radius:o/2,height:i,center:[0,0,n+i/2]})}),[-1,1].flatMap(h=>[-1,1].map(d=>De(zo,{color:g,children:De(Xt,{size:[a,A,.15],center:[h*r/2,d*s/2,.15/2]})})))]}),cdi=({footprint:t="smdslideswitch7",position:e=0})=>{const n=t.replace(/_pin1location\([^)]*\)/g,""),o=W1.string(n).json(),i=W1.string(n).circuitJson(),r=i.filter(u=>u.type==="pcb_smtpad"&&u.shape==="rect"),s=W1.string(t).circuitJson().filter(u=>u.type==="pcb_smtpad"&&(u.shape==="rect"||u.shape==="rotated_rect"));if(r.length<7||!Number.isFinite(o.mpx)||o.mpx<3)throw new Error("SmdSlideSwitch needs signal pads and four mounting pads");const a=Math.atan2(s[1].y-s[0].y,s[1].x-s[0].x)-Math.atan2(r[1].y-r[0].y,r[1].x-r[0].x),A=o.mpx-.5,c=2.7,l=o.mpx>6?1.5:1.4,g=o.mounty;return Bn($A,{rotation:[0,0,a],children:[De(zo,{color:"#aeb4ba",children:Bn(Hl,{children:[De(Xt,{size:[A,c,l],center:[0,g,l/2]}),De(Xt,{size:[A-.3,c-.3,l],center:[0,g,l/2-.15]}),De(Xt,{size:[2.7,.5,.9],center:[0,g-c/2,.65]})]})}),Bn(zo,{color:"#28292c",children:[De(Xt,{size:[A-.32,c-.32,.35],center:[0,g,.175]}),De(Xt,{size:[1,2.25,.65],center:[e===0?-.5:.5,g-1.5,.65]}),i.filter(u=>u.type==="pcb_hole").map((u,h)=>"hole_diameter"in u&&"x"in u?De(Qs,{radius:u.hole_diameter*.42,height:.6,center:[u.x,u.y,-.2]}):null)]}),De(zo,{color:"#c6c7c9",children:r.map((u,h)=>{const d=h<r.length-4,m=u.y+u.height*.4,p=Math.min(u.y-u.height*.4,g+c/2-.2);return De(Xt,{size:[u.width*.8,d?m-p:u.height*.8,.18],center:[u.x,d?(m+p)/2:u.y,.09]},h)})})]})},ldi=({fullWidth:t=1.94,fullLength:e=1.6})=>Bn(fi,{children:[De($A,{rotation:[45*Math.PI,0,0],children:De(Fo,{center:[0,0,-.4],children:De(zo,{color:"grey",children:De(Xt,{size:[1.2,1.6,.55]})})})}),[-1,0,1].flatMap((l,g)=>[De(Fo,{center:[-1.2/2-.03,l*.5,.13/2],children:De(Xt,{size:[.67,.3,.13]})}),De(Fo,{center:[1.2/2+.03,l*.5,.13/2],children:De(Xt,{size:[.67,.3,.13]})})])]}),gdi=({packageWidth:t=10,packageLength:e=10,packageHeight:n=1.2,standoffHeight:o=.2,ballPitch:i=.8,ballDiameter:r=.5,ballRows:s=8,ballColumns:a=8,missingBalls:A=[],footprintString:c})=>{const l=n-o,g=o+l/2,u=Math.max(o/2,r/2),h=c?W1.string(c).circuitJson():null;return Bn(fi,{children:[De(Fo,{z:g,children:De(zo,{color:"#555",children:De(Xt,{size:[t,e,l]})})}),!c&&Array.from({length:s*a}).map((d,m)=>{if(A.includes(m+1))return null;const p=Math.floor(m/a),f=(m%a-(a-1)/2)*i,I=(p-(s-1)/2)*i;return De(Fo,{x:f,y:I,z:u,children:De(pG,{radius:r/2})})}),h&&h.map((d,m)=>d.type==="pcb_smtpad"?De(Fo,{x:d.x,y:d.y,z:u,children:De(pG,{radius:r/2})}):null)]})},jen=({width:t,height:e,depth:n})=>De(KA,{children:[-1,1].map(o=>De(Fo,{offset:[o*(t-e)/2,0,0],children:De($A,{rotation:[Math.PI/2,0,0],children:De(Qs,{radius:e/2,height:n})})},o))}),udi=({footprint:t="usbcmidmount16"})=>{const e=t.replace(/_pin1location\([^)]*\)/g,""),n=W1.string(e).json(),o=W1.string(e).circuitJson(),i=o.filter(C=>C.type==="pcb_smtpad"&&C.shape==="rect"),r=o.filter(C=>C.type==="pcb_plated_hole"),s=o.filter(C=>C.type==="pcb_hole"),a=W1.string(t).circuitJson().find(C=>C.type==="pcb_plated_hole"),A=r[0],c=A&&a&&"x"in a?Math.atan2(a.y,a.x)-Math.atan2(A.y,A.x):0,l=8.94,g=3.2,u=.22,h=n.rowy+.23,d=-n.bodybottom,m=h-d,p=(h+d)/2,_=1.65;if(!Number.isFinite(m)||m<3||r.length!==4)throw new Error("UsbCMidmount requires four mounting slots and a positive body depth");const f=-.9,I=_+.1;return Bn($A,{rotation:[0,0,c],children:[De(zo,{color:"#b8bdc4",children:De(Fo,{offset:[0,p,_],children:Bn(Hl,{children:[De(jen,{width:l,height:g,depth:m}),De(jen,{width:l-u*2,height:g-u*2,depth:m+.2})]})})}),Bn(zo,{color:"#242529",children:[De(Xt,{size:[6.65,m-1.1,.7],center:[0,p+.3,_]}),De(Xt,{size:[7.6,1,2.45],center:[0,h-.65,_]}),s.map((C,y)=>"x"in C&&"hole_diameter"in C?De(Qs,{radius:C.hole_diameter*.42,height:.8,center:[C.x,C.y,-.3]}):null)]}),Bn(zo,{color:"#d3ad57",children:[[-1,1].flatMap(C=>[-2.75,-2.25,-1.25,-.25,.25,1.25,2.25,2.75].map(y=>De(Xt,{size:[.24,m-2,.04],center:[y,p+.1,_+C*.365]}))),i.map((C,y)=>De(Xt,{size:[Math.min(C.width*.7,.35),C.height*.8+.35,.15],center:[C.x,C.y-.175,.075]}))]}),De(zo,{color:"#b8bdc4",children:r.map((C,y)=>De(Xt,{size:[.4,"hole_height"in C?Math.max(.3,C.hole_height-.2):1,I-f],center:[C.x,C.y,(I+f)/2]},y))})]})},Xen=t=>W1.string(t).circuitJson().filter(e=>e.type==="pcb_smtpad"&&(e.shape==="rect"||e.shape==="rotated_rect")).map(e=>({x:e.x,y:e.y,pin:e.port_hints?.[0]})),ddi=({footprint:t="sot143"})=>{const e=Xen(t);if(e.length!==4)throw new Error("SOT143 requires four signal pads");const n=Xen("sot143"),o=W1.string(t).json(),i=n[1],r=e.find(A=>A.pin==="2"),s=o.pin1location?Math.round((Math.atan2(r.y,r.x)-Math.atan2(i.y,i.x))/(Math.PI/2))*(Math.PI/2):0,a=e.map(A=>({...A,x:A.x*Math.cos(s)+A.y*Math.sin(s),y:-A.x*Math.sin(s)+A.y*Math.cos(s)}));return Bn($A,{rotation:[0,0,s],children:[De(Kg,{width:2.9,length:1.3,height:.95,heightAboveSurface:.05,center:{x:0,y:0,z:0},includeNotch:!1,taperRatio:.06}),a.map(A=>{const c=A.y<0?-1:1,l=A.pin==="1"?.83:.43;return De($r,{width:l,thickness:.12,height:.45,padContactLength:.3,bodyDistance:.6,rotation:c<0?Math.PI/2:-Math.PI/2,position:{x:A.x,y:c*1.15,z:.06}},A.pin)})]})},hdi=16/9,mdi=40,bS=1e-6,z_=(t,e)=>{if(!Number.isFinite(e)||e<=0)throw new Error(`${t} must be a finite number greater than zero`)},pdi=t=>{if(t===void 0)return hdi;if(typeof t=="number")return z_("aspectRatio",t),t;if(typeof t!="string"){const[i,r]=t;return z_("aspectRatio width",i),z_("aspectRatio height",r),i/r}const e=t.split(":");if(e.length!==2)throw new Error('aspectRatio must look like "16:9"');const n=Number(e[0]),o=Number(e[1]);return z_("aspectRatio width",n),z_("aspectRatio height",o),n/o},_di=({width:t,height:e,diagonal:n,aspectRatio:o,ratio:i,defaultDiagonal:r=mdi})=>{const s=pdi(o??i);t!==void 0&&z_("width",t),e!==void 0&&z_("height",e),n!==void 0&&z_("diagonal",n),z_("defaultDiagonal",r);let a,A;if(t!==void 0&&e!==void 0)a=t,A=e;else if(n!==void 0&&t!==void 0){if(t>=n)throw new Error("width must be smaller than diagonal");a=t,A=Math.sqrt(n**2-t**2)}else if(n!==void 0&&e!==void 0){if(e>=n)throw new Error("height must be smaller than diagonal");a=Math.sqrt(n**2-e**2),A=e}else t!==void 0?(a=t,A=t/s):e!==void 0?(a=e*s,A=e):(A=(n??r)/Math.sqrt(s**2+1),a=A*s);return{width:a,height:A,diagonal:Math.hypot(a,A),aspectRatio:a/A}},fdi=t=>{const e=[["sitsFlat",t.sitsFlat],["sitsFlatBelowBoard",t.sitsFlatBelowBoard],["foldedToFaceAboveBoard",t.foldedToFaceAboveBoard],["foldedToFaceBelowBoard",t.foldedToFaceBelowBoard],["foldedToFaceAboveBoard",t.foldsAboveBoard],["foldedToFaceBelowBoard",t.foldsBelowBoard],["foldedToRightAngleAboveBoard",t.foldedToRightAngleAboveBoard],["foldedToRightAngleBelowBoard",t.foldedToRightAngleBelowBoard]].filter(n=>n[1]);if(e.length>1)throw new Error("Only one FlexScreen boolean orientation shortcut can be true");return e[0]?.[0]??t.orientation??"sitsFlat"},Idi=(t,e)=>Math.hypot(e[0]-t[0],e[1]-t[1],e[2]-t[2]),Cdi=(t,e,n)=>[t[0]+(e[0]-t[0])*n,t[1]+(e[1]-t[1])*n,t[2]+(e[2]-t[2])*n],GYe=t=>{const e=[0];for(let n=1;n<t.length;n+=1)e.push(e[n-1]+Idi(t[n-1],t[n]));return e},qen=(t,e,n)=>{if(n<=0)return t[0];const o=e.at(-1);if(n>=o)return t.at(-1);for(let i=1;i<t.length;i+=1)if(e[i]>=n){const r=e[i-1],s=e[i]-r;return Cdi(t[i-1],t[i],(n-r)/s)}return t.at(-1)},Oue=(t,e,n)=>{const o=GYe(t),i=o.at(-1),r=Math.max(0,Math.min(e,i)),s=Math.max(r,Math.min(n,i)),a=[qen(t,o,r)];for(let A=1;A<t.length-1;A+=1)o[A]>r&&o[A]<s&&a.push(t[A]);return a.push(qen(t,o,s)),a},ydi=(t,e)=>[t,[t[0],t[1]+e,t[2]]],xdi=({start:t,endZ:e,flexCableLength:n,foldDistanceFromConnector:o,foldOutset:i,foldSegments:r})=>{const s=[t],a=[t[0],t[1]+o,t[2]];o>bS&&s.push(a);for(let l=1;l<=r;l+=1){const g=Math.PI*l/r;s.push([t[0],a[1]+i*Math.sin(g),t[2]+(e-t[2])*(1-Math.cos(g))/2])}const A=GYe(s).at(-1);if(A>n+bS)throw new Error(`flexCableLength must be at least ${A.toFixed(2)} for this 180-degree fold`);const c=Math.max(0,n-A);if(c>bS){const l=s.at(-1);s.push([l[0],l[1]-c,l[2]])}return s},Edi=({start:t,flexCableLength:e,bendRadius:n,bendSegments:o,verticalLead:i,direction:r})=>{const s=2*o*Math.sin(Math.PI/(4*o)),a=Math.min(n,e/s),A=a*s,c=Math.max(0,e-A),l=Math.min(i,c*.45),g=c-l,u=[t];g>bS&&u.push([t[0],t[1]+g,t[2]]);for(let h=1;h<=o;h+=1){const d=Math.PI/2*h/o;u.push([t[0],t[1]+g+a*Math.sin(d),t[2]+r*a*(1-Math.cos(d))])}if(l>bS){const h=u.at(-1);u.push([h[0],h[1],h[2]+r*l])}return u},ZX=({points:t,width:e,thickness:n,color:o,acrossOffset:i=0,normalOffset:r=0,overlap:s=.03})=>De(zo,{color:o,children:t.slice(1).map((a,A)=>{const c=t[A],l=a[0]-c[0],g=a[1]-c[1],u=a[2]-c[2],h=Math.hypot(l,g,u);if(h<bS)return null;const d=Math.asin(u/h),m=Math.atan2(-l,g),p=[(c[0]+a[0])/2,(c[1]+a[1])/2,(c[2]+a[2])/2],_=Math.max(.001,Math.min(e,n,h)/2-.001);return De(Fo,{offset:p,children:De($A,{rotation:[d,0,m],children:De(Gf,{size:[e,h+s,n],center:[i,0,r],roundRadius:_})})},`${A}:${p.join(":")}`)})}),Bdi=t=>{const{width:e,height:n,diagonal:o,aspectRatio:i,ratio:r,defaultDiagonal:s,screenThickness:a=1.2,bezelInset:A=2,bezelDepth:c=.65,activeAreaWidth:l,activeAreaHeight:g,screenColor:u="#071b24",bezelColor:h="#15181d",showScreen:d=!0,flexCableLength:m=28,flexCableThickness:p=.18,flexCableColor:_="#d79528",conductorCount:f=8,conductorPitch:I,conductorWidth:C,conductorThickness:y=.035,conductorColor:x="#8c4a18",cableEdgeMargin:E=.6,exposedContactLength:B=2.4,showConductors:b=!0,showFlexCable:Q=!0,showStiffeners:w=!0,stiffenerLength:D=3,stiffenerThickness:k=.16,stiffenerColor:T="#416bb3",bendRadius:H=3,bendSegments:G=10,rightAngleVerticalLead:U=3,distanceAboveBoard:Y=7,distanceBelowBoard:j=7,foldDistanceFromConnector:ee=7,foldOutset:W=4,foldSegments:Z=18,screenGap:ie=.08,boardTopZ:se=0,boardThickness:ne=1.6,boardClearance:le=.15,cableStartX:he=0,cableStartY:Ie=0,cableStartZ:ce,cableLateralOffset:fe=0,screenOffset:de,screenRotation:Ce,rotation:Qe=[0,0,0],offset:Pe}=t,pe=_di({width:e,height:n,diagonal:o,aspectRatio:i,ratio:r,defaultDiagonal:s}),ve=fdi(t),we=ve==="sitsFlatBelowBoard"||ve==="foldedToFaceBelowBoard"||ve==="foldedToRightAngleBelowBoard",Me=ve==="foldedToFaceAboveBoard"||ve==="foldedToFaceBelowBoard",Oe=ve==="foldedToRightAngleAboveBoard"||ve==="foldedToRightAngleBelowBoard";if(z_("screenThickness",a),z_("flexCableLength",m),z_("flexCableThickness",p),z_("conductorThickness",y),z_("bendRadius",H),z_("foldOutset",W),z_("boardThickness",ne),w&&z_("stiffenerThickness",k),!Number.isInteger(f)||f<1)throw new Error("conductorCount must be a positive integer");if(!Number.isInteger(G)||G<2)throw new Error("bendSegments must be an integer of at least 2");if(!Number.isInteger(Z)||Z<4)throw new Error("foldSegments must be an integer of at least 4");if(le<0||ie<0||E<0||B<0||D<0||U<0||Y<0||j<0||ee<0)throw new Error("clearances, margins, contact lengths, and lead lengths cannot be negative");const ke=t.flexCableWidth??Math.min(12,Math.max(5,pe.width*.3));z_("flexCableWidth",ke);const be=ke-E*2;if(be<=0)throw new Error("cableEdgeMargin leaves no usable flex cable width");const He=I??(f===1?0:be/f);if(f>1&&(!Number.isFinite(He)||He<=0))throw new Error("conductorPitch must be greater than zero");const ye=C??(f===1?Math.min(be,ke*.45):He*.48);if(z_("conductorWidth",ye),(f-1)*He+ye>be+bS)throw new Error("conductorPitch and conductorWidth do not fit inside the flex cable margins");const qe=we&&!Me?se-ne-le-p/2:se+le+p/2,st=[he+fe,Ie,ce??qe],At=we?-1:1,nt=ve==="foldedToFaceAboveBoard"?se+Y:se-ne-j,it=ve==="foldedToFaceAboveBoard"?nt-ie-p/2:nt+ie+p/2,Bt=Me?xdi({start:st,endZ:it,flexCableLength:m,foldDistanceFromConnector:ee,foldOutset:W,foldSegments:Z}):Oe?Edi({start:st,flexCableLength:m,bendRadius:H,bendSegments:G,verticalLead:U,direction:At}):ydi(st,m),It=GYe(Bt).at(-1),kt=Math.min(Math.max(0,B),It/2),Ft=Math.min(Math.max(0,D),It/2),Ct=Oue(Bt,0,kt),Jt=Oue(Bt,It-kt,It),Cn=Oue(Bt,0,Ft),Be=Oue(Bt,It-Ft,It),$e=Bt.at(-1);let _t,ut;ve==="sitsFlat"?(_t=[0,0,0],ut=[$e[0],$e[1]+pe.height/2,$e[2]+p/2+ie]):ve==="sitsFlatBelowBoard"?(_t=[0,Math.PI,0],ut=[$e[0],$e[1]+pe.height/2,$e[2]-p/2-ie]):ve==="foldedToFaceAboveBoard"?(_t=[0,0,0],ut=[$e[0],$e[1]-pe.height/2,nt]):ve==="foldedToFaceBelowBoard"?(_t=[0,Math.PI,0],ut=[$e[0],$e[1]-pe.height/2,nt]):ve==="foldedToRightAngleAboveBoard"?(_t=[Math.PI/2,0,0],ut=[$e[0],$e[1]-p/2-ie,$e[2]+pe.height/2]):(_t=[-Math.PI/2,0,0],ut=[$e[0],$e[1]+p/2+ie,$e[2]-pe.height/2]),ut=[ut[0]+(de?.x??0),ut[1]+(de?.y??0),ut[2]+(de?.z??0)];const Xe=Array.from({length:f},(rt,ht)=>f===1?0:(ht-(f-1)/2)*He),pt=(p+y)/2,bt=-(p+k)/2,et=Bn(fi,{children:[Q&&De(ZX,{points:Bt,width:ke,thickness:p,color:_}),Q&&w&&Ft>bS&&Bn(fi,{children:[De(ZX,{points:Cn,width:ke,thickness:k,color:T,normalOffset:bt}),De(ZX,{points:Be,width:ke,thickness:k,color:T,normalOffset:bt})]}),Q&&b&&kt>bS&&Xe.map((rt,ht)=>Bn(fi,{children:[De(ZX,{points:Ct,width:ye,thickness:y,color:x,acrossOffset:rt,normalOffset:pt}),De(ZX,{points:Jt,width:ye,thickness:y,color:x,acrossOffset:rt,normalOffset:pt})]},`conductor:${ht}`)),d&&De(Fo,{offset:ut,children:De($A,{rotation:Ce??_t,children:De(Uen,{width:pe.width,height:pe.height,thickness:a,bezelInset:A,bezelDepth:c,screenWidth:l,screenHeight:g,screenColor:u,bezelColor:h})})})]});return De(Fo,{offset:{x:Pe?.x??0,y:Pe?.y??0,z:Pe?.z??0},children:De(Fo,{offset:st,children:De($A,{rotation:Qe,children:De(Fo,{offset:[-st[0],-st[1],-st[2]],children:et})})})})},Sdi=({footprint:t})=>{const e=_Ye.string(t.split("_",1)[0]).params().fn;if(_Ye.getModelNames().includes(e)){const A=_Ye.string(t).json();if(A.fn==="flexscreen"){const{fn:c,...l}=A;return De(Bdi,{...l})}}let n=t;if(t.startsWith("jstzh1_5mm")){const A=t.match(/jstzh1_5mm(\d+)?/);n=`zh${A&&A[1]?A[1]:"7"}`}else if(t.startsWith("jstph2_0mm")){const A=t.match(/jstph2_0mm(\d+)?/);n=`jst${A&&A[1]?A[1]:"2"}_ph`}else if(t.startsWith("jstxh2_5mm")){const A=t.match(/jstxh2_5mm(\d+)?/);n=`jst${A&&A[1]?A[1]:"2"}_xh`}const o=W1.string(n).json(),i=t.match(/_color\(([^)]+)\)/),r=i?i[1]:void 0,s=(A,c)=>{if(A==null)return c;const l=za(A);return Number.isFinite(l)?l:c},a=Bgi(o);if(a)return a;switch(o.fn){case"crystal":return De(Jui,{horizontalPadPitch:o.px,verticalPadPitch:o.py,padWidth:o.pw,padHeight:o.ph});case"dip":return De(Pgi,{numPins:o.num_pins,pitch:o.p,bodyWidth:o.w});case"axial":return De(Fui,{pitch:o.p});case"tssop":return De(Dgi,{pinCount:o.num_pins,leadLength:o.pl,leadWidth:o.pw,pitch:o.p,bodyWidth:o.w});case"msop":return De(Rgi,{pinCount:o.num_pins,padContactLength:o.pl,leadWidth:o.pw,pitch:o.p,bodyWidth:o.w});case"vssop":return De(rui,{pinCount:o.num_pins,leadLength:o.pl,leadWidth:o.pw,pitch:o.p,bodyWidth:o.w,bodyLength:o.h});case"qfp":return De(xen,{pinCount:o.num_pins,pitch:o.p,leadWidth:o.pw,padContactLength:o.pl,bodyWidth:o.w});case"tqfp":return De(pui,{});case"lqfp":return De(Cui,{pinCount:o.num_pins});case"qfn":{const A=typeof o.thermalpad?.x=="number"&&typeof o.thermalpad?.y=="number";return De(Sen,{num_pins:o.num_pins,bodyWidth:o.w,bodyLength:o.h,pitch:o.p,padLength:o.pl,padWidth:o.pw,thermalPadSize:A?{width:o.thermalpad.x,length:o.thermalpad.y}:void 0})}case"dfn":{const A=typeof o.thermalpad?.x=="number"&&typeof o.thermalpad?.y=="number";return De(Len,{num_pins:o.num_pins,bodyWidth:o.w,bodyLength:o.h,pitch:o.p,padLength:o.pl,padWidth:o.pw,thermalPadSize:A?{width:o.thermalpad.x,length:o.thermalpad.y}:void 0})}case"pinrow":{const A=t.match(/_rows(\d+)/),c=A&&A[1]?parseInt(A[1],10):1;if(o.male)return De(Ben,{numberOfPins:o.num_pins,pitch:o.p,invert:o.invert,rows:c,smd:o.smd||o.surface_mount,rightangle:o.rightangle});if(o.female)return De(tui,{numberOfPins:o.num_pins,pitch:o.p,rows:c})}case"smdpinheader":return De(Zui,{numberOfPins:o.num_pins,pitch:o.p,bodyWidth:o.bh});case"led5050":return De(ndi,{color:r});case"cap":{switch(o.imperial){case"0402":return De(Ien,{color:"#856c4d"});case"0603":return De(Cen,{color:"#856c4d"});case"0805":return De(yen,{color:"#856c4d"});case"0201":return De(Qen,{color:"#856c4d"});case"01005":return De(ven,{color:"#856c4d"});case"1206":return De(Pen,{color:"#856c4d"});case"1210":return De(wen,{color:"#856c4d"});case"2010":return De(Men,{color:"#856c4d"});case"2512":return De(Den,{color:"#856c4d"})}break}case"sot23":switch(o.num_pins){case 3:return De(Jgi,{color:r});case 5:return De(ben,{})}break;case"sot25":return De(ben,{});case"sot":case"sot343":{const A=o.fn==="sot343";return De(edi,{pads:Jen(n),bodyWidth:A?1.25:1.6,bodyLength:A?2:2.9,bodyHeight:A?1.1:1.3})}case"sot563":return De(ldi,{});case"sot89":{const A=s(o.w,4.2);return De(Fen,{fullWidth:A,bodyWidth:A*.6,bodyLength:s(o.h,4.8)*.94,bodyHeight:1.5,leadWidth:s(o.pw,.48),tabLeadWidth:s(o.pw,.48)*2,padPitch:s(o.p,1.5),leadHeight:.66})}case"sot457":return De(vui,{});case"smdslideswitch":return De(cdi,{footprint:n});case"usbcmidmount":return De(udi,{footprint:n});case"sot143":return De(ddi,{footprint:n});case"sot223":return De(Fen,{});case"sot23w":return De(Wgi,{});case"sot323":return De(_ui,{});case"sod323f":return De(Tui,{});case"sod323fl":return De(kui,{});case"sot363":return De(Nui,{});case"sot886":return De(Rui,{});case"sot963":return De(Pui,{});case"pushbutton":return De(nui,{width:o.w,length:o.h,innerDiameter:o.id});case"jst":if(Ken(n))return De(Vui,{footprint:n});if(o.zh)return De(Yui,{numPins:o.num_pins});if(o.ph)return De(Uui,{numPins:o.num_pins});if(o.xh)return De(Kui,{numPins:o.num_pins});break;case"fpc":return De($ui,{pinCount:o.num_pins,pitch:o.p,padWidth:o.pw,padLength:o.pl,staggered:o.staggered,reverse:o.reverse,rowPitch:o.py,topPadLength:o.toppl,bottomPadLength:o.bottompl,mountPadPitchX:o.mpx,mountPadOffsetY:o.mpy,mountTop:o.mounttop,mountPadWidth:o.mpw,mountPadLength:o.mpl});case"rj45":return De(idi,{bodyWidth:o.w,bodyDepth:o.h,bodyCenterY:o.bodyy,ledPins:o.ledpins||o.num_pins===14,firstPinLeft:o.firstpinleft,firstPinTop:o.firstpintop,signalPitch:o.p,signalRowPitch:o.py,signalHoleDiameter:o.id,shieldPinX:o.shieldx,shieldPinY:o.shieldy,shieldHoleDiameter:o.shieldid,locatorHoleX:o.holex,locatorHoleY:o.holey,locatorHoleDiameter:o.holed,ledPinX:o.ledx,ledPinPitch:o.ledp,ledPinY:o.ledy});case"soic":case"sop8":case"ssop":return De(iui,{pinCount:o.num_pins,leadLength:o.pl,leadWidth:o.pw,pitch:o.p,bodyWidth:o.w});case"son":case"wson":case"vson":{const A=o.fn==="vson"?s(o.grid?.x,3):s(o.w,3),c=o.fn==="vson"?s(o.grid?.y,3):s(o.h,3),l=s(o.epw,0),g=s(o.eph,0),u=o.pl!==void 0?s(o.pl,0):void 0,h=o.pw!==void 0?s(o.pw,0):void 0,d=Jen(n).filter(f=>Number(f.pin??0)<=o.num_pins),m=f=>new Set(f.map(I=>I.toFixed(3))).size,p=d.length>2&&m(d.map(f=>f.y))===2&&m(d.map(f=>f.x))>2,_=De(Len,{num_pins:o.num_pins,bodyWidth:p?c:A,bodyLength:p?A:c,pitch:s(o.p,.5),padLength:u,padWidth:h,thermalPadSize:o.ep&&l>0&&g>0?{width:p?g:l,length:p?l:g}:void 0});return p?De($A,{rotation:[0,0,"90deg"],children:_}):_}case"mlp":case"lga":case"quad":return o.legsoutside?De(xen,{pinCount:o.num_pins,pitch:s(o.p,.5),leadWidth:s(o.pw,.25),padContactLength:s(o.pl,.25),bodyWidth:s(o.w,6)}):De(Sen,{num_pins:o.num_pins,bodyWidth:s(o.w,6),bodyLength:s(o.h,6),pitch:s(o.p,.5),padLength:s(o.pl,.25),padWidth:s(o.pw,.25)});case"bga":{const A=s(o.p,.8),c=o.grid?.x??8,l=o.grid?.y??8;return De(gdi,{ballPitch:A,ballColumns:c,ballRows:l,ballDiameter:A*.625,packageWidth:c*A,packageLength:l*A})}case"sod523":return De(sui,{});case"sod723":return De(Gui,{});case"sod882":return De(Ren,{});case"sma":return De(aui,{});case"smb":return De(Ten,{});case"smc":return De(Aui,{});case"smf":return De(cui,{});case"sod123":return De(uui,{});case"sod123f":return De(lui,{});case"sod123fl":return De(gui,{});case"sod123w":return De(ken,{});case"sod110":return De(ken,{bodyWidth:2.1,bodyLength:1.4});case"sod128":return De(dui,{});case"sod323":return De(Yen,{});case"sod323w":return De(Yen,{});case"sod80":return De(Hen,{});case"sod882d":return De(Ren,{});case"smbf":return De(Ten,{});case"led2835":return De(odi,{color:r,bodyWidth:s(o.w,3.5),bodyLength:s(o.h,2.8),pad1X:s(o.p1x,-.9),pad1Width:s(o.p1w,2.2),pad2X:s(o.p2x,1.375),pad2Width:s(o.p2w,1.25),padLength:s(o.ph,2.2)});case"electrolytic":case"radial":{const A=s(o.p,2.5),c=t.match(/_d([\d.]+)/),l=o.d!==void 0?s(o.d,A*2):c?Number(c[1]):A*2;return De(sdi,{diameter:l,leadPitch:A})}case"potentiometer":return De(adi,{bodyWidth:s(o.w,5.35),bodyLength:s(o.ca,14),bodyHeight:s(o.h,4),leads:$X(n)});case"smdpushbutton":return De(Adi,{padSpanX:s(o.px,4.2),padSpanY:s(o.py,2.15),padWidth:s(o.pw,1.05),padLength:s(o.ph,.7)});case"breakoutheaders":{const A=s(o.p,2.54),c=s(o.w,10)/2,l=[{x:-c,pins:o.left??0,key:"left"},{x:c,pins:o.right??0,key:"right"}];return De(fi,{children:l.filter(({pins:g})=>g>0).map(({x:g,pins:u,key:h})=>De(Fo,{center:[g,0,0],children:De($A,{rotation:[0,0,"90deg"],children:De(Ben,{numberOfPins:u,pitch:A})})},h))})}case"sod923":return De(hui,{});case"hc49":return De(xui,{});case"micromelf":return De(Eui,{});case"minimelf":return De(Hen,{});case"melf":return De(Bui,{});case"ms012":return De(Sui,{pinCount:o.num_pins,padContactLength:o.pl,leadWidth:o.pw,pitch:o.p});case"ms013":return De(bui,{pinCount:o.num_pins,padContactLength:o.pl,leadWidth:o.pw,pitch:o.p});case"sot723":return De(yui,{});case"to220":return De(Oen,{leads:$X(n)});case"to220f":return De(Oen,{mouldedTab:!0,leads:$X(n)});case"to92":return De(Gen,{leads:$X(n)});case"to92l":case"to92s":{const A=s(o.w,4.8),c=s(o.h,4),l=Math.max(A,c);return De(Gen,{bodyDiameter:l,flatCut:Math.max(l-Math.min(A,c),.4),leads:$X(n)})}case"to252":case"dpak":case"to263":case"d2pak":{const A=o.fn==="to263"||o.fn==="d2pak",c=s(o.tabw,A?8.38:6.2),l=Math.min(s(o.tabh,A?10:5.8),A?10:6.5);return De(rdi,{bodyWidth:c,bodyLength:s(o.w,A?10.1:6.6),bodyHeight:A?4.4:2.3,tabWidth:c,tabLength:l,span:s(o.span,A?10.21:6.85),pitch:s(o.p,A?2.54:2.29),leadWidth:s(o.pw,1.5),leadContactLength:s(o.pl,3)})}case"stampboard":case"stampreceiver":return De(Lui,{bodyWidth:o.w,leadsLeft:o.left,leadsRight:o.right,leadsTop:o.top,leadsBottom:o.bottom,leadsPitch:o.p,leadWidth:o.pw,leadLength:o.pl,innerHoles:o.innerhole,innerHoleEdgeDistance:o.innerholeedgedistance});case"mountedpcbmodule":{const A=o.rows??1,c=o.pinRowSide??"left",l=o.holeInset,g=o.width,u=o.height,h=o.pinrow,d=o.pinRowHoleEdgeToEdgeDist,m=Array.isArray(o.holes)?o.holes:[];return De(Hui,{numPins:h,rows:A,p:o.p,id:o.id,od:o.od,width:g,height:u,pinRowSide:c,holes:m,holeInset:l,pinRowHoleEdgeToEdgeDist:d,nopin:o.nopin,female:o.female,screen:o.screen,screenWidth:o.screenwidth,screenHeight:o.screenheight,screenCenterOffsetX:o.screencenteroffsetx,screenCenterOffsetY:o.screencenteroffsety})}}switch(o.imperial){case"0402":return De(Ien,{color:r});case"0603":return De(Cen,{color:r});case"0805":return De(yen,{color:r});case"0201":return De(Qen,{color:r});case"01005":return De(ven,{color:r});case"1206":return De(Pen,{color:r});case"1210":return De(wen,{color:r});case"2010":return De(Men,{color:r});case"2512":return De(Den,{color:r})}if((o.fn==="res"||o.fn==="cap")&&o.p!==void 0&&o.ph!==void 0){const A=za(o.p),c=za(o.ph);if(Number.isFinite(A)&&Number.isFinite(c))return De(tdi,{padPitch:A,padHeight:c,color:r??(o.fn==="cap"?"#856c4d":void 0)})}return null},bdi=t=>t&&typeof t=="object"&&"type"in t,PG=t=>{if(typeof t=="number")return t;if(typeof t=="string"){const e=/^(-?\d+(?:\.\d+)?)\s*deg$/i.exec(t);if(e)return parseFloat(e[1])*Math.PI/180;const n=Number(t);if(!Number.isNaN(n))return n}return 0},Qdi=t=>Array.isArray(t)?[Number(t[0])||0,Number(t[1])||0,Number(t[2])||0]:typeof t=="object"&&t?[Number(t.x)||0,Number(t.y)||0,Number(t.z)||0]:[0,0,0];function j6(t,e,n){const{jscad:{primitives:o,booleans:i,hulls:r,geometries:s,extrusions:a,transforms:A}}=n;if(t==null||t===!1)return[];if(Array.isArray(t))return t.flatMap(u=>j6(u,e,n));if(!bdi(t))return[];const{type:c,props:l,children:g}=t;if(c===pen)return(g??[]).flatMap(u=>j6(u,e,n));if(c===zo){const u=l?.color;return(g??[]).flatMap(h=>j6(h,u??e,n))}if(c===Fo){const u=Qdi(l?.offset??l?.center??{x:l?.x,y:l?.y,z:l?.z});return(g??[]).flatMap(d=>j6(d,e,n)).map(({geom:d,color:m})=>({geom:A.translate(u,d),color:m??e}))}if(c===$A){const u=l?.angles??l?.rotation,h=Array.isArray(u)?[PG(u[0]),PG(u[1]),PG(u[2])]:[PG(l?.x??0),PG(l?.y??0),PG(l?.z??0)];return(g??[]).flatMap(m=>j6(m,e,n)).map(({geom:m,color:p})=>({geom:A.rotateZ(h[2],A.rotateY(h[1],A.rotateX(h[0],m))),color:p}))}if(c===zd||c===Hl||c===KA){const u=(g??[]).flatMap(d=>j6(d,e,n)).map(d=>d.geom);if(u.length===0)return[];let h;return c===zd?h=i.union(u):c===Hl?h=i.subtract(u[0],u.slice(1)):h=r.hull(u),[{geom:h,color:e}]}if(c===_G){const u=l?.points??[];return[{geom:s.geom2.fromPoints(u),color:e??l?.color}]}if(c===fG){const u=(g??[]).flatMap(p=>j6(p,e,n)).map(p=>p.geom);if(u.length===0)return[];const h=u.length>1?i.union(u):u[0],d=l?.height??l?.h??1;let m=a.extrudeLinear({height:d},h);if(m.polygons)for(const p of m.polygons)!p.plane||!p.vertices||p.vertices.length<3||p.vertices.reverse();return[{geom:m,color:e??l?.color}]}if(c===Xt||c===_en||c===Qs||c===pG||c===Gf||c===Ny){let u;if(c===Xt){const h=l?.size??[1,1,1],d=l?.offset,m=l?.center??(d?[d[0],d[1],d[2]]:[0,0,0]);u=o.cuboid({size:h,center:m})}else if(c===_en){const h=l?.size??1,d=l?.offset,m=l?.center??(d?[d[0],d[1],d[2]]:[0,0,0]);u=o.cube({size:h,center:m})}else if(c===Qs){const h=l?.height??1,d=l?.radius??1,m=l?.center??[0,0,0];u=o.cylinder({height:h,radius:d,center:m})}else if(c===pG){const h=l?.radius??1,d=l?.center??[0,0,0];u=o.sphere({radius:h,center:d})}else if(c===Ny){const h=l?.height??1,d=l?.radius??1,m=l?.roundRadius??.1,p=l?.center??[0,0,0];u=o.roundedCylinder({height:h,radius:d,roundRadius:m,center:p})}else{const h=l?.size??[1,1,1],d=l?.roundRadius??.1,m=l?.center??[0,0,0];u=o.roundedCuboid({size:h,roundRadius:d,center:m})}return[{geom:u,color:e??l?.color}]}if(typeof c=="function"){const u=c(l??{});return j6(u,e,n)}return(g??[]).flatMap(u=>j6(u,e,n))}function vdi(t,e){return{geometries:j6(t,void 0,{jscad:e})}}function $en(t){if(t.polygons){const e=[],n=[],o=[];let i=0;for(const s of t.polygons){for(const A of s.vertices)A.index=i,e.push(A[0],A[1],A[2]),t.color&&t.color.length>=3?o.push(t.color[0],t.color[1],t.color[2]):o.push(1,1,1),i++;const a=s.vertices[0].index;for(let A=2;A<s.vertices.length;A++){const c=s.vertices[A-1].index,l=s.vertices[A].index;n.push(a,c,l)}}const r=new ql;if(r.setAttribute("position",new Lg(new Float32Array(e),3)),r.setIndex(n),o.length>0&&r.setAttribute("color",new Lg(new Float32Array(o),3)),t.transforms){const s=new fa;s.fromArray(t.transforms),r.applyMatrix4(s)}return r.computeVertexNormals(),r}if(t.sides){const e=[],n=[];for(const i of t.sides)e.push(i[0][0],i[0][1],0),t.color&&t.color.length>=3?n.push(t.color[0],t.color[1],t.color[2]):n.push(1,1,1);const o=new ql;if(o.setAttribute("position",new Lg(new Float32Array(e),3)),n.length>0&&o.setAttribute("color",new Lg(new Float32Array(n),3)),t.transforms){const i=new fa;i.fromArray(t.transforms),o.applyMatrix4(i)}return o}return console.error("Invalid CSG object: neither polygons nor sides found"),new ql}function Pdi(t,e){const n=fYe(Sdi,{footprint:t});return vdi(n,e)}var wdi=n0(bue()),Zen=te.createContext(null),Mdi=()=>{const t=te.useContext(Zen);if(!t)throw new Error("useHover must be used within a HoverProvider");return t},Ddi=({children:t})=>{const{camera:e,renderer:n}=J1(),[o,i]=te.useState([]),r=te.useMemo(()=>new fYn,[]),s=te.useMemo(()=>new Xo,[]),a=te.useRef(o);a.current=o;const A=te.useRef(null),c=te.useCallback(d=>{i(m=>[...m,d])},[]),l=te.useCallback(d=>{if(A.current){let m=!1,p=A.current.object;for(;p;){if(p===d){m=!0;break}p=p.parent}m&&(A.current.onUnhover(),A.current=null)}i(m=>m.filter(p=>p.object!==d))},[]),g=te.useCallback(d=>{let m=d;for(;m;){const p=a.current.find(_=>_.object===m);if(p)return p;m=m.parent}},[]),u=te.useCallback(d=>{if(!n.domElement)return;const m=n.domElement.getBoundingClientRect();s.x=(d.clientX-m.left)/m.width*2-1,s.y=-((d.clientY-m.top)/m.height)*2+1,r.setFromCamera(s,e);const p=a.current.map(f=>f.object);if(p.length===0){A.current&&(A.current.onUnhover(),A.current=null);return}const _=r.intersectObjects(p,!0);if(_.length>0){const f=_[0],I=g(f.object);if(I){const C={mousePosition:[f.point.x,f.point.y,f.point.z]};A.current!==I?(A.current?.onUnhover(),I.onHover(C),A.current=I):I.onHover(C)}else A.current&&(A.current.onUnhover(),A.current=null)}else A.current&&(A.current.onUnhover(),A.current=null)},[e,n,r,s,g]);te.useEffect(()=>{const d=n.domElement;return d.addEventListener("mousemove",u),()=>{d.removeEventListener("mousemove",u)}},[n,u]);const h=te.useMemo(()=>({addHoverable:c,removeHoverable:l}),[c,l]);return z.jsx(Zen.Provider,{value:h,children:t})},Ndi=({children:t,object:e,onHover:n,onUnhover:o,isHovered:i})=>{const{addHoverable:r,removeHoverable:s}=Mdi();return te.useEffect(()=>e?(r({object:e,onHover:n,onUnhover:o}),()=>{s(e)}):void 0,[e,n,o,r,s]),z.jsx(z.Fragment,{children:t})},eq=Ndi,_B=(t,{castShadow:e=!0,receiveShadow:n=!0}={})=>{t.traverse(o=>{o instanceof wr&&(o.castShadow=e,o.receiveShadow=n)})},Rdi=({positionOffset:t,footprint:e,rotationOffset:n,onHover:o,onUnhover:i,isHovered:r,scale:s,isTranslucent:a=!1})=>{const{rootObject:A}=J1(),c=te.useMemo(()=>{if(!e)return null;const{geometries:l}=Pdi(e,wdi),g=new xh;for(const u of l.flat(1/0)){const h=u.geom;if(!h||!h.polygons&&!h.sides)continue;const d=new Hi(u.color);d.convertLinearToSRGB();const m={...h,color:[d.r,d.g,d.b]},p=$en(m),_=new hg({vertexColors:!0,side:S_,transparent:a,opacity:a?.5:1,depthWrite:!a}),f=new wr(p,_);f.renderOrder=a?2:1,_B(f,{castShadow:!a,receiveShadow:!0}),g.add(f)}return g},[e,a]);return te.useEffect(()=>{if(!(!c||!A))return A.add(c),()=>{A.remove(c)}},[A,c]),te.useEffect(()=>{c&&(t&&c.position.fromArray(t),n&&c.rotation.fromArray(n),s!==void 0&&c.scale.setScalar(s))},[c,t?.[0],t?.[1],t?.[2],n?.[0],n?.[1],n?.[2],s]),te.useEffect(()=>{c&&c.traverse(l=>{l instanceof wr&&l.material instanceof hg&&(r?(l.material.emissive.setHex(255),l.material.emissiveIntensity=.2):l.material.emissiveIntensity=0)})},[r,c]),c?z.jsx(eq,{isHovered:r,onHover:o,onUnhover:i,object:c}):null},etn=new WeakMap,Tdi=()=>{const t=new _u;return t.name="fallback-environment-map",t.mapping=Xoe,t},kdi=t=>{if(!t)return null;const e=t,n=etn.get(e);if(n)return n;let o;if(t instanceof vie){const i=new iBe(t);o=i.fromScene(YYn(),.04).texture,i.dispose()}else o=Tdi();return etn.set(e,o),o};function Fdi(t){const e=new U2;let n=!1;t.updateWorldMatrix(!0,!1);const o=t.parent?t.parent.matrixWorld.clone().invert():new fa;return t.traverse(i=>{if(i.updateWorldMatrix(!0,!1),i instanceof wr&&i.geometry&&(i.geometry.boundingBox||i.geometry.computeBoundingBox(),i.geometry.boundingBox)){const r=o.clone().multiply(i.matrixWorld),s=i.geometry.boundingBox.clone();s.applyMatrix4(r),n?e.union(s):(e.copy(s),n=!0)}}),n?e:null}function Ldi(t){const e=Fdi(t);return e?e.getSize(new jt):new jt}function Hdi(t,e,n="contain_within_bounds"){if(!e)return[1,1,1];const o=Ldi(t),i=[o.x>0?e[0]/o.x:1,o.y>0?e[1]/o.y:1,o.z>0?e[2]/o.z:1];if(n==="fill_bounds")return i;const r=Math.min(...i);return[r,r,r]}var YYe=({model:t,position:e,rotation:n,modelOffset:o=[0,0,0],modelRotation:i=[0,0,0],sourceCoordinateTransform:r,modelSize:s,modelFitMode:a="contain_within_bounds",scale:A})=>{const{rootObject:c}=J1(),l=te.useMemo(()=>new xh,[]),g=te.useMemo(()=>new xh,[]),u=te.useMemo(()=>new xh,[]),h=te.useMemo(()=>new xh,[]);return te.useEffect(()=>(l.add(g),()=>{l.remove(g)}),[l,g]),te.useEffect(()=>(g.add(u),()=>{g.remove(u)}),[g,u]),te.useEffect(()=>(u.add(h),()=>{u.remove(h)}),[u,h]),te.useEffect(()=>{for(;h.children.length>0;){const d=h.children[0];if(!d)break;h.remove(d)}t&&h.add(t)},[h,t]),te.useEffect(()=>{if(!r){h.matrixAutoUpdate=!0,h.position.set(0,0,0),h.rotation.set(0,0,0),h.scale.set(1,1,1),h.updateMatrix();return}h.matrixAutoUpdate=!1,h.matrix.copy(r),h.matrixWorldNeedsUpdate=!0},[h,r]),te.useEffect(()=>{if(c)return c.add(l),()=>{c.remove(l)}},[c,l]),te.useEffect(()=>{if(e?l.position.fromArray(e):l.position.set(0,0,0),n?l.rotation.fromArray(n):l.rotation.set(0,0,0),u.position.fromArray(o),u.rotation.fromArray(i),u.scale.setScalar(A??1),!t){g.scale.set(1,1,1);return}g.scale.set(1,1,1),g.updateWorldMatrix(!0,!0);const d=Hdi(u,s,a);g.scale.set(d[0],d[1],d[2])},[l,g,t,a,o,h,u,i,s,e,n,A]),{boardTransformGroup:l}},ttn=1.25;function ntn({gltfUrl:t,position:e,rotation:n,modelOffset:o=[0,0,0],modelRotation:i=[0,0,0],sourceCoordinateTransform:r,modelSize:s,modelFitMode:a="contain_within_bounds",onHover:A,onUnhover:c,isHovered:l,scale:g,isTranslucent:u=!1}){const{renderer:h}=J1(),[d,m]=te.useState(null),[p,_]=te.useState(null),{boardTransformGroup:f}=YYe({model:d,position:e,rotation:n,modelOffset:o,modelRotation:i,sourceCoordinateTransform:r,modelSize:s,modelFitMode:a,scale:g});if(te.useEffect(()=>{if(!t)return;const I=new KYn;let C=!0;return I.load(t,y=>{if(!C)return;const x=y.scene;x.traverse(E=>{if(E instanceof wr&&E.material){const B=b=>{b.transparent=u,b.opacity=u?.5:1,b.depthWrite=!u,b.needsUpdate=!0};Array.isArray(E.material)?E.material.forEach(B):B(E.material),E.renderOrder=u?2:1}}),_B(x,{castShadow:!u,receiveShadow:!0}),m(x)},void 0,y=>{if(!C)return;console.error(`An error happened loading ${t}`,y);const x=y instanceof Error?y:new Error(`Failed to load glTF model from ${t}`);_(x)}),()=>{C=!1}},[t,u]),te.useEffect(()=>{if(!d||!h)return;const I=kdi(h);if(!I)return;const C=[],y=x=>{x instanceof hg&&(C.push({material:x,envMap:x.envMap??null,envMapIntensity:x.envMapIntensity??1}),x.envMap=I,(typeof x.envMapIntensity!="number"||x.envMapIntensity<ttn)&&(x.envMapIntensity=ttn),x.needsUpdate=!0)};return d.traverse(x=>{if(!(x instanceof wr))return;const E=x.material;Array.isArray(E)?E.forEach(y):E&&y(E)}),()=>{C.forEach(({material:x,envMap:E,envMapIntensity:B})=>{x.envMap=E,x.envMapIntensity=B,x.needsUpdate=!0})}},[d,h]),te.useEffect(()=>{d&&d.traverse(I=>{if(!(I instanceof wr))return;const C=Array.isArray(I.material)?I.material:[I.material];for(const y of C)y instanceof hg&&(l?(y.emissive.setHex(255),y.emissiveIntensity=.2):y.emissiveIntensity=0)})},[l,d]),p)throw p;return d?z.jsx(eq,{isHovered:l,onHover:A,onUnhover:c,object:f}):null}var Odi=n0(QZt()),Gdi=n0(bue()),Ydi=({jscadPlan:t,positionOffset:e,rotationOffset:n,modelOffset:o=[0,0,0],modelRotation:i=[0,0,0],sourceCoordinateTransform:r,modelSize:s,modelFitMode:a="contain_within_bounds",onHover:A,onUnhover:c,isHovered:l,scale:g,isTranslucent:u=!1})=>{const{threeGeom:h,material:d}=te.useMemo(()=>{const _=(0,Odi.executeJscadOperations)(Gdi.default,t);if(!_||!_.polygons&&!_.sides)return{threeGeom:null,material:null};const f=$en(_),I=new hg({vertexColors:!0,side:S_,transparent:u,opacity:u?.5:1,depthWrite:!u});return{threeGeom:f,material:I}},[t,u]),m=te.useMemo(()=>{if(!h)return null;const _=new wr(h,d);return _.renderOrder=u?2:1,_B(_,{castShadow:!u,receiveShadow:!0}),_},[h,d,u]),{boardTransformGroup:p}=YYe({model:m,position:e,rotation:n,modelOffset:o,modelRotation:i,sourceCoordinateTransform:r,modelSize:s,modelFitMode:a,scale:g});return te.useEffect(()=>{if(d)if(l){const _=new Hi(d.color.getHex());d.emissive.copy(_),d.emissive.setRGB(0,0,1),d.emissiveIntensity=.2}else d.emissiveIntensity=0},[l,d]),h?z.jsx(eq,{isHovered:l,onHover:A,onUnhover:c,object:p}):null};function Udi(t){return t.replace(/(DEF|USE)\s+([^\s]+)/g,(e,n,o)=>`${n} ${o.replace(/-/g,"_")}`)}async function Kdi(t){const e=await fetch(t);if(!e.ok)throw new Error(`Failed to fetch "${t}": ${e.status} ${e.statusText}`);const n=await e.text();return new PUn().parse(Udi(n),t)}typeof window<"u"&&!window.TSCIRCUIT_OBJ_LOADER_CACHE&&(window.TSCIRCUIT_OBJ_LOADER_CACHE=new Map);function Vdi(t){const[e,n]=te.useState(null);return te.useEffect(()=>{if(!t)return;const o=t.replace(/&cachebust_origin=$/,""),i=window.TSCIRCUIT_OBJ_LOADER_CACHE;let r=!1;async function s(){try{if(o.endsWith(".wrl"))return await Kdi(o);const A=await fetch(o);if(!A.ok)throw new Error(`Failed to fetch "${o}": ${A.status} ${A.statusText}`);const c=await A.text(),l=c.match(/newmtl[\s\S]*?endmtl/g),g=new LUn;if(l?.length){const u=l.join(`
5303
- `).replace(/^d\s+0\./gm,"d 1."),h=c.replace(/newmtl[\s\S]*?endmtl/g,"").replace(/^mtllib.*/gm,""),d=new bUn;d.setMaterialOptions({invertTrProperty:!0});const m=d.parse(u,"embedded.mtl");return g.setMaterials(m),g.parse(h)}return g.parse(c.replace(/^mtllib.*/gm,""))}catch(A){return A}}function a(){if(i.has(o)){const c=i.get(o);return c.result?Promise.resolve(c.result.clone()):c.promise.then(l=>l instanceof Error?l:l.clone())}const A=s().then(c=>(c instanceof Error||i.set(o,{...i.get(o),result:c}),c));return i.set(o,{promise:A,result:null}),A}return a().then(A=>{r||n(A)}).catch(A=>{console.error(A)}),()=>{r=!0}},[t]),e}function zdi({url:t,position:e,rotation:n,modelOffset:o=[0,0,0],modelRotation:i=[0,0,0],sourceCoordinateTransform:r,modelSize:s,modelFitMode:a="contain_within_bounds",onHover:A,onUnhover:c,isHovered:l,scale:g,isTranslucent:u=!1}){const h=Vdi(t),d=te.useMemo(()=>{if(h&&!(h instanceof Error))return h.traverse(_=>{if(_ instanceof wr&&_.material){const f=I=>{I.transparent=u,I.opacity=u?.5:1,I.depthWrite=!u,I.needsUpdate=!0};Array.isArray(_.material)?_.material.forEach(f):f(_.material),_.renderOrder=u?2:1}}),_B(h,{castShadow:!u,receiveShadow:!0}),h;const p=new wr(new V2(.5,.5,.5),new hg({transparent:!0,color:"red",opacity:.25}));return _B(p,{castShadow:!1,receiveShadow:!0}),p},[h,u]),{boardTransformGroup:m}=YYe({model:d,position:Array.isArray(e)?e:e?[e.x,e.y,e.z]:void 0,rotation:Array.isArray(n)?n:n?[n.x,n.y,n.z]:void 0,modelOffset:o,modelRotation:i,sourceCoordinateTransform:r,modelSize:s,modelFitMode:a,scale:g});if(h instanceof Error)throw h;return z.jsx(eq,{isHovered:l,onHover:A,onUnhover:c,object:m})}var Jdi=new Hi(.82,.82,.82),otn=t=>new hg({color:t?new Hi(t[0],t[1],t[2]):Jdi});function Wdi(t,e){const n=otn(e.color),o=e.brep_faces??[];if(o.length===0)return[n];const i=o.length>1?[...o].sort((g,u)=>g.first-u.first):o,r=[n],s=new Map,a=e.index.array.length/3;let A=0,c=0;const l=g=>{if(!g)return 0;const u=g.join(","),h=s.get(u);if(h!==void 0)return h;const d=r.length;return r.push(otn(g)),s.set(u,d),d};for(;A<a;){const g=i[c];let u=a,h=0;g&&(A<g.first?u=g.first:(u=g.last+1,h=l(g.color),c+=1)),u>A&&t.addGroup(A*3,(u-A)*3,h),A=u}return r}function jdi(t){const e=new xh;for(const n of t){const o=n.attributes.position?.array??[],i=n.index?.array??[];if(!o.length||!i.length)continue;const r=new ql;r.setAttribute("position",new Ms(o,3));const s=n.attributes.normal?.array??[];s.length?r.setAttribute("normal",new Ms(s,3)):r.computeVertexNormals(),r.setIndex(i),r.clearGroups();const a=Wdi(r,n),A=new wr(r,a.length>1?a:a[0]);A.name=n.name,e.add(A)}return e}var UYe,Xdi="https://cdn.jsdelivr.net/npm/occt-import-js@0.0.23/dist";function qdi(t){if(typeof t=="function")return t;if(t&&typeof t=="object"&&"default"in t&&typeof t.default=="function")return t.default;throw new Error("Unable to resolve occt-import-js factory export")}async function $di(){if(!UYe){const t=await import("https://cdn.jsdelivr.net/npm/occt-import-js@0.0.23/+esm");UYe=qdi(t)({locateFile:n=>`${Xdi}/${n}`})}return UYe}async function Zdi(t){const e=await fetch(t);if(!e.ok)throw new Error(`Failed to fetch STEP file: ${e.statusText}`);const n=await e.arrayBuffer(),i=(await $di()).ReadStepFile(new Uint8Array(n),null);if(!i.success||!i.meshes.length)throw new Error("occt-import-js failed to convert STEP file");const r=jdi(i.meshes),s=new GBe;return await new Promise((A,c)=>{s.parse(r,l=>{l instanceof ArrayBuffer?A(l):c(new Error("GLTFExporter did not return binary output"))},l=>{c(l)},{binary:!0})})}var itn="step-glb-cache:v2:";function ehi(t){const e=new Uint8Array(t),n=32768;let o="";for(let i=0;i<e.length;i+=n){const r=e.subarray(i,i+n);o+=String.fromCharCode(...r)}return btoa(o)}function thi(t){const e=atob(t),n=new Uint8Array(e.length);for(let o=0;o<e.length;o+=1)n[o]=e.charCodeAt(o);return n.buffer}function nhi(t){try{const e=localStorage.getItem(`${itn}${t}`);return e?thi(e):null}catch(e){return console.warn("Failed to read STEP GLB cache",e),null}}function rtn(t,e){try{const n=ehi(e);localStorage.setItem(`${itn}${t}`,n)}catch(n){console.warn("Failed to write STEP GLB cache",n)}}function ohi(){const t=globalThis;return t.stepUrlToGltfModelConversions||(t.stepUrlToGltfModelConversions={inProgress:new Map,completed:new Map}),t.stepUrlToGltfModelConversions}var ihi=({stepUrl:t,position:e,rotation:n,modelOffset:o,modelRotation:i,sourceCoordinateTransform:r,modelSize:s,modelFitMode:a,scale:A,onHover:c,onUnhover:l,isHovered:g,isTranslucent:u})=>{const[h,d]=te.useState(null);return te.useEffect(()=>{let m=!0,p=null,_=!0;const f=ohi(),I=nhi(t);if(I){const x={arrayBuffer:I,blobUrl:URL.createObjectURL(new Blob([I],{type:"model/gltf-binary"}))};return f.completed.set(t,x),p=x.blobUrl,_=!1,d(x.blobUrl),()=>{m=!1,p&&_&&URL.revokeObjectURL(p)}}const C=f.completed.get(t);if(C)return p=C.blobUrl,_=!1,d(C.blobUrl),rtn(t,C.arrayBuffer),()=>{m=!1,p&&_&&URL.revokeObjectURL(p)};let y=f.inProgress.get(t);return y||(y=Zdi(t).then(x=>{const E={arrayBuffer:x,blobUrl:URL.createObjectURL(new Blob([x],{type:"model/gltf-binary"}))};return f.completed.set(t,E),f.inProgress.delete(t),E}).catch(x=>{throw f.inProgress.delete(t),x}),f.inProgress.set(t,y)),y.then(x=>{m&&(p=x.blobUrl,_=!1,d(x.blobUrl),rtn(t,x.arrayBuffer))}).catch(x=>{console.error("Failed to convert STEP file to GLB",x),m&&d(null)}),()=>{m=!1,p&&_&&URL.revokeObjectURL(p)}},[t]),h?z.jsx(ntn,{gltfUrl:h,position:e,rotation:n,modelOffset:o,modelRotation:i,sourceCoordinateTransform:r,modelSize:s,modelFitMode:a,scale:A,onHover:c,onUnhover:l,isHovered:g,isTranslucent:u}):null};function Gue(t,e){let{x:n,y:o,z:i}=t;if(e.axisMapping){const r={x:n,y:o,z:i};e.axisMapping.x&&(n=KYe(r,e.axisMapping.x)),e.axisMapping.y&&(o=KYe(r,e.axisMapping.y)),e.axisMapping.z&&(i=KYe(r,e.axisMapping.z))}if(n*=e.flipX??1,o*=e.flipY??1,i*=e.flipZ??1,e.rotation){if(e.rotation.x){const r=e.rotation.x*Math.PI/180,s=Math.cos(r),a=Math.sin(r),A=o*s-i*a,c=o*a+i*s;o=A,i=c}if(e.rotation.y){const r=e.rotation.y*Math.PI/180,s=Math.cos(r),a=Math.sin(r),A=n*s+i*a,c=-n*a+i*s;n=A,i=c}if(e.rotation.z){const r=e.rotation.z*Math.PI/180,s=Math.cos(r),a=Math.sin(r),A=n*s-o*a,c=n*a+o*s;n=A,o=c}}return{x:n,y:o,z:i}}function KYe(t,e){switch(e){case"x":return t.x;case"y":return t.y;case"z":return t.z;case"-x":return-t.x;case"-y":return-t.y;case"-z":return-t.z;default:return 0}}var VYe={STEP_INVERTED:{axisMapping:{x:"-x",y:"z",z:"-y"}},Z_UP_TO_Y_UP_USB_FIX:{axisMapping:{x:"x",y:"-z",z:"y"},flipZ:-1},FOOTPRINTER_MODEL_TRANSFORM:{axisMapping:{x:"x",y:"-z",z:"y"},flipX:-1,rotation:{x:180,y:180}}};function rhi(t,e){if(e.coordinateTransform)return e.coordinateTransform;if(!e.usingGlbCoordinates){if(e.hasFootprinterModel)return VYe.FOOTPRINTER_MODEL_TRANSFORM;if(!e.usingObjFormat)return e.usingStepFormat?VYe.STEP_INVERTED:VYe.Z_UP_TO_Y_UP_USB_FIX}}function tq(t,e){return rhi(t,{usingGlbCoordinates:e==="gltf"||e==="glb"||e==="jscad",usingObjFormat:e==="obj"||e==="wrl",usingStepFormat:e==="step",hasFootprinterModel:e==="footprinter"})}function Yue(t){if(!t)return;const e=Gue({x:1,y:0,z:0},t),n=Gue({x:0,y:1,z:0},t),o=Gue({x:0,y:0,z:1},t);return new fa().makeBasis(new jt(e.x,e.y,e.z),new jt(n.x,n.y,n.z),new jt(o.x,o.y,o.z))}function CP(t){return t*Math.PI/180}function shi(t){if(t==="z+")return[0,0,0];switch(t){case"x+":return[0,CP(-90),0];case"x-":return[0,CP(90),0];case"y+":return[CP(90),0,0];case"y-":return[CP(-90),0,0];case"z-":return[CP(180),0,0];default:return[0,0,0]}}function ahi(t,e,n){if(!t.position)return;let o=t.position.z;return e==="bottom"&&t.position.z>=0&&(o=-(t.position.z+n)),[t.position.x,t.position.y,o]}function Ahi(t,e){return t.rotation?[CP(t.rotation.x),CP(t.rotation.y),CP(t.rotation.z)]:e==="bottom"?[Math.PI,0,0]:[0,0,0]}function chi(t,e){const n=new jt(t.x,t.y,t.z),o=new oy(e[0],e[1],e[2],"XYZ");return n.applyEuler(o),[n.x,n.y,n.z]}function lhi(t,e,n){if(!t.model_origin_position)return[0,0,0];const o=e?Gue(t.model_origin_position,e):t.model_origin_position;return chi(o,n)}function ghi(t,e){const n=ahi(t,e.layer,e.pcbThickness),o=Ahi(t,e.layer),i=tq(t,e.modelType),r=shi(t.model_board_normal_direction??"z+"),s=lhi(t,i,r);return{position:n,rotation:o,modelPosition:[-s[0],-s[1],-s[2]],modelRotation:r,scale:t.model_unit_to_mm_scale_factor??void 0,fitMode:t.model_object_fit??"contain_within_bounds",size:t.size?[t.size.x,t.size.y,t.size.z]:void 0}}var uhi=t=>t.model_glb_url||t.model_gltf_url?t.model_glb_url?"glb":"gltf":t.model_obj_url||t.model_wrl_url||t.model_stl_url?t.model_wrl_url?"wrl":t.model_stl_url?"stl":"obj":t.model_jscad?"jscad":t.footprinter_string?"footprinter":t.model_step_url?"step":"unknown",dhi=t=>t==="step"?"glb":t,hhi=(t,e)=>{if(!t.model_jscad||t.model_origin_alignment!=="bottom_center_of_component")return!1;const n=e.find(o=>o.type==="pcb_component"&&o.pcb_component_id===t.pcb_component_id);return!!(n&&n.do_not_place&&n.is_allowed_to_be_off_board&&n.obstructs_within_bounds===!1)},mhi=(t,e)=>{if(t)return e?e(t):t},phi=(...t)=>t,zYe=class extends ws.Component{constructor(t){super(t),this.state={hasError:!1,error:null}}static getDerivedStateFromError(t){return{hasError:!0,error:t}}render(){return this.state.hasError&&this.state.error?this.props.fallback({error:this.state.error}):this.props.children}},_hi=({error:t,onError:e})=>(te.useEffect(()=>{e(t)},[t,e]),null),stn=({cad_component:t,circuitJson:e,resolveStaticAsset:n})=>{const o=wZt(e),[i,r]=te.useState(!1),{visibility:s}=iR(),[a,A]=te.useState(null),c=te.useCallback(Y=>{Y?.mousePosition?(r(!0),A(Y.mousePosition)):(r(!1),A(null))},[]),l=te.useCallback(()=>{r(!1),A(null)},[]),g=te.useMemo(()=>Ir(e).source_component.getUsing({source_component_id:t.source_component_id})?.name,[e,t.source_component_id]),u=te.useMemo(()=>e.filter(j=>j.type==="pcb_plated_hole"&&j.pcb_component_id===t.pcb_component_id).length>0,[e,t.pcb_component_id]),h=te.useCallback(Y=>mhi(Y,n),[n]),d=h(t.model_wrl_url??t.model_stl_url??t.model_obj_url),m=h(t.model_glb_url??t.model_gltf_url),p=h(t.model_step_url),[_,f]=te.useState(0),[I,C]=te.useState(null);te.useEffect(()=>{f(0),C(null)},[t.cad_component_id,d,m,p]);const x=e.find(Y=>Y.type==="pcb_component"&&Y.source_component_id===t.source_component_id)?.layer??"top",E=te.useMemo(()=>hhi(t,e),[t,e]),B=E?s.enclosure==="translucent":!!t.show_as_translucent_model,b=uhi(t),Q=dhi(b),w=t.model_glb_url?"glb":"gltf",D=t.model_wrl_url?"wrl":t.model_stl_url?"stl":"obj",k=te.useMemo(()=>ghi(t,{layer:x,pcbThickness:o,modelType:Q}),[t,x,o,Q]),T=phi(...k.rotation),H=k.position,G=te.useMemo(()=>{const Y=[];return m&&Y.push(z.jsx(ntn,{gltfUrl:m,position:H,rotation:T,modelOffset:k.modelPosition,modelRotation:k.modelRotation,sourceCoordinateTransform:Yue(tq(t,w)),scale:k.scale,modelSize:k.size,modelFitMode:k.fitMode,onHover:c,onUnhover:l,isHovered:i,isTranslucent:B},`${t.cad_component_id}-gltf-${m}`)),d&&Y.push(z.jsx(zdi,{url:d,position:H,rotation:T,modelOffset:k.modelPosition,modelRotation:k.modelRotation,sourceCoordinateTransform:Yue(tq(t,D)),scale:k.scale,modelSize:k.size,modelFitMode:k.fitMode,onHover:c,onUnhover:l,isHovered:i,isTranslucent:B},`${t.cad_component_id}-mixed-${d}`)),p&&!t.model_jscad&&!t.footprinter_string&&Y.push(z.jsx(ihi,{stepUrl:p,position:H,rotation:T,modelOffset:k.modelPosition,modelRotation:k.modelRotation,sourceCoordinateTransform:Yue(tq(t,Q)),scale:k.scale,modelSize:k.size,modelFitMode:k.fitMode,onHover:c,onUnhover:l,isHovered:i,isTranslucent:B},`${t.cad_component_id}-step-${p}`)),Y},[H,t.cad_component_id,t.footprinter_string,t.model_jscad,B,m,w,c,l,i,D,k.modelPosition,k.modelRotation,k.scale,k.fitMode,k.size,Q,T,p,d]);let U=null;if(G.length>0){if(_>=G.length){if(I)throw I;return null}U=z.jsx(zYe,{fallback:({error:Y})=>z.jsx(_hi,{error:Y,onError:j=>{C(j),f(ee=>Math.max(ee,_+1))}}),children:G[_]},`${t.cad_component_id}-fallback-${_}`)}else t.model_jscad?U=z.jsx(Ydi,{jscadPlan:t.model_jscad,positionOffset:H,rotationOffset:T,modelOffset:k.modelPosition,modelRotation:k.modelRotation,sourceCoordinateTransform:Yue(tq(t,"jscad")),scale:k.scale,modelSize:k.size,modelFitMode:k.fitMode,onHover:c,onUnhover:l,isHovered:i,isTranslucent:B},t.cad_component_id):t.footprinter_string&&(U=z.jsx(Rdi,{positionOffset:H,rotationOffset:T,footprint:t.footprinter_string,scale:k.scale,onHover:c,onUnhover:l,isHovered:i,isTranslucent:B}));if(E){if(s.enclosure==="hidden")return null}else if(t.show_as_translucent_model){if(!s.translucentModels)return null}else if(u&&!s.throughHoleModels||!u&&!s.smtModels)return null;return z.jsxs(z.Fragment,{children:[U,i&&a?z.jsx(DZt,{position:a,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:g??"<unknown>"}):null]})},atn={version:"0.0.599"},Atn="cadViewerLightingEnabled",fhi=()=>typeof window>"u"?!0:window.localStorage.getItem(Atn)!=="false",ctn=te.createContext(void 0),Ihi=({children:t})=>{const[e,n]=te.useState(!1),[o,i]=te.useState(!1),[r,s]=te.useState(fhi);te.useEffect(()=>{window.localStorage.setItem(Atn,r?"true":"false")},[r]);const a=te.useMemo(()=>({darkBackgroundEnabled:e,setDarkBackgroundEnabled:n,gridEnabled:o,setGridEnabled:i,lightingEnabled:r,setLightingEnabled:s}),[e,o,r]);return z.jsx(ctn.Provider,{value:a,children:t})},JYe=()=>{const t=te.useContext(ctn);if(!t)throw new Error("useAppearance must be used within an AppearanceProvider");return t},ltn="cadViewerCameraStateSession",gtn=(t,e)=>{try{const n={position:t.position.toArray(),quaternion:t.quaternion.toArray(),up:t.up.toArray(),fov:t.fov??50,target:e.target.toArray()};sessionStorage.setItem(ltn,JSON.stringify(n))}catch(n){console.warn("Failed to save camera:",n)}},WYe=(t,e)=>{try{const n=sessionStorage.getItem(ltn);if(!n)return!1;const o=JSON.parse(n);if(t.position.fromArray(o.position),t.quaternion.fromArray(o.quaternion),t.up.fromArray(o.up),"fov"in t){const i=t;i.fov=o.fov,i.updateProjectionMatrix?.()}return e.target.fromArray(o.target),e.update(),t.updateMatrixWorld(),!0}catch(n){return console.warn("Failed to restore camera:",n),!1}},utn=te.createContext(void 0),Chi=({children:t,defaultTarget:e,initialCameraPosition:n,initialCameraType:o})=>{const i=te.useRef(null),r=te.useRef(null),[s,a]=te.useState(null),[A,c]=te.useState(o??"perspective"),[l,g]=te.useState(n??null),[u,h]=te.useState(new oy(0,0,0)),d=te.useMemo(()=>{const[f,I,C]=n??[5,-5,5],y=Math.hypot(f-e.x,I-e.y,C-e.z);return y>0?y:5},[n,e]),m=te.useCallback(f=>{const I=[e.x,e.y,e.z],C=r.current,y=i.current;let x=d;switch(C&&y&&(x=C.position.distanceTo(y.target)),f){case"Top Center Angled":{const E=x/Math.sqrt(2);return{position:[e.x,e.y-E,e.z+E],target:I,up:[0,0,1]}}case"Top Down":return{position:[e.x,e.y,e.z+x],target:I,up:[0,0,1]};case"Top Left Corner":return{position:[e.x-x*.6,e.y-x*.6,e.z+x*.6],target:I,up:[0,0,1]};case"Top Right Corner":return{position:[e.x+x*.6,e.y-x*.6,e.z+x*.6],target:I,up:[0,0,1]};case"Left Sideview":return{position:[e.x-x,e.y,e.z],target:I,up:[0,0,1]};case"Right Sideview":return{position:[e.x+x,e.y,e.z],target:I,up:[0,0,1]};case"Front":return{position:[e.x,e.y-x,e.z],target:I,up:[0,0,1]};default:return null}},[d,e,r,i]),p=te.useCallback(f=>{i.current=f},[]),_=te.useMemo(()=>({controlsRef:i,mainCameraRef:r,defaultTarget:e,baseDistance:d,controller:s,setController:a,getPresetConfig:m,handleControlsChange:p,cameraType:A,setCameraType:c,cameraPosition:l,setCameraPosition:g,cameraRotation:u,setCameraRotation:h,saveCameraToSession:gtn,loadCameraFromSession:WYe}),[e,d,s,m,p,A,l,u]);return z.jsx(utn.Provider,{value:_,children:t})},QS=()=>{const t=te.useContext(utn);if(!t)throw new Error("useCameraController must be used within a CameraControllerProvider");return t},yhi=t=>t<.5?4*t*t*t:1-Math.pow(-2*t+2,3)/2,xhi=()=>{const{controlsRef:t,mainCameraRef:e,defaultTarget:n,setController:o,getPresetConfig:i}=QS(),r=te.useRef(null),s=te.useRef(new ny),a=te.useRef(new jt),A=te.useRef(new jt),c=te.useRef(new ny),l=te.useRef(new ny),g=te.useRef(new f0),u=te.useRef(new f0),h=te.useCallback(({position:m,target:p,up:_,durationMs:f=600})=>{if(!e.current)return;const I=t.current?.target??n,C=new jt(m[0],m[1],m[2]),y=p?new jt(p[0],p[1],p[2]):n.clone(),x=new jt(..._??[0,0,1]).normalize(),E=u.current;E.position.copy(C),E.up.copy(x),E.lookAt(y);const B=E.quaternion.clone(),b=e.current.quaternion.clone(),Q=e.current.position.clone(),w=I.clone(),D=g.current;D.up.set(0,0,1),D.position.copy(Q),D.lookAt(w);const k=D.quaternion.clone();D.up.set(0,0,1),D.position.copy(C),D.lookAt(y);const T=D.quaternion.clone(),H=k.clone().invert().multiply(b).normalize(),G=T.clone().invert().multiply(B).normalize();r.current={fromPosition:Q,toPosition:C,fromTarget:w,toTarget:y,toQuaternion:B,rollFrom:H,rollTo:G,startTime:performance.now(),duration:f}},[e,t,n]),d=te.useCallback(m=>{if(m==="Custom")return;const p=i(m);p&&h(p)},[h,i]);return te.useEffect(()=>e.current?(o({animateTo:h,animateToPreset:d}),()=>{o(null)}):void 0,[h,d,e,o]),OX(()=>{if(!e.current||!r.current)return;const{fromPosition:m,toPosition:p,fromTarget:_,toTarget:f,toQuaternion:I,rollFrom:C,rollTo:y,startTime:x,duration:E}=r.current,B=performance.now()-x,b=E<=0?1:Math.min(B/E,1),Q=yhi(b);e.current.position.lerpVectors(m,p,Q);const w=a.current;w.copy(_).lerp(f,Q);const D=g.current;D.up.set(0,0,1),D.position.copy(e.current.position),D.lookAt(w);const k=s.current;k.copy(D.quaternion);const T=c.current;T.copy(C);const H=l.current;H.copy(y),C.dot(y)<0&&(H.x*=-1,H.y*=-1,H.z*=-1,H.w*=-1),H.normalize(),T.slerp(H,Q),e.current.quaternion.copy(k).multiply(T).normalize();const G=A.current;G.set(0,1,0).applyQuaternion(e.current.quaternion).normalize(),e.current.up.copy(G),t.current?.target.copy(w),e.current.updateMatrixWorld(),t.current?.update(),b>=1&&(e.current.position.copy(p),e.current.quaternion.copy(I),e.current.up.set(0,0,1),e.current.updateMatrixWorld(),t.current?.target.copy(f),t.current?.update(),r.current=null)}),null},Ehi=()=>{const{controlsRef:t}=QS(),e=te.useRef(null),n=te.useRef(!1),o=te.useRef(null),i=te.useCallback(s=>{e.current=s,!n.current&&t.current&&WYe(s,t.current)&&(n.current=!0)},[t]),r=te.useCallback(()=>{if(!(!e.current||!t.current)){if(!n.current&&WYe(e.current,t.current)){n.current=!0;return}clearTimeout(o.current),o.current=setTimeout(()=>{e.current&&t.current&&gtn(e.current,t.current)},150)}},[t]);return{handleCameraCreated:i,handleControlsChange:r}};function Bhi(t){t.querySelectorAll("canvas").forEach(e=>e.remove())}var Shi=t=>{t.outputColorSpace=Y2,t.toneMapping=fht,t.toneMappingExposure=1,t.shadowMap.enabled=!0,t.shadowMap.type=hht},bhi=te.forwardRef(({children:t,scene:e,camera:n,style:o,onCreated:i},r)=>{const{cameraType:s}=QS(),a=te.useRef(null),[A,c]=te.useState(null),l=te.useRef([]),g=te.useRef(void 0);g.current=i;const u=te.useRef(null),h=te.useCallback(_=>{l.current.push(_)},[]),d=te.useCallback(_=>{l.current=l.current.filter(f=>f!==_)},[]),m=te.useMemo(()=>new BM,[]);e?.up&&m.up.set(e.up.x,e.up.y,e.up.z);const p=te.useRef(new f0);return te.useImperativeHandle(r,()=>p.current),te.useEffect(()=>{if(!a.current)return;Bhi(a.current);const _=new vie({antialias:!0,alpha:!0});Shi(_),_.setSize(a.current.clientWidth,a.current.clientHeight),_.setPixelRatio(window.devicePixelRatio),a.current.appendChild(_.domElement);const f=a.current.clientWidth/a.current.clientHeight,I=s==="perspective"?new Q_(75,f,.1,1e3):new mF(-10*f,10*f,10,-10,-1e3,1e3);u.current?(I.position.copy(u.current.position),I.quaternion.copy(u.current.quaternion),I.up.copy(u.current.up)):(n?.up&&I.up.set(n.up[0],n.up[1],n.up[2]),n?.position&&I.position.set(n.position[0],n.position[1],n.position[2]),I.lookAt(0,0,0)),m.add(p.current),window.__TSCIRCUIT_THREE_OBJECT=p.current,c({scene:m,camera:I,renderer:_,rootObject:p.current,addFrameListener:h,removeFrameListener:d}),g.current?.({camera:I,renderer:_});let C;const y=new AYn,x=()=>{const B=y.getElapsedTime(),b=y.getDelta();l.current.forEach(Q=>Q(B,b)),_.render(m,I),C=requestAnimationFrame(x)};x();const E=()=>{if(a.current){const B=a.current.clientWidth/a.current.clientHeight;I instanceof Q_?I.aspect=B:I instanceof mF&&(I.left=-10*B,I.right=10*B,I.top=10,I.bottom=-10),I.updateProjectionMatrix(),_.setSize(a.current.clientWidth,a.current.clientHeight)}};return window.addEventListener("resize",E),()=>{u.current={position:I.position.clone(),quaternion:I.quaternion.clone(),up:I.up.clone()},window.removeEventListener("resize",E),cancelAnimationFrame(C),a.current&&_.domElement&&a.current.removeChild(_.domElement),_.dispose(),m.remove(p.current),window.__TSCIRCUIT_THREE_OBJECT===p.current&&(window.__TSCIRCUIT_THREE_OBJECT=void 0)}},[m,h,d,s]),z.jsx("div",{ref:a,style:{width:"100%",height:"100%",...o},children:A&&z.jsx(MZt.Provider,{value:A,children:z.jsx(Ddi,{children:t})})})}),Qhi=`
5303
+ `).replace(/^d\s+0\./gm,"d 1."),h=c.replace(/newmtl[\s\S]*?endmtl/g,"").replace(/^mtllib.*/gm,""),d=new bUn;d.setMaterialOptions({invertTrProperty:!0});const m=d.parse(u,"embedded.mtl");return g.setMaterials(m),g.parse(h)}return g.parse(c.replace(/^mtllib.*/gm,""))}catch(A){return A}}function a(){if(i.has(o)){const c=i.get(o);return c.result?Promise.resolve(c.result.clone()):c.promise.then(l=>l instanceof Error?l:l.clone())}const A=s().then(c=>(c instanceof Error||i.set(o,{...i.get(o),result:c}),c));return i.set(o,{promise:A,result:null}),A}return a().then(A=>{r||n(A)}).catch(A=>{console.error(A)}),()=>{r=!0}},[t]),e}function zdi({url:t,position:e,rotation:n,modelOffset:o=[0,0,0],modelRotation:i=[0,0,0],sourceCoordinateTransform:r,modelSize:s,modelFitMode:a="contain_within_bounds",onHover:A,onUnhover:c,isHovered:l,scale:g,isTranslucent:u=!1}){const h=Vdi(t),d=te.useMemo(()=>{if(h&&!(h instanceof Error))return h.traverse(_=>{if(_ instanceof wr&&_.material){const f=I=>{I.transparent=u,I.opacity=u?.5:1,I.depthWrite=!u,I.needsUpdate=!0};Array.isArray(_.material)?_.material.forEach(f):f(_.material),_.renderOrder=u?2:1}}),_B(h,{castShadow:!u,receiveShadow:!0}),h;const p=new wr(new V2(.5,.5,.5),new hg({transparent:!0,color:"red",opacity:.25}));return _B(p,{castShadow:!1,receiveShadow:!0}),p},[h,u]),{boardTransformGroup:m}=YYe({model:d,position:Array.isArray(e)?e:e?[e.x,e.y,e.z]:void 0,rotation:Array.isArray(n)?n:n?[n.x,n.y,n.z]:void 0,modelOffset:o,modelRotation:i,sourceCoordinateTransform:r,modelSize:s,modelFitMode:a,scale:g});if(h instanceof Error)throw h;return z.jsx(eq,{isHovered:l,onHover:A,onUnhover:c,object:m})}var Jdi=new Hi(.82,.82,.82),otn=t=>new hg({color:t?new Hi(t[0],t[1],t[2]):Jdi});function Wdi(t,e){const n=otn(e.color),o=e.brep_faces??[];if(o.length===0)return[n];const i=o.length>1?[...o].sort((g,u)=>g.first-u.first):o,r=[n],s=new Map,a=e.index.array.length/3;let A=0,c=0;const l=g=>{if(!g)return 0;const u=g.join(","),h=s.get(u);if(h!==void 0)return h;const d=r.length;return r.push(otn(g)),s.set(u,d),d};for(;A<a;){const g=i[c];let u=a,h=0;g&&(A<g.first?u=g.first:(u=g.last+1,h=l(g.color),c+=1)),u>A&&t.addGroup(A*3,(u-A)*3,h),A=u}return r}function jdi(t){const e=new xh;for(const n of t){const o=n.attributes.position?.array??[],i=n.index?.array??[];if(!o.length||!i.length)continue;const r=new ql;r.setAttribute("position",new Ms(o,3));const s=n.attributes.normal?.array??[];s.length?r.setAttribute("normal",new Ms(s,3)):r.computeVertexNormals(),r.setIndex(i),r.clearGroups();const a=Wdi(r,n),A=new wr(r,a.length>1?a:a[0]);A.name=n.name,e.add(A)}return e}var UYe,Xdi="https://cdn.jsdelivr.net/npm/occt-import-js@0.0.23/dist";function qdi(t){if(typeof t=="function")return t;if(t&&typeof t=="object"&&"default"in t&&typeof t.default=="function")return t.default;throw new Error("Unable to resolve occt-import-js factory export")}async function $di(){if(!UYe){const t=await import("https://cdn.jsdelivr.net/npm/occt-import-js@0.0.23/+esm");UYe=qdi(t)({locateFile:n=>`${Xdi}/${n}`})}return UYe}async function Zdi(t){const e=await fetch(t);if(!e.ok)throw new Error(`Failed to fetch STEP file: ${e.statusText}`);const n=await e.arrayBuffer(),i=(await $di()).ReadStepFile(new Uint8Array(n),null);if(!i.success||!i.meshes.length)throw new Error("occt-import-js failed to convert STEP file");const r=jdi(i.meshes),s=new GBe;return await new Promise((A,c)=>{s.parse(r,l=>{l instanceof ArrayBuffer?A(l):c(new Error("GLTFExporter did not return binary output"))},l=>{c(l)},{binary:!0})})}var itn="step-glb-cache:v2:";function ehi(t){const e=new Uint8Array(t),n=32768;let o="";for(let i=0;i<e.length;i+=n){const r=e.subarray(i,i+n);o+=String.fromCharCode(...r)}return btoa(o)}function thi(t){const e=atob(t),n=new Uint8Array(e.length);for(let o=0;o<e.length;o+=1)n[o]=e.charCodeAt(o);return n.buffer}function nhi(t){try{const e=localStorage.getItem(`${itn}${t}`);return e?thi(e):null}catch(e){return console.warn("Failed to read STEP GLB cache",e),null}}function rtn(t,e){try{const n=ehi(e);localStorage.setItem(`${itn}${t}`,n)}catch(n){console.warn("Failed to write STEP GLB cache",n)}}function ohi(){const t=globalThis;return t.stepUrlToGltfModelConversions||(t.stepUrlToGltfModelConversions={inProgress:new Map,completed:new Map}),t.stepUrlToGltfModelConversions}var ihi=({stepUrl:t,position:e,rotation:n,modelOffset:o,modelRotation:i,sourceCoordinateTransform:r,modelSize:s,modelFitMode:a,scale:A,onHover:c,onUnhover:l,isHovered:g,isTranslucent:u})=>{const[h,d]=te.useState(null);return te.useEffect(()=>{let m=!0,p=null,_=!0;const f=ohi(),I=nhi(t);if(I){const x={arrayBuffer:I,blobUrl:URL.createObjectURL(new Blob([I],{type:"model/gltf-binary"}))};return f.completed.set(t,x),p=x.blobUrl,_=!1,d(x.blobUrl),()=>{m=!1,p&&_&&URL.revokeObjectURL(p)}}const C=f.completed.get(t);if(C)return p=C.blobUrl,_=!1,d(C.blobUrl),rtn(t,C.arrayBuffer),()=>{m=!1,p&&_&&URL.revokeObjectURL(p)};let y=f.inProgress.get(t);return y||(y=Zdi(t).then(x=>{const E={arrayBuffer:x,blobUrl:URL.createObjectURL(new Blob([x],{type:"model/gltf-binary"}))};return f.completed.set(t,E),f.inProgress.delete(t),E}).catch(x=>{throw f.inProgress.delete(t),x}),f.inProgress.set(t,y)),y.then(x=>{m&&(p=x.blobUrl,_=!1,d(x.blobUrl),rtn(t,x.arrayBuffer))}).catch(x=>{console.error("Failed to convert STEP file to GLB",x),m&&d(null)}),()=>{m=!1,p&&_&&URL.revokeObjectURL(p)}},[t]),h?z.jsx(ntn,{gltfUrl:h,position:e,rotation:n,modelOffset:o,modelRotation:i,sourceCoordinateTransform:r,modelSize:s,modelFitMode:a,scale:A,onHover:c,onUnhover:l,isHovered:g,isTranslucent:u}):null};function Gue(t,e){let{x:n,y:o,z:i}=t;if(e.axisMapping){const r={x:n,y:o,z:i};e.axisMapping.x&&(n=KYe(r,e.axisMapping.x)),e.axisMapping.y&&(o=KYe(r,e.axisMapping.y)),e.axisMapping.z&&(i=KYe(r,e.axisMapping.z))}if(n*=e.flipX??1,o*=e.flipY??1,i*=e.flipZ??1,e.rotation){if(e.rotation.x){const r=e.rotation.x*Math.PI/180,s=Math.cos(r),a=Math.sin(r),A=o*s-i*a,c=o*a+i*s;o=A,i=c}if(e.rotation.y){const r=e.rotation.y*Math.PI/180,s=Math.cos(r),a=Math.sin(r),A=n*s+i*a,c=-n*a+i*s;n=A,i=c}if(e.rotation.z){const r=e.rotation.z*Math.PI/180,s=Math.cos(r),a=Math.sin(r),A=n*s-o*a,c=n*a+o*s;n=A,o=c}}return{x:n,y:o,z:i}}function KYe(t,e){switch(e){case"x":return t.x;case"y":return t.y;case"z":return t.z;case"-x":return-t.x;case"-y":return-t.y;case"-z":return-t.z;default:return 0}}var VYe={STEP_INVERTED:{axisMapping:{x:"-x",y:"z",z:"-y"}},Z_UP_TO_Y_UP_USB_FIX:{axisMapping:{x:"x",y:"-z",z:"y"},flipZ:-1},FOOTPRINTER_MODEL_TRANSFORM:{axisMapping:{x:"x",y:"-z",z:"y"},flipX:-1,rotation:{x:180,y:180}}};function rhi(t,e){if(e.coordinateTransform)return e.coordinateTransform;if(!e.usingGlbCoordinates){if(e.hasFootprinterModel)return VYe.FOOTPRINTER_MODEL_TRANSFORM;if(!e.usingObjFormat)return e.usingStepFormat?VYe.STEP_INVERTED:VYe.Z_UP_TO_Y_UP_USB_FIX}}function tq(t,e){return rhi(t,{usingGlbCoordinates:e==="gltf"||e==="glb"||e==="jscad",usingObjFormat:e==="obj"||e==="wrl",usingStepFormat:e==="step",hasFootprinterModel:e==="footprinter"})}function Yue(t){if(!t)return;const e=Gue({x:1,y:0,z:0},t),n=Gue({x:0,y:1,z:0},t),o=Gue({x:0,y:0,z:1},t);return new fa().makeBasis(new jt(e.x,e.y,e.z),new jt(n.x,n.y,n.z),new jt(o.x,o.y,o.z))}function CP(t){return t*Math.PI/180}function shi(t){if(t==="z+")return[0,0,0];switch(t){case"x+":return[0,CP(-90),0];case"x-":return[0,CP(90),0];case"y+":return[CP(90),0,0];case"y-":return[CP(-90),0,0];case"z-":return[CP(180),0,0];default:return[0,0,0]}}function ahi(t,e,n){if(!t.position)return;let o=t.position.z;return e==="bottom"&&t.position.z>=0&&(o=-(t.position.z+n)),[t.position.x,t.position.y,o]}function Ahi(t,e){return t.rotation?[CP(t.rotation.x),CP(t.rotation.y),CP(t.rotation.z)]:e==="bottom"?[Math.PI,0,0]:[0,0,0]}function chi(t,e){const n=new jt(t.x,t.y,t.z),o=new oy(e[0],e[1],e[2],"XYZ");return n.applyEuler(o),[n.x,n.y,n.z]}function lhi(t,e,n){if(!t.model_origin_position)return[0,0,0];const o=e?Gue(t.model_origin_position,e):t.model_origin_position;return chi(o,n)}function ghi(t,e){const n=ahi(t,e.layer,e.pcbThickness),o=Ahi(t,e.layer),i=tq(t,e.modelType),r=shi(t.model_board_normal_direction??"z+"),s=lhi(t,i,r);return{position:n,rotation:o,modelPosition:[-s[0],-s[1],-s[2]],modelRotation:r,scale:t.model_unit_to_mm_scale_factor??void 0,fitMode:t.model_object_fit??"contain_within_bounds",size:t.size?[t.size.x,t.size.y,t.size.z]:void 0}}var uhi=t=>t.model_glb_url||t.model_gltf_url?t.model_glb_url?"glb":"gltf":t.model_obj_url||t.model_wrl_url||t.model_stl_url?t.model_wrl_url?"wrl":t.model_stl_url?"stl":"obj":t.model_jscad?"jscad":t.footprinter_string?"footprinter":t.model_step_url?"step":"unknown",dhi=t=>t==="step"?"glb":t,hhi=(t,e)=>{if(!t.model_jscad||t.model_origin_alignment!=="bottom_center_of_component")return!1;const n=e.find(o=>o.type==="pcb_component"&&o.pcb_component_id===t.pcb_component_id);return!!(n&&n.do_not_place&&n.is_allowed_to_be_off_board&&n.obstructs_within_bounds===!1)},mhi=(t,e)=>{if(t)return e?e(t):t},phi=(...t)=>t,zYe=class extends ws.Component{constructor(t){super(t),this.state={hasError:!1,error:null}}static getDerivedStateFromError(t){return{hasError:!0,error:t}}render(){return this.state.hasError&&this.state.error?this.props.fallback({error:this.state.error}):this.props.children}},_hi=({error:t,onError:e})=>(te.useEffect(()=>{e(t)},[t,e]),null),stn=({cad_component:t,circuitJson:e,resolveStaticAsset:n})=>{const o=wZt(e),[i,r]=te.useState(!1),{visibility:s}=iR(),[a,A]=te.useState(null),c=te.useCallback(Y=>{Y?.mousePosition?(r(!0),A(Y.mousePosition)):(r(!1),A(null))},[]),l=te.useCallback(()=>{r(!1),A(null)},[]),g=te.useMemo(()=>Ir(e).source_component.getUsing({source_component_id:t.source_component_id})?.name,[e,t.source_component_id]),u=te.useMemo(()=>e.filter(j=>j.type==="pcb_plated_hole"&&j.pcb_component_id===t.pcb_component_id).length>0,[e,t.pcb_component_id]),h=te.useCallback(Y=>mhi(Y,n),[n]),d=h(t.model_wrl_url??t.model_stl_url??t.model_obj_url),m=h(t.model_glb_url??t.model_gltf_url),p=h(t.model_step_url),[_,f]=te.useState(0),[I,C]=te.useState(null);te.useEffect(()=>{f(0),C(null)},[t.cad_component_id,d,m,p]);const x=e.find(Y=>Y.type==="pcb_component"&&Y.source_component_id===t.source_component_id)?.layer??"top",E=te.useMemo(()=>hhi(t,e),[t,e]),B=E?s.enclosure==="translucent":!!t.show_as_translucent_model,b=uhi(t),Q=dhi(b),w=t.model_glb_url?"glb":"gltf",D=t.model_wrl_url?"wrl":t.model_stl_url?"stl":"obj",k=te.useMemo(()=>ghi(t,{layer:x,pcbThickness:o,modelType:Q}),[t,x,o,Q]),T=phi(...k.rotation),H=k.position,G=te.useMemo(()=>{const Y=[];return m&&Y.push(z.jsx(ntn,{gltfUrl:m,position:H,rotation:T,modelOffset:k.modelPosition,modelRotation:k.modelRotation,sourceCoordinateTransform:Yue(tq(t,w)),scale:k.scale,modelSize:k.size,modelFitMode:k.fitMode,onHover:c,onUnhover:l,isHovered:i,isTranslucent:B},`${t.cad_component_id}-gltf-${m}`)),d&&Y.push(z.jsx(zdi,{url:d,position:H,rotation:T,modelOffset:k.modelPosition,modelRotation:k.modelRotation,sourceCoordinateTransform:Yue(tq(t,D)),scale:k.scale,modelSize:k.size,modelFitMode:k.fitMode,onHover:c,onUnhover:l,isHovered:i,isTranslucent:B},`${t.cad_component_id}-mixed-${d}`)),p&&!t.model_jscad&&!t.footprinter_string&&Y.push(z.jsx(ihi,{stepUrl:p,position:H,rotation:T,modelOffset:k.modelPosition,modelRotation:k.modelRotation,sourceCoordinateTransform:Yue(tq(t,Q)),scale:k.scale,modelSize:k.size,modelFitMode:k.fitMode,onHover:c,onUnhover:l,isHovered:i,isTranslucent:B},`${t.cad_component_id}-step-${p}`)),Y},[H,t.cad_component_id,t.footprinter_string,t.model_jscad,B,m,w,c,l,i,D,k.modelPosition,k.modelRotation,k.scale,k.fitMode,k.size,Q,T,p,d]);let U=null;if(G.length>0){if(_>=G.length){if(I)throw I;return null}U=z.jsx(zYe,{fallback:({error:Y})=>z.jsx(_hi,{error:Y,onError:j=>{C(j),f(ee=>Math.max(ee,_+1))}}),children:G[_]},`${t.cad_component_id}-fallback-${_}`)}else t.model_jscad?U=z.jsx(Ydi,{jscadPlan:t.model_jscad,positionOffset:H,rotationOffset:T,modelOffset:k.modelPosition,modelRotation:k.modelRotation,sourceCoordinateTransform:Yue(tq(t,"jscad")),scale:k.scale,modelSize:k.size,modelFitMode:k.fitMode,onHover:c,onUnhover:l,isHovered:i,isTranslucent:B},t.cad_component_id):t.footprinter_string&&(U=z.jsx(Rdi,{positionOffset:H,rotationOffset:T,footprint:t.footprinter_string,scale:k.scale,onHover:c,onUnhover:l,isHovered:i,isTranslucent:B}));if(E){if(s.enclosure==="hidden")return null}else if(t.show_as_translucent_model){if(!s.translucentModels)return null}else if(u&&!s.throughHoleModels||!u&&!s.smtModels)return null;return z.jsxs(z.Fragment,{children:[U,i&&a?z.jsx(DZt,{position:a,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:g??"<unknown>"}):null]})},atn={version:"0.0.600"},Atn="cadViewerLightingEnabled",fhi=()=>typeof window>"u"?!0:window.localStorage.getItem(Atn)!=="false",ctn=te.createContext(void 0),Ihi=({children:t})=>{const[e,n]=te.useState(!1),[o,i]=te.useState(!1),[r,s]=te.useState(fhi);te.useEffect(()=>{window.localStorage.setItem(Atn,r?"true":"false")},[r]);const a=te.useMemo(()=>({darkBackgroundEnabled:e,setDarkBackgroundEnabled:n,gridEnabled:o,setGridEnabled:i,lightingEnabled:r,setLightingEnabled:s}),[e,o,r]);return z.jsx(ctn.Provider,{value:a,children:t})},JYe=()=>{const t=te.useContext(ctn);if(!t)throw new Error("useAppearance must be used within an AppearanceProvider");return t},ltn="cadViewerCameraStateSession",gtn=(t,e)=>{try{const n={position:t.position.toArray(),quaternion:t.quaternion.toArray(),up:t.up.toArray(),fov:t.fov??50,target:e.target.toArray()};sessionStorage.setItem(ltn,JSON.stringify(n))}catch(n){console.warn("Failed to save camera:",n)}},WYe=(t,e)=>{try{const n=sessionStorage.getItem(ltn);if(!n)return!1;const o=JSON.parse(n);if(t.position.fromArray(o.position),t.quaternion.fromArray(o.quaternion),t.up.fromArray(o.up),"fov"in t){const i=t;i.fov=o.fov,i.updateProjectionMatrix?.()}return e.target.fromArray(o.target),e.update(),t.updateMatrixWorld(),!0}catch(n){return console.warn("Failed to restore camera:",n),!1}},utn=te.createContext(void 0),Chi=({children:t,defaultTarget:e,initialCameraPosition:n,initialCameraType:o})=>{const i=te.useRef(null),r=te.useRef(null),[s,a]=te.useState(null),[A,c]=te.useState(o??"perspective"),[l,g]=te.useState(n??null),[u,h]=te.useState(new oy(0,0,0)),d=te.useMemo(()=>{const[f,I,C]=n??[5,-5,5],y=Math.hypot(f-e.x,I-e.y,C-e.z);return y>0?y:5},[n,e]),m=te.useCallback(f=>{const I=[e.x,e.y,e.z],C=r.current,y=i.current;let x=d;switch(C&&y&&(x=C.position.distanceTo(y.target)),f){case"Top Center Angled":{const E=x/Math.sqrt(2);return{position:[e.x,e.y-E,e.z+E],target:I,up:[0,0,1]}}case"Top Down":return{position:[e.x,e.y,e.z+x],target:I,up:[0,0,1]};case"Top Left Corner":return{position:[e.x-x*.6,e.y-x*.6,e.z+x*.6],target:I,up:[0,0,1]};case"Top Right Corner":return{position:[e.x+x*.6,e.y-x*.6,e.z+x*.6],target:I,up:[0,0,1]};case"Left Sideview":return{position:[e.x-x,e.y,e.z],target:I,up:[0,0,1]};case"Right Sideview":return{position:[e.x+x,e.y,e.z],target:I,up:[0,0,1]};case"Front":return{position:[e.x,e.y-x,e.z],target:I,up:[0,0,1]};default:return null}},[d,e,r,i]),p=te.useCallback(f=>{i.current=f},[]),_=te.useMemo(()=>({controlsRef:i,mainCameraRef:r,defaultTarget:e,baseDistance:d,controller:s,setController:a,getPresetConfig:m,handleControlsChange:p,cameraType:A,setCameraType:c,cameraPosition:l,setCameraPosition:g,cameraRotation:u,setCameraRotation:h,saveCameraToSession:gtn,loadCameraFromSession:WYe}),[e,d,s,m,p,A,l,u]);return z.jsx(utn.Provider,{value:_,children:t})},QS=()=>{const t=te.useContext(utn);if(!t)throw new Error("useCameraController must be used within a CameraControllerProvider");return t},yhi=t=>t<.5?4*t*t*t:1-Math.pow(-2*t+2,3)/2,xhi=()=>{const{controlsRef:t,mainCameraRef:e,defaultTarget:n,setController:o,getPresetConfig:i}=QS(),r=te.useRef(null),s=te.useRef(new ny),a=te.useRef(new jt),A=te.useRef(new jt),c=te.useRef(new ny),l=te.useRef(new ny),g=te.useRef(new f0),u=te.useRef(new f0),h=te.useCallback(({position:m,target:p,up:_,durationMs:f=600})=>{if(!e.current)return;const I=t.current?.target??n,C=new jt(m[0],m[1],m[2]),y=p?new jt(p[0],p[1],p[2]):n.clone(),x=new jt(..._??[0,0,1]).normalize(),E=u.current;E.position.copy(C),E.up.copy(x),E.lookAt(y);const B=E.quaternion.clone(),b=e.current.quaternion.clone(),Q=e.current.position.clone(),w=I.clone(),D=g.current;D.up.set(0,0,1),D.position.copy(Q),D.lookAt(w);const k=D.quaternion.clone();D.up.set(0,0,1),D.position.copy(C),D.lookAt(y);const T=D.quaternion.clone(),H=k.clone().invert().multiply(b).normalize(),G=T.clone().invert().multiply(B).normalize();r.current={fromPosition:Q,toPosition:C,fromTarget:w,toTarget:y,toQuaternion:B,rollFrom:H,rollTo:G,startTime:performance.now(),duration:f}},[e,t,n]),d=te.useCallback(m=>{if(m==="Custom")return;const p=i(m);p&&h(p)},[h,i]);return te.useEffect(()=>e.current?(o({animateTo:h,animateToPreset:d}),()=>{o(null)}):void 0,[h,d,e,o]),OX(()=>{if(!e.current||!r.current)return;const{fromPosition:m,toPosition:p,fromTarget:_,toTarget:f,toQuaternion:I,rollFrom:C,rollTo:y,startTime:x,duration:E}=r.current,B=performance.now()-x,b=E<=0?1:Math.min(B/E,1),Q=yhi(b);e.current.position.lerpVectors(m,p,Q);const w=a.current;w.copy(_).lerp(f,Q);const D=g.current;D.up.set(0,0,1),D.position.copy(e.current.position),D.lookAt(w);const k=s.current;k.copy(D.quaternion);const T=c.current;T.copy(C);const H=l.current;H.copy(y),C.dot(y)<0&&(H.x*=-1,H.y*=-1,H.z*=-1,H.w*=-1),H.normalize(),T.slerp(H,Q),e.current.quaternion.copy(k).multiply(T).normalize();const G=A.current;G.set(0,1,0).applyQuaternion(e.current.quaternion).normalize(),e.current.up.copy(G),t.current?.target.copy(w),e.current.updateMatrixWorld(),t.current?.update(),b>=1&&(e.current.position.copy(p),e.current.quaternion.copy(I),e.current.up.set(0,0,1),e.current.updateMatrixWorld(),t.current?.target.copy(f),t.current?.update(),r.current=null)}),null},Ehi=()=>{const{controlsRef:t}=QS(),e=te.useRef(null),n=te.useRef(!1),o=te.useRef(null),i=te.useCallback(s=>{e.current=s,!n.current&&t.current&&WYe(s,t.current)&&(n.current=!0)},[t]),r=te.useCallback(()=>{if(!(!e.current||!t.current)){if(!n.current&&WYe(e.current,t.current)){n.current=!0;return}clearTimeout(o.current),o.current=setTimeout(()=>{e.current&&t.current&&gtn(e.current,t.current)},150)}},[t]);return{handleCameraCreated:i,handleControlsChange:r}};function Bhi(t){t.querySelectorAll("canvas").forEach(e=>e.remove())}var Shi=t=>{t.outputColorSpace=Y2,t.toneMapping=fht,t.toneMappingExposure=1,t.shadowMap.enabled=!0,t.shadowMap.type=hht},bhi=te.forwardRef(({children:t,scene:e,camera:n,style:o,onCreated:i},r)=>{const{cameraType:s}=QS(),a=te.useRef(null),[A,c]=te.useState(null),l=te.useRef([]),g=te.useRef(void 0);g.current=i;const u=te.useRef(null),h=te.useCallback(_=>{l.current.push(_)},[]),d=te.useCallback(_=>{l.current=l.current.filter(f=>f!==_)},[]),m=te.useMemo(()=>new BM,[]);e?.up&&m.up.set(e.up.x,e.up.y,e.up.z);const p=te.useRef(new f0);return te.useImperativeHandle(r,()=>p.current),te.useEffect(()=>{if(!a.current)return;Bhi(a.current);const _=new vie({antialias:!0,alpha:!0});Shi(_),_.setSize(a.current.clientWidth,a.current.clientHeight),_.setPixelRatio(window.devicePixelRatio),a.current.appendChild(_.domElement);const f=a.current.clientWidth/a.current.clientHeight,I=s==="perspective"?new Q_(75,f,.1,1e3):new mF(-10*f,10*f,10,-10,-1e3,1e3);u.current?(I.position.copy(u.current.position),I.quaternion.copy(u.current.quaternion),I.up.copy(u.current.up)):(n?.up&&I.up.set(n.up[0],n.up[1],n.up[2]),n?.position&&I.position.set(n.position[0],n.position[1],n.position[2]),I.lookAt(0,0,0)),m.add(p.current),window.__TSCIRCUIT_THREE_OBJECT=p.current,c({scene:m,camera:I,renderer:_,rootObject:p.current,addFrameListener:h,removeFrameListener:d}),g.current?.({camera:I,renderer:_});let C;const y=new AYn,x=()=>{const B=y.getElapsedTime(),b=y.getDelta();l.current.forEach(Q=>Q(B,b)),_.render(m,I),C=requestAnimationFrame(x)};x();const E=()=>{if(a.current){const B=a.current.clientWidth/a.current.clientHeight;I instanceof Q_?I.aspect=B:I instanceof mF&&(I.left=-10*B,I.right=10*B,I.top=10,I.bottom=-10),I.updateProjectionMatrix(),_.setSize(a.current.clientWidth,a.current.clientHeight)}};return window.addEventListener("resize",E),()=>{u.current={position:I.position.clone(),quaternion:I.quaternion.clone(),up:I.up.clone()},window.removeEventListener("resize",E),cancelAnimationFrame(C),a.current&&_.domElement&&a.current.removeChild(_.domElement),_.dispose(),m.remove(p.current),window.__TSCIRCUIT_THREE_OBJECT===p.current&&(window.__TSCIRCUIT_THREE_OBJECT=void 0)}},[m,h,d,s]),z.jsx("div",{ref:a,style:{width:"100%",height:"100%",...o},children:A&&z.jsx(MZt.Provider,{value:A,children:z.jsx(Ddi,{children:t})})})}),Qhi=`
5304
5304
  varying vec3 worldPosition;
5305
5305
  void main() {
5306
5306
  worldPosition = (modelMatrix * vec4(position, 1.0)).xyz;
@@ -5580,7 +5580,7 @@ test("${c} should solve problem correctly", () => {
5580
5580
  // Add more specific assertions based on expected output
5581
5581
  // expect(solver.netLabelPlacementSolver!.netLabelPlacements).toMatchInlineSnapshot()
5582
5582
  })
5583
- `,g=new Blob([l],{type:"text/plain"}),u=URL.createObjectURL(g),h=document.createElement("a");h.href=u,h.download=`${c}.test.ts`,h.click(),URL.revokeObjectURL(u)}catch(A){alert(`Error generating test.ts for ${t.getSolverName()}: ${A instanceof Error?A.message:String(A)}`)}o(!1)};return z.jsxs("div",{className:`relative ${e}`,ref:i,children:[z.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>o(!n),title:`Download options for ${t.getSolverName()}`,children:t.getSolverName()}),n&&z.jsxs("div",{className:"absolute top-full left-0 mt-1 bg-white border border-gray-300 rounded shadow-lg z-10 min-w-[150px]",children:[z.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:r,children:"Download JSON"}),z.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),z.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:a,children:"Download test.ts"})]})]})},RAn=t=>t.activeSubSolver?[t,...RAn(t.activeSubSolver)]:[t],oQi=({solver:t})=>{const e=RAn(t);return z.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:e.map((n,o)=>z.jsxs("div",{className:"flex items-center",children:[o>0&&z.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),z.jsx(nQi,{solver:n})]},n.getSolverName()))})},iQi=({solver:t,triggerRender:e,animationSpeed:n=25,renderer:o,onRendererChange:i,onAnimationSpeedChange:r,onDownloadVisualization:s,onSolverStarted:a,onSolverCompleted:A})=>{const[c,l]=te.useReducer(B=>!B,!1),g=te.useRef(void 0),u=te.useRef(null),h="solver-debugger-last-iteration",[d,m]=te.useState(null),p=te.useRef(null),_=te.useMemo(()=>[{label:"Slow",value:250,description:"250ms"},{label:"Normal",value:100,description:"100ms"},{label:"Fast",value:10,description:"10ms"},{label:"Fast (2x)",value:5,description:"5ms"},{label:"Fast (10x)",value:1,description:"1ms"},{label:"Fast 20x",value:.5,description:"2 steps / 1ms"},{label:"Fast 100x",value:.1,description:"10 steps / 1ms"}],[]),f=()=>{const B=Math.max(1,n),b=n<1?Math.round(1/n):1;g.current=setInterval(()=>{if(t.solved||t.failed){g.current&&(clearInterval(g.current),g.current=void 0),l(),e(),A&&t.solved&&A(t);return}for(let Q=0;Q<b&&!(t.solved||t.failed);Q++)t.step();e()},B)},I=()=>{g.current&&(clearInterval(g.current),g.current=void 0)},C=()=>{!t.solved&&!t.failed&&(t.step(),e())},y=()=>{!t.solved&&!t.failed&&(a&&a(t),t.solve(),e(),A&&A(t))},x=()=>{c?(I(),l()):(l(),f())},E=()=>{if(t.solved||t.failed||c)return;u.current===null&&typeof window<"u"&&(u.current=window.localStorage.getItem(h));const B=window.prompt("Step until which iteration?",u.current??`${t.iterations}`);if(B===null)return;u.current=B,typeof window<"u"&&window.localStorage.setItem(h,B);const b=Number(B);if(!Number.isFinite(b)){window.alert("Please enter a valid number for the iteration");return}for(;t.iterations<b&&!t.solved&&!t.failed;)t.step();e(),t.solved&&A&&A(t)};return te.useEffect(()=>()=>{I()},[]),te.useEffect(()=>{(t.solved||t.failed)&&c&&(I(),l())},[t.solved,t.failed,c]),te.useEffect(()=>{c&&(I(),f())},[n,c]),te.useEffect(()=>{if(typeof document>"u")return;const B=b=>{p.current&&!p.current.contains(b.target)&&m(null)};return document.addEventListener("mousedown",B),()=>{document.removeEventListener("mousedown",B)}},[]),z.jsxs("div",{className:"space-y-2 p-2 border-b",children:[z.jsx("div",{className:"flex items-center",children:z.jsxs("div",{className:"flex items-center gap-2",ref:p,children:[z.jsxs("div",{className:"flex h-9 items-center space-x-1 rounded-md border border-slate-200 bg-white p-1 shadow-sm",children:[z.jsxs("div",{className:"relative",children:[z.jsx("button",{type:"button",onClick:()=>m(d==="renderer"?null:"renderer"),className:"flex select-none items-center rounded-sm px-3 py-1 text-sm font-medium outline-none focus:bg-slate-100 data-[state=open]:bg-slate-100","data-state":d==="renderer"?"open":"closed",children:"Renderer"}),d==="renderer"&&z.jsx("div",{className:"absolute left-0 z-50 mt-1 min-w-[10rem] rounded-md border border-slate-200 bg-white p-1 text-slate-950 shadow-md",children:["vector","canvas"].map(B=>z.jsxs("button",{type:"button",onClick:()=>{i(B),m(null)},className:"flex w-full items-center rounded-sm px-2 py-1.5 text-sm hover:bg-slate-100",children:[B==="vector"?"Vector":"Canvas",o===B&&z.jsx("span",{className:"ml-auto text-xs text-slate-500",children:"✓"})]},B))})]}),z.jsxs("div",{className:"relative",children:[z.jsx("button",{type:"button",onClick:()=>m(d==="debug"?null:"debug"),className:"flex select-none items-center rounded-sm px-3 py-1 text-sm font-medium outline-none focus:bg-slate-100 data-[state=open]:bg-slate-100","data-state":d==="debug"?"open":"closed",children:"Debug"}),d==="debug"&&z.jsx("div",{className:"absolute left-0 z-50 mt-1 min-w-[12rem] rounded-md border border-slate-200 bg-white p-1 text-slate-950 shadow-md",children:z.jsx("button",{type:"button",onClick:()=>{s(),m(null)},className:"flex w-full items-center rounded-sm px-2 py-1.5 text-sm hover:bg-slate-100",children:"Download Visualization"})})]}),z.jsxs("div",{className:"relative",children:[z.jsx("button",{type:"button",onClick:()=>m(d==="animation"?null:"animation"),className:"flex select-none items-center rounded-sm px-3 py-1 text-sm font-medium outline-none focus:bg-slate-100 data-[state=open]:bg-slate-100","data-state":d==="animation"?"open":"closed",children:"Animation"}),d==="animation"&&z.jsx("div",{className:"absolute left-0 z-50 mt-1 min-w-[12rem] rounded-md border border-slate-200 bg-white p-1 text-slate-950 shadow-md",children:_.map(B=>z.jsxs("button",{type:"button",onClick:()=>{r(B.value),m(null)},className:"flex w-full items-center rounded-sm px-2 py-1.5 text-sm hover:bg-slate-100",children:[B.label,z.jsx("span",{className:"ml-auto text-xs text-slate-500",children:B.description}),n===B.value&&z.jsx("span",{className:"ml-2 text-xs text-slate-500",children:"✓"})]},B.value))})]})]}),z.jsx(oQi,{solver:t})]})}),z.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[z.jsx("button",{onClick:C,disabled:t.solved||t.failed||c,className:"bg-blue-500 hover:bg-blue-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step"}),z.jsx("button",{onClick:y,disabled:t.solved||t.failed||c,className:"bg-green-500 hover:bg-green-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Solve"}),z.jsx("button",{onClick:x,disabled:t.solved||t.failed,className:`px-3 py-1 rounded text-white text-sm ${c?"bg-red-500 hover:bg-red-600":"bg-yellow-500 hover:bg-yellow-600"} disabled:bg-gray-300`,children:c?"Stop":"Animate"}),z.jsx("button",{onClick:E,disabled:t.solved||t.failed||c,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"}),z.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",t.iterations]}),t.timeToSolve!==void 0&&z.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(t.timeToSolve/1e3).toFixed(3),"s"]}),t.solved&&z.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),t.failed&&z.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),t.error&&z.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",t.error]})]})},rQi=t=>t!==null&&"pipelineDef"in t&&Array.isArray(t.pipelineDef),sQi=(t,e,n)=>{const o=t.currentPipelineStageIndex;return e<o?"Completed":e===o&&t.activeSubSolver?t.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},aQi=(t,e)=>{const o=t.pipelineDef[e].solverName,i=sQi(t,e),r=t[o],s=t.firstIterationOfStage?.[o]??(e===t.currentPipelineStageIndex?t.iterations:null),a=t.iterations;let A=0;if(i==="Completed"){const u=t.pipelineDef[e+1],h=u?t.firstIterationOfStage?.[u.solverName]:void 0;h!==void 0&&s!==null?A=h-s:s!==null&&(A=a-s)}else i==="In Progress"&&s!==null&&(A=a-s);const c=t.timeSpentOnStage?.[o]??0;let l=0;i==="Completed"?l=1:i==="In Progress"&&r&&(l=r.progress??0);const g=r?.stats??null;return{index:e,name:o,status:i,firstIteration:s,iterations:A,progress:l,timeSpent:c,stats:g&&Object.keys(g).length>0?g:null,solverInstance:r??null}},AQi=({status:t})=>{const e={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return z.jsx("span",{className:`font-medium ${e[t]}`,children:t})},cQi=({progress:t})=>{if(t===0)return null;const e=Math.round(t*100);return z.jsxs("div",{className:"flex items-center gap-2",children:[z.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:z.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${e}%`}})}),z.jsxs("span",{className:"text-xs text-gray-500",children:[e,"%"]})]})},TAn=t=>{if(typeof t=="string")return t;if(typeof t=="number"||typeof t=="boolean"||typeof t=="bigint"||t==null)return String(t);if(typeof t=="object")try{return JSON.stringify(t)}catch{return String(t)}return String(t)},lQi=t=>Object.entries(t).map(([e,n])=>`${e}: ${TAn(n)}`).join(", "),gQi=({stats:t})=>{if(!t||Object.keys(t).length===0)return z.jsx("span",{children:"-"});const e=Object.entries(t),n=lQi(t);return z.jsxs("details",{className:"cursor-pointer",children:[z.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:n}),z.jsx("div",{className:"mt-1 text-xs",children:e.map(([o,i])=>z.jsxs("div",{children:[o,": ",TAn(i)]},o))})]})},Sze=t=>{if(t===null||typeof t!="object")return t;if(Array.isArray(t))return t.map(Sze);const e={};for(const[n,o]of Object.entries(t))n.startsWith("_")||(e[n]=Sze(o));return e},uQi=(t,e)=>{try{if(typeof t.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${e}`);return}const n=Sze(t.getConstructorParams()),o=new Blob([JSON.stringify(n,null,2)],{type:"application/json"}),i=URL.createObjectURL(o),r=document.createElement("a");r.href=i,r.download=`${e}_input.json`,r.click(),URL.revokeObjectURL(i)}catch(n){alert(`Error downloading input for ${e}: ${n instanceof Error?n.message:String(n)}`)}},dQi=({expanded:t})=>z.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:`w-4 h-4 transition-transform duration-200 ${t?"rotate-90":""}`,children:z.jsx("path",{fillRule:"evenodd",d:"M4.5 5.653c0-1.426 1.529-2.33 2.779-1.643l11.54 6.348c1.295.712 1.295 2.573 0 3.285L7.28 19.991c-1.25.687-2.779-.217-2.779-1.643V5.653z",clipRule:"evenodd"})}),kAn=t=>{let e=t;for(;e.activeSubSolver;)e=e.activeSubSolver;return e},FAn=({solver:t,onStepUntilPhase:e,onDownloadInput:n,isNested:o=!1,indentLevel:i=0,triggerRender:r})=>{const[s,a]=te.useState(new Set),A=t.pipelineDef.map((p,_)=>aQi(t,_)),c=p=>{a(_=>{const f=new Set(_);return f.has(p)?f.delete(p):f.add(p),f})},l=p=>{e?.(p)},g=p=>{p.solverInstance&&(n?n(p.solverInstance,p.name):uQi(p.solverInstance,p.name))},u=p=>`${(p/1e3).toFixed(2)}s`,h=()=>{if(!t.solved&&!t.failed){const p=t.activeSubSolver;for(;!t.solved&&!t.failed&&(t.step(),!(t.activeSubSolver&&t.activeSubSolver!==p)););r?.()}},d=()=>{if(!t.solved&&!t.failed){const p=kAn(t);for(;!t.solved&&!t.failed&&(t.step(),kAn(t)===p););r?.()}},m=i*24;return z.jsxs("div",{className:o?"":"border-t border-gray-200",children:[!o&&z.jsxs("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200 flex items-center justify-between",children:[z.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Stages"}),z.jsxs("div",{className:"flex gap-2",children:[z.jsx("button",{onClick:d,disabled:t.solved||t.failed,className:"bg-indigo-500 hover:bg-indigo-600 disabled:bg-gray-300 disabled:cursor-not-allowed cursor-pointer text-white px-3 py-1 rounded text-sm",children:"Next Solver"}),z.jsx("button",{onClick:h,disabled:t.solved||t.failed,className:"bg-purple-500 hover:bg-purple-600 disabled:bg-gray-300 disabled:cursor-not-allowed cursor-pointer text-white px-3 py-1 rounded text-sm",children:"Next Stage"})]})]}),z.jsx("div",{className:"overflow-x-auto",children:z.jsxs("table",{className:"w-full text-sm",children:[!o&&z.jsx("thead",{children:z.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stage"}),z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),z.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",z.jsx("sub",{children:"0"})]}),z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),z.jsx("tbody",{children:A.map(p=>{const _=rQi(p.solverInstance),f=s.has(p.name);return z.jsxs(ws.Fragment,{children:[z.jsxs("tr",{className:`border-b border-gray-100 ${p.status==="In Progress"?"bg-yellow-50":""}`,children:[z.jsx("td",{className:"px-4 py-2",children:z.jsxs("div",{className:"flex items-center gap-2",style:{paddingLeft:m},children:[_?z.jsx("button",{onClick:()=>c(p.name),className:"text-gray-500 hover:text-gray-700",title:f?"Collapse":"Expand",children:z.jsx(dQi,{expanded:f})}):z.jsx("span",{className:"w-4"}),z.jsx("span",{className:"text-gray-400 w-6",children:String(p.index+1).padStart(2,"0")}),z.jsx("button",{onClick:()=>l(p.name),disabled:p.status==="Completed"||t.solved||t.failed,className:"text-blue-500 hover:text-blue-700 disabled:text-gray-300 disabled:cursor-not-allowed",title:`Step until ${p.name} completes`,children:z.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:z.jsx("path",{fillRule:"evenodd",d:"M4.5 5.653c0-1.426 1.529-2.33 2.779-1.643l11.54 6.348c1.295.712 1.295 2.573 0 3.285L7.28 19.991c-1.25.687-2.779-.217-2.779-1.643V5.653z",clipRule:"evenodd"})})}),z.jsx("span",{className:"font-medium text-gray-900",children:p.name})]})}),z.jsx("td",{className:"px-4 py-2",children:z.jsx(AQi,{status:p.status})}),z.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:p.firstIteration!==null?p.firstIteration:""}),z.jsx("td",{className:"px-4 py-2 text-gray-600",children:p.iterations}),z.jsx("td",{className:"px-4 py-2",children:z.jsx(cQi,{progress:p.progress})}),z.jsx("td",{className:"px-4 py-2 text-gray-600",children:u(p.timeSpent)}),z.jsx("td",{className:"px-4 py-2 text-gray-500",children:z.jsx(gQi,{stats:p.stats})}),z.jsx("td",{className:"px-4 py-2",children:p.solverInstance?z.jsxs("button",{onClick:()=>g(p),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${p.name}`,children:[z.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:z.jsx("path",{fillRule:"evenodd",d:"M12 2.25a.75.75 0 01.75.75v11.69l3.22-3.22a.75.75 0 111.06 1.06l-4.5 4.5a.75.75 0 01-1.06 0l-4.5-4.5a.75.75 0 111.06-1.06l3.22 3.22V3a.75.75 0 01.75-.75zm-9 13.5a.75.75 0 01.75.75v2.25a1.5 1.5 0 001.5 1.5h13.5a1.5 1.5 0 001.5-1.5V16.5a.75.75 0 011.5 0v2.25a3 3 0 01-3 3H5.25a3 3 0 01-3-3V16.5a.75.75 0 01.75-.75z",clipRule:"evenodd"})}),z.jsx("span",{children:"Input"})]}):null})]}),_&&f&&z.jsx("tr",{children:z.jsx("td",{colSpan:8,className:"p-0",children:z.jsx(FAn,{solver:p.solverInstance,onStepUntilPhase:e,onDownloadInput:n,isNested:!0,indentLevel:i+1,triggerRender:r})})})]},p.name)})})]})})]})};function hQi({graphics:t}){const e=t.points??[],n=t.lines??[],o=t.rects??[],i=t.circles??[],r=t.texts??[];let s=Number.POSITIVE_INFINITY,a=Number.POSITIVE_INFINITY,A=Number.NEGATIVE_INFINITY,c=Number.NEGATIVE_INFINITY;const l=(p,_)=>{typeof p=="number"&&(p<s&&(s=p),p>A&&(A=p)),typeof _=="number"&&(_<a&&(a=_),_>c&&(c=_))};for(const p of e)l(p.x,p.y);for(const p of n){const _=p.points??[];for(const f of _)l(f.x,f.y)}for(const p of o){const _=p.x??0,f=p.y??0,I=p.width??0,C=p.height??0;l(_,f),l(_+I,f+C)}for(const p of i){const _=p.x??0,f=p.y??0,I=p.radius??1;l(_-I,f-I),l(_+I,f+I)}for(const p of r)l(p.x,p.y);(!isFinite(s)||!isFinite(a)||!isFinite(A)||!isFinite(c))&&(s=-20,a=-20,A=20,c=20);const g=10,u=s-g,h=a-g,d=Math.max(1,A-s+2*g),m=Math.max(1,c-a+2*g);return z.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${u} ${h} ${d} ${m}`,role:"img","aria-label":"Graphics fallback",children:[o.map((p,_)=>z.jsx("rect",{x:p.x??0,y:p.y??0,width:p.width??0,height:p.height??0,fill:"none",stroke:p.strokeColor??"black",strokeWidth:p.strokeWidth??1},`rect-${_}`)),n.map((p,_)=>z.jsx("polyline",{fill:"none",stroke:p.strokeColor??"black",strokeWidth:p.strokeWidth??1,points:(p.points??[]).map(f=>`${f.x??0},${f.y??0}`).join(" ")},`line-${_}`)),i.map((p,_)=>z.jsx("circle",{cx:p.x??0,cy:p.y??0,r:p.radius??1.5,fill:p.fillColor??"none",stroke:p.strokeColor??"black",strokeWidth:p.strokeWidth??1},`circle-${_}`)),e.map((p,_)=>z.jsx("circle",{cx:p.x??0,cy:p.y??0,r:p.radius??1.5,fill:p.color??"black"},`point-${_}`)),r.map((p,_)=>z.jsx("text",{x:p.x??0,y:p.y??0,fontSize:p.fontSize??10,fill:p.color??"black",children:p.text??""},`text-${_}`))]})}var mQi=class extends ws.Component{constructor(t){super(t),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(t){console.error("InteractiveGraphics render error:",t)}render(){return this.state.hasError?this.props.fallback:this.props.children}},pQi=({solver:t,createSolver:e,animationSpeed:n=25,onSolverStarted:o,onSolverCompleted:i})=>{const[r,s]=te.useReducer(f=>f+1,0),[a]=te.useState(()=>{if(e)return e();if(!t)throw new Error("GenericSolverDebugger requires solver or createSolver");return t}),[A,c]=te.useState(()=>typeof window>"u"?"vector":window.localStorage.getItem("solver-utils-renderer")==="canvas"?"canvas":"vector"),[l,g]=te.useState(n),u=te.useMemo(()=>{try{return a.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(f){return console.error("Visualization error:",f),{points:[],lines:[],rects:[],circles:[]}}},[a,r]),h=te.useMemo(()=>(u.rects?.length||0)===0&&(u.lines?.length||0)===0&&(u.points?.length||0)===0&&(u.circles?.length||0)===0,[u]);te.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const f=document.createElement("script");f.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(f)}},[]),te.useEffect(()=>{g(n)},[n]);const d=a.pipelineDef!==void 0,m=f=>{const I=a;if(!a.solved&&!a.failed){for(;!a.solved&&!a.failed&&I.currentPipelineStageIndex<=I.pipelineDef.findIndex(C=>C.solverName===f);)a.step();s()}},p=()=>{const f=JSON.stringify(u,null,2),I=new Blob([f],{type:"application/json"}),C=URL.createObjectURL(I),y=document.createElement("a");y.download="visualization.json",y.href=C,document.body.appendChild(y),y.click(),document.body.removeChild(y),URL.revokeObjectURL(C)},_=f=>{c(f),typeof window<"u"&&window.localStorage.setItem("solver-utils-renderer",f)};return z.jsxs("div",{children:[z.jsx(iQi,{solver:a,triggerRender:s,animationSpeed:l,renderer:A,onRendererChange:_,onAnimationSpeedChange:g,onDownloadVisualization:p,onSolverStarted:o,onSolverCompleted:i}),h?z.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):z.jsx(mQi,{fallback:z.jsx(hQi,{graphics:u}),children:A==="canvas"?z.jsx(tQi,{graphics:u}):z.jsx($bi,{graphics:u})}),d&&z.jsx(FAn,{solver:a,onStepUntilPhase:m,triggerRender:s})]})};const _Qi=()=>{te.useEffect(()=>{const t="tailwind-cdn-script";if(document.getElementById(t)||window.tailwind)return;const e=document.createElement("div");e.className="hidden",document.body.appendChild(e);const n=window.getComputedStyle(e).display==="none";if(document.body.removeChild(e),n)return;const o=document.createElement("script");o.id=t,o.src="https://cdn.tailwindcss.com",document.head.appendChild(o)},[])},fQi=1e3,sE=(t,e)=>{const{fileName:n,mimeType:o="text/plain"}=e,i=t instanceof Blob?t:new Blob([t],{type:o}),r=URL.createObjectURL(i),s=document.createElement("a");s.href=r,s.download=n,s.target="_blank",s.rel="noopener noreferrer",s.style.display="none",document.body.appendChild(s),s.click(),document.body.removeChild(s),setTimeout(()=>{URL.revokeObjectURL(r)},fQi)},bze=t=>{let e=t.trim().replace(/[\\/:*?"<>|]/g,"_").replace(/[\x00-\x1f]/g,"").replace(/^\.+/,"").replace(/\.+$/,"").replace(/\s+/g," ").replace(/_+/g,"_");return/^(con|prn|aux|nul|com[0-9]|lpt[0-9])$/i.test(e)&&(e=`_${e}`),e=e.slice(0,200),e||"untitled"},IQi=t=>{const e=t.solverConstructorArgs??[t.solverParams];if(t.solverName!=="AutoroutingPipelineSolver7_MultiGraph"||e.length!==1)return e;const[{input:n,options:o}]=e;return[n,o]},h7="https://github.com/tscircuit/tscircuit-autorouter/issues/new",LAn="https://github.com/tscircuit/copper-pour-solver/issues/new",HAn="https://github.com/tscircuit/calculate-packing/issues/new",CQi="https://github.com/tscircuit/matchpack/issues/new",OAn="https://github.com/tscircuit/schematic-trace-solver/issues/new?template=json-bug-report.yml",yQi={PackSolver2:HAn,LayoutPipelineSolver:CQi,AutoroutingPipelineSolver:h7,AssignableAutoroutingPipeline2:h7,AssignableAutoroutingPipeline3:h7,AutoroutingPipeline1_OriginalUnravel:h7,AutoroutingPipelineSolver3_HgPortPointPathing:h7,AutoroutingPipelineSolver4:h7,AutoroutingPipelineSolver5:h7,AutoroutingPipelineSolver7_MultiGraph:h7,AutoroutingPipelineSolver8:h7,CopperPourPipelineSolver:LAn,SchematicTracePipelineSolver:OAn},xQi=t=>t.toLowerCase().includes("pack")?cyi:t.toLowerCase().includes("rout")?jon:tyi,GAn=t=>{const e=yQi[t];if(e)return e;const n=t.toLowerCase();return n.includes("autorout")?h7:n.includes("schematic")&&n.includes("trace")?OAn:n.includes("copperpour")?LAn:n.includes("pack")?HAn:null},EQi=t=>`${bze(`${t.componentName}-${t.solverName}`)}-solver-input.json`,YAn=t=>{sE(JSON.stringify(t.solverParams,null,2),{fileName:EQi(t),mimeType:"application/json"})},BQi=({solverEvent:t})=>{const e=GAn(t.solverName);return z.jsxs("div",{className:"rf-flex rf-items-center rf-justify-end rf-gap-2 rf-border-b rf-border-gray-200 rf-bg-gray-50 rf-px-4 rf-py-2",children:[z.jsxs(Kc,{type:"button",variant:"outline",size:"sm",onClick:()=>YAn(t),children:[z.jsx(Iq,{className:"rf-w-4 rf-h-4"}),"Download"]}),e?z.jsx(Kc,{asChild:!0,variant:"outline",size:"sm",children:z.jsxs("a",{href:e,target:"_blank",rel:"noopener noreferrer",children:[z.jsx(Mde,{className:"rf-w-4 rf-h-4"}),"Report"]})}):z.jsxs(Kc,{type:"button",variant:"outline",size:"sm",disabled:!0,title:"No report link configured for this solver",children:[z.jsx(Mde,{className:"rf-w-4 rf-h-4"}),"Report"]})]})},SQi=({solverEvent:t})=>{const e=GAn(t.solverName);return e?z.jsx(Kc,{asChild:!0,variant:"ghost",size:"icon",className:"rf-h-8 rf-w-8",children:z.jsx("a",{href:e,target:"_blank",rel:"noopener noreferrer",title:"Report solver bug","aria-label":"Report solver bug",children:z.jsx(Mde,{className:"rf-w-4 rf-h-4"})})}):z.jsx(Kc,{type:"button",variant:"ghost",size:"icon",className:"rf-h-8 rf-w-8",disabled:!0,title:"No report link configured for this solver","aria-label":"Report solver bug",children:z.jsx(Mde,{className:"rf-w-4 rf-h-4"})})},bQi=({solverEvents:t=[]})=>{const[e,n]=te.useState(null);_Qi();const o=te.useMemo(()=>{const a=new Map;for(const A of t){const c=`${A.componentName}-${A.solverName}`;a.set(c,A)}return a},[t]),i=te.useMemo(()=>Array.from(o.keys()),[o]),r=e?o.get(e):null,s=te.useMemo(()=>{if(!r)return{instance:null,error:null,classFound:!1};const a=SDe[r.solverName];if(!a)return{instance:null,error:`Solver class "${r.solverName}" not found in SOLVERS registry. Available: ${Object.keys(SDe).join(", ")}`,classFound:!1};try{return{instance:new a(...IQi(r)),error:null,classFound:!0}}catch(A){const c=A instanceof Error?A.message:String(A);return console.error("Failed to reconstruct solver:",A),{instance:null,error:`Failed to instantiate solver: ${c}`,classFound:!0}}},[r]);return t.length===0?z.jsx("div",{className:"rf-p-4",children:z.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:z.jsxs("div",{className:"rf-p-4",children:[z.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),z.jsx("p",{className:"rf-text-sm rf-text-gray-600",children:"Solvers will appear here when the circuit runs. Solvers are used for tasks like component packing and autorouting."})]})})}):z.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[z.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[z.jsxs("div",{className:"rf-text-xs rf-font-semibold rf-text-gray-500 rf-px-3 rf-py-2 rf-bg-gray-50 rf-border-b rf-border-gray-200",children:[i.length," ",i.length===1?"Solver":"Solvers"]}),i.map(a=>{const A=o.get(a),c=e===a;return z.jsx("div",{className:`rf-px-3 rf-py-2 rf-cursor-pointer rf-border-b rf-border-gray-100 ${c?"rf-bg-blue-50 rf-border-l-2 rf-border-l-blue-500":"hover:rf-bg-gray-50"}`,onClick:()=>n(a),children:(()=>{const l=xQi(A.solverName);return z.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[z.jsx(l,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),z.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[z.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:A.componentName}),z.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:A.solverName})]})]})})()},a)})]}),z.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:r?s.instance?z.jsxs("div",{className:"rf-flex rf-h-full rf-flex-col rf-overflow-y-auto",children:[z.jsx(BQi,{solverEvent:r}),z.jsx("div",{className:"rf-min-h-0 rf-flex-1",children:z.jsx(EB,{fallback:z.jsx("div",{className:"rf-p-4",children:z.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[z.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),z.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",r.solverName]})]})}),children:z.jsx(pQi,{solver:s.instance})})})]}):z.jsxs("div",{className:"rf-p-4",children:[z.jsxs("div",{className:"rf-mb-4",children:[z.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:r.solverName}),z.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",r.componentName]})]}),s.error&&z.jsx("div",{className:`rf-rounded-md rf-border rf-p-4 rf-mb-4 ${s.classFound?"rf-bg-red-50 rf-border-red-200":"rf-bg-yellow-50 rf-border-yellow-200"}`,children:z.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),z.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[z.jsxs("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50 rf-flex rf-items-center rf-justify-between rf-gap-2",children:[z.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"}),z.jsxs("div",{className:"rf-flex rf-items-center rf-gap-1",children:[z.jsx(SQi,{solverEvent:r}),z.jsx(Kc,{type:"button",variant:"ghost",size:"icon",className:"rf-h-8 rf-w-8","aria-label":"Download solver input JSON",title:"Download solver input JSON",onClick:()=>YAn(r),children:z.jsx(Iq,{className:"rf-w-4 rf-h-4"})})]})]}),z.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:z.jsx("pre",{className:"rf-text-xs rf-font-mono rf-text-gray-600 rf-whitespace-pre-wrap rf-overflow-x-auto",children:JSON.stringify(r.solverParams,null,2)})})]})]}):z.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:z.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},QQi=new Map([["custom","Custom"],["fanout","Fanout"],["single_layer_fanout","Single layer fanout"],["tscircuit_simplify","Simplify"]]),vQi=new Set(["tscircuit","default","auto","auto_local"]);function PQi(t){if(t==="FanoutSolver")return"Fanout";if(t==="AutoroutingPipelineSolver11_Simplification")return"Simplify";const e=t.match(/^AutoroutingPipeline(?:Solver)?(\d+)(?:_|$)/);if(e)return`Pipeline${e[1]}`;const n=t.match(/^AssignableAutoroutingPipeline(\d+)$/);return n?`Assignable${n[1]}`:t}function wQi(t){const e=t.autorouterName?.trim(),n=e?.replace(/-/g,"_"),o=n&&QQi.get(n);if(o)return o;if(n&&!vQi.has(n))return e;const i=t.solverName?.trim();if(i)return PQi(i);const r=t.autorouterVersion?.trim();if(r){const s=r.match(/^beta[_-]pipeline(\d+)$/);return s?`Pipeline${s[1]}`:r==="latest"?"default":r}return e?"default":"Unknown"}const Qze="#fbbf24";function MQi(t){const e=t.endSimpleRouteJson?.traces??[],n=new Set(e.flatMap(i=>[i.pcb_trace_id,i.__replaces_pcb_trace_id].filter(r=>r!==void 0)));return[...(t.startSimpleRouteJson?.traces??[]).filter(i=>!n.has(i.pcb_trace_id)),...e]}function UAn(t){const e=new Map((t.startSimpleRouteJson?.traces??[]).map(n=>[n.pcb_trace_id,n]));return(t.endSimpleRouteJson?.traces??[]).filter(n=>{const o=e.get(n.pcb_trace_id);return!o||!!n.__replaces_pcb_trace_id&&n.__replaces_pcb_trace_id!==o.__replaces_pcb_trace_id||JSON.stringify(o.route)!==JSON.stringify(n.route)}).map(n=>n.pcb_trace_id)}function DQi(t,e){return{outer_diameter:t.via_diameter??e.minViaPadDiameter??e.min_via_pad_diameter??e.minViaDiameter??.6,hole_diameter:t.via_hole_diameter??e.minViaHoleDiameter??e.min_via_hole_diameter??.3}}function KAn(t,e){const n=[];for(const a of t.route)a.route_type==="wire"?n.push({...a,layer:a.layer}):a.route_type==="via"?n.push({route_type:"via",x:a.x,y:a.y,from_layer:a.from_layer,to_layer:a.to_layer,...DQi(a,e)}):a.route_type==="through_obstacle"&&n.push({route_type:"through_pad",start:{...a.start},end:{...a.end},width:a.width,start_layer:a.from_layer,end_layer:a.to_layer,pcb_smtpad_id:a.circuitJsonMetadata?.pcb_smtpad_id,pcb_plated_hole_id:a.circuitJsonMetadata?.pcb_plated_hole_id});const o=a=>{let A=-1,c=Number.POSITIVE_INFINITY;return n.forEach((l,g)=>{if(l.route_type!=="wire")return;const u=Math.hypot(l.x-a.x,l.y-a.y);u<c&&(c=u,A=g)}),A},i=t.route.filter(a=>a.route_type==="jumper").map(a=>[o(a.start),o(a.end)].sort((A,c)=>A-c)).filter(([a,A])=>a>=0&&A>a).sort(([a],[A])=>a-A),r=[];let s=0;for(const[a,A]of i)a>=s&&r.push(n.slice(s,a+1)),s=Math.max(s,A);return s<n.length&&r.push(n.slice(s)),r}function NQi(t){const e=[],n=[],o=t.endSimpleRouteJson;if(!o)return{lines:e,circles:n};const i=new Set(UAn(t));for(const r of o.traces??[])if(i.has(r.pcb_trace_id))for(const s of KAn(r,o)){let a;for(const A of s){if(A.route_type==="through_pad"){a={...A.end,layer:A.end_layer,width:A.width};continue}const c=A.route_type==="wire"?A.layer:A.from_layer;a&&a.layer===c&&(a.x!==A.x||a.y!==A.y)&&e.push({points:[{x:a.x,y:a.y},{x:A.x,y:A.y}],strokeWidth:A.route_type==="wire"?A.width:a.width,strokeColor:Qze,layer:c}),A.route_type==="via"&&n.push({center:{x:A.x,y:A.y},radius:A.outer_diameter/2,stroke:Qze,fill:"transparent"}),a={x:A.x,y:A.y,layer:A.route_type==="wire"?A.layer:A.to_layer,width:A.route_type==="wire"?A.width:a?.width??o.minTraceWidth}}}return{coordinateSystem:"cartesian",lines:e,circles:n}}function RQi(t){const e=JSON.stringify(t);let n=2166136261;for(let o=0;o<e.length;o++)n=Math.imul(n^e.charCodeAt(o),16777619);return(n>>>0).toString(36)}const TQi=new Set(["pcb_trace","pcb_via","pcb_copper_pour","pcb_ground_plane","pcb_ground_plane_region","pcb_thermal_spoke","pcb_breakout_point"]);function kQi(t,e,n){const o=n==="input"?e.startSimpleRouteJson??e.errorSimpleRouteJson:e.endSimpleRouteJson,i=t.filter(c=>!TQi.has(c.type)&&!c.type.endsWith("_error")&&!c.type.endsWith("_warning"));if(!o)return i;const r=n==="input"?o.traces??[]:MQi(e),s=new Set(t.filter(c=>c.type==="source_trace").map(c=>c.source_trace_id)),a=["top",...Array.from({length:Math.max(0,o.layerCount-2)},(c,l)=>`inner${l+1}`),...o.layerCount>1?["bottom"]:[]],A=[];for(const c of r){const g=o.connections.find(h=>h.name===c.connection_name||h.source_trace_id===c.connection_name)?.source_trace_id??c.connection_name??"",u=KAn(c,o);for(const[h,d]of u.entries()){const m={type:"pcb_trace",pcb_trace_id:`${e.id}_${n}_${c.pcb_trace_id}_${h}_${RQi(d)}`,subcircuit_id:e.subcircuit_id??void 0,source_trace_id:s.has(g)?g:void 0,route:d};A.push(m);for(const[p,_]of d.entries()){if(_.route_type!=="via")continue;const f=a.indexOf(_.from_layer),I=a.indexOf(_.to_layer),C={type:"pcb_via",pcb_via_id:`${m.pcb_trace_id}_via_${p}`,pcb_trace_id:m.pcb_trace_id,subcircuit_id:e.subcircuit_id??void 0,x:_.x,y:_.y,outer_diameter:_.outer_diameter,hole_diameter:_.hole_diameter,layers:f>=0&&I>=0?a.slice(Math.min(f,I),Math.max(f,I)+1):[_.from_layer,_.to_layer]};A.push(C)}}}return[...i,...A]}const vze=(t,e)=>t.phaseName||`Phase ${t.phaseOrdinal??e+1}`,VAn=t=>t.componentDisplayName?.match(/name="([^"]+)"/)?.[1]?.replace(/^\./,"")||t.componentDisplayName||t.subcircuit_id||"Board",zAn=t=>t.startSimpleRouteJson??t.endSimpleRouteJson??t.errorSimpleRouteJson,FQi={is_showing_autorouting:!0,is_showing_rats_nest:!1,is_showing_drc_errors:!1,is_showing_drc_warnings:!1,is_showing_pcb_groups:!1},LQi=({circuitJson:t,phases:e=[],isRunning:n=!1})=>{const[o,i]=te.useState(null),[r,s]=te.useState("output"),[a,A]=te.useState(!0),[c,l]=te.useState(!1),g=te.useRef(null),[u,h]=te.useState(480),d=o?e.findIndex(T=>T.id===o.id&&zAn(T)===zAn(o)):-1,m=d<0?e.length-1:d,p=e[m],_=d<0,f=!!p?.endSimpleRouteJson,I=p?.startSimpleRouteJson??p?.errorSimpleRouteJson,C=!!I,y=r==="output"&&!f?"input":r==="input"&&!C?"output":r,x=y==="input"?I:p?.endSimpleRouteJson,E=te.useMemo(()=>!p||!x?null:kQi(t??[],p,y),[t,p,x,y]),B=te.useMemo(()=>p&&y==="output"&&a?NQi(p):{lines:[],circles:[]},[p,y,a]);if(te.useLayoutEffect(()=>{const T=g.current;if(!T)return;const H=()=>h(Math.max(360,T.clientHeight));H();const G=new ResizeObserver(H);return G.observe(T),()=>G.disconnect()},[!!p]),!p)return z.jsxs("div",{className:"rf-flex rf-min-h-[400px] rf-flex-col rf-items-center rf-justify-center rf-gap-3 rf-p-8 rf-text-center",children:[z.jsx(jon,{className:"rf-h-7 rf-w-7 rf-text-blue-500"}),z.jsx("h3",{className:"rf-text-base rf-font-medium",children:n?"Waiting for autorouting":"No autorouting captures"}),z.jsx("p",{className:"rf-max-w-md rf-text-sm rf-text-gray-500",children:n?"Phases appear as the circuit routes. Each capture includes its input and output on the PCB.":"Run a circuit with autorouting enabled to inspect its phases. A circuit JSON file alone does not include routing history."})]});const b=vze(p,m),Q=p.status==="running"&&n,w=!f,D=I?.connections.length,k=E?.filter(T=>T.type==="pcb_trace").length??0;return z.jsxs("div",{className:"rf-flex rf-h-full rf-min-h-[620px] rf-flex-col rf-bg-white md:rf-flex-row","data-testid":"autorouting-explorer",children:[z.jsxs("aside",{className:"rf-flex rf-shrink-0 rf-flex-col rf-border-b rf-border-gray-200 md:rf-w-52 md:rf-border-b-0 md:rf-border-r","aria-label":"Routing phases",children:[z.jsxs("div",{className:"rf-flex rf-items-center rf-justify-between rf-px-3 rf-py-2 rf-text-xs rf-text-gray-500",children:[z.jsx("span",{children:"Routing phases"}),z.jsx("span",{children:e.length})]}),z.jsx("div",{className:"rf-flex rf-gap-1 rf-overflow-x-auto rf-px-1.5 rf-pb-1.5 md:rf-flex-col md:rf-overflow-x-hidden md:rf-overflow-y-auto",children:e.map((T,H)=>{const G=UAn(T).length,U=T.endSimpleRouteJson?`${G} ${G===1?"trace":"traces"} routed`:T.status==="error"?"Failed":T.status==="running"&&n?"Routing…":"No output";return z.jsxs("button",{type:"button","aria-pressed":H===m,title:`${VAn(T)} · ${U}`,onClick:()=>i(T),className:Ur("rf-flex rf-min-w-[192px] rf-items-start rf-gap-2 rf-rounded-md rf-border rf-px-2 rf-py-2 rf-text-left md:rf-min-w-0",H===m?"rf-border-blue-200 rf-bg-blue-50":"rf-border-transparent hover:rf-bg-gray-50"),children:[z.jsx("span",{className:Ur("rf-flex rf-h-5 rf-w-5 rf-shrink-0 rf-items-center rf-justify-center rf-rounded-full rf-text-[11px]",H===m?"rf-bg-blue-600 rf-text-white":"rf-bg-gray-100 rf-text-gray-500"),children:H+1}),z.jsxs("span",{className:"rf-min-w-0 rf-flex-1",children:[z.jsxs("span",{className:"rf-flex rf-items-center rf-gap-1",children:[z.jsx("span",{className:"rf-min-w-0 rf-flex-1 rf-truncate rf-text-xs rf-font-medium rf-leading-5 rf-text-gray-800",title:vze(T,H),children:vze(T,H)}),T.status==="complete"?z.jsx(fq,{"aria-label":"Captured",className:"rf-h-3 rf-w-3 rf-shrink-0 rf-text-green-600"}):T.status==="error"?z.jsx(mKe,{"aria-label":"Failed",className:"rf-h-3 rf-w-3 rf-shrink-0 rf-text-red-500"}):n?z.jsx(Y5,{"aria-label":"Routing",className:"rf-h-3 rf-w-3 rf-shrink-0 rf-animate-spin rf-text-blue-500"}):null]}),z.jsxs("span",{className:"rf-block rf-text-[11px] rf-leading-4 rf-text-gray-500",children:[wQi(T)," · ",U]})]})]},T.id)})})]}),z.jsxs("div",{className:"rf-flex rf-min-w-0 rf-flex-1 rf-flex-col",children:[z.jsxs("div",{className:"rf-flex rf-flex-wrap rf-items-center rf-gap-3 rf-border-b rf-border-gray-200 rf-px-4 rf-py-3",children:[z.jsxs("h3",{className:"rf-mr-auto rf-flex rf-items-center rf-gap-2 rf-text-sm rf-font-medium",children:[b,z.jsxs("span",{className:"rf-text-xs rf-font-normal rf-text-gray-500",children:[m+1," of ",e.length]})]}),n&&z.jsx("button",{type:"button",onClick:()=>i(null),disabled:_,className:"rf-text-xs rf-text-blue-600 disabled:rf-text-gray-500",children:_?"Following latest":"Follow latest"}),z.jsx("div",{className:"rf-flex rf-rounded-md rf-bg-gray-100 rf-p-1","aria-label":"Phase snapshot",children:["input","output"].map(T=>z.jsx("button",{type:"button","aria-pressed":y===T,disabled:T==="input"?!C:!f,onClick:()=>s(T),className:Ur("rf-rounded rf-px-3 rf-py-1 rf-text-xs disabled:rf-opacity-40",y===T?"rf-bg-white rf-text-gray-900 rf-shadow-sm":"rf-text-gray-500"),children:T==="input"?"Input":"Output"},T))})]}),z.jsxs("div",{className:"rf-flex rf-flex-wrap rf-items-center rf-justify-between rf-gap-2 rf-px-4 rf-py-2 rf-text-xs rf-text-gray-600",children:[z.jsxs("label",{className:"rf-flex rf-items-center rf-gap-2",children:[z.jsx("input",{type:"checkbox",checked:a,disabled:y!=="output",onChange:T=>A(T.target.checked),className:"rf-accent-blue-600"}),z.jsx("span",{"aria-hidden":"true",className:"rf-inline-block rf-h-0.5 rf-w-3",style:{backgroundColor:Qze}}),"Highlight changes (all layers)"]}),z.jsxs("span",{children:[y==="input"?"Before this phase":"After this phase"," ","· ",k," traces"]})]}),w&&z.jsx("div",{className:Ur("rf-border-y rf-px-4 rf-py-2 rf-text-xs",p.status==="error"?"rf-border-red-100 rf-bg-red-50 rf-text-red-700":"rf-border-blue-100 rf-bg-blue-50 rf-text-blue-700"),role:"status",children:p.status==="error"?`Routing failed: ${p.error?.message||"No output was captured."}`:Q?"Routing in progress. Showing captured input until output is available.":"No output was captured for this phase. Showing the available input."}),z.jsx("div",{ref:g,className:"rf-relative rf-min-h-[360px] rf-flex-1","data-testid":"autorouting-pcb",children:E?z.jsx(fze,{circuitJson:E,height:u,allowEditing:!1,clickToInteractEnabled:!1,initialState:FQi,debugGraphics:B}):z.jsx("div",{className:"rf-p-6 rf-text-sm rf-text-gray-500",children:"No PCB snapshot available for this capture."})}),z.jsxs("div",{className:"rf-flex rf-flex-wrap rf-items-center rf-justify-between rf-gap-2 rf-border-t rf-border-gray-200 rf-px-4 rf-py-3 rf-text-xs rf-text-gray-500",children:[z.jsxs("span",{children:[D===void 0?"Input unavailable":`${D} input connections`,` · ${VAn(p)}`]}),z.jsxs("div",{className:"rf-flex rf-items-center rf-gap-4",children:[z.jsxs("button",{type:"button",disabled:!x,onClick:()=>sE(JSON.stringify(x,null,2),{fileName:`${p.id}-${y}.srj.json`,mimeType:"application/json"}),className:"rf-flex rf-items-center rf-gap-1 disabled:rf-opacity-40",children:[z.jsx(Iq,{className:"rf-h-3 rf-w-3"}),"Download SRJ"]}),z.jsxs("button",{type:"button","aria-expanded":c,onClick:()=>l(!c),className:"rf-flex rf-items-center rf-gap-1",children:[z.jsx(VG,{className:Ur("rf-h-3 rf-w-3",c&&"rf-rotate-90")}),"Inspect SRJ"]})]})]}),c&&z.jsx("pre",{className:"rf-m-0 rf-max-h-64 rf-overflow-auto rf-border-t rf-border-gray-200 rf-bg-gray-50 rf-p-4 rf-text-xs","aria-label":`${b} ${y} SRJ`,children:x?JSON.stringify(x,null,2):"No snapshot captured."})]})]})},JAn=({errorMessage:t,errorStack:e,circuitJsonErrors:n})=>{te.useEffect(()=>{if(t){const o=new Error(t);e&&(o.stack=e);try{UT.captureException(o)}catch{}}},[t,e]),te.useEffect(()=>{if(n&&n.length>0)for(const o of n){const i=new Error(o.message||"Circuit JSON Error");o.stack&&(i.stack=o.stack);try{UT.captureException(i,{error_type:o.type})}catch{}}},[n])},HQi=t=>{te.useEffect(()=>{try{Hxn(t)}catch{}},[t.source,t.component,t.isWebEmbedded,t.activeTab])},WAn="0.0.2778",OQi={version:WAn},Pze={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1},wze=new Map,ome=t=>{const e=wze.get(t);return e?Object.fromEntries(Object.entries(e.stores).map(([n,o])=>[n,o.getState()])):{}},GQi=(t,e,n)=>{if(t===void 0)return{type:"untracked",connection:e.connect(n)};const o=wze.get(n.name);if(o)return{type:"tracked",store:t,...o};const i={connection:e.connect(n),stores:{}};return wze.set(n.name,i),{type:"tracked",store:t,...i}},jAn=(t,e={})=>(n,o,i)=>{const{enabled:r,anonymousActionType:s,store:a,...A}=e;let c;try{c=(r??(Pze?"production":void 0)!=="production")&&window.__REDUX_DEVTOOLS_EXTENSION__}catch{}if(!c)return(Pze?"production":void 0)!=="production"&&r&&console.warn("[zustand devtools middleware] Please install/enable Redux devtools extension"),t(n,o,i);const{connection:l,...g}=GQi(a,c,A);let u=!0;i.setState=(m,p,_)=>{const f=n(m,p);if(!u)return f;const I=_===void 0?{type:s||"anonymous"}:typeof _=="string"?{type:_}:_;return a===void 0?(l?.send(I,o()),f):(l?.send({...I,type:`${a}/${I.type}`},{...ome(A.name),[a]:i.getState()}),f)};const h=(...m)=>{const p=u;u=!1,n(...m),u=p},d=t(i.setState,o,i);if(g.type==="untracked"?l?.init(d):(g.stores[g.store]=i,l?.init(Object.fromEntries(Object.entries(g.stores).map(([m,p])=>[m,m===g.store?d:p.getState()])))),i.dispatchFromDevtools&&typeof i.dispatch=="function"){let m=!1;const p=i.dispatch;i.dispatch=(..._)=>{(Pze?"production":void 0)!=="production"&&_[0].type==="__setState"&&!m&&(console.warn('[zustand devtools middleware] "__setState" action type is reserved to set state from the devtools. Avoid using it.'),m=!0),p(..._)}}return l.subscribe(m=>{var p;switch(m.type){case"ACTION":if(typeof m.payload!="string"){console.error("[zustand devtools middleware] Unsupported action format");return}return Mze(m.payload,_=>{if(_.type==="__setState"){if(a===void 0){h(_.state);return}Object.keys(_.state).length!==1&&console.error(`
5583
+ `,g=new Blob([l],{type:"text/plain"}),u=URL.createObjectURL(g),h=document.createElement("a");h.href=u,h.download=`${c}.test.ts`,h.click(),URL.revokeObjectURL(u)}catch(A){alert(`Error generating test.ts for ${t.getSolverName()}: ${A instanceof Error?A.message:String(A)}`)}o(!1)};return z.jsxs("div",{className:`relative ${e}`,ref:i,children:[z.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>o(!n),title:`Download options for ${t.getSolverName()}`,children:t.getSolverName()}),n&&z.jsxs("div",{className:"absolute top-full left-0 mt-1 bg-white border border-gray-300 rounded shadow-lg z-10 min-w-[150px]",children:[z.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:r,children:"Download JSON"}),z.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),z.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:a,children:"Download test.ts"})]})]})},RAn=t=>t.activeSubSolver?[t,...RAn(t.activeSubSolver)]:[t],oQi=({solver:t})=>{const e=RAn(t);return z.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:e.map((n,o)=>z.jsxs("div",{className:"flex items-center",children:[o>0&&z.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),z.jsx(nQi,{solver:n})]},n.getSolverName()))})},iQi=({solver:t,triggerRender:e,animationSpeed:n=25,renderer:o,onRendererChange:i,onAnimationSpeedChange:r,onDownloadVisualization:s,onSolverStarted:a,onSolverCompleted:A})=>{const[c,l]=te.useReducer(B=>!B,!1),g=te.useRef(void 0),u=te.useRef(null),h="solver-debugger-last-iteration",[d,m]=te.useState(null),p=te.useRef(null),_=te.useMemo(()=>[{label:"Slow",value:250,description:"250ms"},{label:"Normal",value:100,description:"100ms"},{label:"Fast",value:10,description:"10ms"},{label:"Fast (2x)",value:5,description:"5ms"},{label:"Fast (10x)",value:1,description:"1ms"},{label:"Fast 20x",value:.5,description:"2 steps / 1ms"},{label:"Fast 100x",value:.1,description:"10 steps / 1ms"}],[]),f=()=>{const B=Math.max(1,n),b=n<1?Math.round(1/n):1;g.current=setInterval(()=>{if(t.solved||t.failed){g.current&&(clearInterval(g.current),g.current=void 0),l(),e(),A&&t.solved&&A(t);return}for(let Q=0;Q<b&&!(t.solved||t.failed);Q++)t.step();e()},B)},I=()=>{g.current&&(clearInterval(g.current),g.current=void 0)},C=()=>{!t.solved&&!t.failed&&(t.step(),e())},y=()=>{!t.solved&&!t.failed&&(a&&a(t),t.solve(),e(),A&&A(t))},x=()=>{c?(I(),l()):(l(),f())},E=()=>{if(t.solved||t.failed||c)return;u.current===null&&typeof window<"u"&&(u.current=window.localStorage.getItem(h));const B=window.prompt("Step until which iteration?",u.current??`${t.iterations}`);if(B===null)return;u.current=B,typeof window<"u"&&window.localStorage.setItem(h,B);const b=Number(B);if(!Number.isFinite(b)){window.alert("Please enter a valid number for the iteration");return}for(;t.iterations<b&&!t.solved&&!t.failed;)t.step();e(),t.solved&&A&&A(t)};return te.useEffect(()=>()=>{I()},[]),te.useEffect(()=>{(t.solved||t.failed)&&c&&(I(),l())},[t.solved,t.failed,c]),te.useEffect(()=>{c&&(I(),f())},[n,c]),te.useEffect(()=>{if(typeof document>"u")return;const B=b=>{p.current&&!p.current.contains(b.target)&&m(null)};return document.addEventListener("mousedown",B),()=>{document.removeEventListener("mousedown",B)}},[]),z.jsxs("div",{className:"space-y-2 p-2 border-b",children:[z.jsx("div",{className:"flex items-center",children:z.jsxs("div",{className:"flex items-center gap-2",ref:p,children:[z.jsxs("div",{className:"flex h-9 items-center space-x-1 rounded-md border border-slate-200 bg-white p-1 shadow-sm",children:[z.jsxs("div",{className:"relative",children:[z.jsx("button",{type:"button",onClick:()=>m(d==="renderer"?null:"renderer"),className:"flex select-none items-center rounded-sm px-3 py-1 text-sm font-medium outline-none focus:bg-slate-100 data-[state=open]:bg-slate-100","data-state":d==="renderer"?"open":"closed",children:"Renderer"}),d==="renderer"&&z.jsx("div",{className:"absolute left-0 z-50 mt-1 min-w-[10rem] rounded-md border border-slate-200 bg-white p-1 text-slate-950 shadow-md",children:["vector","canvas"].map(B=>z.jsxs("button",{type:"button",onClick:()=>{i(B),m(null)},className:"flex w-full items-center rounded-sm px-2 py-1.5 text-sm hover:bg-slate-100",children:[B==="vector"?"Vector":"Canvas",o===B&&z.jsx("span",{className:"ml-auto text-xs text-slate-500",children:"✓"})]},B))})]}),z.jsxs("div",{className:"relative",children:[z.jsx("button",{type:"button",onClick:()=>m(d==="debug"?null:"debug"),className:"flex select-none items-center rounded-sm px-3 py-1 text-sm font-medium outline-none focus:bg-slate-100 data-[state=open]:bg-slate-100","data-state":d==="debug"?"open":"closed",children:"Debug"}),d==="debug"&&z.jsx("div",{className:"absolute left-0 z-50 mt-1 min-w-[12rem] rounded-md border border-slate-200 bg-white p-1 text-slate-950 shadow-md",children:z.jsx("button",{type:"button",onClick:()=>{s(),m(null)},className:"flex w-full items-center rounded-sm px-2 py-1.5 text-sm hover:bg-slate-100",children:"Download Visualization"})})]}),z.jsxs("div",{className:"relative",children:[z.jsx("button",{type:"button",onClick:()=>m(d==="animation"?null:"animation"),className:"flex select-none items-center rounded-sm px-3 py-1 text-sm font-medium outline-none focus:bg-slate-100 data-[state=open]:bg-slate-100","data-state":d==="animation"?"open":"closed",children:"Animation"}),d==="animation"&&z.jsx("div",{className:"absolute left-0 z-50 mt-1 min-w-[12rem] rounded-md border border-slate-200 bg-white p-1 text-slate-950 shadow-md",children:_.map(B=>z.jsxs("button",{type:"button",onClick:()=>{r(B.value),m(null)},className:"flex w-full items-center rounded-sm px-2 py-1.5 text-sm hover:bg-slate-100",children:[B.label,z.jsx("span",{className:"ml-auto text-xs text-slate-500",children:B.description}),n===B.value&&z.jsx("span",{className:"ml-2 text-xs text-slate-500",children:"✓"})]},B.value))})]})]}),z.jsx(oQi,{solver:t})]})}),z.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[z.jsx("button",{onClick:C,disabled:t.solved||t.failed||c,className:"bg-blue-500 hover:bg-blue-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step"}),z.jsx("button",{onClick:y,disabled:t.solved||t.failed||c,className:"bg-green-500 hover:bg-green-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Solve"}),z.jsx("button",{onClick:x,disabled:t.solved||t.failed,className:`px-3 py-1 rounded text-white text-sm ${c?"bg-red-500 hover:bg-red-600":"bg-yellow-500 hover:bg-yellow-600"} disabled:bg-gray-300`,children:c?"Stop":"Animate"}),z.jsx("button",{onClick:E,disabled:t.solved||t.failed||c,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"}),z.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",t.iterations]}),t.timeToSolve!==void 0&&z.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(t.timeToSolve/1e3).toFixed(3),"s"]}),t.solved&&z.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),t.failed&&z.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),t.error&&z.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",t.error]})]})},rQi=t=>t!==null&&"pipelineDef"in t&&Array.isArray(t.pipelineDef),sQi=(t,e,n)=>{const o=t.currentPipelineStageIndex;return e<o?"Completed":e===o&&t.activeSubSolver?t.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},aQi=(t,e)=>{const o=t.pipelineDef[e].solverName,i=sQi(t,e),r=t[o],s=t.firstIterationOfStage?.[o]??(e===t.currentPipelineStageIndex?t.iterations:null),a=t.iterations;let A=0;if(i==="Completed"){const u=t.pipelineDef[e+1],h=u?t.firstIterationOfStage?.[u.solverName]:void 0;h!==void 0&&s!==null?A=h-s:s!==null&&(A=a-s)}else i==="In Progress"&&s!==null&&(A=a-s);const c=t.timeSpentOnStage?.[o]??0;let l=0;i==="Completed"?l=1:i==="In Progress"&&r&&(l=r.progress??0);const g=r?.stats??null;return{index:e,name:o,status:i,firstIteration:s,iterations:A,progress:l,timeSpent:c,stats:g&&Object.keys(g).length>0?g:null,solverInstance:r??null}},AQi=({status:t})=>{const e={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return z.jsx("span",{className:`font-medium ${e[t]}`,children:t})},cQi=({progress:t})=>{if(t===0)return null;const e=Math.round(t*100);return z.jsxs("div",{className:"flex items-center gap-2",children:[z.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:z.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${e}%`}})}),z.jsxs("span",{className:"text-xs text-gray-500",children:[e,"%"]})]})},TAn=t=>{if(typeof t=="string")return t;if(typeof t=="number"||typeof t=="boolean"||typeof t=="bigint"||t==null)return String(t);if(typeof t=="object")try{return JSON.stringify(t)}catch{return String(t)}return String(t)},lQi=t=>Object.entries(t).map(([e,n])=>`${e}: ${TAn(n)}`).join(", "),gQi=({stats:t})=>{if(!t||Object.keys(t).length===0)return z.jsx("span",{children:"-"});const e=Object.entries(t),n=lQi(t);return z.jsxs("details",{className:"cursor-pointer",children:[z.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:n}),z.jsx("div",{className:"mt-1 text-xs",children:e.map(([o,i])=>z.jsxs("div",{children:[o,": ",TAn(i)]},o))})]})},Sze=t=>{if(t===null||typeof t!="object")return t;if(Array.isArray(t))return t.map(Sze);const e={};for(const[n,o]of Object.entries(t))n.startsWith("_")||(e[n]=Sze(o));return e},uQi=(t,e)=>{try{if(typeof t.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${e}`);return}const n=Sze(t.getConstructorParams()),o=new Blob([JSON.stringify(n,null,2)],{type:"application/json"}),i=URL.createObjectURL(o),r=document.createElement("a");r.href=i,r.download=`${e}_input.json`,r.click(),URL.revokeObjectURL(i)}catch(n){alert(`Error downloading input for ${e}: ${n instanceof Error?n.message:String(n)}`)}},dQi=({expanded:t})=>z.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:`w-4 h-4 transition-transform duration-200 ${t?"rotate-90":""}`,children:z.jsx("path",{fillRule:"evenodd",d:"M4.5 5.653c0-1.426 1.529-2.33 2.779-1.643l11.54 6.348c1.295.712 1.295 2.573 0 3.285L7.28 19.991c-1.25.687-2.779-.217-2.779-1.643V5.653z",clipRule:"evenodd"})}),kAn=t=>{let e=t;for(;e.activeSubSolver;)e=e.activeSubSolver;return e},FAn=({solver:t,onStepUntilPhase:e,onDownloadInput:n,isNested:o=!1,indentLevel:i=0,triggerRender:r})=>{const[s,a]=te.useState(new Set),A=t.pipelineDef.map((p,_)=>aQi(t,_)),c=p=>{a(_=>{const f=new Set(_);return f.has(p)?f.delete(p):f.add(p),f})},l=p=>{e?.(p)},g=p=>{p.solverInstance&&(n?n(p.solverInstance,p.name):uQi(p.solverInstance,p.name))},u=p=>`${(p/1e3).toFixed(2)}s`,h=()=>{if(!t.solved&&!t.failed){const p=t.activeSubSolver;for(;!t.solved&&!t.failed&&(t.step(),!(t.activeSubSolver&&t.activeSubSolver!==p)););r?.()}},d=()=>{if(!t.solved&&!t.failed){const p=kAn(t);for(;!t.solved&&!t.failed&&(t.step(),kAn(t)===p););r?.()}},m=i*24;return z.jsxs("div",{className:o?"":"border-t border-gray-200",children:[!o&&z.jsxs("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200 flex items-center justify-between",children:[z.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Stages"}),z.jsxs("div",{className:"flex gap-2",children:[z.jsx("button",{onClick:d,disabled:t.solved||t.failed,className:"bg-indigo-500 hover:bg-indigo-600 disabled:bg-gray-300 disabled:cursor-not-allowed cursor-pointer text-white px-3 py-1 rounded text-sm",children:"Next Solver"}),z.jsx("button",{onClick:h,disabled:t.solved||t.failed,className:"bg-purple-500 hover:bg-purple-600 disabled:bg-gray-300 disabled:cursor-not-allowed cursor-pointer text-white px-3 py-1 rounded text-sm",children:"Next Stage"})]})]}),z.jsx("div",{className:"overflow-x-auto",children:z.jsxs("table",{className:"w-full text-sm",children:[!o&&z.jsx("thead",{children:z.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stage"}),z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),z.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",z.jsx("sub",{children:"0"})]}),z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),z.jsx("tbody",{children:A.map(p=>{const _=rQi(p.solverInstance),f=s.has(p.name);return z.jsxs(ws.Fragment,{children:[z.jsxs("tr",{className:`border-b border-gray-100 ${p.status==="In Progress"?"bg-yellow-50":""}`,children:[z.jsx("td",{className:"px-4 py-2",children:z.jsxs("div",{className:"flex items-center gap-2",style:{paddingLeft:m},children:[_?z.jsx("button",{onClick:()=>c(p.name),className:"text-gray-500 hover:text-gray-700",title:f?"Collapse":"Expand",children:z.jsx(dQi,{expanded:f})}):z.jsx("span",{className:"w-4"}),z.jsx("span",{className:"text-gray-400 w-6",children:String(p.index+1).padStart(2,"0")}),z.jsx("button",{onClick:()=>l(p.name),disabled:p.status==="Completed"||t.solved||t.failed,className:"text-blue-500 hover:text-blue-700 disabled:text-gray-300 disabled:cursor-not-allowed",title:`Step until ${p.name} completes`,children:z.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:z.jsx("path",{fillRule:"evenodd",d:"M4.5 5.653c0-1.426 1.529-2.33 2.779-1.643l11.54 6.348c1.295.712 1.295 2.573 0 3.285L7.28 19.991c-1.25.687-2.779-.217-2.779-1.643V5.653z",clipRule:"evenodd"})})}),z.jsx("span",{className:"font-medium text-gray-900",children:p.name})]})}),z.jsx("td",{className:"px-4 py-2",children:z.jsx(AQi,{status:p.status})}),z.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:p.firstIteration!==null?p.firstIteration:""}),z.jsx("td",{className:"px-4 py-2 text-gray-600",children:p.iterations}),z.jsx("td",{className:"px-4 py-2",children:z.jsx(cQi,{progress:p.progress})}),z.jsx("td",{className:"px-4 py-2 text-gray-600",children:u(p.timeSpent)}),z.jsx("td",{className:"px-4 py-2 text-gray-500",children:z.jsx(gQi,{stats:p.stats})}),z.jsx("td",{className:"px-4 py-2",children:p.solverInstance?z.jsxs("button",{onClick:()=>g(p),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${p.name}`,children:[z.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:z.jsx("path",{fillRule:"evenodd",d:"M12 2.25a.75.75 0 01.75.75v11.69l3.22-3.22a.75.75 0 111.06 1.06l-4.5 4.5a.75.75 0 01-1.06 0l-4.5-4.5a.75.75 0 111.06-1.06l3.22 3.22V3a.75.75 0 01.75-.75zm-9 13.5a.75.75 0 01.75.75v2.25a1.5 1.5 0 001.5 1.5h13.5a1.5 1.5 0 001.5-1.5V16.5a.75.75 0 011.5 0v2.25a3 3 0 01-3 3H5.25a3 3 0 01-3-3V16.5a.75.75 0 01.75-.75z",clipRule:"evenodd"})}),z.jsx("span",{children:"Input"})]}):null})]}),_&&f&&z.jsx("tr",{children:z.jsx("td",{colSpan:8,className:"p-0",children:z.jsx(FAn,{solver:p.solverInstance,onStepUntilPhase:e,onDownloadInput:n,isNested:!0,indentLevel:i+1,triggerRender:r})})})]},p.name)})})]})})]})};function hQi({graphics:t}){const e=t.points??[],n=t.lines??[],o=t.rects??[],i=t.circles??[],r=t.texts??[];let s=Number.POSITIVE_INFINITY,a=Number.POSITIVE_INFINITY,A=Number.NEGATIVE_INFINITY,c=Number.NEGATIVE_INFINITY;const l=(p,_)=>{typeof p=="number"&&(p<s&&(s=p),p>A&&(A=p)),typeof _=="number"&&(_<a&&(a=_),_>c&&(c=_))};for(const p of e)l(p.x,p.y);for(const p of n){const _=p.points??[];for(const f of _)l(f.x,f.y)}for(const p of o){const _=p.x??0,f=p.y??0,I=p.width??0,C=p.height??0;l(_,f),l(_+I,f+C)}for(const p of i){const _=p.x??0,f=p.y??0,I=p.radius??1;l(_-I,f-I),l(_+I,f+I)}for(const p of r)l(p.x,p.y);(!isFinite(s)||!isFinite(a)||!isFinite(A)||!isFinite(c))&&(s=-20,a=-20,A=20,c=20);const g=10,u=s-g,h=a-g,d=Math.max(1,A-s+2*g),m=Math.max(1,c-a+2*g);return z.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${u} ${h} ${d} ${m}`,role:"img","aria-label":"Graphics fallback",children:[o.map((p,_)=>z.jsx("rect",{x:p.x??0,y:p.y??0,width:p.width??0,height:p.height??0,fill:"none",stroke:p.strokeColor??"black",strokeWidth:p.strokeWidth??1},`rect-${_}`)),n.map((p,_)=>z.jsx("polyline",{fill:"none",stroke:p.strokeColor??"black",strokeWidth:p.strokeWidth??1,points:(p.points??[]).map(f=>`${f.x??0},${f.y??0}`).join(" ")},`line-${_}`)),i.map((p,_)=>z.jsx("circle",{cx:p.x??0,cy:p.y??0,r:p.radius??1.5,fill:p.fillColor??"none",stroke:p.strokeColor??"black",strokeWidth:p.strokeWidth??1},`circle-${_}`)),e.map((p,_)=>z.jsx("circle",{cx:p.x??0,cy:p.y??0,r:p.radius??1.5,fill:p.color??"black"},`point-${_}`)),r.map((p,_)=>z.jsx("text",{x:p.x??0,y:p.y??0,fontSize:p.fontSize??10,fill:p.color??"black",children:p.text??""},`text-${_}`))]})}var mQi=class extends ws.Component{constructor(t){super(t),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(t){console.error("InteractiveGraphics render error:",t)}render(){return this.state.hasError?this.props.fallback:this.props.children}},pQi=({solver:t,createSolver:e,animationSpeed:n=25,onSolverStarted:o,onSolverCompleted:i})=>{const[r,s]=te.useReducer(f=>f+1,0),[a]=te.useState(()=>{if(e)return e();if(!t)throw new Error("GenericSolverDebugger requires solver or createSolver");return t}),[A,c]=te.useState(()=>typeof window>"u"?"vector":window.localStorage.getItem("solver-utils-renderer")==="canvas"?"canvas":"vector"),[l,g]=te.useState(n),u=te.useMemo(()=>{try{return a.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(f){return console.error("Visualization error:",f),{points:[],lines:[],rects:[],circles:[]}}},[a,r]),h=te.useMemo(()=>(u.rects?.length||0)===0&&(u.lines?.length||0)===0&&(u.points?.length||0)===0&&(u.circles?.length||0)===0,[u]);te.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const f=document.createElement("script");f.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(f)}},[]),te.useEffect(()=>{g(n)},[n]);const d=a.pipelineDef!==void 0,m=f=>{const I=a;if(!a.solved&&!a.failed){for(;!a.solved&&!a.failed&&I.currentPipelineStageIndex<=I.pipelineDef.findIndex(C=>C.solverName===f);)a.step();s()}},p=()=>{const f=JSON.stringify(u,null,2),I=new Blob([f],{type:"application/json"}),C=URL.createObjectURL(I),y=document.createElement("a");y.download="visualization.json",y.href=C,document.body.appendChild(y),y.click(),document.body.removeChild(y),URL.revokeObjectURL(C)},_=f=>{c(f),typeof window<"u"&&window.localStorage.setItem("solver-utils-renderer",f)};return z.jsxs("div",{children:[z.jsx(iQi,{solver:a,triggerRender:s,animationSpeed:l,renderer:A,onRendererChange:_,onAnimationSpeedChange:g,onDownloadVisualization:p,onSolverStarted:o,onSolverCompleted:i}),h?z.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):z.jsx(mQi,{fallback:z.jsx(hQi,{graphics:u}),children:A==="canvas"?z.jsx(tQi,{graphics:u}):z.jsx($bi,{graphics:u})}),d&&z.jsx(FAn,{solver:a,onStepUntilPhase:m,triggerRender:s})]})};const _Qi=()=>{te.useEffect(()=>{const t="tailwind-cdn-script";if(document.getElementById(t)||window.tailwind)return;const e=document.createElement("div");e.className="hidden",document.body.appendChild(e);const n=window.getComputedStyle(e).display==="none";if(document.body.removeChild(e),n)return;const o=document.createElement("script");o.id=t,o.src="https://cdn.tailwindcss.com",document.head.appendChild(o)},[])},fQi=1e3,sE=(t,e)=>{const{fileName:n,mimeType:o="text/plain"}=e,i=t instanceof Blob?t:new Blob([t],{type:o}),r=URL.createObjectURL(i),s=document.createElement("a");s.href=r,s.download=n,s.target="_blank",s.rel="noopener noreferrer",s.style.display="none",document.body.appendChild(s),s.click(),document.body.removeChild(s),setTimeout(()=>{URL.revokeObjectURL(r)},fQi)},bze=t=>{let e=t.trim().replace(/[\\/:*?"<>|]/g,"_").replace(/[\x00-\x1f]/g,"").replace(/^\.+/,"").replace(/\.+$/,"").replace(/\s+/g," ").replace(/_+/g,"_");return/^(con|prn|aux|nul|com[0-9]|lpt[0-9])$/i.test(e)&&(e=`_${e}`),e=e.slice(0,200),e||"untitled"},IQi=t=>{const e=t.solverConstructorArgs??[t.solverParams];if(t.solverName!=="AutoroutingPipelineSolver7_MultiGraph"||e.length!==1)return e;const[{input:n,options:o}]=e;return[n,o]},h7="https://github.com/tscircuit/tscircuit-autorouter/issues/new",LAn="https://github.com/tscircuit/copper-pour-solver/issues/new",HAn="https://github.com/tscircuit/calculate-packing/issues/new",CQi="https://github.com/tscircuit/matchpack/issues/new",OAn="https://github.com/tscircuit/schematic-trace-solver/issues/new?template=json-bug-report.yml",yQi={PackSolver2:HAn,LayoutPipelineSolver:CQi,AutoroutingPipelineSolver:h7,AssignableAutoroutingPipeline2:h7,AssignableAutoroutingPipeline3:h7,AutoroutingPipeline1_OriginalUnravel:h7,AutoroutingPipelineSolver3_HgPortPointPathing:h7,AutoroutingPipelineSolver4:h7,AutoroutingPipelineSolver5:h7,AutoroutingPipelineSolver7_MultiGraph:h7,AutoroutingPipelineSolver8:h7,CopperPourPipelineSolver:LAn,SchematicTracePipelineSolver:OAn},xQi=t=>t.toLowerCase().includes("pack")?cyi:t.toLowerCase().includes("rout")?jon:tyi,GAn=t=>{const e=yQi[t];if(e)return e;const n=t.toLowerCase();return n.includes("autorout")?h7:n.includes("schematic")&&n.includes("trace")?OAn:n.includes("copperpour")?LAn:n.includes("pack")?HAn:null},EQi=t=>`${bze(`${t.componentName}-${t.solverName}`)}-solver-input.json`,YAn=t=>{sE(JSON.stringify(t.solverParams,null,2),{fileName:EQi(t),mimeType:"application/json"})},BQi=({solverEvent:t})=>{const e=GAn(t.solverName);return z.jsxs("div",{className:"rf-flex rf-items-center rf-justify-end rf-gap-2 rf-border-b rf-border-gray-200 rf-bg-gray-50 rf-px-4 rf-py-2",children:[z.jsxs(Kc,{type:"button",variant:"outline",size:"sm",onClick:()=>YAn(t),children:[z.jsx(Iq,{className:"rf-w-4 rf-h-4"}),"Download"]}),e?z.jsx(Kc,{asChild:!0,variant:"outline",size:"sm",children:z.jsxs("a",{href:e,target:"_blank",rel:"noopener noreferrer",children:[z.jsx(Mde,{className:"rf-w-4 rf-h-4"}),"Report"]})}):z.jsxs(Kc,{type:"button",variant:"outline",size:"sm",disabled:!0,title:"No report link configured for this solver",children:[z.jsx(Mde,{className:"rf-w-4 rf-h-4"}),"Report"]})]})},SQi=({solverEvent:t})=>{const e=GAn(t.solverName);return e?z.jsx(Kc,{asChild:!0,variant:"ghost",size:"icon",className:"rf-h-8 rf-w-8",children:z.jsx("a",{href:e,target:"_blank",rel:"noopener noreferrer",title:"Report solver bug","aria-label":"Report solver bug",children:z.jsx(Mde,{className:"rf-w-4 rf-h-4"})})}):z.jsx(Kc,{type:"button",variant:"ghost",size:"icon",className:"rf-h-8 rf-w-8",disabled:!0,title:"No report link configured for this solver","aria-label":"Report solver bug",children:z.jsx(Mde,{className:"rf-w-4 rf-h-4"})})},bQi=({solverEvents:t=[]})=>{const[e,n]=te.useState(null);_Qi();const o=te.useMemo(()=>{const a=new Map;for(const A of t){const c=`${A.componentName}-${A.solverName}`;a.set(c,A)}return a},[t]),i=te.useMemo(()=>Array.from(o.keys()),[o]),r=e?o.get(e):null,s=te.useMemo(()=>{if(!r)return{instance:null,error:null,classFound:!1};const a=SDe[r.solverName];if(!a)return{instance:null,error:`Solver class "${r.solverName}" not found in SOLVERS registry. Available: ${Object.keys(SDe).join(", ")}`,classFound:!1};try{return{instance:new a(...IQi(r)),error:null,classFound:!0}}catch(A){const c=A instanceof Error?A.message:String(A);return console.error("Failed to reconstruct solver:",A),{instance:null,error:`Failed to instantiate solver: ${c}`,classFound:!0}}},[r]);return t.length===0?z.jsx("div",{className:"rf-p-4",children:z.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:z.jsxs("div",{className:"rf-p-4",children:[z.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),z.jsx("p",{className:"rf-text-sm rf-text-gray-600",children:"Solvers will appear here when the circuit runs. Solvers are used for tasks like component packing and autorouting."})]})})}):z.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[z.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[z.jsxs("div",{className:"rf-text-xs rf-font-semibold rf-text-gray-500 rf-px-3 rf-py-2 rf-bg-gray-50 rf-border-b rf-border-gray-200",children:[i.length," ",i.length===1?"Solver":"Solvers"]}),i.map(a=>{const A=o.get(a),c=e===a;return z.jsx("div",{className:`rf-px-3 rf-py-2 rf-cursor-pointer rf-border-b rf-border-gray-100 ${c?"rf-bg-blue-50 rf-border-l-2 rf-border-l-blue-500":"hover:rf-bg-gray-50"}`,onClick:()=>n(a),children:(()=>{const l=xQi(A.solverName);return z.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[z.jsx(l,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),z.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[z.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:A.componentName}),z.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:A.solverName})]})]})})()},a)})]}),z.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:r?s.instance?z.jsxs("div",{className:"rf-flex rf-h-full rf-flex-col rf-overflow-y-auto",children:[z.jsx(BQi,{solverEvent:r}),z.jsx("div",{className:"rf-min-h-0 rf-flex-1",children:z.jsx(EB,{fallback:z.jsx("div",{className:"rf-p-4",children:z.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[z.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),z.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",r.solverName]})]})}),children:z.jsx(pQi,{solver:s.instance})})})]}):z.jsxs("div",{className:"rf-p-4",children:[z.jsxs("div",{className:"rf-mb-4",children:[z.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:r.solverName}),z.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",r.componentName]})]}),s.error&&z.jsx("div",{className:`rf-rounded-md rf-border rf-p-4 rf-mb-4 ${s.classFound?"rf-bg-red-50 rf-border-red-200":"rf-bg-yellow-50 rf-border-yellow-200"}`,children:z.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),z.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[z.jsxs("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50 rf-flex rf-items-center rf-justify-between rf-gap-2",children:[z.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"}),z.jsxs("div",{className:"rf-flex rf-items-center rf-gap-1",children:[z.jsx(SQi,{solverEvent:r}),z.jsx(Kc,{type:"button",variant:"ghost",size:"icon",className:"rf-h-8 rf-w-8","aria-label":"Download solver input JSON",title:"Download solver input JSON",onClick:()=>YAn(r),children:z.jsx(Iq,{className:"rf-w-4 rf-h-4"})})]})]}),z.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:z.jsx("pre",{className:"rf-text-xs rf-font-mono rf-text-gray-600 rf-whitespace-pre-wrap rf-overflow-x-auto",children:JSON.stringify(r.solverParams,null,2)})})]})]}):z.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:z.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},QQi=new Map([["custom","Custom"],["fanout","Fanout"],["single_layer_fanout","Single layer fanout"],["tscircuit_simplify","Simplify"]]),vQi=new Set(["tscircuit","default","auto","auto_local"]);function PQi(t){if(t==="FanoutSolver")return"Fanout";if(t==="AutoroutingPipelineSolver11_Simplification")return"Simplify";const e=t.match(/^AutoroutingPipeline(?:Solver)?(\d+)(?:_|$)/);if(e)return`Pipeline${e[1]}`;const n=t.match(/^AssignableAutoroutingPipeline(\d+)$/);return n?`Assignable${n[1]}`:t}function wQi(t){const e=t.autorouterName?.trim(),n=e?.replace(/-/g,"_"),o=n&&QQi.get(n);if(o)return o;if(n&&!vQi.has(n))return e;const i=t.solverName?.trim();if(i)return PQi(i);const r=t.autorouterVersion?.trim();if(r){const s=r.match(/^beta[_-]pipeline(\d+)$/);return s?`Pipeline${s[1]}`:r==="latest"?"default":r}return e?"default":"Unknown"}const Qze="#fbbf24";function MQi(t){const e=t.endSimpleRouteJson?.traces??[],n=new Set(e.flatMap(i=>[i.pcb_trace_id,i.__replaces_pcb_trace_id].filter(r=>r!==void 0)));return[...(t.startSimpleRouteJson?.traces??[]).filter(i=>!n.has(i.pcb_trace_id)),...e]}function UAn(t){const e=new Map((t.startSimpleRouteJson?.traces??[]).map(n=>[n.pcb_trace_id,n]));return(t.endSimpleRouteJson?.traces??[]).filter(n=>{const o=e.get(n.pcb_trace_id);return!o||!!n.__replaces_pcb_trace_id&&n.__replaces_pcb_trace_id!==o.__replaces_pcb_trace_id||JSON.stringify(o.route)!==JSON.stringify(n.route)}).map(n=>n.pcb_trace_id)}function DQi(t,e){return{outer_diameter:t.via_diameter??e.minViaPadDiameter??e.min_via_pad_diameter??e.minViaDiameter??.6,hole_diameter:t.via_hole_diameter??e.minViaHoleDiameter??e.min_via_hole_diameter??.3}}function KAn(t,e){const n=[];for(const a of t.route)a.route_type==="wire"?n.push({...a,layer:a.layer}):a.route_type==="via"?n.push({route_type:"via",x:a.x,y:a.y,from_layer:a.from_layer,to_layer:a.to_layer,...DQi(a,e)}):a.route_type==="through_obstacle"&&n.push({route_type:"through_pad",start:{...a.start},end:{...a.end},width:a.width,start_layer:a.from_layer,end_layer:a.to_layer,pcb_smtpad_id:a.circuitJsonMetadata?.pcb_smtpad_id,pcb_plated_hole_id:a.circuitJsonMetadata?.pcb_plated_hole_id});const o=a=>{let A=-1,c=Number.POSITIVE_INFINITY;return n.forEach((l,g)=>{if(l.route_type!=="wire")return;const u=Math.hypot(l.x-a.x,l.y-a.y);u<c&&(c=u,A=g)}),A},i=t.route.filter(a=>a.route_type==="jumper").map(a=>[o(a.start),o(a.end)].sort((A,c)=>A-c)).filter(([a,A])=>a>=0&&A>a).sort(([a],[A])=>a-A),r=[];let s=0;for(const[a,A]of i)a>=s&&r.push(n.slice(s,a+1)),s=Math.max(s,A);return s<n.length&&r.push(n.slice(s)),r}function NQi(t){const e=[],n=[],o=t.endSimpleRouteJson;if(!o)return{lines:e,circles:n};const i=new Set(UAn(t));for(const r of o.traces??[])if(i.has(r.pcb_trace_id))for(const s of KAn(r,o)){let a;for(const A of s){if(A.route_type==="through_pad"){a={...A.end,layer:A.end_layer,width:A.width};continue}const c=A.route_type==="wire"?A.layer:A.from_layer;a&&a.layer===c&&(a.x!==A.x||a.y!==A.y)&&e.push({points:[{x:a.x,y:a.y},{x:A.x,y:A.y}],strokeWidth:A.route_type==="wire"?A.width:a.width,strokeColor:Qze,layer:c}),A.route_type==="via"&&n.push({center:{x:A.x,y:A.y},radius:A.outer_diameter/2,stroke:Qze,fill:"transparent"}),a={x:A.x,y:A.y,layer:A.route_type==="wire"?A.layer:A.to_layer,width:A.route_type==="wire"?A.width:a?.width??o.minTraceWidth}}}return{coordinateSystem:"cartesian",lines:e,circles:n}}function RQi(t){const e=JSON.stringify(t);let n=2166136261;for(let o=0;o<e.length;o++)n=Math.imul(n^e.charCodeAt(o),16777619);return(n>>>0).toString(36)}const TQi=new Set(["pcb_trace","pcb_via","pcb_copper_pour","pcb_ground_plane","pcb_ground_plane_region","pcb_thermal_spoke","pcb_breakout_point"]);function kQi(t,e,n){const o=n==="input"?e.startSimpleRouteJson??e.errorSimpleRouteJson:e.endSimpleRouteJson,i=t.filter(c=>!TQi.has(c.type)&&!c.type.endsWith("_error")&&!c.type.endsWith("_warning"));if(!o)return i;const r=n==="input"?o.traces??[]:MQi(e),s=new Set(t.filter(c=>c.type==="source_trace").map(c=>c.source_trace_id)),a=["top",...Array.from({length:Math.max(0,o.layerCount-2)},(c,l)=>`inner${l+1}`),...o.layerCount>1?["bottom"]:[]],A=[];for(const c of r){const g=o.connections.find(h=>h.name===c.connection_name||h.source_trace_id===c.connection_name)?.source_trace_id??c.connection_name??"",u=KAn(c,o);for(const[h,d]of u.entries()){const m={type:"pcb_trace",pcb_trace_id:`${e.id}_${n}_${c.pcb_trace_id}_${h}_${RQi(d)}`,subcircuit_id:e.subcircuit_id??void 0,source_trace_id:s.has(g)?g:void 0,route:d};A.push(m);for(const[p,_]of d.entries()){if(_.route_type!=="via")continue;const f=a.indexOf(_.from_layer),I=a.indexOf(_.to_layer),C={type:"pcb_via",pcb_via_id:`${m.pcb_trace_id}_via_${p}`,pcb_trace_id:m.pcb_trace_id,subcircuit_id:e.subcircuit_id??void 0,x:_.x,y:_.y,outer_diameter:_.outer_diameter,hole_diameter:_.hole_diameter,layers:f>=0&&I>=0?a.slice(Math.min(f,I),Math.max(f,I)+1):[_.from_layer,_.to_layer]};A.push(C)}}}return[...i,...A]}const vze=(t,e)=>t.phaseName||`Phase ${t.phaseOrdinal??e+1}`,VAn=t=>t.componentDisplayName?.match(/name="([^"]+)"/)?.[1]?.replace(/^\./,"")||t.componentDisplayName||t.subcircuit_id||"Board",zAn=t=>t.startSimpleRouteJson??t.endSimpleRouteJson??t.errorSimpleRouteJson,FQi={is_showing_autorouting:!0,is_showing_rats_nest:!1,is_showing_drc_errors:!1,is_showing_drc_warnings:!1,is_showing_pcb_groups:!1},LQi=({circuitJson:t,phases:e=[],isRunning:n=!1})=>{const[o,i]=te.useState(null),[r,s]=te.useState("output"),[a,A]=te.useState(!0),[c,l]=te.useState(!1),g=te.useRef(null),[u,h]=te.useState(480),d=o?e.findIndex(T=>T.id===o.id&&zAn(T)===zAn(o)):-1,m=d<0?e.length-1:d,p=e[m],_=d<0,f=!!p?.endSimpleRouteJson,I=p?.startSimpleRouteJson??p?.errorSimpleRouteJson,C=!!I,y=r==="output"&&!f?"input":r==="input"&&!C?"output":r,x=y==="input"?I:p?.endSimpleRouteJson,E=te.useMemo(()=>!p||!x?null:kQi(t??[],p,y),[t,p,x,y]),B=te.useMemo(()=>p&&y==="output"&&a?NQi(p):{lines:[],circles:[]},[p,y,a]);if(te.useLayoutEffect(()=>{const T=g.current;if(!T)return;const H=()=>h(Math.max(360,T.clientHeight));H();const G=new ResizeObserver(H);return G.observe(T),()=>G.disconnect()},[!!p]),!p)return z.jsxs("div",{className:"rf-flex rf-min-h-[400px] rf-flex-col rf-items-center rf-justify-center rf-gap-3 rf-p-8 rf-text-center",children:[z.jsx(jon,{className:"rf-h-7 rf-w-7 rf-text-blue-500"}),z.jsx("h3",{className:"rf-text-base rf-font-medium",children:n?"Waiting for autorouting":"No autorouting captures"}),z.jsx("p",{className:"rf-max-w-md rf-text-sm rf-text-gray-500",children:n?"Phases appear as the circuit routes. Each capture includes its input and output on the PCB.":"Run a circuit with autorouting enabled to inspect its phases. A circuit JSON file alone does not include routing history."})]});const b=vze(p,m),Q=p.status==="running"&&n,w=!f,D=I?.connections.length,k=E?.filter(T=>T.type==="pcb_trace").length??0;return z.jsxs("div",{className:"rf-flex rf-h-full rf-min-h-[620px] rf-flex-col rf-bg-white md:rf-flex-row","data-testid":"autorouting-explorer",children:[z.jsxs("aside",{className:"rf-flex rf-shrink-0 rf-flex-col rf-border-b rf-border-gray-200 md:rf-w-52 md:rf-border-b-0 md:rf-border-r","aria-label":"Routing phases",children:[z.jsxs("div",{className:"rf-flex rf-items-center rf-justify-between rf-px-3 rf-py-2 rf-text-xs rf-text-gray-500",children:[z.jsx("span",{children:"Routing phases"}),z.jsx("span",{children:e.length})]}),z.jsx("div",{className:"rf-flex rf-gap-1 rf-overflow-x-auto rf-px-1.5 rf-pb-1.5 md:rf-flex-col md:rf-overflow-x-hidden md:rf-overflow-y-auto",children:e.map((T,H)=>{const G=UAn(T).length,U=T.endSimpleRouteJson?`${G} ${G===1?"trace":"traces"} routed`:T.status==="error"?"Failed":T.status==="running"&&n?"Routing…":"No output";return z.jsxs("button",{type:"button","aria-pressed":H===m,title:`${VAn(T)} · ${U}`,onClick:()=>i(T),className:Ur("rf-flex rf-min-w-[192px] rf-items-start rf-gap-2 rf-rounded-md rf-border rf-px-2 rf-py-2 rf-text-left md:rf-min-w-0",H===m?"rf-border-blue-200 rf-bg-blue-50":"rf-border-transparent hover:rf-bg-gray-50"),children:[z.jsx("span",{className:Ur("rf-flex rf-h-5 rf-w-5 rf-shrink-0 rf-items-center rf-justify-center rf-rounded-full rf-text-[11px]",H===m?"rf-bg-blue-600 rf-text-white":"rf-bg-gray-100 rf-text-gray-500"),children:H+1}),z.jsxs("span",{className:"rf-min-w-0 rf-flex-1",children:[z.jsxs("span",{className:"rf-flex rf-items-center rf-gap-1",children:[z.jsx("span",{className:"rf-min-w-0 rf-flex-1 rf-truncate rf-text-xs rf-font-medium rf-leading-5 rf-text-gray-800",title:vze(T,H),children:vze(T,H)}),T.status==="complete"?z.jsx(fq,{"aria-label":"Captured",className:"rf-h-3 rf-w-3 rf-shrink-0 rf-text-green-600"}):T.status==="error"?z.jsx(mKe,{"aria-label":"Failed",className:"rf-h-3 rf-w-3 rf-shrink-0 rf-text-red-500"}):n?z.jsx(Y5,{"aria-label":"Routing",className:"rf-h-3 rf-w-3 rf-shrink-0 rf-animate-spin rf-text-blue-500"}):null]}),z.jsxs("span",{className:"rf-block rf-text-[11px] rf-leading-4 rf-text-gray-500",children:[wQi(T)," · ",U]})]})]},T.id)})})]}),z.jsxs("div",{className:"rf-flex rf-min-w-0 rf-flex-1 rf-flex-col",children:[z.jsxs("div",{className:"rf-flex rf-flex-wrap rf-items-center rf-gap-3 rf-border-b rf-border-gray-200 rf-px-4 rf-py-3",children:[z.jsxs("h3",{className:"rf-mr-auto rf-flex rf-items-center rf-gap-2 rf-text-sm rf-font-medium",children:[b,z.jsxs("span",{className:"rf-text-xs rf-font-normal rf-text-gray-500",children:[m+1," of ",e.length]})]}),n&&z.jsx("button",{type:"button",onClick:()=>i(null),disabled:_,className:"rf-text-xs rf-text-blue-600 disabled:rf-text-gray-500",children:_?"Following latest":"Follow latest"}),z.jsx("div",{className:"rf-flex rf-rounded-md rf-bg-gray-100 rf-p-1","aria-label":"Phase snapshot",children:["input","output"].map(T=>z.jsx("button",{type:"button","aria-pressed":y===T,disabled:T==="input"?!C:!f,onClick:()=>s(T),className:Ur("rf-rounded rf-px-3 rf-py-1 rf-text-xs disabled:rf-opacity-40",y===T?"rf-bg-white rf-text-gray-900 rf-shadow-sm":"rf-text-gray-500"),children:T==="input"?"Input":"Output"},T))})]}),z.jsxs("div",{className:"rf-flex rf-flex-wrap rf-items-center rf-justify-between rf-gap-2 rf-px-4 rf-py-2 rf-text-xs rf-text-gray-600",children:[z.jsxs("label",{className:"rf-flex rf-items-center rf-gap-2",children:[z.jsx("input",{type:"checkbox",checked:a,disabled:y!=="output",onChange:T=>A(T.target.checked),className:"rf-accent-blue-600"}),z.jsx("span",{"aria-hidden":"true",className:"rf-inline-block rf-h-0.5 rf-w-3",style:{backgroundColor:Qze}}),"Highlight changes (all layers)"]}),z.jsxs("span",{children:[y==="input"?"Before this phase":"After this phase"," ","· ",k," traces"]})]}),w&&z.jsx("div",{className:Ur("rf-border-y rf-px-4 rf-py-2 rf-text-xs",p.status==="error"?"rf-border-red-100 rf-bg-red-50 rf-text-red-700":"rf-border-blue-100 rf-bg-blue-50 rf-text-blue-700"),role:"status",children:p.status==="error"?`Routing failed: ${p.error?.message||"No output was captured."}`:Q?"Routing in progress. Showing captured input until output is available.":"No output was captured for this phase. Showing the available input."}),z.jsx("div",{ref:g,className:"rf-relative rf-min-h-[360px] rf-flex-1","data-testid":"autorouting-pcb",children:E?z.jsx(fze,{circuitJson:E,height:u,allowEditing:!1,clickToInteractEnabled:!1,initialState:FQi,debugGraphics:B}):z.jsx("div",{className:"rf-p-6 rf-text-sm rf-text-gray-500",children:"No PCB snapshot available for this capture."})}),z.jsxs("div",{className:"rf-flex rf-flex-wrap rf-items-center rf-justify-between rf-gap-2 rf-border-t rf-border-gray-200 rf-px-4 rf-py-3 rf-text-xs rf-text-gray-500",children:[z.jsxs("span",{children:[D===void 0?"Input unavailable":`${D} input connections`,` · ${VAn(p)}`]}),z.jsxs("div",{className:"rf-flex rf-items-center rf-gap-4",children:[z.jsxs("button",{type:"button",disabled:!x,onClick:()=>sE(JSON.stringify(x,null,2),{fileName:`${p.id}-${y}.srj.json`,mimeType:"application/json"}),className:"rf-flex rf-items-center rf-gap-1 disabled:rf-opacity-40",children:[z.jsx(Iq,{className:"rf-h-3 rf-w-3"}),"Download SRJ"]}),z.jsxs("button",{type:"button","aria-expanded":c,onClick:()=>l(!c),className:"rf-flex rf-items-center rf-gap-1",children:[z.jsx(VG,{className:Ur("rf-h-3 rf-w-3",c&&"rf-rotate-90")}),"Inspect SRJ"]})]})]}),c&&z.jsx("pre",{className:"rf-m-0 rf-max-h-64 rf-overflow-auto rf-border-t rf-border-gray-200 rf-bg-gray-50 rf-p-4 rf-text-xs","aria-label":`${b} ${y} SRJ`,children:x?JSON.stringify(x,null,2):"No snapshot captured."})]})]})},JAn=({errorMessage:t,errorStack:e,circuitJsonErrors:n})=>{te.useEffect(()=>{if(t){const o=new Error(t);e&&(o.stack=e);try{UT.captureException(o)}catch{}}},[t,e]),te.useEffect(()=>{if(n&&n.length>0)for(const o of n){const i=new Error(o.message||"Circuit JSON Error");o.stack&&(i.stack=o.stack);try{UT.captureException(i,{error_type:o.type})}catch{}}},[n])},HQi=t=>{te.useEffect(()=>{try{Hxn(t)}catch{}},[t.source,t.component,t.isWebEmbedded,t.activeTab])},WAn="0.0.2780",OQi={version:WAn},Pze={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1},wze=new Map,ome=t=>{const e=wze.get(t);return e?Object.fromEntries(Object.entries(e.stores).map(([n,o])=>[n,o.getState()])):{}},GQi=(t,e,n)=>{if(t===void 0)return{type:"untracked",connection:e.connect(n)};const o=wze.get(n.name);if(o)return{type:"tracked",store:t,...o};const i={connection:e.connect(n),stores:{}};return wze.set(n.name,i),{type:"tracked",store:t,...i}},jAn=(t,e={})=>(n,o,i)=>{const{enabled:r,anonymousActionType:s,store:a,...A}=e;let c;try{c=(r??(Pze?"production":void 0)!=="production")&&window.__REDUX_DEVTOOLS_EXTENSION__}catch{}if(!c)return(Pze?"production":void 0)!=="production"&&r&&console.warn("[zustand devtools middleware] Please install/enable Redux devtools extension"),t(n,o,i);const{connection:l,...g}=GQi(a,c,A);let u=!0;i.setState=(m,p,_)=>{const f=n(m,p);if(!u)return f;const I=_===void 0?{type:s||"anonymous"}:typeof _=="string"?{type:_}:_;return a===void 0?(l?.send(I,o()),f):(l?.send({...I,type:`${a}/${I.type}`},{...ome(A.name),[a]:i.getState()}),f)};const h=(...m)=>{const p=u;u=!1,n(...m),u=p},d=t(i.setState,o,i);if(g.type==="untracked"?l?.init(d):(g.stores[g.store]=i,l?.init(Object.fromEntries(Object.entries(g.stores).map(([m,p])=>[m,m===g.store?d:p.getState()])))),i.dispatchFromDevtools&&typeof i.dispatch=="function"){let m=!1;const p=i.dispatch;i.dispatch=(..._)=>{(Pze?"production":void 0)!=="production"&&_[0].type==="__setState"&&!m&&(console.warn('[zustand devtools middleware] "__setState" action type is reserved to set state from the devtools. Avoid using it.'),m=!0),p(..._)}}return l.subscribe(m=>{var p;switch(m.type){case"ACTION":if(typeof m.payload!="string"){console.error("[zustand devtools middleware] Unsupported action format");return}return Mze(m.payload,_=>{if(_.type==="__setState"){if(a===void 0){h(_.state);return}Object.keys(_.state).length!==1&&console.error(`
5584
5584
  [zustand devtools middleware] Unsupported __setState action format.
5585
5585
  When using 'store' option in devtools(), the 'state' should have only one key, which is a value of 'store' that was passed in devtools(),
5586
5586
  and value of this only key should be a state object. Example: { "type": "__setState", "state": { "abc123Store": { "foo": "bar" } } }