@tscircuit/runframe 0.0.2023 → 0.0.2024
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.
|
@@ -5194,7 +5194,7 @@ ${c.join(`
|
|
|
5194
5194
|
${m}polygon: ${d.polygon.vertices}
|
|
5195
5195
|
`:c+=`
|
|
5196
5196
|
`,d.children.length>0&&A.push(d.children)}return c}};e.exports=s}}),JQn=rt({"node_modules/@jscad/modeling/src/operations/booleans/trees/Tree.js"(t,e){var n=KQn(),o=XQn(),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}}),e5e=rt({"node_modules/@jscad/modeling/src/operations/booleans/trees/index.js"(t,e){e.exports={Tree:JQn()}}}),qQn=rt({"node_modules/@jscad/modeling/src/operations/booleans/intersectGeom3Sub.js"(t,e){var n=Es(),o=ZCe(),{Tree:i}=e5e(),r=(s,a)=>{if(!o(s,a))return n.create();const c=new i(n.toPolygons(s)),l=new i(n.toPolygons(a));c.invert(),l.clipTo(c),l.invert(),c.clipTo(l),l.clipTo(c),c.addPolygons(l.allPolygons()),c.invert();const A=c.allPolygons();return n.create(A)};e.exports=r}}),h_t=rt({"node_modules/@jscad/modeling/src/operations/booleans/intersectGeom3.js"(t,e){var n=ts(),o=kk(),i=qQn(),r=(...s)=>{s=n(s);let a=s.shift();return s.forEach(c=>{a=i(a,c)}),a=o(a),a};e.exports=r}}),$Qn=rt({"node_modules/@jscad/modeling/src/operations/booleans/intersectGeom2.js"(t,e){var n=ts(),o=Es(),i=k4(),r=qCe(),s=$Ce(),a=h_t(),c=(...l)=>{l=n(l);const A=l.map(h=>s({z0:-1,z1:1},h)),u=a(A),_=i(u);return r(_,o.toPolygons(u))};e.exports=c}}),ZQn=rt({"node_modules/@jscad/modeling/src/operations/booleans/intersect.js"(t,e){var n=ts(),o=Nk(),i=Bs(),r=Es(),s=$Qn(),a=h_t(),c=(...l)=>{if(l=n(l),l.length===0)throw new Error("wrong number of arguments");if(!o(l))throw new Error("only intersect of the types are supported");const A=l[0];return i.isA(A)?s(l):r.isA(A)?a(l):A};e.exports=c}}),t5e=rt({"node_modules/@jscad/modeling/src/operations/hulls/hullPoints3.js"(t,e){var n=Ia(),o=yut(),i=r=>o(r,{skipTriangulation:!0}).map(c=>{const l=c.map(A=>r[A]);return n.create(l)});e.exports=i}}),m_t=rt({"node_modules/@jscad/modeling/src/operations/booleans/unionGeom3Sub.js"(t,e){var n=Es(),o=ZCe(),{Tree:i}=e5e(),r=(a,c)=>{if(!o(a,c))return s(a,c);const l=new i(n.toPolygons(a)),A=new i(n.toPolygons(c));l.clipTo(A,!1),A.clipTo(l),A.invert(),A.clipTo(l),A.invert();const u=l.allPolygons().concat(A.allPolygons());return n.create(u)},s=(a,c)=>{let l=n.toPolygons(a);return l=l.concat(n.toPolygons(c)),n.create(l)};e.exports=r}}),n5e=rt({"node_modules/@jscad/modeling/src/operations/booleans/unionGeom3.js"(t,e){var n=ts(),o=kk(),i=m_t(),r=(...s)=>{s=n(s);let a;for(a=1;a<s.length;a+=2)s.push(i(s[a-1],s[a]));let c=s[a-1];return c=o(c),c};e.exports=r}}),g_t=rt({"node_modules/@jscad/modeling/src/operations/minkowski/minkowskiSum.js"(t,e){var n=ts(),o=Es(),i=Ia(),r=t5e(),s=n5e(),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),g=o.isConvex(m);if(p&&g)return u(d,m);if(!p&&g)return c(d,m);if(p&&!g)return c(m,d);throw new Error("minkowskiSum of two non-convex geometries is not yet supported")},c=(h,d)=>{const m=l(h);if(m.length===0)return o.create();const p=m.map(g=>u(g,d));return p.length===1?p[0]:s(p)},l=h=>{const d=o.toPolygons(h);if(d.length===0)return[];const m=[];for(let p=0;p<d.length;p++){const g=d[p],y=g.vertices;let f=0,x=0,I=0;for(let N=0;N<y.length;N++)f+=y[N][0],x+=y[N][1],I+=y[N][2];f/=y.length,x/=y.length,I/=y.length;const E=i.plane(g),b=E[0],P=E[1],B=E[2],w=.1,k=[f-b*w,x-P*w,I-B*w];for(let N=1;N<y.length-1;N++){const F=y[0],O=y[N],G=y[N+1],K=A(k,F,O,G);m.push(o.create(K))}}return m},A=(h,d,m,p)=>[i.create([h,m,d]),i.create([h,d,p]),i.create([d,m,p]),i.create([m,h,p])],u=(h,d)=>{const m=_(h),p=_(d);if(m.length===0||p.length===0)return o.create();const g=[];for(let f=0;f<m.length;f++){const x=m[f];for(let I=0;I<p.length;I++){const E=p[I];g.push([x[0]+E[0],x[1]+E[1],x[2]+E[2]])}}const y=r(g);return o.create(y)},_=h=>{const d=new Set,m=[],p=o.toPolygons(h);for(let g=0;g<p.length;g++){const y=p[g].vertices;for(let f=0;f<y.length;f++){const x=y[f],I=`${x[0]},${x[1]},${x[2]}`;d.has(I)||(d.add(I),m.push(x))}}return m};e.exports=a}}),eRn=rt({"node_modules/@jscad/modeling/src/operations/booleans/scissionGeom3.js"(t,e){var n=Xi(),o=k4(),i=Es(),r=l=>l.sort((A,u)=>A-u).filter((A,u,_)=>!u||A!==_[u-1]),s=(l,A,u)=>{const _=`${A}`,h=l.get(_);h===void 0?l.set(_,[u]):h.push(u)},a=(l,A)=>{const u=`${A}`;return l.get(u)},c=l=>{const A=o(l),u=i.toPolygons(l),_=u.length,h=new Map,d=n.create();u.forEach((f,x)=>{f.vertices.forEach(I=>{s(h,n.snap(d,I,A),x)})});const m=u.map(f=>{let x=[];return f.vertices.forEach(I=>{x=x.concat(a(h,n.snap(d,I,A)))}),{e:1,d:r(x)}});h.clear();let p=0;const g=m.length;for(let f=0;f<g;f++){const x=m[f];if(x.e>0){const I=new Array(_);I[f]=!0;do p=0,I.forEach((E,b)=>{const P=m[b];if(P.e>0){P.e=-1;for(let B=0;B<P.d.length;B++)I[P.d[B]]=!0;p++}});while(p>0);x.indexes=I}}const y=[];for(let f=0;f<g;f++)if(m[f].indexes){const x=[];m[f].indexes.forEach((I,E)=>x.push(u[E])),y.push(i.create(x))}return y};e.exports=c}}),tRn=rt({"node_modules/@jscad/modeling/src/operations/booleans/scission.js"(t,e){var n=ts(),o=Es(),i=eRn(),r=(...s)=>{if(s=n(s),s.length===0)throw new Error("wrong number of arguments");const a=s.map(c=>o.isA(c)?i(c):c);return a.length===1?a[0]:a};e.exports=r}}),nRn=rt({"node_modules/@jscad/modeling/src/operations/booleans/subtractGeom3Sub.js"(t,e){var n=Es(),o=ZCe(),{Tree:i}=e5e(),r=(s,a)=>{if(!o(s,a))return n.clone(s);const c=new i(n.toPolygons(s)),l=new i(n.toPolygons(a));c.invert(),c.clipTo(l),l.clipTo(c,!0),c.addPolygons(l.allPolygons()),c.invert();const A=c.allPolygons();return n.create(A)};e.exports=r}}),p_t=rt({"node_modules/@jscad/modeling/src/operations/booleans/subtractGeom3.js"(t,e){var n=ts(),o=kk(),i=nRn(),r=(...s)=>{s=n(s);let a=s.shift();return s.forEach(c=>{a=i(a,c)}),a=o(a),a};e.exports=r}}),oRn=rt({"node_modules/@jscad/modeling/src/operations/booleans/subtractGeom2.js"(t,e){var n=ts(),o=Es(),i=k4(),r=qCe(),s=$Ce(),a=p_t(),c=(...l)=>{l=n(l);const A=l.map(h=>s({z0:-1,z1:1},h)),u=a(A),_=i(u);return r(_,o.toPolygons(u))};e.exports=c}}),iRn=rt({"node_modules/@jscad/modeling/src/operations/booleans/subtract.js"(t,e){var n=ts(),o=Nk(),i=Bs(),r=Es(),s=oRn(),a=p_t(),c=(...l)=>{if(l=n(l),l.length===0)throw new Error("wrong number of arguments");if(!o(l))throw new Error("only subtract of the types are supported");const A=l[0];return i.isA(A)?s(l):r.isA(A)?a(l):A};e.exports=c}}),f_t=rt({"node_modules/@jscad/modeling/src/operations/booleans/unionGeom2.js"(t,e){var n=ts(),o=Es(),i=k4(),r=qCe(),s=$Ce(),a=n5e(),c=(...l)=>{l=n(l);const A=l.map(h=>s({z0:-1,z1:1},h)),u=a(A),_=i(u);return r(_,o.toPolygons(u))};e.exports=c}}),o5e=rt({"node_modules/@jscad/modeling/src/operations/booleans/union.js"(t,e){var n=ts(),o=Nk(),i=Bs(),r=Es(),s=f_t(),a=n5e(),c=(...l)=>{if(l=n(l),l.length===0)throw new Error("wrong number of arguments");if(!o(l))throw new Error("only unions of the same type are supported");const A=l[0];return i.isA(A)?s(l):r.isA(A)?a(l):A};e.exports=c}}),Hk=rt({"node_modules/@jscad/modeling/src/operations/booleans/index.js"(t,e){e.exports={intersect:ZQn(),minkowski:g_t(),scission:tRn(),subtract:iRn(),union:o5e()}}}),DX=rt({"node_modules/@jscad/modeling/src/operations/expansions/offsetFromPoints.js"(t,e){var{EPS:n,TAU:o}=La(),i=Wut(),r=KCe(),s=js(),a=BX(),c=(l,A)=>{const u={delta:1,corners:"edge",closed:!1,segments:16};let{delta:_,corners:h,closed:d,segments:m}=Object.assign({},u,l);if(Math.abs(_)<n)return A;let p=l.closed?a(A):1;p===0&&(p=1);const g=p>0&&_>=0||p<0&&_<0;_=Math.abs(_);let y=null,f=[];const x=[],I=s.create(),E=A.length;for(let b=0;b<E;b++){const P=(b+1)%E,B=A[b],w=A[P];g?s.subtract(I,B,w):s.subtract(I,w,B),s.normal(I,I),s.normalize(I,I),s.scale(I,I,_);const k=s.add(s.create(),B,I),N=s.add(s.create(),w,I),F=[k,N];if(y!=null&&(d||!d&&P!==0)){const O=i(y[0],y[1],F[0],F[1]);O?(f.pop(),F[0]=O):x.push({c:B,s0:y,s1:F})}y=[k,N],!(P===0&&!d)&&(f.push(F[0]),f.push(F[1]))}if(d&&y!=null){const b=f[0],P=f[1],B=i(y[0],y[1],b,P);if(B)f[0]=B,f.pop();else{const w=A[0],k=[b,P];x.push({c:w,s0:y,s1:k})}}if(h==="edge"){const b=new Map;f.forEach((w,k)=>b.set(w,k));const P=r.create(),B=r.create();x.forEach(w=>{r.fromPoints(P,w.s0[0],w.s0[1]),r.fromPoints(B,w.s1[0],w.s1[1]);const k=r.intersectPointOfLines(P,B);if(Number.isFinite(k[0])&&Number.isFinite(k[1])){const N=w.s0[1],F=b.get(N);f[F]=k,f[(F+1)%f.length]=void 0}else{const N=w.s1[0],F=b.get(N);f[F]=void 0}}),f=f.filter(w=>w!==void 0)}if(h==="round"){let b=Math.floor(m/4);const P=s.create();x.forEach(B=>{let w=s.angle(s.subtract(P,B.s1[0],B.c));if(w-=s.angle(s.subtract(P,B.s0[1],B.c)),g&&w<0&&(w=w+Math.PI,w<0&&(w=w+Math.PI)),!g&&w>0&&(w=w-Math.PI,w>0&&(w=w-Math.PI)),w!==0){b=Math.floor(m*(Math.abs(w)/o));const k=w/b,N=s.angle(s.subtract(P,B.s0[1],B.c)),F=[];for(let O=1;O<b;O++){const G=N+k*O,K=s.fromAngleRadians(s.create(),G);s.scale(K,K,_),s.add(K,K,B.c),F.push(K)}if(F.length>0){const O=B.s0[1];let G=f.findIndex(K=>s.equals(O,K));G=(G+1)%f.length,f.splice(G,0,...F)}}else{const k=B.s1[0],N=f.findIndex(F=>s.equals(k,F));f.splice(N,1)}})}return f};e.exports=c}}),rRn=rt({"node_modules/@jscad/modeling/src/operations/expansions/expandGeom2.js"(t,e){var n=Bs(),o=DX(),i=(r,s)=>{const a={delta:1,corners:"edge",segments:16},{delta:c,corners:l,segments:A}=Object.assign({},a,r);if(!(l==="edge"||l==="chamfer"||l==="round"))throw new Error('corners must be "edge", "chamfer", or "round"');const h=n.toOutlines(s).map(d=>(r={delta:c,corners:l,closed:!0,segments:A},o(r,d))).reduce((d,m)=>d.concat(n.toSides(n.fromPoints(m))),[]);return n.create(h)};e.exports=i}}),sRn=rt({"node_modules/@jscad/modeling/src/operations/expansions/extrudePolygon.js"(t,e){var n=TA(),o=Xi(),i=Es(),r=Ia(),s=(a,c)=>{o.dot(r.plane(c),a)>0&&(c=r.invert(c));const A=[c],u=r.transform(n.fromTranslation(n.create(),a),c),_=c.vertices.length;for(let h=0;h<_;h++){const d=h<_-1?h+1:0,m=r.create([c.vertices[h],u.vertices[h],u.vertices[d],c.vertices[d]]);A.push(m)}return A.push(r.invert(u)),i.create(A)};e.exports=s}}),aRn=rt({"node_modules/@jscad/modeling/src/operations/expansions/expandShell.js"(t,e){var{EPS:n,TAU:o}=La(),i=TA(),r=Xi(),s=__t(),a=Es(),c=Ia(),l=r_t(),A=kk(),u=m_t(),_=sRn(),h=(g,y,f)=>{const x=y.toString();if(g.has(x))g.get(x)[1].push(f);else{const I=[y,[f]];g.set(x,I)}},d=(g,y,f)=>{const x=y[0].toString(),I=y[1].toString(),E=x<I?`${x},${I}`:`${I},${x}`;if(g.has(E))g.get(E)[1].push(f);else{const b=[y,[f]];g.set(E,b)}},m=(g,y)=>{g.findIndex(x=>x===y)<0&&g.push(y)},p=(g,y)=>{const f={delta:1,segments:12},{delta:x,segments:I}=Object.assign({},f,g);let E=a.create();const b=new Map,P=new Map,B=r.create(),w=r.create();return a.toPolygons(y).forEach((N,F)=>{const O=r.scale(r.create(),c.plane(N),2*x),G=c.transform(i.fromTranslation(i.create(),r.scale(r.create(),O,-.5)),N),K=_(O,G);E=u(E,K);const X=N.vertices;for(let $=0;$<X.length;$++){h(b,X[$],c.plane(N));const oe=($+1)%X.length,Ae=[X[$],X[oe]];d(P,Ae,c.plane(N))}}),P.forEach(N=>{const F=N[0],O=N[1],G=F[0],K=F[1],X=r.subtract(r.create(),K,G);r.normalize(X,X);const $=O[0],oe=r.cross(r.create(),$,X);let Ae=[];for(let Me=0;Me<I;Me++)m(Ae,Me*o/I);for(let Me=0,ue=O.length;Me<ue;Me++){const Ie=O[Me],pe=r.dot(oe,Ie),Le=r.dot($,Ie);let Ue=Math.atan2(pe,Le);Ue<0&&(Ue+=o),m(Ae,Ue),Ue=Math.atan2(-pe,-Le),Ue<0&&(Ue+=o),m(Ae,Ue)}Ae=Ae.sort(s);const Z=Ae.length;let se,ae;const ce=[],ge=[],be=[];for(let Me=-1;Me<Z;Me++){const ue=Ae[Me<0?Me+Z:Me],Ie=Math.sin(ue),pe=Math.cos(ue);r.scale(B,$,pe*x),r.scale(w,oe,Ie*x),r.add(B,B,w);const Le=r.add(r.create(),G,B),Ue=r.add(r.create(),K,B);let je=!1;if(Me>=0&&r.distance(Le,se)<n&&(je=!0),!je){if(Me>=0){ce.push(Le),ge.push(Ue);const ye=[ae,Ue,Le,se],$e=c.create(ye);be.push($e)}se=Le,ae=Ue}}ge.reverse(),be.push(c.create(ce)),be.push(c.create(ge));const ve=a.create(be);E=u(E,ve)}),b.forEach(N=>{const F=N[0],O=N[1],G=O[0];let K=null,X=0;for(let Z=1;Z<O.length;Z++){const se=O[Z],ae=r.cross(B,G,se),ce=r.length(ae);ce>.05&&ce>X&&(X=ce,K=se)}K||(K=r.orthogonal(B,G));const $=r.cross(B,G,K);r.normalize($,$);const oe=r.cross(w,$,G),Ae=l({center:[F[0],F[1],F[2]],radius:x,segments:I,axes:[G,$,oe]});E=u(E,Ae)}),A(E)};e.exports=p}}),cRn=rt({"node_modules/@jscad/modeling/src/operations/expansions/expandGeom3.js"(t,e){var n=Es(),o=o5e(),i=aRn(),r=(s,a)=>{const c={delta:1,corners:"round",segments:12},{delta:l,corners:A,segments:u}=Object.assign({},c,s);if(A!=="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:l,corners:A,segments:u};const h=i(s,a);return o(a,h)};e.exports=r}}),lRn=rt({"node_modules/@jscad/modeling/src/operations/expansions/expandPath2.js"(t,e){var n=BX(),o=js(),i=Bs(),r=AA(),s=DX(),a=A=>{let{external:u,internal:_}=A;n(u)<0?u=u.reverse():_=_.reverse();const h=r.fromPoints({closed:!0},u),d=r.fromPoints({closed:!0},_),m=i.toSides(i.fromPoints(r.toPoints(h))),p=i.toSides(i.fromPoints(r.toPoints(d)));return m.push(...p),i.create(m)},c=(A,u,_,h)=>{const{points:d,external:m,internal:p}=A,g=Math.floor(u/2),y=[],f=[];if(_==="round"&&g>0){const I=Math.PI/g,E=d[d.length-1],b=o.angle(o.subtract(o.create(),m[m.length-1],E)),P=d[0],B=o.angle(o.subtract(o.create(),p[0],P));for(let w=1;w<g;w++){let k=b+I*w,N=o.fromAngleRadians(o.create(),k);o.scale(N,N,h),o.add(N,N,E),y.push(N),k=B+I*w,N=o.fromAngleRadians(o.create(),k),o.scale(N,N,h),o.add(N,N,P),f.push(N)}}const x=[];return x.push(...m,...y,...p.reverse(),...f),i.fromPoints(x)},l=(A,u)=>{A=Object.assign({},{delta:1,corners:"edge",segments:16},A);const{delta:h,corners:d,segments:m}=A;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=u.isClosed,g=r.toPoints(u);if(g.length===0)throw new Error("the given geometry cannot be empty");const y={points:g,external:s({delta:h,corners:d,segments:m,closed:p},g),internal:s({delta:-h,corners:d,segments:m,closed:p},g)};return u.isClosed?a(y):c(y,m,d,h)};e.exports=l}}),i5e=rt({"node_modules/@jscad/modeling/src/operations/expansions/expand.js"(t,e){var n=ts(),o=Bs(),i=Es(),r=AA(),s=rRn(),a=cRn(),c=lRn(),l=(A,...u)=>{if(u=n(u),u.length===0)throw new Error("wrong number of arguments");const _=u.map(h=>r.isA(h)?c(A,h):o.isA(h)?s(A,h):i.isA(h)?a(A,h):h);return _.length===1?_[0]:_};e.exports=l}}),ARn=rt({"node_modules/@jscad/modeling/src/operations/expansions/offsetGeom2.js"(t,e){var n=Bs(),o=GCe(),i=DX(),r=(s,a)=>{const c={delta:1,corners:"edge",segments:0},{delta:l,corners:A,segments:u}=Object.assign({},c,s);if(!(A==="edge"||A==="chamfer"||A==="round"))throw new Error('corners must be "edge", "chamfer", or "round"');const _=n.toOutlines(a),d=_.map(m=>(s={delta:_.reduce((y,f)=>y+o.arePointsInside(m,o.create(f)),0)%2===0?l:-l,corners:A,closed:!0,segments:u},i(s,m))).reduce((m,p)=>m.concat(n.toSides(n.fromPoints(p))),[]);return n.create(d)};e.exports=r}}),uRn=rt({"node_modules/@jscad/modeling/src/operations/expansions/offsetPath2.js"(t,e){var n=AA(),o=DX(),i=(r,s)=>{const a={delta:1,corners:"edge",closed:s.isClosed,segments:16},{delta:c,corners:l,closed:A,segments:u}=Object.assign({},a,r);if(!(l==="edge"||l==="chamfer"||l==="round"))throw new Error('corners must be "edge", "chamfer", or "round"');r={delta:c,corners:l,closed:A,segments:u};const _=o(r,n.toPoints(s));return n.fromPoints({closed:A},_)};e.exports=i}}),_Rn=rt({"node_modules/@jscad/modeling/src/operations/expansions/offset.js"(t,e){var n=ts(),o=Bs(),i=AA(),r=ARn(),s=uRn(),a=(c,...l)=>{if(l=n(l),l.length===0)throw new Error("wrong number of arguments");const A=l.map(u=>i.isA(u)?s(c,u):o.isA(u)?r(c,u):u);return A.length===1?A[0]:A};e.exports=a}}),y_t=rt({"node_modules/@jscad/modeling/src/operations/expansions/index.js"(t,e){e.exports={expand:i5e(),offset:_Rn()}}}),TX=rt({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeLinearGeom2.js"(t,e){var n=TA(),o=Xi(),i=Bs(),r=M7(),s=wX(),a=(c,l)=>{const A={offset:[0,0,1],twistAngle:0,twistSteps:12,repair:!0};let{offset:u,twistAngle:_,twistSteps:h,repair:d}=Object.assign({},A,c);if(h<1)throw new Error("twistSteps must be 1 or more");_===0&&(h=1);const m=o.clone(u),p=i.toSides(l);if(p.length===0)throw new Error("the given geometry cannot be empty");const g=r.fromSides(p);m[2]<0&&r.reverse(g,g);const y=n.create(),f=(x,I,E)=>{const b=I/h*_,P=o.scale(o.create(),m,I/h);return n.multiply(y,n.fromZRotation(y,b),n.fromTranslation(n.create(),P)),r.transform(y,E)};return c={numberOfSlices:h+1,capStart:!0,capEnd:!0,repair:d,callback:f},s(c,g)};e.exports=a}}),dRn=rt({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeLinearPath2.js"(t,e){var n=Bs(),o=AA(),i=TX(),r=(s,a)=>{if(!a.isClosed)throw new Error("extruded path must be closed");const c=o.toPoints(a),l=n.fromPoints(c);return i(s,l)};e.exports=r}}),hRn=rt({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeLinear.js"(t,e){var n=ts(),o=Bs(),i=AA(),r=TX(),s=dRn(),a=(c,...l)=>{const A={height:1,twistAngle:0,twistSteps:1,repair:!0},{height:u,twistAngle:_,twistSteps:h,repair:d}=Object.assign({},A,c);if(l=n(l),l.length===0)throw new Error("wrong number of arguments");c={offset:[0,0,u],twistAngle:_,twistSteps:h,repair:d};const m=l.map(p=>i.isA(p)?s(c,p):o.isA(p)?r(c,p):p);return m.length===1?m[0]:m};e.exports=a}}),mRn=rt({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeRectangularPath2.js"(t,e){var n=AA(),o=i5e(),i=TX(),r=(s,a)=>{const c={size:1,height:1},{size:l,height:A}=Object.assign({},c,s);if(s.delta=l,s.offset=[0,0,A],n.toPoints(a).length===0)throw new Error("the given geometry cannot be empty");const _=o(s,a);return i(s,_)};e.exports=r}}),gRn=rt({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeRectangularGeom2.js"(t,e){var{area:n}=Dk(),o=Bs(),i=AA(),r=i5e(),s=TX(),a=(c,l)=>{const A={size:1,height:1},{size:u,height:_}=Object.assign({},A,c);c.delta=u,c.offset=[0,0,_];const h=o.toOutlines(l);if(h.length===0)throw new Error("the given geometry cannot be empty");const m=h.map(g=>(n(g)<0&&g.reverse(),r(c,i.fromPoints({closed:!0},g)))).reduce((g,y)=>g.concat(o.toSides(y)),[]),p=o.create(m);return s(c,p)};e.exports=a}}),pRn=rt({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeRectangular.js"(t,e){var n=ts(),o=Bs(),i=AA(),r=mRn(),s=gRn(),a=(c,...l)=>{const A={size:1,height:1},{size:u,height:_}=Object.assign({},A,c);if(l=n(l),l.length===0)throw new Error("wrong number of arguments");if(u<=0)throw new Error("size must be positive");if(_<=0)throw new Error("height must be positive");const h=l.map(d=>i.isA(d)?r(c,d):o.isA(d)?s(c,d):d);return h.length===1?h[0]:h};e.exports=a}}),fRn=rt({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeHelical.js"(t,e){var{TAU:n}=La(),o=TA(),i=Bs(),r=wX(),s=M7(),a=(c,l)=>{const A={angle:n,startAngle:0,pitch:10,height:0,endOffset:0,segmentsPerRotation:32};let{angle:u,startAngle:_,pitch:h,height:d,endOffset:m,segmentsPerRotation:p}=Object.assign({},A,c);if(d!=0&&(h=d/(u/n)),p<3)throw new Error("The number of segments per rotation needs to be at least 3.");const y=i.toSides(l);if(y.length===0)throw new Error("The given geometry cannot be empty");const f=y.filter(w=>w[0][0]>=0);let x=s.fromSides(y);f.length===0&&(x=s.reverse(x));const I=Math.round(p/n*Math.abs(u)),E=I>=2?I:2,b=o.create(),P=o.create(),B=(w,k,N)=>{const F=_+u/E*k,O=m/E*k,G=(F-_)/n*h;return o.multiply(b,o.fromTranslation(o.create(),[O,0,G*Math.sign(u)]),o.fromXRotation(o.create(),-n/4*Math.sign(u))),o.multiply(P,o.fromZRotation(o.create(),F),b),s.transform(P,N)};return r({numberOfSlices:E+1,callback:B},x)};e.exports=a}}),yRn=rt({"node_modules/@jscad/modeling/src/operations/extrusions/project.js"(t,e){var n=ts(),o=YCe(),i=t3(),r=TA(),s=Bs(),a=Es(),c=Ia(),l=k4(),A=f_t(),u=(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=l(d),g=p*p*Math.sqrt(3)/4;if(p===0)return s.create();const y=a.toPolygons(d);let f=[];for(let I=0;I<y.length;I++){const E=y[I].vertices.map(B=>i.projectionOfPoint(m,B)),b=c.create(E),P=c.plane(b);o(m,P)&&(c.measureArea(b)<g||f.push(b))}if(!o(m,[0,0,1])){const I=r.fromVectorRotation(r.create(),m,[0,0,1]);f=f.map(E=>c.transform(I,E))}f=f.sort((I,E)=>c.measureArea(E)-c.measureArea(I));const x=f.map(I=>s.fromPoints(I.vertices));return A(x)},_=(h,...d)=>{const m={axis:[0,0,1],origin:[0,0,0]},{axis:p,origin:g}=Object.assign({},m,h);if(d=n(d),d.length===0)throw new Error("wrong number of arguments");h={axis:p,origin:g};const y=d.map(f=>a.isA(f)?u(h,f):f);return y.length===1?y[0]:y};e.exports=_}}),Lk=rt({"node_modules/@jscad/modeling/src/operations/extrusions/index.js"(t,e){e.exports={extrudeFromSlices:wX(),extrudeLinear:hRn(),extrudeRectangular:pRn(),extrudeRotate:l_t(),extrudeHelical:fRn(),project:yRn(),slice:M7()}}}),r5e=rt({"node_modules/@jscad/modeling/src/operations/hulls/hullPoints2.js"(t,e){var n=js(),o=s=>{let a=n.fromValues(1/0,1/0);s.forEach(A=>{(A[1]<a[1]||A[1]===a[1]&&A[0]<a[0])&&(a=A)});const c=[];s.forEach(A=>{const u=r(A[1]-a[1],A[0]-a[0]),_=n.squaredDistance(A,a);c.push({point:A,angle:u,distSq:_})}),c.sort((A,u)=>A.angle!==u.angle?A.angle-u.angle:A.distSq-u.distSq);const l=[];return c.forEach(A=>{let u=l.length;for(;u>1&&i(l[u-2],l[u-1],A.point)<=Number.EPSILON;)l.pop(),u=l.length;l.push(A.point)}),l},i=(s,a,c)=>(a[0]-s[0])*(c[1]-s[1])-(a[1]-s[1])*(c[0]-s[0]),r=(s,a)=>s===0&&a===0?-1/0:-a/s;e.exports=o}}),s5e=rt({"node_modules/@jscad/modeling/src/operations/hulls/toUniquePoints.js"(t,e){var n=Bs(),o=Es(),i=AA(),r=s=>{const a=new Set,c=[],l=A=>{const u=A.toString();a.has(u)||(c.push(A),a.add(u))};return s.forEach(A=>{n.isA(A)?n.toPoints(A).forEach(l):o.isA(A)?o.toPoints(A).forEach(u=>u.forEach(l)):i.isA(A)&&i.toPoints(A).forEach(l)}),c};e.exports=r}}),xRn=rt({"node_modules/@jscad/modeling/src/operations/hulls/hullPath2.js"(t,e){var n=ts(),o=AA(),i=r5e(),r=s5e(),s=(...a)=>{a=n(a);const c=r(a),l=i(c);return o.fromPoints({closed:!0},l)};e.exports=s}}),CRn=rt({"node_modules/@jscad/modeling/src/operations/hulls/hullGeom2.js"(t,e){var n=ts(),o=Bs(),i=r5e(),r=s5e(),s=(...a)=>{a=n(a);const c=r(a),l=i(c);return l.length<3?o.create():o.fromPoints(l)};e.exports=s}}),IRn=rt({"node_modules/@jscad/modeling/src/operations/hulls/hullGeom3.js"(t,e){var n=ts(),o=Es(),i=s5e(),r=t5e(),s=(...a)=>{a=n(a);const c=i(a);return c.length===0?o.create():o.create(r(c))};e.exports=s}}),x_t=rt({"node_modules/@jscad/modeling/src/operations/hulls/hull.js"(t,e){var n=ts(),o=Nk(),i=Bs(),r=Es(),s=AA(),a=xRn(),c=CRn(),l=IRn(),A=(...u)=>{if(u=n(u),u.length===0)throw new Error("wrong number of arguments");if(!o(u))throw new Error("only hulls of the same type are supported");const _=u[0];return s.isA(_)?a(u):i.isA(_)?c(u):r.isA(_)?l(u):_};e.exports=A}}),ERn=rt({"node_modules/@jscad/modeling/src/operations/hulls/hullChain.js"(t,e){var n=ts(),o=o5e(),i=x_t(),r=(...s)=>{if(s=n(s),s.length<2)throw new Error("wrong number of arguments");const a=[];for(let c=1;c<s.length;c++)a.push(i(s[c-1],s[c]));return o(a)};e.exports=r}}),bRn=rt({"node_modules/@jscad/modeling/src/operations/hulls/index.js"(t,e){e.exports={hull:x_t(),hullChain:ERn(),hullPoints2:r5e(),hullPoints3:t5e()}}}),SRn=rt({"node_modules/@jscad/modeling/src/operations/minkowski/index.js"(t,e){e.exports={minkowskiSum:g_t()}}}),C_t=rt({"node_modules/@jscad/modeling/src/operations/modifiers/snapPolygons.js"(t,e){var n=Xi(),o=Ia(),i=(s,a)=>{const c=Math.abs(o.measureArea(a));return Number.isFinite(c)&&c>s},r=(s,a)=>{let c=a.map(A=>{const u=A.vertices.map(d=>n.snap(n.create(),d,s)),_=[];for(let d=0;d<u.length;d++){const m=(d+1)%u.length;n.equals(u[d],u[m])||_.push(u[d])}const h=o.create(_);return A.color&&(h.color=A.color),h});const l=s*s*Math.sqrt(3)/4;return c=c.filter(A=>i(l,A)),c};e.exports=r}}),PRn=rt({"node_modules/@jscad/modeling/src/operations/modifiers/mergePolygons.js"(t,e){var n=YCe(),o=Xi(),i=Ia(),r=g=>{const y=i.toPoints(g),f=[];for(let x=0;x<y.length;x++){const I=(x+1)%y.length,E={v1:y[x],v2:y[I]};f.push(E)}for(let x=0;x<f.length;x++){const I=(x+1)%y.length;f[x].next=f[I],f[I].prev=f[x]}return f},s=(g,y)=>{const f=`${y.v1}:${y.v2}`;g.set(f,y)},a=(g,y)=>{const f=`${y.v1}:${y.v2}`;g.delete(f)},c=(g,y)=>{const f=`${y.v2}:${y.v1}`;return g.get(f)},l=(g,y,f)=>{let x=g.prev.v1,I=g.prev.v2,E=y.next.v2;const b=_(x,I,E,f);x=y.prev.v1,I=y.prev.v2,E=g.next.v2;const P=_(x,I,E,f);return[b,P]},A=o.create(),u=o.create(),_=(g,y,f,x)=>{const I=o.subtract(A,y,g),E=o.subtract(u,f,y);return o.cross(I,I,E),o.dot(I,x)},h=g=>{let y;const f=[];for(;g.next;){const x=g.next;f.push(g.v1),g.v1=null,g.v2=null,g.next=null,g.prev=null,g=x}return f.length>0&&(y=i.create(f)),y},d=g=>{if(g.length<2)return g;const y=g[0].plane,f=g.slice(),x=new Map;for(;f.length>0;){const E=f.shift(),b=r(E);for(let P=0;P<b.length;P++){const B=b[P],w=c(x,B);if(w){const k=l(B,w,y);if(k[0]>=0&&k[1]>=0){const N=w.next,F=B.next;B.prev.next=w.next,B.next.prev=w.prev,w.prev.next=B.next,w.next.prev=B.prev,B.v1=null,B.v2=null,B.next=null,B.prev=null,a(x,w),w.v1=null,w.v2=null,w.next=null,w.prev=null;const O=(G,K,X)=>{const $={v1:X.v1,v2:K.v2,next:K.next,prev:X.prev};X.prev.next=$,K.next.prev=$,a(G,K),K.v1=null,K.v2=null,K.next=null,K.prev=null,a(G,X),X.v1=null,X.v2=null,X.next=null,X.prev=null};k[0]===0&&O(x,N,N.prev),k[1]===0&&O(x,F,F.prev)}}else B.next&&s(x,B)}}const I=[];return x.forEach(E=>{const b=h(E);b&&I.push(b)}),x.clear(),I},m=(g,y)=>Math.abs(g[3]-y[3])<15e-8?n(g,y):!1,p=(g,y)=>{const f=[];y.forEach(I=>{const E=f.find(b=>m(b[0],i.plane(I)));E?E[1].push(I):f.push([i.plane(I),[I]])});let x=[];return f.forEach(I=>{const E=I[1],b=d(E);x=x.concat(b)}),x};e.exports=p}}),vRn=rt({"node_modules/@jscad/modeling/src/operations/modifiers/insertTjunctions.js"(t,e){var n=La(),o=Xi(),i=Ia(),r=l=>`${l}`,s=(l,A,u,_,h,d)=>{const m=r(_),p=r(h),g=`${m}/${p}`,y=`${p}/${m}`;if(l.has(y))return a(l,A,u,h,_,null),null;const f={vertex0:_,vertex1:h,polygonindex:d};return l.has(g)?l.get(g).push(f):l.set(g,[f]),A.has(m)?A.get(m).push(g):A.set(m,[g]),u.has(p)?u.get(p).push(g):u.set(p,[g]),g},a=(l,A,u,_,h,d)=>{const m=r(_),p=r(h),g=`${m}/${p}`;let y=-1;const f=l.get(g);for(let x=0;x<f.length;x++){const I=f[x];let E=r(I.vertex0);if(E===m&&(E=r(I.vertex1),E===p&&!(d!==null&&I.polygonindex!==d))){y=x;break}}f.splice(y,1),f.length===0&&l.delete(g),y=A.get(m).indexOf(g),A.get(m).splice(y,1),A.get(m).length===0&&A.delete(m),y=u.get(p).indexOf(g),u.get(p).splice(y,1),u.get(p).length===0&&u.delete(p)},c=l=>{const A=new Map;for(let u=0;u<l.length;u++){const _=l[u],h=_.vertices.length;if(h>=3){let d=_.vertices[0],m=r(d);for(let p=0;p<h;p++){let g=p+1;g===h&&(g=0);const y=_.vertices[g],f=r(y),x=`${m}/${f}`,I=`${f}/${m}`;if(A.has(I)){const E=A.get(I);E.splice(-1,1),E.length===0&&A.delete(I)}else{const E={vertex0:d,vertex1:y,polygonindex:u};A.has(x)?A.get(x).push(E):A.set(x,[E])}d=y,m=f}}else console.warn("warning: invalid polygon found during insertTjunctions")}if(A.size>0){const u=new Map,_=new Map,h=new Map;for(const[m,p]of A)h.set(m,!0),p.forEach(g=>{const y=r(g.vertex0),f=r(g.vertex1);u.has(y)?u.get(y).push(m):u.set(y,[m]),_.has(f)?_.get(f).push(m):_.set(f,[m])});const d=l.slice(0);for(;A.size!==0;){for(const p of A.keys())h.set(p,!0);let m=!1;for(;;){const p=Array.from(h.keys());if(p.length===0)break;const g=p[0];let y=!0;if(A.has(g)){const x=A.get(g)[0];for(let I=0;I<2;I++){const E=I===0?x.vertex0:x.vertex1,b=I===0?x.vertex1:x.vertex0,P=r(E),B=r(b);let w=[];I===0?_.has(P)&&(w=_.get(P)):u.has(P)&&(w=u.get(P));for(let k=0;k<w.length;k++){const N=w[k],F=A.get(N)[0],O=I===0?F.vertex0:F.vertex1;if(I===0?F.vertex1:F.vertex0,r(O)===B){a(A,u,_,E,b,null),a(A,u,_,b,E,null),y=!1,I=2,m=!0;break}else{const K=E,X=b,$=O,oe=o.subtract(o.create(),$,K),Ae=o.dot(o.subtract(o.create(),X,K),oe)/o.dot(oe,oe);if(Ae>0&&Ae<1){const Z=o.scale(o.create(),oe,Ae);if(o.add(Z,Z,K),o.squaredDistance(Z,X)<n.EPS*n.EPS){const ae=F.polygonindex,ce=d[ae],ge=r(F.vertex1);let be=-1;for(let pe=0;pe<ce.vertices.length;pe++)if(r(ce.vertices[pe])===ge){be=pe;break}const ve=ce.vertices.slice(0);ve.splice(be,0,b);const Me=i.create(ve);d[ae]=Me,a(A,u,_,F.vertex0,F.vertex1,ae);const ue=s(A,u,_,F.vertex0,b,ae),Ie=s(A,u,_,b,F.vertex1,ae);ue!==null&&h.set(ue,!0),Ie!==null&&h.set(Ie,!0),y=!1,I=2,m=!0;break}}}}}}y&&h.delete(g)}if(!m)break}l=d}return A.clear(),l};e.exports=c}}),BRn=rt({"node_modules/@jscad/modeling/src/operations/modifiers/triangulatePolygons.js"(t,e){var n=Xi(),o=Ia(),i=(s,a,c)=>{const l=a.vertices.length;if(l>3){if(l>4){const _=[0,0,0];a.vertices.forEach(h=>n.add(_,_,h)),n.snap(_,n.divide(_,_,[l,l,l]),s);for(let h=0;h<l;h++){const d=o.create([_,a.vertices[h],a.vertices[(h+1)%l]]);a.color&&(d.color=a.color),c.push(d)}return}const A=o.create([a.vertices[0],a.vertices[1],a.vertices[2]]),u=o.create([a.vertices[0],a.vertices[2],a.vertices[3]]);a.color&&(A.color=a.color,u.color=a.color),c.push(A,u);return}c.push(a)},r=(s,a)=>{const c=[];return a.forEach(l=>{i(s,l,c)}),c};e.exports=r}}),MRn=rt({"node_modules/@jscad/modeling/src/operations/modifiers/generalize.js"(t,e){var n=ts(),o=k4(),i=Bs(),r=Es(),s=AA(),a=C_t(),c=PRn(),l=vRn(),A=BRn(),u=(m,p)=>p,_=(m,p)=>p,h=(m,p)=>{const g={snap:!1,simplify:!1,triangulate:!1},{snap:y,simplify:f,triangulate:x}=Object.assign({},g,m),I=o(p);let E=r.toPolygons(p);y&&(E=a(I,E)),f&&(E=c(I,E)),x&&(E=l(E),E=A(I,E));const b=Object.assign({},p);return b.polygons=E,b},d=(m,...p)=>{if(p=n(p),p.length===0)throw new Error("wrong number of arguments");const g=p.map(y=>{if(s.isA(y))return u(m,y);if(i.isA(y))return _(m,y);if(r.isA(y))return h(m,y);throw new Error("invalid geometry")});return g.length===1?g[0]:g};e.exports=d}}),wRn=rt({"node_modules/@jscad/modeling/src/operations/modifiers/snap.js"(t,e){var n=ts(),o=js(),i=Bs(),r=Es(),s=AA(),a=k4(),c=C_t(),l=h=>{const d=a(h),p=s.toPoints(h).map(g=>o.snap(o.create(),g,d));return s.create(p)},A=h=>{const d=a(h);let p=i.toSides(h).map(g=>[o.snap(o.create(),g[0],d),o.snap(o.create(),g[1],d)]);return p=p.filter(g=>!o.equals(g[0],g[1])),i.create(p)},u=h=>{const d=a(h),m=r.toPolygons(h),p=c(d,m);return r.create(p)},_=(...h)=>{if(h=n(h),h.length===0)throw new Error("wrong number of arguments");const d=h.map(m=>s.isA(m)?l(m):i.isA(m)?A(m):r.isA(m)?u(m):m);return d.length===1?d[0]:d};e.exports=_}}),DRn=rt({"node_modules/@jscad/modeling/src/operations/modifiers/index.js"(t,e){e.exports={generalize:MRn(),snap:wRn(),retessellate:kk()}}}),TRn=rt({"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}}),QRn=rt({"node_modules/@jscad/modeling/src/operations/transforms/align.js"(t,e){var n=ts(),o=TRn(),i=WCe(),{translate:r}=uB(),s=A=>{if(!Array.isArray(A.modes)||A.modes.length>3)throw new Error("align(): modes must be an array of length <= 3");if(A.modes=o(A.modes,"none",3),A.modes.filter(u=>["center","max","min","none"].includes(u)).length!==3)throw new Error('align(): all modes must be one of "center", "max" or "min"');if(!Array.isArray(A.relativeTo)||A.relativeTo.length>3)throw new Error("align(): relativeTo must be an array of length <= 3");if(A.relativeTo=o(A.relativeTo,0,3),A.relativeTo.filter(u=>Number.isFinite(u)||u==null).length!==3)throw new Error("align(): all relativeTo values must be a number, or null.");if(typeof A.grouped!="boolean")throw new Error("align(): grouped must be a boolean value.");return A},a=(A,u,_)=>{for(let h=0;h<3;h++)A[h]==null&&(u[h]==="center"?A[h]=(_[0][h]+_[1][h])/2:u[h]==="max"?A[h]=_[1][h]:u[h]==="min"&&(A[h]=_[0][h]));return A},c=(A,u,_)=>{const h=i(A),d=[0,0,0];for(let m=0;m<3;m++)u[m]==="center"?d[m]=_[m]-(h[0][m]+h[1][m])/2:u[m]==="max"?d[m]=_[m]-h[1][m]:u[m]==="min"&&(d[m]=_[m]-h[0][m]);return r(d,A)},l=(A,...u)=>{A=Object.assign({},{modes:["center","center","min"],relativeTo:[0,0,0],grouped:!1},A),A=s(A);let{modes:h,relativeTo:d,grouped:m}=A;if(u=n(u),u.length===0)throw new Error("align(): No geometries were provided to act upon");if(d.filter(p=>p==null).length){const p=i(u);d=a(d,h,p)}return m?u=c(u,h,d):u=u.map(p=>c(p,h,d)),u.length===1?u[0]:u};e.exports=l}}),QX=rt({"node_modules/@jscad/modeling/src/operations/transforms/center.js"(t,e){var n=ts(),o=Bs(),i=Es(),r=AA(),s=lB(),{translate:a}=uB(),c=(h,d)=>{const m={axes:[!0,!0,!0],relativeTo:[0,0,0]},{axes:p,relativeTo:g}=Object.assign({},m,h),y=s(d),f=[0,0,0];return p[0]&&(f[0]=g[0]-(y[0][0]+(y[1][0]-y[0][0])/2)),p[1]&&(f[1]=g[1]-(y[0][1]+(y[1][1]-y[0][1])/2)),p[2]&&(f[2]=g[2]-(y[0][2]+(y[1][2]-y[0][2])/2)),a(f,d)},l=(h,...d)=>{const m={axes:[!0,!0,!0],relativeTo:[0,0,0]},{axes:p,relativeTo:g}=Object.assign({},m,h);if(d=n(d),d.length===0)throw new Error("wrong number of arguments");if(g.length!==3)throw new Error("relativeTo must be an array of length 3");h={axes:p,relativeTo:g};const y=d.map(f=>r.isA(f)||o.isA(f)||i.isA(f)?c(h,f):f);return y.length===1?y[0]:y},A=(...h)=>l({axes:[!0,!1,!1]},h),u=(...h)=>l({axes:[!1,!0,!1]},h),_=(...h)=>l({axes:[!1,!1,!0]},h);e.exports={center:l,centerX:A,centerY:u,centerZ:_}}}),RX=rt({"node_modules/@jscad/modeling/src/operations/transforms/scale.js"(t,e){var n=ts(),o=TA(),i=Bs(),r=Es(),s=AA(),a=(u,..._)=>{if(!Array.isArray(u))throw new Error("factors must be an array");if(_=n(_),_.length===0)throw new Error("wrong number of arguments");for(u=u.slice();u.length<3;)u.push(1);if(u[0]<=0||u[1]<=0||u[2]<=0)throw new Error("factors must be positive");const h=o.fromScaling(o.create(),u),d=_.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},c=(u,..._)=>a([u,1,1],_),l=(u,..._)=>a([1,u,1],_),A=(u,..._)=>a([1,1,u],_);e.exports={scale:a,scaleX:c,scaleY:l,scaleZ:A}}}),RRn=rt({"node_modules/@jscad/modeling/src/operations/transforms/transform.js"(t,e){var n=ts(),o=Bs(),i=Es(),r=AA(),s=(a,...c)=>{if(c=n(c),c.length===0)throw new Error("wrong number of arguments");const l=c.map(A=>r.isA(A)?r.transform(a,A):o.isA(A)?o.transform(a,A):i.isA(A)?i.transform(a,A):A);return l.length===1?l[0]:l};e.exports=s}}),dB=rt({"node_modules/@jscad/modeling/src/operations/transforms/index.js"(t,e){e.exports={align:QRn(),center:QX().center,centerX:QX().centerX,centerY:QX().centerY,centerZ:QX().centerZ,mirror:Qk().mirror,mirrorX:Qk().mirrorX,mirrorY:Qk().mirrorY,mirrorZ:Qk().mirrorZ,rotate:Rk().rotate,rotateX:Rk().rotateX,rotateY:Rk().rotateY,rotateZ:Rk().rotateZ,scale:RX().scale,scaleX:RX().scaleX,scaleY:RX().scaleY,scaleZ:RX().scaleZ,transform:RRn(),translate:uB().translate,translateX:uB().translateX,translateY:uB().translateY,translateZ:uB().translateZ}}}),NX=rt({"node_modules/@jscad/modeling/src/index.js"(t,e){e.exports={colors:vX(),curves:BTn(),geometries:zCe(),maths:ZTn(),measurements:aQn(),primitives:_B(),text:FQn(),utils:d_t(),booleans:Hk(),expansions:y_t(),extrusions:Lk(),hulls:bRn(),minkowski:SRn(),modifiers:DRn(),transforms:dB()}}}),I_t=rt({"node_modules/jscad-planner/dist/index.cjs"(t,e){var n=Object.defineProperty,o=Object.getOwnPropertyDescriptor,i=Object.getOwnPropertyNames,r=Object.prototype.hasOwnProperty,s=(_,h)=>{for(var d in h)n(_,d,{get:h[d],enumerable:!0})},a=(_,h,d,m)=>{if(h&&typeof h=="object"||typeof h=="function")for(let p of i(h))!r.call(_,p)&&p!==d&&n(_,p,{get:()=>h[p],enumerable:!(m=o(h,p))||m.enumerable});return _},c=_=>a(n({},"__esModule",{value:!0}),_),l={};s(l,{executeJscadOperations:()=>u,jscadPlanner:()=>A}),e.exports=c(l);var A={booleans:{intersect:(..._)=>({type:"intersect",shapes:_}),subtract:(..._)=>({type:"subtract",shapes:_}),union:(..._)=>({type:"union",shapes:_})},hulls:{hull:(..._)=>({type:"hull",shapes:_.flat()}),hullChain:(..._)=>({type:"hullChain",shapes:_.flat()})},colors:{colorize:(_,h)=>({type:"colorize",color:_,shape:h})},primitives:{cube:_=>({type:"cube",..._}),sphere:_=>({type:"sphere",..._}),cylinder:_=>({type:"cylinder",..._}),polygon:_=>({type:"polygon",..._}),cuboid:_=>({type:"cuboid",..._}),roundedCuboid:_=>({type:"roundedCuboid",..._})},transforms:{rotate:(_,h)=>({type:"rotate",angles:_,shape:h}),scale:(_,h)=>({type:"scale",factors:_,shape:h}),translate:(_,h)=>({type:"translate",vector:_,shape:h})},extrusions:{extrudeLinear:(_,h)=>({type:"extrudeLinear",options:_,shape:h}),extrudeRotate:(_,h)=>({type:"extrudeRotate",options:_,shape:h})},maths:{vec2:{create:(_,h)=>[_,h],fromValues:(_,h)=>[_,h]},vec3:{create:(_,h,d)=>[_,h,d],fromValues:(_,h,d)=>[_,h,d]}},geometries:{geom2:{create:_=>({type:"createGeom2",points:_})},geom3:{create:_=>({type:"createGeom3",polygons:_})},path2:{create:_=>({type:"createPath2",points:_})}},measurements:{measureBoundingBox:_=>({type:"measureBoundingBox",shape:_}),measureArea:_=>({type:"measureArea",shape:_}),measureVolume:_=>({type:"measureVolume",shape:_})},utils:{degToRad:_=>_*Math.PI/180,radToDeg:_=>_*180/Math.PI}},u=(_,h)=>{if(Array.isArray(h)&&h.length===1)return 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(_,g),{type:m,...p}=h;switch(m){case"intersect":return _.booleans.intersect(...h.shapes.map(d));case"subtract":return _.booleans.subtract(...h.shapes.map(d));case"union":return _.booleans.union(...h.shapes.map(d));case"hull":return _.hulls.hull(...h.shapes.map(d));case"hullChain":return _.hulls.hullChain(...h.shapes.map(d));case"colorize":return _.colors.colorize(h.color,d(h.shape));case"cube":return _.primitives.cube(p);case"sphere":return _.primitives.sphere(p);case"cylinder":return _.primitives.cylinder(p);case"polygon":return _.primitives.polygon(p);case"cuboid":return _.primitives.cuboid(p);case"roundedCuboid":return _.primitives.roundedCuboid(p);case"rotate":return _.transforms.rotate(h.angles,d(h.shape));case"scale":return _.transforms.scale(h.factors,d(h.shape));case"translate":return _.transforms.translate(h.vector,d(h.shape));case"extrudeLinear":return _.extrusions.extrudeLinear(h.options,d(h.shape));case"extrudeRotate":return _.extrusions.extrudeRotate(h.options,d(h.shape));case"createGeom2":return _.geometries.geom2.create(h.points);case"createGeom3":return _.geometries.geom3.create(h.polygons);case"createPath2":return _.geometries.path2.create(h.points);case"measureBoundingBox":return _.measurements.measureBoundingBox(d(h.shape));case"measureArea":return _.measurements.measureArea(d(h.shape));case"measureVolume":return _.measurements.measureVolume(d(h.shape));case"degToRad":return _.utils.degToRad(h.degrees);case"radToDeg":return _.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)}`)}}}}),NRn=rt({"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(_,h){h=h||{};var d=typeof _;if(d==="string"&&_.length>0)return c(_);if(d==="number"&&isFinite(_))return h.long?A(_):l(_);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(_))};function c(_){if(_=String(_),!(_.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(_);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 l(_){var h=Math.abs(_);return h>=r?Math.round(_/r)+"d":h>=i?Math.round(_/i)+"h":h>=o?Math.round(_/o)+"m":h>=n?Math.round(_/n)+"s":_+"ms"}function A(_){var h=Math.abs(_);return h>=r?u(_,h,r,"day"):h>=i?u(_,h,i,"hour"):h>=o?u(_,h,o,"minute"):h>=n?u(_,h,n,"second"):_+" ms"}function u(_,h,d,m){var p=h>=d*1.5;return Math.round(_/d)+" "+m+(p?"s":"")}}}),kRn=rt({"node_modules/debug/src/common.js"(t,e){function n(o){r.debug=r,r.default=r,r.coerce=u,r.disable=l,r.enable=a,r.enabled=A,r.humanize=NRn(),r.destroy=_,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,g;function y(...f){if(!y.enabled)return;const x=y,I=Number(new Date),E=I-(d||I);x.diff=E,x.prev=d,x.curr=I,d=I,f[0]=r.coerce(f[0]),typeof f[0]!="string"&&f.unshift("%O");let b=0;f[0]=f[0].replace(/%([a-zA-Z%])/g,(B,w)=>{if(B==="%%")return"%";b++;const k=r.formatters[w];if(typeof k=="function"){const N=f[b];B=k.call(x,N),f.splice(b,1),b--}return B}),r.formatArgs.call(x,f),(x.log||r.log).apply(x,f)}return y.namespace=h,y.useColors=r.useColors(),y.color=r.selectColor(h),y.extend=s,y.destroy=r.destroy,Object.defineProperty(y,"enabled",{enumerable:!0,configurable:!1,get:()=>m!==null?m:(p!==r.namespaces&&(p=r.namespaces,g=r.enabled(h)),g),set:f=>{m=f}}),typeof r.init=="function"&&r.init(y),y}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 c(h,d){let m=0,p=0,g=-1,y=0;for(;m<h.length;)if(p<d.length&&(d[p]===h[m]||d[p]==="*"))d[p]==="*"?(g=p,y=m,p++):(m++,p++);else if(g!==-1)p=g+1,y++,m=y;else return!1;for(;p<d.length&&d[p]==="*";)p++;return p===d.length}function l(){const h=[...r.names,...r.skips.map(d=>"-"+d)].join(",");return r.enable(""),h}function A(h){for(const d of r.skips)if(c(h,d))return!1;for(const d of r.names)if(c(h,d))return!0;return!1}function u(h){return h instanceof Error?h.stack||h.message:h}function _(){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}}),HRn=rt({"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 c=!1;return()=>{c||(c=!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 c;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&&(c=navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/))&&parseInt(c[1],10)>=31||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)}function o(c){if(c[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+c[0]+(this.useColors?"%c ":" ")+"+"+e.exports.humanize(this.diff),!this.useColors)return;const l="color: "+this.color;c.splice(1,0,l,"color: inherit");let A=0,u=0;c[0].replace(/%[a-zA-Z%]/g,_=>{_!=="%%"&&(A++,_==="%c"&&(u=A))}),c.splice(u,0,l)}t.log=console.debug||console.log||(()=>{});function i(c){try{c?t.storage.setItem("debug",c):t.storage.removeItem("debug")}catch{}}function r(){let c;try{c=t.storage.getItem("debug")||t.storage.getItem("DEBUG")}catch{}return!c&&typeof TCe<"u"&&"env"in TCe&&(c=TCe.env.DEBUG),c}function s(){try{return localStorage}catch{}}e.exports=kRn()(t);var{formatters:a}=e.exports;a.j=function(c){try{return JSON.stringify(c)}catch(l){return"[UnexpectedJSONParseError]: "+l.message}}}}),E_t={boardBody:!0,topCopper:!0,bottomCopper:!0,adhesive:!1,solderPaste:!1,topSilkscreen:!0,bottomSilkscreen:!0,topMask:!0,bottomMask:!0,throughHoleModels:!0,smtModels:!0,translucentModels:!0,modelsNotInPosFile:!1,modelsMarkedDNP:!1,modelBoundingBoxes:!1,threedAxis:!1,pcbNotes:!1,backgroundStart:!0,backgroundEnd:!0},b_t=ne.createContext(void 0),LRn=({children:t})=>{const[e,n]=ne.useState(E_t),o=ne.useCallback((s,a)=>{n(c=>({...c,[s]:a}))},[]),i=ne.useCallback(()=>{n(E_t)},[]),r=ne.useMemo(()=>({visibility:e,setLayerVisibility:o,resetToDefaults:i}),[e,o,i]);return W.jsx(b_t.Provider,{value:r,children:t})},hB=()=>{const t=ne.useContext(b_t);if(!t)throw new Error("useLayerVisibility must be used within a LayerVisibilityProvider");return t},a5e=1.2;function S_t(t){return ne.useMemo(()=>{if(!t)return a5e;try{return Ni(t).pcb_board.list()[0]?.thickness??a5e}catch{return a5e}},[t])}var P_t=ne.createContext(null),g1=()=>{const t=ne.useContext(P_t);if(!t)throw new Error("useThree must be used within a ThreeProvider");return t},Fk=(t,e=[])=>{const{addFrameListener:n,removeFrameListener:o}=g1();Qi.useEffect(()=>(n(t),()=>o(t)),[n,o,...e])},Ok={clickToInteractOverlay:100,htmlElements:95,orientationCube:95,contextMenu:90,appearanceMenu:91},v_t=({children:t,position:e,style:n})=>{const{camera:o,renderer:i}=g1(),r=ne.useRef(document.createElement("div")),[s,a]=ne.useState(null);return ne.useEffect(()=>{const c=i?.domElement.parentNode;if(c)return c.style.position!=="relative"&&c.style.position!=="absolute"&&(c.style.position="relative"),c.appendChild(r.current),a(NF.createPortal(t,r.current)),()=>{c.contains(r.current)&&c.removeChild(r.current)}},[i,t]),Fk(()=>{if(!o||!r.current||!i)return;const c=new Dt(...e);c.project(o);const l=i.domElement.getBoundingClientRect(),A=Math.round((c.x+1)/2*l.width),u=Math.round((-c.y+1)/2*l.height);r.current.style.position="absolute",r.current.style.left=`${A}px`,r.current.style.top=`${u}px`,r.current.style.pointerEvents="none",r.current.style.zIndex=Ok.htmlElements.toString(),n&&Object.assign(r.current.style,n)},[o,i,e,n]),s},B_t={in:25.4,inch:25.4,mil:.0254,mm:1,m:1e3,cm:10,ft:304.8,feet:304.8},Ma=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 B_t)return n*B_t[e];throw new Error(`Unsupported unit: ${e}`)},y_=Ma,FRn=Object.defineProperty,ORn=(t,e)=>{for(var n in e)FRn(t,n,{get:e[n],enumerable:!0})},qE={};ORn(qE,{axial:()=>gkn,bga:()=>yNn,breakoutheaders:()=>Mkn,cap:()=>jRn,dfn:()=>qNn,diode:()=>WRn,dip:()=>URn,electrolytic:()=>EFn,hc49:()=>Tkn,jst:()=>OLn,led:()=>XRn,lqfp:()=>vkn,m2host:()=>KFn,melf:()=>jHn,micromelf:()=>$Hn,minimelf:()=>OHn,mlp:()=>BNn,mountedpcbmodule:()=>jFn,ms012:()=>ikn,ms013:()=>skn,msop:()=>JLn,pad:()=>Qkn,pinrow:()=>ZNn,platedhole:()=>kFn,potentiometer:()=>xFn,pushbutton:()=>Ckn,qfn:()=>SNn,qfp:()=>vNn,quad:()=>D7,radial:()=>ykn,res:()=>gNn,sma:()=>nLn,smb:()=>ALn,smbf:()=>SFn,smc:()=>hLn,smf:()=>sLn,smtpad:()=>RFn,sod110:()=>zLn,sod123:()=>_kn,sod123f:()=>mHn,sod123fl:()=>yHn,sod123w:()=>Xkn,sod128:()=>vHn,sod323:()=>Zkn,sod323f:()=>uHn,sod323fl:()=>nFn,sod323w:()=>$Ln,sod523:()=>Fkn,sod723:()=>EHn,sod80:()=>Ykn,sod882:()=>aHn,sod882d:()=>VHn,sod923:()=>oHn,soic:()=>CNn,solderjumper:()=>uFn,son:()=>sFn,sop8:()=>Ukn,sot:()=>LFn,sot223:()=>fLn,sot23:()=>VNn,sot23w:()=>vLn,sot25:()=>jNn,sot323:()=>wFn,sot343:()=>zFn,sot363:()=>HNn,sot457:()=>hFn,sot563:()=>nkn,sot723:()=>ckn,sot886:()=>ONn,sot89:()=>NHn,sot963:()=>pFn,ssop:()=>DNn,stampboard:()=>Ekn,stampreceiver:()=>Pkn,to220:()=>K_t,to220f:()=>LHn,to92:()=>Hkn,to92l:()=>$Fn,to92s:()=>QLn,tqfp:()=>PNn,tssop:()=>RNn,vson:()=>cFn,vssop:()=>WLn});var ai=(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"}),ti=bt({norefdes:Je().optional().describe("disable reference designator label"),invert:Je().optional().describe("hint to invert the orientation of the 3D model"),faceup:Je().optional().describe("The male pin header should face upwards, out of the top layer"),nosilkscreen:Je().optional().describe("omit all silkscreen elements from the footprint")}),ns=(t,e,n,o,i)=>({pcb_plated_hole_id:"",type:"pcb_plated_hole",shape:"circle",x:e,y:n,hole_diameter:Ma(o),outer_diameter:Ma(i),pcb_port_id:"",layers:["top","bottom"],port_hints:[t.toString()]}),_C=t=>{const{pn:e,x:n,y:o,holeDiameter:i,rectPadWidth:r,rectPadHeight:s,holeOffsetX:a=0,holeOffsetY:c=0,rectBorderRadius:l}=t;return{pcb_plated_hole_id:"",type:"pcb_plated_hole",shape:"circular_hole_with_rect_pad",x:n,y:o,hole_diameter:Ma(i),hole_shape:"circle",pad_shape:"rect",rect_pad_width:Ma(r),rect_pad_height:Ma(s),...l!==void 0&&{rect_border_radius:l},pcb_port_id:"",layers:["top","bottom"],port_hints:[e.toString()],hole_offset_x:a,hole_offset_y:c}},kX=Array.from({length:9},(t,e)=>Math.cos(e/8*Math.PI-Math.PI)).map(t=>({x:t,y:-Math.sqrt(1-t**2)})),p1=t=>{if(t.length<2)throw new Error("Rect union outline requires at least two bounds");for(const l of t)if(l.minX>=l.maxX||l.minY>=l.maxY)throw new Error("Each rectangle bound must have min < max on both axes");for(let l=1;l<t.length;l++){const A=t[l-1],u=t[l];if(u.minX<A.minX||u.maxX>A.maxX||u.minY>A.minY||u.maxY<A.maxY)throw new Error("Bounds must be ordered outer-to-inner with tighter X and larger Y span")}const e=()=>{const l=[];let A=t.length-1;for(l.push({x:t[A].minX,y:t[A].maxY});A>0;){const u=t[A],_=t[A-1];l.push({x:u.minX,y:_.maxY}),l.push({x:_.minX,y:_.maxY}),A-=1}return l},n=()=>{const l=[];let A=t.length-1;for(l.push({x:t[A].maxX,y:t[A].maxY});A>0;){const u=t[A],_=t[A-1];l.push({x:u.maxX,y:_.maxY}),l.push({x:_.maxX,y:_.maxY}),A-=1}return l},o=()=>{const l=[];let A=t.length-1;for(l.push({x:t[A].maxX,y:t[A].minY});A>0;){const u=t[A],_=t[A-1];l.push({x:u.maxX,y:_.minY}),l.push({x:_.maxX,y:_.minY}),A-=1}return l},i=()=>{const l=[];let A=t.length-1;for(l.push({x:t[A].minX,y:t[A].minY});A>0;){const u=t[A],_=t[A-1];l.push({x:u.minX,y:_.minY}),l.push({x:_.minX,y:_.minY}),A-=1}return l},r=e(),s=n(),a=o(),c=i();return[...r.reverse(),...s,...a.reverse(),...c]};function H4(t){return typeof t=="string"?t.trim().toLowerCase().endsWith("mil")?parseFloat(t)*.0254:parseFloat(t):Number(t)}var HX=ho([j(),ut()]).transform(t=>H4(t)),GRn=t=>ti.extend({fn:j(),num_pins:ut().optional().default(6),wide:Je().optional(),narrow:Je().optional(),w:HX.optional(),p:HX.default(t.p??"2.54mm"),id:HX.optional(),od:HX.optional(),nosquareplating:Je().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=H4("0.55mm"),e.od=H4("0.95mm")):(e.id=H4("0.8mm"),e.od=H4("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=H4("600mil"):e.narrow?e.w=H4("300mil"):e.w=H4(t.w??"300mil")),e)),zRn=GRn({}),M_t=(t,e,n,o,i)=>{const r=t/2,s=e<=r,a=r-1,c=o,l=c*a;return s?{x:-n/2,y:l/2-(e-1)*c}:{x:n/2,y:-l/2+(e-r-1)*c}},URn=t=>{const e=zRn.parse(t),n=[];for(let g=0;g<e.num_pins;g++){const{x:y,y:f}=M_t(e.num_pins,g+1,e.w,e.p??2.54,e.nosquareplating);if(g===0&&!e.nosquareplating){n.push(_C({pn:g+1,x:y,y:f,holeDiameter:e.id??"0.8mm",rectPadWidth:e.od??"1mm",rectPadHeight:e.od??"1mm"}));continue}n.push(ns(g+1,y,f,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},...kX.map(({x:g,y})=>({x:g*r/6,y:y*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},c=[];for(let g=0;g<e.num_pins;g++){const y=g<e.num_pins/2,f=.6,{y:x}=M_t(e.num_pins,g+1,e.w,e.p??2.54,e.nosquareplating),I=y?-e.w/2-e.od/2-f:e.w/2+e.od/2+f,E=x;c.push({type:"pcb_fabrication_note_text",pcb_fabrication_note_text_id:`pin_${g+1}`,layer:"top",pcb_component_id:`pin_${g+1}`,text:`{pin${g+1}}`,anchor_position:{x:I,y:E},font_size:.3,font:"tscircuit2024",anchor_alignment:"top_left"})}const l=ai(0,s/2+.5,.4),A=e.w+e.od,u=o,_=A/2+.25,h=_,d=u/2+.72,m=d,p={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",outline:p1([{minX:-_,maxX:_,minY:-m,maxY:m},{minX:-h,maxX:h,minY:-d,maxY:d}]),layer:"top"};return{circuitJson:[...n,a,l,...c,p],parameters:e}},Bo=(t,e,n,o,i)=>({type:"pcb_smtpad",x:e,y:n,width:o,height:i,layer:"top",shape:"rect",pcb_smtpad_id:"",port_hints:Array.isArray(t)?t.map(r=>r.toString()):[t.toString()]}),w_t=[{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},{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},{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},{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},{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},{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},{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},{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}],VRn=Object.fromEntries(w_t.map(t=>[t.metric,t])),YRn=Object.fromEntries(w_t.map(t=>[t.imperial,t])),KRn=(t,e)=>({type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:0,y:0},width:t,height:e,layer:"top"});ti.extend({tht:Je(),p:_e.optional(),pw:_e.optional(),ph:_e.optional(),metric:nt.optional(),imperial:nt.optional(),w:_e.optional(),h:_e.optional(),textbottom:Je().optional()});var LX=t=>{let{tht:e,p:n,pw:o,ph:i,metric:r,imperial:s,w:a,h:c,textbottom:l}=t;if(typeof a=="string"&&(a=y_(a)),typeof c=="string"&&(c=y_(c)),typeof n=="string"&&(n=y_(n)),typeof o=="string"&&(o=y_(o)),typeof i=="string"&&(i=y_(i)),c!==void 0&&a!==void 0&&c>a)throw new Error("height cannot be greater than width (rotated footprint not yet implemented)");let A;if(r&&(A=VRn[r]),s&&(A=YRn[s]),A&&(a=A.w_mm_min,c=A.h_mm_min,n=A.p_mm_min,o=A.pw_mm_min,i=A.ph_mm_min),n===void 0||o===void 0||i===void 0)throw new Error("Could not determine required pad dimensions (p, pw, ph)");const u={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:n/2,y:i/2+.4},{x:-n/2-o/2-.2,y:i/2+.4},{x:-n/2-o/2-.2,y:-i/2-.4},{x:n/2,y:-i/2-.4}],stroke_width:.1,pcb_silkscreen_path_id:""},_=l?-i/2-.9:i/2+.9,h=ai(0,_,.2),d=A?.courtyard_width_mm&&A.courtyard_height_mm?KRn(A.courtyard_width_mm,A.courtyard_height_mm):null;return e?[ns(1,-n/2,0,o,o*1/.8),ns(2,n/2,0,o,o*1/.8),u,h,...d?[d]:[]]:[Bo(["1","left"],-n/2,0,o,i),Bo(["2","right"],n/2,0,o,i),u,h,...d?[d]:[]]},WRn=t=>({circuitJson:LX(t),parameters:t}),jRn=t=>({circuitJson:LX(t),parameters:t}),XRn=t=>({circuitJson:LX(t),parameters:t}),w7=t=>{const{padSpacing:e,padWidth:n,padHeight:o,padPitch:i,numRows:r,textbottom:s,courtyardOutline:a}=t,c=[],l=(r-1)*(i/2);for(let w=0;w<r;w++)c.push(l-w*i);const A=[];c.forEach((w,k)=>{A.push(Bo(k+1,-e/2,w,n,o))}),c.slice().reverse().forEach((w,k)=>{A.push(Bo(k+r+1,e/2,w,n,o))});const u=Math.max(...c)+o/2+.4,_=Math.min(...c)-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:u},{x:h*.5,y:u}],stroke_width:.12,pcb_silkscreen_path_id:"silkscreen_top"},p={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:d*.5,y:_},{x:h*.5,y:_}],stroke_width:.12,pcb_silkscreen_path_id:"silkscreen_bottom"},g=-e/2,y=Math.max(...c),f=.2,x=g-n/2-.1,I=y+o/2+.1,E={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"pin1_marker",route:[{x,y:I},{x:x-f,y:I},{x,y:I+f},{x,y:I}],stroke_width:.1},b=s?_-.9:u+.9,P=ai(0,b,.2),B=a?{type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",layer:"top",outline:a}:null;return[...A,m,p,E,P,...B?[B]:[]]},JRn=ti.extend({pw:_e.default("0.5mm"),ph:_e.default("0.4mm"),p:_e.default("0.7mm"),textbottom:Je().optional(),convex:Je().optional(),concave:Je().optional()}),qRn=1,$Rn=t=>{const e=JRn.parse(t);if(e.concave===!0)return[];const n=y_(e.pw),o=y_(e.ph),i=y_(e.p);return w7({padSpacing:qRn,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}]})},ZRn=ti.extend({pw:_e.default("0.5mm"),ph:_e.default("0.32mm"),p:_e.default("0.5mm"),textbottom:Je().optional(),convex:Je().optional(),concave:Je().optional()}),eNn=1,tNn=t=>{const e=ZRn.parse(t),n=y_(e.pw),o=y_(e.ph),i=y_(e.p);return w7({padSpacing:eNn,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}]})},nNn=ti.extend({pw:_e.default("0.9mm"),ph:_e.default("0.4mm"),p:_e.default("0.8mm"),textbottom:Je().optional(),convex:Je().optional(),concave:Je().optional()}),oNn=1.7,iNn=t=>{const e=nNn.parse(t),n=y_(e.pw),o=y_(e.ph),i=y_(e.p);return w7({padSpacing:oNn,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}]})},rNn=ti.extend({pw:_e.default("0.9mm"),ph:_e.default("0.4mm"),p:_e.default("0.8mm"),textbottom:Je().optional(),convex:Je().optional(),concave:Je().optional()}),sNn=1.7,aNn=t=>{const e=rNn.parse(t),n=y_(e.pw),o=y_(e.ph),i=y_(e.p);return w7({padSpacing:sNn,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}]})},cNn=ti.extend({pw:_e.default("0.7mm"),ph:_e.default("0.64mm"),p:_e.default("0.94mm"),textbottom:Je().optional(),convex:Je().optional(),concave:Je().optional()}),lNn=1.4,ANn=t=>{const e=cNn.parse(t),n=y_(e.pw),o=y_(e.ph),i=y_(e.p);return w7({padSpacing:lNn,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}]})},uNn=ti.extend({pw:_e.default("0.9mm"),ph:_e.default("0.9mm"),p:_e.default("1.34mm"),textbottom:Je().optional(),convex:Je().optional(),concave:Je().optional()}),_Nn=3,dNn=t=>{const e=uNn.parse(t),n=y_(e.pw),o=y_(e.ph),i=y_(e.p);return w7({padSpacing:_Nn,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}]})},hNn=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)}},mNn=t=>t?(typeof t=="number"?`${t}`:t).split(/[_x]/)[0]:void 0,gNn=t=>{const e=hNn(t),n=mNn(t.imperial);return e===2&&n==="0402"?{circuitJson:$Rn(t),parameters:t}:e===4&&n==="0402"?{circuitJson:tNn(t),parameters:t}:e===2&&n==="0603"?{circuitJson:iNn(t),parameters:t}:e===4&&n==="0603"?{circuitJson:aNn(t),parameters:t}:e===2&&n==="0606"?{circuitJson:ANn(t),parameters:t}:e===4&&n==="1206"?{circuitJson:dNn(t),parameters:t}:{circuitJson:LX(t),parameters:t}},D_t=(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()]}),T_t="ABCDEFGHIJKLMNOPQRSTUVWXYZ",FX=j().transform(t=>{const[e,n]=t.split(/[x ]/);return{x:parseFloat(e??""),y:parseFloat(n??"")}}).pipe(bt({x:ut(),y:ut()})),pNn=j().or($t(ou())).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($t(j().or(ut()))),fNn=ti.extend({fn:j(),num_pins:ut().optional().default(64),grid:FX.optional(),p:nt.default("0.8mm"),w:_e.optional(),h:_e.optional(),ball:_e.optional().describe("ball diameter"),pad:_e.optional().describe("pad width/height"),circularpads:Je().optional().describe("use circular pads"),tlorigin:Je().optional(),blorigin:Je().optional(),trorigin:Je().optional(),brorigin:Je().optional(),missing:pNn.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=T_t.indexOf(i[1]),s=Number.parseInt(i[2])-1;return r*t.grid.x+s+1})),{...t,origin:e}}),yNn=t=>{const e=fNn.parse(t);let{num_pins:n,grid:o,p:i,w:r,h:s,ball:a,pad:c,missing:l}=e;a??=.75/1.27*i,c??=a*.8;const A=[],u=(l??[]).filter($=>typeof $=="number"),_=o.x*o.y-n;if(l.length===0&&_>0&&(Math.sqrt(_)%1===0?l.push("center"):_===1&&l.push("topleft")),l?.includes("center")){const $=Math.floor(Math.sqrt(_)),oe=Math.floor((o.x-$)/2),Ae=Math.floor((o.y-$)/2);for(let Z=Ae;Z<Ae+$;Z++)for(let se=oe;se<oe+$;se++)u.push(Z*o.x+se+1)}l?.includes("topleft")&&u.push(1);const h=new Set(u);let d=0;for(let $=0;$<o.y;$++)for(let oe=0;oe<o.x;oe++){const Ae=(oe-(o.x-1)/2)*i,Z=($-(o.y-1)/2)*i;let se=oe,ae=$;switch(e.origin){case"bl":se=oe,ae=o.y-1-$;break;case"br":se=o.x-1-oe,ae=o.y-1-$;break;case"tr":se=o.x-1-oe,ae=$;break}let ce=ae*o.x+se+1;if(h.has(ce)){d++;continue}ce-=d;const ge=[ce,`${T_t[ae]}${se+1}`];A.push(e.circularpads?D_t(ge,{x:Ae,y:Z,radius:c/2}):Bo(ge,Ae,Z,c,c))}const m=ai(0,o.y*i/2,.2),p=i/6;let g;const y=o.x*i/2,f=o.y*i/2;switch(e.origin){case"bl":g=[{x:-y,y:-f},{x:-y,y:-f-p},{x:-y-p,y:-f},{x:-y,y:-f}];break;case"br":g=[{x:y,y:-f},{x:y,y:-f-p},{x:y+p,y:-f},{x:y,y:-f}];break;case"tr":g=[{x:y,y:f},{x:y,y:f+p},{x:y+p,y:f},{x:y,y:f}];break;default:g=[{x:-y,y:f},{x:-y,y:f+p},{x:-y-p,y:f},{x:-y,y:f}];break}const x={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"pin1_marker",route:g,stroke_width:.05},I=(o.x-1)*i+c,E=(o.y-1)*i+c,b=r??I,P=s??E,B=Math.max(I/2,b/2),w=Math.max(E/2,P/2),k=1.715,N=1.765,F=B+k,O=F,G=w+N,K=G,X={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",outline:p1([{minX:-F,maxX:F,minY:-K,maxY:K},{minX:-O,maxX:O,minY:-G,maxY:G}]),layer:"top"};return{circuitJson:[...A,m,x,X],parameters:e}},OX=(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()]}),mB=t=>ti.extend({fn:j(),num_pins:ut().optional().default(8),w:_e.default(_e.parse(t.w??"5.3mm")),p:_e.default(_e.parse(t.p??"1.27mm")),pw:_e.default(_e.parse(t.pw??"0.6mm")),pl:_e.default(_e.parse(t.pl??"1.0mm")),legsoutside:Je().optional().default(t.legsoutside??!1),pillpads:Je().optional().default(t.pillpads??!1),silkscreen_stroke_width:ut().optional().default(.1)}).transform(e=>(!e.pw&&!e.pl?(e.pw=_e.parse("0.6mm"),e.pl=_e.parse("1.0mm")):e.pw?e.pl||(e.pl=e.pw*(1/.6)):e.pw=e.pl*(.6/1),e)),xNn=mB({}),c5e=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,c=n<=a,l=a-1,A=i,u=A*l,_=s?r/2:-r/2;return c?{x:-o/2-_,y:u/2-(n-1)*A}:{x:o/2+_,y:-u/2+(n-a-1)*A}},CNn=t=>{const e=xNn.parse(t);return{circuitJson:Gk(e),parameters:e}},Gk=t=>{const e=[];let n=0,o=0;for(let p=0;p<t.num_pins;p++){const{x:g,y}=c5e({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(g)+t.pl/2),o=Math.max(o,Math.abs(y)+t.pw/2),t.pillpads?e.push(OX(p+1,g,y,t.pl,t.pw)):e.push(Bo(p+1,g,y,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=ai(0,s/2+.4,s/12),c={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},...kX.map(({x:p,y:g})=>({x:p*r/6,y:g*r/6+s/2})),{x:r/2,y:s/2},{x:r/2,y:-s/2},{x:-r/2,y:-s/2}]},l=t.w/2,A=s/2,u=Math.max(n,l)+.25,_=Math.min(o,A)+.25,h=Math.min(n,l)+.25,d=Math.max(o,A)+.25,m={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",layer:"top",outline:p1([{minX:-u,maxX:u,minY:-_,maxY:_},{minX:-h,maxX:h,minY:-d,maxY:d}])};return[...e,c,a,m]},Q_t=Nn(["leftside","topside","rightside","bottomside","toppin","bottompin","leftpin","rightpin"]),INn=({num_pins:t,cw:e,ccw:n,startingpin:o})=>{const i=[],r=t/4;let s=1;const a={};for(const c of o??[])a[c]=!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 c=0;c<t;c++)i[s]=c+1,n||!e?(s++,s>t&&(s=1)):(s--,s<1&&(s=t));return i},l5e=ti.extend({fn:j(),cc:Je().default(!0).optional(),ccw:Je().default(!0).optional(),startingpin:j().or($t(Q_t)).transform(t=>typeof t=="string"?t.slice(1,-1).split(","):t).pipe($t(Q_t)).optional(),num_pins:ut().optional().default(64),w:_e.optional(),h:_e.optional(),p:_e.default(_e.parse("0.5mm")),pw:_e.optional(),pl:_e.optional(),thermalpad:ho([tt(!0),FX]).optional(),legsoutside:Je().default(!1)}),A5e=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},R_t=l5e.transform(A5e),ENn=["left","bottom","right","top"],bNn=t=>{const{pin_count:e,pn:n,w:o,h:i,p:r,pl:s,legsoutside:a}=t,c=e/4,l=ENn[Math.floor((n-1)/c)],A=(n-1)%c,u=r*(c-1),_=r*(c-1),h=a?s/2:-s/2;switch(l){case"left":return{x:-o/2-h+.1,y:_/2-A*r,o:"vert"};case"bottom":return{x:-u/2+A*r,y:-i/2-h+.1,o:"horz"};case"right":return{x:o/2+h-.1,y:-_/2+A*r,o:"vert"};case"top":return{x:u/2-A*r,y:i/2+h-.1,o:"horz"};default:throw new Error("Invalid pin number")}},D7=t=>{const e=R_t.parse(t),n=[];let o=0,i=0;const r=INn(e),s=e.num_pins/4;for(let f=0;f<e.num_pins;f++){const{x,y:I,o:E}=bNn({pin_count:e.num_pins,pn:f+1,w:e.w,h:e.h,p:e.p??.5,pl:e.pl,legsoutside:e.legsoutside});let b=e.pw,P=e.pl;E==="vert"&&([b,P]=[P,b]);const B=r[f+1];o=Math.max(o,Math.abs(x)+b/2),i=Math.max(i,Math.abs(I)+P/2),n.push(Bo(B,x,I,b,P))}if(e.thermalpad)if(typeof e.thermalpad=="boolean"){const f=e.p*(s-1)+e.pw,x=e.p*(s-1)+e.pw;o=Math.max(o,f/2),i=Math.max(i,x/2),n.push(Bo(["thermalpad"],0,0,f,x))}else o=Math.max(o,e.thermalpad.x/2),i=Math.max(i,e.thermalpad.y/2),n.push(Bo(["thermalpad"],0,0,e.thermalpad.x,e.thermalpad.y));const a=[];for(const[f,x,I]of[["top-left",-1,1],["bottom-left",-1,-1],["bottom-right",1,-1],["top-right",1,1]]){const E=e.w/2*x,b=e.h/2*I;let P="none",B=E,w=b;const k=e.pw*2;r[1]===1&&f==="top-left"?P="in1":r[s*4]===1&&f==="top-left"||r[s*3+1]===1&&f==="top-right"?P="in2":r[s*3]===1&&f==="top-right"||r[s]===1&&f==="bottom-left"?P="in1":r[s+1]===1&&f==="bottom-left"?P="in2":r[s*2]===1&&f==="bottom-right"?P="in1":r[s*2+1]===1&&f==="bottom-right"&&(P="in2");const N=P==="in1"?1:-1;if(e.legsoutside){const F=P==="in1"?e.pl/2:e.pw/2,O=P==="in1"?e.pw/2:e.pl/2;B+=F*x*N,w-=O*I*N}(P==="none"||e.legsoutside)&&a.push({layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:`pcb_silkscreen_path_${f}`,route:[{x:E-k*x,y:b},{x:E,y:b},{x:E,y:b-k*I}],type:"pcb_silkscreen_path",stroke_width:.1}),(P==="in1"||P==="in2")&&!e.legsoutside&&a.push({layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:`pcb_silkscreen_path_${f}_1`,route:[{x:E-k*x,y:b},{x:E-k*x/2,y:b}],type:"pcb_silkscreen_path",stroke_width:0},{layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:`pcb_silkscreen_path_${f}_2`,route:[{x:E,y:b-k*I/2},{x:E,y:b-k*I}],type:"pcb_silkscreen_path",stroke_width:.1}),(P==="in1"||P==="in2")&&a.push({layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:`pcb_silkscreen_path_${f}_3`,route:[{x:B-.2*-x,y:w+.2*N},{x:B,y:w},{x:B+.2*N*-x,y:w+.2},{x:B-.2*-x,y:w+.2*N}],type:"pcb_silkscreen_path",stroke_width:.1})}const c=ai(0,e.h/2+(e.legsoutside?e.pl*1.2:.5),.3),l=f=>Math.ceil(f/.05)*.05,A=(s-1)*e.p+e.pw,u=(s-1)*e.p+e.pw,_=A/2+.25,h=u/2+.25,d=e.w/2+.25,m=e.h/2+.25,p=Math.max(d,l(o+.25)),g=Math.max(m,l(i+.25)),y={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",layer:"top",outline:p1([{minX:-p,maxX:p,minY:-h,maxY:h},{minX:-d,maxX:d,minY:-m,maxY:m},{minX:-_,maxX:_,minY:-g,maxY:g}])};return{circuitJson:[...n,...a,c,y],parameters:e}};l5e.extend({}).transform(A5e);var SNn=t=>(t.legsoutside=!1,t.pl||(t.pl=.875),t.pw||(t.pw=.25),D7(t)),PNn=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 D7(t)},vNn=t=>{t.legsoutside=!0;const e=R_t.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 D7(t)};l5e.extend({}).transform(A5e);var BNn=t=>(t.legsoutside=!1,t.thermalpad===void 0&&(t.thermalpad=!0),D7(t)),MNn=ti.extend({fn:j(),num_pins:ut().optional().default(8),w:_e.default(_e.parse("3.9mm")),p:_e.default(_e.parse("1.27mm")),pw:_e.optional(),pl:_e.optional(),legsoutside:Je().optional().default(!1),silkscreen_stroke_width:ut().optional().default(.1)}).transform(t=>(t.pw==null&&t.pl==null?(t.pw=_e.parse("0.51mm"),t.pl=_e.parse("1.1mm")):t.pw==null?t.pw=t.pl*(.51/1.1):t.pl==null&&(t.pl=t.pw*(1.1/.51)),t)),wNn=t=>{const{num_pins:e,pn:n,w:o,p:i}=t,r=e/2,s=n<=r,a=r-1,c=i,l=c*a,A=o+_e.parse("0.2mm"),u=(s?-1:1)*(A/2);return s?{x:u,y:l/2-(n-1)*c}:{x:u,y:-l/2+(n-r-1)*c}},DNn=t=>{const e=MNn.parse(t),n=[];for(let p=0;p<e.num_pins;p++){const{x:g,y}=wNn({num_pins:e.num_pins,pn:p+1,w:e.w,p:e.p,pl:e.pl,legsoutside:e.legsoutside});n.push(Bo(p+1,g,y,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=ai(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},...kX.map(({x:p,y:g})=>({x:p*i/6,y:g*i/6+r/2})),{x:i/2,y:r/2},{x:i/2,y:-r/2},{x:-i/2,y:-r/2}]},c=(e.num_pins/2-1)*e.p+e.pw,l=e.legsoutside?e.w/2+e.pl:(e.w+.2)/2+e.pl/2,A=c/2,u=l+.25,_=u,h=A+.445,d=h,m={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",outline:p1([{minX:-u,maxX:u,minY:-d,maxY:d},{minX:-_,maxX:_,minY:-h,maxY:h}]),layer:"top"};return{circuitJson:[...n,a,s,m],parameters:e}},TNn=ti.extend({fn:j(),num_pins:ut().optional().default(8),w:_e.default(_e.parse("3.0mm")),p:_e.default(_e.parse("0.5mm")),pw:_e.default(_e.parse("0.30mm")),pl:_e.default(_e.parse("1.45mm")),legsoutside:Je().optional().default(!0),silkscreen_stroke_width:ut().optional().default(.1)}),QNn=t=>{const{num_pins:e,pn:n,w:o,p:i,pl:r,legsoutside:s}=t,a=e/2,c=n<=a,l=a-1,A=i*l,u=s?r/2:-r/2;return c?{x:-o/2-u,y:A/2-(n-1)*i}:{x:o/2+u,y:-A/2+(n-a-1)*i}},RNn=t=>{const e={...t},n=e.p,o=typeof n=="string"||typeof n=="number"?_e.parse(n):void 0,i=o!=null&&o<=_e.parse("0.5mm"),r=TNn.parse(e),s=[],a=i?r.w-_e.parse("0.15mm"):r.w;for(let x=0;x<r.num_pins;x++){const{x:I,y:E}=QNn({num_pins:r.num_pins,pn:x+1,w:a,p:r.p,pl:r.pl,legsoutside:r.legsoutside});s.push(Bo(x+1,I,E,r.pl,r.pw))}const c=Math.min(1,r.p/2),l=r.w-(r.legsoutside?0:r.pl*2)-.2,A=(r.num_pins/2-1)*r.p+r.pw+c,u=ai(0,A/2+.4,A/12),_={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:-l/2,y:-A/2},{x:-l/2,y:A/2},...kX.map(({x,y:I})=>({x:x*l/6,y:I*l/6+A/2})),{x:l/2,y:A/2},{x:l/2,y:-A/2},{x:-l/2,y:-A/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,g=h/2+.25,y=g+.35,f={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",layer:"top",outline:p1([{minX:-p,maxX:p,minY:-g,maxY:g},{minX:-m,maxX:m,minY:-y,maxY:y}])};return{circuitJson:[...s,_,u,f],parameters:r}},NNn=[{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}],kNn=ti.extend({fn:j(),num_pins:tt(6).default(6),w:j().default("3.1mm"),h:j().default("2.0mm"),p:j().default("0.65mm"),pl:j().default("1.03mm"),pw:j().default("0.35mm"),string:j().optional()}),HNn=t=>{const e=kNn.parse({...t,fn:"sot363"}),n=_e.parse(e.w),o=_e.parse(e.h),i=_e.parse(e.p),r=_e.parse(e.pl),s=_e.parse(e.pw),a=[];for(let d=0;d<6;d++){const{x:m,y:p}=N_t(d+1,n,i);a.push(Bo(d+1,m,p,r,s))}const 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={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:""},A=N_t(1,n,i),u={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"pin_marker_1",route:[{x:A.x-r/2-.3,y:A.y},{x:A.x-r/2-.45,y:A.y+.15},{x:A.x-r/2-.45,y:A.y-.15},{x:A.x-r/2-.3,y:A.y}],stroke_width:.05,pcb_silkscreen_path_id:"pin_marker_1"},_=ai(0,o/2+.4,.25),h={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",outline:NNn,layer:"top"};return{circuitJson:[...a,c,l,_,u,h],parameters:e}},N_t=(t,e,n,o)=>t<=3?{x:-.84,y:n-(t-1)*n}:{x:.84,y:-n+(t-4)*n},LNn=[{x:-.75,y:1},{x:-.75,y:-1},{x:.75,y:-1},{x:.75,y:1}],FNn=ti.extend({fn:j(),num_pins:tt(6).default(6),w:j().default("1.01mm"),h:j().default("1.45mm"),p:j().default("0.5mm"),pl:j().default("0.33mm"),pw:j().default("0.27mm"),string:j().optional()}),ONn=t=>{const e=FNn.parse({...t,fn:"sot886"}),n=_e.parse(e.w),o=_e.parse(e.h),i=_e.parse(e.p),r=_e.parse(e.pl),s=_e.parse(e.pw),a=[];for(let d=0;d<6;d++){const{x:m,y:p}=k_t(d+1,n,i,r);a.push(Bo(d+1,m,p,r,s))}const 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={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:""},A=k_t(1,n,i,r),u={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"pin_marker_1",route:[{x:A.x-r/2-.3,y:A.y},{x:A.x-r/2-.45,y:A.y+.15},{x:A.x-r/2-.45,y:A.y-.15},{x:A.x-r/2-.3,y:A.y}],stroke_width:.05,pcb_silkscreen_path_id:"pin_marker_1"},_=ai(0,o/2+.4,.25),h={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",outline:LNn,layer:"top"};return{circuitJson:[...a,c,l,_,u,h],parameters:e}},k_t=(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}},GNn=[{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}],zNn=[{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}],H_t=ti.extend({fn:j(),num_pins:ut().default(3),w:j().default("1.92mm"),h:j().default("2.74mm"),pl:j().default("1.325mm"),pw:j().default("0.6mm"),p:j().default("0.95mm"),string:j().optional()}),UNn=mB({p:"0.95mm",w:"1.6mm",legsoutside:!0}),VNn=t=>{const e=t.string?.match(/^sot23_(\d+)/),n=e?Number.parseInt(e[1],10):3;if(n===6||n===8){const i=UNn.parse({...t,num_pins:n});return{circuitJson:Gk(i),parameters:i}}const o=H_t.parse({...t,num_pins:n});if(o.num_pins===3)return{circuitJson:KNn(o),parameters:o};if(o.num_pins===5)return{circuitJson:F_t(o),parameters:o};throw new Error("Invalid number of pins")},YNn=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}},KNn=t=>{const e=[];for(let i=0;i<t.num_pins;i++){const{x:r,y:s}=YNn({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(Bo(i+1,r,s,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}const n=ai(0,Number.parseInt(t.h),.3),o={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",outline:GNn,layer:"top"};return[...e,n,o]},L_t=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")},F_t=t=>{const e=[];for(let _=1;_<=t.num_pins;_++){const{x:h,y:d}=L_t({h:Number.parseFloat(t.h),p:Number.parseFloat(t.p),pn:_});e.push(Bo(_,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=ai(0,o+.3,.3),a=L_t({h:Number.parseFloat(t.h),p:Number.parseFloat(t.p),pn:1});a.x=a.x-Number.parseFloat(t.pw)*1.5;const c=.3,l=.4,A={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"pin1_indicator",route:[{x:a.x+c/2,y:a.y},{x:a.x-c/2,y:a.y+l/2},{x:a.x-c/2,y:a.y-l/2},{x:a.x+c/2,y:a.y}],stroke_width:.05},u={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",outline:zNn,layer:"top"};return[...e,s,i,r,A,u]},WNn=H_t.extend({}),jNn=t=>{const e=WNn.parse({...t,num_pins:5});return{circuitJson:F_t(e),parameters:e}},XNn=[{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}],JNn=mB({}),qNn=t=>{const e=JNn.parse(t),n=[];for(let p=0;p<e.num_pins;p++){const{x:g,y}=c5e({num_pins:e.num_pins,pn:p+1,w:e.w,p:e.p??1.27,pl:e.pl,widthincludeslegs:!0});n.push(Bo(p+1,g,y,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 XNn){const{dx:g,dy:y}=p;s.push({layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"",route:[{x:g*i/2-g*e.p,y:y*r/2},{x:g*i/2,y:y*r/2},{x:g*i/2,y:y*r/2-y*e.p}],type:"pcb_silkscreen_path",stroke_width:.1})}const a=e.p/4,c=-i/2-a/2,l=r/2-e.p/2;s.push({layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"",type:"pcb_silkscreen_path",route:[{x:c,y:l},{x:c-a,y:l+a},{x:c-a,y:l-a},{x:c,y:l}],stroke_width:.1});const A=ai(0,r/2+.4,r/12),u=p=>Math.ceil(p/.05)*.05,_=(e.num_pins/2-1)*e.p+e.pw,h=u(e.w/2+.25),d=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,A,...s,m],parameters:e}},gB=({fs:t,pn:e,anchor_x:n,anchor_y:o,textalign:i="center",orthogonal:r=!1,verticallyinverted:s=!1,layer:a="top"})=>{let c=0;r&&s?c=270:s?c=180:r?c=90:c=0;let l="center";return i==="left"&&(s?l="center_right":l="center_left"),i==="right"&&(s?l="center_left":l="center_right"),a==="bottom"&&(l==="center_left"?l="center_right":l==="center_right"&&(l="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:l,ccw_rotation:c}};function O_t({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 $Nn=ti.extend({fn:j(),num_pins:ut().optional().default(6),rows:ho([j(),ut()]).transform(t=>Number(t)).optional().default(1).describe("number of rows"),p:_e.default("0.1in").describe("pitch"),id:_e.default("1.0mm").describe("inner diameter"),od:_e.default("1.5mm").describe("outer diameter"),male:Je().optional().describe("for male pin headers"),female:Je().optional().describe("for female pin headers"),smd:Je().optional().describe("surface mount device"),surfacemount:Je().optional().describe("surface mount device (verbose)"),rightangle:Je().optional().describe("right angle"),pw:_e.optional().default("1.0mm").describe("pad width for SMD"),pl:_e.optional().default("2.0mm").describe("pad length for SMD"),pinlabeltextalignleft:Je().optional().default(!1),pinlabeltextaligncenter:Je().optional().default(!1),pinlabeltextalignright:Je().optional().default(!1),pinlabelverticallyinverted:Je().optional().default(!1),pinlabelorthogonal:Je().optional().default(!1),nosquareplating:Je().optional().default(!1).describe("do not use rectangular pad for pin 1"),nopinlabels:Je().optional().default(!1).describe("omit silkscreen pin labels"),doublesidedpinlabel:Je().optional().default(!1).describe("add silkscreen pins in top and bottom layers"),bottomsidepinlabel:Je().optional().default(!1).describe("place the silkscreen reference text on the bottom layer instead of top")}).transform(t=>{const e=O_t(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:_o.custom,message:"'male' and 'female' cannot both be true; it should be male or female.",path:["male","female"]})}),ZNn=t=>{const e=$Nn.parse(t),{p:n,id:o,od:i,rows:r,num_pins:s,pinlabelAnchorSide:a,pinlabelverticallyinverted:c,pinlabelorthogonal:l,pinlabeltextalignleft:A,pinlabeltextalignright:u,nopinlabels:_,doublesidedpinlabel:h,bottomsidepinlabel:d}=e;let m="center";A?m="left":u&&(m="right");const p=[],g=Math.ceil(s/r),y=(r-1)*n,f=y/2,x=-n,I=({xoff:Ae,yoff:Z,od:se,anchorSide:ae,smd:ce,pw:ge,pl:be})=>{let ve=0,Me=0;if(ce){const ue=se/5;switch(ae){case"right":ve=ge/2+ue;break;case"top":Me=be/2+ue;break;case"bottom":Me=-(be/2+ue);break;case"left":ve=-(ge/2+ue);break}}else{const ue=se*.75;switch(ae){case"right":ve=ue;break;case"top":Me=ue;break;case"bottom":Me=-ue;break;case"left":ve=-ue;break}}return{anchor_x:Ae+ve,anchor_y:Z+Me}},E=(Ae,Z,se)=>{e.smd?p.push(Bo(Ae,Z,se,e.pw,e.pl)):Ae===1&&!e.nosquareplating?p.push(_C({pn:Ae,x:Z,y:se,holeDiameter:o,rectPadWidth:i,rectPadHeight:i})):p.push(ns(Ae,Z,se,o,i));const{anchor_x:ae,anchor_y:ce}=I({xoff:Z,yoff:se,od:i,anchorSide:a,smd:e.smd,pw:e.pw,pl:e.pl});_||(d?p.push(gB({fs:i/5,pn:Ae,anchor_x:ae,anchor_y:ce,textalign:m,orthogonal:l,verticallyinverted:c,layer:"bottom"})):p.push(gB({fs:i/5,pn:Ae,anchor_x:ae,anchor_y:ce,textalign:m,orthogonal:l,verticallyinverted:c,layer:"top"})),h&&p.push(gB({fs:i/5,pn:Ae,anchor_x:ae,anchor_y:ce,textalign:m,orthogonal:l,verticallyinverted:c,layer:"bottom"})))},b=new Set,P=r>2&&g>2;if(r===1){const Ae=-((s-1)/2)*n;for(let Z=0;Z<s;Z++){const se=Z+1,ae=Ae+Z*n,ce=`${ae},0`;if(b.has(ce))throw new Error(`Overlap at ${ce}`);b.add(ce),E(se,ae,0)}}else if(P){const Ae=-((g-1)/2)*n;let Z=1;for(let se=0;se<r&&Z<=s;se++)for(let ae=0;ae<g&&Z<=s;ae++){const ce=Ae+ae*n,ge=f+se*x,be=`${ce},${ge}`;if(b.has(be))throw new Error(`Overlap at ${be}`);b.add(be),E(Z++,ce,ge)}}else{const Ae=-((g-1)/2)*n;let Z=1,se=0,ae=r-1,ce=0,ge=g-1;for(;Z<=s&&se<=ae&&ce<=ge;){for(let be=se;be<=ae&&Z<=s;be++){const ve=Ae+ce*n,Me=f+be*x,ue=`${ve},${Me}`;if(b.has(ue))throw new Error(`Overlap at ${ue}`);b.add(ue),E(Z++,ve,Me)}ce++;for(let be=ce;be<=ge&&Z<=s;be++){const ve=Ae+be*n,Me=f+ae*x,ue=`${ve},${Me}`;if(b.has(ue))throw new Error(`Overlap at ${ue}`);b.add(ue),E(Z++,ve,Me)}if(ae--,ce<=ge){for(let be=ae;be>=se&&Z<=s;be--){const ve=Ae+ge*n,Me=f+be*x,ue=`${ve},${Me}`;if(b.has(ue))throw new Error(`Overlap at ${ue}`);b.add(ue),E(Z++,ve,Me)}ge--}if(se<=ae){for(let be=ge;be>=ce&&Z<=s;be--){const ve=Ae+be*n,Me=f+se*x,ue=`${ve},${Me}`;if(b.has(ue))throw new Error(`Overlap at ${ue}`);b.add(ue),E(Z++,ve,Me)}se++}}if(Z-1<s)throw new Error(`Missing pins: assigned ${Z-1}, expected ${s}`)}const B=ai(0,y/2+n,.5),w=e.smd?e.pw/2:i/2,k=e.smd?e.pl/2:i/2,N=(g-1)*n,F=N/2+w,O=y/2+k,G=N/2+n/2,K=y/2+n/2,X=Math.max(F+.25,G+.5),$=Math.max(O+.25,K+.5),oe={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:0,y:0},width:2*X,height:2*$,layer:"top"};return{circuitJson:[...p,B,oe],parameters:e}},ekn=[{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}],tkn=ti.extend({fn:j(),num_pins:tt(6).default(6),w:j().default("2.1mm"),h:j().default("2.45mm"),p:j().default("0.5mm"),pl:j().default("0.675mm"),pw:j().default("0.35mm"),string:j().optional()}),nkn=t=>{const e=tkn.parse({...t,fn:"sot563"}),n=_e.parse(e.w),o=_e.parse(e.h),i=_e.parse(e.p),r=_e.parse(e.pl),s=_e.parse(e.pw),a=[];for(let d=0;d<6;d++){const{x:m,y:p}=G_t(d+1,n,i,r);a.push(Bo(d+1,m,p,r,s))}const 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={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:""},A=G_t(1,n,i,r),u={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"pin_marker_1",route:[{x:A.x-r/2-.3,y:A.y},{x:A.x-r/2-.45,y:A.y+.15},{x:A.x-r/2-.45,y:A.y-.15},{x:A.x-r/2-.3,y:A.y}],stroke_width:.05,pcb_silkscreen_path_id:"pin_marker_1"},_=ai(0,o/2+.4,.25),h={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",outline:ekn,layer:"top"};return{circuitJson:[...a,c,l,_,u,h],parameters:e}},G_t=(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}},okn=mB({p:"1.27mm",w:"3.9mm",legsoutside:!0}),ikn=t=>{const e=okn.parse({...t,num_pins:8});return{circuitJson:Gk(e),parameters:e}},rkn=mB({p:"1.27mm",w:"7.5mm",legsoutside:!0}),skn=t=>{const e=rkn.parse({...t,num_pins:16});return{circuitJson:Gk(e),parameters:e}},akn=ti.extend({fn:j(),num_pins:tt(3).default(3),w:j().default("1.2mm"),h:j().default("1.2mm"),pw:j().default("0.40mm"),pl:j().default("0.45mm"),p:j().default("0.575mm")}),ckn=t=>{const e=akn.parse(t),n=Akn(e),o=ai(0,_e.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}},lkn=t=>{const{pn:e,p:n}=t;return e===1?{x:n,y:0}:e===2?{x:-n,y:-.4}:{x:-n,y:.4}},Akn=t=>{const e=[];for(let n=0;n<3;n++){const{x:o,y:i}=lkn({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(Bo(n+1,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return e},ukn=ti.extend({fn:j(),num_pins:tt(2).default(2),w:j().default("2.36mm"),h:j().default("1.22mm"),pl:j().default("0.9mm"),pw:j().default("1.2mm"),p:j().default("3.30mm")}),_kn=t=>{const e=ukn.parse(t),n=ai(0,_e.parse(e.h)/4+.4,.3),r={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:hkn(e).concat(n,r),parameters:e}},dkn=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},hkn=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=dkn({pn:n,p:Number.parseFloat(t.p)});e.push(Bo(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return e},mkn=ti.extend({fn:j(),p:_e.optional().default("2.54mm"),id:_e.optional().default("0.7mm"),od:_e.optional().default("1.4mm")}),gkn=t=>{const e=mkn.parse(t),{p:n,id:o,od:i}=e,r=[ns(1,-n/2,0,o,i),ns(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=ai(0,1.5,.5),c=-n/2,l=n/2,A=i/2,u=i/2,_=c-A-.35,h=l+A+.26,d=u+.35,m=_,p=h,g=d,y={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",outline:p1([{minX:_,maxX:h,minY:-g,maxY:g},{minX:m,maxX:p,minY:-d,maxY:d}]),layer:"top"};return{circuitJson:[...r,s,a,y],parameters:e}},pkn=(t,e,n,o,i,r=.1)=>{const s=[],a=[],c=Math.max(1,Math.ceil(Math.PI*n/r)),l=Math.PI/c;for(let A=0;A<=c;A++){const u=A*l,_=t+Math.cos(u)*n,h=e+Math.sin(u)*n;_<t-o&&h>=e-i/2&&h<=e+i/2||s.push({x:_,y:h})}for(let A=0;A<=c;A++){const u=Math.PI+A*l,_=t+Math.cos(u)*n,h=e+Math.sin(u)*n;_<t-o&&h>=e-i/2&&h<=e+i/2||a.push({x:_,y:h})}return{topArc:s,bottomArc:a}},fkn=ti.extend({fn:j(),p:_e.optional().default("5mm"),id:_e.optional().default("0.8mm"),od:_e.optional().default("1.6mm"),ceramic:Je().optional(),electrolytic:Je().optional(),polarized:Je().optional()}),ykn=t=>{const e=fkn.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=[ns(1,-n/2,0,e.id,e.od),ns(2,n/2,0,e.id,e.od)],s=n+.1,{topArc:a,bottomArc:c}=pkn(0,0,s,e.od/2,e.od),l=.02*n,A={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:a,stroke_width:l,pcb_silkscreen_path_id:""},u={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:c,stroke_width:l,pcb_silkscreen_path_id:""},_={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:0,y:s},{x:0,y:-s}],stroke_width:l,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:l,pcb_silkscreen_path_id:""},g={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:d,y:m-h},{x:d,y:m+h}],stroke_width:l,pcb_silkscreen_path_id:""},y=ai(0,s+.12*n,.1*n),f=[...r,A,u,_,y];(e.electrolytic===!0||e.polarized===!0)&&f.push(p,g);const I=n+.25,E={type:"pcb_courtyard_circle",pcb_courtyard_circle_id:"",pcb_component_id:"",center:{x:0,y:0},radius:I,layer:"top"};return f.push(E),{circuitJson:f,parameters:e}},pB=(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}),xkn=ti.extend({fn:tt("pushbutton"),w:_e.default(4.5),h:_e.default(6.5),id:_e.default(1),od:_e.default(1.2)}),Ckn=t=>{const e=xkn.parse(t),n=e.w,o=e.h,i=e.id,r=[ns(1,-n/2,o/2,i,i*1.5),ns(2,-n/2,-o/2,i,i*1.5),ns(3,n/2,-o/2,i,i*1.5),ns(4,n/2,o/2,i,i*1.5)],s=[pB([{x:-n/2,y:-o/2},{x:-n/2,y:o/2}]),pB([{x:n/2,y:-o/2},{x:n/2,y:o/2}]),pB([{x:-n/2,y:0},{x:-n/5,y:0},{x:n/5*1/Math.sqrt(2),y:o/8}]),pB([{x:n/2,y:0},{x:n/5,y:0}])],a=ai(0,o/2+.4,.5),c=i*1.5/2,l=n,A=o,u=l/2+c,_=A/2+c,h=u+.5,d=_+.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}},z_t=ti.extend({fn:j(),w:_e.default("22.58mm"),h:_e.optional(),left:_e.optional().default(20),right:_e.optional().default(20),top:_e.optional().default(2),bottom:_e.optional().default(2),p:_e.default(_e.parse("2.54mm")),pw:_e.default(_e.parse("1.6mm")),pl:_e.default(_e.parse("2.4mm")),innerhole:Je().default(!1),innerholeedgedistance:_e.default(_e.parse("1.61mm")),silkscreenlabels:Je().default(!1),silkscreenlabelmargin:_e.default(_e.parse("0.1mm"))}),Ikn=t=>{const e=z_t.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},GX=(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},Ekn=t=>{const e=z_t.parse(t),n=e.h??Ikn(e),o=[],i=[],r=[];let s=[];const a=1,c=a,l=e.left+e.right+(e.bottom??0)+(e.top??0),u=`pin${l}`.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=GX(e.w/2-e.pl*1.4,m+p*e.p,"right")),o.push(Bo(p+1+e.left+(e.bottom??0),e.w/2-e.pl/2,m+p*e.p,e.pl,e.pw)),e.silkscreenlabels){const g=p+1+e.left+(e.bottom??0),y=`pin${g}`;r.push({type:"pcb_silkscreen_text",pcb_silkscreen_text_id:`pin_${g}`,pcb_component_id:"1",layer:"top",anchor_position:{x:e.w/2-e.pl-(u+e.silkscreenlabelmargin),y:m+p*e.p},text:y,font_size:.7,font:"tscircuit2024",anchor_alignment:"center"})}e.innerhole&&(i.push(ns(p+1+e.left+(e.bottom??0)+l,e.w/2,m+p*e.p,a,c)),i.push(ns(p+1+e.left+(e.bottom??0)+l*2,e.w/2-e.innerholeedgedistance,m+p*e.p,a,c)))}}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=GX(-e.w/2+e.pl*1.4,m-p*e.p,"left")),o.push(Bo(p+1,-e.w/2+e.pl/2,m-p*e.p,e.pl,e.pw)),e.silkscreenlabels){const g=p+1,y=`pin${g}`;r.push({type:"pcb_silkscreen_text",pcb_silkscreen_text_id:`pin_${g}`,pcb_component_id:"1",layer:"top",anchor_position:{x:-e.w/2+e.pl+(u+e.silkscreenlabelmargin),y:m-p*e.p},text:y,font_size:.7,font:"tscircuit2024",anchor_alignment:"center"})}e.innerhole&&(i.push(ns(p+1+l,-e.w/2,m-p*e.p,a,c)),i.push(ns(p+1+l*2,-e.w/2+e.innerholeedgedistance,m-p*e.p,a,c)))}}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=GX(m-p*e.p,n/2-e.pl*1.4,"top")),o.push(Bo(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 g=p+1+e.left+e.right+(e.bottom??0),y=`pin${g}`;r.push({type:"pcb_silkscreen_text",pcb_silkscreen_text_id:`pin_${g}`,pcb_component_id:"1",layer:"top",anchor_position:{x:m-p*e.p,y:n/2-e.pl-(u+e.silkscreenlabelmargin)},text:y,font_size:.7,font:"tscircuit2024",anchor_alignment:"center",ccw_rotation:270})}e.innerhole&&(i.push(ns(p+1+e.left+e.right+(e.bottom??0)+l,m-p*e.p,n/2,a,c)),i.push(ns(p+1+e.left+e.right+(e.bottom??0)+l*2,m-p*e.p,n/2-e.innerholeedgedistance,a,c)))}}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=GX(m+p*e.p,-n/2+e.pl*1.4,"bottom")),o.push(Bo(p+1+e.left,m+p*e.p,-n/2+e.pl/2,e.pw,e.pl)),e.silkscreenlabels){const g=p+1+e.left,y=`pin${g}`;r.push({type:"pcb_silkscreen_text",pcb_silkscreen_text_id:`pin_${g}`,pcb_component_id:"1",layer:"top",anchor_position:{x:m+p*e.p,y:-n/2+e.pl+(u+e.silkscreenlabelmargin)},text:y,font_size:.7,font:"tscircuit2024",anchor_alignment:"center",ccw_rotation:90})}e.innerhole&&(i.push(ns(p+1+e.left+l,m+p*e.p,-n/2,a,c)),i.push(ns(p+1+e.left+l*2,m+p*e.p,-n/2+e.innerholeedgedistance,a,c)))}}const _={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=ai(0,n/1.8,n/25);return{circuitJson:[...o,...i,...r,h,...e.silkscreenlabels?[]:[_],d],parameters:e}},U_t=ti.extend({fn:j(),w:_e.default("22.58mm"),h:_e.optional(),left:_e.optional().default(20),right:_e.optional().default(20),top:_e.optional().default(2),bottom:_e.optional().default(2),p:_e.default(_e.parse("2.54mm")),pw:_e.default(_e.parse("1.6mm")),pl:_e.default(_e.parse("3.2mm")),innerhole:Je().default(!1),innerholeedgedistance:_e.default(_e.parse("1.61mm"))}),bkn=t=>{const e=U_t.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},Skn=(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]},Pkn=t=>{const e=U_t.parse(t),n=e.h??bkn(e),o=[],i=[],r=[],s=1,a=1.2,c=e.left+e.right+(e.bottom??0)+(e.top??0);let l=[],A=1;if(e.left){const d=(e.left-1)/2*e.p;for(let m=0;m<e.left;m++)m===0&&(l=Skn(-e.w/2-e.pl/2,d-m*e.p,"left")),o.push(Bo(A,-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_${A}`,pcb_component_id:"1",layer:"top",anchor_position:{x:-e.w/2+e.pl/2-4.5,y:d-m*e.p},text:`pin${A}`,font_size:.7,font:"tscircuit2024",anchor_alignment:"center"}),A++,e.innerhole&&r.push(ns(A+c,-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(Bo(A,d-m*e.p,-n/2+e.pl/2,e.pw,e.pl)),i.push({type:"pcb_silkscreen_text",pcb_silkscreen_text_id:`pin_${A}`,pcb_component_id:"1",layer:"top",anchor_position:{x:d-m*e.p,y:-n/2+e.pl/2-3.2},text:`pin${A}`,font_size:.7,font:"tscircuit2024",anchor_alignment:"center"}),A++,e.innerhole&&r.push(ns(A+c,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(Bo(A,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_${A}`,pcb_component_id:"1",layer:"top",anchor_position:{x:e.w/2-e.pl/2+3.7,y:d+m*e.p},text:`pin${A}`,font_size:.7,font:"tscircuit2024",anchor_alignment:"center"}),A++,e.innerhole&&r.push(ns(A+c,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(Bo(A,d+m*e.p,n/2-e.pl/2,e.pw,e.pl)),i.push({type:"pcb_silkscreen_text",pcb_silkscreen_text_id:`pin_${A}`,pcb_component_id:"1",layer:"top",anchor_position:{x:d+m*e.p,y:n/2-e.pl/2+3.2},text:`pin${A}`,font_size:.7,font:"tscircuit2024",anchor_alignment:"center"}),A++,e.innerhole&&r.push(ns(A+c,d+m*e.p,n/2-e.innerholeedgedistance,s,a))}const u={type:"pcb_silkscreen_path",pcb_silkscreen_path_id:"1",pcb_component_id:"1",layer:"top",route:l,stroke_width:.1},_={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=ai(0,n/1.8,n/25);return{circuitJson:[...r,...o,...i,_,u,h],parameters:e}},vkn=t=>(t.legsoutside=!0,t.pl||(t.pl=1.5),t.pw||(t.pw=.3),D7(t)),V_t=ti.extend({fn:j(),w:_e.default("10mm"),h:_e.optional(),left:_e.optional().default(20),right:_e.optional().default(20),top:_e.optional().default(0),bottom:_e.optional().default(0),p:_e.default(_e.parse("2.54mm")),id:_e.optional().default(_e.parse("1mm")),od:_e.optional().default(_e.parse("1.5mm"))}),Bkn=t=>{const e=V_t.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},zX=(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]},Mkn=t=>{const e=V_t.parse(t),n=e.h??Bkn(e),o=[],i=e.id,r=e.od;let s=[];if(e.right){const A=-((e.right-1)/2)*e.p;for(let u=0;u<e.right;u++)u===0&&!e.left&&!e.bottom&&(s=zX(e.w/2+r*1.4,A+u*e.p,"right")),o.push(ns(u+1+e.left+(e.bottom??0),e.w/2,A+u*e.p,i,r))}if(e.left){const A=-((e.left-1)/2)*e.p;for(let u=0;u<e.left;u++)u===e.left-1&&(s=zX(-e.w/2-r*1.4,A+u*e.p,"left")),o.push(ns(u+1,-e.w/2,A+u*e.p,i,r))}if(e.top){const A=-((e.top-1)/2)*e.p;for(let u=0;u<e.top;u++)u===e.top-1&&!e.left&&!e.bottom&&!e.right&&(s=zX(A+u*e.p,n/2+r*1.4,"top")),o.push(ns(u+1+e.right+(e.bottom??0)+e.left,A+u*e.p,n/2,i,r))}if(e.bottom){const A=-((e.bottom-1)/2)*e.p;for(let u=0;u<e.bottom;u++)u===0&&!e.left&&(s=zX(A+u*e.p,-n/2-r*1.4,"bottom")),o.push(ns(u+1+e.left,A+u*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},c={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"},l=ai(0,n/1.7,n/25);return{circuitJson:[...o,c,l,a],parameters:e}},wkn=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 u=e-o,_=e+o,h=Array.from({length:r+1},(m,p)=>{const g=Math.PI/2-p*Math.PI/r;return{x:_+Math.cos(g)*i,y:n+Math.sin(g)*i}}),d=Array.from({length:r+1},(m,p)=>{const g=-Math.PI/2+p*Math.PI/r;return{x:u-Math.cos(g)*i,y:n+Math.sin(g)*i}});return[{x:u,y:n+i},{x:_,y:n+i},...h.slice(1,-1),{x:_,y:n-i},{x:u,y:n-i},...d.slice(1,-1)]}const a=n-o,c=n+o,l=Array.from({length:r+1},(u,_)=>{const h=Math.PI-_*Math.PI/r;return{x:e+Math.cos(h)*i,y:c+Math.sin(h)*i}}),A=Array.from({length:r+1},(u,_)=>{const h=_*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:c},...l.slice(1,-1),{x:e+i,y:c},{x:e+i,y:a},...A.slice(1,-1)]},Y_t=(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}}),Dkn=ti.extend({fn:j(),p:_e.optional().default("4.88mm"),id:_e.optional().default("0.8mm"),od:_e.optional().default("1.5mm"),w:_e.optional().default("5.6mm"),h:_e.optional().default("3.5mm")}),Tkn=t=>{const e=Dkn.parse(t),{p:n,id:o,od:i,w:r,h:s}=e,a=s/2,c=[ns(1,-n/2,0,o,i),ns(2,n/2,0,o,i)],l=Y_t(-r/2,0,a,"left"),A=Y_t(r/2,0,a,"right"),u={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[...l,...l.slice(1).reverse(),{x:-r/2,y:-s/2},{x:r/2,y:-s/2},...A,{x:r/2,y:s/2},{x:-r/2,y:s/2}],stroke_width:.1,pcb_silkscreen_path_id:""},_=ai(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:wkn({centerX:0,centerY:0,straightHalfLength:d,radius:m,arcSegmentCount:9}),layer:"top"};return{circuitJson:[...c,u,_,p],parameters:e}};ti.extend({w:_e,h:_e});var Qkn=t=>{const{w:e,h:n}=t,o=Ma(e),i=Ma(n);return{circuitJson:[Bo(1,0,0,o,i),ai(0,i/2+.5,.2)],parameters:t}},fB=(t,e,n,o,i,r)=>({pcb_plated_hole_id:"",type:"pcb_plated_hole",shape:"pill",x:e,y:n,outer_width:Ma(i),outer_height:Ma(r),hole_width:Ma(o),hole_height:Ma(o),pcb_port_id:"",layers:["top","bottom"],port_hints:[t.toString()],ccw_rotation:0}),Rkn=[{x:-2.73,y:3.71},{x:-2.73,y:-1.03},{x:2.73,y:-1.03},{x:2.73,y:3.71}],Nkn=ti.extend({fn:j(),num_pins:ho([tt(3),tt(2)]).default(3),p:j().default("1.27mm"),id:j().default("0.72mm"),od:j().default("0.95mm"),w:j().default("4.5mm"),h:j().default("4.5mm"),inline:Je().default(!1),string:j().optional()}),kkn=(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}}),Hkn=t=>{const e=t.string?.match(/^to92_(\d+)/),n=e?Number.parseInt(e[1],10):3,o=Nkn.parse({...t,num_pins:n}),{p:i,id:r,od:s,w:a,h:c,inline:l}=o,A=Number.parseFloat(c)/2,u=Number.parseFloat(i),_=Number.parseFloat(r),h=Number.parseFloat(s),d=h,m=h*(1.5/1.05);let p=[];if(o.num_pins===3)l?p=[_C({pn:1,x:-u,y:A-u,holeDiameter:_,rectPadWidth:h,rectPadHeight:m}),fB(2,0,A-u,_,d,m),fB(3,u,A-u,_,d,m)]:p=[_C({pn:1,x:-u,y:A-u,holeDiameter:_,rectPadWidth:h,rectPadHeight:h}),ns(2,0,A,_,h),ns(3,u,A-u,_,h)];else if(o.num_pins===2)p=[_C({pn:1,x:-u,y:A-u,holeDiameter:_,rectPadWidth:d,rectPadHeight:m}),fB(2,u,A-u,_,d,m)];else throw new Error("Invalid number of pins for TO-92");const g=Number.parseFloat(a)/2,y=kkn(0,A,g),f={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[...y,{x:-g,y:0},{x:g,y:0},y[0]],stroke_width:.1,pcb_silkscreen_path_id:""},x=ai(0,A+1,.5),I={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",outline:Rkn,layer:"top"};return{circuitJson:[...p,f,x,I],parameters:o}},Lkn=ti.extend({fn:j(),num_pins:tt(2).default(2),w:j().default("2.15mm"),h:j().default("0.7mm"),pl:j().default("0.6mm"),pw:j().default("0.7mm"),p:j().default("1.4mm")}),Fkn=t=>{const e=Lkn.parse(t),n=ai(0,_e.parse(e.h),.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:_e.parse(e.p)/2,y:_e.parse(e.h)/2+.2},{x:-_e.parse(e.w)/2-.2,y:_e.parse(e.h)/2+.2},{x:-_e.parse(e.w)/2-.2,y:-_e.parse(e.h)/2-.2},{x:_e.parse(e.p)/2,y:-_e.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:Gkn(e).concat(o,n,s),parameters:e}},Okn=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},Gkn=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=Okn({pn:n,p:Number.parseFloat(t.p)});e.push(Bo(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return e},zkn=mB({w:"7.05mm",p:"1.27mm",pw:"0.65mm",pl:"1.975mm"}),Ukn=t=>{const e=zkn.parse(t),n=[];for(let _=0;_<e.num_pins;_++){const{x:h,y:d}=c5e({num_pins:e.num_pins,pn:_+1,w:e.w,p:e.p??1.27,pl:e.pl,widthincludeslegs:!0});n.push(Bo(_+1,h,d,e.pl??"1.5mm",e.pw??"0.6mm"))}const o=(e.num_pins/2-1)*e.p+e.pw,i=ai(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,c=e.w/2+.255,l=s/2+.25,A=s/2+.5,u={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",layer:"top",outline:p1([{minX:-c,maxX:c,minY:-l,maxY:l},{minX:-a,maxX:a,minY:-A,maxY:A}])};return{circuitJson:[...n,i,r,u],parameters:e}},Vkn=ti.extend({fn:j(),num_pins:tt(2).default(2),w:j().default("5.0mm"),h:j().default("2.30mm"),pl:j().default("1.25mm"),pw:j().default("2mm"),p:j().default("3.75mm")}),Ykn=t=>{const e=Vkn.parse(t),n=ai(0,_e.parse(e.h)/2+1,.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:_e.parse(e.p)/2+.5,y:_e.parse(e.h)/2+.5},{x:-_e.parse(e.w)/2-.5,y:_e.parse(e.h)/2+.5},{x:-_e.parse(e.w)/2-.5,y:-_e.parse(e.h)/2-.5},{x:_e.parse(e.p)/2+.5,y:-_e.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:Wkn(e).concat(o,n,s),parameters:e}},Kkn=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},Wkn=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=Kkn({pn:n,p:Number.parseFloat(t.p)});e.push(Bo(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return e},jkn=ti.extend({fn:j(),num_pins:tt(2).default(2),w:j().default("4.4mm"),h:j().default("1.7mm"),pl:j().default("1.2mm"),pw:j().default("1.2mm"),p:j().default("2.8mm")}),Xkn=t=>{const e=jkn.parse(t),n=ai(0,_e.parse(e.h)-.5,.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:_e.parse(e.p)/2,y:_e.parse(e.h)/2},{x:-_e.parse(e.w)/2-.2,y:_e.parse(e.h)/2},{x:-_e.parse(e.w)/2-.2,y:-_e.parse(e.h)/2},{x:_e.parse(e.p)/2,y:-_e.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:qkn(e).concat(o,n,s),parameters:e}},Jkn=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},qkn=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=Jkn({pn:n,p:Number.parseFloat(t.p)});e.push(Bo(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return e},$kn=ti.extend({fn:j(),num_pins:tt(2).default(2),w:j().default("3.30mm"),h:j().default("1.80mm"),pl:j().default("0.60mm"),pw:j().default("0.45mm"),p:j().default("2.1mm")}),Zkn=t=>{const e=$kn.parse(t),n=ai(0,_e.parse(e.h)-.5,.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:_e.parse(e.p)/2,y:_e.parse(e.h)/2},{x:-_e.parse(e.w)/2,y:_e.parse(e.h)/2},{x:-_e.parse(e.w)/2,y:-_e.parse(e.h)/2},{x:_e.parse(e.p)/2,y:-_e.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:tHn(e).concat(o,n,s),parameters:e}},eHn=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},tHn=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=eHn({pn:n,p:Number.parseFloat(t.p)});e.push(Bo(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return e},nHn=ti.extend({fn:j(),num_pins:tt(2).default(2),w:j().default("1.4mm"),h:j().default("0.9mm"),pl:j().default("0.36mm"),pw:j().default("0.25mm"),p:j().default("0.85mm")}),oHn=t=>{const e=nHn.parse(t),n=_e.parse(e.w),o=_e.parse(e.h),i=_e.parse(e.pl),r=_e.parse(e.pw),s=_e.parse(e.p),a=ai(0,o,.3),c={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:""},l=s+i,A=r,u=n/2,_=o/2,h=l/2,d=A/2,m=Math.max(u,h),p=Math.max(_,d),g=Math.min(u,h),y=Math.min(_,d),f=m+.05,x=g-.055,I=p,E=y+.155,b={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",outline:p1([{minX:-f,maxX:f,minY:-E,maxY:E},{minX:-x,maxX:x,minY:-I,maxY:I}]),layer:"top"};return{circuitJson:rHn(e).concat(c,a,b),parameters:e}},iHn=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},rHn=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=iHn({pn:n,p:Number.parseFloat(t.p)});e.push(Bo(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return e},sHn=ti.extend({fn:j(),num_pins:tt(2).default(2),w:j().default("1.3mm"),h:j().default("0.9mm"),pl:j().default("0.4mm"),pw:j().default("0.7mm"),p:j().default("0.7mm")}),aHn=t=>{const e=sHn.parse(t),n=ai(0,_e.parse(e.h)+.1,.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:_e.parse(e.p)/2+.2,y:_e.parse(e.h)/2+.2},{x:-_e.parse(e.w)/2-.2,y:_e.parse(e.h)/2+.2},{x:-_e.parse(e.w)/2-.2,y:-_e.parse(e.h)/2-.2},{x:_e.parse(e.p)/2+.2,y:-_e.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:lHn(e).concat(o,n,s),parameters:e}},cHn=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},lHn=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=cHn({pn:n,p:Number.parseFloat(t.p)});e.push(Bo(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return e},AHn=ti.extend({fn:j(),num_pins:tt(2).default(2),w:j().default("3.05mm"),h:j().default("1.4mm"),pl:j().default("0.5mm"),pw:j().default("0.5mm"),pad_spacing:j().default("2.2mm")}),uHn=t=>{const e=AHn.parse(t),n=ai(0,_e.parse(e.h),.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:_e.parse(e.pad_spacing)/2,y:_e.parse(e.h)/2},{x:-_e.parse(e.w)/2-.2,y:_e.parse(e.h)/2},{x:-_e.parse(e.w)/2-.2,y:-_e.parse(e.h)/2},{x:_e.parse(e.pad_spacing)/2,y:-_e.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:dHn(e).concat(o,n,s),parameters:e}},_Hn=t=>{const{pn:e,pad_spacing:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},dHn=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=_Hn({pn:n,pad_spacing:Number.parseFloat(t.pad_spacing)});e.push(Bo(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return e},hHn=ti.extend({fn:j(),num_pins:tt(2).default(2),w:j().default("4.4mm"),h:j().default("2.1mm"),pl:j().default("1.10mm"),pw:j().default("1.10mm"),p:j().default("2.8mm")}),mHn=t=>{const e=hHn.parse(t),n=ai(0,_e.parse(e.h),.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:_e.parse(e.p)/2,y:_e.parse(e.h)/2},{x:-_e.parse(e.w)/2-.2,y:_e.parse(e.h)/2},{x:-_e.parse(e.w)/2-.2,y:-_e.parse(e.h)/2},{x:_e.parse(e.p)/2,y:-_e.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:pHn(e).concat(o,n,s),parameters:e}},gHn=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},pHn=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=gHn({pn:n,p:Number.parseFloat(t.p)});e.push(Bo(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return e},fHn=ti.extend({fn:j(),num_pins:tt(2).default(2),w:j().default("4.4mm"),h:j().default("2.1mm"),pl:j().default("0.91mm"),pw:j().default("1.22mm"),p:j().default("3.146mm")}),yHn=t=>{const e=fHn.parse(t),n=ai(0,_e.parse(e.h),.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:_e.parse(e.p)/2,y:_e.parse(e.h)/2},{x:-_e.parse(e.w)/2-.2,y:_e.parse(e.h)/2},{x:-_e.parse(e.w)/2-.2,y:-_e.parse(e.h)/2},{x:_e.parse(e.p)/2,y:-_e.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:CHn(e).concat(o,n,s),parameters:e}},xHn=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},CHn=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=xHn({pn:n,p:Number.parseFloat(t.p)});e.push(Bo(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return e},IHn=ti.extend({fn:j(),num_pins:tt(2).default(2),w:j().default("1.80mm"),h:j().default("1.00mm"),pl:j().default("0.66mm"),pw:j().default("0.5mm"),p:j().default("0.8mm")}),EHn=t=>{const e=IHn.parse(t),n=ai(0,_e.parse(e.h),.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:_e.parse(e.p)/2,y:_e.parse(e.h)/2},{x:-_e.parse(e.w)/2-.1,y:_e.parse(e.h)/2},{x:-_e.parse(e.w)/2-.1,y:-_e.parse(e.h)/2},{x:_e.parse(e.p)/2,y:-_e.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:SHn(e).concat(o,n,s),parameters:e}},bHn=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},SHn=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=bHn({pn:n,p:Number.parseFloat(t.p)});e.push(Bo(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return e},PHn=ti.extend({fn:j(),num_pins:tt(2).default(2),w:j().default("6.2mm"),h:j().default("3.4mm"),pl:j().default("1.4mm"),pw:j().default("2.1mm"),p:j().default("4.4mm")}),vHn=t=>{const e=PHn.parse(t),n=ai(0,_e.parse(e.h)/2+.4,.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:_e.parse(e.p)/2,y:_e.parse(e.h)/2},{x:-_e.parse(e.w)/2-.2,y:_e.parse(e.h)/2},{x:-_e.parse(e.w)/2-.2,y:-_e.parse(e.h)/2},{x:_e.parse(e.p)/2,y:-_e.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:MHn(e).concat(o,n,s),parameters:e}},BHn=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},MHn=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=BHn({pn:n,p:Number.parseFloat(t.p)});e.push(Bo(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return e},wHn=[{x:-3.0875,y:-2.5},{x:-3.0875,y:2.5},{x:2.0125,y:2.5},{x:2.0125,y:-2.5}],DHn=[{x:-2.85,y:-2.5},{x:-2.85,y:2.5},{x:2.85,y:2.5},{x:2.85,y:-2.5}],THn=ti.extend({fn:j(),num_pins:ho([tt(3),tt(5)]).default(3),w:j().default("4.20mm"),h:j().default("4.80mm"),pl:j().default("1.3mm"),pw:j().default("0.9mm"),p:j().default("1.5mm"),string:j().optional()}),QHn=t=>{const e=[],n=Number.parseFloat(t.p),o=Number.parseFloat(t.pw),i=Number.parseFloat(t.w),r=Number.parseFloat(t.pl),s=.175,a=(r-(r+s))/2;e.push(Bo(1,-i/2+a,n,r,o),Bo(2,-i/2,0,r+s,o),Bo(3,-i/2+a,-n,r,o));const c=ai(0,0,.3),l=Number.parseFloat(t.w)/2-1,A=Number.parseFloat(t.h)/2,u={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-l,y:A},{x:l,y:A},{x:l,y:A/2+.5}],type:"pcb_silkscreen_path",stroke_width:.1},_={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_2",route:[{x:-l,y:-A},{x:l,y:-A},{x:l,y:-A/2-.5}],type:"pcb_silkscreen_path",stroke_width:.1},h={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",outline:wHn,layer:"top"};return[...e,u,_,c,h]},RHn=t=>{const e=[];Number.parseFloat(t.p),Number.parseFloat(t.pw),Number.parseFloat(t.w),e.push(Bo(1,-1.85,-1.5,1.5,.7),Bo(2,-1.85,1.5,1.5,.7),Bo(3,0,0,.8,2),Bo(4,1.85,-1.5,1.5,.7),Bo(5,1.85,1.5,1.5,.7));const n=ai(0,Number.parseFloat(t.h)/2+.5,.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,y:i}],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,y:-i}],type:"pcb_silkscreen_path",stroke_width:.1},a={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",outline:DHn,layer:"top"};return[...e,r,s,n,a]},NHn=t=>{const e=t.string?.match(/^sot89_(\d+)/),n=e?Number.parseInt(e[1],10):3,o=THn.parse({...t,num_pins:n});if(o.num_pins===3)return{circuitJson:QHn(o),parameters:o};if(o.num_pins===5)return{circuitJson:RHn(o),parameters:o};throw new Error("Invalid number of pins for SOT89")},kHn=ti.extend({fn:j(),p:_e.optional().default("5.0mm"),id:_e.optional().default("1.0mm"),od:_e.optional().default("1.9mm"),w:_e.optional().default("13mm"),h:_e.optional().default("7mm"),num_pins:ut().optional(),string:j().optional()}),K_t=t=>{const e=kHn.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"),c=-1,l=i/2,A=r/2,u=2.5,_=i*.4,h=Math.max(u,_/(a-1)),d=Array.from({length:a},(G,K)=>{const X=a%2===0?(K-a/2+.5)*h:(K-Math.floor(a/2))*h;return ns(K+1,X,c,n,o)}),m={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-l,y:-A},{x:l,y:-A},{x:l,y:A},{x:-l,y:A},{x:-l,y:-A}],stroke_width:.1,pcb_silkscreen_path_id:""},p=-A+2*r/3,g={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-l,y:p},{x:l,y:p}],stroke_width:.1,pcb_silkscreen_path_id:""},y=[{type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-i/6,y:p},{x:-i/6,y:A}],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:A}],stroke_width:.1,pcb_silkscreen_path_id:""}],f=ai(0,r/2+.6,.5),x=Math.max(...d.map(G=>Math.abs(G.x)))+o/2,I=c+o/2,E=c-o/2,b=Math.max(x+.25,l-o*.59),P=A-o*.63,B=E-(o/2+.01),w=-b,k=b,N=Math.min(B,E-.25),F=Math.max(P,I+.25),O={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:(w+k)/2,y:(N+F)/2},width:k-w,height:F-N,layer:"top"};return{circuitJson:[...d,m,g,...y,f,O],parameters:{...e,p:h}}},u5e=2.54,HHn=ti.extend({fn:j(),id:_e.optional().default("1.2mm"),od:_e.optional().default("1.905mm"),ph:_e.optional().default("2mm"),w:_e.optional().default("13mm"),h:_e.optional().default("7mm"),num_pins:ut().optional(),string:j().optional()}),LHn=t=>{const e=HHn.parse(t),n=e.num_pins??Number.parseInt(e.string?.match(/^to220f(?:_|-)(\d+)/i)?.[1]??"3"),o=K_t({...e,fn:"to220",string:e.string?.replace(/^to220f/i,"to220"),num_pins:n}),i=-1,r=Array.from({length:n},(a,c)=>{const l=n%2===0?(c-n/2+.5)*u5e:(c-Math.floor(n/2))*u5e;return c===0?_C({pn:1,x:l,y:i,holeDiameter:e.id,rectPadWidth:e.od,rectPadHeight:e.ph}):fB(c+1,l,i,Ma(e.id),Ma(e.od),Ma(e.ph))}),s=o.circuitJson.filter(a=>a.type!=="pcb_plated_hole");return{circuitJson:[...r,...s],parameters:{...e,p:u5e,num_pins:n}}},FHn=ti.extend({fn:j(),num_pins:tt(2).default(2),w:j().default("5.40mm"),h:j().default("2.30mm"),pl:j().default("1.30mm"),pw:j().default("1.70mm"),p:j().default("3.5mm")}),OHn=t=>{const e=FHn.parse(t),n=ai(0,_e.parse(e.h)/2+.4,.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:_e.parse(e.p)/2,y:_e.parse(e.h)/2},{x:-_e.parse(e.w)/2,y:_e.parse(e.h)/2},{x:-_e.parse(e.w)/2,y:-_e.parse(e.h)/2},{x:_e.parse(e.p)/2,y:-_e.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:zHn(e).concat(o,n,s),parameters:e}},GHn=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},zHn=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=GHn({pn:n,p:Number.parseFloat(t.p)});e.push(Bo(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return e},UHn=ti.extend({fn:j(),num_pins:tt(2).default(2),w:j().default("1.90mm"),h:j().default("1.33mm"),pl:j().default("0.5mm"),pw:j().default("0.7mm"),p:j().default("0.8mm")}),VHn=t=>{const e=UHn.parse(t),n=ai(0,_e.parse(e.h)+.1,.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:_e.parse(e.p)/2+.1,y:_e.parse(e.h)/2},{x:-_e.parse(e.w)/2,y:_e.parse(e.h)/2},{x:-_e.parse(e.w)/2,y:-_e.parse(e.h)/2},{x:_e.parse(e.p)/2+.1,y:-_e.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:KHn(e).concat(o,n,s),parameters:e}},YHn=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},KHn=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=YHn({pn:n,p:Number.parseFloat(t.p)});e.push(Bo(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return e},WHn=ti.extend({fn:j(),num_pins:tt(2).default(2),w:j().default("7.0mm"),h:j().default("3.35mm"),pl:j().default("1.50mm"),pw:j().default("2.70mm"),p:j().default("4.8mm")}),jHn=t=>{const e=WHn.parse(t),n=ai(0,_e.parse(e.h),.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:_e.parse(e.p)/2,y:_e.parse(e.h)/2},{x:-_e.parse(e.w)/2,y:_e.parse(e.h)/2},{x:-_e.parse(e.w)/2,y:-_e.parse(e.h)/2},{x:_e.parse(e.p)/2,y:-_e.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:JHn(e).concat(o,n,s),parameters:e}},XHn=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},JHn=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=XHn({pn:n,p:Number.parseFloat(t.p)});e.push(Bo(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return e},qHn=ti.extend({fn:j(),num_pins:tt(2).default(2),w:j().default("3.0mm"),h:j().default("1.80mm"),pl:j().default("0.80mm"),pw:j().default("1.20mm"),p:j().default("1.6mm")}),$Hn=t=>{const e=qHn.parse(t),n=ai(0,_e.parse(e.h),.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:_e.parse(e.p)/2,y:_e.parse(e.h)/2},{x:-_e.parse(e.w)/2-.1,y:_e.parse(e.h)/2},{x:-_e.parse(e.w)/2-.1,y:-_e.parse(e.h)/2},{x:_e.parse(e.p)/2,y:-_e.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:eLn(e).concat(o,n,s),parameters:e}},ZHn=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},eLn=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=ZHn({pn:n,p:Number.parseFloat(t.p)});e.push(Bo(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return e},tLn=ti.extend({fn:j(),num_pins:tt(2).default(2),w:j().default("7.10mm"),h:j().default("3.40mm"),pl:j().default("2.50mm"),pw:j().default("1.80mm"),p:j().default("4.00mm")}),nLn=t=>{const e=tLn.parse(t),n=ai(0,_e.parse(e.h)/2+.5,.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:_e.parse(e.p)/2,y:_e.parse(e.h)/2},{x:-_e.parse(e.w)/2-.5,y:_e.parse(e.h)/2},{x:-_e.parse(e.w)/2-.5,y:-_e.parse(e.h)/2},{x:_e.parse(e.p)/2,y:-_e.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:iLn(e).concat(o,n,s),parameters:e}},oLn=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},iLn=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=oLn({pn:n,p:Number.parseFloat(t.p)});e.push(Bo(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return e},rLn=ti.extend({fn:j(),num_pins:tt(2).default(2),w:j().default("4.80mm"),h:j().default("2.10mm"),pl:j().default("1.30mm"),pw:j().default("1.40mm"),p:j().default("2.9mm")}),sLn=t=>{const e=rLn.parse(t),n=ai(0,_e.parse(e.h)-.5,.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:_e.parse(e.p)/2,y:_e.parse(e.h)/2},{x:-_e.parse(e.w)/2,y:_e.parse(e.h)/2},{x:-_e.parse(e.w)/2,y:-_e.parse(e.h)/2},{x:_e.parse(e.p)/2,y:-_e.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:cLn(e).concat(o,n,s),parameters:e}},aLn=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},cLn=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=aLn({pn:n,p:Number.parseFloat(t.p)});e.push(Bo(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return e},lLn=ti.extend({fn:j(),num_pins:tt(2).default(2),w:j().default("7.30mm"),h:j().default("4.40mm"),pl:j().default("2.50mm"),pw:j().default("2.30mm"),p:j().default("4.30mm")}),ALn=t=>{const e=lLn.parse(t),n=ai(0,_e.parse(e.h)/2+.5,.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:_e.parse(e.p)/2,y:_e.parse(e.h)/2},{x:-_e.parse(e.w)/2-.1,y:_e.parse(e.h)/2},{x:-_e.parse(e.w)/2-.1,y:-_e.parse(e.h)/2},{x:_e.parse(e.p)/2,y:-_e.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:_Ln(e).concat(o,n,s),parameters:e}},uLn=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},_Ln=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=uLn({pn:n,p:Number.parseFloat(t.p)});e.push(Bo(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return e},dLn=ti.extend({fn:j(),num_pins:tt(2).default(2),w:j().default("10.70mm"),h:j().default("6.60mm"),pl:j().default("2.50mm"),pw:j().default("3.30mm"),p:j().default("6.80mm")}),hLn=t=>{const e=dLn.parse(t),n=ai(0,3,.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:_e.parse(e.p)/2,y:_e.parse(e.h)/2-.8},{x:-_e.parse(e.w)/2-.8,y:_e.parse(e.h)/2-.8},{x:-_e.parse(e.w)/2-.8,y:-_e.parse(e.h)/2+.8},{x:_e.parse(e.p)/2,y:-_e.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:gLn(e).concat(o,n,s),parameters:e}},mLn=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},gLn=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=mLn({pn:n,p:Number.parseFloat(t.p)});e.push(Bo(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return e},pLn=ti.extend({fn:j(),num_pins:ut().default(4),w:j().default("8.50mm"),h:j().default("6.90mm"),pl:j().default("2mm"),pw:j().default("1.5mm"),p:j().default("2.30mm"),string:j().optional()}),fLn=t=>{const e=t.string?.match(/^sot223_(\d+)/),n=e?Number.parseInt(e[1],10):4;if(n===8){const i=CLn.parse({...t,num_pins:n});return{circuitJson:Gk(i),parameters:i}}const o=pLn.parse({...t,num_pins:n});if(o.num_pins===4)return{circuitJson:xLn(o),parameters:o};if(o.num_pins===5)return{circuitJson:ELn(o),parameters:o};if(o.num_pins===6)return{circuitJson:SLn(o),parameters:o};throw new Error("Invalid number of pins")},yLn=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}},xLn=t=>{const e=[];let n=0,o=0;for(let d=0;d<t.num_pins;d++){const{x:m,y:p}=yLn({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)}),g=d===3?3.8:Number.parseFloat(t.pw),y=Number.parseFloat(t.pl);n=Math.max(n,Math.abs(m)+y/2),o=Math.max(o,Math.abs(p)+g/2),e.push(Bo(d+1,m,p,y,g))}const i=ai(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},c={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},l=Number.parseFloat(t.w)/2,A=Number.parseFloat(t.h)/2,u=Math.max(n+.25,l+.15),_=Math.max(o+.25,A+.15),h={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:0,y:0},width:2*u,height:2*_,layer:"top"};return[...e,a,c,i,h]},CLn=mB({p:"0.90mm",w:"2.8mm",legsoutside:!0}),ILn=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")},ELn=t=>{const e=[];let n=0,o=0;for(let d=1;d<=t.num_pins;d++){const{x:m,y:p}=ILn({h:Number.parseFloat(t.h),p:1.5,pn:d,w:Number.parseFloat(t.w)});let g=Number.parseFloat(t.pw),y=Number.parseFloat(t.pl);d===5?(g=3.4,y=1.8):(g=1,y=2.2),n=Math.max(n,Math.abs(m)+y/2),o=Math.max(o,Math.abs(p)+g/2),e.push(Bo(d,m,p,y,g))}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},c=ai(0,0,.3),l=Number.parseFloat(t.w)/2,A=Number.parseFloat(t.h)/2,u=Math.max(n+.25,l+.15),_=Math.max(o+.25,A+.15),h={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:0,y:0},width:2*u,height:2*_,layer:"top"};return[...e,s,a,c,h]},bLn=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")},SLn=t=>{const e=[];let n=0,o=0;for(let d=1;d<=t.num_pins;d++){const{x:m,y:p}=bLn({h:Number.parseFloat(t.h),p:1.3,pn:d,w:8.7});let g=Number.parseFloat(t.pw),y=Number.parseFloat(t.pl);d===6?(g=3.4,y=2.15):(g=.6,y=2.2),n=Math.max(n,Math.abs(m)+y/2),o=Math.max(o,Math.abs(p)+g/2),e.push(Bo(d,m,p,y,g))}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},c=ai(0,0,.3),l=Number.parseFloat(t.w)/2,A=Number.parseFloat(t.h)/2,u=Math.max(n+.25,l+.15),_=Math.max(o+.25,A+.15),h={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:0,y:0},width:2*u,height:2*_,layer:"top"};return[...e,s,a,c,h]},PLn=ti.extend({fn:j(),num_pins:ut().default(3),w:j().default("3.40mm"),h:j().default("3.30mm"),pl:j().default("1mm"),pw:j().default("0.7mm"),p:j().default("1.2mm"),string:j().optional()}),vLn=t=>{const e=t.string?.match(/^sot23w_(\d+)/),n=e?Number.parseInt(e[1],3):3,o=PLn.parse({...t,num_pins:n});if(o.num_pins===3)return{circuitJson:MLn(o),parameters:o};throw new Error("Invalid number of pins")},BLn=t=>{const{pn:e,p:n}=t;return e===1?{x:-n,y:.95}:e===2?{x:-n,y:-.95}:{x:n,y:0}},MLn=t=>{const e=[];for(let g=0;g<t.num_pins;g++){const{x:y,y:f}=BLn({num_pins:t.num_pins,pn:g+1,w:Number.parseFloat(t.w),h:Number.parseFloat(t.h),pl:Number.parseFloat(t.pl),p:Number.parseFloat(t.p)});e.push(Bo(g+1,y,f,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}const n=ai(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),c=Number.parseFloat(t.pl),l=Number.parseFloat(t.pw),A=Number.parseFloat(t.h),u=a+c/2,_=.95+l/2,h=A/2,d=u+.25,m=Math.max(_+.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]},wLn=ti.extend({fn:j(),num_pins:ho([tt(3),tt(2)]).default(3),p:j().default("1.27mm"),id:j().default("0.72mm"),od:j().default("0.95mm"),w:j().default("2.5mm"),h:j().default("4.2mm"),string:j().optional()}),DLn=t=>{const{p:e,id:n,od:o,w:i,h:r}=t,s=Number.parseFloat(r)/2,a=Number.parseFloat(e);return[ns(1,-a,s-a,n,o),ns(2,0,s-a,n,o),ns(3,a,s-a,n,o)]},TLn=t=>{const{p:e,id:n,od:o,h:i}=t,r=Number.parseFloat(i)/2,s=Number.parseFloat(e);return[ns(1,-s,r-s,n,o),ns(2,s,r-s,n,o)]},QLn=t=>{const e=t.string?.match(/^to92s_(\d+)/),n=e?Number.parseInt(e[1],10):3,o=wLn.parse({...t,num_pins:n});let i=[];if(o.num_pins===3)i=DLn(o);else if(o.num_pins===2)i=TLn(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:""},c=ai(0,r+1,.5),l=Number.parseFloat(o.od),A=r-s,u=-s-l/2,_=s+l/2,h=A-l/2,d=A+l/2,m=-r,p=r,g=0,y=r+.5,f=Math.min(u,m)-.27,x=Math.max(_,p)+.13,I=Math.min(h,g)-.42,E=Math.max(d,y)+.08,b={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:(f+x)/2,y:(I+E)/2},width:x-f,height:E-I,layer:"top"};return{circuitJson:[...i,a,c,b],parameters:o}},RLn=ti.extend({fn:j(),p:_e.optional(),id:_e.optional(),pw:_e.optional(),pl:_e.optional(),w:_e.optional(),h:_e.optional(),sh:Je().optional().describe('JST SH (Surface-mount) connector family. SH stands for "Super High-density".'),ph:Je().optional().describe('JST PH (Through-hole) connector family. PH stands for "Pin Header".'),zh:Je().optional().describe("JST ZH (Through-hole) connector family. 1.5mm pitch wire-to-board."),string:j().optional()}),NLn=()=>({minX:Number.POSITIVE_INFINITY,maxX:Number.NEGATIVE_INFINITY,minY:Number.POSITIVE_INFINITY,maxY:Number.NEGATIVE_INFINITY}),zk=({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)},kLn={ph:{p:_e.parse("2.2mm"),id:_e.parse("0.70mm"),pw:_e.parse("1.20mm"),pl:_e.parse("1.20mm"),w:_e.parse("6mm"),h:_e.parse("5mm")},sh:{p:_e.parse("1mm"),pw:_e.parse("0.6mm"),pl:_e.parse("1.55mm"),w:_e.parse("5.8mm"),h:_e.parse("7.8mm")},zh:{p:_e.parse("1.5mm"),id:_e.parse("0.73mm"),pw:_e.parse("1.03mm"),pl:_e.parse("1.73mm"),w:_e.parse("3mm"),h:_e.parse("3.5mm")}};function HLn(t){return t.sh?"sh":t.ph?"ph":t.zh?"zh":"ph"}function LLn({variant:t,numPins:e,p:n,id:o,pw:i,pl:r}){const s=[],a=NLn();let c=0;if(t==="ph"){const l=-((e-1)/2)*n;for(let A=0;A<e;A++){const u=l+A*n;s.push(_C({pn:A+1,x:u,y:2,holeDiameter:o,rectPadWidth:i,rectPadHeight:r})),zk({bounds:a,centerX:u,centerY:2,width:i,height:r}),c=Math.max(c,r/2)}}else if(t==="zh"){const l=-((e-1)/2)*n;for(let A=0;A<e;A++){const u=l+A*n;A===0?s.push(_C({pn:A+1,x:u,y:0,holeDiameter:o,rectPadWidth:i,rectPadHeight:r,rectBorderRadius:.12499977})):s.push(fB(A+1,u,0,o,i,r)),zk({bounds:a,centerX:u,centerY:0,width:i,height:r}),c=Math.max(c,r/2)}}else{const l=-((e-1)/2)*n;for(let u=0;u<e;u++){const _=l+u*n;s.push(Bo(u+1,_,-1.325,i,r)),zk({bounds:a,centerX:_,centerY:-1.325,width:i,height:r}),c=Math.max(c,r/2)}const A=(e-1)/2*n+1.3;s.push(Bo(e+1,-A,1.22,1.2,1.8)),s.push(Bo(e+2,A,1.22,1.2,1.8)),zk({bounds:a,centerX:-A,centerY:1.22,width:1.2,height:1.8}),zk({bounds:a,centerX:A,centerY:1.22,width:1.2,height:1.8}),c=Math.max(c,.9)}return{pads:s,padBounds:a,maxPadHalfY:c}}function FLn({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,c=-n/2,l=n/2;return{type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:s,y:c},{x:a,y:c},{x:a,y:l},{x:s,y:l},{x:s,y:c}],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 OLn=t=>{const e=RLn.parse(t),n=HLn(e),o=kLn[n],i=e.p??o.p,r=e.id??o.id,s=e.pw??o.pw,a=e.pl??o.pl,c=e.w??o.w,l=e.h??o.h;let A;const u=t.num_pins;typeof u=="number"&&(A=u);const _=typeof t.string=="string"?t.string:"",h=_.match(/(?:^|_)jst(\d+)(?:_|$)/),d=_.match(/(?:^|_)zh(\d+)(?:_|$)/);if(h&&h[1]){const Ae=Number.parseInt(h[1],10);Number.isNaN(Ae)||(A=Ae)}if(d&&d[1]){const Ae=Number.parseInt(d[1],10);Number.isNaN(Ae)||(A=Ae)}if(typeof A!="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=LLn({variant:n,numPins:A,p:i,id:r,pw:s,pl:a}),{pads:p,padBounds:g,maxPadHalfY:y}=m,f=FLn({variant:n,w:c,h:l,numPins:A,p:i}),x=ai(0,l/2+1,.5),I=f.route.map(Ae=>Ae.x),E=f.route.map(Ae=>Ae.y),b=I.length>0&&E.length>0,P=b?Math.min(g.minX,Math.min(...I)):g.minX,B=b?Math.max(g.maxX,Math.max(...I)):g.maxX,w=b?Math.min(g.minY,Math.min(...E)):g.minY,k=b?Math.max(g.maxY,Math.max(...E)):g.maxY,N=.5,F=.05,O=y+.085,G=P-N,K=B+N,X=w-O,$=k+F,oe={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:(G+K)/2,y:(X+$)/2},width:K-G,height:$-X,layer:"top"};return{circuitJson:[...p,f,x,oe],parameters:{...e,p:i,id:r,pw:s,pl:a,w:c,h:l,num_pins:A,sh:n==="sh",ph:n==="ph",zh:n==="zh"}}},GLn=ti.extend({fn:j(),num_pins:tt(2).default(2),w:j().default("3.30mm"),h:j().default("1.70mm"),pl:j().default("0.80mm"),pw:j().default("1mm"),p:j().default("1.90mm")}),zLn=t=>{const e=GLn.parse(t),n=ai(0,_e.parse(e.h)/2+.5,.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:_e.parse(e.p)/2,y:_e.parse(e.h)/2},{x:-_e.parse(e.w)/2,y:_e.parse(e.h)/2},{x:-_e.parse(e.w)/2,y:-_e.parse(e.h)/2},{x:_e.parse(e.p)/2,y:-_e.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:VLn(e).concat(o,n,s),parameters:e}},ULn=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},VLn=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=ULn({pn:n,p:Number.parseFloat(t.p)});e.push(Bo(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return e},YLn=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"}}},KLn=ti.extend({fn:j(),num_pins:ho([tt(8),tt(10)]).default(8),w:j().optional(),h:j().optional(),p:j().optional(),pl:j().optional(),pw:j().optional(),string:j().optional()}),WLn=t=>{const e=KLn.parse(t),n=YLn(e.num_pins),o=_e.parse(e.w||n.w),i=_e.parse(e.h||n.h),r=_e.parse(e.p||n.p),s=_e.parse(e.pl||n.pl),a=_e.parse(e.pw||n.pw),c=[],l=e.num_pins/2;for(let P=0;P<e.num_pins;P++){const{x:B,y:w}=W_t(e.num_pins,P+1,o,r),k=P<l?P+1:e.num_pins-(P-l);c.push(Bo(k,B,w,s,a))}const A=o,u=i,_={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-A/2,y:u/2},{x:A/2,y:u/2}],stroke_width:.05,pcb_silkscreen_path_id:""},h={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-A/2,y:-u/2},{x:A/2,y:-u/2}],stroke_width:.05,pcb_silkscreen_path_id:""},d=W_t(e.num_pins,1,A,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"},g=ai(0,u/2+.5,.3),y=(e.num_pins/2-1)*r+a,f=o/2+.25,x=f+1.43,I=y/2+.255,E=i/2+.25,b={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",layer:"top",outline:p1([{minX:-x,maxX:x,minY:-I,maxY:I},{minX:-f,maxX:f,minY:-E,maxY:E}])};return{circuitJson:[...c,_,h,g,p,b],parameters:e}},W_t=(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}},jLn=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"}}},XLn=ti.extend({fn:j(),num_pins:ho([tt(8),tt(10),tt(12),tt(16)]).default(8),w:j().optional(),h:j().optional(),p:j().optional(),pl:j().optional(),pw:j().optional(),string:j().optional()}),j_t=(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*_e.parse("2mm"),y:a*o}},JLn=t=>{const e=XLn.parse(t),n=jLn(e.num_pins),o=_e.parse(e.w||n.w),i=_e.parse(e.h||n.h),r=_e.parse(e.p||n.p),s=_e.parse(e.pl||n.pl),a=_e.parse(e.pw||n.pw),c=[];for(let b=0;b<e.num_pins;b++){const{x:P,y:B}=j_t(e.num_pins,b+1,o,r);c.push(Bo(b+1,P,B,s,a))}const l=o,A=i,u={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-l/2,y:A/2},{x:l/2,y:A/2}],stroke_width:.05,pcb_silkscreen_path_id:""},_={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-l/2,y:-A/2},{x:l/2,y:-A/2}],stroke_width:.05,pcb_silkscreen_path_id:""},h=j_t(e.num_pins,1,l,r),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=ai(0,A/2+.5,.3),g=(e.num_pins/2-1)*r+a,y=o/2+.25,f=y+1.43,x=g/2+.255,I=i/2+.25,E={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",layer:"top",outline:p1([{minX:-f,maxX:f,minY:-x,maxY:x},{minX:-y,maxX:y,minY:-I,maxY:I}])};return{circuitJson:[...c,u,_,p,m,E],parameters:e}},qLn=ti.extend({fn:j(),num_pins:tt(2).default(2),w:j().default("3.8mm"),h:j().default("1.65mm"),pl:j().default("1.2mm"),pw:j().default("1.2mm"),pad_spacing:j().default("2.6mm")}),$Ln=t=>{const e=qLn.parse(t),n=ai(0,_e.parse(e.h),.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:_e.parse(e.pad_spacing)/2,y:_e.parse(e.h)/2},{x:-_e.parse(e.w)/2-.2,y:_e.parse(e.h)/2},{x:-_e.parse(e.w)/2-.2,y:-_e.parse(e.h)/2},{x:_e.parse(e.pad_spacing)/2,y:-_e.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:eFn(e).concat(o,n,s),parameters:e}},ZLn=t=>{const{pn:e,pad_spacing:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},eFn=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=ZLn({pn:n,pad_spacing:Number.parseFloat(t.pad_spacing)});e.push(Bo(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return e},tFn=ti.extend({fn:j(),num_pins:tt(2).default(2),w:j().default("3.20mm"),h:j().default("1.65mm"),pl:j().default("0.8mm"),pw:j().default("0.9mm"),pad_spacing:j().default("2.1mm")}),nFn=t=>{const e=tFn.parse(t),n=ai(0,_e.parse(e.h),.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:_e.parse(e.pad_spacing)/2,y:_e.parse(e.h)/2},{x:-_e.parse(e.w)/2-.2,y:_e.parse(e.h)/2},{x:-_e.parse(e.w)/2-.2,y:-_e.parse(e.h)/2},{x:_e.parse(e.pad_spacing)/2,y:-_e.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:iFn(e).concat(o,n,s),parameters:e}},oFn=t=>{const{pn:e,pad_spacing:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},iFn=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=oFn({pn:n,pad_spacing:Number.parseFloat(t.pad_spacing)});e.push(Bo(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return e},rFn=ti.extend({fn:j(),num_pins:ho([tt(6),tt(8)]).default(8),w:j().default("3mm"),h:j().default("3mm"),p:j().default("0.5mm"),pl:j().default("0.52mm"),pw:j().default("0.35mm"),epw:j().default("1.40mm"),eph:j().default("1.60mm"),string:j().optional(),ep:Je().default(!1)}),sFn=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=rFn.parse({...t,num_pins:n}),i=_e.parse(o.w),r=_e.parse(o.h),s=_e.parse(o.p),a=_e.parse(o.pl),c=_e.parse(o.pw),l=_e.parse(o.epw),A=_e.parse(o.eph),u=[];for(let N=0;N<o.num_pins;N++){const{x:F,y:O}=_5e(o.num_pins,N+1,i,s);u.push(Bo(N+1,F,O,a,c))}o.ep&&u.push(Bo(o.num_pins+1,0,0,l,A));const _=i,h=r,d={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-_/2,y:h/2},{x:_/2,y:h/2}],stroke_width:.05,pcb_silkscreen_path_id:""},m={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-_/2,y:-h/2},{x:_/2,y:-h/2}],stroke_width:.05,pcb_silkscreen_path_id:""},p=_5e(o.num_pins,1,_,s),g={x:p.x-.4,y:p.y},y={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"pin_marker_1",route:[{x:g.x-.4,y:g.y},{x:g.x-.7,y:g.y+.3},{x:g.x-.7,y:g.y-.3},{x:g.x-.4,y:g.y}],stroke_width:.05,pcb_silkscreen_path_id:"pin_marker_1"},f=ai(0,h/2+.5,.3),x=Math.abs(_5e(o.num_pins,1,i,s).x),I=(o.num_pins/2-1)*s+c,E=x*2+a,b=i/2+.25,P=E/2+.25,B=I/2+.25,w=r/2+.25,k={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",layer:"top",outline:p1([{minX:-P,maxX:P,minY:-B,maxY:B},{minX:-b,maxX:b,minY:-w,maxY:w}])};return{circuitJson:[...u,d,m,f,y,k],parameters:o}},_5e=(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*_e.parse("1.4mm"),y:a*o}},aFn=ti.extend({fn:j(),num_pins:ut().optional().default(8),p:nt.describe("pitch (distance between center of each pin)"),w:_e.describe("width between vertical rows of pins"),grid:FX.describe("width and height of the border of the footprint"),ep:FX.default("0x0mm").describe("width and height of the central exposed thermal pad"),epx:_e.default("0mm").describe("x offset of the center of the central exposed thermal pad"),pinw:_e.describe("width of the pin pads"),pinh:_e.describe("height of the pin pads")}),cFn=t=>{const e=aFn.parse(t),{num_pins:n,p:o,w:i,grid:r,ep:s,epx:a,pinw:c,pinh:l}=e;if(n%2!==0)throw new Error("invalid number of pins");const A=[];for(let b=0;b<n;b++){const{pinX:P,pinY:B}=lFn({pinCount:n,pinIndex:b,width:i,pitch:o});A.push(Bo(b+1,P,B,c,l))}s.x>0&&s.y>0&&A.push(Bo(e.num_pins+1,a,0,s.x,s.y));const u=AFn(r),_=ai(0,r.y/2+o,r.y/6),h=(n/2-1)*o+l,d=i+c,m=r.x/2+.25,p=d/2+.25,g=h/2+.25,y=h/2+.45+Math.max(0,.8-o),f=Math.min(r.y/2+.25,y),x=Math.max(0,.37-Math.max(0,p-m-.38)*1.4),I=Math.max(g,f-x),E={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",layer:"top",outline:p1([{minX:-p,maxX:p,minY:-I,maxY:I},{minX:-m,maxX:m,minY:-f,maxY:f}])};return{circuitJson:[...A,...u,_,E],parameters:e}},lFn=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}},AFn=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}]},uFn=t=>{const{num_pins:e,bridged:n,p:o=2.54,pw:i=1.5,ph:r=1.5}=t,s=_e.parse(o),a=_e.parse(i),c=_e.parse(r),l=Math.min(c/4,.5),A=[];for(let w=0;w<e;w++)A.push(Bo(w+1,w*s,0,a,c));let u=[];if(n){const w=n.split("").map(Number);if(w.length>1)for(let k=0;k<w.length-1;k++){const N=w[k],F=w[k+1];if(typeof N=="number"&&typeof F=="number"&&!isNaN(N)&&!isNaN(F)){const O=(N-1)*s,G=(F-1)*s,K=Math.sign(G-O),X=O+K*(a/2),$=G-K*(a/2);u.push({type:"pcb_trace",pcb_trace_id:"",route:[{start_pcb_port_id:`{PIN${N}}`,x:X,y:0,width:l,layer:"top",route_type:"wire"},{end_pcb_port_id:`{PIN${F}}`,x:$,y:0,width:l,layer:"top",route_type:"wire"}]})}}}const _=(e-1)*s+a+.7,h=c+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-_/2,y:m-h/2},{x:d+_/2,y:m-h/2},{x:d+_/2,y:m+h/2},{x:d-_/2,y:m+h/2},{x:d-_/2,y:m-h/2}],stroke_width:.15},y=m+h/2+.6,f=ai(d,y,.4),x=(e-1)*s,I=x/2+a/2,E=c/2,b=I+.5,P=E+.5,B={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:x/2,y:0},width:2*b,height:2*P,layer:"top"};return{circuitJson:[...A,...u,p,f,B],parameters:t}},X_t={fn:tt("sot457"),num_pins:tt(6).default(6),pillh:j().default("0.45mm"),pillw:j().default("1.45mm"),pl:j(),pw:j(),p:j(),wave:Je().optional(),reflow:Je().optional()},_Fn=ti.extend({...X_t,h:j().default("2.5mm"),w:j().default("2.7mm"),pl:j().default("0.8mm"),pw:j().default("0.55mm"),p:j().default("0.95mm")}),dFn=ti.extend({...X_t,h:j().default("3mm"),w:j().default("4mm"),pillr:j().default("0.225mm"),pl:j().default("1.45mm"),pw:j().default("1.5mm"),p:j().default("1.475mm")}).transform(t=>({...t,wave:t.wave??(t.reflow===void 0?!0:!t.reflow),reflow:t.reflow??(t.wave===void 0?!1:!t.wave)})),$E=t=>Number.parseFloat(t.replace("mm","")),J_t=({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},q_t=t=>{const e=[],n=$E(t.p),o=$E(t.pl),i=$E(t.pw),r=$E(t.w),s=$E(t.h);if(t.wave){const m={1:({padWidth:p,padHeight:g})=>Bo(1,-n,n,g,p),2:({padWidth:p,padHeight:g})=>Bo(2,-n,-n,g,p),3:({padWidth:p,padHeight:g})=>OX(3,-n,0,$E(t.pillw),$E(t.pillh)),4:({padWidth:p,padHeight:g})=>OX(4,n,0,$E(t.pillw),$E(t.pillh)),5:({padWidth:p,padHeight:g})=>Bo(5,n,n,g,p),6:({padWidth:p,padHeight:g})=>Bo(6,n,-n,g,p)};for(let p=1;p<=t.num_pins;p++){const g=m[p];g&&e.push(g({padWidth:o,padHeight:i}))}}else for(let m=1;m<=t.num_pins;m++){const{x:p,y:g}=J_t({pitch:n,width:r,pinNumber:m});e.push(Bo(m,p,g,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},c={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},l=ai(0,s+.5,.3),A=J_t({pitch:n,width:r,pinNumber:1}),u=t.wave?1:.5,_=t.wave?.7:.3;A.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:A.x+u/2,y:A.y},{x:A.x-u/2,y:A.y+_/2},{x:A.x-u/2,y:A.y-_/2},{x:A.x+u/2,y:A.y}],stroke_width:.05};let d;if(t.wave){const m=2*n,p=2*n,g=m/2+i/2,y=p/2+o/2,f=g+.25,x=y+.25;d={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:0,y:0},width:2*f,height:2*x,layer:"top"}}else{const p=r/2+.1+o/2,g=n+i/2,y=r/2,f=s/2,x=p+.25,I=y+.08,E=g+.25,b=Math.max(f+.45,E);d={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",outline:p1([{minX:-x,maxX:x,minY:-E,maxY:E},{minX:-I,maxX:I,minY:-b,maxY:b}]),layer:"top"}}return[l,a,c,h,...e,d]},hFn=t=>{if(t.wave){const n=dFn.parse({...t,fn:"sot457"});return{circuitJson:q_t(n),parameters:n}}const e=_Fn.parse(t);return{circuitJson:q_t(e),parameters:e}},mFn=[{x:-.8,y:.75},{x:.8,y:.75},{x:.8,y:-.75},{x:-.8,y:-.75}],gFn=ti.extend({fn:j(),num_pins:tt(6).default(6),w:j().default("1.1mm"),h:j().default("1.45mm"),p:j().default("0.35mm"),pl:j().default("0.2mm"),pw:j().default("0.2mm"),string:j().optional()}),pFn=t=>{const e=gFn.parse({...t,fn:"sot963"}),n=_e.parse(e.w),o=_e.parse(e.h),i=_e.parse(e.p),r=_e.parse(e.pl),s=_e.parse(e.pw),a=[];for(let d=0;d<6;d++){const{x:m,y:p}=$_t(d+1,n,i,r);a.push(Bo(d+1,m,p,r,s))}const 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={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:""},A=$_t(1,n,i,r),u={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"pin_marker_1",route:[{x:A.x-r/2-.3,y:A.y},{x:A.x-r/2-.45,y:A.y+.15},{x:A.x-r/2-.45,y:A.y-.15},{x:A.x-r/2-.3,y:A.y}],stroke_width:.05,pcb_silkscreen_path_id:"pin_marker_1"},_=ai(0,o/2+.4,.25),h={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",outline:mFn,layer:"top"};return{circuitJson:[...a,c,l,_,u,h],parameters:e}},$_t=(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}},fFn=ti.extend({fn:j(),num_pins:ho([tt(3),tt(2)]).default(3),p:j().default("3.8mm"),id:j().default("1.25mm"),od:j().default("2.35mm"),ca:j().default("14mm").describe("Caliper axis (width or diameter of the potentiometer body or adjustment knob)"),w:j().default("5.35mm"),h:j().default("4mm"),string:j().optional()}),yFn=t=>{const{p:e,id:n,od:o,h:i,ca:r}=t,s=Number.parseFloat(i),a=Number.parseFloat(r);return[ns(1,0,a/4+.3,n,o),ns(2,s,0,n,o),ns(3,0,-a/4-.3,n,o)]},xFn=t=>{const e=t.string?.match(/^potentiometer_(\d+)/),n=e?Number.parseInt(e[1],10):3,o=fFn.parse({...t,num_pins:n});let i=[];o.num_pins===3&&(i=yFn(o));const r=Number.parseFloat(o.ca)/2+.15,s=Number.parseFloat(o.w),a=Number.parseFloat(o.od)/2+.35,c={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:""},l={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:""},A=Number.parseFloat(o.w)/2,u=ai(A,r+1,.5),_=Number.parseFloat(o.od)/2,h=Number.parseFloat(o.h),d=Number.parseFloat(o.ca)/2,m=-(_+.25),p=h+_+.25,g=d+.25,y={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:(m+p)/2,y:0},width:p-m,height:2*g,layer:"top"};return{circuitJson:[...i,c,l,u,y],parameters:o}},CFn=ti.extend({fn:j(),p:_e.optional().default("7.5mm"),id:_e.optional().default("1mm"),od:_e.optional().default("2mm"),d:_e.optional().default("10.5mm")}),IFn=(t,e,n,o,i)=>{const r=[],s=[];for(let a=0;a<=50;a++){const c=a/50*Math.PI,l=t+Math.cos(c)*n,A=e+Math.sin(c)*n;l<t-o&&A>=e-i/2&&A<=e+i/2||r.push({x:l,y:A})}for(let a=0;a<=50;a++){const c=Math.PI+a/50*Math.PI,l=t+Math.cos(c)*n,A=e+Math.sin(c)*n;l<t-o&&A>=e-i/2&&A<=e+i/2||s.push({x:l,y:A})}return{topArc:r,bottomArc:s}},EFn=t=>{const e=CFn.parse(t),{p:n,id:o,od:i,d:r}=e,s=[ns(1,-n/2,0,o,i),ns(2,n/2,0,o,i)],{topArc:a,bottomArc:c}=IFn(0,0,r/2+.1,i/2,i),l={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:a,stroke_width:.1,pcb_silkscreen_path_id:""},A={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:c,stroke_width:.1,pcb_silkscreen_path_id:""},u={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:""},_=-(r/2+.5),h=i/2+1.5,d=.5,m={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:_-d,y:h},{x:_+d,y:h}],stroke_width:.1,pcb_silkscreen_path_id:""},p={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:_,y:h-d},{x:_,y:h+d}],stroke_width:.1,pcb_silkscreen_path_id:""},g=ai(0,r/2+1,.5),y=r/2,f=n/2+i/2,I=Math.max(y,f)+.25,E={type:"pcb_courtyard_circle",pcb_courtyard_circle_id:"",pcb_component_id:"",center:{x:0,y:0},radius:I,layer:"top"};return{circuitJson:[...s,l,A,u,m,p,g,E],parameters:e}},bFn=ti.extend({fn:j(),num_pins:tt(2).default(2),w:j().default("6.5mm"),h:j().default("3mm"),pl:j().default("1.75mm"),pw:j().default("2.40mm"),p:j().default("4.75mm")}),SFn=t=>{const e=bFn.parse(t),n=ai(0,_e.parse(e.h)-.5,.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:_e.parse(e.p)/2,y:_e.parse(e.h)/2},{x:-_e.parse(e.w)/2-.3,y:_e.parse(e.h)/2},{x:-_e.parse(e.w)/2-.3,y:-_e.parse(e.h)/2},{x:_e.parse(e.p)/2,y:-_e.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:vFn(e).concat(o,n,s),parameters:e}},PFn=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},vFn=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=PFn({pn:n,p:Number.parseFloat(t.p)});e.push(Bo(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return e},BFn=[{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}],MFn=ti.extend({fn:j(),num_pins:ut().default(3),w:j().default("2.45mm"),h:j().default("2.40mm"),pl:j().default("0.92mm"),pw:j().default("0.45mm"),p:j().default("0.891mm"),string:j().optional()}),wFn=t=>{const e=t.string?.match(/^sot323_(\d+)/),n=e?Number.parseInt(e[1],3):3,o=MFn.parse({...t,num_pins:n});if(o.num_pins===3)return{circuitJson:TFn(o),parameters:o};throw new Error("Invalid number of pins")},DFn=t=>{const{pn:e,p:n}=t;return e===1?{x:-n,y:.65}:e===2?{x:-n,y:-.65}:{x:n,y:0}},TFn=t=>{const e=[];for(let c=0;c<t.num_pins;c++){const{x:l,y:A}=DFn({num_pins:t.num_pins,pn:c+1,w:Number.parseFloat(t.w),h:Number.parseFloat(t.h),pl:Number.parseFloat(t.pl),p:Number.parseFloat(t.p)});e.push(Bo(c+1,l,A,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}const n=ai(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:BFn,layer:"top"};return[...e,r,s,n,a]},QFn=ti.extend({fn:j(),circle:Je().optional(),rect:Je().optional(),square:Je().optional(),pill:Je().optional(),d:_e.optional(),pd:_e.optional(),diameter:_e.optional(),r:_e.optional(),pr:_e.optional(),radius:_e.optional(),w:_e.optional(),pw:_e.optional(),width:_e.optional(),h:_e.optional(),ph:_e.optional(),height:_e.optional(),s:_e.optional(),size:_e.optional(),string:j().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=Ma(t.r):t.pr!==void 0?n=Ma(t.pr):t.radius!==void 0?n=Ma(t.radius):t.d!==void 0?n=Ma(t.d)/2:t.pd!==void 0?n=Ma(t.pd)/2:t.diameter!==void 0?n=Ma(t.diameter)/2:n=Ma("1mm")/2:(t.w!==void 0?o=Ma(t.w):t.pw!==void 0?o=Ma(t.pw):t.width!==void 0?o=Ma(t.width):t.s!==void 0?o=Ma(t.s):t.size!==void 0?o=Ma(t.size):o=Ma("1mm"),t.h!==void 0?i=Ma(t.h):t.ph!==void 0?i=Ma(t.ph):t.height!==void 0?i=Ma(t.height):e==="square"||e==="rect"?i=o:i=Ma("1mm")),{fn:t.fn,shape:e,radius:n,width:o,height:i}}),RFn=t=>{const e=QFn.parse(t),{shape:n,radius:o,width:i,height:r}=e;let s,a;return n==="circle"?(s=D_t(1,{x:0,y:0,radius:o}),a=o+.5):n==="pill"?(s=OX(1,0,0,i,r),a=Math.max(i,r)/2+.5):(s=Bo(1,0,0,i,r),a=r/2+.5),{circuitJson:[s,ai(0,a,.2)],parameters:e}},NFn=ti.extend({fn:j(),d:_e.optional(),hd:_e.optional(),r:_e.optional(),hr:_e.optional(),pd:_e.optional(),pr:_e.optional(),squarepad:Je().optional().default(!1)}).transform(t=>{let e;t.d!==void 0?e=Ma(t.d):t.hd!==void 0?e=Ma(t.hd):t.r!==void 0?e=Ma(t.r)*2:t.hr!==void 0?e=Ma(t.hr)*2:e=Ma("1mm");let n;return t.pd!==void 0?n=Ma(t.pd):t.pr!==void 0?n=Ma(t.pr)*2:n=e*(1.5/1),{fn:t.fn,d:e,pd:n,squarepad:t.squarepad??!1}}),kFn=t=>{const e=NFn.parse(t),{d:n,pd:o,squarepad:i}=e;return{circuitJson:[i?_C({pn:1,x:0,y:0,holeDiameter:n,rectPadWidth:o,rectPadHeight:o}):ns(1,0,0,n,o),ai(0,o/2+.5,.2)],parameters:e}},HFn=ti.extend({fn:j(),num_pins:tt(6).default(6),h:j().default("1.3mm"),pl:j().default("1.325mm"),pw:j().default("0.6mm"),p:j().default("0.95mm")}),LFn=t=>{const e=HFn.parse(t);return{circuitJson:FFn(e),parameters:e}},Z_t=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")},FFn=t=>{const e=[];for(let b=1;b<=t.num_pins;b++){const{x:P,y:B}=Z_t({h:Number.parseFloat(t.h),p:Number.parseFloat(t.p),pn:b});e.push(Bo(b,P,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=ai(0,o+.3,.3),a=Z_t({h:Number.parseFloat(t.h),p:Number.parseFloat(t.p),pn:1});a.x=a.x-Number.parseFloat(t.pw)*1.5;const c=.7,l=.3,A={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"pin1_indicator",route:[{x:a.x+c/2-.2,y:a.y},{x:a.x-c/2,y:a.y+l/2},{x:a.x-c/2,y:a.y-l/2},{x:a.x+c/2-.2,y:a.y}],stroke_width:.05},u=Number.parseFloat(t.h),_=Number.parseFloat(t.p),h=Number.parseFloat(t.pl),d=Number.parseFloat(t.pw),m=u/2+.4875,p=_*2+d,g=m+h/2,y=u/2+.4,f=g+.25,x=p/2+.25,I=x+.2,E={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",layer:"top",outline:p1([{minX:-f,maxX:f,minY:-x,maxY:x},{minX:-y,maxX:y,minY:-I,maxY:I}])};return[...e,s,i,r,A,E]},OFn=[{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}],GFn=ti.extend({fn:j(),num_pins:ut().default(4),w:j().default("3.2mm"),h:j().default("2.6mm"),pl:j().default("1.05mm"),pw:j().default("0.45mm"),p:j().default("0.55mm"),string:j().optional()}),zFn=t=>{const e=t.string?.match(/^sot343_(\d+)/),n=e?Number.parseInt(e[1],4):4,o=GFn.parse({...t,num_pins:n});if(o.num_pins===4)return{circuitJson:VFn(o),parameters:o};throw new Error("Invalid number of pins")},UFn=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}},VFn=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,c=-1/0,l=1/0,A=-1/0;for(let x=0;x<t.num_pins;x++){const{x:I,y:E}=UFn({num_pins:t.num_pins,pn:x+1,p:s});e.push(Bo(x+1,I,E,i,r)),I<a&&(a=I),I>c&&(c=I),E<l&&(l=E),E>A&&(A=E)}const u=(a+c)/2,_=A-l,h=o*.3,d=_/2+h;let m=n*.8;o<=2.6&&(m/=2);const p=ai(u,d+.5,.3),g={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_top",route:[{x:u-m/2,y:d},{x:u+m/2,y:d}],type:"pcb_silkscreen_path",stroke_width:.1},y={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_bottom",route:[{x:u-m/2,y:-d},{x:u+m/2,y:-d}],type:"pcb_silkscreen_path",stroke_width:.1},f={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",outline:OFn,layer:"top"};return[...e,g,y,p,f]},YFn=ti.extend({fn:j()}),KFn=t=>{const e=YFn.parse(t),n=[],o=.5-.15,i=1.5,s=.5/2,a=75,c=-37/2;for(let b=0;b<a;b++){const P=b+1;if(P>=24&&P<=31)continue;const B=c-b*s,w=P%2===0,k=i+(w?.25:0),F=.5-k/2,O=Bo(P,F,B,k,o);O.layer=w?"bottom":"top",n.push(O)}const l=46*.0254,A=137*.0254,u=261*.0254,_={type:"pcb_cutout",pcb_cutout_id:"",shape:"rect",center:{x:-A/2+i/2,y:c-u},width:A,height:l},h={x:-.5,y:c},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,g=1/0,y=-1/0;const f=(b,P,B=0,w=0)=>{m=Math.min(m,b-B/2),p=Math.max(p,b+B/2),g=Math.min(g,P-w/2),y=Math.max(y,P+w/2)};for(const b of n){const P=b;f(P.x,P.y,P.width,P.height)}f(_.center.x,_.center.y,_.width,_.height);for(const b of d.route)f(b.x,b.y);const x=(m+p)/2,I=(g+y)/2,E=b=>{typeof b.x=="number"&&(b.x-=x),typeof b.y=="number"&&(b.y-=I),b.center&&(b.center.x-=x,b.center.y-=I),Array.isArray(b.route)&&(b.route=b.route.map(P=>({x:P.x-x,y:P.y-I})))};for(const b of n)E(b);return E(_),E(d),{circuitJson:[...n,_,d],parameters:e}},WFn=ti.extend({fn:j(),numPins:ut().optional().default(0),rows:ho([j(),ut()]).transform(t=>Number(t)).optional().default(1).describe("number of rows"),p:_e.default("2.54mm").describe("pitch"),id:_e.default("1.0mm").describe("inner diameter"),od:_e.default("1.5mm").describe("outer diameter"),male:Je().optional().describe("the module uses male headers"),nopin:Je().optional().default(!1).describe("omit pins rendering"),female:Je().optional().describe("the module uses female headers"),smd:Je().optional().describe("surface mount device"),pinlabeltextalignleft:Je().optional().default(!1),pinlabeltextaligncenter:Je().optional().default(!1),pinlabeltextalignright:Je().optional().default(!1),pinlabelverticallyinverted:Je().optional().default(!1),pinlabelorthogonal:Je().optional().default(!1),nopinlabels:Je().optional().default(!1).describe("omit silkscreen pin labels"),doublesidedpinlabel:Je().optional().default(!1).describe("add silkscreen pins in top and bottom layers"),bottomsidepinlabel:Je().optional().default(!1).describe("place the silkscreen reference text on the bottom layer instead of top"),pinRowSide:Nn(["left","right","top","bottom"]).optional().default("left"),pinrowleft:Je().optional().default(!1),pinrowright:Je().optional().default(!1),pinrowtop:Je().optional().default(!1),pinrowbottom:Je().optional().default(!1),pinrowleftpins:ho([j(),ut()]).transform(t=>Number(t)).optional(),pinrowrightpins:ho([j(),ut()]).transform(t=>Number(t)).optional(),pinrowtoppins:ho([j(),ut()]).transform(t=>Number(t)).optional(),pinrowbottompins:ho([j(),ut()]).transform(t=>Number(t)).optional(),width:_e.optional(),height:_e.optional(),pinRowHoleEdgeToEdgeDist:_e.default("2mm"),holes:ho([j(),$t(j())]).optional().transform(t=>!t||Array.isArray(t)?t:t.startsWith("(")&&t.endsWith(")")?t.slice(1,-1).split(",").map(e=>e.trim()):[t]),holeXDist:_e.optional(),holeYDist:_e.optional(),holeInset:_e.default("1mm"),pinrow:ho([j(),ut()]).optional(),usbposition:Nn(["left","right","top","bottom"]).optional().default("left"),usbleft:Je().optional().default(!1),usbtop:Je().optional().default(!1),usbright:Je().optional().default(!1),usbbottom:Je().optional().default(!1),usbtype:Nn(["micro","c"]).optional(),usbmicro:Je().optional().default(!1),usbc:Je().optional().default(!1),screen:Je().optional().default(!1).describe("add silkscreen outline for screen/display area"),screenwidth:_e.optional(),screenheight:_e.optional(),screencenteroffsetx:_e.optional(),screencenteroffsety:_e.optional()}).transform(t=>{const e=O_t(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(x=>x!==void 0&&x>0),a=(r.left??0)>0&&(r.right??0)>0,c=(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 l=Math.ceil(t.numPins/t.rows),A=Math.max(r.left??0,r.right??0),u=Math.max(r.top??0,r.bottom??0);let _,h;if(s){const x=a?t.p:0,I=c?t.p:0;_=(u>0?(u-1)*t.p:0)+2*t.pinRowHoleEdgeToEdgeDist+x,h=(A>0?(A-1)*t.p:0)+2*t.pinRowHoleEdgeToEdgeDist+I}else n==="left"||n==="right"?(_=(t.rows-1)*t.p+2*t.pinRowHoleEdgeToEdgeDist,h=(l-1)*t.p+2*t.pinRowHoleEdgeToEdgeDist):(h=(t.rows-1)*t.p+2*t.pinRowHoleEdgeToEdgeDist,_=(l-1)*t.p+2*t.pinRowHoleEdgeToEdgeDist);t.numPins===0&&(_=10,h=10);const d=t.width??_,m=t.height??h,p=t.screenwidth??d*.95,g=t.screenheight??m*.95,y=t.screencenteroffsetx??0,f=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:g,screencenteroffsetx:y,screencenteroffsety:f,pinrowleftpins:r.left,pinrowrightpins:r.right,pinrowtoppins:r.top,pinrowbottompins:r.bottom}}).superRefine((t,e)=>{t.male&&t.female&&e.addIssue({code:_o.custom,message:"'male' and 'female' cannot both be true; it should be male or female.",path:["male","female"]})}),jFn=t=>{const e=WFn.parse(t),{p:n,id:o,od:i,rows:r,numPins:s,pinlabelAnchorSide:a,pinlabelverticallyinverted:c,pinlabelorthogonal:l,pinlabeltextalignleft:A,pinlabeltextalignright:u,nopinlabels:_,doublesidedpinlabel:h,bottomsidepinlabel:d,pinRowSide:m,width:p,height:g,pinRowHoleEdgeToEdgeDist:y,holes:f,holeXDist:x,holeYDist:I,holeInset:E,pinrowleftpins:b,pinrowrightpins:P,pinrowtoppins:B,pinrowbottompins:w,usbposition:k,usbtype:N,screen:F,screenwidth:O,screenheight:G,screencenteroffsetx:K,screencenteroffsety:X}=e;let $="center";A?$="left":u&&($="right");const oe=[],Ae={left:b,right:P,top:B,bottom:w},Z=Object.values(Ae).some(ce=>ce!==void 0&&ce>0),se=(ce,ge,be,ve)=>{if(e.smd?oe.push(Bo(ce,ge,be,e.od,e.od)):ce===1?oe.push(_C({pn:ce,x:ge,y:be,holeDiameter:o,rectPadWidth:i,rectPadHeight:i})):oe.push(ns(ce,ge,be,o,i)),!_){const Me=ge+(ve==="left"?-i:ve==="right"?i:0),ue=be+(ve==="top"?i:ve==="bottom"?-i:0);d||oe.push(gB({fs:i/5,pn:ce,anchor_x:Me,anchor_y:ue,textalign:$,orthogonal:l,verticallyinverted:c,layer:"top"})),(h||d)&&oe.push(gB({fs:i/5,pn:ce,anchor_x:Me,anchor_y:ue,textalign:$,orthogonal:l,verticallyinverted:c,layer:"bottom"}))}};if(Z){const ce=n;let ge=1;const be=Ae.left??0,ve=Ae.right??0,Me=Ae.top??0,ue=Ae.bottom??0,Ie=(pe,Le)=>{if(!(Le<=0))if(pe==="left"||pe==="right"){const Ue=pe==="left"?-p/2+y:p/2-y,je=(Le-1)/2*ce;for(let ye=0;ye<Le;ye++)se(ge,Ue,je-ye*ce,pe),ge++}else{const Ue=pe==="top"?g/2-y:-g/2+y,je=-((Le-1)/2)*ce;for(let ye=0;ye<Le;ye++)se(ge,je+ye*ce,Ue,pe),ge++}};Ie("left",be),Ie("right",ve),Ie("top",Me),Ie("bottom",ue)}else{const ce=n;let ge=0,be=0,ve=0,Me=0,ue=0,Ie=0;const pe=Math.ceil(s/r);m==="left"||m==="right"?(ge=m==="left"?-p/2+y:p/2-y,be=(pe-1)/2*ce,ve=0,Me=-ce,ue=m==="left"?ce:-ce,Ie=0):(ge=-(pe-1)/2*ce,be=m==="top"?g/2-y:-g/2+y,ve=ce,Me=0,ue=0,Ie=m==="top"?-ce:ce);let Le=1;for(let Ue=0;Ue<r&&Le<=s;Ue++)for(let je=0;je<pe&&Le<=s;je++){const ye=ge+je*ve+Ue*ue,$e=be+je*Me+Ue*Ie;if(e.smd?oe.push(Bo(Le,ye,$e,e.od,e.od)):Le===1?oe.push(_C({pn:Le,x:ye,y:$e,holeDiameter:o,rectPadWidth:i,rectPadHeight:i})):oe.push(ns(Le,ye,$e,o,i)),!_){const Fe=ye+(m==="left"?-i:m==="right"?i:0),De=$e+(m==="top"?i:m==="bottom"?-i:0);d||oe.push(gB({fs:i/5,pn:Le,anchor_x:Fe,anchor_y:De,textalign:$,orthogonal:l,verticallyinverted:c,layer:"top"})),(h||d)&&oe.push(gB({fs:i/5,pn:Le,anchor_x:Fe,anchor_y:De,textalign:$,orthogonal:l,verticallyinverted:c,layer:"bottom"}))}Le++}}if(f)for(const ce of f){let ge=0,be=0;ce==="topleft"?(ge=-p/2+E,be=g/2-E):ce==="topright"?(ge=p/2-E,be=g/2-E):ce==="bottomleft"?(ge=-p/2+E,be=-g/2+E):ce==="bottomright"?(ge=p/2-E,be=-g/2+E):ce==="center"&&(ge=0,be=0),x!==void 0&&(ge+=x),I!==void 0&&(be+=I),oe.push(ns(s+f.indexOf(ce)+1,ge,be,o,i))}if(!e.nosilkscreen){const ce=[{x:-p/2,y:-g/2},{x:p/2,y:-g/2},{x:p/2,y:g/2},{x:-p/2,y:g/2},{x:-p/2,y:-g/2}];oe.push(pB(ce,{stroke_width:.1,layer:"top"}))}const ae=ai(0,g/2+1,.5);if(oe.push(ae),k&&N){let ce,ge;if(N==="c")ce=8,ge=3;else if(N==="micro")ce=6,ge=2;else return{circuitJson:oe,parameters:e};let be;if(k==="left")be=[{x:-p/2,y:-ce/2},{x:-p/2+ge,y:-ce/2},{x:-p/2+ge,y:ce/2},{x:-p/2,y:ce/2},{x:-p/2,y:-ce/2}];else if(k==="right")be=[{x:p/2-ge,y:-ce/2},{x:p/2,y:-ce/2},{x:p/2,y:ce/2},{x:p/2-ge,y:ce/2},{x:p/2-ge,y:-ce/2}];else if(k==="top")be=[{x:-ce/2,y:g/2-ge},{x:ce/2,y:g/2-ge},{x:ce/2,y:g/2},{x:-ce/2,y:g/2},{x:-ce/2,y:g/2-ge}];else if(k==="bottom")be=[{x:-ce/2,y:-g/2},{x:ce/2,y:-g/2},{x:ce/2,y:-g/2+ge},{x:-ce/2,y:-g/2+ge},{x:-ce/2,y:-g/2}];else return{circuitJson:oe,parameters:e};oe.push(pB(be,{stroke_width:.1,layer:"top"}))}if(F){const ce=O/2,ge=G/2,be=K,ve=X,Me=[{x:-ce+be,y:-ge+ve},{x:ce+be,y:-ge+ve},{x:ce+be,y:ge+ve},{x:-ce+be,y:ge+ve},{x:-ce+be,y:-ge+ve}];oe.push(pB(Me,{stroke_width:.05,layer:"top"}))}return{circuitJson:oe,parameters:e}},XFn=[{x:-1.45,y:2.75},{x:-1.45,y:-1.85},{x:4.05,y:-1.85},{x:4.05,y:2.75}],JFn=[{x:-1.55,y:2.75},{x:-1.55,y:-1.85},{x:3.95,y:-1.85},{x:3.95,y:2.75}],qFn=ti.extend({fn:j(),num_pins:ut().default(3),inline:Je().default(!1),p:j().default("1.27mm"),id:j().default("0.75mm"),od:j().default("1.3mm"),w:j().default("4.8mm"),h:j().default("4.0mm")}),$Fn=t=>{const e=qFn.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=[_C({pn:1,x:0,y:0,holeDiameter:e.id,rectPadWidth:r,rectPadHeight:s}),e.inline?fB(2,n,0,Number.parseFloat(e.id),r,s):ns(2,n,n,e.id,r),e.inline?fB(3,n*2,0,Number.parseFloat(e.id),r,s):ns(3,n*2,0,e.id,r)],c=o/2,l=e.inline?n-.09:n,A=.2,u=A+c-i,_=Array.from({length:32},(p,g)=>{const y=Math.PI*g/31;return{x:l+c*Math.cos(y),y:A+c*Math.sin(y)}}),h={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"",stroke_width:.12,route:[..._,{x:l-c,y:u},{x:l+c,y:u},_[0]]},d=ai(l,A+c+1,.5),m={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",outline:e.inline?JFn:XFn,layer:"top"};return{circuitJson:[...a,h,d,m],parameters:e}},ZFn=(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},eOn=(t,e)=>e.nosilkscreen?t.filter(n=>n.type!=="pcb_silkscreen_path"&&n.type!=="pcb_silkscreen_text"):t,tOn=(t,e)=>{if(!e)return t;const n=t.filter(A=>A.type==="pcb_smtpad"||A.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=(A,u,_=0,h=0)=>{const d=A-_/2,m=A+_/2,p=u-h/2,g=u+h/2;o=Math.min(o,d),i=Math.max(i,m),r=Math.min(r,p),s=Math.max(s,g)};for(const A of n)if(A.type==="pcb_smtpad"){const u=A.shape==="circle"?A.radius*2:A.width,_=A.shape==="circle"?A.radius*2:A.height;a(A.x,A.y,u,_)}else if(A.type==="pcb_plated_hole"){const u=A.outer_diameter??A.hole_diameter;a(A.x,A.y,u,u)}let c=0,l=0;switch(e){case"center":c=(o+i)/2,l=(r+s)/2;break;case"bottomleft":c=o,l=r;break;case"bottomcenter":case"centerbottom":c=(o+i)/2,l=r;break;case"topcenter":case"centertop":c=(o+i)/2,l=s;break;case"leftcenter":case"centerleft":c=o,l=(r+s)/2;break;case"rightcenter":case"centerright":c=i,l=(r+s)/2;break;case"pin1":{const A=n.find(u=>u.port_hints?.[0]==="1")||n[0];c=A.x,l=A.y;break}}if(c===0&&l===0)return t;for(const A of t){if(typeof A.x=="number"&&(A.x-=c),typeof A.y=="number"&&(A.y-=l),A.center&&typeof A.center.x=="number"&&(A.center.x-=c,A.center.y-=l),A.type==="pcb_silkscreen_path")for(const u of A.route)u.x-=c,u.y-=l;A.type==="pcb_silkscreen_text"&&A.anchor_position&&(A.anchor_position.x-=c,A.anchor_position.y-=l)}return t};function nOn(t){return t!=null}var oOn=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"),iOn=t=>{let e=UX();const n=oOn(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,c]=s;if(!a)return null;const l=a.toLowerCase();return c?.includes("?")?null:{fn:l,v:c}}).filter(nOn);for(const{fn:r,v:s}of i)e=e[r](s);return e.setString(n),e},rOn=()=>Object.keys(qE),UX=()=>{const t=new Proxy({},{get:(e,n)=>{if(n==="soup"||n==="circuitJson"){if("fn"in e&&qE[e.fn])return()=>{const{circuitJson:o}=qE[e.fn](e),i=eOn(o,e),r=ZFn(i,e);return tOn(r,e.origin)};if(!qE[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(!qE[e.fn])throw new Error(`Invalid footprint function, got "${e.fn}"${e.string?`, from string "${e.string}"`:""}`);return()=>qE[e.fn](e).parameters}return n==="getFootprintNames"?()=>Object.keys(qE):n==="params"?()=>e:n==="setString"?o=>(e.string=o,t):o=>(Object.keys(e).length===0?`${n}${o}`in qE?(e[`${n}${o}`]=!0,e.fn=`${n}${o}`):(e[n]=!0,e.fn=n,n==="res"||n==="cap"?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};UX.string=iOn,UX.getFootprintNames=rOn;var sOn=UX,edt=Symbol("Fragment");function d5e(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 ln=Symbol("Cuboid"),tdt=Symbol("Cube"),rl=Symbol("Cylinder"),VX=Symbol("Sphere"),Uk=Symbol("RoundedCuboid"),Wo=Symbol("Translate"),W_=Symbol("Rotate"),bh=Symbol("Union"),df=Symbol("Subtract"),kl=Symbol("Hull"),Cr=Symbol("Colorize"),Vk=Symbol("Polygon"),Yk=Symbol("ExtrudeLinear"),H2=Symbol("RoundedCylinder"),or=edt,Ve=(t,e,n)=>d5e(t,e),Jn=(t,e,n)=>d5e(t,e),aOn=({hole:t,isPin1:e})=>{const n=e?"#00ff00":"#b87333";if(t.shape==="circle")return Ve(Cr,{color:n,children:Ve(Wo,{offset:[t.x,t.y,-.005],children:Jn(df,{children:[Ve(rl,{radius:t.outer_diameter/2,height:.01}),Ve(rl,{radius:t.hole_diameter/2,height:.01})]})})});if(t.shape==="circular_hole_with_rect_pad")return Ve(Cr,{color:n,children:Ve(Wo,{offset:[t.x,t.y,0],children:Jn(df,{children:[Ve(ln,{size:[t.rect_pad_width,t.rect_pad_height,.01],center:[0,0,0]}),Ve(rl,{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,c=t.hole_height??.8;return Ve(Cr,{color:n,children:Ve(Wo,{offset:[t.x,t.y,0],children:Jn(df,{children:[Jn(kl,{children:[Ve(rl,{radius:r,height:.01,center:[s?-(o/2-r):0,s?0:-(i/2-r),0]}),Ve(rl,{radius:r,height:.01,center:[s?o/2-r:0,s?0:i/2-r,0]})]}),a===c?Ve(rl,{radius:a/2,height:.01}):Jn(kl,{children:[Ve(rl,{radius:Math.min(a,c)/2,height:.01,center:[a>c?-(a/2-c/2):0,a>c?0:-(c/2-a/2),0]}),Ve(rl,{radius:Math.min(a,c)/2,height:.01,center:[a>c?a/2-c/2:0,a>c?0:c/2-a/2,0]})]})]})})})}throw new Error("Shape not supported: "+t.shape)},j_=({center:t,width:e,length:n,height:o,heightAboveSurface:i=.15,color:r="#555",taperRatio:s=.12,faceRatio:a=.75,straightHeightRatio:c=.5,includeNotch:l=!0,notchRadius:A,notchPosition:u,notchRotation:_=[0,0,0],notchLength:h=.5,notchWidth:d=.25,chamferSize:m=0})=>{const p=o*c,g=o-p,y=Math.min(e,n)*s,f=Math.max(e-y,e*a),x=Math.max(n-y,n*a),I=Math.min(e,n)*.12,E=A??I,b={x:0,y:n/2-E*.25,z:o},P=u??b,B=Jn(bh,{children:[Jn(kl,{children:[Ve(Wo,{z:.005,children:Ve(ln,{size:[f,x,.01]})}),Ve(Wo,{z:p,children:Ve(ln,{size:[e,n,.01]})})]}),Jn(kl,{children:[Ve(Wo,{z:p,children:Ve(ln,{size:[e,n,.01]})}),Ve(Wo,{z:p+g,children:Ve(ln,{size:[f,x,.01]})})]})]}),w=(N,F)=>Ve(Wo,{offset:{x:N,y:F,z:0},children:Ve(W_,{rotation:[0,0,Math.PI/4],children:Ve(ln,{size:[m*Math.SQRT2,m*Math.SQRT2,o*3]})})});let k=B;if(m>0){const N=e/2,F=n/2;k=Jn(df,{children:[B,w(N,F),w(-N,F),w(N,-F),w(-N,-F)]})}return Ve(Cr,{color:r,children:Ve(Wo,{offset:t,children:Ve(Wo,{offset:{x:0,y:0,z:i},children:l?Jn(df,{children:[k,Ve(Wo,{offset:P,children:Ve(W_,{rotation:_,children:Ve(rl,{radius:E,height:d})})})]}):k})})})},cOn=t=>Array.from({length:t},(e,n)=>n);function h5e(t,e){if(t.length<2)throw new Error("Stroke must have at least two points");const n=Array.isArray(t[0])?t.map(([A,u])=>({x:A,y:u})):t,o=e/2,i=[],r=[];function s(A,u){const _=u.x-A.x,h=u.y-A.y,d=Math.sqrt(_*_+h*h);return{x:-h/d,y:_/d}}function a(A,u,_){const h={x:A.x+u.x*o*_,y:A.y+u.y*o*_};_>0?i.push(h):r.unshift(h)}const c=s(n[0],n[1]);a(n[0],c,1),a(n[0],c,-1);for(let A=1;A<n.length-1;A++){const u=n[A-1],_=n[A],h=n[A+1],d=s(u,_),m=s(_,h),p=d.x+m.x,g=d.y+m.y,y=Math.sqrt(p*p+g*g);if(y/2>2*o)a(_,d,1),a(_,m,1),a(_,d,-1),a(_,m,-1);else{const x=1/y;a(_,{x:p*x,y:g*x},1),a(_,{x:p*x,y:g*x},-1)}}const l=s(n[n.length-2],n[n.length-1]);return a(n[n.length-1],l,1),a(n[n.length-1],l,-1),[...i,...r]}var lOn=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}))},AOn=lOn([{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}]),ndt=5.47,YX=.5,uOn=({x:t,y:e,z:n})=>{const o=t>0;return Jn(or,{children:[Ve(Wo,{offset:{x:t+.25/2,y:e,z:n},children:Ve(W_,{rotation:["-90deg",0,"90deg"],children:Ve(Yk,{height:.25,children:Ve(Vk,{points:AOn.slice().reverse().map(i=>[i.x,i.y])})})})}),Ve(Wo,{offset:{x:t,y:e+(o?1:-1),z:n},children:Ve(W_,{rotation:["-90deg","90deg",o?"180deg":"0deg"],children:Ve(Yk,{height:2,children:Ve(Vk,{points:h5e([[0,0],[-1,0],[-1,-1]],.25).map(i=>[i.x,i.y])})})})})]})},_On=({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 Jn(or,{children:[cOn(t).map(a=>{const c=a%i,l=(Math.floor(a/i)-.5)*2;return Ve(uOn,{x:l*r/2,y:c*e-(i-1)/2*e,z:ndt/2+YX})}),Ve(j_,{width:s,length:i*e+.5,height:ndt-YX,heightAboveSurface:YX,center:{x:0,y:0,z:YX}})]})};function dOn(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,c=n+o+(i-n-o)*.25;if(t<=a)return 0;if(t>=c)return e;const l=(t-a)/(c-a);return e/(1+Math.exp(-r*(l-.5)))}var vr=t=>{const{thickness:e,width:n,padContactLength:o,bodyDistance:i,height:r,rotation:s}=t,a=15,c=Array.from({length:a}).map((A,u)=>u/(a-1)*i).map(A=>[A,dOn(A,t)]),l=h5e(c,e);return Ve(Cr,{color:"#fff",children:Ve(Wo,{offset:{z:0,y:0,x:0,...t.position},children:Ve(W_,{rotation:["90deg",0,s??0],children:Ve(Wo,{offset:{x:0,y:0,z:-n/2},children:Ve(Yk,{height:n,children:Ve(Vk,{points:l.map(A=>[A.x,A.y])})})})})})})},hOn=({pinCount:t,leadLength:e,leadWidth:n,pitch:o,bodyWidth:i})=>{const r=Math.ceil(t/2),s=r<=4,a=(r-1)*o/2,c=o*Math.max(r-1,0)+(s?1.5:1.15),l=i-(s?.66:.58),A=.15,u=.8,_=1.22,h=e*.5,d=h+Math.max(.22,Math.min(.4,e*.65)),m=i/2+e/2,p=d*.1,g=Math.min(Math.min(l,c)*.18,1),y=Math.min(Math.min(l,c)*.12,.45);return Jn(or,{children:[Array.from({length:r}).map((f,x)=>Ve(vr,{position:{x:-m,y:x*o-a,z:A/2},width:n,thickness:A,padContactLength:h,bodyDistance:d,curveLength:p,height:u})),Array.from({length:r}).map((f,x)=>Ve(vr,{rotation:Math.PI,position:{x:m,y:x*o-a,z:A/2},width:n,thickness:A,padContactLength:h,bodyDistance:d,curveLength:p,height:u})),Ve(j_,{center:{x:0,y:0,z:0},width:l,length:c,height:_,notchPosition:{x:-(l/2-g-.2),y:c/2-g-.2,z:_},notchRadius:y})]})},mOn=({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 Jn(or,{children:[Array.from({length:r}).map((c,l)=>Ve(vr,{position:{x:-i/2-e-.3,y:l*o-s,z:a/2},width:n,thickness:a,padContactLength:e,bodyDistance:e+.4,height:.6})),Array.from({length:r}).map((c,l)=>Ve(vr,{rotation:Math.PI,position:{x:i/2+e+.3,y:l*o-s,z:a/2},width:n,thickness:a,padContactLength:e,bodyDistance:e+.4,height:.6})),Ve(j_,{center:{x:0,y:0,z:a/2},width:i,length:i,height:1.1,notchRadius:.35,heightAboveSurface:.1,taperRatio:.09})]})},m5e=1,g5e=.5,T7=.5,Kk=.2,gOn=m5e-Kk*2,odt=({color:t="#333"})=>Jn(or,{children:[Ve(ln,{size:[gOn,g5e,T7],offset:[0,0,T7/2],color:t}),Ve(ln,{size:[Kk,T7,g5e],offset:[m5e/2-Kk/2,0,T7/2],color:"#ccc"}),Ve(ln,{size:[Kk,T7,g5e],offset:[-m5e/2+Kk/2,0,T7/2],color:"#ccc"})]}),p5e=1.6,pOn=p5e-.3*2,KX=.3,f5e=.85,Q7=.6,idt=({color:t="#333"})=>Jn(or,{children:[Ve(ln,{size:[pOn,f5e,Q7],offset:[0,0,Q7/2],color:t}),Ve(ln,{size:[KX,f5e,Q7],offset:[p5e/2-KX/2,0,Q7/2],color:"#ccc"}),Ve(ln,{size:[KX,f5e,Q7],offset:[-p5e/2+KX/2,0,Q7/2],color:"#ccc"})]}),y5e=2,x5e=1.25,R7=.55,Wk=.5,fOn=y5e-Wk*2,rdt=({color:t="#333"})=>Jn(or,{children:[Ve(ln,{size:[fOn,x5e,R7],offset:[0,0,R7/2],color:t}),Ve(ln,{size:[Wk,x5e,R7],offset:[y5e/2-Wk/2,0,R7/2],color:"#ccc"}),Ve(ln,{size:[Wk,x5e,R7],offset:[-y5e/2+Wk/2,0,R7/2],color:"#ccc"})]}),yOn=({pinCount:t,pitch:e,leadWidth:n,padContactLength:o,bodyWidth:i})=>{const r=t/4;e||(e=xOn(t,i)),o||(o=COn(t)),n||(n=IOn(t,i)),i||(i=e*(r+4));const s=o,a=i,c=(r-1)*e/2,l=s*.5,A=a+2*l,u=A,_=.8,h=.15,d=l,m=l*.5,p=l*.18;return Jn(or,{children:[Array.from({length:r}).map((g,y)=>Ve(vr,{position:{x:-u/2,y:y*e-c,z:h/2},width:n,thickness:h,padContactLength:m,bodyDistance:d,curveLength:p,height:_})),Array.from({length:r}).map((g,y)=>Ve(vr,{rotation:Math.PI,position:{x:u/2,y:y*e-c,z:h/2},width:n,thickness:h,padContactLength:m,bodyDistance:d,curveLength:p,height:_})),Array.from({length:r}).map((g,y)=>Ve(vr,{rotation:Math.PI/2,position:{x:y*e-c,y:-A/2,z:h/2},width:n,thickness:h,padContactLength:m,bodyDistance:d,curveLength:p,height:_})),Array.from({length:r}).map((g,y)=>Ve(vr,{rotation:-Math.PI/2,position:{x:y*e-c,y:A/2,z:h/2},width:n,thickness:h,padContactLength:m,bodyDistance:d,curveLength:p,height:_})),Ve(j_,{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})]})},xOn=(t,e)=>{switch(t){case 44:case 64:return .8;case 52:return e===14?1:.65;case 208:return .5;default:return .5}},COn=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}},IOn=(t,e)=>{switch(t){case 44:case 64:return .5;case 52:return e===14?.45:.55;case 208:return .3;default:return .25}},sdt=({x:t,y:e,pinThickness:n,shortSidePinLength:o,longSidePinLength:i,bodyHeight:r,bodyLength:s=2.54,bodyWidth:a=2.54,flipZ:c,faceup:l,smd:A,rightangle:u})=>Jn(or,{children:[Ve(Wo,{y:u?-3:0,children:Ve(ln,{color:"#222",size:[s,a,r],center:[t,e,c(r/2)]})}),!l&&Ve(Cr,{color:"gold",children:A?Ve(vr,{rotation:-Math.PI/2,position:{x:t,y:e+1,z:n/2},thickness:n,width:n,height:n,padContactLength:2,bodyDistance:3}):Jn(kl,{children:[Ve(ln,{color:"gold",size:[n,n,o*.9],center:[t,e,c(r*.9+r/2)]}),Ve(ln,{color:"gold",size:[n/1.8,n/1.8,o],center:[t,e,c(r+r/2)]})]})}),Ve(Cr,{color:"gold",children:Ve(Wo,{y:u?-3.9:0,z:u?1:0,children:Ve(W_,{rotation:u?[-Math.PI/2,0,0]:[0,0,0],children:Jn(kl,{children:[Ve(ln,{color:"gold",size:[n,n,i*.9],center:[t,e,c(-i/2*.9)]}),Ve(ln,{color:"gold",size:[n/1.8,n/1.8,i],center:[t,e,c(-i/2)]})]})})})})]}),EOn=({numberOfPins:t,pitch:e=2.54,longSidePinLength:n=6,invert:o,faceup:i,rows:r=1,smd:s,rightangle:a})=>{const A=Math.ceil(t/r),u=2.54,_=3,h=-((A-1)/2)*e,d=!s&&!a?-2-1.6:0,m=p=>(o||i?-p+2:p)+d;return Ve(or,{children:Array.from({length:t},(p,g)=>{const y=Math.floor(g/A),f=g%A,x=h+f*e,I=((r-1)/2-y)*u;return Ve(sdt,{x,y:I,pinThickness:.63,shortSidePinLength:_,longSidePinLength:n,bodyHeight:2,flipZ:m,faceup:i,smd:s,rightangle:a},g)})})},bOn=t=>{const e=["left","bottom","right","top"],{pin_count:n,pn:o,w:i,h:r,p:s,pl:a}=t,c=n/4,l=e[Math.floor((o-1)/c)],A=(o-1)%c,u=s*(c-1),_=s*(c-1),h=-a/2;switch(l){case"left":return{x:-i/2-h,y:_/2-A*s,o:"vert"};case"bottom":return{x:-u/2+A*s,y:-r/2-h,o:"horz"};case"right":return{x:i/2+h,y:-_/2+A*s,o:"vert"};case"top":return{x:u/2-A*s,y:r/2+h,o:"horz"};default:throw new Error("Invalid pin number")}},SOn=({num_pins:t,cw:e,ccw:n,startingpin:o})=>{const i=[],r=t/4;let s=1;const a={};for(const c of o??[])a[c]=!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 c=0;c<t;c++)i[s]=c+1,s++,s>t&&(s=1);return i},POn=({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:c=.05})=>{const l=SOn({num_pins:t,cw:!0,ccw:!0}),A=[];for(let u=0;u<t;u++){const{x:_,y:h,o:d}=bOn({pin_count:t,pn:u+1,w:e,h:n,p:a,pl:s});let m=r,p=s;d==="vert"&&([m,p]=[p,m]);const g=l[u+1];A.push({pn:g,x:_,y:h,pw:m,pl:p})}return Jn(or,{children:[Ve(Cr,{color:"grey",children:Ve(ln,{center:{x:0,y:0,z:o/2},size:[e,n,o]})}),A.map((u,_)=>Ve(ln,{center:{x:u.x,y:u.y,z:c/2},size:[u.pw,u.pl,c]})),i?.length!==void 0&&i?.width!==void 0&&Ve(ln,{center:{x:0,y:0,z:c/2},size:[i.width,i.length,c]})]})},vOn=POn,BOn=()=>{const c=1.1999999999999997;return Jn(or,{children:[Ve(vr,{rotation:Math.PI,position:{x:2.8/2+c/4,y:-1,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:c,height:.95}),Ve(vr,{rotation:Math.PI,position:{x:2.8/2+c/4,y:1,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:c,height:.95}),Ve(vr,{position:{x:-2.8/2-c/4,y:0,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:c,height:.95}),Ve(vr,{position:{x:-2.8/2-c/4,y:-1,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:c,height:.95}),Ve(vr,{position:{x:-2.8/2-c/4,y:1,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:c,height:.95}),Ve(j_,{center:{x:0,y:0,z:0},width:1.6,length:2.9,height:1.2})]})},MOn=BOn,wOn=({fullWidth:t=2.9,fullLength:e=2.8})=>{const A=(t-1.92)/2+.3;return Jn(or,{children:[Ve(vr,{rotation:Math.PI,position:{x:t/2,y:0,z:.075},width:.4,thickness:.15,padContactLength:.25,bodyDistance:A,height:.45}),Ve(vr,{position:{x:-t/2,y:-.95,z:.075},width:.4,thickness:.15,padContactLength:.25,bodyDistance:A,height:.45}),Ve(vr,{position:{x:-t/2,y:.95,z:.075},width:.4,thickness:.15,padContactLength:.25,bodyDistance:A,height:.45}),Ve(j_,{center:{x:0,y:0,z:0},width:1.92,length:2.9,height:1.1,straightHeightRatio:.45,heightAboveSurface:.05})]})},C5e=.6,I5e=.3,N7=.33,jk=.1,DOn=C5e-jk*2,adt=({color:t="#333"})=>Jn(or,{children:[Ve(ln,{size:[DOn,I5e,N7],offset:[0,0,N7/2],color:t}),Ve(ln,{size:[jk,I5e,N7],offset:[C5e/2-jk/2,0,N7/2],color:"#ccc"}),Ve(ln,{size:[jk,I5e,N7],offset:[-C5e/2+jk/2,0,N7/2],color:"#ccc"})]}),E5e=.4,b5e=.2,k7=.13,Xk=.07,TOn=E5e-Xk*2,cdt=({color:t="#333"})=>Jn(or,{children:[Ve(ln,{size:[TOn,b5e,k7],offset:[0,0,k7/2],color:t}),Ve(ln,{size:[Xk,b5e,k7],offset:[E5e/2-Xk/2,0,k7/2],color:"#ccc"}),Ve(ln,{size:[Xk,b5e,k7],offset:[-E5e/2+Xk/2,0,k7/2],color:"#ccc"})]}),S5e=3.2,P5e=1.6,H7=.9,Jk=.5,QOn=S5e-Jk*2,ldt=({color:t="#333"})=>Jn(or,{children:[Ve(ln,{size:[QOn,P5e,H7],offset:[0,0,H7/2],color:t}),Ve(ln,{size:[Jk,P5e,H7],offset:[S5e/2-Jk/2,0,H7/2],color:"#ccc"}),Ve(ln,{size:[Jk,P5e,H7],offset:[-S5e/2+Jk/2,0,H7/2],color:"#ccc"})]}),v5e=3.2,B5e=2.5,L7=1,qk=.6,ROn=v5e-qk*2,Adt=({color:t="#333"})=>Jn(or,{children:[Ve(ln,{size:[ROn,B5e,L7],offset:[0,0,L7/2],color:t}),Ve(ln,{size:[qk,B5e,L7],offset:[v5e/2-qk/2,0,L7/2],color:"#ccc"}),Ve(ln,{size:[qk,B5e,L7],offset:[-v5e/2+qk/2,0,L7/2],color:"#ccc"})]}),M5e=5,w5e=2.5,F7=1.4,$k=.6,NOn=M5e-$k*2,udt=({color:t="#333"})=>Jn(or,{children:[Ve(ln,{size:[NOn,w5e,F7],offset:[0,0,F7/2],color:t}),Ve(ln,{size:[$k,w5e,F7],offset:[M5e/2-$k/2,0,F7/2],color:"#ccc"}),Ve(ln,{size:[$k,w5e,F7],offset:[-M5e/2+$k/2,0,F7/2],color:"#ccc"})]}),D5e=6.3,T5e=3.2,O7=1.8,Zk=.8,kOn=D5e-Zk*2,_dt=({color:t="#333"})=>Jn(or,{children:[Ve(ln,{size:[kOn,T5e,O7],offset:[0,0,O7/2],color:t}),Ve(ln,{size:[Zk,T5e,O7],offset:[D5e/2-Zk/2,0,O7/2],color:"#ccc"}),Ve(ln,{size:[Zk,T5e,O7],offset:[-D5e/2+Zk/2,0,O7/2],color:"#ccc"})]}),ddt=({x:t,y:e,z:n=0,pitch:o=2.54,legsLength:i=3,innerDiameter:r=.945,bodyHeight:s=5,bodyLength:a=o,bodyWidth:c=o,flipZ:l})=>{const A=r/1.5,u=A*1.6;return Jn(or,{children:[Ve(Cr,{color:"#1a1a1a",children:Jn(df,{children:[Ve(ln,{color:"#000",size:[a,c,s],center:[t,e,l(n+s/2)]}),r?Ve(rl,{height:s+.1,radius:r/2,center:[t,e,l(n+s/2)],color:"#222"}):Ve(ln,{size:[u,u,s],center:[t,e,l(n+s/2)]})]})}),Jn(Cr,{color:"silver",children:[Jn(kl,{children:[Ve(ln,{color:"silver",size:[A,A,i*.9],center:[t,e,l(n+-i/2*.9)]}),Ve(ln,{color:"silver",size:[A/1.8,A/1.8,i],center:[t,e,l(n+-i/2)]})]}),Ve(ln,{color:"silver",size:[u,u,u*.5],center:[t,e,l(n+u/2*.5)]})]})]})},HOn=({numberOfPins:t,pitch:e=2.54,legsLength:n=3,innerDiameter:o=.945,rows:i=1,invert:r})=>{const a=Math.ceil(t/i),c=2.54,l=-((a-1)/2)*e,A=u=>r?-u+5:u;return Ve(or,{children:Array.from({length:t},(u,_)=>{const h=Math.floor(_/a),d=_%a,m=l+d*e,p=((i-1)/2-h)*c;return Ve(ddt,{x:m,y:p,pitch:e,legsLength:n,innerDiameter:o,flipZ:A},_)})})},LOn=({width:t,length:e,innerDiameter:n=1})=>{const o=t,i=e,r=t*.7,s=n/2.5;return Jn(or,{children:[Ve(Uk,{color:"#1a1a1f",center:[0,0,r/2],size:[i,i,r],roundRadius:.3}),Ve(Uk,{color:"#f2f2f2",center:[0,0,r+r*.1/2.5],size:[i,i,r*.1],roundRadius:.14}),Ve(rl,{color:"#1a1a1f",height:r*.8,radius:o/3,center:[0,0,r+r*.8/2]}),Ve(rl,{color:"#1a1a1f",height:r*.2,radius:n/2,center:[i/3,i/3,r+r*.1/2]}),Ve(rl,{color:"#1a1a1f",height:r*.2,radius:n/2,center:[-i/3,-i/3,r+r*.1/2]}),Ve(rl,{color:"#1a1a1f",height:r*.2,radius:n/2,center:[-i/3,i/3,r+r*.1/2]}),Ve(rl,{color:"#1a1a1f",height:r*.2,radius:n/2,center:[i/3,-i/3,r+r*.1/2]}),Ve(WX,{thickness:n/3,width:s,horizontalLength:i*.8,verticalLength:r/2,position:{x:-o/2,y:-i/2,z:-r*1.2}}),Ve(WX,{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}),Ve(WX,{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}),Ve(WX,{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}})]})},WX=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]],c=h5e(a,e);return Ve(Cr,{color:"#f2f2f2",children:Ve(Wo,{offset:{x:s?.x||0,y:s?.y||0,z:s?.z||0},children:Ve(W_,{rotation:[0,55,r],children:Ve(Yk,{height:n,children:Ve(Vk,{points:c.map(l=>[l.y,l.x])})})})})})},FOn=({pinCount:t,leadLength:e,leadWidth:n,pitch:o,bodyWidth:i})=>{const r=Math.ceil(t/2),s=(r-1)*o/2,a=.25,c=1,l=.8,A=e*0,u=o*(r-1)+n+.2,_=i*.55;return Jn(or,{children:[Array.from({length:r}).map((h,d)=>Ve(vr,{position:{x:-i/2-A,y:d*o-s,z:a/2},width:n,thickness:a,padContactLength:e/2,bodyDistance:e+.3,height:l})),Array.from({length:r}).map((h,d)=>Ve(vr,{rotation:Math.PI,position:{x:i/2+A,y:d*o-s,z:a/2},width:n,thickness:a,padContactLength:e/2,bodyDistance:e+.3,height:l})),Ve(j_,{center:{x:0,y:0,z:a/2},width:_,length:u,height:c})]})},OOn=({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),c=isNaN(parseFloat(n))?s.leadWidth:parseFloat(n)*.8,l=isNaN(parseFloat(i))?2.6:parseFloat(i)*.8,A=isNaN(parseFloat(r))?2+Number(a)*1.4:parseFloat(r),u=t/2,_=(u-1)*a/2,h=.15,d=.8,m=4.5,p=(m-l)/2,g=p*.5;return Jn(or,{children:[Array.from({length:u}).map((y,f)=>Ve(vr,{position:{x:-m/2,y:_-f*a,z:h/2},width:c,thickness:h,padContactLength:g+.05,bodyDistance:p+.1,height:d})),Array.from({length:u}).map((y,f)=>Ve(vr,{rotation:Math.PI,position:{x:m/2,y:_-f*a,z:h/2},width:c,thickness:h,padContactLength:g+.05,bodyDistance:p+.1,height:d})),Ve(j_,{center:{x:0,y:0,z:h/2},width:l,length:A,height:1})]})},GOn=()=>Jn(or,{children:[Ve(ln,{color:"#ccc",size:[.5,.6,.12],center:[-.725,0,.12/2]}),Ve(ln,{color:"#ccc",size:[.5,.6,.12],center:[.725,0,.12/2]}),Ve(Cr,{color:"#222",children:Jn(bh,{children:[Ve(Wo,{z:.3/2,children:Ve(ln,{size:[1.65,.8,.3]})}),Jn(kl,{children:[Ve(Wo,{z:.3,children:Ve(ln,{size:[1.65,.8,.01]})}),Ve(Wo,{z:.6,children:Ve(ln,{size:[1.65-.2,.8-.2,.01]})})]})]})})]}),zOn=()=>Jn(or,{children:[Ve(ln,{color:"#ccc",size:[.26,.51,.12],center:[-.325,0,.12/2]}),Ve(ln,{color:"#ccc",size:[.26,.51,.12],center:[.325,0,.12/2]}),Ve(Cr,{color:"#222",children:Ve(Wo,{z:.47/2+.02,children:Ve(ln,{size:[.98,.58,.47]})})}),Ve(ln,{color:"#ccc",size:[.98+.001,.26/2,.26/4],center:[0,.26/2,.47/4]}),Ve(ln,{color:"#ccc",size:[.98+.001,.26/2,.26/4],center:[0,-.26/2,.47/4]}),Ve(ln,{color:"#ccc",size:[.26/1.5,.58+.001,.26/4],center:[.65/2,0,.47/4]}),Ve(ln,{color:"#ccc",size:[.26/1.5,.58+.001,.26/4],center:[-.65/2,0,.47/4]})]}),UOn=()=>{const l=Ve(Cr,{color:"#1a1a1a",children:Jn(bh,{children:[Jn(kl,{children:[Ve(Wo,{z:.13,children:Ve(ln,{size:[4,3,.03]})}),Ve(Wo,{z:1.15,children:Ve(ln,{size:[4.4,3.4,.01]})})]}),Jn(kl,{children:[Ve(Wo,{z:1.15,children:Ve(ln,{size:[4.4,3.4,.01]})}),Ve(Wo,{z:2.3,children:Ve(ln,{size:[4,3,.01]})})]})]})}),A=({xDir:u})=>{const d=u*1.78,m=u*(3.4/2-.2/2+1),p=u*(3.4/2-.2/2),g=Math.abs(p-m),y=(m+p)/2;return Ve(Cr,{color:"#c0c0c0",children:Jn(bh,{children:[Ve(ln,{size:[2.3*.8,1.45,.2],center:[d,0,.2/2]}),Ve(ln,{size:[.2,1.45,1.14],center:[m,0,1.14/2+.2]}),Ve(ln,{size:[g,1.45,.2],center:[y,0,.2/2+1.14]})]})})};return Jn(or,{children:[Ve(A,{xDir:1}),Ve(A,{xDir:-1}),l]})},VOn=()=>{const l=Ve(Cr,{color:"#1a1a1a",children:Jn(bh,{children:[Jn(kl,{children:[Ve(Wo,{z:.13,children:Ve(ln,{size:[4,3,.03]})}),Ve(Wo,{z:1.15,children:Ve(ln,{size:[4.4,3.4,.01]})})]}),Jn(kl,{children:[Ve(Wo,{z:1.15,children:Ve(ln,{size:[4.4,3.4,.01]})}),Ve(Wo,{z:2.3,children:Ve(ln,{size:[4,3,.01]})})]})]})}),A=({xDir:u})=>{const d=u*1.78,m=u*(3.4/2-.2/2+1),p=u*(3.4/2-.2/2),g=Math.abs(p-m),y=(m+p)/2;return Ve(Cr,{color:"#c0c0c0",children:Jn(bh,{children:[Ve(ln,{size:[2.3*.8,1.45,.2],center:[d,0,.2/2]}),Ve(ln,{size:[.2,1.45,1.14],center:[m,0,1.14/2+.2]}),Ve(ln,{size:[g,1.45,.2],center:[y,0,.2/2+1.14]})]})})};return Jn(or,{children:[Ve(A,{xDir:1}),Ve(A,{xDir:-1}),l]})},YOn=()=>{const l=Ve(Cr,{color:"#1a1a1a",children:Jn(bh,{children:[Jn(kl,{children:[Ve(Wo,{z:.21000000000000002,children:Ve(ln,{size:[6.3999999999999995,5.6,.03]})}),Ve(Wo,{z:1.15,children:Ve(ln,{size:[6.8,6,.01]})})]}),Jn(kl,{children:[Ve(Wo,{z:1.15,children:Ve(ln,{size:[6.8,6,.01]})}),Ve(Wo,{z:2.3,children:Ve(ln,{size:[6.3999999999999995,5.6,.01]})})]})]})}),A=({xDir:u})=>{const d=u*3.08,m=u*(6/2-.2/2+1),p=u*(6/2-.2/2),g=Math.abs(p-m),y=(m+p)/2;return Ve(Cr,{color:"#c0c0c0",children:Jn(bh,{children:[Ve(ln,{size:[2.3*.8,2.95,.2],center:[d,0,.2/2]}),Ve(ln,{size:[.2,2.95,1.14],center:[m,0,1.14/2+.2]}),Ve(ln,{size:[g,2.95,.2],center:[y,0,.2/2+1.14]})]})})};return Jn(or,{children:[Ve(A,{xDir:1}),Ve(A,{xDir:-1}),l]})},KOn=()=>{const u=Ve(Cr,{color:"#222",children:Jn(bh,{children:[Ve(Wo,{z:.27,children:Ve(ln,{size:[2.9,1.9,.54]})}),Jn(kl,{children:[Ve(Wo,{z:.54,children:Ve(ln,{size:[2.9,1.9,.01]})}),Ve(Wo,{z:1.08,children:Ve(ln,{size:[2.6999999999999997,1.7,.01]})})]})]})});return Jn(or,{children:[Ve(ln,{color:"#ccc",size:[1,1.2,.25],center:[-1.3,0,.25/2]}),Ve(ln,{color:"#ccc",size:[1,1.2,.25],center:[1.3,0,.25/2]}),u]})},WOn=()=>Jn(or,{children:[Ve(ln,{color:"#ccc",size:[1,.6,.12],center:[-1.3,0,.12/2]}),Ve(ln,{color:"#ccc",size:[1,.6,.12],center:[1.3,0,.12/2]}),Ve(Cr,{color:"#222",children:Jn(bh,{children:[Ve(Wo,{z:.55/2,children:Ve(ln,{size:[2.7,1.6,.55]})}),Jn(kl,{children:[Ve(Wo,{z:.55,children:Ve(ln,{size:[2.7,1.6,.01]})}),Ve(Wo,{z:1.1,children:Ve(ln,{size:[2.7-.2,1.6-.2,.01]})})]})]})})]}),jOn=()=>Jn(or,{children:[Ve(ln,{color:"#ccc",size:[1,.9,.2],center:[-1.3,0,.2/2]}),Ve(ln,{color:"#ccc",size:[1,.9,.2],center:[1.3,0,.2/2]}),Ve(Cr,{color:"#222",children:Jn(bh,{children:[Ve(Wo,{z:.2/2,children:Ve(ln,{size:[2.75,1.8,.2]})}),Jn(kl,{children:[Ve(Wo,{z:.2,children:Ve(ln,{size:[2.75,1.8,.01]})}),Ve(Wo,{z:1,children:Ve(ln,{size:[2.75-.4,1.8-.4,.01]})})]})]})}),Ve(ln,{color:"#777",size:[.2,1.8-.4,.01],center:[-1.3+.4,0,1]})]}),XOn=()=>Jn(or,{children:[Ve(ln,{color:"#ccc",size:[.9,.9,.2],center:[-1.225,0,.2/2]}),Ve(ln,{color:"#ccc",size:[.9,.9,.2],center:[1.225,0,.2/2]}),Ve(Cr,{color:"#222",children:Jn(bh,{children:[Jn(kl,{children:[Ve(Wo,{z:.2,children:Ve(ln,{size:[2.6-.1/2,1.7-.1/2,.01]})}),Ve(Wo,{z:.01,children:Ve(ln,{size:[2.6-.1,1.7-.1,.01]})})]}),Jn(kl,{children:[Ve(Wo,{z:.2,children:Ve(ln,{size:[2.6,1.7,.01]})}),Ve(Wo,{z:1,children:Ve(ln,{size:[2.6-.4,1.7-.4,.01]})})]})]})}),Ve(ln,{color:"#777",size:[.2*2.7,1.7-.4,.02],center:[-1.225+.4,0,1]})]}),JOn=()=>Jn(or,{children:[Ve(ln,{color:"#ccc",size:[.9,1.75,.2],center:[-1.825,0,.2/2]}),Ve(ln,{color:"#ccc",size:[.9,1.75,.2],center:[1.825,0,.2/2]}),Ve(Cr,{color:"#222",children:Jn(bh,{children:[Jn(kl,{children:[Ve(Wo,{z:.2,children:Ve(ln,{size:[3.8-.05/2,2.5-.05/2,.01]})}),Ve(Wo,{z:.01,children:Ve(ln,{size:[3.8-.05,2.5-.05,.01]})})]}),Jn(kl,{children:[Ve(Wo,{z:.2,children:Ve(ln,{size:[3.8,2.5,.01]})}),Ve(Wo,{z:1,children:Ve(ln,{size:[3.8-.4,2.5-.4,.01]})})]})]})}),Ve(ln,{color:"#777",size:[.2*2.7,2.5-.4,.02],center:[-1.825+.4,0,1]})]}),qOn=()=>Jn(or,{children:[Ve(ln,{color:"#ccc",size:[.4,.25,.14],center:[-.4,0,.14/2]}),Ve(ln,{color:"#ccc",size:[.4,.25,.14],center:[.4,0,.14/2]}),Ve(Cr,{color:"#222",children:Jn(bh,{children:[Ve(Wo,{z:.14/2,children:Ve(ln,{size:[.8,.6,.14]})}),Jn(kl,{children:[Ve(Wo,{z:.14,children:Ve(ln,{size:[.8,.6,.01]})}),Ve(Wo,{z:.37,children:Ve(ln,{size:[.8-.1,.6-.1,.01]})})]})]})})]}),$On=()=>{const A=3.0999999999999996;return Jn(or,{children:[Ve(vr,{rotation:Math.PI,position:{x:6.6/2+A/4,y:0,z:.25/2},width:3,thickness:.25,padContactLength:.5,bodyDistance:A,height:.75}),Ve(vr,{position:{x:-6.6/2-A/4,y:0,z:.25/2},width:.7,thickness:.25,padContactLength:.5,bodyDistance:A,height:.75}),Ve(vr,{position:{x:-6.6/2-A/4,y:-2.3,z:.25/2},width:.7,thickness:.25,padContactLength:.5,bodyDistance:A,height:.75}),Ve(vr,{position:{x:-6.6/2-A/4,y:2.3,z:.25/2},width:.7,thickness:.25,padContactLength:.5,bodyDistance:A,height:.75}),Ve(j_,{center:{x:0,y:0,z:0},width:3.5,length:6.5,height:1.7,includeNotch:!1,taperRatio:.06,straightHeightRatio:.45})]})},ZOn=()=>Jn(or,{children:[Array.from({length:16}).map((h,d)=>Ve(vr,{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)=>Ve(vr,{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)=>Ve(vr,{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)=>Ve(vr,{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})),Ve(j_,{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})]}),eGn=ZOn,tGn=()=>{const l=.7999999999999998;return Jn(or,{children:[Ve(vr,{rotation:Math.PI,position:{x:2.05/2+l/4,y:0,z:.18/2},width:.3,thickness:.18,padContactLength:.2,bodyDistance:l,height:.65}),Ve(vr,{position:{x:-2.05/2-l/4,y:-.65,z:.18/2},width:.3,thickness:.18,padContactLength:.2,bodyDistance:l,height:.65}),Ve(vr,{position:{x:-2.05/2-l/4,y:.65,z:.18/2},width:.3,thickness:.18,padContactLength:.2,bodyDistance:l,height:.65}),Ve(j_,{center:{x:0,y:0,z:0},width:1.25,length:2,height:.9,includeNotch:!1,taperRatio:.06,straightHeightRatio:.7,heightAboveSurface:.05})]})},nGn=({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,c=s+3.3*o,l=c,A=.8,u=.2,_=(l-i)/2+.4;return Jn(or,{children:[Array.from({length:r}).map((h,d)=>Ve(vr,{position:{x:-l/2-.36,y:d*e-a,z:u/2},width:n,thickness:u,padContactLength:o,bodyDistance:_,height:A})),Array.from({length:r}).map((h,d)=>Ve(vr,{rotation:Math.PI,position:{x:l/2+.36,y:d*e-a,z:u/2},width:n,thickness:u,padContactLength:o,bodyDistance:_,height:A})),Array.from({length:r}).map((h,d)=>Ve(vr,{rotation:Math.PI/2,position:{x:d*e-a,y:-c/2-.36,z:u/2},width:n,thickness:u,padContactLength:o,bodyDistance:_,height:A})),Array.from({length:r}).map((h,d)=>Ve(vr,{rotation:-Math.PI/2,position:{x:d*e-a,y:c/2+.36,z:u/2},width:n,thickness:u,padContactLength:o,bodyDistance:_,height:A})),Ve(j_,{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})]})},oGn=()=>{const o=.20900000000000002,i=.1,r=.3,s=.1,a=.2;return Jn(or,{children:[Ve(Cr,{color:"#222",children:Jn(bh,{children:[Ve(ln,{size:[.85,1.2,o],center:[0,0,o/2]}),Jn(kl,{children:[Ve(Wo,{z:o,children:Ve(ln,{size:[.85,1.2,.01]})}),Ve(Wo,{z:.38,children:Ve(ln,{size:[.85-i,1.2-i,.01]})})]})]})}),Ve(ln,{color:"#ccc",size:[r,.25,s],center:[.55,0,s/2]}),Ve(ln,{color:"#ccc",size:[r,a,s],center:[-.55,.4,s/2]}),Ve(ln,{color:"#ccc",size:[r,a,s],center:[-.55,-.4,s/2]})]})},iGn=({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:c=.2})=>{const l=[],A=Math.floor(t/2),u=a*(A-1);for(let _=0;_<t;_++){const h=_<A?"left":"right",d=_%A,m=u/2-d*a,p=s,g=r,y=h==="left"?-e/2+p/2:e/2-p/2,f=_+1;l.push({pinNumber:f,x:y,y:m,padSizeX:p,padSizeY:g})}return Jn(or,{children:[Ve(j_,{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}}),l.map((_,h)=>Ve(ln,{center:[_.x,_.y,c/2],size:[_.padSizeX,_.padSizeY,c]})),i?.length!==void 0&&i?.width!==void 0&&Ve(ln,{center:[0,0,c/2],size:[i.width,i.length,c]})]})},rGn=({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 c=t/2,l=e/2,A=c-l,u=o/2,_=.85;return Jn(or,{children:[Jn(Cr,{color:s,children:[Jn(kl,{children:[Ve(H2,{height:n,roundRadius:.5,radius:l,center:[-A,0,n]}),Ve(H2,{height:n,roundRadius:.5,radius:l,center:[A,0,n]})]}),Jn(kl,{children:[Ve(H2,{height:_,roundRadius:.1,radius:l+.85,center:[-A,0,n/2+_/2]}),Ve(H2,{height:_,roundRadius:.1,radius:l+.85,center:[A,0,n/2+_/2]})]})]}),Jn(Cr,{color:a,children:[Ve(rl,{height:r+n/2,radius:i/2,center:[-u+.06,0,-(r/2)+n/2]}),Ve(rl,{height:r+n/2,radius:i/2,center:[u-.06,0,-(r/2)+n/2]})]})]})},sGn=({bodyLength:t=1.4,bodyDiameter:e=1.1,color:n="#3a3a3aff",contactColor:o="#c6c6c6",cathodeIdentification:i="#111"})=>Jn(or,{children:[Ve(Cr,{color:n,children:Jn(W_,{rotation:[0,"90deg",0],children:[Ve(Uk,{size:[e,e,t-.2],roundRadius:.2,center:[-e/2,0,.05]}),Ve(rl,{height:.2/2,radius:e/2-.2,center:[-e/2,0,-t/2+.2/2]})]})}),Ve(Cr,{color:i,children:Ve(W_,{rotation:[0,"90deg",0],children:Ve(Uk,{size:[e*1.01,e*1.01,t/3],roundRadius:.2,center:[-e/2,0,-t/4+.1]})})}),Ve(Cr,{color:o,children:Ve(W_,{rotation:[0,"90deg",0],children:Ve(H2,{height:.2,radius:e/2,roundRadius:.2/3,center:[-e/2,0,-t/2]})})}),Ve(Cr,{color:o,children:Ve(W_,{rotation:[0,"90deg",0],children:Ve(H2,{height:.2,radius:e/2,roundRadius:.2/3,center:[-e/2,0,t/2]})})})]}),aGn=({bodyLength:t=3.5,bodyDiameter:e=1.5,color:n="#3a3a3aff",contactColor:o="#c6c6c6"})=>Jn(or,{children:[Ve(Cr,{color:n,children:Ve(W_,{rotation:[0,"90deg",0],children:Ve(H2,{height:t,radius:e/2,roundRadius:.3,center:[-e/2,0,0]})})}),Ve(Cr,{color:o,children:Ve(W_,{rotation:[0,"90deg",0],children:Ve(H2,{height:.5,radius:e/2,roundRadius:.2,center:[-e/2,0,-t/2]})})}),Ve(Cr,{color:o,children:Ve(W_,{rotation:[0,"90deg",0],children:Ve(H2,{height:.5,radius:e/2,roundRadius:.2,center:[-e/2,0,t/2]})})})]}),cGn=({bodyLength:t=3.9,bodyDiameter:e=2.5,color:n="#3a3a3aff",contactColor:o="#c6c6c6"})=>Jn(or,{children:[Ve(Cr,{color:n,children:Ve(W_,{rotation:[0,"90deg",0],children:Ve(H2,{height:t,radius:e/2,roundRadius:.3,center:[-e/2,0,0]})})}),Ve(Cr,{color:o,children:Ve(W_,{rotation:[0,"90deg",0],children:Ve(H2,{height:.55,radius:e/2,roundRadius:.2,center:[-e/2,0,-t/2]})})}),Ve(Cr,{color:o,children:Ve(W_,{rotation:[0,"90deg",0],children:Ve(H2,{height:.55,radius:e/2,roundRadius:.2,center:[-e/2,0,t/2]})})})]}),lGn=({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,c=.2;return Jn(or,{children:[Array.from({length:i}).map((l,A)=>Ve(vr,{position:{x:-s/2-e-.3,y:A*o-a,z:c/2},width:n,thickness:c,padContactLength:e,bodyDistance:e+.4,height:.85})),Array.from({length:i}).map((l,A)=>Ve(vr,{rotation:Math.PI,position:{x:s/2+e+.3,y:A*o-a,z:c/2},width:n,thickness:c,padContactLength:e,bodyDistance:e+.4,height:.85})),Ve(j_,{center:{x:0,y:0,z:c/2},width:s,length:r,height:1.55,notchPosition:{x:-.95,y:r/2-1,z:1.55},heightAboveSurface:.17,taperRatio:.09})]})},AGn=({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,c=.2;return Jn(or,{children:[Array.from({length:i}).map((l,A)=>Ve(vr,{position:{x:-r/2-e-.3,y:A*o-a,z:c/2},width:n,thickness:c,padContactLength:e,bodyDistance:e+.4,height:.85})),Array.from({length:i}).map((l,A)=>Ve(vr,{rotation:Math.PI,position:{x:r/2+e+.3,y:A*o-a,z:c/2},width:n,thickness:c,padContactLength:e,bodyDistance:e+.4,height:.85})),Ve(j_,{center:{x:0,y:0,z:c/2},width:r,length:s,height:1.1,notchPosition:{x:-2.25,y:s/2-1.5,z:1.1},heightAboveSurface:.17,taperRatio:.05})]})},uGn=()=>{const m=7.050000000000001,p=24.95+6.5/2;return Ve(Wo,{center:[0,0,1],children:Jn(or,{children:[Jn(W_,{rotation:[0,55,-55],children:[Jn(df,{children:[Ve(ln,{color:"#ccc",size:[6.5+.1,9.9,1.3],center:[p,0,1.3-2]}),Ve(rl,{color:"black",center:[p,0,1.3-2],radius:3/2,height:1.3*1.2})]}),Ve(Cr,{color:"#222",children:Ve(j_,{width:9.9,length:9.9,height:4.5,center:{x:20,y:0,z:-2.4},includeNotch:!1,straightHeightRatio:.3,taperRatio:.04,heightAboveSurface:1})})]}),Ve(W_,{rotation:[0,55,55],children:Array.from({length:3}).map((g,y)=>{const f=m,x=(y-1)*2.7,I=-.5-.6;return Jn(Cr,{color:"gold",children:[Jn(kl,{children:[Ve(Wo,{center:[15.05-4.5/2+.1,x,I],children:Ve(ln,{size:[4.5,.81+1,.5]})}),Ve(Wo,{center:[15.05-4.5/2-1+.1,x,I],children:Ve(ln,{size:[4.5,.81,.5]})})]}),Ve(Wo,{center:[f,x,I],children:Ve(ln,{size:[16+.1,.81,.5]})})]},`prong-${y}`)})})]})})},_Gn=()=>{const l=1.1999999999999997;return Jn(or,{children:[Ve(vr,{rotation:Math.PI,position:{x:2.8/2+l/4,y:-.95,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:l,height:.95}),Ve(vr,{rotation:Math.PI,position:{x:2.8/2+l/4,y:0,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:l,height:.95}),Ve(vr,{rotation:Math.PI,position:{x:2.8/2+l/4,y:.95,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:l,height:.95}),Ve(vr,{position:{x:-2.8/2-l/4,y:0,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:l,height:.95}),Ve(vr,{position:{x:-2.8/2-l/4,y:-.95,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:l,height:.95}),Ve(vr,{position:{x:-2.8/2-l/4,y:.95,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:l,height:.95}),Ve(j_,{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})]})},dGn=()=>Jn(or,{children:[Ve(j_,{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(l=>{const A=-.35+l*.35;return Ve(ln,{center:[-.8/2+.19/2-.1,A,.12/2],size:[.19,.15,.12]})}),[0,1,2].map(l=>{const A=-.35+l*.35;return Ve(ln,{center:[.8/2-.19/2+.1,A,.12/2],size:[.19,.15,.12]})})]}),hGn=()=>{const s="#222",c=[.43,.4,1.32],l=[.43,.4,.25],A=[0,0,-.66],u=[0,0,-1.32],_=[0,1.28,-2.72],h=[0,1.28,-8.9],d=-7.5;return Jn(Wo,{center:[0,1,10.5],children:[Ve(Cr,{color:s,children:Jn(df,{children:[Ve(Wo,{center:[0,0,2.25],children:Ve(rl,{radius:2.4,height:4.5})}),Ve(Wo,{center:[0,-1.8499999999999999,2.25],children:Ve(ln,{size:[2.4*2,1.1,4.5+.2]})})]})}),Ve(Wo,{center:A,children:Ve(ln,{size:c})}),Jn(kl,{children:[Ve(Wo,{center:u,children:Ve(ln,{size:l})}),Ve(Wo,{center:_,children:Ve(ln,{size:l})})]}),Ve(Wo,{center:h,children:Ve(ln,{size:[.43,.4,12.2]})}),Ve(Wo,{center:[1.3,0,d],children:Ve(ln,{size:[.43,.4,15]})}),Ve(Wo,{center:[-1.3,0,d],children:Ve(ln,{size:[.43,.4,15]})})]})},mGn=()=>Jn(or,{children:[Ve(vr,{rotation:Math.PI,position:{x:2/2+.75/4,y:-.65,z:.15/2},width:.25,thickness:.15,padContactLength:.3,bodyDistance:.75,height:.85}),Ve(vr,{rotation:Math.PI,position:{x:2/2+.75/4,y:0,z:.15/2},width:.25,thickness:.15,padContactLength:.3,bodyDistance:.75,height:.85}),Ve(vr,{rotation:Math.PI,position:{x:2/2+.75/4,y:.65,z:.15/2},width:.25,thickness:.15,padContactLength:.3,bodyDistance:.75,height:.85}),Ve(vr,{position:{x:-2/2-.75/4,y:0,z:.15/2},width:.25,thickness:.15,padContactLength:.3,bodyDistance:.75,height:.85}),Ve(vr,{position:{x:-2/2-.75/4,y:-.65,z:.15/2},width:.25,thickness:.15,padContactLength:.3,bodyDistance:.75,height:.85}),Ve(vr,{position:{x:-2/2-.75/4,y:.65,z:.15/2},width:.25,thickness:.15,padContactLength:.3,bodyDistance:.75,height:.85}),Ve(j_,{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})]}),gGn=mGn,pGn=()=>Jn(or,{children:[Ve(j_,{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 c=-.5+a*.5;return Ve(ln,{center:[-1/2+.3/2,c,.05/2],size:[.3,.2,.05]})}),[0,1,2].map(a=>{const c=-.5+a*.5;return Ve(ln,{center:[1/2-.3/2,c,.05/2],size:[.3,.2,.05]})})]}),fGn=()=>Jn(or,{children:[Ve(vr,{position:{x:-2.5/2,y:0,z:.175/2},width:.3,thickness:.175,padContactLength:.3,bodyDistance:.45,height:.7}),Ve(vr,{rotation:Math.PI,position:{x:2.5/2,y:0,z:.175/2},width:.3,thickness:.175,padContactLength:.3,bodyDistance:.45,height:.7}),Ve(Cr,{color:"#222",children:Ve(j_,{center:{x:0,y:0,z:0},width:1.7,length:1.25,height:.95,includeNotch:!1,taperRatio:.06,straightHeightRatio:.7,heightAboveSurface:.05})}),Ve(ln,{color:"#777",size:[1.7/3,1.25-.075,.02],center:[-.85*2/3+.035,0,.95+.05]})]}),yGn=()=>Jn(or,{children:[Ve(ln,{color:"#ccc",size:[.4,.325,.175],center:[-1.05,0,.175/2]}),Ve(ln,{color:"#ccc",size:[.4,.325,.175],center:[1.05,0,.175/2]}),Ve(Cr,{color:"#222",children:Jn(bh,{children:[Ve(Wo,{z:.175/2,children:Ve(ln,{size:[1.7,1.25,.175]})}),Jn(kl,{children:[Ve(Wo,{z:.175,children:Ve(ln,{size:[1.7,1.25,.01]})}),Ve(Wo,{z:.725,children:Ve(ln,{size:[1.7-.2,1.25-.2,.01]})})]})]})}),Ve(ln,{color:"#777",size:[1.7/3,1.25-.2,.02],center:[-1.05+1.7/4.4+.2,0,.725]})]}),xGn=()=>{const s=-1.0474999999999999,a=1.775/2+.4/2-.04;return Jn(or,{children:[Ve(ln,{color:"#ccc",size:[.4,.325,.13],center:[s,0,.13/2]}),Ve(ln,{color:"#ccc",size:[.4,.325,.13],center:[a,0,.13/2]}),Ve(Cr,{color:"#222",children:Ve(j_,{width:1.775,length:1.25,height:.725,center:{x:0,y:0,z:0},heightAboveSurface:0,straightHeightRatio:.7,taperRatio:.06,includeNotch:!1})}),Ve(ln,{color:"#777",size:[1.775/3,1.25-.05,.02],center:[s+1.775/4.4+.2,0,.725]})]})},CGn=({pitch:t=10})=>Jn(or,{children:[Ve(rl,{height:4,radius:.5,center:[-t/2,0,.5]}),Ve(VX,{radius:.5,center:[-t/2,0,2.5]}),Ve(Wo,{x:-2.5,y:0,z:2.5,children:Jn(W_,{rotation:[0,Math.PI/2,0],children:[Ve(rl,{height:t,radius:.5,center:[0,0,2.5]}),Ve(Cr,{color:"#d2b48c",children:Ve(rl,{height:5,radius:1.3,center:[0,0,2.5]})})]})}),Ve(rl,{height:4,radius:.5,center:[t/2,0,.5]}),Ve(VX,{radius:.5,center:[t/2,0,2.5]})]}),IGn=({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:c,innerHoles:l=!0,innerHoleEdgeDistance:A=1.61,innerHoleDiameter:u=1})=>{const _=t/2,h=e/2,d=e*1.05,m=u/2,p=Math.max(r||0,s||0,a||0,c||0)*i||51,g=[],y=[];if(s){const E=-((s-1)/2)*i;for(let b=0;b<s;b++){const P=E+b*i;g.push({x:_-o/2,y:-P,pl:o,pw:n}),l&&y.push({x:_,y:-P},{x:_-A,y:-P})}}if(r){const E=-((r-1)/2)*i;for(let b=0;b<r;b++){const P=E+b*i;g.push({x:-_+o/2,y:-P,pl:o,pw:n}),l&&y.push({x:-_,y:-P},{x:-_+A,y:-P})}}if(a){const E=-((a-1)/2)*i;for(let b=0;b<a;b++){const P=E+b*i;g.push({x:-P,y:p/2-o/2,pl:n,pw:o}),l&&y.push({x:-P,y:p/2},{x:-P,y:p/2-A})}}if(c){const E=-((c-1)/2)*i;for(let b=0;b<c;b++){const P=E+b*i;g.push({x:-P,y:-p/2+o/2,pl:n,pw:o}),l&&y.push({x:-P,y:-p/2},{x:-P,y:-p/2+A})}}const f=Ve(Cr,{color:"#051a0a",children:Jn(df,{children:[Ve(ln,{center:[0,0,h],size:[t,p,e]}),g.map((E,b)=>Ve(ln,{center:[E.x,E.y,h],size:[E.pl+.01,E.pw+.01,d]},b))]})}),x=l&&y.map((E,b)=>Ve(rl,{color:"black",center:[E.x,E.y,h],radius:m,height:e*1.07})),I=g.map((E,b)=>Ve(ln,{center:[E.x,E.y,h],size:[E.pl+.01,E.pw+.01,d]}));return Jn(or,{children:[f,Ve(Cr,{color:"#FFD700",children:l?Jn(df,{children:[Ve(bh,{children:g.map((E,b)=>Ve(ln,{center:[E.x,E.y,h],size:[E.pl+.01,E.pw+.01,d]},b))}),x]}):I})]})},EGn=({width:t=30,height:e=22,thickness:n=1,bezelInset:o=2,bezelDepth:i=1,screenColor:r="#001414",bezelColor:s="#0f1116",screenWidth:a,screenHeight:c,offset:l})=>{const A=t,u=e,_=Math.max(n,.4),h=Math.max(Math.min(i,_),.2),d=Math.max(_-h,0),m=Math.max(o,0),p=Math.max(a??A-m*2,2),g=Math.max(c??u-m*2,2),y=Math.min(Math.max(h*.6,.2),h),f=l?.x??0,x=l?.y??0,I=l?.z??0;return Jn(Wo,{offset:{x:f,y:x,z:I},children:[d>0&&Ve(Cr,{color:s,children:Ve(ln,{size:[A,u,d],offset:[0,0,d/2]})}),Ve(Cr,{color:s,children:Jn(df,{children:[Ve(ln,{size:[A,u,h],offset:[0,0,d+h/2]}),Ve(ln,{size:[p,g,h+.02],offset:[0,0,d+h/2]})]})}),Ve(Cr,{color:r,children:Ve(ln,{size:[p,g,y],offset:[0,0,d+y/2]})})]})},bGn=({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:c="left",holes:l=[],holeInset:A=1,pinRowHoleEdgeToEdgeDist:u=2,female:_,nopin:h,screen:d,screenWidth:m,screenHeight:p,screenCenterOffsetX:g,screenCenterOffsetY:y})=>{const f=d??!1,x=r/2,I=Math.ceil(t/e);let E,b;c==="left"||c==="right"?(E=(e-1)*n+2*u,b=(I-1)*n+2*u):(b=(e-1)*n+2*u,E=(I-1)*n+2*u),t===0&&(E=10,b=10);const P=Number(s??E),B=Number(a??b),w=[];let k=0,N=0,F=0,O=0,G=0,K=0;c==="left"||c==="right"?(k=c==="left"?-P/2+u:P/2-u,N=-((I-1)/2)*n,F=0,O=n,G=c==="left"?n:-n,K=0):(k=-((I-1)/2)*n,N=c==="top"?B/2-u:-B/2+u,F=n,O=0,G=0,K=c==="top"?-n:n);let X=0;for(let ue=0;ue<e&&X<t;ue++)for(let Ie=0;Ie<I&&X<t;Ie++){const pe=k+Ie*F+ue*G,Le=N+Ie*O+ue*K;w.push({x:pe,y:Le}),X++}const $=[];if(l)for(const ue of l){let Ie=0,pe=0;ue==="topleft"?(Ie=-P/2+A,pe=B/2-A):ue==="topright"?(Ie=P/2-A,pe=B/2-A):ue==="bottomleft"?(Ie=-P/2+A,pe=-B/2+A):ue==="bottomright"?(Ie=P/2-A,pe=-B/2+A):ue==="center"&&(Ie=0,pe=0),$.push({x:Ie,y:pe})}const oe=.63,Ae=2,Z=6,se=3,ae=h||_?0:Ae,ce=ae+r,ge=Ve(Cr,{color:"#008080",children:Jn(df,{children:[Ve(ln,{center:[0,0,x+ae],size:[P,B,r]}),$.map((ue,Ie)=>Ve(rl,{center:[ue.x,ue.y,x+ae],radius:i/2,height:r},`hole-${Ie}`)),w.map((ue,Ie)=>Ve(rl,{center:[ue.x,ue.y,x+ae],radius:i/2,height:r},`pin-hole-${Ie}`))]})}),be=w.map((ue,Ie)=>Ve(Cr,{color:"#FFD700",children:Jn(df,{children:[Ve(rl,{center:[ue.x,ue.y,r/2+ae],radius:i/2,height:r}),Ve(rl,{center:[ue.x,ue.y,r/2+ae],radius:o/2,height:r})]})})),ve=w.map((ue,Ie)=>Ve(sdt,{x:ue.x,y:ue.y,pinThickness:oe,shortSidePinLength:se,longSidePinLength:Z,bodyHeight:Ae,flipZ:pe=>pe})),Me=w.map((ue,Ie)=>Ve(ddt,{x:ue.x,y:ue.y,flipZ:pe=>-pe}));return Jn(or,{children:[ge,be,!_&&!h&&ve,_&&Me,f&&Ve(EGn,{width:m??P*.8,height:p??B*.6,offset:{x:g??0,y:y??0,z:ce}})]})},SGn=()=>{const s=.8999999999999999,a=-s/2+.5/2-.15,c=s/2-.5/2+.15,l=.2,A=.5*.24;return Jn(or,{children:[Ve(ln,{color:"#ccc",size:[.5,.28,.12],center:[a,0,.12/2]}),Ve(ln,{color:"#ccc",size:[.5,.28,.12],center:[c,0,.12/2]}),Ve(Cr,{color:"#222",children:Jn(bh,{children:[Ve(Wo,{z:A/2,children:Ve(ln,{size:[s,.6,A]})}),Jn(kl,{children:[Ve(Wo,{z:A,children:Ve(ln,{size:[s,.6,.01]})}),Ve(Wo,{z:.5,children:Ve(ln,{size:[s-l,.6-l,.01]})})]})]})}),Ve(ln,{color:"#777",size:[1.4/6,.6-l,.02],center:[-s/4,0,.5]})]})},PGn=SGn,vGn=({numPins:t=7,showPins:e=!0,showFootprint:n=!0,bodyColor:o="#f5f5f5",pinColor:i="#635959"})=>{const l=3.5999999999999996,A=6,u=(t-1)*1.5+4,_=-((t-1)*1.5)/2;return Jn(or,{children:[Ve(Wo,{offset:[0,0,6],children:Ve(W_,{angles:[Math.PI,0,0],children:Ve(Cr,{color:o,children:Jn(df,{children:[Ve(ln,{size:[u,3.5,6],center:[0,0,6/2]}),Ve(ln,{size:[u-.5*2,3.5-.5*2,l],center:[0,0,l/2]}),Ve(ln,{size:[u,3.5/3,l],center:[0,0,l/6]}),Ve(ln,{size:[u-.5*2,.5/2,l],center:[0,3.5/2-.5/4,l/2]}),Ve(ln,{size:[u-.5*2,.5/2,l],center:[0,-3.5/2+.5/4,l/2]}),Ve(ln,{size:[1,.5+2,1],center:[-u/4,3.5/2,6/2]}),Ve(ln,{size:[1,.5+3,1],center:[u/4,3.5/2,6/2]}),Ve(ln,{size:[1,.5+2,1],center:[-u/4,-3.5/2,6/2]}),Ve(ln,{size:[1,.5+3,1],center:[u/4,-3.5/2,6/2]})]})})})}),e&&Array.from({length:t}).map((h,d)=>Ve(Cr,{color:i,children:Ve(rl,{height:A,radius:.35,center:[_+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:_+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:_+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 Ve(aOn,{hole:p,isPin1:m})})]})},BGn=({footprint:t})=>{let e=t;if(t.startsWith("jstzh1_5mm")){const r=t.match(/jstzh1_5mm(\d+)?/);e=`zh${r&&r[1]?r[1]:"7"}`}const n=sOn.string(e).json();switch(n.fn){case"dip":return Ve(_On,{numPins:n.num_pins,pitch:n.p,bodyWidth:n.w});case"axial":return Ve(CGn,{pitch:n.p});case"tssop":return Ve(hOn,{pinCount:n.num_pins,leadLength:n.pl,leadWidth:n.pw,pitch:n.p,bodyWidth:n.w});case"msop":return Ve(mOn,{pinCount:n.num_pins,padContactLength:n.pl,leadWidth:n.pw,pitch:n.p,bodyWidth:n.w});case"vssop":return Ve(OOn,{pinCount:n.num_pins,leadLength:n.pl,leadWidth:n.pw,pitch:n.p,bodyWidth:n.w,bodyLength:n.h});case"qfp":return Ve(yOn,{pinCount:n.num_pins,pitch:n.p,leadWidth:n.pw,padContactLength:n.pl,bodyWidth:n.w});case"tqfp":return Ve(eGn,{});case"lqfp":return Ve(nGn,{pinCount:n.num_pins});case"qfn":{const r=typeof n.thermalpad?.x=="number"&&typeof n.thermalpad?.y=="number";return Ve(vOn,{num_pins:n.num_pins,bodyWidth:n.w,bodyLength:n.h,pitch:n.p,padLength:n.pl,padWidth:n.pw,thermalPadSize:r?{width:n.thermalpad.x,length:n.thermalpad.y}:void 0})}case"dfn":{const r=typeof n.thermalpad?.x=="number"&&typeof n.thermalpad?.y=="number";return Ve(iGn,{num_pins:n.num_pins,bodyWidth:n.w,bodyLength:n.h,pitch:n.p,padLength:n.pl,padWidth:n.pw,thermalPadSize:r?{width:n.thermalpad.x,length:n.thermalpad.y}:void 0})}case"pinrow":{const r=t.match(/_rows(\d+)/),s=r&&r[1]?parseInt(r[1],10):1;if(n.male)return Ve(EOn,{numberOfPins:n.num_pins,pitch:n.p,invert:n.invert,faceup:n.faceup,rows:s,smd:n.smd||n.surface_mount,rightangle:n.rightangle});if(n.female)return Ve(HOn,{numberOfPins:n.num_pins,pitch:n.p,rows:s})}case"cap":switch(n.imperial){case"0402":return Ve(odt,{color:"#856c4d"});case"0603":return Ve(idt,{color:"#856c4d"});case"0805":return Ve(rdt,{color:"#856c4d"});case"0201":return Ve(adt,{color:"#856c4d"});case"01005":return Ve(cdt,{color:"#856c4d"});case"1206":return Ve(ldt,{color:"#856c4d"});case"1210":return Ve(Adt,{color:"#856c4d"});case"2010":return Ve(udt,{color:"#856c4d"});case"2512":return Ve(_dt,{color:"#856c4d"})}case"sot235":return Ve(MOn,{});case"sot457":return Ve(_Gn,{});case"sot223":return Ve($On,{});case"sot23w":return Ve(wOn,{});case"sot323":return Ve(tGn,{});case"sod323f":return Ve(yGn,{});case"sod323fl":return Ve(xGn,{});case"sot363":return Ve(gGn,{});case"sot886":return Ve(pGn,{});case"sot963":return Ve(dGn,{});case"pushbutton":return Ve(LOn,{width:n.w,length:n.h,innerDiameter:n.id});case"jst":if(n.zh)return Ve(vGn,{numPins:n.num_pins});break;case"soic":return Ve(FOn,{pinCount:n.num_pins,leadLength:n.pl,leadWidth:n.pw,pitch:n.p,bodyWidth:n.w});case"sod523":return Ve(GOn,{});case"sod723":return Ve(PGn,{});case"sod882":return Ve(zOn,{});case"sma":return Ve(UOn,{});case"smb":return Ve(VOn,{});case"smc":return Ve(YOn,{});case"smf":return Ve(KOn,{});case"sod123f":return Ve(WOn,{});case"sod123fl":return Ve(jOn,{});case"sod123w":return Ve(XOn,{});case"sod128":return Ve(JOn,{});case"sod323":return Ve(fGn,{});case"sod923":return Ve(qOn,{});case"hc49":return Ve(rGn,{});case"micromelf":return Ve(sGn,{});case"minimelf":return Ve(aGn,{});case"melf":return Ve(cGn,{});case"ms012":return Ve(lGn,{pinCount:n.num_pins,padContactLength:n.pl,leadWidth:n.pw,pitch:n.p});case"ms013":return Ve(AGn,{pinCount:n.num_pins,padContactLength:n.pl,leadWidth:n.pw,pitch:n.p});case"sot723":return Ve(oGn,{});case"to220":return Ve(uGn,{});case"to92":return Ve(hGn,{});case"stampboard":case"stampreceiver":return Ve(IGn,{bodyWidth:n.w,leadsLeft:n.left,leadsRight:n.right,leadsTop:n.top,leadsBottom:n.bottom,leadsPitch:n.p,leadWidth:n.pw,leadLength:n.pl,innerHoles:n.innerhole,innerHoleEdgeDistance:n.innerholeedgedistance});case"mountedpcbmodule":{const r=n.rows??1,s=n.pinRowSide??"left",a=n.holeInset,c=n.width,l=n.height,A=n.pinrow,u=n.pinRowHoleEdgeToEdgeDist,_=Array.isArray(n.holes)?n.holes:[];return Ve(bGn,{numPins:A,rows:r,p:n.p,id:n.id,od:n.od,width:c,height:l,pinRowSide:s,holes:_,holeInset:a,pinRowHoleEdgeToEdgeDist:u,nopin:n.nopin,female:n.female,screen:n.screen,screenWidth:n.screenwidth,screenHeight:n.screenheight,screenCenterOffsetX:n.screencenteroffsetx,screenCenterOffsetY:n.screencenteroffsety})}}const o=t.match(/_color\(([^)]+)\)/),i=o?o[1]:void 0;switch(n.imperial){case"0402":return Ve(odt,{color:i});case"0603":return Ve(idt,{color:i});case"0805":return Ve(rdt,{color:i});case"0201":return Ve(adt,{color:i});case"01005":return Ve(cdt,{color:i});case"1206":return Ve(ldt,{color:i});case"1210":return Ve(Adt,{color:i});case"2010":return Ve(udt,{color:i});case"2512":return Ve(_dt,{color:i})}return null},MGn=t=>t&&typeof t=="object"&&"type"in t,G7=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},wGn=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 n3(t,e,n){const{jscad:{primitives:o,booleans:i,hulls:r,geometries:s,extrusions:a,transforms:c}}=n;if(t==null||t===!1)return[];if(Array.isArray(t))return t.flatMap(_=>n3(_,e,n));if(!MGn(t))return[];const{type:l,props:A,children:u}=t;if(l===edt)return(u??[]).flatMap(_=>n3(_,e,n));if(l===Cr){const _=A?.color;return(u??[]).flatMap(h=>n3(h,_??e,n))}if(l===Wo){const _=wGn(A?.offset??A?.center??{x:A?.x,y:A?.y,z:A?.z});return(u??[]).flatMap(d=>n3(d,e,n)).map(({geom:d,color:m})=>({geom:c.translate(_,d),color:m??e}))}if(l===W_){const _=Array.isArray(A?.rotation)?[G7(A.rotation[0]),G7(A.rotation[1]),G7(A.rotation[2])]:[G7(A?.x??0),G7(A?.y??0),G7(A?.z??0)];return(u??[]).flatMap(d=>n3(d,e,n)).map(({geom:d,color:m})=>({geom:c.rotateZ(_[2],c.rotateY(_[1],c.rotateX(_[0],d))),color:m}))}if(l===bh||l===df||l===kl){const _=(u??[]).flatMap(d=>n3(d,e,n)).map(d=>d.geom);if(_.length===0)return[];let h;return l===bh?h=i.union(_):l===df?h=i.subtract(_[0],_.slice(1)):h=r.hull(_),[{geom:h,color:e}]}if(l===Vk){const _=A?.points??[];return[{geom:s.geom2.fromPoints(_),color:e??A?.color}]}if(l===Yk){const _=(u??[]).flatMap(p=>n3(p,e,n)).map(p=>p.geom);if(_.length===0)return[];const h=_.length>1?i.union(_):_[0],d=A?.height??A?.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??A?.color}]}if(l===ln||l===tdt||l===rl||l===VX||l===Uk||l===H2){let _;if(l===ln){const h=A?.size??[1,1,1],d=A?.offset,m=A?.center??(d?[d[0],d[1],d[2]]:[0,0,0]);_=o.cuboid({size:h,center:m})}else if(l===tdt){const h=A?.size??1,d=A?.offset,m=A?.center??(d?[d[0],d[1],d[2]]:[0,0,0]);_=o.cube({size:h,center:m})}else if(l===rl){const h=A?.height??1,d=A?.radius??1,m=A?.center??[0,0,0];_=o.cylinder({height:h,radius:d,center:m})}else if(l===VX){const h=A?.radius??1,d=A?.center??[0,0,0];_=o.sphere({radius:h,center:d})}else if(l===H2){const h=A?.height??1,d=A?.radius??1,m=A?.roundRadius??.1,p=A?.center??[0,0,0];_=o.roundedCylinder({height:h,radius:d,roundRadius:m,center:p})}else{const h=A?.size??[1,1,1],d=A?.roundRadius??.1,m=A?.center??[0,0,0];_=o.roundedCuboid({size:h,roundRadius:d,center:m})}return[{geom:_,color:e??A?.color}]}if(typeof l=="function"){const _=l(A??{});return n3(_,e,n)}return(u??[]).flatMap(_=>n3(_,e,n))}function DGn(t,e){return{geometries:n3(t,void 0,{jscad:e})}}function hdt(t){if(t.polygons){const e=[],n=[],o=[];let i=0;for(const s of t.polygons){for(const c of s.vertices)c.index=i,e.push(c[0],c[1],c[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 c=2;c<s.vertices.length;c++){const l=s.vertices[c-1].index,A=s.vertices[c].index;n.push(a,l,A)}}const r=new oA;if(r.setAttribute("position",new JA(new Float32Array(e),3)),r.setIndex(n),o.length>0&&r.setAttribute("color",new JA(new Float32Array(o),3)),t.transforms){const s=new ys;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 oA;if(o.setAttribute("position",new JA(new Float32Array(e),3)),n.length>0&&o.setAttribute("color",new JA(new Float32Array(n),3)),t.transforms){const i=new ys;i.fromArray(t.transforms),o.applyMatrix4(i)}return o}return console.error("Invalid CSG object: neither polygons nor sides found"),new oA}function TGn(t,e){const n=d5e(BGn,{footprint:t});return DGn(n,e)}var QGn=xl(NX()),mdt=ne.createContext(null),RGn=()=>{const t=ne.useContext(mdt);if(!t)throw new Error("useHover must be used within a HoverProvider");return t},NGn=({children:t})=>{const{camera:e,renderer:n}=g1(),[o,i]=ne.useState([]),r=ne.useMemo(()=>new _7t,[]),s=ne.useMemo(()=>new Ki,[]),a=ne.useRef(o);a.current=o;const c=ne.useRef(null),l=ne.useCallback(d=>{i(m=>[...m,d])},[]),A=ne.useCallback(d=>{if(c.current){let m=!1,p=c.current.object;for(;p;){if(p===d){m=!0;break}p=p.parent}m&&(c.current.onUnhover(),c.current=null)}i(m=>m.filter(p=>p.object!==d))},[]),u=ne.useCallback(d=>{let m=d;for(;m;){const p=a.current.find(g=>g.object===m);if(p)return p;m=m.parent}},[]),_=ne.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(y=>y.object);if(p.length===0){c.current&&(c.current.onUnhover(),c.current=null);return}const g=r.intersectObjects(p,!0);if(g.length>0){const y=g[0],f=u(y.object);if(f){const x={mousePosition:[y.point.x,y.point.y,y.point.z]};c.current!==f?(c.current?.onUnhover(),f.onHover(x),c.current=f):f.onHover(x)}else c.current&&(c.current.onUnhover(),c.current=null)}else c.current&&(c.current.onUnhover(),c.current=null)},[e,n,r,s,u]);ne.useEffect(()=>{const d=n.domElement;return d.addEventListener("mousemove",_),()=>{d.removeEventListener("mousemove",_)}},[n,_]);const h=ne.useMemo(()=>({addHoverable:l,removeHoverable:A}),[l,A]);return W.jsx(mdt.Provider,{value:h,children:t})},kGn=({children:t,object:e,onHover:n,onUnhover:o,isHovered:i})=>{const{addHoverable:r,removeHoverable:s}=RGn();return ne.useEffect(()=>e?(r({object:e,onHover:n,onUnhover:o}),()=>{s(e)}):void 0,[e,n,o,r,s]),W.jsx(W.Fragment,{children:t})},eH=kGn,HGn=({positionOffset:t,footprint:e,rotationOffset:n,onHover:o,onUnhover:i,isHovered:r,scale:s,isTranslucent:a=!1})=>{const{rootObject:c}=g1(),l=ne.useMemo(()=>{if(!e)return null;const{geometries:A}=TGn(e,QGn),u=new Xm;for(const _ of A.flat(1/0)){const h=_.geom;if(!h||!h.polygons&&!h.sides)continue;const d=new xi(_.color);d.convertLinearToSRGB();const m={...h,color:[d.r,d.g,d.b]},p=hdt(m),g=new Xg({vertexColors:!0,side:$h,transparent:a,opacity:a?.5:1,depthWrite:!a}),y=new Mr(p,g);y.renderOrder=a?2:1,u.add(y)}return u},[e,a]);return ne.useEffect(()=>{if(!(!l||!c))return c.add(l),()=>{c.remove(l)}},[c,l]),ne.useEffect(()=>{l&&(t&&l.position.fromArray(t),n&&l.rotation.fromArray(n),s!==void 0&&l.scale.setScalar(s))},[l,t?.[0],t?.[1],t?.[2],n?.[0],n?.[1],n?.[2],s]),ne.useEffect(()=>{l&&l.traverse(A=>{A instanceof Mr&&A.material instanceof Xg&&(r?(A.material.emissive.setHex(255),A.material.emissiveIntensity=.2):A.material.emissiveIntensity=0)})},[r,l]),l?W.jsx(eH,{isHovered:r,onHover:o,onUnhover:i,object:l}):null},gdt=new WeakMap,LGn=()=>{const t=new b0;return t.name="fallback-environment-map",t.mapping=wO,t},FGn=t=>{if(!t)return null;const e=t,n=gdt.get(e);if(n)return n;let o;if(t instanceof cG){const i=new mne(t);o=i.fromScene(PTt(),.04).texture,i.dispose()}else o=LGn();return gdt.set(e,o),o};function OGn(t){const e=new Wx;let n=!1;t.updateWorldMatrix(!0,!1);const o=t.parent?t.parent.matrixWorld.clone().invert():new ys;return t.traverse(i=>{if(i.updateWorldMatrix(!0,!1),i instanceof Mr&&i.geometry&&(i.geometry.boundingBox||i.geometry.computeBoundingBox(),i.geometry.boundingBox)){const r=i.geometry.boundingBox.clone();r.applyMatrix4(i.matrixWorld),r.applyMatrix4(o),n?e.union(r):(e.copy(r),n=!0)}}),n?e:null}function GGn(t){const e=OGn(t);return e?e.getSize(new Dt):new Dt}function zGn(t,e,n="contain_within_bounds"){if(!e)return[1,1,1];const o=GGn(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 Q5e=({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:c})=>{const{rootObject:l}=g1(),A=ne.useMemo(()=>new Xm,[]),u=ne.useMemo(()=>new Xm,[]),_=ne.useMemo(()=>new Xm,[]),h=ne.useMemo(()=>new Xm,[]);return ne.useEffect(()=>(A.add(u),()=>{A.remove(u)}),[A,u]),ne.useEffect(()=>(u.add(_),()=>{u.remove(_)}),[u,_]),ne.useEffect(()=>(_.add(h),()=>{_.remove(h)}),[_,h]),ne.useEffect(()=>{for(;h.children.length>0;){const d=h.children[0];if(!d)break;h.remove(d)}t&&h.add(t)},[h,t]),ne.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]),ne.useEffect(()=>{if(l)return l.add(A),()=>{l.remove(A)}},[l,A]),ne.useEffect(()=>{if(e?A.position.fromArray(e):A.position.set(0,0,0),n?A.rotation.fromArray(n):A.rotation.set(0,0,0),_.position.fromArray(o),_.rotation.fromArray(i),_.scale.setScalar(c??1),!t){u.scale.set(1,1,1);return}u.scale.set(1,1,1),u.updateWorldMatrix(!0,!0);const d=zGn(_,s,a);u.scale.set(d[0],d[1],d[2])},[A,u,t,a,o,h,_,i,s,e,n,c]),{boardTransformGroup:A}},pdt=1.25;function fdt({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:c,onUnhover:l,isHovered:A,scale:u,isTranslucent:_=!1}){const{renderer:h}=g1(),[d,m]=ne.useState(null),[p,g]=ne.useState(null),{boardTransformGroup:y}=Q5e({model:d,position:e,rotation:n,modelOffset:o,modelRotation:i,sourceCoordinateTransform:r,modelSize:s,modelFitMode:a,scale:u});if(ne.useEffect(()=>{if(!t)return;const f=new BTt;let x=!0;return f.load(t,I=>{if(!x)return;const E=I.scene;E.traverse(b=>{if(b instanceof Mr&&b.material){const P=B=>{B.transparent=_,B.opacity=_?.5:1,B.depthWrite=!_,B.needsUpdate=!0};Array.isArray(b.material)?b.material.forEach(P):P(b.material),b.renderOrder=_?2:1}}),m(E)},void 0,I=>{if(!x)return;console.error(`An error happened loading ${t}`,I);const E=I instanceof Error?I:new Error(`Failed to load glTF model from ${t}`);g(E)}),()=>{x=!1}},[t,_]),ne.useEffect(()=>{if(!d||!h)return;const f=FGn(h);if(!f)return;const x=[],I=E=>{E instanceof Xg&&(x.push({material:E,envMap:E.envMap??null,envMapIntensity:E.envMapIntensity??1}),E.envMap=f,(typeof E.envMapIntensity!="number"||E.envMapIntensity<pdt)&&(E.envMapIntensity=pdt),E.needsUpdate=!0)};return d.traverse(E=>{if(!(E instanceof Mr))return;const b=E.material;Array.isArray(b)?b.forEach(I):b&&I(b)}),()=>{x.forEach(({material:E,envMap:b,envMapIntensity:P})=>{E.envMap=b,E.envMapIntensity=P,E.needsUpdate=!0})}},[d,h]),ne.useEffect(()=>{d&&d.traverse(f=>{f instanceof Mr&&f.material instanceof Xg&&(A?(f.material.emissive.setHex(255),f.material.emissiveIntensity=.2):f.material.emissiveIntensity=0)})},[A,d]),p)throw p;return d?W.jsx(eH,{isHovered:A,onHover:c,onUnhover:l,object:y}):null}var UGn=xl(I_t()),VGn=xl(NX()),YGn=({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:c,onUnhover:l,isHovered:A,scale:u,isTranslucent:_=!1})=>{const{threeGeom:h,material:d}=ne.useMemo(()=>{const g=(0,UGn.executeJscadOperations)(VGn.default,t);if(!g||!g.polygons&&!g.sides)return{threeGeom:null,material:null};const y=hdt(g),f=new Xg({vertexColors:!0,side:$h,transparent:_,opacity:_?.5:1,depthWrite:!_});return{threeGeom:y,material:f}},[t,_]),m=ne.useMemo(()=>{if(!h)return null;const g=new Mr(h,d);return g.renderOrder=_?2:1,g},[h,d,_]),{boardTransformGroup:p}=Q5e({model:m,position:e,rotation:n,modelOffset:o,modelRotation:i,sourceCoordinateTransform:r,modelSize:s,modelFitMode:a,scale:u});return ne.useEffect(()=>{if(d)if(A){const g=new xi(d.color.getHex());d.emissive.copy(g),d.emissive.setRGB(0,0,1),d.emissiveIntensity=.2}else d.emissiveIntensity=0},[A,d]),h?W.jsx(eH,{isHovered:A,onHover:c,onUnhover:l,object:p}):null};function KGn(t){return t.replace(/(DEF|USE)\s+([^\s]+)/g,(e,n,o)=>`${n} ${o.replace(/-/g,"_")}`)}async function WGn(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 dQt().parse(KGn(n),t)}typeof window<"u"&&!window.TSCIRCUIT_OBJ_LOADER_CACHE&&(window.TSCIRCUIT_OBJ_LOADER_CACHE=new Map);function jGn(t){const[e,n]=ne.useState(null);return ne.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 WGn(o);const c=await fetch(o);if(!c.ok)throw new Error(`Failed to fetch "${o}": ${c.status} ${c.statusText}`);const l=await c.text(),A=l.match(/newmtl[\s\S]*?endmtl/g),u=new IQt;if(A?.length){const _=A.join(`
|
|
5197
|
-
`).replace(/d 0\./g,"d 1."),h=l.replace(/newmtl[\s\S]*?endmtl/g,"").replace(/^mtllib.*/gm,""),d=new AQt;d.setMaterialOptions({invertTrProperty:!0});const m=d.parse(_.replace(/Kd\s+([\d.]+)\s+([\d.]+)\s+([\d.]+)/g,"Kd $2 $2 $2"),"embedded.mtl");return u.setMaterials(m),u.parse(h)}return u.parse(l.replace(/^mtllib.*/gm,""))}catch(c){return c}}function a(){if(i.has(o)){const l=i.get(o);return l.result?Promise.resolve(l.result.clone()):l.promise.then(A=>A instanceof Error?A:A.clone())}const c=s().then(l=>(l instanceof Error||i.set(o,{...i.get(o),result:l}),l));return i.set(o,{promise:c,result:null}),c}return a().then(c=>{r||n(c)}).catch(c=>{console.error(c)}),()=>{r=!0}},[t]),e}function XGn({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:c,onUnhover:l,isHovered:A,scale:u,isTranslucent:_=!1}){const h=jGn(t),d=ne.useMemo(()=>h&&!(h instanceof Error)?(h.traverse(p=>{if(p instanceof Mr&&p.material){const g=y=>{y.transparent=_,y.opacity=_?.5:1,y.depthWrite=!_,y.needsUpdate=!0};Array.isArray(p.material)?p.material.forEach(g):g(p.material),p.renderOrder=_?2:1}}),h):new Mr(new ZC(.5,.5,.5),new Xg({transparent:!0,color:"red",opacity:.25})),[h,_]),{boardTransformGroup:m}=Q5e({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:u});if(h instanceof Error)throw h;return W.jsx(eH,{isHovered:A,onHover:c,onUnhover:l,object:m})}var R5e,JGn="https://cdn.jsdelivr.net/npm/occt-import-js@0.0.23/dist";function qGn(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 $Gn(){if(!R5e){const t=await import("https://cdn.jsdelivr.net/npm/occt-import-js@0.0.23/+esm");R5e=qGn(t)({locateFile:n=>`${JGn}/${n}`})}return R5e}function ZGn(t){const e=new Xm;for(const n of t){const o=n.attributes.position?.array??[],i=n.index?.array??[];if(!o.length||!i.length)continue;const r=new oA;r.setAttribute("position",new xs(o,3));const s=n.attributes.normal?.array??[];s.length?r.setAttribute("normal",new xs(s,3)):r.computeVertexNormals(),r.setIndex(i);const a=new Xg({color:n.color?new xi(n.color[0],n.color[1],n.color[2]):new xi(.82,.82,.82)}),c=new Mr(r,a);c.name=n.name,e.add(c)}return e}async function ezn(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 $Gn()).ReadStepFile(new Uint8Array(n),null);if(!i.success||!i.meshes.length)throw new Error("occt-import-js failed to convert STEP file");const r=ZGn(i.meshes),s=new Woe;return await new Promise((c,l)=>{s.parse(r,A=>{A instanceof ArrayBuffer?c(A):l(new Error("GLTFExporter did not return binary output"))},A=>{l(A)},{binary:!0})})}var ydt="step-glb-cache:";function tzn(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 nzn(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 ozn(t){try{const e=localStorage.getItem(`${ydt}${t}`);return e?nzn(e):null}catch(e){return console.warn("Failed to read STEP GLB cache",e),null}}function xdt(t,e){try{const n=tzn(e);localStorage.setItem(`${ydt}${t}`,n)}catch(n){console.warn("Failed to write STEP GLB cache",n)}}function izn(){const t=globalThis;return t.stepUrlToGltfModelConversions||(t.stepUrlToGltfModelConversions={inProgress:new Map,completed:new Map}),t.stepUrlToGltfModelConversions}var rzn=({stepUrl:t,position:e,rotation:n,modelOffset:o,modelRotation:i,sourceCoordinateTransform:r,modelSize:s,modelFitMode:a,scale:c,onHover:l,onUnhover:A,isHovered:u,isTranslucent:_})=>{const[h,d]=ne.useState(null);return ne.useEffect(()=>{let m=!0,p=null,g=!0;const y=izn(),f=ozn(t);if(f){const E={arrayBuffer:f,blobUrl:URL.createObjectURL(new Blob([f],{type:"model/gltf-binary"}))};return y.completed.set(t,E),p=E.blobUrl,g=!1,d(E.blobUrl),()=>{m=!1,p&&g&&URL.revokeObjectURL(p)}}const x=y.completed.get(t);if(x)return p=x.blobUrl,g=!1,d(x.blobUrl),xdt(t,x.arrayBuffer),()=>{m=!1,p&&g&&URL.revokeObjectURL(p)};let I=y.inProgress.get(t);return I||(I=ezn(t).then(E=>{const b={arrayBuffer:E,blobUrl:URL.createObjectURL(new Blob([E],{type:"model/gltf-binary"}))};return y.completed.set(t,b),y.inProgress.delete(t),b}).catch(E=>{throw y.inProgress.delete(t),E}),y.inProgress.set(t,I)),I.then(E=>{m&&(p=E.blobUrl,g=!1,d(E.blobUrl),xdt(t,E.arrayBuffer))}).catch(E=>{console.error("Failed to convert STEP file to GLB",E),m&&d(null)}),()=>{m=!1,p&&g&&URL.revokeObjectURL(p)}},[t]),h?W.jsx(fdt,{gltfUrl:h,position:e,rotation:n,modelOffset:o,modelRotation:i,sourceCoordinateTransform:r,modelSize:s,modelFitMode:a,scale:c,onHover:l,onUnhover:A,isHovered:u,isTranslucent:_}):null};function jX(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=N5e(r,e.axisMapping.x)),e.axisMapping.y&&(o=N5e(r,e.axisMapping.y)),e.axisMapping.z&&(i=N5e(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),c=o*s-i*a,l=o*a+i*s;o=c,i=l}if(e.rotation.y){const r=e.rotation.y*Math.PI/180,s=Math.cos(r),a=Math.sin(r),c=n*s+i*a,l=-n*a+i*s;n=c,i=l}if(e.rotation.z){const r=e.rotation.z*Math.PI/180,s=Math.cos(r),a=Math.sin(r),c=n*s-o*a,l=n*a+o*s;n=c,o=l}}return{x:n,y:o,z:i}}function N5e(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 k5e={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 szn(t,e){if(e.coordinateTransform)return e.coordinateTransform;if(!e.usingGlbCoordinates){if(e.hasFootprinterModel)return k5e.FOOTPRINTER_MODEL_TRANSFORM;if(!e.usingObjFormat)return e.usingStepFormat?k5e.STEP_INVERTED:k5e.Z_UP_TO_Y_UP_USB_FIX}}function tH(t,e){return szn(t,{usingGlbCoordinates:e==="gltf"||e==="glb"||e==="jscad",usingObjFormat:e==="obj"||e==="wrl",usingStepFormat:e==="step",hasFootprinterModel:e==="footprinter"})}function XX(t){if(!t)return;const e=jX({x:1,y:0,z:0},t),n=jX({x:0,y:1,z:0},t),o=jX({x:0,y:0,z:1},t);return new ys().makeBasis(new Dt(e.x,e.y,e.z),new Dt(n.x,n.y,n.z),new Dt(o.x,o.y,o.z))}function L4(t){return t*Math.PI/180}function azn(t){if(t==="z+")return[0,0,0];switch(t){case"x+":return[0,L4(-90),0];case"x-":return[0,L4(90),0];case"y+":return[L4(90),0,0];case"y-":return[L4(-90),0,0];case"z-":return[L4(180),0,0];default:return[0,0,0]}}function czn(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 lzn(t,e){return t.rotation?[L4(t.rotation.x),L4(t.rotation.y),L4(t.rotation.z)]:e==="bottom"?[Math.PI,0,0]:[0,0,0]}function Azn(t,e){const n=new Dt(t.x,t.y,t.z),o=new n1(e[0],e[1],e[2],"XYZ");return n.applyEuler(o),[n.x,n.y,n.z]}function uzn(t,e,n){if(!t.model_origin_position)return[0,0,0];const o=e?jX(t.model_origin_position,e):t.model_origin_position;return Azn(o,n)}function _zn(t,e){const n=czn(t,e.layer,e.pcbThickness),o=lzn(t,e.layer),i=tH(t,e.modelType),r=azn(t.model_board_normal_direction??"z+"),s=uzn(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 dzn=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",hzn=t=>t==="step"?"glb":t,mzn=(t,e)=>{if(t)return e?e(t):t},gzn=(...t)=>t,H5e=class extends Qi.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}},pzn=({error:t,onError:e})=>(ne.useEffect(()=>{e(t)},[t,e]),null),Cdt=({cad_component:t,circuitJson:e,resolveStaticAsset:n})=>{const o=S_t(e),[i,r]=ne.useState(!1),{visibility:s}=hB(),[a,c]=ne.useState(null),l=ne.useCallback(K=>{K?.mousePosition?(r(!0),c(K.mousePosition)):(r(!1),c(null))},[]),A=ne.useCallback(()=>{r(!1),c(null)},[]),u=ne.useMemo(()=>Ni(e).source_component.getUsing({source_component_id:t.source_component_id})?.name,[e,t.source_component_id]),_=ne.useMemo(()=>e.filter(X=>X.type==="pcb_plated_hole"&&X.pcb_component_id===t.pcb_component_id).length>0,[e,t.pcb_component_id]),h=ne.useCallback(K=>mzn(K,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),[g,y]=ne.useState(0),[f,x]=ne.useState(null);ne.useEffect(()=>{y(0),x(null)},[t.cad_component_id,d,m,p]);const E=e.find(K=>K.type==="pcb_component"&&K.source_component_id===t.source_component_id)?.layer??"top",b=dzn(t),P=hzn(b),B=t.model_glb_url?"glb":"gltf",w=t.model_wrl_url?"wrl":t.model_stl_url?"stl":"obj",k=ne.useMemo(()=>_zn(t,{layer:E,pcbThickness:o,modelType:P}),[t,E,o,P]),N=gzn(...k.rotation),F=k.position,O=ne.useMemo(()=>{const K=[];return m&&K.push(W.jsx(fdt,{gltfUrl:m,position:F,rotation:N,modelOffset:k.modelPosition,modelRotation:k.modelRotation,sourceCoordinateTransform:XX(tH(t,B)),scale:k.scale,modelSize:k.size,modelFitMode:k.fitMode,onHover:l,onUnhover:A,isHovered:i,isTranslucent:t.show_as_translucent_model},`${t.cad_component_id}-gltf-${m}`)),d&&K.push(W.jsx(XGn,{url:d,position:F,rotation:N,modelOffset:k.modelPosition,modelRotation:k.modelRotation,sourceCoordinateTransform:XX(tH(t,w)),scale:k.scale,modelSize:k.size,modelFitMode:k.fitMode,onHover:l,onUnhover:A,isHovered:i,isTranslucent:t.show_as_translucent_model},`${t.cad_component_id}-mixed-${d}`)),p&&!t.model_jscad&&!t.footprinter_string&&K.push(W.jsx(rzn,{stepUrl:p,position:F,rotation:N,modelOffset:k.modelPosition,modelRotation:k.modelRotation,sourceCoordinateTransform:XX(tH(t,P)),scale:k.scale,modelSize:k.size,modelFitMode:k.fitMode,onHover:l,onUnhover:A,isHovered:i,isTranslucent:t.show_as_translucent_model},`${t.cad_component_id}-step-${p}`)),K},[F,t.cad_component_id,t.footprinter_string,t.model_jscad,t.show_as_translucent_model,m,B,l,A,i,w,k.modelPosition,k.modelRotation,k.scale,k.fitMode,k.size,P,N,p,d]);let G=null;if(O.length>0){if(g>=O.length){if(f)throw f;return null}G=W.jsx(H5e,{fallback:({error:K})=>W.jsx(pzn,{error:K,onError:X=>{x(X),y($=>Math.max($,g+1))}}),children:O[g]},`${t.cad_component_id}-fallback-${g}`)}else t.model_jscad?G=W.jsx(YGn,{jscadPlan:t.model_jscad,positionOffset:F,rotationOffset:N,modelOffset:k.modelPosition,modelRotation:k.modelRotation,sourceCoordinateTransform:XX(tH(t,"jscad")),scale:k.scale,modelSize:k.size,modelFitMode:k.fitMode,onHover:l,onUnhover:A,isHovered:i,isTranslucent:t.show_as_translucent_model},t.cad_component_id):t.footprinter_string&&(G=W.jsx(HGn,{positionOffset:F,rotationOffset:N,footprint:t.footprinter_string,scale:k.scale,onHover:l,onUnhover:A,isHovered:i,isTranslucent:t.show_as_translucent_model}));if(t.show_as_translucent_model){if(!s.translucentModels)return null}else if(_&&!s.throughHoleModels||!_&&!s.smtModels)return null;return W.jsxs(W.Fragment,{children:[G,i&&a?W.jsx(v_t,{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:u??"<unknown>"}):null]})},Idt={version:"0.0.563"};function fzn(t){t.querySelectorAll("canvas").forEach(e=>e.remove())}var yzn=t=>{t.outputColorSpace=YC,t.toneMapping=qve,t.toneMappingExposure=1},Edt="cadViewerCameraStateSession",bdt=(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(Edt,JSON.stringify(n))}catch(n){console.warn("Failed to save camera:",n)}},L5e=(t,e)=>{try{const n=sessionStorage.getItem(Edt);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}},Sdt=ne.createContext(void 0),xzn=({children:t,defaultTarget:e,initialCameraPosition:n,initialCameraType:o})=>{const i=ne.useRef(null),r=ne.useRef(null),[s,a]=ne.useState(null),[c,l]=ne.useState(o??"perspective"),[A,u]=ne.useState(n??null),[_,h]=ne.useState(new n1(0,0,0)),d=ne.useMemo(()=>{const[y,f,x]=n??[5,-5,5],I=Math.hypot(y-e.x,f-e.y,x-e.z);return I>0?I:5},[n,e]),m=ne.useCallback(y=>{const f=[e.x,e.y,e.z],x=r.current,I=i.current;let E=d;switch(x&&I&&(E=x.position.distanceTo(I.target)),y){case"Top Center Angled":{const b=E/Math.sqrt(2);return{position:[e.x,e.y-b,e.z+b],target:f,up:[0,0,1]}}case"Top Down":return{position:[e.x,e.y,e.z+E],target:f,up:[0,0,1]};case"Top Left Corner":return{position:[e.x-E*.6,e.y-E*.6,e.z+E*.6],target:f,up:[0,0,1]};case"Top Right Corner":return{position:[e.x+E*.6,e.y-E*.6,e.z+E*.6],target:f,up:[0,0,1]};case"Left Sideview":return{position:[e.x-E,e.y,e.z],target:f,up:[0,0,1]};case"Right Sideview":return{position:[e.x+E,e.y,e.z],target:f,up:[0,0,1]};case"Front":return{position:[e.x,e.y-E,e.z],target:f,up:[0,0,1]};default:return null}},[d,e,r,i]),p=ne.useCallback(y=>{i.current=y},[]),g=ne.useMemo(()=>({controlsRef:i,mainCameraRef:r,defaultTarget:e,baseDistance:d,controller:s,setController:a,getPresetConfig:m,handleControlsChange:p,cameraType:c,setCameraType:l,cameraPosition:A,setCameraPosition:u,cameraRotation:_,setCameraRotation:h,saveCameraToSession:bdt,loadCameraFromSession:L5e}),[e,d,s,m,p,c,A,_]);return W.jsx(Sdt.Provider,{value:g,children:t})},F4=()=>{const t=ne.useContext(Sdt);if(!t)throw new Error("useCameraController must be used within a CameraControllerProvider");return t},Czn=ne.forwardRef(({children:t,scene:e,camera:n,style:o,onCreated:i},r)=>{const{cameraType:s}=F4(),a=ne.useRef(null),[c,l]=ne.useState(null),A=ne.useRef([]),u=ne.useRef(void 0);u.current=i;const _=ne.useRef(null),h=ne.useCallback(g=>{A.current.push(g)},[]),d=ne.useCallback(g=>{A.current=A.current.filter(y=>y!==g)},[]),m=ne.useMemo(()=>new B6,[]);e?.up&&m.up.set(e.up.x,e.up.y,e.up.z);const p=ne.useRef(new nA);return ne.useImperativeHandle(r,()=>p.current),ne.useEffect(()=>{if(!a.current)return;fzn(a.current);const g=new cG({antialias:!0,alpha:!0});yzn(g),g.setSize(a.current.clientWidth,a.current.clientHeight),g.setPixelRatio(window.devicePixelRatio),a.current.appendChild(g.domElement);const y=a.current.clientWidth/a.current.clientHeight,f=s==="perspective"?new jm(75,y,.1,1e3):new eQ(-10*y,10*y,10,-10,-1e3,1e3);_.current?(f.position.copy(_.current.position),f.quaternion.copy(_.current.quaternion),f.up.copy(_.current.up)):(n?.up&&f.up.set(n.up[0],n.up[1],n.up[2]),n?.position&&f.position.set(n.position[0],n.position[1],n.position[2]),f.lookAt(0,0,0)),m.add(p.current),window.__TSCIRCUIT_THREE_OBJECT=p.current,l({scene:m,camera:f,renderer:g,rootObject:p.current,addFrameListener:h,removeFrameListener:d}),u.current?.({camera:f,renderer:g});let x;const I=new n7t,E=()=>{const P=I.getElapsedTime(),B=I.getDelta();A.current.forEach(w=>w(P,B)),g.render(m,f),x=requestAnimationFrame(E)};E();const b=()=>{if(a.current){const P=a.current.clientWidth/a.current.clientHeight;f instanceof jm?f.aspect=P:f instanceof eQ&&(f.left=-10*P,f.right=10*P,f.top=10,f.bottom=-10),f.updateProjectionMatrix(),g.setSize(a.current.clientWidth,a.current.clientHeight)}};return window.addEventListener("resize",b),()=>{_.current={position:f.position.clone(),quaternion:f.quaternion.clone(),up:f.up.clone()},window.removeEventListener("resize",b),cancelAnimationFrame(x),a.current&&g.domElement&&a.current.removeChild(g.domElement),g.dispose(),m.remove(p.current),window.__TSCIRCUIT_THREE_OBJECT===p.current&&(window.__TSCIRCUIT_THREE_OBJECT=void 0)}},[m,h,d,s]),W.jsx("div",{ref:a,style:{width:"100%",height:"100%",...o},children:c&&W.jsx(P_t.Provider,{value:c,children:W.jsx(NGn,{children:t})})})}),Izn=({autoRotate:t,autoRotateSpeed:e,onStart:n,panSpeed:o,rotateSpeed:i,zoomSpeed:r,enableDamping:s,dampingFactor:a,target:c,onControlsChange:l})=>{const{camera:A,renderer:u}=g1(),_=ne.useMemo(()=>!A||!u?null:new bQt(A,u.domElement),[A,u]);return ne.useEffect(()=>(l?.(_??null),()=>l?.(null)),[_,l]),ne.useEffect(()=>{if(!_)return;const h=()=>{l?.(_)};return _.addEventListener("change",h),()=>{_.removeEventListener("change",h)}},[_,l]),ne.useEffect(()=>{_&&(_.autoRotate=t||!1,_.autoRotateSpeed=e||1,o!==void 0&&(_.panSpeed=o),i!==void 0&&(_.rotateSpeed=i),r!==void 0&&(_.zoomSpeed=r),s!==void 0&&(_.enableDamping=s),a!==void 0&&(_.dampingFactor=a),_.zoomToCursor=!0,_.mouseButtons={LEFT:Vb.ROTATE,MIDDLE:Vb.PAN,RIGHT:null},c&&(_.target.set(c[0],c[1],c[2]),_.update()))},[_,t,e,o,i,r,s,a,c]),ne.useEffect(()=>{if(!(!_||!n))return _.addEventListener("start",n),()=>{_.removeEventListener("start",n)}},[_,n]),ne.useEffect(()=>{if(_)return()=>{_.dispose()}},[_]),Fk(()=>{_?.update()},[_]),null},Ezn=`
|
|
5197
|
+
`).replace(/d 0\./g,"d 1."),h=l.replace(/newmtl[\s\S]*?endmtl/g,"").replace(/^mtllib.*/gm,""),d=new AQt;d.setMaterialOptions({invertTrProperty:!0});const m=d.parse(_.replace(/Kd\s+([\d.]+)\s+([\d.]+)\s+([\d.]+)/g,"Kd $2 $2 $2"),"embedded.mtl");return u.setMaterials(m),u.parse(h)}return u.parse(l.replace(/^mtllib.*/gm,""))}catch(c){return c}}function a(){if(i.has(o)){const l=i.get(o);return l.result?Promise.resolve(l.result.clone()):l.promise.then(A=>A instanceof Error?A:A.clone())}const c=s().then(l=>(l instanceof Error||i.set(o,{...i.get(o),result:l}),l));return i.set(o,{promise:c,result:null}),c}return a().then(c=>{r||n(c)}).catch(c=>{console.error(c)}),()=>{r=!0}},[t]),e}function XGn({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:c,onUnhover:l,isHovered:A,scale:u,isTranslucent:_=!1}){const h=jGn(t),d=ne.useMemo(()=>h&&!(h instanceof Error)?(h.traverse(p=>{if(p instanceof Mr&&p.material){const g=y=>{y.transparent=_,y.opacity=_?.5:1,y.depthWrite=!_,y.needsUpdate=!0};Array.isArray(p.material)?p.material.forEach(g):g(p.material),p.renderOrder=_?2:1}}),h):new Mr(new ZC(.5,.5,.5),new Xg({transparent:!0,color:"red",opacity:.25})),[h,_]),{boardTransformGroup:m}=Q5e({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:u});if(h instanceof Error)throw h;return W.jsx(eH,{isHovered:A,onHover:c,onUnhover:l,object:m})}var R5e,JGn="https://cdn.jsdelivr.net/npm/occt-import-js@0.0.23/dist";function qGn(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 $Gn(){if(!R5e){const t=await import("https://cdn.jsdelivr.net/npm/occt-import-js@0.0.23/+esm");R5e=qGn(t)({locateFile:n=>`${JGn}/${n}`})}return R5e}function ZGn(t){const e=new Xm;for(const n of t){const o=n.attributes.position?.array??[],i=n.index?.array??[];if(!o.length||!i.length)continue;const r=new oA;r.setAttribute("position",new xs(o,3));const s=n.attributes.normal?.array??[];s.length?r.setAttribute("normal",new xs(s,3)):r.computeVertexNormals(),r.setIndex(i);const a=new Xg({color:n.color?new xi(n.color[0],n.color[1],n.color[2]):new xi(.82,.82,.82)}),c=new Mr(r,a);c.name=n.name,e.add(c)}return e}async function ezn(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 $Gn()).ReadStepFile(new Uint8Array(n),null);if(!i.success||!i.meshes.length)throw new Error("occt-import-js failed to convert STEP file");const r=ZGn(i.meshes),s=new Woe;return await new Promise((c,l)=>{s.parse(r,A=>{A instanceof ArrayBuffer?c(A):l(new Error("GLTFExporter did not return binary output"))},A=>{l(A)},{binary:!0})})}var ydt="step-glb-cache:";function tzn(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 nzn(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 ozn(t){try{const e=localStorage.getItem(`${ydt}${t}`);return e?nzn(e):null}catch(e){return console.warn("Failed to read STEP GLB cache",e),null}}function xdt(t,e){try{const n=tzn(e);localStorage.setItem(`${ydt}${t}`,n)}catch(n){console.warn("Failed to write STEP GLB cache",n)}}function izn(){const t=globalThis;return t.stepUrlToGltfModelConversions||(t.stepUrlToGltfModelConversions={inProgress:new Map,completed:new Map}),t.stepUrlToGltfModelConversions}var rzn=({stepUrl:t,position:e,rotation:n,modelOffset:o,modelRotation:i,sourceCoordinateTransform:r,modelSize:s,modelFitMode:a,scale:c,onHover:l,onUnhover:A,isHovered:u,isTranslucent:_})=>{const[h,d]=ne.useState(null);return ne.useEffect(()=>{let m=!0,p=null,g=!0;const y=izn(),f=ozn(t);if(f){const E={arrayBuffer:f,blobUrl:URL.createObjectURL(new Blob([f],{type:"model/gltf-binary"}))};return y.completed.set(t,E),p=E.blobUrl,g=!1,d(E.blobUrl),()=>{m=!1,p&&g&&URL.revokeObjectURL(p)}}const x=y.completed.get(t);if(x)return p=x.blobUrl,g=!1,d(x.blobUrl),xdt(t,x.arrayBuffer),()=>{m=!1,p&&g&&URL.revokeObjectURL(p)};let I=y.inProgress.get(t);return I||(I=ezn(t).then(E=>{const b={arrayBuffer:E,blobUrl:URL.createObjectURL(new Blob([E],{type:"model/gltf-binary"}))};return y.completed.set(t,b),y.inProgress.delete(t),b}).catch(E=>{throw y.inProgress.delete(t),E}),y.inProgress.set(t,I)),I.then(E=>{m&&(p=E.blobUrl,g=!1,d(E.blobUrl),xdt(t,E.arrayBuffer))}).catch(E=>{console.error("Failed to convert STEP file to GLB",E),m&&d(null)}),()=>{m=!1,p&&g&&URL.revokeObjectURL(p)}},[t]),h?W.jsx(fdt,{gltfUrl:h,position:e,rotation:n,modelOffset:o,modelRotation:i,sourceCoordinateTransform:r,modelSize:s,modelFitMode:a,scale:c,onHover:l,onUnhover:A,isHovered:u,isTranslucent:_}):null};function jX(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=N5e(r,e.axisMapping.x)),e.axisMapping.y&&(o=N5e(r,e.axisMapping.y)),e.axisMapping.z&&(i=N5e(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),c=o*s-i*a,l=o*a+i*s;o=c,i=l}if(e.rotation.y){const r=e.rotation.y*Math.PI/180,s=Math.cos(r),a=Math.sin(r),c=n*s+i*a,l=-n*a+i*s;n=c,i=l}if(e.rotation.z){const r=e.rotation.z*Math.PI/180,s=Math.cos(r),a=Math.sin(r),c=n*s-o*a,l=n*a+o*s;n=c,o=l}}return{x:n,y:o,z:i}}function N5e(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 k5e={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 szn(t,e){if(e.coordinateTransform)return e.coordinateTransform;if(!e.usingGlbCoordinates){if(e.hasFootprinterModel)return k5e.FOOTPRINTER_MODEL_TRANSFORM;if(!e.usingObjFormat)return e.usingStepFormat?k5e.STEP_INVERTED:k5e.Z_UP_TO_Y_UP_USB_FIX}}function tH(t,e){return szn(t,{usingGlbCoordinates:e==="gltf"||e==="glb"||e==="jscad",usingObjFormat:e==="obj"||e==="wrl",usingStepFormat:e==="step",hasFootprinterModel:e==="footprinter"})}function XX(t){if(!t)return;const e=jX({x:1,y:0,z:0},t),n=jX({x:0,y:1,z:0},t),o=jX({x:0,y:0,z:1},t);return new ys().makeBasis(new Dt(e.x,e.y,e.z),new Dt(n.x,n.y,n.z),new Dt(o.x,o.y,o.z))}function L4(t){return t*Math.PI/180}function azn(t){if(t==="z+")return[0,0,0];switch(t){case"x+":return[0,L4(-90),0];case"x-":return[0,L4(90),0];case"y+":return[L4(90),0,0];case"y-":return[L4(-90),0,0];case"z-":return[L4(180),0,0];default:return[0,0,0]}}function czn(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 lzn(t,e){return t.rotation?[L4(t.rotation.x),L4(t.rotation.y),L4(t.rotation.z)]:e==="bottom"?[Math.PI,0,0]:[0,0,0]}function Azn(t,e){const n=new Dt(t.x,t.y,t.z),o=new n1(e[0],e[1],e[2],"XYZ");return n.applyEuler(o),[n.x,n.y,n.z]}function uzn(t,e,n){if(!t.model_origin_position)return[0,0,0];const o=e?jX(t.model_origin_position,e):t.model_origin_position;return Azn(o,n)}function _zn(t,e){const n=czn(t,e.layer,e.pcbThickness),o=lzn(t,e.layer),i=tH(t,e.modelType),r=azn(t.model_board_normal_direction??"z+"),s=uzn(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 dzn=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",hzn=t=>t==="step"?"glb":t,mzn=(t,e)=>{if(t)return e?e(t):t},gzn=(...t)=>t,H5e=class extends Qi.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}},pzn=({error:t,onError:e})=>(ne.useEffect(()=>{e(t)},[t,e]),null),Cdt=({cad_component:t,circuitJson:e,resolveStaticAsset:n})=>{const o=S_t(e),[i,r]=ne.useState(!1),{visibility:s}=hB(),[a,c]=ne.useState(null),l=ne.useCallback(K=>{K?.mousePosition?(r(!0),c(K.mousePosition)):(r(!1),c(null))},[]),A=ne.useCallback(()=>{r(!1),c(null)},[]),u=ne.useMemo(()=>Ni(e).source_component.getUsing({source_component_id:t.source_component_id})?.name,[e,t.source_component_id]),_=ne.useMemo(()=>e.filter(X=>X.type==="pcb_plated_hole"&&X.pcb_component_id===t.pcb_component_id).length>0,[e,t.pcb_component_id]),h=ne.useCallback(K=>mzn(K,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),[g,y]=ne.useState(0),[f,x]=ne.useState(null);ne.useEffect(()=>{y(0),x(null)},[t.cad_component_id,d,m,p]);const E=e.find(K=>K.type==="pcb_component"&&K.source_component_id===t.source_component_id)?.layer??"top",b=dzn(t),P=hzn(b),B=t.model_glb_url?"glb":"gltf",w=t.model_wrl_url?"wrl":t.model_stl_url?"stl":"obj",k=ne.useMemo(()=>_zn(t,{layer:E,pcbThickness:o,modelType:P}),[t,E,o,P]),N=gzn(...k.rotation),F=k.position,O=ne.useMemo(()=>{const K=[];return m&&K.push(W.jsx(fdt,{gltfUrl:m,position:F,rotation:N,modelOffset:k.modelPosition,modelRotation:k.modelRotation,sourceCoordinateTransform:XX(tH(t,B)),scale:k.scale,modelSize:k.size,modelFitMode:k.fitMode,onHover:l,onUnhover:A,isHovered:i,isTranslucent:t.show_as_translucent_model},`${t.cad_component_id}-gltf-${m}`)),d&&K.push(W.jsx(XGn,{url:d,position:F,rotation:N,modelOffset:k.modelPosition,modelRotation:k.modelRotation,sourceCoordinateTransform:XX(tH(t,w)),scale:k.scale,modelSize:k.size,modelFitMode:k.fitMode,onHover:l,onUnhover:A,isHovered:i,isTranslucent:t.show_as_translucent_model},`${t.cad_component_id}-mixed-${d}`)),p&&!t.model_jscad&&!t.footprinter_string&&K.push(W.jsx(rzn,{stepUrl:p,position:F,rotation:N,modelOffset:k.modelPosition,modelRotation:k.modelRotation,sourceCoordinateTransform:XX(tH(t,P)),scale:k.scale,modelSize:k.size,modelFitMode:k.fitMode,onHover:l,onUnhover:A,isHovered:i,isTranslucent:t.show_as_translucent_model},`${t.cad_component_id}-step-${p}`)),K},[F,t.cad_component_id,t.footprinter_string,t.model_jscad,t.show_as_translucent_model,m,B,l,A,i,w,k.modelPosition,k.modelRotation,k.scale,k.fitMode,k.size,P,N,p,d]);let G=null;if(O.length>0){if(g>=O.length){if(f)throw f;return null}G=W.jsx(H5e,{fallback:({error:K})=>W.jsx(pzn,{error:K,onError:X=>{x(X),y($=>Math.max($,g+1))}}),children:O[g]},`${t.cad_component_id}-fallback-${g}`)}else t.model_jscad?G=W.jsx(YGn,{jscadPlan:t.model_jscad,positionOffset:F,rotationOffset:N,modelOffset:k.modelPosition,modelRotation:k.modelRotation,sourceCoordinateTransform:XX(tH(t,"jscad")),scale:k.scale,modelSize:k.size,modelFitMode:k.fitMode,onHover:l,onUnhover:A,isHovered:i,isTranslucent:t.show_as_translucent_model},t.cad_component_id):t.footprinter_string&&(G=W.jsx(HGn,{positionOffset:F,rotationOffset:N,footprint:t.footprinter_string,scale:k.scale,onHover:l,onUnhover:A,isHovered:i,isTranslucent:t.show_as_translucent_model}));if(t.show_as_translucent_model){if(!s.translucentModels)return null}else if(_&&!s.throughHoleModels||!_&&!s.smtModels)return null;return W.jsxs(W.Fragment,{children:[G,i&&a?W.jsx(v_t,{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:u??"<unknown>"}):null]})},Idt={version:"0.0.564"};function fzn(t){t.querySelectorAll("canvas").forEach(e=>e.remove())}var yzn=t=>{t.outputColorSpace=YC,t.toneMapping=qve,t.toneMappingExposure=1},Edt="cadViewerCameraStateSession",bdt=(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(Edt,JSON.stringify(n))}catch(n){console.warn("Failed to save camera:",n)}},L5e=(t,e)=>{try{const n=sessionStorage.getItem(Edt);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}},Sdt=ne.createContext(void 0),xzn=({children:t,defaultTarget:e,initialCameraPosition:n,initialCameraType:o})=>{const i=ne.useRef(null),r=ne.useRef(null),[s,a]=ne.useState(null),[c,l]=ne.useState(o??"perspective"),[A,u]=ne.useState(n??null),[_,h]=ne.useState(new n1(0,0,0)),d=ne.useMemo(()=>{const[y,f,x]=n??[5,-5,5],I=Math.hypot(y-e.x,f-e.y,x-e.z);return I>0?I:5},[n,e]),m=ne.useCallback(y=>{const f=[e.x,e.y,e.z],x=r.current,I=i.current;let E=d;switch(x&&I&&(E=x.position.distanceTo(I.target)),y){case"Top Center Angled":{const b=E/Math.sqrt(2);return{position:[e.x,e.y-b,e.z+b],target:f,up:[0,0,1]}}case"Top Down":return{position:[e.x,e.y,e.z+E],target:f,up:[0,0,1]};case"Top Left Corner":return{position:[e.x-E*.6,e.y-E*.6,e.z+E*.6],target:f,up:[0,0,1]};case"Top Right Corner":return{position:[e.x+E*.6,e.y-E*.6,e.z+E*.6],target:f,up:[0,0,1]};case"Left Sideview":return{position:[e.x-E,e.y,e.z],target:f,up:[0,0,1]};case"Right Sideview":return{position:[e.x+E,e.y,e.z],target:f,up:[0,0,1]};case"Front":return{position:[e.x,e.y-E,e.z],target:f,up:[0,0,1]};default:return null}},[d,e,r,i]),p=ne.useCallback(y=>{i.current=y},[]),g=ne.useMemo(()=>({controlsRef:i,mainCameraRef:r,defaultTarget:e,baseDistance:d,controller:s,setController:a,getPresetConfig:m,handleControlsChange:p,cameraType:c,setCameraType:l,cameraPosition:A,setCameraPosition:u,cameraRotation:_,setCameraRotation:h,saveCameraToSession:bdt,loadCameraFromSession:L5e}),[e,d,s,m,p,c,A,_]);return W.jsx(Sdt.Provider,{value:g,children:t})},F4=()=>{const t=ne.useContext(Sdt);if(!t)throw new Error("useCameraController must be used within a CameraControllerProvider");return t},Czn=ne.forwardRef(({children:t,scene:e,camera:n,style:o,onCreated:i},r)=>{const{cameraType:s}=F4(),a=ne.useRef(null),[c,l]=ne.useState(null),A=ne.useRef([]),u=ne.useRef(void 0);u.current=i;const _=ne.useRef(null),h=ne.useCallback(g=>{A.current.push(g)},[]),d=ne.useCallback(g=>{A.current=A.current.filter(y=>y!==g)},[]),m=ne.useMemo(()=>new B6,[]);e?.up&&m.up.set(e.up.x,e.up.y,e.up.z);const p=ne.useRef(new nA);return ne.useImperativeHandle(r,()=>p.current),ne.useEffect(()=>{if(!a.current)return;fzn(a.current);const g=new cG({antialias:!0,alpha:!0});yzn(g),g.setSize(a.current.clientWidth,a.current.clientHeight),g.setPixelRatio(window.devicePixelRatio),a.current.appendChild(g.domElement);const y=a.current.clientWidth/a.current.clientHeight,f=s==="perspective"?new jm(75,y,.1,1e3):new eQ(-10*y,10*y,10,-10,-1e3,1e3);_.current?(f.position.copy(_.current.position),f.quaternion.copy(_.current.quaternion),f.up.copy(_.current.up)):(n?.up&&f.up.set(n.up[0],n.up[1],n.up[2]),n?.position&&f.position.set(n.position[0],n.position[1],n.position[2]),f.lookAt(0,0,0)),m.add(p.current),window.__TSCIRCUIT_THREE_OBJECT=p.current,l({scene:m,camera:f,renderer:g,rootObject:p.current,addFrameListener:h,removeFrameListener:d}),u.current?.({camera:f,renderer:g});let x;const I=new n7t,E=()=>{const P=I.getElapsedTime(),B=I.getDelta();A.current.forEach(w=>w(P,B)),g.render(m,f),x=requestAnimationFrame(E)};E();const b=()=>{if(a.current){const P=a.current.clientWidth/a.current.clientHeight;f instanceof jm?f.aspect=P:f instanceof eQ&&(f.left=-10*P,f.right=10*P,f.top=10,f.bottom=-10),f.updateProjectionMatrix(),g.setSize(a.current.clientWidth,a.current.clientHeight)}};return window.addEventListener("resize",b),()=>{_.current={position:f.position.clone(),quaternion:f.quaternion.clone(),up:f.up.clone()},window.removeEventListener("resize",b),cancelAnimationFrame(x),a.current&&g.domElement&&a.current.removeChild(g.domElement),g.dispose(),m.remove(p.current),window.__TSCIRCUIT_THREE_OBJECT===p.current&&(window.__TSCIRCUIT_THREE_OBJECT=void 0)}},[m,h,d,s]),W.jsx("div",{ref:a,style:{width:"100%",height:"100%",...o},children:c&&W.jsx(P_t.Provider,{value:c,children:W.jsx(NGn,{children:t})})})}),Izn=({autoRotate:t,autoRotateSpeed:e,onStart:n,panSpeed:o,rotateSpeed:i,zoomSpeed:r,enableDamping:s,dampingFactor:a,target:c,onControlsChange:l})=>{const{camera:A,renderer:u}=g1(),_=ne.useMemo(()=>!A||!u?null:new bQt(A,u.domElement),[A,u]);return ne.useEffect(()=>(l?.(_??null),()=>l?.(null)),[_,l]),ne.useEffect(()=>{if(!_)return;const h=()=>{l?.(_)};return _.addEventListener("change",h),()=>{_.removeEventListener("change",h)}},[_,l]),ne.useEffect(()=>{_&&(_.autoRotate=t||!1,_.autoRotateSpeed=e||1,o!==void 0&&(_.panSpeed=o),i!==void 0&&(_.rotateSpeed=i),r!==void 0&&(_.zoomSpeed=r),s!==void 0&&(_.enableDamping=s),a!==void 0&&(_.dampingFactor=a),_.zoomToCursor=!0,_.mouseButtons={LEFT:Vb.ROTATE,MIDDLE:Vb.PAN,RIGHT:null},c&&(_.target.set(c[0],c[1],c[2]),_.update()))},[_,t,e,o,i,r,s,a,c]),ne.useEffect(()=>{if(!(!_||!n))return _.addEventListener("start",n),()=>{_.removeEventListener("start",n)}},[_,n]),ne.useEffect(()=>{if(_)return()=>{_.dispose()}},[_]),Fk(()=>{_?.update()},[_]),null},Ezn=`
|
|
5198
5198
|
varying vec3 worldPosition;
|
|
5199
5199
|
void main() {
|
|
5200
5200
|
worldPosition = (modelMatrix * vec4(position, 1.0)).xyz;
|
|
@@ -5741,7 +5741,7 @@ test("${l} should solve problem correctly", () => {
|
|
|
5741
5741
|
// Add more specific assertions based on expected output
|
|
5742
5742
|
// expect(solver.netLabelPlacementSolver!.netLabelPlacements).toMatchInlineSnapshot()
|
|
5743
5743
|
})
|
|
5744
|
-
`,u=new Blob([A],{type:"text/plain"}),_=URL.createObjectURL(u),h=document.createElement("a");h.href=_,h.download=`${l}.test.ts`,h.click(),URL.revokeObjectURL(_)}catch(c){alert(`Error generating test.ts for ${t.constructor.name}: ${c instanceof Error?c.message:String(c)}`)}o(!1)};return W.jsxs("div",{className:`relative ${e}`,ref:i,children:[W.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>o(!n),title:`Download options for ${t.constructor.name}`,children:t.constructor.name}),n&&W.jsxs("div",{className:"absolute top-full left-0 mt-1 bg-white border border-gray-300 rounded shadow-lg z-10 min-w-[150px]",children:[W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:r,children:"Download JSON"}),W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:a,children:"Download test.ts"})]})]})},JCt=t=>t.activeSubSolver?[t,...JCt(t.activeSubSolver)]:[t],Who=({solver:t})=>{const e=JCt(t);return W.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:e.map((n,o)=>W.jsxs("div",{className:"flex items-center",children:[o>0&&W.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),W.jsx(Kho,{solver:n})]},n.constructor.name))})},jho=({solver:t,triggerRender:e,animationSpeed:n=25,onSolverStarted:o,onSolverCompleted:i})=>{const[r,s]=ne.useReducer(m=>!m,!1),a=ne.useRef(void 0),c=()=>{!t.solved&&!t.failed&&(t.step(),e())},l=()=>{!t.solved&&!t.failed&&(o&&o(t),t.solve(),e(),i&&i(t))},A=()=>{r?(a.current&&(clearInterval(a.current),a.current=void 0),s()):(s(),a.current=setInterval(()=>{if(t.solved||t.failed){a.current&&(clearInterval(a.current),a.current=void 0),s(),e(),i&&t.solved&&i(t);return}t.step(),e()},n))},u=()=>{const m=t;if(m.getCurrentPhase&&!t.solved&&!t.failed){const p=m.getCurrentPhase();for(;m.getCurrentPhase()===p&&!t.solved&&!t.failed;)t.step();e()}},_=()=>{if(t.solved||t.failed||r)return;const m=window.prompt("Step until which iteration?",`${t.iterations}`);if(m===null)return;const p=Number(m);if(!Number.isFinite(p)){window.alert("Please enter a valid number for the iteration");return}for(;t.iterations<p&&!t.solved&&!t.failed;)t.step();e(),t.solved&&i&&i(t)};ne.useEffect(()=>()=>{a.current&&clearInterval(a.current)},[]),ne.useEffect(()=>{(t.solved||t.failed)&&r&&(a.current&&(clearInterval(a.current),a.current=void 0),s())},[t.solved,t.failed,r]);const h=t.getCurrentPhase!==void 0,d=h?t.getCurrentPhase():null;return W.jsxs("div",{className:"space-y-2 p-2 border-b",children:[W.jsx("div",{className:"flex items-center",children:W.jsx(Who,{solver:t})}),W.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[W.jsx("button",{onClick:c,disabled:t.solved||t.failed||r,className:"bg-blue-500 hover:bg-blue-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step"}),W.jsx("button",{onClick:l,disabled:t.solved||t.failed||r,className:"bg-green-500 hover:bg-green-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Solve"}),W.jsx("button",{onClick:A,disabled:t.solved||t.failed,className:`px-3 py-1 rounded text-white text-sm ${r?"bg-red-500 hover:bg-red-600":"bg-yellow-500 hover:bg-yellow-600"} disabled:bg-gray-300`,children:r?"Stop":"Animate"}),W.jsx("button",{onClick:_,disabled:t.solved||t.failed||r,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"}),h&&W.jsx("button",{onClick:u,disabled:t.solved||t.failed||r,className:"bg-purple-500 hover:bg-purple-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Next Stage"}),W.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",t.iterations]}),t.timeToSolve!==void 0&&W.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(t.timeToSolve/1e3).toFixed(3),"s"]}),d&&W.jsxs("div",{className:"text-sm text-gray-600",children:["Phase: ",W.jsx("span",{className:"font-medium",children:d})]}),t.solved&&W.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),t.failed&&W.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),t.error&&W.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",t.error]})]})},Xho=(t,e,n)=>{const o=t.currentPipelineStepIndex;return e<o?"Completed":e===o&&t.activeSubSolver?t.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},Jho=(t,e)=>{const o=t.pipelineDef[e].solverName,i=Xho(t,e),r=t[o],s=t.firstIterationOfPhase?.[o]??null,a=t.iterations;let c=0;if(i==="Completed"){const _=t.pipelineDef[e+1],h=_?t.firstIterationOfPhase?.[_.solverName]:void 0;h!==void 0&&s!==null?c=h-s:s!==null&&(c=a-s)}else i==="In Progress"&&s!==null&&(c=a-s);const l=t.timeSpentOnPhase?.[o]??0;let A=0;i==="Completed"?A=1:i==="In Progress"&&r&&(A=r.progress??0);const u=r?.stats??null;return{index:e,name:o,status:i,firstIteration:s,iterations:c,progress:A,timeSpent:l,stats:u&&Object.keys(u).length>0?u:null,solverInstance:r??null}},qho=({status:t})=>{const e={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return W.jsx("span",{className:`font-medium ${e[t]}`,children:t})},$ho=({progress:t})=>{if(t===0)return null;const e=Math.round(t*100);return W.jsxs("div",{className:"flex items-center gap-2",children:[W.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:W.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${e}%`}})}),W.jsxs("span",{className:"text-xs text-gray-500",children:[e,"%"]})]})},Zho=t=>Object.entries(t).map(([e,n])=>`${e}: ${n}`).join(", "),emo=({stats:t})=>{if(!t||Object.keys(t).length===0)return W.jsx("span",{children:"-"});const e=Object.entries(t),n=Zho(t);return W.jsxs("details",{className:"cursor-pointer",children:[W.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:n}),W.jsx("div",{className:"mt-1 text-xs",children:e.map(([o,i])=>W.jsxs("div",{children:[o,": ",String(i)]},o))})]})},ube=t=>{if(t===null||typeof t!="object")return t;if(Array.isArray(t))return t.map(ube);const e={};for(const[n,o]of Object.entries(t))n.startsWith("_")||(e[n]=ube(o));return e},tmo=(t,e)=>{try{if(typeof t.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${e}`);return}const n=ube(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)}`)}},nmo=({solver:t,onStepUntilPhase:e,onDownloadInput:n})=>{const o=t.pipelineDef.map((a,c)=>Jho(t,c)),i=a=>{e?.(a)},r=a=>{a.solverInstance&&(n?n(a.solverInstance,a.name):tmo(a.solverInstance,a.name))},s=a=>`${(a/1e3).toFixed(2)}s`;return W.jsxs("div",{className:"border-t border-gray-200",children:[W.jsx("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200",children:W.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Steps"})}),W.jsx("div",{className:"overflow-x-auto",children:W.jsxs("table",{className:"w-full text-sm",children:[W.jsx("thead",{children:W.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Step"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),W.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",W.jsx("sub",{children:"0"})]}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),W.jsx("tbody",{children:o.map(a=>W.jsxs("tr",{className:`border-b border-gray-100 ${a.status==="In Progress"?"bg-yellow-50":""}`,children:[W.jsx("td",{className:"px-4 py-2",children:W.jsxs("div",{className:"flex items-center gap-2",children:[W.jsx("span",{className:"text-gray-400 w-6",children:String(a.index+1).padStart(2,"0")}),W.jsx("button",{onClick:()=>i(a.name),disabled:a.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 ${a.name} completes`,children:W.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:W.jsx("path",{fillRule:"evenodd",d:"M4.5 5.653c0-1.426 1.529-2.33 2.779-1.643l11.54 6.348c1.295.712 1.295 2.573 0 3.285L7.28 19.991c-1.25.687-2.779-.217-2.779-1.643V5.653z",clipRule:"evenodd"})})}),W.jsx("span",{className:"font-medium text-gray-900",children:a.name})]})}),W.jsx("td",{className:"px-4 py-2",children:W.jsx(qho,{status:a.status})}),W.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:a.firstIteration!==null?a.firstIteration:""}),W.jsx("td",{className:"px-4 py-2 text-gray-600",children:a.iterations}),W.jsx("td",{className:"px-4 py-2",children:W.jsx($ho,{progress:a.progress})}),W.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(a.timeSpent)}),W.jsx("td",{className:"px-4 py-2 text-gray-500",children:W.jsx(emo,{stats:a.stats})}),W.jsx("td",{className:"px-4 py-2",children:a.solverInstance?W.jsxs("button",{onClick:()=>r(a),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${a.name}`,children:[W.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:W.jsx("path",{fillRule:"evenodd",d:"M12 2.25a.75.75 0 01.75.75v11.69l3.22-3.22a.75.75 0 111.06 1.06l-4.5 4.5a.75.75 0 01-1.06 0l-4.5-4.5a.75.75 0 111.06-1.06l3.22 3.22V3a.75.75 0 01.75-.75zm-9 13.5a.75.75 0 01.75.75v2.25a1.5 1.5 0 001.5 1.5h13.5a1.5 1.5 0 001.5-1.5V16.5a.75.75 0 011.5 0v2.25a3 3 0 01-3 3H5.25a3 3 0 01-3-3V16.5a.75.75 0 01.75-.75z",clipRule:"evenodd"})}),W.jsx("span",{children:"Input"})]}):null})]},a.name))})]})})]})},omo=class extends Qi.Component{constructor(t){super(t),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(t){console.error("InteractiveGraphics render error:",t)}render(){return this.state.hasError?this.props.fallback:this.props.children}};function imo({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,c=Number.NEGATIVE_INFINITY,l=Number.NEGATIVE_INFINITY;const A=(p,g)=>{typeof p=="number"&&(p<s&&(s=p),p>c&&(c=p)),typeof g=="number"&&(g<a&&(a=g),g>l&&(l=g))};for(const p of e)A(p.x,p.y);for(const p of n){const g=p.points??[];for(const y of g)A(y.x,y.y)}for(const p of o){const g=p.x??0,y=p.y??0,f=p.width??0,x=p.height??0;A(g,y),A(g+f,y+x)}for(const p of i){const g=p.x??0,y=p.y??0,f=p.radius??1;A(g-f,y-f),A(g+f,y+f)}for(const p of r)A(p.x,p.y);(!isFinite(s)||!isFinite(a)||!isFinite(c)||!isFinite(l))&&(s=-20,a=-20,c=20,l=20);const u=10,_=s-u,h=a-u,d=Math.max(1,c-s+2*u),m=Math.max(1,l-a+2*u);return W.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${_} ${h} ${d} ${m}`,role:"img","aria-label":"Graphics fallback",children:[o.map((p,g)=>W.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-${g}`)),n.map((p,g)=>W.jsx("polyline",{fill:"none",stroke:p.strokeColor??"black",strokeWidth:p.strokeWidth??1,points:(p.points??[]).map(y=>`${y.x??0},${y.y??0}`).join(" ")},`line-${g}`)),i.map((p,g)=>W.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-${g}`)),e.map((p,g)=>W.jsx("circle",{cx:p.x??0,cy:p.y??0,r:p.radius??1.5,fill:p.color??"black"},`point-${g}`)),r.map((p,g)=>W.jsx("text",{x:p.x??0,y:p.y??0,fontSize:p.fontSize??10,fill:p.color??"black",children:p.text??""},`text-${g}`))]})}var rmo=({solver:t,animationSpeed:e=25,onSolverStarted:n,onSolverCompleted:o})=>{const[i,r]=ne.useReducer(A=>A+1,0),s=ne.useMemo(()=>{try{return t.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(A){return console.error("Visualization error:",A),{points:[],lines:[],rects:[],circles:[]}}},[t,i]),a=ne.useMemo(()=>(s.rects?.length||0)===0&&(s.lines?.length||0)===0&&(s.points?.length||0)===0&&(s.circles?.length||0)===0,[s]);ne.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const A=document.createElement("script");A.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(A)}},[]);const c=t.pipelineDef!==void 0,l=A=>{const u=t;if(!t.solved&&!t.failed){for(;!t.solved&&!t.failed&&u.currentPipelineStepIndex<=u.pipelineDef.findIndex(_=>_.solverName===A);)t.step();r()}};return W.jsxs("div",{children:[W.jsx(jho,{solver:t,triggerRender:r,animationSpeed:e,onSolverStarted:n,onSolverCompleted:o}),a?W.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):W.jsx(omo,{fallback:W.jsx(imo,{graphics:s}),children:W.jsx(Yho,{graphics:s})}),c&&W.jsx(nmo,{solver:t,onStepUntilPhase:l})]})};const smo=()=>{ne.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)},[])},amo=t=>t.toLowerCase().includes("pack")?TXn:t.toLowerCase().includes("rout")?LXn:EXn,cmo=({solverEvents:t=[]})=>{const[e,n]=ne.useState(null);smo();const o=ne.useMemo(()=>{const a=new Map;for(const c of t){const l=`${c.componentName}-${c.solverName}`;a.set(l,c)}return a},[t]),i=ne.useMemo(()=>Array.from(o.keys()),[o]),r=e?o.get(e):null,s=ne.useMemo(()=>{if(!r)return{instance:null,error:null,classFound:!1};const a=jhe[r.solverName];if(!a)return{instance:null,error:`Solver class "${r.solverName}" not found in SOLVERS registry. Available: ${Object.keys(jhe).join(", ")}`,classFound:!1};try{const c=r.solverParams,l=c?.input!==void 0?c.input:c;return{instance:new a(l),error:null,classFound:!0}}catch(c){const l=c instanceof Error?c.message:String(c);return console.error("Failed to reconstruct solver:",c),{instance:null,error:`Failed to instantiate solver: ${l}`,classFound:!0}}},[r]);return t.length===0?W.jsx("div",{className:"rf-p-4",children:W.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:W.jsxs("div",{className:"rf-p-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),W.jsx("p",{className:"rf-text-sm rf-text-gray-600",children:"Solvers will appear here when the circuit runs. Solvers are used for tasks like component packing and autorouting."})]})})}):W.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[W.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[W.jsxs("div",{className:"rf-text-xs rf-font-semibold rf-text-gray-500 rf-px-3 rf-py-2 rf-bg-gray-50 rf-border-b rf-border-gray-200",children:[i.length," ",i.length===1?"Solver":"Solvers"]}),i.map(a=>{const c=o.get(a),l=e===a;return W.jsx("div",{className:`rf-px-3 rf-py-2 rf-cursor-pointer rf-border-b rf-border-gray-100 ${l?"rf-bg-blue-50 rf-border-l-2 rf-border-l-blue-500":"hover:rf-bg-gray-50"}`,onClick:()=>n(a),children:(()=>{const A=amo(c.solverName);return W.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[W.jsx(A,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),W.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[W.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:c.componentName}),W.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:c.solverName})]})]})})()},a)})]}),W.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:r?s.instance?W.jsx(_3,{fallback:W.jsx("div",{className:"rf-p-4",children:W.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),W.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",r.solverName]})]})}),children:W.jsx(rmo,{solver:s.instance})}):W.jsxs("div",{className:"rf-p-4",children:[W.jsxs("div",{className:"rf-mb-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:r.solverName}),W.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",r.componentName]})]}),s.error&&W.jsx("div",{className:`rf-rounded-md rf-border rf-p-4 rf-mb-4 ${s.classFound?"rf-bg-red-50 rf-border-red-200":"rf-bg-yellow-50 rf-border-yellow-200"}`,children:W.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),W.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[W.jsx("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50",children:W.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"})}),W.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:W.jsx("pre",{className:"rf-text-xs rf-font-mono rf-text-gray-600 rf-whitespace-pre-wrap rf-overflow-x-auto",children:JSON.stringify(r.solverParams,null,2)})})]})]}):W.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:W.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},qCt=({errorMessage:t,errorStack:e,circuitJsonErrors:n})=>{ne.useEffect(()=>{if(t){const o=new Error(t);e&&(o.stack=e);try{X9.captureException(o)}catch{}}},[t,e]),ne.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{X9.captureException(i,{error_type:o.type})}catch{}}},[n])},lmo=t=>{ne.useEffect(()=>{try{s6t(t)}catch{}},[t.source,t.component,t.isWebEmbedded,t.activeTab])},$Ct="0.0.2022",Amo={version:$Ct},_be={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1},dbe=new Map,C$=t=>{const e=dbe.get(t);return e?Object.fromEntries(Object.entries(e.stores).map(([n,o])=>[n,o.getState()])):{}},umo=(t,e,n)=>{if(t===void 0)return{type:"untracked",connection:e.connect(n)};const o=dbe.get(n.name);if(o)return{type:"tracked",store:t,...o};const i={connection:e.connect(n),stores:{}};return dbe.set(n.name,i),{type:"tracked",store:t,...i}},ZCt=(t,e={})=>(n,o,i)=>{const{enabled:r,anonymousActionType:s,store:a,...c}=e;let l;try{l=(r??(_be?"production":void 0)!=="production")&&window.__REDUX_DEVTOOLS_EXTENSION__}catch{}if(!l)return(_be?"production":void 0)!=="production"&&r&&console.warn("[zustand devtools middleware] Please install/enable Redux devtools extension"),t(n,o,i);const{connection:A,...u}=umo(a,l,c);let _=!0;i.setState=(m,p,g)=>{const y=n(m,p);if(!_)return y;const f=g===void 0?{type:s||"anonymous"}:typeof g=="string"?{type:g}:g;return a===void 0?(A?.send(f,o()),y):(A?.send({...f,type:`${a}/${f.type}`},{...C$(c.name),[a]:i.getState()}),y)};const h=(...m)=>{const p=_;_=!1,n(...m),_=p},d=t(i.setState,o,i);if(u.type==="untracked"?A?.init(d):(u.stores[u.store]=i,A?.init(Object.fromEntries(Object.entries(u.stores).map(([m,p])=>[m,m===u.store?d:p.getState()])))),i.dispatchFromDevtools&&typeof i.dispatch=="function"){let m=!1;const p=i.dispatch;i.dispatch=(...g)=>{(_be?"production":void 0)!=="production"&&g[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(...g)}}return A.subscribe(m=>{var p;switch(m.type){case"ACTION":if(typeof m.payload!="string"){console.error("[zustand devtools middleware] Unsupported action format");return}return hbe(m.payload,g=>{if(g.type==="__setState"){if(a===void 0){h(g.state);return}Object.keys(g.state).length!==1&&console.error(`
|
|
5744
|
+
`,u=new Blob([A],{type:"text/plain"}),_=URL.createObjectURL(u),h=document.createElement("a");h.href=_,h.download=`${l}.test.ts`,h.click(),URL.revokeObjectURL(_)}catch(c){alert(`Error generating test.ts for ${t.constructor.name}: ${c instanceof Error?c.message:String(c)}`)}o(!1)};return W.jsxs("div",{className:`relative ${e}`,ref:i,children:[W.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>o(!n),title:`Download options for ${t.constructor.name}`,children:t.constructor.name}),n&&W.jsxs("div",{className:"absolute top-full left-0 mt-1 bg-white border border-gray-300 rounded shadow-lg z-10 min-w-[150px]",children:[W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:r,children:"Download JSON"}),W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:a,children:"Download test.ts"})]})]})},JCt=t=>t.activeSubSolver?[t,...JCt(t.activeSubSolver)]:[t],Who=({solver:t})=>{const e=JCt(t);return W.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:e.map((n,o)=>W.jsxs("div",{className:"flex items-center",children:[o>0&&W.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),W.jsx(Kho,{solver:n})]},n.constructor.name))})},jho=({solver:t,triggerRender:e,animationSpeed:n=25,onSolverStarted:o,onSolverCompleted:i})=>{const[r,s]=ne.useReducer(m=>!m,!1),a=ne.useRef(void 0),c=()=>{!t.solved&&!t.failed&&(t.step(),e())},l=()=>{!t.solved&&!t.failed&&(o&&o(t),t.solve(),e(),i&&i(t))},A=()=>{r?(a.current&&(clearInterval(a.current),a.current=void 0),s()):(s(),a.current=setInterval(()=>{if(t.solved||t.failed){a.current&&(clearInterval(a.current),a.current=void 0),s(),e(),i&&t.solved&&i(t);return}t.step(),e()},n))},u=()=>{const m=t;if(m.getCurrentPhase&&!t.solved&&!t.failed){const p=m.getCurrentPhase();for(;m.getCurrentPhase()===p&&!t.solved&&!t.failed;)t.step();e()}},_=()=>{if(t.solved||t.failed||r)return;const m=window.prompt("Step until which iteration?",`${t.iterations}`);if(m===null)return;const p=Number(m);if(!Number.isFinite(p)){window.alert("Please enter a valid number for the iteration");return}for(;t.iterations<p&&!t.solved&&!t.failed;)t.step();e(),t.solved&&i&&i(t)};ne.useEffect(()=>()=>{a.current&&clearInterval(a.current)},[]),ne.useEffect(()=>{(t.solved||t.failed)&&r&&(a.current&&(clearInterval(a.current),a.current=void 0),s())},[t.solved,t.failed,r]);const h=t.getCurrentPhase!==void 0,d=h?t.getCurrentPhase():null;return W.jsxs("div",{className:"space-y-2 p-2 border-b",children:[W.jsx("div",{className:"flex items-center",children:W.jsx(Who,{solver:t})}),W.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[W.jsx("button",{onClick:c,disabled:t.solved||t.failed||r,className:"bg-blue-500 hover:bg-blue-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step"}),W.jsx("button",{onClick:l,disabled:t.solved||t.failed||r,className:"bg-green-500 hover:bg-green-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Solve"}),W.jsx("button",{onClick:A,disabled:t.solved||t.failed,className:`px-3 py-1 rounded text-white text-sm ${r?"bg-red-500 hover:bg-red-600":"bg-yellow-500 hover:bg-yellow-600"} disabled:bg-gray-300`,children:r?"Stop":"Animate"}),W.jsx("button",{onClick:_,disabled:t.solved||t.failed||r,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"}),h&&W.jsx("button",{onClick:u,disabled:t.solved||t.failed||r,className:"bg-purple-500 hover:bg-purple-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Next Stage"}),W.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",t.iterations]}),t.timeToSolve!==void 0&&W.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(t.timeToSolve/1e3).toFixed(3),"s"]}),d&&W.jsxs("div",{className:"text-sm text-gray-600",children:["Phase: ",W.jsx("span",{className:"font-medium",children:d})]}),t.solved&&W.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),t.failed&&W.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),t.error&&W.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",t.error]})]})},Xho=(t,e,n)=>{const o=t.currentPipelineStepIndex;return e<o?"Completed":e===o&&t.activeSubSolver?t.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},Jho=(t,e)=>{const o=t.pipelineDef[e].solverName,i=Xho(t,e),r=t[o],s=t.firstIterationOfPhase?.[o]??null,a=t.iterations;let c=0;if(i==="Completed"){const _=t.pipelineDef[e+1],h=_?t.firstIterationOfPhase?.[_.solverName]:void 0;h!==void 0&&s!==null?c=h-s:s!==null&&(c=a-s)}else i==="In Progress"&&s!==null&&(c=a-s);const l=t.timeSpentOnPhase?.[o]??0;let A=0;i==="Completed"?A=1:i==="In Progress"&&r&&(A=r.progress??0);const u=r?.stats??null;return{index:e,name:o,status:i,firstIteration:s,iterations:c,progress:A,timeSpent:l,stats:u&&Object.keys(u).length>0?u:null,solverInstance:r??null}},qho=({status:t})=>{const e={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return W.jsx("span",{className:`font-medium ${e[t]}`,children:t})},$ho=({progress:t})=>{if(t===0)return null;const e=Math.round(t*100);return W.jsxs("div",{className:"flex items-center gap-2",children:[W.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:W.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${e}%`}})}),W.jsxs("span",{className:"text-xs text-gray-500",children:[e,"%"]})]})},Zho=t=>Object.entries(t).map(([e,n])=>`${e}: ${n}`).join(", "),emo=({stats:t})=>{if(!t||Object.keys(t).length===0)return W.jsx("span",{children:"-"});const e=Object.entries(t),n=Zho(t);return W.jsxs("details",{className:"cursor-pointer",children:[W.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:n}),W.jsx("div",{className:"mt-1 text-xs",children:e.map(([o,i])=>W.jsxs("div",{children:[o,": ",String(i)]},o))})]})},ube=t=>{if(t===null||typeof t!="object")return t;if(Array.isArray(t))return t.map(ube);const e={};for(const[n,o]of Object.entries(t))n.startsWith("_")||(e[n]=ube(o));return e},tmo=(t,e)=>{try{if(typeof t.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${e}`);return}const n=ube(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)}`)}},nmo=({solver:t,onStepUntilPhase:e,onDownloadInput:n})=>{const o=t.pipelineDef.map((a,c)=>Jho(t,c)),i=a=>{e?.(a)},r=a=>{a.solverInstance&&(n?n(a.solverInstance,a.name):tmo(a.solverInstance,a.name))},s=a=>`${(a/1e3).toFixed(2)}s`;return W.jsxs("div",{className:"border-t border-gray-200",children:[W.jsx("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200",children:W.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Steps"})}),W.jsx("div",{className:"overflow-x-auto",children:W.jsxs("table",{className:"w-full text-sm",children:[W.jsx("thead",{children:W.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Step"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),W.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",W.jsx("sub",{children:"0"})]}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),W.jsx("tbody",{children:o.map(a=>W.jsxs("tr",{className:`border-b border-gray-100 ${a.status==="In Progress"?"bg-yellow-50":""}`,children:[W.jsx("td",{className:"px-4 py-2",children:W.jsxs("div",{className:"flex items-center gap-2",children:[W.jsx("span",{className:"text-gray-400 w-6",children:String(a.index+1).padStart(2,"0")}),W.jsx("button",{onClick:()=>i(a.name),disabled:a.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 ${a.name} completes`,children:W.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:W.jsx("path",{fillRule:"evenodd",d:"M4.5 5.653c0-1.426 1.529-2.33 2.779-1.643l11.54 6.348c1.295.712 1.295 2.573 0 3.285L7.28 19.991c-1.25.687-2.779-.217-2.779-1.643V5.653z",clipRule:"evenodd"})})}),W.jsx("span",{className:"font-medium text-gray-900",children:a.name})]})}),W.jsx("td",{className:"px-4 py-2",children:W.jsx(qho,{status:a.status})}),W.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:a.firstIteration!==null?a.firstIteration:""}),W.jsx("td",{className:"px-4 py-2 text-gray-600",children:a.iterations}),W.jsx("td",{className:"px-4 py-2",children:W.jsx($ho,{progress:a.progress})}),W.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(a.timeSpent)}),W.jsx("td",{className:"px-4 py-2 text-gray-500",children:W.jsx(emo,{stats:a.stats})}),W.jsx("td",{className:"px-4 py-2",children:a.solverInstance?W.jsxs("button",{onClick:()=>r(a),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${a.name}`,children:[W.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:W.jsx("path",{fillRule:"evenodd",d:"M12 2.25a.75.75 0 01.75.75v11.69l3.22-3.22a.75.75 0 111.06 1.06l-4.5 4.5a.75.75 0 01-1.06 0l-4.5-4.5a.75.75 0 111.06-1.06l3.22 3.22V3a.75.75 0 01.75-.75zm-9 13.5a.75.75 0 01.75.75v2.25a1.5 1.5 0 001.5 1.5h13.5a1.5 1.5 0 001.5-1.5V16.5a.75.75 0 011.5 0v2.25a3 3 0 01-3 3H5.25a3 3 0 01-3-3V16.5a.75.75 0 01.75-.75z",clipRule:"evenodd"})}),W.jsx("span",{children:"Input"})]}):null})]},a.name))})]})})]})},omo=class extends Qi.Component{constructor(t){super(t),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(t){console.error("InteractiveGraphics render error:",t)}render(){return this.state.hasError?this.props.fallback:this.props.children}};function imo({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,c=Number.NEGATIVE_INFINITY,l=Number.NEGATIVE_INFINITY;const A=(p,g)=>{typeof p=="number"&&(p<s&&(s=p),p>c&&(c=p)),typeof g=="number"&&(g<a&&(a=g),g>l&&(l=g))};for(const p of e)A(p.x,p.y);for(const p of n){const g=p.points??[];for(const y of g)A(y.x,y.y)}for(const p of o){const g=p.x??0,y=p.y??0,f=p.width??0,x=p.height??0;A(g,y),A(g+f,y+x)}for(const p of i){const g=p.x??0,y=p.y??0,f=p.radius??1;A(g-f,y-f),A(g+f,y+f)}for(const p of r)A(p.x,p.y);(!isFinite(s)||!isFinite(a)||!isFinite(c)||!isFinite(l))&&(s=-20,a=-20,c=20,l=20);const u=10,_=s-u,h=a-u,d=Math.max(1,c-s+2*u),m=Math.max(1,l-a+2*u);return W.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${_} ${h} ${d} ${m}`,role:"img","aria-label":"Graphics fallback",children:[o.map((p,g)=>W.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-${g}`)),n.map((p,g)=>W.jsx("polyline",{fill:"none",stroke:p.strokeColor??"black",strokeWidth:p.strokeWidth??1,points:(p.points??[]).map(y=>`${y.x??0},${y.y??0}`).join(" ")},`line-${g}`)),i.map((p,g)=>W.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-${g}`)),e.map((p,g)=>W.jsx("circle",{cx:p.x??0,cy:p.y??0,r:p.radius??1.5,fill:p.color??"black"},`point-${g}`)),r.map((p,g)=>W.jsx("text",{x:p.x??0,y:p.y??0,fontSize:p.fontSize??10,fill:p.color??"black",children:p.text??""},`text-${g}`))]})}var rmo=({solver:t,animationSpeed:e=25,onSolverStarted:n,onSolverCompleted:o})=>{const[i,r]=ne.useReducer(A=>A+1,0),s=ne.useMemo(()=>{try{return t.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(A){return console.error("Visualization error:",A),{points:[],lines:[],rects:[],circles:[]}}},[t,i]),a=ne.useMemo(()=>(s.rects?.length||0)===0&&(s.lines?.length||0)===0&&(s.points?.length||0)===0&&(s.circles?.length||0)===0,[s]);ne.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const A=document.createElement("script");A.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(A)}},[]);const c=t.pipelineDef!==void 0,l=A=>{const u=t;if(!t.solved&&!t.failed){for(;!t.solved&&!t.failed&&u.currentPipelineStepIndex<=u.pipelineDef.findIndex(_=>_.solverName===A);)t.step();r()}};return W.jsxs("div",{children:[W.jsx(jho,{solver:t,triggerRender:r,animationSpeed:e,onSolverStarted:n,onSolverCompleted:o}),a?W.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):W.jsx(omo,{fallback:W.jsx(imo,{graphics:s}),children:W.jsx(Yho,{graphics:s})}),c&&W.jsx(nmo,{solver:t,onStepUntilPhase:l})]})};const smo=()=>{ne.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)},[])},amo=t=>t.toLowerCase().includes("pack")?TXn:t.toLowerCase().includes("rout")?LXn:EXn,cmo=({solverEvents:t=[]})=>{const[e,n]=ne.useState(null);smo();const o=ne.useMemo(()=>{const a=new Map;for(const c of t){const l=`${c.componentName}-${c.solverName}`;a.set(l,c)}return a},[t]),i=ne.useMemo(()=>Array.from(o.keys()),[o]),r=e?o.get(e):null,s=ne.useMemo(()=>{if(!r)return{instance:null,error:null,classFound:!1};const a=jhe[r.solverName];if(!a)return{instance:null,error:`Solver class "${r.solverName}" not found in SOLVERS registry. Available: ${Object.keys(jhe).join(", ")}`,classFound:!1};try{const c=r.solverParams,l=c?.input!==void 0?c.input:c;return{instance:new a(l),error:null,classFound:!0}}catch(c){const l=c instanceof Error?c.message:String(c);return console.error("Failed to reconstruct solver:",c),{instance:null,error:`Failed to instantiate solver: ${l}`,classFound:!0}}},[r]);return t.length===0?W.jsx("div",{className:"rf-p-4",children:W.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:W.jsxs("div",{className:"rf-p-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),W.jsx("p",{className:"rf-text-sm rf-text-gray-600",children:"Solvers will appear here when the circuit runs. Solvers are used for tasks like component packing and autorouting."})]})})}):W.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[W.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[W.jsxs("div",{className:"rf-text-xs rf-font-semibold rf-text-gray-500 rf-px-3 rf-py-2 rf-bg-gray-50 rf-border-b rf-border-gray-200",children:[i.length," ",i.length===1?"Solver":"Solvers"]}),i.map(a=>{const c=o.get(a),l=e===a;return W.jsx("div",{className:`rf-px-3 rf-py-2 rf-cursor-pointer rf-border-b rf-border-gray-100 ${l?"rf-bg-blue-50 rf-border-l-2 rf-border-l-blue-500":"hover:rf-bg-gray-50"}`,onClick:()=>n(a),children:(()=>{const A=amo(c.solverName);return W.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[W.jsx(A,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),W.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[W.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:c.componentName}),W.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:c.solverName})]})]})})()},a)})]}),W.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:r?s.instance?W.jsx(_3,{fallback:W.jsx("div",{className:"rf-p-4",children:W.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),W.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",r.solverName]})]})}),children:W.jsx(rmo,{solver:s.instance})}):W.jsxs("div",{className:"rf-p-4",children:[W.jsxs("div",{className:"rf-mb-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:r.solverName}),W.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",r.componentName]})]}),s.error&&W.jsx("div",{className:`rf-rounded-md rf-border rf-p-4 rf-mb-4 ${s.classFound?"rf-bg-red-50 rf-border-red-200":"rf-bg-yellow-50 rf-border-yellow-200"}`,children:W.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),W.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[W.jsx("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50",children:W.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"})}),W.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:W.jsx("pre",{className:"rf-text-xs rf-font-mono rf-text-gray-600 rf-whitespace-pre-wrap rf-overflow-x-auto",children:JSON.stringify(r.solverParams,null,2)})})]})]}):W.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:W.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},qCt=({errorMessage:t,errorStack:e,circuitJsonErrors:n})=>{ne.useEffect(()=>{if(t){const o=new Error(t);e&&(o.stack=e);try{X9.captureException(o)}catch{}}},[t,e]),ne.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{X9.captureException(i,{error_type:o.type})}catch{}}},[n])},lmo=t=>{ne.useEffect(()=>{try{s6t(t)}catch{}},[t.source,t.component,t.isWebEmbedded,t.activeTab])},$Ct="0.0.2023",Amo={version:$Ct},_be={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1},dbe=new Map,C$=t=>{const e=dbe.get(t);return e?Object.fromEntries(Object.entries(e.stores).map(([n,o])=>[n,o.getState()])):{}},umo=(t,e,n)=>{if(t===void 0)return{type:"untracked",connection:e.connect(n)};const o=dbe.get(n.name);if(o)return{type:"tracked",store:t,...o};const i={connection:e.connect(n),stores:{}};return dbe.set(n.name,i),{type:"tracked",store:t,...i}},ZCt=(t,e={})=>(n,o,i)=>{const{enabled:r,anonymousActionType:s,store:a,...c}=e;let l;try{l=(r??(_be?"production":void 0)!=="production")&&window.__REDUX_DEVTOOLS_EXTENSION__}catch{}if(!l)return(_be?"production":void 0)!=="production"&&r&&console.warn("[zustand devtools middleware] Please install/enable Redux devtools extension"),t(n,o,i);const{connection:A,...u}=umo(a,l,c);let _=!0;i.setState=(m,p,g)=>{const y=n(m,p);if(!_)return y;const f=g===void 0?{type:s||"anonymous"}:typeof g=="string"?{type:g}:g;return a===void 0?(A?.send(f,o()),y):(A?.send({...f,type:`${a}/${f.type}`},{...C$(c.name),[a]:i.getState()}),y)};const h=(...m)=>{const p=_;_=!1,n(...m),_=p},d=t(i.setState,o,i);if(u.type==="untracked"?A?.init(d):(u.stores[u.store]=i,A?.init(Object.fromEntries(Object.entries(u.stores).map(([m,p])=>[m,m===u.store?d:p.getState()])))),i.dispatchFromDevtools&&typeof i.dispatch=="function"){let m=!1;const p=i.dispatch;i.dispatch=(...g)=>{(_be?"production":void 0)!=="production"&&g[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(...g)}}return A.subscribe(m=>{var p;switch(m.type){case"ACTION":if(typeof m.payload!="string"){console.error("[zustand devtools middleware] Unsupported action format");return}return hbe(m.payload,g=>{if(g.type==="__setState"){if(a===void 0){h(g.state);return}Object.keys(g.state).length!==1&&console.error(`
|
|
5745
5745
|
[zustand devtools middleware] Unsupported __setState action format.
|
|
5746
5746
|
When using 'store' option in devtools(), the 'state' should have only one key, which is a value of 'store' that was passed in devtools(),
|
|
5747
5747
|
and value of this only key should be a state object. Example: { "type": "__setState", "state": { "abc123Store": { "foo": "bar" } } }
|