@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.
@@ -5149,7 +5149,7 @@ ${a.join(`
5149
5149
  ${Q}polygon: ${C.polygon.vertices}
5150
5150
  `:a+=`
5151
5151
  `,C.children.length>0&&c.push(C.children)}return a}};A.exports=s}}),r_e=at({"node_modules/@jscad/modeling/src/operations/booleans/trees/Tree.js"(e,A){var t=i_e(),i=s_e(),n=class{constructor(o){this.polygonTree=new i,this.rootnode=new t(null),o&&this.addPolygons(o)}invert(){this.polygonTree.invert(),this.rootnode.invert()}clipTo(o,s=!1){this.rootnode.clipTo(o,s)}allPolygons(){const o=[];return this.polygonTree.getPolygons(o),o}addPolygons(o){const s=new Array(o.length);for(let r=0;r<o.length;r++)s[r]=this.polygonTree.addChild(o[r]);this.rootnode.addPolygonTreeNodes(s)}clear(){this.polygonTree.clear()}toString(){return"Tree: "+this.polygonTree.toString("")}};A.exports=n}}),TuA=at({"node_modules/@jscad/modeling/src/operations/booleans/trees/index.js"(e,A){A.exports={Tree:r_e()}}}),a_e=at({"node_modules/@jscad/modeling/src/operations/booleans/intersectGeom3Sub.js"(e,A){var t=As(),i=JuA(),{Tree:n}=TuA(),o=(s,r)=>{if(!i(s,r))return t.create();const a=new n(t.toPolygons(s)),g=new n(t.toPolygons(r));a.invert(),g.clipTo(a),g.invert(),a.clipTo(g),g.clipTo(a),a.addPolygons(g.allPolygons()),a.invert();const c=a.allPolygons();return t.create(c)};A.exports=o}}),wtt=at({"node_modules/@jscad/modeling/src/operations/booleans/intersectGeom3.js"(e,A){var t=ko(),i=UY(),n=a_e(),o=(...s)=>{s=t(s);let r=s.shift();return s.forEach(a=>{r=n(r,a)}),r=i(r),r};A.exports=o}}),g_e=at({"node_modules/@jscad/modeling/src/operations/booleans/intersectGeom2.js"(e,A){var t=ko(),i=As(),n=sk(),o=HuA(),s=YuA(),r=wtt(),a=(...g)=>{g=t(g);const c=g.map(B=>s({z0:-1,z1:1},B)),I=r(c),l=n(I);return o(l,i.toPolygons(I))};A.exports=a}}),c_e=at({"node_modules/@jscad/modeling/src/operations/booleans/intersect.js"(e,A){var t=ko(),i=LY(),n=os(),o=As(),s=g_e(),r=wtt(),a=(...g)=>{if(g=t(g),g.length===0)throw new Error("wrong number of arguments");if(!i(g))throw new Error("only intersect of the types are supported");const c=g[0];return n.isA(c)?s(g):o.isA(c)?r(g):c};A.exports=a}}),PuA=at({"node_modules/@jscad/modeling/src/operations/hulls/hullPoints3.js"(e,A){var t=tr(),i=_At(),n=o=>i(o,{skipTriangulation:!0}).map(a=>{const g=a.map(c=>o[c]);return t.create(g)});A.exports=n}}),Dtt=at({"node_modules/@jscad/modeling/src/operations/booleans/unionGeom3Sub.js"(e,A){var t=As(),i=JuA(),{Tree:n}=TuA(),o=(r,a)=>{if(!i(r,a))return s(r,a);const g=new n(t.toPolygons(r)),c=new n(t.toPolygons(a));g.clipTo(c,!1),c.clipTo(g),c.invert(),c.clipTo(g),c.invert();const I=g.allPolygons().concat(c.allPolygons());return t.create(I)},s=(r,a)=>{let g=t.toPolygons(r);return g=g.concat(t.toPolygons(a)),t.create(g)};A.exports=o}}),KuA=at({"node_modules/@jscad/modeling/src/operations/booleans/unionGeom3.js"(e,A){var t=ko(),i=UY(),n=Dtt(),o=(...s)=>{s=t(s);let r;for(r=1;r<s.length;r+=2)s.push(n(s[r-1],s[r]));let a=s[r-1];return a=i(a),a};A.exports=o}}),Stt=at({"node_modules/@jscad/modeling/src/operations/minkowski/minkowskiSum.js"(e,A){var t=ko(),i=As(),n=tr(),o=PuA(),s=KuA(),r=(...B)=>{if(B=t(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,m=0;for(let F=0;F<u.length;F++)d+=u[F][0],f+=u[F][1],m+=u[F][2];d/=u.length,f/=u.length,m/=u.length;const w=n.plane(E),D=w[0],S=w[1],_=w[2],b=.1,R=[d-D*b,f-S*b,m-_*b];for(let F=1;F<u.length-1;F++){const H=u[0],Y=u[F],J=u[F+1],O=c(R,H,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 m=0;m<h.length;m++){const w=h[m];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],m=`${f[0]},${f[1]},${f[2]}`;C.has(m)||(C.add(m),Q.push(f))}}return Q};A.exports=r}}),I_e=at({"node_modules/@jscad/modeling/src/operations/booleans/scissionGeom3.js"(e,A){var t=bn(),i=sk(),n=As(),o=g=>g.sort((c,I)=>c-I).filter((c,I,l)=>!I||c!==l[I-1]),s=(g,c,I)=>{const l=`${c}`,B=g.get(l);B===void 0?g.set(l,[I]):B.push(I)},r=(g,c)=>{const I=`${c}`;return g.get(I)},a=g=>{const c=i(g),I=n.toPolygons(g),l=I.length,B=new Map,C=t.create();I.forEach((d,f)=>{d.vertices.forEach(m=>{s(B,t.snap(C,m,c),f)})});const Q=I.map(d=>{let f=[];return d.vertices.forEach(m=>{f=f.concat(r(B,t.snap(C,m,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 m=new Array(l);m[d]=!0;do h=0,m.forEach((w,D)=>{const S=Q[D];if(S.e>0){S.e=-1;for(let _=0;_<S.d.length;_++)m[S.d[_]]=!0;h++}});while(h>0);f.indexes=m}}const u=[];for(let d=0;d<E;d++)if(Q[d].indexes){const f=[];Q[d].indexes.forEach((m,w)=>f.push(I[w])),u.push(n.create(f))}return u};A.exports=a}}),l_e=at({"node_modules/@jscad/modeling/src/operations/booleans/scission.js"(e,A){var t=ko(),i=As(),n=I_e(),o=(...s)=>{if(s=t(s),s.length===0)throw new Error("wrong number of arguments");const r=s.map(a=>i.isA(a)?n(a):a);return r.length===1?r[0]:r};A.exports=o}}),B_e=at({"node_modules/@jscad/modeling/src/operations/booleans/subtractGeom3Sub.js"(e,A){var t=As(),i=JuA(),{Tree:n}=TuA(),o=(s,r)=>{if(!i(s,r))return t.clone(s);const a=new n(t.toPolygons(s)),g=new n(t.toPolygons(r));a.invert(),a.clipTo(g),g.clipTo(a,!0),a.addPolygons(g.allPolygons()),a.invert();const c=a.allPolygons();return t.create(c)};A.exports=o}}),btt=at({"node_modules/@jscad/modeling/src/operations/booleans/subtractGeom3.js"(e,A){var t=ko(),i=UY(),n=B_e(),o=(...s)=>{s=t(s);let r=s.shift();return s.forEach(a=>{r=n(r,a)}),r=i(r),r};A.exports=o}}),C_e=at({"node_modules/@jscad/modeling/src/operations/booleans/subtractGeom2.js"(e,A){var t=ko(),i=As(),n=sk(),o=HuA(),s=YuA(),r=btt(),a=(...g)=>{g=t(g);const c=g.map(B=>s({z0:-1,z1:1},B)),I=r(c),l=n(I);return o(l,i.toPolygons(I))};A.exports=a}}),Q_e=at({"node_modules/@jscad/modeling/src/operations/booleans/subtract.js"(e,A){var t=ko(),i=LY(),n=os(),o=As(),s=C_e(),r=btt(),a=(...g)=>{if(g=t(g),g.length===0)throw new Error("wrong number of arguments");if(!i(g))throw new Error("only subtract of the types are supported");const c=g[0];return n.isA(c)?s(g):o.isA(c)?r(g):c};A.exports=a}}),xtt=at({"node_modules/@jscad/modeling/src/operations/booleans/unionGeom2.js"(e,A){var t=ko(),i=As(),n=sk(),o=HuA(),s=YuA(),r=KuA(),a=(...g)=>{g=t(g);const c=g.map(B=>s({z0:-1,z1:1},B)),I=r(c),l=n(I);return o(l,i.toPolygons(I))};A.exports=a}}),quA=at({"node_modules/@jscad/modeling/src/operations/booleans/union.js"(e,A){var t=ko(),i=LY(),n=os(),o=As(),s=xtt(),r=KuA(),a=(...g)=>{if(g=t(g),g.length===0)throw new Error("wrong number of arguments");if(!i(g))throw new Error("only unions of the same type are supported");const c=g[0];return n.isA(c)?s(g):o.isA(c)?r(g):c};A.exports=a}}),HY=at({"node_modules/@jscad/modeling/src/operations/booleans/index.js"(e,A){A.exports={intersect:c_e(),minkowski:Stt(),scission:l_e(),subtract:Q_e(),union:quA()}}}),eV=at({"node_modules/@jscad/modeling/src/operations/expansions/offsetFromPoints.js"(e,A){var{EPS:t,TAU:i}=Qr(),n=itt(),o=GuA(),s=_s(),r=$Z(),a=(g,c)=>{const I={delta:1,corners:"edge",closed:!1,segments:16};let{delta:l,corners:B,closed:C,segments:Q}=Object.assign({},I,g);if(Math.abs(l)<t)return c;let h=g.closed?r(c):1;h===0&&(h=1);const E=h>0&&l>=0||h<0&&l<0;l=Math.abs(l);let u=null,d=[];const f=[],m=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(m,_,b):s.subtract(m,b,_),s.normal(m,m),s.normalize(m,m),s.scale(m,m,l);const R=s.add(s.create(),_,m),F=s.add(s.create(),b,m),H=[R,F];if(u!=null&&(C||!C&&S!==0)){const Y=n(u[0],u[1],H[0],H[1]);Y?(d.pop(),H[0]=Y):f.push({c:_,s0:u,s1:H})}u=[R,F],!(S===0&&!C)&&(d.push(H[0]),d.push(H[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],R=[D,S];f.push({c:b,s0:u,s1:R})}}if(B==="edge"){const D=new Map;d.forEach((b,R)=>D.set(b,R));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 R=o.intersectPointOfLines(S,_);if(Number.isFinite(R[0])&&Number.isFinite(R[1])){const F=b.s0[1],H=D.get(F);d[H]=R,d[(H+1)%d.length]=void 0}else{const F=b.s1[0],H=D.get(F);d[H]=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 R=b/D,F=s.angle(s.subtract(S,_.s0[1],_.c)),H=[];for(let Y=1;Y<D;Y++){const J=F+R*Y,O=s.fromAngleRadians(s.create(),J);s.scale(O,O,l),s.add(O,O,_.c),H.push(O)}if(H.length>0){const Y=_.s0[1];let J=d.findIndex(O=>s.equals(Y,O));J=(J+1)%d.length,d.splice(J,0,...H)}}else{const R=_.s1[0],F=d.findIndex(H=>s.equals(R,H));d.splice(F,1)}})}return d};A.exports=a}}),h_e=at({"node_modules/@jscad/modeling/src/operations/expansions/expandGeom2.js"(e,A){var t=os(),i=eV(),n=(o,s)=>{const r={delta:1,corners:"edge",segments:16},{delta:a,corners:g,segments:c}=Object.assign({},r,o);if(!(g==="edge"||g==="chamfer"||g==="round"))throw new Error('corners must be "edge", "chamfer", or "round"');const B=t.toOutlines(s).map(C=>(o={delta:a,corners:g,closed:!0,segments:c},i(o,C))).reduce((C,Q)=>C.concat(t.toSides(t.fromPoints(Q))),[]);return t.create(B)};A.exports=n}}),E_e=at({"node_modules/@jscad/modeling/src/operations/expansions/extrudePolygon.js"(e,A){var t=$g(),i=bn(),n=As(),o=tr(),s=(r,a)=>{i.dot(o.plane(a),r)>0&&(a=o.invert(a));const c=[a],I=o.transform(t.fromTranslation(t.create(),r),a),l=a.vertices.length;for(let B=0;B<l;B++){const C=B<l-1?B+1:0,Q=o.create([a.vertices[B],I.vertices[B],I.vertices[C],a.vertices[C]]);c.push(Q)}return c.push(o.invert(I)),n.create(c)};A.exports=s}}),u_e=at({"node_modules/@jscad/modeling/src/operations/expansions/expandShell.js"(e,A){var{EPS:t,TAU:i}=Qr(),n=$g(),o=bn(),s=ytt(),r=As(),a=tr(),g=Qtt(),c=UY(),I=Dtt(),l=E_e(),B=(E,u,d)=>{const f=u.toString();if(E.has(f))E.get(f)[1].push(d);else{const m=[u,[d]];E.set(f,m)}},C=(E,u,d)=>{const f=u[0].toString(),m=u[1].toString(),w=f<m?`${f},${m}`:`${m},${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:m}=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,H)=>{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 W=F.vertices;for(let z=0;z<W.length;z++){B(D,W[z],a.plane(F));const tA=(z+1)%W.length,aA=[W[z],W[tA]];C(S,aA,a.plane(F))}}),S.forEach(F=>{const H=F[0],Y=F[1],J=H[0],O=H[1],W=o.subtract(o.create(),O,J);o.normalize(W,W);const z=Y[0],tA=o.cross(o.create(),z,W);let aA=[];for(let YA=0;YA<m;YA++)Q(aA,YA*i/m);for(let YA=0,EA=Y.length;YA<EA;YA++){const xA=Y[YA],dA=o.dot(tA,xA),WA=o.dot(z,xA);let jA=Math.atan2(dA,WA);jA<0&&(jA+=i),Q(aA,jA),jA=Math.atan2(-dA,-WA),jA<0&&(jA+=i),Q(aA,jA)}aA=aA.sort(s);const eA=aA.length;let oA,rA;const lA=[],pA=[],kA=[];for(let YA=-1;YA<eA;YA++){const EA=aA[YA<0?YA+eA:YA],xA=Math.sin(EA),dA=Math.cos(EA);o.scale(_,z,dA*f),o.scale(b,tA,xA*f),o.add(_,_,b);const WA=o.add(o.create(),J,_),jA=o.add(o.create(),O,_);let It=!1;if(YA>=0&&o.distance(WA,oA)<t&&(It=!0),!It){if(YA>=0){lA.push(WA),pA.push(jA);const mA=[rA,jA,WA,oA],gt=a.create(mA);kA.push(gt)}oA=WA,rA=jA}}pA.reverse(),kA.push(a.create(lA)),kA.push(a.create(pA));const MA=r.create(kA);w=I(w,MA)}),D.forEach(F=>{const H=F[0],Y=F[1],J=Y[0];let O=null,W=0;for(let eA=1;eA<Y.length;eA++){const oA=Y[eA],rA=o.cross(_,J,oA),lA=o.length(rA);lA>.05&&lA>W&&(W=lA,O=oA)}O||(O=o.orthogonal(_,J));const z=o.cross(_,J,O);o.normalize(z,z);const tA=o.cross(b,z,J),aA=g({center:[H[0],H[1],H[2]],radius:f,segments:m,axes:[J,z,tA]});w=I(w,aA)}),c(w)};A.exports=h}}),d_e=at({"node_modules/@jscad/modeling/src/operations/expansions/expandGeom3.js"(e,A){var t=As(),i=quA(),n=u_e(),o=(s,r)=>{const a={delta:1,corners:"round",segments:12},{delta:g,corners:c,segments:I}=Object.assign({},a,s);if(c!=="round")throw new Error('corners must be "round" for 3D geometries');if(t.toPolygons(r).length===0)throw new Error("the given geometry cannot be empty");s={delta:g,corners:c,segments:I};const B=n(s,r);return i(r,B)};A.exports=o}}),p_e=at({"node_modules/@jscad/modeling/src/operations/expansions/expandPath2.js"(e,A){var t=$Z(),i=_s(),n=os(),o=Mg(),s=eV(),r=c=>{let{external:I,internal:l}=c;t(I)<0?I=I.reverse():l=l.reverse();const B=o.fromPoints({closed:!0},I),C=o.fromPoints({closed:!0},l),Q=n.toSides(n.fromPoints(o.toPoints(B))),h=n.toSides(n.fromPoints(o.toPoints(C)));return Q.push(...h),n.create(Q)},a=(c,I,l,B)=>{const{points:C,external:Q,internal:h}=c,E=Math.floor(I/2),u=[],d=[];if(l==="round"&&E>0){const m=Math.PI/E,w=C[C.length-1],D=i.angle(i.subtract(i.create(),Q[Q.length-1],w)),S=C[0],_=i.angle(i.subtract(i.create(),h[0],S));for(let b=1;b<E;b++){let R=D+m*b,F=i.fromAngleRadians(i.create(),R);i.scale(F,F,B),i.add(F,F,w),u.push(F),R=_+m*b,F=i.fromAngleRadians(i.create(),R),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}}),OuA=at({"node_modules/@jscad/modeling/src/operations/expansions/expand.js"(e,A){var t=ko(),i=os(),n=As(),o=Mg(),s=h_e(),r=d_e(),a=p_e(),g=(c,...I)=>{if(I=t(I),I.length===0)throw new Error("wrong number of arguments");const l=I.map(B=>o.isA(B)?a(c,B):i.isA(B)?s(c,B):n.isA(B)?r(c,B):B);return l.length===1?l[0]:l};A.exports=g}}),f_e=at({"node_modules/@jscad/modeling/src/operations/expansions/offsetGeom2.js"(e,A){var t=os(),i=_uA(),n=eV(),o=(s,r)=>{const a={delta:1,corners:"edge",segments:0},{delta:g,corners:c,segments:I}=Object.assign({},a,s);if(!(c==="edge"||c==="chamfer"||c==="round"))throw new Error('corners must be "edge", "chamfer", or "round"');const l=t.toOutlines(r),C=l.map(Q=>(s={delta:l.reduce((u,d)=>u+i.arePointsInside(Q,i.create(d)),0)%2===0?g:-g,corners:c,closed:!0,segments:I},n(s,Q))).reduce((Q,h)=>Q.concat(t.toSides(t.fromPoints(h))),[]);return t.create(C)};A.exports=o}}),y_e=at({"node_modules/@jscad/modeling/src/operations/expansions/offsetPath2.js"(e,A){var t=Mg(),i=eV(),n=(o,s)=>{const r={delta:1,corners:"edge",closed:s.isClosed,segments:16},{delta:a,corners:g,closed:c,segments:I}=Object.assign({},r,o);if(!(g==="edge"||g==="chamfer"||g==="round"))throw new Error('corners must be "edge", "chamfer", or "round"');o={delta:a,corners:g,closed:c,segments:I};const l=i(o,t.toPoints(s));return t.fromPoints({closed:c},l)};A.exports=n}}),m_e=at({"node_modules/@jscad/modeling/src/operations/expansions/offset.js"(e,A){var t=ko(),i=os(),n=Mg(),o=f_e(),s=y_e(),r=(a,...g)=>{if(g=t(g),g.length===0)throw new Error("wrong number of arguments");const c=g.map(I=>n.isA(I)?s(a,I):i.isA(I)?o(a,I):I);return c.length===1?c[0]:c};A.exports=r}}),_tt=at({"node_modules/@jscad/modeling/src/operations/expansions/index.js"(e,A){A.exports={expand:OuA(),offset:m_e()}}}),iV=at({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeLinearGeom2.js"(e,A){var t=$g(),i=bn(),n=os(),o=l2(),s=tV(),r=(a,g)=>{const c={offset:[0,0,1],twistAngle:0,twistSteps:12,repair:!0};let{offset:I,twistAngle:l,twistSteps:B,repair:C}=Object.assign({},c,a);if(B<1)throw new Error("twistSteps must be 1 or more");l===0&&(B=1);const Q=i.clone(I),h=n.toSides(g);if(h.length===0)throw new Error("the given geometry cannot be empty");const E=o.fromSides(h);Q[2]<0&&o.reverse(E,E);const u=t.create(),d=(f,m,w)=>{const D=m/B*l,S=i.scale(i.create(),Q,m/B);return t.multiply(u,t.fromZRotation(u,D),t.fromTranslation(t.create(),S)),o.transform(u,w)};return a={numberOfSlices:B+1,capStart:!0,capEnd:!0,repair:C,callback:d},s(a,E)};A.exports=r}}),w_e=at({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeLinearPath2.js"(e,A){var t=os(),i=Mg(),n=iV(),o=(s,r)=>{if(!r.isClosed)throw new Error("extruded path must be closed");const a=i.toPoints(r),g=t.fromPoints(a);return n(s,g)};A.exports=o}}),D_e=at({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeLinear.js"(e,A){var t=ko(),i=os(),n=Mg(),o=iV(),s=w_e(),r=(a,...g)=>{const c={height:1,twistAngle:0,twistSteps:1,repair:!0},{height:I,twistAngle:l,twistSteps:B,repair:C}=Object.assign({},c,a);if(g=t(g),g.length===0)throw new Error("wrong number of arguments");a={offset:[0,0,I],twistAngle:l,twistSteps:B,repair:C};const Q=g.map(h=>n.isA(h)?s(a,h):i.isA(h)?o(a,h):h);return Q.length===1?Q[0]:Q};A.exports=r}}),S_e=at({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeRectangularPath2.js"(e,A){var t=Mg(),i=OuA(),n=iV(),o=(s,r)=>{const a={size:1,height:1},{size:g,height:c}=Object.assign({},a,s);if(s.delta=g,s.offset=[0,0,c],t.toPoints(r).length===0)throw new Error("the given geometry cannot be empty");const l=i(s,r);return n(s,l)};A.exports=o}}),b_e=at({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeRectangularGeom2.js"(e,A){var{area:t}=MY(),i=os(),n=Mg(),o=OuA(),s=iV(),r=(a,g)=>{const c={size:1,height:1},{size:I,height:l}=Object.assign({},c,a);a.delta=I,a.offset=[0,0,l];const B=i.toOutlines(g);if(B.length===0)throw new Error("the given geometry cannot be empty");const Q=B.map(E=>(t(E)<0&&E.reverse(),o(a,n.fromPoints({closed:!0},E)))).reduce((E,u)=>E.concat(i.toSides(u)),[]),h=i.create(Q);return s(a,h)};A.exports=r}}),x_e=at({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeRectangular.js"(e,A){var t=ko(),i=os(),n=Mg(),o=S_e(),s=b_e(),r=(a,...g)=>{const c={size:1,height:1},{size:I,height:l}=Object.assign({},c,a);if(g=t(g),g.length===0)throw new Error("wrong number of arguments");if(I<=0)throw new Error("size must be positive");if(l<=0)throw new Error("height must be positive");const B=g.map(C=>n.isA(C)?o(a,C):i.isA(C)?s(a,C):C);return B.length===1?B[0]:B};A.exports=r}}),__e=at({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeHelical.js"(e,A){var{TAU:t}=Qr(),i=$g(),n=os(),o=tV(),s=l2(),r=(a,g)=>{const c={angle:t,startAngle:0,pitch:10,height:0,endOffset:0,segmentsPerRotation:32};let{angle:I,startAngle:l,pitch:B,height:C,endOffset:Q,segmentsPerRotation:h}=Object.assign({},c,a);if(C!=0&&(B=C/(I/t)),h<3)throw new Error("The number of segments per rotation needs to be at least 3.");const u=n.toSides(g);if(u.length===0)throw new Error("The given geometry cannot be empty");const d=u.filter(b=>b[0][0]>=0);let f=s.fromSides(u);d.length===0&&(f=s.reverse(f));const m=Math.round(h/t*Math.abs(I)),w=m>=2?m:2,D=i.create(),S=i.create(),_=(b,R,F)=>{const H=l+I/w*R,Y=Q/w*R,J=(H-l)/t*B;return i.multiply(D,i.fromTranslation(i.create(),[Y,0,J*Math.sign(I)]),i.fromXRotation(i.create(),-t/4*Math.sign(I))),i.multiply(S,i.fromZRotation(i.create(),H),D),s.transform(S,F)};return o({numberOfSlices:w+1,callback:_},f)};A.exports=r}}),k_e=at({"node_modules/@jscad/modeling/src/operations/extrusions/project.js"(e,A){var t=ko(),i=MuA(),n=HD(),o=$g(),s=os(),r=As(),a=tr(),g=sk(),c=xtt(),I=(B,C)=>{const Q=n.fromNormalAndPoint(n.create(),B.axis,B.origin);if(Number.isNaN(Q[0])||Number.isNaN(Q[1])||Number.isNaN(Q[2])||Number.isNaN(Q[3]))throw new Error("project: invalid axis or origin");const h=g(C),E=h*h*Math.sqrt(3)/4;if(h===0)return s.create();const u=r.toPolygons(C);let d=[];for(let m=0;m<u.length;m++){const w=u[m].vertices.map(_=>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 m=o.fromVectorRotation(o.create(),Q,[0,0,1]);d=d.map(w=>a.transform(m,w))}d=d.sort((m,w)=>a.measureArea(w)-a.measureArea(m));const f=d.map(m=>s.fromPoints(m.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=t(C),C.length===0)throw new Error("wrong number of arguments");B={axis:h,origin:E};const u=C.map(d=>r.isA(d)?I(B,d):d);return u.length===1?u[0]:u};A.exports=l}}),YY=at({"node_modules/@jscad/modeling/src/operations/extrusions/index.js"(e,A){A.exports={extrudeFromSlices:tV(),extrudeLinear:D_e(),extrudeRectangular:x_e(),extrudeRotate:dtt(),extrudeHelical:__e(),project:k_e(),slice:l2()}}}),WuA=at({"node_modules/@jscad/modeling/src/operations/hulls/hullPoints2.js"(e,A){var t=_s(),i=s=>{let r=t.fromValues(1/0,1/0);s.forEach(c=>{(c[1]<r[1]||c[1]===r[1]&&c[0]<r[0])&&(r=c)});const a=[];s.forEach(c=>{const I=o(c[1]-r[1],c[0]-r[0]),l=t.squaredDistance(c,r);a.push({point:c,angle:I,distSq:l})}),a.sort((c,I)=>c.angle!==I.angle?c.angle-I.angle:c.distSq-I.distSq);const g=[];return a.forEach(c=>{let I=g.length;for(;I>1&&n(g[I-2],g[I-1],c.point)<=Number.EPSILON;)g.pop(),I=g.length;g.push(c.point)}),g},n=(s,r,a)=>(r[0]-s[0])*(a[1]-s[1])-(r[1]-s[1])*(a[0]-s[0]),o=(s,r)=>s===0&&r===0?-1/0:-r/s;A.exports=i}}),ZuA=at({"node_modules/@jscad/modeling/src/operations/hulls/toUniquePoints.js"(e,A){var t=os(),i=As(),n=Mg(),o=s=>{const r=new Set,a=[],g=c=>{const I=c.toString();r.has(I)||(a.push(c),r.add(I))};return s.forEach(c=>{t.isA(c)?t.toPoints(c).forEach(g):i.isA(c)?i.toPoints(c).forEach(I=>I.forEach(g)):n.isA(c)&&n.toPoints(c).forEach(g)}),a};A.exports=o}}),v_e=at({"node_modules/@jscad/modeling/src/operations/hulls/hullPath2.js"(e,A){var t=ko(),i=Mg(),n=WuA(),o=ZuA(),s=(...r)=>{r=t(r);const a=o(r),g=n(a);return i.fromPoints({closed:!0},g)};A.exports=s}}),F_e=at({"node_modules/@jscad/modeling/src/operations/hulls/hullGeom2.js"(e,A){var t=ko(),i=os(),n=WuA(),o=ZuA(),s=(...r)=>{r=t(r);const a=o(r),g=n(a);return g.length<3?i.create():i.fromPoints(g)};A.exports=s}}),M_e=at({"node_modules/@jscad/modeling/src/operations/hulls/hullGeom3.js"(e,A){var t=ko(),i=As(),n=ZuA(),o=PuA(),s=(...r)=>{r=t(r);const a=n(r);return a.length===0?i.create():i.create(o(a))};A.exports=s}}),ktt=at({"node_modules/@jscad/modeling/src/operations/hulls/hull.js"(e,A){var t=ko(),i=LY(),n=os(),o=As(),s=Mg(),r=v_e(),a=F_e(),g=M_e(),c=(...I)=>{if(I=t(I),I.length===0)throw new Error("wrong number of arguments");if(!i(I))throw new Error("only hulls of the same type are supported");const l=I[0];return s.isA(l)?r(I):n.isA(l)?a(I):o.isA(l)?g(I):l};A.exports=c}}),G_e=at({"node_modules/@jscad/modeling/src/operations/hulls/hullChain.js"(e,A){var t=ko(),i=quA(),n=ktt(),o=(...s)=>{if(s=t(s),s.length<2)throw new Error("wrong number of arguments");const r=[];for(let a=1;a<s.length;a++)r.push(n(s[a-1],s[a]));return i(r)};A.exports=o}}),R_e=at({"node_modules/@jscad/modeling/src/operations/hulls/index.js"(e,A){A.exports={hull:ktt(),hullChain:G_e(),hullPoints2:WuA(),hullPoints3:PuA()}}}),N_e=at({"node_modules/@jscad/modeling/src/operations/minkowski/index.js"(e,A){A.exports={minkowskiSum:Stt()}}}),vtt=at({"node_modules/@jscad/modeling/src/operations/modifiers/snapPolygons.js"(e,A){var t=bn(),i=tr(),n=(s,r)=>{const a=Math.abs(i.measureArea(r));return Number.isFinite(a)&&a>s},o=(s,r)=>{let a=r.map(c=>{const I=c.vertices.map(C=>t.snap(t.create(),C,s)),l=[];for(let C=0;C<I.length;C++){const Q=(C+1)%I.length;t.equals(I[C],I[Q])||l.push(I[C])}const B=i.create(l);return c.color&&(B.color=c.color),B});const g=s*s*Math.sqrt(3)/4;return a=a.filter(c=>n(g,c)),a};A.exports=o}}),L_e=at({"node_modules/@jscad/modeling/src/operations/modifiers/mergePolygons.js"(e,A){var t=MuA(),i=bn(),n=tr(),o=E=>{const u=n.toPoints(E),d=[];for(let f=0;f<u.length;f++){const m=(f+1)%u.length,w={v1:u[f],v2:u[m]};d.push(w)}for(let f=0;f<d.length;f++){const m=(f+1)%u.length;d[f].next=d[m],d[m].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,m=E.prev.v2,w=u.next.v2;const D=l(f,m,w,d);f=u.prev.v1,m=u.prev.v2,w=E.next.v2;const S=l(f,m,w,d);return[D,S]},c=i.create(),I=i.create(),l=(E,u,d,f)=>{const m=i.subtract(c,u,E),w=i.subtract(I,d,u);return i.cross(m,m,w),i.dot(m,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 R=g(_,b,u);if(R[0]>=0&&R[1]>=0){const F=b.next,H=_.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,W)=>{const z={v1:W.v1,v2:O.v2,next:O.next,prev:W.prev};W.prev.next=z,O.next.prev=z,r(J,O),O.v1=null,O.v2=null,O.next=null,O.prev=null,r(J,W),W.v1=null,W.v2=null,W.next=null,W.prev=null};R[0]===0&&Y(f,F,F.prev),R[1]===0&&Y(f,H,H.prev)}}else _.next&&s(f,_)}}const m=[];return f.forEach(w=>{const D=B(w);D&&m.push(D)}),f.clear(),m},Q=(E,u)=>Math.abs(E[3]-u[3])<15e-8?t(E,u):!1,h=(E,u)=>{const d=[];u.forEach(m=>{const w=d.find(D=>Q(D[0],n.plane(m)));w?w[1].push(m):d.push([n.plane(m),[m]])});let f=[];return d.forEach(m=>{const w=m[1],D=C(w);f=f.concat(D)}),f};A.exports=h}}),U_e=at({"node_modules/@jscad/modeling/src/operations/modifiers/insertTjunctions.js"(e,A){var t=Qr(),i=bn(),n=tr(),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 m=d[f];let w=o(m.vertex0);if(w===Q&&(w=o(m.vertex1),w===h&&!(C!==null&&m.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}`,m=`${d}/${Q}`;if(c.has(m)){const w=c.get(m);w.splice(-1,1),w.length===0&&c.delete(m)}else{const w={vertex0:C,vertex1:u,polygonindex:I};c.has(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 m=0;m<2;m++){const w=m===0?f.vertex0:f.vertex1,D=m===0?f.vertex1:f.vertex0,S=o(w),_=o(D);let b=[];m===0?l.has(S)&&(b=l.get(S)):I.has(S)&&(b=I.get(S));for(let R=0;R<b.length;R++){const F=b[R],H=c.get(F)[0],Y=m===0?H.vertex0:H.vertex1;if(m===0?H.vertex1:H.vertex0,o(Y)===_){r(c,I,l,w,D,null),r(c,I,l,D,w,null),u=!1,m=2,Q=!0;break}else{const O=w,W=D,z=Y,tA=i.subtract(i.create(),z,O),aA=i.dot(i.subtract(i.create(),W,O),tA)/i.dot(tA,tA);if(aA>0&&aA<1){const eA=i.scale(i.create(),tA,aA);if(i.add(eA,eA,O),i.squaredDistance(eA,W)<t.EPS*t.EPS){const rA=H.polygonindex,lA=C[rA],pA=o(H.vertex1);let kA=-1;for(let dA=0;dA<lA.vertices.length;dA++)if(o(lA.vertices[dA])===pA){kA=dA;break}const MA=lA.vertices.slice(0);MA.splice(kA,0,D);const YA=n.create(MA);C[rA]=YA,r(c,I,l,H.vertex0,H.vertex1,rA);const EA=s(c,I,l,H.vertex0,D,rA),xA=s(c,I,l,D,H.vertex1,rA);EA!==null&&B.set(EA,!0),xA!==null&&B.set(xA,!0),u=!1,m=2,Q=!0;break}}}}}}u&&B.delete(E)}if(!Q)break}g=C}return c.clear(),g};A.exports=a}}),H_e=at({"node_modules/@jscad/modeling/src/operations/modifiers/triangulatePolygons.js"(e,A){var t=bn(),i=tr(),n=(s,r,a)=>{const g=r.vertices.length;if(g>3){if(g>4){const l=[0,0,0];r.vertices.forEach(B=>t.add(l,l,B)),t.snap(l,t.divide(l,l,[g,g,g]),s);for(let B=0;B<g;B++){const C=i.create([l,r.vertices[B],r.vertices[(B+1)%g]]);r.color&&(C.color=r.color),a.push(C)}return}const c=i.create([r.vertices[0],r.vertices[1],r.vertices[2]]),I=i.create([r.vertices[0],r.vertices[2],r.vertices[3]]);r.color&&(c.color=r.color,I.color=r.color),a.push(c,I);return}a.push(r)},o=(s,r)=>{const a=[];return r.forEach(g=>{n(s,g,a)}),a};A.exports=o}}),Y_e=at({"node_modules/@jscad/modeling/src/operations/modifiers/generalize.js"(e,A){var t=ko(),i=sk(),n=os(),o=As(),s=Mg(),r=vtt(),a=L_e(),g=U_e(),c=H_e(),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),m=i(h);let w=o.toPolygons(h);u&&(w=r(m,w)),d&&(w=a(m,w)),f&&(w=g(w),w=c(m,w));const D=Object.assign({},h);return D.polygons=w,D},C=(Q,...h)=>{if(h=t(h),h.length===0)throw new Error("wrong number of arguments");const E=h.map(u=>{if(s.isA(u))return I(Q,u);if(n.isA(u))return l(Q,u);if(o.isA(u))return B(Q,u);throw new Error("invalid geometry")});return E.length===1?E[0]:E};A.exports=C}}),J_e=at({"node_modules/@jscad/modeling/src/operations/modifiers/snap.js"(e,A){var t=ko(),i=_s(),n=os(),o=As(),s=Mg(),r=sk(),a=vtt(),g=B=>{const C=r(B),h=s.toPoints(B).map(E=>i.snap(i.create(),E,C));return s.create(h)},c=B=>{const C=r(B);let h=n.toSides(B).map(E=>[i.snap(i.create(),E[0],C),i.snap(i.create(),E[1],C)]);return h=h.filter(E=>!i.equals(E[0],E[1])),n.create(h)},I=B=>{const C=r(B),Q=o.toPolygons(B),h=a(C,Q);return o.create(h)},l=(...B)=>{if(B=t(B),B.length===0)throw new Error("wrong number of arguments");const C=B.map(Q=>s.isA(Q)?g(Q):n.isA(Q)?c(Q):o.isA(Q)?I(Q):Q);return C.length===1?C[0]:C};A.exports=l}}),T_e=at({"node_modules/@jscad/modeling/src/operations/modifiers/index.js"(e,A){A.exports={generalize:Y_e(),snap:J_e(),retessellate:UY()}}}),P_e=at({"node_modules/@jscad/modeling/src/utils/padArrayToLength.js"(e,A){var t=(i,n,o)=>{for(i=i.slice();i.length<o;)i.push(n);return i};A.exports=t}}),K_e=at({"node_modules/@jscad/modeling/src/operations/transforms/align.js"(e,A){var t=ko(),i=P_e(),n=RuA(),{translate:o}=PF(),s=c=>{if(!Array.isArray(c.modes)||c.modes.length>3)throw new Error("align(): modes must be an array of length <= 3");if(c.modes=i(c.modes,"none",3),c.modes.filter(I=>["center","max","min","none"].includes(I)).length!==3)throw new Error('align(): all modes must be one of "center", "max" or "min"');if(!Array.isArray(c.relativeTo)||c.relativeTo.length>3)throw new Error("align(): relativeTo must be an array of length <= 3");if(c.relativeTo=i(c.relativeTo,0,3),c.relativeTo.filter(I=>Number.isFinite(I)||I==null).length!==3)throw new Error("align(): all relativeTo values must be a number, or null.");if(typeof c.grouped!="boolean")throw new Error("align(): grouped must be a boolean value.");return c},r=(c,I,l)=>{for(let B=0;B<3;B++)c[B]==null&&(I[B]==="center"?c[B]=(l[0][B]+l[1][B])/2:I[B]==="max"?c[B]=l[1][B]:I[B]==="min"&&(c[B]=l[0][B]));return c},a=(c,I,l)=>{const B=n(c),C=[0,0,0];for(let Q=0;Q<3;Q++)I[Q]==="center"?C[Q]=l[Q]-(B[0][Q]+B[1][Q])/2:I[Q]==="max"?C[Q]=l[Q]-B[1][Q]:I[Q]==="min"&&(C[Q]=l[Q]-B[0][Q]);return o(C,c)},g=(c,...I)=>{c=Object.assign({},{modes:["center","center","min"],relativeTo:[0,0,0],grouped:!1},c),c=s(c);let{modes:B,relativeTo:C,grouped:Q}=c;if(I=t(I),I.length===0)throw new Error("align(): No geometries were provided to act upon");if(C.filter(h=>h==null).length){const h=n(I);C=r(C,B,h)}return Q?I=a(I,B,C):I=I.map(h=>a(h,B,C)),I.length===1?I[0]:I};A.exports=g}}),nV=at({"node_modules/@jscad/modeling/src/operations/transforms/center.js"(e,A){var t=ko(),i=os(),n=As(),o=Mg(),s=JF(),{translate:r}=PF(),a=(B,C)=>{const Q={axes:[!0,!0,!0],relativeTo:[0,0,0]},{axes:h,relativeTo:E}=Object.assign({},Q,B),u=s(C),d=[0,0,0];return h[0]&&(d[0]=E[0]-(u[0][0]+(u[1][0]-u[0][0])/2)),h[1]&&(d[1]=E[1]-(u[0][1]+(u[1][1]-u[0][1])/2)),h[2]&&(d[2]=E[2]-(u[0][2]+(u[1][2]-u[0][2])/2)),r(d,C)},g=(B,...C)=>{const Q={axes:[!0,!0,!0],relativeTo:[0,0,0]},{axes:h,relativeTo:E}=Object.assign({},Q,B);if(C=t(C),C.length===0)throw new Error("wrong number of arguments");if(E.length!==3)throw new Error("relativeTo must be an array of length 3");B={axes:h,relativeTo:E};const u=C.map(d=>o.isA(d)||i.isA(d)||n.isA(d)?a(B,d):d);return u.length===1?u[0]:u},c=(...B)=>g({axes:[!0,!1,!1]},B),I=(...B)=>g({axes:[!1,!0,!1]},B),l=(...B)=>g({axes:[!1,!1,!0]},B);A.exports={center:g,centerX:c,centerY:I,centerZ:l}}}),oV=at({"node_modules/@jscad/modeling/src/operations/transforms/scale.js"(e,A){var t=ko(),i=$g(),n=os(),o=As(),s=Mg(),r=(I,...l)=>{if(!Array.isArray(I))throw new Error("factors must be an array");if(l=t(l),l.length===0)throw new Error("wrong number of arguments");for(I=I.slice();I.length<3;)I.push(1);if(I[0]<=0||I[1]<=0||I[2]<=0)throw new Error("factors must be positive");const B=i.fromScaling(i.create(),I),C=l.map(Q=>s.isA(Q)?s.transform(B,Q):n.isA(Q)?n.transform(B,Q):o.isA(Q)?o.transform(B,Q):Q);return C.length===1?C[0]:C},a=(I,...l)=>r([I,1,1],l),g=(I,...l)=>r([1,I,1],l),c=(I,...l)=>r([1,1,I],l);A.exports={scale:r,scaleX:a,scaleY:g,scaleZ:c}}}),q_e=at({"node_modules/@jscad/modeling/src/operations/transforms/transform.js"(e,A){var t=ko(),i=os(),n=As(),o=Mg(),s=(r,...a)=>{if(a=t(a),a.length===0)throw new Error("wrong number of arguments");const g=a.map(c=>o.isA(c)?o.transform(r,c):i.isA(c)?i.transform(r,c):n.isA(c)?n.transform(r,c):c);return g.length===1?g[0]:g};A.exports=s}}),qF=at({"node_modules/@jscad/modeling/src/operations/transforms/index.js"(e,A){A.exports={align:K_e(),center:nV().center,centerX:nV().centerX,centerY:nV().centerY,centerZ:nV().centerZ,mirror:RY().mirror,mirrorX:RY().mirrorX,mirrorY:RY().mirrorY,mirrorZ:RY().mirrorZ,rotate:NY().rotate,rotateX:NY().rotateX,rotateY:NY().rotateY,rotateZ:NY().rotateZ,scale:oV().scale,scaleX:oV().scaleX,scaleY:oV().scaleY,scaleZ:oV().scaleZ,transform:q_e(),translate:PF().translate,translateX:PF().translateX,translateY:PF().translateY,translateZ:PF().translateZ}}}),sV=at({"node_modules/@jscad/modeling/src/index.js"(e,A){A.exports={colors:XZ(),curves:Hbe(),geometries:kuA(),maths:cxe(),measurements:uxe(),primitives:KF(),text:jxe(),utils:mtt(),booleans:HY(),expansions:_tt(),extrusions:YY(),hulls:R_e(),minkowski:N_e(),modifiers:T_e(),transforms:qF()}}}),Ftt=at({"node_modules/jscad-planner/dist/index.cjs"(e,A){var t=Object.defineProperty,i=Object.getOwnPropertyDescriptor,n=Object.getOwnPropertyNames,o=Object.prototype.hasOwnProperty,s=(l,B)=>{for(var C in B)t(l,C,{get:B[C],enumerable:!0})},r=(l,B,C,Q)=>{if(B&&typeof B=="object"||typeof B=="function")for(let h of n(B))!o.call(l,h)&&h!==C&&t(l,h,{get:()=>B[h],enumerable:!(Q=i(B,h))||Q.enumerable});return l},a=l=>r(t({},"__esModule",{value:!0}),l),g={};s(g,{executeJscadOperations:()=>I,jscadPlanner:()=>c}),A.exports=a(g);var c={booleans:{intersect:(...l)=>({type:"intersect",shapes:l}),subtract:(...l)=>({type:"subtract",shapes:l}),union:(...l)=>({type:"union",shapes:l})},hulls:{hull:(...l)=>({type:"hull",shapes:l.flat()}),hullChain:(...l)=>({type:"hullChain",shapes:l.flat()})},colors:{colorize:(l,B)=>({type:"colorize",color:l,shape:B})},primitives:{cube:l=>({type:"cube",...l}),sphere:l=>({type:"sphere",...l}),cylinder:l=>({type:"cylinder",...l}),polygon:l=>({type:"polygon",...l}),cuboid:l=>({type:"cuboid",...l}),roundedCuboid:l=>({type:"roundedCuboid",...l})},transforms:{rotate:(l,B)=>({type:"rotate",angles:l,shape:B}),scale:(l,B)=>({type:"scale",factors:l,shape:B}),translate:(l,B)=>({type:"translate",vector:l,shape:B})},extrusions:{extrudeLinear:(l,B)=>({type:"extrudeLinear",options:l,shape:B}),extrudeRotate:(l,B)=>({type:"extrudeRotate",options:l,shape:B})},maths:{vec2:{create:(l,B)=>[l,B],fromValues:(l,B)=>[l,B]},vec3:{create:(l,B,C)=>[l,B,C],fromValues:(l,B,C)=>[l,B,C]}},geometries:{geom2:{create:l=>({type:"createGeom2",points:l})},geom3:{create:l=>({type:"createGeom3",polygons:l})},path2:{create:l=>({type:"createPath2",points:l})}},measurements:{measureBoundingBox:l=>({type:"measureBoundingBox",shape:l}),measureArea:l=>({type:"measureArea",shape:l}),measureVolume:l=>({type:"measureVolume",shape:l})},utils:{degToRad:l=>l*Math.PI/180,radToDeg:l=>l*180/Math.PI}},I=(l,B)=>{if(Array.isArray(B)&&B.length===1)return I(l,B[0]);if(Array.isArray(B))throw new Error("executeJscadOperations currently doesn't support Array<JscadOperation>, try adding a root union or or executing each element individually");const C=E=>I(l,E),{type:Q,...h}=B;switch(Q){case"intersect":return l.booleans.intersect(...B.shapes.map(C));case"subtract":return l.booleans.subtract(...B.shapes.map(C));case"union":return l.booleans.union(...B.shapes.map(C));case"hull":return l.hulls.hull(...B.shapes.map(C));case"hullChain":return l.hulls.hullChain(...B.shapes.map(C));case"colorize":return l.colors.colorize(B.color,C(B.shape));case"cube":return l.primitives.cube(h);case"sphere":return l.primitives.sphere(h);case"cylinder":return l.primitives.cylinder(h);case"polygon":return l.primitives.polygon(h);case"cuboid":return l.primitives.cuboid(h);case"roundedCuboid":return l.primitives.roundedCuboid(h);case"rotate":return l.transforms.rotate(B.angles,C(B.shape));case"scale":return l.transforms.scale(B.factors,C(B.shape));case"translate":return l.transforms.translate(B.vector,C(B.shape));case"extrudeLinear":return l.extrusions.extrudeLinear(B.options,C(B.shape));case"extrudeRotate":return l.extrusions.extrudeRotate(B.options,C(B.shape));case"createGeom2":return l.geometries.geom2.create(B.points);case"createGeom3":return l.geometries.geom3.create(B.polygons);case"createPath2":return l.geometries.path2.create(B.points);case"measureBoundingBox":return l.measurements.measureBoundingBox(C(B.shape));case"measureArea":return l.measurements.measureArea(C(B.shape));case"measureVolume":return l.measurements.measureVolume(C(B.shape));case"degToRad":return l.utils.degToRad(B.degrees);case"radToDeg":return l.utils.radToDeg(B.radians);default:throw B.type===void 0?new Error(`Operation type is undefined. This usually means the operation object is malformed or not properly initialized. Operation: ${JSON.stringify(B,null,2).slice(0,200)}...`):new Error(`Unsupported operation type: ${B.type}. Operation: ${JSON.stringify(B,null,2)}`)}}}}),O_e=at({"node_modules/ms/index.js"(e,A){var t=1e3,i=t*60,n=i*60,o=n*24,s=o*7,r=o*365.25;A.exports=function(l,B){B=B||{};var C=typeof l;if(C==="string"&&l.length>0)return a(l);if(C==="number"&&isFinite(l))return B.long?c(l):g(l);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(l))};function a(l){if(l=String(l),!(l.length>100)){var B=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(l);if(B){var C=parseFloat(B[1]),Q=(B[2]||"ms").toLowerCase();switch(Q){case"years":case"year":case"yrs":case"yr":case"y":return C*r;case"weeks":case"week":case"w":return C*s;case"days":case"day":case"d":return C*o;case"hours":case"hour":case"hrs":case"hr":case"h":return C*n;case"minutes":case"minute":case"mins":case"min":case"m":return C*i;case"seconds":case"second":case"secs":case"sec":case"s":return C*t;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return C;default:return}}}}function g(l){var B=Math.abs(l);return B>=o?Math.round(l/o)+"d":B>=n?Math.round(l/n)+"h":B>=i?Math.round(l/i)+"m":B>=t?Math.round(l/t)+"s":l+"ms"}function c(l){var B=Math.abs(l);return B>=o?I(l,B,o,"day"):B>=n?I(l,B,n,"hour"):B>=i?I(l,B,i,"minute"):B>=t?I(l,B,t,"second"):l+" ms"}function I(l,B,C,Q){var h=B>=C*1.5;return Math.round(l/C)+" "+Q+(h?"s":"")}}}),W_e=at({"node_modules/debug/src/common.js"(e,A){function t(i){o.debug=o,o.default=o,o.coerce=I,o.disable=g,o.enable=r,o.enabled=c,o.humanize=O_e(),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,m=Number(new Date),w=m-(C||m);f.diff=w,f.prev=C,f.curr=m,C=m,d[0]=o.coerce(d[0]),typeof d[0]!="string"&&d.unshift("%O");let D=0;d[0]=d[0].replace(/%([a-zA-Z%])/g,(_,b)=>{if(_==="%%")return"%";D++;const R=o.formatters[b];if(typeof R=="function"){const F=d[D];_=R.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=t}}),Z_e=at({"node_modules/debug/src/browser.js"(e,A){e.formatArgs=i,e.save=n,e.load=o,e.useColors=t,e.storage=s(),e.destroy=(()=>{let a=!1;return()=>{a||(a=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),e.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"];function t(){if(typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs))return!0;if(typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))return!1;let a;return typeof document<"u"&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent&&(a=navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/))&&parseInt(a[1],10)>=31||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)}function i(a){if(a[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+a[0]+(this.useColors?"%c ":" ")+"+"+A.exports.humanize(this.diff),!this.useColors)return;const g="color: "+this.color;a.splice(1,0,g,"color: inherit");let c=0,I=0;a[0].replace(/%[a-zA-Z%]/g,l=>{l!=="%%"&&(c++,l==="%c"&&(I=c))}),a.splice(I,0,g)}e.log=console.debug||console.log||(()=>{});function n(a){try{a?e.storage.setItem("debug",a):e.storage.removeItem("debug")}catch{}}function o(){let a;try{a=e.storage.getItem("debug")||e.storage.getItem("DEBUG")}catch{}return!a&&typeof puA<"u"&&"env"in puA&&(a=puA.env.DEBUG),a}function s(){try{return localStorage}catch{}}A.exports=W_e()(e);var{formatters:r}=A.exports;r.j=function(a){try{return JSON.stringify(a)}catch(g){return"[UnexpectedJSONParseError]: "+g.message}}}}),Mtt={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},Gtt=AA.createContext(void 0),V_e=({children:e})=>{const[A,t]=AA.useState(Mtt),i=AA.useCallback((s,r)=>{t(a=>({...a,[s]:r}))},[]),n=AA.useCallback(()=>{t(Mtt)},[]),o=AA.useMemo(()=>({visibility:A,setLayerVisibility:i,resetToDefaults:n}),[A,i,n]);return Z.jsx(Gtt.Provider,{value:o,children:e})},OF=()=>{const e=AA.useContext(Gtt);if(!e)throw new Error("useLayerVisibility must be used within a LayerVisibilityProvider");return e},VuA=1.2;function Rtt(e){return AA.useMemo(()=>{if(!e)return VuA;try{return yn(e).pcb_board.list()[0]?.thickness??VuA}catch{return VuA}},[e])}var Ntt=AA.createContext(null),nd=()=>{const e=AA.useContext(Ntt);if(!e)throw new Error("useThree must be used within a ThreeProvider");return e},JY=(e,A=[])=>{const{addFrameListener:t,removeFrameListener:i}=nd();Qn.useEffect(()=>(t(e),()=>i(e)),[t,i,...A])},TY={clickToInteractOverlay:100,htmlElements:95,orientationCube:95,contextMenu:90,appearanceMenu:91},Ltt=({children:e,position:A,style:t})=>{const{camera:i,renderer:n}=nd(),o=AA.useRef(document.createElement("div")),[s,r]=AA.useState(null);return AA.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(UK.createPortal(e,o.current)),()=>{a.contains(o.current)&&a.removeChild(o.current)}},[n,e]),JY(()=>{if(!i||!o.current||!n)return;const a=new Gt(...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=TY.htmlElements.toString(),t&&Object.assign(o.current.style,t)},[i,n,A,t]),s},Utt={in:25.4,inch:25.4,mil:.0254,mm:1,m:1e3,cm:10,ft:304.8,feet:304.8},cr=e=>{let A=typeof e=="number"?"mm":e.replace(/^[^a-zA-Z]+/g,"").toLowerCase();A||(A="mm");const t=typeof e=="number"?e:Number.parseFloat(e.split(A)[0]);if(A in Utt)return t*Utt[A];throw new Error(`Unsupported unit: ${A}`)},Kl=cr,j_e=Object.defineProperty,z_e=(e,A)=>{for(var t in A)j_e(e,t,{get:A[t],enumerable:!0})},Rb={};z_e(Rb,{axial:()=>fve,bga:()=>_ke,breakoutheaders:()=>Gve,cap:()=>nke,dfn:()=>ive,diode:()=>ike,dip:()=>Ake,electrolytic:()=>yGe,hc49:()=>Nve,jst:()=>YMe,led:()=>oke,lqfp:()=>Fve,m2host:()=>PGe,melf:()=>VFe,micromelf:()=>$Fe,minimelf:()=>JFe,mlp:()=>Uke,mountedpcbmodule:()=>qGe,ms012:()=>gve,ms013:()=>Ive,msop:()=>jMe,pad:()=>Lve,pinrow:()=>ove,platedhole:()=>GGe,potentiometer:()=>dGe,pushbutton:()=>Sve,qfn:()=>Rke,qfp:()=>Lke,quad:()=>C2,radial:()=>wve,res:()=>Ske,sma:()=>iMe,smb:()=>IMe,smbf:()=>wGe,smc:()=>QMe,smf:()=>rMe,smtpad:()=>FGe,sod110:()=>TMe,sod123:()=>Eve,sod123f:()=>uFe,sod123fl:()=>yFe,sod123w:()=>Xve,sod128:()=>kFe,sod323:()=>eFe,sod323f:()=>CFe,sod323fl:()=>eGe,sod323w:()=>XMe,sod523:()=>Tve,sod723:()=>SFe,sod80:()=>Zve,sod882:()=>cFe,sod882d:()=>qFe,sod923:()=>sFe,soic:()=>vke,solderjumper:()=>IGe,son:()=>sGe,sop8:()=>Ove,sot:()=>NGe,sot223:()=>dMe,sot23:()=>jke,sot23w:()=>xMe,sot25:()=>Ave,sot323:()=>xGe,sot343:()=>HGe,sot363:()=>Oke,sot457:()=>CGe,sot563:()=>rve,sot723:()=>Bve,sot886:()=>Zke,sot89:()=>NFe,sot963:()=>hGe,ssop:()=>Jke,stampboard:()=>xve,stampreceiver:()=>vve,to220:()=>eet,to220f:()=>HFe,to92:()=>Yve,to92l:()=>WGe,to92s:()=>GMe,tqfp:()=>Nke,tssop:()=>Kke,vson:()=>aGe,vssop:()=>WMe});var Ui=(e,A,t)=>({type:"pcb_silkscreen_text",pcb_silkscreen_text_id:"silkscreen_text_1",font:"tscircuit2024",font_size:t,pcb_component_id:"pcb_component_1",text:"{REF}",layer:"top",anchor_position:{x:e,y:A},anchor_alignment:"center"}),Gi=et({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")}),vo=(e,A,t,i,n)=>({pcb_plated_hole_id:"",type:"pcb_plated_hole",shape:"circle",x:A,y:t,hole_diameter:cr(i),outer_diameter:cr(n),pcb_port_id:"",layers:["top","bottom"],port_hints:[e.toString()]}),Im=e=>{const{pn:A,x:t,y:i,holeDiameter:n,rectPadWidth:o,rectPadHeight:s,holeOffsetX:r=0,holeOffsetY:a=0,rectBorderRadius:g}=e;return{pcb_plated_hole_id:"",type:"pcb_plated_hole",shape:"circular_hole_with_rect_pad",x:t,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}},rV=Array.from({length:9},(e,A)=>Math.cos(A/8*Math.PI-Math.PI)).map(e=>({x:e,y:-Math.sqrt(1-e**2)}));function rk(e){return typeof e=="string"?e.trim().toLowerCase().endsWith("mil")?parseFloat(e)*.0254:parseFloat(e):Number(e)}var aV=Ge([L(),qA()]).transform(e=>rk(e)),X_e=e=>Gi.extend({fn:L(),num_pins:qA().optional().default(6),wide:PA().optional(),narrow:PA().optional(),w:aV.optional(),p:aV.default(e.p??"2.54mm"),id:aV.optional(),od:aV.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=rk("0.55mm"),A.od=rk("0.95mm")):(A.id=rk("0.8mm"),A.od=rk("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=rk("600mil"):A.narrow?A.w=rk("300mil"):A.w=rk(e.w??"300mil")),A)),$_e=X_e({}),Htt=(e,A,t,i,n)=>{const o=e/2,s=A<=o,r=o-1,a=i,g=a*r;return s?{x:-t/2,y:g/2-(A-1)*a}:{x:t/2,y:-g/2+(A-o-1)*a}},Ake=e=>{const A=$_e.parse(e),t=[];for(let g=0;g<A.num_pins;g++){const{x:c,y:I}=Htt(A.num_pins,g+1,A.w,A.p??2.54,A.nosquareplating);if(g===0&&!A.nosquareplating){t.push(Im({pn:g+1,x:c,y:I,holeDiameter:A.id??"0.8mm",rectPadWidth:A.od??"1mm",rectPadHeight:A.od??"1mm"}));continue}t.push(vo(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},...rV.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}=Htt(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:[...t,s,a,...r],parameters:A}},li=(e,A,t,i,n)=>({type:"pcb_smtpad",x:A,y:t,width:i,height:n,layer:"top",shape:"rect",pcb_smtpad_id:"",port_hints:Array.isArray(e)?e.map(o=>o.toString()):[e.toString()]}),Ytt=[{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}],tke=Object.fromEntries(Ytt.map(e=>[e.metric,e])),eke=Object.fromEntries(Ytt.map(e=>[e.imperial,e]));Gi.extend({tht:PA(),p:cA.optional(),pw:cA.optional(),ph:cA.optional(),metric:st.optional(),imperial:st.optional(),w:cA.optional(),h:cA.optional(),textbottom:PA().optional()});var gV=e=>{let{tht:A,p:t,pw:i,ph:n,metric:o,imperial:s,w:r,h:a,textbottom:g}=e;if(typeof r=="string"&&(r=Kl(r)),typeof a=="string"&&(a=Kl(a)),typeof t=="string"&&(t=Kl(t)),typeof i=="string"&&(i=Kl(i)),typeof n=="string"&&(n=Kl(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=tke[o]),s&&(c=eke[s]),c&&(r=c.w_mm_min,a=c.h_mm_min,t=c.p_mm_min,i=c.pw_mm_min,n=c.ph_mm_min),t===void 0||i===void 0||n===void 0)throw new Error("Could not determine required pad dimensions (p, pw, ph)");const I={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:t/2,y:n/2+.4},{x:-t/2-i/2-.2,y:n/2+.4},{x:-t/2-i/2-.2,y:-n/2-.4},{x:t/2,y:-n/2-.4}],stroke_width:.1,pcb_silkscreen_path_id:""},l=g?-n/2-.9:n/2+.9,B=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,-(t/2+i/2),...Q)-C,u=Math.max((r??0)/2,t/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,m={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?[vo(1,-t/2,0,i,i*1/.8),vo(2,t/2,0,i,i*1/.8),I,B,m]:[li(["1","left"],-t/2,0,i,n),li(["2","right"],t/2,0,i,n),I,B,m]},ike=e=>({circuitJson:gV(e),parameters:e}),nke=e=>({circuitJson:gV(e),parameters:e}),oke=e=>({circuitJson:gV(e),parameters:e}),B2=e=>{const{padSpacing:A,padWidth:t,padHeight:i,padPitch:n,numRows:o,textbottom:s}=e,r=[],a=(o-1)*(n/2);for(let S=0;S<o;S++)r.push(a-S*n);const g=[];r.forEach((S,_)=>{g.push(li(_+1,-A/2,S,t,i))}),r.slice().reverse().forEach((S,_)=>{g.push(li(_+o+1,A/2,S,t,i))});const c=Math.max(...r)+i/2+.4,I=Math.min(...r)-i/2-.4,l=-A/2-t/2-.4,B=A/2+t/2+.4,C={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:B*.5,y:c},{x:l*.5,y:c}],stroke_width:.12,pcb_silkscreen_path_id:"silkscreen_top"},Q={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:B*.5,y:I},{x:l*.5,y:I}],stroke_width:.12,pcb_silkscreen_path_id:"silkscreen_bottom"},h=-A/2,E=Math.max(...r),u=.2,d=h-t/2-.1,f=E+i/2+.1,m={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,m,D]},ske=Gi.extend({pw:cA.default("0.5mm"),ph:cA.default("0.4mm"),p:cA.default("0.7mm"),textbottom:PA().optional(),convex:PA().optional(),concave:PA().optional()}),rke=1,ake=e=>{const A=ske.parse(e);if(A.concave===!0)return[];const t=Kl(A.pw),i=Kl(A.ph),n=Kl(A.p);return B2({padSpacing:rke,padWidth:t,padHeight:i,padPitch:n,numRows:2,textbottom:A.textbottom,convex:A.convex,concave:A.concave})},gke=Gi.extend({pw:cA.default("0.5mm"),ph:cA.default("0.32mm"),p:cA.default("0.5mm"),textbottom:PA().optional(),convex:PA().optional(),concave:PA().optional()}),cke=1,Ike=e=>{const A=gke.parse(e),t=Kl(A.pw),i=Kl(A.ph),n=Kl(A.p);return B2({padSpacing:cke,padWidth:t,padHeight:i,padPitch:n,numRows:4,textbottom:A.textbottom,convex:A.convex,concave:A.concave})},lke=Gi.extend({pw:cA.default("0.9mm"),ph:cA.default("0.4mm"),p:cA.default("0.8mm"),textbottom:PA().optional(),convex:PA().optional(),concave:PA().optional()}),Bke=1.7,Cke=e=>{const A=lke.parse(e),t=Kl(A.pw),i=Kl(A.ph),n=Kl(A.p);return B2({padSpacing:Bke,padWidth:t,padHeight:i,padPitch:n,numRows:2,textbottom:A.textbottom,convex:A.convex,concave:A.concave})},Qke=Gi.extend({pw:cA.default("0.9mm"),ph:cA.default("0.4mm"),p:cA.default("0.8mm"),textbottom:PA().optional(),convex:PA().optional(),concave:PA().optional()}),hke=1.7,Eke=e=>{const A=Qke.parse(e),t=Kl(A.pw),i=Kl(A.ph),n=Kl(A.p);return B2({padSpacing:hke,padWidth:t,padHeight:i,padPitch:n,numRows:4,textbottom:A.textbottom,convex:A.convex,concave:A.concave})},uke=Gi.extend({pw:cA.default("0.7mm"),ph:cA.default("0.64mm"),p:cA.default("0.94mm"),textbottom:PA().optional(),convex:PA().optional(),concave:PA().optional()}),dke=1.4,pke=e=>{const A=uke.parse(e),t=Kl(A.pw),i=Kl(A.ph),n=Kl(A.p);return B2({padSpacing:dke,padWidth:t,padHeight:i,padPitch:n,numRows:2,textbottom:A.textbottom,convex:A.convex,concave:A.concave})},fke=Gi.extend({pw:cA.default("0.9mm"),ph:cA.default("0.9mm"),p:cA.default("1.34mm"),textbottom:PA().optional(),convex:PA().optional(),concave:PA().optional()}),yke=3,mke=e=>{const A=fke.parse(e),t=Kl(A.pw),i=Kl(A.ph),n=Kl(A.p);return B2({padSpacing:yke,padWidth:t,padHeight:i,padPitch:n,numRows:4,textbottom:A.textbottom,convex:A.convex,concave:A.concave})},wke=e=>{const A=e.array??e.x;if(typeof A=="number")return Number.isNaN(A)?void 0:A;if(typeof A=="string"){const t=Number.parseInt(A,10);return Number.isNaN(t)?void 0:t}if(typeof e.imperial=="string"){const i=e.imperial.match(/x(2|4)$/)?.[1];if(i)return Number.parseInt(i,10)}},Dke=e=>e?(typeof e=="number"?`${e}`:e).split(/[_x]/)[0]:void 0,Ske=e=>{const A=wke(e),t=Dke(e.imperial);return A===2&&t==="0402"?{circuitJson:ake(e),parameters:e}:A===4&&t==="0402"?{circuitJson:Ike(e),parameters:e}:A===2&&t==="0603"?{circuitJson:Cke(e),parameters:e}:A===4&&t==="0603"?{circuitJson:Eke(e),parameters:e}:A===2&&t==="0606"?{circuitJson:pke(e),parameters:e}:A===4&&t==="1206"?{circuitJson:mke(e),parameters:e}:{circuitJson:gV(e),parameters:e}},Jtt=(e,{x:A,y:t,radius:i})=>({type:"pcb_smtpad",x:A,y:t,radius:i,layer:"top",shape:"circle",pcb_smtpad_id:"",port_hints:Array.isArray(e)?e.map(n=>n.toString()):[e.toString()]}),Ttt="ABCDEFGHIJKLMNOPQRSTUVWXYZ",cV=L().transform(e=>{const[A,t]=e.split(/[x ]/);return{x:parseFloat(A??""),y:parseFloat(t??"")}}).pipe(et({x:qA(),y:qA()})),bke=L().or(St(AI())).transform(e=>Array.isArray(e)?e:(e.startsWith("(")&&e.endsWith(")")&&(e=e.slice(1,-1)),e.split(",").map(A=>{const t=Number(A);return isNaN(t)?A:t}))).pipe(St(L().or(qA()))),xke=Gi.extend({fn:L(),num_pins:qA().optional().default(64),grid:cV.optional(),p:st.default("0.8mm"),w:cA.optional(),h:cA.optional(),ball:cA.optional().describe("ball diameter"),pad:cA.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:bke.default([])}).transform(e=>{let A="tl";if(e.blorigin&&(A="bl"),e.trorigin&&(A="tr"),e.brorigin&&(A="br"),!e.grid){const i=Math.ceil(Math.sqrt(e.num_pins));e.grid={x:i,y:i}}return e.missing&&(e.missing=e.missing.map(i=>{if(typeof i=="number")return i;if(i==="center")return"center";if(i==="topleft")return"topleft";const n=i.match(/([A-Z]+)(\d+)/);if(!n)return i;const o=Ttt.indexOf(n[1]),s=Number.parseInt(n[2])-1;return o*e.grid.x+s+1})),{...e,origin:A}}),_ke=e=>{const A=xke.parse(e);let{num_pins:t,grid:i,p:n,w:o,h:s,ball:r,pad:a,missing:g}=A;r??=.75/1.27*n,a??=r*.8;const c=[],I=(g??[]).filter(m=>typeof m=="number"),l=i.x*i.y-t;if(g.length===0&&l>0&&(Math.sqrt(l)%1===0?g.push("center"):l===1&&g.push("topleft")),g?.includes("center")){const m=Math.floor(Math.sqrt(l)),w=Math.floor((i.x-m)/2),D=Math.floor((i.y-m)/2);for(let S=D;S<D+m;S++)for(let _=w;_<w+m;_++)I.push(S*i.x+_+1)}g?.includes("topleft")&&I.push(1);const B=new Set(I);let C=0;for(let m=0;m<i.y;m++)for(let w=0;w<i.x;w++){const D=(w-(i.x-1)/2)*n,S=(m-(i.y-1)/2)*n;let _=w,b=m;switch(A.origin){case"bl":_=w,b=i.y-1-m;break;case"br":_=i.x-1-w,b=i.y-1-m;break;case"tr":_=i.x-1-w,b=m;break}let R=b*i.x+_+1;if(B.has(R)){C++;continue}R-=C;const F=[R,`${Ttt[b]}${_+1}`];c.push(A.circularpads?Jtt(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}},IV=(e,A,t,i,n)=>({type:"pcb_smtpad",x:A,y:t,width:i,height:n,radius:n/2,layer:"top",shape:"pill",pcb_smtpad_id:"",port_hints:Array.isArray(e)?e.map(o=>o.toString()):[e.toString()]}),WF=e=>Gi.extend({fn:L(),num_pins:qA().optional().default(8),w:cA.default(cA.parse(e.w??"5.3mm")),p:cA.default(cA.parse(e.p??"1.27mm")),pw:cA.default(cA.parse(e.pw??"0.6mm")),pl:cA.default(cA.parse(e.pl??"1.0mm")),legsoutside:PA().optional().default(e.legsoutside??!1),pillpads:PA().optional().default(e.pillpads??!1),silkscreen_stroke_width:qA().optional().default(.1)}).transform(A=>(!A.pw&&!A.pl?(A.pw=cA.parse("0.6mm"),A.pl=cA.parse("1.0mm")):A.pw?A.pl||(A.pl=A.pw*(1/.6)):A.pw=A.pl*(.6/1),A)),kke=WF({}),juA=e=>{e.widthincludeslegs!==void 0&&(e.legsoutside=!e.widthincludeslegs);const{num_pins:A,pn:t,w:i,p:n,pl:o,legsoutside:s}=e,r=A/2,a=t<=r,g=r-1,c=n,I=c*g,l=s?o/2:-o/2;return a?{x:-i/2-l,y:I/2-(t-1)*c}:{x:i/2+l,y:-I/2+(t-r-1)*c}},vke=e=>{const A=kke.parse(e);return{circuitJson:PY(A),parameters:A}},PY=e=>{const A=[];for(let r=0;r<e.num_pins;r++){const{x:a,y:g}=juA({num_pins:e.num_pins,pn:r+1,w:e.w,p:e.p,pl:e.pl,legsoutside:e.legsoutside});e.pillpads?A.push(IV(r+1,a,g,e.pl,e.pw)):A.push(li(r+1,a,g,e.pl,e.pw))}const t=Math.min(1,e.p/2),i=e.w-(e.legsoutside?0:e.pl*2)-.2,n=(e.num_pins/2-1)*e.p+e.pw+t,o=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:e.silkscreen_stroke_width??.1,route:[{x:-i/2,y:-n/2},{x:-i/2,y:n/2},...rV.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]},Ptt=Xt(["leftside","topside","rightside","bottomside","toppin","bottompin","leftpin","rightpin"]),Fke=({num_pins:e,cw:A,ccw:t,startingpin:i})=>{const n=[],o=e/4;let s=1;const r={};for(const a of i??[])r[a]=!0;!r.leftside&&!r.topside&&!r.rightside&&!r.bottomside&&(r.leftside=!0),!r.bottompin&&!r.leftpin&&!r.rightpin&&!r.toppin&&(r.leftside?r.toppin=!0:r.topside?r.rightpin=!0:r.rightside?r.bottompin=!0:r.bottomside&&(r.leftpin=!0)),r.leftside&&r.toppin?s=1:r.leftside&&r.bottompin?s=o:r.bottomside&&r.leftpin?s=o+1:r.bottomside&&r.rightpin?s=o*2:r.rightside&&r.bottompin?s=o*2+1:r.rightside&&r.toppin?s=o*3:r.topside&&r.rightpin?s=o*3+1:r.topside&&r.leftpin&&(s=o*4),n.push(-1);for(let a=0;a<e;a++)n[s]=a+1,t||!A?(s++,s>e&&(s=1)):(s--,s<1&&(s=e));return n},zuA=Gi.extend({fn:L(),cc:PA().default(!0).optional(),ccw:PA().default(!0).optional(),startingpin:L().or(St(Ptt)).transform(e=>typeof e=="string"?e.slice(1,-1).split(","):e).pipe(St(Ptt)).optional(),num_pins:qA().optional().default(64),w:cA.optional(),h:cA.optional(),p:cA.default(cA.parse("0.5mm")),pw:cA.optional(),pl:cA.optional(),thermalpad:Ge([bA(!0),cV]).optional(),legsoutside:PA().default(!1)}),XuA=e=>{e.w&&!e.h?e.h=e.w:!e.w&&e.h&&(e.w=e.h);const A=e.num_pins/4;if(!e.p&&!e.pw&&!e.pl&&e.w){const t=A+4;e.p=e.w/t}return!e.p&&e.w&&e.h&&e.pw&&e.pl&&(e.p=(e.w-e.pl*2)/(A-1)),!e.w&&!e.h&&e.p&&(e.w=e.p*(A+4),e.h=e.w),e.p&&!e.pw&&!e.pl?(e.pw=e.p/2,e.pl=e.p/2):e.pw?e.pl||(e.pl=e.pw*(1/.6)):e.pw=e.pl*(.6/1),e},Ktt=zuA.transform(XuA),Mke=["left","bottom","right","top"],Gke=e=>{const{pin_count:A,pn:t,w:i,h:n,p:o,pl:s,legsoutside:r}=e,a=A/4,g=Mke[Math.floor((t-1)/a)],c=(t-1)%a,I=o*(a-1),l=o*(a-1),B=r?s/2:-s/2;switch(g){case"left":return{x:-i/2-B+.1,y:l/2-c*o,o:"vert"};case"bottom":return{x:-I/2+c*o,y:-n/2-B+.1,o:"horz"};case"right":return{x:i/2+B-.1,y:-l/2+c*o,o:"vert"};case"top":return{x:I/2-c*o,y:n/2+B-.1,o:"horz"};default:throw new Error("Invalid pin number")}},C2=e=>{const A=Ktt.parse(e),t=[],i=Fke(A),n=A.num_pins/4;for(let r=0;r<A.num_pins;r++){const{x:a,y:g,o:c}=Gke({pin_count:A.num_pins,pn:r+1,w:A.w,h:A.h,p:A.p??.5,pl:A.pl,legsoutside:A.legsoutside});let I=A.pw,l=A.pl;c==="vert"&&([I,l]=[l,I]);const B=i[r+1];t.push(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;t.push(li(["thermalpad"],0,0,r,a))}else t.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:[...t,...o,s],parameters:A}};zuA.extend({}).transform(XuA);var Rke=e=>(e.legsoutside=!1,e.pl||(e.pl=.875),e.pw||(e.pw=.25),C2(e)),Nke=e=>{if(e.legsoutside=!0,!e.p)switch(e.num_pins){case 32:e.p=.8;break;case 44:case 48:e.p=.5;break;case 64:case 80:case 100:e.p=.5;break;case 144:e.p=.5;break}if(!e.pl)switch(e.num_pins){case 32:case 44:case 48:case 64:case 80:case 100:e.pl=1.475;break;case 144:e.pl=1.6;break}if(!e.pw)switch(e.num_pins){case 32:e.pw=.55;break;case 44:case 48:case 64:case 80:case 100:e.pw=.3;break;case 144:e.pw=.25;break}return C2(e)},Lke=e=>{e.legsoutside=!0;const A=Ktt.parse(e);if(!e.p)switch(e.num_pins){case 44:case 64:e.p=.8;break;case 52:e.w===14?e.p=1:e.p=.65;break;case 208:e.p=.5;break}if(!e.pl)switch(e.num_pins){case 44:case 52:case 64:e.pl=2.25;break;case 208:e.pl=1.65;break;default:e.pl=A.pl*4;break}if(!e.pw)switch(e.num_pins){case 44:case 64:e.pw=.5;break;case 52:e.w===14?e.pw=.45:e.pw=.55;break;case 208:e.pw=.3;break;default:e.pw=A.pw;break}return C2(e)};zuA.extend({}).transform(XuA);var Uke=e=>(e.legsoutside=!1,e.thermalpad===void 0&&(e.thermalpad=!0),C2(e)),Hke=Gi.extend({fn:L(),num_pins:qA().optional().default(8),w:cA.default(cA.parse("3.9mm")),p:cA.default(cA.parse("1.27mm")),pw:cA.optional(),pl:cA.optional(),legsoutside:PA().optional().default(!1),silkscreen_stroke_width:qA().optional().default(.1)}).transform(e=>(e.pw==null&&e.pl==null?(e.pw=cA.parse("0.51mm"),e.pl=cA.parse("1.1mm")):e.pw==null?e.pw=e.pl*(.51/1.1):e.pl==null&&(e.pl=e.pw*(1.1/.51)),e)),Yke=e=>{const{num_pins:A,pn:t,w:i,p:n}=e,o=A/2,s=t<=o,r=o-1,a=n,g=a*r,c=i+cA.parse("0.2mm"),I=(s?-1:1)*(c/2);return s?{x:I,y:g/2-(t-1)*a}:{x:I,y:-g/2+(t-o-1)*a}},Jke=e=>{const A=Hke.parse(e),t=[];for(let a=0;a<A.num_pins;a++){const{x:g,y:c}=Yke({num_pins:A.num_pins,pn:a+1,w:A.w,p:A.p,pl:A.pl,legsoutside:A.legsoutside});t.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},...rV.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:[...t,r,s],parameters:A}},Tke=Gi.extend({fn:L(),num_pins:qA().optional().default(8),w:cA.default(cA.parse("3.0mm")),p:cA.default(cA.parse("0.5mm")),pw:cA.default(cA.parse("0.30mm")),pl:cA.default(cA.parse("1.45mm")),legsoutside:PA().optional().default(!0),silkscreen_stroke_width:qA().optional().default(.1)}),Pke=e=>{const{num_pins:A,pn:t,w:i,p:n,pl:o,legsoutside:s}=e,r=A/2,a=t<=r,g=r-1,c=n*g,I=s?o/2:-o/2;return a?{x:-i/2-I,y:c/2-(t-1)*n}:{x:i/2+I,y:-c/2+(t-r-1)*n}},Kke=e=>{const A={...e},t=A.p,i=typeof t=="string"||typeof t=="number"?cA.parse(t):void 0,n=i!=null&&i<=cA.parse("0.5mm"),o=Tke.parse(A),s=[],r=n?o.w-cA.parse("0.15mm"):o.w;for(let B=0;B<o.num_pins;B++){const{x:C,y:Q}=Pke({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},...rV.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}},qke=Gi.extend({fn:L(),num_pins:bA(6).default(6),w:L().default("3.1mm"),h:L().default("2.0mm"),p:L().default("0.65mm"),pl:L().default("1.03mm"),pw:L().default("0.35mm"),string:L().optional()}),Oke=e=>{const A=qke.parse({...e,fn:"sot363"}),t=cA.parse(A.w),i=cA.parse(A.h),n=cA.parse(A.p),o=cA.parse(A.pl),s=cA.parse(A.pw),r=[];for(let B=0;B<6;B++){const{x:C,y:Q}=qtt(B+1,t,n);r.push(li(B+1,C,Q,o,s))}const a={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-t/4,y:i/2+.1},{x:t/4,y:i/2+.1}],stroke_width:.05,pcb_silkscreen_path_id:""},g={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-t/4,y:-i/2-.1},{x:t/4,y:-i/2-.1}],stroke_width:.05,pcb_silkscreen_path_id:""},c=qtt(1,t,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}},qtt=(e,A,t,i)=>e<=3?{x:-.84,y:t-(e-1)*t}:{x:.84,y:-t+(e-4)*t},Wke=Gi.extend({fn:L(),num_pins:bA(6).default(6),w:L().default("1.01mm"),h:L().default("1.45mm"),p:L().default("0.5mm"),pl:L().default("0.33mm"),pw:L().default("0.27mm"),string:L().optional()}),Zke=e=>{const A=Wke.parse({...e,fn:"sot886"}),t=cA.parse(A.w),i=cA.parse(A.h),n=cA.parse(A.p),o=cA.parse(A.pl),s=cA.parse(A.pw),r=[];for(let B=0;B<6;B++){const{x:C,y:Q}=Ott(B+1,t,n,o);r.push(li(B+1,C,Q,o,s))}const a={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-t/2,y:i/2},{x:t/2,y:i/2}],stroke_width:.05,pcb_silkscreen_path_id:""},g={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-t/2,y:-i/2},{x:t/2,y:-i/2}],stroke_width:.05,pcb_silkscreen_path_id:""},c=Ott(1,t,n,o),I={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"pin_marker_1",route:[{x:c.x-o/2-.3,y:c.y},{x:c.x-o/2-.45,y:c.y+.15},{x:c.x-o/2-.45,y:c.y-.15},{x:c.x-o/2-.3,y:c.y}],stroke_width:.05,pcb_silkscreen_path_id:"pin_marker_1"},l=Ui(0,i/2+.4,.25);return{circuitJson:[...r,a,g,l,I],parameters:A}},Ott=(e,A,t,i)=>{const n=A/2-i/2;return e<=3?{x:-n,y:t-(e-1)*t}:{x:n,y:-t+(e-4)*t}},Wtt=Gi.extend({fn:L(),num_pins:qA().default(3),w:L().default("1.92mm"),h:L().default("2.74mm"),pl:L().default("1.32mm"),pw:L().default("0.6mm"),p:L().default("0.95mm"),string:L().optional()}),Vke=WF({p:"0.95mm",w:"1.6mm",legsoutside:!0}),jke=e=>{const A=e.string?.match(/^sot23_(\d+)/),t=A?Number.parseInt(A[1],10):3;if(t===6||t===8){const n=Vke.parse({...e,num_pins:t});return{circuitJson:PY(n),parameters:n}}const i=Wtt.parse({...e,num_pins:t});if(i.num_pins===3)return{circuitJson:Xke(i),parameters:i};if(i.num_pins===5)return{circuitJson:Vtt(i),parameters:i};throw new Error("Invalid number of pins")},zke=e=>{const{pn:A,p:t}=e;return A===1?{x:-1.155,y:t}:A===2?{x:-1.155,y:-t}:{x:1.15,y:0}},Xke=e=>{const A=[];for(let i=0;i<e.num_pins;i++){const{x:n,y:o}=zke({num_pins:e.num_pins,pn:i+1,w:Number.parseFloat(e.w),h:Number.parseFloat(e.h),pl:Number.parseFloat(e.pl),p:Number.parseFloat(e.p)});A.push(li(i+1,n,o,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}const t=Ui(0,Number.parseInt(e.h),.3);return[...A,t]},Ztt=e=>{const{p:A,h:t,pn:i}=e;if(i===1)return{x:-t/2-.5,y:A};if(i===2)return{x:-t/2-.5,y:0};if(i===3)return{x:-t/2-.5,y:-A};if(i===4)return{x:t/2+.5,y:-A};if(i===5)return{x:t/2+.5,y:A};throw new Error("Invalid pin number")},Vtt=e=>{const A=[];for(let I=1;I<=e.num_pins;I++){const{x:l,y:B}=Ztt({h:Number.parseFloat(e.h),p:Number.parseFloat(e.p),pn:I});A.push(li(I,l,B,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}const t=(e.num_pins+1)/2*Number.parseFloat(e.p),i=Number.parseFloat(e.h),n={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-t/3,y:i/2+Number.parseFloat(e.p)/1.3},{x:t/3,y:i/2+Number.parseFloat(e.p)/1.3}],type:"pcb_silkscreen_path",stroke_width:.05},o={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_2",route:[{x:-t/3,y:-i/2-Number.parseFloat(e.p)/1.3},{x:t/3,y:-i/2-Number.parseFloat(e.p)/1.3}],type:"pcb_silkscreen_path",stroke_width:.05},s=Ui(0,i+.3,.3),r=Ztt({h:Number.parseFloat(e.h),p:Number.parseFloat(e.p),pn:1});r.x=r.x-Number.parseFloat(e.pw)*1.5;const a=.3,g=.4,c={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"pin1_indicator",route:[{x:r.x+a/2,y:r.y},{x:r.x-a/2,y:r.y+g/2},{x:r.x-a/2,y:r.y-g/2},{x:r.x+a/2,y:r.y}],stroke_width:.05};return[...A,s,n,o,c]},$ke=Wtt.extend({}),Ave=e=>{const A=$ke.parse({...e,num_pins:5});return{circuitJson:Vtt(A),parameters:A}},tve=[{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}],eve=WF({}),ive=e=>{const A=eve.parse(e),t=[];for(let I=0;I<A.num_pins;I++){const{x:l,y:B}=juA({num_pins:A.num_pins,pn:I+1,w:A.w,p:A.p??1.27,pl:A.pl,widthincludeslegs:!0});t.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 tve){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:[...t,c,...s],parameters:A}},ZF=({fs:e,pn:A,anchor_x:t,anchor_y:i,textalign:n="center",orthogonal:o=!1,verticallyinverted:s=!1,layer:r="top"})=>{let a=0;o&&s?a=270:s?a=180:o?a=90:a=0;let g="center";return n==="left"&&(s?g="center_right":g="center_left"),n==="right"&&(s?g="center_left":g="center_right"),r==="bottom"&&(g==="center_left"?g="center_right":g==="center_right"&&(g="center_left")),{type:"pcb_silkscreen_text",pcb_silkscreen_text_id:"silkscreen_text_1",font:"tscircuit2024",font_size:e,pcb_component_id:"pcb_component_1",text:`{PIN${A}}`,layer:r,anchor_position:{x:t,y:i},anchor_alignment:g,ccw_rotation:a}};function jtt({pinlabeltextalignleft:e,pinlabeltextalignright:A,pinlabelorthogonal:t}){let i="top";return t?i="left":i="top",e&&(t?i="bottom":i="right"),A&&(t?i="top":i="left"),i}var nve=Gi.extend({fn:L(),num_pins:qA().optional().default(6),rows:Ge([L(),qA()]).transform(e=>Number(e)).optional().default(1).describe("number of rows"),p:cA.default("0.1in").describe("pitch"),id:cA.default("1.0mm").describe("inner diameter"),od:cA.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:cA.optional().default("1.0mm").describe("pad width for SMD"),pl:cA.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(e=>{const A=jtt(e);return{...e,pinlabelAnchorSide:A,male:e.male??!e.female,female:e.female??!1,smd:e.smd??e.surfacemount??!1,rightangle:e.rightangle??!1}}).superRefine((e,A)=>{e.male&&e.female&&A.addIssue({code:ze.custom,message:"'male' and 'female' cannot both be true; it should be male or female.",path:["male","female"]})}),ove=e=>{const A=nve.parse(e),{p:t,id:i,od:n,rows:o,num_pins:s,pinlabelAnchorSide:r,pinlabelverticallyinverted:a,pinlabelorthogonal:g,pinlabeltextalignleft:c,pinlabeltextalignright:I,nopinlabels:l,doublesidedpinlabel:B,bottomsidepinlabel:C}=A;let Q="center";c?Q="left":I&&(Q="right");const h=[],E=Math.ceil(s/o),u=-t,d=({xoff:S,yoff:_,od:b,anchorSide:R,smd:F,pw:H,pl:Y})=>{let J=0,O=0;if(F){const W=b/5;switch(R){case"right":J=H/2+W;break;case"top":O=Y/2+W;break;case"bottom":O=-(Y/2+W);break;case"left":J=-(H/2+W);break}}else{const W=b*.75;switch(R){case"right":J=W;break;case"top":O=W;break;case"bottom":O=-W;break;case"left":J=-W;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(Im({pn:S,x:_,y:b,holeDiameter:i,rectPadWidth:n,rectPadHeight:n})):h.push(vo(S,_,b,i,n));const{anchor_x:R,anchor_y:F}=d({xoff:_,yoff:b,od:n,anchorSide:r,smd:A.smd,pw:A.pw,pl:A.pl});l||(C?h.push(ZF({fs:n/5,pn:S,anchor_x:R,anchor_y:F,textalign:Q,orthogonal:g,verticallyinverted:a,layer:"bottom"})):h.push(ZF({fs:n/5,pn:S,anchor_x:R,anchor_y:F,textalign:Q,orthogonal:g,verticallyinverted:a,layer:"top"})),B&&h.push(ZF({fs:n/5,pn:S,anchor_x:R,anchor_y:F,textalign:Q,orthogonal:g,verticallyinverted:a,layer:"bottom"})))},m=new Set,w=o>2&&E>2;if(o===1){const S=-((s-1)/2)*t;for(let _=0;_<s;_++){const b=_+1,R=S+_*t,F=`${R},0`;if(m.has(F))throw new Error(`Overlap at ${F}`);m.add(F),f(b,R,0)}}else if(w){const S=-((E-1)/2)*t;let _=1;for(let b=0;b<o&&_<=s;b++)for(let R=0;R<E&&_<=s;R++){const F=S+R*t,H=b*u,Y=`${F},${H}`;if(m.has(Y))throw new Error(`Overlap at ${Y}`);m.add(Y),f(_++,F,H)}}else{const S=-((E-1)/2)*t;let _=1,b=0,R=o-1,F=0,H=E-1;for(;_<=s&&b<=R&&F<=H;){for(let Y=b;Y<=R&&_<=s;Y++){const J=S+F*t,O=Y*u,W=`${J},${O}`;if(m.has(W))throw new Error(`Overlap at ${W}`);m.add(W),f(_++,J,O)}F++;for(let Y=F;Y<=H&&_<=s;Y++){const J=S+Y*t,O=R*u,W=`${J},${O}`;if(m.has(W))throw new Error(`Overlap at ${W}`);m.add(W),f(_++,J,O)}if(R--,F<=H){for(let Y=R;Y>=b&&_<=s;Y--){const J=S+H*t,O=Y*u,W=`${J},${O}`;if(m.has(W))throw new Error(`Overlap at ${W}`);m.add(W),f(_++,J,O)}H--}if(b<=R){for(let Y=H;Y>=F&&_<=s;Y--){const J=S+Y*t,O=b*u,W=`${J},${O}`;if(m.has(W))throw new Error(`Overlap at ${W}`);m.add(W),f(_++,J,O)}b++}}if(_-1<s)throw new Error(`Missing pins: assigned ${_-1}, expected ${s}`)}const D=Ui(0,t,.5);return{circuitJson:[...h,D],parameters:A}},sve=Gi.extend({fn:L(),num_pins:bA(6).default(6),w:L().default("2.1mm"),h:L().default("2.45mm"),p:L().default("0.5mm"),pl:L().default("0.675mm"),pw:L().default("0.35mm"),string:L().optional()}),rve=e=>{const A=sve.parse({...e,fn:"sot563"}),t=cA.parse(A.w),i=cA.parse(A.h),n=cA.parse(A.p),o=cA.parse(A.pl),s=cA.parse(A.pw),r=[];for(let B=0;B<6;B++){const{x:C,y:Q}=ztt(B+1,t,n,o);r.push(li(B+1,C,Q,o,s))}const a={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-t/2,y:i/2},{x:t/2,y:i/2}],stroke_width:.05,pcb_silkscreen_path_id:""},g={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-t/2,y:-i/2},{x:t/2,y:-i/2}],stroke_width:.05,pcb_silkscreen_path_id:""},c=ztt(1,t,n,o),I={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"pin_marker_1",route:[{x:c.x-o/2-.3,y:c.y},{x:c.x-o/2-.45,y:c.y+.15},{x:c.x-o/2-.45,y:c.y-.15},{x:c.x-o/2-.3,y:c.y}],stroke_width:.05,pcb_silkscreen_path_id:"pin_marker_1"},l=Ui(0,i/2+.4,.25);return{circuitJson:[...r,a,g,l,I],parameters:A}},ztt=(e,A,t,i)=>{const n=A/2-i/2;return e<=3?{x:-n,y:t-(e-1)*t}:{x:n,y:-t+(e-4)*t}},ave=WF({p:"1.27mm",w:"3.9mm",legsoutside:!0}),gve=e=>{const A=ave.parse({...e,num_pins:8});return{circuitJson:PY(A),parameters:A}},cve=WF({p:"1.27mm",w:"7.5mm",legsoutside:!0}),Ive=e=>{const A=cve.parse({...e,num_pins:16});return{circuitJson:PY(A),parameters:A}},lve=Gi.extend({fn:L(),num_pins:bA(3).default(3),w:L().default("1.2mm"),h:L().default("1.2mm"),pw:L().default("0.40mm"),pl:L().default("0.45mm"),p:L().default("0.575mm")}),Bve=e=>{const A=lve.parse(e),t=Qve(A),i=Ui(0,cA.parse(A.h),.2);return{circuitJson:[...t,i],parameters:A}},Cve=e=>{const{pn:A,p:t}=e;return A===1?{x:t,y:0}:A===2?{x:-t,y:-.4}:{x:-t,y:.4}},Qve=e=>{const A=[];for(let t=0;t<3;t++){const{x:i,y:n}=Cve({num_pins:e.num_pins,pn:t+1,w:Number.parseFloat(e.w),h:Number.parseFloat(e.h),pl:Number.parseFloat(e.pl),p:Number.parseFloat(e.p)});A.push(li(t+1,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},hve=Gi.extend({fn:L(),num_pins:bA(2).default(2),w:L().default("2.36mm"),h:L().default("1.22mm"),pl:L().default("0.9mm"),pw:L().default("1.2mm"),p:L().default("3.30mm")}),Eve=e=>{const A=hve.parse(e),t=Ui(0,cA.parse(A.h)/4+.4,.3);return{circuitJson:dve(A).concat(t),parameters:A}},uve=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},dve=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=uve({pn:t,p:Number.parseFloat(e.p)});A.push(li(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},pve=Gi.extend({fn:L(),p:cA.optional().default("2.54mm"),id:cA.optional().default("0.7mm"),od:cA.optional().default("1.4mm")}),fve=e=>{const A=pve.parse(e),{p:t,id:i,od:n}=A,o=[vo(1,-t/2,0,i,n),vo(2,t/2,0,i,n)],s={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-t/2+n+i/2,y:0},{x:t/2-n-i/2,y:0}],stroke_width:.1,pcb_silkscreen_path_id:""},r=Ui(0,1.5,.5);return{circuitJson:[...o,s,r],parameters:A}},yve=(e,A,t,i,n,o=.1)=>{const s=[],r=[],a=Math.max(1,Math.ceil(Math.PI*t/o)),g=Math.PI/a;for(let c=0;c<=a;c++){const I=c*g,l=e+Math.cos(I)*t,B=A+Math.sin(I)*t;l<e-i&&B>=A-n/2&&B<=A+n/2||s.push({x:l,y:B})}for(let c=0;c<=a;c++){const I=Math.PI+c*g,l=e+Math.cos(I)*t,B=A+Math.sin(I)*t;l<e-i&&B>=A-n/2&&B<=A+n/2||r.push({x:l,y:B})}return{topArc:s,bottomArc:r}},mve=Gi.extend({fn:L(),p:cA.optional().default("5mm"),id:cA.optional().default("0.8mm"),od:cA.optional().default("1.6mm"),ceramic:PA().optional(),electrolytic:PA().optional(),polarized:PA().optional()}),wve=e=>{const A=mve.parse(e),{p:t,id:i,od:n}=A;i===.8&&n===1.6&&(A.id=t===5?.8:t*.25,A.od=t===5?1.6:t*.5);const o=[vo(1,-t/2,0,A.id,A.od),vo(2,t/2,0,A.id,A.od)],s=t+.1,{topArc:r,bottomArc:a}=yve(0,0,s,A.od/2,A.od),g=.02*t,c={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:r,stroke_width:g,pcb_silkscreen_path_id:""},I={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:a,stroke_width:g,pcb_silkscreen_path_id:""},l={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:0,y:s},{x:0,y:-s}],stroke_width:g,pcb_silkscreen_path_id:""},B=.1*t,C=-(t+B+.04*t),Q=s-B-.08*t,h={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:C-B,y:Q},{x:C+B,y:Q}],stroke_width:g,pcb_silkscreen_path_id:""},E={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:C,y:Q-B},{x:C,y:Q+B}],stroke_width:g,pcb_silkscreen_path_id:""},u=Ui(0,s+.12*t,.1*t),d=[...o,c,I,l,u];return(A.electrolytic===!0||A.polarized===!0)&&d.push(h,E),{circuitJson:d,parameters:A}},VF=(e,A={})=>({type:"pcb_silkscreen_path",layer:A.layer||"top",pcb_component_id:A.pcb_component_id||"",pcb_silkscreen_path_id:A.pcb_silkscreen_path_id||"",route:e,stroke_width:A.stroke_width||.1}),Dve=Gi.extend({fn:bA("pushbutton"),w:cA.default(4.5),h:cA.default(6.5),id:cA.default(1),od:cA.default(1.2)}),Sve=e=>{const A=Dve.parse(e),t=A.w,i=A.h,n=A.id,o=[vo(1,-t/2,i/2,n,n*1.5),vo(2,-t/2,-i/2,n,n*1.5),vo(3,t/2,-i/2,n,n*1.5),vo(4,t/2,i/2,n,n*1.5)],s=[VF([{x:-t/2,y:-i/2},{x:-t/2,y:i/2}]),VF([{x:t/2,y:-i/2},{x:t/2,y:i/2}]),VF([{x:-t/2,y:0},{x:-t/5,y:0},{x:t/5*1/Math.sqrt(2),y:i/8}]),VF([{x:t/2,y:0},{x:t/5,y:0}])],r=Ui(0,i/2+.4,.5);return{circuitJson:[...o,...s,r],parameters:A}},Xtt=Gi.extend({fn:L(),w:cA.default("22.58mm"),h:cA.optional(),left:cA.optional().default(20),right:cA.optional().default(20),top:cA.optional().default(2),bottom:cA.optional().default(2),p:cA.default(cA.parse("2.54mm")),pw:cA.default(cA.parse("1.6mm")),pl:cA.default(cA.parse("2.4mm")),innerhole:PA().default(!1),innerholeedgedistance:cA.default(cA.parse("1.61mm")),silkscreenlabels:PA().default(!1),silkscreenlabelmargin:cA.default(cA.parse("0.1mm"))}),bve=e=>{const A=Xtt.parse(e);return A.left&&A.right?Math.max(A.left,A.right)*A.p:A.left?A.left*A.p:A.right?A.right*A.p:51},lV=(e,A,t)=>{let i=[];return t==="right"&&(i=[{x:e+1/2,y:A},{x:e-1/2,y:A+.6/2},{x:e-1/2,y:A-.6/2},{x:e+1/2,y:A}]),t==="left"&&(i=[{x:e-1/2,y:A},{x:e+1/2,y:A+.6/2},{x:e+1/2,y:A-.6/2},{x:e-1/2,y:A}]),t==="top"&&(i=[{x:e,y:A+1/2},{x:e-.6/2,y:A-1/2},{x:e+.6/2,y:A-1/2},{x:e,y:A+1/2}]),t==="bottom"&&(i=[{x:e,y:A-1/2},{x:e-.6/2,y:A+1/2},{x:e+.6/2,y:A+1/2},{x:e,y:A-1/2}]),i},xve=e=>{const A=Xtt.parse(e),t=A.h??bve(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=lV(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(vo(h+1+A.left+(A.bottom??0)+g,A.w/2,Q+h*A.p,r,a)),n.push(vo(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=lV(-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(vo(h+1+g,-A.w/2,Q-h*A.p,r,a)),n.push(vo(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=lV(Q-h*A.p,t/2-A.pl*1.4,"top")),i.push(li(h+1+A.left+A.right+(A.bottom??0),Q-h*A.p,t/2-A.pl/2,A.pw,A.pl)),A.silkscreenlabels){const E=h+1+A.left+A.right+(A.bottom??0),u=`pin${E}`;o.push({type:"pcb_silkscreen_text",pcb_silkscreen_text_id:`pin_${E}`,pcb_component_id:"1",layer:"top",anchor_position:{x:Q-h*A.p,y:t/2-A.pl-(I+A.silkscreenlabelmargin)},text:u,font_size:.7,font:"tscircuit2024",anchor_alignment:"center",ccw_rotation:270})}A.innerhole&&(n.push(vo(h+1+A.left+A.right+(A.bottom??0)+g,Q-h*A.p,t/2,r,a)),n.push(vo(h+1+A.left+A.right+(A.bottom??0)+g*2,Q-h*A.p,t/2-A.innerholeedgedistance,r,a)))}}if(A.bottom){const Q=-((A.bottom-1)/2)*A.p;for(let h=0;h<A.bottom;h++){if(h===0&&!A.left&&!A.silkscreenlabels&&(s=lV(Q+h*A.p,-t/2+A.pl*1.4,"bottom")),i.push(li(h+1+A.left,Q+h*A.p,-t/2+A.pl/2,A.pw,A.pl)),A.silkscreenlabels){const E=h+1+A.left,u=`pin${E}`;o.push({type:"pcb_silkscreen_text",pcb_silkscreen_text_id:`pin_${E}`,pcb_component_id:"1",layer:"top",anchor_position:{x:Q+h*A.p,y:-t/2+A.pl+(I+A.silkscreenlabelmargin)},text:u,font_size:.7,font:"tscircuit2024",anchor_alignment:"center",ccw_rotation:90})}A.innerhole&&(n.push(vo(h+1+A.left+g,Q+h*A.p,-t/2,r,a)),n.push(vo(h+1+A.left+g*2,Q+h*A.p,-t/2+A.innerholeedgedistance,r,a)))}}const l={type:"pcb_silkscreen_path",pcb_silkscreen_path_id:"pcb_silkscreen_triangle_1",pcb_component_id:"2",route:s,stroke_width:.1,layer:"top"},B={type:"pcb_silkscreen_path",pcb_silkscreen_path_id:"pcb_silkscreen_path_1",pcb_component_id:"1",route:[{x:-A.w/2,y:t/2},{x:A.w/2,y:t/2},{x:A.w/2,y:-t/2},{x:-A.w/2,y:-t/2},{x:-A.w/2,y:t/2}],stroke_width:.1,layer:"top"},C=Ui(0,t/1.8,t/25);return{circuitJson:[...i,...n,...o,B,...A.silkscreenlabels?[]:[l],C],parameters:A}},$tt=Gi.extend({fn:L(),w:cA.default("22.58mm"),h:cA.optional(),left:cA.optional().default(20),right:cA.optional().default(20),top:cA.optional().default(2),bottom:cA.optional().default(2),p:cA.default(cA.parse("2.54mm")),pw:cA.default(cA.parse("1.6mm")),pl:cA.default(cA.parse("3.2mm")),innerhole:PA().default(!1),innerholeedgedistance:cA.default(cA.parse("1.61mm"))}),_ve=e=>{const A=$tt.parse(e);return A.left&&A.right?Math.max(A.left,A.right)*A.p:A.left?A.left*A.p:A.right?A.right*A.p:51},kve=(e,A,t,i=1,n=.6)=>{const o=i/2,s=n/2;return{left:[{x:e+o,y:A},{x:e-o,y:A+s},{x:e-o,y:A-s},{x:e+o,y:A}],right:[{x:e-o,y:A},{x:e+o,y:A+s},{x:e+o,y:A-s},{x:e-o,y:A}],top:[{x:e,y:A-o},{x:e-s,y:A+o},{x:e+s,y:A+o},{x:e,y:A-o}],bottom:[{x:e,y:A+o},{x:e-s,y:A-o},{x:e+s,y:A-o},{x:e,y:A+o}]}[t]},vve=e=>{const A=$tt.parse(e),t=A.h??_ve(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=kve(-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(vo(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,-t/2+A.pl/2,A.pw,A.pl)),n.push({type:"pcb_silkscreen_text",pcb_silkscreen_text_id:`pin_${c}`,pcb_component_id:"1",layer:"top",anchor_position:{x:C-Q*A.p,y:-t/2+A.pl/2-3.2},text:`pin${c}`,font_size:.7,font:"tscircuit2024",anchor_alignment:"center"}),c++,A.innerhole&&o.push(vo(c+a,C-Q*A.p,-t/2+A.innerholeedgedistance,s,r))}if(A.right){const C=-((A.right-1)/2)*A.p;for(let Q=0;Q<A.right;Q++)i.push(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(vo(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,t/2-A.pl/2,A.pw,A.pl)),n.push({type:"pcb_silkscreen_text",pcb_silkscreen_text_id:`pin_${c}`,pcb_component_id:"1",layer:"top",anchor_position:{x:C+Q*A.p,y:t/2-A.pl/2+3.2},text:`pin${c}`,font_size:.7,font:"tscircuit2024",anchor_alignment:"center"}),c++,A.innerhole&&o.push(vo(c+a,C+Q*A.p,t/2-A.innerholeedgedistance,s,r))}const I={type:"pcb_silkscreen_path",pcb_silkscreen_path_id:"1",pcb_component_id:"1",layer:"top",route:g,stroke_width:.1},l={type:"pcb_silkscreen_path",pcb_silkscreen_path_id:"pcb_silkscreen_path_1",pcb_component_id:"1",route:[{x:-A.w/2-A.pl/3,y:t/2+A.pl/3},{x:A.w/2+A.pl/3,y:t/2+A.pl/3},{x:A.w/2+A.pl/3,y:-t/2-A.pl/3},{x:-A.w/2-A.pl/3,y:-t/2-A.pl/3},{x:-A.w/2-A.pl/3,y:t/2+A.pl/3}],stroke_width:.1,layer:"top"},B=Ui(0,t/1.8,t/25);return{circuitJson:[...o,...i,...n,l,I,B],parameters:A}},Fve=e=>(e.legsoutside=!0,e.pl||(e.pl=1.5),e.pw||(e.pw=.3),C2(e)),Aet=Gi.extend({fn:L(),w:cA.default("10mm"),h:cA.optional(),left:cA.optional().default(20),right:cA.optional().default(20),top:cA.optional().default(0),bottom:cA.optional().default(0),p:cA.default(cA.parse("2.54mm")),id:cA.optional().default(cA.parse("1mm")),od:cA.optional().default(cA.parse("1.5mm"))}),Mve=e=>{const A=Aet.parse(e);return A.left&&A.right?Math.max(A.left,A.right)*A.p:A.left?A.left*A.p:A.right?A.right*A.p:51},BV=(e,A,t,i=1,n=.6)=>{const o=i/2,s=n/2;return{left:[{x:e+o,y:A},{x:e-o,y:A+s},{x:e-o,y:A-s},{x:e+o,y:A}],right:[{x:e-o,y:A},{x:e+o,y:A+s},{x:e+o,y:A-s},{x:e-o,y:A}],top:[{x:e,y:A-o},{x:e-s,y:A+o},{x:e+s,y:A+o},{x:e,y:A-o}],bottom:[{x:e,y:A+o},{x:e-s,y:A-o},{x:e+s,y:A-o},{x:e,y:A+o}]}[t]},Gve=e=>{const A=Aet.parse(e),t=A.h??Mve(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=BV(A.w/2+o*1.4,c+I*A.p,"right")),i.push(vo(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=BV(-A.w/2-o*1.4,c+I*A.p,"left")),i.push(vo(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=BV(c+I*A.p,t/2+o*1.4,"top")),i.push(vo(I+1+A.right+(A.bottom??0)+A.left,c+I*A.p,t/2,n,o))}if(A.bottom){const c=-((A.bottom-1)/2)*A.p;for(let I=0;I<A.bottom;I++)I===0&&!A.left&&(s=BV(c+I*A.p,-t/2-o*1.4,"bottom")),i.push(vo(I+1+A.left,c+I*A.p,-t/2,n,o))}const r={type:"pcb_silkscreen_path",pcb_silkscreen_path_id:"1",pcb_component_id:"1",layer:"top",route:s,stroke_width:.1},a={type:"pcb_silkscreen_path",pcb_silkscreen_path_id:"pcb_silkscreen_path_1",pcb_component_id:"1",route:[{x:-A.w/2-o,y:t/2+o},{x:A.w/2+o,y:t/2+o},{x:A.w/2+o,y:-t/2-o},{x:-A.w/2-o,y:-t/2-o},{x:-A.w/2-o,y:t/2+o}],stroke_width:.1,layer:"top"},g=Ui(0,t/1.7,t/25);return{circuitJson:[...i,a,g,r],parameters:A}},tet=(e,A,t,i)=>Array.from({length:25},(n,o)=>{const s=o/24*Math.PI-Math.PI/2;return{x:e+(i==="right"?1:-1)*Math.cos(s)*t,y:A+Math.sin(s)*t}}),Rve=Gi.extend({fn:L(),p:cA.optional().default("4.88mm"),id:cA.optional().default("0.8mm"),od:cA.optional().default("1.5mm"),w:cA.optional().default("5.6mm"),h:cA.optional().default("3.5mm")}),Nve=e=>{const A=Rve.parse(e),{p:t,id:i,od:n,w:o,h:s}=A,r=s/2,a=[vo(1,-t/2,0,i,n),vo(2,t/2,0,i,n)],g=tet(-o/2,0,r,"left"),c=tet(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,t/4,.5);return{circuitJson:[...a,I,l],parameters:A}};Gi.extend({w:cA,h:cA});var Lve=e=>{const{w:A,h:t}=e,i=cr(A),n=cr(t);return{circuitJson:[li(1,0,0,i,n),Ui(0,n/2+.5,.2)],parameters:e}},jF=(e,A,t,i,n,o)=>({pcb_plated_hole_id:"",type:"pcb_plated_hole",shape:"pill",x:A,y:t,outer_width:cr(n),outer_height:cr(o),hole_width:cr(i),hole_height:cr(i),pcb_port_id:"",layers:["top","bottom"],port_hints:[e.toString()],ccw_rotation:0}),Uve=Gi.extend({fn:L(),num_pins:Ge([bA(3),bA(2)]).default(3),p:L().default("1.27mm"),id:L().default("0.72mm"),od:L().default("0.95mm"),w:L().default("4.5mm"),h:L().default("4.5mm"),inline:PA().default(!1),string:L().optional()}),Hve=(e,A,t)=>Array.from({length:25},(i,n)=>{const o=n/24*Math.PI;return{x:e+Math.cos(o)*t,y:A+Math.sin(o)*t}}),Yve=e=>{const A=e.string?.match(/^to92_(\d+)/),t=A?Number.parseInt(A[1],10):3,i=Uve.parse({...e,num_pins:t}),{p:n,id:o,od:s,w:r,h:a,inline:g}=i,c=Number.parseFloat(a)/2,I=Number.parseFloat(n),l=Number.parseFloat(o),B=Number.parseFloat(s),C=B,Q=B*(1.5/1.05);let h=[];if(i.num_pins===3)g?h=[Im({pn:1,x:-I,y:c-I,holeDiameter:l,rectPadWidth:B,rectPadHeight:Q}),jF(2,0,c-I,l,C,Q),jF(3,I,c-I,l,C,Q)]:h=[Im({pn:1,x:-I,y:c-I,holeDiameter:l,rectPadWidth:B,rectPadHeight:B}),vo(2,0,c,l,B),vo(3,I,c-I,l,B)];else if(i.num_pins===2)h=[Im({pn:1,x:-I,y:c-I,holeDiameter:l,rectPadWidth:C,rectPadHeight:Q}),jF(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=Hve(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}},Jve=Gi.extend({fn:L(),num_pins:bA(2).default(2),w:L().default("2.15mm"),h:L().default("1.20mm"),pl:L().default("0.5mm"),pw:L().default("0.6mm"),p:L().default("1.4mm")}),Tve=e=>{const A=Jve.parse(e),t=Ui(0,cA.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:cA.parse(A.p)/2,y:cA.parse(A.h)/2},{x:-cA.parse(A.w)/2-.2,y:cA.parse(A.h)/2},{x:-cA.parse(A.w)/2-.2,y:-cA.parse(A.h)/2},{x:cA.parse(A.p)/2,y:-cA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:Kve(A).concat(i,t),parameters:A}},Pve=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},Kve=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=Pve({pn:t,p:Number.parseFloat(e.p)});A.push(li(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},qve=WF({w:"7.05mm",p:"1.27mm",pw:"0.65mm",pl:"1.975mm"}),Ove=e=>{const A=qve.parse(e),t=[];for(let s=0;s<A.num_pins;s++){const{x:r,y:a}=juA({num_pins:A.num_pins,pn:s+1,w:A.w,p:A.p??1.27,pl:A.pl,widthincludeslegs:!0});t.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:[...t,n,o],parameters:A}},Wve=Gi.extend({fn:L(),num_pins:bA(2).default(2),w:L().default("5.0mm"),h:L().default("2.30mm"),pl:L().default("1.25mm"),pw:L().default("2mm"),p:L().default("3.75mm")}),Zve=e=>{const A=Wve.parse(e),t=Ui(0,cA.parse(A.h)/2+1,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:cA.parse(A.p)/2+.5,y:cA.parse(A.h)/2+.5},{x:-cA.parse(A.w)/2-.5,y:cA.parse(A.h)/2+.5},{x:-cA.parse(A.w)/2-.5,y:-cA.parse(A.h)/2-.5},{x:cA.parse(A.p)/2+.5,y:-cA.parse(A.h)/2-.5}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:jve(A).concat(i,t),parameters:A}},Vve=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},jve=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=Vve({pn:t,p:Number.parseFloat(e.p)});A.push(li(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},zve=Gi.extend({fn:L(),num_pins:bA(2).default(2),w:L().default("4.4mm"),h:L().default("2.1mm"),pl:L().default("1.2mm"),pw:L().default("1.2mm"),p:L().default("2.9mm")}),Xve=e=>{const A=zve.parse(e),t=Ui(0,cA.parse(A.h)-.5,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:cA.parse(A.p)/2,y:cA.parse(A.h)/2},{x:-cA.parse(A.w)/2-.2,y:cA.parse(A.h)/2},{x:-cA.parse(A.w)/2-.2,y:-cA.parse(A.h)/2},{x:cA.parse(A.p)/2,y:-cA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:AFe(A).concat(i,t),parameters:A}},$ve=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},AFe=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=$ve({pn:t,p:Number.parseFloat(e.p)});A.push(li(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},tFe=Gi.extend({fn:L(),num_pins:bA(2).default(2),w:L().default("3.30mm"),h:L().default("1.80mm"),pl:L().default("0.60mm"),pw:L().default("0.45mm"),p:L().default("2.1mm")}),eFe=e=>{const A=tFe.parse(e),t=Ui(0,cA.parse(A.h)-.5,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:cA.parse(A.p)/2,y:cA.parse(A.h)/2},{x:-cA.parse(A.w)/2,y:cA.parse(A.h)/2},{x:-cA.parse(A.w)/2,y:-cA.parse(A.h)/2},{x:cA.parse(A.p)/2,y:-cA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:nFe(A).concat(i,t),parameters:A}},iFe=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},nFe=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=iFe({pn:t,p:Number.parseFloat(e.p)});A.push(li(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},oFe=Gi.extend({fn:L(),num_pins:bA(2).default(2),w:L().default("1.4mm"),h:L().default("0.9mm"),pl:L().default("0.36mm"),pw:L().default("0.25mm"),p:L().default("0.85mm")}),sFe=e=>{const A=oFe.parse(e),t=Ui(0,cA.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:cA.parse(A.p)/2+.15,y:cA.parse(A.h)/2},{x:-cA.parse(A.w)/2-.15,y:cA.parse(A.h)/2},{x:-cA.parse(A.w)/2-.15,y:-cA.parse(A.h)/2},{x:cA.parse(A.p)/2+.15,y:-cA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:aFe(A).concat(i,t),parameters:A}},rFe=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},aFe=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=rFe({pn:t,p:Number.parseFloat(e.p)});A.push(li(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},gFe=Gi.extend({fn:L(),num_pins:bA(2).default(2),w:L().default("1.3mm"),h:L().default("0.9mm"),pl:L().default("0.4mm"),pw:L().default("0.7mm"),p:L().default("0.7mm")}),cFe=e=>{const A=gFe.parse(e),t=Ui(0,cA.parse(A.h)+.1,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:cA.parse(A.p)/2+.2,y:cA.parse(A.h)/2+.2},{x:-cA.parse(A.w)/2-.2,y:cA.parse(A.h)/2+.2},{x:-cA.parse(A.w)/2-.2,y:-cA.parse(A.h)/2-.2},{x:cA.parse(A.p)/2+.2,y:-cA.parse(A.h)/2-.2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:lFe(A).concat(i,t),parameters:A}},IFe=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},lFe=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=IFe({pn:t,p:Number.parseFloat(e.p)});A.push(li(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},BFe=Gi.extend({fn:L(),num_pins:bA(2).default(2),w:L().default("3,05mm"),h:L().default("1.65mm"),pl:L().default("0.6mm"),pw:L().default("0.6mm"),pad_spacing:L().default("2.2mm")}),CFe=e=>{const A=BFe.parse(e),t=Ui(0,cA.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:cA.parse(A.pad_spacing)/2,y:cA.parse(A.h)/2},{x:-cA.parse(A.w)/2-.2,y:cA.parse(A.h)/2},{x:-cA.parse(A.w)/2-.2,y:-cA.parse(A.h)/2},{x:cA.parse(A.pad_spacing)/2,y:-cA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:hFe(A).concat(i,t),parameters:A}},QFe=e=>{const{pn:A,pad_spacing:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},hFe=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=QFe({pn:t,pad_spacing:Number.parseFloat(e.pad_spacing)});A.push(li(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},EFe=Gi.extend({fn:L(),num_pins:bA(2).default(2),w:L().default("4.4mm"),h:L().default("2.1mm"),pl:L().default("1.10mm"),pw:L().default("1.10mm"),p:L().default("2.8mm")}),uFe=e=>{const A=EFe.parse(e),t=Ui(0,cA.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:cA.parse(A.p)/2,y:cA.parse(A.h)/2},{x:-cA.parse(A.w)/2-.2,y:cA.parse(A.h)/2},{x:-cA.parse(A.w)/2-.2,y:-cA.parse(A.h)/2},{x:cA.parse(A.p)/2,y:-cA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:pFe(A).concat(i,t),parameters:A}},dFe=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},pFe=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=dFe({pn:t,p:Number.parseFloat(e.p)});A.push(li(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},fFe=Gi.extend({fn:L(),num_pins:bA(2).default(2),w:L().default("4.4mm"),h:L().default("2.1mm"),pl:L().default("0.91mm"),pw:L().default("1.22mm"),p:L().default("3.146mm")}),yFe=e=>{const A=fFe.parse(e),t=Ui(0,cA.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:cA.parse(A.p)/2,y:cA.parse(A.h)/2},{x:-cA.parse(A.w)/2-.2,y:cA.parse(A.h)/2},{x:-cA.parse(A.w)/2-.2,y:-cA.parse(A.h)/2},{x:cA.parse(A.p)/2,y:-cA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:wFe(A).concat(i,t),parameters:A}},mFe=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},wFe=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=mFe({pn:t,p:Number.parseFloat(e.p)});A.push(li(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},DFe=Gi.extend({fn:L(),num_pins:bA(2).default(2),w:L().default("1.80mm"),h:L().default("1.00mm"),pl:L().default("0.66mm"),pw:L().default("0.5mm"),p:L().default("0.8mm")}),SFe=e=>{const A=DFe.parse(e),t=Ui(0,cA.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:cA.parse(A.p)/2,y:cA.parse(A.h)/2},{x:-cA.parse(A.w)/2-.1,y:cA.parse(A.h)/2},{x:-cA.parse(A.w)/2-.1,y:-cA.parse(A.h)/2},{x:cA.parse(A.p)/2,y:-cA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:xFe(A).concat(i,t),parameters:A}},bFe=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},xFe=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=bFe({pn:t,p:Number.parseFloat(e.p)});A.push(li(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},_Fe=Gi.extend({fn:L(),num_pins:bA(2).default(2),w:L().default("6.2mm"),h:L().default("3.4mm"),pl:L().default("1.4mm"),pw:L().default("2.1mm"),p:L().default("4.4mm")}),kFe=e=>{const A=_Fe.parse(e),t=Ui(0,cA.parse(A.h)/2+.4,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:cA.parse(A.p)/2,y:cA.parse(A.h)/2},{x:-cA.parse(A.w)/2-.2,y:cA.parse(A.h)/2},{x:-cA.parse(A.w)/2-.2,y:-cA.parse(A.h)/2},{x:cA.parse(A.p)/2,y:-cA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:FFe(A).concat(i,t),parameters:A}},vFe=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},FFe=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=vFe({pn:t,p:Number.parseFloat(e.p)});A.push(li(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},MFe=Gi.extend({fn:L(),num_pins:Ge([bA(3),bA(5)]).default(3),w:L().default("4.20mm"),h:L().default("4.80mm"),pl:L().default("1.3mm"),pw:L().default("0.9mm"),p:L().default("1.5mm"),string:L().optional()}),GFe=e=>{const A=[],t=Number.parseFloat(e.p),i=Number.parseFloat(e.pw),n=Number.parseFloat(e.w),o=Number.parseFloat(e.pl),s=.175,r=(o-(o+s))/2;A.push(li(1,-n/2+r,t,o,i),li(2,-n/2,0,o+s,i),li(3,-n/2+r,-t,o,i));const a=Ui(0,0,.3),g=Number.parseFloat(e.w)/2-1,c=Number.parseFloat(e.h)/2,I={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-g,y:c},{x:g,y:c},{x:g,y:c/2+.5}],type:"pcb_silkscreen_path",stroke_width:.1},l={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_2",route:[{x:-g,y:-c},{x:g,y:-c},{x:g,y:-c/2-.5}],type:"pcb_silkscreen_path",stroke_width:.1};return[...A,I,l,a]},RFe=e=>{const A=[];Number.parseFloat(e.p),Number.parseFloat(e.pw),Number.parseFloat(e.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 t=Ui(0,Number.parseFloat(e.h)/2+.5,.3),i=Number.parseFloat(e.w)/2-1,n=Number.parseFloat(e.h)/2,o={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-i,y:n},{x:i,y:n}],type:"pcb_silkscreen_path",stroke_width:.1},s={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_2",route:[{x:-i,y:-n},{x:i,y:-n}],type:"pcb_silkscreen_path",stroke_width:.1};return[...A,o,s,t]},NFe=e=>{const A=e.string?.match(/^sot89_(\d+)/),t=A?Number.parseInt(A[1],10):3,i=MFe.parse({...e,num_pins:t});if(i.num_pins===3)return{circuitJson:GFe(i),parameters:i};if(i.num_pins===5)return{circuitJson:RFe(i),parameters:i};throw new Error("Invalid number of pins for SOT89")},LFe=Gi.extend({fn:L(),p:cA.optional().default("5.0mm"),id:cA.optional().default("1.0mm"),od:cA.optional().default("1.9mm"),w:cA.optional().default("13mm"),h:cA.optional().default("7mm"),num_pins:qA().optional(),string:L().optional()}),eet=e=>{const A=LFe.parse(e),{id:t,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,m)=>{const w=r%2===0?(m-r/2+.5)*B:(m-Math.floor(r/2))*B;return vo(m+1,w,a,t,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}}},$uA=2.54,UFe=Gi.extend({fn:L(),id:cA.optional().default("1.2mm"),od:cA.optional().default("1.905mm"),ph:cA.optional().default("2mm"),w:cA.optional().default("13mm"),h:cA.optional().default("7mm"),num_pins:qA().optional(),string:L().optional()}),HFe=e=>{const A=UFe.parse(e),t=A.num_pins??Number.parseInt(A.string?.match(/^to220f(?:_|-)(\d+)/i)?.[1]??"3"),i=eet({...A,fn:"to220",string:A.string?.replace(/^to220f/i,"to220"),num_pins:t}),n=-1,o=Array.from({length:t},(r,a)=>{const g=t%2===0?(a-t/2+.5)*$uA:(a-Math.floor(t/2))*$uA;return a===0?Im({pn:1,x:g,y:n,holeDiameter:A.id,rectPadWidth:A.od,rectPadHeight:A.ph}):jF(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:$uA,num_pins:t}}},YFe=Gi.extend({fn:L(),num_pins:bA(2).default(2),w:L().default("5.40mm"),h:L().default("2.30mm"),pl:L().default("1.30mm"),pw:L().default("1.70mm"),p:L().default("3.5mm")}),JFe=e=>{const A=YFe.parse(e),t=Ui(0,cA.parse(A.h)/2+.4,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:cA.parse(A.p)/2,y:cA.parse(A.h)/2},{x:-cA.parse(A.w)/2,y:cA.parse(A.h)/2},{x:-cA.parse(A.w)/2,y:-cA.parse(A.h)/2},{x:cA.parse(A.p)/2,y:-cA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:PFe(A).concat(i,t),parameters:A}},TFe=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},PFe=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=TFe({pn:t,p:Number.parseFloat(e.p)});A.push(li(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},KFe=Gi.extend({fn:L(),num_pins:bA(2).default(2),w:L().default("1.90mm"),h:L().default("1.33mm"),pl:L().default("0.5mm"),pw:L().default("0.7mm"),p:L().default("0.8mm")}),qFe=e=>{const A=KFe.parse(e),t=Ui(0,cA.parse(A.h)+.1,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:cA.parse(A.p)/2+.1,y:cA.parse(A.h)/2},{x:-cA.parse(A.w)/2,y:cA.parse(A.h)/2},{x:-cA.parse(A.w)/2,y:-cA.parse(A.h)/2},{x:cA.parse(A.p)/2+.1,y:-cA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:WFe(A).concat(i,t),parameters:A}},OFe=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},WFe=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=OFe({pn:t,p:Number.parseFloat(e.p)});A.push(li(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},ZFe=Gi.extend({fn:L(),num_pins:bA(2).default(2),w:L().default("7.0mm"),h:L().default("3.35mm"),pl:L().default("1.50mm"),pw:L().default("2.70mm"),p:L().default("4.8mm")}),VFe=e=>{const A=ZFe.parse(e),t=Ui(0,cA.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:cA.parse(A.p)/2,y:cA.parse(A.h)/2},{x:-cA.parse(A.w)/2,y:cA.parse(A.h)/2},{x:-cA.parse(A.w)/2,y:-cA.parse(A.h)/2},{x:cA.parse(A.p)/2,y:-cA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:zFe(A).concat(i,t),parameters:A}},jFe=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},zFe=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=jFe({pn:t,p:Number.parseFloat(e.p)});A.push(li(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},XFe=Gi.extend({fn:L(),num_pins:bA(2).default(2),w:L().default("3.0mm"),h:L().default("1.80mm"),pl:L().default("0.80mm"),pw:L().default("1.20mm"),p:L().default("1.6mm")}),$Fe=e=>{const A=XFe.parse(e),t=Ui(0,cA.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:cA.parse(A.p)/2,y:cA.parse(A.h)/2},{x:-cA.parse(A.w)/2-.1,y:cA.parse(A.h)/2},{x:-cA.parse(A.w)/2-.1,y:-cA.parse(A.h)/2},{x:cA.parse(A.p)/2,y:-cA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:tMe(A).concat(i,t),parameters:A}},AMe=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},tMe=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=AMe({pn:t,p:Number.parseFloat(e.p)});A.push(li(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},eMe=Gi.extend({fn:L(),num_pins:bA(2).default(2),w:L().default("7.10mm"),h:L().default("3.40mm"),pl:L().default("2.45mm"),pw:L().default("1.80mm"),p:L().default("4.05mm")}),iMe=e=>{const A=eMe.parse(e),t=Ui(0,cA.parse(A.h)/2+.5,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:cA.parse(A.p)/2,y:cA.parse(A.h)/2},{x:-cA.parse(A.w)/2-.5,y:cA.parse(A.h)/2},{x:-cA.parse(A.w)/2-.5,y:-cA.parse(A.h)/2},{x:cA.parse(A.p)/2,y:-cA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:oMe(A).concat(i,t),parameters:A}},nMe=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},oMe=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=nMe({pn:t,p:Number.parseFloat(e.p)});A.push(li(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},sMe=Gi.extend({fn:L(),num_pins:bA(2).default(2),w:L().default("4.80mm"),h:L().default("2.10mm"),pl:L().default("1.30mm"),pw:L().default("1.40mm"),p:L().default("2.9mm")}),rMe=e=>{const A=sMe.parse(e),t=Ui(0,cA.parse(A.h)-.5,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:cA.parse(A.p)/2,y:cA.parse(A.h)/2},{x:-cA.parse(A.w)/2,y:cA.parse(A.h)/2},{x:-cA.parse(A.w)/2,y:-cA.parse(A.h)/2},{x:cA.parse(A.p)/2,y:-cA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:gMe(A).concat(i,t),parameters:A}},aMe=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},gMe=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=aMe({pn:t,p:Number.parseFloat(e.p)});A.push(li(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},cMe=Gi.extend({fn:L(),num_pins:bA(2).default(2),w:L().default("7.30mm"),h:L().default("4.40mm"),pl:L().default("2.50mm"),pw:L().default("2.30mm"),p:L().default("4.30mm")}),IMe=e=>{const A=cMe.parse(e),t=Ui(0,cA.parse(A.h)/2+.5,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:cA.parse(A.p)/2,y:cA.parse(A.h)/2},{x:-cA.parse(A.w)/2-.1,y:cA.parse(A.h)/2},{x:-cA.parse(A.w)/2-.1,y:-cA.parse(A.h)/2},{x:cA.parse(A.p)/2,y:-cA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:BMe(A).concat(i,t),parameters:A}},lMe=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},BMe=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=lMe({pn:t,p:Number.parseFloat(e.p)});A.push(li(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},CMe=Gi.extend({fn:L(),num_pins:bA(2).default(2),w:L().default("10.70mm"),h:L().default("6.60mm"),pl:L().default("3.30mm"),pw:L().default("2.50mm"),p:L().default("6.80mm")}),QMe=e=>{const A=CMe.parse(e),t=Ui(0,3,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:cA.parse(A.p)/2,y:cA.parse(A.h)/2-.8},{x:-cA.parse(A.w)/2-.8,y:cA.parse(A.h)/2-.8},{x:-cA.parse(A.w)/2-.8,y:-cA.parse(A.h)/2+.8},{x:cA.parse(A.p)/2,y:-cA.parse(A.h)/2+.8}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:EMe(A).concat(i,t),parameters:A}},hMe=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},EMe=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=hMe({pn:t,p:Number.parseFloat(e.p)});A.push(li(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},uMe=Gi.extend({fn:L(),num_pins:qA().default(4),w:L().default("8.50mm"),h:L().default("6.90mm"),pl:L().default("2mm"),pw:L().default("1.5mm"),p:L().default("2.30mm"),string:L().optional()}),dMe=e=>{const A=e.string?.match(/^sot223_(\d+)/),t=A?Number.parseInt(A[1],10):4;if(t===8){const n=yMe.parse({...e,num_pins:t});return{circuitJson:PY(n),parameters:n}}const i=uMe.parse({...e,num_pins:t});if(i.num_pins===4)return{circuitJson:fMe(i),parameters:i};if(i.num_pins===5)return{circuitJson:wMe(i),parameters:i};if(i.num_pins===6)return{circuitJson:SMe(i),parameters:i};throw new Error("Invalid number of pins")},pMe=e=>{const{pn:A,w:t,p:i}=e;return A===1?{x:-t/2+1.1,y:i}:A===2?{x:-t/2+1.1,y:0}:A===3?{x:-t/2+1.1,y:-i}:{x:t/2-1.1,y:0}},fMe=e=>{const A=[];for(let r=0;r<e.num_pins;r++){const{x:a,y:g}=pMe({num_pins:e.num_pins,pn:r+1,w:Number.parseFloat(e.w),h:Number.parseFloat(e.h),pl:Number.parseFloat(e.pl),p:Number.parseFloat(e.p)}),c=r===3?3.8:Number.parseFloat(e.pw);A.push(li(r+1,a,g,Number.parseFloat(e.pl),c))}const t=Ui(0,0,.3),i=Number.parseFloat(e.w)/2-2.4,n=Number.parseFloat(e.h)/2,o={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-i,y:n},{x:i,y:n},{x:i,y:n/2+.5}],type:"pcb_silkscreen_path",stroke_width:.1},s={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_2",route:[{x:-i,y:-n},{x:i,y:-n},{x:i,y:-n/2-.5}],type:"pcb_silkscreen_path",stroke_width:.1};return[...A,o,s,t]},yMe=WF({p:"0.90mm",w:"2.8mm",legsoutside:!0}),mMe=e=>{const{p:A,pn:t,w:i}=e;if(t===1)return{x:-i/2+1.2,y:A/2+A};if(t===2)return{x:-i/2+1.2,y:A/2};if(t===3)return{x:-i/2+1.2,y:-A/2};if(t===4)return{x:-i/2+1.2,y:-A/2-A};if(t===5)return{x:i/2-1,y:0};throw new Error("Invalid pin number")},wMe=e=>{const A=[];for(let r=1;r<=e.num_pins;r++){const{x:a,y:g}=mMe({h:Number.parseFloat(e.h),p:1.5,pn:r,w:Number.parseFloat(e.w)});let c=Number.parseFloat(e.pw),I=Number.parseFloat(e.pl);r===5?(c=3.4,I=1.8):(c=1,I=2.2),A.push(li(r,a,g,I,c))}const t=Number.parseFloat(e.w)/2-2.4,i=Number.parseFloat(e.h)/2,n={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-t,y:i},{x:t,y:i},{x:t,y:i/2+.5}],type:"pcb_silkscreen_path",stroke_width:.1},o={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_2",route:[{x:-t,y:-i},{x:t,y:-i},{x:t,y:-i/2-.5}],type:"pcb_silkscreen_path",stroke_width:.1},s=Ui(0,0,.3);return[...A,n,o,s]},DMe=e=>{const{p:A,pn:t,w:i}=e;if(t===1)return{x:-i/2+1.2,y:2*A};if(t===2)return{x:-i/2+1.2,y:A};if(t===3)return{x:-i/2+1.2,y:0};if(t===4)return{x:-i/2+1.2,y:-A};if(t===5)return{x:-i/2+1.2,y:-2*A};if(t===6)return{x:i/2-1.175,y:0};throw new Error("Invalid pin number")},SMe=e=>{const A=[];for(let r=1;r<=e.num_pins;r++){const{x:a,y:g}=DMe({h:Number.parseFloat(e.h),p:1.3,pn:r,w:8.7});let c=Number.parseFloat(e.pw),I=Number.parseFloat(e.pl);r===6?(c=3.4,I=2.15):(c=.6,I=2.2),A.push(li(r,a,g,I,c))}const t=Number.parseFloat(e.w)/2-2.4,i=Number.parseFloat(e.h)/2,n={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-t,y:i},{x:t,y:i},{x:t,y:i/2+.5}],type:"pcb_silkscreen_path",stroke_width:.1},o={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_2",route:[{x:-t,y:-i},{x:t,y:-i},{x:t,y:-i/2-.5}],type:"pcb_silkscreen_path",stroke_width:.1},s=Ui(0,0,.3);return[...A,n,o,s]},bMe=Gi.extend({fn:L(),num_pins:qA().default(3),w:L().default("3.40mm"),h:L().default("3.30mm"),pl:L().default("1mm"),pw:L().default("0.7mm"),p:L().default("1.2mm"),string:L().optional()}),xMe=e=>{const A=e.string?.match(/^sot23w_(\d+)/),t=A?Number.parseInt(A[1],3):3,i=bMe.parse({...e,num_pins:t});if(i.num_pins===3)return{circuitJson:kMe(i),parameters:i};throw new Error("Invalid number of pins")},_Me=e=>{const{pn:A,p:t}=e;return A===1?{x:-t,y:.95}:A===2?{x:-t,y:-.95}:{x:t,y:0}},kMe=e=>{const A=[];for(let r=0;r<e.num_pins;r++){const{x:a,y:g}=_Me({num_pins:e.num_pins,pn:r+1,w:Number.parseFloat(e.w),h:Number.parseFloat(e.h),pl:Number.parseFloat(e.pl),p:Number.parseFloat(e.p)});A.push(li(r+1,a,g,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}const t=Ui(0,Number.parseInt(e.h)/2+1,.3),i=Number.parseFloat(e.w)/2-1,n=Number.parseFloat(e.h)/2,o={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-i,y:n},{x:i+.3,y:n},{x:i+.3,y:n/2}],type:"pcb_silkscreen_path",stroke_width:.1},s={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_2",route:[{x:-i,y:-n},{x:i+.3,y:-n},{x:i+.3,y:-n/2}],type:"pcb_silkscreen_path",stroke_width:.1};return[...A,o,s,t]},vMe=Gi.extend({fn:L(),num_pins:Ge([bA(3),bA(2)]).default(3),p:L().default("1.27mm"),id:L().default("0.72mm"),od:L().default("0.95mm"),w:L().default("2.5mm"),h:L().default("4.2mm"),string:L().optional()}),FMe=e=>{const{p:A,id:t,od:i,w:n,h:o}=e,s=Number.parseFloat(o)/2,r=Number.parseFloat(A);return[vo(1,-r,s-r,t,i),vo(2,0,s-r,t,i),vo(3,r,s-r,t,i)]},MMe=e=>{const{p:A,id:t,od:i,h:n}=e,o=Number.parseFloat(n)/2,s=Number.parseFloat(A);return[vo(1,-s,o-s,t,i),vo(2,s,o-s,t,i)]},GMe=e=>{const A=e.string?.match(/^to92s_(\d+)/),t=A?Number.parseInt(A[1],10):3,i=vMe.parse({...e,num_pins:t});let n=[];if(i.num_pins===3)n=FMe(i);else if(i.num_pins===2)n=MMe(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}},RMe=Gi.extend({fn:L(),p:cA.optional(),id:cA.optional(),pw:cA.optional(),pl:cA.optional(),w:cA.optional(),h:cA.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:L().optional()}),NMe={ph:{p:cA.parse("2.2mm"),id:cA.parse("0.70mm"),pw:cA.parse("1.20mm"),pl:cA.parse("1.20mm"),w:cA.parse("6mm"),h:cA.parse("5mm")},sh:{p:cA.parse("1mm"),pw:cA.parse("0.6mm"),pl:cA.parse("1.55mm"),w:cA.parse("5.8mm"),h:cA.parse("7.8mm")},zh:{p:cA.parse("1.5mm"),id:cA.parse("0.73mm"),pw:cA.parse("1.03mm"),pl:cA.parse("1.73mm"),w:cA.parse("3mm"),h:cA.parse("3.5mm")}};function LMe(e){return e.sh?"sh":e.ph?"ph":e.zh?"zh":"ph"}function UMe(e,A,t,i,n,o){const s=[];if(e==="ph"){const r=-((A-1)/2)*t;for(let a=0;a<A;a++){const g=r+a*t;s.push(Im({pn:a+1,x:g,y:2,holeDiameter:i,rectPadWidth:n,rectPadHeight:o}))}}else if(e==="zh"){const r=-((A-1)/2)*t;for(let a=0;a<A;a++){const g=r+a*t;a===0?s.push(Im({pn:a+1,x:g,y:0,holeDiameter:i,rectPadWidth:n,rectPadHeight:o,rectBorderRadius:.12499977})):s.push(jF(a+1,g,0,i,n,o))}}else{const r=-((A-1)/2)*t;for(let g=0;g<A;g++){const c=r+g*t;s.push(li(g+1,c,-1.325,n,o))}const a=(A-1)/2*t+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 HMe(e,A,t,i,n){if(e==="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(e==="zh"&&i&&n){const o=(i-1)*n,s=-o/2-1.5,r=o/2+1.5,a=-t/2,g=t/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 YMe=e=>{const A=RMe.parse(e),t=LMe(A),i=NMe[t],n=A.p??i.p,o=A.id??i.id,s=A.pw??i.pw,r=A.pl??i.pl,a=A.w??i.w,g=A.h??i.h;let c;const I=e.num_pins;typeof I=="number"&&(c=I);const l=typeof e.string=="string"?e.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=UMe(t,c,n,o,s,r),h=HMe(t,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:t==="sh",ph:t==="ph",zh:t==="zh"}}},JMe=Gi.extend({fn:L(),num_pins:bA(2).default(2),w:L().default("3.30mm"),h:L().default("1.70mm"),pl:L().default("0.80mm"),pw:L().default("1mm"),p:L().default("1.90mm")}),TMe=e=>{const A=JMe.parse(e),t=Ui(0,cA.parse(A.h)/2+.5,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:cA.parse(A.p)/2,y:cA.parse(A.h)/2},{x:-cA.parse(A.w)/2,y:cA.parse(A.h)/2},{x:-cA.parse(A.w)/2,y:-cA.parse(A.h)/2},{x:cA.parse(A.p)/2,y:-cA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:KMe(A).concat(i,t),parameters:A}},PMe=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},KMe=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=PMe({pn:t,p:Number.parseFloat(e.p)});A.push(li(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},qMe=e=>{switch(e){case 8:return{w:"3.06mm",h:"3.14mm",p:"0.65mm",pl:"1.6mm",pw:"0.5mm"};case 10:return{w:"3.10mm",h:"3.33mm",p:"0.5mm",pl:"1.45mm",pw:"0.3mm"};default:return{w:"3.06mm",h:"3.14mm",p:"0.65mm",pl:"1.6mm",pw:"0.5mm"}}},OMe=Gi.extend({fn:L(),num_pins:Ge([bA(8),bA(10)]).default(8),w:L().optional(),h:L().optional(),p:L().optional(),pl:L().optional(),pw:L().optional(),string:L().optional()}),WMe=e=>{const A=OMe.parse(e),t=qMe(A.num_pins),i=cA.parse(A.w||t.w),n=cA.parse(A.h||t.h),o=cA.parse(A.p||t.p),s=cA.parse(A.pl||t.pl),r=cA.parse(A.pw||t.pw),a=[],g=A.num_pins/2;for(let u=0;u<A.num_pins;u++){const{x:d,y:f}=iet(A.num_pins,u+1,i,o),m=u<g?u+1:A.num_pins-(u-g);a.push(li(m,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=iet(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}},iet=(e,A,t,i)=>{const n=e/2,o=(A-1)%n,s=A<=n?-1:1,r=(n-1)/2-o;return{x:s*cA.parse(e===8?"1.8mm":"2.2mm"),y:r*i}},ZMe=e=>{switch(e){case 10:return{w:"3.10mm",h:"3.32mm",p:"0.5mm",pl:"1.63mm",pw:"0.33mm"};case 12:return{w:"3mm",h:"4mm",p:"0.65mm",pl:"0.88mm",pw:"0.4mm"};case 16:return{w:"3.10mm",h:"4mm",p:"0.5mm",pl:"0.88mm",pw:"0.3mm"};default:return{w:"3.10mm",h:"3.32mm",p:"0.65mm",pl:"1.63mm",pw:"0.4mm"}}},VMe=Gi.extend({fn:L(),num_pins:Ge([bA(8),bA(10),bA(12),bA(16)]).default(8),w:L().optional(),h:L().optional(),p:L().optional(),pl:L().optional(),pw:L().optional(),string:L().optional()}),net=(e,A,t,i)=>{const n=e/2,o=(A-1)%n,s=A<=n?-1:1,r=(n-1)/2-o;return{x:s*cA.parse("2mm"),y:r*i}},jMe=e=>{const A=VMe.parse(e),t=ZMe(A.num_pins),i=cA.parse(A.w||t.w),n=cA.parse(A.h||t.h),o=cA.parse(A.p||t.p),s=cA.parse(A.pl||t.pl),r=cA.parse(A.pw||t.pw),a=[];for(let E=0;E<A.num_pins;E++){const{x:u,y:d}=net(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=net(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}},zMe=Gi.extend({fn:L(),num_pins:bA(2).default(2),w:L().default("3.8mm"),h:L().default("1.65mm"),pl:L().default("1.2mm"),pw:L().default("1.2mm"),pad_spacing:L().default("2.6mm")}),XMe=e=>{const A=zMe.parse(e),t=Ui(0,cA.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:cA.parse(A.pad_spacing)/2,y:cA.parse(A.h)/2},{x:-cA.parse(A.w)/2-.2,y:cA.parse(A.h)/2},{x:-cA.parse(A.w)/2-.2,y:-cA.parse(A.h)/2},{x:cA.parse(A.pad_spacing)/2,y:-cA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:AGe(A).concat(i,t),parameters:A}},$Me=e=>{const{pn:A,pad_spacing:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},AGe=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=$Me({pn:t,pad_spacing:Number.parseFloat(e.pad_spacing)});A.push(li(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},tGe=Gi.extend({fn:L(),num_pins:bA(2).default(2),w:L().default("3.20mm"),h:L().default("1.65mm"),pl:L().default("0.8mm"),pw:L().default("0.9mm"),pad_spacing:L().default("2.1mm")}),eGe=e=>{const A=tGe.parse(e),t=Ui(0,cA.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:cA.parse(A.pad_spacing)/2,y:cA.parse(A.h)/2},{x:-cA.parse(A.w)/2-.2,y:cA.parse(A.h)/2},{x:-cA.parse(A.w)/2-.2,y:-cA.parse(A.h)/2},{x:cA.parse(A.pad_spacing)/2,y:-cA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:nGe(A).concat(i,t),parameters:A}},iGe=e=>{const{pn:A,pad_spacing:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},nGe=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=iGe({pn:t,pad_spacing:Number.parseFloat(e.pad_spacing)});A.push(li(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},oGe=Gi.extend({fn:L(),num_pins:Ge([bA(6),bA(8)]).default(8),w:L().default("3mm"),h:L().default("3mm"),p:L().default("0.5mm"),pl:L().default("0.52mm"),pw:L().default("0.35mm"),epw:L().default("1.40mm"),eph:L().default("1.60mm"),string:L().optional(),ep:PA().default(!1)}),sGe=e=>{e.string&&e.string.includes("_ep")&&(e.ep=!0);const A=e.string?.match(/^son_(\d+)/),t=A?Number.parseInt(A[1],10):e.num_pins||8,i=oGe.parse({...e,num_pins:t}),n=cA.parse(i.w),o=cA.parse(i.h),s=cA.parse(i.p),r=cA.parse(i.pl),a=cA.parse(i.pw),g=cA.parse(i.epw),c=cA.parse(i.eph),I=[];for(let f=0;f<i.num_pins;f++){const{x:m,y:w}=oet(i.num_pins,f+1,n,s);I.push(li(f+1,m,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=oet(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}},oet=(e,A,t,i)=>{const n=e/2,o=(A-1)%n,s=A<=n?-1:1,r=(n-1)/2-o;return{x:s*cA.parse("1.4mm"),y:r*i}},rGe=Gi.extend({fn:L(),num_pins:qA().optional().default(8),p:st.describe("pitch (distance between center of each pin)"),w:cA.describe("width between vertical rows of pins"),grid:cV.describe("width and height of the border of the footprint"),ep:cV.default("0x0mm").describe("width and height of the central exposed thermal pad"),epx:cA.default("0mm").describe("x offset of the center of the central exposed thermal pad"),pinw:cA.describe("width of the pin pads"),pinh:cA.describe("height of the pin pads")}),aGe=e=>{const A=rGe.parse(e),{num_pins:t,p:i,w:n,grid:o,ep:s,epx:r,pinw:a,pinh:g}=A;if(t%2!==0)throw new Error("invalid number of pins");const c=[];for(let B=0;B<t;B++){const{pinX:C,pinY:Q}=gGe({pinCount:t,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=cGe(o),l=Ui(0,o.y/2+i,o.y/6);return{circuitJson:[...c,...I,l],parameters:A}},gGe=e=>{let A=0,t=0;const i=(e.pinCount/2-1)*e.pitch/2,n=e.pinCount/2;return e.pinIndex+1<=n?(A=e.pitch*e.pinIndex-i,t=0-e.width/2):(A=e.pitch*(e.pinCount-e.pinIndex-1)-i,t=e.width/2),{pinX:t,pinY:A}},cGe=e=>{const t=e.y/30;return[{layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"",type:"pcb_silkscreen_path",route:[{x:-e.x/2-.1,y:e.y/2+.1-t},{x:-e.x/2-.1,y:e.y/2+.1},{x:e.x/2+.1,y:e.y/2+.1},{x:e.x/2+.1,y:e.y/2+.1-t}],stroke_width:e.y/30},{layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"",type:"pcb_silkscreen_path",route:[{x:-e.x/2-.1,y:-e.y/2-.1+t},{x:-e.x/2-.1,y:-e.y/2-.1},{x:e.x/2+.1,y:-e.y/2-.1},{x:e.x/2+.1,y:-e.y/2-.1+t}],stroke_width:e.y/30}]},IGe=e=>{const{num_pins:A,bridged:t,p:i=2.54,pw:n=1.5,ph:o=1.5}=e,s=cA.parse(i),r=cA.parse(n),a=cA.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(t){const f=t.split("").map(Number);if(f.length>1)for(let m=0;m<f.length-1;m++){const w=f[m],D=f[m+1];if(typeof w=="number"&&typeof D=="number"&&!isNaN(w)&&!isNaN(D)){const S=(w-1)*s,_=(D-1)*s,b=Math.sign(_-S),R=S+b*(r/2),F=_-b*(r/2);I.push({type:"pcb_trace",pcb_trace_id:"",route:[{start_pcb_port_id:`{PIN${w}}`,x:R,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:e}},set={fn:bA("sot457"),num_pins:bA(6).default(6),pillh:L().default("0.45mm"),pillw:L().default("1.45mm"),pl:L(),pw:L(),p:L(),wave:PA().optional(),reflow:PA().optional()},lGe=Gi.extend({...set,h:L().default("2.5mm"),w:L().default("2.7mm"),pl:L().default("0.8mm"),pw:L().default("0.55mm"),p:L().default("0.95mm")}),BGe=Gi.extend({...set,h:L().default("3mm"),w:L().default("4mm"),pillr:L().default("0.225mm"),pl:L().default("1.45mm"),pw:L().default("1.5mm"),p:L().default("1.475mm")}).transform(e=>({...e,wave:e.wave??(e.reflow===void 0?!0:!e.reflow),reflow:e.reflow??(e.wave===void 0?!1:!e.wave)})),Nb=e=>Number.parseFloat(e.replace("mm","")),ret=({pitch:e,width:A,pinNumber:t})=>{const o={1:{x:-A/2-.1,y:e},2:{x:-A/2-.1,y:0},3:{x:-A/2-.1,y:-e},4:{x:A/2+.1,y:-e},5:{x:A/2+.1,y:0},6:{x:A/2+.1,y:e}}[t];if(!o)throw new Error(`Invalid pin number: ${t}`);return o},aet=e=>{const A=[],t=Nb(e.p),i=Nb(e.pl),n=Nb(e.pw),o=Nb(e.w),s=Nb(e.h);if(e.wave){const C={1:({padWidth:Q,padHeight:h})=>li(1,-t,t,h,Q),2:({padWidth:Q,padHeight:h})=>li(2,-t,-t,h,Q),3:({padWidth:Q,padHeight:h})=>IV(3,-t,0,Nb(e.pillw),Nb(e.pillh)),4:({padWidth:Q,padHeight:h})=>IV(4,t,0,Nb(e.pillw),Nb(e.pillh)),5:({padWidth:Q,padHeight:h})=>li(5,t,t,h,Q),6:({padWidth:Q,padHeight:h})=>li(6,t,-t,h,Q)};for(let Q=1;Q<=e.num_pins;Q++){const h=C[Q];h&&A.push(h({padWidth:i,padHeight:n}))}}else for(let C=1;C<=e.num_pins;C++){const{x:Q,y:h}=ret({pitch:t,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+t/1.3},{x:o/3,y:s/2+t/1.3}],stroke_width:.05},a={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_2",route:[{x:-o/3,y:-s/2-t/1.3},{x:o/3,y:-s/2-t/1.3}],stroke_width:.05},g=Ui(0,s+.5,.3),c=ret({pitch:t,width:o,pinNumber:1}),I=e.wave?1:.5,l=e.wave?.7:.3;c.x-=e.wave?n:n*1.7;const B={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"pin1_indicator",route:[{x:c.x+I/2,y:c.y},{x:c.x-I/2,y:c.y+l/2},{x:c.x-I/2,y:c.y-l/2},{x:c.x+I/2,y:c.y}],stroke_width:.05};return[g,r,a,B,...A]},CGe=e=>{if(e.wave){const t=BGe.parse({...e,fn:"sot457"});return{circuitJson:aet(t),parameters:t}}const A=lGe.parse(e);return{circuitJson:aet(A),parameters:A}},QGe=Gi.extend({fn:L(),num_pins:bA(6).default(6),w:L().default("1.1mm"),h:L().default("1.45mm"),p:L().default("0.35mm"),pl:L().default("0.2mm"),pw:L().default("0.2mm"),string:L().optional()}),hGe=e=>{const A=QGe.parse({...e,fn:"sot963"}),t=cA.parse(A.w),i=cA.parse(A.h),n=cA.parse(A.p),o=cA.parse(A.pl),s=cA.parse(A.pw),r=[];for(let B=0;B<6;B++){const{x:C,y:Q}=get(B+1,t,n,o);r.push(li(B+1,C,Q,o,s))}const a={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-t/2,y:i/2},{x:t/2,y:i/2}],stroke_width:.05,pcb_silkscreen_path_id:""},g={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-t/2,y:-i/2},{x:t/2,y:-i/2}],stroke_width:.05,pcb_silkscreen_path_id:""},c=get(1,t,n,o),I={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"pin_marker_1",route:[{x:c.x-o/2-.3,y:c.y},{x:c.x-o/2-.45,y:c.y+.15},{x:c.x-o/2-.45,y:c.y-.15},{x:c.x-o/2-.3,y:c.y}],stroke_width:.05,pcb_silkscreen_path_id:"pin_marker_1"},l=Ui(0,i/2+.4,.25);return{circuitJson:[...r,a,g,l,I],parameters:A}},get=(e,A,t,i)=>{const n=A/2-i/2;return e<=3?{x:-n,y:t-(e-1)*t}:{x:n,y:-t+(e-4)*t}},EGe=Gi.extend({fn:L(),num_pins:Ge([bA(3),bA(2)]).default(3),p:L().default("3.8mm"),id:L().default("1.25mm"),od:L().default("2.35mm"),ca:L().default("14mm").describe("Caliper axis (width or diameter of the potentiometer body or adjustment knob)"),w:L().default("5.35mm"),h:L().default("4mm"),string:L().optional()}),uGe=e=>{const{p:A,id:t,od:i,h:n,ca:o}=e,s=Number.parseFloat(n),r=Number.parseFloat(o);return[vo(1,0,r/4+.3,t,i),vo(2,s,0,t,i),vo(3,0,-r/4-.3,t,i)]},dGe=e=>{const A=e.string?.match(/^potentiometer_(\d+)/),t=A?Number.parseInt(A[1],10):3,i=EGe.parse({...e,num_pins:t});let n=[];i.num_pins===3&&(n=uGe(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}},pGe=Gi.extend({fn:L(),p:cA.optional().default("7.5mm"),id:cA.optional().default("1mm"),od:cA.optional().default("2mm"),d:cA.optional().default("10.5mm")}),fGe=(e,A,t,i,n)=>{const o=[],s=[];for(let r=0;r<=50;r++){const a=r/50*Math.PI,g=e+Math.cos(a)*t,c=A+Math.sin(a)*t;g<e-i&&c>=A-n/2&&c<=A+n/2||o.push({x:g,y:c})}for(let r=0;r<=50;r++){const a=Math.PI+r/50*Math.PI,g=e+Math.cos(a)*t,c=A+Math.sin(a)*t;g<e-i&&c>=A-n/2&&c<=A+n/2||s.push({x:g,y:c})}return{topArc:o,bottomArc:s}},yGe=e=>{const A=pGe.parse(e),{p:t,id:i,od:n,d:o}=A,s=[vo(1,-t/2,0,i,n),vo(2,t/2,0,i,n)],{topArc:r,bottomArc:a}=fGe(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}},mGe=Gi.extend({fn:L(),num_pins:bA(2).default(2),w:L().default("6.5mm"),h:L().default("3mm"),pl:L().default("1.75mm"),pw:L().default("2.40mm"),p:L().default("4.75mm")}),wGe=e=>{const A=mGe.parse(e),t=Ui(0,cA.parse(A.h)-.5,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:cA.parse(A.p)/2,y:cA.parse(A.h)/2},{x:-cA.parse(A.w)/2-.3,y:cA.parse(A.h)/2},{x:-cA.parse(A.w)/2-.3,y:-cA.parse(A.h)/2},{x:cA.parse(A.p)/2,y:-cA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:SGe(A).concat(i,t),parameters:A}},DGe=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},SGe=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=DGe({pn:t,p:Number.parseFloat(e.p)});A.push(li(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},bGe=Gi.extend({fn:L(),num_pins:qA().default(3),w:L().default("2.45mm"),h:L().default("2.40mm"),pl:L().default("0.92mm"),pw:L().default("0.45mm"),p:L().default("0.891mm"),string:L().optional()}),xGe=e=>{const A=e.string?.match(/^sot323_(\d+)/),t=A?Number.parseInt(A[1],3):3,i=bGe.parse({...e,num_pins:t});if(i.num_pins===3)return{circuitJson:kGe(i),parameters:i};throw new Error("Invalid number of pins")},_Ge=e=>{const{pn:A,p:t}=e;return A===1?{x:-t,y:.65}:A===2?{x:-t,y:-.65}:{x:t,y:0}},kGe=e=>{const A=[];for(let r=0;r<e.num_pins;r++){const{x:a,y:g}=_Ge({num_pins:e.num_pins,pn:r+1,w:Number.parseFloat(e.w),h:Number.parseFloat(e.h),pl:Number.parseFloat(e.pl),p:Number.parseFloat(e.p)});A.push(li(r+1,a,g,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}const t=Ui(0,Number.parseInt(e.h)/2+1,.3),i=Number.parseFloat(e.w)/2-Number.parseFloat(e.pl),n=Number.parseFloat(e.h)/2,o={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-i,y:n+.3},{x:i,y:n+.3},{x:i,y:n/2}],type:"pcb_silkscreen_path",stroke_width:.1},s={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_2",route:[{x:-i,y:-n-.3},{x:i,y:-n-.3},{x:i,y:-n/2}],type:"pcb_silkscreen_path",stroke_width:.1};return[...A,o,s,t]},vGe=Gi.extend({fn:L(),circle:PA().optional(),rect:PA().optional(),square:PA().optional(),pill:PA().optional(),d:cA.optional(),pd:cA.optional(),diameter:cA.optional(),r:cA.optional(),pr:cA.optional(),radius:cA.optional(),w:cA.optional(),pw:cA.optional(),width:cA.optional(),h:cA.optional(),ph:cA.optional(),height:cA.optional(),s:cA.optional(),size:cA.optional(),string:L().optional()}).transform(e=>{let A="rect";e.circle&&(A="circle"),e.square&&(A="square"),e.rect&&(A="rect"),e.pill&&(A="pill");let t,i,n;return A==="circle"?e.r!==void 0?t=cr(e.r):e.pr!==void 0?t=cr(e.pr):e.radius!==void 0?t=cr(e.radius):e.d!==void 0?t=cr(e.d)/2:e.pd!==void 0?t=cr(e.pd)/2:e.diameter!==void 0?t=cr(e.diameter)/2:t=cr("1mm")/2:(e.w!==void 0?i=cr(e.w):e.pw!==void 0?i=cr(e.pw):e.width!==void 0?i=cr(e.width):e.s!==void 0?i=cr(e.s):e.size!==void 0?i=cr(e.size):i=cr("1mm"),e.h!==void 0?n=cr(e.h):e.ph!==void 0?n=cr(e.ph):e.height!==void 0?n=cr(e.height):A==="square"||A==="rect"?n=i:n=cr("1mm")),{fn:e.fn,shape:A,radius:t,width:i,height:n}}),FGe=e=>{const A=vGe.parse(e),{shape:t,radius:i,width:n,height:o}=A;let s,r;return t==="circle"?(s=Jtt(1,{x:0,y:0,radius:i}),r=i+.5):t==="pill"?(s=IV(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}},MGe=Gi.extend({fn:L(),d:cA.optional(),hd:cA.optional(),r:cA.optional(),hr:cA.optional(),pd:cA.optional(),pr:cA.optional(),squarepad:PA().optional().default(!1)}).transform(e=>{let A;e.d!==void 0?A=cr(e.d):e.hd!==void 0?A=cr(e.hd):e.r!==void 0?A=cr(e.r)*2:e.hr!==void 0?A=cr(e.hr)*2:A=cr("1mm");let t;return e.pd!==void 0?t=cr(e.pd):e.pr!==void 0?t=cr(e.pr)*2:t=A*(1.5/1),{fn:e.fn,d:A,pd:t,squarepad:e.squarepad??!1}}),GGe=e=>{const A=MGe.parse(e),{d:t,pd:i,squarepad:n}=A;return{circuitJson:[n?Im({pn:1,x:0,y:0,holeDiameter:t,rectPadWidth:i,rectPadHeight:i}):vo(1,0,0,t,i),Ui(0,i/2+.5,.2)],parameters:A}},RGe=Gi.extend({fn:L(),num_pins:bA(6).default(6),h:L().default("1.6mm"),pl:L().default("1mm"),pw:L().default("0.7mm"),p:L().default("0.95mm")}),NGe=e=>{const A=RGe.parse(e);return{circuitJson:LGe(A),parameters:A}},cet=e=>{const{p:A,h:t,pn:i}=e;if(i===1)return{x:-t/2-.5,y:A};if(i===2)return{x:-t/2-.5,y:0};if(i===3)return{x:-t/2-.5,y:-A};if(i===4)return{x:t/2+.5,y:-A};if(i===5)return{x:t/2+.5,y:0};if(i===6)return{x:t/2+.5,y:A};throw new Error("Invalid pin number")},LGe=e=>{const A=[];for(let I=1;I<=e.num_pins;I++){const{x:l,y:B}=cet({h:Number.parseFloat(e.h),p:Number.parseFloat(e.p),pn:I});A.push(li(I,l,B,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}const t=e.num_pins/2*Number.parseFloat(e.p),i=Number.parseFloat(e.h),n={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-t/3,y:i/2+Number.parseFloat(e.p)/1.3},{x:t/3,y:i/2+Number.parseFloat(e.p)/1.3}],type:"pcb_silkscreen_path",stroke_width:.05},o={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_2",route:[{x:-t/3,y:-i/2-Number.parseFloat(e.p)/1.3},{x:t/3,y:-i/2-Number.parseFloat(e.p)/1.3}],type:"pcb_silkscreen_path",stroke_width:.05},s=Ui(0,i+.3,.3),r=cet({h:Number.parseFloat(e.h),p:Number.parseFloat(e.p),pn:1});r.x=r.x-Number.parseFloat(e.pw)*1.5;const a=.7,g=.3,c={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"pin1_indicator",route:[{x:r.x+a/2,y:r.y},{x:r.x-a/2,y:r.y+g/2},{x:r.x-a/2,y:r.y-g/2},{x:r.x+a/2,y:r.y}],stroke_width:.05};return[...A,s,n,o,c]},UGe=Gi.extend({fn:L(),num_pins:qA().default(4),w:L().default("3.2mm"),h:L().default("2.6mm"),pl:L().default("1.05mm"),pw:L().default("0.45mm"),p:L().default("0.55mm"),string:L().optional()}),HGe=e=>{const A=e.string?.match(/^sot343_(\d+)/),t=A?Number.parseInt(A[1],4):4,i=UGe.parse({...e,num_pins:t});if(i.num_pins===4)return{circuitJson:JGe(i),parameters:i};throw new Error("Invalid number of pins")},YGe=e=>{const{pn:A,p:t}=e;return A===1?{x:-t*1.92,y:-.65}:A===2?{x:-t*1.92,y:.65}:A===3?{x:t,y:.65}:A===4?{x:t,y:-.65}:{x:0,y:0}},JGe=e=>{const A=[],t=Number.parseFloat(e.w),i=Number.parseFloat(e.h),n=Number.parseFloat(e.pl),o=Number.parseFloat(e.pw),s=Number.parseFloat(e.p);let r=1/0,a=-1/0,g=1/0,c=-1/0;for(let d=0;d<e.num_pins;d++){const{x:f,y:m}=YGe({num_pins:e.num_pins,pn:d+1,p:s});A.push(li(d+1,f,m,n,o)),f<r&&(r=f),f>a&&(a=f),m<g&&(g=m),m>c&&(c=m)}const I=(r+a)/2,l=c-g,B=i*.3,C=l/2+B;let Q=t*.8;i<=2.6&&(Q/=2);const h=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]},TGe=Gi.extend({fn:L()}),PGe=e=>{const A=TGe.parse(e),t=[],i=.5-.15,n=1.5,s=.5/2,r=75,a=-37/2;for(let D=0;D<r;D++){const S=D+1;if(S>=24&&S<=31)continue;const _=a-D*s,b=S%2===0,R=n+(b?.25:0),H=.5-R/2,Y=li(S,H,_,R,i);Y.layer=b?"bottom":"top",t.push(Y)}const g=46*.0254,c=137*.0254,I=261*.0254,l={type:"pcb_cutout",pcb_cutout_id:"",shape:"rect",center:{x:-c/2+n/2,y:a-I},width:c,height:g},B={x:-.5,y:a},C={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"pin_marker_1",route:[{x:B.x-.4,y:B.y},{x:B.x-.7,y:B.y+.3},{x:B.x-.7,y:B.y-.3},{x:B.x-.4,y:B.y}],stroke_width:.05,pcb_silkscreen_path_id:"pin_marker_1"};let Q=1/0,h=-1/0,E=1/0,u=-1/0;const d=(D,S,_=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 t){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,m=(E+u)/2,w=D=>{typeof D.x=="number"&&(D.x-=f),typeof D.y=="number"&&(D.y-=m),D.center&&(D.center.x-=f,D.center.y-=m),Array.isArray(D.route)&&(D.route=D.route.map(S=>({x:S.x-f,y:S.y-m})))};for(const D of t)w(D);return w(l),w(C),{circuitJson:[...t,l,C],parameters:A}},KGe=Gi.extend({fn:L(),numPins:qA().optional().default(0),rows:Ge([L(),qA()]).transform(e=>Number(e)).optional().default(1).describe("number of rows"),p:cA.default("2.54mm").describe("pitch"),id:cA.default("1.0mm").describe("inner diameter"),od:cA.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:Xt(["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:Ge([L(),qA()]).transform(e=>Number(e)).optional(),pinrowrightpins:Ge([L(),qA()]).transform(e=>Number(e)).optional(),pinrowtoppins:Ge([L(),qA()]).transform(e=>Number(e)).optional(),pinrowbottompins:Ge([L(),qA()]).transform(e=>Number(e)).optional(),width:cA.optional(),height:cA.optional(),pinRowHoleEdgeToEdgeDist:cA.default("2mm"),holes:Ge([L(),St(L())]).optional().transform(e=>!e||Array.isArray(e)?e:e.startsWith("(")&&e.endsWith(")")?e.slice(1,-1).split(",").map(A=>A.trim()):[e]),holeXDist:cA.optional(),holeYDist:cA.optional(),holeInset:cA.default("1mm"),pinrow:Ge([L(),qA()]).optional(),usbposition:Xt(["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:Xt(["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:cA.optional(),screenheight:cA.optional(),screencenteroffsetx:cA.optional(),screencenteroffsety:cA.optional()}).transform(e=>{const A=jtt(e);let t=e.pinRowSide;e.pinrowleft&&(t="left"),e.pinrowright&&(t="right"),e.pinrowtop&&(t="top"),e.pinrowbottom&&(t="bottom");let i=e.usbposition;e.usbleft&&(i="left"),e.usbtop&&(i="top"),e.usbright&&(i="right"),e.usbbottom&&(i="bottom");let n=e.usbtype;e.usbmicro&&(n="micro"),e.usbc&&(n="c"),e.pinrow!==void 0&&(e.numPins=Number(e.pinrow));const o={left:e.pinrowleftpins,right:e.pinrowrightpins,top:e.pinrowtoppins,bottom:e.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?t="left":(o.right??0)>0?t="right":(o.top??0)>0?t="top":(o.bottom??0)>0&&(t="bottom"),e.numPins=(o.left??0)+(o.right??0)+(o.top??0)+(o.bottom??0));const g=Math.ceil(e.numPins/e.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?e.p:0,m=a?e.p:0;l=(I>0?(I-1)*e.p:0)+2*e.pinRowHoleEdgeToEdgeDist+f,B=(c>0?(c-1)*e.p:0)+2*e.pinRowHoleEdgeToEdgeDist+m}else t==="left"||t==="right"?(l=(e.rows-1)*e.p+2*e.pinRowHoleEdgeToEdgeDist,B=(g-1)*e.p+2*e.pinRowHoleEdgeToEdgeDist):(B=(e.rows-1)*e.p+2*e.pinRowHoleEdgeToEdgeDist,l=(g-1)*e.p+2*e.pinRowHoleEdgeToEdgeDist);e.numPins===0&&(l=10,B=10);const C=e.width??l,Q=e.height??B,h=e.screenwidth??C*.95,E=e.screenheight??Q*.95,u=e.screencenteroffsetx??0,d=e.screencenteroffsety??0;return{...e,pinlabelAnchorSide:A,pinRowSide:t,usbposition:i,usbtype:n,male:e.male??!e.female,female:e.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((e,A)=>{e.male&&e.female&&A.addIssue({code:ze.custom,message:"'male' and 'female' cannot both be true; it should be male or female.",path:["male","female"]})}),qGe=e=>{const A=KGe.parse(e),{p:t,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:m,holeInset:w,pinrowleftpins:D,pinrowrightpins:S,pinrowtoppins:_,pinrowbottompins:b,usbposition:R,usbtype:F,screen:H,screenwidth:Y,screenheight:J,screencenteroffsetx:O,screencenteroffsety:W}=A;let z="center";c?z="left":I&&(z="right");const tA=[],aA={left:D,right:S,top:_,bottom:b},eA=Object.values(aA).some(lA=>lA!==void 0&&lA>0),oA=(lA,pA,kA,MA)=>{if(A.smd?tA.push(li(lA,pA,kA,A.od,A.od)):lA===1?tA.push(Im({pn:lA,x:pA,y:kA,holeDiameter:i,rectPadWidth:n,rectPadHeight:n})):tA.push(vo(lA,pA,kA,i,n)),!l){const YA=pA+(MA==="left"?-n:MA==="right"?n:0),EA=kA+(MA==="top"?n:MA==="bottom"?-n:0);C||tA.push(ZF({fs:n/5,pn:lA,anchor_x:YA,anchor_y:EA,textalign:z,orthogonal:g,verticallyinverted:a,layer:"top"})),(B||C)&&tA.push(ZF({fs:n/5,pn:lA,anchor_x:YA,anchor_y:EA,textalign:z,orthogonal:g,verticallyinverted:a,layer:"bottom"}))}};if(eA){const lA=t;let pA=1;const kA=aA.left??0,MA=aA.right??0,YA=aA.top??0,EA=aA.bottom??0,xA=(dA,WA)=>{if(!(WA<=0))if(dA==="left"||dA==="right"){const jA=dA==="left"?-h/2+u:h/2-u,It=(WA-1)/2*lA;for(let mA=0;mA<WA;mA++)oA(pA,jA,It-mA*lA,dA),pA++}else{const jA=dA==="top"?E/2-u:-E/2+u,It=-((WA-1)/2)*lA;for(let mA=0;mA<WA;mA++)oA(pA,It+mA*lA,jA,dA),pA++}};xA("left",kA),xA("right",MA),xA("top",YA),xA("bottom",EA)}else{const lA=t;let pA=0,kA=0,MA=0,YA=0,EA=0,xA=0;const dA=Math.ceil(s/o);Q==="left"||Q==="right"?(pA=Q==="left"?-h/2+u:h/2-u,kA=(dA-1)/2*lA,MA=0,YA=-lA,EA=Q==="left"?lA:-lA,xA=0):(pA=-(dA-1)/2*lA,kA=Q==="top"?E/2-u:-E/2+u,MA=lA,YA=0,EA=0,xA=Q==="top"?-lA:lA);let WA=1;for(let jA=0;jA<o&&WA<=s;jA++)for(let It=0;It<dA&&WA<=s;It++){const mA=pA+It*MA+jA*EA,gt=kA+It*YA+jA*xA;if(A.smd?tA.push(li(WA,mA,gt,A.od,A.od)):WA===1?tA.push(Im({pn:WA,x:mA,y:gt,holeDiameter:i,rectPadWidth:n,rectPadHeight:n})):tA.push(vo(WA,mA,gt,i,n)),!l){const VA=mA+(Q==="left"?-n:Q==="right"?n:0),JA=gt+(Q==="top"?n:Q==="bottom"?-n:0);C||tA.push(ZF({fs:n/5,pn:WA,anchor_x:VA,anchor_y:JA,textalign:z,orthogonal:g,verticallyinverted:a,layer:"top"})),(B||C)&&tA.push(ZF({fs:n/5,pn:WA,anchor_x:VA,anchor_y:JA,textalign:z,orthogonal:g,verticallyinverted:a,layer:"bottom"}))}WA++}}if(d)for(const lA of d){let pA=0,kA=0;lA==="topleft"?(pA=-h/2+w,kA=E/2-w):lA==="topright"?(pA=h/2-w,kA=E/2-w):lA==="bottomleft"?(pA=-h/2+w,kA=-E/2+w):lA==="bottomright"?(pA=h/2-w,kA=-E/2+w):lA==="center"&&(pA=0,kA=0),f!==void 0&&(pA+=f),m!==void 0&&(kA+=m),tA.push(vo(s+d.indexOf(lA)+1,pA,kA,i,n))}if(!A.nosilkscreen){const lA=[{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}];tA.push(VF(lA,{stroke_width:.1,layer:"top"}))}const rA=Ui(0,E/2+1,.5);if(tA.push(rA),R&&F){let lA,pA;if(F==="c")lA=8,pA=3;else if(F==="micro")lA=6,pA=2;else return{circuitJson:tA,parameters:A};let kA;if(R==="left")kA=[{x:-h/2,y:-lA/2},{x:-h/2+pA,y:-lA/2},{x:-h/2+pA,y:lA/2},{x:-h/2,y:lA/2},{x:-h/2,y:-lA/2}];else if(R==="right")kA=[{x:h/2-pA,y:-lA/2},{x:h/2,y:-lA/2},{x:h/2,y:lA/2},{x:h/2-pA,y:lA/2},{x:h/2-pA,y:-lA/2}];else if(R==="top")kA=[{x:-lA/2,y:E/2-pA},{x:lA/2,y:E/2-pA},{x:lA/2,y:E/2},{x:-lA/2,y:E/2},{x:-lA/2,y:E/2-pA}];else if(R==="bottom")kA=[{x:-lA/2,y:-E/2},{x:lA/2,y:-E/2},{x:lA/2,y:-E/2+pA},{x:-lA/2,y:-E/2+pA},{x:-lA/2,y:-E/2}];else return{circuitJson:tA,parameters:A};tA.push(VF(kA,{stroke_width:.1,layer:"top"}))}if(H){const lA=Y/2,pA=J/2,kA=O,MA=W,YA=[{x:-lA+kA,y:-pA+MA},{x:lA+kA,y:-pA+MA},{x:lA+kA,y:pA+MA},{x:-lA+kA,y:pA+MA},{x:-lA+kA,y:-pA+MA}];tA.push(VF(YA,{stroke_width:.05,layer:"top"}))}return{circuitJson:tA,parameters:A}},OGe=Gi.extend({fn:L(),num_pins:qA().default(3),inline:PA().default(!1),p:L().default("1.27mm"),id:L().default("0.75mm"),od:L().default("1.3mm"),w:L().default("4.8mm"),h:L().default("4.0mm")}),WGe=e=>{const A=OGe.parse(e),t=Number.parseFloat(A.p),i=Number.parseFloat(A.w),n=Number.parseFloat(A.h),o=A.inline?1.05:Number.parseFloat(A.od),s=A.inline?1.5:o,r=[Im({pn:1,x:0,y:0,holeDiameter:A.id,rectPadWidth:o,rectPadHeight:s}),A.inline?jF(2,t,0,Number.parseFloat(A.id),o,s):vo(2,t,t,A.id,o),A.inline?jF(3,t*2,0,Number.parseFloat(A.id),o,s):vo(3,t*2,0,A.id,o)],a=i/2,g=A.inline?t-.09:t,c=.2,I=c+a-n,l=Array.from({length:32},(Q,h)=>{const E=Math.PI*h/31;return{x:g+a*Math.cos(E),y:c+a*Math.sin(E)}}),B={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"",stroke_width:.12,route:[...l,{x:g-a,y:I},{x:g+a,y:I},l[0]]},C=Ui(g,c+a+1,.5);return{circuitJson:[...r,B,C],parameters:A}},ZGe=(e,A)=>{const t=e.filter(i=>i.type==="pcb_silkscreen_text");if(t.length===0)return e;for(const i of t)A.norefdes&&(i.text="");return e},VGe=(e,A)=>A.nosilkscreen?e.filter(t=>t.type!=="pcb_silkscreen_path"&&t.type!=="pcb_silkscreen_text"):e,jGe=(e,A)=>{if(!A)return e;const t=e.filter(c=>c.type==="pcb_smtpad"||c.type==="pcb_plated_hole"||c.type==="pcb_thtpad");if(t.length===0)return e;let i=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 t)if(c.type==="pcb_smtpad"){const I=c.shape==="circle"?c.radius*2:c.width,l=c.shape==="circle"?c.radius*2:c.height;r(c.x,c.y,I,l)}else if(c.type==="pcb_plated_hole"){const I=c.outer_diameter??c.hole_diameter;r(c.x,c.y,I,I)}else if(c.type==="pcb_thtpad"){const I=c.diameter;r(c.x,c.y,I,I)}let a=0,g=0;switch(A){case"center":a=(i+n)/2,g=(o+s)/2;break;case"bottomleft":a=i,g=o;break;case"bottomcenter":case"centerbottom":a=(i+n)/2,g=o;break;case"topcenter":case"centertop":a=(i+n)/2,g=s;break;case"leftcenter":case"centerleft":a=i,g=(o+s)/2;break;case"rightcenter":case"centerright":a=n,g=(o+s)/2;break;case"pin1":{const c=t.find(I=>I.port_hints?.[0]==="1")||t[0];a=c.x,g=c.y;break}}if(a===0&&g===0)return e;for(const c of e){if(typeof c.x=="number"&&(c.x-=a),typeof c.y=="number"&&(c.y-=g),c.center&&typeof c.center.x=="number"&&(c.center.x-=a,c.center.y-=g),c.type==="pcb_silkscreen_path")for(const I of c.route)I.x-=a,I.y-=g;c.type==="pcb_silkscreen_text"&&c.anchor_position&&(c.anchor_position.x-=a,c.anchor_position.y-=g)}return e};function zGe(e){return e!=null}var XGe=e=>e.trim().replace(/^sot-223-(\d+)(?=_|$)/i,"sot223_$1").replace(/^to-220f-(\d+)(?=_|$)/i,"to220f_$1"),$Ge=e=>{let A=CV();const t=XGe(e),n=t.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(zGe);for(const{fn:o,v:s}of n)A=A[o](s);return A.setString(t),A},ARe=()=>Object.keys(Rb),CV=()=>{const e=new Proxy({},{get:(A,t)=>{if(t==="soup"||t==="circuitJson"){if("fn"in A&&Rb[A.fn])return()=>{const{circuitJson:i}=Rb[A.fn](A),n=VGe(i,A),o=ZGe(n,A);return jGe(o,A.origin)};if(!Rb[A.fn])throw new Error(`Invalid footprint function, got "${A.fn}"${A.string?`, from string "${A.string}"`:""}`);return()=>{throw new Error(`No function found for footprinter, make sure to specify .dip, .lr, .p, etc. Got "${t}"`)}}if(t==="json"){if(!Rb[A.fn])throw new Error(`Invalid footprint function, got "${A.fn}"${A.string?`, from string "${A.string}"`:""}`);return()=>Rb[A.fn](A).parameters}return t==="getFootprintNames"?()=>Object.keys(Rb):t==="params"?()=>A:t==="setString"?i=>(A.string=i,e):i=>(Object.keys(A).length===0?`${t}${i}`in Rb?(A[`${t}${i}`]=!0,A.fn=`${t}${i}`):(A[t]=!0,A.fn=t,t==="res"||t==="cap"?i&&(typeof i=="string"&&i.includes("_metric")?A.metric=i.split("_metric")[0]:A.imperial=i):A.num_pins=Number.isNaN(Number.parseFloat(i))?void 0:Number.parseFloat(i)):!i&&["w","h","p"].includes(t)||(A[t]=i??!0),e)}});return e};CV.string=$Ge,CV.getFootprintNames=ARe;var tRe=CV,Iet=Symbol("Fragment");function AdA(e,A,...t){const i=t.length?t:A?.children!==void 0?[A.children]:[],n=[],o=(Array.isArray(i)?i:[i]).flat(1/0);for(const s of o)s==null||s===!1||(Array.isArray(s)?n.push(...s):n.push(s));return{type:e,props:(A&&A.children!==void 0?{...A,children:void 0}:A)||{},children:n}}var Qe=Symbol("Cuboid"),Bet=Symbol("Cube"),ql=Symbol("Cylinder"),QV=Symbol("Sphere"),KY=Symbol("RoundedCuboid"),Zi=Symbol("Translate"),rC=Symbol("Rotate"),zQ=Symbol("Union"),lm=Symbol("Subtract"),Sc=Symbol("Hull"),mo=Symbol("Colorize"),qY=Symbol("Polygon"),OY=Symbol("ExtrudeLinear"),kf=Symbol("RoundedCylinder"),Jn=Iet,zA=(e,A,t)=>AdA(e,A),qe=(e,A,t)=>AdA(e,A),pB=({center:e,width:A,length:t,height:i,heightAboveSurface:n=.15,color:o="#555",taperRatio:s=.12,faceRatio:r=.75,straightHeightRatio:a=.5,includeNotch:g=!0,notchRadius:c,notchPosition:I,notchRotation:l=[0,0,0],notchLength:B=.5,notchWidth:C=.25,chamferSize:Q=0})=>{const h=i*a,E=i-h,u=Math.min(A,t)*s,d=Math.max(A-u,A*r),f=Math.max(t-u,t*r),m=Math.min(A,t)*.12,w=c??m,D={x:0,y:t/2-w*.25,z:i},S=I??D,_=qe(zQ,{children:[qe(Sc,{children:[zA(Zi,{z:.005,children:zA(Qe,{size:[d,f,.01]})}),zA(Zi,{z:h,children:zA(Qe,{size:[A,t,.01]})})]}),qe(Sc,{children:[zA(Zi,{z:h,children:zA(Qe,{size:[A,t,.01]})}),zA(Zi,{z:h+E,children:zA(Qe,{size:[d,f,.01]})})]})]}),b=(F,H)=>zA(Zi,{offset:{x:F,y:H,z:0},children:zA(rC,{rotation:[0,0,Math.PI/4],children:zA(Qe,{size:[Q*Math.SQRT2,Q*Math.SQRT2,i*3]})})});let R=_;if(Q>0){const F=A/2,H=t/2;R=qe(lm,{children:[_,b(F,H),b(-F,H),b(F,-H),b(-F,-H)]})}return zA(mo,{color:o,children:zA(Zi,{offset:e,children:zA(Zi,{offset:{x:0,y:0,z:n},children:g?qe(lm,{children:[R,zA(Zi,{offset:S,children:zA(rC,{rotation:l,children:zA(ql,{radius:w,height:C})})})]}):R})})})},eRe=e=>Array.from({length:e},(A,t)=>t);function tdA(e,A){if(e.length<2)throw new Error("Stroke must have at least two points");const t=Array.isArray(e[0])?e.map(([c,I])=>({x:c,y:I})):e,i=A/2,n=[],o=[];function s(c,I){const l=I.x-c.x,B=I.y-c.y,C=Math.sqrt(l*l+B*B);return{x:-B/C,y:l/C}}function r(c,I,l){const B={x:c.x+I.x*i*l,y:c.y+I.y*i*l};l>0?n.push(B):o.unshift(B)}const a=s(t[0],t[1]);r(t[0],a,1),r(t[0],a,-1);for(let c=1;c<t.length-1;c++){const I=t[c-1],l=t[c],B=t[c+1],C=s(I,l),Q=s(l,B),h=C.x+Q.x,E=C.y+Q.y,u=Math.sqrt(h*h+E*E);if(u/2>2*i)r(l,C,1),r(l,Q,1),r(l,C,-1),r(l,Q,-1);else{const f=1/u;r(l,{x:h*f,y:E*f},1),r(l,{x:h*f,y:E*f},-1)}}const g=s(t[t.length-2],t[t.length-1]);return r(t[t.length-1],g,1),r(t[t.length-1],g,-1),[...n,...o]}var iRe=e=>{const A=Math.min(...e.map(r=>r.x)),t=Math.max(...e.map(r=>r.x)),i=Math.min(...e.map(r=>r.y)),s=5.47/(Math.max(...e.map(r=>r.y))-i);return e.map(r=>({x:(r.x-A-(t-A)/2)*s,y:(r.y-i)*s}))},nRe=iRe([{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}]),Cet=5.47,hV=.5,oRe=({x:e,y:A,z:t})=>{const i=e>0;return qe(Jn,{children:[zA(Zi,{offset:{x:e+.25/2,y:A,z:t},children:zA(rC,{rotation:["-90deg",0,"90deg"],children:zA(OY,{height:.25,children:zA(qY,{points:nRe.slice().reverse().map(n=>[n.x,n.y])})})})}),zA(Zi,{offset:{x:e,y:A+(i?1:-1),z:t},children:zA(rC,{rotation:["-90deg","90deg",i?"180deg":"0deg"],children:zA(OY,{height:2,children:zA(qY,{points:tdA([[0,0],[-1,0],[-1,-1]],.25).map(n=>[n.x,n.y])})})})})]})},sRe=({numPins:e=8,pitch:A=2.54,bodyWidth:t=6.4,rowSpacing:i})=>{const n=Math.floor(e/2),o=i??(t>=7?t:t+1.22),s=t>=7?o-1.22:t;return qe(Jn,{children:[eRe(e).map(r=>{const a=r%n,g=(Math.floor(r/n)-.5)*2;return zA(oRe,{x:g*o/2,y:a*A-(n-1)/2*A,z:Cet/2+hV})}),zA(pB,{width:s,length:n*A+.5,height:Cet-hV,heightAboveSurface:hV,center:{x:0,y:0,z:hV}})]})};function rRe(e,{height:A,padContactLength:t,curveLength:i,bodyDistance:n,steepness:o=10}){i||(i=n*.3);let s=n-t-i;s<0&&(i+=s,s=0);const r=t*.75,a=t+i+(n-t-i)*.25;if(e<=r)return 0;if(e>=a)return A;const g=(e-r)/(a-r);return A/(1+Math.exp(-o*(g-.5)))}var no=e=>{const{thickness:A,width:t,padContactLength:i,bodyDistance:n,height:o,rotation:s}=e,r=15,a=Array.from({length:r}).map((c,I)=>I/(r-1)*n).map(c=>[c,rRe(c,e)]),g=tdA(a,A);return zA(mo,{color:"#fff",children:zA(Zi,{offset:{z:0,y:0,x:0,...e.position},children:zA(rC,{rotation:["90deg",0,s??0],children:zA(Zi,{offset:{x:0,y:0,z:-t/2},children:zA(OY,{height:t,children:zA(qY,{points:g.map(c=>[c.x,c.y])})})})})})})},aRe=({pinCount:e,leadLength:A,leadWidth:t,pitch:i,bodyWidth:n})=>{const o=Math.ceil(e/2),s=i*e/2+t/2,r=(o-1)*i/2,a=.25;return qe(Jn,{children:[Array.from({length:o}).map((g,c)=>zA(no,{position:{x:-n/2-A,y:c*i-r,z:a/2},width:t,thickness:a,padContactLength:A,bodyDistance:A+1,height:.8})),Array.from({length:o}).map((g,c)=>zA(no,{rotation:Math.PI,position:{x:n/2+A,y:c*i-r,z:a/2},width:t,thickness:a,padContactLength:A,bodyDistance:A+1,height:.8})),zA(pB,{center:{x:0,y:0,z:a/2},width:n-t-1,length:s,height:1.5})]})},gRe=({pinCount:e,padContactLength:A=.4,leadWidth:t=.2,pitch:i=.65,bodyWidth:n=3})=>{const o=Math.ceil(e/2),s=(o-1)*i/2,r=.2;return qe(Jn,{children:[Array.from({length:o}).map((a,g)=>zA(no,{position:{x:-n/2-A-.3,y:g*i-s,z:r/2},width:t,thickness:r,padContactLength:A,bodyDistance:A+.4,height:.6})),Array.from({length:o}).map((a,g)=>zA(no,{rotation:Math.PI,position:{x:n/2+A+.3,y:g*i-s,z:r/2},width:t,thickness:r,padContactLength:A,bodyDistance:A+.4,height:.6})),zA(pB,{center:{x:0,y:0,z:r/2},width:n,length:n,height:1.1,notchRadius:.35,heightAboveSurface:.1,taperRatio:.09})]})},edA=1,idA=.5,Q2=.5,WY=.2,cRe=edA-WY*2,Qet=({color:e="#333"})=>qe(Jn,{children:[zA(Qe,{size:[cRe,idA,Q2],offset:[0,0,Q2/2],color:e}),zA(Qe,{size:[WY,Q2,idA],offset:[edA/2-WY/2,0,Q2/2],color:"#ccc"}),zA(Qe,{size:[WY,Q2,idA],offset:[-edA/2+WY/2,0,Q2/2],color:"#ccc"})]}),ndA=1.6,IRe=ndA-.3*2,EV=.3,odA=.85,h2=.6,het=({color:e="#333"})=>qe(Jn,{children:[zA(Qe,{size:[IRe,odA,h2],offset:[0,0,h2/2],color:e}),zA(Qe,{size:[EV,odA,h2],offset:[ndA/2-EV/2,0,h2/2],color:"#ccc"}),zA(Qe,{size:[EV,odA,h2],offset:[-ndA/2+EV/2,0,h2/2],color:"#ccc"})]}),sdA=2,rdA=1.25,E2=.55,ZY=.5,lRe=sdA-ZY*2,Eet=({color:e="#333"})=>qe(Jn,{children:[zA(Qe,{size:[lRe,rdA,E2],offset:[0,0,E2/2],color:e}),zA(Qe,{size:[ZY,rdA,E2],offset:[sdA/2-ZY/2,0,E2/2],color:"#ccc"}),zA(Qe,{size:[ZY,rdA,E2],offset:[-sdA/2+ZY/2,0,E2/2],color:"#ccc"})]}),BRe=({pinCount:e,pitch:A,leadWidth:t,padContactLength:i,bodyWidth:n})=>{const o=e/4;A||(A=CRe(e,n)),i||(i=QRe(e)),t||(t=hRe(e,n)),n||(n=A*(o+4));const s=n,r=(o-1)*A/2,a=s+2*i,g=a,c=.8,I=.15,l=(g-n)/2+.5;return qe(Jn,{children:[Array.from({length:o}).map((B,C)=>zA(no,{position:{x:-g/2-.4,y:C*A-r,z:I/2},width:t,thickness:I,padContactLength:i,bodyDistance:l,height:c})),Array.from({length:o}).map((B,C)=>zA(no,{rotation:Math.PI,position:{x:g/2+.4,y:C*A-r,z:I/2},width:t,thickness:I,padContactLength:i,bodyDistance:l,height:c})),Array.from({length:o}).map((B,C)=>zA(no,{rotation:Math.PI/2,position:{x:C*A-r,y:-a/2-.4,z:I/2},width:t,thickness:I,padContactLength:i,bodyDistance:l,height:c})),Array.from({length:o}).map((B,C)=>zA(no,{rotation:-Math.PI/2,position:{x:C*A-r,y:a/2+.4,z:I/2},width:t,thickness:I,padContactLength:i,bodyDistance:l,height:c})),zA(pB,{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})]})},CRe=(e,A)=>{switch(e){case 44:case 64:return .8;case 52:return A===14?1:.65;case 208:return .5;default:return .5}},QRe=e=>{switch(e){case 32:return .6;case 40:return .6;case 52:case 64:return .65;case 208:return 1.65;default:return .6}},hRe=(e,A)=>{switch(e){case 44:case 64:return .5;case 52:return A===14?.45:.55;case 208:return .3;default:return .25}},uet=({x:e,y:A,pinThickness:t,shortSidePinLength:i,longSidePinLength:n,bodyHeight:o,bodyLength:s=2.54,bodyWidth:r=2.54,flipZ:a,faceup:g,smd:c,rightangle:I})=>qe(Jn,{children:[zA(Zi,{y:I?-3:0,children:zA(Qe,{color:"#222",size:[s,r,o],center:[e,A,a(o/2)]})}),!g&&zA(mo,{color:"gold",children:c?zA(no,{rotation:-Math.PI/2,position:{x:e,y:A+1,z:t/2},thickness:t,width:t,height:t,padContactLength:2,bodyDistance:3}):qe(Sc,{children:[zA(Qe,{color:"gold",size:[t,t,i*.9],center:[e,A,a(o*.9+o/2)]}),zA(Qe,{color:"gold",size:[t/1.8,t/1.8,i],center:[e,A,a(o+o/2)]})]})}),zA(mo,{color:"gold",children:zA(Zi,{y:I?-3.9:0,z:I?1:0,children:zA(rC,{rotation:I?[-Math.PI/2,0,0]:[0,0,0],children:qe(Sc,{children:[zA(Qe,{color:"gold",size:[t,t,n*.9],center:[e,A,a(-n/2*.9)]}),zA(Qe,{color:"gold",size:[t/1.8,t/1.8,n],center:[e,A,a(-n/2)]})]})})})})]}),ERe=({numberOfPins:e,pitch:A=2.54,longSidePinLength:t=6,invert:i,faceup:n,rows:o=1,smd:s,rightangle:r})=>{const c=Math.ceil(e/o),I=2.54,l=3,B=-((c-1)/2)*A,C=!s&&!r?-2-1.6:0,Q=h=>(i||n?-h+2:h)+C;return zA(Jn,{children:Array.from({length:e},(h,E)=>{const u=Math.floor(E/c),d=E%c,f=B+d*A,m=-u*I;return zA(uet,{x:f,y:m,pinThickness:.63,shortSidePinLength:l,longSidePinLength:t,bodyHeight:2,flipZ:Q,faceup:n,smd:s,rightangle:r},E)})})},uRe=e=>{const A=["left","bottom","right","top"],{pin_count:t,pn:i,w:n,h:o,p:s,pl:r}=e,a=t/4,g=A[Math.floor((i-1)/a)],c=(i-1)%a,I=s*(a-1),l=s*(a-1),B=-r/2;switch(g){case"left":return{x:-n/2-B,y:l/2-c*s,o:"vert"};case"bottom":return{x:-I/2+c*s,y:-o/2-B,o:"horz"};case"right":return{x:n/2+B,y:-l/2+c*s,o:"vert"};case"top":return{x:I/2-c*s,y:o/2+B,o:"horz"};default:throw new Error("Invalid pin number")}},dRe=({num_pins:e,cw:A,ccw:t,startingpin:i})=>{const n=[],o=e/4;let s=1;const r={};for(const a of i??[])r[a]=!0;!r.leftside&&!r.topside&&!r.rightside&&!r.bottomside&&(r.leftside=!0),!r.bottompin&&!r.leftpin&&!r.rightpin&&!r.toppin&&(r.leftside?r.toppin=!0:r.topside?r.rightpin=!0:r.rightside?r.bottompin=!0:r.bottomside&&(r.leftpin=!0)),r.leftside&&r.toppin?s=1:r.leftside&&r.bottompin?s=o:r.bottomside&&r.leftpin?s=o+1:r.bottomside&&r.rightpin?s=o*2:r.rightside&&r.bottompin?s=o*2+1:r.rightside&&r.toppin?s=o*3:r.topside&&r.rightpin?s=o*3+1:r.topside&&r.leftpin&&(s=o*4),n.push(-1);for(let a=0;a<e;a++)n[s]=a+1,s++,s>e&&(s=1);return n},pRe=({num_pins:e=16,bodyWidth:A=9,bodyLength:t=9,bodyThickness:i=.8,thermalPadSize:n,padWidth:o=.25,padLength:s=.25,pitch:r=.5,thermalPadThickness:a=.05})=>{const g=dRe({num_pins:e,cw:!0,ccw:!0}),c=[];for(let I=0;I<e;I++){const{x:l,y:B,o:C}=uRe({pin_count:e,pn:I+1,w:A,h:t,p:r,pl:s});let Q=o,h=s;C==="vert"&&([Q,h]=[h,Q]);const E=g[I+1];c.push({pn:E,x:l,y:B,pw:Q,pl:h})}return qe(Jn,{children:[zA(mo,{color:"grey",children:zA(Qe,{center:{x:0,y:0,z:i/2},size:[A,t,i]})}),c.map((I,l)=>zA(Qe,{center:{x:I.x,y:I.y,z:a/2},size:[I.pw,I.pl,a]})),n?.length!==void 0&&n?.width!==void 0&&zA(Qe,{center:{x:0,y:0,z:a/2},size:[n.width,n.length,a]})]})},fRe=pRe,yRe=()=>{const a=1.1999999999999997;return qe(Jn,{children:[zA(no,{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(no,{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(no,{position:{x:-2.8/2-a/4,y:0,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:a,height:.95}),zA(no,{position:{x:-2.8/2-a/4,y:-1,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:a,height:.95}),zA(no,{position:{x:-2.8/2-a/4,y:1,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:a,height:.95}),zA(pB,{center:{x:0,y:0,z:0},width:1.6,length:2.9,height:1.2})]})},mRe=yRe,wRe=({fullWidth:e=2.9,fullLength:A=2.8})=>{const c=(e-1.92)/2+.3;return qe(Jn,{children:[zA(no,{rotation:Math.PI,position:{x:e/2,y:0,z:.075},width:.4,thickness:.15,padContactLength:.25,bodyDistance:c,height:.45}),zA(no,{position:{x:-e/2,y:-.95,z:.075},width:.4,thickness:.15,padContactLength:.25,bodyDistance:c,height:.45}),zA(no,{position:{x:-e/2,y:.95,z:.075},width:.4,thickness:.15,padContactLength:.25,bodyDistance:c,height:.45}),zA(pB,{center:{x:0,y:0,z:0},width:1.92,length:2.9,height:1.1,straightHeightRatio:.45,heightAboveSurface:.05})]})},adA=.6,gdA=.3,u2=.33,VY=.1,DRe=adA-VY*2,det=({color:e="#333"})=>qe(Jn,{children:[zA(Qe,{size:[DRe,gdA,u2],offset:[0,0,u2/2],color:e}),zA(Qe,{size:[VY,gdA,u2],offset:[adA/2-VY/2,0,u2/2],color:"#ccc"}),zA(Qe,{size:[VY,gdA,u2],offset:[-adA/2+VY/2,0,u2/2],color:"#ccc"})]}),cdA=.4,IdA=.2,d2=.13,jY=.07,SRe=cdA-jY*2,pet=({color:e="#333"})=>qe(Jn,{children:[zA(Qe,{size:[SRe,IdA,d2],offset:[0,0,d2/2],color:e}),zA(Qe,{size:[jY,IdA,d2],offset:[cdA/2-jY/2,0,d2/2],color:"#ccc"}),zA(Qe,{size:[jY,IdA,d2],offset:[-cdA/2+jY/2,0,d2/2],color:"#ccc"})]}),ldA=3.2,BdA=1.6,p2=.9,zY=.5,bRe=ldA-zY*2,fet=({color:e="#333"})=>qe(Jn,{children:[zA(Qe,{size:[bRe,BdA,p2],offset:[0,0,p2/2],color:e}),zA(Qe,{size:[zY,BdA,p2],offset:[ldA/2-zY/2,0,p2/2],color:"#ccc"}),zA(Qe,{size:[zY,BdA,p2],offset:[-ldA/2+zY/2,0,p2/2],color:"#ccc"})]}),CdA=3.2,QdA=2.5,f2=1,XY=.6,xRe=CdA-XY*2,yet=({color:e="#333"})=>qe(Jn,{children:[zA(Qe,{size:[xRe,QdA,f2],offset:[0,0,f2/2],color:e}),zA(Qe,{size:[XY,QdA,f2],offset:[CdA/2-XY/2,0,f2/2],color:"#ccc"}),zA(Qe,{size:[XY,QdA,f2],offset:[-CdA/2+XY/2,0,f2/2],color:"#ccc"})]}),hdA=5,EdA=2.5,y2=1.4,$Y=.6,_Re=hdA-$Y*2,met=({color:e="#333"})=>qe(Jn,{children:[zA(Qe,{size:[_Re,EdA,y2],offset:[0,0,y2/2],color:e}),zA(Qe,{size:[$Y,EdA,y2],offset:[hdA/2-$Y/2,0,y2/2],color:"#ccc"}),zA(Qe,{size:[$Y,EdA,y2],offset:[-hdA/2+$Y/2,0,y2/2],color:"#ccc"})]}),udA=6.3,ddA=3.2,m2=1.8,AJ=.8,kRe=udA-AJ*2,wet=({color:e="#333"})=>qe(Jn,{children:[zA(Qe,{size:[kRe,ddA,m2],offset:[0,0,m2/2],color:e}),zA(Qe,{size:[AJ,ddA,m2],offset:[udA/2-AJ/2,0,m2/2],color:"#ccc"}),zA(Qe,{size:[AJ,ddA,m2],offset:[-udA/2+AJ/2,0,m2/2],color:"#ccc"})]}),Det=({x:e,y:A,z:t=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 qe(Jn,{children:[zA(mo,{color:"#1a1a1a",children:qe(lm,{children:[zA(Qe,{color:"#000",size:[r,a,s],center:[e,A,g(t+s/2)]}),o?zA(ql,{height:s+.1,radius:o/2,center:[e,A,g(t+s/2)],color:"#222"}):zA(Qe,{size:[I,I,s],center:[e,A,g(t+s/2)]})]})}),qe(mo,{color:"silver",children:[qe(Sc,{children:[zA(Qe,{color:"silver",size:[c,c,n*.9],center:[e,A,g(t+-n/2*.9)]}),zA(Qe,{color:"silver",size:[c/1.8,c/1.8,n],center:[e,A,g(t+-n/2)]})]}),zA(Qe,{color:"silver",size:[I,I,I*.5],center:[e,A,g(t+I/2*.5)]})]})]})},vRe=({numberOfPins:e,pitch:A=2.54,legsLength:t=3,innerDiameter:i=.945,rows:n=1,invert:o})=>{const r=Math.ceil(e/n),a=2.54,g=-((r-1)/2)*A,c=I=>o?-I+5:I;return zA(Jn,{children:Array.from({length:e},(I,l)=>{const B=Math.floor(l/r),C=l%r,Q=g+C*A,h=-B*a;return zA(Det,{x:Q,y:h,pitch:A,legsLength:t,innerDiameter:i,flipZ:c},l)})})},FRe=({width:e,length:A,innerDiameter:t=1})=>{const i=e,n=A,o=e*.7,s=t/2.5;return qe(Jn,{children:[zA(KY,{color:"#1a1a1f",center:[0,0,o/2],size:[n,n,o],roundRadius:.3}),zA(KY,{color:"#f2f2f2",center:[0,0,o+o*.1/2.5],size:[n,n,o*.1],roundRadius:.14}),zA(ql,{color:"#1a1a1f",height:o*.8,radius:i/3,center:[0,0,o+o*.8/2]}),zA(ql,{color:"#1a1a1f",height:o*.2,radius:t/2,center:[n/3,n/3,o+o*.1/2]}),zA(ql,{color:"#1a1a1f",height:o*.2,radius:t/2,center:[-n/3,-n/3,o+o*.1/2]}),zA(ql,{color:"#1a1a1f",height:o*.2,radius:t/2,center:[-n/3,n/3,o+o*.1/2]}),zA(ql,{color:"#1a1a1f",height:o*.2,radius:t/2,center:[n/3,-n/3,o+o*.1/2]}),zA(uV,{thickness:t/3,width:s,horizontalLength:n*.8,verticalLength:o/2,position:{x:-i/2,y:-n/2,z:-o*1.2}}),zA(uV,{thickness:t/3,width:s,horizontalLength:n*.8,verticalLength:o/2,position:{x:-i/2,y:n/2,z:-o*1.2},rotation:Math.PI}),zA(uV,{thickness:t/3,width:s,horizontalLength:n*.8,verticalLength:o/2,position:{x:i/2,y:n/2,z:-o*1.2},rotation:Math.PI}),zA(uV,{thickness:t/3,width:s,horizontalLength:n*.8,verticalLength:o/2,position:{x:i/2+t/3.6,y:-n/2,z:-o*1.2}})]})},uV=e=>{const{thickness:A,width:t,horizontalLength:i,verticalLength:n,rotation:o=0,position:s}=e,r=[[0,i],[-n/3,i/3],[-n/5,i/4],[0,0]],a=tdA(r,A);return zA(mo,{color:"#f2f2f2",children:zA(Zi,{offset:{x:s?.x||0,y:s?.y||0,z:s?.z||0},children:zA(rC,{rotation:[0,55,o],children:zA(OY,{height:t,children:zA(qY,{points:a.map(g=>[g.y,g.x])})})})})})},MRe=({pinCount:e,leadLength:A,leadWidth:t,pitch:i,bodyWidth:n})=>{const o=Math.ceil(e/2),s=(o-1)*i/2,r=.25,a=1,g=.8,c=A*0,I=i*(o-1)+t+.2,l=n*.55;return qe(Jn,{children:[Array.from({length:o}).map((B,C)=>zA(no,{position:{x:-n/2-c,y:C*i-s,z:r/2},width:t,thickness:r,padContactLength:A/2,bodyDistance:A+.3,height:g})),Array.from({length:o}).map((B,C)=>zA(no,{rotation:Math.PI,position:{x:n/2+c,y:C*i-s,z:r/2},width:t,thickness:r,padContactLength:A/2,bodyDistance:A+.3,height:g})),zA(pB,{center:{x:0,y:0,z:r/2},width:l,length:I,height:a})]})},GRe=({pinCount:e,pitch:A,leadWidth:t,leadLength:i,bodyWidth:n,bodyLength:o})=>{const s=e===8?{pitch:.65,leadWidth:.3}:{pitch:.5,leadWidth:.225},r=isNaN(parseFloat(A))?s.pitch:parseFloat(A),a=isNaN(parseFloat(t))?s.leadWidth:parseFloat(t)*.8,g=isNaN(parseFloat(n))?2.6:parseFloat(n)*.8,c=isNaN(parseFloat(o))?2+Number(r)*1.4:parseFloat(o),I=e/2,l=(I-1)*r/2,B=.15,C=.8,Q=4.5,h=(Q-g)/2,E=h*.5;return qe(Jn,{children:[Array.from({length:I}).map((u,d)=>zA(no,{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(no,{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(pB,{center:{x:0,y:0,z:B/2},width:g,length:c,height:1})]})},RRe=()=>qe(Jn,{children:[zA(Qe,{color:"#ccc",size:[.5,.6,.12],center:[-.725,0,.12/2]}),zA(Qe,{color:"#ccc",size:[.5,.6,.12],center:[.725,0,.12/2]}),zA(mo,{color:"#222",children:qe(zQ,{children:[zA(Zi,{z:.3/2,children:zA(Qe,{size:[1.65,.8,.3]})}),qe(Sc,{children:[zA(Zi,{z:.3,children:zA(Qe,{size:[1.65,.8,.01]})}),zA(Zi,{z:.6,children:zA(Qe,{size:[1.65-.2,.8-.2,.01]})})]})]})})]}),NRe=()=>qe(Jn,{children:[zA(Qe,{color:"#ccc",size:[.26,.51,.12],center:[-.325,0,.12/2]}),zA(Qe,{color:"#ccc",size:[.26,.51,.12],center:[.325,0,.12/2]}),zA(mo,{color:"#222",children:zA(Zi,{z:.47/2+.02,children:zA(Qe,{size:[.98,.58,.47]})})}),zA(Qe,{color:"#ccc",size:[.98+.001,.26/2,.26/4],center:[0,.26/2,.47/4]}),zA(Qe,{color:"#ccc",size:[.98+.001,.26/2,.26/4],center:[0,-.26/2,.47/4]}),zA(Qe,{color:"#ccc",size:[.26/1.5,.58+.001,.26/4],center:[.65/2,0,.47/4]}),zA(Qe,{color:"#ccc",size:[.26/1.5,.58+.001,.26/4],center:[-.65/2,0,.47/4]})]}),LRe=()=>{const g=zA(mo,{color:"#1a1a1a",children:qe(zQ,{children:[qe(Sc,{children:[zA(Zi,{z:.13,children:zA(Qe,{size:[4,3,.03]})}),zA(Zi,{z:1.15,children:zA(Qe,{size:[4.4,3.4,.01]})})]}),qe(Sc,{children:[zA(Zi,{z:1.15,children:zA(Qe,{size:[4.4,3.4,.01]})}),zA(Zi,{z:2.3,children:zA(Qe,{size:[4,3,.01]})})]})]})}),c=({xDir:I})=>{const C=I*1.78,Q=I*(3.4/2-.2/2+1),h=I*(3.4/2-.2/2),E=Math.abs(h-Q),u=(Q+h)/2;return zA(mo,{color:"#c0c0c0",children:qe(zQ,{children:[zA(Qe,{size:[2.3*.8,1.45,.2],center:[C,0,.2/2]}),zA(Qe,{size:[.2,1.45,1.14],center:[Q,0,1.14/2+.2]}),zA(Qe,{size:[E,1.45,.2],center:[u,0,.2/2+1.14]})]})})};return qe(Jn,{children:[zA(c,{xDir:1}),zA(c,{xDir:-1}),g]})},URe=()=>{const g=zA(mo,{color:"#1a1a1a",children:qe(zQ,{children:[qe(Sc,{children:[zA(Zi,{z:.13,children:zA(Qe,{size:[4,3,.03]})}),zA(Zi,{z:1.15,children:zA(Qe,{size:[4.4,3.4,.01]})})]}),qe(Sc,{children:[zA(Zi,{z:1.15,children:zA(Qe,{size:[4.4,3.4,.01]})}),zA(Zi,{z:2.3,children:zA(Qe,{size:[4,3,.01]})})]})]})}),c=({xDir:I})=>{const C=I*1.78,Q=I*(3.4/2-.2/2+1),h=I*(3.4/2-.2/2),E=Math.abs(h-Q),u=(Q+h)/2;return zA(mo,{color:"#c0c0c0",children:qe(zQ,{children:[zA(Qe,{size:[2.3*.8,1.45,.2],center:[C,0,.2/2]}),zA(Qe,{size:[.2,1.45,1.14],center:[Q,0,1.14/2+.2]}),zA(Qe,{size:[E,1.45,.2],center:[u,0,.2/2+1.14]})]})})};return qe(Jn,{children:[zA(c,{xDir:1}),zA(c,{xDir:-1}),g]})},HRe=()=>{const g=zA(mo,{color:"#1a1a1a",children:qe(zQ,{children:[qe(Sc,{children:[zA(Zi,{z:.21000000000000002,children:zA(Qe,{size:[6.3999999999999995,5.6,.03]})}),zA(Zi,{z:1.15,children:zA(Qe,{size:[6.8,6,.01]})})]}),qe(Sc,{children:[zA(Zi,{z:1.15,children:zA(Qe,{size:[6.8,6,.01]})}),zA(Zi,{z:2.3,children:zA(Qe,{size:[6.3999999999999995,5.6,.01]})})]})]})}),c=({xDir:I})=>{const C=I*3.08,Q=I*(6/2-.2/2+1),h=I*(6/2-.2/2),E=Math.abs(h-Q),u=(Q+h)/2;return zA(mo,{color:"#c0c0c0",children:qe(zQ,{children:[zA(Qe,{size:[2.3*.8,2.95,.2],center:[C,0,.2/2]}),zA(Qe,{size:[.2,2.95,1.14],center:[Q,0,1.14/2+.2]}),zA(Qe,{size:[E,2.95,.2],center:[u,0,.2/2+1.14]})]})})};return qe(Jn,{children:[zA(c,{xDir:1}),zA(c,{xDir:-1}),g]})},YRe=()=>{const I=zA(mo,{color:"#222",children:qe(zQ,{children:[zA(Zi,{z:.27,children:zA(Qe,{size:[2.9,1.9,.54]})}),qe(Sc,{children:[zA(Zi,{z:.54,children:zA(Qe,{size:[2.9,1.9,.01]})}),zA(Zi,{z:1.08,children:zA(Qe,{size:[2.6999999999999997,1.7,.01]})})]})]})});return qe(Jn,{children:[zA(Qe,{color:"#ccc",size:[1,1.2,.25],center:[-1.3,0,.25/2]}),zA(Qe,{color:"#ccc",size:[1,1.2,.25],center:[1.3,0,.25/2]}),I]})},JRe=()=>qe(Jn,{children:[zA(Qe,{color:"#ccc",size:[1,.6,.12],center:[-1.3,0,.12/2]}),zA(Qe,{color:"#ccc",size:[1,.6,.12],center:[1.3,0,.12/2]}),zA(mo,{color:"#222",children:qe(zQ,{children:[zA(Zi,{z:.55/2,children:zA(Qe,{size:[2.7,1.6,.55]})}),qe(Sc,{children:[zA(Zi,{z:.55,children:zA(Qe,{size:[2.7,1.6,.01]})}),zA(Zi,{z:1.1,children:zA(Qe,{size:[2.7-.2,1.6-.2,.01]})})]})]})})]}),TRe=()=>qe(Jn,{children:[zA(Qe,{color:"#ccc",size:[1,.9,.2],center:[-1.3,0,.2/2]}),zA(Qe,{color:"#ccc",size:[1,.9,.2],center:[1.3,0,.2/2]}),zA(mo,{color:"#222",children:qe(zQ,{children:[zA(Zi,{z:.2/2,children:zA(Qe,{size:[2.75,1.8,.2]})}),qe(Sc,{children:[zA(Zi,{z:.2,children:zA(Qe,{size:[2.75,1.8,.01]})}),zA(Zi,{z:1,children:zA(Qe,{size:[2.75-.4,1.8-.4,.01]})})]})]})}),zA(Qe,{color:"#777",size:[.2,1.8-.4,.01],center:[-1.3+.4,0,1]})]}),PRe=()=>qe(Jn,{children:[zA(Qe,{color:"#ccc",size:[.9,.9,.2],center:[-1.225,0,.2/2]}),zA(Qe,{color:"#ccc",size:[.9,.9,.2],center:[1.225,0,.2/2]}),zA(mo,{color:"#222",children:qe(zQ,{children:[qe(Sc,{children:[zA(Zi,{z:.2,children:zA(Qe,{size:[2.6-.1/2,1.7-.1/2,.01]})}),zA(Zi,{z:.01,children:zA(Qe,{size:[2.6-.1,1.7-.1,.01]})})]}),qe(Sc,{children:[zA(Zi,{z:.2,children:zA(Qe,{size:[2.6,1.7,.01]})}),zA(Zi,{z:1,children:zA(Qe,{size:[2.6-.4,1.7-.4,.01]})})]})]})}),zA(Qe,{color:"#777",size:[.2*2.7,1.7-.4,.02],center:[-1.225+.4,0,1]})]}),KRe=()=>qe(Jn,{children:[zA(Qe,{color:"#ccc",size:[.9,1.75,.2],center:[-1.825,0,.2/2]}),zA(Qe,{color:"#ccc",size:[.9,1.75,.2],center:[1.825,0,.2/2]}),zA(mo,{color:"#222",children:qe(zQ,{children:[qe(Sc,{children:[zA(Zi,{z:.2,children:zA(Qe,{size:[3.8-.05/2,2.5-.05/2,.01]})}),zA(Zi,{z:.01,children:zA(Qe,{size:[3.8-.05,2.5-.05,.01]})})]}),qe(Sc,{children:[zA(Zi,{z:.2,children:zA(Qe,{size:[3.8,2.5,.01]})}),zA(Zi,{z:1,children:zA(Qe,{size:[3.8-.4,2.5-.4,.01]})})]})]})}),zA(Qe,{color:"#777",size:[.2*2.7,2.5-.4,.02],center:[-1.825+.4,0,1]})]}),qRe=()=>qe(Jn,{children:[zA(Qe,{color:"#ccc",size:[.4,.25,.14],center:[-.4,0,.14/2]}),zA(Qe,{color:"#ccc",size:[.4,.25,.14],center:[.4,0,.14/2]}),zA(mo,{color:"#222",children:qe(zQ,{children:[zA(Zi,{z:.14/2,children:zA(Qe,{size:[.8,.6,.14]})}),qe(Sc,{children:[zA(Zi,{z:.14,children:zA(Qe,{size:[.8,.6,.01]})}),zA(Zi,{z:.37,children:zA(Qe,{size:[.8-.1,.6-.1,.01]})})]})]})})]}),ORe=()=>{const c=3.0999999999999996;return qe(Jn,{children:[zA(no,{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(no,{position:{x:-6.6/2-c/4,y:0,z:.25/2},width:.7,thickness:.25,padContactLength:.5,bodyDistance:c,height:.75}),zA(no,{position:{x:-6.6/2-c/4,y:-2.3,z:.25/2},width:.7,thickness:.25,padContactLength:.5,bodyDistance:c,height:.75}),zA(no,{position:{x:-6.6/2-c/4,y:2.3,z:.25/2},width:.7,thickness:.25,padContactLength:.5,bodyDistance:c,height:.75}),zA(pB,{center:{x:0,y:0,z:0},width:3.5,length:6.5,height:1.7,includeNotch:!1,taperRatio:.06,straightHeightRatio:.45})]})},WRe=()=>qe(Jn,{children:[Array.from({length:16}).map((B,C)=>zA(no,{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(no,{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(no,{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(no,{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(pB,{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})]}),ZRe=WRe,VRe=()=>{const g=.7999999999999998;return qe(Jn,{children:[zA(no,{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(no,{position:{x:-2.05/2-g/4,y:-.65,z:.18/2},width:.3,thickness:.18,padContactLength:.2,bodyDistance:g,height:.65}),zA(no,{position:{x:-2.05/2-g/4,y:.65,z:.18/2},width:.3,thickness:.18,padContactLength:.2,bodyDistance:g,height:.65}),zA(pB,{center:{x:0,y:0,z:0},width:1.25,length:2,height:.9,includeNotch:!1,taperRatio:.06,straightHeightRatio:.7,heightAboveSurface:.05})]})},jRe=({pinCount:e,pitch:A,leadWidth:t,padContactLength:i,bodyWidth:n})=>{const o=e/4;if(o!==Math.floor(o))throw new Error(`LQFP pinCount must be divisible by 4, got ${e}`);A||(A=.5),i||(i=.6),t||(t=.22),n||(n=A*(o+4));const s=n,r=(o-1)*A/2,a=s+3.3*i,g=a,c=.8,I=.2,l=(g-n)/2+.4;return qe(Jn,{children:[Array.from({length:o}).map((B,C)=>zA(no,{position:{x:-g/2-.36,y:C*A-r,z:I/2},width:t,thickness:I,padContactLength:i,bodyDistance:l,height:c})),Array.from({length:o}).map((B,C)=>zA(no,{rotation:Math.PI,position:{x:g/2+.36,y:C*A-r,z:I/2},width:t,thickness:I,padContactLength:i,bodyDistance:l,height:c})),Array.from({length:o}).map((B,C)=>zA(no,{rotation:Math.PI/2,position:{x:C*A-r,y:-a/2-.36,z:I/2},width:t,thickness:I,padContactLength:i,bodyDistance:l,height:c})),Array.from({length:o}).map((B,C)=>zA(no,{rotation:-Math.PI/2,position:{x:C*A-r,y:a/2+.36,z:I/2},width:t,thickness:I,padContactLength:i,bodyDistance:l,height:c})),zA(pB,{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})]})},zRe=()=>{const i=.20900000000000002,n=.1,o=.3,s=.1,r=.2;return qe(Jn,{children:[zA(mo,{color:"#222",children:qe(zQ,{children:[zA(Qe,{size:[.85,1.2,i],center:[0,0,i/2]}),qe(Sc,{children:[zA(Zi,{z:i,children:zA(Qe,{size:[.85,1.2,.01]})}),zA(Zi,{z:.38,children:zA(Qe,{size:[.85-n,1.2-n,.01]})})]})]})}),zA(Qe,{color:"#ccc",size:[o,.25,s],center:[.55,0,s/2]}),zA(Qe,{color:"#ccc",size:[o,r,s],center:[-.55,.4,s/2]}),zA(Qe,{color:"#ccc",size:[o,r,s],center:[-.55,-.4,s/2]})]})},XRe=({num_pins:e,bodyWidth:A=5.3,bodyLength:t=5.3,bodyThickness:i=1,thermalPadSize:n,padWidth:o=t/5.3*.6,padLength:s=t/5.3*1,pitch:r=.5,thermalPadThickness:a=.2})=>{const g=[],c=Math.floor(e/2),I=r*(c-1);for(let l=0;l<e;l++){const B=l<c?"left":"right",C=l%c,Q=I/2-C*r,h=s,E=o,u=B==="left"?-A/2+h/2:A/2-h/2,d=l+1;g.push({pinNumber:d,x:u,y:Q,padSizeX:h,padSizeY:E})}return qe(Jn,{children:[zA(pB,{center:{x:0,y:0,z:0},width:A,length:t,height:i,heightAboveSurface:0,color:"grey",chamferSize:.2,taperRatio:0,notchPosition:{x:-(A/2-s),y:t/2-s,z:i}}),g.map((l,B)=>zA(Qe,{center:[l.x,l.y,a/2],size:[l.padSizeX,l.padSizeY,a]})),n?.length!==void 0&&n?.width!==void 0&&zA(Qe,{center:[0,0,a/2],size:[n.width,n.length,a]})]})},$Re=({bodyLength:e=10.2,bodyWidth:A=4.65,bodyHeight:t=13.46,leadSpacing:i=5,leadDiameter:n=.8,leadLength:o=12.7,color:s="#ddd",leadColor:r="#b87333"})=>{const a=e/2,g=A/2,c=a-g,I=i/2,l=.85;return qe(Jn,{children:[qe(mo,{color:s,children:[qe(Sc,{children:[zA(kf,{height:t,roundRadius:.5,radius:g,center:[-c,0,t]}),zA(kf,{height:t,roundRadius:.5,radius:g,center:[c,0,t]})]}),qe(Sc,{children:[zA(kf,{height:l,roundRadius:.1,radius:g+.85,center:[-c,0,t/2+l/2]}),zA(kf,{height:l,roundRadius:.1,radius:g+.85,center:[c,0,t/2+l/2]})]})]}),qe(mo,{color:r,children:[zA(ql,{height:o+t/2,radius:n/2,center:[-I+.06,0,-(o/2)+t/2]}),zA(ql,{height:o+t/2,radius:n/2,center:[I-.06,0,-(o/2)+t/2]})]})]})},ANe=({bodyLength:e=1.4,bodyDiameter:A=1.1,color:t="#3a3a3aff",contactColor:i="#c6c6c6",cathodeIdentification:n="#111"})=>qe(Jn,{children:[zA(mo,{color:t,children:qe(rC,{rotation:[0,"90deg",0],children:[zA(KY,{size:[A,A,e-.2],roundRadius:.2,center:[-A/2,0,.05]}),zA(ql,{height:.2/2,radius:A/2-.2,center:[-A/2,0,-e/2+.2/2]})]})}),zA(mo,{color:n,children:zA(rC,{rotation:[0,"90deg",0],children:zA(KY,{size:[A*1.01,A*1.01,e/3],roundRadius:.2,center:[-A/2,0,-e/4+.1]})})}),zA(mo,{color:i,children:zA(rC,{rotation:[0,"90deg",0],children:zA(kf,{height:.2,radius:A/2,roundRadius:.2/3,center:[-A/2,0,-e/2]})})}),zA(mo,{color:i,children:zA(rC,{rotation:[0,"90deg",0],children:zA(kf,{height:.2,radius:A/2,roundRadius:.2/3,center:[-A/2,0,e/2]})})})]}),tNe=({bodyLength:e=3.5,bodyDiameter:A=1.5,color:t="#3a3a3aff",contactColor:i="#c6c6c6"})=>qe(Jn,{children:[zA(mo,{color:t,children:zA(rC,{rotation:[0,"90deg",0],children:zA(kf,{height:e,radius:A/2,roundRadius:.3,center:[-A/2,0,0]})})}),zA(mo,{color:i,children:zA(rC,{rotation:[0,"90deg",0],children:zA(kf,{height:.5,radius:A/2,roundRadius:.2,center:[-A/2,0,-e/2]})})}),zA(mo,{color:i,children:zA(rC,{rotation:[0,"90deg",0],children:zA(kf,{height:.5,radius:A/2,roundRadius:.2,center:[-A/2,0,e/2]})})})]}),eNe=({bodyLength:e=3.9,bodyDiameter:A=2.5,color:t="#3a3a3aff",contactColor:i="#c6c6c6"})=>qe(Jn,{children:[zA(mo,{color:t,children:zA(rC,{rotation:[0,"90deg",0],children:zA(kf,{height:e,radius:A/2,roundRadius:.3,center:[-A/2,0,0]})})}),zA(mo,{color:i,children:zA(rC,{rotation:[0,"90deg",0],children:zA(kf,{height:.55,radius:A/2,roundRadius:.2,center:[-A/2,0,-e/2]})})}),zA(mo,{color:i,children:zA(rC,{rotation:[0,"90deg",0],children:zA(kf,{height:.55,radius:A/2,roundRadius:.2,center:[-A/2,0,e/2]})})})]}),iNe=({pinCount:e,padContactLength:A=.6,leadWidth:t=.41,pitch:i=1.27})=>{if(e%2!==0)throw new Error("MS012 pinCount must be even");const n=e/2,o=4.9,s=3.9,r=(n-1)*i/2,a=.2;return qe(Jn,{children:[Array.from({length:n}).map((g,c)=>zA(no,{position:{x:-s/2-A-.3,y:c*i-r,z:a/2},width:t,thickness:a,padContactLength:A,bodyDistance:A+.4,height:.85})),Array.from({length:n}).map((g,c)=>zA(no,{rotation:Math.PI,position:{x:s/2+A+.3,y:c*i-r,z:a/2},width:t,thickness:a,padContactLength:A,bodyDistance:A+.4,height:.85})),zA(pB,{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})]})},nNe=({pinCount:e=16,padContactLength:A=.6,leadWidth:t=.41,pitch:i=1.27})=>{if(e!==16)throw new Error("MS013 only supports 16 pins");const n=e/2,o=7.5,s=10.3,r=(n-1)*i/2,a=.2;return qe(Jn,{children:[Array.from({length:n}).map((g,c)=>zA(no,{position:{x:-o/2-A-.3,y:c*i-r,z:a/2},width:t,thickness:a,padContactLength:A,bodyDistance:A+.4,height:.85})),Array.from({length:n}).map((g,c)=>zA(no,{rotation:Math.PI,position:{x:o/2+A+.3,y:c*i-r,z:a/2},width:t,thickness:a,padContactLength:A,bodyDistance:A+.4,height:.85})),zA(pB,{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})]})},oNe=()=>{const Q=7.050000000000001,h=24.95+6.5/2;return zA(Zi,{center:[0,0,1],children:qe(Jn,{children:[qe(rC,{rotation:[0,55,-55],children:[qe(lm,{children:[zA(Qe,{color:"#ccc",size:[6.5+.1,9.9,1.3],center:[h,0,1.3-2]}),zA(ql,{color:"black",center:[h,0,1.3-2],radius:3/2,height:1.3*1.2})]}),zA(mo,{color:"#222",children:zA(pB,{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(rC,{rotation:[0,55,55],children:Array.from({length:3}).map((E,u)=>{const d=Q,f=(u-1)*2.7,m=-.5-.6;return qe(mo,{color:"gold",children:[qe(Sc,{children:[zA(Zi,{center:[15.05-4.5/2+.1,f,m],children:zA(Qe,{size:[4.5,.81+1,.5]})}),zA(Zi,{center:[15.05-4.5/2-1+.1,f,m],children:zA(Qe,{size:[4.5,.81,.5]})})]}),zA(Zi,{center:[d,f,m],children:zA(Qe,{size:[16+.1,.81,.5]})})]},`prong-${u}`)})})]})})},sNe=()=>{const g=1.1999999999999997;return qe(Jn,{children:[zA(no,{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(no,{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(no,{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(no,{position:{x:-2.8/2-g/4,y:0,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:g,height:.95}),zA(no,{position:{x:-2.8/2-g/4,y:-.95,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:g,height:.95}),zA(no,{position:{x:-2.8/2-g/4,y:.95,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:g,height:.95}),zA(pB,{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})]})},rNe=()=>qe(Jn,{children:[zA(pB,{center:{x:0,y:0,z:0},width:.8,length:1,height:.37,heightAboveSurface:0,color:"#1a1a1a",taperRatio:.15,straightHeightRatio:0,notchPosition:{x:-.8/4,y:.7/2.2,z:.37+.1}}),[0,1,2].map(g=>{const c=-.35+g*.35;return zA(Qe,{center:[-.8/2+.19/2-.1,c,.12/2],size:[.19,.15,.12]})}),[0,1,2].map(g=>{const c=-.35+g*.35;return zA(Qe,{center:[.8/2-.19/2+.1,c,.12/2],size:[.19,.15,.12]})})]}),aNe=()=>{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 qe(Zi,{center:[0,1,10.5],children:[zA(mo,{color:s,children:qe(lm,{children:[zA(Zi,{center:[0,0,2.25],children:zA(ql,{radius:2.4,height:4.5})}),zA(Zi,{center:[0,-1.8499999999999999,2.25],children:zA(Qe,{size:[2.4*2,1.1,4.5+.2]})})]})}),zA(Zi,{center:c,children:zA(Qe,{size:a})}),qe(Sc,{children:[zA(Zi,{center:I,children:zA(Qe,{size:g})}),zA(Zi,{center:l,children:zA(Qe,{size:g})})]}),zA(Zi,{center:B,children:zA(Qe,{size:[.43,.4,12.2]})}),zA(Zi,{center:[1.3,0,C],children:zA(Qe,{size:[.43,.4,15]})}),zA(Zi,{center:[-1.3,0,C],children:zA(Qe,{size:[.43,.4,15]})})]})},gNe=()=>qe(Jn,{children:[zA(no,{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(no,{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(no,{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(no,{position:{x:-2/2-.75/4,y:0,z:.15/2},width:.25,thickness:.15,padContactLength:.3,bodyDistance:.75,height:.85}),zA(no,{position:{x:-2/2-.75/4,y:-.65,z:.15/2},width:.25,thickness:.15,padContactLength:.3,bodyDistance:.75,height:.85}),zA(no,{position:{x:-2/2-.75/4,y:.65,z:.15/2},width:.25,thickness:.15,padContactLength:.3,bodyDistance:.75,height:.85}),zA(pB,{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})]}),cNe=gNe,INe=()=>qe(Jn,{children:[zA(pB,{center:{x:0,y:0,z:.05},width:1,length:1.45,height:.5,heightAboveSurface:0,color:"#1a1a1a",taperRatio:0,includeNotch:!1}),[0,1,2].map(r=>{const a=-.5+r*.5;return zA(Qe,{center:[-1/2+.3/2,a,.05/2],size:[.3,.2,.05]})}),[0,1,2].map(r=>{const a=-.5+r*.5;return zA(Qe,{center:[1/2-.3/2,a,.05/2],size:[.3,.2,.05]})})]}),lNe=()=>qe(Jn,{children:[zA(no,{position:{x:-2.5/2,y:0,z:.175/2},width:.3,thickness:.175,padContactLength:.3,bodyDistance:.45,height:.7}),zA(no,{rotation:Math.PI,position:{x:2.5/2,y:0,z:.175/2},width:.3,thickness:.175,padContactLength:.3,bodyDistance:.45,height:.7}),zA(mo,{color:"#222",children:zA(pB,{center:{x:0,y:0,z:0},width:1.7,length:1.25,height:.95,includeNotch:!1,taperRatio:.06,straightHeightRatio:.7,heightAboveSurface:.05})}),zA(Qe,{color:"#777",size:[1.7/3,1.25-.075,.02],center:[-.85*2/3+.035,0,.95+.05]})]}),BNe=()=>qe(Jn,{children:[zA(Qe,{color:"#ccc",size:[.4,.325,.175],center:[-1.05,0,.175/2]}),zA(Qe,{color:"#ccc",size:[.4,.325,.175],center:[1.05,0,.175/2]}),zA(mo,{color:"#222",children:qe(zQ,{children:[zA(Zi,{z:.175/2,children:zA(Qe,{size:[1.7,1.25,.175]})}),qe(Sc,{children:[zA(Zi,{z:.175,children:zA(Qe,{size:[1.7,1.25,.01]})}),zA(Zi,{z:.725,children:zA(Qe,{size:[1.7-.2,1.25-.2,.01]})})]})]})}),zA(Qe,{color:"#777",size:[1.7/3,1.25-.2,.02],center:[-1.05+1.7/4.4+.2,0,.725]})]}),CNe=()=>{const s=-1.0474999999999999,r=1.775/2+.4/2-.04;return qe(Jn,{children:[zA(Qe,{color:"#ccc",size:[.4,.325,.13],center:[s,0,.13/2]}),zA(Qe,{color:"#ccc",size:[.4,.325,.13],center:[r,0,.13/2]}),zA(mo,{color:"#222",children:zA(pB,{width:1.775,length:1.25,height:.725,center:{x:0,y:0,z:0},heightAboveSurface:0,straightHeightRatio:.7,taperRatio:.06,includeNotch:!1})}),zA(Qe,{color:"#777",size:[1.775/3,1.25-.05,.02],center:[s+1.775/4.4+.2,0,.725]})]})},QNe=({pitch:e=10})=>qe(Jn,{children:[zA(ql,{height:4,radius:.5,center:[-e/2,0,.5]}),zA(QV,{radius:.5,center:[-e/2,0,2.5]}),zA(Zi,{x:-2.5,y:0,z:2.5,children:qe(rC,{rotation:[0,Math.PI/2,0],children:[zA(ql,{height:e,radius:.5,center:[0,0,2.5]}),zA(mo,{color:"#d2b48c",children:zA(ql,{height:5,radius:1.3,center:[0,0,2.5]})})]})}),zA(ql,{height:4,radius:.5,center:[e/2,0,.5]}),zA(QV,{radius:.5,center:[e/2,0,2.5]})]}),hNe=({bodyWidth:e=21,boardThickness:A=.5,leadWidth:t=1.6,leadLength:i=2.4,leadsPitch:n=2.54,leadsLeft:o,leadsRight:s,leadsTop:r,leadsBottom:a,innerHoles:g=!0,innerHoleEdgeDistance:c=1.61,innerHoleDiameter:I=1})=>{const l=e/2,B=A/2,C=A*1.05,Q=I/2,h=Math.max(o||0,s||0,r||0,a||0)*n||51,E=[],u=[];if(s){const w=-((s-1)/2)*n;for(let D=0;D<s;D++){const S=w+D*n;E.push({x:l-i/2,y:-S,pl:i,pw:t}),g&&u.push({x:l,y:-S},{x:l-c,y:-S})}}if(o){const w=-((o-1)/2)*n;for(let D=0;D<o;D++){const S=w+D*n;E.push({x:-l+i/2,y:-S,pl:i,pw:t}),g&&u.push({x:-l,y:-S},{x:-l+c,y:-S})}}if(r){const w=-((r-1)/2)*n;for(let D=0;D<r;D++){const S=w+D*n;E.push({x:-S,y:h/2-i/2,pl:t,pw:i}),g&&u.push({x:-S,y:h/2},{x:-S,y:h/2-c})}}if(a){const w=-((a-1)/2)*n;for(let D=0;D<a;D++){const S=w+D*n;E.push({x:-S,y:-h/2+i/2,pl:t,pw:i}),g&&u.push({x:-S,y:-h/2},{x:-S,y:-h/2+c})}}const d=zA(mo,{color:"#008080",children:qe(lm,{children:[zA(Qe,{center:[0,0,B],size:[e,h,A]}),E.map((w,D)=>zA(Qe,{center:[w.x,w.y,B],size:[w.pl+.01,w.pw+.01,C]},D))]})}),f=g&&u.map((w,D)=>zA(ql,{color:"black",center:[w.x,w.y,B],radius:Q,height:A*1.07})),m=E.map((w,D)=>zA(Qe,{center:[w.x,w.y,B],size:[w.pl+.01,w.pw+.01,C]}));return qe(Jn,{children:[d,zA(mo,{color:"#FFD700",children:g?qe(lm,{children:[zA(zQ,{children:E.map((w,D)=>zA(Qe,{center:[w.x,w.y,B],size:[w.pl+.01,w.pw+.01,C]},D))}),f]}):m})]})},ENe=({width:e=30,height:A=22,thickness:t=1,bezelInset:i=2,bezelDepth:n=1,screenColor:o="#001414",bezelColor:s="#0f1116",screenWidth:r,screenHeight:a,offset:g})=>{const c=e,I=A,l=Math.max(t,.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,m=g?.z??0;return qe(Zi,{offset:{x:d,y:f,z:m},children:[C>0&&zA(mo,{color:s,children:zA(Qe,{size:[c,I,C],offset:[0,0,C/2]})}),zA(mo,{color:s,children:qe(lm,{children:[zA(Qe,{size:[c,I,B],offset:[0,0,C+B/2]}),zA(Qe,{size:[h,E,B+.02],offset:[0,0,C+B/2]})]})}),zA(mo,{color:o,children:zA(Qe,{size:[h,E,u],offset:[0,0,C+u/2]})})]})},uNe=({numPins:e=5,rows:A=1,p:t=2.54,id:i=1,od:n=1.5,boardThickness:o=1.6,width:s,height:r,pinRowSide:a="left",holes:g=[],holeInset:c=1,pinRowHoleEdgeToEdgeDist:I=2,female:l,nopin:B,screen:C,screenWidth:Q,screenHeight:h,screenCenterOffsetX:E,screenCenterOffsetY:u})=>{const d=C??!1,f=o/2,m=Math.ceil(e/A);let w,D;a==="left"||a==="right"?(w=(A-1)*t+2*I,D=(m-1)*t+2*I):(D=(A-1)*t+2*I,w=(m-1)*t+2*I),e===0&&(w=10,D=10);const S=Number(s??w),_=Number(r??D),b=[];let R=0,F=0,H=0,Y=0,J=0,O=0;a==="left"||a==="right"?(R=a==="left"?-S/2+I:S/2-I,F=-((m-1)/2)*t,H=0,Y=t,J=a==="left"?t:-t,O=0):(R=-((m-1)/2)*t,F=a==="top"?_/2-I:-_/2+I,H=t,Y=0,J=0,O=a==="top"?-t:t);let W=0;for(let EA=0;EA<A&&W<e;EA++)for(let xA=0;xA<m&&W<e;xA++){const dA=R+xA*H+EA*J,WA=F+xA*Y+EA*O;b.push({x:dA,y:WA}),W++}const z=[];if(g)for(const EA of g){let xA=0,dA=0;EA==="topleft"?(xA=-S/2+c,dA=_/2-c):EA==="topright"?(xA=S/2-c,dA=_/2-c):EA==="bottomleft"?(xA=-S/2+c,dA=-_/2+c):EA==="bottomright"?(xA=S/2-c,dA=-_/2+c):EA==="center"&&(xA=0,dA=0),z.push({x:xA,y:dA})}const tA=.63,aA=2,eA=6,oA=3,rA=B||l?0:aA,lA=rA+o,pA=zA(mo,{color:"#008080",children:qe(lm,{children:[zA(Qe,{center:[0,0,f+rA],size:[S,_,o]}),z.map((EA,xA)=>zA(ql,{center:[EA.x,EA.y,f+rA],radius:n/2,height:o},`hole-${xA}`)),b.map((EA,xA)=>zA(ql,{center:[EA.x,EA.y,f+rA],radius:n/2,height:o},`pin-hole-${xA}`))]})}),kA=b.map((EA,xA)=>zA(mo,{color:"#FFD700",children:qe(lm,{children:[zA(ql,{center:[EA.x,EA.y,o/2+rA],radius:n/2,height:o}),zA(ql,{center:[EA.x,EA.y,o/2+rA],radius:i/2,height:o})]})})),MA=b.map((EA,xA)=>zA(uet,{x:EA.x,y:EA.y,pinThickness:tA,shortSidePinLength:oA,longSidePinLength:eA,bodyHeight:aA,flipZ:dA=>dA})),YA=b.map((EA,xA)=>zA(Det,{x:EA.x,y:EA.y,flipZ:dA=>-dA}));return qe(Jn,{children:[pA,kA,!l&&!B&&MA,l&&YA,d&&zA(ENe,{width:Q??S*.8,height:h??_*.6,offset:{x:E??0,y:u??0,z:lA}})]})},dNe=({footprint:e})=>{const A=tRe.string(e).json();switch(A.fn){case"dip":return zA(sRe,{numPins:A.num_pins,pitch:A.p,bodyWidth:A.w});case"axial":return zA(QNe,{pitch:A.p});case"tssop":return zA(aRe,{pinCount:A.num_pins,leadLength:A.pl,leadWidth:A.pw,pitch:A.p,bodyWidth:A.w});case"msop":return zA(gRe,{pinCount:A.num_pins,padContactLength:A.pl,leadWidth:A.pw,pitch:A.p,bodyWidth:A.w});case"vssop":return zA(GRe,{pinCount:A.num_pins,leadLength:A.pl,leadWidth:A.pw,pitch:A.p,bodyWidth:A.w,bodyLength:A.h});case"qfp":return zA(BRe,{pinCount:A.num_pins,pitch:A.p,leadWidth:A.pw,padContactLength:A.pl,bodyWidth:A.w});case"tqfp":return zA(ZRe,{});case"lqfp":return zA(jRe,{pinCount:A.num_pins});case"qfn":{const n=typeof A.thermalpad?.x=="number"&&typeof A.thermalpad?.y=="number";return zA(fRe,{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(XRe,{num_pins:A.num_pins,bodyWidth:A.w,bodyLength:A.h,pitch:A.p,padLength:A.pl,padWidth:A.pw,thermalPadSize:n?{width:A.thermalpad.x,length:A.thermalpad.y}:void 0})}case"pinrow":{const n=e.match(/_rows(\d+)/),o=n&&n[1]?parseInt(n[1],10):1;if(A.male)return zA(ERe,{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(vRe,{numberOfPins:A.num_pins,pitch:A.p,rows:o})}case"cap":switch(A.imperial){case"0402":return zA(Qet,{color:"#856c4d"});case"0603":return zA(het,{color:"#856c4d"});case"0805":return zA(Eet,{color:"#856c4d"});case"0201":return zA(det,{color:"#856c4d"});case"01005":return zA(pet,{color:"#856c4d"});case"1206":return zA(fet,{color:"#856c4d"});case"1210":return zA(yet,{color:"#856c4d"});case"2010":return zA(met,{color:"#856c4d"});case"2512":return zA(wet,{color:"#856c4d"})}case"sot235":return zA(mRe,{});case"sot457":return zA(sNe,{});case"sot223":return zA(ORe,{});case"sot23w":return zA(wRe,{});case"sot323":return zA(VRe,{});case"sod323f":return zA(BNe,{});case"sod323fl":return zA(CNe,{});case"sot363":return zA(cNe,{});case"sot886":return zA(INe,{});case"sot963":return zA(rNe,{});case"pushbutton":return zA(FRe,{width:A.w,length:A.h,innerDiameter:A.id});case"soic":return zA(MRe,{pinCount:A.num_pins,leadLength:A.pl,leadWidth:A.pw,pitch:A.p,bodyWidth:A.w});case"sod523":return zA(RRe,{});case"sod882":return zA(NRe,{});case"sma":return zA(LRe,{});case"smb":return zA(URe,{});case"smc":return zA(HRe,{});case"smf":return zA(YRe,{});case"sod123f":return zA(JRe,{});case"sod123fl":return zA(TRe,{});case"sod123w":return zA(PRe,{});case"sod128":return zA(KRe,{});case"sod323":return zA(lNe,{});case"sod923":return zA(qRe,{});case"hc49":return zA($Re,{});case"micromelf":return zA(ANe,{});case"minimelf":return zA(tNe,{});case"melf":return zA(eNe,{});case"ms012":return zA(iNe,{pinCount:A.num_pins,padContactLength:A.pl,leadWidth:A.pw,pitch:A.p});case"ms013":return zA(nNe,{pinCount:A.num_pins,padContactLength:A.pl,leadWidth:A.pw,pitch:A.p});case"sot723":return zA(zRe,{});case"to220":return zA(oNe,{});case"to92":return zA(aNe,{});case"stampboard":case"stampreceiver":return zA(hNe,{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(uNe,{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 t=e.match(/_color\(([^)]+)\)/),i=t?t[1]:void 0;switch(A.imperial){case"0402":return zA(Qet,{color:i});case"0603":return zA(het,{color:i});case"0805":return zA(Eet,{color:i});case"0201":return zA(det,{color:i});case"01005":return zA(pet,{color:i});case"1206":return zA(fet,{color:i});case"1210":return zA(yet,{color:i});case"2010":return zA(met,{color:i});case"2512":return zA(wet,{color:i})}return null},pNe=e=>e&&typeof e=="object"&&"type"in e,w2=e=>{if(typeof e=="number")return e;if(typeof e=="string"){const A=/^(-?\d+(?:\.\d+)?)\s*deg$/i.exec(e);if(A)return parseFloat(A[1])*Math.PI/180;const t=Number(e);if(!Number.isNaN(t))return t}return 0},fNe=e=>Array.isArray(e)?[Number(e[0])||0,Number(e[1])||0,Number(e[2])||0]:typeof e=="object"&&e?[Number(e.x)||0,Number(e.y)||0,Number(e.z)||0]:[0,0,0];function YD(e,A,t){const{jscad:{primitives:i,booleans:n,hulls:o,geometries:s,extrusions:r,transforms:a}}=t;if(e==null||e===!1)return[];if(Array.isArray(e))return e.flatMap(l=>YD(l,A,t));if(!pNe(e))return[];const{type:g,props:c,children:I}=e;if(g===Iet)return(I??[]).flatMap(l=>YD(l,A,t));if(g===mo){const l=c?.color;return(I??[]).flatMap(B=>YD(B,l??A,t))}if(g===Zi){const l=fNe(c?.offset??c?.center??{x:c?.x,y:c?.y,z:c?.z});return(I??[]).flatMap(C=>YD(C,A,t)).map(({geom:C,color:Q})=>({geom:a.translate(l,C),color:Q??A}))}if(g===rC){const l=Array.isArray(c?.rotation)?[w2(c.rotation[0]),w2(c.rotation[1]),w2(c.rotation[2])]:[w2(c?.x??0),w2(c?.y??0),w2(c?.z??0)];return(I??[]).flatMap(C=>YD(C,A,t)).map(({geom:C,color:Q})=>({geom:a.rotateZ(l[2],a.rotateY(l[1],a.rotateX(l[0],C))),color:Q}))}if(g===zQ||g===lm||g===Sc){const l=(I??[]).flatMap(C=>YD(C,A,t)).map(C=>C.geom);if(l.length===0)return[];let B;return g===zQ?B=n.union(l):g===lm?B=n.subtract(l[0],l.slice(1)):B=o.hull(l),[{geom:B,color:A}]}if(g===qY){const l=c?.points??[];return[{geom:s.geom2.fromPoints(l),color:A??c?.color}]}if(g===OY){const l=(I??[]).flatMap(h=>YD(h,A,t)).map(h=>h.geom);if(l.length===0)return[];const B=l.length>1?n.union(l):l[0],C=c?.height??c?.h??1;let Q=r.extrudeLinear({height:C},B);if(Q.polygons)for(const h of Q.polygons)!h.plane||!h.vertices||h.vertices.length<3||h.vertices.reverse();return[{geom:Q,color:A??c?.color}]}if(g===Qe||g===Bet||g===ql||g===QV||g===KY||g===kf){let l;if(g===Qe){const B=c?.size??[1,1,1],C=c?.offset,Q=c?.center??(C?[C[0],C[1],C[2]]:[0,0,0]);l=i.cuboid({size:B,center:Q})}else if(g===Bet){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===ql){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===QV){const B=c?.radius??1,C=c?.center??[0,0,0];l=i.sphere({radius:B,center:C})}else if(g===kf){const B=c?.height??1,C=c?.radius??1,Q=c?.roundRadius??.1,h=c?.center??[0,0,0];l=i.roundedCylinder({height:B,radius:C,roundRadius:Q,center:h})}else{const B=c?.size??[1,1,1],C=c?.roundRadius??.1,Q=c?.center??[0,0,0];l=i.roundedCuboid({size:B,roundRadius:C,center:Q})}return[{geom:l,color:A??c?.color}]}if(typeof g=="function"){const l=g(c??{});return YD(l,A,t)}return(I??[]).flatMap(l=>YD(l,A,t))}function yNe(e,A){return{geometries:YD(e,void 0,{jscad:A})}}function bet(e){if(e.polygons){const A=[],t=[],i=[];let n=0;for(const s of e.polygons){for(const a of s.vertices)a.index=n,A.push(a[0],a[1],a[2]),e.color&&e.color.length>=3?i.push(e.color[0],e.color[1],e.color[2]):i.push(1,1,1),n++;const r=s.vertices[0].index;for(let a=2;a<s.vertices.length;a++){const g=s.vertices[a-1].index,c=s.vertices[a].index;t.push(r,g,c)}}const o=new kg;if(o.setAttribute("position",new mc(new Float32Array(A),3)),o.setIndex(t),i.length>0&&o.setAttribute("color",new mc(new Float32Array(i),3)),e.transforms){const s=new Qs;s.fromArray(e.transforms),o.applyMatrix4(s)}return o.computeVertexNormals(),o}if(e.sides){const A=[],t=[];for(const n of e.sides)A.push(n[0][0],n[0][1],0),e.color&&e.color.length>=3?t.push(e.color[0],e.color[1],e.color[2]):t.push(1,1,1);const i=new kg;if(i.setAttribute("position",new mc(new Float32Array(A),3)),t.length>0&&i.setAttribute("color",new mc(new Float32Array(t),3)),e.transforms){const n=new Qs;n.fromArray(e.transforms),i.applyMatrix4(n)}return i}return console.error("Invalid CSG object: neither polygons nor sides found"),new kg}function mNe(e,A){const t=AdA(dNe,{footprint:e});return yNe(t,A)}var wNe=Xa(sV()),xet=AA.createContext(null),DNe=()=>{const e=AA.useContext(xet);if(!e)throw new Error("useHover must be used within a HoverProvider");return e},SNe=({children:e})=>{const{camera:A,renderer:t}=nd(),[i,n]=AA.useState([]),o=AA.useMemo(()=>new yLt,[]),s=AA.useMemo(()=>new Sn,[]),r=AA.useRef(i);r.current=i;const a=AA.useRef(null),g=AA.useCallback(C=>{n(Q=>[...Q,C])},[]),c=AA.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=AA.useCallback(C=>{let Q=C;for(;Q;){const h=r.current.find(E=>E.object===Q);if(h)return h;Q=Q.parent}},[]),l=AA.useCallback(C=>{if(!t.domElement)return;const Q=t.domElement.getBoundingClientRect();s.x=(C.clientX-Q.left)/Q.width*2-1,s.y=-((C.clientY-Q.top)/Q.height)*2+1,o.setFromCamera(s,A);const h=r.current.map(u=>u.object);if(h.length===0){a.current&&(a.current.onUnhover(),a.current=null);return}const E=o.intersectObjects(h,!0);if(E.length>0){const u=E[0],d=I(u.object);if(d){const 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,t,o,s,I]);AA.useEffect(()=>{const C=t.domElement;return C.addEventListener("mousemove",l),()=>{C.removeEventListener("mousemove",l)}},[t,l]);const B=AA.useMemo(()=>({addHoverable:g,removeHoverable:c}),[g,c]);return Z.jsx(xet.Provider,{value:B,children:e})},bNe=({children:e,object:A,onHover:t,onUnhover:i,isHovered:n})=>{const{addHoverable:o,removeHoverable:s}=DNe();return AA.useEffect(()=>A?(o({object:A,onHover:t,onUnhover:i}),()=>{s(A)}):void 0,[A,t,i,o,s]),Z.jsx(Z.Fragment,{children:e})},tJ=bNe,xNe=({positionOffset:e,footprint:A,rotationOffset:t,onHover:i,onUnhover:n,isHovered:o,scale:s,isTranslucent:r=!1})=>{const{rootObject:a}=nd(),g=AA.useMemo(()=>{if(!A)return null;const{geometries:c}=mNe(A,wNe),I=new Ef;for(const l of c.flat(1/0)){const B=l.geom;if(!B||!B.polygons&&!B.sides)continue;const C=new An(l.color);C.convertLinearToSRGB();const Q={...B,color:[C.r,C.g,C.b]},h=bet(Q),E=new TE({vertexColors:!0,side:YQ,transparent:r,opacity:r?.5:1,depthWrite:!r}),u=new Io(h,E);u.renderOrder=r?2:1,I.add(u)}return I},[A,r]);return AA.useEffect(()=>{if(!(!g||!a))return a.add(g),()=>{a.remove(g)}},[a,g]),AA.useEffect(()=>{g&&(e&&g.position.fromArray(e),t&&g.rotation.fromArray(t),s!==void 0&&g.scale.setScalar(s))},[g,e?.[0],e?.[1],e?.[2],t?.[0],t?.[1],t?.[2],s]),AA.useEffect(()=>{g&&g.traverse(c=>{c instanceof Io&&c.material instanceof TE&&(o?(c.material.emissive.setHex(255),c.material.emissiveIntensity=.2):c.material.emissiveIntensity=0)})},[o,g]),g?Z.jsx(tJ,{isHovered:o,onHover:i,onUnhover:n,object:g}):null},_et=new WeakMap,_Ne=()=>{const e=new $c;return e.name="fallback-environment-map",e.mapping=Eq,e},kNe=e=>{if(!e)return null;const A=e,t=_et.get(A);if(t)return t;let i;if(e instanceof Vq){const n=new P$(e);i=n.fromScene(DHt(),.04).texture,n.dispose()}else i=_Ne();return _et.set(A,i),i},ket=1.25;function vet({gltfUrl:e,position:A,rotation:t,onHover:i,onUnhover:n,isHovered:o,scale:s,isTranslucent:r=!1}){const{renderer:a,rootObject:g}=nd(),[c,I]=AA.useState(null),[l,B]=AA.useState(null);if(AA.useEffect(()=>{if(!e)return;const C=new bHt;let Q=!0;return C.load(e,h=>{if(!Q)return;const E=h.scene;E.traverse(u=>{if(u instanceof Io&&u.material){const d=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 ${e}`,h);const E=h instanceof Error?h:new Error(`Failed to load glTF model from ${e}`);B(E)}),()=>{Q=!1}},[e,r]),AA.useEffect(()=>{c&&(A&&c.position.fromArray(A),t&&c.rotation.fromArray(t),s!==void 0&&c.scale.setScalar(s))},[c,A?.[0],A?.[1],A?.[2],t?.[0],t?.[1],t?.[2],s]),AA.useEffect(()=>{if(!(!g||!c))return g.add(c),()=>{g.remove(c)}},[g,c]),AA.useEffect(()=>{if(!c||!a)return;const C=kNe(a);if(!C)return;const Q=[],h=E=>{E instanceof TE&&(Q.push({material:E,envMap:E.envMap??null,envMapIntensity:E.envMapIntensity??1}),E.envMap=C,(typeof E.envMapIntensity!="number"||E.envMapIntensity<ket)&&(E.envMapIntensity=ket),E.needsUpdate=!0)};return c.traverse(E=>{if(!(E instanceof Io))return;const u=E.material;Array.isArray(u)?u.forEach(h):u&&h(u)}),()=>{Q.forEach(({material:E,envMap:u,envMapIntensity:d})=>{E.envMap=u,E.envMapIntensity=d,E.needsUpdate=!0})}},[c,a]),AA.useEffect(()=>{c&&c.traverse(C=>{C instanceof Io&&C.material instanceof TE&&(o?(C.material.emissive.setHex(255),C.material.emissiveIntensity=.2):C.material.emissiveIntensity=0)})},[o,c]),l)throw l;return c?Z.jsx(tJ,{isHovered:o,onHover:i,onUnhover:n,object:c}):null}var vNe=Xa(Ftt()),FNe=Xa(sV()),MNe=({jscadPlan:e,positionOffset:A,rotationOffset:t,onHover:i,onUnhover:n,isHovered:o,scale:s,isTranslucent:r=!1})=>{const{rootObject:a}=nd(),{threeGeom:g,material:c}=AA.useMemo(()=>{const l=(0,vNe.executeJscadOperations)(FNe.default,e);if(!l||!l.polygons&&!l.sides)return{threeGeom:null,material:null};const B=bet(l),C=new TE({vertexColors:!0,side:YQ,transparent:r,opacity:r?.5:1,depthWrite:!r});return{threeGeom:B,material:C}},[e,r]),I=AA.useMemo(()=>{if(!g)return null;const l=new Io(g,c);return l.renderOrder=r?2:1,l},[g,c,r]);return AA.useEffect(()=>{if(!(!I||!a))return a.add(I),()=>{a.remove(I)}},[a,I]),AA.useEffect(()=>{I&&(A&&I.position.fromArray(A),t&&I.rotation.fromArray(t),s!==void 0&&I.scale.setScalar(s))},[I,A?.[0],A?.[1],A?.[2],t?.[0],t?.[1],t?.[2],s]),AA.useMemo(()=>{if(c)if(o){const l=new An(c.color.getHex());c.emissive.copy(l),c.emissive.setRGB(0,0,1),c.emissiveIntensity=.2}else c.emissiveIntensity=0},[o,c]),g?Z.jsx(tJ,{isHovered:o,onHover:i,onUnhover:n,object:I}):null};function GNe(e){return e.replace(/(DEF|USE)\s+([^\s]+)/g,(A,t,i)=>`${t} ${i.replace(/-/g,"_")}`)}async function RNe(e){const A=await fetch(e);if(!A.ok)throw new Error(`Failed to fetch "${e}": ${A.status} ${A.statusText}`);const t=await A.text();return new lYt().parse(GNe(t),e)}typeof window<"u"&&!window.TSCIRCUIT_OBJ_LOADER_CACHE&&(window.TSCIRCUIT_OBJ_LOADER_CACHE=new Map);function NNe(e){const[A,t]=AA.useState(null);return AA.useEffect(()=>{if(!e)return;const i=e.replace(/&cachebust_origin=$/,""),n=window.TSCIRCUIT_OBJ_LOADER_CACHE;let o=!1;async function s(){try{if(i.endsWith(".wrl"))return await RNe(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 fYt;if(c?.length){const l=c.join(`
5152
- `).replace(/d 0\./g,"d 1."),B=g.replace(/newmtl[\s\S]*?endmtl/g,"").replace(/^mtllib.*/gm,""),C=new gYt;C.setMaterialOptions({invertTrProperty:!0});const Q=C.parse(l.replace(/Kd\s+([\d.]+)\s+([\d.]+)\s+([\d.]+)/g,"Kd $2 $2 $2"),"embedded.mtl");return I.setMaterials(Q),I.parse(B)}return I.parse(g.replace(/^mtllib.*/gm,""))}catch(a){return a}}function r(){if(n.has(i)){const g=n.get(i);return g.result?Promise.resolve(g.result.clone()):g.promise.then(c=>c instanceof Error?c:c.clone())}const a=s().then(g=>(g instanceof Error||n.set(i,{...n.get(i),result:g}),g));return n.set(i,{promise:a,result:null}),a}return r().then(a=>{o||t(a)}).catch(a=>{console.error(a)}),()=>{o=!0}},[e]),A}function LNe({url:e,position:A,rotation:t,onHover:i,onUnhover:n,isHovered:o,scale:s,isTranslucent:r=!1}){const a=NNe(e),{rootObject:g}=nd(),c=AA.useMemo(()=>a&&!(a instanceof Error)?(a.traverse(I=>{if(I instanceof Io&&I.material){const l=B=>{B.transparent=r,B.opacity=r?.5:1,B.depthWrite=!r,B.needsUpdate=!0};Array.isArray(I.material)?I.material.forEach(l):l(I.material),I.renderOrder=r?2:1}}),a):new Io(new ow(.5,.5,.5),new TE({transparent:!0,color:"red",opacity:.25})),[a,r]);if(AA.useEffect(()=>{if(!(!g||!c))return g.add(c),()=>{g.remove(c)}},[g,c]),AA.useEffect(()=>{c&&(A&&(Array.isArray(A)?c.position.fromArray(A):c.position.copy(A)),t&&(Array.isArray(t)?c.rotation.fromArray(t):c.rotation.copy(t)),s!==void 0&&c.scale.setScalar(s))},[c,Array.isArray(A)?A[0]:A?.x,Array.isArray(A)?A[1]:A?.y,Array.isArray(A)?A[2]:A?.z,Array.isArray(t)?t[0]:t?.x,Array.isArray(t)?t[1]:t?.y,Array.isArray(t)?t[2]:t?.z,s]),a instanceof Error)throw a;return Z.jsx(tJ,{isHovered:o,onHover:i,onUnhover:n,object:c})}var pdA,UNe="https://cdn.jsdelivr.net/npm/occt-import-js@0.0.23/dist";function HNe(e){if(typeof e=="function")return e;if(e&&typeof e=="object"&&"default"in e&&typeof e.default=="function")return e.default;throw new Error("Unable to resolve occt-import-js factory export")}async function YNe(){if(!pdA){const e=await import("https://cdn.jsdelivr.net/npm/occt-import-js@0.0.23/+esm");pdA=HNe(e)({locateFile:t=>`${UNe}/${t}`})}return pdA}function JNe(e){const A=new Ef;for(const t of e){const i=t.attributes.position?.array??[],n=t.index?.array??[];if(!i.length||!n.length)continue;const o=new kg;o.setAttribute("position",new $o(i,3));const s=t.attributes.normal?.array??[];s.length?o.setAttribute("normal",new $o(s,3)):o.computeVertexNormals(),o.setIndex(n);const r=new TE({color:t.color?new An(t.color[0],t.color[1],t.color[2]):new An(.82,.82,.82)}),a=new Io(o,r);a.name=t.name,A.add(a)}return A}async function TNe(e){const A=await fetch(e);if(!A.ok)throw new Error(`Failed to fetch STEP file: ${A.statusText}`);const t=await A.arrayBuffer(),n=(await YNe()).ReadStepFile(new Uint8Array(t),null);if(!n.success||!n.meshes.length)throw new Error("occt-import-js failed to convert STEP file");const o=JNe(n.meshes),s=new EtA;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 Fet="step-glb-cache:";function PNe(e){const A=new Uint8Array(e),t=32768;let i="";for(let n=0;n<A.length;n+=t){const o=A.subarray(n,n+t);i+=String.fromCharCode(...o)}return btoa(i)}function KNe(e){const A=atob(e),t=new Uint8Array(A.length);for(let i=0;i<A.length;i+=1)t[i]=A.charCodeAt(i);return t.buffer}function qNe(e){try{const A=localStorage.getItem(`${Fet}${e}`);return A?KNe(A):null}catch(A){return console.warn("Failed to read STEP GLB cache",A),null}}function Met(e,A){try{const t=PNe(A);localStorage.setItem(`${Fet}${e}`,t)}catch(t){console.warn("Failed to write STEP GLB cache",t)}}function ONe(){const e=globalThis;return e.stepUrlToGltfModelConversions||(e.stepUrlToGltfModelConversions={inProgress:new Map,completed:new Map}),e.stepUrlToGltfModelConversions}var WNe=({stepUrl:e,position:A,rotation:t,scale:i,onHover:n,onUnhover:o,isHovered:s,isTranslucent:r})=>{const[a,g]=AA.useState(null);return AA.useEffect(()=>{let c=!0,I=null,l=!0;const B=ONe(),C=qNe(e);if(C){const E={arrayBuffer:C,blobUrl:URL.createObjectURL(new Blob([C],{type:"model/gltf-binary"}))};return B.completed.set(e,E),I=E.blobUrl,l=!1,g(E.blobUrl),()=>{c=!1,I&&l&&URL.revokeObjectURL(I)}}const Q=B.completed.get(e);if(Q)return I=Q.blobUrl,l=!1,g(Q.blobUrl),Met(e,Q.arrayBuffer),()=>{c=!1,I&&l&&URL.revokeObjectURL(I)};let h=B.inProgress.get(e);return h||(h=TNe(e).then(E=>{const u={arrayBuffer:E,blobUrl:URL.createObjectURL(new Blob([E],{type:"model/gltf-binary"}))};return B.completed.set(e,u),B.inProgress.delete(e),u}).catch(E=>{throw B.inProgress.delete(e),E}),B.inProgress.set(e,h)),h.then(E=>{c&&(I=E.blobUrl,l=!1,g(E.blobUrl),Met(e,E.arrayBuffer))}).catch(E=>{console.error("Failed to convert STEP file to GLB",E),c&&g(null)}),()=>{c=!1,I&&l&&URL.revokeObjectURL(I)}},[e]),a?Z.jsx(vet,{gltfUrl:a,position:A,rotation:t,scale:i,onHover:n,onUnhover:o,isHovered:s,isTranslucent:r}):null},ZNe=(e,A)=>{if(e)return A?A(e):e},Get=(...e)=>e,fdA=class extends Qn.Component{constructor(e){super(e),this.state={hasError:!1,error:null}}static getDerivedStateFromError(e){return{hasError:!0,error:e}}render(){return this.state.hasError&&this.state.error?this.props.fallback({error:this.state.error}):this.props.children}},VNe=({error:e,onError:A})=>(AA.useEffect(()=>{A(e)},[e,A]),null),Ret=({cad_component:e,circuitJson:A,resolveStaticAsset:t})=>{const i=Rtt(A),[n,o]=AA.useState(!1),{visibility:s}=OF(),[r,a]=AA.useState(null),g=AA.useCallback(R=>{R?.mousePosition?(o(!0),a(R.mousePosition)):(o(!1),a(null))},[]),c=AA.useCallback(()=>{o(!1),a(null)},[]),I=AA.useMemo(()=>yn(A).source_component.getUsing({source_component_id:e.source_component_id})?.name,[A,e.source_component_id]),l=AA.useMemo(()=>A.filter(F=>F.type==="pcb_plated_hole"&&F.pcb_component_id===e.pcb_component_id).length>0,[A,e.pcb_component_id]),B=AA.useCallback(R=>ZNe(R,t),[t]),C=B(e.model_obj_url??e.model_wrl_url??e.model_stl_url),Q=B(e.model_glb_url??e.model_gltf_url),h=B(e.model_step_url),[E,u]=AA.useState(0),[d,f]=AA.useState(null);AA.useEffect(()=>{u(0),f(null)},[e.cad_component_id,C,Q,h]);const w=A.find(R=>R.type==="pcb_component"&&R.source_component_id===e.source_component_id)?.layer??"top",D=AA.useMemo(()=>e.rotation?Get(e.rotation.x*Math.PI/180,e.rotation.y*Math.PI/180,e.rotation.z*Math.PI/180):Get(0,0,0),[e.rotation,w]),S=AA.useMemo(()=>{if(!e.position)return;let R;return w==="top"?R=e.position.z:w==="bottom"?R=-(e.position.z+i):R=e.position.z,[e.position.x,e.position.y,R]},[e.position,w,i]),_=AA.useMemo(()=>{const R=[];return C&&R.push(Z.jsx(LNe,{url:C,position:S,rotation:D,scale:e.model_unit_to_mm_scale_factor,onHover:g,onUnhover:c,isHovered:n,isTranslucent:e.show_as_translucent_model},`${e.cad_component_id}-mixed-${C}`)),Q&&R.push(Z.jsx(vet,{gltfUrl:Q,position:S,rotation:D,scale:e.model_unit_to_mm_scale_factor,onHover:g,onUnhover:c,isHovered:n,isTranslucent:e.show_as_translucent_model},`${e.cad_component_id}-gltf-${Q}`)),h&&!e.model_jscad&&!e.footprinter_string&&R.push(Z.jsx(WNe,{stepUrl:h,position:S,rotation:D,scale:e.model_unit_to_mm_scale_factor,onHover:g,onUnhover:c,isHovered:n,isTranslucent:e.show_as_translucent_model},`${e.cad_component_id}-step-${h}`)),R},[S,e.cad_component_id,e.footprinter_string,e.model_jscad,e.model_unit_to_mm_scale_factor,e.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=Z.jsx(fdA,{fallback:({error:R})=>Z.jsx(VNe,{error:R,onError:F=>{f(F),u(H=>Math.max(H,E+1))}}),children:_[E]},`${e.cad_component_id}-fallback-${E}`)}else e.model_jscad?b=Z.jsx(MNe,{jscadPlan:e.model_jscad,positionOffset:S,rotationOffset:D,scale:e.model_unit_to_mm_scale_factor,onHover:g,onUnhover:c,isHovered:n,isTranslucent:e.show_as_translucent_model},e.cad_component_id):e.footprinter_string&&(b=Z.jsx(xNe,{positionOffset:S,rotationOffset:D,footprint:e.footprinter_string,scale:e.model_unit_to_mm_scale_factor,onHover:g,onUnhover:c,isHovered:n,isTranslucent:e.show_as_translucent_model}));if(e.show_as_translucent_model){if(!s.translucentModels)return null}else if(l&&!s.throughHoleModels||!l&&!s.smtModels)return null;return Z.jsxs(Z.Fragment,{children:[b,n&&r?Z.jsx(Ltt,{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]})},Net={version:"0.0.542"};function jNe(e){e.querySelectorAll("canvas").forEach(A=>A.remove())}var zNe=e=>{e.outputColorSpace=jm,e.toneMapping=uFA,e.toneMappingExposure=1},Let="cadViewerCameraStateSession",Uet=(e,A)=>{try{const t={position:e.position.toArray(),quaternion:e.quaternion.toArray(),up:e.up.toArray(),fov:e.fov??50,target:A.target.toArray()};sessionStorage.setItem(Let,JSON.stringify(t))}catch(t){console.warn("Failed to save camera:",t)}},ydA=(e,A)=>{try{const t=sessionStorage.getItem(Let);if(!t)return!1;const i=JSON.parse(t);if(e.position.fromArray(i.position),e.quaternion.fromArray(i.quaternion),e.up.fromArray(i.up),"fov"in e){const n=e;n.fov=i.fov,n.updateProjectionMatrix?.()}return A.target.fromArray(i.target),A.update(),e.updateMatrixWorld(),!0}catch(t){return console.warn("Failed to restore camera:",t),!1}},Het=AA.createContext(void 0),XNe=({children:e,defaultTarget:A,initialCameraPosition:t})=>{const i=AA.useRef(null),n=AA.useRef(null),[o,s]=AA.useState(null),[r,a]=AA.useState("perspective"),[g,c]=AA.useState(t??null),[I,l]=AA.useState(new Qf(0,0,0)),B=AA.useMemo(()=>{const[E,u,d]=t??[5,-5,5],f=Math.hypot(E-A.x,u-A.y,d-A.z);return f>0?f:5},[t,A]),C=AA.useCallback(E=>{const u=[A.x,A.y,A.z],d=n.current,f=i.current;let m=B;switch(d&&f&&(m=d.position.distanceTo(f.target)),E){case"Top Center Angled":{const w=m/Math.sqrt(2);return{position:[A.x,A.y-w,A.z+w],target:u,up:[0,0,1]}}case"Top Down":return{position:[A.x,A.y,A.z+m],target:u,up:[0,0,1]};case"Top Left Corner":return{position:[A.x-m*.6,A.y-m*.6,A.z+m*.6],target:u,up:[0,0,1]};case"Top Right Corner":return{position:[A.x+m*.6,A.y-m*.6,A.z+m*.6],target:u,up:[0,0,1]};case"Left Sideview":return{position:[A.x-m,A.y,A.z],target:u,up:[0,0,1]};case"Right Sideview":return{position:[A.x+m,A.y,A.z],target:u,up:[0,0,1]};case"Front":return{position:[A.x,A.y-m,A.z],target:u,up:[0,0,1]};default:return null}},[B,A,n,i]),Q=AA.useCallback(E=>{i.current=E},[]),h=AA.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:Uet,loadCameraFromSession:ydA}),[A,B,o,C,Q,r,g,I]);return Z.jsx(Het.Provider,{value:h,children:e})},ak=()=>{const e=AA.useContext(Het);if(!e)throw new Error("useCameraController must be used within a CameraControllerProvider");return e},$Ne=AA.forwardRef(({children:e,scene:A,camera:t,style:i,onCreated:n},o)=>{const{cameraType:s}=ak(),r=AA.useRef(null),[a,g]=AA.useState(null),c=AA.useRef([]),I=AA.useRef(void 0);I.current=n;const l=AA.useRef(null),B=AA.useCallback(E=>{c.current.push(E)},[]),C=AA.useCallback(E=>{c.current=c.current.filter(u=>u!==E)},[]),Q=AA.useMemo(()=>new Pv,[]);A?.up&&Q.up.set(A.up.x,A.up.y,A.up.z);const h=AA.useRef(new _g);return AA.useImperativeHandle(o,()=>h.current),AA.useEffect(()=>{if(!r.current)return;jNe(r.current);const E=new Vq({antialias:!0,alpha:!0});zNe(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 Yh(75,u,.1,1e3):new cU(-10*u,10*u,10,-10,-1e3,1e3);l.current?(d.position.copy(l.current.position),d.quaternion.copy(l.current.quaternion),d.up.copy(l.current.up)):(t?.up&&d.up.set(t.up[0],t.up[1],t.up[2]),t?.position&&d.position.set(t.position[0],t.position[1],t.position[2]),d.lookAt(0,0,0)),Q.add(h.current),window.__TSCIRCUIT_THREE_OBJECT=h.current,g({scene:Q,camera:d,renderer:E,rootObject:h.current,addFrameListener:B,removeFrameListener:C}),I.current?.({camera:d,renderer:E});let f;const m=new lLt,w=()=>{const S=m.getElapsedTime(),_=m.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 Yh?d.aspect=S:d instanceof cU&&(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]),Z.jsx("div",{ref:r,style:{width:"100%",height:"100%",...i},children:a&&Z.jsx(Ntt.Provider,{value:a,children:Z.jsx(SNe,{children:e})})})}),A2e=({autoRotate:e,autoRotateSpeed:A,onStart:t,panSpeed:i,rotateSpeed:n,zoomSpeed:o,enableDamping:s,dampingFactor:r,target:a,onControlsChange:g})=>{const{camera:c,renderer:I}=nd(),l=AA.useMemo(()=>!c||!I?null:new mYt(c,I.domElement),[c,I]);return AA.useEffect(()=>(g?.(l??null),()=>g?.(null)),[l,g]),AA.useEffect(()=>{if(!l)return;const B=()=>{g?.(l)};return l.addEventListener("change",B),()=>{l.removeEventListener("change",B)}},[l,g]),AA.useEffect(()=>{l&&(l.autoRotate=e||!1,l.autoRotateSpeed=A||1,i!==void 0&&(l.panSpeed=i),n!==void 0&&(l.rotateSpeed=n),o!==void 0&&(l.zoomSpeed=o),s!==void 0&&(l.enableDamping=s),r!==void 0&&(l.dampingFactor=r),l.zoomToCursor=!0,l.mouseButtons={LEFT:Kx.ROTATE,MIDDLE:Kx.PAN,RIGHT:null},a&&(l.target.set(a[0],a[1],a[2]),l.update()))},[l,e,A,i,n,o,s,r,a]),AA.useEffect(()=>{if(!(!l||!t))return l.addEventListener("start",t),()=>{l.removeEventListener("start",t)}},[l,t]),AA.useEffect(()=>{if(l)return()=>{l.dispose()}},[l]),JY(()=>{l?.update()},[l]),null},t2e=`
5152
+ `).replace(/d 0\./g,"d 1."),B=g.replace(/newmtl[\s\S]*?endmtl/g,"").replace(/^mtllib.*/gm,""),C=new gYt;C.setMaterialOptions({invertTrProperty:!0});const Q=C.parse(l.replace(/Kd\s+([\d.]+)\s+([\d.]+)\s+([\d.]+)/g,"Kd $2 $2 $2"),"embedded.mtl");return I.setMaterials(Q),I.parse(B)}return I.parse(g.replace(/^mtllib.*/gm,""))}catch(a){return a}}function r(){if(n.has(i)){const g=n.get(i);return g.result?Promise.resolve(g.result.clone()):g.promise.then(c=>c instanceof Error?c:c.clone())}const a=s().then(g=>(g instanceof Error||n.set(i,{...n.get(i),result:g}),g));return n.set(i,{promise:a,result:null}),a}return r().then(a=>{o||t(a)}).catch(a=>{console.error(a)}),()=>{o=!0}},[e]),A}function LNe({url:e,position:A,rotation:t,onHover:i,onUnhover:n,isHovered:o,scale:s,isTranslucent:r=!1}){const a=NNe(e),{rootObject:g}=nd(),c=AA.useMemo(()=>a&&!(a instanceof Error)?(a.traverse(I=>{if(I instanceof Io&&I.material){const l=B=>{B.transparent=r,B.opacity=r?.5:1,B.depthWrite=!r,B.needsUpdate=!0};Array.isArray(I.material)?I.material.forEach(l):l(I.material),I.renderOrder=r?2:1}}),a):new Io(new ow(.5,.5,.5),new TE({transparent:!0,color:"red",opacity:.25})),[a,r]);if(AA.useEffect(()=>{if(!(!g||!c))return g.add(c),()=>{g.remove(c)}},[g,c]),AA.useEffect(()=>{c&&(A&&(Array.isArray(A)?c.position.fromArray(A):c.position.copy(A)),t&&(Array.isArray(t)?c.rotation.fromArray(t):c.rotation.copy(t)),s!==void 0&&c.scale.setScalar(s))},[c,Array.isArray(A)?A[0]:A?.x,Array.isArray(A)?A[1]:A?.y,Array.isArray(A)?A[2]:A?.z,Array.isArray(t)?t[0]:t?.x,Array.isArray(t)?t[1]:t?.y,Array.isArray(t)?t[2]:t?.z,s]),a instanceof Error)throw a;return Z.jsx(tJ,{isHovered:o,onHover:i,onUnhover:n,object:c})}var pdA,UNe="https://cdn.jsdelivr.net/npm/occt-import-js@0.0.23/dist";function HNe(e){if(typeof e=="function")return e;if(e&&typeof e=="object"&&"default"in e&&typeof e.default=="function")return e.default;throw new Error("Unable to resolve occt-import-js factory export")}async function YNe(){if(!pdA){const e=await import("https://cdn.jsdelivr.net/npm/occt-import-js@0.0.23/+esm");pdA=HNe(e)({locateFile:t=>`${UNe}/${t}`})}return pdA}function JNe(e){const A=new Ef;for(const t of e){const i=t.attributes.position?.array??[],n=t.index?.array??[];if(!i.length||!n.length)continue;const o=new kg;o.setAttribute("position",new $o(i,3));const s=t.attributes.normal?.array??[];s.length?o.setAttribute("normal",new $o(s,3)):o.computeVertexNormals(),o.setIndex(n);const r=new TE({color:t.color?new An(t.color[0],t.color[1],t.color[2]):new An(.82,.82,.82)}),a=new Io(o,r);a.name=t.name,A.add(a)}return A}async function TNe(e){const A=await fetch(e);if(!A.ok)throw new Error(`Failed to fetch STEP file: ${A.statusText}`);const t=await A.arrayBuffer(),n=(await YNe()).ReadStepFile(new Uint8Array(t),null);if(!n.success||!n.meshes.length)throw new Error("occt-import-js failed to convert STEP file");const o=JNe(n.meshes),s=new EtA;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 Fet="step-glb-cache:";function PNe(e){const A=new Uint8Array(e),t=32768;let i="";for(let n=0;n<A.length;n+=t){const o=A.subarray(n,n+t);i+=String.fromCharCode(...o)}return btoa(i)}function KNe(e){const A=atob(e),t=new Uint8Array(A.length);for(let i=0;i<A.length;i+=1)t[i]=A.charCodeAt(i);return t.buffer}function qNe(e){try{const A=localStorage.getItem(`${Fet}${e}`);return A?KNe(A):null}catch(A){return console.warn("Failed to read STEP GLB cache",A),null}}function Met(e,A){try{const t=PNe(A);localStorage.setItem(`${Fet}${e}`,t)}catch(t){console.warn("Failed to write STEP GLB cache",t)}}function ONe(){const e=globalThis;return e.stepUrlToGltfModelConversions||(e.stepUrlToGltfModelConversions={inProgress:new Map,completed:new Map}),e.stepUrlToGltfModelConversions}var WNe=({stepUrl:e,position:A,rotation:t,scale:i,onHover:n,onUnhover:o,isHovered:s,isTranslucent:r})=>{const[a,g]=AA.useState(null);return AA.useEffect(()=>{let c=!0,I=null,l=!0;const B=ONe(),C=qNe(e);if(C){const E={arrayBuffer:C,blobUrl:URL.createObjectURL(new Blob([C],{type:"model/gltf-binary"}))};return B.completed.set(e,E),I=E.blobUrl,l=!1,g(E.blobUrl),()=>{c=!1,I&&l&&URL.revokeObjectURL(I)}}const Q=B.completed.get(e);if(Q)return I=Q.blobUrl,l=!1,g(Q.blobUrl),Met(e,Q.arrayBuffer),()=>{c=!1,I&&l&&URL.revokeObjectURL(I)};let h=B.inProgress.get(e);return h||(h=TNe(e).then(E=>{const u={arrayBuffer:E,blobUrl:URL.createObjectURL(new Blob([E],{type:"model/gltf-binary"}))};return B.completed.set(e,u),B.inProgress.delete(e),u}).catch(E=>{throw B.inProgress.delete(e),E}),B.inProgress.set(e,h)),h.then(E=>{c&&(I=E.blobUrl,l=!1,g(E.blobUrl),Met(e,E.arrayBuffer))}).catch(E=>{console.error("Failed to convert STEP file to GLB",E),c&&g(null)}),()=>{c=!1,I&&l&&URL.revokeObjectURL(I)}},[e]),a?Z.jsx(vet,{gltfUrl:a,position:A,rotation:t,scale:i,onHover:n,onUnhover:o,isHovered:s,isTranslucent:r}):null},ZNe=(e,A)=>{if(e)return A?A(e):e},Get=(...e)=>e,fdA=class extends Qn.Component{constructor(e){super(e),this.state={hasError:!1,error:null}}static getDerivedStateFromError(e){return{hasError:!0,error:e}}render(){return this.state.hasError&&this.state.error?this.props.fallback({error:this.state.error}):this.props.children}},VNe=({error:e,onError:A})=>(AA.useEffect(()=>{A(e)},[e,A]),null),Ret=({cad_component:e,circuitJson:A,resolveStaticAsset:t})=>{const i=Rtt(A),[n,o]=AA.useState(!1),{visibility:s}=OF(),[r,a]=AA.useState(null),g=AA.useCallback(R=>{R?.mousePosition?(o(!0),a(R.mousePosition)):(o(!1),a(null))},[]),c=AA.useCallback(()=>{o(!1),a(null)},[]),I=AA.useMemo(()=>yn(A).source_component.getUsing({source_component_id:e.source_component_id})?.name,[A,e.source_component_id]),l=AA.useMemo(()=>A.filter(F=>F.type==="pcb_plated_hole"&&F.pcb_component_id===e.pcb_component_id).length>0,[A,e.pcb_component_id]),B=AA.useCallback(R=>ZNe(R,t),[t]),C=B(e.model_obj_url??e.model_wrl_url??e.model_stl_url),Q=B(e.model_glb_url??e.model_gltf_url),h=B(e.model_step_url),[E,u]=AA.useState(0),[d,f]=AA.useState(null);AA.useEffect(()=>{u(0),f(null)},[e.cad_component_id,C,Q,h]);const w=A.find(R=>R.type==="pcb_component"&&R.source_component_id===e.source_component_id)?.layer??"top",D=AA.useMemo(()=>e.rotation?Get(e.rotation.x*Math.PI/180,e.rotation.y*Math.PI/180,e.rotation.z*Math.PI/180):Get(0,0,0),[e.rotation,w]),S=AA.useMemo(()=>{if(!e.position)return;let R;return w==="top"?R=e.position.z:w==="bottom"?R=-(e.position.z+i):R=e.position.z,[e.position.x,e.position.y,R]},[e.position,w,i]),_=AA.useMemo(()=>{const R=[];return C&&R.push(Z.jsx(LNe,{url:C,position:S,rotation:D,scale:e.model_unit_to_mm_scale_factor,onHover:g,onUnhover:c,isHovered:n,isTranslucent:e.show_as_translucent_model},`${e.cad_component_id}-mixed-${C}`)),Q&&R.push(Z.jsx(vet,{gltfUrl:Q,position:S,rotation:D,scale:e.model_unit_to_mm_scale_factor,onHover:g,onUnhover:c,isHovered:n,isTranslucent:e.show_as_translucent_model},`${e.cad_component_id}-gltf-${Q}`)),h&&!e.model_jscad&&!e.footprinter_string&&R.push(Z.jsx(WNe,{stepUrl:h,position:S,rotation:D,scale:e.model_unit_to_mm_scale_factor,onHover:g,onUnhover:c,isHovered:n,isTranslucent:e.show_as_translucent_model},`${e.cad_component_id}-step-${h}`)),R},[S,e.cad_component_id,e.footprinter_string,e.model_jscad,e.model_unit_to_mm_scale_factor,e.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=Z.jsx(fdA,{fallback:({error:R})=>Z.jsx(VNe,{error:R,onError:F=>{f(F),u(H=>Math.max(H,E+1))}}),children:_[E]},`${e.cad_component_id}-fallback-${E}`)}else e.model_jscad?b=Z.jsx(MNe,{jscadPlan:e.model_jscad,positionOffset:S,rotationOffset:D,scale:e.model_unit_to_mm_scale_factor,onHover:g,onUnhover:c,isHovered:n,isTranslucent:e.show_as_translucent_model},e.cad_component_id):e.footprinter_string&&(b=Z.jsx(xNe,{positionOffset:S,rotationOffset:D,footprint:e.footprinter_string,scale:e.model_unit_to_mm_scale_factor,onHover:g,onUnhover:c,isHovered:n,isTranslucent:e.show_as_translucent_model}));if(e.show_as_translucent_model){if(!s.translucentModels)return null}else if(l&&!s.throughHoleModels||!l&&!s.smtModels)return null;return Z.jsxs(Z.Fragment,{children:[b,n&&r?Z.jsx(Ltt,{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]})},Net={version:"0.0.543"};function jNe(e){e.querySelectorAll("canvas").forEach(A=>A.remove())}var zNe=e=>{e.outputColorSpace=jm,e.toneMapping=uFA,e.toneMappingExposure=1},Let="cadViewerCameraStateSession",Uet=(e,A)=>{try{const t={position:e.position.toArray(),quaternion:e.quaternion.toArray(),up:e.up.toArray(),fov:e.fov??50,target:A.target.toArray()};sessionStorage.setItem(Let,JSON.stringify(t))}catch(t){console.warn("Failed to save camera:",t)}},ydA=(e,A)=>{try{const t=sessionStorage.getItem(Let);if(!t)return!1;const i=JSON.parse(t);if(e.position.fromArray(i.position),e.quaternion.fromArray(i.quaternion),e.up.fromArray(i.up),"fov"in e){const n=e;n.fov=i.fov,n.updateProjectionMatrix?.()}return A.target.fromArray(i.target),A.update(),e.updateMatrixWorld(),!0}catch(t){return console.warn("Failed to restore camera:",t),!1}},Het=AA.createContext(void 0),XNe=({children:e,defaultTarget:A,initialCameraPosition:t})=>{const i=AA.useRef(null),n=AA.useRef(null),[o,s]=AA.useState(null),[r,a]=AA.useState("perspective"),[g,c]=AA.useState(t??null),[I,l]=AA.useState(new Qf(0,0,0)),B=AA.useMemo(()=>{const[E,u,d]=t??[5,-5,5],f=Math.hypot(E-A.x,u-A.y,d-A.z);return f>0?f:5},[t,A]),C=AA.useCallback(E=>{const u=[A.x,A.y,A.z],d=n.current,f=i.current;let m=B;switch(d&&f&&(m=d.position.distanceTo(f.target)),E){case"Top Center Angled":{const w=m/Math.sqrt(2);return{position:[A.x,A.y-w,A.z+w],target:u,up:[0,0,1]}}case"Top Down":return{position:[A.x,A.y,A.z+m],target:u,up:[0,0,1]};case"Top Left Corner":return{position:[A.x-m*.6,A.y-m*.6,A.z+m*.6],target:u,up:[0,0,1]};case"Top Right Corner":return{position:[A.x+m*.6,A.y-m*.6,A.z+m*.6],target:u,up:[0,0,1]};case"Left Sideview":return{position:[A.x-m,A.y,A.z],target:u,up:[0,0,1]};case"Right Sideview":return{position:[A.x+m,A.y,A.z],target:u,up:[0,0,1]};case"Front":return{position:[A.x,A.y-m,A.z],target:u,up:[0,0,1]};default:return null}},[B,A,n,i]),Q=AA.useCallback(E=>{i.current=E},[]),h=AA.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:Uet,loadCameraFromSession:ydA}),[A,B,o,C,Q,r,g,I]);return Z.jsx(Het.Provider,{value:h,children:e})},ak=()=>{const e=AA.useContext(Het);if(!e)throw new Error("useCameraController must be used within a CameraControllerProvider");return e},$Ne=AA.forwardRef(({children:e,scene:A,camera:t,style:i,onCreated:n},o)=>{const{cameraType:s}=ak(),r=AA.useRef(null),[a,g]=AA.useState(null),c=AA.useRef([]),I=AA.useRef(void 0);I.current=n;const l=AA.useRef(null),B=AA.useCallback(E=>{c.current.push(E)},[]),C=AA.useCallback(E=>{c.current=c.current.filter(u=>u!==E)},[]),Q=AA.useMemo(()=>new Pv,[]);A?.up&&Q.up.set(A.up.x,A.up.y,A.up.z);const h=AA.useRef(new _g);return AA.useImperativeHandle(o,()=>h.current),AA.useEffect(()=>{if(!r.current)return;jNe(r.current);const E=new Vq({antialias:!0,alpha:!0});zNe(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 Yh(75,u,.1,1e3):new cU(-10*u,10*u,10,-10,-1e3,1e3);l.current?(d.position.copy(l.current.position),d.quaternion.copy(l.current.quaternion),d.up.copy(l.current.up)):(t?.up&&d.up.set(t.up[0],t.up[1],t.up[2]),t?.position&&d.position.set(t.position[0],t.position[1],t.position[2]),d.lookAt(0,0,0)),Q.add(h.current),window.__TSCIRCUIT_THREE_OBJECT=h.current,g({scene:Q,camera:d,renderer:E,rootObject:h.current,addFrameListener:B,removeFrameListener:C}),I.current?.({camera:d,renderer:E});let f;const m=new lLt,w=()=>{const S=m.getElapsedTime(),_=m.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 Yh?d.aspect=S:d instanceof cU&&(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]),Z.jsx("div",{ref:r,style:{width:"100%",height:"100%",...i},children:a&&Z.jsx(Ntt.Provider,{value:a,children:Z.jsx(SNe,{children:e})})})}),A2e=({autoRotate:e,autoRotateSpeed:A,onStart:t,panSpeed:i,rotateSpeed:n,zoomSpeed:o,enableDamping:s,dampingFactor:r,target:a,onControlsChange:g})=>{const{camera:c,renderer:I}=nd(),l=AA.useMemo(()=>!c||!I?null:new mYt(c,I.domElement),[c,I]);return AA.useEffect(()=>(g?.(l??null),()=>g?.(null)),[l,g]),AA.useEffect(()=>{if(!l)return;const B=()=>{g?.(l)};return l.addEventListener("change",B),()=>{l.removeEventListener("change",B)}},[l,g]),AA.useEffect(()=>{l&&(l.autoRotate=e||!1,l.autoRotateSpeed=A||1,i!==void 0&&(l.panSpeed=i),n!==void 0&&(l.rotateSpeed=n),o!==void 0&&(l.zoomSpeed=o),s!==void 0&&(l.enableDamping=s),r!==void 0&&(l.dampingFactor=r),l.zoomToCursor=!0,l.mouseButtons={LEFT:Kx.ROTATE,MIDDLE:Kx.PAN,RIGHT:null},a&&(l.target.set(a[0],a[1],a[2]),l.update()))},[l,e,A,i,n,o,s,r,a]),AA.useEffect(()=>{if(!(!l||!t))return l.addEventListener("start",t),()=>{l.removeEventListener("start",t)}},[l,t]),AA.useEffect(()=>{if(l)return()=>{l.dispose()}},[l]),JY(()=>{l?.update()},[l]),null},t2e=`
5153
5153
  varying vec3 worldPosition;
5154
5154
  void main() {
5155
5155
  worldPosition = (modelMatrix * vec4(position, 1.0)).xyz;
@@ -5429,7 +5429,7 @@ You passed in: '`+this.raw_options[o]+"'");return a},t.prototype._is_valid_selec
5429
5429
  `);break}}return s}}}),S6e=Qa({"node_modules/pretty/index.js"(e,A){var t=p6e(),i=D6e(),n=IQt(),o={unformatted:["code","pre","em","strong","span"],indent_inner_html:!0,indent_char:" ",indent_size:2,sep:`
5430
5430
  `};A.exports=function(a,g){var c=n({},o,g);return a=t.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,`
5431
5431
  `).replace(/(\s*<!--)/g,`
5432
- $1`).replace(/>(\s*)(?=<!--\s*\/)/g,"> ")}}});function lQt(e,A,t){if(!A||!t)return;let i=e.get(A);i||(i=new Set,e.set(A,i)),i.add(t);let n=e.get(t);n||(n=new Set,e.set(t,n)),n.add(A)}function b6e(e,A){if(!A.subcircuit_id&&!A.source_group_id)return[...e];let t=A;if(A.subcircuit_id){const r=new Set([A.subcircuit_id]),a=new Map,g=new Map;for(const I of e)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),t={...A,subcircuit_ids:Array.from(r)}}}const i=new Map;for(const r of e){const a=`${r.type}_id`,g=r[a];typeof g=="string"&&i.set(g,r)}const n=new Map;for(const r of e){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);lQt(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);lQt(n,r,l)}}}}const o=[],s=new Set;for(const r of e){let a=!1;(t.subcircuit_id&&"subcircuit_id"in r&&r.subcircuit_id===t.subcircuit_id||t.subcircuit_ids&&"subcircuit_id"in r&&r.subcircuit_id&&t.subcircuit_ids.includes(r.subcircuit_id)||t.source_group_id&&"source_group_id"in r&&r.source_group_id===t.source_group_id||t.source_group_id&&"member_source_group_ids"in r&&Array.isArray(r.member_source_group_ids)&&r.member_source_group_ids.includes(t.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 e.filter(r=>s.has(r))}var Tj=(e,A={})=>{const t=e;let i=t._internal_store;if(!i){i={counts:{},editCount:0},t._internal_store=i;for(const o of t){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()=>(t.editCount=i.editCount,t);if(s==="editCount")return i.editCount;if(s==="subtree")return a=>Tj(b6e(t,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&&(k0A[g]??Bj).parse(I),t.push(I),i.editCount++,I};if(s==="insertAll")return a=>a.map(g=>n.insert(g));const r=s;return{get:a=>t.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=t.find(B=>B.type===I&&B[c]===a[c]);return l?t.find(B=>B.type===r&&B[`${r}_id`]===l[`${r}_id`]):null},getWhere:a=>{const g=Object.keys(a);return t.find(c=>c.type===r&&g.every(I=>c[I]===a[I]))},list:a=>{const g=a?Object.keys(a):[];return t.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&&(k0A[r]??Bj).parse(c),t.push(c),i.editCount++,c},delete:a=>{const g=t.find(c=>c[`${r}_id`]===a);g&&(t.splice(t.indexOf(g),1),i.editCount++)},update:(a,g)=>{const c=t.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 t.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=t.find(B=>B.type==="source_component"&&B.name===g);if(!I)return null;const l=t.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 t.find(B=>B.type==="pcb_port"&&B.source_port_id===l.source_port_id);if(r==="schematic_port")return t.find(B=>B.type==="schematic_port"&&B.source_port_id===l.source_port_id)}}}}});return n};Tj.unparsed=Tj;var Xb=Tj;function lyA(e){const A=e.type;return`${A}:${e[`${A}_id`]}`}var BQt=(e,A={})=>{let t=e._internal_store_indexed;if(!t){t={counts:{},editCount:0,indexes:{}};for(const s of e){const r=s.type,a=s[`${r}_id`];if(!a)continue;const g=Number.parseInt(a.split("_").pop()||"");Number.isNaN(g)||(t.counts[r]=Math.max(t.counts[r]??0,g))}const n=A.indexConfig||{},o=t.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 e){if(n.byId){const r=lyA(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)}}}}e._internal_store_indexed=t}return new Proxy({},{get:(n,o)=>{if(o==="toArray")return()=>(e.editCount=t.editCount,e);if(o==="editCount")return t.editCount;const s=o;return{get:r=>{const a=A.indexConfig||{};return a.byId&&t.indexes.byId?t.indexes.byId.get(`${s}:${r}`)||null:a.byType&&t.indexes.byType?(t.indexes.byType.get(s)||[]).find(c=>c[`${s}_id`]===r)||null:e.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&&t.indexes.byRelation){const B=t.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&&t.indexes.byId?t.indexes.byId.get(`${s}:${h}`)||null:a.byType&&t.indexes.byType?(t.indexes.byType.get(s)||[]).find(u=>u[`${s}_id`]===h)||null:e.find(E=>E.type===s&&E[`${s}_id`]===h)||null}}const l=e.find(B=>B.type===I&&B[c]===r[c]);return l&&e.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&&t.indexes.byCustomField){const c=g[0],I=t.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&&t.indexes.bySubcircuit){const c=r.subcircuit_id;return(t.indexes.bySubcircuit.get(c)||[]).find(l=>l.type===s&&g.every(B=>l[B]===r[B]))||null}return a.byType&&t.indexes.byType?(t.indexes.byType.get(s)||[]).find(I=>g.every(l=>I[l]===r[l]))||null:e.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&&t.indexes.byType)return t.indexes.byType.get(s)||[];if(g.length===1&&g[0]==="subcircuit_id"&&a.bySubcircuit&&t.indexes.bySubcircuit){const I=r.subcircuit_id;return(t.indexes.bySubcircuit.get(I)||[]).filter(B=>B.type===s)}let c;return a.byType&&t.indexes.byType?c=t.indexes.byType.get(s)||[]:c=e.filter(I=>I.type===s),g.length>0?c.filter(I=>g.every(l=>I[l]===r[l])):c},insert:r=>{t.counts[s]??=-1,t.counts[s]++;const a=t.counts[s],g={type:s,[`${s}_id`]:`${s}_${a}`,...r};A.validateInserts&&(k0A[s]??Bj).parse(g),e.push(g),t.editCount++;const c=A.indexConfig||{};if(c.byId&&t.indexes.byId){const I=lyA(g);t.indexes.byId.set(I,g)}if(c.byType&&t.indexes.byType){const I=t.indexes.byType.get(s)||[];I.push(g),t.indexes.byType.set(s,I)}if(c.byRelation&&t.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=t.indexes.byRelation.get(l)||new Map,Q=C.get(B)||[];Q.push(g),C.set(B,Q),t.indexes.byRelation.set(l,C)}}if(c.bySubcircuit&&t.indexes.bySubcircuit&&"subcircuit_id"in g){const I=g.subcircuit_id;if(I&&typeof I=="string"){const l=t.indexes.bySubcircuit.get(I)||[];l.push(g),t.indexes.bySubcircuit.set(I,l)}}if(c.byCustomField&&t.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=t.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&&t.indexes.byId?g=t.indexes.byId.get(`${s}:${r}`):a.byType&&t.indexes.byType?g=(t.indexes.byType.get(s)||[]).find(l=>l[`${s}_id`]===r):g=e.find(I=>I[`${s}_id`]===r),!g)return;const c=e.indexOf(g);if(c>=0&&(e.splice(c,1),t.editCount++),a.byId&&t.indexes.byId){const I=lyA(g);t.indexes.byId.delete(I)}if(a.byType&&t.indexes.byType){const l=(t.indexes.byType.get(s)||[]).filter(B=>B[`${s}_id`]!==r);t.indexes.byType.set(s,l)}if(a.byRelation&&t.indexes.byRelation)for(const[I,l]of t.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&&t.indexes.bySubcircuit&&"subcircuit_id"in g){const I=g.subcircuit_id;if(I){const B=(t.indexes.bySubcircuit.get(I)||[]).filter(C=>C!==g);B.length===0?t.indexes.bySubcircuit.delete(I):t.indexes.bySubcircuit.set(I,B)}}if(a.byCustomField&&t.indexes.byCustomField)for(const I of t.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&&t.indexes.byId?c=t.indexes.byId.get(`${s}:${r}`):g.byType&&t.indexes.byType?c=(t.indexes.byType.get(s)||[]).find(l=>l[`${s}_id`]===r):c=e.find(I=>I.type===s&&I[`${s}_id`]===r),!c)return null;if(g.byRelation&&t.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=t.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&&t.indexes.bySubcircuit&&"subcircuit_id"in c&&"subcircuit_id"in a){const I=c.subcircuit_id,l=a.subcircuit_id;if(I!==l){const C=(t.indexes.bySubcircuit.get(I)||[]).filter(Q=>Q!==c);C.length===0?t.indexes.bySubcircuit.delete(I):t.indexes.bySubcircuit.set(I,C)}}if(g.byCustomField&&t.indexes.byCustomField){for(const I of g.byCustomField)if(I in c&&I in a&&c[I]!==a[I]){const l=t.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),t.editCount++,g.byRelation&&t.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=t.indexes.byRelation.get(l)||new Map,Q=C.get(B)||[];Q.includes(c)||(Q.push(c),C.set(B,Q),t.indexes.byRelation.set(l,C))}}if(g.bySubcircuit&&t.indexes.bySubcircuit&&"subcircuit_id"in c&&"subcircuit_id"in a){const I=c.subcircuit_id;if(I&&typeof I=="string"){const l=t.indexes.bySubcircuit.get(I)||[];l.includes(c)||(l.push(c),t.indexes.bySubcircuit.set(I,l))}}if(g.byCustomField&&t.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=t.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 e.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=e.find(l=>l.type==="source_component"&&l.name===a);if(!c)return null;const I=e.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 e.find(l=>l.type==="pcb_port"&&l.source_port_id===I.source_port_id)||null;if(s==="schematic_port")return e.find(l=>l.type==="schematic_port"&&l.source_port_id===I.source_port_id)||null}return null}}}})};BQt.unparsed=BQt;var x6e=e=>{const A=e.type;return e[`${A}_id`]},CQt=(e,A)=>({minX:Math.min(e.minX,A.minX),minY:Math.min(e.minY,A.minY),maxX:Math.max(e.maxX,A.maxX),maxY:Math.max(e.maxY,A.maxY)}),Pj=(e,A,t)=>{const i=t/2;return{minX:e-i,minY:A-i,maxX:e+i,maxY:A+i}},_6e=(e,A,t,i,n)=>{const o=t/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:e+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))}},ByA=e=>{let A=Number.POSITIVE_INFINITY,t=Number.POSITIVE_INFINITY,i=Number.NEGATIVE_INFINITY,n=Number.NEGATIVE_INFINITY;for(const o of e){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),t=Math.min(t,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=Pj(o.x,o.y,o.hole_diameter);A=Math.min(A,c.minX),t=Math.min(t,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=Pj(o.x,o.y,o.outer_diameter):"hole_diameter"in o&&typeof o.hole_diameter=="number"&&(c=Pj(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=_6e(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?CQt(c,I):I}if("hole_diameter"in o&&typeof o.hole_diameter=="number"){const I=Pj(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?CQt(c,I):I}if(c){A=Math.min(A,c.minX),t=Math.min(t,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),t=Math.min(t,r),i=Math.max(i,s),n=Math.max(n,r),a!==void 0&&g!==void 0&&(A=Math.min(A,s-a/2),t=Math.min(t,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),t=Math.min(t,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),t=Math.min(t,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),t=Math.min(t,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),t=Math.min(t,c.y),i=Math.max(i,c.x),n=Math.max(n,c.y)}return{minX:A,minY:t,maxX:i,maxY:n}};function k6e(e){let A=0;if(e.length==0)return A;for(var t=0;t<e.length;t++){var i=e.charCodeAt(t);A=(A<<5)-A+i,A=A&A}return Math.abs(A)}var QQt=[["#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"]],v6e=e=>{let{x:A,y:t,width:i,height:n}={...e,...e.size,...e.center,...e.position};if(e.x1!==void 0&&e.x2!==void 0&&e.y1!==void 0&&e.y2!==void 0&&(A=(e.x1+e.x2)/2,t=(e.y1+e.y2)/2,i=Math.abs(e.x1-e.x2),n=Math.abs(e.y1-e.y2)),e.points&&Array.isArray(e.points)&&e.points.length>0){const r=e.points.map(B=>B.x),a=e.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,t=(I+l)/2,i=c-g,n=l-I}const o=e.text||e.name||e.source?.text||e.source?.name||"?",s=e;return A===void 0||t===void 0?null:(i===void 0&&"outer_diameter"in e&&(i=e.outer_diameter,n=e.outer_diameter),(i===void 0||n===void 0)&&(i=.1,n=.1),{x:A,y:t,width:i,height:n,title:o,content:s,bg_color:QQt[k6e(e.type||o)%QQt.length]?.[4]??"#f00"})},F6e=e=>!!e,M6e=e=>{const A=e.filter(g=>g.type.startsWith("pcb_")||g.type.startsWith("schematic_")).concat(e.filter(g=>g.type==="pcb_trace"||g.type==="schematic_trace").flatMap(g=>g.route)).map(g=>v6e(g)).filter(F6e);if(A.length===0)return{center:{x:0,y:0},width:0,height:0};let t=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))t=Math.min(t,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-t,r=o-n;return{center:{x:t+s/2,y:n+r/2},width:s,height:r}},Id={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"},mM=(e,A)=>{if(typeof window>"u")return A;try{const t=localStorage.getItem(e);return t!==null?JSON.parse(t):A}catch{return A}},wM=(e,A)=>{if(!(typeof window>"u"))try{localStorage.setItem(e,JSON.stringify(A))}catch{}},G6e=(e,A)=>{if(typeof window>"u")return A;try{const t=localStorage.getItem(e);return t!==null?JSON.parse(t):A}catch{return A}},R6e=(e,A)=>{if(!(typeof window>"u"))try{localStorage.setItem(e,JSON.stringify(A))}catch{}},N6e="named_only",L6e=(e={},A=!1)=>TBt(t=>({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:mM(Id.IS_SHOWING_COPPER_POURS,!0),is_showing_courtyards:mM(Id.IS_SHOWING_COURTYARDS,!0),is_showing_pcb_groups:A?!1:mM(Id.IS_SHOWING_PCB_GROUPS,!0),is_showing_group_anchor_offsets:mM(Id.IS_SHOWING_GROUP_ANCHOR_OFFSETS,!1),is_showing_solder_mask:mM(Id.IS_SHOWING_SOLDER_MASK,!1),is_showing_silkscreen:mM(Id.IS_SHOWING_SILKSCREEN,!0),is_showing_fabrication_notes:mM(Id.IS_SHOWING_FABRICATION_NOTES,!1),pcb_group_view_mode:A?"all":G6e(Id.PCB_GROUP_VIEW_MODE,N6e),hovered_error_id:null,...e,selectLayer:i=>t({selected_layer:i}),setEditMode:i=>t({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=>t({is_showing_rats_nest:i}),setIsMovingComponent:i=>t({is_moving_component:i}),setIsDrawingTrace:i=>t({is_drawing_trace:i}),setIsMouseOverContainer:i=>t({is_mouse_over_container:i}),setIsShowingMultipleTracesLength:i=>t({is_showing_multiple_traces_length:i}),setIsShowingAutorouting:i=>t({is_showing_autorouting:i}),setIsShowingDrcErrors:i=>t({is_showing_drc_errors:i}),setIsShowingCopperPours:i=>{wM(Id.IS_SHOWING_COPPER_POURS,i),t({is_showing_copper_pours:i})},setIsShowingCourtyards:i=>{wM(Id.IS_SHOWING_COURTYARDS,i),t({is_showing_courtyards:i})},setIsShowingPcbGroups:i=>{A||(wM(Id.IS_SHOWING_PCB_GROUPS,i),t({is_showing_pcb_groups:i}))},setIsShowingGroupAnchorOffsets:i=>{wM(Id.IS_SHOWING_GROUP_ANCHOR_OFFSETS,i),t({is_showing_group_anchor_offsets:i})},setIsShowingSolderMask:i=>{wM(Id.IS_SHOWING_SOLDER_MASK,i),t({is_showing_solder_mask:i})},setIsShowingSilkscreen:i=>{wM(Id.IS_SHOWING_SILKSCREEN,i),t({is_showing_silkscreen:i})},setIsShowingFabricationNotes:i=>{wM(Id.IS_SHOWING_FABRICATION_NOTES,i),t({is_showing_fabrication_notes:i})},setPcbGroupViewMode:i=>{A||(R6e(Id.PCB_GROUP_VIEW_MODE,i),t({pcb_group_view_mode:i}))},setHoveredErrorId:i=>t({hovered_error_id:i})})),rl=e=>{const A=AA.useContext(hQt);return XBt(A,e)},hQt=AA.createContext(null),U6e=({children:e,initialState:A,disablePcbGroups:t})=>{const i=AA.useMemo(()=>L6e(A,t),[t]);return Z.jsx(hQt.Provider,{value:i,children:e})},H6e=()=>{const e=rl(t=>t.pcb_viewer_id),A=(t,i)=>ec(t,{containerId:e,...i});return A.error=(t,i)=>ec.error(t,{containerId:e,...i}),A.promise=ec.promise,A},Y6e=()=>{AA.useEffect(()=>{Mje()},[]);const e=rl(A=>A.pcb_viewer_id);return Z.jsx(Fje,{position:"top-center",containerId:e})};function J6e(){var e=AA.useRef(!1),A=AA.useCallback(function(){return e.current},[]);return AA.useEffect(function(){return e.current=!0,function(){e.current=!1}},[]),A}var T6e=function(e){e===void 0&&(e={});var A=AA.useState(e),t=A[0],i=A[1],n=AA.useCallback(function(o){i(function(s){return Object.assign({},s,o instanceof Function?o(s):o)})},[]);return[t,n]},P6e=T6e,K6e=function(){},EQt=typeof window<"u",q6e=ryA(g6e()),O6e=function(){var e=J6e(),A=P6e({value:void 0,error:void 0,noUserInteraction:!0}),t=A[0],i=A[1],n=AA.useCallback(function(o){if(e()){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,q6e.default)(r),i({value:r,error:void 0,noUserInteraction:s})}catch(g){i({value:r,error:g,noUserInteraction:s})}}},[]);return[t,n]},W6e=O6e,Z6e=EQt?AA.useLayoutEffect:AA.useEffect,V6e=Z6e,uQt={x:0,y:0,width:0,height:0,top:0,left:0,bottom:0,right:0};function j6e(){var e=AA.useState(null),A=e[0],t=e[1],i=AA.useState(uQt),n=i[0],o=i[1],s=AA.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 V6e(function(){if(A)return s.observe(A),function(){s.disconnect()}},[A]),[t,n]}var yT=EQt&&typeof window.ResizeObserver<"u"?j6e:function(){return[K6e,uQt]},dQt=({initialTransform:e,initialTouch1:A,initialTouch2:t,finalTouch1:i,finalTouch2:n})=>{if(!i||!n)return e;const o={x:(A.x+t.x)/2,y:(A.y+t.y)/2},s={x:(i.x+n.x)/2,y:(i.y+n.y)/2},r=Math.hypot(t.x-A.x,t.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 tn(sn(c,I),sn(o.x,o.y),za(g,g),sn(-o.x,-o.y),e)},z6e=(e={})=>{const A=AA.useRef(null),[t,i]=AA.useState(0),n=e.canvasElm??A.current,[o,s]=AA.useState(e.initialTransform??ba()),[r,a]=AA.useState(0),[g,c]=AA.useReducer(d=>d+1,0),I=AA.useCallback(d=>{e.onSetTransform&&e.onSetTransform(d),e.transform||s(d)},[e.onSetTransform,s]),l=AA.useCallback(d=>{I(d),c()},[I]),B=e.transform??o,C=AA.useCallback(()=>{i(Date.now())},[]),Q=AA.useRef("none"),h=AA.useRef(null),E=AA.useRef(null);AA.useEffect(()=>{const d=e.canvasElm??A.current;if(d&&!n){a(r+1);return}if(!d){const W=setTimeout(()=>{a(r+1)},100);return()=>clearTimeout(W)}let f=e.transform??o,m={x:0,y:0},w={x:0,y:0},D=!1;const S=W=>({x:W.pageX-d.getBoundingClientRect().left-window.scrollX,y:W.pageY-d.getBoundingClientRect().top-window.scrollY});function _(W){e.enabled!==!1&&(e.shouldDrag&&!e.shouldDrag(W)||(m=S(W),!(Date.now()-t<100)&&(D=!0,W.preventDefault())))}function b(W){if(!D||e.enabled===!1||e.shouldDrag&&!e.shouldDrag(W))return;w=S(W);const z=tn(sn(w.x-m.x,w.y-m.y),f);I(z),f=z,D=!1}function R(W){if(S(W),!D||e.enabled===!1||e.shouldDrag&&!e.shouldDrag(W))return;w=S(W);const z=tn(sn(w.x-m.x,w.y-m.y),f);I(z)}function F(W){if(e.enabled===!1||e.shouldDrag&&!e.shouldDrag(W))return;const z=S(W),tA=tn(sn(z.x,z.y),za(1-W.deltaY/1e3,1-W.deltaY/1e3),sn(-z.x,-z.y),f);I(tA),f=tA,W.preventDefault()}function H(W){if(!D||e.shouldDrag&&!e.shouldDrag(W))return;if(d){const tA=d.getBoundingClientRect();if(W.clientX>=tA.left+10&&W.clientX<=tA.right-10&&W.clientY>=tA.top+10&&W.clientY<=tA.bottom-10)return}D=!1,w=S(W);const z=tn(sn(w.x-m.x,w.y-m.y),f);I(z),f=z}function Y(W){if(W.preventDefault(),e.enabled!==!1){if(W.touches.length===1){Q.current="drag";const z=W.touches[0];h.current={initialTransform:f,initialTouch:{x:z.clientX,y:z.clientY}}}else if(W.touches.length===2){Q.current="pinch";const z=W.touches[0],tA=W.touches[1];E.current={initialTransform:f,initialTouch1:{x:z.clientX,y:z.clientY},initialTouch2:{x:tA.clientX,y:tA.clientY},finalTouch1:null,finalTouch2:null}}}}function J(W){if(W.preventDefault(),e.enabled!==!1){if(Q.current==="drag"&&W.touches.length===1&&h.current){const z=W.touches[0],tA={x:z.clientX,y:z.clientY},aA=tA.x-h.current.initialTouch.x,eA=tA.y-h.current.initialTouch.y,oA=tn(sn(aA,eA),h.current.initialTransform);I(oA)}else if(Q.current==="pinch"&&W.touches.length===2&&E.current){const z=W.touches[0],tA=W.touches[1];E.current.finalTouch1={x:z.clientX,y:z.clientY},E.current.finalTouch2={x:tA.clientX,y:tA.clientY};const aA=dQt(E.current);I(aA)}}}function O(W){W.preventDefault();const z=W.changedTouches[0];if(Q.current==="drag"&&h.current&&z){const tA={x:z.clientX,y:z.clientY},aA=tA.x-h.current.initialTouch.x,eA=tA.y-h.current.initialTouch.y,oA=tn(sn(aA,eA),h.current.initialTransform);I(oA),f=oA}else if(Q.current==="pinch"&&E.current){const tA=dQt(E.current);I(tA),f=tA}Q.current="none",h.current=null,E.current=null}return d.addEventListener("mousedown",_),d.addEventListener("mouseup",b),window.addEventListener("mousemove",R),d.addEventListener("mouseout",H),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",R),d.removeEventListener("mouseout",H),d.removeEventListener("wheel",F),d.removeEventListener("touchstart",Y),d.removeEventListener("touchmove",J),d.removeEventListener("touchend",O),d.removeEventListener("touchcancel",O)}},[n,r,g,t,e.enabled,e.shouldDrag]);const u=AA.useCallback(d=>Ct(B,d),[B]);return{ref:A,transform:B,applyTransformToPoint:u,setTransform:l,cancelDrag:C}},X6e=z6e;function $6e(e){const A=new Map;let t=0;function i(n){for(const[,s]of A)if(s.has(n))return s;const o=new Set;return A.set(`connectivity_net${t++}`,o),o}for(const n of e){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 A7e=class{netMap;idToNetMap;constructor(e){this.netMap=e,this.idToNetMap={};for(const[A,t]of Object.entries(e))for(const i of t)this.idToNetMap[i]=A}addConnections(e){for(const A of e){const t=new Set;for(const n of A){const o=this.idToNetMap[n];o&&t.add(o)}let i;if(t.size===0)i=`connectivity_net${Object.keys(this.netMap).length}`,this.netMap[i]=[];else if(t.size===1)i=t.values().next().value??`connectivity_net${Object.keys(this.netMap).length}`;else{i=t.values().next().value??`connectivity_net${Object.keys(this.netMap).length}`;for(const n of t)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(e){return this.netMap[e]||[]}getNetConnectedToId(e){return this.idToNetMap[e]}areIdsConnected(e,A){if(e===A)return!0;const t=this.getNetConnectedToId(e);if(!t)return!1;const i=this.getNetConnectedToId(A);return i?t===i||i===e||i===e:!1}areAllIdsConnected(e){const A=this.getNetConnectedToId(e[0]);for(const t of e){const i=this.getNetConnectedToId(t);if(i===void 0||i!==A)return!1}return!0}},pQt=e=>{const A=[];for(const i of e)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 t=$6e(A);return new A7e(t)};function t7e({primitivesWithoutInteractionMetadata:e,drawingObjectIdsWithMouseOver:A,primitiveIdsInMousedOverNet:t}){const i=[];for(const n of e){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&&t.includes(n._element.pcb_trace_id)||"pcb_port_id"in n._element&&t.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 e7e(e,A){if(e.length<2)throw new Error("Stroke must have at least two points");const t=e.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(t[0],t[1]),a=t[0].trace_width??A;s(t[0],r,1,a),s(t[0],r,-1,a);for(let I=1;I<t.length-1;I++){const l=t[I-1],B=t[I],C=t[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(t[t.length-2],t[t.length-1]),c=t[t.length-1].trace_width??A;return s(t[t.length-1],g,1,c),s(t[t.length-1],g,-1,c),[...i,...n]}var i7e=(e,A)=>{const{x:t,y:i,width:n,height:o,layer:s,rect_border_radius:r}=e,a=e.corner_radius??r??0,g=[{_pcb_drawing_object_id:wm("rect"),pcb_drawing_type:"rect",x:t,y:i,w:n,h:o,layer:s||"top",_element:e,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,roundness:a,...e.shape==="rotated_rect"&&e.ccw_rotation!==void 0?{ccw_rotation:e.ccw_rotation}:{}}];if(e.is_covered_with_solder_mask){const c=s==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",l={...{_pcb_drawing_object_id:wm("rect"),pcb_drawing_type:"rect",x:t,y:i,w:n,h:o,layer:c,_element:e,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,roundness:a,...e.shape==="rotated_rect"&&e.ccw_rotation!==void 0?{ccw_rotation:e.ccw_rotation}:{}},..."solder_mask_color"in e&&e.solder_mask_color?{color:e.solder_mask_color}:{}};g.push(l)}return g},n7e=(e,A)=>{const{x:t,y:i,radius:n,layer:o}=e,s=[{_pcb_drawing_object_id:wm("circle"),pcb_drawing_type:"circle",x:t,y:i,r:n,layer:o||"top",_element:e,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port}];if(e.is_covered_with_solder_mask){const r=o==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",a={_pcb_drawing_object_id:wm("circle"),pcb_drawing_type:"circle",x:t,y:i,r:n,layer:r,_element:e,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,..."solder_mask_color"in e&&e.solder_mask_color?{color:e.solder_mask_color}:{}};s.push(a)}return s},o7e=(e,A)=>{const{layer:t,points:i}=e,n=[{_pcb_drawing_object_id:wm("polygon"),pcb_drawing_type:"polygon",points:CyA(i),layer:t||"top",_element:e,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port}];if(e.is_covered_with_solder_mask){const o=t==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",s={_pcb_drawing_object_id:wm("polygon"),pcb_drawing_type:"polygon",points:CyA(i),layer:o,_element:e,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,..."solder_mask_color"in e&&e.solder_mask_color?{color:e.solder_mask_color}:{}};n.push(s)}return n},s7e=(e,A)=>{const{x:t,y:i,width:n,height:o,layer:s}=e,r=[{_pcb_drawing_object_id:wm("pill"),pcb_drawing_type:"pill",x:t,y:i,w:n,h:o,layer:s||"top",_element:e,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port}];if(e.is_covered_with_solder_mask){const a=s==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",g={_pcb_drawing_object_id:wm("pill"),pcb_drawing_type:"pill",x:t,y:i,w:n,h:o,layer:a,_element:e,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,..."solder_mask_color"in e&&e.solder_mask_color?{color:e.solder_mask_color}:{}};r.push(g)}return r},r7e=(e,A)=>{const{x:t,y:i,width:n,height:o,layer:s,ccw_rotation:r}=e,a=[{_pcb_drawing_object_id:wm("pill"),pcb_drawing_type:"pill",x:t,y:i,w:n,h:o,layer:s||"top",_element:e,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,ccw_rotation:r}];if(e.is_covered_with_solder_mask){const g=s==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",c={_pcb_drawing_object_id:wm("pill"),pcb_drawing_type:"pill",x:t,y:i,w:n,h:o,layer:g,_element:e,_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 e&&e.solder_mask_color?{color:e.solder_mask_color}:{}};a.push(c)}return a},a7e=(e,A)=>{const{_parent_pcb_component:t,_parent_source_component:i}=A,n=e,o=typeof n.font_size=="string"?Ee.parse(n.font_size):n.font_size??.2;let s;return n.knockout_padding&&(s={left:typeof n.knockout_padding.left=="string"?Ee.parse(n.knockout_padding.left):n.knockout_padding.left,top:typeof n.knockout_padding.top=="string"?Ee.parse(n.knockout_padding.top):n.knockout_padding.top,bottom:typeof n.knockout_padding.bottom=="string"?Ee.parse(n.knockout_padding.bottom):n.knockout_padding.bottom,right:typeof n.knockout_padding.right=="string"?Ee.parse(n.knockout_padding.right):n.knockout_padding.right}),[{_pcb_drawing_object_id:wm("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:e,_parent_pcb_component:t,_parent_source_component:i}]},HI=0,wm=e=>`${e}_${HI++}`,CyA=e=>(e??[]).map(A=>({x:Ee.parse(A.x),y:Ee.parse(A.y)})),g7e=(e,A)=>{const t="pcb_component_id"in e?A.find(s=>s.type==="pcb_component"&&s.pcb_component_id===e.pcb_component_id):void 0,i=t&&"source_component_id"in t?A.find(s=>s.type==="source_component"&&s.source_component_id===t.source_component_id):void 0,n="source_port_id"in e?e.source_port_id:"pcb_port_id"in e?Xb(A).pcb_port.get(e.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(e.type){case"pcb_smtpad":{const s={_parent_pcb_component:t,_parent_source_component:i,_source_port:o};return e.shape==="rect"||e.shape==="rotated_rect"?i7e(e,s):e.shape==="circle"?n7e(e,s):e.shape==="polygon"?o7e(e,s):e.shape==="pill"?s7e(e,s):e.shape==="rotated_pill"?r7e(e,s):[]}case"pcb_trace":{const s=[];if(e.route_thickness_mode==="interpolated"){const g=e.route.map(l=>({x:l.x,y:l.y,trace_width:l.route_type==="wire"?l.width:.5})),c=e7e(g,.5),I=e.route[0].layer;return s.push({_pcb_drawing_object_id:`polygon_${HI++}`,_element:e,pcb_drawing_type:"polygon",points:c,layer:I}),e.route.forEach(l=>{l.route_type==="via"&&s.push({_pcb_drawing_object_id:`circle_${HI++}`,_element:e,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 e.route)g.route_type==="wire"&&(r!==null&&a!==null&&s.push({_pcb_drawing_object_id:`line_${HI++}`,_element:e,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}=e,c=e.from_layer,I=e.to_layer,l=e.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_${HI++}`,pcb_drawing_type:"circle",x:s,y:r,r:a/2,layer:Q,_element:e,_parent_pcb_component:t,_parent_source_component:i});return C.push({_pcb_drawing_object_id:`circle_${HI++}`,pcb_drawing_type:"circle",x:s,y:r,r:g/2,layer:"drill",_element:e}),C}case"pcb_plated_hole":if(e.shape==="circle"){const{x:s,y:r,hole_diameter:a,outer_diameter:g}=e;return[{_pcb_drawing_object_id:`circle_${HI++}`,pcb_drawing_type:"circle",x:s,y:r,r:g/2,layer:"top",_element:e,_parent_pcb_component:t,_parent_source_component:i,_source_port:o},{_pcb_drawing_object_id:`circle_${HI++}`,pcb_drawing_type:"circle",x:s,y:r,r:a/2,layer:"drill",_element:e}]}else if(e.shape==="oval"){const{x:s,y:r,outer_height:a,outer_width:g,hole_height:c,hole_width:I}=e;return[{_pcb_drawing_object_id:`oval_${HI++}`,pcb_drawing_type:"oval",x:s,y:r,rX:g/2,rY:a/2,layer:"top",_element:e,_parent_pcb_component:t,_parent_source_component:i,_source_port:o},{_pcb_drawing_object_id:`oval_${HI++}`,_element:e,pcb_drawing_type:"oval",x:s,y:r,rX:I/2,rY:c/2,layer:"drill"}]}else if(e.shape==="pill"){const{x:s,y:r,outer_height:a,outer_width:g,hole_height:c,hole_width:I}=e;return[{_pcb_drawing_object_id:`pill_${HI++}`,pcb_drawing_type:"pill",x:s,y:r,w:g,h:a,layer:"top",_element:e,_parent_pcb_component:t,_parent_source_component:i,_source_port:o,ccw_rotation:e.ccw_rotation},{_pcb_drawing_object_id:`pill_${HI++}`,_element:e,pcb_drawing_type:"pill",x:s,y:r,w:I,h:c,layer:"drill",ccw_rotation:e.ccw_rotation}]}else if(e.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}=e,C=Ee.parse(l??0),Q=Ee.parse(B??0);return[{_pcb_drawing_object_id:`rect_${HI++}`,pcb_drawing_type:"rect",x:s,y:r,w:g,h:c,layer:"top",_element:e,_parent_pcb_component:t,_parent_source_component:i,_source_port:o,roundness:I},{_pcb_drawing_object_id:`rect_${HI++}`,pcb_drawing_type:"rect",x:s,y:r,w:g,h:c,layer:"bottom",_element:e,_parent_pcb_component:t,_parent_source_component:i,_source_port:o,roundness:I},{_pcb_drawing_object_id:`circle_${HI++}`,_element:e,pcb_drawing_type:"circle",x:s+C,y:r+Q,r:a/2,layer:"drill"}]}else if(e.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}=e;return[{_pcb_drawing_object_id:`rect_${HI++}`,pcb_drawing_type:"rect",x:s,y:r,w:c,h:I,layer:"top",_element:e,_parent_pcb_component:t,_parent_source_component:i,_source_port:o,roundness:l},{_pcb_drawing_object_id:`rect_${HI++}`,pcb_drawing_type:"rect",x:s,y:r,w:c,h:I,layer:"bottom",_element:e,_parent_pcb_component:t,_parent_source_component:i,_source_port:o,roundness:l},{_pcb_drawing_object_id:`pill_${HI++}`,_element:e,pcb_drawing_type:"pill",x:s,y:r,w:a,h:g,layer:"drill"}]}else if(e.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}=e;return[{_pcb_drawing_object_id:`rect_${HI++}`,pcb_drawing_type:"rect",x:s,y:r,w:I,h:l,layer:"top",_element:e,_parent_pcb_component:t,_parent_source_component:i,_source_port:o,ccw_rotation:B,roundness:C},{_pcb_drawing_object_id:`rect_${HI++}`,pcb_drawing_type:"rect",x:s,y:r,w:I,h:l,layer:"bottom",_element:e,_parent_pcb_component:t,_parent_source_component:i,_source_port:o,ccw_rotation:B,roundness:C},{_pcb_drawing_object_id:`pill_${HI++}`,_element:e,pcb_drawing_type:"pill",x:s,y:r,w:a,h:g,layer:"drill",ccw_rotation:c}]}else if(e.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}=e,h=Ee.parse(C??0),E=Ee.parse(Q??0),u=a,d=[];if(u&&Array.isArray(u)){const w=CyA(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_${HI++}`,pcb_drawing_type:"polygon",points:w,layer:D,_element:e,_parent_pcb_component:t,_parent_source_component:i,_source_port:o})}const f={x:s+h,y:r+E},m=[];return g==="circle"?m.push({_pcb_drawing_object_id:`circle_${HI++}`,pcb_drawing_type:"circle",x:f.x,y:f.y,r:(c??0)/2,layer:"drill",_element:e,_parent_pcb_component:t,_parent_source_component:i}):g==="oval"?m.push({_pcb_drawing_object_id:`oval_${HI++}`,pcb_drawing_type:"oval",x:f.x,y:f.y,rX:(I??0)/2,rY:(l??0)/2,layer:"drill",_element:e,_parent_pcb_component:t,_parent_source_component:i}):(g==="pill"||g==="rotated_pill")&&m.push({_pcb_drawing_object_id:`pill_${HI++}`,pcb_drawing_type:"pill",x:f.x,y:f.y,w:I??0,h:l??0,layer:"drill",_element:e,_parent_pcb_component:t,_parent_source_component:i,ccw_rotation:e.ccw_rotation}),[...d,...m]}else return[];case"pcb_copper_text":return a7e(e,{_parent_pcb_component:t,_parent_source_component:i})}return[]},pn={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)"}},Lf=(e,A=1)=>{if(Math.abs(e.a)!==Math.abs(e.d))throw new Error("Cannot scale non-uniformly");return A*Math.abs(e.a)},xc={elementOverlay:40,dimensionOverlay:40,editTraceHintOverlay:40,errorOverlay:40,pcbGroupOverlay:35,ratsNestOverlay:30,toolbarOverlay:70,warnings:30,topLayer:20,clickToInteractOverlay:100},Kj={red:"red",black:"black",green:"green",board:"rgb(255, 255, 255)",other:"#eee",top:pn.board.copper.f,inner1:pn.board.copper.in1,inner2:pn.board.copper.in2,inner3:pn.board.copper.in3,inner4:pn.board.copper.in4,inner5:pn.board.copper.in5,inner6:pn.board.copper.in6,inner7:pn.board.copper.in7,inner8:pn.board.copper.in8,bottom:pn.board.copper.b,drill:pn.board.anchor,keepout:pn.board.background,tkeepout:pn.board.b_crtyd,tplace:pn.board.b_silks,top_courtyard:pn.board.f_crtyd,bottom_courtyard:pn.board.b_crtyd,top_silkscreen:pn.board.f_silks,bottom_silkscreen:pn.board.b_silks,top_fabrication:pn.board.f_fab,bottom_fabrication:pn.board.b_fab,soldermask_top:pn.board.soldermask.top,soldermask_bottom:pn.board.soldermask.bottom,soldermask_with_copper_top:pn.board.soldermaskWithCopper.top,soldermask_with_copper_bottom:pn.board.soldermaskWithCopper.bottom,bottom_notes:pn.board.user_2,top_notes:pn.board.user_2,...pn.board},c7e=["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"],I7e=class{canvasLayerMap;ctxLayerMap;aperture;transform;foregroundLayer="top";lastPoint;constructor(e){this.canvasLayerMap=e,this.ctxLayerMap=Object.fromEntries(Object.entries(e).map(([A,t])=>[A,t.getContext("2d")])),this.transform=ba(),this.transform.d*=-1,this.transform=tn(this.transform,sn(0,-500)),this.lastPoint={x:0,y:0},this.equip({})}clear(){for(const e of Object.values(this.ctxLayerMap))e.clearRect(0,0,e.canvas.width,e.canvas.height)}equip(e){this.aperture={fontSize:0,shape:"circle",mode:"add",size:0,color:"red",layer:"top",opacity:this.foregroundLayer===e.color?1:.5,...e}}drawMeshPattern(e,A,t,i,n,o=45){const s=this.getLayerCtx(),[r,a]=Ct(this.transform,[e,A]),[g,c]=Ct(this.transform,[e+t,A+i]),I=Lf(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:e,y:A,w:t,h:i,mesh_fill:n,is_filled:o=!0,has_stroke:s,is_stroke_dashed:r,stroke_width:a,roundness:g}){const[c,I]=Ct(this.transform,[e-t/2,A-i/2]),[l,B]=Ct(this.transform,[e+t/2,A+i/2]);this.applyAperture();const C=this.getLayerCtx(),Q=g?Lf(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(e-t/2,A-i/2,t,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=Lf(this.transform,a)),r){let u=[];const d=Math.abs(this.transform.a);if(d>0){const m=.1*d,w=m*1.3;m>.5&&(u=[m,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(e,A,t,i,n,o,s){const r=this.getLayerCtx();this.applyAperture();const[a,g]=Ct(this.transform,[e-t/2,A-i/2]),[c,I]=Ct(this.transform,[e+t/2,A+i/2]),l=o?Lf(this.transform,o):0;r.save();const[B,C]=Ct(this.transform,[e,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(e-t/2,A-i/2,t,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(e,A,t,i,n){const o=this.getLayerCtx();this.applyAperture(),o.save();const[s,r]=Ct(this.transform,[e,A]);o.translate(s,r);const a=360-n;n&&o.rotate(a*Math.PI/180),o.translate(-s,-r),this.pill(e,A,t,i),o.restore()}circle(e,A,t,i,n=!0){const o=Lf(this.transform,t),[s,r]=Ct(this.transform,[e,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(e-t,A-t,t*2,t*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(e,A,t,i){const n=Lf(this.transform,t),o=Lf(this.transform,i),[s,r]=Ct(this.transform,[e,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(e,A,t,i){const[n,o]=Ct(this.transform,[e-t/2,A+i/2]),s=Lf(this.transform,t),r=Lf(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(e){if(e.length<3)return;this.applyAperture();const A=this.getLayerCtx(),t=e.map(n=>Ct(this.transform,[n.x,n.y]));A.beginPath(),A.moveTo(t[0][0],t[0][1]);for(let n=1;n<t.length;n++)A.lineTo(t[n][0],t[n][1]);A.closePath(),A.fill("evenodd");const i=Lf(this.transform,this.aperture.size);i>0&&(A.lineWidth=i,A.stroke())}debugText(e,A,t){const[i,n]=Ct(this.transform,[A,t]);this.applyAperture();const o=this.getLayerCtx();o.font="10px sans-serif",o.fillText(e,i,n)}getLayerCtx(){const e=this.ctxLayerMap[this.aperture.layer];if(!e)throw new Error(`No context for layer "${this.aperture.layer}"`);return e}orderAndFadeLayers(){const{canvasLayerMap:e,foregroundLayer:A}=this,t=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",...t?[t]:[],...i?[i]:[],...n?[n]:[],...o?[o]:[],...s?[s]:[]]),a=[A,"edge_cuts",...t?[t]:[],...i?[i]:[],...n?[n]:[],...o?[o]:[],...s?[s]:[]],g=A==="drill"?[]:["drill"],c=A==="drill"?["drill"]:[],I=[...c7e.filter(l=>!a.includes(l)),...g,A,...t?[t]:[],...c,"edge_cuts",...i?[i]:[],...n?[n]:[],...o?[o]:[],...s?[s]:[]];I.forEach((l,B)=>{const C=e[l];C&&(C.style.zIndex=`${xc.topLayer-(I.length-B)}`,C.style.opacity=r.has(l)?"1":"0.5")})}applyAperture(){const{transform:e,aperture:A}=this;let{size:t,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=Lf(e,t),r.lineCap="round",i==="add"){r.globalCompositeOperation="source-over";let a=Kj[n.toLowerCase()];if(!a)try{a=Ha(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=`${Lf(Xy(e),o)}px sans-serif`}moveTo(e,A){this.lastPoint={x:e,y:A}}lineTo(e,A){const[t,i]=Ct(this.transform,[e,A]),{size:n,shape:o,mode:s}=this.aperture,r=Lf(this.transform,n),{lastPoint:a}=this,g=Ct(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(t,i),c.stroke(),c.closePath(),o==="square"&&c.fillRect(t-r/2,i-r/2,r,r),this.lastPoint={x:e,y:A}}polygonWithArcs(e){const A=this.getLayerCtx(),t=i=>{if(i.vertices.length===0)return;const n=i.vertices[0],o=Ct(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=Ct(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,m=Math.sqrt(Math.max(0,C*C-(l/2)**2)),w=Q+m*d*Math.sign(g),D=h+m*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=Ct(this.transform,[w,D]),R=Lf(this.transform,C);A.arc(b[0],b[1],R,-S,-_,g>0)}else{const g=Ct(this.transform,[a.x,a.y]);A.lineTo(g[0],g[1])}}A.closePath()};if(A.beginPath(),t(e.outer_ring),e.inner_rings)for(const i of e.inner_rings)t(i);A.fill("evenodd")}};function l7e(e){return e.type==="pcb_copper_pour"}function qj({canvas:e,elements:A,layers:t,realToCanvasMat:i}){const n=A.filter(l7e);if(n.length===0)return;const o=new eQ(e);o.realToCanvasMat=i,o.drawElements(n,{layers:t})}var B7e={...sp,silkscreen:{top:pn.board.f_fab,bottom:pn.board.b_fab}};function C7e(e){return e.type.includes("pcb_fabrication_note")}function fQt({canvas:e,elements:A,layers:t,realToCanvasMat:i}){const n=new eQ(e);n.configure({colorOverrides:B7e}),n.realToCanvasMat=i;const o=A.filter(C7e);n.drawElements(o,{layers:t})}function Q7e(e){return e.type==="pcb_hole"}function h7e({canvas:e,elements:A,layers:t,realToCanvasMat:i,drawSoldermask:n}){const o=new eQ(e);o.realToCanvasMat=i;const s=A.filter(Q7e);o.drawElements(s,{layers:t,drawSoldermask:n})}function E7e(e){return e.type==="pcb_board"}function u7e({canvas:e,elements:A,layers:t,realToCanvasMat:i,drawSoldermask:n}){const o=new eQ(e);o.realToCanvasMat=i;const s=A.filter(E7e);for(const r of s)o.drawElements([r],{layers:t,drawSoldermask:!1,drawBoardMaterial:n??!1,minBoardOutlineStrokePx:2})}function d7e(e){return e.type==="pcb_cutout"}function p7e({canvas:e,elements:A,layers:t,realToCanvasMat:i}){const n=new eQ(e);n.realToCanvasMat=i;const o=A.filter(d7e);n.drawElements(o,{layers:t})}function f7e(e){return e.type==="pcb_keepout"}function y7e({canvas:e,elements:A,layers:t,realToCanvasMat:i}){const n=A.filter(f7e);if(n.length===0)return;const o=new eQ(e);o.realToCanvasMat=i,o.drawElements(n,{layers:[]})}function m7e(e){return e.type.startsWith("pcb_note_")}function yQt({canvas:e,elements:A,layers:t,realToCanvasMat:i}){const n=new eQ(e);n.realToCanvasMat=i;const o=A.filter(m7e);n.drawElements(o,{layers:t})}function w7e(e){return e.type==="pcb_panel"}function D7e({canvas:e,elements:A,layers:t,realToCanvasMat:i,drawSoldermask:n}){const o=new eQ(e);o.realToCanvasMat=i;const s=A.filter(w7e);for(const r of s)o.drawElements([r],{layers:t})}var S7e={...sp,copper:{...sp.copper,top:Ha(pn.board.pad_front).lighten(.5).toString(),bottom:Ha(pn.board.pad_back).lighten(.5).toString(),inner1:Ha(pn.board.copper.in1).lighten(.5).toString(),inner2:Ha(pn.board.copper.in2).lighten(.5).toString(),inner3:Ha(pn.board.copper.in3).lighten(.5).toString(),inner4:Ha(pn.board.copper.in4).lighten(.5).toString(),inner5:Ha(pn.board.copper.in5).lighten(.5).toString(),inner6:Ha(pn.board.copper.in6).lighten(.5).toString()}};function b7e(e){return e.type==="pcb_smtpad"}function x7e({canvas:e,elements:A,layers:t,realToCanvasMat:i,primitives:n,drawSoldermask:o}){const s=A.filter(b7e).filter(c=>{const I=c.layer;return t.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 eQ(e);c.realToCanvasMat=i,c.drawElements(g,{layers:t,drawSoldermask:o})}if(a.length>0){const c=new eQ(e);c.configure({colorOverrides:S7e}),c.realToCanvasMat=i,c.drawElements(a,{layers:t,drawSoldermask:o})}}var _7e={...sp,copper:{...sp.copper,top:Ha(pn.board.pad_front).lighten(.5).toString(),bottom:Ha(pn.board.pad_back).lighten(.5).toString(),inner1:Ha(pn.board.copper.in1).lighten(.5).toString(),inner2:Ha(pn.board.copper.in2).lighten(.5).toString(),inner3:Ha(pn.board.copper.in3).lighten(.5).toString(),inner4:Ha(pn.board.copper.in4).lighten(.5).toString(),inner5:Ha(pn.board.copper.in5).lighten(.5).toString(),inner6:Ha(pn.board.copper.in6).lighten(.5).toString()}};function k7e(e){return e.type==="pcb_trace"}var v7e=e=>e.map(A=>A.endsWith("_copper")?A.replace("_copper",""):A),F7e=(e,A)=>{const t=e.route.filter(i=>i.route_type==="wire"&&"layer"in i&&A.has(i.layer));return t.length===0?null:{...e,route:t}};function M7e({canvas:e,elements:A,layers:t,realToCanvasMat:i,primitives:n}){const o=new Set(v7e(t)),s=A.filter(k7e).map(c=>F7e(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 eQ(e);c.realToCanvasMat=i,c.drawElements(g,{layers:t})}if(a.length>0){const c=new eQ(e);c.configure({colorOverrides:_7e}),c.realToCanvasMat=i,c.drawElements(a,{layers:t})}}var G7e={...sp,copper:{...sp.copper,top:Ha(pn.board.pad_front).lighten(.5).toString(),bottom:Ha(pn.board.pad_back).lighten(.5).toString()}};function R7e(e){return e.type==="pcb_plated_hole"}function mQt({canvas:e,elements:A,layers:t,realToCanvasMat:i,primitives:n,drawSoldermask:o}){const s=A.filter(R7e);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 eQ(e);c.realToCanvasMat=i,c.drawElements(g,{layers:t,drawSoldermask:o})}if(a.length>0){const c=new eQ(e);c.configure({colorOverrides:G7e}),c.realToCanvasMat=i,c.drawElements(a,{layers:t,drawSoldermask:o})}}function wQt(e){const{lines:A,anchorPoint:t,ccwRotation:i}=e;if(!i)return A;const n=i*Math.PI/180,o=Jl(n),s=tn(sn(t.x,t.y),o,sn(-t.x,-t.y));return Ct(s,t),A.map(r=>({...r,x1:Ct(s,{x:r.x1,y:r.y1}).x,y1:Ct(s,{x:r.x1,y:r.y1}).y,x2:Ct(s,{x:r.x2,y:r.y2}).x,y2:Ct(s,{x:r.x2,y:r.y2}).y}))}var N7e=.6,DQt=.2,SQt=e=>{const A=e.size*.7,t=A*N7e,i=A*DQt,n=A*DQt,o=e.text.split(/\r?\n/),s=e.text.length>0&&A>0,r=s?o.length:0,a=s?o.map(I=>I.length===0?0:I.length*t+(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:t,space_between_chars:i,space_between_lines:n,width:g,height:c}},bQt=e=>{const A=SQt(e);return{width:A.width,height:A.height,lineHeight:A.target_height,lineSpacing:A.space_between_lines,lineCount:A.line_count}},xQt=e=>{const{text_lines:A,line_count:t,line_widths:i,target_height:n,target_width_char:o,space_between_chars:s,space_between_lines:r,width:a}=SQt(e);if(n<=0||t===0)return[];const g=n/12,c=[];for(let I=0;I<t;I++){const l=-I*(n+r),B=i[I],C=(a-B)/2;let Q=e.x+C;for(let h=0;h<A[I].length;h++){const E=A[I][h],u=YF[E]??YF[E.toUpperCase()];if(!u){Q+=o+s;continue}for(const{x1:d,y1:f,x2:m,y2:w}of u)c.push({_pcb_drawing_object_id:wm("line"),pcb_drawing_type:"line",x1:Q+o*d,y1:e.y+l+n*f,x2:Q+o*m,y2:e.y+l+n*w,width:g,layer:e.layer,unit:e.unit,color:e.color});Q+=o+s}}return c};function IS(e){const t=e.color??Kj[e.layer];let i=Ha(t);return e._element?.type==="pcb_copper_pour"&&(i=i.alpha(.7)),e.is_mouse_over||e.is_in_highlighted_net?i.lighten(.5).rgb().toString():i.rgb().toString()}var _Qt=(e,A)=>{e.equip({size:A.zoomIndependent?A.width/e.transform.a:A.width,shape:A.squareCap?"square":"circle",color:IS(A),layer:A.layer}),e.moveTo(A.x1,A.y1),e.lineTo(A.x2,A.y2)},L7e=(e,A,t)=>{switch(t){case"top_left":return{x:0,y:-A};case"top_center":return{x:-e/2,y:-A};case"top_right":return{x:-e,y:-A};case"center_left":return{x:0,y:-A/2};case"center":return{x:-e/2,y:-A/2};case"center_right":return{x:-e,y:-A/2};case"bottom_left":return{x:0,y:0};case"bottom_center":return{x:-e/2,y:0};case"bottom_right":return{x:-e,y:0};default:return{x:0,y:0}}},kQt=e=>e.layer==="bottom_silkscreen"||e.layer==="bottom"?e.is_mirrored!==!1:e.is_mirrored===!0,U7e=(e,A)=>{e.equip({fontSize:A.size,color:IS(A),layer:A.layer});const{width:t,height:i}=bQt(A),n=L7e(t,i,A.align);A.x??=0,A.y??=0;const o={x:A.x,y:A.y};let s=xQt({...A,x:A.x+n.x,y:A.y+n.y});if(kQt(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=wQt(r)}for(const r of s)_Qt(e,r)},H7e=(e,A)=>{const{width:t,height:i,lineHeight:n}=bQt(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=t+o.left+o.right,r=i+o.top+o.bottom,a=t/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?FQt(e,B):vQt(e,B);let C=xQt({...A,x:c,y:I});if(kQt(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=wQt(Q)}for(const Q of C)e.equip({size:Q.width,shape:"circle",color:"black",layer:A.layer,mode:"subtract"}),e.moveTo(Q.x1,Q.y1),e.lineTo(Q.x2,Q.y2);e.equip({mode:"add"})},vQt=(e,A)=>{e.equip({color:IS(A),layer:A.layer,size:A.stroke_width}),e.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})},FQt=(e,A)=>{e.equip({color:IS(A),layer:A.layer}),e.rotatedRect(A.x,A.y,A.w,A.h,A.ccw_rotation,A.roundness,A.mesh_fill)},Y7e=(e,A)=>{e.equip({color:IS(A),layer:A.layer}),e.rotatedPill(A.x,A.y,A.w,A.h,A.ccw_rotation)},J7e=(e,A)=>{e.equip({color:IS(A),layer:A.layer}),e.circle(A.x,A.y,A.r,A.mesh_fill)},T7e=(e,A)=>{e.equip({color:IS(A),layer:A.layer}),e.oval(A.x,A.y,A.rX,A.rY)},P7e=(e,A)=>{e.equip({color:IS(A),layer:A.layer}),e.pill(A.x,A.y,A.w,A.h)},K7e=(e,A)=>{e.equip({color:IS(A),layer:A.layer}),e.polygon(A.points)},q7e=(e,A)=>{e.equip({color:IS(A),layer:A.layer}),e.polygonWithArcs(A.brep_shape)},O7e=(e,A)=>{switch(A.pcb_drawing_type){case"line":return _Qt(e,A);case"text":return A.is_knockout?H7e(e,A):U7e(e,A);case"rect":return A.ccw_rotation?FQt(e,A):vQt(e,A);case"circle":return J7e(e,A);case"oval":return T7e(e,A);case"pill":return A.ccw_rotation?Y7e(e,A):P7e(e,A);case"polygon":return K7e(e,A);case"polygon_with_arcs":return q7e(e,A)}},W7e=(e,A)=>{for(const t of A)O7e(e,t)},Z7e={...sp,copper:{...sp.copper,top:Ha(pn.board.pad_front).lighten(.5).toString(),bottom:Ha(pn.board.pad_back).lighten(.5).toString(),inner1:Ha(pn.board.copper.in1).lighten(.5).toString(),inner2:Ha(pn.board.copper.in2).lighten(.5).toString(),inner3:Ha(pn.board.copper.in3).lighten(.5).toString(),inner4:Ha(pn.board.copper.in4).lighten(.5).toString(),inner5:Ha(pn.board.copper.in5).lighten(.5).toString(),inner6:Ha(pn.board.copper.in6).lighten(.5).toString()},soldermask:{...sp.soldermask,top:Ha(pn.board.soldermask.top).lighten(.35).toString(),bottom:Ha(pn.board.soldermask.bottom).lighten(.35).toString()}};function MQt({canvas:e,elements:A,layers:t,realToCanvasMat:i,drawSoldermaskTop:n,drawSoldermaskBottom:o,primitives:s}){const r=new eQ(e);r.realToCanvasMat=i;const a=A.filter(l=>l.type==="pcb_board");if(a.length<=1)r.drawElements(A,{layers:t,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:t,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 eQ(e);I.configure({colorOverrides:Z7e}),I.realToCanvasMat=i,I.drawElements(c,{layers:t,drawSoldermask:!0,drawSoldermaskTop:n,drawSoldermaskBottom:o,drawBoardMaterial:!1})}var V7e={...sp,silkscreen:{top:pn.board.f_silks,bottom:pn.board.b_silks}};function j7e(e){return e.type.includes("pcb_silkscreen")}function GQt({canvas:e,elements:A,layers:t,realToCanvasMat:i}){const n=new eQ(e);n.configure({colorOverrides:V7e}),n.realToCanvasMat=i;const o=A.filter(j7e);n.drawElements(o,{layers:t})}var z7e={...sp,copper:{...sp.copper,top:Ha(pn.board.pad_front).lighten(.5).toString(),bottom:Ha(pn.board.pad_back).lighten(.5).toString()}};function X7e(e){return e.type==="pcb_via"}function RQt({canvas:e,elements:A,layers:t,realToCanvasMat:i,primitives:n,drawSoldermask:o}){const s=A.filter(X7e).filter(c=>t.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 eQ(e);c.realToCanvasMat=i,c.drawElements(g,{layers:t,drawSoldermask:o})}if(a.length>0){const c=new eQ(e);c.configure({colorOverrides:z7e}),c.realToCanvasMat=i,c.drawElements(a,{layers:t,drawSoldermask:o})}}var $7e={...sp,courtyard:{top:pn.board.f_crtyd,bottom:pn.board.b_crtyd}};function A$e(e){return e.type==="pcb_courtyard_circle"||e.type==="pcb_courtyard_rect"||e.type==="pcb_courtyard_outline"}function NQt({canvas:e,elements:A,layers:t,realToCanvasMat:i}){const n=new eQ(e);n.configure({colorOverrides:$7e}),n.realToCanvasMat=i;const o=A.filter(A$e);n.drawElements(o,{layers:t})}var t$e=["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"],e$e=({primitives:e,elements:A,transform:t,grid:i,width:n=500,height:o=500})=>{const s=AA.useRef({}),r=rl(l=>l.selected_layer),a=rl(l=>l.is_showing_solder_mask),g=rl(l=>l.is_showing_fabrication_notes),c=rl(l=>l.is_showing_courtyards),I=rl(l=>l.is_showing_silkscreen);return AA.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 I7e(l);t&&(B.transform=t),B.clear(),B.foregroundLayer=r;const C=e.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(W7e(B,C),t){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,m=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:m,copperLayer:"inner5_copper"},{canvas:w,copperLayer:"inner6_copper"}];for(const{canvas:Y,copperLayer:J}of D)Y&&M7e({canvas:Y,elements:A,layers:[J],realToCanvasMat:t,primitives:e});Q&&mQt({canvas:Q,elements:A,layers:["top_copper"],realToCanvasMat:t,primitives:e,drawSoldermask:a}),h&&mQt({canvas:h,elements:A,layers:["bottom_copper"],realToCanvasMat:t,primitives:e,drawSoldermask:a}),Q&&qj({canvas:Q,elements:A,layers:["top_copper"],realToCanvasMat:t}),h&&qj({canvas:h,elements:A,layers:["bottom_copper"],realToCanvasMat:t});for(const{canvas:Y,copperLayer:J}of D)Y&&x7e({canvas:Y,elements:A,layers:[J],realToCanvasMat:t,primitives:e,drawSoldermask:a});if(Q&&RQt({canvas:Q,elements:A,layers:["top_copper"],realToCanvasMat:t,primitives:e,drawSoldermask:a}),h&&RQt({canvas:h,elements:A,layers:["bottom_copper"],realToCanvasMat:t,primitives:e,drawSoldermask:a}),a){const Y=r==="bottom"?"bottom":"top",J=Y==="top",O=Y==="bottom",W=s.current.soldermask_top;W&&Y==="top"&&MQt({canvas:W,elements:A,layers:["top_soldermask"],realToCanvasMat:t,drawSoldermaskTop:J,drawSoldermaskBottom:O,primitives:e});const z=s.current.soldermask_bottom;z&&Y==="bottom"&&MQt({canvas:z,elements:A,layers:["bottom_soldermask"],realToCanvasMat:t,drawSoldermaskTop:J,drawSoldermaskBottom:O,primitives:e})}Q&&qj({canvas:Q,elements:A,layers:["top_copper"],realToCanvasMat:t}),h&&qj({canvas:h,elements:A,layers:["bottom_copper"],realToCanvasMat:t});const S=s.current.drill;if(S&&h7e({canvas:S,elements:A,layers:["drill"],realToCanvasMat:t}),I){const Y=s.current.top_silkscreen;Y&&GQt({canvas:Y,elements:A,layers:["top_silkscreen"],realToCanvasMat:t});const J=s.current.bottom_silkscreen;J&&GQt({canvas:J,elements:A,layers:["bottom_silkscreen"],realToCanvasMat:t})}if(g){const Y=s.current.top_fabrication;Y&&fQt({canvas:Y,elements:A,layers:["top_fabrication_note"],realToCanvasMat:t});const J=s.current.bottom_fabrication;J&&fQt({canvas:J,elements:A,layers:["bottom_fabrication_note"],realToCanvasMat:t})}const _=s.current.bottom_notes;_&&yQt({canvas:_,elements:A,layers:["bottom_user_note"],realToCanvasMat:t});const b=s.current.top_notes;if(b&&yQt({canvas:b,elements:A,layers:["top_user_note"],realToCanvasMat:t}),c){const Y=s.current.top_courtyard;Y&&NQt({canvas:Y,elements:A,layers:["top_courtyard"],realToCanvasMat:t});const J=s.current.bottom_courtyard;J&&NQt({canvas:J,elements:A,layers:["bottom_courtyard"],realToCanvasMat:t})}const R=s.current.board;R&&(D7e({canvas:R,elements:A,layers:[],realToCanvasMat:t,drawSoldermask:a}),u7e({canvas:R,elements:A,layers:[],realToCanvasMat:t,drawSoldermask:a}));const F=s.current.edge_cuts;F&&p7e({canvas:F,elements:A,layers:["edge_cuts"],realToCanvasMat:t});const H=[{canvas:Q,layer:"top"},{canvas:h,layer:"bottom"}];for(const{canvas:Y,layer:J}of H)Y&&y7e({canvas:Y,elements:A,layers:[J],realToCanvasMat:t})}B.orderAndFadeLayers()},[e,A,t,r,a,g,c,I]),Z.jsxs("div",{style:{backgroundColor:"black",width:n,height:o,position:"relative"},children:[Z.jsx(_j.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:t,stringifyCoord:(l,B,C)=>`${_j.toMMSI(l,C)}, ${_j.toMMSI(B,C)}`}),t$e.filter(l=>!(!a&&l.includes("soldermask")||!I&&l.includes("silkscreen"))).map(l=>l.replace(/-/g,"")).map((l,B)=>Z.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))]})},i$e=.6,n$e=1;ryA(c6e(),1),ryA(S6e(),1);var Oj=["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 LQt(e,A,t,i={}){const n=i.padding??40,o=i.yFlip??!1;let s;if("center"in e){const c=e.width/2,I=e.height/2;s={minX:e.center.x-c,maxX:e.center.x+c,minY:e.center.y-I,maxY:e.center.y+I}}else s=e;const r=s.maxX-s.minX||1,a=s.maxY-s.minY||1,g=Math.min((A-2*n)/r,(t-2*n)/a);return tn(sn(A/2,t/2),za(g,o?-g:g),sn(-(s.minX+r/2),-(s.minY+a/2)))}function o$e(e){const A=[...e.points||[],...(e.lines||[]).flatMap(t=>t.points),...(e.rects||[]).flatMap(t=>{const i=t.width/2,n=t.height/2;return[{x:t.center.x-i,y:t.center.y-n},{x:t.center.x+i,y:t.center.y-n},{x:t.center.x-i,y:t.center.y+n},{x:t.center.x+i,y:t.center.y+n}]}),...(e.circles||[]).flatMap(t=>[{x:t.center.x-t.radius,y:t.center.y},{x:t.center.x+t.radius,y:t.center.y},{x:t.center.x,y:t.center.y-t.radius},{x:t.center.x,y:t.center.y+t.radius}]),...(e.texts||[]).flatMap(t=>{const i=t.fontSize??12,n=t.text.length*i*i$e,o=i*n$e,s=t.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=t.x+a,I=t.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((t,i)=>({minX:Math.min(t.minX,i.x),maxX:Math.max(t.maxX,i.x),minY:Math.min(t.minY,i.y),maxY:Math.max(t.maxY,i.y)}),{minX:1/0,maxX:-1/0,minY:1/0,maxY:-1/0})}function s$e(e,A,t={}){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(t.transform)s=t.transform;else if(t.viewbox)s=LQt(t.viewbox,n,o,{padding:t.padding,yFlip:t.yFlip});else{const r=o$e(e),a=e.coordinateSystem==="cartesian";s=LQt(r,n,o,{padding:t.padding??40,yFlip:a})}i.clearRect(0,0,n,o),i.save(),e.rects&&e.rects.length>0&&e.rects.forEach(r=>{const a=r.width/2,g=r.height/2,c=Ct(s,{x:r.center.x-a,y:r.center.y-g}),I=Ct(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())}),e.circles&&e.circles.length>0&&e.circles.forEach(r=>{const a=Ct(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())}),e.lines&&e.lines.length>0&&e.lines.forEach((r,a)=>{if(r.points.length===0)return;i.beginPath();const g=Ct(s,r.points[0]);i.moveTo(g.x,g.y);for(let c=1;c<r.points.length;c++){const I=Ct(s,r.points[c]);i.lineTo(I.x,I.y)}if(i.strokeStyle=r.strokeColor||Oj[a%Oj.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()}),e.points&&e.points.length>0&&e.points.forEach((r,a)=>{const g=Ct(s,r);i.beginPath(),i.arc(g.x,g.y,3,0,2*Math.PI),i.fillStyle=r.color||Oj[a%Oj.length],i.fill(),r.label&&!t.disableLabels&&(i.fillStyle=r.color||"black",i.font="12px sans-serif",i.fillText(r.label,g.x+5,g.y-5))}),e.texts&&e.texts.length>0&&e.texts.forEach(r=>{const a=Ct(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 r$e=({children:e,transform:A,debugGraphics:t})=>{const i=AA.useRef(null),[n,{width:o,height:s}]=yT(),r=rl(a=>a.is_showing_autorouting);return AA.useEffect(()=>{r&&i.current&&t&&o&&s&&(i.current.width=o,i.current.height=s,s$e(t,i.current,{transform:A,disableLabels:!0}))},[t,A,o,s,r]),r?Z.jsxs("div",{ref:n,style:{position:"relative",width:"100%",height:"100%"},children:[e,Z.jsx("canvas",{ref:i,style:{position:"absolute",top:0,left:0,opacity:.5,zIndex:100,width:"100%",height:"100%",pointerEvents:"none"}})]}):e},a$e=({children:e,transform:A=ba(),elements:t=[]})=>{const[i,{width:n,height:o}]=yT(),s=AA.useRef(null);return AA.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=t.filter(I=>I.type==="pcb_component"),c=t.filter(I=>I.type==="pcb_manual_edit_conflict_warning");a.strokeStyle=pn.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=Ct(A,Q),E=B*Math.abs(A.a),u=C*Math.abs(A.d),d=.1*Math.abs(A.a),f=E+d*2,m=u+d*2,w=h.x-f/2,D=h.y-m/2;a.beginPath(),a.rect(w,D,f,m),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,H=b+_*2,Y=w+(f-F)/2,J=D+m+5;a.fillStyle="rgba(0, 0, 0, 0.7)",a.beginPath(),a.roundRect(Y,J,F,H,3),a.fill(),a.fillStyle=pn.board.drc_warning,a.textAlign="center",a.textBaseline="middle",a.fillText(S,Y+F/2,J+H/2)})},[t,A,n,o]),Z.jsxs("div",{ref:i,style:{position:"relative",width:"100%",height:"100%"},children:[e,Z.jsx("canvas",{ref:s,style:{position:"absolute",top:0,left:0,pointerEvents:"none",zIndex:xc.warnings}})]})},Wj=(e,A,t)=>t(e,A),UQt=(e,A,t,i,n)=>{const o=n*Math.PI/180,s=Math.cos(o),r=Math.sin(o),a=e-t,g=A-i,c=a*s-g*r,I=a*r+g*s;return{x:c+t,y:I+i}},mT=e=>{if(e.length===0)return null;let A=e[0].x,t=e[0].x,i=e[0].y,n=e[0].y;for(const o of e)A=Wj(A,o.x,Math.min),t=Wj(t,o.x,Math.max),i=Wj(i,o.y,Math.min),n=Wj(n,o.y,Math.max);return{minX:A,maxX:t,minY:i,maxY:n}},g$e=(e,A)=>({minX:Math.min(e.minX,A.minX),maxX:Math.max(e.maxX,A.maxX),minY:Math.min(e.minY,A.minY),maxY:Math.max(e.maxY,A.maxY)}),c$e=(e,A)=>e?g$e(e,A):A,I$e=e=>{switch(e.pcb_drawing_type){case"line":{const A=(e.width??0)/2,t=[{x:e.x1,y:e.y1},{x:e.x2,y:e.y2}],i=mT(t);return i?{minX:i.minX-A,maxX:i.maxX+A,minY:i.minY-A,maxY:i.maxY+A}:null}case"rect":{const A=e.w/2,t=e.h/2,i=[{x:e.x-A,y:e.y-t},{x:e.x+A,y:e.y-t},{x:e.x+A,y:e.y+t},{x:e.x-A,y:e.y+t}],n=e.ccw_rotation??0,o=n===0?i:i.map(s=>UQt(s.x,s.y,e.x,e.y,n));return mT(o)}case"circle":return{minX:e.x-e.r,maxX:e.x+e.r,minY:e.y-e.r,maxY:e.y+e.r};case"oval":return{minX:e.x-e.rX,maxX:e.x+e.rX,minY:e.y-e.rY,maxY:e.y+e.rY};case"pill":{const A=e.w/2,t=e.h/2,i=[{x:e.x-A,y:e.y-t},{x:e.x+A,y:e.y-t},{x:e.x+A,y:e.y+t},{x:e.x-A,y:e.y+t}],n=e.ccw_rotation??0,o=n===0?i:i.map(s=>UQt(s.x,s.y,e.x,e.y,n));return mT(o)}case"polygon":return mT(e.points);case"polygon_with_arcs":{const A=e.brep_shape.outer_ring.vertices.map(t=>({x:t.x,y:t.y}));return mT(A)}case"text":{const A=e.size??0,t=e.text?e.text.length*A*.6:0,i=A;if(t===0&&i===0)return{minX:e.x,maxX:e.x,minY:e.y,maxY:e.y};const n=t/2,o=i/2;return{minX:e.x-n,maxX:e.x+n,minY:e.y-o,maxY:e.y+o}}default:return null}};function l$e(e){const{dimensionStart:A,dimensionEnd:t,screenDimensionStart:i,screenDimensionEnd:n,flipX:o,flipY:s}=e,r=t.x-A.x,a=t.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 m=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&&(m=-m,w=-w),D&&(m+=Math.cos(f*Math.PI/180)*-45,w+=Math.sin(f*Math.PI/180)*-45),S&&(m+=Math.cos(f*Math.PI/180)+-20,w+=Math.sin(f*Math.PI/180)+-10),_&&(m+=Math.cos(f*Math.PI/180)*10,w+=Math.sin(f*Math.PI/180)*10);const b=E+m,R=u+w;return{distance:g,screenDistance:l,x:b,y:R,show:g>.01&&l>30&&h}}function B$e(e){const{dimensionStart:A,dimensionEnd:t,screenDimensionStart:i,screenDimensionEnd:n,flipX:o,flipY:s}=e;return AA.useMemo(()=>l$e({dimensionStart:A,dimensionEnd:t,screenDimensionStart:i,screenDimensionEnd:n,flipX:o,flipY:s}),[A,t,i,n,o,s])}var C$e=(e,A,t)=>{const i=t*Math.PI/180,n=Math.cos(i),o=Math.sin(i),s=e.x-A.x,r=e.y-A.y,a=s*n-r*o,g=s*o+r*n;return{x:a+A.x,y:g+A.y}},HQt=(e,A,t,i)=>{const n={top_left:{x:e.x-A,y:e.y-t},top_center:{x:e.x,y:e.y-t},top_right:{x:e.x+A,y:e.y-t},center_left:{x:e.x-A,y:e.y},center:{x:e.x,y:e.y},center_right:{x:e.x+A,y:e.y},bottom_left:{x:e.x-A,y:e.y+t},bottom_center:{x:e.x,y:e.y+t},bottom_right:{x:e.x+A,y:e.y+t}};return i===0?Object.entries(n).map(([o,s])=>({anchor:o,point:s})):Object.entries(n).map(([o,s])=>({anchor:o,point:C$e(s,e,i)}))},Q$e=e=>{switch(e.pcb_drawing_type){case"rect":{const A=e.ccw_rotation??0;return HQt({x:e.x,y:e.y},e.w/2,e.h/2,A)}case"pill":{const A=e.ccw_rotation??0;return HQt({x:e.x,y:e.y},e.w/2,e.h/2,A)}case"circle":return[{anchor:"circle_center",point:{x:e.x,y:e.y}},{anchor:"circle_right",point:{x:e.x+e.r,y:e.y}},{anchor:"circle_left",point:{x:e.x-e.r,y:e.y}},{anchor:"circle_top",point:{x:e.x,y:e.y-e.r}},{anchor:"circle_bottom",point:{x:e.x,y:e.y+e.r}}];case"oval":return[{anchor:"oval_center",point:{x:e.x,y:e.y}},{anchor:"oval_right",point:{x:e.x+e.rX,y:e.y}},{anchor:"oval_left",point:{x:e.x-e.rX,y:e.y}},{anchor:"oval_top",point:{x:e.x,y:e.y-e.rY}},{anchor:"oval_bottom",point:{x:e.x,y:e.y+e.rY}}];case"line":{const A={x:(e.x1+e.x2)/2,y:(e.y1+e.y2)/2};return[{anchor:"line_start",point:{x:e.x1,y:e.y1}},{anchor:"line_mid",point:A},{anchor:"line_end",point:{x:e.x2,y:e.y2}}]}case"polygon":return e.points.map((A,t)=>({anchor:`polygon_vertex_${t}`,point:A}));case"polygon_with_arcs":return e.brep_shape.outer_ring.vertices.map((A,t)=>({anchor:`polygon_with_arcs_vertex_${t}`,point:{x:A.x,y:A.y}}));default:return[]}},h$e=16,DM=5,YQt=e=>{if(e.pcb_drawing_type==="text")return!0;const A=e._element;if(!A||typeof A!="object")return!1;const t=typeof A.type=="string"?A.type:void 0;return t?!!(t.startsWith("pcb_silkscreen_")||t.startsWith("pcb_note_")||t==="pcb_text"||t.startsWith("pcb_fabrication_note_")&&t!=="pcb_fabrication_note_rect"):!1},E$e=({children:e,transform:A,focusOnHover:t=!1,primitives:i=[]})=>{A||(A=ba());const[n,o]=AA.useState(!1),[s,r]=AA.useState(!1),[a,g]=AA.useState(!1),[c,I]=AA.useState({start:null,end:null}),l=rl(J=>J.is_mouse_over_container),B=AA.useCallback(()=>{a&&(g(!1),window.dispatchEvent(new Event("disarm-dimension-tool")))},[a]),[C,Q]=AA.useState({x:0,y:0}),[h,E]=AA.useState({x:0,y:0}),u=AA.useRef({x:0,y:0}),d=AA.useRef(null),m=d.current?.getBoundingClientRect(),w=AA.useMemo(()=>{const J=new Map;for(const O of i){if(!O._element||YQt(O)||O.pcb_drawing_type==="pill"||O.pcb_drawing_type==="rect"&&O.ccw_rotation&&O.ccw_rotation!==0)continue;const W=I$e(O);if(!W)continue;const z=J.get(O._element);J.set(O._element,c$e(z??void 0,W))}return J},[i]),D=AA.useMemo(()=>{const J=[];for(const O of i){if(!O._element||YQt(O))continue;const W=Q$e(O);if(W.length!==0)for(const z of W)J.push({anchor:z.anchor,point:z.point,element:O._element})}return J},[i]),S=AA.useMemo(()=>{const J=[];w.forEach((O,W)=>{if(!O)return;const z=(O.minX+O.maxX)/2,tA=(O.minY+O.maxY)/2,aA={top_left:{x:O.minX,y:O.minY},top_center:{x:z,y:O.minY},top_right:{x:O.maxX,y:O.minY},center_left:{x:O.minX,y:tA},center:{x:z,y:tA},center_right:{x:O.maxX,y:tA},bottom_left:{x:O.minX,y:O.maxY},bottom_center:{x:z,y:O.maxY},bottom_right:{x:O.maxX,y:O.maxY}};for(const[eA,oA]of Object.entries(aA))J.push({anchor:eA,point:oA,element:W})});for(const O of D)J.push(O);return J.push({anchor:"origin",point:{x:0,y:0},element:null}),J},[w,D]),_=AA.useMemo(()=>S.map((J,O)=>({...J,id:`${O}-${J.anchor}`,screenPoint:Ct(A,J.point)})),[S,A]),b=AA.useCallback(J=>{if(_.length===0)return{point:J,id:null};const O=Ct(A,J);let W=null;for(const z of _){const tA=z.screenPoint.x-O.x,aA=z.screenPoint.y-O.y,eA=Math.hypot(tA,aA);eA>h$e||(!W||eA<W.distance)&&(W={distance:eA,id:z.id,point:z.point})}return W?{point:W.point,id:W.id}:{point:J,id:null}},[_,A]);AA.useEffect(()=>{const J=W=>{const z=W.target;if(z.tagName==="INPUT"||z.tagName==="TEXTAREA"||z.isContentEditable)return;const tA=d.current?.contains(document.activeElement)||document.activeElement===d.current;if(!(!l&&!tA)){if(W.key==="d"){const aA=b({x:u.current.x,y:u.current.y});Q({x:aA.point.x,y:aA.point.y}),E({x:aA.point.x,y:aA.point.y}),I({start:aA.id,end:aA.id}),n?(o(!1),r(!1),I({start:null,end:null})):(o(!0),r(!0)),B()}W.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 R=Ct(A,C),F=Ct(A,h),H={left:Math.min(R.x,F.x),right:Math.max(R.x,F.x),top:Math.min(R.y,F.y),bottom:Math.max(R.y,F.y),flipX:R.x>F.x,flipY:R.y>F.y,width:0,height:0};H.width=H.right-H.left,H.height=H.bottom-H.top;const Y=B$e({dimensionStart:C,dimensionEnd:h,screenDimensionStart:R,screenDimensionEnd:F,flipX:H.flipX,flipY:H.flipY});return Z.jsxs("div",{ref:d,"data-pcb-viewer":!0,tabIndex:0,style:{position:"relative",outline:"none"},onMouseEnter:()=>{t&&d.current&&d.current.focus()},onMouseLeave:()=>{d.current&&d.current.blur()},onClick:()=>{d.current&&d.current.focus()},onMouseMove:J=>{const O=J.currentTarget.getBoundingClientRect(),W=J.clientX-O.left,z=J.clientY-O.top,tA=Ct(Xy(A),{x:W,y:z});if(u.current.x=tA.x,u.current.y=tA.y,s){const aA=b(tA);E({x:aA.point.x,y:aA.point.y}),I(eA=>({...eA,end:aA.id}))}},onMouseDown:J=>{const O=J.currentTarget.getBoundingClientRect(),W=J.clientX-O.left,z=J.clientY-O.top,tA=Ct(Xy(A),{x:W,y:z});if(a&&!n){const aA=b(tA);Q({x:aA.point.x,y:aA.point.y}),E({x:aA.point.x,y:aA.point.y}),I({start:aA.id,end:aA.id}),o(!0),r(!0),B()}else s?(r(!1),I(aA=>({...aA,end:null}))):n&&(o(!1),I({start:null,end:null}))},children:[e,n&&Z.jsxs(Z.Fragment,{children:[Y.show&&Z.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:xc.dimensionOverlay},children:Y.distance.toFixed(2)}),Z.jsx("div",{style:{position:"absolute",left:H.left,width:H.width,textAlign:"center",top:R.y+2,color:"red",mixBlendMode:"difference",pointerEvents:"none",marginTop:H.flipY?0:-20,fontSize:12,fontFamily:"sans-serif",zIndex:xc.dimensionOverlay},children:Math.abs(C.x-h.x).toFixed(2)}),Z.jsx("div",{style:{position:"absolute",left:F.x,height:H.height,display:"flex",flexDirection:"column",justifyContent:"center",top:H.top,color:"red",pointerEvents:"none",mixBlendMode:"difference",fontSize:12,fontFamily:"sans-serif",zIndex:xc.dimensionOverlay},children:Z.jsx("div",{style:{marginLeft:H.flipX?"-100%":4,paddingRight:4},children:Math.abs(C.y-h.y).toFixed(2)})}),Z.jsxs("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none",mixBlendMode:"difference",zIndex:xc.dimensionOverlay},width:m.width,height:m.height,children:[Z.jsx("defs",{children:Z.jsx("marker",{id:"head",orient:"auto",markerWidth:"3",markerHeight:"4",refX:"2",refY:"2",children:Z.jsx("path",{d:"M0,0 V4 L2,2 Z",fill:"red"})})}),Z.jsx("line",{x1:R.x,y1:R.y,x2:F.x,y2:F.y,markerEnd:"url(#head)",strokeWidth:1.5,fill:"none",stroke:"red"}),Z.jsx("line",{x1:R.x,y1:R.y,x2:F.x,y2:R.y,strokeWidth:1.5,fill:"none",strokeDasharray:"2,2",stroke:"red"}),Z.jsx("line",{x1:F.x,y1:R.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,W=DM/2;return Z.jsxs("svg",{width:DM,height:DM,style:{position:"absolute",left:J.screenPoint.x-W,top:J.screenPoint.y-W,pointerEvents:"none",zIndex:xc.dimensionOverlay},children:[Z.jsx("line",{x1:0,y1:0,x2:DM,y2:DM,stroke:O?"#66ccff":"white",strokeWidth:1}),Z.jsx("line",{x1:DM,y1:0,x2:0,y2:DM,stroke:O?"#66ccff":"white",strokeWidth:1})]},J.id)}),Z.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),")",Z.jsx("br",{}),"(",h.x.toFixed(2),",",h.y.toFixed(2),")",Z.jsx("br",{}),"dist:"," ",Math.sqrt((h.x-C.x)**2+(h.y-C.y)**2).toFixed(2)]})]})]})},u$e=(e,A,t=0)=>{const i=e.width/2,n=e.height/2,o=e.center.x-i-t,s=e.center.x+i+t,r=e.center.y-n-t,a=e.center.y+n+t;return A.x>o&&A.x<s&&A.y>r&&A.y<a},d$e=({children:e,disabled:A,transform:t,soup:i,cancelPanDrag:n,onCreateEditEvent:o,onModifyEditEvent:s})=>{t||(t=ba());const r=AA.useRef(null),[a,g]=AA.useState(null),[c,I]=AA.useState(null),l=a!==null;rl(h=>h.in_edit_mode);const B=rl(h=>h.in_move_footprint_mode),C=rl(h=>h.setIsMovingComponent),Q=A||!B;return Z.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=Ct(Xy(t),{x:u,y:d});let m=!1;for(const w of i)if(w.type==="pcb_component"&&u$e(w,f,10/t.a)){n(),g(w.pcb_component_id),m=!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(m||g(null),m)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=Ct(Xy(t),{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:[e,!Q&&i.filter(h=>h.type==="pcb_component").map(h=>{if(!h?.center)return null;const E=Ct(t,h.center);return Z.jsx("div",{style:{position:"absolute",pointerEvents:"none",left:E.x,top:E.y,width:h.width*t.a+20,height:h.height*t.a+20,transform:"translate(-50%, -50%)",background:l&&a===h.pcb_component_id?"rgba(255, 0, 0, 0.2)":""}},h.pcb_component_id)})]})},p$e=({hotkeys:e})=>(AA.useEffect(()=>{const A=t=>{e.forEach(i=>{t.key===i.key&&i.onUse()})};return window.addEventListener("keydown",A),()=>{window.removeEventListener("keydown",A)}},[e]),Z.jsx("div",{className:a1`
5432
+ $1`).replace(/>(\s*)(?=<!--\s*\/)/g,"> ")}}});function lQt(e,A,t){if(!A||!t)return;let i=e.get(A);i||(i=new Set,e.set(A,i)),i.add(t);let n=e.get(t);n||(n=new Set,e.set(t,n)),n.add(A)}function b6e(e,A){if(!A.subcircuit_id&&!A.source_group_id)return[...e];let t=A;if(A.subcircuit_id){const r=new Set([A.subcircuit_id]),a=new Map,g=new Map;for(const I of e)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),t={...A,subcircuit_ids:Array.from(r)}}}const i=new Map;for(const r of e){const a=`${r.type}_id`,g=r[a];typeof g=="string"&&i.set(g,r)}const n=new Map;for(const r of e){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);lQt(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);lQt(n,r,l)}}}}const o=[],s=new Set;for(const r of e){let a=!1;(t.subcircuit_id&&"subcircuit_id"in r&&r.subcircuit_id===t.subcircuit_id||t.subcircuit_ids&&"subcircuit_id"in r&&r.subcircuit_id&&t.subcircuit_ids.includes(r.subcircuit_id)||t.source_group_id&&"source_group_id"in r&&r.source_group_id===t.source_group_id||t.source_group_id&&"member_source_group_ids"in r&&Array.isArray(r.member_source_group_ids)&&r.member_source_group_ids.includes(t.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 e.filter(r=>s.has(r))}var Tj=(e,A={})=>{const t=e;let i=t._internal_store;if(!i){i={counts:{},editCount:0},t._internal_store=i;for(const o of t){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()=>(t.editCount=i.editCount,t);if(s==="editCount")return i.editCount;if(s==="subtree")return a=>Tj(b6e(t,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&&(k0A[g]??Bj).parse(I),t.push(I),i.editCount++,I};if(s==="insertAll")return a=>a.map(g=>n.insert(g));const r=s;return{get:a=>t.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=t.find(B=>B.type===I&&B[c]===a[c]);return l?t.find(B=>B.type===r&&B[`${r}_id`]===l[`${r}_id`]):null},getWhere:a=>{const g=Object.keys(a);return t.find(c=>c.type===r&&g.every(I=>c[I]===a[I]))},list:a=>{const g=a?Object.keys(a):[];return t.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&&(k0A[r]??Bj).parse(c),t.push(c),i.editCount++,c},delete:a=>{const g=t.find(c=>c[`${r}_id`]===a);g&&(t.splice(t.indexOf(g),1),i.editCount++)},update:(a,g)=>{const c=t.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 t.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=t.find(B=>B.type==="source_component"&&B.name===g);if(!I)return null;const l=t.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 t.find(B=>B.type==="pcb_port"&&B.source_port_id===l.source_port_id);if(r==="schematic_port")return t.find(B=>B.type==="schematic_port"&&B.source_port_id===l.source_port_id)}}}}});return n};Tj.unparsed=Tj;var Xb=Tj;function lyA(e){const A=e.type;return`${A}:${e[`${A}_id`]}`}var BQt=(e,A={})=>{let t=e._internal_store_indexed;if(!t){t={counts:{},editCount:0,indexes:{}};for(const s of e){const r=s.type,a=s[`${r}_id`];if(!a)continue;const g=Number.parseInt(a.split("_").pop()||"");Number.isNaN(g)||(t.counts[r]=Math.max(t.counts[r]??0,g))}const n=A.indexConfig||{},o=t.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 e){if(n.byId){const r=lyA(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)}}}}e._internal_store_indexed=t}return new Proxy({},{get:(n,o)=>{if(o==="toArray")return()=>(e.editCount=t.editCount,e);if(o==="editCount")return t.editCount;const s=o;return{get:r=>{const a=A.indexConfig||{};return a.byId&&t.indexes.byId?t.indexes.byId.get(`${s}:${r}`)||null:a.byType&&t.indexes.byType?(t.indexes.byType.get(s)||[]).find(c=>c[`${s}_id`]===r)||null:e.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&&t.indexes.byRelation){const B=t.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&&t.indexes.byId?t.indexes.byId.get(`${s}:${h}`)||null:a.byType&&t.indexes.byType?(t.indexes.byType.get(s)||[]).find(u=>u[`${s}_id`]===h)||null:e.find(E=>E.type===s&&E[`${s}_id`]===h)||null}}const l=e.find(B=>B.type===I&&B[c]===r[c]);return l&&e.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&&t.indexes.byCustomField){const c=g[0],I=t.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&&t.indexes.bySubcircuit){const c=r.subcircuit_id;return(t.indexes.bySubcircuit.get(c)||[]).find(l=>l.type===s&&g.every(B=>l[B]===r[B]))||null}return a.byType&&t.indexes.byType?(t.indexes.byType.get(s)||[]).find(I=>g.every(l=>I[l]===r[l]))||null:e.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&&t.indexes.byType)return t.indexes.byType.get(s)||[];if(g.length===1&&g[0]==="subcircuit_id"&&a.bySubcircuit&&t.indexes.bySubcircuit){const I=r.subcircuit_id;return(t.indexes.bySubcircuit.get(I)||[]).filter(B=>B.type===s)}let c;return a.byType&&t.indexes.byType?c=t.indexes.byType.get(s)||[]:c=e.filter(I=>I.type===s),g.length>0?c.filter(I=>g.every(l=>I[l]===r[l])):c},insert:r=>{t.counts[s]??=-1,t.counts[s]++;const a=t.counts[s],g={type:s,[`${s}_id`]:`${s}_${a}`,...r};A.validateInserts&&(k0A[s]??Bj).parse(g),e.push(g),t.editCount++;const c=A.indexConfig||{};if(c.byId&&t.indexes.byId){const I=lyA(g);t.indexes.byId.set(I,g)}if(c.byType&&t.indexes.byType){const I=t.indexes.byType.get(s)||[];I.push(g),t.indexes.byType.set(s,I)}if(c.byRelation&&t.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=t.indexes.byRelation.get(l)||new Map,Q=C.get(B)||[];Q.push(g),C.set(B,Q),t.indexes.byRelation.set(l,C)}}if(c.bySubcircuit&&t.indexes.bySubcircuit&&"subcircuit_id"in g){const I=g.subcircuit_id;if(I&&typeof I=="string"){const l=t.indexes.bySubcircuit.get(I)||[];l.push(g),t.indexes.bySubcircuit.set(I,l)}}if(c.byCustomField&&t.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=t.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&&t.indexes.byId?g=t.indexes.byId.get(`${s}:${r}`):a.byType&&t.indexes.byType?g=(t.indexes.byType.get(s)||[]).find(l=>l[`${s}_id`]===r):g=e.find(I=>I[`${s}_id`]===r),!g)return;const c=e.indexOf(g);if(c>=0&&(e.splice(c,1),t.editCount++),a.byId&&t.indexes.byId){const I=lyA(g);t.indexes.byId.delete(I)}if(a.byType&&t.indexes.byType){const l=(t.indexes.byType.get(s)||[]).filter(B=>B[`${s}_id`]!==r);t.indexes.byType.set(s,l)}if(a.byRelation&&t.indexes.byRelation)for(const[I,l]of t.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&&t.indexes.bySubcircuit&&"subcircuit_id"in g){const I=g.subcircuit_id;if(I){const B=(t.indexes.bySubcircuit.get(I)||[]).filter(C=>C!==g);B.length===0?t.indexes.bySubcircuit.delete(I):t.indexes.bySubcircuit.set(I,B)}}if(a.byCustomField&&t.indexes.byCustomField)for(const I of t.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&&t.indexes.byId?c=t.indexes.byId.get(`${s}:${r}`):g.byType&&t.indexes.byType?c=(t.indexes.byType.get(s)||[]).find(l=>l[`${s}_id`]===r):c=e.find(I=>I.type===s&&I[`${s}_id`]===r),!c)return null;if(g.byRelation&&t.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=t.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&&t.indexes.bySubcircuit&&"subcircuit_id"in c&&"subcircuit_id"in a){const I=c.subcircuit_id,l=a.subcircuit_id;if(I!==l){const C=(t.indexes.bySubcircuit.get(I)||[]).filter(Q=>Q!==c);C.length===0?t.indexes.bySubcircuit.delete(I):t.indexes.bySubcircuit.set(I,C)}}if(g.byCustomField&&t.indexes.byCustomField){for(const I of g.byCustomField)if(I in c&&I in a&&c[I]!==a[I]){const l=t.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),t.editCount++,g.byRelation&&t.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=t.indexes.byRelation.get(l)||new Map,Q=C.get(B)||[];Q.includes(c)||(Q.push(c),C.set(B,Q),t.indexes.byRelation.set(l,C))}}if(g.bySubcircuit&&t.indexes.bySubcircuit&&"subcircuit_id"in c&&"subcircuit_id"in a){const I=c.subcircuit_id;if(I&&typeof I=="string"){const l=t.indexes.bySubcircuit.get(I)||[];l.includes(c)||(l.push(c),t.indexes.bySubcircuit.set(I,l))}}if(g.byCustomField&&t.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=t.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 e.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=e.find(l=>l.type==="source_component"&&l.name===a);if(!c)return null;const I=e.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 e.find(l=>l.type==="pcb_port"&&l.source_port_id===I.source_port_id)||null;if(s==="schematic_port")return e.find(l=>l.type==="schematic_port"&&l.source_port_id===I.source_port_id)||null}return null}}}})};BQt.unparsed=BQt;var x6e=e=>{const A=e.type;return e[`${A}_id`]},CQt=(e,A)=>({minX:Math.min(e.minX,A.minX),minY:Math.min(e.minY,A.minY),maxX:Math.max(e.maxX,A.maxX),maxY:Math.max(e.maxY,A.maxY)}),Pj=(e,A,t)=>{const i=t/2;return{minX:e-i,minY:A-i,maxX:e+i,maxY:A+i}},_6e=(e,A,t,i,n)=>{const o=t/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:e+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))}},ByA=e=>{let A=Number.POSITIVE_INFINITY,t=Number.POSITIVE_INFINITY,i=Number.NEGATIVE_INFINITY,n=Number.NEGATIVE_INFINITY;for(const o of e){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),t=Math.min(t,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=Pj(o.x,o.y,o.hole_diameter);A=Math.min(A,c.minX),t=Math.min(t,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=Pj(o.x,o.y,o.outer_diameter):"hole_diameter"in o&&typeof o.hole_diameter=="number"&&(c=Pj(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=_6e(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?CQt(c,I):I}if("hole_diameter"in o&&typeof o.hole_diameter=="number"){const I=Pj(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?CQt(c,I):I}if(c){A=Math.min(A,c.minX),t=Math.min(t,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),t=Math.min(t,r),i=Math.max(i,s),n=Math.max(n,r),a!==void 0&&g!==void 0&&(A=Math.min(A,s-a/2),t=Math.min(t,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),t=Math.min(t,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),t=Math.min(t,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),t=Math.min(t,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),t=Math.min(t,c.y),i=Math.max(i,c.x),n=Math.max(n,c.y)}return{minX:A,minY:t,maxX:i,maxY:n}};function k6e(e){let A=0;if(e.length==0)return A;for(var t=0;t<e.length;t++){var i=e.charCodeAt(t);A=(A<<5)-A+i,A=A&A}return Math.abs(A)}var QQt=[["#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"]],v6e=e=>{let{x:A,y:t,width:i,height:n}={...e,...e.size,...e.center,...e.position};if(e.x1!==void 0&&e.x2!==void 0&&e.y1!==void 0&&e.y2!==void 0&&(A=(e.x1+e.x2)/2,t=(e.y1+e.y2)/2,i=Math.abs(e.x1-e.x2),n=Math.abs(e.y1-e.y2)),e.points&&Array.isArray(e.points)&&e.points.length>0){const r=e.points.map(B=>B.x),a=e.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,t=(I+l)/2,i=c-g,n=l-I}const o=e.text||e.name||e.source?.text||e.source?.name||"?",s=e;return A===void 0||t===void 0?null:(i===void 0&&"outer_diameter"in e&&(i=e.outer_diameter,n=e.outer_diameter),(i===void 0||n===void 0)&&(i=.1,n=.1),{x:A,y:t,width:i,height:n,title:o,content:s,bg_color:QQt[k6e(e.type||o)%QQt.length]?.[4]??"#f00"})},F6e=e=>!!e,M6e=e=>{const A=e.filter(g=>g.type.startsWith("pcb_")||g.type.startsWith("schematic_")).concat(e.filter(g=>g.type==="pcb_trace"||g.type==="schematic_trace").flatMap(g=>g.route)).map(g=>v6e(g)).filter(F6e);if(A.length===0)return{center:{x:0,y:0},width:0,height:0};let t=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))t=Math.min(t,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-t,r=o-n;return{center:{x:t+s/2,y:n+r/2},width:s,height:r}},Id={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"},mM=(e,A)=>{if(typeof window>"u")return A;try{const t=localStorage.getItem(e);return t!==null?JSON.parse(t):A}catch{return A}},wM=(e,A)=>{if(!(typeof window>"u"))try{localStorage.setItem(e,JSON.stringify(A))}catch{}},G6e=(e,A)=>{if(typeof window>"u")return A;try{const t=localStorage.getItem(e);return t!==null?JSON.parse(t):A}catch{return A}},R6e=(e,A)=>{if(!(typeof window>"u"))try{localStorage.setItem(e,JSON.stringify(A))}catch{}},N6e="named_only",L6e=(e={},A=!1)=>TBt(t=>({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:mM(Id.IS_SHOWING_COPPER_POURS,!0),is_showing_courtyards:mM(Id.IS_SHOWING_COURTYARDS,!0),is_showing_pcb_groups:A?!1:mM(Id.IS_SHOWING_PCB_GROUPS,!0),is_showing_group_anchor_offsets:mM(Id.IS_SHOWING_GROUP_ANCHOR_OFFSETS,!1),is_showing_solder_mask:mM(Id.IS_SHOWING_SOLDER_MASK,!1),is_showing_silkscreen:mM(Id.IS_SHOWING_SILKSCREEN,!0),is_showing_fabrication_notes:mM(Id.IS_SHOWING_FABRICATION_NOTES,!1),pcb_group_view_mode:A?"all":G6e(Id.PCB_GROUP_VIEW_MODE,N6e),hovered_error_id:null,...e,selectLayer:i=>t({selected_layer:i}),setEditMode:i=>t({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=>t({is_showing_rats_nest:i}),setIsMovingComponent:i=>t({is_moving_component:i}),setIsDrawingTrace:i=>t({is_drawing_trace:i}),setIsMouseOverContainer:i=>t({is_mouse_over_container:i}),setIsShowingMultipleTracesLength:i=>t({is_showing_multiple_traces_length:i}),setIsShowingAutorouting:i=>t({is_showing_autorouting:i}),setIsShowingDrcErrors:i=>t({is_showing_drc_errors:i}),setIsShowingCopperPours:i=>{wM(Id.IS_SHOWING_COPPER_POURS,i),t({is_showing_copper_pours:i})},setIsShowingCourtyards:i=>{wM(Id.IS_SHOWING_COURTYARDS,i),t({is_showing_courtyards:i})},setIsShowingPcbGroups:i=>{A||(wM(Id.IS_SHOWING_PCB_GROUPS,i),t({is_showing_pcb_groups:i}))},setIsShowingGroupAnchorOffsets:i=>{wM(Id.IS_SHOWING_GROUP_ANCHOR_OFFSETS,i),t({is_showing_group_anchor_offsets:i})},setIsShowingSolderMask:i=>{wM(Id.IS_SHOWING_SOLDER_MASK,i),t({is_showing_solder_mask:i})},setIsShowingSilkscreen:i=>{wM(Id.IS_SHOWING_SILKSCREEN,i),t({is_showing_silkscreen:i})},setIsShowingFabricationNotes:i=>{wM(Id.IS_SHOWING_FABRICATION_NOTES,i),t({is_showing_fabrication_notes:i})},setPcbGroupViewMode:i=>{A||(R6e(Id.PCB_GROUP_VIEW_MODE,i),t({pcb_group_view_mode:i}))},setHoveredErrorId:i=>t({hovered_error_id:i})})),rl=e=>{const A=AA.useContext(hQt);return XBt(A,e)},hQt=AA.createContext(null),U6e=({children:e,initialState:A,disablePcbGroups:t})=>{const i=AA.useMemo(()=>L6e(A,t),[t]);return Z.jsx(hQt.Provider,{value:i,children:e})},H6e=()=>{const e=rl(t=>t.pcb_viewer_id),A=(t,i)=>ec(t,{containerId:e,...i});return A.error=(t,i)=>ec.error(t,{containerId:e,...i}),A.promise=ec.promise,A},Y6e=()=>{AA.useEffect(()=>{Mje()},[]);const e=rl(A=>A.pcb_viewer_id);return Z.jsx(Fje,{position:"top-center",containerId:e})};function J6e(){var e=AA.useRef(!1),A=AA.useCallback(function(){return e.current},[]);return AA.useEffect(function(){return e.current=!0,function(){e.current=!1}},[]),A}var T6e=function(e){e===void 0&&(e={});var A=AA.useState(e),t=A[0],i=A[1],n=AA.useCallback(function(o){i(function(s){return Object.assign({},s,o instanceof Function?o(s):o)})},[]);return[t,n]},P6e=T6e,K6e=function(){},EQt=typeof window<"u",q6e=ryA(g6e()),O6e=function(){var e=J6e(),A=P6e({value:void 0,error:void 0,noUserInteraction:!0}),t=A[0],i=A[1],n=AA.useCallback(function(o){if(e()){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,q6e.default)(r),i({value:r,error:void 0,noUserInteraction:s})}catch(g){i({value:r,error:g,noUserInteraction:s})}}},[]);return[t,n]},W6e=O6e,Z6e=EQt?AA.useLayoutEffect:AA.useEffect,V6e=Z6e,uQt={x:0,y:0,width:0,height:0,top:0,left:0,bottom:0,right:0};function j6e(){var e=AA.useState(null),A=e[0],t=e[1],i=AA.useState(uQt),n=i[0],o=i[1],s=AA.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 V6e(function(){if(A)return s.observe(A),function(){s.disconnect()}},[A]),[t,n]}var yT=EQt&&typeof window.ResizeObserver<"u"?j6e:function(){return[K6e,uQt]},dQt=({initialTransform:e,initialTouch1:A,initialTouch2:t,finalTouch1:i,finalTouch2:n})=>{if(!i||!n)return e;const o={x:(A.x+t.x)/2,y:(A.y+t.y)/2},s={x:(i.x+n.x)/2,y:(i.y+n.y)/2},r=Math.hypot(t.x-A.x,t.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 tn(sn(c,I),sn(o.x,o.y),za(g,g),sn(-o.x,-o.y),e)},z6e=(e={})=>{const A=AA.useRef(null),[t,i]=AA.useState(0),n=e.canvasElm??A.current,[o,s]=AA.useState(e.initialTransform??ba()),[r,a]=AA.useState(0),[g,c]=AA.useReducer(d=>d+1,0),I=AA.useCallback(d=>{e.onSetTransform&&e.onSetTransform(d),e.transform||s(d)},[e.onSetTransform,s]),l=AA.useCallback(d=>{I(d),c()},[I]),B=e.transform??o,C=AA.useCallback(()=>{i(Date.now())},[]),Q=AA.useRef("none"),h=AA.useRef(null),E=AA.useRef(null);AA.useEffect(()=>{const d=e.canvasElm??A.current;if(d&&!n){a(r+1);return}if(!d){const W=setTimeout(()=>{a(r+1)},100);return()=>clearTimeout(W)}let f=e.transform??o,m={x:0,y:0},w={x:0,y:0},D=!1;const S=W=>({x:W.pageX-d.getBoundingClientRect().left-window.scrollX,y:W.pageY-d.getBoundingClientRect().top-window.scrollY});function _(W){e.enabled!==!1&&(e.shouldDrag&&!e.shouldDrag(W)||(m=S(W),!(Date.now()-t<100)&&(D=!0,W.preventDefault())))}function b(W){if(!D||e.enabled===!1||e.shouldDrag&&!e.shouldDrag(W))return;w=S(W);const z=tn(sn(w.x-m.x,w.y-m.y),f);I(z),f=z,D=!1}function R(W){if(S(W),!D||e.enabled===!1||e.shouldDrag&&!e.shouldDrag(W))return;w=S(W);const z=tn(sn(w.x-m.x,w.y-m.y),f);I(z)}function F(W){if(e.enabled===!1||e.shouldDrag&&!e.shouldDrag(W))return;const z=S(W),tA=tn(sn(z.x,z.y),za(1-W.deltaY/1e3,1-W.deltaY/1e3),sn(-z.x,-z.y),f);I(tA),f=tA,W.preventDefault()}function H(W){if(!D||e.shouldDrag&&!e.shouldDrag(W))return;if(d){const tA=d.getBoundingClientRect();if(W.clientX>=tA.left+10&&W.clientX<=tA.right-10&&W.clientY>=tA.top+10&&W.clientY<=tA.bottom-10)return}D=!1,w=S(W);const z=tn(sn(w.x-m.x,w.y-m.y),f);I(z),f=z}function Y(W){if(W.preventDefault(),e.enabled!==!1){if(W.touches.length===1){Q.current="drag";const z=W.touches[0];h.current={initialTransform:f,initialTouch:{x:z.clientX,y:z.clientY}}}else if(W.touches.length===2){Q.current="pinch";const z=W.touches[0],tA=W.touches[1];E.current={initialTransform:f,initialTouch1:{x:z.clientX,y:z.clientY},initialTouch2:{x:tA.clientX,y:tA.clientY},finalTouch1:null,finalTouch2:null}}}}function J(W){if(W.preventDefault(),e.enabled!==!1){if(Q.current==="drag"&&W.touches.length===1&&h.current){const z=W.touches[0],tA={x:z.clientX,y:z.clientY},aA=tA.x-h.current.initialTouch.x,eA=tA.y-h.current.initialTouch.y,oA=tn(sn(aA,eA),h.current.initialTransform);I(oA)}else if(Q.current==="pinch"&&W.touches.length===2&&E.current){const z=W.touches[0],tA=W.touches[1];E.current.finalTouch1={x:z.clientX,y:z.clientY},E.current.finalTouch2={x:tA.clientX,y:tA.clientY};const aA=dQt(E.current);I(aA)}}}function O(W){W.preventDefault();const z=W.changedTouches[0];if(Q.current==="drag"&&h.current&&z){const tA={x:z.clientX,y:z.clientY},aA=tA.x-h.current.initialTouch.x,eA=tA.y-h.current.initialTouch.y,oA=tn(sn(aA,eA),h.current.initialTransform);I(oA),f=oA}else if(Q.current==="pinch"&&E.current){const tA=dQt(E.current);I(tA),f=tA}Q.current="none",h.current=null,E.current=null}return d.addEventListener("mousedown",_),d.addEventListener("mouseup",b),window.addEventListener("mousemove",R),d.addEventListener("mouseout",H),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",R),d.removeEventListener("mouseout",H),d.removeEventListener("wheel",F),d.removeEventListener("touchstart",Y),d.removeEventListener("touchmove",J),d.removeEventListener("touchend",O),d.removeEventListener("touchcancel",O)}},[n,r,g,t,e.enabled,e.shouldDrag]);const u=AA.useCallback(d=>Ct(B,d),[B]);return{ref:A,transform:B,applyTransformToPoint:u,setTransform:l,cancelDrag:C}},X6e=z6e;function $6e(e){const A=new Map;let t=0;function i(n){for(const[,s]of A)if(s.has(n))return s;const o=new Set;return A.set(`connectivity_net${t++}`,o),o}for(const n of e){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 A7e=class{netMap;idToNetMap;constructor(e){this.netMap=e,this.idToNetMap={};for(const[A,t]of Object.entries(e))for(const i of t)this.idToNetMap[i]=A}addConnections(e){for(const A of e){const t=new Set;for(const n of A){const o=this.idToNetMap[n];o&&t.add(o)}let i;if(t.size===0)i=`connectivity_net${Object.keys(this.netMap).length}`,this.netMap[i]=[];else if(t.size===1)i=t.values().next().value??`connectivity_net${Object.keys(this.netMap).length}`;else{i=t.values().next().value??`connectivity_net${Object.keys(this.netMap).length}`;for(const n of t)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(e){return this.netMap[e]||[]}getNetConnectedToId(e){return this.idToNetMap[e]}areIdsConnected(e,A){if(e===A)return!0;const t=this.getNetConnectedToId(e);if(!t)return!1;const i=this.getNetConnectedToId(A);return i?t===i||i===e||i===e:!1}areAllIdsConnected(e){const A=this.getNetConnectedToId(e[0]);for(const t of e){const i=this.getNetConnectedToId(t);if(i===void 0||i!==A)return!1}return!0}},pQt=e=>{const A=[];for(const i of e)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 t=$6e(A);return new A7e(t)};function t7e({primitivesWithoutInteractionMetadata:e,drawingObjectIdsWithMouseOver:A,primitiveIdsInMousedOverNet:t}){const i=[];for(const n of e){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&&t.includes(n._element.pcb_trace_id)||"pcb_port_id"in n._element&&t.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 e7e(e,A){if(e.length<2)throw new Error("Stroke must have at least two points");const t=e.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(t[0],t[1]),a=t[0].trace_width??A;s(t[0],r,1,a),s(t[0],r,-1,a);for(let I=1;I<t.length-1;I++){const l=t[I-1],B=t[I],C=t[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(t[t.length-2],t[t.length-1]),c=t[t.length-1].trace_width??A;return s(t[t.length-1],g,1,c),s(t[t.length-1],g,-1,c),[...i,...n]}var i7e=(e,A)=>{const{x:t,y:i,width:n,height:o,layer:s,rect_border_radius:r}=e,a=e.corner_radius??r??0,g=[{_pcb_drawing_object_id:wm("rect"),pcb_drawing_type:"rect",x:t,y:i,w:n,h:o,layer:s||"top",_element:e,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,roundness:a,...e.shape==="rotated_rect"&&e.ccw_rotation!==void 0?{ccw_rotation:e.ccw_rotation}:{}}];if(e.is_covered_with_solder_mask){const c=s==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",l={...{_pcb_drawing_object_id:wm("rect"),pcb_drawing_type:"rect",x:t,y:i,w:n,h:o,layer:c,_element:e,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,roundness:a,...e.shape==="rotated_rect"&&e.ccw_rotation!==void 0?{ccw_rotation:e.ccw_rotation}:{}},..."solder_mask_color"in e&&e.solder_mask_color?{color:e.solder_mask_color}:{}};g.push(l)}return g},n7e=(e,A)=>{const{x:t,y:i,radius:n,layer:o}=e,s=[{_pcb_drawing_object_id:wm("circle"),pcb_drawing_type:"circle",x:t,y:i,r:n,layer:o||"top",_element:e,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port}];if(e.is_covered_with_solder_mask){const r=o==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",a={_pcb_drawing_object_id:wm("circle"),pcb_drawing_type:"circle",x:t,y:i,r:n,layer:r,_element:e,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,..."solder_mask_color"in e&&e.solder_mask_color?{color:e.solder_mask_color}:{}};s.push(a)}return s},o7e=(e,A)=>{const{layer:t,points:i}=e,n=[{_pcb_drawing_object_id:wm("polygon"),pcb_drawing_type:"polygon",points:CyA(i),layer:t||"top",_element:e,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port}];if(e.is_covered_with_solder_mask){const o=t==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",s={_pcb_drawing_object_id:wm("polygon"),pcb_drawing_type:"polygon",points:CyA(i),layer:o,_element:e,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,..."solder_mask_color"in e&&e.solder_mask_color?{color:e.solder_mask_color}:{}};n.push(s)}return n},s7e=(e,A)=>{const{x:t,y:i,width:n,height:o,layer:s}=e,r=[{_pcb_drawing_object_id:wm("pill"),pcb_drawing_type:"pill",x:t,y:i,w:n,h:o,layer:s||"top",_element:e,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port}];if(e.is_covered_with_solder_mask){const a=s==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",g={_pcb_drawing_object_id:wm("pill"),pcb_drawing_type:"pill",x:t,y:i,w:n,h:o,layer:a,_element:e,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,..."solder_mask_color"in e&&e.solder_mask_color?{color:e.solder_mask_color}:{}};r.push(g)}return r},r7e=(e,A)=>{const{x:t,y:i,width:n,height:o,layer:s,ccw_rotation:r}=e,a=[{_pcb_drawing_object_id:wm("pill"),pcb_drawing_type:"pill",x:t,y:i,w:n,h:o,layer:s||"top",_element:e,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,ccw_rotation:r}];if(e.is_covered_with_solder_mask){const g=s==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",c={_pcb_drawing_object_id:wm("pill"),pcb_drawing_type:"pill",x:t,y:i,w:n,h:o,layer:g,_element:e,_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 e&&e.solder_mask_color?{color:e.solder_mask_color}:{}};a.push(c)}return a},a7e=(e,A)=>{const{_parent_pcb_component:t,_parent_source_component:i}=A,n=e,o=typeof n.font_size=="string"?Ee.parse(n.font_size):n.font_size??.2;let s;return n.knockout_padding&&(s={left:typeof n.knockout_padding.left=="string"?Ee.parse(n.knockout_padding.left):n.knockout_padding.left,top:typeof n.knockout_padding.top=="string"?Ee.parse(n.knockout_padding.top):n.knockout_padding.top,bottom:typeof n.knockout_padding.bottom=="string"?Ee.parse(n.knockout_padding.bottom):n.knockout_padding.bottom,right:typeof n.knockout_padding.right=="string"?Ee.parse(n.knockout_padding.right):n.knockout_padding.right}),[{_pcb_drawing_object_id:wm("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:e,_parent_pcb_component:t,_parent_source_component:i}]},HI=0,wm=e=>`${e}_${HI++}`,CyA=e=>(e??[]).map(A=>({x:Ee.parse(A.x),y:Ee.parse(A.y)})),g7e=(e,A)=>{const t="pcb_component_id"in e?A.find(s=>s.type==="pcb_component"&&s.pcb_component_id===e.pcb_component_id):void 0,i=t&&"source_component_id"in t?A.find(s=>s.type==="source_component"&&s.source_component_id===t.source_component_id):void 0,n="source_port_id"in e?e.source_port_id:"pcb_port_id"in e?Xb(A).pcb_port.get(e.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(e.type){case"pcb_smtpad":{const s={_parent_pcb_component:t,_parent_source_component:i,_source_port:o};return e.shape==="rect"||e.shape==="rotated_rect"?i7e(e,s):e.shape==="circle"?n7e(e,s):e.shape==="polygon"?o7e(e,s):e.shape==="pill"?s7e(e,s):e.shape==="rotated_pill"?r7e(e,s):[]}case"pcb_trace":{const s=[];if(e.route_thickness_mode==="interpolated"){const g=e.route.map(l=>({x:l.x,y:l.y,trace_width:l.route_type==="wire"?l.width:.5})),c=e7e(g,.5),I=e.route[0].layer;return s.push({_pcb_drawing_object_id:`polygon_${HI++}`,_element:e,pcb_drawing_type:"polygon",points:c,layer:I}),e.route.forEach(l=>{l.route_type==="via"&&s.push({_pcb_drawing_object_id:`circle_${HI++}`,_element:e,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 e.route)g.route_type==="wire"&&(r!==null&&a!==null&&s.push({_pcb_drawing_object_id:`line_${HI++}`,_element:e,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}=e,c=e.from_layer,I=e.to_layer,l=e.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_${HI++}`,pcb_drawing_type:"circle",x:s,y:r,r:a/2,layer:Q,_element:e,_parent_pcb_component:t,_parent_source_component:i});return C.push({_pcb_drawing_object_id:`circle_${HI++}`,pcb_drawing_type:"circle",x:s,y:r,r:g/2,layer:"drill",_element:e}),C}case"pcb_plated_hole":if(e.shape==="circle"){const{x:s,y:r,hole_diameter:a,outer_diameter:g}=e;return[{_pcb_drawing_object_id:`circle_${HI++}`,pcb_drawing_type:"circle",x:s,y:r,r:g/2,layer:"top",_element:e,_parent_pcb_component:t,_parent_source_component:i,_source_port:o},{_pcb_drawing_object_id:`circle_${HI++}`,pcb_drawing_type:"circle",x:s,y:r,r:a/2,layer:"drill",_element:e}]}else if(e.shape==="oval"){const{x:s,y:r,outer_height:a,outer_width:g,hole_height:c,hole_width:I}=e;return[{_pcb_drawing_object_id:`oval_${HI++}`,pcb_drawing_type:"oval",x:s,y:r,rX:g/2,rY:a/2,layer:"top",_element:e,_parent_pcb_component:t,_parent_source_component:i,_source_port:o},{_pcb_drawing_object_id:`oval_${HI++}`,_element:e,pcb_drawing_type:"oval",x:s,y:r,rX:I/2,rY:c/2,layer:"drill"}]}else if(e.shape==="pill"){const{x:s,y:r,outer_height:a,outer_width:g,hole_height:c,hole_width:I}=e;return[{_pcb_drawing_object_id:`pill_${HI++}`,pcb_drawing_type:"pill",x:s,y:r,w:g,h:a,layer:"top",_element:e,_parent_pcb_component:t,_parent_source_component:i,_source_port:o,ccw_rotation:e.ccw_rotation},{_pcb_drawing_object_id:`pill_${HI++}`,_element:e,pcb_drawing_type:"pill",x:s,y:r,w:I,h:c,layer:"drill",ccw_rotation:e.ccw_rotation}]}else if(e.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}=e,C=Ee.parse(l??0),Q=Ee.parse(B??0);return[{_pcb_drawing_object_id:`rect_${HI++}`,pcb_drawing_type:"rect",x:s,y:r,w:g,h:c,layer:"top",_element:e,_parent_pcb_component:t,_parent_source_component:i,_source_port:o,roundness:I},{_pcb_drawing_object_id:`rect_${HI++}`,pcb_drawing_type:"rect",x:s,y:r,w:g,h:c,layer:"bottom",_element:e,_parent_pcb_component:t,_parent_source_component:i,_source_port:o,roundness:I,is_hoverable:!1},{_pcb_drawing_object_id:`circle_${HI++}`,_element:e,pcb_drawing_type:"circle",x:s+C,y:r+Q,r:a/2,layer:"drill",is_hoverable:!1}]}else if(e.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}=e;return[{_pcb_drawing_object_id:`rect_${HI++}`,pcb_drawing_type:"rect",x:s,y:r,w:c,h:I,layer:"top",_element:e,_parent_pcb_component:t,_parent_source_component:i,_source_port:o,roundness:l},{_pcb_drawing_object_id:`rect_${HI++}`,pcb_drawing_type:"rect",x:s,y:r,w:c,h:I,layer:"bottom",_element:e,_parent_pcb_component:t,_parent_source_component:i,_source_port:o,roundness:l,is_hoverable:!1},{_pcb_drawing_object_id:`pill_${HI++}`,_element:e,pcb_drawing_type:"pill",x:s,y:r,w:a,h:g,layer:"drill",is_hoverable:!1}]}else if(e.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}=e;return[{_pcb_drawing_object_id:`rect_${HI++}`,pcb_drawing_type:"rect",x:s,y:r,w:I,h:l,layer:"top",_element:e,_parent_pcb_component:t,_parent_source_component:i,_source_port:o,ccw_rotation:B,roundness:C},{_pcb_drawing_object_id:`rect_${HI++}`,pcb_drawing_type:"rect",x:s,y:r,w:I,h:l,layer:"bottom",_element:e,_parent_pcb_component:t,_parent_source_component:i,_source_port:o,ccw_rotation:B,roundness:C,is_hoverable:!1},{_pcb_drawing_object_id:`pill_${HI++}`,_element:e,pcb_drawing_type:"pill",x:s,y:r,w:a,h:g,layer:"drill",ccw_rotation:c,is_hoverable:!1}]}else if(e.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}=e,h=Ee.parse(C??0),E=Ee.parse(Q??0),u=a,d=[];if(u&&Array.isArray(u)){const w=CyA(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_${HI++}`,pcb_drawing_type:"polygon",points:w,layer:D,_element:e,_parent_pcb_component:t,_parent_source_component:i,_source_port:o})}const f={x:s+h,y:r+E},m=[];return g==="circle"?m.push({_pcb_drawing_object_id:`circle_${HI++}`,pcb_drawing_type:"circle",x:f.x,y:f.y,r:(c??0)/2,layer:"drill",_element:e,_parent_pcb_component:t,_parent_source_component:i}):g==="oval"?m.push({_pcb_drawing_object_id:`oval_${HI++}`,pcb_drawing_type:"oval",x:f.x,y:f.y,rX:(I??0)/2,rY:(l??0)/2,layer:"drill",_element:e,_parent_pcb_component:t,_parent_source_component:i}):(g==="pill"||g==="rotated_pill")&&m.push({_pcb_drawing_object_id:`pill_${HI++}`,pcb_drawing_type:"pill",x:f.x,y:f.y,w:I??0,h:l??0,layer:"drill",_element:e,_parent_pcb_component:t,_parent_source_component:i,ccw_rotation:e.ccw_rotation}),[...d,...m]}else return[];case"pcb_copper_text":return a7e(e,{_parent_pcb_component:t,_parent_source_component:i})}return[]},pn={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)"}},Lf=(e,A=1)=>{if(Math.abs(e.a)!==Math.abs(e.d))throw new Error("Cannot scale non-uniformly");return A*Math.abs(e.a)},xc={elementOverlay:40,dimensionOverlay:40,editTraceHintOverlay:40,errorOverlay:40,pcbGroupOverlay:35,ratsNestOverlay:30,toolbarOverlay:70,warnings:30,topLayer:20,clickToInteractOverlay:100},Kj={red:"red",black:"black",green:"green",board:"rgb(255, 255, 255)",other:"#eee",top:pn.board.copper.f,inner1:pn.board.copper.in1,inner2:pn.board.copper.in2,inner3:pn.board.copper.in3,inner4:pn.board.copper.in4,inner5:pn.board.copper.in5,inner6:pn.board.copper.in6,inner7:pn.board.copper.in7,inner8:pn.board.copper.in8,bottom:pn.board.copper.b,drill:pn.board.anchor,keepout:pn.board.background,tkeepout:pn.board.b_crtyd,tplace:pn.board.b_silks,top_courtyard:pn.board.f_crtyd,bottom_courtyard:pn.board.b_crtyd,top_silkscreen:pn.board.f_silks,bottom_silkscreen:pn.board.b_silks,top_fabrication:pn.board.f_fab,bottom_fabrication:pn.board.b_fab,soldermask_top:pn.board.soldermask.top,soldermask_bottom:pn.board.soldermask.bottom,soldermask_with_copper_top:pn.board.soldermaskWithCopper.top,soldermask_with_copper_bottom:pn.board.soldermaskWithCopper.bottom,bottom_notes:pn.board.user_2,top_notes:pn.board.user_2,...pn.board},c7e=["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"],I7e=class{canvasLayerMap;ctxLayerMap;aperture;transform;foregroundLayer="top";lastPoint;constructor(e){this.canvasLayerMap=e,this.ctxLayerMap=Object.fromEntries(Object.entries(e).map(([A,t])=>[A,t.getContext("2d")])),this.transform=ba(),this.transform.d*=-1,this.transform=tn(this.transform,sn(0,-500)),this.lastPoint={x:0,y:0},this.equip({})}clear(){for(const e of Object.values(this.ctxLayerMap))e.clearRect(0,0,e.canvas.width,e.canvas.height)}equip(e){this.aperture={fontSize:0,shape:"circle",mode:"add",size:0,color:"red",layer:"top",opacity:this.foregroundLayer===e.color?1:.5,...e}}drawMeshPattern(e,A,t,i,n,o=45){const s=this.getLayerCtx(),[r,a]=Ct(this.transform,[e,A]),[g,c]=Ct(this.transform,[e+t,A+i]),I=Lf(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:e,y:A,w:t,h:i,mesh_fill:n,is_filled:o=!0,has_stroke:s,is_stroke_dashed:r,stroke_width:a,roundness:g}){const[c,I]=Ct(this.transform,[e-t/2,A-i/2]),[l,B]=Ct(this.transform,[e+t/2,A+i/2]);this.applyAperture();const C=this.getLayerCtx(),Q=g?Lf(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(e-t/2,A-i/2,t,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=Lf(this.transform,a)),r){let u=[];const d=Math.abs(this.transform.a);if(d>0){const m=.1*d,w=m*1.3;m>.5&&(u=[m,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(e,A,t,i,n,o,s){const r=this.getLayerCtx();this.applyAperture();const[a,g]=Ct(this.transform,[e-t/2,A-i/2]),[c,I]=Ct(this.transform,[e+t/2,A+i/2]),l=o?Lf(this.transform,o):0;r.save();const[B,C]=Ct(this.transform,[e,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(e-t/2,A-i/2,t,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(e,A,t,i,n){const o=this.getLayerCtx();this.applyAperture(),o.save();const[s,r]=Ct(this.transform,[e,A]);o.translate(s,r);const a=360-n;n&&o.rotate(a*Math.PI/180),o.translate(-s,-r),this.pill(e,A,t,i),o.restore()}circle(e,A,t,i,n=!0){const o=Lf(this.transform,t),[s,r]=Ct(this.transform,[e,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(e-t,A-t,t*2,t*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(e,A,t,i){const n=Lf(this.transform,t),o=Lf(this.transform,i),[s,r]=Ct(this.transform,[e,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(e,A,t,i){const[n,o]=Ct(this.transform,[e-t/2,A+i/2]),s=Lf(this.transform,t),r=Lf(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(e){if(e.length<3)return;this.applyAperture();const A=this.getLayerCtx(),t=e.map(n=>Ct(this.transform,[n.x,n.y]));A.beginPath(),A.moveTo(t[0][0],t[0][1]);for(let n=1;n<t.length;n++)A.lineTo(t[n][0],t[n][1]);A.closePath(),A.fill("evenodd");const i=Lf(this.transform,this.aperture.size);i>0&&(A.lineWidth=i,A.stroke())}debugText(e,A,t){const[i,n]=Ct(this.transform,[A,t]);this.applyAperture();const o=this.getLayerCtx();o.font="10px sans-serif",o.fillText(e,i,n)}getLayerCtx(){const e=this.ctxLayerMap[this.aperture.layer];if(!e)throw new Error(`No context for layer "${this.aperture.layer}"`);return e}orderAndFadeLayers(){const{canvasLayerMap:e,foregroundLayer:A}=this,t=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",...t?[t]:[],...i?[i]:[],...n?[n]:[],...o?[o]:[],...s?[s]:[]]),a=[A,"edge_cuts",...t?[t]:[],...i?[i]:[],...n?[n]:[],...o?[o]:[],...s?[s]:[]],g=A==="drill"?[]:["drill"],c=A==="drill"?["drill"]:[],I=[...c7e.filter(l=>!a.includes(l)),...g,A,...t?[t]:[],...c,"edge_cuts",...i?[i]:[],...n?[n]:[],...o?[o]:[],...s?[s]:[]];I.forEach((l,B)=>{const C=e[l];C&&(C.style.zIndex=`${xc.topLayer-(I.length-B)}`,C.style.opacity=r.has(l)?"1":"0.5")})}applyAperture(){const{transform:e,aperture:A}=this;let{size:t,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=Lf(e,t),r.lineCap="round",i==="add"){r.globalCompositeOperation="source-over";let a=Kj[n.toLowerCase()];if(!a)try{a=Ha(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=`${Lf(Xy(e),o)}px sans-serif`}moveTo(e,A){this.lastPoint={x:e,y:A}}lineTo(e,A){const[t,i]=Ct(this.transform,[e,A]),{size:n,shape:o,mode:s}=this.aperture,r=Lf(this.transform,n),{lastPoint:a}=this,g=Ct(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(t,i),c.stroke(),c.closePath(),o==="square"&&c.fillRect(t-r/2,i-r/2,r,r),this.lastPoint={x:e,y:A}}polygonWithArcs(e){const A=this.getLayerCtx(),t=i=>{if(i.vertices.length===0)return;const n=i.vertices[0],o=Ct(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=Ct(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,m=Math.sqrt(Math.max(0,C*C-(l/2)**2)),w=Q+m*d*Math.sign(g),D=h+m*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=Ct(this.transform,[w,D]),R=Lf(this.transform,C);A.arc(b[0],b[1],R,-S,-_,g>0)}else{const g=Ct(this.transform,[a.x,a.y]);A.lineTo(g[0],g[1])}}A.closePath()};if(A.beginPath(),t(e.outer_ring),e.inner_rings)for(const i of e.inner_rings)t(i);A.fill("evenodd")}};function l7e(e){return e.type==="pcb_copper_pour"}function qj({canvas:e,elements:A,layers:t,realToCanvasMat:i}){const n=A.filter(l7e);if(n.length===0)return;const o=new eQ(e);o.realToCanvasMat=i,o.drawElements(n,{layers:t})}var B7e={...sp,silkscreen:{top:pn.board.f_fab,bottom:pn.board.b_fab}};function C7e(e){return e.type.includes("pcb_fabrication_note")}function fQt({canvas:e,elements:A,layers:t,realToCanvasMat:i}){const n=new eQ(e);n.configure({colorOverrides:B7e}),n.realToCanvasMat=i;const o=A.filter(C7e);n.drawElements(o,{layers:t})}function Q7e(e){return e.type==="pcb_hole"}function h7e({canvas:e,elements:A,layers:t,realToCanvasMat:i,drawSoldermask:n}){const o=new eQ(e);o.realToCanvasMat=i;const s=A.filter(Q7e);o.drawElements(s,{layers:t,drawSoldermask:n})}function E7e(e){return e.type==="pcb_board"}function u7e({canvas:e,elements:A,layers:t,realToCanvasMat:i,drawSoldermask:n}){const o=new eQ(e);o.realToCanvasMat=i;const s=A.filter(E7e);for(const r of s)o.drawElements([r],{layers:t,drawSoldermask:!1,drawBoardMaterial:n??!1,minBoardOutlineStrokePx:2})}function d7e(e){return e.type==="pcb_cutout"}function p7e({canvas:e,elements:A,layers:t,realToCanvasMat:i}){const n=new eQ(e);n.realToCanvasMat=i;const o=A.filter(d7e);n.drawElements(o,{layers:t})}function f7e(e){return e.type==="pcb_keepout"}function y7e({canvas:e,elements:A,layers:t,realToCanvasMat:i}){const n=A.filter(f7e);if(n.length===0)return;const o=new eQ(e);o.realToCanvasMat=i,o.drawElements(n,{layers:[]})}function m7e(e){return e.type.startsWith("pcb_note_")}function yQt({canvas:e,elements:A,layers:t,realToCanvasMat:i}){const n=new eQ(e);n.realToCanvasMat=i;const o=A.filter(m7e);n.drawElements(o,{layers:t})}function w7e(e){return e.type==="pcb_panel"}function D7e({canvas:e,elements:A,layers:t,realToCanvasMat:i,drawSoldermask:n}){const o=new eQ(e);o.realToCanvasMat=i;const s=A.filter(w7e);for(const r of s)o.drawElements([r],{layers:t})}var S7e={...sp,copper:{...sp.copper,top:Ha(pn.board.pad_front).lighten(.5).toString(),bottom:Ha(pn.board.pad_back).lighten(.5).toString(),inner1:Ha(pn.board.copper.in1).lighten(.5).toString(),inner2:Ha(pn.board.copper.in2).lighten(.5).toString(),inner3:Ha(pn.board.copper.in3).lighten(.5).toString(),inner4:Ha(pn.board.copper.in4).lighten(.5).toString(),inner5:Ha(pn.board.copper.in5).lighten(.5).toString(),inner6:Ha(pn.board.copper.in6).lighten(.5).toString()}};function b7e(e){return e.type==="pcb_smtpad"}function x7e({canvas:e,elements:A,layers:t,realToCanvasMat:i,primitives:n,drawSoldermask:o}){const s=A.filter(b7e).filter(c=>{const I=c.layer;return t.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 eQ(e);c.realToCanvasMat=i,c.drawElements(g,{layers:t,drawSoldermask:o})}if(a.length>0){const c=new eQ(e);c.configure({colorOverrides:S7e}),c.realToCanvasMat=i,c.drawElements(a,{layers:t,drawSoldermask:o})}}var _7e={...sp,copper:{...sp.copper,top:Ha(pn.board.pad_front).lighten(.5).toString(),bottom:Ha(pn.board.pad_back).lighten(.5).toString(),inner1:Ha(pn.board.copper.in1).lighten(.5).toString(),inner2:Ha(pn.board.copper.in2).lighten(.5).toString(),inner3:Ha(pn.board.copper.in3).lighten(.5).toString(),inner4:Ha(pn.board.copper.in4).lighten(.5).toString(),inner5:Ha(pn.board.copper.in5).lighten(.5).toString(),inner6:Ha(pn.board.copper.in6).lighten(.5).toString()}};function k7e(e){return e.type==="pcb_trace"}var v7e=e=>e.map(A=>A.endsWith("_copper")?A.replace("_copper",""):A),F7e=(e,A)=>{const t=e.route.filter(i=>i.route_type==="wire"&&"layer"in i&&A.has(i.layer));return t.length===0?null:{...e,route:t}};function M7e({canvas:e,elements:A,layers:t,realToCanvasMat:i,primitives:n}){const o=new Set(v7e(t)),s=A.filter(k7e).map(c=>F7e(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 eQ(e);c.realToCanvasMat=i,c.drawElements(g,{layers:t})}if(a.length>0){const c=new eQ(e);c.configure({colorOverrides:_7e}),c.realToCanvasMat=i,c.drawElements(a,{layers:t})}}var G7e={...sp,copper:{...sp.copper,top:Ha(pn.board.pad_front).lighten(.5).toString(),bottom:Ha(pn.board.pad_back).lighten(.5).toString()}};function R7e(e){return e.type==="pcb_plated_hole"}function mQt({canvas:e,elements:A,layers:t,realToCanvasMat:i,primitives:n,drawSoldermask:o}){const s=A.filter(R7e);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 eQ(e);c.realToCanvasMat=i,c.drawElements(g,{layers:t,drawSoldermask:o})}if(a.length>0){const c=new eQ(e);c.configure({colorOverrides:G7e}),c.realToCanvasMat=i,c.drawElements(a,{layers:t,drawSoldermask:o})}}function wQt(e){const{lines:A,anchorPoint:t,ccwRotation:i}=e;if(!i)return A;const n=i*Math.PI/180,o=Jl(n),s=tn(sn(t.x,t.y),o,sn(-t.x,-t.y));return Ct(s,t),A.map(r=>({...r,x1:Ct(s,{x:r.x1,y:r.y1}).x,y1:Ct(s,{x:r.x1,y:r.y1}).y,x2:Ct(s,{x:r.x2,y:r.y2}).x,y2:Ct(s,{x:r.x2,y:r.y2}).y}))}var N7e=.6,DQt=.2,SQt=e=>{const A=e.size*.7,t=A*N7e,i=A*DQt,n=A*DQt,o=e.text.split(/\r?\n/),s=e.text.length>0&&A>0,r=s?o.length:0,a=s?o.map(I=>I.length===0?0:I.length*t+(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:t,space_between_chars:i,space_between_lines:n,width:g,height:c}},bQt=e=>{const A=SQt(e);return{width:A.width,height:A.height,lineHeight:A.target_height,lineSpacing:A.space_between_lines,lineCount:A.line_count}},xQt=e=>{const{text_lines:A,line_count:t,line_widths:i,target_height:n,target_width_char:o,space_between_chars:s,space_between_lines:r,width:a}=SQt(e);if(n<=0||t===0)return[];const g=n/12,c=[];for(let I=0;I<t;I++){const l=-I*(n+r),B=i[I],C=(a-B)/2;let Q=e.x+C;for(let h=0;h<A[I].length;h++){const E=A[I][h],u=YF[E]??YF[E.toUpperCase()];if(!u){Q+=o+s;continue}for(const{x1:d,y1:f,x2:m,y2:w}of u)c.push({_pcb_drawing_object_id:wm("line"),pcb_drawing_type:"line",x1:Q+o*d,y1:e.y+l+n*f,x2:Q+o*m,y2:e.y+l+n*w,width:g,layer:e.layer,unit:e.unit,color:e.color});Q+=o+s}}return c};function IS(e){const t=e.color??Kj[e.layer];let i=Ha(t);return e._element?.type==="pcb_copper_pour"&&(i=i.alpha(.7)),e.is_mouse_over||e.is_in_highlighted_net?i.lighten(.5).rgb().toString():i.rgb().toString()}var _Qt=(e,A)=>{e.equip({size:A.zoomIndependent?A.width/e.transform.a:A.width,shape:A.squareCap?"square":"circle",color:IS(A),layer:A.layer}),e.moveTo(A.x1,A.y1),e.lineTo(A.x2,A.y2)},L7e=(e,A,t)=>{switch(t){case"top_left":return{x:0,y:-A};case"top_center":return{x:-e/2,y:-A};case"top_right":return{x:-e,y:-A};case"center_left":return{x:0,y:-A/2};case"center":return{x:-e/2,y:-A/2};case"center_right":return{x:-e,y:-A/2};case"bottom_left":return{x:0,y:0};case"bottom_center":return{x:-e/2,y:0};case"bottom_right":return{x:-e,y:0};default:return{x:0,y:0}}},kQt=e=>e.layer==="bottom_silkscreen"||e.layer==="bottom"?e.is_mirrored!==!1:e.is_mirrored===!0,U7e=(e,A)=>{e.equip({fontSize:A.size,color:IS(A),layer:A.layer});const{width:t,height:i}=bQt(A),n=L7e(t,i,A.align);A.x??=0,A.y??=0;const o={x:A.x,y:A.y};let s=xQt({...A,x:A.x+n.x,y:A.y+n.y});if(kQt(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=wQt(r)}for(const r of s)_Qt(e,r)},H7e=(e,A)=>{const{width:t,height:i,lineHeight:n}=bQt(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=t+o.left+o.right,r=i+o.top+o.bottom,a=t/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?FQt(e,B):vQt(e,B);let C=xQt({...A,x:c,y:I});if(kQt(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=wQt(Q)}for(const Q of C)e.equip({size:Q.width,shape:"circle",color:"black",layer:A.layer,mode:"subtract"}),e.moveTo(Q.x1,Q.y1),e.lineTo(Q.x2,Q.y2);e.equip({mode:"add"})},vQt=(e,A)=>{e.equip({color:IS(A),layer:A.layer,size:A.stroke_width}),e.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})},FQt=(e,A)=>{e.equip({color:IS(A),layer:A.layer}),e.rotatedRect(A.x,A.y,A.w,A.h,A.ccw_rotation,A.roundness,A.mesh_fill)},Y7e=(e,A)=>{e.equip({color:IS(A),layer:A.layer}),e.rotatedPill(A.x,A.y,A.w,A.h,A.ccw_rotation)},J7e=(e,A)=>{e.equip({color:IS(A),layer:A.layer}),e.circle(A.x,A.y,A.r,A.mesh_fill)},T7e=(e,A)=>{e.equip({color:IS(A),layer:A.layer}),e.oval(A.x,A.y,A.rX,A.rY)},P7e=(e,A)=>{e.equip({color:IS(A),layer:A.layer}),e.pill(A.x,A.y,A.w,A.h)},K7e=(e,A)=>{e.equip({color:IS(A),layer:A.layer}),e.polygon(A.points)},q7e=(e,A)=>{e.equip({color:IS(A),layer:A.layer}),e.polygonWithArcs(A.brep_shape)},O7e=(e,A)=>{switch(A.pcb_drawing_type){case"line":return _Qt(e,A);case"text":return A.is_knockout?H7e(e,A):U7e(e,A);case"rect":return A.ccw_rotation?FQt(e,A):vQt(e,A);case"circle":return J7e(e,A);case"oval":return T7e(e,A);case"pill":return A.ccw_rotation?Y7e(e,A):P7e(e,A);case"polygon":return K7e(e,A);case"polygon_with_arcs":return q7e(e,A)}},W7e=(e,A)=>{for(const t of A)O7e(e,t)},Z7e={...sp,copper:{...sp.copper,top:Ha(pn.board.pad_front).lighten(.5).toString(),bottom:Ha(pn.board.pad_back).lighten(.5).toString(),inner1:Ha(pn.board.copper.in1).lighten(.5).toString(),inner2:Ha(pn.board.copper.in2).lighten(.5).toString(),inner3:Ha(pn.board.copper.in3).lighten(.5).toString(),inner4:Ha(pn.board.copper.in4).lighten(.5).toString(),inner5:Ha(pn.board.copper.in5).lighten(.5).toString(),inner6:Ha(pn.board.copper.in6).lighten(.5).toString()},soldermask:{...sp.soldermask,top:Ha(pn.board.soldermask.top).lighten(.35).toString(),bottom:Ha(pn.board.soldermask.bottom).lighten(.35).toString()}};function MQt({canvas:e,elements:A,layers:t,realToCanvasMat:i,drawSoldermaskTop:n,drawSoldermaskBottom:o,primitives:s}){const r=new eQ(e);r.realToCanvasMat=i;const a=A.filter(l=>l.type==="pcb_board");if(a.length<=1)r.drawElements(A,{layers:t,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:t,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 eQ(e);I.configure({colorOverrides:Z7e}),I.realToCanvasMat=i,I.drawElements(c,{layers:t,drawSoldermask:!0,drawSoldermaskTop:n,drawSoldermaskBottom:o,drawBoardMaterial:!1})}var V7e={...sp,silkscreen:{top:pn.board.f_silks,bottom:pn.board.b_silks}};function j7e(e){return e.type.includes("pcb_silkscreen")}function GQt({canvas:e,elements:A,layers:t,realToCanvasMat:i}){const n=new eQ(e);n.configure({colorOverrides:V7e}),n.realToCanvasMat=i;const o=A.filter(j7e);n.drawElements(o,{layers:t})}var z7e={...sp,copper:{...sp.copper,top:Ha(pn.board.pad_front).lighten(.5).toString(),bottom:Ha(pn.board.pad_back).lighten(.5).toString()}};function X7e(e){return e.type==="pcb_via"}function RQt({canvas:e,elements:A,layers:t,realToCanvasMat:i,primitives:n,drawSoldermask:o}){const s=A.filter(X7e).filter(c=>t.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 eQ(e);c.realToCanvasMat=i,c.drawElements(g,{layers:t,drawSoldermask:o})}if(a.length>0){const c=new eQ(e);c.configure({colorOverrides:z7e}),c.realToCanvasMat=i,c.drawElements(a,{layers:t,drawSoldermask:o})}}var $7e={...sp,courtyard:{top:pn.board.f_crtyd,bottom:pn.board.b_crtyd}};function A$e(e){return e.type==="pcb_courtyard_circle"||e.type==="pcb_courtyard_rect"||e.type==="pcb_courtyard_outline"}function NQt({canvas:e,elements:A,layers:t,realToCanvasMat:i}){const n=new eQ(e);n.configure({colorOverrides:$7e}),n.realToCanvasMat=i;const o=A.filter(A$e);n.drawElements(o,{layers:t})}var t$e=["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"],e$e=({primitives:e,elements:A,transform:t,grid:i,width:n=500,height:o=500})=>{const s=AA.useRef({}),r=rl(l=>l.selected_layer),a=rl(l=>l.is_showing_solder_mask),g=rl(l=>l.is_showing_fabrication_notes),c=rl(l=>l.is_showing_courtyards),I=rl(l=>l.is_showing_silkscreen);return AA.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 I7e(l);t&&(B.transform=t),B.clear(),B.foregroundLayer=r;const C=e.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(W7e(B,C),t){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,m=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:m,copperLayer:"inner5_copper"},{canvas:w,copperLayer:"inner6_copper"}];for(const{canvas:Y,copperLayer:J}of D)Y&&M7e({canvas:Y,elements:A,layers:[J],realToCanvasMat:t,primitives:e});Q&&mQt({canvas:Q,elements:A,layers:["top_copper"],realToCanvasMat:t,primitives:e,drawSoldermask:a}),h&&mQt({canvas:h,elements:A,layers:["bottom_copper"],realToCanvasMat:t,primitives:e,drawSoldermask:a}),Q&&qj({canvas:Q,elements:A,layers:["top_copper"],realToCanvasMat:t}),h&&qj({canvas:h,elements:A,layers:["bottom_copper"],realToCanvasMat:t});for(const{canvas:Y,copperLayer:J}of D)Y&&x7e({canvas:Y,elements:A,layers:[J],realToCanvasMat:t,primitives:e,drawSoldermask:a});if(Q&&RQt({canvas:Q,elements:A,layers:["top_copper"],realToCanvasMat:t,primitives:e,drawSoldermask:a}),h&&RQt({canvas:h,elements:A,layers:["bottom_copper"],realToCanvasMat:t,primitives:e,drawSoldermask:a}),a){const Y=r==="bottom"?"bottom":"top",J=Y==="top",O=Y==="bottom",W=s.current.soldermask_top;W&&Y==="top"&&MQt({canvas:W,elements:A,layers:["top_soldermask"],realToCanvasMat:t,drawSoldermaskTop:J,drawSoldermaskBottom:O,primitives:e});const z=s.current.soldermask_bottom;z&&Y==="bottom"&&MQt({canvas:z,elements:A,layers:["bottom_soldermask"],realToCanvasMat:t,drawSoldermaskTop:J,drawSoldermaskBottom:O,primitives:e})}Q&&qj({canvas:Q,elements:A,layers:["top_copper"],realToCanvasMat:t}),h&&qj({canvas:h,elements:A,layers:["bottom_copper"],realToCanvasMat:t});const S=s.current.drill;if(S&&h7e({canvas:S,elements:A,layers:["drill"],realToCanvasMat:t}),I){const Y=s.current.top_silkscreen;Y&&GQt({canvas:Y,elements:A,layers:["top_silkscreen"],realToCanvasMat:t});const J=s.current.bottom_silkscreen;J&&GQt({canvas:J,elements:A,layers:["bottom_silkscreen"],realToCanvasMat:t})}if(g){const Y=s.current.top_fabrication;Y&&fQt({canvas:Y,elements:A,layers:["top_fabrication_note"],realToCanvasMat:t});const J=s.current.bottom_fabrication;J&&fQt({canvas:J,elements:A,layers:["bottom_fabrication_note"],realToCanvasMat:t})}const _=s.current.bottom_notes;_&&yQt({canvas:_,elements:A,layers:["bottom_user_note"],realToCanvasMat:t});const b=s.current.top_notes;if(b&&yQt({canvas:b,elements:A,layers:["top_user_note"],realToCanvasMat:t}),c){const Y=s.current.top_courtyard;Y&&NQt({canvas:Y,elements:A,layers:["top_courtyard"],realToCanvasMat:t});const J=s.current.bottom_courtyard;J&&NQt({canvas:J,elements:A,layers:["bottom_courtyard"],realToCanvasMat:t})}const R=s.current.board;R&&(D7e({canvas:R,elements:A,layers:[],realToCanvasMat:t,drawSoldermask:a}),u7e({canvas:R,elements:A,layers:[],realToCanvasMat:t,drawSoldermask:a}));const F=s.current.edge_cuts;F&&p7e({canvas:F,elements:A,layers:["edge_cuts"],realToCanvasMat:t});const H=[{canvas:Q,layer:"top"},{canvas:h,layer:"bottom"}];for(const{canvas:Y,layer:J}of H)Y&&y7e({canvas:Y,elements:A,layers:[J],realToCanvasMat:t})}B.orderAndFadeLayers()},[e,A,t,r,a,g,c,I]),Z.jsxs("div",{style:{backgroundColor:"black",width:n,height:o,position:"relative"},children:[Z.jsx(_j.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:t,stringifyCoord:(l,B,C)=>`${_j.toMMSI(l,C)}, ${_j.toMMSI(B,C)}`}),t$e.filter(l=>!(!a&&l.includes("soldermask")||!I&&l.includes("silkscreen"))).map(l=>l.replace(/-/g,"")).map((l,B)=>Z.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))]})},i$e=.6,n$e=1;ryA(c6e(),1),ryA(S6e(),1);var Oj=["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 LQt(e,A,t,i={}){const n=i.padding??40,o=i.yFlip??!1;let s;if("center"in e){const c=e.width/2,I=e.height/2;s={minX:e.center.x-c,maxX:e.center.x+c,minY:e.center.y-I,maxY:e.center.y+I}}else s=e;const r=s.maxX-s.minX||1,a=s.maxY-s.minY||1,g=Math.min((A-2*n)/r,(t-2*n)/a);return tn(sn(A/2,t/2),za(g,o?-g:g),sn(-(s.minX+r/2),-(s.minY+a/2)))}function o$e(e){const A=[...e.points||[],...(e.lines||[]).flatMap(t=>t.points),...(e.rects||[]).flatMap(t=>{const i=t.width/2,n=t.height/2;return[{x:t.center.x-i,y:t.center.y-n},{x:t.center.x+i,y:t.center.y-n},{x:t.center.x-i,y:t.center.y+n},{x:t.center.x+i,y:t.center.y+n}]}),...(e.circles||[]).flatMap(t=>[{x:t.center.x-t.radius,y:t.center.y},{x:t.center.x+t.radius,y:t.center.y},{x:t.center.x,y:t.center.y-t.radius},{x:t.center.x,y:t.center.y+t.radius}]),...(e.texts||[]).flatMap(t=>{const i=t.fontSize??12,n=t.text.length*i*i$e,o=i*n$e,s=t.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=t.x+a,I=t.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((t,i)=>({minX:Math.min(t.minX,i.x),maxX:Math.max(t.maxX,i.x),minY:Math.min(t.minY,i.y),maxY:Math.max(t.maxY,i.y)}),{minX:1/0,maxX:-1/0,minY:1/0,maxY:-1/0})}function s$e(e,A,t={}){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(t.transform)s=t.transform;else if(t.viewbox)s=LQt(t.viewbox,n,o,{padding:t.padding,yFlip:t.yFlip});else{const r=o$e(e),a=e.coordinateSystem==="cartesian";s=LQt(r,n,o,{padding:t.padding??40,yFlip:a})}i.clearRect(0,0,n,o),i.save(),e.rects&&e.rects.length>0&&e.rects.forEach(r=>{const a=r.width/2,g=r.height/2,c=Ct(s,{x:r.center.x-a,y:r.center.y-g}),I=Ct(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())}),e.circles&&e.circles.length>0&&e.circles.forEach(r=>{const a=Ct(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())}),e.lines&&e.lines.length>0&&e.lines.forEach((r,a)=>{if(r.points.length===0)return;i.beginPath();const g=Ct(s,r.points[0]);i.moveTo(g.x,g.y);for(let c=1;c<r.points.length;c++){const I=Ct(s,r.points[c]);i.lineTo(I.x,I.y)}if(i.strokeStyle=r.strokeColor||Oj[a%Oj.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()}),e.points&&e.points.length>0&&e.points.forEach((r,a)=>{const g=Ct(s,r);i.beginPath(),i.arc(g.x,g.y,3,0,2*Math.PI),i.fillStyle=r.color||Oj[a%Oj.length],i.fill(),r.label&&!t.disableLabels&&(i.fillStyle=r.color||"black",i.font="12px sans-serif",i.fillText(r.label,g.x+5,g.y-5))}),e.texts&&e.texts.length>0&&e.texts.forEach(r=>{const a=Ct(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 r$e=({children:e,transform:A,debugGraphics:t})=>{const i=AA.useRef(null),[n,{width:o,height:s}]=yT(),r=rl(a=>a.is_showing_autorouting);return AA.useEffect(()=>{r&&i.current&&t&&o&&s&&(i.current.width=o,i.current.height=s,s$e(t,i.current,{transform:A,disableLabels:!0}))},[t,A,o,s,r]),r?Z.jsxs("div",{ref:n,style:{position:"relative",width:"100%",height:"100%"},children:[e,Z.jsx("canvas",{ref:i,style:{position:"absolute",top:0,left:0,opacity:.5,zIndex:100,width:"100%",height:"100%",pointerEvents:"none"}})]}):e},a$e=({children:e,transform:A=ba(),elements:t=[]})=>{const[i,{width:n,height:o}]=yT(),s=AA.useRef(null);return AA.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=t.filter(I=>I.type==="pcb_component"),c=t.filter(I=>I.type==="pcb_manual_edit_conflict_warning");a.strokeStyle=pn.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=Ct(A,Q),E=B*Math.abs(A.a),u=C*Math.abs(A.d),d=.1*Math.abs(A.a),f=E+d*2,m=u+d*2,w=h.x-f/2,D=h.y-m/2;a.beginPath(),a.rect(w,D,f,m),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,H=b+_*2,Y=w+(f-F)/2,J=D+m+5;a.fillStyle="rgba(0, 0, 0, 0.7)",a.beginPath(),a.roundRect(Y,J,F,H,3),a.fill(),a.fillStyle=pn.board.drc_warning,a.textAlign="center",a.textBaseline="middle",a.fillText(S,Y+F/2,J+H/2)})},[t,A,n,o]),Z.jsxs("div",{ref:i,style:{position:"relative",width:"100%",height:"100%"},children:[e,Z.jsx("canvas",{ref:s,style:{position:"absolute",top:0,left:0,pointerEvents:"none",zIndex:xc.warnings}})]})},Wj=(e,A,t)=>t(e,A),UQt=(e,A,t,i,n)=>{const o=n*Math.PI/180,s=Math.cos(o),r=Math.sin(o),a=e-t,g=A-i,c=a*s-g*r,I=a*r+g*s;return{x:c+t,y:I+i}},mT=e=>{if(e.length===0)return null;let A=e[0].x,t=e[0].x,i=e[0].y,n=e[0].y;for(const o of e)A=Wj(A,o.x,Math.min),t=Wj(t,o.x,Math.max),i=Wj(i,o.y,Math.min),n=Wj(n,o.y,Math.max);return{minX:A,maxX:t,minY:i,maxY:n}},g$e=(e,A)=>({minX:Math.min(e.minX,A.minX),maxX:Math.max(e.maxX,A.maxX),minY:Math.min(e.minY,A.minY),maxY:Math.max(e.maxY,A.maxY)}),c$e=(e,A)=>e?g$e(e,A):A,I$e=e=>{switch(e.pcb_drawing_type){case"line":{const A=(e.width??0)/2,t=[{x:e.x1,y:e.y1},{x:e.x2,y:e.y2}],i=mT(t);return i?{minX:i.minX-A,maxX:i.maxX+A,minY:i.minY-A,maxY:i.maxY+A}:null}case"rect":{const A=e.w/2,t=e.h/2,i=[{x:e.x-A,y:e.y-t},{x:e.x+A,y:e.y-t},{x:e.x+A,y:e.y+t},{x:e.x-A,y:e.y+t}],n=e.ccw_rotation??0,o=n===0?i:i.map(s=>UQt(s.x,s.y,e.x,e.y,n));return mT(o)}case"circle":return{minX:e.x-e.r,maxX:e.x+e.r,minY:e.y-e.r,maxY:e.y+e.r};case"oval":return{minX:e.x-e.rX,maxX:e.x+e.rX,minY:e.y-e.rY,maxY:e.y+e.rY};case"pill":{const A=e.w/2,t=e.h/2,i=[{x:e.x-A,y:e.y-t},{x:e.x+A,y:e.y-t},{x:e.x+A,y:e.y+t},{x:e.x-A,y:e.y+t}],n=e.ccw_rotation??0,o=n===0?i:i.map(s=>UQt(s.x,s.y,e.x,e.y,n));return mT(o)}case"polygon":return mT(e.points);case"polygon_with_arcs":{const A=e.brep_shape.outer_ring.vertices.map(t=>({x:t.x,y:t.y}));return mT(A)}case"text":{const A=e.size??0,t=e.text?e.text.length*A*.6:0,i=A;if(t===0&&i===0)return{minX:e.x,maxX:e.x,minY:e.y,maxY:e.y};const n=t/2,o=i/2;return{minX:e.x-n,maxX:e.x+n,minY:e.y-o,maxY:e.y+o}}default:return null}};function l$e(e){const{dimensionStart:A,dimensionEnd:t,screenDimensionStart:i,screenDimensionEnd:n,flipX:o,flipY:s}=e,r=t.x-A.x,a=t.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 m=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&&(m=-m,w=-w),D&&(m+=Math.cos(f*Math.PI/180)*-45,w+=Math.sin(f*Math.PI/180)*-45),S&&(m+=Math.cos(f*Math.PI/180)+-20,w+=Math.sin(f*Math.PI/180)+-10),_&&(m+=Math.cos(f*Math.PI/180)*10,w+=Math.sin(f*Math.PI/180)*10);const b=E+m,R=u+w;return{distance:g,screenDistance:l,x:b,y:R,show:g>.01&&l>30&&h}}function B$e(e){const{dimensionStart:A,dimensionEnd:t,screenDimensionStart:i,screenDimensionEnd:n,flipX:o,flipY:s}=e;return AA.useMemo(()=>l$e({dimensionStart:A,dimensionEnd:t,screenDimensionStart:i,screenDimensionEnd:n,flipX:o,flipY:s}),[A,t,i,n,o,s])}var C$e=(e,A,t)=>{const i=t*Math.PI/180,n=Math.cos(i),o=Math.sin(i),s=e.x-A.x,r=e.y-A.y,a=s*n-r*o,g=s*o+r*n;return{x:a+A.x,y:g+A.y}},HQt=(e,A,t,i)=>{const n={top_left:{x:e.x-A,y:e.y-t},top_center:{x:e.x,y:e.y-t},top_right:{x:e.x+A,y:e.y-t},center_left:{x:e.x-A,y:e.y},center:{x:e.x,y:e.y},center_right:{x:e.x+A,y:e.y},bottom_left:{x:e.x-A,y:e.y+t},bottom_center:{x:e.x,y:e.y+t},bottom_right:{x:e.x+A,y:e.y+t}};return i===0?Object.entries(n).map(([o,s])=>({anchor:o,point:s})):Object.entries(n).map(([o,s])=>({anchor:o,point:C$e(s,e,i)}))},Q$e=e=>{switch(e.pcb_drawing_type){case"rect":{const A=e.ccw_rotation??0;return HQt({x:e.x,y:e.y},e.w/2,e.h/2,A)}case"pill":{const A=e.ccw_rotation??0;return HQt({x:e.x,y:e.y},e.w/2,e.h/2,A)}case"circle":return[{anchor:"circle_center",point:{x:e.x,y:e.y}},{anchor:"circle_right",point:{x:e.x+e.r,y:e.y}},{anchor:"circle_left",point:{x:e.x-e.r,y:e.y}},{anchor:"circle_top",point:{x:e.x,y:e.y-e.r}},{anchor:"circle_bottom",point:{x:e.x,y:e.y+e.r}}];case"oval":return[{anchor:"oval_center",point:{x:e.x,y:e.y}},{anchor:"oval_right",point:{x:e.x+e.rX,y:e.y}},{anchor:"oval_left",point:{x:e.x-e.rX,y:e.y}},{anchor:"oval_top",point:{x:e.x,y:e.y-e.rY}},{anchor:"oval_bottom",point:{x:e.x,y:e.y+e.rY}}];case"line":{const A={x:(e.x1+e.x2)/2,y:(e.y1+e.y2)/2};return[{anchor:"line_start",point:{x:e.x1,y:e.y1}},{anchor:"line_mid",point:A},{anchor:"line_end",point:{x:e.x2,y:e.y2}}]}case"polygon":return e.points.map((A,t)=>({anchor:`polygon_vertex_${t}`,point:A}));case"polygon_with_arcs":return e.brep_shape.outer_ring.vertices.map((A,t)=>({anchor:`polygon_with_arcs_vertex_${t}`,point:{x:A.x,y:A.y}}));default:return[]}},h$e=16,DM=5,YQt=e=>{if(e.pcb_drawing_type==="text")return!0;const A=e._element;if(!A||typeof A!="object")return!1;const t=typeof A.type=="string"?A.type:void 0;return t?!!(t.startsWith("pcb_silkscreen_")||t.startsWith("pcb_note_")||t==="pcb_text"||t.startsWith("pcb_fabrication_note_")&&t!=="pcb_fabrication_note_rect"):!1},E$e=({children:e,transform:A,focusOnHover:t=!1,primitives:i=[]})=>{A||(A=ba());const[n,o]=AA.useState(!1),[s,r]=AA.useState(!1),[a,g]=AA.useState(!1),[c,I]=AA.useState({start:null,end:null}),l=rl(J=>J.is_mouse_over_container),B=AA.useCallback(()=>{a&&(g(!1),window.dispatchEvent(new Event("disarm-dimension-tool")))},[a]),[C,Q]=AA.useState({x:0,y:0}),[h,E]=AA.useState({x:0,y:0}),u=AA.useRef({x:0,y:0}),d=AA.useRef(null),m=d.current?.getBoundingClientRect(),w=AA.useMemo(()=>{const J=new Map;for(const O of i){if(!O._element||YQt(O)||O.pcb_drawing_type==="pill"||O.pcb_drawing_type==="rect"&&O.ccw_rotation&&O.ccw_rotation!==0)continue;const W=I$e(O);if(!W)continue;const z=J.get(O._element);J.set(O._element,c$e(z??void 0,W))}return J},[i]),D=AA.useMemo(()=>{const J=[];for(const O of i){if(!O._element||YQt(O))continue;const W=Q$e(O);if(W.length!==0)for(const z of W)J.push({anchor:z.anchor,point:z.point,element:O._element})}return J},[i]),S=AA.useMemo(()=>{const J=[];w.forEach((O,W)=>{if(!O)return;const z=(O.minX+O.maxX)/2,tA=(O.minY+O.maxY)/2,aA={top_left:{x:O.minX,y:O.minY},top_center:{x:z,y:O.minY},top_right:{x:O.maxX,y:O.minY},center_left:{x:O.minX,y:tA},center:{x:z,y:tA},center_right:{x:O.maxX,y:tA},bottom_left:{x:O.minX,y:O.maxY},bottom_center:{x:z,y:O.maxY},bottom_right:{x:O.maxX,y:O.maxY}};for(const[eA,oA]of Object.entries(aA))J.push({anchor:eA,point:oA,element:W})});for(const O of D)J.push(O);return J.push({anchor:"origin",point:{x:0,y:0},element:null}),J},[w,D]),_=AA.useMemo(()=>S.map((J,O)=>({...J,id:`${O}-${J.anchor}`,screenPoint:Ct(A,J.point)})),[S,A]),b=AA.useCallback(J=>{if(_.length===0)return{point:J,id:null};const O=Ct(A,J);let W=null;for(const z of _){const tA=z.screenPoint.x-O.x,aA=z.screenPoint.y-O.y,eA=Math.hypot(tA,aA);eA>h$e||(!W||eA<W.distance)&&(W={distance:eA,id:z.id,point:z.point})}return W?{point:W.point,id:W.id}:{point:J,id:null}},[_,A]);AA.useEffect(()=>{const J=W=>{const z=W.target;if(z.tagName==="INPUT"||z.tagName==="TEXTAREA"||z.isContentEditable)return;const tA=d.current?.contains(document.activeElement)||document.activeElement===d.current;if(!(!l&&!tA)){if(W.key==="d"){const aA=b({x:u.current.x,y:u.current.y});Q({x:aA.point.x,y:aA.point.y}),E({x:aA.point.x,y:aA.point.y}),I({start:aA.id,end:aA.id}),n?(o(!1),r(!1),I({start:null,end:null})):(o(!0),r(!0)),B()}W.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 R=Ct(A,C),F=Ct(A,h),H={left:Math.min(R.x,F.x),right:Math.max(R.x,F.x),top:Math.min(R.y,F.y),bottom:Math.max(R.y,F.y),flipX:R.x>F.x,flipY:R.y>F.y,width:0,height:0};H.width=H.right-H.left,H.height=H.bottom-H.top;const Y=B$e({dimensionStart:C,dimensionEnd:h,screenDimensionStart:R,screenDimensionEnd:F,flipX:H.flipX,flipY:H.flipY});return Z.jsxs("div",{ref:d,"data-pcb-viewer":!0,tabIndex:0,style:{position:"relative",outline:"none"},onMouseEnter:()=>{t&&d.current&&d.current.focus()},onMouseLeave:()=>{d.current&&d.current.blur()},onClick:()=>{d.current&&d.current.focus()},onMouseMove:J=>{const O=J.currentTarget.getBoundingClientRect(),W=J.clientX-O.left,z=J.clientY-O.top,tA=Ct(Xy(A),{x:W,y:z});if(u.current.x=tA.x,u.current.y=tA.y,s){const aA=b(tA);E({x:aA.point.x,y:aA.point.y}),I(eA=>({...eA,end:aA.id}))}},onMouseDown:J=>{const O=J.currentTarget.getBoundingClientRect(),W=J.clientX-O.left,z=J.clientY-O.top,tA=Ct(Xy(A),{x:W,y:z});if(a&&!n){const aA=b(tA);Q({x:aA.point.x,y:aA.point.y}),E({x:aA.point.x,y:aA.point.y}),I({start:aA.id,end:aA.id}),o(!0),r(!0),B()}else s?(r(!1),I(aA=>({...aA,end:null}))):n&&(o(!1),I({start:null,end:null}))},children:[e,n&&Z.jsxs(Z.Fragment,{children:[Y.show&&Z.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:xc.dimensionOverlay},children:Y.distance.toFixed(2)}),Z.jsx("div",{style:{position:"absolute",left:H.left,width:H.width,textAlign:"center",top:R.y+2,color:"red",mixBlendMode:"difference",pointerEvents:"none",marginTop:H.flipY?0:-20,fontSize:12,fontFamily:"sans-serif",zIndex:xc.dimensionOverlay},children:Math.abs(C.x-h.x).toFixed(2)}),Z.jsx("div",{style:{position:"absolute",left:F.x,height:H.height,display:"flex",flexDirection:"column",justifyContent:"center",top:H.top,color:"red",pointerEvents:"none",mixBlendMode:"difference",fontSize:12,fontFamily:"sans-serif",zIndex:xc.dimensionOverlay},children:Z.jsx("div",{style:{marginLeft:H.flipX?"-100%":4,paddingRight:4},children:Math.abs(C.y-h.y).toFixed(2)})}),Z.jsxs("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none",mixBlendMode:"difference",zIndex:xc.dimensionOverlay},width:m.width,height:m.height,children:[Z.jsx("defs",{children:Z.jsx("marker",{id:"head",orient:"auto",markerWidth:"3",markerHeight:"4",refX:"2",refY:"2",children:Z.jsx("path",{d:"M0,0 V4 L2,2 Z",fill:"red"})})}),Z.jsx("line",{x1:R.x,y1:R.y,x2:F.x,y2:F.y,markerEnd:"url(#head)",strokeWidth:1.5,fill:"none",stroke:"red"}),Z.jsx("line",{x1:R.x,y1:R.y,x2:F.x,y2:R.y,strokeWidth:1.5,fill:"none",strokeDasharray:"2,2",stroke:"red"}),Z.jsx("line",{x1:F.x,y1:R.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,W=DM/2;return Z.jsxs("svg",{width:DM,height:DM,style:{position:"absolute",left:J.screenPoint.x-W,top:J.screenPoint.y-W,pointerEvents:"none",zIndex:xc.dimensionOverlay},children:[Z.jsx("line",{x1:0,y1:0,x2:DM,y2:DM,stroke:O?"#66ccff":"white",strokeWidth:1}),Z.jsx("line",{x1:DM,y1:0,x2:0,y2:DM,stroke:O?"#66ccff":"white",strokeWidth:1})]},J.id)}),Z.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),")",Z.jsx("br",{}),"(",h.x.toFixed(2),",",h.y.toFixed(2),")",Z.jsx("br",{}),"dist:"," ",Math.sqrt((h.x-C.x)**2+(h.y-C.y)**2).toFixed(2)]})]})]})},u$e=(e,A,t=0)=>{const i=e.width/2,n=e.height/2,o=e.center.x-i-t,s=e.center.x+i+t,r=e.center.y-n-t,a=e.center.y+n+t;return A.x>o&&A.x<s&&A.y>r&&A.y<a},d$e=({children:e,disabled:A,transform:t,soup:i,cancelPanDrag:n,onCreateEditEvent:o,onModifyEditEvent:s})=>{t||(t=ba());const r=AA.useRef(null),[a,g]=AA.useState(null),[c,I]=AA.useState(null),l=a!==null;rl(h=>h.in_edit_mode);const B=rl(h=>h.in_move_footprint_mode),C=rl(h=>h.setIsMovingComponent),Q=A||!B;return Z.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=Ct(Xy(t),{x:u,y:d});let m=!1;for(const w of i)if(w.type==="pcb_component"&&u$e(w,f,10/t.a)){n(),g(w.pcb_component_id),m=!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(m||g(null),m)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=Ct(Xy(t),{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:[e,!Q&&i.filter(h=>h.type==="pcb_component").map(h=>{if(!h?.center)return null;const E=Ct(t,h.center);return Z.jsx("div",{style:{position:"absolute",pointerEvents:"none",left:E.x,top:E.y,width:h.width*t.a+20,height:h.height*t.a+20,transform:"translate(-50%, -50%)",background:l&&a===h.pcb_component_id?"rgba(255, 0, 0, 0.2)":""}},h.pcb_component_id)})]})},p$e=({hotkeys:e})=>(AA.useEffect(()=>{const A=t=>{e.forEach(i=>{t.key===i.key&&i.onUse()})};return window.addEventListener("keydown",A),()=>{window.removeEventListener("keydown",A)}},[e]),Z.jsx("div",{className:a1`
5433
5433
  display: flex;
5434
5434
  flex-direction: column;
5435
5435
  font-family: sans-serif;
@@ -5468,7 +5468,7 @@ $1`).replace(/>(\s*)(?=<!--\s*\/)/g,"> ")}}});function lQt(e,A,t){if(!A||!t)retu
5468
5468
  transition: opacity 0.2s;
5469
5469
  margin-bottom: 10px;
5470
5470
  color: red;
5471
- `,S$e=({children:e,transform:A=ba(),elements:t})=>{const i=AA.useRef(null),{isShowingDRCErrors:n,hoveredErrorId:o}=rl(g=>({isShowingDRCErrors:g.is_showing_drc_errors,hoveredErrorId:g.hovered_error_id}));if(!t)return Z.jsx("div",{style:{position:"relative"},ref:i,children:e});const s=t.filter(g=>g.type==="pcb_trace_error"),r=t.filter(g=>g.type==="pcb_trace_error"&&g.message?.includes("Multiple components found with name")),a=new Map;return t.forEach(g=>{g.type==="pcb_port"&&a.set(g.pcb_port_id,g)}),Z.jsxs("div",{style:{position:"relative"},ref:i,children:[e,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=t?Xb(t).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=Ct(A,{x:B.x,y:B.y}),d=Ct(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)),m={x:(u.x+d.x)/2,y:(u.y+d.y)/2};if(isNaN(m.x)||isNaN(m.y))return null;const w=QyA(m,i);return Z.jsxs(AA.Fragment,{children:[Z.jsx(w$e,{screenPort1:u,screenPort2:d,errorCenter:m,canLineBeDrawn:f,isHighlighted:E}),Z.jsx("div",{style:{position:"absolute",left:m.x-15,top:m.y-15,width:30,height:30,zIndex:xc.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")}}}}),Z.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:Z.jsx("div",{className:`error-message ${hyA}`,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=>Ct(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],m=QyA(f,i);return Z.jsxs(AA.Fragment,{children:[Z.jsx(D$e,{points:u,errorCenter:f,isHighlighted:E}),Z.jsx("div",{style:{position:"absolute",left:f.x-15,top:f.y-15,width:30,height:30,zIndex:xc.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")}}}}),Z.jsx("div",{style:{position:"absolute",zIndex:E?xc.errorOverlay+10:xc.errorOverlay+1,left:m.left,top:m.top,color:E?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:"flex",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:m.transform},children:Z.jsx("div",{className:`error-message ${hyA}`,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=t?.filter(Q=>Q.type==="source_component"&&Q.name===I||Q.type==="pcb_component"&&t?.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 _=t?.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=Ct(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=QyA(u,i);return Z.jsxs(AA.Fragment,{children:[Z.jsx("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none",mixBlendMode:"difference",zIndex:xc.errorOverlay},width:"100%",height:"100%",children:C?Z.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"}):Z.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})}),Z.jsx("div",{style:{position:"absolute",left:u.x-(D+10),top:u.y-(D+10),width:(D+10)*2,height:(D+10)*2,zIndex:xc.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:_=>{const b=_.currentTarget.nextElementSibling;if(b){const R=b.querySelector(".error-message");R&&(R.style.opacity="1")}},onMouseLeave:_=>{if(!C){const b=_.currentTarget.nextElementSibling;if(b){const R=b.querySelector(".error-message");R&&(R.style.opacity="0")}}}}),Z.jsx("div",{style:{position:"absolute",zIndex:C?xc.errorOverlay+20:xc.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:Z.jsx("div",{className:`error-message ${hyA}`,style:{opacity:C?1:0,border:`1px solid ${C?"#ff4444":"red"}`},children:g.message})})]},`${B}_${h}`)})})]})};function b$e(e,A){return e.size!==A.size?!1:Array.from(e).every(t=>A.has(t))}function x$e({primitiveElement:e,elements:A}){let t=e.trace_length?`${e.trace_length.toFixed(3)}`:"";const i=Xb(A).source_trace.get(e?.source_trace_id);if(i?.display_name&&(i?.max_length?t+=` / ${i.max_length}mm `:t+=" mm ",t+=`(${i.display_name})`),!t)return null;const n=e.trace_length&&i?.max_length&&e.trace_length>i.max_length;return{text:t,isOverLength:n}}function _$e(e){const{primitives:A,is_showing_multiple_traces_length:t,elements:i}=e,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(!t)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 k$e={position:"absolute",left:0,top:0,pointerEvents:"none",color:"red",fontFamily:"sans-serif",fontSize:12,textShadow:"0 0 2px black"},v$e=e=>{const{_element:A,_parent_pcb_component:t,_parent_source_component:i,_source_port:n}=e;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""}},F$e={top:"red",bottom:"aqua"},M$e=({primitive:e,mousePos:A,elements:t})=>{const[i,n]=AA.useState(!1),o=e._element;AA.useEffect(()=>{setTimeout(()=>{n(!0)},100)},[]);const[s,r,a,g]=[e.screen_x,e.screen_y,e.screen_w,e.screen_h],c=e.same_space_index??0,I=26,l=F$e[e?._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 e||o.type==="pcb_plated_hole"&&(o?.shape==="pill"||o?.shape==="oval")&&"ccw_rotation"in e)&&(B=o.ccw_rotation??0),o.type==="pcb_trace"){const h=x$e({primitiveElement:o,elements:t});if(!h)return null;const E=A.y-35;return Z.jsx("div",{style:{zIndex:xc.elementOverlay,position:"absolute",left:A.x,top:E,color:l,pointerEvents:"none",transform:"translateX(-50%)"},children:Z.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=v$e(e);return C.trim().length===0?null:Z.jsx("div",{style:{zIndex:xc.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:Z.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:Z.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})})})},G$e=({highlightedPrimitives:e,mousePos:A,elements:t})=>{const[i,n]=rl(r=>[r.is_moving_component,r.is_showing_multiple_traces_length]),o=e.some(r=>r._element.type==="pcb_smtpad")&&e.some(r=>r._element.type==="pcb_trace");let s=e;return o&&(s=s.filter(r=>r._element.type==="pcb_smtpad")),s=_$e({primitives:s,is_showing_multiple_traces_length:n,elements:t}),Z.jsx("div",{style:k$e,children:!i&&s.map((r,a)=>Z.jsx(M$e,{primitive:r,mousePos:A,elements:t},a))})},Rk=e=>e?.type==="pcb_component",JQt=e=>e?.type==="pcb_group",R$e=e=>e?.type==="pcb_panel",EyA=e=>e?.type==="pcb_board",rI={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},ey={OFFSET_LINE:"white",COMPONENT_MARKER_FILL:"#66ccff",COMPONENT_MARKER_STROKE:"white",LABEL_TEXT:"white"},uyA=({targets:e,transform:A,containerWidth:t,containerHeight:i})=>{if(e.length===0)return null;const n={color:ey.LABEL_TEXT,mixBlendMode:"difference",pointerEvents:"none",fontSize:rI.LABEL_FONT_SIZE,fontFamily:"monospace",fontWeight:"bold"},o=new Map;return e.forEach(s=>{if(!o.has(s.anchor_id)){const r=Ct(A,s.anchor);o.set(s.anchor_id,r)}}),Z.jsx("div",{style:{position:"absolute",left:0,top:0,width:t,height:i,overflow:"hidden",pointerEvents:"none",zIndex:xc.dimensionOverlay},children:Z.jsxs("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none"},width:t,height:i,children:[e.map(s=>{const r=s.anchor,a=s.anchor_id,g=s.target,c=o.get(a),I=Ct(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?rI.LABEL_OFFSET_ABOVE:rI.LABEL_OFFSET_BELOW,d=E?rI.LABEL_OFFSET_RIGHT:rI.LABEL_OFFSET_LEFT,f=C>rI.MIN_LINE_LENGTH_FOR_LABEL,m=Q>rI.MIN_LINE_LENGTH_FOR_LABEL,w=`${s.display_offset_x??l.toFixed(2)}mm`,D=`${s.display_offset_y??B.toFixed(2)}mm`;return Z.jsxs("g",{children:[Z.jsx("line",{x1:c.x,y1:c.y,x2:I.x,y2:c.y,stroke:ey.OFFSET_LINE,strokeWidth:rI.LINE_STROKE_WIDTH,strokeDasharray:rI.LINE_DASH_PATTERN}),Z.jsx("line",{x1:I.x,y1:c.y,x2:I.x,y2:I.y,stroke:ey.OFFSET_LINE,strokeWidth:rI.LINE_STROKE_WIDTH,strokeDasharray:rI.LINE_DASH_PATTERN}),s.type==="component"||s.type==="board"?Z.jsx("circle",{cx:I.x,cy:I.y,r:rI.COMPONENT_MARKER_RADIUS,fill:ey.COMPONENT_MARKER_FILL,stroke:ey.COMPONENT_MARKER_STROKE,strokeWidth:1}):Z.jsxs(Z.Fragment,{children:[Z.jsx("line",{x1:I.x-rI.ANCHOR_MARKER_SIZE,y1:I.y,x2:I.x+rI.ANCHOR_MARKER_SIZE,y2:I.y,stroke:ey.OFFSET_LINE,strokeWidth:rI.ANCHOR_MARKER_STROKE_WIDTH}),Z.jsx("line",{x1:I.x,y1:I.y-rI.ANCHOR_MARKER_SIZE,x2:I.x,y2:I.y+rI.ANCHOR_MARKER_SIZE,stroke:ey.OFFSET_LINE,strokeWidth:rI.ANCHOR_MARKER_STROKE_WIDTH})]}),f&&Z.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:Z.jsx("div",{style:{...n,textAlign:"center"},children:w})}),m&&Z.jsx("foreignObject",{x:I.x+d,y:Math.min(c.y,I.y),width:rI.Y_LABEL_MIN_WIDTH,height:Math.abs(I.y-c.y),style:{overflow:"visible"},children:Z.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])=>Z.jsxs("g",{children:[Z.jsx("line",{x1:r.x-rI.ANCHOR_MARKER_SIZE,y1:r.y,x2:r.x+rI.ANCHOR_MARKER_SIZE,y2:r.y,stroke:ey.OFFSET_LINE,strokeWidth:rI.ANCHOR_MARKER_STROKE_WIDTH}),Z.jsx("line",{x1:r.x,y1:r.y-rI.ANCHOR_MARKER_SIZE,x2:r.x,y2:r.y+rI.ANCHOR_MARKER_SIZE,stroke:ey.OFFSET_LINE,strokeWidth:rI.ANCHOR_MARKER_STROKE_WIDTH})]},`anchor-${s}`))]})})},N$e=({elements:e,highlightedPrimitives:A,transform:t,containerWidth:i,containerHeight:n})=>{const o=e.filter(E=>EyA(E)),s=e.filter(E=>Rk(E)),r=e.filter(E=>JQt(E)),a=A.map(E=>Rk(E._parent_pcb_component)?E._parent_pcb_component.pcb_component_id:Rk(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)}),!rl(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 Z.jsx(uyA,{targets:h,transform:t,containerWidth:i,containerHeight:n})},L$e=({elements:e,highlightedPrimitives:A,transform:t,containerWidth:i,containerHeight:n})=>{const o=e.filter(E=>JQt(E)),s=e.filter(E=>Rk(E)),r=A.map(E=>Rk(E._parent_pcb_component)?E._parent_pcb_component.pcb_component_id:Rk(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))}),!rl(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 Z.jsx(uyA,{targets:h,transform:t,containerWidth:i,containerHeight:n})},U$e=(e,A)=>{const t=e.pcb_component_id,i=A.filter(n=>(n.type==="pcb_smtpad"||n.type==="pcb_plated_hole")&&n.pcb_component_id===t||n.type==="pcb_hole"&&n.pcb_component_id===t);return i.length===0?ByA([e]):ByA(i)},H$e=({elements:e,highlightedPrimitives:A,transform:t,containerWidth:i,containerHeight:n})=>{const o=new Map;for(const r of A)Rk(r._parent_pcb_component)&&o.set(r._parent_pcb_component.pcb_component_id,r._parent_pcb_component),Rk(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=U$e(r,e);if(!a)continue;const g=r.positioned_relative_to_pcb_group_id??r.pcb_group_id,c=g?Xb(e).pcb_group.get(g):null;s.push({component:r,bbox:a,group:c})}return s.length===0?null:Z.jsx("div",{style:{position:"absolute",left:0,top:0,width:i,height:n,overflow:"hidden",pointerEvents:"none",zIndex:xc.dimensionOverlay},children:Z.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=Ct(t,{x:a.minX,y:a.maxY}),I=Ct(t,{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=Ct(t,B);return Z.jsxs("g",{children:[Z.jsx("rect",{x:l.x,y:l.y,width:l.width,height:l.height,fill:"none",stroke:"white",strokeWidth:1.5,strokeDasharray:"4,4"}),Z.jsx("line",{x1:C.x-6,y1:C.y,x2:C.x+6,y2:C.y,stroke:ey.COMPONENT_MARKER_STROKE,strokeWidth:1.5}),Z.jsx("line",{x1:C.x,y1:C.y-6,x2:C.x,y2:C.y+6,stroke:ey.COMPONENT_MARKER_STROKE,strokeWidth:1.5}),Z.jsx("circle",{cx:C.x,cy:C.y,r:rI.COMPONENT_MARKER_RADIUS,fill:ey.COMPONENT_MARKER_FILL,stroke:ey.COMPONENT_MARKER_STROKE,strokeWidth:1})]},r.pcb_component_id)})})})},Y$e=({elements:e,highlightedPrimitives:A,transform:t,containerWidth:i,containerHeight:n})=>{const o=e.filter(B=>R$e(B)),s=e.filter(B=>EyA(B)),r=A.map(B=>EyA(B._element)?B._element.pcb_board_id:null).filter(B=>!!B);if(!rl(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 Z.jsx(uyA,{targets:l,transform:t,containerWidth:i,containerHeight:n})},Zj=e=>{if(e.length===0)return null;let A=e[0].x,t=e[0].y,i=e[0].x,n=e[0].y;for(const o of e)o.x<A&&(A=o.x),o.y<t&&(t=o.y),o.x>i&&(i=o.x),o.y>n&&(n=o.y);return{center:{x:(A+i)/2,y:(t+n)/2},width:i-A,height:n-t}},TQt=(e,A)=>{if(A.length<3)return!1;let t=!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>e.y!=a>e.y&&e.x<(r-o)*(e.y-s)/(a-s||Number.EPSILON)+o&&(t=!t)}return t},J$e=(e,A,t)=>{const i=[];for(const n of e){if(!n._element)continue;if("x1"in n&&n._element?.type==="pcb_trace"){const r=KE({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)/t.a;r<g&&i.push(n);continue}if(n.pcb_drawing_type==="polygon"){const r=n.points.map(g=>({x:Ee.parse(g.x),y:Ee.parse(g.y)})),a=Zj(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;TQt(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:Ee.parse(g.x),y:Ee.parse(g.y)})),a=Zj(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;TQt(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},T$e=({elements:e,children:A,transform:t,primitives:i,onMouseHoverOverPrimitives:n})=>{const[o,s]=AA.useState([]),[r,a]=AA.useState({x:0,y:0}),[g,{width:c,height:I}]=yT(),l=AA.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=Zj(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=Zj(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=Ct(t,h),f={w:E*t.a,h:u*t.a},m=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:m})}return C},[o,t]),B=(C,Q,h,E)=>{a({x:C,y:Q});const u=Ct(Xy(h),{x:C,y:Q}),d=J$e(E,u,h);b$e(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 Z.jsxs("div",{ref:g,style:{position:"relative",width:"100%",height:"100%"},onMouseMove:C=>{if(t){const Q=C.currentTarget.getBoundingClientRect(),h=C.clientX-Q.left,E=C.clientY-Q.top;B(h,E,t,i)}},onTouchStart:C=>{if(t){const Q=C.touches[0],h=C.currentTarget.getBoundingClientRect(),E=Q.clientX-h.left,u=Q.clientY-h.top;B(E,u,t,i)}},children:[A,Z.jsx(G$e,{elements:e,mousePos:r,highlightedPrimitives:l}),t&&Z.jsxs(Z.Fragment,{children:[Z.jsx(N$e,{elements:e,highlightedPrimitives:l,transform:t,containerWidth:c,containerHeight:I}),Z.jsx(L$e,{elements:e,highlightedPrimitives:l,transform:t,containerWidth:c,containerHeight:I}),Z.jsx(H$e,{elements:e,highlightedPrimitives:l,transform:t,containerWidth:c,containerHeight:I}),Z.jsx(Y$e,{elements:e,highlightedPrimitives:l,transform:t,containerWidth:c,containerHeight:I})]})]})},PQt=["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)"],P$e=({children:e,transform:A=ba(),elements:t=[],hoveredComponentIds:i=[]})=>{const[n,{width:o,height:s}]=yT(),r=AA.useRef(null),{is_showing_pcb_groups:a,pcb_group_view_mode:g,is_showing_group_anchor_offsets:c}=rl(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 AA.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=t.filter(w=>w.type==="pcb_group"),C=t.filter(w=>w.type==="pcb_component"),Q=t.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},m=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&&m.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),OA=B.filter(_A=>_A.source_group_id&&JA.includes(_A.source_group_id));for(const _A of OA){const DA=C.filter(NA=>NA.pcb_group_id===_A.pcb_group_id);S=[...S,...DA]}}let _,b,R,F,H=!1;if(w.center&&w.width&&w.height){H=!0;const JA=w.width/2,OA=w.height/2;_=w.center.x-JA,R=w.center.x+JA,b=w.center.y-OA,F=w.center.y+OA}else if(S.length===0||(_=1/0,b=1/0,R=-1/0,F=-1/0,S.forEach(JA=>{if(JA.center&&typeof JA.width=="number"&&typeof JA.height=="number"){const OA=JA.center.x-JA.width/2,_A=JA.center.x+JA.width/2,DA=JA.center.y+JA.height/2,NA=JA.center.y-JA.height/2;_=Math.min(_,OA),R=Math.max(R,_A),b=Math.min(b,NA),F=Math.max(F,DA)}}),_===1/0||R===-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(!H){const _A=1+(J?.5:0);_-=_A,R+=_A,b-=_A,F+=_A}const O=Ct(A,{x:_,y:F}),W=Ct(A,{x:R,y:F}),z=Ct(A,{x:_,y:b}),tA=Ct(A,{x:R,y:b}),aA=PQt[D%PQt.length];l.strokeStyle=aA,l.lineWidth=2;const eA=Math.max(4,Math.min(12,8*Math.abs(A.a))),oA=Math.max(2,Math.min(6,4*Math.abs(A.a))),lA=eA*(J?1.3:1),pA=oA;l.setLineDash([lA,pA]),l.beginPath(),l.moveTo(O.x,O.y),l.lineTo(W.x,W.y),l.lineTo(tA.x,tA.y),l.lineTo(z.x,z.y),l.closePath(),l.stroke();const kA=Math.max(8,Math.min(12,10*Math.abs(A.a))),MA=Y==0||Y==1?0:Y*.11,YA=kA*(1-MA),EA=4,xA=w.name||`Group ${D+1}`;l.font=`${YA}px sans-serif`,l.setLineDash([]);const WA=l.measureText(xA).width+EA*2,jA=YA+EA*2,It=O.x-5,mA=O.y-5,gt=3;if(l.fillStyle="rgba(0, 0, 0, 0.8)",l.beginPath(),l.roundRect(It,mA-jA,WA,jA,gt),l.fill(),l.fillStyle=aA,l.textAlign="left",l.textBaseline="middle",l.fillText(xA,It+EA,mA-jA/2),c&&m.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},OA=Ct(A,JA);l.strokeStyle="white",l.lineWidth=1.5,l.setLineDash([]);const _A=Math.max(4,Math.min(8,6*Math.abs(A.a)));l.beginPath(),l.moveTo(OA.x-_A,OA.y),l.lineTo(OA.x+_A,OA.y),l.stroke(),l.beginPath(),l.moveTo(OA.x,OA.y-_A),l.lineTo(OA.x,OA.y+_A),l.stroke()}})},[t,A,o,s,a,g,c,i]),Z.jsxs("div",{ref:n,style:{position:"relative",width:"100%",height:"100%"},children:[e,Z.jsx("canvas",{ref:r,style:{position:"absolute",top:0,left:0,pointerEvents:"none",zIndex:xc.pcbGroupOverlay,display:a?"block":"none"}})]})},K$e=({transform:e,soup:A,children:t})=>{const i=rl(r=>r.is_showing_rats_nest),{netMap:n,idToNetMap:o}=AA.useMemo(()=>pQt(A||[]),[A]),s=AA.useMemo(()=>{if(!A||!i)return[];const r=l=>{const B=Xb(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=Xb(A).pcb_port.list(),c=Xb(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?t:(e||(e=ba()),Z.jsxs("div",{style:{position:"relative"},children:[t,Z.jsx("svg",{style:{position:"absolute",left:0,top:0,width:"100%",height:"100%",pointerEvents:"none",opacity:.5,zIndex:xc.ratsNestOverlay},children:s.map(({key:r,startPoint:a,endPoint:g,isInNet:c})=>{const I=Ct(e,a),l=Ct(e,g);return Z.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)})})]}))},q$e={version:"1.11.354"},Nk=(e,A,t)=>{const i=rl(s=>s.is_mouse_over_container),n=AA.useRef(i),o=AA.useRef(A);AA.useEffect(()=>{n.current=i},[i]),AA.useEffect(()=>{o.current=A},[A]),AA.useEffect(()=>{if(!e)return;const s=r=>{const a=r.target;if(a.tagName==="INPUT"||a.tagName==="TEXTAREA"||a.isContentEditable)return;const g=e.split("+"),c=g.includes("ctrl"),I=g.includes("shift"),l=g.includes("alt"),B=g.includes("meta"),C=g[g.length-1],Q=t?.current?t.current.contains(document.activeElement)||document.activeElement===t.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)}},[e])},O$e=()=>{const[e,A]=AA.useState(!1);return AA.useEffect(()=>{const t=()=>{A(window.innerWidth<=768)};return t(),window.addEventListener("resize",t),()=>window.removeEventListener("resize",t)},[]),e},wT=(e,A={stopPropagation:!0})=>{const t=AA.useRef(0),i=AA.useCallback(s=>{A.stopPropagation&&s.stopPropagation();const r=Date.now();r-t.current<300||(t.current=r,e?.(s))},[e,A.stopPropagation]),n=AA.useCallback(s=>{s.preventDefault(),i(s)},[i]);return{onClick:i,onTouchEnd:n,style:{touchAction:"manipulation"}}},W$e=({name:e,selected:A,onClick:t})=>{const{style:i,...n}=wT(t);return Z.jsxs("div",{className:a1`
5471
+ `,S$e=({children:e,transform:A=ba(),elements:t})=>{const i=AA.useRef(null),{isShowingDRCErrors:n,hoveredErrorId:o}=rl(g=>({isShowingDRCErrors:g.is_showing_drc_errors,hoveredErrorId:g.hovered_error_id}));if(!t)return Z.jsx("div",{style:{position:"relative"},ref:i,children:e});const s=t.filter(g=>g.type==="pcb_trace_error"),r=t.filter(g=>g.type==="pcb_trace_error"&&g.message?.includes("Multiple components found with name")),a=new Map;return t.forEach(g=>{g.type==="pcb_port"&&a.set(g.pcb_port_id,g)}),Z.jsxs("div",{style:{position:"relative"},ref:i,children:[e,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=t?Xb(t).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=Ct(A,{x:B.x,y:B.y}),d=Ct(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)),m={x:(u.x+d.x)/2,y:(u.y+d.y)/2};if(isNaN(m.x)||isNaN(m.y))return null;const w=QyA(m,i);return Z.jsxs(AA.Fragment,{children:[Z.jsx(w$e,{screenPort1:u,screenPort2:d,errorCenter:m,canLineBeDrawn:f,isHighlighted:E}),Z.jsx("div",{style:{position:"absolute",left:m.x-15,top:m.y-15,width:30,height:30,zIndex:xc.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")}}}}),Z.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:Z.jsx("div",{className:`error-message ${hyA}`,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=>Ct(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],m=QyA(f,i);return Z.jsxs(AA.Fragment,{children:[Z.jsx(D$e,{points:u,errorCenter:f,isHighlighted:E}),Z.jsx("div",{style:{position:"absolute",left:f.x-15,top:f.y-15,width:30,height:30,zIndex:xc.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")}}}}),Z.jsx("div",{style:{position:"absolute",zIndex:E?xc.errorOverlay+10:xc.errorOverlay+1,left:m.left,top:m.top,color:E?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:"flex",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:m.transform},children:Z.jsx("div",{className:`error-message ${hyA}`,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=t?.filter(Q=>Q.type==="source_component"&&Q.name===I||Q.type==="pcb_component"&&t?.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 _=t?.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=Ct(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=QyA(u,i);return Z.jsxs(AA.Fragment,{children:[Z.jsx("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none",mixBlendMode:"difference",zIndex:xc.errorOverlay},width:"100%",height:"100%",children:C?Z.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"}):Z.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})}),Z.jsx("div",{style:{position:"absolute",left:u.x-(D+10),top:u.y-(D+10),width:(D+10)*2,height:(D+10)*2,zIndex:xc.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:_=>{const b=_.currentTarget.nextElementSibling;if(b){const R=b.querySelector(".error-message");R&&(R.style.opacity="1")}},onMouseLeave:_=>{if(!C){const b=_.currentTarget.nextElementSibling;if(b){const R=b.querySelector(".error-message");R&&(R.style.opacity="0")}}}}),Z.jsx("div",{style:{position:"absolute",zIndex:C?xc.errorOverlay+20:xc.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:Z.jsx("div",{className:`error-message ${hyA}`,style:{opacity:C?1:0,border:`1px solid ${C?"#ff4444":"red"}`},children:g.message})})]},`${B}_${h}`)})})]})};function b$e(e,A){return e.size!==A.size?!1:Array.from(e).every(t=>A.has(t))}function x$e({primitiveElement:e,elements:A}){let t=e.trace_length?`${e.trace_length.toFixed(3)}`:"";const i=Xb(A).source_trace.get(e?.source_trace_id);if(i?.display_name&&(i?.max_length?t+=` / ${i.max_length}mm `:t+=" mm ",t+=`(${i.display_name})`),!t)return null;const n=e.trace_length&&i?.max_length&&e.trace_length>i.max_length;return{text:t,isOverLength:n}}function _$e(e){const{primitives:A,is_showing_multiple_traces_length:t,elements:i}=e,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(!t)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 k$e={position:"absolute",left:0,top:0,pointerEvents:"none",color:"red",fontFamily:"sans-serif",fontSize:12,textShadow:"0 0 2px black"},v$e=e=>{const{_element:A,_parent_pcb_component:t,_parent_source_component:i,_source_port:n}=e;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""}},F$e={top:"red",bottom:"aqua"},M$e=({primitive:e,mousePos:A,elements:t})=>{const[i,n]=AA.useState(!1),o=e._element;AA.useEffect(()=>{setTimeout(()=>{n(!0)},100)},[]);const[s,r,a,g]=[e.screen_x,e.screen_y,e.screen_w,e.screen_h],c=e.same_space_index??0,I=26,l=F$e[e?._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 e||o.type==="pcb_plated_hole"&&(o?.shape==="pill"||o?.shape==="oval")&&"ccw_rotation"in e)&&(B=o.ccw_rotation??0),o.type==="pcb_trace"){const h=x$e({primitiveElement:o,elements:t});if(!h)return null;const E=A.y-35;return Z.jsx("div",{style:{zIndex:xc.elementOverlay,position:"absolute",left:A.x,top:E,color:l,pointerEvents:"none",transform:"translateX(-50%)"},children:Z.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=v$e(e);return C.trim().length===0?null:Z.jsx("div",{style:{zIndex:xc.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:Z.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:Z.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})})})},G$e=({highlightedPrimitives:e,mousePos:A,elements:t})=>{const[i,n]=rl(r=>[r.is_moving_component,r.is_showing_multiple_traces_length]),o=e.some(r=>r._element.type==="pcb_smtpad")&&e.some(r=>r._element.type==="pcb_trace");let s=e;return o&&(s=s.filter(r=>r._element.type==="pcb_smtpad")),s=_$e({primitives:s,is_showing_multiple_traces_length:n,elements:t}),Z.jsx("div",{style:k$e,children:!i&&s.map((r,a)=>Z.jsx(M$e,{primitive:r,mousePos:A,elements:t},a))})},Rk=e=>e?.type==="pcb_component",JQt=e=>e?.type==="pcb_group",R$e=e=>e?.type==="pcb_panel",EyA=e=>e?.type==="pcb_board",rI={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},ey={OFFSET_LINE:"white",COMPONENT_MARKER_FILL:"#66ccff",COMPONENT_MARKER_STROKE:"white",LABEL_TEXT:"white"},uyA=({targets:e,transform:A,containerWidth:t,containerHeight:i})=>{if(e.length===0)return null;const n={color:ey.LABEL_TEXT,mixBlendMode:"difference",pointerEvents:"none",fontSize:rI.LABEL_FONT_SIZE,fontFamily:"monospace",fontWeight:"bold"},o=new Map;return e.forEach(s=>{if(!o.has(s.anchor_id)){const r=Ct(A,s.anchor);o.set(s.anchor_id,r)}}),Z.jsx("div",{style:{position:"absolute",left:0,top:0,width:t,height:i,overflow:"hidden",pointerEvents:"none",zIndex:xc.dimensionOverlay},children:Z.jsxs("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none"},width:t,height:i,children:[e.map(s=>{const r=s.anchor,a=s.anchor_id,g=s.target,c=o.get(a),I=Ct(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?rI.LABEL_OFFSET_ABOVE:rI.LABEL_OFFSET_BELOW,d=E?rI.LABEL_OFFSET_RIGHT:rI.LABEL_OFFSET_LEFT,f=C>rI.MIN_LINE_LENGTH_FOR_LABEL,m=Q>rI.MIN_LINE_LENGTH_FOR_LABEL,w=`${s.display_offset_x??l.toFixed(2)}mm`,D=`${s.display_offset_y??B.toFixed(2)}mm`;return Z.jsxs("g",{children:[Z.jsx("line",{x1:c.x,y1:c.y,x2:I.x,y2:c.y,stroke:ey.OFFSET_LINE,strokeWidth:rI.LINE_STROKE_WIDTH,strokeDasharray:rI.LINE_DASH_PATTERN}),Z.jsx("line",{x1:I.x,y1:c.y,x2:I.x,y2:I.y,stroke:ey.OFFSET_LINE,strokeWidth:rI.LINE_STROKE_WIDTH,strokeDasharray:rI.LINE_DASH_PATTERN}),s.type==="component"||s.type==="board"?Z.jsx("circle",{cx:I.x,cy:I.y,r:rI.COMPONENT_MARKER_RADIUS,fill:ey.COMPONENT_MARKER_FILL,stroke:ey.COMPONENT_MARKER_STROKE,strokeWidth:1}):Z.jsxs(Z.Fragment,{children:[Z.jsx("line",{x1:I.x-rI.ANCHOR_MARKER_SIZE,y1:I.y,x2:I.x+rI.ANCHOR_MARKER_SIZE,y2:I.y,stroke:ey.OFFSET_LINE,strokeWidth:rI.ANCHOR_MARKER_STROKE_WIDTH}),Z.jsx("line",{x1:I.x,y1:I.y-rI.ANCHOR_MARKER_SIZE,x2:I.x,y2:I.y+rI.ANCHOR_MARKER_SIZE,stroke:ey.OFFSET_LINE,strokeWidth:rI.ANCHOR_MARKER_STROKE_WIDTH})]}),f&&Z.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:Z.jsx("div",{style:{...n,textAlign:"center"},children:w})}),m&&Z.jsx("foreignObject",{x:I.x+d,y:Math.min(c.y,I.y),width:rI.Y_LABEL_MIN_WIDTH,height:Math.abs(I.y-c.y),style:{overflow:"visible"},children:Z.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])=>Z.jsxs("g",{children:[Z.jsx("line",{x1:r.x-rI.ANCHOR_MARKER_SIZE,y1:r.y,x2:r.x+rI.ANCHOR_MARKER_SIZE,y2:r.y,stroke:ey.OFFSET_LINE,strokeWidth:rI.ANCHOR_MARKER_STROKE_WIDTH}),Z.jsx("line",{x1:r.x,y1:r.y-rI.ANCHOR_MARKER_SIZE,x2:r.x,y2:r.y+rI.ANCHOR_MARKER_SIZE,stroke:ey.OFFSET_LINE,strokeWidth:rI.ANCHOR_MARKER_STROKE_WIDTH})]},`anchor-${s}`))]})})},N$e=({elements:e,highlightedPrimitives:A,transform:t,containerWidth:i,containerHeight:n})=>{const o=e.filter(E=>EyA(E)),s=e.filter(E=>Rk(E)),r=e.filter(E=>JQt(E)),a=A.map(E=>Rk(E._parent_pcb_component)?E._parent_pcb_component.pcb_component_id:Rk(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)}),!rl(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 Z.jsx(uyA,{targets:h,transform:t,containerWidth:i,containerHeight:n})},L$e=({elements:e,highlightedPrimitives:A,transform:t,containerWidth:i,containerHeight:n})=>{const o=e.filter(E=>JQt(E)),s=e.filter(E=>Rk(E)),r=A.map(E=>Rk(E._parent_pcb_component)?E._parent_pcb_component.pcb_component_id:Rk(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))}),!rl(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 Z.jsx(uyA,{targets:h,transform:t,containerWidth:i,containerHeight:n})},U$e=(e,A)=>{const t=e.pcb_component_id,i=A.filter(n=>(n.type==="pcb_smtpad"||n.type==="pcb_plated_hole")&&n.pcb_component_id===t||n.type==="pcb_hole"&&n.pcb_component_id===t);return i.length===0?ByA([e]):ByA(i)},H$e=({elements:e,highlightedPrimitives:A,transform:t,containerWidth:i,containerHeight:n})=>{const o=new Map;for(const r of A)Rk(r._parent_pcb_component)&&o.set(r._parent_pcb_component.pcb_component_id,r._parent_pcb_component),Rk(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=U$e(r,e);if(!a)continue;const g=r.positioned_relative_to_pcb_group_id??r.pcb_group_id,c=g?Xb(e).pcb_group.get(g):null;s.push({component:r,bbox:a,group:c})}return s.length===0?null:Z.jsx("div",{style:{position:"absolute",left:0,top:0,width:i,height:n,overflow:"hidden",pointerEvents:"none",zIndex:xc.dimensionOverlay},children:Z.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=Ct(t,{x:a.minX,y:a.maxY}),I=Ct(t,{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=Ct(t,B);return Z.jsxs("g",{children:[Z.jsx("rect",{x:l.x,y:l.y,width:l.width,height:l.height,fill:"none",stroke:"white",strokeWidth:1.5,strokeDasharray:"4,4"}),Z.jsx("line",{x1:C.x-6,y1:C.y,x2:C.x+6,y2:C.y,stroke:ey.COMPONENT_MARKER_STROKE,strokeWidth:1.5}),Z.jsx("line",{x1:C.x,y1:C.y-6,x2:C.x,y2:C.y+6,stroke:ey.COMPONENT_MARKER_STROKE,strokeWidth:1.5}),Z.jsx("circle",{cx:C.x,cy:C.y,r:rI.COMPONENT_MARKER_RADIUS,fill:ey.COMPONENT_MARKER_FILL,stroke:ey.COMPONENT_MARKER_STROKE,strokeWidth:1})]},r.pcb_component_id)})})})},Y$e=({elements:e,highlightedPrimitives:A,transform:t,containerWidth:i,containerHeight:n})=>{const o=e.filter(B=>R$e(B)),s=e.filter(B=>EyA(B)),r=A.map(B=>EyA(B._element)?B._element.pcb_board_id:null).filter(B=>!!B);if(!rl(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 Z.jsx(uyA,{targets:l,transform:t,containerWidth:i,containerHeight:n})},Zj=e=>{if(e.length===0)return null;let A=e[0].x,t=e[0].y,i=e[0].x,n=e[0].y;for(const o of e)o.x<A&&(A=o.x),o.y<t&&(t=o.y),o.x>i&&(i=o.x),o.y>n&&(n=o.y);return{center:{x:(A+i)/2,y:(t+n)/2},width:i-A,height:n-t}},TQt=(e,A)=>{if(A.length<3)return!1;let t=!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>e.y!=a>e.y&&e.x<(r-o)*(e.y-s)/(a-s||Number.EPSILON)+o&&(t=!t)}return t},J$e=(e,A,t)=>{const i=[];for(const n of e){if(!n._element)continue;if("x1"in n&&n._element?.type==="pcb_trace"){const r=KE({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)/t.a;r<g&&i.push(n);continue}if(n.pcb_drawing_type==="polygon"){const r=n.points.map(g=>({x:Ee.parse(g.x),y:Ee.parse(g.y)})),a=Zj(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;TQt(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:Ee.parse(g.x),y:Ee.parse(g.y)})),a=Zj(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;TQt(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},T$e=({elements:e,children:A,transform:t,primitives:i,onMouseHoverOverPrimitives:n})=>{const[o,s]=AA.useState([]),[r,a]=AA.useState({x:0,y:0}),[g,{width:c,height:I}]=yT(),l=AA.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=Zj(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=Zj(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=Ct(t,h),f={w:E*t.a,h:u*t.a},m=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:m})}return C},[o,t]),B=(C,Q,h,E)=>{a({x:C,y:Q});const u=Ct(Xy(h),{x:C,y:Q}),d=J$e(E,u,h);b$e(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 Z.jsxs("div",{ref:g,style:{position:"relative",width:"100%",height:"100%"},onMouseMove:C=>{if(t){const Q=C.currentTarget.getBoundingClientRect(),h=C.clientX-Q.left,E=C.clientY-Q.top;B(h,E,t,i)}},onTouchStart:C=>{if(t){const Q=C.touches[0],h=C.currentTarget.getBoundingClientRect(),E=Q.clientX-h.left,u=Q.clientY-h.top;B(E,u,t,i)}},children:[A,Z.jsx(G$e,{elements:e,mousePos:r,highlightedPrimitives:l}),t&&Z.jsxs(Z.Fragment,{children:[Z.jsx(N$e,{elements:e,highlightedPrimitives:l,transform:t,containerWidth:c,containerHeight:I}),Z.jsx(L$e,{elements:e,highlightedPrimitives:l,transform:t,containerWidth:c,containerHeight:I}),Z.jsx(H$e,{elements:e,highlightedPrimitives:l,transform:t,containerWidth:c,containerHeight:I}),Z.jsx(Y$e,{elements:e,highlightedPrimitives:l,transform:t,containerWidth:c,containerHeight:I})]})]})},PQt=["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)"],P$e=({children:e,transform:A=ba(),elements:t=[],hoveredComponentIds:i=[]})=>{const[n,{width:o,height:s}]=yT(),r=AA.useRef(null),{is_showing_pcb_groups:a,pcb_group_view_mode:g,is_showing_group_anchor_offsets:c}=rl(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 AA.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=t.filter(w=>w.type==="pcb_group"),C=t.filter(w=>w.type==="pcb_component"),Q=t.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},m=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&&m.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),OA=B.filter(_A=>_A.source_group_id&&JA.includes(_A.source_group_id));for(const _A of OA){const DA=C.filter(NA=>NA.pcb_group_id===_A.pcb_group_id);S=[...S,...DA]}}let _,b,R,F,H=!1;if(w.center&&w.width&&w.height){H=!0;const JA=w.width/2,OA=w.height/2;_=w.center.x-JA,R=w.center.x+JA,b=w.center.y-OA,F=w.center.y+OA}else if(S.length===0||(_=1/0,b=1/0,R=-1/0,F=-1/0,S.forEach(JA=>{if(JA.center&&typeof JA.width=="number"&&typeof JA.height=="number"){const OA=JA.center.x-JA.width/2,_A=JA.center.x+JA.width/2,DA=JA.center.y+JA.height/2,NA=JA.center.y-JA.height/2;_=Math.min(_,OA),R=Math.max(R,_A),b=Math.min(b,NA),F=Math.max(F,DA)}}),_===1/0||R===-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(!H){const _A=1+(J?.5:0);_-=_A,R+=_A,b-=_A,F+=_A}const O=Ct(A,{x:_,y:F}),W=Ct(A,{x:R,y:F}),z=Ct(A,{x:_,y:b}),tA=Ct(A,{x:R,y:b}),aA=PQt[D%PQt.length];l.strokeStyle=aA,l.lineWidth=2;const eA=Math.max(4,Math.min(12,8*Math.abs(A.a))),oA=Math.max(2,Math.min(6,4*Math.abs(A.a))),lA=eA*(J?1.3:1),pA=oA;l.setLineDash([lA,pA]),l.beginPath(),l.moveTo(O.x,O.y),l.lineTo(W.x,W.y),l.lineTo(tA.x,tA.y),l.lineTo(z.x,z.y),l.closePath(),l.stroke();const kA=Math.max(8,Math.min(12,10*Math.abs(A.a))),MA=Y==0||Y==1?0:Y*.11,YA=kA*(1-MA),EA=4,xA=w.name||`Group ${D+1}`;l.font=`${YA}px sans-serif`,l.setLineDash([]);const WA=l.measureText(xA).width+EA*2,jA=YA+EA*2,It=O.x-5,mA=O.y-5,gt=3;if(l.fillStyle="rgba(0, 0, 0, 0.8)",l.beginPath(),l.roundRect(It,mA-jA,WA,jA,gt),l.fill(),l.fillStyle=aA,l.textAlign="left",l.textBaseline="middle",l.fillText(xA,It+EA,mA-jA/2),c&&m.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},OA=Ct(A,JA);l.strokeStyle="white",l.lineWidth=1.5,l.setLineDash([]);const _A=Math.max(4,Math.min(8,6*Math.abs(A.a)));l.beginPath(),l.moveTo(OA.x-_A,OA.y),l.lineTo(OA.x+_A,OA.y),l.stroke(),l.beginPath(),l.moveTo(OA.x,OA.y-_A),l.lineTo(OA.x,OA.y+_A),l.stroke()}})},[t,A,o,s,a,g,c,i]),Z.jsxs("div",{ref:n,style:{position:"relative",width:"100%",height:"100%"},children:[e,Z.jsx("canvas",{ref:r,style:{position:"absolute",top:0,left:0,pointerEvents:"none",zIndex:xc.pcbGroupOverlay,display:a?"block":"none"}})]})},K$e=({transform:e,soup:A,children:t})=>{const i=rl(r=>r.is_showing_rats_nest),{netMap:n,idToNetMap:o}=AA.useMemo(()=>pQt(A||[]),[A]),s=AA.useMemo(()=>{if(!A||!i)return[];const r=l=>{const B=Xb(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=Xb(A).pcb_port.list(),c=Xb(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?t:(e||(e=ba()),Z.jsxs("div",{style:{position:"relative"},children:[t,Z.jsx("svg",{style:{position:"absolute",left:0,top:0,width:"100%",height:"100%",pointerEvents:"none",opacity:.5,zIndex:xc.ratsNestOverlay},children:s.map(({key:r,startPoint:a,endPoint:g,isInNet:c})=>{const I=Ct(e,a),l=Ct(e,g);return Z.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)})})]}))},q$e={version:"1.11.355"},Nk=(e,A,t)=>{const i=rl(s=>s.is_mouse_over_container),n=AA.useRef(i),o=AA.useRef(A);AA.useEffect(()=>{n.current=i},[i]),AA.useEffect(()=>{o.current=A},[A]),AA.useEffect(()=>{if(!e)return;const s=r=>{const a=r.target;if(a.tagName==="INPUT"||a.tagName==="TEXTAREA"||a.isContentEditable)return;const g=e.split("+"),c=g.includes("ctrl"),I=g.includes("shift"),l=g.includes("alt"),B=g.includes("meta"),C=g[g.length-1],Q=t?.current?t.current.contains(document.activeElement)||document.activeElement===t.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)}},[e])},O$e=()=>{const[e,A]=AA.useState(!1);return AA.useEffect(()=>{const t=()=>{A(window.innerWidth<=768)};return t(),window.addEventListener("resize",t),()=>window.removeEventListener("resize",t)},[]),e},wT=(e,A={stopPropagation:!0})=>{const t=AA.useRef(0),i=AA.useCallback(s=>{A.stopPropagation&&s.stopPropagation();const r=Date.now();r-t.current<300||(t.current=r,e?.(s))},[e,A.stopPropagation]),n=AA.useCallback(s=>{s.preventDefault(),i(s)},[i]);return{onClick:i,onTouchEnd:n,style:{touchAction:"manipulation"}}},W$e=({name:e,selected:A,onClick:t})=>{const{style:i,...n}=wT(t);return Z.jsxs("div",{className:a1`
5472
5472
  margin-top: 2px;
5473
5473
  padding: 4px;
5474
5474
  padding-left: 8px;
@@ -5685,7 +5685,7 @@ test("${g} should solve problem correctly", () => {
5685
5685
  // Add more specific assertions based on expected output
5686
5686
  // expect(solver.netLabelPlacementSolver!.netLabelPlacements).toMatchInlineSnapshot()
5687
5687
  })
5688
- `,I=new Blob([c],{type:"text/plain"}),l=URL.createObjectURL(I),B=document.createElement("a");B.href=l,B.download=`${g}.test.ts`,B.click(),URL.revokeObjectURL(l)}catch(a){alert(`Error generating test.ts for ${e.constructor.name}: ${a instanceof Error?a.message:String(a)}`)}i(!1)};return Z.jsxs("div",{className:`relative ${A}`,ref:n,children:[Z.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>i(!t),title:`Download options for ${e.constructor.name}`,children:e.constructor.name}),t&&Z.jsxs("div",{className:"absolute top-full left-0 mt-1 bg-white border border-gray-300 rounded shadow-lg z-10 min-w-[150px]",children:[Z.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:o,children:"Download JSON"}),Z.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),Z.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:r,children:"Download test.ts"})]})]})},Aht=e=>e.activeSubSolver?[e,...Aht(e.activeSubSolver)]:[e],pti=({solver:e})=>{const A=Aht(e);return Z.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:A.map((t,i)=>Z.jsxs("div",{className:"flex items-center",children:[i>0&&Z.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),Z.jsx(dti,{solver:t})]},t.constructor.name))})},fti=({solver:e,triggerRender:A,animationSpeed:t=25,onSolverStarted:i,onSolverCompleted:n})=>{const[o,s]=AA.useReducer(Q=>!Q,!1),r=AA.useRef(void 0),a=()=>{!e.solved&&!e.failed&&(e.step(),A())},g=()=>{!e.solved&&!e.failed&&(i&&i(e),e.solve(),A(),n&&n(e))},c=()=>{o?(r.current&&(clearInterval(r.current),r.current=void 0),s()):(s(),r.current=setInterval(()=>{if(e.solved||e.failed){r.current&&(clearInterval(r.current),r.current=void 0),s(),A(),n&&e.solved&&n(e);return}e.step(),A()},t))},I=()=>{const Q=e;if(Q.getCurrentPhase&&!e.solved&&!e.failed){const h=Q.getCurrentPhase();for(;Q.getCurrentPhase()===h&&!e.solved&&!e.failed;)e.step();A()}},l=()=>{if(e.solved||e.failed||o)return;const Q=window.prompt("Step until which iteration?",`${e.iterations}`);if(Q===null)return;const h=Number(Q);if(!Number.isFinite(h)){window.alert("Please enter a valid number for the iteration");return}for(;e.iterations<h&&!e.solved&&!e.failed;)e.step();A(),e.solved&&n&&n(e)};AA.useEffect(()=>()=>{r.current&&clearInterval(r.current)},[]),AA.useEffect(()=>{(e.solved||e.failed)&&o&&(r.current&&(clearInterval(r.current),r.current=void 0),s())},[e.solved,e.failed,o]);const B=e.getCurrentPhase!==void 0,C=B?e.getCurrentPhase():null;return Z.jsxs("div",{className:"space-y-2 p-2 border-b",children:[Z.jsx("div",{className:"flex items-center",children:Z.jsx(pti,{solver:e})}),Z.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[Z.jsx("button",{onClick:a,disabled:e.solved||e.failed||o,className:"bg-blue-500 hover:bg-blue-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step"}),Z.jsx("button",{onClick:g,disabled:e.solved||e.failed||o,className:"bg-green-500 hover:bg-green-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Solve"}),Z.jsx("button",{onClick:c,disabled:e.solved||e.failed,className:`px-3 py-1 rounded text-white text-sm ${o?"bg-red-500 hover:bg-red-600":"bg-yellow-500 hover:bg-yellow-600"} disabled:bg-gray-300`,children:o?"Stop":"Animate"}),Z.jsx("button",{onClick:l,disabled:e.solved||e.failed||o,className:"bg-orange-500 hover:bg-orange-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step Until Iteration"}),B&&Z.jsx("button",{onClick:I,disabled:e.solved||e.failed||o,className:"bg-purple-500 hover:bg-purple-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Next Stage"}),Z.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",e.iterations]}),e.timeToSolve!==void 0&&Z.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(e.timeToSolve/1e3).toFixed(3),"s"]}),C&&Z.jsxs("div",{className:"text-sm text-gray-600",children:["Phase: ",Z.jsx("span",{className:"font-medium",children:C})]}),e.solved&&Z.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),e.failed&&Z.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),e.error&&Z.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",e.error]})]})},yti=(e,A,t)=>{const i=e.currentPipelineStepIndex;return A<i?"Completed":A===i&&e.activeSubSolver?e.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},mti=(e,A)=>{const i=e.pipelineDef[A].solverName,n=yti(e,A),o=e[i],s=e.firstIterationOfPhase?.[i]??null,r=e.iterations;let a=0;if(n==="Completed"){const l=e.pipelineDef[A+1],B=l?e.firstIterationOfPhase?.[l.solverName]:void 0;B!==void 0&&s!==null?a=B-s:s!==null&&(a=r-s)}else n==="In Progress"&&s!==null&&(a=r-s);const g=e.timeSpentOnPhase?.[i]??0;let c=0;n==="Completed"?c=1:n==="In Progress"&&o&&(c=o.progress??0);const I=o?.stats??null;return{index:A,name:i,status:n,firstIteration:s,iterations:a,progress:c,timeSpent:g,stats:I&&Object.keys(I).length>0?I:null,solverInstance:o??null}},wti=({status:e})=>{const A={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return Z.jsx("span",{className:`font-medium ${A[e]}`,children:e})},Dti=({progress:e})=>{if(e===0)return null;const A=Math.round(e*100);return Z.jsxs("div",{className:"flex items-center gap-2",children:[Z.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:Z.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${A}%`}})}),Z.jsxs("span",{className:"text-xs text-gray-500",children:[A,"%"]})]})},Sti=e=>Object.entries(e).map(([A,t])=>`${A}: ${t}`).join(", "),bti=({stats:e})=>{if(!e||Object.keys(e).length===0)return Z.jsx("span",{children:"-"});const A=Object.entries(e),t=Sti(e);return Z.jsxs("details",{className:"cursor-pointer",children:[Z.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:t}),Z.jsx("div",{className:"mt-1 text-xs",children:A.map(([i,n])=>Z.jsxs("div",{children:[i,": ",String(n)]},i))})]})},SyA=e=>{if(e===null||typeof e!="object")return e;if(Array.isArray(e))return e.map(SyA);const A={};for(const[t,i]of Object.entries(e))t.startsWith("_")||(A[t]=SyA(i));return A},xti=(e,A)=>{try{if(typeof e.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${A}`);return}const t=SyA(e.getConstructorParams()),i=new Blob([JSON.stringify(t,null,2)],{type:"application/json"}),n=URL.createObjectURL(i),o=document.createElement("a");o.href=n,o.download=`${A}_input.json`,o.click(),URL.revokeObjectURL(n)}catch(t){alert(`Error downloading input for ${A}: ${t instanceof Error?t.message:String(t)}`)}},_ti=({solver:e,onStepUntilPhase:A,onDownloadInput:t})=>{const i=e.pipelineDef.map((r,a)=>mti(e,a)),n=r=>{A?.(r)},o=r=>{r.solverInstance&&(t?t(r.solverInstance,r.name):xti(r.solverInstance,r.name))},s=r=>`${(r/1e3).toFixed(2)}s`;return Z.jsxs("div",{className:"border-t border-gray-200",children:[Z.jsx("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200",children:Z.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Steps"})}),Z.jsx("div",{className:"overflow-x-auto",children:Z.jsxs("table",{className:"w-full text-sm",children:[Z.jsx("thead",{children:Z.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Step"}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),Z.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",Z.jsx("sub",{children:"0"})]}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),Z.jsx("tbody",{children:i.map(r=>Z.jsxs("tr",{className:`border-b border-gray-100 ${r.status==="In Progress"?"bg-yellow-50":""}`,children:[Z.jsx("td",{className:"px-4 py-2",children:Z.jsxs("div",{className:"flex items-center gap-2",children:[Z.jsx("span",{className:"text-gray-400 w-6",children:String(r.index+1).padStart(2,"0")}),Z.jsx("button",{onClick:()=>n(r.name),disabled:r.status==="Completed"||e.solved||e.failed,className:"text-blue-500 hover:text-blue-700 disabled:text-gray-300 disabled:cursor-not-allowed",title:`Step until ${r.name} completes`,children:Z.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:Z.jsx("path",{fillRule:"evenodd",d:"M4.5 5.653c0-1.426 1.529-2.33 2.779-1.643l11.54 6.348c1.295.712 1.295 2.573 0 3.285L7.28 19.991c-1.25.687-2.779-.217-2.779-1.643V5.653z",clipRule:"evenodd"})})}),Z.jsx("span",{className:"font-medium text-gray-900",children:r.name})]})}),Z.jsx("td",{className:"px-4 py-2",children:Z.jsx(wti,{status:r.status})}),Z.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:r.firstIteration!==null?r.firstIteration:""}),Z.jsx("td",{className:"px-4 py-2 text-gray-600",children:r.iterations}),Z.jsx("td",{className:"px-4 py-2",children:Z.jsx(Dti,{progress:r.progress})}),Z.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(r.timeSpent)}),Z.jsx("td",{className:"px-4 py-2 text-gray-500",children:Z.jsx(bti,{stats:r.stats})}),Z.jsx("td",{className:"px-4 py-2",children:r.solverInstance?Z.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:[Z.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:Z.jsx("path",{fillRule:"evenodd",d:"M12 2.25a.75.75 0 01.75.75v11.69l3.22-3.22a.75.75 0 111.06 1.06l-4.5 4.5a.75.75 0 01-1.06 0l-4.5-4.5a.75.75 0 111.06-1.06l3.22 3.22V3a.75.75 0 01.75-.75zm-9 13.5a.75.75 0 01.75.75v2.25a1.5 1.5 0 001.5 1.5h13.5a1.5 1.5 0 001.5-1.5V16.5a.75.75 0 011.5 0v2.25a3 3 0 01-3 3H5.25a3 3 0 01-3-3V16.5a.75.75 0 01.75-.75z",clipRule:"evenodd"})}),Z.jsx("span",{children:"Input"})]}):null})]},r.name))})]})})]})},kti=class extends Qn.Component{constructor(e){super(e),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(e){console.error("InteractiveGraphics render error:",e)}render(){return this.state.hasError?this.props.fallback:this.props.children}};function vti({graphics:e}){const A=e.points??[],t=e.lines??[],i=e.rects??[],n=e.circles??[],o=e.texts??[];let s=Number.POSITIVE_INFINITY,r=Number.POSITIVE_INFINITY,a=Number.NEGATIVE_INFINITY,g=Number.NEGATIVE_INFINITY;const c=(h,E)=>{typeof h=="number"&&(h<s&&(s=h),h>a&&(a=h)),typeof E=="number"&&(E<r&&(r=E),E>g&&(g=E))};for(const h of A)c(h.x,h.y);for(const h of t){const E=h.points??[];for(const u of E)c(u.x,u.y)}for(const h of i){const E=h.x??0,u=h.y??0,d=h.width??0,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 Z.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)=>Z.jsx("rect",{x:h.x??0,y:h.y??0,width:h.width??0,height:h.height??0,fill:"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1},`rect-${E}`)),t.map((h,E)=>Z.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)=>Z.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)=>Z.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)=>Z.jsx("text",{x:h.x??0,y:h.y??0,fontSize:h.fontSize??10,fill:h.color??"black",children:h.text??""},`text-${E}`))]})}var Fti=({solver:e,animationSpeed:A=25,onSolverStarted:t,onSolverCompleted:i})=>{const[n,o]=AA.useReducer(c=>c+1,0),s=AA.useMemo(()=>{try{return e.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(c){return console.error("Visualization error:",c),{points:[],lines:[],rects:[],circles:[]}}},[e,n]),r=AA.useMemo(()=>(s.rects?.length||0)===0&&(s.lines?.length||0)===0&&(s.points?.length||0)===0&&(s.circles?.length||0)===0,[s]);AA.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const c=document.createElement("script");c.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(c)}},[]);const a=e.pipelineDef!==void 0,g=c=>{const I=e;if(!e.solved&&!e.failed){for(;!e.solved&&!e.failed&&I.currentPipelineStepIndex<=I.pipelineDef.findIndex(l=>l.solverName===c);)e.step();o()}};return Z.jsxs("div",{children:[Z.jsx(fti,{solver:e,triggerRender:o,animationSpeed:A,onSolverStarted:t,onSolverCompleted:i}),r?Z.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):Z.jsx(kti,{fallback:Z.jsx(vti,{graphics:s}),children:Z.jsx(uti,{graphics:s})}),a&&Z.jsx(_ti,{solver:e,onStepUntilPhase:g})]})};const Mti=()=>{AA.useEffect(()=>{const e="tailwind-cdn-script";if(document.getElementById(e)||window.tailwind)return;const A=document.createElement("div");A.className="hidden",document.body.appendChild(A);const t=window.getComputedStyle(A).display==="none";if(document.body.removeChild(A),t)return;const i=document.createElement("script");i.id=e,i.src="https://cdn.tailwindcss.com",document.head.appendChild(i)},[])},Gti=e=>e.toLowerCase().includes("pack")?gTe:e.toLowerCase().includes("rout")?QTe:ATe,Rti=({solverEvents:e=[]})=>{const[A,t]=AA.useState(null);Mti();const i=AA.useMemo(()=>{const r=new Map;for(const a of e){const g=`${a.componentName}-${a.solverName}`;r.set(g,a)}return r},[e]),n=AA.useMemo(()=>Array.from(i.keys()),[i]),o=A?i.get(A):null,s=AA.useMemo(()=>{if(!o)return{instance:null,error:null,classFound:!1};const r=ZgA[o.solverName];if(!r)return{instance:null,error:`Solver class "${o.solverName}" not found in SOLVERS registry. Available: ${Object.keys(ZgA).join(", ")}`,classFound:!1};try{const a=o.solverParams,g=a?.input!==void 0?a.input:a;return{instance:new r(g),error:null,classFound:!0}}catch(a){const g=a instanceof Error?a.message:String(a);return console.error("Failed to reconstruct solver:",a),{instance:null,error:`Failed to instantiate solver: ${g}`,classFound:!0}}},[o]);return e.length===0?Z.jsx("div",{className:"rf-p-4",children:Z.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:Z.jsxs("div",{className:"rf-p-4",children:[Z.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),Z.jsx("p",{className:"rf-text-sm rf-text-gray-600",children:"Solvers will appear here when the circuit runs. Solvers are used for tasks like component packing and autorouting."})]})})}):Z.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[Z.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[Z.jsxs("div",{className:"rf-text-xs rf-font-semibold rf-text-gray-500 rf-px-3 rf-py-2 rf-bg-gray-50 rf-border-b rf-border-gray-200",children:[n.length," ",n.length===1?"Solver":"Solvers"]}),n.map(r=>{const a=i.get(r),g=A===r;return Z.jsx("div",{className:`rf-px-3 rf-py-2 rf-cursor-pointer rf-border-b rf-border-gray-100 ${g?"rf-bg-blue-50 rf-border-l-2 rf-border-l-blue-500":"hover:rf-bg-gray-50"}`,onClick:()=>t(r),children:(()=>{const c=Gti(a.solverName);return Z.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[Z.jsx(c,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),Z.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[Z.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:a.componentName}),Z.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:a.solverName})]})]})})()},r)})]}),Z.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:o?s.instance?Z.jsx(jD,{fallback:Z.jsx("div",{className:"rf-p-4",children:Z.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[Z.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),Z.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",o.solverName]})]})}),children:Z.jsx(Fti,{solver:s.instance})}):Z.jsxs("div",{className:"rf-p-4",children:[Z.jsxs("div",{className:"rf-mb-4",children:[Z.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:o.solverName}),Z.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",o.componentName]})]}),s.error&&Z.jsx("div",{className:`rf-rounded-md rf-border rf-p-4 rf-mb-4 ${s.classFound?"rf-bg-red-50 rf-border-red-200":"rf-bg-yellow-50 rf-border-yellow-200"}`,children:Z.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),Z.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[Z.jsx("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50",children:Z.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"})}),Z.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:Z.jsx("pre",{className:"rf-text-xs rf-font-mono rf-text-gray-600 rf-whitespace-pre-wrap rf-overflow-x-auto",children:JSON.stringify(o.solverParams,null,2)})})]})]}):Z.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:Z.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},tht=({errorMessage:e,errorStack:A,circuitJsonErrors:t})=>{AA.useEffect(()=>{if(e){const i=new Error(e);A&&(i.stack=A);try{lq.captureException(i)}catch{}}},[e,A]),AA.useEffect(()=>{if(t&&t.length>0)for(const i of t){const n=new Error(i.message||"Circuit JSON Error");i.stack&&(n.stack=i.stack);try{lq.captureException(n,{error_type:i.type})}catch{}}},[t])},eht="0.0.1749",Nti={version:eht},byA={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1},xyA=new Map,$j=e=>{const A=xyA.get(e);return A?Object.fromEntries(Object.entries(A.stores).map(([t,i])=>[t,i.getState()])):{}},Lti=(e,A,t)=>{if(e===void 0)return{type:"untracked",connection:A.connect(t)};const i=xyA.get(t.name);if(i)return{type:"tracked",store:e,...i};const n={connection:A.connect(t),stores:{}};return xyA.set(t.name,n),{type:"tracked",store:e,...n}},iht=(e,A={})=>(t,i,n)=>{const{enabled:o,anonymousActionType:s,store:r,...a}=A;let g;try{g=(o??(byA?"production":void 0)!=="production")&&window.__REDUX_DEVTOOLS_EXTENSION__}catch{}if(!g)return(byA?"production":void 0)!=="production"&&o&&console.warn("[zustand devtools middleware] Please install/enable Redux devtools extension"),e(t,i,n);const{connection:c,...I}=Lti(r,g,a);let l=!0;n.setState=(Q,h,E)=>{const u=t(Q,h);if(!l)return u;const d=E===void 0?{type:s||"anonymous"}:typeof E=="string"?{type:E}:E;return r===void 0?(c?.send(d,i()),u):(c?.send({...d,type:`${r}/${d.type}`},{...$j(a.name),[r]:n.getState()}),u)};const B=(...Q)=>{const h=l;l=!1,t(...Q),l=h},C=e(n.setState,i,n);if(I.type==="untracked"?c?.init(C):(I.stores[I.store]=n,c?.init(Object.fromEntries(Object.entries(I.stores).map(([Q,h])=>[Q,Q===I.store?C:h.getState()])))),n.dispatchFromDevtools&&typeof n.dispatch=="function"){let Q=!1;const h=n.dispatch;n.dispatch=(...E)=>{(byA?"production":void 0)!=="production"&&E[0].type==="__setState"&&!Q&&(console.warn('[zustand devtools middleware] "__setState" action type is reserved to set state from the devtools. Avoid using it.'),Q=!0),h(...E)}}return c.subscribe(Q=>{var h;switch(Q.type){case"ACTION":if(typeof Q.payload!="string"){console.error("[zustand devtools middleware] Unsupported action format");return}return _yA(Q.payload,E=>{if(E.type==="__setState"){if(r===void 0){B(E.state);return}Object.keys(E.state).length!==1&&console.error(`
5688
+ `,I=new Blob([c],{type:"text/plain"}),l=URL.createObjectURL(I),B=document.createElement("a");B.href=l,B.download=`${g}.test.ts`,B.click(),URL.revokeObjectURL(l)}catch(a){alert(`Error generating test.ts for ${e.constructor.name}: ${a instanceof Error?a.message:String(a)}`)}i(!1)};return Z.jsxs("div",{className:`relative ${A}`,ref:n,children:[Z.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>i(!t),title:`Download options for ${e.constructor.name}`,children:e.constructor.name}),t&&Z.jsxs("div",{className:"absolute top-full left-0 mt-1 bg-white border border-gray-300 rounded shadow-lg z-10 min-w-[150px]",children:[Z.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:o,children:"Download JSON"}),Z.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),Z.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:r,children:"Download test.ts"})]})]})},Aht=e=>e.activeSubSolver?[e,...Aht(e.activeSubSolver)]:[e],pti=({solver:e})=>{const A=Aht(e);return Z.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:A.map((t,i)=>Z.jsxs("div",{className:"flex items-center",children:[i>0&&Z.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),Z.jsx(dti,{solver:t})]},t.constructor.name))})},fti=({solver:e,triggerRender:A,animationSpeed:t=25,onSolverStarted:i,onSolverCompleted:n})=>{const[o,s]=AA.useReducer(Q=>!Q,!1),r=AA.useRef(void 0),a=()=>{!e.solved&&!e.failed&&(e.step(),A())},g=()=>{!e.solved&&!e.failed&&(i&&i(e),e.solve(),A(),n&&n(e))},c=()=>{o?(r.current&&(clearInterval(r.current),r.current=void 0),s()):(s(),r.current=setInterval(()=>{if(e.solved||e.failed){r.current&&(clearInterval(r.current),r.current=void 0),s(),A(),n&&e.solved&&n(e);return}e.step(),A()},t))},I=()=>{const Q=e;if(Q.getCurrentPhase&&!e.solved&&!e.failed){const h=Q.getCurrentPhase();for(;Q.getCurrentPhase()===h&&!e.solved&&!e.failed;)e.step();A()}},l=()=>{if(e.solved||e.failed||o)return;const Q=window.prompt("Step until which iteration?",`${e.iterations}`);if(Q===null)return;const h=Number(Q);if(!Number.isFinite(h)){window.alert("Please enter a valid number for the iteration");return}for(;e.iterations<h&&!e.solved&&!e.failed;)e.step();A(),e.solved&&n&&n(e)};AA.useEffect(()=>()=>{r.current&&clearInterval(r.current)},[]),AA.useEffect(()=>{(e.solved||e.failed)&&o&&(r.current&&(clearInterval(r.current),r.current=void 0),s())},[e.solved,e.failed,o]);const B=e.getCurrentPhase!==void 0,C=B?e.getCurrentPhase():null;return Z.jsxs("div",{className:"space-y-2 p-2 border-b",children:[Z.jsx("div",{className:"flex items-center",children:Z.jsx(pti,{solver:e})}),Z.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[Z.jsx("button",{onClick:a,disabled:e.solved||e.failed||o,className:"bg-blue-500 hover:bg-blue-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step"}),Z.jsx("button",{onClick:g,disabled:e.solved||e.failed||o,className:"bg-green-500 hover:bg-green-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Solve"}),Z.jsx("button",{onClick:c,disabled:e.solved||e.failed,className:`px-3 py-1 rounded text-white text-sm ${o?"bg-red-500 hover:bg-red-600":"bg-yellow-500 hover:bg-yellow-600"} disabled:bg-gray-300`,children:o?"Stop":"Animate"}),Z.jsx("button",{onClick:l,disabled:e.solved||e.failed||o,className:"bg-orange-500 hover:bg-orange-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step Until Iteration"}),B&&Z.jsx("button",{onClick:I,disabled:e.solved||e.failed||o,className:"bg-purple-500 hover:bg-purple-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Next Stage"}),Z.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",e.iterations]}),e.timeToSolve!==void 0&&Z.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(e.timeToSolve/1e3).toFixed(3),"s"]}),C&&Z.jsxs("div",{className:"text-sm text-gray-600",children:["Phase: ",Z.jsx("span",{className:"font-medium",children:C})]}),e.solved&&Z.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),e.failed&&Z.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),e.error&&Z.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",e.error]})]})},yti=(e,A,t)=>{const i=e.currentPipelineStepIndex;return A<i?"Completed":A===i&&e.activeSubSolver?e.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},mti=(e,A)=>{const i=e.pipelineDef[A].solverName,n=yti(e,A),o=e[i],s=e.firstIterationOfPhase?.[i]??null,r=e.iterations;let a=0;if(n==="Completed"){const l=e.pipelineDef[A+1],B=l?e.firstIterationOfPhase?.[l.solverName]:void 0;B!==void 0&&s!==null?a=B-s:s!==null&&(a=r-s)}else n==="In Progress"&&s!==null&&(a=r-s);const g=e.timeSpentOnPhase?.[i]??0;let c=0;n==="Completed"?c=1:n==="In Progress"&&o&&(c=o.progress??0);const I=o?.stats??null;return{index:A,name:i,status:n,firstIteration:s,iterations:a,progress:c,timeSpent:g,stats:I&&Object.keys(I).length>0?I:null,solverInstance:o??null}},wti=({status:e})=>{const A={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return Z.jsx("span",{className:`font-medium ${A[e]}`,children:e})},Dti=({progress:e})=>{if(e===0)return null;const A=Math.round(e*100);return Z.jsxs("div",{className:"flex items-center gap-2",children:[Z.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:Z.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${A}%`}})}),Z.jsxs("span",{className:"text-xs text-gray-500",children:[A,"%"]})]})},Sti=e=>Object.entries(e).map(([A,t])=>`${A}: ${t}`).join(", "),bti=({stats:e})=>{if(!e||Object.keys(e).length===0)return Z.jsx("span",{children:"-"});const A=Object.entries(e),t=Sti(e);return Z.jsxs("details",{className:"cursor-pointer",children:[Z.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:t}),Z.jsx("div",{className:"mt-1 text-xs",children:A.map(([i,n])=>Z.jsxs("div",{children:[i,": ",String(n)]},i))})]})},SyA=e=>{if(e===null||typeof e!="object")return e;if(Array.isArray(e))return e.map(SyA);const A={};for(const[t,i]of Object.entries(e))t.startsWith("_")||(A[t]=SyA(i));return A},xti=(e,A)=>{try{if(typeof e.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${A}`);return}const t=SyA(e.getConstructorParams()),i=new Blob([JSON.stringify(t,null,2)],{type:"application/json"}),n=URL.createObjectURL(i),o=document.createElement("a");o.href=n,o.download=`${A}_input.json`,o.click(),URL.revokeObjectURL(n)}catch(t){alert(`Error downloading input for ${A}: ${t instanceof Error?t.message:String(t)}`)}},_ti=({solver:e,onStepUntilPhase:A,onDownloadInput:t})=>{const i=e.pipelineDef.map((r,a)=>mti(e,a)),n=r=>{A?.(r)},o=r=>{r.solverInstance&&(t?t(r.solverInstance,r.name):xti(r.solverInstance,r.name))},s=r=>`${(r/1e3).toFixed(2)}s`;return Z.jsxs("div",{className:"border-t border-gray-200",children:[Z.jsx("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200",children:Z.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Steps"})}),Z.jsx("div",{className:"overflow-x-auto",children:Z.jsxs("table",{className:"w-full text-sm",children:[Z.jsx("thead",{children:Z.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Step"}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),Z.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",Z.jsx("sub",{children:"0"})]}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),Z.jsx("tbody",{children:i.map(r=>Z.jsxs("tr",{className:`border-b border-gray-100 ${r.status==="In Progress"?"bg-yellow-50":""}`,children:[Z.jsx("td",{className:"px-4 py-2",children:Z.jsxs("div",{className:"flex items-center gap-2",children:[Z.jsx("span",{className:"text-gray-400 w-6",children:String(r.index+1).padStart(2,"0")}),Z.jsx("button",{onClick:()=>n(r.name),disabled:r.status==="Completed"||e.solved||e.failed,className:"text-blue-500 hover:text-blue-700 disabled:text-gray-300 disabled:cursor-not-allowed",title:`Step until ${r.name} completes`,children:Z.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:Z.jsx("path",{fillRule:"evenodd",d:"M4.5 5.653c0-1.426 1.529-2.33 2.779-1.643l11.54 6.348c1.295.712 1.295 2.573 0 3.285L7.28 19.991c-1.25.687-2.779-.217-2.779-1.643V5.653z",clipRule:"evenodd"})})}),Z.jsx("span",{className:"font-medium text-gray-900",children:r.name})]})}),Z.jsx("td",{className:"px-4 py-2",children:Z.jsx(wti,{status:r.status})}),Z.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:r.firstIteration!==null?r.firstIteration:""}),Z.jsx("td",{className:"px-4 py-2 text-gray-600",children:r.iterations}),Z.jsx("td",{className:"px-4 py-2",children:Z.jsx(Dti,{progress:r.progress})}),Z.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(r.timeSpent)}),Z.jsx("td",{className:"px-4 py-2 text-gray-500",children:Z.jsx(bti,{stats:r.stats})}),Z.jsx("td",{className:"px-4 py-2",children:r.solverInstance?Z.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:[Z.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:Z.jsx("path",{fillRule:"evenodd",d:"M12 2.25a.75.75 0 01.75.75v11.69l3.22-3.22a.75.75 0 111.06 1.06l-4.5 4.5a.75.75 0 01-1.06 0l-4.5-4.5a.75.75 0 111.06-1.06l3.22 3.22V3a.75.75 0 01.75-.75zm-9 13.5a.75.75 0 01.75.75v2.25a1.5 1.5 0 001.5 1.5h13.5a1.5 1.5 0 001.5-1.5V16.5a.75.75 0 011.5 0v2.25a3 3 0 01-3 3H5.25a3 3 0 01-3-3V16.5a.75.75 0 01.75-.75z",clipRule:"evenodd"})}),Z.jsx("span",{children:"Input"})]}):null})]},r.name))})]})})]})},kti=class extends Qn.Component{constructor(e){super(e),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(e){console.error("InteractiveGraphics render error:",e)}render(){return this.state.hasError?this.props.fallback:this.props.children}};function vti({graphics:e}){const A=e.points??[],t=e.lines??[],i=e.rects??[],n=e.circles??[],o=e.texts??[];let s=Number.POSITIVE_INFINITY,r=Number.POSITIVE_INFINITY,a=Number.NEGATIVE_INFINITY,g=Number.NEGATIVE_INFINITY;const c=(h,E)=>{typeof h=="number"&&(h<s&&(s=h),h>a&&(a=h)),typeof E=="number"&&(E<r&&(r=E),E>g&&(g=E))};for(const h of A)c(h.x,h.y);for(const h of t){const E=h.points??[];for(const u of E)c(u.x,u.y)}for(const h of i){const E=h.x??0,u=h.y??0,d=h.width??0,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 Z.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)=>Z.jsx("rect",{x:h.x??0,y:h.y??0,width:h.width??0,height:h.height??0,fill:"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1},`rect-${E}`)),t.map((h,E)=>Z.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)=>Z.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)=>Z.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)=>Z.jsx("text",{x:h.x??0,y:h.y??0,fontSize:h.fontSize??10,fill:h.color??"black",children:h.text??""},`text-${E}`))]})}var Fti=({solver:e,animationSpeed:A=25,onSolverStarted:t,onSolverCompleted:i})=>{const[n,o]=AA.useReducer(c=>c+1,0),s=AA.useMemo(()=>{try{return e.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(c){return console.error("Visualization error:",c),{points:[],lines:[],rects:[],circles:[]}}},[e,n]),r=AA.useMemo(()=>(s.rects?.length||0)===0&&(s.lines?.length||0)===0&&(s.points?.length||0)===0&&(s.circles?.length||0)===0,[s]);AA.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const c=document.createElement("script");c.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(c)}},[]);const a=e.pipelineDef!==void 0,g=c=>{const I=e;if(!e.solved&&!e.failed){for(;!e.solved&&!e.failed&&I.currentPipelineStepIndex<=I.pipelineDef.findIndex(l=>l.solverName===c);)e.step();o()}};return Z.jsxs("div",{children:[Z.jsx(fti,{solver:e,triggerRender:o,animationSpeed:A,onSolverStarted:t,onSolverCompleted:i}),r?Z.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):Z.jsx(kti,{fallback:Z.jsx(vti,{graphics:s}),children:Z.jsx(uti,{graphics:s})}),a&&Z.jsx(_ti,{solver:e,onStepUntilPhase:g})]})};const Mti=()=>{AA.useEffect(()=>{const e="tailwind-cdn-script";if(document.getElementById(e)||window.tailwind)return;const A=document.createElement("div");A.className="hidden",document.body.appendChild(A);const t=window.getComputedStyle(A).display==="none";if(document.body.removeChild(A),t)return;const i=document.createElement("script");i.id=e,i.src="https://cdn.tailwindcss.com",document.head.appendChild(i)},[])},Gti=e=>e.toLowerCase().includes("pack")?gTe:e.toLowerCase().includes("rout")?QTe:ATe,Rti=({solverEvents:e=[]})=>{const[A,t]=AA.useState(null);Mti();const i=AA.useMemo(()=>{const r=new Map;for(const a of e){const g=`${a.componentName}-${a.solverName}`;r.set(g,a)}return r},[e]),n=AA.useMemo(()=>Array.from(i.keys()),[i]),o=A?i.get(A):null,s=AA.useMemo(()=>{if(!o)return{instance:null,error:null,classFound:!1};const r=ZgA[o.solverName];if(!r)return{instance:null,error:`Solver class "${o.solverName}" not found in SOLVERS registry. Available: ${Object.keys(ZgA).join(", ")}`,classFound:!1};try{const a=o.solverParams,g=a?.input!==void 0?a.input:a;return{instance:new r(g),error:null,classFound:!0}}catch(a){const g=a instanceof Error?a.message:String(a);return console.error("Failed to reconstruct solver:",a),{instance:null,error:`Failed to instantiate solver: ${g}`,classFound:!0}}},[o]);return e.length===0?Z.jsx("div",{className:"rf-p-4",children:Z.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:Z.jsxs("div",{className:"rf-p-4",children:[Z.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),Z.jsx("p",{className:"rf-text-sm rf-text-gray-600",children:"Solvers will appear here when the circuit runs. Solvers are used for tasks like component packing and autorouting."})]})})}):Z.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[Z.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[Z.jsxs("div",{className:"rf-text-xs rf-font-semibold rf-text-gray-500 rf-px-3 rf-py-2 rf-bg-gray-50 rf-border-b rf-border-gray-200",children:[n.length," ",n.length===1?"Solver":"Solvers"]}),n.map(r=>{const a=i.get(r),g=A===r;return Z.jsx("div",{className:`rf-px-3 rf-py-2 rf-cursor-pointer rf-border-b rf-border-gray-100 ${g?"rf-bg-blue-50 rf-border-l-2 rf-border-l-blue-500":"hover:rf-bg-gray-50"}`,onClick:()=>t(r),children:(()=>{const c=Gti(a.solverName);return Z.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[Z.jsx(c,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),Z.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[Z.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:a.componentName}),Z.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:a.solverName})]})]})})()},r)})]}),Z.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:o?s.instance?Z.jsx(jD,{fallback:Z.jsx("div",{className:"rf-p-4",children:Z.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[Z.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),Z.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",o.solverName]})]})}),children:Z.jsx(Fti,{solver:s.instance})}):Z.jsxs("div",{className:"rf-p-4",children:[Z.jsxs("div",{className:"rf-mb-4",children:[Z.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:o.solverName}),Z.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",o.componentName]})]}),s.error&&Z.jsx("div",{className:`rf-rounded-md rf-border rf-p-4 rf-mb-4 ${s.classFound?"rf-bg-red-50 rf-border-red-200":"rf-bg-yellow-50 rf-border-yellow-200"}`,children:Z.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),Z.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[Z.jsx("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50",children:Z.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"})}),Z.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:Z.jsx("pre",{className:"rf-text-xs rf-font-mono rf-text-gray-600 rf-whitespace-pre-wrap rf-overflow-x-auto",children:JSON.stringify(o.solverParams,null,2)})})]})]}):Z.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:Z.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},tht=({errorMessage:e,errorStack:A,circuitJsonErrors:t})=>{AA.useEffect(()=>{if(e){const i=new Error(e);A&&(i.stack=A);try{lq.captureException(i)}catch{}}},[e,A]),AA.useEffect(()=>{if(t&&t.length>0)for(const i of t){const n=new Error(i.message||"Circuit JSON Error");i.stack&&(n.stack=i.stack);try{lq.captureException(n,{error_type:i.type})}catch{}}},[t])},eht="0.0.1751",Nti={version:eht},byA={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1},xyA=new Map,$j=e=>{const A=xyA.get(e);return A?Object.fromEntries(Object.entries(A.stores).map(([t,i])=>[t,i.getState()])):{}},Lti=(e,A,t)=>{if(e===void 0)return{type:"untracked",connection:A.connect(t)};const i=xyA.get(t.name);if(i)return{type:"tracked",store:e,...i};const n={connection:A.connect(t),stores:{}};return xyA.set(t.name,n),{type:"tracked",store:e,...n}},iht=(e,A={})=>(t,i,n)=>{const{enabled:o,anonymousActionType:s,store:r,...a}=A;let g;try{g=(o??(byA?"production":void 0)!=="production")&&window.__REDUX_DEVTOOLS_EXTENSION__}catch{}if(!g)return(byA?"production":void 0)!=="production"&&o&&console.warn("[zustand devtools middleware] Please install/enable Redux devtools extension"),e(t,i,n);const{connection:c,...I}=Lti(r,g,a);let l=!0;n.setState=(Q,h,E)=>{const u=t(Q,h);if(!l)return u;const d=E===void 0?{type:s||"anonymous"}:typeof E=="string"?{type:E}:E;return r===void 0?(c?.send(d,i()),u):(c?.send({...d,type:`${r}/${d.type}`},{...$j(a.name),[r]:n.getState()}),u)};const B=(...Q)=>{const h=l;l=!1,t(...Q),l=h},C=e(n.setState,i,n);if(I.type==="untracked"?c?.init(C):(I.stores[I.store]=n,c?.init(Object.fromEntries(Object.entries(I.stores).map(([Q,h])=>[Q,Q===I.store?C:h.getState()])))),n.dispatchFromDevtools&&typeof n.dispatch=="function"){let Q=!1;const h=n.dispatch;n.dispatch=(...E)=>{(byA?"production":void 0)!=="production"&&E[0].type==="__setState"&&!Q&&(console.warn('[zustand devtools middleware] "__setState" action type is reserved to set state from the devtools. Avoid using it.'),Q=!0),h(...E)}}return c.subscribe(Q=>{var h;switch(Q.type){case"ACTION":if(typeof Q.payload!="string"){console.error("[zustand devtools middleware] Unsupported action format");return}return _yA(Q.payload,E=>{if(E.type==="__setState"){if(r===void 0){B(E.state);return}Object.keys(E.state).length!==1&&console.error(`
5689
5689
  [zustand devtools middleware] Unsupported __setState action format.
5690
5690
  When using 'store' option in devtools(), the 'state' should have only one key, which is a value of 'store' that was passed in devtools(),
5691
5691
  and value of this only key should be a state object. Example: { "type": "__setState", "state": { "abc123Store": { "foo": "bar" } } }