@tscircuit/runframe 0.0.1638 → 0.0.1639
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/standalone.min.js
CHANGED
|
@@ -5137,7 +5137,7 @@ ${a.join(`
|
|
|
5137
5137
|
${Q}polygon: ${C.polygon.vertices}
|
|
5138
5138
|
`:a+=`
|
|
5139
5139
|
`,C.children.length>0&&c.push(C.children)}return a}};A.exports=s}}),A0e=ot({"node_modules/@jscad/modeling/src/operations/booleans/trees/Tree.js"(e,A){var t=jfe(),i=$fe(),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}}),rEA=ot({"node_modules/@jscad/modeling/src/operations/booleans/trees/index.js"(e,A){A.exports={Tree:A0e()}}}),t0e=ot({"node_modules/@jscad/modeling/src/operations/booleans/intersectGeom3Sub.js"(e,A){var t=jo(),i=sEA(),{Tree:n}=rEA(),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}}),o6A=ot({"node_modules/@jscad/modeling/src/operations/booleans/intersectGeom3.js"(e,A){var t=vo(),i=SH(),n=t0e(),o=(...s)=>{s=t(s);let r=s.shift();return s.forEach(a=>{r=n(r,a)}),r=i(r),r};A.exports=o}}),e0e=ot({"node_modules/@jscad/modeling/src/operations/booleans/intersectGeom2.js"(e,A){var t=vo(),i=jo(),n=S_(),o=nEA(),s=oEA(),r=o6A(),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}}),i0e=ot({"node_modules/@jscad/modeling/src/operations/booleans/intersect.js"(e,A){var t=vo(),i=DH(),n=Vo(),o=jo(),s=e0e(),r=o6A(),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}}),n0e=ot({"node_modules/@jscad/modeling/src/operations/booleans/scissionGeom3.js"(e,A){var t=wn(),i=S_(),n=jo(),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 b=Q[D];if(b.e>0){b.e=-1;for(let k=0;k<b.d.length;k++)m[b.d[k]]=!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}}),o0e=ot({"node_modules/@jscad/modeling/src/operations/booleans/scission.js"(e,A){var t=vo(),i=jo(),n=n0e(),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}}),s0e=ot({"node_modules/@jscad/modeling/src/operations/booleans/subtractGeom3Sub.js"(e,A){var t=jo(),i=sEA(),{Tree:n}=rEA(),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}}),s6A=ot({"node_modules/@jscad/modeling/src/operations/booleans/subtractGeom3.js"(e,A){var t=vo(),i=SH(),n=s0e(),o=(...s)=>{s=t(s);let r=s.shift();return s.forEach(a=>{r=n(r,a)}),r=i(r),r};A.exports=o}}),r0e=ot({"node_modules/@jscad/modeling/src/operations/booleans/subtractGeom2.js"(e,A){var t=vo(),i=jo(),n=S_(),o=nEA(),s=oEA(),r=s6A(),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}}),a0e=ot({"node_modules/@jscad/modeling/src/operations/booleans/subtract.js"(e,A){var t=vo(),i=DH(),n=Vo(),o=jo(),s=r0e(),r=s6A(),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}}),r6A=ot({"node_modules/@jscad/modeling/src/operations/booleans/unionGeom3Sub.js"(e,A){var t=jo(),i=sEA(),{Tree:n}=rEA(),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}}),a6A=ot({"node_modules/@jscad/modeling/src/operations/booleans/unionGeom3.js"(e,A){var t=vo(),i=SH(),n=r6A(),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}}),g6A=ot({"node_modules/@jscad/modeling/src/operations/booleans/unionGeom2.js"(e,A){var t=vo(),i=jo(),n=S_(),o=nEA(),s=oEA(),r=a6A(),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}}),aEA=ot({"node_modules/@jscad/modeling/src/operations/booleans/union.js"(e,A){var t=vo(),i=DH(),n=Vo(),o=jo(),s=g6A(),r=a6A(),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}}),gN=ot({"node_modules/@jscad/modeling/src/operations/booleans/index.js"(e,A){A.exports={intersect:i0e(),scission:o0e(),subtract:a0e(),union:aEA()}}}),NW=ot({"node_modules/@jscad/modeling/src/operations/expansions/offsetFromPoints.js"(e,A){var{EPS:t,TAU:i}=dr(),n=UXA(),o=XhA(),s=ps(),r=MW(),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 b=(D+1)%w,k=c[D],x=c[b];E?s.subtract(m,k,x):s.subtract(m,x,k),s.normal(m,m),s.normalize(m,m),s.scale(m,m,l);const v=s.add(s.create(),k,m),R=s.add(s.create(),x,m),U=[v,R];if(u!=null&&(C||!C&&b!==0)){const J=n(u[0],u[1],U[0],U[1]);J?(d.pop(),U[0]=J):f.push({c:k,s0:u,s1:U})}u=[v,R],!(b===0&&!C)&&(d.push(U[0]),d.push(U[1]))}if(C&&u!=null){const D=d[0],b=d[1],k=n(u[0],u[1],D,b);if(k)d[0]=k,d.pop();else{const x=c[0],v=[D,b];f.push({c:x,s0:u,s1:v})}}if(B==="edge"){const D=new Map;d.forEach((x,v)=>D.set(x,v));const b=o.create(),k=o.create();f.forEach(x=>{o.fromPoints(b,x.s0[0],x.s0[1]),o.fromPoints(k,x.s1[0],x.s1[1]);const v=o.intersectPointOfLines(b,k);if(Number.isFinite(v[0])&&Number.isFinite(v[1])){const R=x.s0[1],U=D.get(R);d[U]=v,d[(U+1)%d.length]=void 0}else{const R=x.s1[0],U=D.get(R);d[U]=void 0}}),d=d.filter(x=>x!==void 0)}if(B==="round"){let D=Math.floor(Q/4);const b=s.create();f.forEach(k=>{let x=s.angle(s.subtract(b,k.s1[0],k.c));if(x-=s.angle(s.subtract(b,k.s0[1],k.c)),E&&x<0&&(x=x+Math.PI,x<0&&(x=x+Math.PI)),!E&&x>0&&(x=x-Math.PI,x>0&&(x=x-Math.PI)),x!==0){D=Math.floor(Q*(Math.abs(x)/i));const v=x/D,R=s.angle(s.subtract(b,k.s0[1],k.c)),U=[];for(let J=1;J<D;J++){const H=R+v*J,O=s.fromAngleRadians(s.create(),H);s.scale(O,O,l),s.add(O,O,k.c),U.push(O)}if(U.length>0){const J=k.s0[1];let H=d.findIndex(O=>s.equals(J,O));H=(H+1)%d.length,d.splice(H,0,...U)}}else{const v=k.s1[0],R=d.findIndex(U=>s.equals(v,U));d.splice(R,1)}})}return d};A.exports=a}}),g0e=ot({"node_modules/@jscad/modeling/src/operations/expansions/expandGeom2.js"(e,A){var t=Vo(),i=NW(),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}}),c0e=ot({"node_modules/@jscad/modeling/src/operations/expansions/extrudePolygon.js"(e,A){var t=Wg(),i=wn(),n=jo(),o=or(),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}}),I0e=ot({"node_modules/@jscad/modeling/src/operations/expansions/expandShell.js"(e,A){var{EPS:t,TAU:i}=dr(),n=Wg(),o=wn(),s=i6A(),r=jo(),a=or(),g=jXA(),c=SH(),I=r6A(),l=c0e(),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,b=new Map,k=o.create(),x=o.create();return r.toPolygons(u).forEach((R,U)=>{const J=o.scale(o.create(),a.plane(R),2*f),H=a.transform(n.fromTranslation(n.create(),o.scale(o.create(),J,-.5)),R),O=l(J,H);w=I(w,O);const Z=R.vertices;for(let X=0;X<Z.length;X++){B(D,Z[X],a.plane(R));const iA=(X+1)%Z.length,aA=[Z[X],Z[iA]];C(b,aA,a.plane(R))}}),b.forEach(R=>{const U=R[0],J=R[1],H=U[0],O=U[1],Z=o.subtract(o.create(),O,H);o.normalize(Z,Z);const X=J[0],iA=o.cross(o.create(),X,Z);let aA=[];for(let YA=0;YA<m;YA++)Q(aA,YA*i/m);for(let YA=0,QA=J.length;YA<QA;YA++){const _A=J[YA],pA=o.dot(iA,_A),KA=o.dot(X,_A);let WA=Math.atan2(pA,KA);WA<0&&(WA+=i),Q(aA,WA),WA=Math.atan2(-pA,-KA),WA<0&&(WA+=i),Q(aA,WA)}aA=aA.sort(s);const tA=aA.length;let eA,sA;const IA=[],uA=[],xA=[];for(let YA=-1;YA<tA;YA++){const QA=aA[YA<0?YA+tA:YA],_A=Math.sin(QA),pA=Math.cos(QA);o.scale(k,X,pA*f),o.scale(x,iA,_A*f),o.add(k,k,x);const KA=o.add(o.create(),H,k),WA=o.add(o.create(),O,k);let st=!1;if(YA>=0&&o.distance(KA,eA)<t&&(st=!0),!st){if(YA>=0){IA.push(KA),uA.push(WA);const yA=[sA,WA,KA,eA],jA=a.create(yA);xA.push(jA)}eA=KA,sA=WA}}uA.reverse(),xA.push(a.create(IA)),xA.push(a.create(uA));const kA=r.create(xA);w=I(w,kA)}),D.forEach(R=>{const U=R[0],J=R[1],H=J[0];let O=null,Z=0;for(let tA=1;tA<J.length;tA++){const eA=J[tA],sA=o.cross(k,H,eA),IA=o.length(sA);IA>.05&&IA>Z&&(Z=IA,O=eA)}O||(O=o.orthogonal(k,H));const X=o.cross(k,H,O);o.normalize(X,X);const iA=o.cross(x,X,H),aA=g({center:[U[0],U[1],U[2]],radius:f,segments:m,axes:[H,X,iA]});w=I(w,aA)}),c(w)};A.exports=h}}),l0e=ot({"node_modules/@jscad/modeling/src/operations/expansions/expandGeom3.js"(e,A){var t=jo(),i=aEA(),n=I0e(),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}}),B0e=ot({"node_modules/@jscad/modeling/src/operations/expansions/expandPath2.js"(e,A){var t=MW(),i=ps(),n=Vo(),o=xg(),s=NW(),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)),b=C[0],k=i.angle(i.subtract(i.create(),h[0],b));for(let x=1;x<E;x++){let v=D+m*x,R=i.fromAngleRadians(i.create(),v);i.scale(R,R,B),i.add(R,R,w),u.push(R),v=k+m*x,R=i.fromAngleRadians(i.create(),v),i.scale(R,R,B),i.add(R,R,b),d.push(R)}}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}}),gEA=ot({"node_modules/@jscad/modeling/src/operations/expansions/expand.js"(e,A){var t=vo(),i=Vo(),n=jo(),o=xg(),s=g0e(),r=l0e(),a=B0e(),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}}),C0e=ot({"node_modules/@jscad/modeling/src/operations/expansions/offsetGeom2.js"(e,A){var t=Vo(),i=WhA(),n=NW(),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}}),Q0e=ot({"node_modules/@jscad/modeling/src/operations/expansions/offsetPath2.js"(e,A){var t=xg(),i=NW(),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}}),h0e=ot({"node_modules/@jscad/modeling/src/operations/expansions/offset.js"(e,A){var t=vo(),i=Vo(),n=xg(),o=C0e(),s=Q0e(),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}}),c6A=ot({"node_modules/@jscad/modeling/src/operations/expansions/index.js"(e,A){A.exports={expand:gEA(),offset:h0e()}}}),LW=ot({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeLinearGeom2.js"(e,A){var t=Wg(),i=wn(),n=Vo(),o=aN(),s=vW(),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,b=i.scale(i.create(),Q,m/B);return t.multiply(u,t.fromZRotation(u,D),t.fromTranslation(t.create(),b)),o.transform(u,w)};return a={numberOfSlices:B+1,capStart:!0,capEnd:!0,repair:C,callback:d},s(a,E)};A.exports=r}}),E0e=ot({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeLinearPath2.js"(e,A){var t=Vo(),i=xg(),n=LW(),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}}),u0e=ot({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeLinear.js"(e,A){var t=vo(),i=Vo(),n=xg(),o=LW(),s=E0e(),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}}),d0e=ot({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeRectangularPath2.js"(e,A){var t=xg(),i=gEA(),n=LW(),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}}),p0e=ot({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeRectangularGeom2.js"(e,A){var{area:t}=fH(),i=Vo(),n=xg(),o=gEA(),s=LW(),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}}),f0e=ot({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeRectangular.js"(e,A){var t=vo(),i=Vo(),n=xg(),o=d0e(),s=p0e(),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}}),y0e=ot({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeHelical.js"(e,A){var{TAU:t}=dr(),i=Wg(),n=Vo(),o=vW(),s=aN(),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(x=>x[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(),b=i.create(),k=(x,v,R)=>{const U=l+I/w*v,J=Q/w*v,H=(U-l)/t*B;return i.multiply(D,i.fromTranslation(i.create(),[J,0,H*Math.sign(I)]),i.fromXRotation(i.create(),-t/4*Math.sign(I))),i.multiply(b,i.fromZRotation(i.create(),U),D),s.transform(b,R)};return o({numberOfSlices:w+1,callback:k},f)};A.exports=r}}),m0e=ot({"node_modules/@jscad/modeling/src/operations/extrusions/project.js"(e,A){var t=vo(),i=zhA(),n=uD(),o=Wg(),s=Vo(),r=jo(),a=or(),g=S_(),c=g6A(),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(k=>n.projectionOfPoint(Q,k)),D=a.create(w),b=a.plane(D);i(Q,b)&&(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}}),bH=ot({"node_modules/@jscad/modeling/src/operations/extrusions/index.js"(e,A){A.exports={extrudeFromSlices:vW(),extrudeLinear:u0e(),extrudeRectangular:f0e(),extrudeRotate:A6A(),extrudeHelical:y0e(),project:m0e(),slice:aN()}}}),cEA=ot({"node_modules/@jscad/modeling/src/operations/hulls/hullPoints2.js"(e,A){var t=ps(),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}}),IEA=ot({"node_modules/@jscad/modeling/src/operations/hulls/toUniquePoints.js"(e,A){var t=Vo(),i=jo(),n=xg(),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}}),w0e=ot({"node_modules/@jscad/modeling/src/operations/hulls/hullPath2.js"(e,A){var t=vo(),i=xg(),n=cEA(),o=IEA(),s=(...r)=>{r=t(r);const a=o(r),g=n(a);return i.fromPoints({closed:!0},g)};A.exports=s}}),D0e=ot({"node_modules/@jscad/modeling/src/operations/hulls/hullGeom2.js"(e,A){var t=vo(),i=Vo(),n=cEA(),o=IEA(),s=(...r)=>{r=t(r);const a=o(r),g=n(a);return g.length<3?i.create():i.fromPoints(g)};A.exports=s}}),I6A=ot({"node_modules/@jscad/modeling/src/operations/hulls/hullPoints3.js"(e,A){var t=or(),i=gXA(),n=o=>i(o,{skipTriangulation:!0}).map(a=>{const g=a.map(c=>o[c]);return t.create(g)});A.exports=n}}),S0e=ot({"node_modules/@jscad/modeling/src/operations/hulls/hullGeom3.js"(e,A){var t=vo(),i=jo(),n=IEA(),o=I6A(),s=(...r)=>{r=t(r);const a=n(r);return a.length===0?i.create():i.create(o(a))};A.exports=s}}),l6A=ot({"node_modules/@jscad/modeling/src/operations/hulls/hull.js"(e,A){var t=vo(),i=DH(),n=Vo(),o=jo(),s=xg(),r=w0e(),a=D0e(),g=S0e(),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}}),b0e=ot({"node_modules/@jscad/modeling/src/operations/hulls/hullChain.js"(e,A){var t=vo(),i=aEA(),n=l6A(),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}}),x0e=ot({"node_modules/@jscad/modeling/src/operations/hulls/index.js"(e,A){A.exports={hull:l6A(),hullChain:b0e(),hullPoints2:cEA(),hullPoints3:I6A()}}}),B6A=ot({"node_modules/@jscad/modeling/src/operations/modifiers/snapPolygons.js"(e,A){var t=wn(),i=or(),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}}),_0e=ot({"node_modules/@jscad/modeling/src/operations/modifiers/mergePolygons.js"(e,A){var t=zhA(),i=wn(),n=or(),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 b=l(f,m,w,d);return[D,b]},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 b=0;b<D.length;b++){const k=D[b],x=a(f,k);if(x){const v=g(k,x,u);if(v[0]>=0&&v[1]>=0){const R=x.next,U=k.next;k.prev.next=x.next,k.next.prev=x.prev,x.prev.next=k.next,x.next.prev=k.prev,k.v1=null,k.v2=null,k.next=null,k.prev=null,r(f,x),x.v1=null,x.v2=null,x.next=null,x.prev=null;const J=(H,O,Z)=>{const X={v1:Z.v1,v2:O.v2,next:O.next,prev:Z.prev};Z.prev.next=X,O.next.prev=X,r(H,O),O.v1=null,O.v2=null,O.next=null,O.prev=null,r(H,Z),Z.v1=null,Z.v2=null,Z.next=null,Z.prev=null};v[0]===0&&J(f,R,R.prev),v[1]===0&&J(f,U,U.prev)}}else k.next&&s(f,k)}}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}}),k0e=ot({"node_modules/@jscad/modeling/src/operations/modifiers/insertTjunctions.js"(e,A){var t=dr(),i=wn(),n=or(),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,b=o(w),k=o(D);let x=[];m===0?l.has(b)&&(x=l.get(b)):I.has(b)&&(x=I.get(b));for(let v=0;v<x.length;v++){const R=x[v],U=c.get(R)[0],J=m===0?U.vertex0:U.vertex1;if(m===0?U.vertex1:U.vertex0,o(J)===k){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,Z=D,X=J,iA=i.subtract(i.create(),X,O),aA=i.dot(i.subtract(i.create(),Z,O),iA)/i.dot(iA,iA);if(aA>0&&aA<1){const tA=i.scale(i.create(),iA,aA);if(i.add(tA,tA,O),i.squaredDistance(tA,Z)<t.EPS*t.EPS){const sA=U.polygonindex,IA=C[sA],uA=o(U.vertex1);let xA=-1;for(let pA=0;pA<IA.vertices.length;pA++)if(o(IA.vertices[pA])===uA){xA=pA;break}const kA=IA.vertices.slice(0);kA.splice(xA,0,D);const YA=n.create(kA);C[sA]=YA,r(c,I,l,U.vertex0,U.vertex1,sA);const QA=s(c,I,l,U.vertex0,D,sA),_A=s(c,I,l,D,U.vertex1,sA);QA!==null&&B.set(QA,!0),_A!==null&&B.set(_A,!0),u=!1,m=2,Q=!0;break}}}}}}u&&B.delete(E)}if(!Q)break}g=C}return c.clear(),g};A.exports=a}}),F0e=ot({"node_modules/@jscad/modeling/src/operations/modifiers/triangulatePolygons.js"(e,A){var t=wn(),i=or(),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}}),G0e=ot({"node_modules/@jscad/modeling/src/operations/modifiers/generalize.js"(e,A){var t=vo(),i=S_(),n=Vo(),o=jo(),s=xg(),r=B6A(),a=_0e(),g=k0e(),c=F0e(),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}}),M0e=ot({"node_modules/@jscad/modeling/src/operations/modifiers/snap.js"(e,A){var t=vo(),i=ps(),n=Vo(),o=jo(),s=xg(),r=S_(),a=B6A(),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}}),R0e=ot({"node_modules/@jscad/modeling/src/operations/modifiers/index.js"(e,A){A.exports={generalize:G0e(),snap:M0e(),retessellate:SH()}}}),v0e=ot({"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}}),N0e=ot({"node_modules/@jscad/modeling/src/operations/transforms/align.js"(e,A){var t=vo(),i=v0e(),n=$hA(),{translate:o}=sG(),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}}),UW=ot({"node_modules/@jscad/modeling/src/operations/transforms/center.js"(e,A){var t=vo(),i=Vo(),n=jo(),o=xg(),s=nG(),{translate:r}=sG(),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}}}),HW=ot({"node_modules/@jscad/modeling/src/operations/transforms/scale.js"(e,A){var t=vo(),i=Wg(),n=Vo(),o=jo(),s=xg(),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}}}),L0e=ot({"node_modules/@jscad/modeling/src/operations/transforms/transform.js"(e,A){var t=vo(),i=Vo(),n=jo(),o=xg(),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}}),rG=ot({"node_modules/@jscad/modeling/src/operations/transforms/index.js"(e,A){A.exports={align:N0e(),center:UW().center,centerX:UW().centerX,centerY:UW().centerY,centerZ:UW().centerZ,mirror:mH().mirror,mirrorX:mH().mirrorX,mirrorY:mH().mirrorY,mirrorZ:mH().mirrorZ,rotate:wH().rotate,rotateX:wH().rotateX,rotateY:wH().rotateY,rotateZ:wH().rotateZ,scale:HW().scale,scaleX:HW().scaleX,scaleY:HW().scaleY,scaleZ:HW().scaleZ,transform:L0e(),translate:sG().translate,translateX:sG().translateX,translateY:sG().translateY,translateZ:sG().translateZ}}}),YW=ot({"node_modules/@jscad/modeling/src/index.js"(e,A){A.exports={colors:GW(),curves:Mpe(),geometries:ZhA(),maths:nfe(),measurements:lfe(),primitives:b_(),text:iEA(),utils:n6A(),booleans:gN(),expansions:c6A(),extrusions:bH(),hulls:x0e(),modifiers:R0e(),transforms:rG()}}}),C6A=ot({"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)}`)}}}}),U0e=ot({"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":"")}}}),H0e=ot({"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=U0e(),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,(k,x)=>{if(k==="%%")return"%";D++;const v=o.formatters[x];if(typeof v=="function"){const R=d[D];k=v.call(f,R),d.splice(D,1),D--}return k}),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}}),Y0e=ot({"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 HhA<"u"&&"env"in HhA&&(a=HhA.env.DEBUG),a}function s(){try{return localStorage}catch{}}A.exports=H0e()(e);var{formatters:r}=A.exports;r.j=function(a){try{return JSON.stringify(a)}catch(g){return"[UnexpectedJSONParseError]: "+g.message}}}}),Q6A={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,backgroundStart:!0,backgroundEnd:!0},h6A=V.createContext(void 0),J0e=({children:e})=>{const[A,t]=V.useState(Q6A),i=V.useCallback((s,r)=>{t(a=>({...a,[s]:r}))},[]),n=V.useCallback(()=>{t(Q6A)},[]),o=V.useMemo(()=>({visibility:A,setLayerVisibility:i,resetToDefaults:n}),[A,i,n]);return W.jsx(h6A.Provider,{value:o,children:e})},aG=()=>{const e=V.useContext(h6A);if(!e)throw new Error("useLayerVisibility must be used within a LayerVisibilityProvider");return e},lEA=1.2;function E6A(e){return V.useMemo(()=>{if(!e)return lEA;try{return Ti(e).pcb_board.list()[0]?.thickness??lEA}catch{return lEA}},[e])}var u6A=V.createContext(null),Yu=()=>{const e=V.useContext(u6A);if(!e)throw new Error("useThree must be used within a ThreeProvider");return e},xH=(e,A=[])=>{const{addFrameListener:t,removeFrameListener:i}=Yu();nn.useEffect(()=>(t(e),()=>i(e)),[t,i,...A])},_H={clickToInteractOverlay:100,htmlElements:95,orientationCube:95,contextMenu:90,appearanceMenu:91},d6A=({children:e,position:A,style:t})=>{const{camera:i,renderer:n}=Yu(),o=V.useRef(document.createElement("div")),[s,r]=V.useState(null);return V.useEffect(()=>{const a=n?.domElement.parentNode;if(a)return a.style.position!=="relative"&&a.style.position!=="absolute"&&(a.style.position="relative"),a.appendChild(o.current),r(l5.createPortal(e,o.current)),()=>{a.contains(o.current)&&a.removeChild(o.current)}},[n,e]),xH(()=>{if(!i||!o.current||!n)return;const a=new Mt(...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=_H.htmlElements.toString(),t&&Object.assign(o.current.style,t)},[i,n,A,t]),s},p6A={in:25.4,inch:25.4,mil:.0254,mm:1,m:1e3,cm:10,ft:304.8,feet:304.8},Fr=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 p6A)return t*p6A[A];throw new Error(`Unsupported unit: ${A}`)},Fl=Fr,T0e=Object.defineProperty,K0e=(e,A)=>{for(var t in A)T0e(e,t,{get:A[t],enumerable:!0})},Bb={};K0e(Bb,{axial:()=>lme,bga:()=>fye,breakoutheaders:()=>Dme,cap:()=>j0e,dfn:()=>Wye,diode:()=>V0e,dip:()=>O0e,electrolytic:()=>aSe,hc49:()=>bme,jst:()=>kDe,led:()=>z0e,lqfp:()=>mme,m2host:()=>_Se,melf:()=>Hwe,micromelf:()=>Kwe,minimelf:()=>Fwe,mlp:()=>kye,ms012:()=>Ame,ms013:()=>eme,msop:()=>YDe,pad:()=>xme,pinrow:()=>jye,platedhole:()=>pSe,potentiometer:()=>oSe,pushbutton:()=>Eme,qfn:()=>bye,qfp:()=>_ye,quad:()=>IN,radial:()=>Qme,res:()=>uye,sma:()=>Wwe,smb:()=>tDe,smbf:()=>cSe,smc:()=>oDe,smf:()=>zwe,smtpad:()=>uSe,sod110:()=>GDe,sod123:()=>ame,sod123f:()=>gwe,sod123fl:()=>Bwe,sod123w:()=>Kme,sod128:()=>fwe,sod323:()=>Wme,sod323f:()=>owe,sod323fl:()=>ODe,sod323w:()=>TDe,sod523:()=>Mme,sod723:()=>Ewe,sod80:()=>Hme,sod882:()=>twe,sod882d:()=>vwe,sod923:()=>zme,soic:()=>mye,solderjumper:()=>zDe,son:()=>jDe,sop8:()=>Lme,sot:()=>ySe,sot223:()=>gDe,sot23:()=>Yye,sot23w:()=>uDe,sot25:()=>Pye,sot323:()=>CSe,sot343:()=>DSe,sot363:()=>Nye,sot457:()=>ASe,sot563:()=>Xye,sot723:()=>nme,sot886:()=>Uye,sot89:()=>bwe,sot963:()=>eSe,ssop:()=>Gye,stampboard:()=>dme,stampreceiver:()=>yme,to220:()=>_we,to92:()=>Fme,to92l:()=>FSe,to92s:()=>wDe,tqfp:()=>xye,tssop:()=>Rye,vssop:()=>LDe});var Wi=(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"}),Zi=zA({norefdes:gt().optional().describe("disable reference designator label"),invert:gt().optional().describe("hint to invert the orientation of the 3D model"),faceup:gt().optional().describe("The male pin header should face upwards, out of the top layer"),nosilkscreen:gt().optional().describe("omit all silkscreen elements from the footprint")}),zo=(e,A,t,i,n)=>({pcb_plated_hole_id:"",type:"pcb_plated_hole",shape:"circle",x:A,y:t,hole_diameter:Fr(i),outer_diameter:Fr(n),pcb_port_id:"",layers:["top","bottom"],port_hints:[e.toString()]}),Cb=(e,A,t,i,n,o,s,r)=>({pcb_plated_hole_id:"",type:"pcb_plated_hole",shape:"circular_hole_with_rect_pad",x:A,y:t,hole_diameter:Fr(i),hole_shape:"circle",pad_shape:"rect",rect_pad_width:Fr(n),rect_pad_height:Fr(o),pcb_port_id:"",layers:["top","bottom"],port_hints:[e.toString()],hole_offset_x:s,hole_offset_y:r}),f6A=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 x_(e){return typeof e=="string"?e.trim().toLowerCase().endsWith("mil")?parseFloat(e)*.0254:parseFloat(e):Number(e)}var JW=Ze([Y(),ZA()]).transform(e=>x_(e)),P0e=e=>Zi.extend({fn:Y(),num_pins:ZA().optional().default(6),wide:gt().optional(),narrow:gt().optional(),w:JW.optional(),p:JW.default(e.p??"2.54mm"),id:JW.optional(),od:JW.optional(),nosquareplating:gt().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=x_("0.55mm"),A.od=x_("0.95mm")):(A.id=x_("0.8mm"),A.od=x_("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=x_("600mil"):A.narrow?A.w=x_("300mil"):A.w=x_(e.w??"300mil")),A)),q0e=P0e({}),y6A=(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}},O0e=e=>{const A=q0e.parse(e),t=[];for(let g=0;g<A.num_pins;g++){const{x:c,y:I}=y6A(A.num_pins,g+1,A.w,A.p??2.54,A.nosquareplating);if(g===0&&!A.nosquareplating){t.push(Cb(g+1,c,I,A.id??"0.8mm",A.od??"1mm",A.od??"1mm"));continue}t.push(zo(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},...f6A.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}=y6A(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=Wi(0,o/2+.5,.4);return{circuitJson:[...t,s,a,...r],parameters:A}},di=(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()]}),m6A=[{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}],W0e=Object.fromEntries(m6A.map(e=>[e.metric,e])),Z0e=Object.fromEntries(m6A.map(e=>[e.imperial,e]));Zi.extend({tht:gt(),p:hA.optional(),pw:hA.optional(),ph:hA.optional(),metric:at.optional(),imperial:at.optional(),w:hA.optional(),h:hA.optional(),textbottom:gt().optional()});var TW=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=Fl(r)),typeof a=="string"&&(a=Fl(a)),typeof t=="string"&&(t=Fl(t)),typeof i=="string"&&(i=Fl(i)),typeof n=="string"&&(n=Fl(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=W0e[o]),s&&(c=Z0e[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=Wi(0,l,.2);return A?[zo(1,-t/2,0,i,i*1/.8),zo(2,t/2,0,i,i*1/.8),I,B]:[di(["1","left"],-t/2,0,i,n),di(["2","right"],t/2,0,i,n),I,B]},V0e=e=>({circuitJson:TW(e),parameters:e}),j0e=e=>({circuitJson:TW(e),parameters:e}),z0e=e=>({circuitJson:TW(e),parameters:e}),cN=e=>{const{padSpacing:A,padWidth:t,padHeight:i,padPitch:n,numRows:o,textbottom:s}=e,r=[],a=(o-1)*(n/2);for(let b=0;b<o;b++)r.push(a-b*n);const g=[];r.forEach((b,k)=>{g.push(di(k+1,-A/2,b,t,i))}),r.slice().reverse().forEach((b,k)=>{g.push(di(k+o+1,A/2,b,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=Wi(0,w,.2);return[...g,C,Q,m,D]},X0e=Zi.extend({pw:Y().default("0.5mm"),ph:Y().default("0.4mm"),p:Y().default("0.7mm"),textbottom:gt().optional()}),$0e=1,Aye=e=>{const A=X0e.parse(e),t=Fl(A.pw),i=Fl(A.ph),n=Fl(A.p);return cN({padSpacing:$0e,padWidth:t,padHeight:i,padPitch:n,numRows:2,textbottom:A.textbottom})},tye=Zi.extend({pw:Y().default("0.5mm"),ph:Y().default("0.32mm"),p:Y().default("0.5mm"),textbottom:gt().optional()}),eye=1,iye=e=>{const A=tye.parse(e),t=Fl(A.pw),i=Fl(A.ph),n=Fl(A.p);return cN({padSpacing:eye,padWidth:t,padHeight:i,padPitch:n,numRows:4,textbottom:A.textbottom})},nye=Zi.extend({pw:Y().default("0.9mm"),ph:Y().default("0.4mm"),p:Y().default("0.8mm"),textbottom:gt().optional()}),oye=1.7,sye=e=>{const A=nye.parse(e),t=Fl(A.pw),i=Fl(A.ph),n=Fl(A.p);return cN({padSpacing:oye,padWidth:t,padHeight:i,padPitch:n,numRows:2,textbottom:A.textbottom})},rye=Zi.extend({pw:Y().default("0.9mm"),ph:Y().default("0.4mm"),p:Y().default("0.8mm"),textbottom:gt().optional()}),aye=1.7,gye=e=>{const A=rye.parse(e),t=Fl(A.pw),i=Fl(A.ph),n=Fl(A.p);return cN({padSpacing:aye,padWidth:t,padHeight:i,padPitch:n,numRows:4,textbottom:A.textbottom})},cye=Zi.extend({pw:Y().default("0.7mm"),ph:Y().default("0.64mm"),p:Y().default("0.94mm"),textbottom:gt().optional()}),Iye=1.4,lye=e=>{const A=cye.parse(e),t=Fl(A.pw),i=Fl(A.ph),n=Fl(A.p);return cN({padSpacing:Iye,padWidth:t,padHeight:i,padPitch:n,numRows:2,textbottom:A.textbottom})},Bye=Zi.extend({pw:Y().default("0.9mm"),ph:Y().default("0.9mm"),p:Y().default("1.34mm"),textbottom:gt().optional()}),Cye=3,Qye=e=>{const A=Bye.parse(e),t=Fl(A.pw),i=Fl(A.ph),n=Fl(A.p);return cN({padSpacing:Cye,padWidth:t,padHeight:i,padPitch:n,numRows:4,textbottom:A.textbottom})},hye=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(/(?:array|x)(2|4)$/)?.[1];if(i)return Number.parseInt(i,10)}},Eye=e=>e?(typeof e=="number"?`${e}`:e).split("_")[0]:void 0,uye=e=>{const A=hye(e),t=Eye(e.imperial);return A===2&&t==="0402"?{circuitJson:Aye(e),parameters:e}:A===4&&t==="0402"?{circuitJson:iye(e),parameters:e}:A===2&&t==="0603"?{circuitJson:sye(e),parameters:e}:A===4&&t==="0603"?{circuitJson:gye(e),parameters:e}:A===2&&t==="0606"?{circuitJson:lye(e),parameters:e}:A===4&&t==="1206"?{circuitJson:Qye(e),parameters:e}:{circuitJson:TW(e),parameters:e}},w6A=(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()]}),D6A="ABCDEFGHIJKLMNOPQRSTUVWXYZ",S6A=Y().transform(e=>{const[A,t]=e.split(/[x ]/);return{x:parseFloat(A),y:parseFloat(t)}}).pipe(zA({x:ZA(),y:ZA()})),dye=Y().or(St(Yc())).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(Y().or(ZA()))),pye=Zi.extend({fn:Y(),num_pins:ZA().optional().default(64),grid:S6A.optional(),p:at.default("0.8mm"),w:hA.optional(),h:hA.optional(),ball:hA.optional().describe("ball diameter"),pad:hA.optional().describe("pad width/height"),circularpads:gt().optional().describe("use circular pads"),tlorigin:gt().optional(),blorigin:gt().optional(),trorigin:gt().optional(),brorigin:gt().optional(),missing:dye.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=D6A.indexOf(n[1]),s=Number.parseInt(n[2])-1;return o*e.grid.x+s+1})),{...e,origin:A}}),fye=e=>{const A=pye.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 b=D;b<D+m;b++)for(let k=w;k<w+m;k++)I.push(b*i.x+k+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,b=(m-(i.y-1)/2)*n;let k=w,x=m;switch(A.origin){case"bl":k=w,x=i.y-1-m;break;case"br":k=i.x-1-w,x=i.y-1-m;break;case"tr":k=i.x-1-w,x=m;break}let v=x*i.x+k+1;if(B.has(v)){C++;continue}v-=C;const R=[v,`${D6A[x]}${k+1}`];c.push(A.circularpads?w6A(R,{x:D,y:b,radius:a/2}):di(R,D,b,a,a))}const Q=Wi(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}},KW=(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()]}),dD=e=>Zi.extend({fn:Y(),num_pins:ZA().optional().default(8),w:hA.default(hA.parse(e.w??"5.3mm")),p:hA.default(hA.parse(e.p??"1.27mm")),pw:hA.default(hA.parse(e.pw??"0.6mm")),pl:hA.default(hA.parse(e.pl??"1.0mm")),legsoutside:gt().optional().default(e.legsoutside??!1),pillpads:gt().optional().default(e.pillpads??!1),silkscreen_stroke_width:ZA().optional().default(.1)}).transform(A=>(!A.pw&&!A.pl?(A.pw=hA.parse("0.6mm"),A.pl=hA.parse("1.0mm")):A.pw?A.pl||(A.pl=A.pw*(1/.6)):A.pw=A.pl*(.6/1),A)),yye=dD({}),BEA=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}},mye=e=>{const A=yye.parse(e);return{circuitJson:__(A),parameters:A}},__=e=>{const A=[];for(let r=0;r<e.num_pins;r++){const{x:a,y:g}=BEA({num_pins:e.num_pins,pn:r+1,w:e.w,p:e.p,pl:e.pl,legsoutside:e.legsoutside});e.pillpads?A.push(KW(r+1,a,g,e.pl,e.pw)):A.push(di(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=Wi(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},...f6A.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]},b6A=se(["leftside","topside","rightside","bottomside","toppin","bottompin","leftpin","rightpin"]),wye=({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},CEA=Zi.extend({fn:Y(),cc:gt().default(!0).optional(),ccw:gt().default(!0).optional(),startingpin:Y().or(St(b6A)).transform(e=>typeof e=="string"?e.slice(1,-1).split(","):e).pipe(St(b6A)).optional(),num_pins:ZA().optional().default(64),w:hA.optional(),h:hA.optional(),p:hA.default(hA.parse("0.5mm")),pw:hA.optional(),pl:hA.optional(),thermalpad:Ze([FA(!0),S6A]).optional(),legsoutside:gt().default(!1)}),QEA=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},x6A=CEA.transform(QEA),Dye=["left","bottom","right","top"],Sye=e=>{const{pin_count:A,pn:t,w:i,h:n,p:o,pl:s,legsoutside:r}=e,a=A/4,g=Dye[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")}},IN=e=>{const A=x6A.parse(e),t=[],i=wye(A),n=A.num_pins/4;for(let r=0;r<A.num_pins;r++){const{x:a,y:g,o:c}=Sye({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(di(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(di(["thermalpad"],0,0,r,a))}else t.push(di(["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=Wi(0,A.h/2+(A.legsoutside?A.pl*1.2:.5),.3);return{circuitJson:[...t,...o,s],parameters:A}};CEA.extend({}).transform(QEA);var bye=e=>(e.legsoutside=!1,e.pl||(e.pl=.875),e.pw||(e.pw=.25),IN(e)),xye=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 IN(e)},_ye=e=>{e.legsoutside=!0;const A=x6A.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 IN(e)};CEA.extend({}).transform(QEA);var kye=e=>(e.legsoutside=!1,e.thermalpad===void 0&&(e.thermalpad=!0),IN(e)),Fye=dD({w:"3.9mm",p:"1.27mm"}),Gye=e=>{const A=Fye.parse(e);return{circuitJson:__(A),parameters:A}},Mye=dD({w:"7.1mm",p:"0.65mm",pl:"1.35mm",pw:"0.40mm",legsoutside:!0}),Rye=e=>{const A=Mye.parse(e);return{circuitJson:__(A),parameters:A}},vye=dD({}),Nye=e=>{const A=vye.parse({fn:"sot363",num_pins:6,w:2.56,p:.65,pw:.4,pl:.65,legoutside:!0});return{circuitJson:__(A),parameters:A}},Lye=Zi.extend({fn:Y(),num_pins:FA(6).default(6),w:Y().default("1.01mm"),h:Y().default("1.45mm"),p:Y().default("0.5mm"),pl:Y().default("0.33mm"),pw:Y().default("0.27mm"),string:Y().optional()}),Uye=e=>{const A=Lye.parse({fn:"sot886",...e}),t=hA.parse(A.w),i=hA.parse(A.h),n=hA.parse(A.p),o=hA.parse(A.pl),s=hA.parse(A.pw),r=[];for(let B=0;B<6;B++){const{x:C,y:Q}=_6A(B+1,t,n,o);r.push(di(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=_6A(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=Wi(0,i/2+.4,.25);return{circuitJson:[...r,a,g,l,I],parameters:A}},_6A=(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}},k6A=Zi.extend({fn:Y(),num_pins:ZA().default(3),w:Y().default("1.92mm"),h:Y().default("2.74mm"),pl:Y().default("1.32mm"),pw:Y().default("0.6mm"),p:Y().default("0.95mm"),string:Y().optional()}),Hye=dD({p:"0.95mm",w:"1.6mm",legsoutside:!0}),Yye=e=>{const A=e.string?.match(/^sot23_(\d+)/),t=A?Number.parseInt(A[1],10):3;if(t===6||t===8){const n=Hye.parse({...e,num_pins:t});return{circuitJson:__(n),parameters:n}}const i=k6A.parse({...e,num_pins:t});if(i.num_pins===3)return{circuitJson:Tye(i),parameters:i};if(i.num_pins===5)return{circuitJson:G6A(i),parameters:i};throw new Error("Invalid number of pins")},Jye=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}},Tye=e=>{const A=[];for(let i=0;i<e.num_pins;i++){const{x:n,y:o}=Jye({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(di(i+1,n,o,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}const t=Wi(0,Number.parseInt(e.h),.3);return[...A,t]},F6A=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")},G6A=e=>{const A=[];for(let I=1;I<=e.num_pins;I++){const{x:l,y:B}=F6A({h:Number.parseFloat(e.h),p:Number.parseFloat(e.p),pn:I});A.push(di(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=Wi(0,i+.3,.3),r=F6A({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]},Kye=k6A.extend({}),Pye=e=>{const A=Kye.parse({...e,num_pins:5});return{circuitJson:G6A(A),parameters:A}},qye=[{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}],Oye=dD({}),Wye=e=>{const A=Oye.parse(e),t=[];for(let I=0;I<A.num_pins;I++){const{x:l,y:B}=BEA({num_pins:A.num_pins,pn:I+1,w:A.w,p:A.p??1.27,pl:A.pl,widthincludeslegs:!0});t.push(di(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 qye){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=Wi(0,o/2+.4,o/12);return{circuitJson:[...t,c,...s],parameters:A}},hEA=({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 Zye({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 Vye=Zi.extend({fn:Y(),num_pins:ZA().optional().default(6),rows:Ze([Y(),ZA()]).transform(e=>Number(e)).optional().default(1).describe("number of rows"),p:hA.default("0.1in").describe("pitch"),id:hA.default("1.0mm").describe("inner diameter"),od:hA.default("1.5mm").describe("outer diameter"),male:gt().optional().describe("for male pin headers"),female:gt().optional().describe("for female pin headers"),smd:gt().optional().describe("surface mount device"),surfacemount:gt().optional().describe("surface mount device (verbose)"),rightangle:gt().optional().describe("right angle"),pw:hA.optional().default("1.0mm").describe("pad width for SMD"),pl:hA.optional().default("2.0mm").describe("pad length for SMD"),pinlabeltextalignleft:gt().optional().default(!1),pinlabeltextaligncenter:gt().optional().default(!1),pinlabeltextalignright:gt().optional().default(!1),pinlabelverticallyinverted:gt().optional().default(!1),pinlabelorthogonal:gt().optional().default(!1),nosquareplating:gt().optional().default(!1).describe("do not use rectangular pad for pin 1"),nopinlabels:gt().optional().default(!1).describe("omit silkscreen pin labels"),doublesidedpinlabel:gt().optional().default(!1).describe("add silkscreen pins in top and bottom layers"),bottomsidepinlabel:gt().optional().default(!1).describe("place the silkscreen reference text on the bottom layer instead of top")}).transform(e=>{const A=Zye(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:Oe.custom,message:"'male' and 'female' cannot both be true; it should be male or female.",path:["male","female"]})}),jye=e=>{const A=Vye.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:b,yoff:k,od:x,anchorSide:v,smd:R,pw:U,pl:J})=>{let H=0,O=0;if(R){const Z=x/5;switch(v){case"right":H=U/2+Z;break;case"top":O=J/2+Z;break;case"bottom":O=-(J/2+Z);break;case"left":H=-(U/2+Z);break}}else{const Z=x*.75;switch(v){case"right":H=Z;break;case"top":O=Z;break;case"bottom":O=-Z;break;case"left":H=-Z;break}}return{anchor_x:b+H,anchor_y:k+O}},f=(b,k,x)=>{A.smd?h.push(di(b,k,x,A.pw,A.pl)):b===1&&!A.nosquareplating?h.push(Cb(b,k,x,i,n,n,0,0)):h.push(zo(b,k,x,i,n));const{anchor_x:v,anchor_y:R}=d({xoff:k,yoff:x,od:n,anchorSide:r,smd:A.smd,pw:A.pw,pl:A.pl});l||(C?h.push(hEA({fs:n/5,pn:b,anchor_x:v,anchor_y:R,textalign:Q,orthogonal:g,verticallyinverted:a,layer:"bottom"})):h.push(hEA({fs:n/5,pn:b,anchor_x:v,anchor_y:R,textalign:Q,orthogonal:g,verticallyinverted:a,layer:"top"})),B&&h.push(hEA({fs:n/5,pn:b,anchor_x:v,anchor_y:R,textalign:Q,orthogonal:g,verticallyinverted:a,layer:"bottom"})))},m=new Set,w=o>2&&E>2;if(o===1){const b=-((s-1)/2)*t;for(let k=0;k<s;k++){const x=k+1,v=b+k*t,R=`${v},0`;if(m.has(R))throw new Error(`Overlap at ${R}`);m.add(R),f(x,v,0)}}else if(w){const b=-((E-1)/2)*t;let k=1;for(let x=0;x<o&&k<=s;x++)for(let v=0;v<E&&k<=s;v++){const R=b+v*t,U=x*u,J=`${R},${U}`;if(m.has(J))throw new Error(`Overlap at ${J}`);m.add(J),f(k++,R,U)}}else{const b=-((E-1)/2)*t;let k=1,x=0,v=o-1,R=0,U=E-1;for(;k<=s&&x<=v&&R<=U;){for(let J=x;J<=v&&k<=s;J++){const H=b+R*t,O=J*u,Z=`${H},${O}`;if(m.has(Z))throw new Error(`Overlap at ${Z}`);m.add(Z),f(k++,H,O)}R++;for(let J=R;J<=U&&k<=s;J++){const H=b+J*t,O=v*u,Z=`${H},${O}`;if(m.has(Z))throw new Error(`Overlap at ${Z}`);m.add(Z),f(k++,H,O)}if(v--,R<=U){for(let J=v;J>=x&&k<=s;J--){const H=b+U*t,O=J*u,Z=`${H},${O}`;if(m.has(Z))throw new Error(`Overlap at ${Z}`);m.add(Z),f(k++,H,O)}U--}if(x<=v){for(let J=U;J>=R&&k<=s;J--){const H=b+J*t,O=x*u,Z=`${H},${O}`;if(m.has(Z))throw new Error(`Overlap at ${Z}`);m.add(Z),f(k++,H,O)}x++}}if(k-1<s)throw new Error(`Missing pins: assigned ${k-1}, expected ${s}`)}const D=Wi(0,t,.5);return{circuitJson:[...h,D],parameters:A}},zye=Zi.extend({fn:Y(),num_pins:FA(6).default(6),w:Y().default("2.1mm"),h:Y().default("2.45mm"),p:Y().default("0.5mm"),pl:Y().default("0.675mm"),pw:Y().default("0.35mm"),string:Y().optional()}),Xye=e=>{const A=zye.parse({...e,fn:"sot563"}),t=hA.parse(A.w),i=hA.parse(A.h),n=hA.parse(A.p),o=hA.parse(A.pl),s=hA.parse(A.pw),r=[];for(let B=0;B<6;B++){const{x:C,y:Q}=M6A(B+1,t,n,o);r.push(di(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=M6A(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=Wi(0,i/2+.4,.25);return{circuitJson:[...r,a,g,l,I],parameters:A}},M6A=(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}},$ye=dD({p:"1.27mm",w:"3.9mm",legsoutside:!0}),Ame=e=>{const A=$ye.parse({...e,num_pins:8});return{circuitJson:__(A),parameters:A}},tme=dD({p:"1.27mm",w:"7.5mm",legsoutside:!0}),eme=e=>{const A=tme.parse({...e,num_pins:16});return{circuitJson:__(A),parameters:A}},ime=Zi.extend({fn:Y(),num_pins:FA(3).default(3),w:Y().default("1.2mm"),h:Y().default("1.2mm"),pw:Y().default("0.40mm"),pl:Y().default("0.45mm"),p:Y().default("0.575mm")}),nme=e=>{const A=ime.parse(e),t=sme(A),i=Wi(0,hA.parse(A.h),.2);return{circuitJson:[...t,i],parameters:A}},ome=e=>{const{pn:A,p:t}=e;return A===1?{x:t,y:0}:A===2?{x:-t,y:-.4}:{x:-t,y:.4}},sme=e=>{const A=[];for(let t=0;t<3;t++){const{x:i,y:n}=ome({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(di(t+1,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},rme=Zi.extend({fn:Y(),num_pins:FA(2).default(2),w:Y().default("2.36mm"),h:Y().default("1.22mm"),pl:Y().default("0.9mm"),pw:Y().default("1.2mm"),p:Y().default("3.30mm")}),ame=e=>{const A=rme.parse(e),t=Wi(0,hA.parse(A.h)/4+.4,.3);return{circuitJson:cme(A).concat(t),parameters:A}},gme=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},cme=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=gme({pn:t,p:Number.parseFloat(e.p)});A.push(di(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},Ime=Zi.extend({fn:Y(),p:hA.optional().default("2.54mm"),id:hA.optional().default("0.7mm"),od:hA.optional().default("1.4mm")}),lme=e=>{const A=Ime.parse(e),{p:t,id:i,od:n}=A,o=[zo(1,-t/2,0,i,n),zo(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=Wi(0,1.5,.5);return{circuitJson:[...o,s,r],parameters:A}},Bme=(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}},Cme=Zi.extend({fn:Y(),p:hA.optional().default("5mm"),id:hA.optional().default("0.8mm"),od:hA.optional().default("1.6mm"),ceramic:gt().optional(),electrolytic:gt().optional(),polarized:gt().optional()}),Qme=e=>{const A=Cme.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=[zo(1,-t/2,0,A.id,A.od),zo(2,t/2,0,A.id,A.od)],s=t+.1,{topArc:r,bottomArc:a}=Bme(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=Wi(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}},PW=(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}),hme=Zi.extend({fn:FA("pushbutton"),w:hA.default(4.5),h:hA.default(6.5),id:hA.default(1),od:hA.default(1.2)}),Eme=e=>{const A=hme.parse(e),t=A.w,i=A.h,n=A.id,o=[zo(1,-t/2,i/2,n,n*1.5),zo(2,-t/2,-i/2,n,n*1.5),zo(3,t/2,-i/2,n,n*1.5),zo(4,t/2,i/2,n,n*1.5)],s=[PW([{x:-t/2,y:-i/2},{x:-t/2,y:i/2}]),PW([{x:t/2,y:-i/2},{x:t/2,y:i/2}]),PW([{x:-t/2,y:0},{x:-t/5,y:0},{x:t/5*1/Math.sqrt(2),y:i/8}]),PW([{x:t/2,y:0},{x:t/5,y:0}])],r=Wi(0,i/2+.4,.5);return{circuitJson:[...o,...s,r],parameters:A}},R6A=Zi.extend({fn:Y(),w:hA.default("22.58mm"),h:hA.optional(),left:hA.optional().default(20),right:hA.optional().default(20),top:hA.optional().default(2),bottom:hA.optional().default(2),p:hA.default(hA.parse("2.54mm")),pw:hA.default(hA.parse("1.6mm")),pl:hA.default(hA.parse("2.4mm")),innerhole:gt().default(!1),innerholeedgedistance:hA.default(hA.parse("1.61mm")),silkscreenlabels:gt().default(!1),silkscreenlabelmargin:hA.default(hA.parse("0.1mm"))}),ume=e=>{const A=R6A.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},qW=(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},dme=e=>{const A=R6A.parse(e),t=A.h??ume(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=qW(A.w/2-A.pl*1.4,Q+h*A.p,"right")),i.push(di(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(zo(h+1+A.left+(A.bottom??0)+g,A.w/2,Q+h*A.p,r,a)),n.push(zo(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=qW(-A.w/2+A.pl*1.4,Q-h*A.p,"left")),i.push(di(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(zo(h+1+g,-A.w/2,Q-h*A.p,r,a)),n.push(zo(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=qW(Q-h*A.p,t/2-A.pl*1.4,"top")),i.push(di(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(zo(h+1+A.left+A.right+(A.bottom??0)+g,Q-h*A.p,t/2,r,a)),n.push(zo(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=qW(Q+h*A.p,-t/2+A.pl*1.4,"bottom")),i.push(di(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(zo(h+1+A.left+g,Q+h*A.p,-t/2,r,a)),n.push(zo(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=Wi(0,t/1.8,t/25);return{circuitJson:[...i,...n,...o,B,...A.silkscreenlabels?[]:[l],C],parameters:A}},v6A=Zi.extend({fn:Y(),w:hA.default("22.58mm"),h:hA.optional(),left:hA.optional().default(20),right:hA.optional().default(20),top:hA.optional().default(2),bottom:hA.optional().default(2),p:hA.default(hA.parse("2.54mm")),pw:hA.default(hA.parse("1.6mm")),pl:hA.default(hA.parse("3.2mm")),innerhole:gt().default(!1),innerholeedgedistance:hA.default(hA.parse("1.61mm"))}),pme=e=>{const A=v6A.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},fme=(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]},yme=e=>{const A=v6A.parse(e),t=A.h??pme(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=fme(-A.w/2-A.pl/2,C-Q*A.p,"left")),i.push(di(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(zo(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(di(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(zo(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(di(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(zo(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(di(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(zo(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=Wi(0,t/1.8,t/25);return{circuitJson:[...o,...i,...n,l,I,B],parameters:A}},mme=e=>(e.legsoutside=!0,e.pl||(e.pl=1.5),e.pw||(e.pw=.3),IN(e)),N6A=Zi.extend({fn:Y(),w:hA.default("10mm"),h:hA.optional(),left:hA.optional().default(20),right:hA.optional().default(20),top:hA.optional().default(0),bottom:hA.optional().default(0),p:hA.default(hA.parse("2.54mm")),id:hA.optional().default(hA.parse("1mm")),od:hA.optional().default(hA.parse("1.5mm"))}),wme=e=>{const A=N6A.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},OW=(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]},Dme=e=>{const A=N6A.parse(e),t=A.h??wme(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=OW(A.w/2+o*1.4,c+I*A.p,"right")),i.push(zo(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=OW(-A.w/2-o*1.4,c+I*A.p,"left")),i.push(zo(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=OW(c+I*A.p,t/2+o*1.4,"top")),i.push(zo(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=OW(c+I*A.p,-t/2-o*1.4,"bottom")),i.push(zo(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=Wi(0,t/1.7,t/25);return{circuitJson:[...i,a,g,r],parameters:A}},L6A=(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}}),Sme=Zi.extend({fn:Y(),p:hA.optional().default("4.88mm"),id:hA.optional().default("0.8mm"),od:hA.optional().default("1.5mm"),w:hA.optional().default("5.6mm"),h:hA.optional().default("3.5mm")}),bme=e=>{const A=Sme.parse(e),{p:t,id:i,od:n,w:o,h:s}=A,r=s/2,a=[zo(1,-t/2,0,i,n),zo(2,t/2,0,i,n)],g=L6A(-o/2,0,r,"left"),c=L6A(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=Wi(0,t/4,.5);return{circuitJson:[...a,I,l],parameters:A}};Zi.extend({w:hA,h:hA});var xme=e=>{const{w:A,h:t}=e,i=Fr(A),n=Fr(t);return{circuitJson:[di(1,0,0,i,n),Wi(0,n/2+.5,.2)],parameters:e}},kH=(e,A,t,i,n,o)=>({pcb_plated_hole_id:"",type:"pcb_plated_hole",shape:"pill",x:A,y:t,outer_width:Fr(n),outer_height:Fr(o),hole_width:Fr(i),hole_height:Fr(i),pcb_port_id:"",layers:["top","bottom"],port_hints:[e.toString()],ccw_rotation:0}),_me=Zi.extend({fn:Y(),num_pins:Ze([FA(3),FA(2)]).default(3),p:Y().default("1.27mm"),id:Y().default("0.72mm"),od:Y().default("0.95mm"),w:Y().default("4.5mm"),h:Y().default("4.5mm"),inline:gt().default(!1),string:Y().optional()}),kme=(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}}),Fme=e=>{const A=e.string?.match(/^to92_(\d+)/),t=A?Number.parseInt(A[1],10):3,i=_me.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=[Cb(1,-I,c-I,l,B,Q,0,0),kH(2,0,c-I,l,C,Q),kH(3,I,c-I,l,C,Q)]:h=[Cb(1,-I,c-I,l,B,B,0,0),zo(2,0,c,l,B),zo(3,I,c-I,l,B)];else if(i.num_pins===2)h=[Cb(1,-I,c-I,l,C,Q,0,0),kH(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=kme(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=Wi(0,c+1,.5);return{circuitJson:[...h,d,f],parameters:i}},Gme=Zi.extend({fn:Y(),num_pins:FA(2).default(2),w:Y().default("2.15mm"),h:Y().default("1.20mm"),pl:Y().default("0.5mm"),pw:Y().default("0.6mm"),p:Y().default("1.4mm")}),Mme=e=>{const A=Gme.parse(e),t=Wi(0,hA.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:hA.parse(A.p)/2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2-.2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2-.2,y:-hA.parse(A.h)/2},{x:hA.parse(A.p)/2,y:-hA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:vme(A).concat(i,t),parameters:A}},Rme=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},vme=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=Rme({pn:t,p:Number.parseFloat(e.p)});A.push(di(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},Nme=dD({}),Lme=e=>{const A=Nme.parse(e),t=[];for(let s=0;s<A.num_pins;s++){const{x:r,y:a}=BEA({num_pins:A.num_pins,pn:s+1,w:A.w,p:A.p??1.27,pl:A.pl,widthincludeslegs:!0});t.push(di(s+1,r,a,A.pl??"1.5mm",A.pw??"0.6mm"))}const i=(A.num_pins/2-1)*A.p+A.pw,n=Wi(0,i/2-.5,i/12),o={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"",type:"pcb_silkscreen_path",route:[{x:-A.w/3,y:i/2+.2},{x:A.w/3,y:i/2+.2}],stroke_width:.1};return{circuitJson:[...t,n,o],parameters:A}},Ume=Zi.extend({fn:Y(),num_pins:FA(2).default(2),w:Y().default("5.0mm"),h:Y().default("2.30mm"),pl:Y().default("1.25mm"),pw:Y().default("2mm"),p:Y().default("3.75mm")}),Hme=e=>{const A=Ume.parse(e),t=Wi(0,hA.parse(A.h)/2+1,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:hA.parse(A.p)/2+.5,y:hA.parse(A.h)/2+.5},{x:-hA.parse(A.w)/2-.5,y:hA.parse(A.h)/2+.5},{x:-hA.parse(A.w)/2-.5,y:-hA.parse(A.h)/2-.5},{x:hA.parse(A.p)/2+.5,y:-hA.parse(A.h)/2-.5}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:Jme(A).concat(i,t),parameters:A}},Yme=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},Jme=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=Yme({pn:t,p:Number.parseFloat(e.p)});A.push(di(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},Tme=Zi.extend({fn:Y(),num_pins:FA(2).default(2),w:Y().default("4.4mm"),h:Y().default("2.1mm"),pl:Y().default("1.2mm"),pw:Y().default("1.2mm"),p:Y().default("2.9mm")}),Kme=e=>{const A=Tme.parse(e),t=Wi(0,hA.parse(A.h)-.5,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:hA.parse(A.p)/2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2-.2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2-.2,y:-hA.parse(A.h)/2},{x:hA.parse(A.p)/2,y:-hA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:qme(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}},qme=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(di(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},Ome=Zi.extend({fn:Y(),num_pins:FA(2).default(2),w:Y().default("3.30mm"),h:Y().default("1.80mm"),pl:Y().default("0.60mm"),pw:Y().default("0.45mm"),p:Y().default("2.1mm")}),Wme=e=>{const A=Ome.parse(e),t=Wi(0,hA.parse(A.h)-.5,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:hA.parse(A.p)/2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2,y:-hA.parse(A.h)/2},{x:hA.parse(A.p)/2,y:-hA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:Vme(A).concat(i,t),parameters:A}},Zme=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},Vme=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=Zme({pn:t,p:Number.parseFloat(e.p)});A.push(di(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},jme=Zi.extend({fn:Y(),num_pins:FA(2).default(2),w:Y().default("1.4mm"),h:Y().default("0.9mm"),pl:Y().default("0.36mm"),pw:Y().default("0.25mm"),p:Y().default("0.85mm")}),zme=e=>{const A=jme.parse(e),t=Wi(0,hA.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:hA.parse(A.p)/2+.15,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2-.15,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2-.15,y:-hA.parse(A.h)/2},{x:hA.parse(A.p)/2+.15,y:-hA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:$me(A).concat(i,t),parameters:A}},Xme=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},$me=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=Xme({pn:t,p:Number.parseFloat(e.p)});A.push(di(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},Awe=Zi.extend({fn:Y(),num_pins:FA(2).default(2),w:Y().default("1.3mm"),h:Y().default("0.9mm"),pl:Y().default("0.4mm"),pw:Y().default("0.7mm"),p:Y().default("0.7mm")}),twe=e=>{const A=Awe.parse(e),t=Wi(0,hA.parse(A.h)+.1,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:hA.parse(A.p)/2+.2,y:hA.parse(A.h)/2+.2},{x:-hA.parse(A.w)/2-.2,y:hA.parse(A.h)/2+.2},{x:-hA.parse(A.w)/2-.2,y:-hA.parse(A.h)/2-.2},{x:hA.parse(A.p)/2+.2,y:-hA.parse(A.h)/2-.2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:iwe(A).concat(i,t),parameters:A}},ewe=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},iwe=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=ewe({pn:t,p:Number.parseFloat(e.p)});A.push(di(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},nwe=Zi.extend({fn:Y(),num_pins:FA(2).default(2),w:Y().default("3,05mm"),h:Y().default("1.65mm"),pl:Y().default("0.6mm"),pw:Y().default("0.6mm"),pad_spacing:Y().default("2.2mm")}),owe=e=>{const A=nwe.parse(e),t=Wi(0,hA.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:hA.parse(A.pad_spacing)/2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2-.2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2-.2,y:-hA.parse(A.h)/2},{x:hA.parse(A.pad_spacing)/2,y:-hA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:rwe(A).concat(i,t),parameters:A}},swe=e=>{const{pn:A,pad_spacing:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},rwe=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=swe({pn:t,pad_spacing:Number.parseFloat(e.pad_spacing)});A.push(di(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},awe=Zi.extend({fn:Y(),num_pins:FA(2).default(2),w:Y().default("4.4mm"),h:Y().default("2.1mm"),pl:Y().default("1.2mm"),pw:Y().default("1.2mm"),p:Y().default("2.9mm")}),gwe=e=>{const A=awe.parse(e),t=Wi(0,hA.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:hA.parse(A.p)/2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2-.2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2-.2,y:-hA.parse(A.h)/2},{x:hA.parse(A.p)/2,y:-hA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:Iwe(A).concat(i,t),parameters:A}},cwe=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},Iwe=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=cwe({pn:t,p:Number.parseFloat(e.p)});A.push(di(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},lwe=Zi.extend({fn:Y(),num_pins:FA(2).default(2),w:Y().default("4.4mm"),h:Y().default("2.1mm"),pl:Y().default("0.91mm"),pw:Y().default("1.22mm"),p:Y().default("3.146mm")}),Bwe=e=>{const A=lwe.parse(e),t=Wi(0,hA.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:hA.parse(A.p)/2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2-.2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2-.2,y:-hA.parse(A.h)/2},{x:hA.parse(A.p)/2,y:-hA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:Qwe(A).concat(i,t),parameters:A}},Cwe=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},Qwe=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=Cwe({pn:t,p:Number.parseFloat(e.p)});A.push(di(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},hwe=Zi.extend({fn:Y(),num_pins:FA(2).default(2),w:Y().default("1.80mm"),h:Y().default("1.00mm"),pl:Y().default("0.66mm"),pw:Y().default("0.5mm"),p:Y().default("0.8mm")}),Ewe=e=>{const A=hwe.parse(e),t=Wi(0,hA.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:hA.parse(A.p)/2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2-.1,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2-.1,y:-hA.parse(A.h)/2},{x:hA.parse(A.p)/2,y:-hA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:dwe(A).concat(i,t),parameters:A}},uwe=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},dwe=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=uwe({pn:t,p:Number.parseFloat(e.p)});A.push(di(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},pwe=Zi.extend({fn:Y(),num_pins:FA(2).default(2),w:Y().default("6.2mm"),h:Y().default("3.4mm"),pl:Y().default("1.4mm"),pw:Y().default("2.1mm"),p:Y().default("4.4mm")}),fwe=e=>{const A=pwe.parse(e),t=Wi(0,hA.parse(A.h)/2+.4,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:hA.parse(A.p)/2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2-.2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2-.2,y:-hA.parse(A.h)/2},{x:hA.parse(A.p)/2,y:-hA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:mwe(A).concat(i,t),parameters:A}},ywe=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},mwe=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=ywe({pn:t,p:Number.parseFloat(e.p)});A.push(di(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},wwe=Zi.extend({fn:Y(),num_pins:Ze([FA(3),FA(5)]).default(3),w:Y().default("4.20mm"),h:Y().default("4.80mm"),pl:Y().default("1.3mm"),pw:Y().default("0.9mm"),p:Y().default("1.5mm"),string:Y().optional()}),Dwe=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(di(1,-n/2+r,t,o,i),di(2,-n/2,0,o+s,i),di(3,-n/2+r,-t,o,i));const a=Wi(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]},Swe=e=>{const A=[];Number.parseFloat(e.p),Number.parseFloat(e.pw),Number.parseFloat(e.w),A.push(di(1,-1.85,-1.5,1.5,.7),di(2,-1.85,1.5,1.5,.7),di(3,0,0,.8,2),di(4,1.85,-1.5,1.5,.7),di(5,1.85,1.5,1.5,.7));const t=Wi(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]},bwe=e=>{const A=e.string?.match(/^sot89_(\d+)/),t=A?Number.parseInt(A[1],10):3,i=wwe.parse({...e,num_pins:t});if(i.num_pins===3)return{circuitJson:Dwe(i),parameters:i};if(i.num_pins===5)return{circuitJson:Swe(i),parameters:i};throw new Error("Invalid number of pins for SOT89")},xwe=Zi.extend({fn:Y(),p:hA.optional().default("5.0mm"),id:hA.optional().default("1.0mm"),od:hA.optional().default("1.9mm"),w:hA.optional().default("13mm"),h:hA.optional().default("7mm"),num_pins:ZA().optional(),string:Y().optional()}),_we=e=>{const A=xwe.parse(e),{fn:t,id:i,od:n,w:o,h:s,string:r}=A,a=Number.parseInt(r?.split("_")[1]??"3"),g=-1,c=o/2,I=s/2,l=2.5,B=o*.4,C=Math.max(l,B/(a-1)),Q=Array.from({length:a},(m,w)=>{const D=a%2===0?(w-a/2+.5)*C:(w-Math.floor(a/2))*C;return zo(w+1,D,g,i,n)}),h={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-c,y:-I},{x:c,y:-I},{x:c,y:I},{x:-c,y:I},{x:-c,y:-I}],stroke_width:.1,pcb_silkscreen_path_id:""},E=-I+2*s/3,u={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-c,y:E},{x:c,y:E}],stroke_width:.1,pcb_silkscreen_path_id:""},d=[{type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-o/6,y:E},{x:-o/6,y:I}],stroke_width:.1,pcb_silkscreen_path_id:""},{type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:o/6,y:E},{x:o/6,y:I}],stroke_width:.1,pcb_silkscreen_path_id:""}],f=Wi(0,s/2+.6,.5);return{circuitJson:[...Q,h,u,...d,f],parameters:{...A,p:C}}},kwe=Zi.extend({fn:Y(),num_pins:FA(2).default(2),w:Y().default("5.40mm"),h:Y().default("2.30mm"),pl:Y().default("1.30mm"),pw:Y().default("1.70mm"),p:Y().default("3.5mm")}),Fwe=e=>{const A=kwe.parse(e),t=Wi(0,hA.parse(A.h)/2+.4,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:hA.parse(A.p)/2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2,y:-hA.parse(A.h)/2},{x:hA.parse(A.p)/2,y:-hA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:Mwe(A).concat(i,t),parameters:A}},Gwe=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},Mwe=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=Gwe({pn:t,p:Number.parseFloat(e.p)});A.push(di(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},Rwe=Zi.extend({fn:Y(),num_pins:FA(2).default(2),w:Y().default("1.90mm"),h:Y().default("1.33mm"),pl:Y().default("0.5mm"),pw:Y().default("0.7mm"),p:Y().default("0.8mm")}),vwe=e=>{const A=Rwe.parse(e),t=Wi(0,hA.parse(A.h)+.1,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:hA.parse(A.p)/2+.1,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2,y:-hA.parse(A.h)/2},{x:hA.parse(A.p)/2+.1,y:-hA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:Lwe(A).concat(i,t),parameters:A}},Nwe=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},Lwe=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=Nwe({pn:t,p:Number.parseFloat(e.p)});A.push(di(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},Uwe=Zi.extend({fn:Y(),num_pins:FA(2).default(2),w:Y().default("7.0mm"),h:Y().default("3.35mm"),pl:Y().default("1.50mm"),pw:Y().default("2.70mm"),p:Y().default("4.8mm")}),Hwe=e=>{const A=Uwe.parse(e),t=Wi(0,hA.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:hA.parse(A.p)/2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2,y:-hA.parse(A.h)/2},{x:hA.parse(A.p)/2,y:-hA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:Jwe(A).concat(i,t),parameters:A}},Ywe=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},Jwe=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=Ywe({pn:t,p:Number.parseFloat(e.p)});A.push(di(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},Twe=Zi.extend({fn:Y(),num_pins:FA(2).default(2),w:Y().default("3.0mm"),h:Y().default("1.80mm"),pl:Y().default("0.80mm"),pw:Y().default("1.20mm"),p:Y().default("1.6mm")}),Kwe=e=>{const A=Twe.parse(e),t=Wi(0,hA.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:hA.parse(A.p)/2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2-.1,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2-.1,y:-hA.parse(A.h)/2},{x:hA.parse(A.p)/2,y:-hA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:qwe(A).concat(i,t),parameters:A}},Pwe=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},qwe=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=Pwe({pn:t,p:Number.parseFloat(e.p)});A.push(di(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},Owe=Zi.extend({fn:Y(),num_pins:FA(2).default(2),w:Y().default("7.10mm"),h:Y().default("3.40mm"),pl:Y().default("2.45mm"),pw:Y().default("1.80mm"),p:Y().default("4.05mm")}),Wwe=e=>{const A=Owe.parse(e),t=Wi(0,hA.parse(A.h)/2+.5,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:hA.parse(A.p)/2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2-.5,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2-.5,y:-hA.parse(A.h)/2},{x:hA.parse(A.p)/2,y:-hA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:Vwe(A).concat(i,t),parameters:A}},Zwe=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},Vwe=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=Zwe({pn:t,p:Number.parseFloat(e.p)});A.push(di(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},jwe=Zi.extend({fn:Y(),num_pins:FA(2).default(2),w:Y().default("4.80mm"),h:Y().default("2.10mm"),pl:Y().default("1.30mm"),pw:Y().default("1.40mm"),p:Y().default("2.9mm")}),zwe=e=>{const A=jwe.parse(e),t=Wi(0,hA.parse(A.h)-.5,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:hA.parse(A.p)/2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2,y:-hA.parse(A.h)/2},{x:hA.parse(A.p)/2,y:-hA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:$we(A).concat(i,t),parameters:A}},Xwe=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},$we=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=Xwe({pn:t,p:Number.parseFloat(e.p)});A.push(di(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},ADe=Zi.extend({fn:Y(),num_pins:FA(2).default(2),w:Y().default("7.30mm"),h:Y().default("4.40mm"),pl:Y().default("2.50mm"),pw:Y().default("2.30mm"),p:Y().default("4.30mm")}),tDe=e=>{const A=ADe.parse(e),t=Wi(0,hA.parse(A.h)/2+.5,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:hA.parse(A.p)/2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2-.1,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2-.1,y:-hA.parse(A.h)/2},{x:hA.parse(A.p)/2,y:-hA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:iDe(A).concat(i,t),parameters:A}},eDe=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},iDe=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=eDe({pn:t,p:Number.parseFloat(e.p)});A.push(di(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},nDe=Zi.extend({fn:Y(),num_pins:FA(2).default(2),w:Y().default("10.70mm"),h:Y().default("6.60mm"),pl:Y().default("3.30mm"),pw:Y().default("2.50mm"),p:Y().default("6.80mm")}),oDe=e=>{const A=nDe.parse(e),t=Wi(0,3,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:hA.parse(A.p)/2,y:hA.parse(A.h)/2-.8},{x:-hA.parse(A.w)/2-.8,y:hA.parse(A.h)/2-.8},{x:-hA.parse(A.w)/2-.8,y:-hA.parse(A.h)/2+.8},{x:hA.parse(A.p)/2,y:-hA.parse(A.h)/2+.8}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:rDe(A).concat(i,t),parameters:A}},sDe=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},rDe=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=sDe({pn:t,p:Number.parseFloat(e.p)});A.push(di(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},aDe=Zi.extend({fn:Y(),num_pins:ZA().default(4),w:Y().default("8.50mm"),h:Y().default("6.90mm"),pl:Y().default("2mm"),pw:Y().default("1.5mm"),p:Y().default("2.30mm"),string:Y().optional()}),gDe=e=>{const A=e.string?.match(/^sot223_(\d+)/),t=A?Number.parseInt(A[1],10):4;if(t===8){const n=lDe.parse({...e,num_pins:t});return{circuitJson:__(n),parameters:n}}const i=aDe.parse({...e,num_pins:t});if(i.num_pins===4)return{circuitJson:IDe(i),parameters:i};if(i.num_pins===5)return{circuitJson:CDe(i),parameters:i};if(i.num_pins===6)return{circuitJson:hDe(i),parameters:i};throw new Error("Invalid number of pins")},cDe=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}},IDe=e=>{const A=[];for(let r=0;r<e.num_pins;r++){const{x:a,y:g}=cDe({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(di(r+1,a,g,Number.parseFloat(e.pl),c))}const t=Wi(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]},lDe=dD({p:"0.90mm",w:"2.8mm",legsoutside:!0}),BDe=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")},CDe=e=>{const A=[];for(let r=1;r<=e.num_pins;r++){const{x:a,y:g}=BDe({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(di(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=Wi(0,0,.3);return[...A,n,o,s]},QDe=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")},hDe=e=>{const A=[];for(let r=1;r<=e.num_pins;r++){const{x:a,y:g}=QDe({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(di(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=Wi(0,0,.3);return[...A,n,o,s]},EDe=Zi.extend({fn:Y(),num_pins:ZA().default(3),w:Y().default("3.40mm"),h:Y().default("3.30mm"),pl:Y().default("1mm"),pw:Y().default("0.7mm"),p:Y().default("1.2mm"),string:Y().optional()}),uDe=e=>{const A=e.string?.match(/^sot23w_(\d+)/),t=A?Number.parseInt(A[1],3):3,i=EDe.parse({...e,num_pins:t});if(i.num_pins===3)return{circuitJson:pDe(i),parameters:i};throw new Error("Invalid number of pins")},dDe=e=>{const{pn:A,p:t}=e;return A===1?{x:-t,y:.95}:A===2?{x:-t,y:-.95}:{x:t,y:0}},pDe=e=>{const A=[];for(let r=0;r<e.num_pins;r++){const{x:a,y:g}=dDe({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(di(r+1,a,g,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}const t=Wi(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]},fDe=Zi.extend({fn:Y(),num_pins:Ze([FA(3),FA(2)]).default(3),p:Y().default("1.27mm"),id:Y().default("0.72mm"),od:Y().default("0.95mm"),w:Y().default("2.5mm"),h:Y().default("4.2mm"),string:Y().optional()}),yDe=e=>{const{p:A,id:t,od:i,w:n,h:o}=e,s=Number.parseFloat(o)/2,r=Number.parseFloat(A);return[zo(1,-r,s-r,t,i),zo(2,0,s-r,t,i),zo(3,r,s-r,t,i)]},mDe=e=>{const{p:A,id:t,od:i,h:n}=e,o=Number.parseFloat(n)/2,s=Number.parseFloat(A);return[zo(1,-s,o-s,t,i),zo(2,s,o-s,t,i)]},wDe=e=>{const A=e.string?.match(/^to92s_(\d+)/),t=A?Number.parseInt(A[1],10):3,i=fDe.parse({...e,num_pins:t});let n=[];if(i.num_pins===3)n=yDe(i);else if(i.num_pins===2)n=mDe(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=Wi(0,o+1,.5);return{circuitJson:[...n,r,a],parameters:i}},DDe=Zi.extend({fn:Y(),p:hA.optional(),id:hA.optional(),pw:hA.optional(),pl:hA.optional(),w:hA.optional(),h:hA.optional(),sh:Ze([gt(),Y(),ZA()]).optional().transform(e=>{if(typeof e=="string"){const A=Number(e);return Number.isNaN(A)?!0:A}return e}).describe('JST SH (Surface-mount) connector family. SH stands for "Super High-density".'),ph:gt().optional().describe('JST PH (Through-hole) connector family. PH stands for "Pin Header".'),string:Y().optional()}),SDe={ph:{p:hA.parse("2.2mm"),id:hA.parse("0.70mm"),pw:hA.parse("1.20mm"),pl:hA.parse("1.20mm"),w:hA.parse("6mm"),h:hA.parse("5mm")},sh:{p:hA.parse("1mm"),pw:hA.parse("0.6mm"),pl:hA.parse("1.55mm"),w:hA.parse("5.8mm"),h:hA.parse("7.8mm")}};function bDe(e){return e.sh?"sh":(e.ph,"ph")}function xDe(e,A,t,i,n,o){const s=[];if(e==="ph"){const r=t/2;s.push(Cb(1,-r,2,i,n,o)),s.push(Cb(2,r,2,i,n,o))}else{const r=-((A-1)/2)*t;for(let g=0;g<A;g++){const c=r+g*t;console.log("x si",c),s.push(di(g+1,c,-1.325,n,o))}const a=(A-1)/2*t+1.3;console.log("offset",a),s.push(di(A+1,-a,1.22,1.2,1.8)),s.push(di(A+2,a,1.22,1.2,1.8))}return s}function _De(e,A,t){return e==="ph"?{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:""}:{type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[],stroke_width:.1,pcb_silkscreen_path_id:""}}var kDe=e=>{const A=DDe.parse(e),t=bDe(A),i=SDe[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=t==="sh"?4:2;if(t==="sh"){const Q=(typeof e.string=="string"?e.string:"").match(/sh(\d+)/);if(Q&&Q[1]){const h=parseInt(Q[1],10);Number.isNaN(h)||(c=h)}else typeof A.sh=="number"&&(c=A.sh)}const I=xDe(t,c,n,o,s,r),l=_De(t),B=Wi(0,g/2+1,.5);return{circuitJson:[...I,l,B],parameters:{...A,p:n,id:o,pw:s,pl:r,w:a,h:g,num_pins:c,sh:t==="sh",ph:t==="ph"}}},FDe=Zi.extend({fn:Y(),num_pins:FA(2).default(2),w:Y().default("3.30mm"),h:Y().default("1.70mm"),pl:Y().default("0.80mm"),pw:Y().default("1mm"),p:Y().default("1.90mm")}),GDe=e=>{const A=FDe.parse(e),t=Wi(0,hA.parse(A.h)/2+.5,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:hA.parse(A.p)/2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2,y:-hA.parse(A.h)/2},{x:hA.parse(A.p)/2,y:-hA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:RDe(A).concat(i,t),parameters:A}},MDe=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},RDe=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=MDe({pn:t,p:Number.parseFloat(e.p)});A.push(di(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},vDe=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"}}},NDe=Zi.extend({fn:Y(),num_pins:Ze([FA(8),FA(10)]).default(8),w:Y().optional(),h:Y().optional(),p:Y().optional(),pl:Y().optional(),pw:Y().optional(),string:Y().optional()}),LDe=e=>{const A=NDe.parse(e),t=vDe(A.num_pins),i=hA.parse(A.w||t.w),n=hA.parse(A.h||t.h),o=hA.parse(A.p||t.p),s=hA.parse(A.pl||t.pl),r=hA.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}=U6A(A.num_pins,u+1,i,o),m=u<g?u+1:A.num_pins-(u-g);a.push(di(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=U6A(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=Wi(0,I/2+.5,.3);return{circuitJson:[...a,l,B,E,h],parameters:A}},U6A=(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*hA.parse(e===8?"1.8mm":"2.2mm"),y:r*i}},UDe=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"}}},HDe=Zi.extend({fn:Y(),num_pins:Ze([FA(8),FA(10),FA(12),FA(16)]).default(8),w:Y().optional(),h:Y().optional(),p:Y().optional(),pl:Y().optional(),pw:Y().optional(),string:Y().optional()}),H6A=(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*hA.parse("2mm"),y:r*i}},YDe=e=>{const A=HDe.parse(e),t=UDe(A.num_pins),i=hA.parse(A.w||t.w),n=hA.parse(A.h||t.h),o=hA.parse(A.p||t.p),s=hA.parse(A.pl||t.pl),r=hA.parse(A.pw||t.pw),a=[];for(let E=0;E<A.num_pins;E++){const{x:u,y:d}=H6A(A.num_pins,E+1,i,o);a.push(di(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=H6A(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=Wi(0,c/2+.5,.3);return{circuitJson:[...a,I,l,h,Q],parameters:A}},JDe=Zi.extend({fn:Y(),num_pins:FA(2).default(2),w:Y().default("3.8mm"),h:Y().default("1.65mm"),pl:Y().default("1.2mm"),pw:Y().default("1.2mm"),pad_spacing:Y().default("2.6mm")}),TDe=e=>{const A=JDe.parse(e),t=Wi(0,hA.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:hA.parse(A.pad_spacing)/2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2-.2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2-.2,y:-hA.parse(A.h)/2},{x:hA.parse(A.pad_spacing)/2,y:-hA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:PDe(A).concat(i,t),parameters:A}},KDe=e=>{const{pn:A,pad_spacing:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},PDe=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=KDe({pn:t,pad_spacing:Number.parseFloat(e.pad_spacing)});A.push(di(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},qDe=Zi.extend({fn:Y(),num_pins:FA(2).default(2),w:Y().default("3.20mm"),h:Y().default("1.65mm"),pl:Y().default("0.8mm"),pw:Y().default("0.9mm"),pad_spacing:Y().default("2.1mm")}),ODe=e=>{const A=qDe.parse(e),t=Wi(0,hA.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:hA.parse(A.pad_spacing)/2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2-.2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2-.2,y:-hA.parse(A.h)/2},{x:hA.parse(A.pad_spacing)/2,y:-hA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:ZDe(A).concat(i,t),parameters:A}},WDe=e=>{const{pn:A,pad_spacing:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},ZDe=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=WDe({pn:t,pad_spacing:Number.parseFloat(e.pad_spacing)});A.push(di(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},VDe=Zi.extend({fn:Y(),num_pins:Ze([FA(6),FA(8)]).default(8),w:Y().default("3mm"),h:Y().default("3mm"),p:Y().default("0.5mm"),pl:Y().default("0.52mm"),pw:Y().default("0.35mm"),epw:Y().default("1.40mm"),eph:Y().default("1.60mm"),string:Y().optional(),ep:gt().default(!1)}),jDe=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=VDe.parse({...e,num_pins:t}),n=hA.parse(i.w),o=hA.parse(i.h),s=hA.parse(i.p),r=hA.parse(i.pl),a=hA.parse(i.pw),g=hA.parse(i.epw),c=hA.parse(i.eph),I=[];for(let f=0;f<i.num_pins;f++){const{x:m,y:w}=Y6A(i.num_pins,f+1,n,s);I.push(di(f+1,m,w,r,a))}i.ep&&I.push(di(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=Y6A(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=Wi(0,B/2+.5,.3);return{circuitJson:[...I,C,Q,d,u],parameters:i}},Y6A=(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*hA.parse("1.4mm"),y:r*i}},zDe=e=>{const{num_pins:A,bridged:t,p:i=2.54,pw:n=1.5,ph:o=1.5}=e,s=hA.parse(i),r=hA.parse(n),a=hA.parse(o),g=Math.min(a/4,.5),c=[];for(let f=0;f<A;f++)c.push(di(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 b=(w-1)*s,k=(D-1)*s,x=Math.sign(k-b),v=b+x*(r/2),R=k-x*(r/2);I.push({type:"pcb_trace",pcb_trace_id:"",route:[{start_pcb_port_id:`{PIN${w}}`,x:v,y:0,width:g,layer:"top",route_type:"wire"},{end_pcb_port_id:`{PIN${D}}`,x:R,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=Wi(C,u,.4);return{circuitJson:[...c,...I,h,d],parameters:e}},J6A={fn:FA("sot457"),num_pins:FA(6).default(6),pillh:Y().default("0.45mm"),pillw:Y().default("1.45mm"),pl:Y(),pw:Y(),p:Y(),wave:gt().optional(),reflow:gt().optional()},XDe=Zi.extend({...J6A,h:Y().default("2.5mm"),w:Y().default("2.7mm"),pl:Y().default("0.8mm"),pw:Y().default("0.55mm"),p:Y().default("0.95mm")}),$De=Zi.extend({...J6A,h:Y().default("3mm"),w:Y().default("4mm"),pillr:Y().default("0.225mm"),pl:Y().default("1.45mm"),pw:Y().default("1.5mm"),p:Y().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)})),Qb=e=>Number.parseFloat(e.replace("mm","")),T6A=({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},K6A=e=>{const A=[],t=Qb(e.p),i=Qb(e.pl),n=Qb(e.pw),o=Qb(e.w),s=Qb(e.h);if(e.wave){const C={1:({padWidth:Q,padHeight:h})=>di(1,-t,t,h,Q),2:({padWidth:Q,padHeight:h})=>di(2,-t,-t,h,Q),3:({padWidth:Q,padHeight:h})=>KW(3,-t,0,Qb(e.pillw),Qb(e.pillh)),4:({padWidth:Q,padHeight:h})=>KW(4,t,0,Qb(e.pillw),Qb(e.pillh)),5:({padWidth:Q,padHeight:h})=>di(5,t,t,h,Q),6:({padWidth:Q,padHeight:h})=>di(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}=T6A({pitch:t,width:o,pinNumber:C});A.push(di(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=Wi(0,s+.5,.3),c=T6A({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]},ASe=e=>{if(e.wave){const t=$De.parse({...e,fn:"sot457"});return{circuitJson:K6A(t),parameters:t}}const A=XDe.parse(e);return{circuitJson:K6A(A),parameters:A}},tSe=Zi.extend({fn:Y(),num_pins:FA(6).default(6),w:Y().default("1.1mm"),h:Y().default("1.45mm"),p:Y().default("0.35mm"),pl:Y().default("0.2mm"),pw:Y().default("0.2mm"),string:Y().optional()}),eSe=e=>{const A=tSe.parse({...e,fn:"sot963"}),t=hA.parse(A.w),i=hA.parse(A.h),n=hA.parse(A.p),o=hA.parse(A.pl),s=hA.parse(A.pw),r=[];for(let B=0;B<6;B++){const{x:C,y:Q}=P6A(B+1,t,n,o);r.push(di(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=P6A(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=Wi(0,i/2+.4,.25);return{circuitJson:[...r,a,g,l,I],parameters:A}},P6A=(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}},iSe=Zi.extend({fn:Y(),num_pins:Ze([FA(3),FA(2)]).default(3),p:Y().default("3.8mm"),id:Y().default("1.25mm"),od:Y().default("2.35mm"),ca:Y().default("14mm").describe("Caliper axis (width or diameter of the potentiometer body or adjustment knob)"),w:Y().default("5.35mm"),h:Y().default("4mm"),string:Y().optional()}),nSe=e=>{const{p:A,id:t,od:i,h:n,ca:o}=e,s=Number.parseFloat(n),r=Number.parseFloat(o);return[zo(1,0,r/4+.3,t,i),zo(2,s,0,t,i),zo(3,0,-r/4-.3,t,i)]},oSe=e=>{const A=e.string?.match(/^potentiometer_(\d+)/),t=A?Number.parseInt(A[1],10):3,i=iSe.parse({...e,num_pins:t});let n=[];i.num_pins===3&&(n=nSe(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=Wi(c,o+1,.5);return{circuitJson:[...n,a,g,I],parameters:i}},sSe=Zi.extend({fn:Y(),p:hA.optional().default("7.5mm"),id:hA.optional().default("1mm"),od:hA.optional().default("2mm"),d:hA.optional().default("10.5mm")}),rSe=(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}},aSe=e=>{const A=sSe.parse(e),{p:t,id:i,od:n,d:o}=A,s=[zo(1,-t/2,0,i,n),zo(2,t/2,0,i,n)],{topArc:r,bottomArc:a}=rSe(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=Wi(0,o/2+1,.5);return{circuitJson:[...s,g,c,I,Q,h,E],parameters:A}},gSe=Zi.extend({fn:Y(),num_pins:FA(2).default(2),w:Y().default("6.5mm"),h:Y().default("3mm"),pl:Y().default("1.75mm"),pw:Y().default("2.40mm"),p:Y().default("4.75mm")}),cSe=e=>{const A=gSe.parse(e),t=Wi(0,hA.parse(A.h)-.5,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:hA.parse(A.p)/2,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2-.3,y:hA.parse(A.h)/2},{x:-hA.parse(A.w)/2-.3,y:-hA.parse(A.h)/2},{x:hA.parse(A.p)/2,y:-hA.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:lSe(A).concat(i,t),parameters:A}},ISe=e=>{const{pn:A,p:t}=e;return A===1?{x:-t/2,y:0}:{x:t/2,y:0}},lSe=e=>{const A=[];for(let t=1;t<=e.num_pins;t++){const{x:i,y:n}=ISe({pn:t,p:Number.parseFloat(e.p)});A.push(di(t,i,n,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}return A},BSe=Zi.extend({fn:Y(),num_pins:ZA().default(3),w:Y().default("2.45mm"),h:Y().default("2.40mm"),pl:Y().default("1.225mm"),pw:Y().default("0.5mm"),p:Y().default("0.95mm"),string:Y().optional()}),CSe=e=>{const A=e.string?.match(/^sot323_(\d+)/),t=A?Number.parseInt(A[1],3):3,i=BSe.parse({...e,num_pins:t});if(i.num_pins===3)return{circuitJson:hSe(i),parameters:i};throw new Error("Invalid number of pins")},QSe=e=>{const{pn:A,p:t}=e;return A===1?{x:-t,y:.65}:A===2?{x:-t,y:-.65}:{x:t,y:0}},hSe=e=>{const A=[];for(let r=0;r<e.num_pins;r++){const{x:a,y:g}=QSe({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(di(r+1,a,g,Number.parseFloat(e.pl),Number.parseFloat(e.pw)))}const t=Wi(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]},ESe=Zi.extend({fn:Y(),circle:gt().optional(),rect:gt().optional(),square:gt().optional(),pill:gt().optional(),d:hA.optional(),pd:hA.optional(),diameter:hA.optional(),r:hA.optional(),pr:hA.optional(),radius:hA.optional(),w:hA.optional(),pw:hA.optional(),width:hA.optional(),h:hA.optional(),ph:hA.optional(),height:hA.optional(),s:hA.optional(),size:hA.optional(),string:Y().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=Fr(e.r):e.pr!==void 0?t=Fr(e.pr):e.radius!==void 0?t=Fr(e.radius):e.d!==void 0?t=Fr(e.d)/2:e.pd!==void 0?t=Fr(e.pd)/2:e.diameter!==void 0?t=Fr(e.diameter)/2:t=Fr("1mm")/2:(e.w!==void 0?i=Fr(e.w):e.pw!==void 0?i=Fr(e.pw):e.width!==void 0?i=Fr(e.width):e.s!==void 0?i=Fr(e.s):e.size!==void 0?i=Fr(e.size):i=Fr("1mm"),e.h!==void 0?n=Fr(e.h):e.ph!==void 0?n=Fr(e.ph):e.height!==void 0?n=Fr(e.height):A==="square"||A==="rect"?n=i:n=Fr("1mm")),{fn:e.fn,shape:A,radius:t,width:i,height:n}}),uSe=e=>{const A=ESe.parse(e),{shape:t,radius:i,width:n,height:o}=A;let s,r;return t==="circle"?(s=w6A(1,{x:0,y:0,radius:i}),r=i+.5):t==="pill"?(s=KW(1,0,0,n,o),r=Math.max(n,o)/2+.5):(s=di(1,0,0,n,o),r=o/2+.5),{circuitJson:[s,Wi(0,r,.2)],parameters:A}},dSe=Zi.extend({fn:Y(),d:hA.optional(),hd:hA.optional(),r:hA.optional(),hr:hA.optional(),pd:hA.optional(),pr:hA.optional(),squarepad:gt().optional().default(!1)}).transform(e=>{let A;e.d!==void 0?A=Fr(e.d):e.hd!==void 0?A=Fr(e.hd):e.r!==void 0?A=Fr(e.r)*2:e.hr!==void 0?A=Fr(e.hr)*2:A=Fr("1mm");let t;return e.pd!==void 0?t=Fr(e.pd):e.pr!==void 0?t=Fr(e.pr)*2:t=A*(1.5/1),{fn:e.fn,d:A,pd:t,squarepad:e.squarepad??!1}}),pSe=e=>{const A=dSe.parse(e),{d:t,pd:i,squarepad:n}=A;return{circuitJson:[n?Cb(1,0,0,t,i,i):zo(1,0,0,t,i),Wi(0,i/2+.5,.2)],parameters:A}},fSe=Zi.extend({fn:Y(),num_pins:FA(6).default(6),h:Y().default("1.6mm"),pl:Y().default("1mm"),pw:Y().default("0.7mm"),p:Y().default("0.95mm")}),ySe=e=>{const A=fSe.parse(e);return{circuitJson:mSe(A),parameters:A}},q6A=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")},mSe=e=>{const A=[];for(let I=1;I<=e.num_pins;I++){const{x:l,y:B}=q6A({h:Number.parseFloat(e.h),p:Number.parseFloat(e.p),pn:I});A.push(di(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=Wi(0,i+.3,.3),r=q6A({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]},wSe=Zi.extend({fn:Y(),num_pins:ZA().default(4),w:Y().default("3.2mm"),h:Y().default("2.6mm"),pl:Y().default("1.35mm"),pw:Y().default("0.50mm"),p:Y().default("0.6mm"),string:Y().optional()}),DSe=e=>{const A=e.string?.match(/^sot343_(\d+)/),t=A?Number.parseInt(A[1],4):4,i=wSe.parse({...e,num_pins:t});if(i.num_pins===4)return{circuitJson:bSe(i),parameters:i};throw new Error("Invalid number of pins")},SSe=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}},bSe=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}=SSe({num_pins:e.num_pins,pn:d+1,p:s});A.push(di(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=Wi(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]},xSe=Zi.extend({fn:Y()}),_Se=e=>{const A=xSe.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 b=D+1;if(b>=24&&b<=31)continue;const k=a-D*s,x=b%2===0,v=n+(x?.25:0),U=.5-v/2,J=di(b,U,k,v,i);J.layer=x?"bottom":"top",t.push(J)}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,b,k=0,x=0)=>{Q=Math.min(Q,D-k/2),h=Math.max(h,D+k/2),E=Math.min(E,b-x/2),u=Math.max(u,b+x/2)};for(const D of t)d(D.x,D.y,D.width,D.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(b=>({x:b.x-f,y:b.y-m})))};for(const D of t)w(D);return w(l),w(C),{circuitJson:[...t,l,C],parameters:A}},kSe=Zi.extend({fn:Y(),num_pins:ZA().default(3),inline:gt().default(!1),p:Y().default("1.27mm"),id:Y().default("0.75mm"),od:Y().default("1.3mm"),w:Y().default("4.8mm"),h:Y().default("4.0mm")}),FSe=e=>{const A=kSe.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=[Cb(1,0,0,A.id,o,s,0,0),A.inline?kH(2,t,0,A.id,o,s):zo(2,t,t,A.id,o),A.inline?kH(3,t*2,0,A.id,o,s):zo(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=Wi(g,c+a+1,.5);return{circuitJson:[...r,B,C],parameters:A}};function GSe(e){return e!=null}var MSe=(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=1/0,n=-1/0,o=1/0,s=-1/0;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},RSe=(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},vSe=(e,A)=>A.nosilkscreen?e.filter(t=>t.type!=="pcb_silkscreen_path"&&t.type!=="pcb_silkscreen_text"):e,NSe=e=>{let A=WW();const i=e.replace(/^((?:\d{4}|\d{5}))(?=$|_)/,"res$1").split(/_(?!metric)/).map(n=>{const o=n.match(/([a-zA-Z]+)([\(\d\.\+\?].*)?/);if(!o)return null;const[,s,r]=o;if(!s)return null;const a=s.toLowerCase();return r?.includes("?")?null:{fn:a,v:r}}).filter(GSe);for(const{fn:n,v:o}of i)A=A[n](o);return A.setString(e),A},LSe=()=>Object.keys(Bb),WW=()=>{const e=new Proxy({},{get:(A,t)=>{if(t==="soup"||t==="circuitJson"){if("fn"in A&&Bb[A.fn])return()=>{const{circuitJson:i}=Bb[A.fn](A),n=vSe(i,A),o=RSe(n,A);return MSe(o,A.origin)};if(!Bb[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(!Bb[A.fn])throw new Error(`Invalid footprint function, got "${A.fn}"${A.string?`, from string "${A.string}"`:""}`);return()=>Bb[A.fn](A).parameters}return t==="getFootprintNames"?()=>Object.keys(Bb):t==="params"?()=>A:t==="setString"?i=>(A.string=i,e):i=>(Object.keys(A).length===0?`${t}${i}`in Bb?(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};WW.string=NSe,WW.getFootprintNames=LSe;var USe=WW,O6A=Symbol("Fragment");function EEA(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"),W6A=Symbol("Cube"),Gl=Symbol("Cylinder"),ZW=Symbol("Sphere"),FH=Symbol("RoundedCuboid"),Pi=Symbol("Translate"),VB=Symbol("Rotate"),FQ=Symbol("Union"),rw=Symbol("Subtract"),hc=Symbol("Hull"),Ko=Symbol("Colorize"),GH=Symbol("Polygon"),MH=Symbol("ExtrudeLinear"),lf=Symbol("RoundedCylinder"),Rn=O6A,XA=(e,A,t)=>EEA(e,A),Te=(e,A,t)=>EEA(e,A),aB=({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},b=I??D,k=Te(FQ,{children:[Te(hc,{children:[XA(Pi,{z:.005,children:XA(Qe,{size:[d,f,.01]})}),XA(Pi,{z:h,children:XA(Qe,{size:[A,t,.01]})})]}),Te(hc,{children:[XA(Pi,{z:h,children:XA(Qe,{size:[A,t,.01]})}),XA(Pi,{z:h+E,children:XA(Qe,{size:[d,f,.01]})})]})]}),x=(R,U)=>XA(Pi,{offset:{x:R,y:U,z:0},children:XA(VB,{rotation:[0,0,Math.PI/4],children:XA(Qe,{size:[Q*Math.SQRT2,Q*Math.SQRT2,i*3]})})});let v=k;if(Q>0){const R=A/2,U=t/2;v=Te(rw,{children:[k,x(R,U),x(-R,U),x(R,-U),x(-R,-U)]})}return XA(Ko,{color:o,children:XA(Pi,{offset:e,children:XA(Pi,{offset:{x:0,y:0,z:n},children:g?Te(rw,{children:[v,XA(Pi,{offset:b,children:XA(VB,{rotation:l,children:XA(Gl,{radius:w,height:C})})})]}):v})})})},HSe=e=>Array.from({length:e},(A,t)=>t);function uEA(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 YSe=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}))},JSe=YSe([{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}]),Z6A=5.47,VW=.5,TSe=({x:e,y:A,z:t})=>{const i=e>0;return Te(Rn,{children:[XA(Pi,{offset:{x:e+.25/2,y:A,z:t},children:XA(VB,{rotation:["-90deg",0,"90deg"],children:XA(MH,{height:.25,children:XA(GH,{points:JSe.slice().reverse().map(n=>[n.x,n.y])})})})}),XA(Pi,{offset:{x:e,y:A+(i?1:-1),z:t},children:XA(VB,{rotation:["-90deg","90deg",i?"180deg":"0deg"],children:XA(MH,{height:2,children:XA(GH,{points:uEA([[0,0],[-1,0],[-1,-1]],.25).map(n=>[n.x,n.y])})})})})]})},KSe=({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 Te(Rn,{children:[HSe(e).map(r=>{const a=r%n,g=(Math.floor(r/n)-.5)*2;return XA(TSe,{x:g*o/2,y:a*A-(n-1)/2*A,z:Z6A/2+VW})}),XA(aB,{width:s,length:n*A+.5,height:Z6A-VW,heightAboveSurface:VW,center:{x:0,y:0,z:VW}})]})};function PSe(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 zn=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,PSe(c,e)]),g=uEA(a,A);return XA(Ko,{color:"#fff",children:XA(Pi,{offset:{z:0,y:0,x:0,...e.position},children:XA(VB,{rotation:["90deg",0,s??0],children:XA(Pi,{offset:{x:0,y:0,z:-t/2},children:XA(MH,{height:t,children:XA(GH,{points:g.map(c=>[c.x,c.y])})})})})})})},qSe=({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 Te(Rn,{children:[Array.from({length:o}).map((g,c)=>XA(zn,{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)=>XA(zn,{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})),XA(aB,{center:{x:0,y:0,z:a/2},width:n-t-1,length:s,height:1.5})]})},OSe=({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 Te(Rn,{children:[Array.from({length:o}).map((a,g)=>XA(zn,{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)=>XA(zn,{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})),XA(aB,{center:{x:0,y:0,z:r/2},width:n,length:n,height:1.1,notchRadius:.35,heightAboveSurface:.1,taperRatio:.09})]})},dEA=1,pEA=.5,lN=.5,RH=.2,WSe=dEA-RH*2,V6A=({color:e="#333"})=>Te(Rn,{children:[XA(Qe,{size:[WSe,pEA,lN],offset:[0,0,lN/2],color:e}),XA(Qe,{size:[RH,lN,pEA],offset:[dEA/2-RH/2,0,lN/2],color:"#ccc"}),XA(Qe,{size:[RH,lN,pEA],offset:[-dEA/2+RH/2,0,lN/2],color:"#ccc"})]}),fEA=1.6,ZSe=fEA-.3*2,jW=.3,yEA=.85,BN=.6,j6A=({color:e="#333"})=>Te(Rn,{children:[XA(Qe,{size:[ZSe,yEA,BN],offset:[0,0,BN/2],color:e}),XA(Qe,{size:[jW,yEA,BN],offset:[fEA/2-jW/2,0,BN/2],color:"#ccc"}),XA(Qe,{size:[jW,yEA,BN],offset:[-fEA/2+jW/2,0,BN/2],color:"#ccc"})]}),mEA=2,wEA=1.25,CN=.55,vH=.5,VSe=mEA-vH*2,z6A=({color:e="#333"})=>Te(Rn,{children:[XA(Qe,{size:[VSe,wEA,CN],offset:[0,0,CN/2],color:e}),XA(Qe,{size:[vH,wEA,CN],offset:[mEA/2-vH/2,0,CN/2],color:"#ccc"}),XA(Qe,{size:[vH,wEA,CN],offset:[-mEA/2+vH/2,0,CN/2],color:"#ccc"})]}),jSe=({pinCount:e,pitch:A,leadWidth:t,padContactLength:i,bodyWidth:n})=>{const o=e/4;A||(A=zSe(e,n)),i||(i=XSe(e)),t||(t=$Se(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 Te(Rn,{children:[Array.from({length:o}).map((B,C)=>XA(zn,{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)=>XA(zn,{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)=>XA(zn,{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)=>XA(zn,{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})),XA(aB,{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})]})},zSe=(e,A)=>{switch(e){case 44:case 64:return .8;case 52:return A===14?1:.65;case 208:return .5;default:return .5}},XSe=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}},$Se=(e,A)=>{switch(e){case 44:case 64:return .5;case 52:return A===14?.45:.55;case 208:return .3;default:return .25}},X6A=({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})=>Te(Rn,{children:[XA(Pi,{y:I?-3:0,children:XA(Qe,{color:"#222",size:[s,r,o],center:[e,A,a(o/2)]})}),!g&&XA(Ko,{color:"gold",children:c?XA(zn,{rotation:-Math.PI/2,position:{x:e,y:A+1,z:t/2},thickness:t,width:t,height:t,padContactLength:2,bodyDistance:3}):Te(hc,{children:[XA(Qe,{color:"gold",size:[t,t,i*.9],center:[e,A,a(o*.9+o/2)]}),XA(Qe,{color:"gold",size:[t/1.8,t/1.8,i],center:[e,A,a(o+o/2)]})]})}),XA(Ko,{color:"gold",children:XA(Pi,{y:I?-3.9:0,z:I?1:0,children:XA(VB,{rotation:I?[-Math.PI/2,0,0]:[0,0,0],children:Te(hc,{children:[XA(Qe,{color:"gold",size:[t,t,n*.9],center:[e,A,a(-n/2*.9)]}),XA(Qe,{color:"gold",size:[t/1.8,t/1.8,n],center:[e,A,a(-n/2)]})]})})})})]}),Abe=({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 XA(Rn,{children:Array.from({length:e},(h,E)=>{const u=Math.floor(E/c),d=E%c,f=B+d*A,m=-u*I;return XA(X6A,{x:f,y:m,pinThickness:.63,shortSidePinLength:l,longSidePinLength:t,bodyHeight:2,flipZ:Q,faceup:n,smd:s,rightangle:r},E)})})},tbe=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")}},ebe=({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},ibe=({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=ebe({num_pins:e,cw:!0,ccw:!0}),c=[];for(let I=0;I<e;I++){const{x:l,y:B,o:C}=tbe({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 Te(Rn,{children:[XA(Ko,{color:"grey",children:XA(Qe,{center:{x:0,y:0,z:i/2},size:[A,t,i]})}),c.map((I,l)=>XA(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&&XA(Qe,{center:{x:0,y:0,z:a/2},size:[n.width,n.length,a]})]})},nbe=ibe,obe=()=>{const a=1.1999999999999997;return Te(Rn,{children:[XA(zn,{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}),XA(zn,{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}),XA(zn,{position:{x:-2.8/2-a/4,y:0,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:a,height:.95}),XA(zn,{position:{x:-2.8/2-a/4,y:-1,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:a,height:.95}),XA(zn,{position:{x:-2.8/2-a/4,y:1,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:a,height:.95}),XA(aB,{center:{x:0,y:0,z:0},width:1.6,length:2.9,height:1.2})]})},sbe=obe,rbe=({fullWidth:e=2.9,fullLength:A=2.8})=>{const c=(e-1.92)/2+.3;return Te(Rn,{children:[XA(zn,{rotation:Math.PI,position:{x:e/2,y:0,z:.075},width:.4,thickness:.15,padContactLength:.25,bodyDistance:c,height:.45}),XA(zn,{position:{x:-e/2,y:-.95,z:.075},width:.4,thickness:.15,padContactLength:.25,bodyDistance:c,height:.45}),XA(zn,{position:{x:-e/2,y:.95,z:.075},width:.4,thickness:.15,padContactLength:.25,bodyDistance:c,height:.45}),XA(aB,{center:{x:0,y:0,z:0},width:1.92,length:2.9,height:1.1,straightHeightRatio:.45,heightAboveSurface:.05})]})},DEA=.6,SEA=.3,QN=.33,NH=.1,abe=DEA-NH*2,$6A=({color:e="#333"})=>Te(Rn,{children:[XA(Qe,{size:[abe,SEA,QN],offset:[0,0,QN/2],color:e}),XA(Qe,{size:[NH,SEA,QN],offset:[DEA/2-NH/2,0,QN/2],color:"#ccc"}),XA(Qe,{size:[NH,SEA,QN],offset:[-DEA/2+NH/2,0,QN/2],color:"#ccc"})]}),bEA=.4,xEA=.2,hN=.13,LH=.07,gbe=bEA-LH*2,A7A=({color:e="#333"})=>Te(Rn,{children:[XA(Qe,{size:[gbe,xEA,hN],offset:[0,0,hN/2],color:e}),XA(Qe,{size:[LH,xEA,hN],offset:[bEA/2-LH/2,0,hN/2],color:"#ccc"}),XA(Qe,{size:[LH,xEA,hN],offset:[-bEA/2+LH/2,0,hN/2],color:"#ccc"})]}),_EA=3.2,kEA=1.6,EN=.9,UH=.5,cbe=_EA-UH*2,t7A=({color:e="#333"})=>Te(Rn,{children:[XA(Qe,{size:[cbe,kEA,EN],offset:[0,0,EN/2],color:e}),XA(Qe,{size:[UH,kEA,EN],offset:[_EA/2-UH/2,0,EN/2],color:"#ccc"}),XA(Qe,{size:[UH,kEA,EN],offset:[-_EA/2+UH/2,0,EN/2],color:"#ccc"})]}),FEA=3.2,GEA=2.5,uN=1,HH=.6,Ibe=FEA-HH*2,e7A=({color:e="#333"})=>Te(Rn,{children:[XA(Qe,{size:[Ibe,GEA,uN],offset:[0,0,uN/2],color:e}),XA(Qe,{size:[HH,GEA,uN],offset:[FEA/2-HH/2,0,uN/2],color:"#ccc"}),XA(Qe,{size:[HH,GEA,uN],offset:[-FEA/2+HH/2,0,uN/2],color:"#ccc"})]}),MEA=5,REA=2.5,dN=1.4,YH=.6,lbe=MEA-YH*2,i7A=({color:e="#333"})=>Te(Rn,{children:[XA(Qe,{size:[lbe,REA,dN],offset:[0,0,dN/2],color:e}),XA(Qe,{size:[YH,REA,dN],offset:[MEA/2-YH/2,0,dN/2],color:"#ccc"}),XA(Qe,{size:[YH,REA,dN],offset:[-MEA/2+YH/2,0,dN/2],color:"#ccc"})]}),vEA=6.3,NEA=3.2,pN=1.8,JH=.8,Bbe=vEA-JH*2,n7A=({color:e="#333"})=>Te(Rn,{children:[XA(Qe,{size:[Bbe,NEA,pN],offset:[0,0,pN/2],color:e}),XA(Qe,{size:[JH,NEA,pN],offset:[vEA/2-JH/2,0,pN/2],color:"#ccc"}),XA(Qe,{size:[JH,NEA,pN],offset:[-vEA/2+JH/2,0,pN/2],color:"#ccc"})]}),Cbe=({x:e,y:A,pitch:t=2.54,legsLength:i=3,innerDiameter:n=.945,bodyHeight:o=5,bodyLength:s=t,bodyWidth:r=t,flipZ:a})=>{const g=n/1.5,c=g*1.6;return Te(Rn,{children:[XA(Ko,{color:"#1a1a1a",children:Te(rw,{children:[XA(Qe,{color:"#000",size:[s,r,o],center:[e,A,a(o/2)]}),n?XA(Gl,{height:o+.1,radius:n/2,center:[e,A,a(o/2)],color:"#222"}):XA(Qe,{size:[c,c,o],center:[e,A,a(o/2)]})]})}),Te(Ko,{color:"silver",children:[Te(hc,{children:[XA(Qe,{color:"silver",size:[g,g,i*.9],center:[e,A,a(-i/2*.9)]}),XA(Qe,{color:"silver",size:[g/1.8,g/1.8,i],center:[e,A,a(-i/2)]})]}),XA(Qe,{color:"silver",size:[c,c,c*.5],center:[e,A,a(c/2*.5)]})]})]})},Qbe=({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 XA(Rn,{children:Array.from({length:e},(I,l)=>{const B=Math.floor(l/r),C=l%r,Q=g+C*A,h=-B*a;return XA(Cbe,{x:Q,y:h,pitch:A,legsLength:t,innerDiameter:i,flipZ:c},l)})})},hbe=({width:e,length:A,innerDiameter:t=1})=>{const i=e,n=A,o=e*.7,s=t/2.5;return Te(Rn,{children:[XA(FH,{color:"#1a1a1f",center:[0,0,o/2],size:[n,n,o],roundRadius:.3}),XA(FH,{color:"#f2f2f2",center:[0,0,o+o*.1/2.5],size:[n,n,o*.1],roundRadius:.14}),XA(Gl,{color:"#1a1a1f",height:o*.8,radius:i/3,center:[0,0,o+o*.8/2]}),XA(Gl,{color:"#1a1a1f",height:o*.2,radius:t/2,center:[n/3,n/3,o+o*.1/2]}),XA(Gl,{color:"#1a1a1f",height:o*.2,radius:t/2,center:[-n/3,-n/3,o+o*.1/2]}),XA(Gl,{color:"#1a1a1f",height:o*.2,radius:t/2,center:[-n/3,n/3,o+o*.1/2]}),XA(Gl,{color:"#1a1a1f",height:o*.2,radius:t/2,center:[n/3,-n/3,o+o*.1/2]}),XA(zW,{thickness:t/3,width:s,horizontalLength:n*.8,verticalLength:o/2,position:{x:-i/2,y:-n/2,z:-o*1.2}}),XA(zW,{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}),XA(zW,{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}),XA(zW,{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}})]})},zW=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=uEA(r,A);return XA(Ko,{color:"#f2f2f2",children:XA(Pi,{offset:{x:s?.x||0,y:s?.y||0,z:s?.z||0},children:XA(VB,{rotation:[0,55,o],children:XA(MH,{height:t,children:XA(GH,{points:a.map(g=>[g.y,g.x])})})})})})},Ebe=({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 Te(Rn,{children:[Array.from({length:o}).map((B,C)=>XA(zn,{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)=>XA(zn,{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})),XA(aB,{center:{x:0,y:0,z:r/2},width:l,length:I,height:a})]})},ube=({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 Te(Rn,{children:[Array.from({length:I}).map((u,d)=>XA(zn,{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)=>XA(zn,{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})),XA(aB,{center:{x:0,y:0,z:B/2},width:g,length:c,height:1})]})},dbe=()=>Te(Rn,{children:[XA(Qe,{color:"#ccc",size:[.5,.6,.12],center:[-.725,0,.12/2]}),XA(Qe,{color:"#ccc",size:[.5,.6,.12],center:[.725,0,.12/2]}),XA(Ko,{color:"#222",children:Te(FQ,{children:[XA(Pi,{z:.3/2,children:XA(Qe,{size:[1.65,.8,.3]})}),Te(hc,{children:[XA(Pi,{z:.3,children:XA(Qe,{size:[1.65,.8,.01]})}),XA(Pi,{z:.6,children:XA(Qe,{size:[1.65-.2,.8-.2,.01]})})]})]})})]}),pbe=()=>Te(Rn,{children:[XA(Qe,{color:"#ccc",size:[.26,.51,.12],center:[-.325,0,.12/2]}),XA(Qe,{color:"#ccc",size:[.26,.51,.12],center:[.325,0,.12/2]}),XA(Ko,{color:"#222",children:XA(Pi,{z:.47/2+.02,children:XA(Qe,{size:[.98,.58,.47]})})}),XA(Qe,{color:"#ccc",size:[.98+.001,.26/2,.26/4],center:[0,.26/2,.47/4]}),XA(Qe,{color:"#ccc",size:[.98+.001,.26/2,.26/4],center:[0,-.26/2,.47/4]}),XA(Qe,{color:"#ccc",size:[.26/1.5,.58+.001,.26/4],center:[.65/2,0,.47/4]}),XA(Qe,{color:"#ccc",size:[.26/1.5,.58+.001,.26/4],center:[-.65/2,0,.47/4]})]}),fbe=()=>{const g=XA(Ko,{color:"#1a1a1a",children:Te(FQ,{children:[Te(hc,{children:[XA(Pi,{z:.13,children:XA(Qe,{size:[4,3,.03]})}),XA(Pi,{z:1.15,children:XA(Qe,{size:[4.4,3.4,.01]})})]}),Te(hc,{children:[XA(Pi,{z:1.15,children:XA(Qe,{size:[4.4,3.4,.01]})}),XA(Pi,{z:2.3,children:XA(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 XA(Ko,{color:"#c0c0c0",children:Te(FQ,{children:[XA(Qe,{size:[2.3*.8,1.45,.2],center:[C,0,.2/2]}),XA(Qe,{size:[.2,1.45,1.14],center:[Q,0,1.14/2+.2]}),XA(Qe,{size:[E,1.45,.2],center:[u,0,.2/2+1.14]})]})})};return Te(Rn,{children:[XA(c,{xDir:1}),XA(c,{xDir:-1}),g]})},ybe=()=>{const g=XA(Ko,{color:"#1a1a1a",children:Te(FQ,{children:[Te(hc,{children:[XA(Pi,{z:.13,children:XA(Qe,{size:[4,3,.03]})}),XA(Pi,{z:1.15,children:XA(Qe,{size:[4.4,3.4,.01]})})]}),Te(hc,{children:[XA(Pi,{z:1.15,children:XA(Qe,{size:[4.4,3.4,.01]})}),XA(Pi,{z:2.3,children:XA(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 XA(Ko,{color:"#c0c0c0",children:Te(FQ,{children:[XA(Qe,{size:[2.3*.8,1.45,.2],center:[C,0,.2/2]}),XA(Qe,{size:[.2,1.45,1.14],center:[Q,0,1.14/2+.2]}),XA(Qe,{size:[E,1.45,.2],center:[u,0,.2/2+1.14]})]})})};return Te(Rn,{children:[XA(c,{xDir:1}),XA(c,{xDir:-1}),g]})},mbe=()=>{const g=XA(Ko,{color:"#1a1a1a",children:Te(FQ,{children:[Te(hc,{children:[XA(Pi,{z:.21000000000000002,children:XA(Qe,{size:[6.3999999999999995,5.6,.03]})}),XA(Pi,{z:1.15,children:XA(Qe,{size:[6.8,6,.01]})})]}),Te(hc,{children:[XA(Pi,{z:1.15,children:XA(Qe,{size:[6.8,6,.01]})}),XA(Pi,{z:2.3,children:XA(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 XA(Ko,{color:"#c0c0c0",children:Te(FQ,{children:[XA(Qe,{size:[2.3*.8,2.95,.2],center:[C,0,.2/2]}),XA(Qe,{size:[.2,2.95,1.14],center:[Q,0,1.14/2+.2]}),XA(Qe,{size:[E,2.95,.2],center:[u,0,.2/2+1.14]})]})})};return Te(Rn,{children:[XA(c,{xDir:1}),XA(c,{xDir:-1}),g]})},wbe=()=>{const I=XA(Ko,{color:"#222",children:Te(FQ,{children:[XA(Pi,{z:.27,children:XA(Qe,{size:[2.9,1.9,.54]})}),Te(hc,{children:[XA(Pi,{z:.54,children:XA(Qe,{size:[2.9,1.9,.01]})}),XA(Pi,{z:1.08,children:XA(Qe,{size:[2.6999999999999997,1.7,.01]})})]})]})});return Te(Rn,{children:[XA(Qe,{color:"#ccc",size:[1,1.2,.25],center:[-1.3,0,.25/2]}),XA(Qe,{color:"#ccc",size:[1,1.2,.25],center:[1.3,0,.25/2]}),I]})},Dbe=()=>Te(Rn,{children:[XA(Qe,{color:"#ccc",size:[1,.6,.12],center:[-1.3,0,.12/2]}),XA(Qe,{color:"#ccc",size:[1,.6,.12],center:[1.3,0,.12/2]}),XA(Ko,{color:"#222",children:Te(FQ,{children:[XA(Pi,{z:.55/2,children:XA(Qe,{size:[2.7,1.6,.55]})}),Te(hc,{children:[XA(Pi,{z:.55,children:XA(Qe,{size:[2.7,1.6,.01]})}),XA(Pi,{z:1.1,children:XA(Qe,{size:[2.7-.2,1.6-.2,.01]})})]})]})})]}),Sbe=()=>Te(Rn,{children:[XA(Qe,{color:"#ccc",size:[1,.9,.2],center:[-1.3,0,.2/2]}),XA(Qe,{color:"#ccc",size:[1,.9,.2],center:[1.3,0,.2/2]}),XA(Ko,{color:"#222",children:Te(FQ,{children:[XA(Pi,{z:.2/2,children:XA(Qe,{size:[2.75,1.8,.2]})}),Te(hc,{children:[XA(Pi,{z:.2,children:XA(Qe,{size:[2.75,1.8,.01]})}),XA(Pi,{z:1,children:XA(Qe,{size:[2.75-.4,1.8-.4,.01]})})]})]})}),XA(Qe,{color:"#777",size:[.2,1.8-.4,.01],center:[-1.3+.4,0,1]})]}),bbe=()=>Te(Rn,{children:[XA(Qe,{color:"#ccc",size:[.9,.9,.2],center:[-1.225,0,.2/2]}),XA(Qe,{color:"#ccc",size:[.9,.9,.2],center:[1.225,0,.2/2]}),XA(Ko,{color:"#222",children:Te(FQ,{children:[Te(hc,{children:[XA(Pi,{z:.2,children:XA(Qe,{size:[2.6-.1/2,1.7-.1/2,.01]})}),XA(Pi,{z:.01,children:XA(Qe,{size:[2.6-.1,1.7-.1,.01]})})]}),Te(hc,{children:[XA(Pi,{z:.2,children:XA(Qe,{size:[2.6,1.7,.01]})}),XA(Pi,{z:1,children:XA(Qe,{size:[2.6-.4,1.7-.4,.01]})})]})]})}),XA(Qe,{color:"#777",size:[.2*2.7,1.7-.4,.02],center:[-1.225+.4,0,1]})]}),xbe=()=>Te(Rn,{children:[XA(Qe,{color:"#ccc",size:[.9,1.75,.2],center:[-1.825,0,.2/2]}),XA(Qe,{color:"#ccc",size:[.9,1.75,.2],center:[1.825,0,.2/2]}),XA(Ko,{color:"#222",children:Te(FQ,{children:[Te(hc,{children:[XA(Pi,{z:.2,children:XA(Qe,{size:[3.8-.05/2,2.5-.05/2,.01]})}),XA(Pi,{z:.01,children:XA(Qe,{size:[3.8-.05,2.5-.05,.01]})})]}),Te(hc,{children:[XA(Pi,{z:.2,children:XA(Qe,{size:[3.8,2.5,.01]})}),XA(Pi,{z:1,children:XA(Qe,{size:[3.8-.4,2.5-.4,.01]})})]})]})}),XA(Qe,{color:"#777",size:[.2*2.7,2.5-.4,.02],center:[-1.825+.4,0,1]})]}),_be=()=>Te(Rn,{children:[XA(Qe,{color:"#ccc",size:[.4,.25,.14],center:[-.4,0,.14/2]}),XA(Qe,{color:"#ccc",size:[.4,.25,.14],center:[.4,0,.14/2]}),XA(Ko,{color:"#222",children:Te(FQ,{children:[XA(Pi,{z:.14/2,children:XA(Qe,{size:[.8,.6,.14]})}),Te(hc,{children:[XA(Pi,{z:.14,children:XA(Qe,{size:[.8,.6,.01]})}),XA(Pi,{z:.37,children:XA(Qe,{size:[.8-.1,.6-.1,.01]})})]})]})})]}),kbe=()=>{const c=3.0999999999999996;return Te(Rn,{children:[XA(zn,{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}),XA(zn,{position:{x:-6.6/2-c/4,y:0,z:.25/2},width:.7,thickness:.25,padContactLength:.5,bodyDistance:c,height:.75}),XA(zn,{position:{x:-6.6/2-c/4,y:-2.3,z:.25/2},width:.7,thickness:.25,padContactLength:.5,bodyDistance:c,height:.75}),XA(zn,{position:{x:-6.6/2-c/4,y:2.3,z:.25/2},width:.7,thickness:.25,padContactLength:.5,bodyDistance:c,height:.75}),XA(aB,{center:{x:0,y:0,z:0},width:3.5,length:6.5,height:1.7,includeNotch:!1,taperRatio:.06,straightHeightRatio:.45})]})},Fbe=()=>Te(Rn,{children:[Array.from({length:16}).map((B,C)=>XA(zn,{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)=>XA(zn,{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)=>XA(zn,{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)=>XA(zn,{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})),XA(aB,{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})]}),Gbe=Fbe,Mbe=()=>{const g=.7999999999999998;return Te(Rn,{children:[XA(zn,{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}),XA(zn,{position:{x:-2.05/2-g/4,y:-.65,z:.18/2},width:.3,thickness:.18,padContactLength:.2,bodyDistance:g,height:.65}),XA(zn,{position:{x:-2.05/2-g/4,y:.65,z:.18/2},width:.3,thickness:.18,padContactLength:.2,bodyDistance:g,height:.65}),XA(aB,{center:{x:0,y:0,z:0},width:1.25,length:2,height:.9,includeNotch:!1,taperRatio:.06,straightHeightRatio:.7,heightAboveSurface:.05})]})},Rbe=({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 Te(Rn,{children:[Array.from({length:o}).map((B,C)=>XA(zn,{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)=>XA(zn,{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)=>XA(zn,{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)=>XA(zn,{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})),XA(aB,{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})]})},vbe=()=>{const i=.20900000000000002,n=.1,o=.3,s=.1,r=.2;return Te(Rn,{children:[XA(Ko,{color:"#222",children:Te(FQ,{children:[XA(Qe,{size:[.85,1.2,i],center:[0,0,i/2]}),Te(hc,{children:[XA(Pi,{z:i,children:XA(Qe,{size:[.85,1.2,.01]})}),XA(Pi,{z:.38,children:XA(Qe,{size:[.85-n,1.2-n,.01]})})]})]})}),XA(Qe,{color:"#ccc",size:[o,.25,s],center:[.55,0,s/2]}),XA(Qe,{color:"#ccc",size:[o,r,s],center:[-.55,.4,s/2]}),XA(Qe,{color:"#ccc",size:[o,r,s],center:[-.55,-.4,s/2]})]})},Nbe=({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 Te(Rn,{children:[XA(aB,{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)=>XA(Qe,{center:[l.x,l.y,a/2],size:[l.padSizeX,l.padSizeY,a]})),n?.length!==void 0&&n?.width!==void 0&&XA(Qe,{center:[0,0,a/2],size:[n.width,n.length,a]})]})},Lbe=({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 Te(Rn,{children:[Te(Ko,{color:s,children:[Te(hc,{children:[XA(lf,{height:t,roundRadius:.5,radius:g,center:[-c,0,t]}),XA(lf,{height:t,roundRadius:.5,radius:g,center:[c,0,t]})]}),Te(hc,{children:[XA(lf,{height:l,roundRadius:.1,radius:g+.85,center:[-c,0,t/2+l/2]}),XA(lf,{height:l,roundRadius:.1,radius:g+.85,center:[c,0,t/2+l/2]})]})]}),Te(Ko,{color:r,children:[XA(Gl,{height:o+t/2,radius:n/2,center:[-I+.06,0,-(o/2)+t/2]}),XA(Gl,{height:o+t/2,radius:n/2,center:[I-.06,0,-(o/2)+t/2]})]})]})},Ube=({bodyLength:e=1.4,bodyDiameter:A=1.1,color:t="#3a3a3aff",contactColor:i="#c6c6c6",cathodeIdentification:n="#111"})=>Te(Rn,{children:[XA(Ko,{color:t,children:Te(VB,{rotation:[0,"90deg",0],children:[XA(FH,{size:[A,A,e-.2],roundRadius:.2,center:[-A/2,0,.05]}),XA(Gl,{height:.2/2,radius:A/2-.2,center:[-A/2,0,-e/2+.2/2]})]})}),XA(Ko,{color:n,children:XA(VB,{rotation:[0,"90deg",0],children:XA(FH,{size:[A*1.01,A*1.01,e/3],roundRadius:.2,center:[-A/2,0,-e/4+.1]})})}),XA(Ko,{color:i,children:XA(VB,{rotation:[0,"90deg",0],children:XA(lf,{height:.2,radius:A/2,roundRadius:.2/3,center:[-A/2,0,-e/2]})})}),XA(Ko,{color:i,children:XA(VB,{rotation:[0,"90deg",0],children:XA(lf,{height:.2,radius:A/2,roundRadius:.2/3,center:[-A/2,0,e/2]})})})]}),Hbe=({bodyLength:e=3.5,bodyDiameter:A=1.5,color:t="#3a3a3aff",contactColor:i="#c6c6c6"})=>Te(Rn,{children:[XA(Ko,{color:t,children:XA(VB,{rotation:[0,"90deg",0],children:XA(lf,{height:e,radius:A/2,roundRadius:.3,center:[-A/2,0,0]})})}),XA(Ko,{color:i,children:XA(VB,{rotation:[0,"90deg",0],children:XA(lf,{height:.5,radius:A/2,roundRadius:.2,center:[-A/2,0,-e/2]})})}),XA(Ko,{color:i,children:XA(VB,{rotation:[0,"90deg",0],children:XA(lf,{height:.5,radius:A/2,roundRadius:.2,center:[-A/2,0,e/2]})})})]}),Ybe=({bodyLength:e=3.9,bodyDiameter:A=2.5,color:t="#3a3a3aff",contactColor:i="#c6c6c6"})=>Te(Rn,{children:[XA(Ko,{color:t,children:XA(VB,{rotation:[0,"90deg",0],children:XA(lf,{height:e,radius:A/2,roundRadius:.3,center:[-A/2,0,0]})})}),XA(Ko,{color:i,children:XA(VB,{rotation:[0,"90deg",0],children:XA(lf,{height:.55,radius:A/2,roundRadius:.2,center:[-A/2,0,-e/2]})})}),XA(Ko,{color:i,children:XA(VB,{rotation:[0,"90deg",0],children:XA(lf,{height:.55,radius:A/2,roundRadius:.2,center:[-A/2,0,e/2]})})})]}),Jbe=({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 Te(Rn,{children:[Array.from({length:n}).map((g,c)=>XA(zn,{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)=>XA(zn,{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})),XA(aB,{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})]})},Tbe=({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 Te(Rn,{children:[Array.from({length:n}).map((g,c)=>XA(zn,{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)=>XA(zn,{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})),XA(aB,{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})]})},Kbe=()=>{const Q=7.050000000000001,h=24.95+6.5/2;return XA(Pi,{center:[0,0,1],children:Te(Rn,{children:[Te(VB,{rotation:[0,55,-55],children:[Te(rw,{children:[XA(Qe,{color:"#ccc",size:[6.5+.1,9.9,1.3],center:[h,0,1.3-2]}),XA(Gl,{color:"black",center:[h,0,1.3-2],radius:3/2,height:1.3*1.2})]}),XA(Ko,{color:"#222",children:XA(aB,{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})})]}),XA(VB,{rotation:[0,55,55],children:Array.from({length:3}).map((E,u)=>{const d=Q,f=(u-1)*2.7,m=-.5-.6;return Te(Ko,{color:"gold",children:[Te(hc,{children:[XA(Pi,{center:[15.05-4.5/2+.1,f,m],children:XA(Qe,{size:[4.5,.81+1,.5]})}),XA(Pi,{center:[15.05-4.5/2-1+.1,f,m],children:XA(Qe,{size:[4.5,.81,.5]})})]}),XA(Pi,{center:[d,f,m],children:XA(Qe,{size:[16+.1,.81,.5]})})]},`prong-${u}`)})})]})})},Pbe=()=>{const g=1.1999999999999997;return Te(Rn,{children:[XA(zn,{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}),XA(zn,{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}),XA(zn,{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}),XA(zn,{position:{x:-2.8/2-g/4,y:0,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:g,height:.95}),XA(zn,{position:{x:-2.8/2-g/4,y:-.95,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:g,height:.95}),XA(zn,{position:{x:-2.8/2-g/4,y:.95,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:g,height:.95}),XA(aB,{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})]})},qbe=()=>Te(Rn,{children:[XA(aB,{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 XA(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 XA(Qe,{center:[.8/2-.19/2+.1,c,.12/2],size:[.19,.15,.12]})})]}),Obe=()=>{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 Te(Pi,{center:[0,1,10.5],children:[XA(Ko,{color:s,children:Te(rw,{children:[XA(Pi,{center:[0,0,2.25],children:XA(Gl,{radius:2.4,height:4.5})}),XA(Pi,{center:[0,-1.8499999999999999,2.25],children:XA(Qe,{size:[2.4*2,1.1,4.5+.2]})})]})}),XA(Pi,{center:c,children:XA(Qe,{size:a})}),Te(hc,{children:[XA(Pi,{center:I,children:XA(Qe,{size:g})}),XA(Pi,{center:l,children:XA(Qe,{size:g})})]}),XA(Pi,{center:B,children:XA(Qe,{size:[.43,.4,12.2]})}),XA(Pi,{center:[1.3,0,C],children:XA(Qe,{size:[.43,.4,15]})}),XA(Pi,{center:[-1.3,0,C],children:XA(Qe,{size:[.43,.4,15]})})]})},Wbe=()=>Te(Rn,{children:[XA(zn,{rotation:Math.PI,position:{x:2/2+.75/4,y:-.65,z:.15/2},width:.25,thickness:.15,padContactLength:.3,bodyDistance:.75,height:.85}),XA(zn,{rotation:Math.PI,position:{x:2/2+.75/4,y:0,z:.15/2},width:.25,thickness:.15,padContactLength:.3,bodyDistance:.75,height:.85}),XA(zn,{rotation:Math.PI,position:{x:2/2+.75/4,y:.65,z:.15/2},width:.25,thickness:.15,padContactLength:.3,bodyDistance:.75,height:.85}),XA(zn,{position:{x:-2/2-.75/4,y:0,z:.15/2},width:.25,thickness:.15,padContactLength:.3,bodyDistance:.75,height:.85}),XA(zn,{position:{x:-2/2-.75/4,y:-.65,z:.15/2},width:.25,thickness:.15,padContactLength:.3,bodyDistance:.75,height:.85}),XA(zn,{position:{x:-2/2-.75/4,y:.65,z:.15/2},width:.25,thickness:.15,padContactLength:.3,bodyDistance:.75,height:.85}),XA(aB,{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})]}),Zbe=Wbe,Vbe=()=>Te(Rn,{children:[XA(aB,{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 XA(Qe,{center:[-1/2+.3/2,a,.05/2],size:[.3,.2,.05]})}),[0,1,2].map(r=>{const a=-.5+r*.5;return XA(Qe,{center:[1/2-.3/2,a,.05/2],size:[.3,.2,.05]})})]}),jbe=()=>Te(Rn,{children:[XA(zn,{position:{x:-2.5/2,y:0,z:.175/2},width:.3,thickness:.175,padContactLength:.3,bodyDistance:.45,height:.7}),XA(zn,{rotation:Math.PI,position:{x:2.5/2,y:0,z:.175/2},width:.3,thickness:.175,padContactLength:.3,bodyDistance:.45,height:.7}),XA(Ko,{color:"#222",children:XA(aB,{center:{x:0,y:0,z:0},width:1.7,length:1.25,height:.95,includeNotch:!1,taperRatio:.06,straightHeightRatio:.7,heightAboveSurface:.05})}),XA(Qe,{color:"#777",size:[1.7/3,1.25-.075,.02],center:[-.85*2/3+.035,0,.95+.05]})]}),zbe=()=>Te(Rn,{children:[XA(Qe,{color:"#ccc",size:[.4,.325,.175],center:[-1.05,0,.175/2]}),XA(Qe,{color:"#ccc",size:[.4,.325,.175],center:[1.05,0,.175/2]}),XA(Ko,{color:"#222",children:Te(FQ,{children:[XA(Pi,{z:.175/2,children:XA(Qe,{size:[1.7,1.25,.175]})}),Te(hc,{children:[XA(Pi,{z:.175,children:XA(Qe,{size:[1.7,1.25,.01]})}),XA(Pi,{z:.725,children:XA(Qe,{size:[1.7-.2,1.25-.2,.01]})})]})]})}),XA(Qe,{color:"#777",size:[1.7/3,1.25-.2,.02],center:[-1.05+1.7/4.4+.2,0,.725]})]}),Xbe=()=>{const s=-1.0474999999999999,r=1.775/2+.4/2-.04;return Te(Rn,{children:[XA(Qe,{color:"#ccc",size:[.4,.325,.13],center:[s,0,.13/2]}),XA(Qe,{color:"#ccc",size:[.4,.325,.13],center:[r,0,.13/2]}),XA(Ko,{color:"#222",children:XA(aB,{width:1.775,length:1.25,height:.725,center:{x:0,y:0,z:0},heightAboveSurface:0,straightHeightRatio:.7,taperRatio:.06,includeNotch:!1})}),XA(Qe,{color:"#777",size:[1.775/3,1.25-.05,.02],center:[s+1.775/4.4+.2,0,.725]})]})},$be=({pitch:e=10})=>Te(Rn,{children:[XA(Gl,{height:4,radius:.5,center:[-e/2,0,.5]}),XA(ZW,{radius:.5,center:[-e/2,0,2.5]}),XA(Pi,{x:-2.5,y:0,z:2.5,children:Te(VB,{rotation:[0,Math.PI/2,0],children:[XA(Gl,{height:e,radius:.5,center:[0,0,2.5]}),XA(Ko,{color:"#d2b48c",children:XA(Gl,{height:5,radius:1.3,center:[0,0,2.5]})})]})}),XA(Gl,{height:4,radius:.5,center:[e/2,0,.5]}),XA(ZW,{radius:.5,center:[e/2,0,2.5]})]}),Axe=({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 b=w+D*n;E.push({x:-l+i/2,y:-b,pl:i,pw:t}),g&&u.push({x:-l,y:-b},{x:-l+c,y:-b})}}if(o){const w=-((o-1)/2)*n;for(let D=0;D<o;D++){const b=w+D*n;E.push({x:l-i/2,y:-b,pl:i,pw:t}),g&&u.push({x:l,y:-b},{x:l-c,y:-b})}}if(r){const w=-((r-1)/2)*n;for(let D=0;D<r;D++){const b=w+D*n;E.push({x:-b,y:-h/2+i/2,pl:t,pw:i}),g&&u.push({x:-b,y:-h/2},{x:-b,y:-h/2+c})}}if(a){const w=-((a-1)/2)*n;for(let D=0;D<a;D++){const b=w+D*n;E.push({x:-b,y:h/2-i/2,pl:t,pw:i}),g&&u.push({x:-b,y:h/2},{x:-b,y:h/2-c})}}const d=XA(Ko,{color:"#008080",children:Te(rw,{children:[XA(Qe,{center:[0,0,B],size:[e,h,A]}),E.map((w,D)=>XA(Qe,{center:[w.x,w.y,B],size:[w.pl+.01,w.pw+.01,C]},D))]})}),f=g&&u.map((w,D)=>XA(Gl,{color:"black",center:[w.x,w.y,B],radius:Q,height:A*1.07})),m=E.map((w,D)=>XA(Qe,{center:[w.x,w.y,B],size:[w.pl+.01,w.pw+.01,C]}));return Te(Rn,{children:[d,XA(Ko,{color:"#FFD700",children:g?Te(rw,{children:[XA(FQ,{children:E.map((w,D)=>XA(Qe,{center:[w.x,w.y,B],size:[w.pl+.01,w.pw+.01,C]},D))}),f]}):m})]})},txe=({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,nopin:l})=>{const B=o/2,C=Math.ceil(e/A);let Q,h;a==="left"||a==="right"?(Q=(A-1)*t+2*I,h=(C-1)*t+2*I):(h=(A-1)*t+2*I,Q=(C-1)*t+2*I),e===0&&(Q=10,h=10);const E=Number(s??Q),u=Number(r??h),d=[];let f=0,m=0,w=0,D=0,b=0,k=0;a==="left"||a==="right"?(f=a==="left"?-E/2+I:E/2-I,m=-((C-1)/2)*t,w=0,D=t,b=a==="left"?t:-t,k=0):(f=-((C-1)/2)*t,m=a==="top"?u/2-I:-u/2+I,w=t,D=0,b=0,k=a==="top"?-t:t);let x=0;for(let aA=0;aA<A&&x<e;aA++)for(let tA=0;tA<C&&x<e;tA++){const eA=f+tA*w+aA*b,sA=m+tA*D+aA*k;d.push({x:eA,y:sA}),x++}const v=[];if(g)for(const aA of g){let tA=0,eA=0;aA==="topleft"?(tA=-E/2+c,eA=u/2-c):aA==="topright"?(tA=E/2-c,eA=u/2-c):aA==="bottomleft"?(tA=-E/2+c,eA=-u/2+c):aA==="bottomright"?(tA=E/2-c,eA=-u/2+c):aA==="center"&&(tA=0,eA=0),v.push({x:tA,y:eA})}const R=.63,U=2,J=6,H=3,O=l?0:U,Z=XA(Ko,{color:"#008080",children:Te(rw,{children:[XA(Qe,{center:[0,0,B+O],size:[E,u,o]}),v.map((aA,tA)=>XA(Gl,{center:[aA.x,aA.y,B+O],radius:n/2,height:o},`hole-${tA}`)),d.map((aA,tA)=>XA(Gl,{center:[aA.x,aA.y,B+O],radius:n/2,height:o},`pin-hole-${tA}`))]})}),X=d.map((aA,tA)=>XA(Ko,{color:"#FFD700",children:Te(rw,{children:[XA(Gl,{center:[aA.x,aA.y,o/2+O],radius:n/2,height:o}),XA(Gl,{center:[aA.x,aA.y,o/2+O],radius:i/2,height:o})]})})),iA=d.map((aA,tA)=>XA(X6A,{x:aA.x,y:aA.y,pinThickness:R,shortSidePinLength:H,longSidePinLength:J,bodyHeight:U,flipZ:eA=>eA}));return Te(Rn,{children:[Z,X,!l&&iA]})},exe=({footprint:e})=>{const A=USe.string(e).json();switch(A.fn){case"dip":return XA(KSe,{numPins:A.num_pins,pitch:A.p,bodyWidth:A.w});case"axial":return XA($be,{pitch:A.p});case"tssop":return XA(qSe,{pinCount:A.num_pins,leadLength:A.pl,leadWidth:A.pw,pitch:A.p,bodyWidth:A.w});case"msop":return XA(OSe,{pinCount:A.num_pins,padContactLength:A.pl,leadWidth:A.pw,pitch:A.p,bodyWidth:A.w});case"vssop":return XA(ube,{pinCount:A.num_pins,leadLength:A.pl,leadWidth:A.pw,pitch:A.p,bodyWidth:A.w,bodyLength:A.h});case"qfp":return XA(jSe,{pinCount:A.num_pins,pitch:A.p,leadWidth:A.pw,padContactLength:A.pl,bodyWidth:A.w});case"tqfp":return XA(Gbe,{});case"lqfp":return XA(Rbe,{pinCount:A.num_pins});case"qfn":{const n=typeof A.thermalpad?.x=="number"&&typeof A.thermalpad?.y=="number";return XA(nbe,{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 XA(Nbe,{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 XA(Abe,{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 XA(Qbe,{numberOfPins:A.num_pins,pitch:A.p,rows:o})}case"cap":switch(A.imperial){case"0402":return XA(V6A,{color:"#856c4d"});case"0603":return XA(j6A,{color:"#856c4d"});case"0805":return XA(z6A,{color:"#856c4d"});case"0201":return XA($6A,{color:"#856c4d"});case"01005":return XA(A7A,{color:"#856c4d"});case"1206":return XA(t7A,{color:"#856c4d"});case"1210":return XA(e7A,{color:"#856c4d"});case"2010":return XA(i7A,{color:"#856c4d"});case"2512":return XA(n7A,{color:"#856c4d"})}case"sot235":return XA(sbe,{});case"sot457":return XA(Pbe,{});case"sot223":return XA(kbe,{});case"sot23w":return XA(rbe,{});case"sot323":return XA(Mbe,{});case"sod323f":return XA(zbe,{});case"sod323fl":return XA(Xbe,{});case"sot363":return XA(Zbe,{});case"sot886":return XA(Vbe,{});case"sot963":return XA(qbe,{});case"pushbutton":return XA(hbe,{width:A.w,length:A.h,innerDiameter:A.id});case"soic":return XA(Ebe,{pinCount:A.num_pins,leadLength:A.pl,leadWidth:A.pw,pitch:A.p,bodyWidth:A.w});case"sod523":return XA(dbe,{});case"sod882":return XA(pbe,{});case"sma":return XA(fbe,{});case"smb":return XA(ybe,{});case"smc":return XA(mbe,{});case"smf":return XA(wbe,{});case"sod123f":return XA(Dbe,{});case"sod123fl":return XA(Sbe,{});case"sod123w":return XA(bbe,{});case"sod128":return XA(xbe,{});case"sod323":return XA(jbe,{});case"sod923":return XA(_be,{});case"hc49":return XA(Lbe,{});case"micromelf":return XA(Ube,{});case"minimelf":return XA(Hbe,{});case"melf":return XA(Ybe,{});case"ms012":return XA(Jbe,{pinCount:A.num_pins,padContactLength:A.pl,leadWidth:A.pw,pitch:A.p});case"ms013":return XA(Tbe,{pinCount:A.num_pins,padContactLength:A.pl,leadWidth:A.pw,pitch:A.p});case"sot723":return XA(vbe,{});case"to220":return XA(Kbe,{});case"to92":return XA(Obe,{});case"stampboard":case"stampreceiver":return XA(Axe,{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 XA(txe,{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})}}const t=e.match(/_color\(([^)]+)\)/),i=t?t[1]:void 0;switch(A.imperial){case"0402":return XA(V6A,{color:i});case"0603":return XA(j6A,{color:i});case"0805":return XA(z6A,{color:i});case"0201":return XA($6A,{color:i});case"01005":return XA(A7A,{color:i});case"1206":return XA(t7A,{color:i});case"1210":return XA(e7A,{color:i});case"2010":return XA(i7A,{color:i});case"2512":return XA(n7A,{color:i})}return null},ixe=e=>e&&typeof e=="object"&&"type"in e,fN=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},nxe=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 pD(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=>pD(l,A,t));if(!ixe(e))return[];const{type:g,props:c,children:I}=e;if(g===O6A)return(I??[]).flatMap(l=>pD(l,A,t));if(g===Ko){const l=c?.color;return(I??[]).flatMap(B=>pD(B,l??A,t))}if(g===Pi){const l=nxe(c?.offset??c?.center??{x:c?.x,y:c?.y,z:c?.z});return(I??[]).flatMap(C=>pD(C,A,t)).map(({geom:C,color:Q})=>({geom:a.translate(l,C),color:Q??A}))}if(g===VB){const l=Array.isArray(c?.rotation)?[fN(c.rotation[0]),fN(c.rotation[1]),fN(c.rotation[2])]:[fN(c?.x??0),fN(c?.y??0),fN(c?.z??0)];return(I??[]).flatMap(C=>pD(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===FQ||g===rw||g===hc){const l=(I??[]).flatMap(C=>pD(C,A,t)).map(C=>C.geom);if(l.length===0)return[];let B;return g===FQ?B=n.union(l):g===rw?B=n.subtract(l[0],l.slice(1)):B=o.hull(l),[{geom:B,color:A}]}if(g===GH){const l=c?.points??[];return[{geom:s.geom2.fromPoints(l),color:A??c?.color}]}if(g===MH){const l=(I??[]).flatMap(h=>pD(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===W6A||g===Gl||g===ZW||g===FH||g===lf){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===W6A){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===Gl){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===ZW){const B=c?.radius??1,C=c?.center??[0,0,0];l=i.sphere({radius:B,center:C})}else if(g===lf){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 pD(l,A,t)}return(I??[]).flatMap(l=>pD(l,A,t))}function oxe(e,A){return{geometries:pD(e,void 0,{jscad:A})}}function o7A(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 Sg;if(o.setAttribute("position",new Qc(new Float32Array(A),3)),o.setIndex(t),i.length>0&&o.setAttribute("color",new Qc(new Float32Array(i),3)),e.transforms){const s=new rs;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 Sg;if(i.setAttribute("position",new Qc(new Float32Array(A),3)),t.length>0&&i.setAttribute("color",new Qc(new Float32Array(t),3)),e.transforms){const n=new rs;n.fromArray(e.transforms),i.applyMatrix4(n)}return i}return console.error("Invalid CSG object: neither polygons nor sides found"),new Sg}function sxe(e,A){const t=EEA(exe,{footprint:e});return oxe(t,A)}var rxe=Kr(YW()),s7A=V.createContext(null),axe=()=>{const e=V.useContext(s7A);if(!e)throw new Error("useHover must be used within a HoverProvider");return e},gxe=({children:e})=>{const{camera:A,renderer:t}=Yu(),[i,n]=V.useState([]),o=V.useMemo(()=>new Bae,[]),s=V.useMemo(()=>new ln,[]),r=V.useRef(i);r.current=i;const a=V.useRef(null),g=V.useCallback(C=>{n(Q=>[...Q,C])},[]),c=V.useCallback(C=>{if(a.current){let Q=!1,h=a.current.object;for(;h;){if(h===C){Q=!0;break}h=h.parent}Q&&(a.current.onUnhover(),a.current=null)}n(Q=>Q.filter(h=>h.object!==C))},[]),I=V.useCallback(C=>{let Q=C;for(;Q;){const h=r.current.find(E=>E.object===Q);if(h)return h;Q=Q.parent}},[]),l=V.useCallback(C=>{if(!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]);V.useEffect(()=>{const C=t.domElement;return C.addEventListener("mousemove",l),()=>{C.removeEventListener("mousemove",l)}},[t,l]);const B=V.useMemo(()=>({addHoverable:g,removeHoverable:c}),[g,c]);return W.jsx(s7A.Provider,{value:B,children:e})},cxe=({children:e,object:A,onHover:t,onUnhover:i,isHovered:n})=>{const{addHoverable:o,removeHoverable:s}=axe();return V.useEffect(()=>A?(o({object:A,onHover:t,onUnhover:i}),()=>{s(A)}):void 0,[A,t,i,o,s]),W.jsx(W.Fragment,{children:e})},TH=cxe,Ixe=({positionOffset:e,footprint:A,rotationOffset:t,onHover:i,onUnhover:n,isHovered:o,scale:s,isTranslucent:r=!1})=>{const{rootObject:a}=Yu(),g=V.useMemo(()=>{if(!A)return null;const{geometries:c}=sxe(A,rxe),I=new If;for(const l of c.flat(1/0)){const B=l.geom;if(!B||!B.polygons&&!B.sides)continue;const C=new Oi(l.color);C.convertLinearToSRGB();const Q={...B,color:[C.r,C.g,C.b]},h=o7A(Q),E=new kE({vertexColors:!0,side:ZB,transparent:r,opacity:r?.5:1,depthWrite:!r}),u=new eo(h,E);I.add(u)}return I},[A,r]);return V.useEffect(()=>{if(!(!g||!a))return a.add(g),()=>{a.remove(g)}},[a,g]),V.useEffect(()=>{g&&(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]),V.useEffect(()=>{g&&g.traverse(c=>{c instanceof eo&&c.material instanceof kE&&(o?(c.material.emissive.setHex(255),c.material.emissiveIntensity=.2):c.material.emissiveIntensity=0)})},[o,g]),g?W.jsx(TH,{isHovered:o,onHover:i,onUnhover:n,object:g}):null},r7A=new WeakMap,lxe=()=>{const e=new qc;return e.name="fallback-environment-map",e.mapping=O5,e},Bxe=e=>{if(!e)return null;const A=e,t=r7A.get(A);if(t)return t;let i;if(e instanceof w8){const n=new SrA(e);i=n.fromScene(Lae(),.04).texture,n.dispose()}else i=lxe();return r7A.set(A,i),i},a7A=1.25;function g7A({gltfUrl:e,position:A,rotation:t,onHover:i,onUnhover:n,isHovered:o,scale:s,isTranslucent:r=!1}){const{renderer:a,rootObject:g}=Yu(),[c,I]=V.useState(null),[l,B]=V.useState(null);if(V.useEffect(()=>{if(!e)return;const C=new Hae;let Q=!0;return C.load(e,h=>{if(!Q)return;const E=h.scene;E.traverse(u=>{if(u instanceof eo&&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)}}),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]),V.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]),V.useEffect(()=>{if(!(!g||!c))return g.add(c),()=>{g.remove(c)}},[g,c]),V.useEffect(()=>{if(!c||!a)return;const C=Bxe(a);if(!C)return;const Q=[],h=E=>{E instanceof kE&&(Q.push({material:E,envMap:E.envMap??null,envMapIntensity:E.envMapIntensity??1}),E.envMap=C,(typeof E.envMapIntensity!="number"||E.envMapIntensity<a7A)&&(E.envMapIntensity=a7A),E.needsUpdate=!0)};return c.traverse(E=>{if(!(E instanceof eo))return;const u=E.material;Array.isArray(u)?u.forEach(h):u&&h(u)}),()=>{Q.forEach(({material:E,envMap:u,envMapIntensity:d})=>{E.envMap=u,E.envMapIntensity=d,E.needsUpdate=!0})}},[c,a]),V.useEffect(()=>{c&&c.traverse(C=>{C instanceof eo&&C.material instanceof kE&&(o?(C.material.emissive.setHex(255),C.material.emissiveIntensity=.2):C.material.emissiveIntensity=0)})},[o,c]),l)throw l;return c?W.jsx(TH,{isHovered:o,onHover:i,onUnhover:n,object:c}):null}var Cxe=Kr(C6A()),Qxe=Kr(YW()),hxe=({jscadPlan:e,positionOffset:A,rotationOffset:t,onHover:i,onUnhover:n,isHovered:o,scale:s,isTranslucent:r=!1})=>{const{rootObject:a}=Yu(),{threeGeom:g,material:c}=V.useMemo(()=>{const l=(0,Cxe.executeJscadOperations)(Qxe.default,e);if(!l||!l.polygons&&!l.sides)return{threeGeom:null,material:null};const B=o7A(l),C=new kE({vertexColors:!0,side:ZB,transparent:r,opacity:r?.5:1,depthWrite:!r});return{threeGeom:B,material:C}},[e,r]),I=V.useMemo(()=>g?new eo(g,c):null,[g,c]);return V.useEffect(()=>{if(!(!I||!a))return a.add(I),()=>{a.remove(I)}},[a,I]),V.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]),V.useMemo(()=>{if(c)if(o){const l=new Oi(c.color.getHex());c.emissive.copy(l),c.emissive.setRGB(0,0,1),c.emissiveIntensity=.2}else c.emissiveIntensity=0},[o,c]),g?W.jsx(TH,{isHovered:o,onHover:i,onUnhover:n,object:I}):null};function Exe(e){return e.replace(/(DEF|USE)\s+([^\s]+)/g,(A,t,i)=>`${t} ${i.replace(/-/g,"_")}`)}async function uxe(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 wge().parse(Exe(t),e)}typeof window<"u"&&!window.TSCIRCUIT_OBJ_LOADER_CACHE&&(window.TSCIRCUIT_OBJ_LOADER_CACHE=new Map);function dxe(e){const[A,t]=V.useState(null);return V.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 uxe(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 Mge;if(c?.length){const l=c.join(`
|
|
5140
|
-
`).replace(/d 0\./g,"d 1."),B=g.replace(/newmtl[\s\S]*?endmtl/g,"").replace(/^mtllib.*/gm,""),C=new fge;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 pxe({url:e,position:A,rotation:t,onHover:i,onUnhover:n,isHovered:o,scale:s,isTranslucent:r=!1}){const a=dxe(e),{rootObject:g}=Yu(),c=V.useMemo(()=>a&&!(a instanceof Error)?(a.traverse(I=>{if(I instanceof eo&&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)}}),a):new eo(new ew(.5,.5,.5),new kE({transparent:!0,color:"red",opacity:.25})),[a,r]);if(V.useEffect(()=>{if(!(!g||!c))return g.add(c),()=>{g.remove(c)}},[g,c]),V.useEffect(()=>{c&&(A&&(Array.isArray(A)?c.position.fromArray(A):c.position.copy(A)),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 W.jsx(TH,{isHovered:o,onHover:i,onUnhover:n,object:c})}var LEA,fxe="https://cdn.jsdelivr.net/npm/occt-import-js@0.0.23/dist";function yxe(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 mxe(){if(!LEA){const e=await import("https://cdn.jsdelivr.net/npm/occt-import-js@0.0.23/+esm");LEA=yxe(e)({locateFile:t=>`${fxe}/${t}`})}return LEA}function wxe(e){const A=new If;for(const t of e){const i=t.attributes.position?.array??[],n=t.index?.array??[];if(!i.length||!n.length)continue;const o=new Sg;o.setAttribute("position",new To(i,3));const s=t.attributes.normal?.array??[];s.length?o.setAttribute("normal",new To(s,3)):o.computeVertexNormals(),o.setIndex(n);const r=new kE({color:t.color?new Oi(t.color[0],t.color[1],t.color[2]):new Oi(.82,.82,.82)}),a=new eo(o,r);a.name=t.name,A.add(a)}return A}async function Dxe(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 mxe()).ReadStepFile(new Uint8Array(t),null);if(!n.success||!n.meshes.length)throw new Error("occt-import-js failed to convert STEP file");const o=wxe(n.meshes),s=new iaA;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 c7A="step-glb-cache:";function Sxe(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 bxe(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 xxe(e){try{const A=localStorage.getItem(`${c7A}${e}`);return A?bxe(A):null}catch(A){return console.warn("Failed to read STEP GLB cache",A),null}}function I7A(e,A){try{const t=Sxe(A);localStorage.setItem(`${c7A}${e}`,t)}catch(t){console.warn("Failed to write STEP GLB cache",t)}}function _xe(){const e=globalThis;return e.stepUrlToGltfModelConversions||(e.stepUrlToGltfModelConversions={inProgress:new Map,completed:new Map}),e.stepUrlToGltfModelConversions}var kxe=({stepUrl:e,position:A,rotation:t,scale:i,onHover:n,onUnhover:o,isHovered:s,isTranslucent:r})=>{const[a,g]=V.useState(null);return V.useEffect(()=>{let c=!0,I=null,l=!0;const B=_xe(),C=xxe(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),I7A(e,Q.arrayBuffer),()=>{c=!1,I&&l&&URL.revokeObjectURL(I)};let h=B.inProgress.get(e);return h||(h=Dxe(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),I7A(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?W.jsx(g7A,{gltfUrl:a,position:A,rotation:t,scale:i,onHover:n,onUnhover:o,isHovered:s,isTranslucent:r}):null},Fxe=(e,A)=>{if(e)return A?A(e):e},l7A=(...e)=>e,B7A=({cad_component:e,circuitJson:A,resolveStaticAsset:t})=>{const i=E6A(A),[n,o]=V.useState(!1),{visibility:s}=aG(),[r,a]=V.useState(null),g=V.useCallback(w=>{w?.mousePosition?(o(!0),a(w.mousePosition)):(o(!1),a(null))},[]),c=V.useCallback(()=>{o(!1),a(null)},[]),I=V.useMemo(()=>Ti(A).source_component.getUsing({source_component_id:e.source_component_id})?.name,[A,e.source_component_id]),l=V.useMemo(()=>A.filter(D=>D.type==="pcb_plated_hole"&&D.pcb_component_id===e.pcb_component_id).length>0,[A,e.pcb_component_id]),B=V.useCallback(w=>Fxe(w,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),u=A.find(w=>w.type==="pcb_component"&&w.source_component_id===e.source_component_id)?.layer??"top",d=V.useMemo(()=>e.rotation?l7A(e.rotation.x*Math.PI/180,e.rotation.y*Math.PI/180,e.rotation.z*Math.PI/180):l7A(0,0,0),[e.rotation,u]),f=V.useMemo(()=>{if(!e.position)return;let w;return u==="top"?w=e.position.z:u==="bottom"?w=-(e.position.z+i):w=e.position.z,[e.position.x,e.position.y,w]},[e.position,u,i]);let m=null;if(C?m=W.jsx(pxe,{url:C,position:f,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):Q?m=W.jsx(g7A,{gltfUrl:Q,position:f,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):h&&!e.model_jscad&&!e.footprinter_string?m=W.jsx(kxe,{stepUrl:h,position:f,rotation:d,scale:e.model_unit_to_mm_scale_factor,onHover:g,onUnhover:c,isHovered:n,isTranslucent:e.show_as_translucent_model}):e.model_jscad?m=W.jsx(hxe,{jscadPlan:e.model_jscad,positionOffset:f,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&&(m=W.jsx(Ixe,{positionOffset:f,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})),e.show_as_translucent_model){if(!s.translucentModels)return null}else if(l&&!s.throughHoleModels||!l&&!s.smtModels)return null;return W.jsxs(W.Fragment,{children:[m,n&&r?W.jsx(d6A,{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]})},C7A={version:"0.0.518"};function Gxe(e){e.querySelectorAll("canvas").forEach(A=>A.remove())}var Mxe=e=>{e.outputColorSpace=Wm,e.toneMapping=KKA,e.toneMappingExposure=1},Q7A="cadViewerCameraStateSession",h7A=(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(Q7A,JSON.stringify(t))}catch(t){console.warn("Failed to save camera:",t)}},UEA=(e,A)=>{try{const t=sessionStorage.getItem(Q7A);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}},E7A=V.createContext(void 0),Rxe=({children:e,defaultTarget:A,initialCameraPosition:t})=>{const i=V.useRef(null),n=V.useRef(null),[o,s]=V.useState(null),[r,a]=V.useState("perspective"),[g,c]=V.useState(t??null),[I,l]=V.useState(new gf(0,0,0)),B=V.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=V.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=V.useCallback(E=>{i.current=E},[]),h=V.useMemo(()=>({controlsRef:i,mainCameraRef:n,defaultTarget:A,baseDistance:B,controller:o,setController:s,getPresetConfig:C,handleControlsChange:Q,cameraType:r,setCameraType:a,cameraPosition:g,setCameraPosition:c,cameraRotation:I,setCameraRotation:l,saveCameraToSession:h7A,loadCameraFromSession:UEA}),[A,B,o,C,Q,r,g,I]);return W.jsx(E7A.Provider,{value:h,children:e})},k_=()=>{const e=V.useContext(E7A);if(!e)throw new Error("useCameraController must be used within a CameraControllerProvider");return e},vxe=V.forwardRef(({children:e,scene:A,camera:t,style:i,onCreated:n},o)=>{const{cameraType:s}=k_(),r=V.useRef(null),[a,g]=V.useState(null),c=V.useRef([]),I=V.useRef(void 0);I.current=n;const l=V.useRef(null),B=V.useCallback(E=>{c.current.push(E)},[]),C=V.useCallback(E=>{c.current=c.current.filter(u=>u!==E)},[]),Q=V.useMemo(()=>new OF,[]);A?.up&&Q.up.set(A.up.x,A.up.y,A.up.z);const h=V.useRef(new Dg);return V.useImperativeHandle(o,()=>h.current),V.useEffect(()=>{if(!r.current)return;Gxe(r.current);const E=new w8({antialias:!0,alpha:!0});Mxe(E),E.setSize(r.current.clientWidth,r.current.clientHeight),E.setPixelRatio(window.devicePixelRatio),r.current.appendChild(E.domElement);const u=r.current.clientWidth/r.current.clientHeight,d=s==="perspective"?new wh(75,u,.1,1e3):new YU(-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 iae,w=()=>{const b=m.getElapsedTime(),k=m.getDelta();c.current.forEach(x=>x(b,k)),E.render(Q,d),f=requestAnimationFrame(w)};w();const D=()=>{if(r.current){const b=r.current.clientWidth/r.current.clientHeight;d instanceof wh?d.aspect=b:d instanceof YU&&(d.left=-10*b,d.right=10*b,d.top=10,d.bottom=-10),d.updateProjectionMatrix(),E.setSize(r.current.clientWidth,r.current.clientHeight)}};return window.addEventListener("resize",D),()=>{l.current={position:d.position.clone(),quaternion:d.quaternion.clone(),up:d.up.clone()},window.removeEventListener("resize",D),cancelAnimationFrame(f),r.current&&E.domElement&&r.current.removeChild(E.domElement),E.dispose(),Q.remove(h.current),window.__TSCIRCUIT_THREE_OBJECT===h.current&&(window.__TSCIRCUIT_THREE_OBJECT=void 0)}},[Q,B,C,s]),W.jsx("div",{ref:r,style:{width:"100%",height:"100%",...i},children:a&&W.jsx(u6A.Provider,{value:a,children:W.jsx(gxe,{children:e})})})}),Nxe=({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}=Yu(),l=V.useMemo(()=>!c||!I?null:new vge(c,I.domElement),[c,I]);return V.useEffect(()=>(g?.(l??null),()=>g?.(null)),[l,g]),V.useEffect(()=>{if(!l)return;const B=()=>{g?.(l)};return l.addEventListener("change",B),()=>{l.removeEventListener("change",B)}},[l,g]),V.useEffect(()=>{l&&(l.autoRotate=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:n_.ROTATE,MIDDLE:n_.PAN,RIGHT:null},a&&(l.target.set(a[0],a[1],a[2]),l.update()))},[l,e,A,i,n,o,s,r,a]),V.useEffect(()=>{if(!(!l||!t))return l.addEventListener("start",t),()=>{l.removeEventListener("start",t)}},[l,t]),V.useEffect(()=>{if(l)return()=>{l.dispose()}},[l]),xH(()=>{l?.update()},[l]),null},Lxe=`
|
|
5140
|
+
`).replace(/d 0\./g,"d 1."),B=g.replace(/newmtl[\s\S]*?endmtl/g,"").replace(/^mtllib.*/gm,""),C=new fge;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 pxe({url:e,position:A,rotation:t,onHover:i,onUnhover:n,isHovered:o,scale:s,isTranslucent:r=!1}){const a=dxe(e),{rootObject:g}=Yu(),c=V.useMemo(()=>a&&!(a instanceof Error)?(a.traverse(I=>{if(I instanceof eo&&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)}}),a):new eo(new ew(.5,.5,.5),new kE({transparent:!0,color:"red",opacity:.25})),[a,r]);if(V.useEffect(()=>{if(!(!g||!c))return g.add(c),()=>{g.remove(c)}},[g,c]),V.useEffect(()=>{c&&(A&&(Array.isArray(A)?c.position.fromArray(A):c.position.copy(A)),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 W.jsx(TH,{isHovered:o,onHover:i,onUnhover:n,object:c})}var LEA,fxe="https://cdn.jsdelivr.net/npm/occt-import-js@0.0.23/dist";function yxe(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 mxe(){if(!LEA){const e=await import("https://cdn.jsdelivr.net/npm/occt-import-js@0.0.23/+esm");LEA=yxe(e)({locateFile:t=>`${fxe}/${t}`})}return LEA}function wxe(e){const A=new If;for(const t of e){const i=t.attributes.position?.array??[],n=t.index?.array??[];if(!i.length||!n.length)continue;const o=new Sg;o.setAttribute("position",new To(i,3));const s=t.attributes.normal?.array??[];s.length?o.setAttribute("normal",new To(s,3)):o.computeVertexNormals(),o.setIndex(n);const r=new kE({color:t.color?new Oi(t.color[0],t.color[1],t.color[2]):new Oi(.82,.82,.82)}),a=new eo(o,r);a.name=t.name,A.add(a)}return A}async function Dxe(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 mxe()).ReadStepFile(new Uint8Array(t),null);if(!n.success||!n.meshes.length)throw new Error("occt-import-js failed to convert STEP file");const o=wxe(n.meshes),s=new iaA;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 c7A="step-glb-cache:";function Sxe(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 bxe(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 xxe(e){try{const A=localStorage.getItem(`${c7A}${e}`);return A?bxe(A):null}catch(A){return console.warn("Failed to read STEP GLB cache",A),null}}function I7A(e,A){try{const t=Sxe(A);localStorage.setItem(`${c7A}${e}`,t)}catch(t){console.warn("Failed to write STEP GLB cache",t)}}function _xe(){const e=globalThis;return e.stepUrlToGltfModelConversions||(e.stepUrlToGltfModelConversions={inProgress:new Map,completed:new Map}),e.stepUrlToGltfModelConversions}var kxe=({stepUrl:e,position:A,rotation:t,scale:i,onHover:n,onUnhover:o,isHovered:s,isTranslucent:r})=>{const[a,g]=V.useState(null);return V.useEffect(()=>{let c=!0,I=null,l=!0;const B=_xe(),C=xxe(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),I7A(e,Q.arrayBuffer),()=>{c=!1,I&&l&&URL.revokeObjectURL(I)};let h=B.inProgress.get(e);return h||(h=Dxe(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),I7A(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?W.jsx(g7A,{gltfUrl:a,position:A,rotation:t,scale:i,onHover:n,onUnhover:o,isHovered:s,isTranslucent:r}):null},Fxe=(e,A)=>{if(e)return A?A(e):e},l7A=(...e)=>e,B7A=({cad_component:e,circuitJson:A,resolveStaticAsset:t})=>{const i=E6A(A),[n,o]=V.useState(!1),{visibility:s}=aG(),[r,a]=V.useState(null),g=V.useCallback(w=>{w?.mousePosition?(o(!0),a(w.mousePosition)):(o(!1),a(null))},[]),c=V.useCallback(()=>{o(!1),a(null)},[]),I=V.useMemo(()=>Ti(A).source_component.getUsing({source_component_id:e.source_component_id})?.name,[A,e.source_component_id]),l=V.useMemo(()=>A.filter(D=>D.type==="pcb_plated_hole"&&D.pcb_component_id===e.pcb_component_id).length>0,[A,e.pcb_component_id]),B=V.useCallback(w=>Fxe(w,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),u=A.find(w=>w.type==="pcb_component"&&w.source_component_id===e.source_component_id)?.layer??"top",d=V.useMemo(()=>e.rotation?l7A(e.rotation.x*Math.PI/180,e.rotation.y*Math.PI/180,e.rotation.z*Math.PI/180):l7A(0,0,0),[e.rotation,u]),f=V.useMemo(()=>{if(!e.position)return;let w;return u==="top"?w=e.position.z:u==="bottom"?w=-(e.position.z+i):w=e.position.z,[e.position.x,e.position.y,w]},[e.position,u,i]);let m=null;if(C?m=W.jsx(pxe,{url:C,position:f,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):Q?m=W.jsx(g7A,{gltfUrl:Q,position:f,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):h&&!e.model_jscad&&!e.footprinter_string?m=W.jsx(kxe,{stepUrl:h,position:f,rotation:d,scale:e.model_unit_to_mm_scale_factor,onHover:g,onUnhover:c,isHovered:n,isTranslucent:e.show_as_translucent_model}):e.model_jscad?m=W.jsx(hxe,{jscadPlan:e.model_jscad,positionOffset:f,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&&(m=W.jsx(Ixe,{positionOffset:f,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})),e.show_as_translucent_model){if(!s.translucentModels)return null}else if(l&&!s.throughHoleModels||!l&&!s.smtModels)return null;return W.jsxs(W.Fragment,{children:[m,n&&r?W.jsx(d6A,{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]})},C7A={version:"0.0.519"};function Gxe(e){e.querySelectorAll("canvas").forEach(A=>A.remove())}var Mxe=e=>{e.outputColorSpace=Wm,e.toneMapping=KKA,e.toneMappingExposure=1},Q7A="cadViewerCameraStateSession",h7A=(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(Q7A,JSON.stringify(t))}catch(t){console.warn("Failed to save camera:",t)}},UEA=(e,A)=>{try{const t=sessionStorage.getItem(Q7A);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}},E7A=V.createContext(void 0),Rxe=({children:e,defaultTarget:A,initialCameraPosition:t})=>{const i=V.useRef(null),n=V.useRef(null),[o,s]=V.useState(null),[r,a]=V.useState("perspective"),[g,c]=V.useState(t??null),[I,l]=V.useState(new gf(0,0,0)),B=V.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=V.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=V.useCallback(E=>{i.current=E},[]),h=V.useMemo(()=>({controlsRef:i,mainCameraRef:n,defaultTarget:A,baseDistance:B,controller:o,setController:s,getPresetConfig:C,handleControlsChange:Q,cameraType:r,setCameraType:a,cameraPosition:g,setCameraPosition:c,cameraRotation:I,setCameraRotation:l,saveCameraToSession:h7A,loadCameraFromSession:UEA}),[A,B,o,C,Q,r,g,I]);return W.jsx(E7A.Provider,{value:h,children:e})},k_=()=>{const e=V.useContext(E7A);if(!e)throw new Error("useCameraController must be used within a CameraControllerProvider");return e},vxe=V.forwardRef(({children:e,scene:A,camera:t,style:i,onCreated:n},o)=>{const{cameraType:s}=k_(),r=V.useRef(null),[a,g]=V.useState(null),c=V.useRef([]),I=V.useRef(void 0);I.current=n;const l=V.useRef(null),B=V.useCallback(E=>{c.current.push(E)},[]),C=V.useCallback(E=>{c.current=c.current.filter(u=>u!==E)},[]),Q=V.useMemo(()=>new OF,[]);A?.up&&Q.up.set(A.up.x,A.up.y,A.up.z);const h=V.useRef(new Dg);return V.useImperativeHandle(o,()=>h.current),V.useEffect(()=>{if(!r.current)return;Gxe(r.current);const E=new w8({antialias:!0,alpha:!0});Mxe(E),E.setSize(r.current.clientWidth,r.current.clientHeight),E.setPixelRatio(window.devicePixelRatio),r.current.appendChild(E.domElement);const u=r.current.clientWidth/r.current.clientHeight,d=s==="perspective"?new wh(75,u,.1,1e3):new YU(-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 iae,w=()=>{const b=m.getElapsedTime(),k=m.getDelta();c.current.forEach(x=>x(b,k)),E.render(Q,d),f=requestAnimationFrame(w)};w();const D=()=>{if(r.current){const b=r.current.clientWidth/r.current.clientHeight;d instanceof wh?d.aspect=b:d instanceof YU&&(d.left=-10*b,d.right=10*b,d.top=10,d.bottom=-10),d.updateProjectionMatrix(),E.setSize(r.current.clientWidth,r.current.clientHeight)}};return window.addEventListener("resize",D),()=>{l.current={position:d.position.clone(),quaternion:d.quaternion.clone(),up:d.up.clone()},window.removeEventListener("resize",D),cancelAnimationFrame(f),r.current&&E.domElement&&r.current.removeChild(E.domElement),E.dispose(),Q.remove(h.current),window.__TSCIRCUIT_THREE_OBJECT===h.current&&(window.__TSCIRCUIT_THREE_OBJECT=void 0)}},[Q,B,C,s]),W.jsx("div",{ref:r,style:{width:"100%",height:"100%",...i},children:a&&W.jsx(u6A.Provider,{value:a,children:W.jsx(gxe,{children:e})})})}),Nxe=({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}=Yu(),l=V.useMemo(()=>!c||!I?null:new vge(c,I.domElement),[c,I]);return V.useEffect(()=>(g?.(l??null),()=>g?.(null)),[l,g]),V.useEffect(()=>{if(!l)return;const B=()=>{g?.(l)};return l.addEventListener("change",B),()=>{l.removeEventListener("change",B)}},[l,g]),V.useEffect(()=>{l&&(l.autoRotate=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:n_.ROTATE,MIDDLE:n_.PAN,RIGHT:null},a&&(l.target.set(a[0],a[1],a[2]),l.update()))},[l,e,A,i,n,o,s,r,a]),V.useEffect(()=>{if(!(!l||!t))return l.addEventListener("start",t),()=>{l.removeEventListener("start",t)}},[l,t]),V.useEffect(()=>{if(l)return()=>{l.dispose()}},[l]),xH(()=>{l?.update()},[l]),null},Lxe=`
|
|
5141
5141
|
varying vec3 worldPosition;
|
|
5142
5142
|
void main() {
|
|
5143
5143
|
worldPosition = (modelMatrix * vec4(position, 1.0)).xyz;
|
|
@@ -5176,7 +5176,7 @@ ${a.join(`
|
|
|
5176
5176
|
`+a+` |
|
|
5177
5177
|
`+o.line+" | "+g+`
|
|
5178
5178
|
`+a+" | "+KEA("",n.column-1," ")+KEA("",I,"^")}else A+=`
|
|
5179
|
-
at `+s}return A},eZ.buildMessage=function(e,A){var t={literal:function(g){return'"'+n(g.text)+'"'},class:function(g){var c=g.parts.map(function(I){return Array.isArray(I)?o(I[0])+"-"+o(I[1]):o(I)});return"["+(g.inverted?"^":"")+c.join("")+"]"},any:function(){return"any character"},end:function(){return"end of input"},other:function(g){return g.description}};function i(g){return g.charCodeAt(0).toString(16).toUpperCase()}function n(g){return g.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,function(c){return"\\x0"+i(c)}).replace(/[\x10-\x1F\x7F-\x9F]/g,function(c){return"\\x"+i(c)})}function o(g){return g.replace(/\\/g,"\\\\").replace(/\]/g,"\\]").replace(/\^/g,"\\^").replace(/-/g,"\\-").replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,function(c){return"\\x0"+i(c)}).replace(/[\x10-\x1F\x7F-\x9F]/g,function(c){return"\\x"+i(c)})}function s(g){return t[g.type](g)}function r(g){var c=g.map(s),I,l;if(c.sort(),c.length>0){for(I=1,l=1;I<c.length;I++)c[I-1]!==c[I]&&(c[l]=c[I],l++);c.length=l}switch(c.length){case 1:return c[0];case 2:return c[0]+" or "+c[1];default:return c.slice(0,-1).join(", ")+", or "+c[c.length-1]}}function a(g){return g?'"'+n(g)+'"':"end of input"}return"Expected "+r(e)+" but "+a(A)+" found."};var w_e=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(let o=1;o<e.length;o++){const s=e[o];s.x<A&&(A=s.x),s.y<t&&(t=s.y),s.x>i&&(i=s.x),s.y>n&&(n=s.y)}return{minX:A,minY:t,maxX:i,maxY:n}};function yD(e){if(e.outline&&e.outline.length>=3){const s=w_e(e.outline);return{...s,width:s.maxX-s.minX,height:s.maxY-s.minY,centerX:(s.minX+s.maxX)/2,centerY:(s.minY+s.maxY)/2}}const A=e.width??0,t=e.height??0,i=e.center?.x??0,n=e.center?.y??0;return{...{minX:i-A/2,maxX:i+A/2,minY:n-t/2,maxY:n+t/2},width:A,height:t,centerX:i,centerY:n}}function iZ(e,A){if(e===void 0)return A;if(typeof e=="number")return e;const t=parseFloat(e.replace(/mm$/,""));return isNaN(t)?A:t}function D_e(e){return e.layer==="bottom"?e.is_mirrored!==!1:e.is_mirrored===!0}function S_e(e){const A=e.flat();if(A.length===0)return{minX:0,maxX:0,minY:0,maxY:0,width:0,height:0,centerX:0,centerY:0};const t=Math.min(...A.map(s=>s[0])),i=Math.max(...A.map(s=>s[0])),n=Math.min(...A.map(s=>s[1])),o=Math.max(...A.map(s=>s[1]));return{minX:t,maxX:i,minY:n,maxY:o,width:i-t,height:o-n,centerX:(t+i)/2,centerY:(n+o)/2}}function b_e(e){const A=[];return e.forEach(t=>{t.length===29?(A.push(t.slice(0,15)),A.push(t.slice(14,29))):t.length===17?(A.push(t.slice(0,10)),A.push(t.slice(9,17))):A.push(t)}),A}function x_e(e,A){let t=-e.centerX,i=-e.centerY;return A.includes("left")?t=-e.minX:A.includes("right")&&(t=-e.maxX),A.includes("top")?i=-e.maxY:A.includes("bottom")&&(i=-e.minY),{x:t,y:i}}function __e(e,A){const t=[];let i=e.ccw_rotation??0;if(D_e(e)&&(t.push(G_(A.centerX,A.centerY),{a:-1,b:0,c:0,d:1,e:0,f:0},G_(-A.centerX,-A.centerY)),i=-i),i){const s=i*Math.PI/180;t.push(G_(A.centerX,A.centerY),_7A(s),G_(-A.centerX,-A.centerY))}return{matrix:t.length>0?x7A(...t):void 0,rotationDeg:i}}function k7A(e,A,t,i,n,o,s){A.forEach(r=>{e.beginPath(),r.forEach((a,g)=>{let c={x:a[0],y:a[1]};t&&(c=S7A(t,c));const I=c.x+i.x+n.x,l=c.y+i.y+n.y,B=o(I),C=s(l);g===0?e.moveTo(B,C):e.lineTo(B,C)}),e.stroke()})}function k_e(e,A,t,i,n,o){e.save(),e.translate(A,t),e.rotate(-o),e.fillRect(-i/2,-n/2,i,n),e.restore()}function F_e(e,A,t,i,n,o,s,r,a,g){const c=typeof A.font_size=="number"?A.font_size:.2,I={left:iZ(A.knockout_padding?.left,c*.5),right:iZ(A.knockout_padding?.right,c*.5),top:iZ(A.knockout_padding?.top,c*.3),bottom:iZ(A.knockout_padding?.bottom,c*.3)},l=i.width+I.left+I.right,B=i.height+I.top+I.bottom,C=s(A.anchor_position.x),Q=r(A.anchor_position.y),h=l*a,E=B*a;e.fillStyle=g;const u=o*Math.PI/180;k_e(e,C,Q,h,E,u);const d={x:-i.centerX,y:-i.centerY};e.globalCompositeOperation="destination-out",k7A(e,t,n,d,A.anchor_position,s,r),e.globalCompositeOperation="source-over"}function G_e({layer:e,circuitJson:A,boardData:t,copperColor:i="rgb(230, 153, 51)",traceTextureResolution:n}){const s=A.filter(Q=>Q.type==="pcb_copper_text").filter(Q=>Q.layer===e);if(s.length===0)return null;const r=yD(t),a=document.createElement("canvas"),g=Math.floor(r.width*n),c=Math.floor(r.height*n);a.width=g,a.height=c;const I=a.getContext("2d");if(!I)return null;e==="bottom"&&(I.translate(0,c),I.scale(1,-1)),I.strokeStyle=i,I.fillStyle=i;const l=Q=>(Q-r.minX)*n,B=Q=>(r.maxY-Q)*n;s.forEach(Q=>{const h=typeof Q.font_size=="number"?Q.font_size:.2,E=Math.max(.02,h*.08)*n;I.lineWidth=E,I.lineCap="round",I.lineJoin="round";const u=(0,p_e.vectorText)({height:h*.45,input:Q.text}),d=b_e(u),f=S_e(d),{matrix:m,rotationDeg:w}=__e(Q,f);if(Q.is_knockout)F_e(I,Q,d,f,m,w,l,B,n,i);else{const D=Q.anchor_alignment||"center",b=x_e(f,D);k7A(I,d,m,b,Q.anchor_position,l,B)}});const C=new E_(a);return C.generateMipmaps=!0,C.minFilter=xE,C.magFilter=mI,C.anisotropy=16,C.needsUpdate=!0,C}function M_e({layer:e,circuitJson:A,boardData:t,copperColor:i,traceTextureResolution:n}){const s=Ti(A).pcb_smtpad.list().filter(Q=>Q.layer===e);if(s.length===0)return null;const r=yD(t),a=document.createElement("canvas"),g=Math.floor(r.width*n),c=Math.floor(r.height*n);a.width=g,a.height=c;const I=a.getContext("2d");if(!I)return null;e==="bottom"&&(I.translate(0,c),I.scale(1,-1));const l=Q=>(Q-r.minX)*n,B=Q=>(r.maxY-Q)*n;I.fillStyle=i,s.forEach(Q=>{if(Q.shape==="polygon"&&Q.points){I.beginPath(),Q.points.forEach((f,m)=>{const w=l(f.x),D=B(f.y);m===0?I.moveTo(w,D):I.lineTo(w,D)}),I.closePath(),I.fill();return}if(Q.x===void 0||Q.y===void 0)return;const h=Q.x,E=Q.y,u=l(h),d=B(E);if(Q.shape==="rect"){const f=Q.width*n,m=Q.height*n,w=Ty(Q),D=gG(Q.width,Q.height,w)*n;D>0?(I.beginPath(),I.roundRect(u-f/2,d-m/2,f,m,D),I.fill()):I.fillRect(u-f/2,d-m/2,f,m)}else if(Q.shape==="circle"){const f=(Q.radius??Q.width/2)*n;I.beginPath(),I.arc(u,d,f,0,2*Math.PI),I.fill()}else if(Q.shape==="pill"||Q.shape==="rotated_pill"){const f=Q.width*n,m=Q.height*n,w=Math.min(f,m)/2,b=-(Q.ccw_rotation||0)*(Math.PI/180);b?(I.save(),I.translate(u,d),I.rotate(b),I.beginPath(),I.roundRect(-f/2,-m/2,f,m,w),I.fill(),I.restore()):(I.beginPath(),I.roundRect(u-f/2,d-m/2,f,m,w),I.fill())}else if(Q.shape==="rotated_rect"){const f=Q.width*n,m=Q.height*n,w=Ty(Q),D=gG(Q.width,Q.height,w)*n,k=-(Q.ccw_rotation||0)*(Math.PI/180);I.save(),I.translate(u,d),I.rotate(k),I.beginPath(),I.roundRect(-f/2,-m/2,f,m,D),I.fill(),I.restore()}});const C=new E_(a);return C.generateMipmaps=!0,C.minFilter=xE,C.magFilter=mI,C.anisotropy=16,C.needsUpdate=!0,C}function R_e({layer:e,circuitJson:A,panelData:t,outlineColor:i="black",traceTextureResolution:n}){const o=Ti(A).pcb_board.list().filter(B=>B.pcb_panel_id===t.pcb_board_id);if(o.length===0)return null;const s=document.createElement("canvas"),r=Math.floor(t.width*n),a=Math.floor(t.height*n);s.width=r,s.height=a;const g=s.getContext("2d");if(!g)return null;e==="bottom"&&(g.translate(0,a),g.scale(1,-1)),g.strokeStyle=i,g.lineWidth=.05*n;const c=B=>(B-t.center.x+t.width/2)*n,I=B=>(-(B-t.center.y)+t.height/2)*n;o.forEach(B=>{if(B.outline&&B.outline.length>=2)g.beginPath(),B.outline.forEach((C,Q)=>{const h=c(C.x),E=I(C.y);Q===0?g.moveTo(h,E):g.lineTo(h,E)}),g.closePath(),g.stroke();else{const C=B.width,Q=B.height,{x:h,y:E}=B.center,u=c(h-C/2),d=I(E+Q/2);g.strokeRect(u,d,C*n,Q*n)}});const l=new E_(s);return l.generateMipmaps=!0,l.minFilter=xE,l.magFilter=mI,l.anisotropy=16,l.needsUpdate=!0,l}var v_e=Kr(iEA()),F7A=25.4,N_e=F7A/1e3,L_e=/^\s*(-?\d*(?:\.\d+)?)(?:\s*(mm|mil|inch|in|"))?\s*$/i;function U_e(e){if(!e)return;const A=e.trim().toLowerCase();return A==='"'||A==="inch"?"in":A}function GQ(e){if(e==null)return;if(typeof e=="number")return Number.isFinite(e)?e:void 0;if(typeof e!="string")return;const A=e.trim();if(A.length===0)return;const t=A.match(L_e);if(!t){const r=Number.parseFloat(A);return Number.isFinite(r)?r:void 0}const[,i,n]=t,o=Number.parseFloat(i||"0");if(!Number.isFinite(o))return;switch(U_e(n)){case"mil":return o*N_e;case"in":return o*F7A;case"mm":case void 0:return o;default:return o}}function aw(e,A){const t=GQ(e);return t===void 0?A:t}function G7A(e){let A=e;if(A.startsWith("#")&&(A=A.slice(1)),A.length===6){const t=parseInt(A.slice(0,2),16),i=parseInt(A.slice(2,4),16),n=parseInt(A.slice(4,6),16);return`rgb(${t}, ${i}, ${n})`}return e.startsWith("rgb")?e:"rgb(255, 243, 204)"}function H_e({layer:e,circuitJson:A,boardData:t,silkscreenColor:i="rgb(255,255,255)",traceTextureResolution:n}){const o=Ti(A).pcb_silkscreen_text.list(),s=Ti(A).pcb_silkscreen_path.list(),r=Ti(A).pcb_silkscreen_line.list(),a=Ti(A).pcb_silkscreen_rect.list(),g=Ti(A).pcb_silkscreen_circle.list(),c=Ti(A).pcb_fabrication_note_rect.list(),I=Ti(A).pcb_note_line.list(),l=o.filter(v=>v.layer===e),B=s.filter(v=>v.layer===e),C=r.filter(v=>v.layer===e),Q=a.filter(v=>v.layer===e),h=g.filter(v=>v.layer===e),E=c.filter(v=>v.layer===e),u=I.filter(v=>v.layer===e);if(l.length===0&&B.length===0&&C.length===0&&Q.length===0&&h.length===0&&E.length===0&&u.length===0)return null;const d=yD(t),f=document.createElement("canvas"),m=Math.floor(d.width*n),w=Math.floor(d.height*n);f.width=m,f.height=w;const D=f.getContext("2d");if(!D)return null;e==="bottom"&&(D.translate(0,w),D.scale(1,-1)),D.strokeStyle=i,D.fillStyle=i;const b=v=>(v-d.minX)*n,k=v=>(d.maxY-v)*n;C.forEach(v=>{const R=GQ(v.x1)??0,U=GQ(v.y1)??0,J=GQ(v.x2)??0,H=GQ(v.y2)??0;R===J&&U===H||(D.beginPath(),D.lineWidth=aw(v.stroke_width,.1)*n,D.lineCap="round",D.moveTo(b(R),k(U)),D.lineTo(b(J),k(H)),D.stroke())}),u.forEach(v=>{const R=GQ(v.x1)??0,U=GQ(v.y1)??0,J=GQ(v.x2)??0,H=GQ(v.y2)??0;if(R===J&&U===H)return;D.save();let O=i;v.color?O=G7A(v.color):O="rgb(255, 243, 204)",D.strokeStyle=O,D.beginPath(),D.lineWidth=aw(v.stroke_width,.1)*n,D.lineCap="round";const Z=v.is_dashed??!1;if(Z){const X=Math.max(D.lineWidth*2,1);D.setLineDash([X,X])}D.moveTo(b(R),k(U)),D.lineTo(b(J),k(H)),D.stroke(),Z&&D.setLineDash([]),D.restore()}),B.forEach(v=>{v.route.length<2||(D.beginPath(),D.lineWidth=aw(v.stroke_width,.1)*n,D.lineCap="round",D.lineJoin="round",v.route.forEach((R,U)=>{const J=b(GQ(R.x)??0),H=k(GQ(R.y)??0);U===0?D.moveTo(J,H):D.lineTo(J,H)}),D.stroke())}),h.forEach(v=>{const R=aw(v.radius,0);if(R<=0)return;const U=aw(v.stroke_width,.12),J=U>0,H=GQ(v.center?.x)??0,O=GQ(v.center?.y)??0,Z=b(H),X=k(O),iA=R*n;if(D.save(),D.translate(Z,X),J){const aA=iA+U/2*n,tA=Math.max(0,iA-U/2*n);tA>0?(D.beginPath(),D.arc(0,0,aA,0,2*Math.PI),D.arc(0,0,tA,0,2*Math.PI,!0),D.fill("evenodd")):(D.beginPath(),D.arc(0,0,aA,0,2*Math.PI),D.fill())}else D.beginPath(),D.arc(0,0,iA,0,2*Math.PI),D.fill();D.restore()}),Q.forEach(v=>{const R=aw(v.width,0),U=aw(v.height,0);if(R<=0||U<=0)return;const J=GQ(v.center?.x)??0,H=GQ(v.center?.y)??0,O=b(J),Z=k(H),X=Ty(v),iA=typeof X=="string"?GQ(X):X,aA=gG(R,U,iA);D.save(),D.translate(O,Z);const tA=R/2*n,eA=U/2*n,sA=Math.min(aA*n,tA,eA),IA=v.stroke_width??!1,uA=v.is_filled??!0,xA=v.is_stroke_dashed??!1,kA=IA?aw(v.stroke_width,.1)*n:0;if(((QA,_A,pA,KA,WA)=>{if(D.beginPath(),WA<=0)D.rect(QA,_A,pA,KA);else{const st=WA,yA=QA+pA,jA=_A+KA;D.moveTo(QA+st,_A),D.lineTo(yA-st,_A),D.quadraticCurveTo(yA,_A,yA,_A+st),D.lineTo(yA,jA-st),D.quadraticCurveTo(yA,jA,yA-st,jA),D.lineTo(QA+st,jA),D.quadraticCurveTo(QA,jA,QA,jA-st),D.lineTo(QA,_A+st),D.quadraticCurveTo(QA,_A,QA+st,_A),D.closePath()}})(-tA,-eA,tA*2,eA*2,sA),uA&&D.fill(),IA&&kA>0){if(D.lineWidth=kA,xA){const QA=Math.max(kA*2,1);D.setLineDash([QA,QA])}D.stroke(),xA&&D.setLineDash([])}D.restore()}),E.forEach(v=>{const R=aw(v.width,0),U=aw(v.height,0);if(R<=0||U<=0)return;const J=GQ(v.center?.x)??0,H=GQ(v.center?.y)??0,O=b(J),Z=k(H),X=Ty(v),iA=typeof X=="string"?GQ(X):X,aA=gG(R,U,iA);D.save(),D.translate(O,Z);const tA=R/2*n,eA=U/2*n,sA=Math.min(aA*n,tA,eA),IA=v.has_stroke??!1,uA=v.is_filled??!0,xA=v.is_stroke_dashed??!1,kA=IA?aw(v.stroke_width,.1)*n:0;let YA=i,QA=i;if(v.color){const pA=G7A(v.color);YA=pA,QA=pA}else YA="rgb(255, 243, 204)",QA="rgb(255, 243, 204)";if(((pA,KA,WA,st,yA)=>{if(D.beginPath(),yA<=0)D.rect(pA,KA,WA,st);else{const jA=yA,PA=pA+WA,HA=KA+st;D.moveTo(pA+jA,KA),D.lineTo(PA-jA,KA),D.quadraticCurveTo(PA,KA,PA,KA+jA),D.lineTo(PA,HA-jA),D.quadraticCurveTo(PA,HA,PA-jA,HA),D.lineTo(pA+jA,HA),D.quadraticCurveTo(pA,HA,pA,HA-jA),D.lineTo(pA,KA+jA),D.quadraticCurveTo(pA,KA,pA+jA,KA),D.closePath()}})(-tA,-eA,tA*2,eA*2,sA),uA&&(D.fillStyle=YA,D.fill()),IA&&kA>0){if(D.strokeStyle=QA,D.lineWidth=kA,xA){const pA=Math.max(kA*2,1);D.setLineDash([pA,pA])}D.stroke(),xA&&D.setLineDash([])}D.restore()}),l.forEach(v=>{const R=v.font_size||.25,U=Math.min(Math.max(.01,R*.1),R*.05)*n;D.lineWidth=U,D.lineCap="butt",D.lineJoin="miter";const J=(0,v_e.vectorText)({height:R*.45,input:v.text}),H=[];J.forEach(xA=>{xA.length===29?(H.push(xA.slice(0,15)),H.push(xA.slice(14,29))):xA.length===17?(H.push(xA.slice(0,10)),H.push(xA.slice(9,17))):H.push(xA)});const O=H.flat(),Z={minX:O.length>0?Math.min(...O.map(xA=>xA[0])):0,maxX:O.length>0?Math.max(...O.map(xA=>xA[0])):0,minY:O.length>0?Math.min(...O.map(xA=>xA[1])):0,maxY:O.length>0?Math.max(...O.map(xA=>xA[1])):0},X=(Z.minX+Z.maxX)/2,iA=(Z.minY+Z.maxY)/2;let aA=-X,tA=-iA;const eA=v.anchor_alignment||"center";eA.includes("left")?aA=-Z.minX:eA.includes("right")&&(aA=-Z.maxX),eA.includes("top")?tA=-Z.maxY:eA.includes("bottom")&&(tA=-Z.minY);const sA=[];let IA=v.ccw_rotation??0;if(v.layer==="bottom"&&(sA.push(G_(X,iA),{a:-1,b:0,c:0,d:1,e:0,f:0},G_(-X,-iA)),IA=-IA),IA){const xA=IA*Math.PI/180;sA.push(G_(X,iA),_7A(xA),G_(-X,-iA))}const uA=sA.length>0?x7A(...sA):void 0;H.forEach(xA=>{D.beginPath(),xA.forEach((kA,YA)=>{let QA={x:kA[0],y:kA[1]};uA&&(QA=S7A(uA,QA));const _A=QA.x+aA+v.anchor_position.x,pA=QA.y+tA+v.anchor_position.y,KA=b(_A),WA=k(pA);YA===0?D.moveTo(KA,WA):D.lineTo(KA,WA)}),D.stroke()})});const x=new E_(f);return x.generateMipmaps=!0,x.minFilter=xE,x.magFilter=mI,x.anisotropy=16,x.needsUpdate=!0,x}function M7A(e){return e&&e.route_type==="wire"&&typeof e.layer=="string"&&typeof e.width=="number"}function Y_e({layer:e,circuitJson:A,boardData:t,traceColor:i,traceTextureResolution:n}){const o=Ti(A).pcb_trace.list(),s=Ti(A).pcb_via.list(),r=Ti(A).pcb_plated_hole.list(),a=o.filter(Q=>Q.route.some(h=>M7A(h)&&h.layer===e));if(a.length===0)return null;const g=yD(t),c=document.createElement("canvas"),I=Math.floor(g.width*n),l=Math.floor(g.height*n);c.width=I,c.height=l;const B=c.getContext("2d");if(!B)return null;e==="bottom"&&(B.translate(0,l),B.scale(1,-1)),a.forEach(Q=>{let h=!0;B.beginPath(),B.strokeStyle=i,B.lineCap="round",B.lineJoin="round";let E=0;for(const u of Q.route){if(!M7A(u)||u.layer!==e){h||B.stroke(),h=!0;continue}const d=u.x,f=u.y;E=u.width*n,B.lineWidth=E;const m=(d-g.minX)*n,w=(g.maxY-f)*n;h?(B.moveTo(m,w),h=!1):B.lineTo(m,w)}h||B.stroke()}),B.globalCompositeOperation="destination-out",B.fillStyle="black",s.forEach(Q=>{const h=(Q.x-g.minX)*n,E=(g.maxY-Q.y)*n,u=Q.outer_diameter/2*n;B.beginPath(),B.arc(h,E,u,0,2*Math.PI,!1),B.fill()}),r.forEach(Q=>{if(Q.layers.includes(e)&&Q.shape==="circle"){const h=(Q.x-g.minX)*n,E=(g.maxY-Q.y)*n,u=Q.outer_diameter/2*n;B.beginPath(),B.arc(h,E,u,0,2*Math.PI,!1),B.fill()}else if(Q.layers.includes(e)&&Q.shape==="rotated_pill_hole_with_rect_pad"){const h=(Q.x-g.minX)*n,E=(g.maxY-Q.y)*n,u=(Q.rect_pad_width??Q.hole_width??0)*n,d=(Q.rect_pad_height??Q.hole_height??0)*n,m=-(Q.rect_ccw_rotation||0);m?(B.save(),B.translate(h,E),B.rotate(m*Math.PI/180),B.beginPath(),B.rect(-u/2,-d/2,u,d),B.fill(),B.restore()):(B.beginPath(),B.rect(h-u/2,E-d/2,u,d),B.fill())}}),B.globalCompositeOperation="source-over";const C=new E_(c);return C.generateMipmaps=!0,C.minFilter=xE,C.magFilter=mI,C.anisotropy=16,C.needsUpdate=!0,C}Kr(b_()),Kr(gN());function J_e(e,A,t,i){if(!t||Math.abs(t)<1e-9)return[];const n=4*Math.atan(t),o=A[0]-e[0],s=A[1]-e[1],r=Math.sqrt(o*o+s*s);if(r<1e-9)return[];const a=Math.abs(r/(2*Math.sin(n/2))),g=Math.sqrt(Math.max(0,a*a-r/2*(r/2))),c=[(e[0]+A[0])/2,(e[1]+A[1])/2],I=o/r,B=-(s/r),C=I,Q=c[0]+B*g*Math.sign(t),h=c[1]+C*g*Math.sign(t),E=Math.atan2(e[1]-h,e[0]-Q),u=[],d=Math.max(2,Math.ceil(i*Math.abs(n)/(Math.PI*2)*4)),f=n/d;for(let m=1;m<d;m++){const w=E+f*m;u.push([Q+a*Math.cos(w),h+a*Math.sin(w)])}return u}function R7A(e,A){const t=[],i=e.vertices;for(let n=0;n<i.length;n++){const o=i[n],s=i[(n+1)%i.length];if(t.push([o.x,o.y]),o.bulge){const r=J_e([o.x,o.y],[s.x,s.y],o.bulge,A);t.push(...r)}}return t}function v7A({ctx:e,points:A,canvasXFromPcb:t,canvasYFromPcb:i}){A.length<3||(e.beginPath(),A.forEach((n,o)=>{const s=t(n[0]),r=i(n[1]);o===0?e.moveTo(s,r):e.lineTo(s,r)}),e.closePath(),e.fill())}function T_e({ctx:e,pour:A,canvasXFromPcb:t,canvasYFromPcb:i}){const n=A.brep_shape;if(!n||!n.outer_ring)return;const o=R7A(n.outer_ring,32);if(o.length>=3&&v7A({ctx:e,points:o,canvasXFromPcb:t,canvasYFromPcb:i}),n.inner_rings&&n.inner_rings.length>0){e.globalCompositeOperation="destination-out";for(const s of n.inner_rings){const r=R7A(s,32);r.length>=3&&v7A({ctx:e,points:r,canvasXFromPcb:t,canvasYFromPcb:i})}e.globalCompositeOperation="source-over"}}function K_e({layer:e,circuitJson:A,boardData:t,traceTextureResolution:i=yN}){const n=A.filter(E=>E.type==="pcb_copper_pour"),o=e==="top"?"top_copper":"bottom_copper",s=n.filter(E=>E.layer===e);if(s.length===0)return null;const r=yD(t),a=document.createElement("canvas"),g=Math.floor(r.width*i),c=Math.floor(r.height*i);a.width=g,a.height=c;const I=a.getContext("2d");if(!I)return null;e==="bottom"&&(I.translate(0,c),I.scale(1,-1));const l=E=>(E-r.minX)*i,B=E=>(r.maxY-E)*i,C=s.filter(E=>E.shape==="rect"||E.shape==="polygon"),Q=s.filter(E=>E.shape==="brep");if(C.length>0){const E=new vhA(I);E.setCameraBounds({minX:r.minX,maxX:r.maxX,minY:r.minY,maxY:r.maxY});const u=C.filter(w=>w.covered_with_solder_mask!==!1),d=C.filter(w=>w.covered_with_solder_mask===!1),f=`rgb(${pr.fr4TracesWithMaskGreen.map(w=>w*255).join(",")})`,m=`rgb(${pr.copper.map(w=>w*255).join(",")})`;u.length>0&&(E.configure({colorOverrides:{copper:{top:f,bottom:f,inner1:f,inner2:f,inner3:f,inner4:f,inner5:f,inner6:f}}}),E.drawElements(u,{layers:[o]})),d.length>0&&(E.configure({colorOverrides:{copper:{top:m,bottom:m,inner1:m,inner2:m,inner3:m,inner4:m,inner5:m,inner6:m}}}),E.drawElements(d,{layers:[o]}))}for(const E of Q){const d=E.covered_with_solder_mask!==!1?pr.fr4TracesWithMaskGreen:pr.copper,f=`rgb(${d[0]*255}, ${d[1]*255}, ${d[2]*255})`;I.fillStyle=f,T_e({ctx:I,pour:E,canvasXFromPcb:l,canvasYFromPcb:B})}const h=new E_(a);return h.generateMipmaps=!0,h.minFilter=xE,h.magFilter=mI,h.anisotropy=16,h.needsUpdate=!0,h}var nZ=e=>{const[A=0,t=0,i=0]=e;return`rgb(${Math.round(A*255)}, ${Math.round(t*255)}, ${Math.round(i*255)})`},P_e=e=>{const A=nZ(jxe[e]??pr.fr4SolderMaskGreen),t=nZ(e==="fr1"?pr.fr1TracesWithMaskCopper:pr.fr4TracesWithMaskGreen);return{soldermask:A,soldermaskOverCopper:t,copper:nZ(pr.copper),transparent:"rgba(0,0,0,0)"}},N7A=(e,A)=>{e.setCameraBounds({minX:A.minX,maxX:A.maxX,minY:A.minY,maxY:A.maxY})},q_e=({ctx:e,layer:A,bounds:t,elements:i,boardMaterial:n})=>{const o=P_e(n),s=A==="top"?"top_copper":"bottom_copper",r=new vhA(e);r.configure({colorOverrides:{copper:{top:o.transparent,bottom:o.transparent,inner1:o.transparent,inner2:o.transparent,inner3:o.transparent,inner4:o.transparent,inner5:o.transparent,inner6:o.transparent},drill:o.transparent,boardOutline:o.transparent,substrate:o.transparent,keepout:o.transparent,fabricationNote:o.transparent,silkscreen:{top:o.transparent,bottom:o.transparent},courtyard:{top:o.transparent,bottom:o.transparent},soldermask:{top:o.soldermask,bottom:o.soldermask},soldermaskWithCopperUnderneath:{top:o.soldermaskOverCopper,bottom:o.soldermaskOverCopper},soldermaskOverCopper:{top:o.soldermaskOverCopper,bottom:o.soldermaskOverCopper}}}),N7A(r,t),r.drawElements(i,{layers:[s],drawSoldermask:!0,drawSoldermaskTop:A==="top",drawSoldermaskBottom:A==="bottom"});const a=i.filter(g=>g.type==="pcb_copper_pour"&&g.layer===A&&g.covered_with_solder_mask===!1);if(a.length>0){e.save(),e.globalCompositeOperation="destination-out";const g=new vhA(e);g.configure({colorOverrides:{copper:{top:o.copper,bottom:o.copper,inner1:o.copper,inner2:o.copper,inner3:o.copper,inner4:o.copper,inner5:o.copper,inner6:o.copper}}}),N7A(g,t),g.drawElements(a,{layers:[s]}),e.restore()}},O_e=e=>({minX:e.center.x-e.width/2,maxX:e.center.x+e.width/2,minY:e.center.y-e.height/2,maxY:e.center.y+e.height/2,width:e.width,height:e.height,centerX:e.center.x,centerY:e.center.y}),W_e=(e,A)=>{const t=Math.min(e.minX,A.minX),i=Math.max(e.maxX,A.maxX),n=Math.min(e.minY,A.minY),o=Math.max(e.maxY,A.maxY);return{minX:t,maxX:i,minY:n,maxY:o,width:i-t,height:o-n,centerX:(t+i)/2,centerY:(n+o)/2}},Z_e=(e,A)=>{const t=e.filter(s=>s.type==="pcb_panel"),i=e.filter(s=>s.type==="pcb_board"),n=t.find(s=>s.pcb_panel_id===A.pcb_board_id)??t[0];return n&&n.width>0&&n.height>0?O_e(n):(i.length>1?i:[A]).map(s=>yD(s)).reduce((s,r)=>W_e(s,r))};function V_e({layer:e,circuitJson:A,boardData:t,traceTextureResolution:i=yN}){const n=Z_e(A,t),o=Math.floor(n.width*i),s=Math.floor(n.height*i);if(o<=0||s<=0)return null;const r=document.createElement("canvas");r.width=o,r.height=s;const a=r.getContext("2d");if(!a)return null;e==="bottom"&&(a.translate(0,s),a.scale(1,-1));const g=A.some(I=>I.type==="pcb_board")?A:[t,...A];q_e({ctx:a,layer:e,bounds:n,elements:g,boardMaterial:t.material});const c=new E_(r);return c.generateMipmaps=!0,c.minFilter=xE,c.magFilter=mI,c.anisotropy=16,c.needsUpdate=!0,c}var PEA=e=>{const[A=0,t=0,i=0]=e;return`rgb(${Math.round(A*255)}, ${Math.round(t*255)}, ${Math.round(i*255)})`},j_e=({textures:e,boardData:A,traceTextureResolution:t})=>{if(!e.some(c=>c?.image))return null;const n=yD(A),o=Math.floor(n.width*t),s=Math.floor(n.height*t);if(o<=0||s<=0)return null;const r=document.createElement("canvas");r.width=o,r.height=s+1;const a=r.getContext("2d");if(!a)return null;e.forEach(c=>{if(!c?.image)return;const I=c.image;a.drawImage(I,0,0,o,s)});const g=new E_(r);return g.generateMipmaps=!1,g.minFilter=mI,g.magFilter=mI,g.premultiplyAlpha=!0,g.anisotropy=16,g.needsUpdate=!0,g};function L7A({circuitJson:e,boardData:A,traceTextureResolution:t,visibility:i}){const n=PEA(pr.fr4TracesWithMaskGreen),o=PEA(pr.fr4TracesWithoutMaskTan),s="rgb(255,255,255)",r=PEA(pr.copper),a=i?.boardBody??!0,g=I=>{const l=(I==="top"?i?.topMask:i?.bottomMask)??!0,B=(I==="top"?i?.topCopper:i?.bottomCopper)??!0,C=(I==="top"?i?.topSilkscreen:i?.bottomSilkscreen)??!0,Q=l?V_e({layer:I,circuitJson:e,boardData:A,traceTextureResolution:t}):null,h=B?Y_e({layer:I,circuitJson:e,boardData:A,traceColor:l?n:o,traceTextureResolution:t}):null,E=B?G_e({layer:I,circuitJson:e,boardData:A,copperColor:r,traceTextureResolution:t}):null,u=B?K_e({layer:I,circuitJson:e,boardData:A,traceTextureResolution:t}):null,d=B?M_e({layer:I,circuitJson:e,boardData:A,copperColor:r,traceTextureResolution:t}):null,f=C?H_e({layer:I,circuitJson:e,boardData:A,silkscreenColor:s,traceTextureResolution:t}):null,m=a?R_e({layer:I,circuitJson:e,panelData:A,traceTextureResolution:t}):null;return j_e({textures:[u,h,E,d,Q,f,m],boardData:A,traceTextureResolution:t})},c=A.num_layers??2;return{topBoard:g("top"),bottomBoard:c<2?null:g("bottom")}}function U7A(e,A){const{texture:t,yOffset:i,isBottomLayer:n,usePolygonOffset:o=!1,renderOrder:s=0,isFaux:r=!1}=e;if(!t)return null;const a=yD(A),g=new iw(a.width,a.height),c=new Rd({map:t,transparent:!0,alphaTest:.08,side:ZB,depthWrite:!0,polygonOffset:o,polygonOffsetFactor:o?-4:0,polygonOffsetUnits:o?-4:0,opacity:r?XW:1}),I=new eo(g,c);return I.position.set(a.centerX,a.centerY,i),n&&I.rotation.set(Math.PI,0,0),I.name=`${n?"bottom":"top"}-board-texture-plane`,I.renderOrder=s,I}function z_e(e,A,t,i=!1){const n=[];if(!e||!A||t===null)return n;const o=.005,s=U7A({texture:e.topBoard,yOffset:t/2+o,isBottomLayer:!1,usePolygonOffset:!0,renderOrder:1,isFaux:i},A);s&&n.push(s);const r=U7A({texture:e.bottomBoard,yOffset:-t/2-o,isBottomLayer:!0,usePolygonOffset:!0,renderOrder:1,isFaux:i},A);return r&&n.push(r),n}var X_e=4e6,$_e=4096,Ake=1;function H7A(e,A,t={}){const{maxTexturePixels:i=X_e,maxTextureDimension:n=$_e,minTextureResolution:o=Ake}=t,s=yD(e);if(!Number.isFinite(s.width)||!Number.isFinite(s.height)||s.width<=0||s.height<=0)return A;const r=Math.max(s.width,s.height),a=n/r,g=Math.sqrt(i/(s.width*s.height)),c=Math.min(A,a,g);return Math.max(o,c)}function tke({circuitJson:e,pcbThickness:A,isFaux:t=!1}){const{rootObject:i}=Yu(),{visibility:n}=aG(),o=V.useMemo(()=>{const a=e.filter(I=>I.type==="pcb_panel"),g=Ti(e).pcb_board.list();if(a.length>0){const I=a[0],l=g.find(B=>B.pcb_panel_id===I.pcb_panel_id);return{type:"pcb_board",pcb_board_id:I.pcb_panel_id,center:I.center,width:I.width,height:I.height,thickness:l?.thickness??1.4,material:l?.material??"fr4",num_layers:l?.num_layers??2}}const c=g.filter(I=>!I.pcb_panel_id);return c.length>0?c[0]:null},[e]),s=V.useMemo(()=>o?H7A(o,yN):yN,[o]),r=V.useMemo(()=>!o||!o.width||!o.height?null:L7A({circuitJson:e,boardData:o,traceTextureResolution:s,visibility:n}),[e,o,s,n]);return V.useEffect(()=>{if(!i||!o||!r)return;const a=[],g=C=>{const Q=["map","alphaMap","aoMap","bumpMap","displacementMap","emissiveMap","lightMap","metalnessMap","normalMap","roughnessMap","specularMap"],h=C;for(const E of Q){const u=h[E];u&&u instanceof qc&&(u.dispose(),h[E]=null)}C.dispose()},c=(C,Q,h,E,u=!1,d=!0,f=1)=>{if(!C)return null;const m=yD(o),w=new iw(m.width,m.height),D=new Rd({map:C,transparent:!0,alphaTest:.08,side:ZB,depthWrite:d,polygonOffset:u,polygonOffsetFactor:u?-4:0,polygonOffsetUnits:u?-4:0,opacity:t?XW:1}),b=new eo(w,D);return b.position.set(m.centerX,m.centerY,Q),h&&b.rotation.set(Math.PI,0,0),b.name=E,b.renderOrder=f,b.frustumCulled=!1,b},I=.005,l=c(r.topBoard,A/2+I,!1,"jscad-top-board-texture",!0);l&&(a.push(l),i.add(l));const B=c(r.bottomBoard,-A/2-I,!0,"jscad-bottom-board-texture",!0);return B&&(a.push(B),i.add(B)),()=>{a.forEach(C=>{C.parent===i&&i.remove(C),C.geometry.dispose(),Array.isArray(C.material)?C.material.forEach(Q=>g(Q)):C.material instanceof cf&&g(C.material)}),r.topBoard?.dispose(),r.bottomBoard?.dispose()}},[i,o,r,A]),null}function eke(e){const A=Ti(e).cad_component.list(),t=Ti(e).pcb_smtpad.list(),i=Ti(e).pcb_hole.list(),n=Ti(e).pcb_plated_hole.list(),o=Ti(e).pcb_via.list();if(A.length===0&&t.length===0&&i.length===0&&n.length===0&&o.length===0)return null;const s=[...i,...n,...o,...t],r=uL(s);let a=r.minX,g=r.maxX,c=r.minY,I=r.maxY;for(const u of A)if(u.position){const d=u.position.x,f=u.position.y;a=Math.min(a,d),g=Math.max(g,d),c=Math.min(c,f),I=Math.max(I,f)}a===1/0&&(a=-10,g=10,c=-10,I=10);const l=2,B=Math.max(Math.abs(a),Math.abs(g))+l,C=Math.max(Math.abs(c),Math.abs(I))+l,Q=Math.max(2*B,10),h=Math.max(2*C,10);return{type:"pcb_board",pcb_board_id:"faux-board",center:{x:0,y:0},width:Q,height:h,thickness:1.4,material:"fr4",num_layers:2}}function Y7A(e){if(Ti(e).pcb_board.list().length>0)return e;const t=eke(e);if(!t)return e;const n=t.thickness/2;return[...e.map(s=>{if(s.type==="cad_component"){const r=s;if(r.position){const a=r.position.z??0;return{...r,position:{...r.position,z:a+n}}}}return s}),t]}var ike=V.forwardRef(({circuitJson:e,children:A,autoRotateDisabled:t,clickToInteractEnabled:i,onUserInteraction:n,onCameraControllerReady:o,resolveStaticAsset:s},r)=>{const a=d7A(A),g=V.useMemo(()=>Y7A(e??a),[e,a]),c=Q_e(g),I=V.useMemo(()=>{if(!g)return[5,-5,5];try{const u=Ti(g).pcb_board.list()[0];if(!u)return[5,-5,5];const{width:d,height:f}=u;if(!d&&!f)return[5,-5,5];const m=5,w=Math.max(d,m),D=Math.max(f,m),b=Math.max(w,D);return[b*.4,-b*.7,b*.9]}catch(u){return console.error(u),[5,-5,5]}},[g]),l=V.useMemo(()=>{if(!g)return!1;try{const u=Ti(g).pcb_board.list()[0];return!!u&&u.pcb_board_id==="faux-board"}catch{return!1}},[g]),B=V.useMemo(()=>{if(g)try{const u=Ti(g).pcb_board.list()[0];return u?{width:u.width??0,height:u.height??0}:void 0}catch(u){console.error(u);return}},[g]),C=V.useMemo(()=>{if(g)try{const u=Ti(g).pcb_board.list()[0];return!u||!u.center?void 0:{x:u.center.x,y:u.center.y}}catch(u){console.error(u);return}},[g]),Q=E6A(g),{stls:h}=Wxe(c),E=Ti(g).cad_component.list();return W.jsxs(u7A,{ref:r,autoRotateDisabled:t,initialCameraPosition:I,clickToInteractEnabled:i,boardDimensions:B,boardCenter:C,onUserInteraction:n,onCameraControllerReady:o,children:[h.map(({stlData:u,color:d,layerType:f},m)=>W.jsx(d_e,{stlData:u,color:d,opacity:m===0?l?.8:.95:1,layerType:f},`board-${m}`)),W.jsx(tke,{circuitJson:g,pcbThickness:Q,isFaux:l}),E.map(u=>W.jsx(D7A,{fallback:({error:d})=>W.jsx(w7A,{cad_component:u,error:d}),children:W.jsx(B7A,{cad_component:u,circuitJson:g,resolveStaticAsset:s},u.cad_component_id)},u.cad_component_id))]})}),nke=e=>{let A=0;for(let i=0;i<e.length;i++){const n=(i+1)%e.length;e[i]&&e[n]&&(A+=e[i][0]*e[n][1],A-=e[n][0]*e[i][1])}return A/2<=0};function oke(e,A,t,i,n){let o,s=null;if(t.outline&&t.outline.length>=3){let r=t.outline.map(g=>[g.x,g.y]);nke(r)&&(r=r.reverse());const a=A.ofPolygons([r]);n.push(a),s=a,o=e.extrude(a,i,void 0,void 0,void 0,!0),n.push(o)}else t.outline&&t.outline.length>0&&console.warn("Board outline has fewer than 3 points, falling back to rectangular board."),o=e.cube([t.width,t.height,i],!0),n.push(o),o=o.translate([t.center.x,t.center.y,0]),n.push(o);return{boardOp:o,outlineCrossSection:s}}var ske=64;function _0({Manifold:e,width:A,height:t,thickness:i,borderRadius:n}){const o=gG(A,t,n);if(o<=0)return e.cube([A,t,i],!0);const s=[],r=A-2*o,a=t-2*o;return r>0&&s.push(e.cube([r,t,i],!0)),a>0&&s.push(e.cube([A,a,i],!0)),[[A/2-o,t/2-o],[-A/2+o,t/2-o],[-A/2+o,-t/2+o],[A/2-o,-t/2+o]].forEach(([c,I])=>{s.push(e.cylinder(i,o,o,ske,!0).translate([c,I,0]))}),e.union(s)}var rke=e=>{let A=0;for(let i=0;i<e.length;i++){const n=(i+1)%e.length;e[i]&&e[n]&&(A+=e[i][0]*e[n][1],A-=e[n][0]*e[i][1])}return A/2<=0};function ake(e,A,t,i,n){const o=[],s=Ti(t).pcb_cutout.list();for(const r of s){let a;const g=i*1.5;switch(r.shape){case"rect":{const l=Ty(r);if(typeof l=="number"&&l>0?a=_0({Manifold:e,width:r.width,height:r.height,thickness:g,borderRadius:l}):a=e.cube([r.width,r.height,g],!0),n.push(a),r.rotation){const B=a.rotate([0,0,r.rotation]);n.push(B),a=B}a=a.translate([r.center.x,r.center.y,0]),n.push(a);break}case"circle":a=e.cylinder(g,r.radius,-1,jB,!0),n.push(a),a=a.translate([r.center.x,r.center.y,0]),n.push(a);break;case"polygon":if(r.points.length<3){console.warn(`PCB Cutout [${r.pcb_cutout_id}] polygon has fewer than 3 points, skipping.`);continue}let c=r.points.map(l=>[l.x,l.y]);rke(c)&&(c=c.reverse());const I=A.ofPolygons([c]);n.push(I),a=e.extrude(I,g,0,0,[1,1],!0),n.push(a);break;default:console.warn(`Unsupported cutout shape: ${r.shape} for cutout ${r.pcb_cutout_id}`);continue}a&&o.push(a)}return{cutoutOps:o}}function J7A({Manifold:e,x:A,y:t,diameter:i,thickness:n,segments:o=32}){return e.cylinder(n*1.2,i/2,i/2,o,!0).translate([A,t,0])}function T7A({Manifold:e,x:A,y:t,holeDiameter:i,thickness:n,zOffset:o=.001,segments:s=32}){const r=i/2+o;return e.cylinder(n*1.2,r,r,s,!0).translate([A,t,0])}function gke(e,A,t,i,n){const o=[],s=Ti(t).pcb_hole.list(),r=(g,c,I)=>{const l=_0({Manifold:e,width:g,height:c,thickness:I,borderRadius:Math.min(g,c)/2});return n.push(l),l},a=(g,c,I)=>{const l=[];for(let B=0;B<I;B++){const C=2*Math.PI*B/I;l.push([g/2*Math.cos(C),c/2*Math.sin(C)])}return l};return s.forEach(g=>{const c=g.hole_shape,I=g.x,l=g.y,B=i*1.2,C=g.ccw_rotation??g.rotation??0,Q=g.hole_width??g.hole_diameter,h=g.hole_height??g.hole_diameter;let E=null;if(c==="circle"){E=J7A({Manifold:e,x:I,y:l,diameter:g.hole_diameter,thickness:i,segments:jB}),o.push(E),n.push(E);return}if(c==="pill"||c==="rotated_pill")E=r(Q,h,B);else if(c==="oval"){let u=a(Q,h,jB),d=0;for(let m=0;m<u.length;m++){const w=(m+1)%u.length;d+=u[m][0]*u[w][1],d-=u[w][0]*u[m][1]}d<=0&&(u=u.reverse());const f=A.ofPolygons([u]);n.push(f),E=e.extrude(f,B,0,0,[1,1],!0),n.push(E)}if(E){if(C!==0){const d=E.rotate([0,0,C]);n.push(d),E=d}const u=E.translate([I,l,0]);n.push(u),o.push(u)}}),{nonPlatedHoleBoardDrills:o}}function mD(e){const A=new Sg;if(A.setAttribute("position",new To(e.vertProperties,3)),A.setIndex(new hrA(e.triVerts,1)),e.runIndex&&e.runIndex.length>1&&e.runOriginalID)for(let t=0;t<e.runIndex.length-1;t++){const i=e.runIndex[t],n=e.runIndex[t+1]-i;A.addGroup(i,n,0)}else A.addGroup(0,e.triVerts.length,0);return A}var WH=e=>{let A=0;for(let i=0;i<e.length;i++){const n=(i+1)%e.length;e[i]&&e[n]&&(A+=e[i][0]*e[n][1],A-=e[n][0]*e[i][1])}return A/2<=0},oZ=(e,A,t)=>{const i=[];for(let n=0;n<t;n++){const o=2*Math.PI*n/t;i.push([e/2*Math.cos(o),A/2*Math.sin(o)])}return i},IG=new Oi(...pr.copper),sZ=.05,rZ=.003,Ky=5e-4,aZ=.004;function cke(e,A,t,i,n,o){const s=[],r=Ti(t).pcb_plated_hole.list(),a=[],g=[],c=(C,Q,h)=>{const E=_0({Manifold:e,width:C,height:Q,thickness:h,borderRadius:Math.min(C,Q)/2});return n.push(E),E},I=({padOutline:C,thickness:Q})=>{if(!Array.isArray(C)||C.length<3)return null;let h=C.map(d=>[d.x,d.y]);WH(h)&&(h=h.reverse());const E=A.ofPolygons([h]);n.push(E);const u=e.extrude(E,Q,0,0,[1,1],!0);return n.push(u),u},l=({ph:C,depth:Q,sizeDelta:h=0})=>{if(C.shape!=="hole_with_polygon_pad")return null;const u=C.pad_outline;if(!Array.isArray(u)||u.length<3)return null;const d=C.hole_shape||"circle",f=C.hole_offset_x||0,m=C.hole_offset_y||0;let w=null;if(d==="circle"){const D=Math.max((C.hole_diameter??0)+h,Un),b=Math.max(D/2,Un/2);w=e.cylinder(Q,b,b,jB,!0),n.push(w)}else{const D=C.hole_width??C.hole_diameter,b=C.hole_height??C.hole_diameter;if(!D||!b)return null;const k=Math.max(D+h,Un),x=Math.max(b+h,Un);if(d==="oval"){let v=oZ(k,x,jB);WH(v)&&(v=v.reverse());const R=A.ofPolygons([v]);n.push(R),w=e.extrude(R,Q,0,0,[1,1],!0),n.push(w)}else(d==="pill"||d==="rotated_pill")&&(w=_0({Manifold:e,width:k,height:x,thickness:Q,borderRadius:Math.min(k,x)/2}),n.push(w))}if(!w)return null;if(f||m){const D=w.translate([f,m,0]);n.push(D),w=D}return w};r.forEach((C,Q)=>{if(C.shape==="circle"){const h=T7A({Manifold:e,x:C.x,y:C.y,holeDiameter:C.hole_diameter*1.02,thickness:i,zOffset:Bf,segments:jB});n.push(h),s.push(h);const E=i+2*Bf,u=e.cylinder(E,C.outer_diameter/2,C.outer_diameter/2,jB,!0);n.push(u);const d=e.cylinder(E*1.05,C.hole_diameter/2,C.hole_diameter/2,jB,!0);n.push(d);const f=u.subtract(d);n.push(f);const m=f.translate([C.x,C.y,0]);n.push(m);let w=m;if(o){const b=e.intersection([m,o]);n.push(b),w=b}g.push(w);const D=mD(w.getMesh());a.push({key:`ph-${C.pcb_plated_hole_id||Q}`,geometry:D,color:IG})}else if(C.shape==="pill"){const h=C.hole_width,E=C.hole_height,u=.4,d=C.outer_width??h+u,f=C.outer_height??E+u,m=h+2*Bf,w=E+2*Bf,D=i*1.2;let b=c(m,w,D);if(C.ccw_rotation){const Z=b.rotate([0,0,C.ccw_rotation]);n.push(Z),b=Z}const k=b.translate([C.x,C.y,0]);n.push(k),s.push(k);const x=i+2*Bf,v=c(d,f,x),R=c(h,E,x*1.05);let U=v.subtract(R);if(n.push(U),C.ccw_rotation){const Z=U.rotate([0,0,C.ccw_rotation]);n.push(Z),U=Z}const J=U.translate([C.x,C.y,0]);n.push(J);let H=J;if(o){const Z=e.intersection([J,o]);n.push(Z),H=Z}g.push(H);const O=mD(H.getMesh());a.push({key:`ph-${C.pcb_plated_hole_id||Q}`,geometry:O,color:IG})}else if(C.shape==="pill_hole_with_rect_pad"){if(C.hole_shape&&C.hole_shape!=="pill"||C.pad_shape&&C.pad_shape!=="rect")return;const h=C.hole_width,E=C.hole_height,u=C.hole_offset_x||0,d=C.hole_offset_y||0,f=C.rect_pad_width,m=C.rect_pad_height,w=Ty(C),D=rZ,b=h+2*Bf,k=E+2*Bf,x=i*1.2,R=c(b,k,x).translate([u,d,0]).translate([C.x,C.y,0]);n.push(R),s.push(R);const U=_0({Manifold:e,width:f,height:m,thickness:Math.max(i-2*(D+Ky+aZ),Un),borderRadius:w});n.push(U);const J=_0({Manifold:e,width:f,height:m,thickness:D,borderRadius:w}).translate([0,0,i/2+Ky+D/2]),H=_0({Manifold:e,width:f,height:m,thickness:D,borderRadius:w}).translate([0,0,-i/2-Ky-D/2]);n.push(J,H);const O=c(h,E,i*.8).translate([u,d,0]);n.push(O);const Z=e.union([U,J,H,O]);n.push(Z);const X=c(Math.max(h-2*sZ,.01),Math.max(E-2*sZ,.01),i*1.2).translate([u,d,0]);n.push(X);const iA=Z.subtract(X);n.push(iA);const aA=iA.translate([C.x,C.y,0]);n.push(aA);let tA=aA;if(o){const sA=e.intersection([aA,o]);n.push(sA),tA=sA}g.push(tA);const eA=mD(tA.getMesh());a.push({key:`ph-${C.pcb_plated_hole_id||Q}`,geometry:eA,color:IG})}else if(C.shape==="rotated_pill_hole_with_rect_pad"){if(C.hole_shape&&C.hole_shape!=="rotated_pill"||C.pad_shape&&C.pad_shape!=="rect")return;const h=C.hole_width,E=C.hole_height,u=C.hole_offset_x||0,d=C.hole_offset_y||0,f=C.rect_pad_width,m=C.rect_pad_height,w=Ty(C),D=rZ,b=h+2*Bf,k=E+2*Bf,x=i*1.2;let v=c(b,k,x).translate([u,d,0]);if(C.hole_ccw_rotation){const sA=v.rotate([0,0,C.hole_ccw_rotation]);n.push(sA),v=sA}const R=v.translate([C.x,C.y,0]);n.push(R),s.push(R);let U=_0({Manifold:e,width:f,height:m,thickness:Math.max(i-2*(D+Ky+aZ),Un),borderRadius:w});if(n.push(U),C.rect_ccw_rotation){const sA=U.rotate([0,0,C.rect_ccw_rotation]);n.push(sA),U=sA}let J=_0({Manifold:e,width:f,height:m,thickness:D,borderRadius:w}).translate([0,0,i/2+Ky+D/2]);if(C.rect_ccw_rotation){const sA=J.rotate([0,0,C.rect_ccw_rotation]);n.push(sA),J=sA}let H=_0({Manifold:e,width:f,height:m,thickness:D,borderRadius:w}).translate([0,0,-i/2-Ky-D/2]);if(C.rect_ccw_rotation){const sA=H.rotate([0,0,C.rect_ccw_rotation]);n.push(sA),H=sA}n.push(J,H);let O=c(h,E,i*.8).translate([u,d,0]);if(C.hole_ccw_rotation){const sA=O.rotate([0,0,C.hole_ccw_rotation]);n.push(sA),O=sA}n.push(O);const Z=e.union([U,J,H,O]);n.push(Z);let X=c(Math.max(h-2*sZ,.01),Math.max(E-2*sZ,.01),i*1.2).translate([u,d,0]);if(C.hole_ccw_rotation){const sA=X.rotate([0,0,C.hole_ccw_rotation]);n.push(sA),X=sA}n.push(X);const iA=Z.subtract(X);n.push(iA);const aA=iA.translate([C.x,C.y,0]);n.push(aA);let tA=aA;if(o){const sA=e.intersection([aA,o]);n.push(sA),tA=sA}g.push(tA);const eA=mD(tA.getMesh());a.push({key:`ph-${C.pcb_plated_hole_id||Q}`,geometry:eA,color:IG})}else if(C.shape==="hole_with_polygon_pad"){const h=C.pad_outline;if(!Array.isArray(h)||h.length<3)return;const E=l({ph:C,depth:i*1.2,sizeDelta:2*Un});if(!E)return;const u=E.translate([C.x,C.y,0]);n.push(u),s.push(u);const d=rZ,f=Math.max(i-2*(d+Ky+aZ),Un),m=I({padOutline:h,thickness:f}),w=I({padOutline:h,thickness:d}),D=I({padOutline:h,thickness:d});if(!m||!w||!D)return;const b=w.translate([0,0,i/2+Ky+d/2]),k=D.translate([0,0,-i/2-Ky-d/2]);n.push(b,k);const x=l({ph:C,depth:i*1.02});if(!x)return;const v=l({ph:C,depth:i*.8,sizeDelta:-2*Un})||x,R=e.union([m,b,k,x]);n.push(R);const U=R.subtract(v);n.push(U);const J=U.translate([C.x,C.y,0]);n.push(J);let H=J;if(o){const Z=e.intersection([J,o]);n.push(Z),H=Z}g.push(H);const O=mD(H.getMesh());a.push({key:`ph-${C.pcb_plated_hole_id||Q}`,geometry:O,color:IG})}else if(C.shape==="oval"){const h=C.hole_width,E=C.hole_height,u=C.outer_width??h+.4,d=C.outer_height??E+.4,f=h+2*Bf,m=E+2*Bf,w=i*1.2;let D=oZ(f,m,jB);WH(D)&&(D=D.reverse());const b=A.ofPolygons([D]);n.push(b);let k=e.extrude(b,w,0,0,[1,1],!0);if(n.push(k),C.ccw_rotation){const eA=k.rotate([0,0,C.ccw_rotation]);n.push(eA),k=eA}const x=k.translate([C.x,C.y,0]);n.push(x),s.push(x);const v=i+2*Bf;let R=oZ(u,d,jB);WH(R)&&(R=R.reverse());const U=A.ofPolygons([R]);n.push(U);const J=e.extrude(U,v,0,0,[1,1],!0);n.push(J);let H=oZ(h,E,jB);WH(H)&&(H=H.reverse());const O=A.ofPolygons([H]);n.push(O);const Z=e.extrude(O,v*1.05,0,0,[1,1],!0);n.push(Z);let X=J.subtract(Z);if(n.push(X),C.ccw_rotation){const eA=X.rotate([0,0,C.ccw_rotation]);n.push(eA),X=eA}const iA=X.translate([C.x,C.y,0]);n.push(iA);let aA=iA;if(o){const eA=e.intersection([iA,o]);n.push(eA),aA=eA}g.push(aA);const tA=mD(aA.getMesh());a.push({key:`ph-${C.pcb_plated_hole_id||Q}`,geometry:tA,color:IG})}else if(C.shape==="circular_hole_with_rect_pad"){if(C.hole_shape&&C.hole_shape!=="circle"||C.pad_shape&&C.pad_shape!=="rect")return;const h=C.hole_offset_x||0,E=C.hole_offset_y||0,u=J7A({Manifold:e,x:C.x+h,y:C.y+E,diameter:C.hole_diameter,thickness:i,segments:jB});n.push(u),s.push(u);const d=C.rect_pad_width??C.hole_diameter,f=C.rect_pad_height??C.hole_diameter,m=Ty(C),w=rZ,D=C.hole_diameter/2,b=_0({Manifold:e,width:d,height:f,thickness:Math.max(i-2*(w+Ky+aZ),Un),borderRadius:m});n.push(b);const k=_0({Manifold:e,width:d,height:f,thickness:w,borderRadius:m}).translate([0,0,i/2+Ky+w/2]),x=_0({Manifold:e,width:d,height:f,thickness:w,borderRadius:m}).translate([0,0,-i/2-Ky-w/2]);n.push(k,x);const v=e.cylinder(i*.8,D,D,jB,!0).translate([h,E,0]);n.push(v);const R=e.union([b,k,x,v]);n.push(R);const U=e.cylinder(i*1.2,Math.max(D-Un,.01),Math.max(D-Un,.01),jB,!0).translate([h,E,0]);n.push(U);const J=R.subtract(U);n.push(J);const H=J.translate([C.x,C.y,0]);n.push(H);let O=H;if(o){const X=e.intersection([H,o]);n.push(X),O=X}g.push(O);const Z=mD(O.getMesh());a.push({key:`ph-${C.pcb_plated_hole_id||Q}`,geometry:Z,color:IG})}});let B;return g.length>0&&(B=e.union(g),n.push(B)),{platedHoleBoardDrills:s,platedHoleCopperGeoms:a,platedHoleSubtractOp:B}}function Ike({Manifold:e,x:A,y:t,outerDiameter:i,holeDiameter:n,thickness:o,zOffset:s=.001,segments:r=32}){const a=s,g=s;if(i<n)throw new Error(`Invalid via geometry: outerDiameter (${i}) must be >= holeDiameter (${n})`);const c=Math.min(i/2,n/2+g),I=e.cylinder(o,c,-1,r,!0),l=e.cylinder(a,i/2,-1,r,!0).translate([0,0,o/2]),B=e.cylinder(a,i/2,-1,r,!0).translate([0,0,-o/2]),C=e.union([I,l,B]),Q=o+a*2,h=e.cylinder(Q,n/2,-1,r,!0);return C.subtract(h).translate([A,t,0])}var lke=new Oi(...pr.copper);function Bke(e,A,t,i,n){const o=[],s=Ti(A).pcb_via.list(),r=[];return s.forEach((a,g)=>{if(typeof a.hole_diameter=="number"){const c=T7A({Manifold:e,x:a.x,y:a.y,holeDiameter:a.hole_diameter,thickness:t,zOffset:Bf,segments:jB});i.push(c),o.push(c)}if(typeof a.outer_diameter=="number"&&typeof a.hole_diameter=="number"){const c=Ike({Manifold:e,x:a.x,y:a.y,outerDiameter:a.outer_diameter,holeDiameter:a.hole_diameter,thickness:t,zOffset:Bf,segments:jB});i.push(c);let I=c;if(n){const B=e.intersection([c,n]);i.push(B),I=B}const l=mD(I.getMesh());r.push({key:`via-${a.pcb_via_id||g}`,geometry:l,color:lke})}}),{viaBoardDrills:o,viaCopperGeoms:r}}var Cke=(e,A,t)=>{const[i,n]=V.useState(null),[o,s]=V.useState(null),[r,a]=V.useState(null),[g,c]=V.useState(!0),I=V.useRef([]),l=V.useMemo(()=>{const h=A.filter(d=>d.type==="pcb_panel"),E=Ti(A).pcb_board.list();if(h.length>0){const d=h[0],f=E.find(m=>m.pcb_panel_id===d.pcb_panel_id);return{type:"pcb_board",pcb_board_id:d.pcb_panel_id,center:d.center,width:d.width,height:d.height,thickness:f?.thickness??1.4,material:f?.material??"fr4",num_layers:f?.num_layers??2}}const u=E.filter(d=>!d.pcb_panel_id);return u.length>0?u[0]:null},[A]),B=V.useMemo(()=>{const h=Ti(A).pcb_board.list();return h.length>0&&h[0].pcb_board_id==="faux-board"},[A]),C=V.useMemo(()=>l?H7A(l,yN):yN,[l]);V.useEffect(()=>{if(!e||!l){n(null),s(null),c(!1);return}if((l.width===0||!l.width)&&(l.height===0||!l.height)&&(!l.outline||l.outline.length<3)){n({platedHoles:[],vias:[]}),s(l.thickness??0),c(!1);return}c(!0),a(null);const h=e.Manifold,E=e.CrossSection,u=m=>{if(!(!m||typeof m.delete!="function"))try{m.delete()}catch(w){(!(w instanceof Error)||!w.message?.includes("Manifold instance already deleted"))&&console.warn("Failed to delete Manifold instance",w)}};I.current.forEach(u),I.current=[];let d=null;const f={};try{const m=l.thickness||1.4;s(m);const{boardOp:w,outlineCrossSection:D}=oke(h,E,l,m,I.current);let b=w;const x=m+2*1;let v=null;const R=.01;if(D){let eA=D;if(R>0){const IA=D.offset(R);I.current.push(IA),eA=IA}const sA=h.extrude(eA,x,void 0,void 0,void 0,!0);I.current.push(sA),v=sA}else{const eA=(l.width||0)+2*R,sA=(l.height||0)+2*R,IA=h.cube([eA,sA,x],!0);I.current.push(IA);const uA=IA.translate([l.center.x,l.center.y,0]);I.current.push(uA),v=uA}const U=[];let J=null;const{nonPlatedHoleBoardDrills:H}=gke(h,E,A,m,I.current);U.push(...H);const{platedHoleBoardDrills:O,platedHoleCopperGeoms:Z,platedHoleSubtractOp:X}=cke(h,E,A,m,I.current,v);U.push(...O),f.platedHoles=Z;const{viaBoardDrills:iA,viaCopperGeoms:aA}=Bke(h,A,m,I.current,v);if(U.push(...iA),f.vias=aA,U.length>0){J=h.union(U),I.current.push(J);const eA=X?h.union([J,X]):J;I.current.push(eA);const sA=b.subtract(eA);if(I.current.push(sA),b=sA,X){const IA=X.subtract(J);I.current.push(IA);const uA=IA.getMesh(),xA=mD(uA);f.platedHoles=[{key:"plated-holes-union",geometry:xA,color:new Oi(pr.copper[0],pr.copper[1],pr.copper[2])}]}}const{cutoutOps:tA}=ake(h,E,A,m,I.current);if(tA.length>0){const eA=h.union(tA);I.current.push(eA);const sA=b.subtract(eA);I.current.push(sA),b=sA}if(d=b,d){const eA=d.getMesh(),sA=mD(eA),IA=HEA[l.material]??pr.fr4Tan;f.board={geometry:sA,color:new Oi(IA[0],IA[1],IA[2]),material:l.material,isFaux:B}}n(f)}catch(m){console.error("Error processing geometry with Manifold in hook:",m),a(m.message||"An unknown error occurred while processing geometry in hook."),n(null)}finally{c(!1)}return()=>{I.current.forEach(u),I.current=[]}},[e,A,l]);const Q=V.useMemo(()=>!l||!C?null:L7A({circuitJson:A,boardData:l,traceTextureResolution:C,visibility:t}),[A,l,C,t]);return{geoms:i,textures:Q,pcbThickness:o,error:r,isLoading:g,boardData:l,isFauxBoard:B}},Qke=ZB,hke=({material:e,color:A,side:t=Qke,isFaux:i=!1})=>e==="fr4"?new nw({color:A,side:t,metalness:0,roughness:.8,specularIntensity:.2,ior:1.45,sheen:0,clearcoat:0,transparent:i,opacity:i?XW:1,flatShading:!0,polygonOffset:!0,polygonOffsetFactor:1,polygonOffsetUnits:1}):new kE({color:A,side:t,flatShading:!0,metalness:.1,roughness:.8,transparent:!0,opacity:i?XW:.9,polygonOffset:!0,polygonOffsetFactor:1,polygonOffsetUnits:1});function Eke(e){const A=[];if(!e)return A;if(e.board&&e.board.geometry){const i=new eo(e.board.geometry,hke({material:e.board.material,color:e.board.color,side:ZB,isFaux:e.board.isFaux}));i.name="board-geom",A.push(i)}const t=i=>{i&&i.forEach(n=>{const o=new eo(n.geometry,new kE({color:n.color,side:ZB,flatShading:!0}));o.name=n.key,A.push(o)})};return t(e.platedHoles),t(e.vias),A}var uke=({geometryMeshes:e,textureMeshes:A})=>{const{rootObject:t}=Yu(),{visibility:i}=aG(),n=o=>{o.geometry.dispose();const s=Array.isArray(o.material)?o.material:[o.material];for(const r of s){if(!r)continue;const a=["map","alphaMap","aoMap","bumpMap","displacementMap","emissiveMap","lightMap","metalnessMap","normalMap","roughnessMap","specularMap"],g=r;for(const c of a){const I=g[c];I&&I instanceof qc&&(I.dispose(),g[c]=null)}r.dispose()}};return V.useEffect(()=>{if(t)return e.forEach(o=>{let s=!0;o.name==="board-geom"?s=i.boardBody:(o.name.includes("plated_hole")||o.name.includes("via"))&&(s=i.topCopper||i.bottomCopper),s&&t.add(o)}),A.forEach(o=>{t.add(o)}),()=>{e.forEach(o=>{o.parent===t&&t.remove(o)}),A.forEach(o=>{o.parent===t&&t.remove(o),n(o)})}},[t,e,A,i]),null},dke="https://cdn.jsdelivr.net/npm/manifold-3d@3.2.1",pke=({circuitJson:e,autoRotateDisabled:A,clickToInteractEnabled:t,onUserInteraction:i,children:n,onCameraControllerReady:o,resolveStaticAsset:s})=>{const r=d7A(n),a=V.useMemo(()=>Y7A(e??r),[e,r]),[g,c]=V.useState(null),[I,l]=V.useState(null),{visibility:B}=aG();V.useEffect(()=>{if(window.ManifoldModule&&typeof window.ManifoldModule=="object"&&window.ManifoldModule.setup){c(window.ManifoldModule);return}const v=async Z=>{try{const X=await Z();X.setup(),window.ManifoldModule=X,c(X)}catch(X){console.error("Failed to initialize Manifold:",X),l(`Failed to initialize Manifold: ${X instanceof Error?X.message:"Unknown error"}`)}},R=window.ManifoldModule??window.MANIFOLD??window.MANIFOLD_MODULE;if(R){window.ManifoldModule=R,v(window.ManifoldModule);return}const U="manifoldLoaded",J=()=>{const Z=window.ManifoldModule??window.MANIFOLD??window.MANIFOLD_MODULE;if(Z)window.ManifoldModule=Z,v(window.ManifoldModule);else{const X="ManifoldModule not found on window after script load.";console.error(X),l(X)}};window.addEventListener(U,J,{once:!0});const H=document.createElement("script");H.type="module",H.innerHTML=`
|
|
5179
|
+
at `+s}return A},eZ.buildMessage=function(e,A){var t={literal:function(g){return'"'+n(g.text)+'"'},class:function(g){var c=g.parts.map(function(I){return Array.isArray(I)?o(I[0])+"-"+o(I[1]):o(I)});return"["+(g.inverted?"^":"")+c.join("")+"]"},any:function(){return"any character"},end:function(){return"end of input"},other:function(g){return g.description}};function i(g){return g.charCodeAt(0).toString(16).toUpperCase()}function n(g){return g.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,function(c){return"\\x0"+i(c)}).replace(/[\x10-\x1F\x7F-\x9F]/g,function(c){return"\\x"+i(c)})}function o(g){return g.replace(/\\/g,"\\\\").replace(/\]/g,"\\]").replace(/\^/g,"\\^").replace(/-/g,"\\-").replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,function(c){return"\\x0"+i(c)}).replace(/[\x10-\x1F\x7F-\x9F]/g,function(c){return"\\x"+i(c)})}function s(g){return t[g.type](g)}function r(g){var c=g.map(s),I,l;if(c.sort(),c.length>0){for(I=1,l=1;I<c.length;I++)c[I-1]!==c[I]&&(c[l]=c[I],l++);c.length=l}switch(c.length){case 1:return c[0];case 2:return c[0]+" or "+c[1];default:return c.slice(0,-1).join(", ")+", or "+c[c.length-1]}}function a(g){return g?'"'+n(g)+'"':"end of input"}return"Expected "+r(e)+" but "+a(A)+" found."};var w_e=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(let o=1;o<e.length;o++){const s=e[o];s.x<A&&(A=s.x),s.y<t&&(t=s.y),s.x>i&&(i=s.x),s.y>n&&(n=s.y)}return{minX:A,minY:t,maxX:i,maxY:n}};function yD(e){if(e.outline&&e.outline.length>=3){const s=w_e(e.outline);return{...s,width:s.maxX-s.minX,height:s.maxY-s.minY,centerX:(s.minX+s.maxX)/2,centerY:(s.minY+s.maxY)/2}}const A=e.width??0,t=e.height??0,i=e.center?.x??0,n=e.center?.y??0;return{...{minX:i-A/2,maxX:i+A/2,minY:n-t/2,maxY:n+t/2},width:A,height:t,centerX:i,centerY:n}}function iZ(e,A){if(e===void 0)return A;if(typeof e=="number")return e;const t=parseFloat(e.replace(/mm$/,""));return isNaN(t)?A:t}function D_e(e){return e.layer==="bottom"?e.is_mirrored!==!1:e.is_mirrored===!0}function S_e(e){const A=e.flat();if(A.length===0)return{minX:0,maxX:0,minY:0,maxY:0,width:0,height:0,centerX:0,centerY:0};const t=Math.min(...A.map(s=>s[0])),i=Math.max(...A.map(s=>s[0])),n=Math.min(...A.map(s=>s[1])),o=Math.max(...A.map(s=>s[1]));return{minX:t,maxX:i,minY:n,maxY:o,width:i-t,height:o-n,centerX:(t+i)/2,centerY:(n+o)/2}}function b_e(e){const A=[];return e.forEach(t=>{t.length===29?(A.push(t.slice(0,15)),A.push(t.slice(14,29))):t.length===17?(A.push(t.slice(0,10)),A.push(t.slice(9,17))):A.push(t)}),A}function x_e(e,A){let t=-e.centerX,i=-e.centerY;return A.includes("left")?t=-e.minX:A.includes("right")&&(t=-e.maxX),A.includes("top")?i=-e.maxY:A.includes("bottom")&&(i=-e.minY),{x:t,y:i}}function __e(e,A){const t=[];let i=e.ccw_rotation??0;if(D_e(e)&&(t.push(G_(A.centerX,A.centerY),{a:-1,b:0,c:0,d:1,e:0,f:0},G_(-A.centerX,-A.centerY)),i=-i),i){const s=i*Math.PI/180;t.push(G_(A.centerX,A.centerY),_7A(s),G_(-A.centerX,-A.centerY))}return{matrix:t.length>0?x7A(...t):void 0,rotationDeg:i}}function k7A(e,A,t,i,n,o,s){A.forEach(r=>{e.beginPath(),r.forEach((a,g)=>{let c={x:a[0],y:a[1]};t&&(c=S7A(t,c));const I=c.x+i.x+n.x,l=c.y+i.y+n.y,B=o(I),C=s(l);g===0?e.moveTo(B,C):e.lineTo(B,C)}),e.stroke()})}function k_e(e,A,t,i,n,o){e.save(),e.translate(A,t),e.rotate(-o),e.fillRect(-i/2,-n/2,i,n),e.restore()}function F_e(e,A,t,i,n,o,s,r,a,g){const c=typeof A.font_size=="number"?A.font_size:.2,I={left:iZ(A.knockout_padding?.left,c*.5),right:iZ(A.knockout_padding?.right,c*.5),top:iZ(A.knockout_padding?.top,c*.3),bottom:iZ(A.knockout_padding?.bottom,c*.3)},l=i.width+I.left+I.right,B=i.height+I.top+I.bottom,C=s(A.anchor_position.x),Q=r(A.anchor_position.y),h=l*a,E=B*a;e.fillStyle=g;const u=o*Math.PI/180;k_e(e,C,Q,h,E,u);const d={x:-i.centerX,y:-i.centerY};e.globalCompositeOperation="destination-out",k7A(e,t,n,d,A.anchor_position,s,r),e.globalCompositeOperation="source-over"}function G_e({layer:e,circuitJson:A,boardData:t,copperColor:i="rgb(230, 153, 51)",traceTextureResolution:n}){const s=A.filter(Q=>Q.type==="pcb_copper_text").filter(Q=>Q.layer===e);if(s.length===0)return null;const r=yD(t),a=document.createElement("canvas"),g=Math.floor(r.width*n),c=Math.floor(r.height*n);a.width=g,a.height=c;const I=a.getContext("2d");if(!I)return null;e==="bottom"&&(I.translate(0,c),I.scale(1,-1)),I.strokeStyle=i,I.fillStyle=i;const l=Q=>(Q-r.minX)*n,B=Q=>(r.maxY-Q)*n;s.forEach(Q=>{const h=typeof Q.font_size=="number"?Q.font_size:.2,E=Math.max(.02,h*.08)*n;I.lineWidth=E,I.lineCap="round",I.lineJoin="round";const u=(0,p_e.vectorText)({height:h*.45,input:Q.text}),d=b_e(u),f=S_e(d),{matrix:m,rotationDeg:w}=__e(Q,f);if(Q.is_knockout)F_e(I,Q,d,f,m,w,l,B,n,i);else{const D=Q.anchor_alignment||"center",b=x_e(f,D);k7A(I,d,m,b,Q.anchor_position,l,B)}});const C=new E_(a);return C.generateMipmaps=!0,C.minFilter=xE,C.magFilter=mI,C.anisotropy=16,C.needsUpdate=!0,C}function M_e({layer:e,circuitJson:A,boardData:t,copperColor:i,traceTextureResolution:n}){const s=Ti(A).pcb_smtpad.list().filter(Q=>Q.layer===e);if(s.length===0)return null;const r=yD(t),a=document.createElement("canvas"),g=Math.floor(r.width*n),c=Math.floor(r.height*n);a.width=g,a.height=c;const I=a.getContext("2d");if(!I)return null;e==="bottom"&&(I.translate(0,c),I.scale(1,-1));const l=Q=>(Q-r.minX)*n,B=Q=>(r.maxY-Q)*n;I.fillStyle=i,s.forEach(Q=>{if(Q.shape==="polygon"&&Q.points){I.beginPath(),Q.points.forEach((f,m)=>{const w=l(f.x),D=B(f.y);m===0?I.moveTo(w,D):I.lineTo(w,D)}),I.closePath(),I.fill();return}if(Q.x===void 0||Q.y===void 0)return;const h=Q.x,E=Q.y,u=l(h),d=B(E);if(Q.shape==="rect"){const f=Q.width*n,m=Q.height*n,w=Ty(Q),D=gG(Q.width,Q.height,w)*n;D>0?(I.beginPath(),I.roundRect(u-f/2,d-m/2,f,m,D),I.fill()):I.fillRect(u-f/2,d-m/2,f,m)}else if(Q.shape==="circle"){const f=(Q.radius??Q.width/2)*n;I.beginPath(),I.arc(u,d,f,0,2*Math.PI),I.fill()}else if(Q.shape==="pill"||Q.shape==="rotated_pill"){const f=Q.width*n,m=Q.height*n,w=Math.min(f,m)/2,b=-(Q.ccw_rotation||0)*(Math.PI/180);b?(I.save(),I.translate(u,d),I.rotate(b),I.beginPath(),I.roundRect(-f/2,-m/2,f,m,w),I.fill(),I.restore()):(I.beginPath(),I.roundRect(u-f/2,d-m/2,f,m,w),I.fill())}else if(Q.shape==="rotated_rect"){const f=Q.width*n,m=Q.height*n,w=Ty(Q),D=gG(Q.width,Q.height,w)*n,k=-(Q.ccw_rotation||0)*(Math.PI/180);I.save(),I.translate(u,d),I.rotate(k),I.beginPath(),I.roundRect(-f/2,-m/2,f,m,D),I.fill(),I.restore()}});const C=new E_(a);return C.generateMipmaps=!0,C.minFilter=xE,C.magFilter=mI,C.anisotropy=16,C.needsUpdate=!0,C}function R_e({layer:e,circuitJson:A,panelData:t,outlineColor:i="black",traceTextureResolution:n}){const o=Ti(A).pcb_board.list().filter(B=>B.pcb_panel_id===t.pcb_board_id);if(o.length===0)return null;const s=document.createElement("canvas"),r=Math.floor(t.width*n),a=Math.floor(t.height*n);s.width=r,s.height=a;const g=s.getContext("2d");if(!g)return null;e==="bottom"&&(g.translate(0,a),g.scale(1,-1)),g.strokeStyle=i,g.lineWidth=.05*n;const c=B=>(B-t.center.x+t.width/2)*n,I=B=>(-(B-t.center.y)+t.height/2)*n;o.forEach(B=>{if(B.outline&&B.outline.length>=2)g.beginPath(),B.outline.forEach((C,Q)=>{const h=c(C.x),E=I(C.y);Q===0?g.moveTo(h,E):g.lineTo(h,E)}),g.closePath(),g.stroke();else{const C=B.width,Q=B.height,{x:h,y:E}=B.center,u=c(h-C/2),d=I(E+Q/2);g.strokeRect(u,d,C*n,Q*n)}});const l=new E_(s);return l.generateMipmaps=!0,l.minFilter=xE,l.magFilter=mI,l.anisotropy=16,l.needsUpdate=!0,l}var v_e=Kr(iEA()),F7A=25.4,N_e=F7A/1e3,L_e=/^\s*(-?\d*(?:\.\d+)?)(?:\s*(mm|mil|inch|in|"))?\s*$/i;function U_e(e){if(!e)return;const A=e.trim().toLowerCase();return A==='"'||A==="inch"?"in":A}function GQ(e){if(e==null)return;if(typeof e=="number")return Number.isFinite(e)?e:void 0;if(typeof e!="string")return;const A=e.trim();if(A.length===0)return;const t=A.match(L_e);if(!t){const r=Number.parseFloat(A);return Number.isFinite(r)?r:void 0}const[,i,n]=t,o=Number.parseFloat(i||"0");if(!Number.isFinite(o))return;switch(U_e(n)){case"mil":return o*N_e;case"in":return o*F7A;case"mm":case void 0:return o;default:return o}}function aw(e,A){const t=GQ(e);return t===void 0?A:t}function G7A(e){let A=e;if(A.startsWith("#")&&(A=A.slice(1)),A.length===6){const t=parseInt(A.slice(0,2),16),i=parseInt(A.slice(2,4),16),n=parseInt(A.slice(4,6),16);return`rgb(${t}, ${i}, ${n})`}return e.startsWith("rgb")?e:"rgb(255, 243, 204)"}function H_e({layer:e,circuitJson:A,boardData:t,silkscreenColor:i="rgb(255,255,255)",traceTextureResolution:n}){const o=Ti(A).pcb_silkscreen_text.list(),s=Ti(A).pcb_silkscreen_path.list(),r=Ti(A).pcb_silkscreen_line.list(),a=Ti(A).pcb_silkscreen_rect.list(),g=Ti(A).pcb_silkscreen_circle.list(),c=Ti(A).pcb_fabrication_note_rect.list(),I=Ti(A).pcb_note_line.list(),l=o.filter(v=>v.layer===e),B=s.filter(v=>v.layer===e),C=r.filter(v=>v.layer===e),Q=a.filter(v=>v.layer===e),h=g.filter(v=>v.layer===e),E=c.filter(v=>v.layer===e),u=I.filter(v=>v.layer===e);if(l.length===0&&B.length===0&&C.length===0&&Q.length===0&&h.length===0&&E.length===0&&u.length===0)return null;const d=yD(t),f=document.createElement("canvas"),m=Math.floor(d.width*n),w=Math.floor(d.height*n);f.width=m,f.height=w;const D=f.getContext("2d");if(!D)return null;e==="bottom"&&(D.translate(0,w),D.scale(1,-1)),D.strokeStyle=i,D.fillStyle=i;const b=v=>(v-d.minX)*n,k=v=>(d.maxY-v)*n;C.forEach(v=>{const R=GQ(v.x1)??0,U=GQ(v.y1)??0,J=GQ(v.x2)??0,H=GQ(v.y2)??0;R===J&&U===H||(D.beginPath(),D.lineWidth=aw(v.stroke_width,.1)*n,D.lineCap="round",D.moveTo(b(R),k(U)),D.lineTo(b(J),k(H)),D.stroke())}),u.forEach(v=>{const R=GQ(v.x1)??0,U=GQ(v.y1)??0,J=GQ(v.x2)??0,H=GQ(v.y2)??0;if(R===J&&U===H)return;D.save();let O=i;v.color?O=G7A(v.color):O="rgb(255, 243, 204)",D.strokeStyle=O,D.beginPath(),D.lineWidth=aw(v.stroke_width,.1)*n,D.lineCap="round";const Z=v.is_dashed??!1;if(Z){const X=Math.max(D.lineWidth*2,1);D.setLineDash([X,X])}D.moveTo(b(R),k(U)),D.lineTo(b(J),k(H)),D.stroke(),Z&&D.setLineDash([]),D.restore()}),B.forEach(v=>{v.route.length<2||(D.beginPath(),D.lineWidth=aw(v.stroke_width,.1)*n,D.lineCap="round",D.lineJoin="round",v.route.forEach((R,U)=>{const J=b(GQ(R.x)??0),H=k(GQ(R.y)??0);U===0?D.moveTo(J,H):D.lineTo(J,H)}),D.stroke())}),h.forEach(v=>{const R=aw(v.radius,0);if(R<=0)return;const U=aw(v.stroke_width,.12),J=U>0,H=GQ(v.center?.x)??0,O=GQ(v.center?.y)??0,Z=b(H),X=k(O),iA=R*n;if(D.save(),D.translate(Z,X),J){const aA=iA+U/2*n,tA=Math.max(0,iA-U/2*n);tA>0?(D.beginPath(),D.arc(0,0,aA,0,2*Math.PI),D.arc(0,0,tA,0,2*Math.PI,!0),D.fill("evenodd")):(D.beginPath(),D.arc(0,0,aA,0,2*Math.PI),D.fill())}else D.beginPath(),D.arc(0,0,iA,0,2*Math.PI),D.fill();D.restore()}),Q.forEach(v=>{const R=aw(v.width,0),U=aw(v.height,0);if(R<=0||U<=0)return;const J=GQ(v.center?.x)??0,H=GQ(v.center?.y)??0,O=b(J),Z=k(H),X=Ty(v),iA=typeof X=="string"?GQ(X):X,aA=gG(R,U,iA);D.save(),D.translate(O,Z);const tA=R/2*n,eA=U/2*n,sA=Math.min(aA*n,tA,eA),IA=v.stroke_width??!1,uA=v.is_filled??!0,xA=v.is_stroke_dashed??!1,kA=IA?aw(v.stroke_width,.1)*n:0;if(((QA,_A,pA,KA,WA)=>{if(D.beginPath(),WA<=0)D.rect(QA,_A,pA,KA);else{const st=WA,yA=QA+pA,jA=_A+KA;D.moveTo(QA+st,_A),D.lineTo(yA-st,_A),D.quadraticCurveTo(yA,_A,yA,_A+st),D.lineTo(yA,jA-st),D.quadraticCurveTo(yA,jA,yA-st,jA),D.lineTo(QA+st,jA),D.quadraticCurveTo(QA,jA,QA,jA-st),D.lineTo(QA,_A+st),D.quadraticCurveTo(QA,_A,QA+st,_A),D.closePath()}})(-tA,-eA,tA*2,eA*2,sA),uA&&D.fill(),IA&&kA>0){if(D.lineWidth=kA,xA){const QA=Math.max(kA*2,1);D.setLineDash([QA,QA])}D.stroke(),xA&&D.setLineDash([])}D.restore()}),E.forEach(v=>{const R=aw(v.width,0),U=aw(v.height,0);if(R<=0||U<=0)return;const J=GQ(v.center?.x)??0,H=GQ(v.center?.y)??0,O=b(J),Z=k(H),X=Ty(v),iA=typeof X=="string"?GQ(X):X,aA=gG(R,U,iA);D.save(),D.translate(O,Z);const tA=R/2*n,eA=U/2*n,sA=Math.min(aA*n,tA,eA),IA=v.has_stroke??!1,uA=v.is_filled??!0,xA=v.is_stroke_dashed??!1,kA=IA?aw(v.stroke_width,.1)*n:0;let YA=i,QA=i;if(v.color){const pA=G7A(v.color);YA=pA,QA=pA}else YA="rgb(255, 243, 204)",QA="rgb(255, 243, 204)";if(((pA,KA,WA,st,yA)=>{if(D.beginPath(),yA<=0)D.rect(pA,KA,WA,st);else{const jA=yA,PA=pA+WA,HA=KA+st;D.moveTo(pA+jA,KA),D.lineTo(PA-jA,KA),D.quadraticCurveTo(PA,KA,PA,KA+jA),D.lineTo(PA,HA-jA),D.quadraticCurveTo(PA,HA,PA-jA,HA),D.lineTo(pA+jA,HA),D.quadraticCurveTo(pA,HA,pA,HA-jA),D.lineTo(pA,KA+jA),D.quadraticCurveTo(pA,KA,pA+jA,KA),D.closePath()}})(-tA,-eA,tA*2,eA*2,sA),uA&&(D.fillStyle=YA,D.fill()),IA&&kA>0){if(D.strokeStyle=QA,D.lineWidth=kA,xA){const pA=Math.max(kA*2,1);D.setLineDash([pA,pA])}D.stroke(),xA&&D.setLineDash([])}D.restore()}),l.forEach(v=>{const R=v.font_size||.25,U=Math.min(Math.max(.01,R*.1),R*.05)*n;D.lineWidth=U,D.lineCap="butt",D.lineJoin="miter";const J=(0,v_e.vectorText)({height:R*.45,input:v.text}),H=[];J.forEach(xA=>{xA.length===29?(H.push(xA.slice(0,15)),H.push(xA.slice(14,29))):xA.length===17?(H.push(xA.slice(0,10)),H.push(xA.slice(9,17))):H.push(xA)});const O=H.flat(),Z={minX:O.length>0?Math.min(...O.map(xA=>xA[0])):0,maxX:O.length>0?Math.max(...O.map(xA=>xA[0])):0,minY:O.length>0?Math.min(...O.map(xA=>xA[1])):0,maxY:O.length>0?Math.max(...O.map(xA=>xA[1])):0},X=(Z.minX+Z.maxX)/2,iA=(Z.minY+Z.maxY)/2;let aA=-X,tA=-iA;const eA=v.anchor_alignment||"center";eA.includes("left")?aA=-Z.minX:eA.includes("right")&&(aA=-Z.maxX),eA.includes("top")?tA=-Z.maxY:eA.includes("bottom")&&(tA=-Z.minY);const sA=[];let IA=v.ccw_rotation??0;if(v.layer==="bottom"&&(sA.push(G_(X,iA),{a:-1,b:0,c:0,d:1,e:0,f:0},G_(-X,-iA)),IA=-IA),IA){const xA=IA*Math.PI/180;sA.push(G_(X,iA),_7A(xA),G_(-X,-iA))}const uA=sA.length>0?x7A(...sA):void 0;H.forEach(xA=>{D.beginPath(),xA.forEach((kA,YA)=>{let QA={x:kA[0],y:kA[1]};uA&&(QA=S7A(uA,QA));const _A=QA.x+aA+v.anchor_position.x,pA=QA.y+tA+v.anchor_position.y,KA=b(_A),WA=k(pA);YA===0?D.moveTo(KA,WA):D.lineTo(KA,WA)}),D.stroke()})});const x=new E_(f);return x.generateMipmaps=!0,x.minFilter=xE,x.magFilter=mI,x.anisotropy=16,x.needsUpdate=!0,x}function M7A(e){return e&&e.route_type==="wire"&&typeof e.layer=="string"&&typeof e.width=="number"}function Y_e({layer:e,circuitJson:A,boardData:t,traceColor:i,traceTextureResolution:n}){const o=Ti(A).pcb_trace.list(),s=Ti(A).pcb_via.list(),r=Ti(A).pcb_plated_hole.list(),a=o.filter(Q=>Q.route.some(h=>M7A(h)&&h.layer===e));if(a.length===0)return null;const g=yD(t),c=document.createElement("canvas"),I=Math.floor(g.width*n),l=Math.floor(g.height*n);c.width=I,c.height=l;const B=c.getContext("2d");if(!B)return null;e==="bottom"&&(B.translate(0,l),B.scale(1,-1)),a.forEach(Q=>{let h=!0;B.beginPath(),B.strokeStyle=i,B.lineCap="round",B.lineJoin="round";let E=0;for(const u of Q.route){if(!M7A(u)||u.layer!==e){h||B.stroke(),h=!0;continue}const d=u.x,f=u.y;E=u.width*n,B.lineWidth=E;const m=(d-g.minX)*n,w=(g.maxY-f)*n;h?(B.moveTo(m,w),h=!1):B.lineTo(m,w)}h||B.stroke()}),B.globalCompositeOperation="destination-out",B.fillStyle="black",s.forEach(Q=>{const h=(Q.x-g.minX)*n,E=(g.maxY-Q.y)*n,u=Q.outer_diameter/2*n;B.beginPath(),B.arc(h,E,u,0,2*Math.PI,!1),B.fill()}),r.forEach(Q=>{if(Q.layers.includes(e)&&Q.shape==="circle"){const h=(Q.x-g.minX)*n,E=(g.maxY-Q.y)*n,u=Q.outer_diameter/2*n;B.beginPath(),B.arc(h,E,u,0,2*Math.PI,!1),B.fill()}else if(Q.layers.includes(e)&&Q.shape==="rotated_pill_hole_with_rect_pad"){const h=(Q.x-g.minX)*n,E=(g.maxY-Q.y)*n,u=(Q.rect_pad_width??Q.hole_width??0)*n,d=(Q.rect_pad_height??Q.hole_height??0)*n,m=-(Q.rect_ccw_rotation||0);m?(B.save(),B.translate(h,E),B.rotate(m*Math.PI/180),B.beginPath(),B.rect(-u/2,-d/2,u,d),B.fill(),B.restore()):(B.beginPath(),B.rect(h-u/2,E-d/2,u,d),B.fill())}}),B.globalCompositeOperation="source-over";const C=new E_(c);return C.generateMipmaps=!0,C.minFilter=xE,C.magFilter=mI,C.anisotropy=16,C.needsUpdate=!0,C}Kr(b_()),Kr(gN());function J_e(e,A,t,i){if(!t||Math.abs(t)<1e-9)return[];const n=4*Math.atan(t),o=A[0]-e[0],s=A[1]-e[1],r=Math.sqrt(o*o+s*s);if(r<1e-9)return[];const a=Math.abs(r/(2*Math.sin(n/2))),g=Math.sqrt(Math.max(0,a*a-r/2*(r/2))),c=[(e[0]+A[0])/2,(e[1]+A[1])/2],I=o/r,B=-(s/r),C=I,Q=c[0]+B*g*Math.sign(t),h=c[1]+C*g*Math.sign(t),E=Math.atan2(e[1]-h,e[0]-Q),u=[],d=Math.max(2,Math.ceil(i*Math.abs(n)/(Math.PI*2)*4)),f=n/d;for(let m=1;m<d;m++){const w=E+f*m;u.push([Q+a*Math.cos(w),h+a*Math.sin(w)])}return u}function R7A(e,A){const t=[],i=e.vertices;for(let n=0;n<i.length;n++){const o=i[n],s=i[(n+1)%i.length];if(t.push([o.x,o.y]),o.bulge){const r=J_e([o.x,o.y],[s.x,s.y],o.bulge,A);t.push(...r)}}return t}function v7A({ctx:e,points:A,canvasXFromPcb:t,canvasYFromPcb:i}){A.length<3||(e.beginPath(),A.forEach((n,o)=>{const s=t(n[0]),r=i(n[1]);o===0?e.moveTo(s,r):e.lineTo(s,r)}),e.closePath(),e.fill())}function T_e({ctx:e,pour:A,canvasXFromPcb:t,canvasYFromPcb:i}){const n=A.brep_shape;if(!n||!n.outer_ring)return;const o=R7A(n.outer_ring,32);if(o.length>=3&&v7A({ctx:e,points:o,canvasXFromPcb:t,canvasYFromPcb:i}),n.inner_rings&&n.inner_rings.length>0){e.globalCompositeOperation="destination-out";for(const s of n.inner_rings){const r=R7A(s,32);r.length>=3&&v7A({ctx:e,points:r,canvasXFromPcb:t,canvasYFromPcb:i})}e.globalCompositeOperation="source-over"}}function K_e({layer:e,circuitJson:A,boardData:t,traceTextureResolution:i=yN}){const n=A.filter(E=>E.type==="pcb_copper_pour"),o=e==="top"?"top_copper":"bottom_copper",s=n.filter(E=>E.layer===e);if(s.length===0)return null;const r=yD(t),a=document.createElement("canvas"),g=Math.floor(r.width*i),c=Math.floor(r.height*i);a.width=g,a.height=c;const I=a.getContext("2d");if(!I)return null;e==="bottom"&&(I.translate(0,c),I.scale(1,-1));const l=E=>(E-r.minX)*i,B=E=>(r.maxY-E)*i,C=s.filter(E=>E.shape==="rect"||E.shape==="polygon"),Q=s.filter(E=>E.shape==="brep");if(C.length>0){const E=new vhA(I);E.setCameraBounds({minX:r.minX,maxX:r.maxX,minY:r.minY,maxY:r.maxY});const u=C.filter(w=>w.covered_with_solder_mask!==!1),d=C.filter(w=>w.covered_with_solder_mask===!1),f=`rgb(${pr.fr4TracesWithMaskGreen.map(w=>w*255).join(",")})`,m=`rgb(${pr.copper.map(w=>w*255).join(",")})`;u.length>0&&(E.configure({colorOverrides:{copper:{top:f,bottom:f,inner1:f,inner2:f,inner3:f,inner4:f,inner5:f,inner6:f}}}),E.drawElements(u,{layers:[o]})),d.length>0&&(E.configure({colorOverrides:{copper:{top:m,bottom:m,inner1:m,inner2:m,inner3:m,inner4:m,inner5:m,inner6:m}}}),E.drawElements(d,{layers:[o]}))}for(const E of Q){const d=E.covered_with_solder_mask!==!1?pr.fr4TracesWithMaskGreen:pr.copper,f=`rgb(${d[0]*255}, ${d[1]*255}, ${d[2]*255})`;I.fillStyle=f,T_e({ctx:I,pour:E,canvasXFromPcb:l,canvasYFromPcb:B})}const h=new E_(a);return h.generateMipmaps=!0,h.minFilter=xE,h.magFilter=mI,h.anisotropy=16,h.needsUpdate=!0,h}var nZ=e=>{const[A=0,t=0,i=0]=e;return`rgb(${Math.round(A*255)}, ${Math.round(t*255)}, ${Math.round(i*255)})`},P_e=e=>{const A=nZ(jxe[e]??pr.fr4SolderMaskGreen),t=nZ(e==="fr1"?pr.fr1TracesWithMaskCopper:pr.fr4TracesWithMaskGreen);return{soldermask:A,soldermaskOverCopper:t,copper:nZ(pr.copper),transparent:"rgba(0,0,0,0)"}},N7A=(e,A)=>{e.setCameraBounds({minX:A.minX,maxX:A.maxX,minY:A.minY,maxY:A.maxY})},q_e=({ctx:e,layer:A,bounds:t,elements:i,boardMaterial:n})=>{const o=P_e(n),s=A==="top"?"top_copper":"bottom_copper",r=new vhA(e);r.configure({colorOverrides:{copper:{top:o.transparent,bottom:o.transparent,inner1:o.transparent,inner2:o.transparent,inner3:o.transparent,inner4:o.transparent,inner5:o.transparent,inner6:o.transparent},drill:o.transparent,boardOutline:o.transparent,substrate:o.transparent,keepout:o.transparent,fabricationNote:o.transparent,silkscreen:{top:o.transparent,bottom:o.transparent},courtyard:{top:o.transparent,bottom:o.transparent},soldermask:{top:o.soldermask,bottom:o.soldermask},soldermaskWithCopperUnderneath:{top:o.soldermaskOverCopper,bottom:o.soldermaskOverCopper},soldermaskOverCopper:{top:o.soldermaskOverCopper,bottom:o.soldermaskOverCopper}}}),N7A(r,t),r.drawElements(i,{layers:[s],drawSoldermask:!0,drawSoldermaskTop:A==="top",drawSoldermaskBottom:A==="bottom"});const a=i.filter(g=>g.type==="pcb_copper_pour"&&g.layer===A&&g.covered_with_solder_mask===!1);if(a.length>0){e.save(),e.globalCompositeOperation="destination-out";const g=new vhA(e);g.configure({colorOverrides:{copper:{top:o.copper,bottom:o.copper,inner1:o.copper,inner2:o.copper,inner3:o.copper,inner4:o.copper,inner5:o.copper,inner6:o.copper}}}),N7A(g,t),g.drawElements(a,{layers:[s]}),e.restore()}},O_e=e=>({minX:e.center.x-e.width/2,maxX:e.center.x+e.width/2,minY:e.center.y-e.height/2,maxY:e.center.y+e.height/2,width:e.width,height:e.height,centerX:e.center.x,centerY:e.center.y}),W_e=(e,A)=>{const t=Math.min(e.minX,A.minX),i=Math.max(e.maxX,A.maxX),n=Math.min(e.minY,A.minY),o=Math.max(e.maxY,A.maxY);return{minX:t,maxX:i,minY:n,maxY:o,width:i-t,height:o-n,centerX:(t+i)/2,centerY:(n+o)/2}},Z_e=(e,A)=>{const t=e.filter(s=>s.type==="pcb_panel"),i=e.filter(s=>s.type==="pcb_board"),n=t.find(s=>s.pcb_panel_id===A.pcb_board_id)??t[0];return n&&n.width>0&&n.height>0?O_e(n):(i.length>1?i:[A]).map(s=>yD(s)).reduce((s,r)=>W_e(s,r))};function V_e({layer:e,circuitJson:A,boardData:t,traceTextureResolution:i=yN}){const n=Z_e(A,t),o=Math.floor(n.width*i),s=Math.floor(n.height*i);if(o<=0||s<=0)return null;const r=document.createElement("canvas");r.width=o,r.height=s;const a=r.getContext("2d");if(!a)return null;e==="bottom"&&(a.translate(0,s),a.scale(1,-1));const g=A.some(I=>I.type==="pcb_board")?A:[t,...A];q_e({ctx:a,layer:e,bounds:n,elements:g,boardMaterial:t.material});const c=new E_(r);return c.generateMipmaps=!0,c.minFilter=xE,c.magFilter=mI,c.anisotropy=16,c.needsUpdate=!0,c}var PEA=e=>{const[A=0,t=0,i=0]=e;return`rgb(${Math.round(A*255)}, ${Math.round(t*255)}, ${Math.round(i*255)})`},j_e=({textures:e,boardData:A,traceTextureResolution:t})=>{if(!e.some(c=>c?.image))return null;const n=yD(A),o=Math.floor(n.width*t),s=Math.floor(n.height*t);if(o<=0||s<=0)return null;const r=document.createElement("canvas");r.width=o,r.height=s+1;const a=r.getContext("2d");if(!a)return null;e.forEach(c=>{if(!c?.image)return;const I=c.image;a.drawImage(I,0,0,o,s)});const g=new E_(r);return g.generateMipmaps=!1,g.minFilter=mI,g.magFilter=mI,g.premultiplyAlpha=!0,g.anisotropy=16,g.needsUpdate=!0,g};function L7A({circuitJson:e,boardData:A,traceTextureResolution:t,visibility:i}){const n=PEA(pr.fr4TracesWithMaskGreen),o=PEA(pr.fr4TracesWithoutMaskTan),s="rgb(255,255,255)",r=PEA(pr.copper),a=i?.boardBody??!0,g=I=>{const l=(I==="top"?i?.topMask:i?.bottomMask)??!0,B=(I==="top"?i?.topCopper:i?.bottomCopper)??!0,C=(I==="top"?i?.topSilkscreen:i?.bottomSilkscreen)??!0,Q=l?V_e({layer:I,circuitJson:e,boardData:A,traceTextureResolution:t}):null,h=B?Y_e({layer:I,circuitJson:e,boardData:A,traceColor:l?n:o,traceTextureResolution:t}):null,E=B?G_e({layer:I,circuitJson:e,boardData:A,copperColor:r,traceTextureResolution:t}):null,u=B?K_e({layer:I,circuitJson:e,boardData:A,traceTextureResolution:t}):null,d=B?M_e({layer:I,circuitJson:e,boardData:A,copperColor:r,traceTextureResolution:t}):null,f=C?H_e({layer:I,circuitJson:e,boardData:A,silkscreenColor:s,traceTextureResolution:t}):null,m=a?R_e({layer:I,circuitJson:e,panelData:A,traceTextureResolution:t}):null;return j_e({textures:[u,h,E,d,Q,f,m],boardData:A,traceTextureResolution:t})},c=A.num_layers??2;return{topBoard:g("top"),bottomBoard:c<2?null:g("bottom")}}function U7A(e,A){const{texture:t,yOffset:i,isBottomLayer:n,usePolygonOffset:o=!1,renderOrder:s=0,isFaux:r=!1}=e;if(!t)return null;const a=yD(A),g=new iw(a.width,a.height),c=new Rd({map:t,transparent:!0,alphaTest:.08,side:ZB,depthWrite:!0,polygonOffset:o,polygonOffsetFactor:o?-4:0,polygonOffsetUnits:o?-4:0,opacity:r?XW:1}),I=new eo(g,c);return I.position.set(a.centerX,a.centerY,i),n&&I.rotation.set(Math.PI,0,0),I.name=`${n?"bottom":"top"}-board-texture-plane`,I.renderOrder=s,I}function z_e(e,A,t,i=!1){const n=[];if(!e||!A||t===null)return n;const o=.005,s=U7A({texture:e.topBoard,yOffset:t/2+o,isBottomLayer:!1,usePolygonOffset:!0,renderOrder:1,isFaux:i},A);s&&n.push(s);const r=U7A({texture:e.bottomBoard,yOffset:-t/2-o,isBottomLayer:!0,usePolygonOffset:!0,renderOrder:1,isFaux:i},A);return r&&n.push(r),n}var X_e=4e6,$_e=4096,Ake=1;function H7A(e,A,t={}){const{maxTexturePixels:i=X_e,maxTextureDimension:n=$_e,minTextureResolution:o=Ake}=t,s=yD(e);if(!Number.isFinite(s.width)||!Number.isFinite(s.height)||s.width<=0||s.height<=0)return A;const r=Math.max(s.width,s.height),a=n/r,g=Math.sqrt(i/(s.width*s.height)),c=Math.min(A,a,g);return Math.max(o,c)}function tke({circuitJson:e,pcbThickness:A,isFaux:t=!1}){const{rootObject:i}=Yu(),{visibility:n}=aG(),o=V.useMemo(()=>{const a=e.filter(I=>I.type==="pcb_panel"),g=Ti(e).pcb_board.list();if(a.length>0){const I=a[0],l=g.find(B=>B.pcb_panel_id===I.pcb_panel_id);return{type:"pcb_board",pcb_board_id:I.pcb_panel_id,center:I.center,width:I.width,height:I.height,thickness:l?.thickness??1.4,material:l?.material??"fr4",num_layers:l?.num_layers??2}}const c=g.filter(I=>!I.pcb_panel_id);return c.length>0?c[0]:null},[e]),s=V.useMemo(()=>o?H7A(o,yN):yN,[o]),r=V.useMemo(()=>!o||!o.width||!o.height?null:L7A({circuitJson:e,boardData:o,traceTextureResolution:s,visibility:n}),[e,o,s,n]);return V.useEffect(()=>{if(!i||!o||!r)return;const a=[],g=C=>{const Q=["map","alphaMap","aoMap","bumpMap","displacementMap","emissiveMap","lightMap","metalnessMap","normalMap","roughnessMap","specularMap"],h=C;for(const E of Q){const u=h[E];u&&u instanceof qc&&(u.dispose(),h[E]=null)}C.dispose()},c=(C,Q,h,E,u=!1,d=!0,f=1)=>{if(!C)return null;const m=yD(o),w=new iw(m.width,m.height),D=new Rd({map:C,transparent:!0,alphaTest:.08,side:ZB,depthWrite:d,polygonOffset:u,polygonOffsetFactor:u?-4:0,polygonOffsetUnits:u?-4:0,opacity:t?XW:1}),b=new eo(w,D);return b.position.set(m.centerX,m.centerY,Q),h&&b.rotation.set(Math.PI,0,0),b.name=E,b.renderOrder=f,b.frustumCulled=!1,b},I=.005,l=c(r.topBoard,A/2+I,!1,"jscad-top-board-texture",!0);l&&(a.push(l),i.add(l));const B=c(r.bottomBoard,-A/2-I,!0,"jscad-bottom-board-texture",!0);return B&&(a.push(B),i.add(B)),()=>{a.forEach(C=>{C.parent===i&&i.remove(C),C.geometry.dispose(),Array.isArray(C.material)?C.material.forEach(Q=>g(Q)):C.material instanceof cf&&g(C.material)}),r.topBoard?.dispose(),r.bottomBoard?.dispose()}},[i,o,r,A]),null}function eke(e){const A=Ti(e).cad_component.list(),t=Ti(e).pcb_smtpad.list(),i=Ti(e).pcb_hole.list(),n=Ti(e).pcb_plated_hole.list(),o=Ti(e).pcb_via.list();if(A.length===0&&t.length===0&&i.length===0&&n.length===0&&o.length===0)return null;const s=[...i,...n,...o,...t],r=uL(s);let a=r.minX,g=r.maxX,c=r.minY,I=r.maxY;for(const u of A)if(u.position){const d=u.position.x,f=u.position.y;a=Math.min(a,d),g=Math.max(g,d),c=Math.min(c,f),I=Math.max(I,f)}a===1/0&&(a=-10,g=10,c=-10,I=10);const l=2,B=Math.max(Math.abs(a),Math.abs(g))+l,C=Math.max(Math.abs(c),Math.abs(I))+l,Q=Math.max(2*B,10),h=Math.max(2*C,10);return{type:"pcb_board",pcb_board_id:"faux-board",center:{x:0,y:0},width:Q,height:h,thickness:1.4,material:"fr4",num_layers:2}}function Y7A(e){if(Ti(e).pcb_board.list().length>0)return e;const t=eke(e);if(!t)return e;const n=t.thickness/2;return[...e.map(s=>{if(s.type==="cad_component"){const r=s;if(r.position){const a=r.position.z??0;return{...r,position:{...r.position,z:a+n}}}}return s}),t]}var ike=V.forwardRef(({circuitJson:e,children:A,autoRotateDisabled:t,clickToInteractEnabled:i,onUserInteraction:n,onCameraControllerReady:o,resolveStaticAsset:s},r)=>{const a=d7A(A),g=V.useMemo(()=>Y7A(e??a),[e,a]),c=Q_e(g),I=V.useMemo(()=>{if(!g)return[5,-5,5];try{const u=Ti(g).pcb_board.list()[0];if(!u)return[5,-5,5];const{width:d,height:f}=u;if(!d&&!f)return[5,-5,5];const m=5,w=Math.max(d,m),D=Math.max(f,m),b=Math.max(w,D);return[b*.4,-b*.7,b*.9]}catch(u){return console.error(u),[5,-5,5]}},[g]),l=V.useMemo(()=>{if(!g)return!1;try{const u=Ti(g).pcb_board.list()[0];return!!u&&u.pcb_board_id==="faux-board"}catch{return!1}},[g]),B=V.useMemo(()=>{if(g)try{const u=Ti(g).pcb_board.list()[0];return u?{width:u.width??0,height:u.height??0}:void 0}catch(u){console.error(u);return}},[g]),C=V.useMemo(()=>{if(g)try{const u=Ti(g).pcb_board.list()[0];return!u||!u.center?void 0:{x:u.center.x,y:u.center.y}}catch(u){console.error(u);return}},[g]),Q=E6A(g),{stls:h}=Wxe(c),E=Ti(g).cad_component.list();return W.jsxs(u7A,{ref:r,autoRotateDisabled:t,initialCameraPosition:I,clickToInteractEnabled:i,boardDimensions:B,boardCenter:C,onUserInteraction:n,onCameraControllerReady:o,children:[h.map(({stlData:u,color:d,layerType:f},m)=>W.jsx(d_e,{stlData:u,color:d,opacity:m===0?l?.8:.95:1,layerType:f},`board-${m}`)),W.jsx(tke,{circuitJson:g,pcbThickness:Q,isFaux:l}),E.map(u=>W.jsx(D7A,{fallback:({error:d})=>W.jsx(w7A,{cad_component:u,error:d}),children:W.jsx(B7A,{cad_component:u,circuitJson:g,resolveStaticAsset:s},u.cad_component_id)},u.cad_component_id))]})}),nke=e=>{let A=0;for(let i=0;i<e.length;i++){const n=(i+1)%e.length;e[i]&&e[n]&&(A+=e[i][0]*e[n][1],A-=e[n][0]*e[i][1])}return A/2<=0};function oke(e,A,t,i,n){let o,s=null;if(t.outline&&t.outline.length>=3){let r=t.outline.map(g=>[g.x,g.y]);nke(r)&&(r=r.reverse());const a=A.ofPolygons([r]);n.push(a),s=a,o=e.extrude(a,i,void 0,void 0,void 0,!0),n.push(o)}else t.outline&&t.outline.length>0&&console.warn("Board outline has fewer than 3 points, falling back to rectangular board."),o=e.cube([t.width,t.height,i],!0),n.push(o),o=o.translate([t.center.x,t.center.y,0]),n.push(o);return{boardOp:o,outlineCrossSection:s}}var ske=64;function _0({Manifold:e,width:A,height:t,thickness:i,borderRadius:n}){const o=gG(A,t,n);if(o<=0)return e.cube([A,t,i],!0);const s=[],r=A-2*o,a=t-2*o;return r>0&&s.push(e.cube([r,t,i],!0)),a>0&&s.push(e.cube([A,a,i],!0)),[[A/2-o,t/2-o],[-A/2+o,t/2-o],[-A/2+o,-t/2+o],[A/2-o,-t/2+o]].forEach(([c,I])=>{s.push(e.cylinder(i,o,o,ske,!0).translate([c,I,0]))}),e.union(s)}var rke=e=>{let A=0;for(let i=0;i<e.length;i++){const n=(i+1)%e.length;e[i]&&e[n]&&(A+=e[i][0]*e[n][1],A-=e[n][0]*e[i][1])}return A/2<=0};function ake(e,A,t,i,n){const o=[],s=Ti(t).pcb_cutout.list();for(const r of s){let a;const g=i*1.5;switch(r.shape){case"rect":{const l=Ty(r);if(typeof l=="number"&&l>0?a=_0({Manifold:e,width:r.width,height:r.height,thickness:g,borderRadius:l}):a=e.cube([r.width,r.height,g],!0),n.push(a),r.rotation){const B=a.rotate([0,0,r.rotation]);n.push(B),a=B}a=a.translate([r.center.x,r.center.y,0]),n.push(a);break}case"circle":a=e.cylinder(g,r.radius,-1,jB,!0),n.push(a),a=a.translate([r.center.x,r.center.y,0]),n.push(a);break;case"polygon":if(r.points.length<3){console.warn(`PCB Cutout [${r.pcb_cutout_id}] polygon has fewer than 3 points, skipping.`);continue}let c=r.points.map(l=>[l.x,l.y]);rke(c)&&(c=c.reverse());const I=A.ofPolygons([c]);n.push(I),a=e.extrude(I,g,0,0,[1,1],!0),n.push(a);break;default:console.warn(`Unsupported cutout shape: ${r.shape} for cutout ${r.pcb_cutout_id}`);continue}a&&o.push(a)}return{cutoutOps:o}}function J7A({Manifold:e,x:A,y:t,diameter:i,thickness:n,segments:o=32}){return e.cylinder(n*1.2,i/2,i/2,o,!0).translate([A,t,0])}function T7A({Manifold:e,x:A,y:t,holeDiameter:i,thickness:n,zOffset:o=.001,segments:s=32}){const r=i/2+o;return e.cylinder(n*1.2,r,r,s,!0).translate([A,t,0])}function gke(e,A,t,i,n){const o=[],s=Ti(t).pcb_hole.list(),r=(g,c,I)=>{const l=_0({Manifold:e,width:g,height:c,thickness:I,borderRadius:Math.min(g,c)/2});return n.push(l),l},a=(g,c,I)=>{const l=[];for(let B=0;B<I;B++){const C=2*Math.PI*B/I;l.push([g/2*Math.cos(C),c/2*Math.sin(C)])}return l};return s.forEach(g=>{const c=g.hole_shape,I=g.x,l=g.y,B=i*1.2,C=g.ccw_rotation??g.rotation??0,Q=g.hole_width??g.hole_diameter,h=g.hole_height??g.hole_diameter;let E=null;if(c==="circle"){E=J7A({Manifold:e,x:I,y:l,diameter:g.hole_diameter,thickness:i,segments:jB}),o.push(E),n.push(E);return}if(c==="pill"||c==="rotated_pill")E=r(Q,h,B);else if(c==="oval"){let u=a(Q,h,jB),d=0;for(let m=0;m<u.length;m++){const w=(m+1)%u.length;d+=u[m][0]*u[w][1],d-=u[w][0]*u[m][1]}d<=0&&(u=u.reverse());const f=A.ofPolygons([u]);n.push(f),E=e.extrude(f,B,0,0,[1,1],!0),n.push(E)}if(E){if(C!==0){const d=E.rotate([0,0,C]);n.push(d),E=d}const u=E.translate([I,l,0]);n.push(u),o.push(u)}}),{nonPlatedHoleBoardDrills:o}}function mD(e){const A=new Sg;if(A.setAttribute("position",new To(e.vertProperties,3)),A.setIndex(new hrA(e.triVerts,1)),e.runIndex&&e.runIndex.length>1&&e.runOriginalID)for(let t=0;t<e.runIndex.length-1;t++){const i=e.runIndex[t],n=e.runIndex[t+1]-i;A.addGroup(i,n,0)}else A.addGroup(0,e.triVerts.length,0);return A}var WH=e=>{let A=0;for(let i=0;i<e.length;i++){const n=(i+1)%e.length;e[i]&&e[n]&&(A+=e[i][0]*e[n][1],A-=e[n][0]*e[i][1])}return A/2<=0},oZ=(e,A,t)=>{const i=[];for(let n=0;n<t;n++){const o=2*Math.PI*n/t;i.push([e/2*Math.cos(o),A/2*Math.sin(o)])}return i},IG=new Oi(...pr.copper),sZ=.05,rZ=.003,Ky=5e-4,aZ=.004;function cke(e,A,t,i,n,o){const s=[],r=Ti(t).pcb_plated_hole.list(),a=[],g=[],c=(C,Q,h)=>{const E=_0({Manifold:e,width:C,height:Q,thickness:h,borderRadius:Math.min(C,Q)/2});return n.push(E),E},I=({padOutline:C,thickness:Q})=>{if(!Array.isArray(C)||C.length<3)return null;let h=C.map(d=>[d.x,d.y]);WH(h)&&(h=h.reverse());const E=A.ofPolygons([h]);n.push(E);const u=e.extrude(E,Q,0,0,[1,1],!0);return n.push(u),u},l=({ph:C,depth:Q,sizeDelta:h=0})=>{if(C.shape!=="hole_with_polygon_pad")return null;const u=C.pad_outline;if(!Array.isArray(u)||u.length<3)return null;const d=C.hole_shape||"circle",f=C.hole_offset_x||0,m=C.hole_offset_y||0;let w=null;if(d==="circle"){const D=Math.max((C.hole_diameter??0)+h,Un),b=Math.max(D/2,Un/2);w=e.cylinder(Q,b,b,jB,!0),n.push(w)}else{const D=C.hole_width??C.hole_diameter,b=C.hole_height??C.hole_diameter;if(!D||!b)return null;const k=Math.max(D+h,Un),x=Math.max(b+h,Un);if(d==="oval"){let v=oZ(k,x,jB);WH(v)&&(v=v.reverse());const R=A.ofPolygons([v]);n.push(R),w=e.extrude(R,Q,0,0,[1,1],!0),n.push(w)}else(d==="pill"||d==="rotated_pill")&&(w=_0({Manifold:e,width:k,height:x,thickness:Q,borderRadius:Math.min(k,x)/2}),n.push(w))}if(!w)return null;if(f||m){const D=w.translate([f,m,0]);n.push(D),w=D}return w};r.forEach((C,Q)=>{if(C.shape==="circle"){const h=T7A({Manifold:e,x:C.x,y:C.y,holeDiameter:C.hole_diameter*1.02,thickness:i,zOffset:Bf,segments:jB});n.push(h),s.push(h);const E=i+2*Bf,u=e.cylinder(E,C.outer_diameter/2,C.outer_diameter/2,jB,!0);n.push(u);const d=e.cylinder(E*1.05,C.hole_diameter/2,C.hole_diameter/2,jB,!0);n.push(d);const f=u.subtract(d);n.push(f);const m=f.translate([C.x,C.y,0]);n.push(m);let w=m;if(o){const b=e.intersection([m,o]);n.push(b),w=b}g.push(w);const D=mD(w.getMesh());a.push({key:`ph-${C.pcb_plated_hole_id||Q}`,geometry:D,color:IG})}else if(C.shape==="pill"){const h=C.hole_width,E=C.hole_height,u=.4,d=C.outer_width??h+u,f=C.outer_height??E+u,m=h+2*Bf,w=E+2*Bf,D=i*1.2;let b=c(m,w,D);if(C.ccw_rotation){const Z=b.rotate([0,0,C.ccw_rotation]);n.push(Z),b=Z}const k=b.translate([C.x,C.y,0]);n.push(k),s.push(k);const x=i+2*Bf,v=c(d,f,x),R=c(h,E,x*1.05);let U=v.subtract(R);if(n.push(U),C.ccw_rotation){const Z=U.rotate([0,0,C.ccw_rotation]);n.push(Z),U=Z}const J=U.translate([C.x,C.y,0]);n.push(J);let H=J;if(o){const Z=e.intersection([J,o]);n.push(Z),H=Z}g.push(H);const O=mD(H.getMesh());a.push({key:`ph-${C.pcb_plated_hole_id||Q}`,geometry:O,color:IG})}else if(C.shape==="pill_hole_with_rect_pad"){if(C.hole_shape&&C.hole_shape!=="pill"||C.pad_shape&&C.pad_shape!=="rect")return;const h=C.hole_width,E=C.hole_height,u=C.hole_offset_x||0,d=C.hole_offset_y||0,f=C.rect_pad_width,m=C.rect_pad_height,w=Ty(C),D=rZ,b=h+2*Bf,k=E+2*Bf,x=i*1.2,R=c(b,k,x).translate([u,d,0]).translate([C.x,C.y,0]);n.push(R),s.push(R);const U=_0({Manifold:e,width:f,height:m,thickness:Math.max(i-2*(D+Ky+aZ),Un),borderRadius:w});n.push(U);const J=_0({Manifold:e,width:f,height:m,thickness:D,borderRadius:w}).translate([0,0,i/2+Ky+D/2]),H=_0({Manifold:e,width:f,height:m,thickness:D,borderRadius:w}).translate([0,0,-i/2-Ky-D/2]);n.push(J,H);const O=c(h,E,i*.8).translate([u,d,0]);n.push(O);const Z=e.union([U,J,H,O]);n.push(Z);const X=c(Math.max(h-2*sZ,.01),Math.max(E-2*sZ,.01),i*1.2).translate([u,d,0]);n.push(X);const iA=Z.subtract(X);n.push(iA);const aA=iA.translate([C.x,C.y,0]);n.push(aA);let tA=aA;if(o){const sA=e.intersection([aA,o]);n.push(sA),tA=sA}g.push(tA);const eA=mD(tA.getMesh());a.push({key:`ph-${C.pcb_plated_hole_id||Q}`,geometry:eA,color:IG})}else if(C.shape==="rotated_pill_hole_with_rect_pad"){if(C.hole_shape&&C.hole_shape!=="rotated_pill"||C.pad_shape&&C.pad_shape!=="rect")return;const h=C.hole_width,E=C.hole_height,u=C.hole_offset_x||0,d=C.hole_offset_y||0,f=C.rect_pad_width,m=C.rect_pad_height,w=Ty(C),D=rZ,b=h+2*Bf,k=E+2*Bf,x=i*1.2;let v=c(b,k,x).translate([u,d,0]);if(C.hole_ccw_rotation){const sA=v.rotate([0,0,C.hole_ccw_rotation]);n.push(sA),v=sA}const R=v.translate([C.x,C.y,0]);n.push(R),s.push(R);let U=_0({Manifold:e,width:f,height:m,thickness:Math.max(i-2*(D+Ky+aZ),Un),borderRadius:w});if(n.push(U),C.rect_ccw_rotation){const sA=U.rotate([0,0,C.rect_ccw_rotation]);n.push(sA),U=sA}let J=_0({Manifold:e,width:f,height:m,thickness:D,borderRadius:w}).translate([0,0,i/2+Ky+D/2]);if(C.rect_ccw_rotation){const sA=J.rotate([0,0,C.rect_ccw_rotation]);n.push(sA),J=sA}let H=_0({Manifold:e,width:f,height:m,thickness:D,borderRadius:w}).translate([0,0,-i/2-Ky-D/2]);if(C.rect_ccw_rotation){const sA=H.rotate([0,0,C.rect_ccw_rotation]);n.push(sA),H=sA}n.push(J,H);let O=c(h,E,i*.8).translate([u,d,0]);if(C.hole_ccw_rotation){const sA=O.rotate([0,0,C.hole_ccw_rotation]);n.push(sA),O=sA}n.push(O);const Z=e.union([U,J,H,O]);n.push(Z);let X=c(Math.max(h-2*sZ,.01),Math.max(E-2*sZ,.01),i*1.2).translate([u,d,0]);if(C.hole_ccw_rotation){const sA=X.rotate([0,0,C.hole_ccw_rotation]);n.push(sA),X=sA}n.push(X);const iA=Z.subtract(X);n.push(iA);const aA=iA.translate([C.x,C.y,0]);n.push(aA);let tA=aA;if(o){const sA=e.intersection([aA,o]);n.push(sA),tA=sA}g.push(tA);const eA=mD(tA.getMesh());a.push({key:`ph-${C.pcb_plated_hole_id||Q}`,geometry:eA,color:IG})}else if(C.shape==="hole_with_polygon_pad"){const h=C.pad_outline;if(!Array.isArray(h)||h.length<3)return;const E=l({ph:C,depth:i*1.2,sizeDelta:2*Un});if(!E)return;const u=E.translate([C.x,C.y,0]);n.push(u),s.push(u);const d=rZ,f=Math.max(i-2*(d+Ky+aZ),Un),m=I({padOutline:h,thickness:f}),w=I({padOutline:h,thickness:d}),D=I({padOutline:h,thickness:d});if(!m||!w||!D)return;const b=w.translate([0,0,i/2+Ky+d/2]),k=D.translate([0,0,-i/2-Ky-d/2]);n.push(b,k);const x=l({ph:C,depth:i*1.02});if(!x)return;const v=l({ph:C,depth:i*.8,sizeDelta:-2*Un})||x,R=e.union([m,b,k,x]);n.push(R);const U=R.subtract(v);n.push(U);const J=U.translate([C.x,C.y,0]);n.push(J);let H=J;if(o){const Z=e.intersection([J,o]);n.push(Z),H=Z}g.push(H);const O=mD(H.getMesh());a.push({key:`ph-${C.pcb_plated_hole_id||Q}`,geometry:O,color:IG})}else if(C.shape==="oval"){const h=C.hole_width,E=C.hole_height,u=C.outer_width??h+.4,d=C.outer_height??E+.4,f=h+2*Bf,m=E+2*Bf,w=i*1.2;let D=oZ(f,m,jB);WH(D)&&(D=D.reverse());const b=A.ofPolygons([D]);n.push(b);let k=e.extrude(b,w,0,0,[1,1],!0);if(n.push(k),C.ccw_rotation){const eA=k.rotate([0,0,C.ccw_rotation]);n.push(eA),k=eA}const x=k.translate([C.x,C.y,0]);n.push(x),s.push(x);const v=i+2*Bf;let R=oZ(u,d,jB);WH(R)&&(R=R.reverse());const U=A.ofPolygons([R]);n.push(U);const J=e.extrude(U,v,0,0,[1,1],!0);n.push(J);let H=oZ(h,E,jB);WH(H)&&(H=H.reverse());const O=A.ofPolygons([H]);n.push(O);const Z=e.extrude(O,v*1.05,0,0,[1,1],!0);n.push(Z);let X=J.subtract(Z);if(n.push(X),C.ccw_rotation){const eA=X.rotate([0,0,C.ccw_rotation]);n.push(eA),X=eA}const iA=X.translate([C.x,C.y,0]);n.push(iA);let aA=iA;if(o){const eA=e.intersection([iA,o]);n.push(eA),aA=eA}g.push(aA);const tA=mD(aA.getMesh());a.push({key:`ph-${C.pcb_plated_hole_id||Q}`,geometry:tA,color:IG})}else if(C.shape==="circular_hole_with_rect_pad"){if(C.hole_shape&&C.hole_shape!=="circle"||C.pad_shape&&C.pad_shape!=="rect")return;const h=C.hole_offset_x||0,E=C.hole_offset_y||0,u=J7A({Manifold:e,x:C.x+h,y:C.y+E,diameter:C.hole_diameter,thickness:i,segments:jB});n.push(u),s.push(u);const d=C.rect_pad_width??C.hole_diameter,f=C.rect_pad_height??C.hole_diameter,m=Ty(C),w=rZ,D=C.hole_diameter/2,b=_0({Manifold:e,width:d,height:f,thickness:Math.max(i-2*(w+Ky+aZ),Un),borderRadius:m});n.push(b);const k=_0({Manifold:e,width:d,height:f,thickness:w,borderRadius:m}).translate([0,0,i/2+Ky+w/2]),x=_0({Manifold:e,width:d,height:f,thickness:w,borderRadius:m}).translate([0,0,-i/2-Ky-w/2]);n.push(k,x);const v=e.cylinder(i*.8,D,D,jB,!0).translate([h,E,0]);n.push(v);const R=e.union([b,k,x,v]);n.push(R);const U=e.cylinder(i*1.2,Math.max(D-Un,.01),Math.max(D-Un,.01),jB,!0).translate([h,E,0]);n.push(U);const J=R.subtract(U);n.push(J);const H=J.translate([C.x,C.y,0]);n.push(H);let O=H;if(o){const X=e.intersection([H,o]);n.push(X),O=X}g.push(O);const Z=mD(O.getMesh());a.push({key:`ph-${C.pcb_plated_hole_id||Q}`,geometry:Z,color:IG})}});let B;return g.length>0&&(B=e.union(g),n.push(B)),{platedHoleBoardDrills:s,platedHoleCopperGeoms:a,platedHoleSubtractOp:B}}function Ike({Manifold:e,x:A,y:t,outerDiameter:i,holeDiameter:n,thickness:o,zOffset:s=.001,segments:r=32}){const a=s,g=s;if(i<n)throw new Error(`Invalid via geometry: outerDiameter (${i}) must be >= holeDiameter (${n})`);const c=Math.min(i/2,n/2+g),I=e.cylinder(o,c,-1,r,!0),l=e.cylinder(a,i/2,-1,r,!0).translate([0,0,o/2]),B=e.cylinder(a,i/2,-1,r,!0).translate([0,0,-o/2]),C=e.union([I,l,B]),Q=o+a*2,h=e.cylinder(Q,n/2,-1,r,!0);return C.subtract(h).translate([A,t,0])}var lke=new Oi(...pr.copper);function Bke(e,A,t,i,n){const o=[],s=Ti(A).pcb_via.list(),r=[];return s.forEach((a,g)=>{if(typeof a.hole_diameter=="number"){const c=T7A({Manifold:e,x:a.x,y:a.y,holeDiameter:a.hole_diameter,thickness:t,zOffset:Bf,segments:jB});i.push(c),o.push(c)}if(typeof a.outer_diameter=="number"&&typeof a.hole_diameter=="number"){const c=Ike({Manifold:e,x:a.x,y:a.y,outerDiameter:a.outer_diameter,holeDiameter:a.hole_diameter,thickness:t,zOffset:Bf,segments:jB});i.push(c);let I=c;if(n){const B=e.intersection([c,n]);i.push(B),I=B}const l=mD(I.getMesh());r.push({key:`via-${a.pcb_via_id||g}`,geometry:l,color:lke})}}),{viaBoardDrills:o,viaCopperGeoms:r}}var Cke=(e,A,t)=>{const[i,n]=V.useState(null),[o,s]=V.useState(null),[r,a]=V.useState(null),[g,c]=V.useState(!0),I=V.useRef([]),l=V.useMemo(()=>{const h=A.filter(d=>d.type==="pcb_panel"),E=Ti(A).pcb_board.list();if(h.length>0){const d=h[0],f=E.find(m=>m.pcb_panel_id===d.pcb_panel_id);return{type:"pcb_board",pcb_board_id:d.pcb_panel_id,center:d.center,width:d.width,height:d.height,thickness:f?.thickness??1.4,material:f?.material??"fr4",num_layers:f?.num_layers??2}}const u=E.filter(d=>!d.pcb_panel_id);return u.length>0?u[0]:null},[A]),B=V.useMemo(()=>{const h=Ti(A).pcb_board.list();return h.length>0&&h[0].pcb_board_id==="faux-board"},[A]),C=V.useMemo(()=>l?H7A(l,yN):yN,[l]);V.useEffect(()=>{if(!e||!l){n(null),s(null),c(!1);return}if((l.width===0||!l.width)&&(l.height===0||!l.height)&&(!l.outline||l.outline.length<3)){n({platedHoles:[],vias:[]}),s(l.thickness??0),c(!1);return}c(!0),a(null);const h=e.Manifold,E=e.CrossSection,u=m=>{if(!(!m||typeof m.delete!="function"))try{m.delete()}catch(w){(!(w instanceof Error)||!w.message?.includes("Manifold instance already deleted"))&&console.warn("Failed to delete Manifold instance",w)}};I.current.forEach(u),I.current=[];let d=null;const f={};try{const m=l.thickness||1.4;s(m);const{boardOp:w,outlineCrossSection:D}=oke(h,E,l,m,I.current);let b=w;const x=m+2*1;let v=null;const R=.01;if(D){let eA=D;if(R>0){const IA=D.offset(R);I.current.push(IA),eA=IA}const sA=h.extrude(eA,x,void 0,void 0,void 0,!0);I.current.push(sA),v=sA}else{const eA=(l.width||0)+2*R,sA=(l.height||0)+2*R,IA=h.cube([eA,sA,x],!0);I.current.push(IA);const uA=IA.translate([l.center.x,l.center.y,0]);I.current.push(uA),v=uA}const U=[];let J=null;const{nonPlatedHoleBoardDrills:H}=gke(h,E,A,m,I.current);U.push(...H);const{platedHoleBoardDrills:O,platedHoleCopperGeoms:Z,platedHoleSubtractOp:X}=cke(h,E,A,m,I.current,v);U.push(...O),f.platedHoles=Z;const{viaBoardDrills:iA,viaCopperGeoms:aA}=Bke(h,A,m,I.current,v);if(U.push(...iA),f.vias=aA,U.length>0){J=h.union(U),I.current.push(J);const eA=X?h.union([J,X]):J;I.current.push(eA);const sA=b.subtract(eA);if(I.current.push(sA),b=sA,X){const IA=X.subtract(J);I.current.push(IA);const uA=IA.getMesh(),xA=mD(uA);f.platedHoles=[{key:"plated-holes-union",geometry:xA,color:new Oi(pr.copper[0],pr.copper[1],pr.copper[2])}]}}const{cutoutOps:tA}=ake(h,E,A,m,I.current);if(tA.length>0){const eA=h.union(tA);I.current.push(eA);const sA=b.subtract(eA);I.current.push(sA),b=sA}if(d=b,d){const eA=d.getMesh(),sA=mD(eA),IA=HEA[l.material]??pr.fr4Tan;f.board={geometry:sA,color:new Oi(IA[0],IA[1],IA[2]),material:l.material,isFaux:B}}n(f)}catch(m){console.error("Error processing geometry with Manifold in hook:",m),a(m.message||"An unknown error occurred while processing geometry in hook."),n(null)}finally{c(!1)}return()=>{I.current.forEach(u),I.current=[]}},[e,A,l]);const Q=V.useMemo(()=>!l||!C?null:L7A({circuitJson:A,boardData:l,traceTextureResolution:C,visibility:t}),[A,l,C,t]);return{geoms:i,textures:Q,pcbThickness:o,error:r,isLoading:g,boardData:l,isFauxBoard:B}},Qke=ZB,hke=({material:e,color:A,side:t=Qke,isFaux:i=!1})=>e==="fr4"?new nw({color:A,side:t,metalness:0,roughness:.8,specularIntensity:.2,ior:1.45,sheen:0,clearcoat:0,transparent:i,opacity:i?XW:1,flatShading:!0,polygonOffset:!0,polygonOffsetFactor:1,polygonOffsetUnits:1}):new kE({color:A,side:t,flatShading:!0,metalness:.1,roughness:.8,transparent:!0,opacity:i?XW:.9,polygonOffset:!0,polygonOffsetFactor:1,polygonOffsetUnits:1});function Eke(e){const A=[];if(!e)return A;if(e.board&&e.board.geometry){const i=new eo(e.board.geometry,hke({material:e.board.material,color:e.board.color,side:ZB,isFaux:e.board.isFaux}));i.name="board-geom",A.push(i)}const t=i=>{i&&i.forEach(n=>{const o=new eo(n.geometry,new kE({color:n.color,side:ZB,flatShading:!0}));o.name=n.key,A.push(o)})};return t(e.platedHoles),t(e.vias),A}var uke=({geometryMeshes:e,textureMeshes:A})=>{const{rootObject:t}=Yu(),{visibility:i}=aG(),n=o=>{o.geometry.dispose();const s=Array.isArray(o.material)?o.material:[o.material];for(const r of s){if(!r)continue;const a=["map","alphaMap","aoMap","bumpMap","displacementMap","emissiveMap","lightMap","metalnessMap","normalMap","roughnessMap","specularMap"],g=r;for(const c of a){const I=g[c];I&&I instanceof qc&&(I.dispose(),g[c]=null)}r.dispose()}};return V.useEffect(()=>{if(t)return e.forEach(o=>{let s=!0;o.name==="board-geom"?s=i.boardBody:(o.name.includes("plated_hole")||o.name.includes("via"))&&(s=i.topCopper||i.bottomCopper),s&&t.add(o)}),()=>{e.forEach(o=>{o.parent===t&&t.remove(o),n(o)})}},[t,e,i]),V.useEffect(()=>{if(t)return A.forEach(o=>{t.add(o)}),()=>{A.forEach(o=>{o.parent===t&&t.remove(o),n(o)})}},[t,A]),null},dke="https://cdn.jsdelivr.net/npm/manifold-3d@3.2.1",pke=({circuitJson:e,autoRotateDisabled:A,clickToInteractEnabled:t,onUserInteraction:i,children:n,onCameraControllerReady:o,resolveStaticAsset:s})=>{const r=d7A(n),a=V.useMemo(()=>Y7A(e??r),[e,r]),[g,c]=V.useState(null),[I,l]=V.useState(null),{visibility:B}=aG();V.useEffect(()=>{if(window.ManifoldModule&&typeof window.ManifoldModule=="object"&&window.ManifoldModule.setup){c(window.ManifoldModule);return}const v=async Z=>{try{const X=await Z();X.setup(),window.ManifoldModule=X,c(X)}catch(X){console.error("Failed to initialize Manifold:",X),l(`Failed to initialize Manifold: ${X instanceof Error?X.message:"Unknown error"}`)}},R=window.ManifoldModule??window.MANIFOLD??window.MANIFOLD_MODULE;if(R){window.ManifoldModule=R,v(window.ManifoldModule);return}const U="manifoldLoaded",J=()=>{const Z=window.ManifoldModule??window.MANIFOLD??window.MANIFOLD_MODULE;if(Z)window.ManifoldModule=Z,v(window.ManifoldModule);else{const X="ManifoldModule not found on window after script load.";console.error(X),l(X)}};window.addEventListener(U,J,{once:!0});const H=document.createElement("script");H.type="module",H.innerHTML=`
|
|
5180
5180
|
try {
|
|
5181
5181
|
const { default: ManifoldModule } = await import('${dke}/manifold.js');
|
|
5182
5182
|
window.ManifoldModule = ManifoldModule;
|