@tscircuit/runframe 0.0.1491 → 0.0.1493
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.
|
@@ -5063,8 +5063,8 @@ ${a.join(`
|
|
|
5063
5063
|
`){h=Y,u-=b.height*Q,P();continue}D=b.width*E,F.width+=D,h+=D,m!==" "&&(F.segments=F.segments.concat(b.segments))}for(F.segments.length&&P(),d=0,f=k.length;d<f;d++)F=k[d],_>F.width&&(x=_-F.width,C==="right"?F=o({x},F):C==="center"&&(F=o({x:x/2},F))),v=v.concat(F.segments);return v};A.exports=n}}),UBA=oe({"node_modules/@jscad/modeling/src/text/index.js"(t,A){A.exports={vectorChar:Z8A(),vectorText:Brt()}}}),ZU=oe({"node_modules/@jscad/modeling/src/utils/areAllShapesTheSameType.js"(t,A){var e=Tn(),i=Kn(),o=yg(),n=s=>{let r;for(const a of s){let g=0;if(e.isA(a)&&(g=1),i.isA(a)&&(g=2),o.isA(a)&&(g=3),r&&g!==r)return!1;r=g}return!0};A.exports=n}}),Crt=oe({"node_modules/@jscad/modeling/src/utils/degToRad.js"(t,A){var e=i=>i*.017453292519943295;A.exports=e}}),V8A=oe({"node_modules/@jscad/modeling/src/utils/fnNumberSort.js"(t,A){var e=(i,o)=>i-o;A.exports=e}}),lrt=oe({"node_modules/@jscad/modeling/src/utils/insertSorted.js"(t,A){var e=(i,o,n)=>{let s=0,r=i.length;for(;r>s;){const a=Math.floor((s+r)/2),g=i[a];n(o,g)>0?s=a+1:r=a}i.splice(s,0,o)};A.exports=e}}),Qrt=oe({"node_modules/@jscad/modeling/src/utils/radiusToSegments.js"(t,A){var{TAU:e}=lr(),i=(o,n,s)=>{const r=n>0?o*e/n:0,a=s>0?e/s:0;return Math.ceil(Math.max(r,a,4))};A.exports=i}}),Ert=oe({"node_modules/@jscad/modeling/src/utils/radToDeg.js"(t,A){var e=i=>i*57.29577951308232;A.exports=e}}),j8A=oe({"node_modules/@jscad/modeling/src/utils/index.js"(t,A){A.exports={areAllShapesTheSameType:ZU(),degToRad:Crt(),flatten:Gn(),fnNumberSort:V8A(),insertSorted:lrt(),radiusToSegments:Qrt(),radToDeg:Ert()}}}),LBA=oe({"node_modules/@jscad/modeling/src/operations/booleans/fromFakePolygons.js"(t,A){var e=Bs(),i=Tn(),o=(s,r)=>{if(r.vertices.length<4)return null;const a=[],g=r.vertices.filter((B,C)=>B[2]>0?(a.push(C),!0):!1);if(g.length!==2)throw new Error("Assertion failed: fromFakePolygon: not enough points found");const I=g.map(B=>{const C=Math.round(B[0]/s)*s+0,l=Math.round(B[1]/s)*s+0;return e.fromValues(C,l)});if(e.equals(I[0],I[1]))return null;const c=a[1]-a[0];if(c===1||c===3)c===1&&I.reverse();else throw new Error("Assertion failed: fromFakePolygon: unknown index ordering");return I},n=(s,r)=>{const a=r.map(g=>o(s,g)).filter(g=>g!==null);return i.create(a)};A.exports=n}}),HBA=oe({"node_modules/@jscad/modeling/src/operations/booleans/to3DWalls.js"(t,A){var e=ho(),i=Tn(),o=Kn(),n=Xs(),s=(a,g,I)=>{const c=[e.fromVec2(e.create(),I[0],a),e.fromVec2(e.create(),I[1],a),e.fromVec2(e.create(),I[1],g),e.fromVec2(e.create(),I[0],g)];return n.create(c)},r=(a,g)=>{const c=i.toSides(g).map(C=>s(a.z0,a.z1,C));return o.create(c)};A.exports=r}}),hrt=oe({"node_modules/@jscad/modeling/src/maths/OrthoNormalBasis.js"(t,A){var e=Tg(),i=Bs(),o=ho(),n=function(s,r){arguments.length<2&&(r=o.orthogonal(o.create(),s)),this.v=o.normalize(o.create(),o.cross(o.create(),s,r)),this.u=o.cross(o.create(),this.v,s),this.plane=s,this.planeorigin=o.scale(o.create(),s,s[3])};n.prototype={getProjectionMatrix:function(){return e.fromValues(this.u[0],this.v[0],this.plane[0],0,this.u[1],this.v[1],this.plane[1],0,this.u[2],this.v[2],this.plane[2],0,0,0,-this.plane[3],1)},getInverseProjectionMatrix:function(){const s=o.scale(o.create(),this.plane,this.plane[3]);return e.fromValues(this.u[0],this.u[1],this.u[2],0,this.v[0],this.v[1],this.v[2],0,this.plane[0],this.plane[1],this.plane[2],0,s[0],s[1],s[2],1)},to2D:function(s){return i.fromValues(o.dot(s,this.u),o.dot(s,this.v))},to3D:function(s){const r=o.scale(o.create(),this.u,s[0]),a=o.scale(o.create(),this.v,s[1]),g=o.add(r,r,this.planeorigin);return o.add(a,a,g)}},A.exports=n}}),urt=oe({"node_modules/@jscad/modeling/src/operations/modifiers/reTesselateCoplanarPolygons.js"(t,A){var{EPS:e}=lr(),i=RBA(),o=Bs(),n=hrt(),s=k8A(),{insertSorted:r,fnNumberSort:a}=j8A(),g=Xs(),I=c=>{if(c.length<2)return c;const B=[],C=c.length,l=g.plane(c[0]),Q=new n(l),E=[],h=[],u=new Map,d=new Map,f=new Map,m=10/e;for(let F=0;F<C;F++){const k=c[F];let v=[],_=k.vertices.length,Y=-1;if(_>0){let P,T;for(let O=0;O<_;O++){let W=Q.to2D(k.vertices[O]);const AA=Math.floor(W[1]*m);let oA;f.has(AA)?oA=f.get(AA):f.has(AA+1)?oA=f.get(AA+1):f.has(AA-1)?oA=f.get(AA-1):(oA=W[1],f.set(AA,W[1])),W=o.fromValues(W[0],oA),v.push(W);const IA=W[1];(O===0||IA<P)&&(P=IA,Y=O),(O===0||IA>T)&&(T=IA);let tA=d.get(IA);tA||(tA={},d.set(IA,tA)),tA[F]=!0}if(P>=T)v=[],_=0,Y=-1;else{let O=u.get(P);O||(O=[],u.set(P,O)),O.push(F)}}v.reverse(),Y=_-Y-1,E.push(v),h.push(Y)}const b=[];d.forEach((F,k)=>b.push(k)),b.sort(a);let D=[],x=[];for(let F=0;F<b.length;F++){const k=[],v=b[F],_=d.get(v);for(let P=0;P<D.length;++P){const T=D[P],O=T.polygonindex;if(_[O]){const W=E[O],AA=W.length;let oA=T.leftvertexindex,IA=T.rightvertexindex;for(;;){let sA=oA+1;if(sA>=AA&&(sA=0),W[sA][1]!==v)break;oA=sA}let tA=IA-1;if(tA<0&&(tA=AA-1),W[tA][1]===v&&(IA=tA),oA!==T.leftvertexindex&&oA===IA)D.splice(P,1),--P;else{T.leftvertexindex=oA,T.rightvertexindex=IA,T.topleft=W[oA],T.topright=W[IA];let sA=oA+1;sA>=AA&&(sA=0),T.bottomleft=W[sA];let aA=IA-1;aA<0&&(aA=AA-1),T.bottomright=W[aA]}}}let Y;if(F>=b.length-1)D=[],Y=null;else{Y=Number(b[F+1]);const P=.5*(v+Y),T=u.get(v);for(const O in T){const W=T[O],AA=E[W],oA=AA.length,IA=h[W];let tA=IA;for(;;){let FA=tA+1;if(FA>=oA&&(FA=0),AA[FA][1]!==v||FA===IA)break;tA=FA}let sA=IA;for(;;){let FA=sA-1;if(FA<0&&(FA=oA-1),AA[FA][1]!==v||FA===tA)break;sA=FA}let aA=tA+1;aA>=oA&&(aA=0);let dA=sA-1;dA<0&&(dA=oA-1);const SA={polygonindex:W,leftvertexindex:tA,rightvertexindex:sA,topleft:AA[tA],topright:AA[sA],bottomleft:AA[aA],bottomright:AA[dA]};r(D,SA,(FA,MA)=>{const qA=s(FA.topleft,FA.bottomleft,P),CA=s(MA.topleft,MA.bottomleft,P);return qA>CA?1:qA<CA?-1:0})}}for(const P in D){const T=D[P];let O=s(T.topleft,T.bottomleft,v);const W=o.fromValues(O,v);O=s(T.topright,T.bottomright,v);const AA=o.fromValues(O,v);O=s(T.topleft,T.bottomleft,Y);const oA=o.fromValues(O,Y);O=s(T.topright,T.bottomright,Y);const IA=o.fromValues(O,Y),tA={topleft:W,topright:AA,bottomleft:oA,bottomright:IA,leftline:i.fromPoints(i.create(),W,oA),rightline:i.fromPoints(i.create(),IA,AA)};if(k.length>0){const sA=k[k.length-1],aA=o.distance(tA.topleft,sA.topright),dA=o.distance(tA.bottomleft,sA.bottomright);aA<e&&dA<e&&(tA.topleft=sA.topleft,tA.leftline=sA.leftline,tA.bottomleft=sA.bottomleft,k.splice(k.length-1,1))}k.push(tA)}if(F>0){const P=new Set,T=new Set;for(let O=0;O<k.length;O++){const W=k[O];for(let AA=0;AA<x.length;AA++)if(!T.has(AA)){const oA=x[AA];if(o.distance(oA.bottomleft,W.topleft)<e&&o.distance(oA.bottomright,W.topright)<e){T.add(AA);const IA=i.direction(W.leftline),tA=i.direction(oA.leftline),sA=IA[0]-tA[0],aA=i.direction(W.rightline),dA=i.direction(oA.rightline),SA=aA[0]-dA[0],FA=Math.abs(sA)<e,MA=Math.abs(SA)<e,qA=FA||sA>=0,CA=MA||SA>=0;qA&&CA&&(W.outpolygon=oA.outpolygon,W.leftlinecontinues=FA,W.rightlinecontinues=MA,P.add(AA));break}}}for(let O=0;O<x.length;O++)if(!P.has(O)){const W=x[O];W.outpolygon.rightpoints.push(W.bottomright),o.distance(W.bottomright,W.bottomleft)>e&&W.outpolygon.leftpoints.push(W.bottomleft),W.outpolygon.leftpoints.reverse();const oA=W.outpolygon.rightpoints.concat(W.outpolygon.leftpoints).map(tA=>Q.to3D(tA)),IA=g.fromPointsAndPlane(oA,l);IA.vertices.length&&B.push(IA)}}for(let P=0;P<k.length;P++){const T=k[P];T.outpolygon?(T.leftlinecontinues||T.outpolygon.leftpoints.push(T.topleft),T.rightlinecontinues||T.outpolygon.rightpoints.push(T.topright)):(T.outpolygon={leftpoints:[],rightpoints:[]},T.outpolygon.leftpoints.push(T.topleft),o.distance(T.topleft,T.topright)>e&&T.outpolygon.rightpoints.push(T.topright))}x=k}return B};A.exports=I}}),VU=oe({"node_modules/@jscad/modeling/src/operations/modifiers/retessellate.js"(t,A){var e=Kn(),i=Xs(),{NEPS:o}=lr(),n=urt(),s=g=>{if(g.isRetesselated)return g;const I=e.toPolygons(g).map((l,Q)=>({vertices:l.vertices,plane:i.plane(l),index:Q})),c=r(I),B=[];c.forEach(l=>{if(Array.isArray(l)){const Q=n(l);B.push(...Q)}else B.push(l)});const C=e.create(B);return C.isRetesselated=!0,C},r=g=>{let I=[g];const c=[];for(let C=3;C>=0;C--){const l=[],Q=C===3?15e-9:o;I.forEach(E=>{E.sort(a(C,Q));let h=0;for(let u=1;u<E.length;u++)E[u].plane[C]-E[h].plane[C]>Q&&(u-h===1?c.push(E[h]):l.push(E.slice(h,u)),h=u);E.length-h===1?c.push(E[h]):l.push(E.slice(h))}),I=l}const B=[];return I.forEach(C=>{C[0]&&(B[C[0].index]=C)}),c.forEach(C=>{B[C.index]=C}),B},a=(g,I)=>(c,B)=>c.plane[g]-B.plane[g]>I?1:B.plane[g]-c.plane[g]>I?-1:0;A.exports=s}}),YBA=oe({"node_modules/@jscad/modeling/src/operations/booleans/mayOverlap.js"(t,A){var{EPS:e}=lr(),i=AF(),o=(n,s)=>{if(n.polygons.length===0||s.polygons.length===0)return!1;const r=i(n),a=r[0],g=r[1],I=i(s),c=I[0],B=I[1];return!(c[0]-g[0]>e||a[0]-B[0]>e||c[1]-g[1]>e||a[1]-B[1]>e||c[2]-g[2]>e||a[2]-B[2]>e)};A.exports=o}}),drt=oe({"node_modules/@jscad/modeling/src/operations/booleans/trees/Node.js"(t,A){var e=Gm(),i=Xs(),o=class ryA{constructor(s){this.plane=null,this.front=null,this.back=null,this.polygontreenodes=[],this.parent=s}invert(){const s=[this];let r;for(let a=0;a<s.length;a++){r=s[a],r.plane&&(r.plane=e.flip(e.create(),r.plane)),r.front&&s.push(r.front),r.back&&s.push(r.back);const g=r.front;r.front=r.back,r.back=g}}clipPolygons(s,r){let a={node:this,polygontreenodes:s},g;const I=[];do{if(g=a.node,s=a.polygontreenodes,g.plane){const c=g.plane,B=[],C=[],l=r?B:C,Q=s.length;for(let h=0;h<Q;h++){const u=s[h];u.isRemoved()||u.splitByPlane(c,l,B,C,B)}g.front&&C.length>0&&I.push({node:g.front,polygontreenodes:C});const E=B.length;if(g.back&&E>0)I.push({node:g.back,polygontreenodes:B});else for(let h=0;h<E;h++)B[h].remove()}a=I.pop()}while(a!==void 0)}clipTo(s,r){let a=this;const g=[];do a.polygontreenodes.length>0&&s.rootnode.clipPolygons(a.polygontreenodes,r),a.front&&g.push(a.front),a.back&&g.push(a.back),a=g.pop();while(a!==void 0)}addPolygonTreeNodes(s){let r={node:this,polygontreenodes:s};const a=[];do{const g=r.node,I=r.polygontreenodes;if(I.length===0){r=a.pop();continue}if(!g.plane){let l=0;l=Math.floor(I.length/2);const Q=I[l].getPolygon();g.plane=i.plane(Q)}const c=[],B=[],C=I.length;for(let l=0;l<C;++l)I[l].splitByPlane(g.plane,g.polygontreenodes,B,c,B);c.length>0&&(g.front||(g.front=new ryA(g)),C===c.length&&B.length===0?g.front.polygontreenodes=c:a.push({node:g.front,polygontreenodes:c})),B.length>0&&(g.back||(g.back=new ryA(g)),C===B.length&&c.length===0?g.back.polygontreenodes=B:a.push({node:g.back,polygontreenodes:B})),r=a.pop()}while(r!==void 0)}};A.exports=o}}),prt=oe({"node_modules/@jscad/modeling/src/operations/booleans/trees/splitLineSegmentByPlane.js"(t,A){var e=ho(),i=(o,n,s)=>{const r=e.subtract(e.create(),s,n);let a=(o[3]-e.dot(o,n))/e.dot(o,r);return Number.isNaN(a)&&(a=0),a>1&&(a=1),a<0&&(a=0),e.scale(r,r,a),e.add(r,n,r),r};A.exports=i}}),frt=oe({"node_modules/@jscad/modeling/src/operations/booleans/trees/splitPolygonByPlane.js"(t,A){var{EPS:e}=lr(),i=Gm(),o=ho(),n=Xs(),s=prt(),r=(a,g)=>{const I={type:null,front:null,back:null},c=g.vertices,B=c.length,C=n.plane(g);if(i.equals(C,a))I.type=0;else{let l=!1,Q=!1;const E=[],h=-e;for(let u=0;u<B;u++){const d=o.dot(a,c[u])-a[3],f=d<h;E.push(f),d>e&&(l=!0),d<h&&(Q=!0)}if(!l&&!Q){const u=o.dot(a,C);I.type=u>=0?0:1}else if(!Q)I.type=2;else if(!l)I.type=3;else{I.type=4;const u=[],d=[];let f=E[0];for(let b=0;b<B;b++){const D=c[b];let x=b+1;x>=B&&(x=0);const F=E[x];if(f===F)f?d.push(D):u.push(D);else{const k=c[x],v=s(a,D,k);f?(d.push(D),d.push(v),u.push(v)):(u.push(D),u.push(v),d.push(v))}f=F}const m=e*e;if(d.length>=3){let b=d[d.length-1];for(let D=0;D<d.length;D++){const x=d[D];o.squaredDistance(x,b)<m&&(d.splice(D,1),D--),b=x}}if(u.length>=3){let b=u[u.length-1];for(let D=0;D<u.length;D++){const x=u[D];o.squaredDistance(x,b)<m&&(u.splice(D,1),D--),b=x}}u.length>=3&&(I.front=n.fromPointsAndPlane(u,C)),d.length>=3&&(I.back=n.fromPointsAndPlane(d,C))}}return I};A.exports=r}}),yrt=oe({"node_modules/@jscad/modeling/src/operations/booleans/trees/PolygonTreeNode.js"(t,A){var{EPS:e}=lr(),i=ho(),o=Xs(),n=frt(),s=class Qce{constructor(a,g){this.parent=a,this.children=[],this.polygon=g,this.removed=!1}addPolygons(a){if(!this.isRootNode())throw new Error("Assertion failed");const g=this;a.forEach(I=>{g.addChild(I)})}remove(){if(!this.removed){this.removed=!0,this.polygon=null;const a=this.parent.children,g=a.indexOf(this);if(g<0)throw new Error("Assertion failed");a.splice(g,1),this.parent.recursivelyInvalidatePolygon()}}isRemoved(){return this.removed}isRootNode(){return!this.parent}invert(){if(!this.isRootNode())throw new Error("Assertion failed");this.invertSub()}getPolygon(){if(!this.polygon)throw new Error("Assertion failed");return this.polygon}getPolygons(a){let g=[this];const I=[g];let c,B,C,l;for(c=0;c<I.length;++c)for(g=I[c],B=0,C=g.length;B<C;B++)l=g[B],l.polygon?a.push(l.polygon):l.children.length>0&&I.push(l.children)}splitByPlane(a,g,I,c,B){if(this.children.length){const C=[this.children];let l,Q,E,h,u;for(l=0;l<C.length;l++)for(u=C[l],Q=0,E=u.length;Q<E;Q++)h=u[Q],h.children.length>0?C.push(h.children):h._splitByPlane(a,g,I,c,B)}else this._splitByPlane(a,g,I,c,B)}_splitByPlane(a,g,I,c,B){const C=this.polygon;if(C){const l=o.measureBoundingSphere(C),Q=l[3]+e,E=l,h=i.dot(a,E)-a[3];if(h>Q)c.push(this);else if(h<-Q)B.push(this);else{const u=n(a,C);switch(u.type){case 0:g.push(this);break;case 1:I.push(this);break;case 2:c.push(this);break;case 3:B.push(this);break;case 4:if(u.front){const d=this.addChild(u.front);c.push(d)}if(u.back){const d=this.addChild(u.back);B.push(d)}break}}}}addChild(a){const g=new Qce(this,a);return this.children.push(g),g}invertSub(){let a=[this];const g=[a];let I,c,B,C;for(I=0;I<g.length;I++)for(a=g[I],c=0,B=a.length;c<B;c++)C=a[c],C.polygon&&(C.polygon=o.invert(C.polygon)),C.children.length>0&&g.push(C.children)}recursivelyInvalidatePolygon(){this.polygon=null,this.parent&&this.parent.recursivelyInvalidatePolygon()}clear(){let a=[this];const g=[a];for(let I=0;I<g.length;++I){a=g[I];const c=a.length;for(let B=0;B<c;B++){const C=a[B];C.polygon&&(C.polygon=null),C.parent&&(C.parent=null),C.children.length>0&&g.push(C.children),C.children=[]}}}toString(){let a="",g=[this];const I=[g];let c,B,C,l;for(c=0;c<I.length;++c){g=I[c];const Q=" ".repeat(c);for(B=0,C=g.length;B<C;B++)l=g[B],a+=`${Q}PolygonTreeNode (${l.isRootNode()}): ${l.children.length}`,l.polygon?a+=`
|
|
5064
5064
|
${Q}polygon: ${l.polygon.vertices}
|
|
5065
5065
|
`:a+=`
|
|
5066
|
-
`,l.children.length>0&&I.push(l.children)}return a}};A.exports=s}}),wrt=oe({"node_modules/@jscad/modeling/src/operations/booleans/trees/Tree.js"(t,A){var e=drt(),i=yrt(),o=class{constructor(n){this.polygonTree=new i,this.rootnode=new e(null),n&&this.addPolygons(n)}invert(){this.polygonTree.invert(),this.rootnode.invert()}clipTo(n,s=!1){this.rootnode.clipTo(n,s)}allPolygons(){const n=[];return this.polygonTree.getPolygons(n),n}addPolygons(n){const s=new Array(n.length);for(let r=0;r<n.length;r++)s[r]=this.polygonTree.addChild(n[r]);this.rootnode.addPolygonTreeNodes(s)}clear(){this.polygonTree.clear()}toString(){return"Tree: "+this.polygonTree.toString("")}};A.exports=o}}),JBA=oe({"node_modules/@jscad/modeling/src/operations/booleans/trees/index.js"(t,A){A.exports={Tree:wrt()}}}),mrt=oe({"node_modules/@jscad/modeling/src/operations/booleans/intersectGeom3Sub.js"(t,A){var e=Kn(),i=YBA(),{Tree:o}=JBA(),n=(s,r)=>{if(!i(s,r))return e.create();const a=new o(e.toPolygons(s)),g=new o(e.toPolygons(r));a.invert(),g.clipTo(a),g.invert(),a.clipTo(g),g.clipTo(a),a.addPolygons(g.allPolygons()),a.invert();const I=a.allPolygons();return e.create(I)};A.exports=n}}),z8A=oe({"node_modules/@jscad/modeling/src/operations/booleans/intersectGeom3.js"(t,A){var e=Gn(),i=VU(),o=mrt(),n=(...s)=>{s=e(s);let r=s.shift();return s.forEach(a=>{r=o(r,a)}),r=i(r),r};A.exports=n}}),Drt=oe({"node_modules/@jscad/modeling/src/operations/booleans/intersectGeom2.js"(t,A){var e=Gn(),i=Kn(),o=bx(),n=LBA(),s=HBA(),r=z8A(),a=(...g)=>{g=e(g);const I=g.map(C=>s({z0:-1,z1:1},C)),c=r(I),B=o(c);return n(B,i.toPolygons(c))};A.exports=a}}),Srt=oe({"node_modules/@jscad/modeling/src/operations/booleans/intersect.js"(t,A){var e=Gn(),i=ZU(),o=Tn(),n=Kn(),s=Drt(),r=z8A(),a=(...g)=>{if(g=e(g),g.length===0)throw new Error("wrong number of arguments");if(!i(g))throw new Error("only intersect of the types are supported");const I=g[0];return o.isA(I)?s(g):n.isA(I)?r(g):I};A.exports=a}}),brt=oe({"node_modules/@jscad/modeling/src/operations/booleans/scissionGeom3.js"(t,A){var e=ho(),i=bx(),o=Kn(),n=g=>g.sort((I,c)=>I-c).filter((I,c,B)=>!c||I!==B[c-1]),s=(g,I,c)=>{const B=`${I}`,C=g.get(B);C===void 0?g.set(B,[c]):C.push(c)},r=(g,I)=>{const c=`${I}`;return g.get(c)},a=g=>{const I=i(g),c=o.toPolygons(g),B=c.length,C=new Map,l=e.create();c.forEach((d,f)=>{d.vertices.forEach(m=>{s(C,e.snap(l,m,I),f)})});const Q=c.map(d=>{let f=[];return d.vertices.forEach(m=>{f=f.concat(r(C,e.snap(l,m,I)))}),{e:1,d:n(f)}});C.clear();let E=0;const h=Q.length;for(let d=0;d<h;d++){const f=Q[d];if(f.e>0){const m=new Array(B);m[d]=!0;do E=0,m.forEach((b,D)=>{const x=Q[D];if(x.e>0){x.e=-1;for(let F=0;F<x.d.length;F++)m[x.d[F]]=!0;E++}});while(E>0);f.indexes=m}}const u=[];for(let d=0;d<h;d++)if(Q[d].indexes){const f=[];Q[d].indexes.forEach((m,b)=>f.push(c[b])),u.push(o.create(f))}return u};A.exports=a}}),xrt=oe({"node_modules/@jscad/modeling/src/operations/booleans/scission.js"(t,A){var e=Gn(),i=Kn(),o=brt(),n=(...s)=>{if(s=e(s),s.length===0)throw new Error("wrong number of arguments");const r=s.map(a=>i.isA(a)?o(a):a);return r.length===1?r[0]:r};A.exports=n}}),krt=oe({"node_modules/@jscad/modeling/src/operations/booleans/subtractGeom3Sub.js"(t,A){var e=Kn(),i=YBA(),{Tree:o}=JBA(),n=(s,r)=>{if(!i(s,r))return e.clone(s);const a=new o(e.toPolygons(s)),g=new o(e.toPolygons(r));a.invert(),a.clipTo(g),g.clipTo(a,!0),a.addPolygons(g.allPolygons()),a.invert();const I=a.allPolygons();return e.create(I)};A.exports=n}}),X8A=oe({"node_modules/@jscad/modeling/src/operations/booleans/subtractGeom3.js"(t,A){var e=Gn(),i=VU(),o=krt(),n=(...s)=>{s=e(s);let r=s.shift();return s.forEach(a=>{r=o(r,a)}),r=i(r),r};A.exports=n}}),Grt=oe({"node_modules/@jscad/modeling/src/operations/booleans/subtractGeom2.js"(t,A){var e=Gn(),i=Kn(),o=bx(),n=LBA(),s=HBA(),r=X8A(),a=(...g)=>{g=e(g);const I=g.map(C=>s({z0:-1,z1:1},C)),c=r(I),B=o(c);return n(B,i.toPolygons(c))};A.exports=a}}),Frt=oe({"node_modules/@jscad/modeling/src/operations/booleans/subtract.js"(t,A){var e=Gn(),i=ZU(),o=Tn(),n=Kn(),s=Grt(),r=X8A(),a=(...g)=>{if(g=e(g),g.length===0)throw new Error("wrong number of arguments");if(!i(g))throw new Error("only subtract of the types are supported");const I=g[0];return o.isA(I)?s(g):n.isA(I)?r(g):I};A.exports=a}}),$8A=oe({"node_modules/@jscad/modeling/src/operations/booleans/unionGeom3Sub.js"(t,A){var e=Kn(),i=YBA(),{Tree:o}=JBA(),n=(r,a)=>{if(!i(r,a))return s(r,a);const g=new o(e.toPolygons(r)),I=new o(e.toPolygons(a));g.clipTo(I,!1),I.clipTo(g),I.invert(),I.clipTo(g),I.invert();const c=g.allPolygons().concat(I.allPolygons());return e.create(c)},s=(r,a)=>{let g=e.toPolygons(r);return g=g.concat(e.toPolygons(a)),e.create(g)};A.exports=n}}),AWA=oe({"node_modules/@jscad/modeling/src/operations/booleans/unionGeom3.js"(t,A){var e=Gn(),i=VU(),o=$8A(),n=(...s)=>{s=e(s);let r;for(r=1;r<s.length;r+=2)s.push(o(s[r-1],s[r]));let a=s[r-1];return a=i(a),a};A.exports=n}}),eWA=oe({"node_modules/@jscad/modeling/src/operations/booleans/unionGeom2.js"(t,A){var e=Gn(),i=Kn(),o=bx(),n=LBA(),s=HBA(),r=AWA(),a=(...g)=>{g=e(g);const I=g.map(C=>s({z0:-1,z1:1},C)),c=r(I),B=o(c);return n(B,i.toPolygons(c))};A.exports=a}}),TBA=oe({"node_modules/@jscad/modeling/src/operations/booleans/union.js"(t,A){var e=Gn(),i=ZU(),o=Tn(),n=Kn(),s=eWA(),r=AWA(),a=(...g)=>{if(g=e(g),g.length===0)throw new Error("wrong number of arguments");if(!i(g))throw new Error("only unions of the same type are supported");const I=g[0];return o.isA(I)?s(g):n.isA(I)?r(g):I};A.exports=a}}),ON=oe({"node_modules/@jscad/modeling/src/operations/booleans/index.js"(t,A){A.exports={intersect:Srt(),scission:xrt(),subtract:Frt(),union:TBA()}}}),t5=oe({"node_modules/@jscad/modeling/src/operations/expansions/offsetFromPoints.js"(t,A){var{EPS:e,TAU:i}=lr(),o=G8A(),n=RBA(),s=Bs(),r=$O(),a=(g,I)=>{const c={delta:1,corners:"edge",closed:!1,segments:16};let{delta:B,corners:C,closed:l,segments:Q}=Object.assign({},c,g);if(Math.abs(B)<e)return I;let E=g.closed?r(I):1;E===0&&(E=1);const h=E>0&&B>=0||E<0&&B<0;B=Math.abs(B);let u=null,d=[];const f=[],m=s.create(),b=I.length;for(let D=0;D<b;D++){const x=(D+1)%b,F=I[D],k=I[x];h?s.subtract(m,F,k):s.subtract(m,k,F),s.normal(m,m),s.normalize(m,m),s.scale(m,m,B);const v=s.add(s.create(),F,m),_=s.add(s.create(),k,m),Y=[v,_];if(u!=null&&(l||!l&&x!==0)){const P=o(u[0],u[1],Y[0],Y[1]);P?(d.pop(),Y[0]=P):f.push({c:F,s0:u,s1:Y})}u=[v,_],!(x===0&&!l)&&(d.push(Y[0]),d.push(Y[1]))}if(l&&u!=null){const D=d[0],x=d[1],F=o(u[0],u[1],D,x);if(F)d[0]=F,d.pop();else{const k=I[0],v=[D,x];f.push({c:k,s0:u,s1:v})}}if(C==="edge"){const D=new Map;d.forEach((k,v)=>D.set(k,v));const x=n.create(),F=n.create();f.forEach(k=>{n.fromPoints(x,k.s0[0],k.s0[1]),n.fromPoints(F,k.s1[0],k.s1[1]);const v=n.intersectPointOfLines(x,F);if(Number.isFinite(v[0])&&Number.isFinite(v[1])){const _=k.s0[1],Y=D.get(_);d[Y]=v,d[(Y+1)%d.length]=void 0}else{const _=k.s1[0],Y=D.get(_);d[Y]=void 0}}),d=d.filter(k=>k!==void 0)}if(C==="round"){let D=Math.floor(Q/4);const x=s.create();f.forEach(F=>{let k=s.angle(s.subtract(x,F.s1[0],F.c));if(k-=s.angle(s.subtract(x,F.s0[1],F.c)),h&&k<0&&(k=k+Math.PI,k<0&&(k=k+Math.PI)),!h&&k>0&&(k=k-Math.PI,k>0&&(k=k-Math.PI)),k!==0){D=Math.floor(Q*(Math.abs(k)/i));const v=k/D,_=s.angle(s.subtract(x,F.s0[1],F.c)),Y=[];for(let P=1;P<D;P++){const T=_+v*P,O=s.fromAngleRadians(s.create(),T);s.scale(O,O,B),s.add(O,O,F.c),Y.push(O)}if(Y.length>0){const P=F.s0[1];let T=d.findIndex(O=>s.equals(P,O));T=(T+1)%d.length,d.splice(T,0,...Y)}}else{const v=F.s1[0],_=d.findIndex(Y=>s.equals(v,Y));d.splice(_,1)}})}return d};A.exports=a}}),Rrt=oe({"node_modules/@jscad/modeling/src/operations/expansions/expandGeom2.js"(t,A){var e=Tn(),i=t5(),o=(n,s)=>{const r={delta:1,corners:"edge",segments:16},{delta:a,corners:g,segments:I}=Object.assign({},r,n);if(!(g==="edge"||g==="chamfer"||g==="round"))throw new Error('corners must be "edge", "chamfer", or "round"');const C=e.toOutlines(s).map(l=>(n={delta:a,corners:g,closed:!0,segments:I},i(n,l))).reduce((l,Q)=>l.concat(e.toSides(e.fromPoints(Q))),[]);return e.create(C)};A.exports=o}}),Mrt=oe({"node_modules/@jscad/modeling/src/operations/expansions/extrudePolygon.js"(t,A){var e=Tg(),i=ho(),o=Kn(),n=Xs(),s=(r,a)=>{i.dot(n.plane(a),r)>0&&(a=n.invert(a));const I=[a],c=n.transform(e.fromTranslation(e.create(),r),a),B=a.vertices.length;for(let C=0;C<B;C++){const l=C<B-1?C+1:0,Q=n.create([a.vertices[C],c.vertices[C],c.vertices[l],a.vertices[l]]);I.push(Q)}return I.push(n.invert(c)),o.create(I)};A.exports=s}}),Nrt=oe({"node_modules/@jscad/modeling/src/operations/expansions/expandShell.js"(t,A){var{EPS:e,TAU:i}=lr(),o=Tg(),n=ho(),s=V8A(),r=Kn(),a=Xs(),g=T8A(),I=VU(),c=$8A(),B=Mrt(),C=(h,u,d)=>{const f=u.toString();if(h.has(f))h.get(f)[1].push(d);else{const m=[u,[d]];h.set(f,m)}},l=(h,u,d)=>{const f=u[0].toString(),m=u[1].toString(),b=f<m?`${f},${m}`:`${m},${f}`;if(h.has(b))h.get(b)[1].push(d);else{const D=[u,[d]];h.set(b,D)}},Q=(h,u)=>{h.findIndex(f=>f===u)<0&&h.push(u)},E=(h,u)=>{const d={delta:1,segments:12},{delta:f,segments:m}=Object.assign({},d,h);let b=r.create();const D=new Map,x=new Map,F=n.create(),k=n.create();return r.toPolygons(u).forEach((_,Y)=>{const P=n.scale(n.create(),a.plane(_),2*f),T=a.transform(o.fromTranslation(o.create(),n.scale(n.create(),P,-.5)),_),O=B(P,T);b=c(b,O);const W=_.vertices;for(let AA=0;AA<W.length;AA++){C(D,W[AA],a.plane(_));const oA=(AA+1)%W.length,IA=[W[AA],W[oA]];l(x,IA,a.plane(_))}}),x.forEach(_=>{const Y=_[0],P=_[1],T=Y[0],O=Y[1],W=n.subtract(n.create(),O,T);n.normalize(W,W);const AA=P[0],oA=n.cross(n.create(),AA,W);let IA=[];for(let qA=0;qA<m;qA++)Q(IA,qA*i/m);for(let qA=0,CA=P.length;qA<CA;qA++){const GA=P[qA],uA=n.dot(oA,GA),TA=n.dot(AA,GA);let $A=Math.atan2(uA,TA);$A<0&&($A+=i),Q(IA,$A),$A=Math.atan2(-uA,-TA),$A<0&&($A+=i),Q(IA,$A)}IA=IA.sort(s);const tA=IA.length;let sA,aA;const dA=[],SA=[],FA=[];for(let qA=-1;qA<tA;qA++){const CA=IA[qA<0?qA+tA:qA],GA=Math.sin(CA),uA=Math.cos(CA);n.scale(F,AA,uA*f),n.scale(k,oA,GA*f),n.add(F,F,k);const TA=n.add(n.create(),T,F),$A=n.add(n.create(),O,F);let ae=!1;if(qA>=0&&n.distance(TA,sA)<e&&(ae=!0),!ae){if(qA>=0){dA.push(TA),SA.push($A);const fA=[aA,$A,TA,sA],KA=a.create(fA);FA.push(KA)}sA=TA,aA=$A}}SA.reverse(),FA.push(a.create(dA)),FA.push(a.create(SA));const MA=r.create(FA);b=c(b,MA)}),D.forEach(_=>{const Y=_[0],P=_[1],T=P[0];let O=null,W=0;for(let tA=1;tA<P.length;tA++){const sA=P[tA],aA=n.cross(F,T,sA),dA=n.length(aA);dA>.05&&dA>W&&(W=dA,O=sA)}O||(O=n.orthogonal(F,T));const AA=n.cross(F,T,O);n.normalize(AA,AA);const oA=n.cross(k,AA,T),IA=g({center:[Y[0],Y[1],Y[2]],radius:f,segments:m,axes:[T,AA,oA]});b=c(b,IA)}),I(b)};A.exports=E}}),_rt=oe({"node_modules/@jscad/modeling/src/operations/expansions/expandGeom3.js"(t,A){var e=Kn(),i=TBA(),o=Nrt(),n=(s,r)=>{const a={delta:1,corners:"round",segments:12},{delta:g,corners:I,segments:c}=Object.assign({},a,s);if(I!=="round")throw new Error('corners must be "round" for 3D geometries');if(e.toPolygons(r).length===0)throw new Error("the given geometry cannot be empty");s={delta:g,corners:I,segments:c};const C=o(s,r);return i(r,C)};A.exports=n}}),vrt=oe({"node_modules/@jscad/modeling/src/operations/expansions/expandPath2.js"(t,A){var e=$O(),i=Bs(),o=Tn(),n=yg(),s=t5(),r=I=>{let{external:c,internal:B}=I;e(c)<0?c=c.reverse():B=B.reverse();const C=n.fromPoints({closed:!0},c),l=n.fromPoints({closed:!0},B),Q=o.toSides(o.fromPoints(n.toPoints(C))),E=o.toSides(o.fromPoints(n.toPoints(l)));return Q.push(...E),o.create(Q)},a=(I,c,B,C)=>{const{points:l,external:Q,internal:E}=I,h=Math.floor(c/2),u=[],d=[];if(B==="round"&&h>0){const m=Math.PI/h,b=l[l.length-1],D=i.angle(i.subtract(i.create(),Q[Q.length-1],b)),x=l[0],F=i.angle(i.subtract(i.create(),E[0],x));for(let k=1;k<h;k++){let v=D+m*k,_=i.fromAngleRadians(i.create(),v);i.scale(_,_,C),i.add(_,_,b),u.push(_),v=F+m*k,_=i.fromAngleRadians(i.create(),v),i.scale(_,_,C),i.add(_,_,x),d.push(_)}}const f=[];return f.push(...Q,...u,...E.reverse(),...d),o.fromPoints(f)},g=(I,c)=>{I=Object.assign({},{delta:1,corners:"edge",segments:16},I);const{delta:C,corners:l,segments:Q}=I;if(C<=0)throw new Error("the given delta must be positive for paths");if(!(l==="edge"||l==="chamfer"||l==="round"))throw new Error('corners must be "edge", "chamfer", or "round"');const E=c.isClosed,h=n.toPoints(c);if(h.length===0)throw new Error("the given geometry cannot be empty");const u={points:h,external:s({delta:C,corners:l,segments:Q,closed:E},h),internal:s({delta:-C,corners:l,segments:Q,closed:E},h)};return c.isClosed?r(u):a(u,Q,l,C)};A.exports=g}}),KBA=oe({"node_modules/@jscad/modeling/src/operations/expansions/expand.js"(t,A){var e=Gn(),i=Tn(),o=Kn(),n=yg(),s=Rrt(),r=_rt(),a=vrt(),g=(I,...c)=>{if(c=e(c),c.length===0)throw new Error("wrong number of arguments");const B=c.map(C=>n.isA(C)?a(I,C):i.isA(C)?s(I,C):o.isA(C)?r(I,C):C);return B.length===1?B[0]:B};A.exports=g}}),Urt=oe({"node_modules/@jscad/modeling/src/operations/expansions/offsetGeom2.js"(t,A){var e=Tn(),i=bBA(),o=t5(),n=(s,r)=>{const a={delta:1,corners:"edge",segments:0},{delta:g,corners:I,segments:c}=Object.assign({},a,s);if(!(I==="edge"||I==="chamfer"||I==="round"))throw new Error('corners must be "edge", "chamfer", or "round"');const B=e.toOutlines(r),l=B.map(Q=>(s={delta:B.reduce((u,d)=>u+i.arePointsInside(Q,i.create(d)),0)%2===0?g:-g,corners:I,closed:!0,segments:c},o(s,Q))).reduce((Q,E)=>Q.concat(e.toSides(e.fromPoints(E))),[]);return e.create(l)};A.exports=n}}),Lrt=oe({"node_modules/@jscad/modeling/src/operations/expansions/offsetPath2.js"(t,A){var e=yg(),i=t5(),o=(n,s)=>{const r={delta:1,corners:"edge",closed:s.isClosed,segments:16},{delta:a,corners:g,closed:I,segments:c}=Object.assign({},r,n);if(!(g==="edge"||g==="chamfer"||g==="round"))throw new Error('corners must be "edge", "chamfer", or "round"');n={delta:a,corners:g,closed:I,segments:c};const B=i(n,e.toPoints(s));return e.fromPoints({closed:I},B)};A.exports=o}}),Hrt=oe({"node_modules/@jscad/modeling/src/operations/expansions/offset.js"(t,A){var e=Gn(),i=Tn(),o=yg(),n=Urt(),s=Lrt(),r=(a,...g)=>{if(g=e(g),g.length===0)throw new Error("wrong number of arguments");const I=g.map(c=>o.isA(c)?s(a,c):i.isA(c)?n(a,c):c);return I.length===1?I[0]:I};A.exports=r}}),tWA=oe({"node_modules/@jscad/modeling/src/operations/expansions/index.js"(t,A){A.exports={expand:KBA(),offset:Hrt()}}}),i5=oe({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeLinearGeom2.js"(t,A){var e=Tg(),i=ho(),o=Tn(),n=PN(),s=e5(),r=(a,g)=>{const I={offset:[0,0,1],twistAngle:0,twistSteps:12,repair:!0};let{offset:c,twistAngle:B,twistSteps:C,repair:l}=Object.assign({},I,a);if(C<1)throw new Error("twistSteps must be 1 or more");B===0&&(C=1);const Q=i.clone(c),E=o.toSides(g);if(E.length===0)throw new Error("the given geometry cannot be empty");const h=n.fromSides(E);Q[2]<0&&n.reverse(h,h);const u=e.create(),d=(f,m,b)=>{const D=m/C*B,x=i.scale(i.create(),Q,m/C);return e.multiply(u,e.fromZRotation(u,D),e.fromTranslation(e.create(),x)),n.transform(u,b)};return a={numberOfSlices:C+1,capStart:!0,capEnd:!0,repair:l,callback:d},s(a,h)};A.exports=r}}),Yrt=oe({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeLinearPath2.js"(t,A){var e=Tn(),i=yg(),o=i5(),n=(s,r)=>{if(!r.isClosed)throw new Error("extruded path must be closed");const a=i.toPoints(r),g=e.fromPoints(a);return o(s,g)};A.exports=n}}),Jrt=oe({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeLinear.js"(t,A){var e=Gn(),i=Tn(),o=yg(),n=i5(),s=Yrt(),r=(a,...g)=>{const I={height:1,twistAngle:0,twistSteps:1,repair:!0},{height:c,twistAngle:B,twistSteps:C,repair:l}=Object.assign({},I,a);if(g=e(g),g.length===0)throw new Error("wrong number of arguments");a={offset:[0,0,c],twistAngle:B,twistSteps:C,repair:l};const Q=g.map(E=>o.isA(E)?s(a,E):i.isA(E)?n(a,E):E);return Q.length===1?Q[0]:Q};A.exports=r}}),Trt=oe({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeRectangularPath2.js"(t,A){var e=yg(),i=KBA(),o=i5(),n=(s,r)=>{const a={size:1,height:1},{size:g,height:I}=Object.assign({},a,s);if(s.delta=g,s.offset=[0,0,I],e.toPoints(r).length===0)throw new Error("the given geometry cannot be empty");const B=i(s,r);return o(s,B)};A.exports=n}}),Krt=oe({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeRectangularGeom2.js"(t,A){var{area:e}=qU(),i=Tn(),o=yg(),n=KBA(),s=i5(),r=(a,g)=>{const I={size:1,height:1},{size:c,height:B}=Object.assign({},I,a);a.delta=c,a.offset=[0,0,B];const C=i.toOutlines(g);if(C.length===0)throw new Error("the given geometry cannot be empty");const Q=C.map(h=>(e(h)<0&&h.reverse(),n(a,o.fromPoints({closed:!0},h)))).reduce((h,u)=>h.concat(i.toSides(u)),[]),E=i.create(Q);return s(a,E)};A.exports=r}}),qrt=oe({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeRectangular.js"(t,A){var e=Gn(),i=Tn(),o=yg(),n=Trt(),s=Krt(),r=(a,...g)=>{const I={size:1,height:1},{size:c,height:B}=Object.assign({},I,a);if(g=e(g),g.length===0)throw new Error("wrong number of arguments");if(c<=0)throw new Error("size must be positive");if(B<=0)throw new Error("height must be positive");const C=g.map(l=>o.isA(l)?n(a,l):i.isA(l)?s(a,l):l);return C.length===1?C[0]:C};A.exports=r}}),Prt=oe({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeHelical.js"(t,A){var{TAU:e}=lr(),i=Tg(),o=Tn(),n=e5(),s=PN(),r=(a,g)=>{const I={angle:e,startAngle:0,pitch:10,height:0,endOffset:0,segmentsPerRotation:32};let{angle:c,startAngle:B,pitch:C,height:l,endOffset:Q,segmentsPerRotation:E}=Object.assign({},I,a);if(l!=0&&(C=l/(c/e)),E<3)throw new Error("The number of segments per rotation needs to be at least 3.");const u=o.toSides(g);if(u.length===0)throw new Error("The given geometry cannot be empty");const d=u.filter(k=>k[0][0]>=0);let f=s.fromSides(u);d.length===0&&(f=s.reverse(f));const m=Math.round(E/e*Math.abs(c)),b=m>=2?m:2,D=i.create(),x=i.create(),F=(k,v,_)=>{const Y=B+c/b*v,P=Q/b*v,T=(Y-B)/e*C;return i.multiply(D,i.fromTranslation(i.create(),[P,0,T*Math.sign(c)]),i.fromXRotation(i.create(),-e/4*Math.sign(c))),i.multiply(x,i.fromZRotation(i.create(),Y),D),s.transform(x,_)};return n({numberOfSlices:b+1,callback:F},f)};A.exports=r}}),Ort=oe({"node_modules/@jscad/modeling/src/operations/extrusions/project.js"(t,A){var e=Gn(),i=FBA(),o=Gm(),n=Tg(),s=Tn(),r=Kn(),a=Xs(),g=bx(),I=eWA(),c=(C,l)=>{const Q=o.fromNormalAndPoint(o.create(),C.axis,C.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 E=g(l),h=E*E*Math.sqrt(3)/4;if(E===0)return s.create();const u=r.toPolygons(l);let d=[];for(let m=0;m<u.length;m++){const b=u[m].vertices.map(F=>o.projectionOfPoint(Q,F)),D=a.create(b),x=a.plane(D);i(Q,x)&&(a.measureArea(D)<h||d.push(D))}if(!i(Q,[0,0,1])){const m=n.fromVectorRotation(n.create(),Q,[0,0,1]);d=d.map(b=>a.transform(m,b))}d=d.sort((m,b)=>a.measureArea(b)-a.measureArea(m));const f=d.map(m=>s.fromPoints(m.vertices));return I(f)},B=(C,...l)=>{const Q={axis:[0,0,1],origin:[0,0,0]},{axis:E,origin:h}=Object.assign({},Q,C);if(l=e(l),l.length===0)throw new Error("wrong number of arguments");C={axis:E,origin:h};const u=l.map(d=>r.isA(d)?c(C,d):d);return u.length===1?u[0]:u};A.exports=B}}),jU=oe({"node_modules/@jscad/modeling/src/operations/extrusions/index.js"(t,A){A.exports={extrudeFromSlices:e5(),extrudeLinear:Jrt(),extrudeRectangular:qrt(),extrudeRotate:O8A(),extrudeHelical:Prt(),project:Ort(),slice:PN()}}}),qBA=oe({"node_modules/@jscad/modeling/src/operations/hulls/hullPoints2.js"(t,A){var e=Bs(),i=s=>{let r=e.fromValues(1/0,1/0);s.forEach(I=>{(I[1]<r[1]||I[1]===r[1]&&I[0]<r[0])&&(r=I)});const a=[];s.forEach(I=>{const c=n(I[1]-r[1],I[0]-r[0]),B=e.squaredDistance(I,r);a.push({point:I,angle:c,distSq:B})}),a.sort((I,c)=>I.angle!==c.angle?I.angle-c.angle:I.distSq-c.distSq);const g=[];return a.forEach(I=>{let c=g.length;for(;c>1&&o(g[c-2],g[c-1],I.point)<=Number.EPSILON;)g.pop(),c=g.length;g.push(I.point)}),g},o=(s,r,a)=>(r[0]-s[0])*(a[1]-s[1])-(r[1]-s[1])*(a[0]-s[0]),n=(s,r)=>s===0&&r===0?-1/0:-r/s;A.exports=i}}),PBA=oe({"node_modules/@jscad/modeling/src/operations/hulls/toUniquePoints.js"(t,A){var e=Tn(),i=Kn(),o=yg(),n=s=>{const r=new Set,a=[],g=I=>{const c=I.toString();r.has(c)||(a.push(I),r.add(c))};return s.forEach(I=>{e.isA(I)?e.toPoints(I).forEach(g):i.isA(I)?i.toPoints(I).forEach(c=>c.forEach(g)):o.isA(I)&&o.toPoints(I).forEach(g)}),a};A.exports=n}}),Wrt=oe({"node_modules/@jscad/modeling/src/operations/hulls/hullPath2.js"(t,A){var e=Gn(),i=yg(),o=qBA(),n=PBA(),s=(...r)=>{r=e(r);const a=n(r),g=o(a);return i.fromPoints({closed:!0},g)};A.exports=s}}),Zrt=oe({"node_modules/@jscad/modeling/src/operations/hulls/hullGeom2.js"(t,A){var e=Gn(),i=Tn(),o=qBA(),n=PBA(),s=(...r)=>{r=e(r);const a=n(r),g=o(a);return g.length<3?i.create():i.fromPoints(g)};A.exports=s}}),iWA=oe({"node_modules/@jscad/modeling/src/operations/hulls/hullPoints3.js"(t,A){var e=Xs(),i=e8A(),o=n=>i(n,{skipTriangulation:!0}).map(a=>{const g=a.map(I=>n[I]);return e.create(g)});A.exports=o}}),Vrt=oe({"node_modules/@jscad/modeling/src/operations/hulls/hullGeom3.js"(t,A){var e=Gn(),i=Kn(),o=PBA(),n=iWA(),s=(...r)=>{r=e(r);const a=o(r);return a.length===0?i.create():i.create(n(a))};A.exports=s}}),oWA=oe({"node_modules/@jscad/modeling/src/operations/hulls/hull.js"(t,A){var e=Gn(),i=ZU(),o=Tn(),n=Kn(),s=yg(),r=Wrt(),a=Zrt(),g=Vrt(),I=(...c)=>{if(c=e(c),c.length===0)throw new Error("wrong number of arguments");if(!i(c))throw new Error("only hulls of the same type are supported");const B=c[0];return s.isA(B)?r(c):o.isA(B)?a(c):n.isA(B)?g(c):B};A.exports=I}}),jrt=oe({"node_modules/@jscad/modeling/src/operations/hulls/hullChain.js"(t,A){var e=Gn(),i=TBA(),o=oWA(),n=(...s)=>{if(s=e(s),s.length<2)throw new Error("wrong number of arguments");const r=[];for(let a=1;a<s.length;a++)r.push(o(s[a-1],s[a]));return i(r)};A.exports=n}}),zrt=oe({"node_modules/@jscad/modeling/src/operations/hulls/index.js"(t,A){A.exports={hull:oWA(),hullChain:jrt(),hullPoints2:qBA(),hullPoints3:iWA()}}}),nWA=oe({"node_modules/@jscad/modeling/src/operations/modifiers/snapPolygons.js"(t,A){var e=ho(),i=Xs(),o=(s,r)=>{const a=Math.abs(i.measureArea(r));return Number.isFinite(a)&&a>s},n=(s,r)=>{let a=r.map(I=>{const c=I.vertices.map(l=>e.snap(e.create(),l,s)),B=[];for(let l=0;l<c.length;l++){const Q=(l+1)%c.length;e.equals(c[l],c[Q])||B.push(c[l])}const C=i.create(B);return I.color&&(C.color=I.color),C});const g=s*s*Math.sqrt(3)/4;return a=a.filter(I=>o(g,I)),a};A.exports=n}}),Xrt=oe({"node_modules/@jscad/modeling/src/operations/modifiers/mergePolygons.js"(t,A){var e=FBA(),i=ho(),o=Xs(),n=h=>{const u=o.toPoints(h),d=[];for(let f=0;f<u.length;f++){const m=(f+1)%u.length,b={v1:u[f],v2:u[m]};d.push(b)}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=(h,u)=>{const d=`${u.v1}:${u.v2}`;h.set(d,u)},r=(h,u)=>{const d=`${u.v1}:${u.v2}`;h.delete(d)},a=(h,u)=>{const d=`${u.v2}:${u.v1}`;return h.get(d)},g=(h,u,d)=>{let f=h.prev.v1,m=h.prev.v2,b=u.next.v2;const D=B(f,m,b,d);f=u.prev.v1,m=u.prev.v2,b=h.next.v2;const x=B(f,m,b,d);return[D,x]},I=i.create(),c=i.create(),B=(h,u,d,f)=>{const m=i.subtract(I,u,h),b=i.subtract(c,d,u);return i.cross(m,m,b),i.dot(m,f)},C=h=>{let u;const d=[];for(;h.next;){const f=h.next;d.push(h.v1),h.v1=null,h.v2=null,h.next=null,h.prev=null,h=f}return d.length>0&&(u=o.create(d)),u},l=h=>{if(h.length<2)return h;const u=h[0].plane,d=h.slice(),f=new Map;for(;d.length>0;){const b=d.shift(),D=n(b);for(let x=0;x<D.length;x++){const F=D[x],k=a(f,F);if(k){const v=g(F,k,u);if(v[0]>=0&&v[1]>=0){const _=k.next,Y=F.next;F.prev.next=k.next,F.next.prev=k.prev,k.prev.next=F.next,k.next.prev=F.prev,F.v1=null,F.v2=null,F.next=null,F.prev=null,r(f,k),k.v1=null,k.v2=null,k.next=null,k.prev=null;const P=(T,O,W)=>{const AA={v1:W.v1,v2:O.v2,next:O.next,prev:W.prev};W.prev.next=AA,O.next.prev=AA,r(T,O),O.v1=null,O.v2=null,O.next=null,O.prev=null,r(T,W),W.v1=null,W.v2=null,W.next=null,W.prev=null};v[0]===0&&P(f,_,_.prev),v[1]===0&&P(f,Y,Y.prev)}}else F.next&&s(f,F)}}const m=[];return f.forEach(b=>{const D=C(b);D&&m.push(D)}),f.clear(),m},Q=(h,u)=>Math.abs(h[3]-u[3])<15e-8?e(h,u):!1,E=(h,u)=>{const d=[];u.forEach(m=>{const b=d.find(D=>Q(D[0],o.plane(m)));b?b[1].push(m):d.push([o.plane(m),[m]])});let f=[];return d.forEach(m=>{const b=m[1],D=l(b);f=f.concat(D)}),f};A.exports=E}}),$rt=oe({"node_modules/@jscad/modeling/src/operations/modifiers/insertTjunctions.js"(t,A){var e=lr(),i=ho(),o=Xs(),n=g=>`${g}`,s=(g,I,c,B,C,l)=>{const Q=n(B),E=n(C),h=`${Q}/${E}`,u=`${E}/${Q}`;if(g.has(u))return r(g,I,c,C,B,null),null;const d={vertex0:B,vertex1:C,polygonindex:l};return g.has(h)?g.get(h).push(d):g.set(h,[d]),I.has(Q)?I.get(Q).push(h):I.set(Q,[h]),c.has(E)?c.get(E).push(h):c.set(E,[h]),h},r=(g,I,c,B,C,l)=>{const Q=n(B),E=n(C),h=`${Q}/${E}`;let u=-1;const d=g.get(h);for(let f=0;f<d.length;f++){const m=d[f];let b=n(m.vertex0);if(b===Q&&(b=n(m.vertex1),b===E&&!(l!==null&&m.polygonindex!==l))){u=f;break}}d.splice(u,1),d.length===0&&g.delete(h),u=I.get(Q).indexOf(h),I.get(Q).splice(u,1),I.get(Q).length===0&&I.delete(Q),u=c.get(E).indexOf(h),c.get(E).splice(u,1),c.get(E).length===0&&c.delete(E)},a=g=>{const I=new Map;for(let c=0;c<g.length;c++){const B=g[c],C=B.vertices.length;if(C>=3){let l=B.vertices[0],Q=n(l);for(let E=0;E<C;E++){let h=E+1;h===C&&(h=0);const u=B.vertices[h],d=n(u),f=`${Q}/${d}`,m=`${d}/${Q}`;if(I.has(m)){const b=I.get(m);b.splice(-1,1),b.length===0&&I.delete(m)}else{const b={vertex0:l,vertex1:u,polygonindex:c};I.has(f)?I.get(f).push(b):I.set(f,[b])}l=u,Q=d}}else console.warn("warning: invalid polygon found during insertTjunctions")}if(I.size>0){const c=new Map,B=new Map,C=new Map;for(const[Q,E]of I)C.set(Q,!0),E.forEach(h=>{const u=n(h.vertex0),d=n(h.vertex1);c.has(u)?c.get(u).push(Q):c.set(u,[Q]),B.has(d)?B.get(d).push(Q):B.set(d,[Q])});const l=g.slice(0);for(;I.size!==0;){for(const E of I.keys())C.set(E,!0);let Q=!1;for(;;){const E=Array.from(C.keys());if(E.length===0)break;const h=E[0];let u=!0;if(I.has(h)){const f=I.get(h)[0];for(let m=0;m<2;m++){const b=m===0?f.vertex0:f.vertex1,D=m===0?f.vertex1:f.vertex0,x=n(b),F=n(D);let k=[];m===0?B.has(x)&&(k=B.get(x)):c.has(x)&&(k=c.get(x));for(let v=0;v<k.length;v++){const _=k[v],Y=I.get(_)[0],P=m===0?Y.vertex0:Y.vertex1;if(m===0?Y.vertex1:Y.vertex0,n(P)===F){r(I,c,B,b,D,null),r(I,c,B,D,b,null),u=!1,m=2,Q=!0;break}else{const O=b,W=D,AA=P,oA=i.subtract(i.create(),AA,O),IA=i.dot(i.subtract(i.create(),W,O),oA)/i.dot(oA,oA);if(IA>0&&IA<1){const tA=i.scale(i.create(),oA,IA);if(i.add(tA,tA,O),i.squaredDistance(tA,W)<e.EPS*e.EPS){const aA=Y.polygonindex,dA=l[aA],SA=n(Y.vertex1);let FA=-1;for(let uA=0;uA<dA.vertices.length;uA++)if(n(dA.vertices[uA])===SA){FA=uA;break}const MA=dA.vertices.slice(0);MA.splice(FA,0,D);const qA=o.create(MA);l[aA]=qA,r(I,c,B,Y.vertex0,Y.vertex1,aA);const CA=s(I,c,B,Y.vertex0,D,aA),GA=s(I,c,B,D,Y.vertex1,aA);CA!==null&&C.set(CA,!0),GA!==null&&C.set(GA,!0),u=!1,m=2,Q=!0;break}}}}}}u&&C.delete(h)}if(!Q)break}g=l}return I.clear(),g};A.exports=a}}),Aat=oe({"node_modules/@jscad/modeling/src/operations/modifiers/triangulatePolygons.js"(t,A){var e=ho(),i=Xs(),o=(s,r,a)=>{const g=r.vertices.length;if(g>3){if(g>4){const B=[0,0,0];r.vertices.forEach(C=>e.add(B,B,C)),e.snap(B,e.divide(B,B,[g,g,g]),s);for(let C=0;C<g;C++){const l=i.create([B,r.vertices[C],r.vertices[(C+1)%g]]);r.color&&(l.color=r.color),a.push(l)}return}const I=i.create([r.vertices[0],r.vertices[1],r.vertices[2]]),c=i.create([r.vertices[0],r.vertices[2],r.vertices[3]]);r.color&&(I.color=r.color,c.color=r.color),a.push(I,c);return}a.push(r)},n=(s,r)=>{const a=[];return r.forEach(g=>{o(s,g,a)}),a};A.exports=n}}),eat=oe({"node_modules/@jscad/modeling/src/operations/modifiers/generalize.js"(t,A){var e=Gn(),i=bx(),o=Tn(),n=Kn(),s=yg(),r=nWA(),a=Xrt(),g=$rt(),I=Aat(),c=(Q,E)=>E,B=(Q,E)=>E,C=(Q,E)=>{const h={snap:!1,simplify:!1,triangulate:!1},{snap:u,simplify:d,triangulate:f}=Object.assign({},h,Q),m=i(E);let b=n.toPolygons(E);u&&(b=r(m,b)),d&&(b=a(m,b)),f&&(b=g(b),b=I(m,b));const D=Object.assign({},E);return D.polygons=b,D},l=(Q,...E)=>{if(E=e(E),E.length===0)throw new Error("wrong number of arguments");const h=E.map(u=>{if(s.isA(u))return c(Q,u);if(o.isA(u))return B(Q,u);if(n.isA(u))return C(Q,u);throw new Error("invalid geometry")});return h.length===1?h[0]:h};A.exports=l}}),tat=oe({"node_modules/@jscad/modeling/src/operations/modifiers/snap.js"(t,A){var e=Gn(),i=Bs(),o=Tn(),n=Kn(),s=yg(),r=bx(),a=nWA(),g=C=>{const l=r(C),E=s.toPoints(C).map(h=>i.snap(i.create(),h,l));return s.create(E)},I=C=>{const l=r(C);let E=o.toSides(C).map(h=>[i.snap(i.create(),h[0],l),i.snap(i.create(),h[1],l)]);return E=E.filter(h=>!i.equals(h[0],h[1])),o.create(E)},c=C=>{const l=r(C),Q=n.toPolygons(C),E=a(l,Q);return n.create(E)},B=(...C)=>{if(C=e(C),C.length===0)throw new Error("wrong number of arguments");const l=C.map(Q=>s.isA(Q)?g(Q):o.isA(Q)?I(Q):n.isA(Q)?c(Q):Q);return l.length===1?l[0]:l};A.exports=B}}),iat=oe({"node_modules/@jscad/modeling/src/operations/modifiers/index.js"(t,A){A.exports={generalize:eat(),snap:tat(),retessellate:VU()}}}),oat=oe({"node_modules/@jscad/modeling/src/utils/padArrayToLength.js"(t,A){var e=(i,o,n)=>{for(i=i.slice();i.length<n;)i.push(o);return i};A.exports=e}}),nat=oe({"node_modules/@jscad/modeling/src/operations/transforms/align.js"(t,A){var e=Gn(),i=oat(),o=MBA(),{translate:n}=tF(),s=I=>{if(!Array.isArray(I.modes)||I.modes.length>3)throw new Error("align(): modes must be an array of length <= 3");if(I.modes=i(I.modes,"none",3),I.modes.filter(c=>["center","max","min","none"].includes(c)).length!==3)throw new Error('align(): all modes must be one of "center", "max" or "min"');if(!Array.isArray(I.relativeTo)||I.relativeTo.length>3)throw new Error("align(): relativeTo must be an array of length <= 3");if(I.relativeTo=i(I.relativeTo,0,3),I.relativeTo.filter(c=>Number.isFinite(c)||c==null).length!==3)throw new Error("align(): all relativeTo values must be a number, or null.");if(typeof I.grouped!="boolean")throw new Error("align(): grouped must be a boolean value.");return I},r=(I,c,B)=>{for(let C=0;C<3;C++)I[C]==null&&(c[C]==="center"?I[C]=(B[0][C]+B[1][C])/2:c[C]==="max"?I[C]=B[1][C]:c[C]==="min"&&(I[C]=B[0][C]));return I},a=(I,c,B)=>{const C=o(I),l=[0,0,0];for(let Q=0;Q<3;Q++)c[Q]==="center"?l[Q]=B[Q]-(C[0][Q]+C[1][Q])/2:c[Q]==="max"?l[Q]=B[Q]-C[1][Q]:c[Q]==="min"&&(l[Q]=B[Q]-C[0][Q]);return n(l,I)},g=(I,...c)=>{I=Object.assign({},{modes:["center","center","min"],relativeTo:[0,0,0],grouped:!1},I),I=s(I);let{modes:C,relativeTo:l,grouped:Q}=I;if(c=e(c),c.length===0)throw new Error("align(): No geometries were provided to act upon");if(l.filter(E=>E==null).length){const E=o(c);l=r(l,C,E)}return Q?c=a(c,C,l):c=c.map(E=>a(E,C,l)),c.length===1?c[0]:c};A.exports=g}}),o5=oe({"node_modules/@jscad/modeling/src/operations/transforms/center.js"(t,A){var e=Gn(),i=Tn(),o=Kn(),n=yg(),s=AF(),{translate:r}=tF(),a=(C,l)=>{const Q={axes:[!0,!0,!0],relativeTo:[0,0,0]},{axes:E,relativeTo:h}=Object.assign({},Q,C),u=s(l),d=[0,0,0];return E[0]&&(d[0]=h[0]-(u[0][0]+(u[1][0]-u[0][0])/2)),E[1]&&(d[1]=h[1]-(u[0][1]+(u[1][1]-u[0][1])/2)),E[2]&&(d[2]=h[2]-(u[0][2]+(u[1][2]-u[0][2])/2)),r(d,l)},g=(C,...l)=>{const Q={axes:[!0,!0,!0],relativeTo:[0,0,0]},{axes:E,relativeTo:h}=Object.assign({},Q,C);if(l=e(l),l.length===0)throw new Error("wrong number of arguments");if(h.length!==3)throw new Error("relativeTo must be an array of length 3");C={axes:E,relativeTo:h};const u=l.map(d=>n.isA(d)||i.isA(d)||o.isA(d)?a(C,d):d);return u.length===1?u[0]:u},I=(...C)=>g({axes:[!0,!1,!1]},C),c=(...C)=>g({axes:[!1,!0,!1]},C),B=(...C)=>g({axes:[!1,!1,!0]},C);A.exports={center:g,centerX:I,centerY:c,centerZ:B}}}),n5=oe({"node_modules/@jscad/modeling/src/operations/transforms/scale.js"(t,A){var e=Gn(),i=Tg(),o=Tn(),n=Kn(),s=yg(),r=(c,...B)=>{if(!Array.isArray(c))throw new Error("factors must be an array");if(B=e(B),B.length===0)throw new Error("wrong number of arguments");for(c=c.slice();c.length<3;)c.push(1);if(c[0]<=0||c[1]<=0||c[2]<=0)throw new Error("factors must be positive");const C=i.fromScaling(i.create(),c),l=B.map(Q=>s.isA(Q)?s.transform(C,Q):o.isA(Q)?o.transform(C,Q):n.isA(Q)?n.transform(C,Q):Q);return l.length===1?l[0]:l},a=(c,...B)=>r([c,1,1],B),g=(c,...B)=>r([1,c,1],B),I=(c,...B)=>r([1,1,c],B);A.exports={scale:r,scaleX:a,scaleY:g,scaleZ:I}}}),sat=oe({"node_modules/@jscad/modeling/src/operations/transforms/transform.js"(t,A){var e=Gn(),i=Tn(),o=Kn(),n=yg(),s=(r,...a)=>{if(a=e(a),a.length===0)throw new Error("wrong number of arguments");const g=a.map(I=>n.isA(I)?n.transform(r,I):i.isA(I)?i.transform(r,I):o.isA(I)?o.transform(r,I):I);return g.length===1?g[0]:g};A.exports=s}}),iF=oe({"node_modules/@jscad/modeling/src/operations/transforms/index.js"(t,A){A.exports={align:nat(),center:o5().center,centerX:o5().centerX,centerY:o5().centerY,centerZ:o5().centerZ,mirror:OU().mirror,mirrorX:OU().mirrorX,mirrorY:OU().mirrorY,mirrorZ:OU().mirrorZ,rotate:WU().rotate,rotateX:WU().rotateX,rotateY:WU().rotateY,rotateZ:WU().rotateZ,scale:n5().scale,scaleX:n5().scaleX,scaleY:n5().scaleY,scaleZ:n5().scaleZ,transform:sat(),translate:tF().translate,translateX:tF().translateX,translateY:tF().translateY,translateZ:tF().translateZ}}}),s5=oe({"node_modules/@jscad/modeling/src/index.js"(t,A){A.exports={colors:XO(),curves:tst(),geometries:xBA(),maths:bst(),measurements:_st(),primitives:xx(),text:UBA(),utils:j8A(),booleans:ON(),expansions:tWA(),extrusions:jU(),hulls:zrt(),modifiers:iat(),transforms:iF()}}}),sWA=oe({"node_modules/jscad-planner/dist/index.cjs"(t,A){var e=Object.defineProperty,i=Object.getOwnPropertyDescriptor,o=Object.getOwnPropertyNames,n=Object.prototype.hasOwnProperty,s=(B,C)=>{for(var l in C)e(B,l,{get:C[l],enumerable:!0})},r=(B,C,l,Q)=>{if(C&&typeof C=="object"||typeof C=="function")for(let E of o(C))!n.call(B,E)&&E!==l&&e(B,E,{get:()=>C[E],enumerable:!(Q=i(C,E))||Q.enumerable});return B},a=B=>r(e({},"__esModule",{value:!0}),B),g={};s(g,{executeJscadOperations:()=>c,jscadPlanner:()=>I}),A.exports=a(g);var I={booleans:{intersect:(...B)=>({type:"intersect",shapes:B}),subtract:(...B)=>({type:"subtract",shapes:B}),union:(...B)=>({type:"union",shapes:B})},hulls:{hull:(...B)=>({type:"hull",shapes:B.flat()}),hullChain:(...B)=>({type:"hullChain",shapes:B.flat()})},colors:{colorize:(B,C)=>({type:"colorize",color:B,shape:C})},primitives:{cube:B=>({type:"cube",...B}),sphere:B=>({type:"sphere",...B}),cylinder:B=>({type:"cylinder",...B}),polygon:B=>({type:"polygon",...B}),cuboid:B=>({type:"cuboid",...B}),roundedCuboid:B=>({type:"roundedCuboid",...B})},transforms:{rotate:(B,C)=>({type:"rotate",angles:B,shape:C}),scale:(B,C)=>({type:"scale",factors:B,shape:C}),translate:(B,C)=>({type:"translate",vector:B,shape:C})},extrusions:{extrudeLinear:(B,C)=>({type:"extrudeLinear",options:B,shape:C}),extrudeRotate:(B,C)=>({type:"extrudeRotate",options:B,shape:C})},maths:{vec2:{create:(B,C)=>[B,C],fromValues:(B,C)=>[B,C]},vec3:{create:(B,C,l)=>[B,C,l],fromValues:(B,C,l)=>[B,C,l]}},geometries:{geom2:{create:B=>({type:"createGeom2",points:B})},geom3:{create:B=>({type:"createGeom3",polygons:B})},path2:{create:B=>({type:"createPath2",points:B})}},measurements:{measureBoundingBox:B=>({type:"measureBoundingBox",shape:B}),measureArea:B=>({type:"measureArea",shape:B}),measureVolume:B=>({type:"measureVolume",shape:B})},utils:{degToRad:B=>B*Math.PI/180,radToDeg:B=>B*180/Math.PI}},c=(B,C)=>{if(Array.isArray(C)&&C.length===1)return c(B,C[0]);if(Array.isArray(C))throw new Error("executeJscadOperations currently doesn't support Array<JscadOperation>, try adding a root union or or executing each element individually");const l=h=>c(B,h),{type:Q,...E}=C;switch(Q){case"intersect":return B.booleans.intersect(...C.shapes.map(l));case"subtract":return B.booleans.subtract(...C.shapes.map(l));case"union":return B.booleans.union(...C.shapes.map(l));case"hull":return B.hulls.hull(...C.shapes.map(l));case"hullChain":return B.hulls.hullChain(...C.shapes.map(l));case"colorize":return B.colors.colorize(C.color,l(C.shape));case"cube":return B.primitives.cube(E);case"sphere":return B.primitives.sphere(E);case"cylinder":return B.primitives.cylinder(E);case"polygon":return B.primitives.polygon(E);case"cuboid":return B.primitives.cuboid(E);case"roundedCuboid":return B.primitives.roundedCuboid(E);case"rotate":return B.transforms.rotate(C.angles,l(C.shape));case"scale":return B.transforms.scale(C.factors,l(C.shape));case"translate":return B.transforms.translate(C.vector,l(C.shape));case"extrudeLinear":return B.extrusions.extrudeLinear(C.options,l(C.shape));case"extrudeRotate":return B.extrusions.extrudeRotate(C.options,l(C.shape));case"createGeom2":return B.geometries.geom2.create(C.points);case"createGeom3":return B.geometries.geom3.create(C.polygons);case"createPath2":return B.geometries.path2.create(C.points);case"measureBoundingBox":return B.measurements.measureBoundingBox(l(C.shape));case"measureArea":return B.measurements.measureArea(l(C.shape));case"measureVolume":return B.measurements.measureVolume(l(C.shape));case"degToRad":return B.utils.degToRad(C.degrees);case"radToDeg":return B.utils.radToDeg(C.radians);default:throw C.type===void 0?new Error(`Operation type is undefined. This usually means the operation object is malformed or not properly initialized. Operation: ${JSON.stringify(C,null,2).slice(0,200)}...`):new Error(`Unsupported operation type: ${C.type}. Operation: ${JSON.stringify(C,null,2)}`)}}}}),rat=oe({"node_modules/ms/index.js"(t,A){var e=1e3,i=e*60,o=i*60,n=o*24,s=n*7,r=n*365.25;A.exports=function(B,C){C=C||{};var l=typeof B;if(l==="string"&&B.length>0)return a(B);if(l==="number"&&isFinite(B))return C.long?I(B):g(B);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(B))};function a(B){if(B=String(B),!(B.length>100)){var C=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(B);if(C){var l=parseFloat(C[1]),Q=(C[2]||"ms").toLowerCase();switch(Q){case"years":case"year":case"yrs":case"yr":case"y":return l*r;case"weeks":case"week":case"w":return l*s;case"days":case"day":case"d":return l*n;case"hours":case"hour":case"hrs":case"hr":case"h":return l*o;case"minutes":case"minute":case"mins":case"min":case"m":return l*i;case"seconds":case"second":case"secs":case"sec":case"s":return l*e;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return l;default:return}}}}function g(B){var C=Math.abs(B);return C>=n?Math.round(B/n)+"d":C>=o?Math.round(B/o)+"h":C>=i?Math.round(B/i)+"m":C>=e?Math.round(B/e)+"s":B+"ms"}function I(B){var C=Math.abs(B);return C>=n?c(B,C,n,"day"):C>=o?c(B,C,o,"hour"):C>=i?c(B,C,i,"minute"):C>=e?c(B,C,e,"second"):B+" ms"}function c(B,C,l,Q){var E=C>=l*1.5;return Math.round(B/l)+" "+Q+(E?"s":"")}}}),aat=oe({"node_modules/debug/src/common.js"(t,A){function e(i){n.debug=n,n.default=n,n.coerce=c,n.disable=g,n.enable=r,n.enabled=I,n.humanize=rat(),n.destroy=B,Object.keys(i).forEach(C=>{n[C]=i[C]}),n.names=[],n.skips=[],n.formatters={};function o(C){let l=0;for(let Q=0;Q<C.length;Q++)l=(l<<5)-l+C.charCodeAt(Q),l|=0;return n.colors[Math.abs(l)%n.colors.length]}n.selectColor=o;function n(C){let l,Q=null,E,h;function u(...d){if(!u.enabled)return;const f=u,m=Number(new Date),b=m-(l||m);f.diff=b,f.prev=l,f.curr=m,l=m,d[0]=n.coerce(d[0]),typeof d[0]!="string"&&d.unshift("%O");let D=0;d[0]=d[0].replace(/%([a-zA-Z%])/g,(F,k)=>{if(F==="%%")return"%";D++;const v=n.formatters[k];if(typeof v=="function"){const _=d[D];F=v.call(f,_),d.splice(D,1),D--}return F}),n.formatArgs.call(f,d),(f.log||n.log).apply(f,d)}return u.namespace=C,u.useColors=n.useColors(),u.color=n.selectColor(C),u.extend=s,u.destroy=n.destroy,Object.defineProperty(u,"enabled",{enumerable:!0,configurable:!1,get:()=>Q!==null?Q:(E!==n.namespaces&&(E=n.namespaces,h=n.enabled(C)),h),set:d=>{Q=d}}),typeof n.init=="function"&&n.init(u),u}function s(C,l){const Q=n(this.namespace+(typeof l>"u"?":":l)+C);return Q.log=this.log,Q}function r(C){n.save(C),n.namespaces=C,n.names=[],n.skips=[];const l=(typeof C=="string"?C:"").trim().replace(/\s+/g,",").split(",").filter(Boolean);for(const Q of l)Q[0]==="-"?n.skips.push(Q.slice(1)):n.names.push(Q)}function a(C,l){let Q=0,E=0,h=-1,u=0;for(;Q<C.length;)if(E<l.length&&(l[E]===C[Q]||l[E]==="*"))l[E]==="*"?(h=E,u=Q,E++):(Q++,E++);else if(h!==-1)E=h+1,u++,Q=u;else return!1;for(;E<l.length&&l[E]==="*";)E++;return E===l.length}function g(){const C=[...n.names,...n.skips.map(l=>"-"+l)].join(",");return n.enable(""),C}function I(C){for(const l of n.skips)if(a(C,l))return!1;for(const l of n.names)if(a(C,l))return!0;return!1}function c(C){return C instanceof Error?C.stack||C.message:C}function B(){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 n.enable(n.load()),n}A.exports=e}}),gat=oe({"node_modules/debug/src/browser.js"(t,A){t.formatArgs=i,t.save=o,t.load=n,t.useColors=e,t.storage=s(),t.destroy=(()=>{let a=!1;return()=>{a||(a=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),t.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"];function e(){if(typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs))return!0;if(typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))return!1;let a;return typeof document<"u"&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent&&(a=navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/))&&parseInt(a[1],10)>=31||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)}function i(a){if(a[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+a[0]+(this.useColors?"%c ":" ")+"+"+A.exports.humanize(this.diff),!this.useColors)return;const g="color: "+this.color;a.splice(1,0,g,"color: inherit");let I=0,c=0;a[0].replace(/%[a-zA-Z%]/g,B=>{B!=="%%"&&(I++,B==="%c"&&(c=I))}),a.splice(c,0,g)}t.log=console.debug||console.log||(()=>{});function o(a){try{a?t.storage.setItem("debug",a):t.storage.removeItem("debug")}catch{}}function n(){let a;try{a=t.storage.getItem("debug")||t.storage.getItem("DEBUG")}catch{}return!a&&typeof dBA<"u"&&"env"in dBA&&(a=dBA.env.DEBUG),a}function s(){try{return localStorage}catch{}}A.exports=aat()(t);var{formatters:r}=A.exports;r.j=function(a){try{return JSON.stringify(a)}catch(g){return"[UnexpectedJSONParseError]: "+g.message}}}}),rWA={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},aWA=$.createContext(void 0),Iat=({children:t})=>{const[A,e]=$.useState(rWA),i=$.useCallback((s,r)=>{e(a=>({...a,[s]:r}))},[]),o=$.useCallback(()=>{e(rWA)},[]),n=$.useMemo(()=>({visibility:A,setLayerVisibility:i,resetToDefaults:o}),[A,i,o]);return V.jsx(aWA.Provider,{value:n,children:t})},WN=()=>{const t=$.useContext(aWA);if(!t)throw new Error("useLayerVisibility must be used within a LayerVisibilityProvider");return t},gWA=$.createContext(null),ku=()=>{const t=$.useContext(gWA);if(!t)throw new Error("useThree must be used within a ThreeProvider");return t},zU=(t,A=[])=>{const{addFrameListener:e,removeFrameListener:i}=ku();Xi.useEffect(()=>(e(t),()=>i(t)),[e,i,...A])},XU={clickToInteractOverlay:100,htmlElements:95,orientationCube:95,contextMenu:90,appearanceMenu:91},IWA=({children:t,position:A,style:e})=>{const{camera:i,renderer:o}=ku(),n=$.useRef(document.createElement("div")),[s,r]=$.useState(null);return $.useEffect(()=>{const a=o?.domElement.parentNode;if(a)return a.style.position!=="relative"&&a.style.position!=="absolute"&&(a.style.position="relative"),a.appendChild(n.current),r(PJ.createPortal(t,n.current)),()=>{a.contains(n.current)&&a.removeChild(n.current)}},[o,t]),zU(()=>{if(!i||!n.current||!o)return;const a=new Me(...A);a.project(i);const g=o.domElement.getBoundingClientRect(),I=Math.round((a.x+1)/2*g.width),c=Math.round((-a.y+1)/2*g.height);n.current.style.position="absolute",n.current.style.left=`${I}px`,n.current.style.top=`${c}px`,n.current.style.pointerEvents="none",n.current.style.zIndex=XU.htmlElements.toString(),e&&Object.assign(n.current.style,e)},[i,o,A,e]),s},cWA={in:25.4,inch:25.4,mil:.0254,mm:1,m:1e3,cm:10,ft:304.8,feet:304.8},mr=t=>{let A=typeof t=="number"?"mm":t.replace(/^[^a-zA-Z]+/g,"").toLowerCase();A||(A="mm");const e=typeof t=="number"?t:Number.parseFloat(t.split(A)[0]);if(A in cWA)return e*cWA[A];throw new Error(`Unsupported unit: ${A}`)},yB=mr,BWA={Hz:{baseUnit:"Hz",variants:{MHz:1e6,kHz:1e3,Hz:1}},g:{baseUnit:"g",variants:{kg:1e3,g:1}},Ω:{baseUnit:"Ω",variants:{mΩ:.001,Ω:1,kΩ:1e3,KΩ:1e3,kohm:1e3,MΩ:1e6,GΩ:1e9,TΩ:1e12}},V:{baseUnit:"V",variants:{mV:.001,V:1,kV:1e3,KV:1e3,MV:1e6,GV:1e9,TV:1e12}},A:{baseUnit:"A",variants:{µA:1e-6,mA:.001,ma:.001,A:1,kA:1e3,MA:1e6}},F:{baseUnit:"F",variants:{pF:1e-12,nF:1e-9,µF:1e-6,uF:1e-6,mF:.001,F:1}},ml:{baseUnit:"ml",variants:{ml:1,mL:1,l:1e3,L:1e3}},deg:{baseUnit:"deg",variants:{rad:180/Math.PI}},ms:{baseUnit:"ms",variants:{fs:1e-12,ps:1e-9,ns:1e-6,us:.001,µs:.001,ms:1,s:1e3}},mm:{baseUnit:"mm",variants:{nm:1e-6,µm:.001,um:.001,mm:1,cm:10,dm:100,m:1e3,km:1e6,in:25.4,ft:304.8,IN:25.4,FT:304.8,yd:914.4,mi:1609344,mil:.0254}}},OBA=new Set;for(const[t,A]of Object.entries(BWA)){OBA.add(t);for(const e of Object.keys(A.variants))OBA.add(e)}function cat(t){for(const[A,e]of Object.entries(BWA))if(t in e.variants)return{baseUnit:e.baseUnit,conversionFactor:e.variants[t]};return{baseUnit:t,conversionFactor:1}}var CWA={tera:1e12,T:1e12,giga:1e9,G:1e9,mega:1e6,M:1e6,kilo:1e3,k:1e3,deci:.1,d:.1,centi:.01,c:.01,milli:.001,m:.001,micro:1e-6,u:1e-6,µ:1e-6,nano:1e-9,n:1e-9,pico:1e-12,p:1e-12};function yw(t){if(t==null)return{parsedUnit:null,unitOfValue:null,value:null};if(typeof t=="string"&&t.match(/^-?[\d\.]+$/))return{value:Number.parseFloat(t),parsedUnit:null,unitOfValue:null};if(typeof t=="number")return{value:t,parsedUnit:null,unitOfValue:null};if(typeof t=="object"&&"x"in t&&"y"in t){const{parsedUnit:r,unitOfValue:a}=yw(t.x),g=yw(t.x),I=yw(t.y);return g.value===null||I.value===null?{parsedUnit:null,unitOfValue:null,value:null}:{parsedUnit:r,unitOfValue:a,value:{x:g.value,y:I.value}}}const e=t.toString().split("").reverse().join("").match(/[^\d\s]+/)?.[0];if(!e)throw new Error(`Could not determine unit: "${t}"`);const i=e.split("").reverse().join(""),o=t.slice(0,-i.length);if(i in CWA&&!OBA.has(i)){const r=CWA[i];return{parsedUnit:null,unitOfValue:null,value:Number.parseFloat(o)*r}}const{baseUnit:n,conversionFactor:s}=cat(i);return{parsedUnit:i,unitOfValue:n,value:s*Number.parseFloat(o)}}var WBA=H().or(WA()).transform(t=>yw(t).value),lWA=H().or(WA()).transform(t=>yw(t).value).transform(t=>Number.parseFloat(t.toPrecision(12))),Bat=H().or(WA()).transform(t=>yw(t).value),ZN=H().or(WA()).transform(t=>yw(t).value),Ae=H().or(WA()).transform(t=>yw(t).value),r5=H().or(WA()).transform(t=>yw(t).value),mt=Ae,ZBA=H().or(WA()).transform(t=>yw(t).value),VBA=H().or(WA()).transform(t=>yw(t).value),VN=VBA,Cat=H().datetime(),bd=H().or(WA()).transform(t=>typeof t=="number"?t:t.endsWith("deg")?Number.parseFloat(t.split("deg")[0]):t.endsWith("rad")?Number.parseFloat(t.split("rad")[0])*180/Math.PI:Number.parseFloat(t)),lat=WA().or(H().endsWith("mAh")).transform(t=>{if(typeof t=="string"){const A=t.replace("mAh",""),e=Number.parseFloat(A);if(Number.isNaN(e))throw new Error("Invalid capacity");return e}return t}).describe("Battery capacity in mAh"),ko=OA({x:mt,y:mt}),jBA=OA({x:mt,y:mt,z:mt}),QWA=OA({width:WA(),height:WA()}),Qat=t=>{const A="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";return Array.from({length:t},()=>A[Math.floor(Math.random()*A.length)]).join("")},Vt=t=>H().optional().default(()=>`${t}_${Qat(10)}`),oF=Bt(["top_left","top_center","top_right","center_left","center","center_right","bottom_left","bottom_center","bottom_right"]);Bt(["top_silkscreen","bottom_silkscreen","top_copper","bottom_copper","top_soldermask","bottom_soldermask","top_fabrication_note","bottom_fabrication_note","inner1_copper","inner2_copper","inner3_copper","inner4_copper","inner5_copper","inner6_copper"]);var Eat=Bt(["jlcpcb","macrofab","pcbway","digikey","mouser","lcsc"]),wB=OA({type:xA("source_component"),ftype:H().optional(),source_component_id:H(),name:H(),manufacturer_part_number:H().optional(),supplier_part_numbers:_a(Eat,be(H())).optional(),display_value:H().optional(),are_pins_interchangeable:ce().optional(),internally_connected_source_port_ids:be(be(H())).optional(),source_group_id:H().optional(),subcircuit_id:H().optional()}),EWA=wB.extend({ftype:xA("simple_capacitor"),capacitance:lWA,max_voltage_rating:ZN.optional(),display_capacitance:H().optional(),max_decoupling_trace_length:mt.optional()}),hWA=wB.extend({ftype:xA("simple_resistor"),resistance:WBA,display_resistance:H().optional()}),zBA=wB.extend({ftype:xA("simple_diode")}),hat=wB.extend({ftype:xA("simple_fiducial")}),uWA=zBA.extend({ftype:xA("simple_led"),color:H().optional(),wavelength:H().optional()}),uat=wB.extend({ftype:xA("simple_ground")}),dWA=wB.extend({ftype:xA("simple_chip")}),pWA=wB.extend({ftype:xA("simple_power_source"),voltage:ZN}),dat=wB.extend({ftype:xA("simple_fuse"),current_rating_amps:WA().describe("Nominal current in amps the fuse is rated for"),voltage_rating_volts:WA().describe("Voltage rating in volts, e.g. ±5V would be 5")}),fWA=wB.extend({ftype:xA("simple_battery"),capacity:lat}),yWA=wB.extend({ftype:xA("simple_inductor"),inductance:Bat,max_current_rating:WA().optional()}),wWA=wB.extend({ftype:xA("simple_push_button")}),mWA=wB.extend({ftype:xA("simple_potentiometer"),max_resistance:WBA}),pat=wB.extend({ftype:xA("simple_crystal"),frequency:WA().describe("Frequency in Hz"),load_capacitance:WA().optional().describe("Load capacitance in pF")}),DWA=wB.extend({ftype:xA("simple_pin_header"),pin_count:WA(),gender:Bt(["male","female"]).optional().default("male")}),SWA=wB.extend({ftype:xA("simple_pinout")}),bWA=wB.extend({ftype:xA("simple_resonator"),load_capacitance:lWA,equivalent_series_resistance:WBA.optional(),frequency:r5}),xWA=wB.extend({ftype:xA("simple_transistor"),transistor_type:Bt(["npn","pnp"])}),kWA=wB.extend({ftype:xA("simple_test_point"),footprint_variant:Bt(["pad","through_hole"]).optional(),pad_shape:Bt(["rect","circle"]).optional(),pad_diameter:ei([WA(),H()]).optional(),hole_diameter:ei([WA(),H()]).optional(),width:ei([WA(),H()]).optional(),height:ei([WA(),H()]).optional()}),GWA=wB.extend({ftype:xA("simple_mosfet"),channel_type:Bt(["n","p"]),mosfet_mode:Bt(["enhancement","depletion"])}),FWA=wB.extend({ftype:xA("simple_op_amp")}),RWA=wB.extend({ftype:xA("simple_switch")}),MWA=OA({type:xA("source_project_metadata"),name:H().optional(),software_used_string:H().optional(),project_url:H().optional(),created_at:Cat.optional()}),fat=OA({type:xA("source_missing_property_error"),source_missing_property_error_id:Vt("source_missing_property_error"),source_component_id:H(),property_name:H(),subcircuit_id:H().optional(),error_type:xA("source_missing_property_error").default("source_missing_property_error"),message:H()}).describe("The source code is missing a property"),yat=OA({type:xA("source_failed_to_create_component_error"),source_failed_to_create_component_error_id:Vt("source_failed_to_create_component_error"),error_type:xA("source_failed_to_create_component_error").default("source_failed_to_create_component_error"),component_name:H().optional(),subcircuit_id:H().optional(),parent_source_component_id:H().optional(),message:H(),pcb_center:OA({x:WA().optional(),y:WA().optional()}).optional(),schematic_center:OA({x:WA().optional(),y:WA().optional()}).optional()}).describe("Error emitted when a component fails to be constructed"),NWA=OA({type:xA("source_trace_not_connected_error"),source_trace_not_connected_error_id:Vt("source_trace_not_connected_error"),error_type:xA("source_trace_not_connected_error").default("source_trace_not_connected_error"),message:H(),subcircuit_id:H().optional(),source_group_id:H().optional(),source_trace_id:H().optional(),connected_source_port_ids:be(H()).optional(),selectors_not_found:be(H()).optional()}).describe("Occurs when a source trace selector does not match any ports"),wat=OA({type:xA("source_property_ignored_warning"),source_property_ignored_warning_id:Vt("source_property_ignored_warning"),source_component_id:H(),property_name:H(),subcircuit_id:H().optional(),error_type:xA("source_property_ignored_warning").default("source_property_ignored_warning"),message:H()}).describe("The source property was ignored"),_WA=OA({type:xA("source_pin_missing_trace_warning"),source_pin_missing_trace_warning_id:Vt("source_pin_missing_trace_warning"),warning_type:xA("source_pin_missing_trace_warning").default("source_pin_missing_trace_warning"),message:H(),source_component_id:H(),source_port_id:H(),subcircuit_id:H().optional()}).describe("Warning emitted when a source component pin is missing a trace connection"),mat=wB.extend({ftype:xA("simple_voltage_probe")}),Dat=wB.extend({ftype:xA("interconnect")}),Sat=ei([hWA,EWA,zBA,hat,uWA,uat,dWA,pWA,fWA,yWA,wWA,mWA,pat,DWA,SWA,bWA,RWA,xWA,kWA,GWA,FWA,dat,mat,Dat,MWA,fat,yat,NWA,wat,_WA]),bat=OA({type:xA("source_port"),pin_number:WA().optional(),port_hints:be(H()).optional(),name:H(),source_port_id:H(),source_component_id:H().optional(),source_group_id:H().optional(),subcircuit_id:H().optional(),subcircuit_connectivity_map_key:H().optional(),must_be_connected:ce().optional()}),xat=OA({type:xA("source_component_internal_connection"),source_component_internal_connection_id:H(),source_component_id:H(),source_port_ids:be(H()),subcircuit_id:H().optional()}),kat=OA({type:xA("source_trace"),source_trace_id:H(),connected_source_port_ids:be(H()),connected_source_net_ids:be(H()),subcircuit_id:H().optional(),subcircuit_connectivity_map_key:H().optional(),max_length:WA().optional(),min_trace_thickness:WA().optional(),display_name:H().optional()}),Gat=OA({type:xA("source_group"),source_group_id:H(),subcircuit_id:H().optional(),parent_subcircuit_id:H().optional(),parent_source_group_id:H().optional(),is_subcircuit:ce().optional(),show_as_schematic_box:ce().optional(),name:H().optional(),was_automatically_named:ce().optional()}),Fat=OA({type:xA("source_net"),source_net_id:H(),name:H(),member_source_group_ids:be(H()),is_power:ce().optional(),is_ground:ce().optional(),is_digital_signal:ce().optional(),is_analog_signal:ce().optional(),is_positive_voltage_source:ce().optional(),trace_width:WA().optional(),subcircuit_id:H().optional(),subcircuit_connectivity_map_key:H().optional()}),Rat=OA({type:xA("source_board"),source_board_id:H(),source_group_id:H(),title:H().optional()}).describe("Defines a board in the source domain"),Mat=OA({type:xA("source_pcb_ground_plane"),source_pcb_ground_plane_id:H(),source_group_id:H(),source_net_id:H(),subcircuit_id:H().optional()}).describe("Defines a ground plane in the source domain"),Nat=["top","bottom","inner1","inner2","inner3","inner4","inner5","inner6"],vWA=Bt(Nat),vr=vWA.or(OA({name:vWA})).transform(t=>typeof t=="string"?t:t.name),Fm=Bt(["top","bottom"]),_at=OA({type:xA("source_manually_placed_via"),source_manually_placed_via_id:H(),source_group_id:H(),source_net_id:H(),subcircuit_id:H().optional(),source_trace_id:H().optional()}).describe("Defines a via that is manually placed in the source domain"),vat=OA({type:xA("source_pin_must_be_connected_error"),source_pin_must_be_connected_error_id:Vt("source_pin_must_be_connected_error"),error_type:xA("source_pin_must_be_connected_error").default("source_pin_must_be_connected_error"),message:H(),source_component_id:H(),source_port_id:H(),subcircuit_id:H().optional()}).describe("Error emitted when a pin with mustBeConnected attribute is not connected to any trace"),Uat=OA({type:xA("unknown_error_finding_part"),unknown_error_finding_part_id:Vt("unknown_error_finding_part"),error_type:xA("unknown_error_finding_part").default("unknown_error_finding_part"),message:H(),source_component_id:H().optional(),subcircuit_id:H().optional()}).describe("Error emitted when an unexpected error occurs while finding a part"),Lat=OA({type:xA("schematic_box"),schematic_component_id:H().optional(),width:mt,height:mt,is_dashed:ce().default(!1),x:mt,y:mt,subcircuit_id:H().optional()}).describe("Draws a box on the schematic"),Hat=OA({type:xA("schematic_path"),schematic_component_id:H(),fill_color:Bt(["red","blue"]).optional(),is_filled:ce().optional(),points:be(ko),subcircuit_id:H().optional()}),Yat=_a(OA({left_margin:Ae.optional(),right_margin:Ae.optional(),top_margin:Ae.optional(),bottom_margin:Ae.optional()})),Jat=OA({left_size:WA(),right_size:WA(),top_size:WA().optional(),bottom_size:WA().optional()}),Tat=OA({left_side:OA({pins:be(WA()),direction:Bt(["top-to-bottom","bottom-to-top"]).optional()}).optional(),right_side:OA({pins:be(WA()),direction:Bt(["top-to-bottom","bottom-to-top"]).optional()}).optional(),top_side:OA({pins:be(WA()),direction:Bt(["left-to-right","right-to-left"]).optional()}).optional(),bottom_side:OA({pins:be(WA()),direction:Bt(["left-to-right","right-to-left"]).optional()}).optional()}),Kat=ei([Jat,Tat]),qat=OA({type:xA("schematic_component"),size:QWA,center:ko,source_component_id:H().optional(),schematic_component_id:H(),pin_spacing:Ae.optional(),pin_styles:Yat.optional(),box_width:Ae.optional(),symbol_name:H().optional(),port_arrangement:Kat.optional(),port_labels:_a(H()).optional(),symbol_display_value:H().optional(),subcircuit_id:H().optional(),schematic_group_id:H().optional(),is_schematic_group:ce().optional(),source_group_id:H().optional(),is_box_with_pins:ce().optional().default(!0)}),Pat=OA({type:xA("schematic_line"),schematic_line_id:Vt("schematic_line"),schematic_component_id:H(),x1:mt,y1:mt,x2:mt,y2:mt,stroke_width:mt.nullable().optional(),color:H().default("#000000"),is_dashed:ce().default(!1),subcircuit_id:H().optional()}).describe("Draws a styled line on the schematic"),Oat=OA({type:xA("schematic_rect"),schematic_rect_id:Vt("schematic_rect"),schematic_component_id:H(),center:ko,width:mt,height:mt,rotation:bd.default(0),stroke_width:mt.nullable().optional(),color:H().default("#000000"),is_filled:ce().default(!1),fill_color:H().optional(),is_dashed:ce().default(!1),subcircuit_id:H().optional()}).describe("Draws a styled rectangle on the schematic"),Wat=OA({type:xA("schematic_circle"),schematic_circle_id:Vt("schematic_circle"),schematic_component_id:H(),center:ko,radius:mt,stroke_width:mt.nullable().optional(),color:H().default("#000000"),is_filled:ce().default(!1),fill_color:H().optional(),is_dashed:ce().default(!1),subcircuit_id:H().optional()}).describe("Draws a styled circle on the schematic"),Zat=OA({type:xA("schematic_arc"),schematic_arc_id:Vt("schematic_arc"),schematic_component_id:H(),center:ko,radius:mt,start_angle_degrees:bd,end_angle_degrees:bd,direction:Bt(["clockwise","counterclockwise"]).default("counterclockwise"),stroke_width:mt.nullable().optional(),color:H().default("#000000"),is_dashed:ce().default(!1),subcircuit_id:H().optional()}).describe("Draws a styled arc on the schematic"),Vat=OA({type:xA("schematic_trace"),schematic_trace_id:H(),source_trace_id:H().optional(),junctions:be(OA({x:WA(),y:WA()})),edges:be(OA({from:OA({x:WA(),y:WA()}),to:OA({x:WA(),y:WA()}),is_crossing:ce().optional(),from_schematic_port_id:H().optional(),to_schematic_port_id:H().optional()})),subcircuit_id:H().optional(),subcircuit_connectivity_map_key:H().optional()}),jat=Bt(["center","left","right","top","bottom"]),zat=OA({type:xA("schematic_text"),schematic_component_id:H().optional(),schematic_text_id:H(),text:H(),font_size:WA().default(.18),position:OA({x:mt,y:mt}),rotation:WA().default(0),anchor:ei([jat.describe("legacy"),oF]).default("center"),color:H().default("#000000"),subcircuit_id:H().optional()}),Xat=OA({type:xA("schematic_port"),schematic_port_id:H(),source_port_id:H(),schematic_component_id:H().optional(),center:ko,facing_direction:Bt(["up","down","left","right"]).optional(),distance_from_component_edge:WA().optional(),side_of_component:Bt(["top","bottom","left","right"]).optional(),true_ccw_index:WA().optional(),pin_number:WA().optional(),display_pin_label:H().optional(),subcircuit_id:H().optional(),is_connected:ce().optional(),has_input_arrow:ce().optional(),has_output_arrow:ce().optional()}).describe("Defines a port on a schematic component"),$at=OA({type:xA("schematic_net_label"),schematic_net_label_id:Vt("schematic_net_label"),schematic_trace_id:H().optional(),source_trace_id:H().optional(),source_net_id:H(),center:ko,anchor_position:ko.optional(),anchor_side:Bt(["top","bottom","left","right"]),text:H(),symbol_name:H().optional(),is_movable:ce().optional(),subcircuit_id:H().optional()}),Agt=OA({type:xA("schematic_error"),schematic_error_id:H(),error_type:xA("schematic_port_not_found").default("schematic_port_not_found"),message:H(),subcircuit_id:H().optional()}).describe("Defines a schematic error on the schematic"),egt=OA({type:xA("schematic_layout_error"),schematic_layout_error_id:Vt("schematic_layout_error"),error_type:xA("schematic_layout_error").default("schematic_layout_error"),message:H(),source_group_id:H(),schematic_group_id:H(),subcircuit_id:H().optional()}).describe("Error emitted when schematic layout fails for a group"),XBA=OA({type:xA("schematic_debug_object"),label:H().optional(),subcircuit_id:H().optional()}),tgt=XBA.extend({shape:xA("rect"),center:ko,size:QWA}),igt=XBA.extend({shape:xA("line"),start:ko,end:ko}),ogt=XBA.extend({shape:xA("point"),center:ko}),ngt=Kp("shape",[tgt,igt,ogt]),sgt=OA({type:xA("schematic_voltage_probe"),schematic_voltage_probe_id:H(),source_component_id:H().optional(),name:H().optional(),position:ko,schematic_trace_id:H(),voltage:ZN.optional(),subcircuit_id:H().optional(),color:H().optional(),label_alignment:oF.optional()}).describe("Defines a voltage probe measurement point on a schematic trace"),rgt=OA({type:xA("schematic_manual_edit_conflict_warning"),schematic_manual_edit_conflict_warning_id:Vt("schematic_manual_edit_conflict_warning"),warning_type:xA("schematic_manual_edit_conflict_warning").default("schematic_manual_edit_conflict_warning"),message:H(),schematic_component_id:H(),schematic_group_id:H().optional(),subcircuit_id:H().optional(),source_component_id:H()}).describe("Warning emitted when a component has both manual placement and explicit schX/schY coordinates"),agt=OA({type:xA("schematic_group"),schematic_group_id:Vt("schematic_group"),source_group_id:H(),is_subcircuit:ce().optional(),subcircuit_id:H().optional(),width:Ae,height:Ae,center:ko,schematic_component_ids:be(H()),show_as_schematic_box:ce().optional(),name:H().optional(),description:H().optional()}).describe("Defines a group of components on the schematic"),ggt=OA({type:xA("schematic_table"),schematic_table_id:Vt("schematic_table"),anchor_position:ko,column_widths:be(mt),row_heights:be(mt),cell_padding:mt.optional(),border_width:mt.optional(),subcircuit_id:H().optional(),schematic_component_id:H().optional(),anchor:oF.optional()}).describe("Defines a table on the schematic"),Igt=OA({type:xA("schematic_table_cell"),schematic_table_cell_id:Vt("schematic_table_cell"),schematic_table_id:H(),start_row_index:WA(),end_row_index:WA(),start_column_index:WA(),end_column_index:WA(),text:H().optional(),center:ko,width:mt,height:mt,horizontal_align:Bt(["left","center","right"]).optional(),vertical_align:Bt(["top","middle","bottom"]).optional(),font_size:mt.optional(),subcircuit_id:H().optional()}).describe("Defines a cell within a schematic_table"),cgt=OA({type:xA("schematic_sheet"),schematic_sheet_id:Vt("schematic_sheet"),name:H().optional(),subcircuit_id:H().optional()}).describe("Defines a schematic sheet or page that components can be placed on"),Bgt=OA({x:mt,y:mt,bulge:WA().optional()}),UWA=OA({vertices:be(Bgt)}),Cgt=OA({outer_ring:UWA,inner_rings:be(UWA).default([])}),lgt=OA({x:mt,y:mt,via:ce().optional(),via_to_layer:vr.optional()});be(lgt);var Qgt=OA({x:mt,y:mt,via:ce().optional(),to_layer:vr.optional(),trace_width:mt.optional()}),Egt=OA({type:xA("pcb_component"),pcb_component_id:Vt("pcb_component"),source_component_id:H(),center:ko,layer:vr,rotation:bd,display_offset_x:H().optional().describe("How to display the x offset for this part, usually corresponding with how the user specified it"),display_offset_y:H().optional().describe("How to display the y offset for this part, usually corresponding with how the user specified it"),width:Ae,height:Ae,do_not_place:ce().optional(),subcircuit_id:H().optional(),pcb_group_id:H().optional(),position_mode:Bt(["packed","relative_to_group_anchor","none"]).optional(),positioned_relative_to_pcb_group_id:H().optional(),positioned_relative_to_pcb_board_id:H().optional(),obstructs_within_bounds:ce().default(!0).describe("Does this component take up all the space within its bounds on a layer. This is generally true except for when separated pin headers are being represented by a single component (in which case, chips can be placed between the pin headers) or for tall modules where chips fit underneath")}).describe("Defines a component on the PCB"),LWA=OA({type:xA("pcb_hole"),pcb_hole_id:Vt("pcb_hole"),pcb_group_id:H().optional(),subcircuit_id:H().optional(),pcb_component_id:H().optional(),hole_shape:xA("circle"),hole_diameter:WA(),x:mt,y:mt,is_covered_with_solder_mask:ce().optional(),soldermask_margin:WA().optional()});LWA.describe("Defines a circular hole on the PCB");var HWA=OA({type:xA("pcb_hole"),pcb_hole_id:Vt("pcb_hole"),pcb_group_id:H().optional(),subcircuit_id:H().optional(),pcb_component_id:H().optional(),hole_shape:xA("rect"),hole_width:WA(),hole_height:WA(),x:mt,y:mt,is_covered_with_solder_mask:ce().optional(),soldermask_margin:WA().optional()});HWA.describe("Defines a rectangular (square-capable) hole on the PCB. Use equal width/height for square.");var YWA=OA({type:xA("pcb_hole"),pcb_hole_id:Vt("pcb_hole"),pcb_group_id:H().optional(),subcircuit_id:H().optional(),pcb_component_id:H().optional(),hole_shape:Bt(["circle","square"]),hole_diameter:WA(),x:mt,y:mt,is_covered_with_solder_mask:ce().optional(),soldermask_margin:WA().optional()});YWA.describe("Defines a circular or square hole on the PCB");var JWA=OA({type:xA("pcb_hole"),pcb_hole_id:Vt("pcb_hole"),pcb_group_id:H().optional(),subcircuit_id:H().optional(),pcb_component_id:H().optional(),hole_shape:xA("oval"),hole_width:WA(),hole_height:WA(),x:mt,y:mt,is_covered_with_solder_mask:ce().optional(),soldermask_margin:WA().optional()});JWA.describe("Defines an oval hole on the PCB");var TWA=OA({type:xA("pcb_hole"),pcb_hole_id:Vt("pcb_hole"),pcb_group_id:H().optional(),subcircuit_id:H().optional(),pcb_component_id:H().optional(),hole_shape:xA("pill"),hole_width:WA(),hole_height:WA(),x:mt,y:mt,is_covered_with_solder_mask:ce().optional(),soldermask_margin:WA().optional()});TWA.describe("Defines a pill-shaped hole on the PCB");var KWA=OA({type:xA("pcb_hole"),pcb_hole_id:Vt("pcb_hole"),pcb_group_id:H().optional(),subcircuit_id:H().optional(),pcb_component_id:H().optional(),hole_shape:xA("rotated_pill"),hole_width:WA(),hole_height:WA(),x:mt,y:mt,ccw_rotation:bd,is_covered_with_solder_mask:ce().optional(),soldermask_margin:WA().optional()});KWA.describe("Defines a rotated pill-shaped hole on the PCB");var hgt=YWA.or(JWA).or(TWA).or(KWA).or(LWA).or(HWA),ugt=OA({type:xA("pcb_plated_hole"),shape:xA("circle"),pcb_group_id:H().optional(),subcircuit_id:H().optional(),outer_diameter:WA(),hole_diameter:WA(),is_covered_with_solder_mask:ce().optional(),x:mt,y:mt,layers:be(vr),port_hints:be(H()).optional(),pcb_component_id:H().optional(),pcb_port_id:H().optional(),pcb_plated_hole_id:Vt("pcb_plated_hole"),soldermask_margin:WA().optional()}),dgt=OA({type:xA("pcb_plated_hole"),shape:Bt(["oval","pill"]),pcb_group_id:H().optional(),subcircuit_id:H().optional(),outer_width:WA(),outer_height:WA(),hole_width:WA(),hole_height:WA(),is_covered_with_solder_mask:ce().optional(),x:mt,y:mt,ccw_rotation:bd,layers:be(vr),port_hints:be(H()).optional(),pcb_component_id:H().optional(),pcb_port_id:H().optional(),pcb_plated_hole_id:Vt("pcb_plated_hole"),soldermask_margin:WA().optional()}),pgt=OA({type:xA("pcb_plated_hole"),shape:xA("circular_hole_with_rect_pad"),pcb_group_id:H().optional(),subcircuit_id:H().optional(),hole_shape:xA("circle"),pad_shape:xA("rect"),hole_diameter:WA(),rect_pad_width:WA(),rect_pad_height:WA(),rect_border_radius:WA().optional(),hole_offset_x:mt.default(0),hole_offset_y:mt.default(0),is_covered_with_solder_mask:ce().optional(),x:mt,y:mt,layers:be(vr),port_hints:be(H()).optional(),pcb_component_id:H().optional(),pcb_port_id:H().optional(),pcb_plated_hole_id:Vt("pcb_plated_hole"),soldermask_margin:WA().optional()}),fgt=OA({type:xA("pcb_plated_hole"),shape:xA("pill_hole_with_rect_pad"),pcb_group_id:H().optional(),subcircuit_id:H().optional(),hole_shape:xA("pill"),pad_shape:xA("rect"),hole_width:WA(),hole_height:WA(),rect_pad_width:WA(),rect_pad_height:WA(),rect_border_radius:WA().optional(),hole_offset_x:mt.default(0),hole_offset_y:mt.default(0),is_covered_with_solder_mask:ce().optional(),x:mt,y:mt,layers:be(vr),port_hints:be(H()).optional(),pcb_component_id:H().optional(),pcb_port_id:H().optional(),pcb_plated_hole_id:Vt("pcb_plated_hole"),soldermask_margin:WA().optional()}),ygt=OA({type:xA("pcb_plated_hole"),shape:xA("rotated_pill_hole_with_rect_pad"),pcb_group_id:H().optional(),subcircuit_id:H().optional(),hole_shape:xA("rotated_pill"),pad_shape:xA("rect"),hole_width:WA(),hole_height:WA(),hole_ccw_rotation:bd,rect_pad_width:WA(),rect_pad_height:WA(),rect_border_radius:WA().optional(),rect_ccw_rotation:bd,hole_offset_x:mt.default(0),hole_offset_y:mt.default(0),is_covered_with_solder_mask:ce().optional(),x:mt,y:mt,layers:be(vr),port_hints:be(H()).optional(),pcb_component_id:H().optional(),pcb_port_id:H().optional(),pcb_plated_hole_id:Vt("pcb_plated_hole"),soldermask_margin:WA().optional()}),wgt=OA({type:xA("pcb_plated_hole"),shape:xA("hole_with_polygon_pad"),pcb_group_id:H().optional(),subcircuit_id:H().optional(),hole_shape:Bt(["circle","oval","pill","rotated_pill"]),hole_diameter:WA().optional(),hole_width:WA().optional(),hole_height:WA().optional(),pad_outline:be(OA({x:mt,y:mt})).min(3),hole_offset_x:mt.default(0),hole_offset_y:mt.default(0),is_covered_with_solder_mask:ce().optional(),x:mt,y:mt,layers:be(vr),port_hints:be(H()).optional(),pcb_component_id:H().optional(),pcb_port_id:H().optional(),pcb_plated_hole_id:Vt("pcb_plated_hole"),soldermask_margin:WA().optional()}),mgt=ei([ugt,dgt,pgt,fgt,ygt,wgt]),Dgt=OA({type:xA("pcb_port"),pcb_port_id:Vt("pcb_port"),pcb_group_id:H().optional(),subcircuit_id:H().optional(),source_port_id:H(),pcb_component_id:H().optional(),x:mt,y:mt,layers:be(vr),is_board_pinout:ce().optional()}).describe("Defines a port on the PCB"),Sgt=OA({type:xA("pcb_smtpad"),shape:xA("circle"),pcb_smtpad_id:Vt("pcb_smtpad"),pcb_group_id:H().optional(),subcircuit_id:H().optional(),x:mt,y:mt,radius:WA(),layer:vr,port_hints:be(H()).optional(),pcb_component_id:H().optional(),pcb_port_id:H().optional(),is_covered_with_solder_mask:ce().optional(),soldermask_margin:WA().optional()}),bgt=OA({type:xA("pcb_smtpad"),shape:xA("rect"),pcb_smtpad_id:Vt("pcb_smtpad"),pcb_group_id:H().optional(),subcircuit_id:H().optional(),x:mt,y:mt,width:WA(),height:WA(),rect_border_radius:WA().optional(),corner_radius:WA().optional(),layer:vr,port_hints:be(H()).optional(),pcb_component_id:H().optional(),pcb_port_id:H().optional(),is_covered_with_solder_mask:ce().optional(),soldermask_margin:WA().optional()}),xgt=OA({type:xA("pcb_smtpad"),shape:xA("rotated_rect"),pcb_smtpad_id:Vt("pcb_smtpad"),pcb_group_id:H().optional(),subcircuit_id:H().optional(),x:mt,y:mt,width:WA(),height:WA(),rect_border_radius:WA().optional(),corner_radius:WA().optional(),ccw_rotation:bd,layer:vr,port_hints:be(H()).optional(),pcb_component_id:H().optional(),pcb_port_id:H().optional(),is_covered_with_solder_mask:ce().optional(),soldermask_margin:WA().optional()}),kgt=OA({type:xA("pcb_smtpad"),shape:xA("pill"),pcb_smtpad_id:Vt("pcb_smtpad"),pcb_group_id:H().optional(),subcircuit_id:H().optional(),x:mt,y:mt,width:WA(),height:WA(),radius:WA(),layer:vr,port_hints:be(H()).optional(),pcb_component_id:H().optional(),pcb_port_id:H().optional(),is_covered_with_solder_mask:ce().optional(),soldermask_margin:WA().optional()}),Ggt=OA({type:xA("pcb_smtpad"),shape:xA("rotated_pill"),pcb_smtpad_id:Vt("pcb_smtpad"),pcb_group_id:H().optional(),subcircuit_id:H().optional(),x:mt,y:mt,width:WA(),height:WA(),radius:WA(),ccw_rotation:bd,layer:vr,port_hints:be(H()).optional(),pcb_component_id:H().optional(),pcb_port_id:H().optional(),is_covered_with_solder_mask:ce().optional(),soldermask_margin:WA().optional()}),Fgt=OA({type:xA("pcb_smtpad"),shape:xA("polygon"),pcb_smtpad_id:Vt("pcb_smtpad"),pcb_group_id:H().optional(),subcircuit_id:H().optional(),points:be(ko),layer:vr,port_hints:be(H()).optional(),pcb_component_id:H().optional(),pcb_port_id:H().optional(),is_covered_with_solder_mask:ce().optional(),soldermask_margin:WA().optional()}),Rgt=Kp("shape",[Sgt,bgt,xgt,Ggt,kgt,Fgt]).describe("Defines an SMT pad on the PCB"),Mgt=OA({type:xA("pcb_solder_paste"),shape:xA("circle"),pcb_solder_paste_id:Vt("pcb_solder_paste"),pcb_group_id:H().optional(),subcircuit_id:H().optional(),x:mt,y:mt,radius:WA(),layer:vr,pcb_component_id:H().optional(),pcb_smtpad_id:H().optional()}),Ngt=OA({type:xA("pcb_solder_paste"),shape:xA("rect"),pcb_solder_paste_id:Vt("pcb_solder_paste"),pcb_group_id:H().optional(),subcircuit_id:H().optional(),x:mt,y:mt,width:WA(),height:WA(),layer:vr,pcb_component_id:H().optional(),pcb_smtpad_id:H().optional()}),_gt=OA({type:xA("pcb_solder_paste"),shape:xA("pill"),pcb_solder_paste_id:Vt("pcb_solder_paste"),pcb_group_id:H().optional(),subcircuit_id:H().optional(),x:mt,y:mt,width:WA(),height:WA(),radius:WA(),layer:vr,pcb_component_id:H().optional(),pcb_smtpad_id:H().optional()}),vgt=OA({type:xA("pcb_solder_paste"),shape:xA("rotated_rect"),pcb_solder_paste_id:Vt("pcb_solder_paste"),pcb_group_id:H().optional(),subcircuit_id:H().optional(),x:mt,y:mt,width:WA(),height:WA(),ccw_rotation:mt,layer:vr,pcb_component_id:H().optional(),pcb_smtpad_id:H().optional()}),Ugt=OA({type:xA("pcb_solder_paste"),shape:xA("oval"),pcb_solder_paste_id:Vt("pcb_solder_paste"),pcb_group_id:H().optional(),subcircuit_id:H().optional(),x:mt,y:mt,width:WA(),height:WA(),layer:vr,pcb_component_id:H().optional(),pcb_smtpad_id:H().optional()}),Lgt=ei([Mgt,Ngt,_gt,vgt,Ugt]).describe("Defines solderpaste on the PCB"),Hgt=OA({type:xA("pcb_text"),pcb_text_id:Vt("pcb_text"),pcb_group_id:H().optional(),subcircuit_id:H().optional(),text:H(),center:ko,layer:vr,width:Ae,height:Ae,lines:WA(),align:Bt(["bottom-left"])}).describe("Defines text on the PCB"),Ygt=OA({route_type:xA("wire"),x:mt,y:mt,width:mt,start_pcb_port_id:H().optional(),end_pcb_port_id:H().optional(),layer:vr}),Jgt=OA({route_type:xA("via"),x:mt,y:mt,hole_diameter:mt.optional(),outer_diameter:mt.optional(),from_layer:H(),to_layer:H()}),Tgt=ei([Ygt,Jgt]),Kgt=OA({type:xA("pcb_trace"),source_trace_id:H().optional(),pcb_component_id:H().optional(),pcb_trace_id:Vt("pcb_trace"),pcb_group_id:H().optional(),subcircuit_id:H().optional(),route_thickness_mode:Bt(["constant","interpolated"]).default("constant").optional(),route_order_index:WA().optional(),should_round_corners:ce().optional(),trace_length:WA().optional(),highlight_color:H().optional(),route:be(Tgt)}).describe("Defines a trace on the PCB"),qgt=OA({type:xA("pcb_trace_error"),pcb_trace_error_id:Vt("pcb_trace_error"),error_type:xA("pcb_trace_error").default("pcb_trace_error"),message:H(),center:ko.optional(),pcb_trace_id:H(),source_trace_id:H(),pcb_component_ids:be(H()),pcb_port_ids:be(H()),subcircuit_id:H().optional()}).describe("Defines a trace error on the PCB"),Pgt=OA({type:xA("pcb_trace_missing_error"),pcb_trace_missing_error_id:Vt("pcb_trace_missing_error"),error_type:xA("pcb_trace_missing_error").default("pcb_trace_missing_error"),message:H(),center:ko.optional(),source_trace_id:H(),pcb_component_ids:be(H()),pcb_port_ids:be(H()),subcircuit_id:H().optional()}).describe("Defines an error when a source trace has no corresponding PCB trace"),Ogt=OA({type:xA("pcb_port_not_matched_error"),pcb_error_id:Vt("pcb_error"),error_type:xA("pcb_port_not_matched_error").default("pcb_port_not_matched_error"),message:H(),pcb_component_ids:be(H()),subcircuit_id:H().optional()}).describe("Defines a trace error on the PCB where a port is not matched"),Wgt=OA({type:xA("pcb_port_not_connected_error"),pcb_port_not_connected_error_id:Vt("pcb_port_not_connected_error"),error_type:xA("pcb_port_not_connected_error").default("pcb_port_not_connected_error"),message:H(),pcb_port_ids:be(H()),pcb_component_ids:be(H()),subcircuit_id:H().optional()}).describe("Defines an error when a pcb port is not connected to any trace"),Zgt=OA({type:xA("pcb_net"),pcb_net_id:Vt("pcb_net"),source_net_id:H().optional(),highlight_color:H().optional()}).describe("Defines a net on the PCB"),Vgt=OA({type:xA("pcb_via"),pcb_via_id:Vt("pcb_via"),pcb_group_id:H().optional(),subcircuit_id:H().optional(),subcircuit_connectivity_map_key:H().optional(),x:mt,y:mt,outer_diameter:mt.default("0.6mm"),hole_diameter:mt.default("0.25mm"),from_layer:vr.optional(),to_layer:vr.optional(),layers:be(vr),pcb_trace_id:H().optional(),net_is_assignable:ce().optional(),net_assigned:ce().optional(),is_tented:ce().optional()}).describe("Defines a via on the PCB"),jgt=OA({type:xA("pcb_board"),pcb_board_id:Vt("pcb_board"),pcb_panel_id:H().optional(),is_subcircuit:ce().optional(),subcircuit_id:H().optional(),width:Ae.optional(),height:Ae.optional(),center:ko,display_offset_x:H().optional().describe("How to display the x offset for this board, usually corresponding with how the user specified it"),display_offset_y:H().optional().describe("How to display the y offset for this board, usually corresponding with how the user specified it"),thickness:Ae.optional().default(1.4),num_layers:WA().optional().default(4),outline:be(ko).optional(),shape:Bt(["rect","polygon"]).optional(),material:Bt(["fr4","fr1"]).default("fr4"),anchor_position:ko.optional(),anchor_alignment:oF.optional(),position_mode:Bt(["relative_to_panel_anchor","none"]).optional()}).describe("Defines the board outline of the PCB"),zgt=OA({type:xA("pcb_panel"),pcb_panel_id:Vt("pcb_panel"),width:Ae,height:Ae,center:ko,covered_with_solder_mask:ce().optional().default(!0)}).describe("Defines a PCB panel that can contain multiple boards"),Xgt=OA({type:xA("pcb_placement_error"),pcb_placement_error_id:Vt("pcb_placement_error"),error_type:xA("pcb_placement_error").default("pcb_placement_error"),message:H(),subcircuit_id:H().optional()}).describe("Defines a placement error on the PCB"),$gt=OA({type:xA("pcb_trace_hint"),pcb_trace_hint_id:Vt("pcb_trace_hint"),pcb_port_id:H(),pcb_component_id:H(),route:be(Qgt),subcircuit_id:H().optional()}).describe("A hint that can be used during generation of a PCB trace"),AIt=OA({type:xA("pcb_silkscreen_line"),pcb_silkscreen_line_id:Vt("pcb_silkscreen_line"),pcb_component_id:H(),pcb_group_id:H().optional(),subcircuit_id:H().optional(),stroke_width:mt.default("0.1mm"),x1:mt,y1:mt,x2:mt,y2:mt,layer:Fm}).describe("Defines a silkscreen line on the PCB"),eIt=OA({type:xA("pcb_silkscreen_path"),pcb_silkscreen_path_id:Vt("pcb_silkscreen_path"),pcb_component_id:H(),pcb_group_id:H().optional(),subcircuit_id:H().optional(),layer:Fm,route:be(ko),stroke_width:Ae}).describe("Defines a silkscreen path on the PCB"),tIt=OA({type:xA("pcb_silkscreen_text"),pcb_silkscreen_text_id:Vt("pcb_silkscreen_text"),pcb_group_id:H().optional(),subcircuit_id:H().optional(),font:xA("tscircuit2024").default("tscircuit2024"),font_size:mt.default("0.2mm"),pcb_component_id:H(),text:H(),is_knockout:ce().default(!1).optional(),knockout_padding:OA({left:Ae,top:Ae,bottom:Ae,right:Ae}).default({left:"0.2mm",top:"0.2mm",bottom:"0.2mm",right:"0.2mm"}).optional(),ccw_rotation:WA().optional(),layer:vr,is_mirrored:ce().default(!1).optional(),anchor_position:ko.default({x:0,y:0}),anchor_alignment:oF.default("center")}).describe("Defines silkscreen text on the PCB"),iIt=OA({type:xA("pcb_copper_text"),pcb_copper_text_id:Vt("pcb_copper_text"),pcb_group_id:H().optional(),subcircuit_id:H().optional(),font:xA("tscircuit2024").default("tscircuit2024"),font_size:mt.default("0.2mm"),pcb_component_id:H(),text:H(),is_knockout:ce().default(!1).optional(),knockout_padding:OA({left:Ae,top:Ae,bottom:Ae,right:Ae}).default({left:"0.2mm",top:"0.2mm",bottom:"0.2mm",right:"0.2mm"}).optional(),ccw_rotation:WA().optional(),layer:vr,is_mirrored:ce().default(!1).optional(),anchor_position:ko.default({x:0,y:0}),anchor_alignment:oF.default("center")}).describe("Defines copper text on the PCB"),oIt=OA({type:xA("pcb_silkscreen_rect"),pcb_silkscreen_rect_id:Vt("pcb_silkscreen_rect"),pcb_component_id:H(),pcb_group_id:H().optional(),subcircuit_id:H().optional(),center:ko,width:Ae,height:Ae,layer:vr,stroke_width:Ae.default("1mm"),corner_radius:Ae.optional(),is_filled:ce().default(!0).optional(),has_stroke:ce().optional(),is_stroke_dashed:ce().optional(),ccw_rotation:WA().optional()}).describe("Defines a silkscreen rect on the PCB"),nIt=OA({type:xA("pcb_silkscreen_circle"),pcb_silkscreen_circle_id:Vt("pcb_silkscreen_circle"),pcb_component_id:H(),pcb_group_id:H().optional(),subcircuit_id:H().optional(),center:ko,radius:Ae,layer:Fm,stroke_width:Ae.default("1mm")}).describe("Defines a silkscreen circle on the PCB"),sIt=OA({type:xA("pcb_silkscreen_oval"),pcb_silkscreen_oval_id:Vt("pcb_silkscreen_oval"),pcb_component_id:H(),pcb_group_id:H().optional(),subcircuit_id:H().optional(),center:ko,radius_x:mt,radius_y:mt,layer:Fm,ccw_rotation:bd.optional()}).describe("Defines a silkscreen oval on the PCB"),rIt=OA({type:xA("pcb_silkscreen_pill"),pcb_silkscreen_pill_id:Vt("pcb_silkscreen_pill"),pcb_component_id:H(),pcb_group_id:H().optional(),subcircuit_id:H().optional(),center:ko,width:Ae,height:Ae,layer:vr,ccw_rotation:WA().optional()}).describe("Defines a silkscreen pill on the PCB"),aIt=OA({type:xA("pcb_fabrication_note_text"),pcb_fabrication_note_text_id:Vt("pcb_fabrication_note_text"),subcircuit_id:H().optional(),pcb_group_id:H().optional(),font:xA("tscircuit2024").default("tscircuit2024"),font_size:mt.default("1mm"),pcb_component_id:H(),text:H(),layer:Fm,anchor_position:ko.default({x:0,y:0}),anchor_alignment:Bt(["center","top_left","top_right","bottom_left","bottom_right"]).default("center"),color:H().optional()}).describe("Defines a fabrication note in text on the PCB, useful for leaving notes for assemblers or fabricators"),gIt=OA({type:xA("pcb_fabrication_note_path"),pcb_fabrication_note_path_id:Vt("pcb_fabrication_note_path"),pcb_component_id:H(),subcircuit_id:H().optional(),layer:vr,route:be(ko),stroke_width:Ae,color:H().optional()}).describe("Defines a fabrication path on the PCB for fabricators or assemblers"),IIt=OA({type:xA("pcb_fabrication_note_rect"),pcb_fabrication_note_rect_id:Vt("pcb_fabrication_note_rect"),pcb_component_id:H(),pcb_group_id:H().optional(),subcircuit_id:H().optional(),center:ko,width:Ae,height:Ae,layer:Fm,stroke_width:Ae.default("0.1mm"),corner_radius:Ae.optional(),is_filled:ce().optional(),has_stroke:ce().optional(),is_stroke_dashed:ce().optional(),color:H().optional()}).describe("Defines a fabrication note rectangle on the PCB"),cIt=OA({type:xA("pcb_fabrication_note_dimension"),pcb_fabrication_note_dimension_id:Vt("pcb_fabrication_note_dimension"),pcb_component_id:H(),pcb_group_id:H().optional(),subcircuit_id:H().optional(),layer:Fm,from:ko,to:ko,text:H().optional(),text_ccw_rotation:WA().optional(),offset:Ae.optional(),offset_distance:Ae.optional(),offset_direction:OA({x:WA(),y:WA()}).optional(),font:xA("tscircuit2024").default("tscircuit2024"),font_size:Ae.default("1mm"),color:H().optional(),arrow_size:Ae.default("1mm")}).describe("Defines a measurement annotation within PCB fabrication notes"),BIt=OA({type:xA("pcb_note_text"),pcb_note_text_id:Vt("pcb_note_text"),pcb_component_id:H().optional(),pcb_group_id:H().optional(),subcircuit_id:H().optional(),name:H().optional(),font:xA("tscircuit2024").default("tscircuit2024"),font_size:mt.default("1mm"),text:H().optional(),anchor_position:ko.default({x:0,y:0}),anchor_alignment:Bt(["center","top_left","top_right","bottom_left","bottom_right"]).default("center"),color:H().optional()}).describe("Defines a documentation note in text on the PCB"),CIt=OA({type:xA("pcb_note_rect"),pcb_note_rect_id:Vt("pcb_note_rect"),pcb_component_id:H().optional(),pcb_group_id:H().optional(),subcircuit_id:H().optional(),name:H().optional(),text:H().optional(),center:ko,width:Ae,height:Ae,stroke_width:Ae.default("0.1mm"),corner_radius:Ae.optional(),is_filled:ce().optional(),has_stroke:ce().optional(),is_stroke_dashed:ce().optional(),color:H().optional()}).describe("Defines a rectangular documentation note on the PCB"),lIt=OA({type:xA("pcb_note_path"),pcb_note_path_id:Vt("pcb_note_path"),pcb_component_id:H().optional(),pcb_group_id:H().optional(),subcircuit_id:H().optional(),name:H().optional(),text:H().optional(),route:be(ko),stroke_width:Ae.default("0.1mm"),color:H().optional()}).describe("Defines a polyline documentation note on the PCB"),QIt=OA({type:xA("pcb_note_line"),pcb_note_line_id:Vt("pcb_note_line"),pcb_component_id:H().optional(),pcb_group_id:H().optional(),subcircuit_id:H().optional(),name:H().optional(),text:H().optional(),x1:mt,y1:mt,x2:mt,y2:mt,stroke_width:mt.default("0.1mm"),color:H().optional(),is_dashed:ce().optional()}).describe("Defines a straight documentation note line on the PCB"),EIt=OA({type:xA("pcb_note_dimension"),pcb_note_dimension_id:Vt("pcb_note_dimension"),pcb_component_id:H().optional(),pcb_group_id:H().optional(),subcircuit_id:H().optional(),name:H().optional(),from:ko,to:ko,text:H().optional(),text_ccw_rotation:WA().optional(),offset_distance:Ae.optional(),offset_direction:OA({x:WA(),y:WA()}).optional(),font:xA("tscircuit2024").default("tscircuit2024"),font_size:Ae.default("1mm"),color:H().optional(),arrow_size:Ae.default("1mm")}).describe("Defines a measurement annotation within PCB documentation notes"),hIt=OA({type:xA("pcb_footprint_overlap_error"),pcb_error_id:Vt("pcb_error"),error_type:xA("pcb_footprint_overlap_error").default("pcb_footprint_overlap_error"),message:H(),pcb_smtpad_ids:be(H()).optional(),pcb_plated_hole_ids:be(H()).optional(),pcb_hole_ids:be(H()).optional(),pcb_keepout_ids:be(H()).optional()}).describe("Error emitted when a pcb footprint overlaps with another element"),uIt=OA({type:xA("pcb_keepout"),shape:xA("rect"),pcb_group_id:H().optional(),subcircuit_id:H().optional(),center:ko,width:mt,height:mt,pcb_keepout_id:H(),layers:be(H()),description:H().optional()}).or(OA({type:xA("pcb_keepout"),shape:xA("circle"),pcb_group_id:H().optional(),subcircuit_id:H().optional(),center:ko,radius:mt,pcb_keepout_id:H(),layers:be(H()),description:H().optional()})),a5=OA({type:xA("pcb_cutout"),pcb_cutout_id:Vt("pcb_cutout"),pcb_group_id:H().optional(),subcircuit_id:H().optional(),pcb_board_id:H().optional(),pcb_panel_id:H().optional()}),dIt=a5.extend({shape:xA("rect"),center:ko,width:Ae,height:Ae,rotation:bd.optional(),corner_radius:Ae.optional()}),pIt=a5.extend({shape:xA("circle"),center:ko,radius:Ae}),fIt=a5.extend({shape:xA("polygon"),points:be(ko)}),yIt=a5.extend({shape:xA("path"),route:be(ko),slot_width:Ae,slot_length:Ae.optional(),space_between_slots:Ae.optional(),slot_corner_radius:Ae.optional()}),wIt=Kp("shape",[dIt,pIt,fIt,yIt]).describe("Defines a cutout on the PCB, removing board material."),mIt=OA({type:xA("pcb_missing_footprint_error"),pcb_missing_footprint_error_id:Vt("pcb_missing_footprint_error"),pcb_group_id:H().optional(),subcircuit_id:H().optional(),error_type:xA("pcb_missing_footprint_error").default("pcb_missing_footprint_error"),source_component_id:H(),message:H()}).describe("Defines a missing footprint error on the PCB"),DIt=OA({type:xA("external_footprint_load_error"),external_footprint_load_error_id:Vt("external_footprint_load_error"),pcb_component_id:H(),source_component_id:H(),pcb_group_id:H().optional(),subcircuit_id:H().optional(),footprinter_string:H().optional(),error_type:xA("external_footprint_load_error").default("external_footprint_load_error"),message:H()}).describe("Defines an error when an external footprint fails to load"),SIt=OA({type:xA("circuit_json_footprint_load_error"),circuit_json_footprint_load_error_id:Vt("circuit_json_footprint_load_error"),pcb_component_id:H(),source_component_id:H(),pcb_group_id:H().optional(),subcircuit_id:H().optional(),error_type:xA("circuit_json_footprint_load_error").default("circuit_json_footprint_load_error"),message:H(),circuit_json:be(HI()).optional()}).describe("Defines an error when a circuit JSON footprint fails to load"),bIt=OA({type:xA("pcb_group"),pcb_group_id:Vt("pcb_group"),source_group_id:H(),is_subcircuit:ce().optional(),subcircuit_id:H().optional(),width:Ae.optional(),height:Ae.optional(),center:ko,display_offset_x:H().optional().describe("How to display the x offset for this group, usually corresponding with how the user specified it"),display_offset_y:H().optional().describe("How to display the y offset for this group, usually corresponding with how the user specified it"),outline:be(ko).optional(),anchor_position:ko.optional(),anchor_alignment:oF.default("center"),position_mode:Bt(["packed","relative_to_group_anchor","none"]).optional(),positioned_relative_to_pcb_group_id:H().optional(),positioned_relative_to_pcb_board_id:H().optional(),pcb_component_ids:be(H()),child_layout_mode:Bt(["packed","none"]).optional(),name:H().optional(),description:H().optional(),layout_mode:H().optional(),autorouter_configuration:OA({trace_clearance:Ae}).optional(),autorouter_used_string:H().optional()}).describe("Defines a group of components on the PCB"),xIt=OA({type:xA("pcb_autorouting_error"),pcb_error_id:Vt("pcb_autorouting_error"),error_type:xA("pcb_autorouting_error").default("pcb_autorouting_error"),message:H(),subcircuit_id:H().optional()}).describe("The autorouting has failed to route a portion of the board"),kIt=OA({type:xA("pcb_manual_edit_conflict_warning"),pcb_manual_edit_conflict_warning_id:Vt("pcb_manual_edit_conflict_warning"),warning_type:xA("pcb_manual_edit_conflict_warning").default("pcb_manual_edit_conflict_warning"),message:H(),pcb_component_id:H(),pcb_group_id:H().optional(),subcircuit_id:H().optional(),source_component_id:H()}).describe("Warning emitted when a component has both manual placement and explicit pcbX/pcbY coordinates"),GIt=OA({type:xA("pcb_breakout_point"),pcb_breakout_point_id:Vt("pcb_breakout_point"),pcb_group_id:H(),subcircuit_id:H().optional(),source_trace_id:H().optional(),source_port_id:H().optional(),source_net_id:H().optional(),x:mt,y:mt}).describe("Defines a routing target within a pcb_group for a source_trace or source_net"),FIt=OA({type:xA("pcb_ground_plane"),pcb_ground_plane_id:Vt("pcb_ground_plane"),source_pcb_ground_plane_id:H(),source_net_id:H(),pcb_group_id:H().optional(),subcircuit_id:H().optional()}).describe("Defines a ground plane on the PCB"),RIt=OA({type:xA("pcb_ground_plane_region"),pcb_ground_plane_region_id:Vt("pcb_ground_plane_region"),pcb_ground_plane_id:H(),pcb_group_id:H().optional(),subcircuit_id:H().optional(),layer:vr,points:be(ko)}).describe("Defines a polygon region of a ground plane"),MIt=OA({type:xA("pcb_thermal_spoke"),pcb_thermal_spoke_id:Vt("pcb_thermal_spoke"),pcb_ground_plane_id:H(),shape:H(),spoke_count:WA(),spoke_thickness:mt,spoke_inner_diameter:mt,spoke_outer_diameter:mt,pcb_plated_hole_id:H().optional(),subcircuit_id:H().optional()}).describe("Pattern for connecting a ground plane to a plated hole"),$BA=OA({type:xA("pcb_copper_pour"),pcb_copper_pour_id:Vt("pcb_copper_pour"),pcb_group_id:H().optional(),subcircuit_id:H().optional(),layer:vr,source_net_id:H().optional(),covered_with_solder_mask:ce().optional().default(!0)}),NIt=$BA.extend({shape:xA("rect"),center:ko,width:Ae,height:Ae,rotation:bd.optional()}),_It=$BA.extend({shape:xA("brep"),brep_shape:Cgt}),vIt=$BA.extend({shape:xA("polygon"),points:be(ko)}),UIt=Kp("shape",[NIt,_It,vIt]).describe("Defines a copper pour on the PCB."),LIt=OA({type:xA("pcb_component_outside_board_error"),pcb_component_outside_board_error_id:Vt("pcb_component_outside_board_error"),error_type:xA("pcb_component_outside_board_error").default("pcb_component_outside_board_error"),message:H(),pcb_component_id:H(),pcb_board_id:H(),component_center:ko,component_bounds:OA({min_x:WA(),max_x:WA(),min_y:WA(),max_y:WA()}),subcircuit_id:H().optional(),source_component_id:H().optional()}).describe("Error emitted when a PCB component is placed outside the board boundaries"),HIt=OA({type:xA("pcb_component_invalid_layer_error"),pcb_component_invalid_layer_error_id:Vt("pcb_component_invalid_layer_error"),error_type:xA("pcb_component_invalid_layer_error").default("pcb_component_invalid_layer_error"),message:H(),pcb_component_id:H().optional(),source_component_id:H(),layer:vr,subcircuit_id:H().optional()}).describe("Error emitted when a component is placed on an invalid layer (components can only be on 'top' or 'bottom' layers)"),YIt=OA({type:xA("pcb_via_clearance_error"),pcb_error_id:Vt("pcb_error"),error_type:xA("pcb_via_clearance_error").default("pcb_via_clearance_error"),message:H(),pcb_via_ids:be(H()).min(2),minimum_clearance:mt.optional(),actual_clearance:mt.optional(),pcb_center:OA({x:WA().optional(),y:WA().optional()}).optional(),subcircuit_id:H().optional()}).describe("Error emitted when vias are closer than the allowed clearance"),JIt=OA({type:xA("pcb_courtyard_rect"),pcb_courtyard_rect_id:Vt("pcb_courtyard_rect"),pcb_component_id:H(),pcb_group_id:H().optional(),subcircuit_id:H().optional(),center:ko,width:Ae,height:Ae,layer:Fm,color:H().optional()}).describe("Defines a courtyard rectangle on the PCB"),TIt=OA({type:xA("pcb_courtyard_outline"),pcb_courtyard_outline_id:Vt("pcb_courtyard_outline"),pcb_component_id:H(),pcb_group_id:H().optional(),subcircuit_id:H().optional(),layer:Fm,outline:be(ko).min(2),stroke_width:Ae.default("0.1mm"),is_closed:ce().optional(),is_stroke_dashed:ce().optional(),color:H().optional()}).describe("Defines a courtyard outline on the PCB"),KIt=OA({type:xA("pcb_courtyard_polygon"),pcb_courtyard_polygon_id:Vt("pcb_courtyard_polygon"),pcb_component_id:H(),pcb_group_id:H().optional(),subcircuit_id:H().optional(),layer:Fm,points:be(ko).min(3),color:H().optional()}).describe("Defines a courtyard polygon on the PCB"),qIt=OA({type:xA("cad_component"),cad_component_id:H(),pcb_component_id:H(),source_component_id:H(),position:jBA,rotation:jBA.optional(),size:jBA.optional(),layer:vr.optional(),subcircuit_id:H().optional(),footprinter_string:H().optional(),model_obj_url:H().optional(),model_stl_url:H().optional(),model_3mf_url:H().optional(),model_gltf_url:H().optional(),model_glb_url:H().optional(),model_step_url:H().optional(),model_wrl_url:H().optional(),model_unit_to_mm_scale_factor:WA().optional(),model_jscad:HI().optional(),show_as_translucent_model:ce().optional()}).describe("Defines a component on the PCB"),qWA=Bt(["sinewave","square","triangle","sawtooth"]),PIt=ei([H(),WA()]).transform(t=>typeof t=="string"?t.endsWith("%")?parseFloat(t.slice(0,-1))/100:parseFloat(t):t).pipe(WA().min(0,"Duty cycle must be non-negative").max(1,"Duty cycle cannot be greater than 100%")),OIt=OA({type:xA("simulation_voltage_source"),simulation_voltage_source_id:Vt("simulation_voltage_source"),is_dc_source:xA(!0).optional().default(!0),positive_source_port_id:H().optional(),negative_source_port_id:H().optional(),positive_source_net_id:H().optional(),negative_source_net_id:H().optional(),voltage:ZN}).describe("Defines a DC voltage source for simulation"),WIt=OA({type:xA("simulation_voltage_source"),simulation_voltage_source_id:Vt("simulation_voltage_source"),is_dc_source:xA(!1),terminal1_source_port_id:H().optional(),terminal2_source_port_id:H().optional(),terminal1_source_net_id:H().optional(),terminal2_source_net_id:H().optional(),voltage:ZN.optional(),frequency:r5.optional(),peak_to_peak_voltage:ZN.optional(),wave_shape:qWA.optional(),phase:bd.optional(),duty_cycle:PIt.optional()}).describe("Defines an AC voltage source for simulation"),ZIt=ei([OIt,WIt]).describe("Defines a voltage source for simulation"),VIt=ei([H(),WA()]).transform(t=>typeof t=="string"?t.endsWith("%")?parseFloat(t.slice(0,-1))/100:parseFloat(t):t).pipe(WA().min(0,"Duty cycle must be non-negative").max(1,"Duty cycle cannot be greater than 100%")),jIt=OA({type:xA("simulation_current_source"),simulation_current_source_id:Vt("simulation_current_source"),is_dc_source:xA(!0).optional().default(!0),positive_source_port_id:H().optional(),negative_source_port_id:H().optional(),positive_source_net_id:H().optional(),negative_source_net_id:H().optional(),current:ZBA}).describe("Defines a DC current source for simulation"),zIt=OA({type:xA("simulation_current_source"),simulation_current_source_id:Vt("simulation_current_source"),is_dc_source:xA(!1),terminal1_source_port_id:H().optional(),terminal2_source_port_id:H().optional(),terminal1_source_net_id:H().optional(),terminal2_source_net_id:H().optional(),current:ZBA.optional(),frequency:r5.optional(),peak_to_peak_current:ZBA.optional(),wave_shape:qWA.optional(),phase:bd.optional(),duty_cycle:VIt.optional()}).describe("Defines an AC current source for simulation"),XIt=ei([jIt,zIt]).describe("Defines a current source for simulation"),$It=ei([xA("spice_dc_sweep"),xA("spice_dc_operating_point"),xA("spice_transient_analysis"),xA("spice_ac_analysis")]),Act=OA({type:xA("simulation_experiment"),simulation_experiment_id:Vt("simulation_experiment"),name:H(),experiment_type:$It,time_per_step:VBA.optional(),start_time_ms:VN.optional(),end_time_ms:VN.optional()}).describe("Defines a simulation experiment configuration"),ect=OA({type:xA("simulation_transient_voltage_graph"),simulation_transient_voltage_graph_id:Vt("simulation_transient_voltage_graph"),simulation_experiment_id:H(),timestamps_ms:be(WA()).optional(),voltage_levels:be(WA()),source_component_id:H().optional(),subcircuit_connectivity_map_key:H().optional(),time_per_step:VBA,start_time_ms:VN,end_time_ms:VN,name:H().optional(),color:H().optional()}).describe("Stores voltage measurements over time for a simulation"),tct=OA({type:xA("simulation_switch"),simulation_switch_id:Vt("simulation_switch"),source_component_id:H().optional(),closes_at:VN.optional(),opens_at:VN.optional(),starts_closed:ce().optional(),switching_frequency:r5.optional()}).describe("Defines a switch for simulation timing control"),ict=OA({type:xA("simulation_voltage_probe"),simulation_voltage_probe_id:Vt("simulation_voltage_probe"),source_component_id:H().optional(),name:H().optional(),signal_input_source_port_id:H().optional(),signal_input_source_net_id:H().optional(),reference_input_source_port_id:H().optional(),reference_input_source_net_id:H().optional(),subcircuit_id:H().optional(),color:H().optional()}).describe("Defines a voltage probe for simulation. If a reference input is not provided, it measures against ground. If a reference input is provided, it measures the differential voltage between two points.").superRefine((t,A)=>{if(t.reference_input_source_port_id||t.reference_input_source_net_id){const i=!!t.signal_input_source_port_id||!!t.reference_input_source_port_id,o=!!t.signal_input_source_net_id||!!t.reference_input_source_net_id;i&&o?A.addIssue({code:Ot.custom,message:"Cannot mix port and net connections in a differential probe."}):i?(!t.signal_input_source_port_id||!t.reference_input_source_port_id)&&A.addIssue({code:Ot.custom,message:"Differential port probe requires both signal_input_source_port_id and reference_input_source_port_id."}):o&&(!t.signal_input_source_net_id||!t.reference_input_source_net_id)&&A.addIssue({code:Ot.custom,message:"Differential net probe requires both signal_input_source_net_id and reference_input_source_net_id."})}else!!t.signal_input_source_port_id==!!t.signal_input_source_net_id&&A.addIssue({code:Ot.custom,message:"A voltage probe must have exactly one of signal_input_source_port_id or signal_input_source_net_id."})}),oct=OA({type:xA("simulation_unknown_experiment_error"),simulation_unknown_experiment_error_id:Vt("simulation_unknown_experiment_error"),error_type:xA("simulation_unknown_experiment_error").default("simulation_unknown_experiment_error"),message:H(),simulation_experiment_id:H().optional(),subcircuit_id:H().optional()}).describe("An unknown error occurred during the simulation experiment."),nct=OA({type:xA("simulation_op_amp"),simulation_op_amp_id:Vt("simulation_op_amp"),source_component_id:H().optional(),inverting_input_source_port_id:H(),non_inverting_input_source_port_id:H(),output_source_port_id:H(),positive_supply_source_port_id:H(),negative_supply_source_port_id:H()}).describe("Defines a simple ideal operational amplifier for simulation");ei([kat,bat,xat,Sat,Fat,Gat,dWA,EWA,zBA,uWA,hWA,pWA,fWA,yWA,DWA,SWA,bWA,RWA,xWA,kWA,GWA,FWA,mWA,wWA,Mat,_at,Rat,MWA,NWA,_WA,vat,Uat,Egt,hgt,mIt,DIt,SIt,kIt,mgt,uIt,Dgt,Zgt,Hgt,Kgt,Vgt,Rgt,Lgt,jgt,zgt,bIt,$gt,AIt,eIt,tIt,rIt,iIt,oIt,nIt,sIt,qgt,Pgt,Xgt,Ogt,Wgt,YIt,gIt,aIt,IIt,cIt,BIt,CIt,lIt,QIt,EIt,xIt,hIt,GIt,wIt,FIt,RIt,MIt,UIt,LIt,HIt,JIt,TIt,KIt,Lat,zat,Pat,Oat,Wat,Zat,qat,Xat,Vat,Hat,Agt,egt,$at,ngt,sgt,rgt,agt,cgt,ggt,Igt,qIt,ZIt,XIt,Act,ect,tct,ict,oct,nct]);var sct=Object.defineProperty,rct=(t,A)=>{for(var e in A)sct(t,e,{get:A[e],enumerable:!0})},hS={};rct(hS,{axial:()=>GBt,bga:()=>Hct,breakoutheaders:()=>KBt,cap:()=>lct,dfn:()=>cBt,diode:()=>Cct,dip:()=>Ict,electrolytic:()=>SQt,hc49:()=>PBt,jst:()=>Zlt,led:()=>Qct,lqfp:()=>JBt,m2host:()=>WQt,melf:()=>ilt,micromelf:()=>rlt,minimelf:()=>VCt,mlp:()=>Zct,ms012:()=>uBt,ms013:()=>pBt,msop:()=>oQt,pad:()=>OBt,pinrow:()=>lBt,platedhole:()=>LQt,potentiometer:()=>wQt,pushbutton:()=>_Bt,qfn:()=>Pct,qfp:()=>Wct,quad:()=>zN,radial:()=>MBt,res:()=>vct,sma:()=>clt,smb:()=>dlt,smbf:()=>xQt,smc:()=>wlt,smf:()=>Qlt,smtpad:()=>vQt,sod110:()=>jlt,sod123:()=>SBt,sod123f:()=>bCt,sod123fl:()=>FCt,sod123w:()=>rCt,sod128:()=>HCt,sod323:()=>cCt,sod323f:()=>wCt,sod323fl:()=>IQt,sod323w:()=>sQt,sod523:()=>zBt,sod723:()=>_Ct,sod80:()=>iCt,sod882:()=>dCt,sod882d:()=>$Ct,sod923:()=>QCt,soic:()=>Jct,solderjumper:()=>QQt,son:()=>lQt,sop8:()=>eCt,sot:()=>YQt,sot223:()=>blt,sot23:()=>oBt,sot23w:()=>vlt,sot25:()=>aBt,sot323:()=>RQt,sot343:()=>KQt,sot363:()=>ABt,sot457:()=>uQt,sot563:()=>EBt,sot723:()=>yBt,sot886:()=>tBt,sot89:()=>PCt,sot963:()=>pQt,ssop:()=>jct,stampboard:()=>UBt,stampreceiver:()=>YBt,to220:()=>WCt,to92:()=>VBt,to92l:()=>VQt,to92s:()=>Tlt,tqfp:()=>Oct,tssop:()=>Xct,vssop:()=>eQt});var Yi=(t,A,e)=>({type:"pcb_silkscreen_text",pcb_silkscreen_text_id:"silkscreen_text_1",font:"tscircuit2024",font_size:e,pcb_component_id:"pcb_component_1",text:"{REF}",layer:"top",anchor_position:{x:t,y:A},anchor_alignment:"center"}),Ji=OA({norefdes:ce().optional().describe("disable reference designator label"),invert:ce().optional().describe("hint to invert the orientation of the 3D model"),faceup:ce().optional().describe("The male pin header should face upwards, out of the top layer"),nosilkscreen:ce().optional().describe("omit all silkscreen elements from the footprint")}),qn=(t,A,e,i,o)=>({pcb_plated_hole_id:"",type:"pcb_plated_hole",shape:"circle",x:A,y:e,hole_diameter:mr(i),outer_diameter:mr(o),pcb_port_id:"",layers:["top","bottom"],port_hints:[t.toString()]}),uS=(t,A,e,i,o,n,s,r)=>({pcb_plated_hole_id:"",type:"pcb_plated_hole",shape:"circular_hole_with_rect_pad",x:A,y:e,hole_diameter:mr(i),hole_shape:"circle",pad_shape:"rect",rect_pad_width:mr(o),rect_pad_height:mr(n),pcb_port_id:"",layers:["top","bottom"],port_hints:[t.toString()],hole_offset_x:s,hole_offset_y:r}),PWA=Array.from({length:9},(t,A)=>Math.cos(A/8*Math.PI-Math.PI)).map(t=>({x:t,y:-Math.sqrt(1-t**2)}));function kx(t){return typeof t=="string"?t.trim().toLowerCase().endsWith("mil")?parseFloat(t)*.0254:parseFloat(t):Number(t)}var g5=ei([H(),WA()]).transform(t=>kx(t)),act=t=>Ji.extend({fn:H(),num_pins:WA().optional().default(6),wide:ce().optional(),narrow:ce().optional(),w:g5.optional(),p:g5.default(t.p??"2.54mm"),id:g5.optional(),od:g5.optional(),nosquareplating:ce().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=kx("0.55mm"),A.od=kx("0.95mm")):(A.id=kx("0.8mm"),A.od=kx("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=kx("600mil"):A.narrow?A.w=kx("300mil"):A.w=kx(t.w??"300mil")),A)),gct=act({}),OWA=(t,A,e,i,o)=>{const n=t/2,s=A<=n,r=n-1,a=i,g=a*r;return s?{x:-e/2,y:g/2-(A-1)*a}:{x:e/2,y:-g/2+(A-n-1)*a}},Ict=t=>{const A=gct.parse(t),e=[];for(let g=0;g<A.num_pins;g++){const{x:I,y:c}=OWA(A.num_pins,g+1,A.w,A.p??2.54,A.nosquareplating);if(g===0&&!A.nosquareplating){e.push(uS(g+1,I,c,A.id??"0.8mm",A.od??"1mm",A.od??"1mm"));continue}e.push(qn(g+1,I,c,A.id??"0.8mm",A.od??"1mm"))}(A.num_pins/2-1)*A.p+A.od;const o=A.w-A.od-1,n=(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:-o/2,y:-n/2},{x:-o/2,y:n/2},...PWA.map(({x:g,y:I})=>({x:g*o/6,y:I*o/6+n/2})),{x:o/2,y:n/2},{x:o/2,y:-n/2},{x:-o/2,y:-n/2}],type:"pcb_silkscreen_path",stroke_width:.1},r=[];for(let g=0;g<A.num_pins;g++){const I=g<A.num_pins/2,c=.6,{y:B}=OWA(A.num_pins,g+1,A.w,A.p??2.54,A.nosquareplating),C=I?-A.w/2-A.od/2-c:A.w/2+A.od/2+c,l=B;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:C,y:l},font_size:.3,font:"tscircuit2024",anchor_alignment:"top_left"})}const a=Yi(0,n/2+.5,.4);return{circuitJson:[...e,s,a,...r],parameters:A}},Qi=(t,A,e,i,o)=>({type:"pcb_smtpad",x:A,y:e,width:i,height:o,layer:"top",shape:"rect",pcb_smtpad_id:"",port_hints:Array.isArray(t)?t.map(n=>n.toString()):[t.toString()]}),WWA=[{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}],cct=Object.fromEntries(WWA.map(t=>[t.metric,t])),Bct=Object.fromEntries(WWA.map(t=>[t.imperial,t]));Ji.extend({tht:ce(),p:Ae.optional(),pw:Ae.optional(),ph:Ae.optional(),metric:mt.optional(),imperial:mt.optional(),w:Ae.optional(),h:Ae.optional(),textbottom:ce().optional()});var I5=t=>{let{tht:A,p:e,pw:i,ph:o,metric:n,imperial:s,w:r,h:a,textbottom:g}=t;if(typeof r=="string"&&(r=yB(r)),typeof a=="string"&&(a=yB(a)),typeof e=="string"&&(e=yB(e)),typeof i=="string"&&(i=yB(i)),typeof o=="string"&&(o=yB(o)),a!==void 0&&r!==void 0&&a>r)throw new Error("height cannot be greater than width (rotated footprint not yet implemented)");let I;if(n&&(I=cct[n]),s&&(I=Bct[s]),I&&(r=I.w_mm_min,a=I.h_mm_min,e=I.p_mm_min,i=I.pw_mm_min,o=I.ph_mm_min),e===void 0||i===void 0||o===void 0)throw new Error("Could not determine required pad dimensions (p, pw, ph)");const c={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:e/2,y:o/2+.4},{x:-e/2-i/2-.2,y:o/2+.4},{x:-e/2-i/2-.2,y:-o/2-.4},{x:e/2,y:-o/2-.4}],stroke_width:.1,pcb_silkscreen_path_id:""},B=g?-o/2-.9:o/2+.9,C=Yi(0,B,.2);return A?[qn(1,-e/2,0,i,i*1/.8),qn(2,e/2,0,i,i*1/.8),c,C]:[Qi(["1","left"],-e/2,0,i,o),Qi(["2","right"],e/2,0,i,o),c,C]},Cct=t=>({circuitJson:I5(t),parameters:t}),lct=t=>({circuitJson:I5(t),parameters:t}),Qct=t=>({circuitJson:I5(t),parameters:t}),jN=t=>{const{padSpacing:A,padWidth:e,padHeight:i,padPitch:o,numRows:n,textbottom:s}=t,r=[],a=(n-1)*(o/2);for(let x=0;x<n;x++)r.push(a-x*o);const g=[];r.forEach((x,F)=>{g.push(Qi(F+1,-A/2,x,e,i))}),r.slice().reverse().forEach((x,F)=>{g.push(Qi(F+n+1,A/2,x,e,i))});const I=Math.max(...r)+i/2+.4,c=Math.min(...r)-i/2-.4,B=-A/2-e/2-.4,C=A/2+e/2+.4,l={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:C*.5,y:I},{x:B*.5,y:I}],stroke_width:.12,pcb_silkscreen_path_id:"silkscreen_top"},Q={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:C*.5,y:c},{x:B*.5,y:c}],stroke_width:.12,pcb_silkscreen_path_id:"silkscreen_bottom"},E=-A/2,h=Math.max(...r),u=.2,d=E-e/2-.1,f=h+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},b=s?c-.9:I+.9,D=Yi(0,b,.2);return[...g,l,Q,m,D]},Ect=Ji.extend({pw:H().default("0.5mm"),ph:H().default("0.4mm"),p:H().default("0.7mm"),textbottom:ce().optional()}),hct=1,uct=t=>{const A=Ect.parse(t),e=yB(A.pw),i=yB(A.ph),o=yB(A.p);return jN({padSpacing:hct,padWidth:e,padHeight:i,padPitch:o,numRows:2,textbottom:A.textbottom})},dct=Ji.extend({pw:H().default("0.5mm"),ph:H().default("0.32mm"),p:H().default("0.5mm"),textbottom:ce().optional()}),pct=1,fct=t=>{const A=dct.parse(t),e=yB(A.pw),i=yB(A.ph),o=yB(A.p);return jN({padSpacing:pct,padWidth:e,padHeight:i,padPitch:o,numRows:4,textbottom:A.textbottom})},yct=Ji.extend({pw:H().default("0.9mm"),ph:H().default("0.4mm"),p:H().default("0.8mm"),textbottom:ce().optional()}),wct=1.7,mct=t=>{const A=yct.parse(t),e=yB(A.pw),i=yB(A.ph),o=yB(A.p);return jN({padSpacing:wct,padWidth:e,padHeight:i,padPitch:o,numRows:2,textbottom:A.textbottom})},Dct=Ji.extend({pw:H().default("0.9mm"),ph:H().default("0.4mm"),p:H().default("0.8mm"),textbottom:ce().optional()}),Sct=1.7,bct=t=>{const A=Dct.parse(t),e=yB(A.pw),i=yB(A.ph),o=yB(A.p);return jN({padSpacing:Sct,padWidth:e,padHeight:i,padPitch:o,numRows:4,textbottom:A.textbottom})},xct=Ji.extend({pw:H().default("0.7mm"),ph:H().default("0.64mm"),p:H().default("0.94mm"),textbottom:ce().optional()}),kct=1.4,Gct=t=>{const A=xct.parse(t),e=yB(A.pw),i=yB(A.ph),o=yB(A.p);return jN({padSpacing:kct,padWidth:e,padHeight:i,padPitch:o,numRows:2,textbottom:A.textbottom})},Fct=Ji.extend({pw:H().default("0.9mm"),ph:H().default("0.9mm"),p:H().default("1.34mm"),textbottom:ce().optional()}),Rct=3,Mct=t=>{const A=Fct.parse(t),e=yB(A.pw),i=yB(A.ph),o=yB(A.p);return jN({padSpacing:Rct,padWidth:e,padHeight:i,padPitch:o,numRows:4,textbottom:A.textbottom})},Nct=t=>{const A=t.array??t.x;if(typeof A=="number")return Number.isNaN(A)?void 0:A;if(typeof A=="string"){const e=Number.parseInt(A,10);return Number.isNaN(e)?void 0:e}if(typeof t.imperial=="string"){const i=t.imperial.match(/(?:array|x)(2|4)$/)?.[1];if(i)return Number.parseInt(i,10)}},_ct=t=>t?(typeof t=="number"?`${t}`:t).split("_")[0]:void 0,vct=t=>{const A=Nct(t),e=_ct(t.imperial);return A===2&&e==="0402"?{circuitJson:uct(t),parameters:t}:A===4&&e==="0402"?{circuitJson:fct(t),parameters:t}:A===2&&e==="0603"?{circuitJson:mct(t),parameters:t}:A===4&&e==="0603"?{circuitJson:bct(t),parameters:t}:A===2&&e==="0606"?{circuitJson:Gct(t),parameters:t}:A===4&&e==="1206"?{circuitJson:Mct(t),parameters:t}:{circuitJson:I5(t),parameters:t}},ZWA=(t,{x:A,y:e,radius:i})=>({type:"pcb_smtpad",x:A,y:e,radius:i,layer:"top",shape:"circle",pcb_smtpad_id:"",port_hints:Array.isArray(t)?t.map(o=>o.toString()):[t.toString()]}),VWA="ABCDEFGHIJKLMNOPQRSTUVWXYZ",jWA=H().transform(t=>{const[A,e]=t.split(/[x ]/);return{x:parseFloat(A),y:parseFloat(e)}}).pipe(OA({x:WA(),y:WA()})),Uct=H().or(be(HI())).transform(t=>Array.isArray(t)?t:(t.startsWith("(")&&t.endsWith(")")&&(t=t.slice(1,-1)),t.split(",").map(A=>{const e=Number(A);return isNaN(e)?A:e}))).pipe(be(H().or(WA()))),Lct=Ji.extend({fn:H(),num_pins:WA().optional().default(64),grid:jWA.optional(),p:mt.default("0.8mm"),w:Ae.optional(),h:Ae.optional(),ball:Ae.optional().describe("ball diameter"),pad:Ae.optional().describe("pad width/height"),circularpads:ce().optional().describe("use circular pads"),tlorigin:ce().optional(),blorigin:ce().optional(),trorigin:ce().optional(),brorigin:ce().optional(),missing:Uct.default([])}).transform(t=>{let A="tl";if(t.blorigin&&(A="bl"),t.trorigin&&(A="tr"),t.brorigin&&(A="br"),!t.grid){const i=Math.ceil(Math.sqrt(t.num_pins));t.grid={x:i,y:i}}return t.missing&&(t.missing=t.missing.map(i=>{if(typeof i=="number")return i;if(i==="center")return"center";if(i==="topleft")return"topleft";const o=i.match(/([A-Z]+)(\d+)/);if(!o)return i;const n=VWA.indexOf(o[1]),s=Number.parseInt(o[2])-1;return n*t.grid.x+s+1})),{...t,origin:A}}),Hct=t=>{const A=Lct.parse(t);let{num_pins:e,grid:i,p:o,w:n,h:s,ball:r,pad:a,missing:g}=A;r??=.75/1.27*o,a??=r*.8;const I=[],c=(g??[]).filter(m=>typeof m=="number"),B=i.x*i.y-e;if(g.length===0&&B>0&&(Math.sqrt(B)%1===0?g.push("center"):B===1&&g.push("topleft")),g?.includes("center")){const m=Math.floor(Math.sqrt(B)),b=Math.floor((i.x-m)/2),D=Math.floor((i.y-m)/2);for(let x=D;x<D+m;x++)for(let F=b;F<b+m;F++)c.push(x*i.x+F+1)}g?.includes("topleft")&&c.push(1);const C=new Set(c);let l=0;for(let m=0;m<i.y;m++)for(let b=0;b<i.x;b++){const D=(b-(i.x-1)/2)*o,x=(m-(i.y-1)/2)*o;let F=b,k=m;switch(A.origin){case"bl":F=b,k=i.y-1-m;break;case"br":F=i.x-1-b,k=i.y-1-m;break;case"tr":F=i.x-1-b,k=m;break}let v=k*i.x+F+1;if(C.has(v)){l++;continue}v-=l;const _=[v,`${VWA[k]}${F+1}`];I.push(A.circularpads?ZWA(_,{x:D,y:x,radius:a/2}):Qi(_,D,x,a,a))}const Q=Yi(0,i.y*o/2,.2),E=o/6;let h;const u=i.x*o/2,d=i.y*o/2;switch(A.origin){case"bl":h=[{x:-u,y:-d},{x:-u,y:-d-E},{x:-u-E,y:-d},{x:-u,y:-d}];break;case"br":h=[{x:u,y:-d},{x:u,y:-d-E},{x:u+E,y:-d},{x:u,y:-d}];break;case"tr":h=[{x:u,y:d},{x:u,y:d+E},{x:u+E,y:d},{x:u,y:d}];break;default:h=[{x:-u,y:d},{x:-u,y:d+E},{x:-u-E,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:h,stroke_width:.05};return{circuitJson:[...I,Q,f],parameters:A}},c5=(t,A,e,i,o)=>({type:"pcb_smtpad",x:A,y:e,width:i,height:o,radius:o/2,layer:"top",shape:"pill",pcb_smtpad_id:"",port_hints:Array.isArray(t)?t.map(n=>n.toString()):[t.toString()]}),Rm=t=>Ji.extend({fn:H(),num_pins:WA().optional().default(8),w:Ae.default(Ae.parse(t.w??"5.3mm")),p:Ae.default(Ae.parse(t.p??"1.27mm")),pw:Ae.default(Ae.parse(t.pw??"0.6mm")),pl:Ae.default(Ae.parse(t.pl??"1.0mm")),legsoutside:ce().optional().default(t.legsoutside??!1),pillpads:ce().optional().default(t.pillpads??!1),silkscreen_stroke_width:WA().optional().default(.1)}).transform(A=>(!A.pw&&!A.pl?(A.pw=Ae.parse("0.6mm"),A.pl=Ae.parse("1.0mm")):A.pw?A.pl||(A.pl=A.pw*(1/.6)):A.pw=A.pl*(.6/1),A)),Yct=Rm({}),ACA=t=>{t.widthincludeslegs!==void 0&&(t.legsoutside=!t.widthincludeslegs);const{num_pins:A,pn:e,w:i,p:o,pl:n,legsoutside:s}=t,r=A/2,a=e<=r,g=r-1,I=o,c=I*g,B=s?n/2:-n/2;return a?{x:-i/2-B,y:c/2-(e-1)*I}:{x:i/2+B,y:-c/2+(e-r-1)*I}},Jct=t=>{const A=Yct.parse(t);return{circuitJson:Gx(A),parameters:A}},Gx=t=>{const A=[];for(let r=0;r<t.num_pins;r++){const{x:a,y:g}=ACA({num_pins:t.num_pins,pn:r+1,w:t.w,p:t.p,pl:t.pl,legsoutside:t.legsoutside});t.pillpads?A.push(c5(r+1,a,g,t.pl,t.pw)):A.push(Qi(r+1,a,g,t.pl,t.pw))}const e=Math.min(1,t.p/2),i=t.w-(t.legsoutside?0:t.pl*2)-.2,o=(t.num_pins/2-1)*t.p+t.pw+e,n=Yi(0,o/2+.4,o/12),s={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",stroke_width:t.silkscreen_stroke_width??.1,route:[{x:-i/2,y:-o/2},{x:-i/2,y:o/2},...PWA.map(({x:r,y:a})=>({x:r*i/6,y:a*i/6+o/2})),{x:i/2,y:o/2},{x:i/2,y:-o/2},{x:-i/2,y:-o/2}]};return[...A,s,n]},zWA=Bt(["leftside","topside","rightside","bottomside","toppin","bottompin","leftpin","rightpin"]),Tct=({num_pins:t,cw:A,ccw:e,startingpin:i})=>{const o=[],n=t/4;let s=1;const r={};for(const a of i??[])r[a]=!0;!r.leftside&&!r.topside&&!r.rightside&&!r.bottomside&&(r.leftside=!0),!r.bottompin&&!r.leftpin&&!r.rightpin&&!r.toppin&&(r.leftside?r.toppin=!0:r.topside?r.rightpin=!0:r.rightside?r.bottompin=!0:r.bottomside&&(r.leftpin=!0)),r.leftside&&r.toppin?s=1:r.leftside&&r.bottompin?s=n:r.bottomside&&r.leftpin?s=n+1:r.bottomside&&r.rightpin?s=n*2:r.rightside&&r.bottompin?s=n*2+1:r.rightside&&r.toppin?s=n*3:r.topside&&r.rightpin?s=n*3+1:r.topside&&r.leftpin&&(s=n*4),o.push(-1);for(let a=0;a<t;a++)o[s]=a+1,e||!A?(s++,s>t&&(s=1)):(s--,s<1&&(s=t));return o},eCA=Ji.extend({fn:H(),cc:ce().default(!0).optional(),ccw:ce().default(!0).optional(),startingpin:H().or(be(zWA)).transform(t=>typeof t=="string"?t.slice(1,-1).split(","):t).pipe(be(zWA)).optional(),num_pins:WA().optional().default(64),w:Ae.optional(),h:Ae.optional(),p:Ae.default(Ae.parse("0.5mm")),pw:Ae.optional(),pl:Ae.optional(),thermalpad:ei([xA(!0),jWA]).optional(),legsoutside:ce().default(!1)}),tCA=t=>{t.w&&!t.h?t.h=t.w:!t.w&&t.h&&(t.w=t.h);const A=t.num_pins/4;if(!t.p&&!t.pw&&!t.pl&&t.w){const e=A+4;t.p=t.w/e}return!t.p&&t.w&&t.h&&t.pw&&t.pl&&(t.p=(t.w-t.pl*2)/(A-1)),!t.w&&!t.h&&t.p&&(t.w=t.p*(A+4),t.h=t.w),t.p&&!t.pw&&!t.pl?(t.pw=t.p/2,t.pl=t.p/2):t.pw?t.pl||(t.pl=t.pw*(1/.6)):t.pw=t.pl*(.6/1),t},XWA=eCA.transform(tCA),Kct=["left","bottom","right","top"],qct=t=>{const{pin_count:A,pn:e,w:i,h:o,p:n,pl:s,legsoutside:r}=t,a=A/4,g=Kct[Math.floor((e-1)/a)],I=(e-1)%a,c=n*(a-1),B=n*(a-1),C=r?s/2:-s/2;switch(g){case"left":return{x:-i/2-C+.1,y:B/2-I*n,o:"vert"};case"bottom":return{x:-c/2+I*n,y:-o/2-C+.1,o:"horz"};case"right":return{x:i/2+C-.1,y:-B/2+I*n,o:"vert"};case"top":return{x:c/2-I*n,y:o/2+C-.1,o:"horz"};default:throw new Error("Invalid pin number")}},zN=t=>{const A=XWA.parse(t),e=[],i=Tct(A),o=A.num_pins/4;for(let r=0;r<A.num_pins;r++){const{x:a,y:g,o:I}=qct({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 c=A.pw,B=A.pl;I==="vert"&&([c,B]=[B,c]);const C=i[r+1];e.push(Qi(C,a,g,c,B))}if(A.thermalpad)if(typeof A.thermalpad=="boolean"){const r=A.p*(o-1)+A.pw,a=A.p*(o-1)+A.pw;e.push(Qi(["thermalpad"],0,0,r,a))}else e.push(Qi(["thermalpad"],0,0,A.thermalpad.x,A.thermalpad.y));const n=[];for(const[r,a,g]of[["top-left",-1,1],["bottom-left",-1,-1],["bottom-right",1,-1],["top-right",1,1]]){const I=A.w/2*a,c=A.h/2*g;let B="none",C=I,l=c;const Q=A.pw*2;i[1]===1&&r==="top-left"?B="in1":i[o*4]===1&&r==="top-left"||i[o*3+1]===1&&r==="top-right"?B="in2":i[o*3]===1&&r==="top-right"||i[o]===1&&r==="bottom-left"?B="in1":i[o+1]===1&&r==="bottom-left"?B="in2":i[o*2]===1&&r==="bottom-right"?B="in1":i[o*2+1]===1&&r==="bottom-right"&&(B="in2");const E=B==="in1"?1:-1;if(A.legsoutside){const h=B==="in1"?A.pl/2:A.pw/2,u=B==="in1"?A.pw/2:A.pl/2;C+=h*a*E,l-=u*g*E}(B==="none"||A.legsoutside)&&n.push({layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:`pcb_silkscreen_path_${r}`,route:[{x:I-Q*a,y:c},{x:I,y:c},{x:I,y:c-Q*g}],type:"pcb_silkscreen_path",stroke_width:.1}),(B==="in1"||B==="in2")&&!A.legsoutside&&n.push({layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:`pcb_silkscreen_path_${r}_1`,route:[{x:I-Q*a,y:c},{x:I-Q*a/2,y:c}],type:"pcb_silkscreen_path",stroke_width:0},{layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:`pcb_silkscreen_path_${r}_2`,route:[{x:I,y:c-Q*g/2},{x:I,y:c-Q*g}],type:"pcb_silkscreen_path",stroke_width:.1}),(B==="in1"||B==="in2")&&n.push({layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:`pcb_silkscreen_path_${r}_3`,route:[{x:C-.2*-a,y:l+.2*E},{x:C,y:l},{x:C+.2*E*-a,y:l+.2},{x:C-.2*-a,y:l+.2*E}],type:"pcb_silkscreen_path",stroke_width:.1})}const s=Yi(0,A.h/2+(A.legsoutside?A.pl*1.2:.5),.3);return{circuitJson:[...e,...n,s],parameters:A}};eCA.extend({}).transform(tCA);var Pct=t=>(t.legsoutside=!1,t.pl||(t.pl=.875),t.pw||(t.pw=.25),zN(t)),Oct=t=>{if(t.legsoutside=!0,!t.p)switch(t.num_pins){case 32:t.p=.8;break;case 44:case 48:t.p=.5;break;case 64:case 80:case 100:t.p=.5;break;case 144:t.p=.5;break}if(!t.pl)switch(t.num_pins){case 32:case 44:case 48:case 64:case 80:case 100:t.pl=1.475;break;case 144:t.pl=1.6;break}if(!t.pw)switch(t.num_pins){case 32:t.pw=.55;break;case 44:case 48:case 64:case 80:case 100:t.pw=.3;break;case 144:t.pw=.25;break}return zN(t)},Wct=t=>{t.legsoutside=!0;const A=XWA.parse(t);if(!t.p)switch(t.num_pins){case 44:case 64:t.p=.8;break;case 52:t.w===14?t.p=1:t.p=.65;break;case 208:t.p=.5;break}if(!t.pl)switch(t.num_pins){case 44:case 52:case 64:t.pl=2.25;break;case 208:t.pl=1.65;break;default:t.pl=A.pl*4;break}if(!t.pw)switch(t.num_pins){case 44:case 64:t.pw=.5;break;case 52:t.w===14?t.pw=.45:t.pw=.55;break;case 208:t.pw=.3;break;default:t.pw=A.pw;break}return zN(t)};eCA.extend({}).transform(tCA);var Zct=t=>(t.legsoutside=!1,t.thermalpad===void 0&&(t.thermalpad=!0),zN(t)),Vct=Rm({w:"3.9mm",p:"1.27mm"}),jct=t=>{const A=Vct.parse(t);return{circuitJson:Gx(A),parameters:A}},zct=Rm({w:"7.1mm",p:"0.65mm",pl:"1.35mm",pw:"0.40mm",legsoutside:!0}),Xct=t=>{const A=zct.parse(t);return{circuitJson:Gx(A),parameters:A}},$ct=Rm({}),ABt=t=>{const A=$ct.parse({fn:"sot363",num_pins:6,w:2.56,p:.65,pw:.4,pl:.65,legoutside:!0});return{circuitJson:Gx(A),parameters:A}},eBt=Ji.extend({fn:H(),num_pins:xA(6).default(6),w:H().default("1.01mm"),h:H().default("1.45mm"),p:H().default("0.5mm"),pl:H().default("0.33mm"),pw:H().default("0.27mm"),string:H().optional()}),tBt=t=>{const A=eBt.parse({fn:"sot886",...t}),e=Ae.parse(A.w),i=Ae.parse(A.h),o=Ae.parse(A.p),n=Ae.parse(A.pl),s=Ae.parse(A.pw),r=[];for(let C=0;C<6;C++){const{x:l,y:Q}=$WA(C+1,e,o,n);r.push(Qi(C+1,l,Q,n,s))}const a={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-e/2,y:i/2},{x:e/2,y:i/2}],stroke_width:.05,pcb_silkscreen_path_id:""},g={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-e/2,y:-i/2},{x:e/2,y:-i/2}],stroke_width:.05,pcb_silkscreen_path_id:""},I=$WA(1,e,o,n),c={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"pin_marker_1",route:[{x:I.x-n/2-.3,y:I.y},{x:I.x-n/2-.45,y:I.y+.15},{x:I.x-n/2-.45,y:I.y-.15},{x:I.x-n/2-.3,y:I.y}],stroke_width:.05,pcb_silkscreen_path_id:"pin_marker_1"},B=Yi(0,i/2+.4,.25);return{circuitJson:[...r,a,g,B,c],parameters:A}},$WA=(t,A,e,i)=>{const o=A/2-i/2;return t<=3?{x:-o,y:e-(t-1)*e}:{x:o,y:-e+(t-4)*e}},AZA=Ji.extend({fn:H(),num_pins:WA().default(3),w:H().default("1.92mm"),h:H().default("2.74mm"),pl:H().default("1.32mm"),pw:H().default("0.6mm"),p:H().default("0.95mm"),string:H().optional()}),iBt=Rm({p:"0.95mm",w:"1.6mm",legsoutside:!0}),oBt=t=>{const A=t.string?.match(/^sot23_(\d+)/),e=A?Number.parseInt(A[1],10):3;if(e===6||e===8){const o=iBt.parse({...t,num_pins:e});return{circuitJson:Gx(o),parameters:o}}const i=AZA.parse({...t,num_pins:e});if(i.num_pins===3)return{circuitJson:sBt(i),parameters:i};if(i.num_pins===5)return{circuitJson:tZA(i),parameters:i};throw new Error("Invalid number of pins")},nBt=t=>{const{pn:A,p:e}=t;return A===1?{x:-1.155,y:e}:A===2?{x:-1.155,y:-e}:{x:1.15,y:0}},sBt=t=>{const A=[];for(let i=0;i<t.num_pins;i++){const{x:o,y:n}=nBt({num_pins:t.num_pins,pn:i+1,w:Number.parseFloat(t.w),h:Number.parseFloat(t.h),pl:Number.parseFloat(t.pl),p:Number.parseFloat(t.p)});A.push(Qi(i+1,o,n,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}const e=Yi(0,Number.parseInt(t.h),.3);return[...A,e]},eZA=t=>{const{p:A,h:e,pn:i}=t;if(i===1)return{x:-e/2-.5,y:A};if(i===2)return{x:-e/2-.5,y:0};if(i===3)return{x:-e/2-.5,y:-A};if(i===4)return{x:e/2+.5,y:-A};if(i===5)return{x:e/2+.5,y:A};throw new Error("Invalid pin number")},tZA=t=>{const A=[];for(let c=1;c<=t.num_pins;c++){const{x:B,y:C}=eZA({h:Number.parseFloat(t.h),p:Number.parseFloat(t.p),pn:c});A.push(Qi(c,B,C,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}const e=(t.num_pins+1)/2*Number.parseFloat(t.p),i=Number.parseFloat(t.h),o={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-e/3,y:i/2+Number.parseFloat(t.p)/1.3},{x:e/3,y:i/2+Number.parseFloat(t.p)/1.3}],type:"pcb_silkscreen_path",stroke_width:.05},n={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_2",route:[{x:-e/3,y:-i/2-Number.parseFloat(t.p)/1.3},{x:e/3,y:-i/2-Number.parseFloat(t.p)/1.3}],type:"pcb_silkscreen_path",stroke_width:.05},s=Yi(0,i+.3,.3),r=eZA({h:Number.parseFloat(t.h),p:Number.parseFloat(t.p),pn:1});r.x=r.x-Number.parseFloat(t.pw)*1.5;const a=.3,g=.4,I={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,o,n,I]},rBt=AZA.extend({}),aBt=t=>{const A=rBt.parse({...t,num_pins:5});return{circuitJson:tZA(A),parameters:A}},gBt=[{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}],IBt=Rm({}),cBt=t=>{const A=IBt.parse(t),e=[];for(let c=0;c<A.num_pins;c++){const{x:B,y:C}=ACA({num_pins:A.num_pins,pn:c+1,w:A.w,p:A.p??1.27,pl:A.pl,widthincludeslegs:!0});e.push(Qi(c+1,B,C,A.pl??"1mm",A.pw??"0.6mm"))}const i=Math.min(1,A.p/2),o=A.w+i,n=(A.num_pins/2-1)*A.p+A.pw+i,s=[];for(const c of gBt){const{dx:B,dy:C}=c;s.push({layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"",route:[{x:B*o/2-B*A.p,y:C*n/2},{x:B*o/2,y:C*n/2},{x:B*o/2,y:C*n/2-C*A.p}],type:"pcb_silkscreen_path",stroke_width:.1})}const r=A.p/4,a=-o/2-r/2,g=n/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 I=Yi(0,n/2+.4,n/12);return{circuitJson:[...e,I,...s],parameters:A}},iCA=({fs:t,pn:A,anchor_x:e,anchor_y:i,textalign:o="center",orthogonal:n=!1,verticallyinverted:s=!1,layer:r="top"})=>{let a=0;n&&s?a=270:s?a=180:n?a=90:a=0;let g="center";return o==="left"&&(s?g="center_right":g="center_left"),o==="right"&&(s?g="center_left":g="center_right"),r==="bottom"&&(g==="center_left"?g="center_right":g==="center_right"&&(g="center_left")),{type:"pcb_silkscreen_text",pcb_silkscreen_text_id:"silkscreen_text_1",font:"tscircuit2024",font_size:t,pcb_component_id:"pcb_component_1",text:`{PIN${A}}`,layer:r,anchor_position:{x:e,y:i},anchor_alignment:g,ccw_rotation:a}};function BBt({pinlabeltextalignleft:t,pinlabeltextalignright:A,pinlabelorthogonal:e}){let i="top";return e?i="left":i="top",t&&(e?i="bottom":i="right"),A&&(e?i="top":i="left"),i}var CBt=Ji.extend({fn:H(),num_pins:WA().optional().default(6),rows:ei([H(),WA()]).transform(t=>Number(t)).optional().default(1).describe("number of rows"),p:Ae.default("0.1in").describe("pitch"),id:Ae.default("1.0mm").describe("inner diameter"),od:Ae.default("1.5mm").describe("outer diameter"),male:ce().optional().describe("for male pin headers"),female:ce().optional().describe("for female pin headers"),smd:ce().optional().describe("surface mount device"),surfacemount:ce().optional().describe("surface mount device (verbose)"),rightangle:ce().optional().describe("right angle"),pw:Ae.optional().default("1.0mm").describe("pad width for SMD"),pl:Ae.optional().default("2.0mm").describe("pad length for SMD"),pinlabeltextalignleft:ce().optional().default(!1),pinlabeltextaligncenter:ce().optional().default(!1),pinlabeltextalignright:ce().optional().default(!1),pinlabelverticallyinverted:ce().optional().default(!1),pinlabelorthogonal:ce().optional().default(!1),nosquareplating:ce().optional().default(!1).describe("do not use rectangular pad for pin 1"),nopinlabels:ce().optional().default(!1).describe("omit silkscreen pin labels"),doublesidedpinlabel:ce().optional().default(!1).describe("add silkscreen pins in top and bottom layers"),bottomsidepinlabel:ce().optional().default(!1).describe("place the silkscreen reference text on the bottom layer instead of top")}).transform(t=>{const A=BBt(t);return{...t,pinlabelAnchorSide:A,male:t.male??!t.female,female:t.female??!1,smd:t.smd??t.surfacemount??!1,rightangle:t.rightangle??!1}}).superRefine((t,A)=>{t.male&&t.female&&A.addIssue({code:Ot.custom,message:"'male' and 'female' cannot both be true; it should be male or female.",path:["male","female"]})}),lBt=t=>{const A=CBt.parse(t),{p:e,id:i,od:o,rows:n,num_pins:s,pinlabelAnchorSide:r,pinlabelverticallyinverted:a,pinlabelorthogonal:g,pinlabeltextalignleft:I,pinlabeltextalignright:c,nopinlabels:B,doublesidedpinlabel:C,bottomsidepinlabel:l}=A;let Q="center";I?Q="left":c&&(Q="right");const E=[],h=Math.ceil(s/n),u=-e,d=({xoff:x,yoff:F,od:k,anchorSide:v,smd:_,pw:Y,pl:P})=>{let T=0,O=0;if(_){const W=k/5;switch(v){case"right":T=Y/2+W;break;case"top":O=P/2+W;break;case"bottom":O=-(P/2+W);break;case"left":T=-(Y/2+W);break}}else{const W=k*.75;switch(v){case"right":T=W;break;case"top":O=W;break;case"bottom":O=-W;break;case"left":T=-W;break}}return{anchor_x:x+T,anchor_y:F+O}},f=(x,F,k)=>{A.smd?E.push(Qi(x,F,k,A.pw,A.pl)):x===1&&!A.nosquareplating?E.push(uS(x,F,k,i,o,o,0,0)):E.push(qn(x,F,k,i,o));const{anchor_x:v,anchor_y:_}=d({xoff:F,yoff:k,od:o,anchorSide:r,smd:A.smd,pw:A.pw,pl:A.pl});B||(l?E.push(iCA({fs:o/5,pn:x,anchor_x:v,anchor_y:_,textalign:Q,orthogonal:g,verticallyinverted:a,layer:"bottom"})):E.push(iCA({fs:o/5,pn:x,anchor_x:v,anchor_y:_,textalign:Q,orthogonal:g,verticallyinverted:a,layer:"top"})),C&&E.push(iCA({fs:o/5,pn:x,anchor_x:v,anchor_y:_,textalign:Q,orthogonal:g,verticallyinverted:a,layer:"bottom"})))},m=new Set,b=n>2&&h>2;if(n===1){const x=-((s-1)/2)*e;for(let F=0;F<s;F++){const k=F+1,v=x+F*e,_=`${v},0`;if(m.has(_))throw new Error(`Overlap at ${_}`);m.add(_),f(k,v,0)}}else if(b){const x=-((h-1)/2)*e;let F=1;for(let k=0;k<n&&F<=s;k++)for(let v=0;v<h&&F<=s;v++){const _=x+v*e,Y=k*u,P=`${_},${Y}`;if(m.has(P))throw new Error(`Overlap at ${P}`);m.add(P),f(F++,_,Y)}}else{const x=-((h-1)/2)*e;let F=1,k=0,v=n-1,_=0,Y=h-1;for(;F<=s&&k<=v&&_<=Y;){for(let P=k;P<=v&&F<=s;P++){const T=x+_*e,O=P*u,W=`${T},${O}`;if(m.has(W))throw new Error(`Overlap at ${W}`);m.add(W),f(F++,T,O)}_++;for(let P=_;P<=Y&&F<=s;P++){const T=x+P*e,O=v*u,W=`${T},${O}`;if(m.has(W))throw new Error(`Overlap at ${W}`);m.add(W),f(F++,T,O)}if(v--,_<=Y){for(let P=v;P>=k&&F<=s;P--){const T=x+Y*e,O=P*u,W=`${T},${O}`;if(m.has(W))throw new Error(`Overlap at ${W}`);m.add(W),f(F++,T,O)}Y--}if(k<=v){for(let P=Y;P>=_&&F<=s;P--){const T=x+P*e,O=k*u,W=`${T},${O}`;if(m.has(W))throw new Error(`Overlap at ${W}`);m.add(W),f(F++,T,O)}k++}}if(F-1<s)throw new Error(`Missing pins: assigned ${F-1}, expected ${s}`)}const D=Yi(0,e,.5);return{circuitJson:[...E,D],parameters:A}},QBt=Ji.extend({fn:H(),num_pins:xA(6).default(6),w:H().default("2.1mm"),h:H().default("2.45mm"),p:H().default("0.5mm"),pl:H().default("0.675mm"),pw:H().default("0.35mm"),string:H().optional()}),EBt=t=>{const A=QBt.parse({...t,fn:"sot563"}),e=Ae.parse(A.w),i=Ae.parse(A.h),o=Ae.parse(A.p),n=Ae.parse(A.pl),s=Ae.parse(A.pw),r=[];for(let C=0;C<6;C++){const{x:l,y:Q}=iZA(C+1,e,o,n);r.push(Qi(C+1,l,Q,n,s))}const a={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-e/2,y:i/2},{x:e/2,y:i/2}],stroke_width:.05,pcb_silkscreen_path_id:""},g={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-e/2,y:-i/2},{x:e/2,y:-i/2}],stroke_width:.05,pcb_silkscreen_path_id:""},I=iZA(1,e,o,n),c={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"pin_marker_1",route:[{x:I.x-n/2-.3,y:I.y},{x:I.x-n/2-.45,y:I.y+.15},{x:I.x-n/2-.45,y:I.y-.15},{x:I.x-n/2-.3,y:I.y}],stroke_width:.05,pcb_silkscreen_path_id:"pin_marker_1"},B=Yi(0,i/2+.4,.25);return{circuitJson:[...r,a,g,B,c],parameters:A}},iZA=(t,A,e,i)=>{const o=A/2-i/2;return t<=3?{x:-o,y:e-(t-1)*e}:{x:o,y:-e+(t-4)*e}},hBt=Rm({p:"1.27mm",w:"3.9mm",legsoutside:!0}),uBt=t=>{const A=hBt.parse({...t,num_pins:8});return{circuitJson:Gx(A),parameters:A}},dBt=Rm({p:"1.27mm",w:"7.5mm",legsoutside:!0}),pBt=t=>{const A=dBt.parse({...t,num_pins:16});return{circuitJson:Gx(A),parameters:A}},fBt=Ji.extend({fn:H(),num_pins:xA(3).default(3),w:H().default("1.2mm"),h:H().default("1.2mm"),pw:H().default("0.40mm"),pl:H().default("0.45mm"),p:H().default("0.575mm")}),yBt=t=>{const A=fBt.parse(t),e=mBt(A),i=Yi(0,Ae.parse(A.h),.2);return{circuitJson:[...e,i],parameters:A}},wBt=t=>{const{pn:A,p:e}=t;return A===1?{x:e,y:0}:A===2?{x:-e,y:-.4}:{x:-e,y:.4}},mBt=t=>{const A=[];for(let e=0;e<3;e++){const{x:i,y:o}=wBt({num_pins:t.num_pins,pn:e+1,w:Number.parseFloat(t.w),h:Number.parseFloat(t.h),pl:Number.parseFloat(t.pl),p:Number.parseFloat(t.p)});A.push(Qi(e+1,i,o,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},DBt=Ji.extend({fn:H(),num_pins:xA(2).default(2),w:H().default("2.36mm"),h:H().default("1.22mm"),pl:H().default("0.9mm"),pw:H().default("1.2mm"),p:H().default("3.30mm")}),SBt=t=>{const A=DBt.parse(t),e=Yi(0,Ae.parse(A.h)/4+.4,.3);return{circuitJson:xBt(A).concat(e),parameters:A}},bBt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},xBt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:o}=bBt({pn:e,p:Number.parseFloat(t.p)});A.push(Qi(e,i,o,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},kBt=Ji.extend({fn:H(),p:Ae.optional().default("2.54mm"),id:Ae.optional().default("0.7mm"),od:Ae.optional().default("1.4mm")}),GBt=t=>{const A=kBt.parse(t),{p:e,id:i,od:o}=A,n=[qn(1,-e/2,0,i,o),qn(2,e/2,0,i,o)],s={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-e/2+o+i/2,y:0},{x:e/2-o-i/2,y:0}],stroke_width:.1,pcb_silkscreen_path_id:""},r=Yi(0,1.5,.5);return{circuitJson:[...n,s,r],parameters:A}},FBt=(t,A,e,i,o,n=.1)=>{const s=[],r=[],a=Math.max(1,Math.ceil(Math.PI*e/n)),g=Math.PI/a;for(let I=0;I<=a;I++){const c=I*g,B=t+Math.cos(c)*e,C=A+Math.sin(c)*e;B<t-i&&C>=A-o/2&&C<=A+o/2||s.push({x:B,y:C})}for(let I=0;I<=a;I++){const c=Math.PI+I*g,B=t+Math.cos(c)*e,C=A+Math.sin(c)*e;B<t-i&&C>=A-o/2&&C<=A+o/2||r.push({x:B,y:C})}return{topArc:s,bottomArc:r}},RBt=Ji.extend({fn:H(),p:Ae.optional().default("5mm"),id:Ae.optional().default("0.8mm"),od:Ae.optional().default("1.6mm"),ceramic:ce().optional(),electrolytic:ce().optional(),polarized:ce().optional()}),MBt=t=>{const A=RBt.parse(t),{p:e,id:i,od:o}=A;i===.8&&o===1.6&&(A.id=e===5?.8:e*.25,A.od=e===5?1.6:e*.5);const n=[qn(1,-e/2,0,A.id,A.od),qn(2,e/2,0,A.id,A.od)],s=e+.1,{topArc:r,bottomArc:a}=FBt(0,0,s,A.od/2,A.od),g=.02*e,I={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:r,stroke_width:g,pcb_silkscreen_path_id:""},c={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:a,stroke_width:g,pcb_silkscreen_path_id:""},B={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:""},C=.1*e,l=-(e+C+.04*e),Q=s-C-.08*e,E={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:l-C,y:Q},{x:l+C,y:Q}],stroke_width:g,pcb_silkscreen_path_id:""},h={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:l,y:Q-C},{x:l,y:Q+C}],stroke_width:g,pcb_silkscreen_path_id:""},u=Yi(0,s+.12*e,.1*e),d=[...n,I,c,B,u];return(A.electrolytic===!0||A.polarized===!0)&&d.push(E,h),{circuitJson:d,parameters:A}},B5=(t,A={})=>({type:"pcb_silkscreen_path",layer:A.layer||"top",pcb_component_id:A.pcb_component_id||"",pcb_silkscreen_path_id:A.pcb_silkscreen_path_id||"",route:t,stroke_width:A.stroke_width||.1}),NBt=Ji.extend({fn:xA("pushbutton"),w:Ae.default(4.5),h:Ae.default(6.5),id:Ae.default(1),od:Ae.default(1.2)}),_Bt=t=>{const A=NBt.parse(t),e=A.w,i=A.h,o=A.id,n=[qn(1,-e/2,i/2,o,o*1.5),qn(2,-e/2,-i/2,o,o*1.5),qn(3,e/2,-i/2,o,o*1.5),qn(4,e/2,i/2,o,o*1.5)],s=[B5([{x:-e/2,y:-i/2},{x:-e/2,y:i/2}]),B5([{x:e/2,y:-i/2},{x:e/2,y:i/2}]),B5([{x:-e/2,y:0},{x:-e/5,y:0},{x:e/5*1/Math.sqrt(2),y:i/8}]),B5([{x:e/2,y:0},{x:e/5,y:0}])],r=Yi(0,i/2+.4,.5);return{circuitJson:[...n,...s,r],parameters:A}},oZA=Ji.extend({fn:H(),w:Ae.default("22.58mm"),h:Ae.optional(),left:Ae.optional().default(20),right:Ae.optional().default(20),top:Ae.optional().default(2),bottom:Ae.optional().default(2),p:Ae.default(Ae.parse("2.54mm")),pw:Ae.default(Ae.parse("1.6mm")),pl:Ae.default(Ae.parse("2.4mm")),innerhole:ce().default(!1),innerholeedgedistance:Ae.default(Ae.parse("1.61mm")),silkscreenlabels:ce().default(!1),silkscreenlabelmargin:Ae.default(Ae.parse("0.1mm"))}),vBt=t=>{const A=oZA.parse(t);return A.left&&A.right?Math.max(A.left,A.right)*A.p:A.left?A.left*A.p:A.right?A.right*A.p:51},C5=(t,A,e)=>{let i=[];return e==="right"&&(i=[{x:t+1/2,y:A},{x:t-1/2,y:A+.6/2},{x:t-1/2,y:A-.6/2},{x:t+1/2,y:A}]),e==="left"&&(i=[{x:t-1/2,y:A},{x:t+1/2,y:A+.6/2},{x:t+1/2,y:A-.6/2},{x:t-1/2,y:A}]),e==="top"&&(i=[{x:t,y:A+1/2},{x:t-.6/2,y:A-1/2},{x:t+.6/2,y:A-1/2},{x:t,y:A+1/2}]),e==="bottom"&&(i=[{x:t,y:A-1/2},{x:t-.6/2,y:A+1/2},{x:t+.6/2,y:A+1/2},{x:t,y:A-1/2}]),i},UBt=t=>{const A=oZA.parse(t),e=A.h??vBt(A),i=[],o=[],n=[];let s=[];const r=1,a=r,g=A.left+A.right+(A.bottom??0)+(A.top??0),c=`pin${g}`.length*.7/2;if(A.right){const Q=-((A.right-1)/2)*A.p;for(let E=0;E<A.right;E++){if(E===0&&!A.left&&!A.bottom&&!A.silkscreenlabels&&(s=C5(A.w/2-A.pl*1.4,Q+E*A.p,"right")),i.push(Qi(E+1+A.left+(A.bottom??0),A.w/2-A.pl/2,Q+E*A.p,A.pl,A.pw)),A.silkscreenlabels){const h=E+1+A.left+(A.bottom??0),u=`pin${h}`;n.push({type:"pcb_silkscreen_text",pcb_silkscreen_text_id:`pin_${h}`,pcb_component_id:"1",layer:"top",anchor_position:{x:A.w/2-A.pl-(c+A.silkscreenlabelmargin),y:Q+E*A.p},text:u,font_size:.7,font:"tscircuit2024",anchor_alignment:"center"})}A.innerhole&&(o.push(qn(E+1+A.left+(A.bottom??0)+g,A.w/2,Q+E*A.p,r,a)),o.push(qn(E+1+A.left+(A.bottom??0)+g*2,A.w/2-A.innerholeedgedistance,Q+E*A.p,r,a)))}}if(A.left){const Q=(A.left-1)/2*A.p;for(let E=0;E<A.left;E++){if(E===0&&!A.silkscreenlabels&&(s=C5(-A.w/2+A.pl*1.4,Q-E*A.p,"left")),i.push(Qi(E+1,-A.w/2+A.pl/2,Q-E*A.p,A.pl,A.pw)),A.silkscreenlabels){const h=E+1,u=`pin${h}`;n.push({type:"pcb_silkscreen_text",pcb_silkscreen_text_id:`pin_${h}`,pcb_component_id:"1",layer:"top",anchor_position:{x:-A.w/2+A.pl+(c+A.silkscreenlabelmargin),y:Q-E*A.p},text:u,font_size:.7,font:"tscircuit2024",anchor_alignment:"center"})}A.innerhole&&(o.push(qn(E+1+g,-A.w/2,Q-E*A.p,r,a)),o.push(qn(E+1+g*2,-A.w/2+A.innerholeedgedistance,Q-E*A.p,r,a)))}}if(A.top){const Q=(A.top-1)/2*A.p;for(let E=0;E<A.top;E++){if(E===0&&!A.left&&!A.bottom&&!A.right&&!A.silkscreenlabels&&(s=C5(Q-E*A.p,e/2-A.pl*1.4,"top")),i.push(Qi(E+1+A.left+A.right+(A.bottom??0),Q-E*A.p,e/2-A.pl/2,A.pw,A.pl)),A.silkscreenlabels){const h=E+1+A.left+A.right+(A.bottom??0),u=`pin${h}`;n.push({type:"pcb_silkscreen_text",pcb_silkscreen_text_id:`pin_${h}`,pcb_component_id:"1",layer:"top",anchor_position:{x:Q-E*A.p,y:e/2-A.pl-(c+A.silkscreenlabelmargin)},text:u,font_size:.7,font:"tscircuit2024",anchor_alignment:"center",ccw_rotation:270})}A.innerhole&&(o.push(qn(E+1+A.left+A.right+(A.bottom??0)+g,Q-E*A.p,e/2,r,a)),o.push(qn(E+1+A.left+A.right+(A.bottom??0)+g*2,Q-E*A.p,e/2-A.innerholeedgedistance,r,a)))}}if(A.bottom){const Q=-((A.bottom-1)/2)*A.p;for(let E=0;E<A.bottom;E++){if(E===0&&!A.left&&!A.silkscreenlabels&&(s=C5(Q+E*A.p,-e/2+A.pl*1.4,"bottom")),i.push(Qi(E+1+A.left,Q+E*A.p,-e/2+A.pl/2,A.pw,A.pl)),A.silkscreenlabels){const h=E+1+A.left,u=`pin${h}`;n.push({type:"pcb_silkscreen_text",pcb_silkscreen_text_id:`pin_${h}`,pcb_component_id:"1",layer:"top",anchor_position:{x:Q+E*A.p,y:-e/2+A.pl+(c+A.silkscreenlabelmargin)},text:u,font_size:.7,font:"tscircuit2024",anchor_alignment:"center",ccw_rotation:90})}A.innerhole&&(o.push(qn(E+1+A.left+g,Q+E*A.p,-e/2,r,a)),o.push(qn(E+1+A.left+g*2,Q+E*A.p,-e/2+A.innerholeedgedistance,r,a)))}}const B={type:"pcb_silkscreen_path",pcb_silkscreen_path_id:"pcb_silkscreen_triangle_1",pcb_component_id:"2",route:s,stroke_width:.1,layer:"top"},C={type:"pcb_silkscreen_path",pcb_silkscreen_path_id:"pcb_silkscreen_path_1",pcb_component_id:"1",route:[{x:-A.w/2,y:e/2},{x:A.w/2,y:e/2},{x:A.w/2,y:-e/2},{x:-A.w/2,y:-e/2},{x:-A.w/2,y:e/2}],stroke_width:.1,layer:"top"},l=Yi(0,e/1.8,e/25);return{circuitJson:[...i,...o,...n,C,...A.silkscreenlabels?[]:[B],l],parameters:A}},nZA=Ji.extend({fn:H(),w:Ae.default("22.58mm"),h:Ae.optional(),left:Ae.optional().default(20),right:Ae.optional().default(20),top:Ae.optional().default(2),bottom:Ae.optional().default(2),p:Ae.default(Ae.parse("2.54mm")),pw:Ae.default(Ae.parse("1.6mm")),pl:Ae.default(Ae.parse("3.2mm")),innerhole:ce().default(!1),innerholeedgedistance:Ae.default(Ae.parse("1.61mm"))}),LBt=t=>{const A=nZA.parse(t);return A.left&&A.right?Math.max(A.left,A.right)*A.p:A.left?A.left*A.p:A.right?A.right*A.p:51},HBt=(t,A,e,i=1,o=.6)=>{const n=i/2,s=o/2;return{left:[{x:t+n,y:A},{x:t-n,y:A+s},{x:t-n,y:A-s},{x:t+n,y:A}],right:[{x:t-n,y:A},{x:t+n,y:A+s},{x:t+n,y:A-s},{x:t-n,y:A}],top:[{x:t,y:A-n},{x:t-s,y:A+n},{x:t+s,y:A+n},{x:t,y:A-n}],bottom:[{x:t,y:A+n},{x:t-s,y:A-n},{x:t+s,y:A-n},{x:t,y:A+n}]}[e]},YBt=t=>{const A=nZA.parse(t),e=A.h??LBt(A),i=[],o=[],n=[],s=1,r=1.2,a=A.left+A.right+(A.bottom??0)+(A.top??0);let g=[],I=1;if(A.left){const l=(A.left-1)/2*A.p;for(let Q=0;Q<A.left;Q++)Q===0&&(g=HBt(-A.w/2-A.pl/2,l-Q*A.p,"left")),i.push(Qi(I,-A.w/2+A.pl/2,l-Q*A.p,A.pl,A.pw)),o.push({type:"pcb_silkscreen_text",pcb_silkscreen_text_id:`pin_${I}`,pcb_component_id:"1",layer:"top",anchor_position:{x:-A.w/2+A.pl/2-4.5,y:l-Q*A.p},text:`pin${I}`,font_size:.7,font:"tscircuit2024",anchor_alignment:"center"}),I++,A.innerhole&&n.push(qn(I+a,-A.w/2+A.innerholeedgedistance,l-Q*A.p,s,r))}if(A.bottom){const l=(A.bottom-1)/2*A.p;for(let Q=A.bottom-1;Q>=0;Q--)i.push(Qi(I,l-Q*A.p,-e/2+A.pl/2,A.pw,A.pl)),o.push({type:"pcb_silkscreen_text",pcb_silkscreen_text_id:`pin_${I}`,pcb_component_id:"1",layer:"top",anchor_position:{x:l-Q*A.p,y:-e/2+A.pl/2-3.2},text:`pin${I}`,font_size:.7,font:"tscircuit2024",anchor_alignment:"center"}),I++,A.innerhole&&n.push(qn(I+a,l-Q*A.p,-e/2+A.innerholeedgedistance,s,r))}if(A.right){const l=-((A.right-1)/2)*A.p;for(let Q=0;Q<A.right;Q++)i.push(Qi(I,A.w/2-A.pl/2,l+Q*A.p,A.pl,A.pw)),o.push({type:"pcb_silkscreen_text",pcb_silkscreen_text_id:`pin_${I}`,pcb_component_id:"1",layer:"top",anchor_position:{x:A.w/2-A.pl/2+3.7,y:l+Q*A.p},text:`pin${I}`,font_size:.7,font:"tscircuit2024",anchor_alignment:"center"}),I++,A.innerhole&&n.push(qn(I+a,A.w/2-A.innerholeedgedistance,l+Q*A.p,s,r))}if(A.top){const l=-((A.top-1)/2)*A.p;for(let Q=A.top-1;Q>=0;Q--)i.push(Qi(I,l+Q*A.p,e/2-A.pl/2,A.pw,A.pl)),o.push({type:"pcb_silkscreen_text",pcb_silkscreen_text_id:`pin_${I}`,pcb_component_id:"1",layer:"top",anchor_position:{x:l+Q*A.p,y:e/2-A.pl/2+3.2},text:`pin${I}`,font_size:.7,font:"tscircuit2024",anchor_alignment:"center"}),I++,A.innerhole&&n.push(qn(I+a,l+Q*A.p,e/2-A.innerholeedgedistance,s,r))}const c={type:"pcb_silkscreen_path",pcb_silkscreen_path_id:"1",pcb_component_id:"1",layer:"top",route:g,stroke_width:.1},B={type:"pcb_silkscreen_path",pcb_silkscreen_path_id:"pcb_silkscreen_path_1",pcb_component_id:"1",route:[{x:-A.w/2-A.pl/3,y:e/2+A.pl/3},{x:A.w/2+A.pl/3,y:e/2+A.pl/3},{x:A.w/2+A.pl/3,y:-e/2-A.pl/3},{x:-A.w/2-A.pl/3,y:-e/2-A.pl/3},{x:-A.w/2-A.pl/3,y:e/2+A.pl/3}],stroke_width:.1,layer:"top"},C=Yi(0,e/1.8,e/25);return{circuitJson:[...n,...i,...o,B,c,C],parameters:A}},JBt=t=>(t.legsoutside=!0,t.pl||(t.pl=1.5),t.pw||(t.pw=.3),zN(t)),sZA=Ji.extend({fn:H(),w:Ae.default("10mm"),h:Ae.optional(),left:Ae.optional().default(20),right:Ae.optional().default(20),top:Ae.optional().default(0),bottom:Ae.optional().default(0),p:Ae.default(Ae.parse("2.54mm")),id:Ae.optional().default(Ae.parse("1mm")),od:Ae.optional().default(Ae.parse("1.5mm"))}),TBt=t=>{const A=sZA.parse(t);return A.left&&A.right?Math.max(A.left,A.right)*A.p:A.left?A.left*A.p:A.right?A.right*A.p:51},l5=(t,A,e,i=1,o=.6)=>{const n=i/2,s=o/2;return{left:[{x:t+n,y:A},{x:t-n,y:A+s},{x:t-n,y:A-s},{x:t+n,y:A}],right:[{x:t-n,y:A},{x:t+n,y:A+s},{x:t+n,y:A-s},{x:t-n,y:A}],top:[{x:t,y:A-n},{x:t-s,y:A+n},{x:t+s,y:A+n},{x:t,y:A-n}],bottom:[{x:t,y:A+n},{x:t-s,y:A-n},{x:t+s,y:A-n},{x:t,y:A+n}]}[e]},KBt=t=>{const A=sZA.parse(t),e=A.h??TBt(A),i=[],o=A.id,n=A.od;let s=[];if(A.right){const I=-((A.right-1)/2)*A.p;for(let c=0;c<A.right;c++)c===0&&!A.left&&!A.bottom&&(s=l5(A.w/2+n*1.4,I+c*A.p,"right")),i.push(qn(c+1+A.left+(A.bottom??0),A.w/2,I+c*A.p,o,n))}if(A.left){const I=-((A.left-1)/2)*A.p;for(let c=0;c<A.left;c++)c===A.left-1&&(s=l5(-A.w/2-n*1.4,I+c*A.p,"left")),i.push(qn(c+1,-A.w/2,I+c*A.p,o,n))}if(A.top){const I=-((A.top-1)/2)*A.p;for(let c=0;c<A.top;c++)c===A.top-1&&!A.left&&!A.bottom&&!A.right&&(s=l5(I+c*A.p,e/2+n*1.4,"top")),i.push(qn(c+1+A.right+(A.bottom??0)+A.left,I+c*A.p,e/2,o,n))}if(A.bottom){const I=-((A.bottom-1)/2)*A.p;for(let c=0;c<A.bottom;c++)c===0&&!A.left&&(s=l5(I+c*A.p,-e/2-n*1.4,"bottom")),i.push(qn(c+1+A.left,I+c*A.p,-e/2,o,n))}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-n,y:e/2+n},{x:A.w/2+n,y:e/2+n},{x:A.w/2+n,y:-e/2-n},{x:-A.w/2-n,y:-e/2-n},{x:-A.w/2-n,y:e/2+n}],stroke_width:.1,layer:"top"},g=Yi(0,e/1.7,e/25);return{circuitJson:[...i,a,g,r],parameters:A}},rZA=(t,A,e,i)=>Array.from({length:25},(o,n)=>{const s=n/24*Math.PI-Math.PI/2;return{x:t+(i==="right"?1:-1)*Math.cos(s)*e,y:A+Math.sin(s)*e}}),qBt=Ji.extend({fn:H(),p:Ae.optional().default("4.88mm"),id:Ae.optional().default("0.8mm"),od:Ae.optional().default("1.5mm"),w:Ae.optional().default("5.6mm"),h:Ae.optional().default("3.5mm")}),PBt=t=>{const A=qBt.parse(t),{p:e,id:i,od:o,w:n,h:s}=A,r=s/2,a=[qn(1,-e/2,0,i,o),qn(2,e/2,0,i,o)],g=rZA(-n/2,0,r,"left"),I=rZA(n/2,0,r,"right"),c={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[...g,...g.slice(1).reverse(),{x:-n/2,y:-s/2},{x:n/2,y:-s/2},...I,{x:n/2,y:s/2},{x:-n/2,y:s/2}],stroke_width:.1,pcb_silkscreen_path_id:""},B=Yi(0,e/4,.5);return{circuitJson:[...a,c,B],parameters:A}};Ji.extend({w:Ae,h:Ae});var OBt=t=>{const{w:A,h:e}=t,i=mr(A),o=mr(e);return{circuitJson:[Qi(1,0,0,i,o),Yi(0,o/2+.5,.2)],parameters:t}},$U=(t,A,e,i,o,n)=>({pcb_plated_hole_id:"",type:"pcb_plated_hole",shape:"pill",x:A,y:e,outer_width:mr(o),outer_height:mr(n),hole_width:mr(i),hole_height:mr(i),pcb_port_id:"",layers:["top","bottom"],port_hints:[t.toString()],ccw_rotation:0}),WBt=Ji.extend({fn:H(),num_pins:ei([xA(3),xA(2)]).default(3),p:H().default("1.27mm"),id:H().default("0.72mm"),od:H().default("0.95mm"),w:H().default("4.5mm"),h:H().default("4.5mm"),inline:ce().default(!1),string:H().optional()}),ZBt=(t,A,e)=>Array.from({length:25},(i,o)=>{const n=o/24*Math.PI;return{x:t+Math.cos(n)*e,y:A+Math.sin(n)*e}}),VBt=t=>{const A=t.string?.match(/^to92_(\d+)/),e=A?Number.parseInt(A[1],10):3,i=WBt.parse({...t,num_pins:e}),{p:o,id:n,od:s,w:r,h:a,inline:g}=i,I=Number.parseFloat(a)/2,c=Number.parseFloat(o),B=Number.parseFloat(n),C=Number.parseFloat(s),l=C,Q=C*(1.5/1.05);let E=[];if(i.num_pins===3)g?E=[uS(1,-c,I-c,B,C,Q,0,0),$U(2,0,I-c,B,l,Q),$U(3,c,I-c,B,l,Q)]:E=[uS(1,-c,I-c,B,C,C,0,0),qn(2,0,I,B,C),qn(3,c,I-c,B,C)];else if(i.num_pins===2)E=[uS(1,-c,I-c,B,l,Q,0,0),$U(2,c,I-c,B,l,Q)];else throw new Error("Invalid number of pins for TO-92");const h=Number.parseFloat(r)/2,u=ZBt(0,I,h),d={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[...u,{x:-h,y:0},{x:h,y:0},u[0]],stroke_width:.1,pcb_silkscreen_path_id:""},f=Yi(0,I+1,.5);return{circuitJson:[...E,d,f],parameters:i}},jBt=Ji.extend({fn:H(),num_pins:xA(2).default(2),w:H().default("2.15mm"),h:H().default("1.20mm"),pl:H().default("0.5mm"),pw:H().default("0.6mm"),p:H().default("1.4mm")}),zBt=t=>{const A=jBt.parse(t),e=Yi(0,Ae.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:Ae.parse(A.p)/2,y:Ae.parse(A.h)/2},{x:-Ae.parse(A.w)/2-.2,y:Ae.parse(A.h)/2},{x:-Ae.parse(A.w)/2-.2,y:-Ae.parse(A.h)/2},{x:Ae.parse(A.p)/2,y:-Ae.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:$Bt(A).concat(i,e),parameters:A}},XBt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},$Bt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:o}=XBt({pn:e,p:Number.parseFloat(t.p)});A.push(Qi(e,i,o,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},ACt=Rm({}),eCt=t=>{const A=ACt.parse(t),e=[];for(let s=0;s<A.num_pins;s++){const{x:r,y:a}=ACA({num_pins:A.num_pins,pn:s+1,w:A.w,p:A.p??1.27,pl:A.pl,widthincludeslegs:!0});e.push(Qi(s+1,r,a,A.pl??"1.5mm",A.pw??"0.6mm"))}const i=(A.num_pins/2-1)*A.p+A.pw,o=Yi(0,i/2-.5,i/12),n={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:[...e,o,n],parameters:A}},tCt=Ji.extend({fn:H(),num_pins:xA(2).default(2),w:H().default("5.0mm"),h:H().default("2.30mm"),pl:H().default("1.25mm"),pw:H().default("2mm"),p:H().default("3.75mm")}),iCt=t=>{const A=tCt.parse(t),e=Yi(0,Ae.parse(A.h)/2+1,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:Ae.parse(A.p)/2+.5,y:Ae.parse(A.h)/2+.5},{x:-Ae.parse(A.w)/2-.5,y:Ae.parse(A.h)/2+.5},{x:-Ae.parse(A.w)/2-.5,y:-Ae.parse(A.h)/2-.5},{x:Ae.parse(A.p)/2+.5,y:-Ae.parse(A.h)/2-.5}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:nCt(A).concat(i,e),parameters:A}},oCt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},nCt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:o}=oCt({pn:e,p:Number.parseFloat(t.p)});A.push(Qi(e,i,o,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},sCt=Ji.extend({fn:H(),num_pins:xA(2).default(2),w:H().default("4.4mm"),h:H().default("2.1mm"),pl:H().default("1.2mm"),pw:H().default("1.2mm"),p:H().default("2.9mm")}),rCt=t=>{const A=sCt.parse(t),e=Yi(0,Ae.parse(A.h)-.5,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:Ae.parse(A.p)/2,y:Ae.parse(A.h)/2},{x:-Ae.parse(A.w)/2-.2,y:Ae.parse(A.h)/2},{x:-Ae.parse(A.w)/2-.2,y:-Ae.parse(A.h)/2},{x:Ae.parse(A.p)/2,y:-Ae.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:gCt(A).concat(i,e),parameters:A}},aCt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},gCt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:o}=aCt({pn:e,p:Number.parseFloat(t.p)});A.push(Qi(e,i,o,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},ICt=Ji.extend({fn:H(),num_pins:xA(2).default(2),w:H().default("3.30mm"),h:H().default("1.80mm"),pl:H().default("0.60mm"),pw:H().default("0.45mm"),p:H().default("2.1mm")}),cCt=t=>{const A=ICt.parse(t),e=Yi(0,Ae.parse(A.h)-.5,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:Ae.parse(A.p)/2,y:Ae.parse(A.h)/2},{x:-Ae.parse(A.w)/2,y:Ae.parse(A.h)/2},{x:-Ae.parse(A.w)/2,y:-Ae.parse(A.h)/2},{x:Ae.parse(A.p)/2,y:-Ae.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:CCt(A).concat(i,e),parameters:A}},BCt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},CCt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:o}=BCt({pn:e,p:Number.parseFloat(t.p)});A.push(Qi(e,i,o,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},lCt=Ji.extend({fn:H(),num_pins:xA(2).default(2),w:H().default("1.4mm"),h:H().default("0.9mm"),pl:H().default("0.36mm"),pw:H().default("0.25mm"),p:H().default("0.85mm")}),QCt=t=>{const A=lCt.parse(t),e=Yi(0,Ae.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:Ae.parse(A.p)/2+.15,y:Ae.parse(A.h)/2},{x:-Ae.parse(A.w)/2-.15,y:Ae.parse(A.h)/2},{x:-Ae.parse(A.w)/2-.15,y:-Ae.parse(A.h)/2},{x:Ae.parse(A.p)/2+.15,y:-Ae.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:hCt(A).concat(i,e),parameters:A}},ECt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},hCt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:o}=ECt({pn:e,p:Number.parseFloat(t.p)});A.push(Qi(e,i,o,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},uCt=Ji.extend({fn:H(),num_pins:xA(2).default(2),w:H().default("1.3mm"),h:H().default("0.9mm"),pl:H().default("0.4mm"),pw:H().default("0.7mm"),p:H().default("0.7mm")}),dCt=t=>{const A=uCt.parse(t),e=Yi(0,Ae.parse(A.h)+.1,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:Ae.parse(A.p)/2+.2,y:Ae.parse(A.h)/2+.2},{x:-Ae.parse(A.w)/2-.2,y:Ae.parse(A.h)/2+.2},{x:-Ae.parse(A.w)/2-.2,y:-Ae.parse(A.h)/2-.2},{x:Ae.parse(A.p)/2+.2,y:-Ae.parse(A.h)/2-.2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:fCt(A).concat(i,e),parameters:A}},pCt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},fCt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:o}=pCt({pn:e,p:Number.parseFloat(t.p)});A.push(Qi(e,i,o,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},yCt=Ji.extend({fn:H(),num_pins:xA(2).default(2),w:H().default("3,05mm"),h:H().default("1.65mm"),pl:H().default("0.6mm"),pw:H().default("0.6mm"),pad_spacing:H().default("2.2mm")}),wCt=t=>{const A=yCt.parse(t),e=Yi(0,Ae.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:Ae.parse(A.pad_spacing)/2,y:Ae.parse(A.h)/2},{x:-Ae.parse(A.w)/2-.2,y:Ae.parse(A.h)/2},{x:-Ae.parse(A.w)/2-.2,y:-Ae.parse(A.h)/2},{x:Ae.parse(A.pad_spacing)/2,y:-Ae.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:DCt(A).concat(i,e),parameters:A}},mCt=t=>{const{pn:A,pad_spacing:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},DCt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:o}=mCt({pn:e,pad_spacing:Number.parseFloat(t.pad_spacing)});A.push(Qi(e,i,o,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},SCt=Ji.extend({fn:H(),num_pins:xA(2).default(2),w:H().default("4.4mm"),h:H().default("2.1mm"),pl:H().default("1.2mm"),pw:H().default("1.2mm"),p:H().default("2.9mm")}),bCt=t=>{const A=SCt.parse(t),e=Yi(0,Ae.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:Ae.parse(A.p)/2,y:Ae.parse(A.h)/2},{x:-Ae.parse(A.w)/2-.2,y:Ae.parse(A.h)/2},{x:-Ae.parse(A.w)/2-.2,y:-Ae.parse(A.h)/2},{x:Ae.parse(A.p)/2,y:-Ae.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:kCt(A).concat(i,e),parameters:A}},xCt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},kCt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:o}=xCt({pn:e,p:Number.parseFloat(t.p)});A.push(Qi(e,i,o,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},GCt=Ji.extend({fn:H(),num_pins:xA(2).default(2),w:H().default("4.4mm"),h:H().default("2.1mm"),pl:H().default("0.91mm"),pw:H().default("1.22mm"),p:H().default("3.146mm")}),FCt=t=>{const A=GCt.parse(t),e=Yi(0,Ae.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:Ae.parse(A.p)/2,y:Ae.parse(A.h)/2},{x:-Ae.parse(A.w)/2-.2,y:Ae.parse(A.h)/2},{x:-Ae.parse(A.w)/2-.2,y:-Ae.parse(A.h)/2},{x:Ae.parse(A.p)/2,y:-Ae.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:MCt(A).concat(i,e),parameters:A}},RCt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},MCt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:o}=RCt({pn:e,p:Number.parseFloat(t.p)});A.push(Qi(e,i,o,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},NCt=Ji.extend({fn:H(),num_pins:xA(2).default(2),w:H().default("1.80mm"),h:H().default("1.00mm"),pl:H().default("0.66mm"),pw:H().default("0.5mm"),p:H().default("0.8mm")}),_Ct=t=>{const A=NCt.parse(t),e=Yi(0,Ae.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:Ae.parse(A.p)/2,y:Ae.parse(A.h)/2},{x:-Ae.parse(A.w)/2-.1,y:Ae.parse(A.h)/2},{x:-Ae.parse(A.w)/2-.1,y:-Ae.parse(A.h)/2},{x:Ae.parse(A.p)/2,y:-Ae.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:UCt(A).concat(i,e),parameters:A}},vCt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},UCt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:o}=vCt({pn:e,p:Number.parseFloat(t.p)});A.push(Qi(e,i,o,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},LCt=Ji.extend({fn:H(),num_pins:xA(2).default(2),w:H().default("6.2mm"),h:H().default("3.4mm"),pl:H().default("1.4mm"),pw:H().default("2.1mm"),p:H().default("4.4mm")}),HCt=t=>{const A=LCt.parse(t),e=Yi(0,Ae.parse(A.h)/2+.4,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:Ae.parse(A.p)/2,y:Ae.parse(A.h)/2},{x:-Ae.parse(A.w)/2-.2,y:Ae.parse(A.h)/2},{x:-Ae.parse(A.w)/2-.2,y:-Ae.parse(A.h)/2},{x:Ae.parse(A.p)/2,y:-Ae.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:JCt(A).concat(i,e),parameters:A}},YCt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},JCt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:o}=YCt({pn:e,p:Number.parseFloat(t.p)});A.push(Qi(e,i,o,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},TCt=Ji.extend({fn:H(),num_pins:ei([xA(3),xA(5)]).default(3),w:H().default("4.20mm"),h:H().default("4.80mm"),pl:H().default("1.3mm"),pw:H().default("0.9mm"),p:H().default("1.5mm"),string:H().optional()}),KCt=t=>{const A=[],e=Number.parseFloat(t.p),i=Number.parseFloat(t.pw),o=Number.parseFloat(t.w),n=Number.parseFloat(t.pl),s=.175,r=(n-(n+s))/2;A.push(Qi(1,-o/2+r,e,n,i),Qi(2,-o/2,0,n+s,i),Qi(3,-o/2+r,-e,n,i));const a=Yi(0,0,.3),g=Number.parseFloat(t.w)/2-1,I=Number.parseFloat(t.h)/2,c={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-g,y:I},{x:g,y:I},{x:g,y:I/2+.5}],type:"pcb_silkscreen_path",stroke_width:.1},B={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_2",route:[{x:-g,y:-I},{x:g,y:-I},{x:g,y:-I/2-.5}],type:"pcb_silkscreen_path",stroke_width:.1};return[...A,c,B,a]},qCt=t=>{const A=[];Number.parseFloat(t.p),Number.parseFloat(t.pw),Number.parseFloat(t.w),A.push(Qi(1,-1.85,-1.5,1.5,.7),Qi(2,-1.85,1.5,1.5,.7),Qi(3,0,0,.8,2),Qi(4,1.85,-1.5,1.5,.7),Qi(5,1.85,1.5,1.5,.7));const e=Yi(0,Number.parseFloat(t.h)/2+.5,.3),i=Number.parseFloat(t.w)/2-1,o=Number.parseFloat(t.h)/2,n={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-i,y:o},{x:i,y:o}],type:"pcb_silkscreen_path",stroke_width:.1},s={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_2",route:[{x:-i,y:-o},{x:i,y:-o}],type:"pcb_silkscreen_path",stroke_width:.1};return[...A,n,s,e]},PCt=t=>{const A=t.string?.match(/^sot89_(\d+)/),e=A?Number.parseInt(A[1],10):3,i=TCt.parse({...t,num_pins:e});if(i.num_pins===3)return{circuitJson:KCt(i),parameters:i};if(i.num_pins===5)return{circuitJson:qCt(i),parameters:i};throw new Error("Invalid number of pins for SOT89")},OCt=Ji.extend({fn:H(),p:Ae.optional().default("5.0mm"),id:Ae.optional().default("1.0mm"),od:Ae.optional().default("1.9mm"),w:Ae.optional().default("13mm"),h:Ae.optional().default("7mm"),num_pins:WA().optional(),string:H().optional()}),WCt=t=>{const A=OCt.parse(t),{fn:e,id:i,od:o,w:n,h:s,string:r}=A,a=Number.parseInt(r?.split("_")[1]??"3"),g=-1,I=n/2,c=s/2,B=2.5,C=n*.4,l=Math.max(B,C/(a-1)),Q=Array.from({length:a},(m,b)=>{const D=a%2===0?(b-a/2+.5)*l:(b-Math.floor(a/2))*l;return qn(b+1,D,g,i,o)}),E={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-I,y:-c},{x:I,y:-c},{x:I,y:c},{x:-I,y:c},{x:-I,y:-c}],stroke_width:.1,pcb_silkscreen_path_id:""},h=-c+2*s/3,u={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-I,y:h},{x:I,y:h}],stroke_width:.1,pcb_silkscreen_path_id:""},d=[{type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-n/6,y:h},{x:-n/6,y:c}],stroke_width:.1,pcb_silkscreen_path_id:""},{type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:n/6,y:h},{x:n/6,y:c}],stroke_width:.1,pcb_silkscreen_path_id:""}],f=Yi(0,s/2+.6,.5);return{circuitJson:[...Q,E,u,...d,f],parameters:{...A,p:l}}},ZCt=Ji.extend({fn:H(),num_pins:xA(2).default(2),w:H().default("5.40mm"),h:H().default("2.30mm"),pl:H().default("1.30mm"),pw:H().default("1.70mm"),p:H().default("3.5mm")}),VCt=t=>{const A=ZCt.parse(t),e=Yi(0,Ae.parse(A.h)/2+.4,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:Ae.parse(A.p)/2,y:Ae.parse(A.h)/2},{x:-Ae.parse(A.w)/2,y:Ae.parse(A.h)/2},{x:-Ae.parse(A.w)/2,y:-Ae.parse(A.h)/2},{x:Ae.parse(A.p)/2,y:-Ae.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:zCt(A).concat(i,e),parameters:A}},jCt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},zCt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:o}=jCt({pn:e,p:Number.parseFloat(t.p)});A.push(Qi(e,i,o,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},XCt=Ji.extend({fn:H(),num_pins:xA(2).default(2),w:H().default("1.90mm"),h:H().default("1.33mm"),pl:H().default("0.5mm"),pw:H().default("0.7mm"),p:H().default("0.8mm")}),$Ct=t=>{const A=XCt.parse(t),e=Yi(0,Ae.parse(A.h)+.1,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:Ae.parse(A.p)/2+.1,y:Ae.parse(A.h)/2},{x:-Ae.parse(A.w)/2,y:Ae.parse(A.h)/2},{x:-Ae.parse(A.w)/2,y:-Ae.parse(A.h)/2},{x:Ae.parse(A.p)/2+.1,y:-Ae.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:elt(A).concat(i,e),parameters:A}},Alt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},elt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:o}=Alt({pn:e,p:Number.parseFloat(t.p)});A.push(Qi(e,i,o,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},tlt=Ji.extend({fn:H(),num_pins:xA(2).default(2),w:H().default("7.0mm"),h:H().default("3.35mm"),pl:H().default("1.50mm"),pw:H().default("2.70mm"),p:H().default("4.8mm")}),ilt=t=>{const A=tlt.parse(t),e=Yi(0,Ae.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:Ae.parse(A.p)/2,y:Ae.parse(A.h)/2},{x:-Ae.parse(A.w)/2,y:Ae.parse(A.h)/2},{x:-Ae.parse(A.w)/2,y:-Ae.parse(A.h)/2},{x:Ae.parse(A.p)/2,y:-Ae.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:nlt(A).concat(i,e),parameters:A}},olt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},nlt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:o}=olt({pn:e,p:Number.parseFloat(t.p)});A.push(Qi(e,i,o,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},slt=Ji.extend({fn:H(),num_pins:xA(2).default(2),w:H().default("3.0mm"),h:H().default("1.80mm"),pl:H().default("0.80mm"),pw:H().default("1.20mm"),p:H().default("1.6mm")}),rlt=t=>{const A=slt.parse(t),e=Yi(0,Ae.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:Ae.parse(A.p)/2,y:Ae.parse(A.h)/2},{x:-Ae.parse(A.w)/2-.1,y:Ae.parse(A.h)/2},{x:-Ae.parse(A.w)/2-.1,y:-Ae.parse(A.h)/2},{x:Ae.parse(A.p)/2,y:-Ae.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:glt(A).concat(i,e),parameters:A}},alt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},glt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:o}=alt({pn:e,p:Number.parseFloat(t.p)});A.push(Qi(e,i,o,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},Ilt=Ji.extend({fn:H(),num_pins:xA(2).default(2),w:H().default("7.10mm"),h:H().default("3.40mm"),pl:H().default("2.45mm"),pw:H().default("1.80mm"),p:H().default("4.05mm")}),clt=t=>{const A=Ilt.parse(t),e=Yi(0,Ae.parse(A.h)/2+.5,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:Ae.parse(A.p)/2,y:Ae.parse(A.h)/2},{x:-Ae.parse(A.w)/2-.5,y:Ae.parse(A.h)/2},{x:-Ae.parse(A.w)/2-.5,y:-Ae.parse(A.h)/2},{x:Ae.parse(A.p)/2,y:-Ae.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:Clt(A).concat(i,e),parameters:A}},Blt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},Clt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:o}=Blt({pn:e,p:Number.parseFloat(t.p)});A.push(Qi(e,i,o,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},llt=Ji.extend({fn:H(),num_pins:xA(2).default(2),w:H().default("4.80mm"),h:H().default("2.10mm"),pl:H().default("1.30mm"),pw:H().default("1.40mm"),p:H().default("2.9mm")}),Qlt=t=>{const A=llt.parse(t),e=Yi(0,Ae.parse(A.h)-.5,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:Ae.parse(A.p)/2,y:Ae.parse(A.h)/2},{x:-Ae.parse(A.w)/2,y:Ae.parse(A.h)/2},{x:-Ae.parse(A.w)/2,y:-Ae.parse(A.h)/2},{x:Ae.parse(A.p)/2,y:-Ae.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:hlt(A).concat(i,e),parameters:A}},Elt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},hlt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:o}=Elt({pn:e,p:Number.parseFloat(t.p)});A.push(Qi(e,i,o,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},ult=Ji.extend({fn:H(),num_pins:xA(2).default(2),w:H().default("7.30mm"),h:H().default("4.40mm"),pl:H().default("2.50mm"),pw:H().default("2.30mm"),p:H().default("4.30mm")}),dlt=t=>{const A=ult.parse(t),e=Yi(0,Ae.parse(A.h)/2+.5,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:Ae.parse(A.p)/2,y:Ae.parse(A.h)/2},{x:-Ae.parse(A.w)/2-.1,y:Ae.parse(A.h)/2},{x:-Ae.parse(A.w)/2-.1,y:-Ae.parse(A.h)/2},{x:Ae.parse(A.p)/2,y:-Ae.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:flt(A).concat(i,e),parameters:A}},plt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},flt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:o}=plt({pn:e,p:Number.parseFloat(t.p)});A.push(Qi(e,i,o,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},ylt=Ji.extend({fn:H(),num_pins:xA(2).default(2),w:H().default("10.70mm"),h:H().default("6.60mm"),pl:H().default("3.30mm"),pw:H().default("2.50mm"),p:H().default("6.80mm")}),wlt=t=>{const A=ylt.parse(t),e=Yi(0,3,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:Ae.parse(A.p)/2,y:Ae.parse(A.h)/2-.8},{x:-Ae.parse(A.w)/2-.8,y:Ae.parse(A.h)/2-.8},{x:-Ae.parse(A.w)/2-.8,y:-Ae.parse(A.h)/2+.8},{x:Ae.parse(A.p)/2,y:-Ae.parse(A.h)/2+.8}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:Dlt(A).concat(i,e),parameters:A}},mlt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},Dlt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:o}=mlt({pn:e,p:Number.parseFloat(t.p)});A.push(Qi(e,i,o,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},Slt=Ji.extend({fn:H(),num_pins:WA().default(4),w:H().default("8.50mm"),h:H().default("6.90mm"),pl:H().default("2mm"),pw:H().default("1.5mm"),p:H().default("2.30mm"),string:H().optional()}),blt=t=>{const A=t.string?.match(/^sot223_(\d+)/),e=A?Number.parseInt(A[1],10):4;if(e===8){const o=Glt.parse({...t,num_pins:e});return{circuitJson:Gx(o),parameters:o}}const i=Slt.parse({...t,num_pins:e});if(i.num_pins===4)return{circuitJson:klt(i),parameters:i};if(i.num_pins===5)return{circuitJson:Rlt(i),parameters:i};if(i.num_pins===6)return{circuitJson:Nlt(i),parameters:i};throw new Error("Invalid number of pins")},xlt=t=>{const{pn:A,w:e,p:i}=t;return A===1?{x:-e/2+1.1,y:i}:A===2?{x:-e/2+1.1,y:0}:A===3?{x:-e/2+1.1,y:-i}:{x:e/2-1.1,y:0}},klt=t=>{const A=[];for(let r=0;r<t.num_pins;r++){const{x:a,y:g}=xlt({num_pins:t.num_pins,pn:r+1,w:Number.parseFloat(t.w),h:Number.parseFloat(t.h),pl:Number.parseFloat(t.pl),p:Number.parseFloat(t.p)}),I=r===3?3.8:Number.parseFloat(t.pw);A.push(Qi(r+1,a,g,Number.parseFloat(t.pl),I))}const e=Yi(0,0,.3),i=Number.parseFloat(t.w)/2-2.4,o=Number.parseFloat(t.h)/2,n={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-i,y:o},{x:i,y:o},{x:i,y:o/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:-o},{x:i,y:-o},{x:i,y:-o/2-.5}],type:"pcb_silkscreen_path",stroke_width:.1};return[...A,n,s,e]},Glt=Rm({p:"0.90mm",w:"2.8mm",legsoutside:!0}),Flt=t=>{const{p:A,pn:e,w:i}=t;if(e===1)return{x:-i/2+1.2,y:A/2+A};if(e===2)return{x:-i/2+1.2,y:A/2};if(e===3)return{x:-i/2+1.2,y:-A/2};if(e===4)return{x:-i/2+1.2,y:-A/2-A};if(e===5)return{x:i/2-1,y:0};throw new Error("Invalid pin number")},Rlt=t=>{const A=[];for(let r=1;r<=t.num_pins;r++){const{x:a,y:g}=Flt({h:Number.parseFloat(t.h),p:1.5,pn:r,w:Number.parseFloat(t.w)});let I=Number.parseFloat(t.pw),c=Number.parseFloat(t.pl);r===5?(I=3.4,c=1.8):(I=1,c=2.2),A.push(Qi(r,a,g,c,I))}const e=Number.parseFloat(t.w)/2-2.4,i=Number.parseFloat(t.h)/2,o={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-e,y:i},{x:e,y:i},{x:e,y:i/2+.5}],type:"pcb_silkscreen_path",stroke_width:.1},n={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_2",route:[{x:-e,y:-i},{x:e,y:-i},{x:e,y:-i/2-.5}],type:"pcb_silkscreen_path",stroke_width:.1},s=Yi(0,0,.3);return[...A,o,n,s]},Mlt=t=>{const{p:A,pn:e,w:i}=t;if(e===1)return{x:-i/2+1.2,y:2*A};if(e===2)return{x:-i/2+1.2,y:A};if(e===3)return{x:-i/2+1.2,y:0};if(e===4)return{x:-i/2+1.2,y:-A};if(e===5)return{x:-i/2+1.2,y:-2*A};if(e===6)return{x:i/2-1.175,y:0};throw new Error("Invalid pin number")},Nlt=t=>{const A=[];for(let r=1;r<=t.num_pins;r++){const{x:a,y:g}=Mlt({h:Number.parseFloat(t.h),p:1.3,pn:r,w:8.7});let I=Number.parseFloat(t.pw),c=Number.parseFloat(t.pl);r===6?(I=3.4,c=2.15):(I=.6,c=2.2),A.push(Qi(r,a,g,c,I))}const e=Number.parseFloat(t.w)/2-2.4,i=Number.parseFloat(t.h)/2,o={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-e,y:i},{x:e,y:i},{x:e,y:i/2+.5}],type:"pcb_silkscreen_path",stroke_width:.1},n={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_2",route:[{x:-e,y:-i},{x:e,y:-i},{x:e,y:-i/2-.5}],type:"pcb_silkscreen_path",stroke_width:.1},s=Yi(0,0,.3);return[...A,o,n,s]},_lt=Ji.extend({fn:H(),num_pins:WA().default(3),w:H().default("3.40mm"),h:H().default("3.30mm"),pl:H().default("1mm"),pw:H().default("0.7mm"),p:H().default("1.2mm"),string:H().optional()}),vlt=t=>{const A=t.string?.match(/^sot23w_(\d+)/),e=A?Number.parseInt(A[1],3):3,i=_lt.parse({...t,num_pins:e});if(i.num_pins===3)return{circuitJson:Llt(i),parameters:i};throw new Error("Invalid number of pins")},Ult=t=>{const{pn:A,p:e}=t;return A===1?{x:-e,y:.95}:A===2?{x:-e,y:-.95}:{x:e,y:0}},Llt=t=>{const A=[];for(let r=0;r<t.num_pins;r++){const{x:a,y:g}=Ult({num_pins:t.num_pins,pn:r+1,w:Number.parseFloat(t.w),h:Number.parseFloat(t.h),pl:Number.parseFloat(t.pl),p:Number.parseFloat(t.p)});A.push(Qi(r+1,a,g,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}const e=Yi(0,Number.parseInt(t.h)/2+1,.3),i=Number.parseFloat(t.w)/2-1,o=Number.parseFloat(t.h)/2,n={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-i,y:o},{x:i+.3,y:o},{x:i+.3,y:o/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:-o},{x:i+.3,y:-o},{x:i+.3,y:-o/2}],type:"pcb_silkscreen_path",stroke_width:.1};return[...A,n,s,e]},Hlt=Ji.extend({fn:H(),num_pins:ei([xA(3),xA(2)]).default(3),p:H().default("1.27mm"),id:H().default("0.72mm"),od:H().default("0.95mm"),w:H().default("2.5mm"),h:H().default("4.2mm"),string:H().optional()}),Ylt=t=>{const{p:A,id:e,od:i,w:o,h:n}=t,s=Number.parseFloat(n)/2,r=Number.parseFloat(A);return[qn(1,-r,s-r,e,i),qn(2,0,s-r,e,i),qn(3,r,s-r,e,i)]},Jlt=t=>{const{p:A,id:e,od:i,h:o}=t,n=Number.parseFloat(o)/2,s=Number.parseFloat(A);return[qn(1,-s,n-s,e,i),qn(2,s,n-s,e,i)]},Tlt=t=>{const A=t.string?.match(/^to92s_(\d+)/),e=A?Number.parseInt(A[1],10):3,i=Hlt.parse({...t,num_pins:e});let o=[];if(i.num_pins===3)o=Ylt(i);else if(i.num_pins===2)o=Jlt(i);else throw new Error("Invalid number of pins for TO-92");const n=Number.parseFloat(i.h)/2,s=Number.parseFloat(i.p),r={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-n,y:n-s},{x:-1.9,y:0},{x:1.9,y:0},{x:n,y:n-s},{x:1.5,y:Number.parseFloat(i.h)/2+.5},{x:-1.5,y:Number.parseFloat(i.h)/2+.5},{x:-n,y:n-s}],stroke_width:.1,pcb_silkscreen_path_id:""},a=Yi(0,n+1,.5);return{circuitJson:[...o,r,a],parameters:i}},Klt=Ji.extend({fn:H(),p:Ae.optional(),id:Ae.optional(),pw:Ae.optional(),pl:Ae.optional(),w:Ae.optional(),h:Ae.optional(),sh:ei([ce(),H(),WA()]).optional().transform(t=>{if(typeof t=="string"){const A=Number(t);return Number.isNaN(A)?!0:A}return t}).describe('JST SH (Surface-mount) connector family. SH stands for "Super High-density".'),ph:ce().optional().describe('JST PH (Through-hole) connector family. PH stands for "Pin Header".'),string:H().optional()}),qlt={ph:{p:Ae.parse("2.2mm"),id:Ae.parse("0.70mm"),pw:Ae.parse("1.20mm"),pl:Ae.parse("1.20mm"),w:Ae.parse("6mm"),h:Ae.parse("5mm")},sh:{p:Ae.parse("1mm"),pw:Ae.parse("0.6mm"),pl:Ae.parse("1.55mm"),w:Ae.parse("5.8mm"),h:Ae.parse("7.8mm")}};function Plt(t){return t.sh?"sh":(t.ph,"ph")}function Olt(t,A,e,i,o,n){const s=[];if(t==="ph"){const r=e/2;s.push(uS(1,-r,2,i,o,n)),s.push(uS(2,r,2,i,o,n))}else{const r=-((A-1)/2)*e;for(let g=0;g<A;g++){const I=r+g*e;console.log("x si",I),s.push(Qi(g+1,I,-1.325,o,n))}const a=(A-1)/2*e+1.3;console.log("offset",a),s.push(Qi(A+1,-a,1.22,1.2,1.8)),s.push(Qi(A+2,a,1.22,1.2,1.8))}return s}function Wlt(t,A,e){return t==="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 Zlt=t=>{const A=Klt.parse(t),e=Plt(A),i=qlt[e],o=A.p??i.p,n=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 I=e==="sh"?4:2;if(e==="sh"){const Q=(typeof t.string=="string"?t.string:"").match(/sh(\d+)/);if(Q&&Q[1]){const E=parseInt(Q[1],10);Number.isNaN(E)||(I=E)}else typeof A.sh=="number"&&(I=A.sh)}const c=Olt(e,I,o,n,s,r),B=Wlt(e),C=Yi(0,g/2+1,.5);return{circuitJson:[...c,B,C],parameters:{...A,p:o,id:n,pw:s,pl:r,w:a,h:g,num_pins:I,sh:e==="sh",ph:e==="ph"}}},Vlt=Ji.extend({fn:H(),num_pins:xA(2).default(2),w:H().default("3.30mm"),h:H().default("1.70mm"),pl:H().default("0.80mm"),pw:H().default("1mm"),p:H().default("1.90mm")}),jlt=t=>{const A=Vlt.parse(t),e=Yi(0,Ae.parse(A.h)/2+.5,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:Ae.parse(A.p)/2,y:Ae.parse(A.h)/2},{x:-Ae.parse(A.w)/2,y:Ae.parse(A.h)/2},{x:-Ae.parse(A.w)/2,y:-Ae.parse(A.h)/2},{x:Ae.parse(A.p)/2,y:-Ae.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:Xlt(A).concat(i,e),parameters:A}},zlt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},Xlt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:o}=zlt({pn:e,p:Number.parseFloat(t.p)});A.push(Qi(e,i,o,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},$lt=t=>{switch(t){case 8:return{w:"3.06mm",h:"3.14mm",p:"0.65mm",pl:"1.6mm",pw:"0.5mm"};case 10:return{w:"3.10mm",h:"3.33mm",p:"0.5mm",pl:"1.45mm",pw:"0.3mm"};default:return{w:"3.06mm",h:"3.14mm",p:"0.65mm",pl:"1.6mm",pw:"0.5mm"}}},AQt=Ji.extend({fn:H(),num_pins:ei([xA(8),xA(10)]).default(8),w:H().optional(),h:H().optional(),p:H().optional(),pl:H().optional(),pw:H().optional(),string:H().optional()}),eQt=t=>{const A=AQt.parse(t),e=$lt(A.num_pins),i=Ae.parse(A.w||e.w),o=Ae.parse(A.h||e.h),n=Ae.parse(A.p||e.p),s=Ae.parse(A.pl||e.pl),r=Ae.parse(A.pw||e.pw),a=[],g=A.num_pins/2;for(let u=0;u<A.num_pins;u++){const{x:d,y:f}=aZA(A.num_pins,u+1,i,n),m=u<g?u+1:A.num_pins-(u-g);a.push(Qi(m,d,f,s,r))}const I=i,c=o,B={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-I/2,y:c/2},{x:I/2,y:c/2}],stroke_width:.05,pcb_silkscreen_path_id:""},C={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-I/2,y:-c/2},{x:I/2,y:-c/2}],stroke_width:.05,pcb_silkscreen_path_id:""},l=aZA(A.num_pins,1,I,n),Q={x:l.x-.8,y:l.y},E={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"},h=Yi(0,c/2+.5,.3);return{circuitJson:[...a,B,C,h,E],parameters:A}},aZA=(t,A,e,i)=>{const o=t/2,n=(A-1)%o,s=A<=o?-1:1,r=(o-1)/2-n;return{x:s*Ae.parse(t===8?"1.8mm":"2.2mm"),y:r*i}},tQt=t=>{switch(t){case 10:return{w:"3.10mm",h:"3.32mm",p:"0.5mm",pl:"1.63mm",pw:"0.33mm"};case 12:return{w:"3mm",h:"4mm",p:"0.65mm",pl:"0.88mm",pw:"0.4mm"};case 16:return{w:"3.10mm",h:"4mm",p:"0.5mm",pl:"0.88mm",pw:"0.3mm"};default:return{w:"3.10mm",h:"3.32mm",p:"0.65mm",pl:"1.63mm",pw:"0.4mm"}}},iQt=Ji.extend({fn:H(),num_pins:ei([xA(8),xA(10),xA(12),xA(16)]).default(8),w:H().optional(),h:H().optional(),p:H().optional(),pl:H().optional(),pw:H().optional(),string:H().optional()}),gZA=(t,A,e,i)=>{const o=t/2,n=(A-1)%o,s=A<=o?-1:1,r=(o-1)/2-n;return{x:s*Ae.parse("2mm"),y:r*i}},oQt=t=>{const A=iQt.parse(t),e=tQt(A.num_pins),i=Ae.parse(A.w||e.w),o=Ae.parse(A.h||e.h),n=Ae.parse(A.p||e.p),s=Ae.parse(A.pl||e.pl),r=Ae.parse(A.pw||e.pw),a=[];for(let h=0;h<A.num_pins;h++){const{x:u,y:d}=gZA(A.num_pins,h+1,i,n);a.push(Qi(h+1,u,d,s,r))}const g=i,I=o,c={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-g/2,y:I/2},{x:g/2,y:I/2}],stroke_width:.05,pcb_silkscreen_path_id:""},B={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-g/2,y:-I/2},{x:g/2,y:-I/2}],stroke_width:.05,pcb_silkscreen_path_id:""},C=gZA(A.num_pins,1,g,n),l={x:C.x-.8,y:C.y},Q={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"pin_marker_1",route:[{x:l.x-.4,y:l.y},{x:l.x-.7,y:l.y+.3},{x:l.x-.7,y:l.y-.3},{x:l.x-.4,y:l.y}],stroke_width:.05,pcb_silkscreen_path_id:"pin_marker_1"},E=Yi(0,I/2+.5,.3);return{circuitJson:[...a,c,B,E,Q],parameters:A}},nQt=Ji.extend({fn:H(),num_pins:xA(2).default(2),w:H().default("3.8mm"),h:H().default("1.65mm"),pl:H().default("1.2mm"),pw:H().default("1.2mm"),pad_spacing:H().default("2.6mm")}),sQt=t=>{const A=nQt.parse(t),e=Yi(0,Ae.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:Ae.parse(A.pad_spacing)/2,y:Ae.parse(A.h)/2},{x:-Ae.parse(A.w)/2-.2,y:Ae.parse(A.h)/2},{x:-Ae.parse(A.w)/2-.2,y:-Ae.parse(A.h)/2},{x:Ae.parse(A.pad_spacing)/2,y:-Ae.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:aQt(A).concat(i,e),parameters:A}},rQt=t=>{const{pn:A,pad_spacing:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},aQt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:o}=rQt({pn:e,pad_spacing:Number.parseFloat(t.pad_spacing)});A.push(Qi(e,i,o,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},gQt=Ji.extend({fn:H(),num_pins:xA(2).default(2),w:H().default("3.20mm"),h:H().default("1.65mm"),pl:H().default("0.8mm"),pw:H().default("0.9mm"),pad_spacing:H().default("2.1mm")}),IQt=t=>{const A=gQt.parse(t),e=Yi(0,Ae.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:Ae.parse(A.pad_spacing)/2,y:Ae.parse(A.h)/2},{x:-Ae.parse(A.w)/2-.2,y:Ae.parse(A.h)/2},{x:-Ae.parse(A.w)/2-.2,y:-Ae.parse(A.h)/2},{x:Ae.parse(A.pad_spacing)/2,y:-Ae.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:BQt(A).concat(i,e),parameters:A}},cQt=t=>{const{pn:A,pad_spacing:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},BQt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:o}=cQt({pn:e,pad_spacing:Number.parseFloat(t.pad_spacing)});A.push(Qi(e,i,o,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},CQt=Ji.extend({fn:H(),num_pins:ei([xA(6),xA(8)]).default(8),w:H().default("3mm"),h:H().default("3mm"),p:H().default("0.5mm"),pl:H().default("0.52mm"),pw:H().default("0.35mm"),epw:H().default("1.40mm"),eph:H().default("1.60mm"),string:H().optional(),ep:ce().default(!1)}),lQt=t=>{t.string&&t.string.includes("_ep")&&(t.ep=!0);const A=t.string?.match(/^son_(\d+)/),e=A?Number.parseInt(A[1],10):t.num_pins||8,i=CQt.parse({...t,num_pins:e}),o=Ae.parse(i.w),n=Ae.parse(i.h),s=Ae.parse(i.p),r=Ae.parse(i.pl),a=Ae.parse(i.pw),g=Ae.parse(i.epw),I=Ae.parse(i.eph),c=[];for(let f=0;f<i.num_pins;f++){const{x:m,y:b}=IZA(i.num_pins,f+1,o,s);c.push(Qi(f+1,m,b,r,a))}i.ep&&c.push(Qi(i.num_pins+1,0,0,g,I));const B=o,C=n,l={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-B/2,y:C/2},{x:B/2,y:C/2}],stroke_width:.05,pcb_silkscreen_path_id:""},Q={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-B/2,y:-C/2},{x:B/2,y:-C/2}],stroke_width:.05,pcb_silkscreen_path_id:""},E=IZA(i.num_pins,1,B,s),h={x:E.x-.4,y:E.y},u={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"pin_marker_1",route:[{x:h.x-.4,y:h.y},{x:h.x-.7,y:h.y+.3},{x:h.x-.7,y:h.y-.3},{x:h.x-.4,y:h.y}],stroke_width:.05,pcb_silkscreen_path_id:"pin_marker_1"},d=Yi(0,C/2+.5,.3);return{circuitJson:[...c,l,Q,d,u],parameters:i}},IZA=(t,A,e,i)=>{const o=t/2,n=(A-1)%o,s=A<=o?-1:1,r=(o-1)/2-n;return{x:s*Ae.parse("1.4mm"),y:r*i}},QQt=t=>{const{num_pins:A,bridged:e,p:i=2.54,pw:o=1.5,ph:n=1.5}=t,s=Ae.parse(i),r=Ae.parse(o),a=Ae.parse(n),g=Math.min(a/4,.5),I=[];for(let f=0;f<A;f++)I.push(Qi(f+1,f*s,0,r,a));let c=[];if(e){const f=e.split("").map(Number);if(f.length>1)for(let m=0;m<f.length-1;m++){const b=f[m],D=f[m+1];if(typeof b=="number"&&typeof D=="number"&&!isNaN(b)&&!isNaN(D)){const x=(b-1)*s,F=(D-1)*s,k=Math.sign(F-x),v=x+k*(r/2),_=F-k*(r/2);c.push({type:"pcb_trace",pcb_trace_id:"",route:[{start_pcb_port_id:`{PIN${b}}`,x:v,y:0,width:g,layer:"top",route_type:"wire"},{end_pcb_port_id:`{PIN${D}}`,x:_,y:0,width:g,layer:"top",route_type:"wire"}]})}}}const B=(A-1)*s+r+.7,C=a+1,l=(A-1)*s/2,Q=0,E={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"outline",route:[{x:l-B/2,y:Q-C/2},{x:l+B/2,y:Q-C/2},{x:l+B/2,y:Q+C/2},{x:l-B/2,y:Q+C/2},{x:l-B/2,y:Q-C/2}],stroke_width:.15},u=Q+C/2+.6,d=Yi(l,u,.4);return{circuitJson:[...I,...c,E,d],parameters:t}},cZA={fn:xA("sot457"),num_pins:xA(6).default(6),pillh:H().default("0.45mm"),pillw:H().default("1.45mm"),pl:H(),pw:H(),p:H(),wave:ce().optional(),reflow:ce().optional()},EQt=Ji.extend({...cZA,h:H().default("2.5mm"),w:H().default("2.7mm"),pl:H().default("0.8mm"),pw:H().default("0.55mm"),p:H().default("0.95mm")}),hQt=Ji.extend({...cZA,h:H().default("3mm"),w:H().default("4mm"),pillr:H().default("0.225mm"),pl:H().default("1.45mm"),pw:H().default("1.5mm"),p:H().default("1.475mm")}).transform(t=>({...t,wave:t.wave??(t.reflow===void 0?!0:!t.reflow),reflow:t.reflow??(t.wave===void 0?!1:!t.wave)})),dS=t=>Number.parseFloat(t.replace("mm","")),BZA=({pitch:t,width:A,pinNumber:e})=>{const n={1:{x:-A/2-.1,y:t},2:{x:-A/2-.1,y:0},3:{x:-A/2-.1,y:-t},4:{x:A/2+.1,y:-t},5:{x:A/2+.1,y:0},6:{x:A/2+.1,y:t}}[e];if(!n)throw new Error(`Invalid pin number: ${e}`);return n},CZA=t=>{const A=[],e=dS(t.p),i=dS(t.pl),o=dS(t.pw),n=dS(t.w),s=dS(t.h);if(t.wave){const l={1:({padWidth:Q,padHeight:E})=>Qi(1,-e,e,E,Q),2:({padWidth:Q,padHeight:E})=>Qi(2,-e,-e,E,Q),3:({padWidth:Q,padHeight:E})=>c5(3,-e,0,dS(t.pillw),dS(t.pillh)),4:({padWidth:Q,padHeight:E})=>c5(4,e,0,dS(t.pillw),dS(t.pillh)),5:({padWidth:Q,padHeight:E})=>Qi(5,e,e,E,Q),6:({padWidth:Q,padHeight:E})=>Qi(6,e,-e,E,Q)};for(let Q=1;Q<=t.num_pins;Q++){const E=l[Q];E&&A.push(E({padWidth:i,padHeight:o}))}}else for(let l=1;l<=t.num_pins;l++){const{x:Q,y:E}=BZA({pitch:e,width:n,pinNumber:l});A.push(Qi(l,Q,E,i,o))}const r={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-n/3,y:s/2+e/1.3},{x:n/3,y:s/2+e/1.3}],stroke_width:.05},a={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_2",route:[{x:-n/3,y:-s/2-e/1.3},{x:n/3,y:-s/2-e/1.3}],stroke_width:.05},g=Yi(0,s+.5,.3),I=BZA({pitch:e,width:n,pinNumber:1}),c=t.wave?1:.5,B=t.wave?.7:.3;I.x-=t.wave?o:o*1.7;const C={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"pin1_indicator",route:[{x:I.x+c/2,y:I.y},{x:I.x-c/2,y:I.y+B/2},{x:I.x-c/2,y:I.y-B/2},{x:I.x+c/2,y:I.y}],stroke_width:.05};return[g,r,a,C,...A]},uQt=t=>{if(t.wave){const e=hQt.parse({...t,fn:"sot457"});return{circuitJson:CZA(e),parameters:e}}const A=EQt.parse(t);return{circuitJson:CZA(A),parameters:A}},dQt=Ji.extend({fn:H(),num_pins:xA(6).default(6),w:H().default("1.1mm"),h:H().default("1.45mm"),p:H().default("0.35mm"),pl:H().default("0.2mm"),pw:H().default("0.2mm"),string:H().optional()}),pQt=t=>{const A=dQt.parse({...t,fn:"sot963"}),e=Ae.parse(A.w),i=Ae.parse(A.h),o=Ae.parse(A.p),n=Ae.parse(A.pl),s=Ae.parse(A.pw),r=[];for(let C=0;C<6;C++){const{x:l,y:Q}=lZA(C+1,e,o,n);r.push(Qi(C+1,l,Q,n,s))}const a={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-e/2,y:i/2},{x:e/2,y:i/2}],stroke_width:.05,pcb_silkscreen_path_id:""},g={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-e/2,y:-i/2},{x:e/2,y:-i/2}],stroke_width:.05,pcb_silkscreen_path_id:""},I=lZA(1,e,o,n),c={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"pin_marker_1",route:[{x:I.x-n/2-.3,y:I.y},{x:I.x-n/2-.45,y:I.y+.15},{x:I.x-n/2-.45,y:I.y-.15},{x:I.x-n/2-.3,y:I.y}],stroke_width:.05,pcb_silkscreen_path_id:"pin_marker_1"},B=Yi(0,i/2+.4,.25);return{circuitJson:[...r,a,g,B,c],parameters:A}},lZA=(t,A,e,i)=>{const o=A/2-i/2;return t<=3?{x:-o,y:e-(t-1)*e}:{x:o,y:-e+(t-4)*e}},fQt=Ji.extend({fn:H(),num_pins:ei([xA(3),xA(2)]).default(3),p:H().default("3.8mm"),id:H().default("1.25mm"),od:H().default("2.35mm"),ca:H().default("14mm").describe("Caliper axis (width or diameter of the potentiometer body or adjustment knob)"),w:H().default("5.35mm"),h:H().default("4mm"),string:H().optional()}),yQt=t=>{const{p:A,id:e,od:i,h:o,ca:n}=t,s=Number.parseFloat(o),r=Number.parseFloat(n);return[qn(1,0,r/4+.3,e,i),qn(2,s,0,e,i),qn(3,0,-r/4-.3,e,i)]},wQt=t=>{const A=t.string?.match(/^potentiometer_(\d+)/),e=A?Number.parseInt(A[1],10):3,i=fQt.parse({...t,num_pins:e});let o=[];i.num_pins===3&&(o=yQt(i));const n=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:n-1.75},{x:0,y:n},{x:s,y:n},{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:-n},{x:0,y:-n},{x:0,y:-n+1.75}],stroke_width:.1,pcb_silkscreen_path_id:""},I=Number.parseFloat(i.w)/2,c=Yi(I,n+1,.5);return{circuitJson:[...o,a,g,c],parameters:i}},mQt=Ji.extend({fn:H(),p:Ae.optional().default("7.5mm"),id:Ae.optional().default("1mm"),od:Ae.optional().default("2mm"),d:Ae.optional().default("10.5mm")}),DQt=(t,A,e,i,o)=>{const n=[],s=[];for(let r=0;r<=50;r++){const a=r/50*Math.PI,g=t+Math.cos(a)*e,I=A+Math.sin(a)*e;g<t-i&&I>=A-o/2&&I<=A+o/2||n.push({x:g,y:I})}for(let r=0;r<=50;r++){const a=Math.PI+r/50*Math.PI,g=t+Math.cos(a)*e,I=A+Math.sin(a)*e;g<t-i&&I>=A-o/2&&I<=A+o/2||s.push({x:g,y:I})}return{topArc:n,bottomArc:s}},SQt=t=>{const A=mQt.parse(t),{p:e,id:i,od:o,d:n}=A,s=[qn(1,-e/2,0,i,o),qn(2,e/2,0,i,o)],{topArc:r,bottomArc:a}=DQt(0,0,n/2+.1,o/2,o),g={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:r,stroke_width:.1,pcb_silkscreen_path_id:""},I={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:a,stroke_width:.1,pcb_silkscreen_path_id:""},c={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:0,y:n/2+.1},{x:0,y:-(n/2+.1)}],stroke_width:.1,pcb_silkscreen_path_id:""},B=-(n/2+.5),C=o/2+1.5,l=.5,Q={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:B-l,y:C},{x:B+l,y:C}],stroke_width:.1,pcb_silkscreen_path_id:""},E={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:B,y:C-l},{x:B,y:C+l}],stroke_width:.1,pcb_silkscreen_path_id:""},h=Yi(0,n/2+1,.5);return{circuitJson:[...s,g,I,c,Q,E,h],parameters:A}},bQt=Ji.extend({fn:H(),num_pins:xA(2).default(2),w:H().default("6.5mm"),h:H().default("3mm"),pl:H().default("1.75mm"),pw:H().default("2.40mm"),p:H().default("4.75mm")}),xQt=t=>{const A=bQt.parse(t),e=Yi(0,Ae.parse(A.h)-.5,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:Ae.parse(A.p)/2,y:Ae.parse(A.h)/2},{x:-Ae.parse(A.w)/2-.3,y:Ae.parse(A.h)/2},{x:-Ae.parse(A.w)/2-.3,y:-Ae.parse(A.h)/2},{x:Ae.parse(A.p)/2,y:-Ae.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:GQt(A).concat(i,e),parameters:A}},kQt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},GQt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:o}=kQt({pn:e,p:Number.parseFloat(t.p)});A.push(Qi(e,i,o,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},FQt=Ji.extend({fn:H(),num_pins:WA().default(3),w:H().default("2.45mm"),h:H().default("2.40mm"),pl:H().default("1.225mm"),pw:H().default("0.5mm"),p:H().default("0.95mm"),string:H().optional()}),RQt=t=>{const A=t.string?.match(/^sot323_(\d+)/),e=A?Number.parseInt(A[1],3):3,i=FQt.parse({...t,num_pins:e});if(i.num_pins===3)return{circuitJson:NQt(i),parameters:i};throw new Error("Invalid number of pins")},MQt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e,y:.65}:A===2?{x:-e,y:-.65}:{x:e,y:0}},NQt=t=>{const A=[];for(let r=0;r<t.num_pins;r++){const{x:a,y:g}=MQt({num_pins:t.num_pins,pn:r+1,w:Number.parseFloat(t.w),h:Number.parseFloat(t.h),pl:Number.parseFloat(t.pl),p:Number.parseFloat(t.p)});A.push(Qi(r+1,a,g,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}const e=Yi(0,Number.parseInt(t.h)/2+1,.3),i=Number.parseFloat(t.w)/2-Number.parseFloat(t.pl),o=Number.parseFloat(t.h)/2,n={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-i,y:o+.3},{x:i,y:o+.3},{x:i,y:o/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:-o-.3},{x:i,y:-o-.3},{x:i,y:-o/2}],type:"pcb_silkscreen_path",stroke_width:.1};return[...A,n,s,e]},_Qt=Ji.extend({fn:H(),circle:ce().optional(),rect:ce().optional(),square:ce().optional(),pill:ce().optional(),d:Ae.optional(),pd:Ae.optional(),diameter:Ae.optional(),r:Ae.optional(),pr:Ae.optional(),radius:Ae.optional(),w:Ae.optional(),pw:Ae.optional(),width:Ae.optional(),h:Ae.optional(),ph:Ae.optional(),height:Ae.optional(),s:Ae.optional(),size:Ae.optional(),string:H().optional()}).transform(t=>{let A="rect";t.circle&&(A="circle"),t.square&&(A="square"),t.rect&&(A="rect"),t.pill&&(A="pill");let e,i,o;return A==="circle"?t.r!==void 0?e=mr(t.r):t.pr!==void 0?e=mr(t.pr):t.radius!==void 0?e=mr(t.radius):t.d!==void 0?e=mr(t.d)/2:t.pd!==void 0?e=mr(t.pd)/2:t.diameter!==void 0?e=mr(t.diameter)/2:e=mr("1mm")/2:(t.w!==void 0?i=mr(t.w):t.pw!==void 0?i=mr(t.pw):t.width!==void 0?i=mr(t.width):t.s!==void 0?i=mr(t.s):t.size!==void 0?i=mr(t.size):i=mr("1mm"),t.h!==void 0?o=mr(t.h):t.ph!==void 0?o=mr(t.ph):t.height!==void 0?o=mr(t.height):A==="square"||A==="rect"?o=i:o=mr("1mm")),{fn:t.fn,shape:A,radius:e,width:i,height:o}}),vQt=t=>{const A=_Qt.parse(t),{shape:e,radius:i,width:o,height:n}=A;let s,r;return e==="circle"?(s=ZWA(1,{x:0,y:0,radius:i}),r=i+.5):e==="pill"?(s=c5(1,0,0,o,n),r=Math.max(o,n)/2+.5):(s=Qi(1,0,0,o,n),r=n/2+.5),{circuitJson:[s,Yi(0,r,.2)],parameters:A}},UQt=Ji.extend({fn:H(),d:Ae.optional(),hd:Ae.optional(),r:Ae.optional(),hr:Ae.optional(),pd:Ae.optional(),pr:Ae.optional(),squarepad:ce().optional().default(!1)}).transform(t=>{let A;t.d!==void 0?A=mr(t.d):t.hd!==void 0?A=mr(t.hd):t.r!==void 0?A=mr(t.r)*2:t.hr!==void 0?A=mr(t.hr)*2:A=mr("1mm");let e;return t.pd!==void 0?e=mr(t.pd):t.pr!==void 0?e=mr(t.pr)*2:e=A*(1.5/1),{fn:t.fn,d:A,pd:e,squarepad:t.squarepad??!1}}),LQt=t=>{const A=UQt.parse(t),{d:e,pd:i,squarepad:o}=A;return{circuitJson:[o?uS(1,0,0,e,i,i):qn(1,0,0,e,i),Yi(0,i/2+.5,.2)],parameters:A}},HQt=Ji.extend({fn:H(),num_pins:xA(6).default(6),h:H().default("1.6mm"),pl:H().default("1mm"),pw:H().default("0.7mm"),p:H().default("0.95mm")}),YQt=t=>{const A=HQt.parse(t);return{circuitJson:JQt(A),parameters:A}},QZA=t=>{const{p:A,h:e,pn:i}=t;if(i===1)return{x:-e/2-.5,y:A};if(i===2)return{x:-e/2-.5,y:0};if(i===3)return{x:-e/2-.5,y:-A};if(i===4)return{x:e/2+.5,y:-A};if(i===5)return{x:e/2+.5,y:0};if(i===6)return{x:e/2+.5,y:A};throw new Error("Invalid pin number")},JQt=t=>{const A=[];for(let c=1;c<=t.num_pins;c++){const{x:B,y:C}=QZA({h:Number.parseFloat(t.h),p:Number.parseFloat(t.p),pn:c});A.push(Qi(c,B,C,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}const e=t.num_pins/2*Number.parseFloat(t.p),i=Number.parseFloat(t.h),o={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-e/3,y:i/2+Number.parseFloat(t.p)/1.3},{x:e/3,y:i/2+Number.parseFloat(t.p)/1.3}],type:"pcb_silkscreen_path",stroke_width:.05},n={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_2",route:[{x:-e/3,y:-i/2-Number.parseFloat(t.p)/1.3},{x:e/3,y:-i/2-Number.parseFloat(t.p)/1.3}],type:"pcb_silkscreen_path",stroke_width:.05},s=Yi(0,i+.3,.3),r=QZA({h:Number.parseFloat(t.h),p:Number.parseFloat(t.p),pn:1});r.x=r.x-Number.parseFloat(t.pw)*1.5;const a=.7,g=.3,I={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,o,n,I]},TQt=Ji.extend({fn:H(),num_pins:WA().default(4),w:H().default("3.2mm"),h:H().default("2.6mm"),pl:H().default("1.35mm"),pw:H().default("0.50mm"),p:H().default("0.6mm"),string:H().optional()}),KQt=t=>{const A=t.string?.match(/^sot343_(\d+)/),e=A?Number.parseInt(A[1],4):4,i=TQt.parse({...t,num_pins:e});if(i.num_pins===4)return{circuitJson:PQt(i),parameters:i};throw new Error("Invalid number of pins")},qQt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e*1.92,y:-.65}:A===2?{x:-e*1.92,y:.65}:A===3?{x:e,y:.65}:A===4?{x:e,y:-.65}:{x:0,y:0}},PQt=t=>{const A=[],e=Number.parseFloat(t.w),i=Number.parseFloat(t.h),o=Number.parseFloat(t.pl),n=Number.parseFloat(t.pw),s=Number.parseFloat(t.p);let r=1/0,a=-1/0,g=1/0,I=-1/0;for(let d=0;d<t.num_pins;d++){const{x:f,y:m}=qQt({num_pins:t.num_pins,pn:d+1,p:s});A.push(Qi(d+1,f,m,o,n)),f<r&&(r=f),f>a&&(a=f),m<g&&(g=m),m>I&&(I=m)}const c=(r+a)/2,B=I-g,C=i*.3,l=B/2+C;let Q=e*.8;i<=2.6&&(Q/=2);const E=Yi(c,l+.5,.3),h={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_top",route:[{x:c-Q/2,y:l},{x:c+Q/2,y:l}],type:"pcb_silkscreen_path",stroke_width:.1},u={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_bottom",route:[{x:c-Q/2,y:-l},{x:c+Q/2,y:-l}],type:"pcb_silkscreen_path",stroke_width:.1};return[...A,h,u,E]},OQt=Ji.extend({fn:H()}),WQt=t=>{const A=OQt.parse(t),e=[],i=.5-.15,o=1.5,s=.5/2,r=75,a=-37/2;for(let D=0;D<r;D++){const x=D+1;if(x>=24&&x<=31)continue;const F=a-D*s,k=x%2===0,v=o+(k?.25:0),Y=.5-v/2,P=Qi(x,Y,F,v,i);P.layer=k?"bottom":"top",e.push(P)}const g=46*.0254,I=137*.0254,c=261*.0254,B={type:"pcb_cutout",pcb_cutout_id:"",shape:"rect",center:{x:-I/2+o/2,y:a-c},width:I,height:g},C={x:-.5,y:a},l={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"};let Q=1/0,E=-1/0,h=1/0,u=-1/0;const d=(D,x,F=0,k=0)=>{Q=Math.min(Q,D-F/2),E=Math.max(E,D+F/2),h=Math.min(h,x-k/2),u=Math.max(u,x+k/2)};for(const D of e)d(D.x,D.y,D.width,D.height);d(B.center.x,B.center.y,B.width,B.height);for(const D of l.route)d(D.x,D.y);const f=(Q+E)/2,m=(h+u)/2,b=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(x=>({x:x.x-f,y:x.y-m})))};for(const D of e)b(D);return b(B),b(l),{circuitJson:[...e,B,l],parameters:A}},ZQt=Ji.extend({fn:H(),num_pins:WA().default(3),inline:ce().default(!1),p:H().default("1.27mm"),id:H().default("0.75mm"),od:H().default("1.3mm"),w:H().default("4.8mm"),h:H().default("4.0mm")}),VQt=t=>{const A=ZQt.parse(t),e=Number.parseFloat(A.p),i=Number.parseFloat(A.w),o=Number.parseFloat(A.h),n=A.inline?1.05:Number.parseFloat(A.od),s=A.inline?1.5:n,r=[uS(1,0,0,A.id,n,s,0,0),A.inline?$U(2,e,0,A.id,n,s):qn(2,e,e,A.id,n),A.inline?$U(3,e*2,0,A.id,n,s):qn(3,e*2,0,A.id,n)],a=i/2,g=A.inline?e-.09:e,I=.2,c=I+a-o,B=Array.from({length:32},(Q,E)=>{const h=Math.PI*E/31;return{x:g+a*Math.cos(h),y:I+a*Math.sin(h)}}),C={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"",stroke_width:.12,route:[...B,{x:g-a,y:c},{x:g+a,y:c},B[0]]},l=Yi(g,I+a+1,.5);return{circuitJson:[...r,C,l],parameters:A}};function jQt(t){return t!=null}var zQt=(t,A)=>{if(!A)return t;const e=t.filter(I=>I.type==="pcb_smtpad"||I.type==="pcb_plated_hole"||I.type==="pcb_thtpad");if(e.length===0)return t;let i=1/0,o=-1/0,n=1/0,s=-1/0;const r=(I,c,B=0,C=0)=>{const l=I-B/2,Q=I+B/2,E=c-C/2,h=c+C/2;i=Math.min(i,l),o=Math.max(o,Q),n=Math.min(n,E),s=Math.max(s,h)};for(const I of e)if(I.type==="pcb_smtpad"){const c=I.shape==="circle"?I.radius*2:I.width,B=I.shape==="circle"?I.radius*2:I.height;r(I.x,I.y,c,B)}else if(I.type==="pcb_plated_hole"){const c=I.outer_diameter??I.hole_diameter;r(I.x,I.y,c,c)}else if(I.type==="pcb_thtpad"){const c=I.diameter;r(I.x,I.y,c,c)}let a=0,g=0;switch(A){case"center":a=(i+o)/2,g=(n+s)/2;break;case"bottomleft":a=i,g=n;break;case"bottomcenter":case"centerbottom":a=(i+o)/2,g=n;break;case"topcenter":case"centertop":a=(i+o)/2,g=s;break;case"leftcenter":case"centerleft":a=i,g=(n+s)/2;break;case"rightcenter":case"centerright":a=o,g=(n+s)/2;break;case"pin1":const I=e.find(c=>c.port_hints?.[0]==="1")||e[0];a=I.x,g=I.y;break}if(a===0&&g===0)return t;for(const I of t){if(typeof I.x=="number"&&(I.x-=a),typeof I.y=="number"&&(I.y-=g),I.center&&typeof I.center.x=="number"&&(I.center.x-=a,I.center.y-=g),I.type==="pcb_silkscreen_path")for(const c of I.route)c.x-=a,c.y-=g;I.type==="pcb_silkscreen_text"&&I.anchor_position&&(I.anchor_position.x-=a,I.anchor_position.y-=g)}return t},XQt=(t,A)=>{const e=t.filter(i=>i.type==="pcb_silkscreen_text");if(e.length===0)return t;for(const i of e)A.norefdes&&(i.text="");return t},$Qt=(t,A)=>A.nosilkscreen?t.filter(e=>e.type!=="pcb_silkscreen_path"&&e.type!=="pcb_silkscreen_text"):t,AEt=t=>{let A=Q5();const i=t.replace(/^((?:\d{4}|\d{5}))(?=$|_)/,"res$1").split(/_(?!metric)/).map(o=>{const n=o.match(/([a-zA-Z]+)([\(\d\.\+\?].*)?/);if(!n)return null;const[,s,r]=n;if(!s)return null;const a=s.toLowerCase();return r?.includes("?")?null:{fn:a,v:r}}).filter(jQt);for(const{fn:o,v:n}of i)A=A[o](n);return A.setString(t),A},eEt=()=>Object.keys(hS),Q5=()=>{const t=new Proxy({},{get:(A,e)=>{if(e==="soup"||e==="circuitJson"){if("fn"in A&&hS[A.fn])return()=>{const{circuitJson:i}=hS[A.fn](A),o=$Qt(i,A),n=XQt(o,A);return zQt(n,A.origin)};if(!hS[A.fn])throw new Error(`Invalid footprint function, got "${A.fn}"${A.string?`, from string "${A.string}"`:""}`);return()=>{throw new Error(`No function found for footprinter, make sure to specify .dip, .lr, .p, etc. Got "${e}"`)}}if(e==="json"){if(!hS[A.fn])throw new Error(`Invalid footprint function, got "${A.fn}"${A.string?`, from string "${A.string}"`:""}`);return()=>hS[A.fn](A).parameters}return e==="getFootprintNames"?()=>Object.keys(hS):e==="params"?()=>A:e==="setString"?i=>(A.string=i,t):i=>(Object.keys(A).length===0?`${e}${i}`in hS?(A[`${e}${i}`]=!0,A.fn=`${e}${i}`):(A[e]=!0,A.fn=e,e==="res"||e==="cap"?i&&(typeof i=="string"&&i.includes("_metric")?A.metric=i.split("_metric")[0]:A.imperial=i):A.num_pins=Number.isNaN(Number.parseFloat(i))?void 0:Number.parseFloat(i)):!i&&["w","h","p"].includes(e)||(A[e]=i??!0),t)}});return t};Q5.string=AEt,Q5.getFootprintNames=eEt;var tEt=Q5,EZA=Symbol("Fragment");function oCA(t,A,...e){const i=e.length?e:A?.children!==void 0?[A.children]:[],o=[],n=(Array.isArray(i)?i:[i]).flat(1/0);for(const s of n)s==null||s===!1||(Array.isArray(s)?o.push(...s):o.push(s));return{type:t,props:(A&&A.children!==void 0?{...A,children:void 0}:A)||{},children:o}}var ut=Symbol("Cuboid"),hZA=Symbol("Cube"),Vp=Symbol("Cylinder"),uZA=Symbol("Sphere"),AL=Symbol("RoundedCuboid"),Zi=Symbol("Translate"),pQ=Symbol("Rotate"),lE=Symbol("Union"),nF=Symbol("Subtract"),BI=Symbol("Hull"),fs=Symbol("Colorize"),eL=Symbol("Polygon"),tL=Symbol("ExtrudeLinear"),jp=Symbol("RoundedCylinder"),Jo=EZA,ee=(t,A,e)=>oCA(t,A),Pt=(t,A,e)=>oCA(t,A),zB=({center:t,width:A,length:e,height:i,heightAboveSurface:o=.15,color:n="#555",taperRatio:s=.12,faceRatio:r=.75,straightHeightRatio:a=.5,includeNotch:g=!0,notchRadius:I,notchPosition:c,notchRotation:B=[0,0,0],notchLength:C=.5,notchWidth:l=.25,chamferSize:Q=0})=>{const E=i*a,h=i-E,u=Math.min(A,e)*s,d=Math.max(A-u,A*r),f=Math.max(e-u,e*r),m=Math.min(A,e)*.12,b=I??m,D={x:0,y:e/2-b*.25,z:i},x=c??D,F=Pt(lE,{children:[Pt(BI,{children:[ee(Zi,{z:.005,children:ee(ut,{size:[d,f,.01]})}),ee(Zi,{z:E,children:ee(ut,{size:[A,e,.01]})})]}),Pt(BI,{children:[ee(Zi,{z:E,children:ee(ut,{size:[A,e,.01]})}),ee(Zi,{z:E+h,children:ee(ut,{size:[d,f,.01]})})]})]}),k=(_,Y)=>ee(Zi,{offset:{x:_,y:Y,z:0},children:ee(pQ,{rotation:[0,0,Math.PI/4],children:ee(ut,{size:[Q*Math.SQRT2,Q*Math.SQRT2,i*3]})})});let v=F;if(Q>0){const _=A/2,Y=e/2;v=Pt(nF,{children:[F,k(_,Y),k(-_,Y),k(_,-Y),k(-_,-Y)]})}return ee(fs,{color:n,children:ee(Zi,{offset:t,children:ee(Zi,{offset:{x:0,y:0,z:o},children:g?Pt(nF,{children:[v,ee(Zi,{offset:x,children:ee(pQ,{rotation:B,children:ee(Vp,{radius:b,height:l})})})]}):v})})})},iEt=t=>Array.from({length:t},(A,e)=>e);function nCA(t,A){if(t.length<2)throw new Error("Stroke must have at least two points");const e=Array.isArray(t[0])?t.map(([I,c])=>({x:I,y:c})):t,i=A/2,o=[],n=[];function s(I,c){const B=c.x-I.x,C=c.y-I.y,l=Math.sqrt(B*B+C*C);return{x:-C/l,y:B/l}}function r(I,c,B){const C={x:I.x+c.x*i*B,y:I.y+c.y*i*B};B>0?o.push(C):n.unshift(C)}const a=s(e[0],e[1]);r(e[0],a,1),r(e[0],a,-1);for(let I=1;I<e.length-1;I++){const c=e[I-1],B=e[I],C=e[I+1],l=s(c,B),Q=s(B,C),E=l.x+Q.x,h=l.y+Q.y,u=Math.sqrt(E*E+h*h);if(u/2>2*i)r(B,l,1),r(B,Q,1),r(B,l,-1),r(B,Q,-1);else{const f=1/u;r(B,{x:E*f,y:h*f},1),r(B,{x:E*f,y:h*f},-1)}}const g=s(e[e.length-2],e[e.length-1]);return r(e[e.length-1],g,1),r(e[e.length-1],g,-1),[...o,...n]}var oEt=t=>{const A=Math.min(...t.map(r=>r.x)),e=Math.max(...t.map(r=>r.x)),i=Math.min(...t.map(r=>r.y)),s=5.47/(Math.max(...t.map(r=>r.y))-i);return t.map(r=>({x:(r.x-A-(e-A)/2)*s,y:(r.y-i)*s}))},nEt=oEt([{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}]),dZA=5.47,E5=.5,sEt=({x:t,y:A,z:e})=>{const i=t>0;return Pt(Jo,{children:[ee(Zi,{offset:{x:t+.25/2,y:A,z:e},children:ee(pQ,{rotation:["-90deg",0,"90deg"],children:ee(tL,{height:.25,children:ee(eL,{points:nEt.slice().reverse().map(o=>[o.x,o.y])})})})}),ee(Zi,{offset:{x:t,y:A+(i?1:-1),z:e},children:ee(pQ,{rotation:["-90deg","90deg",i?"180deg":"0deg"],children:ee(tL,{height:2,children:ee(eL,{points:nCA([[0,0],[-1,0],[-1,-1]],.25).map(o=>[o.x,o.y])})})})})]})},rEt=({numPins:t=8,pitch:A=2.54,bodyWidth:e=6.4,rowSpacing:i})=>{const o=Math.floor(t/2),n=i??(e>=7?e:e+1.22),s=e>=7?n-1.22:e;return Pt(Jo,{children:[iEt(t).map(r=>{const a=r%o,g=(Math.floor(r/o)-.5)*2;return ee(sEt,{x:g*n/2,y:a*A-(o-1)/2*A,z:dZA/2+E5})}),ee(zB,{width:s,length:o*A+.5,height:dZA-E5,heightAboveSurface:E5,center:{x:0,y:0,z:E5}})]})};function aEt(t,{height:A,padContactLength:e,curveLength:i,bodyDistance:o,steepness:n=10}){i||(i=o*.3);let s=o-e-i;s<0&&(i+=s,s=0);const r=e*.75,a=e+i+(o-e-i)*.25;if(t<=r)return 0;if(t>=a)return A;const g=(t-r)/(a-r);return A/(1+Math.exp(-n*(g-.5)))}var qo=t=>{const{thickness:A,width:e,padContactLength:i,bodyDistance:o,height:n,rotation:s}=t,r=15,a=Array.from({length:r}).map((I,c)=>c/(r-1)*o).map(I=>[I,aEt(I,t)]),g=nCA(a,A);return ee(fs,{color:"#fff",children:ee(Zi,{offset:{z:0,y:0,x:0,...t.position},children:ee(pQ,{rotation:["90deg",0,s??0],children:ee(Zi,{offset:{x:0,y:0,z:-e/2},children:ee(tL,{height:e,children:ee(eL,{points:g.map(I=>[I.x,I.y])})})})})})})},gEt=({pinCount:t,leadLength:A,leadWidth:e,pitch:i,bodyWidth:o})=>{const n=Math.ceil(t/2),s=i*t/2+e/2,r=(n-1)*i/2,a=.25;return Pt(Jo,{children:[Array.from({length:n}).map((g,I)=>ee(qo,{position:{x:-o/2-A,y:I*i-r,z:a/2},width:e,thickness:a,padContactLength:A,bodyDistance:A+1,height:.8})),Array.from({length:n}).map((g,I)=>ee(qo,{rotation:Math.PI,position:{x:o/2+A,y:I*i-r,z:a/2},width:e,thickness:a,padContactLength:A,bodyDistance:A+1,height:.8})),ee(zB,{center:{x:0,y:0,z:a/2},width:o-e-1,length:s,height:1.5})]})},IEt=({pinCount:t,padContactLength:A=.4,leadWidth:e=.2,pitch:i=.65,bodyWidth:o=3})=>{const n=Math.ceil(t/2),s=(n-1)*i/2,r=.2;return Pt(Jo,{children:[Array.from({length:n}).map((a,g)=>ee(qo,{position:{x:-o/2-A-.3,y:g*i-s,z:r/2},width:e,thickness:r,padContactLength:A,bodyDistance:A+.4,height:.6})),Array.from({length:n}).map((a,g)=>ee(qo,{rotation:Math.PI,position:{x:o/2+A+.3,y:g*i-s,z:r/2},width:e,thickness:r,padContactLength:A,bodyDistance:A+.4,height:.6})),ee(zB,{center:{x:0,y:0,z:r/2},width:o,length:o,height:1.1,notchRadius:.35,heightAboveSurface:.1,taperRatio:.09})]})},sCA=1,rCA=.5,XN=.5,iL=.2,cEt=sCA-iL*2,pZA=({color:t="#333"})=>Pt(Jo,{children:[ee(ut,{size:[cEt,rCA,XN],offset:[0,0,XN/2],color:t}),ee(ut,{size:[iL,XN,rCA],offset:[sCA/2-iL/2,0,XN/2],color:"#ccc"}),ee(ut,{size:[iL,XN,rCA],offset:[-sCA/2+iL/2,0,XN/2],color:"#ccc"})]}),aCA=1.6,BEt=aCA-.3*2,h5=.3,gCA=.85,$N=.6,fZA=({color:t="#333"})=>Pt(Jo,{children:[ee(ut,{size:[BEt,gCA,$N],offset:[0,0,$N/2],color:t}),ee(ut,{size:[h5,gCA,$N],offset:[aCA/2-h5/2,0,$N/2],color:"#ccc"}),ee(ut,{size:[h5,gCA,$N],offset:[-aCA/2+h5/2,0,$N/2],color:"#ccc"})]}),ICA=2,cCA=1.25,A_=.55,oL=.5,CEt=ICA-oL*2,yZA=({color:t="#333"})=>Pt(Jo,{children:[ee(ut,{size:[CEt,cCA,A_],offset:[0,0,A_/2],color:t}),ee(ut,{size:[oL,cCA,A_],offset:[ICA/2-oL/2,0,A_/2],color:"#ccc"}),ee(ut,{size:[oL,cCA,A_],offset:[-ICA/2+oL/2,0,A_/2],color:"#ccc"})]}),lEt=({pinCount:t,pitch:A,leadWidth:e,padContactLength:i,bodyWidth:o})=>{const n=t/4;A||(A=QEt(t,o)),i||(i=EEt(t)),e||(e=hEt(t,o)),o||(o=A*(n+4));const s=o,r=(n-1)*A/2,a=s+2*i,g=a,I=.8,c=.15,B=(g-o)/2+.5;return Pt(Jo,{children:[Array.from({length:n}).map((C,l)=>ee(qo,{position:{x:-g/2-.4,y:l*A-r,z:c/2},width:e,thickness:c,padContactLength:i,bodyDistance:B,height:I})),Array.from({length:n}).map((C,l)=>ee(qo,{rotation:Math.PI,position:{x:g/2+.4,y:l*A-r,z:c/2},width:e,thickness:c,padContactLength:i,bodyDistance:B,height:I})),Array.from({length:n}).map((C,l)=>ee(qo,{rotation:Math.PI/2,position:{x:l*A-r,y:-a/2-.4,z:c/2},width:e,thickness:c,padContactLength:i,bodyDistance:B,height:I})),Array.from({length:n}).map((C,l)=>ee(qo,{rotation:-Math.PI/2,position:{x:l*A-r,y:a/2+.4,z:c/2},width:e,thickness:c,padContactLength:i,bodyDistance:B,height:I})),ee(zB,{center:{x:0,y:0,z:0},width:o,length:s,height:1.5,taperRatio:.03,chamferSize:.7,notchPosition:{x:-(s/2-1.5),y:o/2-1.5,z:1.5},notchRadius:1.5/2})]})},QEt=(t,A)=>{switch(t){case 44:case 64:return .8;case 52:return A===14?1:.65;case 208:return .5;default:return .5}},EEt=t=>{switch(t){case 32:return .6;case 40:return .6;case 52:case 64:return .65;case 208:return 1.65;default:return .6}},hEt=(t,A)=>{switch(t){case 44:case 64:return .5;case 52:return A===14?.45:.55;case 208:return .3;default:return .25}},uEt=({numberOfPins:t,pitch:A=2.54,longSidePinLength:e=6,invert:i,faceup:o,rows:n=1})=>{const a=Math.ceil(t/n),g=2.54,I=a*A,c=n>1?(n-1)*g+.63*3:.63*3,B=3,C=-((a-1)/2)*A,l=n>1?-((n-1)*g)/2:0,Q=E=>i||o?-E+2:E;return Pt(Jo,{children:[ee(ut,{color:"#222",size:[I,c,2],center:[0,l,Q(2/2)]}),Array.from({length:t},(E,h)=>{const u=Math.floor(h/a),d=h%a,f=C+d*A,m=-u*g;return Pt(Jo,{children:[!o&&ee(fs,{color:"gold",children:Pt(BI,{children:[ee(ut,{color:"gold",size:[.63,.63,B*.9],center:[f,m,Q(2*.9+2/2)]}),ee(ut,{color:"gold",size:[.63/1.8,.63/1.8,B],center:[f,m,Q(2+2/2)]})]})}),ee(fs,{color:"gold",children:Pt(BI,{children:[ee(ut,{color:"gold",size:[.63,.63,e*.9],center:[f,m,Q(-e/2*.9)]}),ee(ut,{color:"gold",size:[.63/1.8,.63/1.8,e],center:[f,m,Q(-e/2)]})]})})]})})]})},dEt=t=>{const A=["left","bottom","right","top"],{pin_count:e,pn:i,w:o,h:n,p:s,pl:r}=t,a=e/4,g=A[Math.floor((i-1)/a)],I=(i-1)%a,c=s*(a-1),B=s*(a-1),C=-r/2;switch(g){case"left":return{x:-o/2-C,y:B/2-I*s,o:"vert"};case"bottom":return{x:-c/2+I*s,y:-n/2-C,o:"horz"};case"right":return{x:o/2+C,y:-B/2+I*s,o:"vert"};case"top":return{x:c/2-I*s,y:n/2+C,o:"horz"};default:throw new Error("Invalid pin number")}},pEt=({num_pins:t,cw:A,ccw:e,startingpin:i})=>{const o=[],n=t/4;let s=1;const r={};for(const a of i??[])r[a]=!0;!r.leftside&&!r.topside&&!r.rightside&&!r.bottomside&&(r.leftside=!0),!r.bottompin&&!r.leftpin&&!r.rightpin&&!r.toppin&&(r.leftside?r.toppin=!0:r.topside?r.rightpin=!0:r.rightside?r.bottompin=!0:r.bottomside&&(r.leftpin=!0)),r.leftside&&r.toppin?s=1:r.leftside&&r.bottompin?s=n:r.bottomside&&r.leftpin?s=n+1:r.bottomside&&r.rightpin?s=n*2:r.rightside&&r.bottompin?s=n*2+1:r.rightside&&r.toppin?s=n*3:r.topside&&r.rightpin?s=n*3+1:r.topside&&r.leftpin&&(s=n*4),o.push(-1);for(let a=0;a<t;a++)o[s]=a+1,s++,s>t&&(s=1);return o},fEt=({num_pins:t=16,bodyWidth:A=9,bodyLength:e=9,bodyThickness:i=.8,thermalPadSize:o,padWidth:n=.25,padLength:s=.25,pitch:r=.5,thermalPadThickness:a=.05})=>{const g=pEt({num_pins:t,cw:!0,ccw:!0}),I=[];for(let c=0;c<t;c++){const{x:B,y:C,o:l}=dEt({pin_count:t,pn:c+1,w:A,h:e,p:r,pl:s});let Q=n,E=s;l==="vert"&&([Q,E]=[E,Q]);const h=g[c+1];I.push({pn:h,x:B,y:C,pw:Q,pl:E})}return Pt(Jo,{children:[ee(fs,{color:"grey",children:ee(ut,{center:{x:0,y:0,z:i/2},size:[A,e,i]})}),I.map((c,B)=>ee(ut,{center:{x:c.x,y:c.y,z:a/2},size:[c.pw,c.pl,a]})),o?.length!==void 0&&o?.width!==void 0&&ee(ut,{center:{x:0,y:0,z:a/2},size:[o.width,o.length,a]})]})},yEt=fEt,wEt=()=>{const a=1.1999999999999997;return Pt(Jo,{children:[ee(qo,{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}),ee(qo,{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}),ee(qo,{position:{x:-2.8/2-a/4,y:0,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:a,height:.95}),ee(qo,{position:{x:-2.8/2-a/4,y:-1,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:a,height:.95}),ee(qo,{position:{x:-2.8/2-a/4,y:1,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:a,height:.95}),ee(zB,{center:{x:0,y:0,z:0},width:1.6,length:2.9,height:1.2})]})},mEt=wEt,DEt=({fullWidth:t=2.9,fullLength:A=2.8})=>{const I=(t-1.92)/2+.3;return Pt(Jo,{children:[ee(qo,{rotation:Math.PI,position:{x:t/2,y:0,z:.075},width:.4,thickness:.15,padContactLength:.25,bodyDistance:I,height:.45}),ee(qo,{position:{x:-t/2,y:-.95,z:.075},width:.4,thickness:.15,padContactLength:.25,bodyDistance:I,height:.45}),ee(qo,{position:{x:-t/2,y:.95,z:.075},width:.4,thickness:.15,padContactLength:.25,bodyDistance:I,height:.45}),ee(zB,{center:{x:0,y:0,z:0},width:1.92,length:2.9,height:1.1,straightHeightRatio:.45,heightAboveSurface:.05})]})},BCA=.6,CCA=.3,e_=.33,nL=.1,SEt=BCA-nL*2,wZA=({color:t="#333"})=>Pt(Jo,{children:[ee(ut,{size:[SEt,CCA,e_],offset:[0,0,e_/2],color:t}),ee(ut,{size:[nL,CCA,e_],offset:[BCA/2-nL/2,0,e_/2],color:"#ccc"}),ee(ut,{size:[nL,CCA,e_],offset:[-BCA/2+nL/2,0,e_/2],color:"#ccc"})]}),lCA=.4,QCA=.2,t_=.13,sL=.07,bEt=lCA-sL*2,mZA=({color:t="#333"})=>Pt(Jo,{children:[ee(ut,{size:[bEt,QCA,t_],offset:[0,0,t_/2],color:t}),ee(ut,{size:[sL,QCA,t_],offset:[lCA/2-sL/2,0,t_/2],color:"#ccc"}),ee(ut,{size:[sL,QCA,t_],offset:[-lCA/2+sL/2,0,t_/2],color:"#ccc"})]}),ECA=3.2,hCA=1.6,i_=.9,rL=.5,xEt=ECA-rL*2,DZA=({color:t="#333"})=>Pt(Jo,{children:[ee(ut,{size:[xEt,hCA,i_],offset:[0,0,i_/2],color:t}),ee(ut,{size:[rL,hCA,i_],offset:[ECA/2-rL/2,0,i_/2],color:"#ccc"}),ee(ut,{size:[rL,hCA,i_],offset:[-ECA/2+rL/2,0,i_/2],color:"#ccc"})]}),uCA=3.2,dCA=2.5,o_=1,aL=.6,kEt=uCA-aL*2,SZA=({color:t="#333"})=>Pt(Jo,{children:[ee(ut,{size:[kEt,dCA,o_],offset:[0,0,o_/2],color:t}),ee(ut,{size:[aL,dCA,o_],offset:[uCA/2-aL/2,0,o_/2],color:"#ccc"}),ee(ut,{size:[aL,dCA,o_],offset:[-uCA/2+aL/2,0,o_/2],color:"#ccc"})]}),pCA=5,fCA=2.5,n_=1.4,gL=.6,GEt=pCA-gL*2,bZA=({color:t="#333"})=>Pt(Jo,{children:[ee(ut,{size:[GEt,fCA,n_],offset:[0,0,n_/2],color:t}),ee(ut,{size:[gL,fCA,n_],offset:[pCA/2-gL/2,0,n_/2],color:"#ccc"}),ee(ut,{size:[gL,fCA,n_],offset:[-pCA/2+gL/2,0,n_/2],color:"#ccc"})]}),yCA=6.3,wCA=3.2,s_=1.8,IL=.8,FEt=yCA-IL*2,xZA=({color:t="#333"})=>Pt(Jo,{children:[ee(ut,{size:[FEt,wCA,s_],offset:[0,0,s_/2],color:t}),ee(ut,{size:[IL,wCA,s_],offset:[yCA/2-IL/2,0,s_/2],color:"#ccc"}),ee(ut,{size:[IL,wCA,s_],offset:[-yCA/2+IL/2,0,s_/2],color:"#ccc"})]}),REt=({numberOfPins:t,pitch:A=2.54,legsLength:e=3,outerDiameter:i=.945,innerDiameter:o=.945,rows:n=1})=>{const s=o/1.5,r=s*2+i,a=5,g=Math.ceil(t/n),I=2.54,c=(g-1)*A+i+A/2,B=n>1?(n-1)*I+r:r,C=s*1.6,l=-((g-1)/2)*A,Q=n>1?-((n-1)*I)/2:0,E=ee(fs,{color:"#1a1a1a",children:Pt(nF,{children:[ee(ut,{color:"#000",size:[c,B,a],center:[0,Q,a/2]}),Array.from({length:t},(h,u)=>{const d=Math.floor(u/g),f=u%g,m=l+f*A,b=-d*I;return o?ee(Vp,{height:a+.1,radius:o/2,center:[m,b,a/2],color:"#222"},u):ee(ut,{size:[C,C,a],center:[m,b,a/2]},u)})]})});return Pt(Jo,{children:[E,Array.from({length:t},(h,u)=>{const d=Math.floor(u/g),f=u%g,m=l+f*A,b=-d*I;return Pt(fs,{color:"silver",children:[Pt(BI,{children:[ee(ut,{color:"silver",size:[s,s,e*.9],center:[m,b,-e/2*.9]}),ee(ut,{color:"silver",size:[s/1.8,s/1.8,e],center:[m,b,-e/2]})]}),ee(ut,{color:"silver",size:[C,C,C*.5],center:[m,b,C/2*.5]})]},u)})]})},MEt=({width:t,length:A,innerDiameter:e=1})=>{const i=t,o=A,n=t*.7,s=e/2.5;return Pt(Jo,{children:[ee(AL,{color:"#1a1a1f",center:[0,0,n/2],size:[o,o,n],roundRadius:.3}),ee(AL,{color:"#f2f2f2",center:[0,0,n+n*.1/2.5],size:[o,o,n*.1],roundRadius:.14}),ee(Vp,{color:"#1a1a1f",height:n*.8,radius:i/3,center:[0,0,n+n*.8/2]}),ee(Vp,{color:"#1a1a1f",height:n*.2,radius:e/2,center:[o/3,o/3,n+n*.1/2]}),ee(Vp,{color:"#1a1a1f",height:n*.2,radius:e/2,center:[-o/3,-o/3,n+n*.1/2]}),ee(Vp,{color:"#1a1a1f",height:n*.2,radius:e/2,center:[-o/3,o/3,n+n*.1/2]}),ee(Vp,{color:"#1a1a1f",height:n*.2,radius:e/2,center:[o/3,-o/3,n+n*.1/2]}),ee(u5,{thickness:e/3,width:s,horizontalLength:o*.8,verticalLength:n/2,position:{x:-i/2,y:-o/2,z:-n*1.2}}),ee(u5,{thickness:e/3,width:s,horizontalLength:o*.8,verticalLength:n/2,position:{x:-i/2,y:o/2,z:-n*1.2},rotation:Math.PI}),ee(u5,{thickness:e/3,width:s,horizontalLength:o*.8,verticalLength:n/2,position:{x:i/2,y:o/2,z:-n*1.2},rotation:Math.PI}),ee(u5,{thickness:e/3,width:s,horizontalLength:o*.8,verticalLength:n/2,position:{x:i/2+e/3.6,y:-o/2,z:-n*1.2}})]})},u5=t=>{const{thickness:A,width:e,horizontalLength:i,verticalLength:o,rotation:n=0,position:s}=t,r=[[0,i],[-o/3,i/3],[-o/5,i/4],[0,0]],a=nCA(r,A);return ee(fs,{color:"#f2f2f2",children:ee(Zi,{offset:{x:s?.x||0,y:s?.y||0,z:s?.z||0},children:ee(pQ,{rotation:[0,55,n],children:ee(tL,{height:e,children:ee(eL,{points:a.map(g=>[g.y,g.x])})})})})})},NEt=({pinCount:t,leadLength:A,leadWidth:e,pitch:i,bodyWidth:o})=>{const n=Math.ceil(t/2),s=(n-1)*i/2,r=.25,a=1,g=.8,I=A*0,c=i*(n-1)+e+.2,B=o*.55;return Pt(Jo,{children:[Array.from({length:n}).map((C,l)=>ee(qo,{position:{x:-o/2-I,y:l*i-s,z:r/2},width:e,thickness:r,padContactLength:A/2,bodyDistance:A+.3,height:g})),Array.from({length:n}).map((C,l)=>ee(qo,{rotation:Math.PI,position:{x:o/2+I,y:l*i-s,z:r/2},width:e,thickness:r,padContactLength:A/2,bodyDistance:A+.3,height:g})),ee(zB,{center:{x:0,y:0,z:r/2},width:B,length:c,height:a})]})},_Et=({pinCount:t,pitch:A,leadWidth:e,leadLength:i,bodyWidth:o,bodyLength:n})=>{const s=t===8?{pitch:.65,leadWidth:.3}:{pitch:.5,leadWidth:.225},r=isNaN(parseFloat(A))?s.pitch:parseFloat(A),a=isNaN(parseFloat(e))?s.leadWidth:parseFloat(e)*.8,g=isNaN(parseFloat(o))?2.6:parseFloat(o)*.8,I=isNaN(parseFloat(n))?2+Number(r)*1.4:parseFloat(n),c=t/2,B=(c-1)*r/2,C=.15,l=.8,Q=4.5,E=(Q-g)/2,h=E*.5;return Pt(Jo,{children:[Array.from({length:c}).map((u,d)=>ee(qo,{position:{x:-Q/2,y:B-d*r,z:C/2},width:a,thickness:C,padContactLength:h+.05,bodyDistance:E+.1,height:l})),Array.from({length:c}).map((u,d)=>ee(qo,{rotation:Math.PI,position:{x:Q/2,y:B-d*r,z:C/2},width:a,thickness:C,padContactLength:h+.05,bodyDistance:E+.1,height:l})),ee(zB,{center:{x:0,y:0,z:C/2},width:g,length:I,height:1})]})},vEt=()=>Pt(Jo,{children:[ee(ut,{color:"#ccc",size:[.5,.6,.12],center:[-.725,0,.12/2]}),ee(ut,{color:"#ccc",size:[.5,.6,.12],center:[.725,0,.12/2]}),ee(fs,{color:"#222",children:Pt(lE,{children:[ee(Zi,{z:.3/2,children:ee(ut,{size:[1.65,.8,.3]})}),Pt(BI,{children:[ee(Zi,{z:.3,children:ee(ut,{size:[1.65,.8,.01]})}),ee(Zi,{z:.6,children:ee(ut,{size:[1.65-.2,.8-.2,.01]})})]})]})})]}),UEt=()=>Pt(Jo,{children:[ee(ut,{color:"#ccc",size:[.26,.51,.12],center:[-.325,0,.12/2]}),ee(ut,{color:"#ccc",size:[.26,.51,.12],center:[.325,0,.12/2]}),ee(fs,{color:"#222",children:ee(Zi,{z:.47/2+.02,children:ee(ut,{size:[.98,.58,.47]})})}),ee(ut,{color:"#ccc",size:[.98+.001,.26/2,.26/4],center:[0,.26/2,.47/4]}),ee(ut,{color:"#ccc",size:[.98+.001,.26/2,.26/4],center:[0,-.26/2,.47/4]}),ee(ut,{color:"#ccc",size:[.26/1.5,.58+.001,.26/4],center:[.65/2,0,.47/4]}),ee(ut,{color:"#ccc",size:[.26/1.5,.58+.001,.26/4],center:[-.65/2,0,.47/4]})]}),LEt=()=>{const g=ee(fs,{color:"#1a1a1a",children:Pt(lE,{children:[Pt(BI,{children:[ee(Zi,{z:.13,children:ee(ut,{size:[4,3,.03]})}),ee(Zi,{z:1.15,children:ee(ut,{size:[4.4,3.4,.01]})})]}),Pt(BI,{children:[ee(Zi,{z:1.15,children:ee(ut,{size:[4.4,3.4,.01]})}),ee(Zi,{z:2.3,children:ee(ut,{size:[4,3,.01]})})]})]})}),I=({xDir:c})=>{const l=c*1.78,Q=c*(3.4/2-.2/2+1),E=c*(3.4/2-.2/2),h=Math.abs(E-Q),u=(Q+E)/2;return ee(fs,{color:"#c0c0c0",children:Pt(lE,{children:[ee(ut,{size:[2.3*.8,1.45,.2],center:[l,0,.2/2]}),ee(ut,{size:[.2,1.45,1.14],center:[Q,0,1.14/2+.2]}),ee(ut,{size:[h,1.45,.2],center:[u,0,.2/2+1.14]})]})})};return Pt(Jo,{children:[ee(I,{xDir:1}),ee(I,{xDir:-1}),g]})},HEt=()=>{const g=ee(fs,{color:"#1a1a1a",children:Pt(lE,{children:[Pt(BI,{children:[ee(Zi,{z:.13,children:ee(ut,{size:[4,3,.03]})}),ee(Zi,{z:1.15,children:ee(ut,{size:[4.4,3.4,.01]})})]}),Pt(BI,{children:[ee(Zi,{z:1.15,children:ee(ut,{size:[4.4,3.4,.01]})}),ee(Zi,{z:2.3,children:ee(ut,{size:[4,3,.01]})})]})]})}),I=({xDir:c})=>{const l=c*1.78,Q=c*(3.4/2-.2/2+1),E=c*(3.4/2-.2/2),h=Math.abs(E-Q),u=(Q+E)/2;return ee(fs,{color:"#c0c0c0",children:Pt(lE,{children:[ee(ut,{size:[2.3*.8,1.45,.2],center:[l,0,.2/2]}),ee(ut,{size:[.2,1.45,1.14],center:[Q,0,1.14/2+.2]}),ee(ut,{size:[h,1.45,.2],center:[u,0,.2/2+1.14]})]})})};return Pt(Jo,{children:[ee(I,{xDir:1}),ee(I,{xDir:-1}),g]})},YEt=()=>{const g=ee(fs,{color:"#1a1a1a",children:Pt(lE,{children:[Pt(BI,{children:[ee(Zi,{z:.21000000000000002,children:ee(ut,{size:[6.3999999999999995,5.6,.03]})}),ee(Zi,{z:1.15,children:ee(ut,{size:[6.8,6,.01]})})]}),Pt(BI,{children:[ee(Zi,{z:1.15,children:ee(ut,{size:[6.8,6,.01]})}),ee(Zi,{z:2.3,children:ee(ut,{size:[6.3999999999999995,5.6,.01]})})]})]})}),I=({xDir:c})=>{const l=c*3.08,Q=c*(6/2-.2/2+1),E=c*(6/2-.2/2),h=Math.abs(E-Q),u=(Q+E)/2;return ee(fs,{color:"#c0c0c0",children:Pt(lE,{children:[ee(ut,{size:[2.3*.8,2.95,.2],center:[l,0,.2/2]}),ee(ut,{size:[.2,2.95,1.14],center:[Q,0,1.14/2+.2]}),ee(ut,{size:[h,2.95,.2],center:[u,0,.2/2+1.14]})]})})};return Pt(Jo,{children:[ee(I,{xDir:1}),ee(I,{xDir:-1}),g]})},JEt=()=>{const c=ee(fs,{color:"#222",children:Pt(lE,{children:[ee(Zi,{z:.27,children:ee(ut,{size:[2.9,1.9,.54]})}),Pt(BI,{children:[ee(Zi,{z:.54,children:ee(ut,{size:[2.9,1.9,.01]})}),ee(Zi,{z:1.08,children:ee(ut,{size:[2.6999999999999997,1.7,.01]})})]})]})});return Pt(Jo,{children:[ee(ut,{color:"#ccc",size:[1,1.2,.25],center:[-1.3,0,.25/2]}),ee(ut,{color:"#ccc",size:[1,1.2,.25],center:[1.3,0,.25/2]}),c]})},TEt=()=>Pt(Jo,{children:[ee(ut,{color:"#ccc",size:[1,.6,.12],center:[-1.3,0,.12/2]}),ee(ut,{color:"#ccc",size:[1,.6,.12],center:[1.3,0,.12/2]}),ee(fs,{color:"#222",children:Pt(lE,{children:[ee(Zi,{z:.55/2,children:ee(ut,{size:[2.7,1.6,.55]})}),Pt(BI,{children:[ee(Zi,{z:.55,children:ee(ut,{size:[2.7,1.6,.01]})}),ee(Zi,{z:1.1,children:ee(ut,{size:[2.7-.2,1.6-.2,.01]})})]})]})})]}),KEt=()=>Pt(Jo,{children:[ee(ut,{color:"#ccc",size:[1,.9,.2],center:[-1.3,0,.2/2]}),ee(ut,{color:"#ccc",size:[1,.9,.2],center:[1.3,0,.2/2]}),ee(fs,{color:"#222",children:Pt(lE,{children:[ee(Zi,{z:.2/2,children:ee(ut,{size:[2.75,1.8,.2]})}),Pt(BI,{children:[ee(Zi,{z:.2,children:ee(ut,{size:[2.75,1.8,.01]})}),ee(Zi,{z:1,children:ee(ut,{size:[2.75-.4,1.8-.4,.01]})})]})]})}),ee(ut,{color:"#777",size:[.2,1.8-.4,.01],center:[-1.3+.4,0,1]})]}),qEt=()=>Pt(Jo,{children:[ee(ut,{color:"#ccc",size:[.9,.9,.2],center:[-1.225,0,.2/2]}),ee(ut,{color:"#ccc",size:[.9,.9,.2],center:[1.225,0,.2/2]}),ee(fs,{color:"#222",children:Pt(lE,{children:[Pt(BI,{children:[ee(Zi,{z:.2,children:ee(ut,{size:[2.6-.1/2,1.7-.1/2,.01]})}),ee(Zi,{z:.01,children:ee(ut,{size:[2.6-.1,1.7-.1,.01]})})]}),Pt(BI,{children:[ee(Zi,{z:.2,children:ee(ut,{size:[2.6,1.7,.01]})}),ee(Zi,{z:1,children:ee(ut,{size:[2.6-.4,1.7-.4,.01]})})]})]})}),ee(ut,{color:"#777",size:[.2*2.7,1.7-.4,.02],center:[-1.225+.4,0,1]})]}),PEt=()=>Pt(Jo,{children:[ee(ut,{color:"#ccc",size:[.9,1.75,.2],center:[-1.825,0,.2/2]}),ee(ut,{color:"#ccc",size:[.9,1.75,.2],center:[1.825,0,.2/2]}),ee(fs,{color:"#222",children:Pt(lE,{children:[Pt(BI,{children:[ee(Zi,{z:.2,children:ee(ut,{size:[3.8-.05/2,2.5-.05/2,.01]})}),ee(Zi,{z:.01,children:ee(ut,{size:[3.8-.05,2.5-.05,.01]})})]}),Pt(BI,{children:[ee(Zi,{z:.2,children:ee(ut,{size:[3.8,2.5,.01]})}),ee(Zi,{z:1,children:ee(ut,{size:[3.8-.4,2.5-.4,.01]})})]})]})}),ee(ut,{color:"#777",size:[.2*2.7,2.5-.4,.02],center:[-1.825+.4,0,1]})]}),OEt=()=>Pt(Jo,{children:[ee(ut,{color:"#ccc",size:[.4,.25,.14],center:[-.4,0,.14/2]}),ee(ut,{color:"#ccc",size:[.4,.25,.14],center:[.4,0,.14/2]}),ee(fs,{color:"#222",children:Pt(lE,{children:[ee(Zi,{z:.14/2,children:ee(ut,{size:[.8,.6,.14]})}),Pt(BI,{children:[ee(Zi,{z:.14,children:ee(ut,{size:[.8,.6,.01]})}),ee(Zi,{z:.37,children:ee(ut,{size:[.8-.1,.6-.1,.01]})})]})]})})]}),WEt=()=>{const I=3.0999999999999996;return Pt(Jo,{children:[ee(qo,{rotation:Math.PI,position:{x:6.6/2+I/4,y:0,z:.25/2},width:3,thickness:.25,padContactLength:.5,bodyDistance:I,height:.75}),ee(qo,{position:{x:-6.6/2-I/4,y:0,z:.25/2},width:.7,thickness:.25,padContactLength:.5,bodyDistance:I,height:.75}),ee(qo,{position:{x:-6.6/2-I/4,y:-2.3,z:.25/2},width:.7,thickness:.25,padContactLength:.5,bodyDistance:I,height:.75}),ee(qo,{position:{x:-6.6/2-I/4,y:2.3,z:.25/2},width:.7,thickness:.25,padContactLength:.5,bodyDistance:I,height:.75}),ee(zB,{center:{x:0,y:0,z:0},width:3.5,length:6.5,height:1.7,includeNotch:!1,taperRatio:.06,straightHeightRatio:.45})]})},ZEt=()=>Pt(Jo,{children:[Array.from({length:16}).map((C,l)=>ee(qo,{position:{x:-10.5/2,y:l*.5-3.75,z:.25/2},width:.2,thickness:.25,padContactLength:.45,bodyDistance:.95,height:.65})),Array.from({length:16}).map((C,l)=>ee(qo,{rotation:Math.PI,position:{x:10.5/2,y:l*.5-3.75,z:.25/2},width:.2,thickness:.25,padContactLength:.45,bodyDistance:.95,height:.65})),Array.from({length:16}).map((C,l)=>ee(qo,{rotation:Math.PI/2,position:{x:l*.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((C,l)=>ee(qo,{rotation:-Math.PI/2,position:{x:l*.5-3.75,y:10.5/2,z:.25/2},width:.2,thickness:.25,padContactLength:.45,bodyDistance:.95,height:.65})),ee(zB,{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})]}),VEt=ZEt,jEt=()=>{const g=.7999999999999998;return Pt(Jo,{children:[ee(qo,{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}),ee(qo,{position:{x:-2.05/2-g/4,y:-.65,z:.18/2},width:.3,thickness:.18,padContactLength:.2,bodyDistance:g,height:.65}),ee(qo,{position:{x:-2.05/2-g/4,y:.65,z:.18/2},width:.3,thickness:.18,padContactLength:.2,bodyDistance:g,height:.65}),ee(zB,{center:{x:0,y:0,z:0},width:1.25,length:2,height:.9,includeNotch:!1,taperRatio:.06,straightHeightRatio:.7,heightAboveSurface:.05})]})},zEt=({pinCount:t,pitch:A,leadWidth:e,padContactLength:i,bodyWidth:o})=>{const n=t/4;if(n!==Math.floor(n))throw new Error(`LQFP pinCount must be divisible by 4, got ${t}`);A||(A=.5),i||(i=.6),e||(e=.22),o||(o=A*(n+4));const s=o,r=(n-1)*A/2,a=s+3.3*i,g=a,I=.8,c=.2,B=(g-o)/2+.4;return Pt(Jo,{children:[Array.from({length:n}).map((C,l)=>ee(qo,{position:{x:-g/2-.36,y:l*A-r,z:c/2},width:e,thickness:c,padContactLength:i,bodyDistance:B,height:I})),Array.from({length:n}).map((C,l)=>ee(qo,{rotation:Math.PI,position:{x:g/2+.36,y:l*A-r,z:c/2},width:e,thickness:c,padContactLength:i,bodyDistance:B,height:I})),Array.from({length:n}).map((C,l)=>ee(qo,{rotation:Math.PI/2,position:{x:l*A-r,y:-a/2-.36,z:c/2},width:e,thickness:c,padContactLength:i,bodyDistance:B,height:I})),Array.from({length:n}).map((C,l)=>ee(qo,{rotation:-Math.PI/2,position:{x:l*A-r,y:a/2+.36,z:c/2},width:e,thickness:c,padContactLength:i,bodyDistance:B,height:I})),ee(zB,{center:{x:0,y:0,z:0},width:o,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})]})},XEt=()=>{const i=.20900000000000002,o=.1,n=.3,s=.1,r=.2;return Pt(Jo,{children:[ee(fs,{color:"#222",children:Pt(lE,{children:[ee(ut,{size:[.85,1.2,i],center:[0,0,i/2]}),Pt(BI,{children:[ee(Zi,{z:i,children:ee(ut,{size:[.85,1.2,.01]})}),ee(Zi,{z:.38,children:ee(ut,{size:[.85-o,1.2-o,.01]})})]})]})}),ee(ut,{color:"#ccc",size:[n,.25,s],center:[.55,0,s/2]}),ee(ut,{color:"#ccc",size:[n,r,s],center:[-.55,.4,s/2]}),ee(ut,{color:"#ccc",size:[n,r,s],center:[-.55,-.4,s/2]})]})},$Et=({num_pins:t,bodyWidth:A=5.3,bodyLength:e=5.3,bodyThickness:i=1,thermalPadSize:o,padWidth:n=e/5.3*.6,padLength:s=e/5.3*1,pitch:r=.5,thermalPadThickness:a=.2})=>{const g=[],I=Math.floor(t/2),c=r*(I-1);for(let B=0;B<t;B++){const C=B<I?"left":"right",l=B%I,Q=c/2-l*r,E=s,h=n,u=C==="left"?-A/2+E/2:A/2-E/2,d=B+1;g.push({pinNumber:d,x:u,y:Q,padSizeX:E,padSizeY:h})}return Pt(Jo,{children:[ee(zB,{center:{x:0,y:0,z:0},width:A,length:e,height:i,heightAboveSurface:0,color:"grey",chamferSize:.2,taperRatio:0,notchPosition:{x:-(A/2-s),y:e/2-s,z:i}}),g.map((B,C)=>ee(ut,{center:[B.x,B.y,a/2],size:[B.padSizeX,B.padSizeY,a]})),o?.length!==void 0&&o?.width!==void 0&&ee(ut,{center:[0,0,a/2],size:[o.width,o.length,a]})]})},Aht=({bodyLength:t=10.2,bodyWidth:A=4.65,bodyHeight:e=13.46,leadSpacing:i=5,leadDiameter:o=.8,leadLength:n=12.7,color:s="#ddd",leadColor:r="#b87333"})=>{const a=t/2,g=A/2,I=a-g,c=i/2,B=.85;return Pt(Jo,{children:[Pt(fs,{color:s,children:[Pt(BI,{children:[ee(jp,{height:e,roundRadius:.5,radius:g,center:[-I,0,e]}),ee(jp,{height:e,roundRadius:.5,radius:g,center:[I,0,e]})]}),Pt(BI,{children:[ee(jp,{height:B,roundRadius:.1,radius:g+.85,center:[-I,0,e/2+B/2]}),ee(jp,{height:B,roundRadius:.1,radius:g+.85,center:[I,0,e/2+B/2]})]})]}),Pt(fs,{color:r,children:[ee(Vp,{height:n+e/2,radius:o/2,center:[-c+.06,0,-(n/2)+e/2]}),ee(Vp,{height:n+e/2,radius:o/2,center:[c-.06,0,-(n/2)+e/2]})]})]})},eht=({bodyLength:t=1.4,bodyDiameter:A=1.1,color:e="#3a3a3aff",contactColor:i="#c6c6c6",cathodeIdentification:o="#111"})=>Pt(Jo,{children:[ee(fs,{color:e,children:Pt(pQ,{rotation:[0,"90deg",0],children:[ee(AL,{size:[A,A,t-.2],roundRadius:.2,center:[-A/2,0,.05]}),ee(Vp,{height:.2/2,radius:A/2-.2,center:[-A/2,0,-t/2+.2/2]})]})}),ee(fs,{color:o,children:ee(pQ,{rotation:[0,"90deg",0],children:ee(AL,{size:[A*1.01,A*1.01,t/3],roundRadius:.2,center:[-A/2,0,-t/4+.1]})})}),ee(fs,{color:i,children:ee(pQ,{rotation:[0,"90deg",0],children:ee(jp,{height:.2,radius:A/2,roundRadius:.2/3,center:[-A/2,0,-t/2]})})}),ee(fs,{color:i,children:ee(pQ,{rotation:[0,"90deg",0],children:ee(jp,{height:.2,radius:A/2,roundRadius:.2/3,center:[-A/2,0,t/2]})})})]}),tht=({bodyLength:t=3.5,bodyDiameter:A=1.5,color:e="#3a3a3aff",contactColor:i="#c6c6c6"})=>Pt(Jo,{children:[ee(fs,{color:e,children:ee(pQ,{rotation:[0,"90deg",0],children:ee(jp,{height:t,radius:A/2,roundRadius:.3,center:[-A/2,0,0]})})}),ee(fs,{color:i,children:ee(pQ,{rotation:[0,"90deg",0],children:ee(jp,{height:.5,radius:A/2,roundRadius:.2,center:[-A/2,0,-t/2]})})}),ee(fs,{color:i,children:ee(pQ,{rotation:[0,"90deg",0],children:ee(jp,{height:.5,radius:A/2,roundRadius:.2,center:[-A/2,0,t/2]})})})]}),iht=({bodyLength:t=3.9,bodyDiameter:A=2.5,color:e="#3a3a3aff",contactColor:i="#c6c6c6"})=>Pt(Jo,{children:[ee(fs,{color:e,children:ee(pQ,{rotation:[0,"90deg",0],children:ee(jp,{height:t,radius:A/2,roundRadius:.3,center:[-A/2,0,0]})})}),ee(fs,{color:i,children:ee(pQ,{rotation:[0,"90deg",0],children:ee(jp,{height:.55,radius:A/2,roundRadius:.2,center:[-A/2,0,-t/2]})})}),ee(fs,{color:i,children:ee(pQ,{rotation:[0,"90deg",0],children:ee(jp,{height:.55,radius:A/2,roundRadius:.2,center:[-A/2,0,t/2]})})})]}),oht=({pinCount:t,padContactLength:A=.6,leadWidth:e=.41,pitch:i=1.27})=>{if(t%2!==0)throw new Error("MS012 pinCount must be even");const o=t/2,n=4.9,s=3.9,r=(o-1)*i/2,a=.2;return Pt(Jo,{children:[Array.from({length:o}).map((g,I)=>ee(qo,{position:{x:-s/2-A-.3,y:I*i-r,z:a/2},width:e,thickness:a,padContactLength:A,bodyDistance:A+.4,height:.85})),Array.from({length:o}).map((g,I)=>ee(qo,{rotation:Math.PI,position:{x:s/2+A+.3,y:I*i-r,z:a/2},width:e,thickness:a,padContactLength:A,bodyDistance:A+.4,height:.85})),ee(zB,{center:{x:0,y:0,z:a/2},width:s,length:n,height:1.55,notchPosition:{x:-.95,y:n/2-1,z:1.55},heightAboveSurface:.17,taperRatio:.09})]})},nht=({pinCount:t=16,padContactLength:A=.6,leadWidth:e=.41,pitch:i=1.27})=>{if(t!==16)throw new Error("MS013 only supports 16 pins");const o=t/2,n=7.5,s=10.3,r=(o-1)*i/2,a=.2;return Pt(Jo,{children:[Array.from({length:o}).map((g,I)=>ee(qo,{position:{x:-n/2-A-.3,y:I*i-r,z:a/2},width:e,thickness:a,padContactLength:A,bodyDistance:A+.4,height:.85})),Array.from({length:o}).map((g,I)=>ee(qo,{rotation:Math.PI,position:{x:n/2+A+.3,y:I*i-r,z:a/2},width:e,thickness:a,padContactLength:A,bodyDistance:A+.4,height:.85})),ee(zB,{center:{x:0,y:0,z:a/2},width:n,length:s,height:1.1,notchPosition:{x:-2.25,y:s/2-1.5,z:1.1},heightAboveSurface:.17,taperRatio:.05})]})},sht=()=>{const Q=7.050000000000001,E=24.95+6.5/2;return ee(Zi,{center:[0,0,1],children:Pt(Jo,{children:[Pt(pQ,{rotation:[0,55,-55],children:[Pt(nF,{children:[ee(ut,{color:"#ccc",size:[6.5+.1,9.9,1.3],center:[E,0,1.3-2]}),ee(Vp,{color:"black",center:[E,0,1.3-2],radius:3/2,height:1.3*1.2})]}),ee(fs,{color:"#222",children:ee(zB,{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})})]}),ee(pQ,{rotation:[0,55,55],children:Array.from({length:3}).map((h,u)=>{const d=Q,f=(u-1)*2.7,m=-.5-.6;return Pt(fs,{color:"gold",children:[Pt(BI,{children:[ee(Zi,{center:[15.05-4.5/2+.1,f,m],children:ee(ut,{size:[4.5,.81+1,.5]})}),ee(Zi,{center:[15.05-4.5/2-1+.1,f,m],children:ee(ut,{size:[4.5,.81,.5]})})]}),ee(Zi,{center:[d,f,m],children:ee(ut,{size:[16+.1,.81,.5]})})]},`prong-${u}`)})})]})})},rht=()=>{const g=1.1999999999999997;return Pt(Jo,{children:[ee(qo,{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}),ee(qo,{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}),ee(qo,{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}),ee(qo,{position:{x:-2.8/2-g/4,y:0,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:g,height:.95}),ee(qo,{position:{x:-2.8/2-g/4,y:-.95,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:g,height:.95}),ee(qo,{position:{x:-2.8/2-g/4,y:.95,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:g,height:.95}),ee(zB,{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})]})},aht=()=>Pt(Jo,{children:[ee(zB,{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 I=-.35+g*.35;return ee(ut,{center:[-.8/2+.19/2-.1,I,.12/2],size:[.19,.15,.12]})}),[0,1,2].map(g=>{const I=-.35+g*.35;return ee(ut,{center:[.8/2-.19/2+.1,I,.12/2],size:[.19,.15,.12]})})]}),ght=()=>{const s="#222",a=[.43,.4,1.32],g=[.43,.4,.25],I=[0,0,-.66],c=[0,0,-1.32],B=[0,1.28,-2.72],C=[0,1.28,-8.9],l=-7.5;return Pt(Zi,{center:[0,1,10.5],children:[ee(fs,{color:s,children:Pt(nF,{children:[ee(Zi,{center:[0,0,2.25],children:ee(Vp,{radius:2.4,height:4.5})}),ee(Zi,{center:[0,-1.8499999999999999,2.25],children:ee(ut,{size:[2.4*2,1.1,4.5+.2]})})]})}),ee(Zi,{center:I,children:ee(ut,{size:a})}),Pt(BI,{children:[ee(Zi,{center:c,children:ee(ut,{size:g})}),ee(Zi,{center:B,children:ee(ut,{size:g})})]}),ee(Zi,{center:C,children:ee(ut,{size:[.43,.4,12.2]})}),ee(Zi,{center:[1.3,0,l],children:ee(ut,{size:[.43,.4,15]})}),ee(Zi,{center:[-1.3,0,l],children:ee(ut,{size:[.43,.4,15]})})]})},Iht=()=>Pt(Jo,{children:[ee(qo,{rotation:Math.PI,position:{x:2/2+.75/4,y:-.65,z:.15/2},width:.25,thickness:.15,padContactLength:.3,bodyDistance:.75,height:.85}),ee(qo,{rotation:Math.PI,position:{x:2/2+.75/4,y:0,z:.15/2},width:.25,thickness:.15,padContactLength:.3,bodyDistance:.75,height:.85}),ee(qo,{rotation:Math.PI,position:{x:2/2+.75/4,y:.65,z:.15/2},width:.25,thickness:.15,padContactLength:.3,bodyDistance:.75,height:.85}),ee(qo,{position:{x:-2/2-.75/4,y:0,z:.15/2},width:.25,thickness:.15,padContactLength:.3,bodyDistance:.75,height:.85}),ee(qo,{position:{x:-2/2-.75/4,y:-.65,z:.15/2},width:.25,thickness:.15,padContactLength:.3,bodyDistance:.75,height:.85}),ee(qo,{position:{x:-2/2-.75/4,y:.65,z:.15/2},width:.25,thickness:.15,padContactLength:.3,bodyDistance:.75,height:.85}),ee(zB,{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})]}),cht=Iht,Bht=()=>Pt(Jo,{children:[ee(zB,{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 ee(ut,{center:[-1/2+.3/2,a,.05/2],size:[.3,.2,.05]})}),[0,1,2].map(r=>{const a=-.5+r*.5;return ee(ut,{center:[1/2-.3/2,a,.05/2],size:[.3,.2,.05]})})]}),Cht=()=>Pt(Jo,{children:[ee(qo,{position:{x:-2.5/2,y:0,z:.175/2},width:.3,thickness:.175,padContactLength:.3,bodyDistance:.45,height:.7}),ee(qo,{rotation:Math.PI,position:{x:2.5/2,y:0,z:.175/2},width:.3,thickness:.175,padContactLength:.3,bodyDistance:.45,height:.7}),ee(fs,{color:"#222",children:ee(zB,{center:{x:0,y:0,z:0},width:1.7,length:1.25,height:.95,includeNotch:!1,taperRatio:.06,straightHeightRatio:.7,heightAboveSurface:.05})}),ee(ut,{color:"#777",size:[1.7/3,1.25-.075,.02],center:[-.85*2/3+.035,0,.95+.05]})]}),lht=()=>Pt(Jo,{children:[ee(ut,{color:"#ccc",size:[.4,.325,.175],center:[-1.05,0,.175/2]}),ee(ut,{color:"#ccc",size:[.4,.325,.175],center:[1.05,0,.175/2]}),ee(fs,{color:"#222",children:Pt(lE,{children:[ee(Zi,{z:.175/2,children:ee(ut,{size:[1.7,1.25,.175]})}),Pt(BI,{children:[ee(Zi,{z:.175,children:ee(ut,{size:[1.7,1.25,.01]})}),ee(Zi,{z:.725,children:ee(ut,{size:[1.7-.2,1.25-.2,.01]})})]})]})}),ee(ut,{color:"#777",size:[1.7/3,1.25-.2,.02],center:[-1.05+1.7/4.4+.2,0,.725]})]}),Qht=()=>{const s=-1.0474999999999999,r=1.775/2+.4/2-.04;return Pt(Jo,{children:[ee(ut,{color:"#ccc",size:[.4,.325,.13],center:[s,0,.13/2]}),ee(ut,{color:"#ccc",size:[.4,.325,.13],center:[r,0,.13/2]}),ee(fs,{color:"#222",children:ee(zB,{width:1.775,length:1.25,height:.725,center:{x:0,y:0,z:0},heightAboveSurface:0,straightHeightRatio:.7,taperRatio:.06,includeNotch:!1})}),ee(ut,{color:"#777",size:[1.775/3,1.25-.05,.02],center:[s+1.775/4.4+.2,0,.725]})]})},Eht=({footprint:t})=>{const A=tEt.string(t).json();switch(A.fn){case"dip":return ee(rEt,{numPins:A.num_pins,pitch:A.p,bodyWidth:A.w});case"tssop":return ee(gEt,{pinCount:A.num_pins,leadLength:A.pl,leadWidth:A.pw,pitch:A.p,bodyWidth:A.w});case"msop":return ee(IEt,{pinCount:A.num_pins,padContactLength:A.pl,leadWidth:A.pw,pitch:A.p,bodyWidth:A.w});case"vssop":return ee(_Et,{pinCount:A.num_pins,leadLength:A.pl,leadWidth:A.pw,pitch:A.p,bodyWidth:A.w,bodyLength:A.h});case"qfp":return ee(lEt,{pinCount:A.num_pins,pitch:A.p,leadWidth:A.pw,padContactLength:A.pl,bodyWidth:A.w});case"tqfp":return ee(VEt,{});case"lqfp":return ee(zEt,{pinCount:A.num_pins});case"qfn":{const o=typeof A.thermalpad?.x=="number"&&typeof A.thermalpad?.y=="number";return ee(yEt,{num_pins:A.num_pins,bodyWidth:A.w,bodyLength:A.h,pitch:A.p,padLength:A.pl,padWidth:A.pw,thermalPadSize:o?{width:A.thermalpad.x,length:A.thermalpad.y}:void 0})}case"dfn":{const o=typeof A.thermalpad?.x=="number"&&typeof A.thermalpad?.y=="number";return ee($Et,{num_pins:A.num_pins,bodyWidth:A.w,bodyLength:A.h,pitch:A.p,padLength:A.pl,padWidth:A.pw,thermalPadSize:o?{width:A.thermalpad.x,length:A.thermalpad.y}:void 0})}case"pinrow":{const o=t.match(/_rows(\d+)/),n=o&&o[1]?parseInt(o[1],10):1;if(A.male)return ee(uEt,{numberOfPins:A.num_pins,pitch:A.p,invert:A.invert,faceup:A.faceup,rows:n});if(A.female)return ee(REt,{numberOfPins:A.num_pins,pitch:A.p,rows:n})}case"cap":switch(A.imperial){case"0402":return ee(pZA,{color:"#856c4d"});case"0603":return ee(fZA,{color:"#856c4d"});case"0805":return ee(yZA,{color:"#856c4d"});case"0201":return ee(wZA,{color:"#856c4d"});case"01005":return ee(mZA,{color:"#856c4d"});case"1206":return ee(DZA,{color:"#856c4d"});case"1210":return ee(SZA,{color:"#856c4d"});case"2010":return ee(bZA,{color:"#856c4d"});case"2512":return ee(xZA,{color:"#856c4d"})}case"sot235":return ee(mEt,{});case"sot457":return ee(rht,{});case"sot223":return ee(WEt,{});case"sot23w":return ee(DEt,{});case"sot323":return ee(jEt,{});case"sod323f":return ee(lht,{});case"sod323fl":return ee(Qht,{});case"sot363":return ee(cht,{});case"sot886":return ee(Bht,{});case"sot963":return ee(aht,{});case"pushbutton":return ee(MEt,{width:A.w,length:A.h,innerDiameter:A.id});case"soic":return ee(NEt,{pinCount:A.num_pins,leadLength:A.pl,leadWidth:A.pw,pitch:A.p,bodyWidth:A.w});case"sod523":return ee(vEt,{});case"sod882":return ee(UEt,{});case"sma":return ee(LEt,{});case"smb":return ee(HEt,{});case"smc":return ee(YEt,{});case"smf":return ee(JEt,{});case"sod123f":return ee(TEt,{});case"sod123fl":return ee(KEt,{});case"sod123w":return ee(qEt,{});case"sod128":return ee(PEt,{});case"sod323":return ee(Cht,{});case"sod923":return ee(OEt,{});case"hc49":return ee(Aht,{});case"micromelf":return ee(eht,{});case"minimelf":return ee(tht,{});case"melf":return ee(iht,{});case"ms012":return ee(oht,{pinCount:A.num_pins,padContactLength:A.pl,leadWidth:A.pw,pitch:A.p});case"ms013":return ee(nht,{pinCount:A.num_pins,padContactLength:A.pl,leadWidth:A.pw,pitch:A.p});case"sot723":return ee(XEt,{});case"to220":return ee(sht,{});case"to92":return ee(ght,{})}const e=t.match(/_color\(([^)]+)\)/),i=e?e[1]:void 0;switch(A.imperial){case"0402":return ee(pZA,{color:i});case"0603":return ee(fZA,{color:i});case"0805":return ee(yZA,{color:i});case"0201":return ee(wZA,{color:i});case"01005":return ee(mZA,{color:i});case"1206":return ee(DZA,{color:i});case"1210":return ee(SZA,{color:i});case"2010":return ee(bZA,{color:i});case"2512":return ee(xZA,{color:i})}return null},hht=t=>t&&typeof t=="object"&&"type"in t,r_=t=>{if(typeof t=="number")return t;if(typeof t=="string"){const A=/^(-?\d+(?:\.\d+)?)\s*deg$/i.exec(t);if(A)return parseFloat(A[1])*Math.PI/180;const e=Number(t);if(!Number.isNaN(e))return e}return 0},uht=t=>Array.isArray(t)?[Number(t[0])||0,Number(t[1])||0,Number(t[2])||0]:typeof t=="object"&&t?[Number(t.x)||0,Number(t.y)||0,Number(t.z)||0]:[0,0,0];function Mm(t,A,e){const{jscad:{primitives:i,booleans:o,hulls:n,geometries:s,extrusions:r,transforms:a}}=e;if(t==null||t===!1)return[];if(Array.isArray(t))return t.flatMap(B=>Mm(B,A,e));if(!hht(t))return[];const{type:g,props:I,children:c}=t;if(g===EZA)return(c??[]).flatMap(B=>Mm(B,A,e));if(g===fs){const B=I?.color;return(c??[]).flatMap(C=>Mm(C,B??A,e))}if(g===Zi){const B=uht(I?.offset??I?.center??{x:I?.x,y:I?.y,z:I?.z});return(c??[]).flatMap(l=>Mm(l,A,e)).map(({geom:l,color:Q})=>({geom:a.translate(B,l),color:Q??A}))}if(g===pQ){const B=Array.isArray(I?.rotation)?[r_(I.rotation[0]),r_(I.rotation[1]),r_(I.rotation[2])]:[r_(I?.x??0),r_(I?.y??0),r_(I?.z??0)];return(c??[]).flatMap(l=>Mm(l,A,e)).map(({geom:l,color:Q})=>({geom:a.rotateZ(B[2],a.rotateY(B[1],a.rotateX(B[0],l))),color:Q}))}if(g===lE||g===nF||g===BI){const B=(c??[]).flatMap(l=>Mm(l,A,e)).map(l=>l.geom);if(B.length===0)return[];let C;return g===lE?C=o.union(B):g===nF?C=o.subtract(B[0],B.slice(1)):C=n.hull(B),[{geom:C,color:A}]}if(g===eL){const B=I?.points??[];return[{geom:s.geom2.fromPoints(B),color:A??I?.color}]}if(g===tL){const B=(c??[]).flatMap(E=>Mm(E,A,e)).map(E=>E.geom);if(B.length===0)return[];const C=B.length>1?o.union(B):B[0],l=I?.height??I?.h??1;let Q=r.extrudeLinear({height:l},C);if(Q.polygons)for(const E of Q.polygons)!E.plane||!E.vertices||E.vertices.length<3||E.vertices.reverse();return[{geom:Q,color:A??I?.color}]}if(g===ut||g===hZA||g===Vp||g===uZA||g===AL||g===jp){let B;if(g===ut){const C=I?.size??[1,1,1],l=I?.offset,Q=I?.center??(l?[l[0],l[1],l[2]]:[0,0,0]);B=i.cuboid({size:C,center:Q})}else if(g===hZA){const C=I?.size??1,l=I?.offset,Q=I?.center??(l?[l[0],l[1],l[2]]:[0,0,0]);B=i.cube({size:C,center:Q})}else if(g===Vp){const C=I?.height??1,l=I?.radius??1,Q=I?.center??[0,0,0];B=i.cylinder({height:C,radius:l,center:Q})}else if(g===uZA){const C=I?.radius??1,l=I?.center??[0,0,0];B=i.sphere({radius:C,center:l})}else if(g===jp){const C=I?.height??1,l=I?.radius??1,Q=I?.roundRadius??.1,E=I?.center??[0,0,0];B=i.roundedCylinder({height:C,radius:l,roundRadius:Q,center:E})}else{const C=I?.size??[1,1,1],l=I?.roundRadius??.1,Q=I?.center??[0,0,0];B=i.roundedCuboid({size:C,roundRadius:l,center:Q})}return[{geom:B,color:A??I?.color}]}if(typeof g=="function"){const B=g(I??{});return Mm(B,A,e)}return(c??[]).flatMap(B=>Mm(B,A,e))}function dht(t,A){return{geometries:Mm(t,void 0,{jscad:A})}}function kZA(t){if(t.polygons){const A=[],e=[],i=[];let o=0;for(const s of t.polygons){for(const a of s.vertices)a.index=o,A.push(a[0],a[1],a[2]),t.color&&t.color.length>=3?i.push(t.color[0],t.color[1],t.color[2]):i.push(1,1,1),o++;const r=s.vertices[0].index;for(let a=2;a<s.vertices.length;a++){const g=s.vertices[a-1].index,I=s.vertices[a].index;e.push(r,g,I)}}const n=new dg;if(n.setAttribute("position",new gI(new Float32Array(A),3)),n.setIndex(e),i.length>0&&n.setAttribute("color",new gI(new Float32Array(i),3)),t.transforms){const s=new es;s.fromArray(t.transforms),n.applyMatrix4(s)}return n.computeVertexNormals(),n}if(t.sides){const A=[],e=[];for(const o of t.sides)A.push(o[0][0],o[0][1],0),t.color&&t.color.length>=3?e.push(t.color[0],t.color[1],t.color[2]):e.push(1,1,1);const i=new dg;if(i.setAttribute("position",new gI(new Float32Array(A),3)),e.length>0&&i.setAttribute("color",new gI(new Float32Array(e),3)),t.transforms){const o=new es;o.fromArray(t.transforms),i.applyMatrix4(o)}return i}return console.error("Invalid CSG object: neither polygons nor sides found"),new dg}function pht(t,A){const e=oCA(Eht,{footprint:t});return dht(e,A)}var fht=_r(s5()),GZA=$.createContext(null),yht=()=>{const t=$.useContext(GZA);if(!t)throw new Error("useHover must be used within a HoverProvider");return t},wht=({children:t})=>{const{camera:A,renderer:e}=ku(),[i,o]=$.useState([]),n=$.useMemo(()=>new vme,[]),s=$.useMemo(()=>new Io,[]),r=$.useRef(i);r.current=i;const a=$.useRef(null),g=$.useCallback(l=>{o(Q=>[...Q,l])},[]),I=$.useCallback(l=>{if(a.current){let Q=!1,E=a.current.object;for(;E;){if(E===l){Q=!0;break}E=E.parent}Q&&(a.current.onUnhover(),a.current=null)}o(Q=>Q.filter(E=>E.object!==l))},[]),c=$.useCallback(l=>{let Q=l;for(;Q;){const E=r.current.find(h=>h.object===Q);if(E)return E;Q=Q.parent}},[]),B=$.useCallback(l=>{if(!e.domElement)return;const Q=e.domElement.getBoundingClientRect();s.x=(l.clientX-Q.left)/Q.width*2-1,s.y=-((l.clientY-Q.top)/Q.height)*2+1,n.setFromCamera(s,A);const E=r.current.map(u=>u.object);if(E.length===0){a.current&&(a.current.onUnhover(),a.current=null);return}const h=n.intersectObjects(E,!0);if(h.length>0){const u=h[0],d=c(u.object);if(d){const f={mousePosition:[u.point.x,u.point.y,u.point.z]};a.current!==d?(a.current?.onUnhover(),d.onHover(f),a.current=d):d.onHover(f)}else a.current&&(a.current.onUnhover(),a.current=null)}else a.current&&(a.current.onUnhover(),a.current=null)},[A,e,n,s,c]);$.useEffect(()=>{const l=e.domElement;return l.addEventListener("mousemove",B),()=>{l.removeEventListener("mousemove",B)}},[e,B]);const C=$.useMemo(()=>({addHoverable:g,removeHoverable:I}),[g,I]);return V.jsx(GZA.Provider,{value:C,children:t})},mht=({children:t,object:A,onHover:e,onUnhover:i,isHovered:o})=>{const{addHoverable:n,removeHoverable:s}=yht();return $.useEffect(()=>A?(n({object:A,onHover:e,onUnhover:i}),()=>{s(A)}):void 0,[A,e,i,n,s]),V.jsx(V.Fragment,{children:t})},cL=mht,Dht=({positionOffset:t,footprint:A,rotationOffset:e,onHover:i,onUnhover:o,isHovered:n,scale:s,isTranslucent:r=!1})=>{const{rootObject:a}=ku(),g=$.useMemo(()=>{if(!A)return null;const{geometries:I}=pht(A,fht),c=new Jp;for(const B of I.flat(1/0)){const C=B.geom;if(!C||!C.polygons&&!C.sides)continue;const l=new Li(B.color);l.convertLinearToSRGB();const Q={...C,color:[l.r,l.g,l.b]},E=kZA(Q),h=new Ih({vertexColors:!0,side:JC,transparent:r,opacity:r?.5:1,depthWrite:!r}),u=new Wo(E,h);c.add(u)}return c},[A,r]);return $.useEffect(()=>{if(!(!g||!a))return a.add(g),()=>{a.remove(g)}},[a,g]),$.useEffect(()=>{g&&(t&&g.position.fromArray(t),e&&g.rotation.fromArray(e),s!==void 0&&g.scale.setScalar(s))},[g,t?.[0],t?.[1],t?.[2],e?.[0],e?.[1],e?.[2],s]),$.useEffect(()=>{g&&g.traverse(I=>{I instanceof Wo&&I.material instanceof Ih&&(n?(I.material.emissive.setHex(255),I.material.emissiveIntensity=.2):I.material.emissiveIntensity=0)})},[n,g]),g?V.jsx(cL,{isHovered:n,onHover:i,onUnhover:o,object:g}):null},FZA=new WeakMap,Sht=()=>{const t=new Uc;return t.name="fallback-environment-map",t.mapping=bT,t},bht=t=>{if(!t)return null;const A=t,e=FZA.get(A);if(e)return e;let i;if(t instanceof nK){const o=new Fz(t);i=o.fromScene(JSe(),.04).texture,o.dispose()}else i=Sht();return FZA.set(A,i),i},RZA=1.25;function MZA({gltfUrl:t,position:A,rotation:e,onHover:i,onUnhover:o,isHovered:n,scale:s,isTranslucent:r=!1}){const{renderer:a,rootObject:g}=ku(),[I,c]=$.useState(null),[B,C]=$.useState(null);if($.useEffect(()=>{if(!t)return;const l=new KSe;let Q=!0;return l.load(t,E=>{if(!Q)return;const h=E.scene;h.traverse(u=>{if(u instanceof Wo&&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)}}),c(h)},void 0,E=>{if(!Q)return;console.error(`An error happened loading ${t}`,E);const h=E instanceof Error?E:new Error(`Failed to load glTF model from ${t}`);C(h)}),()=>{Q=!1}},[t,r]),$.useEffect(()=>{I&&(A&&I.position.fromArray(A),e&&I.rotation.fromArray(e),s!==void 0&&I.scale.setScalar(s))},[I,A?.[0],A?.[1],A?.[2],e?.[0],e?.[1],e?.[2],s]),$.useEffect(()=>{if(!(!g||!I))return g.add(I),()=>{g.remove(I)}},[g,I]),$.useEffect(()=>{if(!I||!a)return;const l=bht(a);if(!l)return;const Q=[],E=h=>{h instanceof Ih&&(Q.push({material:h,envMap:h.envMap??null,envMapIntensity:h.envMapIntensity??1}),h.envMap=l,(typeof h.envMapIntensity!="number"||h.envMapIntensity<RZA)&&(h.envMapIntensity=RZA),h.needsUpdate=!0)};return I.traverse(h=>{if(!(h instanceof Wo))return;const u=h.material;Array.isArray(u)?u.forEach(E):u&&E(u)}),()=>{Q.forEach(({material:h,envMap:u,envMapIntensity:d})=>{h.envMap=u,h.envMapIntensity=d,h.needsUpdate=!0})}},[I,a]),$.useEffect(()=>{I&&I.traverse(l=>{l instanceof Wo&&l.material instanceof Ih&&(n?(l.material.emissive.setHex(255),l.material.emissiveIntensity=.2):l.material.emissiveIntensity=0)})},[n,I]),B)throw B;return I?V.jsx(cL,{isHovered:n,onHover:i,onUnhover:o,object:I}):null}var xht=_r(sWA()),kht=_r(s5()),Ght=({jscadPlan:t,positionOffset:A,rotationOffset:e,onHover:i,onUnhover:o,isHovered:n,scale:s,isTranslucent:r=!1})=>{const{rootObject:a}=ku(),{threeGeom:g,material:I}=$.useMemo(()=>{const B=(0,xht.executeJscadOperations)(kht.default,t);if(!B||!B.polygons&&!B.sides)return{threeGeom:null,material:null};const C=kZA(B),l=new Ih({vertexColors:!0,side:JC,transparent:r,opacity:r?.5:1,depthWrite:!r});return{threeGeom:C,material:l}},[t,r]),c=$.useMemo(()=>g?new Wo(g,I):null,[g,I]);return $.useEffect(()=>{if(!(!c||!a))return a.add(c),()=>{a.remove(c)}},[a,c]),$.useEffect(()=>{c&&(A&&c.position.fromArray(A),e&&c.rotation.fromArray(e),s!==void 0&&c.scale.setScalar(s))},[c,A?.[0],A?.[1],A?.[2],e?.[0],e?.[1],e?.[2],s]),$.useMemo(()=>{if(I)if(n){const B=new Li(I.color.getHex());I.emissive.copy(B),I.emissive.setRGB(0,0,1),I.emissiveIntensity=.2}else I.emissiveIntensity=0},[n,I]),g?V.jsx(cL,{isHovered:n,onHover:i,onUnhover:o,object:c}):null};function Fht(t){return t.replace(/(DEF|USE)\s+([^\s]+)/g,(A,e,i)=>`${e} ${i.replace(/-/g,"_")}`)}async function Rht(t){const A=await fetch(t);if(!A.ok)throw new Error(`Failed to fetch "${t}": ${A.status} ${A.statusText}`);const e=await A.text();return new xbe().parse(Fht(e),t)}typeof window<"u"&&!window.TSCIRCUIT_OBJ_LOADER_CACHE&&(window.TSCIRCUIT_OBJ_LOADER_CACHE=new Map);function Mht(t){const[A,e]=$.useState(null);return $.useEffect(()=>{if(!t)return;const i=t.replace(/&cachebust_origin=$/,""),o=window.TSCIRCUIT_OBJ_LOADER_CACHE;let n=!1;async function s(){try{if(i.endsWith(".wrl"))return await Rht(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(),I=g.match(/newmtl[\s\S]*?endmtl/g),c=new Ube;if(I?.length){const B=I.join(`
|
|
5067
|
-
`).replace(/d 0\./g,"d 1."),C=g.replace(/newmtl[\s\S]*?endmtl/g,"").replace(/^mtllib.*/gm,""),l=new Dbe;l.setMaterialOptions({invertTrProperty:!0});const Q=l.parse(B.replace(/Kd\s+([\d.]+)\s+([\d.]+)\s+([\d.]+)/g,"Kd $2 $2 $2"),"embedded.mtl");return c.setMaterials(Q),c.parse(C)}return c.parse(g.replace(/^mtllib.*/gm,""))}catch(a){return a}}function r(){if(o.has(i)){const g=o.get(i);return g.result?Promise.resolve(g.result.clone()):g.promise.then(I=>I instanceof Error?I:I.clone())}const a=s().then(g=>(g instanceof Error||o.set(i,{...o.get(i),result:g}),g));return o.set(i,{promise:a,result:null}),a}return r().then(a=>{n||e(a)}).catch(a=>{console.error(a)}),()=>{n=!0}},[t]),A}function Nht({url:t,position:A,rotation:e,onHover:i,onUnhover:o,isHovered:n,scale:s,isTranslucent:r=!1}){const a=Mht(t),{rootObject:g}=ku(),I=$.useMemo(()=>a&&!(a instanceof Error)?(a.traverse(c=>{if(c instanceof Wo&&c.material){const B=C=>{C.transparent=r,C.opacity=r?.5:1,C.depthWrite=!r,C.needsUpdate=!0};Array.isArray(c.material)?c.material.forEach(B):B(c.material)}}),a):new Wo(new Bw(.5,.5,.5),new Ih({transparent:!0,color:"red",opacity:.25})),[a,r]);if($.useEffect(()=>{if(!(!g||!I))return g.add(I),()=>{g.remove(I)}},[g,I]),$.useEffect(()=>{I&&(A&&(Array.isArray(A)?I.position.fromArray(A):I.position.copy(A)),e&&(Array.isArray(e)?I.rotation.fromArray(e):I.rotation.copy(e)),s!==void 0&&I.scale.setScalar(s))},[I,Array.isArray(A)?A[0]:A?.x,Array.isArray(A)?A[1]:A?.y,Array.isArray(A)?A[2]:A?.z,Array.isArray(e)?e[0]:e?.x,Array.isArray(e)?e[1]:e?.y,Array.isArray(e)?e[2]:e?.z,s]),a instanceof Error)throw a;return V.jsx(cL,{isHovered:n,onHover:i,onUnhover:o,object:I})}var mCA,_ht="https://cdn.jsdelivr.net/npm/occt-import-js@0.0.23/dist";function vht(t){if(typeof t=="function")return t;if(t&&typeof t=="object"&&"default"in t&&typeof t.default=="function")return t.default;throw new Error("Unable to resolve occt-import-js factory export")}async function Uht(){if(!mCA){const t=await import("https://cdn.jsdelivr.net/npm/occt-import-js@0.0.23/+esm");mCA=vht(t)({locateFile:e=>`${_ht}/${e}`})}return mCA}function Lht(t){const A=new Jp;for(const e of t){const i=e.attributes.position?.array??[],o=e.index?.array??[];if(!i.length||!o.length)continue;const n=new dg;n.setAttribute("position",new vn(i,3));const s=e.attributes.normal?.array??[];s.length?n.setAttribute("normal",new vn(s,3)):n.computeVertexNormals(),n.setIndex(o);const r=new Ih({color:e.color?new Li(e.color[0],e.color[1],e.color[2]):new Li(.82,.82,.82)}),a=new Wo(n,r);a.name=e.name,A.add(a)}return A}async function Hht(t){const A=await fetch(t);if(!A.ok)throw new Error(`Failed to fetch STEP file: ${A.statusText}`);const e=await A.arrayBuffer(),o=(await Uht()).ReadStepFile(new Uint8Array(e),null);if(!o.success||!o.meshes.length)throw new Error("occt-import-js failed to convert STEP file");const n=Lht(o.meshes),s=new A6,r=await new Promise((a,g)=>{s.parse(n,I=>{I instanceof ArrayBuffer?a(I):g(new Error("GLTFExporter did not return binary output"))},I=>{g(I)},{binary:!0})});return URL.createObjectURL(new Blob([r],{type:"model/gltf-binary"}))}var NZA="step-glb-cache:";function Yht(t){const A=new Uint8Array(t),e=32768;let i="";for(let o=0;o<A.length;o+=e){const n=A.subarray(o,o+e);i+=String.fromCharCode(...n)}return btoa(i)}function Jht(t){const A=atob(t),e=new Uint8Array(A.length);for(let i=0;i<A.length;i+=1)e[i]=A.charCodeAt(i);return e.buffer}function Tht(t){try{const A=localStorage.getItem(`${NZA}${t}`);return A?Jht(A):null}catch(A){return console.warn("Failed to read STEP GLB cache",A),null}}function Kht(t,A){try{const e=Yht(A);localStorage.setItem(`${NZA}${t}`,e)}catch(e){console.warn("Failed to write STEP GLB cache",e)}}var qht=({stepUrl:t,position:A,rotation:e,scale:i,onHover:o,onUnhover:n,isHovered:s,isTranslucent:r})=>{const[a,g]=$.useState(null);return $.useEffect(()=>{let I=!0,c=null;const B=Tht(t);return B?(c=URL.createObjectURL(new Blob([B],{type:"model/gltf-binary"})),g(c),()=>{I=!1,c&&URL.revokeObjectURL(c)}):(Hht(t).then(C=>{if(!I){URL.revokeObjectURL(C);return}c=C,g(C),fetch(C).then(l=>l.arrayBuffer()).then(l=>{Kht(t,l)}).catch(l=>{console.warn("Failed to cache STEP GLB",l)})}).catch(C=>{console.error("Failed to convert STEP file to GLB",C),I&&g(null)}),()=>{I=!1,c&&URL.revokeObjectURL(c)})},[t]),a?V.jsx(MZA,{gltfUrl:a,position:A,rotation:e,scale:i,onHover:o,onUnhover:n,isHovered:s,isTranslucent:r}):null},DCA=(...t)=>t,SCA=1.2;function _ZA(t){return $.useMemo(()=>{if(!t)return SCA;try{return mi(t).pcb_board.list()[0]?.thickness??SCA}catch{return SCA}},[t])}var vZA=({cad_component:t,circuitJson:A})=>{const e=_ZA(A),[i,o]=$.useState(!1),{visibility:n}=WN(),[s,r]=$.useState(null),a=$.useCallback(f=>{f?.mousePosition?(o(!0),r(f.mousePosition)):(o(!1),r(null))},[]),g=$.useCallback(()=>{o(!1),r(null)},[]),I=$.useMemo(()=>mi(A).source_component.getUsing({source_component_id:t.source_component_id})?.name,[A,t.source_component_id]),c=$.useMemo(()=>A.filter(m=>m.type==="pcb_plated_hole"&&m.pcb_component_id===t.pcb_component_id).length>0,[A,t.pcb_component_id]),B=t.model_obj_url??t.model_wrl_url??t.model_stl_url,C=t.model_glb_url??t.model_gltf_url,l=t.model_step_url,E=A.find(f=>f.type==="pcb_component"&&f.source_component_id===t.source_component_id)?.layer??"top",h=$.useMemo(()=>{const f=t.rotation?DCA(t.rotation.x*Math.PI/180,t.rotation.y*Math.PI/180,t.rotation.z*Math.PI/180):DCA(0,0,0);return E==="bottom"?DCA(f[0]+Math.PI,f[1],f[2]):f},[t.rotation,E]),u=$.useMemo(()=>{if(!t.position)return;const f=.55;let m;return E==="top"?m=e/2:E==="bottom"?m=-(e/2)-f:m=t.position.z,[t.position.x,t.position.y,m]},[t.position,E,e]);let d=null;if(B?d=V.jsx(Nht,{url:B,position:u,rotation:h,scale:t.model_unit_to_mm_scale_factor,onHover:a,onUnhover:g,isHovered:i,isTranslucent:t.show_as_translucent_model},t.cad_component_id):C?d=V.jsx(MZA,{gltfUrl:C,position:u,rotation:h,scale:t.model_unit_to_mm_scale_factor,onHover:a,onUnhover:g,isHovered:i,isTranslucent:t.show_as_translucent_model},t.cad_component_id):l&&!t.model_jscad&&!t.footprinter_string?d=V.jsx(qht,{stepUrl:l,position:u,rotation:h,scale:t.model_unit_to_mm_scale_factor,onHover:a,onUnhover:g,isHovered:i,isTranslucent:t.show_as_translucent_model}):t.model_jscad?d=V.jsx(Ght,{jscadPlan:t.model_jscad,positionOffset:u,rotationOffset:h,scale:t.model_unit_to_mm_scale_factor,onHover:a,onUnhover:g,isHovered:i,isTranslucent:t.show_as_translucent_model},t.cad_component_id):t.footprinter_string&&(d=V.jsx(Dht,{positionOffset:u,rotationOffset:h,footprint:t.footprinter_string,scale:t.model_unit_to_mm_scale_factor,onHover:a,onUnhover:g,isHovered:i,isTranslucent:t.show_as_translucent_model})),t.show_as_translucent_model){if(!n.translucentModels)return null}else if(c&&!n.throughHoleModels||!c&&!n.smtModels)return null;return V.jsxs(V.Fragment,{children:[d,i&&s?V.jsx(IWA,{position:s,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]})},UZA={version:"0.0.499"};function Pht(t){t.querySelectorAll("canvas").forEach(A=>A.remove())}var Oht=t=>{t.outputColorSpace=iw,t.toneMapping=qDA,t.toneMappingExposure=1},LZA="cadViewerCameraStateSession",HZA=(t,A)=>{try{const e={position:t.position.toArray(),quaternion:t.quaternion.toArray(),up:t.up.toArray(),fov:t.fov??50,target:A.target.toArray()};sessionStorage.setItem(LZA,JSON.stringify(e))}catch(e){console.warn("Failed to save camera:",e)}},bCA=(t,A)=>{try{const e=sessionStorage.getItem(LZA);if(!e)return!1;const i=JSON.parse(e);if(t.position.fromArray(i.position),t.quaternion.fromArray(i.quaternion),t.up.fromArray(i.up),"fov"in t){const o=t;o.fov=i.fov,o.updateProjectionMatrix?.()}return A.target.fromArray(i.target),A.update(),t.updateMatrixWorld(),!0}catch(e){return console.warn("Failed to restore camera:",e),!1}},YZA=$.createContext(void 0),Wht=({children:t,defaultTarget:A,initialCameraPosition:e})=>{const i=$.useRef(null),o=$.useRef(null),[n,s]=$.useState(null),[r,a]=$.useState("perspective"),[g,I]=$.useState(e??null),[c,B]=$.useState(new Hp(0,0,0)),C=$.useMemo(()=>{const[h,u,d]=e??[5,-5,5],f=Math.hypot(h-A.x,u-A.y,d-A.z);return f>0?f:5},[e,A]),l=$.useCallback(h=>{const u=[A.x,A.y,A.z],d=o.current,f=i.current;let m=C;switch(d&&f&&(m=d.position.distanceTo(f.target)),h){case"Top Center Angled":{const b=m/Math.sqrt(2);return{position:[A.x,A.y-b,A.z+b],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}},[C,A,o,i]),Q=$.useCallback(h=>{i.current=h},[]),E=$.useMemo(()=>({controlsRef:i,mainCameraRef:o,defaultTarget:A,baseDistance:C,controller:n,setController:s,getPresetConfig:l,handleControlsChange:Q,cameraType:r,setCameraType:a,cameraPosition:g,setCameraPosition:I,cameraRotation:c,setCameraRotation:B,saveCameraToSession:HZA,loadCameraFromSession:bCA}),[A,C,n,l,Q,r,g,c]);return V.jsx(YZA.Provider,{value:E,children:t})},Fx=()=>{const t=$.useContext(YZA);if(!t)throw new Error("useCameraController must be used within a CameraControllerProvider");return t},Zht=$.forwardRef(({children:t,scene:A,camera:e,style:i,onCreated:o},n)=>{const{cameraType:s}=Fx(),r=$.useRef(null),[a,g]=$.useState(null),I=$.useRef([]),c=$.useRef(void 0);c.current=o;const B=$.useRef(null),C=$.useCallback(h=>{I.current.push(h)},[]),l=$.useCallback(h=>{I.current=I.current.filter(u=>u!==h)},[]),Q=$.useMemo(()=>new lG,[]);A?.up&&Q.up.set(A.up.x,A.up.y,A.up.z);const E=$.useRef(new ug);return $.useImperativeHandle(n,()=>E.current),$.useEffect(()=>{if(!r.current)return;Pht(r.current);const h=new nK({antialias:!0,alpha:!0});Oht(h),h.setSize(r.current.clientWidth,r.current.clientHeight),h.setPixelRatio(window.devicePixelRatio),r.current.appendChild(h.domElement);const u=r.current.clientWidth/r.current.clientHeight,d=s==="perspective"?new rE(75,u,.1,1e3):new W1(-10*u,10*u,10,-10,-1e3,1e3);B.current?(d.position.copy(B.current.position),d.quaternion.copy(B.current.quaternion),d.up.copy(B.current.up)):(e?.up&&d.up.set(e.up[0],e.up[1],e.up[2]),e?.position&&d.position.set(e.position[0],e.position[1],e.position[2]),d.lookAt(0,0,0)),Q.add(E.current),window.__TSCIRCUIT_THREE_OBJECT=E.current,g({scene:Q,camera:d,renderer:h,rootObject:E.current,addFrameListener:C,removeFrameListener:l}),c.current?.({camera:d,renderer:h});let f;const m=new Sme,b=()=>{const x=m.getElapsedTime(),F=m.getDelta();I.current.forEach(k=>k(x,F)),h.render(Q,d),f=requestAnimationFrame(b)};b();const D=()=>{if(r.current){const x=r.current.clientWidth/r.current.clientHeight;d instanceof rE?d.aspect=x:d instanceof W1&&(d.left=-10*x,d.right=10*x,d.top=10,d.bottom=-10),d.updateProjectionMatrix(),h.setSize(r.current.clientWidth,r.current.clientHeight)}};return window.addEventListener("resize",D),()=>{B.current={position:d.position.clone(),quaternion:d.quaternion.clone(),up:d.up.clone()},window.removeEventListener("resize",D),cancelAnimationFrame(f),r.current&&h.domElement&&r.current.removeChild(h.domElement),h.dispose(),Q.remove(E.current),window.__TSCIRCUIT_THREE_OBJECT===E.current&&(window.__TSCIRCUIT_THREE_OBJECT=void 0)}},[Q,C,l,s]),V.jsx("div",{ref:r,style:{width:"100%",height:"100%",...i},children:a&&V.jsx(gWA.Provider,{value:a,children:V.jsx(wht,{children:t})})})}),Vht=({autoRotate:t,autoRotateSpeed:A,onStart:e,panSpeed:i,rotateSpeed:o,zoomSpeed:n,enableDamping:s,dampingFactor:r,target:a,onControlsChange:g})=>{const{camera:I,renderer:c}=ku(),B=$.useMemo(()=>!I||!c?null:new Hbe(I,c.domElement),[I,c]);return $.useEffect(()=>(g?.(B??null),()=>g?.(null)),[B,g]),$.useEffect(()=>{if(!B)return;const C=()=>{g?.(B)};return B.addEventListener("change",C),()=>{B.removeEventListener("change",C)}},[B,g]),$.useEffect(()=>{B&&(B.autoRotate=t||!1,B.autoRotateSpeed=A||1,i!==void 0&&(B.panSpeed=i),o!==void 0&&(B.rotateSpeed=o),n!==void 0&&(B.zoomSpeed=n),s!==void 0&&(B.enableDamping=s),r!==void 0&&(B.dampingFactor=r),B.zoomToCursor=!0,B.mouseButtons={LEFT:Gb.ROTATE,MIDDLE:Gb.PAN,RIGHT:null},a&&(B.target.set(a[0],a[1],a[2]),B.update()))},[B,t,A,i,o,n,s,r,a]),$.useEffect(()=>{if(!(!B||!e))return B.addEventListener("start",e),()=>{B.removeEventListener("start",e)}},[B,e]),$.useEffect(()=>{if(B)return()=>{B.dispose()}},[B]),zU(()=>{B?.update()},[B]),null},jht=`
|
|
5066
|
+
`,l.children.length>0&&I.push(l.children)}return a}};A.exports=s}}),wrt=oe({"node_modules/@jscad/modeling/src/operations/booleans/trees/Tree.js"(t,A){var e=drt(),i=yrt(),o=class{constructor(n){this.polygonTree=new i,this.rootnode=new e(null),n&&this.addPolygons(n)}invert(){this.polygonTree.invert(),this.rootnode.invert()}clipTo(n,s=!1){this.rootnode.clipTo(n,s)}allPolygons(){const n=[];return this.polygonTree.getPolygons(n),n}addPolygons(n){const s=new Array(n.length);for(let r=0;r<n.length;r++)s[r]=this.polygonTree.addChild(n[r]);this.rootnode.addPolygonTreeNodes(s)}clear(){this.polygonTree.clear()}toString(){return"Tree: "+this.polygonTree.toString("")}};A.exports=o}}),JBA=oe({"node_modules/@jscad/modeling/src/operations/booleans/trees/index.js"(t,A){A.exports={Tree:wrt()}}}),mrt=oe({"node_modules/@jscad/modeling/src/operations/booleans/intersectGeom3Sub.js"(t,A){var e=Kn(),i=YBA(),{Tree:o}=JBA(),n=(s,r)=>{if(!i(s,r))return e.create();const a=new o(e.toPolygons(s)),g=new o(e.toPolygons(r));a.invert(),g.clipTo(a),g.invert(),a.clipTo(g),g.clipTo(a),a.addPolygons(g.allPolygons()),a.invert();const I=a.allPolygons();return e.create(I)};A.exports=n}}),z8A=oe({"node_modules/@jscad/modeling/src/operations/booleans/intersectGeom3.js"(t,A){var e=Gn(),i=VU(),o=mrt(),n=(...s)=>{s=e(s);let r=s.shift();return s.forEach(a=>{r=o(r,a)}),r=i(r),r};A.exports=n}}),Drt=oe({"node_modules/@jscad/modeling/src/operations/booleans/intersectGeom2.js"(t,A){var e=Gn(),i=Kn(),o=bx(),n=LBA(),s=HBA(),r=z8A(),a=(...g)=>{g=e(g);const I=g.map(C=>s({z0:-1,z1:1},C)),c=r(I),B=o(c);return n(B,i.toPolygons(c))};A.exports=a}}),Srt=oe({"node_modules/@jscad/modeling/src/operations/booleans/intersect.js"(t,A){var e=Gn(),i=ZU(),o=Tn(),n=Kn(),s=Drt(),r=z8A(),a=(...g)=>{if(g=e(g),g.length===0)throw new Error("wrong number of arguments");if(!i(g))throw new Error("only intersect of the types are supported");const I=g[0];return o.isA(I)?s(g):n.isA(I)?r(g):I};A.exports=a}}),brt=oe({"node_modules/@jscad/modeling/src/operations/booleans/scissionGeom3.js"(t,A){var e=ho(),i=bx(),o=Kn(),n=g=>g.sort((I,c)=>I-c).filter((I,c,B)=>!c||I!==B[c-1]),s=(g,I,c)=>{const B=`${I}`,C=g.get(B);C===void 0?g.set(B,[c]):C.push(c)},r=(g,I)=>{const c=`${I}`;return g.get(c)},a=g=>{const I=i(g),c=o.toPolygons(g),B=c.length,C=new Map,l=e.create();c.forEach((d,f)=>{d.vertices.forEach(m=>{s(C,e.snap(l,m,I),f)})});const Q=c.map(d=>{let f=[];return d.vertices.forEach(m=>{f=f.concat(r(C,e.snap(l,m,I)))}),{e:1,d:n(f)}});C.clear();let E=0;const h=Q.length;for(let d=0;d<h;d++){const f=Q[d];if(f.e>0){const m=new Array(B);m[d]=!0;do E=0,m.forEach((b,D)=>{const x=Q[D];if(x.e>0){x.e=-1;for(let F=0;F<x.d.length;F++)m[x.d[F]]=!0;E++}});while(E>0);f.indexes=m}}const u=[];for(let d=0;d<h;d++)if(Q[d].indexes){const f=[];Q[d].indexes.forEach((m,b)=>f.push(c[b])),u.push(o.create(f))}return u};A.exports=a}}),xrt=oe({"node_modules/@jscad/modeling/src/operations/booleans/scission.js"(t,A){var e=Gn(),i=Kn(),o=brt(),n=(...s)=>{if(s=e(s),s.length===0)throw new Error("wrong number of arguments");const r=s.map(a=>i.isA(a)?o(a):a);return r.length===1?r[0]:r};A.exports=n}}),krt=oe({"node_modules/@jscad/modeling/src/operations/booleans/subtractGeom3Sub.js"(t,A){var e=Kn(),i=YBA(),{Tree:o}=JBA(),n=(s,r)=>{if(!i(s,r))return e.clone(s);const a=new o(e.toPolygons(s)),g=new o(e.toPolygons(r));a.invert(),a.clipTo(g),g.clipTo(a,!0),a.addPolygons(g.allPolygons()),a.invert();const I=a.allPolygons();return e.create(I)};A.exports=n}}),X8A=oe({"node_modules/@jscad/modeling/src/operations/booleans/subtractGeom3.js"(t,A){var e=Gn(),i=VU(),o=krt(),n=(...s)=>{s=e(s);let r=s.shift();return s.forEach(a=>{r=o(r,a)}),r=i(r),r};A.exports=n}}),Grt=oe({"node_modules/@jscad/modeling/src/operations/booleans/subtractGeom2.js"(t,A){var e=Gn(),i=Kn(),o=bx(),n=LBA(),s=HBA(),r=X8A(),a=(...g)=>{g=e(g);const I=g.map(C=>s({z0:-1,z1:1},C)),c=r(I),B=o(c);return n(B,i.toPolygons(c))};A.exports=a}}),Frt=oe({"node_modules/@jscad/modeling/src/operations/booleans/subtract.js"(t,A){var e=Gn(),i=ZU(),o=Tn(),n=Kn(),s=Grt(),r=X8A(),a=(...g)=>{if(g=e(g),g.length===0)throw new Error("wrong number of arguments");if(!i(g))throw new Error("only subtract of the types are supported");const I=g[0];return o.isA(I)?s(g):n.isA(I)?r(g):I};A.exports=a}}),$8A=oe({"node_modules/@jscad/modeling/src/operations/booleans/unionGeom3Sub.js"(t,A){var e=Kn(),i=YBA(),{Tree:o}=JBA(),n=(r,a)=>{if(!i(r,a))return s(r,a);const g=new o(e.toPolygons(r)),I=new o(e.toPolygons(a));g.clipTo(I,!1),I.clipTo(g),I.invert(),I.clipTo(g),I.invert();const c=g.allPolygons().concat(I.allPolygons());return e.create(c)},s=(r,a)=>{let g=e.toPolygons(r);return g=g.concat(e.toPolygons(a)),e.create(g)};A.exports=n}}),AWA=oe({"node_modules/@jscad/modeling/src/operations/booleans/unionGeom3.js"(t,A){var e=Gn(),i=VU(),o=$8A(),n=(...s)=>{s=e(s);let r;for(r=1;r<s.length;r+=2)s.push(o(s[r-1],s[r]));let a=s[r-1];return a=i(a),a};A.exports=n}}),eWA=oe({"node_modules/@jscad/modeling/src/operations/booleans/unionGeom2.js"(t,A){var e=Gn(),i=Kn(),o=bx(),n=LBA(),s=HBA(),r=AWA(),a=(...g)=>{g=e(g);const I=g.map(C=>s({z0:-1,z1:1},C)),c=r(I),B=o(c);return n(B,i.toPolygons(c))};A.exports=a}}),TBA=oe({"node_modules/@jscad/modeling/src/operations/booleans/union.js"(t,A){var e=Gn(),i=ZU(),o=Tn(),n=Kn(),s=eWA(),r=AWA(),a=(...g)=>{if(g=e(g),g.length===0)throw new Error("wrong number of arguments");if(!i(g))throw new Error("only unions of the same type are supported");const I=g[0];return o.isA(I)?s(g):n.isA(I)?r(g):I};A.exports=a}}),ON=oe({"node_modules/@jscad/modeling/src/operations/booleans/index.js"(t,A){A.exports={intersect:Srt(),scission:xrt(),subtract:Frt(),union:TBA()}}}),t5=oe({"node_modules/@jscad/modeling/src/operations/expansions/offsetFromPoints.js"(t,A){var{EPS:e,TAU:i}=lr(),o=G8A(),n=RBA(),s=Bs(),r=$O(),a=(g,I)=>{const c={delta:1,corners:"edge",closed:!1,segments:16};let{delta:B,corners:C,closed:l,segments:Q}=Object.assign({},c,g);if(Math.abs(B)<e)return I;let E=g.closed?r(I):1;E===0&&(E=1);const h=E>0&&B>=0||E<0&&B<0;B=Math.abs(B);let u=null,d=[];const f=[],m=s.create(),b=I.length;for(let D=0;D<b;D++){const x=(D+1)%b,F=I[D],k=I[x];h?s.subtract(m,F,k):s.subtract(m,k,F),s.normal(m,m),s.normalize(m,m),s.scale(m,m,B);const v=s.add(s.create(),F,m),_=s.add(s.create(),k,m),Y=[v,_];if(u!=null&&(l||!l&&x!==0)){const P=o(u[0],u[1],Y[0],Y[1]);P?(d.pop(),Y[0]=P):f.push({c:F,s0:u,s1:Y})}u=[v,_],!(x===0&&!l)&&(d.push(Y[0]),d.push(Y[1]))}if(l&&u!=null){const D=d[0],x=d[1],F=o(u[0],u[1],D,x);if(F)d[0]=F,d.pop();else{const k=I[0],v=[D,x];f.push({c:k,s0:u,s1:v})}}if(C==="edge"){const D=new Map;d.forEach((k,v)=>D.set(k,v));const x=n.create(),F=n.create();f.forEach(k=>{n.fromPoints(x,k.s0[0],k.s0[1]),n.fromPoints(F,k.s1[0],k.s1[1]);const v=n.intersectPointOfLines(x,F);if(Number.isFinite(v[0])&&Number.isFinite(v[1])){const _=k.s0[1],Y=D.get(_);d[Y]=v,d[(Y+1)%d.length]=void 0}else{const _=k.s1[0],Y=D.get(_);d[Y]=void 0}}),d=d.filter(k=>k!==void 0)}if(C==="round"){let D=Math.floor(Q/4);const x=s.create();f.forEach(F=>{let k=s.angle(s.subtract(x,F.s1[0],F.c));if(k-=s.angle(s.subtract(x,F.s0[1],F.c)),h&&k<0&&(k=k+Math.PI,k<0&&(k=k+Math.PI)),!h&&k>0&&(k=k-Math.PI,k>0&&(k=k-Math.PI)),k!==0){D=Math.floor(Q*(Math.abs(k)/i));const v=k/D,_=s.angle(s.subtract(x,F.s0[1],F.c)),Y=[];for(let P=1;P<D;P++){const T=_+v*P,O=s.fromAngleRadians(s.create(),T);s.scale(O,O,B),s.add(O,O,F.c),Y.push(O)}if(Y.length>0){const P=F.s0[1];let T=d.findIndex(O=>s.equals(P,O));T=(T+1)%d.length,d.splice(T,0,...Y)}}else{const v=F.s1[0],_=d.findIndex(Y=>s.equals(v,Y));d.splice(_,1)}})}return d};A.exports=a}}),Rrt=oe({"node_modules/@jscad/modeling/src/operations/expansions/expandGeom2.js"(t,A){var e=Tn(),i=t5(),o=(n,s)=>{const r={delta:1,corners:"edge",segments:16},{delta:a,corners:g,segments:I}=Object.assign({},r,n);if(!(g==="edge"||g==="chamfer"||g==="round"))throw new Error('corners must be "edge", "chamfer", or "round"');const C=e.toOutlines(s).map(l=>(n={delta:a,corners:g,closed:!0,segments:I},i(n,l))).reduce((l,Q)=>l.concat(e.toSides(e.fromPoints(Q))),[]);return e.create(C)};A.exports=o}}),Mrt=oe({"node_modules/@jscad/modeling/src/operations/expansions/extrudePolygon.js"(t,A){var e=Tg(),i=ho(),o=Kn(),n=Xs(),s=(r,a)=>{i.dot(n.plane(a),r)>0&&(a=n.invert(a));const I=[a],c=n.transform(e.fromTranslation(e.create(),r),a),B=a.vertices.length;for(let C=0;C<B;C++){const l=C<B-1?C+1:0,Q=n.create([a.vertices[C],c.vertices[C],c.vertices[l],a.vertices[l]]);I.push(Q)}return I.push(n.invert(c)),o.create(I)};A.exports=s}}),Nrt=oe({"node_modules/@jscad/modeling/src/operations/expansions/expandShell.js"(t,A){var{EPS:e,TAU:i}=lr(),o=Tg(),n=ho(),s=V8A(),r=Kn(),a=Xs(),g=T8A(),I=VU(),c=$8A(),B=Mrt(),C=(h,u,d)=>{const f=u.toString();if(h.has(f))h.get(f)[1].push(d);else{const m=[u,[d]];h.set(f,m)}},l=(h,u,d)=>{const f=u[0].toString(),m=u[1].toString(),b=f<m?`${f},${m}`:`${m},${f}`;if(h.has(b))h.get(b)[1].push(d);else{const D=[u,[d]];h.set(b,D)}},Q=(h,u)=>{h.findIndex(f=>f===u)<0&&h.push(u)},E=(h,u)=>{const d={delta:1,segments:12},{delta:f,segments:m}=Object.assign({},d,h);let b=r.create();const D=new Map,x=new Map,F=n.create(),k=n.create();return r.toPolygons(u).forEach((_,Y)=>{const P=n.scale(n.create(),a.plane(_),2*f),T=a.transform(o.fromTranslation(o.create(),n.scale(n.create(),P,-.5)),_),O=B(P,T);b=c(b,O);const W=_.vertices;for(let AA=0;AA<W.length;AA++){C(D,W[AA],a.plane(_));const oA=(AA+1)%W.length,IA=[W[AA],W[oA]];l(x,IA,a.plane(_))}}),x.forEach(_=>{const Y=_[0],P=_[1],T=Y[0],O=Y[1],W=n.subtract(n.create(),O,T);n.normalize(W,W);const AA=P[0],oA=n.cross(n.create(),AA,W);let IA=[];for(let qA=0;qA<m;qA++)Q(IA,qA*i/m);for(let qA=0,CA=P.length;qA<CA;qA++){const GA=P[qA],uA=n.dot(oA,GA),TA=n.dot(AA,GA);let $A=Math.atan2(uA,TA);$A<0&&($A+=i),Q(IA,$A),$A=Math.atan2(-uA,-TA),$A<0&&($A+=i),Q(IA,$A)}IA=IA.sort(s);const tA=IA.length;let sA,aA;const dA=[],SA=[],FA=[];for(let qA=-1;qA<tA;qA++){const CA=IA[qA<0?qA+tA:qA],GA=Math.sin(CA),uA=Math.cos(CA);n.scale(F,AA,uA*f),n.scale(k,oA,GA*f),n.add(F,F,k);const TA=n.add(n.create(),T,F),$A=n.add(n.create(),O,F);let ae=!1;if(qA>=0&&n.distance(TA,sA)<e&&(ae=!0),!ae){if(qA>=0){dA.push(TA),SA.push($A);const fA=[aA,$A,TA,sA],KA=a.create(fA);FA.push(KA)}sA=TA,aA=$A}}SA.reverse(),FA.push(a.create(dA)),FA.push(a.create(SA));const MA=r.create(FA);b=c(b,MA)}),D.forEach(_=>{const Y=_[0],P=_[1],T=P[0];let O=null,W=0;for(let tA=1;tA<P.length;tA++){const sA=P[tA],aA=n.cross(F,T,sA),dA=n.length(aA);dA>.05&&dA>W&&(W=dA,O=sA)}O||(O=n.orthogonal(F,T));const AA=n.cross(F,T,O);n.normalize(AA,AA);const oA=n.cross(k,AA,T),IA=g({center:[Y[0],Y[1],Y[2]],radius:f,segments:m,axes:[T,AA,oA]});b=c(b,IA)}),I(b)};A.exports=E}}),_rt=oe({"node_modules/@jscad/modeling/src/operations/expansions/expandGeom3.js"(t,A){var e=Kn(),i=TBA(),o=Nrt(),n=(s,r)=>{const a={delta:1,corners:"round",segments:12},{delta:g,corners:I,segments:c}=Object.assign({},a,s);if(I!=="round")throw new Error('corners must be "round" for 3D geometries');if(e.toPolygons(r).length===0)throw new Error("the given geometry cannot be empty");s={delta:g,corners:I,segments:c};const C=o(s,r);return i(r,C)};A.exports=n}}),vrt=oe({"node_modules/@jscad/modeling/src/operations/expansions/expandPath2.js"(t,A){var e=$O(),i=Bs(),o=Tn(),n=yg(),s=t5(),r=I=>{let{external:c,internal:B}=I;e(c)<0?c=c.reverse():B=B.reverse();const C=n.fromPoints({closed:!0},c),l=n.fromPoints({closed:!0},B),Q=o.toSides(o.fromPoints(n.toPoints(C))),E=o.toSides(o.fromPoints(n.toPoints(l)));return Q.push(...E),o.create(Q)},a=(I,c,B,C)=>{const{points:l,external:Q,internal:E}=I,h=Math.floor(c/2),u=[],d=[];if(B==="round"&&h>0){const m=Math.PI/h,b=l[l.length-1],D=i.angle(i.subtract(i.create(),Q[Q.length-1],b)),x=l[0],F=i.angle(i.subtract(i.create(),E[0],x));for(let k=1;k<h;k++){let v=D+m*k,_=i.fromAngleRadians(i.create(),v);i.scale(_,_,C),i.add(_,_,b),u.push(_),v=F+m*k,_=i.fromAngleRadians(i.create(),v),i.scale(_,_,C),i.add(_,_,x),d.push(_)}}const f=[];return f.push(...Q,...u,...E.reverse(),...d),o.fromPoints(f)},g=(I,c)=>{I=Object.assign({},{delta:1,corners:"edge",segments:16},I);const{delta:C,corners:l,segments:Q}=I;if(C<=0)throw new Error("the given delta must be positive for paths");if(!(l==="edge"||l==="chamfer"||l==="round"))throw new Error('corners must be "edge", "chamfer", or "round"');const E=c.isClosed,h=n.toPoints(c);if(h.length===0)throw new Error("the given geometry cannot be empty");const u={points:h,external:s({delta:C,corners:l,segments:Q,closed:E},h),internal:s({delta:-C,corners:l,segments:Q,closed:E},h)};return c.isClosed?r(u):a(u,Q,l,C)};A.exports=g}}),KBA=oe({"node_modules/@jscad/modeling/src/operations/expansions/expand.js"(t,A){var e=Gn(),i=Tn(),o=Kn(),n=yg(),s=Rrt(),r=_rt(),a=vrt(),g=(I,...c)=>{if(c=e(c),c.length===0)throw new Error("wrong number of arguments");const B=c.map(C=>n.isA(C)?a(I,C):i.isA(C)?s(I,C):o.isA(C)?r(I,C):C);return B.length===1?B[0]:B};A.exports=g}}),Urt=oe({"node_modules/@jscad/modeling/src/operations/expansions/offsetGeom2.js"(t,A){var e=Tn(),i=bBA(),o=t5(),n=(s,r)=>{const a={delta:1,corners:"edge",segments:0},{delta:g,corners:I,segments:c}=Object.assign({},a,s);if(!(I==="edge"||I==="chamfer"||I==="round"))throw new Error('corners must be "edge", "chamfer", or "round"');const B=e.toOutlines(r),l=B.map(Q=>(s={delta:B.reduce((u,d)=>u+i.arePointsInside(Q,i.create(d)),0)%2===0?g:-g,corners:I,closed:!0,segments:c},o(s,Q))).reduce((Q,E)=>Q.concat(e.toSides(e.fromPoints(E))),[]);return e.create(l)};A.exports=n}}),Lrt=oe({"node_modules/@jscad/modeling/src/operations/expansions/offsetPath2.js"(t,A){var e=yg(),i=t5(),o=(n,s)=>{const r={delta:1,corners:"edge",closed:s.isClosed,segments:16},{delta:a,corners:g,closed:I,segments:c}=Object.assign({},r,n);if(!(g==="edge"||g==="chamfer"||g==="round"))throw new Error('corners must be "edge", "chamfer", or "round"');n={delta:a,corners:g,closed:I,segments:c};const B=i(n,e.toPoints(s));return e.fromPoints({closed:I},B)};A.exports=o}}),Hrt=oe({"node_modules/@jscad/modeling/src/operations/expansions/offset.js"(t,A){var e=Gn(),i=Tn(),o=yg(),n=Urt(),s=Lrt(),r=(a,...g)=>{if(g=e(g),g.length===0)throw new Error("wrong number of arguments");const I=g.map(c=>o.isA(c)?s(a,c):i.isA(c)?n(a,c):c);return I.length===1?I[0]:I};A.exports=r}}),tWA=oe({"node_modules/@jscad/modeling/src/operations/expansions/index.js"(t,A){A.exports={expand:KBA(),offset:Hrt()}}}),i5=oe({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeLinearGeom2.js"(t,A){var e=Tg(),i=ho(),o=Tn(),n=PN(),s=e5(),r=(a,g)=>{const I={offset:[0,0,1],twistAngle:0,twistSteps:12,repair:!0};let{offset:c,twistAngle:B,twistSteps:C,repair:l}=Object.assign({},I,a);if(C<1)throw new Error("twistSteps must be 1 or more");B===0&&(C=1);const Q=i.clone(c),E=o.toSides(g);if(E.length===0)throw new Error("the given geometry cannot be empty");const h=n.fromSides(E);Q[2]<0&&n.reverse(h,h);const u=e.create(),d=(f,m,b)=>{const D=m/C*B,x=i.scale(i.create(),Q,m/C);return e.multiply(u,e.fromZRotation(u,D),e.fromTranslation(e.create(),x)),n.transform(u,b)};return a={numberOfSlices:C+1,capStart:!0,capEnd:!0,repair:l,callback:d},s(a,h)};A.exports=r}}),Yrt=oe({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeLinearPath2.js"(t,A){var e=Tn(),i=yg(),o=i5(),n=(s,r)=>{if(!r.isClosed)throw new Error("extruded path must be closed");const a=i.toPoints(r),g=e.fromPoints(a);return o(s,g)};A.exports=n}}),Jrt=oe({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeLinear.js"(t,A){var e=Gn(),i=Tn(),o=yg(),n=i5(),s=Yrt(),r=(a,...g)=>{const I={height:1,twistAngle:0,twistSteps:1,repair:!0},{height:c,twistAngle:B,twistSteps:C,repair:l}=Object.assign({},I,a);if(g=e(g),g.length===0)throw new Error("wrong number of arguments");a={offset:[0,0,c],twistAngle:B,twistSteps:C,repair:l};const Q=g.map(E=>o.isA(E)?s(a,E):i.isA(E)?n(a,E):E);return Q.length===1?Q[0]:Q};A.exports=r}}),Trt=oe({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeRectangularPath2.js"(t,A){var e=yg(),i=KBA(),o=i5(),n=(s,r)=>{const a={size:1,height:1},{size:g,height:I}=Object.assign({},a,s);if(s.delta=g,s.offset=[0,0,I],e.toPoints(r).length===0)throw new Error("the given geometry cannot be empty");const B=i(s,r);return o(s,B)};A.exports=n}}),Krt=oe({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeRectangularGeom2.js"(t,A){var{area:e}=qU(),i=Tn(),o=yg(),n=KBA(),s=i5(),r=(a,g)=>{const I={size:1,height:1},{size:c,height:B}=Object.assign({},I,a);a.delta=c,a.offset=[0,0,B];const C=i.toOutlines(g);if(C.length===0)throw new Error("the given geometry cannot be empty");const Q=C.map(h=>(e(h)<0&&h.reverse(),n(a,o.fromPoints({closed:!0},h)))).reduce((h,u)=>h.concat(i.toSides(u)),[]),E=i.create(Q);return s(a,E)};A.exports=r}}),qrt=oe({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeRectangular.js"(t,A){var e=Gn(),i=Tn(),o=yg(),n=Trt(),s=Krt(),r=(a,...g)=>{const I={size:1,height:1},{size:c,height:B}=Object.assign({},I,a);if(g=e(g),g.length===0)throw new Error("wrong number of arguments");if(c<=0)throw new Error("size must be positive");if(B<=0)throw new Error("height must be positive");const C=g.map(l=>o.isA(l)?n(a,l):i.isA(l)?s(a,l):l);return C.length===1?C[0]:C};A.exports=r}}),Prt=oe({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeHelical.js"(t,A){var{TAU:e}=lr(),i=Tg(),o=Tn(),n=e5(),s=PN(),r=(a,g)=>{const I={angle:e,startAngle:0,pitch:10,height:0,endOffset:0,segmentsPerRotation:32};let{angle:c,startAngle:B,pitch:C,height:l,endOffset:Q,segmentsPerRotation:E}=Object.assign({},I,a);if(l!=0&&(C=l/(c/e)),E<3)throw new Error("The number of segments per rotation needs to be at least 3.");const u=o.toSides(g);if(u.length===0)throw new Error("The given geometry cannot be empty");const d=u.filter(k=>k[0][0]>=0);let f=s.fromSides(u);d.length===0&&(f=s.reverse(f));const m=Math.round(E/e*Math.abs(c)),b=m>=2?m:2,D=i.create(),x=i.create(),F=(k,v,_)=>{const Y=B+c/b*v,P=Q/b*v,T=(Y-B)/e*C;return i.multiply(D,i.fromTranslation(i.create(),[P,0,T*Math.sign(c)]),i.fromXRotation(i.create(),-e/4*Math.sign(c))),i.multiply(x,i.fromZRotation(i.create(),Y),D),s.transform(x,_)};return n({numberOfSlices:b+1,callback:F},f)};A.exports=r}}),Ort=oe({"node_modules/@jscad/modeling/src/operations/extrusions/project.js"(t,A){var e=Gn(),i=FBA(),o=Gm(),n=Tg(),s=Tn(),r=Kn(),a=Xs(),g=bx(),I=eWA(),c=(C,l)=>{const Q=o.fromNormalAndPoint(o.create(),C.axis,C.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 E=g(l),h=E*E*Math.sqrt(3)/4;if(E===0)return s.create();const u=r.toPolygons(l);let d=[];for(let m=0;m<u.length;m++){const b=u[m].vertices.map(F=>o.projectionOfPoint(Q,F)),D=a.create(b),x=a.plane(D);i(Q,x)&&(a.measureArea(D)<h||d.push(D))}if(!i(Q,[0,0,1])){const m=n.fromVectorRotation(n.create(),Q,[0,0,1]);d=d.map(b=>a.transform(m,b))}d=d.sort((m,b)=>a.measureArea(b)-a.measureArea(m));const f=d.map(m=>s.fromPoints(m.vertices));return I(f)},B=(C,...l)=>{const Q={axis:[0,0,1],origin:[0,0,0]},{axis:E,origin:h}=Object.assign({},Q,C);if(l=e(l),l.length===0)throw new Error("wrong number of arguments");C={axis:E,origin:h};const u=l.map(d=>r.isA(d)?c(C,d):d);return u.length===1?u[0]:u};A.exports=B}}),jU=oe({"node_modules/@jscad/modeling/src/operations/extrusions/index.js"(t,A){A.exports={extrudeFromSlices:e5(),extrudeLinear:Jrt(),extrudeRectangular:qrt(),extrudeRotate:O8A(),extrudeHelical:Prt(),project:Ort(),slice:PN()}}}),qBA=oe({"node_modules/@jscad/modeling/src/operations/hulls/hullPoints2.js"(t,A){var e=Bs(),i=s=>{let r=e.fromValues(1/0,1/0);s.forEach(I=>{(I[1]<r[1]||I[1]===r[1]&&I[0]<r[0])&&(r=I)});const a=[];s.forEach(I=>{const c=n(I[1]-r[1],I[0]-r[0]),B=e.squaredDistance(I,r);a.push({point:I,angle:c,distSq:B})}),a.sort((I,c)=>I.angle!==c.angle?I.angle-c.angle:I.distSq-c.distSq);const g=[];return a.forEach(I=>{let c=g.length;for(;c>1&&o(g[c-2],g[c-1],I.point)<=Number.EPSILON;)g.pop(),c=g.length;g.push(I.point)}),g},o=(s,r,a)=>(r[0]-s[0])*(a[1]-s[1])-(r[1]-s[1])*(a[0]-s[0]),n=(s,r)=>s===0&&r===0?-1/0:-r/s;A.exports=i}}),PBA=oe({"node_modules/@jscad/modeling/src/operations/hulls/toUniquePoints.js"(t,A){var e=Tn(),i=Kn(),o=yg(),n=s=>{const r=new Set,a=[],g=I=>{const c=I.toString();r.has(c)||(a.push(I),r.add(c))};return s.forEach(I=>{e.isA(I)?e.toPoints(I).forEach(g):i.isA(I)?i.toPoints(I).forEach(c=>c.forEach(g)):o.isA(I)&&o.toPoints(I).forEach(g)}),a};A.exports=n}}),Wrt=oe({"node_modules/@jscad/modeling/src/operations/hulls/hullPath2.js"(t,A){var e=Gn(),i=yg(),o=qBA(),n=PBA(),s=(...r)=>{r=e(r);const a=n(r),g=o(a);return i.fromPoints({closed:!0},g)};A.exports=s}}),Zrt=oe({"node_modules/@jscad/modeling/src/operations/hulls/hullGeom2.js"(t,A){var e=Gn(),i=Tn(),o=qBA(),n=PBA(),s=(...r)=>{r=e(r);const a=n(r),g=o(a);return g.length<3?i.create():i.fromPoints(g)};A.exports=s}}),iWA=oe({"node_modules/@jscad/modeling/src/operations/hulls/hullPoints3.js"(t,A){var e=Xs(),i=e8A(),o=n=>i(n,{skipTriangulation:!0}).map(a=>{const g=a.map(I=>n[I]);return e.create(g)});A.exports=o}}),Vrt=oe({"node_modules/@jscad/modeling/src/operations/hulls/hullGeom3.js"(t,A){var e=Gn(),i=Kn(),o=PBA(),n=iWA(),s=(...r)=>{r=e(r);const a=o(r);return a.length===0?i.create():i.create(n(a))};A.exports=s}}),oWA=oe({"node_modules/@jscad/modeling/src/operations/hulls/hull.js"(t,A){var e=Gn(),i=ZU(),o=Tn(),n=Kn(),s=yg(),r=Wrt(),a=Zrt(),g=Vrt(),I=(...c)=>{if(c=e(c),c.length===0)throw new Error("wrong number of arguments");if(!i(c))throw new Error("only hulls of the same type are supported");const B=c[0];return s.isA(B)?r(c):o.isA(B)?a(c):n.isA(B)?g(c):B};A.exports=I}}),jrt=oe({"node_modules/@jscad/modeling/src/operations/hulls/hullChain.js"(t,A){var e=Gn(),i=TBA(),o=oWA(),n=(...s)=>{if(s=e(s),s.length<2)throw new Error("wrong number of arguments");const r=[];for(let a=1;a<s.length;a++)r.push(o(s[a-1],s[a]));return i(r)};A.exports=n}}),zrt=oe({"node_modules/@jscad/modeling/src/operations/hulls/index.js"(t,A){A.exports={hull:oWA(),hullChain:jrt(),hullPoints2:qBA(),hullPoints3:iWA()}}}),nWA=oe({"node_modules/@jscad/modeling/src/operations/modifiers/snapPolygons.js"(t,A){var e=ho(),i=Xs(),o=(s,r)=>{const a=Math.abs(i.measureArea(r));return Number.isFinite(a)&&a>s},n=(s,r)=>{let a=r.map(I=>{const c=I.vertices.map(l=>e.snap(e.create(),l,s)),B=[];for(let l=0;l<c.length;l++){const Q=(l+1)%c.length;e.equals(c[l],c[Q])||B.push(c[l])}const C=i.create(B);return I.color&&(C.color=I.color),C});const g=s*s*Math.sqrt(3)/4;return a=a.filter(I=>o(g,I)),a};A.exports=n}}),Xrt=oe({"node_modules/@jscad/modeling/src/operations/modifiers/mergePolygons.js"(t,A){var e=FBA(),i=ho(),o=Xs(),n=h=>{const u=o.toPoints(h),d=[];for(let f=0;f<u.length;f++){const m=(f+1)%u.length,b={v1:u[f],v2:u[m]};d.push(b)}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=(h,u)=>{const d=`${u.v1}:${u.v2}`;h.set(d,u)},r=(h,u)=>{const d=`${u.v1}:${u.v2}`;h.delete(d)},a=(h,u)=>{const d=`${u.v2}:${u.v1}`;return h.get(d)},g=(h,u,d)=>{let f=h.prev.v1,m=h.prev.v2,b=u.next.v2;const D=B(f,m,b,d);f=u.prev.v1,m=u.prev.v2,b=h.next.v2;const x=B(f,m,b,d);return[D,x]},I=i.create(),c=i.create(),B=(h,u,d,f)=>{const m=i.subtract(I,u,h),b=i.subtract(c,d,u);return i.cross(m,m,b),i.dot(m,f)},C=h=>{let u;const d=[];for(;h.next;){const f=h.next;d.push(h.v1),h.v1=null,h.v2=null,h.next=null,h.prev=null,h=f}return d.length>0&&(u=o.create(d)),u},l=h=>{if(h.length<2)return h;const u=h[0].plane,d=h.slice(),f=new Map;for(;d.length>0;){const b=d.shift(),D=n(b);for(let x=0;x<D.length;x++){const F=D[x],k=a(f,F);if(k){const v=g(F,k,u);if(v[0]>=0&&v[1]>=0){const _=k.next,Y=F.next;F.prev.next=k.next,F.next.prev=k.prev,k.prev.next=F.next,k.next.prev=F.prev,F.v1=null,F.v2=null,F.next=null,F.prev=null,r(f,k),k.v1=null,k.v2=null,k.next=null,k.prev=null;const P=(T,O,W)=>{const AA={v1:W.v1,v2:O.v2,next:O.next,prev:W.prev};W.prev.next=AA,O.next.prev=AA,r(T,O),O.v1=null,O.v2=null,O.next=null,O.prev=null,r(T,W),W.v1=null,W.v2=null,W.next=null,W.prev=null};v[0]===0&&P(f,_,_.prev),v[1]===0&&P(f,Y,Y.prev)}}else F.next&&s(f,F)}}const m=[];return f.forEach(b=>{const D=C(b);D&&m.push(D)}),f.clear(),m},Q=(h,u)=>Math.abs(h[3]-u[3])<15e-8?e(h,u):!1,E=(h,u)=>{const d=[];u.forEach(m=>{const b=d.find(D=>Q(D[0],o.plane(m)));b?b[1].push(m):d.push([o.plane(m),[m]])});let f=[];return d.forEach(m=>{const b=m[1],D=l(b);f=f.concat(D)}),f};A.exports=E}}),$rt=oe({"node_modules/@jscad/modeling/src/operations/modifiers/insertTjunctions.js"(t,A){var e=lr(),i=ho(),o=Xs(),n=g=>`${g}`,s=(g,I,c,B,C,l)=>{const Q=n(B),E=n(C),h=`${Q}/${E}`,u=`${E}/${Q}`;if(g.has(u))return r(g,I,c,C,B,null),null;const d={vertex0:B,vertex1:C,polygonindex:l};return g.has(h)?g.get(h).push(d):g.set(h,[d]),I.has(Q)?I.get(Q).push(h):I.set(Q,[h]),c.has(E)?c.get(E).push(h):c.set(E,[h]),h},r=(g,I,c,B,C,l)=>{const Q=n(B),E=n(C),h=`${Q}/${E}`;let u=-1;const d=g.get(h);for(let f=0;f<d.length;f++){const m=d[f];let b=n(m.vertex0);if(b===Q&&(b=n(m.vertex1),b===E&&!(l!==null&&m.polygonindex!==l))){u=f;break}}d.splice(u,1),d.length===0&&g.delete(h),u=I.get(Q).indexOf(h),I.get(Q).splice(u,1),I.get(Q).length===0&&I.delete(Q),u=c.get(E).indexOf(h),c.get(E).splice(u,1),c.get(E).length===0&&c.delete(E)},a=g=>{const I=new Map;for(let c=0;c<g.length;c++){const B=g[c],C=B.vertices.length;if(C>=3){let l=B.vertices[0],Q=n(l);for(let E=0;E<C;E++){let h=E+1;h===C&&(h=0);const u=B.vertices[h],d=n(u),f=`${Q}/${d}`,m=`${d}/${Q}`;if(I.has(m)){const b=I.get(m);b.splice(-1,1),b.length===0&&I.delete(m)}else{const b={vertex0:l,vertex1:u,polygonindex:c};I.has(f)?I.get(f).push(b):I.set(f,[b])}l=u,Q=d}}else console.warn("warning: invalid polygon found during insertTjunctions")}if(I.size>0){const c=new Map,B=new Map,C=new Map;for(const[Q,E]of I)C.set(Q,!0),E.forEach(h=>{const u=n(h.vertex0),d=n(h.vertex1);c.has(u)?c.get(u).push(Q):c.set(u,[Q]),B.has(d)?B.get(d).push(Q):B.set(d,[Q])});const l=g.slice(0);for(;I.size!==0;){for(const E of I.keys())C.set(E,!0);let Q=!1;for(;;){const E=Array.from(C.keys());if(E.length===0)break;const h=E[0];let u=!0;if(I.has(h)){const f=I.get(h)[0];for(let m=0;m<2;m++){const b=m===0?f.vertex0:f.vertex1,D=m===0?f.vertex1:f.vertex0,x=n(b),F=n(D);let k=[];m===0?B.has(x)&&(k=B.get(x)):c.has(x)&&(k=c.get(x));for(let v=0;v<k.length;v++){const _=k[v],Y=I.get(_)[0],P=m===0?Y.vertex0:Y.vertex1;if(m===0?Y.vertex1:Y.vertex0,n(P)===F){r(I,c,B,b,D,null),r(I,c,B,D,b,null),u=!1,m=2,Q=!0;break}else{const O=b,W=D,AA=P,oA=i.subtract(i.create(),AA,O),IA=i.dot(i.subtract(i.create(),W,O),oA)/i.dot(oA,oA);if(IA>0&&IA<1){const tA=i.scale(i.create(),oA,IA);if(i.add(tA,tA,O),i.squaredDistance(tA,W)<e.EPS*e.EPS){const aA=Y.polygonindex,dA=l[aA],SA=n(Y.vertex1);let FA=-1;for(let uA=0;uA<dA.vertices.length;uA++)if(n(dA.vertices[uA])===SA){FA=uA;break}const MA=dA.vertices.slice(0);MA.splice(FA,0,D);const qA=o.create(MA);l[aA]=qA,r(I,c,B,Y.vertex0,Y.vertex1,aA);const CA=s(I,c,B,Y.vertex0,D,aA),GA=s(I,c,B,D,Y.vertex1,aA);CA!==null&&C.set(CA,!0),GA!==null&&C.set(GA,!0),u=!1,m=2,Q=!0;break}}}}}}u&&C.delete(h)}if(!Q)break}g=l}return I.clear(),g};A.exports=a}}),Aat=oe({"node_modules/@jscad/modeling/src/operations/modifiers/triangulatePolygons.js"(t,A){var e=ho(),i=Xs(),o=(s,r,a)=>{const g=r.vertices.length;if(g>3){if(g>4){const B=[0,0,0];r.vertices.forEach(C=>e.add(B,B,C)),e.snap(B,e.divide(B,B,[g,g,g]),s);for(let C=0;C<g;C++){const l=i.create([B,r.vertices[C],r.vertices[(C+1)%g]]);r.color&&(l.color=r.color),a.push(l)}return}const I=i.create([r.vertices[0],r.vertices[1],r.vertices[2]]),c=i.create([r.vertices[0],r.vertices[2],r.vertices[3]]);r.color&&(I.color=r.color,c.color=r.color),a.push(I,c);return}a.push(r)},n=(s,r)=>{const a=[];return r.forEach(g=>{o(s,g,a)}),a};A.exports=n}}),eat=oe({"node_modules/@jscad/modeling/src/operations/modifiers/generalize.js"(t,A){var e=Gn(),i=bx(),o=Tn(),n=Kn(),s=yg(),r=nWA(),a=Xrt(),g=$rt(),I=Aat(),c=(Q,E)=>E,B=(Q,E)=>E,C=(Q,E)=>{const h={snap:!1,simplify:!1,triangulate:!1},{snap:u,simplify:d,triangulate:f}=Object.assign({},h,Q),m=i(E);let b=n.toPolygons(E);u&&(b=r(m,b)),d&&(b=a(m,b)),f&&(b=g(b),b=I(m,b));const D=Object.assign({},E);return D.polygons=b,D},l=(Q,...E)=>{if(E=e(E),E.length===0)throw new Error("wrong number of arguments");const h=E.map(u=>{if(s.isA(u))return c(Q,u);if(o.isA(u))return B(Q,u);if(n.isA(u))return C(Q,u);throw new Error("invalid geometry")});return h.length===1?h[0]:h};A.exports=l}}),tat=oe({"node_modules/@jscad/modeling/src/operations/modifiers/snap.js"(t,A){var e=Gn(),i=Bs(),o=Tn(),n=Kn(),s=yg(),r=bx(),a=nWA(),g=C=>{const l=r(C),E=s.toPoints(C).map(h=>i.snap(i.create(),h,l));return s.create(E)},I=C=>{const l=r(C);let E=o.toSides(C).map(h=>[i.snap(i.create(),h[0],l),i.snap(i.create(),h[1],l)]);return E=E.filter(h=>!i.equals(h[0],h[1])),o.create(E)},c=C=>{const l=r(C),Q=n.toPolygons(C),E=a(l,Q);return n.create(E)},B=(...C)=>{if(C=e(C),C.length===0)throw new Error("wrong number of arguments");const l=C.map(Q=>s.isA(Q)?g(Q):o.isA(Q)?I(Q):n.isA(Q)?c(Q):Q);return l.length===1?l[0]:l};A.exports=B}}),iat=oe({"node_modules/@jscad/modeling/src/operations/modifiers/index.js"(t,A){A.exports={generalize:eat(),snap:tat(),retessellate:VU()}}}),oat=oe({"node_modules/@jscad/modeling/src/utils/padArrayToLength.js"(t,A){var e=(i,o,n)=>{for(i=i.slice();i.length<n;)i.push(o);return i};A.exports=e}}),nat=oe({"node_modules/@jscad/modeling/src/operations/transforms/align.js"(t,A){var e=Gn(),i=oat(),o=MBA(),{translate:n}=tF(),s=I=>{if(!Array.isArray(I.modes)||I.modes.length>3)throw new Error("align(): modes must be an array of length <= 3");if(I.modes=i(I.modes,"none",3),I.modes.filter(c=>["center","max","min","none"].includes(c)).length!==3)throw new Error('align(): all modes must be one of "center", "max" or "min"');if(!Array.isArray(I.relativeTo)||I.relativeTo.length>3)throw new Error("align(): relativeTo must be an array of length <= 3");if(I.relativeTo=i(I.relativeTo,0,3),I.relativeTo.filter(c=>Number.isFinite(c)||c==null).length!==3)throw new Error("align(): all relativeTo values must be a number, or null.");if(typeof I.grouped!="boolean")throw new Error("align(): grouped must be a boolean value.");return I},r=(I,c,B)=>{for(let C=0;C<3;C++)I[C]==null&&(c[C]==="center"?I[C]=(B[0][C]+B[1][C])/2:c[C]==="max"?I[C]=B[1][C]:c[C]==="min"&&(I[C]=B[0][C]));return I},a=(I,c,B)=>{const C=o(I),l=[0,0,0];for(let Q=0;Q<3;Q++)c[Q]==="center"?l[Q]=B[Q]-(C[0][Q]+C[1][Q])/2:c[Q]==="max"?l[Q]=B[Q]-C[1][Q]:c[Q]==="min"&&(l[Q]=B[Q]-C[0][Q]);return n(l,I)},g=(I,...c)=>{I=Object.assign({},{modes:["center","center","min"],relativeTo:[0,0,0],grouped:!1},I),I=s(I);let{modes:C,relativeTo:l,grouped:Q}=I;if(c=e(c),c.length===0)throw new Error("align(): No geometries were provided to act upon");if(l.filter(E=>E==null).length){const E=o(c);l=r(l,C,E)}return Q?c=a(c,C,l):c=c.map(E=>a(E,C,l)),c.length===1?c[0]:c};A.exports=g}}),o5=oe({"node_modules/@jscad/modeling/src/operations/transforms/center.js"(t,A){var e=Gn(),i=Tn(),o=Kn(),n=yg(),s=AF(),{translate:r}=tF(),a=(C,l)=>{const Q={axes:[!0,!0,!0],relativeTo:[0,0,0]},{axes:E,relativeTo:h}=Object.assign({},Q,C),u=s(l),d=[0,0,0];return E[0]&&(d[0]=h[0]-(u[0][0]+(u[1][0]-u[0][0])/2)),E[1]&&(d[1]=h[1]-(u[0][1]+(u[1][1]-u[0][1])/2)),E[2]&&(d[2]=h[2]-(u[0][2]+(u[1][2]-u[0][2])/2)),r(d,l)},g=(C,...l)=>{const Q={axes:[!0,!0,!0],relativeTo:[0,0,0]},{axes:E,relativeTo:h}=Object.assign({},Q,C);if(l=e(l),l.length===0)throw new Error("wrong number of arguments");if(h.length!==3)throw new Error("relativeTo must be an array of length 3");C={axes:E,relativeTo:h};const u=l.map(d=>n.isA(d)||i.isA(d)||o.isA(d)?a(C,d):d);return u.length===1?u[0]:u},I=(...C)=>g({axes:[!0,!1,!1]},C),c=(...C)=>g({axes:[!1,!0,!1]},C),B=(...C)=>g({axes:[!1,!1,!0]},C);A.exports={center:g,centerX:I,centerY:c,centerZ:B}}}),n5=oe({"node_modules/@jscad/modeling/src/operations/transforms/scale.js"(t,A){var e=Gn(),i=Tg(),o=Tn(),n=Kn(),s=yg(),r=(c,...B)=>{if(!Array.isArray(c))throw new Error("factors must be an array");if(B=e(B),B.length===0)throw new Error("wrong number of arguments");for(c=c.slice();c.length<3;)c.push(1);if(c[0]<=0||c[1]<=0||c[2]<=0)throw new Error("factors must be positive");const C=i.fromScaling(i.create(),c),l=B.map(Q=>s.isA(Q)?s.transform(C,Q):o.isA(Q)?o.transform(C,Q):n.isA(Q)?n.transform(C,Q):Q);return l.length===1?l[0]:l},a=(c,...B)=>r([c,1,1],B),g=(c,...B)=>r([1,c,1],B),I=(c,...B)=>r([1,1,c],B);A.exports={scale:r,scaleX:a,scaleY:g,scaleZ:I}}}),sat=oe({"node_modules/@jscad/modeling/src/operations/transforms/transform.js"(t,A){var e=Gn(),i=Tn(),o=Kn(),n=yg(),s=(r,...a)=>{if(a=e(a),a.length===0)throw new Error("wrong number of arguments");const g=a.map(I=>n.isA(I)?n.transform(r,I):i.isA(I)?i.transform(r,I):o.isA(I)?o.transform(r,I):I);return g.length===1?g[0]:g};A.exports=s}}),iF=oe({"node_modules/@jscad/modeling/src/operations/transforms/index.js"(t,A){A.exports={align:nat(),center:o5().center,centerX:o5().centerX,centerY:o5().centerY,centerZ:o5().centerZ,mirror:OU().mirror,mirrorX:OU().mirrorX,mirrorY:OU().mirrorY,mirrorZ:OU().mirrorZ,rotate:WU().rotate,rotateX:WU().rotateX,rotateY:WU().rotateY,rotateZ:WU().rotateZ,scale:n5().scale,scaleX:n5().scaleX,scaleY:n5().scaleY,scaleZ:n5().scaleZ,transform:sat(),translate:tF().translate,translateX:tF().translateX,translateY:tF().translateY,translateZ:tF().translateZ}}}),s5=oe({"node_modules/@jscad/modeling/src/index.js"(t,A){A.exports={colors:XO(),curves:tst(),geometries:xBA(),maths:bst(),measurements:_st(),primitives:xx(),text:UBA(),utils:j8A(),booleans:ON(),expansions:tWA(),extrusions:jU(),hulls:zrt(),modifiers:iat(),transforms:iF()}}}),sWA=oe({"node_modules/jscad-planner/dist/index.cjs"(t,A){var e=Object.defineProperty,i=Object.getOwnPropertyDescriptor,o=Object.getOwnPropertyNames,n=Object.prototype.hasOwnProperty,s=(B,C)=>{for(var l in C)e(B,l,{get:C[l],enumerable:!0})},r=(B,C,l,Q)=>{if(C&&typeof C=="object"||typeof C=="function")for(let E of o(C))!n.call(B,E)&&E!==l&&e(B,E,{get:()=>C[E],enumerable:!(Q=i(C,E))||Q.enumerable});return B},a=B=>r(e({},"__esModule",{value:!0}),B),g={};s(g,{executeJscadOperations:()=>c,jscadPlanner:()=>I}),A.exports=a(g);var I={booleans:{intersect:(...B)=>({type:"intersect",shapes:B}),subtract:(...B)=>({type:"subtract",shapes:B}),union:(...B)=>({type:"union",shapes:B})},hulls:{hull:(...B)=>({type:"hull",shapes:B.flat()}),hullChain:(...B)=>({type:"hullChain",shapes:B.flat()})},colors:{colorize:(B,C)=>({type:"colorize",color:B,shape:C})},primitives:{cube:B=>({type:"cube",...B}),sphere:B=>({type:"sphere",...B}),cylinder:B=>({type:"cylinder",...B}),polygon:B=>({type:"polygon",...B}),cuboid:B=>({type:"cuboid",...B}),roundedCuboid:B=>({type:"roundedCuboid",...B})},transforms:{rotate:(B,C)=>({type:"rotate",angles:B,shape:C}),scale:(B,C)=>({type:"scale",factors:B,shape:C}),translate:(B,C)=>({type:"translate",vector:B,shape:C})},extrusions:{extrudeLinear:(B,C)=>({type:"extrudeLinear",options:B,shape:C}),extrudeRotate:(B,C)=>({type:"extrudeRotate",options:B,shape:C})},maths:{vec2:{create:(B,C)=>[B,C],fromValues:(B,C)=>[B,C]},vec3:{create:(B,C,l)=>[B,C,l],fromValues:(B,C,l)=>[B,C,l]}},geometries:{geom2:{create:B=>({type:"createGeom2",points:B})},geom3:{create:B=>({type:"createGeom3",polygons:B})},path2:{create:B=>({type:"createPath2",points:B})}},measurements:{measureBoundingBox:B=>({type:"measureBoundingBox",shape:B}),measureArea:B=>({type:"measureArea",shape:B}),measureVolume:B=>({type:"measureVolume",shape:B})},utils:{degToRad:B=>B*Math.PI/180,radToDeg:B=>B*180/Math.PI}},c=(B,C)=>{if(Array.isArray(C)&&C.length===1)return c(B,C[0]);if(Array.isArray(C))throw new Error("executeJscadOperations currently doesn't support Array<JscadOperation>, try adding a root union or or executing each element individually");const l=h=>c(B,h),{type:Q,...E}=C;switch(Q){case"intersect":return B.booleans.intersect(...C.shapes.map(l));case"subtract":return B.booleans.subtract(...C.shapes.map(l));case"union":return B.booleans.union(...C.shapes.map(l));case"hull":return B.hulls.hull(...C.shapes.map(l));case"hullChain":return B.hulls.hullChain(...C.shapes.map(l));case"colorize":return B.colors.colorize(C.color,l(C.shape));case"cube":return B.primitives.cube(E);case"sphere":return B.primitives.sphere(E);case"cylinder":return B.primitives.cylinder(E);case"polygon":return B.primitives.polygon(E);case"cuboid":return B.primitives.cuboid(E);case"roundedCuboid":return B.primitives.roundedCuboid(E);case"rotate":return B.transforms.rotate(C.angles,l(C.shape));case"scale":return B.transforms.scale(C.factors,l(C.shape));case"translate":return B.transforms.translate(C.vector,l(C.shape));case"extrudeLinear":return B.extrusions.extrudeLinear(C.options,l(C.shape));case"extrudeRotate":return B.extrusions.extrudeRotate(C.options,l(C.shape));case"createGeom2":return B.geometries.geom2.create(C.points);case"createGeom3":return B.geometries.geom3.create(C.polygons);case"createPath2":return B.geometries.path2.create(C.points);case"measureBoundingBox":return B.measurements.measureBoundingBox(l(C.shape));case"measureArea":return B.measurements.measureArea(l(C.shape));case"measureVolume":return B.measurements.measureVolume(l(C.shape));case"degToRad":return B.utils.degToRad(C.degrees);case"radToDeg":return B.utils.radToDeg(C.radians);default:throw C.type===void 0?new Error(`Operation type is undefined. This usually means the operation object is malformed or not properly initialized. Operation: ${JSON.stringify(C,null,2).slice(0,200)}...`):new Error(`Unsupported operation type: ${C.type}. Operation: ${JSON.stringify(C,null,2)}`)}}}}),rat=oe({"node_modules/ms/index.js"(t,A){var e=1e3,i=e*60,o=i*60,n=o*24,s=n*7,r=n*365.25;A.exports=function(B,C){C=C||{};var l=typeof B;if(l==="string"&&B.length>0)return a(B);if(l==="number"&&isFinite(B))return C.long?I(B):g(B);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(B))};function a(B){if(B=String(B),!(B.length>100)){var C=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(B);if(C){var l=parseFloat(C[1]),Q=(C[2]||"ms").toLowerCase();switch(Q){case"years":case"year":case"yrs":case"yr":case"y":return l*r;case"weeks":case"week":case"w":return l*s;case"days":case"day":case"d":return l*n;case"hours":case"hour":case"hrs":case"hr":case"h":return l*o;case"minutes":case"minute":case"mins":case"min":case"m":return l*i;case"seconds":case"second":case"secs":case"sec":case"s":return l*e;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return l;default:return}}}}function g(B){var C=Math.abs(B);return C>=n?Math.round(B/n)+"d":C>=o?Math.round(B/o)+"h":C>=i?Math.round(B/i)+"m":C>=e?Math.round(B/e)+"s":B+"ms"}function I(B){var C=Math.abs(B);return C>=n?c(B,C,n,"day"):C>=o?c(B,C,o,"hour"):C>=i?c(B,C,i,"minute"):C>=e?c(B,C,e,"second"):B+" ms"}function c(B,C,l,Q){var E=C>=l*1.5;return Math.round(B/l)+" "+Q+(E?"s":"")}}}),aat=oe({"node_modules/debug/src/common.js"(t,A){function e(i){n.debug=n,n.default=n,n.coerce=c,n.disable=g,n.enable=r,n.enabled=I,n.humanize=rat(),n.destroy=B,Object.keys(i).forEach(C=>{n[C]=i[C]}),n.names=[],n.skips=[],n.formatters={};function o(C){let l=0;for(let Q=0;Q<C.length;Q++)l=(l<<5)-l+C.charCodeAt(Q),l|=0;return n.colors[Math.abs(l)%n.colors.length]}n.selectColor=o;function n(C){let l,Q=null,E,h;function u(...d){if(!u.enabled)return;const f=u,m=Number(new Date),b=m-(l||m);f.diff=b,f.prev=l,f.curr=m,l=m,d[0]=n.coerce(d[0]),typeof d[0]!="string"&&d.unshift("%O");let D=0;d[0]=d[0].replace(/%([a-zA-Z%])/g,(F,k)=>{if(F==="%%")return"%";D++;const v=n.formatters[k];if(typeof v=="function"){const _=d[D];F=v.call(f,_),d.splice(D,1),D--}return F}),n.formatArgs.call(f,d),(f.log||n.log).apply(f,d)}return u.namespace=C,u.useColors=n.useColors(),u.color=n.selectColor(C),u.extend=s,u.destroy=n.destroy,Object.defineProperty(u,"enabled",{enumerable:!0,configurable:!1,get:()=>Q!==null?Q:(E!==n.namespaces&&(E=n.namespaces,h=n.enabled(C)),h),set:d=>{Q=d}}),typeof n.init=="function"&&n.init(u),u}function s(C,l){const Q=n(this.namespace+(typeof l>"u"?":":l)+C);return Q.log=this.log,Q}function r(C){n.save(C),n.namespaces=C,n.names=[],n.skips=[];const l=(typeof C=="string"?C:"").trim().replace(/\s+/g,",").split(",").filter(Boolean);for(const Q of l)Q[0]==="-"?n.skips.push(Q.slice(1)):n.names.push(Q)}function a(C,l){let Q=0,E=0,h=-1,u=0;for(;Q<C.length;)if(E<l.length&&(l[E]===C[Q]||l[E]==="*"))l[E]==="*"?(h=E,u=Q,E++):(Q++,E++);else if(h!==-1)E=h+1,u++,Q=u;else return!1;for(;E<l.length&&l[E]==="*";)E++;return E===l.length}function g(){const C=[...n.names,...n.skips.map(l=>"-"+l)].join(",");return n.enable(""),C}function I(C){for(const l of n.skips)if(a(C,l))return!1;for(const l of n.names)if(a(C,l))return!0;return!1}function c(C){return C instanceof Error?C.stack||C.message:C}function B(){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 n.enable(n.load()),n}A.exports=e}}),gat=oe({"node_modules/debug/src/browser.js"(t,A){t.formatArgs=i,t.save=o,t.load=n,t.useColors=e,t.storage=s(),t.destroy=(()=>{let a=!1;return()=>{a||(a=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),t.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"];function e(){if(typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs))return!0;if(typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))return!1;let a;return typeof document<"u"&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent&&(a=navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/))&&parseInt(a[1],10)>=31||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)}function i(a){if(a[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+a[0]+(this.useColors?"%c ":" ")+"+"+A.exports.humanize(this.diff),!this.useColors)return;const g="color: "+this.color;a.splice(1,0,g,"color: inherit");let I=0,c=0;a[0].replace(/%[a-zA-Z%]/g,B=>{B!=="%%"&&(I++,B==="%c"&&(c=I))}),a.splice(c,0,g)}t.log=console.debug||console.log||(()=>{});function o(a){try{a?t.storage.setItem("debug",a):t.storage.removeItem("debug")}catch{}}function n(){let a;try{a=t.storage.getItem("debug")||t.storage.getItem("DEBUG")}catch{}return!a&&typeof dBA<"u"&&"env"in dBA&&(a=dBA.env.DEBUG),a}function s(){try{return localStorage}catch{}}A.exports=aat()(t);var{formatters:r}=A.exports;r.j=function(a){try{return JSON.stringify(a)}catch(g){return"[UnexpectedJSONParseError]: "+g.message}}}}),rWA={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},aWA=$.createContext(void 0),Iat=({children:t})=>{const[A,e]=$.useState(rWA),i=$.useCallback((s,r)=>{e(a=>({...a,[s]:r}))},[]),o=$.useCallback(()=>{e(rWA)},[]),n=$.useMemo(()=>({visibility:A,setLayerVisibility:i,resetToDefaults:o}),[A,i,o]);return V.jsx(aWA.Provider,{value:n,children:t})},WN=()=>{const t=$.useContext(aWA);if(!t)throw new Error("useLayerVisibility must be used within a LayerVisibilityProvider");return t},OBA=1.2;function gWA(t){return $.useMemo(()=>{if(!t)return OBA;try{return mi(t).pcb_board.list()[0]?.thickness??OBA}catch{return OBA}},[t])}var IWA=$.createContext(null),ku=()=>{const t=$.useContext(IWA);if(!t)throw new Error("useThree must be used within a ThreeProvider");return t},zU=(t,A=[])=>{const{addFrameListener:e,removeFrameListener:i}=ku();Xi.useEffect(()=>(e(t),()=>i(t)),[e,i,...A])},XU={clickToInteractOverlay:100,htmlElements:95,orientationCube:95,contextMenu:90,appearanceMenu:91},cWA=({children:t,position:A,style:e})=>{const{camera:i,renderer:o}=ku(),n=$.useRef(document.createElement("div")),[s,r]=$.useState(null);return $.useEffect(()=>{const a=o?.domElement.parentNode;if(a)return a.style.position!=="relative"&&a.style.position!=="absolute"&&(a.style.position="relative"),a.appendChild(n.current),r(PJ.createPortal(t,n.current)),()=>{a.contains(n.current)&&a.removeChild(n.current)}},[o,t]),zU(()=>{if(!i||!n.current||!o)return;const a=new Me(...A);a.project(i);const g=o.domElement.getBoundingClientRect(),I=Math.round((a.x+1)/2*g.width),c=Math.round((-a.y+1)/2*g.height);n.current.style.position="absolute",n.current.style.left=`${I}px`,n.current.style.top=`${c}px`,n.current.style.pointerEvents="none",n.current.style.zIndex=XU.htmlElements.toString(),e&&Object.assign(n.current.style,e)},[i,o,A,e]),s},BWA={in:25.4,inch:25.4,mil:.0254,mm:1,m:1e3,cm:10,ft:304.8,feet:304.8},mr=t=>{let A=typeof t=="number"?"mm":t.replace(/^[^a-zA-Z]+/g,"").toLowerCase();A||(A="mm");const e=typeof t=="number"?t:Number.parseFloat(t.split(A)[0]);if(A in BWA)return e*BWA[A];throw new Error(`Unsupported unit: ${A}`)},yB=mr,CWA={Hz:{baseUnit:"Hz",variants:{MHz:1e6,kHz:1e3,Hz:1}},g:{baseUnit:"g",variants:{kg:1e3,g:1}},Ω:{baseUnit:"Ω",variants:{mΩ:.001,Ω:1,kΩ:1e3,KΩ:1e3,kohm:1e3,MΩ:1e6,GΩ:1e9,TΩ:1e12}},V:{baseUnit:"V",variants:{mV:.001,V:1,kV:1e3,KV:1e3,MV:1e6,GV:1e9,TV:1e12}},A:{baseUnit:"A",variants:{µA:1e-6,mA:.001,ma:.001,A:1,kA:1e3,MA:1e6}},F:{baseUnit:"F",variants:{pF:1e-12,nF:1e-9,µF:1e-6,uF:1e-6,mF:.001,F:1}},ml:{baseUnit:"ml",variants:{ml:1,mL:1,l:1e3,L:1e3}},deg:{baseUnit:"deg",variants:{rad:180/Math.PI}},ms:{baseUnit:"ms",variants:{fs:1e-12,ps:1e-9,ns:1e-6,us:.001,µs:.001,ms:1,s:1e3}},mm:{baseUnit:"mm",variants:{nm:1e-6,µm:.001,um:.001,mm:1,cm:10,dm:100,m:1e3,km:1e6,in:25.4,ft:304.8,IN:25.4,FT:304.8,yd:914.4,mi:1609344,mil:.0254}}},WBA=new Set;for(const[t,A]of Object.entries(CWA)){WBA.add(t);for(const e of Object.keys(A.variants))WBA.add(e)}function cat(t){for(const[A,e]of Object.entries(CWA))if(t in e.variants)return{baseUnit:e.baseUnit,conversionFactor:e.variants[t]};return{baseUnit:t,conversionFactor:1}}var lWA={tera:1e12,T:1e12,giga:1e9,G:1e9,mega:1e6,M:1e6,kilo:1e3,k:1e3,deci:.1,d:.1,centi:.01,c:.01,milli:.001,m:.001,micro:1e-6,u:1e-6,µ:1e-6,nano:1e-9,n:1e-9,pico:1e-12,p:1e-12};function yw(t){if(t==null)return{parsedUnit:null,unitOfValue:null,value:null};if(typeof t=="string"&&t.match(/^-?[\d\.]+$/))return{value:Number.parseFloat(t),parsedUnit:null,unitOfValue:null};if(typeof t=="number")return{value:t,parsedUnit:null,unitOfValue:null};if(typeof t=="object"&&"x"in t&&"y"in t){const{parsedUnit:r,unitOfValue:a}=yw(t.x),g=yw(t.x),I=yw(t.y);return g.value===null||I.value===null?{parsedUnit:null,unitOfValue:null,value:null}:{parsedUnit:r,unitOfValue:a,value:{x:g.value,y:I.value}}}const e=t.toString().split("").reverse().join("").match(/[^\d\s]+/)?.[0];if(!e)throw new Error(`Could not determine unit: "${t}"`);const i=e.split("").reverse().join(""),o=t.slice(0,-i.length);if(i in lWA&&!WBA.has(i)){const r=lWA[i];return{parsedUnit:null,unitOfValue:null,value:Number.parseFloat(o)*r}}const{baseUnit:n,conversionFactor:s}=cat(i);return{parsedUnit:i,unitOfValue:n,value:s*Number.parseFloat(o)}}var ZBA=H().or(WA()).transform(t=>yw(t).value),QWA=H().or(WA()).transform(t=>yw(t).value).transform(t=>Number.parseFloat(t.toPrecision(12))),Bat=H().or(WA()).transform(t=>yw(t).value),ZN=H().or(WA()).transform(t=>yw(t).value),Ae=H().or(WA()).transform(t=>yw(t).value),r5=H().or(WA()).transform(t=>yw(t).value),mt=Ae,VBA=H().or(WA()).transform(t=>yw(t).value),jBA=H().or(WA()).transform(t=>yw(t).value),VN=jBA,Cat=H().datetime(),bd=H().or(WA()).transform(t=>typeof t=="number"?t:t.endsWith("deg")?Number.parseFloat(t.split("deg")[0]):t.endsWith("rad")?Number.parseFloat(t.split("rad")[0])*180/Math.PI:Number.parseFloat(t)),lat=WA().or(H().endsWith("mAh")).transform(t=>{if(typeof t=="string"){const A=t.replace("mAh",""),e=Number.parseFloat(A);if(Number.isNaN(e))throw new Error("Invalid capacity");return e}return t}).describe("Battery capacity in mAh"),ko=OA({x:mt,y:mt}),zBA=OA({x:mt,y:mt,z:mt}),EWA=OA({width:WA(),height:WA()}),Qat=t=>{const A="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";return Array.from({length:t},()=>A[Math.floor(Math.random()*A.length)]).join("")},Vt=t=>H().optional().default(()=>`${t}_${Qat(10)}`),oF=Bt(["top_left","top_center","top_right","center_left","center","center_right","bottom_left","bottom_center","bottom_right"]);Bt(["top_silkscreen","bottom_silkscreen","top_copper","bottom_copper","top_soldermask","bottom_soldermask","top_fabrication_note","bottom_fabrication_note","inner1_copper","inner2_copper","inner3_copper","inner4_copper","inner5_copper","inner6_copper"]);var Eat=Bt(["jlcpcb","macrofab","pcbway","digikey","mouser","lcsc"]),wB=OA({type:xA("source_component"),ftype:H().optional(),source_component_id:H(),name:H(),manufacturer_part_number:H().optional(),supplier_part_numbers:_a(Eat,be(H())).optional(),display_value:H().optional(),are_pins_interchangeable:ce().optional(),internally_connected_source_port_ids:be(be(H())).optional(),source_group_id:H().optional(),subcircuit_id:H().optional()}),hWA=wB.extend({ftype:xA("simple_capacitor"),capacitance:QWA,max_voltage_rating:ZN.optional(),display_capacitance:H().optional(),max_decoupling_trace_length:mt.optional()}),uWA=wB.extend({ftype:xA("simple_resistor"),resistance:ZBA,display_resistance:H().optional()}),XBA=wB.extend({ftype:xA("simple_diode")}),hat=wB.extend({ftype:xA("simple_fiducial")}),dWA=XBA.extend({ftype:xA("simple_led"),color:H().optional(),wavelength:H().optional()}),uat=wB.extend({ftype:xA("simple_ground")}),pWA=wB.extend({ftype:xA("simple_chip")}),fWA=wB.extend({ftype:xA("simple_power_source"),voltage:ZN}),dat=wB.extend({ftype:xA("simple_fuse"),current_rating_amps:WA().describe("Nominal current in amps the fuse is rated for"),voltage_rating_volts:WA().describe("Voltage rating in volts, e.g. ±5V would be 5")}),yWA=wB.extend({ftype:xA("simple_battery"),capacity:lat}),wWA=wB.extend({ftype:xA("simple_inductor"),inductance:Bat,max_current_rating:WA().optional()}),mWA=wB.extend({ftype:xA("simple_push_button")}),DWA=wB.extend({ftype:xA("simple_potentiometer"),max_resistance:ZBA}),pat=wB.extend({ftype:xA("simple_crystal"),frequency:WA().describe("Frequency in Hz"),load_capacitance:WA().optional().describe("Load capacitance in pF")}),SWA=wB.extend({ftype:xA("simple_pin_header"),pin_count:WA(),gender:Bt(["male","female"]).optional().default("male")}),bWA=wB.extend({ftype:xA("simple_pinout")}),xWA=wB.extend({ftype:xA("simple_resonator"),load_capacitance:QWA,equivalent_series_resistance:ZBA.optional(),frequency:r5}),kWA=wB.extend({ftype:xA("simple_transistor"),transistor_type:Bt(["npn","pnp"])}),GWA=wB.extend({ftype:xA("simple_test_point"),footprint_variant:Bt(["pad","through_hole"]).optional(),pad_shape:Bt(["rect","circle"]).optional(),pad_diameter:ei([WA(),H()]).optional(),hole_diameter:ei([WA(),H()]).optional(),width:ei([WA(),H()]).optional(),height:ei([WA(),H()]).optional()}),FWA=wB.extend({ftype:xA("simple_mosfet"),channel_type:Bt(["n","p"]),mosfet_mode:Bt(["enhancement","depletion"])}),RWA=wB.extend({ftype:xA("simple_op_amp")}),MWA=wB.extend({ftype:xA("simple_switch")}),NWA=OA({type:xA("source_project_metadata"),name:H().optional(),software_used_string:H().optional(),project_url:H().optional(),created_at:Cat.optional()}),fat=OA({type:xA("source_missing_property_error"),source_missing_property_error_id:Vt("source_missing_property_error"),source_component_id:H(),property_name:H(),subcircuit_id:H().optional(),error_type:xA("source_missing_property_error").default("source_missing_property_error"),message:H()}).describe("The source code is missing a property"),yat=OA({type:xA("source_failed_to_create_component_error"),source_failed_to_create_component_error_id:Vt("source_failed_to_create_component_error"),error_type:xA("source_failed_to_create_component_error").default("source_failed_to_create_component_error"),component_name:H().optional(),subcircuit_id:H().optional(),parent_source_component_id:H().optional(),message:H(),pcb_center:OA({x:WA().optional(),y:WA().optional()}).optional(),schematic_center:OA({x:WA().optional(),y:WA().optional()}).optional()}).describe("Error emitted when a component fails to be constructed"),_WA=OA({type:xA("source_trace_not_connected_error"),source_trace_not_connected_error_id:Vt("source_trace_not_connected_error"),error_type:xA("source_trace_not_connected_error").default("source_trace_not_connected_error"),message:H(),subcircuit_id:H().optional(),source_group_id:H().optional(),source_trace_id:H().optional(),connected_source_port_ids:be(H()).optional(),selectors_not_found:be(H()).optional()}).describe("Occurs when a source trace selector does not match any ports"),wat=OA({type:xA("source_property_ignored_warning"),source_property_ignored_warning_id:Vt("source_property_ignored_warning"),source_component_id:H(),property_name:H(),subcircuit_id:H().optional(),error_type:xA("source_property_ignored_warning").default("source_property_ignored_warning"),message:H()}).describe("The source property was ignored"),vWA=OA({type:xA("source_pin_missing_trace_warning"),source_pin_missing_trace_warning_id:Vt("source_pin_missing_trace_warning"),warning_type:xA("source_pin_missing_trace_warning").default("source_pin_missing_trace_warning"),message:H(),source_component_id:H(),source_port_id:H(),subcircuit_id:H().optional()}).describe("Warning emitted when a source component pin is missing a trace connection"),mat=wB.extend({ftype:xA("simple_voltage_probe")}),Dat=wB.extend({ftype:xA("interconnect")}),Sat=ei([uWA,hWA,XBA,hat,dWA,uat,pWA,fWA,yWA,wWA,mWA,DWA,pat,SWA,bWA,xWA,MWA,kWA,GWA,FWA,RWA,dat,mat,Dat,NWA,fat,yat,_WA,wat,vWA]),bat=OA({type:xA("source_port"),pin_number:WA().optional(),port_hints:be(H()).optional(),name:H(),source_port_id:H(),source_component_id:H().optional(),source_group_id:H().optional(),subcircuit_id:H().optional(),subcircuit_connectivity_map_key:H().optional(),must_be_connected:ce().optional()}),xat=OA({type:xA("source_component_internal_connection"),source_component_internal_connection_id:H(),source_component_id:H(),source_port_ids:be(H()),subcircuit_id:H().optional()}),kat=OA({type:xA("source_trace"),source_trace_id:H(),connected_source_port_ids:be(H()),connected_source_net_ids:be(H()),subcircuit_id:H().optional(),subcircuit_connectivity_map_key:H().optional(),max_length:WA().optional(),min_trace_thickness:WA().optional(),display_name:H().optional()}),Gat=OA({type:xA("source_group"),source_group_id:H(),subcircuit_id:H().optional(),parent_subcircuit_id:H().optional(),parent_source_group_id:H().optional(),is_subcircuit:ce().optional(),show_as_schematic_box:ce().optional(),name:H().optional(),was_automatically_named:ce().optional()}),Fat=OA({type:xA("source_net"),source_net_id:H(),name:H(),member_source_group_ids:be(H()),is_power:ce().optional(),is_ground:ce().optional(),is_digital_signal:ce().optional(),is_analog_signal:ce().optional(),is_positive_voltage_source:ce().optional(),trace_width:WA().optional(),subcircuit_id:H().optional(),subcircuit_connectivity_map_key:H().optional()}),Rat=OA({type:xA("source_board"),source_board_id:H(),source_group_id:H(),title:H().optional()}).describe("Defines a board in the source domain"),Mat=OA({type:xA("source_pcb_ground_plane"),source_pcb_ground_plane_id:H(),source_group_id:H(),source_net_id:H(),subcircuit_id:H().optional()}).describe("Defines a ground plane in the source domain"),Nat=["top","bottom","inner1","inner2","inner3","inner4","inner5","inner6"],UWA=Bt(Nat),vr=UWA.or(OA({name:UWA})).transform(t=>typeof t=="string"?t:t.name),Fm=Bt(["top","bottom"]),_at=OA({type:xA("source_manually_placed_via"),source_manually_placed_via_id:H(),source_group_id:H(),source_net_id:H(),subcircuit_id:H().optional(),source_trace_id:H().optional()}).describe("Defines a via that is manually placed in the source domain"),vat=OA({type:xA("source_pin_must_be_connected_error"),source_pin_must_be_connected_error_id:Vt("source_pin_must_be_connected_error"),error_type:xA("source_pin_must_be_connected_error").default("source_pin_must_be_connected_error"),message:H(),source_component_id:H(),source_port_id:H(),subcircuit_id:H().optional()}).describe("Error emitted when a pin with mustBeConnected attribute is not connected to any trace"),Uat=OA({type:xA("unknown_error_finding_part"),unknown_error_finding_part_id:Vt("unknown_error_finding_part"),error_type:xA("unknown_error_finding_part").default("unknown_error_finding_part"),message:H(),source_component_id:H().optional(),subcircuit_id:H().optional()}).describe("Error emitted when an unexpected error occurs while finding a part"),Lat=OA({type:xA("schematic_box"),schematic_component_id:H().optional(),width:mt,height:mt,is_dashed:ce().default(!1),x:mt,y:mt,subcircuit_id:H().optional()}).describe("Draws a box on the schematic"),Hat=OA({type:xA("schematic_path"),schematic_component_id:H(),fill_color:Bt(["red","blue"]).optional(),is_filled:ce().optional(),points:be(ko),subcircuit_id:H().optional()}),Yat=_a(OA({left_margin:Ae.optional(),right_margin:Ae.optional(),top_margin:Ae.optional(),bottom_margin:Ae.optional()})),Jat=OA({left_size:WA(),right_size:WA(),top_size:WA().optional(),bottom_size:WA().optional()}),Tat=OA({left_side:OA({pins:be(WA()),direction:Bt(["top-to-bottom","bottom-to-top"]).optional()}).optional(),right_side:OA({pins:be(WA()),direction:Bt(["top-to-bottom","bottom-to-top"]).optional()}).optional(),top_side:OA({pins:be(WA()),direction:Bt(["left-to-right","right-to-left"]).optional()}).optional(),bottom_side:OA({pins:be(WA()),direction:Bt(["left-to-right","right-to-left"]).optional()}).optional()}),Kat=ei([Jat,Tat]),qat=OA({type:xA("schematic_component"),size:EWA,center:ko,source_component_id:H().optional(),schematic_component_id:H(),pin_spacing:Ae.optional(),pin_styles:Yat.optional(),box_width:Ae.optional(),symbol_name:H().optional(),port_arrangement:Kat.optional(),port_labels:_a(H()).optional(),symbol_display_value:H().optional(),subcircuit_id:H().optional(),schematic_group_id:H().optional(),is_schematic_group:ce().optional(),source_group_id:H().optional(),is_box_with_pins:ce().optional().default(!0)}),Pat=OA({type:xA("schematic_line"),schematic_line_id:Vt("schematic_line"),schematic_component_id:H(),x1:mt,y1:mt,x2:mt,y2:mt,stroke_width:mt.nullable().optional(),color:H().default("#000000"),is_dashed:ce().default(!1),subcircuit_id:H().optional()}).describe("Draws a styled line on the schematic"),Oat=OA({type:xA("schematic_rect"),schematic_rect_id:Vt("schematic_rect"),schematic_component_id:H(),center:ko,width:mt,height:mt,rotation:bd.default(0),stroke_width:mt.nullable().optional(),color:H().default("#000000"),is_filled:ce().default(!1),fill_color:H().optional(),is_dashed:ce().default(!1),subcircuit_id:H().optional()}).describe("Draws a styled rectangle on the schematic"),Wat=OA({type:xA("schematic_circle"),schematic_circle_id:Vt("schematic_circle"),schematic_component_id:H(),center:ko,radius:mt,stroke_width:mt.nullable().optional(),color:H().default("#000000"),is_filled:ce().default(!1),fill_color:H().optional(),is_dashed:ce().default(!1),subcircuit_id:H().optional()}).describe("Draws a styled circle on the schematic"),Zat=OA({type:xA("schematic_arc"),schematic_arc_id:Vt("schematic_arc"),schematic_component_id:H(),center:ko,radius:mt,start_angle_degrees:bd,end_angle_degrees:bd,direction:Bt(["clockwise","counterclockwise"]).default("counterclockwise"),stroke_width:mt.nullable().optional(),color:H().default("#000000"),is_dashed:ce().default(!1),subcircuit_id:H().optional()}).describe("Draws a styled arc on the schematic"),Vat=OA({type:xA("schematic_trace"),schematic_trace_id:H(),source_trace_id:H().optional(),junctions:be(OA({x:WA(),y:WA()})),edges:be(OA({from:OA({x:WA(),y:WA()}),to:OA({x:WA(),y:WA()}),is_crossing:ce().optional(),from_schematic_port_id:H().optional(),to_schematic_port_id:H().optional()})),subcircuit_id:H().optional(),subcircuit_connectivity_map_key:H().optional()}),jat=Bt(["center","left","right","top","bottom"]),zat=OA({type:xA("schematic_text"),schematic_component_id:H().optional(),schematic_text_id:H(),text:H(),font_size:WA().default(.18),position:OA({x:mt,y:mt}),rotation:WA().default(0),anchor:ei([jat.describe("legacy"),oF]).default("center"),color:H().default("#000000"),subcircuit_id:H().optional()}),Xat=OA({type:xA("schematic_port"),schematic_port_id:H(),source_port_id:H(),schematic_component_id:H().optional(),center:ko,facing_direction:Bt(["up","down","left","right"]).optional(),distance_from_component_edge:WA().optional(),side_of_component:Bt(["top","bottom","left","right"]).optional(),true_ccw_index:WA().optional(),pin_number:WA().optional(),display_pin_label:H().optional(),subcircuit_id:H().optional(),is_connected:ce().optional(),has_input_arrow:ce().optional(),has_output_arrow:ce().optional()}).describe("Defines a port on a schematic component"),$at=OA({type:xA("schematic_net_label"),schematic_net_label_id:Vt("schematic_net_label"),schematic_trace_id:H().optional(),source_trace_id:H().optional(),source_net_id:H(),center:ko,anchor_position:ko.optional(),anchor_side:Bt(["top","bottom","left","right"]),text:H(),symbol_name:H().optional(),is_movable:ce().optional(),subcircuit_id:H().optional()}),Agt=OA({type:xA("schematic_error"),schematic_error_id:H(),error_type:xA("schematic_port_not_found").default("schematic_port_not_found"),message:H(),subcircuit_id:H().optional()}).describe("Defines a schematic error on the schematic"),egt=OA({type:xA("schematic_layout_error"),schematic_layout_error_id:Vt("schematic_layout_error"),error_type:xA("schematic_layout_error").default("schematic_layout_error"),message:H(),source_group_id:H(),schematic_group_id:H(),subcircuit_id:H().optional()}).describe("Error emitted when schematic layout fails for a group"),$BA=OA({type:xA("schematic_debug_object"),label:H().optional(),subcircuit_id:H().optional()}),tgt=$BA.extend({shape:xA("rect"),center:ko,size:EWA}),igt=$BA.extend({shape:xA("line"),start:ko,end:ko}),ogt=$BA.extend({shape:xA("point"),center:ko}),ngt=Kp("shape",[tgt,igt,ogt]),sgt=OA({type:xA("schematic_voltage_probe"),schematic_voltage_probe_id:H(),source_component_id:H().optional(),name:H().optional(),position:ko,schematic_trace_id:H(),voltage:ZN.optional(),subcircuit_id:H().optional(),color:H().optional(),label_alignment:oF.optional()}).describe("Defines a voltage probe measurement point on a schematic trace"),rgt=OA({type:xA("schematic_manual_edit_conflict_warning"),schematic_manual_edit_conflict_warning_id:Vt("schematic_manual_edit_conflict_warning"),warning_type:xA("schematic_manual_edit_conflict_warning").default("schematic_manual_edit_conflict_warning"),message:H(),schematic_component_id:H(),schematic_group_id:H().optional(),subcircuit_id:H().optional(),source_component_id:H()}).describe("Warning emitted when a component has both manual placement and explicit schX/schY coordinates"),agt=OA({type:xA("schematic_group"),schematic_group_id:Vt("schematic_group"),source_group_id:H(),is_subcircuit:ce().optional(),subcircuit_id:H().optional(),width:Ae,height:Ae,center:ko,schematic_component_ids:be(H()),show_as_schematic_box:ce().optional(),name:H().optional(),description:H().optional()}).describe("Defines a group of components on the schematic"),ggt=OA({type:xA("schematic_table"),schematic_table_id:Vt("schematic_table"),anchor_position:ko,column_widths:be(mt),row_heights:be(mt),cell_padding:mt.optional(),border_width:mt.optional(),subcircuit_id:H().optional(),schematic_component_id:H().optional(),anchor:oF.optional()}).describe("Defines a table on the schematic"),Igt=OA({type:xA("schematic_table_cell"),schematic_table_cell_id:Vt("schematic_table_cell"),schematic_table_id:H(),start_row_index:WA(),end_row_index:WA(),start_column_index:WA(),end_column_index:WA(),text:H().optional(),center:ko,width:mt,height:mt,horizontal_align:Bt(["left","center","right"]).optional(),vertical_align:Bt(["top","middle","bottom"]).optional(),font_size:mt.optional(),subcircuit_id:H().optional()}).describe("Defines a cell within a schematic_table"),cgt=OA({type:xA("schematic_sheet"),schematic_sheet_id:Vt("schematic_sheet"),name:H().optional(),subcircuit_id:H().optional()}).describe("Defines a schematic sheet or page that components can be placed on"),Bgt=OA({x:mt,y:mt,bulge:WA().optional()}),LWA=OA({vertices:be(Bgt)}),Cgt=OA({outer_ring:LWA,inner_rings:be(LWA).default([])}),lgt=OA({x:mt,y:mt,via:ce().optional(),via_to_layer:vr.optional()});be(lgt);var Qgt=OA({x:mt,y:mt,via:ce().optional(),to_layer:vr.optional(),trace_width:mt.optional()}),Egt=OA({type:xA("pcb_component"),pcb_component_id:Vt("pcb_component"),source_component_id:H(),center:ko,layer:vr,rotation:bd,display_offset_x:H().optional().describe("How to display the x offset for this part, usually corresponding with how the user specified it"),display_offset_y:H().optional().describe("How to display the y offset for this part, usually corresponding with how the user specified it"),width:Ae,height:Ae,do_not_place:ce().optional(),subcircuit_id:H().optional(),pcb_group_id:H().optional(),position_mode:Bt(["packed","relative_to_group_anchor","none"]).optional(),positioned_relative_to_pcb_group_id:H().optional(),positioned_relative_to_pcb_board_id:H().optional(),obstructs_within_bounds:ce().default(!0).describe("Does this component take up all the space within its bounds on a layer. This is generally true except for when separated pin headers are being represented by a single component (in which case, chips can be placed between the pin headers) or for tall modules where chips fit underneath")}).describe("Defines a component on the PCB"),HWA=OA({type:xA("pcb_hole"),pcb_hole_id:Vt("pcb_hole"),pcb_group_id:H().optional(),subcircuit_id:H().optional(),pcb_component_id:H().optional(),hole_shape:xA("circle"),hole_diameter:WA(),x:mt,y:mt,is_covered_with_solder_mask:ce().optional(),soldermask_margin:WA().optional()});HWA.describe("Defines a circular hole on the PCB");var YWA=OA({type:xA("pcb_hole"),pcb_hole_id:Vt("pcb_hole"),pcb_group_id:H().optional(),subcircuit_id:H().optional(),pcb_component_id:H().optional(),hole_shape:xA("rect"),hole_width:WA(),hole_height:WA(),x:mt,y:mt,is_covered_with_solder_mask:ce().optional(),soldermask_margin:WA().optional()});YWA.describe("Defines a rectangular (square-capable) hole on the PCB. Use equal width/height for square.");var JWA=OA({type:xA("pcb_hole"),pcb_hole_id:Vt("pcb_hole"),pcb_group_id:H().optional(),subcircuit_id:H().optional(),pcb_component_id:H().optional(),hole_shape:Bt(["circle","square"]),hole_diameter:WA(),x:mt,y:mt,is_covered_with_solder_mask:ce().optional(),soldermask_margin:WA().optional()});JWA.describe("Defines a circular or square hole on the PCB");var TWA=OA({type:xA("pcb_hole"),pcb_hole_id:Vt("pcb_hole"),pcb_group_id:H().optional(),subcircuit_id:H().optional(),pcb_component_id:H().optional(),hole_shape:xA("oval"),hole_width:WA(),hole_height:WA(),x:mt,y:mt,is_covered_with_solder_mask:ce().optional(),soldermask_margin:WA().optional()});TWA.describe("Defines an oval hole on the PCB");var KWA=OA({type:xA("pcb_hole"),pcb_hole_id:Vt("pcb_hole"),pcb_group_id:H().optional(),subcircuit_id:H().optional(),pcb_component_id:H().optional(),hole_shape:xA("pill"),hole_width:WA(),hole_height:WA(),x:mt,y:mt,is_covered_with_solder_mask:ce().optional(),soldermask_margin:WA().optional()});KWA.describe("Defines a pill-shaped hole on the PCB");var qWA=OA({type:xA("pcb_hole"),pcb_hole_id:Vt("pcb_hole"),pcb_group_id:H().optional(),subcircuit_id:H().optional(),pcb_component_id:H().optional(),hole_shape:xA("rotated_pill"),hole_width:WA(),hole_height:WA(),x:mt,y:mt,ccw_rotation:bd,is_covered_with_solder_mask:ce().optional(),soldermask_margin:WA().optional()});qWA.describe("Defines a rotated pill-shaped hole on the PCB");var hgt=JWA.or(TWA).or(KWA).or(qWA).or(HWA).or(YWA),ugt=OA({type:xA("pcb_plated_hole"),shape:xA("circle"),pcb_group_id:H().optional(),subcircuit_id:H().optional(),outer_diameter:WA(),hole_diameter:WA(),is_covered_with_solder_mask:ce().optional(),x:mt,y:mt,layers:be(vr),port_hints:be(H()).optional(),pcb_component_id:H().optional(),pcb_port_id:H().optional(),pcb_plated_hole_id:Vt("pcb_plated_hole"),soldermask_margin:WA().optional()}),dgt=OA({type:xA("pcb_plated_hole"),shape:Bt(["oval","pill"]),pcb_group_id:H().optional(),subcircuit_id:H().optional(),outer_width:WA(),outer_height:WA(),hole_width:WA(),hole_height:WA(),is_covered_with_solder_mask:ce().optional(),x:mt,y:mt,ccw_rotation:bd,layers:be(vr),port_hints:be(H()).optional(),pcb_component_id:H().optional(),pcb_port_id:H().optional(),pcb_plated_hole_id:Vt("pcb_plated_hole"),soldermask_margin:WA().optional()}),pgt=OA({type:xA("pcb_plated_hole"),shape:xA("circular_hole_with_rect_pad"),pcb_group_id:H().optional(),subcircuit_id:H().optional(),hole_shape:xA("circle"),pad_shape:xA("rect"),hole_diameter:WA(),rect_pad_width:WA(),rect_pad_height:WA(),rect_border_radius:WA().optional(),hole_offset_x:mt.default(0),hole_offset_y:mt.default(0),is_covered_with_solder_mask:ce().optional(),x:mt,y:mt,layers:be(vr),port_hints:be(H()).optional(),pcb_component_id:H().optional(),pcb_port_id:H().optional(),pcb_plated_hole_id:Vt("pcb_plated_hole"),soldermask_margin:WA().optional()}),fgt=OA({type:xA("pcb_plated_hole"),shape:xA("pill_hole_with_rect_pad"),pcb_group_id:H().optional(),subcircuit_id:H().optional(),hole_shape:xA("pill"),pad_shape:xA("rect"),hole_width:WA(),hole_height:WA(),rect_pad_width:WA(),rect_pad_height:WA(),rect_border_radius:WA().optional(),hole_offset_x:mt.default(0),hole_offset_y:mt.default(0),is_covered_with_solder_mask:ce().optional(),x:mt,y:mt,layers:be(vr),port_hints:be(H()).optional(),pcb_component_id:H().optional(),pcb_port_id:H().optional(),pcb_plated_hole_id:Vt("pcb_plated_hole"),soldermask_margin:WA().optional()}),ygt=OA({type:xA("pcb_plated_hole"),shape:xA("rotated_pill_hole_with_rect_pad"),pcb_group_id:H().optional(),subcircuit_id:H().optional(),hole_shape:xA("rotated_pill"),pad_shape:xA("rect"),hole_width:WA(),hole_height:WA(),hole_ccw_rotation:bd,rect_pad_width:WA(),rect_pad_height:WA(),rect_border_radius:WA().optional(),rect_ccw_rotation:bd,hole_offset_x:mt.default(0),hole_offset_y:mt.default(0),is_covered_with_solder_mask:ce().optional(),x:mt,y:mt,layers:be(vr),port_hints:be(H()).optional(),pcb_component_id:H().optional(),pcb_port_id:H().optional(),pcb_plated_hole_id:Vt("pcb_plated_hole"),soldermask_margin:WA().optional()}),wgt=OA({type:xA("pcb_plated_hole"),shape:xA("hole_with_polygon_pad"),pcb_group_id:H().optional(),subcircuit_id:H().optional(),hole_shape:Bt(["circle","oval","pill","rotated_pill"]),hole_diameter:WA().optional(),hole_width:WA().optional(),hole_height:WA().optional(),pad_outline:be(OA({x:mt,y:mt})).min(3),hole_offset_x:mt.default(0),hole_offset_y:mt.default(0),is_covered_with_solder_mask:ce().optional(),x:mt,y:mt,layers:be(vr),port_hints:be(H()).optional(),pcb_component_id:H().optional(),pcb_port_id:H().optional(),pcb_plated_hole_id:Vt("pcb_plated_hole"),soldermask_margin:WA().optional()}),mgt=ei([ugt,dgt,pgt,fgt,ygt,wgt]),Dgt=OA({type:xA("pcb_port"),pcb_port_id:Vt("pcb_port"),pcb_group_id:H().optional(),subcircuit_id:H().optional(),source_port_id:H(),pcb_component_id:H().optional(),x:mt,y:mt,layers:be(vr),is_board_pinout:ce().optional()}).describe("Defines a port on the PCB"),Sgt=OA({type:xA("pcb_smtpad"),shape:xA("circle"),pcb_smtpad_id:Vt("pcb_smtpad"),pcb_group_id:H().optional(),subcircuit_id:H().optional(),x:mt,y:mt,radius:WA(),layer:vr,port_hints:be(H()).optional(),pcb_component_id:H().optional(),pcb_port_id:H().optional(),is_covered_with_solder_mask:ce().optional(),soldermask_margin:WA().optional()}),bgt=OA({type:xA("pcb_smtpad"),shape:xA("rect"),pcb_smtpad_id:Vt("pcb_smtpad"),pcb_group_id:H().optional(),subcircuit_id:H().optional(),x:mt,y:mt,width:WA(),height:WA(),rect_border_radius:WA().optional(),corner_radius:WA().optional(),layer:vr,port_hints:be(H()).optional(),pcb_component_id:H().optional(),pcb_port_id:H().optional(),is_covered_with_solder_mask:ce().optional(),soldermask_margin:WA().optional()}),xgt=OA({type:xA("pcb_smtpad"),shape:xA("rotated_rect"),pcb_smtpad_id:Vt("pcb_smtpad"),pcb_group_id:H().optional(),subcircuit_id:H().optional(),x:mt,y:mt,width:WA(),height:WA(),rect_border_radius:WA().optional(),corner_radius:WA().optional(),ccw_rotation:bd,layer:vr,port_hints:be(H()).optional(),pcb_component_id:H().optional(),pcb_port_id:H().optional(),is_covered_with_solder_mask:ce().optional(),soldermask_margin:WA().optional()}),kgt=OA({type:xA("pcb_smtpad"),shape:xA("pill"),pcb_smtpad_id:Vt("pcb_smtpad"),pcb_group_id:H().optional(),subcircuit_id:H().optional(),x:mt,y:mt,width:WA(),height:WA(),radius:WA(),layer:vr,port_hints:be(H()).optional(),pcb_component_id:H().optional(),pcb_port_id:H().optional(),is_covered_with_solder_mask:ce().optional(),soldermask_margin:WA().optional()}),Ggt=OA({type:xA("pcb_smtpad"),shape:xA("rotated_pill"),pcb_smtpad_id:Vt("pcb_smtpad"),pcb_group_id:H().optional(),subcircuit_id:H().optional(),x:mt,y:mt,width:WA(),height:WA(),radius:WA(),ccw_rotation:bd,layer:vr,port_hints:be(H()).optional(),pcb_component_id:H().optional(),pcb_port_id:H().optional(),is_covered_with_solder_mask:ce().optional(),soldermask_margin:WA().optional()}),Fgt=OA({type:xA("pcb_smtpad"),shape:xA("polygon"),pcb_smtpad_id:Vt("pcb_smtpad"),pcb_group_id:H().optional(),subcircuit_id:H().optional(),points:be(ko),layer:vr,port_hints:be(H()).optional(),pcb_component_id:H().optional(),pcb_port_id:H().optional(),is_covered_with_solder_mask:ce().optional(),soldermask_margin:WA().optional()}),Rgt=Kp("shape",[Sgt,bgt,xgt,Ggt,kgt,Fgt]).describe("Defines an SMT pad on the PCB"),Mgt=OA({type:xA("pcb_solder_paste"),shape:xA("circle"),pcb_solder_paste_id:Vt("pcb_solder_paste"),pcb_group_id:H().optional(),subcircuit_id:H().optional(),x:mt,y:mt,radius:WA(),layer:vr,pcb_component_id:H().optional(),pcb_smtpad_id:H().optional()}),Ngt=OA({type:xA("pcb_solder_paste"),shape:xA("rect"),pcb_solder_paste_id:Vt("pcb_solder_paste"),pcb_group_id:H().optional(),subcircuit_id:H().optional(),x:mt,y:mt,width:WA(),height:WA(),layer:vr,pcb_component_id:H().optional(),pcb_smtpad_id:H().optional()}),_gt=OA({type:xA("pcb_solder_paste"),shape:xA("pill"),pcb_solder_paste_id:Vt("pcb_solder_paste"),pcb_group_id:H().optional(),subcircuit_id:H().optional(),x:mt,y:mt,width:WA(),height:WA(),radius:WA(),layer:vr,pcb_component_id:H().optional(),pcb_smtpad_id:H().optional()}),vgt=OA({type:xA("pcb_solder_paste"),shape:xA("rotated_rect"),pcb_solder_paste_id:Vt("pcb_solder_paste"),pcb_group_id:H().optional(),subcircuit_id:H().optional(),x:mt,y:mt,width:WA(),height:WA(),ccw_rotation:mt,layer:vr,pcb_component_id:H().optional(),pcb_smtpad_id:H().optional()}),Ugt=OA({type:xA("pcb_solder_paste"),shape:xA("oval"),pcb_solder_paste_id:Vt("pcb_solder_paste"),pcb_group_id:H().optional(),subcircuit_id:H().optional(),x:mt,y:mt,width:WA(),height:WA(),layer:vr,pcb_component_id:H().optional(),pcb_smtpad_id:H().optional()}),Lgt=ei([Mgt,Ngt,_gt,vgt,Ugt]).describe("Defines solderpaste on the PCB"),Hgt=OA({type:xA("pcb_text"),pcb_text_id:Vt("pcb_text"),pcb_group_id:H().optional(),subcircuit_id:H().optional(),text:H(),center:ko,layer:vr,width:Ae,height:Ae,lines:WA(),align:Bt(["bottom-left"])}).describe("Defines text on the PCB"),Ygt=OA({route_type:xA("wire"),x:mt,y:mt,width:mt,start_pcb_port_id:H().optional(),end_pcb_port_id:H().optional(),layer:vr}),Jgt=OA({route_type:xA("via"),x:mt,y:mt,hole_diameter:mt.optional(),outer_diameter:mt.optional(),from_layer:H(),to_layer:H()}),Tgt=ei([Ygt,Jgt]),Kgt=OA({type:xA("pcb_trace"),source_trace_id:H().optional(),pcb_component_id:H().optional(),pcb_trace_id:Vt("pcb_trace"),pcb_group_id:H().optional(),subcircuit_id:H().optional(),route_thickness_mode:Bt(["constant","interpolated"]).default("constant").optional(),route_order_index:WA().optional(),should_round_corners:ce().optional(),trace_length:WA().optional(),highlight_color:H().optional(),route:be(Tgt)}).describe("Defines a trace on the PCB"),qgt=OA({type:xA("pcb_trace_error"),pcb_trace_error_id:Vt("pcb_trace_error"),error_type:xA("pcb_trace_error").default("pcb_trace_error"),message:H(),center:ko.optional(),pcb_trace_id:H(),source_trace_id:H(),pcb_component_ids:be(H()),pcb_port_ids:be(H()),subcircuit_id:H().optional()}).describe("Defines a trace error on the PCB"),Pgt=OA({type:xA("pcb_trace_missing_error"),pcb_trace_missing_error_id:Vt("pcb_trace_missing_error"),error_type:xA("pcb_trace_missing_error").default("pcb_trace_missing_error"),message:H(),center:ko.optional(),source_trace_id:H(),pcb_component_ids:be(H()),pcb_port_ids:be(H()),subcircuit_id:H().optional()}).describe("Defines an error when a source trace has no corresponding PCB trace"),Ogt=OA({type:xA("pcb_port_not_matched_error"),pcb_error_id:Vt("pcb_error"),error_type:xA("pcb_port_not_matched_error").default("pcb_port_not_matched_error"),message:H(),pcb_component_ids:be(H()),subcircuit_id:H().optional()}).describe("Defines a trace error on the PCB where a port is not matched"),Wgt=OA({type:xA("pcb_port_not_connected_error"),pcb_port_not_connected_error_id:Vt("pcb_port_not_connected_error"),error_type:xA("pcb_port_not_connected_error").default("pcb_port_not_connected_error"),message:H(),pcb_port_ids:be(H()),pcb_component_ids:be(H()),subcircuit_id:H().optional()}).describe("Defines an error when a pcb port is not connected to any trace"),Zgt=OA({type:xA("pcb_net"),pcb_net_id:Vt("pcb_net"),source_net_id:H().optional(),highlight_color:H().optional()}).describe("Defines a net on the PCB"),Vgt=OA({type:xA("pcb_via"),pcb_via_id:Vt("pcb_via"),pcb_group_id:H().optional(),subcircuit_id:H().optional(),subcircuit_connectivity_map_key:H().optional(),x:mt,y:mt,outer_diameter:mt.default("0.6mm"),hole_diameter:mt.default("0.25mm"),from_layer:vr.optional(),to_layer:vr.optional(),layers:be(vr),pcb_trace_id:H().optional(),net_is_assignable:ce().optional(),net_assigned:ce().optional(),is_tented:ce().optional()}).describe("Defines a via on the PCB"),jgt=OA({type:xA("pcb_board"),pcb_board_id:Vt("pcb_board"),pcb_panel_id:H().optional(),is_subcircuit:ce().optional(),subcircuit_id:H().optional(),width:Ae.optional(),height:Ae.optional(),center:ko,display_offset_x:H().optional().describe("How to display the x offset for this board, usually corresponding with how the user specified it"),display_offset_y:H().optional().describe("How to display the y offset for this board, usually corresponding with how the user specified it"),thickness:Ae.optional().default(1.4),num_layers:WA().optional().default(4),outline:be(ko).optional(),shape:Bt(["rect","polygon"]).optional(),material:Bt(["fr4","fr1"]).default("fr4"),anchor_position:ko.optional(),anchor_alignment:oF.optional(),position_mode:Bt(["relative_to_panel_anchor","none"]).optional()}).describe("Defines the board outline of the PCB"),zgt=OA({type:xA("pcb_panel"),pcb_panel_id:Vt("pcb_panel"),width:Ae,height:Ae,center:ko,covered_with_solder_mask:ce().optional().default(!0)}).describe("Defines a PCB panel that can contain multiple boards"),Xgt=OA({type:xA("pcb_placement_error"),pcb_placement_error_id:Vt("pcb_placement_error"),error_type:xA("pcb_placement_error").default("pcb_placement_error"),message:H(),subcircuit_id:H().optional()}).describe("Defines a placement error on the PCB"),$gt=OA({type:xA("pcb_trace_hint"),pcb_trace_hint_id:Vt("pcb_trace_hint"),pcb_port_id:H(),pcb_component_id:H(),route:be(Qgt),subcircuit_id:H().optional()}).describe("A hint that can be used during generation of a PCB trace"),AIt=OA({type:xA("pcb_silkscreen_line"),pcb_silkscreen_line_id:Vt("pcb_silkscreen_line"),pcb_component_id:H(),pcb_group_id:H().optional(),subcircuit_id:H().optional(),stroke_width:mt.default("0.1mm"),x1:mt,y1:mt,x2:mt,y2:mt,layer:Fm}).describe("Defines a silkscreen line on the PCB"),eIt=OA({type:xA("pcb_silkscreen_path"),pcb_silkscreen_path_id:Vt("pcb_silkscreen_path"),pcb_component_id:H(),pcb_group_id:H().optional(),subcircuit_id:H().optional(),layer:Fm,route:be(ko),stroke_width:Ae}).describe("Defines a silkscreen path on the PCB"),tIt=OA({type:xA("pcb_silkscreen_text"),pcb_silkscreen_text_id:Vt("pcb_silkscreen_text"),pcb_group_id:H().optional(),subcircuit_id:H().optional(),font:xA("tscircuit2024").default("tscircuit2024"),font_size:mt.default("0.2mm"),pcb_component_id:H(),text:H(),is_knockout:ce().default(!1).optional(),knockout_padding:OA({left:Ae,top:Ae,bottom:Ae,right:Ae}).default({left:"0.2mm",top:"0.2mm",bottom:"0.2mm",right:"0.2mm"}).optional(),ccw_rotation:WA().optional(),layer:vr,is_mirrored:ce().default(!1).optional(),anchor_position:ko.default({x:0,y:0}),anchor_alignment:oF.default("center")}).describe("Defines silkscreen text on the PCB"),iIt=OA({type:xA("pcb_copper_text"),pcb_copper_text_id:Vt("pcb_copper_text"),pcb_group_id:H().optional(),subcircuit_id:H().optional(),font:xA("tscircuit2024").default("tscircuit2024"),font_size:mt.default("0.2mm"),pcb_component_id:H(),text:H(),is_knockout:ce().default(!1).optional(),knockout_padding:OA({left:Ae,top:Ae,bottom:Ae,right:Ae}).default({left:"0.2mm",top:"0.2mm",bottom:"0.2mm",right:"0.2mm"}).optional(),ccw_rotation:WA().optional(),layer:vr,is_mirrored:ce().default(!1).optional(),anchor_position:ko.default({x:0,y:0}),anchor_alignment:oF.default("center")}).describe("Defines copper text on the PCB"),oIt=OA({type:xA("pcb_silkscreen_rect"),pcb_silkscreen_rect_id:Vt("pcb_silkscreen_rect"),pcb_component_id:H(),pcb_group_id:H().optional(),subcircuit_id:H().optional(),center:ko,width:Ae,height:Ae,layer:vr,stroke_width:Ae.default("1mm"),corner_radius:Ae.optional(),is_filled:ce().default(!0).optional(),has_stroke:ce().optional(),is_stroke_dashed:ce().optional(),ccw_rotation:WA().optional()}).describe("Defines a silkscreen rect on the PCB"),nIt=OA({type:xA("pcb_silkscreen_circle"),pcb_silkscreen_circle_id:Vt("pcb_silkscreen_circle"),pcb_component_id:H(),pcb_group_id:H().optional(),subcircuit_id:H().optional(),center:ko,radius:Ae,layer:Fm,stroke_width:Ae.default("1mm")}).describe("Defines a silkscreen circle on the PCB"),sIt=OA({type:xA("pcb_silkscreen_oval"),pcb_silkscreen_oval_id:Vt("pcb_silkscreen_oval"),pcb_component_id:H(),pcb_group_id:H().optional(),subcircuit_id:H().optional(),center:ko,radius_x:mt,radius_y:mt,layer:Fm,ccw_rotation:bd.optional()}).describe("Defines a silkscreen oval on the PCB"),rIt=OA({type:xA("pcb_silkscreen_pill"),pcb_silkscreen_pill_id:Vt("pcb_silkscreen_pill"),pcb_component_id:H(),pcb_group_id:H().optional(),subcircuit_id:H().optional(),center:ko,width:Ae,height:Ae,layer:vr,ccw_rotation:WA().optional()}).describe("Defines a silkscreen pill on the PCB"),aIt=OA({type:xA("pcb_fabrication_note_text"),pcb_fabrication_note_text_id:Vt("pcb_fabrication_note_text"),subcircuit_id:H().optional(),pcb_group_id:H().optional(),font:xA("tscircuit2024").default("tscircuit2024"),font_size:mt.default("1mm"),pcb_component_id:H(),text:H(),layer:Fm,anchor_position:ko.default({x:0,y:0}),anchor_alignment:Bt(["center","top_left","top_right","bottom_left","bottom_right"]).default("center"),color:H().optional()}).describe("Defines a fabrication note in text on the PCB, useful for leaving notes for assemblers or fabricators"),gIt=OA({type:xA("pcb_fabrication_note_path"),pcb_fabrication_note_path_id:Vt("pcb_fabrication_note_path"),pcb_component_id:H(),subcircuit_id:H().optional(),layer:vr,route:be(ko),stroke_width:Ae,color:H().optional()}).describe("Defines a fabrication path on the PCB for fabricators or assemblers"),IIt=OA({type:xA("pcb_fabrication_note_rect"),pcb_fabrication_note_rect_id:Vt("pcb_fabrication_note_rect"),pcb_component_id:H(),pcb_group_id:H().optional(),subcircuit_id:H().optional(),center:ko,width:Ae,height:Ae,layer:Fm,stroke_width:Ae.default("0.1mm"),corner_radius:Ae.optional(),is_filled:ce().optional(),has_stroke:ce().optional(),is_stroke_dashed:ce().optional(),color:H().optional()}).describe("Defines a fabrication note rectangle on the PCB"),cIt=OA({type:xA("pcb_fabrication_note_dimension"),pcb_fabrication_note_dimension_id:Vt("pcb_fabrication_note_dimension"),pcb_component_id:H(),pcb_group_id:H().optional(),subcircuit_id:H().optional(),layer:Fm,from:ko,to:ko,text:H().optional(),text_ccw_rotation:WA().optional(),offset:Ae.optional(),offset_distance:Ae.optional(),offset_direction:OA({x:WA(),y:WA()}).optional(),font:xA("tscircuit2024").default("tscircuit2024"),font_size:Ae.default("1mm"),color:H().optional(),arrow_size:Ae.default("1mm")}).describe("Defines a measurement annotation within PCB fabrication notes"),BIt=OA({type:xA("pcb_note_text"),pcb_note_text_id:Vt("pcb_note_text"),pcb_component_id:H().optional(),pcb_group_id:H().optional(),subcircuit_id:H().optional(),name:H().optional(),font:xA("tscircuit2024").default("tscircuit2024"),font_size:mt.default("1mm"),text:H().optional(),anchor_position:ko.default({x:0,y:0}),anchor_alignment:Bt(["center","top_left","top_right","bottom_left","bottom_right"]).default("center"),color:H().optional()}).describe("Defines a documentation note in text on the PCB"),CIt=OA({type:xA("pcb_note_rect"),pcb_note_rect_id:Vt("pcb_note_rect"),pcb_component_id:H().optional(),pcb_group_id:H().optional(),subcircuit_id:H().optional(),name:H().optional(),text:H().optional(),center:ko,width:Ae,height:Ae,stroke_width:Ae.default("0.1mm"),corner_radius:Ae.optional(),is_filled:ce().optional(),has_stroke:ce().optional(),is_stroke_dashed:ce().optional(),color:H().optional()}).describe("Defines a rectangular documentation note on the PCB"),lIt=OA({type:xA("pcb_note_path"),pcb_note_path_id:Vt("pcb_note_path"),pcb_component_id:H().optional(),pcb_group_id:H().optional(),subcircuit_id:H().optional(),name:H().optional(),text:H().optional(),route:be(ko),stroke_width:Ae.default("0.1mm"),color:H().optional()}).describe("Defines a polyline documentation note on the PCB"),QIt=OA({type:xA("pcb_note_line"),pcb_note_line_id:Vt("pcb_note_line"),pcb_component_id:H().optional(),pcb_group_id:H().optional(),subcircuit_id:H().optional(),name:H().optional(),text:H().optional(),x1:mt,y1:mt,x2:mt,y2:mt,stroke_width:mt.default("0.1mm"),color:H().optional(),is_dashed:ce().optional()}).describe("Defines a straight documentation note line on the PCB"),EIt=OA({type:xA("pcb_note_dimension"),pcb_note_dimension_id:Vt("pcb_note_dimension"),pcb_component_id:H().optional(),pcb_group_id:H().optional(),subcircuit_id:H().optional(),name:H().optional(),from:ko,to:ko,text:H().optional(),text_ccw_rotation:WA().optional(),offset_distance:Ae.optional(),offset_direction:OA({x:WA(),y:WA()}).optional(),font:xA("tscircuit2024").default("tscircuit2024"),font_size:Ae.default("1mm"),color:H().optional(),arrow_size:Ae.default("1mm")}).describe("Defines a measurement annotation within PCB documentation notes"),hIt=OA({type:xA("pcb_footprint_overlap_error"),pcb_error_id:Vt("pcb_error"),error_type:xA("pcb_footprint_overlap_error").default("pcb_footprint_overlap_error"),message:H(),pcb_smtpad_ids:be(H()).optional(),pcb_plated_hole_ids:be(H()).optional(),pcb_hole_ids:be(H()).optional(),pcb_keepout_ids:be(H()).optional()}).describe("Error emitted when a pcb footprint overlaps with another element"),uIt=OA({type:xA("pcb_keepout"),shape:xA("rect"),pcb_group_id:H().optional(),subcircuit_id:H().optional(),center:ko,width:mt,height:mt,pcb_keepout_id:H(),layers:be(H()),description:H().optional()}).or(OA({type:xA("pcb_keepout"),shape:xA("circle"),pcb_group_id:H().optional(),subcircuit_id:H().optional(),center:ko,radius:mt,pcb_keepout_id:H(),layers:be(H()),description:H().optional()})),a5=OA({type:xA("pcb_cutout"),pcb_cutout_id:Vt("pcb_cutout"),pcb_group_id:H().optional(),subcircuit_id:H().optional(),pcb_board_id:H().optional(),pcb_panel_id:H().optional()}),dIt=a5.extend({shape:xA("rect"),center:ko,width:Ae,height:Ae,rotation:bd.optional(),corner_radius:Ae.optional()}),pIt=a5.extend({shape:xA("circle"),center:ko,radius:Ae}),fIt=a5.extend({shape:xA("polygon"),points:be(ko)}),yIt=a5.extend({shape:xA("path"),route:be(ko),slot_width:Ae,slot_length:Ae.optional(),space_between_slots:Ae.optional(),slot_corner_radius:Ae.optional()}),wIt=Kp("shape",[dIt,pIt,fIt,yIt]).describe("Defines a cutout on the PCB, removing board material."),mIt=OA({type:xA("pcb_missing_footprint_error"),pcb_missing_footprint_error_id:Vt("pcb_missing_footprint_error"),pcb_group_id:H().optional(),subcircuit_id:H().optional(),error_type:xA("pcb_missing_footprint_error").default("pcb_missing_footprint_error"),source_component_id:H(),message:H()}).describe("Defines a missing footprint error on the PCB"),DIt=OA({type:xA("external_footprint_load_error"),external_footprint_load_error_id:Vt("external_footprint_load_error"),pcb_component_id:H(),source_component_id:H(),pcb_group_id:H().optional(),subcircuit_id:H().optional(),footprinter_string:H().optional(),error_type:xA("external_footprint_load_error").default("external_footprint_load_error"),message:H()}).describe("Defines an error when an external footprint fails to load"),SIt=OA({type:xA("circuit_json_footprint_load_error"),circuit_json_footprint_load_error_id:Vt("circuit_json_footprint_load_error"),pcb_component_id:H(),source_component_id:H(),pcb_group_id:H().optional(),subcircuit_id:H().optional(),error_type:xA("circuit_json_footprint_load_error").default("circuit_json_footprint_load_error"),message:H(),circuit_json:be(HI()).optional()}).describe("Defines an error when a circuit JSON footprint fails to load"),bIt=OA({type:xA("pcb_group"),pcb_group_id:Vt("pcb_group"),source_group_id:H(),is_subcircuit:ce().optional(),subcircuit_id:H().optional(),width:Ae.optional(),height:Ae.optional(),center:ko,display_offset_x:H().optional().describe("How to display the x offset for this group, usually corresponding with how the user specified it"),display_offset_y:H().optional().describe("How to display the y offset for this group, usually corresponding with how the user specified it"),outline:be(ko).optional(),anchor_position:ko.optional(),anchor_alignment:oF.default("center"),position_mode:Bt(["packed","relative_to_group_anchor","none"]).optional(),positioned_relative_to_pcb_group_id:H().optional(),positioned_relative_to_pcb_board_id:H().optional(),pcb_component_ids:be(H()),child_layout_mode:Bt(["packed","none"]).optional(),name:H().optional(),description:H().optional(),layout_mode:H().optional(),autorouter_configuration:OA({trace_clearance:Ae}).optional(),autorouter_used_string:H().optional()}).describe("Defines a group of components on the PCB"),xIt=OA({type:xA("pcb_autorouting_error"),pcb_error_id:Vt("pcb_autorouting_error"),error_type:xA("pcb_autorouting_error").default("pcb_autorouting_error"),message:H(),subcircuit_id:H().optional()}).describe("The autorouting has failed to route a portion of the board"),kIt=OA({type:xA("pcb_manual_edit_conflict_warning"),pcb_manual_edit_conflict_warning_id:Vt("pcb_manual_edit_conflict_warning"),warning_type:xA("pcb_manual_edit_conflict_warning").default("pcb_manual_edit_conflict_warning"),message:H(),pcb_component_id:H(),pcb_group_id:H().optional(),subcircuit_id:H().optional(),source_component_id:H()}).describe("Warning emitted when a component has both manual placement and explicit pcbX/pcbY coordinates"),GIt=OA({type:xA("pcb_breakout_point"),pcb_breakout_point_id:Vt("pcb_breakout_point"),pcb_group_id:H(),subcircuit_id:H().optional(),source_trace_id:H().optional(),source_port_id:H().optional(),source_net_id:H().optional(),x:mt,y:mt}).describe("Defines a routing target within a pcb_group for a source_trace or source_net"),FIt=OA({type:xA("pcb_ground_plane"),pcb_ground_plane_id:Vt("pcb_ground_plane"),source_pcb_ground_plane_id:H(),source_net_id:H(),pcb_group_id:H().optional(),subcircuit_id:H().optional()}).describe("Defines a ground plane on the PCB"),RIt=OA({type:xA("pcb_ground_plane_region"),pcb_ground_plane_region_id:Vt("pcb_ground_plane_region"),pcb_ground_plane_id:H(),pcb_group_id:H().optional(),subcircuit_id:H().optional(),layer:vr,points:be(ko)}).describe("Defines a polygon region of a ground plane"),MIt=OA({type:xA("pcb_thermal_spoke"),pcb_thermal_spoke_id:Vt("pcb_thermal_spoke"),pcb_ground_plane_id:H(),shape:H(),spoke_count:WA(),spoke_thickness:mt,spoke_inner_diameter:mt,spoke_outer_diameter:mt,pcb_plated_hole_id:H().optional(),subcircuit_id:H().optional()}).describe("Pattern for connecting a ground plane to a plated hole"),ACA=OA({type:xA("pcb_copper_pour"),pcb_copper_pour_id:Vt("pcb_copper_pour"),pcb_group_id:H().optional(),subcircuit_id:H().optional(),layer:vr,source_net_id:H().optional(),covered_with_solder_mask:ce().optional().default(!0)}),NIt=ACA.extend({shape:xA("rect"),center:ko,width:Ae,height:Ae,rotation:bd.optional()}),_It=ACA.extend({shape:xA("brep"),brep_shape:Cgt}),vIt=ACA.extend({shape:xA("polygon"),points:be(ko)}),UIt=Kp("shape",[NIt,_It,vIt]).describe("Defines a copper pour on the PCB."),LIt=OA({type:xA("pcb_component_outside_board_error"),pcb_component_outside_board_error_id:Vt("pcb_component_outside_board_error"),error_type:xA("pcb_component_outside_board_error").default("pcb_component_outside_board_error"),message:H(),pcb_component_id:H(),pcb_board_id:H(),component_center:ko,component_bounds:OA({min_x:WA(),max_x:WA(),min_y:WA(),max_y:WA()}),subcircuit_id:H().optional(),source_component_id:H().optional()}).describe("Error emitted when a PCB component is placed outside the board boundaries"),HIt=OA({type:xA("pcb_component_invalid_layer_error"),pcb_component_invalid_layer_error_id:Vt("pcb_component_invalid_layer_error"),error_type:xA("pcb_component_invalid_layer_error").default("pcb_component_invalid_layer_error"),message:H(),pcb_component_id:H().optional(),source_component_id:H(),layer:vr,subcircuit_id:H().optional()}).describe("Error emitted when a component is placed on an invalid layer (components can only be on 'top' or 'bottom' layers)"),YIt=OA({type:xA("pcb_via_clearance_error"),pcb_error_id:Vt("pcb_error"),error_type:xA("pcb_via_clearance_error").default("pcb_via_clearance_error"),message:H(),pcb_via_ids:be(H()).min(2),minimum_clearance:mt.optional(),actual_clearance:mt.optional(),pcb_center:OA({x:WA().optional(),y:WA().optional()}).optional(),subcircuit_id:H().optional()}).describe("Error emitted when vias are closer than the allowed clearance"),JIt=OA({type:xA("pcb_courtyard_rect"),pcb_courtyard_rect_id:Vt("pcb_courtyard_rect"),pcb_component_id:H(),pcb_group_id:H().optional(),subcircuit_id:H().optional(),center:ko,width:Ae,height:Ae,layer:Fm,color:H().optional()}).describe("Defines a courtyard rectangle on the PCB"),TIt=OA({type:xA("pcb_courtyard_outline"),pcb_courtyard_outline_id:Vt("pcb_courtyard_outline"),pcb_component_id:H(),pcb_group_id:H().optional(),subcircuit_id:H().optional(),layer:Fm,outline:be(ko).min(2),stroke_width:Ae.default("0.1mm"),is_closed:ce().optional(),is_stroke_dashed:ce().optional(),color:H().optional()}).describe("Defines a courtyard outline on the PCB"),KIt=OA({type:xA("pcb_courtyard_polygon"),pcb_courtyard_polygon_id:Vt("pcb_courtyard_polygon"),pcb_component_id:H(),pcb_group_id:H().optional(),subcircuit_id:H().optional(),layer:Fm,points:be(ko).min(3),color:H().optional()}).describe("Defines a courtyard polygon on the PCB"),qIt=OA({type:xA("cad_component"),cad_component_id:H(),pcb_component_id:H(),source_component_id:H(),position:zBA,rotation:zBA.optional(),size:zBA.optional(),layer:vr.optional(),subcircuit_id:H().optional(),footprinter_string:H().optional(),model_obj_url:H().optional(),model_stl_url:H().optional(),model_3mf_url:H().optional(),model_gltf_url:H().optional(),model_glb_url:H().optional(),model_step_url:H().optional(),model_wrl_url:H().optional(),model_unit_to_mm_scale_factor:WA().optional(),model_jscad:HI().optional(),show_as_translucent_model:ce().optional()}).describe("Defines a component on the PCB"),PWA=Bt(["sinewave","square","triangle","sawtooth"]),PIt=ei([H(),WA()]).transform(t=>typeof t=="string"?t.endsWith("%")?parseFloat(t.slice(0,-1))/100:parseFloat(t):t).pipe(WA().min(0,"Duty cycle must be non-negative").max(1,"Duty cycle cannot be greater than 100%")),OIt=OA({type:xA("simulation_voltage_source"),simulation_voltage_source_id:Vt("simulation_voltage_source"),is_dc_source:xA(!0).optional().default(!0),positive_source_port_id:H().optional(),negative_source_port_id:H().optional(),positive_source_net_id:H().optional(),negative_source_net_id:H().optional(),voltage:ZN}).describe("Defines a DC voltage source for simulation"),WIt=OA({type:xA("simulation_voltage_source"),simulation_voltage_source_id:Vt("simulation_voltage_source"),is_dc_source:xA(!1),terminal1_source_port_id:H().optional(),terminal2_source_port_id:H().optional(),terminal1_source_net_id:H().optional(),terminal2_source_net_id:H().optional(),voltage:ZN.optional(),frequency:r5.optional(),peak_to_peak_voltage:ZN.optional(),wave_shape:PWA.optional(),phase:bd.optional(),duty_cycle:PIt.optional()}).describe("Defines an AC voltage source for simulation"),ZIt=ei([OIt,WIt]).describe("Defines a voltage source for simulation"),VIt=ei([H(),WA()]).transform(t=>typeof t=="string"?t.endsWith("%")?parseFloat(t.slice(0,-1))/100:parseFloat(t):t).pipe(WA().min(0,"Duty cycle must be non-negative").max(1,"Duty cycle cannot be greater than 100%")),jIt=OA({type:xA("simulation_current_source"),simulation_current_source_id:Vt("simulation_current_source"),is_dc_source:xA(!0).optional().default(!0),positive_source_port_id:H().optional(),negative_source_port_id:H().optional(),positive_source_net_id:H().optional(),negative_source_net_id:H().optional(),current:VBA}).describe("Defines a DC current source for simulation"),zIt=OA({type:xA("simulation_current_source"),simulation_current_source_id:Vt("simulation_current_source"),is_dc_source:xA(!1),terminal1_source_port_id:H().optional(),terminal2_source_port_id:H().optional(),terminal1_source_net_id:H().optional(),terminal2_source_net_id:H().optional(),current:VBA.optional(),frequency:r5.optional(),peak_to_peak_current:VBA.optional(),wave_shape:PWA.optional(),phase:bd.optional(),duty_cycle:VIt.optional()}).describe("Defines an AC current source for simulation"),XIt=ei([jIt,zIt]).describe("Defines a current source for simulation"),$It=ei([xA("spice_dc_sweep"),xA("spice_dc_operating_point"),xA("spice_transient_analysis"),xA("spice_ac_analysis")]),Act=OA({type:xA("simulation_experiment"),simulation_experiment_id:Vt("simulation_experiment"),name:H(),experiment_type:$It,time_per_step:jBA.optional(),start_time_ms:VN.optional(),end_time_ms:VN.optional()}).describe("Defines a simulation experiment configuration"),ect=OA({type:xA("simulation_transient_voltage_graph"),simulation_transient_voltage_graph_id:Vt("simulation_transient_voltage_graph"),simulation_experiment_id:H(),timestamps_ms:be(WA()).optional(),voltage_levels:be(WA()),source_component_id:H().optional(),subcircuit_connectivity_map_key:H().optional(),time_per_step:jBA,start_time_ms:VN,end_time_ms:VN,name:H().optional(),color:H().optional()}).describe("Stores voltage measurements over time for a simulation"),tct=OA({type:xA("simulation_switch"),simulation_switch_id:Vt("simulation_switch"),source_component_id:H().optional(),closes_at:VN.optional(),opens_at:VN.optional(),starts_closed:ce().optional(),switching_frequency:r5.optional()}).describe("Defines a switch for simulation timing control"),ict=OA({type:xA("simulation_voltage_probe"),simulation_voltage_probe_id:Vt("simulation_voltage_probe"),source_component_id:H().optional(),name:H().optional(),signal_input_source_port_id:H().optional(),signal_input_source_net_id:H().optional(),reference_input_source_port_id:H().optional(),reference_input_source_net_id:H().optional(),subcircuit_id:H().optional(),color:H().optional()}).describe("Defines a voltage probe for simulation. If a reference input is not provided, it measures against ground. If a reference input is provided, it measures the differential voltage between two points.").superRefine((t,A)=>{if(t.reference_input_source_port_id||t.reference_input_source_net_id){const i=!!t.signal_input_source_port_id||!!t.reference_input_source_port_id,o=!!t.signal_input_source_net_id||!!t.reference_input_source_net_id;i&&o?A.addIssue({code:Ot.custom,message:"Cannot mix port and net connections in a differential probe."}):i?(!t.signal_input_source_port_id||!t.reference_input_source_port_id)&&A.addIssue({code:Ot.custom,message:"Differential port probe requires both signal_input_source_port_id and reference_input_source_port_id."}):o&&(!t.signal_input_source_net_id||!t.reference_input_source_net_id)&&A.addIssue({code:Ot.custom,message:"Differential net probe requires both signal_input_source_net_id and reference_input_source_net_id."})}else!!t.signal_input_source_port_id==!!t.signal_input_source_net_id&&A.addIssue({code:Ot.custom,message:"A voltage probe must have exactly one of signal_input_source_port_id or signal_input_source_net_id."})}),oct=OA({type:xA("simulation_unknown_experiment_error"),simulation_unknown_experiment_error_id:Vt("simulation_unknown_experiment_error"),error_type:xA("simulation_unknown_experiment_error").default("simulation_unknown_experiment_error"),message:H(),simulation_experiment_id:H().optional(),subcircuit_id:H().optional()}).describe("An unknown error occurred during the simulation experiment."),nct=OA({type:xA("simulation_op_amp"),simulation_op_amp_id:Vt("simulation_op_amp"),source_component_id:H().optional(),inverting_input_source_port_id:H(),non_inverting_input_source_port_id:H(),output_source_port_id:H(),positive_supply_source_port_id:H(),negative_supply_source_port_id:H()}).describe("Defines a simple ideal operational amplifier for simulation");ei([kat,bat,xat,Sat,Fat,Gat,pWA,hWA,XBA,dWA,uWA,fWA,yWA,wWA,SWA,bWA,xWA,MWA,kWA,GWA,FWA,RWA,DWA,mWA,Mat,_at,Rat,NWA,_WA,vWA,vat,Uat,Egt,hgt,mIt,DIt,SIt,kIt,mgt,uIt,Dgt,Zgt,Hgt,Kgt,Vgt,Rgt,Lgt,jgt,zgt,bIt,$gt,AIt,eIt,tIt,rIt,iIt,oIt,nIt,sIt,qgt,Pgt,Xgt,Ogt,Wgt,YIt,gIt,aIt,IIt,cIt,BIt,CIt,lIt,QIt,EIt,xIt,hIt,GIt,wIt,FIt,RIt,MIt,UIt,LIt,HIt,JIt,TIt,KIt,Lat,zat,Pat,Oat,Wat,Zat,qat,Xat,Vat,Hat,Agt,egt,$at,ngt,sgt,rgt,agt,cgt,ggt,Igt,qIt,ZIt,XIt,Act,ect,tct,ict,oct,nct]);var sct=Object.defineProperty,rct=(t,A)=>{for(var e in A)sct(t,e,{get:A[e],enumerable:!0})},hS={};rct(hS,{axial:()=>GBt,bga:()=>Hct,breakoutheaders:()=>KBt,cap:()=>lct,dfn:()=>cBt,diode:()=>Cct,dip:()=>Ict,electrolytic:()=>SQt,hc49:()=>PBt,jst:()=>Zlt,led:()=>Qct,lqfp:()=>JBt,m2host:()=>WQt,melf:()=>ilt,micromelf:()=>rlt,minimelf:()=>VCt,mlp:()=>Zct,ms012:()=>uBt,ms013:()=>pBt,msop:()=>oQt,pad:()=>OBt,pinrow:()=>lBt,platedhole:()=>LQt,potentiometer:()=>wQt,pushbutton:()=>_Bt,qfn:()=>Pct,qfp:()=>Wct,quad:()=>zN,radial:()=>MBt,res:()=>vct,sma:()=>clt,smb:()=>dlt,smbf:()=>xQt,smc:()=>wlt,smf:()=>Qlt,smtpad:()=>vQt,sod110:()=>jlt,sod123:()=>SBt,sod123f:()=>bCt,sod123fl:()=>FCt,sod123w:()=>rCt,sod128:()=>HCt,sod323:()=>cCt,sod323f:()=>wCt,sod323fl:()=>IQt,sod323w:()=>sQt,sod523:()=>zBt,sod723:()=>_Ct,sod80:()=>iCt,sod882:()=>dCt,sod882d:()=>$Ct,sod923:()=>QCt,soic:()=>Jct,solderjumper:()=>QQt,son:()=>lQt,sop8:()=>eCt,sot:()=>YQt,sot223:()=>blt,sot23:()=>oBt,sot23w:()=>vlt,sot25:()=>aBt,sot323:()=>RQt,sot343:()=>KQt,sot363:()=>ABt,sot457:()=>uQt,sot563:()=>EBt,sot723:()=>yBt,sot886:()=>tBt,sot89:()=>PCt,sot963:()=>pQt,ssop:()=>jct,stampboard:()=>UBt,stampreceiver:()=>YBt,to220:()=>WCt,to92:()=>VBt,to92l:()=>VQt,to92s:()=>Tlt,tqfp:()=>Oct,tssop:()=>Xct,vssop:()=>eQt});var Yi=(t,A,e)=>({type:"pcb_silkscreen_text",pcb_silkscreen_text_id:"silkscreen_text_1",font:"tscircuit2024",font_size:e,pcb_component_id:"pcb_component_1",text:"{REF}",layer:"top",anchor_position:{x:t,y:A},anchor_alignment:"center"}),Ji=OA({norefdes:ce().optional().describe("disable reference designator label"),invert:ce().optional().describe("hint to invert the orientation of the 3D model"),faceup:ce().optional().describe("The male pin header should face upwards, out of the top layer"),nosilkscreen:ce().optional().describe("omit all silkscreen elements from the footprint")}),qn=(t,A,e,i,o)=>({pcb_plated_hole_id:"",type:"pcb_plated_hole",shape:"circle",x:A,y:e,hole_diameter:mr(i),outer_diameter:mr(o),pcb_port_id:"",layers:["top","bottom"],port_hints:[t.toString()]}),uS=(t,A,e,i,o,n,s,r)=>({pcb_plated_hole_id:"",type:"pcb_plated_hole",shape:"circular_hole_with_rect_pad",x:A,y:e,hole_diameter:mr(i),hole_shape:"circle",pad_shape:"rect",rect_pad_width:mr(o),rect_pad_height:mr(n),pcb_port_id:"",layers:["top","bottom"],port_hints:[t.toString()],hole_offset_x:s,hole_offset_y:r}),OWA=Array.from({length:9},(t,A)=>Math.cos(A/8*Math.PI-Math.PI)).map(t=>({x:t,y:-Math.sqrt(1-t**2)}));function kx(t){return typeof t=="string"?t.trim().toLowerCase().endsWith("mil")?parseFloat(t)*.0254:parseFloat(t):Number(t)}var g5=ei([H(),WA()]).transform(t=>kx(t)),act=t=>Ji.extend({fn:H(),num_pins:WA().optional().default(6),wide:ce().optional(),narrow:ce().optional(),w:g5.optional(),p:g5.default(t.p??"2.54mm"),id:g5.optional(),od:g5.optional(),nosquareplating:ce().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=kx("0.55mm"),A.od=kx("0.95mm")):(A.id=kx("0.8mm"),A.od=kx("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=kx("600mil"):A.narrow?A.w=kx("300mil"):A.w=kx(t.w??"300mil")),A)),gct=act({}),WWA=(t,A,e,i,o)=>{const n=t/2,s=A<=n,r=n-1,a=i,g=a*r;return s?{x:-e/2,y:g/2-(A-1)*a}:{x:e/2,y:-g/2+(A-n-1)*a}},Ict=t=>{const A=gct.parse(t),e=[];for(let g=0;g<A.num_pins;g++){const{x:I,y:c}=WWA(A.num_pins,g+1,A.w,A.p??2.54,A.nosquareplating);if(g===0&&!A.nosquareplating){e.push(uS(g+1,I,c,A.id??"0.8mm",A.od??"1mm",A.od??"1mm"));continue}e.push(qn(g+1,I,c,A.id??"0.8mm",A.od??"1mm"))}(A.num_pins/2-1)*A.p+A.od;const o=A.w-A.od-1,n=(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:-o/2,y:-n/2},{x:-o/2,y:n/2},...OWA.map(({x:g,y:I})=>({x:g*o/6,y:I*o/6+n/2})),{x:o/2,y:n/2},{x:o/2,y:-n/2},{x:-o/2,y:-n/2}],type:"pcb_silkscreen_path",stroke_width:.1},r=[];for(let g=0;g<A.num_pins;g++){const I=g<A.num_pins/2,c=.6,{y:B}=WWA(A.num_pins,g+1,A.w,A.p??2.54,A.nosquareplating),C=I?-A.w/2-A.od/2-c:A.w/2+A.od/2+c,l=B;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:C,y:l},font_size:.3,font:"tscircuit2024",anchor_alignment:"top_left"})}const a=Yi(0,n/2+.5,.4);return{circuitJson:[...e,s,a,...r],parameters:A}},Qi=(t,A,e,i,o)=>({type:"pcb_smtpad",x:A,y:e,width:i,height:o,layer:"top",shape:"rect",pcb_smtpad_id:"",port_hints:Array.isArray(t)?t.map(n=>n.toString()):[t.toString()]}),ZWA=[{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}],cct=Object.fromEntries(ZWA.map(t=>[t.metric,t])),Bct=Object.fromEntries(ZWA.map(t=>[t.imperial,t]));Ji.extend({tht:ce(),p:Ae.optional(),pw:Ae.optional(),ph:Ae.optional(),metric:mt.optional(),imperial:mt.optional(),w:Ae.optional(),h:Ae.optional(),textbottom:ce().optional()});var I5=t=>{let{tht:A,p:e,pw:i,ph:o,metric:n,imperial:s,w:r,h:a,textbottom:g}=t;if(typeof r=="string"&&(r=yB(r)),typeof a=="string"&&(a=yB(a)),typeof e=="string"&&(e=yB(e)),typeof i=="string"&&(i=yB(i)),typeof o=="string"&&(o=yB(o)),a!==void 0&&r!==void 0&&a>r)throw new Error("height cannot be greater than width (rotated footprint not yet implemented)");let I;if(n&&(I=cct[n]),s&&(I=Bct[s]),I&&(r=I.w_mm_min,a=I.h_mm_min,e=I.p_mm_min,i=I.pw_mm_min,o=I.ph_mm_min),e===void 0||i===void 0||o===void 0)throw new Error("Could not determine required pad dimensions (p, pw, ph)");const c={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:e/2,y:o/2+.4},{x:-e/2-i/2-.2,y:o/2+.4},{x:-e/2-i/2-.2,y:-o/2-.4},{x:e/2,y:-o/2-.4}],stroke_width:.1,pcb_silkscreen_path_id:""},B=g?-o/2-.9:o/2+.9,C=Yi(0,B,.2);return A?[qn(1,-e/2,0,i,i*1/.8),qn(2,e/2,0,i,i*1/.8),c,C]:[Qi(["1","left"],-e/2,0,i,o),Qi(["2","right"],e/2,0,i,o),c,C]},Cct=t=>({circuitJson:I5(t),parameters:t}),lct=t=>({circuitJson:I5(t),parameters:t}),Qct=t=>({circuitJson:I5(t),parameters:t}),jN=t=>{const{padSpacing:A,padWidth:e,padHeight:i,padPitch:o,numRows:n,textbottom:s}=t,r=[],a=(n-1)*(o/2);for(let x=0;x<n;x++)r.push(a-x*o);const g=[];r.forEach((x,F)=>{g.push(Qi(F+1,-A/2,x,e,i))}),r.slice().reverse().forEach((x,F)=>{g.push(Qi(F+n+1,A/2,x,e,i))});const I=Math.max(...r)+i/2+.4,c=Math.min(...r)-i/2-.4,B=-A/2-e/2-.4,C=A/2+e/2+.4,l={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:C*.5,y:I},{x:B*.5,y:I}],stroke_width:.12,pcb_silkscreen_path_id:"silkscreen_top"},Q={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:C*.5,y:c},{x:B*.5,y:c}],stroke_width:.12,pcb_silkscreen_path_id:"silkscreen_bottom"},E=-A/2,h=Math.max(...r),u=.2,d=E-e/2-.1,f=h+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},b=s?c-.9:I+.9,D=Yi(0,b,.2);return[...g,l,Q,m,D]},Ect=Ji.extend({pw:H().default("0.5mm"),ph:H().default("0.4mm"),p:H().default("0.7mm"),textbottom:ce().optional()}),hct=1,uct=t=>{const A=Ect.parse(t),e=yB(A.pw),i=yB(A.ph),o=yB(A.p);return jN({padSpacing:hct,padWidth:e,padHeight:i,padPitch:o,numRows:2,textbottom:A.textbottom})},dct=Ji.extend({pw:H().default("0.5mm"),ph:H().default("0.32mm"),p:H().default("0.5mm"),textbottom:ce().optional()}),pct=1,fct=t=>{const A=dct.parse(t),e=yB(A.pw),i=yB(A.ph),o=yB(A.p);return jN({padSpacing:pct,padWidth:e,padHeight:i,padPitch:o,numRows:4,textbottom:A.textbottom})},yct=Ji.extend({pw:H().default("0.9mm"),ph:H().default("0.4mm"),p:H().default("0.8mm"),textbottom:ce().optional()}),wct=1.7,mct=t=>{const A=yct.parse(t),e=yB(A.pw),i=yB(A.ph),o=yB(A.p);return jN({padSpacing:wct,padWidth:e,padHeight:i,padPitch:o,numRows:2,textbottom:A.textbottom})},Dct=Ji.extend({pw:H().default("0.9mm"),ph:H().default("0.4mm"),p:H().default("0.8mm"),textbottom:ce().optional()}),Sct=1.7,bct=t=>{const A=Dct.parse(t),e=yB(A.pw),i=yB(A.ph),o=yB(A.p);return jN({padSpacing:Sct,padWidth:e,padHeight:i,padPitch:o,numRows:4,textbottom:A.textbottom})},xct=Ji.extend({pw:H().default("0.7mm"),ph:H().default("0.64mm"),p:H().default("0.94mm"),textbottom:ce().optional()}),kct=1.4,Gct=t=>{const A=xct.parse(t),e=yB(A.pw),i=yB(A.ph),o=yB(A.p);return jN({padSpacing:kct,padWidth:e,padHeight:i,padPitch:o,numRows:2,textbottom:A.textbottom})},Fct=Ji.extend({pw:H().default("0.9mm"),ph:H().default("0.9mm"),p:H().default("1.34mm"),textbottom:ce().optional()}),Rct=3,Mct=t=>{const A=Fct.parse(t),e=yB(A.pw),i=yB(A.ph),o=yB(A.p);return jN({padSpacing:Rct,padWidth:e,padHeight:i,padPitch:o,numRows:4,textbottom:A.textbottom})},Nct=t=>{const A=t.array??t.x;if(typeof A=="number")return Number.isNaN(A)?void 0:A;if(typeof A=="string"){const e=Number.parseInt(A,10);return Number.isNaN(e)?void 0:e}if(typeof t.imperial=="string"){const i=t.imperial.match(/(?:array|x)(2|4)$/)?.[1];if(i)return Number.parseInt(i,10)}},_ct=t=>t?(typeof t=="number"?`${t}`:t).split("_")[0]:void 0,vct=t=>{const A=Nct(t),e=_ct(t.imperial);return A===2&&e==="0402"?{circuitJson:uct(t),parameters:t}:A===4&&e==="0402"?{circuitJson:fct(t),parameters:t}:A===2&&e==="0603"?{circuitJson:mct(t),parameters:t}:A===4&&e==="0603"?{circuitJson:bct(t),parameters:t}:A===2&&e==="0606"?{circuitJson:Gct(t),parameters:t}:A===4&&e==="1206"?{circuitJson:Mct(t),parameters:t}:{circuitJson:I5(t),parameters:t}},VWA=(t,{x:A,y:e,radius:i})=>({type:"pcb_smtpad",x:A,y:e,radius:i,layer:"top",shape:"circle",pcb_smtpad_id:"",port_hints:Array.isArray(t)?t.map(o=>o.toString()):[t.toString()]}),jWA="ABCDEFGHIJKLMNOPQRSTUVWXYZ",zWA=H().transform(t=>{const[A,e]=t.split(/[x ]/);return{x:parseFloat(A),y:parseFloat(e)}}).pipe(OA({x:WA(),y:WA()})),Uct=H().or(be(HI())).transform(t=>Array.isArray(t)?t:(t.startsWith("(")&&t.endsWith(")")&&(t=t.slice(1,-1)),t.split(",").map(A=>{const e=Number(A);return isNaN(e)?A:e}))).pipe(be(H().or(WA()))),Lct=Ji.extend({fn:H(),num_pins:WA().optional().default(64),grid:zWA.optional(),p:mt.default("0.8mm"),w:Ae.optional(),h:Ae.optional(),ball:Ae.optional().describe("ball diameter"),pad:Ae.optional().describe("pad width/height"),circularpads:ce().optional().describe("use circular pads"),tlorigin:ce().optional(),blorigin:ce().optional(),trorigin:ce().optional(),brorigin:ce().optional(),missing:Uct.default([])}).transform(t=>{let A="tl";if(t.blorigin&&(A="bl"),t.trorigin&&(A="tr"),t.brorigin&&(A="br"),!t.grid){const i=Math.ceil(Math.sqrt(t.num_pins));t.grid={x:i,y:i}}return t.missing&&(t.missing=t.missing.map(i=>{if(typeof i=="number")return i;if(i==="center")return"center";if(i==="topleft")return"topleft";const o=i.match(/([A-Z]+)(\d+)/);if(!o)return i;const n=jWA.indexOf(o[1]),s=Number.parseInt(o[2])-1;return n*t.grid.x+s+1})),{...t,origin:A}}),Hct=t=>{const A=Lct.parse(t);let{num_pins:e,grid:i,p:o,w:n,h:s,ball:r,pad:a,missing:g}=A;r??=.75/1.27*o,a??=r*.8;const I=[],c=(g??[]).filter(m=>typeof m=="number"),B=i.x*i.y-e;if(g.length===0&&B>0&&(Math.sqrt(B)%1===0?g.push("center"):B===1&&g.push("topleft")),g?.includes("center")){const m=Math.floor(Math.sqrt(B)),b=Math.floor((i.x-m)/2),D=Math.floor((i.y-m)/2);for(let x=D;x<D+m;x++)for(let F=b;F<b+m;F++)c.push(x*i.x+F+1)}g?.includes("topleft")&&c.push(1);const C=new Set(c);let l=0;for(let m=0;m<i.y;m++)for(let b=0;b<i.x;b++){const D=(b-(i.x-1)/2)*o,x=(m-(i.y-1)/2)*o;let F=b,k=m;switch(A.origin){case"bl":F=b,k=i.y-1-m;break;case"br":F=i.x-1-b,k=i.y-1-m;break;case"tr":F=i.x-1-b,k=m;break}let v=k*i.x+F+1;if(C.has(v)){l++;continue}v-=l;const _=[v,`${jWA[k]}${F+1}`];I.push(A.circularpads?VWA(_,{x:D,y:x,radius:a/2}):Qi(_,D,x,a,a))}const Q=Yi(0,i.y*o/2,.2),E=o/6;let h;const u=i.x*o/2,d=i.y*o/2;switch(A.origin){case"bl":h=[{x:-u,y:-d},{x:-u,y:-d-E},{x:-u-E,y:-d},{x:-u,y:-d}];break;case"br":h=[{x:u,y:-d},{x:u,y:-d-E},{x:u+E,y:-d},{x:u,y:-d}];break;case"tr":h=[{x:u,y:d},{x:u,y:d+E},{x:u+E,y:d},{x:u,y:d}];break;default:h=[{x:-u,y:d},{x:-u,y:d+E},{x:-u-E,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:h,stroke_width:.05};return{circuitJson:[...I,Q,f],parameters:A}},c5=(t,A,e,i,o)=>({type:"pcb_smtpad",x:A,y:e,width:i,height:o,radius:o/2,layer:"top",shape:"pill",pcb_smtpad_id:"",port_hints:Array.isArray(t)?t.map(n=>n.toString()):[t.toString()]}),Rm=t=>Ji.extend({fn:H(),num_pins:WA().optional().default(8),w:Ae.default(Ae.parse(t.w??"5.3mm")),p:Ae.default(Ae.parse(t.p??"1.27mm")),pw:Ae.default(Ae.parse(t.pw??"0.6mm")),pl:Ae.default(Ae.parse(t.pl??"1.0mm")),legsoutside:ce().optional().default(t.legsoutside??!1),pillpads:ce().optional().default(t.pillpads??!1),silkscreen_stroke_width:WA().optional().default(.1)}).transform(A=>(!A.pw&&!A.pl?(A.pw=Ae.parse("0.6mm"),A.pl=Ae.parse("1.0mm")):A.pw?A.pl||(A.pl=A.pw*(1/.6)):A.pw=A.pl*(.6/1),A)),Yct=Rm({}),eCA=t=>{t.widthincludeslegs!==void 0&&(t.legsoutside=!t.widthincludeslegs);const{num_pins:A,pn:e,w:i,p:o,pl:n,legsoutside:s}=t,r=A/2,a=e<=r,g=r-1,I=o,c=I*g,B=s?n/2:-n/2;return a?{x:-i/2-B,y:c/2-(e-1)*I}:{x:i/2+B,y:-c/2+(e-r-1)*I}},Jct=t=>{const A=Yct.parse(t);return{circuitJson:Gx(A),parameters:A}},Gx=t=>{const A=[];for(let r=0;r<t.num_pins;r++){const{x:a,y:g}=eCA({num_pins:t.num_pins,pn:r+1,w:t.w,p:t.p,pl:t.pl,legsoutside:t.legsoutside});t.pillpads?A.push(c5(r+1,a,g,t.pl,t.pw)):A.push(Qi(r+1,a,g,t.pl,t.pw))}const e=Math.min(1,t.p/2),i=t.w-(t.legsoutside?0:t.pl*2)-.2,o=(t.num_pins/2-1)*t.p+t.pw+e,n=Yi(0,o/2+.4,o/12),s={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",stroke_width:t.silkscreen_stroke_width??.1,route:[{x:-i/2,y:-o/2},{x:-i/2,y:o/2},...OWA.map(({x:r,y:a})=>({x:r*i/6,y:a*i/6+o/2})),{x:i/2,y:o/2},{x:i/2,y:-o/2},{x:-i/2,y:-o/2}]};return[...A,s,n]},XWA=Bt(["leftside","topside","rightside","bottomside","toppin","bottompin","leftpin","rightpin"]),Tct=({num_pins:t,cw:A,ccw:e,startingpin:i})=>{const o=[],n=t/4;let s=1;const r={};for(const a of i??[])r[a]=!0;!r.leftside&&!r.topside&&!r.rightside&&!r.bottomside&&(r.leftside=!0),!r.bottompin&&!r.leftpin&&!r.rightpin&&!r.toppin&&(r.leftside?r.toppin=!0:r.topside?r.rightpin=!0:r.rightside?r.bottompin=!0:r.bottomside&&(r.leftpin=!0)),r.leftside&&r.toppin?s=1:r.leftside&&r.bottompin?s=n:r.bottomside&&r.leftpin?s=n+1:r.bottomside&&r.rightpin?s=n*2:r.rightside&&r.bottompin?s=n*2+1:r.rightside&&r.toppin?s=n*3:r.topside&&r.rightpin?s=n*3+1:r.topside&&r.leftpin&&(s=n*4),o.push(-1);for(let a=0;a<t;a++)o[s]=a+1,e||!A?(s++,s>t&&(s=1)):(s--,s<1&&(s=t));return o},tCA=Ji.extend({fn:H(),cc:ce().default(!0).optional(),ccw:ce().default(!0).optional(),startingpin:H().or(be(XWA)).transform(t=>typeof t=="string"?t.slice(1,-1).split(","):t).pipe(be(XWA)).optional(),num_pins:WA().optional().default(64),w:Ae.optional(),h:Ae.optional(),p:Ae.default(Ae.parse("0.5mm")),pw:Ae.optional(),pl:Ae.optional(),thermalpad:ei([xA(!0),zWA]).optional(),legsoutside:ce().default(!1)}),iCA=t=>{t.w&&!t.h?t.h=t.w:!t.w&&t.h&&(t.w=t.h);const A=t.num_pins/4;if(!t.p&&!t.pw&&!t.pl&&t.w){const e=A+4;t.p=t.w/e}return!t.p&&t.w&&t.h&&t.pw&&t.pl&&(t.p=(t.w-t.pl*2)/(A-1)),!t.w&&!t.h&&t.p&&(t.w=t.p*(A+4),t.h=t.w),t.p&&!t.pw&&!t.pl?(t.pw=t.p/2,t.pl=t.p/2):t.pw?t.pl||(t.pl=t.pw*(1/.6)):t.pw=t.pl*(.6/1),t},$WA=tCA.transform(iCA),Kct=["left","bottom","right","top"],qct=t=>{const{pin_count:A,pn:e,w:i,h:o,p:n,pl:s,legsoutside:r}=t,a=A/4,g=Kct[Math.floor((e-1)/a)],I=(e-1)%a,c=n*(a-1),B=n*(a-1),C=r?s/2:-s/2;switch(g){case"left":return{x:-i/2-C+.1,y:B/2-I*n,o:"vert"};case"bottom":return{x:-c/2+I*n,y:-o/2-C+.1,o:"horz"};case"right":return{x:i/2+C-.1,y:-B/2+I*n,o:"vert"};case"top":return{x:c/2-I*n,y:o/2+C-.1,o:"horz"};default:throw new Error("Invalid pin number")}},zN=t=>{const A=$WA.parse(t),e=[],i=Tct(A),o=A.num_pins/4;for(let r=0;r<A.num_pins;r++){const{x:a,y:g,o:I}=qct({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 c=A.pw,B=A.pl;I==="vert"&&([c,B]=[B,c]);const C=i[r+1];e.push(Qi(C,a,g,c,B))}if(A.thermalpad)if(typeof A.thermalpad=="boolean"){const r=A.p*(o-1)+A.pw,a=A.p*(o-1)+A.pw;e.push(Qi(["thermalpad"],0,0,r,a))}else e.push(Qi(["thermalpad"],0,0,A.thermalpad.x,A.thermalpad.y));const n=[];for(const[r,a,g]of[["top-left",-1,1],["bottom-left",-1,-1],["bottom-right",1,-1],["top-right",1,1]]){const I=A.w/2*a,c=A.h/2*g;let B="none",C=I,l=c;const Q=A.pw*2;i[1]===1&&r==="top-left"?B="in1":i[o*4]===1&&r==="top-left"||i[o*3+1]===1&&r==="top-right"?B="in2":i[o*3]===1&&r==="top-right"||i[o]===1&&r==="bottom-left"?B="in1":i[o+1]===1&&r==="bottom-left"?B="in2":i[o*2]===1&&r==="bottom-right"?B="in1":i[o*2+1]===1&&r==="bottom-right"&&(B="in2");const E=B==="in1"?1:-1;if(A.legsoutside){const h=B==="in1"?A.pl/2:A.pw/2,u=B==="in1"?A.pw/2:A.pl/2;C+=h*a*E,l-=u*g*E}(B==="none"||A.legsoutside)&&n.push({layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:`pcb_silkscreen_path_${r}`,route:[{x:I-Q*a,y:c},{x:I,y:c},{x:I,y:c-Q*g}],type:"pcb_silkscreen_path",stroke_width:.1}),(B==="in1"||B==="in2")&&!A.legsoutside&&n.push({layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:`pcb_silkscreen_path_${r}_1`,route:[{x:I-Q*a,y:c},{x:I-Q*a/2,y:c}],type:"pcb_silkscreen_path",stroke_width:0},{layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:`pcb_silkscreen_path_${r}_2`,route:[{x:I,y:c-Q*g/2},{x:I,y:c-Q*g}],type:"pcb_silkscreen_path",stroke_width:.1}),(B==="in1"||B==="in2")&&n.push({layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:`pcb_silkscreen_path_${r}_3`,route:[{x:C-.2*-a,y:l+.2*E},{x:C,y:l},{x:C+.2*E*-a,y:l+.2},{x:C-.2*-a,y:l+.2*E}],type:"pcb_silkscreen_path",stroke_width:.1})}const s=Yi(0,A.h/2+(A.legsoutside?A.pl*1.2:.5),.3);return{circuitJson:[...e,...n,s],parameters:A}};tCA.extend({}).transform(iCA);var Pct=t=>(t.legsoutside=!1,t.pl||(t.pl=.875),t.pw||(t.pw=.25),zN(t)),Oct=t=>{if(t.legsoutside=!0,!t.p)switch(t.num_pins){case 32:t.p=.8;break;case 44:case 48:t.p=.5;break;case 64:case 80:case 100:t.p=.5;break;case 144:t.p=.5;break}if(!t.pl)switch(t.num_pins){case 32:case 44:case 48:case 64:case 80:case 100:t.pl=1.475;break;case 144:t.pl=1.6;break}if(!t.pw)switch(t.num_pins){case 32:t.pw=.55;break;case 44:case 48:case 64:case 80:case 100:t.pw=.3;break;case 144:t.pw=.25;break}return zN(t)},Wct=t=>{t.legsoutside=!0;const A=$WA.parse(t);if(!t.p)switch(t.num_pins){case 44:case 64:t.p=.8;break;case 52:t.w===14?t.p=1:t.p=.65;break;case 208:t.p=.5;break}if(!t.pl)switch(t.num_pins){case 44:case 52:case 64:t.pl=2.25;break;case 208:t.pl=1.65;break;default:t.pl=A.pl*4;break}if(!t.pw)switch(t.num_pins){case 44:case 64:t.pw=.5;break;case 52:t.w===14?t.pw=.45:t.pw=.55;break;case 208:t.pw=.3;break;default:t.pw=A.pw;break}return zN(t)};tCA.extend({}).transform(iCA);var Zct=t=>(t.legsoutside=!1,t.thermalpad===void 0&&(t.thermalpad=!0),zN(t)),Vct=Rm({w:"3.9mm",p:"1.27mm"}),jct=t=>{const A=Vct.parse(t);return{circuitJson:Gx(A),parameters:A}},zct=Rm({w:"7.1mm",p:"0.65mm",pl:"1.35mm",pw:"0.40mm",legsoutside:!0}),Xct=t=>{const A=zct.parse(t);return{circuitJson:Gx(A),parameters:A}},$ct=Rm({}),ABt=t=>{const A=$ct.parse({fn:"sot363",num_pins:6,w:2.56,p:.65,pw:.4,pl:.65,legoutside:!0});return{circuitJson:Gx(A),parameters:A}},eBt=Ji.extend({fn:H(),num_pins:xA(6).default(6),w:H().default("1.01mm"),h:H().default("1.45mm"),p:H().default("0.5mm"),pl:H().default("0.33mm"),pw:H().default("0.27mm"),string:H().optional()}),tBt=t=>{const A=eBt.parse({fn:"sot886",...t}),e=Ae.parse(A.w),i=Ae.parse(A.h),o=Ae.parse(A.p),n=Ae.parse(A.pl),s=Ae.parse(A.pw),r=[];for(let C=0;C<6;C++){const{x:l,y:Q}=AZA(C+1,e,o,n);r.push(Qi(C+1,l,Q,n,s))}const a={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-e/2,y:i/2},{x:e/2,y:i/2}],stroke_width:.05,pcb_silkscreen_path_id:""},g={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-e/2,y:-i/2},{x:e/2,y:-i/2}],stroke_width:.05,pcb_silkscreen_path_id:""},I=AZA(1,e,o,n),c={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"pin_marker_1",route:[{x:I.x-n/2-.3,y:I.y},{x:I.x-n/2-.45,y:I.y+.15},{x:I.x-n/2-.45,y:I.y-.15},{x:I.x-n/2-.3,y:I.y}],stroke_width:.05,pcb_silkscreen_path_id:"pin_marker_1"},B=Yi(0,i/2+.4,.25);return{circuitJson:[...r,a,g,B,c],parameters:A}},AZA=(t,A,e,i)=>{const o=A/2-i/2;return t<=3?{x:-o,y:e-(t-1)*e}:{x:o,y:-e+(t-4)*e}},eZA=Ji.extend({fn:H(),num_pins:WA().default(3),w:H().default("1.92mm"),h:H().default("2.74mm"),pl:H().default("1.32mm"),pw:H().default("0.6mm"),p:H().default("0.95mm"),string:H().optional()}),iBt=Rm({p:"0.95mm",w:"1.6mm",legsoutside:!0}),oBt=t=>{const A=t.string?.match(/^sot23_(\d+)/),e=A?Number.parseInt(A[1],10):3;if(e===6||e===8){const o=iBt.parse({...t,num_pins:e});return{circuitJson:Gx(o),parameters:o}}const i=eZA.parse({...t,num_pins:e});if(i.num_pins===3)return{circuitJson:sBt(i),parameters:i};if(i.num_pins===5)return{circuitJson:iZA(i),parameters:i};throw new Error("Invalid number of pins")},nBt=t=>{const{pn:A,p:e}=t;return A===1?{x:-1.155,y:e}:A===2?{x:-1.155,y:-e}:{x:1.15,y:0}},sBt=t=>{const A=[];for(let i=0;i<t.num_pins;i++){const{x:o,y:n}=nBt({num_pins:t.num_pins,pn:i+1,w:Number.parseFloat(t.w),h:Number.parseFloat(t.h),pl:Number.parseFloat(t.pl),p:Number.parseFloat(t.p)});A.push(Qi(i+1,o,n,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}const e=Yi(0,Number.parseInt(t.h),.3);return[...A,e]},tZA=t=>{const{p:A,h:e,pn:i}=t;if(i===1)return{x:-e/2-.5,y:A};if(i===2)return{x:-e/2-.5,y:0};if(i===3)return{x:-e/2-.5,y:-A};if(i===4)return{x:e/2+.5,y:-A};if(i===5)return{x:e/2+.5,y:A};throw new Error("Invalid pin number")},iZA=t=>{const A=[];for(let c=1;c<=t.num_pins;c++){const{x:B,y:C}=tZA({h:Number.parseFloat(t.h),p:Number.parseFloat(t.p),pn:c});A.push(Qi(c,B,C,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}const e=(t.num_pins+1)/2*Number.parseFloat(t.p),i=Number.parseFloat(t.h),o={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-e/3,y:i/2+Number.parseFloat(t.p)/1.3},{x:e/3,y:i/2+Number.parseFloat(t.p)/1.3}],type:"pcb_silkscreen_path",stroke_width:.05},n={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_2",route:[{x:-e/3,y:-i/2-Number.parseFloat(t.p)/1.3},{x:e/3,y:-i/2-Number.parseFloat(t.p)/1.3}],type:"pcb_silkscreen_path",stroke_width:.05},s=Yi(0,i+.3,.3),r=tZA({h:Number.parseFloat(t.h),p:Number.parseFloat(t.p),pn:1});r.x=r.x-Number.parseFloat(t.pw)*1.5;const a=.3,g=.4,I={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,o,n,I]},rBt=eZA.extend({}),aBt=t=>{const A=rBt.parse({...t,num_pins:5});return{circuitJson:iZA(A),parameters:A}},gBt=[{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}],IBt=Rm({}),cBt=t=>{const A=IBt.parse(t),e=[];for(let c=0;c<A.num_pins;c++){const{x:B,y:C}=eCA({num_pins:A.num_pins,pn:c+1,w:A.w,p:A.p??1.27,pl:A.pl,widthincludeslegs:!0});e.push(Qi(c+1,B,C,A.pl??"1mm",A.pw??"0.6mm"))}const i=Math.min(1,A.p/2),o=A.w+i,n=(A.num_pins/2-1)*A.p+A.pw+i,s=[];for(const c of gBt){const{dx:B,dy:C}=c;s.push({layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"",route:[{x:B*o/2-B*A.p,y:C*n/2},{x:B*o/2,y:C*n/2},{x:B*o/2,y:C*n/2-C*A.p}],type:"pcb_silkscreen_path",stroke_width:.1})}const r=A.p/4,a=-o/2-r/2,g=n/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 I=Yi(0,n/2+.4,n/12);return{circuitJson:[...e,I,...s],parameters:A}},oCA=({fs:t,pn:A,anchor_x:e,anchor_y:i,textalign:o="center",orthogonal:n=!1,verticallyinverted:s=!1,layer:r="top"})=>{let a=0;n&&s?a=270:s?a=180:n?a=90:a=0;let g="center";return o==="left"&&(s?g="center_right":g="center_left"),o==="right"&&(s?g="center_left":g="center_right"),r==="bottom"&&(g==="center_left"?g="center_right":g==="center_right"&&(g="center_left")),{type:"pcb_silkscreen_text",pcb_silkscreen_text_id:"silkscreen_text_1",font:"tscircuit2024",font_size:t,pcb_component_id:"pcb_component_1",text:`{PIN${A}}`,layer:r,anchor_position:{x:e,y:i},anchor_alignment:g,ccw_rotation:a}};function BBt({pinlabeltextalignleft:t,pinlabeltextalignright:A,pinlabelorthogonal:e}){let i="top";return e?i="left":i="top",t&&(e?i="bottom":i="right"),A&&(e?i="top":i="left"),i}var CBt=Ji.extend({fn:H(),num_pins:WA().optional().default(6),rows:ei([H(),WA()]).transform(t=>Number(t)).optional().default(1).describe("number of rows"),p:Ae.default("0.1in").describe("pitch"),id:Ae.default("1.0mm").describe("inner diameter"),od:Ae.default("1.5mm").describe("outer diameter"),male:ce().optional().describe("for male pin headers"),female:ce().optional().describe("for female pin headers"),smd:ce().optional().describe("surface mount device"),surfacemount:ce().optional().describe("surface mount device (verbose)"),rightangle:ce().optional().describe("right angle"),pw:Ae.optional().default("1.0mm").describe("pad width for SMD"),pl:Ae.optional().default("2.0mm").describe("pad length for SMD"),pinlabeltextalignleft:ce().optional().default(!1),pinlabeltextaligncenter:ce().optional().default(!1),pinlabeltextalignright:ce().optional().default(!1),pinlabelverticallyinverted:ce().optional().default(!1),pinlabelorthogonal:ce().optional().default(!1),nosquareplating:ce().optional().default(!1).describe("do not use rectangular pad for pin 1"),nopinlabels:ce().optional().default(!1).describe("omit silkscreen pin labels"),doublesidedpinlabel:ce().optional().default(!1).describe("add silkscreen pins in top and bottom layers"),bottomsidepinlabel:ce().optional().default(!1).describe("place the silkscreen reference text on the bottom layer instead of top")}).transform(t=>{const A=BBt(t);return{...t,pinlabelAnchorSide:A,male:t.male??!t.female,female:t.female??!1,smd:t.smd??t.surfacemount??!1,rightangle:t.rightangle??!1}}).superRefine((t,A)=>{t.male&&t.female&&A.addIssue({code:Ot.custom,message:"'male' and 'female' cannot both be true; it should be male or female.",path:["male","female"]})}),lBt=t=>{const A=CBt.parse(t),{p:e,id:i,od:o,rows:n,num_pins:s,pinlabelAnchorSide:r,pinlabelverticallyinverted:a,pinlabelorthogonal:g,pinlabeltextalignleft:I,pinlabeltextalignright:c,nopinlabels:B,doublesidedpinlabel:C,bottomsidepinlabel:l}=A;let Q="center";I?Q="left":c&&(Q="right");const E=[],h=Math.ceil(s/n),u=-e,d=({xoff:x,yoff:F,od:k,anchorSide:v,smd:_,pw:Y,pl:P})=>{let T=0,O=0;if(_){const W=k/5;switch(v){case"right":T=Y/2+W;break;case"top":O=P/2+W;break;case"bottom":O=-(P/2+W);break;case"left":T=-(Y/2+W);break}}else{const W=k*.75;switch(v){case"right":T=W;break;case"top":O=W;break;case"bottom":O=-W;break;case"left":T=-W;break}}return{anchor_x:x+T,anchor_y:F+O}},f=(x,F,k)=>{A.smd?E.push(Qi(x,F,k,A.pw,A.pl)):x===1&&!A.nosquareplating?E.push(uS(x,F,k,i,o,o,0,0)):E.push(qn(x,F,k,i,o));const{anchor_x:v,anchor_y:_}=d({xoff:F,yoff:k,od:o,anchorSide:r,smd:A.smd,pw:A.pw,pl:A.pl});B||(l?E.push(oCA({fs:o/5,pn:x,anchor_x:v,anchor_y:_,textalign:Q,orthogonal:g,verticallyinverted:a,layer:"bottom"})):E.push(oCA({fs:o/5,pn:x,anchor_x:v,anchor_y:_,textalign:Q,orthogonal:g,verticallyinverted:a,layer:"top"})),C&&E.push(oCA({fs:o/5,pn:x,anchor_x:v,anchor_y:_,textalign:Q,orthogonal:g,verticallyinverted:a,layer:"bottom"})))},m=new Set,b=n>2&&h>2;if(n===1){const x=-((s-1)/2)*e;for(let F=0;F<s;F++){const k=F+1,v=x+F*e,_=`${v},0`;if(m.has(_))throw new Error(`Overlap at ${_}`);m.add(_),f(k,v,0)}}else if(b){const x=-((h-1)/2)*e;let F=1;for(let k=0;k<n&&F<=s;k++)for(let v=0;v<h&&F<=s;v++){const _=x+v*e,Y=k*u,P=`${_},${Y}`;if(m.has(P))throw new Error(`Overlap at ${P}`);m.add(P),f(F++,_,Y)}}else{const x=-((h-1)/2)*e;let F=1,k=0,v=n-1,_=0,Y=h-1;for(;F<=s&&k<=v&&_<=Y;){for(let P=k;P<=v&&F<=s;P++){const T=x+_*e,O=P*u,W=`${T},${O}`;if(m.has(W))throw new Error(`Overlap at ${W}`);m.add(W),f(F++,T,O)}_++;for(let P=_;P<=Y&&F<=s;P++){const T=x+P*e,O=v*u,W=`${T},${O}`;if(m.has(W))throw new Error(`Overlap at ${W}`);m.add(W),f(F++,T,O)}if(v--,_<=Y){for(let P=v;P>=k&&F<=s;P--){const T=x+Y*e,O=P*u,W=`${T},${O}`;if(m.has(W))throw new Error(`Overlap at ${W}`);m.add(W),f(F++,T,O)}Y--}if(k<=v){for(let P=Y;P>=_&&F<=s;P--){const T=x+P*e,O=k*u,W=`${T},${O}`;if(m.has(W))throw new Error(`Overlap at ${W}`);m.add(W),f(F++,T,O)}k++}}if(F-1<s)throw new Error(`Missing pins: assigned ${F-1}, expected ${s}`)}const D=Yi(0,e,.5);return{circuitJson:[...E,D],parameters:A}},QBt=Ji.extend({fn:H(),num_pins:xA(6).default(6),w:H().default("2.1mm"),h:H().default("2.45mm"),p:H().default("0.5mm"),pl:H().default("0.675mm"),pw:H().default("0.35mm"),string:H().optional()}),EBt=t=>{const A=QBt.parse({...t,fn:"sot563"}),e=Ae.parse(A.w),i=Ae.parse(A.h),o=Ae.parse(A.p),n=Ae.parse(A.pl),s=Ae.parse(A.pw),r=[];for(let C=0;C<6;C++){const{x:l,y:Q}=oZA(C+1,e,o,n);r.push(Qi(C+1,l,Q,n,s))}const a={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-e/2,y:i/2},{x:e/2,y:i/2}],stroke_width:.05,pcb_silkscreen_path_id:""},g={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-e/2,y:-i/2},{x:e/2,y:-i/2}],stroke_width:.05,pcb_silkscreen_path_id:""},I=oZA(1,e,o,n),c={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"pin_marker_1",route:[{x:I.x-n/2-.3,y:I.y},{x:I.x-n/2-.45,y:I.y+.15},{x:I.x-n/2-.45,y:I.y-.15},{x:I.x-n/2-.3,y:I.y}],stroke_width:.05,pcb_silkscreen_path_id:"pin_marker_1"},B=Yi(0,i/2+.4,.25);return{circuitJson:[...r,a,g,B,c],parameters:A}},oZA=(t,A,e,i)=>{const o=A/2-i/2;return t<=3?{x:-o,y:e-(t-1)*e}:{x:o,y:-e+(t-4)*e}},hBt=Rm({p:"1.27mm",w:"3.9mm",legsoutside:!0}),uBt=t=>{const A=hBt.parse({...t,num_pins:8});return{circuitJson:Gx(A),parameters:A}},dBt=Rm({p:"1.27mm",w:"7.5mm",legsoutside:!0}),pBt=t=>{const A=dBt.parse({...t,num_pins:16});return{circuitJson:Gx(A),parameters:A}},fBt=Ji.extend({fn:H(),num_pins:xA(3).default(3),w:H().default("1.2mm"),h:H().default("1.2mm"),pw:H().default("0.40mm"),pl:H().default("0.45mm"),p:H().default("0.575mm")}),yBt=t=>{const A=fBt.parse(t),e=mBt(A),i=Yi(0,Ae.parse(A.h),.2);return{circuitJson:[...e,i],parameters:A}},wBt=t=>{const{pn:A,p:e}=t;return A===1?{x:e,y:0}:A===2?{x:-e,y:-.4}:{x:-e,y:.4}},mBt=t=>{const A=[];for(let e=0;e<3;e++){const{x:i,y:o}=wBt({num_pins:t.num_pins,pn:e+1,w:Number.parseFloat(t.w),h:Number.parseFloat(t.h),pl:Number.parseFloat(t.pl),p:Number.parseFloat(t.p)});A.push(Qi(e+1,i,o,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},DBt=Ji.extend({fn:H(),num_pins:xA(2).default(2),w:H().default("2.36mm"),h:H().default("1.22mm"),pl:H().default("0.9mm"),pw:H().default("1.2mm"),p:H().default("3.30mm")}),SBt=t=>{const A=DBt.parse(t),e=Yi(0,Ae.parse(A.h)/4+.4,.3);return{circuitJson:xBt(A).concat(e),parameters:A}},bBt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},xBt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:o}=bBt({pn:e,p:Number.parseFloat(t.p)});A.push(Qi(e,i,o,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},kBt=Ji.extend({fn:H(),p:Ae.optional().default("2.54mm"),id:Ae.optional().default("0.7mm"),od:Ae.optional().default("1.4mm")}),GBt=t=>{const A=kBt.parse(t),{p:e,id:i,od:o}=A,n=[qn(1,-e/2,0,i,o),qn(2,e/2,0,i,o)],s={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-e/2+o+i/2,y:0},{x:e/2-o-i/2,y:0}],stroke_width:.1,pcb_silkscreen_path_id:""},r=Yi(0,1.5,.5);return{circuitJson:[...n,s,r],parameters:A}},FBt=(t,A,e,i,o,n=.1)=>{const s=[],r=[],a=Math.max(1,Math.ceil(Math.PI*e/n)),g=Math.PI/a;for(let I=0;I<=a;I++){const c=I*g,B=t+Math.cos(c)*e,C=A+Math.sin(c)*e;B<t-i&&C>=A-o/2&&C<=A+o/2||s.push({x:B,y:C})}for(let I=0;I<=a;I++){const c=Math.PI+I*g,B=t+Math.cos(c)*e,C=A+Math.sin(c)*e;B<t-i&&C>=A-o/2&&C<=A+o/2||r.push({x:B,y:C})}return{topArc:s,bottomArc:r}},RBt=Ji.extend({fn:H(),p:Ae.optional().default("5mm"),id:Ae.optional().default("0.8mm"),od:Ae.optional().default("1.6mm"),ceramic:ce().optional(),electrolytic:ce().optional(),polarized:ce().optional()}),MBt=t=>{const A=RBt.parse(t),{p:e,id:i,od:o}=A;i===.8&&o===1.6&&(A.id=e===5?.8:e*.25,A.od=e===5?1.6:e*.5);const n=[qn(1,-e/2,0,A.id,A.od),qn(2,e/2,0,A.id,A.od)],s=e+.1,{topArc:r,bottomArc:a}=FBt(0,0,s,A.od/2,A.od),g=.02*e,I={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:r,stroke_width:g,pcb_silkscreen_path_id:""},c={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:a,stroke_width:g,pcb_silkscreen_path_id:""},B={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:""},C=.1*e,l=-(e+C+.04*e),Q=s-C-.08*e,E={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:l-C,y:Q},{x:l+C,y:Q}],stroke_width:g,pcb_silkscreen_path_id:""},h={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:l,y:Q-C},{x:l,y:Q+C}],stroke_width:g,pcb_silkscreen_path_id:""},u=Yi(0,s+.12*e,.1*e),d=[...n,I,c,B,u];return(A.electrolytic===!0||A.polarized===!0)&&d.push(E,h),{circuitJson:d,parameters:A}},B5=(t,A={})=>({type:"pcb_silkscreen_path",layer:A.layer||"top",pcb_component_id:A.pcb_component_id||"",pcb_silkscreen_path_id:A.pcb_silkscreen_path_id||"",route:t,stroke_width:A.stroke_width||.1}),NBt=Ji.extend({fn:xA("pushbutton"),w:Ae.default(4.5),h:Ae.default(6.5),id:Ae.default(1),od:Ae.default(1.2)}),_Bt=t=>{const A=NBt.parse(t),e=A.w,i=A.h,o=A.id,n=[qn(1,-e/2,i/2,o,o*1.5),qn(2,-e/2,-i/2,o,o*1.5),qn(3,e/2,-i/2,o,o*1.5),qn(4,e/2,i/2,o,o*1.5)],s=[B5([{x:-e/2,y:-i/2},{x:-e/2,y:i/2}]),B5([{x:e/2,y:-i/2},{x:e/2,y:i/2}]),B5([{x:-e/2,y:0},{x:-e/5,y:0},{x:e/5*1/Math.sqrt(2),y:i/8}]),B5([{x:e/2,y:0},{x:e/5,y:0}])],r=Yi(0,i/2+.4,.5);return{circuitJson:[...n,...s,r],parameters:A}},nZA=Ji.extend({fn:H(),w:Ae.default("22.58mm"),h:Ae.optional(),left:Ae.optional().default(20),right:Ae.optional().default(20),top:Ae.optional().default(2),bottom:Ae.optional().default(2),p:Ae.default(Ae.parse("2.54mm")),pw:Ae.default(Ae.parse("1.6mm")),pl:Ae.default(Ae.parse("2.4mm")),innerhole:ce().default(!1),innerholeedgedistance:Ae.default(Ae.parse("1.61mm")),silkscreenlabels:ce().default(!1),silkscreenlabelmargin:Ae.default(Ae.parse("0.1mm"))}),vBt=t=>{const A=nZA.parse(t);return A.left&&A.right?Math.max(A.left,A.right)*A.p:A.left?A.left*A.p:A.right?A.right*A.p:51},C5=(t,A,e)=>{let i=[];return e==="right"&&(i=[{x:t+1/2,y:A},{x:t-1/2,y:A+.6/2},{x:t-1/2,y:A-.6/2},{x:t+1/2,y:A}]),e==="left"&&(i=[{x:t-1/2,y:A},{x:t+1/2,y:A+.6/2},{x:t+1/2,y:A-.6/2},{x:t-1/2,y:A}]),e==="top"&&(i=[{x:t,y:A+1/2},{x:t-.6/2,y:A-1/2},{x:t+.6/2,y:A-1/2},{x:t,y:A+1/2}]),e==="bottom"&&(i=[{x:t,y:A-1/2},{x:t-.6/2,y:A+1/2},{x:t+.6/2,y:A+1/2},{x:t,y:A-1/2}]),i},UBt=t=>{const A=nZA.parse(t),e=A.h??vBt(A),i=[],o=[],n=[];let s=[];const r=1,a=r,g=A.left+A.right+(A.bottom??0)+(A.top??0),c=`pin${g}`.length*.7/2;if(A.right){const Q=-((A.right-1)/2)*A.p;for(let E=0;E<A.right;E++){if(E===0&&!A.left&&!A.bottom&&!A.silkscreenlabels&&(s=C5(A.w/2-A.pl*1.4,Q+E*A.p,"right")),i.push(Qi(E+1+A.left+(A.bottom??0),A.w/2-A.pl/2,Q+E*A.p,A.pl,A.pw)),A.silkscreenlabels){const h=E+1+A.left+(A.bottom??0),u=`pin${h}`;n.push({type:"pcb_silkscreen_text",pcb_silkscreen_text_id:`pin_${h}`,pcb_component_id:"1",layer:"top",anchor_position:{x:A.w/2-A.pl-(c+A.silkscreenlabelmargin),y:Q+E*A.p},text:u,font_size:.7,font:"tscircuit2024",anchor_alignment:"center"})}A.innerhole&&(o.push(qn(E+1+A.left+(A.bottom??0)+g,A.w/2,Q+E*A.p,r,a)),o.push(qn(E+1+A.left+(A.bottom??0)+g*2,A.w/2-A.innerholeedgedistance,Q+E*A.p,r,a)))}}if(A.left){const Q=(A.left-1)/2*A.p;for(let E=0;E<A.left;E++){if(E===0&&!A.silkscreenlabels&&(s=C5(-A.w/2+A.pl*1.4,Q-E*A.p,"left")),i.push(Qi(E+1,-A.w/2+A.pl/2,Q-E*A.p,A.pl,A.pw)),A.silkscreenlabels){const h=E+1,u=`pin${h}`;n.push({type:"pcb_silkscreen_text",pcb_silkscreen_text_id:`pin_${h}`,pcb_component_id:"1",layer:"top",anchor_position:{x:-A.w/2+A.pl+(c+A.silkscreenlabelmargin),y:Q-E*A.p},text:u,font_size:.7,font:"tscircuit2024",anchor_alignment:"center"})}A.innerhole&&(o.push(qn(E+1+g,-A.w/2,Q-E*A.p,r,a)),o.push(qn(E+1+g*2,-A.w/2+A.innerholeedgedistance,Q-E*A.p,r,a)))}}if(A.top){const Q=(A.top-1)/2*A.p;for(let E=0;E<A.top;E++){if(E===0&&!A.left&&!A.bottom&&!A.right&&!A.silkscreenlabels&&(s=C5(Q-E*A.p,e/2-A.pl*1.4,"top")),i.push(Qi(E+1+A.left+A.right+(A.bottom??0),Q-E*A.p,e/2-A.pl/2,A.pw,A.pl)),A.silkscreenlabels){const h=E+1+A.left+A.right+(A.bottom??0),u=`pin${h}`;n.push({type:"pcb_silkscreen_text",pcb_silkscreen_text_id:`pin_${h}`,pcb_component_id:"1",layer:"top",anchor_position:{x:Q-E*A.p,y:e/2-A.pl-(c+A.silkscreenlabelmargin)},text:u,font_size:.7,font:"tscircuit2024",anchor_alignment:"center",ccw_rotation:270})}A.innerhole&&(o.push(qn(E+1+A.left+A.right+(A.bottom??0)+g,Q-E*A.p,e/2,r,a)),o.push(qn(E+1+A.left+A.right+(A.bottom??0)+g*2,Q-E*A.p,e/2-A.innerholeedgedistance,r,a)))}}if(A.bottom){const Q=-((A.bottom-1)/2)*A.p;for(let E=0;E<A.bottom;E++){if(E===0&&!A.left&&!A.silkscreenlabels&&(s=C5(Q+E*A.p,-e/2+A.pl*1.4,"bottom")),i.push(Qi(E+1+A.left,Q+E*A.p,-e/2+A.pl/2,A.pw,A.pl)),A.silkscreenlabels){const h=E+1+A.left,u=`pin${h}`;n.push({type:"pcb_silkscreen_text",pcb_silkscreen_text_id:`pin_${h}`,pcb_component_id:"1",layer:"top",anchor_position:{x:Q+E*A.p,y:-e/2+A.pl+(c+A.silkscreenlabelmargin)},text:u,font_size:.7,font:"tscircuit2024",anchor_alignment:"center",ccw_rotation:90})}A.innerhole&&(o.push(qn(E+1+A.left+g,Q+E*A.p,-e/2,r,a)),o.push(qn(E+1+A.left+g*2,Q+E*A.p,-e/2+A.innerholeedgedistance,r,a)))}}const B={type:"pcb_silkscreen_path",pcb_silkscreen_path_id:"pcb_silkscreen_triangle_1",pcb_component_id:"2",route:s,stroke_width:.1,layer:"top"},C={type:"pcb_silkscreen_path",pcb_silkscreen_path_id:"pcb_silkscreen_path_1",pcb_component_id:"1",route:[{x:-A.w/2,y:e/2},{x:A.w/2,y:e/2},{x:A.w/2,y:-e/2},{x:-A.w/2,y:-e/2},{x:-A.w/2,y:e/2}],stroke_width:.1,layer:"top"},l=Yi(0,e/1.8,e/25);return{circuitJson:[...i,...o,...n,C,...A.silkscreenlabels?[]:[B],l],parameters:A}},sZA=Ji.extend({fn:H(),w:Ae.default("22.58mm"),h:Ae.optional(),left:Ae.optional().default(20),right:Ae.optional().default(20),top:Ae.optional().default(2),bottom:Ae.optional().default(2),p:Ae.default(Ae.parse("2.54mm")),pw:Ae.default(Ae.parse("1.6mm")),pl:Ae.default(Ae.parse("3.2mm")),innerhole:ce().default(!1),innerholeedgedistance:Ae.default(Ae.parse("1.61mm"))}),LBt=t=>{const A=sZA.parse(t);return A.left&&A.right?Math.max(A.left,A.right)*A.p:A.left?A.left*A.p:A.right?A.right*A.p:51},HBt=(t,A,e,i=1,o=.6)=>{const n=i/2,s=o/2;return{left:[{x:t+n,y:A},{x:t-n,y:A+s},{x:t-n,y:A-s},{x:t+n,y:A}],right:[{x:t-n,y:A},{x:t+n,y:A+s},{x:t+n,y:A-s},{x:t-n,y:A}],top:[{x:t,y:A-n},{x:t-s,y:A+n},{x:t+s,y:A+n},{x:t,y:A-n}],bottom:[{x:t,y:A+n},{x:t-s,y:A-n},{x:t+s,y:A-n},{x:t,y:A+n}]}[e]},YBt=t=>{const A=sZA.parse(t),e=A.h??LBt(A),i=[],o=[],n=[],s=1,r=1.2,a=A.left+A.right+(A.bottom??0)+(A.top??0);let g=[],I=1;if(A.left){const l=(A.left-1)/2*A.p;for(let Q=0;Q<A.left;Q++)Q===0&&(g=HBt(-A.w/2-A.pl/2,l-Q*A.p,"left")),i.push(Qi(I,-A.w/2+A.pl/2,l-Q*A.p,A.pl,A.pw)),o.push({type:"pcb_silkscreen_text",pcb_silkscreen_text_id:`pin_${I}`,pcb_component_id:"1",layer:"top",anchor_position:{x:-A.w/2+A.pl/2-4.5,y:l-Q*A.p},text:`pin${I}`,font_size:.7,font:"tscircuit2024",anchor_alignment:"center"}),I++,A.innerhole&&n.push(qn(I+a,-A.w/2+A.innerholeedgedistance,l-Q*A.p,s,r))}if(A.bottom){const l=(A.bottom-1)/2*A.p;for(let Q=A.bottom-1;Q>=0;Q--)i.push(Qi(I,l-Q*A.p,-e/2+A.pl/2,A.pw,A.pl)),o.push({type:"pcb_silkscreen_text",pcb_silkscreen_text_id:`pin_${I}`,pcb_component_id:"1",layer:"top",anchor_position:{x:l-Q*A.p,y:-e/2+A.pl/2-3.2},text:`pin${I}`,font_size:.7,font:"tscircuit2024",anchor_alignment:"center"}),I++,A.innerhole&&n.push(qn(I+a,l-Q*A.p,-e/2+A.innerholeedgedistance,s,r))}if(A.right){const l=-((A.right-1)/2)*A.p;for(let Q=0;Q<A.right;Q++)i.push(Qi(I,A.w/2-A.pl/2,l+Q*A.p,A.pl,A.pw)),o.push({type:"pcb_silkscreen_text",pcb_silkscreen_text_id:`pin_${I}`,pcb_component_id:"1",layer:"top",anchor_position:{x:A.w/2-A.pl/2+3.7,y:l+Q*A.p},text:`pin${I}`,font_size:.7,font:"tscircuit2024",anchor_alignment:"center"}),I++,A.innerhole&&n.push(qn(I+a,A.w/2-A.innerholeedgedistance,l+Q*A.p,s,r))}if(A.top){const l=-((A.top-1)/2)*A.p;for(let Q=A.top-1;Q>=0;Q--)i.push(Qi(I,l+Q*A.p,e/2-A.pl/2,A.pw,A.pl)),o.push({type:"pcb_silkscreen_text",pcb_silkscreen_text_id:`pin_${I}`,pcb_component_id:"1",layer:"top",anchor_position:{x:l+Q*A.p,y:e/2-A.pl/2+3.2},text:`pin${I}`,font_size:.7,font:"tscircuit2024",anchor_alignment:"center"}),I++,A.innerhole&&n.push(qn(I+a,l+Q*A.p,e/2-A.innerholeedgedistance,s,r))}const c={type:"pcb_silkscreen_path",pcb_silkscreen_path_id:"1",pcb_component_id:"1",layer:"top",route:g,stroke_width:.1},B={type:"pcb_silkscreen_path",pcb_silkscreen_path_id:"pcb_silkscreen_path_1",pcb_component_id:"1",route:[{x:-A.w/2-A.pl/3,y:e/2+A.pl/3},{x:A.w/2+A.pl/3,y:e/2+A.pl/3},{x:A.w/2+A.pl/3,y:-e/2-A.pl/3},{x:-A.w/2-A.pl/3,y:-e/2-A.pl/3},{x:-A.w/2-A.pl/3,y:e/2+A.pl/3}],stroke_width:.1,layer:"top"},C=Yi(0,e/1.8,e/25);return{circuitJson:[...n,...i,...o,B,c,C],parameters:A}},JBt=t=>(t.legsoutside=!0,t.pl||(t.pl=1.5),t.pw||(t.pw=.3),zN(t)),rZA=Ji.extend({fn:H(),w:Ae.default("10mm"),h:Ae.optional(),left:Ae.optional().default(20),right:Ae.optional().default(20),top:Ae.optional().default(0),bottom:Ae.optional().default(0),p:Ae.default(Ae.parse("2.54mm")),id:Ae.optional().default(Ae.parse("1mm")),od:Ae.optional().default(Ae.parse("1.5mm"))}),TBt=t=>{const A=rZA.parse(t);return A.left&&A.right?Math.max(A.left,A.right)*A.p:A.left?A.left*A.p:A.right?A.right*A.p:51},l5=(t,A,e,i=1,o=.6)=>{const n=i/2,s=o/2;return{left:[{x:t+n,y:A},{x:t-n,y:A+s},{x:t-n,y:A-s},{x:t+n,y:A}],right:[{x:t-n,y:A},{x:t+n,y:A+s},{x:t+n,y:A-s},{x:t-n,y:A}],top:[{x:t,y:A-n},{x:t-s,y:A+n},{x:t+s,y:A+n},{x:t,y:A-n}],bottom:[{x:t,y:A+n},{x:t-s,y:A-n},{x:t+s,y:A-n},{x:t,y:A+n}]}[e]},KBt=t=>{const A=rZA.parse(t),e=A.h??TBt(A),i=[],o=A.id,n=A.od;let s=[];if(A.right){const I=-((A.right-1)/2)*A.p;for(let c=0;c<A.right;c++)c===0&&!A.left&&!A.bottom&&(s=l5(A.w/2+n*1.4,I+c*A.p,"right")),i.push(qn(c+1+A.left+(A.bottom??0),A.w/2,I+c*A.p,o,n))}if(A.left){const I=-((A.left-1)/2)*A.p;for(let c=0;c<A.left;c++)c===A.left-1&&(s=l5(-A.w/2-n*1.4,I+c*A.p,"left")),i.push(qn(c+1,-A.w/2,I+c*A.p,o,n))}if(A.top){const I=-((A.top-1)/2)*A.p;for(let c=0;c<A.top;c++)c===A.top-1&&!A.left&&!A.bottom&&!A.right&&(s=l5(I+c*A.p,e/2+n*1.4,"top")),i.push(qn(c+1+A.right+(A.bottom??0)+A.left,I+c*A.p,e/2,o,n))}if(A.bottom){const I=-((A.bottom-1)/2)*A.p;for(let c=0;c<A.bottom;c++)c===0&&!A.left&&(s=l5(I+c*A.p,-e/2-n*1.4,"bottom")),i.push(qn(c+1+A.left,I+c*A.p,-e/2,o,n))}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-n,y:e/2+n},{x:A.w/2+n,y:e/2+n},{x:A.w/2+n,y:-e/2-n},{x:-A.w/2-n,y:-e/2-n},{x:-A.w/2-n,y:e/2+n}],stroke_width:.1,layer:"top"},g=Yi(0,e/1.7,e/25);return{circuitJson:[...i,a,g,r],parameters:A}},aZA=(t,A,e,i)=>Array.from({length:25},(o,n)=>{const s=n/24*Math.PI-Math.PI/2;return{x:t+(i==="right"?1:-1)*Math.cos(s)*e,y:A+Math.sin(s)*e}}),qBt=Ji.extend({fn:H(),p:Ae.optional().default("4.88mm"),id:Ae.optional().default("0.8mm"),od:Ae.optional().default("1.5mm"),w:Ae.optional().default("5.6mm"),h:Ae.optional().default("3.5mm")}),PBt=t=>{const A=qBt.parse(t),{p:e,id:i,od:o,w:n,h:s}=A,r=s/2,a=[qn(1,-e/2,0,i,o),qn(2,e/2,0,i,o)],g=aZA(-n/2,0,r,"left"),I=aZA(n/2,0,r,"right"),c={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[...g,...g.slice(1).reverse(),{x:-n/2,y:-s/2},{x:n/2,y:-s/2},...I,{x:n/2,y:s/2},{x:-n/2,y:s/2}],stroke_width:.1,pcb_silkscreen_path_id:""},B=Yi(0,e/4,.5);return{circuitJson:[...a,c,B],parameters:A}};Ji.extend({w:Ae,h:Ae});var OBt=t=>{const{w:A,h:e}=t,i=mr(A),o=mr(e);return{circuitJson:[Qi(1,0,0,i,o),Yi(0,o/2+.5,.2)],parameters:t}},$U=(t,A,e,i,o,n)=>({pcb_plated_hole_id:"",type:"pcb_plated_hole",shape:"pill",x:A,y:e,outer_width:mr(o),outer_height:mr(n),hole_width:mr(i),hole_height:mr(i),pcb_port_id:"",layers:["top","bottom"],port_hints:[t.toString()],ccw_rotation:0}),WBt=Ji.extend({fn:H(),num_pins:ei([xA(3),xA(2)]).default(3),p:H().default("1.27mm"),id:H().default("0.72mm"),od:H().default("0.95mm"),w:H().default("4.5mm"),h:H().default("4.5mm"),inline:ce().default(!1),string:H().optional()}),ZBt=(t,A,e)=>Array.from({length:25},(i,o)=>{const n=o/24*Math.PI;return{x:t+Math.cos(n)*e,y:A+Math.sin(n)*e}}),VBt=t=>{const A=t.string?.match(/^to92_(\d+)/),e=A?Number.parseInt(A[1],10):3,i=WBt.parse({...t,num_pins:e}),{p:o,id:n,od:s,w:r,h:a,inline:g}=i,I=Number.parseFloat(a)/2,c=Number.parseFloat(o),B=Number.parseFloat(n),C=Number.parseFloat(s),l=C,Q=C*(1.5/1.05);let E=[];if(i.num_pins===3)g?E=[uS(1,-c,I-c,B,C,Q,0,0),$U(2,0,I-c,B,l,Q),$U(3,c,I-c,B,l,Q)]:E=[uS(1,-c,I-c,B,C,C,0,0),qn(2,0,I,B,C),qn(3,c,I-c,B,C)];else if(i.num_pins===2)E=[uS(1,-c,I-c,B,l,Q,0,0),$U(2,c,I-c,B,l,Q)];else throw new Error("Invalid number of pins for TO-92");const h=Number.parseFloat(r)/2,u=ZBt(0,I,h),d={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[...u,{x:-h,y:0},{x:h,y:0},u[0]],stroke_width:.1,pcb_silkscreen_path_id:""},f=Yi(0,I+1,.5);return{circuitJson:[...E,d,f],parameters:i}},jBt=Ji.extend({fn:H(),num_pins:xA(2).default(2),w:H().default("2.15mm"),h:H().default("1.20mm"),pl:H().default("0.5mm"),pw:H().default("0.6mm"),p:H().default("1.4mm")}),zBt=t=>{const A=jBt.parse(t),e=Yi(0,Ae.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:Ae.parse(A.p)/2,y:Ae.parse(A.h)/2},{x:-Ae.parse(A.w)/2-.2,y:Ae.parse(A.h)/2},{x:-Ae.parse(A.w)/2-.2,y:-Ae.parse(A.h)/2},{x:Ae.parse(A.p)/2,y:-Ae.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:$Bt(A).concat(i,e),parameters:A}},XBt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},$Bt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:o}=XBt({pn:e,p:Number.parseFloat(t.p)});A.push(Qi(e,i,o,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},ACt=Rm({}),eCt=t=>{const A=ACt.parse(t),e=[];for(let s=0;s<A.num_pins;s++){const{x:r,y:a}=eCA({num_pins:A.num_pins,pn:s+1,w:A.w,p:A.p??1.27,pl:A.pl,widthincludeslegs:!0});e.push(Qi(s+1,r,a,A.pl??"1.5mm",A.pw??"0.6mm"))}const i=(A.num_pins/2-1)*A.p+A.pw,o=Yi(0,i/2-.5,i/12),n={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:[...e,o,n],parameters:A}},tCt=Ji.extend({fn:H(),num_pins:xA(2).default(2),w:H().default("5.0mm"),h:H().default("2.30mm"),pl:H().default("1.25mm"),pw:H().default("2mm"),p:H().default("3.75mm")}),iCt=t=>{const A=tCt.parse(t),e=Yi(0,Ae.parse(A.h)/2+1,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:Ae.parse(A.p)/2+.5,y:Ae.parse(A.h)/2+.5},{x:-Ae.parse(A.w)/2-.5,y:Ae.parse(A.h)/2+.5},{x:-Ae.parse(A.w)/2-.5,y:-Ae.parse(A.h)/2-.5},{x:Ae.parse(A.p)/2+.5,y:-Ae.parse(A.h)/2-.5}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:nCt(A).concat(i,e),parameters:A}},oCt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},nCt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:o}=oCt({pn:e,p:Number.parseFloat(t.p)});A.push(Qi(e,i,o,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},sCt=Ji.extend({fn:H(),num_pins:xA(2).default(2),w:H().default("4.4mm"),h:H().default("2.1mm"),pl:H().default("1.2mm"),pw:H().default("1.2mm"),p:H().default("2.9mm")}),rCt=t=>{const A=sCt.parse(t),e=Yi(0,Ae.parse(A.h)-.5,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:Ae.parse(A.p)/2,y:Ae.parse(A.h)/2},{x:-Ae.parse(A.w)/2-.2,y:Ae.parse(A.h)/2},{x:-Ae.parse(A.w)/2-.2,y:-Ae.parse(A.h)/2},{x:Ae.parse(A.p)/2,y:-Ae.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:gCt(A).concat(i,e),parameters:A}},aCt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},gCt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:o}=aCt({pn:e,p:Number.parseFloat(t.p)});A.push(Qi(e,i,o,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},ICt=Ji.extend({fn:H(),num_pins:xA(2).default(2),w:H().default("3.30mm"),h:H().default("1.80mm"),pl:H().default("0.60mm"),pw:H().default("0.45mm"),p:H().default("2.1mm")}),cCt=t=>{const A=ICt.parse(t),e=Yi(0,Ae.parse(A.h)-.5,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:Ae.parse(A.p)/2,y:Ae.parse(A.h)/2},{x:-Ae.parse(A.w)/2,y:Ae.parse(A.h)/2},{x:-Ae.parse(A.w)/2,y:-Ae.parse(A.h)/2},{x:Ae.parse(A.p)/2,y:-Ae.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:CCt(A).concat(i,e),parameters:A}},BCt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},CCt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:o}=BCt({pn:e,p:Number.parseFloat(t.p)});A.push(Qi(e,i,o,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},lCt=Ji.extend({fn:H(),num_pins:xA(2).default(2),w:H().default("1.4mm"),h:H().default("0.9mm"),pl:H().default("0.36mm"),pw:H().default("0.25mm"),p:H().default("0.85mm")}),QCt=t=>{const A=lCt.parse(t),e=Yi(0,Ae.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:Ae.parse(A.p)/2+.15,y:Ae.parse(A.h)/2},{x:-Ae.parse(A.w)/2-.15,y:Ae.parse(A.h)/2},{x:-Ae.parse(A.w)/2-.15,y:-Ae.parse(A.h)/2},{x:Ae.parse(A.p)/2+.15,y:-Ae.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:hCt(A).concat(i,e),parameters:A}},ECt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},hCt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:o}=ECt({pn:e,p:Number.parseFloat(t.p)});A.push(Qi(e,i,o,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},uCt=Ji.extend({fn:H(),num_pins:xA(2).default(2),w:H().default("1.3mm"),h:H().default("0.9mm"),pl:H().default("0.4mm"),pw:H().default("0.7mm"),p:H().default("0.7mm")}),dCt=t=>{const A=uCt.parse(t),e=Yi(0,Ae.parse(A.h)+.1,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:Ae.parse(A.p)/2+.2,y:Ae.parse(A.h)/2+.2},{x:-Ae.parse(A.w)/2-.2,y:Ae.parse(A.h)/2+.2},{x:-Ae.parse(A.w)/2-.2,y:-Ae.parse(A.h)/2-.2},{x:Ae.parse(A.p)/2+.2,y:-Ae.parse(A.h)/2-.2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:fCt(A).concat(i,e),parameters:A}},pCt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},fCt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:o}=pCt({pn:e,p:Number.parseFloat(t.p)});A.push(Qi(e,i,o,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},yCt=Ji.extend({fn:H(),num_pins:xA(2).default(2),w:H().default("3,05mm"),h:H().default("1.65mm"),pl:H().default("0.6mm"),pw:H().default("0.6mm"),pad_spacing:H().default("2.2mm")}),wCt=t=>{const A=yCt.parse(t),e=Yi(0,Ae.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:Ae.parse(A.pad_spacing)/2,y:Ae.parse(A.h)/2},{x:-Ae.parse(A.w)/2-.2,y:Ae.parse(A.h)/2},{x:-Ae.parse(A.w)/2-.2,y:-Ae.parse(A.h)/2},{x:Ae.parse(A.pad_spacing)/2,y:-Ae.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:DCt(A).concat(i,e),parameters:A}},mCt=t=>{const{pn:A,pad_spacing:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},DCt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:o}=mCt({pn:e,pad_spacing:Number.parseFloat(t.pad_spacing)});A.push(Qi(e,i,o,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},SCt=Ji.extend({fn:H(),num_pins:xA(2).default(2),w:H().default("4.4mm"),h:H().default("2.1mm"),pl:H().default("1.2mm"),pw:H().default("1.2mm"),p:H().default("2.9mm")}),bCt=t=>{const A=SCt.parse(t),e=Yi(0,Ae.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:Ae.parse(A.p)/2,y:Ae.parse(A.h)/2},{x:-Ae.parse(A.w)/2-.2,y:Ae.parse(A.h)/2},{x:-Ae.parse(A.w)/2-.2,y:-Ae.parse(A.h)/2},{x:Ae.parse(A.p)/2,y:-Ae.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:kCt(A).concat(i,e),parameters:A}},xCt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},kCt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:o}=xCt({pn:e,p:Number.parseFloat(t.p)});A.push(Qi(e,i,o,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},GCt=Ji.extend({fn:H(),num_pins:xA(2).default(2),w:H().default("4.4mm"),h:H().default("2.1mm"),pl:H().default("0.91mm"),pw:H().default("1.22mm"),p:H().default("3.146mm")}),FCt=t=>{const A=GCt.parse(t),e=Yi(0,Ae.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:Ae.parse(A.p)/2,y:Ae.parse(A.h)/2},{x:-Ae.parse(A.w)/2-.2,y:Ae.parse(A.h)/2},{x:-Ae.parse(A.w)/2-.2,y:-Ae.parse(A.h)/2},{x:Ae.parse(A.p)/2,y:-Ae.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:MCt(A).concat(i,e),parameters:A}},RCt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},MCt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:o}=RCt({pn:e,p:Number.parseFloat(t.p)});A.push(Qi(e,i,o,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},NCt=Ji.extend({fn:H(),num_pins:xA(2).default(2),w:H().default("1.80mm"),h:H().default("1.00mm"),pl:H().default("0.66mm"),pw:H().default("0.5mm"),p:H().default("0.8mm")}),_Ct=t=>{const A=NCt.parse(t),e=Yi(0,Ae.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:Ae.parse(A.p)/2,y:Ae.parse(A.h)/2},{x:-Ae.parse(A.w)/2-.1,y:Ae.parse(A.h)/2},{x:-Ae.parse(A.w)/2-.1,y:-Ae.parse(A.h)/2},{x:Ae.parse(A.p)/2,y:-Ae.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:UCt(A).concat(i,e),parameters:A}},vCt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},UCt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:o}=vCt({pn:e,p:Number.parseFloat(t.p)});A.push(Qi(e,i,o,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},LCt=Ji.extend({fn:H(),num_pins:xA(2).default(2),w:H().default("6.2mm"),h:H().default("3.4mm"),pl:H().default("1.4mm"),pw:H().default("2.1mm"),p:H().default("4.4mm")}),HCt=t=>{const A=LCt.parse(t),e=Yi(0,Ae.parse(A.h)/2+.4,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:Ae.parse(A.p)/2,y:Ae.parse(A.h)/2},{x:-Ae.parse(A.w)/2-.2,y:Ae.parse(A.h)/2},{x:-Ae.parse(A.w)/2-.2,y:-Ae.parse(A.h)/2},{x:Ae.parse(A.p)/2,y:-Ae.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:JCt(A).concat(i,e),parameters:A}},YCt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},JCt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:o}=YCt({pn:e,p:Number.parseFloat(t.p)});A.push(Qi(e,i,o,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},TCt=Ji.extend({fn:H(),num_pins:ei([xA(3),xA(5)]).default(3),w:H().default("4.20mm"),h:H().default("4.80mm"),pl:H().default("1.3mm"),pw:H().default("0.9mm"),p:H().default("1.5mm"),string:H().optional()}),KCt=t=>{const A=[],e=Number.parseFloat(t.p),i=Number.parseFloat(t.pw),o=Number.parseFloat(t.w),n=Number.parseFloat(t.pl),s=.175,r=(n-(n+s))/2;A.push(Qi(1,-o/2+r,e,n,i),Qi(2,-o/2,0,n+s,i),Qi(3,-o/2+r,-e,n,i));const a=Yi(0,0,.3),g=Number.parseFloat(t.w)/2-1,I=Number.parseFloat(t.h)/2,c={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-g,y:I},{x:g,y:I},{x:g,y:I/2+.5}],type:"pcb_silkscreen_path",stroke_width:.1},B={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_2",route:[{x:-g,y:-I},{x:g,y:-I},{x:g,y:-I/2-.5}],type:"pcb_silkscreen_path",stroke_width:.1};return[...A,c,B,a]},qCt=t=>{const A=[];Number.parseFloat(t.p),Number.parseFloat(t.pw),Number.parseFloat(t.w),A.push(Qi(1,-1.85,-1.5,1.5,.7),Qi(2,-1.85,1.5,1.5,.7),Qi(3,0,0,.8,2),Qi(4,1.85,-1.5,1.5,.7),Qi(5,1.85,1.5,1.5,.7));const e=Yi(0,Number.parseFloat(t.h)/2+.5,.3),i=Number.parseFloat(t.w)/2-1,o=Number.parseFloat(t.h)/2,n={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-i,y:o},{x:i,y:o}],type:"pcb_silkscreen_path",stroke_width:.1},s={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_2",route:[{x:-i,y:-o},{x:i,y:-o}],type:"pcb_silkscreen_path",stroke_width:.1};return[...A,n,s,e]},PCt=t=>{const A=t.string?.match(/^sot89_(\d+)/),e=A?Number.parseInt(A[1],10):3,i=TCt.parse({...t,num_pins:e});if(i.num_pins===3)return{circuitJson:KCt(i),parameters:i};if(i.num_pins===5)return{circuitJson:qCt(i),parameters:i};throw new Error("Invalid number of pins for SOT89")},OCt=Ji.extend({fn:H(),p:Ae.optional().default("5.0mm"),id:Ae.optional().default("1.0mm"),od:Ae.optional().default("1.9mm"),w:Ae.optional().default("13mm"),h:Ae.optional().default("7mm"),num_pins:WA().optional(),string:H().optional()}),WCt=t=>{const A=OCt.parse(t),{fn:e,id:i,od:o,w:n,h:s,string:r}=A,a=Number.parseInt(r?.split("_")[1]??"3"),g=-1,I=n/2,c=s/2,B=2.5,C=n*.4,l=Math.max(B,C/(a-1)),Q=Array.from({length:a},(m,b)=>{const D=a%2===0?(b-a/2+.5)*l:(b-Math.floor(a/2))*l;return qn(b+1,D,g,i,o)}),E={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-I,y:-c},{x:I,y:-c},{x:I,y:c},{x:-I,y:c},{x:-I,y:-c}],stroke_width:.1,pcb_silkscreen_path_id:""},h=-c+2*s/3,u={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-I,y:h},{x:I,y:h}],stroke_width:.1,pcb_silkscreen_path_id:""},d=[{type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-n/6,y:h},{x:-n/6,y:c}],stroke_width:.1,pcb_silkscreen_path_id:""},{type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:n/6,y:h},{x:n/6,y:c}],stroke_width:.1,pcb_silkscreen_path_id:""}],f=Yi(0,s/2+.6,.5);return{circuitJson:[...Q,E,u,...d,f],parameters:{...A,p:l}}},ZCt=Ji.extend({fn:H(),num_pins:xA(2).default(2),w:H().default("5.40mm"),h:H().default("2.30mm"),pl:H().default("1.30mm"),pw:H().default("1.70mm"),p:H().default("3.5mm")}),VCt=t=>{const A=ZCt.parse(t),e=Yi(0,Ae.parse(A.h)/2+.4,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:Ae.parse(A.p)/2,y:Ae.parse(A.h)/2},{x:-Ae.parse(A.w)/2,y:Ae.parse(A.h)/2},{x:-Ae.parse(A.w)/2,y:-Ae.parse(A.h)/2},{x:Ae.parse(A.p)/2,y:-Ae.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:zCt(A).concat(i,e),parameters:A}},jCt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},zCt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:o}=jCt({pn:e,p:Number.parseFloat(t.p)});A.push(Qi(e,i,o,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},XCt=Ji.extend({fn:H(),num_pins:xA(2).default(2),w:H().default("1.90mm"),h:H().default("1.33mm"),pl:H().default("0.5mm"),pw:H().default("0.7mm"),p:H().default("0.8mm")}),$Ct=t=>{const A=XCt.parse(t),e=Yi(0,Ae.parse(A.h)+.1,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:Ae.parse(A.p)/2+.1,y:Ae.parse(A.h)/2},{x:-Ae.parse(A.w)/2,y:Ae.parse(A.h)/2},{x:-Ae.parse(A.w)/2,y:-Ae.parse(A.h)/2},{x:Ae.parse(A.p)/2+.1,y:-Ae.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:elt(A).concat(i,e),parameters:A}},Alt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},elt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:o}=Alt({pn:e,p:Number.parseFloat(t.p)});A.push(Qi(e,i,o,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},tlt=Ji.extend({fn:H(),num_pins:xA(2).default(2),w:H().default("7.0mm"),h:H().default("3.35mm"),pl:H().default("1.50mm"),pw:H().default("2.70mm"),p:H().default("4.8mm")}),ilt=t=>{const A=tlt.parse(t),e=Yi(0,Ae.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:Ae.parse(A.p)/2,y:Ae.parse(A.h)/2},{x:-Ae.parse(A.w)/2,y:Ae.parse(A.h)/2},{x:-Ae.parse(A.w)/2,y:-Ae.parse(A.h)/2},{x:Ae.parse(A.p)/2,y:-Ae.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:nlt(A).concat(i,e),parameters:A}},olt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},nlt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:o}=olt({pn:e,p:Number.parseFloat(t.p)});A.push(Qi(e,i,o,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},slt=Ji.extend({fn:H(),num_pins:xA(2).default(2),w:H().default("3.0mm"),h:H().default("1.80mm"),pl:H().default("0.80mm"),pw:H().default("1.20mm"),p:H().default("1.6mm")}),rlt=t=>{const A=slt.parse(t),e=Yi(0,Ae.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:Ae.parse(A.p)/2,y:Ae.parse(A.h)/2},{x:-Ae.parse(A.w)/2-.1,y:Ae.parse(A.h)/2},{x:-Ae.parse(A.w)/2-.1,y:-Ae.parse(A.h)/2},{x:Ae.parse(A.p)/2,y:-Ae.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:glt(A).concat(i,e),parameters:A}},alt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},glt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:o}=alt({pn:e,p:Number.parseFloat(t.p)});A.push(Qi(e,i,o,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},Ilt=Ji.extend({fn:H(),num_pins:xA(2).default(2),w:H().default("7.10mm"),h:H().default("3.40mm"),pl:H().default("2.45mm"),pw:H().default("1.80mm"),p:H().default("4.05mm")}),clt=t=>{const A=Ilt.parse(t),e=Yi(0,Ae.parse(A.h)/2+.5,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:Ae.parse(A.p)/2,y:Ae.parse(A.h)/2},{x:-Ae.parse(A.w)/2-.5,y:Ae.parse(A.h)/2},{x:-Ae.parse(A.w)/2-.5,y:-Ae.parse(A.h)/2},{x:Ae.parse(A.p)/2,y:-Ae.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:Clt(A).concat(i,e),parameters:A}},Blt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},Clt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:o}=Blt({pn:e,p:Number.parseFloat(t.p)});A.push(Qi(e,i,o,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},llt=Ji.extend({fn:H(),num_pins:xA(2).default(2),w:H().default("4.80mm"),h:H().default("2.10mm"),pl:H().default("1.30mm"),pw:H().default("1.40mm"),p:H().default("2.9mm")}),Qlt=t=>{const A=llt.parse(t),e=Yi(0,Ae.parse(A.h)-.5,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:Ae.parse(A.p)/2,y:Ae.parse(A.h)/2},{x:-Ae.parse(A.w)/2,y:Ae.parse(A.h)/2},{x:-Ae.parse(A.w)/2,y:-Ae.parse(A.h)/2},{x:Ae.parse(A.p)/2,y:-Ae.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:hlt(A).concat(i,e),parameters:A}},Elt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},hlt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:o}=Elt({pn:e,p:Number.parseFloat(t.p)});A.push(Qi(e,i,o,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},ult=Ji.extend({fn:H(),num_pins:xA(2).default(2),w:H().default("7.30mm"),h:H().default("4.40mm"),pl:H().default("2.50mm"),pw:H().default("2.30mm"),p:H().default("4.30mm")}),dlt=t=>{const A=ult.parse(t),e=Yi(0,Ae.parse(A.h)/2+.5,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:Ae.parse(A.p)/2,y:Ae.parse(A.h)/2},{x:-Ae.parse(A.w)/2-.1,y:Ae.parse(A.h)/2},{x:-Ae.parse(A.w)/2-.1,y:-Ae.parse(A.h)/2},{x:Ae.parse(A.p)/2,y:-Ae.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:flt(A).concat(i,e),parameters:A}},plt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},flt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:o}=plt({pn:e,p:Number.parseFloat(t.p)});A.push(Qi(e,i,o,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},ylt=Ji.extend({fn:H(),num_pins:xA(2).default(2),w:H().default("10.70mm"),h:H().default("6.60mm"),pl:H().default("3.30mm"),pw:H().default("2.50mm"),p:H().default("6.80mm")}),wlt=t=>{const A=ylt.parse(t),e=Yi(0,3,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:Ae.parse(A.p)/2,y:Ae.parse(A.h)/2-.8},{x:-Ae.parse(A.w)/2-.8,y:Ae.parse(A.h)/2-.8},{x:-Ae.parse(A.w)/2-.8,y:-Ae.parse(A.h)/2+.8},{x:Ae.parse(A.p)/2,y:-Ae.parse(A.h)/2+.8}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:Dlt(A).concat(i,e),parameters:A}},mlt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},Dlt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:o}=mlt({pn:e,p:Number.parseFloat(t.p)});A.push(Qi(e,i,o,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},Slt=Ji.extend({fn:H(),num_pins:WA().default(4),w:H().default("8.50mm"),h:H().default("6.90mm"),pl:H().default("2mm"),pw:H().default("1.5mm"),p:H().default("2.30mm"),string:H().optional()}),blt=t=>{const A=t.string?.match(/^sot223_(\d+)/),e=A?Number.parseInt(A[1],10):4;if(e===8){const o=Glt.parse({...t,num_pins:e});return{circuitJson:Gx(o),parameters:o}}const i=Slt.parse({...t,num_pins:e});if(i.num_pins===4)return{circuitJson:klt(i),parameters:i};if(i.num_pins===5)return{circuitJson:Rlt(i),parameters:i};if(i.num_pins===6)return{circuitJson:Nlt(i),parameters:i};throw new Error("Invalid number of pins")},xlt=t=>{const{pn:A,w:e,p:i}=t;return A===1?{x:-e/2+1.1,y:i}:A===2?{x:-e/2+1.1,y:0}:A===3?{x:-e/2+1.1,y:-i}:{x:e/2-1.1,y:0}},klt=t=>{const A=[];for(let r=0;r<t.num_pins;r++){const{x:a,y:g}=xlt({num_pins:t.num_pins,pn:r+1,w:Number.parseFloat(t.w),h:Number.parseFloat(t.h),pl:Number.parseFloat(t.pl),p:Number.parseFloat(t.p)}),I=r===3?3.8:Number.parseFloat(t.pw);A.push(Qi(r+1,a,g,Number.parseFloat(t.pl),I))}const e=Yi(0,0,.3),i=Number.parseFloat(t.w)/2-2.4,o=Number.parseFloat(t.h)/2,n={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-i,y:o},{x:i,y:o},{x:i,y:o/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:-o},{x:i,y:-o},{x:i,y:-o/2-.5}],type:"pcb_silkscreen_path",stroke_width:.1};return[...A,n,s,e]},Glt=Rm({p:"0.90mm",w:"2.8mm",legsoutside:!0}),Flt=t=>{const{p:A,pn:e,w:i}=t;if(e===1)return{x:-i/2+1.2,y:A/2+A};if(e===2)return{x:-i/2+1.2,y:A/2};if(e===3)return{x:-i/2+1.2,y:-A/2};if(e===4)return{x:-i/2+1.2,y:-A/2-A};if(e===5)return{x:i/2-1,y:0};throw new Error("Invalid pin number")},Rlt=t=>{const A=[];for(let r=1;r<=t.num_pins;r++){const{x:a,y:g}=Flt({h:Number.parseFloat(t.h),p:1.5,pn:r,w:Number.parseFloat(t.w)});let I=Number.parseFloat(t.pw),c=Number.parseFloat(t.pl);r===5?(I=3.4,c=1.8):(I=1,c=2.2),A.push(Qi(r,a,g,c,I))}const e=Number.parseFloat(t.w)/2-2.4,i=Number.parseFloat(t.h)/2,o={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-e,y:i},{x:e,y:i},{x:e,y:i/2+.5}],type:"pcb_silkscreen_path",stroke_width:.1},n={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_2",route:[{x:-e,y:-i},{x:e,y:-i},{x:e,y:-i/2-.5}],type:"pcb_silkscreen_path",stroke_width:.1},s=Yi(0,0,.3);return[...A,o,n,s]},Mlt=t=>{const{p:A,pn:e,w:i}=t;if(e===1)return{x:-i/2+1.2,y:2*A};if(e===2)return{x:-i/2+1.2,y:A};if(e===3)return{x:-i/2+1.2,y:0};if(e===4)return{x:-i/2+1.2,y:-A};if(e===5)return{x:-i/2+1.2,y:-2*A};if(e===6)return{x:i/2-1.175,y:0};throw new Error("Invalid pin number")},Nlt=t=>{const A=[];for(let r=1;r<=t.num_pins;r++){const{x:a,y:g}=Mlt({h:Number.parseFloat(t.h),p:1.3,pn:r,w:8.7});let I=Number.parseFloat(t.pw),c=Number.parseFloat(t.pl);r===6?(I=3.4,c=2.15):(I=.6,c=2.2),A.push(Qi(r,a,g,c,I))}const e=Number.parseFloat(t.w)/2-2.4,i=Number.parseFloat(t.h)/2,o={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-e,y:i},{x:e,y:i},{x:e,y:i/2+.5}],type:"pcb_silkscreen_path",stroke_width:.1},n={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_2",route:[{x:-e,y:-i},{x:e,y:-i},{x:e,y:-i/2-.5}],type:"pcb_silkscreen_path",stroke_width:.1},s=Yi(0,0,.3);return[...A,o,n,s]},_lt=Ji.extend({fn:H(),num_pins:WA().default(3),w:H().default("3.40mm"),h:H().default("3.30mm"),pl:H().default("1mm"),pw:H().default("0.7mm"),p:H().default("1.2mm"),string:H().optional()}),vlt=t=>{const A=t.string?.match(/^sot23w_(\d+)/),e=A?Number.parseInt(A[1],3):3,i=_lt.parse({...t,num_pins:e});if(i.num_pins===3)return{circuitJson:Llt(i),parameters:i};throw new Error("Invalid number of pins")},Ult=t=>{const{pn:A,p:e}=t;return A===1?{x:-e,y:.95}:A===2?{x:-e,y:-.95}:{x:e,y:0}},Llt=t=>{const A=[];for(let r=0;r<t.num_pins;r++){const{x:a,y:g}=Ult({num_pins:t.num_pins,pn:r+1,w:Number.parseFloat(t.w),h:Number.parseFloat(t.h),pl:Number.parseFloat(t.pl),p:Number.parseFloat(t.p)});A.push(Qi(r+1,a,g,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}const e=Yi(0,Number.parseInt(t.h)/2+1,.3),i=Number.parseFloat(t.w)/2-1,o=Number.parseFloat(t.h)/2,n={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-i,y:o},{x:i+.3,y:o},{x:i+.3,y:o/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:-o},{x:i+.3,y:-o},{x:i+.3,y:-o/2}],type:"pcb_silkscreen_path",stroke_width:.1};return[...A,n,s,e]},Hlt=Ji.extend({fn:H(),num_pins:ei([xA(3),xA(2)]).default(3),p:H().default("1.27mm"),id:H().default("0.72mm"),od:H().default("0.95mm"),w:H().default("2.5mm"),h:H().default("4.2mm"),string:H().optional()}),Ylt=t=>{const{p:A,id:e,od:i,w:o,h:n}=t,s=Number.parseFloat(n)/2,r=Number.parseFloat(A);return[qn(1,-r,s-r,e,i),qn(2,0,s-r,e,i),qn(3,r,s-r,e,i)]},Jlt=t=>{const{p:A,id:e,od:i,h:o}=t,n=Number.parseFloat(o)/2,s=Number.parseFloat(A);return[qn(1,-s,n-s,e,i),qn(2,s,n-s,e,i)]},Tlt=t=>{const A=t.string?.match(/^to92s_(\d+)/),e=A?Number.parseInt(A[1],10):3,i=Hlt.parse({...t,num_pins:e});let o=[];if(i.num_pins===3)o=Ylt(i);else if(i.num_pins===2)o=Jlt(i);else throw new Error("Invalid number of pins for TO-92");const n=Number.parseFloat(i.h)/2,s=Number.parseFloat(i.p),r={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-n,y:n-s},{x:-1.9,y:0},{x:1.9,y:0},{x:n,y:n-s},{x:1.5,y:Number.parseFloat(i.h)/2+.5},{x:-1.5,y:Number.parseFloat(i.h)/2+.5},{x:-n,y:n-s}],stroke_width:.1,pcb_silkscreen_path_id:""},a=Yi(0,n+1,.5);return{circuitJson:[...o,r,a],parameters:i}},Klt=Ji.extend({fn:H(),p:Ae.optional(),id:Ae.optional(),pw:Ae.optional(),pl:Ae.optional(),w:Ae.optional(),h:Ae.optional(),sh:ei([ce(),H(),WA()]).optional().transform(t=>{if(typeof t=="string"){const A=Number(t);return Number.isNaN(A)?!0:A}return t}).describe('JST SH (Surface-mount) connector family. SH stands for "Super High-density".'),ph:ce().optional().describe('JST PH (Through-hole) connector family. PH stands for "Pin Header".'),string:H().optional()}),qlt={ph:{p:Ae.parse("2.2mm"),id:Ae.parse("0.70mm"),pw:Ae.parse("1.20mm"),pl:Ae.parse("1.20mm"),w:Ae.parse("6mm"),h:Ae.parse("5mm")},sh:{p:Ae.parse("1mm"),pw:Ae.parse("0.6mm"),pl:Ae.parse("1.55mm"),w:Ae.parse("5.8mm"),h:Ae.parse("7.8mm")}};function Plt(t){return t.sh?"sh":(t.ph,"ph")}function Olt(t,A,e,i,o,n){const s=[];if(t==="ph"){const r=e/2;s.push(uS(1,-r,2,i,o,n)),s.push(uS(2,r,2,i,o,n))}else{const r=-((A-1)/2)*e;for(let g=0;g<A;g++){const I=r+g*e;console.log("x si",I),s.push(Qi(g+1,I,-1.325,o,n))}const a=(A-1)/2*e+1.3;console.log("offset",a),s.push(Qi(A+1,-a,1.22,1.2,1.8)),s.push(Qi(A+2,a,1.22,1.2,1.8))}return s}function Wlt(t,A,e){return t==="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 Zlt=t=>{const A=Klt.parse(t),e=Plt(A),i=qlt[e],o=A.p??i.p,n=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 I=e==="sh"?4:2;if(e==="sh"){const Q=(typeof t.string=="string"?t.string:"").match(/sh(\d+)/);if(Q&&Q[1]){const E=parseInt(Q[1],10);Number.isNaN(E)||(I=E)}else typeof A.sh=="number"&&(I=A.sh)}const c=Olt(e,I,o,n,s,r),B=Wlt(e),C=Yi(0,g/2+1,.5);return{circuitJson:[...c,B,C],parameters:{...A,p:o,id:n,pw:s,pl:r,w:a,h:g,num_pins:I,sh:e==="sh",ph:e==="ph"}}},Vlt=Ji.extend({fn:H(),num_pins:xA(2).default(2),w:H().default("3.30mm"),h:H().default("1.70mm"),pl:H().default("0.80mm"),pw:H().default("1mm"),p:H().default("1.90mm")}),jlt=t=>{const A=Vlt.parse(t),e=Yi(0,Ae.parse(A.h)/2+.5,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:Ae.parse(A.p)/2,y:Ae.parse(A.h)/2},{x:-Ae.parse(A.w)/2,y:Ae.parse(A.h)/2},{x:-Ae.parse(A.w)/2,y:-Ae.parse(A.h)/2},{x:Ae.parse(A.p)/2,y:-Ae.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:Xlt(A).concat(i,e),parameters:A}},zlt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},Xlt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:o}=zlt({pn:e,p:Number.parseFloat(t.p)});A.push(Qi(e,i,o,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},$lt=t=>{switch(t){case 8:return{w:"3.06mm",h:"3.14mm",p:"0.65mm",pl:"1.6mm",pw:"0.5mm"};case 10:return{w:"3.10mm",h:"3.33mm",p:"0.5mm",pl:"1.45mm",pw:"0.3mm"};default:return{w:"3.06mm",h:"3.14mm",p:"0.65mm",pl:"1.6mm",pw:"0.5mm"}}},AQt=Ji.extend({fn:H(),num_pins:ei([xA(8),xA(10)]).default(8),w:H().optional(),h:H().optional(),p:H().optional(),pl:H().optional(),pw:H().optional(),string:H().optional()}),eQt=t=>{const A=AQt.parse(t),e=$lt(A.num_pins),i=Ae.parse(A.w||e.w),o=Ae.parse(A.h||e.h),n=Ae.parse(A.p||e.p),s=Ae.parse(A.pl||e.pl),r=Ae.parse(A.pw||e.pw),a=[],g=A.num_pins/2;for(let u=0;u<A.num_pins;u++){const{x:d,y:f}=gZA(A.num_pins,u+1,i,n),m=u<g?u+1:A.num_pins-(u-g);a.push(Qi(m,d,f,s,r))}const I=i,c=o,B={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-I/2,y:c/2},{x:I/2,y:c/2}],stroke_width:.05,pcb_silkscreen_path_id:""},C={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-I/2,y:-c/2},{x:I/2,y:-c/2}],stroke_width:.05,pcb_silkscreen_path_id:""},l=gZA(A.num_pins,1,I,n),Q={x:l.x-.8,y:l.y},E={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"},h=Yi(0,c/2+.5,.3);return{circuitJson:[...a,B,C,h,E],parameters:A}},gZA=(t,A,e,i)=>{const o=t/2,n=(A-1)%o,s=A<=o?-1:1,r=(o-1)/2-n;return{x:s*Ae.parse(t===8?"1.8mm":"2.2mm"),y:r*i}},tQt=t=>{switch(t){case 10:return{w:"3.10mm",h:"3.32mm",p:"0.5mm",pl:"1.63mm",pw:"0.33mm"};case 12:return{w:"3mm",h:"4mm",p:"0.65mm",pl:"0.88mm",pw:"0.4mm"};case 16:return{w:"3.10mm",h:"4mm",p:"0.5mm",pl:"0.88mm",pw:"0.3mm"};default:return{w:"3.10mm",h:"3.32mm",p:"0.65mm",pl:"1.63mm",pw:"0.4mm"}}},iQt=Ji.extend({fn:H(),num_pins:ei([xA(8),xA(10),xA(12),xA(16)]).default(8),w:H().optional(),h:H().optional(),p:H().optional(),pl:H().optional(),pw:H().optional(),string:H().optional()}),IZA=(t,A,e,i)=>{const o=t/2,n=(A-1)%o,s=A<=o?-1:1,r=(o-1)/2-n;return{x:s*Ae.parse("2mm"),y:r*i}},oQt=t=>{const A=iQt.parse(t),e=tQt(A.num_pins),i=Ae.parse(A.w||e.w),o=Ae.parse(A.h||e.h),n=Ae.parse(A.p||e.p),s=Ae.parse(A.pl||e.pl),r=Ae.parse(A.pw||e.pw),a=[];for(let h=0;h<A.num_pins;h++){const{x:u,y:d}=IZA(A.num_pins,h+1,i,n);a.push(Qi(h+1,u,d,s,r))}const g=i,I=o,c={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-g/2,y:I/2},{x:g/2,y:I/2}],stroke_width:.05,pcb_silkscreen_path_id:""},B={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-g/2,y:-I/2},{x:g/2,y:-I/2}],stroke_width:.05,pcb_silkscreen_path_id:""},C=IZA(A.num_pins,1,g,n),l={x:C.x-.8,y:C.y},Q={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"pin_marker_1",route:[{x:l.x-.4,y:l.y},{x:l.x-.7,y:l.y+.3},{x:l.x-.7,y:l.y-.3},{x:l.x-.4,y:l.y}],stroke_width:.05,pcb_silkscreen_path_id:"pin_marker_1"},E=Yi(0,I/2+.5,.3);return{circuitJson:[...a,c,B,E,Q],parameters:A}},nQt=Ji.extend({fn:H(),num_pins:xA(2).default(2),w:H().default("3.8mm"),h:H().default("1.65mm"),pl:H().default("1.2mm"),pw:H().default("1.2mm"),pad_spacing:H().default("2.6mm")}),sQt=t=>{const A=nQt.parse(t),e=Yi(0,Ae.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:Ae.parse(A.pad_spacing)/2,y:Ae.parse(A.h)/2},{x:-Ae.parse(A.w)/2-.2,y:Ae.parse(A.h)/2},{x:-Ae.parse(A.w)/2-.2,y:-Ae.parse(A.h)/2},{x:Ae.parse(A.pad_spacing)/2,y:-Ae.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:aQt(A).concat(i,e),parameters:A}},rQt=t=>{const{pn:A,pad_spacing:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},aQt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:o}=rQt({pn:e,pad_spacing:Number.parseFloat(t.pad_spacing)});A.push(Qi(e,i,o,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},gQt=Ji.extend({fn:H(),num_pins:xA(2).default(2),w:H().default("3.20mm"),h:H().default("1.65mm"),pl:H().default("0.8mm"),pw:H().default("0.9mm"),pad_spacing:H().default("2.1mm")}),IQt=t=>{const A=gQt.parse(t),e=Yi(0,Ae.parse(A.h),.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:Ae.parse(A.pad_spacing)/2,y:Ae.parse(A.h)/2},{x:-Ae.parse(A.w)/2-.2,y:Ae.parse(A.h)/2},{x:-Ae.parse(A.w)/2-.2,y:-Ae.parse(A.h)/2},{x:Ae.parse(A.pad_spacing)/2,y:-Ae.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:BQt(A).concat(i,e),parameters:A}},cQt=t=>{const{pn:A,pad_spacing:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},BQt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:o}=cQt({pn:e,pad_spacing:Number.parseFloat(t.pad_spacing)});A.push(Qi(e,i,o,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},CQt=Ji.extend({fn:H(),num_pins:ei([xA(6),xA(8)]).default(8),w:H().default("3mm"),h:H().default("3mm"),p:H().default("0.5mm"),pl:H().default("0.52mm"),pw:H().default("0.35mm"),epw:H().default("1.40mm"),eph:H().default("1.60mm"),string:H().optional(),ep:ce().default(!1)}),lQt=t=>{t.string&&t.string.includes("_ep")&&(t.ep=!0);const A=t.string?.match(/^son_(\d+)/),e=A?Number.parseInt(A[1],10):t.num_pins||8,i=CQt.parse({...t,num_pins:e}),o=Ae.parse(i.w),n=Ae.parse(i.h),s=Ae.parse(i.p),r=Ae.parse(i.pl),a=Ae.parse(i.pw),g=Ae.parse(i.epw),I=Ae.parse(i.eph),c=[];for(let f=0;f<i.num_pins;f++){const{x:m,y:b}=cZA(i.num_pins,f+1,o,s);c.push(Qi(f+1,m,b,r,a))}i.ep&&c.push(Qi(i.num_pins+1,0,0,g,I));const B=o,C=n,l={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-B/2,y:C/2},{x:B/2,y:C/2}],stroke_width:.05,pcb_silkscreen_path_id:""},Q={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-B/2,y:-C/2},{x:B/2,y:-C/2}],stroke_width:.05,pcb_silkscreen_path_id:""},E=cZA(i.num_pins,1,B,s),h={x:E.x-.4,y:E.y},u={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"pin_marker_1",route:[{x:h.x-.4,y:h.y},{x:h.x-.7,y:h.y+.3},{x:h.x-.7,y:h.y-.3},{x:h.x-.4,y:h.y}],stroke_width:.05,pcb_silkscreen_path_id:"pin_marker_1"},d=Yi(0,C/2+.5,.3);return{circuitJson:[...c,l,Q,d,u],parameters:i}},cZA=(t,A,e,i)=>{const o=t/2,n=(A-1)%o,s=A<=o?-1:1,r=(o-1)/2-n;return{x:s*Ae.parse("1.4mm"),y:r*i}},QQt=t=>{const{num_pins:A,bridged:e,p:i=2.54,pw:o=1.5,ph:n=1.5}=t,s=Ae.parse(i),r=Ae.parse(o),a=Ae.parse(n),g=Math.min(a/4,.5),I=[];for(let f=0;f<A;f++)I.push(Qi(f+1,f*s,0,r,a));let c=[];if(e){const f=e.split("").map(Number);if(f.length>1)for(let m=0;m<f.length-1;m++){const b=f[m],D=f[m+1];if(typeof b=="number"&&typeof D=="number"&&!isNaN(b)&&!isNaN(D)){const x=(b-1)*s,F=(D-1)*s,k=Math.sign(F-x),v=x+k*(r/2),_=F-k*(r/2);c.push({type:"pcb_trace",pcb_trace_id:"",route:[{start_pcb_port_id:`{PIN${b}}`,x:v,y:0,width:g,layer:"top",route_type:"wire"},{end_pcb_port_id:`{PIN${D}}`,x:_,y:0,width:g,layer:"top",route_type:"wire"}]})}}}const B=(A-1)*s+r+.7,C=a+1,l=(A-1)*s/2,Q=0,E={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"outline",route:[{x:l-B/2,y:Q-C/2},{x:l+B/2,y:Q-C/2},{x:l+B/2,y:Q+C/2},{x:l-B/2,y:Q+C/2},{x:l-B/2,y:Q-C/2}],stroke_width:.15},u=Q+C/2+.6,d=Yi(l,u,.4);return{circuitJson:[...I,...c,E,d],parameters:t}},BZA={fn:xA("sot457"),num_pins:xA(6).default(6),pillh:H().default("0.45mm"),pillw:H().default("1.45mm"),pl:H(),pw:H(),p:H(),wave:ce().optional(),reflow:ce().optional()},EQt=Ji.extend({...BZA,h:H().default("2.5mm"),w:H().default("2.7mm"),pl:H().default("0.8mm"),pw:H().default("0.55mm"),p:H().default("0.95mm")}),hQt=Ji.extend({...BZA,h:H().default("3mm"),w:H().default("4mm"),pillr:H().default("0.225mm"),pl:H().default("1.45mm"),pw:H().default("1.5mm"),p:H().default("1.475mm")}).transform(t=>({...t,wave:t.wave??(t.reflow===void 0?!0:!t.reflow),reflow:t.reflow??(t.wave===void 0?!1:!t.wave)})),dS=t=>Number.parseFloat(t.replace("mm","")),CZA=({pitch:t,width:A,pinNumber:e})=>{const n={1:{x:-A/2-.1,y:t},2:{x:-A/2-.1,y:0},3:{x:-A/2-.1,y:-t},4:{x:A/2+.1,y:-t},5:{x:A/2+.1,y:0},6:{x:A/2+.1,y:t}}[e];if(!n)throw new Error(`Invalid pin number: ${e}`);return n},lZA=t=>{const A=[],e=dS(t.p),i=dS(t.pl),o=dS(t.pw),n=dS(t.w),s=dS(t.h);if(t.wave){const l={1:({padWidth:Q,padHeight:E})=>Qi(1,-e,e,E,Q),2:({padWidth:Q,padHeight:E})=>Qi(2,-e,-e,E,Q),3:({padWidth:Q,padHeight:E})=>c5(3,-e,0,dS(t.pillw),dS(t.pillh)),4:({padWidth:Q,padHeight:E})=>c5(4,e,0,dS(t.pillw),dS(t.pillh)),5:({padWidth:Q,padHeight:E})=>Qi(5,e,e,E,Q),6:({padWidth:Q,padHeight:E})=>Qi(6,e,-e,E,Q)};for(let Q=1;Q<=t.num_pins;Q++){const E=l[Q];E&&A.push(E({padWidth:i,padHeight:o}))}}else for(let l=1;l<=t.num_pins;l++){const{x:Q,y:E}=CZA({pitch:e,width:n,pinNumber:l});A.push(Qi(l,Q,E,i,o))}const r={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-n/3,y:s/2+e/1.3},{x:n/3,y:s/2+e/1.3}],stroke_width:.05},a={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_2",route:[{x:-n/3,y:-s/2-e/1.3},{x:n/3,y:-s/2-e/1.3}],stroke_width:.05},g=Yi(0,s+.5,.3),I=CZA({pitch:e,width:n,pinNumber:1}),c=t.wave?1:.5,B=t.wave?.7:.3;I.x-=t.wave?o:o*1.7;const C={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"pin1_indicator",route:[{x:I.x+c/2,y:I.y},{x:I.x-c/2,y:I.y+B/2},{x:I.x-c/2,y:I.y-B/2},{x:I.x+c/2,y:I.y}],stroke_width:.05};return[g,r,a,C,...A]},uQt=t=>{if(t.wave){const e=hQt.parse({...t,fn:"sot457"});return{circuitJson:lZA(e),parameters:e}}const A=EQt.parse(t);return{circuitJson:lZA(A),parameters:A}},dQt=Ji.extend({fn:H(),num_pins:xA(6).default(6),w:H().default("1.1mm"),h:H().default("1.45mm"),p:H().default("0.35mm"),pl:H().default("0.2mm"),pw:H().default("0.2mm"),string:H().optional()}),pQt=t=>{const A=dQt.parse({...t,fn:"sot963"}),e=Ae.parse(A.w),i=Ae.parse(A.h),o=Ae.parse(A.p),n=Ae.parse(A.pl),s=Ae.parse(A.pw),r=[];for(let C=0;C<6;C++){const{x:l,y:Q}=QZA(C+1,e,o,n);r.push(Qi(C+1,l,Q,n,s))}const a={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-e/2,y:i/2},{x:e/2,y:i/2}],stroke_width:.05,pcb_silkscreen_path_id:""},g={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-e/2,y:-i/2},{x:e/2,y:-i/2}],stroke_width:.05,pcb_silkscreen_path_id:""},I=QZA(1,e,o,n),c={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"pin_marker_1",route:[{x:I.x-n/2-.3,y:I.y},{x:I.x-n/2-.45,y:I.y+.15},{x:I.x-n/2-.45,y:I.y-.15},{x:I.x-n/2-.3,y:I.y}],stroke_width:.05,pcb_silkscreen_path_id:"pin_marker_1"},B=Yi(0,i/2+.4,.25);return{circuitJson:[...r,a,g,B,c],parameters:A}},QZA=(t,A,e,i)=>{const o=A/2-i/2;return t<=3?{x:-o,y:e-(t-1)*e}:{x:o,y:-e+(t-4)*e}},fQt=Ji.extend({fn:H(),num_pins:ei([xA(3),xA(2)]).default(3),p:H().default("3.8mm"),id:H().default("1.25mm"),od:H().default("2.35mm"),ca:H().default("14mm").describe("Caliper axis (width or diameter of the potentiometer body or adjustment knob)"),w:H().default("5.35mm"),h:H().default("4mm"),string:H().optional()}),yQt=t=>{const{p:A,id:e,od:i,h:o,ca:n}=t,s=Number.parseFloat(o),r=Number.parseFloat(n);return[qn(1,0,r/4+.3,e,i),qn(2,s,0,e,i),qn(3,0,-r/4-.3,e,i)]},wQt=t=>{const A=t.string?.match(/^potentiometer_(\d+)/),e=A?Number.parseInt(A[1],10):3,i=fQt.parse({...t,num_pins:e});let o=[];i.num_pins===3&&(o=yQt(i));const n=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:n-1.75},{x:0,y:n},{x:s,y:n},{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:-n},{x:0,y:-n},{x:0,y:-n+1.75}],stroke_width:.1,pcb_silkscreen_path_id:""},I=Number.parseFloat(i.w)/2,c=Yi(I,n+1,.5);return{circuitJson:[...o,a,g,c],parameters:i}},mQt=Ji.extend({fn:H(),p:Ae.optional().default("7.5mm"),id:Ae.optional().default("1mm"),od:Ae.optional().default("2mm"),d:Ae.optional().default("10.5mm")}),DQt=(t,A,e,i,o)=>{const n=[],s=[];for(let r=0;r<=50;r++){const a=r/50*Math.PI,g=t+Math.cos(a)*e,I=A+Math.sin(a)*e;g<t-i&&I>=A-o/2&&I<=A+o/2||n.push({x:g,y:I})}for(let r=0;r<=50;r++){const a=Math.PI+r/50*Math.PI,g=t+Math.cos(a)*e,I=A+Math.sin(a)*e;g<t-i&&I>=A-o/2&&I<=A+o/2||s.push({x:g,y:I})}return{topArc:n,bottomArc:s}},SQt=t=>{const A=mQt.parse(t),{p:e,id:i,od:o,d:n}=A,s=[qn(1,-e/2,0,i,o),qn(2,e/2,0,i,o)],{topArc:r,bottomArc:a}=DQt(0,0,n/2+.1,o/2,o),g={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:r,stroke_width:.1,pcb_silkscreen_path_id:""},I={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:a,stroke_width:.1,pcb_silkscreen_path_id:""},c={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:0,y:n/2+.1},{x:0,y:-(n/2+.1)}],stroke_width:.1,pcb_silkscreen_path_id:""},B=-(n/2+.5),C=o/2+1.5,l=.5,Q={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:B-l,y:C},{x:B+l,y:C}],stroke_width:.1,pcb_silkscreen_path_id:""},E={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:B,y:C-l},{x:B,y:C+l}],stroke_width:.1,pcb_silkscreen_path_id:""},h=Yi(0,n/2+1,.5);return{circuitJson:[...s,g,I,c,Q,E,h],parameters:A}},bQt=Ji.extend({fn:H(),num_pins:xA(2).default(2),w:H().default("6.5mm"),h:H().default("3mm"),pl:H().default("1.75mm"),pw:H().default("2.40mm"),p:H().default("4.75mm")}),xQt=t=>{const A=bQt.parse(t),e=Yi(0,Ae.parse(A.h)-.5,.3),i={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:Ae.parse(A.p)/2,y:Ae.parse(A.h)/2},{x:-Ae.parse(A.w)/2-.3,y:Ae.parse(A.h)/2},{x:-Ae.parse(A.w)/2-.3,y:-Ae.parse(A.h)/2},{x:Ae.parse(A.p)/2,y:-Ae.parse(A.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""};return{circuitJson:GQt(A).concat(i,e),parameters:A}},kQt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e/2,y:0}:{x:e/2,y:0}},GQt=t=>{const A=[];for(let e=1;e<=t.num_pins;e++){const{x:i,y:o}=kQt({pn:e,p:Number.parseFloat(t.p)});A.push(Qi(e,i,o,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return A},FQt=Ji.extend({fn:H(),num_pins:WA().default(3),w:H().default("2.45mm"),h:H().default("2.40mm"),pl:H().default("1.225mm"),pw:H().default("0.5mm"),p:H().default("0.95mm"),string:H().optional()}),RQt=t=>{const A=t.string?.match(/^sot323_(\d+)/),e=A?Number.parseInt(A[1],3):3,i=FQt.parse({...t,num_pins:e});if(i.num_pins===3)return{circuitJson:NQt(i),parameters:i};throw new Error("Invalid number of pins")},MQt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e,y:.65}:A===2?{x:-e,y:-.65}:{x:e,y:0}},NQt=t=>{const A=[];for(let r=0;r<t.num_pins;r++){const{x:a,y:g}=MQt({num_pins:t.num_pins,pn:r+1,w:Number.parseFloat(t.w),h:Number.parseFloat(t.h),pl:Number.parseFloat(t.pl),p:Number.parseFloat(t.p)});A.push(Qi(r+1,a,g,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}const e=Yi(0,Number.parseInt(t.h)/2+1,.3),i=Number.parseFloat(t.w)/2-Number.parseFloat(t.pl),o=Number.parseFloat(t.h)/2,n={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-i,y:o+.3},{x:i,y:o+.3},{x:i,y:o/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:-o-.3},{x:i,y:-o-.3},{x:i,y:-o/2}],type:"pcb_silkscreen_path",stroke_width:.1};return[...A,n,s,e]},_Qt=Ji.extend({fn:H(),circle:ce().optional(),rect:ce().optional(),square:ce().optional(),pill:ce().optional(),d:Ae.optional(),pd:Ae.optional(),diameter:Ae.optional(),r:Ae.optional(),pr:Ae.optional(),radius:Ae.optional(),w:Ae.optional(),pw:Ae.optional(),width:Ae.optional(),h:Ae.optional(),ph:Ae.optional(),height:Ae.optional(),s:Ae.optional(),size:Ae.optional(),string:H().optional()}).transform(t=>{let A="rect";t.circle&&(A="circle"),t.square&&(A="square"),t.rect&&(A="rect"),t.pill&&(A="pill");let e,i,o;return A==="circle"?t.r!==void 0?e=mr(t.r):t.pr!==void 0?e=mr(t.pr):t.radius!==void 0?e=mr(t.radius):t.d!==void 0?e=mr(t.d)/2:t.pd!==void 0?e=mr(t.pd)/2:t.diameter!==void 0?e=mr(t.diameter)/2:e=mr("1mm")/2:(t.w!==void 0?i=mr(t.w):t.pw!==void 0?i=mr(t.pw):t.width!==void 0?i=mr(t.width):t.s!==void 0?i=mr(t.s):t.size!==void 0?i=mr(t.size):i=mr("1mm"),t.h!==void 0?o=mr(t.h):t.ph!==void 0?o=mr(t.ph):t.height!==void 0?o=mr(t.height):A==="square"||A==="rect"?o=i:o=mr("1mm")),{fn:t.fn,shape:A,radius:e,width:i,height:o}}),vQt=t=>{const A=_Qt.parse(t),{shape:e,radius:i,width:o,height:n}=A;let s,r;return e==="circle"?(s=VWA(1,{x:0,y:0,radius:i}),r=i+.5):e==="pill"?(s=c5(1,0,0,o,n),r=Math.max(o,n)/2+.5):(s=Qi(1,0,0,o,n),r=n/2+.5),{circuitJson:[s,Yi(0,r,.2)],parameters:A}},UQt=Ji.extend({fn:H(),d:Ae.optional(),hd:Ae.optional(),r:Ae.optional(),hr:Ae.optional(),pd:Ae.optional(),pr:Ae.optional(),squarepad:ce().optional().default(!1)}).transform(t=>{let A;t.d!==void 0?A=mr(t.d):t.hd!==void 0?A=mr(t.hd):t.r!==void 0?A=mr(t.r)*2:t.hr!==void 0?A=mr(t.hr)*2:A=mr("1mm");let e;return t.pd!==void 0?e=mr(t.pd):t.pr!==void 0?e=mr(t.pr)*2:e=A*(1.5/1),{fn:t.fn,d:A,pd:e,squarepad:t.squarepad??!1}}),LQt=t=>{const A=UQt.parse(t),{d:e,pd:i,squarepad:o}=A;return{circuitJson:[o?uS(1,0,0,e,i,i):qn(1,0,0,e,i),Yi(0,i/2+.5,.2)],parameters:A}},HQt=Ji.extend({fn:H(),num_pins:xA(6).default(6),h:H().default("1.6mm"),pl:H().default("1mm"),pw:H().default("0.7mm"),p:H().default("0.95mm")}),YQt=t=>{const A=HQt.parse(t);return{circuitJson:JQt(A),parameters:A}},EZA=t=>{const{p:A,h:e,pn:i}=t;if(i===1)return{x:-e/2-.5,y:A};if(i===2)return{x:-e/2-.5,y:0};if(i===3)return{x:-e/2-.5,y:-A};if(i===4)return{x:e/2+.5,y:-A};if(i===5)return{x:e/2+.5,y:0};if(i===6)return{x:e/2+.5,y:A};throw new Error("Invalid pin number")},JQt=t=>{const A=[];for(let c=1;c<=t.num_pins;c++){const{x:B,y:C}=EZA({h:Number.parseFloat(t.h),p:Number.parseFloat(t.p),pn:c});A.push(Qi(c,B,C,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}const e=t.num_pins/2*Number.parseFloat(t.p),i=Number.parseFloat(t.h),o={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-e/3,y:i/2+Number.parseFloat(t.p)/1.3},{x:e/3,y:i/2+Number.parseFloat(t.p)/1.3}],type:"pcb_silkscreen_path",stroke_width:.05},n={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_2",route:[{x:-e/3,y:-i/2-Number.parseFloat(t.p)/1.3},{x:e/3,y:-i/2-Number.parseFloat(t.p)/1.3}],type:"pcb_silkscreen_path",stroke_width:.05},s=Yi(0,i+.3,.3),r=EZA({h:Number.parseFloat(t.h),p:Number.parseFloat(t.p),pn:1});r.x=r.x-Number.parseFloat(t.pw)*1.5;const a=.7,g=.3,I={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,o,n,I]},TQt=Ji.extend({fn:H(),num_pins:WA().default(4),w:H().default("3.2mm"),h:H().default("2.6mm"),pl:H().default("1.35mm"),pw:H().default("0.50mm"),p:H().default("0.6mm"),string:H().optional()}),KQt=t=>{const A=t.string?.match(/^sot343_(\d+)/),e=A?Number.parseInt(A[1],4):4,i=TQt.parse({...t,num_pins:e});if(i.num_pins===4)return{circuitJson:PQt(i),parameters:i};throw new Error("Invalid number of pins")},qQt=t=>{const{pn:A,p:e}=t;return A===1?{x:-e*1.92,y:-.65}:A===2?{x:-e*1.92,y:.65}:A===3?{x:e,y:.65}:A===4?{x:e,y:-.65}:{x:0,y:0}},PQt=t=>{const A=[],e=Number.parseFloat(t.w),i=Number.parseFloat(t.h),o=Number.parseFloat(t.pl),n=Number.parseFloat(t.pw),s=Number.parseFloat(t.p);let r=1/0,a=-1/0,g=1/0,I=-1/0;for(let d=0;d<t.num_pins;d++){const{x:f,y:m}=qQt({num_pins:t.num_pins,pn:d+1,p:s});A.push(Qi(d+1,f,m,o,n)),f<r&&(r=f),f>a&&(a=f),m<g&&(g=m),m>I&&(I=m)}const c=(r+a)/2,B=I-g,C=i*.3,l=B/2+C;let Q=e*.8;i<=2.6&&(Q/=2);const E=Yi(c,l+.5,.3),h={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_top",route:[{x:c-Q/2,y:l},{x:c+Q/2,y:l}],type:"pcb_silkscreen_path",stroke_width:.1},u={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_bottom",route:[{x:c-Q/2,y:-l},{x:c+Q/2,y:-l}],type:"pcb_silkscreen_path",stroke_width:.1};return[...A,h,u,E]},OQt=Ji.extend({fn:H()}),WQt=t=>{const A=OQt.parse(t),e=[],i=.5-.15,o=1.5,s=.5/2,r=75,a=-37/2;for(let D=0;D<r;D++){const x=D+1;if(x>=24&&x<=31)continue;const F=a-D*s,k=x%2===0,v=o+(k?.25:0),Y=.5-v/2,P=Qi(x,Y,F,v,i);P.layer=k?"bottom":"top",e.push(P)}const g=46*.0254,I=137*.0254,c=261*.0254,B={type:"pcb_cutout",pcb_cutout_id:"",shape:"rect",center:{x:-I/2+o/2,y:a-c},width:I,height:g},C={x:-.5,y:a},l={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"};let Q=1/0,E=-1/0,h=1/0,u=-1/0;const d=(D,x,F=0,k=0)=>{Q=Math.min(Q,D-F/2),E=Math.max(E,D+F/2),h=Math.min(h,x-k/2),u=Math.max(u,x+k/2)};for(const D of e)d(D.x,D.y,D.width,D.height);d(B.center.x,B.center.y,B.width,B.height);for(const D of l.route)d(D.x,D.y);const f=(Q+E)/2,m=(h+u)/2,b=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(x=>({x:x.x-f,y:x.y-m})))};for(const D of e)b(D);return b(B),b(l),{circuitJson:[...e,B,l],parameters:A}},ZQt=Ji.extend({fn:H(),num_pins:WA().default(3),inline:ce().default(!1),p:H().default("1.27mm"),id:H().default("0.75mm"),od:H().default("1.3mm"),w:H().default("4.8mm"),h:H().default("4.0mm")}),VQt=t=>{const A=ZQt.parse(t),e=Number.parseFloat(A.p),i=Number.parseFloat(A.w),o=Number.parseFloat(A.h),n=A.inline?1.05:Number.parseFloat(A.od),s=A.inline?1.5:n,r=[uS(1,0,0,A.id,n,s,0,0),A.inline?$U(2,e,0,A.id,n,s):qn(2,e,e,A.id,n),A.inline?$U(3,e*2,0,A.id,n,s):qn(3,e*2,0,A.id,n)],a=i/2,g=A.inline?e-.09:e,I=.2,c=I+a-o,B=Array.from({length:32},(Q,E)=>{const h=Math.PI*E/31;return{x:g+a*Math.cos(h),y:I+a*Math.sin(h)}}),C={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"",stroke_width:.12,route:[...B,{x:g-a,y:c},{x:g+a,y:c},B[0]]},l=Yi(g,I+a+1,.5);return{circuitJson:[...r,C,l],parameters:A}};function jQt(t){return t!=null}var zQt=(t,A)=>{if(!A)return t;const e=t.filter(I=>I.type==="pcb_smtpad"||I.type==="pcb_plated_hole"||I.type==="pcb_thtpad");if(e.length===0)return t;let i=1/0,o=-1/0,n=1/0,s=-1/0;const r=(I,c,B=0,C=0)=>{const l=I-B/2,Q=I+B/2,E=c-C/2,h=c+C/2;i=Math.min(i,l),o=Math.max(o,Q),n=Math.min(n,E),s=Math.max(s,h)};for(const I of e)if(I.type==="pcb_smtpad"){const c=I.shape==="circle"?I.radius*2:I.width,B=I.shape==="circle"?I.radius*2:I.height;r(I.x,I.y,c,B)}else if(I.type==="pcb_plated_hole"){const c=I.outer_diameter??I.hole_diameter;r(I.x,I.y,c,c)}else if(I.type==="pcb_thtpad"){const c=I.diameter;r(I.x,I.y,c,c)}let a=0,g=0;switch(A){case"center":a=(i+o)/2,g=(n+s)/2;break;case"bottomleft":a=i,g=n;break;case"bottomcenter":case"centerbottom":a=(i+o)/2,g=n;break;case"topcenter":case"centertop":a=(i+o)/2,g=s;break;case"leftcenter":case"centerleft":a=i,g=(n+s)/2;break;case"rightcenter":case"centerright":a=o,g=(n+s)/2;break;case"pin1":const I=e.find(c=>c.port_hints?.[0]==="1")||e[0];a=I.x,g=I.y;break}if(a===0&&g===0)return t;for(const I of t){if(typeof I.x=="number"&&(I.x-=a),typeof I.y=="number"&&(I.y-=g),I.center&&typeof I.center.x=="number"&&(I.center.x-=a,I.center.y-=g),I.type==="pcb_silkscreen_path")for(const c of I.route)c.x-=a,c.y-=g;I.type==="pcb_silkscreen_text"&&I.anchor_position&&(I.anchor_position.x-=a,I.anchor_position.y-=g)}return t},XQt=(t,A)=>{const e=t.filter(i=>i.type==="pcb_silkscreen_text");if(e.length===0)return t;for(const i of e)A.norefdes&&(i.text="");return t},$Qt=(t,A)=>A.nosilkscreen?t.filter(e=>e.type!=="pcb_silkscreen_path"&&e.type!=="pcb_silkscreen_text"):t,AEt=t=>{let A=Q5();const i=t.replace(/^((?:\d{4}|\d{5}))(?=$|_)/,"res$1").split(/_(?!metric)/).map(o=>{const n=o.match(/([a-zA-Z]+)([\(\d\.\+\?].*)?/);if(!n)return null;const[,s,r]=n;if(!s)return null;const a=s.toLowerCase();return r?.includes("?")?null:{fn:a,v:r}}).filter(jQt);for(const{fn:o,v:n}of i)A=A[o](n);return A.setString(t),A},eEt=()=>Object.keys(hS),Q5=()=>{const t=new Proxy({},{get:(A,e)=>{if(e==="soup"||e==="circuitJson"){if("fn"in A&&hS[A.fn])return()=>{const{circuitJson:i}=hS[A.fn](A),o=$Qt(i,A),n=XQt(o,A);return zQt(n,A.origin)};if(!hS[A.fn])throw new Error(`Invalid footprint function, got "${A.fn}"${A.string?`, from string "${A.string}"`:""}`);return()=>{throw new Error(`No function found for footprinter, make sure to specify .dip, .lr, .p, etc. Got "${e}"`)}}if(e==="json"){if(!hS[A.fn])throw new Error(`Invalid footprint function, got "${A.fn}"${A.string?`, from string "${A.string}"`:""}`);return()=>hS[A.fn](A).parameters}return e==="getFootprintNames"?()=>Object.keys(hS):e==="params"?()=>A:e==="setString"?i=>(A.string=i,t):i=>(Object.keys(A).length===0?`${e}${i}`in hS?(A[`${e}${i}`]=!0,A.fn=`${e}${i}`):(A[e]=!0,A.fn=e,e==="res"||e==="cap"?i&&(typeof i=="string"&&i.includes("_metric")?A.metric=i.split("_metric")[0]:A.imperial=i):A.num_pins=Number.isNaN(Number.parseFloat(i))?void 0:Number.parseFloat(i)):!i&&["w","h","p"].includes(e)||(A[e]=i??!0),t)}});return t};Q5.string=AEt,Q5.getFootprintNames=eEt;var tEt=Q5,hZA=Symbol("Fragment");function nCA(t,A,...e){const i=e.length?e:A?.children!==void 0?[A.children]:[],o=[],n=(Array.isArray(i)?i:[i]).flat(1/0);for(const s of n)s==null||s===!1||(Array.isArray(s)?o.push(...s):o.push(s));return{type:t,props:(A&&A.children!==void 0?{...A,children:void 0}:A)||{},children:o}}var ut=Symbol("Cuboid"),uZA=Symbol("Cube"),Vp=Symbol("Cylinder"),dZA=Symbol("Sphere"),AL=Symbol("RoundedCuboid"),Zi=Symbol("Translate"),pQ=Symbol("Rotate"),lE=Symbol("Union"),nF=Symbol("Subtract"),BI=Symbol("Hull"),fs=Symbol("Colorize"),eL=Symbol("Polygon"),tL=Symbol("ExtrudeLinear"),jp=Symbol("RoundedCylinder"),Jo=hZA,ee=(t,A,e)=>nCA(t,A),Pt=(t,A,e)=>nCA(t,A),zB=({center:t,width:A,length:e,height:i,heightAboveSurface:o=.15,color:n="#555",taperRatio:s=.12,faceRatio:r=.75,straightHeightRatio:a=.5,includeNotch:g=!0,notchRadius:I,notchPosition:c,notchRotation:B=[0,0,0],notchLength:C=.5,notchWidth:l=.25,chamferSize:Q=0})=>{const E=i*a,h=i-E,u=Math.min(A,e)*s,d=Math.max(A-u,A*r),f=Math.max(e-u,e*r),m=Math.min(A,e)*.12,b=I??m,D={x:0,y:e/2-b*.25,z:i},x=c??D,F=Pt(lE,{children:[Pt(BI,{children:[ee(Zi,{z:.005,children:ee(ut,{size:[d,f,.01]})}),ee(Zi,{z:E,children:ee(ut,{size:[A,e,.01]})})]}),Pt(BI,{children:[ee(Zi,{z:E,children:ee(ut,{size:[A,e,.01]})}),ee(Zi,{z:E+h,children:ee(ut,{size:[d,f,.01]})})]})]}),k=(_,Y)=>ee(Zi,{offset:{x:_,y:Y,z:0},children:ee(pQ,{rotation:[0,0,Math.PI/4],children:ee(ut,{size:[Q*Math.SQRT2,Q*Math.SQRT2,i*3]})})});let v=F;if(Q>0){const _=A/2,Y=e/2;v=Pt(nF,{children:[F,k(_,Y),k(-_,Y),k(_,-Y),k(-_,-Y)]})}return ee(fs,{color:n,children:ee(Zi,{offset:t,children:ee(Zi,{offset:{x:0,y:0,z:o},children:g?Pt(nF,{children:[v,ee(Zi,{offset:x,children:ee(pQ,{rotation:B,children:ee(Vp,{radius:b,height:l})})})]}):v})})})},iEt=t=>Array.from({length:t},(A,e)=>e);function sCA(t,A){if(t.length<2)throw new Error("Stroke must have at least two points");const e=Array.isArray(t[0])?t.map(([I,c])=>({x:I,y:c})):t,i=A/2,o=[],n=[];function s(I,c){const B=c.x-I.x,C=c.y-I.y,l=Math.sqrt(B*B+C*C);return{x:-C/l,y:B/l}}function r(I,c,B){const C={x:I.x+c.x*i*B,y:I.y+c.y*i*B};B>0?o.push(C):n.unshift(C)}const a=s(e[0],e[1]);r(e[0],a,1),r(e[0],a,-1);for(let I=1;I<e.length-1;I++){const c=e[I-1],B=e[I],C=e[I+1],l=s(c,B),Q=s(B,C),E=l.x+Q.x,h=l.y+Q.y,u=Math.sqrt(E*E+h*h);if(u/2>2*i)r(B,l,1),r(B,Q,1),r(B,l,-1),r(B,Q,-1);else{const f=1/u;r(B,{x:E*f,y:h*f},1),r(B,{x:E*f,y:h*f},-1)}}const g=s(e[e.length-2],e[e.length-1]);return r(e[e.length-1],g,1),r(e[e.length-1],g,-1),[...o,...n]}var oEt=t=>{const A=Math.min(...t.map(r=>r.x)),e=Math.max(...t.map(r=>r.x)),i=Math.min(...t.map(r=>r.y)),s=5.47/(Math.max(...t.map(r=>r.y))-i);return t.map(r=>({x:(r.x-A-(e-A)/2)*s,y:(r.y-i)*s}))},nEt=oEt([{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}]),pZA=5.47,E5=.5,sEt=({x:t,y:A,z:e})=>{const i=t>0;return Pt(Jo,{children:[ee(Zi,{offset:{x:t+.25/2,y:A,z:e},children:ee(pQ,{rotation:["-90deg",0,"90deg"],children:ee(tL,{height:.25,children:ee(eL,{points:nEt.slice().reverse().map(o=>[o.x,o.y])})})})}),ee(Zi,{offset:{x:t,y:A+(i?1:-1),z:e},children:ee(pQ,{rotation:["-90deg","90deg",i?"180deg":"0deg"],children:ee(tL,{height:2,children:ee(eL,{points:sCA([[0,0],[-1,0],[-1,-1]],.25).map(o=>[o.x,o.y])})})})})]})},rEt=({numPins:t=8,pitch:A=2.54,bodyWidth:e=6.4,rowSpacing:i})=>{const o=Math.floor(t/2),n=i??(e>=7?e:e+1.22),s=e>=7?n-1.22:e;return Pt(Jo,{children:[iEt(t).map(r=>{const a=r%o,g=(Math.floor(r/o)-.5)*2;return ee(sEt,{x:g*n/2,y:a*A-(o-1)/2*A,z:pZA/2+E5})}),ee(zB,{width:s,length:o*A+.5,height:pZA-E5,heightAboveSurface:E5,center:{x:0,y:0,z:E5}})]})};function aEt(t,{height:A,padContactLength:e,curveLength:i,bodyDistance:o,steepness:n=10}){i||(i=o*.3);let s=o-e-i;s<0&&(i+=s,s=0);const r=e*.75,a=e+i+(o-e-i)*.25;if(t<=r)return 0;if(t>=a)return A;const g=(t-r)/(a-r);return A/(1+Math.exp(-n*(g-.5)))}var qo=t=>{const{thickness:A,width:e,padContactLength:i,bodyDistance:o,height:n,rotation:s}=t,r=15,a=Array.from({length:r}).map((I,c)=>c/(r-1)*o).map(I=>[I,aEt(I,t)]),g=sCA(a,A);return ee(fs,{color:"#fff",children:ee(Zi,{offset:{z:0,y:0,x:0,...t.position},children:ee(pQ,{rotation:["90deg",0,s??0],children:ee(Zi,{offset:{x:0,y:0,z:-e/2},children:ee(tL,{height:e,children:ee(eL,{points:g.map(I=>[I.x,I.y])})})})})})})},gEt=({pinCount:t,leadLength:A,leadWidth:e,pitch:i,bodyWidth:o})=>{const n=Math.ceil(t/2),s=i*t/2+e/2,r=(n-1)*i/2,a=.25;return Pt(Jo,{children:[Array.from({length:n}).map((g,I)=>ee(qo,{position:{x:-o/2-A,y:I*i-r,z:a/2},width:e,thickness:a,padContactLength:A,bodyDistance:A+1,height:.8})),Array.from({length:n}).map((g,I)=>ee(qo,{rotation:Math.PI,position:{x:o/2+A,y:I*i-r,z:a/2},width:e,thickness:a,padContactLength:A,bodyDistance:A+1,height:.8})),ee(zB,{center:{x:0,y:0,z:a/2},width:o-e-1,length:s,height:1.5})]})},IEt=({pinCount:t,padContactLength:A=.4,leadWidth:e=.2,pitch:i=.65,bodyWidth:o=3})=>{const n=Math.ceil(t/2),s=(n-1)*i/2,r=.2;return Pt(Jo,{children:[Array.from({length:n}).map((a,g)=>ee(qo,{position:{x:-o/2-A-.3,y:g*i-s,z:r/2},width:e,thickness:r,padContactLength:A,bodyDistance:A+.4,height:.6})),Array.from({length:n}).map((a,g)=>ee(qo,{rotation:Math.PI,position:{x:o/2+A+.3,y:g*i-s,z:r/2},width:e,thickness:r,padContactLength:A,bodyDistance:A+.4,height:.6})),ee(zB,{center:{x:0,y:0,z:r/2},width:o,length:o,height:1.1,notchRadius:.35,heightAboveSurface:.1,taperRatio:.09})]})},rCA=1,aCA=.5,XN=.5,iL=.2,cEt=rCA-iL*2,fZA=({color:t="#333"})=>Pt(Jo,{children:[ee(ut,{size:[cEt,aCA,XN],offset:[0,0,XN/2],color:t}),ee(ut,{size:[iL,XN,aCA],offset:[rCA/2-iL/2,0,XN/2],color:"#ccc"}),ee(ut,{size:[iL,XN,aCA],offset:[-rCA/2+iL/2,0,XN/2],color:"#ccc"})]}),gCA=1.6,BEt=gCA-.3*2,h5=.3,ICA=.85,$N=.6,yZA=({color:t="#333"})=>Pt(Jo,{children:[ee(ut,{size:[BEt,ICA,$N],offset:[0,0,$N/2],color:t}),ee(ut,{size:[h5,ICA,$N],offset:[gCA/2-h5/2,0,$N/2],color:"#ccc"}),ee(ut,{size:[h5,ICA,$N],offset:[-gCA/2+h5/2,0,$N/2],color:"#ccc"})]}),cCA=2,BCA=1.25,A_=.55,oL=.5,CEt=cCA-oL*2,wZA=({color:t="#333"})=>Pt(Jo,{children:[ee(ut,{size:[CEt,BCA,A_],offset:[0,0,A_/2],color:t}),ee(ut,{size:[oL,BCA,A_],offset:[cCA/2-oL/2,0,A_/2],color:"#ccc"}),ee(ut,{size:[oL,BCA,A_],offset:[-cCA/2+oL/2,0,A_/2],color:"#ccc"})]}),lEt=({pinCount:t,pitch:A,leadWidth:e,padContactLength:i,bodyWidth:o})=>{const n=t/4;A||(A=QEt(t,o)),i||(i=EEt(t)),e||(e=hEt(t,o)),o||(o=A*(n+4));const s=o,r=(n-1)*A/2,a=s+2*i,g=a,I=.8,c=.15,B=(g-o)/2+.5;return Pt(Jo,{children:[Array.from({length:n}).map((C,l)=>ee(qo,{position:{x:-g/2-.4,y:l*A-r,z:c/2},width:e,thickness:c,padContactLength:i,bodyDistance:B,height:I})),Array.from({length:n}).map((C,l)=>ee(qo,{rotation:Math.PI,position:{x:g/2+.4,y:l*A-r,z:c/2},width:e,thickness:c,padContactLength:i,bodyDistance:B,height:I})),Array.from({length:n}).map((C,l)=>ee(qo,{rotation:Math.PI/2,position:{x:l*A-r,y:-a/2-.4,z:c/2},width:e,thickness:c,padContactLength:i,bodyDistance:B,height:I})),Array.from({length:n}).map((C,l)=>ee(qo,{rotation:-Math.PI/2,position:{x:l*A-r,y:a/2+.4,z:c/2},width:e,thickness:c,padContactLength:i,bodyDistance:B,height:I})),ee(zB,{center:{x:0,y:0,z:0},width:o,length:s,height:1.5,taperRatio:.03,chamferSize:.7,notchPosition:{x:-(s/2-1.5),y:o/2-1.5,z:1.5},notchRadius:1.5/2})]})},QEt=(t,A)=>{switch(t){case 44:case 64:return .8;case 52:return A===14?1:.65;case 208:return .5;default:return .5}},EEt=t=>{switch(t){case 32:return .6;case 40:return .6;case 52:case 64:return .65;case 208:return 1.65;default:return .6}},hEt=(t,A)=>{switch(t){case 44:case 64:return .5;case 52:return A===14?.45:.55;case 208:return .3;default:return .25}},uEt=({numberOfPins:t,pitch:A=2.54,longSidePinLength:e=6,invert:i,faceup:o,rows:n=1})=>{const a=Math.ceil(t/n),g=2.54,I=a*A,c=n>1?(n-1)*g+.63*3:.63*3,B=3,C=-((a-1)/2)*A,l=n>1?-((n-1)*g)/2:0,Q=E=>i||o?-E+2:E;return Pt(Jo,{children:[ee(ut,{color:"#222",size:[I,c,2],center:[0,l,Q(2/2)]}),Array.from({length:t},(E,h)=>{const u=Math.floor(h/a),d=h%a,f=C+d*A,m=-u*g;return Pt(Jo,{children:[!o&&ee(fs,{color:"gold",children:Pt(BI,{children:[ee(ut,{color:"gold",size:[.63,.63,B*.9],center:[f,m,Q(2*.9+2/2)]}),ee(ut,{color:"gold",size:[.63/1.8,.63/1.8,B],center:[f,m,Q(2+2/2)]})]})}),ee(fs,{color:"gold",children:Pt(BI,{children:[ee(ut,{color:"gold",size:[.63,.63,e*.9],center:[f,m,Q(-e/2*.9)]}),ee(ut,{color:"gold",size:[.63/1.8,.63/1.8,e],center:[f,m,Q(-e/2)]})]})})]})})]})},dEt=t=>{const A=["left","bottom","right","top"],{pin_count:e,pn:i,w:o,h:n,p:s,pl:r}=t,a=e/4,g=A[Math.floor((i-1)/a)],I=(i-1)%a,c=s*(a-1),B=s*(a-1),C=-r/2;switch(g){case"left":return{x:-o/2-C,y:B/2-I*s,o:"vert"};case"bottom":return{x:-c/2+I*s,y:-n/2-C,o:"horz"};case"right":return{x:o/2+C,y:-B/2+I*s,o:"vert"};case"top":return{x:c/2-I*s,y:n/2+C,o:"horz"};default:throw new Error("Invalid pin number")}},pEt=({num_pins:t,cw:A,ccw:e,startingpin:i})=>{const o=[],n=t/4;let s=1;const r={};for(const a of i??[])r[a]=!0;!r.leftside&&!r.topside&&!r.rightside&&!r.bottomside&&(r.leftside=!0),!r.bottompin&&!r.leftpin&&!r.rightpin&&!r.toppin&&(r.leftside?r.toppin=!0:r.topside?r.rightpin=!0:r.rightside?r.bottompin=!0:r.bottomside&&(r.leftpin=!0)),r.leftside&&r.toppin?s=1:r.leftside&&r.bottompin?s=n:r.bottomside&&r.leftpin?s=n+1:r.bottomside&&r.rightpin?s=n*2:r.rightside&&r.bottompin?s=n*2+1:r.rightside&&r.toppin?s=n*3:r.topside&&r.rightpin?s=n*3+1:r.topside&&r.leftpin&&(s=n*4),o.push(-1);for(let a=0;a<t;a++)o[s]=a+1,s++,s>t&&(s=1);return o},fEt=({num_pins:t=16,bodyWidth:A=9,bodyLength:e=9,bodyThickness:i=.8,thermalPadSize:o,padWidth:n=.25,padLength:s=.25,pitch:r=.5,thermalPadThickness:a=.05})=>{const g=pEt({num_pins:t,cw:!0,ccw:!0}),I=[];for(let c=0;c<t;c++){const{x:B,y:C,o:l}=dEt({pin_count:t,pn:c+1,w:A,h:e,p:r,pl:s});let Q=n,E=s;l==="vert"&&([Q,E]=[E,Q]);const h=g[c+1];I.push({pn:h,x:B,y:C,pw:Q,pl:E})}return Pt(Jo,{children:[ee(fs,{color:"grey",children:ee(ut,{center:{x:0,y:0,z:i/2},size:[A,e,i]})}),I.map((c,B)=>ee(ut,{center:{x:c.x,y:c.y,z:a/2},size:[c.pw,c.pl,a]})),o?.length!==void 0&&o?.width!==void 0&&ee(ut,{center:{x:0,y:0,z:a/2},size:[o.width,o.length,a]})]})},yEt=fEt,wEt=()=>{const a=1.1999999999999997;return Pt(Jo,{children:[ee(qo,{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}),ee(qo,{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}),ee(qo,{position:{x:-2.8/2-a/4,y:0,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:a,height:.95}),ee(qo,{position:{x:-2.8/2-a/4,y:-1,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:a,height:.95}),ee(qo,{position:{x:-2.8/2-a/4,y:1,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:a,height:.95}),ee(zB,{center:{x:0,y:0,z:0},width:1.6,length:2.9,height:1.2})]})},mEt=wEt,DEt=({fullWidth:t=2.9,fullLength:A=2.8})=>{const I=(t-1.92)/2+.3;return Pt(Jo,{children:[ee(qo,{rotation:Math.PI,position:{x:t/2,y:0,z:.075},width:.4,thickness:.15,padContactLength:.25,bodyDistance:I,height:.45}),ee(qo,{position:{x:-t/2,y:-.95,z:.075},width:.4,thickness:.15,padContactLength:.25,bodyDistance:I,height:.45}),ee(qo,{position:{x:-t/2,y:.95,z:.075},width:.4,thickness:.15,padContactLength:.25,bodyDistance:I,height:.45}),ee(zB,{center:{x:0,y:0,z:0},width:1.92,length:2.9,height:1.1,straightHeightRatio:.45,heightAboveSurface:.05})]})},CCA=.6,lCA=.3,e_=.33,nL=.1,SEt=CCA-nL*2,mZA=({color:t="#333"})=>Pt(Jo,{children:[ee(ut,{size:[SEt,lCA,e_],offset:[0,0,e_/2],color:t}),ee(ut,{size:[nL,lCA,e_],offset:[CCA/2-nL/2,0,e_/2],color:"#ccc"}),ee(ut,{size:[nL,lCA,e_],offset:[-CCA/2+nL/2,0,e_/2],color:"#ccc"})]}),QCA=.4,ECA=.2,t_=.13,sL=.07,bEt=QCA-sL*2,DZA=({color:t="#333"})=>Pt(Jo,{children:[ee(ut,{size:[bEt,ECA,t_],offset:[0,0,t_/2],color:t}),ee(ut,{size:[sL,ECA,t_],offset:[QCA/2-sL/2,0,t_/2],color:"#ccc"}),ee(ut,{size:[sL,ECA,t_],offset:[-QCA/2+sL/2,0,t_/2],color:"#ccc"})]}),hCA=3.2,uCA=1.6,i_=.9,rL=.5,xEt=hCA-rL*2,SZA=({color:t="#333"})=>Pt(Jo,{children:[ee(ut,{size:[xEt,uCA,i_],offset:[0,0,i_/2],color:t}),ee(ut,{size:[rL,uCA,i_],offset:[hCA/2-rL/2,0,i_/2],color:"#ccc"}),ee(ut,{size:[rL,uCA,i_],offset:[-hCA/2+rL/2,0,i_/2],color:"#ccc"})]}),dCA=3.2,pCA=2.5,o_=1,aL=.6,kEt=dCA-aL*2,bZA=({color:t="#333"})=>Pt(Jo,{children:[ee(ut,{size:[kEt,pCA,o_],offset:[0,0,o_/2],color:t}),ee(ut,{size:[aL,pCA,o_],offset:[dCA/2-aL/2,0,o_/2],color:"#ccc"}),ee(ut,{size:[aL,pCA,o_],offset:[-dCA/2+aL/2,0,o_/2],color:"#ccc"})]}),fCA=5,yCA=2.5,n_=1.4,gL=.6,GEt=fCA-gL*2,xZA=({color:t="#333"})=>Pt(Jo,{children:[ee(ut,{size:[GEt,yCA,n_],offset:[0,0,n_/2],color:t}),ee(ut,{size:[gL,yCA,n_],offset:[fCA/2-gL/2,0,n_/2],color:"#ccc"}),ee(ut,{size:[gL,yCA,n_],offset:[-fCA/2+gL/2,0,n_/2],color:"#ccc"})]}),wCA=6.3,mCA=3.2,s_=1.8,IL=.8,FEt=wCA-IL*2,kZA=({color:t="#333"})=>Pt(Jo,{children:[ee(ut,{size:[FEt,mCA,s_],offset:[0,0,s_/2],color:t}),ee(ut,{size:[IL,mCA,s_],offset:[wCA/2-IL/2,0,s_/2],color:"#ccc"}),ee(ut,{size:[IL,mCA,s_],offset:[-wCA/2+IL/2,0,s_/2],color:"#ccc"})]}),REt=({numberOfPins:t,pitch:A=2.54,legsLength:e=3,outerDiameter:i=.945,innerDiameter:o=.945,rows:n=1})=>{const s=o/1.5,r=s*2+i,a=5,g=Math.ceil(t/n),I=2.54,c=(g-1)*A+i+A/2,B=n>1?(n-1)*I+r:r,C=s*1.6,l=-((g-1)/2)*A,Q=n>1?-((n-1)*I)/2:0,E=ee(fs,{color:"#1a1a1a",children:Pt(nF,{children:[ee(ut,{color:"#000",size:[c,B,a],center:[0,Q,a/2]}),Array.from({length:t},(h,u)=>{const d=Math.floor(u/g),f=u%g,m=l+f*A,b=-d*I;return o?ee(Vp,{height:a+.1,radius:o/2,center:[m,b,a/2],color:"#222"},u):ee(ut,{size:[C,C,a],center:[m,b,a/2]},u)})]})});return Pt(Jo,{children:[E,Array.from({length:t},(h,u)=>{const d=Math.floor(u/g),f=u%g,m=l+f*A,b=-d*I;return Pt(fs,{color:"silver",children:[Pt(BI,{children:[ee(ut,{color:"silver",size:[s,s,e*.9],center:[m,b,-e/2*.9]}),ee(ut,{color:"silver",size:[s/1.8,s/1.8,e],center:[m,b,-e/2]})]}),ee(ut,{color:"silver",size:[C,C,C*.5],center:[m,b,C/2*.5]})]},u)})]})},MEt=({width:t,length:A,innerDiameter:e=1})=>{const i=t,o=A,n=t*.7,s=e/2.5;return Pt(Jo,{children:[ee(AL,{color:"#1a1a1f",center:[0,0,n/2],size:[o,o,n],roundRadius:.3}),ee(AL,{color:"#f2f2f2",center:[0,0,n+n*.1/2.5],size:[o,o,n*.1],roundRadius:.14}),ee(Vp,{color:"#1a1a1f",height:n*.8,radius:i/3,center:[0,0,n+n*.8/2]}),ee(Vp,{color:"#1a1a1f",height:n*.2,radius:e/2,center:[o/3,o/3,n+n*.1/2]}),ee(Vp,{color:"#1a1a1f",height:n*.2,radius:e/2,center:[-o/3,-o/3,n+n*.1/2]}),ee(Vp,{color:"#1a1a1f",height:n*.2,radius:e/2,center:[-o/3,o/3,n+n*.1/2]}),ee(Vp,{color:"#1a1a1f",height:n*.2,radius:e/2,center:[o/3,-o/3,n+n*.1/2]}),ee(u5,{thickness:e/3,width:s,horizontalLength:o*.8,verticalLength:n/2,position:{x:-i/2,y:-o/2,z:-n*1.2}}),ee(u5,{thickness:e/3,width:s,horizontalLength:o*.8,verticalLength:n/2,position:{x:-i/2,y:o/2,z:-n*1.2},rotation:Math.PI}),ee(u5,{thickness:e/3,width:s,horizontalLength:o*.8,verticalLength:n/2,position:{x:i/2,y:o/2,z:-n*1.2},rotation:Math.PI}),ee(u5,{thickness:e/3,width:s,horizontalLength:o*.8,verticalLength:n/2,position:{x:i/2+e/3.6,y:-o/2,z:-n*1.2}})]})},u5=t=>{const{thickness:A,width:e,horizontalLength:i,verticalLength:o,rotation:n=0,position:s}=t,r=[[0,i],[-o/3,i/3],[-o/5,i/4],[0,0]],a=sCA(r,A);return ee(fs,{color:"#f2f2f2",children:ee(Zi,{offset:{x:s?.x||0,y:s?.y||0,z:s?.z||0},children:ee(pQ,{rotation:[0,55,n],children:ee(tL,{height:e,children:ee(eL,{points:a.map(g=>[g.y,g.x])})})})})})},NEt=({pinCount:t,leadLength:A,leadWidth:e,pitch:i,bodyWidth:o})=>{const n=Math.ceil(t/2),s=(n-1)*i/2,r=.25,a=1,g=.8,I=A*0,c=i*(n-1)+e+.2,B=o*.55;return Pt(Jo,{children:[Array.from({length:n}).map((C,l)=>ee(qo,{position:{x:-o/2-I,y:l*i-s,z:r/2},width:e,thickness:r,padContactLength:A/2,bodyDistance:A+.3,height:g})),Array.from({length:n}).map((C,l)=>ee(qo,{rotation:Math.PI,position:{x:o/2+I,y:l*i-s,z:r/2},width:e,thickness:r,padContactLength:A/2,bodyDistance:A+.3,height:g})),ee(zB,{center:{x:0,y:0,z:r/2},width:B,length:c,height:a})]})},_Et=({pinCount:t,pitch:A,leadWidth:e,leadLength:i,bodyWidth:o,bodyLength:n})=>{const s=t===8?{pitch:.65,leadWidth:.3}:{pitch:.5,leadWidth:.225},r=isNaN(parseFloat(A))?s.pitch:parseFloat(A),a=isNaN(parseFloat(e))?s.leadWidth:parseFloat(e)*.8,g=isNaN(parseFloat(o))?2.6:parseFloat(o)*.8,I=isNaN(parseFloat(n))?2+Number(r)*1.4:parseFloat(n),c=t/2,B=(c-1)*r/2,C=.15,l=.8,Q=4.5,E=(Q-g)/2,h=E*.5;return Pt(Jo,{children:[Array.from({length:c}).map((u,d)=>ee(qo,{position:{x:-Q/2,y:B-d*r,z:C/2},width:a,thickness:C,padContactLength:h+.05,bodyDistance:E+.1,height:l})),Array.from({length:c}).map((u,d)=>ee(qo,{rotation:Math.PI,position:{x:Q/2,y:B-d*r,z:C/2},width:a,thickness:C,padContactLength:h+.05,bodyDistance:E+.1,height:l})),ee(zB,{center:{x:0,y:0,z:C/2},width:g,length:I,height:1})]})},vEt=()=>Pt(Jo,{children:[ee(ut,{color:"#ccc",size:[.5,.6,.12],center:[-.725,0,.12/2]}),ee(ut,{color:"#ccc",size:[.5,.6,.12],center:[.725,0,.12/2]}),ee(fs,{color:"#222",children:Pt(lE,{children:[ee(Zi,{z:.3/2,children:ee(ut,{size:[1.65,.8,.3]})}),Pt(BI,{children:[ee(Zi,{z:.3,children:ee(ut,{size:[1.65,.8,.01]})}),ee(Zi,{z:.6,children:ee(ut,{size:[1.65-.2,.8-.2,.01]})})]})]})})]}),UEt=()=>Pt(Jo,{children:[ee(ut,{color:"#ccc",size:[.26,.51,.12],center:[-.325,0,.12/2]}),ee(ut,{color:"#ccc",size:[.26,.51,.12],center:[.325,0,.12/2]}),ee(fs,{color:"#222",children:ee(Zi,{z:.47/2+.02,children:ee(ut,{size:[.98,.58,.47]})})}),ee(ut,{color:"#ccc",size:[.98+.001,.26/2,.26/4],center:[0,.26/2,.47/4]}),ee(ut,{color:"#ccc",size:[.98+.001,.26/2,.26/4],center:[0,-.26/2,.47/4]}),ee(ut,{color:"#ccc",size:[.26/1.5,.58+.001,.26/4],center:[.65/2,0,.47/4]}),ee(ut,{color:"#ccc",size:[.26/1.5,.58+.001,.26/4],center:[-.65/2,0,.47/4]})]}),LEt=()=>{const g=ee(fs,{color:"#1a1a1a",children:Pt(lE,{children:[Pt(BI,{children:[ee(Zi,{z:.13,children:ee(ut,{size:[4,3,.03]})}),ee(Zi,{z:1.15,children:ee(ut,{size:[4.4,3.4,.01]})})]}),Pt(BI,{children:[ee(Zi,{z:1.15,children:ee(ut,{size:[4.4,3.4,.01]})}),ee(Zi,{z:2.3,children:ee(ut,{size:[4,3,.01]})})]})]})}),I=({xDir:c})=>{const l=c*1.78,Q=c*(3.4/2-.2/2+1),E=c*(3.4/2-.2/2),h=Math.abs(E-Q),u=(Q+E)/2;return ee(fs,{color:"#c0c0c0",children:Pt(lE,{children:[ee(ut,{size:[2.3*.8,1.45,.2],center:[l,0,.2/2]}),ee(ut,{size:[.2,1.45,1.14],center:[Q,0,1.14/2+.2]}),ee(ut,{size:[h,1.45,.2],center:[u,0,.2/2+1.14]})]})})};return Pt(Jo,{children:[ee(I,{xDir:1}),ee(I,{xDir:-1}),g]})},HEt=()=>{const g=ee(fs,{color:"#1a1a1a",children:Pt(lE,{children:[Pt(BI,{children:[ee(Zi,{z:.13,children:ee(ut,{size:[4,3,.03]})}),ee(Zi,{z:1.15,children:ee(ut,{size:[4.4,3.4,.01]})})]}),Pt(BI,{children:[ee(Zi,{z:1.15,children:ee(ut,{size:[4.4,3.4,.01]})}),ee(Zi,{z:2.3,children:ee(ut,{size:[4,3,.01]})})]})]})}),I=({xDir:c})=>{const l=c*1.78,Q=c*(3.4/2-.2/2+1),E=c*(3.4/2-.2/2),h=Math.abs(E-Q),u=(Q+E)/2;return ee(fs,{color:"#c0c0c0",children:Pt(lE,{children:[ee(ut,{size:[2.3*.8,1.45,.2],center:[l,0,.2/2]}),ee(ut,{size:[.2,1.45,1.14],center:[Q,0,1.14/2+.2]}),ee(ut,{size:[h,1.45,.2],center:[u,0,.2/2+1.14]})]})})};return Pt(Jo,{children:[ee(I,{xDir:1}),ee(I,{xDir:-1}),g]})},YEt=()=>{const g=ee(fs,{color:"#1a1a1a",children:Pt(lE,{children:[Pt(BI,{children:[ee(Zi,{z:.21000000000000002,children:ee(ut,{size:[6.3999999999999995,5.6,.03]})}),ee(Zi,{z:1.15,children:ee(ut,{size:[6.8,6,.01]})})]}),Pt(BI,{children:[ee(Zi,{z:1.15,children:ee(ut,{size:[6.8,6,.01]})}),ee(Zi,{z:2.3,children:ee(ut,{size:[6.3999999999999995,5.6,.01]})})]})]})}),I=({xDir:c})=>{const l=c*3.08,Q=c*(6/2-.2/2+1),E=c*(6/2-.2/2),h=Math.abs(E-Q),u=(Q+E)/2;return ee(fs,{color:"#c0c0c0",children:Pt(lE,{children:[ee(ut,{size:[2.3*.8,2.95,.2],center:[l,0,.2/2]}),ee(ut,{size:[.2,2.95,1.14],center:[Q,0,1.14/2+.2]}),ee(ut,{size:[h,2.95,.2],center:[u,0,.2/2+1.14]})]})})};return Pt(Jo,{children:[ee(I,{xDir:1}),ee(I,{xDir:-1}),g]})},JEt=()=>{const c=ee(fs,{color:"#222",children:Pt(lE,{children:[ee(Zi,{z:.27,children:ee(ut,{size:[2.9,1.9,.54]})}),Pt(BI,{children:[ee(Zi,{z:.54,children:ee(ut,{size:[2.9,1.9,.01]})}),ee(Zi,{z:1.08,children:ee(ut,{size:[2.6999999999999997,1.7,.01]})})]})]})});return Pt(Jo,{children:[ee(ut,{color:"#ccc",size:[1,1.2,.25],center:[-1.3,0,.25/2]}),ee(ut,{color:"#ccc",size:[1,1.2,.25],center:[1.3,0,.25/2]}),c]})},TEt=()=>Pt(Jo,{children:[ee(ut,{color:"#ccc",size:[1,.6,.12],center:[-1.3,0,.12/2]}),ee(ut,{color:"#ccc",size:[1,.6,.12],center:[1.3,0,.12/2]}),ee(fs,{color:"#222",children:Pt(lE,{children:[ee(Zi,{z:.55/2,children:ee(ut,{size:[2.7,1.6,.55]})}),Pt(BI,{children:[ee(Zi,{z:.55,children:ee(ut,{size:[2.7,1.6,.01]})}),ee(Zi,{z:1.1,children:ee(ut,{size:[2.7-.2,1.6-.2,.01]})})]})]})})]}),KEt=()=>Pt(Jo,{children:[ee(ut,{color:"#ccc",size:[1,.9,.2],center:[-1.3,0,.2/2]}),ee(ut,{color:"#ccc",size:[1,.9,.2],center:[1.3,0,.2/2]}),ee(fs,{color:"#222",children:Pt(lE,{children:[ee(Zi,{z:.2/2,children:ee(ut,{size:[2.75,1.8,.2]})}),Pt(BI,{children:[ee(Zi,{z:.2,children:ee(ut,{size:[2.75,1.8,.01]})}),ee(Zi,{z:1,children:ee(ut,{size:[2.75-.4,1.8-.4,.01]})})]})]})}),ee(ut,{color:"#777",size:[.2,1.8-.4,.01],center:[-1.3+.4,0,1]})]}),qEt=()=>Pt(Jo,{children:[ee(ut,{color:"#ccc",size:[.9,.9,.2],center:[-1.225,0,.2/2]}),ee(ut,{color:"#ccc",size:[.9,.9,.2],center:[1.225,0,.2/2]}),ee(fs,{color:"#222",children:Pt(lE,{children:[Pt(BI,{children:[ee(Zi,{z:.2,children:ee(ut,{size:[2.6-.1/2,1.7-.1/2,.01]})}),ee(Zi,{z:.01,children:ee(ut,{size:[2.6-.1,1.7-.1,.01]})})]}),Pt(BI,{children:[ee(Zi,{z:.2,children:ee(ut,{size:[2.6,1.7,.01]})}),ee(Zi,{z:1,children:ee(ut,{size:[2.6-.4,1.7-.4,.01]})})]})]})}),ee(ut,{color:"#777",size:[.2*2.7,1.7-.4,.02],center:[-1.225+.4,0,1]})]}),PEt=()=>Pt(Jo,{children:[ee(ut,{color:"#ccc",size:[.9,1.75,.2],center:[-1.825,0,.2/2]}),ee(ut,{color:"#ccc",size:[.9,1.75,.2],center:[1.825,0,.2/2]}),ee(fs,{color:"#222",children:Pt(lE,{children:[Pt(BI,{children:[ee(Zi,{z:.2,children:ee(ut,{size:[3.8-.05/2,2.5-.05/2,.01]})}),ee(Zi,{z:.01,children:ee(ut,{size:[3.8-.05,2.5-.05,.01]})})]}),Pt(BI,{children:[ee(Zi,{z:.2,children:ee(ut,{size:[3.8,2.5,.01]})}),ee(Zi,{z:1,children:ee(ut,{size:[3.8-.4,2.5-.4,.01]})})]})]})}),ee(ut,{color:"#777",size:[.2*2.7,2.5-.4,.02],center:[-1.825+.4,0,1]})]}),OEt=()=>Pt(Jo,{children:[ee(ut,{color:"#ccc",size:[.4,.25,.14],center:[-.4,0,.14/2]}),ee(ut,{color:"#ccc",size:[.4,.25,.14],center:[.4,0,.14/2]}),ee(fs,{color:"#222",children:Pt(lE,{children:[ee(Zi,{z:.14/2,children:ee(ut,{size:[.8,.6,.14]})}),Pt(BI,{children:[ee(Zi,{z:.14,children:ee(ut,{size:[.8,.6,.01]})}),ee(Zi,{z:.37,children:ee(ut,{size:[.8-.1,.6-.1,.01]})})]})]})})]}),WEt=()=>{const I=3.0999999999999996;return Pt(Jo,{children:[ee(qo,{rotation:Math.PI,position:{x:6.6/2+I/4,y:0,z:.25/2},width:3,thickness:.25,padContactLength:.5,bodyDistance:I,height:.75}),ee(qo,{position:{x:-6.6/2-I/4,y:0,z:.25/2},width:.7,thickness:.25,padContactLength:.5,bodyDistance:I,height:.75}),ee(qo,{position:{x:-6.6/2-I/4,y:-2.3,z:.25/2},width:.7,thickness:.25,padContactLength:.5,bodyDistance:I,height:.75}),ee(qo,{position:{x:-6.6/2-I/4,y:2.3,z:.25/2},width:.7,thickness:.25,padContactLength:.5,bodyDistance:I,height:.75}),ee(zB,{center:{x:0,y:0,z:0},width:3.5,length:6.5,height:1.7,includeNotch:!1,taperRatio:.06,straightHeightRatio:.45})]})},ZEt=()=>Pt(Jo,{children:[Array.from({length:16}).map((C,l)=>ee(qo,{position:{x:-10.5/2,y:l*.5-3.75,z:.25/2},width:.2,thickness:.25,padContactLength:.45,bodyDistance:.95,height:.65})),Array.from({length:16}).map((C,l)=>ee(qo,{rotation:Math.PI,position:{x:10.5/2,y:l*.5-3.75,z:.25/2},width:.2,thickness:.25,padContactLength:.45,bodyDistance:.95,height:.65})),Array.from({length:16}).map((C,l)=>ee(qo,{rotation:Math.PI/2,position:{x:l*.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((C,l)=>ee(qo,{rotation:-Math.PI/2,position:{x:l*.5-3.75,y:10.5/2,z:.25/2},width:.2,thickness:.25,padContactLength:.45,bodyDistance:.95,height:.65})),ee(zB,{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})]}),VEt=ZEt,jEt=()=>{const g=.7999999999999998;return Pt(Jo,{children:[ee(qo,{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}),ee(qo,{position:{x:-2.05/2-g/4,y:-.65,z:.18/2},width:.3,thickness:.18,padContactLength:.2,bodyDistance:g,height:.65}),ee(qo,{position:{x:-2.05/2-g/4,y:.65,z:.18/2},width:.3,thickness:.18,padContactLength:.2,bodyDistance:g,height:.65}),ee(zB,{center:{x:0,y:0,z:0},width:1.25,length:2,height:.9,includeNotch:!1,taperRatio:.06,straightHeightRatio:.7,heightAboveSurface:.05})]})},zEt=({pinCount:t,pitch:A,leadWidth:e,padContactLength:i,bodyWidth:o})=>{const n=t/4;if(n!==Math.floor(n))throw new Error(`LQFP pinCount must be divisible by 4, got ${t}`);A||(A=.5),i||(i=.6),e||(e=.22),o||(o=A*(n+4));const s=o,r=(n-1)*A/2,a=s+3.3*i,g=a,I=.8,c=.2,B=(g-o)/2+.4;return Pt(Jo,{children:[Array.from({length:n}).map((C,l)=>ee(qo,{position:{x:-g/2-.36,y:l*A-r,z:c/2},width:e,thickness:c,padContactLength:i,bodyDistance:B,height:I})),Array.from({length:n}).map((C,l)=>ee(qo,{rotation:Math.PI,position:{x:g/2+.36,y:l*A-r,z:c/2},width:e,thickness:c,padContactLength:i,bodyDistance:B,height:I})),Array.from({length:n}).map((C,l)=>ee(qo,{rotation:Math.PI/2,position:{x:l*A-r,y:-a/2-.36,z:c/2},width:e,thickness:c,padContactLength:i,bodyDistance:B,height:I})),Array.from({length:n}).map((C,l)=>ee(qo,{rotation:-Math.PI/2,position:{x:l*A-r,y:a/2+.36,z:c/2},width:e,thickness:c,padContactLength:i,bodyDistance:B,height:I})),ee(zB,{center:{x:0,y:0,z:0},width:o,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})]})},XEt=()=>{const i=.20900000000000002,o=.1,n=.3,s=.1,r=.2;return Pt(Jo,{children:[ee(fs,{color:"#222",children:Pt(lE,{children:[ee(ut,{size:[.85,1.2,i],center:[0,0,i/2]}),Pt(BI,{children:[ee(Zi,{z:i,children:ee(ut,{size:[.85,1.2,.01]})}),ee(Zi,{z:.38,children:ee(ut,{size:[.85-o,1.2-o,.01]})})]})]})}),ee(ut,{color:"#ccc",size:[n,.25,s],center:[.55,0,s/2]}),ee(ut,{color:"#ccc",size:[n,r,s],center:[-.55,.4,s/2]}),ee(ut,{color:"#ccc",size:[n,r,s],center:[-.55,-.4,s/2]})]})},$Et=({num_pins:t,bodyWidth:A=5.3,bodyLength:e=5.3,bodyThickness:i=1,thermalPadSize:o,padWidth:n=e/5.3*.6,padLength:s=e/5.3*1,pitch:r=.5,thermalPadThickness:a=.2})=>{const g=[],I=Math.floor(t/2),c=r*(I-1);for(let B=0;B<t;B++){const C=B<I?"left":"right",l=B%I,Q=c/2-l*r,E=s,h=n,u=C==="left"?-A/2+E/2:A/2-E/2,d=B+1;g.push({pinNumber:d,x:u,y:Q,padSizeX:E,padSizeY:h})}return Pt(Jo,{children:[ee(zB,{center:{x:0,y:0,z:0},width:A,length:e,height:i,heightAboveSurface:0,color:"grey",chamferSize:.2,taperRatio:0,notchPosition:{x:-(A/2-s),y:e/2-s,z:i}}),g.map((B,C)=>ee(ut,{center:[B.x,B.y,a/2],size:[B.padSizeX,B.padSizeY,a]})),o?.length!==void 0&&o?.width!==void 0&&ee(ut,{center:[0,0,a/2],size:[o.width,o.length,a]})]})},Aht=({bodyLength:t=10.2,bodyWidth:A=4.65,bodyHeight:e=13.46,leadSpacing:i=5,leadDiameter:o=.8,leadLength:n=12.7,color:s="#ddd",leadColor:r="#b87333"})=>{const a=t/2,g=A/2,I=a-g,c=i/2,B=.85;return Pt(Jo,{children:[Pt(fs,{color:s,children:[Pt(BI,{children:[ee(jp,{height:e,roundRadius:.5,radius:g,center:[-I,0,e]}),ee(jp,{height:e,roundRadius:.5,radius:g,center:[I,0,e]})]}),Pt(BI,{children:[ee(jp,{height:B,roundRadius:.1,radius:g+.85,center:[-I,0,e/2+B/2]}),ee(jp,{height:B,roundRadius:.1,radius:g+.85,center:[I,0,e/2+B/2]})]})]}),Pt(fs,{color:r,children:[ee(Vp,{height:n+e/2,radius:o/2,center:[-c+.06,0,-(n/2)+e/2]}),ee(Vp,{height:n+e/2,radius:o/2,center:[c-.06,0,-(n/2)+e/2]})]})]})},eht=({bodyLength:t=1.4,bodyDiameter:A=1.1,color:e="#3a3a3aff",contactColor:i="#c6c6c6",cathodeIdentification:o="#111"})=>Pt(Jo,{children:[ee(fs,{color:e,children:Pt(pQ,{rotation:[0,"90deg",0],children:[ee(AL,{size:[A,A,t-.2],roundRadius:.2,center:[-A/2,0,.05]}),ee(Vp,{height:.2/2,radius:A/2-.2,center:[-A/2,0,-t/2+.2/2]})]})}),ee(fs,{color:o,children:ee(pQ,{rotation:[0,"90deg",0],children:ee(AL,{size:[A*1.01,A*1.01,t/3],roundRadius:.2,center:[-A/2,0,-t/4+.1]})})}),ee(fs,{color:i,children:ee(pQ,{rotation:[0,"90deg",0],children:ee(jp,{height:.2,radius:A/2,roundRadius:.2/3,center:[-A/2,0,-t/2]})})}),ee(fs,{color:i,children:ee(pQ,{rotation:[0,"90deg",0],children:ee(jp,{height:.2,radius:A/2,roundRadius:.2/3,center:[-A/2,0,t/2]})})})]}),tht=({bodyLength:t=3.5,bodyDiameter:A=1.5,color:e="#3a3a3aff",contactColor:i="#c6c6c6"})=>Pt(Jo,{children:[ee(fs,{color:e,children:ee(pQ,{rotation:[0,"90deg",0],children:ee(jp,{height:t,radius:A/2,roundRadius:.3,center:[-A/2,0,0]})})}),ee(fs,{color:i,children:ee(pQ,{rotation:[0,"90deg",0],children:ee(jp,{height:.5,radius:A/2,roundRadius:.2,center:[-A/2,0,-t/2]})})}),ee(fs,{color:i,children:ee(pQ,{rotation:[0,"90deg",0],children:ee(jp,{height:.5,radius:A/2,roundRadius:.2,center:[-A/2,0,t/2]})})})]}),iht=({bodyLength:t=3.9,bodyDiameter:A=2.5,color:e="#3a3a3aff",contactColor:i="#c6c6c6"})=>Pt(Jo,{children:[ee(fs,{color:e,children:ee(pQ,{rotation:[0,"90deg",0],children:ee(jp,{height:t,radius:A/2,roundRadius:.3,center:[-A/2,0,0]})})}),ee(fs,{color:i,children:ee(pQ,{rotation:[0,"90deg",0],children:ee(jp,{height:.55,radius:A/2,roundRadius:.2,center:[-A/2,0,-t/2]})})}),ee(fs,{color:i,children:ee(pQ,{rotation:[0,"90deg",0],children:ee(jp,{height:.55,radius:A/2,roundRadius:.2,center:[-A/2,0,t/2]})})})]}),oht=({pinCount:t,padContactLength:A=.6,leadWidth:e=.41,pitch:i=1.27})=>{if(t%2!==0)throw new Error("MS012 pinCount must be even");const o=t/2,n=4.9,s=3.9,r=(o-1)*i/2,a=.2;return Pt(Jo,{children:[Array.from({length:o}).map((g,I)=>ee(qo,{position:{x:-s/2-A-.3,y:I*i-r,z:a/2},width:e,thickness:a,padContactLength:A,bodyDistance:A+.4,height:.85})),Array.from({length:o}).map((g,I)=>ee(qo,{rotation:Math.PI,position:{x:s/2+A+.3,y:I*i-r,z:a/2},width:e,thickness:a,padContactLength:A,bodyDistance:A+.4,height:.85})),ee(zB,{center:{x:0,y:0,z:a/2},width:s,length:n,height:1.55,notchPosition:{x:-.95,y:n/2-1,z:1.55},heightAboveSurface:.17,taperRatio:.09})]})},nht=({pinCount:t=16,padContactLength:A=.6,leadWidth:e=.41,pitch:i=1.27})=>{if(t!==16)throw new Error("MS013 only supports 16 pins");const o=t/2,n=7.5,s=10.3,r=(o-1)*i/2,a=.2;return Pt(Jo,{children:[Array.from({length:o}).map((g,I)=>ee(qo,{position:{x:-n/2-A-.3,y:I*i-r,z:a/2},width:e,thickness:a,padContactLength:A,bodyDistance:A+.4,height:.85})),Array.from({length:o}).map((g,I)=>ee(qo,{rotation:Math.PI,position:{x:n/2+A+.3,y:I*i-r,z:a/2},width:e,thickness:a,padContactLength:A,bodyDistance:A+.4,height:.85})),ee(zB,{center:{x:0,y:0,z:a/2},width:n,length:s,height:1.1,notchPosition:{x:-2.25,y:s/2-1.5,z:1.1},heightAboveSurface:.17,taperRatio:.05})]})},sht=()=>{const Q=7.050000000000001,E=24.95+6.5/2;return ee(Zi,{center:[0,0,1],children:Pt(Jo,{children:[Pt(pQ,{rotation:[0,55,-55],children:[Pt(nF,{children:[ee(ut,{color:"#ccc",size:[6.5+.1,9.9,1.3],center:[E,0,1.3-2]}),ee(Vp,{color:"black",center:[E,0,1.3-2],radius:3/2,height:1.3*1.2})]}),ee(fs,{color:"#222",children:ee(zB,{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})})]}),ee(pQ,{rotation:[0,55,55],children:Array.from({length:3}).map((h,u)=>{const d=Q,f=(u-1)*2.7,m=-.5-.6;return Pt(fs,{color:"gold",children:[Pt(BI,{children:[ee(Zi,{center:[15.05-4.5/2+.1,f,m],children:ee(ut,{size:[4.5,.81+1,.5]})}),ee(Zi,{center:[15.05-4.5/2-1+.1,f,m],children:ee(ut,{size:[4.5,.81,.5]})})]}),ee(Zi,{center:[d,f,m],children:ee(ut,{size:[16+.1,.81,.5]})})]},`prong-${u}`)})})]})})},rht=()=>{const g=1.1999999999999997;return Pt(Jo,{children:[ee(qo,{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}),ee(qo,{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}),ee(qo,{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}),ee(qo,{position:{x:-2.8/2-g/4,y:0,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:g,height:.95}),ee(qo,{position:{x:-2.8/2-g/4,y:-.95,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:g,height:.95}),ee(qo,{position:{x:-2.8/2-g/4,y:.95,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:g,height:.95}),ee(zB,{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})]})},aht=()=>Pt(Jo,{children:[ee(zB,{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 I=-.35+g*.35;return ee(ut,{center:[-.8/2+.19/2-.1,I,.12/2],size:[.19,.15,.12]})}),[0,1,2].map(g=>{const I=-.35+g*.35;return ee(ut,{center:[.8/2-.19/2+.1,I,.12/2],size:[.19,.15,.12]})})]}),ght=()=>{const s="#222",a=[.43,.4,1.32],g=[.43,.4,.25],I=[0,0,-.66],c=[0,0,-1.32],B=[0,1.28,-2.72],C=[0,1.28,-8.9],l=-7.5;return Pt(Zi,{center:[0,1,10.5],children:[ee(fs,{color:s,children:Pt(nF,{children:[ee(Zi,{center:[0,0,2.25],children:ee(Vp,{radius:2.4,height:4.5})}),ee(Zi,{center:[0,-1.8499999999999999,2.25],children:ee(ut,{size:[2.4*2,1.1,4.5+.2]})})]})}),ee(Zi,{center:I,children:ee(ut,{size:a})}),Pt(BI,{children:[ee(Zi,{center:c,children:ee(ut,{size:g})}),ee(Zi,{center:B,children:ee(ut,{size:g})})]}),ee(Zi,{center:C,children:ee(ut,{size:[.43,.4,12.2]})}),ee(Zi,{center:[1.3,0,l],children:ee(ut,{size:[.43,.4,15]})}),ee(Zi,{center:[-1.3,0,l],children:ee(ut,{size:[.43,.4,15]})})]})},Iht=()=>Pt(Jo,{children:[ee(qo,{rotation:Math.PI,position:{x:2/2+.75/4,y:-.65,z:.15/2},width:.25,thickness:.15,padContactLength:.3,bodyDistance:.75,height:.85}),ee(qo,{rotation:Math.PI,position:{x:2/2+.75/4,y:0,z:.15/2},width:.25,thickness:.15,padContactLength:.3,bodyDistance:.75,height:.85}),ee(qo,{rotation:Math.PI,position:{x:2/2+.75/4,y:.65,z:.15/2},width:.25,thickness:.15,padContactLength:.3,bodyDistance:.75,height:.85}),ee(qo,{position:{x:-2/2-.75/4,y:0,z:.15/2},width:.25,thickness:.15,padContactLength:.3,bodyDistance:.75,height:.85}),ee(qo,{position:{x:-2/2-.75/4,y:-.65,z:.15/2},width:.25,thickness:.15,padContactLength:.3,bodyDistance:.75,height:.85}),ee(qo,{position:{x:-2/2-.75/4,y:.65,z:.15/2},width:.25,thickness:.15,padContactLength:.3,bodyDistance:.75,height:.85}),ee(zB,{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})]}),cht=Iht,Bht=()=>Pt(Jo,{children:[ee(zB,{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 ee(ut,{center:[-1/2+.3/2,a,.05/2],size:[.3,.2,.05]})}),[0,1,2].map(r=>{const a=-.5+r*.5;return ee(ut,{center:[1/2-.3/2,a,.05/2],size:[.3,.2,.05]})})]}),Cht=()=>Pt(Jo,{children:[ee(qo,{position:{x:-2.5/2,y:0,z:.175/2},width:.3,thickness:.175,padContactLength:.3,bodyDistance:.45,height:.7}),ee(qo,{rotation:Math.PI,position:{x:2.5/2,y:0,z:.175/2},width:.3,thickness:.175,padContactLength:.3,bodyDistance:.45,height:.7}),ee(fs,{color:"#222",children:ee(zB,{center:{x:0,y:0,z:0},width:1.7,length:1.25,height:.95,includeNotch:!1,taperRatio:.06,straightHeightRatio:.7,heightAboveSurface:.05})}),ee(ut,{color:"#777",size:[1.7/3,1.25-.075,.02],center:[-.85*2/3+.035,0,.95+.05]})]}),lht=()=>Pt(Jo,{children:[ee(ut,{color:"#ccc",size:[.4,.325,.175],center:[-1.05,0,.175/2]}),ee(ut,{color:"#ccc",size:[.4,.325,.175],center:[1.05,0,.175/2]}),ee(fs,{color:"#222",children:Pt(lE,{children:[ee(Zi,{z:.175/2,children:ee(ut,{size:[1.7,1.25,.175]})}),Pt(BI,{children:[ee(Zi,{z:.175,children:ee(ut,{size:[1.7,1.25,.01]})}),ee(Zi,{z:.725,children:ee(ut,{size:[1.7-.2,1.25-.2,.01]})})]})]})}),ee(ut,{color:"#777",size:[1.7/3,1.25-.2,.02],center:[-1.05+1.7/4.4+.2,0,.725]})]}),Qht=()=>{const s=-1.0474999999999999,r=1.775/2+.4/2-.04;return Pt(Jo,{children:[ee(ut,{color:"#ccc",size:[.4,.325,.13],center:[s,0,.13/2]}),ee(ut,{color:"#ccc",size:[.4,.325,.13],center:[r,0,.13/2]}),ee(fs,{color:"#222",children:ee(zB,{width:1.775,length:1.25,height:.725,center:{x:0,y:0,z:0},heightAboveSurface:0,straightHeightRatio:.7,taperRatio:.06,includeNotch:!1})}),ee(ut,{color:"#777",size:[1.775/3,1.25-.05,.02],center:[s+1.775/4.4+.2,0,.725]})]})},Eht=({footprint:t})=>{const A=tEt.string(t).json();switch(A.fn){case"dip":return ee(rEt,{numPins:A.num_pins,pitch:A.p,bodyWidth:A.w});case"tssop":return ee(gEt,{pinCount:A.num_pins,leadLength:A.pl,leadWidth:A.pw,pitch:A.p,bodyWidth:A.w});case"msop":return ee(IEt,{pinCount:A.num_pins,padContactLength:A.pl,leadWidth:A.pw,pitch:A.p,bodyWidth:A.w});case"vssop":return ee(_Et,{pinCount:A.num_pins,leadLength:A.pl,leadWidth:A.pw,pitch:A.p,bodyWidth:A.w,bodyLength:A.h});case"qfp":return ee(lEt,{pinCount:A.num_pins,pitch:A.p,leadWidth:A.pw,padContactLength:A.pl,bodyWidth:A.w});case"tqfp":return ee(VEt,{});case"lqfp":return ee(zEt,{pinCount:A.num_pins});case"qfn":{const o=typeof A.thermalpad?.x=="number"&&typeof A.thermalpad?.y=="number";return ee(yEt,{num_pins:A.num_pins,bodyWidth:A.w,bodyLength:A.h,pitch:A.p,padLength:A.pl,padWidth:A.pw,thermalPadSize:o?{width:A.thermalpad.x,length:A.thermalpad.y}:void 0})}case"dfn":{const o=typeof A.thermalpad?.x=="number"&&typeof A.thermalpad?.y=="number";return ee($Et,{num_pins:A.num_pins,bodyWidth:A.w,bodyLength:A.h,pitch:A.p,padLength:A.pl,padWidth:A.pw,thermalPadSize:o?{width:A.thermalpad.x,length:A.thermalpad.y}:void 0})}case"pinrow":{const o=t.match(/_rows(\d+)/),n=o&&o[1]?parseInt(o[1],10):1;if(A.male)return ee(uEt,{numberOfPins:A.num_pins,pitch:A.p,invert:A.invert,faceup:A.faceup,rows:n});if(A.female)return ee(REt,{numberOfPins:A.num_pins,pitch:A.p,rows:n})}case"cap":switch(A.imperial){case"0402":return ee(fZA,{color:"#856c4d"});case"0603":return ee(yZA,{color:"#856c4d"});case"0805":return ee(wZA,{color:"#856c4d"});case"0201":return ee(mZA,{color:"#856c4d"});case"01005":return ee(DZA,{color:"#856c4d"});case"1206":return ee(SZA,{color:"#856c4d"});case"1210":return ee(bZA,{color:"#856c4d"});case"2010":return ee(xZA,{color:"#856c4d"});case"2512":return ee(kZA,{color:"#856c4d"})}case"sot235":return ee(mEt,{});case"sot457":return ee(rht,{});case"sot223":return ee(WEt,{});case"sot23w":return ee(DEt,{});case"sot323":return ee(jEt,{});case"sod323f":return ee(lht,{});case"sod323fl":return ee(Qht,{});case"sot363":return ee(cht,{});case"sot886":return ee(Bht,{});case"sot963":return ee(aht,{});case"pushbutton":return ee(MEt,{width:A.w,length:A.h,innerDiameter:A.id});case"soic":return ee(NEt,{pinCount:A.num_pins,leadLength:A.pl,leadWidth:A.pw,pitch:A.p,bodyWidth:A.w});case"sod523":return ee(vEt,{});case"sod882":return ee(UEt,{});case"sma":return ee(LEt,{});case"smb":return ee(HEt,{});case"smc":return ee(YEt,{});case"smf":return ee(JEt,{});case"sod123f":return ee(TEt,{});case"sod123fl":return ee(KEt,{});case"sod123w":return ee(qEt,{});case"sod128":return ee(PEt,{});case"sod323":return ee(Cht,{});case"sod923":return ee(OEt,{});case"hc49":return ee(Aht,{});case"micromelf":return ee(eht,{});case"minimelf":return ee(tht,{});case"melf":return ee(iht,{});case"ms012":return ee(oht,{pinCount:A.num_pins,padContactLength:A.pl,leadWidth:A.pw,pitch:A.p});case"ms013":return ee(nht,{pinCount:A.num_pins,padContactLength:A.pl,leadWidth:A.pw,pitch:A.p});case"sot723":return ee(XEt,{});case"to220":return ee(sht,{});case"to92":return ee(ght,{})}const e=t.match(/_color\(([^)]+)\)/),i=e?e[1]:void 0;switch(A.imperial){case"0402":return ee(fZA,{color:i});case"0603":return ee(yZA,{color:i});case"0805":return ee(wZA,{color:i});case"0201":return ee(mZA,{color:i});case"01005":return ee(DZA,{color:i});case"1206":return ee(SZA,{color:i});case"1210":return ee(bZA,{color:i});case"2010":return ee(xZA,{color:i});case"2512":return ee(kZA,{color:i})}return null},hht=t=>t&&typeof t=="object"&&"type"in t,r_=t=>{if(typeof t=="number")return t;if(typeof t=="string"){const A=/^(-?\d+(?:\.\d+)?)\s*deg$/i.exec(t);if(A)return parseFloat(A[1])*Math.PI/180;const e=Number(t);if(!Number.isNaN(e))return e}return 0},uht=t=>Array.isArray(t)?[Number(t[0])||0,Number(t[1])||0,Number(t[2])||0]:typeof t=="object"&&t?[Number(t.x)||0,Number(t.y)||0,Number(t.z)||0]:[0,0,0];function Mm(t,A,e){const{jscad:{primitives:i,booleans:o,hulls:n,geometries:s,extrusions:r,transforms:a}}=e;if(t==null||t===!1)return[];if(Array.isArray(t))return t.flatMap(B=>Mm(B,A,e));if(!hht(t))return[];const{type:g,props:I,children:c}=t;if(g===hZA)return(c??[]).flatMap(B=>Mm(B,A,e));if(g===fs){const B=I?.color;return(c??[]).flatMap(C=>Mm(C,B??A,e))}if(g===Zi){const B=uht(I?.offset??I?.center??{x:I?.x,y:I?.y,z:I?.z});return(c??[]).flatMap(l=>Mm(l,A,e)).map(({geom:l,color:Q})=>({geom:a.translate(B,l),color:Q??A}))}if(g===pQ){const B=Array.isArray(I?.rotation)?[r_(I.rotation[0]),r_(I.rotation[1]),r_(I.rotation[2])]:[r_(I?.x??0),r_(I?.y??0),r_(I?.z??0)];return(c??[]).flatMap(l=>Mm(l,A,e)).map(({geom:l,color:Q})=>({geom:a.rotateZ(B[2],a.rotateY(B[1],a.rotateX(B[0],l))),color:Q}))}if(g===lE||g===nF||g===BI){const B=(c??[]).flatMap(l=>Mm(l,A,e)).map(l=>l.geom);if(B.length===0)return[];let C;return g===lE?C=o.union(B):g===nF?C=o.subtract(B[0],B.slice(1)):C=n.hull(B),[{geom:C,color:A}]}if(g===eL){const B=I?.points??[];return[{geom:s.geom2.fromPoints(B),color:A??I?.color}]}if(g===tL){const B=(c??[]).flatMap(E=>Mm(E,A,e)).map(E=>E.geom);if(B.length===0)return[];const C=B.length>1?o.union(B):B[0],l=I?.height??I?.h??1;let Q=r.extrudeLinear({height:l},C);if(Q.polygons)for(const E of Q.polygons)!E.plane||!E.vertices||E.vertices.length<3||E.vertices.reverse();return[{geom:Q,color:A??I?.color}]}if(g===ut||g===uZA||g===Vp||g===dZA||g===AL||g===jp){let B;if(g===ut){const C=I?.size??[1,1,1],l=I?.offset,Q=I?.center??(l?[l[0],l[1],l[2]]:[0,0,0]);B=i.cuboid({size:C,center:Q})}else if(g===uZA){const C=I?.size??1,l=I?.offset,Q=I?.center??(l?[l[0],l[1],l[2]]:[0,0,0]);B=i.cube({size:C,center:Q})}else if(g===Vp){const C=I?.height??1,l=I?.radius??1,Q=I?.center??[0,0,0];B=i.cylinder({height:C,radius:l,center:Q})}else if(g===dZA){const C=I?.radius??1,l=I?.center??[0,0,0];B=i.sphere({radius:C,center:l})}else if(g===jp){const C=I?.height??1,l=I?.radius??1,Q=I?.roundRadius??.1,E=I?.center??[0,0,0];B=i.roundedCylinder({height:C,radius:l,roundRadius:Q,center:E})}else{const C=I?.size??[1,1,1],l=I?.roundRadius??.1,Q=I?.center??[0,0,0];B=i.roundedCuboid({size:C,roundRadius:l,center:Q})}return[{geom:B,color:A??I?.color}]}if(typeof g=="function"){const B=g(I??{});return Mm(B,A,e)}return(c??[]).flatMap(B=>Mm(B,A,e))}function dht(t,A){return{geometries:Mm(t,void 0,{jscad:A})}}function GZA(t){if(t.polygons){const A=[],e=[],i=[];let o=0;for(const s of t.polygons){for(const a of s.vertices)a.index=o,A.push(a[0],a[1],a[2]),t.color&&t.color.length>=3?i.push(t.color[0],t.color[1],t.color[2]):i.push(1,1,1),o++;const r=s.vertices[0].index;for(let a=2;a<s.vertices.length;a++){const g=s.vertices[a-1].index,I=s.vertices[a].index;e.push(r,g,I)}}const n=new dg;if(n.setAttribute("position",new gI(new Float32Array(A),3)),n.setIndex(e),i.length>0&&n.setAttribute("color",new gI(new Float32Array(i),3)),t.transforms){const s=new es;s.fromArray(t.transforms),n.applyMatrix4(s)}return n.computeVertexNormals(),n}if(t.sides){const A=[],e=[];for(const o of t.sides)A.push(o[0][0],o[0][1],0),t.color&&t.color.length>=3?e.push(t.color[0],t.color[1],t.color[2]):e.push(1,1,1);const i=new dg;if(i.setAttribute("position",new gI(new Float32Array(A),3)),e.length>0&&i.setAttribute("color",new gI(new Float32Array(e),3)),t.transforms){const o=new es;o.fromArray(t.transforms),i.applyMatrix4(o)}return i}return console.error("Invalid CSG object: neither polygons nor sides found"),new dg}function pht(t,A){const e=nCA(Eht,{footprint:t});return dht(e,A)}var fht=_r(s5()),FZA=$.createContext(null),yht=()=>{const t=$.useContext(FZA);if(!t)throw new Error("useHover must be used within a HoverProvider");return t},wht=({children:t})=>{const{camera:A,renderer:e}=ku(),[i,o]=$.useState([]),n=$.useMemo(()=>new vme,[]),s=$.useMemo(()=>new Io,[]),r=$.useRef(i);r.current=i;const a=$.useRef(null),g=$.useCallback(l=>{o(Q=>[...Q,l])},[]),I=$.useCallback(l=>{if(a.current){let Q=!1,E=a.current.object;for(;E;){if(E===l){Q=!0;break}E=E.parent}Q&&(a.current.onUnhover(),a.current=null)}o(Q=>Q.filter(E=>E.object!==l))},[]),c=$.useCallback(l=>{let Q=l;for(;Q;){const E=r.current.find(h=>h.object===Q);if(E)return E;Q=Q.parent}},[]),B=$.useCallback(l=>{if(!e.domElement)return;const Q=e.domElement.getBoundingClientRect();s.x=(l.clientX-Q.left)/Q.width*2-1,s.y=-((l.clientY-Q.top)/Q.height)*2+1,n.setFromCamera(s,A);const E=r.current.map(u=>u.object);if(E.length===0){a.current&&(a.current.onUnhover(),a.current=null);return}const h=n.intersectObjects(E,!0);if(h.length>0){const u=h[0],d=c(u.object);if(d){const f={mousePosition:[u.point.x,u.point.y,u.point.z]};a.current!==d?(a.current?.onUnhover(),d.onHover(f),a.current=d):d.onHover(f)}else a.current&&(a.current.onUnhover(),a.current=null)}else a.current&&(a.current.onUnhover(),a.current=null)},[A,e,n,s,c]);$.useEffect(()=>{const l=e.domElement;return l.addEventListener("mousemove",B),()=>{l.removeEventListener("mousemove",B)}},[e,B]);const C=$.useMemo(()=>({addHoverable:g,removeHoverable:I}),[g,I]);return V.jsx(FZA.Provider,{value:C,children:t})},mht=({children:t,object:A,onHover:e,onUnhover:i,isHovered:o})=>{const{addHoverable:n,removeHoverable:s}=yht();return $.useEffect(()=>A?(n({object:A,onHover:e,onUnhover:i}),()=>{s(A)}):void 0,[A,e,i,n,s]),V.jsx(V.Fragment,{children:t})},cL=mht,Dht=({positionOffset:t,footprint:A,rotationOffset:e,onHover:i,onUnhover:o,isHovered:n,scale:s,isTranslucent:r=!1})=>{const{rootObject:a}=ku(),g=$.useMemo(()=>{if(!A)return null;const{geometries:I}=pht(A,fht),c=new Jp;for(const B of I.flat(1/0)){const C=B.geom;if(!C||!C.polygons&&!C.sides)continue;const l=new Li(B.color);l.convertLinearToSRGB();const Q={...C,color:[l.r,l.g,l.b]},E=GZA(Q),h=new Ih({vertexColors:!0,side:JC,transparent:r,opacity:r?.5:1,depthWrite:!r}),u=new Wo(E,h);c.add(u)}return c},[A,r]);return $.useEffect(()=>{if(!(!g||!a))return a.add(g),()=>{a.remove(g)}},[a,g]),$.useEffect(()=>{g&&(t&&g.position.fromArray(t),e&&g.rotation.fromArray(e),s!==void 0&&g.scale.setScalar(s))},[g,t?.[0],t?.[1],t?.[2],e?.[0],e?.[1],e?.[2],s]),$.useEffect(()=>{g&&g.traverse(I=>{I instanceof Wo&&I.material instanceof Ih&&(n?(I.material.emissive.setHex(255),I.material.emissiveIntensity=.2):I.material.emissiveIntensity=0)})},[n,g]),g?V.jsx(cL,{isHovered:n,onHover:i,onUnhover:o,object:g}):null},RZA=new WeakMap,Sht=()=>{const t=new Uc;return t.name="fallback-environment-map",t.mapping=bT,t},bht=t=>{if(!t)return null;const A=t,e=RZA.get(A);if(e)return e;let i;if(t instanceof nK){const o=new Fz(t);i=o.fromScene(JSe(),.04).texture,o.dispose()}else i=Sht();return RZA.set(A,i),i},MZA=1.25;function NZA({gltfUrl:t,position:A,rotation:e,onHover:i,onUnhover:o,isHovered:n,scale:s,isTranslucent:r=!1}){const{renderer:a,rootObject:g}=ku(),[I,c]=$.useState(null),[B,C]=$.useState(null);if($.useEffect(()=>{if(!t)return;const l=new KSe;let Q=!0;return l.load(t,E=>{if(!Q)return;const h=E.scene;h.traverse(u=>{if(u instanceof Wo&&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)}}),c(h)},void 0,E=>{if(!Q)return;console.error(`An error happened loading ${t}`,E);const h=E instanceof Error?E:new Error(`Failed to load glTF model from ${t}`);C(h)}),()=>{Q=!1}},[t,r]),$.useEffect(()=>{I&&(A&&I.position.fromArray(A),e&&I.rotation.fromArray(e),s!==void 0&&I.scale.setScalar(s))},[I,A?.[0],A?.[1],A?.[2],e?.[0],e?.[1],e?.[2],s]),$.useEffect(()=>{if(!(!g||!I))return g.add(I),()=>{g.remove(I)}},[g,I]),$.useEffect(()=>{if(!I||!a)return;const l=bht(a);if(!l)return;const Q=[],E=h=>{h instanceof Ih&&(Q.push({material:h,envMap:h.envMap??null,envMapIntensity:h.envMapIntensity??1}),h.envMap=l,(typeof h.envMapIntensity!="number"||h.envMapIntensity<MZA)&&(h.envMapIntensity=MZA),h.needsUpdate=!0)};return I.traverse(h=>{if(!(h instanceof Wo))return;const u=h.material;Array.isArray(u)?u.forEach(E):u&&E(u)}),()=>{Q.forEach(({material:h,envMap:u,envMapIntensity:d})=>{h.envMap=u,h.envMapIntensity=d,h.needsUpdate=!0})}},[I,a]),$.useEffect(()=>{I&&I.traverse(l=>{l instanceof Wo&&l.material instanceof Ih&&(n?(l.material.emissive.setHex(255),l.material.emissiveIntensity=.2):l.material.emissiveIntensity=0)})},[n,I]),B)throw B;return I?V.jsx(cL,{isHovered:n,onHover:i,onUnhover:o,object:I}):null}var xht=_r(sWA()),kht=_r(s5()),Ght=({jscadPlan:t,positionOffset:A,rotationOffset:e,onHover:i,onUnhover:o,isHovered:n,scale:s,isTranslucent:r=!1})=>{const{rootObject:a}=ku(),{threeGeom:g,material:I}=$.useMemo(()=>{const B=(0,xht.executeJscadOperations)(kht.default,t);if(!B||!B.polygons&&!B.sides)return{threeGeom:null,material:null};const C=GZA(B),l=new Ih({vertexColors:!0,side:JC,transparent:r,opacity:r?.5:1,depthWrite:!r});return{threeGeom:C,material:l}},[t,r]),c=$.useMemo(()=>g?new Wo(g,I):null,[g,I]);return $.useEffect(()=>{if(!(!c||!a))return a.add(c),()=>{a.remove(c)}},[a,c]),$.useEffect(()=>{c&&(A&&c.position.fromArray(A),e&&c.rotation.fromArray(e),s!==void 0&&c.scale.setScalar(s))},[c,A?.[0],A?.[1],A?.[2],e?.[0],e?.[1],e?.[2],s]),$.useMemo(()=>{if(I)if(n){const B=new Li(I.color.getHex());I.emissive.copy(B),I.emissive.setRGB(0,0,1),I.emissiveIntensity=.2}else I.emissiveIntensity=0},[n,I]),g?V.jsx(cL,{isHovered:n,onHover:i,onUnhover:o,object:c}):null};function Fht(t){return t.replace(/(DEF|USE)\s+([^\s]+)/g,(A,e,i)=>`${e} ${i.replace(/-/g,"_")}`)}async function Rht(t){const A=await fetch(t);if(!A.ok)throw new Error(`Failed to fetch "${t}": ${A.status} ${A.statusText}`);const e=await A.text();return new xbe().parse(Fht(e),t)}typeof window<"u"&&!window.TSCIRCUIT_OBJ_LOADER_CACHE&&(window.TSCIRCUIT_OBJ_LOADER_CACHE=new Map);function Mht(t){const[A,e]=$.useState(null);return $.useEffect(()=>{if(!t)return;const i=t.replace(/&cachebust_origin=$/,""),o=window.TSCIRCUIT_OBJ_LOADER_CACHE;let n=!1;async function s(){try{if(i.endsWith(".wrl"))return await Rht(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(),I=g.match(/newmtl[\s\S]*?endmtl/g),c=new Ube;if(I?.length){const B=I.join(`
|
|
5067
|
+
`).replace(/d 0\./g,"d 1."),C=g.replace(/newmtl[\s\S]*?endmtl/g,"").replace(/^mtllib.*/gm,""),l=new Dbe;l.setMaterialOptions({invertTrProperty:!0});const Q=l.parse(B.replace(/Kd\s+([\d.]+)\s+([\d.]+)\s+([\d.]+)/g,"Kd $2 $2 $2"),"embedded.mtl");return c.setMaterials(Q),c.parse(C)}return c.parse(g.replace(/^mtllib.*/gm,""))}catch(a){return a}}function r(){if(o.has(i)){const g=o.get(i);return g.result?Promise.resolve(g.result.clone()):g.promise.then(I=>I instanceof Error?I:I.clone())}const a=s().then(g=>(g instanceof Error||o.set(i,{...o.get(i),result:g}),g));return o.set(i,{promise:a,result:null}),a}return r().then(a=>{n||e(a)}).catch(a=>{console.error(a)}),()=>{n=!0}},[t]),A}function Nht({url:t,position:A,rotation:e,onHover:i,onUnhover:o,isHovered:n,scale:s,isTranslucent:r=!1}){const a=Mht(t),{rootObject:g}=ku(),I=$.useMemo(()=>a&&!(a instanceof Error)?(a.traverse(c=>{if(c instanceof Wo&&c.material){const B=C=>{C.transparent=r,C.opacity=r?.5:1,C.depthWrite=!r,C.needsUpdate=!0};Array.isArray(c.material)?c.material.forEach(B):B(c.material)}}),a):new Wo(new Bw(.5,.5,.5),new Ih({transparent:!0,color:"red",opacity:.25})),[a,r]);if($.useEffect(()=>{if(!(!g||!I))return g.add(I),()=>{g.remove(I)}},[g,I]),$.useEffect(()=>{I&&(A&&(Array.isArray(A)?I.position.fromArray(A):I.position.copy(A)),e&&(Array.isArray(e)?I.rotation.fromArray(e):I.rotation.copy(e)),s!==void 0&&I.scale.setScalar(s))},[I,Array.isArray(A)?A[0]:A?.x,Array.isArray(A)?A[1]:A?.y,Array.isArray(A)?A[2]:A?.z,Array.isArray(e)?e[0]:e?.x,Array.isArray(e)?e[1]:e?.y,Array.isArray(e)?e[2]:e?.z,s]),a instanceof Error)throw a;return V.jsx(cL,{isHovered:n,onHover:i,onUnhover:o,object:I})}var DCA,_ht="https://cdn.jsdelivr.net/npm/occt-import-js@0.0.23/dist";function vht(t){if(typeof t=="function")return t;if(t&&typeof t=="object"&&"default"in t&&typeof t.default=="function")return t.default;throw new Error("Unable to resolve occt-import-js factory export")}async function Uht(){if(!DCA){const t=await import("https://cdn.jsdelivr.net/npm/occt-import-js@0.0.23/+esm");DCA=vht(t)({locateFile:e=>`${_ht}/${e}`})}return DCA}function Lht(t){const A=new Jp;for(const e of t){const i=e.attributes.position?.array??[],o=e.index?.array??[];if(!i.length||!o.length)continue;const n=new dg;n.setAttribute("position",new vn(i,3));const s=e.attributes.normal?.array??[];s.length?n.setAttribute("normal",new vn(s,3)):n.computeVertexNormals(),n.setIndex(o);const r=new Ih({color:e.color?new Li(e.color[0],e.color[1],e.color[2]):new Li(.82,.82,.82)}),a=new Wo(n,r);a.name=e.name,A.add(a)}return A}async function Hht(t){const A=await fetch(t);if(!A.ok)throw new Error(`Failed to fetch STEP file: ${A.statusText}`);const e=await A.arrayBuffer(),o=(await Uht()).ReadStepFile(new Uint8Array(e),null);if(!o.success||!o.meshes.length)throw new Error("occt-import-js failed to convert STEP file");const n=Lht(o.meshes),s=new A6,r=await new Promise((a,g)=>{s.parse(n,I=>{I instanceof ArrayBuffer?a(I):g(new Error("GLTFExporter did not return binary output"))},I=>{g(I)},{binary:!0})});return URL.createObjectURL(new Blob([r],{type:"model/gltf-binary"}))}var _ZA="step-glb-cache:";function Yht(t){const A=new Uint8Array(t),e=32768;let i="";for(let o=0;o<A.length;o+=e){const n=A.subarray(o,o+e);i+=String.fromCharCode(...n)}return btoa(i)}function Jht(t){const A=atob(t),e=new Uint8Array(A.length);for(let i=0;i<A.length;i+=1)e[i]=A.charCodeAt(i);return e.buffer}function Tht(t){try{const A=localStorage.getItem(`${_ZA}${t}`);return A?Jht(A):null}catch(A){return console.warn("Failed to read STEP GLB cache",A),null}}function Kht(t,A){try{const e=Yht(A);localStorage.setItem(`${_ZA}${t}`,e)}catch(e){console.warn("Failed to write STEP GLB cache",e)}}var qht=({stepUrl:t,position:A,rotation:e,scale:i,onHover:o,onUnhover:n,isHovered:s,isTranslucent:r})=>{const[a,g]=$.useState(null);return $.useEffect(()=>{let I=!0,c=null;const B=Tht(t);return B?(c=URL.createObjectURL(new Blob([B],{type:"model/gltf-binary"})),g(c),()=>{I=!1,c&&URL.revokeObjectURL(c)}):(Hht(t).then(C=>{if(!I){URL.revokeObjectURL(C);return}c=C,g(C),fetch(C).then(l=>l.arrayBuffer()).then(l=>{Kht(t,l)}).catch(l=>{console.warn("Failed to cache STEP GLB",l)})}).catch(C=>{console.error("Failed to convert STEP file to GLB",C),I&&g(null)}),()=>{I=!1,c&&URL.revokeObjectURL(c)})},[t]),a?V.jsx(NZA,{gltfUrl:a,position:A,rotation:e,scale:i,onHover:o,onUnhover:n,isHovered:s,isTranslucent:r}):null},SCA=(...t)=>t,vZA=({cad_component:t,circuitJson:A})=>{const e=gWA(A),[i,o]=$.useState(!1),{visibility:n}=WN(),[s,r]=$.useState(null),a=$.useCallback(f=>{f?.mousePosition?(o(!0),r(f.mousePosition)):(o(!1),r(null))},[]),g=$.useCallback(()=>{o(!1),r(null)},[]),I=$.useMemo(()=>mi(A).source_component.getUsing({source_component_id:t.source_component_id})?.name,[A,t.source_component_id]),c=$.useMemo(()=>A.filter(m=>m.type==="pcb_plated_hole"&&m.pcb_component_id===t.pcb_component_id).length>0,[A,t.pcb_component_id]),B=t.model_obj_url??t.model_wrl_url??t.model_stl_url,C=t.model_glb_url??t.model_gltf_url,l=t.model_step_url,E=A.find(f=>f.type==="pcb_component"&&f.source_component_id===t.source_component_id)?.layer??"top",h=$.useMemo(()=>{const f=t.rotation?SCA(t.rotation.x*Math.PI/180,t.rotation.y*Math.PI/180,t.rotation.z*Math.PI/180):SCA(0,0,0);return E==="bottom"?SCA(f[0]+Math.PI,f[1],-f[2]):f},[t.rotation,E]),u=$.useMemo(()=>{if(!t.position)return;const f=.55;let m;return E==="top"?m=e/2:E==="bottom"?m=-(e/2)-f:m=t.position.z,[t.position.x,t.position.y,m]},[t.position,E,e]);let d=null;if(B?d=V.jsx(Nht,{url:B,position:u,rotation:h,scale:t.model_unit_to_mm_scale_factor,onHover:a,onUnhover:g,isHovered:i,isTranslucent:t.show_as_translucent_model},t.cad_component_id):C?d=V.jsx(NZA,{gltfUrl:C,position:u,rotation:h,scale:t.model_unit_to_mm_scale_factor,onHover:a,onUnhover:g,isHovered:i,isTranslucent:t.show_as_translucent_model},t.cad_component_id):l&&!t.model_jscad&&!t.footprinter_string?d=V.jsx(qht,{stepUrl:l,position:u,rotation:h,scale:t.model_unit_to_mm_scale_factor,onHover:a,onUnhover:g,isHovered:i,isTranslucent:t.show_as_translucent_model}):t.model_jscad?d=V.jsx(Ght,{jscadPlan:t.model_jscad,positionOffset:u,rotationOffset:h,scale:t.model_unit_to_mm_scale_factor,onHover:a,onUnhover:g,isHovered:i,isTranslucent:t.show_as_translucent_model},t.cad_component_id):t.footprinter_string&&(d=V.jsx(Dht,{positionOffset:u,rotationOffset:h,footprint:t.footprinter_string,scale:t.model_unit_to_mm_scale_factor,onHover:a,onUnhover:g,isHovered:i,isTranslucent:t.show_as_translucent_model})),t.show_as_translucent_model){if(!n.translucentModels)return null}else if(c&&!n.throughHoleModels||!c&&!n.smtModels)return null;return V.jsxs(V.Fragment,{children:[d,i&&s?V.jsx(cWA,{position:s,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]})},UZA={version:"0.0.500"};function Pht(t){t.querySelectorAll("canvas").forEach(A=>A.remove())}var Oht=t=>{t.outputColorSpace=iw,t.toneMapping=qDA,t.toneMappingExposure=1},LZA="cadViewerCameraStateSession",HZA=(t,A)=>{try{const e={position:t.position.toArray(),quaternion:t.quaternion.toArray(),up:t.up.toArray(),fov:t.fov??50,target:A.target.toArray()};sessionStorage.setItem(LZA,JSON.stringify(e))}catch(e){console.warn("Failed to save camera:",e)}},bCA=(t,A)=>{try{const e=sessionStorage.getItem(LZA);if(!e)return!1;const i=JSON.parse(e);if(t.position.fromArray(i.position),t.quaternion.fromArray(i.quaternion),t.up.fromArray(i.up),"fov"in t){const o=t;o.fov=i.fov,o.updateProjectionMatrix?.()}return A.target.fromArray(i.target),A.update(),t.updateMatrixWorld(),!0}catch(e){return console.warn("Failed to restore camera:",e),!1}},YZA=$.createContext(void 0),Wht=({children:t,defaultTarget:A,initialCameraPosition:e})=>{const i=$.useRef(null),o=$.useRef(null),[n,s]=$.useState(null),[r,a]=$.useState("perspective"),[g,I]=$.useState(e??null),[c,B]=$.useState(new Hp(0,0,0)),C=$.useMemo(()=>{const[h,u,d]=e??[5,-5,5],f=Math.hypot(h-A.x,u-A.y,d-A.z);return f>0?f:5},[e,A]),l=$.useCallback(h=>{const u=[A.x,A.y,A.z],d=o.current,f=i.current;let m=C;switch(d&&f&&(m=d.position.distanceTo(f.target)),h){case"Top Center Angled":{const b=m/Math.sqrt(2);return{position:[A.x,A.y-b,A.z+b],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}},[C,A,o,i]),Q=$.useCallback(h=>{i.current=h},[]),E=$.useMemo(()=>({controlsRef:i,mainCameraRef:o,defaultTarget:A,baseDistance:C,controller:n,setController:s,getPresetConfig:l,handleControlsChange:Q,cameraType:r,setCameraType:a,cameraPosition:g,setCameraPosition:I,cameraRotation:c,setCameraRotation:B,saveCameraToSession:HZA,loadCameraFromSession:bCA}),[A,C,n,l,Q,r,g,c]);return V.jsx(YZA.Provider,{value:E,children:t})},Fx=()=>{const t=$.useContext(YZA);if(!t)throw new Error("useCameraController must be used within a CameraControllerProvider");return t},Zht=$.forwardRef(({children:t,scene:A,camera:e,style:i,onCreated:o},n)=>{const{cameraType:s}=Fx(),r=$.useRef(null),[a,g]=$.useState(null),I=$.useRef([]),c=$.useRef(void 0);c.current=o;const B=$.useRef(null),C=$.useCallback(h=>{I.current.push(h)},[]),l=$.useCallback(h=>{I.current=I.current.filter(u=>u!==h)},[]),Q=$.useMemo(()=>new lG,[]);A?.up&&Q.up.set(A.up.x,A.up.y,A.up.z);const E=$.useRef(new ug);return $.useImperativeHandle(n,()=>E.current),$.useEffect(()=>{if(!r.current)return;Pht(r.current);const h=new nK({antialias:!0,alpha:!0});Oht(h),h.setSize(r.current.clientWidth,r.current.clientHeight),h.setPixelRatio(window.devicePixelRatio),r.current.appendChild(h.domElement);const u=r.current.clientWidth/r.current.clientHeight,d=s==="perspective"?new rE(75,u,.1,1e3):new W1(-10*u,10*u,10,-10,-1e3,1e3);B.current?(d.position.copy(B.current.position),d.quaternion.copy(B.current.quaternion),d.up.copy(B.current.up)):(e?.up&&d.up.set(e.up[0],e.up[1],e.up[2]),e?.position&&d.position.set(e.position[0],e.position[1],e.position[2]),d.lookAt(0,0,0)),Q.add(E.current),window.__TSCIRCUIT_THREE_OBJECT=E.current,g({scene:Q,camera:d,renderer:h,rootObject:E.current,addFrameListener:C,removeFrameListener:l}),c.current?.({camera:d,renderer:h});let f;const m=new Sme,b=()=>{const x=m.getElapsedTime(),F=m.getDelta();I.current.forEach(k=>k(x,F)),h.render(Q,d),f=requestAnimationFrame(b)};b();const D=()=>{if(r.current){const x=r.current.clientWidth/r.current.clientHeight;d instanceof rE?d.aspect=x:d instanceof W1&&(d.left=-10*x,d.right=10*x,d.top=10,d.bottom=-10),d.updateProjectionMatrix(),h.setSize(r.current.clientWidth,r.current.clientHeight)}};return window.addEventListener("resize",D),()=>{B.current={position:d.position.clone(),quaternion:d.quaternion.clone(),up:d.up.clone()},window.removeEventListener("resize",D),cancelAnimationFrame(f),r.current&&h.domElement&&r.current.removeChild(h.domElement),h.dispose(),Q.remove(E.current),window.__TSCIRCUIT_THREE_OBJECT===E.current&&(window.__TSCIRCUIT_THREE_OBJECT=void 0)}},[Q,C,l,s]),V.jsx("div",{ref:r,style:{width:"100%",height:"100%",...i},children:a&&V.jsx(IWA.Provider,{value:a,children:V.jsx(wht,{children:t})})})}),Vht=({autoRotate:t,autoRotateSpeed:A,onStart:e,panSpeed:i,rotateSpeed:o,zoomSpeed:n,enableDamping:s,dampingFactor:r,target:a,onControlsChange:g})=>{const{camera:I,renderer:c}=ku(),B=$.useMemo(()=>!I||!c?null:new Hbe(I,c.domElement),[I,c]);return $.useEffect(()=>(g?.(B??null),()=>g?.(null)),[B,g]),$.useEffect(()=>{if(!B)return;const C=()=>{g?.(B)};return B.addEventListener("change",C),()=>{B.removeEventListener("change",C)}},[B,g]),$.useEffect(()=>{B&&(B.autoRotate=t||!1,B.autoRotateSpeed=A||1,i!==void 0&&(B.panSpeed=i),o!==void 0&&(B.rotateSpeed=o),n!==void 0&&(B.zoomSpeed=n),s!==void 0&&(B.enableDamping=s),r!==void 0&&(B.dampingFactor=r),B.zoomToCursor=!0,B.mouseButtons={LEFT:Gb.ROTATE,MIDDLE:Gb.PAN,RIGHT:null},a&&(B.target.set(a[0],a[1],a[2]),B.update()))},[B,t,A,i,o,n,s,r,a]),$.useEffect(()=>{if(!(!B||!e))return B.addEventListener("start",e),()=>{B.removeEventListener("start",e)}},[B,e]),$.useEffect(()=>{if(B)return()=>{B.dispose()}},[B]),zU(()=>{B?.update()},[B]),null},jht=`
|
|
5068
5068
|
varying vec3 worldPosition;
|
|
5069
5069
|
void main() {
|
|
5070
5070
|
worldPosition = (modelMatrix * vec4(position, 1.0)).xyz;
|
|
@@ -5098,12 +5098,12 @@ ${a.join(`
|
|
|
5098
5098
|
gl_FragColor = vec4(color, max(g1, g2) * a);
|
|
5099
5099
|
if (gl_FragColor.a <= 0.0) discard;
|
|
5100
5100
|
}
|
|
5101
|
-
`,Xht=({rotation:t,infiniteGrid:A,cellSize:e=1,sectionSize:i=10})=>{const{scene:o,camera:n}=ku(),s=1e3,r=$.useMemo(()=>{const a=new Cw(s,s);a.rotateX(-Math.PI/2);const g=new nm({vertexShader:jht,fragmentShader:zht,uniforms:{cellSize:{value:e},sectionSize:{value:i},gridColor:{value:new Li(15658734)},sectionColor:{value:new Li(13421823)},fadeDistance:{value:100},fadeStrength:{value:1.5}},transparent:!0,side:JC}),I=new Wo(a,g);return t&&I.rotation.fromArray(t),I},[s,e,i,t]);return zU(()=>{A&&r.position.set(n.position.x,n.position.y,0)}),$.useEffect(()=>{if(!(!o||!r))return o.add(r),()=>{o.remove(r),r.geometry.dispose(),Array.isArray(r.material)?r.material.forEach(a=>a.dispose()):r.material.dispose()}},[o,r]),null},$ht=()=>{const{scene:t}=ku(),A=$.useMemo(()=>new CxA(16777215,Math.PI/2),[]),e=$.useMemo(()=>{const i=new eX(16777215,Math.PI/4);return i.position.set(-10,-10,10),i.decay=0,i},[]);return $.useEffect(()=>{if(t)return t.add(A),t.add(e),()=>{t.remove(A),t.remove(e)}},[t,A,e]),null},Aut=t=>t<.5?4*t*t*t:1-Math.pow(-2*t+2,3)/2,eut=()=>{const{controlsRef:t,mainCameraRef:A,defaultTarget:e,setController:i,getPresetConfig:o}=Fx(),n=$.useRef(null),s=$.useRef(new dd),r=$.useRef(new Me),a=$.useRef(new Me),g=$.useRef(new dd),I=$.useRef(new dd),c=$.useRef(new ug),B=$.useRef(new ug),C=$.useCallback(({position:Q,target:E,up:h,durationMs:u=600})=>{if(!A.current)return;const d=t.current?.target??e,f=new Me(Q[0],Q[1],Q[2]),m=E?new Me(E[0],E[1],E[2]):e.clone(),b=new Me(...h??[0,0,1]).normalize(),D=B.current;D.position.copy(f),D.up.copy(b),D.lookAt(m);const x=D.quaternion.clone(),F=A.current.quaternion.clone(),k=A.current.position.clone(),v=d.clone(),_=c.current;_.up.set(0,0,1),_.position.copy(k),_.lookAt(v);const Y=_.quaternion.clone();_.up.set(0,0,1),_.position.copy(f),_.lookAt(m);const P=_.quaternion.clone(),T=Y.clone().invert().multiply(F).normalize(),O=P.clone().invert().multiply(x).normalize();n.current={fromPosition:k,toPosition:f,fromTarget:v,toTarget:m,toQuaternion:x,rollFrom:T,rollTo:O,startTime:performance.now(),duration:u}},[A,t,e]),l=$.useCallback(Q=>{if(Q==="Custom")return;const E=o(Q);E&&C(E)},[C,o]);return $.useEffect(()=>A.current?(i({animateTo:C,animateToPreset:l}),()=>{i(null)}):void 0,[C,l,A,i]),zU(()=>{if(!A.current||!n.current)return;const{fromPosition:Q,toPosition:E,fromTarget:h,toTarget:u,toQuaternion:d,rollFrom:f,rollTo:m,startTime:b,duration:D}=n.current,x=performance.now()-b,F=D<=0?1:Math.min(x/D,1),k=Aut(F);A.current.position.lerpVectors(Q,E,k);const v=r.current;v.copy(h).lerp(u,k);const _=c.current;_.up.set(0,0,1),_.position.copy(A.current.position),_.lookAt(v);const Y=s.current;Y.copy(_.quaternion);const P=g.current;P.copy(f);const T=I.current;T.copy(m),f.dot(m)<0&&(T.x*=-1,T.y*=-1,T.z*=-1,T.w*=-1),T.normalize(),P.slerp(T,k),A.current.quaternion.copy(Y).multiply(P).normalize();const O=a.current;O.set(0,1,0).applyQuaternion(A.current.quaternion).normalize(),A.current.up.copy(O),t.current?.target.copy(v),A.current.updateMatrixWorld(),t.current?.update(),F>=1&&(A.current.position.copy(E),A.current.quaternion.copy(d),A.current.up.set(0,0,1),A.current.updateMatrixWorld(),t.current?.target.copy(u),t.current?.update(),n.current=null)}),null},tut=()=>{const{controlsRef:t}=Fx(),A=$.useRef(null),e=$.useRef(!1),i=$.useRef(null),o=$.useCallback(s=>{A.current=s,!e.current&&t.current&&bCA(s,t.current)&&(e.current=!0)},[t]),n=$.useCallback(()=>{if(!(!A.current||!t.current)){if(!e.current&&bCA(A.current,t.current)){e.current=!0;return}clearTimeout(i.current),i.current=setTimeout(()=>{A.current&&t.current&&HZA(A.current,t.current)},150)}},[t]);return{handleCameraCreated:o,handleControlsChange:n}};function iut(t,A){const e=new dd().setFromEuler(new Hp(t.x,t.y,t.z)),i=new Me(0,0,1);return i.applyQuaternion(e),i.multiplyScalar(A)}var out=()=>{const{mainCameraRef:t}=Fx(),A=$.useRef(null),e=$.useRef(null),i=$.useRef(null),o=$.useRef(null),n=$.useRef(null),s=$.useRef(null);return $.useEffect(()=>{if(!A.current)return;const r=document.createElement("canvas");e.current=r,A.current.appendChild(r);const a=new nK({canvas:r,antialias:!0,alpha:!0});a.setSize(120,120),a.setPixelRatio(window.devicePixelRatio),i.current=a;const g=new lG;o.current=g;const I=new rE(75,1,.1,1e3);I.up.set(0,0,1),n.current=I;const c=new CxA(16777215,Math.PI/2);g.add(c);const B=new Jp;B.rotation.fromArray([Math.PI/2,0,0]);const C=1,l=new Wo(new Bw(C,C,C),new Ih({color:"white"}));B.add(l);const Q=new X1(new Kwe(new Bw(C,C,C)),new QG({color:0,linewidth:2}));B.add(Q),g.add(B);const E=.51,h=(F,k,v)=>{const _=new d6;return _.text=F,_.position.fromArray(k),v&&_.rotation.fromArray(v),_.color="black",_.fontSize=.25,_.anchorX="center",_.anchorY="middle",_.depthOffset=0,_.font=null,_.sync(),_},u=h("Front",[0,0,E]),d=h("Back",[0,0,-E],[0,Math.PI,0]),f=h("Right",[E,0,0],[0,Math.PI/2,0]),m=h("Left",[-E,0,0],[0,-Math.PI/2,0]),b=h("Top",[0,E,0],[-Math.PI/2,0,0]),D=h("Bottom",[0,-E,0],[Math.PI/2,0,0]);B.add(u),B.add(d),B.add(f),B.add(m),B.add(b),B.add(D);const x=()=>{if(t.current){const F=iut(t.current.rotation??new Hp(0,0,0),2);F.equals(I.position)||(I.position.copy(F),I.lookAt(0,0,0))}a.render(g,I),s.current=requestAnimationFrame(x)};return x(),()=>{s.current&&cancelAnimationFrame(s.current),u.dispose(),d.dispose(),f.dispose(),m.dispose(),b.dispose(),D.dispose(),l.geometry.dispose(),l.material.dispose(),Q.geometry.dispose(),Q.material.dispose(),g.clear(),a.dispose(),e.current&&A.current&&A.current.removeChild(e.current)}},[t]),V.jsx("div",{ref:A,style:{position:"absolute",top:0,left:0,width:120,height:120,zIndex:XU.orientationCube}})},nut=()=>{const{camera:t}=ku(),{setCameraRotation:A}=Fx();return zU(()=>{t&&A(t.rotation)}),null},JZA=$.forwardRef(({children:t,initialCameraPosition:A=[5,-5,5],autoRotateDisabled:e,clickToInteractEnabled:i=!1,boardDimensions:o,boardCenter:n,onUserInteraction:s,onCameraControllerReady:r},a)=>{const[g,I]=$.useState(!i),{mainCameraRef:c,handleControlsChange:B,controller:C}=Fx(),{handleCameraCreated:l,handleControlsChange:Q}=tut();$.useEffect(()=>{r&&r(C)},[C,r]);const E=$.useMemo(()=>{if(!o)return 10;const u=o.width??0,d=o.height??0,m=Math.max(u,d)*1.5;return m>10?m:10},[o]),h=$.useMemo(()=>{if(n)return[n.x,n.y,0]},[n]);return V.jsxs("div",{style:{position:"relative",width:"100%",height:"100%"},children:[V.jsx(out,{}),V.jsxs(Zht,{ref:a,scene:{up:new Me(0,0,1)},camera:{up:[0,0,1],position:A},onCreated:({camera:u})=>{c.current=u,l(u)},children:[V.jsx(eut,{}),V.jsx(nut,{}),g&&V.jsx(Vht,{autoRotate:!e,autoRotateSpeed:1,onStart:s,rotateSpeed:.5,panSpeed:.75,zoomSpeed:.5,enableDamping:!0,dampingFactor:.1,target:h,onControlsChange:u=>{B(u),Q()}}),V.jsx($ht,{}),V.jsx(Xht,{rotation:[Math.PI/2,0,0],infiniteGrid:!0,cellSize:3,sectionSize:E,args:[E,E]}),t]}),V.jsxs("div",{style:{position:"absolute",right:24,bottom:24,fontFamily:"sans-serif",color:"white",WebkitTextStroke:"0.5px rgba(0, 0, 0, 0.5)",fontSize:11},children:["@",UZA.version]}),i&&!g&&V.jsx("button",{type:"button",onClick:()=>I(!0),onKeyDown:u=>{(u.key==="Enter"||u.key===" ")&&I(!0)},style:{position:"absolute",inset:0,cursor:"pointer",zIndex:XU.clickToInteractOverlay,display:"flex",alignItems:"center",justifyContent:"center"},children:V.jsx("div",{style:{backgroundColor:"rgba(0, 0, 0, 0.8)",color:"white",padding:"12px 24px",borderRadius:"8px",fontSize:"16px",fontFamily:"sans-serif",pointerEvents:"none"},children:"Click to Interact"})})]})}),TZA=t=>$.useMemo(()=>{if(!t)return[];const A=new mXe;return A.add(t),A.render(),A.getCircuitJson()},[t]),sut=t=>{const[A,e]=$.useState([]),[i,o]=$.useState(!0);return $.useEffect(()=>{if(!t)return;(async()=>{o(!0);const r=(Array.isArray(t)?t:[t]).map(async(a,g)=>{const I=xet.serialize({binary:!0},[a]),B=await new Blob(I).arrayBuffer(),l=a.layerType||(g===0?"board":void 0);return{stlData:B,color:a.color,layerType:l}});try{const a=await Promise.all(r);e(a)}catch(a){console.error("Error generating STLs:",a),e([])}finally{o(!1)}})()},[t]),{stls:A,loading:i}},rut=_r(xx()),aut=_r(XO()),wo=.01,$a={traces:.001,copper:.002},Go={copper:[.9,.6,.2],fr4Tan:[.6,.43,.28],fr4SolderMaskGreen:[.02,.1,.04],fr4TracesWithMaskGreen:[0,.5,.25],fr4TracesWithoutMaskTan:[.6,.43,.28],fr1Tan:[.8,.4,.2],fr1TracesWithMaskCopper:[.9,.6,.2],fr1SolderMaskGreen:[.02,.1,.04]},zp=.001,KC=32,BL=.035,Qc=150,d5=.6,xCA={fr1:Go.fr1Tan,fr4:Go.fr4Tan},gut={fr1:Go.fr1TracesWithMaskCopper,fr4:Go.fr4TracesWithoutMaskTan},KZA={fr1:Go.fr1SolderMaskGreen,fr4:Go.fr4SolderMaskGreen},Iut=_r(jU()),cut=_r(xx()),But=_r(iF()),Cut=_r(tWA()),kCA=t=>{let A=0;for(let i=0;i<t.length;i++){const o=(i+1)%t.length;A+=t[i][0]*t[o][1],A-=t[o][0]*t[i][1]}return A/2<=0},GCA=(t,A=1.2,e={})=>{const{xyOutset:i=0}=e,{outline:o}=t;let n=o.map(a=>[a.x,a.y]);kCA(n)&&(n=n.reverse());let s=(0,cut.polygon)({points:n});i!==0&&(s=(0,Cut.expand)({delta:i,corners:"edge"},s));let r=(0,Iut.extrudeLinear)({height:A},s);return r=(0,But.translate)([0,0,-A/2],r),r},lut=t=>{const A=t.filter(a=>a.type==="pcb_panel"),e=mi(t).pcb_board.list();let i,o=1.2;if(A.length>0)i=A[0],o=e.find(g=>g.pcb_panel_id===i.pcb_panel_id)?.thickness??1.2;else{if(i=e.filter(g=>!g.pcb_panel_id)[0],!i)return console.warn("No pcb_board or pcb_panel found for simplified geometry"),[];o=i.thickness??1.2}let n;"outline"in i&&i.outline&&i.outline.length>0?n=GCA({outline:i.outline},o):n=(0,rut.cuboid)({size:[i.width??10,i.height??10,o],center:[i.center.x,i.center.y,0]});const s="material"in i&&i.material?i.material:A.length>0?e.find(a=>a.pcb_panel_id===i.pcb_panel_id)?.material??"fr4":"fr4",r=xCA[s]??Go.fr4Tan;return[(0,aut.colorize)(r,n)]},XB=_r(iF()),va=_r(xx()),dh=_r(XO()),Ag=_r(ON()),$s=_r(xx()),Nm=_r(XO()),Xr=_r(ON()),qZA=_r(iF()),CL=_r(jU()),xd=_r(iF()),Qut=1e-5;function i0(t,A,e){if(typeof e!="number"||!Number.isFinite(e)||e<=0)return 0;const i=t/2,o=A/2,n=Math.min(i,o)-2*Qut;return Math.max(0,Math.min(e,n))}function kl(t){if(!(!t||typeof t!="object"))return t.corner_radius??t.cornerRadius??t.rect_pad_border_radius??t.rectPadBorderRadius??t.rect_border_radius??t.rectBorderRadius??void 0}var Rx=_r(xx()),Eut=_r(jU()),p5=_r(iF()),hut=_r(ON()),uut=64,dut=(t,A,e)=>{const i=(0,Rx.ellipse)({center:[0,0],radius:[Math.max(t/2,wo/2),Math.max(A/2,wo/2)],segments:uut}),o=(0,Eut.extrudeLinear)({height:e},i);return(0,p5.translate)([0,0,-e/2],o)},put=(t,A,e)=>{const i=Math.max(t,wo),o=Math.max(A,wo);if(Math.abs(i-o)<1e-6)return(0,Rx.cylinder)({center:[0,0,0],radius:i/2,height:e});const n=i>=o,s=n?i:o,r=n?o:i,a=Math.max(s-r,0),g=(0,Rx.cuboid)({center:[0,0,0],size:n?[a,r,e]:[r,a,e]});if(a<=1e-6)return(0,Rx.cylinder)({center:[0,0,0],radius:r/2,height:e});const I=a/2,c=(0,Rx.cylinder)({center:n?[-I,0,0]:[0,-I,0],radius:r/2,height:e}),B=(0,Rx.cylinder)({center:n?[I,0,0]:[0,I,0],radius:r/2,height:e});return(0,hut.union)(g,c,B)},f5=(t,A,e={})=>{const i=t.hole_shape||"circle",o=e.sizeDelta??0,n=t.hole_offset_x||0,s=t.hole_offset_y||0,r=[t.x+n,t.y+s,0];if(i==="circle"){const C=Math.max((t.hole_diameter??0)+o,wo),l=Math.max(C/2,wo/2);return(0,Rx.cylinder)({center:r,radius:l,height:A})}const a=t.hole_width??t.hole_diameter,g=t.hole_height??t.hole_diameter;if(!a||!g)return null;const I=Math.max(a+o,wo),c=Math.max(g+o,wo);if(i==="oval"){const C=dut(I,c,A);return(0,p5.translate)([r[0],r[1],0],C)}if(i==="pill"||i==="rotated_pill"){let C=put(I,c,A);if(!C)return null;const l=t.ccw_rotation||0;return l&&(C=(0,p5.rotateZ)(l*Math.PI/180,C)),(0,p5.translate)(r,C)}const B=Math.max((t.hole_diameter??a??g??wo)+o,wo);return(0,Rx.cylinder)({center:r,radius:B/2,height:A})},o0=.02,y5=64,sF=(t,A)=>A?(0,Xr.intersect)(A,t):t,a_=({width:t,height:A,thickness:e,center:i,borderRadius:o})=>{const n=i0(t,A,o);if(n<=0)return(0,$s.cuboid)({center:i,size:[t,A,e]});const s=(0,$s.roundedRectangle)({size:[t,A],roundRadius:n,segments:y5}),r=(0,CL.extrudeLinear)({height:e},s),a=i[2]-e/2;return(0,xd.translate)([i[0],i[1],a],r)},lL=(t,A,e={})=>{const{clipGeom:i}=e;t.shape||(t.shape="circle");const o=A.pcbThickness+2*o0+4*wo,n=A.pcbThickness/2+$a.copper,s=-A.pcbThickness/2-$a.copper,r=n-s;if(t.shape==="circle"){const a=t.outer_diameter??Math.max(t.hole_diameter,0),g=r+.01,I=(0,$s.cylinder)({center:[t.x,t.y,0],radius:a/2,height:g}),c=sF(I,i),B=(0,$s.cylinder)({center:[t.x,t.y,0],radius:Math.max(t.hole_diameter/2,.01),height:o});return(0,Nm.colorize)(Go.copper,(0,Xr.subtract)(c,B))}if(t.shape==="oval"){const a=t.outer_width||t.hole_width||0,g=t.outer_height||t.hole_height||0,I=t.hole_width||0,c=t.hole_height||0,B=(()=>{const Q=(0,$s.cylinder)({center:[0,0,0],radius:1,height:r+.01,segments:64}),E=(0,qZA.scale)([a/2,g/2,1],Q);return(0,xd.translate)([t.x,t.y,0],E)})(),C=sF(B,i),l=(()=>{const Q=(0,$s.cylinder)({center:[0,0,0],radius:1,height:o,segments:64}),E=(0,qZA.scale)([Math.max(I/2,.01),Math.max(c/2,.01),1],Q);return(0,xd.translate)([t.x,t.y,0],E)})();return(0,Nm.colorize)(Go.copper,(0,Xr.subtract)(C,l))}if(t.shape==="circular_hole_with_rect_pad"){const a=t.hole_offset_x||0,g=t.hole_offset_y||0,I=t.rect_pad_width||t.hole_diameter,c=t.rect_pad_height||t.hole_diameter,B=kl(t),C=sF((0,Xr.union)(a_({width:I,height:c,thickness:o0,center:[t.x,t.y,n],borderRadius:B}),a_({width:I,height:c,thickness:o0,center:[t.x,t.y,s],borderRadius:B}),(()=>{const h=Math.max(r-o0*2,wo),f=(n+s)/2,m=(0,$s.roundedRectangle)({size:[I,c],roundRadius:B||0,segments:y5}),b=(0,CL.extrudeLinear)({height:h},m);return(0,xd.translate)([t.x,t.y,f-h/2],b)})(),(0,$s.cylinder)({center:[t.x+(a||0),t.y+(g||0),0],radius:t.hole_diameter/2,height:r})),i),l=(0,$s.cylinder)({center:[t.x+(a||0),t.y+(g||0),0],radius:Math.max(t.hole_diameter/2-wo,.01),height:o}),Q=(0,$s.cylinder)({center:[t.x+(a||0),t.y+(g||0),0],radius:t.hole_diameter/2,height:r});let E=(0,Xr.union)((0,Xr.subtract)(C,Q),Q);return e.clipGeom?(E=(0,Xr.subtract)(E,l),E=(0,Xr.intersect)(E,e.clipGeom),(0,Nm.colorize)(Go.copper,E)):(0,Nm.colorize)(Go.copper,(0,Xr.subtract)(E,l))}if(t.shape==="pill"){const a=(t.ccw_rotation||0)*Math.PI/180,g=k=>{if(!a)return k;const v=(0,xd.translate)([-t.x,-t.y,0],k),_=(0,xd.rotate)([0,0,a],v);return(0,xd.translate)([t.x,t.y,0],_)},I=t.hole_height>t.hole_width,c=I?t.hole_height:t.hole_width,B=I?t.hole_width:t.hole_height,C=I?t.outer_height||B+.2:t.outer_width||c+.2,l=I?t.outer_width||c+.2:t.outer_height||B+.2,Q=B/2,E=Math.abs(c-B),h=r+.01,d=((k,v,_)=>{const Y=v/2,P=Math.abs(k-v);if(P<=1e-6)return(0,$s.cylinder)({center:[t.x,t.y,0],radius:Y,height:_});const T=(0,$s.cuboid)({center:[t.x,t.y,0],size:I?[v,P,_]:[P,v,_]}),O=(0,$s.cylinder)({center:I?[t.x,t.y-P/2,0]:[t.x-P/2,t.y,0],radius:Y,height:_}),W=(0,$s.cylinder)({center:I?[t.x,t.y+P/2,0]:[t.x+P/2,t.y,0],radius:Y,height:_});return(0,Xr.union)(T,O,W)})(C,l,h),f=(0,$s.cuboid)({center:[t.x,t.y,0],size:I?[B-2*wo,E,o]:[E,B-2*wo,o]}),m=(0,$s.cylinder)({center:I?[t.x,t.y-E/2,0]:[t.x-E/2,t.y,0],radius:Q-wo,height:o}),b=(0,$s.cylinder)({center:I?[t.x,t.y+E/2,0]:[t.x+E/2,t.y,0],radius:Q-wo,height:o}),D=(0,Xr.union)(f,m,b),x=sF(g(d),i),F=g(D);return(0,Nm.colorize)(Go.copper,(0,Xr.subtract)(x,F))}if(t.shape==="pill_hole_with_rect_pad"){if(t.hole_shape&&t.hole_shape!=="pill"||t.pad_shape&&t.pad_shape!=="rect")throw new Error("Invalid hole_shape or pad_shape for pill_hole_with_rect_pad");const a=t.hole_offset_x||0,g=t.hole_offset_y||0,I=t.hole_height>t.hole_width,c=I?t.hole_height:t.hole_width,B=I?t.hole_width:t.hole_height,C=B/2,l=Math.abs(c-B),Q=t.rect_pad_width||c+.2,E=t.rect_pad_height||B+.2,h=kl(t),u=.03,d=(0,Xr.union)((0,$s.cuboid)({center:[t.x+a,t.y+g,0],size:I?[B+2*u,l+2*u,r]:[l+2*u,B+2*u,r]}),(0,$s.cylinder)({center:I?[t.x+a,t.y+g-l/2,0]:[t.x+a-l/2,t.y+g,0],radius:C+u,height:r}),(0,$s.cylinder)({center:I?[t.x+a,t.y+g+l/2,0]:[t.x+a+l/2,t.y+g,0],radius:C+u,height:r})),f=(0,Xr.union)((0,$s.cuboid)({center:[t.x+a,t.y+g,0],size:I?[B,l,o*1.1]:[l,B,o*1.1]}),(0,$s.cylinder)({center:I?[t.x+a,t.y+g-l/2,0]:[t.x+a-l/2,t.y+g,0],radius:C,height:o*1.1}),(0,$s.cylinder)({center:I?[t.x+a,t.y+g+l/2,0]:[t.x+a+l/2,t.y+g,0],radius:C,height:o*1.1})),m=a_({width:Q,height:E,thickness:o0,center:[t.x,t.y,n],borderRadius:h}),b=a_({width:Q,height:E,thickness:o0,center:[t.x,t.y,s],borderRadius:h}),D=(()=>{const P=Math.max(r-o0*2,wo),W=(n+s)/2,AA=(0,$s.roundedRectangle)({size:[Q,E],roundRadius:h||0,segments:y5}),oA=(0,CL.extrudeLinear)({height:P},AA);return(0,xd.translate)([t.x,t.y,W-P/2],oA)})(),x=(0,Xr.subtract)(m,f),F=(0,Xr.subtract)(b,f),k=(0,Xr.subtract)(D,f),v=(0,Xr.union)((0,$s.cuboid)({center:[t.x+a,t.y+g,0],size:I?[B-2*wo,l-2*wo,o*1.1]:[l-2*wo,B-2*wo,o*1.1]}),(0,$s.cylinder)({center:I?[t.x+a,t.y+g-l/2,0]:[t.x+a-l/2,t.y+g,0],radius:C-wo,height:o*1.1}),(0,$s.cylinder)({center:I?[t.x+a,t.y+g+l/2,0]:[t.x+a+l/2,t.y+g,0],radius:C-wo,height:o*1.1})),_=(0,Xr.subtract)(d,v),Y=sF((0,Xr.union)(x,F,k,_),i);return(0,Nm.colorize)(Go.copper,Y)}else if(t.shape==="rotated_pill_hole_with_rect_pad"){if(t.hole_shape&&t.hole_shape!=="rotated_pill"||t.pad_shape&&t.pad_shape!=="rect")throw new Error("Invalid hole_shape or pad_shape for rotated_pill_hole_with_rect_pad");const a=t.hole_offset_x||0,g=t.hole_offset_y||0,I=t.hole_width,c=t.hole_height,B=I>=c,C=B?I:c,l=B?c:I,Q=l/2,E=Math.abs(C-l),h=t.rect_pad_width||I+.2,u=t.rect_pad_height||c+.2,d=kl(t),f=.03,m=(t.hole_ccw_rotation||0)*Math.PI/180,b=(t.rect_ccw_rotation||0)*Math.PI/180,D=IA=>{const tA=a*Math.cos(m)-g*Math.sin(m),sA=a*Math.sin(m)+g*Math.cos(m),aA=(0,xd.rotate)([0,0,m],IA);return(0,xd.translate)([t.x+tA,t.y+sA,0],aA)},x=IA=>{if(!b)return IA;const tA=(0,xd.translate)([-t.x,-t.y,0],IA),sA=(0,xd.rotate)([0,0,b],tA);return(0,xd.translate)([t.x,t.y,0],sA)},F=D((0,Xr.union)((0,$s.cuboid)({center:[0,0,0],size:B?[E+2*f,l+2*f,r]:[l+2*f,E+2*f,r]}),(0,$s.cylinder)({center:B?[-E/2,0,0]:[0,-E/2,0],radius:Q+f,height:r}),(0,$s.cylinder)({center:B?[E/2,0,0]:[0,E/2,0],radius:Q+f,height:r}))),k=D((0,Xr.union)((0,$s.cuboid)({center:[0,0,0],size:B?[E,l,o*1.1]:[l,E,o*1.1]}),(0,$s.cylinder)({center:B?[-E/2,0,0]:[0,-E/2,0],radius:Q,height:o*1.1}),(0,$s.cylinder)({center:B?[E/2,0,0]:[0,E/2,0],radius:Q,height:o*1.1}))),v=x(a_({width:h,height:u,thickness:o0,center:[t.x,t.y,n],borderRadius:d})),_=x(a_({width:h,height:u,thickness:o0,center:[t.x,t.y,s],borderRadius:d})),Y=x((()=>{const IA=Math.max(r-o0*2,wo),aA=(n+s)/2,dA=(0,$s.roundedRectangle)({size:[h,u],roundRadius:d||0,segments:y5}),SA=(0,CL.extrudeLinear)({height:IA},dA);return(0,xd.translate)([t.x,t.y,aA-IA/2],SA)})()),P=(0,Xr.subtract)(v,k),T=(0,Xr.subtract)(_,k),O=(0,Xr.subtract)(Y,k),W=D((0,Xr.union)((0,$s.cuboid)({center:[0,0,0],size:B?[E-2*wo,l-2*wo,o*1.1]:[l-2*wo,E-2*wo,o*1.1]}),(0,$s.cylinder)({center:B?[-E/2,0,0]:[0,-E/2,0],radius:Q-wo,height:o*1.1}),(0,$s.cylinder)({center:B?[E/2,0,0]:[0,E/2,0],radius:Q-wo,height:o*1.1}))),AA=(0,Xr.subtract)(F,W),oA=sF((0,Xr.union)(P,T,O,AA),i);return(0,Nm.colorize)(Go.copper,oA)}else if(t.shape==="hole_with_polygon_pad"){const a=t.pad_outline;if(!Array.isArray(a)||a.length<3)throw new Error(`Invalid pad_outline for plated hole at (${t.x}, ${t.y})`);const g=a.map(f=>[f.x,f.y]),I=(0,$s.polygon)({points:g}),c=(n+s)/2,B=(f,m)=>{const b=Math.max(f,wo),D=(0,CL.extrudeLinear)({height:b},I);return(0,xd.translate)([t.x,t.y,m-b/2],D)},C=B(Math.max(r-o0*2,wo),c),l=B(o0,n),Q=B(o0,s),E=sF((0,Xr.union)(C,l,Q),i),h=f5(t,r);if(!h)return(0,Nm.colorize)(Go.copper,E);const u=f5(t,o,{sizeDelta:-2*wo})||h;let d=(0,Xr.union)((0,Xr.subtract)(E,h),h);return e.clipGeom?(d=(0,Xr.subtract)(d,u),d=(0,Xr.intersect)(d,e.clipGeom),(0,Nm.colorize)(Go.copper,d)):(0,Nm.colorize)(Go.copper,(0,Xr.subtract)(d,u))}else throw new Error(`Unsupported plated hole shape: ${t.shape}`)},g_=_r(jU()),PZA=_r(xx()),fut=_r(ON());function yut(t,A,e,i){if(!e||Math.abs(e)<1e-9)return[];const o=4*Math.atan(e),n=A[0]-t[0],s=A[1]-t[1],r=Math.sqrt(n*n+s*s);if(r<1e-9)return[];const a=Math.abs(r/(2*Math.sin(o/2))),g=Math.sqrt(Math.max(0,a*a-r/2*(r/2))),I=[(t[0]+A[0])/2,(t[1]+A[1])/2],c=n/r,C=-(s/r),l=c,Q=I[0]+C*g*Math.sign(e),E=I[1]+l*g*Math.sign(e),h=Math.atan2(t[1]-E,t[0]-Q),u=[],d=Math.max(2,Math.ceil(i*Math.abs(o)/(Math.PI*2)*4)),f=o/d;for(let m=1;m<d;m++){const b=h+f*m;u.push([Q+a*Math.cos(b),E+a*Math.sin(b)])}return u}function w5(t,A){const e=[],i=t.vertices;for(let o=0;o<i.length;o++){const n=i[o],s=i[(o+1)%i.length];if(e.push([n.x,n.y]),n.bulge){const r=yut([n.x,n.y],[s.x,s.y],n.bulge,A);e.push(...r)}}return e}function OZA(t){let A=0;for(let e=0;e<t.length;e++){const i=(e+1)%t.length;A+=t[e][0]*t[i][1],A-=t[i][0]*t[e][1]}return A/2<=0}function wut(t,A=16){let e=w5(t.outer_ring,A);OZA(e)&&e.reverse();const i=(0,PZA.polygon)({points:e});if(!t.inner_rings||t.inner_rings.length===0)return i;const o=t.inner_rings.map(n=>{let s=w5(n,A);return OZA(s)&&s.reverse(),(0,PZA.polygon)({points:s})});return o.length===0?i:(0,fut.subtract)(i,o)}var WZA=_r(ON()),mut=_r(iF()),QL=_r(xx());function Dut({x:t,y:A,outerDiameter:e,holeDiameter:i,thickness:o}){if(e<=i)throw new Error(`Invalid via geometry: outerDiameter (${e}) must be > holeDiameter (${i})`);const n=wo,s=wo,r=Math.min(e/2,i/2+s),a=(0,QL.cylinder)({center:[0,0,0],radius:r,height:o,segments:KC}),g=(0,QL.cylinder)({center:[0,0,o/2],radius:e/2,height:n,segments:KC}),I=(0,QL.cylinder)({center:[0,0,-o/2],radius:e/2,height:n,segments:KC}),c=(0,WZA.union)([a,g,I]),B=o+n*2,C=(0,QL.cylinder)({center:[0,0,0],radius:i/2,height:B,segments:KC}),l=(0,WZA.subtract)(c,C);return(0,mut.translate)([t,A,0],l)}function Sut({x:t,y:A,holeDiameter:e,thickness:i}){const o=i*1.5,n=e/2+wo;return(0,QL.cylinder)({center:[t,A,0],radius:n,height:o,segments:KC})}var ZZA=64,but=1,FCA=.05,VZA=(t,A,e,i)=>{const o=i0(t,A,i);if(o<=0)return(0,va.cuboid)({center:[0,0,0],size:[t,A,e]});const n=(0,va.roundedRectangle)({size:[t,A],roundRadius:o,segments:ZZA}),s=(0,g_.extrudeLinear)({height:e},n);return(0,XB.translate)([0,0,-e/2],s)},jZA=["initializing","processing_pads","processing_copper_pours","processing_plated_holes","processing_holes","processing_cutouts","processing_vias","finalizing","done"],xut=class{circuitJson;board;plated_holes;holes;pads;traces;pcb_vias;pcb_cutouts;pcb_copper_pours;boardGeom=null;platedHoleGeoms=[];padGeoms=[];viaGeoms=[];copperPourGeoms=[];boardClipGeom=null;state="initializing";currentIndex=0;ctx;onCompleteCallback;finalGeoms=[];getHoleToCut(t,A){const e=wo/10;for(const i of this.pcb_vias)if(Math.abs(i.x-t)<e&&Math.abs(i.y-A)<e&&i.hole_diameter)return{diameter:i.hole_diameter};for(const i of this.plated_holes)if(i.shape==="circle"&&Math.abs(i.x-t)<e&&Math.abs(i.y-A)<e&&i.hole_diameter)return{diameter:i.hole_diameter};return null}constructor(t,A){this.circuitJson=t,this.onCompleteCallback=A;const e=t.filter(o=>o.type==="pcb_panel"),i=mi(t).pcb_board.list();if(e.length>0){const o=e[0],n=i.find(s=>s.pcb_panel_id===o.pcb_panel_id);this.board={type:"pcb_board",pcb_board_id:o.pcb_panel_id,center:o.center,width:o.width,height:o.height,thickness:n?.thickness??1.4,material:n?.material??"fr4",num_layers:n?.num_layers??2}}else{const o=i.filter(n=>!n.pcb_panel_id);this.board=o[0]}this.plated_holes=mi(t).pcb_plated_hole.list(),this.holes=mi(t).pcb_hole.list(),this.pads=mi(t).pcb_smtpad.list(),this.traces=mi(t).pcb_trace.list(),this.pcb_vias=mi(t).pcb_via.list(),this.pcb_cutouts=mi(t).pcb_cutout.list(),this.pcb_copper_pours=t.filter(o=>o.type==="pcb_copper_pour"),this.ctx={pcbThickness:this.board.thickness??1.2},this.initializeBoard()}initializeBoard(){const t=this.ctx.pcbThickness+2*but;this.board.outline&&this.board.outline.length>0?(this.boardGeom=GCA({outline:this.board.outline},this.ctx.pcbThickness),this.boardClipGeom=GCA({outline:this.board.outline},t,{xyOutset:FCA})):(this.boardGeom=(0,va.cuboid)({size:[this.board.width,this.board.height,this.ctx.pcbThickness],center:[this.board.center.x,this.board.center.y,0]}),this.boardClipGeom=(0,va.cuboid)({size:[this.board.width+2*FCA,this.board.height+2*FCA,t],center:[this.board.center.x,this.board.center.y,0]})),this.state="processing_pads",this.currentIndex=0}goToNextState(){const t=jZA.indexOf(this.state);t!==-1&&(this.state=jZA[t+1],this.currentIndex=0)}step(t=1){if(this.state==="done"||!this.boardGeom)return!0;for(let A=0;A<t&&this.state!=="done";A++)switch(this.state){case"processing_plated_holes":this.currentIndex<this.plated_holes.length?(this.processPlatedHole(this.plated_holes[this.currentIndex]),this.currentIndex++):this.goToNextState();break;case"processing_holes":this.currentIndex<this.holes.length?(this.processHole(this.holes[this.currentIndex]),this.currentIndex++):this.goToNextState();break;case"processing_pads":this.currentIndex<this.pads.length?(this.processPad(this.pads[this.currentIndex]),this.currentIndex++):this.goToNextState();break;case"processing_vias":this.currentIndex<this.pcb_vias.length?(this.processVia(this.pcb_vias[this.currentIndex]),this.currentIndex++):this.goToNextState();break;case"processing_cutouts":this.currentIndex<this.pcb_cutouts.length?(this.processCutout(this.pcb_cutouts[this.currentIndex]),this.currentIndex++):this.goToNextState();break;case"processing_copper_pours":this.currentIndex<this.pcb_copper_pours.length?(this.processCopperPour(this.pcb_copper_pours[this.currentIndex]),this.currentIndex++):this.goToNextState();break;case"finalizing":this.finalize(),this.state="done";break}return this.state==="done"}processCutout(t){if(!this.boardGeom)return;let A=null;const e=this.ctx.pcbThickness*1.5;switch(t.shape){case"rect":{const i=i0(t.width,t.height,kl(t));if(i>0){const o=(0,va.roundedRectangle)({size:[t.width,t.height],roundRadius:i,segments:ZZA});A=(0,g_.extrudeLinear)({height:e},o),A=(0,XB.translate)([0,0,-e/2],A)}else A=(0,va.cuboid)({center:[0,0,0],size:[t.width,t.height,e]});if(t.rotation){const o=t.rotation*Math.PI/180;A=(0,XB.rotateZ)(o,A)}A=(0,XB.translate)([t.center.x,t.center.y,0],A);break}case"circle":A=(0,va.cylinder)({center:[t.center.x,t.center.y,0],radius:t.radius,height:e});break;case"polygon":{let i=t.points.map(n=>[n.x,n.y]);if(i.length<3){console.warn(`PCB Cutout [${t.pcb_cutout_id}] polygon has fewer than 3 points, skipping.`);break}kCA(i)&&(i=i.reverse());const o=(0,va.polygon)({points:i});A=(0,g_.extrudeLinear)({height:e},o),A=(0,XB.translate)([0,0,-e/2],A);break}}A&&(this.boardGeom=(0,Ag.subtract)(this.boardGeom,A))}processCopperPour(t){const A=t.layer==="bottom"?-1:1,e=A*this.ctx.pcbThickness/2+A*$a.copper;let i=null;if(t.shape==="rect"){let o=(0,va.cuboid)({center:[0,0,0],size:[t.width,t.height,wo]});if("rotation"in t&&t.rotation){const n=t.rotation*Math.PI/180;o=(0,XB.rotateZ)(n,o)}i=(0,XB.translate)([t.center.x,t.center.y,e],o)}else if(t.shape==="brep"){const o=t.brep_shape;if(o?.outer_ring){const n=wut(o);i=(0,g_.extrudeLinear)({height:wo},n),i=(0,XB.translate)([0,0,e],i)}}else if(t.shape==="polygon"){let o=t.points.map(s=>[s.x,s.y]);if(o.length<3){console.warn(`PCB Copper Pour [${t.pcb_copper_pour_id}] polygon has fewer than 3 points, skipping.`);return}kCA(o)&&(o=o.reverse());const n=(0,va.polygon)({points:o});i=(0,g_.extrudeLinear)({height:wo},n),i=(0,XB.translate)([0,0,e],i)}if(i){this.boardClipGeom&&(i=(0,Ag.intersect)(this.boardClipGeom,i));const n=t.covered_with_solder_mask!==!1?gut[this.board.material]??Go.fr4TracesWithoutMaskTan:Go.copper,s=(0,dh.colorize)(n,i);this.copperPourGeoms.push(s)}}processPlatedHole(t,A={}){if(this.boardGeom){if(t.shape==="circle"||t.shape==="circular_hole_with_rect_pad"){let e=null;if(t.shape==="circular_hole_with_rect_pad"){if(t.hole_shape&&t.hole_shape!=="circle"||t.pad_shape&&t.pad_shape!=="rect")return;e=(0,va.cylinder)({center:[t.x+(t.hole_offset_x||0),t.y+(t.hole_offset_y||0),0],radius:t.hole_diameter/2+wo,height:this.ctx.pcbThickness*1.5})}else e=(0,va.cylinder)({center:[t.x,t.y,0],radius:t.hole_diameter/2+wo,height:this.ctx.pcbThickness*1.5});A.dontCutBoard||(this.boardGeom=(0,Ag.subtract)(this.boardGeom,e)),this.padGeoms=this.padGeoms.map(o=>(0,dh.colorize)(Go.copper,(0,Ag.subtract)(o,e)));const i=lL(t,this.ctx,{clipGeom:this.boardClipGeom});this.platedHoleGeoms.push(i)}else if(t.shape==="pill"||t.shape==="oval"){const e=t.hole_height>t.hole_width,i=e?t.hole_height:t.hole_width,o=e?t.hole_width:t.hole_height,n=o/2,s=Math.abs(i-o);let r;if(r=(0,Ag.union)((0,va.cuboid)({center:[t.x,t.y,0],size:e?[o,s,this.ctx.pcbThickness*1.5]:[s,o,this.ctx.pcbThickness*1.5]}),(0,va.cylinder)({center:e?[t.x,t.y-s/2,0]:[t.x-s/2,t.y,0],radius:n,height:this.ctx.pcbThickness*1.5}),(0,va.cylinder)({center:e?[t.x,t.y+s/2,0]:[t.x+s/2,t.y,0],radius:n,height:this.ctx.pcbThickness*1.5})),t.ccw_rotation){const g=t.ccw_rotation*Math.PI/180;r=(0,XB.translate)([t.x,t.y,0],(0,XB.rotateZ)(g,(0,XB.translate)([-t.x,-t.y,0],r)))}A.dontCutBoard||(this.boardGeom=(0,Ag.subtract)(this.boardGeom,r)),this.padGeoms=this.padGeoms.map(g=>(0,dh.colorize)(Go.copper,(0,Ag.subtract)(g,r)));const a=lL(t,this.ctx,{clipGeom:this.boardClipGeom});this.platedHoleGeoms.push(a)}else if(t.shape==="pill_hole_with_rect_pad"){if(t.hole_shape&&t.hole_shape!=="pill"||t.pad_shape&&t.pad_shape!=="rect")return;const e=t.hole_height>t.hole_width,i=e?t.hole_height:t.hole_width,o=e?t.hole_width:t.hole_height,n=o/2,s=Math.abs(i-o);let r;r=(0,Ag.union)((0,va.cuboid)({center:[t.x+(t.hole_offset_x||0),t.y+(t.hole_offset_y||0),0],size:e?[o,s,this.ctx.pcbThickness*1.5]:[s,o,this.ctx.pcbThickness*1.5]}),(0,va.cylinder)({center:e?[t.x+(t.hole_offset_x||0),t.y+(t.hole_offset_y||0)-s/2,0]:[t.x+(t.hole_offset_x||0)-s/2,t.y+(t.hole_offset_y||0),0],radius:n,height:this.ctx.pcbThickness*1.5}),(0,va.cylinder)({center:e?[t.x+(t.hole_offset_x||0),t.y+(t.hole_offset_y||0)+s/2,0]:[t.x+(t.hole_offset_x||0)+s/2,t.y+(t.hole_offset_y||0),0],radius:n,height:this.ctx.pcbThickness*1.5})),A.dontCutBoard||(this.boardGeom=(0,Ag.subtract)(this.boardGeom,r)),this.padGeoms=this.padGeoms.map(g=>(0,dh.colorize)(Go.copper,(0,Ag.subtract)(g,r)));const a=lL(t,this.ctx,{clipGeom:this.boardClipGeom});this.platedHoleGeoms.push(a)}else if(t.shape==="rotated_pill_hole_with_rect_pad"){if(t.hole_shape&&t.hole_shape!=="rotated_pill"||t.pad_shape&&t.pad_shape!=="rect")return;const e=t.hole_width,i=t.hole_height,o=e>=i,n=o?e:i,s=o?i:e,r=s/2,a=Math.abs(n-s),g=t.hole_offset_x||0,I=t.hole_offset_y||0;let c=(0,Ag.union)((0,va.cuboid)({center:[0,0,0],size:o?[a,s,this.ctx.pcbThickness*1.5]:[s,a,this.ctx.pcbThickness*1.5]}),(0,va.cylinder)({center:o?[-a/2,0,0]:[0,-a/2,0],radius:r,height:this.ctx.pcbThickness*1.5}),(0,va.cylinder)({center:o?[a/2,0,0]:[0,a/2,0],radius:r,height:this.ctx.pcbThickness*1.5}));const B=(t.hole_ccw_rotation||0)*Math.PI/180,C=g*Math.cos(B)-I*Math.sin(B),l=g*Math.sin(B)+I*Math.cos(B);c=(0,XB.rotateZ)(B,c);const Q=(0,XB.translate)([t.x+C,t.y+l,0],c);A.dontCutBoard||(this.boardGeom=(0,Ag.subtract)(this.boardGeom,Q)),this.padGeoms=this.padGeoms.map(h=>(0,dh.colorize)(Go.copper,(0,Ag.subtract)(h,Q)));const E=lL(t,this.ctx,{clipGeom:this.boardClipGeom});this.platedHoleGeoms.push(E)}else if(t.shape==="hole_with_polygon_pad"){const e=t.pad_outline;if(!Array.isArray(e)||e.length<3)return;const i=this.ctx.pcbThickness*1.5,o=f5(t,i,{sizeDelta:2*wo}),n=f5(t,i,{sizeDelta:-2*wo});if(!o||!n)return;A.dontCutBoard||(this.boardGeom=(0,Ag.subtract)(this.boardGeom,o)),this.padGeoms=this.padGeoms.map(r=>(0,dh.colorize)(Go.copper,(0,Ag.subtract)(r,o))),this.platedHoleGeoms=this.platedHoleGeoms.map(r=>(0,dh.colorize)(Go.copper,(0,Ag.subtract)(r,n)));const s=lL(t,this.ctx,{clipGeom:this.boardClipGeom});this.platedHoleGeoms.push(s)}}}processHole(t){if(!this.boardGeom)return;const A=this.ctx.pcbThickness*1.5;if(t.hole_shape==="circle"){const e=(0,va.cylinder)({center:[t.x,t.y,0],radius:t.hole_diameter/2+wo,height:A});this.boardGeom=(0,Ag.subtract)(this.boardGeom,e),this.padGeoms=this.padGeoms.map(o=>(0,dh.colorize)(Go.copper,(0,Ag.subtract)(o,e)));const i=(0,va.cylinder)({center:[t.x,t.y,0],radius:t.hole_diameter/2+wo/2,height:A});this.platedHoleGeoms=this.platedHoleGeoms.map(o=>(0,dh.colorize)(Go.copper,(0,Ag.subtract)(o,i)))}else if(t.hole_shape==="pill"||t.hole_shape==="rotated_pill"||t.hole_shape==="oval"){const e=t.hole_width??t.hole_diameter,i=t.hole_height??t.hole_diameter,o=t.ccw_rotation??t.rotation??0,n=.02,s=(g,I,c,B)=>{if(g<=0||I<=0)return null;if(B)return(0,XB.translate)([0,0,-c/2],(0,g_.extrudeLinear)({height:c},(0,va.ellipse)({radius:[g/2,I/2]})));const C=Math.min(g,I)/2,l=Math.abs(g-I);return g>I?(0,Ag.union)((0,va.cuboid)({center:[0,0,0],size:[l,I,c]}),(0,va.cylinder)({center:[-l/2,0,0],radius:C,height:c}),(0,va.cylinder)({center:[l/2,0,0],radius:C,height:c})):(0,Ag.union)((0,va.cuboid)({center:[0,0,0],size:[g,l,c]}),(0,va.cylinder)({center:[0,-l/2,0],radius:C,height:c}),(0,va.cylinder)({center:[0,l/2,0],radius:C,height:c}))};let r=s(e,i,A,t.hole_shape==="oval"),a=s(e-2*n,i-2*n,A,t.hole_shape==="oval");if(r&&o!==0&&(r=(0,XB.rotateZ)(o*Math.PI/180,r)),a&&o!==0&&(a=(0,XB.rotateZ)(o*Math.PI/180,a)),r){const g=(0,XB.translate)([t.x,t.y,0],r);this.boardGeom=(0,Ag.subtract)(this.boardGeom,g),this.padGeoms=this.padGeoms.map(I=>(0,dh.colorize)(Go.copper,(0,Ag.subtract)(I,g)))}if(a){const g=(0,XB.translate)([t.x,t.y,0],a);this.platedHoleGeoms=this.platedHoleGeoms.map(I=>(0,dh.colorize)(Go.copper,(0,Ag.subtract)(I,g)))}}}processPad(t){const A=t.layer==="bottom"?-1:1,e=A*this.ctx.pcbThickness/2+A*$a.copper,i=kl(t);if(t.shape==="rect"){const o=VZA(t.width,t.height,wo,i);let s=(0,XB.translate)([t.x,t.y,e],o);this.boardClipGeom&&(s=(0,Ag.intersect)(this.boardClipGeom,s)),s=(0,dh.colorize)(Go.copper,s),this.padGeoms.push(s)}else if(t.shape==="rotated_rect"){let o=VZA(t.width,t.height,wo,i);const n=t.ccw_rotation*Math.PI/180;o=(0,XB.rotateZ)(n,o);let r=(0,XB.translate)([t.x,t.y,e],o);this.boardClipGeom&&(r=(0,Ag.intersect)(this.boardClipGeom,r)),r=(0,dh.colorize)(Go.copper,r),this.padGeoms.push(r)}else if(t.shape==="circle"){let o=(0,va.cylinder)({center:[t.x,t.y,e],radius:t.radius,height:wo});this.boardClipGeom&&(o=(0,Ag.intersect)(this.boardClipGeom,o)),o=(0,dh.colorize)(Go.copper,o),this.padGeoms.push(o)}}processVia(t){if(this.boardGeom){if(typeof t.outer_diameter=="number"&&typeof t.hole_diameter=="number"){const A=Dut({x:t.x,y:t.y,outerDiameter:t.outer_diameter,holeDiameter:t.hole_diameter,thickness:this.ctx.pcbThickness});let e=A;this.boardClipGeom&&(e=(0,Ag.intersect)(this.boardClipGeom,A),e=(0,dh.colorize)(Go.copper,e)),this.viaGeoms.push(e)}if(typeof t.hole_diameter=="number"){const A=Sut({x:t.x,y:t.y,holeDiameter:t.hole_diameter,thickness:this.ctx.pcbThickness});this.boardGeom=(0,Ag.subtract)(this.boardGeom,A),this.padGeoms=this.padGeoms.map(e=>(0,dh.colorize)(Go.copper,(0,Ag.subtract)(e,A)))}}}finalize(){if(!this.boardGeom)return;const t=xCA[this.board.material]??Go.fr4Tan;this.boardGeom=(0,dh.colorize)(t,this.boardGeom),this.finalGeoms=[this.boardGeom,...this.platedHoleGeoms,...this.padGeoms,...this.viaGeoms,...this.copperPourGeoms],this.onCompleteCallback&&this.onCompleteCallback(this.finalGeoms)}getGeoms(){return this.finalGeoms}},kut=t=>{const[A,e]=$.useState(null),i=$.useRef(!1);return $.useEffect(()=>{let o=!1;if(!t){e(null);return}if(!t.some(g=>g.type==="pcb_board"||g.type==="pcb_panel")){e(null);return}const s=lut(t);e(s);const r=new xut(t,g=>{});return(async()=>{if(!i.current){i.current=!0;try{let g=!1;for(;!g&&!o;)g=r.step(1),g||await new Promise(I=>setTimeout(I,0));o||e(r.getGeoms())}catch(g){console.error("Error during board geometry building:",g)}finally{i.current=!1}}})(),()=>{o=!0}},[t]),A},Gut=({children:t,parent:A,position:e,rotation:i,scale:o,color:n,fontSize:s,anchorX:r,anchorY:a,depthOffset:g})=>{const{rootObject:I}=ku(),c=$.useMemo(()=>{const B=new d6;return B.text=t,e&&B.position.fromArray(e),i&&B.rotation.fromArray(i),o&&B.scale.fromArray(o),B.color=n||"white",B.fontSize=s||1,B.anchorX=r||"center",B.anchorY=a||"middle",B.depthOffset=g||0,B.font=null,B.sync(),B},[t,e,i,o,n,s,r,a,g]);return $.useEffect(()=>{const B=A||I;if(!(!B||!c))return B.add(c),()=>{B.remove(c),c.dispose()}},[I,A,c]),null},zZA=({error:t,cad_component:A})=>{const{rootObject:e}=ku(),[i,o]=$.useState(!1),[n,s]=$.useState(null),r=$.useCallback(c=>{c?.mousePosition?(o(!0),s(c.mousePosition)):(o(!1),s(null))},[]),a=$.useCallback(()=>{o(!1),s(null)},[]),g=$.useMemo(()=>A?.position?[A.position.x,A.position.y,A.position.z].map(B=>Number.isNaN(B)?0:B):[0,0,0],[A]),I=$.useMemo(()=>{const c=new Jp;return c.position.fromArray(g),c},[g]);return $.useEffect(()=>{if(e)return e.add(I),()=>{e.remove(I)}},[e,I]),V.jsxs(V.Fragment,{children:[V.jsxs(cL,{isHovered:i,onHover:r,onUnhover:a,object:I,children:[V.jsx(Fut,{parent:I}),V.jsx(Gut,{parent:I,scale:[.1,.1,.1],color:"red",anchorX:"center",anchorY:"middle",depthOffset:-99999,children:`${t.toString().slice(0,50)}...`})]}),i&&n?V.jsx(IWA,{position:n,style:{fontFamily:"sans-serif",transform:"translate3d(-1rem, 0rem, 0)",backgroundColor:"white",padding:"6px",borderRadius:"4px",color:"red",pointerEvents:"none",userSelect:"none",WebkitUserSelect:"none",MozUserSelect:"none",msUserSelect:"none"},children:t.toString()}):null]})},Fut=({parent:t})=>{const A=$.useMemo(()=>{const e=new Wo(new Bw(.5,.5,.5),new Ih({depthTest:!1,transparent:!0,color:"red",opacity:.5}));return e.renderOrder=999999,e.rotation.fromArray([Math.PI/4,Math.PI/4,0]),e},[]);return $.useEffect(()=>(t.add(A),()=>{t.remove(A)}),[t,A]),null};function Rut({stlUrl:t,stlData:A,mtlUrl:e,color:i,opacity:o=1}){const{rootObject:n}=ku(),[s,r]=$.useState(null);$.useEffect(()=>{const g=new mbe;if(A){try{const I=g.parse(A);r(I)}catch(I){console.error("Failed to parse STL data",I),r(null)}return}t&&g.load(t,I=>{r(I)})},[t,A]);const a=$.useMemo(()=>{if(!s)return null;const g=new Ih({color:Array.isArray(i)?new Li(i[0],i[1],i[2]):i,transparent:o!==1,opacity:o});return new Wo(s,g)},[s,i,o]);return $.useEffect(()=>{if(!(!n||!a))return n.add(a),()=>{n.remove(a),a.geometry.dispose(),Array.isArray(a.material)?a.material.forEach(g=>g.dispose()):a.material.dispose()}},[n,a]),null}function Mut({stlData:t,color:A,opacity:e=1,layerType:i}){const{visibility:o}=WN();let n=!0;return i==="board"?n=o.boardBody:i==="top-copper"?n=o.topCopper:i==="bottom-copper"?n=o.bottomCopper:i==="top-silkscreen"?n=o.topSilkscreen:i==="bottom-silkscreen"&&(n=o.bottomSilkscreen),n?V.jsx(Rut,{stlData:t,color:A,opacity:e}):null}var XZA=class extends Xi.Component{constructor(t){super(t),this.state={hasError:!1,error:null}}static getDerivedStateFromError(t){return{hasError:!0,error:t}}render(){return this.state.hasError&&this.state.error?this.props.fallback({error:this.state.error}):this.props.children}},Nut=t=>{if(t.length===0)return null;let A=t[0].x,e=t[0].y,i=t[0].x,o=t[0].y;for(let n=1;n<t.length;n++){const s=t[n];s.x<A&&(A=s.x),s.y<e&&(e=s.y),s.x>i&&(i=s.x),s.y>o&&(o=s.y)}return{minX:A,minY:e,maxX:i,maxY:o}};function rF(t){if(t.outline&&t.outline.length>=3){const s=Nut(t.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=t.width??0,e=t.height??0,i=t.center?.x??0,o=t.center?.y??0;return{...{minX:i-A/2,maxX:i+A/2,minY:o-e/2,maxY:o+e/2},width:A,height:e,centerX:i,centerY:o}}function m5({layer:t,circuitJson:A,boardData:e,soldermaskColor:i,traceTextureResolution:o}){const n=rF(e),s=document.createElement("canvas"),r=Math.floor(n.width*o),a=Math.floor(n.height*o);s.width=r,s.height=a;const g=s.getContext("2d");if(!g)return null;t==="bottom"&&(g.translate(0,a),g.scale(1,-1));const I=f=>(f-n.minX)*o,c=f=>(n.maxY-f)*o;if(g.fillStyle=i,e.outline&&e.outline.length>=3){g.beginPath();const f=e.outline[0];g.moveTo(I(f.x),c(f.y));for(let m=1;m<e.outline.length;m++){const b=e.outline[m];g.lineTo(I(b.x),c(b.y))}g.closePath(),g.fill()}else g.fillRect(0,0,r,a);g.globalCompositeOperation="destination-out",g.fillStyle="black",mi(A).pcb_smtpad.list().filter(f=>f.layer===t).forEach(f=>{if(f.shape==="polygon"&&f.points){g.beginPath(),f.points.forEach((F,k)=>{const v=I(F.x),_=c(F.y);k===0?g.moveTo(v,_):g.lineTo(v,_)}),g.closePath(),g.fill();return}if(f.x===void 0||f.y===void 0)return;if(Number.isNaN(f.x)||Number.isNaN(f.y)){console.warn(`[soldermask-texture] Skipping pad ${f.pcb_smtpad_id} with NaN coordinates`);return}const m=f.x,b=f.y,D=I(m),x=c(b);if(f.shape==="rect"){const F=f.width*o,k=f.height*o,v=kl(f),_=i0(f.width,f.height,v)*o;_>0?(g.beginPath(),g.roundRect(D-F/2,x-k/2,F,k,_),g.fill()):g.fillRect(D-F/2,x-k/2,F,k)}else if(f.shape==="circle"){const F=(f.radius??f.width/2)*o;g.beginPath(),g.arc(D,x,F,0,2*Math.PI),g.fill()}else if(f.shape==="pill"){const F=f.width*o,k=f.height*o,v=kl(f),_=i0(f.width,f.height,v)*o;g.beginPath(),g.roundRect(D-F/2,x-k/2,F,k,_),g.fill()}else if(f.shape==="rotated_rect"){const F=f.width*o,k=f.height*o,v=kl(f),_=i0(f.width,f.height,v)*o,P=-(f.ccw_rotation||0)*(Math.PI/180);g.save(),g.translate(D,x),g.rotate(P),g.beginPath(),g.roundRect(-F/2,-k/2,F,k,_),g.fill(),g.restore()}}),mi(A).pcb_via.list().forEach(f=>{const m=I(f.x),b=c(f.y),D=f.outer_diameter/2*o;g.beginPath(),g.arc(m,b,D,0,2*Math.PI),g.fill()}),mi(A).pcb_plated_hole.list().forEach(f=>{if(!f.layers?.includes(t))return;const m=f.x,b=f.y,D=I(m),x=c(b);if(f.shape==="circle"){const k=f.outer_diameter/2*o;g.beginPath(),g.arc(D,x,k,0,2*Math.PI),g.fill()}else if(f.shape==="pill"){const F=(f.outer_width??f.outer_diameter??f.hole_width)*o,k=(f.outer_height??f.outer_diameter??f.hole_height)*o,v=Math.min(F,k)/2,Y=-(f.ccw_rotation||0);Y?(g.save(),g.translate(D,x),g.rotate(Y*Math.PI/180),g.beginPath(),g.roundRect(-F/2,-k/2,F,k,v),g.fill(),g.restore()):(g.beginPath(),g.roundRect(D-F/2,x-k/2,F,k,v),g.fill())}else if(f.shape==="oval"){const F=(f.outer_width??f.outer_diameter??f.hole_width)*o,k=(f.outer_height??f.outer_diameter??f.hole_height)*o,v=F/2,_=k/2,P=-(f.ccw_rotation||0);P?(g.save(),g.translate(D,x),g.rotate(P*Math.PI/180),g.beginPath(),g.ellipse(0,0,v,_,0,0,2*Math.PI),g.fill(),g.restore()):(g.beginPath(),g.ellipse(D,x,v,_,0,0,2*Math.PI),g.fill())}else if(f.shape==="hole_with_polygon_pad"){const F=f.hole_shape||"circle",k=f.hole_offset_x||0,v=f.hole_offset_y||0,_=I(f.x+k),Y=c(f.y+v);if(F==="pill"||F==="rotated_pill"){const P=(f.outer_width??f.outer_diameter??f.hole_width)*o,T=(f.outer_height??f.outer_diameter??f.hole_height)*o,O=Math.min(P,T)/2,AA=-(f.ccw_rotation||0);AA?(g.save(),g.translate(_,Y),g.rotate(AA*Math.PI/180),g.beginPath(),g.roundRect(-P/2,-T/2,P,T,O),g.fill(),g.restore()):(g.beginPath(),g.roundRect(_-P/2,Y-T/2,P,T,O),g.fill())}else if(F==="oval"){const P=(f.outer_width??f.outer_diameter??f.hole_width)*o,T=(f.outer_height??f.outer_diameter??f.hole_height)*o,O=P/2,W=T/2,oA=-(f.ccw_rotation||0);oA?(g.save(),g.translate(_,Y),g.rotate(oA*Math.PI/180),g.beginPath(),g.ellipse(0,0,O,W,0,0,2*Math.PI),g.fill(),g.restore()):(g.beginPath(),g.ellipse(_,Y,O,W,0,0,2*Math.PI),g.fill())}else if(F==="circle"){const T=(f.outer_diameter??f.hole_diameter??0)*o/2;g.beginPath(),g.arc(_,Y,T,0,2*Math.PI),g.fill()}f.pad_outline&&f.pad_outline.length>=3&&(g.beginPath(),f.pad_outline.forEach((P,T)=>{const O=I(f.x+P.x),W=c(f.y+P.y);T===0?g.moveTo(O,W):g.lineTo(O,W)}),g.closePath(),g.fill())}else if(f.shape==="circular_hole_with_rect_pad"){const F=(f.rect_pad_width??f.hole_diameter??0)*o,k=(f.rect_pad_height??f.hole_diameter??0)*o,v=kl(f),_=i0(f.rect_pad_width??f.hole_diameter??0,f.rect_pad_height??f.hole_diameter??0,v)*o;_>0?(g.beginPath(),g.roundRect(D-F/2,x-k/2,F,k,_),g.fill()):g.fillRect(D-F/2,x-k/2,F,k)}else if(f.shape==="pill_hole_with_rect_pad"){const F=(f.rect_pad_width??f.hole_width??0)*o,k=(f.rect_pad_height??f.hole_height??0)*o,v=kl(f),_=i0(f.rect_pad_width??f.hole_width??0,f.rect_pad_height??f.hole_height??0,v)*o,P=-(f.ccw_rotation||0);P?(g.save(),g.translate(D,x),g.rotate(P*Math.PI/180),g.beginPath(),g.roundRect(-F/2,-k/2,F,k,_),g.fill(),g.restore()):(g.beginPath(),g.roundRect(D-F/2,x-k/2,F,k,_),g.fill())}else if(f.shape==="rotated_pill_hole_with_rect_pad"){const F=(f.rect_pad_width??f.hole_width??0)*o,k=(f.rect_pad_height??f.hole_height??0)*o,v=kl(f),_=i0(f.rect_pad_width??f.hole_width??0,f.rect_pad_height??f.hole_height??0,v)*o,P=-(f.rect_ccw_rotation||0);P?(g.save(),g.translate(D,x),g.rotate(P*Math.PI/180),g.beginPath(),g.roundRect(-F/2,-k/2,F,k,_),g.fill(),g.restore()):(g.beginPath(),g.roundRect(D-F/2,x-k/2,F,k,_),g.fill())}}),mi(A).pcb_hole.list().forEach(f=>{const m=f.x,b=f.y,D=I(m),x=c(b),F=f.hole_shape;if(F==="circle"&&typeof f.hole_diameter=="number"){const k=f.hole_diameter/2*o;g.beginPath(),g.arc(D,x,k,0,2*Math.PI),g.fill()}else if(F==="pill"&&typeof f.hole_width=="number"&&typeof f.hole_height=="number"){const k=f.hole_width*o,v=f.hole_height*o,_=Math.min(k,v)/2;g.beginPath(),g.roundRect(D-k/2,x-v/2,k,v,_),g.fill()}else if(F==="rotated_pill"&&typeof f.hole_width=="number"&&typeof f.hole_height=="number"){const k=f.hole_width*o,v=f.hole_height*o,_=Math.min(k,v)/2,P=-(f.ccw_rotation||0)*(Math.PI/180);P?(g.save(),g.translate(D,x),g.rotate(P),g.beginPath(),g.roundRect(-k/2,-v/2,k,v,_),g.fill(),g.restore()):(g.beginPath(),g.roundRect(D-k/2,x-v/2,k,v,_),g.fill())}else if(F==="oval"&&typeof f.hole_width=="number"&&typeof f.hole_height=="number"){const k=f.hole_width*o,v=f.hole_height*o,_=k/2,Y=v/2;g.beginPath(),g.ellipse(D,x,_,Y,0,0,2*Math.PI),g.fill()}}),mi(A).pcb_copper_pour.list().forEach(f=>{if(f.layer===t&&f.covered_with_solder_mask===!1)if(f.shape==="rect"){const m=I(f.center.x),b=c(f.center.y),D=f.width*o,x=f.height*o;g.fillRect(m-D/2,b-x/2,D,x)}else f.shape==="polygon"&&f.points&&(g.beginPath(),f.points.forEach((m,b)=>{const D=I(m.x),x=c(m.y);b===0?g.moveTo(D,x):g.lineTo(D,x)}),g.closePath(),g.fill())}),mi(A).pcb_cutout.list().forEach(f=>{switch(f.shape){case"rect":{const m=I(f.center.x),b=c(f.center.y),D=f.width*o,x=f.height*o,F=kl(f),k=i0(f.width,f.height,F);if(f.rotation){g.save(),g.translate(m,b);const v=-f.rotation*(Math.PI/180);g.rotate(v),k>0?(g.beginPath(),g.roundRect(-D/2,-x/2,D,x,k*o),g.fill()):g.fillRect(-D/2,-x/2,D,x),g.restore()}else k>0?(g.beginPath(),g.roundRect(m-D/2,b-x/2,D,x,k*o),g.fill()):g.fillRect(m-D/2,b-x/2,D,x);break}case"circle":{const m=I(f.center.x),b=c(f.center.y),D=f.radius*o;g.beginPath(),g.arc(m,b,D,0,2*Math.PI),g.fill();break}case"polygon":{if(!f.points||f.points.length<3){console.warn(`PCB Cutout [${f.pcb_cutout_id}] polygon has fewer than 3 points, skipping in soldermask texture.`);break}g.beginPath(),f.points.forEach((m,b)=>{const D=I(m.x),x=c(m.y);b===0?g.moveTo(D,x):g.lineTo(D,x)}),g.closePath(),g.fill();break}default:console.warn(`Unsupported cutout shape: ${f.shape} for cutout ${f.pcb_cutout_id} in soldermask texture.`)}}),g.globalCompositeOperation="source-over";const d=new uM(s);return d.generateMipmaps=!0,d.minFilter=fu,d.magFilter=ZB,d.anisotropy=16,d.needsUpdate=!0,d}var _ut=_r(UBA());function $ZA(t,A){return Array.isArray(A)?[t.a*A[0]+t.c*A[1]+t.e,t.b*A[0]+t.d*A[1]+t.f]:{x:t.a*A.x+t.c*A.y+t.e,y:t.b*A.x+t.d*A.y+t.f}}function Mx(t,A=0){return{a:1,c:0,e:t,b:0,d:1,f:A}}function AVA(...t){t=Array.isArray(t[0])?t[0]:t;const A=(e,i)=>({a:e.a*i.a+e.c*i.b,c:e.a*i.c+e.c*i.d,e:e.a*i.e+e.c*i.f+e.e,b:e.b*i.a+e.d*i.b,d:e.b*i.c+e.d*i.d,f:e.b*i.e+e.d*i.f+e.f});switch(t.length){case 0:throw new Error("no matrices provided");case 1:return t[0];case 2:return A(t[0],t[1]);default:{const[e,i,...o]=t,n=A(e,i);return AVA(n,...o)}}}function eVA(...t){return AVA(...t)}var{cos:vut,sin:Uut}=Math;function tVA(t,A,e){const i=vut(t),o=Uut(t);return{a:i,c:-o,e:0,b:o,d:i,f:0}}function Lut(t,A){function e(){this.constructor=t}e.prototype=A.prototype,t.prototype=new e}function D5(t,A,e,i){var o=Error.call(this,t);return Object.setPrototypeOf&&Object.setPrototypeOf(o,D5.prototype),o.expected=A,o.found=e,o.location=i,o.name="SyntaxError",o}Lut(D5,Error);function RCA(t,A,e){return e=e||" ",t.length>A?t:(A-=t.length,e+=e.repeat(A),t+e.slice(0,A))}D5.prototype.format=function(t){var A="Error: "+this.message;if(this.location){var e=null,i;for(i=0;i<t.length;i++)if(t[i].source===this.location.source){e=t[i].text.split(/\r\n|\n|\r/g);break}var o=this.location.start,n=this.location.source&&typeof this.location.source.offset=="function"?this.location.source.offset(o):o,s=this.location.source+":"+n.line+":"+n.column;if(e){var r=this.location.end,a=RCA("",n.line.toString().length," "),g=e[o.line-1],I=o.line===r.line?r.column:g.length+1,c=I-o.column||1;A+=`
|
|
5101
|
+
`,Xht=({rotation:t,infiniteGrid:A,cellSize:e=1,sectionSize:i=10})=>{const{scene:o,camera:n}=ku(),s=1e3,r=$.useMemo(()=>{const a=new Cw(s,s);a.rotateX(-Math.PI/2);const g=new nm({vertexShader:jht,fragmentShader:zht,uniforms:{cellSize:{value:e},sectionSize:{value:i},gridColor:{value:new Li(15658734)},sectionColor:{value:new Li(13421823)},fadeDistance:{value:100},fadeStrength:{value:1.5}},transparent:!0,side:JC}),I=new Wo(a,g);return t&&I.rotation.fromArray(t),I},[s,e,i,t]);return zU(()=>{A&&r.position.set(n.position.x,n.position.y,0)}),$.useEffect(()=>{if(!(!o||!r))return o.add(r),()=>{o.remove(r),r.geometry.dispose(),Array.isArray(r.material)?r.material.forEach(a=>a.dispose()):r.material.dispose()}},[o,r]),null},$ht=()=>{const{scene:t}=ku(),A=$.useMemo(()=>new CxA(16777215,Math.PI/2),[]),e=$.useMemo(()=>{const i=new eX(16777215,Math.PI/4);return i.position.set(-10,-10,10),i.decay=0,i},[]);return $.useEffect(()=>{if(t)return t.add(A),t.add(e),()=>{t.remove(A),t.remove(e)}},[t,A,e]),null},Aut=t=>t<.5?4*t*t*t:1-Math.pow(-2*t+2,3)/2,eut=()=>{const{controlsRef:t,mainCameraRef:A,defaultTarget:e,setController:i,getPresetConfig:o}=Fx(),n=$.useRef(null),s=$.useRef(new dd),r=$.useRef(new Me),a=$.useRef(new Me),g=$.useRef(new dd),I=$.useRef(new dd),c=$.useRef(new ug),B=$.useRef(new ug),C=$.useCallback(({position:Q,target:E,up:h,durationMs:u=600})=>{if(!A.current)return;const d=t.current?.target??e,f=new Me(Q[0],Q[1],Q[2]),m=E?new Me(E[0],E[1],E[2]):e.clone(),b=new Me(...h??[0,0,1]).normalize(),D=B.current;D.position.copy(f),D.up.copy(b),D.lookAt(m);const x=D.quaternion.clone(),F=A.current.quaternion.clone(),k=A.current.position.clone(),v=d.clone(),_=c.current;_.up.set(0,0,1),_.position.copy(k),_.lookAt(v);const Y=_.quaternion.clone();_.up.set(0,0,1),_.position.copy(f),_.lookAt(m);const P=_.quaternion.clone(),T=Y.clone().invert().multiply(F).normalize(),O=P.clone().invert().multiply(x).normalize();n.current={fromPosition:k,toPosition:f,fromTarget:v,toTarget:m,toQuaternion:x,rollFrom:T,rollTo:O,startTime:performance.now(),duration:u}},[A,t,e]),l=$.useCallback(Q=>{if(Q==="Custom")return;const E=o(Q);E&&C(E)},[C,o]);return $.useEffect(()=>A.current?(i({animateTo:C,animateToPreset:l}),()=>{i(null)}):void 0,[C,l,A,i]),zU(()=>{if(!A.current||!n.current)return;const{fromPosition:Q,toPosition:E,fromTarget:h,toTarget:u,toQuaternion:d,rollFrom:f,rollTo:m,startTime:b,duration:D}=n.current,x=performance.now()-b,F=D<=0?1:Math.min(x/D,1),k=Aut(F);A.current.position.lerpVectors(Q,E,k);const v=r.current;v.copy(h).lerp(u,k);const _=c.current;_.up.set(0,0,1),_.position.copy(A.current.position),_.lookAt(v);const Y=s.current;Y.copy(_.quaternion);const P=g.current;P.copy(f);const T=I.current;T.copy(m),f.dot(m)<0&&(T.x*=-1,T.y*=-1,T.z*=-1,T.w*=-1),T.normalize(),P.slerp(T,k),A.current.quaternion.copy(Y).multiply(P).normalize();const O=a.current;O.set(0,1,0).applyQuaternion(A.current.quaternion).normalize(),A.current.up.copy(O),t.current?.target.copy(v),A.current.updateMatrixWorld(),t.current?.update(),F>=1&&(A.current.position.copy(E),A.current.quaternion.copy(d),A.current.up.set(0,0,1),A.current.updateMatrixWorld(),t.current?.target.copy(u),t.current?.update(),n.current=null)}),null},tut=()=>{const{controlsRef:t}=Fx(),A=$.useRef(null),e=$.useRef(!1),i=$.useRef(null),o=$.useCallback(s=>{A.current=s,!e.current&&t.current&&bCA(s,t.current)&&(e.current=!0)},[t]),n=$.useCallback(()=>{if(!(!A.current||!t.current)){if(!e.current&&bCA(A.current,t.current)){e.current=!0;return}clearTimeout(i.current),i.current=setTimeout(()=>{A.current&&t.current&&HZA(A.current,t.current)},150)}},[t]);return{handleCameraCreated:o,handleControlsChange:n}};function iut(t,A){const e=new dd().setFromEuler(new Hp(t.x,t.y,t.z)),i=new Me(0,0,1);return i.applyQuaternion(e),i.multiplyScalar(A)}var out=()=>{const{mainCameraRef:t}=Fx(),A=$.useRef(null),e=$.useRef(null),i=$.useRef(null),o=$.useRef(null),n=$.useRef(null),s=$.useRef(null);return $.useEffect(()=>{if(!A.current)return;const r=document.createElement("canvas");e.current=r,A.current.appendChild(r);const a=new nK({canvas:r,antialias:!0,alpha:!0});a.setSize(120,120),a.setPixelRatio(window.devicePixelRatio),i.current=a;const g=new lG;o.current=g;const I=new rE(75,1,.1,1e3);I.up.set(0,0,1),n.current=I;const c=new CxA(16777215,Math.PI/2);g.add(c);const B=new Jp;B.rotation.fromArray([Math.PI/2,0,0]);const C=1,l=new Wo(new Bw(C,C,C),new Ih({color:"white"}));B.add(l);const Q=new X1(new Kwe(new Bw(C,C,C)),new QG({color:0,linewidth:2}));B.add(Q),g.add(B);const E=.51,h=(F,k,v)=>{const _=new d6;return _.text=F,_.position.fromArray(k),v&&_.rotation.fromArray(v),_.color="black",_.fontSize=.25,_.anchorX="center",_.anchorY="middle",_.depthOffset=0,_.font=null,_.sync(),_},u=h("Front",[0,0,E]),d=h("Back",[0,0,-E],[0,Math.PI,0]),f=h("Right",[E,0,0],[0,Math.PI/2,0]),m=h("Left",[-E,0,0],[0,-Math.PI/2,0]),b=h("Top",[0,E,0],[-Math.PI/2,0,0]),D=h("Bottom",[0,-E,0],[Math.PI/2,0,0]);B.add(u),B.add(d),B.add(f),B.add(m),B.add(b),B.add(D);const x=()=>{if(t.current){const F=iut(t.current.rotation??new Hp(0,0,0),2);F.equals(I.position)||(I.position.copy(F),I.lookAt(0,0,0))}a.render(g,I),s.current=requestAnimationFrame(x)};return x(),()=>{s.current&&cancelAnimationFrame(s.current),u.dispose(),d.dispose(),f.dispose(),m.dispose(),b.dispose(),D.dispose(),l.geometry.dispose(),l.material.dispose(),Q.geometry.dispose(),Q.material.dispose(),g.clear(),a.dispose(),e.current&&A.current&&A.current.removeChild(e.current)}},[t]),V.jsx("div",{ref:A,style:{position:"absolute",top:0,left:0,width:120,height:120,zIndex:XU.orientationCube}})},nut=()=>{const{camera:t}=ku(),{setCameraRotation:A}=Fx();return zU(()=>{t&&A(t.rotation)}),null},JZA=$.forwardRef(({children:t,initialCameraPosition:A=[5,-5,5],autoRotateDisabled:e,clickToInteractEnabled:i=!1,boardDimensions:o,boardCenter:n,onUserInteraction:s,onCameraControllerReady:r},a)=>{const[g,I]=$.useState(!i),{mainCameraRef:c,handleControlsChange:B,controller:C}=Fx(),{handleCameraCreated:l,handleControlsChange:Q}=tut();$.useEffect(()=>{r&&r(C)},[C,r]);const E=$.useMemo(()=>{if(!o)return 10;const u=o.width??0,d=o.height??0,m=Math.max(u,d)*1.5;return m>10?m:10},[o]),h=$.useMemo(()=>{if(n)return[n.x,n.y,0]},[n]);return V.jsxs("div",{style:{position:"relative",width:"100%",height:"100%"},children:[V.jsx(out,{}),V.jsxs(Zht,{ref:a,scene:{up:new Me(0,0,1)},camera:{up:[0,0,1],position:A},onCreated:({camera:u})=>{c.current=u,l(u)},children:[V.jsx(eut,{}),V.jsx(nut,{}),g&&V.jsx(Vht,{autoRotate:!e,autoRotateSpeed:1,onStart:s,rotateSpeed:.5,panSpeed:.75,zoomSpeed:.5,enableDamping:!0,dampingFactor:.1,target:h,onControlsChange:u=>{B(u),Q()}}),V.jsx($ht,{}),V.jsx(Xht,{rotation:[Math.PI/2,0,0],infiniteGrid:!0,cellSize:3,sectionSize:E,args:[E,E]}),t]}),V.jsxs("div",{style:{position:"absolute",right:24,bottom:24,fontFamily:"sans-serif",color:"white",WebkitTextStroke:"0.5px rgba(0, 0, 0, 0.5)",fontSize:11},children:["@",UZA.version]}),i&&!g&&V.jsx("button",{type:"button",onClick:()=>I(!0),onKeyDown:u=>{(u.key==="Enter"||u.key===" ")&&I(!0)},style:{position:"absolute",inset:0,cursor:"pointer",zIndex:XU.clickToInteractOverlay,display:"flex",alignItems:"center",justifyContent:"center"},children:V.jsx("div",{style:{backgroundColor:"rgba(0, 0, 0, 0.8)",color:"white",padding:"12px 24px",borderRadius:"8px",fontSize:"16px",fontFamily:"sans-serif",pointerEvents:"none"},children:"Click to Interact"})})]})}),TZA=t=>$.useMemo(()=>{if(!t)return[];const A=new mXe;return A.add(t),A.render(),A.getCircuitJson()},[t]),sut=t=>{const[A,e]=$.useState([]),[i,o]=$.useState(!0);return $.useEffect(()=>{if(!t)return;(async()=>{o(!0);const r=(Array.isArray(t)?t:[t]).map(async(a,g)=>{const I=xet.serialize({binary:!0},[a]),B=await new Blob(I).arrayBuffer(),l=a.layerType||(g===0?"board":void 0);return{stlData:B,color:a.color,layerType:l}});try{const a=await Promise.all(r);e(a)}catch(a){console.error("Error generating STLs:",a),e([])}finally{o(!1)}})()},[t]),{stls:A,loading:i}},rut=_r(xx()),aut=_r(XO()),wo=.01,$a={traces:.001,copper:.002},Go={copper:[.9,.6,.2],fr4Tan:[.6,.43,.28],fr4SolderMaskGreen:[.02,.1,.04],fr4TracesWithMaskGreen:[0,.5,.25],fr4TracesWithoutMaskTan:[.6,.43,.28],fr1Tan:[.8,.4,.2],fr1TracesWithMaskCopper:[.9,.6,.2],fr1SolderMaskGreen:[.02,.1,.04]},zp=.001,KC=32,BL=.035,Qc=150,d5=.6,xCA={fr1:Go.fr1Tan,fr4:Go.fr4Tan},gut={fr1:Go.fr1TracesWithMaskCopper,fr4:Go.fr4TracesWithoutMaskTan},KZA={fr1:Go.fr1SolderMaskGreen,fr4:Go.fr4SolderMaskGreen},Iut=_r(jU()),cut=_r(xx()),But=_r(iF()),Cut=_r(tWA()),kCA=t=>{let A=0;for(let i=0;i<t.length;i++){const o=(i+1)%t.length;A+=t[i][0]*t[o][1],A-=t[o][0]*t[i][1]}return A/2<=0},GCA=(t,A=1.2,e={})=>{const{xyOutset:i=0}=e,{outline:o}=t;let n=o.map(a=>[a.x,a.y]);kCA(n)&&(n=n.reverse());let s=(0,cut.polygon)({points:n});i!==0&&(s=(0,Cut.expand)({delta:i,corners:"edge"},s));let r=(0,Iut.extrudeLinear)({height:A},s);return r=(0,But.translate)([0,0,-A/2],r),r},lut=t=>{const A=t.filter(a=>a.type==="pcb_panel"),e=mi(t).pcb_board.list();let i,o=1.2;if(A.length>0)i=A[0],o=e.find(g=>g.pcb_panel_id===i.pcb_panel_id)?.thickness??1.2;else{if(i=e.filter(g=>!g.pcb_panel_id)[0],!i)return console.warn("No pcb_board or pcb_panel found for simplified geometry"),[];o=i.thickness??1.2}let n;"outline"in i&&i.outline&&i.outline.length>0?n=GCA({outline:i.outline},o):n=(0,rut.cuboid)({size:[i.width??10,i.height??10,o],center:[i.center.x,i.center.y,0]});const s="material"in i&&i.material?i.material:A.length>0?e.find(a=>a.pcb_panel_id===i.pcb_panel_id)?.material??"fr4":"fr4",r=xCA[s]??Go.fr4Tan;return[(0,aut.colorize)(r,n)]},XB=_r(iF()),va=_r(xx()),dh=_r(XO()),Ag=_r(ON()),$s=_r(xx()),Nm=_r(XO()),Xr=_r(ON()),qZA=_r(iF()),CL=_r(jU()),xd=_r(iF()),Qut=1e-5;function i0(t,A,e){if(typeof e!="number"||!Number.isFinite(e)||e<=0)return 0;const i=t/2,o=A/2,n=Math.min(i,o)-2*Qut;return Math.max(0,Math.min(e,n))}function kl(t){if(!(!t||typeof t!="object"))return t.corner_radius??t.cornerRadius??t.rect_pad_border_radius??t.rectPadBorderRadius??t.rect_border_radius??t.rectBorderRadius??void 0}var Rx=_r(xx()),Eut=_r(jU()),p5=_r(iF()),hut=_r(ON()),uut=64,dut=(t,A,e)=>{const i=(0,Rx.ellipse)({center:[0,0],radius:[Math.max(t/2,wo/2),Math.max(A/2,wo/2)],segments:uut}),o=(0,Eut.extrudeLinear)({height:e},i);return(0,p5.translate)([0,0,-e/2],o)},put=(t,A,e)=>{const i=Math.max(t,wo),o=Math.max(A,wo);if(Math.abs(i-o)<1e-6)return(0,Rx.cylinder)({center:[0,0,0],radius:i/2,height:e});const n=i>=o,s=n?i:o,r=n?o:i,a=Math.max(s-r,0),g=(0,Rx.cuboid)({center:[0,0,0],size:n?[a,r,e]:[r,a,e]});if(a<=1e-6)return(0,Rx.cylinder)({center:[0,0,0],radius:r/2,height:e});const I=a/2,c=(0,Rx.cylinder)({center:n?[-I,0,0]:[0,-I,0],radius:r/2,height:e}),B=(0,Rx.cylinder)({center:n?[I,0,0]:[0,I,0],radius:r/2,height:e});return(0,hut.union)(g,c,B)},f5=(t,A,e={})=>{const i=t.hole_shape||"circle",o=e.sizeDelta??0,n=t.hole_offset_x||0,s=t.hole_offset_y||0,r=[t.x+n,t.y+s,0];if(i==="circle"){const C=Math.max((t.hole_diameter??0)+o,wo),l=Math.max(C/2,wo/2);return(0,Rx.cylinder)({center:r,radius:l,height:A})}const a=t.hole_width??t.hole_diameter,g=t.hole_height??t.hole_diameter;if(!a||!g)return null;const I=Math.max(a+o,wo),c=Math.max(g+o,wo);if(i==="oval"){const C=dut(I,c,A);return(0,p5.translate)([r[0],r[1],0],C)}if(i==="pill"||i==="rotated_pill"){let C=put(I,c,A);if(!C)return null;const l=t.ccw_rotation||0;return l&&(C=(0,p5.rotateZ)(l*Math.PI/180,C)),(0,p5.translate)(r,C)}const B=Math.max((t.hole_diameter??a??g??wo)+o,wo);return(0,Rx.cylinder)({center:r,radius:B/2,height:A})},o0=.02,y5=64,sF=(t,A)=>A?(0,Xr.intersect)(A,t):t,a_=({width:t,height:A,thickness:e,center:i,borderRadius:o})=>{const n=i0(t,A,o);if(n<=0)return(0,$s.cuboid)({center:i,size:[t,A,e]});const s=(0,$s.roundedRectangle)({size:[t,A],roundRadius:n,segments:y5}),r=(0,CL.extrudeLinear)({height:e},s),a=i[2]-e/2;return(0,xd.translate)([i[0],i[1],a],r)},lL=(t,A,e={})=>{const{clipGeom:i}=e;t.shape||(t.shape="circle");const o=A.pcbThickness+2*o0+4*wo,n=A.pcbThickness/2+$a.copper,s=-A.pcbThickness/2-$a.copper,r=n-s;if(t.shape==="circle"){const a=t.outer_diameter??Math.max(t.hole_diameter,0),g=r+.01,I=(0,$s.cylinder)({center:[t.x,t.y,0],radius:a/2,height:g}),c=sF(I,i),B=(0,$s.cylinder)({center:[t.x,t.y,0],radius:Math.max(t.hole_diameter/2,.01),height:o});return(0,Nm.colorize)(Go.copper,(0,Xr.subtract)(c,B))}if(t.shape==="oval"){const a=t.outer_width||t.hole_width||0,g=t.outer_height||t.hole_height||0,I=t.hole_width||0,c=t.hole_height||0,B=(()=>{const Q=(0,$s.cylinder)({center:[0,0,0],radius:1,height:r+.01,segments:64}),E=(0,qZA.scale)([a/2,g/2,1],Q);return(0,xd.translate)([t.x,t.y,0],E)})(),C=sF(B,i),l=(()=>{const Q=(0,$s.cylinder)({center:[0,0,0],radius:1,height:o,segments:64}),E=(0,qZA.scale)([Math.max(I/2,.01),Math.max(c/2,.01),1],Q);return(0,xd.translate)([t.x,t.y,0],E)})();return(0,Nm.colorize)(Go.copper,(0,Xr.subtract)(C,l))}if(t.shape==="circular_hole_with_rect_pad"){const a=t.hole_offset_x||0,g=t.hole_offset_y||0,I=t.rect_pad_width||t.hole_diameter,c=t.rect_pad_height||t.hole_diameter,B=kl(t),C=sF((0,Xr.union)(a_({width:I,height:c,thickness:o0,center:[t.x,t.y,n],borderRadius:B}),a_({width:I,height:c,thickness:o0,center:[t.x,t.y,s],borderRadius:B}),(()=>{const h=Math.max(r-o0*2,wo),f=(n+s)/2,m=(0,$s.roundedRectangle)({size:[I,c],roundRadius:B||0,segments:y5}),b=(0,CL.extrudeLinear)({height:h},m);return(0,xd.translate)([t.x,t.y,f-h/2],b)})(),(0,$s.cylinder)({center:[t.x+(a||0),t.y+(g||0),0],radius:t.hole_diameter/2,height:r})),i),l=(0,$s.cylinder)({center:[t.x+(a||0),t.y+(g||0),0],radius:Math.max(t.hole_diameter/2-wo,.01),height:o}),Q=(0,$s.cylinder)({center:[t.x+(a||0),t.y+(g||0),0],radius:t.hole_diameter/2,height:r});let E=(0,Xr.union)((0,Xr.subtract)(C,Q),Q);return e.clipGeom?(E=(0,Xr.subtract)(E,l),E=(0,Xr.intersect)(E,e.clipGeom),(0,Nm.colorize)(Go.copper,E)):(0,Nm.colorize)(Go.copper,(0,Xr.subtract)(E,l))}if(t.shape==="pill"){const a=(t.ccw_rotation||0)*Math.PI/180,g=k=>{if(!a)return k;const v=(0,xd.translate)([-t.x,-t.y,0],k),_=(0,xd.rotate)([0,0,a],v);return(0,xd.translate)([t.x,t.y,0],_)},I=t.hole_height>t.hole_width,c=I?t.hole_height:t.hole_width,B=I?t.hole_width:t.hole_height,C=I?t.outer_height||B+.2:t.outer_width||c+.2,l=I?t.outer_width||c+.2:t.outer_height||B+.2,Q=B/2,E=Math.abs(c-B),h=r+.01,d=((k,v,_)=>{const Y=v/2,P=Math.abs(k-v);if(P<=1e-6)return(0,$s.cylinder)({center:[t.x,t.y,0],radius:Y,height:_});const T=(0,$s.cuboid)({center:[t.x,t.y,0],size:I?[v,P,_]:[P,v,_]}),O=(0,$s.cylinder)({center:I?[t.x,t.y-P/2,0]:[t.x-P/2,t.y,0],radius:Y,height:_}),W=(0,$s.cylinder)({center:I?[t.x,t.y+P/2,0]:[t.x+P/2,t.y,0],radius:Y,height:_});return(0,Xr.union)(T,O,W)})(C,l,h),f=(0,$s.cuboid)({center:[t.x,t.y,0],size:I?[B-2*wo,E,o]:[E,B-2*wo,o]}),m=(0,$s.cylinder)({center:I?[t.x,t.y-E/2,0]:[t.x-E/2,t.y,0],radius:Q-wo,height:o}),b=(0,$s.cylinder)({center:I?[t.x,t.y+E/2,0]:[t.x+E/2,t.y,0],radius:Q-wo,height:o}),D=(0,Xr.union)(f,m,b),x=sF(g(d),i),F=g(D);return(0,Nm.colorize)(Go.copper,(0,Xr.subtract)(x,F))}if(t.shape==="pill_hole_with_rect_pad"){if(t.hole_shape&&t.hole_shape!=="pill"||t.pad_shape&&t.pad_shape!=="rect")throw new Error("Invalid hole_shape or pad_shape for pill_hole_with_rect_pad");const a=t.hole_offset_x||0,g=t.hole_offset_y||0,I=t.hole_height>t.hole_width,c=I?t.hole_height:t.hole_width,B=I?t.hole_width:t.hole_height,C=B/2,l=Math.abs(c-B),Q=t.rect_pad_width||c+.2,E=t.rect_pad_height||B+.2,h=kl(t),u=.03,d=(0,Xr.union)((0,$s.cuboid)({center:[t.x+a,t.y+g,0],size:I?[B+2*u,l+2*u,r]:[l+2*u,B+2*u,r]}),(0,$s.cylinder)({center:I?[t.x+a,t.y+g-l/2,0]:[t.x+a-l/2,t.y+g,0],radius:C+u,height:r}),(0,$s.cylinder)({center:I?[t.x+a,t.y+g+l/2,0]:[t.x+a+l/2,t.y+g,0],radius:C+u,height:r})),f=(0,Xr.union)((0,$s.cuboid)({center:[t.x+a,t.y+g,0],size:I?[B,l,o*1.1]:[l,B,o*1.1]}),(0,$s.cylinder)({center:I?[t.x+a,t.y+g-l/2,0]:[t.x+a-l/2,t.y+g,0],radius:C,height:o*1.1}),(0,$s.cylinder)({center:I?[t.x+a,t.y+g+l/2,0]:[t.x+a+l/2,t.y+g,0],radius:C,height:o*1.1})),m=a_({width:Q,height:E,thickness:o0,center:[t.x,t.y,n],borderRadius:h}),b=a_({width:Q,height:E,thickness:o0,center:[t.x,t.y,s],borderRadius:h}),D=(()=>{const P=Math.max(r-o0*2,wo),W=(n+s)/2,AA=(0,$s.roundedRectangle)({size:[Q,E],roundRadius:h||0,segments:y5}),oA=(0,CL.extrudeLinear)({height:P},AA);return(0,xd.translate)([t.x,t.y,W-P/2],oA)})(),x=(0,Xr.subtract)(m,f),F=(0,Xr.subtract)(b,f),k=(0,Xr.subtract)(D,f),v=(0,Xr.union)((0,$s.cuboid)({center:[t.x+a,t.y+g,0],size:I?[B-2*wo,l-2*wo,o*1.1]:[l-2*wo,B-2*wo,o*1.1]}),(0,$s.cylinder)({center:I?[t.x+a,t.y+g-l/2,0]:[t.x+a-l/2,t.y+g,0],radius:C-wo,height:o*1.1}),(0,$s.cylinder)({center:I?[t.x+a,t.y+g+l/2,0]:[t.x+a+l/2,t.y+g,0],radius:C-wo,height:o*1.1})),_=(0,Xr.subtract)(d,v),Y=sF((0,Xr.union)(x,F,k,_),i);return(0,Nm.colorize)(Go.copper,Y)}else if(t.shape==="rotated_pill_hole_with_rect_pad"){if(t.hole_shape&&t.hole_shape!=="rotated_pill"||t.pad_shape&&t.pad_shape!=="rect")throw new Error("Invalid hole_shape or pad_shape for rotated_pill_hole_with_rect_pad");const a=t.hole_offset_x||0,g=t.hole_offset_y||0,I=t.hole_width,c=t.hole_height,B=I>=c,C=B?I:c,l=B?c:I,Q=l/2,E=Math.abs(C-l),h=t.rect_pad_width||I+.2,u=t.rect_pad_height||c+.2,d=kl(t),f=.03,m=(t.hole_ccw_rotation||0)*Math.PI/180,b=(t.rect_ccw_rotation||0)*Math.PI/180,D=IA=>{const tA=a*Math.cos(m)-g*Math.sin(m),sA=a*Math.sin(m)+g*Math.cos(m),aA=(0,xd.rotate)([0,0,m],IA);return(0,xd.translate)([t.x+tA,t.y+sA,0],aA)},x=IA=>{if(!b)return IA;const tA=(0,xd.translate)([-t.x,-t.y,0],IA),sA=(0,xd.rotate)([0,0,b],tA);return(0,xd.translate)([t.x,t.y,0],sA)},F=D((0,Xr.union)((0,$s.cuboid)({center:[0,0,0],size:B?[E+2*f,l+2*f,r]:[l+2*f,E+2*f,r]}),(0,$s.cylinder)({center:B?[-E/2,0,0]:[0,-E/2,0],radius:Q+f,height:r}),(0,$s.cylinder)({center:B?[E/2,0,0]:[0,E/2,0],radius:Q+f,height:r}))),k=D((0,Xr.union)((0,$s.cuboid)({center:[0,0,0],size:B?[E,l,o*1.1]:[l,E,o*1.1]}),(0,$s.cylinder)({center:B?[-E/2,0,0]:[0,-E/2,0],radius:Q,height:o*1.1}),(0,$s.cylinder)({center:B?[E/2,0,0]:[0,E/2,0],radius:Q,height:o*1.1}))),v=x(a_({width:h,height:u,thickness:o0,center:[t.x,t.y,n],borderRadius:d})),_=x(a_({width:h,height:u,thickness:o0,center:[t.x,t.y,s],borderRadius:d})),Y=x((()=>{const IA=Math.max(r-o0*2,wo),aA=(n+s)/2,dA=(0,$s.roundedRectangle)({size:[h,u],roundRadius:d||0,segments:y5}),SA=(0,CL.extrudeLinear)({height:IA},dA);return(0,xd.translate)([t.x,t.y,aA-IA/2],SA)})()),P=(0,Xr.subtract)(v,k),T=(0,Xr.subtract)(_,k),O=(0,Xr.subtract)(Y,k),W=D((0,Xr.union)((0,$s.cuboid)({center:[0,0,0],size:B?[E-2*wo,l-2*wo,o*1.1]:[l-2*wo,E-2*wo,o*1.1]}),(0,$s.cylinder)({center:B?[-E/2,0,0]:[0,-E/2,0],radius:Q-wo,height:o*1.1}),(0,$s.cylinder)({center:B?[E/2,0,0]:[0,E/2,0],radius:Q-wo,height:o*1.1}))),AA=(0,Xr.subtract)(F,W),oA=sF((0,Xr.union)(P,T,O,AA),i);return(0,Nm.colorize)(Go.copper,oA)}else if(t.shape==="hole_with_polygon_pad"){const a=t.pad_outline;if(!Array.isArray(a)||a.length<3)throw new Error(`Invalid pad_outline for plated hole at (${t.x}, ${t.y})`);const g=a.map(f=>[f.x,f.y]),I=(0,$s.polygon)({points:g}),c=(n+s)/2,B=(f,m)=>{const b=Math.max(f,wo),D=(0,CL.extrudeLinear)({height:b},I);return(0,xd.translate)([t.x,t.y,m-b/2],D)},C=B(Math.max(r-o0*2,wo),c),l=B(o0,n),Q=B(o0,s),E=sF((0,Xr.union)(C,l,Q),i),h=f5(t,r);if(!h)return(0,Nm.colorize)(Go.copper,E);const u=f5(t,o,{sizeDelta:-2*wo})||h;let d=(0,Xr.union)((0,Xr.subtract)(E,h),h);return e.clipGeom?(d=(0,Xr.subtract)(d,u),d=(0,Xr.intersect)(d,e.clipGeom),(0,Nm.colorize)(Go.copper,d)):(0,Nm.colorize)(Go.copper,(0,Xr.subtract)(d,u))}else throw new Error(`Unsupported plated hole shape: ${t.shape}`)},g_=_r(jU()),PZA=_r(xx()),fut=_r(ON());function yut(t,A,e,i){if(!e||Math.abs(e)<1e-9)return[];const o=4*Math.atan(e),n=A[0]-t[0],s=A[1]-t[1],r=Math.sqrt(n*n+s*s);if(r<1e-9)return[];const a=Math.abs(r/(2*Math.sin(o/2))),g=Math.sqrt(Math.max(0,a*a-r/2*(r/2))),I=[(t[0]+A[0])/2,(t[1]+A[1])/2],c=n/r,C=-(s/r),l=c,Q=I[0]+C*g*Math.sign(e),E=I[1]+l*g*Math.sign(e),h=Math.atan2(t[1]-E,t[0]-Q),u=[],d=Math.max(2,Math.ceil(i*Math.abs(o)/(Math.PI*2)*4)),f=o/d;for(let m=1;m<d;m++){const b=h+f*m;u.push([Q+a*Math.cos(b),E+a*Math.sin(b)])}return u}function w5(t,A){const e=[],i=t.vertices;for(let o=0;o<i.length;o++){const n=i[o],s=i[(o+1)%i.length];if(e.push([n.x,n.y]),n.bulge){const r=yut([n.x,n.y],[s.x,s.y],n.bulge,A);e.push(...r)}}return e}function OZA(t){let A=0;for(let e=0;e<t.length;e++){const i=(e+1)%t.length;A+=t[e][0]*t[i][1],A-=t[i][0]*t[e][1]}return A/2<=0}function wut(t,A=16){let e=w5(t.outer_ring,A);OZA(e)&&e.reverse();const i=(0,PZA.polygon)({points:e});if(!t.inner_rings||t.inner_rings.length===0)return i;const o=t.inner_rings.map(n=>{let s=w5(n,A);return OZA(s)&&s.reverse(),(0,PZA.polygon)({points:s})});return o.length===0?i:(0,fut.subtract)(i,o)}var WZA=_r(ON()),mut=_r(iF()),QL=_r(xx());function Dut({x:t,y:A,outerDiameter:e,holeDiameter:i,thickness:o}){if(e<=i)throw new Error(`Invalid via geometry: outerDiameter (${e}) must be > holeDiameter (${i})`);const n=wo,s=wo,r=Math.min(e/2,i/2+s),a=(0,QL.cylinder)({center:[0,0,0],radius:r,height:o,segments:KC}),g=(0,QL.cylinder)({center:[0,0,o/2],radius:e/2,height:n,segments:KC}),I=(0,QL.cylinder)({center:[0,0,-o/2],radius:e/2,height:n,segments:KC}),c=(0,WZA.union)([a,g,I]),B=o+n*2,C=(0,QL.cylinder)({center:[0,0,0],radius:i/2,height:B,segments:KC}),l=(0,WZA.subtract)(c,C);return(0,mut.translate)([t,A,0],l)}function Sut({x:t,y:A,holeDiameter:e,thickness:i}){const o=i*1.5,n=e/2+wo;return(0,QL.cylinder)({center:[t,A,0],radius:n,height:o,segments:KC})}var ZZA=64,but=1,FCA=.05,VZA=(t,A,e,i)=>{const o=i0(t,A,i);if(o<=0)return(0,va.cuboid)({center:[0,0,0],size:[t,A,e]});const n=(0,va.roundedRectangle)({size:[t,A],roundRadius:o,segments:ZZA}),s=(0,g_.extrudeLinear)({height:e},n);return(0,XB.translate)([0,0,-e/2],s)},jZA=["initializing","processing_pads","processing_copper_pours","processing_plated_holes","processing_holes","processing_cutouts","processing_vias","finalizing","done"],xut=class{circuitJson;board;plated_holes;holes;pads;traces;pcb_vias;pcb_cutouts;pcb_copper_pours;boardGeom=null;platedHoleGeoms=[];padGeoms=[];viaGeoms=[];copperPourGeoms=[];boardClipGeom=null;state="initializing";currentIndex=0;ctx;onCompleteCallback;finalGeoms=[];getHoleToCut(t,A){const e=wo/10;for(const i of this.pcb_vias)if(Math.abs(i.x-t)<e&&Math.abs(i.y-A)<e&&i.hole_diameter)return{diameter:i.hole_diameter};for(const i of this.plated_holes)if(i.shape==="circle"&&Math.abs(i.x-t)<e&&Math.abs(i.y-A)<e&&i.hole_diameter)return{diameter:i.hole_diameter};return null}constructor(t,A){this.circuitJson=t,this.onCompleteCallback=A;const e=t.filter(o=>o.type==="pcb_panel"),i=mi(t).pcb_board.list();if(e.length>0){const o=e[0],n=i.find(s=>s.pcb_panel_id===o.pcb_panel_id);this.board={type:"pcb_board",pcb_board_id:o.pcb_panel_id,center:o.center,width:o.width,height:o.height,thickness:n?.thickness??1.4,material:n?.material??"fr4",num_layers:n?.num_layers??2}}else{const o=i.filter(n=>!n.pcb_panel_id);this.board=o[0]}this.plated_holes=mi(t).pcb_plated_hole.list(),this.holes=mi(t).pcb_hole.list(),this.pads=mi(t).pcb_smtpad.list(),this.traces=mi(t).pcb_trace.list(),this.pcb_vias=mi(t).pcb_via.list(),this.pcb_cutouts=mi(t).pcb_cutout.list(),this.pcb_copper_pours=t.filter(o=>o.type==="pcb_copper_pour"),this.ctx={pcbThickness:this.board.thickness??1.2},this.initializeBoard()}initializeBoard(){const t=this.ctx.pcbThickness+2*but;this.board.outline&&this.board.outline.length>0?(this.boardGeom=GCA({outline:this.board.outline},this.ctx.pcbThickness),this.boardClipGeom=GCA({outline:this.board.outline},t,{xyOutset:FCA})):(this.boardGeom=(0,va.cuboid)({size:[this.board.width,this.board.height,this.ctx.pcbThickness],center:[this.board.center.x,this.board.center.y,0]}),this.boardClipGeom=(0,va.cuboid)({size:[this.board.width+2*FCA,this.board.height+2*FCA,t],center:[this.board.center.x,this.board.center.y,0]})),this.state="processing_pads",this.currentIndex=0}goToNextState(){const t=jZA.indexOf(this.state);t!==-1&&(this.state=jZA[t+1],this.currentIndex=0)}step(t=1){if(this.state==="done"||!this.boardGeom)return!0;for(let A=0;A<t&&this.state!=="done";A++)switch(this.state){case"processing_plated_holes":this.currentIndex<this.plated_holes.length?(this.processPlatedHole(this.plated_holes[this.currentIndex]),this.currentIndex++):this.goToNextState();break;case"processing_holes":this.currentIndex<this.holes.length?(this.processHole(this.holes[this.currentIndex]),this.currentIndex++):this.goToNextState();break;case"processing_pads":this.currentIndex<this.pads.length?(this.processPad(this.pads[this.currentIndex]),this.currentIndex++):this.goToNextState();break;case"processing_vias":this.currentIndex<this.pcb_vias.length?(this.processVia(this.pcb_vias[this.currentIndex]),this.currentIndex++):this.goToNextState();break;case"processing_cutouts":this.currentIndex<this.pcb_cutouts.length?(this.processCutout(this.pcb_cutouts[this.currentIndex]),this.currentIndex++):this.goToNextState();break;case"processing_copper_pours":this.currentIndex<this.pcb_copper_pours.length?(this.processCopperPour(this.pcb_copper_pours[this.currentIndex]),this.currentIndex++):this.goToNextState();break;case"finalizing":this.finalize(),this.state="done";break}return this.state==="done"}processCutout(t){if(!this.boardGeom)return;let A=null;const e=this.ctx.pcbThickness*1.5;switch(t.shape){case"rect":{const i=i0(t.width,t.height,kl(t));if(i>0){const o=(0,va.roundedRectangle)({size:[t.width,t.height],roundRadius:i,segments:ZZA});A=(0,g_.extrudeLinear)({height:e},o),A=(0,XB.translate)([0,0,-e/2],A)}else A=(0,va.cuboid)({center:[0,0,0],size:[t.width,t.height,e]});if(t.rotation){const o=t.rotation*Math.PI/180;A=(0,XB.rotateZ)(o,A)}A=(0,XB.translate)([t.center.x,t.center.y,0],A);break}case"circle":A=(0,va.cylinder)({center:[t.center.x,t.center.y,0],radius:t.radius,height:e});break;case"polygon":{let i=t.points.map(n=>[n.x,n.y]);if(i.length<3){console.warn(`PCB Cutout [${t.pcb_cutout_id}] polygon has fewer than 3 points, skipping.`);break}kCA(i)&&(i=i.reverse());const o=(0,va.polygon)({points:i});A=(0,g_.extrudeLinear)({height:e},o),A=(0,XB.translate)([0,0,-e/2],A);break}}A&&(this.boardGeom=(0,Ag.subtract)(this.boardGeom,A))}processCopperPour(t){const A=t.layer==="bottom"?-1:1,e=A*this.ctx.pcbThickness/2+A*$a.copper;let i=null;if(t.shape==="rect"){let o=(0,va.cuboid)({center:[0,0,0],size:[t.width,t.height,wo]});if("rotation"in t&&t.rotation){const n=t.rotation*Math.PI/180;o=(0,XB.rotateZ)(n,o)}i=(0,XB.translate)([t.center.x,t.center.y,e],o)}else if(t.shape==="brep"){const o=t.brep_shape;if(o?.outer_ring){const n=wut(o);i=(0,g_.extrudeLinear)({height:wo},n),i=(0,XB.translate)([0,0,e],i)}}else if(t.shape==="polygon"){let o=t.points.map(s=>[s.x,s.y]);if(o.length<3){console.warn(`PCB Copper Pour [${t.pcb_copper_pour_id}] polygon has fewer than 3 points, skipping.`);return}kCA(o)&&(o=o.reverse());const n=(0,va.polygon)({points:o});i=(0,g_.extrudeLinear)({height:wo},n),i=(0,XB.translate)([0,0,e],i)}if(i){this.boardClipGeom&&(i=(0,Ag.intersect)(this.boardClipGeom,i));const n=t.covered_with_solder_mask!==!1?gut[this.board.material]??Go.fr4TracesWithoutMaskTan:Go.copper,s=(0,dh.colorize)(n,i);this.copperPourGeoms.push(s)}}processPlatedHole(t,A={}){if(this.boardGeom){if(t.shape==="circle"||t.shape==="circular_hole_with_rect_pad"){let e=null;if(t.shape==="circular_hole_with_rect_pad"){if(t.hole_shape&&t.hole_shape!=="circle"||t.pad_shape&&t.pad_shape!=="rect")return;e=(0,va.cylinder)({center:[t.x+(t.hole_offset_x||0),t.y+(t.hole_offset_y||0),0],radius:t.hole_diameter/2+wo,height:this.ctx.pcbThickness*1.5})}else e=(0,va.cylinder)({center:[t.x,t.y,0],radius:t.hole_diameter/2+wo,height:this.ctx.pcbThickness*1.5});A.dontCutBoard||(this.boardGeom=(0,Ag.subtract)(this.boardGeom,e)),this.padGeoms=this.padGeoms.map(o=>(0,dh.colorize)(Go.copper,(0,Ag.subtract)(o,e)));const i=lL(t,this.ctx,{clipGeom:this.boardClipGeom});this.platedHoleGeoms.push(i)}else if(t.shape==="pill"||t.shape==="oval"){const e=t.hole_height>t.hole_width,i=e?t.hole_height:t.hole_width,o=e?t.hole_width:t.hole_height,n=o/2,s=Math.abs(i-o);let r;if(r=(0,Ag.union)((0,va.cuboid)({center:[t.x,t.y,0],size:e?[o,s,this.ctx.pcbThickness*1.5]:[s,o,this.ctx.pcbThickness*1.5]}),(0,va.cylinder)({center:e?[t.x,t.y-s/2,0]:[t.x-s/2,t.y,0],radius:n,height:this.ctx.pcbThickness*1.5}),(0,va.cylinder)({center:e?[t.x,t.y+s/2,0]:[t.x+s/2,t.y,0],radius:n,height:this.ctx.pcbThickness*1.5})),t.ccw_rotation){const g=t.ccw_rotation*Math.PI/180;r=(0,XB.translate)([t.x,t.y,0],(0,XB.rotateZ)(g,(0,XB.translate)([-t.x,-t.y,0],r)))}A.dontCutBoard||(this.boardGeom=(0,Ag.subtract)(this.boardGeom,r)),this.padGeoms=this.padGeoms.map(g=>(0,dh.colorize)(Go.copper,(0,Ag.subtract)(g,r)));const a=lL(t,this.ctx,{clipGeom:this.boardClipGeom});this.platedHoleGeoms.push(a)}else if(t.shape==="pill_hole_with_rect_pad"){if(t.hole_shape&&t.hole_shape!=="pill"||t.pad_shape&&t.pad_shape!=="rect")return;const e=t.hole_height>t.hole_width,i=e?t.hole_height:t.hole_width,o=e?t.hole_width:t.hole_height,n=o/2,s=Math.abs(i-o);let r;r=(0,Ag.union)((0,va.cuboid)({center:[t.x+(t.hole_offset_x||0),t.y+(t.hole_offset_y||0),0],size:e?[o,s,this.ctx.pcbThickness*1.5]:[s,o,this.ctx.pcbThickness*1.5]}),(0,va.cylinder)({center:e?[t.x+(t.hole_offset_x||0),t.y+(t.hole_offset_y||0)-s/2,0]:[t.x+(t.hole_offset_x||0)-s/2,t.y+(t.hole_offset_y||0),0],radius:n,height:this.ctx.pcbThickness*1.5}),(0,va.cylinder)({center:e?[t.x+(t.hole_offset_x||0),t.y+(t.hole_offset_y||0)+s/2,0]:[t.x+(t.hole_offset_x||0)+s/2,t.y+(t.hole_offset_y||0),0],radius:n,height:this.ctx.pcbThickness*1.5})),A.dontCutBoard||(this.boardGeom=(0,Ag.subtract)(this.boardGeom,r)),this.padGeoms=this.padGeoms.map(g=>(0,dh.colorize)(Go.copper,(0,Ag.subtract)(g,r)));const a=lL(t,this.ctx,{clipGeom:this.boardClipGeom});this.platedHoleGeoms.push(a)}else if(t.shape==="rotated_pill_hole_with_rect_pad"){if(t.hole_shape&&t.hole_shape!=="rotated_pill"||t.pad_shape&&t.pad_shape!=="rect")return;const e=t.hole_width,i=t.hole_height,o=e>=i,n=o?e:i,s=o?i:e,r=s/2,a=Math.abs(n-s),g=t.hole_offset_x||0,I=t.hole_offset_y||0;let c=(0,Ag.union)((0,va.cuboid)({center:[0,0,0],size:o?[a,s,this.ctx.pcbThickness*1.5]:[s,a,this.ctx.pcbThickness*1.5]}),(0,va.cylinder)({center:o?[-a/2,0,0]:[0,-a/2,0],radius:r,height:this.ctx.pcbThickness*1.5}),(0,va.cylinder)({center:o?[a/2,0,0]:[0,a/2,0],radius:r,height:this.ctx.pcbThickness*1.5}));const B=(t.hole_ccw_rotation||0)*Math.PI/180,C=g*Math.cos(B)-I*Math.sin(B),l=g*Math.sin(B)+I*Math.cos(B);c=(0,XB.rotateZ)(B,c);const Q=(0,XB.translate)([t.x+C,t.y+l,0],c);A.dontCutBoard||(this.boardGeom=(0,Ag.subtract)(this.boardGeom,Q)),this.padGeoms=this.padGeoms.map(h=>(0,dh.colorize)(Go.copper,(0,Ag.subtract)(h,Q)));const E=lL(t,this.ctx,{clipGeom:this.boardClipGeom});this.platedHoleGeoms.push(E)}else if(t.shape==="hole_with_polygon_pad"){const e=t.pad_outline;if(!Array.isArray(e)||e.length<3)return;const i=this.ctx.pcbThickness*1.5,o=f5(t,i,{sizeDelta:2*wo}),n=f5(t,i,{sizeDelta:-2*wo});if(!o||!n)return;A.dontCutBoard||(this.boardGeom=(0,Ag.subtract)(this.boardGeom,o)),this.padGeoms=this.padGeoms.map(r=>(0,dh.colorize)(Go.copper,(0,Ag.subtract)(r,o))),this.platedHoleGeoms=this.platedHoleGeoms.map(r=>(0,dh.colorize)(Go.copper,(0,Ag.subtract)(r,n)));const s=lL(t,this.ctx,{clipGeom:this.boardClipGeom});this.platedHoleGeoms.push(s)}}}processHole(t){if(!this.boardGeom)return;const A=this.ctx.pcbThickness*1.5;if(t.hole_shape==="circle"){const e=(0,va.cylinder)({center:[t.x,t.y,0],radius:t.hole_diameter/2+wo,height:A});this.boardGeom=(0,Ag.subtract)(this.boardGeom,e),this.padGeoms=this.padGeoms.map(o=>(0,dh.colorize)(Go.copper,(0,Ag.subtract)(o,e)));const i=(0,va.cylinder)({center:[t.x,t.y,0],radius:t.hole_diameter/2+wo/2,height:A});this.platedHoleGeoms=this.platedHoleGeoms.map(o=>(0,dh.colorize)(Go.copper,(0,Ag.subtract)(o,i)))}else if(t.hole_shape==="pill"||t.hole_shape==="rotated_pill"||t.hole_shape==="oval"){const e=t.hole_width??t.hole_diameter,i=t.hole_height??t.hole_diameter,o=t.ccw_rotation??t.rotation??0,n=.02,s=(g,I,c,B)=>{if(g<=0||I<=0)return null;if(B)return(0,XB.translate)([0,0,-c/2],(0,g_.extrudeLinear)({height:c},(0,va.ellipse)({radius:[g/2,I/2]})));const C=Math.min(g,I)/2,l=Math.abs(g-I);return g>I?(0,Ag.union)((0,va.cuboid)({center:[0,0,0],size:[l,I,c]}),(0,va.cylinder)({center:[-l/2,0,0],radius:C,height:c}),(0,va.cylinder)({center:[l/2,0,0],radius:C,height:c})):(0,Ag.union)((0,va.cuboid)({center:[0,0,0],size:[g,l,c]}),(0,va.cylinder)({center:[0,-l/2,0],radius:C,height:c}),(0,va.cylinder)({center:[0,l/2,0],radius:C,height:c}))};let r=s(e,i,A,t.hole_shape==="oval"),a=s(e-2*n,i-2*n,A,t.hole_shape==="oval");if(r&&o!==0&&(r=(0,XB.rotateZ)(o*Math.PI/180,r)),a&&o!==0&&(a=(0,XB.rotateZ)(o*Math.PI/180,a)),r){const g=(0,XB.translate)([t.x,t.y,0],r);this.boardGeom=(0,Ag.subtract)(this.boardGeom,g),this.padGeoms=this.padGeoms.map(I=>(0,dh.colorize)(Go.copper,(0,Ag.subtract)(I,g)))}if(a){const g=(0,XB.translate)([t.x,t.y,0],a);this.platedHoleGeoms=this.platedHoleGeoms.map(I=>(0,dh.colorize)(Go.copper,(0,Ag.subtract)(I,g)))}}}processPad(t){const A=t.layer==="bottom"?-1:1,e=A*this.ctx.pcbThickness/2+A*$a.copper,i=kl(t);if(t.shape==="rect"){const o=VZA(t.width,t.height,wo,i);let s=(0,XB.translate)([t.x,t.y,e],o);this.boardClipGeom&&(s=(0,Ag.intersect)(this.boardClipGeom,s)),s=(0,dh.colorize)(Go.copper,s),this.padGeoms.push(s)}else if(t.shape==="rotated_rect"){let o=VZA(t.width,t.height,wo,i);const n=t.ccw_rotation*Math.PI/180;o=(0,XB.rotateZ)(n,o);let r=(0,XB.translate)([t.x,t.y,e],o);this.boardClipGeom&&(r=(0,Ag.intersect)(this.boardClipGeom,r)),r=(0,dh.colorize)(Go.copper,r),this.padGeoms.push(r)}else if(t.shape==="circle"){let o=(0,va.cylinder)({center:[t.x,t.y,e],radius:t.radius,height:wo});this.boardClipGeom&&(o=(0,Ag.intersect)(this.boardClipGeom,o)),o=(0,dh.colorize)(Go.copper,o),this.padGeoms.push(o)}}processVia(t){if(this.boardGeom){if(typeof t.outer_diameter=="number"&&typeof t.hole_diameter=="number"){const A=Dut({x:t.x,y:t.y,outerDiameter:t.outer_diameter,holeDiameter:t.hole_diameter,thickness:this.ctx.pcbThickness});let e=A;this.boardClipGeom&&(e=(0,Ag.intersect)(this.boardClipGeom,A),e=(0,dh.colorize)(Go.copper,e)),this.viaGeoms.push(e)}if(typeof t.hole_diameter=="number"){const A=Sut({x:t.x,y:t.y,holeDiameter:t.hole_diameter,thickness:this.ctx.pcbThickness});this.boardGeom=(0,Ag.subtract)(this.boardGeom,A),this.padGeoms=this.padGeoms.map(e=>(0,dh.colorize)(Go.copper,(0,Ag.subtract)(e,A)))}}}finalize(){if(!this.boardGeom)return;const t=xCA[this.board.material]??Go.fr4Tan;this.boardGeom=(0,dh.colorize)(t,this.boardGeom),this.finalGeoms=[this.boardGeom,...this.platedHoleGeoms,...this.padGeoms,...this.viaGeoms,...this.copperPourGeoms],this.onCompleteCallback&&this.onCompleteCallback(this.finalGeoms)}getGeoms(){return this.finalGeoms}},kut=t=>{const[A,e]=$.useState(null),i=$.useRef(!1);return $.useEffect(()=>{let o=!1;if(!t){e(null);return}if(!t.some(g=>g.type==="pcb_board"||g.type==="pcb_panel")){e(null);return}const s=lut(t);e(s);const r=new xut(t,g=>{});return(async()=>{if(!i.current){i.current=!0;try{let g=!1;for(;!g&&!o;)g=r.step(1),g||await new Promise(I=>setTimeout(I,0));o||e(r.getGeoms())}catch(g){console.error("Error during board geometry building:",g)}finally{i.current=!1}}})(),()=>{o=!0}},[t]),A},Gut=({children:t,parent:A,position:e,rotation:i,scale:o,color:n,fontSize:s,anchorX:r,anchorY:a,depthOffset:g})=>{const{rootObject:I}=ku(),c=$.useMemo(()=>{const B=new d6;return B.text=t,e&&B.position.fromArray(e),i&&B.rotation.fromArray(i),o&&B.scale.fromArray(o),B.color=n||"white",B.fontSize=s||1,B.anchorX=r||"center",B.anchorY=a||"middle",B.depthOffset=g||0,B.font=null,B.sync(),B},[t,e,i,o,n,s,r,a,g]);return $.useEffect(()=>{const B=A||I;if(!(!B||!c))return B.add(c),()=>{B.remove(c),c.dispose()}},[I,A,c]),null},zZA=({error:t,cad_component:A})=>{const{rootObject:e}=ku(),[i,o]=$.useState(!1),[n,s]=$.useState(null),r=$.useCallback(c=>{c?.mousePosition?(o(!0),s(c.mousePosition)):(o(!1),s(null))},[]),a=$.useCallback(()=>{o(!1),s(null)},[]),g=$.useMemo(()=>A?.position?[A.position.x,A.position.y,A.position.z].map(B=>Number.isNaN(B)?0:B):[0,0,0],[A]),I=$.useMemo(()=>{const c=new Jp;return c.position.fromArray(g),c},[g]);return $.useEffect(()=>{if(e)return e.add(I),()=>{e.remove(I)}},[e,I]),V.jsxs(V.Fragment,{children:[V.jsxs(cL,{isHovered:i,onHover:r,onUnhover:a,object:I,children:[V.jsx(Fut,{parent:I}),V.jsx(Gut,{parent:I,scale:[.1,.1,.1],color:"red",anchorX:"center",anchorY:"middle",depthOffset:-99999,children:`${t.toString().slice(0,50)}...`})]}),i&&n?V.jsx(cWA,{position:n,style:{fontFamily:"sans-serif",transform:"translate3d(-1rem, 0rem, 0)",backgroundColor:"white",padding:"6px",borderRadius:"4px",color:"red",pointerEvents:"none",userSelect:"none",WebkitUserSelect:"none",MozUserSelect:"none",msUserSelect:"none"},children:t.toString()}):null]})},Fut=({parent:t})=>{const A=$.useMemo(()=>{const e=new Wo(new Bw(.5,.5,.5),new Ih({depthTest:!1,transparent:!0,color:"red",opacity:.5}));return e.renderOrder=999999,e.rotation.fromArray([Math.PI/4,Math.PI/4,0]),e},[]);return $.useEffect(()=>(t.add(A),()=>{t.remove(A)}),[t,A]),null};function Rut({stlUrl:t,stlData:A,mtlUrl:e,color:i,opacity:o=1}){const{rootObject:n}=ku(),[s,r]=$.useState(null);$.useEffect(()=>{const g=new mbe;if(A){try{const I=g.parse(A);r(I)}catch(I){console.error("Failed to parse STL data",I),r(null)}return}t&&g.load(t,I=>{r(I)})},[t,A]);const a=$.useMemo(()=>{if(!s)return null;const g=new Ih({color:Array.isArray(i)?new Li(i[0],i[1],i[2]):i,transparent:o!==1,opacity:o});return new Wo(s,g)},[s,i,o]);return $.useEffect(()=>{if(!(!n||!a))return n.add(a),()=>{n.remove(a),a.geometry.dispose(),Array.isArray(a.material)?a.material.forEach(g=>g.dispose()):a.material.dispose()}},[n,a]),null}function Mut({stlData:t,color:A,opacity:e=1,layerType:i}){const{visibility:o}=WN();let n=!0;return i==="board"?n=o.boardBody:i==="top-copper"?n=o.topCopper:i==="bottom-copper"?n=o.bottomCopper:i==="top-silkscreen"?n=o.topSilkscreen:i==="bottom-silkscreen"&&(n=o.bottomSilkscreen),n?V.jsx(Rut,{stlData:t,color:A,opacity:e}):null}var XZA=class extends Xi.Component{constructor(t){super(t),this.state={hasError:!1,error:null}}static getDerivedStateFromError(t){return{hasError:!0,error:t}}render(){return this.state.hasError&&this.state.error?this.props.fallback({error:this.state.error}):this.props.children}},Nut=t=>{if(t.length===0)return null;let A=t[0].x,e=t[0].y,i=t[0].x,o=t[0].y;for(let n=1;n<t.length;n++){const s=t[n];s.x<A&&(A=s.x),s.y<e&&(e=s.y),s.x>i&&(i=s.x),s.y>o&&(o=s.y)}return{minX:A,minY:e,maxX:i,maxY:o}};function rF(t){if(t.outline&&t.outline.length>=3){const s=Nut(t.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=t.width??0,e=t.height??0,i=t.center?.x??0,o=t.center?.y??0;return{...{minX:i-A/2,maxX:i+A/2,minY:o-e/2,maxY:o+e/2},width:A,height:e,centerX:i,centerY:o}}function m5({layer:t,circuitJson:A,boardData:e,soldermaskColor:i,traceTextureResolution:o}){const n=rF(e),s=document.createElement("canvas"),r=Math.floor(n.width*o),a=Math.floor(n.height*o);s.width=r,s.height=a;const g=s.getContext("2d");if(!g)return null;t==="bottom"&&(g.translate(0,a),g.scale(1,-1));const I=f=>(f-n.minX)*o,c=f=>(n.maxY-f)*o;if(g.fillStyle=i,e.outline&&e.outline.length>=3){g.beginPath();const f=e.outline[0];g.moveTo(I(f.x),c(f.y));for(let m=1;m<e.outline.length;m++){const b=e.outline[m];g.lineTo(I(b.x),c(b.y))}g.closePath(),g.fill()}else g.fillRect(0,0,r,a);g.globalCompositeOperation="destination-out",g.fillStyle="black",mi(A).pcb_smtpad.list().filter(f=>f.layer===t).forEach(f=>{if(f.shape==="polygon"&&f.points){g.beginPath(),f.points.forEach((F,k)=>{const v=I(F.x),_=c(F.y);k===0?g.moveTo(v,_):g.lineTo(v,_)}),g.closePath(),g.fill();return}if(f.x===void 0||f.y===void 0)return;if(Number.isNaN(f.x)||Number.isNaN(f.y)){console.warn(`[soldermask-texture] Skipping pad ${f.pcb_smtpad_id} with NaN coordinates`);return}const m=f.x,b=f.y,D=I(m),x=c(b);if(f.shape==="rect"){const F=f.width*o,k=f.height*o,v=kl(f),_=i0(f.width,f.height,v)*o;_>0?(g.beginPath(),g.roundRect(D-F/2,x-k/2,F,k,_),g.fill()):g.fillRect(D-F/2,x-k/2,F,k)}else if(f.shape==="circle"){const F=(f.radius??f.width/2)*o;g.beginPath(),g.arc(D,x,F,0,2*Math.PI),g.fill()}else if(f.shape==="pill"){const F=f.width*o,k=f.height*o,v=kl(f),_=i0(f.width,f.height,v)*o;g.beginPath(),g.roundRect(D-F/2,x-k/2,F,k,_),g.fill()}else if(f.shape==="rotated_rect"){const F=f.width*o,k=f.height*o,v=kl(f),_=i0(f.width,f.height,v)*o,P=-(f.ccw_rotation||0)*(Math.PI/180);g.save(),g.translate(D,x),g.rotate(P),g.beginPath(),g.roundRect(-F/2,-k/2,F,k,_),g.fill(),g.restore()}}),mi(A).pcb_via.list().forEach(f=>{const m=I(f.x),b=c(f.y),D=f.outer_diameter/2*o;g.beginPath(),g.arc(m,b,D,0,2*Math.PI),g.fill()}),mi(A).pcb_plated_hole.list().forEach(f=>{if(!f.layers?.includes(t))return;const m=f.x,b=f.y,D=I(m),x=c(b);if(f.shape==="circle"){const k=f.outer_diameter/2*o;g.beginPath(),g.arc(D,x,k,0,2*Math.PI),g.fill()}else if(f.shape==="pill"){const F=(f.outer_width??f.outer_diameter??f.hole_width)*o,k=(f.outer_height??f.outer_diameter??f.hole_height)*o,v=Math.min(F,k)/2,Y=-(f.ccw_rotation||0);Y?(g.save(),g.translate(D,x),g.rotate(Y*Math.PI/180),g.beginPath(),g.roundRect(-F/2,-k/2,F,k,v),g.fill(),g.restore()):(g.beginPath(),g.roundRect(D-F/2,x-k/2,F,k,v),g.fill())}else if(f.shape==="oval"){const F=(f.outer_width??f.outer_diameter??f.hole_width)*o,k=(f.outer_height??f.outer_diameter??f.hole_height)*o,v=F/2,_=k/2,P=-(f.ccw_rotation||0);P?(g.save(),g.translate(D,x),g.rotate(P*Math.PI/180),g.beginPath(),g.ellipse(0,0,v,_,0,0,2*Math.PI),g.fill(),g.restore()):(g.beginPath(),g.ellipse(D,x,v,_,0,0,2*Math.PI),g.fill())}else if(f.shape==="hole_with_polygon_pad"){const F=f.hole_shape||"circle",k=f.hole_offset_x||0,v=f.hole_offset_y||0,_=I(f.x+k),Y=c(f.y+v);if(F==="pill"||F==="rotated_pill"){const P=(f.outer_width??f.outer_diameter??f.hole_width)*o,T=(f.outer_height??f.outer_diameter??f.hole_height)*o,O=Math.min(P,T)/2,AA=-(f.ccw_rotation||0);AA?(g.save(),g.translate(_,Y),g.rotate(AA*Math.PI/180),g.beginPath(),g.roundRect(-P/2,-T/2,P,T,O),g.fill(),g.restore()):(g.beginPath(),g.roundRect(_-P/2,Y-T/2,P,T,O),g.fill())}else if(F==="oval"){const P=(f.outer_width??f.outer_diameter??f.hole_width)*o,T=(f.outer_height??f.outer_diameter??f.hole_height)*o,O=P/2,W=T/2,oA=-(f.ccw_rotation||0);oA?(g.save(),g.translate(_,Y),g.rotate(oA*Math.PI/180),g.beginPath(),g.ellipse(0,0,O,W,0,0,2*Math.PI),g.fill(),g.restore()):(g.beginPath(),g.ellipse(_,Y,O,W,0,0,2*Math.PI),g.fill())}else if(F==="circle"){const T=(f.outer_diameter??f.hole_diameter??0)*o/2;g.beginPath(),g.arc(_,Y,T,0,2*Math.PI),g.fill()}f.pad_outline&&f.pad_outline.length>=3&&(g.beginPath(),f.pad_outline.forEach((P,T)=>{const O=I(f.x+P.x),W=c(f.y+P.y);T===0?g.moveTo(O,W):g.lineTo(O,W)}),g.closePath(),g.fill())}else if(f.shape==="circular_hole_with_rect_pad"){const F=(f.rect_pad_width??f.hole_diameter??0)*o,k=(f.rect_pad_height??f.hole_diameter??0)*o,v=kl(f),_=i0(f.rect_pad_width??f.hole_diameter??0,f.rect_pad_height??f.hole_diameter??0,v)*o;_>0?(g.beginPath(),g.roundRect(D-F/2,x-k/2,F,k,_),g.fill()):g.fillRect(D-F/2,x-k/2,F,k)}else if(f.shape==="pill_hole_with_rect_pad"){const F=(f.rect_pad_width??f.hole_width??0)*o,k=(f.rect_pad_height??f.hole_height??0)*o,v=kl(f),_=i0(f.rect_pad_width??f.hole_width??0,f.rect_pad_height??f.hole_height??0,v)*o,P=-(f.ccw_rotation||0);P?(g.save(),g.translate(D,x),g.rotate(P*Math.PI/180),g.beginPath(),g.roundRect(-F/2,-k/2,F,k,_),g.fill(),g.restore()):(g.beginPath(),g.roundRect(D-F/2,x-k/2,F,k,_),g.fill())}else if(f.shape==="rotated_pill_hole_with_rect_pad"){const F=(f.rect_pad_width??f.hole_width??0)*o,k=(f.rect_pad_height??f.hole_height??0)*o,v=kl(f),_=i0(f.rect_pad_width??f.hole_width??0,f.rect_pad_height??f.hole_height??0,v)*o,P=-(f.rect_ccw_rotation||0);P?(g.save(),g.translate(D,x),g.rotate(P*Math.PI/180),g.beginPath(),g.roundRect(-F/2,-k/2,F,k,_),g.fill(),g.restore()):(g.beginPath(),g.roundRect(D-F/2,x-k/2,F,k,_),g.fill())}}),mi(A).pcb_hole.list().forEach(f=>{const m=f.x,b=f.y,D=I(m),x=c(b),F=f.hole_shape;if(F==="circle"&&typeof f.hole_diameter=="number"){const k=f.hole_diameter/2*o;g.beginPath(),g.arc(D,x,k,0,2*Math.PI),g.fill()}else if(F==="pill"&&typeof f.hole_width=="number"&&typeof f.hole_height=="number"){const k=f.hole_width*o,v=f.hole_height*o,_=Math.min(k,v)/2;g.beginPath(),g.roundRect(D-k/2,x-v/2,k,v,_),g.fill()}else if(F==="rotated_pill"&&typeof f.hole_width=="number"&&typeof f.hole_height=="number"){const k=f.hole_width*o,v=f.hole_height*o,_=Math.min(k,v)/2,P=-(f.ccw_rotation||0)*(Math.PI/180);P?(g.save(),g.translate(D,x),g.rotate(P),g.beginPath(),g.roundRect(-k/2,-v/2,k,v,_),g.fill(),g.restore()):(g.beginPath(),g.roundRect(D-k/2,x-v/2,k,v,_),g.fill())}else if(F==="oval"&&typeof f.hole_width=="number"&&typeof f.hole_height=="number"){const k=f.hole_width*o,v=f.hole_height*o,_=k/2,Y=v/2;g.beginPath(),g.ellipse(D,x,_,Y,0,0,2*Math.PI),g.fill()}}),mi(A).pcb_copper_pour.list().forEach(f=>{if(f.layer===t&&f.covered_with_solder_mask===!1)if(f.shape==="rect"){const m=I(f.center.x),b=c(f.center.y),D=f.width*o,x=f.height*o;g.fillRect(m-D/2,b-x/2,D,x)}else f.shape==="polygon"&&f.points&&(g.beginPath(),f.points.forEach((m,b)=>{const D=I(m.x),x=c(m.y);b===0?g.moveTo(D,x):g.lineTo(D,x)}),g.closePath(),g.fill())}),mi(A).pcb_cutout.list().forEach(f=>{switch(f.shape){case"rect":{const m=I(f.center.x),b=c(f.center.y),D=f.width*o,x=f.height*o,F=kl(f),k=i0(f.width,f.height,F);if(f.rotation){g.save(),g.translate(m,b);const v=-f.rotation*(Math.PI/180);g.rotate(v),k>0?(g.beginPath(),g.roundRect(-D/2,-x/2,D,x,k*o),g.fill()):g.fillRect(-D/2,-x/2,D,x),g.restore()}else k>0?(g.beginPath(),g.roundRect(m-D/2,b-x/2,D,x,k*o),g.fill()):g.fillRect(m-D/2,b-x/2,D,x);break}case"circle":{const m=I(f.center.x),b=c(f.center.y),D=f.radius*o;g.beginPath(),g.arc(m,b,D,0,2*Math.PI),g.fill();break}case"polygon":{if(!f.points||f.points.length<3){console.warn(`PCB Cutout [${f.pcb_cutout_id}] polygon has fewer than 3 points, skipping in soldermask texture.`);break}g.beginPath(),f.points.forEach((m,b)=>{const D=I(m.x),x=c(m.y);b===0?g.moveTo(D,x):g.lineTo(D,x)}),g.closePath(),g.fill();break}default:console.warn(`Unsupported cutout shape: ${f.shape} for cutout ${f.pcb_cutout_id} in soldermask texture.`)}}),g.globalCompositeOperation="source-over";const d=new uM(s);return d.generateMipmaps=!0,d.minFilter=fu,d.magFilter=ZB,d.anisotropy=16,d.needsUpdate=!0,d}var _ut=_r(UBA());function $ZA(t,A){return Array.isArray(A)?[t.a*A[0]+t.c*A[1]+t.e,t.b*A[0]+t.d*A[1]+t.f]:{x:t.a*A.x+t.c*A.y+t.e,y:t.b*A.x+t.d*A.y+t.f}}function Mx(t,A=0){return{a:1,c:0,e:t,b:0,d:1,f:A}}function AVA(...t){t=Array.isArray(t[0])?t[0]:t;const A=(e,i)=>({a:e.a*i.a+e.c*i.b,c:e.a*i.c+e.c*i.d,e:e.a*i.e+e.c*i.f+e.e,b:e.b*i.a+e.d*i.b,d:e.b*i.c+e.d*i.d,f:e.b*i.e+e.d*i.f+e.f});switch(t.length){case 0:throw new Error("no matrices provided");case 1:return t[0];case 2:return A(t[0],t[1]);default:{const[e,i,...o]=t,n=A(e,i);return AVA(n,...o)}}}function eVA(...t){return AVA(...t)}var{cos:vut,sin:Uut}=Math;function tVA(t,A,e){const i=vut(t),o=Uut(t);return{a:i,c:-o,e:0,b:o,d:i,f:0}}function Lut(t,A){function e(){this.constructor=t}e.prototype=A.prototype,t.prototype=new e}function D5(t,A,e,i){var o=Error.call(this,t);return Object.setPrototypeOf&&Object.setPrototypeOf(o,D5.prototype),o.expected=A,o.found=e,o.location=i,o.name="SyntaxError",o}Lut(D5,Error);function RCA(t,A,e){return e=e||" ",t.length>A?t:(A-=t.length,e+=e.repeat(A),t+e.slice(0,A))}D5.prototype.format=function(t){var A="Error: "+this.message;if(this.location){var e=null,i;for(i=0;i<t.length;i++)if(t[i].source===this.location.source){e=t[i].text.split(/\r\n|\n|\r/g);break}var o=this.location.start,n=this.location.source&&typeof this.location.source.offset=="function"?this.location.source.offset(o):o,s=this.location.source+":"+n.line+":"+n.column;if(e){var r=this.location.end,a=RCA("",n.line.toString().length," "),g=e[o.line-1],I=o.line===r.line?r.column:g.length+1,c=I-o.column||1;A+=`
|
|
5102
5102
|
--> `+s+`
|
|
5103
5103
|
`+a+` |
|
|
5104
5104
|
`+n.line+" | "+g+`
|
|
5105
5105
|
`+a+" | "+RCA("",o.column-1," ")+RCA("",c,"^")}else A+=`
|
|
5106
|
-
at `+s}return A},D5.buildMessage=function(t,A){var e={literal:function(g){return'"'+o(g.text)+'"'},class:function(g){var I=g.parts.map(function(c){return Array.isArray(c)?n(c[0])+"-"+n(c[1]):n(c)});return"["+(g.inverted?"^":"")+I.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 o(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(I){return"\\x0"+i(I)}).replace(/[\x10-\x1F\x7F-\x9F]/g,function(I){return"\\x"+i(I)})}function n(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(I){return"\\x0"+i(I)}).replace(/[\x10-\x1F\x7F-\x9F]/g,function(I){return"\\x"+i(I)})}function s(g){return e[g.type](g)}function r(g){var I=g.map(s),c,B;if(I.sort(),I.length>0){for(c=1,B=1;c<I.length;c++)I[c-1]!==I[c]&&(I[B]=I[c],B++);I.length=B}switch(I.length){case 1:return I[0];case 2:return I[0]+" or "+I[1];default:return I.slice(0,-1).join(", ")+", or "+I[I.length-1]}}function a(g){return g?'"'+o(g)+'"':"end of input"}return"Expected "+r(t)+" but "+a(A)+" found."};var iVA=25.4,Hut=iVA/1e3,Yut=/^\s*(-?\d*(?:\.\d+)?)(?:\s*(mm|mil|inch|in|"))?\s*$/i;function Jut(t){if(!t)return;const A=t.trim().toLowerCase();return A==='"'||A==="inch"?"in":A}function fQ(t){if(t==null)return;if(typeof t=="number")return Number.isFinite(t)?t:void 0;if(typeof t!="string")return;const A=t.trim();if(A.length===0)return;const e=A.match(Yut);if(!e){const r=Number.parseFloat(A);return Number.isFinite(r)?r:void 0}const[,i,o]=e,n=Number.parseFloat(i||"0");if(!Number.isFinite(n))return;switch(Jut(o)){case"mil":return n*Hut;case"in":return n*iVA;case"mm":case void 0:return n;default:return n}}function ww(t,A){const e=fQ(t);return e===void 0?A:e}function oVA(t){let A=t;if(A.startsWith("#")&&(A=A.slice(1)),A.length===6){const e=parseInt(A.slice(0,2),16),i=parseInt(A.slice(2,4),16),o=parseInt(A.slice(4,6),16);return`rgb(${e}, ${i}, ${o})`}return t.startsWith("rgb")?t:"rgb(255, 243, 204)"}function S5({layer:t,circuitJson:A,boardData:e,silkscreenColor:i="rgb(255,255,255)",traceTextureResolution:o}){const n=mi(A).pcb_silkscreen_text.list(),s=mi(A).pcb_silkscreen_path.list(),r=mi(A).pcb_silkscreen_line.list(),a=mi(A).pcb_silkscreen_rect.list(),g=mi(A).pcb_silkscreen_circle.list(),I=mi(A).pcb_fabrication_note_rect.list(),c=mi(A).pcb_note_line.list(),B=n.filter(v=>v.layer===t),C=s.filter(v=>v.layer===t),l=r.filter(v=>v.layer===t),Q=a.filter(v=>v.layer===t),E=g.filter(v=>v.layer===t),h=I.filter(v=>v.layer===t),u=c.filter(v=>v.layer===t);if(B.length===0&&C.length===0&&l.length===0&&Q.length===0&&E.length===0&&h.length===0&&u.length===0)return null;const d=rF(e),f=document.createElement("canvas"),m=Math.floor(d.width*o),b=Math.floor(d.height*o);f.width=m,f.height=b;const D=f.getContext("2d");if(!D)return null;t==="bottom"&&(D.translate(0,b),D.scale(1,-1)),D.strokeStyle=i,D.fillStyle=i;const x=v=>(v-d.minX)*o,F=v=>(d.maxY-v)*o;l.forEach(v=>{const _=fQ(v.x1)??0,Y=fQ(v.y1)??0,P=fQ(v.x2)??0,T=fQ(v.y2)??0;_===P&&Y===T||(D.beginPath(),D.lineWidth=ww(v.stroke_width,.1)*o,D.lineCap="round",D.moveTo(x(_),F(Y)),D.lineTo(x(P),F(T)),D.stroke())}),u.forEach(v=>{const _=fQ(v.x1)??0,Y=fQ(v.y1)??0,P=fQ(v.x2)??0,T=fQ(v.y2)??0;if(_===P&&Y===T)return;D.save();let O=i;v.color?O=oVA(v.color):O="rgb(255, 243, 204)",D.strokeStyle=O,D.beginPath(),D.lineWidth=ww(v.stroke_width,.1)*o,D.lineCap="round";const W=v.is_dashed??!1;if(W){const AA=Math.max(D.lineWidth*2,1);D.setLineDash([AA,AA])}D.moveTo(x(_),F(Y)),D.lineTo(x(P),F(T)),D.stroke(),W&&D.setLineDash([]),D.restore()}),C.forEach(v=>{v.route.length<2||(D.beginPath(),D.lineWidth=ww(v.stroke_width,.1)*o,D.lineCap="round",D.lineJoin="round",v.route.forEach((_,Y)=>{const P=x(fQ(_.x)??0),T=F(fQ(_.y)??0);Y===0?D.moveTo(P,T):D.lineTo(P,T)}),D.stroke())}),E.forEach(v=>{const _=ww(v.radius,0);if(_<=0)return;const Y=ww(v.stroke_width,.12),P=Y>0,T=fQ(v.center?.x)??0,O=fQ(v.center?.y)??0,W=x(T),AA=F(O),oA=_*o;if(D.save(),D.translate(W,AA),P){const IA=oA+Y/2*o,tA=Math.max(0,oA-Y/2*o);tA>0?(D.beginPath(),D.arc(0,0,IA,0,2*Math.PI),D.arc(0,0,tA,0,2*Math.PI,!0),D.fill("evenodd")):(D.beginPath(),D.arc(0,0,IA,0,2*Math.PI),D.fill())}else D.beginPath(),D.arc(0,0,oA,0,2*Math.PI),D.fill();D.restore()}),Q.forEach(v=>{const _=ww(v.width,0),Y=ww(v.height,0);if(_<=0||Y<=0)return;const P=fQ(v.center?.x)??0,T=fQ(v.center?.y)??0,O=x(P),W=F(T),AA=kl(v),oA=typeof AA=="string"?fQ(AA):AA,IA=i0(_,Y,oA);D.save(),D.translate(O,W);const tA=_/2*o,sA=Y/2*o,aA=Math.min(IA*o,tA,sA),dA=v.stroke_width??!1,SA=v.is_filled??!0,FA=v.is_stroke_dashed??!1,MA=dA?ww(v.stroke_width,.1)*o:0;if(((CA,GA,uA,TA,$A)=>{if(D.beginPath(),$A<=0)D.rect(CA,GA,uA,TA);else{const ae=$A,fA=CA+uA,KA=GA+TA;D.moveTo(CA+ae,GA),D.lineTo(fA-ae,GA),D.quadraticCurveTo(fA,GA,fA,GA+ae),D.lineTo(fA,KA-ae),D.quadraticCurveTo(fA,KA,fA-ae,KA),D.lineTo(CA+ae,KA),D.quadraticCurveTo(CA,KA,CA,KA-ae),D.lineTo(CA,GA+ae),D.quadraticCurveTo(CA,GA,CA+ae,GA),D.closePath()}})(-tA,-sA,tA*2,sA*2,aA),SA&&D.fill(),dA&&MA>0){if(D.lineWidth=MA,FA){const CA=Math.max(MA*2,1);D.setLineDash([CA,CA])}D.stroke(),FA&&D.setLineDash([])}D.restore()}),h.forEach(v=>{const _=ww(v.width,0),Y=ww(v.height,0);if(_<=0||Y<=0)return;const P=fQ(v.center?.x)??0,T=fQ(v.center?.y)??0,O=x(P),W=F(T),AA=kl(v),oA=typeof AA=="string"?fQ(AA):AA,IA=i0(_,Y,oA);D.save(),D.translate(O,W);const tA=_/2*o,sA=Y/2*o,aA=Math.min(IA*o,tA,sA),dA=v.has_stroke??!1,SA=v.is_filled??!0,FA=v.is_stroke_dashed??!1,MA=dA?ww(v.stroke_width,.1)*o:0;let qA=i,CA=i;if(v.color){const uA=oVA(v.color);qA=uA,CA=uA}else qA="rgb(255, 243, 204)",CA="rgb(255, 243, 204)";if(((uA,TA,$A,ae,fA)=>{if(D.beginPath(),fA<=0)D.rect(uA,TA,$A,ae);else{const KA=fA,JA=uA+$A,UA=TA+ae;D.moveTo(uA+KA,TA),D.lineTo(JA-KA,TA),D.quadraticCurveTo(JA,TA,JA,TA+KA),D.lineTo(JA,UA-KA),D.quadraticCurveTo(JA,UA,JA-KA,UA),D.lineTo(uA+KA,UA),D.quadraticCurveTo(uA,UA,uA,UA-KA),D.lineTo(uA,TA+KA),D.quadraticCurveTo(uA,TA,uA+KA,TA),D.closePath()}})(-tA,-sA,tA*2,sA*2,aA),SA&&(D.fillStyle=qA,D.fill()),dA&&MA>0){if(D.strokeStyle=CA,D.lineWidth=MA,FA){const uA=Math.max(MA*2,1);D.setLineDash([uA,uA])}D.stroke(),FA&&D.setLineDash([])}D.restore()}),B.forEach(v=>{const _=v.font_size||.25,Y=Math.min(Math.max(.01,_*.1),_*.05)*o;D.lineWidth=Y,D.lineCap="butt",D.lineJoin="miter";const P=(0,_ut.vectorText)({height:_*.45,input:v.text}),T=[];P.forEach(FA=>{FA.length===29?(T.push(FA.slice(0,15)),T.push(FA.slice(14,29))):FA.length===17?(T.push(FA.slice(0,10)),T.push(FA.slice(9,17))):T.push(FA)});const O=T.flat(),W={minX:O.length>0?Math.min(...O.map(FA=>FA[0])):0,maxX:O.length>0?Math.max(...O.map(FA=>FA[0])):0,minY:O.length>0?Math.min(...O.map(FA=>FA[1])):0,maxY:O.length>0?Math.max(...O.map(FA=>FA[1])):0},AA=(W.minX+W.maxX)/2,oA=(W.minY+W.maxY)/2;let IA=-AA,tA=-oA;const sA=v.anchor_alignment||"center";sA.includes("left")?IA=-W.minX:sA.includes("right")&&(IA=-W.maxX),sA.includes("top")?tA=-W.maxY:sA.includes("bottom")&&(tA=-W.minY);const aA=[];let dA=v.ccw_rotation??0;if(v.layer==="bottom"&&(aA.push(Mx(AA,oA),{a:-1,b:0,c:0,d:1,e:0,f:0},Mx(-AA,-oA)),dA=-dA),dA){const FA=dA*Math.PI/180;aA.push(Mx(AA,oA),tVA(FA),Mx(-AA,-oA))}const SA=aA.length>0?eVA(...aA):void 0;T.forEach(FA=>{D.beginPath(),FA.forEach((MA,qA)=>{let CA={x:MA[0],y:MA[1]};SA&&(CA=$ZA(SA,CA));const GA=CA.x+IA+v.anchor_position.x,uA=CA.y+tA+v.anchor_position.y,TA=x(GA),$A=F(uA);qA===0?D.moveTo(TA,$A):D.lineTo(TA,$A)}),D.stroke()})});const k=new uM(f);return k.generateMipmaps=!0,k.minFilter=fu,k.magFilter=ZB,k.anisotropy=16,k.needsUpdate=!0,k}function nVA(t){return t&&t.route_type==="wire"&&typeof t.layer=="string"&&typeof t.width=="number"}function I_({layer:t,circuitJson:A,boardData:e,traceColor:i,traceTextureResolution:o}){const n=mi(A).pcb_trace.list(),s=mi(A).pcb_via.list(),r=mi(A).pcb_plated_hole.list(),a=n.filter(Q=>Q.route.some(E=>nVA(E)&&E.layer===t));if(a.length===0)return null;const g=rF(e),I=document.createElement("canvas"),c=Math.floor(g.width*o),B=Math.floor(g.height*o);I.width=c,I.height=B;const C=I.getContext("2d");if(!C)return null;t==="bottom"&&(C.translate(0,B),C.scale(1,-1)),a.forEach(Q=>{let E=!0;C.beginPath(),C.strokeStyle=i,C.lineCap="round",C.lineJoin="round";let h=0;for(const u of Q.route){if(!nVA(u)||u.layer!==t){E||C.stroke(),E=!0;continue}const d=u.x,f=u.y;h=u.width*o,C.lineWidth=h;const m=(d-g.minX)*o,b=(g.maxY-f)*o;E?(C.moveTo(m,b),E=!1):C.lineTo(m,b)}E||C.stroke()}),C.globalCompositeOperation="destination-out",C.fillStyle="black",s.forEach(Q=>{const E=(Q.x-g.minX)*o,h=(g.maxY-Q.y)*o,u=Q.outer_diameter/2*o;C.beginPath(),C.arc(E,h,u,0,2*Math.PI,!1),C.fill()}),r.forEach(Q=>{if(Q.layers.includes(t)&&Q.shape==="circle"){const E=(Q.x-g.minX)*o,h=(g.maxY-Q.y)*o,u=Q.outer_diameter/2*o;C.beginPath(),C.arc(E,h,u,0,2*Math.PI,!1),C.fill()}else if(Q.layers.includes(t)&&Q.shape==="rotated_pill_hole_with_rect_pad"){const E=(Q.x-g.minX)*o,h=(g.maxY-Q.y)*o,u=(Q.rect_pad_width??Q.hole_width??0)*o,d=(Q.rect_pad_height??Q.hole_height??0)*o,m=-(Q.rect_ccw_rotation||0);m?(C.save(),C.translate(E,h),C.rotate(m*Math.PI/180),C.beginPath(),C.rect(-u/2,-d/2,u,d),C.fill(),C.restore()):(C.beginPath(),C.rect(E-u/2,h-d/2,u,d),C.fill())}}),C.globalCompositeOperation="source-over";const l=new uM(I);return l.generateMipmaps=!0,l.minFilter=fu,l.magFilter=ZB,l.anisotropy=16,l.needsUpdate=!0,l}var Tut=_r(UBA());function b5(t,A){if(t===void 0)return A;if(typeof t=="number")return t;const e=parseFloat(t.replace(/mm$/,""));return isNaN(e)?A:e}function Kut(t){return t.layer==="bottom"?t.is_mirrored!==!1:t.is_mirrored===!0}function qut(t){const A=t.flat();if(A.length===0)return{minX:0,maxX:0,minY:0,maxY:0,width:0,height:0,centerX:0,centerY:0};const e=Math.min(...A.map(s=>s[0])),i=Math.max(...A.map(s=>s[0])),o=Math.min(...A.map(s=>s[1])),n=Math.max(...A.map(s=>s[1]));return{minX:e,maxX:i,minY:o,maxY:n,width:i-e,height:n-o,centerX:(e+i)/2,centerY:(o+n)/2}}function Put(t){const A=[];return t.forEach(e=>{e.length===29?(A.push(e.slice(0,15)),A.push(e.slice(14,29))):e.length===17?(A.push(e.slice(0,10)),A.push(e.slice(9,17))):A.push(e)}),A}function Out(t,A){let e=-t.centerX,i=-t.centerY;return A.includes("left")?e=-t.minX:A.includes("right")&&(e=-t.maxX),A.includes("top")?i=-t.maxY:A.includes("bottom")&&(i=-t.minY),{x:e,y:i}}function Wut(t,A){const e=[];let i=t.ccw_rotation??0;if(Kut(t)&&(e.push(Mx(A.centerX,A.centerY),{a:-1,b:0,c:0,d:1,e:0,f:0},Mx(-A.centerX,-A.centerY)),i=-i),i){const s=i*Math.PI/180;e.push(Mx(A.centerX,A.centerY),tVA(s),Mx(-A.centerX,-A.centerY))}return{matrix:e.length>0?eVA(...e):void 0,rotationDeg:i}}function sVA(t,A,e,i,o,n,s){A.forEach(r=>{t.beginPath(),r.forEach((a,g)=>{let I={x:a[0],y:a[1]};e&&(I=$ZA(e,I));const c=I.x+i.x+o.x,B=I.y+i.y+o.y,C=n(c),l=s(B);g===0?t.moveTo(C,l):t.lineTo(C,l)}),t.stroke()})}function Zut(t,A,e,i,o,n){t.save(),t.translate(A,e),t.rotate(-n),t.fillRect(-i/2,-o/2,i,o),t.restore()}function Vut(t,A,e,i,o,n,s,r,a,g){const I=typeof A.font_size=="number"?A.font_size:.2,c={left:b5(A.knockout_padding?.left,I*.5),right:b5(A.knockout_padding?.right,I*.5),top:b5(A.knockout_padding?.top,I*.3),bottom:b5(A.knockout_padding?.bottom,I*.3)},B=i.width+c.left+c.right,C=i.height+c.top+c.bottom,l=s(A.anchor_position.x),Q=r(A.anchor_position.y),E=B*a,h=C*a;t.fillStyle=g;const u=n*Math.PI/180;Zut(t,l,Q,E,h,u);const d={x:-i.centerX,y:-i.centerY};t.globalCompositeOperation="destination-out",sVA(t,e,o,d,A.anchor_position,s,r),t.globalCompositeOperation="source-over"}function x5({layer:t,circuitJson:A,boardData:e,copperColor:i="rgb(230, 153, 51)",traceTextureResolution:o}){const s=A.filter(Q=>Q.type==="pcb_copper_text").filter(Q=>Q.layer===t);if(s.length===0)return null;const r=rF(e),a=document.createElement("canvas"),g=Math.floor(r.width*o),I=Math.floor(r.height*o);a.width=g,a.height=I;const c=a.getContext("2d");if(!c)return null;t==="bottom"&&(c.translate(0,I),c.scale(1,-1)),c.strokeStyle=i,c.fillStyle=i;const B=Q=>(Q-r.minX)*o,C=Q=>(r.maxY-Q)*o;s.forEach(Q=>{const E=typeof Q.font_size=="number"?Q.font_size:.2,h=Math.max(.02,E*.08)*o;c.lineWidth=h,c.lineCap="round",c.lineJoin="round";const u=(0,Tut.vectorText)({height:E*.45,input:Q.text}),d=Put(u),f=qut(d),{matrix:m,rotationDeg:b}=Wut(Q,f);if(Q.is_knockout)Vut(c,Q,d,f,m,b,B,C,o,i);else{const D=Q.anchor_alignment||"center",x=Out(f,D);sVA(c,d,m,x,Q.anchor_position,B,C)}});const l=new uM(a);return l.generateMipmaps=!0,l.minFilter=fu,l.magFilter=ZB,l.anisotropy=16,l.needsUpdate=!0,l}function k5({layer:t,circuitJson:A,panelData:e,outlineColor:i="black",traceTextureResolution:o}){const n=mi(A).pcb_board.list().filter(C=>C.pcb_panel_id===e.pcb_board_id);if(n.length===0)return null;const s=document.createElement("canvas"),r=Math.floor(e.width*o),a=Math.floor(e.height*o);s.width=r,s.height=a;const g=s.getContext("2d");if(!g)return null;t==="bottom"&&(g.translate(0,a),g.scale(1,-1)),g.strokeStyle=i,g.lineWidth=.05*o;const I=C=>(C-e.center.x+e.width/2)*o,c=C=>(-(C-e.center.y)+e.height/2)*o;n.forEach(C=>{if(C.outline&&C.outline.length>=2)g.beginPath(),C.outline.forEach((l,Q)=>{const E=I(l.x),h=c(l.y);Q===0?g.moveTo(E,h):g.lineTo(E,h)}),g.closePath(),g.stroke();else{const l=C.width,Q=C.height,{x:E,y:h}=C.center,u=I(E-l/2),d=c(h+Q/2);g.strokeRect(u,d,l*o,Q*o)}});const B=new uM(s);return B.generateMipmaps=!0,B.minFilter=fu,B.magFilter=ZB,B.anisotropy=16,B.needsUpdate=!0,B}function jut({circuitJson:t,pcbThickness:A,isFaux:e=!1}){const{rootObject:i}=ku(),{visibility:o}=WN(),n=$.useMemo(()=>{const r=t.filter(I=>I.type==="pcb_panel"),a=mi(t).pcb_board.list();if(r.length>0){const I=r[0],c=a.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:c?.thickness??1.4,material:c?.material??"fr4",num_layers:c?.num_layers??2}}const g=a.filter(I=>!I.pcb_panel_id);return g.length>0?g[0]:null},[t]),s=$.useMemo(()=>{if(!n||!n.width||!n.height)return null;const r=KZA[n.material]??Go.fr4SolderMaskGreen,a=`rgb(${Math.round(r[0]*255)}, ${Math.round(r[1]*255)}, ${Math.round(r[2]*255)})`,g="rgb(255,255,255)",I=Go.fr4TracesWithMaskGreen,c=`rgb(${Math.round(I[0]*255)}, ${Math.round(I[1]*255)}, ${Math.round(I[2]*255)})`;return{topSoldermask:m5({layer:"top",circuitJson:t,boardData:n,soldermaskColor:a,traceTextureResolution:Qc}),bottomSoldermask:m5({layer:"bottom",circuitJson:t,boardData:n,soldermaskColor:a,traceTextureResolution:Qc}),topSilkscreen:S5({layer:"top",circuitJson:t,boardData:n,silkscreenColor:g,traceTextureResolution:Qc}),bottomSilkscreen:S5({layer:"bottom",circuitJson:t,boardData:n,silkscreenColor:g,traceTextureResolution:Qc}),topTraceWithMask:I_({layer:"top",circuitJson:t,boardData:n,traceColor:c,traceTextureResolution:Qc}),bottomTraceWithMask:I_({layer:"bottom",circuitJson:t,boardData:n,traceColor:c,traceTextureResolution:Qc}),topCopperText:x5({layer:"top",circuitJson:t,boardData:n,copperColor:`rgb(${Math.round(Go.copper[0]*255)}, ${Math.round(Go.copper[1]*255)}, ${Math.round(Go.copper[2]*255)})`,traceTextureResolution:Qc}),bottomCopperText:x5({layer:"bottom",circuitJson:t,boardData:n,copperColor:`rgb(${Math.round(Go.copper[0]*255)}, ${Math.round(Go.copper[1]*255)}, ${Math.round(Go.copper[2]*255)})`,traceTextureResolution:Qc}),topPanelOutlines:k5({layer:"top",circuitJson:t,panelData:n,traceTextureResolution:Qc}),bottomPanelOutlines:k5({layer:"bottom",circuitJson:t,panelData:n,traceTextureResolution:Qc})}},[t,n]);return $.useEffect(()=>{if(!i||!n||!s)return;const r=[],a=(I,c,B,C,l=!1,Q=!1)=>{if(!I)return null;const E=rF(n),h=new Cw(E.width,E.height),u=new pd({map:I,transparent:!0,side:JC,depthWrite:Q,polygonOffset:l,polygonOffsetFactor:l?-1:0,polygonOffsetUnits:l?-1:0,opacity:e?d5:1}),d=new Wo(h,u);return d.position.set(E.centerX,E.centerY,c),B&&d.rotation.set(Math.PI,0,0),d.name=C,d},g=.001;if(o.topMask){const I=a(s.topSoldermask,A/2+g,!1,"jscad-top-soldermask",!0);I&&(r.push(I),i.add(I))}if(o.bottomMask){const I=a(s.bottomSoldermask,-A/2-g,!0,"jscad-bottom-soldermask",!0);I&&(r.push(I),i.add(I))}if(o.topCopper&&o.topMask){const I=a(s.topTraceWithMask,A/2+$a.traces+.004,!1,"jscad-top-trace-with-mask");I&&(r.push(I),i.add(I))}if(o.bottomCopper&&o.bottomMask){const I=a(s.bottomTraceWithMask,-A/2-$a.traces-.005,!0,"jscad-bottom-trace-with-mask");I&&(r.push(I),i.add(I))}if(o.topSilkscreen){const I=a(s.topSilkscreen,A/2+g+.002,!1,"jscad-top-silkscreen");I&&(r.push(I),i.add(I))}if(o.bottomSilkscreen){const I=a(s.bottomSilkscreen,-A/2-g-.002,!0,"jscad-bottom-silkscreen");I&&(r.push(I),i.add(I))}if(o.topCopper){const I=a(s.topCopperText,A/2+$a.copper,!1,"jscad-top-copper-text");I&&(r.push(I),i.add(I))}if(o.bottomCopper){const I=a(s.bottomCopperText,-A/2-$a.copper,!0,"jscad-bottom-copper-text");I&&(r.push(I),i.add(I))}if(o.boardBody){const I=a(s.topPanelOutlines,A/2+g+.003,!1,"jscad-top-panel-outlines",!1,!0);I&&(r.push(I),i.add(I));const c=a(s.bottomPanelOutlines,-A/2-g-.003,!0,"jscad-bottom-panel-outlines",!1,!0);c&&(r.push(c),i.add(c))}return()=>{r.forEach(I=>{I.parent===i&&i.remove(I),I.geometry.dispose(),I.material instanceof Yp&&I.material.dispose()})}},[i,n,s,A,o]),null}function zut(t){const A=mi(t).cad_component.list(),e=mi(t).pcb_smtpad.list(),i=mi(t).pcb_hole.list(),o=mi(t).pcb_plated_hole.list(),n=mi(t).pcb_via.list();if(A.length===0&&e.length===0&&i.length===0&&o.length===0&&n.length===0)return null;const s=[...i,...o,...n,...e],r=d2(s);let a=r.minX,g=r.maxX,I=r.minY,c=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),I=Math.min(I,f),c=Math.max(c,f)}a===1/0&&(a=-10,g=10,I=-10,c=10);const B=2,C=Math.max(Math.abs(a),Math.abs(g))+B,l=Math.max(Math.abs(I),Math.abs(c))+B,Q=Math.max(2*C,10),E=Math.max(2*l,10);return{type:"pcb_board",pcb_board_id:"faux-board",center:{x:0,y:0},width:Q,height:E,thickness:1.4,material:"fr4",num_layers:2}}function rVA(t){if(mi(t).pcb_board.list().length>0)return t;const e=zut(t);if(!e)return t;const o=e.thickness/2;return[...t.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+o}}}}return s}),e]}var Xut=$.forwardRef(({circuitJson:t,children:A,autoRotateDisabled:e,clickToInteractEnabled:i,onUserInteraction:o,onCameraControllerReady:n},s)=>{const r=TZA(A),a=$.useMemo(()=>rVA(t??r),[t,r]),g=kut(a),I=$.useMemo(()=>{if(!a)return[5,-5,5];try{const h=mi(a).pcb_board.list()[0];if(!h)return[5,-5,5];const{width:u,height:d}=h;if(!u&&!d)return[5,-5,5];const f=5,m=Math.max(u,f),b=Math.max(d,f),D=Math.max(m,b);return[D*.4,-D*.7,D*.9]}catch(h){return console.error(h),[5,-5,5]}},[a]),c=$.useMemo(()=>{if(!a)return!1;try{const h=mi(a).pcb_board.list()[0];return!!h&&h.pcb_board_id==="faux-board"}catch{return!1}},[a]),B=$.useMemo(()=>{if(a)try{const h=mi(a).pcb_board.list()[0];return h?{width:h.width??0,height:h.height??0}:void 0}catch(h){console.error(h);return}},[a]),C=$.useMemo(()=>{if(a)try{const h=mi(a).pcb_board.list()[0];return!h||!h.center?void 0:{x:h.center.x,y:h.center.y}}catch(h){console.error(h);return}},[a]),l=_ZA(a),{stls:Q}=sut(g),E=mi(a).cad_component.list();return V.jsxs(JZA,{ref:s,autoRotateDisabled:e,initialCameraPosition:I,clickToInteractEnabled:i,boardDimensions:B,boardCenter:C,onUserInteraction:o,onCameraControllerReady:n,children:[Q.map(({stlData:h,color:u,layerType:d},f)=>V.jsx(Mut,{stlData:h,color:u,opacity:f===0?c?.8:.95:1,layerType:d},`board-${f}`)),V.jsx(jut,{circuitJson:a,pcbThickness:l,isFaux:c}),E.map(h=>V.jsx(XZA,{fallback:({error:u})=>V.jsx(zZA,{cad_component:h,error:u}),children:V.jsx(vZA,{cad_component:h,circuitJson:a},h.cad_component_id)},h.cad_component_id))]})}),$ut=t=>{let A=0;for(let i=0;i<t.length;i++){const o=(i+1)%t.length;t[i]&&t[o]&&(A+=t[i][0]*t[o][1],A-=t[o][0]*t[i][1])}return A/2<=0};function Adt(t,A,e,i,o){let n,s=null;if(e.outline&&e.outline.length>=3){let r=e.outline.map(g=>[g.x,g.y]);$ut(r)&&(r=r.reverse());const a=A.ofPolygons([r]);o.push(a),s=a,n=t.extrude(a,i,void 0,void 0,void 0,!0),o.push(n)}else e.outline&&e.outline.length>0&&console.warn("Board outline has fewer than 3 points, falling back to rectangular board."),n=t.cube([e.width,e.height,i],!0),o.push(n),n=n.translate([e.center.x,e.center.y,0]),o.push(n);return{boardOp:n,outlineCrossSection:s}}var edt=64;function kd({Manifold:t,width:A,height:e,thickness:i,borderRadius:o}){const n=i0(A,e,o);if(n<=0)return t.cube([A,e,i],!0);const s=[],r=A-2*n,a=e-2*n;return r>0&&s.push(t.cube([r,e,i],!0)),a>0&&s.push(t.cube([A,a,i],!0)),[[A/2-n,e/2-n],[-A/2+n,e/2-n],[-A/2+n,-e/2+n],[A/2-n,-e/2+n]].forEach(([I,c])=>{s.push(t.cylinder(i,n,n,edt,!0).translate([I,c,0]))}),t.union(s)}function tdt({Manifold:t,pad:A,padBaseThickness:e}){if(A.shape==="rect"){const i=kl(A);return kd({Manifold:t,width:A.width,height:A.height,thickness:e,borderRadius:i})}else if(A.shape==="rotated_rect"){const i=kl(A);let o=kd({Manifold:t,width:A.width,height:A.height,thickness:e,borderRadius:i});const n=A.ccw_rotation??0;return n&&(o=o.rotate([0,0,n])),o}else if(A.shape==="circle"&&A.radius)return t.cylinder(e,A.radius,-1,32,!0);return null}var idt=t=>{let A=0;for(let i=0;i<t.length;i++){const o=(i+1)%t.length;t[i]&&t[o]&&(A+=t[i][0]*t[o][1],A-=t[o][0]*t[i][1])}return A/2<=0};function odt(t,A,e,i,o){const n=[],s=mi(e).pcb_cutout.list();for(const r of s){let a;const g=i*1.5;switch(r.shape){case"rect":{const B=kl(r);if(typeof B=="number"&&B>0?a=kd({Manifold:t,width:r.width,height:r.height,thickness:g,borderRadius:B}):a=t.cube([r.width,r.height,g],!0),o.push(a),r.rotation){const C=a.rotate([0,0,r.rotation]);o.push(C),a=C}a=a.translate([r.center.x,r.center.y,0]),o.push(a);break}case"circle":a=t.cylinder(g,r.radius,-1,KC,!0),o.push(a),a=a.translate([r.center.x,r.center.y,0]),o.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 I=r.points.map(B=>[B.x,B.y]);idt(I)&&(I=I.reverse());const c=A.ofPolygons([I]);o.push(c),a=t.extrude(c,g,0,0,[1,1],!0),o.push(a);break;default:console.warn(`Unsupported cutout shape: ${r.shape} for cutout ${r.pcb_cutout_id}`);continue}a&&n.push(a)}return{cutoutOps:n}}function aVA({Manifold:t,x:A,y:e,diameter:i,thickness:o,segments:n=32}){return t.cylinder(o*1.2,i/2,i/2,n,!0).translate([A,e,0])}function gVA({Manifold:t,x:A,y:e,holeDiameter:i,thickness:o,zOffset:n=.001,segments:s=32}){const r=i/2+n;return t.cylinder(o*1.2,r,r,s,!0).translate([A,e,0])}function ndt(t,A,e,i,o){const n=[],s=mi(e).pcb_hole.list(),r=(g,I,c)=>{const B=kd({Manifold:t,width:g,height:I,thickness:c,borderRadius:Math.min(g,I)/2});return o.push(B),B},a=(g,I,c)=>{const B=[];for(let C=0;C<c;C++){const l=2*Math.PI*C/c;B.push([g/2*Math.cos(l),I/2*Math.sin(l)])}return B};return s.forEach(g=>{const I=g.hole_shape,c=g.x,B=g.y,C=i*1.2,l=g.ccw_rotation??g.rotation??0,Q=g.hole_width??g.hole_diameter,E=g.hole_height??g.hole_diameter;let h=null;if(I==="circle"){h=aVA({Manifold:t,x:c,y:B,diameter:g.hole_diameter,thickness:i,segments:KC}),n.push(h),o.push(h);return}if(I==="pill"||I==="rotated_pill")h=r(Q,E,C);else if(I==="oval"){let u=a(Q,E,KC),d=0;for(let m=0;m<u.length;m++){const b=(m+1)%u.length;d+=u[m][0]*u[b][1],d-=u[b][0]*u[m][1]}d<=0&&(u=u.reverse());const f=A.ofPolygons([u]);o.push(f),h=t.extrude(f,C,0,0,[1,1],!0),o.push(h)}if(h){if(l!==0){const d=h.rotate([0,0,l]);o.push(d),h=d}const u=h.translate([c,B,0]);o.push(u),n.push(u)}}),{nonPlatedHoleBoardDrills:n}}function mw(t){const A=new dg;if(A.setAttribute("position",new vn(t.vertProperties,3)),A.setIndex(new fz(t.triVerts,1)),t.runIndex&&t.runIndex.length>1&&t.runOriginalID)for(let e=0;e<t.runIndex.length-1;e++){const i=t.runIndex[e],o=t.runIndex[e+1]-i;A.addGroup(i,o,0)}else A.addGroup(0,t.triVerts.length,0);return A}var EL=t=>{let A=0;for(let i=0;i<t.length;i++){const o=(i+1)%t.length;t[i]&&t[o]&&(A+=t[i][0]*t[o][1],A-=t[o][0]*t[i][1])}return A/2<=0},G5=(t,A,e)=>{const i=[];for(let o=0;o<e;o++){const n=2*Math.PI*o/e;i.push([t/2*Math.cos(n),A/2*Math.sin(n)])}return i},aF=new Li(...Go.copper),F5=.05;function sdt(t,A,e,i,o,n){const s=[],r=mi(e).pcb_plated_hole.list(),a=[],g=[],I=(l,Q,E)=>{const h=kd({Manifold:t,width:l,height:Q,thickness:E,borderRadius:Math.min(l,Q)/2});return o.push(h),h},c=({padOutline:l,thickness:Q})=>{if(!Array.isArray(l)||l.length<3)return null;let E=l.map(d=>[d.x,d.y]);EL(E)&&(E=E.reverse());const h=A.ofPolygons([E]);o.push(h);const u=t.extrude(h,Q,0,0,[1,1],!0);return o.push(u),u},B=({ph:l,depth:Q,sizeDelta:E=0})=>{if(l.shape!=="hole_with_polygon_pad")return null;const u=l.pad_outline;if(!Array.isArray(u)||u.length<3)return null;const d=l.hole_shape||"circle",f=l.hole_offset_x||0,m=l.hole_offset_y||0;let b=null;if(d==="circle"){const D=Math.max((l.hole_diameter??0)+E,wo),x=Math.max(D/2,wo/2);b=t.cylinder(Q,x,x,KC,!0),o.push(b)}else{const D=l.hole_width??l.hole_diameter,x=l.hole_height??l.hole_diameter;if(!D||!x)return null;const F=Math.max(D+E,wo),k=Math.max(x+E,wo);if(d==="oval"){let v=G5(F,k,KC);EL(v)&&(v=v.reverse());const _=A.ofPolygons([v]);o.push(_),b=t.extrude(_,Q,0,0,[1,1],!0),o.push(b)}else(d==="pill"||d==="rotated_pill")&&(b=kd({Manifold:t,width:F,height:k,thickness:Q,borderRadius:Math.min(F,k)/2}),o.push(b))}if(!b)return null;if(f||m){const D=b.translate([f,m,0]);o.push(D),b=D}return b};r.forEach((l,Q)=>{if(l.shape==="circle"){const E=gVA({Manifold:t,x:l.x,y:l.y,holeDiameter:l.hole_diameter*1.02,thickness:i,zOffset:zp,segments:KC});o.push(E),s.push(E);const h=i+2*zp,u=t.cylinder(h,l.outer_diameter/2,l.outer_diameter/2,KC,!0);o.push(u);const d=t.cylinder(h*1.05,l.hole_diameter/2,l.hole_diameter/2,KC,!0);o.push(d);const f=u.subtract(d);o.push(f);const m=f.translate([l.x,l.y,0]);o.push(m);let b=m;if(n){const x=t.intersection([m,n]);o.push(x),b=x}g.push(b);const D=mw(b.getMesh());a.push({key:`ph-${l.pcb_plated_hole_id||Q}`,geometry:D,color:aF})}else if(l.shape==="pill"){const E=l.hole_width,h=l.hole_height,u=.4,d=l.outer_width??E+u,f=l.outer_height??h+u,m=E+2*zp,b=h+2*zp,D=i*1.2;let x=I(m,b,D);if(l.ccw_rotation){const W=x.rotate([0,0,l.ccw_rotation]);o.push(W),x=W}const F=x.translate([l.x,l.y,0]);o.push(F),s.push(F);const k=i+2*zp,v=I(d,f,k),_=I(E,h,k*1.05);let Y=v.subtract(_);if(o.push(Y),l.ccw_rotation){const W=Y.rotate([0,0,l.ccw_rotation]);o.push(W),Y=W}const P=Y.translate([l.x,l.y,0]);o.push(P);let T=P;if(n){const W=t.intersection([P,n]);o.push(W),T=W}g.push(T);const O=mw(T.getMesh());a.push({key:`ph-${l.pcb_plated_hole_id||Q}`,geometry:O,color:aF})}else if(l.shape==="pill_hole_with_rect_pad"){if(l.hole_shape&&l.hole_shape!=="pill"||l.pad_shape&&l.pad_shape!=="rect")return;const E=l.hole_width,h=l.hole_height,u=l.hole_offset_x||0,d=l.hole_offset_y||0,f=l.rect_pad_width,m=l.rect_pad_height,b=kl(l),D=BL,x=E+2*zp,F=h+2*zp,k=i*1.2,_=I(x,F,k).translate([u,d,0]).translate([l.x,l.y,0]);o.push(_),s.push(_);const Y=kd({Manifold:t,width:f,height:m,thickness:i-2*D-2*$a.copper+.1,borderRadius:b});o.push(Y);const P=kd({Manifold:t,width:f,height:m,thickness:D,borderRadius:b}).translate([0,0,i/2/2+$a.copper]),T=kd({Manifold:t,width:f,height:m,thickness:D,borderRadius:b}).translate([0,0,-i/2/2-$a.copper]);o.push(P,T);const O=I(E,h,i*1.02).translate([u,d,0]);o.push(O);const W=t.union([Y,P,T,O]);o.push(W);const AA=I(Math.max(E-2*F5,.01),Math.max(h-2*F5,.01),i*1.2).translate([u,d,0]);o.push(AA);const oA=W.subtract(AA);o.push(oA);const IA=oA.translate([l.x,l.y,0]);o.push(IA);let tA=IA;if(n){const aA=t.intersection([IA,n]);o.push(aA),tA=aA}g.push(tA);const sA=mw(tA.getMesh());a.push({key:`ph-${l.pcb_plated_hole_id||Q}`,geometry:sA,color:aF})}else if(l.shape==="rotated_pill_hole_with_rect_pad"){if(l.hole_shape&&l.hole_shape!=="rotated_pill"||l.pad_shape&&l.pad_shape!=="rect")return;const E=l.hole_width,h=l.hole_height,u=l.hole_offset_x||0,d=l.hole_offset_y||0,f=l.rect_pad_width,m=l.rect_pad_height,b=kl(l),D=BL,x=E+2*zp,F=h+2*zp,k=i*1.2;let v=I(x,F,k).translate([u,d,0]);if(l.hole_ccw_rotation){const aA=v.rotate([0,0,l.hole_ccw_rotation]);o.push(aA),v=aA}const _=v.translate([l.x,l.y,0]);o.push(_),s.push(_);let Y=kd({Manifold:t,width:f,height:m,thickness:i-2*D-2*$a.copper+.1,borderRadius:b});if(o.push(Y),l.rect_ccw_rotation){const aA=Y.rotate([0,0,l.rect_ccw_rotation]);o.push(aA),Y=aA}let P=kd({Manifold:t,width:f,height:m,thickness:D,borderRadius:b}).translate([0,0,i/2/2+$a.copper]);if(l.rect_ccw_rotation){const aA=P.rotate([0,0,l.rect_ccw_rotation]);o.push(aA),P=aA}let T=kd({Manifold:t,width:f,height:m,thickness:D,borderRadius:b}).translate([0,0,-i/2/2-$a.copper]);if(l.rect_ccw_rotation){const aA=T.rotate([0,0,l.rect_ccw_rotation]);o.push(aA),T=aA}o.push(P,T);let O=I(E,h,i*1.02).translate([u,d,0]);if(l.hole_ccw_rotation){const aA=O.rotate([0,0,l.hole_ccw_rotation]);o.push(aA),O=aA}o.push(O);const W=t.union([Y,P,T,O]);o.push(W);let AA=I(Math.max(E-2*F5,.01),Math.max(h-2*F5,.01),i*1.2).translate([u,d,0]);if(l.hole_ccw_rotation){const aA=AA.rotate([0,0,l.hole_ccw_rotation]);o.push(aA),AA=aA}o.push(AA);const oA=W.subtract(AA);o.push(oA);const IA=oA.translate([l.x,l.y,0]);o.push(IA);let tA=IA;if(n){const aA=t.intersection([IA,n]);o.push(aA),tA=aA}g.push(tA);const sA=mw(tA.getMesh());a.push({key:`ph-${l.pcb_plated_hole_id||Q}`,geometry:sA,color:aF})}else if(l.shape==="hole_with_polygon_pad"){const E=l.pad_outline;if(!Array.isArray(E)||E.length<3)return;const h=B({ph:l,depth:i*1.2,sizeDelta:2*wo});if(!h)return;const u=h.translate([l.x,l.y,0]);o.push(u),s.push(u);const d=BL,f=Math.max(i-2*d-2*$a.copper+.1,wo),m=c({padOutline:E,thickness:f}),b=c({padOutline:E,thickness:d}),D=c({padOutline:E,thickness:d});if(!m||!b||!D)return;const x=b.translate([0,0,i/2/2+$a.copper]),F=D.translate([0,0,-i/2/2-$a.copper]);o.push(x,F);const k=B({ph:l,depth:i*1.02});if(!k)return;const v=B({ph:l,depth:i*1.2,sizeDelta:-2*wo})||k,_=t.union([m,x,F,k]);o.push(_);const Y=_.subtract(v);o.push(Y);const P=Y.translate([l.x,l.y,0]);o.push(P);let T=P;if(n){const W=t.intersection([P,n]);o.push(W),T=W}g.push(T);const O=mw(T.getMesh());a.push({key:`ph-${l.pcb_plated_hole_id||Q}`,geometry:O,color:aF})}else if(l.shape==="oval"){const E=l.hole_width,h=l.hole_height,u=l.outer_width??E+.4,d=l.outer_height??h+.4,f=E+2*zp,m=h+2*zp,b=i*1.2;let D=G5(f,m,KC);EL(D)&&(D=D.reverse());const x=A.ofPolygons([D]);o.push(x);let F=t.extrude(x,b,0,0,[1,1],!0);if(o.push(F),l.ccw_rotation){const sA=F.rotate([0,0,l.ccw_rotation]);o.push(sA),F=sA}const k=F.translate([l.x,l.y,0]);o.push(k),s.push(k);const v=i+2*zp;let _=G5(u,d,KC);EL(_)&&(_=_.reverse());const Y=A.ofPolygons([_]);o.push(Y);const P=t.extrude(Y,v,0,0,[1,1],!0);o.push(P);let T=G5(E,h,KC);EL(T)&&(T=T.reverse());const O=A.ofPolygons([T]);o.push(O);const W=t.extrude(O,v*1.05,0,0,[1,1],!0);o.push(W);let AA=P.subtract(W);if(o.push(AA),l.ccw_rotation){const sA=AA.rotate([0,0,l.ccw_rotation]);o.push(sA),AA=sA}const oA=AA.translate([l.x,l.y,0]);o.push(oA);let IA=oA;if(n){const sA=t.intersection([oA,n]);o.push(sA),IA=sA}g.push(IA);const tA=mw(IA.getMesh());a.push({key:`ph-${l.pcb_plated_hole_id||Q}`,geometry:tA,color:aF})}else if(l.shape==="circular_hole_with_rect_pad"){if(l.hole_shape&&l.hole_shape!=="circle"||l.pad_shape&&l.pad_shape!=="rect")return;const E=l.hole_offset_x||0,h=l.hole_offset_y||0,u=aVA({Manifold:t,x:l.x+E,y:l.y+h,diameter:l.hole_diameter,thickness:i,segments:KC});o.push(u),s.push(u);const d=l.rect_pad_width??l.hole_diameter,f=l.rect_pad_height??l.hole_diameter,m=kl(l),b=BL,D=l.hole_diameter/2,x=kd({Manifold:t,width:d,height:f,thickness:i-2*b-2*$a.copper+.1,borderRadius:m});o.push(x);const F=kd({Manifold:t,width:d,height:f,thickness:b,borderRadius:m}).translate([0,0,i/2/2+$a.copper]),k=kd({Manifold:t,width:d,height:f,thickness:b,borderRadius:m}).translate([0,0,-i/2/2-$a.copper]);o.push(F,k);const v=t.cylinder(i*1.02,D,D,KC,!0).translate([E,h,0]);o.push(v);const _=t.union([x,F,k,v]);o.push(_);const Y=t.cylinder(i*1.2,Math.max(D-wo,.01),Math.max(D-wo,.01),KC,!0).translate([E,h,0]);o.push(Y);const P=_.subtract(Y);o.push(P);const T=P.translate([l.x,l.y,0]);o.push(T);let O=T;if(n){const AA=t.intersection([T,n]);o.push(AA),O=AA}g.push(O);const W=mw(O.getMesh());a.push({key:`ph-${l.pcb_plated_hole_id||Q}`,geometry:W,color:aF})}});let C;return g.length>0&&(C=t.union(g),o.push(C)),{platedHoleBoardDrills:s,platedHoleCopperGeoms:a,platedHoleSubtractOp:C}}var rdt=new Li(...Go.copper);function adt(t,A,e,i,o,n){const s=[];return mi(A).pcb_smtpad.list().forEach((a,g)=>{const I=BL,c=a.layer==="bottom"?-e/2-$a.copper:e/2+$a.copper;let B=tdt({Manifold:t,pad:a,padBaseThickness:I});if(B){i.push(B);const C=B.translate([a.x,a.y,c]);i.push(C);let l=C;if(o&&(l=C.subtract(o),i.push(l)),n){const E=t.intersection([l,n]);i.push(E),l=E}const Q=mw(l.getMesh());s.push({key:`smt_pad-${a.layer||"top"}-${a.pcb_smtpad_id||g}`,geometry:Q,color:rdt})}}),{smtPadGeoms:s}}function gdt({Manifold:t,x:A,y:e,outerDiameter:i,holeDiameter:o,thickness:n,zOffset:s=.001,segments:r=32}){const a=s,g=s;if(i<o)throw new Error(`Invalid via geometry: outerDiameter (${i}) must be >= holeDiameter (${o})`);const I=Math.min(i/2,o/2+g),c=t.cylinder(n,I,-1,r,!0),B=t.cylinder(a,i/2,-1,r,!0).translate([0,0,n/2]),C=t.cylinder(a,i/2,-1,r,!0).translate([0,0,-n/2]),l=t.union([c,B,C]),Q=n+a*2,E=t.cylinder(Q,o/2,-1,r,!0);return l.subtract(E).translate([A,e,0])}var Idt=new Li(...Go.copper);function cdt(t,A,e,i,o){const n=[],s=mi(A).pcb_via.list(),r=[];return s.forEach((a,g)=>{if(typeof a.hole_diameter=="number"){const I=gVA({Manifold:t,x:a.x,y:a.y,holeDiameter:a.hole_diameter,thickness:e,zOffset:zp,segments:KC});i.push(I),n.push(I)}if(typeof a.outer_diameter=="number"&&typeof a.hole_diameter=="number"){const I=gdt({Manifold:t,x:a.x,y:a.y,outerDiameter:a.outer_diameter,holeDiameter:a.hole_diameter,thickness:e,zOffset:zp,segments:KC});i.push(I);let c=I;if(o){const C=t.intersection([I,o]);i.push(C),c=C}const B=mw(c.getMesh());r.push({key:`via-${a.pcb_via_id||g}`,geometry:B,color:Idt})}}),{viaBoardDrills:n,viaCopperGeoms:r}}function IVA({ctx:t,points:A,canvasXFromPcb:e,canvasYFromPcb:i}){A.length<3||(t.beginPath(),A.forEach((o,n)=>{const s=e(o[0]),r=i(o[1]);n===0?t.moveTo(s,r):t.lineTo(s,r)}),t.closePath(),t.fill())}function Bdt({ctx:t,pour:A,canvasXFromPcb:e,canvasYFromPcb:i}){const o=A.brep_shape;if(!o||!o.outer_ring)return;const n=w5(o.outer_ring,32);if(n.length>=3&&IVA({ctx:t,points:n,canvasXFromPcb:e,canvasYFromPcb:i}),o.inner_rings&&o.inner_rings.length>0){t.globalCompositeOperation="destination-out";for(const s of o.inner_rings){const r=w5(s,32);r.length>=3&&IVA({ctx:t,points:r,canvasXFromPcb:e,canvasYFromPcb:i})}t.globalCompositeOperation="source-over"}}function cVA({layer:t,circuitJson:A,boardData:e,traceTextureResolution:i=Qc}){const o=A.filter(h=>h.type==="pcb_copper_pour"),n=t==="top"?"top_copper":"bottom_copper",s=o.filter(h=>h.layer===t);if(s.length===0)return null;const r=rF(e),a=document.createElement("canvas"),g=Math.floor(r.width*i),I=Math.floor(r.height*i);a.width=g,a.height=I;const c=a.getContext("2d");if(!c)return null;t==="bottom"&&(c.translate(0,I),c.scale(1,-1));const B=h=>(h-r.minX)*i,C=h=>(r.maxY-h)*i,l=s.filter(h=>h.shape==="rect"||h.shape==="polygon"),Q=s.filter(h=>h.shape==="brep");if(l.length>0){const h=new Rtt(c);h.setCameraBounds({minX:r.minX,maxX:r.maxX,minY:r.minY,maxY:r.maxY});const u=l.filter(b=>b.covered_with_solder_mask!==!1),d=l.filter(b=>b.covered_with_solder_mask===!1),f=`rgb(${Go.fr4TracesWithMaskGreen.map(b=>b*255).join(",")})`,m=`rgb(${Go.copper.map(b=>b*255).join(",")})`;u.length>0&&(h.configure({colorOverrides:{copper:{top:f,bottom:f,inner1:f,inner2:f,inner3:f,inner4:f,inner5:f,inner6:f}}}),h.drawElements(u,{layers:[n]})),d.length>0&&(h.configure({colorOverrides:{copper:{top:m,bottom:m,inner1:m,inner2:m,inner3:m,inner4:m,inner5:m,inner6:m}}}),h.drawElements(d,{layers:[n]}))}for(const h of Q){const d=h.covered_with_solder_mask!==!1?Go.fr4TracesWithMaskGreen:Go.copper,f=`rgb(${d[0]*255}, ${d[1]*255}, ${d[2]*255})`;c.fillStyle=f,Bdt({ctx:c,pour:h,canvasXFromPcb:B,canvasYFromPcb:C})}const E=new uM(a);return E.generateMipmaps=!0,E.minFilter=fu,E.magFilter=ZB,E.anisotropy=16,E.needsUpdate=!0,E}function Xp(t,A){const{texture:e,yOffset:i,isBottomLayer:o,textureType:n,usePolygonOffset:s=!1,renderOrder:r=0,isFaux:a=!1}=t;if(!e)return null;const g=rF(A),I=new Cw(g.width,g.height),c=new pd({map:e,transparent:!0,side:JC,depthWrite:n==="panel-outlines",polygonOffset:s,polygonOffsetFactor:s?-4:0,polygonOffsetUnits:s?-4:0,opacity:a?d5:1}),B=new Wo(I,c);return B.position.set(g.centerX,g.centerY,i),o&&B.rotation.set(Math.PI,0,0),B.name=`${o?"bottom":"top"}-${n}-texture-plane`,B.renderOrder=r,B}function Cdt(t,A,e,i=!1){const o=[];if(!t||!A||e===null)return o;const n=Xp({texture:t.topTrace,yOffset:e/2+$a.traces,isBottomLayer:!1,textureType:"trace",usePolygonOffset:!1,renderOrder:2,isFaux:i},A);n&&o.push(n);const s=Xp({texture:t.topTraceWithMask,yOffset:e/2+$a.traces,isBottomLayer:!1,textureType:"trace-with-mask",usePolygonOffset:!1,renderOrder:2,isFaux:i},A);s&&o.push(s);const r=Xp({texture:t.topSilkscreen,yOffset:e/2+.003,isBottomLayer:!1,textureType:"silkscreen",usePolygonOffset:!1,renderOrder:3,isFaux:i},A);r&&o.push(r);const a=Xp({texture:t.bottomTrace,yOffset:-e/2-$a.traces,isBottomLayer:!0,textureType:"trace",usePolygonOffset:!1,renderOrder:2,isFaux:i},A);a&&o.push(a);const g=Xp({texture:t.bottomTraceWithMask,yOffset:-e/2-$a.traces,isBottomLayer:!0,textureType:"trace-with-mask",usePolygonOffset:!1,renderOrder:2,isFaux:i},A);g&&o.push(g);const I=Xp({texture:t.bottomSilkscreen,yOffset:-e/2-.003,isBottomLayer:!0,textureType:"silkscreen",usePolygonOffset:!1,renderOrder:3,isFaux:i},A);I&&o.push(I);const c=Xp({texture:t.topSoldermask,yOffset:e/2+.001,isBottomLayer:!1,textureType:"soldermask",usePolygonOffset:!0,renderOrder:1,isFaux:i},A);c&&o.push(c);const B=Xp({texture:t.bottomSoldermask,yOffset:-e/2-.001,isBottomLayer:!0,textureType:"soldermask",usePolygonOffset:!0,renderOrder:1,isFaux:i},A);B&&o.push(B);const C=Xp({texture:t.topCopperText,yOffset:e/2+$a.copper,isBottomLayer:!1,textureType:"copper-text",usePolygonOffset:!1,renderOrder:2,isFaux:i},A);C&&o.push(C);const l=Xp({texture:t.bottomCopperText,yOffset:-e/2-$a.copper,isBottomLayer:!0,textureType:"copper-text",usePolygonOffset:!1,renderOrder:2,isFaux:i},A);l&&o.push(l);const Q=Xp({texture:t.topCopper,yOffset:e/2+$a.copper,isBottomLayer:!1,textureType:"copper",usePolygonOffset:!1,renderOrder:2,isFaux:i},A);Q&&o.push(Q);const E=Xp({texture:t.bottomCopper,yOffset:-e/2-$a.copper,isBottomLayer:!0,textureType:"copper",usePolygonOffset:!1,renderOrder:2,isFaux:i},A);E&&o.push(E);const h=Xp({texture:t.topPanelOutlines,yOffset:e/2+.004,isBottomLayer:!1,textureType:"panel-outlines",usePolygonOffset:!1,renderOrder:4,isFaux:i},A);h&&o.push(h);const u=Xp({texture:t.bottomPanelOutlines,yOffset:-e/2-.004,isBottomLayer:!0,textureType:"panel-outlines",usePolygonOffset:!1,renderOrder:4,isFaux:i},A);return u&&o.push(u),o}var ldt=(t,A)=>{const[e,i]=$.useState(null),[o,n]=$.useState(null),[s,r]=$.useState(null),[a,g]=$.useState(null),[I,c]=$.useState(!0),B=$.useRef([]),C=$.useMemo(()=>{const Q=A.filter(u=>u.type==="pcb_panel"),E=mi(A).pcb_board.list();if(Q.length>0){const u=Q[0],d=E.find(f=>f.pcb_panel_id===u.pcb_panel_id);return{type:"pcb_board",pcb_board_id:u.pcb_panel_id,center:u.center,width:u.width,height:u.height,thickness:d?.thickness??1.4,material:d?.material??"fr4",num_layers:d?.num_layers??2}}const h=E.filter(u=>!u.pcb_panel_id);return h.length>0?h[0]:null},[A]),l=$.useMemo(()=>{const Q=mi(A).pcb_board.list();return Q.length>0&&Q[0].pcb_board_id==="faux-board"},[A]);return $.useEffect(()=>{if(!t||!C){i(null),n(null),r(null),c(!1);return}if((C.width===0||!C.width)&&(C.height===0||!C.height)&&(!C.outline||C.outline.length<3)){i({platedHoles:[],smtPads:[],vias:[]}),n({}),r(C.thickness??0),c(!1);return}c(!0),g(null);const Q=t.Manifold,E=t.CrossSection,h=m=>{if(!(!m||typeof m.delete!="function"))try{m.delete()}catch(b){(!(b instanceof Error)||!b.message?.includes("Manifold instance already deleted"))&&console.warn("Failed to delete Manifold instance",b)}};B.current.forEach(h),B.current=[];let u=null;const d={},f={};try{const m=C.thickness||1.4;r(m);const{boardOp:b,outlineCrossSection:D}=Adt(Q,E,C,m,B.current);let x=b;const k=m+2*1;let v=null;const _=.01;if(D){let TA=D;if(_>0){const ae=D.offset(_);B.current.push(ae),TA=ae}const $A=Q.extrude(TA,k,void 0,void 0,void 0,!0);B.current.push($A),v=$A}else{const TA=(C.width||0)+2*_,$A=(C.height||0)+2*_,ae=Q.cube([TA,$A,k],!0);B.current.push(ae);const fA=ae.translate([C.center.x,C.center.y,0]);B.current.push(fA),v=fA}const Y=[];let P=null;const{nonPlatedHoleBoardDrills:T}=ndt(Q,E,A,m,B.current);Y.push(...T);const{platedHoleBoardDrills:O,platedHoleCopperGeoms:W,platedHoleSubtractOp:AA}=sdt(Q,E,A,m,B.current,v);Y.push(...O),d.platedHoles=W;const{viaBoardDrills:oA,viaCopperGeoms:IA}=cdt(Q,A,m,B.current,v);if(Y.push(...oA),d.vias=IA,Y.length>0){P=Q.union(Y),B.current.push(P);const TA=AA?Q.union([P,AA]):P;B.current.push(TA);const $A=x.subtract(TA);if(B.current.push($A),x=$A,AA){const ae=AA.subtract(P);B.current.push(ae);const fA=ae.getMesh(),KA=mw(fA);d.platedHoles=[{key:"plated-holes-union",geometry:KA,color:new Li(Go.copper[0],Go.copper[1],Go.copper[2])}]}}const{cutoutOps:tA}=odt(Q,E,A,m,B.current);if(tA.length>0){const TA=Q.union(tA);B.current.push(TA);const $A=x.subtract(TA);B.current.push($A),x=$A}if(u=x,u){const TA=u.getMesh(),$A=mw(TA),ae=xCA[C.material]??Go.fr4Tan;d.board={geometry:$A,color:new Li(ae[0],ae[1],ae[2]),material:C.material,isFaux:l}}const{smtPadGeoms:sA}=adt(Q,A,m,B.current,P,v);d.smtPads=sA,i(d);const aA=Go.fr4TracesWithoutMaskTan,dA=`rgb(${Math.round(aA[0]*255)}, ${Math.round(aA[1]*255)}, ${Math.round(aA[2]*255)})`;f.topTrace=I_({layer:"top",circuitJson:A,boardData:C,traceColor:dA,traceTextureResolution:Qc}),f.bottomTrace=I_({layer:"bottom",circuitJson:A,boardData:C,traceColor:dA,traceTextureResolution:Qc});const SA=Go.fr4TracesWithMaskGreen,FA=`rgb(${Math.round(SA[0]*255)}, ${Math.round(SA[1]*255)}, ${Math.round(SA[2]*255)})`;f.topTraceWithMask=I_({layer:"top",circuitJson:A,boardData:C,traceColor:FA,traceTextureResolution:Qc}),f.bottomTraceWithMask=I_({layer:"bottom",circuitJson:A,boardData:C,traceColor:FA,traceTextureResolution:Qc});const MA="rgb(255,255,255)";f.topSilkscreen=S5({layer:"top",circuitJson:A,boardData:C,silkscreenColor:MA,traceTextureResolution:Qc}),f.bottomSilkscreen=S5({layer:"bottom",circuitJson:A,boardData:C,silkscreenColor:MA,traceTextureResolution:Qc});const qA=KZA[C.material]??Go.fr4SolderMaskGreen,CA=`rgb(${Math.round(qA[0]*255)}, ${Math.round(qA[1]*255)}, ${Math.round(qA[2]*255)})`;f.topSoldermask=m5({layer:"top",circuitJson:A,boardData:C,soldermaskColor:CA,traceTextureResolution:Qc}),f.bottomSoldermask=m5({layer:"bottom",circuitJson:A,boardData:C,soldermaskColor:CA,traceTextureResolution:Qc});const GA=Go.copper,uA=`rgb(${Math.round(GA[0]*255)}, ${Math.round(GA[1]*255)}, ${Math.round(GA[2]*255)})`;f.topCopperText=x5({layer:"top",circuitJson:A,boardData:C,copperColor:uA,traceTextureResolution:Qc}),f.bottomCopperText=x5({layer:"bottom",circuitJson:A,boardData:C,copperColor:uA,traceTextureResolution:Qc}),f.topPanelOutlines=k5({layer:"top",circuitJson:A,panelData:C,traceTextureResolution:Qc}),f.bottomPanelOutlines=k5({layer:"bottom",circuitJson:A,panelData:C,traceTextureResolution:Qc}),f.topCopper=cVA({layer:"top",circuitJson:A,boardData:C,traceTextureResolution:Qc}),f.bottomCopper=cVA({layer:"bottom",circuitJson:A,boardData:C,traceTextureResolution:Qc}),n(f)}catch(m){console.error("Error processing geometry with Manifold in hook:",m),g(m.message||"An unknown error occurred while processing geometry in hook."),i(null),n(null)}finally{c(!1)}return()=>{B.current.forEach(h),B.current=[]}},[t,A,C]),{geoms:e,textures:o,pcbThickness:s,error:a,isLoading:I,boardData:C,isFauxBoard:l}},Qdt=JC,Edt=({material:t,color:A,side:e=Qdt,isFaux:i=!1})=>t==="fr4"?new lw({color:A,side:e,metalness:0,roughness:.8,specularIntensity:.2,ior:1.45,sheen:0,clearcoat:0,transparent:i,opacity:i?d5:1,flatShading:!0}):new Ih({color:A,side:e,flatShading:!0,metalness:.1,roughness:.8,transparent:!0,opacity:i?d5:.9});function hdt(t){const A=[];if(!t)return A;if(t.board&&t.board.geometry){const i=new Wo(t.board.geometry,Edt({material:t.board.material,color:t.board.color,side:JC,isFaux:t.board.isFaux}));i.name="board-geom",A.push(i)}const e=i=>{i&&i.forEach(o=>{const n=new Wo(o.geometry,new Ih({color:o.color,side:JC,flatShading:!0,polygonOffset:!0,polygonOffsetFactor:-1,polygonOffsetUnits:-1}));n.name=o.key,A.push(n)})};return e(t.platedHoles),e(t.smtPads),e(t.vias),A}var udt=({geometryMeshes:t,textureMeshes:A})=>{const{rootObject:e}=ku(),{visibility:i}=WN();return $.useEffect(()=>{if(e)return t.forEach(o=>{let n=!0;o.name==="board-geom"?n=i.boardBody:o.name.includes("smt_pad")?o.name.includes("smt_pad-top")?n=i.topCopper:o.name.includes("smt_pad-bottom")?n=i.bottomCopper:n=i.topCopper||i.bottomCopper:(o.name.includes("plated_hole")||o.name.includes("via"))&&(n=i.topCopper||i.bottomCopper),n&&e.add(o)}),A.forEach(o=>{let n=!0;o.name.includes("top-trace-texture-plane")&&!o.name.includes("with-mask")?n=i.topCopper&&!i.topMask:o.name.includes("top-trace-with-mask")?n=i.topCopper&&i.topMask:o.name.includes("bottom-trace-texture-plane")&&!o.name.includes("with-mask")?n=i.bottomCopper&&!i.bottomMask:o.name.includes("bottom-trace-with-mask")?n=i.bottomCopper&&i.bottomMask:o.name.includes("top-silkscreen")?n=i.topSilkscreen:o.name.includes("bottom-silkscreen")?n=i.bottomSilkscreen:o.name.includes("top-soldermask")?n=i.topMask:o.name.includes("bottom-soldermask")?n=i.bottomMask:o.name.includes("top-copper-text")?n=i.topCopper:o.name.includes("bottom-copper-text")?n=i.bottomCopper:o.name.includes("top-copper")?n=i.topCopper:o.name.includes("bottom-copper")?n=i.bottomCopper:o.name.includes("panel-outlines")&&(n=i.boardBody),n&&e.add(o)}),()=>{t.forEach(o=>{o.parent===e&&e.remove(o)}),A.forEach(o=>{o.parent===e&&e.remove(o)})}},[e,t,A,i]),null},ddt="https://cdn.jsdelivr.net/npm/manifold-3d@3.2.1",pdt=({circuitJson:t,autoRotateDisabled:A,clickToInteractEnabled:e,onUserInteraction:i,children:o,onCameraControllerReady:n})=>{const s=TZA(o),r=$.useMemo(()=>rVA(t??s),[t,s]),[a,g]=$.useState(null),[I,c]=$.useState(null);$.useEffect(()=>{if(window.ManifoldModule&&typeof window.ManifoldModule=="object"&&window.ManifoldModule.setup){g(window.ManifoldModule);return}const F=async T=>{try{const O=await T();O.setup(),window.ManifoldModule=O,g(O)}catch(O){console.error("Failed to initialize Manifold:",O),c(`Failed to initialize Manifold: ${O instanceof Error?O.message:"Unknown error"}`)}},k=window.ManifoldModule??window.MANIFOLD??window.MANIFOLD_MODULE;if(k){window.ManifoldModule=k,F(window.ManifoldModule);return}const v="manifoldLoaded",_=()=>{const T=window.ManifoldModule??window.MANIFOLD??window.MANIFOLD_MODULE;if(T)window.ManifoldModule=T,F(window.ManifoldModule);else{const O="ManifoldModule not found on window after script load.";console.error(O),c(O)}};window.addEventListener(v,_,{once:!0});const Y=document.createElement("script");Y.type="module",Y.innerHTML=`
|
|
5106
|
+
at `+s}return A},D5.buildMessage=function(t,A){var e={literal:function(g){return'"'+o(g.text)+'"'},class:function(g){var I=g.parts.map(function(c){return Array.isArray(c)?n(c[0])+"-"+n(c[1]):n(c)});return"["+(g.inverted?"^":"")+I.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 o(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(I){return"\\x0"+i(I)}).replace(/[\x10-\x1F\x7F-\x9F]/g,function(I){return"\\x"+i(I)})}function n(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(I){return"\\x0"+i(I)}).replace(/[\x10-\x1F\x7F-\x9F]/g,function(I){return"\\x"+i(I)})}function s(g){return e[g.type](g)}function r(g){var I=g.map(s),c,B;if(I.sort(),I.length>0){for(c=1,B=1;c<I.length;c++)I[c-1]!==I[c]&&(I[B]=I[c],B++);I.length=B}switch(I.length){case 1:return I[0];case 2:return I[0]+" or "+I[1];default:return I.slice(0,-1).join(", ")+", or "+I[I.length-1]}}function a(g){return g?'"'+o(g)+'"':"end of input"}return"Expected "+r(t)+" but "+a(A)+" found."};var iVA=25.4,Hut=iVA/1e3,Yut=/^\s*(-?\d*(?:\.\d+)?)(?:\s*(mm|mil|inch|in|"))?\s*$/i;function Jut(t){if(!t)return;const A=t.trim().toLowerCase();return A==='"'||A==="inch"?"in":A}function fQ(t){if(t==null)return;if(typeof t=="number")return Number.isFinite(t)?t:void 0;if(typeof t!="string")return;const A=t.trim();if(A.length===0)return;const e=A.match(Yut);if(!e){const r=Number.parseFloat(A);return Number.isFinite(r)?r:void 0}const[,i,o]=e,n=Number.parseFloat(i||"0");if(!Number.isFinite(n))return;switch(Jut(o)){case"mil":return n*Hut;case"in":return n*iVA;case"mm":case void 0:return n;default:return n}}function ww(t,A){const e=fQ(t);return e===void 0?A:e}function oVA(t){let A=t;if(A.startsWith("#")&&(A=A.slice(1)),A.length===6){const e=parseInt(A.slice(0,2),16),i=parseInt(A.slice(2,4),16),o=parseInt(A.slice(4,6),16);return`rgb(${e}, ${i}, ${o})`}return t.startsWith("rgb")?t:"rgb(255, 243, 204)"}function S5({layer:t,circuitJson:A,boardData:e,silkscreenColor:i="rgb(255,255,255)",traceTextureResolution:o}){const n=mi(A).pcb_silkscreen_text.list(),s=mi(A).pcb_silkscreen_path.list(),r=mi(A).pcb_silkscreen_line.list(),a=mi(A).pcb_silkscreen_rect.list(),g=mi(A).pcb_silkscreen_circle.list(),I=mi(A).pcb_fabrication_note_rect.list(),c=mi(A).pcb_note_line.list(),B=n.filter(v=>v.layer===t),C=s.filter(v=>v.layer===t),l=r.filter(v=>v.layer===t),Q=a.filter(v=>v.layer===t),E=g.filter(v=>v.layer===t),h=I.filter(v=>v.layer===t),u=c.filter(v=>v.layer===t);if(B.length===0&&C.length===0&&l.length===0&&Q.length===0&&E.length===0&&h.length===0&&u.length===0)return null;const d=rF(e),f=document.createElement("canvas"),m=Math.floor(d.width*o),b=Math.floor(d.height*o);f.width=m,f.height=b;const D=f.getContext("2d");if(!D)return null;t==="bottom"&&(D.translate(0,b),D.scale(1,-1)),D.strokeStyle=i,D.fillStyle=i;const x=v=>(v-d.minX)*o,F=v=>(d.maxY-v)*o;l.forEach(v=>{const _=fQ(v.x1)??0,Y=fQ(v.y1)??0,P=fQ(v.x2)??0,T=fQ(v.y2)??0;_===P&&Y===T||(D.beginPath(),D.lineWidth=ww(v.stroke_width,.1)*o,D.lineCap="round",D.moveTo(x(_),F(Y)),D.lineTo(x(P),F(T)),D.stroke())}),u.forEach(v=>{const _=fQ(v.x1)??0,Y=fQ(v.y1)??0,P=fQ(v.x2)??0,T=fQ(v.y2)??0;if(_===P&&Y===T)return;D.save();let O=i;v.color?O=oVA(v.color):O="rgb(255, 243, 204)",D.strokeStyle=O,D.beginPath(),D.lineWidth=ww(v.stroke_width,.1)*o,D.lineCap="round";const W=v.is_dashed??!1;if(W){const AA=Math.max(D.lineWidth*2,1);D.setLineDash([AA,AA])}D.moveTo(x(_),F(Y)),D.lineTo(x(P),F(T)),D.stroke(),W&&D.setLineDash([]),D.restore()}),C.forEach(v=>{v.route.length<2||(D.beginPath(),D.lineWidth=ww(v.stroke_width,.1)*o,D.lineCap="round",D.lineJoin="round",v.route.forEach((_,Y)=>{const P=x(fQ(_.x)??0),T=F(fQ(_.y)??0);Y===0?D.moveTo(P,T):D.lineTo(P,T)}),D.stroke())}),E.forEach(v=>{const _=ww(v.radius,0);if(_<=0)return;const Y=ww(v.stroke_width,.12),P=Y>0,T=fQ(v.center?.x)??0,O=fQ(v.center?.y)??0,W=x(T),AA=F(O),oA=_*o;if(D.save(),D.translate(W,AA),P){const IA=oA+Y/2*o,tA=Math.max(0,oA-Y/2*o);tA>0?(D.beginPath(),D.arc(0,0,IA,0,2*Math.PI),D.arc(0,0,tA,0,2*Math.PI,!0),D.fill("evenodd")):(D.beginPath(),D.arc(0,0,IA,0,2*Math.PI),D.fill())}else D.beginPath(),D.arc(0,0,oA,0,2*Math.PI),D.fill();D.restore()}),Q.forEach(v=>{const _=ww(v.width,0),Y=ww(v.height,0);if(_<=0||Y<=0)return;const P=fQ(v.center?.x)??0,T=fQ(v.center?.y)??0,O=x(P),W=F(T),AA=kl(v),oA=typeof AA=="string"?fQ(AA):AA,IA=i0(_,Y,oA);D.save(),D.translate(O,W);const tA=_/2*o,sA=Y/2*o,aA=Math.min(IA*o,tA,sA),dA=v.stroke_width??!1,SA=v.is_filled??!0,FA=v.is_stroke_dashed??!1,MA=dA?ww(v.stroke_width,.1)*o:0;if(((CA,GA,uA,TA,$A)=>{if(D.beginPath(),$A<=0)D.rect(CA,GA,uA,TA);else{const ae=$A,fA=CA+uA,KA=GA+TA;D.moveTo(CA+ae,GA),D.lineTo(fA-ae,GA),D.quadraticCurveTo(fA,GA,fA,GA+ae),D.lineTo(fA,KA-ae),D.quadraticCurveTo(fA,KA,fA-ae,KA),D.lineTo(CA+ae,KA),D.quadraticCurveTo(CA,KA,CA,KA-ae),D.lineTo(CA,GA+ae),D.quadraticCurveTo(CA,GA,CA+ae,GA),D.closePath()}})(-tA,-sA,tA*2,sA*2,aA),SA&&D.fill(),dA&&MA>0){if(D.lineWidth=MA,FA){const CA=Math.max(MA*2,1);D.setLineDash([CA,CA])}D.stroke(),FA&&D.setLineDash([])}D.restore()}),h.forEach(v=>{const _=ww(v.width,0),Y=ww(v.height,0);if(_<=0||Y<=0)return;const P=fQ(v.center?.x)??0,T=fQ(v.center?.y)??0,O=x(P),W=F(T),AA=kl(v),oA=typeof AA=="string"?fQ(AA):AA,IA=i0(_,Y,oA);D.save(),D.translate(O,W);const tA=_/2*o,sA=Y/2*o,aA=Math.min(IA*o,tA,sA),dA=v.has_stroke??!1,SA=v.is_filled??!0,FA=v.is_stroke_dashed??!1,MA=dA?ww(v.stroke_width,.1)*o:0;let qA=i,CA=i;if(v.color){const uA=oVA(v.color);qA=uA,CA=uA}else qA="rgb(255, 243, 204)",CA="rgb(255, 243, 204)";if(((uA,TA,$A,ae,fA)=>{if(D.beginPath(),fA<=0)D.rect(uA,TA,$A,ae);else{const KA=fA,JA=uA+$A,UA=TA+ae;D.moveTo(uA+KA,TA),D.lineTo(JA-KA,TA),D.quadraticCurveTo(JA,TA,JA,TA+KA),D.lineTo(JA,UA-KA),D.quadraticCurveTo(JA,UA,JA-KA,UA),D.lineTo(uA+KA,UA),D.quadraticCurveTo(uA,UA,uA,UA-KA),D.lineTo(uA,TA+KA),D.quadraticCurveTo(uA,TA,uA+KA,TA),D.closePath()}})(-tA,-sA,tA*2,sA*2,aA),SA&&(D.fillStyle=qA,D.fill()),dA&&MA>0){if(D.strokeStyle=CA,D.lineWidth=MA,FA){const uA=Math.max(MA*2,1);D.setLineDash([uA,uA])}D.stroke(),FA&&D.setLineDash([])}D.restore()}),B.forEach(v=>{const _=v.font_size||.25,Y=Math.min(Math.max(.01,_*.1),_*.05)*o;D.lineWidth=Y,D.lineCap="butt",D.lineJoin="miter";const P=(0,_ut.vectorText)({height:_*.45,input:v.text}),T=[];P.forEach(FA=>{FA.length===29?(T.push(FA.slice(0,15)),T.push(FA.slice(14,29))):FA.length===17?(T.push(FA.slice(0,10)),T.push(FA.slice(9,17))):T.push(FA)});const O=T.flat(),W={minX:O.length>0?Math.min(...O.map(FA=>FA[0])):0,maxX:O.length>0?Math.max(...O.map(FA=>FA[0])):0,minY:O.length>0?Math.min(...O.map(FA=>FA[1])):0,maxY:O.length>0?Math.max(...O.map(FA=>FA[1])):0},AA=(W.minX+W.maxX)/2,oA=(W.minY+W.maxY)/2;let IA=-AA,tA=-oA;const sA=v.anchor_alignment||"center";sA.includes("left")?IA=-W.minX:sA.includes("right")&&(IA=-W.maxX),sA.includes("top")?tA=-W.maxY:sA.includes("bottom")&&(tA=-W.minY);const aA=[];let dA=v.ccw_rotation??0;if(v.layer==="bottom"&&(aA.push(Mx(AA,oA),{a:-1,b:0,c:0,d:1,e:0,f:0},Mx(-AA,-oA)),dA=-dA),dA){const FA=dA*Math.PI/180;aA.push(Mx(AA,oA),tVA(FA),Mx(-AA,-oA))}const SA=aA.length>0?eVA(...aA):void 0;T.forEach(FA=>{D.beginPath(),FA.forEach((MA,qA)=>{let CA={x:MA[0],y:MA[1]};SA&&(CA=$ZA(SA,CA));const GA=CA.x+IA+v.anchor_position.x,uA=CA.y+tA+v.anchor_position.y,TA=x(GA),$A=F(uA);qA===0?D.moveTo(TA,$A):D.lineTo(TA,$A)}),D.stroke()})});const k=new uM(f);return k.generateMipmaps=!0,k.minFilter=fu,k.magFilter=ZB,k.anisotropy=16,k.needsUpdate=!0,k}function nVA(t){return t&&t.route_type==="wire"&&typeof t.layer=="string"&&typeof t.width=="number"}function I_({layer:t,circuitJson:A,boardData:e,traceColor:i,traceTextureResolution:o}){const n=mi(A).pcb_trace.list(),s=mi(A).pcb_via.list(),r=mi(A).pcb_plated_hole.list(),a=n.filter(Q=>Q.route.some(E=>nVA(E)&&E.layer===t));if(a.length===0)return null;const g=rF(e),I=document.createElement("canvas"),c=Math.floor(g.width*o),B=Math.floor(g.height*o);I.width=c,I.height=B;const C=I.getContext("2d");if(!C)return null;t==="bottom"&&(C.translate(0,B),C.scale(1,-1)),a.forEach(Q=>{let E=!0;C.beginPath(),C.strokeStyle=i,C.lineCap="round",C.lineJoin="round";let h=0;for(const u of Q.route){if(!nVA(u)||u.layer!==t){E||C.stroke(),E=!0;continue}const d=u.x,f=u.y;h=u.width*o,C.lineWidth=h;const m=(d-g.minX)*o,b=(g.maxY-f)*o;E?(C.moveTo(m,b),E=!1):C.lineTo(m,b)}E||C.stroke()}),C.globalCompositeOperation="destination-out",C.fillStyle="black",s.forEach(Q=>{const E=(Q.x-g.minX)*o,h=(g.maxY-Q.y)*o,u=Q.outer_diameter/2*o;C.beginPath(),C.arc(E,h,u,0,2*Math.PI,!1),C.fill()}),r.forEach(Q=>{if(Q.layers.includes(t)&&Q.shape==="circle"){const E=(Q.x-g.minX)*o,h=(g.maxY-Q.y)*o,u=Q.outer_diameter/2*o;C.beginPath(),C.arc(E,h,u,0,2*Math.PI,!1),C.fill()}else if(Q.layers.includes(t)&&Q.shape==="rotated_pill_hole_with_rect_pad"){const E=(Q.x-g.minX)*o,h=(g.maxY-Q.y)*o,u=(Q.rect_pad_width??Q.hole_width??0)*o,d=(Q.rect_pad_height??Q.hole_height??0)*o,m=-(Q.rect_ccw_rotation||0);m?(C.save(),C.translate(E,h),C.rotate(m*Math.PI/180),C.beginPath(),C.rect(-u/2,-d/2,u,d),C.fill(),C.restore()):(C.beginPath(),C.rect(E-u/2,h-d/2,u,d),C.fill())}}),C.globalCompositeOperation="source-over";const l=new uM(I);return l.generateMipmaps=!0,l.minFilter=fu,l.magFilter=ZB,l.anisotropy=16,l.needsUpdate=!0,l}var Tut=_r(UBA());function b5(t,A){if(t===void 0)return A;if(typeof t=="number")return t;const e=parseFloat(t.replace(/mm$/,""));return isNaN(e)?A:e}function Kut(t){return t.layer==="bottom"?t.is_mirrored!==!1:t.is_mirrored===!0}function qut(t){const A=t.flat();if(A.length===0)return{minX:0,maxX:0,minY:0,maxY:0,width:0,height:0,centerX:0,centerY:0};const e=Math.min(...A.map(s=>s[0])),i=Math.max(...A.map(s=>s[0])),o=Math.min(...A.map(s=>s[1])),n=Math.max(...A.map(s=>s[1]));return{minX:e,maxX:i,minY:o,maxY:n,width:i-e,height:n-o,centerX:(e+i)/2,centerY:(o+n)/2}}function Put(t){const A=[];return t.forEach(e=>{e.length===29?(A.push(e.slice(0,15)),A.push(e.slice(14,29))):e.length===17?(A.push(e.slice(0,10)),A.push(e.slice(9,17))):A.push(e)}),A}function Out(t,A){let e=-t.centerX,i=-t.centerY;return A.includes("left")?e=-t.minX:A.includes("right")&&(e=-t.maxX),A.includes("top")?i=-t.maxY:A.includes("bottom")&&(i=-t.minY),{x:e,y:i}}function Wut(t,A){const e=[];let i=t.ccw_rotation??0;if(Kut(t)&&(e.push(Mx(A.centerX,A.centerY),{a:-1,b:0,c:0,d:1,e:0,f:0},Mx(-A.centerX,-A.centerY)),i=-i),i){const s=i*Math.PI/180;e.push(Mx(A.centerX,A.centerY),tVA(s),Mx(-A.centerX,-A.centerY))}return{matrix:e.length>0?eVA(...e):void 0,rotationDeg:i}}function sVA(t,A,e,i,o,n,s){A.forEach(r=>{t.beginPath(),r.forEach((a,g)=>{let I={x:a[0],y:a[1]};e&&(I=$ZA(e,I));const c=I.x+i.x+o.x,B=I.y+i.y+o.y,C=n(c),l=s(B);g===0?t.moveTo(C,l):t.lineTo(C,l)}),t.stroke()})}function Zut(t,A,e,i,o,n){t.save(),t.translate(A,e),t.rotate(-n),t.fillRect(-i/2,-o/2,i,o),t.restore()}function Vut(t,A,e,i,o,n,s,r,a,g){const I=typeof A.font_size=="number"?A.font_size:.2,c={left:b5(A.knockout_padding?.left,I*.5),right:b5(A.knockout_padding?.right,I*.5),top:b5(A.knockout_padding?.top,I*.3),bottom:b5(A.knockout_padding?.bottom,I*.3)},B=i.width+c.left+c.right,C=i.height+c.top+c.bottom,l=s(A.anchor_position.x),Q=r(A.anchor_position.y),E=B*a,h=C*a;t.fillStyle=g;const u=n*Math.PI/180;Zut(t,l,Q,E,h,u);const d={x:-i.centerX,y:-i.centerY};t.globalCompositeOperation="destination-out",sVA(t,e,o,d,A.anchor_position,s,r),t.globalCompositeOperation="source-over"}function x5({layer:t,circuitJson:A,boardData:e,copperColor:i="rgb(230, 153, 51)",traceTextureResolution:o}){const s=A.filter(Q=>Q.type==="pcb_copper_text").filter(Q=>Q.layer===t);if(s.length===0)return null;const r=rF(e),a=document.createElement("canvas"),g=Math.floor(r.width*o),I=Math.floor(r.height*o);a.width=g,a.height=I;const c=a.getContext("2d");if(!c)return null;t==="bottom"&&(c.translate(0,I),c.scale(1,-1)),c.strokeStyle=i,c.fillStyle=i;const B=Q=>(Q-r.minX)*o,C=Q=>(r.maxY-Q)*o;s.forEach(Q=>{const E=typeof Q.font_size=="number"?Q.font_size:.2,h=Math.max(.02,E*.08)*o;c.lineWidth=h,c.lineCap="round",c.lineJoin="round";const u=(0,Tut.vectorText)({height:E*.45,input:Q.text}),d=Put(u),f=qut(d),{matrix:m,rotationDeg:b}=Wut(Q,f);if(Q.is_knockout)Vut(c,Q,d,f,m,b,B,C,o,i);else{const D=Q.anchor_alignment||"center",x=Out(f,D);sVA(c,d,m,x,Q.anchor_position,B,C)}});const l=new uM(a);return l.generateMipmaps=!0,l.minFilter=fu,l.magFilter=ZB,l.anisotropy=16,l.needsUpdate=!0,l}function k5({layer:t,circuitJson:A,panelData:e,outlineColor:i="black",traceTextureResolution:o}){const n=mi(A).pcb_board.list().filter(C=>C.pcb_panel_id===e.pcb_board_id);if(n.length===0)return null;const s=document.createElement("canvas"),r=Math.floor(e.width*o),a=Math.floor(e.height*o);s.width=r,s.height=a;const g=s.getContext("2d");if(!g)return null;t==="bottom"&&(g.translate(0,a),g.scale(1,-1)),g.strokeStyle=i,g.lineWidth=.05*o;const I=C=>(C-e.center.x+e.width/2)*o,c=C=>(-(C-e.center.y)+e.height/2)*o;n.forEach(C=>{if(C.outline&&C.outline.length>=2)g.beginPath(),C.outline.forEach((l,Q)=>{const E=I(l.x),h=c(l.y);Q===0?g.moveTo(E,h):g.lineTo(E,h)}),g.closePath(),g.stroke();else{const l=C.width,Q=C.height,{x:E,y:h}=C.center,u=I(E-l/2),d=c(h+Q/2);g.strokeRect(u,d,l*o,Q*o)}});const B=new uM(s);return B.generateMipmaps=!0,B.minFilter=fu,B.magFilter=ZB,B.anisotropy=16,B.needsUpdate=!0,B}function jut({circuitJson:t,pcbThickness:A,isFaux:e=!1}){const{rootObject:i}=ku(),{visibility:o}=WN(),n=$.useMemo(()=>{const r=t.filter(I=>I.type==="pcb_panel"),a=mi(t).pcb_board.list();if(r.length>0){const I=r[0],c=a.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:c?.thickness??1.4,material:c?.material??"fr4",num_layers:c?.num_layers??2}}const g=a.filter(I=>!I.pcb_panel_id);return g.length>0?g[0]:null},[t]),s=$.useMemo(()=>{if(!n||!n.width||!n.height)return null;const r=KZA[n.material]??Go.fr4SolderMaskGreen,a=`rgb(${Math.round(r[0]*255)}, ${Math.round(r[1]*255)}, ${Math.round(r[2]*255)})`,g="rgb(255,255,255)",I=Go.fr4TracesWithMaskGreen,c=`rgb(${Math.round(I[0]*255)}, ${Math.round(I[1]*255)}, ${Math.round(I[2]*255)})`;return{topSoldermask:m5({layer:"top",circuitJson:t,boardData:n,soldermaskColor:a,traceTextureResolution:Qc}),bottomSoldermask:m5({layer:"bottom",circuitJson:t,boardData:n,soldermaskColor:a,traceTextureResolution:Qc}),topSilkscreen:S5({layer:"top",circuitJson:t,boardData:n,silkscreenColor:g,traceTextureResolution:Qc}),bottomSilkscreen:S5({layer:"bottom",circuitJson:t,boardData:n,silkscreenColor:g,traceTextureResolution:Qc}),topTraceWithMask:I_({layer:"top",circuitJson:t,boardData:n,traceColor:c,traceTextureResolution:Qc}),bottomTraceWithMask:I_({layer:"bottom",circuitJson:t,boardData:n,traceColor:c,traceTextureResolution:Qc}),topCopperText:x5({layer:"top",circuitJson:t,boardData:n,copperColor:`rgb(${Math.round(Go.copper[0]*255)}, ${Math.round(Go.copper[1]*255)}, ${Math.round(Go.copper[2]*255)})`,traceTextureResolution:Qc}),bottomCopperText:x5({layer:"bottom",circuitJson:t,boardData:n,copperColor:`rgb(${Math.round(Go.copper[0]*255)}, ${Math.round(Go.copper[1]*255)}, ${Math.round(Go.copper[2]*255)})`,traceTextureResolution:Qc}),topPanelOutlines:k5({layer:"top",circuitJson:t,panelData:n,traceTextureResolution:Qc}),bottomPanelOutlines:k5({layer:"bottom",circuitJson:t,panelData:n,traceTextureResolution:Qc})}},[t,n]);return $.useEffect(()=>{if(!i||!n||!s)return;const r=[],a=(I,c,B,C,l=!1,Q=!1)=>{if(!I)return null;const E=rF(n),h=new Cw(E.width,E.height),u=new pd({map:I,transparent:!0,side:JC,depthWrite:Q,polygonOffset:l,polygonOffsetFactor:l?-1:0,polygonOffsetUnits:l?-1:0,opacity:e?d5:1}),d=new Wo(h,u);return d.position.set(E.centerX,E.centerY,c),B&&d.rotation.set(Math.PI,0,0),d.name=C,d},g=.001;if(o.topMask){const I=a(s.topSoldermask,A/2+g,!1,"jscad-top-soldermask",!0);I&&(r.push(I),i.add(I))}if(o.bottomMask){const I=a(s.bottomSoldermask,-A/2-g,!0,"jscad-bottom-soldermask",!0);I&&(r.push(I),i.add(I))}if(o.topCopper&&o.topMask){const I=a(s.topTraceWithMask,A/2+$a.traces+.004,!1,"jscad-top-trace-with-mask");I&&(r.push(I),i.add(I))}if(o.bottomCopper&&o.bottomMask){const I=a(s.bottomTraceWithMask,-A/2-$a.traces-.005,!0,"jscad-bottom-trace-with-mask");I&&(r.push(I),i.add(I))}if(o.topSilkscreen){const I=a(s.topSilkscreen,A/2+g+.002,!1,"jscad-top-silkscreen");I&&(r.push(I),i.add(I))}if(o.bottomSilkscreen){const I=a(s.bottomSilkscreen,-A/2-g-.002,!0,"jscad-bottom-silkscreen");I&&(r.push(I),i.add(I))}if(o.topCopper){const I=a(s.topCopperText,A/2+$a.copper,!1,"jscad-top-copper-text");I&&(r.push(I),i.add(I))}if(o.bottomCopper){const I=a(s.bottomCopperText,-A/2-$a.copper,!0,"jscad-bottom-copper-text");I&&(r.push(I),i.add(I))}if(o.boardBody){const I=a(s.topPanelOutlines,A/2+g+.003,!1,"jscad-top-panel-outlines",!1,!0);I&&(r.push(I),i.add(I));const c=a(s.bottomPanelOutlines,-A/2-g-.003,!0,"jscad-bottom-panel-outlines",!1,!0);c&&(r.push(c),i.add(c))}return()=>{r.forEach(I=>{I.parent===i&&i.remove(I),I.geometry.dispose(),I.material instanceof Yp&&I.material.dispose()})}},[i,n,s,A,o]),null}function zut(t){const A=mi(t).cad_component.list(),e=mi(t).pcb_smtpad.list(),i=mi(t).pcb_hole.list(),o=mi(t).pcb_plated_hole.list(),n=mi(t).pcb_via.list();if(A.length===0&&e.length===0&&i.length===0&&o.length===0&&n.length===0)return null;const s=[...i,...o,...n,...e],r=d2(s);let a=r.minX,g=r.maxX,I=r.minY,c=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),I=Math.min(I,f),c=Math.max(c,f)}a===1/0&&(a=-10,g=10,I=-10,c=10);const B=2,C=Math.max(Math.abs(a),Math.abs(g))+B,l=Math.max(Math.abs(I),Math.abs(c))+B,Q=Math.max(2*C,10),E=Math.max(2*l,10);return{type:"pcb_board",pcb_board_id:"faux-board",center:{x:0,y:0},width:Q,height:E,thickness:1.4,material:"fr4",num_layers:2}}function rVA(t){if(mi(t).pcb_board.list().length>0)return t;const e=zut(t);if(!e)return t;const o=e.thickness/2;return[...t.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+o}}}}return s}),e]}var Xut=$.forwardRef(({circuitJson:t,children:A,autoRotateDisabled:e,clickToInteractEnabled:i,onUserInteraction:o,onCameraControllerReady:n},s)=>{const r=TZA(A),a=$.useMemo(()=>rVA(t??r),[t,r]),g=kut(a),I=$.useMemo(()=>{if(!a)return[5,-5,5];try{const h=mi(a).pcb_board.list()[0];if(!h)return[5,-5,5];const{width:u,height:d}=h;if(!u&&!d)return[5,-5,5];const f=5,m=Math.max(u,f),b=Math.max(d,f),D=Math.max(m,b);return[D*.4,-D*.7,D*.9]}catch(h){return console.error(h),[5,-5,5]}},[a]),c=$.useMemo(()=>{if(!a)return!1;try{const h=mi(a).pcb_board.list()[0];return!!h&&h.pcb_board_id==="faux-board"}catch{return!1}},[a]),B=$.useMemo(()=>{if(a)try{const h=mi(a).pcb_board.list()[0];return h?{width:h.width??0,height:h.height??0}:void 0}catch(h){console.error(h);return}},[a]),C=$.useMemo(()=>{if(a)try{const h=mi(a).pcb_board.list()[0];return!h||!h.center?void 0:{x:h.center.x,y:h.center.y}}catch(h){console.error(h);return}},[a]),l=gWA(a),{stls:Q}=sut(g),E=mi(a).cad_component.list();return V.jsxs(JZA,{ref:s,autoRotateDisabled:e,initialCameraPosition:I,clickToInteractEnabled:i,boardDimensions:B,boardCenter:C,onUserInteraction:o,onCameraControllerReady:n,children:[Q.map(({stlData:h,color:u,layerType:d},f)=>V.jsx(Mut,{stlData:h,color:u,opacity:f===0?c?.8:.95:1,layerType:d},`board-${f}`)),V.jsx(jut,{circuitJson:a,pcbThickness:l,isFaux:c}),E.map(h=>V.jsx(XZA,{fallback:({error:u})=>V.jsx(zZA,{cad_component:h,error:u}),children:V.jsx(vZA,{cad_component:h,circuitJson:a},h.cad_component_id)},h.cad_component_id))]})}),$ut=t=>{let A=0;for(let i=0;i<t.length;i++){const o=(i+1)%t.length;t[i]&&t[o]&&(A+=t[i][0]*t[o][1],A-=t[o][0]*t[i][1])}return A/2<=0};function Adt(t,A,e,i,o){let n,s=null;if(e.outline&&e.outline.length>=3){let r=e.outline.map(g=>[g.x,g.y]);$ut(r)&&(r=r.reverse());const a=A.ofPolygons([r]);o.push(a),s=a,n=t.extrude(a,i,void 0,void 0,void 0,!0),o.push(n)}else e.outline&&e.outline.length>0&&console.warn("Board outline has fewer than 3 points, falling back to rectangular board."),n=t.cube([e.width,e.height,i],!0),o.push(n),n=n.translate([e.center.x,e.center.y,0]),o.push(n);return{boardOp:n,outlineCrossSection:s}}var edt=64;function kd({Manifold:t,width:A,height:e,thickness:i,borderRadius:o}){const n=i0(A,e,o);if(n<=0)return t.cube([A,e,i],!0);const s=[],r=A-2*n,a=e-2*n;return r>0&&s.push(t.cube([r,e,i],!0)),a>0&&s.push(t.cube([A,a,i],!0)),[[A/2-n,e/2-n],[-A/2+n,e/2-n],[-A/2+n,-e/2+n],[A/2-n,-e/2+n]].forEach(([I,c])=>{s.push(t.cylinder(i,n,n,edt,!0).translate([I,c,0]))}),t.union(s)}function tdt({Manifold:t,pad:A,padBaseThickness:e}){if(A.shape==="rect"){const i=kl(A);return kd({Manifold:t,width:A.width,height:A.height,thickness:e,borderRadius:i})}else if(A.shape==="rotated_rect"){const i=kl(A);let o=kd({Manifold:t,width:A.width,height:A.height,thickness:e,borderRadius:i});const n=A.ccw_rotation??0;return n&&(o=o.rotate([0,0,n])),o}else if(A.shape==="circle"&&A.radius)return t.cylinder(e,A.radius,-1,32,!0);return null}var idt=t=>{let A=0;for(let i=0;i<t.length;i++){const o=(i+1)%t.length;t[i]&&t[o]&&(A+=t[i][0]*t[o][1],A-=t[o][0]*t[i][1])}return A/2<=0};function odt(t,A,e,i,o){const n=[],s=mi(e).pcb_cutout.list();for(const r of s){let a;const g=i*1.5;switch(r.shape){case"rect":{const B=kl(r);if(typeof B=="number"&&B>0?a=kd({Manifold:t,width:r.width,height:r.height,thickness:g,borderRadius:B}):a=t.cube([r.width,r.height,g],!0),o.push(a),r.rotation){const C=a.rotate([0,0,r.rotation]);o.push(C),a=C}a=a.translate([r.center.x,r.center.y,0]),o.push(a);break}case"circle":a=t.cylinder(g,r.radius,-1,KC,!0),o.push(a),a=a.translate([r.center.x,r.center.y,0]),o.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 I=r.points.map(B=>[B.x,B.y]);idt(I)&&(I=I.reverse());const c=A.ofPolygons([I]);o.push(c),a=t.extrude(c,g,0,0,[1,1],!0),o.push(a);break;default:console.warn(`Unsupported cutout shape: ${r.shape} for cutout ${r.pcb_cutout_id}`);continue}a&&n.push(a)}return{cutoutOps:n}}function aVA({Manifold:t,x:A,y:e,diameter:i,thickness:o,segments:n=32}){return t.cylinder(o*1.2,i/2,i/2,n,!0).translate([A,e,0])}function gVA({Manifold:t,x:A,y:e,holeDiameter:i,thickness:o,zOffset:n=.001,segments:s=32}){const r=i/2+n;return t.cylinder(o*1.2,r,r,s,!0).translate([A,e,0])}function ndt(t,A,e,i,o){const n=[],s=mi(e).pcb_hole.list(),r=(g,I,c)=>{const B=kd({Manifold:t,width:g,height:I,thickness:c,borderRadius:Math.min(g,I)/2});return o.push(B),B},a=(g,I,c)=>{const B=[];for(let C=0;C<c;C++){const l=2*Math.PI*C/c;B.push([g/2*Math.cos(l),I/2*Math.sin(l)])}return B};return s.forEach(g=>{const I=g.hole_shape,c=g.x,B=g.y,C=i*1.2,l=g.ccw_rotation??g.rotation??0,Q=g.hole_width??g.hole_diameter,E=g.hole_height??g.hole_diameter;let h=null;if(I==="circle"){h=aVA({Manifold:t,x:c,y:B,diameter:g.hole_diameter,thickness:i,segments:KC}),n.push(h),o.push(h);return}if(I==="pill"||I==="rotated_pill")h=r(Q,E,C);else if(I==="oval"){let u=a(Q,E,KC),d=0;for(let m=0;m<u.length;m++){const b=(m+1)%u.length;d+=u[m][0]*u[b][1],d-=u[b][0]*u[m][1]}d<=0&&(u=u.reverse());const f=A.ofPolygons([u]);o.push(f),h=t.extrude(f,C,0,0,[1,1],!0),o.push(h)}if(h){if(l!==0){const d=h.rotate([0,0,l]);o.push(d),h=d}const u=h.translate([c,B,0]);o.push(u),n.push(u)}}),{nonPlatedHoleBoardDrills:n}}function mw(t){const A=new dg;if(A.setAttribute("position",new vn(t.vertProperties,3)),A.setIndex(new fz(t.triVerts,1)),t.runIndex&&t.runIndex.length>1&&t.runOriginalID)for(let e=0;e<t.runIndex.length-1;e++){const i=t.runIndex[e],o=t.runIndex[e+1]-i;A.addGroup(i,o,0)}else A.addGroup(0,t.triVerts.length,0);return A}var EL=t=>{let A=0;for(let i=0;i<t.length;i++){const o=(i+1)%t.length;t[i]&&t[o]&&(A+=t[i][0]*t[o][1],A-=t[o][0]*t[i][1])}return A/2<=0},G5=(t,A,e)=>{const i=[];for(let o=0;o<e;o++){const n=2*Math.PI*o/e;i.push([t/2*Math.cos(n),A/2*Math.sin(n)])}return i},aF=new Li(...Go.copper),F5=.05;function sdt(t,A,e,i,o,n){const s=[],r=mi(e).pcb_plated_hole.list(),a=[],g=[],I=(l,Q,E)=>{const h=kd({Manifold:t,width:l,height:Q,thickness:E,borderRadius:Math.min(l,Q)/2});return o.push(h),h},c=({padOutline:l,thickness:Q})=>{if(!Array.isArray(l)||l.length<3)return null;let E=l.map(d=>[d.x,d.y]);EL(E)&&(E=E.reverse());const h=A.ofPolygons([E]);o.push(h);const u=t.extrude(h,Q,0,0,[1,1],!0);return o.push(u),u},B=({ph:l,depth:Q,sizeDelta:E=0})=>{if(l.shape!=="hole_with_polygon_pad")return null;const u=l.pad_outline;if(!Array.isArray(u)||u.length<3)return null;const d=l.hole_shape||"circle",f=l.hole_offset_x||0,m=l.hole_offset_y||0;let b=null;if(d==="circle"){const D=Math.max((l.hole_diameter??0)+E,wo),x=Math.max(D/2,wo/2);b=t.cylinder(Q,x,x,KC,!0),o.push(b)}else{const D=l.hole_width??l.hole_diameter,x=l.hole_height??l.hole_diameter;if(!D||!x)return null;const F=Math.max(D+E,wo),k=Math.max(x+E,wo);if(d==="oval"){let v=G5(F,k,KC);EL(v)&&(v=v.reverse());const _=A.ofPolygons([v]);o.push(_),b=t.extrude(_,Q,0,0,[1,1],!0),o.push(b)}else(d==="pill"||d==="rotated_pill")&&(b=kd({Manifold:t,width:F,height:k,thickness:Q,borderRadius:Math.min(F,k)/2}),o.push(b))}if(!b)return null;if(f||m){const D=b.translate([f,m,0]);o.push(D),b=D}return b};r.forEach((l,Q)=>{if(l.shape==="circle"){const E=gVA({Manifold:t,x:l.x,y:l.y,holeDiameter:l.hole_diameter*1.02,thickness:i,zOffset:zp,segments:KC});o.push(E),s.push(E);const h=i+2*zp,u=t.cylinder(h,l.outer_diameter/2,l.outer_diameter/2,KC,!0);o.push(u);const d=t.cylinder(h*1.05,l.hole_diameter/2,l.hole_diameter/2,KC,!0);o.push(d);const f=u.subtract(d);o.push(f);const m=f.translate([l.x,l.y,0]);o.push(m);let b=m;if(n){const x=t.intersection([m,n]);o.push(x),b=x}g.push(b);const D=mw(b.getMesh());a.push({key:`ph-${l.pcb_plated_hole_id||Q}`,geometry:D,color:aF})}else if(l.shape==="pill"){const E=l.hole_width,h=l.hole_height,u=.4,d=l.outer_width??E+u,f=l.outer_height??h+u,m=E+2*zp,b=h+2*zp,D=i*1.2;let x=I(m,b,D);if(l.ccw_rotation){const W=x.rotate([0,0,l.ccw_rotation]);o.push(W),x=W}const F=x.translate([l.x,l.y,0]);o.push(F),s.push(F);const k=i+2*zp,v=I(d,f,k),_=I(E,h,k*1.05);let Y=v.subtract(_);if(o.push(Y),l.ccw_rotation){const W=Y.rotate([0,0,l.ccw_rotation]);o.push(W),Y=W}const P=Y.translate([l.x,l.y,0]);o.push(P);let T=P;if(n){const W=t.intersection([P,n]);o.push(W),T=W}g.push(T);const O=mw(T.getMesh());a.push({key:`ph-${l.pcb_plated_hole_id||Q}`,geometry:O,color:aF})}else if(l.shape==="pill_hole_with_rect_pad"){if(l.hole_shape&&l.hole_shape!=="pill"||l.pad_shape&&l.pad_shape!=="rect")return;const E=l.hole_width,h=l.hole_height,u=l.hole_offset_x||0,d=l.hole_offset_y||0,f=l.rect_pad_width,m=l.rect_pad_height,b=kl(l),D=BL,x=E+2*zp,F=h+2*zp,k=i*1.2,_=I(x,F,k).translate([u,d,0]).translate([l.x,l.y,0]);o.push(_),s.push(_);const Y=kd({Manifold:t,width:f,height:m,thickness:i-2*D-2*$a.copper+.1,borderRadius:b});o.push(Y);const P=kd({Manifold:t,width:f,height:m,thickness:D,borderRadius:b}).translate([0,0,i/2/2+$a.copper]),T=kd({Manifold:t,width:f,height:m,thickness:D,borderRadius:b}).translate([0,0,-i/2/2-$a.copper]);o.push(P,T);const O=I(E,h,i*1.02).translate([u,d,0]);o.push(O);const W=t.union([Y,P,T,O]);o.push(W);const AA=I(Math.max(E-2*F5,.01),Math.max(h-2*F5,.01),i*1.2).translate([u,d,0]);o.push(AA);const oA=W.subtract(AA);o.push(oA);const IA=oA.translate([l.x,l.y,0]);o.push(IA);let tA=IA;if(n){const aA=t.intersection([IA,n]);o.push(aA),tA=aA}g.push(tA);const sA=mw(tA.getMesh());a.push({key:`ph-${l.pcb_plated_hole_id||Q}`,geometry:sA,color:aF})}else if(l.shape==="rotated_pill_hole_with_rect_pad"){if(l.hole_shape&&l.hole_shape!=="rotated_pill"||l.pad_shape&&l.pad_shape!=="rect")return;const E=l.hole_width,h=l.hole_height,u=l.hole_offset_x||0,d=l.hole_offset_y||0,f=l.rect_pad_width,m=l.rect_pad_height,b=kl(l),D=BL,x=E+2*zp,F=h+2*zp,k=i*1.2;let v=I(x,F,k).translate([u,d,0]);if(l.hole_ccw_rotation){const aA=v.rotate([0,0,l.hole_ccw_rotation]);o.push(aA),v=aA}const _=v.translate([l.x,l.y,0]);o.push(_),s.push(_);let Y=kd({Manifold:t,width:f,height:m,thickness:i-2*D-2*$a.copper+.1,borderRadius:b});if(o.push(Y),l.rect_ccw_rotation){const aA=Y.rotate([0,0,l.rect_ccw_rotation]);o.push(aA),Y=aA}let P=kd({Manifold:t,width:f,height:m,thickness:D,borderRadius:b}).translate([0,0,i/2/2+$a.copper]);if(l.rect_ccw_rotation){const aA=P.rotate([0,0,l.rect_ccw_rotation]);o.push(aA),P=aA}let T=kd({Manifold:t,width:f,height:m,thickness:D,borderRadius:b}).translate([0,0,-i/2/2-$a.copper]);if(l.rect_ccw_rotation){const aA=T.rotate([0,0,l.rect_ccw_rotation]);o.push(aA),T=aA}o.push(P,T);let O=I(E,h,i*1.02).translate([u,d,0]);if(l.hole_ccw_rotation){const aA=O.rotate([0,0,l.hole_ccw_rotation]);o.push(aA),O=aA}o.push(O);const W=t.union([Y,P,T,O]);o.push(W);let AA=I(Math.max(E-2*F5,.01),Math.max(h-2*F5,.01),i*1.2).translate([u,d,0]);if(l.hole_ccw_rotation){const aA=AA.rotate([0,0,l.hole_ccw_rotation]);o.push(aA),AA=aA}o.push(AA);const oA=W.subtract(AA);o.push(oA);const IA=oA.translate([l.x,l.y,0]);o.push(IA);let tA=IA;if(n){const aA=t.intersection([IA,n]);o.push(aA),tA=aA}g.push(tA);const sA=mw(tA.getMesh());a.push({key:`ph-${l.pcb_plated_hole_id||Q}`,geometry:sA,color:aF})}else if(l.shape==="hole_with_polygon_pad"){const E=l.pad_outline;if(!Array.isArray(E)||E.length<3)return;const h=B({ph:l,depth:i*1.2,sizeDelta:2*wo});if(!h)return;const u=h.translate([l.x,l.y,0]);o.push(u),s.push(u);const d=BL,f=Math.max(i-2*d-2*$a.copper+.1,wo),m=c({padOutline:E,thickness:f}),b=c({padOutline:E,thickness:d}),D=c({padOutline:E,thickness:d});if(!m||!b||!D)return;const x=b.translate([0,0,i/2/2+$a.copper]),F=D.translate([0,0,-i/2/2-$a.copper]);o.push(x,F);const k=B({ph:l,depth:i*1.02});if(!k)return;const v=B({ph:l,depth:i*1.2,sizeDelta:-2*wo})||k,_=t.union([m,x,F,k]);o.push(_);const Y=_.subtract(v);o.push(Y);const P=Y.translate([l.x,l.y,0]);o.push(P);let T=P;if(n){const W=t.intersection([P,n]);o.push(W),T=W}g.push(T);const O=mw(T.getMesh());a.push({key:`ph-${l.pcb_plated_hole_id||Q}`,geometry:O,color:aF})}else if(l.shape==="oval"){const E=l.hole_width,h=l.hole_height,u=l.outer_width??E+.4,d=l.outer_height??h+.4,f=E+2*zp,m=h+2*zp,b=i*1.2;let D=G5(f,m,KC);EL(D)&&(D=D.reverse());const x=A.ofPolygons([D]);o.push(x);let F=t.extrude(x,b,0,0,[1,1],!0);if(o.push(F),l.ccw_rotation){const sA=F.rotate([0,0,l.ccw_rotation]);o.push(sA),F=sA}const k=F.translate([l.x,l.y,0]);o.push(k),s.push(k);const v=i+2*zp;let _=G5(u,d,KC);EL(_)&&(_=_.reverse());const Y=A.ofPolygons([_]);o.push(Y);const P=t.extrude(Y,v,0,0,[1,1],!0);o.push(P);let T=G5(E,h,KC);EL(T)&&(T=T.reverse());const O=A.ofPolygons([T]);o.push(O);const W=t.extrude(O,v*1.05,0,0,[1,1],!0);o.push(W);let AA=P.subtract(W);if(o.push(AA),l.ccw_rotation){const sA=AA.rotate([0,0,l.ccw_rotation]);o.push(sA),AA=sA}const oA=AA.translate([l.x,l.y,0]);o.push(oA);let IA=oA;if(n){const sA=t.intersection([oA,n]);o.push(sA),IA=sA}g.push(IA);const tA=mw(IA.getMesh());a.push({key:`ph-${l.pcb_plated_hole_id||Q}`,geometry:tA,color:aF})}else if(l.shape==="circular_hole_with_rect_pad"){if(l.hole_shape&&l.hole_shape!=="circle"||l.pad_shape&&l.pad_shape!=="rect")return;const E=l.hole_offset_x||0,h=l.hole_offset_y||0,u=aVA({Manifold:t,x:l.x+E,y:l.y+h,diameter:l.hole_diameter,thickness:i,segments:KC});o.push(u),s.push(u);const d=l.rect_pad_width??l.hole_diameter,f=l.rect_pad_height??l.hole_diameter,m=kl(l),b=BL,D=l.hole_diameter/2,x=kd({Manifold:t,width:d,height:f,thickness:i-2*b-2*$a.copper+.1,borderRadius:m});o.push(x);const F=kd({Manifold:t,width:d,height:f,thickness:b,borderRadius:m}).translate([0,0,i/2/2+$a.copper]),k=kd({Manifold:t,width:d,height:f,thickness:b,borderRadius:m}).translate([0,0,-i/2/2-$a.copper]);o.push(F,k);const v=t.cylinder(i*1.02,D,D,KC,!0).translate([E,h,0]);o.push(v);const _=t.union([x,F,k,v]);o.push(_);const Y=t.cylinder(i*1.2,Math.max(D-wo,.01),Math.max(D-wo,.01),KC,!0).translate([E,h,0]);o.push(Y);const P=_.subtract(Y);o.push(P);const T=P.translate([l.x,l.y,0]);o.push(T);let O=T;if(n){const AA=t.intersection([T,n]);o.push(AA),O=AA}g.push(O);const W=mw(O.getMesh());a.push({key:`ph-${l.pcb_plated_hole_id||Q}`,geometry:W,color:aF})}});let C;return g.length>0&&(C=t.union(g),o.push(C)),{platedHoleBoardDrills:s,platedHoleCopperGeoms:a,platedHoleSubtractOp:C}}var rdt=new Li(...Go.copper);function adt(t,A,e,i,o,n){const s=[];return mi(A).pcb_smtpad.list().forEach((a,g)=>{const I=BL,c=a.layer==="bottom"?-e/2-$a.copper:e/2+$a.copper;let B=tdt({Manifold:t,pad:a,padBaseThickness:I});if(B){i.push(B);const C=B.translate([a.x,a.y,c]);i.push(C);let l=C;if(o&&(l=C.subtract(o),i.push(l)),n){const E=t.intersection([l,n]);i.push(E),l=E}const Q=mw(l.getMesh());s.push({key:`smt_pad-${a.layer||"top"}-${a.pcb_smtpad_id||g}`,geometry:Q,color:rdt})}}),{smtPadGeoms:s}}function gdt({Manifold:t,x:A,y:e,outerDiameter:i,holeDiameter:o,thickness:n,zOffset:s=.001,segments:r=32}){const a=s,g=s;if(i<o)throw new Error(`Invalid via geometry: outerDiameter (${i}) must be >= holeDiameter (${o})`);const I=Math.min(i/2,o/2+g),c=t.cylinder(n,I,-1,r,!0),B=t.cylinder(a,i/2,-1,r,!0).translate([0,0,n/2]),C=t.cylinder(a,i/2,-1,r,!0).translate([0,0,-n/2]),l=t.union([c,B,C]),Q=n+a*2,E=t.cylinder(Q,o/2,-1,r,!0);return l.subtract(E).translate([A,e,0])}var Idt=new Li(...Go.copper);function cdt(t,A,e,i,o){const n=[],s=mi(A).pcb_via.list(),r=[];return s.forEach((a,g)=>{if(typeof a.hole_diameter=="number"){const I=gVA({Manifold:t,x:a.x,y:a.y,holeDiameter:a.hole_diameter,thickness:e,zOffset:zp,segments:KC});i.push(I),n.push(I)}if(typeof a.outer_diameter=="number"&&typeof a.hole_diameter=="number"){const I=gdt({Manifold:t,x:a.x,y:a.y,outerDiameter:a.outer_diameter,holeDiameter:a.hole_diameter,thickness:e,zOffset:zp,segments:KC});i.push(I);let c=I;if(o){const C=t.intersection([I,o]);i.push(C),c=C}const B=mw(c.getMesh());r.push({key:`via-${a.pcb_via_id||g}`,geometry:B,color:Idt})}}),{viaBoardDrills:n,viaCopperGeoms:r}}function IVA({ctx:t,points:A,canvasXFromPcb:e,canvasYFromPcb:i}){A.length<3||(t.beginPath(),A.forEach((o,n)=>{const s=e(o[0]),r=i(o[1]);n===0?t.moveTo(s,r):t.lineTo(s,r)}),t.closePath(),t.fill())}function Bdt({ctx:t,pour:A,canvasXFromPcb:e,canvasYFromPcb:i}){const o=A.brep_shape;if(!o||!o.outer_ring)return;const n=w5(o.outer_ring,32);if(n.length>=3&&IVA({ctx:t,points:n,canvasXFromPcb:e,canvasYFromPcb:i}),o.inner_rings&&o.inner_rings.length>0){t.globalCompositeOperation="destination-out";for(const s of o.inner_rings){const r=w5(s,32);r.length>=3&&IVA({ctx:t,points:r,canvasXFromPcb:e,canvasYFromPcb:i})}t.globalCompositeOperation="source-over"}}function cVA({layer:t,circuitJson:A,boardData:e,traceTextureResolution:i=Qc}){const o=A.filter(h=>h.type==="pcb_copper_pour"),n=t==="top"?"top_copper":"bottom_copper",s=o.filter(h=>h.layer===t);if(s.length===0)return null;const r=rF(e),a=document.createElement("canvas"),g=Math.floor(r.width*i),I=Math.floor(r.height*i);a.width=g,a.height=I;const c=a.getContext("2d");if(!c)return null;t==="bottom"&&(c.translate(0,I),c.scale(1,-1));const B=h=>(h-r.minX)*i,C=h=>(r.maxY-h)*i,l=s.filter(h=>h.shape==="rect"||h.shape==="polygon"),Q=s.filter(h=>h.shape==="brep");if(l.length>0){const h=new Rtt(c);h.setCameraBounds({minX:r.minX,maxX:r.maxX,minY:r.minY,maxY:r.maxY});const u=l.filter(b=>b.covered_with_solder_mask!==!1),d=l.filter(b=>b.covered_with_solder_mask===!1),f=`rgb(${Go.fr4TracesWithMaskGreen.map(b=>b*255).join(",")})`,m=`rgb(${Go.copper.map(b=>b*255).join(",")})`;u.length>0&&(h.configure({colorOverrides:{copper:{top:f,bottom:f,inner1:f,inner2:f,inner3:f,inner4:f,inner5:f,inner6:f}}}),h.drawElements(u,{layers:[n]})),d.length>0&&(h.configure({colorOverrides:{copper:{top:m,bottom:m,inner1:m,inner2:m,inner3:m,inner4:m,inner5:m,inner6:m}}}),h.drawElements(d,{layers:[n]}))}for(const h of Q){const d=h.covered_with_solder_mask!==!1?Go.fr4TracesWithMaskGreen:Go.copper,f=`rgb(${d[0]*255}, ${d[1]*255}, ${d[2]*255})`;c.fillStyle=f,Bdt({ctx:c,pour:h,canvasXFromPcb:B,canvasYFromPcb:C})}const E=new uM(a);return E.generateMipmaps=!0,E.minFilter=fu,E.magFilter=ZB,E.anisotropy=16,E.needsUpdate=!0,E}function Xp(t,A){const{texture:e,yOffset:i,isBottomLayer:o,textureType:n,usePolygonOffset:s=!1,renderOrder:r=0,isFaux:a=!1}=t;if(!e)return null;const g=rF(A),I=new Cw(g.width,g.height),c=new pd({map:e,transparent:!0,side:JC,depthWrite:n==="panel-outlines",polygonOffset:s,polygonOffsetFactor:s?-4:0,polygonOffsetUnits:s?-4:0,opacity:a?d5:1}),B=new Wo(I,c);return B.position.set(g.centerX,g.centerY,i),o&&B.rotation.set(Math.PI,0,0),B.name=`${o?"bottom":"top"}-${n}-texture-plane`,B.renderOrder=r,B}function Cdt(t,A,e,i=!1){const o=[];if(!t||!A||e===null)return o;const n=Xp({texture:t.topTrace,yOffset:e/2+$a.traces,isBottomLayer:!1,textureType:"trace",usePolygonOffset:!1,renderOrder:2,isFaux:i},A);n&&o.push(n);const s=Xp({texture:t.topTraceWithMask,yOffset:e/2+$a.traces,isBottomLayer:!1,textureType:"trace-with-mask",usePolygonOffset:!1,renderOrder:2,isFaux:i},A);s&&o.push(s);const r=Xp({texture:t.topSilkscreen,yOffset:e/2+.003,isBottomLayer:!1,textureType:"silkscreen",usePolygonOffset:!1,renderOrder:3,isFaux:i},A);r&&o.push(r);const a=Xp({texture:t.bottomTrace,yOffset:-e/2-$a.traces,isBottomLayer:!0,textureType:"trace",usePolygonOffset:!1,renderOrder:2,isFaux:i},A);a&&o.push(a);const g=Xp({texture:t.bottomTraceWithMask,yOffset:-e/2-$a.traces,isBottomLayer:!0,textureType:"trace-with-mask",usePolygonOffset:!1,renderOrder:2,isFaux:i},A);g&&o.push(g);const I=Xp({texture:t.bottomSilkscreen,yOffset:-e/2-.003,isBottomLayer:!0,textureType:"silkscreen",usePolygonOffset:!1,renderOrder:3,isFaux:i},A);I&&o.push(I);const c=Xp({texture:t.topSoldermask,yOffset:e/2+.001,isBottomLayer:!1,textureType:"soldermask",usePolygonOffset:!0,renderOrder:1,isFaux:i},A);c&&o.push(c);const B=Xp({texture:t.bottomSoldermask,yOffset:-e/2-.001,isBottomLayer:!0,textureType:"soldermask",usePolygonOffset:!0,renderOrder:1,isFaux:i},A);B&&o.push(B);const C=Xp({texture:t.topCopperText,yOffset:e/2+$a.copper,isBottomLayer:!1,textureType:"copper-text",usePolygonOffset:!1,renderOrder:2,isFaux:i},A);C&&o.push(C);const l=Xp({texture:t.bottomCopperText,yOffset:-e/2-$a.copper,isBottomLayer:!0,textureType:"copper-text",usePolygonOffset:!1,renderOrder:2,isFaux:i},A);l&&o.push(l);const Q=Xp({texture:t.topCopper,yOffset:e/2+$a.copper,isBottomLayer:!1,textureType:"copper",usePolygonOffset:!1,renderOrder:2,isFaux:i},A);Q&&o.push(Q);const E=Xp({texture:t.bottomCopper,yOffset:-e/2-$a.copper,isBottomLayer:!0,textureType:"copper",usePolygonOffset:!1,renderOrder:2,isFaux:i},A);E&&o.push(E);const h=Xp({texture:t.topPanelOutlines,yOffset:e/2+.004,isBottomLayer:!1,textureType:"panel-outlines",usePolygonOffset:!1,renderOrder:4,isFaux:i},A);h&&o.push(h);const u=Xp({texture:t.bottomPanelOutlines,yOffset:-e/2-.004,isBottomLayer:!0,textureType:"panel-outlines",usePolygonOffset:!1,renderOrder:4,isFaux:i},A);return u&&o.push(u),o}var ldt=(t,A)=>{const[e,i]=$.useState(null),[o,n]=$.useState(null),[s,r]=$.useState(null),[a,g]=$.useState(null),[I,c]=$.useState(!0),B=$.useRef([]),C=$.useMemo(()=>{const Q=A.filter(u=>u.type==="pcb_panel"),E=mi(A).pcb_board.list();if(Q.length>0){const u=Q[0],d=E.find(f=>f.pcb_panel_id===u.pcb_panel_id);return{type:"pcb_board",pcb_board_id:u.pcb_panel_id,center:u.center,width:u.width,height:u.height,thickness:d?.thickness??1.4,material:d?.material??"fr4",num_layers:d?.num_layers??2}}const h=E.filter(u=>!u.pcb_panel_id);return h.length>0?h[0]:null},[A]),l=$.useMemo(()=>{const Q=mi(A).pcb_board.list();return Q.length>0&&Q[0].pcb_board_id==="faux-board"},[A]);return $.useEffect(()=>{if(!t||!C){i(null),n(null),r(null),c(!1);return}if((C.width===0||!C.width)&&(C.height===0||!C.height)&&(!C.outline||C.outline.length<3)){i({platedHoles:[],smtPads:[],vias:[]}),n({}),r(C.thickness??0),c(!1);return}c(!0),g(null);const Q=t.Manifold,E=t.CrossSection,h=m=>{if(!(!m||typeof m.delete!="function"))try{m.delete()}catch(b){(!(b instanceof Error)||!b.message?.includes("Manifold instance already deleted"))&&console.warn("Failed to delete Manifold instance",b)}};B.current.forEach(h),B.current=[];let u=null;const d={},f={};try{const m=C.thickness||1.4;r(m);const{boardOp:b,outlineCrossSection:D}=Adt(Q,E,C,m,B.current);let x=b;const k=m+2*1;let v=null;const _=.01;if(D){let TA=D;if(_>0){const ae=D.offset(_);B.current.push(ae),TA=ae}const $A=Q.extrude(TA,k,void 0,void 0,void 0,!0);B.current.push($A),v=$A}else{const TA=(C.width||0)+2*_,$A=(C.height||0)+2*_,ae=Q.cube([TA,$A,k],!0);B.current.push(ae);const fA=ae.translate([C.center.x,C.center.y,0]);B.current.push(fA),v=fA}const Y=[];let P=null;const{nonPlatedHoleBoardDrills:T}=ndt(Q,E,A,m,B.current);Y.push(...T);const{platedHoleBoardDrills:O,platedHoleCopperGeoms:W,platedHoleSubtractOp:AA}=sdt(Q,E,A,m,B.current,v);Y.push(...O),d.platedHoles=W;const{viaBoardDrills:oA,viaCopperGeoms:IA}=cdt(Q,A,m,B.current,v);if(Y.push(...oA),d.vias=IA,Y.length>0){P=Q.union(Y),B.current.push(P);const TA=AA?Q.union([P,AA]):P;B.current.push(TA);const $A=x.subtract(TA);if(B.current.push($A),x=$A,AA){const ae=AA.subtract(P);B.current.push(ae);const fA=ae.getMesh(),KA=mw(fA);d.platedHoles=[{key:"plated-holes-union",geometry:KA,color:new Li(Go.copper[0],Go.copper[1],Go.copper[2])}]}}const{cutoutOps:tA}=odt(Q,E,A,m,B.current);if(tA.length>0){const TA=Q.union(tA);B.current.push(TA);const $A=x.subtract(TA);B.current.push($A),x=$A}if(u=x,u){const TA=u.getMesh(),$A=mw(TA),ae=xCA[C.material]??Go.fr4Tan;d.board={geometry:$A,color:new Li(ae[0],ae[1],ae[2]),material:C.material,isFaux:l}}const{smtPadGeoms:sA}=adt(Q,A,m,B.current,P,v);d.smtPads=sA,i(d);const aA=Go.fr4TracesWithoutMaskTan,dA=`rgb(${Math.round(aA[0]*255)}, ${Math.round(aA[1]*255)}, ${Math.round(aA[2]*255)})`;f.topTrace=I_({layer:"top",circuitJson:A,boardData:C,traceColor:dA,traceTextureResolution:Qc}),f.bottomTrace=I_({layer:"bottom",circuitJson:A,boardData:C,traceColor:dA,traceTextureResolution:Qc});const SA=Go.fr4TracesWithMaskGreen,FA=`rgb(${Math.round(SA[0]*255)}, ${Math.round(SA[1]*255)}, ${Math.round(SA[2]*255)})`;f.topTraceWithMask=I_({layer:"top",circuitJson:A,boardData:C,traceColor:FA,traceTextureResolution:Qc}),f.bottomTraceWithMask=I_({layer:"bottom",circuitJson:A,boardData:C,traceColor:FA,traceTextureResolution:Qc});const MA="rgb(255,255,255)";f.topSilkscreen=S5({layer:"top",circuitJson:A,boardData:C,silkscreenColor:MA,traceTextureResolution:Qc}),f.bottomSilkscreen=S5({layer:"bottom",circuitJson:A,boardData:C,silkscreenColor:MA,traceTextureResolution:Qc});const qA=KZA[C.material]??Go.fr4SolderMaskGreen,CA=`rgb(${Math.round(qA[0]*255)}, ${Math.round(qA[1]*255)}, ${Math.round(qA[2]*255)})`;f.topSoldermask=m5({layer:"top",circuitJson:A,boardData:C,soldermaskColor:CA,traceTextureResolution:Qc}),f.bottomSoldermask=m5({layer:"bottom",circuitJson:A,boardData:C,soldermaskColor:CA,traceTextureResolution:Qc});const GA=Go.copper,uA=`rgb(${Math.round(GA[0]*255)}, ${Math.round(GA[1]*255)}, ${Math.round(GA[2]*255)})`;f.topCopperText=x5({layer:"top",circuitJson:A,boardData:C,copperColor:uA,traceTextureResolution:Qc}),f.bottomCopperText=x5({layer:"bottom",circuitJson:A,boardData:C,copperColor:uA,traceTextureResolution:Qc}),f.topPanelOutlines=k5({layer:"top",circuitJson:A,panelData:C,traceTextureResolution:Qc}),f.bottomPanelOutlines=k5({layer:"bottom",circuitJson:A,panelData:C,traceTextureResolution:Qc}),f.topCopper=cVA({layer:"top",circuitJson:A,boardData:C,traceTextureResolution:Qc}),f.bottomCopper=cVA({layer:"bottom",circuitJson:A,boardData:C,traceTextureResolution:Qc}),n(f)}catch(m){console.error("Error processing geometry with Manifold in hook:",m),g(m.message||"An unknown error occurred while processing geometry in hook."),i(null),n(null)}finally{c(!1)}return()=>{B.current.forEach(h),B.current=[]}},[t,A,C]),{geoms:e,textures:o,pcbThickness:s,error:a,isLoading:I,boardData:C,isFauxBoard:l}},Qdt=JC,Edt=({material:t,color:A,side:e=Qdt,isFaux:i=!1})=>t==="fr4"?new lw({color:A,side:e,metalness:0,roughness:.8,specularIntensity:.2,ior:1.45,sheen:0,clearcoat:0,transparent:i,opacity:i?d5:1,flatShading:!0}):new Ih({color:A,side:e,flatShading:!0,metalness:.1,roughness:.8,transparent:!0,opacity:i?d5:.9});function hdt(t){const A=[];if(!t)return A;if(t.board&&t.board.geometry){const i=new Wo(t.board.geometry,Edt({material:t.board.material,color:t.board.color,side:JC,isFaux:t.board.isFaux}));i.name="board-geom",A.push(i)}const e=i=>{i&&i.forEach(o=>{const n=new Wo(o.geometry,new Ih({color:o.color,side:JC,flatShading:!0,polygonOffset:!0,polygonOffsetFactor:-1,polygonOffsetUnits:-1}));n.name=o.key,A.push(n)})};return e(t.platedHoles),e(t.smtPads),e(t.vias),A}var udt=({geometryMeshes:t,textureMeshes:A})=>{const{rootObject:e}=ku(),{visibility:i}=WN();return $.useEffect(()=>{if(e)return t.forEach(o=>{let n=!0;o.name==="board-geom"?n=i.boardBody:o.name.includes("smt_pad")?o.name.includes("smt_pad-top")?n=i.topCopper:o.name.includes("smt_pad-bottom")?n=i.bottomCopper:n=i.topCopper||i.bottomCopper:(o.name.includes("plated_hole")||o.name.includes("via"))&&(n=i.topCopper||i.bottomCopper),n&&e.add(o)}),A.forEach(o=>{let n=!0;o.name.includes("top-trace-texture-plane")&&!o.name.includes("with-mask")?n=i.topCopper&&!i.topMask:o.name.includes("top-trace-with-mask")?n=i.topCopper&&i.topMask:o.name.includes("bottom-trace-texture-plane")&&!o.name.includes("with-mask")?n=i.bottomCopper&&!i.bottomMask:o.name.includes("bottom-trace-with-mask")?n=i.bottomCopper&&i.bottomMask:o.name.includes("top-silkscreen")?n=i.topSilkscreen:o.name.includes("bottom-silkscreen")?n=i.bottomSilkscreen:o.name.includes("top-soldermask")?n=i.topMask:o.name.includes("bottom-soldermask")?n=i.bottomMask:o.name.includes("top-copper-text")?n=i.topCopper:o.name.includes("bottom-copper-text")?n=i.bottomCopper:o.name.includes("top-copper")?n=i.topCopper:o.name.includes("bottom-copper")?n=i.bottomCopper:o.name.includes("panel-outlines")&&(n=i.boardBody),n&&e.add(o)}),()=>{t.forEach(o=>{o.parent===e&&e.remove(o)}),A.forEach(o=>{o.parent===e&&e.remove(o)})}},[e,t,A,i]),null},ddt="https://cdn.jsdelivr.net/npm/manifold-3d@3.2.1",pdt=({circuitJson:t,autoRotateDisabled:A,clickToInteractEnabled:e,onUserInteraction:i,children:o,onCameraControllerReady:n})=>{const s=TZA(o),r=$.useMemo(()=>rVA(t??s),[t,s]),[a,g]=$.useState(null),[I,c]=$.useState(null);$.useEffect(()=>{if(window.ManifoldModule&&typeof window.ManifoldModule=="object"&&window.ManifoldModule.setup){g(window.ManifoldModule);return}const F=async T=>{try{const O=await T();O.setup(),window.ManifoldModule=O,g(O)}catch(O){console.error("Failed to initialize Manifold:",O),c(`Failed to initialize Manifold: ${O instanceof Error?O.message:"Unknown error"}`)}},k=window.ManifoldModule??window.MANIFOLD??window.MANIFOLD_MODULE;if(k){window.ManifoldModule=k,F(window.ManifoldModule);return}const v="manifoldLoaded",_=()=>{const T=window.ManifoldModule??window.MANIFOLD??window.MANIFOLD_MODULE;if(T)window.ManifoldModule=T,F(window.ManifoldModule);else{const O="ManifoldModule not found on window after script load.";console.error(O),c(O)}};window.addEventListener(v,_,{once:!0});const Y=document.createElement("script");Y.type="module",Y.innerHTML=`
|
|
5107
5107
|
try {
|
|
5108
5108
|
const { default: ManifoldModule } = await import('${ddt}/manifold.js');
|
|
5109
5109
|
window.ManifoldModule = ManifoldModule;
|
|
@@ -5613,7 +5613,7 @@ test("${g} should solve problem correctly", () => {
|
|
|
5613
5613
|
// Add more specific assertions based on expected output
|
|
5614
5614
|
// expect(solver.netLabelPlacementSolver!.netLabelPlacements).toMatchInlineSnapshot()
|
|
5615
5615
|
})
|
|
5616
|
-
`,c=new Blob([I],{type:"text/plain"}),B=URL.createObjectURL(c),C=document.createElement("a");C.href=B,C.download=`${g}.test.ts`,C.click(),URL.revokeObjectURL(B)}catch(a){alert(`Error generating test.ts for ${t.constructor.name}: ${a instanceof Error?a.message:String(a)}`)}i(!1)};return V.jsxs("div",{className:`relative ${A}`,ref:o,children:[V.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>i(!e),title:`Download options for ${t.constructor.name}`,children:t.constructor.name}),e&&V.jsxs("div",{className:"absolute top-full left-0 mt-1 bg-white border border-gray-300 rounded shadow-lg z-10 min-w-[150px]",children:[V.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:n,children:"Download JSON"}),V.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),V.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:r,children:"Download test.ts"})]})]})},Gee=t=>t.activeSubSolver?[t,...Gee(t.activeSubSolver)]:[t],SYt=({solver:t})=>{const A=Gee(t);return V.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:A.map((e,i)=>V.jsxs("div",{className:"flex items-center",children:[i>0&&V.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),V.jsx(DYt,{solver:e})]},e.constructor.name))})},bYt=({solver:t,triggerRender:A,animationSpeed:e=25,onSolverStarted:i,onSolverCompleted:o})=>{const[n,s]=$.useReducer(Q=>!Q,!1),r=$.useRef(void 0),a=()=>{!t.solved&&!t.failed&&(t.step(),A())},g=()=>{!t.solved&&!t.failed&&(i&&i(t),t.solve(),A(),o&&o(t))},I=()=>{n?(r.current&&(clearInterval(r.current),r.current=void 0),s()):(s(),r.current=setInterval(()=>{if(t.solved||t.failed){r.current&&(clearInterval(r.current),r.current=void 0),s(),A(),o&&t.solved&&o(t);return}t.step(),A()},e))},c=()=>{const Q=t;if(Q.getCurrentPhase&&!t.solved&&!t.failed){const E=Q.getCurrentPhase();for(;Q.getCurrentPhase()===E&&!t.solved&&!t.failed;)t.step();A()}},B=()=>{if(t.solved||t.failed||n)return;const Q=window.prompt("Step until which iteration?",`${t.iterations}`);if(Q===null)return;const E=Number(Q);if(!Number.isFinite(E)){window.alert("Please enter a valid number for the iteration");return}for(;t.iterations<E&&!t.solved&&!t.failed;)t.step();A(),t.solved&&o&&o(t)};$.useEffect(()=>()=>{r.current&&clearInterval(r.current)},[]),$.useEffect(()=>{(t.solved||t.failed)&&n&&(r.current&&(clearInterval(r.current),r.current=void 0),s())},[t.solved,t.failed,n]);const C=t.getCurrentPhase!==void 0,l=C?t.getCurrentPhase():null;return V.jsxs("div",{className:"space-y-2 p-2 border-b",children:[V.jsx("div",{className:"flex items-center",children:V.jsx(SYt,{solver:t})}),V.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[V.jsx("button",{onClick:a,disabled:t.solved||t.failed||n,className:"bg-blue-500 hover:bg-blue-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step"}),V.jsx("button",{onClick:g,disabled:t.solved||t.failed||n,className:"bg-green-500 hover:bg-green-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Solve"}),V.jsx("button",{onClick:I,disabled:t.solved||t.failed,className:`px-3 py-1 rounded text-white text-sm ${n?"bg-red-500 hover:bg-red-600":"bg-yellow-500 hover:bg-yellow-600"} disabled:bg-gray-300`,children:n?"Stop":"Animate"}),V.jsx("button",{onClick:B,disabled:t.solved||t.failed||n,className:"bg-orange-500 hover:bg-orange-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step Until Iteration"}),C&&V.jsx("button",{onClick:c,disabled:t.solved||t.failed||n,className:"bg-purple-500 hover:bg-purple-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Next Stage"}),V.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",t.iterations]}),t.timeToSolve!==void 0&&V.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(t.timeToSolve/1e3).toFixed(3),"s"]}),l&&V.jsxs("div",{className:"text-sm text-gray-600",children:["Phase: ",V.jsx("span",{className:"font-medium",children:l})]}),t.solved&&V.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),t.failed&&V.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),t.error&&V.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",t.error]})]})},xYt=(t,A,e)=>{const i=t.currentPipelineStepIndex;return A<i?"Completed":A===i&&t.activeSubSolver?t.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},kYt=(t,A)=>{const i=t.pipelineDef[A].solverName,o=xYt(t,A),n=t[i],s=t.firstIterationOfPhase?.[i]??null,r=t.iterations;let a=0;if(o==="Completed"){const B=t.pipelineDef[A+1],C=B?t.firstIterationOfPhase?.[B.solverName]:void 0;C!==void 0&&s!==null?a=C-s:s!==null&&(a=r-s)}else o==="In Progress"&&s!==null&&(a=r-s);const g=t.timeSpentOnPhase?.[i]??0;let I=0;o==="Completed"?I=1:o==="In Progress"&&n&&(I=n.progress??0);const c=n?.stats??null;return{index:A,name:i,status:o,firstIteration:s,iterations:a,progress:I,timeSpent:g,stats:c&&Object.keys(c).length>0?c:null,solverInstance:n??null}},GYt=({status:t})=>{const A={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return V.jsx("span",{className:`font-medium ${A[t]}`,children:t})},FYt=({progress:t})=>{if(t===0)return null;const A=Math.round(t*100);return V.jsxs("div",{className:"flex items-center gap-2",children:[V.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:V.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${A}%`}})}),V.jsxs("span",{className:"text-xs text-gray-500",children:[A,"%"]})]})},RYt=t=>Object.entries(t).map(([A,e])=>`${A}: ${e}`).join(", "),MYt=({stats:t})=>{if(!t||Object.keys(t).length===0)return V.jsx("span",{children:"-"});const A=Object.entries(t),e=RYt(t);return V.jsxs("details",{className:"cursor-pointer",children:[V.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:e}),V.jsx("div",{className:"mt-1 text-xs",children:A.map(([i,o])=>V.jsxs("div",{children:[i,": ",String(o)]},i))})]})},AhA=t=>{if(t===null||typeof t!="object")return t;if(Array.isArray(t))return t.map(AhA);const A={};for(const[e,i]of Object.entries(t))e.startsWith("_")||(A[e]=AhA(i));return A},NYt=(t,A)=>{try{if(typeof t.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${A}`);return}const e=AhA(t.getConstructorParams()),i=new Blob([JSON.stringify(e,null,2)],{type:"application/json"}),o=URL.createObjectURL(i),n=document.createElement("a");n.href=o,n.download=`${A}_input.json`,n.click(),URL.revokeObjectURL(o)}catch(e){alert(`Error downloading input for ${A}: ${e instanceof Error?e.message:String(e)}`)}},_Yt=({solver:t,onStepUntilPhase:A,onDownloadInput:e})=>{const i=t.pipelineDef.map((r,a)=>kYt(t,a)),o=r=>{A?.(r)},n=r=>{r.solverInstance&&(e?e(r.solverInstance,r.name):NYt(r.solverInstance,r.name))},s=r=>`${(r/1e3).toFixed(2)}s`;return V.jsxs("div",{className:"border-t border-gray-200",children:[V.jsx("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200",children:V.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Steps"})}),V.jsx("div",{className:"overflow-x-auto",children:V.jsxs("table",{className:"w-full text-sm",children:[V.jsx("thead",{children:V.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[V.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Step"}),V.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),V.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",V.jsx("sub",{children:"0"})]}),V.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),V.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),V.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),V.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),V.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),V.jsx("tbody",{children:i.map(r=>V.jsxs("tr",{className:`border-b border-gray-100 ${r.status==="In Progress"?"bg-yellow-50":""}`,children:[V.jsx("td",{className:"px-4 py-2",children:V.jsxs("div",{className:"flex items-center gap-2",children:[V.jsx("span",{className:"text-gray-400 w-6",children:String(r.index+1).padStart(2,"0")}),V.jsx("button",{onClick:()=>o(r.name),disabled:r.status==="Completed"||t.solved||t.failed,className:"text-blue-500 hover:text-blue-700 disabled:text-gray-300 disabled:cursor-not-allowed",title:`Step until ${r.name} completes`,children:V.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:V.jsx("path",{fillRule:"evenodd",d:"M4.5 5.653c0-1.426 1.529-2.33 2.779-1.643l11.54 6.348c1.295.712 1.295 2.573 0 3.285L7.28 19.991c-1.25.687-2.779-.217-2.779-1.643V5.653z",clipRule:"evenodd"})})}),V.jsx("span",{className:"font-medium text-gray-900",children:r.name})]})}),V.jsx("td",{className:"px-4 py-2",children:V.jsx(GYt,{status:r.status})}),V.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:r.firstIteration!==null?r.firstIteration:""}),V.jsx("td",{className:"px-4 py-2 text-gray-600",children:r.iterations}),V.jsx("td",{className:"px-4 py-2",children:V.jsx(FYt,{progress:r.progress})}),V.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(r.timeSpent)}),V.jsx("td",{className:"px-4 py-2 text-gray-500",children:V.jsx(MYt,{stats:r.stats})}),V.jsx("td",{className:"px-4 py-2",children:r.solverInstance?V.jsxs("button",{onClick:()=>n(r),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${r.name}`,children:[V.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:V.jsx("path",{fillRule:"evenodd",d:"M12 2.25a.75.75 0 01.75.75v11.69l3.22-3.22a.75.75 0 111.06 1.06l-4.5 4.5a.75.75 0 01-1.06 0l-4.5-4.5a.75.75 0 111.06-1.06l3.22 3.22V3a.75.75 0 01.75-.75zm-9 13.5a.75.75 0 01.75.75v2.25a1.5 1.5 0 001.5 1.5h13.5a1.5 1.5 0 001.5-1.5V16.5a.75.75 0 011.5 0v2.25a3 3 0 01-3 3H5.25a3 3 0 01-3-3V16.5a.75.75 0 01.75-.75z",clipRule:"evenodd"})}),V.jsx("span",{children:"Input"})]}):null})]},r.name))})]})})]})},vYt=class extends Xi.Component{constructor(t){super(t),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(t){console.error("InteractiveGraphics render error:",t)}render(){return this.state.hasError?this.props.fallback:this.props.children}};function UYt({graphics:t}){const A=t.points??[],e=t.lines??[],i=t.rects??[],o=t.circles??[],n=t.texts??[];let s=Number.POSITIVE_INFINITY,r=Number.POSITIVE_INFINITY,a=Number.NEGATIVE_INFINITY,g=Number.NEGATIVE_INFINITY;const I=(E,h)=>{typeof E=="number"&&(E<s&&(s=E),E>a&&(a=E)),typeof h=="number"&&(h<r&&(r=h),h>g&&(g=h))};for(const E of A)I(E.x,E.y);for(const E of e){const h=E.points??[];for(const u of h)I(u.x,u.y)}for(const E of i){const h=E.x??0,u=E.y??0,d=E.width??0,f=E.height??0;I(h,u),I(h+d,u+f)}for(const E of o){const h=E.x??0,u=E.y??0,d=E.radius??1;I(h-d,u-d),I(h+d,u+d)}for(const E of n)I(E.x,E.y);(!isFinite(s)||!isFinite(r)||!isFinite(a)||!isFinite(g))&&(s=-20,r=-20,a=20,g=20);const c=10,B=s-c,C=r-c,l=Math.max(1,a-s+2*c),Q=Math.max(1,g-r+2*c);return V.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${B} ${C} ${l} ${Q}`,role:"img","aria-label":"Graphics fallback",children:[i.map((E,h)=>V.jsx("rect",{x:E.x??0,y:E.y??0,width:E.width??0,height:E.height??0,fill:"none",stroke:E.strokeColor??"black",strokeWidth:E.strokeWidth??1},`rect-${h}`)),e.map((E,h)=>V.jsx("polyline",{fill:"none",stroke:E.strokeColor??"black",strokeWidth:E.strokeWidth??1,points:(E.points??[]).map(u=>`${u.x??0},${u.y??0}`).join(" ")},`line-${h}`)),o.map((E,h)=>V.jsx("circle",{cx:E.x??0,cy:E.y??0,r:E.radius??1.5,fill:E.fillColor??"none",stroke:E.strokeColor??"black",strokeWidth:E.strokeWidth??1},`circle-${h}`)),A.map((E,h)=>V.jsx("circle",{cx:E.x??0,cy:E.y??0,r:E.radius??1.5,fill:E.color??"black"},`point-${h}`)),n.map((E,h)=>V.jsx("text",{x:E.x??0,y:E.y??0,fontSize:E.fontSize??10,fill:E.color??"black",children:E.text??""},`text-${h}`))]})}var LYt=({solver:t,animationSpeed:A=25,onSolverStarted:e,onSolverCompleted:i})=>{const[o,n]=$.useReducer(I=>I+1,0),s=$.useMemo(()=>{try{return t.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(I){return console.error("Visualization error:",I),{points:[],lines:[],rects:[],circles:[]}}},[t,o]),r=$.useMemo(()=>(s.rects?.length||0)===0&&(s.lines?.length||0)===0&&(s.points?.length||0)===0&&(s.circles?.length||0)===0,[s]);$.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const I=document.createElement("script");I.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(I)}},[]);const a=t.pipelineDef!==void 0,g=I=>{const c=t;if(!t.solved&&!t.failed){for(;!t.solved&&!t.failed&&c.currentPipelineStepIndex<=c.pipelineDef.findIndex(B=>B.solverName===I);)t.step();n()}};return V.jsxs("div",{children:[V.jsx(bYt,{solver:t,triggerRender:n,animationSpeed:A,onSolverStarted:e,onSolverCompleted:i}),r?V.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):V.jsx(vYt,{fallback:V.jsx(UYt,{graphics:s}),children:V.jsx(mYt,{graphics:s})}),a&&V.jsx(_Yt,{solver:t,onStepUntilPhase:g})]})};const HYt=()=>{$.useEffect(()=>{const t="tailwind-cdn-script";if(document.getElementById(t)||window.tailwind)return;const A=document.createElement("div");A.className="hidden",document.body.appendChild(A);const e=window.getComputedStyle(A).display==="none";if(document.body.removeChild(A),e)return;const i=document.createElement("script");i.id=t,i.src="https://cdn.tailwindcss.com",document.head.appendChild(i)},[])},YYt=t=>t.toLowerCase().includes("pack")?Jwt:t.toLowerCase().includes("rout")?Wwt:Rwt,JYt=({solverEvents:t=[]})=>{const[A,e]=$.useState(null);HYt();const i=$.useMemo(()=>{const r=new Map;for(const a of t){const g=`${a.componentName}-${a.solverName}`;r.set(g,a)}return r},[t]),o=$.useMemo(()=>Array.from(i.keys()),[i]),n=A?i.get(A):null,s=$.useMemo(()=>{if(!n)return{instance:null,error:null,classFound:!1};const r=WiA[n.solverName];if(!r)return{instance:null,error:`Solver class "${n.solverName}" not found in SOLVERS registry. Available: ${Object.keys(WiA).join(", ")}`,classFound:!1};try{const a=n.solverParams,g=a?.input!==void 0?a.input:a;return{instance:new r(g),error:null,classFound:!0}}catch(a){const g=a instanceof Error?a.message:String(a);return console.error("Failed to reconstruct solver:",a),{instance:null,error:`Failed to instantiate solver: ${g}`,classFound:!0}}},[n]);return t.length===0?V.jsx("div",{className:"rf-p-4",children:V.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:V.jsxs("div",{className:"rf-p-4",children:[V.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),V.jsx("p",{className:"rf-text-sm rf-text-gray-600",children:"Solvers will appear here when the circuit runs. Solvers are used for tasks like component packing and autorouting."})]})})}):V.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[V.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[V.jsxs("div",{className:"rf-text-xs rf-font-semibold rf-text-gray-500 rf-px-3 rf-py-2 rf-bg-gray-50 rf-border-b rf-border-gray-200",children:[o.length," ",o.length===1?"Solver":"Solvers"]}),o.map(r=>{const a=i.get(r),g=A===r;return V.jsx("div",{className:`rf-px-3 rf-py-2 rf-cursor-pointer rf-border-b rf-border-gray-100 ${g?"rf-bg-blue-50 rf-border-l-2 rf-border-l-blue-500":"hover:rf-bg-gray-50"}`,onClick:()=>e(r),children:(()=>{const I=YYt(a.solverName);return V.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[V.jsx(I,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),V.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[V.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:a.componentName}),V.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:a.solverName})]})]})})()},r)})]}),V.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:n?s.instance?V.jsx(Tm,{fallback:V.jsx("div",{className:"rf-p-4",children:V.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[V.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),V.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",n.solverName]})]})}),children:V.jsx(LYt,{solver:s.instance})}):V.jsxs("div",{className:"rf-p-4",children:[V.jsxs("div",{className:"rf-mb-4",children:[V.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:n.solverName}),V.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",n.componentName]})]}),s.error&&V.jsx("div",{className:`rf-rounded-md rf-border rf-p-4 rf-mb-4 ${s.classFound?"rf-bg-red-50 rf-border-red-200":"rf-bg-yellow-50 rf-border-yellow-200"}`,children:V.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),V.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[V.jsx("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50",children:V.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"})}),V.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:V.jsx("pre",{className:"rf-text-xs rf-font-mono rf-text-gray-600 rf-whitespace-pre-wrap rf-overflow-x-auto",children:JSON.stringify(n.solverParams,null,2)})})]})]}):V.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:V.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},Fee=({errorMessage:t,errorStack:A,circuitJsonErrors:e})=>{$.useEffect(()=>{if(t){const i=new Error(t);A&&(i.stack=A);try{yT.captureException(i)}catch{}}},[t,A]),$.useEffect(()=>{if(e&&e.length>0)for(const i of e){const o=new Error(i.message||"Circuit JSON Error");i.stack&&(o.stack=i.stack);try{yT.captureException(o,{error_type:i.type})}catch{}}},[e])},Ree="0.0.1490",TYt={version:Ree},ehA={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1},thA=new Map,jW=t=>{const A=thA.get(t);return A?Object.fromEntries(Object.entries(A.stores).map(([e,i])=>[e,i.getState()])):{}},KYt=(t,A,e)=>{if(t===void 0)return{type:"untracked",connection:A.connect(e)};const i=thA.get(e.name);if(i)return{type:"tracked",store:t,...i};const o={connection:A.connect(e),stores:{}};return thA.set(e.name,o),{type:"tracked",store:t,...o}},Mee=(t,A={})=>(e,i,o)=>{const{enabled:n,anonymousActionType:s,store:r,...a}=A;let g;try{g=(n??(ehA?"production":void 0)!=="production")&&window.__REDUX_DEVTOOLS_EXTENSION__}catch{}if(!g)return(ehA?"production":void 0)!=="production"&&n&&console.warn("[zustand devtools middleware] Please install/enable Redux devtools extension"),t(e,i,o);const{connection:I,...c}=KYt(r,g,a);let B=!0;o.setState=(Q,E,h)=>{const u=e(Q,E);if(!B)return u;const d=h===void 0?{type:s||"anonymous"}:typeof h=="string"?{type:h}:h;return r===void 0?(I?.send(d,i()),u):(I?.send({...d,type:`${r}/${d.type}`},{...jW(a.name),[r]:o.getState()}),u)};const C=(...Q)=>{const E=B;B=!1,e(...Q),B=E},l=t(o.setState,i,o);if(c.type==="untracked"?I?.init(l):(c.stores[c.store]=o,I?.init(Object.fromEntries(Object.entries(c.stores).map(([Q,E])=>[Q,Q===c.store?l:E.getState()])))),o.dispatchFromDevtools&&typeof o.dispatch=="function"){let Q=!1;const E=o.dispatch;o.dispatch=(...h)=>{(ehA?"production":void 0)!=="production"&&h[0].type==="__setState"&&!Q&&(console.warn('[zustand devtools middleware] "__setState" action type is reserved to set state from the devtools. Avoid using it.'),Q=!0),E(...h)}}return I.subscribe(Q=>{var E;switch(Q.type){case"ACTION":if(typeof Q.payload!="string"){console.error("[zustand devtools middleware] Unsupported action format");return}return ihA(Q.payload,h=>{if(h.type==="__setState"){if(r===void 0){C(h.state);return}Object.keys(h.state).length!==1&&console.error(`
|
|
5616
|
+
`,c=new Blob([I],{type:"text/plain"}),B=URL.createObjectURL(c),C=document.createElement("a");C.href=B,C.download=`${g}.test.ts`,C.click(),URL.revokeObjectURL(B)}catch(a){alert(`Error generating test.ts for ${t.constructor.name}: ${a instanceof Error?a.message:String(a)}`)}i(!1)};return V.jsxs("div",{className:`relative ${A}`,ref:o,children:[V.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>i(!e),title:`Download options for ${t.constructor.name}`,children:t.constructor.name}),e&&V.jsxs("div",{className:"absolute top-full left-0 mt-1 bg-white border border-gray-300 rounded shadow-lg z-10 min-w-[150px]",children:[V.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:n,children:"Download JSON"}),V.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),V.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:r,children:"Download test.ts"})]})]})},Gee=t=>t.activeSubSolver?[t,...Gee(t.activeSubSolver)]:[t],SYt=({solver:t})=>{const A=Gee(t);return V.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:A.map((e,i)=>V.jsxs("div",{className:"flex items-center",children:[i>0&&V.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),V.jsx(DYt,{solver:e})]},e.constructor.name))})},bYt=({solver:t,triggerRender:A,animationSpeed:e=25,onSolverStarted:i,onSolverCompleted:o})=>{const[n,s]=$.useReducer(Q=>!Q,!1),r=$.useRef(void 0),a=()=>{!t.solved&&!t.failed&&(t.step(),A())},g=()=>{!t.solved&&!t.failed&&(i&&i(t),t.solve(),A(),o&&o(t))},I=()=>{n?(r.current&&(clearInterval(r.current),r.current=void 0),s()):(s(),r.current=setInterval(()=>{if(t.solved||t.failed){r.current&&(clearInterval(r.current),r.current=void 0),s(),A(),o&&t.solved&&o(t);return}t.step(),A()},e))},c=()=>{const Q=t;if(Q.getCurrentPhase&&!t.solved&&!t.failed){const E=Q.getCurrentPhase();for(;Q.getCurrentPhase()===E&&!t.solved&&!t.failed;)t.step();A()}},B=()=>{if(t.solved||t.failed||n)return;const Q=window.prompt("Step until which iteration?",`${t.iterations}`);if(Q===null)return;const E=Number(Q);if(!Number.isFinite(E)){window.alert("Please enter a valid number for the iteration");return}for(;t.iterations<E&&!t.solved&&!t.failed;)t.step();A(),t.solved&&o&&o(t)};$.useEffect(()=>()=>{r.current&&clearInterval(r.current)},[]),$.useEffect(()=>{(t.solved||t.failed)&&n&&(r.current&&(clearInterval(r.current),r.current=void 0),s())},[t.solved,t.failed,n]);const C=t.getCurrentPhase!==void 0,l=C?t.getCurrentPhase():null;return V.jsxs("div",{className:"space-y-2 p-2 border-b",children:[V.jsx("div",{className:"flex items-center",children:V.jsx(SYt,{solver:t})}),V.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[V.jsx("button",{onClick:a,disabled:t.solved||t.failed||n,className:"bg-blue-500 hover:bg-blue-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step"}),V.jsx("button",{onClick:g,disabled:t.solved||t.failed||n,className:"bg-green-500 hover:bg-green-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Solve"}),V.jsx("button",{onClick:I,disabled:t.solved||t.failed,className:`px-3 py-1 rounded text-white text-sm ${n?"bg-red-500 hover:bg-red-600":"bg-yellow-500 hover:bg-yellow-600"} disabled:bg-gray-300`,children:n?"Stop":"Animate"}),V.jsx("button",{onClick:B,disabled:t.solved||t.failed||n,className:"bg-orange-500 hover:bg-orange-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step Until Iteration"}),C&&V.jsx("button",{onClick:c,disabled:t.solved||t.failed||n,className:"bg-purple-500 hover:bg-purple-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Next Stage"}),V.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",t.iterations]}),t.timeToSolve!==void 0&&V.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(t.timeToSolve/1e3).toFixed(3),"s"]}),l&&V.jsxs("div",{className:"text-sm text-gray-600",children:["Phase: ",V.jsx("span",{className:"font-medium",children:l})]}),t.solved&&V.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),t.failed&&V.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),t.error&&V.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",t.error]})]})},xYt=(t,A,e)=>{const i=t.currentPipelineStepIndex;return A<i?"Completed":A===i&&t.activeSubSolver?t.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},kYt=(t,A)=>{const i=t.pipelineDef[A].solverName,o=xYt(t,A),n=t[i],s=t.firstIterationOfPhase?.[i]??null,r=t.iterations;let a=0;if(o==="Completed"){const B=t.pipelineDef[A+1],C=B?t.firstIterationOfPhase?.[B.solverName]:void 0;C!==void 0&&s!==null?a=C-s:s!==null&&(a=r-s)}else o==="In Progress"&&s!==null&&(a=r-s);const g=t.timeSpentOnPhase?.[i]??0;let I=0;o==="Completed"?I=1:o==="In Progress"&&n&&(I=n.progress??0);const c=n?.stats??null;return{index:A,name:i,status:o,firstIteration:s,iterations:a,progress:I,timeSpent:g,stats:c&&Object.keys(c).length>0?c:null,solverInstance:n??null}},GYt=({status:t})=>{const A={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return V.jsx("span",{className:`font-medium ${A[t]}`,children:t})},FYt=({progress:t})=>{if(t===0)return null;const A=Math.round(t*100);return V.jsxs("div",{className:"flex items-center gap-2",children:[V.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:V.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${A}%`}})}),V.jsxs("span",{className:"text-xs text-gray-500",children:[A,"%"]})]})},RYt=t=>Object.entries(t).map(([A,e])=>`${A}: ${e}`).join(", "),MYt=({stats:t})=>{if(!t||Object.keys(t).length===0)return V.jsx("span",{children:"-"});const A=Object.entries(t),e=RYt(t);return V.jsxs("details",{className:"cursor-pointer",children:[V.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:e}),V.jsx("div",{className:"mt-1 text-xs",children:A.map(([i,o])=>V.jsxs("div",{children:[i,": ",String(o)]},i))})]})},AhA=t=>{if(t===null||typeof t!="object")return t;if(Array.isArray(t))return t.map(AhA);const A={};for(const[e,i]of Object.entries(t))e.startsWith("_")||(A[e]=AhA(i));return A},NYt=(t,A)=>{try{if(typeof t.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${A}`);return}const e=AhA(t.getConstructorParams()),i=new Blob([JSON.stringify(e,null,2)],{type:"application/json"}),o=URL.createObjectURL(i),n=document.createElement("a");n.href=o,n.download=`${A}_input.json`,n.click(),URL.revokeObjectURL(o)}catch(e){alert(`Error downloading input for ${A}: ${e instanceof Error?e.message:String(e)}`)}},_Yt=({solver:t,onStepUntilPhase:A,onDownloadInput:e})=>{const i=t.pipelineDef.map((r,a)=>kYt(t,a)),o=r=>{A?.(r)},n=r=>{r.solverInstance&&(e?e(r.solverInstance,r.name):NYt(r.solverInstance,r.name))},s=r=>`${(r/1e3).toFixed(2)}s`;return V.jsxs("div",{className:"border-t border-gray-200",children:[V.jsx("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200",children:V.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Steps"})}),V.jsx("div",{className:"overflow-x-auto",children:V.jsxs("table",{className:"w-full text-sm",children:[V.jsx("thead",{children:V.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[V.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Step"}),V.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),V.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",V.jsx("sub",{children:"0"})]}),V.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),V.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),V.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),V.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),V.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),V.jsx("tbody",{children:i.map(r=>V.jsxs("tr",{className:`border-b border-gray-100 ${r.status==="In Progress"?"bg-yellow-50":""}`,children:[V.jsx("td",{className:"px-4 py-2",children:V.jsxs("div",{className:"flex items-center gap-2",children:[V.jsx("span",{className:"text-gray-400 w-6",children:String(r.index+1).padStart(2,"0")}),V.jsx("button",{onClick:()=>o(r.name),disabled:r.status==="Completed"||t.solved||t.failed,className:"text-blue-500 hover:text-blue-700 disabled:text-gray-300 disabled:cursor-not-allowed",title:`Step until ${r.name} completes`,children:V.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:V.jsx("path",{fillRule:"evenodd",d:"M4.5 5.653c0-1.426 1.529-2.33 2.779-1.643l11.54 6.348c1.295.712 1.295 2.573 0 3.285L7.28 19.991c-1.25.687-2.779-.217-2.779-1.643V5.653z",clipRule:"evenodd"})})}),V.jsx("span",{className:"font-medium text-gray-900",children:r.name})]})}),V.jsx("td",{className:"px-4 py-2",children:V.jsx(GYt,{status:r.status})}),V.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:r.firstIteration!==null?r.firstIteration:""}),V.jsx("td",{className:"px-4 py-2 text-gray-600",children:r.iterations}),V.jsx("td",{className:"px-4 py-2",children:V.jsx(FYt,{progress:r.progress})}),V.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(r.timeSpent)}),V.jsx("td",{className:"px-4 py-2 text-gray-500",children:V.jsx(MYt,{stats:r.stats})}),V.jsx("td",{className:"px-4 py-2",children:r.solverInstance?V.jsxs("button",{onClick:()=>n(r),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${r.name}`,children:[V.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:V.jsx("path",{fillRule:"evenodd",d:"M12 2.25a.75.75 0 01.75.75v11.69l3.22-3.22a.75.75 0 111.06 1.06l-4.5 4.5a.75.75 0 01-1.06 0l-4.5-4.5a.75.75 0 111.06-1.06l3.22 3.22V3a.75.75 0 01.75-.75zm-9 13.5a.75.75 0 01.75.75v2.25a1.5 1.5 0 001.5 1.5h13.5a1.5 1.5 0 001.5-1.5V16.5a.75.75 0 011.5 0v2.25a3 3 0 01-3 3H5.25a3 3 0 01-3-3V16.5a.75.75 0 01.75-.75z",clipRule:"evenodd"})}),V.jsx("span",{children:"Input"})]}):null})]},r.name))})]})})]})},vYt=class extends Xi.Component{constructor(t){super(t),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(t){console.error("InteractiveGraphics render error:",t)}render(){return this.state.hasError?this.props.fallback:this.props.children}};function UYt({graphics:t}){const A=t.points??[],e=t.lines??[],i=t.rects??[],o=t.circles??[],n=t.texts??[];let s=Number.POSITIVE_INFINITY,r=Number.POSITIVE_INFINITY,a=Number.NEGATIVE_INFINITY,g=Number.NEGATIVE_INFINITY;const I=(E,h)=>{typeof E=="number"&&(E<s&&(s=E),E>a&&(a=E)),typeof h=="number"&&(h<r&&(r=h),h>g&&(g=h))};for(const E of A)I(E.x,E.y);for(const E of e){const h=E.points??[];for(const u of h)I(u.x,u.y)}for(const E of i){const h=E.x??0,u=E.y??0,d=E.width??0,f=E.height??0;I(h,u),I(h+d,u+f)}for(const E of o){const h=E.x??0,u=E.y??0,d=E.radius??1;I(h-d,u-d),I(h+d,u+d)}for(const E of n)I(E.x,E.y);(!isFinite(s)||!isFinite(r)||!isFinite(a)||!isFinite(g))&&(s=-20,r=-20,a=20,g=20);const c=10,B=s-c,C=r-c,l=Math.max(1,a-s+2*c),Q=Math.max(1,g-r+2*c);return V.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${B} ${C} ${l} ${Q}`,role:"img","aria-label":"Graphics fallback",children:[i.map((E,h)=>V.jsx("rect",{x:E.x??0,y:E.y??0,width:E.width??0,height:E.height??0,fill:"none",stroke:E.strokeColor??"black",strokeWidth:E.strokeWidth??1},`rect-${h}`)),e.map((E,h)=>V.jsx("polyline",{fill:"none",stroke:E.strokeColor??"black",strokeWidth:E.strokeWidth??1,points:(E.points??[]).map(u=>`${u.x??0},${u.y??0}`).join(" ")},`line-${h}`)),o.map((E,h)=>V.jsx("circle",{cx:E.x??0,cy:E.y??0,r:E.radius??1.5,fill:E.fillColor??"none",stroke:E.strokeColor??"black",strokeWidth:E.strokeWidth??1},`circle-${h}`)),A.map((E,h)=>V.jsx("circle",{cx:E.x??0,cy:E.y??0,r:E.radius??1.5,fill:E.color??"black"},`point-${h}`)),n.map((E,h)=>V.jsx("text",{x:E.x??0,y:E.y??0,fontSize:E.fontSize??10,fill:E.color??"black",children:E.text??""},`text-${h}`))]})}var LYt=({solver:t,animationSpeed:A=25,onSolverStarted:e,onSolverCompleted:i})=>{const[o,n]=$.useReducer(I=>I+1,0),s=$.useMemo(()=>{try{return t.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(I){return console.error("Visualization error:",I),{points:[],lines:[],rects:[],circles:[]}}},[t,o]),r=$.useMemo(()=>(s.rects?.length||0)===0&&(s.lines?.length||0)===0&&(s.points?.length||0)===0&&(s.circles?.length||0)===0,[s]);$.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const I=document.createElement("script");I.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(I)}},[]);const a=t.pipelineDef!==void 0,g=I=>{const c=t;if(!t.solved&&!t.failed){for(;!t.solved&&!t.failed&&c.currentPipelineStepIndex<=c.pipelineDef.findIndex(B=>B.solverName===I);)t.step();n()}};return V.jsxs("div",{children:[V.jsx(bYt,{solver:t,triggerRender:n,animationSpeed:A,onSolverStarted:e,onSolverCompleted:i}),r?V.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):V.jsx(vYt,{fallback:V.jsx(UYt,{graphics:s}),children:V.jsx(mYt,{graphics:s})}),a&&V.jsx(_Yt,{solver:t,onStepUntilPhase:g})]})};const HYt=()=>{$.useEffect(()=>{const t="tailwind-cdn-script";if(document.getElementById(t)||window.tailwind)return;const A=document.createElement("div");A.className="hidden",document.body.appendChild(A);const e=window.getComputedStyle(A).display==="none";if(document.body.removeChild(A),e)return;const i=document.createElement("script");i.id=t,i.src="https://cdn.tailwindcss.com",document.head.appendChild(i)},[])},YYt=t=>t.toLowerCase().includes("pack")?Jwt:t.toLowerCase().includes("rout")?Wwt:Rwt,JYt=({solverEvents:t=[]})=>{const[A,e]=$.useState(null);HYt();const i=$.useMemo(()=>{const r=new Map;for(const a of t){const g=`${a.componentName}-${a.solverName}`;r.set(g,a)}return r},[t]),o=$.useMemo(()=>Array.from(i.keys()),[i]),n=A?i.get(A):null,s=$.useMemo(()=>{if(!n)return{instance:null,error:null,classFound:!1};const r=WiA[n.solverName];if(!r)return{instance:null,error:`Solver class "${n.solverName}" not found in SOLVERS registry. Available: ${Object.keys(WiA).join(", ")}`,classFound:!1};try{const a=n.solverParams,g=a?.input!==void 0?a.input:a;return{instance:new r(g),error:null,classFound:!0}}catch(a){const g=a instanceof Error?a.message:String(a);return console.error("Failed to reconstruct solver:",a),{instance:null,error:`Failed to instantiate solver: ${g}`,classFound:!0}}},[n]);return t.length===0?V.jsx("div",{className:"rf-p-4",children:V.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:V.jsxs("div",{className:"rf-p-4",children:[V.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),V.jsx("p",{className:"rf-text-sm rf-text-gray-600",children:"Solvers will appear here when the circuit runs. Solvers are used for tasks like component packing and autorouting."})]})})}):V.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[V.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[V.jsxs("div",{className:"rf-text-xs rf-font-semibold rf-text-gray-500 rf-px-3 rf-py-2 rf-bg-gray-50 rf-border-b rf-border-gray-200",children:[o.length," ",o.length===1?"Solver":"Solvers"]}),o.map(r=>{const a=i.get(r),g=A===r;return V.jsx("div",{className:`rf-px-3 rf-py-2 rf-cursor-pointer rf-border-b rf-border-gray-100 ${g?"rf-bg-blue-50 rf-border-l-2 rf-border-l-blue-500":"hover:rf-bg-gray-50"}`,onClick:()=>e(r),children:(()=>{const I=YYt(a.solverName);return V.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[V.jsx(I,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),V.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[V.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:a.componentName}),V.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:a.solverName})]})]})})()},r)})]}),V.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:n?s.instance?V.jsx(Tm,{fallback:V.jsx("div",{className:"rf-p-4",children:V.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[V.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),V.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",n.solverName]})]})}),children:V.jsx(LYt,{solver:s.instance})}):V.jsxs("div",{className:"rf-p-4",children:[V.jsxs("div",{className:"rf-mb-4",children:[V.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:n.solverName}),V.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",n.componentName]})]}),s.error&&V.jsx("div",{className:`rf-rounded-md rf-border rf-p-4 rf-mb-4 ${s.classFound?"rf-bg-red-50 rf-border-red-200":"rf-bg-yellow-50 rf-border-yellow-200"}`,children:V.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),V.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[V.jsx("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50",children:V.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"})}),V.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:V.jsx("pre",{className:"rf-text-xs rf-font-mono rf-text-gray-600 rf-whitespace-pre-wrap rf-overflow-x-auto",children:JSON.stringify(n.solverParams,null,2)})})]})]}):V.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:V.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},Fee=({errorMessage:t,errorStack:A,circuitJsonErrors:e})=>{$.useEffect(()=>{if(t){const i=new Error(t);A&&(i.stack=A);try{yT.captureException(i)}catch{}}},[t,A]),$.useEffect(()=>{if(e&&e.length>0)for(const i of e){const o=new Error(i.message||"Circuit JSON Error");i.stack&&(o.stack=i.stack);try{yT.captureException(o,{error_type:i.type})}catch{}}},[e])},Ree="0.0.1492",TYt={version:Ree},ehA={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1},thA=new Map,jW=t=>{const A=thA.get(t);return A?Object.fromEntries(Object.entries(A.stores).map(([e,i])=>[e,i.getState()])):{}},KYt=(t,A,e)=>{if(t===void 0)return{type:"untracked",connection:A.connect(e)};const i=thA.get(e.name);if(i)return{type:"tracked",store:t,...i};const o={connection:A.connect(e),stores:{}};return thA.set(e.name,o),{type:"tracked",store:t,...o}},Mee=(t,A={})=>(e,i,o)=>{const{enabled:n,anonymousActionType:s,store:r,...a}=A;let g;try{g=(n??(ehA?"production":void 0)!=="production")&&window.__REDUX_DEVTOOLS_EXTENSION__}catch{}if(!g)return(ehA?"production":void 0)!=="production"&&n&&console.warn("[zustand devtools middleware] Please install/enable Redux devtools extension"),t(e,i,o);const{connection:I,...c}=KYt(r,g,a);let B=!0;o.setState=(Q,E,h)=>{const u=e(Q,E);if(!B)return u;const d=h===void 0?{type:s||"anonymous"}:typeof h=="string"?{type:h}:h;return r===void 0?(I?.send(d,i()),u):(I?.send({...d,type:`${r}/${d.type}`},{...jW(a.name),[r]:o.getState()}),u)};const C=(...Q)=>{const E=B;B=!1,e(...Q),B=E},l=t(o.setState,i,o);if(c.type==="untracked"?I?.init(l):(c.stores[c.store]=o,I?.init(Object.fromEntries(Object.entries(c.stores).map(([Q,E])=>[Q,Q===c.store?l:E.getState()])))),o.dispatchFromDevtools&&typeof o.dispatch=="function"){let Q=!1;const E=o.dispatch;o.dispatch=(...h)=>{(ehA?"production":void 0)!=="production"&&h[0].type==="__setState"&&!Q&&(console.warn('[zustand devtools middleware] "__setState" action type is reserved to set state from the devtools. Avoid using it.'),Q=!0),E(...h)}}return I.subscribe(Q=>{var E;switch(Q.type){case"ACTION":if(typeof Q.payload!="string"){console.error("[zustand devtools middleware] Unsupported action format");return}return ihA(Q.payload,h=>{if(h.type==="__setState"){if(r===void 0){C(h.state);return}Object.keys(h.state).length!==1&&console.error(`
|
|
5617
5617
|
[zustand devtools middleware] Unsupported __setState action format.
|
|
5618
5618
|
When using 'store' option in devtools(), the 'state' should have only one key, which is a value of 'store' that was passed in devtools(),
|
|
5619
5619
|
and value of this only key should be a state object. Example: { "type": "__setState", "state": { "abc123Store": { "foo": "bar" } } }
|