@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.
package/dist/standalone.min.js
CHANGED
|
@@ -5198,7 +5198,7 @@ ${c.join(`
|
|
|
5198
5198
|
${m}polygon: ${d.polygon.vertices}
|
|
5199
5199
|
`:c+=`
|
|
5200
5200
|
`,d.children.length>0&&A.push(d.children)}return c}};e.exports=s}}),aHn=rt({"node_modules/@jscad/modeling/src/operations/booleans/trees/Tree.js"(t,e){var n=oHn(),o=sHn(),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}}),AIe=rt({"node_modules/@jscad/modeling/src/operations/booleans/trees/index.js"(t,e){e.exports={Tree:aHn()}}}),cHn=rt({"node_modules/@jscad/modeling/src/operations/booleans/intersectGeom3Sub.js"(t,e){var n=bs(),o=lIe(),{Tree:i}=AIe(),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}}),oht=rt({"node_modules/@jscad/modeling/src/operations/booleans/intersectGeom3.js"(t,e){var n=ns(),o=aH(),i=cHn(),r=(...s)=>{s=n(s);let a=s.shift();return s.forEach(c=>{a=i(a,c)}),a=o(a),a};e.exports=r}}),lHn=rt({"node_modules/@jscad/modeling/src/operations/booleans/intersectGeom2.js"(t,e){var n=ns(),o=bs(),i=K4(),r=aIe(),s=cIe(),a=oht(),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}}),AHn=rt({"node_modules/@jscad/modeling/src/operations/booleans/intersect.js"(t,e){var n=ns(),o=sH(),i=Ms(),r=bs(),s=lHn(),a=oht(),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}}),uIe=rt({"node_modules/@jscad/modeling/src/operations/hulls/hullPoints3.js"(t,e){var n=Ia(),o=cdt(),i=r=>o(r,{skipTriangulation:!0}).map(c=>{const l=c.map(A=>r[A]);return n.create(l)});e.exports=i}}),iht=rt({"node_modules/@jscad/modeling/src/operations/booleans/unionGeom3Sub.js"(t,e){var n=bs(),o=lIe(),{Tree:i}=AIe(),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}}),_Ie=rt({"node_modules/@jscad/modeling/src/operations/booleans/unionGeom3.js"(t,e){var n=ns(),o=aH(),i=iht(),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}}),rht=rt({"node_modules/@jscad/modeling/src/operations/minkowski/minkowskiSum.js"(t,e){var n=ns(),o=bs(),i=Ia(),r=uIe(),s=_Ie(),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],f=g.vertices;let y=0,x=0,I=0;for(let N=0;N<f.length;N++)y+=f[N][0],x+=f[N][1],I+=f[N][2];y/=f.length,x/=f.length,I/=f.length;const E=i.plane(g),b=E[0],P=E[1],B=E[2],w=.1,k=[y-b*w,x-P*w,I-B*w];for(let N=1;N<f.length-1;N++){const L=f[0],F=f[N],G=f[N+1],W=A(k,L,F,G);m.push(o.create(W))}}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 y=0;y<m.length;y++){const x=m[y];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 f=r(g);return o.create(f)},_=h=>{const d=new Set,m=[],p=o.toPolygons(h);for(let g=0;g<p.length;g++){const f=p[g].vertices;for(let y=0;y<f.length;y++){const x=f[y],I=`${x[0]},${x[1]},${x[2]}`;d.has(I)||(d.add(I),m.push(x))}}return m};e.exports=a}}),uHn=rt({"node_modules/@jscad/modeling/src/operations/booleans/scissionGeom3.js"(t,e){var n=Ji(),o=K4(),i=bs(),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((y,x)=>{y.vertices.forEach(I=>{s(h,n.snap(d,I,A),x)})});const m=u.map(y=>{let x=[];return y.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 y=0;y<g;y++){const x=m[y];if(x.e>0){const I=new Array(_);I[y]=!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 f=[];for(let y=0;y<g;y++)if(m[y].indexes){const x=[];m[y].indexes.forEach((I,E)=>x.push(u[E])),f.push(i.create(x))}return f};e.exports=c}}),_Hn=rt({"node_modules/@jscad/modeling/src/operations/booleans/scission.js"(t,e){var n=ns(),o=bs(),i=uHn(),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}}),dHn=rt({"node_modules/@jscad/modeling/src/operations/booleans/subtractGeom3Sub.js"(t,e){var n=bs(),o=lIe(),{Tree:i}=AIe(),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}}),sht=rt({"node_modules/@jscad/modeling/src/operations/booleans/subtractGeom3.js"(t,e){var n=ns(),o=aH(),i=dHn(),r=(...s)=>{s=n(s);let a=s.shift();return s.forEach(c=>{a=i(a,c)}),a=o(a),a};e.exports=r}}),hHn=rt({"node_modules/@jscad/modeling/src/operations/booleans/subtractGeom2.js"(t,e){var n=ns(),o=bs(),i=K4(),r=aIe(),s=cIe(),a=sht(),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}}),mHn=rt({"node_modules/@jscad/modeling/src/operations/booleans/subtract.js"(t,e){var n=ns(),o=sH(),i=Ms(),r=bs(),s=hHn(),a=sht(),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}}),aht=rt({"node_modules/@jscad/modeling/src/operations/booleans/unionGeom2.js"(t,e){var n=ns(),o=bs(),i=K4(),r=aIe(),s=cIe(),a=_Ie(),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}}),dIe=rt({"node_modules/@jscad/modeling/src/operations/booleans/union.js"(t,e){var n=ns(),o=sH(),i=Ms(),r=bs(),s=aht(),a=_Ie(),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}}),cH=rt({"node_modules/@jscad/modeling/src/operations/booleans/index.js"(t,e){e.exports={intersect:AHn(),minkowski:rht(),scission:_Hn(),subtract:mHn(),union:dIe()}}}),hJ=rt({"node_modules/@jscad/modeling/src/operations/expansions/offsetFromPoints.js"(t,e){var{EPS:n,TAU:o}=La(),i=kdt(),r=nIe(),s=Xs(),a=uJ(),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 f=null,y=[];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),L=[k,N];if(f!=null&&(d||!d&&P!==0)){const F=i(f[0],f[1],L[0],L[1]);F?(y.pop(),L[0]=F):x.push({c:B,s0:f,s1:L})}f=[k,N],!(P===0&&!d)&&(y.push(L[0]),y.push(L[1]))}if(d&&f!=null){const b=y[0],P=y[1],B=i(f[0],f[1],b,P);if(B)y[0]=B,y.pop();else{const w=A[0],k=[b,P];x.push({c:w,s0:f,s1:k})}}if(h==="edge"){const b=new Map;y.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],L=b.get(N);y[L]=k,y[(L+1)%y.length]=void 0}else{const N=w.s1[0],L=b.get(N);y[L]=void 0}}),y=y.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)),L=[];for(let F=1;F<b;F++){const G=N+k*F,W=s.fromAngleRadians(s.create(),G);s.scale(W,W,_),s.add(W,W,B.c),L.push(W)}if(L.length>0){const F=B.s0[1];let G=y.findIndex(W=>s.equals(F,W));G=(G+1)%y.length,y.splice(G,0,...L)}}else{const k=B.s1[0],N=y.findIndex(L=>s.equals(k,L));y.splice(N,1)}})}return y};e.exports=c}}),gHn=rt({"node_modules/@jscad/modeling/src/operations/expansions/expandGeom2.js"(t,e){var n=Ms(),o=hJ(),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}}),pHn=rt({"node_modules/@jscad/modeling/src/operations/expansions/extrudePolygon.js"(t,e){var n=NA(),o=Ji(),i=bs(),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}}),fHn=rt({"node_modules/@jscad/modeling/src/operations/expansions/expandShell.js"(t,e){var{EPS:n,TAU:o}=La(),i=NA(),r=Ji(),s=tht(),a=bs(),c=Ia(),l=jdt(),A=aH(),u=iht(),_=pHn(),h=(g,f,y)=>{const x=f.toString();if(g.has(x))g.get(x)[1].push(y);else{const I=[f,[y]];g.set(x,I)}},d=(g,f,y)=>{const x=f[0].toString(),I=f[1].toString(),E=x<I?`${x},${I}`:`${I},${x}`;if(g.has(E))g.get(E)[1].push(y);else{const b=[f,[y]];g.set(E,b)}},m=(g,f)=>{g.findIndex(x=>x===f)<0&&g.push(f)},p=(g,f)=>{const y={delta:1,segments:12},{delta:x,segments:I}=Object.assign({},y,g);let E=a.create();const b=new Map,P=new Map,B=r.create(),w=r.create();return a.toPolygons(f).forEach((N,L)=>{const F=r.scale(r.create(),c.plane(N),2*x),G=c.transform(i.fromTranslation(i.create(),r.scale(r.create(),F,-.5)),N),W=_(F,G);E=u(E,W);const J=N.vertices;for(let $=0;$<J.length;$++){h(b,J[$],c.plane(N));const oe=($+1)%J.length,Ae=[J[$],J[oe]];d(P,Ae,c.plane(N))}}),P.forEach(N=>{const L=N[0],F=N[1],G=L[0],W=L[1],J=r.subtract(r.create(),W,G);r.normalize(J,J);const $=F[0],oe=r.cross(r.create(),$,J);let Ae=[];for(let ve=0;ve<I;ve++)m(Ae,ve*o/I);for(let ve=0,le=F.length;ve<le;ve++){const Ie=F[ve],pe=r.dot(oe,Ie),ke=r.dot($,Ie);let Ue=Math.atan2(pe,ke);Ue<0&&(Ue+=o),m(Ae,Ue),Ue=Math.atan2(-pe,-ke),Ue<0&&(Ue+=o),m(Ae,Ue)}Ae=Ae.sort(s);const ee=Ae.length;let ie,ae;const re=[],_e=[],xe=[];for(let ve=-1;ve<ee;ve++){const le=Ae[ve<0?ve+ee:ve],Ie=Math.sin(le),pe=Math.cos(le);r.scale(B,$,pe*x),r.scale(w,oe,Ie*x),r.add(B,B,w);const ke=r.add(r.create(),G,B),Ue=r.add(r.create(),W,B);let je=!1;if(ve>=0&&r.distance(ke,ie)<n&&(je=!0),!je){if(ve>=0){re.push(ke),_e.push(Ue);const ye=[ae,Ue,ke,ie],qe=c.create(ye);xe.push(qe)}ie=ke,ae=Ue}}_e.reverse(),xe.push(c.create(re)),xe.push(c.create(_e));const be=a.create(xe);E=u(E,be)}),b.forEach(N=>{const L=N[0],F=N[1],G=F[0];let W=null,J=0;for(let ee=1;ee<F.length;ee++){const ie=F[ee],ae=r.cross(B,G,ie),re=r.length(ae);re>.05&&re>J&&(J=re,W=ie)}W||(W=r.orthogonal(B,G));const $=r.cross(B,G,W);r.normalize($,$);const oe=r.cross(w,$,G),Ae=l({center:[L[0],L[1],L[2]],radius:x,segments:I,axes:[G,$,oe]});E=u(E,Ae)}),A(E)};e.exports=p}}),yHn=rt({"node_modules/@jscad/modeling/src/operations/expansions/expandGeom3.js"(t,e){var n=bs(),o=dIe(),i=fHn(),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}}),xHn=rt({"node_modules/@jscad/modeling/src/operations/expansions/expandPath2.js"(t,e){var n=uJ(),o=Xs(),i=Ms(),r=hA(),s=hJ(),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),f=[],y=[];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),f.push(N),k=B+I*w,N=o.fromAngleRadians(o.create(),k),o.scale(N,N,h),o.add(N,N,P),y.push(N)}}const x=[];return x.push(...m,...f,...p.reverse(),...y),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 f={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(f):c(f,m,d,h)};e.exports=l}}),hIe=rt({"node_modules/@jscad/modeling/src/operations/expansions/expand.js"(t,e){var n=ns(),o=Ms(),i=bs(),r=hA(),s=gHn(),a=yHn(),c=xHn(),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}}),CHn=rt({"node_modules/@jscad/modeling/src/operations/expansions/offsetGeom2.js"(t,e){var n=Ms(),o=q5e(),i=hJ(),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((f,y)=>f+o.arePointsInside(m,o.create(y)),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}}),IHn=rt({"node_modules/@jscad/modeling/src/operations/expansions/offsetPath2.js"(t,e){var n=hA(),o=hJ(),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}}),EHn=rt({"node_modules/@jscad/modeling/src/operations/expansions/offset.js"(t,e){var n=ns(),o=Ms(),i=hA(),r=CHn(),s=IHn(),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}}),cht=rt({"node_modules/@jscad/modeling/src/operations/expansions/index.js"(t,e){e.exports={expand:hIe(),offset:EHn()}}}),mJ=rt({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeLinearGeom2.js"(t,e){var n=NA(),o=Ji(),i=Ms(),r=VD(),s=dJ(),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 f=n.create(),y=(x,I,E)=>{const b=I/h*_,P=o.scale(o.create(),m,I/h);return n.multiply(f,n.fromZRotation(f,b),n.fromTranslation(n.create(),P)),r.transform(f,E)};return c={numberOfSlices:h+1,capStart:!0,capEnd:!0,repair:d,callback:y},s(c,g)};e.exports=a}}),bHn=rt({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeLinearPath2.js"(t,e){var n=Ms(),o=hA(),i=mJ(),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}}),SHn=rt({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeLinear.js"(t,e){var n=ns(),o=Ms(),i=hA(),r=mJ(),s=bHn(),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}}),PHn=rt({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeRectangularPath2.js"(t,e){var n=hA(),o=hIe(),i=mJ(),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}}),vHn=rt({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeRectangularGeom2.js"(t,e){var{area:n}=nH(),o=Ms(),i=hA(),r=hIe(),s=mJ(),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,f)=>g.concat(o.toSides(f)),[]),p=o.create(m);return s(c,p)};e.exports=a}}),BHn=rt({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeRectangular.js"(t,e){var n=ns(),o=Ms(),i=hA(),r=PHn(),s=vHn(),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}}),MHn=rt({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeHelical.js"(t,e){var{TAU:n}=La(),o=NA(),i=Ms(),r=dJ(),s=VD(),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 f=i.toSides(l);if(f.length===0)throw new Error("The given geometry cannot be empty");const y=f.filter(w=>w[0][0]>=0);let x=s.fromSides(f);y.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 L=_+u/E*k,F=m/E*k,G=(L-_)/n*h;return o.multiply(b,o.fromTranslation(o.create(),[F,0,G*Math.sign(u)]),o.fromXRotation(o.create(),-n/4*Math.sign(u))),o.multiply(P,o.fromZRotation(o.create(),L),b),s.transform(P,N)};return r({numberOfSlices:E+1,callback:B},x)};e.exports=a}}),wHn=rt({"node_modules/@jscad/modeling/src/operations/extrusions/project.js"(t,e){var n=ns(),o=tIe(),i=d3(),r=NA(),s=Ms(),a=bs(),c=Ia(),l=K4(),A=aht(),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 f=a.toPolygons(d);let y=[];for(let I=0;I<f.length;I++){const E=f[I].vertices.map(B=>i.projectionOfPoint(m,B)),b=c.create(E),P=c.plane(b);o(m,P)&&(c.measureArea(b)<g||y.push(b))}if(!o(m,[0,0,1])){const I=r.fromVectorRotation(r.create(),m,[0,0,1]);y=y.map(E=>c.transform(I,E))}y=y.sort((I,E)=>c.measureArea(E)-c.measureArea(I));const x=y.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 f=d.map(y=>a.isA(y)?u(h,y):y);return f.length===1?f[0]:f};e.exports=_}}),lH=rt({"node_modules/@jscad/modeling/src/operations/extrusions/index.js"(t,e){e.exports={extrudeFromSlices:dJ(),extrudeLinear:SHn(),extrudeRectangular:BHn(),extrudeRotate:$dt(),extrudeHelical:MHn(),project:wHn(),slice:VD()}}}),mIe=rt({"node_modules/@jscad/modeling/src/operations/hulls/hullPoints2.js"(t,e){var n=Xs(),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}}),gIe=rt({"node_modules/@jscad/modeling/src/operations/hulls/toUniquePoints.js"(t,e){var n=Ms(),o=bs(),i=hA(),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}}),DHn=rt({"node_modules/@jscad/modeling/src/operations/hulls/hullPath2.js"(t,e){var n=ns(),o=hA(),i=mIe(),r=gIe(),s=(...a)=>{a=n(a);const c=r(a),l=i(c);return o.fromPoints({closed:!0},l)};e.exports=s}}),THn=rt({"node_modules/@jscad/modeling/src/operations/hulls/hullGeom2.js"(t,e){var n=ns(),o=Ms(),i=mIe(),r=gIe(),s=(...a)=>{a=n(a);const c=r(a),l=i(c);return l.length<3?o.create():o.fromPoints(l)};e.exports=s}}),QHn=rt({"node_modules/@jscad/modeling/src/operations/hulls/hullGeom3.js"(t,e){var n=ns(),o=bs(),i=gIe(),r=uIe(),s=(...a)=>{a=n(a);const c=i(a);return c.length===0?o.create():o.create(r(c))};e.exports=s}}),lht=rt({"node_modules/@jscad/modeling/src/operations/hulls/hull.js"(t,e){var n=ns(),o=sH(),i=Ms(),r=bs(),s=hA(),a=DHn(),c=THn(),l=QHn(),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}}),RHn=rt({"node_modules/@jscad/modeling/src/operations/hulls/hullChain.js"(t,e){var n=ns(),o=dIe(),i=lht(),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}}),NHn=rt({"node_modules/@jscad/modeling/src/operations/hulls/index.js"(t,e){e.exports={hull:lht(),hullChain:RHn(),hullPoints2:mIe(),hullPoints3:uIe()}}}),kHn=rt({"node_modules/@jscad/modeling/src/operations/minkowski/index.js"(t,e){e.exports={minkowskiSum:rht()}}}),Aht=rt({"node_modules/@jscad/modeling/src/operations/modifiers/snapPolygons.js"(t,e){var n=Ji(),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}}),HHn=rt({"node_modules/@jscad/modeling/src/operations/modifiers/mergePolygons.js"(t,e){var n=tIe(),o=Ji(),i=Ia(),r=g=>{const f=i.toPoints(g),y=[];for(let x=0;x<f.length;x++){const I=(x+1)%f.length,E={v1:f[x],v2:f[I]};y.push(E)}for(let x=0;x<y.length;x++){const I=(x+1)%f.length;y[x].next=y[I],y[I].prev=y[x]}return y},s=(g,f)=>{const y=`${f.v1}:${f.v2}`;g.set(y,f)},a=(g,f)=>{const y=`${f.v1}:${f.v2}`;g.delete(y)},c=(g,f)=>{const y=`${f.v2}:${f.v1}`;return g.get(y)},l=(g,f,y)=>{let x=g.prev.v1,I=g.prev.v2,E=f.next.v2;const b=_(x,I,E,y);x=f.prev.v1,I=f.prev.v2,E=g.next.v2;const P=_(x,I,E,y);return[b,P]},A=o.create(),u=o.create(),_=(g,f,y,x)=>{const I=o.subtract(A,f,g),E=o.subtract(u,y,f);return o.cross(I,I,E),o.dot(I,x)},h=g=>{let f;const y=[];for(;g.next;){const x=g.next;y.push(g.v1),g.v1=null,g.v2=null,g.next=null,g.prev=null,g=x}return y.length>0&&(f=i.create(y)),f},d=g=>{if(g.length<2)return g;const f=g[0].plane,y=g.slice(),x=new Map;for(;y.length>0;){const E=y.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,f);if(k[0]>=0&&k[1]>=0){const N=w.next,L=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 F=(G,W,J)=>{const $={v1:J.v1,v2:W.v2,next:W.next,prev:J.prev};J.prev.next=$,W.next.prev=$,a(G,W),W.v1=null,W.v2=null,W.next=null,W.prev=null,a(G,J),J.v1=null,J.v2=null,J.next=null,J.prev=null};k[0]===0&&F(x,N,N.prev),k[1]===0&&F(x,L,L.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,f)=>Math.abs(g[3]-f[3])<15e-8?n(g,f):!1,p=(g,f)=>{const y=[];f.forEach(I=>{const E=y.find(b=>m(b[0],i.plane(I)));E?E[1].push(I):y.push([i.plane(I),[I]])});let x=[];return y.forEach(I=>{const E=I[1],b=d(E);x=x.concat(b)}),x};e.exports=p}}),LHn=rt({"node_modules/@jscad/modeling/src/operations/modifiers/insertTjunctions.js"(t,e){var n=La(),o=Ji(),i=Ia(),r=l=>`${l}`,s=(l,A,u,_,h,d)=>{const m=r(_),p=r(h),g=`${m}/${p}`,f=`${p}/${m}`;if(l.has(f))return a(l,A,u,h,_,null),null;const y={vertex0:_,vertex1:h,polygonindex:d};return l.has(g)?l.get(g).push(y):l.set(g,[y]),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 f=-1;const y=l.get(g);for(let x=0;x<y.length;x++){const I=y[x];let E=r(I.vertex0);if(E===m&&(E=r(I.vertex1),E===p&&!(d!==null&&I.polygonindex!==d))){f=x;break}}y.splice(f,1),y.length===0&&l.delete(g),f=A.get(m).indexOf(g),A.get(m).splice(f,1),A.get(m).length===0&&A.delete(m),f=u.get(p).indexOf(g),u.get(p).splice(f,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 f=_.vertices[g],y=r(f),x=`${m}/${y}`,I=`${y}/${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:f,polygonindex:u};A.has(x)?A.get(x).push(E):A.set(x,[E])}d=f,m=y}}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 f=r(g.vertex0),y=r(g.vertex1);u.has(f)?u.get(f).push(m):u.set(f,[m]),_.has(y)?_.get(y).push(m):_.set(y,[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 f=!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],L=A.get(N)[0],F=I===0?L.vertex0:L.vertex1;if(I===0?L.vertex1:L.vertex0,r(F)===B){a(A,u,_,E,b,null),a(A,u,_,b,E,null),f=!1,I=2,m=!0;break}else{const W=E,J=b,$=F,oe=o.subtract(o.create(),$,W),Ae=o.dot(o.subtract(o.create(),J,W),oe)/o.dot(oe,oe);if(Ae>0&&Ae<1){const ee=o.scale(o.create(),oe,Ae);if(o.add(ee,ee,W),o.squaredDistance(ee,J)<n.EPS*n.EPS){const ae=L.polygonindex,re=d[ae],_e=r(L.vertex1);let xe=-1;for(let pe=0;pe<re.vertices.length;pe++)if(r(re.vertices[pe])===_e){xe=pe;break}const be=re.vertices.slice(0);be.splice(xe,0,b);const ve=i.create(be);d[ae]=ve,a(A,u,_,L.vertex0,L.vertex1,ae);const le=s(A,u,_,L.vertex0,b,ae),Ie=s(A,u,_,b,L.vertex1,ae);le!==null&&h.set(le,!0),Ie!==null&&h.set(Ie,!0),f=!1,I=2,m=!0;break}}}}}}f&&h.delete(g)}if(!m)break}l=d}return A.clear(),l};e.exports=c}}),FHn=rt({"node_modules/@jscad/modeling/src/operations/modifiers/triangulatePolygons.js"(t,e){var n=Ji(),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}}),OHn=rt({"node_modules/@jscad/modeling/src/operations/modifiers/generalize.js"(t,e){var n=ns(),o=K4(),i=Ms(),r=bs(),s=hA(),a=Aht(),c=HHn(),l=LHn(),A=FHn(),u=(m,p)=>p,_=(m,p)=>p,h=(m,p)=>{const g={snap:!1,simplify:!1,triangulate:!1},{snap:f,simplify:y,triangulate:x}=Object.assign({},g,m),I=o(p);let E=r.toPolygons(p);f&&(E=a(I,E)),y&&(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(f=>{if(s.isA(f))return u(m,f);if(i.isA(f))return _(m,f);if(r.isA(f))return h(m,f);throw new Error("invalid geometry")});return g.length===1?g[0]:g};e.exports=d}}),GHn=rt({"node_modules/@jscad/modeling/src/operations/modifiers/snap.js"(t,e){var n=ns(),o=Xs(),i=Ms(),r=bs(),s=hA(),a=K4(),c=Aht(),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=_}}),zHn=rt({"node_modules/@jscad/modeling/src/operations/modifiers/index.js"(t,e){e.exports={generalize:OHn(),snap:GHn(),retessellate:aH()}}}),UHn=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}}),VHn=rt({"node_modules/@jscad/modeling/src/operations/transforms/align.js"(t,e){var n=ns(),o=UHn(),i=oIe(),{translate:r}=CB(),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}}),gJ=rt({"node_modules/@jscad/modeling/src/operations/transforms/center.js"(t,e){var n=ns(),o=Ms(),i=bs(),r=hA(),s=yB(),{translate:a}=CB(),c=(h,d)=>{const m={axes:[!0,!0,!0],relativeTo:[0,0,0]},{axes:p,relativeTo:g}=Object.assign({},m,h),f=s(d),y=[0,0,0];return p[0]&&(y[0]=g[0]-(f[0][0]+(f[1][0]-f[0][0])/2)),p[1]&&(y[1]=g[1]-(f[0][1]+(f[1][1]-f[0][1])/2)),p[2]&&(y[2]=g[2]-(f[0][2]+(f[1][2]-f[0][2])/2)),a(y,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 f=d.map(y=>r.isA(y)||o.isA(y)||i.isA(y)?c(h,y):y);return f.length===1?f[0]:f},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:_}}}),pJ=rt({"node_modules/@jscad/modeling/src/operations/transforms/scale.js"(t,e){var n=ns(),o=NA(),i=Ms(),r=bs(),s=hA(),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}}}),YHn=rt({"node_modules/@jscad/modeling/src/operations/transforms/transform.js"(t,e){var n=ns(),o=Ms(),i=bs(),r=hA(),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}}),EB=rt({"node_modules/@jscad/modeling/src/operations/transforms/index.js"(t,e){e.exports={align:VHn(),center:gJ().center,centerX:gJ().centerX,centerY:gJ().centerY,centerZ:gJ().centerZ,mirror:iH().mirror,mirrorX:iH().mirrorX,mirrorY:iH().mirrorY,mirrorZ:iH().mirrorZ,rotate:rH().rotate,rotateX:rH().rotateX,rotateY:rH().rotateY,rotateZ:rH().rotateZ,scale:pJ().scale,scaleX:pJ().scaleX,scaleY:pJ().scaleY,scaleZ:pJ().scaleZ,transform:YHn(),translate:CB().translate,translateX:CB().translateX,translateY:CB().translateY,translateZ:CB().translateZ}}}),fJ=rt({"node_modules/@jscad/modeling/src/index.js"(t,e){e.exports={colors:AJ(),curves:FNn(),geometries:$5e(),maths:Akn(),measurements:fkn(),primitives:IB(),text:Jkn(),utils:nht(),booleans:cH(),expansions:cht(),extrusions:lH(),hulls:NHn(),minkowski:kHn(),modifiers:zHn(),transforms:EB()}}}),uht=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)}`)}}}}),KHn=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":"")}}}),WHn=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=KHn(),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 f(...y){if(!f.enabled)return;const x=f,I=Number(new Date),E=I-(d||I);x.diff=E,x.prev=d,x.curr=I,d=I,y[0]=r.coerce(y[0]),typeof y[0]!="string"&&y.unshift("%O");let b=0;y[0]=y[0].replace(/%([a-zA-Z%])/g,(B,w)=>{if(B==="%%")return"%";b++;const k=r.formatters[w];if(typeof k=="function"){const N=y[b];B=k.call(x,N),y.splice(b,1),b--}return B}),r.formatArgs.call(x,y),(x.log||r.log).apply(x,y)}return f.namespace=h,f.useColors=r.useColors(),f.color=r.selectColor(h),f.extend=s,f.destroy=r.destroy,Object.defineProperty(f,"enabled",{enumerable:!0,configurable:!1,get:()=>m!==null?m:(p!==r.namespaces&&(p=r.namespaces,g=r.enabled(h)),g),set:y=>{m=y}}),typeof r.init=="function"&&r.init(f),f}function s(h,d){const m=r(this.namespace+(typeof d>"u"?":":d)+h);return m.log=this.log,m}function a(h){r.save(h),r.namespaces=h,r.names=[],r.skips=[];const d=(typeof h=="string"?h:"").trim().replace(/\s+/g,",").split(",").filter(Boolean);for(const m of d)m[0]==="-"?r.skips.push(m.slice(1)):r.names.push(m)}function c(h,d){let m=0,p=0,g=-1,f=0;for(;m<h.length;)if(p<d.length&&(d[p]===h[m]||d[p]==="*"))d[p]==="*"?(g=p,f=m,p++):(m++,p++);else if(g!==-1)p=g+1,f++,m=f;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}}),jHn=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 z5e<"u"&&"env"in z5e&&(c=z5e.env.DEBUG),c}function s(){try{return localStorage}catch{}}e.exports=WHn()(t);var{formatters:a}=e.exports;a.j=function(c){try{return JSON.stringify(c)}catch(l){return"[UnexpectedJSONParseError]: "+l.message}}}}),_ht={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},dht=j.createContext(void 0),XHn=({children:t})=>{const[e,n]=j.useState(_ht),o=j.useCallback((s,a)=>{n(c=>({...c,[s]:a}))},[]),i=j.useCallback(()=>{n(_ht)},[]),r=j.useMemo(()=>({visibility:e,setLayerVisibility:o,resetToDefaults:i}),[e,o,i]);return K.jsx(dht.Provider,{value:r,children:t})},bB=()=>{const t=j.useContext(dht);if(!t)throw new Error("useLayerVisibility must be used within a LayerVisibilityProvider");return t},pIe=1.2;function hht(t){return j.useMemo(()=>{if(!t)return pIe;try{return Ni(t).pcb_board.list()[0]?.thickness??pIe}catch{return pIe}},[t])}var mht=j.createContext(null),C1=()=>{const t=j.useContext(mht);if(!t)throw new Error("useThree must be used within a ThreeProvider");return t},AH=(t,e=[])=>{const{addFrameListener:n,removeFrameListener:o}=C1();Ri.useEffect(()=>(n(t),()=>o(t)),[n,o,...e])},uH={clickToInteractOverlay:100,htmlElements:95,orientationCube:95,contextMenu:90,appearanceMenu:91},ght=({children:t,position:e,style:n})=>{const{camera:o,renderer:i}=C1(),r=j.useRef(document.createElement("div")),[s,a]=j.useState(null);return j.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(DW.createPortal(t,r.current)),()=>{c.contains(r.current)&&c.removeChild(r.current)}},[i,t]),AH(()=>{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=uH.htmlElements.toString(),n&&Object.assign(r.current.style,n)},[o,i,e,n]),s},pht={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 pht)return n*pht[e];throw new Error(`Unsupported unit: ${e}`)},C_=Ma,JHn=Object.defineProperty,qHn=(t,e)=>{for(var n in e)JHn(t,n,{get:e[n],enumerable:!0})},rb={};qHn(rb,{axial:()=>vFn,bga:()=>wLn,breakoutheaders:()=>OFn,cap:()=>rLn,dfn:()=>cFn,diode:()=>iLn,dip:()=>eLn,electrolytic:()=>Rzn,hc49:()=>UFn,jst:()=>qGn,led:()=>sLn,lqfp:()=>LFn,m2host:()=>oUn,melf:()=>rGn,micromelf:()=>lGn,minimelf:()=>qOn,mlp:()=>FLn,mountedpcbmodule:()=>rUn,ms012:()=>mFn,ms013:()=>pFn,msop:()=>azn,pad:()=>VFn,pinrow:()=>AFn,platedhole:()=>Wzn,potentiometer:()=>Dzn,pushbutton:()=>TFn,qfn:()=>kLn,qfp:()=>LLn,quad:()=>KD,radial:()=>wFn,res:()=>vLn,sma:()=>dGn,smb:()=>CGn,smbf:()=>kzn,smc:()=>SGn,smf:()=>pGn,smtpad:()=>Yzn,sod110:()=>ZGn,sod123:()=>EFn,sod123f:()=>POn,sod123fl:()=>wOn,sod123w:()=>sOn,sod128:()=>LOn,sod323:()=>AOn,sod323f:()=>IOn,sod323fl:()=>dzn,sod323w:()=>lzn,sod523:()=>JFn,sod723:()=>ROn,sod80:()=>nOn,sod882:()=>fOn,sod882d:()=>tGn,sod923:()=>hOn,soic:()=>TLn,solderjumper:()=>Izn,son:()=>pzn,sop8:()=>eOn,sot:()=>Xzn,sot223:()=>MGn,sot23:()=>tFn,sot23w:()=>LGn,sot25:()=>rFn,sot323:()=>Gzn,sot343:()=>Zzn,sot363:()=>jLn,sot457:()=>Szn,sot563:()=>dFn,sot723:()=>yFn,sot886:()=>qLn,sot89:()=>KOn,sot963:()=>Bzn,ssop:()=>zLn,stampboard:()=>RFn,stampreceiver:()=>HFn,to220:()=>Nht,to220f:()=>XOn,to92:()=>jFn,to92l:()=>lUn,to92s:()=>VGn,tqfp:()=>HLn,tssop:()=>YLn,vson:()=>yzn,vssop:()=>izn});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")}),os=(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()]}),EC=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}},yJ=Array.from({length:9},(t,e)=>Math.cos(e/8*Math.PI-Math.PI)).map(t=>({x:t,y:-Math.sqrt(1-t**2)})),I1=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 W4(t){return typeof t=="string"?t.trim().toLowerCase().endsWith("mil")?parseFloat(t)*.0254:parseFloat(t):Number(t)}var xJ=ho([X(),ut()]).transform(t=>W4(t)),$Hn=t=>ti.extend({fn:X(),num_pins:ut().optional().default(6),wide:Je().optional(),narrow:Je().optional(),w:xJ.optional(),p:xJ.default(t.p??"2.54mm"),id:xJ.optional(),od:xJ.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=W4("0.55mm"),e.od=W4("0.95mm")):(e.id=W4("0.8mm"),e.od=W4("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=W4("600mil"):e.narrow?e.w=W4("300mil"):e.w=W4(t.w??"300mil")),e)),ZHn=$Hn({}),fht=(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}},eLn=t=>{const e=ZHn.parse(t),n=[];for(let g=0;g<e.num_pins;g++){const{x:f,y}=fht(e.num_pins,g+1,e.w,e.p??2.54,e.nosquareplating);if(g===0&&!e.nosquareplating){n.push(EC({pn:g+1,x:f,y,holeDiameter:e.id??"0.8mm",rectPadWidth:e.od??"1mm",rectPadHeight:e.od??"1mm"}));continue}n.push(os(g+1,f,y,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},...yJ.map(({x:g,y:f})=>({x:g*r/6,y:f*r/6+s/2})),{x:r/2,y:s/2},{x:r/2,y:-s/2},{x:-r/2,y:-s/2}],type:"pcb_silkscreen_path",stroke_width:.1},c=[];for(let g=0;g<e.num_pins;g++){const f=g<e.num_pins/2,y=.6,{y:x}=fht(e.num_pins,g+1,e.w,e.p??2.54,e.nosquareplating),I=f?-e.w/2-e.od/2-y:e.w/2+e.od/2+y,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:I1([{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()]}),yht=[{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}],tLn=Object.fromEntries(yht.map(t=>[t.metric,t])),nLn=Object.fromEntries(yht.map(t=>[t.imperial,t])),oLn=(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:de.optional(),pw:de.optional(),ph:de.optional(),metric:nt.optional(),imperial:nt.optional(),w:de.optional(),h:de.optional(),textbottom:Je().optional()});var CJ=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=C_(a)),typeof c=="string"&&(c=C_(c)),typeof n=="string"&&(n=C_(n)),typeof o=="string"&&(o=C_(o)),typeof i=="string"&&(i=C_(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=tLn[r]),s&&(A=nLn[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?oLn(A.courtyard_width_mm,A.courtyard_height_mm):null;return e?[os(1,-n/2,0,o,o*1/.8),os(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]:[]]},iLn=t=>({circuitJson:CJ(t),parameters:t}),rLn=t=>({circuitJson:CJ(t),parameters:t}),sLn=t=>({circuitJson:CJ(t),parameters:t}),YD=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,f=Math.max(...c),y=.2,x=g-n/2-.1,I=f+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-y,y:I},{x,y:I+y},{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]:[]]},aLn=ti.extend({pw:de.default("0.5mm"),ph:de.default("0.4mm"),p:de.default("0.7mm"),textbottom:Je().optional(),convex:Je().optional(),concave:Je().optional()}),cLn=1,lLn=t=>{const e=aLn.parse(t);if(e.concave===!0)return[];const n=C_(e.pw),o=C_(e.ph),i=C_(e.p);return YD({padSpacing:cLn,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}]})},ALn=ti.extend({pw:de.default("0.5mm"),ph:de.default("0.32mm"),p:de.default("0.5mm"),textbottom:Je().optional(),convex:Je().optional(),concave:Je().optional()}),uLn=1,_Ln=t=>{const e=ALn.parse(t),n=C_(e.pw),o=C_(e.ph),i=C_(e.p);return YD({padSpacing:uLn,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}]})},dLn=ti.extend({pw:de.default("0.9mm"),ph:de.default("0.4mm"),p:de.default("0.8mm"),textbottom:Je().optional(),convex:Je().optional(),concave:Je().optional()}),hLn=1.7,mLn=t=>{const e=dLn.parse(t),n=C_(e.pw),o=C_(e.ph),i=C_(e.p);return YD({padSpacing:hLn,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}]})},gLn=ti.extend({pw:de.default("0.9mm"),ph:de.default("0.4mm"),p:de.default("0.8mm"),textbottom:Je().optional(),convex:Je().optional(),concave:Je().optional()}),pLn=1.7,fLn=t=>{const e=gLn.parse(t),n=C_(e.pw),o=C_(e.ph),i=C_(e.p);return YD({padSpacing:pLn,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}]})},yLn=ti.extend({pw:de.default("0.7mm"),ph:de.default("0.64mm"),p:de.default("0.94mm"),textbottom:Je().optional(),convex:Je().optional(),concave:Je().optional()}),xLn=1.4,CLn=t=>{const e=yLn.parse(t),n=C_(e.pw),o=C_(e.ph),i=C_(e.p);return YD({padSpacing:xLn,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}]})},ILn=ti.extend({pw:de.default("0.9mm"),ph:de.default("0.9mm"),p:de.default("1.34mm"),textbottom:Je().optional(),convex:Je().optional(),concave:Je().optional()}),ELn=3,bLn=t=>{const e=ILn.parse(t),n=C_(e.pw),o=C_(e.ph),i=C_(e.p);return YD({padSpacing:ELn,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}]})},SLn=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)}},PLn=t=>t?(typeof t=="number"?`${t}`:t).split(/[_x]/)[0]:void 0,vLn=t=>{const e=SLn(t),n=PLn(t.imperial);return e===2&&n==="0402"?{circuitJson:lLn(t),parameters:t}:e===4&&n==="0402"?{circuitJson:_Ln(t),parameters:t}:e===2&&n==="0603"?{circuitJson:mLn(t),parameters:t}:e===4&&n==="0603"?{circuitJson:fLn(t),parameters:t}:e===2&&n==="0606"?{circuitJson:CLn(t),parameters:t}:e===4&&n==="1206"?{circuitJson:bLn(t),parameters:t}:{circuitJson:CJ(t),parameters:t}},xht=(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()]}),Cht="ABCDEFGHIJKLMNOPQRSTUVWXYZ",IJ=X().transform(t=>{const[e,n]=t.split(/[x ]/);return{x:parseFloat(e??""),y:parseFloat(n??"")}}).pipe(bt({x:ut(),y:ut()})),BLn=X().or($t(Zu())).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(X().or(ut()))),MLn=ti.extend({fn:X(),num_pins:ut().optional().default(64),grid:IJ.optional(),p:nt.default("0.8mm"),w:de.optional(),h:de.optional(),ball:de.optional().describe("ball diameter"),pad:de.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:BLn.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=Cht.indexOf(i[1]),s=Number.parseInt(i[2])-1;return r*t.grid.x+s+1})),{...t,origin:e}}),wLn=t=>{const e=MLn.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 ee=Ae;ee<Ae+$;ee++)for(let ie=oe;ie<oe+$;ie++)u.push(ee*o.x+ie+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,ee=($-(o.y-1)/2)*i;let ie=oe,ae=$;switch(e.origin){case"bl":ie=oe,ae=o.y-1-$;break;case"br":ie=o.x-1-oe,ae=o.y-1-$;break;case"tr":ie=o.x-1-oe,ae=$;break}let re=ae*o.x+ie+1;if(h.has(re)){d++;continue}re-=d;const _e=[re,`${Cht[ae]}${ie+1}`];A.push(e.circularpads?xht(_e,{x:Ae,y:ee,radius:c/2}):Bo(_e,Ae,ee,c,c))}const m=ai(0,o.y*i/2,.2),p=i/6;let g;const f=o.x*i/2,y=o.y*i/2;switch(e.origin){case"bl":g=[{x:-f,y:-y},{x:-f,y:-y-p},{x:-f-p,y:-y},{x:-f,y:-y}];break;case"br":g=[{x:f,y:-y},{x:f,y:-y-p},{x:f+p,y:-y},{x:f,y:-y}];break;case"tr":g=[{x:f,y},{x:f,y:y+p},{x:f+p,y},{x:f,y}];break;default:g=[{x:-f,y},{x:-f,y:y+p},{x:-f-p,y},{x:-f,y}];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,L=B+k,F=L,G=w+N,W=G,J={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",outline:I1([{minX:-L,maxX:L,minY:-W,maxY:W},{minX:-F,maxX:F,minY:-G,maxY:G}]),layer:"top"};return{circuitJson:[...A,m,x,J],parameters:e}},EJ=(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()]}),SB=t=>ti.extend({fn:X(),num_pins:ut().optional().default(8),w:de.default(de.parse(t.w??"5.3mm")),p:de.default(de.parse(t.p??"1.27mm")),pw:de.default(de.parse(t.pw??"0.6mm")),pl:de.default(de.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=de.parse("0.6mm"),e.pl=de.parse("1.0mm")):e.pw?e.pl||(e.pl=e.pw*(1/.6)):e.pw=e.pl*(.6/1),e)),DLn=SB({}),fIe=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}},TLn=t=>{const e=DLn.parse(t);return{circuitJson:_H(e),parameters:e}},_H=t=>{const e=[];let n=0,o=0;for(let p=0;p<t.num_pins;p++){const{x:g,y:f}=fIe({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(f)+t.pw/2),t.pillpads?e.push(EJ(p+1,g,f,t.pl,t.pw)):e.push(Bo(p+1,g,f,t.pl,t.pw))}const i=Math.min(1,t.p/2),r=t.w-(t.legsoutside?0:t.pl*2)-.2,s=(t.num_pins/2-1)*t.p+t.pw+i,a=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},...yJ.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:I1([{minX:-u,maxX:u,minY:-_,maxY:_},{minX:-h,maxX:h,minY:-d,maxY:d}])};return[...e,c,a,m]},Iht=Nn(["leftside","topside","rightside","bottomside","toppin","bottompin","leftpin","rightpin"]),QLn=({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},yIe=ti.extend({fn:X(),cc:Je().default(!0).optional(),ccw:Je().default(!0).optional(),startingpin:X().or($t(Iht)).transform(t=>typeof t=="string"?t.slice(1,-1).split(","):t).pipe($t(Iht)).optional(),num_pins:ut().optional().default(64),w:de.optional(),h:de.optional(),p:de.default(de.parse("0.5mm")),pw:de.optional(),pl:de.optional(),thermalpad:ho([tt(!0),IJ]).optional(),legsoutside:Je().default(!1)}),xIe=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},Eht=yIe.transform(xIe),RLn=["left","bottom","right","top"],NLn=t=>{const{pin_count:e,pn:n,w:o,h:i,p:r,pl:s,legsoutside:a}=t,c=e/4,l=RLn[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")}},KD=t=>{const e=Eht.parse(t),n=[];let o=0,i=0;const r=QLn(e),s=e.num_pins/4;for(let y=0;y<e.num_pins;y++){const{x,y:I,o:E}=NLn({pin_count:e.num_pins,pn:y+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[y+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 y=e.p*(s-1)+e.pw,x=e.p*(s-1)+e.pw;o=Math.max(o,y/2),i=Math.max(i,x/2),n.push(Bo(["thermalpad"],0,0,y,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[y,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&&y==="top-left"?P="in1":r[s*4]===1&&y==="top-left"||r[s*3+1]===1&&y==="top-right"?P="in2":r[s*3]===1&&y==="top-right"||r[s]===1&&y==="bottom-left"?P="in1":r[s+1]===1&&y==="bottom-left"?P="in2":r[s*2]===1&&y==="bottom-right"?P="in1":r[s*2+1]===1&&y==="bottom-right"&&(P="in2");const N=P==="in1"?1:-1;if(e.legsoutside){const L=P==="in1"?e.pl/2:e.pw/2,F=P==="in1"?e.pw/2:e.pl/2;B+=L*x*N,w-=F*I*N}(P==="none"||e.legsoutside)&&a.push({layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:`pcb_silkscreen_path_${y}`,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_${y}_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_${y}_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_${y}_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=y=>Math.ceil(y/.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)),f={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",layer:"top",outline:I1([{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,f],parameters:e}};yIe.extend({}).transform(xIe);var kLn=t=>(t.legsoutside=!1,t.pl||(t.pl=.875),t.pw||(t.pw=.25),KD(t)),HLn=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 KD(t)},LLn=t=>{t.legsoutside=!0;const e=Eht.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 KD(t)};yIe.extend({}).transform(xIe);var FLn=t=>(t.legsoutside=!1,t.thermalpad===void 0&&(t.thermalpad=!0),KD(t)),OLn=ti.extend({fn:X(),num_pins:ut().optional().default(8),w:de.default(de.parse("3.9mm")),p:de.default(de.parse("1.27mm")),pw:de.optional(),pl:de.optional(),legsoutside:Je().optional().default(!1),silkscreen_stroke_width:ut().optional().default(.1)}).transform(t=>(t.pw==null&&t.pl==null?(t.pw=de.parse("0.51mm"),t.pl=de.parse("1.1mm")):t.pw==null?t.pw=t.pl*(.51/1.1):t.pl==null&&(t.pl=t.pw*(1.1/.51)),t)),GLn=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+de.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}},zLn=t=>{const e=OLn.parse(t),n=[];for(let p=0;p<e.num_pins;p++){const{x:g,y:f}=GLn({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,f,e.pl,e.pw))}const o=Math.min(1,e.p/2),i=e.w-(e.legsoutside?0:e.pl)-.2,r=(e.num_pins/2-1)*e.p+e.pw+o,s=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},...yJ.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:I1([{minX:-u,maxX:u,minY:-d,maxY:d},{minX:-_,maxX:_,minY:-h,maxY:h}]),layer:"top"};return{circuitJson:[...n,a,s,m],parameters:e}},ULn=ti.extend({fn:X(),num_pins:ut().optional().default(8),w:de.default(de.parse("3.0mm")),p:de.default(de.parse("0.5mm")),pw:de.default(de.parse("0.30mm")),pl:de.default(de.parse("1.45mm")),legsoutside:Je().optional().default(!0),silkscreen_stroke_width:ut().optional().default(.1)}),VLn=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}},YLn=t=>{const e={...t},n=e.p,o=typeof n=="string"||typeof n=="number"?de.parse(n):void 0,i=o!=null&&o<=de.parse("0.5mm"),r=ULn.parse(e),s=[],a=i?r.w-de.parse("0.15mm"):r.w;for(let x=0;x<r.num_pins;x++){const{x:I,y:E}=VLn({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},...yJ.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,f=g+.35,y={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",layer:"top",outline:I1([{minX:-p,maxX:p,minY:-g,maxY:g},{minX:-m,maxX:m,minY:-f,maxY:f}])};return{circuitJson:[...s,_,u,y],parameters:r}},KLn=[{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}],WLn=ti.extend({fn:X(),num_pins:tt(6).default(6),w:X().default("3.1mm"),h:X().default("2.0mm"),p:X().default("0.65mm"),pl:X().default("1.03mm"),pw:X().default("0.35mm"),string:X().optional()}),jLn=t=>{const e=WLn.parse({...t,fn:"sot363"}),n=de.parse(e.w),o=de.parse(e.h),i=de.parse(e.p),r=de.parse(e.pl),s=de.parse(e.pw),a=[];for(let d=0;d<6;d++){const{x:m,y:p}=bht(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=bht(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:KLn,layer:"top"};return{circuitJson:[...a,c,l,_,u,h],parameters:e}},bht=(t,e,n,o)=>t<=3?{x:-.84,y:n-(t-1)*n}:{x:.84,y:-n+(t-4)*n},XLn=[{x:-.75,y:1},{x:-.75,y:-1},{x:.75,y:-1},{x:.75,y:1}],JLn=ti.extend({fn:X(),num_pins:tt(6).default(6),w:X().default("1.01mm"),h:X().default("1.45mm"),p:X().default("0.5mm"),pl:X().default("0.33mm"),pw:X().default("0.27mm"),string:X().optional()}),qLn=t=>{const e=JLn.parse({...t,fn:"sot886"}),n=de.parse(e.w),o=de.parse(e.h),i=de.parse(e.p),r=de.parse(e.pl),s=de.parse(e.pw),a=[];for(let d=0;d<6;d++){const{x:m,y:p}=Sht(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=Sht(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:XLn,layer:"top"};return{circuitJson:[...a,c,l,_,u,h],parameters:e}},Sht=(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}},$Ln=[{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}],ZLn=[{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}],Pht=ti.extend({fn:X(),num_pins:ut().default(3),w:X().default("1.92mm"),h:X().default("2.74mm"),pl:X().default("1.325mm"),pw:X().default("0.6mm"),p:X().default("0.95mm"),string:X().optional()}),eFn=SB({p:"0.95mm",w:"1.6mm",legsoutside:!0}),tFn=t=>{const e=t.string?.match(/^sot23_(\d+)/),n=e?Number.parseInt(e[1],10):3;if(n===6||n===8){const i=eFn.parse({...t,num_pins:n});return{circuitJson:_H(i),parameters:i}}const o=Pht.parse({...t,num_pins:n});if(o.num_pins===3)return{circuitJson:oFn(o),parameters:o};if(o.num_pins===5)return{circuitJson:Bht(o),parameters:o};throw new Error("Invalid number of pins")},nFn=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}},oFn=t=>{const e=[];for(let i=0;i<t.num_pins;i++){const{x:r,y:s}=nFn({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:$Ln,layer:"top"};return[...e,n,o]},vht=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")},Bht=t=>{const e=[];for(let _=1;_<=t.num_pins;_++){const{x:h,y:d}=vht({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=vht({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:ZLn,layer:"top"};return[...e,s,i,r,A,u]},iFn=Pht.extend({}),rFn=t=>{const e=iFn.parse({...t,num_pins:5});return{circuitJson:Bht(e),parameters:e}},sFn=[{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}],aFn=SB({}),cFn=t=>{const e=aFn.parse(t),n=[];for(let p=0;p<e.num_pins;p++){const{x:g,y:f}=fIe({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,f,e.pl??"1mm",e.pw??"0.6mm"))}const o=Math.min(1,e.p/2),i=e.w+o,r=(e.num_pins/2-1)*e.p+e.pw+o,s=[];for(const p of sFn){const{dx:g,dy:f}=p;s.push({layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"",route:[{x:g*i/2-g*e.p,y:f*r/2},{x:g*i/2,y:f*r/2},{x:g*i/2,y:f*r/2-f*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}},PB=({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 Mht({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 lFn=ti.extend({fn:X(),num_pins:ut().optional().default(6),rows:ho([X(),ut()]).transform(t=>Number(t)).optional().default(1).describe("number of rows"),p:de.default("0.1in").describe("pitch"),id:de.default("1.0mm").describe("inner diameter"),od:de.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:de.optional().default("1.0mm").describe("pad width for SMD"),pl:de.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=Mht(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"]})}),AFn=t=>{const e=lFn.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),f=(r-1)*n,y=f/2,x=-n,I=({xoff:Ae,yoff:ee,od:ie,anchorSide:ae,smd:re,pw:_e,pl:xe})=>{let be=0,ve=0;if(re){const le=ie/5;switch(ae){case"right":be=_e/2+le;break;case"top":ve=xe/2+le;break;case"bottom":ve=-(xe/2+le);break;case"left":be=-(_e/2+le);break}}else{const le=ie*.75;switch(ae){case"right":be=le;break;case"top":ve=le;break;case"bottom":ve=-le;break;case"left":be=-le;break}}return{anchor_x:Ae+be,anchor_y:ee+ve}},E=(Ae,ee,ie)=>{e.smd?p.push(Bo(Ae,ee,ie,e.pw,e.pl)):Ae===1&&!e.nosquareplating?p.push(EC({pn:Ae,x:ee,y:ie,holeDiameter:o,rectPadWidth:i,rectPadHeight:i})):p.push(os(Ae,ee,ie,o,i));const{anchor_x:ae,anchor_y:re}=I({xoff:ee,yoff:ie,od:i,anchorSide:a,smd:e.smd,pw:e.pw,pl:e.pl});_||(d?p.push(PB({fs:i/5,pn:Ae,anchor_x:ae,anchor_y:re,textalign:m,orthogonal:l,verticallyinverted:c,layer:"bottom"})):p.push(PB({fs:i/5,pn:Ae,anchor_x:ae,anchor_y:re,textalign:m,orthogonal:l,verticallyinverted:c,layer:"top"})),h&&p.push(PB({fs:i/5,pn:Ae,anchor_x:ae,anchor_y:re,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 ee=0;ee<s;ee++){const ie=ee+1,ae=Ae+ee*n,re=`${ae},0`;if(b.has(re))throw new Error(`Overlap at ${re}`);b.add(re),E(ie,ae,0)}}else if(P){const Ae=-((g-1)/2)*n;let ee=1;for(let ie=0;ie<r&&ee<=s;ie++)for(let ae=0;ae<g&&ee<=s;ae++){const re=Ae+ae*n,_e=y+ie*x,xe=`${re},${_e}`;if(b.has(xe))throw new Error(`Overlap at ${xe}`);b.add(xe),E(ee++,re,_e)}}else{const Ae=-((g-1)/2)*n;let ee=1,ie=0,ae=r-1,re=0,_e=g-1;for(;ee<=s&&ie<=ae&&re<=_e;){for(let xe=ie;xe<=ae&&ee<=s;xe++){const be=Ae+re*n,ve=y+xe*x,le=`${be},${ve}`;if(b.has(le))throw new Error(`Overlap at ${le}`);b.add(le),E(ee++,be,ve)}re++;for(let xe=re;xe<=_e&&ee<=s;xe++){const be=Ae+xe*n,ve=y+ae*x,le=`${be},${ve}`;if(b.has(le))throw new Error(`Overlap at ${le}`);b.add(le),E(ee++,be,ve)}if(ae--,re<=_e){for(let xe=ae;xe>=ie&&ee<=s;xe--){const be=Ae+_e*n,ve=y+xe*x,le=`${be},${ve}`;if(b.has(le))throw new Error(`Overlap at ${le}`);b.add(le),E(ee++,be,ve)}_e--}if(ie<=ae){for(let xe=_e;xe>=re&&ee<=s;xe--){const be=Ae+xe*n,ve=y+ie*x,le=`${be},${ve}`;if(b.has(le))throw new Error(`Overlap at ${le}`);b.add(le),E(ee++,be,ve)}ie++}}if(ee-1<s)throw new Error(`Missing pins: assigned ${ee-1}, expected ${s}`)}const B=ai(0,f/2+n,.5),w=e.smd?e.pw/2:i/2,k=e.smd?e.pl/2:i/2,N=(g-1)*n,L=N/2+w,F=f/2+k,G=N/2+n/2,W=f/2+n/2,J=Math.max(L+.25,G+.5),$=Math.max(F+.25,W+.5),oe={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:0,y:0},width:2*J,height:2*$,layer:"top"};return{circuitJson:[...p,B,oe],parameters:e}},uFn=[{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}],_Fn=ti.extend({fn:X(),num_pins:tt(6).default(6),w:X().default("2.1mm"),h:X().default("2.45mm"),p:X().default("0.5mm"),pl:X().default("0.675mm"),pw:X().default("0.35mm"),string:X().optional()}),dFn=t=>{const e=_Fn.parse({...t,fn:"sot563"}),n=de.parse(e.w),o=de.parse(e.h),i=de.parse(e.p),r=de.parse(e.pl),s=de.parse(e.pw),a=[];for(let d=0;d<6;d++){const{x:m,y:p}=wht(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=wht(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:uFn,layer:"top"};return{circuitJson:[...a,c,l,_,u,h],parameters:e}},wht=(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}},hFn=SB({p:"1.27mm",w:"3.9mm",legsoutside:!0}),mFn=t=>{const e=hFn.parse({...t,num_pins:8});return{circuitJson:_H(e),parameters:e}},gFn=SB({p:"1.27mm",w:"7.5mm",legsoutside:!0}),pFn=t=>{const e=gFn.parse({...t,num_pins:16});return{circuitJson:_H(e),parameters:e}},fFn=ti.extend({fn:X(),num_pins:tt(3).default(3),w:X().default("1.2mm"),h:X().default("1.2mm"),pw:X().default("0.40mm"),pl:X().default("0.45mm"),p:X().default("0.575mm")}),yFn=t=>{const e=fFn.parse(t),n=CFn(e),o=ai(0,de.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}},xFn=t=>{const{pn:e,p:n}=t;return e===1?{x:n,y:0}:e===2?{x:-n,y:-.4}:{x:-n,y:.4}},CFn=t=>{const e=[];for(let n=0;n<3;n++){const{x:o,y:i}=xFn({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},IFn=ti.extend({fn:X(),num_pins:tt(2).default(2),w:X().default("2.36mm"),h:X().default("1.22mm"),pl:X().default("0.9mm"),pw:X().default("1.2mm"),p:X().default("3.30mm")}),EFn=t=>{const e=IFn.parse(t),n=ai(0,de.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:SFn(e).concat(n,r),parameters:e}},bFn=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},SFn=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=bFn({pn:n,p:Number.parseFloat(t.p)});e.push(Bo(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return e},PFn=ti.extend({fn:X(),p:de.optional().default("2.54mm"),id:de.optional().default("0.7mm"),od:de.optional().default("1.4mm")}),vFn=t=>{const e=PFn.parse(t),{p:n,id:o,od:i}=e,r=[os(1,-n/2,0,o,i),os(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,f={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",outline:I1([{minX:_,maxX:h,minY:-g,maxY:g},{minX:m,maxX:p,minY:-d,maxY:d}]),layer:"top"};return{circuitJson:[...r,s,a,f],parameters:e}},BFn=(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}},MFn=ti.extend({fn:X(),p:de.optional().default("5mm"),id:de.optional().default("0.8mm"),od:de.optional().default("1.6mm"),ceramic:Je().optional(),electrolytic:Je().optional(),polarized:Je().optional()}),wFn=t=>{const e=MFn.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=[os(1,-n/2,0,e.id,e.od),os(2,n/2,0,e.id,e.od)],s=n+.1,{topArc:a,bottomArc:c}=BFn(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:""},f=ai(0,s+.12*n,.1*n),y=[...r,A,u,_,f];(e.electrolytic===!0||e.polarized===!0)&&y.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 y.push(E),{circuitJson:y,parameters:e}},vB=(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}),DFn=ti.extend({fn:tt("pushbutton"),w:de.default(4.5),h:de.default(6.5),id:de.default(1),od:de.default(1.2)}),TFn=t=>{const e=DFn.parse(t),n=e.w,o=e.h,i=e.id,r=[os(1,-n/2,o/2,i,i*1.5),os(2,-n/2,-o/2,i,i*1.5),os(3,n/2,-o/2,i,i*1.5),os(4,n/2,o/2,i,i*1.5)],s=[vB([{x:-n/2,y:-o/2},{x:-n/2,y:o/2}]),vB([{x:n/2,y:-o/2},{x:n/2,y:o/2}]),vB([{x:-n/2,y:0},{x:-n/5,y:0},{x:n/5*1/Math.sqrt(2),y:o/8}]),vB([{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}},Dht=ti.extend({fn:X(),w:de.default("22.58mm"),h:de.optional(),left:de.optional().default(20),right:de.optional().default(20),top:de.optional().default(2),bottom:de.optional().default(2),p:de.default(de.parse("2.54mm")),pw:de.default(de.parse("1.6mm")),pl:de.default(de.parse("2.4mm")),innerhole:Je().default(!1),innerholeedgedistance:de.default(de.parse("1.61mm")),silkscreenlabels:Je().default(!1),silkscreenlabelmargin:de.default(de.parse("0.1mm"))}),QFn=t=>{const e=Dht.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},bJ=(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},RFn=t=>{const e=Dht.parse(t),n=e.h??QFn(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=bJ(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),f=`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:f,font_size:.7,font:"tscircuit2024",anchor_alignment:"center"})}e.innerhole&&(i.push(os(p+1+e.left+(e.bottom??0)+l,e.w/2,m+p*e.p,a,c)),i.push(os(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=bJ(-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,f=`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:f,font_size:.7,font:"tscircuit2024",anchor_alignment:"center"})}e.innerhole&&(i.push(os(p+1+l,-e.w/2,m-p*e.p,a,c)),i.push(os(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=bJ(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),f=`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:f,font_size:.7,font:"tscircuit2024",anchor_alignment:"center",ccw_rotation:270})}e.innerhole&&(i.push(os(p+1+e.left+e.right+(e.bottom??0)+l,m-p*e.p,n/2,a,c)),i.push(os(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=bJ(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,f=`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:f,font_size:.7,font:"tscircuit2024",anchor_alignment:"center",ccw_rotation:90})}e.innerhole&&(i.push(os(p+1+e.left+l,m+p*e.p,-n/2,a,c)),i.push(os(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}},Tht=ti.extend({fn:X(),w:de.default("22.58mm"),h:de.optional(),left:de.optional().default(20),right:de.optional().default(20),top:de.optional().default(2),bottom:de.optional().default(2),p:de.default(de.parse("2.54mm")),pw:de.default(de.parse("1.6mm")),pl:de.default(de.parse("3.2mm")),innerhole:Je().default(!1),innerholeedgedistance:de.default(de.parse("1.61mm"))}),NFn=t=>{const e=Tht.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},kFn=(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]},HFn=t=>{const e=Tht.parse(t),n=e.h??NFn(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=kFn(-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(os(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(os(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(os(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(os(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}},LFn=t=>(t.legsoutside=!0,t.pl||(t.pl=1.5),t.pw||(t.pw=.3),KD(t)),Qht=ti.extend({fn:X(),w:de.default("10mm"),h:de.optional(),left:de.optional().default(20),right:de.optional().default(20),top:de.optional().default(0),bottom:de.optional().default(0),p:de.default(de.parse("2.54mm")),id:de.optional().default(de.parse("1mm")),od:de.optional().default(de.parse("1.5mm"))}),FFn=t=>{const e=Qht.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},SJ=(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]},OFn=t=>{const e=Qht.parse(t),n=e.h??FFn(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=SJ(e.w/2+r*1.4,A+u*e.p,"right")),o.push(os(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=SJ(-e.w/2-r*1.4,A+u*e.p,"left")),o.push(os(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=SJ(A+u*e.p,n/2+r*1.4,"top")),o.push(os(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=SJ(A+u*e.p,-n/2-r*1.4,"bottom")),o.push(os(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}},GFn=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)]},Rht=(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}}),zFn=ti.extend({fn:X(),p:de.optional().default("4.88mm"),id:de.optional().default("0.8mm"),od:de.optional().default("1.5mm"),w:de.optional().default("5.6mm"),h:de.optional().default("3.5mm")}),UFn=t=>{const e=zFn.parse(t),{p:n,id:o,od:i,w:r,h:s}=e,a=s/2,c=[os(1,-n/2,0,o,i),os(2,n/2,0,o,i)],l=Rht(-r/2,0,a,"left"),A=Rht(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:GFn({centerX:0,centerY:0,straightHalfLength:d,radius:m,arcSegmentCount:9}),layer:"top"};return{circuitJson:[...c,u,_,p],parameters:e}};ti.extend({w:de,h:de});var VFn=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}},BB=(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}),YFn=[{x:-2.73,y:3.71},{x:-2.73,y:-1.03},{x:2.73,y:-1.03},{x:2.73,y:3.71}],KFn=ti.extend({fn:X(),num_pins:ho([tt(3),tt(2)]).default(3),p:X().default("1.27mm"),id:X().default("0.72mm"),od:X().default("0.95mm"),w:X().default("4.5mm"),h:X().default("4.5mm"),inline:Je().default(!1),string:X().optional()}),WFn=(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}}),jFn=t=>{const e=t.string?.match(/^to92_(\d+)/),n=e?Number.parseInt(e[1],10):3,o=KFn.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=[EC({pn:1,x:-u,y:A-u,holeDiameter:_,rectPadWidth:h,rectPadHeight:m}),BB(2,0,A-u,_,d,m),BB(3,u,A-u,_,d,m)]:p=[EC({pn:1,x:-u,y:A-u,holeDiameter:_,rectPadWidth:h,rectPadHeight:h}),os(2,0,A,_,h),os(3,u,A-u,_,h)];else if(o.num_pins===2)p=[EC({pn:1,x:-u,y:A-u,holeDiameter:_,rectPadWidth:d,rectPadHeight:m}),BB(2,u,A-u,_,d,m)];else throw new Error("Invalid number of pins for TO-92");const g=Number.parseFloat(a)/2,f=WFn(0,A,g),y={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[...f,{x:-g,y:0},{x:g,y:0},f[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:YFn,layer:"top"};return{circuitJson:[...p,y,x,I],parameters:o}},XFn=ti.extend({fn:X(),num_pins:tt(2).default(2),w:X().default("2.15mm"),h:X().default("0.7mm"),pl:X().default("0.6mm"),pw:X().default("0.7mm"),p:X().default("1.4mm")}),JFn=t=>{const e=XFn.parse(t),n=ai(0,de.parse(e.h),.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:de.parse(e.p)/2,y:de.parse(e.h)/2+.2},{x:-de.parse(e.w)/2-.2,y:de.parse(e.h)/2+.2},{x:-de.parse(e.w)/2-.2,y:-de.parse(e.h)/2-.2},{x:de.parse(e.p)/2,y:-de.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:$Fn(e).concat(o,n,s),parameters:e}},qFn=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},$Fn=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=qFn({pn:n,p:Number.parseFloat(t.p)});e.push(Bo(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return e},ZFn=SB({w:"7.05mm",p:"1.27mm",pw:"0.65mm",pl:"1.975mm"}),eOn=t=>{const e=ZFn.parse(t),n=[];for(let _=0;_<e.num_pins;_++){const{x:h,y:d}=fIe({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:I1([{minX:-c,maxX:c,minY:-l,maxY:l},{minX:-a,maxX:a,minY:-A,maxY:A}])};return{circuitJson:[...n,i,r,u],parameters:e}},tOn=ti.extend({fn:X(),num_pins:tt(2).default(2),w:X().default("5.0mm"),h:X().default("2.30mm"),pl:X().default("1.25mm"),pw:X().default("2mm"),p:X().default("3.75mm")}),nOn=t=>{const e=tOn.parse(t),n=ai(0,de.parse(e.h)/2+1,.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:de.parse(e.p)/2+.5,y:de.parse(e.h)/2+.5},{x:-de.parse(e.w)/2-.5,y:de.parse(e.h)/2+.5},{x:-de.parse(e.w)/2-.5,y:-de.parse(e.h)/2-.5},{x:de.parse(e.p)/2+.5,y:-de.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:iOn(e).concat(o,n,s),parameters:e}},oOn=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},iOn=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=oOn({pn:n,p:Number.parseFloat(t.p)});e.push(Bo(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return e},rOn=ti.extend({fn:X(),num_pins:tt(2).default(2),w:X().default("4.4mm"),h:X().default("1.7mm"),pl:X().default("1.2mm"),pw:X().default("1.2mm"),p:X().default("2.8mm")}),sOn=t=>{const e=rOn.parse(t),n=ai(0,de.parse(e.h)-.5,.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:de.parse(e.p)/2,y:de.parse(e.h)/2},{x:-de.parse(e.w)/2-.2,y:de.parse(e.h)/2},{x:-de.parse(e.w)/2-.2,y:-de.parse(e.h)/2},{x:de.parse(e.p)/2,y:-de.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:cOn(e).concat(o,n,s),parameters:e}},aOn=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},cOn=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=aOn({pn:n,p:Number.parseFloat(t.p)});e.push(Bo(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return e},lOn=ti.extend({fn:X(),num_pins:tt(2).default(2),w:X().default("3.30mm"),h:X().default("1.80mm"),pl:X().default("0.60mm"),pw:X().default("0.45mm"),p:X().default("2.1mm")}),AOn=t=>{const e=lOn.parse(t),n=ai(0,de.parse(e.h)-.5,.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:de.parse(e.p)/2,y:de.parse(e.h)/2},{x:-de.parse(e.w)/2,y:de.parse(e.h)/2},{x:-de.parse(e.w)/2,y:-de.parse(e.h)/2},{x:de.parse(e.p)/2,y:-de.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:_On(e).concat(o,n,s),parameters:e}},uOn=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},_On=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=uOn({pn:n,p:Number.parseFloat(t.p)});e.push(Bo(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return e},dOn=ti.extend({fn:X(),num_pins:tt(2).default(2),w:X().default("1.4mm"),h:X().default("0.9mm"),pl:X().default("0.36mm"),pw:X().default("0.25mm"),p:X().default("0.85mm")}),hOn=t=>{const e=dOn.parse(t),n=de.parse(e.w),o=de.parse(e.h),i=de.parse(e.pl),r=de.parse(e.pw),s=de.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),f=Math.min(_,d),y=m+.05,x=g-.055,I=p,E=f+.155,b={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",outline:I1([{minX:-y,maxX:y,minY:-E,maxY:E},{minX:-x,maxX:x,minY:-I,maxY:I}]),layer:"top"};return{circuitJson:gOn(e).concat(c,a,b),parameters:e}},mOn=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},gOn=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=mOn({pn:n,p:Number.parseFloat(t.p)});e.push(Bo(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return e},pOn=ti.extend({fn:X(),num_pins:tt(2).default(2),w:X().default("1.3mm"),h:X().default("0.9mm"),pl:X().default("0.4mm"),pw:X().default("0.7mm"),p:X().default("0.7mm")}),fOn=t=>{const e=pOn.parse(t),n=ai(0,de.parse(e.h)+.1,.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:de.parse(e.p)/2+.2,y:de.parse(e.h)/2+.2},{x:-de.parse(e.w)/2-.2,y:de.parse(e.h)/2+.2},{x:-de.parse(e.w)/2-.2,y:-de.parse(e.h)/2-.2},{x:de.parse(e.p)/2+.2,y:-de.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:xOn(e).concat(o,n,s),parameters:e}},yOn=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},xOn=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=yOn({pn:n,p:Number.parseFloat(t.p)});e.push(Bo(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return e},COn=ti.extend({fn:X(),num_pins:tt(2).default(2),w:X().default("3.05mm"),h:X().default("1.4mm"),pl:X().default("0.5mm"),pw:X().default("0.5mm"),pad_spacing:X().default("2.2mm")}),IOn=t=>{const e=COn.parse(t),n=ai(0,de.parse(e.h),.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:de.parse(e.pad_spacing)/2,y:de.parse(e.h)/2},{x:-de.parse(e.w)/2-.2,y:de.parse(e.h)/2},{x:-de.parse(e.w)/2-.2,y:-de.parse(e.h)/2},{x:de.parse(e.pad_spacing)/2,y:-de.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:bOn(e).concat(o,n,s),parameters:e}},EOn=t=>{const{pn:e,pad_spacing:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},bOn=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=EOn({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},SOn=ti.extend({fn:X(),num_pins:tt(2).default(2),w:X().default("4.4mm"),h:X().default("2.1mm"),pl:X().default("1.10mm"),pw:X().default("1.10mm"),p:X().default("2.8mm")}),POn=t=>{const e=SOn.parse(t),n=ai(0,de.parse(e.h),.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:de.parse(e.p)/2,y:de.parse(e.h)/2},{x:-de.parse(e.w)/2-.2,y:de.parse(e.h)/2},{x:-de.parse(e.w)/2-.2,y:-de.parse(e.h)/2},{x:de.parse(e.p)/2,y:-de.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:BOn(e).concat(o,n,s),parameters:e}},vOn=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},BOn=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=vOn({pn:n,p:Number.parseFloat(t.p)});e.push(Bo(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return e},MOn=ti.extend({fn:X(),num_pins:tt(2).default(2),w:X().default("4.4mm"),h:X().default("2.1mm"),pl:X().default("0.91mm"),pw:X().default("1.22mm"),p:X().default("3.146mm")}),wOn=t=>{const e=MOn.parse(t),n=ai(0,de.parse(e.h),.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:de.parse(e.p)/2,y:de.parse(e.h)/2},{x:-de.parse(e.w)/2-.2,y:de.parse(e.h)/2},{x:-de.parse(e.w)/2-.2,y:-de.parse(e.h)/2},{x:de.parse(e.p)/2,y:-de.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:TOn(e).concat(o,n,s),parameters:e}},DOn=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},TOn=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=DOn({pn:n,p:Number.parseFloat(t.p)});e.push(Bo(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return e},QOn=ti.extend({fn:X(),num_pins:tt(2).default(2),w:X().default("1.80mm"),h:X().default("1.00mm"),pl:X().default("0.66mm"),pw:X().default("0.5mm"),p:X().default("0.8mm")}),ROn=t=>{const e=QOn.parse(t),n=ai(0,de.parse(e.h),.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:de.parse(e.p)/2,y:de.parse(e.h)/2},{x:-de.parse(e.w)/2-.1,y:de.parse(e.h)/2},{x:-de.parse(e.w)/2-.1,y:-de.parse(e.h)/2},{x:de.parse(e.p)/2,y:-de.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:kOn(e).concat(o,n,s),parameters:e}},NOn=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},kOn=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=NOn({pn:n,p:Number.parseFloat(t.p)});e.push(Bo(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return e},HOn=ti.extend({fn:X(),num_pins:tt(2).default(2),w:X().default("6.2mm"),h:X().default("3.4mm"),pl:X().default("1.4mm"),pw:X().default("2.1mm"),p:X().default("4.4mm")}),LOn=t=>{const e=HOn.parse(t),n=ai(0,de.parse(e.h)/2+.4,.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:de.parse(e.p)/2,y:de.parse(e.h)/2},{x:-de.parse(e.w)/2-.2,y:de.parse(e.h)/2},{x:-de.parse(e.w)/2-.2,y:-de.parse(e.h)/2},{x:de.parse(e.p)/2,y:-de.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:OOn(e).concat(o,n,s),parameters:e}},FOn=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},OOn=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=FOn({pn:n,p:Number.parseFloat(t.p)});e.push(Bo(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return e},GOn=[{x:-3.0875,y:-2.5},{x:-3.0875,y:2.5},{x:2.0125,y:2.5},{x:2.0125,y:-2.5}],zOn=[{x:-2.85,y:-2.5},{x:-2.85,y:2.5},{x:2.85,y:2.5},{x:2.85,y:-2.5}],UOn=ti.extend({fn:X(),num_pins:ho([tt(3),tt(5)]).default(3),w:X().default("4.20mm"),h:X().default("4.80mm"),pl:X().default("1.3mm"),pw:X().default("0.9mm"),p:X().default("1.5mm"),string:X().optional()}),VOn=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:GOn,layer:"top"};return[...e,u,_,c,h]},YOn=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:zOn,layer:"top"};return[...e,r,s,n,a]},KOn=t=>{const e=t.string?.match(/^sot89_(\d+)/),n=e?Number.parseInt(e[1],10):3,o=UOn.parse({...t,num_pins:n});if(o.num_pins===3)return{circuitJson:VOn(o),parameters:o};if(o.num_pins===5)return{circuitJson:YOn(o),parameters:o};throw new Error("Invalid number of pins for SOT89")},WOn=ti.extend({fn:X(),p:de.optional().default("5.0mm"),id:de.optional().default("1.0mm"),od:de.optional().default("1.9mm"),w:de.optional().default("13mm"),h:de.optional().default("7mm"),num_pins:ut().optional(),string:X().optional()}),Nht=t=>{const e=WOn.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,W)=>{const J=a%2===0?(W-a/2+.5)*h:(W-Math.floor(a/2))*h;return os(W+1,J,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:""},f=[{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:""}],y=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),L=Math.max(P,I+.25),F={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:(w+k)/2,y:(N+L)/2},width:k-w,height:L-N,layer:"top"};return{circuitJson:[...d,m,g,...f,y,F],parameters:{...e,p:h}}},CIe=2.54,jOn=ti.extend({fn:X(),id:de.optional().default("1.2mm"),od:de.optional().default("1.905mm"),ph:de.optional().default("2mm"),w:de.optional().default("13mm"),h:de.optional().default("7mm"),num_pins:ut().optional(),string:X().optional()}),XOn=t=>{const e=jOn.parse(t),n=e.num_pins??Number.parseInt(e.string?.match(/^to220f(?:_|-)(\d+)/i)?.[1]??"3"),o=Nht({...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)*CIe:(c-Math.floor(n/2))*CIe;return c===0?EC({pn:1,x:l,y:i,holeDiameter:e.id,rectPadWidth:e.od,rectPadHeight:e.ph}):BB(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:CIe,num_pins:n}}},JOn=ti.extend({fn:X(),num_pins:tt(2).default(2),w:X().default("5.40mm"),h:X().default("2.30mm"),pl:X().default("1.30mm"),pw:X().default("1.70mm"),p:X().default("3.5mm")}),qOn=t=>{const e=JOn.parse(t),n=ai(0,de.parse(e.h)/2+.4,.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:de.parse(e.p)/2,y:de.parse(e.h)/2},{x:-de.parse(e.w)/2,y:de.parse(e.h)/2},{x:-de.parse(e.w)/2,y:-de.parse(e.h)/2},{x:de.parse(e.p)/2,y:-de.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:ZOn(e).concat(o,n,s),parameters:e}},$On=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},ZOn=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=$On({pn:n,p:Number.parseFloat(t.p)});e.push(Bo(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return e},eGn=ti.extend({fn:X(),num_pins:tt(2).default(2),w:X().default("1.90mm"),h:X().default("1.33mm"),pl:X().default("0.5mm"),pw:X().default("0.7mm"),p:X().default("0.8mm")}),tGn=t=>{const e=eGn.parse(t),n=ai(0,de.parse(e.h)+.1,.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:de.parse(e.p)/2+.1,y:de.parse(e.h)/2},{x:-de.parse(e.w)/2,y:de.parse(e.h)/2},{x:-de.parse(e.w)/2,y:-de.parse(e.h)/2},{x:de.parse(e.p)/2+.1,y:-de.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:oGn(e).concat(o,n,s),parameters:e}},nGn=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},oGn=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=nGn({pn:n,p:Number.parseFloat(t.p)});e.push(Bo(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return e},iGn=ti.extend({fn:X(),num_pins:tt(2).default(2),w:X().default("7.0mm"),h:X().default("3.35mm"),pl:X().default("1.50mm"),pw:X().default("2.70mm"),p:X().default("4.8mm")}),rGn=t=>{const e=iGn.parse(t),n=ai(0,de.parse(e.h),.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:de.parse(e.p)/2,y:de.parse(e.h)/2},{x:-de.parse(e.w)/2,y:de.parse(e.h)/2},{x:-de.parse(e.w)/2,y:-de.parse(e.h)/2},{x:de.parse(e.p)/2,y:-de.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:aGn(e).concat(o,n,s),parameters:e}},sGn=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},aGn=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=sGn({pn:n,p:Number.parseFloat(t.p)});e.push(Bo(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return e},cGn=ti.extend({fn:X(),num_pins:tt(2).default(2),w:X().default("3.0mm"),h:X().default("1.80mm"),pl:X().default("0.80mm"),pw:X().default("1.20mm"),p:X().default("1.6mm")}),lGn=t=>{const e=cGn.parse(t),n=ai(0,de.parse(e.h),.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:de.parse(e.p)/2,y:de.parse(e.h)/2},{x:-de.parse(e.w)/2-.1,y:de.parse(e.h)/2},{x:-de.parse(e.w)/2-.1,y:-de.parse(e.h)/2},{x:de.parse(e.p)/2,y:-de.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:uGn(e).concat(o,n,s),parameters:e}},AGn=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},uGn=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=AGn({pn:n,p:Number.parseFloat(t.p)});e.push(Bo(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return e},_Gn=ti.extend({fn:X(),num_pins:tt(2).default(2),w:X().default("7.10mm"),h:X().default("3.40mm"),pl:X().default("2.50mm"),pw:X().default("1.80mm"),p:X().default("4.00mm")}),dGn=t=>{const e=_Gn.parse(t),n=ai(0,de.parse(e.h)/2+.5,.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:de.parse(e.p)/2,y:de.parse(e.h)/2},{x:-de.parse(e.w)/2-.5,y:de.parse(e.h)/2},{x:-de.parse(e.w)/2-.5,y:-de.parse(e.h)/2},{x:de.parse(e.p)/2,y:-de.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:mGn(e).concat(o,n,s),parameters:e}},hGn=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},mGn=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=hGn({pn:n,p:Number.parseFloat(t.p)});e.push(Bo(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return e},gGn=ti.extend({fn:X(),num_pins:tt(2).default(2),w:X().default("4.80mm"),h:X().default("2.10mm"),pl:X().default("1.30mm"),pw:X().default("1.40mm"),p:X().default("2.9mm")}),pGn=t=>{const e=gGn.parse(t),n=ai(0,de.parse(e.h)-.5,.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:de.parse(e.p)/2,y:de.parse(e.h)/2},{x:-de.parse(e.w)/2,y:de.parse(e.h)/2},{x:-de.parse(e.w)/2,y:-de.parse(e.h)/2},{x:de.parse(e.p)/2,y:-de.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:yGn(e).concat(o,n,s),parameters:e}},fGn=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},yGn=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=fGn({pn:n,p:Number.parseFloat(t.p)});e.push(Bo(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return e},xGn=ti.extend({fn:X(),num_pins:tt(2).default(2),w:X().default("7.30mm"),h:X().default("4.40mm"),pl:X().default("2.50mm"),pw:X().default("2.30mm"),p:X().default("4.30mm")}),CGn=t=>{const e=xGn.parse(t),n=ai(0,de.parse(e.h)/2+.5,.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:de.parse(e.p)/2,y:de.parse(e.h)/2},{x:-de.parse(e.w)/2-.1,y:de.parse(e.h)/2},{x:-de.parse(e.w)/2-.1,y:-de.parse(e.h)/2},{x:de.parse(e.p)/2,y:-de.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:EGn(e).concat(o,n,s),parameters:e}},IGn=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},EGn=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=IGn({pn:n,p:Number.parseFloat(t.p)});e.push(Bo(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return e},bGn=ti.extend({fn:X(),num_pins:tt(2).default(2),w:X().default("10.70mm"),h:X().default("6.60mm"),pl:X().default("2.50mm"),pw:X().default("3.30mm"),p:X().default("6.80mm")}),SGn=t=>{const e=bGn.parse(t),n=ai(0,3,.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:de.parse(e.p)/2,y:de.parse(e.h)/2-.8},{x:-de.parse(e.w)/2-.8,y:de.parse(e.h)/2-.8},{x:-de.parse(e.w)/2-.8,y:-de.parse(e.h)/2+.8},{x:de.parse(e.p)/2,y:-de.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:vGn(e).concat(o,n,s),parameters:e}},PGn=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},vGn=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=PGn({pn:n,p:Number.parseFloat(t.p)});e.push(Bo(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return e},BGn=ti.extend({fn:X(),num_pins:ut().default(4),w:X().default("8.50mm"),h:X().default("6.90mm"),pl:X().default("2mm"),pw:X().default("1.5mm"),p:X().default("2.30mm"),string:X().optional()}),MGn=t=>{const e=t.string?.match(/^sot223_(\d+)/),n=e?Number.parseInt(e[1],10):4;if(n===8){const i=TGn.parse({...t,num_pins:n});return{circuitJson:_H(i),parameters:i}}const o=BGn.parse({...t,num_pins:n});if(o.num_pins===4)return{circuitJson:DGn(o),parameters:o};if(o.num_pins===5)return{circuitJson:RGn(o),parameters:o};if(o.num_pins===6)return{circuitJson:kGn(o),parameters:o};throw new Error("Invalid number of pins")},wGn=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}},DGn=t=>{const e=[];let n=0,o=0;for(let d=0;d<t.num_pins;d++){const{x:m,y:p}=wGn({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),f=Number.parseFloat(t.pl);n=Math.max(n,Math.abs(m)+f/2),o=Math.max(o,Math.abs(p)+g/2),e.push(Bo(d+1,m,p,f,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]},TGn=SB({p:"0.90mm",w:"2.8mm",legsoutside:!0}),QGn=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")},RGn=t=>{const e=[];let n=0,o=0;for(let d=1;d<=t.num_pins;d++){const{x:m,y:p}=QGn({h:Number.parseFloat(t.h),p:1.5,pn:d,w:Number.parseFloat(t.w)});let g=Number.parseFloat(t.pw),f=Number.parseFloat(t.pl);d===5?(g=3.4,f=1.8):(g=1,f=2.2),n=Math.max(n,Math.abs(m)+f/2),o=Math.max(o,Math.abs(p)+g/2),e.push(Bo(d,m,p,f,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]},NGn=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")},kGn=t=>{const e=[];let n=0,o=0;for(let d=1;d<=t.num_pins;d++){const{x:m,y:p}=NGn({h:Number.parseFloat(t.h),p:1.3,pn:d,w:8.7});let g=Number.parseFloat(t.pw),f=Number.parseFloat(t.pl);d===6?(g=3.4,f=2.15):(g=.6,f=2.2),n=Math.max(n,Math.abs(m)+f/2),o=Math.max(o,Math.abs(p)+g/2),e.push(Bo(d,m,p,f,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]},HGn=ti.extend({fn:X(),num_pins:ut().default(3),w:X().default("3.40mm"),h:X().default("3.30mm"),pl:X().default("1mm"),pw:X().default("0.7mm"),p:X().default("1.2mm"),string:X().optional()}),LGn=t=>{const e=t.string?.match(/^sot23w_(\d+)/),n=e?Number.parseInt(e[1],3):3,o=HGn.parse({...t,num_pins:n});if(o.num_pins===3)return{circuitJson:OGn(o),parameters:o};throw new Error("Invalid number of pins")},FGn=t=>{const{pn:e,p:n}=t;return e===1?{x:-n,y:.95}:e===2?{x:-n,y:-.95}:{x:n,y:0}},OGn=t=>{const e=[];for(let g=0;g<t.num_pins;g++){const{x:f,y}=FGn({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,f,y,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]},GGn=ti.extend({fn:X(),num_pins:ho([tt(3),tt(2)]).default(3),p:X().default("1.27mm"),id:X().default("0.72mm"),od:X().default("0.95mm"),w:X().default("2.5mm"),h:X().default("4.2mm"),string:X().optional()}),zGn=t=>{const{p:e,id:n,od:o,w:i,h:r}=t,s=Number.parseFloat(r)/2,a=Number.parseFloat(e);return[os(1,-a,s-a,n,o),os(2,0,s-a,n,o),os(3,a,s-a,n,o)]},UGn=t=>{const{p:e,id:n,od:o,h:i}=t,r=Number.parseFloat(i)/2,s=Number.parseFloat(e);return[os(1,-s,r-s,n,o),os(2,s,r-s,n,o)]},VGn=t=>{const e=t.string?.match(/^to92s_(\d+)/),n=e?Number.parseInt(e[1],10):3,o=GGn.parse({...t,num_pins:n});let i=[];if(o.num_pins===3)i=zGn(o);else if(o.num_pins===2)i=UGn(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,f=r+.5,y=Math.min(u,m)-.27,x=Math.max(_,p)+.13,I=Math.min(h,g)-.42,E=Math.max(d,f)+.08,b={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:(y+x)/2,y:(I+E)/2},width:x-y,height:E-I,layer:"top"};return{circuitJson:[...i,a,c,b],parameters:o}},YGn=ti.extend({fn:X(),p:de.optional(),id:de.optional(),pw:de.optional(),pl:de.optional(),w:de.optional(),h:de.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:X().optional()}),KGn=()=>({minX:Number.POSITIVE_INFINITY,maxX:Number.NEGATIVE_INFINITY,minY:Number.POSITIVE_INFINITY,maxY:Number.NEGATIVE_INFINITY}),dH=({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)},WGn={ph:{p:de.parse("2.2mm"),id:de.parse("0.70mm"),pw:de.parse("1.20mm"),pl:de.parse("1.20mm"),w:de.parse("6mm"),h:de.parse("5mm")},sh:{p:de.parse("1mm"),pw:de.parse("0.6mm"),pl:de.parse("1.55mm"),w:de.parse("5.8mm"),h:de.parse("7.8mm")},zh:{p:de.parse("1.5mm"),id:de.parse("0.73mm"),pw:de.parse("1.03mm"),pl:de.parse("1.73mm"),w:de.parse("3mm"),h:de.parse("3.5mm")}};function jGn(t){return t.sh?"sh":t.ph?"ph":t.zh?"zh":"ph"}function XGn({variant:t,numPins:e,p:n,id:o,pw:i,pl:r}){const s=[],a=KGn();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(EC({pn:A+1,x:u,y:2,holeDiameter:o,rectPadWidth:i,rectPadHeight:r})),dH({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(EC({pn:A+1,x:u,y:0,holeDiameter:o,rectPadWidth:i,rectPadHeight:r,rectBorderRadius:.12499977})):s.push(BB(A+1,u,0,o,i,r)),dH({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)),dH({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)),dH({bounds:a,centerX:-A,centerY:1.22,width:1.2,height:1.8}),dH({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 JGn({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 qGn=t=>{const e=YGn.parse(t),n=jGn(e),o=WGn[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=XGn({variant:n,numPins:A,p:i,id:r,pw:s,pl:a}),{pads:p,padBounds:g,maxPadHalfY:f}=m,y=JGn({variant:n,w:c,h:l,numPins:A,p:i}),x=ai(0,l/2+1,.5),I=y.route.map(Ae=>Ae.x),E=y.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,L=.05,F=f+.085,G=P-N,W=B+N,J=w-F,$=k+L,oe={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:(G+W)/2,y:(J+$)/2},width:W-G,height:$-J,layer:"top"};return{circuitJson:[...p,y,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"}}},$Gn=ti.extend({fn:X(),num_pins:tt(2).default(2),w:X().default("3.30mm"),h:X().default("1.70mm"),pl:X().default("0.80mm"),pw:X().default("1mm"),p:X().default("1.90mm")}),ZGn=t=>{const e=$Gn.parse(t),n=ai(0,de.parse(e.h)/2+.5,.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:de.parse(e.p)/2,y:de.parse(e.h)/2},{x:-de.parse(e.w)/2,y:de.parse(e.h)/2},{x:-de.parse(e.w)/2,y:-de.parse(e.h)/2},{x:de.parse(e.p)/2,y:-de.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:tzn(e).concat(o,n,s),parameters:e}},ezn=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},tzn=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=ezn({pn:n,p:Number.parseFloat(t.p)});e.push(Bo(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return e},nzn=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"}}},ozn=ti.extend({fn:X(),num_pins:ho([tt(8),tt(10)]).default(8),w:X().optional(),h:X().optional(),p:X().optional(),pl:X().optional(),pw:X().optional(),string:X().optional()}),izn=t=>{const e=ozn.parse(t),n=nzn(e.num_pins),o=de.parse(e.w||n.w),i=de.parse(e.h||n.h),r=de.parse(e.p||n.p),s=de.parse(e.pl||n.pl),a=de.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}=kht(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=kht(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),f=(e.num_pins/2-1)*r+a,y=o/2+.25,x=y+1.43,I=f/2+.255,E=i/2+.25,b={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",layer:"top",outline:I1([{minX:-x,maxX:x,minY:-I,maxY:I},{minX:-y,maxX:y,minY:-E,maxY:E}])};return{circuitJson:[...c,_,h,g,p,b],parameters:e}},kht=(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}},rzn=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"}}},szn=ti.extend({fn:X(),num_pins:ho([tt(8),tt(10),tt(12),tt(16)]).default(8),w:X().optional(),h:X().optional(),p:X().optional(),pl:X().optional(),pw:X().optional(),string:X().optional()}),Hht=(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*de.parse("2mm"),y:a*o}},azn=t=>{const e=szn.parse(t),n=rzn(e.num_pins),o=de.parse(e.w||n.w),i=de.parse(e.h||n.h),r=de.parse(e.p||n.p),s=de.parse(e.pl||n.pl),a=de.parse(e.pw||n.pw),c=[];for(let b=0;b<e.num_pins;b++){const{x:P,y:B}=Hht(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=Hht(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,f=o/2+.25,y=f+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:I1([{minX:-y,maxX:y,minY:-x,maxY:x},{minX:-f,maxX:f,minY:-I,maxY:I}])};return{circuitJson:[...c,u,_,p,m,E],parameters:e}},czn=ti.extend({fn:X(),num_pins:tt(2).default(2),w:X().default("3.8mm"),h:X().default("1.65mm"),pl:X().default("1.2mm"),pw:X().default("1.2mm"),pad_spacing:X().default("2.6mm")}),lzn=t=>{const e=czn.parse(t),n=ai(0,de.parse(e.h),.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:de.parse(e.pad_spacing)/2,y:de.parse(e.h)/2},{x:-de.parse(e.w)/2-.2,y:de.parse(e.h)/2},{x:-de.parse(e.w)/2-.2,y:-de.parse(e.h)/2},{x:de.parse(e.pad_spacing)/2,y:-de.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:uzn(e).concat(o,n,s),parameters:e}},Azn=t=>{const{pn:e,pad_spacing:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},uzn=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=Azn({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},_zn=ti.extend({fn:X(),num_pins:tt(2).default(2),w:X().default("3.20mm"),h:X().default("1.65mm"),pl:X().default("0.8mm"),pw:X().default("0.9mm"),pad_spacing:X().default("2.1mm")}),dzn=t=>{const e=_zn.parse(t),n=ai(0,de.parse(e.h),.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:de.parse(e.pad_spacing)/2,y:de.parse(e.h)/2},{x:-de.parse(e.w)/2-.2,y:de.parse(e.h)/2},{x:-de.parse(e.w)/2-.2,y:-de.parse(e.h)/2},{x:de.parse(e.pad_spacing)/2,y:-de.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:mzn(e).concat(o,n,s),parameters:e}},hzn=t=>{const{pn:e,pad_spacing:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},mzn=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=hzn({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},gzn=ti.extend({fn:X(),num_pins:ho([tt(6),tt(8)]).default(8),w:X().default("3mm"),h:X().default("3mm"),p:X().default("0.5mm"),pl:X().default("0.52mm"),pw:X().default("0.35mm"),epw:X().default("1.40mm"),eph:X().default("1.60mm"),string:X().optional(),ep:Je().default(!1)}),pzn=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=gzn.parse({...t,num_pins:n}),i=de.parse(o.w),r=de.parse(o.h),s=de.parse(o.p),a=de.parse(o.pl),c=de.parse(o.pw),l=de.parse(o.epw),A=de.parse(o.eph),u=[];for(let N=0;N<o.num_pins;N++){const{x:L,y:F}=IIe(o.num_pins,N+1,i,s);u.push(Bo(N+1,L,F,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=IIe(o.num_pins,1,_,s),g={x:p.x-.4,y:p.y},f={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"},y=ai(0,h/2+.5,.3),x=Math.abs(IIe(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:I1([{minX:-P,maxX:P,minY:-B,maxY:B},{minX:-b,maxX:b,minY:-w,maxY:w}])};return{circuitJson:[...u,d,m,y,f,k],parameters:o}},IIe=(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*de.parse("1.4mm"),y:a*o}},fzn=ti.extend({fn:X(),num_pins:ut().optional().default(8),p:nt.describe("pitch (distance between center of each pin)"),w:de.describe("width between vertical rows of pins"),grid:IJ.describe("width and height of the border of the footprint"),ep:IJ.default("0x0mm").describe("width and height of the central exposed thermal pad"),epx:de.default("0mm").describe("x offset of the center of the central exposed thermal pad"),pinw:de.describe("width of the pin pads"),pinh:de.describe("height of the pin pads")}),yzn=t=>{const e=fzn.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}=xzn({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=Czn(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,f=h/2+.45+Math.max(0,.8-o),y=Math.min(r.y/2+.25,f),x=Math.max(0,.37-Math.max(0,p-m-.38)*1.4),I=Math.max(g,y-x),E={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",layer:"top",outline:I1([{minX:-p,maxX:p,minY:-I,maxY:I},{minX:-m,maxX:m,minY:-y,maxY:y}])};return{circuitJson:[...A,...u,_,E],parameters:e}},xzn=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}},Czn=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}]},Izn=t=>{const{num_pins:e,bridged:n,p:o=2.54,pw:i=1.5,ph:r=1.5}=t,s=de.parse(o),a=de.parse(i),c=de.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],L=w[k+1];if(typeof N=="number"&&typeof L=="number"&&!isNaN(N)&&!isNaN(L)){const F=(N-1)*s,G=(L-1)*s,W=Math.sign(G-F),J=F+W*(a/2),$=G-W*(a/2);u.push({type:"pcb_trace",pcb_trace_id:"",route:[{start_pcb_port_id:`{PIN${N}}`,x:J,y:0,width:l,layer:"top",route_type:"wire"},{end_pcb_port_id:`{PIN${L}}`,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},f=m+h/2+.6,y=ai(d,f,.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,y,B],parameters:t}},Lht={fn:tt("sot457"),num_pins:tt(6).default(6),pillh:X().default("0.45mm"),pillw:X().default("1.45mm"),pl:X(),pw:X(),p:X(),wave:Je().optional(),reflow:Je().optional()},Ezn=ti.extend({...Lht,h:X().default("2.5mm"),w:X().default("2.7mm"),pl:X().default("0.8mm"),pw:X().default("0.55mm"),p:X().default("0.95mm")}),bzn=ti.extend({...Lht,h:X().default("3mm"),w:X().default("4mm"),pillr:X().default("0.225mm"),pl:X().default("1.45mm"),pw:X().default("1.5mm"),p:X().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)})),sb=t=>Number.parseFloat(t.replace("mm","")),Fht=({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},Oht=t=>{const e=[],n=sb(t.p),o=sb(t.pl),i=sb(t.pw),r=sb(t.w),s=sb(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})=>EJ(3,-n,0,sb(t.pillw),sb(t.pillh)),4:({padWidth:p,padHeight:g})=>EJ(4,n,0,sb(t.pillw),sb(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}=Fht({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=Fht({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,f=p/2+o/2,y=g+.25,x=f+.25;d={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:0,y:0},width:2*y,height:2*x,layer:"top"}}else{const p=r/2+.1+o/2,g=n+i/2,f=r/2,y=s/2,x=p+.25,I=f+.08,E=g+.25,b=Math.max(y+.45,E);d={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",outline:I1([{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]},Szn=t=>{if(t.wave){const n=bzn.parse({...t,fn:"sot457"});return{circuitJson:Oht(n),parameters:n}}const e=Ezn.parse(t);return{circuitJson:Oht(e),parameters:e}},Pzn=[{x:-.8,y:.75},{x:.8,y:.75},{x:.8,y:-.75},{x:-.8,y:-.75}],vzn=ti.extend({fn:X(),num_pins:tt(6).default(6),w:X().default("1.1mm"),h:X().default("1.45mm"),p:X().default("0.35mm"),pl:X().default("0.2mm"),pw:X().default("0.2mm"),string:X().optional()}),Bzn=t=>{const e=vzn.parse({...t,fn:"sot963"}),n=de.parse(e.w),o=de.parse(e.h),i=de.parse(e.p),r=de.parse(e.pl),s=de.parse(e.pw),a=[];for(let d=0;d<6;d++){const{x:m,y:p}=Ght(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=Ght(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:Pzn,layer:"top"};return{circuitJson:[...a,c,l,_,u,h],parameters:e}},Ght=(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}},Mzn=ti.extend({fn:X(),num_pins:ho([tt(3),tt(2)]).default(3),p:X().default("3.8mm"),id:X().default("1.25mm"),od:X().default("2.35mm"),ca:X().default("14mm").describe("Caliper axis (width or diameter of the potentiometer body or adjustment knob)"),w:X().default("5.35mm"),h:X().default("4mm"),string:X().optional()}),wzn=t=>{const{p:e,id:n,od:o,h:i,ca:r}=t,s=Number.parseFloat(i),a=Number.parseFloat(r);return[os(1,0,a/4+.3,n,o),os(2,s,0,n,o),os(3,0,-a/4-.3,n,o)]},Dzn=t=>{const e=t.string?.match(/^potentiometer_(\d+)/),n=e?Number.parseInt(e[1],10):3,o=Mzn.parse({...t,num_pins:n});let i=[];o.num_pins===3&&(i=wzn(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,f={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,f],parameters:o}},Tzn=ti.extend({fn:X(),p:de.optional().default("7.5mm"),id:de.optional().default("1mm"),od:de.optional().default("2mm"),d:de.optional().default("10.5mm")}),Qzn=(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}},Rzn=t=>{const e=Tzn.parse(t),{p:n,id:o,od:i,d:r}=e,s=[os(1,-n/2,0,o,i),os(2,n/2,0,o,i)],{topArc:a,bottomArc:c}=Qzn(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),f=r/2,y=n/2+i/2,I=Math.max(f,y)+.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}},Nzn=ti.extend({fn:X(),num_pins:tt(2).default(2),w:X().default("6.5mm"),h:X().default("3mm"),pl:X().default("1.75mm"),pw:X().default("2.40mm"),p:X().default("4.75mm")}),kzn=t=>{const e=Nzn.parse(t),n=ai(0,de.parse(e.h)-.5,.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:de.parse(e.p)/2,y:de.parse(e.h)/2},{x:-de.parse(e.w)/2-.3,y:de.parse(e.h)/2},{x:-de.parse(e.w)/2-.3,y:-de.parse(e.h)/2},{x:de.parse(e.p)/2,y:-de.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:Lzn(e).concat(o,n,s),parameters:e}},Hzn=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},Lzn=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=Hzn({pn:n,p:Number.parseFloat(t.p)});e.push(Bo(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return e},Fzn=[{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}],Ozn=ti.extend({fn:X(),num_pins:ut().default(3),w:X().default("2.45mm"),h:X().default("2.40mm"),pl:X().default("0.92mm"),pw:X().default("0.45mm"),p:X().default("0.891mm"),string:X().optional()}),Gzn=t=>{const e=t.string?.match(/^sot323_(\d+)/),n=e?Number.parseInt(e[1],3):3,o=Ozn.parse({...t,num_pins:n});if(o.num_pins===3)return{circuitJson:Uzn(o),parameters:o};throw new Error("Invalid number of pins")},zzn=t=>{const{pn:e,p:n}=t;return e===1?{x:-n,y:.65}:e===2?{x:-n,y:-.65}:{x:n,y:0}},Uzn=t=>{const e=[];for(let c=0;c<t.num_pins;c++){const{x:l,y:A}=zzn({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:Fzn,layer:"top"};return[...e,r,s,n,a]},Vzn=ti.extend({fn:X(),circle:Je().optional(),rect:Je().optional(),square:Je().optional(),pill:Je().optional(),d:de.optional(),pd:de.optional(),diameter:de.optional(),r:de.optional(),pr:de.optional(),radius:de.optional(),w:de.optional(),pw:de.optional(),width:de.optional(),h:de.optional(),ph:de.optional(),height:de.optional(),s:de.optional(),size:de.optional(),string:X().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}}),Yzn=t=>{const e=Vzn.parse(t),{shape:n,radius:o,width:i,height:r}=e;let s,a;return n==="circle"?(s=xht(1,{x:0,y:0,radius:o}),a=o+.5):n==="pill"?(s=EJ(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}},Kzn=ti.extend({fn:X(),d:de.optional(),hd:de.optional(),r:de.optional(),hr:de.optional(),pd:de.optional(),pr:de.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}}),Wzn=t=>{const e=Kzn.parse(t),{d:n,pd:o,squarepad:i}=e;return{circuitJson:[i?EC({pn:1,x:0,y:0,holeDiameter:n,rectPadWidth:o,rectPadHeight:o}):os(1,0,0,n,o),ai(0,o/2+.5,.2)],parameters:e}},jzn=ti.extend({fn:X(),num_pins:tt(6).default(6),h:X().default("1.3mm"),pl:X().default("1.325mm"),pw:X().default("0.6mm"),p:X().default("0.95mm")}),Xzn=t=>{const e=jzn.parse(t);return{circuitJson:Jzn(e),parameters:e}},zht=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")},Jzn=t=>{const e=[];for(let b=1;b<=t.num_pins;b++){const{x:P,y:B}=zht({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=zht({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,f=u/2+.4,y=g+.25,x=p/2+.25,I=x+.2,E={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",layer:"top",outline:I1([{minX:-y,maxX:y,minY:-x,maxY:x},{minX:-f,maxX:f,minY:-I,maxY:I}])};return[...e,s,i,r,A,E]},qzn=[{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}],$zn=ti.extend({fn:X(),num_pins:ut().default(4),w:X().default("3.2mm"),h:X().default("2.6mm"),pl:X().default("1.05mm"),pw:X().default("0.45mm"),p:X().default("0.55mm"),string:X().optional()}),Zzn=t=>{const e=t.string?.match(/^sot343_(\d+)/),n=e?Number.parseInt(e[1],4):4,o=$zn.parse({...t,num_pins:n});if(o.num_pins===4)return{circuitJson:tUn(o),parameters:o};throw new Error("Invalid number of pins")},eUn=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}},tUn=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}=eUn({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},f={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},y={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",outline:qzn,layer:"top"};return[...e,g,f,p,y]},nUn=ti.extend({fn:X()}),oUn=t=>{const e=nUn.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),L=.5-k/2,F=Bo(P,L,B,k,o);F.layer=w?"bottom":"top",n.push(F)}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,f=-1/0;const y=(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),f=Math.max(f,P+w/2)};for(const b of n){const P=b;y(P.x,P.y,P.width,P.height)}y(_.center.x,_.center.y,_.width,_.height);for(const b of d.route)y(b.x,b.y);const x=(m+p)/2,I=(g+f)/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}},iUn=ti.extend({fn:X(),numPins:ut().optional().default(0),rows:ho([X(),ut()]).transform(t=>Number(t)).optional().default(1).describe("number of rows"),p:de.default("2.54mm").describe("pitch"),id:de.default("1.0mm").describe("inner diameter"),od:de.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([X(),ut()]).transform(t=>Number(t)).optional(),pinrowrightpins:ho([X(),ut()]).transform(t=>Number(t)).optional(),pinrowtoppins:ho([X(),ut()]).transform(t=>Number(t)).optional(),pinrowbottompins:ho([X(),ut()]).transform(t=>Number(t)).optional(),width:de.optional(),height:de.optional(),pinRowHoleEdgeToEdgeDist:de.default("2mm"),holes:ho([X(),$t(X())]).optional().transform(t=>!t||Array.isArray(t)?t:t.startsWith("(")&&t.endsWith(")")?t.slice(1,-1).split(",").map(e=>e.trim()):[t]),holeXDist:de.optional(),holeYDist:de.optional(),holeInset:de.default("1mm"),pinrow:ho([X(),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:de.optional(),screenheight:de.optional(),screencenteroffsetx:de.optional(),screencenteroffsety:de.optional()}).transform(t=>{const e=Mht(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,f=t.screencenteroffsetx??0,y=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:f,screencenteroffsety:y,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"]})}),rUn=t=>{const e=iUn.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:f,holes:y,holeXDist:x,holeYDist:I,holeInset:E,pinrowleftpins:b,pinrowrightpins:P,pinrowtoppins:B,pinrowbottompins:w,usbposition:k,usbtype:N,screen:L,screenwidth:F,screenheight:G,screencenteroffsetx:W,screencenteroffsety:J}=e;let $="center";A?$="left":u&&($="right");const oe=[],Ae={left:b,right:P,top:B,bottom:w},ee=Object.values(Ae).some(re=>re!==void 0&&re>0),ie=(re,_e,xe,be)=>{if(e.smd?oe.push(Bo(re,_e,xe,e.od,e.od)):re===1?oe.push(EC({pn:re,x:_e,y:xe,holeDiameter:o,rectPadWidth:i,rectPadHeight:i})):oe.push(os(re,_e,xe,o,i)),!_){const ve=_e+(be==="left"?-i:be==="right"?i:0),le=xe+(be==="top"?i:be==="bottom"?-i:0);d||oe.push(PB({fs:i/5,pn:re,anchor_x:ve,anchor_y:le,textalign:$,orthogonal:l,verticallyinverted:c,layer:"top"})),(h||d)&&oe.push(PB({fs:i/5,pn:re,anchor_x:ve,anchor_y:le,textalign:$,orthogonal:l,verticallyinverted:c,layer:"bottom"}))}};if(ee){const re=n;let _e=1;const xe=Ae.left??0,be=Ae.right??0,ve=Ae.top??0,le=Ae.bottom??0,Ie=(pe,ke)=>{if(!(ke<=0))if(pe==="left"||pe==="right"){const Ue=pe==="left"?-p/2+f:p/2-f,je=(ke-1)/2*re;for(let ye=0;ye<ke;ye++)ie(_e,Ue,je-ye*re,pe),_e++}else{const Ue=pe==="top"?g/2-f:-g/2+f,je=-((ke-1)/2)*re;for(let ye=0;ye<ke;ye++)ie(_e,je+ye*re,Ue,pe),_e++}};Ie("left",xe),Ie("right",be),Ie("top",ve),Ie("bottom",le)}else{const re=n;let _e=0,xe=0,be=0,ve=0,le=0,Ie=0;const pe=Math.ceil(s/r);m==="left"||m==="right"?(_e=m==="left"?-p/2+f:p/2-f,xe=(pe-1)/2*re,be=0,ve=-re,le=m==="left"?re:-re,Ie=0):(_e=-(pe-1)/2*re,xe=m==="top"?g/2-f:-g/2+f,be=re,ve=0,le=0,Ie=m==="top"?-re:re);let ke=1;for(let Ue=0;Ue<r&&ke<=s;Ue++)for(let je=0;je<pe&&ke<=s;je++){const ye=_e+je*be+Ue*le,qe=xe+je*ve+Ue*Ie;if(e.smd?oe.push(Bo(ke,ye,qe,e.od,e.od)):ke===1?oe.push(EC({pn:ke,x:ye,y:qe,holeDiameter:o,rectPadWidth:i,rectPadHeight:i})):oe.push(os(ke,ye,qe,o,i)),!_){const Fe=ye+(m==="left"?-i:m==="right"?i:0),De=qe+(m==="top"?i:m==="bottom"?-i:0);d||oe.push(PB({fs:i/5,pn:ke,anchor_x:Fe,anchor_y:De,textalign:$,orthogonal:l,verticallyinverted:c,layer:"top"})),(h||d)&&oe.push(PB({fs:i/5,pn:ke,anchor_x:Fe,anchor_y:De,textalign:$,orthogonal:l,verticallyinverted:c,layer:"bottom"}))}ke++}}if(y)for(const re of y){let _e=0,xe=0;re==="topleft"?(_e=-p/2+E,xe=g/2-E):re==="topright"?(_e=p/2-E,xe=g/2-E):re==="bottomleft"?(_e=-p/2+E,xe=-g/2+E):re==="bottomright"?(_e=p/2-E,xe=-g/2+E):re==="center"&&(_e=0,xe=0),x!==void 0&&(_e+=x),I!==void 0&&(xe+=I),oe.push(os(s+y.indexOf(re)+1,_e,xe,o,i))}if(!e.nosilkscreen){const re=[{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(vB(re,{stroke_width:.1,layer:"top"}))}const ae=ai(0,g/2+1,.5);if(oe.push(ae),k&&N){let re,_e;if(N==="c")re=8,_e=3;else if(N==="micro")re=6,_e=2;else return{circuitJson:oe,parameters:e};let xe;if(k==="left")xe=[{x:-p/2,y:-re/2},{x:-p/2+_e,y:-re/2},{x:-p/2+_e,y:re/2},{x:-p/2,y:re/2},{x:-p/2,y:-re/2}];else if(k==="right")xe=[{x:p/2-_e,y:-re/2},{x:p/2,y:-re/2},{x:p/2,y:re/2},{x:p/2-_e,y:re/2},{x:p/2-_e,y:-re/2}];else if(k==="top")xe=[{x:-re/2,y:g/2-_e},{x:re/2,y:g/2-_e},{x:re/2,y:g/2},{x:-re/2,y:g/2},{x:-re/2,y:g/2-_e}];else if(k==="bottom")xe=[{x:-re/2,y:-g/2},{x:re/2,y:-g/2},{x:re/2,y:-g/2+_e},{x:-re/2,y:-g/2+_e},{x:-re/2,y:-g/2}];else return{circuitJson:oe,parameters:e};oe.push(vB(xe,{stroke_width:.1,layer:"top"}))}if(L){const re=F/2,_e=G/2,xe=W,be=J,ve=[{x:-re+xe,y:-_e+be},{x:re+xe,y:-_e+be},{x:re+xe,y:_e+be},{x:-re+xe,y:_e+be},{x:-re+xe,y:-_e+be}];oe.push(vB(ve,{stroke_width:.05,layer:"top"}))}return{circuitJson:oe,parameters:e}},sUn=[{x:-1.45,y:2.75},{x:-1.45,y:-1.85},{x:4.05,y:-1.85},{x:4.05,y:2.75}],aUn=[{x:-1.55,y:2.75},{x:-1.55,y:-1.85},{x:3.95,y:-1.85},{x:3.95,y:2.75}],cUn=ti.extend({fn:X(),num_pins:ut().default(3),inline:Je().default(!1),p:X().default("1.27mm"),id:X().default("0.75mm"),od:X().default("1.3mm"),w:X().default("4.8mm"),h:X().default("4.0mm")}),lUn=t=>{const e=cUn.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=[EC({pn:1,x:0,y:0,holeDiameter:e.id,rectPadWidth:r,rectPadHeight:s}),e.inline?BB(2,n,0,Number.parseFloat(e.id),r,s):os(2,n,n,e.id,r),e.inline?BB(3,n*2,0,Number.parseFloat(e.id),r,s):os(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 f=Math.PI*g/31;return{x:l+c*Math.cos(f),y:A+c*Math.sin(f)}}),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?aUn:sUn,layer:"top"};return{circuitJson:[...a,h,d,m],parameters:e}},AUn=(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},uUn=(t,e)=>e.nosilkscreen?t.filter(n=>n.type!=="pcb_silkscreen_path"&&n.type!=="pcb_silkscreen_text"):t,_Un=(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 dUn(t){return t!=null}var hUn=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"),mUn=t=>{let e=PJ();const n=hUn(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(dUn);for(const{fn:r,v:s}of i)e=e[r](s);return e.setString(n),e},gUn=()=>Object.keys(rb),PJ=()=>{const t=new Proxy({},{get:(e,n)=>{if(n==="soup"||n==="circuitJson"){if("fn"in e&&rb[e.fn])return()=>{const{circuitJson:o}=rb[e.fn](e),i=uUn(o,e),r=AUn(i,e);return _Un(r,e.origin)};if(!rb[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(!rb[e.fn])throw new Error(`Invalid footprint function, got "${e.fn}"${e.string?`, from string "${e.string}"`:""}`);return()=>rb[e.fn](e).parameters}return n==="getFootprintNames"?()=>Object.keys(rb):n==="params"?()=>e:n==="setString"?o=>(e.string=o,t):o=>(Object.keys(e).length===0?`${n}${o}`in rb?(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};PJ.string=mUn,PJ.getFootprintNames=gUn;var pUn=PJ,Uht=Symbol("Fragment");function EIe(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"),Vht=Symbol("Cube"),al=Symbol("Cylinder"),vJ=Symbol("Sphere"),hH=Symbol("RoundedCuboid"),Wo=Symbol("Translate"),X_=Symbol("Rotate"),Sh=Symbol("Union"),gf=Symbol("Subtract"),Ol=Symbol("Hull"),Er=Symbol("Colorize"),mH=Symbol("Polygon"),gH=Symbol("ExtrudeLinear"),U2=Symbol("RoundedCylinder"),ir=Uht,Ve=(t,e,n)=>EIe(t,e),Jn=(t,e,n)=>EIe(t,e),fUn=({hole:t,isPin1:e})=>{const n=e?"#00ff00":"#b87333";if(t.shape==="circle")return Ve(Er,{color:n,children:Ve(Wo,{offset:[t.x,t.y,-.005],children:Jn(gf,{children:[Ve(al,{radius:t.outer_diameter/2,height:.01}),Ve(al,{radius:t.hole_diameter/2,height:.01})]})})});if(t.shape==="circular_hole_with_rect_pad")return Ve(Er,{color:n,children:Ve(Wo,{offset:[t.x,t.y,0],children:Jn(gf,{children:[Ve(ln,{size:[t.rect_pad_width,t.rect_pad_height,.01],center:[0,0,0]}),Ve(al,{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(Er,{color:n,children:Ve(Wo,{offset:[t.x,t.y,0],children:Jn(gf,{children:[Jn(Ol,{children:[Ve(al,{radius:r,height:.01,center:[s?-(o/2-r):0,s?0:-(i/2-r),0]}),Ve(al,{radius:r,height:.01,center:[s?o/2-r:0,s?0:i/2-r,0]})]}),a===c?Ve(al,{radius:a/2,height:.01}):Jn(Ol,{children:[Ve(al,{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(al,{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,f=Math.min(e,n)*s,y=Math.max(e-f,e*a),x=Math.max(n-f,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(Sh,{children:[Jn(Ol,{children:[Ve(Wo,{z:.005,children:Ve(ln,{size:[y,x,.01]})}),Ve(Wo,{z:p,children:Ve(ln,{size:[e,n,.01]})})]}),Jn(Ol,{children:[Ve(Wo,{z:p,children:Ve(ln,{size:[e,n,.01]})}),Ve(Wo,{z:p+g,children:Ve(ln,{size:[y,x,.01]})})]})]}),w=(N,L)=>Ve(Wo,{offset:{x:N,y:L,z:0},children:Ve(X_,{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,L=n/2;k=Jn(gf,{children:[B,w(N,L),w(-N,L),w(N,-L),w(-N,-L)]})}return Ve(Er,{color:r,children:Ve(Wo,{offset:t,children:Ve(Wo,{offset:{x:0,y:0,z:i},children:l?Jn(gf,{children:[k,Ve(Wo,{offset:P,children:Ve(X_,{rotation:_,children:Ve(al,{radius:E,height:d})})})]}):k})})})},yUn=t=>Array.from({length:t},(e,n)=>n);function bIe(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,f=Math.sqrt(p*p+g*g);if(f/2>2*o)a(_,d,1),a(_,m,1),a(_,d,-1),a(_,m,-1);else{const x=1/f;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 xUn=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}))},CUn=xUn([{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}]),Yht=5.47,BJ=.5,IUn=({x:t,y:e,z:n})=>{const o=t>0;return Jn(ir,{children:[Ve(Wo,{offset:{x:t+.25/2,y:e,z:n},children:Ve(X_,{rotation:["-90deg",0,"90deg"],children:Ve(gH,{height:.25,children:Ve(mH,{points:CUn.slice().reverse().map(i=>[i.x,i.y])})})})}),Ve(Wo,{offset:{x:t,y:e+(o?1:-1),z:n},children:Ve(X_,{rotation:["-90deg","90deg",o?"180deg":"0deg"],children:Ve(gH,{height:2,children:Ve(mH,{points:bIe([[0,0],[-1,0],[-1,-1]],.25).map(i=>[i.x,i.y])})})})})]})},EUn=({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(ir,{children:[yUn(t).map(a=>{const c=a%i,l=(Math.floor(a/i)-.5)*2;return Ve(IUn,{x:l*r/2,y:c*e-(i-1)/2*e,z:Yht/2+BJ})}),Ve(J_,{width:s,length:i*e+.5,height:Yht-BJ,heightAboveSurface:BJ,center:{x:0,y:0,z:BJ}})]})};function bUn(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 Mr=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,bUn(A,t)]),l=bIe(c,e);return Ve(Er,{color:"#fff",children:Ve(Wo,{offset:{z:0,y:0,x:0,...t.position},children:Ve(X_,{rotation:["90deg",0,s??0],children:Ve(Wo,{offset:{x:0,y:0,z:-n/2},children:Ve(gH,{height:n,children:Ve(mH,{points:l.map(A=>[A.x,A.y])})})})})})})},SUn=({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),f=Math.min(Math.min(l,c)*.12,.45);return Jn(ir,{children:[Array.from({length:r}).map((y,x)=>Ve(Mr,{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((y,x)=>Ve(Mr,{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:f})]})},PUn=({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(ir,{children:[Array.from({length:r}).map((c,l)=>Ve(Mr,{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(Mr,{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})]})},SIe=1,PIe=.5,WD=.5,pH=.2,vUn=SIe-pH*2,Kht=({color:t="#333"})=>Jn(ir,{children:[Ve(ln,{size:[vUn,PIe,WD],offset:[0,0,WD/2],color:t}),Ve(ln,{size:[pH,WD,PIe],offset:[SIe/2-pH/2,0,WD/2],color:"#ccc"}),Ve(ln,{size:[pH,WD,PIe],offset:[-SIe/2+pH/2,0,WD/2],color:"#ccc"})]}),vIe=1.6,BUn=vIe-.3*2,MJ=.3,BIe=.85,jD=.6,Wht=({color:t="#333"})=>Jn(ir,{children:[Ve(ln,{size:[BUn,BIe,jD],offset:[0,0,jD/2],color:t}),Ve(ln,{size:[MJ,BIe,jD],offset:[vIe/2-MJ/2,0,jD/2],color:"#ccc"}),Ve(ln,{size:[MJ,BIe,jD],offset:[-vIe/2+MJ/2,0,jD/2],color:"#ccc"})]}),MIe=2,wIe=1.25,XD=.55,fH=.5,MUn=MIe-fH*2,jht=({color:t="#333"})=>Jn(ir,{children:[Ve(ln,{size:[MUn,wIe,XD],offset:[0,0,XD/2],color:t}),Ve(ln,{size:[fH,wIe,XD],offset:[MIe/2-fH/2,0,XD/2],color:"#ccc"}),Ve(ln,{size:[fH,wIe,XD],offset:[-MIe/2+fH/2,0,XD/2],color:"#ccc"})]}),wUn=({pinCount:t,pitch:e,leadWidth:n,padContactLength:o,bodyWidth:i})=>{const r=t/4;e||(e=DUn(t,i)),o||(o=TUn(t)),n||(n=QUn(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(ir,{children:[Array.from({length:r}).map((g,f)=>Ve(Mr,{position:{x:-u/2,y:f*e-c,z:h/2},width:n,thickness:h,padContactLength:m,bodyDistance:d,curveLength:p,height:_})),Array.from({length:r}).map((g,f)=>Ve(Mr,{rotation:Math.PI,position:{x:u/2,y:f*e-c,z:h/2},width:n,thickness:h,padContactLength:m,bodyDistance:d,curveLength:p,height:_})),Array.from({length:r}).map((g,f)=>Ve(Mr,{rotation:Math.PI/2,position:{x:f*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,f)=>Ve(Mr,{rotation:-Math.PI/2,position:{x:f*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})]})},DUn=(t,e)=>{switch(t){case 44:case 64:return .8;case 52:return e===14?1:.65;case 208:return .5;default:return .5}},TUn=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}},QUn=(t,e)=>{switch(t){case 44:case 64:return .5;case 52:return e===14?.45:.55;case 208:return .3;default:return .25}},Xht=({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(ir,{children:[Ve(Wo,{y:u?-3:0,children:Ve(ln,{color:"#222",size:[s,a,r],center:[t,e,c(r/2)]})}),!l&&Ve(Er,{color:"gold",children:A?Ve(Mr,{rotation:-Math.PI/2,position:{x:t,y:e+1,z:n/2},thickness:n,width:n,height:n,padContactLength:2,bodyDistance:3}):Jn(Ol,{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(Er,{color:"gold",children:Ve(Wo,{y:u?-3.9:0,z:u?1:0,children:Ve(X_,{rotation:u?[-Math.PI/2,0,0]:[0,0,0],children:Jn(Ol,{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)]})]})})})})]}),RUn=({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(ir,{children:Array.from({length:t},(p,g)=>{const f=Math.floor(g/A),y=g%A,x=h+y*e,I=((r-1)/2-f)*u;return Ve(Xht,{x,y:I,pinThickness:.63,shortSidePinLength:_,longSidePinLength:n,bodyHeight:2,flipZ:m,faceup:i,smd:s,rightangle:a},g)})})},NUn=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")}},kUn=({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},HUn=({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=kUn({num_pins:t,cw:!0,ccw:!0}),A=[];for(let u=0;u<t;u++){const{x:_,y:h,o:d}=NUn({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(ir,{children:[Ve(Er,{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]})]})},LUn=HUn,FUn=()=>{const c=1.1999999999999997;return Jn(ir,{children:[Ve(Mr,{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(Mr,{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(Mr,{position:{x:-2.8/2-c/4,y:0,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:c,height:.95}),Ve(Mr,{position:{x:-2.8/2-c/4,y:-1,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:c,height:.95}),Ve(Mr,{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})]})},OUn=FUn,GUn=({fullWidth:t=2.9,fullLength:e=2.8})=>{const A=(t-1.92)/2+.3;return Jn(ir,{children:[Ve(Mr,{rotation:Math.PI,position:{x:t/2,y:0,z:.075},width:.4,thickness:.15,padContactLength:.25,bodyDistance:A,height:.45}),Ve(Mr,{position:{x:-t/2,y:-.95,z:.075},width:.4,thickness:.15,padContactLength:.25,bodyDistance:A,height:.45}),Ve(Mr,{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})]})},DIe=.6,TIe=.3,JD=.33,yH=.1,zUn=DIe-yH*2,Jht=({color:t="#333"})=>Jn(ir,{children:[Ve(ln,{size:[zUn,TIe,JD],offset:[0,0,JD/2],color:t}),Ve(ln,{size:[yH,TIe,JD],offset:[DIe/2-yH/2,0,JD/2],color:"#ccc"}),Ve(ln,{size:[yH,TIe,JD],offset:[-DIe/2+yH/2,0,JD/2],color:"#ccc"})]}),QIe=.4,RIe=.2,qD=.13,xH=.07,UUn=QIe-xH*2,qht=({color:t="#333"})=>Jn(ir,{children:[Ve(ln,{size:[UUn,RIe,qD],offset:[0,0,qD/2],color:t}),Ve(ln,{size:[xH,RIe,qD],offset:[QIe/2-xH/2,0,qD/2],color:"#ccc"}),Ve(ln,{size:[xH,RIe,qD],offset:[-QIe/2+xH/2,0,qD/2],color:"#ccc"})]}),NIe=3.2,kIe=1.6,$D=.9,CH=.5,VUn=NIe-CH*2,$ht=({color:t="#333"})=>Jn(ir,{children:[Ve(ln,{size:[VUn,kIe,$D],offset:[0,0,$D/2],color:t}),Ve(ln,{size:[CH,kIe,$D],offset:[NIe/2-CH/2,0,$D/2],color:"#ccc"}),Ve(ln,{size:[CH,kIe,$D],offset:[-NIe/2+CH/2,0,$D/2],color:"#ccc"})]}),HIe=3.2,LIe=2.5,ZD=1,IH=.6,YUn=HIe-IH*2,Zht=({color:t="#333"})=>Jn(ir,{children:[Ve(ln,{size:[YUn,LIe,ZD],offset:[0,0,ZD/2],color:t}),Ve(ln,{size:[IH,LIe,ZD],offset:[HIe/2-IH/2,0,ZD/2],color:"#ccc"}),Ve(ln,{size:[IH,LIe,ZD],offset:[-HIe/2+IH/2,0,ZD/2],color:"#ccc"})]}),FIe=5,OIe=2.5,e7=1.4,EH=.6,KUn=FIe-EH*2,emt=({color:t="#333"})=>Jn(ir,{children:[Ve(ln,{size:[KUn,OIe,e7],offset:[0,0,e7/2],color:t}),Ve(ln,{size:[EH,OIe,e7],offset:[FIe/2-EH/2,0,e7/2],color:"#ccc"}),Ve(ln,{size:[EH,OIe,e7],offset:[-FIe/2+EH/2,0,e7/2],color:"#ccc"})]}),GIe=6.3,zIe=3.2,t7=1.8,bH=.8,WUn=GIe-bH*2,tmt=({color:t="#333"})=>Jn(ir,{children:[Ve(ln,{size:[WUn,zIe,t7],offset:[0,0,t7/2],color:t}),Ve(ln,{size:[bH,zIe,t7],offset:[GIe/2-bH/2,0,t7/2],color:"#ccc"}),Ve(ln,{size:[bH,zIe,t7],offset:[-GIe/2+bH/2,0,t7/2],color:"#ccc"})]}),nmt=({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(ir,{children:[Ve(Er,{color:"#1a1a1a",children:Jn(gf,{children:[Ve(ln,{color:"#000",size:[a,c,s],center:[t,e,l(n+s/2)]}),r?Ve(al,{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(Er,{color:"silver",children:[Jn(Ol,{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)]})]})]})},jUn=({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(ir,{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(nmt,{x:m,y:p,pitch:e,legsLength:n,innerDiameter:o,flipZ:A},_)})})},XUn=({width:t,length:e,innerDiameter:n=1})=>{const o=t,i=e,r=t*.7,s=n/2.5;return Jn(ir,{children:[Ve(hH,{color:"#1a1a1f",center:[0,0,r/2],size:[i,i,r],roundRadius:.3}),Ve(hH,{color:"#f2f2f2",center:[0,0,r+r*.1/2.5],size:[i,i,r*.1],roundRadius:.14}),Ve(al,{color:"#1a1a1f",height:r*.8,radius:o/3,center:[0,0,r+r*.8/2]}),Ve(al,{color:"#1a1a1f",height:r*.2,radius:n/2,center:[i/3,i/3,r+r*.1/2]}),Ve(al,{color:"#1a1a1f",height:r*.2,radius:n/2,center:[-i/3,-i/3,r+r*.1/2]}),Ve(al,{color:"#1a1a1f",height:r*.2,radius:n/2,center:[-i/3,i/3,r+r*.1/2]}),Ve(al,{color:"#1a1a1f",height:r*.2,radius:n/2,center:[i/3,-i/3,r+r*.1/2]}),Ve(wJ,{thickness:n/3,width:s,horizontalLength:i*.8,verticalLength:r/2,position:{x:-o/2,y:-i/2,z:-r*1.2}}),Ve(wJ,{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(wJ,{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(wJ,{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}})]})},wJ=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=bIe(a,e);return Ve(Er,{color:"#f2f2f2",children:Ve(Wo,{offset:{x:s?.x||0,y:s?.y||0,z:s?.z||0},children:Ve(X_,{rotation:[0,55,r],children:Ve(gH,{height:n,children:Ve(mH,{points:c.map(l=>[l.y,l.x])})})})})})},JUn=({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(ir,{children:[Array.from({length:r}).map((h,d)=>Ve(Mr,{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(Mr,{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})]})},qUn=({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(ir,{children:[Array.from({length:u}).map((f,y)=>Ve(Mr,{position:{x:-m/2,y:_-y*a,z:h/2},width:c,thickness:h,padContactLength:g+.05,bodyDistance:p+.1,height:d})),Array.from({length:u}).map((f,y)=>Ve(Mr,{rotation:Math.PI,position:{x:m/2,y:_-y*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})]})},$Un=()=>Jn(ir,{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(Er,{color:"#222",children:Jn(Sh,{children:[Ve(Wo,{z:.3/2,children:Ve(ln,{size:[1.65,.8,.3]})}),Jn(Ol,{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]})})]})]})})]}),ZUn=()=>Jn(ir,{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(Er,{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]})]}),eVn=()=>{const l=Ve(Er,{color:"#1a1a1a",children:Jn(Sh,{children:[Jn(Ol,{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(Ol,{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),f=(m+p)/2;return Ve(Er,{color:"#c0c0c0",children:Jn(Sh,{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:[f,0,.2/2+1.14]})]})})};return Jn(ir,{children:[Ve(A,{xDir:1}),Ve(A,{xDir:-1}),l]})},tVn=()=>{const l=Ve(Er,{color:"#1a1a1a",children:Jn(Sh,{children:[Jn(Ol,{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(Ol,{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),f=(m+p)/2;return Ve(Er,{color:"#c0c0c0",children:Jn(Sh,{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:[f,0,.2/2+1.14]})]})})};return Jn(ir,{children:[Ve(A,{xDir:1}),Ve(A,{xDir:-1}),l]})},nVn=()=>{const l=Ve(Er,{color:"#1a1a1a",children:Jn(Sh,{children:[Jn(Ol,{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(Ol,{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),f=(m+p)/2;return Ve(Er,{color:"#c0c0c0",children:Jn(Sh,{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:[f,0,.2/2+1.14]})]})})};return Jn(ir,{children:[Ve(A,{xDir:1}),Ve(A,{xDir:-1}),l]})},oVn=()=>{const u=Ve(Er,{color:"#222",children:Jn(Sh,{children:[Ve(Wo,{z:.27,children:Ve(ln,{size:[2.9,1.9,.54]})}),Jn(Ol,{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(ir,{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]})},iVn=()=>Jn(ir,{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(Er,{color:"#222",children:Jn(Sh,{children:[Ve(Wo,{z:.55/2,children:Ve(ln,{size:[2.7,1.6,.55]})}),Jn(Ol,{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]})})]})]})})]}),rVn=()=>Jn(ir,{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(Er,{color:"#222",children:Jn(Sh,{children:[Ve(Wo,{z:.2/2,children:Ve(ln,{size:[2.75,1.8,.2]})}),Jn(Ol,{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]})]}),sVn=()=>Jn(ir,{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(Er,{color:"#222",children:Jn(Sh,{children:[Jn(Ol,{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(Ol,{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]})]}),aVn=()=>Jn(ir,{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(Er,{color:"#222",children:Jn(Sh,{children:[Jn(Ol,{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(Ol,{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]})]}),cVn=()=>Jn(ir,{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(Er,{color:"#222",children:Jn(Sh,{children:[Ve(Wo,{z:.14/2,children:Ve(ln,{size:[.8,.6,.14]})}),Jn(Ol,{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]})})]})]})})]}),lVn=()=>{const A=3.0999999999999996;return Jn(ir,{children:[Ve(Mr,{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(Mr,{position:{x:-6.6/2-A/4,y:0,z:.25/2},width:.7,thickness:.25,padContactLength:.5,bodyDistance:A,height:.75}),Ve(Mr,{position:{x:-6.6/2-A/4,y:-2.3,z:.25/2},width:.7,thickness:.25,padContactLength:.5,bodyDistance:A,height:.75}),Ve(Mr,{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})]})},AVn=()=>Jn(ir,{children:[Array.from({length:16}).map((h,d)=>Ve(Mr,{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(Mr,{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(Mr,{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(Mr,{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})]}),uVn=AVn,_Vn=()=>{const l=.7999999999999998;return Jn(ir,{children:[Ve(Mr,{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(Mr,{position:{x:-2.05/2-l/4,y:-.65,z:.18/2},width:.3,thickness:.18,padContactLength:.2,bodyDistance:l,height:.65}),Ve(Mr,{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})]})},dVn=({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(ir,{children:[Array.from({length:r}).map((h,d)=>Ve(Mr,{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(Mr,{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(Mr,{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(Mr,{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})]})},hVn=()=>{const o=.20900000000000002,i=.1,r=.3,s=.1,a=.2;return Jn(ir,{children:[Ve(Er,{color:"#222",children:Jn(Sh,{children:[Ve(ln,{size:[.85,1.2,o],center:[0,0,o/2]}),Jn(Ol,{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]})]})},mVn=({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,f=h==="left"?-e/2+p/2:e/2-p/2,y=_+1;l.push({pinNumber:y,x:f,y:m,padSizeX:p,padSizeY:g})}return Jn(ir,{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]})]})},gVn=({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(ir,{children:[Jn(Er,{color:s,children:[Jn(Ol,{children:[Ve(U2,{height:n,roundRadius:.5,radius:l,center:[-A,0,n]}),Ve(U2,{height:n,roundRadius:.5,radius:l,center:[A,0,n]})]}),Jn(Ol,{children:[Ve(U2,{height:_,roundRadius:.1,radius:l+.85,center:[-A,0,n/2+_/2]}),Ve(U2,{height:_,roundRadius:.1,radius:l+.85,center:[A,0,n/2+_/2]})]})]}),Jn(Er,{color:a,children:[Ve(al,{height:r+n/2,radius:i/2,center:[-u+.06,0,-(r/2)+n/2]}),Ve(al,{height:r+n/2,radius:i/2,center:[u-.06,0,-(r/2)+n/2]})]})]})},pVn=({bodyLength:t=1.4,bodyDiameter:e=1.1,color:n="#3a3a3aff",contactColor:o="#c6c6c6",cathodeIdentification:i="#111"})=>Jn(ir,{children:[Ve(Er,{color:n,children:Jn(X_,{rotation:[0,"90deg",0],children:[Ve(hH,{size:[e,e,t-.2],roundRadius:.2,center:[-e/2,0,.05]}),Ve(al,{height:.2/2,radius:e/2-.2,center:[-e/2,0,-t/2+.2/2]})]})}),Ve(Er,{color:i,children:Ve(X_,{rotation:[0,"90deg",0],children:Ve(hH,{size:[e*1.01,e*1.01,t/3],roundRadius:.2,center:[-e/2,0,-t/4+.1]})})}),Ve(Er,{color:o,children:Ve(X_,{rotation:[0,"90deg",0],children:Ve(U2,{height:.2,radius:e/2,roundRadius:.2/3,center:[-e/2,0,-t/2]})})}),Ve(Er,{color:o,children:Ve(X_,{rotation:[0,"90deg",0],children:Ve(U2,{height:.2,radius:e/2,roundRadius:.2/3,center:[-e/2,0,t/2]})})})]}),fVn=({bodyLength:t=3.5,bodyDiameter:e=1.5,color:n="#3a3a3aff",contactColor:o="#c6c6c6"})=>Jn(ir,{children:[Ve(Er,{color:n,children:Ve(X_,{rotation:[0,"90deg",0],children:Ve(U2,{height:t,radius:e/2,roundRadius:.3,center:[-e/2,0,0]})})}),Ve(Er,{color:o,children:Ve(X_,{rotation:[0,"90deg",0],children:Ve(U2,{height:.5,radius:e/2,roundRadius:.2,center:[-e/2,0,-t/2]})})}),Ve(Er,{color:o,children:Ve(X_,{rotation:[0,"90deg",0],children:Ve(U2,{height:.5,radius:e/2,roundRadius:.2,center:[-e/2,0,t/2]})})})]}),yVn=({bodyLength:t=3.9,bodyDiameter:e=2.5,color:n="#3a3a3aff",contactColor:o="#c6c6c6"})=>Jn(ir,{children:[Ve(Er,{color:n,children:Ve(X_,{rotation:[0,"90deg",0],children:Ve(U2,{height:t,radius:e/2,roundRadius:.3,center:[-e/2,0,0]})})}),Ve(Er,{color:o,children:Ve(X_,{rotation:[0,"90deg",0],children:Ve(U2,{height:.55,radius:e/2,roundRadius:.2,center:[-e/2,0,-t/2]})})}),Ve(Er,{color:o,children:Ve(X_,{rotation:[0,"90deg",0],children:Ve(U2,{height:.55,radius:e/2,roundRadius:.2,center:[-e/2,0,t/2]})})})]}),xVn=({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(ir,{children:[Array.from({length:i}).map((l,A)=>Ve(Mr,{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(Mr,{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})]})},CVn=({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(ir,{children:[Array.from({length:i}).map((l,A)=>Ve(Mr,{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(Mr,{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})]})},IVn=()=>{const m=7.050000000000001,p=24.95+6.5/2;return Ve(Wo,{center:[0,0,1],children:Jn(ir,{children:[Jn(X_,{rotation:[0,55,-55],children:[Jn(gf,{children:[Ve(ln,{color:"#ccc",size:[6.5+.1,9.9,1.3],center:[p,0,1.3-2]}),Ve(al,{color:"black",center:[p,0,1.3-2],radius:3/2,height:1.3*1.2})]}),Ve(Er,{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(X_,{rotation:[0,55,55],children:Array.from({length:3}).map((g,f)=>{const y=m,x=(f-1)*2.7,I=-.5-.6;return Jn(Er,{color:"gold",children:[Jn(Ol,{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:[y,x,I],children:Ve(ln,{size:[16+.1,.81,.5]})})]},`prong-${f}`)})})]})})},EVn=()=>{const l=1.1999999999999997;return Jn(ir,{children:[Ve(Mr,{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(Mr,{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(Mr,{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(Mr,{position:{x:-2.8/2-l/4,y:0,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:l,height:.95}),Ve(Mr,{position:{x:-2.8/2-l/4,y:-.95,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:l,height:.95}),Ve(Mr,{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})]})},bVn=()=>Jn(ir,{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]})})]}),SVn=()=>{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(Er,{color:s,children:Jn(gf,{children:[Ve(Wo,{center:[0,0,2.25],children:Ve(al,{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(Ol,{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]})})]})},PVn=()=>Jn(ir,{children:[Ve(Mr,{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(Mr,{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(Mr,{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(Mr,{position:{x:-2/2-.75/4,y:0,z:.15/2},width:.25,thickness:.15,padContactLength:.3,bodyDistance:.75,height:.85}),Ve(Mr,{position:{x:-2/2-.75/4,y:-.65,z:.15/2},width:.25,thickness:.15,padContactLength:.3,bodyDistance:.75,height:.85}),Ve(Mr,{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})]}),vVn=PVn,BVn=()=>Jn(ir,{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]})})]}),MVn=()=>Jn(ir,{children:[Ve(Mr,{position:{x:-2.5/2,y:0,z:.175/2},width:.3,thickness:.175,padContactLength:.3,bodyDistance:.45,height:.7}),Ve(Mr,{rotation:Math.PI,position:{x:2.5/2,y:0,z:.175/2},width:.3,thickness:.175,padContactLength:.3,bodyDistance:.45,height:.7}),Ve(Er,{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]})]}),wVn=()=>Jn(ir,{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(Er,{color:"#222",children:Jn(Sh,{children:[Ve(Wo,{z:.175/2,children:Ve(ln,{size:[1.7,1.25,.175]})}),Jn(Ol,{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]})]}),DVn=()=>{const s=-1.0474999999999999,a=1.775/2+.4/2-.04;return Jn(ir,{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(Er,{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]})]})},TVn=({pitch:t=10})=>Jn(ir,{children:[Ve(al,{height:4,radius:.5,center:[-t/2,0,.5]}),Ve(vJ,{radius:.5,center:[-t/2,0,2.5]}),Ve(Wo,{x:-2.5,y:0,z:2.5,children:Jn(X_,{rotation:[0,Math.PI/2,0],children:[Ve(al,{height:t,radius:.5,center:[0,0,2.5]}),Ve(Er,{color:"#d2b48c",children:Ve(al,{height:5,radius:1.3,center:[0,0,2.5]})})]})}),Ve(al,{height:4,radius:.5,center:[t/2,0,.5]}),Ve(vJ,{radius:.5,center:[t/2,0,2.5]})]}),QVn=({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=[],f=[];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&&f.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&&f.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&&f.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&&f.push({x:-P,y:-p/2},{x:-P,y:-p/2+A})}}const y=Ve(Er,{color:"#051a0a",children:Jn(gf,{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&&f.map((E,b)=>Ve(al,{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(ir,{children:[y,Ve(Er,{color:"#FFD700",children:l?Jn(gf,{children:[Ve(Sh,{children:g.map((E,b)=>Ve(ln,{center:[E.x,E.y,h],size:[E.pl+.01,E.pw+.01,d]},b))}),x]}):I})]})},RVn=({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),f=Math.min(Math.max(h*.6,.2),h),y=l?.x??0,x=l?.y??0,I=l?.z??0;return Jn(Wo,{offset:{x:y,y:x,z:I},children:[d>0&&Ve(Er,{color:s,children:Ve(ln,{size:[A,u,d],offset:[0,0,d/2]})}),Ve(Er,{color:s,children:Jn(gf,{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(Er,{color:r,children:Ve(ln,{size:[p,g,f],offset:[0,0,d+f/2]})})]})},NVn=({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:f})=>{const y=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,L=0,F=0,G=0,W=0;c==="left"||c==="right"?(k=c==="left"?-P/2+u:P/2-u,N=-((I-1)/2)*n,L=0,F=n,G=c==="left"?n:-n,W=0):(k=-((I-1)/2)*n,N=c==="top"?B/2-u:-B/2+u,L=n,F=0,G=0,W=c==="top"?-n:n);let J=0;for(let le=0;le<e&&J<t;le++)for(let Ie=0;Ie<I&&J<t;Ie++){const pe=k+Ie*L+le*G,ke=N+Ie*F+le*W;w.push({x:pe,y:ke}),J++}const $=[];if(l)for(const le of l){let Ie=0,pe=0;le==="topleft"?(Ie=-P/2+A,pe=B/2-A):le==="topright"?(Ie=P/2-A,pe=B/2-A):le==="bottomleft"?(Ie=-P/2+A,pe=-B/2+A):le==="bottomright"?(Ie=P/2-A,pe=-B/2+A):le==="center"&&(Ie=0,pe=0),$.push({x:Ie,y:pe})}const oe=.63,Ae=2,ee=6,ie=3,ae=h||_?0:Ae,re=ae+r,_e=Ve(Er,{color:"#008080",children:Jn(gf,{children:[Ve(ln,{center:[0,0,x+ae],size:[P,B,r]}),$.map((le,Ie)=>Ve(al,{center:[le.x,le.y,x+ae],radius:i/2,height:r},`hole-${Ie}`)),w.map((le,Ie)=>Ve(al,{center:[le.x,le.y,x+ae],radius:i/2,height:r},`pin-hole-${Ie}`))]})}),xe=w.map((le,Ie)=>Ve(Er,{color:"#FFD700",children:Jn(gf,{children:[Ve(al,{center:[le.x,le.y,r/2+ae],radius:i/2,height:r}),Ve(al,{center:[le.x,le.y,r/2+ae],radius:o/2,height:r})]})})),be=w.map((le,Ie)=>Ve(Xht,{x:le.x,y:le.y,pinThickness:oe,shortSidePinLength:ie,longSidePinLength:ee,bodyHeight:Ae,flipZ:pe=>pe})),ve=w.map((le,Ie)=>Ve(nmt,{x:le.x,y:le.y,flipZ:pe=>-pe}));return Jn(ir,{children:[_e,xe,!_&&!h&&be,_&&ve,y&&Ve(RVn,{width:m??P*.8,height:p??B*.6,offset:{x:g??0,y:f??0,z:re}})]})},kVn=()=>{const s=.8999999999999999,a=-s/2+.5/2-.15,c=s/2-.5/2+.15,l=.2,A=.5*.24;return Jn(ir,{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(Er,{color:"#222",children:Jn(Sh,{children:[Ve(Wo,{z:A/2,children:Ve(ln,{size:[s,.6,A]})}),Jn(Ol,{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]})]})},HVn=kVn,LVn=({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(ir,{children:[Ve(Wo,{offset:[0,0,6],children:Ve(X_,{angles:[Math.PI,0,0],children:Ve(Er,{color:o,children:Jn(gf,{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(Er,{color:i,children:Ve(al,{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(fUn,{hole:p,isPin1:m})})]})},FVn=({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=pUn.string(e).json();switch(n.fn){case"dip":return Ve(EUn,{numPins:n.num_pins,pitch:n.p,bodyWidth:n.w});case"axial":return Ve(TVn,{pitch:n.p});case"tssop":return Ve(SUn,{pinCount:n.num_pins,leadLength:n.pl,leadWidth:n.pw,pitch:n.p,bodyWidth:n.w});case"msop":return Ve(PUn,{pinCount:n.num_pins,padContactLength:n.pl,leadWidth:n.pw,pitch:n.p,bodyWidth:n.w});case"vssop":return Ve(qUn,{pinCount:n.num_pins,leadLength:n.pl,leadWidth:n.pw,pitch:n.p,bodyWidth:n.w,bodyLength:n.h});case"qfp":return Ve(wUn,{pinCount:n.num_pins,pitch:n.p,leadWidth:n.pw,padContactLength:n.pl,bodyWidth:n.w});case"tqfp":return Ve(uVn,{});case"lqfp":return Ve(dVn,{pinCount:n.num_pins});case"qfn":{const r=typeof n.thermalpad?.x=="number"&&typeof n.thermalpad?.y=="number";return Ve(LUn,{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(mVn,{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(RUn,{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(jUn,{numberOfPins:n.num_pins,pitch:n.p,rows:s})}case"cap":switch(n.imperial){case"0402":return Ve(Kht,{color:"#856c4d"});case"0603":return Ve(Wht,{color:"#856c4d"});case"0805":return Ve(jht,{color:"#856c4d"});case"0201":return Ve(Jht,{color:"#856c4d"});case"01005":return Ve(qht,{color:"#856c4d"});case"1206":return Ve($ht,{color:"#856c4d"});case"1210":return Ve(Zht,{color:"#856c4d"});case"2010":return Ve(emt,{color:"#856c4d"});case"2512":return Ve(tmt,{color:"#856c4d"})}case"sot235":return Ve(OUn,{});case"sot457":return Ve(EVn,{});case"sot223":return Ve(lVn,{});case"sot23w":return Ve(GUn,{});case"sot323":return Ve(_Vn,{});case"sod323f":return Ve(wVn,{});case"sod323fl":return Ve(DVn,{});case"sot363":return Ve(vVn,{});case"sot886":return Ve(BVn,{});case"sot963":return Ve(bVn,{});case"pushbutton":return Ve(XUn,{width:n.w,length:n.h,innerDiameter:n.id});case"jst":if(n.zh)return Ve(LVn,{numPins:n.num_pins});break;case"soic":return Ve(JUn,{pinCount:n.num_pins,leadLength:n.pl,leadWidth:n.pw,pitch:n.p,bodyWidth:n.w});case"sod523":return Ve($Un,{});case"sod723":return Ve(HVn,{});case"sod882":return Ve(ZUn,{});case"sma":return Ve(eVn,{});case"smb":return Ve(tVn,{});case"smc":return Ve(nVn,{});case"smf":return Ve(oVn,{});case"sod123f":return Ve(iVn,{});case"sod123fl":return Ve(rVn,{});case"sod123w":return Ve(sVn,{});case"sod128":return Ve(aVn,{});case"sod323":return Ve(MVn,{});case"sod923":return Ve(cVn,{});case"hc49":return Ve(gVn,{});case"micromelf":return Ve(pVn,{});case"minimelf":return Ve(fVn,{});case"melf":return Ve(yVn,{});case"ms012":return Ve(xVn,{pinCount:n.num_pins,padContactLength:n.pl,leadWidth:n.pw,pitch:n.p});case"ms013":return Ve(CVn,{pinCount:n.num_pins,padContactLength:n.pl,leadWidth:n.pw,pitch:n.p});case"sot723":return Ve(hVn,{});case"to220":return Ve(IVn,{});case"to92":return Ve(SVn,{});case"stampboard":case"stampreceiver":return Ve(QVn,{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(NVn,{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(Kht,{color:i});case"0603":return Ve(Wht,{color:i});case"0805":return Ve(jht,{color:i});case"0201":return Ve(Jht,{color:i});case"01005":return Ve(qht,{color:i});case"1206":return Ve($ht,{color:i});case"1210":return Ve(Zht,{color:i});case"2010":return Ve(emt,{color:i});case"2512":return Ve(tmt,{color:i})}return null},OVn=t=>t&&typeof t=="object"&&"type"in t,n7=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},GVn=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 h3(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(_=>h3(_,e,n));if(!OVn(t))return[];const{type:l,props:A,children:u}=t;if(l===Uht)return(u??[]).flatMap(_=>h3(_,e,n));if(l===Er){const _=A?.color;return(u??[]).flatMap(h=>h3(h,_??e,n))}if(l===Wo){const _=GVn(A?.offset??A?.center??{x:A?.x,y:A?.y,z:A?.z});return(u??[]).flatMap(d=>h3(d,e,n)).map(({geom:d,color:m})=>({geom:c.translate(_,d),color:m??e}))}if(l===X_){const _=Array.isArray(A?.rotation)?[n7(A.rotation[0]),n7(A.rotation[1]),n7(A.rotation[2])]:[n7(A?.x??0),n7(A?.y??0),n7(A?.z??0)];return(u??[]).flatMap(d=>h3(d,e,n)).map(({geom:d,color:m})=>({geom:c.rotateZ(_[2],c.rotateY(_[1],c.rotateX(_[0],d))),color:m}))}if(l===Sh||l===gf||l===Ol){const _=(u??[]).flatMap(d=>h3(d,e,n)).map(d=>d.geom);if(_.length===0)return[];let h;return l===Sh?h=i.union(_):l===gf?h=i.subtract(_[0],_.slice(1)):h=r.hull(_),[{geom:h,color:e}]}if(l===mH){const _=A?.points??[];return[{geom:s.geom2.fromPoints(_),color:e??A?.color}]}if(l===gH){const _=(u??[]).flatMap(p=>h3(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===Vht||l===al||l===vJ||l===hH||l===U2){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===Vht){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===al){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===vJ){const h=A?.radius??1,d=A?.center??[0,0,0];_=o.sphere({radius:h,center:d})}else if(l===U2){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 h3(_,e,n)}return(u??[]).flatMap(_=>h3(_,e,n))}function zVn(t,e){return{geometries:h3(t,void 0,{jscad:e})}}function omt(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 _A;if(r.setAttribute("position",new nu(new Float32Array(e),3)),r.setIndex(n),o.length>0&&r.setAttribute("color",new nu(new Float32Array(o),3)),t.transforms){const s=new Cs;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 _A;if(o.setAttribute("position",new nu(new Float32Array(e),3)),n.length>0&&o.setAttribute("color",new nu(new Float32Array(n),3)),t.transforms){const i=new Cs;i.fromArray(t.transforms),o.applyMatrix4(i)}return o}return console.error("Invalid CSG object: neither polygons nor sides found"),new _A}function UVn(t,e){const n=EIe(FVn,{footprint:t});return zVn(n,e)}var VVn=bl(fJ()),imt=j.createContext(null),YVn=()=>{const t=j.useContext(imt);if(!t)throw new Error("useHover must be used within a HoverProvider");return t},KVn=({children:t})=>{const{camera:e,renderer:n}=C1(),[o,i]=j.useState([]),r=j.useMemo(()=>new evn,[]),s=j.useMemo(()=>new Ui,[]),a=j.useRef(o);a.current=o;const c=j.useRef(null),l=j.useCallback(d=>{i(m=>[...m,d])},[]),A=j.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=j.useCallback(d=>{let m=d;for(;m;){const p=a.current.find(g=>g.object===m);if(p)return p;m=m.parent}},[]),_=j.useCallback(d=>{if(!n.domElement)return;const m=n.domElement.getBoundingClientRect();s.x=(d.clientX-m.left)/m.width*2-1,s.y=-((d.clientY-m.top)/m.height)*2+1,r.setFromCamera(s,e);const p=a.current.map(f=>f.object);if(p.length===0){c.current&&(c.current.onUnhover(),c.current=null);return}const g=r.intersectObjects(p,!0);if(g.length>0){const f=g[0],y=u(f.object);if(y){const x={mousePosition:[f.point.x,f.point.y,f.point.z]};c.current!==y?(c.current?.onUnhover(),y.onHover(x),c.current=y):y.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]);j.useEffect(()=>{const d=n.domElement;return d.addEventListener("mousemove",_),()=>{d.removeEventListener("mousemove",_)}},[n,_]);const h=j.useMemo(()=>({addHoverable:l,removeHoverable:A}),[l,A]);return K.jsx(imt.Provider,{value:h,children:t})},WVn=({children:t,object:e,onHover:n,onUnhover:o,isHovered:i})=>{const{addHoverable:r,removeHoverable:s}=YVn();return j.useEffect(()=>e?(r({object:e,onHover:n,onUnhover:o}),()=>{s(e)}):void 0,[e,n,o,r,s]),K.jsx(K.Fragment,{children:t})},SH=WVn,jVn=({positionOffset:t,footprint:e,rotationOffset:n,onHover:o,onUnhover:i,isHovered:r,scale:s,isTranslucent:a=!1})=>{const{rootObject:c}=C1(),l=j.useMemo(()=>{if(!e)return null;const{geometries:A}=UVn(e,VVn),u=new rg;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=omt(m),g=new op({vertexColors:!0,side:am,transparent:a,opacity:a?.5:1,depthWrite:!a}),f=new Tr(p,g);f.renderOrder=a?2:1,u.add(f)}return u},[e,a]);return j.useEffect(()=>{if(!(!l||!c))return c.add(l),()=>{c.remove(l)}},[c,l]),j.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]),j.useEffect(()=>{l&&l.traverse(A=>{A instanceof Tr&&A.material instanceof op&&(r?(A.material.emissive.setHex(255),A.material.emissiveIntensity=.2):A.material.emissiveIntensity=0)})},[r,l]),l?K.jsx(SH,{isHovered:r,onHover:o,onUnhover:i,object:l}):null},rmt=new WeakMap,XVn=()=>{const t=new Mu;return t.name="fallback-environment-map",t.mapping=Pj,t},JVn=t=>{if(!t)return null;const e=t,n=rmt.get(e);if(n)return n;let o;if(t instanceof iX){const i=new fme(t);o=i.fromScene(bvn(),.04).texture,i.dispose()}else o=XVn();return rmt.set(e,o),o};function qVn(t){const e=new yC;let n=!1;t.updateWorldMatrix(!0,!1);const o=t.parent?t.parent.matrixWorld.clone().invert():new Cs;return t.traverse(i=>{if(i.updateWorldMatrix(!0,!1),i instanceof Tr&&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 $Vn(t){const e=qVn(t);return e?e.getSize(new Dt):new Dt}function ZVn(t,e,n="contain_within_bounds"){if(!e)return[1,1,1];const o=$Vn(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 UIe=({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}=C1(),A=j.useMemo(()=>new rg,[]),u=j.useMemo(()=>new rg,[]),_=j.useMemo(()=>new rg,[]),h=j.useMemo(()=>new rg,[]);return j.useEffect(()=>(A.add(u),()=>{A.remove(u)}),[A,u]),j.useEffect(()=>(u.add(_),()=>{u.remove(_)}),[u,_]),j.useEffect(()=>(_.add(h),()=>{_.remove(h)}),[_,h]),j.useEffect(()=>{for(;h.children.length>0;){const d=h.children[0];if(!d)break;h.remove(d)}t&&h.add(t)},[h,t]),j.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]),j.useEffect(()=>{if(l)return l.add(A),()=>{l.remove(A)}},[l,A]),j.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=ZVn(_,s,a);u.scale.set(d[0],d[1],d[2])},[A,u,t,a,o,h,_,i,s,e,n,c]),{boardTransformGroup:A}},smt=1.25;function amt({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}=C1(),[d,m]=j.useState(null),[p,g]=j.useState(null),{boardTransformGroup:f}=UIe({model:d,position:e,rotation:n,modelOffset:o,modelRotation:i,sourceCoordinateTransform:r,modelSize:s,modelFitMode:a,scale:u});if(j.useEffect(()=>{if(!t)return;const y=new Pvn;let x=!0;return y.load(t,I=>{if(!x)return;const E=I.scene;E.traverse(b=>{if(b instanceof Tr&&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,_]),j.useEffect(()=>{if(!d||!h)return;const y=JVn(h);if(!y)return;const x=[],I=E=>{E instanceof op&&(x.push({material:E,envMap:E.envMap??null,envMapIntensity:E.envMapIntensity??1}),E.envMap=y,(typeof E.envMapIntensity!="number"||E.envMapIntensity<smt)&&(E.envMapIntensity=smt),E.needsUpdate=!0)};return d.traverse(E=>{if(!(E instanceof Tr))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]),j.useEffect(()=>{d&&d.traverse(y=>{y instanceof Tr&&y.material instanceof op&&(A?(y.material.emissive.setHex(255),y.material.emissiveIntensity=.2):y.material.emissiveIntensity=0)})},[A,d]),p)throw p;return d?K.jsx(SH,{isHovered:A,onHover:c,onUnhover:l,object:f}):null}var eYn=bl(uht()),tYn=bl(fJ()),nYn=({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}=j.useMemo(()=>{const g=(0,eYn.executeJscadOperations)(tYn.default,t);if(!g||!g.polygons&&!g.sides)return{threeGeom:null,material:null};const f=omt(g),y=new op({vertexColors:!0,side:am,transparent:_,opacity:_?.5:1,depthWrite:!_});return{threeGeom:f,material:y}},[t,_]),m=j.useMemo(()=>{if(!h)return null;const g=new Tr(h,d);return g.renderOrder=_?2:1,g},[h,d,_]),{boardTransformGroup:p}=UIe({model:m,position:e,rotation:n,modelOffset:o,modelRotation:i,sourceCoordinateTransform:r,modelSize:s,modelFitMode:a,scale:u});return j.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?K.jsx(SH,{isHovered:A,onHover:c,onUnhover:l,object:p}):null};function oYn(t){return t.replace(/(DEF|USE)\s+([^\s]+)/g,(e,n,o)=>`${n} ${o.replace(/-/g,"_")}`)}async function iYn(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 u6n().parse(oYn(n),t)}typeof window<"u"&&!window.TSCIRCUIT_OBJ_LOADER_CACHE&&(window.TSCIRCUIT_OBJ_LOADER_CACHE=new Map);function rYn(t){const[e,n]=j.useState(null);return j.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 iYn(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 x6n;if(A?.length){const _=A.join(`
|
|
5201
|
-
`).replace(/d 0\./g,"d 1."),h=l.replace(/newmtl[\s\S]*?endmtl/g,"").replace(/^mtllib.*/gm,""),d=new c6n;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 sYn({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=rYn(t),d=j.useMemo(()=>h&&!(h instanceof Error)?(h.traverse(p=>{if(p instanceof Tr&&p.material){const g=f=>{f.transparent=_,f.opacity=_?.5:1,f.depthWrite=!_,f.needsUpdate=!0};Array.isArray(p.material)?p.material.forEach(g):g(p.material),p.renderOrder=_?2:1}}),h):new Tr(new Q5(.5,.5,.5),new op({transparent:!0,color:"red",opacity:.25})),[h,_]),{boardTransformGroup:m}=UIe({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 K.jsx(SH,{isHovered:A,onHover:c,onUnhover:l,object:m})}var VIe,aYn="https://cdn.jsdelivr.net/npm/occt-import-js@0.0.23/dist";function cYn(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 lYn(){if(!VIe){const t=await import("https://cdn.jsdelivr.net/npm/occt-import-js@0.0.23/+esm");VIe=cYn(t)({locateFile:n=>`${aYn}/${n}`})}return VIe}function AYn(t){const e=new rg;for(const n of t){const o=n.attributes.position?.array??[],i=n.index?.array??[];if(!o.length||!i.length)continue;const r=new _A;r.setAttribute("position",new Is(o,3));const s=n.attributes.normal?.array??[];s.length?r.setAttribute("normal",new Is(s,3)):r.computeVertexNormals(),r.setIndex(i);const a=new op({color:n.color?new xi(n.color[0],n.color[1],n.color[2]):new xi(.82,.82,.82)}),c=new Tr(r,a);c.name=n.name,e.add(c)}return e}async function uYn(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 lYn()).ReadStepFile(new Uint8Array(n),null);if(!i.success||!i.meshes.length)throw new Error("occt-import-js failed to convert STEP file");const r=AYn(i.meshes),s=new Xme;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 cmt="step-glb-cache:";function _Yn(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 dYn(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 hYn(t){try{const e=localStorage.getItem(`${cmt}${t}`);return e?dYn(e):null}catch(e){return console.warn("Failed to read STEP GLB cache",e),null}}function lmt(t,e){try{const n=_Yn(e);localStorage.setItem(`${cmt}${t}`,n)}catch(n){console.warn("Failed to write STEP GLB cache",n)}}function mYn(){const t=globalThis;return t.stepUrlToGltfModelConversions||(t.stepUrlToGltfModelConversions={inProgress:new Map,completed:new Map}),t.stepUrlToGltfModelConversions}var gYn=({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]=j.useState(null);return j.useEffect(()=>{let m=!0,p=null,g=!0;const f=mYn(),y=hYn(t);if(y){const E={arrayBuffer:y,blobUrl:URL.createObjectURL(new Blob([y],{type:"model/gltf-binary"}))};return f.completed.set(t,E),p=E.blobUrl,g=!1,d(E.blobUrl),()=>{m=!1,p&&g&&URL.revokeObjectURL(p)}}const x=f.completed.get(t);if(x)return p=x.blobUrl,g=!1,d(x.blobUrl),lmt(t,x.arrayBuffer),()=>{m=!1,p&&g&&URL.revokeObjectURL(p)};let I=f.inProgress.get(t);return I||(I=uYn(t).then(E=>{const b={arrayBuffer:E,blobUrl:URL.createObjectURL(new Blob([E],{type:"model/gltf-binary"}))};return f.completed.set(t,b),f.inProgress.delete(t),b}).catch(E=>{throw f.inProgress.delete(t),E}),f.inProgress.set(t,I)),I.then(E=>{m&&(p=E.blobUrl,g=!1,d(E.blobUrl),lmt(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?K.jsx(amt,{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 DJ(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=YIe(r,e.axisMapping.x)),e.axisMapping.y&&(o=YIe(r,e.axisMapping.y)),e.axisMapping.z&&(i=YIe(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 YIe(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 KIe={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 pYn(t,e){if(e.coordinateTransform)return e.coordinateTransform;if(!e.usingGlbCoordinates){if(e.hasFootprinterModel)return KIe.FOOTPRINTER_MODEL_TRANSFORM;if(!e.usingObjFormat)return e.usingStepFormat?KIe.STEP_INVERTED:KIe.Z_UP_TO_Y_UP_USB_FIX}}function PH(t,e){return pYn(t,{usingGlbCoordinates:e==="gltf"||e==="glb"||e==="jscad",usingObjFormat:e==="obj"||e==="wrl",usingStepFormat:e==="step",hasFootprinterModel:e==="footprinter"})}function TJ(t){if(!t)return;const e=DJ({x:1,y:0,z:0},t),n=DJ({x:0,y:1,z:0},t),o=DJ({x:0,y:0,z:1},t);return new Cs().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 j4(t){return t*Math.PI/180}function fYn(t){if(t==="z+")return[0,0,0];switch(t){case"x+":return[0,j4(-90),0];case"x-":return[0,j4(90),0];case"y+":return[j4(90),0,0];case"y-":return[j4(-90),0,0];case"z-":return[j4(180),0,0];default:return[0,0,0]}}function yYn(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 xYn(t,e){return t.rotation?[j4(t.rotation.x),j4(t.rotation.y),j4(t.rotation.z)]:e==="bottom"?[Math.PI,0,0]:[0,0,0]}function CYn(t,e){const n=new Dt(t.x,t.y,t.z),o=new p1(e[0],e[1],e[2],"XYZ");return n.applyEuler(o),[n.x,n.y,n.z]}function IYn(t,e,n){if(!t.model_origin_position)return[0,0,0];const o=e?DJ(t.model_origin_position,e):t.model_origin_position;return CYn(o,n)}function EYn(t,e){const n=yYn(t,e.layer,e.pcbThickness),o=xYn(t,e.layer),i=PH(t,e.modelType),r=fYn(t.model_board_normal_direction??"z+"),s=IYn(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 bYn=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",SYn=t=>t==="step"?"glb":t,PYn=(t,e)=>{if(t)return e?e(t):t},vYn=(...t)=>t,WIe=class extends Ri.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}},BYn=({error:t,onError:e})=>(j.useEffect(()=>{e(t)},[t,e]),null),Amt=({cad_component:t,circuitJson:e,resolveStaticAsset:n})=>{const o=hht(e),[i,r]=j.useState(!1),{visibility:s}=bB(),[a,c]=j.useState(null),l=j.useCallback(W=>{W?.mousePosition?(r(!0),c(W.mousePosition)):(r(!1),c(null))},[]),A=j.useCallback(()=>{r(!1),c(null)},[]),u=j.useMemo(()=>Ni(e).source_component.getUsing({source_component_id:t.source_component_id})?.name,[e,t.source_component_id]),_=j.useMemo(()=>e.filter(J=>J.type==="pcb_plated_hole"&&J.pcb_component_id===t.pcb_component_id).length>0,[e,t.pcb_component_id]),h=j.useCallback(W=>PYn(W,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,f]=j.useState(0),[y,x]=j.useState(null);j.useEffect(()=>{f(0),x(null)},[t.cad_component_id,d,m,p]);const E=e.find(W=>W.type==="pcb_component"&&W.source_component_id===t.source_component_id)?.layer??"top",b=bYn(t),P=SYn(b),B=t.model_glb_url?"glb":"gltf",w=t.model_wrl_url?"wrl":t.model_stl_url?"stl":"obj",k=j.useMemo(()=>EYn(t,{layer:E,pcbThickness:o,modelType:P}),[t,E,o,P]),N=vYn(...k.rotation),L=k.position,F=j.useMemo(()=>{const W=[];return m&&W.push(K.jsx(amt,{gltfUrl:m,position:L,rotation:N,modelOffset:k.modelPosition,modelRotation:k.modelRotation,sourceCoordinateTransform:TJ(PH(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&&W.push(K.jsx(sYn,{url:d,position:L,rotation:N,modelOffset:k.modelPosition,modelRotation:k.modelRotation,sourceCoordinateTransform:TJ(PH(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&&W.push(K.jsx(gYn,{stepUrl:p,position:L,rotation:N,modelOffset:k.modelPosition,modelRotation:k.modelRotation,sourceCoordinateTransform:TJ(PH(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}`)),W},[L,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(F.length>0){if(g>=F.length){if(y)throw y;return null}G=K.jsx(WIe,{fallback:({error:W})=>K.jsx(BYn,{error:W,onError:J=>{x(J),f($=>Math.max($,g+1))}}),children:F[g]},`${t.cad_component_id}-fallback-${g}`)}else t.model_jscad?G=K.jsx(nYn,{jscadPlan:t.model_jscad,positionOffset:L,rotationOffset:N,modelOffset:k.modelPosition,modelRotation:k.modelRotation,sourceCoordinateTransform:TJ(PH(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=K.jsx(jVn,{positionOffset:L,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 K.jsxs(K.Fragment,{children:[G,i&&a?K.jsx(ght,{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]})},umt={version:"0.0.563"};function MYn(t){t.querySelectorAll("canvas").forEach(e=>e.remove())}var wYn=t=>{t.outputColorSpace=S5,t.toneMapping=Met,t.toneMappingExposure=1},_mt="cadViewerCameraStateSession",dmt=(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(_mt,JSON.stringify(n))}catch(n){console.warn("Failed to save camera:",n)}},jIe=(t,e)=>{try{const n=sessionStorage.getItem(_mt);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}},hmt=j.createContext(void 0),DYn=({children:t,defaultTarget:e,initialCameraPosition:n,initialCameraType:o})=>{const i=j.useRef(null),r=j.useRef(null),[s,a]=j.useState(null),[c,l]=j.useState(o??"perspective"),[A,u]=j.useState(n??null),[_,h]=j.useState(new p1(0,0,0)),d=j.useMemo(()=>{const[f,y,x]=n??[5,-5,5],I=Math.hypot(f-e.x,y-e.y,x-e.z);return I>0?I:5},[n,e]),m=j.useCallback(f=>{const y=[e.x,e.y,e.z],x=r.current,I=i.current;let E=d;switch(x&&I&&(E=x.position.distanceTo(I.target)),f){case"Top Center Angled":{const b=E/Math.sqrt(2);return{position:[e.x,e.y-b,e.z+b],target:y,up:[0,0,1]}}case"Top Down":return{position:[e.x,e.y,e.z+E],target:y,up:[0,0,1]};case"Top Left Corner":return{position:[e.x-E*.6,e.y-E*.6,e.z+E*.6],target:y,up:[0,0,1]};case"Top Right Corner":return{position:[e.x+E*.6,e.y-E*.6,e.z+E*.6],target:y,up:[0,0,1]};case"Left Sideview":return{position:[e.x-E,e.y,e.z],target:y,up:[0,0,1]};case"Right Sideview":return{position:[e.x+E,e.y,e.z],target:y,up:[0,0,1]};case"Front":return{position:[e.x,e.y-E,e.z],target:y,up:[0,0,1]};default:return null}},[d,e,r,i]),p=j.useCallback(f=>{i.current=f},[]),g=j.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:dmt,loadCameraFromSession:jIe}),[e,d,s,m,p,c,A,_]);return K.jsx(hmt.Provider,{value:g,children:t})},X4=()=>{const t=j.useContext(hmt);if(!t)throw new Error("useCameraController must be used within a CameraControllerProvider");return t},TYn=j.forwardRef(({children:t,scene:e,camera:n,style:o,onCreated:i},r)=>{const{cameraType:s}=X4(),a=j.useRef(null),[c,l]=j.useState(null),A=j.useRef([]),u=j.useRef(void 0);u.current=i;const _=j.useRef(null),h=j.useCallback(g=>{A.current.push(g)},[]),d=j.useCallback(g=>{A.current=A.current.filter(f=>f!==g)},[]),m=j.useMemo(()=>new aB,[]);e?.up&&m.up.set(e.up.x,e.up.y,e.up.z);const p=j.useRef(new uA);return j.useImperativeHandle(r,()=>p.current),j.useEffect(()=>{if(!a.current)return;MYn(a.current);const g=new iX({antialias:!0,alpha:!0});wYn(g),g.setSize(a.current.clientWidth,a.current.clientHeight),g.setPixelRatio(window.devicePixelRatio),a.current.appendChild(g.domElement);const f=a.current.clientWidth/a.current.clientHeight,y=s==="perspective"?new ig(75,f,.1,1e3):new fk(-10*f,10*f,10,-10,-1e3,1e3);_.current?(y.position.copy(_.current.position),y.quaternion.copy(_.current.quaternion),y.up.copy(_.current.up)):(n?.up&&y.up.set(n.up[0],n.up[1],n.up[2]),n?.position&&y.position.set(n.position[0],n.position[1],n.position[2]),y.lookAt(0,0,0)),m.add(p.current),window.__TSCIRCUIT_THREE_OBJECT=p.current,l({scene:m,camera:y,renderer:g,rootObject:p.current,addFrameListener:h,removeFrameListener:d}),u.current?.({camera:y,renderer:g});let x;const I=new VPn,E=()=>{const P=I.getElapsedTime(),B=I.getDelta();A.current.forEach(w=>w(P,B)),g.render(m,y),x=requestAnimationFrame(E)};E();const b=()=>{if(a.current){const P=a.current.clientWidth/a.current.clientHeight;y instanceof ig?y.aspect=P:y instanceof fk&&(y.left=-10*P,y.right=10*P,y.top=10,y.bottom=-10),y.updateProjectionMatrix(),g.setSize(a.current.clientWidth,a.current.clientHeight)}};return window.addEventListener("resize",b),()=>{_.current={position:y.position.clone(),quaternion:y.quaternion.clone(),up:y.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]),K.jsx("div",{ref:a,style:{width:"100%",height:"100%",...o},children:c&&K.jsx(mht.Provider,{value:c,children:K.jsx(KVn,{children:t})})})}),QYn=({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}=C1(),_=j.useMemo(()=>!A||!u?null:new I6n(A,u.domElement),[A,u]);return j.useEffect(()=>(l?.(_??null),()=>l?.(null)),[_,l]),j.useEffect(()=>{if(!_)return;const h=()=>{l?.(_)};return _.addEventListener("change",h),()=>{_.removeEventListener("change",h)}},[_,l]),j.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:E4.ROTATE,MIDDLE:E4.PAN,RIGHT:null},c&&(_.target.set(c[0],c[1],c[2]),_.update()))},[_,t,e,o,i,r,s,a,c]),j.useEffect(()=>{if(!(!_||!n))return _.addEventListener("start",n),()=>{_.removeEventListener("start",n)}},[_,n]),j.useEffect(()=>{if(_)return()=>{_.dispose()}},[_]),AH(()=>{_?.update()},[_]),null},RYn=`
|
|
5201
|
+
`).replace(/d 0\./g,"d 1."),h=l.replace(/newmtl[\s\S]*?endmtl/g,"").replace(/^mtllib.*/gm,""),d=new c6n;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 sYn({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=rYn(t),d=j.useMemo(()=>h&&!(h instanceof Error)?(h.traverse(p=>{if(p instanceof Tr&&p.material){const g=f=>{f.transparent=_,f.opacity=_?.5:1,f.depthWrite=!_,f.needsUpdate=!0};Array.isArray(p.material)?p.material.forEach(g):g(p.material),p.renderOrder=_?2:1}}),h):new Tr(new Q5(.5,.5,.5),new op({transparent:!0,color:"red",opacity:.25})),[h,_]),{boardTransformGroup:m}=UIe({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 K.jsx(SH,{isHovered:A,onHover:c,onUnhover:l,object:m})}var VIe,aYn="https://cdn.jsdelivr.net/npm/occt-import-js@0.0.23/dist";function cYn(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 lYn(){if(!VIe){const t=await import("https://cdn.jsdelivr.net/npm/occt-import-js@0.0.23/+esm");VIe=cYn(t)({locateFile:n=>`${aYn}/${n}`})}return VIe}function AYn(t){const e=new rg;for(const n of t){const o=n.attributes.position?.array??[],i=n.index?.array??[];if(!o.length||!i.length)continue;const r=new _A;r.setAttribute("position",new Is(o,3));const s=n.attributes.normal?.array??[];s.length?r.setAttribute("normal",new Is(s,3)):r.computeVertexNormals(),r.setIndex(i);const a=new op({color:n.color?new xi(n.color[0],n.color[1],n.color[2]):new xi(.82,.82,.82)}),c=new Tr(r,a);c.name=n.name,e.add(c)}return e}async function uYn(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 lYn()).ReadStepFile(new Uint8Array(n),null);if(!i.success||!i.meshes.length)throw new Error("occt-import-js failed to convert STEP file");const r=AYn(i.meshes),s=new Xme;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 cmt="step-glb-cache:";function _Yn(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 dYn(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 hYn(t){try{const e=localStorage.getItem(`${cmt}${t}`);return e?dYn(e):null}catch(e){return console.warn("Failed to read STEP GLB cache",e),null}}function lmt(t,e){try{const n=_Yn(e);localStorage.setItem(`${cmt}${t}`,n)}catch(n){console.warn("Failed to write STEP GLB cache",n)}}function mYn(){const t=globalThis;return t.stepUrlToGltfModelConversions||(t.stepUrlToGltfModelConversions={inProgress:new Map,completed:new Map}),t.stepUrlToGltfModelConversions}var gYn=({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]=j.useState(null);return j.useEffect(()=>{let m=!0,p=null,g=!0;const f=mYn(),y=hYn(t);if(y){const E={arrayBuffer:y,blobUrl:URL.createObjectURL(new Blob([y],{type:"model/gltf-binary"}))};return f.completed.set(t,E),p=E.blobUrl,g=!1,d(E.blobUrl),()=>{m=!1,p&&g&&URL.revokeObjectURL(p)}}const x=f.completed.get(t);if(x)return p=x.blobUrl,g=!1,d(x.blobUrl),lmt(t,x.arrayBuffer),()=>{m=!1,p&&g&&URL.revokeObjectURL(p)};let I=f.inProgress.get(t);return I||(I=uYn(t).then(E=>{const b={arrayBuffer:E,blobUrl:URL.createObjectURL(new Blob([E],{type:"model/gltf-binary"}))};return f.completed.set(t,b),f.inProgress.delete(t),b}).catch(E=>{throw f.inProgress.delete(t),E}),f.inProgress.set(t,I)),I.then(E=>{m&&(p=E.blobUrl,g=!1,d(E.blobUrl),lmt(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?K.jsx(amt,{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 DJ(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=YIe(r,e.axisMapping.x)),e.axisMapping.y&&(o=YIe(r,e.axisMapping.y)),e.axisMapping.z&&(i=YIe(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 YIe(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 KIe={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 pYn(t,e){if(e.coordinateTransform)return e.coordinateTransform;if(!e.usingGlbCoordinates){if(e.hasFootprinterModel)return KIe.FOOTPRINTER_MODEL_TRANSFORM;if(!e.usingObjFormat)return e.usingStepFormat?KIe.STEP_INVERTED:KIe.Z_UP_TO_Y_UP_USB_FIX}}function PH(t,e){return pYn(t,{usingGlbCoordinates:e==="gltf"||e==="glb"||e==="jscad",usingObjFormat:e==="obj"||e==="wrl",usingStepFormat:e==="step",hasFootprinterModel:e==="footprinter"})}function TJ(t){if(!t)return;const e=DJ({x:1,y:0,z:0},t),n=DJ({x:0,y:1,z:0},t),o=DJ({x:0,y:0,z:1},t);return new Cs().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 j4(t){return t*Math.PI/180}function fYn(t){if(t==="z+")return[0,0,0];switch(t){case"x+":return[0,j4(-90),0];case"x-":return[0,j4(90),0];case"y+":return[j4(90),0,0];case"y-":return[j4(-90),0,0];case"z-":return[j4(180),0,0];default:return[0,0,0]}}function yYn(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 xYn(t,e){return t.rotation?[j4(t.rotation.x),j4(t.rotation.y),j4(t.rotation.z)]:e==="bottom"?[Math.PI,0,0]:[0,0,0]}function CYn(t,e){const n=new Dt(t.x,t.y,t.z),o=new p1(e[0],e[1],e[2],"XYZ");return n.applyEuler(o),[n.x,n.y,n.z]}function IYn(t,e,n){if(!t.model_origin_position)return[0,0,0];const o=e?DJ(t.model_origin_position,e):t.model_origin_position;return CYn(o,n)}function EYn(t,e){const n=yYn(t,e.layer,e.pcbThickness),o=xYn(t,e.layer),i=PH(t,e.modelType),r=fYn(t.model_board_normal_direction??"z+"),s=IYn(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 bYn=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",SYn=t=>t==="step"?"glb":t,PYn=(t,e)=>{if(t)return e?e(t):t},vYn=(...t)=>t,WIe=class extends Ri.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}},BYn=({error:t,onError:e})=>(j.useEffect(()=>{e(t)},[t,e]),null),Amt=({cad_component:t,circuitJson:e,resolveStaticAsset:n})=>{const o=hht(e),[i,r]=j.useState(!1),{visibility:s}=bB(),[a,c]=j.useState(null),l=j.useCallback(W=>{W?.mousePosition?(r(!0),c(W.mousePosition)):(r(!1),c(null))},[]),A=j.useCallback(()=>{r(!1),c(null)},[]),u=j.useMemo(()=>Ni(e).source_component.getUsing({source_component_id:t.source_component_id})?.name,[e,t.source_component_id]),_=j.useMemo(()=>e.filter(J=>J.type==="pcb_plated_hole"&&J.pcb_component_id===t.pcb_component_id).length>0,[e,t.pcb_component_id]),h=j.useCallback(W=>PYn(W,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,f]=j.useState(0),[y,x]=j.useState(null);j.useEffect(()=>{f(0),x(null)},[t.cad_component_id,d,m,p]);const E=e.find(W=>W.type==="pcb_component"&&W.source_component_id===t.source_component_id)?.layer??"top",b=bYn(t),P=SYn(b),B=t.model_glb_url?"glb":"gltf",w=t.model_wrl_url?"wrl":t.model_stl_url?"stl":"obj",k=j.useMemo(()=>EYn(t,{layer:E,pcbThickness:o,modelType:P}),[t,E,o,P]),N=vYn(...k.rotation),L=k.position,F=j.useMemo(()=>{const W=[];return m&&W.push(K.jsx(amt,{gltfUrl:m,position:L,rotation:N,modelOffset:k.modelPosition,modelRotation:k.modelRotation,sourceCoordinateTransform:TJ(PH(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&&W.push(K.jsx(sYn,{url:d,position:L,rotation:N,modelOffset:k.modelPosition,modelRotation:k.modelRotation,sourceCoordinateTransform:TJ(PH(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&&W.push(K.jsx(gYn,{stepUrl:p,position:L,rotation:N,modelOffset:k.modelPosition,modelRotation:k.modelRotation,sourceCoordinateTransform:TJ(PH(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}`)),W},[L,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(F.length>0){if(g>=F.length){if(y)throw y;return null}G=K.jsx(WIe,{fallback:({error:W})=>K.jsx(BYn,{error:W,onError:J=>{x(J),f($=>Math.max($,g+1))}}),children:F[g]},`${t.cad_component_id}-fallback-${g}`)}else t.model_jscad?G=K.jsx(nYn,{jscadPlan:t.model_jscad,positionOffset:L,rotationOffset:N,modelOffset:k.modelPosition,modelRotation:k.modelRotation,sourceCoordinateTransform:TJ(PH(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=K.jsx(jVn,{positionOffset:L,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 K.jsxs(K.Fragment,{children:[G,i&&a?K.jsx(ght,{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]})},umt={version:"0.0.564"};function MYn(t){t.querySelectorAll("canvas").forEach(e=>e.remove())}var wYn=t=>{t.outputColorSpace=S5,t.toneMapping=Met,t.toneMappingExposure=1},_mt="cadViewerCameraStateSession",dmt=(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(_mt,JSON.stringify(n))}catch(n){console.warn("Failed to save camera:",n)}},jIe=(t,e)=>{try{const n=sessionStorage.getItem(_mt);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}},hmt=j.createContext(void 0),DYn=({children:t,defaultTarget:e,initialCameraPosition:n,initialCameraType:o})=>{const i=j.useRef(null),r=j.useRef(null),[s,a]=j.useState(null),[c,l]=j.useState(o??"perspective"),[A,u]=j.useState(n??null),[_,h]=j.useState(new p1(0,0,0)),d=j.useMemo(()=>{const[f,y,x]=n??[5,-5,5],I=Math.hypot(f-e.x,y-e.y,x-e.z);return I>0?I:5},[n,e]),m=j.useCallback(f=>{const y=[e.x,e.y,e.z],x=r.current,I=i.current;let E=d;switch(x&&I&&(E=x.position.distanceTo(I.target)),f){case"Top Center Angled":{const b=E/Math.sqrt(2);return{position:[e.x,e.y-b,e.z+b],target:y,up:[0,0,1]}}case"Top Down":return{position:[e.x,e.y,e.z+E],target:y,up:[0,0,1]};case"Top Left Corner":return{position:[e.x-E*.6,e.y-E*.6,e.z+E*.6],target:y,up:[0,0,1]};case"Top Right Corner":return{position:[e.x+E*.6,e.y-E*.6,e.z+E*.6],target:y,up:[0,0,1]};case"Left Sideview":return{position:[e.x-E,e.y,e.z],target:y,up:[0,0,1]};case"Right Sideview":return{position:[e.x+E,e.y,e.z],target:y,up:[0,0,1]};case"Front":return{position:[e.x,e.y-E,e.z],target:y,up:[0,0,1]};default:return null}},[d,e,r,i]),p=j.useCallback(f=>{i.current=f},[]),g=j.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:dmt,loadCameraFromSession:jIe}),[e,d,s,m,p,c,A,_]);return K.jsx(hmt.Provider,{value:g,children:t})},X4=()=>{const t=j.useContext(hmt);if(!t)throw new Error("useCameraController must be used within a CameraControllerProvider");return t},TYn=j.forwardRef(({children:t,scene:e,camera:n,style:o,onCreated:i},r)=>{const{cameraType:s}=X4(),a=j.useRef(null),[c,l]=j.useState(null),A=j.useRef([]),u=j.useRef(void 0);u.current=i;const _=j.useRef(null),h=j.useCallback(g=>{A.current.push(g)},[]),d=j.useCallback(g=>{A.current=A.current.filter(f=>f!==g)},[]),m=j.useMemo(()=>new aB,[]);e?.up&&m.up.set(e.up.x,e.up.y,e.up.z);const p=j.useRef(new uA);return j.useImperativeHandle(r,()=>p.current),j.useEffect(()=>{if(!a.current)return;MYn(a.current);const g=new iX({antialias:!0,alpha:!0});wYn(g),g.setSize(a.current.clientWidth,a.current.clientHeight),g.setPixelRatio(window.devicePixelRatio),a.current.appendChild(g.domElement);const f=a.current.clientWidth/a.current.clientHeight,y=s==="perspective"?new ig(75,f,.1,1e3):new fk(-10*f,10*f,10,-10,-1e3,1e3);_.current?(y.position.copy(_.current.position),y.quaternion.copy(_.current.quaternion),y.up.copy(_.current.up)):(n?.up&&y.up.set(n.up[0],n.up[1],n.up[2]),n?.position&&y.position.set(n.position[0],n.position[1],n.position[2]),y.lookAt(0,0,0)),m.add(p.current),window.__TSCIRCUIT_THREE_OBJECT=p.current,l({scene:m,camera:y,renderer:g,rootObject:p.current,addFrameListener:h,removeFrameListener:d}),u.current?.({camera:y,renderer:g});let x;const I=new VPn,E=()=>{const P=I.getElapsedTime(),B=I.getDelta();A.current.forEach(w=>w(P,B)),g.render(m,y),x=requestAnimationFrame(E)};E();const b=()=>{if(a.current){const P=a.current.clientWidth/a.current.clientHeight;y instanceof ig?y.aspect=P:y instanceof fk&&(y.left=-10*P,y.right=10*P,y.top=10,y.bottom=-10),y.updateProjectionMatrix(),g.setSize(a.current.clientWidth,a.current.clientHeight)}};return window.addEventListener("resize",b),()=>{_.current={position:y.position.clone(),quaternion:y.quaternion.clone(),up:y.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]),K.jsx("div",{ref:a,style:{width:"100%",height:"100%",...o},children:c&&K.jsx(mht.Provider,{value:c,children:K.jsx(KVn,{children:t})})})}),QYn=({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}=C1(),_=j.useMemo(()=>!A||!u?null:new I6n(A,u.domElement),[A,u]);return j.useEffect(()=>(l?.(_??null),()=>l?.(null)),[_,l]),j.useEffect(()=>{if(!_)return;const h=()=>{l?.(_)};return _.addEventListener("change",h),()=>{_.removeEventListener("change",h)}},[_,l]),j.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:E4.ROTATE,MIDDLE:E4.PAN,RIGHT:null},c&&(_.target.set(c[0],c[1],c[2]),_.update()))},[_,t,e,o,i,r,s,a,c]),j.useEffect(()=>{if(!(!_||!n))return _.addEventListener("start",n),()=>{_.removeEventListener("start",n)}},[_,n]),j.useEffect(()=>{if(_)return()=>{_.dispose()}},[_]),AH(()=>{_?.update()},[_]),null},RYn=`
|
|
5202
5202
|
varying vec3 worldPosition;
|
|
5203
5203
|
void main() {
|
|
5204
5204
|
worldPosition = (modelMatrix * vec4(position, 1.0)).xyz;
|
|
@@ -5745,7 +5745,7 @@ test("${l} should solve problem correctly", () => {
|
|
|
5745
5745
|
// Add more specific assertions based on expected output
|
|
5746
5746
|
// expect(solver.netLabelPlacementSolver!.netLabelPlacements).toMatchInlineSnapshot()
|
|
5747
5747
|
})
|
|
5748
|
-
`,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 K.jsxs("div",{className:`relative ${e}`,ref:i,children:[K.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&&K.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:[K.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:r,children:"Download JSON"}),K.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),K.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:a,children:"Download test.ts"})]})]})},xIt=t=>t.activeSubSolver?[t,...xIt(t.activeSubSolver)]:[t],qpo=({solver:t})=>{const e=xIt(t);return K.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:e.map((n,o)=>K.jsxs("div",{className:"flex items-center",children:[o>0&&K.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),K.jsx(Jpo,{solver:n})]},n.constructor.name))})},$po=({solver:t,triggerRender:e,animationSpeed:n=25,onSolverStarted:o,onSolverCompleted:i})=>{const[r,s]=j.useReducer(m=>!m,!1),a=j.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)};j.useEffect(()=>()=>{a.current&&clearInterval(a.current)},[]),j.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 K.jsxs("div",{className:"space-y-2 p-2 border-b",children:[K.jsx("div",{className:"flex items-center",children:K.jsx(qpo,{solver:t})}),K.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[K.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"}),K.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"}),K.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"}),K.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&&K.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"}),K.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",t.iterations]}),t.timeToSolve!==void 0&&K.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(t.timeToSolve/1e3).toFixed(3),"s"]}),d&&K.jsxs("div",{className:"text-sm text-gray-600",children:["Phase: ",K.jsx("span",{className:"font-medium",children:d})]}),t.solved&&K.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),t.failed&&K.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),t.error&&K.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",t.error]})]})},Zpo=(t,e,n)=>{const o=t.currentPipelineStepIndex;return e<o?"Completed":e===o&&t.activeSubSolver?t.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},efo=(t,e)=>{const o=t.pipelineDef[e].solverName,i=Zpo(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}},tfo=({status:t})=>{const e={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return K.jsx("span",{className:`font-medium ${e[t]}`,children:t})},nfo=({progress:t})=>{if(t===0)return null;const e=Math.round(t*100);return K.jsxs("div",{className:"flex items-center gap-2",children:[K.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:K.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${e}%`}})}),K.jsxs("span",{className:"text-xs text-gray-500",children:[e,"%"]})]})},ofo=t=>Object.entries(t).map(([e,n])=>`${e}: ${n}`).join(", "),ifo=({stats:t})=>{if(!t||Object.keys(t).length===0)return K.jsx("span",{children:"-"});const e=Object.entries(t),n=ofo(t);return K.jsxs("details",{className:"cursor-pointer",children:[K.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:n}),K.jsx("div",{className:"mt-1 text-xs",children:e.map(([o,i])=>K.jsxs("div",{children:[o,": ",String(i)]},o))})]})},fSe=t=>{if(t===null||typeof t!="object")return t;if(Array.isArray(t))return t.map(fSe);const e={};for(const[n,o]of Object.entries(t))n.startsWith("_")||(e[n]=fSe(o));return e},rfo=(t,e)=>{try{if(typeof t.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${e}`);return}const n=fSe(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)}`)}},sfo=({solver:t,onStepUntilPhase:e,onDownloadInput:n})=>{const o=t.pipelineDef.map((a,c)=>efo(t,c)),i=a=>{e?.(a)},r=a=>{a.solverInstance&&(n?n(a.solverInstance,a.name):rfo(a.solverInstance,a.name))},s=a=>`${(a/1e3).toFixed(2)}s`;return K.jsxs("div",{className:"border-t border-gray-200",children:[K.jsx("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200",children:K.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Steps"})}),K.jsx("div",{className:"overflow-x-auto",children:K.jsxs("table",{className:"w-full text-sm",children:[K.jsx("thead",{children:K.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[K.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Step"}),K.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),K.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",K.jsx("sub",{children:"0"})]}),K.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),K.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),K.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),K.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),K.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),K.jsx("tbody",{children:o.map(a=>K.jsxs("tr",{className:`border-b border-gray-100 ${a.status==="In Progress"?"bg-yellow-50":""}`,children:[K.jsx("td",{className:"px-4 py-2",children:K.jsxs("div",{className:"flex items-center gap-2",children:[K.jsx("span",{className:"text-gray-400 w-6",children:String(a.index+1).padStart(2,"0")}),K.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:K.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:K.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"})})}),K.jsx("span",{className:"font-medium text-gray-900",children:a.name})]})}),K.jsx("td",{className:"px-4 py-2",children:K.jsx(tfo,{status:a.status})}),K.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:a.firstIteration!==null?a.firstIteration:""}),K.jsx("td",{className:"px-4 py-2 text-gray-600",children:a.iterations}),K.jsx("td",{className:"px-4 py-2",children:K.jsx(nfo,{progress:a.progress})}),K.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(a.timeSpent)}),K.jsx("td",{className:"px-4 py-2 text-gray-500",children:K.jsx(ifo,{stats:a.stats})}),K.jsx("td",{className:"px-4 py-2",children:a.solverInstance?K.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:[K.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:K.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"})}),K.jsx("span",{children:"Input"})]}):null})]},a.name))})]})})]})},afo=class extends Ri.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 cfo({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 f of g)A(f.x,f.y)}for(const p of o){const g=p.x??0,f=p.y??0,y=p.width??0,x=p.height??0;A(g,f),A(g+y,f+x)}for(const p of i){const g=p.x??0,f=p.y??0,y=p.radius??1;A(g-y,f-y),A(g+y,f+y)}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 K.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${_} ${h} ${d} ${m}`,role:"img","aria-label":"Graphics fallback",children:[o.map((p,g)=>K.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)=>K.jsx("polyline",{fill:"none",stroke:p.strokeColor??"black",strokeWidth:p.strokeWidth??1,points:(p.points??[]).map(f=>`${f.x??0},${f.y??0}`).join(" ")},`line-${g}`)),i.map((p,g)=>K.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)=>K.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)=>K.jsx("text",{x:p.x??0,y:p.y??0,fontSize:p.fontSize??10,fill:p.color??"black",children:p.text??""},`text-${g}`))]})}var lfo=({solver:t,animationSpeed:e=25,onSolverStarted:n,onSolverCompleted:o})=>{const[i,r]=j.useReducer(A=>A+1,0),s=j.useMemo(()=>{try{return t.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(A){return console.error("Visualization error:",A),{points:[],lines:[],rects:[],circles:[]}}},[t,i]),a=j.useMemo(()=>(s.rects?.length||0)===0&&(s.lines?.length||0)===0&&(s.points?.length||0)===0&&(s.circles?.length||0)===0,[s]);j.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 K.jsxs("div",{children:[K.jsx($po,{solver:t,triggerRender:r,animationSpeed:e,onSolverStarted:n,onSolverCompleted:o}),a?K.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):K.jsx(afo,{fallback:K.jsx(cfo,{graphics:s}),children:K.jsx(Xpo,{graphics:s})}),c&&K.jsx(sfo,{solver:t,onStepUntilPhase:l})]})};const Afo=()=>{j.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)},[])},ufo=t=>t.toLowerCase().includes("pack")?X$n:t.toLowerCase().includes("rout")?eZn:R$n,_fo=({solverEvents:t=[]})=>{const[e,n]=j.useState(null);Afo();const o=j.useMemo(()=>{const a=new Map;for(const c of t){const l=`${c.componentName}-${c.solverName}`;a.set(l,c)}return a},[t]),i=j.useMemo(()=>Array.from(o.keys()),[o]),r=e?o.get(e):null,s=j.useMemo(()=>{if(!r)return{instance:null,error:null,classFound:!1};const a=y_e[r.solverName];if(!a)return{instance:null,error:`Solver class "${r.solverName}" not found in SOLVERS registry. Available: ${Object.keys(y_e).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?K.jsx("div",{className:"rf-p-4",children:K.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:K.jsxs("div",{className:"rf-p-4",children:[K.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),K.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."})]})})}):K.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[K.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[K.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 K.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=ufo(c.solverName);return K.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[K.jsx(A,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),K.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[K.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:c.componentName}),K.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:c.solverName})]})]})})()},a)})]}),K.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:r?s.instance?K.jsx(PC,{fallback:K.jsx("div",{className:"rf-p-4",children:K.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[K.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),K.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",r.solverName]})]})}),children:K.jsx(lfo,{solver:s.instance})}):K.jsxs("div",{className:"rf-p-4",children:[K.jsxs("div",{className:"rf-mb-4",children:[K.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:r.solverName}),K.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",r.componentName]})]}),s.error&&K.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:K.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),K.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[K.jsx("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50",children:K.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"})}),K.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:K.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)})})]})]}):K.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:K.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},CIt=({errorMessage:t,errorStack:e,circuitJsonErrors:n})=>{j.useEffect(()=>{if(t){const o=new Error(t);e&&(o.stack=e);try{Uw.captureException(o)}catch{}}},[t,e]),j.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{Uw.captureException(i,{error_type:o.type})}catch{}}},[n])},IIt=t=>{j.useEffect(()=>{try{j5n(t)}catch{}},[t.source,t.component,t.isWebEmbedded,t.activeTab])},EIt="0.0.2022",dfo={version:EIt},cZ=qJe()($Je(t=>({lastRunEvalVersion:void 0,setLastRunEvalVersion:e=>{t({lastRunEvalVersion:e})}}),{name:"runframe-runner-store"})),hfo=t=>{const[e,n]=j.useState([]),[o,i]=j.useState(null),[r,s]=j.useState(""),[a,c]=Cw("eval-version-selection",null),l=cZ(h=>h.setLastRunEvalVersion),A=cZ(h=>h.lastRunEvalVersion);return j.useEffect(()=>{t&&fetch("https://data.jsdelivr.com/v1/package/npm/@tscircuit/eval").then(h=>h.json()).then(h=>{if(Array.isArray(h?.versions)){let d=[...h.versions];h.tags?.latest&&(i(h.tags.latest),d=d.filter(m=>m!==h.tags.latest)),n(d)}}).catch(()=>{})},[t]),j.useEffect(()=>{t&&(a?(window.TSCIRCUIT_LATEST_EVAL_VERSION=a,l(a)):o&&(window.TSCIRCUIT_LATEST_EVAL_VERSION=o,l(o)))},[t,a,o]),{versions:j.useMemo(()=>e.filter(h=>h.includes(r)).slice(0,50),[e,r]),latestVersion:o,lastRunEvalVersion:A,search:r,setSearch:s,selectVersion:h=>{c(h),s("")}}},mfo=({snippetNames:t,onSelect:e,onCancel:n,isOpen:o})=>{const[i,r]=j.useState(""),[s,a]=j.useState("");if(!o)return null;const c=t.filter(u=>u.toLowerCase().includes(s.toLowerCase())),l=s&&!t.includes(s),A=u=>{u.key==="Enter"&&(c.length===1?r(c[0]):l&&r(s))};return K.jsx("div",{className:"rf-fixed rf-inset-0 rf-bg-black rf-bg-opacity-50 rf-flex rf-items-center rf-justify-center rf-z-[100]",children:K.jsxs("div",{className:"rf-bg-white rf-rounded-lg rf-p-6 rf-w-96",children:[K.jsx("h2",{className:"rf-text-lg rf-font-semibold rf-mb-4",children:"Select Snippet"}),K.jsx("input",{type:"text",className:"rf-w-full rf-px-4 rf-py-2 rf-border rf-rounded rf-mb-4",placeholder:"Search snippets or new snippet name...",value:s,onChange:u=>a(u.target.value),onKeyDown:A}),K.jsxs("div",{className:"rf-h-60 rf-overflow-y-auto",children:[c.map(u=>K.jsx("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 ${i===u?"bg-blue-50":""}`,onClick:()=>r(u),children:u},u)),l&&K.jsxs("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 text-blue-500 ${i===s?"bg-blue-50":""}`,onClick:()=>r(s),children:['Create new "',s,'"']})]}),K.jsxs("div",{className:"rf-mt-4 rf-flex rf-justify-end rf-gap-2",children:[K.jsx("button",{type:"button",className:"rf-px-4 rf-py-2 rf-text-gray-600 rf-hover:text-gray-800",onClick:n,children:"Cancel"}),K.jsx("button",{type:"button",className:"rf-px-4 rf-py-2 rf-bg-blue-500 rf-text-white rf-rounded rf-hover:bg-blue-600 rf-disabled:opacity-50",onClick:()=>i&&e(i),disabled:!i,children:i===s?`Create "${i}"`:`Save to ${i}`})]})]})})},gfo=t=>{const e=j.useRef(null),n=i0(o=>o.recentEvents);j.useEffect(()=>{if(n.length===0)return;const o=n[0];o.event_id!==e.current&&(t(o),e.current=o.event_id)},[n,t])};function pfo(t){const e=ffo(t),n=j.forwardRef((o,i)=>{const{children:r,...s}=o,a=j.Children.toArray(r),c=a.find(xfo);if(c){const l=c.props.children,A=a.map(u=>u===c?j.Children.count(l)>1?j.Children.only(null):j.isValidElement(l)?l.props.children:null:u);return K.jsx(e,{...s,ref:i,children:j.isValidElement(l)?j.cloneElement(l,void 0,A):null})}return K.jsx(e,{...s,ref:i,children:r})});return n.displayName=`${t}.Slot`,n}function ffo(t){const e=j.forwardRef((n,o)=>{const{children:i,...r}=n;if(j.isValidElement(i)){const s=Ifo(i),a=Cfo(r,i.props);return i.type!==j.Fragment&&(a.ref=o?F2(o,s):s),j.cloneElement(i,a)}return j.Children.count(i)>1?j.Children.only(null):null});return e.displayName=`${t}.SlotClone`,e}var yfo=Symbol("radix.slottable");function xfo(t){return j.isValidElement(t)&&typeof t.type=="function"&&"__radixId"in t.type&&t.type.__radixId===yfo}function Cfo(t,e){const n={...e};for(const o in e){const i=t[o],r=e[o];/^on[A-Z]/.test(o)?i&&r?n[o]=(...a)=>{const c=r(...a);return i(...a),c}:i&&(n[o]=i):o==="style"?n[o]={...i,...r}:o==="className"&&(n[o]=[i,r].filter(Boolean).join(" "))}return{...t,...n}}function Ifo(t){let e=Object.getOwnPropertyDescriptor(t.props,"ref")?.get,n=e&&"isReactWarning"in e&&e.isReactWarning;return n?t.ref:(e=Object.getOwnPropertyDescriptor(t,"ref")?.get,n=e&&"isReactWarning"in e&&e.isReactWarning,n?t.props.ref:t.props.ref||t.ref)}var lZ="Dialog",[bIt,SIt]=C5(lZ),[Efo,j5]=bIt(lZ),PIt=t=>{const{__scopeDialog:e,children:n,open:o,defaultOpen:i,onOpenChange:r,modal:s=!0}=t,a=j.useRef(null),c=j.useRef(null),[l,A]=m4({prop:o,defaultProp:i??!1,onChange:r,caller:lZ});return K.jsx(Efo,{scope:e,triggerRef:a,contentRef:c,contentId:qg(),titleId:qg(),descriptionId:qg(),open:l,onOpenChange:A,onOpenToggle:j.useCallback(()=>A(u=>!u),[A]),modal:s,children:n})};PIt.displayName=lZ;var vIt="DialogTrigger",BIt=j.forwardRef((t,e)=>{const{__scopeDialog:n,...o}=t,i=j5(vIt,n),r=r0(e,i.triggerRef);return K.jsx(El.button,{type:"button","aria-haspopup":"dialog","aria-expanded":i.open,"aria-controls":i.contentId,"data-state":CSe(i.open),...o,ref:r,onClick:Ir(t.onClick,i.onOpenToggle)})});BIt.displayName=vIt;var ySe="DialogPortal",[bfo,MIt]=bIt(ySe,{forceMount:void 0}),wIt=t=>{const{__scopeDialog:e,forceMount:n,children:o,container:i}=t,r=j5(ySe,e);return K.jsx(bfo,{scope:e,forceMount:n,children:j.Children.map(o,s=>K.jsx(Vy,{present:n||r.open,children:K.jsx(Mq,{asChild:!0,container:i,children:s})}))})};wIt.displayName=ySe;var AZ="DialogOverlay",DIt=j.forwardRef((t,e)=>{const n=MIt(AZ,t.__scopeDialog),{forceMount:o=n.forceMount,...i}=t,r=j5(AZ,t.__scopeDialog);return r.modal?K.jsx(Vy,{present:o||r.open,children:K.jsx(Pfo,{...i,ref:e})}):null});DIt.displayName=AZ;var Sfo=pfo("DialogOverlay.RemoveScroll"),Pfo=j.forwardRef((t,e)=>{const{__scopeDialog:n,...o}=t,i=j5(AZ,n);return K.jsx(Hq,{as:Sfo,allowPinchZoom:!0,shards:[i.contentRef],children:K.jsx(El.div,{"data-state":CSe(i.open),...o,ref:e,style:{pointerEvents:"auto",...o.style}})})}),a9="DialogContent",TIt=j.forwardRef((t,e)=>{const n=MIt(a9,t.__scopeDialog),{forceMount:o=n.forceMount,...i}=t,r=j5(a9,t.__scopeDialog);return K.jsx(Vy,{present:o||r.open,children:r.modal?K.jsx(vfo,{...i,ref:e}):K.jsx(Bfo,{...i,ref:e})})});TIt.displayName=a9;var vfo=j.forwardRef((t,e)=>{const n=j5(a9,t.__scopeDialog),o=j.useRef(null),i=r0(e,n.contentRef,o);return j.useEffect(()=>{const r=o.current;if(r)return dEe(r)},[]),K.jsx(QIt,{...t,ref:i,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:Ir(t.onCloseAutoFocus,r=>{r.preventDefault(),n.triggerRef.current?.focus()}),onPointerDownOutside:Ir(t.onPointerDownOutside,r=>{const s=r.detail.originalEvent,a=s.button===0&&s.ctrlKey===!0;(s.button===2||a)&&r.preventDefault()}),onFocusOutside:Ir(t.onFocusOutside,r=>r.preventDefault())})}),Bfo=j.forwardRef((t,e)=>{const n=j5(a9,t.__scopeDialog),o=j.useRef(!1),i=j.useRef(!1);return K.jsx(QIt,{...t,ref:e,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:r=>{t.onCloseAutoFocus?.(r),r.defaultPrevented||(o.current||n.triggerRef.current?.focus(),r.preventDefault()),o.current=!1,i.current=!1},onInteractOutside:r=>{t.onInteractOutside?.(r),r.defaultPrevented||(o.current=!0,r.detail.originalEvent.type==="pointerdown"&&(i.current=!0));const s=r.target;n.triggerRef.current?.contains(s)&&r.preventDefault(),r.detail.originalEvent.type==="focusin"&&i.current&&r.preventDefault()}})}),QIt=j.forwardRef((t,e)=>{const{__scopeDialog:n,trapFocus:o,onOpenAutoFocus:i,onCloseAutoFocus:r,...s}=t,a=j5(a9,n),c=j.useRef(null),l=r0(e,c);return W3e(),K.jsxs(K.Fragment,{children:[K.jsx(gq,{asChild:!0,loop:!0,trapped:o,onMountAutoFocus:i,onUnmountAutoFocus:r,children:K.jsx(WH,{role:"dialog",id:a.contentId,"aria-describedby":a.descriptionId,"aria-labelledby":a.titleId,"data-state":CSe(a.open),...s,ref:l,onDismiss:()=>a.onOpenChange(!1)})}),K.jsxs(K.Fragment,{children:[K.jsx(wfo,{titleId:a.titleId}),K.jsx(Tfo,{contentRef:c,descriptionId:a.descriptionId})]})]})}),xSe="DialogTitle",RIt=j.forwardRef((t,e)=>{const{__scopeDialog:n,...o}=t,i=j5(xSe,n);return K.jsx(El.h2,{id:i.titleId,...o,ref:e})});RIt.displayName=xSe;var NIt="DialogDescription",kIt=j.forwardRef((t,e)=>{const{__scopeDialog:n,...o}=t,i=j5(NIt,n);return K.jsx(El.p,{id:i.descriptionId,...o,ref:e})});kIt.displayName=NIt;var HIt="DialogClose",LIt=j.forwardRef((t,e)=>{const{__scopeDialog:n,...o}=t,i=j5(HIt,n);return K.jsx(El.button,{type:"button",...o,ref:e,onClick:Ir(t.onClick,()=>i.onOpenChange(!1))})});LIt.displayName=HIt;function CSe(t){return t?"open":"closed"}var FIt="DialogTitleWarning",[Mfo,OIt]=j2n(FIt,{contentName:a9,titleName:xSe,docsSlug:"dialog"}),wfo=({titleId:t})=>{const e=OIt(FIt),n=`\`${e.contentName}\` requires a \`${e.titleName}\` for the component to be accessible for screen reader users.
|
|
5748
|
+
`,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 K.jsxs("div",{className:`relative ${e}`,ref:i,children:[K.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&&K.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:[K.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:r,children:"Download JSON"}),K.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),K.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:a,children:"Download test.ts"})]})]})},xIt=t=>t.activeSubSolver?[t,...xIt(t.activeSubSolver)]:[t],qpo=({solver:t})=>{const e=xIt(t);return K.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:e.map((n,o)=>K.jsxs("div",{className:"flex items-center",children:[o>0&&K.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),K.jsx(Jpo,{solver:n})]},n.constructor.name))})},$po=({solver:t,triggerRender:e,animationSpeed:n=25,onSolverStarted:o,onSolverCompleted:i})=>{const[r,s]=j.useReducer(m=>!m,!1),a=j.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)};j.useEffect(()=>()=>{a.current&&clearInterval(a.current)},[]),j.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 K.jsxs("div",{className:"space-y-2 p-2 border-b",children:[K.jsx("div",{className:"flex items-center",children:K.jsx(qpo,{solver:t})}),K.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[K.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"}),K.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"}),K.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"}),K.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&&K.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"}),K.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",t.iterations]}),t.timeToSolve!==void 0&&K.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(t.timeToSolve/1e3).toFixed(3),"s"]}),d&&K.jsxs("div",{className:"text-sm text-gray-600",children:["Phase: ",K.jsx("span",{className:"font-medium",children:d})]}),t.solved&&K.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),t.failed&&K.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),t.error&&K.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",t.error]})]})},Zpo=(t,e,n)=>{const o=t.currentPipelineStepIndex;return e<o?"Completed":e===o&&t.activeSubSolver?t.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},efo=(t,e)=>{const o=t.pipelineDef[e].solverName,i=Zpo(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}},tfo=({status:t})=>{const e={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return K.jsx("span",{className:`font-medium ${e[t]}`,children:t})},nfo=({progress:t})=>{if(t===0)return null;const e=Math.round(t*100);return K.jsxs("div",{className:"flex items-center gap-2",children:[K.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:K.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${e}%`}})}),K.jsxs("span",{className:"text-xs text-gray-500",children:[e,"%"]})]})},ofo=t=>Object.entries(t).map(([e,n])=>`${e}: ${n}`).join(", "),ifo=({stats:t})=>{if(!t||Object.keys(t).length===0)return K.jsx("span",{children:"-"});const e=Object.entries(t),n=ofo(t);return K.jsxs("details",{className:"cursor-pointer",children:[K.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:n}),K.jsx("div",{className:"mt-1 text-xs",children:e.map(([o,i])=>K.jsxs("div",{children:[o,": ",String(i)]},o))})]})},fSe=t=>{if(t===null||typeof t!="object")return t;if(Array.isArray(t))return t.map(fSe);const e={};for(const[n,o]of Object.entries(t))n.startsWith("_")||(e[n]=fSe(o));return e},rfo=(t,e)=>{try{if(typeof t.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${e}`);return}const n=fSe(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)}`)}},sfo=({solver:t,onStepUntilPhase:e,onDownloadInput:n})=>{const o=t.pipelineDef.map((a,c)=>efo(t,c)),i=a=>{e?.(a)},r=a=>{a.solverInstance&&(n?n(a.solverInstance,a.name):rfo(a.solverInstance,a.name))},s=a=>`${(a/1e3).toFixed(2)}s`;return K.jsxs("div",{className:"border-t border-gray-200",children:[K.jsx("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200",children:K.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Steps"})}),K.jsx("div",{className:"overflow-x-auto",children:K.jsxs("table",{className:"w-full text-sm",children:[K.jsx("thead",{children:K.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[K.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Step"}),K.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),K.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",K.jsx("sub",{children:"0"})]}),K.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),K.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),K.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),K.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),K.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),K.jsx("tbody",{children:o.map(a=>K.jsxs("tr",{className:`border-b border-gray-100 ${a.status==="In Progress"?"bg-yellow-50":""}`,children:[K.jsx("td",{className:"px-4 py-2",children:K.jsxs("div",{className:"flex items-center gap-2",children:[K.jsx("span",{className:"text-gray-400 w-6",children:String(a.index+1).padStart(2,"0")}),K.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:K.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:K.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"})})}),K.jsx("span",{className:"font-medium text-gray-900",children:a.name})]})}),K.jsx("td",{className:"px-4 py-2",children:K.jsx(tfo,{status:a.status})}),K.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:a.firstIteration!==null?a.firstIteration:""}),K.jsx("td",{className:"px-4 py-2 text-gray-600",children:a.iterations}),K.jsx("td",{className:"px-4 py-2",children:K.jsx(nfo,{progress:a.progress})}),K.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(a.timeSpent)}),K.jsx("td",{className:"px-4 py-2 text-gray-500",children:K.jsx(ifo,{stats:a.stats})}),K.jsx("td",{className:"px-4 py-2",children:a.solverInstance?K.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:[K.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:K.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"})}),K.jsx("span",{children:"Input"})]}):null})]},a.name))})]})})]})},afo=class extends Ri.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 cfo({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 f of g)A(f.x,f.y)}for(const p of o){const g=p.x??0,f=p.y??0,y=p.width??0,x=p.height??0;A(g,f),A(g+y,f+x)}for(const p of i){const g=p.x??0,f=p.y??0,y=p.radius??1;A(g-y,f-y),A(g+y,f+y)}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 K.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${_} ${h} ${d} ${m}`,role:"img","aria-label":"Graphics fallback",children:[o.map((p,g)=>K.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)=>K.jsx("polyline",{fill:"none",stroke:p.strokeColor??"black",strokeWidth:p.strokeWidth??1,points:(p.points??[]).map(f=>`${f.x??0},${f.y??0}`).join(" ")},`line-${g}`)),i.map((p,g)=>K.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)=>K.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)=>K.jsx("text",{x:p.x??0,y:p.y??0,fontSize:p.fontSize??10,fill:p.color??"black",children:p.text??""},`text-${g}`))]})}var lfo=({solver:t,animationSpeed:e=25,onSolverStarted:n,onSolverCompleted:o})=>{const[i,r]=j.useReducer(A=>A+1,0),s=j.useMemo(()=>{try{return t.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(A){return console.error("Visualization error:",A),{points:[],lines:[],rects:[],circles:[]}}},[t,i]),a=j.useMemo(()=>(s.rects?.length||0)===0&&(s.lines?.length||0)===0&&(s.points?.length||0)===0&&(s.circles?.length||0)===0,[s]);j.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 K.jsxs("div",{children:[K.jsx($po,{solver:t,triggerRender:r,animationSpeed:e,onSolverStarted:n,onSolverCompleted:o}),a?K.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):K.jsx(afo,{fallback:K.jsx(cfo,{graphics:s}),children:K.jsx(Xpo,{graphics:s})}),c&&K.jsx(sfo,{solver:t,onStepUntilPhase:l})]})};const Afo=()=>{j.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)},[])},ufo=t=>t.toLowerCase().includes("pack")?X$n:t.toLowerCase().includes("rout")?eZn:R$n,_fo=({solverEvents:t=[]})=>{const[e,n]=j.useState(null);Afo();const o=j.useMemo(()=>{const a=new Map;for(const c of t){const l=`${c.componentName}-${c.solverName}`;a.set(l,c)}return a},[t]),i=j.useMemo(()=>Array.from(o.keys()),[o]),r=e?o.get(e):null,s=j.useMemo(()=>{if(!r)return{instance:null,error:null,classFound:!1};const a=y_e[r.solverName];if(!a)return{instance:null,error:`Solver class "${r.solverName}" not found in SOLVERS registry. Available: ${Object.keys(y_e).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?K.jsx("div",{className:"rf-p-4",children:K.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:K.jsxs("div",{className:"rf-p-4",children:[K.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),K.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."})]})})}):K.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[K.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[K.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 K.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=ufo(c.solverName);return K.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[K.jsx(A,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),K.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[K.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:c.componentName}),K.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:c.solverName})]})]})})()},a)})]}),K.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:r?s.instance?K.jsx(PC,{fallback:K.jsx("div",{className:"rf-p-4",children:K.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[K.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),K.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",r.solverName]})]})}),children:K.jsx(lfo,{solver:s.instance})}):K.jsxs("div",{className:"rf-p-4",children:[K.jsxs("div",{className:"rf-mb-4",children:[K.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:r.solverName}),K.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",r.componentName]})]}),s.error&&K.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:K.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),K.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[K.jsx("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50",children:K.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"})}),K.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:K.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)})})]})]}):K.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:K.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},CIt=({errorMessage:t,errorStack:e,circuitJsonErrors:n})=>{j.useEffect(()=>{if(t){const o=new Error(t);e&&(o.stack=e);try{Uw.captureException(o)}catch{}}},[t,e]),j.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{Uw.captureException(i,{error_type:o.type})}catch{}}},[n])},IIt=t=>{j.useEffect(()=>{try{j5n(t)}catch{}},[t.source,t.component,t.isWebEmbedded,t.activeTab])},EIt="0.0.2023",dfo={version:EIt},cZ=qJe()($Je(t=>({lastRunEvalVersion:void 0,setLastRunEvalVersion:e=>{t({lastRunEvalVersion:e})}}),{name:"runframe-runner-store"})),hfo=t=>{const[e,n]=j.useState([]),[o,i]=j.useState(null),[r,s]=j.useState(""),[a,c]=Cw("eval-version-selection",null),l=cZ(h=>h.setLastRunEvalVersion),A=cZ(h=>h.lastRunEvalVersion);return j.useEffect(()=>{t&&fetch("https://data.jsdelivr.com/v1/package/npm/@tscircuit/eval").then(h=>h.json()).then(h=>{if(Array.isArray(h?.versions)){let d=[...h.versions];h.tags?.latest&&(i(h.tags.latest),d=d.filter(m=>m!==h.tags.latest)),n(d)}}).catch(()=>{})},[t]),j.useEffect(()=>{t&&(a?(window.TSCIRCUIT_LATEST_EVAL_VERSION=a,l(a)):o&&(window.TSCIRCUIT_LATEST_EVAL_VERSION=o,l(o)))},[t,a,o]),{versions:j.useMemo(()=>e.filter(h=>h.includes(r)).slice(0,50),[e,r]),latestVersion:o,lastRunEvalVersion:A,search:r,setSearch:s,selectVersion:h=>{c(h),s("")}}},mfo=({snippetNames:t,onSelect:e,onCancel:n,isOpen:o})=>{const[i,r]=j.useState(""),[s,a]=j.useState("");if(!o)return null;const c=t.filter(u=>u.toLowerCase().includes(s.toLowerCase())),l=s&&!t.includes(s),A=u=>{u.key==="Enter"&&(c.length===1?r(c[0]):l&&r(s))};return K.jsx("div",{className:"rf-fixed rf-inset-0 rf-bg-black rf-bg-opacity-50 rf-flex rf-items-center rf-justify-center rf-z-[100]",children:K.jsxs("div",{className:"rf-bg-white rf-rounded-lg rf-p-6 rf-w-96",children:[K.jsx("h2",{className:"rf-text-lg rf-font-semibold rf-mb-4",children:"Select Snippet"}),K.jsx("input",{type:"text",className:"rf-w-full rf-px-4 rf-py-2 rf-border rf-rounded rf-mb-4",placeholder:"Search snippets or new snippet name...",value:s,onChange:u=>a(u.target.value),onKeyDown:A}),K.jsxs("div",{className:"rf-h-60 rf-overflow-y-auto",children:[c.map(u=>K.jsx("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 ${i===u?"bg-blue-50":""}`,onClick:()=>r(u),children:u},u)),l&&K.jsxs("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 text-blue-500 ${i===s?"bg-blue-50":""}`,onClick:()=>r(s),children:['Create new "',s,'"']})]}),K.jsxs("div",{className:"rf-mt-4 rf-flex rf-justify-end rf-gap-2",children:[K.jsx("button",{type:"button",className:"rf-px-4 rf-py-2 rf-text-gray-600 rf-hover:text-gray-800",onClick:n,children:"Cancel"}),K.jsx("button",{type:"button",className:"rf-px-4 rf-py-2 rf-bg-blue-500 rf-text-white rf-rounded rf-hover:bg-blue-600 rf-disabled:opacity-50",onClick:()=>i&&e(i),disabled:!i,children:i===s?`Create "${i}"`:`Save to ${i}`})]})]})})},gfo=t=>{const e=j.useRef(null),n=i0(o=>o.recentEvents);j.useEffect(()=>{if(n.length===0)return;const o=n[0];o.event_id!==e.current&&(t(o),e.current=o.event_id)},[n,t])};function pfo(t){const e=ffo(t),n=j.forwardRef((o,i)=>{const{children:r,...s}=o,a=j.Children.toArray(r),c=a.find(xfo);if(c){const l=c.props.children,A=a.map(u=>u===c?j.Children.count(l)>1?j.Children.only(null):j.isValidElement(l)?l.props.children:null:u);return K.jsx(e,{...s,ref:i,children:j.isValidElement(l)?j.cloneElement(l,void 0,A):null})}return K.jsx(e,{...s,ref:i,children:r})});return n.displayName=`${t}.Slot`,n}function ffo(t){const e=j.forwardRef((n,o)=>{const{children:i,...r}=n;if(j.isValidElement(i)){const s=Ifo(i),a=Cfo(r,i.props);return i.type!==j.Fragment&&(a.ref=o?F2(o,s):s),j.cloneElement(i,a)}return j.Children.count(i)>1?j.Children.only(null):null});return e.displayName=`${t}.SlotClone`,e}var yfo=Symbol("radix.slottable");function xfo(t){return j.isValidElement(t)&&typeof t.type=="function"&&"__radixId"in t.type&&t.type.__radixId===yfo}function Cfo(t,e){const n={...e};for(const o in e){const i=t[o],r=e[o];/^on[A-Z]/.test(o)?i&&r?n[o]=(...a)=>{const c=r(...a);return i(...a),c}:i&&(n[o]=i):o==="style"?n[o]={...i,...r}:o==="className"&&(n[o]=[i,r].filter(Boolean).join(" "))}return{...t,...n}}function Ifo(t){let e=Object.getOwnPropertyDescriptor(t.props,"ref")?.get,n=e&&"isReactWarning"in e&&e.isReactWarning;return n?t.ref:(e=Object.getOwnPropertyDescriptor(t,"ref")?.get,n=e&&"isReactWarning"in e&&e.isReactWarning,n?t.props.ref:t.props.ref||t.ref)}var lZ="Dialog",[bIt,SIt]=C5(lZ),[Efo,j5]=bIt(lZ),PIt=t=>{const{__scopeDialog:e,children:n,open:o,defaultOpen:i,onOpenChange:r,modal:s=!0}=t,a=j.useRef(null),c=j.useRef(null),[l,A]=m4({prop:o,defaultProp:i??!1,onChange:r,caller:lZ});return K.jsx(Efo,{scope:e,triggerRef:a,contentRef:c,contentId:qg(),titleId:qg(),descriptionId:qg(),open:l,onOpenChange:A,onOpenToggle:j.useCallback(()=>A(u=>!u),[A]),modal:s,children:n})};PIt.displayName=lZ;var vIt="DialogTrigger",BIt=j.forwardRef((t,e)=>{const{__scopeDialog:n,...o}=t,i=j5(vIt,n),r=r0(e,i.triggerRef);return K.jsx(El.button,{type:"button","aria-haspopup":"dialog","aria-expanded":i.open,"aria-controls":i.contentId,"data-state":CSe(i.open),...o,ref:r,onClick:Ir(t.onClick,i.onOpenToggle)})});BIt.displayName=vIt;var ySe="DialogPortal",[bfo,MIt]=bIt(ySe,{forceMount:void 0}),wIt=t=>{const{__scopeDialog:e,forceMount:n,children:o,container:i}=t,r=j5(ySe,e);return K.jsx(bfo,{scope:e,forceMount:n,children:j.Children.map(o,s=>K.jsx(Vy,{present:n||r.open,children:K.jsx(Mq,{asChild:!0,container:i,children:s})}))})};wIt.displayName=ySe;var AZ="DialogOverlay",DIt=j.forwardRef((t,e)=>{const n=MIt(AZ,t.__scopeDialog),{forceMount:o=n.forceMount,...i}=t,r=j5(AZ,t.__scopeDialog);return r.modal?K.jsx(Vy,{present:o||r.open,children:K.jsx(Pfo,{...i,ref:e})}):null});DIt.displayName=AZ;var Sfo=pfo("DialogOverlay.RemoveScroll"),Pfo=j.forwardRef((t,e)=>{const{__scopeDialog:n,...o}=t,i=j5(AZ,n);return K.jsx(Hq,{as:Sfo,allowPinchZoom:!0,shards:[i.contentRef],children:K.jsx(El.div,{"data-state":CSe(i.open),...o,ref:e,style:{pointerEvents:"auto",...o.style}})})}),a9="DialogContent",TIt=j.forwardRef((t,e)=>{const n=MIt(a9,t.__scopeDialog),{forceMount:o=n.forceMount,...i}=t,r=j5(a9,t.__scopeDialog);return K.jsx(Vy,{present:o||r.open,children:r.modal?K.jsx(vfo,{...i,ref:e}):K.jsx(Bfo,{...i,ref:e})})});TIt.displayName=a9;var vfo=j.forwardRef((t,e)=>{const n=j5(a9,t.__scopeDialog),o=j.useRef(null),i=r0(e,n.contentRef,o);return j.useEffect(()=>{const r=o.current;if(r)return dEe(r)},[]),K.jsx(QIt,{...t,ref:i,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:Ir(t.onCloseAutoFocus,r=>{r.preventDefault(),n.triggerRef.current?.focus()}),onPointerDownOutside:Ir(t.onPointerDownOutside,r=>{const s=r.detail.originalEvent,a=s.button===0&&s.ctrlKey===!0;(s.button===2||a)&&r.preventDefault()}),onFocusOutside:Ir(t.onFocusOutside,r=>r.preventDefault())})}),Bfo=j.forwardRef((t,e)=>{const n=j5(a9,t.__scopeDialog),o=j.useRef(!1),i=j.useRef(!1);return K.jsx(QIt,{...t,ref:e,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:r=>{t.onCloseAutoFocus?.(r),r.defaultPrevented||(o.current||n.triggerRef.current?.focus(),r.preventDefault()),o.current=!1,i.current=!1},onInteractOutside:r=>{t.onInteractOutside?.(r),r.defaultPrevented||(o.current=!0,r.detail.originalEvent.type==="pointerdown"&&(i.current=!0));const s=r.target;n.triggerRef.current?.contains(s)&&r.preventDefault(),r.detail.originalEvent.type==="focusin"&&i.current&&r.preventDefault()}})}),QIt=j.forwardRef((t,e)=>{const{__scopeDialog:n,trapFocus:o,onOpenAutoFocus:i,onCloseAutoFocus:r,...s}=t,a=j5(a9,n),c=j.useRef(null),l=r0(e,c);return W3e(),K.jsxs(K.Fragment,{children:[K.jsx(gq,{asChild:!0,loop:!0,trapped:o,onMountAutoFocus:i,onUnmountAutoFocus:r,children:K.jsx(WH,{role:"dialog",id:a.contentId,"aria-describedby":a.descriptionId,"aria-labelledby":a.titleId,"data-state":CSe(a.open),...s,ref:l,onDismiss:()=>a.onOpenChange(!1)})}),K.jsxs(K.Fragment,{children:[K.jsx(wfo,{titleId:a.titleId}),K.jsx(Tfo,{contentRef:c,descriptionId:a.descriptionId})]})]})}),xSe="DialogTitle",RIt=j.forwardRef((t,e)=>{const{__scopeDialog:n,...o}=t,i=j5(xSe,n);return K.jsx(El.h2,{id:i.titleId,...o,ref:e})});RIt.displayName=xSe;var NIt="DialogDescription",kIt=j.forwardRef((t,e)=>{const{__scopeDialog:n,...o}=t,i=j5(NIt,n);return K.jsx(El.p,{id:i.descriptionId,...o,ref:e})});kIt.displayName=NIt;var HIt="DialogClose",LIt=j.forwardRef((t,e)=>{const{__scopeDialog:n,...o}=t,i=j5(HIt,n);return K.jsx(El.button,{type:"button",...o,ref:e,onClick:Ir(t.onClick,()=>i.onOpenChange(!1))})});LIt.displayName=HIt;function CSe(t){return t?"open":"closed"}var FIt="DialogTitleWarning",[Mfo,OIt]=j2n(FIt,{contentName:a9,titleName:xSe,docsSlug:"dialog"}),wfo=({titleId:t})=>{const e=OIt(FIt),n=`\`${e.contentName}\` requires a \`${e.titleName}\` for the component to be accessible for screen reader users.
|
|
5749
5749
|
|
|
5750
5750
|
If you want to hide the \`${e.titleName}\`, you can wrap it with our VisuallyHidden component.
|
|
5751
5751
|
|