@tscircuit/runframe 0.0.1750 → 0.0.1752
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
|
@@ -5153,7 +5153,7 @@ ${a.join(`
|
|
|
5153
5153
|
${Q}polygon: ${C.polygon.vertices}
|
|
5154
5154
|
`:a+=`
|
|
5155
5155
|
`,C.children.length>0&&c.push(C.children)}return a}};A.exports=s}}),CFt=ae({"node_modules/@jscad/modeling/src/operations/booleans/trees/Tree.js"(t,A){var e=cFt(),i=BFt(),n=class{constructor(o){this.polygonTree=new i,this.rootnode=new e(null),o&&this.addPolygons(o)}invert(){this.polygonTree.invert(),this.rootnode.invert()}clipTo(o,s=!1){this.rootnode.clipTo(o,s)}allPolygons(){const o=[];return this.polygonTree.getPolygons(o),o}addPolygons(o){const s=new Array(o.length);for(let r=0;r<o.length;r++)s[r]=this.polygonTree.addChild(o[r]);this.rootnode.addPolygonTreeNodes(s)}clear(){this.polygonTree.clear()}toString(){return"Tree: "+this.polygonTree.toString("")}};A.exports=n}}),XdA=ae({"node_modules/@jscad/modeling/src/operations/booleans/trees/index.js"(t,A){A.exports={Tree:CFt()}}}),QFt=ae({"node_modules/@jscad/modeling/src/operations/booleans/intersectGeom3Sub.js"(t,A){var e=es(),i=zdA(),{Tree:n}=XdA(),o=(s,r)=>{if(!i(s,r))return e.create();const a=new n(e.toPolygons(s)),g=new n(e.toPolygons(r));a.invert(),g.clipTo(a),g.invert(),a.clipTo(g),g.clipTo(a),a.addPolygons(g.allPolygons()),a.invert();const c=a.allPolygons();return e.create(c)};A.exports=o}}),lie=ae({"node_modules/@jscad/modeling/src/operations/booleans/intersectGeom3.js"(t,A){var e=vo(),i=rJ(),n=QFt(),o=(...s)=>{s=e(s);let r=s.shift();return s.forEach(a=>{r=n(r,a)}),r=i(r),r};A.exports=o}}),hFt=ae({"node_modules/@jscad/modeling/src/operations/booleans/intersectGeom2.js"(t,A){var e=vo(),i=es(),n=Ck(),o=VdA(),s=jdA(),r=lie(),a=(...g)=>{g=e(g);const c=g.map(B=>s({z0:-1,z1:1},B)),I=r(c),l=n(I);return o(l,i.toPolygons(I))};A.exports=a}}),EFt=ae({"node_modules/@jscad/modeling/src/operations/booleans/intersect.js"(t,A){var e=vo(),i=sJ(),n=ss(),o=es(),s=hFt(),r=lie(),a=(...g)=>{if(g=e(g),g.length===0)throw new Error("wrong number of arguments");if(!i(g))throw new Error("only intersect of the types are supported");const c=g[0];return n.isA(c)?s(g):o.isA(c)?r(g):c};A.exports=a}}),$dA=ae({"node_modules/@jscad/modeling/src/operations/hulls/hullPoints3.js"(t,A){var e=er(),i=Ete(),n=o=>i(o,{skipTriangulation:!0}).map(a=>{const g=a.map(c=>o[c]);return e.create(g)});A.exports=n}}),Bie=ae({"node_modules/@jscad/modeling/src/operations/booleans/unionGeom3Sub.js"(t,A){var e=es(),i=zdA(),{Tree:n}=XdA(),o=(r,a)=>{if(!i(r,a))return s(r,a);const g=new n(e.toPolygons(r)),c=new n(e.toPolygons(a));g.clipTo(c,!1),c.clipTo(g),c.invert(),c.clipTo(g),c.invert();const I=g.allPolygons().concat(c.allPolygons());return e.create(I)},s=(r,a)=>{let g=e.toPolygons(r);return g=g.concat(e.toPolygons(a)),e.create(g)};A.exports=o}}),ApA=ae({"node_modules/@jscad/modeling/src/operations/booleans/unionGeom3.js"(t,A){var e=vo(),i=rJ(),n=Bie(),o=(...s)=>{s=e(s);let r;for(r=1;r<s.length;r+=2)s.push(n(s[r-1],s[r]));let a=s[r-1];return a=i(a),a};A.exports=o}}),Cie=ae({"node_modules/@jscad/modeling/src/operations/minkowski/minkowskiSum.js"(t,A){var e=vo(),i=es(),n=er(),o=$dA(),s=ApA(),r=(...B)=>{if(B=e(B),B.length!==2)throw new Error("minkowskiSum requires exactly two geometries");const[C,Q]=B;if(!i.isA(C)||!i.isA(Q))throw new Error("minkowskiSum requires geom3 geometries");const h=i.isConvex(C),E=i.isConvex(Q);if(h&&E)return I(C,Q);if(!h&&E)return a(C,Q);if(h&&!E)return a(Q,C);throw new Error("minkowskiSum of two non-convex geometries is not yet supported")},a=(B,C)=>{const Q=g(B);if(Q.length===0)return i.create();const h=Q.map(E=>I(E,C));return h.length===1?h[0]:s(h)},g=B=>{const C=i.toPolygons(B);if(C.length===0)return[];const Q=[];for(let h=0;h<C.length;h++){const E=C[h],u=E.vertices;let d=0,f=0,y=0;for(let F=0;F<u.length;F++)d+=u[F][0],f+=u[F][1],y+=u[F][2];d/=u.length,f/=u.length,y/=u.length;const w=n.plane(E),D=w[0],S=w[1],_=w[2],b=.1,N=[d-D*b,f-S*b,y-_*b];for(let F=1;F<u.length-1;F++){const L=u[0],Y=u[F],J=u[F+1],O=c(N,L,Y,J);Q.push(i.create(O))}}return Q},c=(B,C,Q,h)=>[n.create([B,Q,C]),n.create([B,C,h]),n.create([C,Q,h]),n.create([Q,B,h])],I=(B,C)=>{const Q=l(B),h=l(C);if(Q.length===0||h.length===0)return i.create();const E=[];for(let d=0;d<Q.length;d++){const f=Q[d];for(let y=0;y<h.length;y++){const w=h[y];E.push([f[0]+w[0],f[1]+w[1],f[2]+w[2]])}}const u=o(E);return i.create(u)},l=B=>{const C=new Set,Q=[],h=i.toPolygons(B);for(let E=0;E<h.length;E++){const u=h[E].vertices;for(let d=0;d<u.length;d++){const f=u[d],y=`${f[0]},${f[1]},${f[2]}`;C.has(y)||(C.add(y),Q.push(f))}}return Q};A.exports=r}}),uFt=ae({"node_modules/@jscad/modeling/src/operations/booleans/scissionGeom3.js"(t,A){var e=xn(),i=Ck(),n=es(),o=g=>g.sort((c,I)=>c-I).filter((c,I,l)=>!I||c!==l[I-1]),s=(g,c,I)=>{const l=`${c}`,B=g.get(l);B===void 0?g.set(l,[I]):B.push(I)},r=(g,c)=>{const I=`${c}`;return g.get(I)},a=g=>{const c=i(g),I=n.toPolygons(g),l=I.length,B=new Map,C=e.create();I.forEach((d,f)=>{d.vertices.forEach(y=>{s(B,e.snap(C,y,c),f)})});const Q=I.map(d=>{let f=[];return d.vertices.forEach(y=>{f=f.concat(r(B,e.snap(C,y,c)))}),{e:1,d:o(f)}});B.clear();let h=0;const E=Q.length;for(let d=0;d<E;d++){const f=Q[d];if(f.e>0){const y=new Array(l);y[d]=!0;do h=0,y.forEach((w,D)=>{const S=Q[D];if(S.e>0){S.e=-1;for(let _=0;_<S.d.length;_++)y[S.d[_]]=!0;h++}});while(h>0);f.indexes=y}}const u=[];for(let d=0;d<E;d++)if(Q[d].indexes){const f=[];Q[d].indexes.forEach((y,w)=>f.push(I[w])),u.push(n.create(f))}return u};A.exports=a}}),dFt=ae({"node_modules/@jscad/modeling/src/operations/booleans/scission.js"(t,A){var e=vo(),i=es(),n=uFt(),o=(...s)=>{if(s=e(s),s.length===0)throw new Error("wrong number of arguments");const r=s.map(a=>i.isA(a)?n(a):a);return r.length===1?r[0]:r};A.exports=o}}),pFt=ae({"node_modules/@jscad/modeling/src/operations/booleans/subtractGeom3Sub.js"(t,A){var e=es(),i=zdA(),{Tree:n}=XdA(),o=(s,r)=>{if(!i(s,r))return e.clone(s);const a=new n(e.toPolygons(s)),g=new n(e.toPolygons(r));a.invert(),a.clipTo(g),g.clipTo(a,!0),a.addPolygons(g.allPolygons()),a.invert();const c=a.allPolygons();return e.create(c)};A.exports=o}}),Qie=ae({"node_modules/@jscad/modeling/src/operations/booleans/subtractGeom3.js"(t,A){var e=vo(),i=rJ(),n=pFt(),o=(...s)=>{s=e(s);let r=s.shift();return s.forEach(a=>{r=n(r,a)}),r=i(r),r};A.exports=o}}),fFt=ae({"node_modules/@jscad/modeling/src/operations/booleans/subtractGeom2.js"(t,A){var e=vo(),i=es(),n=Ck(),o=VdA(),s=jdA(),r=Qie(),a=(...g)=>{g=e(g);const c=g.map(B=>s({z0:-1,z1:1},B)),I=r(c),l=n(I);return o(l,i.toPolygons(I))};A.exports=a}}),yFt=ae({"node_modules/@jscad/modeling/src/operations/booleans/subtract.js"(t,A){var e=vo(),i=sJ(),n=ss(),o=es(),s=fFt(),r=Qie(),a=(...g)=>{if(g=e(g),g.length===0)throw new Error("wrong number of arguments");if(!i(g))throw new Error("only subtract of the types are supported");const c=g[0];return n.isA(c)?s(g):o.isA(c)?r(g):c};A.exports=a}}),hie=ae({"node_modules/@jscad/modeling/src/operations/booleans/unionGeom2.js"(t,A){var e=vo(),i=es(),n=Ck(),o=VdA(),s=jdA(),r=ApA(),a=(...g)=>{g=e(g);const c=g.map(B=>s({z0:-1,z1:1},B)),I=r(c),l=n(I);return o(l,i.toPolygons(I))};A.exports=a}}),epA=ae({"node_modules/@jscad/modeling/src/operations/booleans/union.js"(t,A){var e=vo(),i=sJ(),n=ss(),o=es(),s=hie(),r=ApA(),a=(...g)=>{if(g=e(g),g.length===0)throw new Error("wrong number of arguments");if(!i(g))throw new Error("only unions of the same type are supported");const c=g[0];return n.isA(c)?s(g):o.isA(c)?r(g):c};A.exports=a}}),aJ=ae({"node_modules/@jscad/modeling/src/operations/booleans/index.js"(t,A){A.exports={intersect:EFt(),minkowski:Cie(),scission:dFt(),subtract:yFt(),union:epA()}}}),YV=ae({"node_modules/@jscad/modeling/src/operations/expansions/offsetFromPoints.js"(t,A){var{EPS:e,TAU:i}=Qr(),n=qte(),o=KdA(),s=ks(),r=LV(),a=(g,c)=>{const I={delta:1,corners:"edge",closed:!1,segments:16};let{delta:l,corners:B,closed:C,segments:Q}=Object.assign({},I,g);if(Math.abs(l)<e)return c;let h=g.closed?r(c):1;h===0&&(h=1);const E=h>0&&l>=0||h<0&&l<0;l=Math.abs(l);let u=null,d=[];const f=[],y=s.create(),w=c.length;for(let D=0;D<w;D++){const S=(D+1)%w,_=c[D],b=c[S];E?s.subtract(y,_,b):s.subtract(y,b,_),s.normal(y,y),s.normalize(y,y),s.scale(y,y,l);const N=s.add(s.create(),_,y),F=s.add(s.create(),b,y),L=[N,F];if(u!=null&&(C||!C&&S!==0)){const Y=n(u[0],u[1],L[0],L[1]);Y?(d.pop(),L[0]=Y):f.push({c:_,s0:u,s1:L})}u=[N,F],!(S===0&&!C)&&(d.push(L[0]),d.push(L[1]))}if(C&&u!=null){const D=d[0],S=d[1],_=n(u[0],u[1],D,S);if(_)d[0]=_,d.pop();else{const b=c[0],N=[D,S];f.push({c:b,s0:u,s1:N})}}if(B==="edge"){const D=new Map;d.forEach((b,N)=>D.set(b,N));const S=o.create(),_=o.create();f.forEach(b=>{o.fromPoints(S,b.s0[0],b.s0[1]),o.fromPoints(_,b.s1[0],b.s1[1]);const N=o.intersectPointOfLines(S,_);if(Number.isFinite(N[0])&&Number.isFinite(N[1])){const F=b.s0[1],L=D.get(F);d[L]=N,d[(L+1)%d.length]=void 0}else{const F=b.s1[0],L=D.get(F);d[L]=void 0}}),d=d.filter(b=>b!==void 0)}if(B==="round"){let D=Math.floor(Q/4);const S=s.create();f.forEach(_=>{let b=s.angle(s.subtract(S,_.s1[0],_.c));if(b-=s.angle(s.subtract(S,_.s0[1],_.c)),E&&b<0&&(b=b+Math.PI,b<0&&(b=b+Math.PI)),!E&&b>0&&(b=b-Math.PI,b>0&&(b=b-Math.PI)),b!==0){D=Math.floor(Q*(Math.abs(b)/i));const N=b/D,F=s.angle(s.subtract(S,_.s0[1],_.c)),L=[];for(let Y=1;Y<D;Y++){const J=F+N*Y,O=s.fromAngleRadians(s.create(),J);s.scale(O,O,l),s.add(O,O,_.c),L.push(O)}if(L.length>0){const Y=_.s0[1];let J=d.findIndex(O=>s.equals(Y,O));J=(J+1)%d.length,d.splice(J,0,...L)}}else{const N=_.s1[0],F=d.findIndex(L=>s.equals(N,L));d.splice(F,1)}})}return d};A.exports=a}}),mFt=ae({"node_modules/@jscad/modeling/src/operations/expansions/expandGeom2.js"(t,A){var e=ss(),i=YV(),n=(o,s)=>{const r={delta:1,corners:"edge",segments:16},{delta:a,corners:g,segments:c}=Object.assign({},r,o);if(!(g==="edge"||g==="chamfer"||g==="round"))throw new Error('corners must be "edge", "chamfer", or "round"');const B=e.toOutlines(s).map(C=>(o={delta:a,corners:g,closed:!0,segments:c},i(o,C))).reduce((C,Q)=>C.concat(e.toSides(e.fromPoints(Q))),[]);return e.create(B)};A.exports=n}}),wFt=ae({"node_modules/@jscad/modeling/src/operations/expansions/extrudePolygon.js"(t,A){var e=ic(),i=xn(),n=es(),o=er(),s=(r,a)=>{i.dot(o.plane(a),r)>0&&(a=o.invert(a));const c=[a],I=o.transform(e.fromTranslation(e.create(),r),a),l=a.vertices.length;for(let B=0;B<l;B++){const C=B<l-1?B+1:0,Q=o.create([a.vertices[B],I.vertices[B],I.vertices[C],a.vertices[C]]);c.push(Q)}return c.push(o.invert(I)),n.create(c)};A.exports=s}}),DFt=ae({"node_modules/@jscad/modeling/src/operations/expansions/expandShell.js"(t,A){var{EPS:e,TAU:i}=Qr(),n=ic(),o=xn(),s=cie(),r=es(),a=er(),g=iie(),c=rJ(),I=Bie(),l=wFt(),B=(E,u,d)=>{const f=u.toString();if(E.has(f))E.get(f)[1].push(d);else{const y=[u,[d]];E.set(f,y)}},C=(E,u,d)=>{const f=u[0].toString(),y=u[1].toString(),w=f<y?`${f},${y}`:`${y},${f}`;if(E.has(w))E.get(w)[1].push(d);else{const D=[u,[d]];E.set(w,D)}},Q=(E,u)=>{E.findIndex(f=>f===u)<0&&E.push(u)},h=(E,u)=>{const d={delta:1,segments:12},{delta:f,segments:y}=Object.assign({},d,E);let w=r.create();const D=new Map,S=new Map,_=o.create(),b=o.create();return r.toPolygons(u).forEach((F,L)=>{const Y=o.scale(o.create(),a.plane(F),2*f),J=a.transform(n.fromTranslation(n.create(),o.scale(o.create(),Y,-.5)),F),O=l(Y,J);w=I(w,O);const Z=F.vertices;for(let X=0;X<Z.length;X++){B(D,Z[X],a.plane(F));const eA=(X+1)%Z.length,gA=[Z[X],Z[eA]];C(S,gA,a.plane(F))}}),S.forEach(F=>{const L=F[0],Y=F[1],J=L[0],O=L[1],Z=o.subtract(o.create(),O,J);o.normalize(Z,Z);const X=Y[0],eA=o.cross(o.create(),X,Z);let gA=[];for(let LA=0;LA<y;LA++)Q(gA,LA*i/y);for(let LA=0,QA=Y.length;LA<QA;LA++){const kA=Y[LA],dA=o.dot(eA,kA),qA=o.dot(X,kA);let VA=Math.atan2(dA,qA);VA<0&&(VA+=i),Q(gA,VA),VA=Math.atan2(-dA,-qA),VA<0&&(VA+=i),Q(gA,VA)}gA=gA.sort(s);const tA=gA.length;let iA,sA;const aA=[],EA=[],bA=[];for(let LA=-1;LA<tA;LA++){const QA=gA[LA<0?LA+tA:LA],kA=Math.sin(QA),dA=Math.cos(QA);o.scale(_,X,dA*f),o.scale(b,eA,kA*f),o.add(_,_,b);const qA=o.add(o.create(),J,_),VA=o.add(o.create(),O,_);let ce=!1;if(LA>=0&&o.distance(qA,iA)<e&&(ce=!0),!ce){if(LA>=0){aA.push(qA),EA.push(VA);const fA=[sA,VA,qA,iA],ge=a.create(fA);bA.push(ge)}iA=qA,sA=VA}}EA.reverse(),bA.push(a.create(aA)),bA.push(a.create(EA));const _A=r.create(bA);w=I(w,_A)}),D.forEach(F=>{const L=F[0],Y=F[1],J=Y[0];let O=null,Z=0;for(let tA=1;tA<Y.length;tA++){const iA=Y[tA],sA=o.cross(_,J,iA),aA=o.length(sA);aA>.05&&aA>Z&&(Z=aA,O=iA)}O||(O=o.orthogonal(_,J));const X=o.cross(_,J,O);o.normalize(X,X);const eA=o.cross(b,X,J),gA=g({center:[L[0],L[1],L[2]],radius:f,segments:y,axes:[J,X,eA]});w=I(w,gA)}),c(w)};A.exports=h}}),SFt=ae({"node_modules/@jscad/modeling/src/operations/expansions/expandGeom3.js"(t,A){var e=es(),i=epA(),n=DFt(),o=(s,r)=>{const a={delta:1,corners:"round",segments:12},{delta:g,corners:c,segments:I}=Object.assign({},a,s);if(c!=="round")throw new Error('corners must be "round" for 3D geometries');if(e.toPolygons(r).length===0)throw new Error("the given geometry cannot be empty");s={delta:g,corners:c,segments:I};const B=n(s,r);return i(r,B)};A.exports=o}}),bFt=ae({"node_modules/@jscad/modeling/src/operations/expansions/expandPath2.js"(t,A){var e=LV(),i=ks(),n=ss(),o=Lg(),s=YV(),r=c=>{let{external:I,internal:l}=c;e(I)<0?I=I.reverse():l=l.reverse();const B=o.fromPoints({closed:!0},I),C=o.fromPoints({closed:!0},l),Q=n.toSides(n.fromPoints(o.toPoints(B))),h=n.toSides(n.fromPoints(o.toPoints(C)));return Q.push(...h),n.create(Q)},a=(c,I,l,B)=>{const{points:C,external:Q,internal:h}=c,E=Math.floor(I/2),u=[],d=[];if(l==="round"&&E>0){const y=Math.PI/E,w=C[C.length-1],D=i.angle(i.subtract(i.create(),Q[Q.length-1],w)),S=C[0],_=i.angle(i.subtract(i.create(),h[0],S));for(let b=1;b<E;b++){let N=D+y*b,F=i.fromAngleRadians(i.create(),N);i.scale(F,F,B),i.add(F,F,w),u.push(F),N=_+y*b,F=i.fromAngleRadians(i.create(),N),i.scale(F,F,B),i.add(F,F,S),d.push(F)}}const f=[];return f.push(...Q,...u,...h.reverse(),...d),n.fromPoints(f)},g=(c,I)=>{c=Object.assign({},{delta:1,corners:"edge",segments:16},c);const{delta:B,corners:C,segments:Q}=c;if(B<=0)throw new Error("the given delta must be positive for paths");if(!(C==="edge"||C==="chamfer"||C==="round"))throw new Error('corners must be "edge", "chamfer", or "round"');const h=I.isClosed,E=o.toPoints(I);if(E.length===0)throw new Error("the given geometry cannot be empty");const u={points:E,external:s({delta:B,corners:C,segments:Q,closed:h},E),internal:s({delta:-B,corners:C,segments:Q,closed:h},E)};return I.isClosed?r(u):a(u,Q,C,B)};A.exports=g}}),tpA=ae({"node_modules/@jscad/modeling/src/operations/expansions/expand.js"(t,A){var e=vo(),i=ss(),n=es(),o=Lg(),s=mFt(),r=SFt(),a=bFt(),g=(c,...I)=>{if(I=e(I),I.length===0)throw new Error("wrong number of arguments");const l=I.map(B=>o.isA(B)?a(c,B):i.isA(B)?s(c,B):n.isA(B)?r(c,B):B);return l.length===1?l[0]:l};A.exports=g}}),xFt=ae({"node_modules/@jscad/modeling/src/operations/expansions/offsetGeom2.js"(t,A){var e=ss(),i=HdA(),n=YV(),o=(s,r)=>{const a={delta:1,corners:"edge",segments:0},{delta:g,corners:c,segments:I}=Object.assign({},a,s);if(!(c==="edge"||c==="chamfer"||c==="round"))throw new Error('corners must be "edge", "chamfer", or "round"');const l=e.toOutlines(r),C=l.map(Q=>(s={delta:l.reduce((u,d)=>u+i.arePointsInside(Q,i.create(d)),0)%2===0?g:-g,corners:c,closed:!0,segments:I},n(s,Q))).reduce((Q,h)=>Q.concat(e.toSides(e.fromPoints(h))),[]);return e.create(C)};A.exports=o}}),_Ft=ae({"node_modules/@jscad/modeling/src/operations/expansions/offsetPath2.js"(t,A){var e=Lg(),i=YV(),n=(o,s)=>{const r={delta:1,corners:"edge",closed:s.isClosed,segments:16},{delta:a,corners:g,closed:c,segments:I}=Object.assign({},r,o);if(!(g==="edge"||g==="chamfer"||g==="round"))throw new Error('corners must be "edge", "chamfer", or "round"');o={delta:a,corners:g,closed:c,segments:I};const l=i(o,e.toPoints(s));return e.fromPoints({closed:c},l)};A.exports=n}}),kFt=ae({"node_modules/@jscad/modeling/src/operations/expansions/offset.js"(t,A){var e=vo(),i=ss(),n=Lg(),o=xFt(),s=_Ft(),r=(a,...g)=>{if(g=e(g),g.length===0)throw new Error("wrong number of arguments");const c=g.map(I=>n.isA(I)?s(a,I):i.isA(I)?o(a,I):I);return c.length===1?c[0]:c};A.exports=r}}),Eie=ae({"node_modules/@jscad/modeling/src/operations/expansions/index.js"(t,A){A.exports={expand:tpA(),offset:kFt()}}}),JV=ae({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeLinearGeom2.js"(t,A){var e=ic(),i=xn(),n=ss(),o=b1(),s=HV(),r=(a,g)=>{const c={offset:[0,0,1],twistAngle:0,twistSteps:12,repair:!0};let{offset:I,twistAngle:l,twistSteps:B,repair:C}=Object.assign({},c,a);if(B<1)throw new Error("twistSteps must be 1 or more");l===0&&(B=1);const Q=i.clone(I),h=n.toSides(g);if(h.length===0)throw new Error("the given geometry cannot be empty");const E=o.fromSides(h);Q[2]<0&&o.reverse(E,E);const u=e.create(),d=(f,y,w)=>{const D=y/B*l,S=i.scale(i.create(),Q,y/B);return e.multiply(u,e.fromZRotation(u,D),e.fromTranslation(e.create(),S)),o.transform(u,w)};return a={numberOfSlices:B+1,capStart:!0,capEnd:!0,repair:C,callback:d},s(a,E)};A.exports=r}}),vFt=ae({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeLinearPath2.js"(t,A){var e=ss(),i=Lg(),n=JV(),o=(s,r)=>{if(!r.isClosed)throw new Error("extruded path must be closed");const a=i.toPoints(r),g=e.fromPoints(a);return n(s,g)};A.exports=o}}),FFt=ae({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeLinear.js"(t,A){var e=vo(),i=ss(),n=Lg(),o=JV(),s=vFt(),r=(a,...g)=>{const c={height:1,twistAngle:0,twistSteps:1,repair:!0},{height:I,twistAngle:l,twistSteps:B,repair:C}=Object.assign({},c,a);if(g=e(g),g.length===0)throw new Error("wrong number of arguments");a={offset:[0,0,I],twistAngle:l,twistSteps:B,repair:C};const Q=g.map(h=>n.isA(h)?s(a,h):i.isA(h)?o(a,h):h);return Q.length===1?Q[0]:Q};A.exports=r}}),MFt=ae({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeRectangularPath2.js"(t,A){var e=Lg(),i=tpA(),n=JV(),o=(s,r)=>{const a={size:1,height:1},{size:g,height:c}=Object.assign({},a,s);if(s.delta=g,s.offset=[0,0,c],e.toPoints(r).length===0)throw new Error("the given geometry cannot be empty");const l=i(s,r);return n(s,l)};A.exports=o}}),RFt=ae({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeRectangularGeom2.js"(t,A){var{area:e}=tJ(),i=ss(),n=Lg(),o=tpA(),s=JV(),r=(a,g)=>{const c={size:1,height:1},{size:I,height:l}=Object.assign({},c,a);a.delta=I,a.offset=[0,0,l];const B=i.toOutlines(g);if(B.length===0)throw new Error("the given geometry cannot be empty");const Q=B.map(E=>(e(E)<0&&E.reverse(),o(a,n.fromPoints({closed:!0},E)))).reduce((E,u)=>E.concat(i.toSides(u)),[]),h=i.create(Q);return s(a,h)};A.exports=r}}),NFt=ae({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeRectangular.js"(t,A){var e=vo(),i=ss(),n=Lg(),o=MFt(),s=RFt(),r=(a,...g)=>{const c={size:1,height:1},{size:I,height:l}=Object.assign({},c,a);if(g=e(g),g.length===0)throw new Error("wrong number of arguments");if(I<=0)throw new Error("size must be positive");if(l<=0)throw new Error("height must be positive");const B=g.map(C=>n.isA(C)?o(a,C):i.isA(C)?s(a,C):C);return B.length===1?B[0]:B};A.exports=r}}),GFt=ae({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeHelical.js"(t,A){var{TAU:e}=Qr(),i=ic(),n=ss(),o=HV(),s=b1(),r=(a,g)=>{const c={angle:e,startAngle:0,pitch:10,height:0,endOffset:0,segmentsPerRotation:32};let{angle:I,startAngle:l,pitch:B,height:C,endOffset:Q,segmentsPerRotation:h}=Object.assign({},c,a);if(C!=0&&(B=C/(I/e)),h<3)throw new Error("The number of segments per rotation needs to be at least 3.");const u=n.toSides(g);if(u.length===0)throw new Error("The given geometry cannot be empty");const d=u.filter(b=>b[0][0]>=0);let f=s.fromSides(u);d.length===0&&(f=s.reverse(f));const y=Math.round(h/e*Math.abs(I)),w=y>=2?y:2,D=i.create(),S=i.create(),_=(b,N,F)=>{const L=l+I/w*N,Y=Q/w*N,J=(L-l)/e*B;return i.multiply(D,i.fromTranslation(i.create(),[Y,0,J*Math.sign(I)]),i.fromXRotation(i.create(),-e/4*Math.sign(I))),i.multiply(S,i.fromZRotation(i.create(),L),D),s.transform(S,F)};return o({numberOfSlices:w+1,callback:_},f)};A.exports=r}}),LFt=ae({"node_modules/@jscad/modeling/src/operations/extrusions/project.js"(t,A){var e=vo(),i=PdA(),n=zD(),o=ic(),s=ss(),r=es(),a=er(),g=Ck(),c=hie(),I=(B,C)=>{const Q=n.fromNormalAndPoint(n.create(),B.axis,B.origin);if(Number.isNaN(Q[0])||Number.isNaN(Q[1])||Number.isNaN(Q[2])||Number.isNaN(Q[3]))throw new Error("project: invalid axis or origin");const h=g(C),E=h*h*Math.sqrt(3)/4;if(h===0)return s.create();const u=r.toPolygons(C);let d=[];for(let y=0;y<u.length;y++){const w=u[y].vertices.map(_=>n.projectionOfPoint(Q,_)),D=a.create(w),S=a.plane(D);i(Q,S)&&(a.measureArea(D)<E||d.push(D))}if(!i(Q,[0,0,1])){const y=o.fromVectorRotation(o.create(),Q,[0,0,1]);d=d.map(w=>a.transform(y,w))}d=d.sort((y,w)=>a.measureArea(w)-a.measureArea(y));const f=d.map(y=>s.fromPoints(y.vertices));return c(f)},l=(B,...C)=>{const Q={axis:[0,0,1],origin:[0,0,0]},{axis:h,origin:E}=Object.assign({},Q,B);if(C=e(C),C.length===0)throw new Error("wrong number of arguments");B={axis:h,origin:E};const u=C.map(d=>r.isA(d)?I(B,d):d);return u.length===1?u[0]:u};A.exports=l}}),gJ=ae({"node_modules/@jscad/modeling/src/operations/extrusions/index.js"(t,A){A.exports={extrudeFromSlices:HV(),extrudeLinear:FFt(),extrudeRectangular:NFt(),extrudeRotate:rie(),extrudeHelical:GFt(),project:LFt(),slice:b1()}}}),ipA=ae({"node_modules/@jscad/modeling/src/operations/hulls/hullPoints2.js"(t,A){var e=ks(),i=s=>{let r=e.fromValues(1/0,1/0);s.forEach(c=>{(c[1]<r[1]||c[1]===r[1]&&c[0]<r[0])&&(r=c)});const a=[];s.forEach(c=>{const I=o(c[1]-r[1],c[0]-r[0]),l=e.squaredDistance(c,r);a.push({point:c,angle:I,distSq:l})}),a.sort((c,I)=>c.angle!==I.angle?c.angle-I.angle:c.distSq-I.distSq);const g=[];return a.forEach(c=>{let I=g.length;for(;I>1&&n(g[I-2],g[I-1],c.point)<=Number.EPSILON;)g.pop(),I=g.length;g.push(c.point)}),g},n=(s,r,a)=>(r[0]-s[0])*(a[1]-s[1])-(r[1]-s[1])*(a[0]-s[0]),o=(s,r)=>s===0&&r===0?-1/0:-r/s;A.exports=i}}),npA=ae({"node_modules/@jscad/modeling/src/operations/hulls/toUniquePoints.js"(t,A){var e=ss(),i=es(),n=Lg(),o=s=>{const r=new Set,a=[],g=c=>{const I=c.toString();r.has(I)||(a.push(c),r.add(I))};return s.forEach(c=>{e.isA(c)?e.toPoints(c).forEach(g):i.isA(c)?i.toPoints(c).forEach(I=>I.forEach(g)):n.isA(c)&&n.toPoints(c).forEach(g)}),a};A.exports=o}}),UFt=ae({"node_modules/@jscad/modeling/src/operations/hulls/hullPath2.js"(t,A){var e=vo(),i=Lg(),n=ipA(),o=npA(),s=(...r)=>{r=e(r);const a=o(r),g=n(a);return i.fromPoints({closed:!0},g)};A.exports=s}}),HFt=ae({"node_modules/@jscad/modeling/src/operations/hulls/hullGeom2.js"(t,A){var e=vo(),i=ss(),n=ipA(),o=npA(),s=(...r)=>{r=e(r);const a=o(r),g=n(a);return g.length<3?i.create():i.fromPoints(g)};A.exports=s}}),YFt=ae({"node_modules/@jscad/modeling/src/operations/hulls/hullGeom3.js"(t,A){var e=vo(),i=es(),n=npA(),o=$dA(),s=(...r)=>{r=e(r);const a=n(r);return a.length===0?i.create():i.create(o(a))};A.exports=s}}),uie=ae({"node_modules/@jscad/modeling/src/operations/hulls/hull.js"(t,A){var e=vo(),i=sJ(),n=ss(),o=es(),s=Lg(),r=UFt(),a=HFt(),g=YFt(),c=(...I)=>{if(I=e(I),I.length===0)throw new Error("wrong number of arguments");if(!i(I))throw new Error("only hulls of the same type are supported");const l=I[0];return s.isA(l)?r(I):n.isA(l)?a(I):o.isA(l)?g(I):l};A.exports=c}}),JFt=ae({"node_modules/@jscad/modeling/src/operations/hulls/hullChain.js"(t,A){var e=vo(),i=epA(),n=uie(),o=(...s)=>{if(s=e(s),s.length<2)throw new Error("wrong number of arguments");const r=[];for(let a=1;a<s.length;a++)r.push(n(s[a-1],s[a]));return i(r)};A.exports=o}}),TFt=ae({"node_modules/@jscad/modeling/src/operations/hulls/index.js"(t,A){A.exports={hull:uie(),hullChain:JFt(),hullPoints2:ipA(),hullPoints3:$dA()}}}),PFt=ae({"node_modules/@jscad/modeling/src/operations/minkowski/index.js"(t,A){A.exports={minkowskiSum:Cie()}}}),die=ae({"node_modules/@jscad/modeling/src/operations/modifiers/snapPolygons.js"(t,A){var e=xn(),i=er(),n=(s,r)=>{const a=Math.abs(i.measureArea(r));return Number.isFinite(a)&&a>s},o=(s,r)=>{let a=r.map(c=>{const I=c.vertices.map(C=>e.snap(e.create(),C,s)),l=[];for(let C=0;C<I.length;C++){const Q=(C+1)%I.length;e.equals(I[C],I[Q])||l.push(I[C])}const B=i.create(l);return c.color&&(B.color=c.color),B});const g=s*s*Math.sqrt(3)/4;return a=a.filter(c=>n(g,c)),a};A.exports=o}}),KFt=ae({"node_modules/@jscad/modeling/src/operations/modifiers/mergePolygons.js"(t,A){var e=PdA(),i=xn(),n=er(),o=E=>{const u=n.toPoints(E),d=[];for(let f=0;f<u.length;f++){const y=(f+1)%u.length,w={v1:u[f],v2:u[y]};d.push(w)}for(let f=0;f<d.length;f++){const y=(f+1)%u.length;d[f].next=d[y],d[y].prev=d[f]}return d},s=(E,u)=>{const d=`${u.v1}:${u.v2}`;E.set(d,u)},r=(E,u)=>{const d=`${u.v1}:${u.v2}`;E.delete(d)},a=(E,u)=>{const d=`${u.v2}:${u.v1}`;return E.get(d)},g=(E,u,d)=>{let f=E.prev.v1,y=E.prev.v2,w=u.next.v2;const D=l(f,y,w,d);f=u.prev.v1,y=u.prev.v2,w=E.next.v2;const S=l(f,y,w,d);return[D,S]},c=i.create(),I=i.create(),l=(E,u,d,f)=>{const y=i.subtract(c,u,E),w=i.subtract(I,d,u);return i.cross(y,y,w),i.dot(y,f)},B=E=>{let u;const d=[];for(;E.next;){const f=E.next;d.push(E.v1),E.v1=null,E.v2=null,E.next=null,E.prev=null,E=f}return d.length>0&&(u=n.create(d)),u},C=E=>{if(E.length<2)return E;const u=E[0].plane,d=E.slice(),f=new Map;for(;d.length>0;){const w=d.shift(),D=o(w);for(let S=0;S<D.length;S++){const _=D[S],b=a(f,_);if(b){const N=g(_,b,u);if(N[0]>=0&&N[1]>=0){const F=b.next,L=_.next;_.prev.next=b.next,_.next.prev=b.prev,b.prev.next=_.next,b.next.prev=_.prev,_.v1=null,_.v2=null,_.next=null,_.prev=null,r(f,b),b.v1=null,b.v2=null,b.next=null,b.prev=null;const Y=(J,O,Z)=>{const X={v1:Z.v1,v2:O.v2,next:O.next,prev:Z.prev};Z.prev.next=X,O.next.prev=X,r(J,O),O.v1=null,O.v2=null,O.next=null,O.prev=null,r(J,Z),Z.v1=null,Z.v2=null,Z.next=null,Z.prev=null};N[0]===0&&Y(f,F,F.prev),N[1]===0&&Y(f,L,L.prev)}}else _.next&&s(f,_)}}const y=[];return f.forEach(w=>{const D=B(w);D&&y.push(D)}),f.clear(),y},Q=(E,u)=>Math.abs(E[3]-u[3])<15e-8?e(E,u):!1,h=(E,u)=>{const d=[];u.forEach(y=>{const w=d.find(D=>Q(D[0],n.plane(y)));w?w[1].push(y):d.push([n.plane(y),[y]])});let f=[];return d.forEach(y=>{const w=y[1],D=C(w);f=f.concat(D)}),f};A.exports=h}}),qFt=ae({"node_modules/@jscad/modeling/src/operations/modifiers/insertTjunctions.js"(t,A){var e=Qr(),i=xn(),n=er(),o=g=>`${g}`,s=(g,c,I,l,B,C)=>{const Q=o(l),h=o(B),E=`${Q}/${h}`,u=`${h}/${Q}`;if(g.has(u))return r(g,c,I,B,l,null),null;const d={vertex0:l,vertex1:B,polygonindex:C};return g.has(E)?g.get(E).push(d):g.set(E,[d]),c.has(Q)?c.get(Q).push(E):c.set(Q,[E]),I.has(h)?I.get(h).push(E):I.set(h,[E]),E},r=(g,c,I,l,B,C)=>{const Q=o(l),h=o(B),E=`${Q}/${h}`;let u=-1;const d=g.get(E);for(let f=0;f<d.length;f++){const y=d[f];let w=o(y.vertex0);if(w===Q&&(w=o(y.vertex1),w===h&&!(C!==null&&y.polygonindex!==C))){u=f;break}}d.splice(u,1),d.length===0&&g.delete(E),u=c.get(Q).indexOf(E),c.get(Q).splice(u,1),c.get(Q).length===0&&c.delete(Q),u=I.get(h).indexOf(E),I.get(h).splice(u,1),I.get(h).length===0&&I.delete(h)},a=g=>{const c=new Map;for(let I=0;I<g.length;I++){const l=g[I],B=l.vertices.length;if(B>=3){let C=l.vertices[0],Q=o(C);for(let h=0;h<B;h++){let E=h+1;E===B&&(E=0);const u=l.vertices[E],d=o(u),f=`${Q}/${d}`,y=`${d}/${Q}`;if(c.has(y)){const w=c.get(y);w.splice(-1,1),w.length===0&&c.delete(y)}else{const w={vertex0:C,vertex1:u,polygonindex:I};c.has(f)?c.get(f).push(w):c.set(f,[w])}C=u,Q=d}}else console.warn("warning: invalid polygon found during insertTjunctions")}if(c.size>0){const I=new Map,l=new Map,B=new Map;for(const[Q,h]of c)B.set(Q,!0),h.forEach(E=>{const u=o(E.vertex0),d=o(E.vertex1);I.has(u)?I.get(u).push(Q):I.set(u,[Q]),l.has(d)?l.get(d).push(Q):l.set(d,[Q])});const C=g.slice(0);for(;c.size!==0;){for(const h of c.keys())B.set(h,!0);let Q=!1;for(;;){const h=Array.from(B.keys());if(h.length===0)break;const E=h[0];let u=!0;if(c.has(E)){const f=c.get(E)[0];for(let y=0;y<2;y++){const w=y===0?f.vertex0:f.vertex1,D=y===0?f.vertex1:f.vertex0,S=o(w),_=o(D);let b=[];y===0?l.has(S)&&(b=l.get(S)):I.has(S)&&(b=I.get(S));for(let N=0;N<b.length;N++){const F=b[N],L=c.get(F)[0],Y=y===0?L.vertex0:L.vertex1;if(y===0?L.vertex1:L.vertex0,o(Y)===_){r(c,I,l,w,D,null),r(c,I,l,D,w,null),u=!1,y=2,Q=!0;break}else{const O=w,Z=D,X=Y,eA=i.subtract(i.create(),X,O),gA=i.dot(i.subtract(i.create(),Z,O),eA)/i.dot(eA,eA);if(gA>0&&gA<1){const tA=i.scale(i.create(),eA,gA);if(i.add(tA,tA,O),i.squaredDistance(tA,Z)<e.EPS*e.EPS){const sA=L.polygonindex,aA=C[sA],EA=o(L.vertex1);let bA=-1;for(let dA=0;dA<aA.vertices.length;dA++)if(o(aA.vertices[dA])===EA){bA=dA;break}const _A=aA.vertices.slice(0);_A.splice(bA,0,D);const LA=n.create(_A);C[sA]=LA,r(c,I,l,L.vertex0,L.vertex1,sA);const QA=s(c,I,l,L.vertex0,D,sA),kA=s(c,I,l,D,L.vertex1,sA);QA!==null&&B.set(QA,!0),kA!==null&&B.set(kA,!0),u=!1,y=2,Q=!0;break}}}}}}u&&B.delete(E)}if(!Q)break}g=C}return c.clear(),g};A.exports=a}}),OFt=ae({"node_modules/@jscad/modeling/src/operations/modifiers/triangulatePolygons.js"(t,A){var e=xn(),i=er(),n=(s,r,a)=>{const g=r.vertices.length;if(g>3){if(g>4){const l=[0,0,0];r.vertices.forEach(B=>e.add(l,l,B)),e.snap(l,e.divide(l,l,[g,g,g]),s);for(let B=0;B<g;B++){const C=i.create([l,r.vertices[B],r.vertices[(B+1)%g]]);r.color&&(C.color=r.color),a.push(C)}return}const c=i.create([r.vertices[0],r.vertices[1],r.vertices[2]]),I=i.create([r.vertices[0],r.vertices[2],r.vertices[3]]);r.color&&(c.color=r.color,I.color=r.color),a.push(c,I);return}a.push(r)},o=(s,r)=>{const a=[];return r.forEach(g=>{n(s,g,a)}),a};A.exports=o}}),WFt=ae({"node_modules/@jscad/modeling/src/operations/modifiers/generalize.js"(t,A){var e=vo(),i=Ck(),n=ss(),o=es(),s=Lg(),r=die(),a=KFt(),g=qFt(),c=OFt(),I=(Q,h)=>h,l=(Q,h)=>h,B=(Q,h)=>{const E={snap:!1,simplify:!1,triangulate:!1},{snap:u,simplify:d,triangulate:f}=Object.assign({},E,Q),y=i(h);let w=o.toPolygons(h);u&&(w=r(y,w)),d&&(w=a(y,w)),f&&(w=g(w),w=c(y,w));const D=Object.assign({},h);return D.polygons=w,D},C=(Q,...h)=>{if(h=e(h),h.length===0)throw new Error("wrong number of arguments");const E=h.map(u=>{if(s.isA(u))return I(Q,u);if(n.isA(u))return l(Q,u);if(o.isA(u))return B(Q,u);throw new Error("invalid geometry")});return E.length===1?E[0]:E};A.exports=C}}),ZFt=ae({"node_modules/@jscad/modeling/src/operations/modifiers/snap.js"(t,A){var e=vo(),i=ks(),n=ss(),o=es(),s=Lg(),r=Ck(),a=die(),g=B=>{const C=r(B),h=s.toPoints(B).map(E=>i.snap(i.create(),E,C));return s.create(h)},c=B=>{const C=r(B);let h=n.toSides(B).map(E=>[i.snap(i.create(),E[0],C),i.snap(i.create(),E[1],C)]);return h=h.filter(E=>!i.equals(E[0],E[1])),n.create(h)},I=B=>{const C=r(B),Q=o.toPolygons(B),h=a(C,Q);return o.create(h)},l=(...B)=>{if(B=e(B),B.length===0)throw new Error("wrong number of arguments");const C=B.map(Q=>s.isA(Q)?g(Q):n.isA(Q)?c(Q):o.isA(Q)?I(Q):Q);return C.length===1?C[0]:C};A.exports=l}}),VFt=ae({"node_modules/@jscad/modeling/src/operations/modifiers/index.js"(t,A){A.exports={generalize:WFt(),snap:ZFt(),retessellate:rJ()}}}),jFt=ae({"node_modules/@jscad/modeling/src/utils/padArrayToLength.js"(t,A){var e=(i,n,o)=>{for(i=i.slice();i.length<o;)i.push(n);return i};A.exports=e}}),zFt=ae({"node_modules/@jscad/modeling/src/operations/transforms/align.js"(t,A){var e=vo(),i=jFt(),n=qdA(),{translate:o}=eM(),s=c=>{if(!Array.isArray(c.modes)||c.modes.length>3)throw new Error("align(): modes must be an array of length <= 3");if(c.modes=i(c.modes,"none",3),c.modes.filter(I=>["center","max","min","none"].includes(I)).length!==3)throw new Error('align(): all modes must be one of "center", "max" or "min"');if(!Array.isArray(c.relativeTo)||c.relativeTo.length>3)throw new Error("align(): relativeTo must be an array of length <= 3");if(c.relativeTo=i(c.relativeTo,0,3),c.relativeTo.filter(I=>Number.isFinite(I)||I==null).length!==3)throw new Error("align(): all relativeTo values must be a number, or null.");if(typeof c.grouped!="boolean")throw new Error("align(): grouped must be a boolean value.");return c},r=(c,I,l)=>{for(let B=0;B<3;B++)c[B]==null&&(I[B]==="center"?c[B]=(l[0][B]+l[1][B])/2:I[B]==="max"?c[B]=l[1][B]:I[B]==="min"&&(c[B]=l[0][B]));return c},a=(c,I,l)=>{const B=n(c),C=[0,0,0];for(let Q=0;Q<3;Q++)I[Q]==="center"?C[Q]=l[Q]-(B[0][Q]+B[1][Q])/2:I[Q]==="max"?C[Q]=l[Q]-B[1][Q]:I[Q]==="min"&&(C[Q]=l[Q]-B[0][Q]);return o(C,c)},g=(c,...I)=>{c=Object.assign({},{modes:["center","center","min"],relativeTo:[0,0,0],grouped:!1},c),c=s(c);let{modes:B,relativeTo:C,grouped:Q}=c;if(I=e(I),I.length===0)throw new Error("align(): No geometries were provided to act upon");if(C.filter(h=>h==null).length){const h=n(I);C=r(C,B,h)}return Q?I=a(I,B,C):I=I.map(h=>a(h,B,C)),I.length===1?I[0]:I};A.exports=g}}),TV=ae({"node_modules/@jscad/modeling/src/operations/transforms/center.js"(t,A){var e=vo(),i=ss(),n=es(),o=Lg(),s=$F(),{translate:r}=eM(),a=(B,C)=>{const Q={axes:[!0,!0,!0],relativeTo:[0,0,0]},{axes:h,relativeTo:E}=Object.assign({},Q,B),u=s(C),d=[0,0,0];return h[0]&&(d[0]=E[0]-(u[0][0]+(u[1][0]-u[0][0])/2)),h[1]&&(d[1]=E[1]-(u[0][1]+(u[1][1]-u[0][1])/2)),h[2]&&(d[2]=E[2]-(u[0][2]+(u[1][2]-u[0][2])/2)),r(d,C)},g=(B,...C)=>{const Q={axes:[!0,!0,!0],relativeTo:[0,0,0]},{axes:h,relativeTo:E}=Object.assign({},Q,B);if(C=e(C),C.length===0)throw new Error("wrong number of arguments");if(E.length!==3)throw new Error("relativeTo must be an array of length 3");B={axes:h,relativeTo:E};const u=C.map(d=>o.isA(d)||i.isA(d)||n.isA(d)?a(B,d):d);return u.length===1?u[0]:u},c=(...B)=>g({axes:[!0,!1,!1]},B),I=(...B)=>g({axes:[!1,!0,!1]},B),l=(...B)=>g({axes:[!1,!1,!0]},B);A.exports={center:g,centerX:c,centerY:I,centerZ:l}}}),PV=ae({"node_modules/@jscad/modeling/src/operations/transforms/scale.js"(t,A){var e=vo(),i=ic(),n=ss(),o=es(),s=Lg(),r=(I,...l)=>{if(!Array.isArray(I))throw new Error("factors must be an array");if(l=e(l),l.length===0)throw new Error("wrong number of arguments");for(I=I.slice();I.length<3;)I.push(1);if(I[0]<=0||I[1]<=0||I[2]<=0)throw new Error("factors must be positive");const B=i.fromScaling(i.create(),I),C=l.map(Q=>s.isA(Q)?s.transform(B,Q):n.isA(Q)?n.transform(B,Q):o.isA(Q)?o.transform(B,Q):Q);return C.length===1?C[0]:C},a=(I,...l)=>r([I,1,1],l),g=(I,...l)=>r([1,I,1],l),c=(I,...l)=>r([1,1,I],l);A.exports={scale:r,scaleX:a,scaleY:g,scaleZ:c}}}),XFt=ae({"node_modules/@jscad/modeling/src/operations/transforms/transform.js"(t,A){var e=vo(),i=ss(),n=es(),o=Lg(),s=(r,...a)=>{if(a=e(a),a.length===0)throw new Error("wrong number of arguments");const g=a.map(c=>o.isA(c)?o.transform(r,c):i.isA(c)?i.transform(r,c):n.isA(c)?n.transform(r,c):c);return g.length===1?g[0]:g};A.exports=s}}),iM=ae({"node_modules/@jscad/modeling/src/operations/transforms/index.js"(t,A){A.exports={align:zFt(),center:TV().center,centerX:TV().centerX,centerY:TV().centerY,centerZ:TV().centerZ,mirror:nJ().mirror,mirrorX:nJ().mirrorX,mirrorY:nJ().mirrorY,mirrorZ:nJ().mirrorZ,rotate:oJ().rotate,rotateX:oJ().rotateX,rotateY:oJ().rotateY,rotateZ:oJ().rotateZ,scale:PV().scale,scaleX:PV().scaleX,scaleY:PV().scaleY,scaleZ:PV().scaleZ,transform:XFt(),translate:eM().translate,translateX:eM().translateX,translateY:eM().translateY,translateZ:eM().translateZ}}}),KV=ae({"node_modules/@jscad/modeling/src/index.js"(t,A){A.exports={colors:GV(),curves:Okt(),geometries:YdA(),maths:Evt(),measurements:Dvt(),primitives:tM(),text:iFt(),utils:Iie(),booleans:aJ(),expansions:Eie(),extrusions:gJ(),hulls:TFt(),minkowski:PFt(),modifiers:VFt(),transforms:iM()}}}),pie=ae({"node_modules/jscad-planner/dist/index.cjs"(t,A){var e=Object.defineProperty,i=Object.getOwnPropertyDescriptor,n=Object.getOwnPropertyNames,o=Object.prototype.hasOwnProperty,s=(l,B)=>{for(var C in B)e(l,C,{get:B[C],enumerable:!0})},r=(l,B,C,Q)=>{if(B&&typeof B=="object"||typeof B=="function")for(let h of n(B))!o.call(l,h)&&h!==C&&e(l,h,{get:()=>B[h],enumerable:!(Q=i(B,h))||Q.enumerable});return l},a=l=>r(e({},"__esModule",{value:!0}),l),g={};s(g,{executeJscadOperations:()=>I,jscadPlanner:()=>c}),A.exports=a(g);var c={booleans:{intersect:(...l)=>({type:"intersect",shapes:l}),subtract:(...l)=>({type:"subtract",shapes:l}),union:(...l)=>({type:"union",shapes:l})},hulls:{hull:(...l)=>({type:"hull",shapes:l.flat()}),hullChain:(...l)=>({type:"hullChain",shapes:l.flat()})},colors:{colorize:(l,B)=>({type:"colorize",color:l,shape:B})},primitives:{cube:l=>({type:"cube",...l}),sphere:l=>({type:"sphere",...l}),cylinder:l=>({type:"cylinder",...l}),polygon:l=>({type:"polygon",...l}),cuboid:l=>({type:"cuboid",...l}),roundedCuboid:l=>({type:"roundedCuboid",...l})},transforms:{rotate:(l,B)=>({type:"rotate",angles:l,shape:B}),scale:(l,B)=>({type:"scale",factors:l,shape:B}),translate:(l,B)=>({type:"translate",vector:l,shape:B})},extrusions:{extrudeLinear:(l,B)=>({type:"extrudeLinear",options:l,shape:B}),extrudeRotate:(l,B)=>({type:"extrudeRotate",options:l,shape:B})},maths:{vec2:{create:(l,B)=>[l,B],fromValues:(l,B)=>[l,B]},vec3:{create:(l,B,C)=>[l,B,C],fromValues:(l,B,C)=>[l,B,C]}},geometries:{geom2:{create:l=>({type:"createGeom2",points:l})},geom3:{create:l=>({type:"createGeom3",polygons:l})},path2:{create:l=>({type:"createPath2",points:l})}},measurements:{measureBoundingBox:l=>({type:"measureBoundingBox",shape:l}),measureArea:l=>({type:"measureArea",shape:l}),measureVolume:l=>({type:"measureVolume",shape:l})},utils:{degToRad:l=>l*Math.PI/180,radToDeg:l=>l*180/Math.PI}},I=(l,B)=>{if(Array.isArray(B)&&B.length===1)return I(l,B[0]);if(Array.isArray(B))throw new Error("executeJscadOperations currently doesn't support Array<JscadOperation>, try adding a root union or or executing each element individually");const C=E=>I(l,E),{type:Q,...h}=B;switch(Q){case"intersect":return l.booleans.intersect(...B.shapes.map(C));case"subtract":return l.booleans.subtract(...B.shapes.map(C));case"union":return l.booleans.union(...B.shapes.map(C));case"hull":return l.hulls.hull(...B.shapes.map(C));case"hullChain":return l.hulls.hullChain(...B.shapes.map(C));case"colorize":return l.colors.colorize(B.color,C(B.shape));case"cube":return l.primitives.cube(h);case"sphere":return l.primitives.sphere(h);case"cylinder":return l.primitives.cylinder(h);case"polygon":return l.primitives.polygon(h);case"cuboid":return l.primitives.cuboid(h);case"roundedCuboid":return l.primitives.roundedCuboid(h);case"rotate":return l.transforms.rotate(B.angles,C(B.shape));case"scale":return l.transforms.scale(B.factors,C(B.shape));case"translate":return l.transforms.translate(B.vector,C(B.shape));case"extrudeLinear":return l.extrusions.extrudeLinear(B.options,C(B.shape));case"extrudeRotate":return l.extrusions.extrudeRotate(B.options,C(B.shape));case"createGeom2":return l.geometries.geom2.create(B.points);case"createGeom3":return l.geometries.geom3.create(B.polygons);case"createPath2":return l.geometries.path2.create(B.points);case"measureBoundingBox":return l.measurements.measureBoundingBox(C(B.shape));case"measureArea":return l.measurements.measureArea(C(B.shape));case"measureVolume":return l.measurements.measureVolume(C(B.shape));case"degToRad":return l.utils.degToRad(B.degrees);case"radToDeg":return l.utils.radToDeg(B.radians);default:throw B.type===void 0?new Error(`Operation type is undefined. This usually means the operation object is malformed or not properly initialized. Operation: ${JSON.stringify(B,null,2).slice(0,200)}...`):new Error(`Unsupported operation type: ${B.type}. Operation: ${JSON.stringify(B,null,2)}`)}}}}),$Ft=ae({"node_modules/ms/index.js"(t,A){var e=1e3,i=e*60,n=i*60,o=n*24,s=o*7,r=o*365.25;A.exports=function(l,B){B=B||{};var C=typeof l;if(C==="string"&&l.length>0)return a(l);if(C==="number"&&isFinite(l))return B.long?c(l):g(l);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(l))};function a(l){if(l=String(l),!(l.length>100)){var B=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(l);if(B){var C=parseFloat(B[1]),Q=(B[2]||"ms").toLowerCase();switch(Q){case"years":case"year":case"yrs":case"yr":case"y":return C*r;case"weeks":case"week":case"w":return C*s;case"days":case"day":case"d":return C*o;case"hours":case"hour":case"hrs":case"hr":case"h":return C*n;case"minutes":case"minute":case"mins":case"min":case"m":return C*i;case"seconds":case"second":case"secs":case"sec":case"s":return C*e;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return C;default:return}}}}function g(l){var B=Math.abs(l);return B>=o?Math.round(l/o)+"d":B>=n?Math.round(l/n)+"h":B>=i?Math.round(l/i)+"m":B>=e?Math.round(l/e)+"s":l+"ms"}function c(l){var B=Math.abs(l);return B>=o?I(l,B,o,"day"):B>=n?I(l,B,n,"hour"):B>=i?I(l,B,i,"minute"):B>=e?I(l,B,e,"second"):l+" ms"}function I(l,B,C,Q){var h=B>=C*1.5;return Math.round(l/C)+" "+Q+(h?"s":"")}}}),AMt=ae({"node_modules/debug/src/common.js"(t,A){function e(i){o.debug=o,o.default=o,o.coerce=I,o.disable=g,o.enable=r,o.enabled=c,o.humanize=$Ft(),o.destroy=l,Object.keys(i).forEach(B=>{o[B]=i[B]}),o.names=[],o.skips=[],o.formatters={};function n(B){let C=0;for(let Q=0;Q<B.length;Q++)C=(C<<5)-C+B.charCodeAt(Q),C|=0;return o.colors[Math.abs(C)%o.colors.length]}o.selectColor=n;function o(B){let C,Q=null,h,E;function u(...d){if(!u.enabled)return;const f=u,y=Number(new Date),w=y-(C||y);f.diff=w,f.prev=C,f.curr=y,C=y,d[0]=o.coerce(d[0]),typeof d[0]!="string"&&d.unshift("%O");let D=0;d[0]=d[0].replace(/%([a-zA-Z%])/g,(_,b)=>{if(_==="%%")return"%";D++;const N=o.formatters[b];if(typeof N=="function"){const F=d[D];_=N.call(f,F),d.splice(D,1),D--}return _}),o.formatArgs.call(f,d),(f.log||o.log).apply(f,d)}return u.namespace=B,u.useColors=o.useColors(),u.color=o.selectColor(B),u.extend=s,u.destroy=o.destroy,Object.defineProperty(u,"enabled",{enumerable:!0,configurable:!1,get:()=>Q!==null?Q:(h!==o.namespaces&&(h=o.namespaces,E=o.enabled(B)),E),set:d=>{Q=d}}),typeof o.init=="function"&&o.init(u),u}function s(B,C){const Q=o(this.namespace+(typeof C>"u"?":":C)+B);return Q.log=this.log,Q}function r(B){o.save(B),o.namespaces=B,o.names=[],o.skips=[];const C=(typeof B=="string"?B:"").trim().replace(/\s+/g,",").split(",").filter(Boolean);for(const Q of C)Q[0]==="-"?o.skips.push(Q.slice(1)):o.names.push(Q)}function a(B,C){let Q=0,h=0,E=-1,u=0;for(;Q<B.length;)if(h<C.length&&(C[h]===B[Q]||C[h]==="*"))C[h]==="*"?(E=h,u=Q,h++):(Q++,h++);else if(E!==-1)h=E+1,u++,Q=u;else return!1;for(;h<C.length&&C[h]==="*";)h++;return h===C.length}function g(){const B=[...o.names,...o.skips.map(C=>"-"+C)].join(",");return o.enable(""),B}function c(B){for(const C of o.skips)if(a(B,C))return!1;for(const C of o.names)if(a(B,C))return!0;return!1}function I(B){return B instanceof Error?B.stack||B.message:B}function l(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return o.enable(o.load()),o}A.exports=e}}),eMt=ae({"node_modules/debug/src/browser.js"(t,A){t.formatArgs=i,t.save=n,t.load=o,t.useColors=e,t.storage=s(),t.destroy=(()=>{let a=!1;return()=>{a||(a=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),t.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"];function e(){if(typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs))return!0;if(typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))return!1;let a;return typeof document<"u"&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent&&(a=navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/))&&parseInt(a[1],10)>=31||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)}function i(a){if(a[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+a[0]+(this.useColors?"%c ":" ")+"+"+A.exports.humanize(this.diff),!this.useColors)return;const g="color: "+this.color;a.splice(1,0,g,"color: inherit");let c=0,I=0;a[0].replace(/%[a-zA-Z%]/g,l=>{l!=="%%"&&(c++,l==="%c"&&(I=c))}),a.splice(I,0,g)}t.log=console.debug||console.log||(()=>{});function n(a){try{a?t.storage.setItem("debug",a):t.storage.removeItem("debug")}catch{}}function o(){let a;try{a=t.storage.getItem("debug")||t.storage.getItem("DEBUG")}catch{}return!a&&typeof kdA<"u"&&"env"in kdA&&(a=kdA.env.DEBUG),a}function s(){try{return localStorage}catch{}}A.exports=AMt()(t);var{formatters:r}=A.exports;r.j=function(a){try{return JSON.stringify(a)}catch(g){return"[UnexpectedJSONParseError]: "+g.message}}}}),fie={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},yie=V.createContext(void 0),tMt=({children:t})=>{const[A,e]=V.useState(fie),i=V.useCallback((s,r)=>{e(a=>({...a,[s]:r}))},[]),n=V.useCallback(()=>{e(fie)},[]),o=V.useMemo(()=>({visibility:A,setLayerVisibility:i,resetToDefaults:n}),[A,i,n]);return W.jsx(yie.Provider,{value:o,children:t})},nM=()=>{const t=V.useContext(yie);if(!t)throw new Error("useLayerVisibility must be used within a LayerVisibilityProvider");return t},opA=1.2;function mie(t){return V.useMemo(()=>{if(!t)return opA;try{return wn(t).pcb_board.list()[0]?.thickness??opA}catch{return opA}},[t])}var wie=V.createContext(null),rd=()=>{const t=V.useContext(wie);if(!t)throw new Error("useThree must be used within a ThreeProvider");return t},cJ=(t,A=[])=>{const{addFrameListener:e,removeFrameListener:i}=rd();Qn.useEffect(()=>(e(t),()=>i(t)),[e,i,...A])},IJ={clickToInteractOverlay:100,htmlElements:95,orientationCube:95,contextMenu:90,appearanceMenu:91},Die=({children:t,position:A,style:e})=>{const{camera:i,renderer:n}=rd(),o=V.useRef(document.createElement("div")),[s,r]=V.useState(null);return V.useEffect(()=>{const a=n?.domElement.parentNode;if(a)return a.style.position!=="relative"&&a.style.position!=="absolute"&&(a.style.position="relative"),a.appendChild(o.current),r(QW.createPortal(t,o.current)),()=>{a.contains(o.current)&&a.removeChild(o.current)}},[n,t]),cJ(()=>{if(!i||!o.current||!n)return;const a=new Re(...A);a.project(i);const g=n.domElement.getBoundingClientRect(),c=Math.round((a.x+1)/2*g.width),I=Math.round((-a.y+1)/2*g.height);o.current.style.position="absolute",o.current.style.left=`${c}px`,o.current.style.top=`${I}px`,o.current.style.pointerEvents="none",o.current.style.zIndex=IJ.htmlElements.toString(),e&&Object.assign(o.current.style,e)},[i,n,A,e]),s},Sie={in:25.4,inch:25.4,mil:.0254,mm:1,m:1e3,cm:10,ft:304.8,feet:304.8},cr=t=>{let A=typeof t=="number"?"mm":t.replace(/^[^a-zA-Z]+/g,"").toLowerCase();A||(A="mm");const e=typeof t=="number"?t:Number.parseFloat(t.split(A)[0]);if(A in Sie)return e*Sie[A];throw new Error(`Unsupported unit: ${A}`)},Ol=cr,iMt=Object.defineProperty,nMt=(t,A)=>{for(var e in A)iMt(t,e,{get:A[e],enumerable:!0})},Pb={};nMt(Pb,{axial:()=>xRt,bga:()=>GMt,breakoutheaders:()=>JRt,cap:()=>IMt,dfn:()=>cRt,diode:()=>cMt,dip:()=>rMt,electrolytic:()=>_1t,hc49:()=>PRt,jst:()=>WGt,led:()=>lMt,lqfp:()=>HRt,m2host:()=>j1t,melf:()=>tGt,micromelf:()=>sGt,minimelf:()=>ZNt,mlp:()=>qMt,mountedpcbmodule:()=>X1t,ms012:()=>hRt,ms013:()=>uRt,msop:()=>i1t,pad:()=>KRt,pinrow:()=>lRt,platedhole:()=>J1t,potentiometer:()=>S1t,pushbutton:()=>MRt,qfn:()=>TMt,qfp:()=>KMt,quad:()=>_1,radial:()=>vRt,res:()=>MMt,sma:()=>cGt,smb:()=>uGt,smbf:()=>v1t,smc:()=>yGt,smf:()=>CGt,smtpad:()=>H1t,sod110:()=>VGt,sod123:()=>wRt,sod123f:()=>DNt,sod123fl:()=>_Nt,sod123w:()=>oNt,sod128:()=>LNt,sod323:()=>gNt,sod323f:()=>fNt,sod323fl:()=>g1t,sod323w:()=>o1t,sod523:()=>VRt,sod723:()=>MNt,sod80:()=>eNt,sod882:()=>ENt,sod882d:()=>XNt,sod923:()=>BNt,soic:()=>UMt,solderjumper:()=>u1t,son:()=>B1t,sop8:()=>$Rt,sot:()=>P1t,sot223:()=>SGt,sot23:()=>iRt,sot23w:()=>NGt,sot25:()=>rRt,sot323:()=>N1t,sot343:()=>O1t,sot363:()=>$Mt,sot457:()=>f1t,sot563:()=>CRt,sot723:()=>pRt,sot886:()=>eRt,sot89:()=>PNt,sot963:()=>m1t,ssop:()=>ZMt,stampboard:()=>NRt,stampreceiver:()=>URt,to220:()=>Kie,to220f:()=>ONt,to92:()=>WRt,to92l:()=>A2t,to92s:()=>JGt,tqfp:()=>PMt,tssop:()=>zMt,vson:()=>Q1t,vssop:()=>A1t});var Ui=(t,A,e)=>({type:"pcb_silkscreen_text",pcb_silkscreen_text_id:"silkscreen_text_1",font:"tscircuit2024",font_size:e,pcb_component_id:"pcb_component_1",text:"{REF}",layer:"top",anchor_position:{x:t,y:A},anchor_alignment:"center"}),Ri=te({norefdes:PA().optional().describe("disable reference designator label"),invert:PA().optional().describe("hint to invert the orientation of the 3D model"),faceup:PA().optional().describe("The male pin header should face upwards, out of the top layer"),nosilkscreen:PA().optional().describe("omit all silkscreen elements from the footprint")}),Fo=(t,A,e,i,n)=>({pcb_plated_hole_id:"",type:"pcb_plated_hole",shape:"circle",x:A,y:e,hole_diameter:cr(i),outer_diameter:cr(n),pcb_port_id:"",layers:["top","bottom"],port_hints:[t.toString()]}),fm=t=>{const{pn:A,x:e,y:i,holeDiameter:n,rectPadWidth:o,rectPadHeight:s,holeOffsetX:r=0,holeOffsetY:a=0,rectBorderRadius:g}=t;return{pcb_plated_hole_id:"",type:"pcb_plated_hole",shape:"circular_hole_with_rect_pad",x:e,y:i,hole_diameter:cr(n),hole_shape:"circle",pad_shape:"rect",rect_pad_width:cr(o),rect_pad_height:cr(s),...g!==void 0&&{rect_border_radius:g},pcb_port_id:"",layers:["top","bottom"],port_hints:[A.toString()],hole_offset_x:r,hole_offset_y:a}},qV=Array.from({length:9},(t,A)=>Math.cos(A/8*Math.PI-Math.PI)).map(t=>({x:t,y:-Math.sqrt(1-t**2)}));function Qk(t){return typeof t=="string"?t.trim().toLowerCase().endsWith("mil")?parseFloat(t)*.0254:parseFloat(t):Number(t)}var OV=Rt([U(),OA()]).transform(t=>Qk(t)),oMt=t=>Ri.extend({fn:U(),num_pins:OA().optional().default(6),wide:PA().optional(),narrow:PA().optional(),w:OV.optional(),p:OV.default(t.p??"2.54mm"),id:OV.optional(),od:OV.optional(),nosquareplating:PA().optional().default(!1).describe("do not use rectangular pad for pin 1")}).transform(A=>(!A.id&&!A.od?Math.abs(A.p-1.27)<.01?(A.id=Qk("0.55mm"),A.od=Qk("0.95mm")):(A.id=Qk("0.8mm"),A.od=Qk("1.6mm")):A.id?A.od||(A.od=A.id*(1.5/1)):A.id=A.od*(1/1.5),A.w||(A.wide?A.w=Qk("600mil"):A.narrow?A.w=Qk("300mil"):A.w=Qk(t.w??"300mil")),A)),sMt=oMt({}),bie=(t,A,e,i,n)=>{const o=t/2,s=A<=o,r=o-1,a=i,g=a*r;return s?{x:-e/2,y:g/2-(A-1)*a}:{x:e/2,y:-g/2+(A-o-1)*a}},rMt=t=>{const A=sMt.parse(t),e=[];for(let g=0;g<A.num_pins;g++){const{x:c,y:I}=bie(A.num_pins,g+1,A.w,A.p??2.54,A.nosquareplating);if(g===0&&!A.nosquareplating){e.push(fm({pn:g+1,x:c,y:I,holeDiameter:A.id??"0.8mm",rectPadWidth:A.od??"1mm",rectPadHeight:A.od??"1mm"}));continue}e.push(Fo(g+1,c,I,A.id??"0.8mm",A.od??"1mm"))}(A.num_pins/2-1)*A.p+A.od;const n=A.w-A.od-1,o=(A.num_pins/2-1)*A.p+A.od+.4,s={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-n/2,y:-o/2},{x:-n/2,y:o/2},...qV.map(({x:g,y:c})=>({x:g*n/6,y:c*n/6+o/2})),{x:n/2,y:o/2},{x:n/2,y:-o/2},{x:-n/2,y:-o/2}],type:"pcb_silkscreen_path",stroke_width:.1},r=[];for(let g=0;g<A.num_pins;g++){const c=g<A.num_pins/2,I=.6,{y:l}=bie(A.num_pins,g+1,A.w,A.p??2.54,A.nosquareplating),B=c?-A.w/2-A.od/2-I:A.w/2+A.od/2+I,C=l;r.push({type:"pcb_fabrication_note_text",pcb_fabrication_note_text_id:`pin_${g+1}`,layer:"top",pcb_component_id:`pin_${g+1}`,text:`{pin${g+1}}`,anchor_position:{x:B,y:C},font_size:.3,font:"tscircuit2024",anchor_alignment:"top_left"})}const a=Ui(0,o/2+.5,.4);return{circuitJson:[...e,s,a,...r],parameters:A}},li=(t,A,e,i,n)=>({type:"pcb_smtpad",x:A,y:e,width:i,height:n,layer:"top",shape:"rect",pcb_smtpad_id:"",port_hints:Array.isArray(t)?t.map(o=>o.toString()):[t.toString()]}),xie=[{imperial:"01005",metric:"0402",p_mm_min:.5,pw_mm_min:.4,ph_mm_min:.3,w_mm_min:.58,h_mm_min:.21},{imperial:"0504",metric:"1310",p_mm_min:1.1,pw_mm_min:.65,ph_mm_min:1.3,w_mm_min:.58,h_mm_min:.21},{imperial:"1812",metric:"4532",p_mm_min:4.275,pw_mm_min:1.125,ph_mm_min:3.4,w_mm_min:5.4,h_mm_min:3.4},{imperial:"0201",metric:"0603",p_mm_min:.66,pw_mm_min:.46,ph_mm_min:.4,w_mm_min:.9,h_mm_min:.3},{imperial:"0402",metric:"1005",p_mm_min:1.02,pw_mm_min:.54,ph_mm_min:.64,w_mm_min:1.56,h_mm_min:.64},{imperial:"0603",metric:"1608",p_mm_min:1.65,pw_mm_min:.8,ph_mm_min:.95,w_mm_min:2.45,h_mm_min:.95},{imperial:"0805",metric:"2012",p_mm_min:1.825,pw_mm_min:1.025,ph_mm_min:1.4,w_mm_min:2.8499999999999996,h_mm_min:1.4},{imperial:"1206",metric:"3216",p_mm_min:2.925,pw_mm_min:1.125,ph_mm_min:1.75,w_mm_min:4.05,h_mm_min:1.75},{imperial:"1210",metric:"3225",p_mm_min:2.925,pw_mm_min:1.125,ph_mm_min:2.65,w_mm_min:4.05,h_mm_min:2.65},{imperial:"2010",metric:"5025",p_mm_min:4.625,pw_mm_min:1.225,ph_mm_min:2.65,w_mm_min:5.85,h_mm_min:2.65},{imperial:"2512",metric:"6332",p_mm_min:5.925,pw_mm_min:1.225,ph_mm_min:3.35,w_mm_min:7.15,h_mm_min:3.35}],aMt=Object.fromEntries(xie.map(t=>[t.metric,t])),gMt=Object.fromEntries(xie.map(t=>[t.imperial,t]));Ri.extend({tht:PA(),p:IA.optional(),pw:IA.optional(),ph:IA.optional(),metric:se.optional(),imperial:se.optional(),w:IA.optional(),h:IA.optional(),textbottom:PA().optional()});var WV=t=>{let{tht:A,p:e,pw:i,ph:n,metric:o,imperial:s,w:r,h:a,textbottom:g}=t;if(typeof r=="string"&&(r=Ol(r)),typeof a=="string"&&(a=Ol(a)),typeof e=="string"&&(e=Ol(e)),typeof i=="string"&&(i=Ol(i)),typeof n=="string"&&(n=Ol(n)),a!==void 0&&r!==void 0&&a>r)throw new Error("height cannot be greater than width (rotated footprint not yet implemented)");let c;if(o&&(c=aMt[o]),s&&(c=gMt[s]),c&&(r=c.w_mm_min,a=c.h_mm_min,e=c.p_mm_min,i=c.pw_mm_min,n=c.ph_mm_min),e===void 0||i===void 0||n===void 0)throw new Error("Could not determine required pad dimensions (p, pw, ph)");const I={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:e/2,y:n/2+.4},{x:-e/2-i/2-.2,y:n/2+.4},{x:-e/2-i/2-.2,y:-n/2-.4},{x:e/2,y:-n/2-.4}],stroke_width:.1,pcb_silkscreen_path_id:""},l=g?-n/2-.9:n/2+.9,B=Ui(0,l,.2),C=.25,Q=I.route.map(w=>w.x),h=I.route.map(w=>w.y),E=Math.min(-(r??0)/2,-(e/2+i/2),...Q)-C,u=Math.max((r??0)/2,e/2+i/2,...Q)+C,d=Math.min(-(a??0)/2,-n/2,...h)-C,f=Math.max((a??0)/2,n/2,...h)+C,y={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:(E+u)/2,y:(d+f)/2},width:u-E,height:f-d,layer:"top"};return A?[Fo(1,-e/2,0,i,i*1/.8),Fo(2,e/2,0,i,i*1/.8),I,B,y]:[li(["1","left"],-e/2,0,i,n),li(["2","right"],e/2,0,i,n),I,B,y]},cMt=t=>({circuitJson:WV(t),parameters:t}),IMt=t=>({circuitJson:WV(t),parameters:t}),lMt=t=>({circuitJson:WV(t),parameters:t}),x1=t=>{const{padSpacing:A,padWidth:e,padHeight:i,padPitch:n,numRows:o,textbottom:s}=t,r=[],a=(o-1)*(n/2);for(let S=0;S<o;S++)r.push(a-S*n);const g=[];r.forEach((S,_)=>{g.push(li(_+1,-A/2,S,e,i))}),r.slice().reverse().forEach((S,_)=>{g.push(li(_+o+1,A/2,S,e,i))});const c=Math.max(...r)+i/2+.4,I=Math.min(...r)-i/2-.4,l=-A/2-e/2-.4,B=A/2+e/2+.4,C={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:B*.5,y:c},{x:l*.5,y:c}],stroke_width:.12,pcb_silkscreen_path_id:"silkscreen_top"},Q={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:B*.5,y:I},{x:l*.5,y:I}],stroke_width:.12,pcb_silkscreen_path_id:"silkscreen_bottom"},h=-A/2,E=Math.max(...r),u=.2,d=h-e/2-.1,f=E+i/2+.1,y={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"pin1_marker",route:[{x:d,y:f},{x:d-u,y:f},{x:d,y:f+u},{x:d,y:f}],stroke_width:.1},w=s?I-.9:c+.9,D=Ui(0,w,.2);return[...g,C,Q,y,D]},BMt=Ri.extend({pw:IA.default("0.5mm"),ph:IA.default("0.4mm"),p:IA.default("0.7mm"),textbottom:PA().optional(),convex:PA().optional(),concave:PA().optional()}),CMt=1,QMt=t=>{const A=BMt.parse(t);if(A.concave===!0)return[];const e=Ol(A.pw),i=Ol(A.ph),n=Ol(A.p);return x1({padSpacing:CMt,padWidth:e,padHeight:i,padPitch:n,numRows:2,textbottom:A.textbottom,convex:A.convex,concave:A.concave})},hMt=Ri.extend({pw:IA.default("0.5mm"),ph:IA.default("0.32mm"),p:IA.default("0.5mm"),textbottom:PA().optional(),convex:PA().optional(),concave:PA().optional()}),EMt=1,uMt=t=>{const A=hMt.parse(t),e=Ol(A.pw),i=Ol(A.ph),n=Ol(A.p);return x1({padSpacing:EMt,padWidth:e,padHeight:i,padPitch:n,numRows:4,textbottom:A.textbottom,convex:A.convex,concave:A.concave})},dMt=Ri.extend({pw:IA.default("0.9mm"),ph:IA.default("0.4mm"),p:IA.default("0.8mm"),textbottom:PA().optional(),convex:PA().optional(),concave:PA().optional()}),pMt=1.7,fMt=t=>{const A=dMt.parse(t),e=Ol(A.pw),i=Ol(A.ph),n=Ol(A.p);return x1({padSpacing:pMt,padWidth:e,padHeight:i,padPitch:n,numRows:2,textbottom:A.textbottom,convex:A.convex,concave:A.concave})},yMt=Ri.extend({pw:IA.default("0.9mm"),ph:IA.default("0.4mm"),p:IA.default("0.8mm"),textbottom:PA().optional(),convex:PA().optional(),concave:PA().optional()}),mMt=1.7,wMt=t=>{const A=yMt.parse(t),e=Ol(A.pw),i=Ol(A.ph),n=Ol(A.p);return x1({padSpacing:mMt,padWidth:e,padHeight:i,padPitch:n,numRows:4,textbottom:A.textbottom,convex:A.convex,concave:A.concave})},DMt=Ri.extend({pw:IA.default("0.7mm"),ph:IA.default("0.64mm"),p:IA.default("0.94mm"),textbottom:PA().optional(),convex:PA().optional(),concave:PA().optional()}),SMt=1.4,bMt=t=>{const A=DMt.parse(t),e=Ol(A.pw),i=Ol(A.ph),n=Ol(A.p);return x1({padSpacing:SMt,padWidth:e,padHeight:i,padPitch:n,numRows:2,textbottom:A.textbottom,convex:A.convex,concave:A.concave})},xMt=Ri.extend({pw:IA.default("0.9mm"),ph:IA.default("0.9mm"),p:IA.default("1.34mm"),textbottom:PA().optional(),convex:PA().optional(),concave:PA().optional()}),_Mt=3,kMt=t=>{const A=xMt.parse(t),e=Ol(A.pw),i=Ol(A.ph),n=Ol(A.p);return x1({padSpacing:_Mt,padWidth:e,padHeight:i,padPitch:n,numRows:4,textbottom:A.textbottom,convex:A.convex,concave:A.concave})},vMt=t=>{const A=t.array??t.x;if(typeof A=="number")return Number.isNaN(A)?void 0:A;if(typeof A=="string"){const e=Number.parseInt(A,10);return Number.isNaN(e)?void 0:e}if(typeof t.imperial=="string"){const i=t.imperial.match(/x(2|4)$/)?.[1];if(i)return Number.parseInt(i,10)}},FMt=t=>t?(typeof t=="number"?`${t}`:t).split(/[_x]/)[0]:void 0,MMt=t=>{const A=vMt(t),e=FMt(t.imperial);return A===2&&e==="0402"?{circuitJson:QMt(t),parameters:t}:A===4&&e==="0402"?{circuitJson:uMt(t),parameters:t}:A===2&&e==="0603"?{circuitJson:fMt(t),parameters:t}:A===4&&e==="0603"?{circuitJson:wMt(t),parameters:t}:A===2&&e==="0606"?{circuitJson:bMt(t),parameters:t}:A===4&&e==="1206"?{circuitJson:kMt(t),parameters:t}:{circuitJson:WV(t),parameters:t}},_ie=(t,{x:A,y:e,radius:i})=>({type:"pcb_smtpad",x:A,y:e,radius:i,layer:"top",shape:"circle",pcb_smtpad_id:"",port_hints:Array.isArray(t)?t.map(n=>n.toString()):[t.toString()]}),kie="ABCDEFGHIJKLMNOPQRSTUVWXYZ",ZV=U().transform(t=>{const[A,e]=t.split(/[x ]/);return{x:parseFloat(A??""),y:parseFloat(e??"")}}).pipe(te({x:OA(),y:OA()})),RMt=U().or(Se(AI())).transform(t=>Array.isArray(t)?t:(t.startsWith("(")&&t.endsWith(")")&&(t=t.slice(1,-1)),t.split(",").map(A=>{const e=Number(A);return isNaN(e)?A:e}))).pipe(Se(U().or(OA()))),NMt=Ri.extend({fn:U(),num_pins:OA().optional().default(64),grid:ZV.optional(),p:se.default("0.8mm"),w:IA.optional(),h:IA.optional(),ball:IA.optional().describe("ball diameter"),pad:IA.optional().describe("pad width/height"),circularpads:PA().optional().describe("use circular pads"),tlorigin:PA().optional(),blorigin:PA().optional(),trorigin:PA().optional(),brorigin:PA().optional(),missing:RMt.default([])}).transform(t=>{let A="tl";if(t.blorigin&&(A="bl"),t.trorigin&&(A="tr"),t.brorigin&&(A="br"),!t.grid){const i=Math.ceil(Math.sqrt(t.num_pins));t.grid={x:i,y:i}}return t.missing&&(t.missing=t.missing.map(i=>{if(typeof i=="number")return i;if(i==="center")return"center";if(i==="topleft")return"topleft";const n=i.match(/([A-Z]+)(\d+)/);if(!n)return i;const o=kie.indexOf(n[1]),s=Number.parseInt(n[2])-1;return o*t.grid.x+s+1})),{...t,origin:A}}),GMt=t=>{const A=NMt.parse(t);let{num_pins:e,grid:i,p:n,w:o,h:s,ball:r,pad:a,missing:g}=A;r??=.75/1.27*n,a??=r*.8;const c=[],I=(g??[]).filter(y=>typeof y=="number"),l=i.x*i.y-e;if(g.length===0&&l>0&&(Math.sqrt(l)%1===0?g.push("center"):l===1&&g.push("topleft")),g?.includes("center")){const y=Math.floor(Math.sqrt(l)),w=Math.floor((i.x-y)/2),D=Math.floor((i.y-y)/2);for(let S=D;S<D+y;S++)for(let _=w;_<w+y;_++)I.push(S*i.x+_+1)}g?.includes("topleft")&&I.push(1);const B=new Set(I);let C=0;for(let y=0;y<i.y;y++)for(let w=0;w<i.x;w++){const D=(w-(i.x-1)/2)*n,S=(y-(i.y-1)/2)*n;let _=w,b=y;switch(A.origin){case"bl":_=w,b=i.y-1-y;break;case"br":_=i.x-1-w,b=i.y-1-y;break;case"tr":_=i.x-1-w,b=y;break}let N=b*i.x+_+1;if(B.has(N)){C++;continue}N-=C;const F=[N,`${kie[b]}${_+1}`];c.push(A.circularpads?_ie(F,{x:D,y:S,radius:a/2}):li(F,D,S,a,a))}const Q=Ui(0,i.y*n/2,.2),h=n/6;let E;const u=i.x*n/2,d=i.y*n/2;switch(A.origin){case"bl":E=[{x:-u,y:-d},{x:-u,y:-d-h},{x:-u-h,y:-d},{x:-u,y:-d}];break;case"br":E=[{x:u,y:-d},{x:u,y:-d-h},{x:u+h,y:-d},{x:u,y:-d}];break;case"tr":E=[{x:u,y:d},{x:u,y:d+h},{x:u+h,y:d},{x:u,y:d}];break;default:E=[{x:-u,y:d},{x:-u,y:d+h},{x:-u-h,y:d},{x:-u,y:d}];break}const f={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"pin1_marker",route:E,stroke_width:.05};return{circuitJson:[...c,Q,f],parameters:A}},VV=(t,A,e,i,n)=>({type:"pcb_smtpad",x:A,y:e,width:i,height:n,radius:n/2,layer:"top",shape:"pill",pcb_smtpad_id:"",port_hints:Array.isArray(t)?t.map(o=>o.toString()):[t.toString()]}),oM=t=>Ri.extend({fn:U(),num_pins:OA().optional().default(8),w:IA.default(IA.parse(t.w??"5.3mm")),p:IA.default(IA.parse(t.p??"1.27mm")),pw:IA.default(IA.parse(t.pw??"0.6mm")),pl:IA.default(IA.parse(t.pl??"1.0mm")),legsoutside:PA().optional().default(t.legsoutside??!1),pillpads:PA().optional().default(t.pillpads??!1),silkscreen_stroke_width:OA().optional().default(.1)}).transform(A=>(!A.pw&&!A.pl?(A.pw=IA.parse("0.6mm"),A.pl=IA.parse("1.0mm")):A.pw?A.pl||(A.pl=A.pw*(1/.6)):A.pw=A.pl*(.6/1),A)),LMt=oM({}),spA=t=>{t.widthincludeslegs!==void 0&&(t.legsoutside=!t.widthincludeslegs);const{num_pins:A,pn:e,w:i,p:n,pl:o,legsoutside:s}=t,r=A/2,a=e<=r,g=r-1,c=n,I=c*g,l=s?o/2:-o/2;return a?{x:-i/2-l,y:I/2-(e-1)*c}:{x:i/2+l,y:-I/2+(e-r-1)*c}},UMt=t=>{const A=LMt.parse(t);return{circuitJson:lJ(A),parameters:A}},lJ=t=>{const A=[];for(let r=0;r<t.num_pins;r++){const{x:a,y:g}=spA({num_pins:t.num_pins,pn:r+1,w:t.w,p:t.p,pl:t.pl,legsoutside:t.legsoutside});t.pillpads?A.push(VV(r+1,a,g,t.pl,t.pw)):A.push(li(r+1,a,g,t.pl,t.pw))}const e=Math.min(1,t.p/2),i=t.w-(t.legsoutside?0:t.pl*2)-.2,n=(t.num_pins/2-1)*t.p+t.pw+e,o=Ui(0,n/2+.4,n/12),s={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",stroke_width:t.silkscreen_stroke_width??.1,route:[{x:-i/2,y:-n/2},{x:-i/2,y:n/2},...qV.map(({x:r,y:a})=>({x:r*i/6,y:a*i/6+n/2})),{x:i/2,y:n/2},{x:i/2,y:-n/2},{x:-i/2,y:-n/2}]};return[...A,s,o]},vie=Xe(["leftside","topside","rightside","bottomside","toppin","bottompin","leftpin","rightpin"]),HMt=({num_pins:t,cw:A,ccw:e,startingpin:i})=>{const n=[],o=t/4;let s=1;const r={};for(const a of i??[])r[a]=!0;!r.leftside&&!r.topside&&!r.rightside&&!r.bottomside&&(r.leftside=!0),!r.bottompin&&!r.leftpin&&!r.rightpin&&!r.toppin&&(r.leftside?r.toppin=!0:r.topside?r.rightpin=!0:r.rightside?r.bottompin=!0:r.bottomside&&(r.leftpin=!0)),r.leftside&&r.toppin?s=1:r.leftside&&r.bottompin?s=o:r.bottomside&&r.leftpin?s=o+1:r.bottomside&&r.rightpin?s=o*2:r.rightside&&r.bottompin?s=o*2+1:r.rightside&&r.toppin?s=o*3:r.topside&&r.rightpin?s=o*3+1:r.topside&&r.leftpin&&(s=o*4),n.push(-1);for(let a=0;a<t;a++)n[s]=a+1,e||!A?(s++,s>t&&(s=1)):(s--,s<1&&(s=t));return n},rpA=Ri.extend({fn:U(),cc:PA().default(!0).optional(),ccw:PA().default(!0).optional(),startingpin:U().or(Se(vie)).transform(t=>typeof t=="string"?t.slice(1,-1).split(","):t).pipe(Se(vie)).optional(),num_pins:OA().optional().default(64),w:IA.optional(),h:IA.optional(),p:IA.default(IA.parse("0.5mm")),pw:IA.optional(),pl:IA.optional(),thermalpad:Rt([xA(!0),ZV]).optional(),legsoutside:PA().default(!1)}),apA=t=>{t.w&&!t.h?t.h=t.w:!t.w&&t.h&&(t.w=t.h);const A=t.num_pins/4;if(!t.p&&!t.pw&&!t.pl&&t.w){const e=A+4;t.p=t.w/e}return!t.p&&t.w&&t.h&&t.pw&&t.pl&&(t.p=(t.w-t.pl*2)/(A-1)),!t.w&&!t.h&&t.p&&(t.w=t.p*(A+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},Fie=rpA.transform(apA),YMt=["left","bottom","right","top"],JMt=t=>{const{pin_count:A,pn:e,w:i,h:n,p:o,pl:s,legsoutside:r}=t,a=A/4,g=YMt[Math.floor((e-1)/a)],c=(e-1)%a,I=o*(a-1),l=o*(a-1),B=r?s/2:-s/2;switch(g){case"left":return{x:-i/2-B+.1,y:l/2-c*o,o:"vert"};case"bottom":return{x:-I/2+c*o,y:-n/2-B+.1,o:"horz"};case"right":return{x:i/2+B-.1,y:-l/2+c*o,o:"vert"};case"top":return{x:I/2-c*o,y:n/2+B-.1,o:"horz"};default:throw new Error("Invalid pin number")}},_1=t=>{const A=Fie.parse(t),e=[],i=HMt(A),n=A.num_pins/4;for(let r=0;r<A.num_pins;r++){const{x:a,y:g,o:c}=JMt({pin_count:A.num_pins,pn:r+1,w:A.w,h:A.h,p:A.p??.5,pl:A.pl,legsoutside:A.legsoutside});let I=A.pw,l=A.pl;c==="vert"&&([I,l]=[l,I]);const B=i[r+1];e.push(li(B,a,g,I,l))}if(A.thermalpad)if(typeof A.thermalpad=="boolean"){const r=A.p*(n-1)+A.pw,a=A.p*(n-1)+A.pw;e.push(li(["thermalpad"],0,0,r,a))}else e.push(li(["thermalpad"],0,0,A.thermalpad.x,A.thermalpad.y));const o=[];for(const[r,a,g]of[["top-left",-1,1],["bottom-left",-1,-1],["bottom-right",1,-1],["top-right",1,1]]){const c=A.w/2*a,I=A.h/2*g;let l="none",B=c,C=I;const Q=A.pw*2;i[1]===1&&r==="top-left"?l="in1":i[n*4]===1&&r==="top-left"||i[n*3+1]===1&&r==="top-right"?l="in2":i[n*3]===1&&r==="top-right"||i[n]===1&&r==="bottom-left"?l="in1":i[n+1]===1&&r==="bottom-left"?l="in2":i[n*2]===1&&r==="bottom-right"?l="in1":i[n*2+1]===1&&r==="bottom-right"&&(l="in2");const h=l==="in1"?1:-1;if(A.legsoutside){const E=l==="in1"?A.pl/2:A.pw/2,u=l==="in1"?A.pw/2:A.pl/2;B+=E*a*h,C-=u*g*h}(l==="none"||A.legsoutside)&&o.push({layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:`pcb_silkscreen_path_${r}`,route:[{x:c-Q*a,y:I},{x:c,y:I},{x:c,y:I-Q*g}],type:"pcb_silkscreen_path",stroke_width:.1}),(l==="in1"||l==="in2")&&!A.legsoutside&&o.push({layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:`pcb_silkscreen_path_${r}_1`,route:[{x:c-Q*a,y:I},{x:c-Q*a/2,y:I}],type:"pcb_silkscreen_path",stroke_width:0},{layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:`pcb_silkscreen_path_${r}_2`,route:[{x:c,y:I-Q*g/2},{x:c,y:I-Q*g}],type:"pcb_silkscreen_path",stroke_width:.1}),(l==="in1"||l==="in2")&&o.push({layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:`pcb_silkscreen_path_${r}_3`,route:[{x:B-.2*-a,y:C+.2*h},{x:B,y:C},{x:B+.2*h*-a,y:C+.2},{x:B-.2*-a,y:C+.2*h}],type:"pcb_silkscreen_path",stroke_width:.1})}const s=Ui(0,A.h/2+(A.legsoutside?A.pl*1.2:.5),.3);return{circuitJson:[...e,...o,s],parameters:A}};rpA.extend({}).transform(apA);var TMt=t=>(t.legsoutside=!1,t.pl||(t.pl=.875),t.pw||(t.pw=.25),_1(t)),PMt=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 _1(t)},KMt=t=>{t.legsoutside=!0;const A=Fie.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=A.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=A.pw;break}return _1(t)};rpA.extend({}).transform(apA);var qMt=t=>(t.legsoutside=!1,t.thermalpad===void 0&&(t.thermalpad=!0),_1(t)),OMt=Ri.extend({fn:U(),num_pins:OA().optional().default(8),w:IA.default(IA.parse("3.9mm")),p:IA.default(IA.parse("1.27mm")),pw:IA.optional(),pl:IA.optional(),legsoutside:PA().optional().default(!1),silkscreen_stroke_width:OA().optional().default(.1)}).transform(t=>(t.pw==null&&t.pl==null?(t.pw=IA.parse("0.51mm"),t.pl=IA.parse("1.1mm")):t.pw==null?t.pw=t.pl*(.51/1.1):t.pl==null&&(t.pl=t.pw*(1.1/.51)),t)),WMt=t=>{const{num_pins:A,pn:e,w:i,p:n}=t,o=A/2,s=e<=o,r=o-1,a=n,g=a*r,c=i+IA.parse("0.2mm"),I=(s?-1:1)*(c/2);return s?{x:I,y:g/2-(e-1)*a}:{x:I,y:-g/2+(e-o-1)*a}},ZMt=t=>{const A=OMt.parse(t),e=[];for(let a=0;a<A.num_pins;a++){const{x:g,y:c}=WMt({num_pins:A.num_pins,pn:a+1,w:A.w,p:A.p,pl:A.pl,legsoutside:A.legsoutside});e.push(li(a+1,g,c,A.pl,A.pw))}const i=Math.min(1,A.p/2),n=A.w-(A.legsoutside?0:A.pl)-.2,o=(A.num_pins/2-1)*A.p+A.pw+i,s=Ui(0,o/2+.4,o/12),r={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",stroke_width:A.silkscreen_stroke_width??.1,route:[{x:-n/2,y:-o/2},{x:-n/2,y:o/2},...qV.map(({x:a,y:g})=>({x:a*n/6,y:g*n/6+o/2})),{x:n/2,y:o/2},{x:n/2,y:-o/2},{x:-n/2,y:-o/2}]};return{circuitJson:[...e,r,s],parameters:A}},VMt=Ri.extend({fn:U(),num_pins:OA().optional().default(8),w:IA.default(IA.parse("3.0mm")),p:IA.default(IA.parse("0.5mm")),pw:IA.default(IA.parse("0.30mm")),pl:IA.default(IA.parse("1.45mm")),legsoutside:PA().optional().default(!0),silkscreen_stroke_width:OA().optional().default(.1)}),jMt=t=>{const{num_pins:A,pn:e,w:i,p:n,pl:o,legsoutside:s}=t,r=A/2,a=e<=r,g=r-1,c=n*g,I=s?o/2:-o/2;return a?{x:-i/2-I,y:c/2-(e-1)*n}:{x:i/2+I,y:-c/2+(e-r-1)*n}},zMt=t=>{const A={...t},e=A.p,i=typeof e=="string"||typeof e=="number"?IA.parse(e):void 0,n=i!=null&&i<=IA.parse("0.5mm"),o=VMt.parse(A),s=[],r=n?o.w-IA.parse("0.15mm"):o.w;for(let B=0;B<o.num_pins;B++){const{x:C,y:Q}=jMt({num_pins:o.num_pins,pn:B+1,w:r,p:o.p,pl:o.pl,legsoutside:o.legsoutside});s.push(li(B+1,C,Q,o.pl,o.pw))}const a=Math.min(1,o.p/2),g=o.w-(o.legsoutside?0:o.pl*2)-.2,c=(o.num_pins/2-1)*o.p+o.pw+a,I=Ui(0,c/2+.4,c/12),l={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",stroke_width:o.silkscreen_stroke_width??.1,route:[{x:-g/2,y:-c/2},{x:-g/2,y:c/2},...qV.map(({x:B,y:C})=>({x:B*g/6,y:C*g/6+c/2})),{x:g/2,y:c/2},{x:g/2,y:-c/2},{x:-g/2,y:-c/2}]};return{circuitJson:[...s,l,I],parameters:o}},XMt=Ri.extend({fn:U(),num_pins:xA(6).default(6),w:U().default("3.1mm"),h:U().default("2.0mm"),p:U().default("0.65mm"),pl:U().default("1.03mm"),pw:U().default("0.35mm"),string:U().optional()}),$Mt=t=>{const A=XMt.parse({...t,fn:"sot363"}),e=IA.parse(A.w),i=IA.parse(A.h),n=IA.parse(A.p),o=IA.parse(A.pl),s=IA.parse(A.pw),r=[];for(let B=0;B<6;B++){const{x:C,y:Q}=Mie(B+1,e,n);r.push(li(B+1,C,Q,o,s))}const a={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-e/4,y:i/2+.1},{x:e/4,y:i/2+.1}],stroke_width:.05,pcb_silkscreen_path_id:""},g={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-e/4,y:-i/2-.1},{x:e/4,y:-i/2-.1}],stroke_width:.05,pcb_silkscreen_path_id:""},c=Mie(1,e,n),I={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"pin_marker_1",route:[{x:c.x-o/2-.3,y:c.y},{x:c.x-o/2-.45,y:c.y+.15},{x:c.x-o/2-.45,y:c.y-.15},{x:c.x-o/2-.3,y:c.y}],stroke_width:.05,pcb_silkscreen_path_id:"pin_marker_1"},l=Ui(0,i/2+.4,.25);return{circuitJson:[...r,a,g,l,I],parameters:A}},Mie=(t,A,e,i)=>t<=3?{x:-.84,y:e-(t-1)*e}:{x:.84,y:-e+(t-4)*e},ARt=Ri.extend({fn:U(),num_pins:xA(6).default(6),w:U().default("1.01mm"),h:U().default("1.45mm"),p:U().default("0.5mm"),pl:U().default("0.33mm"),pw:U().default("0.27mm"),string:U().optional()}),eRt=t=>{const A=ARt.parse({...t,fn:"sot886"}),e=IA.parse(A.w),i=IA.parse(A.h),n=IA.parse(A.p),o=IA.parse(A.pl),s=IA.parse(A.pw),r=[];for(let B=0;B<6;B++){const{x:C,y:Q}=Rie(B+1,e,n,o);r.push(li(B+1,C,Q,o,s))}const a={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-e/2,y:i/2},{x:e/2,y:i/2}],stroke_width:.05,pcb_silkscreen_path_id:""},g={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-e/2,y:-i/2},{x:e/2,y:-i/2}],stroke_width:.05,pcb_silkscreen_path_id:""},c=Rie(1,e,n,o),I={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"pin_marker_1",route:[{x:c.x-o/2-.3,y:c.y},{x:c.x-o/2-.45,y:c.y+.15},{x:c.x-o/2-.45,y:c.y-.15},{x:c.x-o/2-.3,y:c.y}],stroke_width:.05,pcb_silkscreen_path_id:"pin_marker_1"},l=Ui(0,i/2+.4,.25);return{circuitJson:[...r,a,g,l,I],parameters:A}},Rie=(t,A,e,i)=>{const n=A/2-i/2;return t<=3?{x:-n,y:e-(t-1)*e}:{x:n,y:-e+(t-4)*e}},Nie=Ri.extend({fn:U(),num_pins:OA().default(3),w:U().default("1.92mm"),h:U().default("2.74mm"),pl:U().default("1.32mm"),pw:U().default("0.6mm"),p:U().default("0.95mm"),string:U().optional()}),tRt=oM({p:"0.95mm",w:"1.6mm",legsoutside:!0}),iRt=t=>{const A=t.string?.match(/^sot23_(\d+)/),e=A?Number.parseInt(A[1],10):3;if(e===6||e===8){const n=tRt.parse({...t,num_pins:e});return{circuitJson:lJ(n),parameters:n}}const i=Nie.parse({...t,num_pins:e});if(i.num_pins===3)return{circuitJson:oRt(i),parameters:i};if(i.num_pins===5)return{circuitJson:Lie(i),parameters:i};throw new Error("Invalid number of pins")},nRt=t=>{const{pn:A,p:e}=t;return A===1?{x:-1.155,y:e}:A===2?{x:-1.155,y:-e}:{x:1.15,y:0}},oRt=t=>{const A=[];for(let i=0;i<t.num_pins;i++){const{x:n,y:o}=nRt({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)});A.push(li(i+1,n,o,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}const e=Ui(0,Number.parseInt(t.h),.3);return[...A,e]},Gie=t=>{const{p:A,h:e,pn:i}=t;if(i===1)return{x:-e/2-.5,y:A};if(i===2)return{x:-e/2-.5,y:0};if(i===3)return{x:-e/2-.5,y:-A};if(i===4)return{x:e/2+.5,y:-A};if(i===5)return{x:e/2+.5,y:A};throw new Error("Invalid pin number")},Lie=t=>{const A=[];for(let I=1;I<=t.num_pins;I++){const{x:l,y:B}=Gie({h:Number.parseFloat(t.h),p:Number.parseFloat(t.p),pn:I});A.push(li(I,l,B,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}const e=(t.num_pins+1)/2*Number.parseFloat(t.p),i=Number.parseFloat(t.h),n={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-e/3,y:i/2+Number.parseFloat(t.p)/1.3},{x:e/3,y:i/2+Number.parseFloat(t.p)/1.3}],type:"pcb_silkscreen_path",stroke_width:.05},o={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_2",route:[{x:-e/3,y:-i/2-Number.parseFloat(t.p)/1.3},{x:e/3,y:-i/2-Number.parseFloat(t.p)/1.3}],type:"pcb_silkscreen_path",stroke_width:.05},s=Ui(0,i+.3,.3),r=Gie({h:Number.parseFloat(t.h),p:Number.parseFloat(t.p),pn:1});r.x=r.x-Number.parseFloat(t.pw)*1.5;const a=.3,g=.4,c={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"pin1_indicator",route:[{x:r.x+a/2,y:r.y},{x:r.x-a/2,y:r.y+g/2},{x:r.x-a/2,y:r.y-g/2},{x:r.x+a/2,y:r.y}],stroke_width:.05};return[...A,s,n,o,c]},sRt=Nie.extend({}),rRt=t=>{const A=sRt.parse({...t,num_pins:5});return{circuitJson:Lie(A),parameters:A}},aRt=[{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}],gRt=oM({}),cRt=t=>{const A=gRt.parse(t),e=[];for(let I=0;I<A.num_pins;I++){const{x:l,y:B}=spA({num_pins:A.num_pins,pn:I+1,w:A.w,p:A.p??1.27,pl:A.pl,widthincludeslegs:!0});e.push(li(I+1,l,B,A.pl??"1mm",A.pw??"0.6mm"))}const i=Math.min(1,A.p/2),n=A.w+i,o=(A.num_pins/2-1)*A.p+A.pw+i,s=[];for(const I of aRt){const{dx:l,dy:B}=I;s.push({layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"",route:[{x:l*n/2-l*A.p,y:B*o/2},{x:l*n/2,y:B*o/2},{x:l*n/2,y:B*o/2-B*A.p}],type:"pcb_silkscreen_path",stroke_width:.1})}const r=A.p/4,a=-n/2-r/2,g=o/2-A.p/2;s.push({layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"",type:"pcb_silkscreen_path",route:[{x:a,y:g},{x:a-r,y:g+r},{x:a-r,y:g-r},{x:a,y:g}],stroke_width:.1});const c=Ui(0,o/2+.4,o/12);return{circuitJson:[...e,c,...s],parameters:A}},sM=({fs:t,pn:A,anchor_x:e,anchor_y:i,textalign:n="center",orthogonal:o=!1,verticallyinverted:s=!1,layer:r="top"})=>{let a=0;o&&s?a=270:s?a=180:o?a=90:a=0;let g="center";return n==="left"&&(s?g="center_right":g="center_left"),n==="right"&&(s?g="center_left":g="center_right"),r==="bottom"&&(g==="center_left"?g="center_right":g==="center_right"&&(g="center_left")),{type:"pcb_silkscreen_text",pcb_silkscreen_text_id:"silkscreen_text_1",font:"tscircuit2024",font_size:t,pcb_component_id:"pcb_component_1",text:`{PIN${A}}`,layer:r,anchor_position:{x:e,y:i},anchor_alignment:g,ccw_rotation:a}};function Uie({pinlabeltextalignleft:t,pinlabeltextalignright:A,pinlabelorthogonal:e}){let i="top";return e?i="left":i="top",t&&(e?i="bottom":i="right"),A&&(e?i="top":i="left"),i}var IRt=Ri.extend({fn:U(),num_pins:OA().optional().default(6),rows:Rt([U(),OA()]).transform(t=>Number(t)).optional().default(1).describe("number of rows"),p:IA.default("0.1in").describe("pitch"),id:IA.default("1.0mm").describe("inner diameter"),od:IA.default("1.5mm").describe("outer diameter"),male:PA().optional().describe("for male pin headers"),female:PA().optional().describe("for female pin headers"),smd:PA().optional().describe("surface mount device"),surfacemount:PA().optional().describe("surface mount device (verbose)"),rightangle:PA().optional().describe("right angle"),pw:IA.optional().default("1.0mm").describe("pad width for SMD"),pl:IA.optional().default("2.0mm").describe("pad length for SMD"),pinlabeltextalignleft:PA().optional().default(!1),pinlabeltextaligncenter:PA().optional().default(!1),pinlabeltextalignright:PA().optional().default(!1),pinlabelverticallyinverted:PA().optional().default(!1),pinlabelorthogonal:PA().optional().default(!1),nosquareplating:PA().optional().default(!1).describe("do not use rectangular pad for pin 1"),nopinlabels:PA().optional().default(!1).describe("omit silkscreen pin labels"),doublesidedpinlabel:PA().optional().default(!1).describe("add silkscreen pins in top and bottom layers"),bottomsidepinlabel:PA().optional().default(!1).describe("place the silkscreen reference text on the bottom layer instead of top")}).transform(t=>{const A=Uie(t);return{...t,pinlabelAnchorSide:A,male:t.male??!t.female,female:t.female??!1,smd:t.smd??t.surfacemount??!1,rightangle:t.rightangle??!1}}).superRefine((t,A)=>{t.male&&t.female&&A.addIssue({code:zt.custom,message:"'male' and 'female' cannot both be true; it should be male or female.",path:["male","female"]})}),lRt=t=>{const A=IRt.parse(t),{p:e,id:i,od:n,rows:o,num_pins:s,pinlabelAnchorSide:r,pinlabelverticallyinverted:a,pinlabelorthogonal:g,pinlabeltextalignleft:c,pinlabeltextalignright:I,nopinlabels:l,doublesidedpinlabel:B,bottomsidepinlabel:C}=A;let Q="center";c?Q="left":I&&(Q="right");const h=[],E=Math.ceil(s/o),u=-e,d=({xoff:S,yoff:_,od:b,anchorSide:N,smd:F,pw:L,pl:Y})=>{let J=0,O=0;if(F){const Z=b/5;switch(N){case"right":J=L/2+Z;break;case"top":O=Y/2+Z;break;case"bottom":O=-(Y/2+Z);break;case"left":J=-(L/2+Z);break}}else{const Z=b*.75;switch(N){case"right":J=Z;break;case"top":O=Z;break;case"bottom":O=-Z;break;case"left":J=-Z;break}}return{anchor_x:S+J,anchor_y:_+O}},f=(S,_,b)=>{A.smd?h.push(li(S,_,b,A.pw,A.pl)):S===1&&!A.nosquareplating?h.push(fm({pn:S,x:_,y:b,holeDiameter:i,rectPadWidth:n,rectPadHeight:n})):h.push(Fo(S,_,b,i,n));const{anchor_x:N,anchor_y:F}=d({xoff:_,yoff:b,od:n,anchorSide:r,smd:A.smd,pw:A.pw,pl:A.pl});l||(C?h.push(sM({fs:n/5,pn:S,anchor_x:N,anchor_y:F,textalign:Q,orthogonal:g,verticallyinverted:a,layer:"bottom"})):h.push(sM({fs:n/5,pn:S,anchor_x:N,anchor_y:F,textalign:Q,orthogonal:g,verticallyinverted:a,layer:"top"})),B&&h.push(sM({fs:n/5,pn:S,anchor_x:N,anchor_y:F,textalign:Q,orthogonal:g,verticallyinverted:a,layer:"bottom"})))},y=new Set,w=o>2&&E>2;if(o===1){const S=-((s-1)/2)*e;for(let _=0;_<s;_++){const b=_+1,N=S+_*e,F=`${N},0`;if(y.has(F))throw new Error(`Overlap at ${F}`);y.add(F),f(b,N,0)}}else if(w){const S=-((E-1)/2)*e;let _=1;for(let b=0;b<o&&_<=s;b++)for(let N=0;N<E&&_<=s;N++){const F=S+N*e,L=b*u,Y=`${F},${L}`;if(y.has(Y))throw new Error(`Overlap at ${Y}`);y.add(Y),f(_++,F,L)}}else{const S=-((E-1)/2)*e;let _=1,b=0,N=o-1,F=0,L=E-1;for(;_<=s&&b<=N&&F<=L;){for(let Y=b;Y<=N&&_<=s;Y++){const J=S+F*e,O=Y*u,Z=`${J},${O}`;if(y.has(Z))throw new Error(`Overlap at ${Z}`);y.add(Z),f(_++,J,O)}F++;for(let Y=F;Y<=L&&_<=s;Y++){const J=S+Y*e,O=N*u,Z=`${J},${O}`;if(y.has(Z))throw new Error(`Overlap at ${Z}`);y.add(Z),f(_++,J,O)}if(N--,F<=L){for(let Y=N;Y>=b&&_<=s;Y--){const J=S+L*e,O=Y*u,Z=`${J},${O}`;if(y.has(Z))throw new Error(`Overlap at ${Z}`);y.add(Z),f(_++,J,O)}L--}if(b<=N){for(let Y=L;Y>=F&&_<=s;Y--){const J=S+Y*e,O=b*u,Z=`${J},${O}`;if(y.has(Z))throw new Error(`Overlap at ${Z}`);y.add(Z),f(_++,J,O)}b++}}if(_-1<s)throw new Error(`Missing pins: assigned ${_-1}, expected ${s}`)}const D=Ui(0,e,.5);return{circuitJson:[...h,D],parameters:A}},BRt=Ri.extend({fn:U(),num_pins:xA(6).default(6),w:U().default("2.1mm"),h:U().default("2.45mm"),p:U().default("0.5mm"),pl:U().default("0.675mm"),pw:U().default("0.35mm"),string:U().optional()}),CRt=t=>{const A=BRt.parse({...t,fn:"sot563"}),e=IA.parse(A.w),i=IA.parse(A.h),n=IA.parse(A.p),o=IA.parse(A.pl),s=IA.parse(A.pw),r=[];for(let B=0;B<6;B++){const{x:C,y:Q}=Hie(B+1,e,n,o);r.push(li(B+1,C,Q,o,s))}const a={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-e/2,y:i/2},{x:e/2,y:i/2}],stroke_width:.05,pcb_silkscreen_path_id:""},g={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-e/2,y:-i/2},{x:e/2,y:-i/2}],stroke_width:.05,pcb_silkscreen_path_id:""},c=Hie(1,e,n,o),I={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"pin_marker_1",route:[{x:c.x-o/2-.3,y:c.y},{x:c.x-o/2-.45,y:c.y+.15},{x:c.x-o/2-.45,y:c.y-.15},{x:c.x-o/2-.3,y:c.y}],stroke_width:.05,pcb_silkscreen_path_id:"pin_marker_1"},l=Ui(0,i/2+.4,.25);return{circuitJson:[...r,a,g,l,I],parameters:A}},Hie=(t,A,e,i)=>{const n=A/2-i/2;return t<=3?{x:-n,y:e-(t-1)*e}:{x:n,y:-e+(t-4)*e}},QRt=oM({p:"1.27mm",w:"3.9mm",legsoutside:!0}),hRt=t=>{const A=QRt.parse({...t,num_pins:8});return{circuitJson:lJ(A),parameters:A}},ERt=oM({p:"1.27mm",w:"7.5mm",legsoutside:!0}),uRt=t=>{const A=ERt.parse({...t,num_pins:16});return{circuitJson:lJ(A),parameters:A}},dRt=Ri.extend({fn:U(),num_pins:xA(3).default(3),w:U().default("1.2mm"),h:U().default("1.2mm"),pw:U().default("0.40mm"),pl:U().default("0.45mm"),p:U().default("0.575mm")}),pRt=t=>{const A=dRt.parse(t),e=yRt(A),i=Ui(0,IA.parse(A.h),.2);return{circuitJson:[...e,i],parameters:A}},fRt=t=>{const{pn:A,p:e}=t;return A===1?{x:e,y:0}:A===2?{x:-e,y:-.4}:{x:-e,y:.4}},yRt=t=>{const A=[];for(let e=0;e<3;e++){const{x:i,y:n}=fRt({num_pins:t.num_pins,pn:e+1,w:Number.parseFloat(t.w),h:Number.parseFloat(t.h),pl:Number.parseFloat(t.pl),p:Number.parseFloat(t.p)});A.push(li(e+1,i,n,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},mRt=Ri.extend({fn:U(),num_pins:xA(2).default(2),w:U().default("2.36mm"),h:U().default("1.22mm"),pl:U().default("0.9mm"),pw:U().default("1.2mm"),p:U().default("3.30mm")}),wRt=t=>{const A=mRt.parse(t),e=Ui(0,IA.parse(A.h)/4+.4,.3);return{circuitJson:SRt(A).concat(e),parameters:A}},DRt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},SRt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:n}=DRt({pn:e,p:Number.parseFloat(t.p)});A.push(li(e,i,n,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},bRt=Ri.extend({fn:U(),p:IA.optional().default("2.54mm"),id:IA.optional().default("0.7mm"),od:IA.optional().default("1.4mm")}),xRt=t=>{const A=bRt.parse(t),{p:e,id:i,od:n}=A,o=[Fo(1,-e/2,0,i,n),Fo(2,e/2,0,i,n)],s={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-e/2+n+i/2,y:0},{x:e/2-n-i/2,y:0}],stroke_width:.1,pcb_silkscreen_path_id:""},r=Ui(0,1.5,.5);return{circuitJson:[...o,s,r],parameters:A}},_Rt=(t,A,e,i,n,o=.1)=>{const s=[],r=[],a=Math.max(1,Math.ceil(Math.PI*e/o)),g=Math.PI/a;for(let c=0;c<=a;c++){const I=c*g,l=t+Math.cos(I)*e,B=A+Math.sin(I)*e;l<t-i&&B>=A-n/2&&B<=A+n/2||s.push({x:l,y:B})}for(let c=0;c<=a;c++){const I=Math.PI+c*g,l=t+Math.cos(I)*e,B=A+Math.sin(I)*e;l<t-i&&B>=A-n/2&&B<=A+n/2||r.push({x:l,y:B})}return{topArc:s,bottomArc:r}},kRt=Ri.extend({fn:U(),p:IA.optional().default("5mm"),id:IA.optional().default("0.8mm"),od:IA.optional().default("1.6mm"),ceramic:PA().optional(),electrolytic:PA().optional(),polarized:PA().optional()}),vRt=t=>{const A=kRt.parse(t),{p:e,id:i,od:n}=A;i===.8&&n===1.6&&(A.id=e===5?.8:e*.25,A.od=e===5?1.6:e*.5);const o=[Fo(1,-e/2,0,A.id,A.od),Fo(2,e/2,0,A.id,A.od)],s=e+.1,{topArc:r,bottomArc:a}=_Rt(0,0,s,A.od/2,A.od),g=.02*e,c={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:r,stroke_width:g,pcb_silkscreen_path_id:""},I={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:a,stroke_width:g,pcb_silkscreen_path_id:""},l={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:0,y:s},{x:0,y:-s}],stroke_width:g,pcb_silkscreen_path_id:""},B=.1*e,C=-(e+B+.04*e),Q=s-B-.08*e,h={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:C-B,y:Q},{x:C+B,y:Q}],stroke_width:g,pcb_silkscreen_path_id:""},E={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:C,y:Q-B},{x:C,y:Q+B}],stroke_width:g,pcb_silkscreen_path_id:""},u=Ui(0,s+.12*e,.1*e),d=[...o,c,I,l,u];return(A.electrolytic===!0||A.polarized===!0)&&d.push(h,E),{circuitJson:d,parameters:A}},rM=(t,A={})=>({type:"pcb_silkscreen_path",layer:A.layer||"top",pcb_component_id:A.pcb_component_id||"",pcb_silkscreen_path_id:A.pcb_silkscreen_path_id||"",route:t,stroke_width:A.stroke_width||.1}),FRt=Ri.extend({fn:xA("pushbutton"),w:IA.default(4.5),h:IA.default(6.5),id:IA.default(1),od:IA.default(1.2)}),MRt=t=>{const A=FRt.parse(t),e=A.w,i=A.h,n=A.id,o=[Fo(1,-e/2,i/2,n,n*1.5),Fo(2,-e/2,-i/2,n,n*1.5),Fo(3,e/2,-i/2,n,n*1.5),Fo(4,e/2,i/2,n,n*1.5)],s=[rM([{x:-e/2,y:-i/2},{x:-e/2,y:i/2}]),rM([{x:e/2,y:-i/2},{x:e/2,y:i/2}]),rM([{x:-e/2,y:0},{x:-e/5,y:0},{x:e/5*1/Math.sqrt(2),y:i/8}]),rM([{x:e/2,y:0},{x:e/5,y:0}])],r=Ui(0,i/2+.4,.5);return{circuitJson:[...o,...s,r],parameters:A}},Yie=Ri.extend({fn:U(),w:IA.default("22.58mm"),h:IA.optional(),left:IA.optional().default(20),right:IA.optional().default(20),top:IA.optional().default(2),bottom:IA.optional().default(2),p:IA.default(IA.parse("2.54mm")),pw:IA.default(IA.parse("1.6mm")),pl:IA.default(IA.parse("2.4mm")),innerhole:PA().default(!1),innerholeedgedistance:IA.default(IA.parse("1.61mm")),silkscreenlabels:PA().default(!1),silkscreenlabelmargin:IA.default(IA.parse("0.1mm"))}),RRt=t=>{const A=Yie.parse(t);return A.left&&A.right?Math.max(A.left,A.right)*A.p:A.left?A.left*A.p:A.right?A.right*A.p:51},jV=(t,A,e)=>{let i=[];return e==="right"&&(i=[{x:t+1/2,y:A},{x:t-1/2,y:A+.6/2},{x:t-1/2,y:A-.6/2},{x:t+1/2,y:A}]),e==="left"&&(i=[{x:t-1/2,y:A},{x:t+1/2,y:A+.6/2},{x:t+1/2,y:A-.6/2},{x:t-1/2,y:A}]),e==="top"&&(i=[{x:t,y:A+1/2},{x:t-.6/2,y:A-1/2},{x:t+.6/2,y:A-1/2},{x:t,y:A+1/2}]),e==="bottom"&&(i=[{x:t,y:A-1/2},{x:t-.6/2,y:A+1/2},{x:t+.6/2,y:A+1/2},{x:t,y:A-1/2}]),i},NRt=t=>{const A=Yie.parse(t),e=A.h??RRt(A),i=[],n=[],o=[];let s=[];const r=1,a=r,g=A.left+A.right+(A.bottom??0)+(A.top??0),I=`pin${g}`.length*.7/2;if(A.right){const Q=-((A.right-1)/2)*A.p;for(let h=0;h<A.right;h++){if(h===0&&!A.left&&!A.bottom&&!A.silkscreenlabels&&(s=jV(A.w/2-A.pl*1.4,Q+h*A.p,"right")),i.push(li(h+1+A.left+(A.bottom??0),A.w/2-A.pl/2,Q+h*A.p,A.pl,A.pw)),A.silkscreenlabels){const E=h+1+A.left+(A.bottom??0),u=`pin${E}`;o.push({type:"pcb_silkscreen_text",pcb_silkscreen_text_id:`pin_${E}`,pcb_component_id:"1",layer:"top",anchor_position:{x:A.w/2-A.pl-(I+A.silkscreenlabelmargin),y:Q+h*A.p},text:u,font_size:.7,font:"tscircuit2024",anchor_alignment:"center"})}A.innerhole&&(n.push(Fo(h+1+A.left+(A.bottom??0)+g,A.w/2,Q+h*A.p,r,a)),n.push(Fo(h+1+A.left+(A.bottom??0)+g*2,A.w/2-A.innerholeedgedistance,Q+h*A.p,r,a)))}}if(A.left){const Q=(A.left-1)/2*A.p;for(let h=0;h<A.left;h++){if(h===0&&!A.silkscreenlabels&&(s=jV(-A.w/2+A.pl*1.4,Q-h*A.p,"left")),i.push(li(h+1,-A.w/2+A.pl/2,Q-h*A.p,A.pl,A.pw)),A.silkscreenlabels){const E=h+1,u=`pin${E}`;o.push({type:"pcb_silkscreen_text",pcb_silkscreen_text_id:`pin_${E}`,pcb_component_id:"1",layer:"top",anchor_position:{x:-A.w/2+A.pl+(I+A.silkscreenlabelmargin),y:Q-h*A.p},text:u,font_size:.7,font:"tscircuit2024",anchor_alignment:"center"})}A.innerhole&&(n.push(Fo(h+1+g,-A.w/2,Q-h*A.p,r,a)),n.push(Fo(h+1+g*2,-A.w/2+A.innerholeedgedistance,Q-h*A.p,r,a)))}}if(A.top){const Q=(A.top-1)/2*A.p;for(let h=0;h<A.top;h++){if(h===0&&!A.left&&!A.bottom&&!A.right&&!A.silkscreenlabels&&(s=jV(Q-h*A.p,e/2-A.pl*1.4,"top")),i.push(li(h+1+A.left+A.right+(A.bottom??0),Q-h*A.p,e/2-A.pl/2,A.pw,A.pl)),A.silkscreenlabels){const E=h+1+A.left+A.right+(A.bottom??0),u=`pin${E}`;o.push({type:"pcb_silkscreen_text",pcb_silkscreen_text_id:`pin_${E}`,pcb_component_id:"1",layer:"top",anchor_position:{x:Q-h*A.p,y:e/2-A.pl-(I+A.silkscreenlabelmargin)},text:u,font_size:.7,font:"tscircuit2024",anchor_alignment:"center",ccw_rotation:270})}A.innerhole&&(n.push(Fo(h+1+A.left+A.right+(A.bottom??0)+g,Q-h*A.p,e/2,r,a)),n.push(Fo(h+1+A.left+A.right+(A.bottom??0)+g*2,Q-h*A.p,e/2-A.innerholeedgedistance,r,a)))}}if(A.bottom){const Q=-((A.bottom-1)/2)*A.p;for(let h=0;h<A.bottom;h++){if(h===0&&!A.left&&!A.silkscreenlabels&&(s=jV(Q+h*A.p,-e/2+A.pl*1.4,"bottom")),i.push(li(h+1+A.left,Q+h*A.p,-e/2+A.pl/2,A.pw,A.pl)),A.silkscreenlabels){const E=h+1+A.left,u=`pin${E}`;o.push({type:"pcb_silkscreen_text",pcb_silkscreen_text_id:`pin_${E}`,pcb_component_id:"1",layer:"top",anchor_position:{x:Q+h*A.p,y:-e/2+A.pl+(I+A.silkscreenlabelmargin)},text:u,font_size:.7,font:"tscircuit2024",anchor_alignment:"center",ccw_rotation:90})}A.innerhole&&(n.push(Fo(h+1+A.left+g,Q+h*A.p,-e/2,r,a)),n.push(Fo(h+1+A.left+g*2,Q+h*A.p,-e/2+A.innerholeedgedistance,r,a)))}}const l={type:"pcb_silkscreen_path",pcb_silkscreen_path_id:"pcb_silkscreen_triangle_1",pcb_component_id:"2",route:s,stroke_width:.1,layer:"top"},B={type:"pcb_silkscreen_path",pcb_silkscreen_path_id:"pcb_silkscreen_path_1",pcb_component_id:"1",route:[{x:-A.w/2,y:e/2},{x:A.w/2,y:e/2},{x:A.w/2,y:-e/2},{x:-A.w/2,y:-e/2},{x:-A.w/2,y:e/2}],stroke_width:.1,layer:"top"},C=Ui(0,e/1.8,e/25);return{circuitJson:[...i,...n,...o,B,...A.silkscreenlabels?[]:[l],C],parameters:A}},Jie=Ri.extend({fn:U(),w:IA.default("22.58mm"),h:IA.optional(),left:IA.optional().default(20),right:IA.optional().default(20),top:IA.optional().default(2),bottom:IA.optional().default(2),p:IA.default(IA.parse("2.54mm")),pw:IA.default(IA.parse("1.6mm")),pl:IA.default(IA.parse("3.2mm")),innerhole:PA().default(!1),innerholeedgedistance:IA.default(IA.parse("1.61mm"))}),GRt=t=>{const A=Jie.parse(t);return A.left&&A.right?Math.max(A.left,A.right)*A.p:A.left?A.left*A.p:A.right?A.right*A.p:51},LRt=(t,A,e,i=1,n=.6)=>{const o=i/2,s=n/2;return{left:[{x:t+o,y:A},{x:t-o,y:A+s},{x:t-o,y:A-s},{x:t+o,y:A}],right:[{x:t-o,y:A},{x:t+o,y:A+s},{x:t+o,y:A-s},{x:t-o,y:A}],top:[{x:t,y:A-o},{x:t-s,y:A+o},{x:t+s,y:A+o},{x:t,y:A-o}],bottom:[{x:t,y:A+o},{x:t-s,y:A-o},{x:t+s,y:A-o},{x:t,y:A+o}]}[e]},URt=t=>{const A=Jie.parse(t),e=A.h??GRt(A),i=[],n=[],o=[],s=1,r=1.2,a=A.left+A.right+(A.bottom??0)+(A.top??0);let g=[],c=1;if(A.left){const C=(A.left-1)/2*A.p;for(let Q=0;Q<A.left;Q++)Q===0&&(g=LRt(-A.w/2-A.pl/2,C-Q*A.p,"left")),i.push(li(c,-A.w/2+A.pl/2,C-Q*A.p,A.pl,A.pw)),n.push({type:"pcb_silkscreen_text",pcb_silkscreen_text_id:`pin_${c}`,pcb_component_id:"1",layer:"top",anchor_position:{x:-A.w/2+A.pl/2-4.5,y:C-Q*A.p},text:`pin${c}`,font_size:.7,font:"tscircuit2024",anchor_alignment:"center"}),c++,A.innerhole&&o.push(Fo(c+a,-A.w/2+A.innerholeedgedistance,C-Q*A.p,s,r))}if(A.bottom){const C=(A.bottom-1)/2*A.p;for(let Q=A.bottom-1;Q>=0;Q--)i.push(li(c,C-Q*A.p,-e/2+A.pl/2,A.pw,A.pl)),n.push({type:"pcb_silkscreen_text",pcb_silkscreen_text_id:`pin_${c}`,pcb_component_id:"1",layer:"top",anchor_position:{x:C-Q*A.p,y:-e/2+A.pl/2-3.2},text:`pin${c}`,font_size:.7,font:"tscircuit2024",anchor_alignment:"center"}),c++,A.innerhole&&o.push(Fo(c+a,C-Q*A.p,-e/2+A.innerholeedgedistance,s,r))}if(A.right){const C=-((A.right-1)/2)*A.p;for(let Q=0;Q<A.right;Q++)i.push(li(c,A.w/2-A.pl/2,C+Q*A.p,A.pl,A.pw)),n.push({type:"pcb_silkscreen_text",pcb_silkscreen_text_id:`pin_${c}`,pcb_component_id:"1",layer:"top",anchor_position:{x:A.w/2-A.pl/2+3.7,y:C+Q*A.p},text:`pin${c}`,font_size:.7,font:"tscircuit2024",anchor_alignment:"center"}),c++,A.innerhole&&o.push(Fo(c+a,A.w/2-A.innerholeedgedistance,C+Q*A.p,s,r))}if(A.top){const C=-((A.top-1)/2)*A.p;for(let Q=A.top-1;Q>=0;Q--)i.push(li(c,C+Q*A.p,e/2-A.pl/2,A.pw,A.pl)),n.push({type:"pcb_silkscreen_text",pcb_silkscreen_text_id:`pin_${c}`,pcb_component_id:"1",layer:"top",anchor_position:{x:C+Q*A.p,y:e/2-A.pl/2+3.2},text:`pin${c}`,font_size:.7,font:"tscircuit2024",anchor_alignment:"center"}),c++,A.innerhole&&o.push(Fo(c+a,C+Q*A.p,e/2-A.innerholeedgedistance,s,r))}const I={type:"pcb_silkscreen_path",pcb_silkscreen_path_id:"1",pcb_component_id:"1",layer:"top",route:g,stroke_width:.1},l={type:"pcb_silkscreen_path",pcb_silkscreen_path_id:"pcb_silkscreen_path_1",pcb_component_id:"1",route:[{x:-A.w/2-A.pl/3,y:e/2+A.pl/3},{x:A.w/2+A.pl/3,y:e/2+A.pl/3},{x:A.w/2+A.pl/3,y:-e/2-A.pl/3},{x:-A.w/2-A.pl/3,y:-e/2-A.pl/3},{x:-A.w/2-A.pl/3,y:e/2+A.pl/3}],stroke_width:.1,layer:"top"},B=Ui(0,e/1.8,e/25);return{circuitJson:[...o,...i,...n,l,I,B],parameters:A}},HRt=t=>(t.legsoutside=!0,t.pl||(t.pl=1.5),t.pw||(t.pw=.3),_1(t)),Tie=Ri.extend({fn:U(),w:IA.default("10mm"),h:IA.optional(),left:IA.optional().default(20),right:IA.optional().default(20),top:IA.optional().default(0),bottom:IA.optional().default(0),p:IA.default(IA.parse("2.54mm")),id:IA.optional().default(IA.parse("1mm")),od:IA.optional().default(IA.parse("1.5mm"))}),YRt=t=>{const A=Tie.parse(t);return A.left&&A.right?Math.max(A.left,A.right)*A.p:A.left?A.left*A.p:A.right?A.right*A.p:51},zV=(t,A,e,i=1,n=.6)=>{const o=i/2,s=n/2;return{left:[{x:t+o,y:A},{x:t-o,y:A+s},{x:t-o,y:A-s},{x:t+o,y:A}],right:[{x:t-o,y:A},{x:t+o,y:A+s},{x:t+o,y:A-s},{x:t-o,y:A}],top:[{x:t,y:A-o},{x:t-s,y:A+o},{x:t+s,y:A+o},{x:t,y:A-o}],bottom:[{x:t,y:A+o},{x:t-s,y:A-o},{x:t+s,y:A-o},{x:t,y:A+o}]}[e]},JRt=t=>{const A=Tie.parse(t),e=A.h??YRt(A),i=[],n=A.id,o=A.od;let s=[];if(A.right){const c=-((A.right-1)/2)*A.p;for(let I=0;I<A.right;I++)I===0&&!A.left&&!A.bottom&&(s=zV(A.w/2+o*1.4,c+I*A.p,"right")),i.push(Fo(I+1+A.left+(A.bottom??0),A.w/2,c+I*A.p,n,o))}if(A.left){const c=-((A.left-1)/2)*A.p;for(let I=0;I<A.left;I++)I===A.left-1&&(s=zV(-A.w/2-o*1.4,c+I*A.p,"left")),i.push(Fo(I+1,-A.w/2,c+I*A.p,n,o))}if(A.top){const c=-((A.top-1)/2)*A.p;for(let I=0;I<A.top;I++)I===A.top-1&&!A.left&&!A.bottom&&!A.right&&(s=zV(c+I*A.p,e/2+o*1.4,"top")),i.push(Fo(I+1+A.right+(A.bottom??0)+A.left,c+I*A.p,e/2,n,o))}if(A.bottom){const c=-((A.bottom-1)/2)*A.p;for(let I=0;I<A.bottom;I++)I===0&&!A.left&&(s=zV(c+I*A.p,-e/2-o*1.4,"bottom")),i.push(Fo(I+1+A.left,c+I*A.p,-e/2,n,o))}const r={type:"pcb_silkscreen_path",pcb_silkscreen_path_id:"1",pcb_component_id:"1",layer:"top",route:s,stroke_width:.1},a={type:"pcb_silkscreen_path",pcb_silkscreen_path_id:"pcb_silkscreen_path_1",pcb_component_id:"1",route:[{x:-A.w/2-o,y:e/2+o},{x:A.w/2+o,y:e/2+o},{x:A.w/2+o,y:-e/2-o},{x:-A.w/2-o,y:-e/2-o},{x:-A.w/2-o,y:e/2+o}],stroke_width:.1,layer:"top"},g=Ui(0,e/1.7,e/25);return{circuitJson:[...i,a,g,r],parameters:A}},Pie=(t,A,e,i)=>Array.from({length:25},(n,o)=>{const s=o/24*Math.PI-Math.PI/2;return{x:t+(i==="right"?1:-1)*Math.cos(s)*e,y:A+Math.sin(s)*e}}),TRt=Ri.extend({fn:U(),p:IA.optional().default("4.88mm"),id:IA.optional().default("0.8mm"),od:IA.optional().default("1.5mm"),w:IA.optional().default("5.6mm"),h:IA.optional().default("3.5mm")}),PRt=t=>{const A=TRt.parse(t),{p:e,id:i,od:n,w:o,h:s}=A,r=s/2,a=[Fo(1,-e/2,0,i,n),Fo(2,e/2,0,i,n)],g=Pie(-o/2,0,r,"left"),c=Pie(o/2,0,r,"right"),I={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[...g,...g.slice(1).reverse(),{x:-o/2,y:-s/2},{x:o/2,y:-s/2},...c,{x:o/2,y:s/2},{x:-o/2,y:s/2}],stroke_width:.1,pcb_silkscreen_path_id:""},l=Ui(0,e/4,.5);return{circuitJson:[...a,I,l],parameters:A}};Ri.extend({w:IA,h:IA});var KRt=t=>{const{w:A,h:e}=t,i=cr(A),n=cr(e);return{circuitJson:[li(1,0,0,i,n),Ui(0,n/2+.5,.2)],parameters:t}},aM=(t,A,e,i,n,o)=>({pcb_plated_hole_id:"",type:"pcb_plated_hole",shape:"pill",x:A,y:e,outer_width:cr(n),outer_height:cr(o),hole_width:cr(i),hole_height:cr(i),pcb_port_id:"",layers:["top","bottom"],port_hints:[t.toString()],ccw_rotation:0}),qRt=Ri.extend({fn:U(),num_pins:Rt([xA(3),xA(2)]).default(3),p:U().default("1.27mm"),id:U().default("0.72mm"),od:U().default("0.95mm"),w:U().default("4.5mm"),h:U().default("4.5mm"),inline:PA().default(!1),string:U().optional()}),ORt=(t,A,e)=>Array.from({length:25},(i,n)=>{const o=n/24*Math.PI;return{x:t+Math.cos(o)*e,y:A+Math.sin(o)*e}}),WRt=t=>{const A=t.string?.match(/^to92_(\d+)/),e=A?Number.parseInt(A[1],10):3,i=qRt.parse({...t,num_pins:e}),{p:n,id:o,od:s,w:r,h:a,inline:g}=i,c=Number.parseFloat(a)/2,I=Number.parseFloat(n),l=Number.parseFloat(o),B=Number.parseFloat(s),C=B,Q=B*(1.5/1.05);let h=[];if(i.num_pins===3)g?h=[fm({pn:1,x:-I,y:c-I,holeDiameter:l,rectPadWidth:B,rectPadHeight:Q}),aM(2,0,c-I,l,C,Q),aM(3,I,c-I,l,C,Q)]:h=[fm({pn:1,x:-I,y:c-I,holeDiameter:l,rectPadWidth:B,rectPadHeight:B}),Fo(2,0,c,l,B),Fo(3,I,c-I,l,B)];else if(i.num_pins===2)h=[fm({pn:1,x:-I,y:c-I,holeDiameter:l,rectPadWidth:C,rectPadHeight:Q}),aM(2,I,c-I,l,C,Q)];else throw new Error("Invalid number of pins for TO-92");const E=Number.parseFloat(r)/2,u=ORt(0,c,E),d={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[...u,{x:-E,y:0},{x:E,y:0},u[0]],stroke_width:.1,pcb_silkscreen_path_id:""},f=Ui(0,c+1,.5);return{circuitJson:[...h,d,f],parameters:i}},ZRt=Ri.extend({fn:U(),num_pins:xA(2).default(2),w:U().default("2.15mm"),h:U().default("1.20mm"),pl:U().default("0.5mm"),pw:U().default("0.6mm"),p:U().default("1.4mm")}),VRt=t=>{const A=ZRt.parse(t),e=Ui(0,IA.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:IA.parse(A.p)/2,y:IA.parse(A.h)/2},{x:-IA.parse(A.w)/2-.2,y:IA.parse(A.h)/2},{x:-IA.parse(A.w)/2-.2,y:-IA.parse(A.h)/2},{x:IA.parse(A.p)/2,y:-IA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:zRt(A).concat(i,e),parameters:A}},jRt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},zRt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:n}=jRt({pn:e,p:Number.parseFloat(t.p)});A.push(li(e,i,n,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},XRt=oM({w:"7.05mm",p:"1.27mm",pw:"0.65mm",pl:"1.975mm"}),$Rt=t=>{const A=XRt.parse(t),e=[];for(let s=0;s<A.num_pins;s++){const{x:r,y:a}=spA({num_pins:A.num_pins,pn:s+1,w:A.w,p:A.p??1.27,pl:A.pl,widthincludeslegs:!0});e.push(li(s+1,r,a,A.pl??"1.5mm",A.pw??"0.6mm"))}const i=(A.num_pins/2-1)*A.p+A.pw,n=Ui(0,i/2+1,i/12),o={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"",type:"pcb_silkscreen_path",route:[{x:-A.w/3,y:i/2+.4},{x:A.w/3,y:i/2+.4}],stroke_width:.1};return{circuitJson:[...e,n,o],parameters:A}},ANt=Ri.extend({fn:U(),num_pins:xA(2).default(2),w:U().default("5.0mm"),h:U().default("2.30mm"),pl:U().default("1.25mm"),pw:U().default("2mm"),p:U().default("3.75mm")}),eNt=t=>{const A=ANt.parse(t),e=Ui(0,IA.parse(A.h)/2+1,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:IA.parse(A.p)/2+.5,y:IA.parse(A.h)/2+.5},{x:-IA.parse(A.w)/2-.5,y:IA.parse(A.h)/2+.5},{x:-IA.parse(A.w)/2-.5,y:-IA.parse(A.h)/2-.5},{x:IA.parse(A.p)/2+.5,y:-IA.parse(A.h)/2-.5}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:iNt(A).concat(i,e),parameters:A}},tNt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},iNt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:n}=tNt({pn:e,p:Number.parseFloat(t.p)});A.push(li(e,i,n,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},nNt=Ri.extend({fn:U(),num_pins:xA(2).default(2),w:U().default("4.4mm"),h:U().default("2.1mm"),pl:U().default("1.2mm"),pw:U().default("1.2mm"),p:U().default("2.9mm")}),oNt=t=>{const A=nNt.parse(t),e=Ui(0,IA.parse(A.h)-.5,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:IA.parse(A.p)/2,y:IA.parse(A.h)/2},{x:-IA.parse(A.w)/2-.2,y:IA.parse(A.h)/2},{x:-IA.parse(A.w)/2-.2,y:-IA.parse(A.h)/2},{x:IA.parse(A.p)/2,y:-IA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:rNt(A).concat(i,e),parameters:A}},sNt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},rNt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:n}=sNt({pn:e,p:Number.parseFloat(t.p)});A.push(li(e,i,n,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},aNt=Ri.extend({fn:U(),num_pins:xA(2).default(2),w:U().default("3.30mm"),h:U().default("1.80mm"),pl:U().default("0.60mm"),pw:U().default("0.45mm"),p:U().default("2.1mm")}),gNt=t=>{const A=aNt.parse(t),e=Ui(0,IA.parse(A.h)-.5,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:IA.parse(A.p)/2,y:IA.parse(A.h)/2},{x:-IA.parse(A.w)/2,y:IA.parse(A.h)/2},{x:-IA.parse(A.w)/2,y:-IA.parse(A.h)/2},{x:IA.parse(A.p)/2,y:-IA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:INt(A).concat(i,e),parameters:A}},cNt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},INt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:n}=cNt({pn:e,p:Number.parseFloat(t.p)});A.push(li(e,i,n,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},lNt=Ri.extend({fn:U(),num_pins:xA(2).default(2),w:U().default("1.4mm"),h:U().default("0.9mm"),pl:U().default("0.36mm"),pw:U().default("0.25mm"),p:U().default("0.85mm")}),BNt=t=>{const A=lNt.parse(t),e=Ui(0,IA.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:IA.parse(A.p)/2+.15,y:IA.parse(A.h)/2},{x:-IA.parse(A.w)/2-.15,y:IA.parse(A.h)/2},{x:-IA.parse(A.w)/2-.15,y:-IA.parse(A.h)/2},{x:IA.parse(A.p)/2+.15,y:-IA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:QNt(A).concat(i,e),parameters:A}},CNt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},QNt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:n}=CNt({pn:e,p:Number.parseFloat(t.p)});A.push(li(e,i,n,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},hNt=Ri.extend({fn:U(),num_pins:xA(2).default(2),w:U().default("1.3mm"),h:U().default("0.9mm"),pl:U().default("0.4mm"),pw:U().default("0.7mm"),p:U().default("0.7mm")}),ENt=t=>{const A=hNt.parse(t),e=Ui(0,IA.parse(A.h)+.1,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:IA.parse(A.p)/2+.2,y:IA.parse(A.h)/2+.2},{x:-IA.parse(A.w)/2-.2,y:IA.parse(A.h)/2+.2},{x:-IA.parse(A.w)/2-.2,y:-IA.parse(A.h)/2-.2},{x:IA.parse(A.p)/2+.2,y:-IA.parse(A.h)/2-.2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:dNt(A).concat(i,e),parameters:A}},uNt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},dNt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:n}=uNt({pn:e,p:Number.parseFloat(t.p)});A.push(li(e,i,n,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},pNt=Ri.extend({fn:U(),num_pins:xA(2).default(2),w:U().default("3,05mm"),h:U().default("1.65mm"),pl:U().default("0.6mm"),pw:U().default("0.6mm"),pad_spacing:U().default("2.2mm")}),fNt=t=>{const A=pNt.parse(t),e=Ui(0,IA.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:IA.parse(A.pad_spacing)/2,y:IA.parse(A.h)/2},{x:-IA.parse(A.w)/2-.2,y:IA.parse(A.h)/2},{x:-IA.parse(A.w)/2-.2,y:-IA.parse(A.h)/2},{x:IA.parse(A.pad_spacing)/2,y:-IA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:mNt(A).concat(i,e),parameters:A}},yNt=t=>{const{pn:A,pad_spacing:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},mNt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:n}=yNt({pn:e,pad_spacing:Number.parseFloat(t.pad_spacing)});A.push(li(e,i,n,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},wNt=Ri.extend({fn:U(),num_pins:xA(2).default(2),w:U().default("4.4mm"),h:U().default("2.1mm"),pl:U().default("1.10mm"),pw:U().default("1.10mm"),p:U().default("2.8mm")}),DNt=t=>{const A=wNt.parse(t),e=Ui(0,IA.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:IA.parse(A.p)/2,y:IA.parse(A.h)/2},{x:-IA.parse(A.w)/2-.2,y:IA.parse(A.h)/2},{x:-IA.parse(A.w)/2-.2,y:-IA.parse(A.h)/2},{x:IA.parse(A.p)/2,y:-IA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:bNt(A).concat(i,e),parameters:A}},SNt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},bNt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:n}=SNt({pn:e,p:Number.parseFloat(t.p)});A.push(li(e,i,n,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},xNt=Ri.extend({fn:U(),num_pins:xA(2).default(2),w:U().default("4.4mm"),h:U().default("2.1mm"),pl:U().default("0.91mm"),pw:U().default("1.22mm"),p:U().default("3.146mm")}),_Nt=t=>{const A=xNt.parse(t),e=Ui(0,IA.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:IA.parse(A.p)/2,y:IA.parse(A.h)/2},{x:-IA.parse(A.w)/2-.2,y:IA.parse(A.h)/2},{x:-IA.parse(A.w)/2-.2,y:-IA.parse(A.h)/2},{x:IA.parse(A.p)/2,y:-IA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:vNt(A).concat(i,e),parameters:A}},kNt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},vNt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:n}=kNt({pn:e,p:Number.parseFloat(t.p)});A.push(li(e,i,n,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},FNt=Ri.extend({fn:U(),num_pins:xA(2).default(2),w:U().default("1.80mm"),h:U().default("1.00mm"),pl:U().default("0.66mm"),pw:U().default("0.5mm"),p:U().default("0.8mm")}),MNt=t=>{const A=FNt.parse(t),e=Ui(0,IA.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:IA.parse(A.p)/2,y:IA.parse(A.h)/2},{x:-IA.parse(A.w)/2-.1,y:IA.parse(A.h)/2},{x:-IA.parse(A.w)/2-.1,y:-IA.parse(A.h)/2},{x:IA.parse(A.p)/2,y:-IA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:NNt(A).concat(i,e),parameters:A}},RNt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},NNt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:n}=RNt({pn:e,p:Number.parseFloat(t.p)});A.push(li(e,i,n,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},GNt=Ri.extend({fn:U(),num_pins:xA(2).default(2),w:U().default("6.2mm"),h:U().default("3.4mm"),pl:U().default("1.4mm"),pw:U().default("2.1mm"),p:U().default("4.4mm")}),LNt=t=>{const A=GNt.parse(t),e=Ui(0,IA.parse(A.h)/2+.4,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:IA.parse(A.p)/2,y:IA.parse(A.h)/2},{x:-IA.parse(A.w)/2-.2,y:IA.parse(A.h)/2},{x:-IA.parse(A.w)/2-.2,y:-IA.parse(A.h)/2},{x:IA.parse(A.p)/2,y:-IA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:HNt(A).concat(i,e),parameters:A}},UNt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},HNt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:n}=UNt({pn:e,p:Number.parseFloat(t.p)});A.push(li(e,i,n,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},YNt=Ri.extend({fn:U(),num_pins:Rt([xA(3),xA(5)]).default(3),w:U().default("4.20mm"),h:U().default("4.80mm"),pl:U().default("1.3mm"),pw:U().default("0.9mm"),p:U().default("1.5mm"),string:U().optional()}),JNt=t=>{const A=[],e=Number.parseFloat(t.p),i=Number.parseFloat(t.pw),n=Number.parseFloat(t.w),o=Number.parseFloat(t.pl),s=.175,r=(o-(o+s))/2;A.push(li(1,-n/2+r,e,o,i),li(2,-n/2,0,o+s,i),li(3,-n/2+r,-e,o,i));const a=Ui(0,0,.3),g=Number.parseFloat(t.w)/2-1,c=Number.parseFloat(t.h)/2,I={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-g,y:c},{x:g,y:c},{x:g,y:c/2+.5}],type:"pcb_silkscreen_path",stroke_width:.1},l={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_2",route:[{x:-g,y:-c},{x:g,y:-c},{x:g,y:-c/2-.5}],type:"pcb_silkscreen_path",stroke_width:.1};return[...A,I,l,a]},TNt=t=>{const A=[];Number.parseFloat(t.p),Number.parseFloat(t.pw),Number.parseFloat(t.w),A.push(li(1,-1.85,-1.5,1.5,.7),li(2,-1.85,1.5,1.5,.7),li(3,0,0,.8,2),li(4,1.85,-1.5,1.5,.7),li(5,1.85,1.5,1.5,.7));const e=Ui(0,Number.parseFloat(t.h)/2+.5,.3),i=Number.parseFloat(t.w)/2-1,n=Number.parseFloat(t.h)/2,o={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-i,y:n},{x:i,y:n}],type:"pcb_silkscreen_path",stroke_width:.1},s={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_2",route:[{x:-i,y:-n},{x:i,y:-n}],type:"pcb_silkscreen_path",stroke_width:.1};return[...A,o,s,e]},PNt=t=>{const A=t.string?.match(/^sot89_(\d+)/),e=A?Number.parseInt(A[1],10):3,i=YNt.parse({...t,num_pins:e});if(i.num_pins===3)return{circuitJson:JNt(i),parameters:i};if(i.num_pins===5)return{circuitJson:TNt(i),parameters:i};throw new Error("Invalid number of pins for SOT89")},KNt=Ri.extend({fn:U(),p:IA.optional().default("5.0mm"),id:IA.optional().default("1.0mm"),od:IA.optional().default("1.9mm"),w:IA.optional().default("13mm"),h:IA.optional().default("7mm"),num_pins:OA().optional(),string:U().optional()}),Kie=t=>{const A=KNt.parse(t),{id:e,od:i,w:n,h:o,string:s}=A,r=A.num_pins??Number.parseInt(s?.match(/^to220(?:_|-)(\d+)/i)?.[1]??"3"),a=-1,g=n/2,c=o/2,I=2.5,l=n*.4,B=Math.max(I,l/(r-1)),C=Array.from({length:r},(f,y)=>{const w=r%2===0?(y-r/2+.5)*B:(y-Math.floor(r/2))*B;return Fo(y+1,w,a,e,i)}),Q={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-g,y:-c},{x:g,y:-c},{x:g,y:c},{x:-g,y:c},{x:-g,y:-c}],stroke_width:.1,pcb_silkscreen_path_id:""},h=-c+2*o/3,E={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-g,y:h},{x:g,y:h}],stroke_width:.1,pcb_silkscreen_path_id:""},u=[{type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-n/6,y:h},{x:-n/6,y:c}],stroke_width:.1,pcb_silkscreen_path_id:""},{type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:n/6,y:h},{x:n/6,y:c}],stroke_width:.1,pcb_silkscreen_path_id:""}],d=Ui(0,o/2+.6,.5);return{circuitJson:[...C,Q,E,...u,d],parameters:{...A,p:B}}},gpA=2.54,qNt=Ri.extend({fn:U(),id:IA.optional().default("1.2mm"),od:IA.optional().default("1.905mm"),ph:IA.optional().default("2mm"),w:IA.optional().default("13mm"),h:IA.optional().default("7mm"),num_pins:OA().optional(),string:U().optional()}),ONt=t=>{const A=qNt.parse(t),e=A.num_pins??Number.parseInt(A.string?.match(/^to220f(?:_|-)(\d+)/i)?.[1]??"3"),i=Kie({...A,fn:"to220",string:A.string?.replace(/^to220f/i,"to220"),num_pins:e}),n=-1,o=Array.from({length:e},(r,a)=>{const g=e%2===0?(a-e/2+.5)*gpA:(a-Math.floor(e/2))*gpA;return a===0?fm({pn:1,x:g,y:n,holeDiameter:A.id,rectPadWidth:A.od,rectPadHeight:A.ph}):aM(a+1,g,n,cr(A.id),cr(A.od),cr(A.ph))}),s=i.circuitJson.filter(r=>r.type!=="pcb_plated_hole");return{circuitJson:[...o,...s],parameters:{...A,p:gpA,num_pins:e}}},WNt=Ri.extend({fn:U(),num_pins:xA(2).default(2),w:U().default("5.40mm"),h:U().default("2.30mm"),pl:U().default("1.30mm"),pw:U().default("1.70mm"),p:U().default("3.5mm")}),ZNt=t=>{const A=WNt.parse(t),e=Ui(0,IA.parse(A.h)/2+.4,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:IA.parse(A.p)/2,y:IA.parse(A.h)/2},{x:-IA.parse(A.w)/2,y:IA.parse(A.h)/2},{x:-IA.parse(A.w)/2,y:-IA.parse(A.h)/2},{x:IA.parse(A.p)/2,y:-IA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:jNt(A).concat(i,e),parameters:A}},VNt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},jNt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:n}=VNt({pn:e,p:Number.parseFloat(t.p)});A.push(li(e,i,n,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},zNt=Ri.extend({fn:U(),num_pins:xA(2).default(2),w:U().default("1.90mm"),h:U().default("1.33mm"),pl:U().default("0.5mm"),pw:U().default("0.7mm"),p:U().default("0.8mm")}),XNt=t=>{const A=zNt.parse(t),e=Ui(0,IA.parse(A.h)+.1,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:IA.parse(A.p)/2+.1,y:IA.parse(A.h)/2},{x:-IA.parse(A.w)/2,y:IA.parse(A.h)/2},{x:-IA.parse(A.w)/2,y:-IA.parse(A.h)/2},{x:IA.parse(A.p)/2+.1,y:-IA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:AGt(A).concat(i,e),parameters:A}},$Nt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},AGt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:n}=$Nt({pn:e,p:Number.parseFloat(t.p)});A.push(li(e,i,n,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},eGt=Ri.extend({fn:U(),num_pins:xA(2).default(2),w:U().default("7.0mm"),h:U().default("3.35mm"),pl:U().default("1.50mm"),pw:U().default("2.70mm"),p:U().default("4.8mm")}),tGt=t=>{const A=eGt.parse(t),e=Ui(0,IA.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:IA.parse(A.p)/2,y:IA.parse(A.h)/2},{x:-IA.parse(A.w)/2,y:IA.parse(A.h)/2},{x:-IA.parse(A.w)/2,y:-IA.parse(A.h)/2},{x:IA.parse(A.p)/2,y:-IA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:nGt(A).concat(i,e),parameters:A}},iGt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},nGt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:n}=iGt({pn:e,p:Number.parseFloat(t.p)});A.push(li(e,i,n,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},oGt=Ri.extend({fn:U(),num_pins:xA(2).default(2),w:U().default("3.0mm"),h:U().default("1.80mm"),pl:U().default("0.80mm"),pw:U().default("1.20mm"),p:U().default("1.6mm")}),sGt=t=>{const A=oGt.parse(t),e=Ui(0,IA.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:IA.parse(A.p)/2,y:IA.parse(A.h)/2},{x:-IA.parse(A.w)/2-.1,y:IA.parse(A.h)/2},{x:-IA.parse(A.w)/2-.1,y:-IA.parse(A.h)/2},{x:IA.parse(A.p)/2,y:-IA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:aGt(A).concat(i,e),parameters:A}},rGt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},aGt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:n}=rGt({pn:e,p:Number.parseFloat(t.p)});A.push(li(e,i,n,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},gGt=Ri.extend({fn:U(),num_pins:xA(2).default(2),w:U().default("7.10mm"),h:U().default("3.40mm"),pl:U().default("2.45mm"),pw:U().default("1.80mm"),p:U().default("4.05mm")}),cGt=t=>{const A=gGt.parse(t),e=Ui(0,IA.parse(A.h)/2+.5,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:IA.parse(A.p)/2,y:IA.parse(A.h)/2},{x:-IA.parse(A.w)/2-.5,y:IA.parse(A.h)/2},{x:-IA.parse(A.w)/2-.5,y:-IA.parse(A.h)/2},{x:IA.parse(A.p)/2,y:-IA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:lGt(A).concat(i,e),parameters:A}},IGt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},lGt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:n}=IGt({pn:e,p:Number.parseFloat(t.p)});A.push(li(e,i,n,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},BGt=Ri.extend({fn:U(),num_pins:xA(2).default(2),w:U().default("4.80mm"),h:U().default("2.10mm"),pl:U().default("1.30mm"),pw:U().default("1.40mm"),p:U().default("2.9mm")}),CGt=t=>{const A=BGt.parse(t),e=Ui(0,IA.parse(A.h)-.5,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:IA.parse(A.p)/2,y:IA.parse(A.h)/2},{x:-IA.parse(A.w)/2,y:IA.parse(A.h)/2},{x:-IA.parse(A.w)/2,y:-IA.parse(A.h)/2},{x:IA.parse(A.p)/2,y:-IA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:hGt(A).concat(i,e),parameters:A}},QGt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},hGt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:n}=QGt({pn:e,p:Number.parseFloat(t.p)});A.push(li(e,i,n,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},EGt=Ri.extend({fn:U(),num_pins:xA(2).default(2),w:U().default("7.30mm"),h:U().default("4.40mm"),pl:U().default("2.50mm"),pw:U().default("2.30mm"),p:U().default("4.30mm")}),uGt=t=>{const A=EGt.parse(t),e=Ui(0,IA.parse(A.h)/2+.5,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:IA.parse(A.p)/2,y:IA.parse(A.h)/2},{x:-IA.parse(A.w)/2-.1,y:IA.parse(A.h)/2},{x:-IA.parse(A.w)/2-.1,y:-IA.parse(A.h)/2},{x:IA.parse(A.p)/2,y:-IA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:pGt(A).concat(i,e),parameters:A}},dGt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},pGt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:n}=dGt({pn:e,p:Number.parseFloat(t.p)});A.push(li(e,i,n,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},fGt=Ri.extend({fn:U(),num_pins:xA(2).default(2),w:U().default("10.70mm"),h:U().default("6.60mm"),pl:U().default("3.30mm"),pw:U().default("2.50mm"),p:U().default("6.80mm")}),yGt=t=>{const A=fGt.parse(t),e=Ui(0,3,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:IA.parse(A.p)/2,y:IA.parse(A.h)/2-.8},{x:-IA.parse(A.w)/2-.8,y:IA.parse(A.h)/2-.8},{x:-IA.parse(A.w)/2-.8,y:-IA.parse(A.h)/2+.8},{x:IA.parse(A.p)/2,y:-IA.parse(A.h)/2+.8}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:wGt(A).concat(i,e),parameters:A}},mGt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},wGt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:n}=mGt({pn:e,p:Number.parseFloat(t.p)});A.push(li(e,i,n,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},DGt=Ri.extend({fn:U(),num_pins:OA().default(4),w:U().default("8.50mm"),h:U().default("6.90mm"),pl:U().default("2mm"),pw:U().default("1.5mm"),p:U().default("2.30mm"),string:U().optional()}),SGt=t=>{const A=t.string?.match(/^sot223_(\d+)/),e=A?Number.parseInt(A[1],10):4;if(e===8){const n=_Gt.parse({...t,num_pins:e});return{circuitJson:lJ(n),parameters:n}}const i=DGt.parse({...t,num_pins:e});if(i.num_pins===4)return{circuitJson:xGt(i),parameters:i};if(i.num_pins===5)return{circuitJson:vGt(i),parameters:i};if(i.num_pins===6)return{circuitJson:MGt(i),parameters:i};throw new Error("Invalid number of pins")},bGt=t=>{const{pn:A,w:e,p:i}=t;return A===1?{x:-e/2+1.1,y:i}:A===2?{x:-e/2+1.1,y:0}:A===3?{x:-e/2+1.1,y:-i}:{x:e/2-1.1,y:0}},xGt=t=>{const A=[];for(let r=0;r<t.num_pins;r++){const{x:a,y:g}=bGt({num_pins:t.num_pins,pn:r+1,w:Number.parseFloat(t.w),h:Number.parseFloat(t.h),pl:Number.parseFloat(t.pl),p:Number.parseFloat(t.p)}),c=r===3?3.8:Number.parseFloat(t.pw);A.push(li(r+1,a,g,Number.parseFloat(t.pl),c))}const e=Ui(0,0,.3),i=Number.parseFloat(t.w)/2-2.4,n=Number.parseFloat(t.h)/2,o={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-i,y:n},{x:i,y:n},{x:i,y:n/2+.5}],type:"pcb_silkscreen_path",stroke_width:.1},s={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_2",route:[{x:-i,y:-n},{x:i,y:-n},{x:i,y:-n/2-.5}],type:"pcb_silkscreen_path",stroke_width:.1};return[...A,o,s,e]},_Gt=oM({p:"0.90mm",w:"2.8mm",legsoutside:!0}),kGt=t=>{const{p:A,pn:e,w:i}=t;if(e===1)return{x:-i/2+1.2,y:A/2+A};if(e===2)return{x:-i/2+1.2,y:A/2};if(e===3)return{x:-i/2+1.2,y:-A/2};if(e===4)return{x:-i/2+1.2,y:-A/2-A};if(e===5)return{x:i/2-1,y:0};throw new Error("Invalid pin number")},vGt=t=>{const A=[];for(let r=1;r<=t.num_pins;r++){const{x:a,y:g}=kGt({h:Number.parseFloat(t.h),p:1.5,pn:r,w:Number.parseFloat(t.w)});let c=Number.parseFloat(t.pw),I=Number.parseFloat(t.pl);r===5?(c=3.4,I=1.8):(c=1,I=2.2),A.push(li(r,a,g,I,c))}const e=Number.parseFloat(t.w)/2-2.4,i=Number.parseFloat(t.h)/2,n={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-e,y:i},{x:e,y:i},{x:e,y:i/2+.5}],type:"pcb_silkscreen_path",stroke_width:.1},o={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_2",route:[{x:-e,y:-i},{x:e,y:-i},{x:e,y:-i/2-.5}],type:"pcb_silkscreen_path",stroke_width:.1},s=Ui(0,0,.3);return[...A,n,o,s]},FGt=t=>{const{p:A,pn:e,w:i}=t;if(e===1)return{x:-i/2+1.2,y:2*A};if(e===2)return{x:-i/2+1.2,y:A};if(e===3)return{x:-i/2+1.2,y:0};if(e===4)return{x:-i/2+1.2,y:-A};if(e===5)return{x:-i/2+1.2,y:-2*A};if(e===6)return{x:i/2-1.175,y:0};throw new Error("Invalid pin number")},MGt=t=>{const A=[];for(let r=1;r<=t.num_pins;r++){const{x:a,y:g}=FGt({h:Number.parseFloat(t.h),p:1.3,pn:r,w:8.7});let c=Number.parseFloat(t.pw),I=Number.parseFloat(t.pl);r===6?(c=3.4,I=2.15):(c=.6,I=2.2),A.push(li(r,a,g,I,c))}const e=Number.parseFloat(t.w)/2-2.4,i=Number.parseFloat(t.h)/2,n={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-e,y:i},{x:e,y:i},{x:e,y:i/2+.5}],type:"pcb_silkscreen_path",stroke_width:.1},o={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_2",route:[{x:-e,y:-i},{x:e,y:-i},{x:e,y:-i/2-.5}],type:"pcb_silkscreen_path",stroke_width:.1},s=Ui(0,0,.3);return[...A,n,o,s]},RGt=Ri.extend({fn:U(),num_pins:OA().default(3),w:U().default("3.40mm"),h:U().default("3.30mm"),pl:U().default("1mm"),pw:U().default("0.7mm"),p:U().default("1.2mm"),string:U().optional()}),NGt=t=>{const A=t.string?.match(/^sot23w_(\d+)/),e=A?Number.parseInt(A[1],3):3,i=RGt.parse({...t,num_pins:e});if(i.num_pins===3)return{circuitJson:LGt(i),parameters:i};throw new Error("Invalid number of pins")},GGt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e,y:.95}:A===2?{x:-e,y:-.95}:{x:e,y:0}},LGt=t=>{const A=[];for(let r=0;r<t.num_pins;r++){const{x:a,y:g}=GGt({num_pins:t.num_pins,pn:r+1,w:Number.parseFloat(t.w),h:Number.parseFloat(t.h),pl:Number.parseFloat(t.pl),p:Number.parseFloat(t.p)});A.push(li(r+1,a,g,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}const e=Ui(0,Number.parseInt(t.h)/2+1,.3),i=Number.parseFloat(t.w)/2-1,n=Number.parseFloat(t.h)/2,o={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-i,y:n},{x:i+.3,y:n},{x:i+.3,y:n/2}],type:"pcb_silkscreen_path",stroke_width:.1},s={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_2",route:[{x:-i,y:-n},{x:i+.3,y:-n},{x:i+.3,y:-n/2}],type:"pcb_silkscreen_path",stroke_width:.1};return[...A,o,s,e]},UGt=Ri.extend({fn:U(),num_pins:Rt([xA(3),xA(2)]).default(3),p:U().default("1.27mm"),id:U().default("0.72mm"),od:U().default("0.95mm"),w:U().default("2.5mm"),h:U().default("4.2mm"),string:U().optional()}),HGt=t=>{const{p:A,id:e,od:i,w:n,h:o}=t,s=Number.parseFloat(o)/2,r=Number.parseFloat(A);return[Fo(1,-r,s-r,e,i),Fo(2,0,s-r,e,i),Fo(3,r,s-r,e,i)]},YGt=t=>{const{p:A,id:e,od:i,h:n}=t,o=Number.parseFloat(n)/2,s=Number.parseFloat(A);return[Fo(1,-s,o-s,e,i),Fo(2,s,o-s,e,i)]},JGt=t=>{const A=t.string?.match(/^to92s_(\d+)/),e=A?Number.parseInt(A[1],10):3,i=UGt.parse({...t,num_pins:e});let n=[];if(i.num_pins===3)n=HGt(i);else if(i.num_pins===2)n=YGt(i);else throw new Error("Invalid number of pins for TO-92");const o=Number.parseFloat(i.h)/2,s=Number.parseFloat(i.p),r={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-o,y:o-s},{x:-1.9,y:0},{x:1.9,y:0},{x:o,y:o-s},{x:1.5,y:Number.parseFloat(i.h)/2+.5},{x:-1.5,y:Number.parseFloat(i.h)/2+.5},{x:-o,y:o-s}],stroke_width:.1,pcb_silkscreen_path_id:""},a=Ui(0,o+1,.5);return{circuitJson:[...n,r,a],parameters:i}},TGt=Ri.extend({fn:U(),p:IA.optional(),id:IA.optional(),pw:IA.optional(),pl:IA.optional(),w:IA.optional(),h:IA.optional(),sh:PA().optional().describe('JST SH (Surface-mount) connector family. SH stands for "Super High-density".'),ph:PA().optional().describe('JST PH (Through-hole) connector family. PH stands for "Pin Header".'),zh:PA().optional().describe("JST ZH (Through-hole) connector family. 1.5mm pitch wire-to-board."),string:U().optional()}),PGt={ph:{p:IA.parse("2.2mm"),id:IA.parse("0.70mm"),pw:IA.parse("1.20mm"),pl:IA.parse("1.20mm"),w:IA.parse("6mm"),h:IA.parse("5mm")},sh:{p:IA.parse("1mm"),pw:IA.parse("0.6mm"),pl:IA.parse("1.55mm"),w:IA.parse("5.8mm"),h:IA.parse("7.8mm")},zh:{p:IA.parse("1.5mm"),id:IA.parse("0.73mm"),pw:IA.parse("1.03mm"),pl:IA.parse("1.73mm"),w:IA.parse("3mm"),h:IA.parse("3.5mm")}};function KGt(t){return t.sh?"sh":t.ph?"ph":t.zh?"zh":"ph"}function qGt(t,A,e,i,n,o){const s=[];if(t==="ph"){const r=-((A-1)/2)*e;for(let a=0;a<A;a++){const g=r+a*e;s.push(fm({pn:a+1,x:g,y:2,holeDiameter:i,rectPadWidth:n,rectPadHeight:o}))}}else if(t==="zh"){const r=-((A-1)/2)*e;for(let a=0;a<A;a++){const g=r+a*e;a===0?s.push(fm({pn:a+1,x:g,y:0,holeDiameter:i,rectPadWidth:n,rectPadHeight:o,rectBorderRadius:.12499977})):s.push(aM(a+1,g,0,i,n,o))}}else{const r=-((A-1)/2)*e;for(let g=0;g<A;g++){const c=r+g*e;s.push(li(g+1,c,-1.325,n,o))}const a=(A-1)/2*e+1.3;s.push(li(A+1,-a,1.22,1.2,1.8)),s.push(li(A+2,a,1.22,1.2,1.8))}return s}function OGt(t,A,e,i,n){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"&&i&&n){const o=(i-1)*n,s=-o/2-1.5,r=o/2+1.5,a=-e/2,g=e/2;return{type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:s,y:a},{x:r,y:a},{x:r,y:g},{x:s,y:g},{x:s,y:a}],stroke_width:.1,pcb_silkscreen_path_id:""}}else return{type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[],stroke_width:.1,pcb_silkscreen_path_id:""}}var WGt=t=>{const A=TGt.parse(t),e=KGt(A),i=PGt[e],n=A.p??i.p,o=A.id??i.id,s=A.pw??i.pw,r=A.pl??i.pl,a=A.w??i.w,g=A.h??i.h;let c;const I=t.num_pins;typeof I=="number"&&(c=I);const l=typeof t.string=="string"?t.string:"",B=l.match(/(?:^|_)jst(\d+)(?:_|$)/),C=l.match(/(?:^|_)zh(\d+)(?:_|$)/);if(B&&B[1]){const u=Number.parseInt(B[1],10);Number.isNaN(u)||(c=u)}if(C&&C[1]){const u=Number.parseInt(C[1],10);Number.isNaN(u)||(c=u)}if(typeof c!="number")throw new Error(`JST requires an explicit pin count (e.g. jst6_sh or .jst(6))${A.string?`, from string "${A.string}"`:""}`);const Q=qGt(e,c,n,o,s,r),h=OGt(e,a,g,c,n),E=Ui(0,g/2+1,.5);return{circuitJson:[...Q,h,E],parameters:{...A,p:n,id:o,pw:s,pl:r,w:a,h:g,num_pins:c,sh:e==="sh",ph:e==="ph",zh:e==="zh"}}},ZGt=Ri.extend({fn:U(),num_pins:xA(2).default(2),w:U().default("3.30mm"),h:U().default("1.70mm"),pl:U().default("0.80mm"),pw:U().default("1mm"),p:U().default("1.90mm")}),VGt=t=>{const A=ZGt.parse(t),e=Ui(0,IA.parse(A.h)/2+.5,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:IA.parse(A.p)/2,y:IA.parse(A.h)/2},{x:-IA.parse(A.w)/2,y:IA.parse(A.h)/2},{x:-IA.parse(A.w)/2,y:-IA.parse(A.h)/2},{x:IA.parse(A.p)/2,y:-IA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:zGt(A).concat(i,e),parameters:A}},jGt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},zGt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:n}=jGt({pn:e,p:Number.parseFloat(t.p)});A.push(li(e,i,n,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},XGt=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"}}},$Gt=Ri.extend({fn:U(),num_pins:Rt([xA(8),xA(10)]).default(8),w:U().optional(),h:U().optional(),p:U().optional(),pl:U().optional(),pw:U().optional(),string:U().optional()}),A1t=t=>{const A=$Gt.parse(t),e=XGt(A.num_pins),i=IA.parse(A.w||e.w),n=IA.parse(A.h||e.h),o=IA.parse(A.p||e.p),s=IA.parse(A.pl||e.pl),r=IA.parse(A.pw||e.pw),a=[],g=A.num_pins/2;for(let u=0;u<A.num_pins;u++){const{x:d,y:f}=qie(A.num_pins,u+1,i,o),y=u<g?u+1:A.num_pins-(u-g);a.push(li(y,d,f,s,r))}const c=i,I=n,l={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-c/2,y:I/2},{x:c/2,y:I/2}],stroke_width:.05,pcb_silkscreen_path_id:""},B={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-c/2,y:-I/2},{x:c/2,y:-I/2}],stroke_width:.05,pcb_silkscreen_path_id:""},C=qie(A.num_pins,1,c,o),Q={x:C.x-.8,y:C.y},h={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"pin_marker_1",route:[{x:Q.x-.4,y:Q.y},{x:Q.x-.7,y:Q.y+.3},{x:Q.x-.7,y:Q.y-.3},{x:Q.x-.4,y:Q.y}],stroke_width:.05,pcb_silkscreen_path_id:"pin_marker_1"},E=Ui(0,I/2+.5,.3);return{circuitJson:[...a,l,B,E,h],parameters:A}},qie=(t,A,e,i)=>{const n=t/2,o=(A-1)%n,s=A<=n?-1:1,r=(n-1)/2-o;return{x:s*IA.parse(t===8?"1.8mm":"2.2mm"),y:r*i}},e1t=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"}}},t1t=Ri.extend({fn:U(),num_pins:Rt([xA(8),xA(10),xA(12),xA(16)]).default(8),w:U().optional(),h:U().optional(),p:U().optional(),pl:U().optional(),pw:U().optional(),string:U().optional()}),Oie=(t,A,e,i)=>{const n=t/2,o=(A-1)%n,s=A<=n?-1:1,r=(n-1)/2-o;return{x:s*IA.parse("2mm"),y:r*i}},i1t=t=>{const A=t1t.parse(t),e=e1t(A.num_pins),i=IA.parse(A.w||e.w),n=IA.parse(A.h||e.h),o=IA.parse(A.p||e.p),s=IA.parse(A.pl||e.pl),r=IA.parse(A.pw||e.pw),a=[];for(let E=0;E<A.num_pins;E++){const{x:u,y:d}=Oie(A.num_pins,E+1,i,o);a.push(li(E+1,u,d,s,r))}const g=i,c=n,I={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-g/2,y:c/2},{x:g/2,y:c/2}],stroke_width:.05,pcb_silkscreen_path_id:""},l={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-g/2,y:-c/2},{x:g/2,y:-c/2}],stroke_width:.05,pcb_silkscreen_path_id:""},B=Oie(A.num_pins,1,g,o),C={x:B.x-.8,y:B.y},Q={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"pin_marker_1",route:[{x:C.x-.4,y:C.y},{x:C.x-.7,y:C.y+.3},{x:C.x-.7,y:C.y-.3},{x:C.x-.4,y:C.y}],stroke_width:.05,pcb_silkscreen_path_id:"pin_marker_1"},h=Ui(0,c/2+.5,.3);return{circuitJson:[...a,I,l,h,Q],parameters:A}},n1t=Ri.extend({fn:U(),num_pins:xA(2).default(2),w:U().default("3.8mm"),h:U().default("1.65mm"),pl:U().default("1.2mm"),pw:U().default("1.2mm"),pad_spacing:U().default("2.6mm")}),o1t=t=>{const A=n1t.parse(t),e=Ui(0,IA.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:IA.parse(A.pad_spacing)/2,y:IA.parse(A.h)/2},{x:-IA.parse(A.w)/2-.2,y:IA.parse(A.h)/2},{x:-IA.parse(A.w)/2-.2,y:-IA.parse(A.h)/2},{x:IA.parse(A.pad_spacing)/2,y:-IA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:r1t(A).concat(i,e),parameters:A}},s1t=t=>{const{pn:A,pad_spacing:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},r1t=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:n}=s1t({pn:e,pad_spacing:Number.parseFloat(t.pad_spacing)});A.push(li(e,i,n,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},a1t=Ri.extend({fn:U(),num_pins:xA(2).default(2),w:U().default("3.20mm"),h:U().default("1.65mm"),pl:U().default("0.8mm"),pw:U().default("0.9mm"),pad_spacing:U().default("2.1mm")}),g1t=t=>{const A=a1t.parse(t),e=Ui(0,IA.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:IA.parse(A.pad_spacing)/2,y:IA.parse(A.h)/2},{x:-IA.parse(A.w)/2-.2,y:IA.parse(A.h)/2},{x:-IA.parse(A.w)/2-.2,y:-IA.parse(A.h)/2},{x:IA.parse(A.pad_spacing)/2,y:-IA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:I1t(A).concat(i,e),parameters:A}},c1t=t=>{const{pn:A,pad_spacing:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},I1t=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:n}=c1t({pn:e,pad_spacing:Number.parseFloat(t.pad_spacing)});A.push(li(e,i,n,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},l1t=Ri.extend({fn:U(),num_pins:Rt([xA(6),xA(8)]).default(8),w:U().default("3mm"),h:U().default("3mm"),p:U().default("0.5mm"),pl:U().default("0.52mm"),pw:U().default("0.35mm"),epw:U().default("1.40mm"),eph:U().default("1.60mm"),string:U().optional(),ep:PA().default(!1)}),B1t=t=>{t.string&&t.string.includes("_ep")&&(t.ep=!0);const A=t.string?.match(/^son_(\d+)/),e=A?Number.parseInt(A[1],10):t.num_pins||8,i=l1t.parse({...t,num_pins:e}),n=IA.parse(i.w),o=IA.parse(i.h),s=IA.parse(i.p),r=IA.parse(i.pl),a=IA.parse(i.pw),g=IA.parse(i.epw),c=IA.parse(i.eph),I=[];for(let f=0;f<i.num_pins;f++){const{x:y,y:w}=Wie(i.num_pins,f+1,n,s);I.push(li(f+1,y,w,r,a))}i.ep&&I.push(li(i.num_pins+1,0,0,g,c));const l=n,B=o,C={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-l/2,y:B/2},{x:l/2,y:B/2}],stroke_width:.05,pcb_silkscreen_path_id:""},Q={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-l/2,y:-B/2},{x:l/2,y:-B/2}],stroke_width:.05,pcb_silkscreen_path_id:""},h=Wie(i.num_pins,1,l,s),E={x:h.x-.4,y:h.y},u={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"pin_marker_1",route:[{x:E.x-.4,y:E.y},{x:E.x-.7,y:E.y+.3},{x:E.x-.7,y:E.y-.3},{x:E.x-.4,y:E.y}],stroke_width:.05,pcb_silkscreen_path_id:"pin_marker_1"},d=Ui(0,B/2+.5,.3);return{circuitJson:[...I,C,Q,d,u],parameters:i}},Wie=(t,A,e,i)=>{const n=t/2,o=(A-1)%n,s=A<=n?-1:1,r=(n-1)/2-o;return{x:s*IA.parse("1.4mm"),y:r*i}},C1t=Ri.extend({fn:U(),num_pins:OA().optional().default(8),p:se.describe("pitch (distance between center of each pin)"),w:IA.describe("width between vertical rows of pins"),grid:ZV.describe("width and height of the border of the footprint"),ep:ZV.default("0x0mm").describe("width and height of the central exposed thermal pad"),epx:IA.default("0mm").describe("x offset of the center of the central exposed thermal pad"),pinw:IA.describe("width of the pin pads"),pinh:IA.describe("height of the pin pads")}),Q1t=t=>{const A=C1t.parse(t),{num_pins:e,p:i,w:n,grid:o,ep:s,epx:r,pinw:a,pinh:g}=A;if(e%2!==0)throw new Error("invalid number of pins");const c=[];for(let B=0;B<e;B++){const{pinX:C,pinY:Q}=h1t({pinCount:e,pinIndex:B,width:n,pitch:i});c.push(li(B+1,C,Q,a,g))}s.x>0&&s.y>0&&c.push(li(A.num_pins+1,r,0,s.x,s.y));const I=E1t(o),l=Ui(0,o.y/2+i,o.y/6);return{circuitJson:[...c,...I,l],parameters:A}},h1t=t=>{let A=0,e=0;const i=(t.pinCount/2-1)*t.pitch/2,n=t.pinCount/2;return t.pinIndex+1<=n?(A=t.pitch*t.pinIndex-i,e=0-t.width/2):(A=t.pitch*(t.pinCount-t.pinIndex-1)-i,e=t.width/2),{pinX:e,pinY:A}},E1t=t=>{const e=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-e},{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-e}],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+e},{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+e}],stroke_width:t.y/30}]},u1t=t=>{const{num_pins:A,bridged:e,p:i=2.54,pw:n=1.5,ph:o=1.5}=t,s=IA.parse(i),r=IA.parse(n),a=IA.parse(o),g=Math.min(a/4,.5),c=[];for(let f=0;f<A;f++)c.push(li(f+1,f*s,0,r,a));let I=[];if(e){const f=e.split("").map(Number);if(f.length>1)for(let y=0;y<f.length-1;y++){const w=f[y],D=f[y+1];if(typeof w=="number"&&typeof D=="number"&&!isNaN(w)&&!isNaN(D)){const S=(w-1)*s,_=(D-1)*s,b=Math.sign(_-S),N=S+b*(r/2),F=_-b*(r/2);I.push({type:"pcb_trace",pcb_trace_id:"",route:[{start_pcb_port_id:`{PIN${w}}`,x:N,y:0,width:g,layer:"top",route_type:"wire"},{end_pcb_port_id:`{PIN${D}}`,x:F,y:0,width:g,layer:"top",route_type:"wire"}]})}}}const l=(A-1)*s+r+.7,B=a+1,C=(A-1)*s/2,Q=0,h={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"outline",route:[{x:C-l/2,y:Q-B/2},{x:C+l/2,y:Q-B/2},{x:C+l/2,y:Q+B/2},{x:C-l/2,y:Q+B/2},{x:C-l/2,y:Q-B/2}],stroke_width:.15},u=Q+B/2+.6,d=Ui(C,u,.4);return{circuitJson:[...c,...I,h,d],parameters:t}},Zie={fn:xA("sot457"),num_pins:xA(6).default(6),pillh:U().default("0.45mm"),pillw:U().default("1.45mm"),pl:U(),pw:U(),p:U(),wave:PA().optional(),reflow:PA().optional()},d1t=Ri.extend({...Zie,h:U().default("2.5mm"),w:U().default("2.7mm"),pl:U().default("0.8mm"),pw:U().default("0.55mm"),p:U().default("0.95mm")}),p1t=Ri.extend({...Zie,h:U().default("3mm"),w:U().default("4mm"),pillr:U().default("0.225mm"),pl:U().default("1.45mm"),pw:U().default("1.5mm"),p:U().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)})),Kb=t=>Number.parseFloat(t.replace("mm","")),Vie=({pitch:t,width:A,pinNumber:e})=>{const o={1:{x:-A/2-.1,y:t},2:{x:-A/2-.1,y:0},3:{x:-A/2-.1,y:-t},4:{x:A/2+.1,y:-t},5:{x:A/2+.1,y:0},6:{x:A/2+.1,y:t}}[e];if(!o)throw new Error(`Invalid pin number: ${e}`);return o},jie=t=>{const A=[],e=Kb(t.p),i=Kb(t.pl),n=Kb(t.pw),o=Kb(t.w),s=Kb(t.h);if(t.wave){const C={1:({padWidth:Q,padHeight:h})=>li(1,-e,e,h,Q),2:({padWidth:Q,padHeight:h})=>li(2,-e,-e,h,Q),3:({padWidth:Q,padHeight:h})=>VV(3,-e,0,Kb(t.pillw),Kb(t.pillh)),4:({padWidth:Q,padHeight:h})=>VV(4,e,0,Kb(t.pillw),Kb(t.pillh)),5:({padWidth:Q,padHeight:h})=>li(5,e,e,h,Q),6:({padWidth:Q,padHeight:h})=>li(6,e,-e,h,Q)};for(let Q=1;Q<=t.num_pins;Q++){const h=C[Q];h&&A.push(h({padWidth:i,padHeight:n}))}}else for(let C=1;C<=t.num_pins;C++){const{x:Q,y:h}=Vie({pitch:e,width:o,pinNumber:C});A.push(li(C,Q,h,i,n))}const r={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-o/3,y:s/2+e/1.3},{x:o/3,y:s/2+e/1.3}],stroke_width:.05},a={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_2",route:[{x:-o/3,y:-s/2-e/1.3},{x:o/3,y:-s/2-e/1.3}],stroke_width:.05},g=Ui(0,s+.5,.3),c=Vie({pitch:e,width:o,pinNumber:1}),I=t.wave?1:.5,l=t.wave?.7:.3;c.x-=t.wave?n:n*1.7;const B={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"pin1_indicator",route:[{x:c.x+I/2,y:c.y},{x:c.x-I/2,y:c.y+l/2},{x:c.x-I/2,y:c.y-l/2},{x:c.x+I/2,y:c.y}],stroke_width:.05};return[g,r,a,B,...A]},f1t=t=>{if(t.wave){const e=p1t.parse({...t,fn:"sot457"});return{circuitJson:jie(e),parameters:e}}const A=d1t.parse(t);return{circuitJson:jie(A),parameters:A}},y1t=Ri.extend({fn:U(),num_pins:xA(6).default(6),w:U().default("1.1mm"),h:U().default("1.45mm"),p:U().default("0.35mm"),pl:U().default("0.2mm"),pw:U().default("0.2mm"),string:U().optional()}),m1t=t=>{const A=y1t.parse({...t,fn:"sot963"}),e=IA.parse(A.w),i=IA.parse(A.h),n=IA.parse(A.p),o=IA.parse(A.pl),s=IA.parse(A.pw),r=[];for(let B=0;B<6;B++){const{x:C,y:Q}=zie(B+1,e,n,o);r.push(li(B+1,C,Q,o,s))}const a={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-e/2,y:i/2},{x:e/2,y:i/2}],stroke_width:.05,pcb_silkscreen_path_id:""},g={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-e/2,y:-i/2},{x:e/2,y:-i/2}],stroke_width:.05,pcb_silkscreen_path_id:""},c=zie(1,e,n,o),I={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"pin_marker_1",route:[{x:c.x-o/2-.3,y:c.y},{x:c.x-o/2-.45,y:c.y+.15},{x:c.x-o/2-.45,y:c.y-.15},{x:c.x-o/2-.3,y:c.y}],stroke_width:.05,pcb_silkscreen_path_id:"pin_marker_1"},l=Ui(0,i/2+.4,.25);return{circuitJson:[...r,a,g,l,I],parameters:A}},zie=(t,A,e,i)=>{const n=A/2-i/2;return t<=3?{x:-n,y:e-(t-1)*e}:{x:n,y:-e+(t-4)*e}},w1t=Ri.extend({fn:U(),num_pins:Rt([xA(3),xA(2)]).default(3),p:U().default("3.8mm"),id:U().default("1.25mm"),od:U().default("2.35mm"),ca:U().default("14mm").describe("Caliper axis (width or diameter of the potentiometer body or adjustment knob)"),w:U().default("5.35mm"),h:U().default("4mm"),string:U().optional()}),D1t=t=>{const{p:A,id:e,od:i,h:n,ca:o}=t,s=Number.parseFloat(n),r=Number.parseFloat(o);return[Fo(1,0,r/4+.3,e,i),Fo(2,s,0,e,i),Fo(3,0,-r/4-.3,e,i)]},S1t=t=>{const A=t.string?.match(/^potentiometer_(\d+)/),e=A?Number.parseInt(A[1],10):3,i=w1t.parse({...t,num_pins:e});let n=[];i.num_pins===3&&(n=D1t(i));const o=Number.parseFloat(i.ca)/2+.15,s=Number.parseFloat(i.w),r=Number.parseFloat(i.od)/2+.35,a={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:0,y:o-1.75},{x:0,y:o},{x:s,y:o},{x:s,y:r}],stroke_width:.1,pcb_silkscreen_path_id:""},g={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:s,y:-r},{x:s,y:-o},{x:0,y:-o},{x:0,y:-o+1.75}],stroke_width:.1,pcb_silkscreen_path_id:""},c=Number.parseFloat(i.w)/2,I=Ui(c,o+1,.5);return{circuitJson:[...n,a,g,I],parameters:i}},b1t=Ri.extend({fn:U(),p:IA.optional().default("7.5mm"),id:IA.optional().default("1mm"),od:IA.optional().default("2mm"),d:IA.optional().default("10.5mm")}),x1t=(t,A,e,i,n)=>{const o=[],s=[];for(let r=0;r<=50;r++){const a=r/50*Math.PI,g=t+Math.cos(a)*e,c=A+Math.sin(a)*e;g<t-i&&c>=A-n/2&&c<=A+n/2||o.push({x:g,y:c})}for(let r=0;r<=50;r++){const a=Math.PI+r/50*Math.PI,g=t+Math.cos(a)*e,c=A+Math.sin(a)*e;g<t-i&&c>=A-n/2&&c<=A+n/2||s.push({x:g,y:c})}return{topArc:o,bottomArc:s}},_1t=t=>{const A=b1t.parse(t),{p:e,id:i,od:n,d:o}=A,s=[Fo(1,-e/2,0,i,n),Fo(2,e/2,0,i,n)],{topArc:r,bottomArc:a}=x1t(0,0,o/2+.1,n/2,n),g={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:r,stroke_width:.1,pcb_silkscreen_path_id:""},c={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:a,stroke_width:.1,pcb_silkscreen_path_id:""},I={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:0,y:o/2+.1},{x:0,y:-(o/2+.1)}],stroke_width:.1,pcb_silkscreen_path_id:""},l=-(o/2+.5),B=n/2+1.5,C=.5,Q={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:l-C,y:B},{x:l+C,y:B}],stroke_width:.1,pcb_silkscreen_path_id:""},h={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:l,y:B-C},{x:l,y:B+C}],stroke_width:.1,pcb_silkscreen_path_id:""},E=Ui(0,o/2+1,.5);return{circuitJson:[...s,g,c,I,Q,h,E],parameters:A}},k1t=Ri.extend({fn:U(),num_pins:xA(2).default(2),w:U().default("6.5mm"),h:U().default("3mm"),pl:U().default("1.75mm"),pw:U().default("2.40mm"),p:U().default("4.75mm")}),v1t=t=>{const A=k1t.parse(t),e=Ui(0,IA.parse(A.h)-.5,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:IA.parse(A.p)/2,y:IA.parse(A.h)/2},{x:-IA.parse(A.w)/2-.3,y:IA.parse(A.h)/2},{x:-IA.parse(A.w)/2-.3,y:-IA.parse(A.h)/2},{x:IA.parse(A.p)/2,y:-IA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:M1t(A).concat(i,e),parameters:A}},F1t=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},M1t=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:n}=F1t({pn:e,p:Number.parseFloat(t.p)});A.push(li(e,i,n,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},R1t=Ri.extend({fn:U(),num_pins:OA().default(3),w:U().default("2.45mm"),h:U().default("2.40mm"),pl:U().default("0.92mm"),pw:U().default("0.45mm"),p:U().default("0.891mm"),string:U().optional()}),N1t=t=>{const A=t.string?.match(/^sot323_(\d+)/),e=A?Number.parseInt(A[1],3):3,i=R1t.parse({...t,num_pins:e});if(i.num_pins===3)return{circuitJson:L1t(i),parameters:i};throw new Error("Invalid number of pins")},G1t=t=>{const{pn:A,p:e}=t;return A===1?{x:-e,y:.65}:A===2?{x:-e,y:-.65}:{x:e,y:0}},L1t=t=>{const A=[];for(let r=0;r<t.num_pins;r++){const{x:a,y:g}=G1t({num_pins:t.num_pins,pn:r+1,w:Number.parseFloat(t.w),h:Number.parseFloat(t.h),pl:Number.parseFloat(t.pl),p:Number.parseFloat(t.p)});A.push(li(r+1,a,g,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}const e=Ui(0,Number.parseInt(t.h)/2+1,.3),i=Number.parseFloat(t.w)/2-Number.parseFloat(t.pl),n=Number.parseFloat(t.h)/2,o={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-i,y:n+.3},{x:i,y:n+.3},{x:i,y:n/2}],type:"pcb_silkscreen_path",stroke_width:.1},s={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_2",route:[{x:-i,y:-n-.3},{x:i,y:-n-.3},{x:i,y:-n/2}],type:"pcb_silkscreen_path",stroke_width:.1};return[...A,o,s,e]},U1t=Ri.extend({fn:U(),circle:PA().optional(),rect:PA().optional(),square:PA().optional(),pill:PA().optional(),d:IA.optional(),pd:IA.optional(),diameter:IA.optional(),r:IA.optional(),pr:IA.optional(),radius:IA.optional(),w:IA.optional(),pw:IA.optional(),width:IA.optional(),h:IA.optional(),ph:IA.optional(),height:IA.optional(),s:IA.optional(),size:IA.optional(),string:U().optional()}).transform(t=>{let A="rect";t.circle&&(A="circle"),t.square&&(A="square"),t.rect&&(A="rect"),t.pill&&(A="pill");let e,i,n;return A==="circle"?t.r!==void 0?e=cr(t.r):t.pr!==void 0?e=cr(t.pr):t.radius!==void 0?e=cr(t.radius):t.d!==void 0?e=cr(t.d)/2:t.pd!==void 0?e=cr(t.pd)/2:t.diameter!==void 0?e=cr(t.diameter)/2:e=cr("1mm")/2:(t.w!==void 0?i=cr(t.w):t.pw!==void 0?i=cr(t.pw):t.width!==void 0?i=cr(t.width):t.s!==void 0?i=cr(t.s):t.size!==void 0?i=cr(t.size):i=cr("1mm"),t.h!==void 0?n=cr(t.h):t.ph!==void 0?n=cr(t.ph):t.height!==void 0?n=cr(t.height):A==="square"||A==="rect"?n=i:n=cr("1mm")),{fn:t.fn,shape:A,radius:e,width:i,height:n}}),H1t=t=>{const A=U1t.parse(t),{shape:e,radius:i,width:n,height:o}=A;let s,r;return e==="circle"?(s=_ie(1,{x:0,y:0,radius:i}),r=i+.5):e==="pill"?(s=VV(1,0,0,n,o),r=Math.max(n,o)/2+.5):(s=li(1,0,0,n,o),r=o/2+.5),{circuitJson:[s,Ui(0,r,.2)],parameters:A}},Y1t=Ri.extend({fn:U(),d:IA.optional(),hd:IA.optional(),r:IA.optional(),hr:IA.optional(),pd:IA.optional(),pr:IA.optional(),squarepad:PA().optional().default(!1)}).transform(t=>{let A;t.d!==void 0?A=cr(t.d):t.hd!==void 0?A=cr(t.hd):t.r!==void 0?A=cr(t.r)*2:t.hr!==void 0?A=cr(t.hr)*2:A=cr("1mm");let e;return t.pd!==void 0?e=cr(t.pd):t.pr!==void 0?e=cr(t.pr)*2:e=A*(1.5/1),{fn:t.fn,d:A,pd:e,squarepad:t.squarepad??!1}}),J1t=t=>{const A=Y1t.parse(t),{d:e,pd:i,squarepad:n}=A;return{circuitJson:[n?fm({pn:1,x:0,y:0,holeDiameter:e,rectPadWidth:i,rectPadHeight:i}):Fo(1,0,0,e,i),Ui(0,i/2+.5,.2)],parameters:A}},T1t=Ri.extend({fn:U(),num_pins:xA(6).default(6),h:U().default("1.6mm"),pl:U().default("1mm"),pw:U().default("0.7mm"),p:U().default("0.95mm")}),P1t=t=>{const A=T1t.parse(t);return{circuitJson:K1t(A),parameters:A}},Xie=t=>{const{p:A,h:e,pn:i}=t;if(i===1)return{x:-e/2-.5,y:A};if(i===2)return{x:-e/2-.5,y:0};if(i===3)return{x:-e/2-.5,y:-A};if(i===4)return{x:e/2+.5,y:-A};if(i===5)return{x:e/2+.5,y:0};if(i===6)return{x:e/2+.5,y:A};throw new Error("Invalid pin number")},K1t=t=>{const A=[];for(let I=1;I<=t.num_pins;I++){const{x:l,y:B}=Xie({h:Number.parseFloat(t.h),p:Number.parseFloat(t.p),pn:I});A.push(li(I,l,B,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}const e=t.num_pins/2*Number.parseFloat(t.p),i=Number.parseFloat(t.h),n={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-e/3,y:i/2+Number.parseFloat(t.p)/1.3},{x:e/3,y:i/2+Number.parseFloat(t.p)/1.3}],type:"pcb_silkscreen_path",stroke_width:.05},o={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_2",route:[{x:-e/3,y:-i/2-Number.parseFloat(t.p)/1.3},{x:e/3,y:-i/2-Number.parseFloat(t.p)/1.3}],type:"pcb_silkscreen_path",stroke_width:.05},s=Ui(0,i+.3,.3),r=Xie({h:Number.parseFloat(t.h),p:Number.parseFloat(t.p),pn:1});r.x=r.x-Number.parseFloat(t.pw)*1.5;const a=.7,g=.3,c={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"pin1_indicator",route:[{x:r.x+a/2,y:r.y},{x:r.x-a/2,y:r.y+g/2},{x:r.x-a/2,y:r.y-g/2},{x:r.x+a/2,y:r.y}],stroke_width:.05};return[...A,s,n,o,c]},q1t=Ri.extend({fn:U(),num_pins:OA().default(4),w:U().default("3.2mm"),h:U().default("2.6mm"),pl:U().default("1.05mm"),pw:U().default("0.45mm"),p:U().default("0.55mm"),string:U().optional()}),O1t=t=>{const A=t.string?.match(/^sot343_(\d+)/),e=A?Number.parseInt(A[1],4):4,i=q1t.parse({...t,num_pins:e});if(i.num_pins===4)return{circuitJson:Z1t(i),parameters:i};throw new Error("Invalid number of pins")},W1t=t=>{const{pn:A,p:e}=t;return A===1?{x:-e*1.92,y:-.65}:A===2?{x:-e*1.92,y:.65}:A===3?{x:e,y:.65}:A===4?{x:e,y:-.65}:{x:0,y:0}},Z1t=t=>{const A=[],e=Number.parseFloat(t.w),i=Number.parseFloat(t.h),n=Number.parseFloat(t.pl),o=Number.parseFloat(t.pw),s=Number.parseFloat(t.p);let r=1/0,a=-1/0,g=1/0,c=-1/0;for(let d=0;d<t.num_pins;d++){const{x:f,y}=W1t({num_pins:t.num_pins,pn:d+1,p:s});A.push(li(d+1,f,y,n,o)),f<r&&(r=f),f>a&&(a=f),y<g&&(g=y),y>c&&(c=y)}const I=(r+a)/2,l=c-g,B=i*.3,C=l/2+B;let Q=e*.8;i<=2.6&&(Q/=2);const h=Ui(I,C+.5,.3),E={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_top",route:[{x:I-Q/2,y:C},{x:I+Q/2,y:C}],type:"pcb_silkscreen_path",stroke_width:.1},u={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_bottom",route:[{x:I-Q/2,y:-C},{x:I+Q/2,y:-C}],type:"pcb_silkscreen_path",stroke_width:.1};return[...A,E,u,h]},V1t=Ri.extend({fn:U()}),j1t=t=>{const A=V1t.parse(t),e=[],i=.5-.15,n=1.5,s=.5/2,r=75,a=-37/2;for(let D=0;D<r;D++){const S=D+1;if(S>=24&&S<=31)continue;const _=a-D*s,b=S%2===0,N=n+(b?.25:0),L=.5-N/2,Y=li(S,L,_,N,i);Y.layer=b?"bottom":"top",e.push(Y)}const g=46*.0254,c=137*.0254,I=261*.0254,l={type:"pcb_cutout",pcb_cutout_id:"",shape:"rect",center:{x:-c/2+n/2,y:a-I},width:c,height:g},B={x:-.5,y:a},C={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"pin_marker_1",route:[{x:B.x-.4,y:B.y},{x:B.x-.7,y:B.y+.3},{x:B.x-.7,y:B.y-.3},{x:B.x-.4,y:B.y}],stroke_width:.05,pcb_silkscreen_path_id:"pin_marker_1"};let Q=1/0,h=-1/0,E=1/0,u=-1/0;const d=(D,S,_=0,b=0)=>{Q=Math.min(Q,D-_/2),h=Math.max(h,D+_/2),E=Math.min(E,S-b/2),u=Math.max(u,S+b/2)};for(const D of e){const S=D;d(S.x,S.y,S.width,S.height)}d(l.center.x,l.center.y,l.width,l.height);for(const D of C.route)d(D.x,D.y);const f=(Q+h)/2,y=(E+u)/2,w=D=>{typeof D.x=="number"&&(D.x-=f),typeof D.y=="number"&&(D.y-=y),D.center&&(D.center.x-=f,D.center.y-=y),Array.isArray(D.route)&&(D.route=D.route.map(S=>({x:S.x-f,y:S.y-y})))};for(const D of e)w(D);return w(l),w(C),{circuitJson:[...e,l,C],parameters:A}},z1t=Ri.extend({fn:U(),numPins:OA().optional().default(0),rows:Rt([U(),OA()]).transform(t=>Number(t)).optional().default(1).describe("number of rows"),p:IA.default("2.54mm").describe("pitch"),id:IA.default("1.0mm").describe("inner diameter"),od:IA.default("1.5mm").describe("outer diameter"),male:PA().optional().describe("the module uses male headers"),nopin:PA().optional().default(!1).describe("omit pins rendering"),female:PA().optional().describe("the module uses female headers"),smd:PA().optional().describe("surface mount device"),pinlabeltextalignleft:PA().optional().default(!1),pinlabeltextaligncenter:PA().optional().default(!1),pinlabeltextalignright:PA().optional().default(!1),pinlabelverticallyinverted:PA().optional().default(!1),pinlabelorthogonal:PA().optional().default(!1),nopinlabels:PA().optional().default(!1).describe("omit silkscreen pin labels"),doublesidedpinlabel:PA().optional().default(!1).describe("add silkscreen pins in top and bottom layers"),bottomsidepinlabel:PA().optional().default(!1).describe("place the silkscreen reference text on the bottom layer instead of top"),pinRowSide:Xe(["left","right","top","bottom"]).optional().default("left"),pinrowleft:PA().optional().default(!1),pinrowright:PA().optional().default(!1),pinrowtop:PA().optional().default(!1),pinrowbottom:PA().optional().default(!1),pinrowleftpins:Rt([U(),OA()]).transform(t=>Number(t)).optional(),pinrowrightpins:Rt([U(),OA()]).transform(t=>Number(t)).optional(),pinrowtoppins:Rt([U(),OA()]).transform(t=>Number(t)).optional(),pinrowbottompins:Rt([U(),OA()]).transform(t=>Number(t)).optional(),width:IA.optional(),height:IA.optional(),pinRowHoleEdgeToEdgeDist:IA.default("2mm"),holes:Rt([U(),Se(U())]).optional().transform(t=>!t||Array.isArray(t)?t:t.startsWith("(")&&t.endsWith(")")?t.slice(1,-1).split(",").map(A=>A.trim()):[t]),holeXDist:IA.optional(),holeYDist:IA.optional(),holeInset:IA.default("1mm"),pinrow:Rt([U(),OA()]).optional(),usbposition:Xe(["left","right","top","bottom"]).optional().default("left"),usbleft:PA().optional().default(!1),usbtop:PA().optional().default(!1),usbright:PA().optional().default(!1),usbbottom:PA().optional().default(!1),usbtype:Xe(["micro","c"]).optional(),usbmicro:PA().optional().default(!1),usbc:PA().optional().default(!1),screen:PA().optional().default(!1).describe("add silkscreen outline for screen/display area"),screenwidth:IA.optional(),screenheight:IA.optional(),screencenteroffsetx:IA.optional(),screencenteroffsety:IA.optional()}).transform(t=>{const A=Uie(t);let e=t.pinRowSide;t.pinrowleft&&(e="left"),t.pinrowright&&(e="right"),t.pinrowtop&&(e="top"),t.pinrowbottom&&(e="bottom");let i=t.usbposition;t.usbleft&&(i="left"),t.usbtop&&(i="top"),t.usbright&&(i="right"),t.usbbottom&&(i="bottom");let n=t.usbtype;t.usbmicro&&(n="micro"),t.usbc&&(n="c"),t.pinrow!==void 0&&(t.numPins=Number(t.pinrow));const o={left:t.pinrowleftpins,right:t.pinrowrightpins,top:t.pinrowtoppins,bottom:t.pinrowbottompins},s=Object.values(o).some(f=>f!==void 0&&f>0),r=(o.left??0)>0&&(o.right??0)>0,a=(o.top??0)>0&&(o.bottom??0)>0;s&&((o.left??0)>0?e="left":(o.right??0)>0?e="right":(o.top??0)>0?e="top":(o.bottom??0)>0&&(e="bottom"),t.numPins=(o.left??0)+(o.right??0)+(o.top??0)+(o.bottom??0));const g=Math.ceil(t.numPins/t.rows),c=Math.max(o.left??0,o.right??0),I=Math.max(o.top??0,o.bottom??0);let l,B;if(s){const f=r?t.p:0,y=a?t.p:0;l=(I>0?(I-1)*t.p:0)+2*t.pinRowHoleEdgeToEdgeDist+f,B=(c>0?(c-1)*t.p:0)+2*t.pinRowHoleEdgeToEdgeDist+y}else e==="left"||e==="right"?(l=(t.rows-1)*t.p+2*t.pinRowHoleEdgeToEdgeDist,B=(g-1)*t.p+2*t.pinRowHoleEdgeToEdgeDist):(B=(t.rows-1)*t.p+2*t.pinRowHoleEdgeToEdgeDist,l=(g-1)*t.p+2*t.pinRowHoleEdgeToEdgeDist);t.numPins===0&&(l=10,B=10);const C=t.width??l,Q=t.height??B,h=t.screenwidth??C*.95,E=t.screenheight??Q*.95,u=t.screencenteroffsetx??0,d=t.screencenteroffsety??0;return{...t,pinlabelAnchorSide:A,pinRowSide:e,usbposition:i,usbtype:n,male:t.male??!t.female,female:t.female??!1,width:C,height:Q,screenwidth:h,screenheight:E,screencenteroffsetx:u,screencenteroffsety:d,pinrowleftpins:o.left,pinrowrightpins:o.right,pinrowtoppins:o.top,pinrowbottompins:o.bottom}}).superRefine((t,A)=>{t.male&&t.female&&A.addIssue({code:zt.custom,message:"'male' and 'female' cannot both be true; it should be male or female.",path:["male","female"]})}),X1t=t=>{const A=z1t.parse(t),{p:e,id:i,od:n,rows:o,numPins:s,pinlabelAnchorSide:r,pinlabelverticallyinverted:a,pinlabelorthogonal:g,pinlabeltextalignleft:c,pinlabeltextalignright:I,nopinlabels:l,doublesidedpinlabel:B,bottomsidepinlabel:C,pinRowSide:Q,width:h,height:E,pinRowHoleEdgeToEdgeDist:u,holes:d,holeXDist:f,holeYDist:y,holeInset:w,pinrowleftpins:D,pinrowrightpins:S,pinrowtoppins:_,pinrowbottompins:b,usbposition:N,usbtype:F,screen:L,screenwidth:Y,screenheight:J,screencenteroffsetx:O,screencenteroffsety:Z}=A;let X="center";c?X="left":I&&(X="right");const eA=[],gA={left:D,right:S,top:_,bottom:b},tA=Object.values(gA).some(aA=>aA!==void 0&&aA>0),iA=(aA,EA,bA,_A)=>{if(A.smd?eA.push(li(aA,EA,bA,A.od,A.od)):aA===1?eA.push(fm({pn:aA,x:EA,y:bA,holeDiameter:i,rectPadWidth:n,rectPadHeight:n})):eA.push(Fo(aA,EA,bA,i,n)),!l){const LA=EA+(_A==="left"?-n:_A==="right"?n:0),QA=bA+(_A==="top"?n:_A==="bottom"?-n:0);C||eA.push(sM({fs:n/5,pn:aA,anchor_x:LA,anchor_y:QA,textalign:X,orthogonal:g,verticallyinverted:a,layer:"top"})),(B||C)&&eA.push(sM({fs:n/5,pn:aA,anchor_x:LA,anchor_y:QA,textalign:X,orthogonal:g,verticallyinverted:a,layer:"bottom"}))}};if(tA){const aA=e;let EA=1;const bA=gA.left??0,_A=gA.right??0,LA=gA.top??0,QA=gA.bottom??0,kA=(dA,qA)=>{if(!(qA<=0))if(dA==="left"||dA==="right"){const VA=dA==="left"?-h/2+u:h/2-u,ce=(qA-1)/2*aA;for(let fA=0;fA<qA;fA++)iA(EA,VA,ce-fA*aA,dA),EA++}else{const VA=dA==="top"?E/2-u:-E/2+u,ce=-((qA-1)/2)*aA;for(let fA=0;fA<qA;fA++)iA(EA,ce+fA*aA,VA,dA),EA++}};kA("left",bA),kA("right",_A),kA("top",LA),kA("bottom",QA)}else{const aA=e;let EA=0,bA=0,_A=0,LA=0,QA=0,kA=0;const dA=Math.ceil(s/o);Q==="left"||Q==="right"?(EA=Q==="left"?-h/2+u:h/2-u,bA=(dA-1)/2*aA,_A=0,LA=-aA,QA=Q==="left"?aA:-aA,kA=0):(EA=-(dA-1)/2*aA,bA=Q==="top"?E/2-u:-E/2+u,_A=aA,LA=0,QA=0,kA=Q==="top"?-aA:aA);let qA=1;for(let VA=0;VA<o&&qA<=s;VA++)for(let ce=0;ce<dA&&qA<=s;ce++){const fA=EA+ce*_A+VA*QA,ge=bA+ce*LA+VA*kA;if(A.smd?eA.push(li(qA,fA,ge,A.od,A.od)):qA===1?eA.push(fm({pn:qA,x:fA,y:ge,holeDiameter:i,rectPadWidth:n,rectPadHeight:n})):eA.push(Fo(qA,fA,ge,i,n)),!l){const jA=fA+(Q==="left"?-n:Q==="right"?n:0),JA=ge+(Q==="top"?n:Q==="bottom"?-n:0);C||eA.push(sM({fs:n/5,pn:qA,anchor_x:jA,anchor_y:JA,textalign:X,orthogonal:g,verticallyinverted:a,layer:"top"})),(B||C)&&eA.push(sM({fs:n/5,pn:qA,anchor_x:jA,anchor_y:JA,textalign:X,orthogonal:g,verticallyinverted:a,layer:"bottom"}))}qA++}}if(d)for(const aA of d){let EA=0,bA=0;aA==="topleft"?(EA=-h/2+w,bA=E/2-w):aA==="topright"?(EA=h/2-w,bA=E/2-w):aA==="bottomleft"?(EA=-h/2+w,bA=-E/2+w):aA==="bottomright"?(EA=h/2-w,bA=-E/2+w):aA==="center"&&(EA=0,bA=0),f!==void 0&&(EA+=f),y!==void 0&&(bA+=y),eA.push(Fo(s+d.indexOf(aA)+1,EA,bA,i,n))}if(!A.nosilkscreen){const aA=[{x:-h/2,y:-E/2},{x:h/2,y:-E/2},{x:h/2,y:E/2},{x:-h/2,y:E/2},{x:-h/2,y:-E/2}];eA.push(rM(aA,{stroke_width:.1,layer:"top"}))}const sA=Ui(0,E/2+1,.5);if(eA.push(sA),N&&F){let aA,EA;if(F==="c")aA=8,EA=3;else if(F==="micro")aA=6,EA=2;else return{circuitJson:eA,parameters:A};let bA;if(N==="left")bA=[{x:-h/2,y:-aA/2},{x:-h/2+EA,y:-aA/2},{x:-h/2+EA,y:aA/2},{x:-h/2,y:aA/2},{x:-h/2,y:-aA/2}];else if(N==="right")bA=[{x:h/2-EA,y:-aA/2},{x:h/2,y:-aA/2},{x:h/2,y:aA/2},{x:h/2-EA,y:aA/2},{x:h/2-EA,y:-aA/2}];else if(N==="top")bA=[{x:-aA/2,y:E/2-EA},{x:aA/2,y:E/2-EA},{x:aA/2,y:E/2},{x:-aA/2,y:E/2},{x:-aA/2,y:E/2-EA}];else if(N==="bottom")bA=[{x:-aA/2,y:-E/2},{x:aA/2,y:-E/2},{x:aA/2,y:-E/2+EA},{x:-aA/2,y:-E/2+EA},{x:-aA/2,y:-E/2}];else return{circuitJson:eA,parameters:A};eA.push(rM(bA,{stroke_width:.1,layer:"top"}))}if(L){const aA=Y/2,EA=J/2,bA=O,_A=Z,LA=[{x:-aA+bA,y:-EA+_A},{x:aA+bA,y:-EA+_A},{x:aA+bA,y:EA+_A},{x:-aA+bA,y:EA+_A},{x:-aA+bA,y:-EA+_A}];eA.push(rM(LA,{stroke_width:.05,layer:"top"}))}return{circuitJson:eA,parameters:A}},$1t=Ri.extend({fn:U(),num_pins:OA().default(3),inline:PA().default(!1),p:U().default("1.27mm"),id:U().default("0.75mm"),od:U().default("1.3mm"),w:U().default("4.8mm"),h:U().default("4.0mm")}),A2t=t=>{const A=$1t.parse(t),e=Number.parseFloat(A.p),i=Number.parseFloat(A.w),n=Number.parseFloat(A.h),o=A.inline?1.05:Number.parseFloat(A.od),s=A.inline?1.5:o,r=[fm({pn:1,x:0,y:0,holeDiameter:A.id,rectPadWidth:o,rectPadHeight:s}),A.inline?aM(2,e,0,Number.parseFloat(A.id),o,s):Fo(2,e,e,A.id,o),A.inline?aM(3,e*2,0,Number.parseFloat(A.id),o,s):Fo(3,e*2,0,A.id,o)],a=i/2,g=A.inline?e-.09:e,c=.2,I=c+a-n,l=Array.from({length:32},(Q,h)=>{const E=Math.PI*h/31;return{x:g+a*Math.cos(E),y:c+a*Math.sin(E)}}),B={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"",stroke_width:.12,route:[...l,{x:g-a,y:I},{x:g+a,y:I},l[0]]},C=Ui(g,c+a+1,.5);return{circuitJson:[...r,B,C],parameters:A}},e2t=(t,A)=>{const e=t.filter(i=>i.type==="pcb_silkscreen_text");if(e.length===0)return t;for(const i of e)A.norefdes&&(i.text="");return t},t2t=(t,A)=>A.nosilkscreen?t.filter(e=>e.type!=="pcb_silkscreen_path"&&e.type!=="pcb_silkscreen_text"):t,i2t=(t,A)=>{if(!A)return t;const e=t.filter(c=>c.type==="pcb_smtpad"||c.type==="pcb_plated_hole"||c.type==="pcb_thtpad");if(e.length===0)return t;let i=Number.POSITIVE_INFINITY,n=Number.NEGATIVE_INFINITY,o=Number.POSITIVE_INFINITY,s=Number.NEGATIVE_INFINITY;const r=(c,I,l=0,B=0)=>{const C=c-l/2,Q=c+l/2,h=I-B/2,E=I+B/2;i=Math.min(i,C),n=Math.max(n,Q),o=Math.min(o,h),s=Math.max(s,E)};for(const c of e)if(c.type==="pcb_smtpad"){const I=c.shape==="circle"?c.radius*2:c.width,l=c.shape==="circle"?c.radius*2:c.height;r(c.x,c.y,I,l)}else if(c.type==="pcb_plated_hole"){const I=c.outer_diameter??c.hole_diameter;r(c.x,c.y,I,I)}else if(c.type==="pcb_thtpad"){const I=c.diameter;r(c.x,c.y,I,I)}let a=0,g=0;switch(A){case"center":a=(i+n)/2,g=(o+s)/2;break;case"bottomleft":a=i,g=o;break;case"bottomcenter":case"centerbottom":a=(i+n)/2,g=o;break;case"topcenter":case"centertop":a=(i+n)/2,g=s;break;case"leftcenter":case"centerleft":a=i,g=(o+s)/2;break;case"rightcenter":case"centerright":a=n,g=(o+s)/2;break;case"pin1":{const c=e.find(I=>I.port_hints?.[0]==="1")||e[0];a=c.x,g=c.y;break}}if(a===0&&g===0)return t;for(const c of t){if(typeof c.x=="number"&&(c.x-=a),typeof c.y=="number"&&(c.y-=g),c.center&&typeof c.center.x=="number"&&(c.center.x-=a,c.center.y-=g),c.type==="pcb_silkscreen_path")for(const I of c.route)I.x-=a,I.y-=g;c.type==="pcb_silkscreen_text"&&c.anchor_position&&(c.anchor_position.x-=a,c.anchor_position.y-=g)}return t};function n2t(t){return t!=null}var o2t=t=>t.trim().replace(/^sot-223-(\d+)(?=_|$)/i,"sot223_$1").replace(/^to-220f-(\d+)(?=_|$)/i,"to220f_$1"),s2t=t=>{let A=XV();const e=o2t(t),n=e.replace(/^((?:\d{4}|\d{5}))(?=$|_|x)/,"res$1").replace(/^zh(\d+)(?:$|_)/,"jst$1_zh").split(/_(?!metric)/).map(o=>{const s=o.match(/([a-zA-Z]+)([\(\d\.\+\?].*)?/);if(!s)return null;const[,r,a]=s;if(!r)return null;const g=r.toLowerCase();return a?.includes("?")?null:{fn:g,v:a}}).filter(n2t);for(const{fn:o,v:s}of n)A=A[o](s);return A.setString(e),A},r2t=()=>Object.keys(Pb),XV=()=>{const t=new Proxy({},{get:(A,e)=>{if(e==="soup"||e==="circuitJson"){if("fn"in A&&Pb[A.fn])return()=>{const{circuitJson:i}=Pb[A.fn](A),n=t2t(i,A),o=e2t(n,A);return i2t(o,A.origin)};if(!Pb[A.fn])throw new Error(`Invalid footprint function, got "${A.fn}"${A.string?`, from string "${A.string}"`:""}`);return()=>{throw new Error(`No function found for footprinter, make sure to specify .dip, .lr, .p, etc. Got "${e}"`)}}if(e==="json"){if(!Pb[A.fn])throw new Error(`Invalid footprint function, got "${A.fn}"${A.string?`, from string "${A.string}"`:""}`);return()=>Pb[A.fn](A).parameters}return e==="getFootprintNames"?()=>Object.keys(Pb):e==="params"?()=>A:e==="setString"?i=>(A.string=i,t):i=>(Object.keys(A).length===0?`${e}${i}`in Pb?(A[`${e}${i}`]=!0,A.fn=`${e}${i}`):(A[e]=!0,A.fn=e,e==="res"||e==="cap"?i&&(typeof i=="string"&&i.includes("_metric")?A.metric=i.split("_metric")[0]:A.imperial=i):A.num_pins=Number.isNaN(Number.parseFloat(i))?void 0:Number.parseFloat(i)):!i&&["w","h","p"].includes(e)||(A[e]=i??!0),t)}});return t};XV.string=s2t,XV.getFootprintNames=r2t;var a2t=XV,$ie=Symbol("Fragment");function cpA(t,A,...e){const i=e.length?e:A?.children!==void 0?[A.children]:[],n=[],o=(Array.isArray(i)?i:[i]).flat(1/0);for(const s of o)s==null||s===!1||(Array.isArray(s)?n.push(...s):n.push(s));return{type:t,props:(A&&A.children!==void 0?{...A,children:void 0}:A)||{},children:n}}var Qt=Symbol("Cuboid"),Ane=Symbol("Cube"),Wl=Symbol("Cylinder"),$V=Symbol("Sphere"),BJ=Symbol("RoundedCuboid"),Zi=Symbol("Translate"),aC=Symbol("Rotate"),XQ=Symbol("Union"),ym=Symbol("Subtract"),xc=Symbol("Hull"),Do=Symbol("Colorize"),CJ=Symbol("Polygon"),QJ=Symbol("ExtrudeLinear"),Gf=Symbol("RoundedCylinder"),Tn=$ie,zA=(t,A,e)=>cpA(t,A),qt=(t,A,e)=>cpA(t,A),yB=({center:t,width:A,length:e,height:i,heightAboveSurface:n=.15,color:o="#555",taperRatio:s=.12,faceRatio:r=.75,straightHeightRatio:a=.5,includeNotch:g=!0,notchRadius:c,notchPosition:I,notchRotation:l=[0,0,0],notchLength:B=.5,notchWidth:C=.25,chamferSize:Q=0})=>{const h=i*a,E=i-h,u=Math.min(A,e)*s,d=Math.max(A-u,A*r),f=Math.max(e-u,e*r),y=Math.min(A,e)*.12,w=c??y,D={x:0,y:e/2-w*.25,z:i},S=I??D,_=qt(XQ,{children:[qt(xc,{children:[zA(Zi,{z:.005,children:zA(Qt,{size:[d,f,.01]})}),zA(Zi,{z:h,children:zA(Qt,{size:[A,e,.01]})})]}),qt(xc,{children:[zA(Zi,{z:h,children:zA(Qt,{size:[A,e,.01]})}),zA(Zi,{z:h+E,children:zA(Qt,{size:[d,f,.01]})})]})]}),b=(F,L)=>zA(Zi,{offset:{x:F,y:L,z:0},children:zA(aC,{rotation:[0,0,Math.PI/4],children:zA(Qt,{size:[Q*Math.SQRT2,Q*Math.SQRT2,i*3]})})});let N=_;if(Q>0){const F=A/2,L=e/2;N=qt(ym,{children:[_,b(F,L),b(-F,L),b(F,-L),b(-F,-L)]})}return zA(Do,{color:o,children:zA(Zi,{offset:t,children:zA(Zi,{offset:{x:0,y:0,z:n},children:g?qt(ym,{children:[N,zA(Zi,{offset:S,children:zA(aC,{rotation:l,children:zA(Wl,{radius:w,height:C})})})]}):N})})})},g2t=t=>Array.from({length:t},(A,e)=>e);function IpA(t,A){if(t.length<2)throw new Error("Stroke must have at least two points");const e=Array.isArray(t[0])?t.map(([c,I])=>({x:c,y:I})):t,i=A/2,n=[],o=[];function s(c,I){const l=I.x-c.x,B=I.y-c.y,C=Math.sqrt(l*l+B*B);return{x:-B/C,y:l/C}}function r(c,I,l){const B={x:c.x+I.x*i*l,y:c.y+I.y*i*l};l>0?n.push(B):o.unshift(B)}const a=s(e[0],e[1]);r(e[0],a,1),r(e[0],a,-1);for(let c=1;c<e.length-1;c++){const I=e[c-1],l=e[c],B=e[c+1],C=s(I,l),Q=s(l,B),h=C.x+Q.x,E=C.y+Q.y,u=Math.sqrt(h*h+E*E);if(u/2>2*i)r(l,C,1),r(l,Q,1),r(l,C,-1),r(l,Q,-1);else{const f=1/u;r(l,{x:h*f,y:E*f},1),r(l,{x:h*f,y:E*f},-1)}}const g=s(e[e.length-2],e[e.length-1]);return r(e[e.length-1],g,1),r(e[e.length-1],g,-1),[...n,...o]}var c2t=t=>{const A=Math.min(...t.map(r=>r.x)),e=Math.max(...t.map(r=>r.x)),i=Math.min(...t.map(r=>r.y)),s=5.47/(Math.max(...t.map(r=>r.y))-i);return t.map(r=>({x:(r.x-A-(e-A)/2)*s,y:(r.y-i)*s}))},I2t=c2t([{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}]),ene=5.47,A9=.5,l2t=({x:t,y:A,z:e})=>{const i=t>0;return qt(Tn,{children:[zA(Zi,{offset:{x:t+.25/2,y:A,z:e},children:zA(aC,{rotation:["-90deg",0,"90deg"],children:zA(QJ,{height:.25,children:zA(CJ,{points:I2t.slice().reverse().map(n=>[n.x,n.y])})})})}),zA(Zi,{offset:{x:t,y:A+(i?1:-1),z:e},children:zA(aC,{rotation:["-90deg","90deg",i?"180deg":"0deg"],children:zA(QJ,{height:2,children:zA(CJ,{points:IpA([[0,0],[-1,0],[-1,-1]],.25).map(n=>[n.x,n.y])})})})})]})},B2t=({numPins:t=8,pitch:A=2.54,bodyWidth:e=6.4,rowSpacing:i})=>{const n=Math.floor(t/2),o=i??(e>=7?e:e+1.22),s=e>=7?o-1.22:e;return qt(Tn,{children:[g2t(t).map(r=>{const a=r%n,g=(Math.floor(r/n)-.5)*2;return zA(l2t,{x:g*o/2,y:a*A-(n-1)/2*A,z:ene/2+A9})}),zA(yB,{width:s,length:n*A+.5,height:ene-A9,heightAboveSurface:A9,center:{x:0,y:0,z:A9}})]})};function C2t(t,{height:A,padContactLength:e,curveLength:i,bodyDistance:n,steepness:o=10}){i||(i=n*.3);let s=n-e-i;s<0&&(i+=s,s=0);const r=e*.75,a=e+i+(n-e-i)*.25;if(t<=r)return 0;if(t>=a)return A;const g=(t-r)/(a-r);return A/(1+Math.exp(-o*(g-.5)))}var so=t=>{const{thickness:A,width:e,padContactLength:i,bodyDistance:n,height:o,rotation:s}=t,r=15,a=Array.from({length:r}).map((c,I)=>I/(r-1)*n).map(c=>[c,C2t(c,t)]),g=IpA(a,A);return zA(Do,{color:"#fff",children:zA(Zi,{offset:{z:0,y:0,x:0,...t.position},children:zA(aC,{rotation:["90deg",0,s??0],children:zA(Zi,{offset:{x:0,y:0,z:-e/2},children:zA(QJ,{height:e,children:zA(CJ,{points:g.map(c=>[c.x,c.y])})})})})})})},Q2t=({pinCount:t,leadLength:A,leadWidth:e,pitch:i,bodyWidth:n})=>{const o=Math.ceil(t/2),s=i*t/2+e/2,r=(o-1)*i/2,a=.25;return qt(Tn,{children:[Array.from({length:o}).map((g,c)=>zA(so,{position:{x:-n/2-A,y:c*i-r,z:a/2},width:e,thickness:a,padContactLength:A,bodyDistance:A+1,height:.8})),Array.from({length:o}).map((g,c)=>zA(so,{rotation:Math.PI,position:{x:n/2+A,y:c*i-r,z:a/2},width:e,thickness:a,padContactLength:A,bodyDistance:A+1,height:.8})),zA(yB,{center:{x:0,y:0,z:a/2},width:n-e-1,length:s,height:1.5})]})},h2t=({pinCount:t,padContactLength:A=.4,leadWidth:e=.2,pitch:i=.65,bodyWidth:n=3})=>{const o=Math.ceil(t/2),s=(o-1)*i/2,r=.2;return qt(Tn,{children:[Array.from({length:o}).map((a,g)=>zA(so,{position:{x:-n/2-A-.3,y:g*i-s,z:r/2},width:e,thickness:r,padContactLength:A,bodyDistance:A+.4,height:.6})),Array.from({length:o}).map((a,g)=>zA(so,{rotation:Math.PI,position:{x:n/2+A+.3,y:g*i-s,z:r/2},width:e,thickness:r,padContactLength:A,bodyDistance:A+.4,height:.6})),zA(yB,{center:{x:0,y:0,z:r/2},width:n,length:n,height:1.1,notchRadius:.35,heightAboveSurface:.1,taperRatio:.09})]})},lpA=1,BpA=.5,k1=.5,hJ=.2,E2t=lpA-hJ*2,tne=({color:t="#333"})=>qt(Tn,{children:[zA(Qt,{size:[E2t,BpA,k1],offset:[0,0,k1/2],color:t}),zA(Qt,{size:[hJ,k1,BpA],offset:[lpA/2-hJ/2,0,k1/2],color:"#ccc"}),zA(Qt,{size:[hJ,k1,BpA],offset:[-lpA/2+hJ/2,0,k1/2],color:"#ccc"})]}),CpA=1.6,u2t=CpA-.3*2,e9=.3,QpA=.85,v1=.6,ine=({color:t="#333"})=>qt(Tn,{children:[zA(Qt,{size:[u2t,QpA,v1],offset:[0,0,v1/2],color:t}),zA(Qt,{size:[e9,QpA,v1],offset:[CpA/2-e9/2,0,v1/2],color:"#ccc"}),zA(Qt,{size:[e9,QpA,v1],offset:[-CpA/2+e9/2,0,v1/2],color:"#ccc"})]}),hpA=2,EpA=1.25,F1=.55,EJ=.5,d2t=hpA-EJ*2,nne=({color:t="#333"})=>qt(Tn,{children:[zA(Qt,{size:[d2t,EpA,F1],offset:[0,0,F1/2],color:t}),zA(Qt,{size:[EJ,EpA,F1],offset:[hpA/2-EJ/2,0,F1/2],color:"#ccc"}),zA(Qt,{size:[EJ,EpA,F1],offset:[-hpA/2+EJ/2,0,F1/2],color:"#ccc"})]}),p2t=({pinCount:t,pitch:A,leadWidth:e,padContactLength:i,bodyWidth:n})=>{const o=t/4;A||(A=f2t(t,n)),i||(i=y2t(t)),e||(e=m2t(t,n)),n||(n=A*(o+4));const s=n,r=(o-1)*A/2,a=s+2*i,g=a,c=.8,I=.15,l=(g-n)/2+.5;return qt(Tn,{children:[Array.from({length:o}).map((B,C)=>zA(so,{position:{x:-g/2-.4,y:C*A-r,z:I/2},width:e,thickness:I,padContactLength:i,bodyDistance:l,height:c})),Array.from({length:o}).map((B,C)=>zA(so,{rotation:Math.PI,position:{x:g/2+.4,y:C*A-r,z:I/2},width:e,thickness:I,padContactLength:i,bodyDistance:l,height:c})),Array.from({length:o}).map((B,C)=>zA(so,{rotation:Math.PI/2,position:{x:C*A-r,y:-a/2-.4,z:I/2},width:e,thickness:I,padContactLength:i,bodyDistance:l,height:c})),Array.from({length:o}).map((B,C)=>zA(so,{rotation:-Math.PI/2,position:{x:C*A-r,y:a/2+.4,z:I/2},width:e,thickness:I,padContactLength:i,bodyDistance:l,height:c})),zA(yB,{center:{x:0,y:0,z:0},width:n,length:s,height:1.5,taperRatio:.03,chamferSize:.7,notchPosition:{x:-(s/2-1.5),y:n/2-1.5,z:1.5},notchRadius:1.5/2})]})},f2t=(t,A)=>{switch(t){case 44:case 64:return .8;case 52:return A===14?1:.65;case 208:return .5;default:return .5}},y2t=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}},m2t=(t,A)=>{switch(t){case 44:case 64:return .5;case 52:return A===14?.45:.55;case 208:return .3;default:return .25}},one=({x:t,y:A,pinThickness:e,shortSidePinLength:i,longSidePinLength:n,bodyHeight:o,bodyLength:s=2.54,bodyWidth:r=2.54,flipZ:a,faceup:g,smd:c,rightangle:I})=>qt(Tn,{children:[zA(Zi,{y:I?-3:0,children:zA(Qt,{color:"#222",size:[s,r,o],center:[t,A,a(o/2)]})}),!g&&zA(Do,{color:"gold",children:c?zA(so,{rotation:-Math.PI/2,position:{x:t,y:A+1,z:e/2},thickness:e,width:e,height:e,padContactLength:2,bodyDistance:3}):qt(xc,{children:[zA(Qt,{color:"gold",size:[e,e,i*.9],center:[t,A,a(o*.9+o/2)]}),zA(Qt,{color:"gold",size:[e/1.8,e/1.8,i],center:[t,A,a(o+o/2)]})]})}),zA(Do,{color:"gold",children:zA(Zi,{y:I?-3.9:0,z:I?1:0,children:zA(aC,{rotation:I?[-Math.PI/2,0,0]:[0,0,0],children:qt(xc,{children:[zA(Qt,{color:"gold",size:[e,e,n*.9],center:[t,A,a(-n/2*.9)]}),zA(Qt,{color:"gold",size:[e/1.8,e/1.8,n],center:[t,A,a(-n/2)]})]})})})})]}),w2t=({numberOfPins:t,pitch:A=2.54,longSidePinLength:e=6,invert:i,faceup:n,rows:o=1,smd:s,rightangle:r})=>{const c=Math.ceil(t/o),I=2.54,l=3,B=-((c-1)/2)*A,C=!s&&!r?-2-1.6:0,Q=h=>(i||n?-h+2:h)+C;return zA(Tn,{children:Array.from({length:t},(h,E)=>{const u=Math.floor(E/c),d=E%c,f=B+d*A,y=-u*I;return zA(one,{x:f,y,pinThickness:.63,shortSidePinLength:l,longSidePinLength:e,bodyHeight:2,flipZ:Q,faceup:n,smd:s,rightangle:r},E)})})},D2t=t=>{const A=["left","bottom","right","top"],{pin_count:e,pn:i,w:n,h:o,p:s,pl:r}=t,a=e/4,g=A[Math.floor((i-1)/a)],c=(i-1)%a,I=s*(a-1),l=s*(a-1),B=-r/2;switch(g){case"left":return{x:-n/2-B,y:l/2-c*s,o:"vert"};case"bottom":return{x:-I/2+c*s,y:-o/2-B,o:"horz"};case"right":return{x:n/2+B,y:-l/2+c*s,o:"vert"};case"top":return{x:I/2-c*s,y:o/2+B,o:"horz"};default:throw new Error("Invalid pin number")}},S2t=({num_pins:t,cw:A,ccw:e,startingpin:i})=>{const n=[],o=t/4;let s=1;const r={};for(const a of i??[])r[a]=!0;!r.leftside&&!r.topside&&!r.rightside&&!r.bottomside&&(r.leftside=!0),!r.bottompin&&!r.leftpin&&!r.rightpin&&!r.toppin&&(r.leftside?r.toppin=!0:r.topside?r.rightpin=!0:r.rightside?r.bottompin=!0:r.bottomside&&(r.leftpin=!0)),r.leftside&&r.toppin?s=1:r.leftside&&r.bottompin?s=o:r.bottomside&&r.leftpin?s=o+1:r.bottomside&&r.rightpin?s=o*2:r.rightside&&r.bottompin?s=o*2+1:r.rightside&&r.toppin?s=o*3:r.topside&&r.rightpin?s=o*3+1:r.topside&&r.leftpin&&(s=o*4),n.push(-1);for(let a=0;a<t;a++)n[s]=a+1,s++,s>t&&(s=1);return n},b2t=({num_pins:t=16,bodyWidth:A=9,bodyLength:e=9,bodyThickness:i=.8,thermalPadSize:n,padWidth:o=.25,padLength:s=.25,pitch:r=.5,thermalPadThickness:a=.05})=>{const g=S2t({num_pins:t,cw:!0,ccw:!0}),c=[];for(let I=0;I<t;I++){const{x:l,y:B,o:C}=D2t({pin_count:t,pn:I+1,w:A,h:e,p:r,pl:s});let Q=o,h=s;C==="vert"&&([Q,h]=[h,Q]);const E=g[I+1];c.push({pn:E,x:l,y:B,pw:Q,pl:h})}return qt(Tn,{children:[zA(Do,{color:"grey",children:zA(Qt,{center:{x:0,y:0,z:i/2},size:[A,e,i]})}),c.map((I,l)=>zA(Qt,{center:{x:I.x,y:I.y,z:a/2},size:[I.pw,I.pl,a]})),n?.length!==void 0&&n?.width!==void 0&&zA(Qt,{center:{x:0,y:0,z:a/2},size:[n.width,n.length,a]})]})},x2t=b2t,_2t=()=>{const a=1.1999999999999997;return qt(Tn,{children:[zA(so,{rotation:Math.PI,position:{x:2.8/2+a/4,y:-1,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:a,height:.95}),zA(so,{rotation:Math.PI,position:{x:2.8/2+a/4,y:1,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:a,height:.95}),zA(so,{position:{x:-2.8/2-a/4,y:0,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:a,height:.95}),zA(so,{position:{x:-2.8/2-a/4,y:-1,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:a,height:.95}),zA(so,{position:{x:-2.8/2-a/4,y:1,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:a,height:.95}),zA(yB,{center:{x:0,y:0,z:0},width:1.6,length:2.9,height:1.2})]})},k2t=_2t,v2t=({fullWidth:t=2.9,fullLength:A=2.8})=>{const c=(t-1.92)/2+.3;return qt(Tn,{children:[zA(so,{rotation:Math.PI,position:{x:t/2,y:0,z:.075},width:.4,thickness:.15,padContactLength:.25,bodyDistance:c,height:.45}),zA(so,{position:{x:-t/2,y:-.95,z:.075},width:.4,thickness:.15,padContactLength:.25,bodyDistance:c,height:.45}),zA(so,{position:{x:-t/2,y:.95,z:.075},width:.4,thickness:.15,padContactLength:.25,bodyDistance:c,height:.45}),zA(yB,{center:{x:0,y:0,z:0},width:1.92,length:2.9,height:1.1,straightHeightRatio:.45,heightAboveSurface:.05})]})},upA=.6,dpA=.3,M1=.33,uJ=.1,F2t=upA-uJ*2,sne=({color:t="#333"})=>qt(Tn,{children:[zA(Qt,{size:[F2t,dpA,M1],offset:[0,0,M1/2],color:t}),zA(Qt,{size:[uJ,dpA,M1],offset:[upA/2-uJ/2,0,M1/2],color:"#ccc"}),zA(Qt,{size:[uJ,dpA,M1],offset:[-upA/2+uJ/2,0,M1/2],color:"#ccc"})]}),ppA=.4,fpA=.2,R1=.13,dJ=.07,M2t=ppA-dJ*2,rne=({color:t="#333"})=>qt(Tn,{children:[zA(Qt,{size:[M2t,fpA,R1],offset:[0,0,R1/2],color:t}),zA(Qt,{size:[dJ,fpA,R1],offset:[ppA/2-dJ/2,0,R1/2],color:"#ccc"}),zA(Qt,{size:[dJ,fpA,R1],offset:[-ppA/2+dJ/2,0,R1/2],color:"#ccc"})]}),ypA=3.2,mpA=1.6,N1=.9,pJ=.5,R2t=ypA-pJ*2,ane=({color:t="#333"})=>qt(Tn,{children:[zA(Qt,{size:[R2t,mpA,N1],offset:[0,0,N1/2],color:t}),zA(Qt,{size:[pJ,mpA,N1],offset:[ypA/2-pJ/2,0,N1/2],color:"#ccc"}),zA(Qt,{size:[pJ,mpA,N1],offset:[-ypA/2+pJ/2,0,N1/2],color:"#ccc"})]}),wpA=3.2,DpA=2.5,G1=1,fJ=.6,N2t=wpA-fJ*2,gne=({color:t="#333"})=>qt(Tn,{children:[zA(Qt,{size:[N2t,DpA,G1],offset:[0,0,G1/2],color:t}),zA(Qt,{size:[fJ,DpA,G1],offset:[wpA/2-fJ/2,0,G1/2],color:"#ccc"}),zA(Qt,{size:[fJ,DpA,G1],offset:[-wpA/2+fJ/2,0,G1/2],color:"#ccc"})]}),SpA=5,bpA=2.5,L1=1.4,yJ=.6,G2t=SpA-yJ*2,cne=({color:t="#333"})=>qt(Tn,{children:[zA(Qt,{size:[G2t,bpA,L1],offset:[0,0,L1/2],color:t}),zA(Qt,{size:[yJ,bpA,L1],offset:[SpA/2-yJ/2,0,L1/2],color:"#ccc"}),zA(Qt,{size:[yJ,bpA,L1],offset:[-SpA/2+yJ/2,0,L1/2],color:"#ccc"})]}),xpA=6.3,_pA=3.2,U1=1.8,mJ=.8,L2t=xpA-mJ*2,Ine=({color:t="#333"})=>qt(Tn,{children:[zA(Qt,{size:[L2t,_pA,U1],offset:[0,0,U1/2],color:t}),zA(Qt,{size:[mJ,_pA,U1],offset:[xpA/2-mJ/2,0,U1/2],color:"#ccc"}),zA(Qt,{size:[mJ,_pA,U1],offset:[-xpA/2+mJ/2,0,U1/2],color:"#ccc"})]}),lne=({x:t,y:A,z:e=0,pitch:i=2.54,legsLength:n=3,innerDiameter:o=.945,bodyHeight:s=5,bodyLength:r=i,bodyWidth:a=i,flipZ:g})=>{const c=o/1.5,I=c*1.6;return qt(Tn,{children:[zA(Do,{color:"#1a1a1a",children:qt(ym,{children:[zA(Qt,{color:"#000",size:[r,a,s],center:[t,A,g(e+s/2)]}),o?zA(Wl,{height:s+.1,radius:o/2,center:[t,A,g(e+s/2)],color:"#222"}):zA(Qt,{size:[I,I,s],center:[t,A,g(e+s/2)]})]})}),qt(Do,{color:"silver",children:[qt(xc,{children:[zA(Qt,{color:"silver",size:[c,c,n*.9],center:[t,A,g(e+-n/2*.9)]}),zA(Qt,{color:"silver",size:[c/1.8,c/1.8,n],center:[t,A,g(e+-n/2)]})]}),zA(Qt,{color:"silver",size:[I,I,I*.5],center:[t,A,g(e+I/2*.5)]})]})]})},U2t=({numberOfPins:t,pitch:A=2.54,legsLength:e=3,innerDiameter:i=.945,rows:n=1,invert:o})=>{const r=Math.ceil(t/n),a=2.54,g=-((r-1)/2)*A,c=I=>o?-I+5:I;return zA(Tn,{children:Array.from({length:t},(I,l)=>{const B=Math.floor(l/r),C=l%r,Q=g+C*A,h=-B*a;return zA(lne,{x:Q,y:h,pitch:A,legsLength:e,innerDiameter:i,flipZ:c},l)})})},H2t=({width:t,length:A,innerDiameter:e=1})=>{const i=t,n=A,o=t*.7,s=e/2.5;return qt(Tn,{children:[zA(BJ,{color:"#1a1a1f",center:[0,0,o/2],size:[n,n,o],roundRadius:.3}),zA(BJ,{color:"#f2f2f2",center:[0,0,o+o*.1/2.5],size:[n,n,o*.1],roundRadius:.14}),zA(Wl,{color:"#1a1a1f",height:o*.8,radius:i/3,center:[0,0,o+o*.8/2]}),zA(Wl,{color:"#1a1a1f",height:o*.2,radius:e/2,center:[n/3,n/3,o+o*.1/2]}),zA(Wl,{color:"#1a1a1f",height:o*.2,radius:e/2,center:[-n/3,-n/3,o+o*.1/2]}),zA(Wl,{color:"#1a1a1f",height:o*.2,radius:e/2,center:[-n/3,n/3,o+o*.1/2]}),zA(Wl,{color:"#1a1a1f",height:o*.2,radius:e/2,center:[n/3,-n/3,o+o*.1/2]}),zA(t9,{thickness:e/3,width:s,horizontalLength:n*.8,verticalLength:o/2,position:{x:-i/2,y:-n/2,z:-o*1.2}}),zA(t9,{thickness:e/3,width:s,horizontalLength:n*.8,verticalLength:o/2,position:{x:-i/2,y:n/2,z:-o*1.2},rotation:Math.PI}),zA(t9,{thickness:e/3,width:s,horizontalLength:n*.8,verticalLength:o/2,position:{x:i/2,y:n/2,z:-o*1.2},rotation:Math.PI}),zA(t9,{thickness:e/3,width:s,horizontalLength:n*.8,verticalLength:o/2,position:{x:i/2+e/3.6,y:-n/2,z:-o*1.2}})]})},t9=t=>{const{thickness:A,width:e,horizontalLength:i,verticalLength:n,rotation:o=0,position:s}=t,r=[[0,i],[-n/3,i/3],[-n/5,i/4],[0,0]],a=IpA(r,A);return zA(Do,{color:"#f2f2f2",children:zA(Zi,{offset:{x:s?.x||0,y:s?.y||0,z:s?.z||0},children:zA(aC,{rotation:[0,55,o],children:zA(QJ,{height:e,children:zA(CJ,{points:a.map(g=>[g.y,g.x])})})})})})},Y2t=({pinCount:t,leadLength:A,leadWidth:e,pitch:i,bodyWidth:n})=>{const o=Math.ceil(t/2),s=(o-1)*i/2,r=.25,a=1,g=.8,c=A*0,I=i*(o-1)+e+.2,l=n*.55;return qt(Tn,{children:[Array.from({length:o}).map((B,C)=>zA(so,{position:{x:-n/2-c,y:C*i-s,z:r/2},width:e,thickness:r,padContactLength:A/2,bodyDistance:A+.3,height:g})),Array.from({length:o}).map((B,C)=>zA(so,{rotation:Math.PI,position:{x:n/2+c,y:C*i-s,z:r/2},width:e,thickness:r,padContactLength:A/2,bodyDistance:A+.3,height:g})),zA(yB,{center:{x:0,y:0,z:r/2},width:l,length:I,height:a})]})},J2t=({pinCount:t,pitch:A,leadWidth:e,leadLength:i,bodyWidth:n,bodyLength:o})=>{const s=t===8?{pitch:.65,leadWidth:.3}:{pitch:.5,leadWidth:.225},r=isNaN(parseFloat(A))?s.pitch:parseFloat(A),a=isNaN(parseFloat(e))?s.leadWidth:parseFloat(e)*.8,g=isNaN(parseFloat(n))?2.6:parseFloat(n)*.8,c=isNaN(parseFloat(o))?2+Number(r)*1.4:parseFloat(o),I=t/2,l=(I-1)*r/2,B=.15,C=.8,Q=4.5,h=(Q-g)/2,E=h*.5;return qt(Tn,{children:[Array.from({length:I}).map((u,d)=>zA(so,{position:{x:-Q/2,y:l-d*r,z:B/2},width:a,thickness:B,padContactLength:E+.05,bodyDistance:h+.1,height:C})),Array.from({length:I}).map((u,d)=>zA(so,{rotation:Math.PI,position:{x:Q/2,y:l-d*r,z:B/2},width:a,thickness:B,padContactLength:E+.05,bodyDistance:h+.1,height:C})),zA(yB,{center:{x:0,y:0,z:B/2},width:g,length:c,height:1})]})},T2t=()=>qt(Tn,{children:[zA(Qt,{color:"#ccc",size:[.5,.6,.12],center:[-.725,0,.12/2]}),zA(Qt,{color:"#ccc",size:[.5,.6,.12],center:[.725,0,.12/2]}),zA(Do,{color:"#222",children:qt(XQ,{children:[zA(Zi,{z:.3/2,children:zA(Qt,{size:[1.65,.8,.3]})}),qt(xc,{children:[zA(Zi,{z:.3,children:zA(Qt,{size:[1.65,.8,.01]})}),zA(Zi,{z:.6,children:zA(Qt,{size:[1.65-.2,.8-.2,.01]})})]})]})})]}),P2t=()=>qt(Tn,{children:[zA(Qt,{color:"#ccc",size:[.26,.51,.12],center:[-.325,0,.12/2]}),zA(Qt,{color:"#ccc",size:[.26,.51,.12],center:[.325,0,.12/2]}),zA(Do,{color:"#222",children:zA(Zi,{z:.47/2+.02,children:zA(Qt,{size:[.98,.58,.47]})})}),zA(Qt,{color:"#ccc",size:[.98+.001,.26/2,.26/4],center:[0,.26/2,.47/4]}),zA(Qt,{color:"#ccc",size:[.98+.001,.26/2,.26/4],center:[0,-.26/2,.47/4]}),zA(Qt,{color:"#ccc",size:[.26/1.5,.58+.001,.26/4],center:[.65/2,0,.47/4]}),zA(Qt,{color:"#ccc",size:[.26/1.5,.58+.001,.26/4],center:[-.65/2,0,.47/4]})]}),K2t=()=>{const g=zA(Do,{color:"#1a1a1a",children:qt(XQ,{children:[qt(xc,{children:[zA(Zi,{z:.13,children:zA(Qt,{size:[4,3,.03]})}),zA(Zi,{z:1.15,children:zA(Qt,{size:[4.4,3.4,.01]})})]}),qt(xc,{children:[zA(Zi,{z:1.15,children:zA(Qt,{size:[4.4,3.4,.01]})}),zA(Zi,{z:2.3,children:zA(Qt,{size:[4,3,.01]})})]})]})}),c=({xDir:I})=>{const C=I*1.78,Q=I*(3.4/2-.2/2+1),h=I*(3.4/2-.2/2),E=Math.abs(h-Q),u=(Q+h)/2;return zA(Do,{color:"#c0c0c0",children:qt(XQ,{children:[zA(Qt,{size:[2.3*.8,1.45,.2],center:[C,0,.2/2]}),zA(Qt,{size:[.2,1.45,1.14],center:[Q,0,1.14/2+.2]}),zA(Qt,{size:[E,1.45,.2],center:[u,0,.2/2+1.14]})]})})};return qt(Tn,{children:[zA(c,{xDir:1}),zA(c,{xDir:-1}),g]})},q2t=()=>{const g=zA(Do,{color:"#1a1a1a",children:qt(XQ,{children:[qt(xc,{children:[zA(Zi,{z:.13,children:zA(Qt,{size:[4,3,.03]})}),zA(Zi,{z:1.15,children:zA(Qt,{size:[4.4,3.4,.01]})})]}),qt(xc,{children:[zA(Zi,{z:1.15,children:zA(Qt,{size:[4.4,3.4,.01]})}),zA(Zi,{z:2.3,children:zA(Qt,{size:[4,3,.01]})})]})]})}),c=({xDir:I})=>{const C=I*1.78,Q=I*(3.4/2-.2/2+1),h=I*(3.4/2-.2/2),E=Math.abs(h-Q),u=(Q+h)/2;return zA(Do,{color:"#c0c0c0",children:qt(XQ,{children:[zA(Qt,{size:[2.3*.8,1.45,.2],center:[C,0,.2/2]}),zA(Qt,{size:[.2,1.45,1.14],center:[Q,0,1.14/2+.2]}),zA(Qt,{size:[E,1.45,.2],center:[u,0,.2/2+1.14]})]})})};return qt(Tn,{children:[zA(c,{xDir:1}),zA(c,{xDir:-1}),g]})},O2t=()=>{const g=zA(Do,{color:"#1a1a1a",children:qt(XQ,{children:[qt(xc,{children:[zA(Zi,{z:.21000000000000002,children:zA(Qt,{size:[6.3999999999999995,5.6,.03]})}),zA(Zi,{z:1.15,children:zA(Qt,{size:[6.8,6,.01]})})]}),qt(xc,{children:[zA(Zi,{z:1.15,children:zA(Qt,{size:[6.8,6,.01]})}),zA(Zi,{z:2.3,children:zA(Qt,{size:[6.3999999999999995,5.6,.01]})})]})]})}),c=({xDir:I})=>{const C=I*3.08,Q=I*(6/2-.2/2+1),h=I*(6/2-.2/2),E=Math.abs(h-Q),u=(Q+h)/2;return zA(Do,{color:"#c0c0c0",children:qt(XQ,{children:[zA(Qt,{size:[2.3*.8,2.95,.2],center:[C,0,.2/2]}),zA(Qt,{size:[.2,2.95,1.14],center:[Q,0,1.14/2+.2]}),zA(Qt,{size:[E,2.95,.2],center:[u,0,.2/2+1.14]})]})})};return qt(Tn,{children:[zA(c,{xDir:1}),zA(c,{xDir:-1}),g]})},W2t=()=>{const I=zA(Do,{color:"#222",children:qt(XQ,{children:[zA(Zi,{z:.27,children:zA(Qt,{size:[2.9,1.9,.54]})}),qt(xc,{children:[zA(Zi,{z:.54,children:zA(Qt,{size:[2.9,1.9,.01]})}),zA(Zi,{z:1.08,children:zA(Qt,{size:[2.6999999999999997,1.7,.01]})})]})]})});return qt(Tn,{children:[zA(Qt,{color:"#ccc",size:[1,1.2,.25],center:[-1.3,0,.25/2]}),zA(Qt,{color:"#ccc",size:[1,1.2,.25],center:[1.3,0,.25/2]}),I]})},Z2t=()=>qt(Tn,{children:[zA(Qt,{color:"#ccc",size:[1,.6,.12],center:[-1.3,0,.12/2]}),zA(Qt,{color:"#ccc",size:[1,.6,.12],center:[1.3,0,.12/2]}),zA(Do,{color:"#222",children:qt(XQ,{children:[zA(Zi,{z:.55/2,children:zA(Qt,{size:[2.7,1.6,.55]})}),qt(xc,{children:[zA(Zi,{z:.55,children:zA(Qt,{size:[2.7,1.6,.01]})}),zA(Zi,{z:1.1,children:zA(Qt,{size:[2.7-.2,1.6-.2,.01]})})]})]})})]}),V2t=()=>qt(Tn,{children:[zA(Qt,{color:"#ccc",size:[1,.9,.2],center:[-1.3,0,.2/2]}),zA(Qt,{color:"#ccc",size:[1,.9,.2],center:[1.3,0,.2/2]}),zA(Do,{color:"#222",children:qt(XQ,{children:[zA(Zi,{z:.2/2,children:zA(Qt,{size:[2.75,1.8,.2]})}),qt(xc,{children:[zA(Zi,{z:.2,children:zA(Qt,{size:[2.75,1.8,.01]})}),zA(Zi,{z:1,children:zA(Qt,{size:[2.75-.4,1.8-.4,.01]})})]})]})}),zA(Qt,{color:"#777",size:[.2,1.8-.4,.01],center:[-1.3+.4,0,1]})]}),j2t=()=>qt(Tn,{children:[zA(Qt,{color:"#ccc",size:[.9,.9,.2],center:[-1.225,0,.2/2]}),zA(Qt,{color:"#ccc",size:[.9,.9,.2],center:[1.225,0,.2/2]}),zA(Do,{color:"#222",children:qt(XQ,{children:[qt(xc,{children:[zA(Zi,{z:.2,children:zA(Qt,{size:[2.6-.1/2,1.7-.1/2,.01]})}),zA(Zi,{z:.01,children:zA(Qt,{size:[2.6-.1,1.7-.1,.01]})})]}),qt(xc,{children:[zA(Zi,{z:.2,children:zA(Qt,{size:[2.6,1.7,.01]})}),zA(Zi,{z:1,children:zA(Qt,{size:[2.6-.4,1.7-.4,.01]})})]})]})}),zA(Qt,{color:"#777",size:[.2*2.7,1.7-.4,.02],center:[-1.225+.4,0,1]})]}),z2t=()=>qt(Tn,{children:[zA(Qt,{color:"#ccc",size:[.9,1.75,.2],center:[-1.825,0,.2/2]}),zA(Qt,{color:"#ccc",size:[.9,1.75,.2],center:[1.825,0,.2/2]}),zA(Do,{color:"#222",children:qt(XQ,{children:[qt(xc,{children:[zA(Zi,{z:.2,children:zA(Qt,{size:[3.8-.05/2,2.5-.05/2,.01]})}),zA(Zi,{z:.01,children:zA(Qt,{size:[3.8-.05,2.5-.05,.01]})})]}),qt(xc,{children:[zA(Zi,{z:.2,children:zA(Qt,{size:[3.8,2.5,.01]})}),zA(Zi,{z:1,children:zA(Qt,{size:[3.8-.4,2.5-.4,.01]})})]})]})}),zA(Qt,{color:"#777",size:[.2*2.7,2.5-.4,.02],center:[-1.825+.4,0,1]})]}),X2t=()=>qt(Tn,{children:[zA(Qt,{color:"#ccc",size:[.4,.25,.14],center:[-.4,0,.14/2]}),zA(Qt,{color:"#ccc",size:[.4,.25,.14],center:[.4,0,.14/2]}),zA(Do,{color:"#222",children:qt(XQ,{children:[zA(Zi,{z:.14/2,children:zA(Qt,{size:[.8,.6,.14]})}),qt(xc,{children:[zA(Zi,{z:.14,children:zA(Qt,{size:[.8,.6,.01]})}),zA(Zi,{z:.37,children:zA(Qt,{size:[.8-.1,.6-.1,.01]})})]})]})})]}),$2t=()=>{const c=3.0999999999999996;return qt(Tn,{children:[zA(so,{rotation:Math.PI,position:{x:6.6/2+c/4,y:0,z:.25/2},width:3,thickness:.25,padContactLength:.5,bodyDistance:c,height:.75}),zA(so,{position:{x:-6.6/2-c/4,y:0,z:.25/2},width:.7,thickness:.25,padContactLength:.5,bodyDistance:c,height:.75}),zA(so,{position:{x:-6.6/2-c/4,y:-2.3,z:.25/2},width:.7,thickness:.25,padContactLength:.5,bodyDistance:c,height:.75}),zA(so,{position:{x:-6.6/2-c/4,y:2.3,z:.25/2},width:.7,thickness:.25,padContactLength:.5,bodyDistance:c,height:.75}),zA(yB,{center:{x:0,y:0,z:0},width:3.5,length:6.5,height:1.7,includeNotch:!1,taperRatio:.06,straightHeightRatio:.45})]})},ALt=()=>qt(Tn,{children:[Array.from({length:16}).map((B,C)=>zA(so,{position:{x:-10.5/2,y:C*.5-3.75,z:.25/2},width:.2,thickness:.25,padContactLength:.45,bodyDistance:.95,height:.65})),Array.from({length:16}).map((B,C)=>zA(so,{rotation:Math.PI,position:{x:10.5/2,y:C*.5-3.75,z:.25/2},width:.2,thickness:.25,padContactLength:.45,bodyDistance:.95,height:.65})),Array.from({length:16}).map((B,C)=>zA(so,{rotation:Math.PI/2,position:{x:C*.5-3.75,y:-10.5/2,z:.25/2},width:.2,thickness:.25,padContactLength:.45,bodyDistance:.95,height:.65})),Array.from({length:16}).map((B,C)=>zA(so,{rotation:-Math.PI/2,position:{x:C*.5-3.75,y:10.5/2,z:.25/2},width:.2,thickness:.25,padContactLength:.45,bodyDistance:.95,height:.65})),zA(yB,{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})]}),eLt=ALt,tLt=()=>{const g=.7999999999999998;return qt(Tn,{children:[zA(so,{rotation:Math.PI,position:{x:2.05/2+g/4,y:0,z:.18/2},width:.3,thickness:.18,padContactLength:.2,bodyDistance:g,height:.65}),zA(so,{position:{x:-2.05/2-g/4,y:-.65,z:.18/2},width:.3,thickness:.18,padContactLength:.2,bodyDistance:g,height:.65}),zA(so,{position:{x:-2.05/2-g/4,y:.65,z:.18/2},width:.3,thickness:.18,padContactLength:.2,bodyDistance:g,height:.65}),zA(yB,{center:{x:0,y:0,z:0},width:1.25,length:2,height:.9,includeNotch:!1,taperRatio:.06,straightHeightRatio:.7,heightAboveSurface:.05})]})},iLt=({pinCount:t,pitch:A,leadWidth:e,padContactLength:i,bodyWidth:n})=>{const o=t/4;if(o!==Math.floor(o))throw new Error(`LQFP pinCount must be divisible by 4, got ${t}`);A||(A=.5),i||(i=.6),e||(e=.22),n||(n=A*(o+4));const s=n,r=(o-1)*A/2,a=s+3.3*i,g=a,c=.8,I=.2,l=(g-n)/2+.4;return qt(Tn,{children:[Array.from({length:o}).map((B,C)=>zA(so,{position:{x:-g/2-.36,y:C*A-r,z:I/2},width:e,thickness:I,padContactLength:i,bodyDistance:l,height:c})),Array.from({length:o}).map((B,C)=>zA(so,{rotation:Math.PI,position:{x:g/2+.36,y:C*A-r,z:I/2},width:e,thickness:I,padContactLength:i,bodyDistance:l,height:c})),Array.from({length:o}).map((B,C)=>zA(so,{rotation:Math.PI/2,position:{x:C*A-r,y:-a/2-.36,z:I/2},width:e,thickness:I,padContactLength:i,bodyDistance:l,height:c})),Array.from({length:o}).map((B,C)=>zA(so,{rotation:-Math.PI/2,position:{x:C*A-r,y:a/2+.36,z:I/2},width:e,thickness:I,padContactLength:i,bodyDistance:l,height:c})),zA(yB,{center:{x:0,y:0,z:0},width:n,length:s,height:1.5,heightAboveSurface:.1,taperRatio:.04,chamferSize:.7,notchPosition:{x:-(s/2-1.5),y:s/2-1.5,z:1.5},notchRadius:1.5/2})]})},nLt=()=>{const i=.20900000000000002,n=.1,o=.3,s=.1,r=.2;return qt(Tn,{children:[zA(Do,{color:"#222",children:qt(XQ,{children:[zA(Qt,{size:[.85,1.2,i],center:[0,0,i/2]}),qt(xc,{children:[zA(Zi,{z:i,children:zA(Qt,{size:[.85,1.2,.01]})}),zA(Zi,{z:.38,children:zA(Qt,{size:[.85-n,1.2-n,.01]})})]})]})}),zA(Qt,{color:"#ccc",size:[o,.25,s],center:[.55,0,s/2]}),zA(Qt,{color:"#ccc",size:[o,r,s],center:[-.55,.4,s/2]}),zA(Qt,{color:"#ccc",size:[o,r,s],center:[-.55,-.4,s/2]})]})},oLt=({num_pins:t,bodyWidth:A=5.3,bodyLength:e=5.3,bodyThickness:i=1,thermalPadSize:n,padWidth:o=e/5.3*.6,padLength:s=e/5.3*1,pitch:r=.5,thermalPadThickness:a=.2})=>{const g=[],c=Math.floor(t/2),I=r*(c-1);for(let l=0;l<t;l++){const B=l<c?"left":"right",C=l%c,Q=I/2-C*r,h=s,E=o,u=B==="left"?-A/2+h/2:A/2-h/2,d=l+1;g.push({pinNumber:d,x:u,y:Q,padSizeX:h,padSizeY:E})}return qt(Tn,{children:[zA(yB,{center:{x:0,y:0,z:0},width:A,length:e,height:i,heightAboveSurface:0,color:"grey",chamferSize:.2,taperRatio:0,notchPosition:{x:-(A/2-s),y:e/2-s,z:i}}),g.map((l,B)=>zA(Qt,{center:[l.x,l.y,a/2],size:[l.padSizeX,l.padSizeY,a]})),n?.length!==void 0&&n?.width!==void 0&&zA(Qt,{center:[0,0,a/2],size:[n.width,n.length,a]})]})},sLt=({bodyLength:t=10.2,bodyWidth:A=4.65,bodyHeight:e=13.46,leadSpacing:i=5,leadDiameter:n=.8,leadLength:o=12.7,color:s="#ddd",leadColor:r="#b87333"})=>{const a=t/2,g=A/2,c=a-g,I=i/2,l=.85;return qt(Tn,{children:[qt(Do,{color:s,children:[qt(xc,{children:[zA(Gf,{height:e,roundRadius:.5,radius:g,center:[-c,0,e]}),zA(Gf,{height:e,roundRadius:.5,radius:g,center:[c,0,e]})]}),qt(xc,{children:[zA(Gf,{height:l,roundRadius:.1,radius:g+.85,center:[-c,0,e/2+l/2]}),zA(Gf,{height:l,roundRadius:.1,radius:g+.85,center:[c,0,e/2+l/2]})]})]}),qt(Do,{color:r,children:[zA(Wl,{height:o+e/2,radius:n/2,center:[-I+.06,0,-(o/2)+e/2]}),zA(Wl,{height:o+e/2,radius:n/2,center:[I-.06,0,-(o/2)+e/2]})]})]})},rLt=({bodyLength:t=1.4,bodyDiameter:A=1.1,color:e="#3a3a3aff",contactColor:i="#c6c6c6",cathodeIdentification:n="#111"})=>qt(Tn,{children:[zA(Do,{color:e,children:qt(aC,{rotation:[0,"90deg",0],children:[zA(BJ,{size:[A,A,t-.2],roundRadius:.2,center:[-A/2,0,.05]}),zA(Wl,{height:.2/2,radius:A/2-.2,center:[-A/2,0,-t/2+.2/2]})]})}),zA(Do,{color:n,children:zA(aC,{rotation:[0,"90deg",0],children:zA(BJ,{size:[A*1.01,A*1.01,t/3],roundRadius:.2,center:[-A/2,0,-t/4+.1]})})}),zA(Do,{color:i,children:zA(aC,{rotation:[0,"90deg",0],children:zA(Gf,{height:.2,radius:A/2,roundRadius:.2/3,center:[-A/2,0,-t/2]})})}),zA(Do,{color:i,children:zA(aC,{rotation:[0,"90deg",0],children:zA(Gf,{height:.2,radius:A/2,roundRadius:.2/3,center:[-A/2,0,t/2]})})})]}),aLt=({bodyLength:t=3.5,bodyDiameter:A=1.5,color:e="#3a3a3aff",contactColor:i="#c6c6c6"})=>qt(Tn,{children:[zA(Do,{color:e,children:zA(aC,{rotation:[0,"90deg",0],children:zA(Gf,{height:t,radius:A/2,roundRadius:.3,center:[-A/2,0,0]})})}),zA(Do,{color:i,children:zA(aC,{rotation:[0,"90deg",0],children:zA(Gf,{height:.5,radius:A/2,roundRadius:.2,center:[-A/2,0,-t/2]})})}),zA(Do,{color:i,children:zA(aC,{rotation:[0,"90deg",0],children:zA(Gf,{height:.5,radius:A/2,roundRadius:.2,center:[-A/2,0,t/2]})})})]}),gLt=({bodyLength:t=3.9,bodyDiameter:A=2.5,color:e="#3a3a3aff",contactColor:i="#c6c6c6"})=>qt(Tn,{children:[zA(Do,{color:e,children:zA(aC,{rotation:[0,"90deg",0],children:zA(Gf,{height:t,radius:A/2,roundRadius:.3,center:[-A/2,0,0]})})}),zA(Do,{color:i,children:zA(aC,{rotation:[0,"90deg",0],children:zA(Gf,{height:.55,radius:A/2,roundRadius:.2,center:[-A/2,0,-t/2]})})}),zA(Do,{color:i,children:zA(aC,{rotation:[0,"90deg",0],children:zA(Gf,{height:.55,radius:A/2,roundRadius:.2,center:[-A/2,0,t/2]})})})]}),cLt=({pinCount:t,padContactLength:A=.6,leadWidth:e=.41,pitch:i=1.27})=>{if(t%2!==0)throw new Error("MS012 pinCount must be even");const n=t/2,o=4.9,s=3.9,r=(n-1)*i/2,a=.2;return qt(Tn,{children:[Array.from({length:n}).map((g,c)=>zA(so,{position:{x:-s/2-A-.3,y:c*i-r,z:a/2},width:e,thickness:a,padContactLength:A,bodyDistance:A+.4,height:.85})),Array.from({length:n}).map((g,c)=>zA(so,{rotation:Math.PI,position:{x:s/2+A+.3,y:c*i-r,z:a/2},width:e,thickness:a,padContactLength:A,bodyDistance:A+.4,height:.85})),zA(yB,{center:{x:0,y:0,z:a/2},width:s,length:o,height:1.55,notchPosition:{x:-.95,y:o/2-1,z:1.55},heightAboveSurface:.17,taperRatio:.09})]})},ILt=({pinCount:t=16,padContactLength:A=.6,leadWidth:e=.41,pitch:i=1.27})=>{if(t!==16)throw new Error("MS013 only supports 16 pins");const n=t/2,o=7.5,s=10.3,r=(n-1)*i/2,a=.2;return qt(Tn,{children:[Array.from({length:n}).map((g,c)=>zA(so,{position:{x:-o/2-A-.3,y:c*i-r,z:a/2},width:e,thickness:a,padContactLength:A,bodyDistance:A+.4,height:.85})),Array.from({length:n}).map((g,c)=>zA(so,{rotation:Math.PI,position:{x:o/2+A+.3,y:c*i-r,z:a/2},width:e,thickness:a,padContactLength:A,bodyDistance:A+.4,height:.85})),zA(yB,{center:{x:0,y:0,z:a/2},width:o,length:s,height:1.1,notchPosition:{x:-2.25,y:s/2-1.5,z:1.1},heightAboveSurface:.17,taperRatio:.05})]})},lLt=()=>{const Q=7.050000000000001,h=24.95+6.5/2;return zA(Zi,{center:[0,0,1],children:qt(Tn,{children:[qt(aC,{rotation:[0,55,-55],children:[qt(ym,{children:[zA(Qt,{color:"#ccc",size:[6.5+.1,9.9,1.3],center:[h,0,1.3-2]}),zA(Wl,{color:"black",center:[h,0,1.3-2],radius:3/2,height:1.3*1.2})]}),zA(Do,{color:"#222",children:zA(yB,{width:9.9,length:9.9,height:4.5,center:{x:20,y:0,z:-2.4},includeNotch:!1,straightHeightRatio:.3,taperRatio:.04,heightAboveSurface:1})})]}),zA(aC,{rotation:[0,55,55],children:Array.from({length:3}).map((E,u)=>{const d=Q,f=(u-1)*2.7,y=-.5-.6;return qt(Do,{color:"gold",children:[qt(xc,{children:[zA(Zi,{center:[15.05-4.5/2+.1,f,y],children:zA(Qt,{size:[4.5,.81+1,.5]})}),zA(Zi,{center:[15.05-4.5/2-1+.1,f,y],children:zA(Qt,{size:[4.5,.81,.5]})})]}),zA(Zi,{center:[d,f,y],children:zA(Qt,{size:[16+.1,.81,.5]})})]},`prong-${u}`)})})]})})},BLt=()=>{const g=1.1999999999999997;return qt(Tn,{children:[zA(so,{rotation:Math.PI,position:{x:2.8/2+g/4,y:-.95,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:g,height:.95}),zA(so,{rotation:Math.PI,position:{x:2.8/2+g/4,y:0,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:g,height:.95}),zA(so,{rotation:Math.PI,position:{x:2.8/2+g/4,y:.95,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:g,height:.95}),zA(so,{position:{x:-2.8/2-g/4,y:0,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:g,height:.95}),zA(so,{position:{x:-2.8/2-g/4,y:-.95,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:g,height:.95}),zA(so,{position:{x:-2.8/2-g/4,y:.95,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:g,height:.95}),zA(yB,{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})]})},CLt=()=>qt(Tn,{children:[zA(yB,{center:{x:0,y:0,z:0},width:.8,length:1,height:.37,heightAboveSurface:0,color:"#1a1a1a",taperRatio:.15,straightHeightRatio:0,notchPosition:{x:-.8/4,y:.7/2.2,z:.37+.1}}),[0,1,2].map(g=>{const c=-.35+g*.35;return zA(Qt,{center:[-.8/2+.19/2-.1,c,.12/2],size:[.19,.15,.12]})}),[0,1,2].map(g=>{const c=-.35+g*.35;return zA(Qt,{center:[.8/2-.19/2+.1,c,.12/2],size:[.19,.15,.12]})})]}),QLt=()=>{const s="#222",a=[.43,.4,1.32],g=[.43,.4,.25],c=[0,0,-.66],I=[0,0,-1.32],l=[0,1.28,-2.72],B=[0,1.28,-8.9],C=-7.5;return qt(Zi,{center:[0,1,10.5],children:[zA(Do,{color:s,children:qt(ym,{children:[zA(Zi,{center:[0,0,2.25],children:zA(Wl,{radius:2.4,height:4.5})}),zA(Zi,{center:[0,-1.8499999999999999,2.25],children:zA(Qt,{size:[2.4*2,1.1,4.5+.2]})})]})}),zA(Zi,{center:c,children:zA(Qt,{size:a})}),qt(xc,{children:[zA(Zi,{center:I,children:zA(Qt,{size:g})}),zA(Zi,{center:l,children:zA(Qt,{size:g})})]}),zA(Zi,{center:B,children:zA(Qt,{size:[.43,.4,12.2]})}),zA(Zi,{center:[1.3,0,C],children:zA(Qt,{size:[.43,.4,15]})}),zA(Zi,{center:[-1.3,0,C],children:zA(Qt,{size:[.43,.4,15]})})]})},hLt=()=>qt(Tn,{children:[zA(so,{rotation:Math.PI,position:{x:2/2+.75/4,y:-.65,z:.15/2},width:.25,thickness:.15,padContactLength:.3,bodyDistance:.75,height:.85}),zA(so,{rotation:Math.PI,position:{x:2/2+.75/4,y:0,z:.15/2},width:.25,thickness:.15,padContactLength:.3,bodyDistance:.75,height:.85}),zA(so,{rotation:Math.PI,position:{x:2/2+.75/4,y:.65,z:.15/2},width:.25,thickness:.15,padContactLength:.3,bodyDistance:.75,height:.85}),zA(so,{position:{x:-2/2-.75/4,y:0,z:.15/2},width:.25,thickness:.15,padContactLength:.3,bodyDistance:.75,height:.85}),zA(so,{position:{x:-2/2-.75/4,y:-.65,z:.15/2},width:.25,thickness:.15,padContactLength:.3,bodyDistance:.75,height:.85}),zA(so,{position:{x:-2/2-.75/4,y:.65,z:.15/2},width:.25,thickness:.15,padContactLength:.3,bodyDistance:.75,height:.85}),zA(yB,{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})]}),ELt=hLt,uLt=()=>qt(Tn,{children:[zA(yB,{center:{x:0,y:0,z:.05},width:1,length:1.45,height:.5,heightAboveSurface:0,color:"#1a1a1a",taperRatio:0,includeNotch:!1}),[0,1,2].map(r=>{const a=-.5+r*.5;return zA(Qt,{center:[-1/2+.3/2,a,.05/2],size:[.3,.2,.05]})}),[0,1,2].map(r=>{const a=-.5+r*.5;return zA(Qt,{center:[1/2-.3/2,a,.05/2],size:[.3,.2,.05]})})]}),dLt=()=>qt(Tn,{children:[zA(so,{position:{x:-2.5/2,y:0,z:.175/2},width:.3,thickness:.175,padContactLength:.3,bodyDistance:.45,height:.7}),zA(so,{rotation:Math.PI,position:{x:2.5/2,y:0,z:.175/2},width:.3,thickness:.175,padContactLength:.3,bodyDistance:.45,height:.7}),zA(Do,{color:"#222",children:zA(yB,{center:{x:0,y:0,z:0},width:1.7,length:1.25,height:.95,includeNotch:!1,taperRatio:.06,straightHeightRatio:.7,heightAboveSurface:.05})}),zA(Qt,{color:"#777",size:[1.7/3,1.25-.075,.02],center:[-.85*2/3+.035,0,.95+.05]})]}),pLt=()=>qt(Tn,{children:[zA(Qt,{color:"#ccc",size:[.4,.325,.175],center:[-1.05,0,.175/2]}),zA(Qt,{color:"#ccc",size:[.4,.325,.175],center:[1.05,0,.175/2]}),zA(Do,{color:"#222",children:qt(XQ,{children:[zA(Zi,{z:.175/2,children:zA(Qt,{size:[1.7,1.25,.175]})}),qt(xc,{children:[zA(Zi,{z:.175,children:zA(Qt,{size:[1.7,1.25,.01]})}),zA(Zi,{z:.725,children:zA(Qt,{size:[1.7-.2,1.25-.2,.01]})})]})]})}),zA(Qt,{color:"#777",size:[1.7/3,1.25-.2,.02],center:[-1.05+1.7/4.4+.2,0,.725]})]}),fLt=()=>{const s=-1.0474999999999999,r=1.775/2+.4/2-.04;return qt(Tn,{children:[zA(Qt,{color:"#ccc",size:[.4,.325,.13],center:[s,0,.13/2]}),zA(Qt,{color:"#ccc",size:[.4,.325,.13],center:[r,0,.13/2]}),zA(Do,{color:"#222",children:zA(yB,{width:1.775,length:1.25,height:.725,center:{x:0,y:0,z:0},heightAboveSurface:0,straightHeightRatio:.7,taperRatio:.06,includeNotch:!1})}),zA(Qt,{color:"#777",size:[1.775/3,1.25-.05,.02],center:[s+1.775/4.4+.2,0,.725]})]})},yLt=({pitch:t=10})=>qt(Tn,{children:[zA(Wl,{height:4,radius:.5,center:[-t/2,0,.5]}),zA($V,{radius:.5,center:[-t/2,0,2.5]}),zA(Zi,{x:-2.5,y:0,z:2.5,children:qt(aC,{rotation:[0,Math.PI/2,0],children:[zA(Wl,{height:t,radius:.5,center:[0,0,2.5]}),zA(Do,{color:"#d2b48c",children:zA(Wl,{height:5,radius:1.3,center:[0,0,2.5]})})]})}),zA(Wl,{height:4,radius:.5,center:[t/2,0,.5]}),zA($V,{radius:.5,center:[t/2,0,2.5]})]}),mLt=({bodyWidth:t=21,boardThickness:A=.5,leadWidth:e=1.6,leadLength:i=2.4,leadsPitch:n=2.54,leadsLeft:o,leadsRight:s,leadsTop:r,leadsBottom:a,innerHoles:g=!0,innerHoleEdgeDistance:c=1.61,innerHoleDiameter:I=1})=>{const l=t/2,B=A/2,C=A*1.05,Q=I/2,h=Math.max(o||0,s||0,r||0,a||0)*n||51,E=[],u=[];if(s){const w=-((s-1)/2)*n;for(let D=0;D<s;D++){const S=w+D*n;E.push({x:l-i/2,y:-S,pl:i,pw:e}),g&&u.push({x:l,y:-S},{x:l-c,y:-S})}}if(o){const w=-((o-1)/2)*n;for(let D=0;D<o;D++){const S=w+D*n;E.push({x:-l+i/2,y:-S,pl:i,pw:e}),g&&u.push({x:-l,y:-S},{x:-l+c,y:-S})}}if(r){const w=-((r-1)/2)*n;for(let D=0;D<r;D++){const S=w+D*n;E.push({x:-S,y:h/2-i/2,pl:e,pw:i}),g&&u.push({x:-S,y:h/2},{x:-S,y:h/2-c})}}if(a){const w=-((a-1)/2)*n;for(let D=0;D<a;D++){const S=w+D*n;E.push({x:-S,y:-h/2+i/2,pl:e,pw:i}),g&&u.push({x:-S,y:-h/2},{x:-S,y:-h/2+c})}}const d=zA(Do,{color:"#008080",children:qt(ym,{children:[zA(Qt,{center:[0,0,B],size:[t,h,A]}),E.map((w,D)=>zA(Qt,{center:[w.x,w.y,B],size:[w.pl+.01,w.pw+.01,C]},D))]})}),f=g&&u.map((w,D)=>zA(Wl,{color:"black",center:[w.x,w.y,B],radius:Q,height:A*1.07})),y=E.map((w,D)=>zA(Qt,{center:[w.x,w.y,B],size:[w.pl+.01,w.pw+.01,C]}));return qt(Tn,{children:[d,zA(Do,{color:"#FFD700",children:g?qt(ym,{children:[zA(XQ,{children:E.map((w,D)=>zA(Qt,{center:[w.x,w.y,B],size:[w.pl+.01,w.pw+.01,C]},D))}),f]}):y})]})},wLt=({width:t=30,height:A=22,thickness:e=1,bezelInset:i=2,bezelDepth:n=1,screenColor:o="#001414",bezelColor:s="#0f1116",screenWidth:r,screenHeight:a,offset:g})=>{const c=t,I=A,l=Math.max(e,.4),B=Math.max(Math.min(n,l),.2),C=Math.max(l-B,0),Q=Math.max(i,0),h=Math.max(r??c-Q*2,2),E=Math.max(a??I-Q*2,2),u=Math.min(Math.max(B*.6,.2),B),d=g?.x??0,f=g?.y??0,y=g?.z??0;return qt(Zi,{offset:{x:d,y:f,z:y},children:[C>0&&zA(Do,{color:s,children:zA(Qt,{size:[c,I,C],offset:[0,0,C/2]})}),zA(Do,{color:s,children:qt(ym,{children:[zA(Qt,{size:[c,I,B],offset:[0,0,C+B/2]}),zA(Qt,{size:[h,E,B+.02],offset:[0,0,C+B/2]})]})}),zA(Do,{color:o,children:zA(Qt,{size:[h,E,u],offset:[0,0,C+u/2]})})]})},DLt=({numPins:t=5,rows:A=1,p:e=2.54,id:i=1,od:n=1.5,boardThickness:o=1.6,width:s,height:r,pinRowSide:a="left",holes:g=[],holeInset:c=1,pinRowHoleEdgeToEdgeDist:I=2,female:l,nopin:B,screen:C,screenWidth:Q,screenHeight:h,screenCenterOffsetX:E,screenCenterOffsetY:u})=>{const d=C??!1,f=o/2,y=Math.ceil(t/A);let w,D;a==="left"||a==="right"?(w=(A-1)*e+2*I,D=(y-1)*e+2*I):(D=(A-1)*e+2*I,w=(y-1)*e+2*I),t===0&&(w=10,D=10);const S=Number(s??w),_=Number(r??D),b=[];let N=0,F=0,L=0,Y=0,J=0,O=0;a==="left"||a==="right"?(N=a==="left"?-S/2+I:S/2-I,F=-((y-1)/2)*e,L=0,Y=e,J=a==="left"?e:-e,O=0):(N=-((y-1)/2)*e,F=a==="top"?_/2-I:-_/2+I,L=e,Y=0,J=0,O=a==="top"?-e:e);let Z=0;for(let QA=0;QA<A&&Z<t;QA++)for(let kA=0;kA<y&&Z<t;kA++){const dA=N+kA*L+QA*J,qA=F+kA*Y+QA*O;b.push({x:dA,y:qA}),Z++}const X=[];if(g)for(const QA of g){let kA=0,dA=0;QA==="topleft"?(kA=-S/2+c,dA=_/2-c):QA==="topright"?(kA=S/2-c,dA=_/2-c):QA==="bottomleft"?(kA=-S/2+c,dA=-_/2+c):QA==="bottomright"?(kA=S/2-c,dA=-_/2+c):QA==="center"&&(kA=0,dA=0),X.push({x:kA,y:dA})}const eA=.63,gA=2,tA=6,iA=3,sA=B||l?0:gA,aA=sA+o,EA=zA(Do,{color:"#008080",children:qt(ym,{children:[zA(Qt,{center:[0,0,f+sA],size:[S,_,o]}),X.map((QA,kA)=>zA(Wl,{center:[QA.x,QA.y,f+sA],radius:n/2,height:o},`hole-${kA}`)),b.map((QA,kA)=>zA(Wl,{center:[QA.x,QA.y,f+sA],radius:n/2,height:o},`pin-hole-${kA}`))]})}),bA=b.map((QA,kA)=>zA(Do,{color:"#FFD700",children:qt(ym,{children:[zA(Wl,{center:[QA.x,QA.y,o/2+sA],radius:n/2,height:o}),zA(Wl,{center:[QA.x,QA.y,o/2+sA],radius:i/2,height:o})]})})),_A=b.map((QA,kA)=>zA(one,{x:QA.x,y:QA.y,pinThickness:eA,shortSidePinLength:iA,longSidePinLength:tA,bodyHeight:gA,flipZ:dA=>dA})),LA=b.map((QA,kA)=>zA(lne,{x:QA.x,y:QA.y,flipZ:dA=>-dA}));return qt(Tn,{children:[EA,bA,!l&&!B&&_A,l&&LA,d&&zA(wLt,{width:Q??S*.8,height:h??_*.6,offset:{x:E??0,y:u??0,z:aA}})]})},SLt=({footprint:t})=>{const A=a2t.string(t).json();switch(A.fn){case"dip":return zA(B2t,{numPins:A.num_pins,pitch:A.p,bodyWidth:A.w});case"axial":return zA(yLt,{pitch:A.p});case"tssop":return zA(Q2t,{pinCount:A.num_pins,leadLength:A.pl,leadWidth:A.pw,pitch:A.p,bodyWidth:A.w});case"msop":return zA(h2t,{pinCount:A.num_pins,padContactLength:A.pl,leadWidth:A.pw,pitch:A.p,bodyWidth:A.w});case"vssop":return zA(J2t,{pinCount:A.num_pins,leadLength:A.pl,leadWidth:A.pw,pitch:A.p,bodyWidth:A.w,bodyLength:A.h});case"qfp":return zA(p2t,{pinCount:A.num_pins,pitch:A.p,leadWidth:A.pw,padContactLength:A.pl,bodyWidth:A.w});case"tqfp":return zA(eLt,{});case"lqfp":return zA(iLt,{pinCount:A.num_pins});case"qfn":{const n=typeof A.thermalpad?.x=="number"&&typeof A.thermalpad?.y=="number";return zA(x2t,{num_pins:A.num_pins,bodyWidth:A.w,bodyLength:A.h,pitch:A.p,padLength:A.pl,padWidth:A.pw,thermalPadSize:n?{width:A.thermalpad.x,length:A.thermalpad.y}:void 0})}case"dfn":{const n=typeof A.thermalpad?.x=="number"&&typeof A.thermalpad?.y=="number";return zA(oLt,{num_pins:A.num_pins,bodyWidth:A.w,bodyLength:A.h,pitch:A.p,padLength:A.pl,padWidth:A.pw,thermalPadSize:n?{width:A.thermalpad.x,length:A.thermalpad.y}:void 0})}case"pinrow":{const n=t.match(/_rows(\d+)/),o=n&&n[1]?parseInt(n[1],10):1;if(A.male)return zA(w2t,{numberOfPins:A.num_pins,pitch:A.p,invert:A.invert,faceup:A.faceup,rows:o,smd:A.smd||A.surface_mount,rightangle:A.rightangle});if(A.female)return zA(U2t,{numberOfPins:A.num_pins,pitch:A.p,rows:o})}case"cap":switch(A.imperial){case"0402":return zA(tne,{color:"#856c4d"});case"0603":return zA(ine,{color:"#856c4d"});case"0805":return zA(nne,{color:"#856c4d"});case"0201":return zA(sne,{color:"#856c4d"});case"01005":return zA(rne,{color:"#856c4d"});case"1206":return zA(ane,{color:"#856c4d"});case"1210":return zA(gne,{color:"#856c4d"});case"2010":return zA(cne,{color:"#856c4d"});case"2512":return zA(Ine,{color:"#856c4d"})}case"sot235":return zA(k2t,{});case"sot457":return zA(BLt,{});case"sot223":return zA($2t,{});case"sot23w":return zA(v2t,{});case"sot323":return zA(tLt,{});case"sod323f":return zA(pLt,{});case"sod323fl":return zA(fLt,{});case"sot363":return zA(ELt,{});case"sot886":return zA(uLt,{});case"sot963":return zA(CLt,{});case"pushbutton":return zA(H2t,{width:A.w,length:A.h,innerDiameter:A.id});case"soic":return zA(Y2t,{pinCount:A.num_pins,leadLength:A.pl,leadWidth:A.pw,pitch:A.p,bodyWidth:A.w});case"sod523":return zA(T2t,{});case"sod882":return zA(P2t,{});case"sma":return zA(K2t,{});case"smb":return zA(q2t,{});case"smc":return zA(O2t,{});case"smf":return zA(W2t,{});case"sod123f":return zA(Z2t,{});case"sod123fl":return zA(V2t,{});case"sod123w":return zA(j2t,{});case"sod128":return zA(z2t,{});case"sod323":return zA(dLt,{});case"sod923":return zA(X2t,{});case"hc49":return zA(sLt,{});case"micromelf":return zA(rLt,{});case"minimelf":return zA(aLt,{});case"melf":return zA(gLt,{});case"ms012":return zA(cLt,{pinCount:A.num_pins,padContactLength:A.pl,leadWidth:A.pw,pitch:A.p});case"ms013":return zA(ILt,{pinCount:A.num_pins,padContactLength:A.pl,leadWidth:A.pw,pitch:A.p});case"sot723":return zA(nLt,{});case"to220":return zA(lLt,{});case"to92":return zA(QLt,{});case"stampboard":case"stampreceiver":return zA(mLt,{bodyWidth:A.w,leadsLeft:A.left,leadsRight:A.right,leadsTop:A.top,leadsBottom:A.bottom,leadsPitch:A.p,leadWidth:A.pw,leadLength:A.pl,innerHoles:A.innerhole,innerHoleEdgeDistance:A.innerholeedgedistance});case"mountedpcbmodule":{const n=A.rows??1,o=A.pinRowSide??"left",s=A.holeInset,r=A.width,a=A.height,g=A.pinrow,c=A.pinRowHoleEdgeToEdgeDist,I=Array.isArray(A.holes)?A.holes:[];return zA(DLt,{numPins:g,rows:n,p:A.p,id:A.id,od:A.od,width:r,height:a,pinRowSide:o,holes:I,holeInset:s,pinRowHoleEdgeToEdgeDist:c,nopin:A.nopin,female:A.female,screen:A.screen,screenWidth:A.screenwidth,screenHeight:A.screenheight,screenCenterOffsetX:A.screencenteroffsetx,screenCenterOffsetY:A.screencenteroffsety})}}const e=t.match(/_color\(([^)]+)\)/),i=e?e[1]:void 0;switch(A.imperial){case"0402":return zA(tne,{color:i});case"0603":return zA(ine,{color:i});case"0805":return zA(nne,{color:i});case"0201":return zA(sne,{color:i});case"01005":return zA(rne,{color:i});case"1206":return zA(ane,{color:i});case"1210":return zA(gne,{color:i});case"2010":return zA(cne,{color:i});case"2512":return zA(Ine,{color:i})}return null},bLt=t=>t&&typeof t=="object"&&"type"in t,H1=t=>{if(typeof t=="number")return t;if(typeof t=="string"){const A=/^(-?\d+(?:\.\d+)?)\s*deg$/i.exec(t);if(A)return parseFloat(A[1])*Math.PI/180;const e=Number(t);if(!Number.isNaN(e))return e}return 0},xLt=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 XD(t,A,e){const{jscad:{primitives:i,booleans:n,hulls:o,geometries:s,extrusions:r,transforms:a}}=e;if(t==null||t===!1)return[];if(Array.isArray(t))return t.flatMap(l=>XD(l,A,e));if(!bLt(t))return[];const{type:g,props:c,children:I}=t;if(g===$ie)return(I??[]).flatMap(l=>XD(l,A,e));if(g===Do){const l=c?.color;return(I??[]).flatMap(B=>XD(B,l??A,e))}if(g===Zi){const l=xLt(c?.offset??c?.center??{x:c?.x,y:c?.y,z:c?.z});return(I??[]).flatMap(C=>XD(C,A,e)).map(({geom:C,color:Q})=>({geom:a.translate(l,C),color:Q??A}))}if(g===aC){const l=Array.isArray(c?.rotation)?[H1(c.rotation[0]),H1(c.rotation[1]),H1(c.rotation[2])]:[H1(c?.x??0),H1(c?.y??0),H1(c?.z??0)];return(I??[]).flatMap(C=>XD(C,A,e)).map(({geom:C,color:Q})=>({geom:a.rotateZ(l[2],a.rotateY(l[1],a.rotateX(l[0],C))),color:Q}))}if(g===XQ||g===ym||g===xc){const l=(I??[]).flatMap(C=>XD(C,A,e)).map(C=>C.geom);if(l.length===0)return[];let B;return g===XQ?B=n.union(l):g===ym?B=n.subtract(l[0],l.slice(1)):B=o.hull(l),[{geom:B,color:A}]}if(g===CJ){const l=c?.points??[];return[{geom:s.geom2.fromPoints(l),color:A??c?.color}]}if(g===QJ){const l=(I??[]).flatMap(h=>XD(h,A,e)).map(h=>h.geom);if(l.length===0)return[];const B=l.length>1?n.union(l):l[0],C=c?.height??c?.h??1;let Q=r.extrudeLinear({height:C},B);if(Q.polygons)for(const h of Q.polygons)!h.plane||!h.vertices||h.vertices.length<3||h.vertices.reverse();return[{geom:Q,color:A??c?.color}]}if(g===Qt||g===Ane||g===Wl||g===$V||g===BJ||g===Gf){let l;if(g===Qt){const B=c?.size??[1,1,1],C=c?.offset,Q=c?.center??(C?[C[0],C[1],C[2]]:[0,0,0]);l=i.cuboid({size:B,center:Q})}else if(g===Ane){const B=c?.size??1,C=c?.offset,Q=c?.center??(C?[C[0],C[1],C[2]]:[0,0,0]);l=i.cube({size:B,center:Q})}else if(g===Wl){const B=c?.height??1,C=c?.radius??1,Q=c?.center??[0,0,0];l=i.cylinder({height:B,radius:C,center:Q})}else if(g===$V){const B=c?.radius??1,C=c?.center??[0,0,0];l=i.sphere({radius:B,center:C})}else if(g===Gf){const B=c?.height??1,C=c?.radius??1,Q=c?.roundRadius??.1,h=c?.center??[0,0,0];l=i.roundedCylinder({height:B,radius:C,roundRadius:Q,center:h})}else{const B=c?.size??[1,1,1],C=c?.roundRadius??.1,Q=c?.center??[0,0,0];l=i.roundedCuboid({size:B,roundRadius:C,center:Q})}return[{geom:l,color:A??c?.color}]}if(typeof g=="function"){const l=g(c??{});return XD(l,A,e)}return(I??[]).flatMap(l=>XD(l,A,e))}function _Lt(t,A){return{geometries:XD(t,void 0,{jscad:A})}}function Bne(t){if(t.polygons){const A=[],e=[],i=[];let n=0;for(const s of t.polygons){for(const a of s.vertices)a.index=n,A.push(a[0],a[1],a[2]),t.color&&t.color.length>=3?i.push(t.color[0],t.color[1],t.color[2]):i.push(1,1,1),n++;const r=s.vertices[0].index;for(let a=2;a<s.vertices.length;a++){const g=s.vertices[a-1].index,c=s.vertices[a].index;e.push(r,g,c)}}const o=new Ng;if(o.setAttribute("position",new bc(new Float32Array(A),3)),o.setIndex(e),i.length>0&&o.setAttribute("color",new bc(new Float32Array(i),3)),t.transforms){const s=new hs;s.fromArray(t.transforms),o.applyMatrix4(s)}return o.computeVertexNormals(),o}if(t.sides){const A=[],e=[];for(const n of t.sides)A.push(n[0][0],n[0][1],0),t.color&&t.color.length>=3?e.push(t.color[0],t.color[1],t.color[2]):e.push(1,1,1);const i=new Ng;if(i.setAttribute("position",new bc(new Float32Array(A),3)),e.length>0&&i.setAttribute("color",new bc(new Float32Array(e),3)),t.transforms){const n=new hs;n.fromArray(t.transforms),i.applyMatrix4(n)}return i}return console.error("Invalid CSG object: neither polygons nor sides found"),new Ng}function kLt(t,A){const e=cpA(SLt,{footprint:t});return _Lt(e,A)}var vLt=tg(KV()),Cne=V.createContext(null),FLt=()=>{const t=V.useContext(Cne);if(!t)throw new Error("useHover must be used within a HoverProvider");return t},MLt=({children:t})=>{const{camera:A,renderer:e}=rd(),[i,n]=V.useState([]),o=V.useMemo(()=>new mdt,[]),s=V.useMemo(()=>new fn,[]),r=V.useRef(i);r.current=i;const a=V.useRef(null),g=V.useCallback(C=>{n(Q=>[...Q,C])},[]),c=V.useCallback(C=>{if(a.current){let Q=!1,h=a.current.object;for(;h;){if(h===C){Q=!0;break}h=h.parent}Q&&(a.current.onUnhover(),a.current=null)}n(Q=>Q.filter(h=>h.object!==C))},[]),I=V.useCallback(C=>{let Q=C;for(;Q;){const h=r.current.find(E=>E.object===Q);if(h)return h;Q=Q.parent}},[]),l=V.useCallback(C=>{if(!e.domElement)return;const Q=e.domElement.getBoundingClientRect();s.x=(C.clientX-Q.left)/Q.width*2-1,s.y=-((C.clientY-Q.top)/Q.height)*2+1,o.setFromCamera(s,A);const h=r.current.map(u=>u.object);if(h.length===0){a.current&&(a.current.onUnhover(),a.current=null);return}const E=o.intersectObjects(h,!0);if(E.length>0){const u=E[0],d=I(u.object);if(d){const f={mousePosition:[u.point.x,u.point.y,u.point.z]};a.current!==d?(a.current?.onUnhover(),d.onHover(f),a.current=d):d.onHover(f)}else a.current&&(a.current.onUnhover(),a.current=null)}else a.current&&(a.current.onUnhover(),a.current=null)},[A,e,o,s,I]);V.useEffect(()=>{const C=e.domElement;return C.addEventListener("mousemove",l),()=>{C.removeEventListener("mousemove",l)}},[e,l]);const B=V.useMemo(()=>({addHoverable:g,removeHoverable:c}),[g,c]);return W.jsx(Cne.Provider,{value:B,children:t})},RLt=({children:t,object:A,onHover:e,onUnhover:i,isHovered:n})=>{const{addHoverable:o,removeHoverable:s}=FLt();return V.useEffect(()=>A?(o({object:A,onHover:e,onUnhover:i}),()=>{s(A)}):void 0,[A,e,i,o,s]),W.jsx(W.Fragment,{children:t})},wJ=RLt,NLt=({positionOffset:t,footprint:A,rotationOffset:e,onHover:i,onUnhover:n,isHovered:o,scale:s,isTranslucent:r=!1})=>{const{rootObject:a}=rd(),g=V.useMemo(()=>{if(!A)return null;const{geometries:c}=kLt(A,vLt),I=new Nf;for(const l of c.flat(1/0)){const B=l.geom;if(!B||!B.polygons&&!B.sides)continue;const C=new en(l.color);C.convertLinearToSRGB();const Q={...B,color:[C.r,C.g,C.b]},h=Bne(Q),E=new jE({vertexColors:!0,side:OQ,transparent:r,opacity:r?.5:1,depthWrite:!r}),u=new Bo(h,E);u.renderOrder=r?2:1,I.add(u)}return I},[A,r]);return V.useEffect(()=>{if(!(!g||!a))return a.add(g),()=>{a.remove(g)}},[a,g]),V.useEffect(()=>{g&&(t&&g.position.fromArray(t),e&&g.rotation.fromArray(e),s!==void 0&&g.scale.setScalar(s))},[g,t?.[0],t?.[1],t?.[2],e?.[0],e?.[1],e?.[2],s]),V.useEffect(()=>{g&&g.traverse(c=>{c instanceof Bo&&c.material instanceof jE&&(o?(c.material.emissive.setHex(255),c.material.emissiveIntensity=.2):c.material.emissiveIntensity=0)})},[o,g]),g?W.jsx(wJ,{isHovered:o,onHover:i,onUnhover:n,object:g}):null},Qne=new WeakMap,GLt=()=>{const t=new nI;return t.name="fallback-environment-map",t.mapping=jW,t},LLt=t=>{if(!t)return null;const A=t,e=Qne.get(A);if(e)return e;let i;if(t instanceof xZ){const n=new QcA(t);i=n.fromScene(Wdt(),.04).texture,n.dispose()}else i=GLt();return Qne.set(A,i),i},hne=1.25;function Ene({gltfUrl:t,position:A,rotation:e,onHover:i,onUnhover:n,isHovered:o,scale:s,isTranslucent:r=!1}){const{renderer:a,rootObject:g}=rd(),[c,I]=V.useState(null),[l,B]=V.useState(null);if(V.useEffect(()=>{if(!t)return;const C=new Vdt;let Q=!0;return C.load(t,h=>{if(!Q)return;const E=h.scene;E.traverse(u=>{if(u instanceof Bo&&u.material){const d=f=>{f.transparent=r,f.opacity=r?.5:1,f.depthWrite=!r,f.needsUpdate=!0};Array.isArray(u.material)?u.material.forEach(d):d(u.material),u.renderOrder=r?2:1}}),I(E)},void 0,h=>{if(!Q)return;console.error(`An error happened loading ${t}`,h);const E=h instanceof Error?h:new Error(`Failed to load glTF model from ${t}`);B(E)}),()=>{Q=!1}},[t,r]),V.useEffect(()=>{c&&(A&&c.position.fromArray(A),e&&c.rotation.fromArray(e),s!==void 0&&c.scale.setScalar(s))},[c,A?.[0],A?.[1],A?.[2],e?.[0],e?.[1],e?.[2],s]),V.useEffect(()=>{if(!(!g||!c))return g.add(c),()=>{g.remove(c)}},[g,c]),V.useEffect(()=>{if(!c||!a)return;const C=LLt(a);if(!C)return;const Q=[],h=E=>{E instanceof jE&&(Q.push({material:E,envMap:E.envMap??null,envMapIntensity:E.envMapIntensity??1}),E.envMap=C,(typeof E.envMapIntensity!="number"||E.envMapIntensity<hne)&&(E.envMapIntensity=hne),E.needsUpdate=!0)};return c.traverse(E=>{if(!(E instanceof Bo))return;const u=E.material;Array.isArray(u)?u.forEach(h):u&&h(u)}),()=>{Q.forEach(({material:E,envMap:u,envMapIntensity:d})=>{E.envMap=u,E.envMapIntensity=d,E.needsUpdate=!0})}},[c,a]),V.useEffect(()=>{c&&c.traverse(C=>{C instanceof Bo&&C.material instanceof jE&&(o?(C.material.emissive.setHex(255),C.material.emissiveIntensity=.2):C.material.emissiveIntensity=0)})},[o,c]),l)throw l;return c?W.jsx(wJ,{isHovered:o,onHover:i,onUnhover:n,object:c}):null}var ULt=tg(pie()),HLt=tg(KV()),YLt=({jscadPlan:t,positionOffset:A,rotationOffset:e,onHover:i,onUnhover:n,isHovered:o,scale:s,isTranslucent:r=!1})=>{const{rootObject:a}=rd(),{threeGeom:g,material:c}=V.useMemo(()=>{const l=(0,ULt.executeJscadOperations)(HLt.default,t);if(!l||!l.polygons&&!l.sides)return{threeGeom:null,material:null};const B=Bne(l),C=new jE({vertexColors:!0,side:OQ,transparent:r,opacity:r?.5:1,depthWrite:!r});return{threeGeom:B,material:C}},[t,r]),I=V.useMemo(()=>{if(!g)return null;const l=new Bo(g,c);return l.renderOrder=r?2:1,l},[g,c,r]);return V.useEffect(()=>{if(!(!I||!a))return a.add(I),()=>{a.remove(I)}},[a,I]),V.useEffect(()=>{I&&(A&&I.position.fromArray(A),e&&I.rotation.fromArray(e),s!==void 0&&I.scale.setScalar(s))},[I,A?.[0],A?.[1],A?.[2],e?.[0],e?.[1],e?.[2],s]),V.useMemo(()=>{if(c)if(o){const l=new en(c.color.getHex());c.emissive.copy(l),c.emissive.setRGB(0,0,1),c.emissiveIntensity=.2}else c.emissiveIntensity=0},[o,c]),g?W.jsx(wJ,{isHovered:o,onHover:i,onUnhover:n,object:I}):null};function JLt(t){return t.replace(/(DEF|USE)\s+([^\s]+)/g,(A,e,i)=>`${e} ${i.replace(/-/g,"_")}`)}async function TLt(t){const A=await fetch(t);if(!A.ok)throw new Error(`Failed to fetch "${t}": ${A.status} ${A.statusText}`);const e=await A.text();return new Rpt().parse(JLt(e),t)}typeof window<"u"&&!window.TSCIRCUIT_OBJ_LOADER_CACHE&&(window.TSCIRCUIT_OBJ_LOADER_CACHE=new Map);function PLt(t){const[A,e]=V.useState(null);return V.useEffect(()=>{if(!t)return;const i=t.replace(/&cachebust_origin=$/,""),n=window.TSCIRCUIT_OBJ_LOADER_CACHE;let o=!1;async function s(){try{if(i.endsWith(".wrl"))return await TLt(i);const a=await fetch(i);if(!a.ok)throw new Error(`Failed to fetch "${i}": ${a.status} ${a.statusText}`);const g=await a.text(),c=g.match(/newmtl[\s\S]*?endmtl/g),I=new Ppt;if(c?.length){const l=c.join(`
|
|
5156
|
-
`).replace(/d 0\./g,"d 1."),B=g.replace(/newmtl[\s\S]*?endmtl/g,"").replace(/^mtllib.*/gm,""),C=new vpt;C.setMaterialOptions({invertTrProperty:!0});const Q=C.parse(l.replace(/Kd\s+([\d.]+)\s+([\d.]+)\s+([\d.]+)/g,"Kd $2 $2 $2"),"embedded.mtl");return I.setMaterials(Q),I.parse(B)}return I.parse(g.replace(/^mtllib.*/gm,""))}catch(a){return a}}function r(){if(n.has(i)){const g=n.get(i);return g.result?Promise.resolve(g.result.clone()):g.promise.then(c=>c instanceof Error?c:c.clone())}const a=s().then(g=>(g instanceof Error||n.set(i,{...n.get(i),result:g}),g));return n.set(i,{promise:a,result:null}),a}return r().then(a=>{o||e(a)}).catch(a=>{console.error(a)}),()=>{o=!0}},[t]),A}function KLt({url:t,position:A,rotation:e,onHover:i,onUnhover:n,isHovered:o,scale:s,isTranslucent:r=!1}){const a=PLt(t),{rootObject:g}=rd(),c=V.useMemo(()=>a&&!(a instanceof Error)?(a.traverse(I=>{if(I instanceof Bo&&I.material){const l=B=>{B.transparent=r,B.opacity=r?.5:1,B.depthWrite=!r,B.needsUpdate=!0};Array.isArray(I.material)?I.material.forEach(l):l(I.material),I.renderOrder=r?2:1}}),a):new Bo(new vw(.5,.5,.5),new jE({transparent:!0,color:"red",opacity:.25})),[a,r]);if(V.useEffect(()=>{if(!(!g||!c))return g.add(c),()=>{g.remove(c)}},[g,c]),V.useEffect(()=>{c&&(A&&(Array.isArray(A)?c.position.fromArray(A):c.position.copy(A)),e&&(Array.isArray(e)?c.rotation.fromArray(e):c.rotation.copy(e)),s!==void 0&&c.scale.setScalar(s))},[c,Array.isArray(A)?A[0]:A?.x,Array.isArray(A)?A[1]:A?.y,Array.isArray(A)?A[2]:A?.z,Array.isArray(e)?e[0]:e?.x,Array.isArray(e)?e[1]:e?.y,Array.isArray(e)?e[2]:e?.z,s]),a instanceof Error)throw a;return W.jsx(wJ,{isHovered:o,onHover:i,onUnhover:n,object:c})}var kpA,qLt="https://cdn.jsdelivr.net/npm/occt-import-js@0.0.23/dist";function OLt(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 WLt(){if(!kpA){const t=await import("https://cdn.jsdelivr.net/npm/occt-import-js@0.0.23/+esm");kpA=OLt(t)({locateFile:e=>`${qLt}/${e}`})}return kpA}function ZLt(t){const A=new Nf;for(const e of t){const i=e.attributes.position?.array??[],n=e.index?.array??[];if(!i.length||!n.length)continue;const o=new Ng;o.setAttribute("position",new As(i,3));const s=e.attributes.normal?.array??[];s.length?o.setAttribute("normal",new As(s,3)):o.computeVertexNormals(),o.setIndex(n);const r=new jE({color:e.color?new en(e.color[0],e.color[1],e.color[2]):new en(.82,.82,.82)}),a=new Bo(o,r);a.name=e.name,A.add(a)}return A}async function VLt(t){const A=await fetch(t);if(!A.ok)throw new Error(`Failed to fetch STEP file: ${A.statusText}`);const e=await A.arrayBuffer(),n=(await WLt()).ReadStepFile(new Uint8Array(e),null);if(!n.success||!n.meshes.length)throw new Error("occt-import-js failed to convert STEP file");const o=ZLt(n.meshes),s=new OcA;return await new Promise((a,g)=>{s.parse(o,c=>{c instanceof ArrayBuffer?a(c):g(new Error("GLTFExporter did not return binary output"))},c=>{g(c)},{binary:!0})})}var une="step-glb-cache:";function jLt(t){const A=new Uint8Array(t),e=32768;let i="";for(let n=0;n<A.length;n+=e){const o=A.subarray(n,n+e);i+=String.fromCharCode(...o)}return btoa(i)}function zLt(t){const A=atob(t),e=new Uint8Array(A.length);for(let i=0;i<A.length;i+=1)e[i]=A.charCodeAt(i);return e.buffer}function XLt(t){try{const A=localStorage.getItem(`${une}${t}`);return A?zLt(A):null}catch(A){return console.warn("Failed to read STEP GLB cache",A),null}}function dne(t,A){try{const e=jLt(A);localStorage.setItem(`${une}${t}`,e)}catch(e){console.warn("Failed to write STEP GLB cache",e)}}function $Lt(){const t=globalThis;return t.stepUrlToGltfModelConversions||(t.stepUrlToGltfModelConversions={inProgress:new Map,completed:new Map}),t.stepUrlToGltfModelConversions}var AUt=({stepUrl:t,position:A,rotation:e,scale:i,onHover:n,onUnhover:o,isHovered:s,isTranslucent:r})=>{const[a,g]=V.useState(null);return V.useEffect(()=>{let c=!0,I=null,l=!0;const B=$Lt(),C=XLt(t);if(C){const E={arrayBuffer:C,blobUrl:URL.createObjectURL(new Blob([C],{type:"model/gltf-binary"}))};return B.completed.set(t,E),I=E.blobUrl,l=!1,g(E.blobUrl),()=>{c=!1,I&&l&&URL.revokeObjectURL(I)}}const Q=B.completed.get(t);if(Q)return I=Q.blobUrl,l=!1,g(Q.blobUrl),dne(t,Q.arrayBuffer),()=>{c=!1,I&&l&&URL.revokeObjectURL(I)};let h=B.inProgress.get(t);return h||(h=VLt(t).then(E=>{const u={arrayBuffer:E,blobUrl:URL.createObjectURL(new Blob([E],{type:"model/gltf-binary"}))};return B.completed.set(t,u),B.inProgress.delete(t),u}).catch(E=>{throw B.inProgress.delete(t),E}),B.inProgress.set(t,h)),h.then(E=>{c&&(I=E.blobUrl,l=!1,g(E.blobUrl),dne(t,E.arrayBuffer))}).catch(E=>{console.error("Failed to convert STEP file to GLB",E),c&&g(null)}),()=>{c=!1,I&&l&&URL.revokeObjectURL(I)}},[t]),a?W.jsx(Ene,{gltfUrl:a,position:A,rotation:e,scale:i,onHover:n,onUnhover:o,isHovered:s,isTranslucent:r}):null},eUt=(t,A)=>{if(t)return A?A(t):t},pne=(...t)=>t,vpA=class extends Qn.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}},tUt=({error:t,onError:A})=>(V.useEffect(()=>{A(t)},[t,A]),null),fne=({cad_component:t,circuitJson:A,resolveStaticAsset:e})=>{const i=mie(A),[n,o]=V.useState(!1),{visibility:s}=nM(),[r,a]=V.useState(null),g=V.useCallback(N=>{N?.mousePosition?(o(!0),a(N.mousePosition)):(o(!1),a(null))},[]),c=V.useCallback(()=>{o(!1),a(null)},[]),I=V.useMemo(()=>wn(A).source_component.getUsing({source_component_id:t.source_component_id})?.name,[A,t.source_component_id]),l=V.useMemo(()=>A.filter(F=>F.type==="pcb_plated_hole"&&F.pcb_component_id===t.pcb_component_id).length>0,[A,t.pcb_component_id]),B=V.useCallback(N=>eUt(N,e),[e]),C=B(t.model_obj_url??t.model_wrl_url??t.model_stl_url),Q=B(t.model_glb_url??t.model_gltf_url),h=B(t.model_step_url),[E,u]=V.useState(0),[d,f]=V.useState(null);V.useEffect(()=>{u(0),f(null)},[t.cad_component_id,C,Q,h]);const w=A.find(N=>N.type==="pcb_component"&&N.source_component_id===t.source_component_id)?.layer??"top",D=V.useMemo(()=>t.rotation?pne(t.rotation.x*Math.PI/180,t.rotation.y*Math.PI/180,t.rotation.z*Math.PI/180):pne(0,0,0),[t.rotation,w]),S=V.useMemo(()=>{if(!t.position)return;let N;return w==="top"?N=t.position.z:w==="bottom"?N=-(t.position.z+i):N=t.position.z,[t.position.x,t.position.y,N]},[t.position,w,i]),_=V.useMemo(()=>{const N=[];return C&&N.push(W.jsx(KLt,{url:C,position:S,rotation:D,scale:t.model_unit_to_mm_scale_factor,onHover:g,onUnhover:c,isHovered:n,isTranslucent:t.show_as_translucent_model},`${t.cad_component_id}-mixed-${C}`)),Q&&N.push(W.jsx(Ene,{gltfUrl:Q,position:S,rotation:D,scale:t.model_unit_to_mm_scale_factor,onHover:g,onUnhover:c,isHovered:n,isTranslucent:t.show_as_translucent_model},`${t.cad_component_id}-gltf-${Q}`)),h&&!t.model_jscad&&!t.footprinter_string&&N.push(W.jsx(AUt,{stepUrl:h,position:S,rotation:D,scale:t.model_unit_to_mm_scale_factor,onHover:g,onUnhover:c,isHovered:n,isTranslucent:t.show_as_translucent_model},`${t.cad_component_id}-step-${h}`)),N},[S,t.cad_component_id,t.footprinter_string,t.model_jscad,t.model_unit_to_mm_scale_factor,t.show_as_translucent_model,Q,g,c,n,D,h,C]);let b=null;if(_.length>0){if(E>=_.length){if(d)throw d;return null}b=W.jsx(vpA,{fallback:({error:N})=>W.jsx(tUt,{error:N,onError:F=>{f(F),u(L=>Math.max(L,E+1))}}),children:_[E]},`${t.cad_component_id}-fallback-${E}`)}else t.model_jscad?b=W.jsx(YLt,{jscadPlan:t.model_jscad,positionOffset:S,rotationOffset:D,scale:t.model_unit_to_mm_scale_factor,onHover:g,onUnhover:c,isHovered:n,isTranslucent:t.show_as_translucent_model},t.cad_component_id):t.footprinter_string&&(b=W.jsx(NLt,{positionOffset:S,rotationOffset:D,footprint:t.footprinter_string,scale:t.model_unit_to_mm_scale_factor,onHover:g,onUnhover:c,isHovered:n,isTranslucent:t.show_as_translucent_model}));if(t.show_as_translucent_model){if(!s.translucentModels)return null}else if(l&&!s.throughHoleModels||!l&&!s.smtModels)return null;return W.jsxs(W.Fragment,{children:[b,n&&r?W.jsx(Die,{position:r,style:{fontFamily:"sans-serif",transform:"translate3d(1rem, 1rem, 0)",backgroundColor:"white",padding:"5px",borderRadius:"3px",pointerEvents:"none",userSelect:"none",WebkitUserSelect:"none",MozUserSelect:"none",msUserSelect:"none"},children:I??"<unknown>"}):null]})},yne={version:"0.0.542"};function iUt(t){t.querySelectorAll("canvas").forEach(A=>A.remove())}var nUt=t=>{t.outputColorSpace=yw,t.toneMapping=P5A,t.toneMappingExposure=1},mne="cadViewerCameraStateSession",wne=(t,A)=>{try{const e={position:t.position.toArray(),quaternion:t.quaternion.toArray(),up:t.up.toArray(),fov:t.fov??50,target:A.target.toArray()};sessionStorage.setItem(mne,JSON.stringify(e))}catch(e){console.warn("Failed to save camera:",e)}},FpA=(t,A)=>{try{const e=sessionStorage.getItem(mne);if(!e)return!1;const i=JSON.parse(e);if(t.position.fromArray(i.position),t.quaternion.fromArray(i.quaternion),t.up.fromArray(i.up),"fov"in t){const n=t;n.fov=i.fov,n.updateProjectionMatrix?.()}return A.target.fromArray(i.target),A.update(),t.updateMatrixWorld(),!0}catch(e){return console.warn("Failed to restore camera:",e),!1}},Dne=V.createContext(void 0),oUt=({children:t,defaultTarget:A,initialCameraPosition:e})=>{const i=V.useRef(null),n=V.useRef(null),[o,s]=V.useState(null),[r,a]=V.useState("perspective"),[g,c]=V.useState(e??null),[I,l]=V.useState(new Mf(0,0,0)),B=V.useMemo(()=>{const[E,u,d]=e??[5,-5,5],f=Math.hypot(E-A.x,u-A.y,d-A.z);return f>0?f:5},[e,A]),C=V.useCallback(E=>{const u=[A.x,A.y,A.z],d=n.current,f=i.current;let y=B;switch(d&&f&&(y=d.position.distanceTo(f.target)),E){case"Top Center Angled":{const w=y/Math.sqrt(2);return{position:[A.x,A.y-w,A.z+w],target:u,up:[0,0,1]}}case"Top Down":return{position:[A.x,A.y,A.z+y],target:u,up:[0,0,1]};case"Top Left Corner":return{position:[A.x-y*.6,A.y-y*.6,A.z+y*.6],target:u,up:[0,0,1]};case"Top Right Corner":return{position:[A.x+y*.6,A.y-y*.6,A.z+y*.6],target:u,up:[0,0,1]};case"Left Sideview":return{position:[A.x-y,A.y,A.z],target:u,up:[0,0,1]};case"Right Sideview":return{position:[A.x+y,A.y,A.z],target:u,up:[0,0,1]};case"Front":return{position:[A.x,A.y-y,A.z],target:u,up:[0,0,1]};default:return null}},[B,A,n,i]),Q=V.useCallback(E=>{i.current=E},[]),h=V.useMemo(()=>({controlsRef:i,mainCameraRef:n,defaultTarget:A,baseDistance:B,controller:o,setController:s,getPresetConfig:C,handleControlsChange:Q,cameraType:r,setCameraType:a,cameraPosition:g,setCameraPosition:c,cameraRotation:I,setCameraRotation:l,saveCameraToSession:wne,loadCameraFromSession:FpA}),[A,B,o,C,Q,r,g,I]);return W.jsx(Dne.Provider,{value:h,children:t})},hk=()=>{const t=V.useContext(Dne);if(!t)throw new Error("useCameraController must be used within a CameraControllerProvider");return t},sUt=V.forwardRef(({children:t,scene:A,camera:e,style:i,onCreated:n},o)=>{const{cameraType:s}=hk(),r=V.useRef(null),[a,g]=V.useState(null),c=V.useRef([]),I=V.useRef(void 0);I.current=n;const l=V.useRef(null),B=V.useCallback(E=>{c.current.push(E)},[]),C=V.useCallback(E=>{c.current=c.current.filter(u=>u!==E)},[]),Q=V.useMemo(()=>new YF,[]);A?.up&&Q.up.set(A.up.x,A.up.y,A.up.z);const h=V.useRef(new Rg);return V.useImperativeHandle(o,()=>h.current),V.useEffect(()=>{if(!r.current)return;iUt(r.current);const E=new xZ({antialias:!0,alpha:!0});nUt(E),E.setSize(r.current.clientWidth,r.current.clientHeight),E.setPixelRatio(window.devicePixelRatio),r.current.appendChild(E.domElement);const u=r.current.clientWidth/r.current.clientHeight,d=s==="perspective"?new Wh(75,u,.1,1e3):new pY(-10*u,10*u,10,-10,-1e3,1e3);l.current?(d.position.copy(l.current.position),d.quaternion.copy(l.current.quaternion),d.up.copy(l.current.up)):(e?.up&&d.up.set(e.up[0],e.up[1],e.up[2]),e?.position&&d.position.set(e.position[0],e.position[1],e.position[2]),d.lookAt(0,0,0)),Q.add(h.current),window.__TSCIRCUIT_THREE_OBJECT=h.current,g({scene:Q,camera:d,renderer:E,rootObject:h.current,addFrameListener:B,removeFrameListener:C}),I.current?.({camera:d,renderer:E});let f;const y=new Bdt,w=()=>{const S=y.getElapsedTime(),_=y.getDelta();c.current.forEach(b=>b(S,_)),E.render(Q,d),f=requestAnimationFrame(w)};w();const D=()=>{if(r.current){const S=r.current.clientWidth/r.current.clientHeight;d instanceof Wh?d.aspect=S:d instanceof pY&&(d.left=-10*S,d.right=10*S,d.top=10,d.bottom=-10),d.updateProjectionMatrix(),E.setSize(r.current.clientWidth,r.current.clientHeight)}};return window.addEventListener("resize",D),()=>{l.current={position:d.position.clone(),quaternion:d.quaternion.clone(),up:d.up.clone()},window.removeEventListener("resize",D),cancelAnimationFrame(f),r.current&&E.domElement&&r.current.removeChild(E.domElement),E.dispose(),Q.remove(h.current),window.__TSCIRCUIT_THREE_OBJECT===h.current&&(window.__TSCIRCUIT_THREE_OBJECT=void 0)}},[Q,B,C,s]),W.jsx("div",{ref:r,style:{width:"100%",height:"100%",...i},children:a&&W.jsx(wie.Provider,{value:a,children:W.jsx(MLt,{children:t})})})}),rUt=({autoRotate:t,autoRotateSpeed:A,onStart:e,panSpeed:i,rotateSpeed:n,zoomSpeed:o,enableDamping:s,dampingFactor:r,target:a,onControlsChange:g})=>{const{camera:c,renderer:I}=rd(),l=V.useMemo(()=>!c||!I?null:new qpt(c,I.domElement),[c,I]);return V.useEffect(()=>(g?.(l??null),()=>g?.(null)),[l,g]),V.useEffect(()=>{if(!l)return;const B=()=>{g?.(l)};return l.addEventListener("change",B),()=>{l.removeEventListener("change",B)}},[l,g]),V.useEffect(()=>{l&&(l.autoRotate=t||!1,l.autoRotateSpeed=A||1,i!==void 0&&(l.panSpeed=i),n!==void 0&&(l.rotateSpeed=n),o!==void 0&&(l.zoomSpeed=o),s!==void 0&&(l.enableDamping=s),r!==void 0&&(l.dampingFactor=r),l.zoomToCursor=!0,l.mouseButtons={LEFT:W_.ROTATE,MIDDLE:W_.PAN,RIGHT:null},a&&(l.target.set(a[0],a[1],a[2]),l.update()))},[l,t,A,i,n,o,s,r,a]),V.useEffect(()=>{if(!(!l||!e))return l.addEventListener("start",e),()=>{l.removeEventListener("start",e)}},[l,e]),V.useEffect(()=>{if(l)return()=>{l.dispose()}},[l]),cJ(()=>{l?.update()},[l]),null},aUt=`
|
|
5156
|
+
`).replace(/d 0\./g,"d 1."),B=g.replace(/newmtl[\s\S]*?endmtl/g,"").replace(/^mtllib.*/gm,""),C=new vpt;C.setMaterialOptions({invertTrProperty:!0});const Q=C.parse(l.replace(/Kd\s+([\d.]+)\s+([\d.]+)\s+([\d.]+)/g,"Kd $2 $2 $2"),"embedded.mtl");return I.setMaterials(Q),I.parse(B)}return I.parse(g.replace(/^mtllib.*/gm,""))}catch(a){return a}}function r(){if(n.has(i)){const g=n.get(i);return g.result?Promise.resolve(g.result.clone()):g.promise.then(c=>c instanceof Error?c:c.clone())}const a=s().then(g=>(g instanceof Error||n.set(i,{...n.get(i),result:g}),g));return n.set(i,{promise:a,result:null}),a}return r().then(a=>{o||e(a)}).catch(a=>{console.error(a)}),()=>{o=!0}},[t]),A}function KLt({url:t,position:A,rotation:e,onHover:i,onUnhover:n,isHovered:o,scale:s,isTranslucent:r=!1}){const a=PLt(t),{rootObject:g}=rd(),c=V.useMemo(()=>a&&!(a instanceof Error)?(a.traverse(I=>{if(I instanceof Bo&&I.material){const l=B=>{B.transparent=r,B.opacity=r?.5:1,B.depthWrite=!r,B.needsUpdate=!0};Array.isArray(I.material)?I.material.forEach(l):l(I.material),I.renderOrder=r?2:1}}),a):new Bo(new vw(.5,.5,.5),new jE({transparent:!0,color:"red",opacity:.25})),[a,r]);if(V.useEffect(()=>{if(!(!g||!c))return g.add(c),()=>{g.remove(c)}},[g,c]),V.useEffect(()=>{c&&(A&&(Array.isArray(A)?c.position.fromArray(A):c.position.copy(A)),e&&(Array.isArray(e)?c.rotation.fromArray(e):c.rotation.copy(e)),s!==void 0&&c.scale.setScalar(s))},[c,Array.isArray(A)?A[0]:A?.x,Array.isArray(A)?A[1]:A?.y,Array.isArray(A)?A[2]:A?.z,Array.isArray(e)?e[0]:e?.x,Array.isArray(e)?e[1]:e?.y,Array.isArray(e)?e[2]:e?.z,s]),a instanceof Error)throw a;return W.jsx(wJ,{isHovered:o,onHover:i,onUnhover:n,object:c})}var kpA,qLt="https://cdn.jsdelivr.net/npm/occt-import-js@0.0.23/dist";function OLt(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 WLt(){if(!kpA){const t=await import("https://cdn.jsdelivr.net/npm/occt-import-js@0.0.23/+esm");kpA=OLt(t)({locateFile:e=>`${qLt}/${e}`})}return kpA}function ZLt(t){const A=new Nf;for(const e of t){const i=e.attributes.position?.array??[],n=e.index?.array??[];if(!i.length||!n.length)continue;const o=new Ng;o.setAttribute("position",new As(i,3));const s=e.attributes.normal?.array??[];s.length?o.setAttribute("normal",new As(s,3)):o.computeVertexNormals(),o.setIndex(n);const r=new jE({color:e.color?new en(e.color[0],e.color[1],e.color[2]):new en(.82,.82,.82)}),a=new Bo(o,r);a.name=e.name,A.add(a)}return A}async function VLt(t){const A=await fetch(t);if(!A.ok)throw new Error(`Failed to fetch STEP file: ${A.statusText}`);const e=await A.arrayBuffer(),n=(await WLt()).ReadStepFile(new Uint8Array(e),null);if(!n.success||!n.meshes.length)throw new Error("occt-import-js failed to convert STEP file");const o=ZLt(n.meshes),s=new OcA;return await new Promise((a,g)=>{s.parse(o,c=>{c instanceof ArrayBuffer?a(c):g(new Error("GLTFExporter did not return binary output"))},c=>{g(c)},{binary:!0})})}var une="step-glb-cache:";function jLt(t){const A=new Uint8Array(t),e=32768;let i="";for(let n=0;n<A.length;n+=e){const o=A.subarray(n,n+e);i+=String.fromCharCode(...o)}return btoa(i)}function zLt(t){const A=atob(t),e=new Uint8Array(A.length);for(let i=0;i<A.length;i+=1)e[i]=A.charCodeAt(i);return e.buffer}function XLt(t){try{const A=localStorage.getItem(`${une}${t}`);return A?zLt(A):null}catch(A){return console.warn("Failed to read STEP GLB cache",A),null}}function dne(t,A){try{const e=jLt(A);localStorage.setItem(`${une}${t}`,e)}catch(e){console.warn("Failed to write STEP GLB cache",e)}}function $Lt(){const t=globalThis;return t.stepUrlToGltfModelConversions||(t.stepUrlToGltfModelConversions={inProgress:new Map,completed:new Map}),t.stepUrlToGltfModelConversions}var AUt=({stepUrl:t,position:A,rotation:e,scale:i,onHover:n,onUnhover:o,isHovered:s,isTranslucent:r})=>{const[a,g]=V.useState(null);return V.useEffect(()=>{let c=!0,I=null,l=!0;const B=$Lt(),C=XLt(t);if(C){const E={arrayBuffer:C,blobUrl:URL.createObjectURL(new Blob([C],{type:"model/gltf-binary"}))};return B.completed.set(t,E),I=E.blobUrl,l=!1,g(E.blobUrl),()=>{c=!1,I&&l&&URL.revokeObjectURL(I)}}const Q=B.completed.get(t);if(Q)return I=Q.blobUrl,l=!1,g(Q.blobUrl),dne(t,Q.arrayBuffer),()=>{c=!1,I&&l&&URL.revokeObjectURL(I)};let h=B.inProgress.get(t);return h||(h=VLt(t).then(E=>{const u={arrayBuffer:E,blobUrl:URL.createObjectURL(new Blob([E],{type:"model/gltf-binary"}))};return B.completed.set(t,u),B.inProgress.delete(t),u}).catch(E=>{throw B.inProgress.delete(t),E}),B.inProgress.set(t,h)),h.then(E=>{c&&(I=E.blobUrl,l=!1,g(E.blobUrl),dne(t,E.arrayBuffer))}).catch(E=>{console.error("Failed to convert STEP file to GLB",E),c&&g(null)}),()=>{c=!1,I&&l&&URL.revokeObjectURL(I)}},[t]),a?W.jsx(Ene,{gltfUrl:a,position:A,rotation:e,scale:i,onHover:n,onUnhover:o,isHovered:s,isTranslucent:r}):null},eUt=(t,A)=>{if(t)return A?A(t):t},pne=(...t)=>t,vpA=class extends Qn.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}},tUt=({error:t,onError:A})=>(V.useEffect(()=>{A(t)},[t,A]),null),fne=({cad_component:t,circuitJson:A,resolveStaticAsset:e})=>{const i=mie(A),[n,o]=V.useState(!1),{visibility:s}=nM(),[r,a]=V.useState(null),g=V.useCallback(N=>{N?.mousePosition?(o(!0),a(N.mousePosition)):(o(!1),a(null))},[]),c=V.useCallback(()=>{o(!1),a(null)},[]),I=V.useMemo(()=>wn(A).source_component.getUsing({source_component_id:t.source_component_id})?.name,[A,t.source_component_id]),l=V.useMemo(()=>A.filter(F=>F.type==="pcb_plated_hole"&&F.pcb_component_id===t.pcb_component_id).length>0,[A,t.pcb_component_id]),B=V.useCallback(N=>eUt(N,e),[e]),C=B(t.model_obj_url??t.model_wrl_url??t.model_stl_url),Q=B(t.model_glb_url??t.model_gltf_url),h=B(t.model_step_url),[E,u]=V.useState(0),[d,f]=V.useState(null);V.useEffect(()=>{u(0),f(null)},[t.cad_component_id,C,Q,h]);const w=A.find(N=>N.type==="pcb_component"&&N.source_component_id===t.source_component_id)?.layer??"top",D=V.useMemo(()=>t.rotation?pne(t.rotation.x*Math.PI/180,t.rotation.y*Math.PI/180,t.rotation.z*Math.PI/180):pne(0,0,0),[t.rotation,w]),S=V.useMemo(()=>{if(!t.position)return;let N;return w==="top"?N=t.position.z:w==="bottom"?N=-(t.position.z+i):N=t.position.z,[t.position.x,t.position.y,N]},[t.position,w,i]),_=V.useMemo(()=>{const N=[];return C&&N.push(W.jsx(KLt,{url:C,position:S,rotation:D,scale:t.model_unit_to_mm_scale_factor,onHover:g,onUnhover:c,isHovered:n,isTranslucent:t.show_as_translucent_model},`${t.cad_component_id}-mixed-${C}`)),Q&&N.push(W.jsx(Ene,{gltfUrl:Q,position:S,rotation:D,scale:t.model_unit_to_mm_scale_factor,onHover:g,onUnhover:c,isHovered:n,isTranslucent:t.show_as_translucent_model},`${t.cad_component_id}-gltf-${Q}`)),h&&!t.model_jscad&&!t.footprinter_string&&N.push(W.jsx(AUt,{stepUrl:h,position:S,rotation:D,scale:t.model_unit_to_mm_scale_factor,onHover:g,onUnhover:c,isHovered:n,isTranslucent:t.show_as_translucent_model},`${t.cad_component_id}-step-${h}`)),N},[S,t.cad_component_id,t.footprinter_string,t.model_jscad,t.model_unit_to_mm_scale_factor,t.show_as_translucent_model,Q,g,c,n,D,h,C]);let b=null;if(_.length>0){if(E>=_.length){if(d)throw d;return null}b=W.jsx(vpA,{fallback:({error:N})=>W.jsx(tUt,{error:N,onError:F=>{f(F),u(L=>Math.max(L,E+1))}}),children:_[E]},`${t.cad_component_id}-fallback-${E}`)}else t.model_jscad?b=W.jsx(YLt,{jscadPlan:t.model_jscad,positionOffset:S,rotationOffset:D,scale:t.model_unit_to_mm_scale_factor,onHover:g,onUnhover:c,isHovered:n,isTranslucent:t.show_as_translucent_model},t.cad_component_id):t.footprinter_string&&(b=W.jsx(NLt,{positionOffset:S,rotationOffset:D,footprint:t.footprinter_string,scale:t.model_unit_to_mm_scale_factor,onHover:g,onUnhover:c,isHovered:n,isTranslucent:t.show_as_translucent_model}));if(t.show_as_translucent_model){if(!s.translucentModels)return null}else if(l&&!s.throughHoleModels||!l&&!s.smtModels)return null;return W.jsxs(W.Fragment,{children:[b,n&&r?W.jsx(Die,{position:r,style:{fontFamily:"sans-serif",transform:"translate3d(1rem, 1rem, 0)",backgroundColor:"white",padding:"5px",borderRadius:"3px",pointerEvents:"none",userSelect:"none",WebkitUserSelect:"none",MozUserSelect:"none",msUserSelect:"none"},children:I??"<unknown>"}):null]})},yne={version:"0.0.543"};function iUt(t){t.querySelectorAll("canvas").forEach(A=>A.remove())}var nUt=t=>{t.outputColorSpace=yw,t.toneMapping=P5A,t.toneMappingExposure=1},mne="cadViewerCameraStateSession",wne=(t,A)=>{try{const e={position:t.position.toArray(),quaternion:t.quaternion.toArray(),up:t.up.toArray(),fov:t.fov??50,target:A.target.toArray()};sessionStorage.setItem(mne,JSON.stringify(e))}catch(e){console.warn("Failed to save camera:",e)}},FpA=(t,A)=>{try{const e=sessionStorage.getItem(mne);if(!e)return!1;const i=JSON.parse(e);if(t.position.fromArray(i.position),t.quaternion.fromArray(i.quaternion),t.up.fromArray(i.up),"fov"in t){const n=t;n.fov=i.fov,n.updateProjectionMatrix?.()}return A.target.fromArray(i.target),A.update(),t.updateMatrixWorld(),!0}catch(e){return console.warn("Failed to restore camera:",e),!1}},Dne=V.createContext(void 0),oUt=({children:t,defaultTarget:A,initialCameraPosition:e})=>{const i=V.useRef(null),n=V.useRef(null),[o,s]=V.useState(null),[r,a]=V.useState("perspective"),[g,c]=V.useState(e??null),[I,l]=V.useState(new Mf(0,0,0)),B=V.useMemo(()=>{const[E,u,d]=e??[5,-5,5],f=Math.hypot(E-A.x,u-A.y,d-A.z);return f>0?f:5},[e,A]),C=V.useCallback(E=>{const u=[A.x,A.y,A.z],d=n.current,f=i.current;let y=B;switch(d&&f&&(y=d.position.distanceTo(f.target)),E){case"Top Center Angled":{const w=y/Math.sqrt(2);return{position:[A.x,A.y-w,A.z+w],target:u,up:[0,0,1]}}case"Top Down":return{position:[A.x,A.y,A.z+y],target:u,up:[0,0,1]};case"Top Left Corner":return{position:[A.x-y*.6,A.y-y*.6,A.z+y*.6],target:u,up:[0,0,1]};case"Top Right Corner":return{position:[A.x+y*.6,A.y-y*.6,A.z+y*.6],target:u,up:[0,0,1]};case"Left Sideview":return{position:[A.x-y,A.y,A.z],target:u,up:[0,0,1]};case"Right Sideview":return{position:[A.x+y,A.y,A.z],target:u,up:[0,0,1]};case"Front":return{position:[A.x,A.y-y,A.z],target:u,up:[0,0,1]};default:return null}},[B,A,n,i]),Q=V.useCallback(E=>{i.current=E},[]),h=V.useMemo(()=>({controlsRef:i,mainCameraRef:n,defaultTarget:A,baseDistance:B,controller:o,setController:s,getPresetConfig:C,handleControlsChange:Q,cameraType:r,setCameraType:a,cameraPosition:g,setCameraPosition:c,cameraRotation:I,setCameraRotation:l,saveCameraToSession:wne,loadCameraFromSession:FpA}),[A,B,o,C,Q,r,g,I]);return W.jsx(Dne.Provider,{value:h,children:t})},hk=()=>{const t=V.useContext(Dne);if(!t)throw new Error("useCameraController must be used within a CameraControllerProvider");return t},sUt=V.forwardRef(({children:t,scene:A,camera:e,style:i,onCreated:n},o)=>{const{cameraType:s}=hk(),r=V.useRef(null),[a,g]=V.useState(null),c=V.useRef([]),I=V.useRef(void 0);I.current=n;const l=V.useRef(null),B=V.useCallback(E=>{c.current.push(E)},[]),C=V.useCallback(E=>{c.current=c.current.filter(u=>u!==E)},[]),Q=V.useMemo(()=>new YF,[]);A?.up&&Q.up.set(A.up.x,A.up.y,A.up.z);const h=V.useRef(new Rg);return V.useImperativeHandle(o,()=>h.current),V.useEffect(()=>{if(!r.current)return;iUt(r.current);const E=new xZ({antialias:!0,alpha:!0});nUt(E),E.setSize(r.current.clientWidth,r.current.clientHeight),E.setPixelRatio(window.devicePixelRatio),r.current.appendChild(E.domElement);const u=r.current.clientWidth/r.current.clientHeight,d=s==="perspective"?new Wh(75,u,.1,1e3):new pY(-10*u,10*u,10,-10,-1e3,1e3);l.current?(d.position.copy(l.current.position),d.quaternion.copy(l.current.quaternion),d.up.copy(l.current.up)):(e?.up&&d.up.set(e.up[0],e.up[1],e.up[2]),e?.position&&d.position.set(e.position[0],e.position[1],e.position[2]),d.lookAt(0,0,0)),Q.add(h.current),window.__TSCIRCUIT_THREE_OBJECT=h.current,g({scene:Q,camera:d,renderer:E,rootObject:h.current,addFrameListener:B,removeFrameListener:C}),I.current?.({camera:d,renderer:E});let f;const y=new Bdt,w=()=>{const S=y.getElapsedTime(),_=y.getDelta();c.current.forEach(b=>b(S,_)),E.render(Q,d),f=requestAnimationFrame(w)};w();const D=()=>{if(r.current){const S=r.current.clientWidth/r.current.clientHeight;d instanceof Wh?d.aspect=S:d instanceof pY&&(d.left=-10*S,d.right=10*S,d.top=10,d.bottom=-10),d.updateProjectionMatrix(),E.setSize(r.current.clientWidth,r.current.clientHeight)}};return window.addEventListener("resize",D),()=>{l.current={position:d.position.clone(),quaternion:d.quaternion.clone(),up:d.up.clone()},window.removeEventListener("resize",D),cancelAnimationFrame(f),r.current&&E.domElement&&r.current.removeChild(E.domElement),E.dispose(),Q.remove(h.current),window.__TSCIRCUIT_THREE_OBJECT===h.current&&(window.__TSCIRCUIT_THREE_OBJECT=void 0)}},[Q,B,C,s]),W.jsx("div",{ref:r,style:{width:"100%",height:"100%",...i},children:a&&W.jsx(wie.Provider,{value:a,children:W.jsx(MLt,{children:t})})})}),rUt=({autoRotate:t,autoRotateSpeed:A,onStart:e,panSpeed:i,rotateSpeed:n,zoomSpeed:o,enableDamping:s,dampingFactor:r,target:a,onControlsChange:g})=>{const{camera:c,renderer:I}=rd(),l=V.useMemo(()=>!c||!I?null:new qpt(c,I.domElement),[c,I]);return V.useEffect(()=>(g?.(l??null),()=>g?.(null)),[l,g]),V.useEffect(()=>{if(!l)return;const B=()=>{g?.(l)};return l.addEventListener("change",B),()=>{l.removeEventListener("change",B)}},[l,g]),V.useEffect(()=>{l&&(l.autoRotate=t||!1,l.autoRotateSpeed=A||1,i!==void 0&&(l.panSpeed=i),n!==void 0&&(l.rotateSpeed=n),o!==void 0&&(l.zoomSpeed=o),s!==void 0&&(l.enableDamping=s),r!==void 0&&(l.dampingFactor=r),l.zoomToCursor=!0,l.mouseButtons={LEFT:W_.ROTATE,MIDDLE:W_.PAN,RIGHT:null},a&&(l.target.set(a[0],a[1],a[2]),l.update()))},[l,t,A,i,n,o,s,r,a]),V.useEffect(()=>{if(!(!l||!e))return l.addEventListener("start",e),()=>{l.removeEventListener("start",e)}},[l,e]),V.useEffect(()=>{if(l)return()=>{l.dispose()}},[l]),cJ(()=>{l?.update()},[l]),null},aUt=`
|
|
5157
5157
|
varying vec3 worldPosition;
|
|
5158
5158
|
void main() {
|
|
5159
5159
|
worldPosition = (modelMatrix * vec4(position, 1.0)).xyz;
|
|
@@ -5433,7 +5433,7 @@ You passed in: '`+this.raw_options[o]+"'");return a},e.prototype._is_valid_selec
|
|
|
5433
5433
|
`);break}}return s}}}),SAi=ha({"node_modules/pretty/index.js"(t,A){var e=pAi(),i=DAi(),n=Rhe(),o={unformatted:["code","pre","em","strong","span"],indent_inner_html:!0,indent_char:" ",indent_size:2,sep:`
|
|
5434
5434
|
`};A.exports=function(a,g){var c=n({},o,g);return a=e.html(a,c),c.ocd===!0?(c.newlines&&(c.sep=c.newlines),s(a,c)):a};function s(r,a){return i(r,a).replace(/^\s+/g,"").replace(/\s+$/g,`
|
|
5435
5435
|
`).replace(/(\s*<!--)/g,`
|
|
5436
|
-
$1`).replace(/>(\s*)(?=<!--\s*\/)/g,"> ")}}});function Nhe(t,A,e){if(!A||!e)return;let i=t.get(A);i||(i=new Set,t.set(A,i)),i.add(e);let n=t.get(e);n||(n=new Set,t.set(e,n)),n.add(A)}function bAi(t,A){if(!A.subcircuit_id&&!A.source_group_id)return[...t];let e=A;if(A.subcircuit_id){const r=new Set([A.subcircuit_id]),a=new Map,g=new Map;for(const I of t)if(I.type==="source_group"){const l=I.source_group_id,B=I.subcircuit_id;B&&g.set(l,B);const C=I.parent_source_group_id;C&&(a.has(C)||a.set(C,[]),a.get(C).push(l))}let c;for(const[I,l]of g)if(l===A.subcircuit_id){c=I;break}if(c){const I=l=>{const B=a.get(l)||[];for(const C of B){const Q=g.get(C);Q&&r.add(Q),I(C)}};I(c),e={...A,subcircuit_ids:Array.from(r)}}}const i=new Map;for(const r of t){const a=`${r.type}_id`,g=r[a];typeof g=="string"&&i.set(g,r)}const n=new Map;for(const r of t){const a=Object.entries(r);for(const[g,c]of a)if(g!=="parent_source_group_id"){if(g.endsWith("_id")&&typeof c=="string"){const I=i.get(c);Nhe(n,r,I)}else if(g.endsWith("_ids")&&Array.isArray(c)){for(const I of c)if(typeof I=="string"){const l=i.get(I);Nhe(n,r,l)}}}}const o=[],s=new Set;for(const r of t){let a=!1;(e.subcircuit_id&&"subcircuit_id"in r&&r.subcircuit_id===e.subcircuit_id||e.subcircuit_ids&&"subcircuit_id"in r&&r.subcircuit_id&&e.subcircuit_ids.includes(r.subcircuit_id)||e.source_group_id&&"source_group_id"in r&&r.source_group_id===e.source_group_id||e.source_group_id&&"member_source_group_ids"in r&&Array.isArray(r.member_source_group_ids)&&r.member_source_group_ids.includes(e.source_group_id))&&(a=!0),a&&(o.push(r),s.add(r))}for(;o.length>0;){const r=o.shift(),a=n.get(r);if(a)for(const g of a)s.has(g)||(s.add(g),o.push(g))}return t.filter(r=>s.has(r))}var _z=(t,A={})=>{const e=t;let i=e._internal_store;if(!i){i={counts:{},editCount:0},e._internal_store=i;for(const o of e){const s=o.type,r=o[`${s}_id`];if(!r)continue;const a=Number.parseInt(r.split("_").pop());Number.isNaN(a)||(i.counts[s]=Math.max(i.counts[s]??0,a))}}const n=new Proxy({},{get:(o,s)=>{if(s==="toArray")return()=>(e.editCount=i.editCount,e);if(s==="editCount")return i.editCount;if(s==="subtree")return a=>_z(bAi(e,a),A);if(s==="insert")return a=>{const g=a.type;if(!g)throw new Error("insert requires an element with a type");i.counts[g]??=-1,i.counts[g]++;const c=i.counts[g],I={...a,type:g,[`${g}_id`]:`${g}_${c}`};return A.validateInserts&&(JyA[g]??tz).parse(I),e.push(I),i.editCount++,I};if(s==="insertAll")return a=>a.map(g=>n.insert(g));const r=s;return{get:a=>e.find(g=>g.type===r&&g[`${r}_id`]===a),getUsing:a=>{const g=Object.keys(a);if(g.length!==1)throw new Error("getUsing requires exactly one key, e.g. { pcb_component_id }");const c=g[0],I=c.replace("_id",""),l=e.find(B=>B.type===I&&B[c]===a[c]);return l?e.find(B=>B.type===r&&B[`${r}_id`]===l[`${r}_id`]):null},getWhere:a=>{const g=Object.keys(a);return e.find(c=>c.type===r&&g.every(I=>c[I]===a[I]))},list:a=>{const g=a?Object.keys(a):[];return e.filter(c=>c.type===r&&g.every(I=>c[I]===a[I]))},insert:a=>{i.counts[r]??=-1,i.counts[r]++;const g=i.counts[r],c={type:r,[`${r}_id`]:`${r}_${g}`,...a};return A.validateInserts&&(JyA[r]??tz).parse(c),e.push(c),i.editCount++,c},delete:a=>{const g=e.find(c=>c[`${r}_id`]===a);g&&(e.splice(e.indexOf(g),1),i.editCount++)},update:(a,g)=>{const c=e.find(I=>I.type===r&&I[`${r}_id`]===a);return c?(Object.assign(c,g),i.editCount++,c):null},select:a=>{if(r==="source_component")return e.find(g=>g.type==="source_component"&&g.name===a.replace(/\./g,""));if(r==="pcb_port"||r==="source_port"||r==="schematic_port"){const[g,c]=a.replace(/\./g,"").split(/[\s\>]+/),I=e.find(B=>B.type==="source_component"&&B.name===g);if(!I)return null;const l=e.find(B=>B.type==="source_port"&&B.source_component_id===I.source_component_id&&(B.name===c||(B.port_hints??[]).includes(c)));if(!l)return null;if(r==="source_port")return l;if(r==="pcb_port")return e.find(B=>B.type==="pcb_port"&&B.source_port_id===l.source_port_id);if(r==="schematic_port")return e.find(B=>B.type==="schematic_port"&&B.source_port_id===l.source_port_id)}}}}});return n};_z.unparsed=_z;var rx=_z;function dmA(t){const A=t.type;return`${A}:${t[`${A}_id`]}`}var Ghe=(t,A={})=>{let e=t._internal_store_indexed;if(!e){e={counts:{},editCount:0,indexes:{}};for(const s of t){const r=s.type,a=s[`${r}_id`];if(!a)continue;const g=Number.parseInt(a.split("_").pop()||"");Number.isNaN(g)||(e.counts[r]=Math.max(e.counts[r]??0,g))}const n=A.indexConfig||{},o=e.indexes;if(n.byId&&(o.byId=new Map),n.byType&&(o.byType=new Map),n.byRelation&&(o.byRelation=new Map),n.bySubcircuit&&(o.bySubcircuit=new Map),n.byCustomField&&n.byCustomField.length>0){o.byCustomField=new Map;for(const s of n.byCustomField)o.byCustomField.set(s,new Map)}for(const s of t){if(n.byId){const r=dmA(s);o.byId.set(r,s)}if(n.byType){const r=o.byType.get(s.type)||[];r.push(s),o.byType.set(s.type,r)}if(n.byRelation){const r=Object.entries(s);for(const[a,g]of r)if(a.endsWith("_id")&&a!==`${s.type}_id`&&typeof g=="string"){const c=o.byRelation.get(a)||new Map,I=c.get(g)||[];I.push(s),c.set(g,I),o.byRelation.set(a,c)}}if(n.bySubcircuit&&"subcircuit_id"in s){const r=s.subcircuit_id;if(r&&typeof r=="string"){const a=o.bySubcircuit.get(r)||[];a.push(s),o.bySubcircuit.set(r,a)}}if(n.byCustomField&&o.byCustomField){for(const r of n.byCustomField)if(r in s){const a=s[r];if(a!==void 0&&(typeof a=="string"||typeof a=="number")){const g=String(a),c=o.byCustomField.get(r),I=c.get(g)||[];I.push(s),c.set(g,I)}}}}t._internal_store_indexed=e}return new Proxy({},{get:(n,o)=>{if(o==="toArray")return()=>(t.editCount=e.editCount,t);if(o==="editCount")return e.editCount;const s=o;return{get:r=>{const a=A.indexConfig||{};return a.byId&&e.indexes.byId?e.indexes.byId.get(`${s}:${r}`)||null:a.byType&&e.indexes.byType?(e.indexes.byType.get(s)||[]).find(c=>c[`${s}_id`]===r)||null:t.find(g=>g.type===s&&g[`${s}_id`]===r)||null},getUsing:r=>{const a=A.indexConfig||{},g=Object.keys(r);if(g.length!==1)throw new Error("getUsing requires exactly one key, e.g. { pcb_component_id }");const c=g[0],I=c.replace("_id","");if(a.byRelation&&e.indexes.byRelation){const B=e.indexes.byRelation.get(c);if(B){const Q=(B.get(r[c])||[]).find(E=>E.type===I);if(!Q)return null;const h=Q[`${s}_id`];return a.byId&&e.indexes.byId?e.indexes.byId.get(`${s}:${h}`)||null:a.byType&&e.indexes.byType?(e.indexes.byType.get(s)||[]).find(u=>u[`${s}_id`]===h)||null:t.find(E=>E.type===s&&E[`${s}_id`]===h)||null}}const l=t.find(B=>B.type===I&&B[c]===r[c]);return l&&t.find(B=>B.type===s&&B[`${s}_id`]===l[`${s}_id`])||null},getWhere:r=>{const a=A.indexConfig||{},g=Object.keys(r);if(g.length===1&&a.byCustomField&&e.indexes.byCustomField){const c=g[0],I=e.indexes.byCustomField.get(c);if(I){const l=String(r[c]);return(I.get(l)||[]).find(C=>C.type===s)||null}}if("subcircuit_id"in r&&a.bySubcircuit&&e.indexes.bySubcircuit){const c=r.subcircuit_id;return(e.indexes.bySubcircuit.get(c)||[]).find(l=>l.type===s&&g.every(B=>l[B]===r[B]))||null}return a.byType&&e.indexes.byType?(e.indexes.byType.get(s)||[]).find(I=>g.every(l=>I[l]===r[l]))||null:t.find(c=>c.type===s&&g.every(I=>c[I]===r[I]))||null},list:r=>{const a=A.indexConfig||{},g=r?Object.keys(r):[];if(g.length===0&&a.byType&&e.indexes.byType)return e.indexes.byType.get(s)||[];if(g.length===1&&g[0]==="subcircuit_id"&&a.bySubcircuit&&e.indexes.bySubcircuit){const I=r.subcircuit_id;return(e.indexes.bySubcircuit.get(I)||[]).filter(B=>B.type===s)}let c;return a.byType&&e.indexes.byType?c=e.indexes.byType.get(s)||[]:c=t.filter(I=>I.type===s),g.length>0?c.filter(I=>g.every(l=>I[l]===r[l])):c},insert:r=>{e.counts[s]??=-1,e.counts[s]++;const a=e.counts[s],g={type:s,[`${s}_id`]:`${s}_${a}`,...r};A.validateInserts&&(JyA[s]??tz).parse(g),t.push(g),e.editCount++;const c=A.indexConfig||{};if(c.byId&&e.indexes.byId){const I=dmA(g);e.indexes.byId.set(I,g)}if(c.byType&&e.indexes.byType){const I=e.indexes.byType.get(s)||[];I.push(g),e.indexes.byType.set(s,I)}if(c.byRelation&&e.indexes.byRelation){const I=Object.entries(g);for(const[l,B]of I)if(l.endsWith("_id")&&l!==`${g.type}_id`&&typeof B=="string"){const C=e.indexes.byRelation.get(l)||new Map,Q=C.get(B)||[];Q.push(g),C.set(B,Q),e.indexes.byRelation.set(l,C)}}if(c.bySubcircuit&&e.indexes.bySubcircuit&&"subcircuit_id"in g){const I=g.subcircuit_id;if(I&&typeof I=="string"){const l=e.indexes.bySubcircuit.get(I)||[];l.push(g),e.indexes.bySubcircuit.set(I,l)}}if(c.byCustomField&&e.indexes.byCustomField){for(const I of c.byCustomField)if(I in g){const l=g[I];if(l!==void 0&&(typeof l=="string"||typeof l=="number")){const B=String(l),C=e.indexes.byCustomField.get(I),Q=C.get(B)||[];Q.push(g),C.set(B,Q)}}}return g},delete:r=>{const a=A.indexConfig||{};let g;if(a.byId&&e.indexes.byId?g=e.indexes.byId.get(`${s}:${r}`):a.byType&&e.indexes.byType?g=(e.indexes.byType.get(s)||[]).find(l=>l[`${s}_id`]===r):g=t.find(I=>I[`${s}_id`]===r),!g)return;const c=t.indexOf(g);if(c>=0&&(t.splice(c,1),e.editCount++),a.byId&&e.indexes.byId){const I=dmA(g);e.indexes.byId.delete(I)}if(a.byType&&e.indexes.byType){const l=(e.indexes.byType.get(s)||[]).filter(B=>B[`${s}_id`]!==r);e.indexes.byType.set(s,l)}if(a.byRelation&&e.indexes.byRelation)for(const[I,l]of e.indexes.byRelation.entries())for(const[B,C]of l.entries()){const Q=C.filter(h=>h!==g);Q.length===0?l.delete(B):l.set(B,Q)}if(a.bySubcircuit&&e.indexes.bySubcircuit&&"subcircuit_id"in g){const I=g.subcircuit_id;if(I){const B=(e.indexes.bySubcircuit.get(I)||[]).filter(C=>C!==g);B.length===0?e.indexes.bySubcircuit.delete(I):e.indexes.bySubcircuit.set(I,B)}}if(a.byCustomField&&e.indexes.byCustomField)for(const I of e.indexes.byCustomField.values())for(const[l,B]of I.entries()){const C=B.filter(Q=>Q!==g);C.length===0?I.delete(l):I.set(l,C)}},update:(r,a)=>{const g=A.indexConfig||{};let c;if(g.byId&&e.indexes.byId?c=e.indexes.byId.get(`${s}:${r}`):g.byType&&e.indexes.byType?c=(e.indexes.byType.get(s)||[]).find(l=>l[`${s}_id`]===r):c=t.find(I=>I.type===s&&I[`${s}_id`]===r),!c)return null;if(g.byRelation&&e.indexes.byRelation){const I=Object.entries(c);for(const[l,B]of I)if(l.endsWith("_id")&&l!==`${c.type}_id`&&typeof B=="string"&&l in a&&a[l]!==B){const C=e.indexes.byRelation.get(l);if(C){const h=(C.get(B)||[]).filter(E=>E!==c);h.length===0?C.delete(B):C.set(B,h)}}}if(g.bySubcircuit&&e.indexes.bySubcircuit&&"subcircuit_id"in c&&"subcircuit_id"in a){const I=c.subcircuit_id,l=a.subcircuit_id;if(I!==l){const C=(e.indexes.bySubcircuit.get(I)||[]).filter(Q=>Q!==c);C.length===0?e.indexes.bySubcircuit.delete(I):e.indexes.bySubcircuit.set(I,C)}}if(g.byCustomField&&e.indexes.byCustomField){for(const I of g.byCustomField)if(I in c&&I in a&&c[I]!==a[I]){const l=e.indexes.byCustomField.get(I);if(l){const B=String(c[I]),Q=(l.get(B)||[]).filter(h=>h!==c);Q.length===0?l.delete(B):l.set(B,Q)}}}if(Object.assign(c,a),e.editCount++,g.byRelation&&e.indexes.byRelation){const I=Object.entries(c);for(const[l,B]of I)if(l.endsWith("_id")&&l!==`${c.type}_id`&&typeof B=="string"&&l in a){const C=e.indexes.byRelation.get(l)||new Map,Q=C.get(B)||[];Q.includes(c)||(Q.push(c),C.set(B,Q),e.indexes.byRelation.set(l,C))}}if(g.bySubcircuit&&e.indexes.bySubcircuit&&"subcircuit_id"in c&&"subcircuit_id"in a){const I=c.subcircuit_id;if(I&&typeof I=="string"){const l=e.indexes.bySubcircuit.get(I)||[];l.includes(c)||(l.push(c),e.indexes.bySubcircuit.set(I,l))}}if(g.byCustomField&&e.indexes.byCustomField){for(const I of g.byCustomField)if(I in c&&I in a){const l=c[I];if(l!==void 0&&(typeof l=="string"||typeof l=="number")){const B=String(l),C=e.indexes.byCustomField.get(I),Q=C.get(B)||[];Q.includes(c)||(Q.push(c),C.set(B,Q))}}}return c},select:r=>{if(s==="source_component")return t.find(a=>a.type==="source_component"&&a.name===r.replace(/\./g,""))||null;if(s==="pcb_port"||s==="source_port"||s==="schematic_port"){const[a,g]=r.replace(/\./g,"").split(/[\s\>]+/),c=t.find(l=>l.type==="source_component"&&l.name===a);if(!c)return null;const I=t.find(l=>l.type==="source_port"&&l.source_component_id===c.source_component_id&&(l.name===g||(l.port_hints??[]).includes(g)));if(!I)return null;if(s==="source_port")return I;if(s==="pcb_port")return t.find(l=>l.type==="pcb_port"&&l.source_port_id===I.source_port_id)||null;if(s==="schematic_port")return t.find(l=>l.type==="schematic_port"&&l.source_port_id===I.source_port_id)||null}return null}}}})};Ghe.unparsed=Ghe;var xAi=t=>{const A=t.type;return t[`${A}_id`]},Lhe=(t,A)=>({minX:Math.min(t.minX,A.minX),minY:Math.min(t.minY,A.minY),maxX:Math.max(t.maxX,A.maxX),maxY:Math.max(t.maxY,A.maxY)}),kz=(t,A,e)=>{const i=e/2;return{minX:t-i,minY:A-i,maxX:t+i,maxY:A+i}},_Ai=(t,A,e,i,n)=>{const o=e/2,s=i/2,r=n*Math.PI/180,a=Math.cos(r),g=Math.sin(r),c=[{x:-o,y:-s},{x:o,y:-s},{x:o,y:s},{x:-o,y:s}].map(I=>({x:t+I.x*a-I.y*g,y:A+I.x*g+I.y*a}));return{minX:Math.min(...c.map(I=>I.x)),minY:Math.min(...c.map(I=>I.y)),maxX:Math.max(...c.map(I=>I.x)),maxY:Math.max(...c.map(I=>I.y))}},pmA=t=>{let A=Number.POSITIVE_INFINITY,e=Number.POSITIVE_INFINITY,i=Number.NEGATIVE_INFINITY,n=Number.NEGATIVE_INFINITY;for(const o of t){if(!o.type.startsWith("pcb_"))continue;if(o.type==="pcb_smtpad"&&o.shape==="polygon"&&Array.isArray(o.points)){for(const c of o.points)A=Math.min(A,c.x),e=Math.min(e,c.y),i=Math.max(i,c.x),n=Math.max(n,c.y);continue}if(o.type==="pcb_hole"&&o.hole_shape==="circle"){const c=kz(o.x,o.y,o.hole_diameter);A=Math.min(A,c.minX),e=Math.min(e,c.minY),i=Math.max(i,c.maxX),n=Math.max(n,c.maxY);continue}if(o.type==="pcb_plated_hole"){let c;if("outer_diameter"in o&&typeof o.outer_diameter=="number"?c=kz(o.x,o.y,o.outer_diameter):"hole_diameter"in o&&typeof o.hole_diameter=="number"&&(c=kz(o.x,o.y,o.hole_diameter)),"rect_pad_width"in o&&typeof o.rect_pad_width=="number"&&"rect_pad_height"in o&&typeof o.rect_pad_height=="number"){const I=_Ai(o.x,o.y,o.rect_pad_width,o.rect_pad_height,"rect_ccw_rotation"in o?o.rect_ccw_rotation??0:0);c=c?Lhe(c,I):I}if("hole_diameter"in o&&typeof o.hole_diameter=="number"){const I=kz(o.x+("hole_offset_x"in o?o.hole_offset_x??0:0),o.y+("hole_offset_y"in o?o.hole_offset_y??0:0),o.hole_diameter);c=c?Lhe(c,I):I}if(c){A=Math.min(A,c.minX),e=Math.min(e,c.minY),i=Math.max(i,c.maxX),n=Math.max(n,c.maxY);continue}}let s,r,a,g;if("x"in o&&"y"in o&&(s=Number(o.x),r=Number(o.y)),"outer_diameter"in o&&(a=Number(o.outer_diameter),g=Number(o.outer_diameter)),"width"in o&&(a=Number(o.width)),"height"in o&&(g=Number(o.height)),"center"in o&&(s=o.center.x,r=o.center.y),s!==void 0&&r!==void 0)A=Math.min(A,s),e=Math.min(e,r),i=Math.max(i,s),n=Math.max(n,r),a!==void 0&&g!==void 0&&(A=Math.min(A,s-a/2),e=Math.min(e,r-g/2),i=Math.max(i,s+a/2),n=Math.max(n,r+g/2)),"radius"in o&&(A=Math.min(A,s-o.radius),e=Math.min(e,r-o.radius),i=Math.max(i,s+o.radius),n=Math.max(n,r+o.radius));else if(o.type==="pcb_trace")for(const c of o.route)A=Math.min(A,c.x),e=Math.min(e,c.y),i=Math.max(i,c.x),n=Math.max(n,c.y);else if(o.type==="pcb_courtyard_outline")for(const c of o.outline)A=Math.min(A,c.x),e=Math.min(e,c.y),i=Math.max(i,c.x),n=Math.max(n,c.y);else if(o.type==="pcb_courtyard_polygon")for(const c of o.points)A=Math.min(A,c.x),e=Math.min(e,c.y),i=Math.max(i,c.x),n=Math.max(n,c.y)}return{minX:A,minY:e,maxX:i,maxY:n}};function kAi(t){let A=0;if(t.length==0)return A;for(var e=0;e<t.length;e++){var i=t.charCodeAt(e);A=(A<<5)-A+i,A=A&A}return Math.abs(A)}var Uhe=[["#69d2e7","#a7dbd8","#e0e4cc","#f38630","#fa6900"],["#fe4365","#fc9d9a","#f9cdad","#c8c8a9","#83af9b"],["#ecd078","#d95b43","#c02942","#542437","#53777a"],["#556270","#4ecdc4","#c7f464","#ff6b6b","#c44d58"],["#774f38","#e08e79","#f1d4af","#ece5ce","#c5e0dc"],["#e8ddcb","#cdb380","#036564","#033649","#031634"],["#490a3d","#bd1550","#e97f02","#f8ca00","#8a9b0f"],["#594f4f","#547980","#45ada8","#9de0ad","#e5fcc2"],["#00a0b0","#6a4a3c","#cc333f","#eb6841","#edc951"],["#e94e77","#d68189","#c6a49a","#c6e5d9","#f4ead5"],["#3fb8af","#7fc7af","#dad8a7","#ff9e9d","#ff3d7f"],["#d9ceb2","#948c75","#d5ded9","#7a6a53","#99b2b7"],["#ffffff","#cbe86b","#f2e9e1","#1c140d","#cbe86b"],["#efffcd","#dce9be","#555152","#2e2633","#99173c"],["#343838","#005f6b","#008c9e","#00b4cc","#00dffc"],["#413e4a","#73626e","#b38184","#f0b49e","#f7e4be"],["#ff4e50","#fc913a","#f9d423","#ede574","#e1f5c4"],["#99b898","#fecea8","#ff847c","#e84a5f","#2a363b"],["#655643","#80bca3","#f6f7bd","#e6ac27","#bf4d28"],["#00a8c6","#40c0cb","#f9f2e7","#aee239","#8fbe00"],["#351330","#424254","#64908a","#e8caa4","#cc2a41"],["#554236","#f77825","#d3ce3d","#f1efa5","#60b99a"],["#5d4157","#838689","#a8caba","#cad7b2","#ebe3aa"],["#8c2318","#5e8c6a","#88a65e","#bfb35a","#f2c45a"],["#fad089","#ff9c5b","#f5634a","#ed303c","#3b8183"],["#ff4242","#f4fad2","#d4ee5e","#e1edb9","#f0f2eb"],["#f8b195","#f67280","#c06c84","#6c5b7b","#355c7d"],["#d1e751","#ffffff","#000000","#4dbce9","#26ade4"],["#1b676b","#519548","#88c425","#bef202","#eafde6"],["#5e412f","#fcebb6","#78c0a8","#f07818","#f0a830"],["#bcbdac","#cfbe27","#f27435","#f02475","#3b2d38"],["#452632","#91204d","#e4844a","#e8bf56","#e2f7ce"],["#eee6ab","#c5bc8e","#696758","#45484b","#36393b"],["#f0d8a8","#3d1c00","#86b8b1","#f2d694","#fa2a00"],["#2a044a","#0b2e59","#0d6759","#7ab317","#a0c55f"],["#f04155","#ff823a","#f2f26f","#fff7bd","#95cfb7"],["#b9d7d9","#668284","#2a2829","#493736","#7b3b3b"],["#bbbb88","#ccc68d","#eedd99","#eec290","#eeaa88"],["#b3cc57","#ecf081","#ffbe40","#ef746f","#ab3e5b"],["#a3a948","#edb92e","#f85931","#ce1836","#009989"],["#300030","#480048","#601848","#c04848","#f07241"],["#67917a","#170409","#b8af03","#ccbf82","#e33258"],["#aab3ab","#c4cbb7","#ebefc9","#eee0b7","#e8caaf"],["#e8d5b7","#0e2430","#fc3a51","#f5b349","#e8d5b9"],["#ab526b","#bca297","#c5ceae","#f0e2a4","#f4ebc3"],["#607848","#789048","#c0d860","#f0f0d8","#604848"],["#b6d8c0","#c8d9bf","#dadabd","#ecdbbc","#fedcba"],["#a8e6ce","#dcedc2","#ffd3b5","#ffaaa6","#ff8c94"],["#3e4147","#fffedf","#dfba69","#5a2e2e","#2a2c31"],["#fc354c","#29221f","#13747d","#0abfbc","#fcf7c5"],["#cc0c39","#e6781e","#c8cf02","#f8fcc1","#1693a7"],["#1c2130","#028f76","#b3e099","#ffeaad","#d14334"],["#a7c5bd","#e5ddcb","#eb7b59","#cf4647","#524656"],["#dad6ca","#1bb0ce","#4f8699","#6a5e72","#563444"],["#5c323e","#a82743","#e15e32","#c0d23e","#e5f04c"],["#edebe6","#d6e1c7","#94c7b6","#403b33","#d3643b"],["#fdf1cc","#c6d6b8","#987f69","#e3ad40","#fcd036"],["#230f2b","#f21d41","#ebebbc","#bce3c5","#82b3ae"],["#b9d3b0","#81bda4","#b28774","#f88f79","#f6aa93"],["#3a111c","#574951","#83988e","#bcdea5","#e6f9bc"],["#5e3929","#cd8c52","#b7d1a3","#dee8be","#fcf7d3"],["#1c0113","#6b0103","#a30006","#c21a01","#f03c02"],["#000000","#9f111b","#b11623","#292c37","#cccccc"],["#382f32","#ffeaf2","#fcd9e5","#fbc5d8","#f1396d"],["#e3dfba","#c8d6bf","#93ccc6","#6cbdb5","#1a1f1e"],["#f6f6f6","#e8e8e8","#333333","#990100","#b90504"],["#1b325f","#9cc4e4","#e9f2f9","#3a89c9","#f26c4f"],["#a1dbb2","#fee5ad","#faca66","#f7a541","#f45d4c"],["#c1b398","#605951","#fbeec2","#61a6ab","#accec0"],["#5e9fa3","#dcd1b4","#fab87f","#f87e7b","#b05574"],["#951f2b","#f5f4d7","#e0dfb1","#a5a36c","#535233"],["#8dccad","#988864","#fea6a2","#f9d6ac","#ffe9af"],["#2d2d29","#215a6d","#3ca2a2","#92c7a3","#dfece6"],["#413d3d","#040004","#c8ff00","#fa023c","#4b000f"],["#eff3cd","#b2d5ba","#61ada0","#248f8d","#605063"],["#ffefd3","#fffee4","#d0ecea","#9fd6d2","#8b7a5e"],["#cfffdd","#b4dec1","#5c5863","#a85163","#ff1f4c"],["#9dc9ac","#fffec7","#f56218","#ff9d2e","#919167"],["#4e395d","#827085","#8ebe94","#ccfc8e","#dc5b3e"],["#a8a7a7","#cc527a","#e8175d","#474747","#363636"],["#f8edd1","#d88a8a","#474843","#9d9d93","#c5cfc6"],["#046d8b","#309292","#2fb8ac","#93a42a","#ecbe13"],["#f38a8a","#55443d","#a0cab5","#cde9ca","#f1edd0"],["#a70267","#f10c49","#fb6b41","#f6d86b","#339194"],["#ff003c","#ff8a00","#fabe28","#88c100","#00c176"],["#ffedbf","#f7803c","#f54828","#2e0d23","#f8e4c1"],["#4e4d4a","#353432","#94ba65","#2790b0","#2b4e72"],["#0ca5b0","#4e3f30","#fefeeb","#f8f4e4","#a5b3aa"],["#4d3b3b","#de6262","#ffb88c","#ffd0b3","#f5e0d3"],["#fffbb7","#a6f6af","#66b6ab","#5b7c8d","#4f2958"],["#edf6ee","#d1c089","#b3204d","#412e28","#151101"],["#9d7e79","#ccac95","#9a947c","#748b83","#5b756c"],["#fcfef5","#e9ffe1","#cdcfb7","#d6e6c3","#fafbe3"],["#9cddc8","#bfd8ad","#ddd9ab","#f7af63","#633d2e"],["#30261c","#403831","#36544f","#1f5f61","#0b8185"],["#aaff00","#ffaa00","#ff00aa","#aa00ff","#00aaff"],["#d1313d","#e5625c","#f9bf76","#8eb2c5","#615375"],["#ffe181","#eee9e5","#fad3b2","#ffba7f","#ff9c97"],["#73c8a9","#dee1b6","#e1b866","#bd5532","#373b44"],["#805841","#dcf7f3","#fffcdd","#ffd8d8","#f5a2a2"]],vAi=t=>{let{x:A,y:e,width:i,height:n}={...t,...t.size,...t.center,...t.position};if(t.x1!==void 0&&t.x2!==void 0&&t.y1!==void 0&&t.y2!==void 0&&(A=(t.x1+t.x2)/2,e=(t.y1+t.y2)/2,i=Math.abs(t.x1-t.x2),n=Math.abs(t.y1-t.y2)),t.points&&Array.isArray(t.points)&&t.points.length>0){const r=t.points.map(B=>B.x),a=t.points.map(B=>B.y),g=Math.min(...r),c=Math.max(...r),I=Math.min(...a),l=Math.max(...a);A=(g+c)/2,e=(I+l)/2,i=c-g,n=l-I}const o=t.text||t.name||t.source?.text||t.source?.name||"?",s=t;return A===void 0||e===void 0?null:(i===void 0&&"outer_diameter"in t&&(i=t.outer_diameter,n=t.outer_diameter),(i===void 0||n===void 0)&&(i=.1,n=.1),{x:A,y:e,width:i,height:n,title:o,content:s,bg_color:Uhe[kAi(t.type||o)%Uhe.length]?.[4]??"#f00"})},FAi=t=>!!t,MAi=t=>{const A=t.filter(g=>g.type.startsWith("pcb_")||g.type.startsWith("schematic_")).concat(t.filter(g=>g.type==="pcb_trace"||g.type==="schematic_trace").flatMap(g=>g.route)).map(g=>vAi(g)).filter(FAi);if(A.length===0)return{center:{x:0,y:0},width:0,height:0};let e=A[0].x-A[0].width/2,i=A[0].x+A[0].width/2,n=A[0].y-A[0].height/2,o=A[0].y+A[0].height/2;for(const g of A.slice(1))e=Math.min(e,g.x-g.width/2),i=Math.max(i,g.x+g.width/2),n=Math.min(n,g.y-g.height/2),o=Math.max(o,g.y+g.height/2);const s=i-e,r=o-n;return{center:{x:e+s/2,y:n+r/2},width:s,height:r}},Cd={IS_SHOWING_PCB_GROUPS:"pcb_viewer_is_showing_pcb_groups",PCB_GROUP_VIEW_MODE:"pcb_viewer_group_view_mode",IS_SHOWING_COPPER_POURS:"pcb_viewer_is_showing_copper_pours",IS_SHOWING_COURTYARDS:"pcb_viewer_is_showing_courtyards",IS_SHOWING_GROUP_ANCHOR_OFFSETS:"pcb_viewer_is_showing_group_anchor_offsets",IS_SHOWING_SOLDER_MASK:"pcb_viewer_is_showing_solder_mask",IS_SHOWING_FABRICATION_NOTES:"pcb_viewer_is_showing_fabrication_notes",IS_SHOWING_SILKSCREEN:"pcb_viewer_is_showing_silkscreen"},GM=(t,A)=>{if(typeof window>"u")return A;try{const e=localStorage.getItem(t);return e!==null?JSON.parse(e):A}catch{return A}},LM=(t,A)=>{if(!(typeof window>"u"))try{localStorage.setItem(t,JSON.stringify(A))}catch{}},RAi=(t,A)=>{if(typeof window>"u")return A;try{const e=localStorage.getItem(t);return e!==null?JSON.parse(e):A}catch{return A}},NAi=(t,A)=>{if(!(typeof window>"u"))try{localStorage.setItem(t,JSON.stringify(A))}catch{}},GAi="named_only",LAi=(t={},A=!1)=>y4A(e=>({selected_layer:"top",pcb_viewer_id:`pcb_viewer_${Math.random().toString().slice(2,10)}`,in_edit_mode:!1,in_move_footprint_mode:!1,in_draw_trace_mode:!1,is_moving_component:!1,is_drawing_trace:!1,is_mouse_over_container:!1,is_showing_multiple_traces_length:!1,is_showing_rats_nest:!1,is_showing_autorouting:!0,is_showing_drc_errors:!0,is_showing_copper_pours:GM(Cd.IS_SHOWING_COPPER_POURS,!0),is_showing_courtyards:GM(Cd.IS_SHOWING_COURTYARDS,!0),is_showing_pcb_groups:A?!1:GM(Cd.IS_SHOWING_PCB_GROUPS,!0),is_showing_group_anchor_offsets:GM(Cd.IS_SHOWING_GROUP_ANCHOR_OFFSETS,!1),is_showing_solder_mask:GM(Cd.IS_SHOWING_SOLDER_MASK,!1),is_showing_silkscreen:GM(Cd.IS_SHOWING_SILKSCREEN,!0),is_showing_fabrication_notes:GM(Cd.IS_SHOWING_FABRICATION_NOTES,!1),pcb_group_view_mode:A?"all":RAi(Cd.PCB_GROUP_VIEW_MODE,GAi),hovered_error_id:null,...t,selectLayer:i=>e({selected_layer:i}),setEditMode:i=>e({in_edit_mode:i!=="off",in_move_footprint_mode:i==="move_footprint",in_draw_trace_mode:i==="draw_trace",is_moving_component:!1,is_drawing_trace:!1}),setIsShowingRatsNest:i=>e({is_showing_rats_nest:i}),setIsMovingComponent:i=>e({is_moving_component:i}),setIsDrawingTrace:i=>e({is_drawing_trace:i}),setIsMouseOverContainer:i=>e({is_mouse_over_container:i}),setIsShowingMultipleTracesLength:i=>e({is_showing_multiple_traces_length:i}),setIsShowingAutorouting:i=>e({is_showing_autorouting:i}),setIsShowingDrcErrors:i=>e({is_showing_drc_errors:i}),setIsShowingCopperPours:i=>{LM(Cd.IS_SHOWING_COPPER_POURS,i),e({is_showing_copper_pours:i})},setIsShowingCourtyards:i=>{LM(Cd.IS_SHOWING_COURTYARDS,i),e({is_showing_courtyards:i})},setIsShowingPcbGroups:i=>{A||(LM(Cd.IS_SHOWING_PCB_GROUPS,i),e({is_showing_pcb_groups:i}))},setIsShowingGroupAnchorOffsets:i=>{LM(Cd.IS_SHOWING_GROUP_ANCHOR_OFFSETS,i),e({is_showing_group_anchor_offsets:i})},setIsShowingSolderMask:i=>{LM(Cd.IS_SHOWING_SOLDER_MASK,i),e({is_showing_solder_mask:i})},setIsShowingSilkscreen:i=>{LM(Cd.IS_SHOWING_SILKSCREEN,i),e({is_showing_silkscreen:i})},setIsShowingFabricationNotes:i=>{LM(Cd.IS_SHOWING_FABRICATION_NOTES,i),e({is_showing_fabrication_notes:i})},setPcbGroupViewMode:i=>{A||(NAi(Cd.PCB_GROUP_VIEW_MODE,i),e({pcb_group_view_mode:i}))},setHoveredErrorId:i=>e({hovered_error_id:i})})),gl=t=>{const A=V.useContext(Hhe);return F4A(A,t)},Hhe=V.createContext(null),UAi=({children:t,initialState:A,disablePcbGroups:e})=>{const i=V.useMemo(()=>LAi(A,e),[e]);return W.jsx(Hhe.Provider,{value:i,children:t})},HAi=()=>{const t=gl(e=>e.pcb_viewer_id),A=(e,i)=>sc(e,{containerId:t,...i});return A.error=(e,i)=>sc.error(e,{containerId:t,...i}),A.promise=sc.promise,A},YAi=()=>{V.useEffect(()=>{M6t()},[]);const t=gl(A=>A.pcb_viewer_id);return W.jsx(F6t,{position:"top-center",containerId:t})};function JAi(){var t=V.useRef(!1),A=V.useCallback(function(){return t.current},[]);return V.useEffect(function(){return t.current=!0,function(){t.current=!1}},[]),A}var TAi=function(t){t===void 0&&(t={});var A=V.useState(t),e=A[0],i=A[1],n=V.useCallback(function(o){i(function(s){return Object.assign({},s,o instanceof Function?o(s):o)})},[]);return[e,n]},PAi=TAi,KAi=function(){},Yhe=typeof window<"u",qAi=CmA(gAi()),OAi=function(){var t=JAi(),A=PAi({value:void 0,error:void 0,noUserInteraction:!0}),e=A[0],i=A[1],n=V.useCallback(function(o){if(t()){var s,r;try{if(typeof o!="string"&&typeof o!="number"){var a=new Error("Cannot copy typeof "+typeof o+" to clipboard, must be a string");console.error(a),i({value:o,error:a,noUserInteraction:!0});return}else if(o===""){var a=new Error("Cannot copy empty string to clipboard.");console.error(a),i({value:o,error:a,noUserInteraction:!0});return}r=o.toString(),s=(0,qAi.default)(r),i({value:r,error:void 0,noUserInteraction:s})}catch(g){i({value:r,error:g,noUserInteraction:s})}}},[]);return[e,n]},WAi=OAi,ZAi=Yhe?V.useLayoutEffect:V.useEffect,VAi=ZAi,Jhe={x:0,y:0,width:0,height:0,top:0,left:0,bottom:0,right:0};function jAi(){var t=V.useState(null),A=t[0],e=t[1],i=V.useState(Jhe),n=i[0],o=i[1],s=V.useMemo(function(){return new window.ResizeObserver(function(r){if(r[0]){var a=r[0].contentRect,g=a.x,c=a.y,I=a.width,l=a.height,B=a.top,C=a.left,Q=a.bottom,h=a.right;o({x:g,y:c,width:I,height:l,top:B,left:C,bottom:Q,right:h})}})},[]);return VAi(function(){if(A)return s.observe(A),function(){s.disconnect()}},[A]),[e,n]}var qT=Yhe&&typeof window.ResizeObserver<"u"?jAi:function(){return[KAi,Jhe]},The=({initialTransform:t,initialTouch1:A,initialTouch2:e,finalTouch1:i,finalTouch2:n})=>{if(!i||!n)return t;const o={x:(A.x+e.x)/2,y:(A.y+e.y)/2},s={x:(i.x+n.x)/2,y:(i.y+n.y)/2},r=Math.hypot(e.x-A.x,e.y-A.y),a=Math.hypot(n.x-i.x,n.y-i.y),g=r===0?1:a/r,c=s.x-o.x,I=s.y-o.y;return An(on(c,I),on(o.x,o.y),$a(g,g),on(-o.x,-o.y),t)},zAi=(t={})=>{const A=V.useRef(null),[e,i]=V.useState(0),n=t.canvasElm??A.current,[o,s]=V.useState(t.initialTransform??xa()),[r,a]=V.useState(0),[g,c]=V.useReducer(d=>d+1,0),I=V.useCallback(d=>{t.onSetTransform&&t.onSetTransform(d),t.transform||s(d)},[t.onSetTransform,s]),l=V.useCallback(d=>{I(d),c()},[I]),B=t.transform??o,C=V.useCallback(()=>{i(Date.now())},[]),Q=V.useRef("none"),h=V.useRef(null),E=V.useRef(null);V.useEffect(()=>{const d=t.canvasElm??A.current;if(d&&!n){a(r+1);return}if(!d){const Z=setTimeout(()=>{a(r+1)},100);return()=>clearTimeout(Z)}let f=t.transform??o,y={x:0,y:0},w={x:0,y:0},D=!1;const S=Z=>({x:Z.pageX-d.getBoundingClientRect().left-window.scrollX,y:Z.pageY-d.getBoundingClientRect().top-window.scrollY});function _(Z){t.enabled!==!1&&(t.shouldDrag&&!t.shouldDrag(Z)||(y=S(Z),!(Date.now()-e<100)&&(D=!0,Z.preventDefault())))}function b(Z){if(!D||t.enabled===!1||t.shouldDrag&&!t.shouldDrag(Z))return;w=S(Z);const X=An(on(w.x-y.x,w.y-y.y),f);I(X),f=X,D=!1}function N(Z){if(S(Z),!D||t.enabled===!1||t.shouldDrag&&!t.shouldDrag(Z))return;w=S(Z);const X=An(on(w.x-y.x,w.y-y.y),f);I(X)}function F(Z){if(t.enabled===!1||t.shouldDrag&&!t.shouldDrag(Z))return;const X=S(Z),eA=An(on(X.x,X.y),$a(1-Z.deltaY/1e3,1-Z.deltaY/1e3),on(-X.x,-X.y),f);I(eA),f=eA,Z.preventDefault()}function L(Z){if(!D||t.shouldDrag&&!t.shouldDrag(Z))return;if(d){const eA=d.getBoundingClientRect();if(Z.clientX>=eA.left+10&&Z.clientX<=eA.right-10&&Z.clientY>=eA.top+10&&Z.clientY<=eA.bottom-10)return}D=!1,w=S(Z);const X=An(on(w.x-y.x,w.y-y.y),f);I(X),f=X}function Y(Z){if(Z.preventDefault(),t.enabled!==!1){if(Z.touches.length===1){Q.current="drag";const X=Z.touches[0];h.current={initialTransform:f,initialTouch:{x:X.clientX,y:X.clientY}}}else if(Z.touches.length===2){Q.current="pinch";const X=Z.touches[0],eA=Z.touches[1];E.current={initialTransform:f,initialTouch1:{x:X.clientX,y:X.clientY},initialTouch2:{x:eA.clientX,y:eA.clientY},finalTouch1:null,finalTouch2:null}}}}function J(Z){if(Z.preventDefault(),t.enabled!==!1){if(Q.current==="drag"&&Z.touches.length===1&&h.current){const X=Z.touches[0],eA={x:X.clientX,y:X.clientY},gA=eA.x-h.current.initialTouch.x,tA=eA.y-h.current.initialTouch.y,iA=An(on(gA,tA),h.current.initialTransform);I(iA)}else if(Q.current==="pinch"&&Z.touches.length===2&&E.current){const X=Z.touches[0],eA=Z.touches[1];E.current.finalTouch1={x:X.clientX,y:X.clientY},E.current.finalTouch2={x:eA.clientX,y:eA.clientY};const gA=The(E.current);I(gA)}}}function O(Z){Z.preventDefault();const X=Z.changedTouches[0];if(Q.current==="drag"&&h.current&&X){const eA={x:X.clientX,y:X.clientY},gA=eA.x-h.current.initialTouch.x,tA=eA.y-h.current.initialTouch.y,iA=An(on(gA,tA),h.current.initialTransform);I(iA),f=iA}else if(Q.current==="pinch"&&E.current){const eA=The(E.current);I(eA),f=eA}Q.current="none",h.current=null,E.current=null}return d.addEventListener("mousedown",_),d.addEventListener("mouseup",b),window.addEventListener("mousemove",N),d.addEventListener("mouseout",L),d.addEventListener("wheel",F),d.addEventListener("touchstart",Y,{passive:!1}),d.addEventListener("touchmove",J,{passive:!1}),d.addEventListener("touchend",O,{passive:!1}),d.addEventListener("touchcancel",O,{passive:!1}),()=>{d.removeEventListener("mousedown",_),d.removeEventListener("mouseup",b),window.removeEventListener("mousemove",N),d.removeEventListener("mouseout",L),d.removeEventListener("wheel",F),d.removeEventListener("touchstart",Y),d.removeEventListener("touchmove",J),d.removeEventListener("touchend",O),d.removeEventListener("touchcancel",O)}},[n,r,g,e,t.enabled,t.shouldDrag]);const u=V.useCallback(d=>Ce(B,d),[B]);return{ref:A,transform:B,applyTransformToPoint:u,setTransform:l,cancelDrag:C}},XAi=zAi;function $Ai(t){const A=new Map;let e=0;function i(n){for(const[,s]of A)if(s.has(n))return s;const o=new Set;return A.set(`connectivity_net${e++}`,o),o}for(const n of t){let o=null;for(const s of n){if(!o)o=i(s);else if(!o.has(s)){const r=i(s);if(r!==o){for(const a of r)o.add(a);A.delete(Array.from(A.entries()).find(([,a])=>a===r)[0])}}o.add(s)}}return Object.fromEntries(Array.from(A.entries()).map(([n,o])=>[n,Array.from(o)]))}var Aei=class{netMap;idToNetMap;constructor(t){this.netMap=t,this.idToNetMap={};for(const[A,e]of Object.entries(t))for(const i of e)this.idToNetMap[i]=A}addConnections(t){for(const A of t){const e=new Set;for(const n of A){const o=this.idToNetMap[n];o&&e.add(o)}let i;if(e.size===0)i=`connectivity_net${Object.keys(this.netMap).length}`,this.netMap[i]=[];else if(e.size===1)i=e.values().next().value??`connectivity_net${Object.keys(this.netMap).length}`;else{i=e.values().next().value??`connectivity_net${Object.keys(this.netMap).length}`;for(const n of e)if(n!==i){this.netMap[i].push(...this.netMap[n]),this.netMap[n]=this.netMap[i];for(const o of this.netMap[i])this.idToNetMap[o]=i}}for(const n of A)this.netMap[i].includes(n)||this.netMap[i].push(n),this.idToNetMap[n]=i}}getIdsConnectedToNet(t){return this.netMap[t]||[]}getNetConnectedToId(t){return this.idToNetMap[t]}areIdsConnected(t,A){if(t===A)return!0;const e=this.getNetConnectedToId(t);if(!e)return!1;const i=this.getNetConnectedToId(A);return i?e===i||i===t||i===t:!1}areAllIdsConnected(t){const A=this.getNetConnectedToId(t[0]);for(const e of t){const i=this.getNetConnectedToId(e);if(i===void 0||i!==A)return!1}return!0}},Phe=t=>{const A=[];for(const i of t)if(i.type==="source_trace")A.push([i.source_trace_id,...i.connected_source_port_ids??[],...i.connected_source_net_ids??[]].filter(Boolean));else if(i.type==="pcb_port"){const{pcb_port_id:n,source_port_id:o}=i;o&&n&&A.push([o,n])}else if(i.type==="pcb_smtpad"){const{pcb_smtpad_id:n,pcb_port_id:o}=i;o&&n&&A.push([n,o])}else if(i.type==="pcb_plated_hole"){const{pcb_plated_hole_id:n,pcb_port_id:o}=i;o&&n&&A.push([n,o])}else if(i.type==="pcb_trace"){const{pcb_trace_id:n,source_trace_id:o}=i,s=Array.isArray(i.route)?i.route.filter(r=>r&&r.route_type==="wire"):[];if(o&&n&&A.push([n,o]),Array.isArray(s)){const r=s.find(g=>g?.start_pcb_port_id)?.start_pcb_port_id,a=s.find(g=>g?.end_pcb_port_id)?.end_pcb_port_id;r&&n&&a&&A.push([r,n,a])}}else if(i.type==="pcb_via"){const{pcb_via_id:n,pcb_trace_id:o}=i;o&&n&&A.push([n,o])}else if(i.type==="source_component"&&i.internally_connected_source_port_ids)for(const n of i.internally_connected_source_port_ids)A.push(n);const e=$Ai(A);return new Aei(e)};function eei({primitivesWithoutInteractionMetadata:t,drawingObjectIdsWithMouseOver:A,primitiveIdsInMousedOverNet:e}){const i=[];for(const n of t){const o={...n};n?.layer==="drill"?(o.is_in_highlighted_net=!1,o.is_mouse_over=!1):A.has(n._pcb_drawing_object_id)?o.is_mouse_over=!0:n._element&&("pcb_trace_id"in n._element&&e.includes(n._element.pcb_trace_id)||"pcb_port_id"in n._element&&e.includes(n._element.pcb_port_id))?o.is_in_highlighted_net=!0:(o.is_in_highlighted_net=!1,o.is_mouse_over=!1),i.push(o)}return i}function tei(t,A){if(t.length<2)throw new Error("Stroke must have at least two points");const e=t.map(I=>Array.isArray(I)?{x:I[0],y:I[1]}:I),i=[],n=[];function o(I,l){const B=l.x-I.x,C=l.y-I.y,Q=Math.sqrt(B*B+C*C);return{x:-C/Q,y:B/Q}}function s(I,l,B,C){const Q=C/2,h={x:I.x+l.x*Q*B,y:I.y+l.y*Q*B};B>0?i.push(h):n.unshift(h)}const r=o(e[0],e[1]),a=e[0].trace_width??A;s(e[0],r,1,a),s(e[0],r,-1,a);for(let I=1;I<e.length-1;I++){const l=e[I-1],B=e[I],C=e[I+1],Q=o(l,B),h=o(B,C),E=Q.x+h.x,u=Q.y+h.y,d=Math.sqrt(E*E+u*u),f=B.trace_width??A;if(d/2>2*(f/2))s(B,Q,1,f),s(B,h,1,f),s(B,Q,-1,f),s(B,h,-1,f);else{const w=1/d;s(B,{x:E*w,y:u*w},1,f),s(B,{x:E*w,y:u*w},-1,f)}}const g=o(e[e.length-2],e[e.length-1]),c=e[e.length-1].trace_width??A;return s(e[e.length-1],g,1,c),s(e[e.length-1],g,-1,c),[...i,...n]}var iei=(t,A)=>{const{x:e,y:i,width:n,height:o,layer:s,rect_border_radius:r}=t,a=t.corner_radius??r??0,g=[{_pcb_drawing_object_id:Nm("rect"),pcb_drawing_type:"rect",x:e,y:i,w:n,h:o,layer:s||"top",_element:t,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,roundness:a,...t.shape==="rotated_rect"&&t.ccw_rotation!==void 0?{ccw_rotation:t.ccw_rotation}:{}}];if(t.is_covered_with_solder_mask){const c=s==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",l={...{_pcb_drawing_object_id:Nm("rect"),pcb_drawing_type:"rect",x:e,y:i,w:n,h:o,layer:c,_element:t,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,roundness:a,...t.shape==="rotated_rect"&&t.ccw_rotation!==void 0?{ccw_rotation:t.ccw_rotation}:{}},..."solder_mask_color"in t&&t.solder_mask_color?{color:t.solder_mask_color}:{}};g.push(l)}return g},nei=(t,A)=>{const{x:e,y:i,radius:n,layer:o}=t,s=[{_pcb_drawing_object_id:Nm("circle"),pcb_drawing_type:"circle",x:e,y:i,r:n,layer:o||"top",_element:t,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port}];if(t.is_covered_with_solder_mask){const r=o==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",a={_pcb_drawing_object_id:Nm("circle"),pcb_drawing_type:"circle",x:e,y:i,r:n,layer:r,_element:t,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,..."solder_mask_color"in t&&t.solder_mask_color?{color:t.solder_mask_color}:{}};s.push(a)}return s},oei=(t,A)=>{const{layer:e,points:i}=t,n=[{_pcb_drawing_object_id:Nm("polygon"),pcb_drawing_type:"polygon",points:fmA(i),layer:e||"top",_element:t,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port}];if(t.is_covered_with_solder_mask){const o=e==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",s={_pcb_drawing_object_id:Nm("polygon"),pcb_drawing_type:"polygon",points:fmA(i),layer:o,_element:t,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,..."solder_mask_color"in t&&t.solder_mask_color?{color:t.solder_mask_color}:{}};n.push(s)}return n},sei=(t,A)=>{const{x:e,y:i,width:n,height:o,layer:s}=t,r=[{_pcb_drawing_object_id:Nm("pill"),pcb_drawing_type:"pill",x:e,y:i,w:n,h:o,layer:s||"top",_element:t,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port}];if(t.is_covered_with_solder_mask){const a=s==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",g={_pcb_drawing_object_id:Nm("pill"),pcb_drawing_type:"pill",x:e,y:i,w:n,h:o,layer:a,_element:t,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,..."solder_mask_color"in t&&t.solder_mask_color?{color:t.solder_mask_color}:{}};r.push(g)}return r},rei=(t,A)=>{const{x:e,y:i,width:n,height:o,layer:s,ccw_rotation:r}=t,a=[{_pcb_drawing_object_id:Nm("pill"),pcb_drawing_type:"pill",x:e,y:i,w:n,h:o,layer:s||"top",_element:t,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,ccw_rotation:r}];if(t.is_covered_with_solder_mask){const g=s==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",c={_pcb_drawing_object_id:Nm("pill"),pcb_drawing_type:"pill",x:e,y:i,w:n,h:o,layer:g,_element:t,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,ccw_rotation:r,..."solder_mask_color"in t&&t.solder_mask_color?{color:t.solder_mask_color}:{}};a.push(c)}return a},aei=(t,A)=>{const{_parent_pcb_component:e,_parent_source_component:i}=A,n=t,o=typeof n.font_size=="string"?Et.parse(n.font_size):n.font_size??.2;let s;return n.knockout_padding&&(s={left:typeof n.knockout_padding.left=="string"?Et.parse(n.knockout_padding.left):n.knockout_padding.left,top:typeof n.knockout_padding.top=="string"?Et.parse(n.knockout_padding.top):n.knockout_padding.top,bottom:typeof n.knockout_padding.bottom=="string"?Et.parse(n.knockout_padding.bottom):n.knockout_padding.bottom,right:typeof n.knockout_padding.right=="string"?Et.parse(n.knockout_padding.right):n.knockout_padding.right}),[{_pcb_drawing_object_id:Nm("text"),pcb_drawing_type:"text",x:n.anchor_position.x,y:n.anchor_position.y,layer:n.layer,align:n.anchor_alignment??"center",text:n.text,size:o,ccw_rotation:n.ccw_rotation,is_mirrored:n.is_mirrored,is_knockout:n.is_knockout,knockout_padding:s,_element:t,_parent_pcb_component:e,_parent_source_component:i}]},TI=0,Nm=t=>`${t}_${TI++}`,fmA=t=>(t??[]).map(A=>({x:Et.parse(A.x),y:Et.parse(A.y)})),gei=(t,A)=>{const e="pcb_component_id"in t?A.find(s=>s.type==="pcb_component"&&s.pcb_component_id===t.pcb_component_id):void 0,i=e&&"source_component_id"in e?A.find(s=>s.type==="source_component"&&s.source_component_id===e.source_component_id):void 0,n="source_port_id"in t?t.source_port_id:"pcb_port_id"in t?rx(A).pcb_port.get(t.pcb_port_id)?.source_port_id:void 0,o=n?A.find(s=>s.type==="source_port"&&s.source_port_id===n):void 0;switch(t.type){case"pcb_smtpad":{const s={_parent_pcb_component:e,_parent_source_component:i,_source_port:o};return t.shape==="rect"||t.shape==="rotated_rect"?iei(t,s):t.shape==="circle"?nei(t,s):t.shape==="polygon"?oei(t,s):t.shape==="pill"?sei(t,s):t.shape==="rotated_pill"?rei(t,s):[]}case"pcb_trace":{const s=[];if(t.route_thickness_mode==="interpolated"){const g=t.route.map(l=>({x:l.x,y:l.y,trace_width:l.route_type==="wire"?l.width:.5})),c=tei(g,.5),I=t.route[0].layer;return s.push({_pcb_drawing_object_id:`polygon_${TI++}`,_element:t,pcb_drawing_type:"polygon",points:c,layer:I}),t.route.forEach(l=>{l.route_type==="via"&&s.push({_pcb_drawing_object_id:`circle_${TI++}`,_element:t,pcb_drawing_type:"circle",x:l.x,y:l.y,r:l.outer_diameter/2,layer:l.from_layer})}),s}let r=null,a=null;for(const g of t.route)g.route_type==="wire"&&(r!==null&&a!==null&&s.push({_pcb_drawing_object_id:`line_${TI++}`,_element:t,pcb_drawing_type:"line",x1:r,y1:a,x2:g.x,y2:g.y,width:g.width,squareCap:!1,layer:g.layer}),r=g.x,a=g.y);return s}case"pcb_via":{const{x:s,y:r,outer_diameter:a,hole_diameter:g}=t,c=t.from_layer,I=t.to_layer,l=t.layers,B=[];c&&I?B.push(c,I):l&&Array.isArray(l)?B.push(...l):B.push("top","bottom");const C=[];for(const Q of B)C.push({_pcb_drawing_object_id:`circle_${TI++}`,pcb_drawing_type:"circle",x:s,y:r,r:a/2,layer:Q,_element:t,_parent_pcb_component:e,_parent_source_component:i});return C.push({_pcb_drawing_object_id:`circle_${TI++}`,pcb_drawing_type:"circle",x:s,y:r,r:g/2,layer:"drill",_element:t}),C}case"pcb_plated_hole":if(t.shape==="circle"){const{x:s,y:r,hole_diameter:a,outer_diameter:g}=t;return[{_pcb_drawing_object_id:`circle_${TI++}`,pcb_drawing_type:"circle",x:s,y:r,r:g/2,layer:"top",_element:t,_parent_pcb_component:e,_parent_source_component:i,_source_port:o},{_pcb_drawing_object_id:`circle_${TI++}`,pcb_drawing_type:"circle",x:s,y:r,r:a/2,layer:"drill",_element:t}]}else if(t.shape==="oval"){const{x:s,y:r,outer_height:a,outer_width:g,hole_height:c,hole_width:I}=t;return[{_pcb_drawing_object_id:`oval_${TI++}`,pcb_drawing_type:"oval",x:s,y:r,rX:g/2,rY:a/2,layer:"top",_element:t,_parent_pcb_component:e,_parent_source_component:i,_source_port:o},{_pcb_drawing_object_id:`oval_${TI++}`,_element:t,pcb_drawing_type:"oval",x:s,y:r,rX:I/2,rY:c/2,layer:"drill"}]}else if(t.shape==="pill"){const{x:s,y:r,outer_height:a,outer_width:g,hole_height:c,hole_width:I}=t;return[{_pcb_drawing_object_id:`pill_${TI++}`,pcb_drawing_type:"pill",x:s,y:r,w:g,h:a,layer:"top",_element:t,_parent_pcb_component:e,_parent_source_component:i,_source_port:o,ccw_rotation:t.ccw_rotation},{_pcb_drawing_object_id:`pill_${TI++}`,_element:t,pcb_drawing_type:"pill",x:s,y:r,w:I,h:c,layer:"drill",ccw_rotation:t.ccw_rotation}]}else if(t.shape==="circular_hole_with_rect_pad"){const{x:s,y:r,hole_diameter:a,rect_pad_width:g,rect_pad_height:c,rect_border_radius:I,hole_offset_x:l,hole_offset_y:B}=t,C=Et.parse(l??0),Q=Et.parse(B??0);return[{_pcb_drawing_object_id:`rect_${TI++}`,pcb_drawing_type:"rect",x:s,y:r,w:g,h:c,layer:"top",_element:t,_parent_pcb_component:e,_parent_source_component:i,_source_port:o,roundness:I},{_pcb_drawing_object_id:`rect_${TI++}`,pcb_drawing_type:"rect",x:s,y:r,w:g,h:c,layer:"bottom",_element:t,_parent_pcb_component:e,_parent_source_component:i,_source_port:o,roundness:I},{_pcb_drawing_object_id:`circle_${TI++}`,_element:t,pcb_drawing_type:"circle",x:s+C,y:r+Q,r:a/2,layer:"drill"}]}else if(t.shape==="pill_hole_with_rect_pad"){const{x:s,y:r,hole_width:a,hole_height:g,rect_pad_width:c,rect_pad_height:I,rect_border_radius:l}=t;return[{_pcb_drawing_object_id:`rect_${TI++}`,pcb_drawing_type:"rect",x:s,y:r,w:c,h:I,layer:"top",_element:t,_parent_pcb_component:e,_parent_source_component:i,_source_port:o,roundness:l},{_pcb_drawing_object_id:`rect_${TI++}`,pcb_drawing_type:"rect",x:s,y:r,w:c,h:I,layer:"bottom",_element:t,_parent_pcb_component:e,_parent_source_component:i,_source_port:o,roundness:l},{_pcb_drawing_object_id:`pill_${TI++}`,_element:t,pcb_drawing_type:"pill",x:s,y:r,w:a,h:g,layer:"drill"}]}else if(t.shape==="rotated_pill_hole_with_rect_pad"){const{x:s,y:r,hole_width:a,hole_height:g,hole_ccw_rotation:c,rect_pad_width:I,rect_pad_height:l,rect_ccw_rotation:B,rect_border_radius:C}=t;return[{_pcb_drawing_object_id:`rect_${TI++}`,pcb_drawing_type:"rect",x:s,y:r,w:I,h:l,layer:"top",_element:t,_parent_pcb_component:e,_parent_source_component:i,_source_port:o,ccw_rotation:B,roundness:C},{_pcb_drawing_object_id:`rect_${TI++}`,pcb_drawing_type:"rect",x:s,y:r,w:I,h:l,layer:"bottom",_element:t,_parent_pcb_component:e,_parent_source_component:i,_source_port:o,ccw_rotation:B,roundness:C},{_pcb_drawing_object_id:`pill_${TI++}`,_element:t,pcb_drawing_type:"pill",x:s,y:r,w:a,h:g,layer:"drill",ccw_rotation:c}]}else if(t.shape==="hole_with_polygon_pad"){const{x:s,y:r,pad_outline:a,hole_shape:g,hole_diameter:c,hole_width:I,hole_height:l,layers:B,hole_offset_x:C,hole_offset_y:Q}=t,h=Et.parse(C??0),E=Et.parse(Q??0),u=a,d=[];if(u&&Array.isArray(u)){const w=fmA(u).map(D=>({x:D.x+s,y:D.y+r}));for(const D of B||["top","bottom"])d.push({_pcb_drawing_object_id:`polygon_${TI++}`,pcb_drawing_type:"polygon",points:w,layer:D,_element:t,_parent_pcb_component:e,_parent_source_component:i,_source_port:o})}const f={x:s+h,y:r+E},y=[];return g==="circle"?y.push({_pcb_drawing_object_id:`circle_${TI++}`,pcb_drawing_type:"circle",x:f.x,y:f.y,r:(c??0)/2,layer:"drill",_element:t,_parent_pcb_component:e,_parent_source_component:i}):g==="oval"?y.push({_pcb_drawing_object_id:`oval_${TI++}`,pcb_drawing_type:"oval",x:f.x,y:f.y,rX:(I??0)/2,rY:(l??0)/2,layer:"drill",_element:t,_parent_pcb_component:e,_parent_source_component:i}):(g==="pill"||g==="rotated_pill")&&y.push({_pcb_drawing_object_id:`pill_${TI++}`,pcb_drawing_type:"pill",x:f.x,y:f.y,w:I??0,h:l??0,layer:"drill",_element:t,_parent_pcb_component:e,_parent_source_component:i,ccw_rotation:t.ccw_rotation}),[...d,...y]}else return[];case"pcb_copper_text":return aei(t,{_parent_pcb_component:e,_parent_source_component:i})}return[]},yn={board:{anchor:"rgb(255, 38, 226)",aux_items:"rgb(255, 255, 255)",b_adhes:"rgb(0, 0, 132)",b_crtyd:"rgb(38, 233, 255)",b_fab:"rgb(88, 93, 132)",b_mask:"rgba(2, 255, 238, 0.400)",b_paste:"rgb(0, 194, 194)",b_silks:"rgb(242, 237, 161)",background:"rgb(0, 16, 35)",cmts_user:"rgb(89, 148, 220)",copper:{b:"rgb(77, 127, 196)",f:"rgb(200, 52, 52)",in1:"rgb(127, 200, 127)",in10:"rgb(237, 124, 51)",in11:"rgb(91, 195, 235)",in12:"rgb(247, 111, 142)",in13:"rgb(167, 165, 198)",in14:"rgb(40, 204, 217)",in15:"rgb(232, 178, 167)",in16:"rgb(242, 237, 161)",in17:"rgb(237, 124, 51)",in18:"rgb(91, 195, 235)",in19:"rgb(247, 111, 142)",in2:"rgb(206, 125, 44)",in20:"rgb(167, 165, 198)",in21:"rgb(40, 204, 217)",in22:"rgb(232, 178, 167)",in23:"rgb(242, 237, 161)",in24:"rgb(237, 124, 51)",in25:"rgb(91, 195, 235)",in26:"rgb(247, 111, 142)",in27:"rgb(167, 165, 198)",in28:"rgb(40, 204, 217)",in29:"rgb(232, 178, 167)",in3:"rgb(79, 203, 203)",in30:"rgb(242, 237, 161)",in4:"rgb(219, 98, 139)",in5:"rgb(167, 165, 198)",in6:"rgb(40, 204, 217)",in7:"rgb(232, 178, 167)",in8:"rgb(242, 237, 161)",in9:"rgb(141, 203, 129)"},cursor:"rgb(255, 255, 255)",drc:"rgb(194, 194, 194)",drc_error:"rgba(215, 91, 107, 0.800)",drc_exclusion:"rgb(255, 255, 255)",drc_warning:"rgba(255, 208, 66, 0.902)",dwgs_user:"rgb(194, 194, 194)",eco1_user:"rgb(180, 219, 210)",eco2_user:"rgb(216, 200, 82)",edge_cuts:"rgb(208, 210, 205)",f_adhes:"rgb(132, 0, 132)",f_crtyd:"rgb(255, 0, 245)",f_fab:"rgb(175, 175, 175)",f_mask:"rgba(216, 100, 255, 0.400)",f_paste:"rgba(180, 160, 154, 0.902)",f_silks:"rgb(242, 237, 161)",footprint_text_back:"rgb(0, 0, 132)",footprint_text_front:"rgb(194, 194, 194)",footprint_text_invisible:"rgb(132, 132, 132)",grid:"rgb(132, 132, 132)",grid_axes:"rgb(194, 194, 194)",margin:"rgb(255, 38, 226)",microvia:"rgb(0, 132, 132)",no_connect:"rgb(0, 0, 132)",pad_back:"rgb(77, 127, 196)",pad_front:"rgb(200, 52, 52)",pad_plated_hole:"rgb(194, 194, 0)",pad_through_hole:"rgb(227, 183, 46)",plated_hole:"rgb(26, 196, 210)",ratsnest:"rgba(245, 255, 213, 0.702)",select_overlay:"rgb(4, 255, 67)",soldermaskWithCopper:{top:"rgb(18, 82, 50)",bottom:"rgb(77, 127, 196)"},soldermask:{top:"rgb(12, 55, 33)",bottom:"rgb(12, 55, 33)"},through_via:"rgb(236, 236, 236)",user_1:"rgb(194, 194, 194)",user_2:"rgb(89, 148, 220)",user_3:"rgb(180, 219, 210)",user_4:"rgb(216, 200, 82)",user_5:"rgb(194, 194, 194)",user_6:"rgb(89, 148, 220)",user_7:"rgb(180, 219, 210)",user_8:"rgb(216, 200, 82)",user_9:"rgb(232, 178, 167)",via_blind_buried:"rgb(187, 151, 38)",via_hole:"rgb(227, 183, 46)",via_micro:"rgb(0, 132, 132)",via_through:"rgb(236, 236, 236)",worksheet:"rgb(200, 114, 171)"}},Pf=(t,A=1)=>{if(Math.abs(t.a)!==Math.abs(t.d))throw new Error("Cannot scale non-uniformly");return A*Math.abs(t.a)},kc={elementOverlay:40,dimensionOverlay:40,editTraceHintOverlay:40,errorOverlay:40,pcbGroupOverlay:35,ratsNestOverlay:30,toolbarOverlay:70,warnings:30,topLayer:20,clickToInteractOverlay:100},vz={red:"red",black:"black",green:"green",board:"rgb(255, 255, 255)",other:"#eee",top:yn.board.copper.f,inner1:yn.board.copper.in1,inner2:yn.board.copper.in2,inner3:yn.board.copper.in3,inner4:yn.board.copper.in4,inner5:yn.board.copper.in5,inner6:yn.board.copper.in6,inner7:yn.board.copper.in7,inner8:yn.board.copper.in8,bottom:yn.board.copper.b,drill:yn.board.anchor,keepout:yn.board.background,tkeepout:yn.board.b_crtyd,tplace:yn.board.b_silks,top_courtyard:yn.board.f_crtyd,bottom_courtyard:yn.board.b_crtyd,top_silkscreen:yn.board.f_silks,bottom_silkscreen:yn.board.b_silks,top_fabrication:yn.board.f_fab,bottom_fabrication:yn.board.b_fab,soldermask_top:yn.board.soldermask.top,soldermask_bottom:yn.board.soldermask.bottom,soldermask_with_copper_top:yn.board.soldermaskWithCopper.top,soldermask_with_copper_bottom:yn.board.soldermaskWithCopper.bottom,bottom_notes:yn.board.user_2,top_notes:yn.board.user_2,...yn.board},cei=["board","inner6","inner5","inner4","inner3","inner2","inner1","bottom","soldermask_bottom","bottom_silkscreen","top","soldermask_top","bottom_courtyard","bottom_fabrication","top_courtyard","top_fabrication","edge_cuts","top_silkscreen"],Iei=class{canvasLayerMap;ctxLayerMap;aperture;transform;foregroundLayer="top";lastPoint;constructor(t){this.canvasLayerMap=t,this.ctxLayerMap=Object.fromEntries(Object.entries(t).map(([A,e])=>[A,e.getContext("2d")])),this.transform=xa(),this.transform.d*=-1,this.transform=An(this.transform,on(0,-500)),this.lastPoint={x:0,y:0},this.equip({})}clear(){for(const t of Object.values(this.ctxLayerMap))t.clearRect(0,0,t.canvas.width,t.canvas.height)}equip(t){this.aperture={fontSize:0,shape:"circle",mode:"add",size:0,color:"red",layer:"top",opacity:this.foregroundLayer===t.color?1:.5,...t}}drawMeshPattern(t,A,e,i,n,o=45){const s=this.getLayerCtx(),[r,a]=Ce(this.transform,[t,A]),[g,c]=Ce(this.transform,[t+e,A+i]),I=Pf(this.transform,n);s.lineWidth=1,s.strokeStyle=this.aperture.color;const l=B=>{const C=Math.sin(B),Q=Math.cos(B),h=Math.sqrt((g-r)**2+(c-a)**2);for(let E=-h;E<=h;E+=I)s.beginPath(),s.moveTo(r+E*Q-h*C,a+E*C+h*Q),s.lineTo(r+E*Q+h*C,a+E*C-h*Q),s.stroke()};l(o*Math.PI/180),l((o+90)*Math.PI/180)}rect({x:t,y:A,w:e,h:i,mesh_fill:n,is_filled:o=!0,has_stroke:s,is_stroke_dashed:r,stroke_width:a,roundness:g}){const[c,I]=Ce(this.transform,[t-e/2,A-i/2]),[l,B]=Ce(this.transform,[t+e/2,A+i/2]);this.applyAperture();const C=this.getLayerCtx(),Q=g?Pf(this.transform,g):0,h=s===void 0?o===!1:s;if(n)C.save(),C.beginPath(),Q>0&&C.roundRect?C.roundRect(c,I,l-c,B-I,Q):C.rect(c,I,l-c,B-I),C.clip(),this.drawMeshPattern(t-e/2,A-i/2,e,i,.15),C.restore(),Q>0&&C.roundRect?(C.beginPath(),C.roundRect(c,I,l-c,B-I,Q),C.stroke()):C.strokeRect(c,I,l-c,B-I);else if(o!==!1&&(Q>0&&C.roundRect?(C.beginPath(),C.roundRect(c,I,l-c,B-I,Q),C.fill()):C.fillRect(c,I,l-c,B-I)),h){const E=C.lineWidth;if(a!==void 0&&(C.lineWidth=Pf(this.transform,a)),r){let u=[];const d=Math.abs(this.transform.a);if(d>0){const y=.1*d,w=y*1.3;y>.5&&(u=[y,w])}C.setLineDash(u)}Q>0&&C.roundRect?(C.beginPath(),C.roundRect(c,I,l-c,B-I,Q),C.stroke()):C.strokeRect(c,I,l-c,B-I),r&&C.setLineDash([]),a!==void 0&&(C.lineWidth=E)}}rotatedRect(t,A,e,i,n,o,s){const r=this.getLayerCtx();this.applyAperture();const[a,g]=Ce(this.transform,[t-e/2,A-i/2]),[c,I]=Ce(this.transform,[t+e/2,A+i/2]),l=o?Pf(this.transform,o):0;r.save();const[B,C]=Ce(this.transform,[t,A]);r.translate(B,C);const Q=360-n;n&&r.rotate(Q*Math.PI/180),r.translate(-B,-C),s?(r.beginPath(),l>0&&r.roundRect?r.roundRect(a,g,c-a,I-g,l):r.rect(a,g,c-a,I-g),r.clip(),this.drawMeshPattern(t-e/2,A-i/2,e,i,.15),l>0&&r.roundRect?(r.beginPath(),r.roundRect(a,g,c-a,I-g,l),r.stroke()):r.strokeRect(a,g,c-a,I-g)):l>0&&r.roundRect?(r.beginPath(),r.roundRect(a,g,c-a,I-g,l),r.fill()):r.fillRect(a,g,c-a,I-g),r.restore()}rotatedPill(t,A,e,i,n){const o=this.getLayerCtx();this.applyAperture(),o.save();const[s,r]=Ce(this.transform,[t,A]);o.translate(s,r);const a=360-n;n&&o.rotate(a*Math.PI/180),o.translate(-s,-r),this.pill(t,A,e,i),o.restore()}circle(t,A,e,i,n=!0){const o=Pf(this.transform,e),[s,r]=Ce(this.transform,[t,A]);this.applyAperture();const a=this.getLayerCtx();i?(a.save(),a.beginPath(),a.arc(s,r,o,0,2*Math.PI),a.clip(),this.drawMeshPattern(t-e,A-e,e*2,e*2,.15),a.restore(),a.beginPath(),a.arc(s,r,o,0,2*Math.PI),a.stroke()):(a.beginPath(),a.arc(s,r,o,0,2*Math.PI),a.fill())}oval(t,A,e,i){const n=Pf(this.transform,e),o=Pf(this.transform,i),[s,r]=Ce(this.transform,[t,A]);this.applyAperture();const a=this.getLayerCtx();a.beginPath(),a.ellipse(s,r,n,o,0,0,2*Math.PI),a.fill(),a.closePath()}pill(t,A,e,i){const[n,o]=Ce(this.transform,[t-e/2,A+i/2]),s=Pf(this.transform,e),r=Pf(this.transform,i),a=Math.min(s,r)/2;this.applyAperture();const g=this.getLayerCtx();g.beginPath(),g.arc(n+a,o+a,a,Math.PI,Math.PI*1.5),g.arc(n+s-a,o+a,a,Math.PI*1.5,0),g.arc(n+s-a,o+r-a,a,0,Math.PI*.5),g.arc(n+a,o+r-a,a,Math.PI*.5,Math.PI),g.fill(),g.closePath()}polygon(t){if(t.length<3)return;this.applyAperture();const A=this.getLayerCtx(),e=t.map(n=>Ce(this.transform,[n.x,n.y]));A.beginPath(),A.moveTo(e[0][0],e[0][1]);for(let n=1;n<e.length;n++)A.lineTo(e[n][0],e[n][1]);A.closePath(),A.fill("evenodd");const i=Pf(this.transform,this.aperture.size);i>0&&(A.lineWidth=i,A.stroke())}debugText(t,A,e){const[i,n]=Ce(this.transform,[A,e]);this.applyAperture();const o=this.getLayerCtx();o.font="10px sans-serif",o.fillText(t,i,n)}getLayerCtx(){const t=this.ctxLayerMap[this.aperture.layer];if(!t)throw new Error(`No context for layer "${this.aperture.layer}"`);return t}orderAndFadeLayers(){const{canvasLayerMap:t,foregroundLayer:A}=this,e=A==="top"?"soldermask_top":A==="bottom"?"soldermask_bottom":void 0,i=A==="top"?"top_silkscreen":A==="bottom"?"bottom_silkscreen":void 0,n=A==="top"?"top_notes":A==="bottom"?"bottom_notes":void 0,o=A==="top"?"top_fabrication":A==="bottom"?"bottom_fabrication":void 0,s=A==="top"?"top_courtyard":A==="bottom"?"bottom_courtyard":void 0,r=new Set([A,"drill","edge_cuts","other","board",...e?[e]:[],...i?[i]:[],...n?[n]:[],...o?[o]:[],...s?[s]:[]]),a=[A,"edge_cuts",...e?[e]:[],...i?[i]:[],...n?[n]:[],...o?[o]:[],...s?[s]:[]],g=A==="drill"?[]:["drill"],c=A==="drill"?["drill"]:[],I=[...cei.filter(l=>!a.includes(l)),...g,A,...e?[e]:[],...c,"edge_cuts",...i?[i]:[],...n?[n]:[],...o?[o]:[],...s?[s]:[]];I.forEach((l,B)=>{const C=t[l];C&&(C.style.zIndex=`${kc.topLayer-(I.length-B)}`,C.style.opacity=r.has(l)?"1":"0.5")})}applyAperture(){const{transform:t,aperture:A}=this;let{size:e,mode:i,color:n,fontSize:o,layer:s}=A;s in this.ctxLayerMap||(this.aperture.layer="other");const r=this.getLayerCtx();if(!r)throw new Error(`No context for layer "${this.foregroundLayer}"`);if(n||(n="undefined"),r.lineWidth=Pf(t,e),r.lineCap="round",i==="add"){r.globalCompositeOperation="source-over";let a=vz[n.toLowerCase()];if(!a)try{a=Ta(n).rgb().toString()}catch{console.warn(`Invalid color format: '${n}'`),a="white"}r.fillStyle=a,r.strokeStyle=a}else r.globalCompositeOperation="destination-out",r.fillStyle="rgba(0,0,0,1)",r.strokeStyle="rgba(0,0,0,1)";r.font=`${Pf(tm(t),o)}px sans-serif`}moveTo(t,A){this.lastPoint={x:t,y:A}}lineTo(t,A){const[e,i]=Ce(this.transform,[t,A]),{size:n,shape:o,mode:s}=this.aperture,r=Pf(this.transform,n),{lastPoint:a}=this,g=Ce(this.transform,a);this.applyAperture();const c=this.getLayerCtx();o==="square"&&c.fillRect(g.x-r/2,g.y-r/2,r,r),c.beginPath(),c.moveTo(g.x,g.y),c.lineTo(e,i),c.stroke(),c.closePath(),o==="square"&&c.fillRect(e-r/2,i-r/2,r,r),this.lastPoint={x:t,y:A}}polygonWithArcs(t){const A=this.getLayerCtx(),e=i=>{if(i.vertices.length===0)return;const n=i.vertices[0],o=Ce(this.transform,[n.x,n.y]);A.moveTo(o[0],o[1]);for(let s=0;s<i.vertices.length;s++){const r=i.vertices[s],a=i.vertices[(s+1)%i.vertices.length];if(r.bulge&&r.bulge!==0){const g=r.bulge,c=a.x-r.x,I=a.y-r.y,l=Math.sqrt(c*c+I*I);if(l<1e-9){const F=Ce(this.transform,[a.x,a.y]);A.lineTo(F[0],F[1]);continue}const B=4*Math.atan(g),C=Math.abs(l/(2*Math.sin(B/2))),Q=(r.x+a.x)/2,h=(r.y+a.y)/2,E=c/l,d=-(I/l),f=E,y=Math.sqrt(Math.max(0,C*C-(l/2)**2)),w=Q+y*d*Math.sign(g),D=h+y*f*Math.sign(g),S=Math.atan2(r.y-D,r.x-w);let _=Math.atan2(a.y-D,a.x-w);g>0&&_<S?_+=2*Math.PI:g<0&&_>S&&(_-=2*Math.PI);const b=Ce(this.transform,[w,D]),N=Pf(this.transform,C);A.arc(b[0],b[1],N,-S,-_,g>0)}else{const g=Ce(this.transform,[a.x,a.y]);A.lineTo(g[0],g[1])}}A.closePath()};if(A.beginPath(),e(t.outer_ring),t.inner_rings)for(const i of t.inner_rings)e(i);A.fill("evenodd")}};function lei(t){return t.type==="pcb_copper_pour"}function Fz({canvas:t,elements:A,layers:e,realToCanvasMat:i}){const n=A.filter(lei);if(n.length===0)return;const o=new iQ(t);o.realToCanvasMat=i,o.drawElements(n,{layers:e})}var Bei={...gp,silkscreen:{top:yn.board.f_fab,bottom:yn.board.b_fab}};function Cei(t){return t.type.includes("pcb_fabrication_note")}function Khe({canvas:t,elements:A,layers:e,realToCanvasMat:i}){const n=new iQ(t);n.configure({colorOverrides:Bei}),n.realToCanvasMat=i;const o=A.filter(Cei);n.drawElements(o,{layers:e})}function Qei(t){return t.type==="pcb_hole"}function hei({canvas:t,elements:A,layers:e,realToCanvasMat:i,drawSoldermask:n}){const o=new iQ(t);o.realToCanvasMat=i;const s=A.filter(Qei);o.drawElements(s,{layers:e,drawSoldermask:n})}function Eei(t){return t.type==="pcb_board"}function uei({canvas:t,elements:A,layers:e,realToCanvasMat:i,drawSoldermask:n}){const o=new iQ(t);o.realToCanvasMat=i;const s=A.filter(Eei);for(const r of s)o.drawElements([r],{layers:e,drawSoldermask:!1,drawBoardMaterial:n??!1,minBoardOutlineStrokePx:2})}function dei(t){return t.type==="pcb_cutout"}function pei({canvas:t,elements:A,layers:e,realToCanvasMat:i}){const n=new iQ(t);n.realToCanvasMat=i;const o=A.filter(dei);n.drawElements(o,{layers:e})}function fei(t){return t.type==="pcb_keepout"}function yei({canvas:t,elements:A,layers:e,realToCanvasMat:i}){const n=A.filter(fei);if(n.length===0)return;const o=new iQ(t);o.realToCanvasMat=i,o.drawElements(n,{layers:[]})}function mei(t){return t.type.startsWith("pcb_note_")}function qhe({canvas:t,elements:A,layers:e,realToCanvasMat:i}){const n=new iQ(t);n.realToCanvasMat=i;const o=A.filter(mei);n.drawElements(o,{layers:e})}function wei(t){return t.type==="pcb_panel"}function Dei({canvas:t,elements:A,layers:e,realToCanvasMat:i,drawSoldermask:n}){const o=new iQ(t);o.realToCanvasMat=i;const s=A.filter(wei);for(const r of s)o.drawElements([r],{layers:e})}var Sei={...gp,copper:{...gp.copper,top:Ta(yn.board.pad_front).lighten(.5).toString(),bottom:Ta(yn.board.pad_back).lighten(.5).toString(),inner1:Ta(yn.board.copper.in1).lighten(.5).toString(),inner2:Ta(yn.board.copper.in2).lighten(.5).toString(),inner3:Ta(yn.board.copper.in3).lighten(.5).toString(),inner4:Ta(yn.board.copper.in4).lighten(.5).toString(),inner5:Ta(yn.board.copper.in5).lighten(.5).toString(),inner6:Ta(yn.board.copper.in6).lighten(.5).toString()}};function bei(t){return t.type==="pcb_smtpad"}function xei({canvas:t,elements:A,layers:e,realToCanvasMat:i,primitives:n,drawSoldermask:o}){const s=A.filter(bei).filter(c=>{const I=c.layer;return e.some(l=>l==="top_copper"&&I==="top"||l==="bottom_copper"&&I==="bottom"||l==="inner1_copper"&&I==="inner1"||l==="inner2_copper"&&I==="inner2"||l==="inner3_copper"&&I==="inner3"||l==="inner4_copper"&&I==="inner4"||l==="inner5_copper"&&I==="inner5"||l==="inner6_copper"&&I==="inner6")});if(s.length===0)return;const r=new Set;if(n)for(const c of n)(c.is_mouse_over||c.is_in_highlighted_net)&&c._element?.type==="pcb_smtpad"&&r.add(c._element.pcb_smtpad_id);const a=s.filter(c=>r.has(c.pcb_smtpad_id)),g=s.filter(c=>!r.has(c.pcb_smtpad_id));if(g.length>0){const c=new iQ(t);c.realToCanvasMat=i,c.drawElements(g,{layers:e,drawSoldermask:o})}if(a.length>0){const c=new iQ(t);c.configure({colorOverrides:Sei}),c.realToCanvasMat=i,c.drawElements(a,{layers:e,drawSoldermask:o})}}var _ei={...gp,copper:{...gp.copper,top:Ta(yn.board.pad_front).lighten(.5).toString(),bottom:Ta(yn.board.pad_back).lighten(.5).toString(),inner1:Ta(yn.board.copper.in1).lighten(.5).toString(),inner2:Ta(yn.board.copper.in2).lighten(.5).toString(),inner3:Ta(yn.board.copper.in3).lighten(.5).toString(),inner4:Ta(yn.board.copper.in4).lighten(.5).toString(),inner5:Ta(yn.board.copper.in5).lighten(.5).toString(),inner6:Ta(yn.board.copper.in6).lighten(.5).toString()}};function kei(t){return t.type==="pcb_trace"}var vei=t=>t.map(A=>A.endsWith("_copper")?A.replace("_copper",""):A),Fei=(t,A)=>{const e=t.route.filter(i=>i.route_type==="wire"&&"layer"in i&&A.has(i.layer));return e.length===0?null:{...t,route:e}};function Mei({canvas:t,elements:A,layers:e,realToCanvasMat:i,primitives:n}){const o=new Set(vei(e)),s=A.filter(kei).map(c=>Fei(c,o)).filter(c=>c!==null);if(s.length===0)return;const r=new Set;if(n)for(const c of n)(c.is_mouse_over||c.is_in_highlighted_net)&&c._element?.type==="pcb_trace"&&r.add(c._element.pcb_trace_id);const a=[],g=[];for(const c of s)r.has(c.pcb_trace_id)?a.push(c):g.push(c);if(g.length>0){const c=new iQ(t);c.realToCanvasMat=i,c.drawElements(g,{layers:e})}if(a.length>0){const c=new iQ(t);c.configure({colorOverrides:_ei}),c.realToCanvasMat=i,c.drawElements(a,{layers:e})}}var Rei={...gp,copper:{...gp.copper,top:Ta(yn.board.pad_front).lighten(.5).toString(),bottom:Ta(yn.board.pad_back).lighten(.5).toString()}};function Nei(t){return t.type==="pcb_plated_hole"}function Ohe({canvas:t,elements:A,layers:e,realToCanvasMat:i,primitives:n,drawSoldermask:o}){const s=A.filter(Nei);if(s.length===0)return;const r=new Set;if(n)for(const c of n)(c.is_mouse_over||c.is_in_highlighted_net)&&c._element?.type==="pcb_plated_hole"&&r.add(c._element.pcb_plated_hole_id);const a=s.filter(c=>r.has(c.pcb_plated_hole_id)),g=s.filter(c=>!r.has(c.pcb_plated_hole_id));if(g.length>0){const c=new iQ(t);c.realToCanvasMat=i,c.drawElements(g,{layers:e,drawSoldermask:o})}if(a.length>0){const c=new iQ(t);c.configure({colorOverrides:Rei}),c.realToCanvasMat=i,c.drawElements(a,{layers:e,drawSoldermask:o})}}function Whe(t){const{lines:A,anchorPoint:e,ccwRotation:i}=t;if(!i)return A;const n=i*Math.PI/180,o=Tl(n),s=An(on(e.x,e.y),o,on(-e.x,-e.y));return Ce(s,e),A.map(r=>({...r,x1:Ce(s,{x:r.x1,y:r.y1}).x,y1:Ce(s,{x:r.x1,y:r.y1}).y,x2:Ce(s,{x:r.x2,y:r.y2}).x,y2:Ce(s,{x:r.x2,y:r.y2}).y}))}var Gei=.6,Zhe=.2,Vhe=t=>{const A=t.size*.7,e=A*Gei,i=A*Zhe,n=A*Zhe,o=t.text.split(/\r?\n/),s=t.text.length>0&&A>0,r=s?o.length:0,a=s?o.map(I=>I.length===0?0:I.length*e+(I.length-1)*i):[],g=a.length>0?Math.max(...a):0,c=r>0?r*A+(r-1)*n:0;return{text_lines:o,line_count:r,line_widths:a,target_height:A,target_width_char:e,space_between_chars:i,space_between_lines:n,width:g,height:c}},jhe=t=>{const A=Vhe(t);return{width:A.width,height:A.height,lineHeight:A.target_height,lineSpacing:A.space_between_lines,lineCount:A.line_count}},zhe=t=>{const{text_lines:A,line_count:e,line_widths:i,target_height:n,target_width_char:o,space_between_chars:s,space_between_lines:r,width:a}=Vhe(t);if(n<=0||e===0)return[];const g=n/12,c=[];for(let I=0;I<e;I++){const l=-I*(n+r),B=i[I],C=(a-B)/2;let Q=t.x+C;for(let h=0;h<A[I].length;h++){const E=A[I][h],u=XF[E]??XF[E.toUpperCase()];if(!u){Q+=o+s;continue}for(const{x1:d,y1:f,x2:y,y2:w}of u)c.push({_pcb_drawing_object_id:Nm("line"),pcb_drawing_type:"line",x1:Q+o*d,y1:t.y+l+n*f,x2:Q+o*y,y2:t.y+l+n*w,width:g,layer:t.layer,unit:t.unit,color:t.color});Q+=o+s}}return c};function yS(t){const e=t.color??vz[t.layer];let i=Ta(e);return t._element?.type==="pcb_copper_pour"&&(i=i.alpha(.7)),t.is_mouse_over||t.is_in_highlighted_net?i.lighten(.5).rgb().toString():i.rgb().toString()}var Xhe=(t,A)=>{t.equip({size:A.zoomIndependent?A.width/t.transform.a:A.width,shape:A.squareCap?"square":"circle",color:yS(A),layer:A.layer}),t.moveTo(A.x1,A.y1),t.lineTo(A.x2,A.y2)},Lei=(t,A,e)=>{switch(e){case"top_left":return{x:0,y:-A};case"top_center":return{x:-t/2,y:-A};case"top_right":return{x:-t,y:-A};case"center_left":return{x:0,y:-A/2};case"center":return{x:-t/2,y:-A/2};case"center_right":return{x:-t,y:-A/2};case"bottom_left":return{x:0,y:0};case"bottom_center":return{x:-t/2,y:0};case"bottom_right":return{x:-t,y:0};default:return{x:0,y:0}}},$he=t=>t.layer==="bottom_silkscreen"||t.layer==="bottom"?t.is_mirrored!==!1:t.is_mirrored===!0,Uei=(t,A)=>{t.equip({fontSize:A.size,color:yS(A),layer:A.layer});const{width:e,height:i}=jhe(A),n=Lei(e,i,A.align);A.x??=0,A.y??=0;const o={x:A.x,y:A.y};let s=zhe({...A,x:A.x+n.x,y:A.y+n.y});if($he(A)&&(s=s.map(r=>({...r,x1:2*A.x-r.x1,x2:2*A.x-r.x2}))),A.ccw_rotation){const r={lines:s,anchorPoint:o,ccwRotation:A.ccw_rotation};s=Whe(r)}for(const r of s)Xhe(t,r)},Hei=(t,A)=>{const{width:e,height:i,lineHeight:n}=jhe(A);A.x??=0,A.y??=0;const o=A.knockout_padding??{left:A.size*.5,right:A.size*.5,top:A.size*.3,bottom:A.size*.3},s=e+o.left+o.right,r=i+o.top+o.bottom,a=e/2,g=n-i/2,c=A.x-a,I=A.y-g,l={x:A.x,y:A.y},B={_pcb_drawing_object_id:`knockout_rect_${A._pcb_drawing_object_id}`,x:A.x,y:A.y,w:s,h:r,layer:A.layer,ccw_rotation:A.ccw_rotation};A.ccw_rotation?eEe(t,B):AEe(t,B);let C=zhe({...A,x:c,y:I});if($he(A)&&(C=C.map(Q=>({...Q,x1:2*A.x-Q.x1,x2:2*A.x-Q.x2}))),A.ccw_rotation){const Q={lines:C,anchorPoint:l,ccwRotation:A.ccw_rotation};C=Whe(Q)}for(const Q of C)t.equip({size:Q.width,shape:"circle",color:"black",layer:A.layer,mode:"subtract"}),t.moveTo(Q.x1,Q.y1),t.lineTo(Q.x2,Q.y2);t.equip({mode:"add"})},AEe=(t,A)=>{t.equip({color:yS(A),layer:A.layer,size:A.stroke_width}),t.rect({x:A.x,y:A.y,w:A.w,h:A.h,mesh_fill:A.mesh_fill,is_filled:A.is_filled,has_stroke:A.has_stroke,is_stroke_dashed:A.is_stroke_dashed,stroke_width:A.stroke_width,roundness:A.roundness})},eEe=(t,A)=>{t.equip({color:yS(A),layer:A.layer}),t.rotatedRect(A.x,A.y,A.w,A.h,A.ccw_rotation,A.roundness,A.mesh_fill)},Yei=(t,A)=>{t.equip({color:yS(A),layer:A.layer}),t.rotatedPill(A.x,A.y,A.w,A.h,A.ccw_rotation)},Jei=(t,A)=>{t.equip({color:yS(A),layer:A.layer}),t.circle(A.x,A.y,A.r,A.mesh_fill)},Tei=(t,A)=>{t.equip({color:yS(A),layer:A.layer}),t.oval(A.x,A.y,A.rX,A.rY)},Pei=(t,A)=>{t.equip({color:yS(A),layer:A.layer}),t.pill(A.x,A.y,A.w,A.h)},Kei=(t,A)=>{t.equip({color:yS(A),layer:A.layer}),t.polygon(A.points)},qei=(t,A)=>{t.equip({color:yS(A),layer:A.layer}),t.polygonWithArcs(A.brep_shape)},Oei=(t,A)=>{switch(A.pcb_drawing_type){case"line":return Xhe(t,A);case"text":return A.is_knockout?Hei(t,A):Uei(t,A);case"rect":return A.ccw_rotation?eEe(t,A):AEe(t,A);case"circle":return Jei(t,A);case"oval":return Tei(t,A);case"pill":return A.ccw_rotation?Yei(t,A):Pei(t,A);case"polygon":return Kei(t,A);case"polygon_with_arcs":return qei(t,A)}},Wei=(t,A)=>{for(const e of A)Oei(t,e)},Zei={...gp,copper:{...gp.copper,top:Ta(yn.board.pad_front).lighten(.5).toString(),bottom:Ta(yn.board.pad_back).lighten(.5).toString(),inner1:Ta(yn.board.copper.in1).lighten(.5).toString(),inner2:Ta(yn.board.copper.in2).lighten(.5).toString(),inner3:Ta(yn.board.copper.in3).lighten(.5).toString(),inner4:Ta(yn.board.copper.in4).lighten(.5).toString(),inner5:Ta(yn.board.copper.in5).lighten(.5).toString(),inner6:Ta(yn.board.copper.in6).lighten(.5).toString()},soldermask:{...gp.soldermask,top:Ta(yn.board.soldermask.top).lighten(.35).toString(),bottom:Ta(yn.board.soldermask.bottom).lighten(.35).toString()}};function tEe({canvas:t,elements:A,layers:e,realToCanvasMat:i,drawSoldermaskTop:n,drawSoldermaskBottom:o,primitives:s}){const r=new iQ(t);r.realToCanvasMat=i;const a=A.filter(l=>l.type==="pcb_board");if(a.length<=1)r.drawElements(A,{layers:e,drawSoldermask:!0,drawSoldermaskTop:n,drawSoldermaskBottom:o,drawBoardMaterial:!1});else{const l=A.filter(B=>B.type!=="pcb_board");for(const B of a)r.drawElements([B,...l],{layers:e,drawSoldermask:!0,drawSoldermaskTop:n,drawSoldermaskBottom:o,drawBoardMaterial:!1})}if(!s)return;const g=new Set;for(const l of s){if(!(l.is_mouse_over||l.is_in_highlighted_net))continue;const B=l._element;B?.type==="pcb_smtpad"?g.add(B.pcb_smtpad_id):B?.type==="pcb_plated_hole"?g.add(B.pcb_plated_hole_id):B?.type==="pcb_via"&&g.add(B.pcb_via_id)}if(g.size===0)return;const c=A.filter(l=>l.type==="pcb_smtpad"?g.has(l.pcb_smtpad_id):l.type==="pcb_plated_hole"?g.has(l.pcb_plated_hole_id):l.type==="pcb_via"?g.has(l.pcb_via_id):!1);if(c.length===0)return;const I=new iQ(t);I.configure({colorOverrides:Zei}),I.realToCanvasMat=i,I.drawElements(c,{layers:e,drawSoldermask:!0,drawSoldermaskTop:n,drawSoldermaskBottom:o,drawBoardMaterial:!1})}var Vei={...gp,silkscreen:{top:yn.board.f_silks,bottom:yn.board.b_silks}};function jei(t){return t.type.includes("pcb_silkscreen")}function iEe({canvas:t,elements:A,layers:e,realToCanvasMat:i}){const n=new iQ(t);n.configure({colorOverrides:Vei}),n.realToCanvasMat=i;const o=A.filter(jei);n.drawElements(o,{layers:e})}var zei={...gp,copper:{...gp.copper,top:Ta(yn.board.pad_front).lighten(.5).toString(),bottom:Ta(yn.board.pad_back).lighten(.5).toString()}};function Xei(t){return t.type==="pcb_via"}function nEe({canvas:t,elements:A,layers:e,realToCanvasMat:i,primitives:n,drawSoldermask:o}){const s=A.filter(Xei).filter(c=>e.some(I=>I.includes("copper")));if(s.length===0)return;const r=new Set;if(n)for(const c of n)(c.is_mouse_over||c.is_in_highlighted_net)&&c._element?.type==="pcb_via"&&r.add(c._element.pcb_via_id);const a=s.filter(c=>r.has(c.pcb_via_id)),g=s.filter(c=>!r.has(c.pcb_via_id));if(g.length>0){const c=new iQ(t);c.realToCanvasMat=i,c.drawElements(g,{layers:e,drawSoldermask:o})}if(a.length>0){const c=new iQ(t);c.configure({colorOverrides:zei}),c.realToCanvasMat=i,c.drawElements(a,{layers:e,drawSoldermask:o})}}var $ei={...gp,courtyard:{top:yn.board.f_crtyd,bottom:yn.board.b_crtyd}};function Ati(t){return t.type==="pcb_courtyard_circle"||t.type==="pcb_courtyard_rect"||t.type==="pcb_courtyard_outline"}function oEe({canvas:t,elements:A,layers:e,realToCanvasMat:i}){const n=new iQ(t);n.configure({colorOverrides:$ei}),n.realToCanvasMat=i;const o=A.filter(Ati);n.drawElements(o,{layers:e})}var eti=["board","bottom","soldermask_bottom","bottom_silkscreen","top","soldermask_top","soldermask_with_copper_bottom","soldermask_with_copper_top","top_fabrication","bottom_fabrication","inner1","inner2","inner3","inner4","inner5","inner6","drill","edge_cuts","bottom_notes","top_notes","top_silkscreen","top_courtyard","bottom_courtyard","other"],tti=({primitives:t,elements:A,transform:e,grid:i,width:n=500,height:o=500})=>{const s=V.useRef({}),r=gl(l=>l.selected_layer),a=gl(l=>l.is_showing_solder_mask),g=gl(l=>l.is_showing_fabrication_notes),c=gl(l=>l.is_showing_courtyards),I=gl(l=>l.is_showing_silkscreen);return V.useEffect(()=>{if(!s.current||Object.keys(s.current).length===0)return;const l=Object.fromEntries(Object.entries(s.current).filter(([Q,h])=>!!h));if(Object.keys(l).length===0)return;const B=new Iei(l);e&&(B.transform=e),B.clear(),B.foregroundLayer=r;const C=t.filter(Q=>a||!Q.layer?.includes("soldermask")).filter(Q=>I||!Q.layer?.includes("silkscreen")).filter(Q=>g||!Q.layer?.includes("fabrication")).filter(Q=>Q.layer!=="board").filter(Q=>Q._element?.type!=="pcb_smtpad").filter(Q=>Q._element?.type!=="pcb_plated_hole").filter(Q=>Q._element?.type!=="pcb_via").filter(Q=>Q._element?.type!=="pcb_trace");if(Wei(B,C),e){const Q=s.current.top,h=s.current.bottom,E=s.current.inner1,u=s.current.inner2,d=s.current.inner3,f=s.current.inner4,y=s.current.inner5,w=s.current.inner6,D=[{canvas:Q,copperLayer:"top_copper"},{canvas:h,copperLayer:"bottom_copper"},{canvas:E,copperLayer:"inner1_copper"},{canvas:u,copperLayer:"inner2_copper"},{canvas:d,copperLayer:"inner3_copper"},{canvas:f,copperLayer:"inner4_copper"},{canvas:y,copperLayer:"inner5_copper"},{canvas:w,copperLayer:"inner6_copper"}];for(const{canvas:Y,copperLayer:J}of D)Y&&Mei({canvas:Y,elements:A,layers:[J],realToCanvasMat:e,primitives:t});Q&&Ohe({canvas:Q,elements:A,layers:["top_copper"],realToCanvasMat:e,primitives:t,drawSoldermask:a}),h&&Ohe({canvas:h,elements:A,layers:["bottom_copper"],realToCanvasMat:e,primitives:t,drawSoldermask:a}),Q&&Fz({canvas:Q,elements:A,layers:["top_copper"],realToCanvasMat:e}),h&&Fz({canvas:h,elements:A,layers:["bottom_copper"],realToCanvasMat:e});for(const{canvas:Y,copperLayer:J}of D)Y&&xei({canvas:Y,elements:A,layers:[J],realToCanvasMat:e,primitives:t,drawSoldermask:a});if(Q&&nEe({canvas:Q,elements:A,layers:["top_copper"],realToCanvasMat:e,primitives:t,drawSoldermask:a}),h&&nEe({canvas:h,elements:A,layers:["bottom_copper"],realToCanvasMat:e,primitives:t,drawSoldermask:a}),a){const Y=r==="bottom"?"bottom":"top",J=Y==="top",O=Y==="bottom",Z=s.current.soldermask_top;Z&&Y==="top"&&tEe({canvas:Z,elements:A,layers:["top_soldermask"],realToCanvasMat:e,drawSoldermaskTop:J,drawSoldermaskBottom:O,primitives:t});const X=s.current.soldermask_bottom;X&&Y==="bottom"&&tEe({canvas:X,elements:A,layers:["bottom_soldermask"],realToCanvasMat:e,drawSoldermaskTop:J,drawSoldermaskBottom:O,primitives:t})}Q&&Fz({canvas:Q,elements:A,layers:["top_copper"],realToCanvasMat:e}),h&&Fz({canvas:h,elements:A,layers:["bottom_copper"],realToCanvasMat:e});const S=s.current.drill;if(S&&hei({canvas:S,elements:A,layers:["drill"],realToCanvasMat:e}),I){const Y=s.current.top_silkscreen;Y&&iEe({canvas:Y,elements:A,layers:["top_silkscreen"],realToCanvasMat:e});const J=s.current.bottom_silkscreen;J&&iEe({canvas:J,elements:A,layers:["bottom_silkscreen"],realToCanvasMat:e})}if(g){const Y=s.current.top_fabrication;Y&&Khe({canvas:Y,elements:A,layers:["top_fabrication_note"],realToCanvasMat:e});const J=s.current.bottom_fabrication;J&&Khe({canvas:J,elements:A,layers:["bottom_fabrication_note"],realToCanvasMat:e})}const _=s.current.bottom_notes;_&&qhe({canvas:_,elements:A,layers:["bottom_user_note"],realToCanvasMat:e});const b=s.current.top_notes;if(b&&qhe({canvas:b,elements:A,layers:["top_user_note"],realToCanvasMat:e}),c){const Y=s.current.top_courtyard;Y&&oEe({canvas:Y,elements:A,layers:["top_courtyard"],realToCanvasMat:e});const J=s.current.bottom_courtyard;J&&oEe({canvas:J,elements:A,layers:["bottom_courtyard"],realToCanvasMat:e})}const N=s.current.board;N&&(Dei({canvas:N,elements:A,layers:[],realToCanvasMat:e,drawSoldermask:a}),uei({canvas:N,elements:A,layers:[],realToCanvasMat:e,drawSoldermask:a}));const F=s.current.edge_cuts;F&&pei({canvas:F,elements:A,layers:["edge_cuts"],realToCanvasMat:e});const L=[{canvas:Q,layer:"top"},{canvas:h,layer:"bottom"}];for(const{canvas:Y,layer:J}of L)Y&&yei({canvas:Y,elements:A,layers:[J],realToCanvasMat:e})}B.orderAndFadeLayers()},[t,A,e,r,a,g,c,I]),W.jsxs("div",{style:{backgroundColor:"black",width:n,height:o,position:"relative"},children:[W.jsx(hz.SuperGrid,{textColor:"rgba(0,255,0,0.8)",majorColor:"rgba(0,255,0,0.4)",minorColor:"rgba(0,255,0,0.2)",screenSpaceCellSize:200,width:n,height:o,transform:e,stringifyCoord:(l,B,C)=>`${hz.toMMSI(l,C)}, ${hz.toMMSI(B,C)}`}),eti.filter(l=>!(!a&&l.includes("soldermask")||!I&&l.includes("silkscreen"))).map(l=>l.replace(/-/g,"")).map((l,B)=>W.jsx("canvas",{className:`pcb-layer-${l}`,ref:C=>{s.current??={},C?s.current[l]=C:delete s.current[l]},style:{position:"absolute",zIndex:B,left:0,top:0,pointerEvents:"none"},width:n,height:o},l))]})},iti=.6,nti=1;CmA(cAi(),1),CmA(SAi(),1);var Mz=["rgba(239, 68, 68, 0.8)","rgba(249, 115, 22, 0.8)","rgba(245, 158, 11, 0.8)","rgba(234, 179, 8, 0.8)","rgba(132, 204, 22, 0.8)","rgba(34, 197, 94, 0.8)","rgba(16, 185, 129, 0.8)","rgba(20, 184, 166, 0.8)","rgba(6, 182, 212, 0.8)","rgba(14, 165, 233, 0.8)","rgba(59, 130, 246, 0.8)","rgba(99, 102, 241, 0.8)","rgba(139, 92, 246, 0.8)","rgba(168, 85, 247, 0.8)","rgba(217, 70, 239, 0.8)","rgba(236, 72, 153, 0.8)","rgba(249, 168, 212, 0.8)","rgba(161, 161, 170, 0.8)"];function sEe(t,A,e,i={}){const n=i.padding??40,o=i.yFlip??!1;let s;if("center"in t){const c=t.width/2,I=t.height/2;s={minX:t.center.x-c,maxX:t.center.x+c,minY:t.center.y-I,maxY:t.center.y+I}}else s=t;const r=s.maxX-s.minX||1,a=s.maxY-s.minY||1,g=Math.min((A-2*n)/r,(e-2*n)/a);return An(on(A/2,e/2),$a(g,o?-g:g),on(-(s.minX+r/2),-(s.minY+a/2)))}function oti(t){const A=[...t.points||[],...(t.lines||[]).flatMap(e=>e.points),...(t.rects||[]).flatMap(e=>{const i=e.width/2,n=e.height/2;return[{x:e.center.x-i,y:e.center.y-n},{x:e.center.x+i,y:e.center.y-n},{x:e.center.x-i,y:e.center.y+n},{x:e.center.x+i,y:e.center.y+n}]}),...(t.circles||[]).flatMap(e=>[{x:e.center.x-e.radius,y:e.center.y},{x:e.center.x+e.radius,y:e.center.y},{x:e.center.x,y:e.center.y-e.radius},{x:e.center.x,y:e.center.y+e.radius}]),...(t.texts||[]).flatMap(e=>{const i=e.fontSize??12,n=e.text.length*i*iti,o=i*nti,s=e.anchorSide??"center",r={top_left:{dx:0,dy:0},top_center:{dx:-n/2,dy:0},top_right:{dx:-n,dy:0},center_left:{dx:0,dy:-o/2},center:{dx:-n/2,dy:-o/2},center_right:{dx:-n,dy:-o/2},bottom_left:{dx:0,dy:-o},bottom_center:{dx:-n/2,dy:-o},bottom_right:{dx:-n,dy:-o}},{dx:a,dy:g}=r[s],c=e.x+a,I=e.y+g;return[{x:c,y:I},{x:c+n,y:I+o}]})];return A.length===0?{minX:-1,maxX:1,minY:-1,maxY:1}:A.reduce((e,i)=>({minX:Math.min(e.minX,i.x),maxX:Math.max(e.maxX,i.x),minY:Math.min(e.minY,i.y),maxY:Math.max(e.maxY,i.y)}),{minX:1/0,maxX:-1/0,minY:1/0,maxY:-1/0})}function sti(t,A,e={}){const i=A instanceof HTMLCanvasElement?A.getContext("2d"):A;if(!i)throw new Error("Could not get 2D context from canvas");const n=A instanceof HTMLCanvasElement?A.width:A.canvas.width,o=A instanceof HTMLCanvasElement?A.height:A.canvas.height;let s;if(e.transform)s=e.transform;else if(e.viewbox)s=sEe(e.viewbox,n,o,{padding:e.padding,yFlip:e.yFlip});else{const r=oti(t),a=t.coordinateSystem==="cartesian";s=sEe(r,n,o,{padding:e.padding??40,yFlip:a})}i.clearRect(0,0,n,o),i.save(),t.rects&&t.rects.length>0&&t.rects.forEach(r=>{const a=r.width/2,g=r.height/2,c=Ce(s,{x:r.center.x-a,y:r.center.y-g}),I=Ce(s,{x:r.center.x+a,y:r.center.y+g}),l=Math.abs(I.x-c.x),B=Math.abs(I.y-c.y);i.beginPath(),i.rect(Math.min(c.x,I.x),Math.min(c.y,I.y),l,B),r.fill&&(i.fillStyle=r.fill,i.fill()),r.stroke&&(i.strokeStyle=r.stroke,i.stroke())}),t.circles&&t.circles.length>0&&t.circles.forEach(r=>{const a=Ce(s,r.center),g=r.radius*Math.abs(s.a);i.beginPath(),i.arc(a.x,a.y,g,0,2*Math.PI),r.fill&&(i.fillStyle=r.fill,i.fill()),r.stroke&&(i.strokeStyle=r.stroke??"transparent",i.stroke())}),t.lines&&t.lines.length>0&&t.lines.forEach((r,a)=>{if(r.points.length===0)return;i.beginPath();const g=Ce(s,r.points[0]);i.moveTo(g.x,g.y);for(let c=1;c<r.points.length;c++){const I=Ce(s,r.points[c]);i.lineTo(I.x,I.y)}if(i.strokeStyle=r.strokeColor||Mz[a%Mz.length],r.strokeWidth?i.lineWidth=r.strokeWidth*s.a:i.lineWidth=2,i.lineCap="round",r.strokeDash)if(typeof r.strokeDash=="string"){let c;if(r.strokeDash.includes(","))c=r.strokeDash.split(",").map(I=>parseFloat(I.trim())).filter(I=>!Number.isNaN(I));else{const I=parseFloat(r.strokeDash.trim());c=Number.isNaN(I)?[]:[I]}i.setLineDash(c)}else i.setLineDash(r.strokeDash.map(c=>c*Math.abs(s.a)));else i.setLineDash([]);i.stroke()}),t.points&&t.points.length>0&&t.points.forEach((r,a)=>{const g=Ce(s,r);i.beginPath(),i.arc(g.x,g.y,3,0,2*Math.PI),i.fillStyle=r.color||Mz[a%Mz.length],i.fill(),r.label&&!e.disableLabels&&(i.fillStyle=r.color||"black",i.font="12px sans-serif",i.fillText(r.label,g.x+5,g.y-5))}),t.texts&&t.texts.length>0&&t.texts.forEach(r=>{const a=Ce(s,{x:r.x,y:r.y});i.fillStyle=r.color||"black",i.font=`${(r.fontSize??12)*Math.abs(s.a)}px sans-serif`;const g=r.anchorSide??"center",c={top_left:"left",center_left:"left",bottom_left:"left",top_center:"center",center:"center",bottom_center:"center",top_right:"right",center_right:"right",bottom_right:"right"},I={top_left:"top",top_center:"top",top_right:"top",center_left:"middle",center:"middle",center_right:"middle",bottom_left:"bottom",bottom_center:"bottom",bottom_right:"bottom"};i.textAlign=c[g],i.textBaseline=I[g],i.fillText(r.text,a.x,a.y)}),i.restore()}var rti=({children:t,transform:A,debugGraphics:e})=>{const i=V.useRef(null),[n,{width:o,height:s}]=qT(),r=gl(a=>a.is_showing_autorouting);return V.useEffect(()=>{r&&i.current&&e&&o&&s&&(i.current.width=o,i.current.height=s,sti(e,i.current,{transform:A,disableLabels:!0}))},[e,A,o,s,r]),r?W.jsxs("div",{ref:n,style:{position:"relative",width:"100%",height:"100%"},children:[t,W.jsx("canvas",{ref:i,style:{position:"absolute",top:0,left:0,opacity:.5,zIndex:100,width:"100%",height:"100%",pointerEvents:"none"}})]}):t},ati=({children:t,transform:A=xa(),elements:e=[]})=>{const[i,{width:n,height:o}]=qT(),s=V.useRef(null);return V.useEffect(()=>{const r=s.current;if(!r||!n||!o)return;r.width=n,r.height=o;const a=r.getContext("2d");if(!a)return;a.clearRect(0,0,n,o);const g=e.filter(I=>I.type==="pcb_component"),c=e.filter(I=>I.type==="pcb_manual_edit_conflict_warning");a.strokeStyle=yn.board.drc_warning,a.lineWidth=2,c.forEach(I=>{const l=g.find(O=>O.pcb_component_id===I.pcb_component_id);if(!l)return;const{width:B,height:C,center:Q}=l,h=Ce(A,Q),E=B*Math.abs(A.a),u=C*Math.abs(A.d),d=.1*Math.abs(A.a),f=E+d*2,y=u+d*2,w=h.x-f/2,D=h.y-y/2;a.beginPath(),a.rect(w,D,f,y),a.stroke();const S="Manual Edit Conflict",_=4,b=Math.max(8,Math.min(12,10*Math.abs(A.a)));a.font=`${b}px sans-serif`;const F=a.measureText(S).width+_*2,L=b+_*2,Y=w+(f-F)/2,J=D+y+5;a.fillStyle="rgba(0, 0, 0, 0.7)",a.beginPath(),a.roundRect(Y,J,F,L,3),a.fill(),a.fillStyle=yn.board.drc_warning,a.textAlign="center",a.textBaseline="middle",a.fillText(S,Y+F/2,J+L/2)})},[e,A,n,o]),W.jsxs("div",{ref:i,style:{position:"relative",width:"100%",height:"100%"},children:[t,W.jsx("canvas",{ref:s,style:{position:"absolute",top:0,left:0,pointerEvents:"none",zIndex:kc.warnings}})]})},Rz=(t,A,e)=>e(t,A),rEe=(t,A,e,i,n)=>{const o=n*Math.PI/180,s=Math.cos(o),r=Math.sin(o),a=t-e,g=A-i,c=a*s-g*r,I=a*r+g*s;return{x:c+e,y:I+i}},OT=t=>{if(t.length===0)return null;let A=t[0].x,e=t[0].x,i=t[0].y,n=t[0].y;for(const o of t)A=Rz(A,o.x,Math.min),e=Rz(e,o.x,Math.max),i=Rz(i,o.y,Math.min),n=Rz(n,o.y,Math.max);return{minX:A,maxX:e,minY:i,maxY:n}},gti=(t,A)=>({minX:Math.min(t.minX,A.minX),maxX:Math.max(t.maxX,A.maxX),minY:Math.min(t.minY,A.minY),maxY:Math.max(t.maxY,A.maxY)}),cti=(t,A)=>t?gti(t,A):A,Iti=t=>{switch(t.pcb_drawing_type){case"line":{const A=(t.width??0)/2,e=[{x:t.x1,y:t.y1},{x:t.x2,y:t.y2}],i=OT(e);return i?{minX:i.minX-A,maxX:i.maxX+A,minY:i.minY-A,maxY:i.maxY+A}:null}case"rect":{const A=t.w/2,e=t.h/2,i=[{x:t.x-A,y:t.y-e},{x:t.x+A,y:t.y-e},{x:t.x+A,y:t.y+e},{x:t.x-A,y:t.y+e}],n=t.ccw_rotation??0,o=n===0?i:i.map(s=>rEe(s.x,s.y,t.x,t.y,n));return OT(o)}case"circle":return{minX:t.x-t.r,maxX:t.x+t.r,minY:t.y-t.r,maxY:t.y+t.r};case"oval":return{minX:t.x-t.rX,maxX:t.x+t.rX,minY:t.y-t.rY,maxY:t.y+t.rY};case"pill":{const A=t.w/2,e=t.h/2,i=[{x:t.x-A,y:t.y-e},{x:t.x+A,y:t.y-e},{x:t.x+A,y:t.y+e},{x:t.x-A,y:t.y+e}],n=t.ccw_rotation??0,o=n===0?i:i.map(s=>rEe(s.x,s.y,t.x,t.y,n));return OT(o)}case"polygon":return OT(t.points);case"polygon_with_arcs":{const A=t.brep_shape.outer_ring.vertices.map(e=>({x:e.x,y:e.y}));return OT(A)}case"text":{const A=t.size??0,e=t.text?t.text.length*A*.6:0,i=A;if(e===0&&i===0)return{minX:t.x,maxX:t.x,minY:t.y,maxY:t.y};const n=e/2,o=i/2;return{minX:t.x-n,maxX:t.x+n,minY:t.y-o,maxY:t.y+o}}default:return null}};function lti(t){const{dimensionStart:A,dimensionEnd:e,screenDimensionStart:i,screenDimensionEnd:n,flipX:o,flipY:s}=t,r=e.x-A.x,a=e.y-A.y,g=Math.sqrt(r*r+a*a),c=n.x-i.x,I=n.y-i.y,l=Math.sqrt(c*c+I*I),B=Math.atan2(I,c)*(180/Math.PI),C=Math.abs(B)%90,h=Math.min(C,90-C)>15,E=(i.x+n.x)/2,u=(i.y+n.y)/2,d=15,f=B+90;let y=Math.cos(f*Math.PI/180)*d,w=Math.sin(f*Math.PI/180)*d;const D=c>0&&I<0,S=c>0&&I>0,_=c<0&&I>0;o!==s&&!D&&(y=-y,w=-w),D&&(y+=Math.cos(f*Math.PI/180)*-45,w+=Math.sin(f*Math.PI/180)*-45),S&&(y+=Math.cos(f*Math.PI/180)+-20,w+=Math.sin(f*Math.PI/180)+-10),_&&(y+=Math.cos(f*Math.PI/180)*10,w+=Math.sin(f*Math.PI/180)*10);const b=E+y,N=u+w;return{distance:g,screenDistance:l,x:b,y:N,show:g>.01&&l>30&&h}}function Bti(t){const{dimensionStart:A,dimensionEnd:e,screenDimensionStart:i,screenDimensionEnd:n,flipX:o,flipY:s}=t;return V.useMemo(()=>lti({dimensionStart:A,dimensionEnd:e,screenDimensionStart:i,screenDimensionEnd:n,flipX:o,flipY:s}),[A,e,i,n,o,s])}var Cti=(t,A,e)=>{const i=e*Math.PI/180,n=Math.cos(i),o=Math.sin(i),s=t.x-A.x,r=t.y-A.y,a=s*n-r*o,g=s*o+r*n;return{x:a+A.x,y:g+A.y}},aEe=(t,A,e,i)=>{const n={top_left:{x:t.x-A,y:t.y-e},top_center:{x:t.x,y:t.y-e},top_right:{x:t.x+A,y:t.y-e},center_left:{x:t.x-A,y:t.y},center:{x:t.x,y:t.y},center_right:{x:t.x+A,y:t.y},bottom_left:{x:t.x-A,y:t.y+e},bottom_center:{x:t.x,y:t.y+e},bottom_right:{x:t.x+A,y:t.y+e}};return i===0?Object.entries(n).map(([o,s])=>({anchor:o,point:s})):Object.entries(n).map(([o,s])=>({anchor:o,point:Cti(s,t,i)}))},Qti=t=>{switch(t.pcb_drawing_type){case"rect":{const A=t.ccw_rotation??0;return aEe({x:t.x,y:t.y},t.w/2,t.h/2,A)}case"pill":{const A=t.ccw_rotation??0;return aEe({x:t.x,y:t.y},t.w/2,t.h/2,A)}case"circle":return[{anchor:"circle_center",point:{x:t.x,y:t.y}},{anchor:"circle_right",point:{x:t.x+t.r,y:t.y}},{anchor:"circle_left",point:{x:t.x-t.r,y:t.y}},{anchor:"circle_top",point:{x:t.x,y:t.y-t.r}},{anchor:"circle_bottom",point:{x:t.x,y:t.y+t.r}}];case"oval":return[{anchor:"oval_center",point:{x:t.x,y:t.y}},{anchor:"oval_right",point:{x:t.x+t.rX,y:t.y}},{anchor:"oval_left",point:{x:t.x-t.rX,y:t.y}},{anchor:"oval_top",point:{x:t.x,y:t.y-t.rY}},{anchor:"oval_bottom",point:{x:t.x,y:t.y+t.rY}}];case"line":{const A={x:(t.x1+t.x2)/2,y:(t.y1+t.y2)/2};return[{anchor:"line_start",point:{x:t.x1,y:t.y1}},{anchor:"line_mid",point:A},{anchor:"line_end",point:{x:t.x2,y:t.y2}}]}case"polygon":return t.points.map((A,e)=>({anchor:`polygon_vertex_${e}`,point:A}));case"polygon_with_arcs":return t.brep_shape.outer_ring.vertices.map((A,e)=>({anchor:`polygon_with_arcs_vertex_${e}`,point:{x:A.x,y:A.y}}));default:return[]}},hti=16,UM=5,gEe=t=>{if(t.pcb_drawing_type==="text")return!0;const A=t._element;if(!A||typeof A!="object")return!1;const e=typeof A.type=="string"?A.type:void 0;return e?!!(e.startsWith("pcb_silkscreen_")||e.startsWith("pcb_note_")||e==="pcb_text"||e.startsWith("pcb_fabrication_note_")&&e!=="pcb_fabrication_note_rect"):!1},Eti=({children:t,transform:A,focusOnHover:e=!1,primitives:i=[]})=>{A||(A=xa());const[n,o]=V.useState(!1),[s,r]=V.useState(!1),[a,g]=V.useState(!1),[c,I]=V.useState({start:null,end:null}),l=gl(J=>J.is_mouse_over_container),B=V.useCallback(()=>{a&&(g(!1),window.dispatchEvent(new Event("disarm-dimension-tool")))},[a]),[C,Q]=V.useState({x:0,y:0}),[h,E]=V.useState({x:0,y:0}),u=V.useRef({x:0,y:0}),d=V.useRef(null),y=d.current?.getBoundingClientRect(),w=V.useMemo(()=>{const J=new Map;for(const O of i){if(!O._element||gEe(O)||O.pcb_drawing_type==="pill"||O.pcb_drawing_type==="rect"&&O.ccw_rotation&&O.ccw_rotation!==0)continue;const Z=Iti(O);if(!Z)continue;const X=J.get(O._element);J.set(O._element,cti(X??void 0,Z))}return J},[i]),D=V.useMemo(()=>{const J=[];for(const O of i){if(!O._element||gEe(O))continue;const Z=Qti(O);if(Z.length!==0)for(const X of Z)J.push({anchor:X.anchor,point:X.point,element:O._element})}return J},[i]),S=V.useMemo(()=>{const J=[];w.forEach((O,Z)=>{if(!O)return;const X=(O.minX+O.maxX)/2,eA=(O.minY+O.maxY)/2,gA={top_left:{x:O.minX,y:O.minY},top_center:{x:X,y:O.minY},top_right:{x:O.maxX,y:O.minY},center_left:{x:O.minX,y:eA},center:{x:X,y:eA},center_right:{x:O.maxX,y:eA},bottom_left:{x:O.minX,y:O.maxY},bottom_center:{x:X,y:O.maxY},bottom_right:{x:O.maxX,y:O.maxY}};for(const[tA,iA]of Object.entries(gA))J.push({anchor:tA,point:iA,element:Z})});for(const O of D)J.push(O);return J.push({anchor:"origin",point:{x:0,y:0},element:null}),J},[w,D]),_=V.useMemo(()=>S.map((J,O)=>({...J,id:`${O}-${J.anchor}`,screenPoint:Ce(A,J.point)})),[S,A]),b=V.useCallback(J=>{if(_.length===0)return{point:J,id:null};const O=Ce(A,J);let Z=null;for(const X of _){const eA=X.screenPoint.x-O.x,gA=X.screenPoint.y-O.y,tA=Math.hypot(eA,gA);tA>hti||(!Z||tA<Z.distance)&&(Z={distance:tA,id:X.id,point:X.point})}return Z?{point:Z.point,id:Z.id}:{point:J,id:null}},[_,A]);V.useEffect(()=>{const J=Z=>{const X=Z.target;if(X.tagName==="INPUT"||X.tagName==="TEXTAREA"||X.isContentEditable)return;const eA=d.current?.contains(document.activeElement)||document.activeElement===d.current;if(!(!l&&!eA)){if(Z.key==="d"){const gA=b({x:u.current.x,y:u.current.y});Q({x:gA.point.x,y:gA.point.y}),E({x:gA.point.x,y:gA.point.y}),I({start:gA.id,end:gA.id}),n?(o(!1),r(!1),I({start:null,end:null})):(o(!0),r(!0)),B()}Z.key==="Escape"&&(o(!1),r(!1),I({start:null,end:null}),B())}},O=()=>{g(!0)};return window.addEventListener("keydown",J),window.addEventListener("arm-dimension-tool",O),()=>{window.removeEventListener("keydown",J),window.removeEventListener("arm-dimension-tool",O),B()}},[l,n,B,b]);const N=Ce(A,C),F=Ce(A,h),L={left:Math.min(N.x,F.x),right:Math.max(N.x,F.x),top:Math.min(N.y,F.y),bottom:Math.max(N.y,F.y),flipX:N.x>F.x,flipY:N.y>F.y,width:0,height:0};L.width=L.right-L.left,L.height=L.bottom-L.top;const Y=Bti({dimensionStart:C,dimensionEnd:h,screenDimensionStart:N,screenDimensionEnd:F,flipX:L.flipX,flipY:L.flipY});return W.jsxs("div",{ref:d,"data-pcb-viewer":!0,tabIndex:0,style:{position:"relative",outline:"none"},onMouseEnter:()=>{e&&d.current&&d.current.focus()},onMouseLeave:()=>{d.current&&d.current.blur()},onClick:()=>{d.current&&d.current.focus()},onMouseMove:J=>{const O=J.currentTarget.getBoundingClientRect(),Z=J.clientX-O.left,X=J.clientY-O.top,eA=Ce(tm(A),{x:Z,y:X});if(u.current.x=eA.x,u.current.y=eA.y,s){const gA=b(eA);E({x:gA.point.x,y:gA.point.y}),I(tA=>({...tA,end:gA.id}))}},onMouseDown:J=>{const O=J.currentTarget.getBoundingClientRect(),Z=J.clientX-O.left,X=J.clientY-O.top,eA=Ce(tm(A),{x:Z,y:X});if(a&&!n){const gA=b(eA);Q({x:gA.point.x,y:gA.point.y}),E({x:gA.point.x,y:gA.point.y}),I({start:gA.id,end:gA.id}),o(!0),r(!0),B()}else s?(r(!1),I(gA=>({...gA,end:null}))):n&&(o(!1),I({start:null,end:null}))},children:[t,n&&W.jsxs(W.Fragment,{children:[Y.show&&W.jsx("div",{style:{position:"absolute",left:Y.x,top:Y.y,color:"red",mixBlendMode:"difference",pointerEvents:"none",fontSize:12,fontFamily:"sans-serif",whiteSpace:"nowrap",zIndex:kc.dimensionOverlay},children:Y.distance.toFixed(2)}),W.jsx("div",{style:{position:"absolute",left:L.left,width:L.width,textAlign:"center",top:N.y+2,color:"red",mixBlendMode:"difference",pointerEvents:"none",marginTop:L.flipY?0:-20,fontSize:12,fontFamily:"sans-serif",zIndex:kc.dimensionOverlay},children:Math.abs(C.x-h.x).toFixed(2)}),W.jsx("div",{style:{position:"absolute",left:F.x,height:L.height,display:"flex",flexDirection:"column",justifyContent:"center",top:L.top,color:"red",pointerEvents:"none",mixBlendMode:"difference",fontSize:12,fontFamily:"sans-serif",zIndex:kc.dimensionOverlay},children:W.jsx("div",{style:{marginLeft:L.flipX?"-100%":4,paddingRight:4},children:Math.abs(C.y-h.y).toFixed(2)})}),W.jsxs("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none",mixBlendMode:"difference",zIndex:kc.dimensionOverlay},width:y.width,height:y.height,children:[W.jsx("defs",{children:W.jsx("marker",{id:"head",orient:"auto",markerWidth:"3",markerHeight:"4",refX:"2",refY:"2",children:W.jsx("path",{d:"M0,0 V4 L2,2 Z",fill:"red"})})}),W.jsx("line",{x1:N.x,y1:N.y,x2:F.x,y2:F.y,markerEnd:"url(#head)",strokeWidth:1.5,fill:"none",stroke:"red"}),W.jsx("line",{x1:N.x,y1:N.y,x2:F.x,y2:N.y,strokeWidth:1.5,fill:"none",strokeDasharray:"2,2",stroke:"red"}),W.jsx("line",{x1:F.x,y1:N.y,x2:F.x,y2:F.y,strokeWidth:1.5,fill:"none",strokeDasharray:"2,2",stroke:"red"})]}),s&&_.map(J=>{const O=J.id===c.start||J.id===c.end,Z=UM/2;return W.jsxs("svg",{width:UM,height:UM,style:{position:"absolute",left:J.screenPoint.x-Z,top:J.screenPoint.y-Z,pointerEvents:"none",zIndex:kc.dimensionOverlay},children:[W.jsx("line",{x1:0,y1:0,x2:UM,y2:UM,stroke:O?"#66ccff":"white",strokeWidth:1}),W.jsx("line",{x1:UM,y1:0,x2:0,y2:UM,stroke:O?"#66ccff":"white",strokeWidth:1})]},J.id)}),W.jsxs("div",{style:{right:0,bottom:0,position:"absolute",color:"red",fontFamily:"sans-serif",fontSize:12,margin:4},children:["(",C.x.toFixed(2),",",C.y.toFixed(2),")",W.jsx("br",{}),"(",h.x.toFixed(2),",",h.y.toFixed(2),")",W.jsx("br",{}),"dist:"," ",Math.sqrt((h.x-C.x)**2+(h.y-C.y)**2).toFixed(2)]})]})]})},uti=(t,A,e=0)=>{const i=t.width/2,n=t.height/2,o=t.center.x-i-e,s=t.center.x+i+e,r=t.center.y-n-e,a=t.center.y+n+e;return A.x>o&&A.x<s&&A.y>r&&A.y<a},dti=({children:t,disabled:A,transform:e,soup:i,cancelPanDrag:n,onCreateEditEvent:o,onModifyEditEvent:s})=>{e||(e=xa());const r=V.useRef(null),[a,g]=V.useState(null),[c,I]=V.useState(null),l=a!==null;gl(h=>h.in_edit_mode);const B=gl(h=>h.in_move_footprint_mode),C=gl(h=>h.setIsMovingComponent),Q=A||!B;return W.jsxs("div",{ref:r,style:{position:"relative",overflow:"hidden"},onMouseDown:h=>{if(Q)return;const E=h.currentTarget.getBoundingClientRect(),u=h.clientX-E.left,d=h.clientY-E.top;if(Number.isNaN(u)||Number.isNaN(d))return;const f=Ce(tm(e),{x:u,y:d});let y=!1;for(const w of i)if(w.type==="pcb_component"&&uti(w,f,10/e.a)){n(),g(w.pcb_component_id),y=!0;const D=Math.random().toString();I({dragStart:f,originalCenter:w.center,dragEnd:f,edit_event_id:D}),o({edit_event_id:D,edit_event_type:"edit_pcb_component_location",pcb_edit_event_type:"edit_component_location",pcb_component_id:w.pcb_component_id,original_center:w.center,new_center:w.center,in_progress:!0,created_at:Date.now()}),C(!0);break}if(y||g(null),y)return h.preventDefault(),!1},onMouseMove:h=>{if(!a||!c)return;const E=h.currentTarget.getBoundingClientRect(),u=h.clientX-E.left,d=h.clientY-E.top;if(Number.isNaN(u)||Number.isNaN(d))return;const f=Ce(tm(e),{x:u,y:d});I({...c,dragEnd:f}),s({edit_event_id:c.edit_event_id,new_center:{x:c.originalCenter.x+f.x-c.dragStart.x,y:c.originalCenter.y+f.y-c.dragStart.y}})},onMouseUp:h=>{a&&(g(null),C(!1),c&&(s({edit_event_id:c.edit_event_id,in_progress:!1}),I(null)))},children:[t,!Q&&i.filter(h=>h.type==="pcb_component").map(h=>{if(!h?.center)return null;const E=Ce(e,h.center);return W.jsx("div",{style:{position:"absolute",pointerEvents:"none",left:E.x,top:E.y,width:h.width*e.a+20,height:h.height*e.a+20,transform:"translate(-50%, -50%)",background:l&&a===h.pcb_component_id?"rgba(255, 0, 0, 0.2)":""}},h.pcb_component_id)})]})},pti=({hotkeys:t})=>(V.useEffect(()=>{const A=e=>{t.forEach(i=>{e.key===i.key&&i.onUse()})};return window.addEventListener("keydown",A),()=>{window.removeEventListener("keydown",A)}},[t]),W.jsx("div",{className:D2`
|
|
5436
|
+
$1`).replace(/>(\s*)(?=<!--\s*\/)/g,"> ")}}});function Nhe(t,A,e){if(!A||!e)return;let i=t.get(A);i||(i=new Set,t.set(A,i)),i.add(e);let n=t.get(e);n||(n=new Set,t.set(e,n)),n.add(A)}function bAi(t,A){if(!A.subcircuit_id&&!A.source_group_id)return[...t];let e=A;if(A.subcircuit_id){const r=new Set([A.subcircuit_id]),a=new Map,g=new Map;for(const I of t)if(I.type==="source_group"){const l=I.source_group_id,B=I.subcircuit_id;B&&g.set(l,B);const C=I.parent_source_group_id;C&&(a.has(C)||a.set(C,[]),a.get(C).push(l))}let c;for(const[I,l]of g)if(l===A.subcircuit_id){c=I;break}if(c){const I=l=>{const B=a.get(l)||[];for(const C of B){const Q=g.get(C);Q&&r.add(Q),I(C)}};I(c),e={...A,subcircuit_ids:Array.from(r)}}}const i=new Map;for(const r of t){const a=`${r.type}_id`,g=r[a];typeof g=="string"&&i.set(g,r)}const n=new Map;for(const r of t){const a=Object.entries(r);for(const[g,c]of a)if(g!=="parent_source_group_id"){if(g.endsWith("_id")&&typeof c=="string"){const I=i.get(c);Nhe(n,r,I)}else if(g.endsWith("_ids")&&Array.isArray(c)){for(const I of c)if(typeof I=="string"){const l=i.get(I);Nhe(n,r,l)}}}}const o=[],s=new Set;for(const r of t){let a=!1;(e.subcircuit_id&&"subcircuit_id"in r&&r.subcircuit_id===e.subcircuit_id||e.subcircuit_ids&&"subcircuit_id"in r&&r.subcircuit_id&&e.subcircuit_ids.includes(r.subcircuit_id)||e.source_group_id&&"source_group_id"in r&&r.source_group_id===e.source_group_id||e.source_group_id&&"member_source_group_ids"in r&&Array.isArray(r.member_source_group_ids)&&r.member_source_group_ids.includes(e.source_group_id))&&(a=!0),a&&(o.push(r),s.add(r))}for(;o.length>0;){const r=o.shift(),a=n.get(r);if(a)for(const g of a)s.has(g)||(s.add(g),o.push(g))}return t.filter(r=>s.has(r))}var _z=(t,A={})=>{const e=t;let i=e._internal_store;if(!i){i={counts:{},editCount:0},e._internal_store=i;for(const o of e){const s=o.type,r=o[`${s}_id`];if(!r)continue;const a=Number.parseInt(r.split("_").pop());Number.isNaN(a)||(i.counts[s]=Math.max(i.counts[s]??0,a))}}const n=new Proxy({},{get:(o,s)=>{if(s==="toArray")return()=>(e.editCount=i.editCount,e);if(s==="editCount")return i.editCount;if(s==="subtree")return a=>_z(bAi(e,a),A);if(s==="insert")return a=>{const g=a.type;if(!g)throw new Error("insert requires an element with a type");i.counts[g]??=-1,i.counts[g]++;const c=i.counts[g],I={...a,type:g,[`${g}_id`]:`${g}_${c}`};return A.validateInserts&&(JyA[g]??tz).parse(I),e.push(I),i.editCount++,I};if(s==="insertAll")return a=>a.map(g=>n.insert(g));const r=s;return{get:a=>e.find(g=>g.type===r&&g[`${r}_id`]===a),getUsing:a=>{const g=Object.keys(a);if(g.length!==1)throw new Error("getUsing requires exactly one key, e.g. { pcb_component_id }");const c=g[0],I=c.replace("_id",""),l=e.find(B=>B.type===I&&B[c]===a[c]);return l?e.find(B=>B.type===r&&B[`${r}_id`]===l[`${r}_id`]):null},getWhere:a=>{const g=Object.keys(a);return e.find(c=>c.type===r&&g.every(I=>c[I]===a[I]))},list:a=>{const g=a?Object.keys(a):[];return e.filter(c=>c.type===r&&g.every(I=>c[I]===a[I]))},insert:a=>{i.counts[r]??=-1,i.counts[r]++;const g=i.counts[r],c={type:r,[`${r}_id`]:`${r}_${g}`,...a};return A.validateInserts&&(JyA[r]??tz).parse(c),e.push(c),i.editCount++,c},delete:a=>{const g=e.find(c=>c[`${r}_id`]===a);g&&(e.splice(e.indexOf(g),1),i.editCount++)},update:(a,g)=>{const c=e.find(I=>I.type===r&&I[`${r}_id`]===a);return c?(Object.assign(c,g),i.editCount++,c):null},select:a=>{if(r==="source_component")return e.find(g=>g.type==="source_component"&&g.name===a.replace(/\./g,""));if(r==="pcb_port"||r==="source_port"||r==="schematic_port"){const[g,c]=a.replace(/\./g,"").split(/[\s\>]+/),I=e.find(B=>B.type==="source_component"&&B.name===g);if(!I)return null;const l=e.find(B=>B.type==="source_port"&&B.source_component_id===I.source_component_id&&(B.name===c||(B.port_hints??[]).includes(c)));if(!l)return null;if(r==="source_port")return l;if(r==="pcb_port")return e.find(B=>B.type==="pcb_port"&&B.source_port_id===l.source_port_id);if(r==="schematic_port")return e.find(B=>B.type==="schematic_port"&&B.source_port_id===l.source_port_id)}}}}});return n};_z.unparsed=_z;var rx=_z;function dmA(t){const A=t.type;return`${A}:${t[`${A}_id`]}`}var Ghe=(t,A={})=>{let e=t._internal_store_indexed;if(!e){e={counts:{},editCount:0,indexes:{}};for(const s of t){const r=s.type,a=s[`${r}_id`];if(!a)continue;const g=Number.parseInt(a.split("_").pop()||"");Number.isNaN(g)||(e.counts[r]=Math.max(e.counts[r]??0,g))}const n=A.indexConfig||{},o=e.indexes;if(n.byId&&(o.byId=new Map),n.byType&&(o.byType=new Map),n.byRelation&&(o.byRelation=new Map),n.bySubcircuit&&(o.bySubcircuit=new Map),n.byCustomField&&n.byCustomField.length>0){o.byCustomField=new Map;for(const s of n.byCustomField)o.byCustomField.set(s,new Map)}for(const s of t){if(n.byId){const r=dmA(s);o.byId.set(r,s)}if(n.byType){const r=o.byType.get(s.type)||[];r.push(s),o.byType.set(s.type,r)}if(n.byRelation){const r=Object.entries(s);for(const[a,g]of r)if(a.endsWith("_id")&&a!==`${s.type}_id`&&typeof g=="string"){const c=o.byRelation.get(a)||new Map,I=c.get(g)||[];I.push(s),c.set(g,I),o.byRelation.set(a,c)}}if(n.bySubcircuit&&"subcircuit_id"in s){const r=s.subcircuit_id;if(r&&typeof r=="string"){const a=o.bySubcircuit.get(r)||[];a.push(s),o.bySubcircuit.set(r,a)}}if(n.byCustomField&&o.byCustomField){for(const r of n.byCustomField)if(r in s){const a=s[r];if(a!==void 0&&(typeof a=="string"||typeof a=="number")){const g=String(a),c=o.byCustomField.get(r),I=c.get(g)||[];I.push(s),c.set(g,I)}}}}t._internal_store_indexed=e}return new Proxy({},{get:(n,o)=>{if(o==="toArray")return()=>(t.editCount=e.editCount,t);if(o==="editCount")return e.editCount;const s=o;return{get:r=>{const a=A.indexConfig||{};return a.byId&&e.indexes.byId?e.indexes.byId.get(`${s}:${r}`)||null:a.byType&&e.indexes.byType?(e.indexes.byType.get(s)||[]).find(c=>c[`${s}_id`]===r)||null:t.find(g=>g.type===s&&g[`${s}_id`]===r)||null},getUsing:r=>{const a=A.indexConfig||{},g=Object.keys(r);if(g.length!==1)throw new Error("getUsing requires exactly one key, e.g. { pcb_component_id }");const c=g[0],I=c.replace("_id","");if(a.byRelation&&e.indexes.byRelation){const B=e.indexes.byRelation.get(c);if(B){const Q=(B.get(r[c])||[]).find(E=>E.type===I);if(!Q)return null;const h=Q[`${s}_id`];return a.byId&&e.indexes.byId?e.indexes.byId.get(`${s}:${h}`)||null:a.byType&&e.indexes.byType?(e.indexes.byType.get(s)||[]).find(u=>u[`${s}_id`]===h)||null:t.find(E=>E.type===s&&E[`${s}_id`]===h)||null}}const l=t.find(B=>B.type===I&&B[c]===r[c]);return l&&t.find(B=>B.type===s&&B[`${s}_id`]===l[`${s}_id`])||null},getWhere:r=>{const a=A.indexConfig||{},g=Object.keys(r);if(g.length===1&&a.byCustomField&&e.indexes.byCustomField){const c=g[0],I=e.indexes.byCustomField.get(c);if(I){const l=String(r[c]);return(I.get(l)||[]).find(C=>C.type===s)||null}}if("subcircuit_id"in r&&a.bySubcircuit&&e.indexes.bySubcircuit){const c=r.subcircuit_id;return(e.indexes.bySubcircuit.get(c)||[]).find(l=>l.type===s&&g.every(B=>l[B]===r[B]))||null}return a.byType&&e.indexes.byType?(e.indexes.byType.get(s)||[]).find(I=>g.every(l=>I[l]===r[l]))||null:t.find(c=>c.type===s&&g.every(I=>c[I]===r[I]))||null},list:r=>{const a=A.indexConfig||{},g=r?Object.keys(r):[];if(g.length===0&&a.byType&&e.indexes.byType)return e.indexes.byType.get(s)||[];if(g.length===1&&g[0]==="subcircuit_id"&&a.bySubcircuit&&e.indexes.bySubcircuit){const I=r.subcircuit_id;return(e.indexes.bySubcircuit.get(I)||[]).filter(B=>B.type===s)}let c;return a.byType&&e.indexes.byType?c=e.indexes.byType.get(s)||[]:c=t.filter(I=>I.type===s),g.length>0?c.filter(I=>g.every(l=>I[l]===r[l])):c},insert:r=>{e.counts[s]??=-1,e.counts[s]++;const a=e.counts[s],g={type:s,[`${s}_id`]:`${s}_${a}`,...r};A.validateInserts&&(JyA[s]??tz).parse(g),t.push(g),e.editCount++;const c=A.indexConfig||{};if(c.byId&&e.indexes.byId){const I=dmA(g);e.indexes.byId.set(I,g)}if(c.byType&&e.indexes.byType){const I=e.indexes.byType.get(s)||[];I.push(g),e.indexes.byType.set(s,I)}if(c.byRelation&&e.indexes.byRelation){const I=Object.entries(g);for(const[l,B]of I)if(l.endsWith("_id")&&l!==`${g.type}_id`&&typeof B=="string"){const C=e.indexes.byRelation.get(l)||new Map,Q=C.get(B)||[];Q.push(g),C.set(B,Q),e.indexes.byRelation.set(l,C)}}if(c.bySubcircuit&&e.indexes.bySubcircuit&&"subcircuit_id"in g){const I=g.subcircuit_id;if(I&&typeof I=="string"){const l=e.indexes.bySubcircuit.get(I)||[];l.push(g),e.indexes.bySubcircuit.set(I,l)}}if(c.byCustomField&&e.indexes.byCustomField){for(const I of c.byCustomField)if(I in g){const l=g[I];if(l!==void 0&&(typeof l=="string"||typeof l=="number")){const B=String(l),C=e.indexes.byCustomField.get(I),Q=C.get(B)||[];Q.push(g),C.set(B,Q)}}}return g},delete:r=>{const a=A.indexConfig||{};let g;if(a.byId&&e.indexes.byId?g=e.indexes.byId.get(`${s}:${r}`):a.byType&&e.indexes.byType?g=(e.indexes.byType.get(s)||[]).find(l=>l[`${s}_id`]===r):g=t.find(I=>I[`${s}_id`]===r),!g)return;const c=t.indexOf(g);if(c>=0&&(t.splice(c,1),e.editCount++),a.byId&&e.indexes.byId){const I=dmA(g);e.indexes.byId.delete(I)}if(a.byType&&e.indexes.byType){const l=(e.indexes.byType.get(s)||[]).filter(B=>B[`${s}_id`]!==r);e.indexes.byType.set(s,l)}if(a.byRelation&&e.indexes.byRelation)for(const[I,l]of e.indexes.byRelation.entries())for(const[B,C]of l.entries()){const Q=C.filter(h=>h!==g);Q.length===0?l.delete(B):l.set(B,Q)}if(a.bySubcircuit&&e.indexes.bySubcircuit&&"subcircuit_id"in g){const I=g.subcircuit_id;if(I){const B=(e.indexes.bySubcircuit.get(I)||[]).filter(C=>C!==g);B.length===0?e.indexes.bySubcircuit.delete(I):e.indexes.bySubcircuit.set(I,B)}}if(a.byCustomField&&e.indexes.byCustomField)for(const I of e.indexes.byCustomField.values())for(const[l,B]of I.entries()){const C=B.filter(Q=>Q!==g);C.length===0?I.delete(l):I.set(l,C)}},update:(r,a)=>{const g=A.indexConfig||{};let c;if(g.byId&&e.indexes.byId?c=e.indexes.byId.get(`${s}:${r}`):g.byType&&e.indexes.byType?c=(e.indexes.byType.get(s)||[]).find(l=>l[`${s}_id`]===r):c=t.find(I=>I.type===s&&I[`${s}_id`]===r),!c)return null;if(g.byRelation&&e.indexes.byRelation){const I=Object.entries(c);for(const[l,B]of I)if(l.endsWith("_id")&&l!==`${c.type}_id`&&typeof B=="string"&&l in a&&a[l]!==B){const C=e.indexes.byRelation.get(l);if(C){const h=(C.get(B)||[]).filter(E=>E!==c);h.length===0?C.delete(B):C.set(B,h)}}}if(g.bySubcircuit&&e.indexes.bySubcircuit&&"subcircuit_id"in c&&"subcircuit_id"in a){const I=c.subcircuit_id,l=a.subcircuit_id;if(I!==l){const C=(e.indexes.bySubcircuit.get(I)||[]).filter(Q=>Q!==c);C.length===0?e.indexes.bySubcircuit.delete(I):e.indexes.bySubcircuit.set(I,C)}}if(g.byCustomField&&e.indexes.byCustomField){for(const I of g.byCustomField)if(I in c&&I in a&&c[I]!==a[I]){const l=e.indexes.byCustomField.get(I);if(l){const B=String(c[I]),Q=(l.get(B)||[]).filter(h=>h!==c);Q.length===0?l.delete(B):l.set(B,Q)}}}if(Object.assign(c,a),e.editCount++,g.byRelation&&e.indexes.byRelation){const I=Object.entries(c);for(const[l,B]of I)if(l.endsWith("_id")&&l!==`${c.type}_id`&&typeof B=="string"&&l in a){const C=e.indexes.byRelation.get(l)||new Map,Q=C.get(B)||[];Q.includes(c)||(Q.push(c),C.set(B,Q),e.indexes.byRelation.set(l,C))}}if(g.bySubcircuit&&e.indexes.bySubcircuit&&"subcircuit_id"in c&&"subcircuit_id"in a){const I=c.subcircuit_id;if(I&&typeof I=="string"){const l=e.indexes.bySubcircuit.get(I)||[];l.includes(c)||(l.push(c),e.indexes.bySubcircuit.set(I,l))}}if(g.byCustomField&&e.indexes.byCustomField){for(const I of g.byCustomField)if(I in c&&I in a){const l=c[I];if(l!==void 0&&(typeof l=="string"||typeof l=="number")){const B=String(l),C=e.indexes.byCustomField.get(I),Q=C.get(B)||[];Q.includes(c)||(Q.push(c),C.set(B,Q))}}}return c},select:r=>{if(s==="source_component")return t.find(a=>a.type==="source_component"&&a.name===r.replace(/\./g,""))||null;if(s==="pcb_port"||s==="source_port"||s==="schematic_port"){const[a,g]=r.replace(/\./g,"").split(/[\s\>]+/),c=t.find(l=>l.type==="source_component"&&l.name===a);if(!c)return null;const I=t.find(l=>l.type==="source_port"&&l.source_component_id===c.source_component_id&&(l.name===g||(l.port_hints??[]).includes(g)));if(!I)return null;if(s==="source_port")return I;if(s==="pcb_port")return t.find(l=>l.type==="pcb_port"&&l.source_port_id===I.source_port_id)||null;if(s==="schematic_port")return t.find(l=>l.type==="schematic_port"&&l.source_port_id===I.source_port_id)||null}return null}}}})};Ghe.unparsed=Ghe;var xAi=t=>{const A=t.type;return t[`${A}_id`]},Lhe=(t,A)=>({minX:Math.min(t.minX,A.minX),minY:Math.min(t.minY,A.minY),maxX:Math.max(t.maxX,A.maxX),maxY:Math.max(t.maxY,A.maxY)}),kz=(t,A,e)=>{const i=e/2;return{minX:t-i,minY:A-i,maxX:t+i,maxY:A+i}},_Ai=(t,A,e,i,n)=>{const o=e/2,s=i/2,r=n*Math.PI/180,a=Math.cos(r),g=Math.sin(r),c=[{x:-o,y:-s},{x:o,y:-s},{x:o,y:s},{x:-o,y:s}].map(I=>({x:t+I.x*a-I.y*g,y:A+I.x*g+I.y*a}));return{minX:Math.min(...c.map(I=>I.x)),minY:Math.min(...c.map(I=>I.y)),maxX:Math.max(...c.map(I=>I.x)),maxY:Math.max(...c.map(I=>I.y))}},pmA=t=>{let A=Number.POSITIVE_INFINITY,e=Number.POSITIVE_INFINITY,i=Number.NEGATIVE_INFINITY,n=Number.NEGATIVE_INFINITY;for(const o of t){if(!o.type.startsWith("pcb_"))continue;if(o.type==="pcb_smtpad"&&o.shape==="polygon"&&Array.isArray(o.points)){for(const c of o.points)A=Math.min(A,c.x),e=Math.min(e,c.y),i=Math.max(i,c.x),n=Math.max(n,c.y);continue}if(o.type==="pcb_hole"&&o.hole_shape==="circle"){const c=kz(o.x,o.y,o.hole_diameter);A=Math.min(A,c.minX),e=Math.min(e,c.minY),i=Math.max(i,c.maxX),n=Math.max(n,c.maxY);continue}if(o.type==="pcb_plated_hole"){let c;if("outer_diameter"in o&&typeof o.outer_diameter=="number"?c=kz(o.x,o.y,o.outer_diameter):"hole_diameter"in o&&typeof o.hole_diameter=="number"&&(c=kz(o.x,o.y,o.hole_diameter)),"rect_pad_width"in o&&typeof o.rect_pad_width=="number"&&"rect_pad_height"in o&&typeof o.rect_pad_height=="number"){const I=_Ai(o.x,o.y,o.rect_pad_width,o.rect_pad_height,"rect_ccw_rotation"in o?o.rect_ccw_rotation??0:0);c=c?Lhe(c,I):I}if("hole_diameter"in o&&typeof o.hole_diameter=="number"){const I=kz(o.x+("hole_offset_x"in o?o.hole_offset_x??0:0),o.y+("hole_offset_y"in o?o.hole_offset_y??0:0),o.hole_diameter);c=c?Lhe(c,I):I}if(c){A=Math.min(A,c.minX),e=Math.min(e,c.minY),i=Math.max(i,c.maxX),n=Math.max(n,c.maxY);continue}}let s,r,a,g;if("x"in o&&"y"in o&&(s=Number(o.x),r=Number(o.y)),"outer_diameter"in o&&(a=Number(o.outer_diameter),g=Number(o.outer_diameter)),"width"in o&&(a=Number(o.width)),"height"in o&&(g=Number(o.height)),"center"in o&&(s=o.center.x,r=o.center.y),s!==void 0&&r!==void 0)A=Math.min(A,s),e=Math.min(e,r),i=Math.max(i,s),n=Math.max(n,r),a!==void 0&&g!==void 0&&(A=Math.min(A,s-a/2),e=Math.min(e,r-g/2),i=Math.max(i,s+a/2),n=Math.max(n,r+g/2)),"radius"in o&&(A=Math.min(A,s-o.radius),e=Math.min(e,r-o.radius),i=Math.max(i,s+o.radius),n=Math.max(n,r+o.radius));else if(o.type==="pcb_trace")for(const c of o.route)A=Math.min(A,c.x),e=Math.min(e,c.y),i=Math.max(i,c.x),n=Math.max(n,c.y);else if(o.type==="pcb_courtyard_outline")for(const c of o.outline)A=Math.min(A,c.x),e=Math.min(e,c.y),i=Math.max(i,c.x),n=Math.max(n,c.y);else if(o.type==="pcb_courtyard_polygon")for(const c of o.points)A=Math.min(A,c.x),e=Math.min(e,c.y),i=Math.max(i,c.x),n=Math.max(n,c.y)}return{minX:A,minY:e,maxX:i,maxY:n}};function kAi(t){let A=0;if(t.length==0)return A;for(var e=0;e<t.length;e++){var i=t.charCodeAt(e);A=(A<<5)-A+i,A=A&A}return Math.abs(A)}var Uhe=[["#69d2e7","#a7dbd8","#e0e4cc","#f38630","#fa6900"],["#fe4365","#fc9d9a","#f9cdad","#c8c8a9","#83af9b"],["#ecd078","#d95b43","#c02942","#542437","#53777a"],["#556270","#4ecdc4","#c7f464","#ff6b6b","#c44d58"],["#774f38","#e08e79","#f1d4af","#ece5ce","#c5e0dc"],["#e8ddcb","#cdb380","#036564","#033649","#031634"],["#490a3d","#bd1550","#e97f02","#f8ca00","#8a9b0f"],["#594f4f","#547980","#45ada8","#9de0ad","#e5fcc2"],["#00a0b0","#6a4a3c","#cc333f","#eb6841","#edc951"],["#e94e77","#d68189","#c6a49a","#c6e5d9","#f4ead5"],["#3fb8af","#7fc7af","#dad8a7","#ff9e9d","#ff3d7f"],["#d9ceb2","#948c75","#d5ded9","#7a6a53","#99b2b7"],["#ffffff","#cbe86b","#f2e9e1","#1c140d","#cbe86b"],["#efffcd","#dce9be","#555152","#2e2633","#99173c"],["#343838","#005f6b","#008c9e","#00b4cc","#00dffc"],["#413e4a","#73626e","#b38184","#f0b49e","#f7e4be"],["#ff4e50","#fc913a","#f9d423","#ede574","#e1f5c4"],["#99b898","#fecea8","#ff847c","#e84a5f","#2a363b"],["#655643","#80bca3","#f6f7bd","#e6ac27","#bf4d28"],["#00a8c6","#40c0cb","#f9f2e7","#aee239","#8fbe00"],["#351330","#424254","#64908a","#e8caa4","#cc2a41"],["#554236","#f77825","#d3ce3d","#f1efa5","#60b99a"],["#5d4157","#838689","#a8caba","#cad7b2","#ebe3aa"],["#8c2318","#5e8c6a","#88a65e","#bfb35a","#f2c45a"],["#fad089","#ff9c5b","#f5634a","#ed303c","#3b8183"],["#ff4242","#f4fad2","#d4ee5e","#e1edb9","#f0f2eb"],["#f8b195","#f67280","#c06c84","#6c5b7b","#355c7d"],["#d1e751","#ffffff","#000000","#4dbce9","#26ade4"],["#1b676b","#519548","#88c425","#bef202","#eafde6"],["#5e412f","#fcebb6","#78c0a8","#f07818","#f0a830"],["#bcbdac","#cfbe27","#f27435","#f02475","#3b2d38"],["#452632","#91204d","#e4844a","#e8bf56","#e2f7ce"],["#eee6ab","#c5bc8e","#696758","#45484b","#36393b"],["#f0d8a8","#3d1c00","#86b8b1","#f2d694","#fa2a00"],["#2a044a","#0b2e59","#0d6759","#7ab317","#a0c55f"],["#f04155","#ff823a","#f2f26f","#fff7bd","#95cfb7"],["#b9d7d9","#668284","#2a2829","#493736","#7b3b3b"],["#bbbb88","#ccc68d","#eedd99","#eec290","#eeaa88"],["#b3cc57","#ecf081","#ffbe40","#ef746f","#ab3e5b"],["#a3a948","#edb92e","#f85931","#ce1836","#009989"],["#300030","#480048","#601848","#c04848","#f07241"],["#67917a","#170409","#b8af03","#ccbf82","#e33258"],["#aab3ab","#c4cbb7","#ebefc9","#eee0b7","#e8caaf"],["#e8d5b7","#0e2430","#fc3a51","#f5b349","#e8d5b9"],["#ab526b","#bca297","#c5ceae","#f0e2a4","#f4ebc3"],["#607848","#789048","#c0d860","#f0f0d8","#604848"],["#b6d8c0","#c8d9bf","#dadabd","#ecdbbc","#fedcba"],["#a8e6ce","#dcedc2","#ffd3b5","#ffaaa6","#ff8c94"],["#3e4147","#fffedf","#dfba69","#5a2e2e","#2a2c31"],["#fc354c","#29221f","#13747d","#0abfbc","#fcf7c5"],["#cc0c39","#e6781e","#c8cf02","#f8fcc1","#1693a7"],["#1c2130","#028f76","#b3e099","#ffeaad","#d14334"],["#a7c5bd","#e5ddcb","#eb7b59","#cf4647","#524656"],["#dad6ca","#1bb0ce","#4f8699","#6a5e72","#563444"],["#5c323e","#a82743","#e15e32","#c0d23e","#e5f04c"],["#edebe6","#d6e1c7","#94c7b6","#403b33","#d3643b"],["#fdf1cc","#c6d6b8","#987f69","#e3ad40","#fcd036"],["#230f2b","#f21d41","#ebebbc","#bce3c5","#82b3ae"],["#b9d3b0","#81bda4","#b28774","#f88f79","#f6aa93"],["#3a111c","#574951","#83988e","#bcdea5","#e6f9bc"],["#5e3929","#cd8c52","#b7d1a3","#dee8be","#fcf7d3"],["#1c0113","#6b0103","#a30006","#c21a01","#f03c02"],["#000000","#9f111b","#b11623","#292c37","#cccccc"],["#382f32","#ffeaf2","#fcd9e5","#fbc5d8","#f1396d"],["#e3dfba","#c8d6bf","#93ccc6","#6cbdb5","#1a1f1e"],["#f6f6f6","#e8e8e8","#333333","#990100","#b90504"],["#1b325f","#9cc4e4","#e9f2f9","#3a89c9","#f26c4f"],["#a1dbb2","#fee5ad","#faca66","#f7a541","#f45d4c"],["#c1b398","#605951","#fbeec2","#61a6ab","#accec0"],["#5e9fa3","#dcd1b4","#fab87f","#f87e7b","#b05574"],["#951f2b","#f5f4d7","#e0dfb1","#a5a36c","#535233"],["#8dccad","#988864","#fea6a2","#f9d6ac","#ffe9af"],["#2d2d29","#215a6d","#3ca2a2","#92c7a3","#dfece6"],["#413d3d","#040004","#c8ff00","#fa023c","#4b000f"],["#eff3cd","#b2d5ba","#61ada0","#248f8d","#605063"],["#ffefd3","#fffee4","#d0ecea","#9fd6d2","#8b7a5e"],["#cfffdd","#b4dec1","#5c5863","#a85163","#ff1f4c"],["#9dc9ac","#fffec7","#f56218","#ff9d2e","#919167"],["#4e395d","#827085","#8ebe94","#ccfc8e","#dc5b3e"],["#a8a7a7","#cc527a","#e8175d","#474747","#363636"],["#f8edd1","#d88a8a","#474843","#9d9d93","#c5cfc6"],["#046d8b","#309292","#2fb8ac","#93a42a","#ecbe13"],["#f38a8a","#55443d","#a0cab5","#cde9ca","#f1edd0"],["#a70267","#f10c49","#fb6b41","#f6d86b","#339194"],["#ff003c","#ff8a00","#fabe28","#88c100","#00c176"],["#ffedbf","#f7803c","#f54828","#2e0d23","#f8e4c1"],["#4e4d4a","#353432","#94ba65","#2790b0","#2b4e72"],["#0ca5b0","#4e3f30","#fefeeb","#f8f4e4","#a5b3aa"],["#4d3b3b","#de6262","#ffb88c","#ffd0b3","#f5e0d3"],["#fffbb7","#a6f6af","#66b6ab","#5b7c8d","#4f2958"],["#edf6ee","#d1c089","#b3204d","#412e28","#151101"],["#9d7e79","#ccac95","#9a947c","#748b83","#5b756c"],["#fcfef5","#e9ffe1","#cdcfb7","#d6e6c3","#fafbe3"],["#9cddc8","#bfd8ad","#ddd9ab","#f7af63","#633d2e"],["#30261c","#403831","#36544f","#1f5f61","#0b8185"],["#aaff00","#ffaa00","#ff00aa","#aa00ff","#00aaff"],["#d1313d","#e5625c","#f9bf76","#8eb2c5","#615375"],["#ffe181","#eee9e5","#fad3b2","#ffba7f","#ff9c97"],["#73c8a9","#dee1b6","#e1b866","#bd5532","#373b44"],["#805841","#dcf7f3","#fffcdd","#ffd8d8","#f5a2a2"]],vAi=t=>{let{x:A,y:e,width:i,height:n}={...t,...t.size,...t.center,...t.position};if(t.x1!==void 0&&t.x2!==void 0&&t.y1!==void 0&&t.y2!==void 0&&(A=(t.x1+t.x2)/2,e=(t.y1+t.y2)/2,i=Math.abs(t.x1-t.x2),n=Math.abs(t.y1-t.y2)),t.points&&Array.isArray(t.points)&&t.points.length>0){const r=t.points.map(B=>B.x),a=t.points.map(B=>B.y),g=Math.min(...r),c=Math.max(...r),I=Math.min(...a),l=Math.max(...a);A=(g+c)/2,e=(I+l)/2,i=c-g,n=l-I}const o=t.text||t.name||t.source?.text||t.source?.name||"?",s=t;return A===void 0||e===void 0?null:(i===void 0&&"outer_diameter"in t&&(i=t.outer_diameter,n=t.outer_diameter),(i===void 0||n===void 0)&&(i=.1,n=.1),{x:A,y:e,width:i,height:n,title:o,content:s,bg_color:Uhe[kAi(t.type||o)%Uhe.length]?.[4]??"#f00"})},FAi=t=>!!t,MAi=t=>{const A=t.filter(g=>g.type.startsWith("pcb_")||g.type.startsWith("schematic_")).concat(t.filter(g=>g.type==="pcb_trace"||g.type==="schematic_trace").flatMap(g=>g.route)).map(g=>vAi(g)).filter(FAi);if(A.length===0)return{center:{x:0,y:0},width:0,height:0};let e=A[0].x-A[0].width/2,i=A[0].x+A[0].width/2,n=A[0].y-A[0].height/2,o=A[0].y+A[0].height/2;for(const g of A.slice(1))e=Math.min(e,g.x-g.width/2),i=Math.max(i,g.x+g.width/2),n=Math.min(n,g.y-g.height/2),o=Math.max(o,g.y+g.height/2);const s=i-e,r=o-n;return{center:{x:e+s/2,y:n+r/2},width:s,height:r}},Cd={IS_SHOWING_PCB_GROUPS:"pcb_viewer_is_showing_pcb_groups",PCB_GROUP_VIEW_MODE:"pcb_viewer_group_view_mode",IS_SHOWING_COPPER_POURS:"pcb_viewer_is_showing_copper_pours",IS_SHOWING_COURTYARDS:"pcb_viewer_is_showing_courtyards",IS_SHOWING_GROUP_ANCHOR_OFFSETS:"pcb_viewer_is_showing_group_anchor_offsets",IS_SHOWING_SOLDER_MASK:"pcb_viewer_is_showing_solder_mask",IS_SHOWING_FABRICATION_NOTES:"pcb_viewer_is_showing_fabrication_notes",IS_SHOWING_SILKSCREEN:"pcb_viewer_is_showing_silkscreen"},GM=(t,A)=>{if(typeof window>"u")return A;try{const e=localStorage.getItem(t);return e!==null?JSON.parse(e):A}catch{return A}},LM=(t,A)=>{if(!(typeof window>"u"))try{localStorage.setItem(t,JSON.stringify(A))}catch{}},RAi=(t,A)=>{if(typeof window>"u")return A;try{const e=localStorage.getItem(t);return e!==null?JSON.parse(e):A}catch{return A}},NAi=(t,A)=>{if(!(typeof window>"u"))try{localStorage.setItem(t,JSON.stringify(A))}catch{}},GAi="named_only",LAi=(t={},A=!1)=>y4A(e=>({selected_layer:"top",pcb_viewer_id:`pcb_viewer_${Math.random().toString().slice(2,10)}`,in_edit_mode:!1,in_move_footprint_mode:!1,in_draw_trace_mode:!1,is_moving_component:!1,is_drawing_trace:!1,is_mouse_over_container:!1,is_showing_multiple_traces_length:!1,is_showing_rats_nest:!1,is_showing_autorouting:!0,is_showing_drc_errors:!0,is_showing_copper_pours:GM(Cd.IS_SHOWING_COPPER_POURS,!0),is_showing_courtyards:GM(Cd.IS_SHOWING_COURTYARDS,!0),is_showing_pcb_groups:A?!1:GM(Cd.IS_SHOWING_PCB_GROUPS,!0),is_showing_group_anchor_offsets:GM(Cd.IS_SHOWING_GROUP_ANCHOR_OFFSETS,!1),is_showing_solder_mask:GM(Cd.IS_SHOWING_SOLDER_MASK,!1),is_showing_silkscreen:GM(Cd.IS_SHOWING_SILKSCREEN,!0),is_showing_fabrication_notes:GM(Cd.IS_SHOWING_FABRICATION_NOTES,!1),pcb_group_view_mode:A?"all":RAi(Cd.PCB_GROUP_VIEW_MODE,GAi),hovered_error_id:null,...t,selectLayer:i=>e({selected_layer:i}),setEditMode:i=>e({in_edit_mode:i!=="off",in_move_footprint_mode:i==="move_footprint",in_draw_trace_mode:i==="draw_trace",is_moving_component:!1,is_drawing_trace:!1}),setIsShowingRatsNest:i=>e({is_showing_rats_nest:i}),setIsMovingComponent:i=>e({is_moving_component:i}),setIsDrawingTrace:i=>e({is_drawing_trace:i}),setIsMouseOverContainer:i=>e({is_mouse_over_container:i}),setIsShowingMultipleTracesLength:i=>e({is_showing_multiple_traces_length:i}),setIsShowingAutorouting:i=>e({is_showing_autorouting:i}),setIsShowingDrcErrors:i=>e({is_showing_drc_errors:i}),setIsShowingCopperPours:i=>{LM(Cd.IS_SHOWING_COPPER_POURS,i),e({is_showing_copper_pours:i})},setIsShowingCourtyards:i=>{LM(Cd.IS_SHOWING_COURTYARDS,i),e({is_showing_courtyards:i})},setIsShowingPcbGroups:i=>{A||(LM(Cd.IS_SHOWING_PCB_GROUPS,i),e({is_showing_pcb_groups:i}))},setIsShowingGroupAnchorOffsets:i=>{LM(Cd.IS_SHOWING_GROUP_ANCHOR_OFFSETS,i),e({is_showing_group_anchor_offsets:i})},setIsShowingSolderMask:i=>{LM(Cd.IS_SHOWING_SOLDER_MASK,i),e({is_showing_solder_mask:i})},setIsShowingSilkscreen:i=>{LM(Cd.IS_SHOWING_SILKSCREEN,i),e({is_showing_silkscreen:i})},setIsShowingFabricationNotes:i=>{LM(Cd.IS_SHOWING_FABRICATION_NOTES,i),e({is_showing_fabrication_notes:i})},setPcbGroupViewMode:i=>{A||(NAi(Cd.PCB_GROUP_VIEW_MODE,i),e({pcb_group_view_mode:i}))},setHoveredErrorId:i=>e({hovered_error_id:i})})),gl=t=>{const A=V.useContext(Hhe);return F4A(A,t)},Hhe=V.createContext(null),UAi=({children:t,initialState:A,disablePcbGroups:e})=>{const i=V.useMemo(()=>LAi(A,e),[e]);return W.jsx(Hhe.Provider,{value:i,children:t})},HAi=()=>{const t=gl(e=>e.pcb_viewer_id),A=(e,i)=>sc(e,{containerId:t,...i});return A.error=(e,i)=>sc.error(e,{containerId:t,...i}),A.promise=sc.promise,A},YAi=()=>{V.useEffect(()=>{M6t()},[]);const t=gl(A=>A.pcb_viewer_id);return W.jsx(F6t,{position:"top-center",containerId:t})};function JAi(){var t=V.useRef(!1),A=V.useCallback(function(){return t.current},[]);return V.useEffect(function(){return t.current=!0,function(){t.current=!1}},[]),A}var TAi=function(t){t===void 0&&(t={});var A=V.useState(t),e=A[0],i=A[1],n=V.useCallback(function(o){i(function(s){return Object.assign({},s,o instanceof Function?o(s):o)})},[]);return[e,n]},PAi=TAi,KAi=function(){},Yhe=typeof window<"u",qAi=CmA(gAi()),OAi=function(){var t=JAi(),A=PAi({value:void 0,error:void 0,noUserInteraction:!0}),e=A[0],i=A[1],n=V.useCallback(function(o){if(t()){var s,r;try{if(typeof o!="string"&&typeof o!="number"){var a=new Error("Cannot copy typeof "+typeof o+" to clipboard, must be a string");console.error(a),i({value:o,error:a,noUserInteraction:!0});return}else if(o===""){var a=new Error("Cannot copy empty string to clipboard.");console.error(a),i({value:o,error:a,noUserInteraction:!0});return}r=o.toString(),s=(0,qAi.default)(r),i({value:r,error:void 0,noUserInteraction:s})}catch(g){i({value:r,error:g,noUserInteraction:s})}}},[]);return[e,n]},WAi=OAi,ZAi=Yhe?V.useLayoutEffect:V.useEffect,VAi=ZAi,Jhe={x:0,y:0,width:0,height:0,top:0,left:0,bottom:0,right:0};function jAi(){var t=V.useState(null),A=t[0],e=t[1],i=V.useState(Jhe),n=i[0],o=i[1],s=V.useMemo(function(){return new window.ResizeObserver(function(r){if(r[0]){var a=r[0].contentRect,g=a.x,c=a.y,I=a.width,l=a.height,B=a.top,C=a.left,Q=a.bottom,h=a.right;o({x:g,y:c,width:I,height:l,top:B,left:C,bottom:Q,right:h})}})},[]);return VAi(function(){if(A)return s.observe(A),function(){s.disconnect()}},[A]),[e,n]}var qT=Yhe&&typeof window.ResizeObserver<"u"?jAi:function(){return[KAi,Jhe]},The=({initialTransform:t,initialTouch1:A,initialTouch2:e,finalTouch1:i,finalTouch2:n})=>{if(!i||!n)return t;const o={x:(A.x+e.x)/2,y:(A.y+e.y)/2},s={x:(i.x+n.x)/2,y:(i.y+n.y)/2},r=Math.hypot(e.x-A.x,e.y-A.y),a=Math.hypot(n.x-i.x,n.y-i.y),g=r===0?1:a/r,c=s.x-o.x,I=s.y-o.y;return An(on(c,I),on(o.x,o.y),$a(g,g),on(-o.x,-o.y),t)},zAi=(t={})=>{const A=V.useRef(null),[e,i]=V.useState(0),n=t.canvasElm??A.current,[o,s]=V.useState(t.initialTransform??xa()),[r,a]=V.useState(0),[g,c]=V.useReducer(d=>d+1,0),I=V.useCallback(d=>{t.onSetTransform&&t.onSetTransform(d),t.transform||s(d)},[t.onSetTransform,s]),l=V.useCallback(d=>{I(d),c()},[I]),B=t.transform??o,C=V.useCallback(()=>{i(Date.now())},[]),Q=V.useRef("none"),h=V.useRef(null),E=V.useRef(null);V.useEffect(()=>{const d=t.canvasElm??A.current;if(d&&!n){a(r+1);return}if(!d){const Z=setTimeout(()=>{a(r+1)},100);return()=>clearTimeout(Z)}let f=t.transform??o,y={x:0,y:0},w={x:0,y:0},D=!1;const S=Z=>({x:Z.pageX-d.getBoundingClientRect().left-window.scrollX,y:Z.pageY-d.getBoundingClientRect().top-window.scrollY});function _(Z){t.enabled!==!1&&(t.shouldDrag&&!t.shouldDrag(Z)||(y=S(Z),!(Date.now()-e<100)&&(D=!0,Z.preventDefault())))}function b(Z){if(!D||t.enabled===!1||t.shouldDrag&&!t.shouldDrag(Z))return;w=S(Z);const X=An(on(w.x-y.x,w.y-y.y),f);I(X),f=X,D=!1}function N(Z){if(S(Z),!D||t.enabled===!1||t.shouldDrag&&!t.shouldDrag(Z))return;w=S(Z);const X=An(on(w.x-y.x,w.y-y.y),f);I(X)}function F(Z){if(t.enabled===!1||t.shouldDrag&&!t.shouldDrag(Z))return;const X=S(Z),eA=An(on(X.x,X.y),$a(1-Z.deltaY/1e3,1-Z.deltaY/1e3),on(-X.x,-X.y),f);I(eA),f=eA,Z.preventDefault()}function L(Z){if(!D||t.shouldDrag&&!t.shouldDrag(Z))return;if(d){const eA=d.getBoundingClientRect();if(Z.clientX>=eA.left+10&&Z.clientX<=eA.right-10&&Z.clientY>=eA.top+10&&Z.clientY<=eA.bottom-10)return}D=!1,w=S(Z);const X=An(on(w.x-y.x,w.y-y.y),f);I(X),f=X}function Y(Z){if(Z.preventDefault(),t.enabled!==!1){if(Z.touches.length===1){Q.current="drag";const X=Z.touches[0];h.current={initialTransform:f,initialTouch:{x:X.clientX,y:X.clientY}}}else if(Z.touches.length===2){Q.current="pinch";const X=Z.touches[0],eA=Z.touches[1];E.current={initialTransform:f,initialTouch1:{x:X.clientX,y:X.clientY},initialTouch2:{x:eA.clientX,y:eA.clientY},finalTouch1:null,finalTouch2:null}}}}function J(Z){if(Z.preventDefault(),t.enabled!==!1){if(Q.current==="drag"&&Z.touches.length===1&&h.current){const X=Z.touches[0],eA={x:X.clientX,y:X.clientY},gA=eA.x-h.current.initialTouch.x,tA=eA.y-h.current.initialTouch.y,iA=An(on(gA,tA),h.current.initialTransform);I(iA)}else if(Q.current==="pinch"&&Z.touches.length===2&&E.current){const X=Z.touches[0],eA=Z.touches[1];E.current.finalTouch1={x:X.clientX,y:X.clientY},E.current.finalTouch2={x:eA.clientX,y:eA.clientY};const gA=The(E.current);I(gA)}}}function O(Z){Z.preventDefault();const X=Z.changedTouches[0];if(Q.current==="drag"&&h.current&&X){const eA={x:X.clientX,y:X.clientY},gA=eA.x-h.current.initialTouch.x,tA=eA.y-h.current.initialTouch.y,iA=An(on(gA,tA),h.current.initialTransform);I(iA),f=iA}else if(Q.current==="pinch"&&E.current){const eA=The(E.current);I(eA),f=eA}Q.current="none",h.current=null,E.current=null}return d.addEventListener("mousedown",_),d.addEventListener("mouseup",b),window.addEventListener("mousemove",N),d.addEventListener("mouseout",L),d.addEventListener("wheel",F),d.addEventListener("touchstart",Y,{passive:!1}),d.addEventListener("touchmove",J,{passive:!1}),d.addEventListener("touchend",O,{passive:!1}),d.addEventListener("touchcancel",O,{passive:!1}),()=>{d.removeEventListener("mousedown",_),d.removeEventListener("mouseup",b),window.removeEventListener("mousemove",N),d.removeEventListener("mouseout",L),d.removeEventListener("wheel",F),d.removeEventListener("touchstart",Y),d.removeEventListener("touchmove",J),d.removeEventListener("touchend",O),d.removeEventListener("touchcancel",O)}},[n,r,g,e,t.enabled,t.shouldDrag]);const u=V.useCallback(d=>Ce(B,d),[B]);return{ref:A,transform:B,applyTransformToPoint:u,setTransform:l,cancelDrag:C}},XAi=zAi;function $Ai(t){const A=new Map;let e=0;function i(n){for(const[,s]of A)if(s.has(n))return s;const o=new Set;return A.set(`connectivity_net${e++}`,o),o}for(const n of t){let o=null;for(const s of n){if(!o)o=i(s);else if(!o.has(s)){const r=i(s);if(r!==o){for(const a of r)o.add(a);A.delete(Array.from(A.entries()).find(([,a])=>a===r)[0])}}o.add(s)}}return Object.fromEntries(Array.from(A.entries()).map(([n,o])=>[n,Array.from(o)]))}var Aei=class{netMap;idToNetMap;constructor(t){this.netMap=t,this.idToNetMap={};for(const[A,e]of Object.entries(t))for(const i of e)this.idToNetMap[i]=A}addConnections(t){for(const A of t){const e=new Set;for(const n of A){const o=this.idToNetMap[n];o&&e.add(o)}let i;if(e.size===0)i=`connectivity_net${Object.keys(this.netMap).length}`,this.netMap[i]=[];else if(e.size===1)i=e.values().next().value??`connectivity_net${Object.keys(this.netMap).length}`;else{i=e.values().next().value??`connectivity_net${Object.keys(this.netMap).length}`;for(const n of e)if(n!==i){this.netMap[i].push(...this.netMap[n]),this.netMap[n]=this.netMap[i];for(const o of this.netMap[i])this.idToNetMap[o]=i}}for(const n of A)this.netMap[i].includes(n)||this.netMap[i].push(n),this.idToNetMap[n]=i}}getIdsConnectedToNet(t){return this.netMap[t]||[]}getNetConnectedToId(t){return this.idToNetMap[t]}areIdsConnected(t,A){if(t===A)return!0;const e=this.getNetConnectedToId(t);if(!e)return!1;const i=this.getNetConnectedToId(A);return i?e===i||i===t||i===t:!1}areAllIdsConnected(t){const A=this.getNetConnectedToId(t[0]);for(const e of t){const i=this.getNetConnectedToId(e);if(i===void 0||i!==A)return!1}return!0}},Phe=t=>{const A=[];for(const i of t)if(i.type==="source_trace")A.push([i.source_trace_id,...i.connected_source_port_ids??[],...i.connected_source_net_ids??[]].filter(Boolean));else if(i.type==="pcb_port"){const{pcb_port_id:n,source_port_id:o}=i;o&&n&&A.push([o,n])}else if(i.type==="pcb_smtpad"){const{pcb_smtpad_id:n,pcb_port_id:o}=i;o&&n&&A.push([n,o])}else if(i.type==="pcb_plated_hole"){const{pcb_plated_hole_id:n,pcb_port_id:o}=i;o&&n&&A.push([n,o])}else if(i.type==="pcb_trace"){const{pcb_trace_id:n,source_trace_id:o}=i,s=Array.isArray(i.route)?i.route.filter(r=>r&&r.route_type==="wire"):[];if(o&&n&&A.push([n,o]),Array.isArray(s)){const r=s.find(g=>g?.start_pcb_port_id)?.start_pcb_port_id,a=s.find(g=>g?.end_pcb_port_id)?.end_pcb_port_id;r&&n&&a&&A.push([r,n,a])}}else if(i.type==="pcb_via"){const{pcb_via_id:n,pcb_trace_id:o}=i;o&&n&&A.push([n,o])}else if(i.type==="source_component"&&i.internally_connected_source_port_ids)for(const n of i.internally_connected_source_port_ids)A.push(n);const e=$Ai(A);return new Aei(e)};function eei({primitivesWithoutInteractionMetadata:t,drawingObjectIdsWithMouseOver:A,primitiveIdsInMousedOverNet:e}){const i=[];for(const n of t){const o={...n};n?.layer==="drill"?(o.is_in_highlighted_net=!1,o.is_mouse_over=!1):A.has(n._pcb_drawing_object_id)?o.is_mouse_over=!0:n._element&&("pcb_trace_id"in n._element&&e.includes(n._element.pcb_trace_id)||"pcb_port_id"in n._element&&e.includes(n._element.pcb_port_id))?o.is_in_highlighted_net=!0:(o.is_in_highlighted_net=!1,o.is_mouse_over=!1),i.push(o)}return i}function tei(t,A){if(t.length<2)throw new Error("Stroke must have at least two points");const e=t.map(I=>Array.isArray(I)?{x:I[0],y:I[1]}:I),i=[],n=[];function o(I,l){const B=l.x-I.x,C=l.y-I.y,Q=Math.sqrt(B*B+C*C);return{x:-C/Q,y:B/Q}}function s(I,l,B,C){const Q=C/2,h={x:I.x+l.x*Q*B,y:I.y+l.y*Q*B};B>0?i.push(h):n.unshift(h)}const r=o(e[0],e[1]),a=e[0].trace_width??A;s(e[0],r,1,a),s(e[0],r,-1,a);for(let I=1;I<e.length-1;I++){const l=e[I-1],B=e[I],C=e[I+1],Q=o(l,B),h=o(B,C),E=Q.x+h.x,u=Q.y+h.y,d=Math.sqrt(E*E+u*u),f=B.trace_width??A;if(d/2>2*(f/2))s(B,Q,1,f),s(B,h,1,f),s(B,Q,-1,f),s(B,h,-1,f);else{const w=1/d;s(B,{x:E*w,y:u*w},1,f),s(B,{x:E*w,y:u*w},-1,f)}}const g=o(e[e.length-2],e[e.length-1]),c=e[e.length-1].trace_width??A;return s(e[e.length-1],g,1,c),s(e[e.length-1],g,-1,c),[...i,...n]}var iei=(t,A)=>{const{x:e,y:i,width:n,height:o,layer:s,rect_border_radius:r}=t,a=t.corner_radius??r??0,g=[{_pcb_drawing_object_id:Nm("rect"),pcb_drawing_type:"rect",x:e,y:i,w:n,h:o,layer:s||"top",_element:t,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,roundness:a,...t.shape==="rotated_rect"&&t.ccw_rotation!==void 0?{ccw_rotation:t.ccw_rotation}:{}}];if(t.is_covered_with_solder_mask){const c=s==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",l={...{_pcb_drawing_object_id:Nm("rect"),pcb_drawing_type:"rect",x:e,y:i,w:n,h:o,layer:c,_element:t,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,roundness:a,...t.shape==="rotated_rect"&&t.ccw_rotation!==void 0?{ccw_rotation:t.ccw_rotation}:{}},..."solder_mask_color"in t&&t.solder_mask_color?{color:t.solder_mask_color}:{}};g.push(l)}return g},nei=(t,A)=>{const{x:e,y:i,radius:n,layer:o}=t,s=[{_pcb_drawing_object_id:Nm("circle"),pcb_drawing_type:"circle",x:e,y:i,r:n,layer:o||"top",_element:t,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port}];if(t.is_covered_with_solder_mask){const r=o==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",a={_pcb_drawing_object_id:Nm("circle"),pcb_drawing_type:"circle",x:e,y:i,r:n,layer:r,_element:t,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,..."solder_mask_color"in t&&t.solder_mask_color?{color:t.solder_mask_color}:{}};s.push(a)}return s},oei=(t,A)=>{const{layer:e,points:i}=t,n=[{_pcb_drawing_object_id:Nm("polygon"),pcb_drawing_type:"polygon",points:fmA(i),layer:e||"top",_element:t,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port}];if(t.is_covered_with_solder_mask){const o=e==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",s={_pcb_drawing_object_id:Nm("polygon"),pcb_drawing_type:"polygon",points:fmA(i),layer:o,_element:t,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,..."solder_mask_color"in t&&t.solder_mask_color?{color:t.solder_mask_color}:{}};n.push(s)}return n},sei=(t,A)=>{const{x:e,y:i,width:n,height:o,layer:s}=t,r=[{_pcb_drawing_object_id:Nm("pill"),pcb_drawing_type:"pill",x:e,y:i,w:n,h:o,layer:s||"top",_element:t,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port}];if(t.is_covered_with_solder_mask){const a=s==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",g={_pcb_drawing_object_id:Nm("pill"),pcb_drawing_type:"pill",x:e,y:i,w:n,h:o,layer:a,_element:t,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,..."solder_mask_color"in t&&t.solder_mask_color?{color:t.solder_mask_color}:{}};r.push(g)}return r},rei=(t,A)=>{const{x:e,y:i,width:n,height:o,layer:s,ccw_rotation:r}=t,a=[{_pcb_drawing_object_id:Nm("pill"),pcb_drawing_type:"pill",x:e,y:i,w:n,h:o,layer:s||"top",_element:t,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,ccw_rotation:r}];if(t.is_covered_with_solder_mask){const g=s==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",c={_pcb_drawing_object_id:Nm("pill"),pcb_drawing_type:"pill",x:e,y:i,w:n,h:o,layer:g,_element:t,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,ccw_rotation:r,..."solder_mask_color"in t&&t.solder_mask_color?{color:t.solder_mask_color}:{}};a.push(c)}return a},aei=(t,A)=>{const{_parent_pcb_component:e,_parent_source_component:i}=A,n=t,o=typeof n.font_size=="string"?Et.parse(n.font_size):n.font_size??.2;let s;return n.knockout_padding&&(s={left:typeof n.knockout_padding.left=="string"?Et.parse(n.knockout_padding.left):n.knockout_padding.left,top:typeof n.knockout_padding.top=="string"?Et.parse(n.knockout_padding.top):n.knockout_padding.top,bottom:typeof n.knockout_padding.bottom=="string"?Et.parse(n.knockout_padding.bottom):n.knockout_padding.bottom,right:typeof n.knockout_padding.right=="string"?Et.parse(n.knockout_padding.right):n.knockout_padding.right}),[{_pcb_drawing_object_id:Nm("text"),pcb_drawing_type:"text",x:n.anchor_position.x,y:n.anchor_position.y,layer:n.layer,align:n.anchor_alignment??"center",text:n.text,size:o,ccw_rotation:n.ccw_rotation,is_mirrored:n.is_mirrored,is_knockout:n.is_knockout,knockout_padding:s,_element:t,_parent_pcb_component:e,_parent_source_component:i}]},TI=0,Nm=t=>`${t}_${TI++}`,fmA=t=>(t??[]).map(A=>({x:Et.parse(A.x),y:Et.parse(A.y)})),gei=(t,A)=>{const e="pcb_component_id"in t?A.find(s=>s.type==="pcb_component"&&s.pcb_component_id===t.pcb_component_id):void 0,i=e&&"source_component_id"in e?A.find(s=>s.type==="source_component"&&s.source_component_id===e.source_component_id):void 0,n="source_port_id"in t?t.source_port_id:"pcb_port_id"in t?rx(A).pcb_port.get(t.pcb_port_id)?.source_port_id:void 0,o=n?A.find(s=>s.type==="source_port"&&s.source_port_id===n):void 0;switch(t.type){case"pcb_smtpad":{const s={_parent_pcb_component:e,_parent_source_component:i,_source_port:o};return t.shape==="rect"||t.shape==="rotated_rect"?iei(t,s):t.shape==="circle"?nei(t,s):t.shape==="polygon"?oei(t,s):t.shape==="pill"?sei(t,s):t.shape==="rotated_pill"?rei(t,s):[]}case"pcb_trace":{const s=[];if(t.route_thickness_mode==="interpolated"){const g=t.route.map(l=>({x:l.x,y:l.y,trace_width:l.route_type==="wire"?l.width:.5})),c=tei(g,.5),I=t.route[0].layer;return s.push({_pcb_drawing_object_id:`polygon_${TI++}`,_element:t,pcb_drawing_type:"polygon",points:c,layer:I}),t.route.forEach(l=>{l.route_type==="via"&&s.push({_pcb_drawing_object_id:`circle_${TI++}`,_element:t,pcb_drawing_type:"circle",x:l.x,y:l.y,r:l.outer_diameter/2,layer:l.from_layer})}),s}let r=null,a=null;for(const g of t.route)g.route_type==="wire"&&(r!==null&&a!==null&&s.push({_pcb_drawing_object_id:`line_${TI++}`,_element:t,pcb_drawing_type:"line",x1:r,y1:a,x2:g.x,y2:g.y,width:g.width,squareCap:!1,layer:g.layer}),r=g.x,a=g.y);return s}case"pcb_via":{const{x:s,y:r,outer_diameter:a,hole_diameter:g}=t,c=t.from_layer,I=t.to_layer,l=t.layers,B=[];c&&I?B.push(c,I):l&&Array.isArray(l)?B.push(...l):B.push("top","bottom");const C=[];for(const Q of B)C.push({_pcb_drawing_object_id:`circle_${TI++}`,pcb_drawing_type:"circle",x:s,y:r,r:a/2,layer:Q,_element:t,_parent_pcb_component:e,_parent_source_component:i});return C.push({_pcb_drawing_object_id:`circle_${TI++}`,pcb_drawing_type:"circle",x:s,y:r,r:g/2,layer:"drill",_element:t}),C}case"pcb_plated_hole":if(t.shape==="circle"){const{x:s,y:r,hole_diameter:a,outer_diameter:g}=t;return[{_pcb_drawing_object_id:`circle_${TI++}`,pcb_drawing_type:"circle",x:s,y:r,r:g/2,layer:"top",_element:t,_parent_pcb_component:e,_parent_source_component:i,_source_port:o},{_pcb_drawing_object_id:`circle_${TI++}`,pcb_drawing_type:"circle",x:s,y:r,r:a/2,layer:"drill",_element:t}]}else if(t.shape==="oval"){const{x:s,y:r,outer_height:a,outer_width:g,hole_height:c,hole_width:I}=t;return[{_pcb_drawing_object_id:`oval_${TI++}`,pcb_drawing_type:"oval",x:s,y:r,rX:g/2,rY:a/2,layer:"top",_element:t,_parent_pcb_component:e,_parent_source_component:i,_source_port:o},{_pcb_drawing_object_id:`oval_${TI++}`,_element:t,pcb_drawing_type:"oval",x:s,y:r,rX:I/2,rY:c/2,layer:"drill"}]}else if(t.shape==="pill"){const{x:s,y:r,outer_height:a,outer_width:g,hole_height:c,hole_width:I}=t;return[{_pcb_drawing_object_id:`pill_${TI++}`,pcb_drawing_type:"pill",x:s,y:r,w:g,h:a,layer:"top",_element:t,_parent_pcb_component:e,_parent_source_component:i,_source_port:o,ccw_rotation:t.ccw_rotation},{_pcb_drawing_object_id:`pill_${TI++}`,_element:t,pcb_drawing_type:"pill",x:s,y:r,w:I,h:c,layer:"drill",ccw_rotation:t.ccw_rotation}]}else if(t.shape==="circular_hole_with_rect_pad"){const{x:s,y:r,hole_diameter:a,rect_pad_width:g,rect_pad_height:c,rect_border_radius:I,hole_offset_x:l,hole_offset_y:B}=t,C=Et.parse(l??0),Q=Et.parse(B??0);return[{_pcb_drawing_object_id:`rect_${TI++}`,pcb_drawing_type:"rect",x:s,y:r,w:g,h:c,layer:"top",_element:t,_parent_pcb_component:e,_parent_source_component:i,_source_port:o,roundness:I},{_pcb_drawing_object_id:`rect_${TI++}`,pcb_drawing_type:"rect",x:s,y:r,w:g,h:c,layer:"bottom",_element:t,_parent_pcb_component:e,_parent_source_component:i,_source_port:o,roundness:I,is_hoverable:!1},{_pcb_drawing_object_id:`circle_${TI++}`,_element:t,pcb_drawing_type:"circle",x:s+C,y:r+Q,r:a/2,layer:"drill",is_hoverable:!1}]}else if(t.shape==="pill_hole_with_rect_pad"){const{x:s,y:r,hole_width:a,hole_height:g,rect_pad_width:c,rect_pad_height:I,rect_border_radius:l}=t;return[{_pcb_drawing_object_id:`rect_${TI++}`,pcb_drawing_type:"rect",x:s,y:r,w:c,h:I,layer:"top",_element:t,_parent_pcb_component:e,_parent_source_component:i,_source_port:o,roundness:l},{_pcb_drawing_object_id:`rect_${TI++}`,pcb_drawing_type:"rect",x:s,y:r,w:c,h:I,layer:"bottom",_element:t,_parent_pcb_component:e,_parent_source_component:i,_source_port:o,roundness:l,is_hoverable:!1},{_pcb_drawing_object_id:`pill_${TI++}`,_element:t,pcb_drawing_type:"pill",x:s,y:r,w:a,h:g,layer:"drill",is_hoverable:!1}]}else if(t.shape==="rotated_pill_hole_with_rect_pad"){const{x:s,y:r,hole_width:a,hole_height:g,hole_ccw_rotation:c,rect_pad_width:I,rect_pad_height:l,rect_ccw_rotation:B,rect_border_radius:C}=t;return[{_pcb_drawing_object_id:`rect_${TI++}`,pcb_drawing_type:"rect",x:s,y:r,w:I,h:l,layer:"top",_element:t,_parent_pcb_component:e,_parent_source_component:i,_source_port:o,ccw_rotation:B,roundness:C},{_pcb_drawing_object_id:`rect_${TI++}`,pcb_drawing_type:"rect",x:s,y:r,w:I,h:l,layer:"bottom",_element:t,_parent_pcb_component:e,_parent_source_component:i,_source_port:o,ccw_rotation:B,roundness:C,is_hoverable:!1},{_pcb_drawing_object_id:`pill_${TI++}`,_element:t,pcb_drawing_type:"pill",x:s,y:r,w:a,h:g,layer:"drill",ccw_rotation:c,is_hoverable:!1}]}else if(t.shape==="hole_with_polygon_pad"){const{x:s,y:r,pad_outline:a,hole_shape:g,hole_diameter:c,hole_width:I,hole_height:l,layers:B,hole_offset_x:C,hole_offset_y:Q}=t,h=Et.parse(C??0),E=Et.parse(Q??0),u=a,d=[];if(u&&Array.isArray(u)){const w=fmA(u).map(D=>({x:D.x+s,y:D.y+r}));for(const D of B||["top","bottom"])d.push({_pcb_drawing_object_id:`polygon_${TI++}`,pcb_drawing_type:"polygon",points:w,layer:D,_element:t,_parent_pcb_component:e,_parent_source_component:i,_source_port:o})}const f={x:s+h,y:r+E},y=[];return g==="circle"?y.push({_pcb_drawing_object_id:`circle_${TI++}`,pcb_drawing_type:"circle",x:f.x,y:f.y,r:(c??0)/2,layer:"drill",_element:t,_parent_pcb_component:e,_parent_source_component:i}):g==="oval"?y.push({_pcb_drawing_object_id:`oval_${TI++}`,pcb_drawing_type:"oval",x:f.x,y:f.y,rX:(I??0)/2,rY:(l??0)/2,layer:"drill",_element:t,_parent_pcb_component:e,_parent_source_component:i}):(g==="pill"||g==="rotated_pill")&&y.push({_pcb_drawing_object_id:`pill_${TI++}`,pcb_drawing_type:"pill",x:f.x,y:f.y,w:I??0,h:l??0,layer:"drill",_element:t,_parent_pcb_component:e,_parent_source_component:i,ccw_rotation:t.ccw_rotation}),[...d,...y]}else return[];case"pcb_copper_text":return aei(t,{_parent_pcb_component:e,_parent_source_component:i})}return[]},yn={board:{anchor:"rgb(255, 38, 226)",aux_items:"rgb(255, 255, 255)",b_adhes:"rgb(0, 0, 132)",b_crtyd:"rgb(38, 233, 255)",b_fab:"rgb(88, 93, 132)",b_mask:"rgba(2, 255, 238, 0.400)",b_paste:"rgb(0, 194, 194)",b_silks:"rgb(242, 237, 161)",background:"rgb(0, 16, 35)",cmts_user:"rgb(89, 148, 220)",copper:{b:"rgb(77, 127, 196)",f:"rgb(200, 52, 52)",in1:"rgb(127, 200, 127)",in10:"rgb(237, 124, 51)",in11:"rgb(91, 195, 235)",in12:"rgb(247, 111, 142)",in13:"rgb(167, 165, 198)",in14:"rgb(40, 204, 217)",in15:"rgb(232, 178, 167)",in16:"rgb(242, 237, 161)",in17:"rgb(237, 124, 51)",in18:"rgb(91, 195, 235)",in19:"rgb(247, 111, 142)",in2:"rgb(206, 125, 44)",in20:"rgb(167, 165, 198)",in21:"rgb(40, 204, 217)",in22:"rgb(232, 178, 167)",in23:"rgb(242, 237, 161)",in24:"rgb(237, 124, 51)",in25:"rgb(91, 195, 235)",in26:"rgb(247, 111, 142)",in27:"rgb(167, 165, 198)",in28:"rgb(40, 204, 217)",in29:"rgb(232, 178, 167)",in3:"rgb(79, 203, 203)",in30:"rgb(242, 237, 161)",in4:"rgb(219, 98, 139)",in5:"rgb(167, 165, 198)",in6:"rgb(40, 204, 217)",in7:"rgb(232, 178, 167)",in8:"rgb(242, 237, 161)",in9:"rgb(141, 203, 129)"},cursor:"rgb(255, 255, 255)",drc:"rgb(194, 194, 194)",drc_error:"rgba(215, 91, 107, 0.800)",drc_exclusion:"rgb(255, 255, 255)",drc_warning:"rgba(255, 208, 66, 0.902)",dwgs_user:"rgb(194, 194, 194)",eco1_user:"rgb(180, 219, 210)",eco2_user:"rgb(216, 200, 82)",edge_cuts:"rgb(208, 210, 205)",f_adhes:"rgb(132, 0, 132)",f_crtyd:"rgb(255, 0, 245)",f_fab:"rgb(175, 175, 175)",f_mask:"rgba(216, 100, 255, 0.400)",f_paste:"rgba(180, 160, 154, 0.902)",f_silks:"rgb(242, 237, 161)",footprint_text_back:"rgb(0, 0, 132)",footprint_text_front:"rgb(194, 194, 194)",footprint_text_invisible:"rgb(132, 132, 132)",grid:"rgb(132, 132, 132)",grid_axes:"rgb(194, 194, 194)",margin:"rgb(255, 38, 226)",microvia:"rgb(0, 132, 132)",no_connect:"rgb(0, 0, 132)",pad_back:"rgb(77, 127, 196)",pad_front:"rgb(200, 52, 52)",pad_plated_hole:"rgb(194, 194, 0)",pad_through_hole:"rgb(227, 183, 46)",plated_hole:"rgb(26, 196, 210)",ratsnest:"rgba(245, 255, 213, 0.702)",select_overlay:"rgb(4, 255, 67)",soldermaskWithCopper:{top:"rgb(18, 82, 50)",bottom:"rgb(77, 127, 196)"},soldermask:{top:"rgb(12, 55, 33)",bottom:"rgb(12, 55, 33)"},through_via:"rgb(236, 236, 236)",user_1:"rgb(194, 194, 194)",user_2:"rgb(89, 148, 220)",user_3:"rgb(180, 219, 210)",user_4:"rgb(216, 200, 82)",user_5:"rgb(194, 194, 194)",user_6:"rgb(89, 148, 220)",user_7:"rgb(180, 219, 210)",user_8:"rgb(216, 200, 82)",user_9:"rgb(232, 178, 167)",via_blind_buried:"rgb(187, 151, 38)",via_hole:"rgb(227, 183, 46)",via_micro:"rgb(0, 132, 132)",via_through:"rgb(236, 236, 236)",worksheet:"rgb(200, 114, 171)"}},Pf=(t,A=1)=>{if(Math.abs(t.a)!==Math.abs(t.d))throw new Error("Cannot scale non-uniformly");return A*Math.abs(t.a)},kc={elementOverlay:40,dimensionOverlay:40,editTraceHintOverlay:40,errorOverlay:40,pcbGroupOverlay:35,ratsNestOverlay:30,toolbarOverlay:70,warnings:30,topLayer:20,clickToInteractOverlay:100},vz={red:"red",black:"black",green:"green",board:"rgb(255, 255, 255)",other:"#eee",top:yn.board.copper.f,inner1:yn.board.copper.in1,inner2:yn.board.copper.in2,inner3:yn.board.copper.in3,inner4:yn.board.copper.in4,inner5:yn.board.copper.in5,inner6:yn.board.copper.in6,inner7:yn.board.copper.in7,inner8:yn.board.copper.in8,bottom:yn.board.copper.b,drill:yn.board.anchor,keepout:yn.board.background,tkeepout:yn.board.b_crtyd,tplace:yn.board.b_silks,top_courtyard:yn.board.f_crtyd,bottom_courtyard:yn.board.b_crtyd,top_silkscreen:yn.board.f_silks,bottom_silkscreen:yn.board.b_silks,top_fabrication:yn.board.f_fab,bottom_fabrication:yn.board.b_fab,soldermask_top:yn.board.soldermask.top,soldermask_bottom:yn.board.soldermask.bottom,soldermask_with_copper_top:yn.board.soldermaskWithCopper.top,soldermask_with_copper_bottom:yn.board.soldermaskWithCopper.bottom,bottom_notes:yn.board.user_2,top_notes:yn.board.user_2,...yn.board},cei=["board","inner6","inner5","inner4","inner3","inner2","inner1","bottom","soldermask_bottom","bottom_silkscreen","top","soldermask_top","bottom_courtyard","bottom_fabrication","top_courtyard","top_fabrication","edge_cuts","top_silkscreen"],Iei=class{canvasLayerMap;ctxLayerMap;aperture;transform;foregroundLayer="top";lastPoint;constructor(t){this.canvasLayerMap=t,this.ctxLayerMap=Object.fromEntries(Object.entries(t).map(([A,e])=>[A,e.getContext("2d")])),this.transform=xa(),this.transform.d*=-1,this.transform=An(this.transform,on(0,-500)),this.lastPoint={x:0,y:0},this.equip({})}clear(){for(const t of Object.values(this.ctxLayerMap))t.clearRect(0,0,t.canvas.width,t.canvas.height)}equip(t){this.aperture={fontSize:0,shape:"circle",mode:"add",size:0,color:"red",layer:"top",opacity:this.foregroundLayer===t.color?1:.5,...t}}drawMeshPattern(t,A,e,i,n,o=45){const s=this.getLayerCtx(),[r,a]=Ce(this.transform,[t,A]),[g,c]=Ce(this.transform,[t+e,A+i]),I=Pf(this.transform,n);s.lineWidth=1,s.strokeStyle=this.aperture.color;const l=B=>{const C=Math.sin(B),Q=Math.cos(B),h=Math.sqrt((g-r)**2+(c-a)**2);for(let E=-h;E<=h;E+=I)s.beginPath(),s.moveTo(r+E*Q-h*C,a+E*C+h*Q),s.lineTo(r+E*Q+h*C,a+E*C-h*Q),s.stroke()};l(o*Math.PI/180),l((o+90)*Math.PI/180)}rect({x:t,y:A,w:e,h:i,mesh_fill:n,is_filled:o=!0,has_stroke:s,is_stroke_dashed:r,stroke_width:a,roundness:g}){const[c,I]=Ce(this.transform,[t-e/2,A-i/2]),[l,B]=Ce(this.transform,[t+e/2,A+i/2]);this.applyAperture();const C=this.getLayerCtx(),Q=g?Pf(this.transform,g):0,h=s===void 0?o===!1:s;if(n)C.save(),C.beginPath(),Q>0&&C.roundRect?C.roundRect(c,I,l-c,B-I,Q):C.rect(c,I,l-c,B-I),C.clip(),this.drawMeshPattern(t-e/2,A-i/2,e,i,.15),C.restore(),Q>0&&C.roundRect?(C.beginPath(),C.roundRect(c,I,l-c,B-I,Q),C.stroke()):C.strokeRect(c,I,l-c,B-I);else if(o!==!1&&(Q>0&&C.roundRect?(C.beginPath(),C.roundRect(c,I,l-c,B-I,Q),C.fill()):C.fillRect(c,I,l-c,B-I)),h){const E=C.lineWidth;if(a!==void 0&&(C.lineWidth=Pf(this.transform,a)),r){let u=[];const d=Math.abs(this.transform.a);if(d>0){const y=.1*d,w=y*1.3;y>.5&&(u=[y,w])}C.setLineDash(u)}Q>0&&C.roundRect?(C.beginPath(),C.roundRect(c,I,l-c,B-I,Q),C.stroke()):C.strokeRect(c,I,l-c,B-I),r&&C.setLineDash([]),a!==void 0&&(C.lineWidth=E)}}rotatedRect(t,A,e,i,n,o,s){const r=this.getLayerCtx();this.applyAperture();const[a,g]=Ce(this.transform,[t-e/2,A-i/2]),[c,I]=Ce(this.transform,[t+e/2,A+i/2]),l=o?Pf(this.transform,o):0;r.save();const[B,C]=Ce(this.transform,[t,A]);r.translate(B,C);const Q=360-n;n&&r.rotate(Q*Math.PI/180),r.translate(-B,-C),s?(r.beginPath(),l>0&&r.roundRect?r.roundRect(a,g,c-a,I-g,l):r.rect(a,g,c-a,I-g),r.clip(),this.drawMeshPattern(t-e/2,A-i/2,e,i,.15),l>0&&r.roundRect?(r.beginPath(),r.roundRect(a,g,c-a,I-g,l),r.stroke()):r.strokeRect(a,g,c-a,I-g)):l>0&&r.roundRect?(r.beginPath(),r.roundRect(a,g,c-a,I-g,l),r.fill()):r.fillRect(a,g,c-a,I-g),r.restore()}rotatedPill(t,A,e,i,n){const o=this.getLayerCtx();this.applyAperture(),o.save();const[s,r]=Ce(this.transform,[t,A]);o.translate(s,r);const a=360-n;n&&o.rotate(a*Math.PI/180),o.translate(-s,-r),this.pill(t,A,e,i),o.restore()}circle(t,A,e,i,n=!0){const o=Pf(this.transform,e),[s,r]=Ce(this.transform,[t,A]);this.applyAperture();const a=this.getLayerCtx();i?(a.save(),a.beginPath(),a.arc(s,r,o,0,2*Math.PI),a.clip(),this.drawMeshPattern(t-e,A-e,e*2,e*2,.15),a.restore(),a.beginPath(),a.arc(s,r,o,0,2*Math.PI),a.stroke()):(a.beginPath(),a.arc(s,r,o,0,2*Math.PI),a.fill())}oval(t,A,e,i){const n=Pf(this.transform,e),o=Pf(this.transform,i),[s,r]=Ce(this.transform,[t,A]);this.applyAperture();const a=this.getLayerCtx();a.beginPath(),a.ellipse(s,r,n,o,0,0,2*Math.PI),a.fill(),a.closePath()}pill(t,A,e,i){const[n,o]=Ce(this.transform,[t-e/2,A+i/2]),s=Pf(this.transform,e),r=Pf(this.transform,i),a=Math.min(s,r)/2;this.applyAperture();const g=this.getLayerCtx();g.beginPath(),g.arc(n+a,o+a,a,Math.PI,Math.PI*1.5),g.arc(n+s-a,o+a,a,Math.PI*1.5,0),g.arc(n+s-a,o+r-a,a,0,Math.PI*.5),g.arc(n+a,o+r-a,a,Math.PI*.5,Math.PI),g.fill(),g.closePath()}polygon(t){if(t.length<3)return;this.applyAperture();const A=this.getLayerCtx(),e=t.map(n=>Ce(this.transform,[n.x,n.y]));A.beginPath(),A.moveTo(e[0][0],e[0][1]);for(let n=1;n<e.length;n++)A.lineTo(e[n][0],e[n][1]);A.closePath(),A.fill("evenodd");const i=Pf(this.transform,this.aperture.size);i>0&&(A.lineWidth=i,A.stroke())}debugText(t,A,e){const[i,n]=Ce(this.transform,[A,e]);this.applyAperture();const o=this.getLayerCtx();o.font="10px sans-serif",o.fillText(t,i,n)}getLayerCtx(){const t=this.ctxLayerMap[this.aperture.layer];if(!t)throw new Error(`No context for layer "${this.aperture.layer}"`);return t}orderAndFadeLayers(){const{canvasLayerMap:t,foregroundLayer:A}=this,e=A==="top"?"soldermask_top":A==="bottom"?"soldermask_bottom":void 0,i=A==="top"?"top_silkscreen":A==="bottom"?"bottom_silkscreen":void 0,n=A==="top"?"top_notes":A==="bottom"?"bottom_notes":void 0,o=A==="top"?"top_fabrication":A==="bottom"?"bottom_fabrication":void 0,s=A==="top"?"top_courtyard":A==="bottom"?"bottom_courtyard":void 0,r=new Set([A,"drill","edge_cuts","other","board",...e?[e]:[],...i?[i]:[],...n?[n]:[],...o?[o]:[],...s?[s]:[]]),a=[A,"edge_cuts",...e?[e]:[],...i?[i]:[],...n?[n]:[],...o?[o]:[],...s?[s]:[]],g=A==="drill"?[]:["drill"],c=A==="drill"?["drill"]:[],I=[...cei.filter(l=>!a.includes(l)),...g,A,...e?[e]:[],...c,"edge_cuts",...i?[i]:[],...n?[n]:[],...o?[o]:[],...s?[s]:[]];I.forEach((l,B)=>{const C=t[l];C&&(C.style.zIndex=`${kc.topLayer-(I.length-B)}`,C.style.opacity=r.has(l)?"1":"0.5")})}applyAperture(){const{transform:t,aperture:A}=this;let{size:e,mode:i,color:n,fontSize:o,layer:s}=A;s in this.ctxLayerMap||(this.aperture.layer="other");const r=this.getLayerCtx();if(!r)throw new Error(`No context for layer "${this.foregroundLayer}"`);if(n||(n="undefined"),r.lineWidth=Pf(t,e),r.lineCap="round",i==="add"){r.globalCompositeOperation="source-over";let a=vz[n.toLowerCase()];if(!a)try{a=Ta(n).rgb().toString()}catch{console.warn(`Invalid color format: '${n}'`),a="white"}r.fillStyle=a,r.strokeStyle=a}else r.globalCompositeOperation="destination-out",r.fillStyle="rgba(0,0,0,1)",r.strokeStyle="rgba(0,0,0,1)";r.font=`${Pf(tm(t),o)}px sans-serif`}moveTo(t,A){this.lastPoint={x:t,y:A}}lineTo(t,A){const[e,i]=Ce(this.transform,[t,A]),{size:n,shape:o,mode:s}=this.aperture,r=Pf(this.transform,n),{lastPoint:a}=this,g=Ce(this.transform,a);this.applyAperture();const c=this.getLayerCtx();o==="square"&&c.fillRect(g.x-r/2,g.y-r/2,r,r),c.beginPath(),c.moveTo(g.x,g.y),c.lineTo(e,i),c.stroke(),c.closePath(),o==="square"&&c.fillRect(e-r/2,i-r/2,r,r),this.lastPoint={x:t,y:A}}polygonWithArcs(t){const A=this.getLayerCtx(),e=i=>{if(i.vertices.length===0)return;const n=i.vertices[0],o=Ce(this.transform,[n.x,n.y]);A.moveTo(o[0],o[1]);for(let s=0;s<i.vertices.length;s++){const r=i.vertices[s],a=i.vertices[(s+1)%i.vertices.length];if(r.bulge&&r.bulge!==0){const g=r.bulge,c=a.x-r.x,I=a.y-r.y,l=Math.sqrt(c*c+I*I);if(l<1e-9){const F=Ce(this.transform,[a.x,a.y]);A.lineTo(F[0],F[1]);continue}const B=4*Math.atan(g),C=Math.abs(l/(2*Math.sin(B/2))),Q=(r.x+a.x)/2,h=(r.y+a.y)/2,E=c/l,d=-(I/l),f=E,y=Math.sqrt(Math.max(0,C*C-(l/2)**2)),w=Q+y*d*Math.sign(g),D=h+y*f*Math.sign(g),S=Math.atan2(r.y-D,r.x-w);let _=Math.atan2(a.y-D,a.x-w);g>0&&_<S?_+=2*Math.PI:g<0&&_>S&&(_-=2*Math.PI);const b=Ce(this.transform,[w,D]),N=Pf(this.transform,C);A.arc(b[0],b[1],N,-S,-_,g>0)}else{const g=Ce(this.transform,[a.x,a.y]);A.lineTo(g[0],g[1])}}A.closePath()};if(A.beginPath(),e(t.outer_ring),t.inner_rings)for(const i of t.inner_rings)e(i);A.fill("evenodd")}};function lei(t){return t.type==="pcb_copper_pour"}function Fz({canvas:t,elements:A,layers:e,realToCanvasMat:i}){const n=A.filter(lei);if(n.length===0)return;const o=new iQ(t);o.realToCanvasMat=i,o.drawElements(n,{layers:e})}var Bei={...gp,silkscreen:{top:yn.board.f_fab,bottom:yn.board.b_fab}};function Cei(t){return t.type.includes("pcb_fabrication_note")}function Khe({canvas:t,elements:A,layers:e,realToCanvasMat:i}){const n=new iQ(t);n.configure({colorOverrides:Bei}),n.realToCanvasMat=i;const o=A.filter(Cei);n.drawElements(o,{layers:e})}function Qei(t){return t.type==="pcb_hole"}function hei({canvas:t,elements:A,layers:e,realToCanvasMat:i,drawSoldermask:n}){const o=new iQ(t);o.realToCanvasMat=i;const s=A.filter(Qei);o.drawElements(s,{layers:e,drawSoldermask:n})}function Eei(t){return t.type==="pcb_board"}function uei({canvas:t,elements:A,layers:e,realToCanvasMat:i,drawSoldermask:n}){const o=new iQ(t);o.realToCanvasMat=i;const s=A.filter(Eei);for(const r of s)o.drawElements([r],{layers:e,drawSoldermask:!1,drawBoardMaterial:n??!1,minBoardOutlineStrokePx:2})}function dei(t){return t.type==="pcb_cutout"}function pei({canvas:t,elements:A,layers:e,realToCanvasMat:i}){const n=new iQ(t);n.realToCanvasMat=i;const o=A.filter(dei);n.drawElements(o,{layers:e})}function fei(t){return t.type==="pcb_keepout"}function yei({canvas:t,elements:A,layers:e,realToCanvasMat:i}){const n=A.filter(fei);if(n.length===0)return;const o=new iQ(t);o.realToCanvasMat=i,o.drawElements(n,{layers:[]})}function mei(t){return t.type.startsWith("pcb_note_")}function qhe({canvas:t,elements:A,layers:e,realToCanvasMat:i}){const n=new iQ(t);n.realToCanvasMat=i;const o=A.filter(mei);n.drawElements(o,{layers:e})}function wei(t){return t.type==="pcb_panel"}function Dei({canvas:t,elements:A,layers:e,realToCanvasMat:i,drawSoldermask:n}){const o=new iQ(t);o.realToCanvasMat=i;const s=A.filter(wei);for(const r of s)o.drawElements([r],{layers:e})}var Sei={...gp,copper:{...gp.copper,top:Ta(yn.board.pad_front).lighten(.5).toString(),bottom:Ta(yn.board.pad_back).lighten(.5).toString(),inner1:Ta(yn.board.copper.in1).lighten(.5).toString(),inner2:Ta(yn.board.copper.in2).lighten(.5).toString(),inner3:Ta(yn.board.copper.in3).lighten(.5).toString(),inner4:Ta(yn.board.copper.in4).lighten(.5).toString(),inner5:Ta(yn.board.copper.in5).lighten(.5).toString(),inner6:Ta(yn.board.copper.in6).lighten(.5).toString()}};function bei(t){return t.type==="pcb_smtpad"}function xei({canvas:t,elements:A,layers:e,realToCanvasMat:i,primitives:n,drawSoldermask:o}){const s=A.filter(bei).filter(c=>{const I=c.layer;return e.some(l=>l==="top_copper"&&I==="top"||l==="bottom_copper"&&I==="bottom"||l==="inner1_copper"&&I==="inner1"||l==="inner2_copper"&&I==="inner2"||l==="inner3_copper"&&I==="inner3"||l==="inner4_copper"&&I==="inner4"||l==="inner5_copper"&&I==="inner5"||l==="inner6_copper"&&I==="inner6")});if(s.length===0)return;const r=new Set;if(n)for(const c of n)(c.is_mouse_over||c.is_in_highlighted_net)&&c._element?.type==="pcb_smtpad"&&r.add(c._element.pcb_smtpad_id);const a=s.filter(c=>r.has(c.pcb_smtpad_id)),g=s.filter(c=>!r.has(c.pcb_smtpad_id));if(g.length>0){const c=new iQ(t);c.realToCanvasMat=i,c.drawElements(g,{layers:e,drawSoldermask:o})}if(a.length>0){const c=new iQ(t);c.configure({colorOverrides:Sei}),c.realToCanvasMat=i,c.drawElements(a,{layers:e,drawSoldermask:o})}}var _ei={...gp,copper:{...gp.copper,top:Ta(yn.board.pad_front).lighten(.5).toString(),bottom:Ta(yn.board.pad_back).lighten(.5).toString(),inner1:Ta(yn.board.copper.in1).lighten(.5).toString(),inner2:Ta(yn.board.copper.in2).lighten(.5).toString(),inner3:Ta(yn.board.copper.in3).lighten(.5).toString(),inner4:Ta(yn.board.copper.in4).lighten(.5).toString(),inner5:Ta(yn.board.copper.in5).lighten(.5).toString(),inner6:Ta(yn.board.copper.in6).lighten(.5).toString()}};function kei(t){return t.type==="pcb_trace"}var vei=t=>t.map(A=>A.endsWith("_copper")?A.replace("_copper",""):A),Fei=(t,A)=>{const e=t.route.filter(i=>i.route_type==="wire"&&"layer"in i&&A.has(i.layer));return e.length===0?null:{...t,route:e}};function Mei({canvas:t,elements:A,layers:e,realToCanvasMat:i,primitives:n}){const o=new Set(vei(e)),s=A.filter(kei).map(c=>Fei(c,o)).filter(c=>c!==null);if(s.length===0)return;const r=new Set;if(n)for(const c of n)(c.is_mouse_over||c.is_in_highlighted_net)&&c._element?.type==="pcb_trace"&&r.add(c._element.pcb_trace_id);const a=[],g=[];for(const c of s)r.has(c.pcb_trace_id)?a.push(c):g.push(c);if(g.length>0){const c=new iQ(t);c.realToCanvasMat=i,c.drawElements(g,{layers:e})}if(a.length>0){const c=new iQ(t);c.configure({colorOverrides:_ei}),c.realToCanvasMat=i,c.drawElements(a,{layers:e})}}var Rei={...gp,copper:{...gp.copper,top:Ta(yn.board.pad_front).lighten(.5).toString(),bottom:Ta(yn.board.pad_back).lighten(.5).toString()}};function Nei(t){return t.type==="pcb_plated_hole"}function Ohe({canvas:t,elements:A,layers:e,realToCanvasMat:i,primitives:n,drawSoldermask:o}){const s=A.filter(Nei);if(s.length===0)return;const r=new Set;if(n)for(const c of n)(c.is_mouse_over||c.is_in_highlighted_net)&&c._element?.type==="pcb_plated_hole"&&r.add(c._element.pcb_plated_hole_id);const a=s.filter(c=>r.has(c.pcb_plated_hole_id)),g=s.filter(c=>!r.has(c.pcb_plated_hole_id));if(g.length>0){const c=new iQ(t);c.realToCanvasMat=i,c.drawElements(g,{layers:e,drawSoldermask:o})}if(a.length>0){const c=new iQ(t);c.configure({colorOverrides:Rei}),c.realToCanvasMat=i,c.drawElements(a,{layers:e,drawSoldermask:o})}}function Whe(t){const{lines:A,anchorPoint:e,ccwRotation:i}=t;if(!i)return A;const n=i*Math.PI/180,o=Tl(n),s=An(on(e.x,e.y),o,on(-e.x,-e.y));return Ce(s,e),A.map(r=>({...r,x1:Ce(s,{x:r.x1,y:r.y1}).x,y1:Ce(s,{x:r.x1,y:r.y1}).y,x2:Ce(s,{x:r.x2,y:r.y2}).x,y2:Ce(s,{x:r.x2,y:r.y2}).y}))}var Gei=.6,Zhe=.2,Vhe=t=>{const A=t.size*.7,e=A*Gei,i=A*Zhe,n=A*Zhe,o=t.text.split(/\r?\n/),s=t.text.length>0&&A>0,r=s?o.length:0,a=s?o.map(I=>I.length===0?0:I.length*e+(I.length-1)*i):[],g=a.length>0?Math.max(...a):0,c=r>0?r*A+(r-1)*n:0;return{text_lines:o,line_count:r,line_widths:a,target_height:A,target_width_char:e,space_between_chars:i,space_between_lines:n,width:g,height:c}},jhe=t=>{const A=Vhe(t);return{width:A.width,height:A.height,lineHeight:A.target_height,lineSpacing:A.space_between_lines,lineCount:A.line_count}},zhe=t=>{const{text_lines:A,line_count:e,line_widths:i,target_height:n,target_width_char:o,space_between_chars:s,space_between_lines:r,width:a}=Vhe(t);if(n<=0||e===0)return[];const g=n/12,c=[];for(let I=0;I<e;I++){const l=-I*(n+r),B=i[I],C=(a-B)/2;let Q=t.x+C;for(let h=0;h<A[I].length;h++){const E=A[I][h],u=XF[E]??XF[E.toUpperCase()];if(!u){Q+=o+s;continue}for(const{x1:d,y1:f,x2:y,y2:w}of u)c.push({_pcb_drawing_object_id:Nm("line"),pcb_drawing_type:"line",x1:Q+o*d,y1:t.y+l+n*f,x2:Q+o*y,y2:t.y+l+n*w,width:g,layer:t.layer,unit:t.unit,color:t.color});Q+=o+s}}return c};function yS(t){const e=t.color??vz[t.layer];let i=Ta(e);return t._element?.type==="pcb_copper_pour"&&(i=i.alpha(.7)),t.is_mouse_over||t.is_in_highlighted_net?i.lighten(.5).rgb().toString():i.rgb().toString()}var Xhe=(t,A)=>{t.equip({size:A.zoomIndependent?A.width/t.transform.a:A.width,shape:A.squareCap?"square":"circle",color:yS(A),layer:A.layer}),t.moveTo(A.x1,A.y1),t.lineTo(A.x2,A.y2)},Lei=(t,A,e)=>{switch(e){case"top_left":return{x:0,y:-A};case"top_center":return{x:-t/2,y:-A};case"top_right":return{x:-t,y:-A};case"center_left":return{x:0,y:-A/2};case"center":return{x:-t/2,y:-A/2};case"center_right":return{x:-t,y:-A/2};case"bottom_left":return{x:0,y:0};case"bottom_center":return{x:-t/2,y:0};case"bottom_right":return{x:-t,y:0};default:return{x:0,y:0}}},$he=t=>t.layer==="bottom_silkscreen"||t.layer==="bottom"?t.is_mirrored!==!1:t.is_mirrored===!0,Uei=(t,A)=>{t.equip({fontSize:A.size,color:yS(A),layer:A.layer});const{width:e,height:i}=jhe(A),n=Lei(e,i,A.align);A.x??=0,A.y??=0;const o={x:A.x,y:A.y};let s=zhe({...A,x:A.x+n.x,y:A.y+n.y});if($he(A)&&(s=s.map(r=>({...r,x1:2*A.x-r.x1,x2:2*A.x-r.x2}))),A.ccw_rotation){const r={lines:s,anchorPoint:o,ccwRotation:A.ccw_rotation};s=Whe(r)}for(const r of s)Xhe(t,r)},Hei=(t,A)=>{const{width:e,height:i,lineHeight:n}=jhe(A);A.x??=0,A.y??=0;const o=A.knockout_padding??{left:A.size*.5,right:A.size*.5,top:A.size*.3,bottom:A.size*.3},s=e+o.left+o.right,r=i+o.top+o.bottom,a=e/2,g=n-i/2,c=A.x-a,I=A.y-g,l={x:A.x,y:A.y},B={_pcb_drawing_object_id:`knockout_rect_${A._pcb_drawing_object_id}`,x:A.x,y:A.y,w:s,h:r,layer:A.layer,ccw_rotation:A.ccw_rotation};A.ccw_rotation?eEe(t,B):AEe(t,B);let C=zhe({...A,x:c,y:I});if($he(A)&&(C=C.map(Q=>({...Q,x1:2*A.x-Q.x1,x2:2*A.x-Q.x2}))),A.ccw_rotation){const Q={lines:C,anchorPoint:l,ccwRotation:A.ccw_rotation};C=Whe(Q)}for(const Q of C)t.equip({size:Q.width,shape:"circle",color:"black",layer:A.layer,mode:"subtract"}),t.moveTo(Q.x1,Q.y1),t.lineTo(Q.x2,Q.y2);t.equip({mode:"add"})},AEe=(t,A)=>{t.equip({color:yS(A),layer:A.layer,size:A.stroke_width}),t.rect({x:A.x,y:A.y,w:A.w,h:A.h,mesh_fill:A.mesh_fill,is_filled:A.is_filled,has_stroke:A.has_stroke,is_stroke_dashed:A.is_stroke_dashed,stroke_width:A.stroke_width,roundness:A.roundness})},eEe=(t,A)=>{t.equip({color:yS(A),layer:A.layer}),t.rotatedRect(A.x,A.y,A.w,A.h,A.ccw_rotation,A.roundness,A.mesh_fill)},Yei=(t,A)=>{t.equip({color:yS(A),layer:A.layer}),t.rotatedPill(A.x,A.y,A.w,A.h,A.ccw_rotation)},Jei=(t,A)=>{t.equip({color:yS(A),layer:A.layer}),t.circle(A.x,A.y,A.r,A.mesh_fill)},Tei=(t,A)=>{t.equip({color:yS(A),layer:A.layer}),t.oval(A.x,A.y,A.rX,A.rY)},Pei=(t,A)=>{t.equip({color:yS(A),layer:A.layer}),t.pill(A.x,A.y,A.w,A.h)},Kei=(t,A)=>{t.equip({color:yS(A),layer:A.layer}),t.polygon(A.points)},qei=(t,A)=>{t.equip({color:yS(A),layer:A.layer}),t.polygonWithArcs(A.brep_shape)},Oei=(t,A)=>{switch(A.pcb_drawing_type){case"line":return Xhe(t,A);case"text":return A.is_knockout?Hei(t,A):Uei(t,A);case"rect":return A.ccw_rotation?eEe(t,A):AEe(t,A);case"circle":return Jei(t,A);case"oval":return Tei(t,A);case"pill":return A.ccw_rotation?Yei(t,A):Pei(t,A);case"polygon":return Kei(t,A);case"polygon_with_arcs":return qei(t,A)}},Wei=(t,A)=>{for(const e of A)Oei(t,e)},Zei={...gp,copper:{...gp.copper,top:Ta(yn.board.pad_front).lighten(.5).toString(),bottom:Ta(yn.board.pad_back).lighten(.5).toString(),inner1:Ta(yn.board.copper.in1).lighten(.5).toString(),inner2:Ta(yn.board.copper.in2).lighten(.5).toString(),inner3:Ta(yn.board.copper.in3).lighten(.5).toString(),inner4:Ta(yn.board.copper.in4).lighten(.5).toString(),inner5:Ta(yn.board.copper.in5).lighten(.5).toString(),inner6:Ta(yn.board.copper.in6).lighten(.5).toString()},soldermask:{...gp.soldermask,top:Ta(yn.board.soldermask.top).lighten(.35).toString(),bottom:Ta(yn.board.soldermask.bottom).lighten(.35).toString()}};function tEe({canvas:t,elements:A,layers:e,realToCanvasMat:i,drawSoldermaskTop:n,drawSoldermaskBottom:o,primitives:s}){const r=new iQ(t);r.realToCanvasMat=i;const a=A.filter(l=>l.type==="pcb_board");if(a.length<=1)r.drawElements(A,{layers:e,drawSoldermask:!0,drawSoldermaskTop:n,drawSoldermaskBottom:o,drawBoardMaterial:!1});else{const l=A.filter(B=>B.type!=="pcb_board");for(const B of a)r.drawElements([B,...l],{layers:e,drawSoldermask:!0,drawSoldermaskTop:n,drawSoldermaskBottom:o,drawBoardMaterial:!1})}if(!s)return;const g=new Set;for(const l of s){if(!(l.is_mouse_over||l.is_in_highlighted_net))continue;const B=l._element;B?.type==="pcb_smtpad"?g.add(B.pcb_smtpad_id):B?.type==="pcb_plated_hole"?g.add(B.pcb_plated_hole_id):B?.type==="pcb_via"&&g.add(B.pcb_via_id)}if(g.size===0)return;const c=A.filter(l=>l.type==="pcb_smtpad"?g.has(l.pcb_smtpad_id):l.type==="pcb_plated_hole"?g.has(l.pcb_plated_hole_id):l.type==="pcb_via"?g.has(l.pcb_via_id):!1);if(c.length===0)return;const I=new iQ(t);I.configure({colorOverrides:Zei}),I.realToCanvasMat=i,I.drawElements(c,{layers:e,drawSoldermask:!0,drawSoldermaskTop:n,drawSoldermaskBottom:o,drawBoardMaterial:!1})}var Vei={...gp,silkscreen:{top:yn.board.f_silks,bottom:yn.board.b_silks}};function jei(t){return t.type.includes("pcb_silkscreen")}function iEe({canvas:t,elements:A,layers:e,realToCanvasMat:i}){const n=new iQ(t);n.configure({colorOverrides:Vei}),n.realToCanvasMat=i;const o=A.filter(jei);n.drawElements(o,{layers:e})}var zei={...gp,copper:{...gp.copper,top:Ta(yn.board.pad_front).lighten(.5).toString(),bottom:Ta(yn.board.pad_back).lighten(.5).toString()}};function Xei(t){return t.type==="pcb_via"}function nEe({canvas:t,elements:A,layers:e,realToCanvasMat:i,primitives:n,drawSoldermask:o}){const s=A.filter(Xei).filter(c=>e.some(I=>I.includes("copper")));if(s.length===0)return;const r=new Set;if(n)for(const c of n)(c.is_mouse_over||c.is_in_highlighted_net)&&c._element?.type==="pcb_via"&&r.add(c._element.pcb_via_id);const a=s.filter(c=>r.has(c.pcb_via_id)),g=s.filter(c=>!r.has(c.pcb_via_id));if(g.length>0){const c=new iQ(t);c.realToCanvasMat=i,c.drawElements(g,{layers:e,drawSoldermask:o})}if(a.length>0){const c=new iQ(t);c.configure({colorOverrides:zei}),c.realToCanvasMat=i,c.drawElements(a,{layers:e,drawSoldermask:o})}}var $ei={...gp,courtyard:{top:yn.board.f_crtyd,bottom:yn.board.b_crtyd}};function Ati(t){return t.type==="pcb_courtyard_circle"||t.type==="pcb_courtyard_rect"||t.type==="pcb_courtyard_outline"}function oEe({canvas:t,elements:A,layers:e,realToCanvasMat:i}){const n=new iQ(t);n.configure({colorOverrides:$ei}),n.realToCanvasMat=i;const o=A.filter(Ati);n.drawElements(o,{layers:e})}var eti=["board","bottom","soldermask_bottom","bottom_silkscreen","top","soldermask_top","soldermask_with_copper_bottom","soldermask_with_copper_top","top_fabrication","bottom_fabrication","inner1","inner2","inner3","inner4","inner5","inner6","drill","edge_cuts","bottom_notes","top_notes","top_silkscreen","top_courtyard","bottom_courtyard","other"],tti=({primitives:t,elements:A,transform:e,grid:i,width:n=500,height:o=500})=>{const s=V.useRef({}),r=gl(l=>l.selected_layer),a=gl(l=>l.is_showing_solder_mask),g=gl(l=>l.is_showing_fabrication_notes),c=gl(l=>l.is_showing_courtyards),I=gl(l=>l.is_showing_silkscreen);return V.useEffect(()=>{if(!s.current||Object.keys(s.current).length===0)return;const l=Object.fromEntries(Object.entries(s.current).filter(([Q,h])=>!!h));if(Object.keys(l).length===0)return;const B=new Iei(l);e&&(B.transform=e),B.clear(),B.foregroundLayer=r;const C=t.filter(Q=>a||!Q.layer?.includes("soldermask")).filter(Q=>I||!Q.layer?.includes("silkscreen")).filter(Q=>g||!Q.layer?.includes("fabrication")).filter(Q=>Q.layer!=="board").filter(Q=>Q._element?.type!=="pcb_smtpad").filter(Q=>Q._element?.type!=="pcb_plated_hole").filter(Q=>Q._element?.type!=="pcb_via").filter(Q=>Q._element?.type!=="pcb_trace");if(Wei(B,C),e){const Q=s.current.top,h=s.current.bottom,E=s.current.inner1,u=s.current.inner2,d=s.current.inner3,f=s.current.inner4,y=s.current.inner5,w=s.current.inner6,D=[{canvas:Q,copperLayer:"top_copper"},{canvas:h,copperLayer:"bottom_copper"},{canvas:E,copperLayer:"inner1_copper"},{canvas:u,copperLayer:"inner2_copper"},{canvas:d,copperLayer:"inner3_copper"},{canvas:f,copperLayer:"inner4_copper"},{canvas:y,copperLayer:"inner5_copper"},{canvas:w,copperLayer:"inner6_copper"}];for(const{canvas:Y,copperLayer:J}of D)Y&&Mei({canvas:Y,elements:A,layers:[J],realToCanvasMat:e,primitives:t});Q&&Ohe({canvas:Q,elements:A,layers:["top_copper"],realToCanvasMat:e,primitives:t,drawSoldermask:a}),h&&Ohe({canvas:h,elements:A,layers:["bottom_copper"],realToCanvasMat:e,primitives:t,drawSoldermask:a}),Q&&Fz({canvas:Q,elements:A,layers:["top_copper"],realToCanvasMat:e}),h&&Fz({canvas:h,elements:A,layers:["bottom_copper"],realToCanvasMat:e});for(const{canvas:Y,copperLayer:J}of D)Y&&xei({canvas:Y,elements:A,layers:[J],realToCanvasMat:e,primitives:t,drawSoldermask:a});if(Q&&nEe({canvas:Q,elements:A,layers:["top_copper"],realToCanvasMat:e,primitives:t,drawSoldermask:a}),h&&nEe({canvas:h,elements:A,layers:["bottom_copper"],realToCanvasMat:e,primitives:t,drawSoldermask:a}),a){const Y=r==="bottom"?"bottom":"top",J=Y==="top",O=Y==="bottom",Z=s.current.soldermask_top;Z&&Y==="top"&&tEe({canvas:Z,elements:A,layers:["top_soldermask"],realToCanvasMat:e,drawSoldermaskTop:J,drawSoldermaskBottom:O,primitives:t});const X=s.current.soldermask_bottom;X&&Y==="bottom"&&tEe({canvas:X,elements:A,layers:["bottom_soldermask"],realToCanvasMat:e,drawSoldermaskTop:J,drawSoldermaskBottom:O,primitives:t})}Q&&Fz({canvas:Q,elements:A,layers:["top_copper"],realToCanvasMat:e}),h&&Fz({canvas:h,elements:A,layers:["bottom_copper"],realToCanvasMat:e});const S=s.current.drill;if(S&&hei({canvas:S,elements:A,layers:["drill"],realToCanvasMat:e}),I){const Y=s.current.top_silkscreen;Y&&iEe({canvas:Y,elements:A,layers:["top_silkscreen"],realToCanvasMat:e});const J=s.current.bottom_silkscreen;J&&iEe({canvas:J,elements:A,layers:["bottom_silkscreen"],realToCanvasMat:e})}if(g){const Y=s.current.top_fabrication;Y&&Khe({canvas:Y,elements:A,layers:["top_fabrication_note"],realToCanvasMat:e});const J=s.current.bottom_fabrication;J&&Khe({canvas:J,elements:A,layers:["bottom_fabrication_note"],realToCanvasMat:e})}const _=s.current.bottom_notes;_&&qhe({canvas:_,elements:A,layers:["bottom_user_note"],realToCanvasMat:e});const b=s.current.top_notes;if(b&&qhe({canvas:b,elements:A,layers:["top_user_note"],realToCanvasMat:e}),c){const Y=s.current.top_courtyard;Y&&oEe({canvas:Y,elements:A,layers:["top_courtyard"],realToCanvasMat:e});const J=s.current.bottom_courtyard;J&&oEe({canvas:J,elements:A,layers:["bottom_courtyard"],realToCanvasMat:e})}const N=s.current.board;N&&(Dei({canvas:N,elements:A,layers:[],realToCanvasMat:e,drawSoldermask:a}),uei({canvas:N,elements:A,layers:[],realToCanvasMat:e,drawSoldermask:a}));const F=s.current.edge_cuts;F&&pei({canvas:F,elements:A,layers:["edge_cuts"],realToCanvasMat:e});const L=[{canvas:Q,layer:"top"},{canvas:h,layer:"bottom"}];for(const{canvas:Y,layer:J}of L)Y&&yei({canvas:Y,elements:A,layers:[J],realToCanvasMat:e})}B.orderAndFadeLayers()},[t,A,e,r,a,g,c,I]),W.jsxs("div",{style:{backgroundColor:"black",width:n,height:o,position:"relative"},children:[W.jsx(hz.SuperGrid,{textColor:"rgba(0,255,0,0.8)",majorColor:"rgba(0,255,0,0.4)",minorColor:"rgba(0,255,0,0.2)",screenSpaceCellSize:200,width:n,height:o,transform:e,stringifyCoord:(l,B,C)=>`${hz.toMMSI(l,C)}, ${hz.toMMSI(B,C)}`}),eti.filter(l=>!(!a&&l.includes("soldermask")||!I&&l.includes("silkscreen"))).map(l=>l.replace(/-/g,"")).map((l,B)=>W.jsx("canvas",{className:`pcb-layer-${l}`,ref:C=>{s.current??={},C?s.current[l]=C:delete s.current[l]},style:{position:"absolute",zIndex:B,left:0,top:0,pointerEvents:"none"},width:n,height:o},l))]})},iti=.6,nti=1;CmA(cAi(),1),CmA(SAi(),1);var Mz=["rgba(239, 68, 68, 0.8)","rgba(249, 115, 22, 0.8)","rgba(245, 158, 11, 0.8)","rgba(234, 179, 8, 0.8)","rgba(132, 204, 22, 0.8)","rgba(34, 197, 94, 0.8)","rgba(16, 185, 129, 0.8)","rgba(20, 184, 166, 0.8)","rgba(6, 182, 212, 0.8)","rgba(14, 165, 233, 0.8)","rgba(59, 130, 246, 0.8)","rgba(99, 102, 241, 0.8)","rgba(139, 92, 246, 0.8)","rgba(168, 85, 247, 0.8)","rgba(217, 70, 239, 0.8)","rgba(236, 72, 153, 0.8)","rgba(249, 168, 212, 0.8)","rgba(161, 161, 170, 0.8)"];function sEe(t,A,e,i={}){const n=i.padding??40,o=i.yFlip??!1;let s;if("center"in t){const c=t.width/2,I=t.height/2;s={minX:t.center.x-c,maxX:t.center.x+c,minY:t.center.y-I,maxY:t.center.y+I}}else s=t;const r=s.maxX-s.minX||1,a=s.maxY-s.minY||1,g=Math.min((A-2*n)/r,(e-2*n)/a);return An(on(A/2,e/2),$a(g,o?-g:g),on(-(s.minX+r/2),-(s.minY+a/2)))}function oti(t){const A=[...t.points||[],...(t.lines||[]).flatMap(e=>e.points),...(t.rects||[]).flatMap(e=>{const i=e.width/2,n=e.height/2;return[{x:e.center.x-i,y:e.center.y-n},{x:e.center.x+i,y:e.center.y-n},{x:e.center.x-i,y:e.center.y+n},{x:e.center.x+i,y:e.center.y+n}]}),...(t.circles||[]).flatMap(e=>[{x:e.center.x-e.radius,y:e.center.y},{x:e.center.x+e.radius,y:e.center.y},{x:e.center.x,y:e.center.y-e.radius},{x:e.center.x,y:e.center.y+e.radius}]),...(t.texts||[]).flatMap(e=>{const i=e.fontSize??12,n=e.text.length*i*iti,o=i*nti,s=e.anchorSide??"center",r={top_left:{dx:0,dy:0},top_center:{dx:-n/2,dy:0},top_right:{dx:-n,dy:0},center_left:{dx:0,dy:-o/2},center:{dx:-n/2,dy:-o/2},center_right:{dx:-n,dy:-o/2},bottom_left:{dx:0,dy:-o},bottom_center:{dx:-n/2,dy:-o},bottom_right:{dx:-n,dy:-o}},{dx:a,dy:g}=r[s],c=e.x+a,I=e.y+g;return[{x:c,y:I},{x:c+n,y:I+o}]})];return A.length===0?{minX:-1,maxX:1,minY:-1,maxY:1}:A.reduce((e,i)=>({minX:Math.min(e.minX,i.x),maxX:Math.max(e.maxX,i.x),minY:Math.min(e.minY,i.y),maxY:Math.max(e.maxY,i.y)}),{minX:1/0,maxX:-1/0,minY:1/0,maxY:-1/0})}function sti(t,A,e={}){const i=A instanceof HTMLCanvasElement?A.getContext("2d"):A;if(!i)throw new Error("Could not get 2D context from canvas");const n=A instanceof HTMLCanvasElement?A.width:A.canvas.width,o=A instanceof HTMLCanvasElement?A.height:A.canvas.height;let s;if(e.transform)s=e.transform;else if(e.viewbox)s=sEe(e.viewbox,n,o,{padding:e.padding,yFlip:e.yFlip});else{const r=oti(t),a=t.coordinateSystem==="cartesian";s=sEe(r,n,o,{padding:e.padding??40,yFlip:a})}i.clearRect(0,0,n,o),i.save(),t.rects&&t.rects.length>0&&t.rects.forEach(r=>{const a=r.width/2,g=r.height/2,c=Ce(s,{x:r.center.x-a,y:r.center.y-g}),I=Ce(s,{x:r.center.x+a,y:r.center.y+g}),l=Math.abs(I.x-c.x),B=Math.abs(I.y-c.y);i.beginPath(),i.rect(Math.min(c.x,I.x),Math.min(c.y,I.y),l,B),r.fill&&(i.fillStyle=r.fill,i.fill()),r.stroke&&(i.strokeStyle=r.stroke,i.stroke())}),t.circles&&t.circles.length>0&&t.circles.forEach(r=>{const a=Ce(s,r.center),g=r.radius*Math.abs(s.a);i.beginPath(),i.arc(a.x,a.y,g,0,2*Math.PI),r.fill&&(i.fillStyle=r.fill,i.fill()),r.stroke&&(i.strokeStyle=r.stroke??"transparent",i.stroke())}),t.lines&&t.lines.length>0&&t.lines.forEach((r,a)=>{if(r.points.length===0)return;i.beginPath();const g=Ce(s,r.points[0]);i.moveTo(g.x,g.y);for(let c=1;c<r.points.length;c++){const I=Ce(s,r.points[c]);i.lineTo(I.x,I.y)}if(i.strokeStyle=r.strokeColor||Mz[a%Mz.length],r.strokeWidth?i.lineWidth=r.strokeWidth*s.a:i.lineWidth=2,i.lineCap="round",r.strokeDash)if(typeof r.strokeDash=="string"){let c;if(r.strokeDash.includes(","))c=r.strokeDash.split(",").map(I=>parseFloat(I.trim())).filter(I=>!Number.isNaN(I));else{const I=parseFloat(r.strokeDash.trim());c=Number.isNaN(I)?[]:[I]}i.setLineDash(c)}else i.setLineDash(r.strokeDash.map(c=>c*Math.abs(s.a)));else i.setLineDash([]);i.stroke()}),t.points&&t.points.length>0&&t.points.forEach((r,a)=>{const g=Ce(s,r);i.beginPath(),i.arc(g.x,g.y,3,0,2*Math.PI),i.fillStyle=r.color||Mz[a%Mz.length],i.fill(),r.label&&!e.disableLabels&&(i.fillStyle=r.color||"black",i.font="12px sans-serif",i.fillText(r.label,g.x+5,g.y-5))}),t.texts&&t.texts.length>0&&t.texts.forEach(r=>{const a=Ce(s,{x:r.x,y:r.y});i.fillStyle=r.color||"black",i.font=`${(r.fontSize??12)*Math.abs(s.a)}px sans-serif`;const g=r.anchorSide??"center",c={top_left:"left",center_left:"left",bottom_left:"left",top_center:"center",center:"center",bottom_center:"center",top_right:"right",center_right:"right",bottom_right:"right"},I={top_left:"top",top_center:"top",top_right:"top",center_left:"middle",center:"middle",center_right:"middle",bottom_left:"bottom",bottom_center:"bottom",bottom_right:"bottom"};i.textAlign=c[g],i.textBaseline=I[g],i.fillText(r.text,a.x,a.y)}),i.restore()}var rti=({children:t,transform:A,debugGraphics:e})=>{const i=V.useRef(null),[n,{width:o,height:s}]=qT(),r=gl(a=>a.is_showing_autorouting);return V.useEffect(()=>{r&&i.current&&e&&o&&s&&(i.current.width=o,i.current.height=s,sti(e,i.current,{transform:A,disableLabels:!0}))},[e,A,o,s,r]),r?W.jsxs("div",{ref:n,style:{position:"relative",width:"100%",height:"100%"},children:[t,W.jsx("canvas",{ref:i,style:{position:"absolute",top:0,left:0,opacity:.5,zIndex:100,width:"100%",height:"100%",pointerEvents:"none"}})]}):t},ati=({children:t,transform:A=xa(),elements:e=[]})=>{const[i,{width:n,height:o}]=qT(),s=V.useRef(null);return V.useEffect(()=>{const r=s.current;if(!r||!n||!o)return;r.width=n,r.height=o;const a=r.getContext("2d");if(!a)return;a.clearRect(0,0,n,o);const g=e.filter(I=>I.type==="pcb_component"),c=e.filter(I=>I.type==="pcb_manual_edit_conflict_warning");a.strokeStyle=yn.board.drc_warning,a.lineWidth=2,c.forEach(I=>{const l=g.find(O=>O.pcb_component_id===I.pcb_component_id);if(!l)return;const{width:B,height:C,center:Q}=l,h=Ce(A,Q),E=B*Math.abs(A.a),u=C*Math.abs(A.d),d=.1*Math.abs(A.a),f=E+d*2,y=u+d*2,w=h.x-f/2,D=h.y-y/2;a.beginPath(),a.rect(w,D,f,y),a.stroke();const S="Manual Edit Conflict",_=4,b=Math.max(8,Math.min(12,10*Math.abs(A.a)));a.font=`${b}px sans-serif`;const F=a.measureText(S).width+_*2,L=b+_*2,Y=w+(f-F)/2,J=D+y+5;a.fillStyle="rgba(0, 0, 0, 0.7)",a.beginPath(),a.roundRect(Y,J,F,L,3),a.fill(),a.fillStyle=yn.board.drc_warning,a.textAlign="center",a.textBaseline="middle",a.fillText(S,Y+F/2,J+L/2)})},[e,A,n,o]),W.jsxs("div",{ref:i,style:{position:"relative",width:"100%",height:"100%"},children:[t,W.jsx("canvas",{ref:s,style:{position:"absolute",top:0,left:0,pointerEvents:"none",zIndex:kc.warnings}})]})},Rz=(t,A,e)=>e(t,A),rEe=(t,A,e,i,n)=>{const o=n*Math.PI/180,s=Math.cos(o),r=Math.sin(o),a=t-e,g=A-i,c=a*s-g*r,I=a*r+g*s;return{x:c+e,y:I+i}},OT=t=>{if(t.length===0)return null;let A=t[0].x,e=t[0].x,i=t[0].y,n=t[0].y;for(const o of t)A=Rz(A,o.x,Math.min),e=Rz(e,o.x,Math.max),i=Rz(i,o.y,Math.min),n=Rz(n,o.y,Math.max);return{minX:A,maxX:e,minY:i,maxY:n}},gti=(t,A)=>({minX:Math.min(t.minX,A.minX),maxX:Math.max(t.maxX,A.maxX),minY:Math.min(t.minY,A.minY),maxY:Math.max(t.maxY,A.maxY)}),cti=(t,A)=>t?gti(t,A):A,Iti=t=>{switch(t.pcb_drawing_type){case"line":{const A=(t.width??0)/2,e=[{x:t.x1,y:t.y1},{x:t.x2,y:t.y2}],i=OT(e);return i?{minX:i.minX-A,maxX:i.maxX+A,minY:i.minY-A,maxY:i.maxY+A}:null}case"rect":{const A=t.w/2,e=t.h/2,i=[{x:t.x-A,y:t.y-e},{x:t.x+A,y:t.y-e},{x:t.x+A,y:t.y+e},{x:t.x-A,y:t.y+e}],n=t.ccw_rotation??0,o=n===0?i:i.map(s=>rEe(s.x,s.y,t.x,t.y,n));return OT(o)}case"circle":return{minX:t.x-t.r,maxX:t.x+t.r,minY:t.y-t.r,maxY:t.y+t.r};case"oval":return{minX:t.x-t.rX,maxX:t.x+t.rX,minY:t.y-t.rY,maxY:t.y+t.rY};case"pill":{const A=t.w/2,e=t.h/2,i=[{x:t.x-A,y:t.y-e},{x:t.x+A,y:t.y-e},{x:t.x+A,y:t.y+e},{x:t.x-A,y:t.y+e}],n=t.ccw_rotation??0,o=n===0?i:i.map(s=>rEe(s.x,s.y,t.x,t.y,n));return OT(o)}case"polygon":return OT(t.points);case"polygon_with_arcs":{const A=t.brep_shape.outer_ring.vertices.map(e=>({x:e.x,y:e.y}));return OT(A)}case"text":{const A=t.size??0,e=t.text?t.text.length*A*.6:0,i=A;if(e===0&&i===0)return{minX:t.x,maxX:t.x,minY:t.y,maxY:t.y};const n=e/2,o=i/2;return{minX:t.x-n,maxX:t.x+n,minY:t.y-o,maxY:t.y+o}}default:return null}};function lti(t){const{dimensionStart:A,dimensionEnd:e,screenDimensionStart:i,screenDimensionEnd:n,flipX:o,flipY:s}=t,r=e.x-A.x,a=e.y-A.y,g=Math.sqrt(r*r+a*a),c=n.x-i.x,I=n.y-i.y,l=Math.sqrt(c*c+I*I),B=Math.atan2(I,c)*(180/Math.PI),C=Math.abs(B)%90,h=Math.min(C,90-C)>15,E=(i.x+n.x)/2,u=(i.y+n.y)/2,d=15,f=B+90;let y=Math.cos(f*Math.PI/180)*d,w=Math.sin(f*Math.PI/180)*d;const D=c>0&&I<0,S=c>0&&I>0,_=c<0&&I>0;o!==s&&!D&&(y=-y,w=-w),D&&(y+=Math.cos(f*Math.PI/180)*-45,w+=Math.sin(f*Math.PI/180)*-45),S&&(y+=Math.cos(f*Math.PI/180)+-20,w+=Math.sin(f*Math.PI/180)+-10),_&&(y+=Math.cos(f*Math.PI/180)*10,w+=Math.sin(f*Math.PI/180)*10);const b=E+y,N=u+w;return{distance:g,screenDistance:l,x:b,y:N,show:g>.01&&l>30&&h}}function Bti(t){const{dimensionStart:A,dimensionEnd:e,screenDimensionStart:i,screenDimensionEnd:n,flipX:o,flipY:s}=t;return V.useMemo(()=>lti({dimensionStart:A,dimensionEnd:e,screenDimensionStart:i,screenDimensionEnd:n,flipX:o,flipY:s}),[A,e,i,n,o,s])}var Cti=(t,A,e)=>{const i=e*Math.PI/180,n=Math.cos(i),o=Math.sin(i),s=t.x-A.x,r=t.y-A.y,a=s*n-r*o,g=s*o+r*n;return{x:a+A.x,y:g+A.y}},aEe=(t,A,e,i)=>{const n={top_left:{x:t.x-A,y:t.y-e},top_center:{x:t.x,y:t.y-e},top_right:{x:t.x+A,y:t.y-e},center_left:{x:t.x-A,y:t.y},center:{x:t.x,y:t.y},center_right:{x:t.x+A,y:t.y},bottom_left:{x:t.x-A,y:t.y+e},bottom_center:{x:t.x,y:t.y+e},bottom_right:{x:t.x+A,y:t.y+e}};return i===0?Object.entries(n).map(([o,s])=>({anchor:o,point:s})):Object.entries(n).map(([o,s])=>({anchor:o,point:Cti(s,t,i)}))},Qti=t=>{switch(t.pcb_drawing_type){case"rect":{const A=t.ccw_rotation??0;return aEe({x:t.x,y:t.y},t.w/2,t.h/2,A)}case"pill":{const A=t.ccw_rotation??0;return aEe({x:t.x,y:t.y},t.w/2,t.h/2,A)}case"circle":return[{anchor:"circle_center",point:{x:t.x,y:t.y}},{anchor:"circle_right",point:{x:t.x+t.r,y:t.y}},{anchor:"circle_left",point:{x:t.x-t.r,y:t.y}},{anchor:"circle_top",point:{x:t.x,y:t.y-t.r}},{anchor:"circle_bottom",point:{x:t.x,y:t.y+t.r}}];case"oval":return[{anchor:"oval_center",point:{x:t.x,y:t.y}},{anchor:"oval_right",point:{x:t.x+t.rX,y:t.y}},{anchor:"oval_left",point:{x:t.x-t.rX,y:t.y}},{anchor:"oval_top",point:{x:t.x,y:t.y-t.rY}},{anchor:"oval_bottom",point:{x:t.x,y:t.y+t.rY}}];case"line":{const A={x:(t.x1+t.x2)/2,y:(t.y1+t.y2)/2};return[{anchor:"line_start",point:{x:t.x1,y:t.y1}},{anchor:"line_mid",point:A},{anchor:"line_end",point:{x:t.x2,y:t.y2}}]}case"polygon":return t.points.map((A,e)=>({anchor:`polygon_vertex_${e}`,point:A}));case"polygon_with_arcs":return t.brep_shape.outer_ring.vertices.map((A,e)=>({anchor:`polygon_with_arcs_vertex_${e}`,point:{x:A.x,y:A.y}}));default:return[]}},hti=16,UM=5,gEe=t=>{if(t.pcb_drawing_type==="text")return!0;const A=t._element;if(!A||typeof A!="object")return!1;const e=typeof A.type=="string"?A.type:void 0;return e?!!(e.startsWith("pcb_silkscreen_")||e.startsWith("pcb_note_")||e==="pcb_text"||e.startsWith("pcb_fabrication_note_")&&e!=="pcb_fabrication_note_rect"):!1},Eti=({children:t,transform:A,focusOnHover:e=!1,primitives:i=[]})=>{A||(A=xa());const[n,o]=V.useState(!1),[s,r]=V.useState(!1),[a,g]=V.useState(!1),[c,I]=V.useState({start:null,end:null}),l=gl(J=>J.is_mouse_over_container),B=V.useCallback(()=>{a&&(g(!1),window.dispatchEvent(new Event("disarm-dimension-tool")))},[a]),[C,Q]=V.useState({x:0,y:0}),[h,E]=V.useState({x:0,y:0}),u=V.useRef({x:0,y:0}),d=V.useRef(null),y=d.current?.getBoundingClientRect(),w=V.useMemo(()=>{const J=new Map;for(const O of i){if(!O._element||gEe(O)||O.pcb_drawing_type==="pill"||O.pcb_drawing_type==="rect"&&O.ccw_rotation&&O.ccw_rotation!==0)continue;const Z=Iti(O);if(!Z)continue;const X=J.get(O._element);J.set(O._element,cti(X??void 0,Z))}return J},[i]),D=V.useMemo(()=>{const J=[];for(const O of i){if(!O._element||gEe(O))continue;const Z=Qti(O);if(Z.length!==0)for(const X of Z)J.push({anchor:X.anchor,point:X.point,element:O._element})}return J},[i]),S=V.useMemo(()=>{const J=[];w.forEach((O,Z)=>{if(!O)return;const X=(O.minX+O.maxX)/2,eA=(O.minY+O.maxY)/2,gA={top_left:{x:O.minX,y:O.minY},top_center:{x:X,y:O.minY},top_right:{x:O.maxX,y:O.minY},center_left:{x:O.minX,y:eA},center:{x:X,y:eA},center_right:{x:O.maxX,y:eA},bottom_left:{x:O.minX,y:O.maxY},bottom_center:{x:X,y:O.maxY},bottom_right:{x:O.maxX,y:O.maxY}};for(const[tA,iA]of Object.entries(gA))J.push({anchor:tA,point:iA,element:Z})});for(const O of D)J.push(O);return J.push({anchor:"origin",point:{x:0,y:0},element:null}),J},[w,D]),_=V.useMemo(()=>S.map((J,O)=>({...J,id:`${O}-${J.anchor}`,screenPoint:Ce(A,J.point)})),[S,A]),b=V.useCallback(J=>{if(_.length===0)return{point:J,id:null};const O=Ce(A,J);let Z=null;for(const X of _){const eA=X.screenPoint.x-O.x,gA=X.screenPoint.y-O.y,tA=Math.hypot(eA,gA);tA>hti||(!Z||tA<Z.distance)&&(Z={distance:tA,id:X.id,point:X.point})}return Z?{point:Z.point,id:Z.id}:{point:J,id:null}},[_,A]);V.useEffect(()=>{const J=Z=>{const X=Z.target;if(X.tagName==="INPUT"||X.tagName==="TEXTAREA"||X.isContentEditable)return;const eA=d.current?.contains(document.activeElement)||document.activeElement===d.current;if(!(!l&&!eA)){if(Z.key==="d"){const gA=b({x:u.current.x,y:u.current.y});Q({x:gA.point.x,y:gA.point.y}),E({x:gA.point.x,y:gA.point.y}),I({start:gA.id,end:gA.id}),n?(o(!1),r(!1),I({start:null,end:null})):(o(!0),r(!0)),B()}Z.key==="Escape"&&(o(!1),r(!1),I({start:null,end:null}),B())}},O=()=>{g(!0)};return window.addEventListener("keydown",J),window.addEventListener("arm-dimension-tool",O),()=>{window.removeEventListener("keydown",J),window.removeEventListener("arm-dimension-tool",O),B()}},[l,n,B,b]);const N=Ce(A,C),F=Ce(A,h),L={left:Math.min(N.x,F.x),right:Math.max(N.x,F.x),top:Math.min(N.y,F.y),bottom:Math.max(N.y,F.y),flipX:N.x>F.x,flipY:N.y>F.y,width:0,height:0};L.width=L.right-L.left,L.height=L.bottom-L.top;const Y=Bti({dimensionStart:C,dimensionEnd:h,screenDimensionStart:N,screenDimensionEnd:F,flipX:L.flipX,flipY:L.flipY});return W.jsxs("div",{ref:d,"data-pcb-viewer":!0,tabIndex:0,style:{position:"relative",outline:"none"},onMouseEnter:()=>{e&&d.current&&d.current.focus()},onMouseLeave:()=>{d.current&&d.current.blur()},onClick:()=>{d.current&&d.current.focus()},onMouseMove:J=>{const O=J.currentTarget.getBoundingClientRect(),Z=J.clientX-O.left,X=J.clientY-O.top,eA=Ce(tm(A),{x:Z,y:X});if(u.current.x=eA.x,u.current.y=eA.y,s){const gA=b(eA);E({x:gA.point.x,y:gA.point.y}),I(tA=>({...tA,end:gA.id}))}},onMouseDown:J=>{const O=J.currentTarget.getBoundingClientRect(),Z=J.clientX-O.left,X=J.clientY-O.top,eA=Ce(tm(A),{x:Z,y:X});if(a&&!n){const gA=b(eA);Q({x:gA.point.x,y:gA.point.y}),E({x:gA.point.x,y:gA.point.y}),I({start:gA.id,end:gA.id}),o(!0),r(!0),B()}else s?(r(!1),I(gA=>({...gA,end:null}))):n&&(o(!1),I({start:null,end:null}))},children:[t,n&&W.jsxs(W.Fragment,{children:[Y.show&&W.jsx("div",{style:{position:"absolute",left:Y.x,top:Y.y,color:"red",mixBlendMode:"difference",pointerEvents:"none",fontSize:12,fontFamily:"sans-serif",whiteSpace:"nowrap",zIndex:kc.dimensionOverlay},children:Y.distance.toFixed(2)}),W.jsx("div",{style:{position:"absolute",left:L.left,width:L.width,textAlign:"center",top:N.y+2,color:"red",mixBlendMode:"difference",pointerEvents:"none",marginTop:L.flipY?0:-20,fontSize:12,fontFamily:"sans-serif",zIndex:kc.dimensionOverlay},children:Math.abs(C.x-h.x).toFixed(2)}),W.jsx("div",{style:{position:"absolute",left:F.x,height:L.height,display:"flex",flexDirection:"column",justifyContent:"center",top:L.top,color:"red",pointerEvents:"none",mixBlendMode:"difference",fontSize:12,fontFamily:"sans-serif",zIndex:kc.dimensionOverlay},children:W.jsx("div",{style:{marginLeft:L.flipX?"-100%":4,paddingRight:4},children:Math.abs(C.y-h.y).toFixed(2)})}),W.jsxs("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none",mixBlendMode:"difference",zIndex:kc.dimensionOverlay},width:y.width,height:y.height,children:[W.jsx("defs",{children:W.jsx("marker",{id:"head",orient:"auto",markerWidth:"3",markerHeight:"4",refX:"2",refY:"2",children:W.jsx("path",{d:"M0,0 V4 L2,2 Z",fill:"red"})})}),W.jsx("line",{x1:N.x,y1:N.y,x2:F.x,y2:F.y,markerEnd:"url(#head)",strokeWidth:1.5,fill:"none",stroke:"red"}),W.jsx("line",{x1:N.x,y1:N.y,x2:F.x,y2:N.y,strokeWidth:1.5,fill:"none",strokeDasharray:"2,2",stroke:"red"}),W.jsx("line",{x1:F.x,y1:N.y,x2:F.x,y2:F.y,strokeWidth:1.5,fill:"none",strokeDasharray:"2,2",stroke:"red"})]}),s&&_.map(J=>{const O=J.id===c.start||J.id===c.end,Z=UM/2;return W.jsxs("svg",{width:UM,height:UM,style:{position:"absolute",left:J.screenPoint.x-Z,top:J.screenPoint.y-Z,pointerEvents:"none",zIndex:kc.dimensionOverlay},children:[W.jsx("line",{x1:0,y1:0,x2:UM,y2:UM,stroke:O?"#66ccff":"white",strokeWidth:1}),W.jsx("line",{x1:UM,y1:0,x2:0,y2:UM,stroke:O?"#66ccff":"white",strokeWidth:1})]},J.id)}),W.jsxs("div",{style:{right:0,bottom:0,position:"absolute",color:"red",fontFamily:"sans-serif",fontSize:12,margin:4},children:["(",C.x.toFixed(2),",",C.y.toFixed(2),")",W.jsx("br",{}),"(",h.x.toFixed(2),",",h.y.toFixed(2),")",W.jsx("br",{}),"dist:"," ",Math.sqrt((h.x-C.x)**2+(h.y-C.y)**2).toFixed(2)]})]})]})},uti=(t,A,e=0)=>{const i=t.width/2,n=t.height/2,o=t.center.x-i-e,s=t.center.x+i+e,r=t.center.y-n-e,a=t.center.y+n+e;return A.x>o&&A.x<s&&A.y>r&&A.y<a},dti=({children:t,disabled:A,transform:e,soup:i,cancelPanDrag:n,onCreateEditEvent:o,onModifyEditEvent:s})=>{e||(e=xa());const r=V.useRef(null),[a,g]=V.useState(null),[c,I]=V.useState(null),l=a!==null;gl(h=>h.in_edit_mode);const B=gl(h=>h.in_move_footprint_mode),C=gl(h=>h.setIsMovingComponent),Q=A||!B;return W.jsxs("div",{ref:r,style:{position:"relative",overflow:"hidden"},onMouseDown:h=>{if(Q)return;const E=h.currentTarget.getBoundingClientRect(),u=h.clientX-E.left,d=h.clientY-E.top;if(Number.isNaN(u)||Number.isNaN(d))return;const f=Ce(tm(e),{x:u,y:d});let y=!1;for(const w of i)if(w.type==="pcb_component"&&uti(w,f,10/e.a)){n(),g(w.pcb_component_id),y=!0;const D=Math.random().toString();I({dragStart:f,originalCenter:w.center,dragEnd:f,edit_event_id:D}),o({edit_event_id:D,edit_event_type:"edit_pcb_component_location",pcb_edit_event_type:"edit_component_location",pcb_component_id:w.pcb_component_id,original_center:w.center,new_center:w.center,in_progress:!0,created_at:Date.now()}),C(!0);break}if(y||g(null),y)return h.preventDefault(),!1},onMouseMove:h=>{if(!a||!c)return;const E=h.currentTarget.getBoundingClientRect(),u=h.clientX-E.left,d=h.clientY-E.top;if(Number.isNaN(u)||Number.isNaN(d))return;const f=Ce(tm(e),{x:u,y:d});I({...c,dragEnd:f}),s({edit_event_id:c.edit_event_id,new_center:{x:c.originalCenter.x+f.x-c.dragStart.x,y:c.originalCenter.y+f.y-c.dragStart.y}})},onMouseUp:h=>{a&&(g(null),C(!1),c&&(s({edit_event_id:c.edit_event_id,in_progress:!1}),I(null)))},children:[t,!Q&&i.filter(h=>h.type==="pcb_component").map(h=>{if(!h?.center)return null;const E=Ce(e,h.center);return W.jsx("div",{style:{position:"absolute",pointerEvents:"none",left:E.x,top:E.y,width:h.width*e.a+20,height:h.height*e.a+20,transform:"translate(-50%, -50%)",background:l&&a===h.pcb_component_id?"rgba(255, 0, 0, 0.2)":""}},h.pcb_component_id)})]})},pti=({hotkeys:t})=>(V.useEffect(()=>{const A=e=>{t.forEach(i=>{e.key===i.key&&i.onUse()})};return window.addEventListener("keydown",A),()=>{window.removeEventListener("keydown",A)}},[t]),W.jsx("div",{className:D2`
|
|
5437
5437
|
display: flex;
|
|
5438
5438
|
flex-direction: column;
|
|
5439
5439
|
font-family: sans-serif;
|
|
@@ -5472,7 +5472,7 @@ $1`).replace(/>(\s*)(?=<!--\s*\/)/g,"> ")}}});function Nhe(t,A,e){if(!A||!e)retu
|
|
|
5472
5472
|
transition: opacity 0.2s;
|
|
5473
5473
|
margin-bottom: 10px;
|
|
5474
5474
|
color: red;
|
|
5475
|
-
`,Sti=({children:t,transform:A=xa(),elements:e})=>{const i=V.useRef(null),{isShowingDRCErrors:n,hoveredErrorId:o}=gl(g=>({isShowingDRCErrors:g.is_showing_drc_errors,hoveredErrorId:g.hovered_error_id}));if(!e)return W.jsx("div",{style:{position:"relative"},ref:i,children:t});const s=e.filter(g=>g.type==="pcb_trace_error"),r=e.filter(g=>g.type==="pcb_trace_error"&&g.message?.includes("Multiple components found with name")),a=new Map;return e.forEach(g=>{g.type==="pcb_port"&&a.set(g.pcb_port_id,g)}),W.jsxs("div",{style:{position:"relative"},ref:i,children:[t,s.map((g,c)=>{const{pcb_port_ids:I,pcb_trace_id:l}=g,B=I?.[0]?a.get(I[0]):void 0,C=I?.[1]?a.get(I[1]):void 0,Q=e?rx(e).pcb_trace.get(l):void 0,h=g.pcb_trace_error_id||`error_${c}_${g.error_type}_${g.message?.slice(0,20)}`,E=o===h;if(B&&C){const u=Ce(A,{x:B.x,y:B.y}),d=Ce(A,{x:C.x,y:C.y});if(!n)return null;const f=!(isNaN(u.x)||isNaN(u.y)||isNaN(d.x)||isNaN(d.y)),y={x:(u.x+d.x)/2,y:(u.y+d.y)/2};if(isNaN(y.x)||isNaN(y.y))return null;const w=ymA(y,i);return W.jsxs(V.Fragment,{children:[W.jsx(wti,{screenPort1:u,screenPort2:d,errorCenter:y,canLineBeDrawn:f,isHighlighted:E}),W.jsx("div",{style:{position:"absolute",left:y.x-15,top:y.y-15,width:30,height:30,zIndex:kc.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:D=>{const S=D.currentTarget.nextElementSibling;if(S){const _=S.querySelector(".error-message");_&&(_.style.opacity="1")}},onMouseLeave:D=>{if(!E){const S=D.currentTarget.nextElementSibling;if(S){const _=S.querySelector(".error-message");_&&(_.style.opacity="0")}}}}),W.jsx("div",{style:{position:"absolute",zIndex:E?200:100,left:w.left,top:w.top,color:E?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:n||E?"flex":"none",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:w.transform},children:W.jsx("div",{className:`error-message ${mmA}`,style:{opacity:E?1:0,border:`1px solid ${E?"#ff4444":"red"}`},children:g.message})})]},h)}if(Q?.route&&(n||E)){const u=Q.route.map(w=>Ce(A,{x:w.x,y:w.y}));if(u.some(w=>isNaN(w.x)||isNaN(w.y)))return null;const d=Math.floor(u.length/2),f=u[d],y=ymA(f,i);return W.jsxs(V.Fragment,{children:[W.jsx(Dti,{points:u,errorCenter:f,isHighlighted:E}),W.jsx("div",{style:{position:"absolute",left:f.x-15,top:f.y-15,width:30,height:30,zIndex:kc.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:w=>{const D=w.currentTarget.nextElementSibling;if(D){const S=D.querySelector(".error-message");S&&(S.style.opacity="1")}},onMouseLeave:w=>{if(!E){const D=w.currentTarget.nextElementSibling;if(D){const S=D.querySelector(".error-message");S&&(S.style.opacity="0")}}}}),W.jsx("div",{style:{position:"absolute",zIndex:E?kc.errorOverlay+10:kc.errorOverlay+1,left:y.left,top:y.top,color:E?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:"flex",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:y.transform},children:W.jsx("div",{className:`error-message ${mmA}`,style:{opacity:E?1:0,border:`1px solid ${E?"#ff4444":"red"}`},children:g.message})})]},h)}return null}),r.map((g,c)=>{const I=g.component_name||g.message?.match(/name "([^"]+)"/)?.[1];if(!I)return null;const l=e?.filter(Q=>Q.type==="source_component"&&Q.name===I||Q.type==="pcb_component"&&e?.find(h=>h.type==="source_component"&&h.source_component_id===Q.source_component_id&&h.name===I))||[],B=g.pcb_trace_error_id||`error_${c}_${g.error_type}_${g.message?.slice(0,20)}`,C=o===B;return!C&&!n?null:l.map((Q,h)=>{let E={x:0,y:0};if(Q.type==="pcb_component")E=Q.center||{x:0,y:0};else if(Q.type==="source_component"){const _=e?.find(b=>b.type==="pcb_component"&&b.source_component_id===Q.source_component_id);_&&_.type==="pcb_component"&&(E=_.center||{x:0,y:0})}const u=Ce(A,E);if(isNaN(u.x)||isNaN(u.y))return null;const d=Math.abs(A.a),D=Math.max(8,Math.min(30,.5*d)),S=ymA(u,i);return W.jsxs(V.Fragment,{children:[W.jsx("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none",mixBlendMode:"difference",zIndex:kc.errorOverlay},width:"100%",height:"100%",children:C?W.jsx("polygon",{points:`${u.x},${u.y-D*1.25} ${u.x+D},${u.y} ${u.x},${u.y+D*1.25} ${u.x-D},${u.y}`,fill:"#ff4444"}):W.jsx("circle",{cx:u.x,cy:u.y,r:D,fill:"none",stroke:C?"#ff4444":"red",strokeWidth:C?Math.max(2,D*.15):Math.max(1,D*.1),opacity:1})}),W.jsx("div",{style:{position:"absolute",left:u.x-(D+10),top:u.y-(D+10),width:(D+10)*2,height:(D+10)*2,zIndex:kc.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:_=>{const b=_.currentTarget.nextElementSibling;if(b){const N=b.querySelector(".error-message");N&&(N.style.opacity="1")}},onMouseLeave:_=>{if(!C){const b=_.currentTarget.nextElementSibling;if(b){const N=b.querySelector(".error-message");N&&(N.style.opacity="0")}}}}),W.jsx("div",{style:{position:"absolute",zIndex:C?kc.errorOverlay+20:kc.errorOverlay+10,left:S.left,top:S.top,color:C?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:n||C?"flex":"none",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:S.transform},children:W.jsx("div",{className:`error-message ${mmA}`,style:{opacity:C?1:0,border:`1px solid ${C?"#ff4444":"red"}`},children:g.message})})]},`${B}_${h}`)})})]})};function bti(t,A){return t.size!==A.size?!1:Array.from(t).every(e=>A.has(e))}function xti({primitiveElement:t,elements:A}){let e=t.trace_length?`${t.trace_length.toFixed(3)}`:"";const i=rx(A).source_trace.get(t?.source_trace_id);if(i?.display_name&&(i?.max_length?e+=` / ${i.max_length}mm `:e+=" mm ",e+=`(${i.display_name})`),!e)return null;const n=t.trace_length&&i?.max_length&&t.trace_length>i.max_length;return{text:e,isOverLength:n}}function _ti(t){const{primitives:A,is_showing_multiple_traces_length:e,elements:i}=t,n=A.filter(a=>a._element.type==="pcb_trace"),o=i.filter(a=>a.type==="source_trace"),s=A.filter(a=>a._element.type!=="pcb_trace"),r=n.filter(a=>o.some(g=>a._element.type==="pcb_trace"&&a._element.source_trace_id===g.source_trace_id&&g.max_length!==void 0));if(!e)return[...s,...r];if(n.length>1){const a=n.reduce((g,c)=>{const I=g._element.trace_length;return c._element.trace_length<I?c:g},n[0]);return[...s,a]}return A}var kti={position:"absolute",left:0,top:0,pointerEvents:"none",color:"red",fontFamily:"sans-serif",fontSize:12,textShadow:"0 0 2px black"},vti=t=>{const{_element:A,_parent_pcb_component:e,_parent_source_component:i,_source_port:n}=t;switch(A.type){case"pcb_trace":return A.trace_length?`${A.trace_length.toFixed(3)}`:"";case"pcb_smtpad":case"pcb_plated_hole":{const o=[],s=Array.from(new Set((A.port_hints??[]).concat(n?.port_hints??[]))).filter(a=>!/^[0-9]+$/.test(a)).filter(a=>!a.includes("unnamed_")).sort((a,g)=>g.localeCompare(a)),r=i&&"name"in i&&i.name&&!i.name.includes("unnamed_")?i.name:null;return s.length>0?r?o.push(...s.map(a=>`${r}.${a}`)):o.push(...s):r&&o.push(r),o.join(", ")}default:return""}},Fti={top:"red",bottom:"aqua"},Mti=({primitive:t,mousePos:A,elements:e})=>{const[i,n]=V.useState(!1),o=t._element;V.useEffect(()=>{setTimeout(()=>{n(!0)},100)},[]);const[s,r,a,g]=[t.screen_x,t.screen_y,t.screen_w,t.screen_h],c=t.same_space_index??0,I=26,l=Fti[t?._element?.layer]??"red";let B=0;if(o.type==="pcb_smtpad"&&o?.shape==="rotated_rect"?B=o?.ccw_rotation??0:(o.type==="pcb_smtpad"&&(o?.shape==="pill"||o?.shape==="rotated_pill")&&"ccw_rotation"in t||o.type==="pcb_plated_hole"&&(o?.shape==="pill"||o?.shape==="oval")&&"ccw_rotation"in t)&&(B=o.ccw_rotation??0),o.type==="pcb_trace"){const h=xti({primitiveElement:o,elements:e});if(!h)return null;const E=A.y-35;return W.jsx("div",{style:{zIndex:kc.elementOverlay,position:"absolute",left:A.x,top:E,color:l,pointerEvents:"none",transform:"translateX(-50%)"},children:W.jsx("div",{style:{backgroundColor:"#f2efcc",color:h.isOverLength?"red":"black",textShadow:"none",WebkitFontSmoothing:"antialiased",MozOsxFontSmoothing:"grayscale",padding:"6px 6px",borderRadius:"6px",fontSize:"14px",minWidth:"45px",textAlign:"center",whiteSpace:"nowrap"},children:h.text})})}const C=vti(t);return C.trim().length===0?null:W.jsx("div",{style:{zIndex:kc.elementOverlay,position:"absolute",left:s-a/2-8,top:r-g/2-8,width:a+16,height:g+16,color:l,transform:`rotate(${-B}deg)`,transformOrigin:"center center"},children:W.jsx("div",{style:{width:i?`calc(100% + ${I*2*c}px)`:"100%",height:i?`calc(100% + ${I*2*c}px)`:"100%",marginLeft:i?`${-I*c}px`:0,marginTop:i?`${-I*c}px`:0,border:`1px solid ${l}`,opacity:i||c===0?1:0,transition:"width 0.2s, height 0.2s, margin-left 0.2s, margin-top 0.2s, opacity 0.2s"},children:W.jsx("div",{style:{position:"absolute",bottom:g+20+I*c,marginRight:i?`${-I*c}px`:0,marginBottom:i?0:-I*c,transition:"margin-right 0.2s, margin-bottom 0.2s",backgroundColor:"#f2efcc",color:"black",textShadow:"none",WebkitFontSmoothing:"antialiased",MozOsxFontSmoothing:"grayscale",padding:"6px 6px",borderRadius:"6px",fontSize:"14px",transform:`rotate(${B}deg)`,minWidth:"45px",textAlign:"center"},children:C})})})},Rti=({highlightedPrimitives:t,mousePos:A,elements:e})=>{const[i,n]=gl(r=>[r.is_moving_component,r.is_showing_multiple_traces_length]),o=t.some(r=>r._element.type==="pcb_smtpad")&&t.some(r=>r._element.type==="pcb_trace");let s=t;return o&&(s=s.filter(r=>r._element.type==="pcb_smtpad")),s=_ti({primitives:s,is_showing_multiple_traces_length:n,elements:e}),W.jsx("div",{style:kti,children:!i&&s.map((r,a)=>W.jsx(Mti,{primitive:r,mousePos:A,elements:e},a))})},Tk=t=>t?.type==="pcb_component",cEe=t=>t?.type==="pcb_group",Nti=t=>t?.type==="pcb_panel",wmA=t=>t?.type==="pcb_board",aI={MIN_LINE_LENGTH_FOR_LABEL:40,LABEL_OFFSET_ABOVE:2,LABEL_OFFSET_BELOW:-18,LABEL_OFFSET_RIGHT:8,LABEL_OFFSET_LEFT:-120,Y_LABEL_MIN_WIDTH:110,LINE_STROKE_WIDTH:1.5,LINE_DASH_PATTERN:"4,4",COMPONENT_MARKER_RADIUS:3,LABEL_FONT_SIZE:11,ANCHOR_MARKER_SIZE:6,ANCHOR_MARKER_STROKE_WIDTH:1.5},ly={OFFSET_LINE:"white",COMPONENT_MARKER_FILL:"#66ccff",COMPONENT_MARKER_STROKE:"white",LABEL_TEXT:"white"},DmA=({targets:t,transform:A,containerWidth:e,containerHeight:i})=>{if(t.length===0)return null;const n={color:ly.LABEL_TEXT,mixBlendMode:"difference",pointerEvents:"none",fontSize:aI.LABEL_FONT_SIZE,fontFamily:"monospace",fontWeight:"bold"},o=new Map;return t.forEach(s=>{if(!o.has(s.anchor_id)){const r=Ce(A,s.anchor);o.set(s.anchor_id,r)}}),W.jsx("div",{style:{position:"absolute",left:0,top:0,width:e,height:i,overflow:"hidden",pointerEvents:"none",zIndex:kc.dimensionOverlay},children:W.jsxs("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none"},width:e,height:i,children:[t.map(s=>{const r=s.anchor,a=s.anchor_id,g=s.target,c=o.get(a),I=Ce(A,g),l=g.x-r.x,B=g.y-r.y,C=Math.abs(I.x-c.x),Q=Math.abs(I.y-c.y),h=I.y<c.y,E=I.x>c.x,u=h?aI.LABEL_OFFSET_ABOVE:aI.LABEL_OFFSET_BELOW,d=E?aI.LABEL_OFFSET_RIGHT:aI.LABEL_OFFSET_LEFT,f=C>aI.MIN_LINE_LENGTH_FOR_LABEL,y=Q>aI.MIN_LINE_LENGTH_FOR_LABEL,w=`${s.display_offset_x??l.toFixed(2)}mm`,D=`${s.display_offset_y??B.toFixed(2)}mm`;return W.jsxs("g",{children:[W.jsx("line",{x1:c.x,y1:c.y,x2:I.x,y2:c.y,stroke:ly.OFFSET_LINE,strokeWidth:aI.LINE_STROKE_WIDTH,strokeDasharray:aI.LINE_DASH_PATTERN}),W.jsx("line",{x1:I.x,y1:c.y,x2:I.x,y2:I.y,stroke:ly.OFFSET_LINE,strokeWidth:aI.LINE_STROKE_WIDTH,strokeDasharray:aI.LINE_DASH_PATTERN}),s.type==="component"||s.type==="board"?W.jsx("circle",{cx:I.x,cy:I.y,r:aI.COMPONENT_MARKER_RADIUS,fill:ly.COMPONENT_MARKER_FILL,stroke:ly.COMPONENT_MARKER_STROKE,strokeWidth:1}):W.jsxs(W.Fragment,{children:[W.jsx("line",{x1:I.x-aI.ANCHOR_MARKER_SIZE,y1:I.y,x2:I.x+aI.ANCHOR_MARKER_SIZE,y2:I.y,stroke:ly.OFFSET_LINE,strokeWidth:aI.ANCHOR_MARKER_STROKE_WIDTH}),W.jsx("line",{x1:I.x,y1:I.y-aI.ANCHOR_MARKER_SIZE,x2:I.x,y2:I.y+aI.ANCHOR_MARKER_SIZE,stroke:ly.OFFSET_LINE,strokeWidth:aI.ANCHOR_MARKER_STROKE_WIDTH})]}),f&&W.jsx("foreignObject",{x:Math.min(c.x,I.x),y:c.y+u,width:Math.abs(I.x-c.x),height:20,style:{overflow:"visible"},children:W.jsx("div",{style:{...n,textAlign:"center"},children:w})}),y&&W.jsx("foreignObject",{x:I.x+d,y:Math.min(c.y,I.y),width:aI.Y_LABEL_MIN_WIDTH,height:Math.abs(I.y-c.y),style:{overflow:"visible"},children:W.jsx("div",{style:{...n,display:"flex",alignItems:"center",justifyContent:E?"flex-start":"flex-end",whiteSpace:"nowrap",padding:"0 4px",height:"100%"},children:D})})]},s.id)}),Array.from(o.entries()).map(([s,r])=>W.jsxs("g",{children:[W.jsx("line",{x1:r.x-aI.ANCHOR_MARKER_SIZE,y1:r.y,x2:r.x+aI.ANCHOR_MARKER_SIZE,y2:r.y,stroke:ly.OFFSET_LINE,strokeWidth:aI.ANCHOR_MARKER_STROKE_WIDTH}),W.jsx("line",{x1:r.x,y1:r.y-aI.ANCHOR_MARKER_SIZE,x2:r.x,y2:r.y+aI.ANCHOR_MARKER_SIZE,stroke:ly.OFFSET_LINE,strokeWidth:aI.ANCHOR_MARKER_STROKE_WIDTH})]},`anchor-${s}`))]})})},Gti=({elements:t,highlightedPrimitives:A,transform:e,containerWidth:i,containerHeight:n})=>{const o=t.filter(E=>wmA(E)),s=t.filter(E=>Tk(E)),r=t.filter(E=>cEe(E)),a=A.map(E=>Tk(E._parent_pcb_component)?E._parent_pcb_component.pcb_component_id:Tk(E._element)?E._element.pcb_component_id:null).filter(E=>!!E),g=new Set;if(a.forEach(E=>{const u=s.find(d=>d.pcb_component_id===E);u?.pcb_group_id&&g.add(u.pcb_group_id)}),!gl(E=>E.is_showing_group_anchor_offsets)&&a.length===0)return null;const I=s.map(E=>{const u=E.positioned_relative_to_pcb_board_id;if(!u)return null;const d=o.find(f=>f.pcb_board_id===u);return d?{component:E,board:d,type:"component"}:null}).filter(E=>!!E),l=r.map(E=>{const u=E.positioned_relative_to_pcb_board_id;if(!u||!E.center)return null;const d=o.find(f=>f.pcb_board_id===u);return d?{group:E,board:d,type:"group"}:null}).filter(E=>!!E),B=[...I,...l];if(B.length===0)return null;const C=a.length===0,Q=B.filter(E=>E.type==="component"?C||a.includes(E.component.pcb_component_id):C||g.has(E.group.pcb_group_id));if(Q.length===0)return null;const h=Q.map(E=>E.type==="component"?{id:`${E.board.pcb_board_id}-${E.component.pcb_component_id}-${E.type}`,anchor:E.board.center,anchor_id:E.board.pcb_board_id,target:E.component.center,type:"component",display_offset_x:E.component.display_offset_x,display_offset_y:E.component.display_offset_y}:{id:`${E.board.pcb_board_id}-${E.group.pcb_group_id}-${E.type}`,anchor:E.board.center,anchor_id:E.board.pcb_board_id,target:{x:E.group.anchor_position?.x??E.group.center.x,y:E.group.anchor_position?.y??E.group.center.y},type:"group",display_offset_x:E.group.display_offset_x,display_offset_y:E.group.display_offset_y}).filter(E=>!!E);return W.jsx(DmA,{targets:h,transform:e,containerWidth:i,containerHeight:n})},Lti=({elements:t,highlightedPrimitives:A,transform:e,containerWidth:i,containerHeight:n})=>{const o=t.filter(E=>cEe(E)),s=t.filter(E=>Tk(E)),r=A.map(E=>Tk(E._parent_pcb_component)?E._parent_pcb_component.pcb_component_id:Tk(E._element)?E._element.pcb_component_id:null).filter(E=>!!E),a=(E,u)=>{if(u.has(E))return;u.add(E);const d=o.find(f=>f.pcb_group_id===E);d?.position_mode==="relative_to_group_anchor"&&d.positioned_relative_to_pcb_group_id&&a(d.positioned_relative_to_pcb_group_id,u)},g=new Set;if(r.forEach(E=>{const u=s.find(d=>d.pcb_component_id===E);u&&(u.position_mode==="relative_to_group_anchor"&&u.positioned_relative_to_pcb_group_id&&a(u.positioned_relative_to_pcb_group_id,g),u.pcb_group_id&&a(u.pcb_group_id,g))}),!gl(E=>E.is_showing_group_anchor_offsets)&&r.length===0)return null;const I=s.map(E=>{if(E.position_mode==="relative_to_group_anchor"&&E.positioned_relative_to_pcb_group_id){const u=o.find(d=>d.pcb_group_id===E.positioned_relative_to_pcb_group_id);return u&&u.anchor_position?{component:E,parentGroup:u,type:"component"}:null}if(E.pcb_group_id){const u=o.find(d=>d.pcb_group_id===E.pcb_group_id);return u&&u.anchor_position?{component:E,parentGroup:u,type:"component"}:null}return null}).filter(E=>!!E),l=o.map(E=>{if(E.position_mode==="relative_to_group_anchor"&&E.positioned_relative_to_pcb_group_id){const u=o.find(d=>d.pcb_group_id===E.positioned_relative_to_pcb_group_id);if(u&&u.anchor_position&&E.anchor_position)return{group:E,parentGroup:u,type:"group"}}return null}).filter(E=>!!E),B=[...I,...l];if(B.length===0)return null;const C=r.length===0,Q=B.filter(E=>E.type==="component"?C||r.includes(E.component.pcb_component_id):C||g.has(E.group.pcb_group_id)||g.has(E.parentGroup.pcb_group_id));if(Q.length===0)return null;const h=Q.map(E=>{const u=E.parentGroup.anchor_position;return u?E.type==="component"?E.component.center?{id:`${E.parentGroup.pcb_group_id}-${E.component.pcb_component_id}-${E.type}`,anchor:u,anchor_id:E.parentGroup.pcb_group_id,target:E.component.center,type:"component",display_offset_x:E.component.display_offset_x,display_offset_y:E.component.display_offset_y}:null:E.group.anchor_position?{id:`${E.parentGroup.pcb_group_id}-${E.group.pcb_group_id}-${E.type}`,anchor:u,anchor_id:E.parentGroup.pcb_group_id,target:E.group.anchor_position,type:"group",display_offset_x:E.group.display_offset_x,display_offset_y:E.group.display_offset_y}:null:null}).filter(E=>!!E);return W.jsx(DmA,{targets:h,transform:e,containerWidth:i,containerHeight:n})},Uti=(t,A)=>{const e=t.pcb_component_id,i=A.filter(n=>(n.type==="pcb_smtpad"||n.type==="pcb_plated_hole")&&n.pcb_component_id===e||n.type==="pcb_hole"&&n.pcb_component_id===e);return i.length===0?pmA([t]):pmA(i)},Hti=({elements:t,highlightedPrimitives:A,transform:e,containerWidth:i,containerHeight:n})=>{const o=new Map;for(const r of A)Tk(r._parent_pcb_component)&&o.set(r._parent_pcb_component.pcb_component_id,r._parent_pcb_component),Tk(r._element)&&o.set(r._element.pcb_component_id,r._element);if(o.size===0)return null;const s=[];for(const r of o.values()){const a=Uti(r,t);if(!a)continue;const g=r.positioned_relative_to_pcb_group_id??r.pcb_group_id,c=g?rx(t).pcb_group.get(g):null;s.push({component:r,bbox:a,group:c})}return s.length===0?null:W.jsx("div",{style:{position:"absolute",left:0,top:0,width:i,height:n,overflow:"hidden",pointerEvents:"none",zIndex:kc.dimensionOverlay},children:W.jsx("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none"},width:i,height:n,children:s.map(({component:r,bbox:a,group:g})=>{const c=Ce(e,{x:a.minX,y:a.maxY}),I=Ce(e,{x:a.maxX,y:a.minY}),l={x:Math.min(c.x,I.x),y:Math.min(c.y,I.y),width:Math.abs(I.x-c.x),height:Math.abs(I.y-c.y)},B=r.center??{x:(a.minX+a.maxX)/2,y:(a.minY+a.maxY)/2},C=Ce(e,B);return W.jsxs("g",{children:[W.jsx("rect",{x:l.x,y:l.y,width:l.width,height:l.height,fill:"none",stroke:"white",strokeWidth:1.5,strokeDasharray:"4,4"}),W.jsx("line",{x1:C.x-6,y1:C.y,x2:C.x+6,y2:C.y,stroke:ly.COMPONENT_MARKER_STROKE,strokeWidth:1.5}),W.jsx("line",{x1:C.x,y1:C.y-6,x2:C.x,y2:C.y+6,stroke:ly.COMPONENT_MARKER_STROKE,strokeWidth:1.5}),W.jsx("circle",{cx:C.x,cy:C.y,r:aI.COMPONENT_MARKER_RADIUS,fill:ly.COMPONENT_MARKER_FILL,stroke:ly.COMPONENT_MARKER_STROKE,strokeWidth:1})]},r.pcb_component_id)})})})},Yti=({elements:t,highlightedPrimitives:A,transform:e,containerWidth:i,containerHeight:n})=>{const o=t.filter(B=>Nti(B)),s=t.filter(B=>wmA(B)),r=A.map(B=>wmA(B._element)?B._element.pcb_board_id:null).filter(B=>!!B);if(!gl(B=>B.is_showing_group_anchor_offsets)&&r.length===0)return null;const g=s.map(B=>{const C=B.pcb_panel_id,Q=B.position_mode;if(!C||Q!=="relative_to_panel_anchor")return null;const h=o.find(E=>E.pcb_panel_id===C);return h?{board:B,panel:h,type:"board"}:null}).filter(B=>!!B);if(g.length===0)return null;const c=r.length===0,I=g.filter(B=>c||r.includes(B.board.pcb_board_id));if(I.length===0)return null;const l=I.map(B=>B.board.center?{id:`${B.panel.pcb_panel_id}-${B.board.pcb_board_id}-${B.type}`,anchor:B.panel.center,anchor_id:B.panel.pcb_panel_id,target:B.board.center,type:"board",display_offset_x:B.board.display_offset_x,display_offset_y:B.board.display_offset_y}:null).filter(B=>!!B);return W.jsx(DmA,{targets:l,transform:e,containerWidth:i,containerHeight:n})},Nz=t=>{if(t.length===0)return null;let A=t[0].x,e=t[0].y,i=t[0].x,n=t[0].y;for(const o of t)o.x<A&&(A=o.x),o.y<e&&(e=o.y),o.x>i&&(i=o.x),o.y>n&&(n=o.y);return{center:{x:(A+i)/2,y:(e+n)/2},width:i-A,height:n-e}},IEe=(t,A)=>{if(A.length<3)return!1;let e=!1;for(let i=0,n=A.length-1;i<A.length;n=i++){const o=A[i].x,s=A[i].y,r=A[n].x,a=A[n].y;s>t.y!=a>t.y&&t.x<(r-o)*(t.y-s)/(a-s||Number.EPSILON)+o&&(e=!e)}return e},Jti=(t,A,e)=>{const i=[];for(const n of t){if(!n._element)continue;if("x1"in n&&n._element?.type==="pcb_trace"){const r=HE({x:A.x,y:A.y},{x:n.x1,y:n.y1},{x:n.x2,y:n.y2}),a=n.width||.5,g=Math.max(a*25,2)/e.a;r<g&&i.push(n);continue}if(n.pcb_drawing_type==="polygon"){const r=n.points.map(g=>({x:Et.parse(g.x),y:Et.parse(g.y)})),a=Nz(r);if(!a||A.x<a.center.x-a.width/2||A.x>a.center.x+a.width/2||A.y<a.center.y-a.height/2||A.y>a.center.y+a.height/2)continue;IEe(A,r)&&i.push(n);continue}if(n.pcb_drawing_type==="polygon_with_arcs"){const r=n.brep_shape.outer_ring.vertices.map(g=>({x:Et.parse(g.x),y:Et.parse(g.y)})),a=Nz(r);if(!a||A.x<a.center.x-a.width/2||A.x>a.center.x+a.width/2||A.y<a.center.y-a.height/2||A.y>a.center.y+a.height/2)continue;IEe(A,r)&&i.push(n);continue}if(!("x"in n&&"y"in n))continue;let o=0,s=0;if("w"in n&&"h"in n)o=n.w,s=n.h;else if("r"in n)o=n.r*2,s=n.r*2;else if("rX"in n&&"rY"in n)o=n.rX*2,s=n.rY*2;else continue;Math.abs(n.x-A.x)<o/2&&Math.abs(n.y-A.y)<s/2&&i.push(n)}return i},Tti=({elements:t,children:A,transform:e,primitives:i,onMouseHoverOverPrimitives:n})=>{const[o,s]=V.useState([]),[r,a]=V.useState({x:0,y:0}),[g,{width:c,height:I}]=qT(),l=V.useMemo(()=>{const C=[];for(const Q of o){if(Q._element?.type==="pcb_via"||Q._element?.type==="pcb_component"||Q?.layer==="drill")continue;let h=null,E=0,u=0;if(Q.pcb_drawing_type==="polygon"){const w=Nz(Q.points);if(!w)continue;h=w.center,E=w.width,u=w.height}else if(Q.pcb_drawing_type==="polygon_with_arcs"){const w=Q.brep_shape.outer_ring.vertices.map(S=>({x:S.x,y:S.y})),D=Nz(w);if(!D)continue;h=D.center,E=D.width,u=D.height}else"x"in Q&&"y"in Q&&(h={x:Q.x,y:Q.y},E="w"in Q?Q.w:"r"in Q?Q.r*2:"rX"in Q&&"rY"in Q?Q.rX*2:0,u="h"in Q?Q.h:"r"in Q?Q.r*2:"rX"in Q&&"rY"in Q?Q.rY*2:0);if(!h)continue;const d=Ce(e,h),f={w:E*e.a,h:u*e.a},y=C.filter(w=>d.x===w.screen_x&&d.y===w.screen_y&&f.w===w.screen_w&&f.h===w.screen_h).length;C.push({...Q,x:h.x,y:h.y,w:E,h:u,screen_x:d.x,screen_y:d.y,screen_w:f.w,screen_h:f.h,same_space_index:y})}return C},[o,e]),B=(C,Q,h,E)=>{a({x:C,y:Q});const u=Ce(tm(h),{x:C,y:Q}),d=Jti(E,u,h);bti(new Set(d.map(f=>f._pcb_drawing_object_id)),new Set(o.map(f=>f._pcb_drawing_object_id)))||(s(d),n(d))};return W.jsxs("div",{ref:g,style:{position:"relative",width:"100%",height:"100%"},onMouseMove:C=>{if(e){const Q=C.currentTarget.getBoundingClientRect(),h=C.clientX-Q.left,E=C.clientY-Q.top;B(h,E,e,i)}},onTouchStart:C=>{if(e){const Q=C.touches[0],h=C.currentTarget.getBoundingClientRect(),E=Q.clientX-h.left,u=Q.clientY-h.top;B(E,u,e,i)}},children:[A,W.jsx(Rti,{elements:t,mousePos:r,highlightedPrimitives:l}),e&&W.jsxs(W.Fragment,{children:[W.jsx(Gti,{elements:t,highlightedPrimitives:l,transform:e,containerWidth:c,containerHeight:I}),W.jsx(Lti,{elements:t,highlightedPrimitives:l,transform:e,containerWidth:c,containerHeight:I}),W.jsx(Hti,{elements:t,highlightedPrimitives:l,transform:e,containerWidth:c,containerHeight:I}),W.jsx(Yti,{elements:t,highlightedPrimitives:l,transform:e,containerWidth:c,containerHeight:I})]})]})},lEe=["rgb(255, 100, 100)","rgb(100, 255, 100)","rgb(100, 100, 255)","rgb(255, 255, 100)","rgb(255, 100, 255)","rgb(100, 255, 255)","rgb(255, 150, 100)","rgb(150, 100, 255)","rgb(100, 255, 150)","rgb(255, 100, 150)"],Pti=({children:t,transform:A=xa(),elements:e=[],hoveredComponentIds:i=[]})=>{const[n,{width:o,height:s}]=qT(),r=V.useRef(null),{is_showing_pcb_groups:a,pcb_group_view_mode:g,is_showing_group_anchor_offsets:c}=gl(I=>({is_showing_pcb_groups:I.is_showing_pcb_groups,pcb_group_view_mode:I.pcb_group_view_mode,is_showing_group_anchor_offsets:I.is_showing_group_anchor_offsets}));return V.useEffect(()=>{const I=r.current;if(!I||!o||!s)return;I.width=o,I.height=s;const l=I.getContext("2d");if(!l||(l.clearRect(0,0,o,s),!a))return;const B=e.filter(w=>w.type==="pcb_group"),C=e.filter(w=>w.type==="pcb_component"),Q=e.filter(w=>w.type==="source_group"),h=new Map(Q.map(w=>[w.source_group_id,w])),E=B.filter(w=>{if(w.name?.toLowerCase().includes("subpanel"))return!1;if(g==="all")return!0;if(!w.source_group_id)return!1;const D=h.get(w.source_group_id);return D?D.was_automatically_named!==!0:!1}),u=new Map;Q.forEach(w=>{const D=w;if(D.parent_source_group_id){const S=u.get(D.parent_source_group_id)||[];S.push(w.source_group_id),u.set(D.parent_source_group_id,S)}});const d=w=>{const D=[],S=u.get(w)||[];for(const _ of S)D.push(_),D.push(...d(_));return D},f=w=>{const D=Q.find(S=>S.source_group_id===w);return D?.parent_source_group_id?1+f(D.parent_source_group_id):0},y=new Set;if(i.length>0)for(const w of C){if(!i.includes(w.pcb_component_id))continue;const D=w.positioned_relative_to_pcb_group_id??w.pcb_group_id;D&&y.add(D)}E.forEach((w,D)=>{let S=C.filter(JA=>JA.pcb_group_id===w.pcb_group_id);if(w.source_group_id){const JA=d(w.source_group_id),WA=B.filter(vA=>vA.source_group_id&&JA.includes(vA.source_group_id));for(const vA of WA){const wA=C.filter(RA=>RA.pcb_group_id===vA.pcb_group_id);S=[...S,...wA]}}let _,b,N,F,L=!1;if(w.center&&w.width&&w.height){L=!0;const JA=w.width/2,WA=w.height/2;_=w.center.x-JA,N=w.center.x+JA,b=w.center.y-WA,F=w.center.y+WA}else if(S.length===0||(_=1/0,b=1/0,N=-1/0,F=-1/0,S.forEach(JA=>{if(JA.center&&typeof JA.width=="number"&&typeof JA.height=="number"){const WA=JA.center.x-JA.width/2,vA=JA.center.x+JA.width/2,wA=JA.center.y+JA.height/2,RA=JA.center.y-JA.height/2;_=Math.min(_,WA),N=Math.max(N,vA),b=Math.min(b,RA),F=Math.max(F,wA)}}),_===1/0||N===-1/0))return;const Y=w.source_group_id?f(w.source_group_id):0,J=w.source_group_id?d(w.source_group_id).length>0:!1;if(!L){const vA=1+(J?.5:0);_-=vA,N+=vA,b-=vA,F+=vA}const O=Ce(A,{x:_,y:F}),Z=Ce(A,{x:N,y:F}),X=Ce(A,{x:_,y:b}),eA=Ce(A,{x:N,y:b}),gA=lEe[D%lEe.length];l.strokeStyle=gA,l.lineWidth=2;const tA=Math.max(4,Math.min(12,8*Math.abs(A.a))),iA=Math.max(2,Math.min(6,4*Math.abs(A.a))),aA=tA*(J?1.3:1),EA=iA;l.setLineDash([aA,EA]),l.beginPath(),l.moveTo(O.x,O.y),l.lineTo(Z.x,Z.y),l.lineTo(eA.x,eA.y),l.lineTo(X.x,X.y),l.closePath(),l.stroke();const bA=Math.max(8,Math.min(12,10*Math.abs(A.a))),_A=Y==0||Y==1?0:Y*.11,LA=bA*(1-_A),QA=4,kA=w.name||`Group ${D+1}`;l.font=`${LA}px sans-serif`,l.setLineDash([]);const qA=l.measureText(kA).width+QA*2,VA=LA+QA*2,ce=O.x-5,fA=O.y-5,ge=3;if(l.fillStyle="rgba(0, 0, 0, 0.8)",l.beginPath(),l.roundRect(ce,fA-VA,qA,VA,ge),l.fill(),l.fillStyle=gA,l.textAlign="left",l.textBaseline="middle",l.fillText(kA,ce+QA,fA-VA/2),c&&y.has(w.pcb_group_id)&&!!w.anchor_position&&w.anchor_position){const JA=Array.isArray(w.anchor_position)?{x:w.anchor_position[0]??0,y:w.anchor_position[1]??0}:{x:w.anchor_position.x,y:w.anchor_position.y},WA=Ce(A,JA);l.strokeStyle="white",l.lineWidth=1.5,l.setLineDash([]);const vA=Math.max(4,Math.min(8,6*Math.abs(A.a)));l.beginPath(),l.moveTo(WA.x-vA,WA.y),l.lineTo(WA.x+vA,WA.y),l.stroke(),l.beginPath(),l.moveTo(WA.x,WA.y-vA),l.lineTo(WA.x,WA.y+vA),l.stroke()}})},[e,A,o,s,a,g,c,i]),W.jsxs("div",{ref:n,style:{position:"relative",width:"100%",height:"100%"},children:[t,W.jsx("canvas",{ref:r,style:{position:"absolute",top:0,left:0,pointerEvents:"none",zIndex:kc.pcbGroupOverlay,display:a?"block":"none"}})]})},Kti=({transform:t,soup:A,children:e})=>{const i=gl(r=>r.is_showing_rats_nest),{netMap:n,idToNetMap:o}=V.useMemo(()=>Phe(A||[]),[A]),s=V.useMemo(()=>{if(!A||!i)return[];const r=l=>{const B=rx(A)[l.replace(/_\d+$/,"")].get(l);return B&&"x"in B&&"y"in B?{x:B.x,y:B.y}:null},a=(l,B)=>{const C=n[B]||[];let Q=null,h=1/0;return C.forEach(E=>{const u=r(E);if(u){const d=Math.sqrt((l.x-u.x)**2+(l.y-u.y)**2);d<h&&d>0&&(h=d,Q=u)}}),Q},g=rx(A).pcb_port.list(),c=rx(A).source_trace.list(),I=[];return g.forEach((l,B)=>{const C=o[l.pcb_port_id];let Q=!1;for(const u of c)u.connected_source_port_ids.includes(l.source_port_id)&&u.connected_source_net_ids.length>0&&(Q=!0);if(!C)return;const h={x:l.x,y:l.y},E=a(h,C);E&&I.push({key:`${l.pcb_port_id}-${B}`,startPoint:h,endPoint:E,isInNet:Q})}),I},[A,n,o,i]);return!A||!i?e:(t||(t=xa()),W.jsxs("div",{style:{position:"relative"},children:[e,W.jsx("svg",{style:{position:"absolute",left:0,top:0,width:"100%",height:"100%",pointerEvents:"none",opacity:.5,zIndex:kc.ratsNestOverlay},children:s.map(({key:r,startPoint:a,endPoint:g,isInNet:c})=>{const I=Ce(t,a),l=Ce(t,g);return W.jsx("line",{x1:I.x,y1:I.y,x2:l.x,y2:l.y,stroke:"white",strokeWidth:"1",strokeDasharray:c?"6,6":void 0},r)})})]}))},qti={version:"1.11.354"},Pk=(t,A,e)=>{const i=gl(s=>s.is_mouse_over_container),n=V.useRef(i),o=V.useRef(A);V.useEffect(()=>{n.current=i},[i]),V.useEffect(()=>{o.current=A},[A]),V.useEffect(()=>{if(!t)return;const s=r=>{const a=r.target;if(a.tagName==="INPUT"||a.tagName==="TEXTAREA"||a.isContentEditable)return;const g=t.split("+"),c=g.includes("ctrl"),I=g.includes("shift"),l=g.includes("alt"),B=g.includes("meta"),C=g[g.length-1],Q=e?.current?e.current.contains(document.activeElement)||document.activeElement===e.current:!1;(n.current||Q)&&(!c||r.ctrlKey)&&(!I||r.shiftKey)&&(!l||r.altKey)&&(!B||r.metaKey)&&r.key.toLowerCase()===C.toLowerCase()&&(r.preventDefault(),o.current())};return window.addEventListener("keydown",s),()=>{window.removeEventListener("keydown",s)}},[t])},Oti=()=>{const[t,A]=V.useState(!1);return V.useEffect(()=>{const e=()=>{A(window.innerWidth<=768)};return e(),window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[]),t},WT=(t,A={stopPropagation:!0})=>{const e=V.useRef(0),i=V.useCallback(s=>{A.stopPropagation&&s.stopPropagation();const r=Date.now();r-e.current<300||(e.current=r,t?.(s))},[t,A.stopPropagation]),n=V.useCallback(s=>{s.preventDefault(),i(s)},[i]);return{onClick:i,onTouchEnd:n,style:{touchAction:"manipulation"}}},Wti=({name:t,selected:A,onClick:e})=>{const{style:i,...n}=WT(e);return W.jsxs("div",{className:D2`
|
|
5475
|
+
`,Sti=({children:t,transform:A=xa(),elements:e})=>{const i=V.useRef(null),{isShowingDRCErrors:n,hoveredErrorId:o}=gl(g=>({isShowingDRCErrors:g.is_showing_drc_errors,hoveredErrorId:g.hovered_error_id}));if(!e)return W.jsx("div",{style:{position:"relative"},ref:i,children:t});const s=e.filter(g=>g.type==="pcb_trace_error"),r=e.filter(g=>g.type==="pcb_trace_error"&&g.message?.includes("Multiple components found with name")),a=new Map;return e.forEach(g=>{g.type==="pcb_port"&&a.set(g.pcb_port_id,g)}),W.jsxs("div",{style:{position:"relative"},ref:i,children:[t,s.map((g,c)=>{const{pcb_port_ids:I,pcb_trace_id:l}=g,B=I?.[0]?a.get(I[0]):void 0,C=I?.[1]?a.get(I[1]):void 0,Q=e?rx(e).pcb_trace.get(l):void 0,h=g.pcb_trace_error_id||`error_${c}_${g.error_type}_${g.message?.slice(0,20)}`,E=o===h;if(B&&C){const u=Ce(A,{x:B.x,y:B.y}),d=Ce(A,{x:C.x,y:C.y});if(!n)return null;const f=!(isNaN(u.x)||isNaN(u.y)||isNaN(d.x)||isNaN(d.y)),y={x:(u.x+d.x)/2,y:(u.y+d.y)/2};if(isNaN(y.x)||isNaN(y.y))return null;const w=ymA(y,i);return W.jsxs(V.Fragment,{children:[W.jsx(wti,{screenPort1:u,screenPort2:d,errorCenter:y,canLineBeDrawn:f,isHighlighted:E}),W.jsx("div",{style:{position:"absolute",left:y.x-15,top:y.y-15,width:30,height:30,zIndex:kc.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:D=>{const S=D.currentTarget.nextElementSibling;if(S){const _=S.querySelector(".error-message");_&&(_.style.opacity="1")}},onMouseLeave:D=>{if(!E){const S=D.currentTarget.nextElementSibling;if(S){const _=S.querySelector(".error-message");_&&(_.style.opacity="0")}}}}),W.jsx("div",{style:{position:"absolute",zIndex:E?200:100,left:w.left,top:w.top,color:E?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:n||E?"flex":"none",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:w.transform},children:W.jsx("div",{className:`error-message ${mmA}`,style:{opacity:E?1:0,border:`1px solid ${E?"#ff4444":"red"}`},children:g.message})})]},h)}if(Q?.route&&(n||E)){const u=Q.route.map(w=>Ce(A,{x:w.x,y:w.y}));if(u.some(w=>isNaN(w.x)||isNaN(w.y)))return null;const d=Math.floor(u.length/2),f=u[d],y=ymA(f,i);return W.jsxs(V.Fragment,{children:[W.jsx(Dti,{points:u,errorCenter:f,isHighlighted:E}),W.jsx("div",{style:{position:"absolute",left:f.x-15,top:f.y-15,width:30,height:30,zIndex:kc.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:w=>{const D=w.currentTarget.nextElementSibling;if(D){const S=D.querySelector(".error-message");S&&(S.style.opacity="1")}},onMouseLeave:w=>{if(!E){const D=w.currentTarget.nextElementSibling;if(D){const S=D.querySelector(".error-message");S&&(S.style.opacity="0")}}}}),W.jsx("div",{style:{position:"absolute",zIndex:E?kc.errorOverlay+10:kc.errorOverlay+1,left:y.left,top:y.top,color:E?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:"flex",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:y.transform},children:W.jsx("div",{className:`error-message ${mmA}`,style:{opacity:E?1:0,border:`1px solid ${E?"#ff4444":"red"}`},children:g.message})})]},h)}return null}),r.map((g,c)=>{const I=g.component_name||g.message?.match(/name "([^"]+)"/)?.[1];if(!I)return null;const l=e?.filter(Q=>Q.type==="source_component"&&Q.name===I||Q.type==="pcb_component"&&e?.find(h=>h.type==="source_component"&&h.source_component_id===Q.source_component_id&&h.name===I))||[],B=g.pcb_trace_error_id||`error_${c}_${g.error_type}_${g.message?.slice(0,20)}`,C=o===B;return!C&&!n?null:l.map((Q,h)=>{let E={x:0,y:0};if(Q.type==="pcb_component")E=Q.center||{x:0,y:0};else if(Q.type==="source_component"){const _=e?.find(b=>b.type==="pcb_component"&&b.source_component_id===Q.source_component_id);_&&_.type==="pcb_component"&&(E=_.center||{x:0,y:0})}const u=Ce(A,E);if(isNaN(u.x)||isNaN(u.y))return null;const d=Math.abs(A.a),D=Math.max(8,Math.min(30,.5*d)),S=ymA(u,i);return W.jsxs(V.Fragment,{children:[W.jsx("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none",mixBlendMode:"difference",zIndex:kc.errorOverlay},width:"100%",height:"100%",children:C?W.jsx("polygon",{points:`${u.x},${u.y-D*1.25} ${u.x+D},${u.y} ${u.x},${u.y+D*1.25} ${u.x-D},${u.y}`,fill:"#ff4444"}):W.jsx("circle",{cx:u.x,cy:u.y,r:D,fill:"none",stroke:C?"#ff4444":"red",strokeWidth:C?Math.max(2,D*.15):Math.max(1,D*.1),opacity:1})}),W.jsx("div",{style:{position:"absolute",left:u.x-(D+10),top:u.y-(D+10),width:(D+10)*2,height:(D+10)*2,zIndex:kc.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:_=>{const b=_.currentTarget.nextElementSibling;if(b){const N=b.querySelector(".error-message");N&&(N.style.opacity="1")}},onMouseLeave:_=>{if(!C){const b=_.currentTarget.nextElementSibling;if(b){const N=b.querySelector(".error-message");N&&(N.style.opacity="0")}}}}),W.jsx("div",{style:{position:"absolute",zIndex:C?kc.errorOverlay+20:kc.errorOverlay+10,left:S.left,top:S.top,color:C?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:n||C?"flex":"none",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:S.transform},children:W.jsx("div",{className:`error-message ${mmA}`,style:{opacity:C?1:0,border:`1px solid ${C?"#ff4444":"red"}`},children:g.message})})]},`${B}_${h}`)})})]})};function bti(t,A){return t.size!==A.size?!1:Array.from(t).every(e=>A.has(e))}function xti({primitiveElement:t,elements:A}){let e=t.trace_length?`${t.trace_length.toFixed(3)}`:"";const i=rx(A).source_trace.get(t?.source_trace_id);if(i?.display_name&&(i?.max_length?e+=` / ${i.max_length}mm `:e+=" mm ",e+=`(${i.display_name})`),!e)return null;const n=t.trace_length&&i?.max_length&&t.trace_length>i.max_length;return{text:e,isOverLength:n}}function _ti(t){const{primitives:A,is_showing_multiple_traces_length:e,elements:i}=t,n=A.filter(a=>a._element.type==="pcb_trace"),o=i.filter(a=>a.type==="source_trace"),s=A.filter(a=>a._element.type!=="pcb_trace"),r=n.filter(a=>o.some(g=>a._element.type==="pcb_trace"&&a._element.source_trace_id===g.source_trace_id&&g.max_length!==void 0));if(!e)return[...s,...r];if(n.length>1){const a=n.reduce((g,c)=>{const I=g._element.trace_length;return c._element.trace_length<I?c:g},n[0]);return[...s,a]}return A}var kti={position:"absolute",left:0,top:0,pointerEvents:"none",color:"red",fontFamily:"sans-serif",fontSize:12,textShadow:"0 0 2px black"},vti=t=>{const{_element:A,_parent_pcb_component:e,_parent_source_component:i,_source_port:n}=t;switch(A.type){case"pcb_trace":return A.trace_length?`${A.trace_length.toFixed(3)}`:"";case"pcb_smtpad":case"pcb_plated_hole":{const o=[],s=Array.from(new Set((A.port_hints??[]).concat(n?.port_hints??[]))).filter(a=>!/^[0-9]+$/.test(a)).filter(a=>!a.includes("unnamed_")).sort((a,g)=>g.localeCompare(a)),r=i&&"name"in i&&i.name&&!i.name.includes("unnamed_")?i.name:null;return s.length>0?r?o.push(...s.map(a=>`${r}.${a}`)):o.push(...s):r&&o.push(r),o.join(", ")}default:return""}},Fti={top:"red",bottom:"aqua"},Mti=({primitive:t,mousePos:A,elements:e})=>{const[i,n]=V.useState(!1),o=t._element;V.useEffect(()=>{setTimeout(()=>{n(!0)},100)},[]);const[s,r,a,g]=[t.screen_x,t.screen_y,t.screen_w,t.screen_h],c=t.same_space_index??0,I=26,l=Fti[t?._element?.layer]??"red";let B=0;if(o.type==="pcb_smtpad"&&o?.shape==="rotated_rect"?B=o?.ccw_rotation??0:(o.type==="pcb_smtpad"&&(o?.shape==="pill"||o?.shape==="rotated_pill")&&"ccw_rotation"in t||o.type==="pcb_plated_hole"&&(o?.shape==="pill"||o?.shape==="oval")&&"ccw_rotation"in t)&&(B=o.ccw_rotation??0),o.type==="pcb_trace"){const h=xti({primitiveElement:o,elements:e});if(!h)return null;const E=A.y-35;return W.jsx("div",{style:{zIndex:kc.elementOverlay,position:"absolute",left:A.x,top:E,color:l,pointerEvents:"none",transform:"translateX(-50%)"},children:W.jsx("div",{style:{backgroundColor:"#f2efcc",color:h.isOverLength?"red":"black",textShadow:"none",WebkitFontSmoothing:"antialiased",MozOsxFontSmoothing:"grayscale",padding:"6px 6px",borderRadius:"6px",fontSize:"14px",minWidth:"45px",textAlign:"center",whiteSpace:"nowrap"},children:h.text})})}const C=vti(t);return C.trim().length===0?null:W.jsx("div",{style:{zIndex:kc.elementOverlay,position:"absolute",left:s-a/2-8,top:r-g/2-8,width:a+16,height:g+16,color:l,transform:`rotate(${-B}deg)`,transformOrigin:"center center"},children:W.jsx("div",{style:{width:i?`calc(100% + ${I*2*c}px)`:"100%",height:i?`calc(100% + ${I*2*c}px)`:"100%",marginLeft:i?`${-I*c}px`:0,marginTop:i?`${-I*c}px`:0,border:`1px solid ${l}`,opacity:i||c===0?1:0,transition:"width 0.2s, height 0.2s, margin-left 0.2s, margin-top 0.2s, opacity 0.2s"},children:W.jsx("div",{style:{position:"absolute",bottom:g+20+I*c,marginRight:i?`${-I*c}px`:0,marginBottom:i?0:-I*c,transition:"margin-right 0.2s, margin-bottom 0.2s",backgroundColor:"#f2efcc",color:"black",textShadow:"none",WebkitFontSmoothing:"antialiased",MozOsxFontSmoothing:"grayscale",padding:"6px 6px",borderRadius:"6px",fontSize:"14px",transform:`rotate(${B}deg)`,minWidth:"45px",textAlign:"center"},children:C})})})},Rti=({highlightedPrimitives:t,mousePos:A,elements:e})=>{const[i,n]=gl(r=>[r.is_moving_component,r.is_showing_multiple_traces_length]),o=t.some(r=>r._element.type==="pcb_smtpad")&&t.some(r=>r._element.type==="pcb_trace");let s=t;return o&&(s=s.filter(r=>r._element.type==="pcb_smtpad")),s=_ti({primitives:s,is_showing_multiple_traces_length:n,elements:e}),W.jsx("div",{style:kti,children:!i&&s.map((r,a)=>W.jsx(Mti,{primitive:r,mousePos:A,elements:e},a))})},Tk=t=>t?.type==="pcb_component",cEe=t=>t?.type==="pcb_group",Nti=t=>t?.type==="pcb_panel",wmA=t=>t?.type==="pcb_board",aI={MIN_LINE_LENGTH_FOR_LABEL:40,LABEL_OFFSET_ABOVE:2,LABEL_OFFSET_BELOW:-18,LABEL_OFFSET_RIGHT:8,LABEL_OFFSET_LEFT:-120,Y_LABEL_MIN_WIDTH:110,LINE_STROKE_WIDTH:1.5,LINE_DASH_PATTERN:"4,4",COMPONENT_MARKER_RADIUS:3,LABEL_FONT_SIZE:11,ANCHOR_MARKER_SIZE:6,ANCHOR_MARKER_STROKE_WIDTH:1.5},ly={OFFSET_LINE:"white",COMPONENT_MARKER_FILL:"#66ccff",COMPONENT_MARKER_STROKE:"white",LABEL_TEXT:"white"},DmA=({targets:t,transform:A,containerWidth:e,containerHeight:i})=>{if(t.length===0)return null;const n={color:ly.LABEL_TEXT,mixBlendMode:"difference",pointerEvents:"none",fontSize:aI.LABEL_FONT_SIZE,fontFamily:"monospace",fontWeight:"bold"},o=new Map;return t.forEach(s=>{if(!o.has(s.anchor_id)){const r=Ce(A,s.anchor);o.set(s.anchor_id,r)}}),W.jsx("div",{style:{position:"absolute",left:0,top:0,width:e,height:i,overflow:"hidden",pointerEvents:"none",zIndex:kc.dimensionOverlay},children:W.jsxs("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none"},width:e,height:i,children:[t.map(s=>{const r=s.anchor,a=s.anchor_id,g=s.target,c=o.get(a),I=Ce(A,g),l=g.x-r.x,B=g.y-r.y,C=Math.abs(I.x-c.x),Q=Math.abs(I.y-c.y),h=I.y<c.y,E=I.x>c.x,u=h?aI.LABEL_OFFSET_ABOVE:aI.LABEL_OFFSET_BELOW,d=E?aI.LABEL_OFFSET_RIGHT:aI.LABEL_OFFSET_LEFT,f=C>aI.MIN_LINE_LENGTH_FOR_LABEL,y=Q>aI.MIN_LINE_LENGTH_FOR_LABEL,w=`${s.display_offset_x??l.toFixed(2)}mm`,D=`${s.display_offset_y??B.toFixed(2)}mm`;return W.jsxs("g",{children:[W.jsx("line",{x1:c.x,y1:c.y,x2:I.x,y2:c.y,stroke:ly.OFFSET_LINE,strokeWidth:aI.LINE_STROKE_WIDTH,strokeDasharray:aI.LINE_DASH_PATTERN}),W.jsx("line",{x1:I.x,y1:c.y,x2:I.x,y2:I.y,stroke:ly.OFFSET_LINE,strokeWidth:aI.LINE_STROKE_WIDTH,strokeDasharray:aI.LINE_DASH_PATTERN}),s.type==="component"||s.type==="board"?W.jsx("circle",{cx:I.x,cy:I.y,r:aI.COMPONENT_MARKER_RADIUS,fill:ly.COMPONENT_MARKER_FILL,stroke:ly.COMPONENT_MARKER_STROKE,strokeWidth:1}):W.jsxs(W.Fragment,{children:[W.jsx("line",{x1:I.x-aI.ANCHOR_MARKER_SIZE,y1:I.y,x2:I.x+aI.ANCHOR_MARKER_SIZE,y2:I.y,stroke:ly.OFFSET_LINE,strokeWidth:aI.ANCHOR_MARKER_STROKE_WIDTH}),W.jsx("line",{x1:I.x,y1:I.y-aI.ANCHOR_MARKER_SIZE,x2:I.x,y2:I.y+aI.ANCHOR_MARKER_SIZE,stroke:ly.OFFSET_LINE,strokeWidth:aI.ANCHOR_MARKER_STROKE_WIDTH})]}),f&&W.jsx("foreignObject",{x:Math.min(c.x,I.x),y:c.y+u,width:Math.abs(I.x-c.x),height:20,style:{overflow:"visible"},children:W.jsx("div",{style:{...n,textAlign:"center"},children:w})}),y&&W.jsx("foreignObject",{x:I.x+d,y:Math.min(c.y,I.y),width:aI.Y_LABEL_MIN_WIDTH,height:Math.abs(I.y-c.y),style:{overflow:"visible"},children:W.jsx("div",{style:{...n,display:"flex",alignItems:"center",justifyContent:E?"flex-start":"flex-end",whiteSpace:"nowrap",padding:"0 4px",height:"100%"},children:D})})]},s.id)}),Array.from(o.entries()).map(([s,r])=>W.jsxs("g",{children:[W.jsx("line",{x1:r.x-aI.ANCHOR_MARKER_SIZE,y1:r.y,x2:r.x+aI.ANCHOR_MARKER_SIZE,y2:r.y,stroke:ly.OFFSET_LINE,strokeWidth:aI.ANCHOR_MARKER_STROKE_WIDTH}),W.jsx("line",{x1:r.x,y1:r.y-aI.ANCHOR_MARKER_SIZE,x2:r.x,y2:r.y+aI.ANCHOR_MARKER_SIZE,stroke:ly.OFFSET_LINE,strokeWidth:aI.ANCHOR_MARKER_STROKE_WIDTH})]},`anchor-${s}`))]})})},Gti=({elements:t,highlightedPrimitives:A,transform:e,containerWidth:i,containerHeight:n})=>{const o=t.filter(E=>wmA(E)),s=t.filter(E=>Tk(E)),r=t.filter(E=>cEe(E)),a=A.map(E=>Tk(E._parent_pcb_component)?E._parent_pcb_component.pcb_component_id:Tk(E._element)?E._element.pcb_component_id:null).filter(E=>!!E),g=new Set;if(a.forEach(E=>{const u=s.find(d=>d.pcb_component_id===E);u?.pcb_group_id&&g.add(u.pcb_group_id)}),!gl(E=>E.is_showing_group_anchor_offsets)&&a.length===0)return null;const I=s.map(E=>{const u=E.positioned_relative_to_pcb_board_id;if(!u)return null;const d=o.find(f=>f.pcb_board_id===u);return d?{component:E,board:d,type:"component"}:null}).filter(E=>!!E),l=r.map(E=>{const u=E.positioned_relative_to_pcb_board_id;if(!u||!E.center)return null;const d=o.find(f=>f.pcb_board_id===u);return d?{group:E,board:d,type:"group"}:null}).filter(E=>!!E),B=[...I,...l];if(B.length===0)return null;const C=a.length===0,Q=B.filter(E=>E.type==="component"?C||a.includes(E.component.pcb_component_id):C||g.has(E.group.pcb_group_id));if(Q.length===0)return null;const h=Q.map(E=>E.type==="component"?{id:`${E.board.pcb_board_id}-${E.component.pcb_component_id}-${E.type}`,anchor:E.board.center,anchor_id:E.board.pcb_board_id,target:E.component.center,type:"component",display_offset_x:E.component.display_offset_x,display_offset_y:E.component.display_offset_y}:{id:`${E.board.pcb_board_id}-${E.group.pcb_group_id}-${E.type}`,anchor:E.board.center,anchor_id:E.board.pcb_board_id,target:{x:E.group.anchor_position?.x??E.group.center.x,y:E.group.anchor_position?.y??E.group.center.y},type:"group",display_offset_x:E.group.display_offset_x,display_offset_y:E.group.display_offset_y}).filter(E=>!!E);return W.jsx(DmA,{targets:h,transform:e,containerWidth:i,containerHeight:n})},Lti=({elements:t,highlightedPrimitives:A,transform:e,containerWidth:i,containerHeight:n})=>{const o=t.filter(E=>cEe(E)),s=t.filter(E=>Tk(E)),r=A.map(E=>Tk(E._parent_pcb_component)?E._parent_pcb_component.pcb_component_id:Tk(E._element)?E._element.pcb_component_id:null).filter(E=>!!E),a=(E,u)=>{if(u.has(E))return;u.add(E);const d=o.find(f=>f.pcb_group_id===E);d?.position_mode==="relative_to_group_anchor"&&d.positioned_relative_to_pcb_group_id&&a(d.positioned_relative_to_pcb_group_id,u)},g=new Set;if(r.forEach(E=>{const u=s.find(d=>d.pcb_component_id===E);u&&(u.position_mode==="relative_to_group_anchor"&&u.positioned_relative_to_pcb_group_id&&a(u.positioned_relative_to_pcb_group_id,g),u.pcb_group_id&&a(u.pcb_group_id,g))}),!gl(E=>E.is_showing_group_anchor_offsets)&&r.length===0)return null;const I=s.map(E=>{if(E.position_mode==="relative_to_group_anchor"&&E.positioned_relative_to_pcb_group_id){const u=o.find(d=>d.pcb_group_id===E.positioned_relative_to_pcb_group_id);return u&&u.anchor_position?{component:E,parentGroup:u,type:"component"}:null}if(E.pcb_group_id){const u=o.find(d=>d.pcb_group_id===E.pcb_group_id);return u&&u.anchor_position?{component:E,parentGroup:u,type:"component"}:null}return null}).filter(E=>!!E),l=o.map(E=>{if(E.position_mode==="relative_to_group_anchor"&&E.positioned_relative_to_pcb_group_id){const u=o.find(d=>d.pcb_group_id===E.positioned_relative_to_pcb_group_id);if(u&&u.anchor_position&&E.anchor_position)return{group:E,parentGroup:u,type:"group"}}return null}).filter(E=>!!E),B=[...I,...l];if(B.length===0)return null;const C=r.length===0,Q=B.filter(E=>E.type==="component"?C||r.includes(E.component.pcb_component_id):C||g.has(E.group.pcb_group_id)||g.has(E.parentGroup.pcb_group_id));if(Q.length===0)return null;const h=Q.map(E=>{const u=E.parentGroup.anchor_position;return u?E.type==="component"?E.component.center?{id:`${E.parentGroup.pcb_group_id}-${E.component.pcb_component_id}-${E.type}`,anchor:u,anchor_id:E.parentGroup.pcb_group_id,target:E.component.center,type:"component",display_offset_x:E.component.display_offset_x,display_offset_y:E.component.display_offset_y}:null:E.group.anchor_position?{id:`${E.parentGroup.pcb_group_id}-${E.group.pcb_group_id}-${E.type}`,anchor:u,anchor_id:E.parentGroup.pcb_group_id,target:E.group.anchor_position,type:"group",display_offset_x:E.group.display_offset_x,display_offset_y:E.group.display_offset_y}:null:null}).filter(E=>!!E);return W.jsx(DmA,{targets:h,transform:e,containerWidth:i,containerHeight:n})},Uti=(t,A)=>{const e=t.pcb_component_id,i=A.filter(n=>(n.type==="pcb_smtpad"||n.type==="pcb_plated_hole")&&n.pcb_component_id===e||n.type==="pcb_hole"&&n.pcb_component_id===e);return i.length===0?pmA([t]):pmA(i)},Hti=({elements:t,highlightedPrimitives:A,transform:e,containerWidth:i,containerHeight:n})=>{const o=new Map;for(const r of A)Tk(r._parent_pcb_component)&&o.set(r._parent_pcb_component.pcb_component_id,r._parent_pcb_component),Tk(r._element)&&o.set(r._element.pcb_component_id,r._element);if(o.size===0)return null;const s=[];for(const r of o.values()){const a=Uti(r,t);if(!a)continue;const g=r.positioned_relative_to_pcb_group_id??r.pcb_group_id,c=g?rx(t).pcb_group.get(g):null;s.push({component:r,bbox:a,group:c})}return s.length===0?null:W.jsx("div",{style:{position:"absolute",left:0,top:0,width:i,height:n,overflow:"hidden",pointerEvents:"none",zIndex:kc.dimensionOverlay},children:W.jsx("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none"},width:i,height:n,children:s.map(({component:r,bbox:a,group:g})=>{const c=Ce(e,{x:a.minX,y:a.maxY}),I=Ce(e,{x:a.maxX,y:a.minY}),l={x:Math.min(c.x,I.x),y:Math.min(c.y,I.y),width:Math.abs(I.x-c.x),height:Math.abs(I.y-c.y)},B=r.center??{x:(a.minX+a.maxX)/2,y:(a.minY+a.maxY)/2},C=Ce(e,B);return W.jsxs("g",{children:[W.jsx("rect",{x:l.x,y:l.y,width:l.width,height:l.height,fill:"none",stroke:"white",strokeWidth:1.5,strokeDasharray:"4,4"}),W.jsx("line",{x1:C.x-6,y1:C.y,x2:C.x+6,y2:C.y,stroke:ly.COMPONENT_MARKER_STROKE,strokeWidth:1.5}),W.jsx("line",{x1:C.x,y1:C.y-6,x2:C.x,y2:C.y+6,stroke:ly.COMPONENT_MARKER_STROKE,strokeWidth:1.5}),W.jsx("circle",{cx:C.x,cy:C.y,r:aI.COMPONENT_MARKER_RADIUS,fill:ly.COMPONENT_MARKER_FILL,stroke:ly.COMPONENT_MARKER_STROKE,strokeWidth:1})]},r.pcb_component_id)})})})},Yti=({elements:t,highlightedPrimitives:A,transform:e,containerWidth:i,containerHeight:n})=>{const o=t.filter(B=>Nti(B)),s=t.filter(B=>wmA(B)),r=A.map(B=>wmA(B._element)?B._element.pcb_board_id:null).filter(B=>!!B);if(!gl(B=>B.is_showing_group_anchor_offsets)&&r.length===0)return null;const g=s.map(B=>{const C=B.pcb_panel_id,Q=B.position_mode;if(!C||Q!=="relative_to_panel_anchor")return null;const h=o.find(E=>E.pcb_panel_id===C);return h?{board:B,panel:h,type:"board"}:null}).filter(B=>!!B);if(g.length===0)return null;const c=r.length===0,I=g.filter(B=>c||r.includes(B.board.pcb_board_id));if(I.length===0)return null;const l=I.map(B=>B.board.center?{id:`${B.panel.pcb_panel_id}-${B.board.pcb_board_id}-${B.type}`,anchor:B.panel.center,anchor_id:B.panel.pcb_panel_id,target:B.board.center,type:"board",display_offset_x:B.board.display_offset_x,display_offset_y:B.board.display_offset_y}:null).filter(B=>!!B);return W.jsx(DmA,{targets:l,transform:e,containerWidth:i,containerHeight:n})},Nz=t=>{if(t.length===0)return null;let A=t[0].x,e=t[0].y,i=t[0].x,n=t[0].y;for(const o of t)o.x<A&&(A=o.x),o.y<e&&(e=o.y),o.x>i&&(i=o.x),o.y>n&&(n=o.y);return{center:{x:(A+i)/2,y:(e+n)/2},width:i-A,height:n-e}},IEe=(t,A)=>{if(A.length<3)return!1;let e=!1;for(let i=0,n=A.length-1;i<A.length;n=i++){const o=A[i].x,s=A[i].y,r=A[n].x,a=A[n].y;s>t.y!=a>t.y&&t.x<(r-o)*(t.y-s)/(a-s||Number.EPSILON)+o&&(e=!e)}return e},Jti=(t,A,e)=>{const i=[];for(const n of t){if(!n._element)continue;if("x1"in n&&n._element?.type==="pcb_trace"){const r=HE({x:A.x,y:A.y},{x:n.x1,y:n.y1},{x:n.x2,y:n.y2}),a=n.width||.5,g=Math.max(a*25,2)/e.a;r<g&&i.push(n);continue}if(n.pcb_drawing_type==="polygon"){const r=n.points.map(g=>({x:Et.parse(g.x),y:Et.parse(g.y)})),a=Nz(r);if(!a||A.x<a.center.x-a.width/2||A.x>a.center.x+a.width/2||A.y<a.center.y-a.height/2||A.y>a.center.y+a.height/2)continue;IEe(A,r)&&i.push(n);continue}if(n.pcb_drawing_type==="polygon_with_arcs"){const r=n.brep_shape.outer_ring.vertices.map(g=>({x:Et.parse(g.x),y:Et.parse(g.y)})),a=Nz(r);if(!a||A.x<a.center.x-a.width/2||A.x>a.center.x+a.width/2||A.y<a.center.y-a.height/2||A.y>a.center.y+a.height/2)continue;IEe(A,r)&&i.push(n);continue}if(!("x"in n&&"y"in n))continue;let o=0,s=0;if("w"in n&&"h"in n)o=n.w,s=n.h;else if("r"in n)o=n.r*2,s=n.r*2;else if("rX"in n&&"rY"in n)o=n.rX*2,s=n.rY*2;else continue;Math.abs(n.x-A.x)<o/2&&Math.abs(n.y-A.y)<s/2&&i.push(n)}return i},Tti=({elements:t,children:A,transform:e,primitives:i,onMouseHoverOverPrimitives:n})=>{const[o,s]=V.useState([]),[r,a]=V.useState({x:0,y:0}),[g,{width:c,height:I}]=qT(),l=V.useMemo(()=>{const C=[];for(const Q of o){if(Q._element?.type==="pcb_via"||Q._element?.type==="pcb_component"||Q?.layer==="drill"||Q?.is_hoverable===!1)continue;let h=null,E=0,u=0;if(Q.pcb_drawing_type==="polygon"){const w=Nz(Q.points);if(!w)continue;h=w.center,E=w.width,u=w.height}else if(Q.pcb_drawing_type==="polygon_with_arcs"){const w=Q.brep_shape.outer_ring.vertices.map(S=>({x:S.x,y:S.y})),D=Nz(w);if(!D)continue;h=D.center,E=D.width,u=D.height}else"x"in Q&&"y"in Q&&(h={x:Q.x,y:Q.y},E="w"in Q?Q.w:"r"in Q?Q.r*2:"rX"in Q&&"rY"in Q?Q.rX*2:0,u="h"in Q?Q.h:"r"in Q?Q.r*2:"rX"in Q&&"rY"in Q?Q.rY*2:0);if(!h)continue;const d=Ce(e,h),f={w:E*e.a,h:u*e.a},y=C.filter(w=>d.x===w.screen_x&&d.y===w.screen_y&&f.w===w.screen_w&&f.h===w.screen_h).length;C.push({...Q,x:h.x,y:h.y,w:E,h:u,screen_x:d.x,screen_y:d.y,screen_w:f.w,screen_h:f.h,same_space_index:y})}return C},[o,e]),B=(C,Q,h,E)=>{a({x:C,y:Q});const u=Ce(tm(h),{x:C,y:Q}),d=Jti(E,u,h);bti(new Set(d.map(f=>f._pcb_drawing_object_id)),new Set(o.map(f=>f._pcb_drawing_object_id)))||(s(d),n(d))};return W.jsxs("div",{ref:g,style:{position:"relative",width:"100%",height:"100%"},onMouseMove:C=>{if(e){const Q=C.currentTarget.getBoundingClientRect(),h=C.clientX-Q.left,E=C.clientY-Q.top;B(h,E,e,i)}},onTouchStart:C=>{if(e){const Q=C.touches[0],h=C.currentTarget.getBoundingClientRect(),E=Q.clientX-h.left,u=Q.clientY-h.top;B(E,u,e,i)}},children:[A,W.jsx(Rti,{elements:t,mousePos:r,highlightedPrimitives:l}),e&&W.jsxs(W.Fragment,{children:[W.jsx(Gti,{elements:t,highlightedPrimitives:l,transform:e,containerWidth:c,containerHeight:I}),W.jsx(Lti,{elements:t,highlightedPrimitives:l,transform:e,containerWidth:c,containerHeight:I}),W.jsx(Hti,{elements:t,highlightedPrimitives:l,transform:e,containerWidth:c,containerHeight:I}),W.jsx(Yti,{elements:t,highlightedPrimitives:l,transform:e,containerWidth:c,containerHeight:I})]})]})},lEe=["rgb(255, 100, 100)","rgb(100, 255, 100)","rgb(100, 100, 255)","rgb(255, 255, 100)","rgb(255, 100, 255)","rgb(100, 255, 255)","rgb(255, 150, 100)","rgb(150, 100, 255)","rgb(100, 255, 150)","rgb(255, 100, 150)"],Pti=({children:t,transform:A=xa(),elements:e=[],hoveredComponentIds:i=[]})=>{const[n,{width:o,height:s}]=qT(),r=V.useRef(null),{is_showing_pcb_groups:a,pcb_group_view_mode:g,is_showing_group_anchor_offsets:c}=gl(I=>({is_showing_pcb_groups:I.is_showing_pcb_groups,pcb_group_view_mode:I.pcb_group_view_mode,is_showing_group_anchor_offsets:I.is_showing_group_anchor_offsets}));return V.useEffect(()=>{const I=r.current;if(!I||!o||!s)return;I.width=o,I.height=s;const l=I.getContext("2d");if(!l||(l.clearRect(0,0,o,s),!a))return;const B=e.filter(w=>w.type==="pcb_group"),C=e.filter(w=>w.type==="pcb_component"),Q=e.filter(w=>w.type==="source_group"),h=new Map(Q.map(w=>[w.source_group_id,w])),E=B.filter(w=>{if(w.name?.toLowerCase().includes("subpanel"))return!1;if(g==="all")return!0;if(!w.source_group_id)return!1;const D=h.get(w.source_group_id);return D?D.was_automatically_named!==!0:!1}),u=new Map;Q.forEach(w=>{const D=w;if(D.parent_source_group_id){const S=u.get(D.parent_source_group_id)||[];S.push(w.source_group_id),u.set(D.parent_source_group_id,S)}});const d=w=>{const D=[],S=u.get(w)||[];for(const _ of S)D.push(_),D.push(...d(_));return D},f=w=>{const D=Q.find(S=>S.source_group_id===w);return D?.parent_source_group_id?1+f(D.parent_source_group_id):0},y=new Set;if(i.length>0)for(const w of C){if(!i.includes(w.pcb_component_id))continue;const D=w.positioned_relative_to_pcb_group_id??w.pcb_group_id;D&&y.add(D)}E.forEach((w,D)=>{let S=C.filter(JA=>JA.pcb_group_id===w.pcb_group_id);if(w.source_group_id){const JA=d(w.source_group_id),WA=B.filter(vA=>vA.source_group_id&&JA.includes(vA.source_group_id));for(const vA of WA){const wA=C.filter(RA=>RA.pcb_group_id===vA.pcb_group_id);S=[...S,...wA]}}let _,b,N,F,L=!1;if(w.center&&w.width&&w.height){L=!0;const JA=w.width/2,WA=w.height/2;_=w.center.x-JA,N=w.center.x+JA,b=w.center.y-WA,F=w.center.y+WA}else if(S.length===0||(_=1/0,b=1/0,N=-1/0,F=-1/0,S.forEach(JA=>{if(JA.center&&typeof JA.width=="number"&&typeof JA.height=="number"){const WA=JA.center.x-JA.width/2,vA=JA.center.x+JA.width/2,wA=JA.center.y+JA.height/2,RA=JA.center.y-JA.height/2;_=Math.min(_,WA),N=Math.max(N,vA),b=Math.min(b,RA),F=Math.max(F,wA)}}),_===1/0||N===-1/0))return;const Y=w.source_group_id?f(w.source_group_id):0,J=w.source_group_id?d(w.source_group_id).length>0:!1;if(!L){const vA=1+(J?.5:0);_-=vA,N+=vA,b-=vA,F+=vA}const O=Ce(A,{x:_,y:F}),Z=Ce(A,{x:N,y:F}),X=Ce(A,{x:_,y:b}),eA=Ce(A,{x:N,y:b}),gA=lEe[D%lEe.length];l.strokeStyle=gA,l.lineWidth=2;const tA=Math.max(4,Math.min(12,8*Math.abs(A.a))),iA=Math.max(2,Math.min(6,4*Math.abs(A.a))),aA=tA*(J?1.3:1),EA=iA;l.setLineDash([aA,EA]),l.beginPath(),l.moveTo(O.x,O.y),l.lineTo(Z.x,Z.y),l.lineTo(eA.x,eA.y),l.lineTo(X.x,X.y),l.closePath(),l.stroke();const bA=Math.max(8,Math.min(12,10*Math.abs(A.a))),_A=Y==0||Y==1?0:Y*.11,LA=bA*(1-_A),QA=4,kA=w.name||`Group ${D+1}`;l.font=`${LA}px sans-serif`,l.setLineDash([]);const qA=l.measureText(kA).width+QA*2,VA=LA+QA*2,ce=O.x-5,fA=O.y-5,ge=3;if(l.fillStyle="rgba(0, 0, 0, 0.8)",l.beginPath(),l.roundRect(ce,fA-VA,qA,VA,ge),l.fill(),l.fillStyle=gA,l.textAlign="left",l.textBaseline="middle",l.fillText(kA,ce+QA,fA-VA/2),c&&y.has(w.pcb_group_id)&&!!w.anchor_position&&w.anchor_position){const JA=Array.isArray(w.anchor_position)?{x:w.anchor_position[0]??0,y:w.anchor_position[1]??0}:{x:w.anchor_position.x,y:w.anchor_position.y},WA=Ce(A,JA);l.strokeStyle="white",l.lineWidth=1.5,l.setLineDash([]);const vA=Math.max(4,Math.min(8,6*Math.abs(A.a)));l.beginPath(),l.moveTo(WA.x-vA,WA.y),l.lineTo(WA.x+vA,WA.y),l.stroke(),l.beginPath(),l.moveTo(WA.x,WA.y-vA),l.lineTo(WA.x,WA.y+vA),l.stroke()}})},[e,A,o,s,a,g,c,i]),W.jsxs("div",{ref:n,style:{position:"relative",width:"100%",height:"100%"},children:[t,W.jsx("canvas",{ref:r,style:{position:"absolute",top:0,left:0,pointerEvents:"none",zIndex:kc.pcbGroupOverlay,display:a?"block":"none"}})]})},Kti=({transform:t,soup:A,children:e})=>{const i=gl(r=>r.is_showing_rats_nest),{netMap:n,idToNetMap:o}=V.useMemo(()=>Phe(A||[]),[A]),s=V.useMemo(()=>{if(!A||!i)return[];const r=l=>{const B=rx(A)[l.replace(/_\d+$/,"")].get(l);return B&&"x"in B&&"y"in B?{x:B.x,y:B.y}:null},a=(l,B)=>{const C=n[B]||[];let Q=null,h=1/0;return C.forEach(E=>{const u=r(E);if(u){const d=Math.sqrt((l.x-u.x)**2+(l.y-u.y)**2);d<h&&d>0&&(h=d,Q=u)}}),Q},g=rx(A).pcb_port.list(),c=rx(A).source_trace.list(),I=[];return g.forEach((l,B)=>{const C=o[l.pcb_port_id];let Q=!1;for(const u of c)u.connected_source_port_ids.includes(l.source_port_id)&&u.connected_source_net_ids.length>0&&(Q=!0);if(!C)return;const h={x:l.x,y:l.y},E=a(h,C);E&&I.push({key:`${l.pcb_port_id}-${B}`,startPoint:h,endPoint:E,isInNet:Q})}),I},[A,n,o,i]);return!A||!i?e:(t||(t=xa()),W.jsxs("div",{style:{position:"relative"},children:[e,W.jsx("svg",{style:{position:"absolute",left:0,top:0,width:"100%",height:"100%",pointerEvents:"none",opacity:.5,zIndex:kc.ratsNestOverlay},children:s.map(({key:r,startPoint:a,endPoint:g,isInNet:c})=>{const I=Ce(t,a),l=Ce(t,g);return W.jsx("line",{x1:I.x,y1:I.y,x2:l.x,y2:l.y,stroke:"white",strokeWidth:"1",strokeDasharray:c?"6,6":void 0},r)})})]}))},qti={version:"1.11.355"},Pk=(t,A,e)=>{const i=gl(s=>s.is_mouse_over_container),n=V.useRef(i),o=V.useRef(A);V.useEffect(()=>{n.current=i},[i]),V.useEffect(()=>{o.current=A},[A]),V.useEffect(()=>{if(!t)return;const s=r=>{const a=r.target;if(a.tagName==="INPUT"||a.tagName==="TEXTAREA"||a.isContentEditable)return;const g=t.split("+"),c=g.includes("ctrl"),I=g.includes("shift"),l=g.includes("alt"),B=g.includes("meta"),C=g[g.length-1],Q=e?.current?e.current.contains(document.activeElement)||document.activeElement===e.current:!1;(n.current||Q)&&(!c||r.ctrlKey)&&(!I||r.shiftKey)&&(!l||r.altKey)&&(!B||r.metaKey)&&r.key.toLowerCase()===C.toLowerCase()&&(r.preventDefault(),o.current())};return window.addEventListener("keydown",s),()=>{window.removeEventListener("keydown",s)}},[t])},Oti=()=>{const[t,A]=V.useState(!1);return V.useEffect(()=>{const e=()=>{A(window.innerWidth<=768)};return e(),window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[]),t},WT=(t,A={stopPropagation:!0})=>{const e=V.useRef(0),i=V.useCallback(s=>{A.stopPropagation&&s.stopPropagation();const r=Date.now();r-e.current<300||(e.current=r,t?.(s))},[t,A.stopPropagation]),n=V.useCallback(s=>{s.preventDefault(),i(s)},[i]);return{onClick:i,onTouchEnd:n,style:{touchAction:"manipulation"}}},Wti=({name:t,selected:A,onClick:e})=>{const{style:i,...n}=WT(e);return W.jsxs("div",{className:D2`
|
|
5476
5476
|
margin-top: 2px;
|
|
5477
5477
|
padding: 4px;
|
|
5478
5478
|
padding-left: 8px;
|
|
@@ -5689,7 +5689,7 @@ test("${g} should solve problem correctly", () => {
|
|
|
5689
5689
|
// Add more specific assertions based on expected output
|
|
5690
5690
|
// expect(solver.netLabelPlacementSolver!.netLabelPlacements).toMatchInlineSnapshot()
|
|
5691
5691
|
})
|
|
5692
|
-
`,I=new Blob([c],{type:"text/plain"}),l=URL.createObjectURL(I),B=document.createElement("a");B.href=l,B.download=`${g}.test.ts`,B.click(),URL.revokeObjectURL(l)}catch(a){alert(`Error generating test.ts for ${t.constructor.name}: ${a instanceof Error?a.message:String(a)}`)}i(!1)};return W.jsxs("div",{className:`relative ${A}`,ref:n,children:[W.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>i(!e),title:`Download options for ${t.constructor.name}`,children:t.constructor.name}),e&&W.jsxs("div",{className:"absolute top-full left-0 mt-1 bg-white border border-gray-300 rounded shadow-lg z-10 min-w-[150px]",children:[W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:o,children:"Download JSON"}),W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:r,children:"Download test.ts"})]})]})},fEe=t=>t.activeSubSolver?[t,...fEe(t.activeSubSolver)]:[t],pni=({solver:t})=>{const A=fEe(t);return W.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:A.map((e,i)=>W.jsxs("div",{className:"flex items-center",children:[i>0&&W.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),W.jsx(dni,{solver:e})]},e.constructor.name))})},fni=({solver:t,triggerRender:A,animationSpeed:e=25,onSolverStarted:i,onSolverCompleted:n})=>{const[o,s]=V.useReducer(Q=>!Q,!1),r=V.useRef(void 0),a=()=>{!t.solved&&!t.failed&&(t.step(),A())},g=()=>{!t.solved&&!t.failed&&(i&&i(t),t.solve(),A(),n&&n(t))},c=()=>{o?(r.current&&(clearInterval(r.current),r.current=void 0),s()):(s(),r.current=setInterval(()=>{if(t.solved||t.failed){r.current&&(clearInterval(r.current),r.current=void 0),s(),A(),n&&t.solved&&n(t);return}t.step(),A()},e))},I=()=>{const Q=t;if(Q.getCurrentPhase&&!t.solved&&!t.failed){const h=Q.getCurrentPhase();for(;Q.getCurrentPhase()===h&&!t.solved&&!t.failed;)t.step();A()}},l=()=>{if(t.solved||t.failed||o)return;const Q=window.prompt("Step until which iteration?",`${t.iterations}`);if(Q===null)return;const h=Number(Q);if(!Number.isFinite(h)){window.alert("Please enter a valid number for the iteration");return}for(;t.iterations<h&&!t.solved&&!t.failed;)t.step();A(),t.solved&&n&&n(t)};V.useEffect(()=>()=>{r.current&&clearInterval(r.current)},[]),V.useEffect(()=>{(t.solved||t.failed)&&o&&(r.current&&(clearInterval(r.current),r.current=void 0),s())},[t.solved,t.failed,o]);const B=t.getCurrentPhase!==void 0,C=B?t.getCurrentPhase():null;return W.jsxs("div",{className:"space-y-2 p-2 border-b",children:[W.jsx("div",{className:"flex items-center",children:W.jsx(pni,{solver:t})}),W.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[W.jsx("button",{onClick:a,disabled:t.solved||t.failed||o,className:"bg-blue-500 hover:bg-blue-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step"}),W.jsx("button",{onClick:g,disabled:t.solved||t.failed||o,className:"bg-green-500 hover:bg-green-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Solve"}),W.jsx("button",{onClick:c,disabled:t.solved||t.failed,className:`px-3 py-1 rounded text-white text-sm ${o?"bg-red-500 hover:bg-red-600":"bg-yellow-500 hover:bg-yellow-600"} disabled:bg-gray-300`,children:o?"Stop":"Animate"}),W.jsx("button",{onClick:l,disabled:t.solved||t.failed||o,className:"bg-orange-500 hover:bg-orange-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step Until Iteration"}),B&&W.jsx("button",{onClick:I,disabled:t.solved||t.failed||o,className:"bg-purple-500 hover:bg-purple-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Next Stage"}),W.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",t.iterations]}),t.timeToSolve!==void 0&&W.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(t.timeToSolve/1e3).toFixed(3),"s"]}),C&&W.jsxs("div",{className:"text-sm text-gray-600",children:["Phase: ",W.jsx("span",{className:"font-medium",children:C})]}),t.solved&&W.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),t.failed&&W.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),t.error&&W.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",t.error]})]})},yni=(t,A,e)=>{const i=t.currentPipelineStepIndex;return A<i?"Completed":A===i&&t.activeSubSolver?t.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},mni=(t,A)=>{const i=t.pipelineDef[A].solverName,n=yni(t,A),o=t[i],s=t.firstIterationOfPhase?.[i]??null,r=t.iterations;let a=0;if(n==="Completed"){const l=t.pipelineDef[A+1],B=l?t.firstIterationOfPhase?.[l.solverName]:void 0;B!==void 0&&s!==null?a=B-s:s!==null&&(a=r-s)}else n==="In Progress"&&s!==null&&(a=r-s);const g=t.timeSpentOnPhase?.[i]??0;let c=0;n==="Completed"?c=1:n==="In Progress"&&o&&(c=o.progress??0);const I=o?.stats??null;return{index:A,name:i,status:n,firstIteration:s,iterations:a,progress:c,timeSpent:g,stats:I&&Object.keys(I).length>0?I:null,solverInstance:o??null}},wni=({status:t})=>{const A={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return W.jsx("span",{className:`font-medium ${A[t]}`,children:t})},Dni=({progress:t})=>{if(t===0)return null;const A=Math.round(t*100);return W.jsxs("div",{className:"flex items-center gap-2",children:[W.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:W.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${A}%`}})}),W.jsxs("span",{className:"text-xs text-gray-500",children:[A,"%"]})]})},Sni=t=>Object.entries(t).map(([A,e])=>`${A}: ${e}`).join(", "),bni=({stats:t})=>{if(!t||Object.keys(t).length===0)return W.jsx("span",{children:"-"});const A=Object.entries(t),e=Sni(t);return W.jsxs("details",{className:"cursor-pointer",children:[W.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:e}),W.jsx("div",{className:"mt-1 text-xs",children:A.map(([i,n])=>W.jsxs("div",{children:[i,": ",String(n)]},i))})]})},MmA=t=>{if(t===null||typeof t!="object")return t;if(Array.isArray(t))return t.map(MmA);const A={};for(const[e,i]of Object.entries(t))e.startsWith("_")||(A[e]=MmA(i));return A},xni=(t,A)=>{try{if(typeof t.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${A}`);return}const e=MmA(t.getConstructorParams()),i=new Blob([JSON.stringify(e,null,2)],{type:"application/json"}),n=URL.createObjectURL(i),o=document.createElement("a");o.href=n,o.download=`${A}_input.json`,o.click(),URL.revokeObjectURL(n)}catch(e){alert(`Error downloading input for ${A}: ${e instanceof Error?e.message:String(e)}`)}},_ni=({solver:t,onStepUntilPhase:A,onDownloadInput:e})=>{const i=t.pipelineDef.map((r,a)=>mni(t,a)),n=r=>{A?.(r)},o=r=>{r.solverInstance&&(e?e(r.solverInstance,r.name):xni(r.solverInstance,r.name))},s=r=>`${(r/1e3).toFixed(2)}s`;return W.jsxs("div",{className:"border-t border-gray-200",children:[W.jsx("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200",children:W.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Steps"})}),W.jsx("div",{className:"overflow-x-auto",children:W.jsxs("table",{className:"w-full text-sm",children:[W.jsx("thead",{children:W.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Step"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),W.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",W.jsx("sub",{children:"0"})]}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),W.jsx("tbody",{children:i.map(r=>W.jsxs("tr",{className:`border-b border-gray-100 ${r.status==="In Progress"?"bg-yellow-50":""}`,children:[W.jsx("td",{className:"px-4 py-2",children:W.jsxs("div",{className:"flex items-center gap-2",children:[W.jsx("span",{className:"text-gray-400 w-6",children:String(r.index+1).padStart(2,"0")}),W.jsx("button",{onClick:()=>n(r.name),disabled:r.status==="Completed"||t.solved||t.failed,className:"text-blue-500 hover:text-blue-700 disabled:text-gray-300 disabled:cursor-not-allowed",title:`Step until ${r.name} completes`,children:W.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:W.jsx("path",{fillRule:"evenodd",d:"M4.5 5.653c0-1.426 1.529-2.33 2.779-1.643l11.54 6.348c1.295.712 1.295 2.573 0 3.285L7.28 19.991c-1.25.687-2.779-.217-2.779-1.643V5.653z",clipRule:"evenodd"})})}),W.jsx("span",{className:"font-medium text-gray-900",children:r.name})]})}),W.jsx("td",{className:"px-4 py-2",children:W.jsx(wni,{status:r.status})}),W.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:r.firstIteration!==null?r.firstIteration:""}),W.jsx("td",{className:"px-4 py-2 text-gray-600",children:r.iterations}),W.jsx("td",{className:"px-4 py-2",children:W.jsx(Dni,{progress:r.progress})}),W.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(r.timeSpent)}),W.jsx("td",{className:"px-4 py-2 text-gray-500",children:W.jsx(bni,{stats:r.stats})}),W.jsx("td",{className:"px-4 py-2",children:r.solverInstance?W.jsxs("button",{onClick:()=>o(r),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${r.name}`,children:[W.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:W.jsx("path",{fillRule:"evenodd",d:"M12 2.25a.75.75 0 01.75.75v11.69l3.22-3.22a.75.75 0 111.06 1.06l-4.5 4.5a.75.75 0 01-1.06 0l-4.5-4.5a.75.75 0 111.06-1.06l3.22 3.22V3a.75.75 0 01.75-.75zm-9 13.5a.75.75 0 01.75.75v2.25a1.5 1.5 0 001.5 1.5h13.5a1.5 1.5 0 001.5-1.5V16.5a.75.75 0 011.5 0v2.25a3 3 0 01-3 3H5.25a3 3 0 01-3-3V16.5a.75.75 0 01.75-.75z",clipRule:"evenodd"})}),W.jsx("span",{children:"Input"})]}):null})]},r.name))})]})})]})},kni=class extends Qn.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 vni({graphics:t}){const A=t.points??[],e=t.lines??[],i=t.rects??[],n=t.circles??[],o=t.texts??[];let s=Number.POSITIVE_INFINITY,r=Number.POSITIVE_INFINITY,a=Number.NEGATIVE_INFINITY,g=Number.NEGATIVE_INFINITY;const c=(h,E)=>{typeof h=="number"&&(h<s&&(s=h),h>a&&(a=h)),typeof E=="number"&&(E<r&&(r=E),E>g&&(g=E))};for(const h of A)c(h.x,h.y);for(const h of e){const E=h.points??[];for(const u of E)c(u.x,u.y)}for(const h of i){const E=h.x??0,u=h.y??0,d=h.width??0,f=h.height??0;c(E,u),c(E+d,u+f)}for(const h of n){const E=h.x??0,u=h.y??0,d=h.radius??1;c(E-d,u-d),c(E+d,u+d)}for(const h of o)c(h.x,h.y);(!isFinite(s)||!isFinite(r)||!isFinite(a)||!isFinite(g))&&(s=-20,r=-20,a=20,g=20);const I=10,l=s-I,B=r-I,C=Math.max(1,a-s+2*I),Q=Math.max(1,g-r+2*I);return W.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${l} ${B} ${C} ${Q}`,role:"img","aria-label":"Graphics fallback",children:[i.map((h,E)=>W.jsx("rect",{x:h.x??0,y:h.y??0,width:h.width??0,height:h.height??0,fill:"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1},`rect-${E}`)),e.map((h,E)=>W.jsx("polyline",{fill:"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1,points:(h.points??[]).map(u=>`${u.x??0},${u.y??0}`).join(" ")},`line-${E}`)),n.map((h,E)=>W.jsx("circle",{cx:h.x??0,cy:h.y??0,r:h.radius??1.5,fill:h.fillColor??"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1},`circle-${E}`)),A.map((h,E)=>W.jsx("circle",{cx:h.x??0,cy:h.y??0,r:h.radius??1.5,fill:h.color??"black"},`point-${E}`)),o.map((h,E)=>W.jsx("text",{x:h.x??0,y:h.y??0,fontSize:h.fontSize??10,fill:h.color??"black",children:h.text??""},`text-${E}`))]})}var Fni=({solver:t,animationSpeed:A=25,onSolverStarted:e,onSolverCompleted:i})=>{const[n,o]=V.useReducer(c=>c+1,0),s=V.useMemo(()=>{try{return t.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(c){return console.error("Visualization error:",c),{points:[],lines:[],rects:[],circles:[]}}},[t,n]),r=V.useMemo(()=>(s.rects?.length||0)===0&&(s.lines?.length||0)===0&&(s.points?.length||0)===0&&(s.circles?.length||0)===0,[s]);V.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const c=document.createElement("script");c.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(c)}},[]);const a=t.pipelineDef!==void 0,g=c=>{const I=t;if(!t.solved&&!t.failed){for(;!t.solved&&!t.failed&&I.currentPipelineStepIndex<=I.pipelineDef.findIndex(l=>l.solverName===c);)t.step();o()}};return W.jsxs("div",{children:[W.jsx(fni,{solver:t,triggerRender:o,animationSpeed:A,onSolverStarted:e,onSolverCompleted:i}),r?W.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):W.jsx(kni,{fallback:W.jsx(vni,{graphics:s}),children:W.jsx(uni,{graphics:s})}),a&&W.jsx(_ni,{solver:t,onStepUntilPhase:g})]})};const Mni=()=>{V.useEffect(()=>{const t="tailwind-cdn-script";if(document.getElementById(t)||window.tailwind)return;const A=document.createElement("div");A.className="hidden",document.body.appendChild(A);const e=window.getComputedStyle(A).display==="none";if(document.body.removeChild(A),e)return;const i=document.createElement("script");i.id=t,i.src="https://cdn.tailwindcss.com",document.head.appendChild(i)},[])},Rni=t=>t.toLowerCase().includes("pack")?yqt:t.toLowerCase().includes("rout")?bqt:rqt,Nni=({solverEvents:t=[]})=>{const[A,e]=V.useState(null);Mni();const i=V.useMemo(()=>{const r=new Map;for(const a of t){const g=`${a.componentName}-${a.solverName}`;r.set(g,a)}return r},[t]),n=V.useMemo(()=>Array.from(i.keys()),[i]),o=A?i.get(A):null,s=V.useMemo(()=>{if(!o)return{instance:null,error:null,classFound:!1};const r=WrA[o.solverName];if(!r)return{instance:null,error:`Solver class "${o.solverName}" not found in SOLVERS registry. Available: ${Object.keys(WrA).join(", ")}`,classFound:!1};try{const a=o.solverParams,g=a?.input!==void 0?a.input:a;return{instance:new r(g),error:null,classFound:!0}}catch(a){const g=a instanceof Error?a.message:String(a);return console.error("Failed to reconstruct solver:",a),{instance:null,error:`Failed to instantiate solver: ${g}`,classFound:!0}}},[o]);return t.length===0?W.jsx("div",{className:"rf-p-4",children:W.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:W.jsxs("div",{className:"rf-p-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),W.jsx("p",{className:"rf-text-sm rf-text-gray-600",children:"Solvers will appear here when the circuit runs. Solvers are used for tasks like component packing and autorouting."})]})})}):W.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[W.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[W.jsxs("div",{className:"rf-text-xs rf-font-semibold rf-text-gray-500 rf-px-3 rf-py-2 rf-bg-gray-50 rf-border-b rf-border-gray-200",children:[n.length," ",n.length===1?"Solver":"Solvers"]}),n.map(r=>{const a=i.get(r),g=A===r;return W.jsx("div",{className:`rf-px-3 rf-py-2 rf-cursor-pointer rf-border-b rf-border-gray-100 ${g?"rf-bg-blue-50 rf-border-l-2 rf-border-l-blue-500":"hover:rf-bg-gray-50"}`,onClick:()=>e(r),children:(()=>{const c=Rni(a.solverName);return W.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[W.jsx(c,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),W.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[W.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:a.componentName}),W.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:a.solverName})]})]})})()},r)})]}),W.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:o?s.instance?W.jsx(Dm,{fallback:W.jsx("div",{className:"rf-p-4",children:W.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),W.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",o.solverName]})]})}),children:W.jsx(Fni,{solver:s.instance})}):W.jsxs("div",{className:"rf-p-4",children:[W.jsxs("div",{className:"rf-mb-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:o.solverName}),W.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",o.componentName]})]}),s.error&&W.jsx("div",{className:`rf-rounded-md rf-border rf-p-4 rf-mb-4 ${s.classFound?"rf-bg-red-50 rf-border-red-200":"rf-bg-yellow-50 rf-border-yellow-200"}`,children:W.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),W.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[W.jsx("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50",children:W.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"})}),W.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:W.jsx("pre",{className:"rf-text-xs rf-font-mono rf-text-gray-600 rf-whitespace-pre-wrap rf-overflow-x-auto",children:JSON.stringify(o.solverParams,null,2)})})]})]}):W.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:W.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},yEe=({errorMessage:t,errorStack:A,circuitJsonErrors:e})=>{V.useEffect(()=>{if(t){const i=new Error(t);A&&(i.stack=A);try{qW.captureException(i)}catch{}}},[t,A]),V.useEffect(()=>{if(e&&e.length>0)for(const i of e){const n=new Error(i.message||"Circuit JSON Error");i.stack&&(n.stack=i.stack);try{qW.captureException(n,{error_type:i.type})}catch{}}},[e])},mEe="0.0.1749",Gni={version:mEe},Jz=M4A()(R4A(t=>({lastRunEvalVersion:void 0,setLastRunEvalVersion:A=>{t({lastRunEvalVersion:A})}}),{name:"runframe-runner-store"})),Lni=t=>{const[A,e]=V.useState([]),[i,n]=V.useState(null),[o,s]=V.useState(""),[r,a]=cG("eval-version-selection",null),g=Jz(B=>B.setLastRunEvalVersion),c=Jz(B=>B.lastRunEvalVersion);return V.useEffect(()=>{t&&fetch("https://data.jsdelivr.com/v1/package/npm/@tscircuit/eval").then(B=>B.json()).then(B=>{if(Array.isArray(B?.versions)){let C=[...B.versions];B.tags?.latest&&(n(B.tags.latest),C=C.filter(Q=>Q!==B.tags.latest)),e(C)}}).catch(()=>{})},[t]),V.useEffect(()=>{t&&(r?(window.TSCIRCUIT_LATEST_EVAL_VERSION=r,g(r)):i&&(window.TSCIRCUIT_LATEST_EVAL_VERSION=i,g(i)))},[t,r,i]),{versions:V.useMemo(()=>A.filter(B=>B.includes(o)).slice(0,50),[A,o]),latestVersion:i,lastRunEvalVersion:c,search:o,setSearch:s,selectVersion:B=>{a(B),s("")}}},Uni=({snippetNames:t,onSelect:A,onCancel:e,isOpen:i})=>{const[n,o]=V.useState(""),[s,r]=V.useState("");if(!i)return null;const a=t.filter(I=>I.toLowerCase().includes(s.toLowerCase())),g=s&&!t.includes(s),c=I=>{I.key==="Enter"&&(a.length===1?o(a[0]):g&&o(s))};return W.jsx("div",{className:"rf-fixed rf-inset-0 rf-bg-black rf-bg-opacity-50 rf-flex rf-items-center rf-justify-center rf-z-[100]",children:W.jsxs("div",{className:"rf-bg-white rf-rounded-lg rf-p-6 rf-w-96",children:[W.jsx("h2",{className:"rf-text-lg rf-font-semibold rf-mb-4",children:"Select Snippet"}),W.jsx("input",{type:"text",className:"rf-w-full rf-px-4 rf-py-2 rf-border rf-rounded rf-mb-4",placeholder:"Search snippets or new snippet name...",value:s,onChange:I=>r(I.target.value),onKeyDown:c}),W.jsxs("div",{className:"rf-h-60 rf-overflow-y-auto",children:[a.map(I=>W.jsx("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 ${n===I?"bg-blue-50":""}`,onClick:()=>o(I),children:I},I)),g&&W.jsxs("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 text-blue-500 ${n===s?"bg-blue-50":""}`,onClick:()=>o(s),children:['Create new "',s,'"']})]}),W.jsxs("div",{className:"rf-mt-4 rf-flex rf-justify-end rf-gap-2",children:[W.jsx("button",{type:"button",className:"rf-px-4 rf-py-2 rf-text-gray-600 rf-hover:text-gray-800",onClick:e,children:"Cancel"}),W.jsx("button",{type:"button",className:"rf-px-4 rf-py-2 rf-bg-blue-500 rf-text-white rf-rounded rf-hover:bg-blue-600 rf-disabled:opacity-50",onClick:()=>n&&A(n),disabled:!n,children:n===s?`Create "${n}"`:`Save to ${n}`})]})]})})},Hni=t=>{const A=V.useRef(null),e=MI(i=>i.recentEvents);V.useEffect(()=>{if(e.length===0)return;const i=e[0];i.event_id!==A.current&&(t(i),A.current=i.event_id)},[e,t])};function Yni(t){const A=Jni(t),e=V.forwardRef((i,n)=>{const{children:o,...s}=i,r=V.Children.toArray(o),a=r.find(Pni);if(a){const g=a.props.children,c=r.map(I=>I===a?V.Children.count(g)>1?V.Children.only(null):V.isValidElement(g)?g.props.children:null:I);return W.jsx(A,{...s,ref:n,children:V.isValidElement(g)?V.cloneElement(g,void 0,c):null})}return W.jsx(A,{...s,ref:n,children:o})});return e.displayName=`${t}.Slot`,e}function Jni(t){const A=V.forwardRef((e,i)=>{const{children:n,...o}=e;if(V.isValidElement(n)){const s=qni(n),r=Kni(o,n.props);return n.type!==V.Fragment&&(r.ref=i?_f(i,s):s),V.cloneElement(n,r)}return V.Children.count(n)>1?V.Children.only(null):null});return A.displayName=`${t}.SlotClone`,A}var Tni=Symbol("radix.slottable");function Pni(t){return V.isValidElement(t)&&typeof t.type=="function"&&"__radixId"in t.type&&t.type.__radixId===Tni}function Kni(t,A){const e={...A};for(const i in A){const n=t[i],o=A[i];/^on[A-Z]/.test(i)?n&&o?e[i]=(...r)=>{const a=o(...r);return n(...r),a}:n&&(e[i]=n):i==="style"?e[i]={...n,...o}:i==="className"&&(e[i]=[n,o].filter(Boolean).join(" "))}return{...t,...e}}function qni(t){let A=Object.getOwnPropertyDescriptor(t.props,"ref")?.get,e=A&&"isReactWarning"in A&&A.isReactWarning;return e?t.ref:(A=Object.getOwnPropertyDescriptor(t,"ref")?.get,e=A&&"isReactWarning"in A&&A.isReactWarning,e?t.props.ref:t.props.ref||t.ref)}var Tz="Dialog",[wEe,DEe]=dw(Tz),[Oni,Ow]=wEe(Tz),SEe=t=>{const{__scopeDialog:A,children:e,open:i,defaultOpen:n,onOpenChange:o,modal:s=!0}=t,r=V.useRef(null),a=V.useRef(null),[g,c]=G_({prop:i,defaultProp:n??!1,onChange:o,caller:Tz});return W.jsx(Oni,{scope:A,triggerRef:r,contentRef:a,contentId:qE(),titleId:qE(),descriptionId:qE(),open:g,onOpenChange:c,onOpenToggle:V.useCallback(()=>c(I=>!I),[c]),modal:s,children:e})};SEe.displayName=Tz;var bEe="DialogTrigger",xEe=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,n=Ow(bEe,e),o=RI(A,n.triggerRef);return W.jsx(Ag.button,{type:"button","aria-haspopup":"dialog","aria-expanded":n.open,"aria-controls":n.contentId,"data-state":GmA(n.open),...i,ref:o,onClick:Vn(t.onClick,n.onOpenToggle)})});xEe.displayName=bEe;var RmA="DialogPortal",[Wni,_Ee]=wEe(RmA,{forceMount:void 0}),kEe=t=>{const{__scopeDialog:A,forceMount:e,children:i,container:n}=t,o=Ow(RmA,A);return W.jsx(Wni,{scope:A,forceMount:e,children:V.Children.map(i,s=>W.jsx(q0,{present:e||o.open,children:W.jsx($9,{asChild:!0,container:n,children:s})}))})};kEe.displayName=RmA;var Pz="DialogOverlay",vEe=V.forwardRef((t,A)=>{const e=_Ee(Pz,t.__scopeDialog),{forceMount:i=e.forceMount,...n}=t,o=Ow(Pz,t.__scopeDialog);return o.modal?W.jsx(q0,{present:i||o.open,children:W.jsx(Vni,{...n,ref:A})}):null});vEe.displayName=Pz;var Zni=Yni("DialogOverlay.RemoveScroll"),Vni=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,n=Ow(Pz,e);return W.jsx(rj,{as:Zni,allowPinchZoom:!0,shards:[n.contentRef],children:W.jsx(Ag.div,{"data-state":GmA(n.open),...i,ref:A,style:{pointerEvents:"auto",...i.style}})})}),PM="DialogContent",FEe=V.forwardRef((t,A)=>{const e=_Ee(PM,t.__scopeDialog),{forceMount:i=e.forceMount,...n}=t,o=Ow(PM,t.__scopeDialog);return W.jsx(q0,{present:i||o.open,children:o.modal?W.jsx(jni,{...n,ref:A}):W.jsx(zni,{...n,ref:A})})});FEe.displayName=PM;var jni=V.forwardRef((t,A)=>{const e=Ow(PM,t.__scopeDialog),i=V.useRef(null),n=RI(A,e.contentRef,i);return V.useEffect(()=>{const o=i.current;if(o)return jfA(o)},[]),W.jsx(MEe,{...t,ref:n,trapFocus:e.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:Vn(t.onCloseAutoFocus,o=>{o.preventDefault(),e.triggerRef.current?.focus()}),onPointerDownOutside:Vn(t.onPointerDownOutside,o=>{const s=o.detail.originalEvent,r=s.button===0&&s.ctrlKey===!0;(s.button===2||r)&&o.preventDefault()}),onFocusOutside:Vn(t.onFocusOutside,o=>o.preventDefault())})}),zni=V.forwardRef((t,A)=>{const e=Ow(PM,t.__scopeDialog),i=V.useRef(!1),n=V.useRef(!1);return W.jsx(MEe,{...t,ref:A,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:o=>{t.onCloseAutoFocus?.(o),o.defaultPrevented||(i.current||e.triggerRef.current?.focus(),o.preventDefault()),i.current=!1,n.current=!1},onInteractOutside:o=>{t.onInteractOutside?.(o),o.defaultPrevented||(i.current=!0,o.detail.originalEvent.type==="pointerdown"&&(n.current=!0));const s=o.target;e.triggerRef.current?.contains(s)&&o.preventDefault(),o.detail.originalEvent.type==="focusin"&&n.current&&o.preventDefault()}})}),MEe=V.forwardRef((t,A)=>{const{__scopeDialog:e,trapFocus:i,onOpenAutoFocus:n,onCloseAutoFocus:o,...s}=t,r=Ow(PM,e),a=V.useRef(null),g=RI(A,a);return vfA(),W.jsxs(W.Fragment,{children:[W.jsx(Y9,{asChild:!0,loop:!0,trapped:i,onMountAutoFocus:n,onUnmountAutoFocus:o,children:W.jsx(qJ,{role:"dialog",id:r.contentId,"aria-describedby":r.descriptionId,"aria-labelledby":r.titleId,"data-state":GmA(r.open),...s,ref:g,onDismiss:()=>r.onOpenChange(!1)})}),W.jsxs(W.Fragment,{children:[W.jsx($ni,{titleId:r.titleId}),W.jsx(eoi,{contentRef:a,descriptionId:r.descriptionId})]})]})}),NmA="DialogTitle",REe=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,n=Ow(NmA,e);return W.jsx(Ag.h2,{id:n.titleId,...i,ref:A})});REe.displayName=NmA;var NEe="DialogDescription",GEe=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,n=Ow(NEe,e);return W.jsx(Ag.p,{id:n.descriptionId,...i,ref:A})});GEe.displayName=NEe;var LEe="DialogClose",UEe=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,n=Ow(LEe,e);return W.jsx(Ag.button,{type:"button",...i,ref:A,onClick:Vn(t.onClick,()=>n.onOpenChange(!1))})});UEe.displayName=LEe;function GmA(t){return t?"open":"closed"}var HEe="DialogTitleWarning",[Xni,YEe]=Kat(HEe,{contentName:PM,titleName:NmA,docsSlug:"dialog"}),$ni=({titleId:t})=>{const A=YEe(HEe),e=`\`${A.contentName}\` requires a \`${A.titleName}\` for the component to be accessible for screen reader users.
|
|
5692
|
+
`,I=new Blob([c],{type:"text/plain"}),l=URL.createObjectURL(I),B=document.createElement("a");B.href=l,B.download=`${g}.test.ts`,B.click(),URL.revokeObjectURL(l)}catch(a){alert(`Error generating test.ts for ${t.constructor.name}: ${a instanceof Error?a.message:String(a)}`)}i(!1)};return W.jsxs("div",{className:`relative ${A}`,ref:n,children:[W.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>i(!e),title:`Download options for ${t.constructor.name}`,children:t.constructor.name}),e&&W.jsxs("div",{className:"absolute top-full left-0 mt-1 bg-white border border-gray-300 rounded shadow-lg z-10 min-w-[150px]",children:[W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:o,children:"Download JSON"}),W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:r,children:"Download test.ts"})]})]})},fEe=t=>t.activeSubSolver?[t,...fEe(t.activeSubSolver)]:[t],pni=({solver:t})=>{const A=fEe(t);return W.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:A.map((e,i)=>W.jsxs("div",{className:"flex items-center",children:[i>0&&W.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),W.jsx(dni,{solver:e})]},e.constructor.name))})},fni=({solver:t,triggerRender:A,animationSpeed:e=25,onSolverStarted:i,onSolverCompleted:n})=>{const[o,s]=V.useReducer(Q=>!Q,!1),r=V.useRef(void 0),a=()=>{!t.solved&&!t.failed&&(t.step(),A())},g=()=>{!t.solved&&!t.failed&&(i&&i(t),t.solve(),A(),n&&n(t))},c=()=>{o?(r.current&&(clearInterval(r.current),r.current=void 0),s()):(s(),r.current=setInterval(()=>{if(t.solved||t.failed){r.current&&(clearInterval(r.current),r.current=void 0),s(),A(),n&&t.solved&&n(t);return}t.step(),A()},e))},I=()=>{const Q=t;if(Q.getCurrentPhase&&!t.solved&&!t.failed){const h=Q.getCurrentPhase();for(;Q.getCurrentPhase()===h&&!t.solved&&!t.failed;)t.step();A()}},l=()=>{if(t.solved||t.failed||o)return;const Q=window.prompt("Step until which iteration?",`${t.iterations}`);if(Q===null)return;const h=Number(Q);if(!Number.isFinite(h)){window.alert("Please enter a valid number for the iteration");return}for(;t.iterations<h&&!t.solved&&!t.failed;)t.step();A(),t.solved&&n&&n(t)};V.useEffect(()=>()=>{r.current&&clearInterval(r.current)},[]),V.useEffect(()=>{(t.solved||t.failed)&&o&&(r.current&&(clearInterval(r.current),r.current=void 0),s())},[t.solved,t.failed,o]);const B=t.getCurrentPhase!==void 0,C=B?t.getCurrentPhase():null;return W.jsxs("div",{className:"space-y-2 p-2 border-b",children:[W.jsx("div",{className:"flex items-center",children:W.jsx(pni,{solver:t})}),W.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[W.jsx("button",{onClick:a,disabled:t.solved||t.failed||o,className:"bg-blue-500 hover:bg-blue-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step"}),W.jsx("button",{onClick:g,disabled:t.solved||t.failed||o,className:"bg-green-500 hover:bg-green-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Solve"}),W.jsx("button",{onClick:c,disabled:t.solved||t.failed,className:`px-3 py-1 rounded text-white text-sm ${o?"bg-red-500 hover:bg-red-600":"bg-yellow-500 hover:bg-yellow-600"} disabled:bg-gray-300`,children:o?"Stop":"Animate"}),W.jsx("button",{onClick:l,disabled:t.solved||t.failed||o,className:"bg-orange-500 hover:bg-orange-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step Until Iteration"}),B&&W.jsx("button",{onClick:I,disabled:t.solved||t.failed||o,className:"bg-purple-500 hover:bg-purple-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Next Stage"}),W.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",t.iterations]}),t.timeToSolve!==void 0&&W.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(t.timeToSolve/1e3).toFixed(3),"s"]}),C&&W.jsxs("div",{className:"text-sm text-gray-600",children:["Phase: ",W.jsx("span",{className:"font-medium",children:C})]}),t.solved&&W.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),t.failed&&W.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),t.error&&W.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",t.error]})]})},yni=(t,A,e)=>{const i=t.currentPipelineStepIndex;return A<i?"Completed":A===i&&t.activeSubSolver?t.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},mni=(t,A)=>{const i=t.pipelineDef[A].solverName,n=yni(t,A),o=t[i],s=t.firstIterationOfPhase?.[i]??null,r=t.iterations;let a=0;if(n==="Completed"){const l=t.pipelineDef[A+1],B=l?t.firstIterationOfPhase?.[l.solverName]:void 0;B!==void 0&&s!==null?a=B-s:s!==null&&(a=r-s)}else n==="In Progress"&&s!==null&&(a=r-s);const g=t.timeSpentOnPhase?.[i]??0;let c=0;n==="Completed"?c=1:n==="In Progress"&&o&&(c=o.progress??0);const I=o?.stats??null;return{index:A,name:i,status:n,firstIteration:s,iterations:a,progress:c,timeSpent:g,stats:I&&Object.keys(I).length>0?I:null,solverInstance:o??null}},wni=({status:t})=>{const A={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return W.jsx("span",{className:`font-medium ${A[t]}`,children:t})},Dni=({progress:t})=>{if(t===0)return null;const A=Math.round(t*100);return W.jsxs("div",{className:"flex items-center gap-2",children:[W.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:W.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${A}%`}})}),W.jsxs("span",{className:"text-xs text-gray-500",children:[A,"%"]})]})},Sni=t=>Object.entries(t).map(([A,e])=>`${A}: ${e}`).join(", "),bni=({stats:t})=>{if(!t||Object.keys(t).length===0)return W.jsx("span",{children:"-"});const A=Object.entries(t),e=Sni(t);return W.jsxs("details",{className:"cursor-pointer",children:[W.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:e}),W.jsx("div",{className:"mt-1 text-xs",children:A.map(([i,n])=>W.jsxs("div",{children:[i,": ",String(n)]},i))})]})},MmA=t=>{if(t===null||typeof t!="object")return t;if(Array.isArray(t))return t.map(MmA);const A={};for(const[e,i]of Object.entries(t))e.startsWith("_")||(A[e]=MmA(i));return A},xni=(t,A)=>{try{if(typeof t.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${A}`);return}const e=MmA(t.getConstructorParams()),i=new Blob([JSON.stringify(e,null,2)],{type:"application/json"}),n=URL.createObjectURL(i),o=document.createElement("a");o.href=n,o.download=`${A}_input.json`,o.click(),URL.revokeObjectURL(n)}catch(e){alert(`Error downloading input for ${A}: ${e instanceof Error?e.message:String(e)}`)}},_ni=({solver:t,onStepUntilPhase:A,onDownloadInput:e})=>{const i=t.pipelineDef.map((r,a)=>mni(t,a)),n=r=>{A?.(r)},o=r=>{r.solverInstance&&(e?e(r.solverInstance,r.name):xni(r.solverInstance,r.name))},s=r=>`${(r/1e3).toFixed(2)}s`;return W.jsxs("div",{className:"border-t border-gray-200",children:[W.jsx("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200",children:W.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Steps"})}),W.jsx("div",{className:"overflow-x-auto",children:W.jsxs("table",{className:"w-full text-sm",children:[W.jsx("thead",{children:W.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Step"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),W.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",W.jsx("sub",{children:"0"})]}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),W.jsx("tbody",{children:i.map(r=>W.jsxs("tr",{className:`border-b border-gray-100 ${r.status==="In Progress"?"bg-yellow-50":""}`,children:[W.jsx("td",{className:"px-4 py-2",children:W.jsxs("div",{className:"flex items-center gap-2",children:[W.jsx("span",{className:"text-gray-400 w-6",children:String(r.index+1).padStart(2,"0")}),W.jsx("button",{onClick:()=>n(r.name),disabled:r.status==="Completed"||t.solved||t.failed,className:"text-blue-500 hover:text-blue-700 disabled:text-gray-300 disabled:cursor-not-allowed",title:`Step until ${r.name} completes`,children:W.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:W.jsx("path",{fillRule:"evenodd",d:"M4.5 5.653c0-1.426 1.529-2.33 2.779-1.643l11.54 6.348c1.295.712 1.295 2.573 0 3.285L7.28 19.991c-1.25.687-2.779-.217-2.779-1.643V5.653z",clipRule:"evenodd"})})}),W.jsx("span",{className:"font-medium text-gray-900",children:r.name})]})}),W.jsx("td",{className:"px-4 py-2",children:W.jsx(wni,{status:r.status})}),W.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:r.firstIteration!==null?r.firstIteration:""}),W.jsx("td",{className:"px-4 py-2 text-gray-600",children:r.iterations}),W.jsx("td",{className:"px-4 py-2",children:W.jsx(Dni,{progress:r.progress})}),W.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(r.timeSpent)}),W.jsx("td",{className:"px-4 py-2 text-gray-500",children:W.jsx(bni,{stats:r.stats})}),W.jsx("td",{className:"px-4 py-2",children:r.solverInstance?W.jsxs("button",{onClick:()=>o(r),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${r.name}`,children:[W.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:W.jsx("path",{fillRule:"evenodd",d:"M12 2.25a.75.75 0 01.75.75v11.69l3.22-3.22a.75.75 0 111.06 1.06l-4.5 4.5a.75.75 0 01-1.06 0l-4.5-4.5a.75.75 0 111.06-1.06l3.22 3.22V3a.75.75 0 01.75-.75zm-9 13.5a.75.75 0 01.75.75v2.25a1.5 1.5 0 001.5 1.5h13.5a1.5 1.5 0 001.5-1.5V16.5a.75.75 0 011.5 0v2.25a3 3 0 01-3 3H5.25a3 3 0 01-3-3V16.5a.75.75 0 01.75-.75z",clipRule:"evenodd"})}),W.jsx("span",{children:"Input"})]}):null})]},r.name))})]})})]})},kni=class extends Qn.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 vni({graphics:t}){const A=t.points??[],e=t.lines??[],i=t.rects??[],n=t.circles??[],o=t.texts??[];let s=Number.POSITIVE_INFINITY,r=Number.POSITIVE_INFINITY,a=Number.NEGATIVE_INFINITY,g=Number.NEGATIVE_INFINITY;const c=(h,E)=>{typeof h=="number"&&(h<s&&(s=h),h>a&&(a=h)),typeof E=="number"&&(E<r&&(r=E),E>g&&(g=E))};for(const h of A)c(h.x,h.y);for(const h of e){const E=h.points??[];for(const u of E)c(u.x,u.y)}for(const h of i){const E=h.x??0,u=h.y??0,d=h.width??0,f=h.height??0;c(E,u),c(E+d,u+f)}for(const h of n){const E=h.x??0,u=h.y??0,d=h.radius??1;c(E-d,u-d),c(E+d,u+d)}for(const h of o)c(h.x,h.y);(!isFinite(s)||!isFinite(r)||!isFinite(a)||!isFinite(g))&&(s=-20,r=-20,a=20,g=20);const I=10,l=s-I,B=r-I,C=Math.max(1,a-s+2*I),Q=Math.max(1,g-r+2*I);return W.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${l} ${B} ${C} ${Q}`,role:"img","aria-label":"Graphics fallback",children:[i.map((h,E)=>W.jsx("rect",{x:h.x??0,y:h.y??0,width:h.width??0,height:h.height??0,fill:"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1},`rect-${E}`)),e.map((h,E)=>W.jsx("polyline",{fill:"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1,points:(h.points??[]).map(u=>`${u.x??0},${u.y??0}`).join(" ")},`line-${E}`)),n.map((h,E)=>W.jsx("circle",{cx:h.x??0,cy:h.y??0,r:h.radius??1.5,fill:h.fillColor??"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1},`circle-${E}`)),A.map((h,E)=>W.jsx("circle",{cx:h.x??0,cy:h.y??0,r:h.radius??1.5,fill:h.color??"black"},`point-${E}`)),o.map((h,E)=>W.jsx("text",{x:h.x??0,y:h.y??0,fontSize:h.fontSize??10,fill:h.color??"black",children:h.text??""},`text-${E}`))]})}var Fni=({solver:t,animationSpeed:A=25,onSolverStarted:e,onSolverCompleted:i})=>{const[n,o]=V.useReducer(c=>c+1,0),s=V.useMemo(()=>{try{return t.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(c){return console.error("Visualization error:",c),{points:[],lines:[],rects:[],circles:[]}}},[t,n]),r=V.useMemo(()=>(s.rects?.length||0)===0&&(s.lines?.length||0)===0&&(s.points?.length||0)===0&&(s.circles?.length||0)===0,[s]);V.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const c=document.createElement("script");c.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(c)}},[]);const a=t.pipelineDef!==void 0,g=c=>{const I=t;if(!t.solved&&!t.failed){for(;!t.solved&&!t.failed&&I.currentPipelineStepIndex<=I.pipelineDef.findIndex(l=>l.solverName===c);)t.step();o()}};return W.jsxs("div",{children:[W.jsx(fni,{solver:t,triggerRender:o,animationSpeed:A,onSolverStarted:e,onSolverCompleted:i}),r?W.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):W.jsx(kni,{fallback:W.jsx(vni,{graphics:s}),children:W.jsx(uni,{graphics:s})}),a&&W.jsx(_ni,{solver:t,onStepUntilPhase:g})]})};const Mni=()=>{V.useEffect(()=>{const t="tailwind-cdn-script";if(document.getElementById(t)||window.tailwind)return;const A=document.createElement("div");A.className="hidden",document.body.appendChild(A);const e=window.getComputedStyle(A).display==="none";if(document.body.removeChild(A),e)return;const i=document.createElement("script");i.id=t,i.src="https://cdn.tailwindcss.com",document.head.appendChild(i)},[])},Rni=t=>t.toLowerCase().includes("pack")?yqt:t.toLowerCase().includes("rout")?bqt:rqt,Nni=({solverEvents:t=[]})=>{const[A,e]=V.useState(null);Mni();const i=V.useMemo(()=>{const r=new Map;for(const a of t){const g=`${a.componentName}-${a.solverName}`;r.set(g,a)}return r},[t]),n=V.useMemo(()=>Array.from(i.keys()),[i]),o=A?i.get(A):null,s=V.useMemo(()=>{if(!o)return{instance:null,error:null,classFound:!1};const r=WrA[o.solverName];if(!r)return{instance:null,error:`Solver class "${o.solverName}" not found in SOLVERS registry. Available: ${Object.keys(WrA).join(", ")}`,classFound:!1};try{const a=o.solverParams,g=a?.input!==void 0?a.input:a;return{instance:new r(g),error:null,classFound:!0}}catch(a){const g=a instanceof Error?a.message:String(a);return console.error("Failed to reconstruct solver:",a),{instance:null,error:`Failed to instantiate solver: ${g}`,classFound:!0}}},[o]);return t.length===0?W.jsx("div",{className:"rf-p-4",children:W.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:W.jsxs("div",{className:"rf-p-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),W.jsx("p",{className:"rf-text-sm rf-text-gray-600",children:"Solvers will appear here when the circuit runs. Solvers are used for tasks like component packing and autorouting."})]})})}):W.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[W.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[W.jsxs("div",{className:"rf-text-xs rf-font-semibold rf-text-gray-500 rf-px-3 rf-py-2 rf-bg-gray-50 rf-border-b rf-border-gray-200",children:[n.length," ",n.length===1?"Solver":"Solvers"]}),n.map(r=>{const a=i.get(r),g=A===r;return W.jsx("div",{className:`rf-px-3 rf-py-2 rf-cursor-pointer rf-border-b rf-border-gray-100 ${g?"rf-bg-blue-50 rf-border-l-2 rf-border-l-blue-500":"hover:rf-bg-gray-50"}`,onClick:()=>e(r),children:(()=>{const c=Rni(a.solverName);return W.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[W.jsx(c,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),W.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[W.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:a.componentName}),W.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:a.solverName})]})]})})()},r)})]}),W.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:o?s.instance?W.jsx(Dm,{fallback:W.jsx("div",{className:"rf-p-4",children:W.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),W.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",o.solverName]})]})}),children:W.jsx(Fni,{solver:s.instance})}):W.jsxs("div",{className:"rf-p-4",children:[W.jsxs("div",{className:"rf-mb-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:o.solverName}),W.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",o.componentName]})]}),s.error&&W.jsx("div",{className:`rf-rounded-md rf-border rf-p-4 rf-mb-4 ${s.classFound?"rf-bg-red-50 rf-border-red-200":"rf-bg-yellow-50 rf-border-yellow-200"}`,children:W.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),W.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[W.jsx("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50",children:W.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"})}),W.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:W.jsx("pre",{className:"rf-text-xs rf-font-mono rf-text-gray-600 rf-whitespace-pre-wrap rf-overflow-x-auto",children:JSON.stringify(o.solverParams,null,2)})})]})]}):W.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:W.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},yEe=({errorMessage:t,errorStack:A,circuitJsonErrors:e})=>{V.useEffect(()=>{if(t){const i=new Error(t);A&&(i.stack=A);try{qW.captureException(i)}catch{}}},[t,A]),V.useEffect(()=>{if(e&&e.length>0)for(const i of e){const n=new Error(i.message||"Circuit JSON Error");i.stack&&(n.stack=i.stack);try{qW.captureException(n,{error_type:i.type})}catch{}}},[e])},mEe="0.0.1751",Gni={version:mEe},Jz=M4A()(R4A(t=>({lastRunEvalVersion:void 0,setLastRunEvalVersion:A=>{t({lastRunEvalVersion:A})}}),{name:"runframe-runner-store"})),Lni=t=>{const[A,e]=V.useState([]),[i,n]=V.useState(null),[o,s]=V.useState(""),[r,a]=cG("eval-version-selection",null),g=Jz(B=>B.setLastRunEvalVersion),c=Jz(B=>B.lastRunEvalVersion);return V.useEffect(()=>{t&&fetch("https://data.jsdelivr.com/v1/package/npm/@tscircuit/eval").then(B=>B.json()).then(B=>{if(Array.isArray(B?.versions)){let C=[...B.versions];B.tags?.latest&&(n(B.tags.latest),C=C.filter(Q=>Q!==B.tags.latest)),e(C)}}).catch(()=>{})},[t]),V.useEffect(()=>{t&&(r?(window.TSCIRCUIT_LATEST_EVAL_VERSION=r,g(r)):i&&(window.TSCIRCUIT_LATEST_EVAL_VERSION=i,g(i)))},[t,r,i]),{versions:V.useMemo(()=>A.filter(B=>B.includes(o)).slice(0,50),[A,o]),latestVersion:i,lastRunEvalVersion:c,search:o,setSearch:s,selectVersion:B=>{a(B),s("")}}},Uni=({snippetNames:t,onSelect:A,onCancel:e,isOpen:i})=>{const[n,o]=V.useState(""),[s,r]=V.useState("");if(!i)return null;const a=t.filter(I=>I.toLowerCase().includes(s.toLowerCase())),g=s&&!t.includes(s),c=I=>{I.key==="Enter"&&(a.length===1?o(a[0]):g&&o(s))};return W.jsx("div",{className:"rf-fixed rf-inset-0 rf-bg-black rf-bg-opacity-50 rf-flex rf-items-center rf-justify-center rf-z-[100]",children:W.jsxs("div",{className:"rf-bg-white rf-rounded-lg rf-p-6 rf-w-96",children:[W.jsx("h2",{className:"rf-text-lg rf-font-semibold rf-mb-4",children:"Select Snippet"}),W.jsx("input",{type:"text",className:"rf-w-full rf-px-4 rf-py-2 rf-border rf-rounded rf-mb-4",placeholder:"Search snippets or new snippet name...",value:s,onChange:I=>r(I.target.value),onKeyDown:c}),W.jsxs("div",{className:"rf-h-60 rf-overflow-y-auto",children:[a.map(I=>W.jsx("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 ${n===I?"bg-blue-50":""}`,onClick:()=>o(I),children:I},I)),g&&W.jsxs("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 text-blue-500 ${n===s?"bg-blue-50":""}`,onClick:()=>o(s),children:['Create new "',s,'"']})]}),W.jsxs("div",{className:"rf-mt-4 rf-flex rf-justify-end rf-gap-2",children:[W.jsx("button",{type:"button",className:"rf-px-4 rf-py-2 rf-text-gray-600 rf-hover:text-gray-800",onClick:e,children:"Cancel"}),W.jsx("button",{type:"button",className:"rf-px-4 rf-py-2 rf-bg-blue-500 rf-text-white rf-rounded rf-hover:bg-blue-600 rf-disabled:opacity-50",onClick:()=>n&&A(n),disabled:!n,children:n===s?`Create "${n}"`:`Save to ${n}`})]})]})})},Hni=t=>{const A=V.useRef(null),e=MI(i=>i.recentEvents);V.useEffect(()=>{if(e.length===0)return;const i=e[0];i.event_id!==A.current&&(t(i),A.current=i.event_id)},[e,t])};function Yni(t){const A=Jni(t),e=V.forwardRef((i,n)=>{const{children:o,...s}=i,r=V.Children.toArray(o),a=r.find(Pni);if(a){const g=a.props.children,c=r.map(I=>I===a?V.Children.count(g)>1?V.Children.only(null):V.isValidElement(g)?g.props.children:null:I);return W.jsx(A,{...s,ref:n,children:V.isValidElement(g)?V.cloneElement(g,void 0,c):null})}return W.jsx(A,{...s,ref:n,children:o})});return e.displayName=`${t}.Slot`,e}function Jni(t){const A=V.forwardRef((e,i)=>{const{children:n,...o}=e;if(V.isValidElement(n)){const s=qni(n),r=Kni(o,n.props);return n.type!==V.Fragment&&(r.ref=i?_f(i,s):s),V.cloneElement(n,r)}return V.Children.count(n)>1?V.Children.only(null):null});return A.displayName=`${t}.SlotClone`,A}var Tni=Symbol("radix.slottable");function Pni(t){return V.isValidElement(t)&&typeof t.type=="function"&&"__radixId"in t.type&&t.type.__radixId===Tni}function Kni(t,A){const e={...A};for(const i in A){const n=t[i],o=A[i];/^on[A-Z]/.test(i)?n&&o?e[i]=(...r)=>{const a=o(...r);return n(...r),a}:n&&(e[i]=n):i==="style"?e[i]={...n,...o}:i==="className"&&(e[i]=[n,o].filter(Boolean).join(" "))}return{...t,...e}}function qni(t){let A=Object.getOwnPropertyDescriptor(t.props,"ref")?.get,e=A&&"isReactWarning"in A&&A.isReactWarning;return e?t.ref:(A=Object.getOwnPropertyDescriptor(t,"ref")?.get,e=A&&"isReactWarning"in A&&A.isReactWarning,e?t.props.ref:t.props.ref||t.ref)}var Tz="Dialog",[wEe,DEe]=dw(Tz),[Oni,Ow]=wEe(Tz),SEe=t=>{const{__scopeDialog:A,children:e,open:i,defaultOpen:n,onOpenChange:o,modal:s=!0}=t,r=V.useRef(null),a=V.useRef(null),[g,c]=G_({prop:i,defaultProp:n??!1,onChange:o,caller:Tz});return W.jsx(Oni,{scope:A,triggerRef:r,contentRef:a,contentId:qE(),titleId:qE(),descriptionId:qE(),open:g,onOpenChange:c,onOpenToggle:V.useCallback(()=>c(I=>!I),[c]),modal:s,children:e})};SEe.displayName=Tz;var bEe="DialogTrigger",xEe=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,n=Ow(bEe,e),o=RI(A,n.triggerRef);return W.jsx(Ag.button,{type:"button","aria-haspopup":"dialog","aria-expanded":n.open,"aria-controls":n.contentId,"data-state":GmA(n.open),...i,ref:o,onClick:Vn(t.onClick,n.onOpenToggle)})});xEe.displayName=bEe;var RmA="DialogPortal",[Wni,_Ee]=wEe(RmA,{forceMount:void 0}),kEe=t=>{const{__scopeDialog:A,forceMount:e,children:i,container:n}=t,o=Ow(RmA,A);return W.jsx(Wni,{scope:A,forceMount:e,children:V.Children.map(i,s=>W.jsx(q0,{present:e||o.open,children:W.jsx($9,{asChild:!0,container:n,children:s})}))})};kEe.displayName=RmA;var Pz="DialogOverlay",vEe=V.forwardRef((t,A)=>{const e=_Ee(Pz,t.__scopeDialog),{forceMount:i=e.forceMount,...n}=t,o=Ow(Pz,t.__scopeDialog);return o.modal?W.jsx(q0,{present:i||o.open,children:W.jsx(Vni,{...n,ref:A})}):null});vEe.displayName=Pz;var Zni=Yni("DialogOverlay.RemoveScroll"),Vni=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,n=Ow(Pz,e);return W.jsx(rj,{as:Zni,allowPinchZoom:!0,shards:[n.contentRef],children:W.jsx(Ag.div,{"data-state":GmA(n.open),...i,ref:A,style:{pointerEvents:"auto",...i.style}})})}),PM="DialogContent",FEe=V.forwardRef((t,A)=>{const e=_Ee(PM,t.__scopeDialog),{forceMount:i=e.forceMount,...n}=t,o=Ow(PM,t.__scopeDialog);return W.jsx(q0,{present:i||o.open,children:o.modal?W.jsx(jni,{...n,ref:A}):W.jsx(zni,{...n,ref:A})})});FEe.displayName=PM;var jni=V.forwardRef((t,A)=>{const e=Ow(PM,t.__scopeDialog),i=V.useRef(null),n=RI(A,e.contentRef,i);return V.useEffect(()=>{const o=i.current;if(o)return jfA(o)},[]),W.jsx(MEe,{...t,ref:n,trapFocus:e.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:Vn(t.onCloseAutoFocus,o=>{o.preventDefault(),e.triggerRef.current?.focus()}),onPointerDownOutside:Vn(t.onPointerDownOutside,o=>{const s=o.detail.originalEvent,r=s.button===0&&s.ctrlKey===!0;(s.button===2||r)&&o.preventDefault()}),onFocusOutside:Vn(t.onFocusOutside,o=>o.preventDefault())})}),zni=V.forwardRef((t,A)=>{const e=Ow(PM,t.__scopeDialog),i=V.useRef(!1),n=V.useRef(!1);return W.jsx(MEe,{...t,ref:A,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:o=>{t.onCloseAutoFocus?.(o),o.defaultPrevented||(i.current||e.triggerRef.current?.focus(),o.preventDefault()),i.current=!1,n.current=!1},onInteractOutside:o=>{t.onInteractOutside?.(o),o.defaultPrevented||(i.current=!0,o.detail.originalEvent.type==="pointerdown"&&(n.current=!0));const s=o.target;e.triggerRef.current?.contains(s)&&o.preventDefault(),o.detail.originalEvent.type==="focusin"&&n.current&&o.preventDefault()}})}),MEe=V.forwardRef((t,A)=>{const{__scopeDialog:e,trapFocus:i,onOpenAutoFocus:n,onCloseAutoFocus:o,...s}=t,r=Ow(PM,e),a=V.useRef(null),g=RI(A,a);return vfA(),W.jsxs(W.Fragment,{children:[W.jsx(Y9,{asChild:!0,loop:!0,trapped:i,onMountAutoFocus:n,onUnmountAutoFocus:o,children:W.jsx(qJ,{role:"dialog",id:r.contentId,"aria-describedby":r.descriptionId,"aria-labelledby":r.titleId,"data-state":GmA(r.open),...s,ref:g,onDismiss:()=>r.onOpenChange(!1)})}),W.jsxs(W.Fragment,{children:[W.jsx($ni,{titleId:r.titleId}),W.jsx(eoi,{contentRef:a,descriptionId:r.descriptionId})]})]})}),NmA="DialogTitle",REe=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,n=Ow(NmA,e);return W.jsx(Ag.h2,{id:n.titleId,...i,ref:A})});REe.displayName=NmA;var NEe="DialogDescription",GEe=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,n=Ow(NEe,e);return W.jsx(Ag.p,{id:n.descriptionId,...i,ref:A})});GEe.displayName=NEe;var LEe="DialogClose",UEe=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,n=Ow(LEe,e);return W.jsx(Ag.button,{type:"button",...i,ref:A,onClick:Vn(t.onClick,()=>n.onOpenChange(!1))})});UEe.displayName=LEe;function GmA(t){return t?"open":"closed"}var HEe="DialogTitleWarning",[Xni,YEe]=Kat(HEe,{contentName:PM,titleName:NmA,docsSlug:"dialog"}),$ni=({titleId:t})=>{const A=YEe(HEe),e=`\`${A.contentName}\` requires a \`${A.titleName}\` for the component to be accessible for screen reader users.
|
|
5693
5693
|
|
|
5694
5694
|
If you want to hide the \`${A.titleName}\`, you can wrap it with our VisuallyHidden component.
|
|
5695
5695
|
|