@tscircuit/runframe 0.0.2778 → 0.0.2780

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.
@@ -5304,7 +5304,7 @@ ${A.join(`
5304
5304
  ${m}polygon: ${d.polygon.vertices}
5305
5305
  `:A+=`
5306
5306
  `,d.children.length>0&&l.push(d.children)}return A}};e.exports=s}}),TAi=yt({"node_modules/@jscad/modeling/src/operations/booleans/trees/Tree.js"(t,e){var n=MAi(),o=RAi(),i=class{constructor(r){this.polygonTree=new o,this.rootnode=new n(null),r&&this.addPolygons(r)}invert(){this.polygonTree.invert(),this.rootnode.invert()}clipTo(r,s=!1){this.rootnode.clipTo(r,s)}allPolygons(){const r=[];return this.polygonTree.getPolygons(r),r}addPolygons(r){const s=new Array(r.length);for(let a=0;a<r.length;a++)s[a]=this.polygonTree.addChild(r[a]);this.rootnode.addPolygonTreeNodes(s)}clear(){this.polygonTree.clear()}toString(){return"Tree: "+this.polygonTree.toString("")}};e.exports=i}}),nUe=yt({"node_modules/@jscad/modeling/src/operations/booleans/trees/index.js"(t,e){e.exports={Tree:TAi()}}}),kAi=yt({"node_modules/@jscad/modeling/src/operations/booleans/intersectGeom3Sub.js"(t,e){var n=Pa(),o=tUe(),{Tree:i}=nUe(),r=(s,a)=>{if(!o(s,a))return n.create();const A=new i(n.toPolygons(s)),c=new i(n.toPolygons(a));A.invert(),c.clipTo(A),c.invert(),A.clipTo(c),c.clipTo(A),A.addPolygons(c.allPolygons()),A.invert();const l=A.allPolygons();return n.create(l)};e.exports=r}}),Jen=yt({"node_modules/@jscad/modeling/src/operations/booleans/intersectGeom3.js"(t,e){var n=sa(),o=oq(),i=kAi(),r=(...s)=>{s=n(s);let a=s.shift();return s.forEach(A=>{a=i(a,A)}),a=o(a),a};e.exports=r}}),FAi=yt({"node_modules/@jscad/modeling/src/operations/booleans/intersectGeom2.js"(t,e){var n=sa(),o=Pa(),i=bP(),r=ZYe(),s=eUe(),a=Jen(),A=(...c)=>{c=n(c);const l=c.map(h=>s({z0:-1,z1:1},h)),g=a(l),u=i(g);return r(u,o.toPolygons(g))};e.exports=A}}),LAi=yt({"node_modules/@jscad/modeling/src/operations/booleans/intersect.js"(t,e){var n=sa(),o=nq(),i=ka(),r=Pa(),s=FAi(),a=Jen(),A=(...c)=>{if(c=n(c),c.length===0)throw new Error("wrong number of arguments");if(!o(c))throw new Error("only intersect of the types are supported");const l=c[0];return i.isA(l)?s(c):r.isA(l)?a(c):l};e.exports=A}}),oUe=yt({"node_modules/@jscad/modeling/src/operations/hulls/hullPoints3.js"(t,e){var n=zA(),o=$Zt(),i=r=>o(r,{skipTriangulation:!0}).map(A=>{const c=A.map(l=>r[l]);return n.create(c)});e.exports=i}}),Wen=yt({"node_modules/@jscad/modeling/src/operations/booleans/unionGeom3Sub.js"(t,e){var n=Pa(),o=tUe(),{Tree:i}=nUe(),r=(a,A)=>{if(!o(a,A))return s(a,A);const c=new i(n.toPolygons(a)),l=new i(n.toPolygons(A));c.clipTo(l,!1),l.clipTo(c),l.invert(),l.clipTo(c),l.invert();const g=c.allPolygons().concat(l.allPolygons());return n.create(g)},s=(a,A)=>{let c=n.toPolygons(a);return c=c.concat(n.toPolygons(A)),n.create(c)};e.exports=r}}),iUe=yt({"node_modules/@jscad/modeling/src/operations/booleans/unionGeom3.js"(t,e){var n=sa(),o=oq(),i=Wen(),r=(...s)=>{s=n(s);let a;for(a=1;a<s.length;a+=2)s.push(i(s[a-1],s[a]));let A=s[a-1];return A=o(A),A};e.exports=r}}),jen=yt({"node_modules/@jscad/modeling/src/operations/minkowski/minkowskiSum.js"(t,e){var n=sa(),o=Pa(),i=zA(),r=oUe(),s=iUe(),a=(...h)=>{if(h=n(h),h.length!==2)throw new Error("minkowskiSum requires exactly two geometries");const[d,m]=h;if(!o.isA(d)||!o.isA(m))throw new Error("minkowskiSum requires geom3 geometries");const p=o.isConvex(d),_=o.isConvex(m);if(p&&_)return g(d,m);if(!p&&_)return A(d,m);if(p&&!_)return A(m,d);throw new Error("minkowskiSum of two non-convex geometries is not yet supported")},A=(h,d)=>{const m=c(h);if(m.length===0)return o.create();const p=m.map(_=>g(_,d));return p.length===1?p[0]:s(p)},c=h=>{const d=o.toPolygons(h);if(d.length===0)return[];const m=[];for(let p=0;p<d.length;p++){const _=d[p],f=_.vertices;let I=0,C=0,y=0;for(let D=0;D<f.length;D++)I+=f[D][0],C+=f[D][1],y+=f[D][2];I/=f.length,C/=f.length,y/=f.length;const x=i.plane(_),E=x[0],B=x[1],b=x[2],Q=.1,w=[I-E*Q,C-B*Q,y-b*Q];for(let D=1;D<f.length-1;D++){const k=f[0],R=f[D],H=f[D+1],G=l(w,k,R,H);m.push(o.create(G))}}return m},l=(h,d,m,p)=>[i.create([h,m,d]),i.create([h,d,p]),i.create([d,m,p]),i.create([m,h,p])],g=(h,d)=>{const m=u(h),p=u(d);if(m.length===0||p.length===0)return o.create();const _=[];for(let I=0;I<m.length;I++){const C=m[I];for(let y=0;y<p.length;y++){const x=p[y];_.push([C[0]+x[0],C[1]+x[1],C[2]+x[2]])}}const f=r(_);return o.create(f)},u=h=>{const d=new Set,m=[],p=o.toPolygons(h);for(let _=0;_<p.length;_++){const f=p[_].vertices;for(let I=0;I<f.length;I++){const C=f[I],y=`${C[0]},${C[1]},${C[2]}`;d.has(y)||(d.add(y),m.push(C))}}return m};e.exports=a}}),HAi=yt({"node_modules/@jscad/modeling/src/operations/booleans/scissionGeom3.js"(t,e){var n=Jr(),o=bP(),i=Pa(),r=c=>c.sort((l,g)=>l-g).filter((l,g,u)=>!g||l!==u[g-1]),s=(c,l,g)=>{const u=`${l}`,h=c.get(u);h===void 0?c.set(u,[g]):h.push(g)},a=(c,l)=>{const g=`${l}`;return c.get(g)},A=c=>{const l=o(c),g=i.toPolygons(c),u=g.length,h=new Map,d=n.create();g.forEach((I,C)=>{I.vertices.forEach(y=>{s(h,n.snap(d,y,l),C)})});const m=g.map(I=>{let C=[];return I.vertices.forEach(y=>{C=C.concat(a(h,n.snap(d,y,l)))}),{e:1,d:r(C)}});h.clear();let p=0;const _=m.length;for(let I=0;I<_;I++){const C=m[I];if(C.e>0){const y=new Array(u);y[I]=!0;do p=0,y.forEach((x,E)=>{const B=m[E];if(B.e>0){B.e=-1;for(let b=0;b<B.d.length;b++)y[B.d[b]]=!0;p++}});while(p>0);C.indexes=y}}const f=[];for(let I=0;I<_;I++)if(m[I].indexes){const C=[];m[I].indexes.forEach((y,x)=>C.push(g[x])),f.push(i.create(C))}return f};e.exports=A}}),OAi=yt({"node_modules/@jscad/modeling/src/operations/booleans/scission.js"(t,e){var n=sa(),o=Pa(),i=HAi(),r=(...s)=>{if(s=n(s),s.length===0)throw new Error("wrong number of arguments");const a=s.map(A=>o.isA(A)?i(A):A);return a.length===1?a[0]:a};e.exports=r}}),GAi=yt({"node_modules/@jscad/modeling/src/operations/booleans/subtractGeom3Sub.js"(t,e){var n=Pa(),o=tUe(),{Tree:i}=nUe(),r=(s,a)=>{if(!o(s,a))return n.clone(s);const A=new i(n.toPolygons(s)),c=new i(n.toPolygons(a));A.invert(),A.clipTo(c),c.clipTo(A,!0),A.addPolygons(c.allPolygons()),A.invert();const l=A.allPolygons();return n.create(l)};e.exports=r}}),Xen=yt({"node_modules/@jscad/modeling/src/operations/booleans/subtractGeom3.js"(t,e){var n=sa(),o=oq(),i=GAi(),r=(...s)=>{s=n(s);let a=s.shift();return s.forEach(A=>{a=i(a,A)}),a=o(a),a};e.exports=r}}),YAi=yt({"node_modules/@jscad/modeling/src/operations/booleans/subtractGeom2.js"(t,e){var n=sa(),o=Pa(),i=bP(),r=ZYe(),s=eUe(),a=Xen(),A=(...c)=>{c=n(c);const l=c.map(h=>s({z0:-1,z1:1},h)),g=a(l),u=i(g);return r(u,o.toPolygons(g))};e.exports=A}}),UAi=yt({"node_modules/@jscad/modeling/src/operations/booleans/subtract.js"(t,e){var n=sa(),o=nq(),i=ka(),r=Pa(),s=YAi(),a=Xen(),A=(...c)=>{if(c=n(c),c.length===0)throw new Error("wrong number of arguments");if(!o(c))throw new Error("only subtract of the types are supported");const l=c[0];return i.isA(l)?s(c):r.isA(l)?a(c):l};e.exports=A}}),qen=yt({"node_modules/@jscad/modeling/src/operations/booleans/unionGeom2.js"(t,e){var n=sa(),o=Pa(),i=bP(),r=ZYe(),s=eUe(),a=iUe(),A=(...c)=>{c=n(c);const l=c.map(h=>s({z0:-1,z1:1},h)),g=a(l),u=i(g);return r(u,o.toPolygons(g))};e.exports=A}}),rUe=yt({"node_modules/@jscad/modeling/src/operations/booleans/union.js"(t,e){var n=sa(),o=nq(),i=ka(),r=Pa(),s=qen(),a=iUe(),A=(...c)=>{if(c=n(c),c.length===0)throw new Error("wrong number of arguments");if(!o(c))throw new Error("only unions of the same type are supported");const l=c[0];return i.isA(l)?s(c):r.isA(l)?a(c):l};e.exports=A}}),iq=yt({"node_modules/@jscad/modeling/src/operations/booleans/index.js"(t,e){e.exports={intersect:LAi(),minkowski:jen(),scission:OAi(),subtract:UAi(),union:rUe()}}}),ide=yt({"node_modules/@jscad/modeling/src/operations/expansions/offsetFromPoints.js"(t,e){var{EPS:n,TAU:o}=Ac(),i=ben(),r=WYe(),s=gA(),a=tde(),A=(c,l)=>{const g={delta:1,corners:"edge",closed:!1,segments:16};let{delta:u,corners:h,closed:d,segments:m}=Object.assign({},g,c);if(Math.abs(u)<n)return l;let p=c.closed?a(l):1;p===0&&(p=1);const _=p>0&&u>=0||p<0&&u<0;u=Math.abs(u);let f=null,I=[];const C=[],y=s.create(),x=l.length;for(let E=0;E<x;E++){const B=(E+1)%x,b=l[E],Q=l[B];_?s.subtract(y,b,Q):s.subtract(y,Q,b),s.normal(y,y),s.normalize(y,y),s.scale(y,y,u);const w=s.add(s.create(),b,y),D=s.add(s.create(),Q,y),k=[w,D];if(f!=null&&(d||!d&&B!==0)){const R=i(f[0],f[1],k[0],k[1]);R?(I.pop(),k[0]=R):C.push({c:b,s0:f,s1:k})}f=[w,D],!(B===0&&!d)&&(I.push(k[0]),I.push(k[1]))}if(d&&f!=null){const E=I[0],B=I[1],b=i(f[0],f[1],E,B);if(b)I[0]=b,I.pop();else{const Q=l[0],w=[E,B];C.push({c:Q,s0:f,s1:w})}}if(h==="edge"){const E=new Map;I.forEach((Q,w)=>E.set(Q,w));const B=r.create(),b=r.create();C.forEach(Q=>{r.fromPoints(B,Q.s0[0],Q.s0[1]),r.fromPoints(b,Q.s1[0],Q.s1[1]);const w=r.intersectPointOfLines(B,b);if(Number.isFinite(w[0])&&Number.isFinite(w[1])){const D=Q.s0[1],k=E.get(D);I[k]=w,I[(k+1)%I.length]=void 0}else{const D=Q.s1[0],k=E.get(D);I[k]=void 0}}),I=I.filter(Q=>Q!==void 0)}if(h==="round"){let E=Math.floor(m/4);const B=s.create();C.forEach(b=>{let Q=s.angle(s.subtract(B,b.s1[0],b.c));if(Q-=s.angle(s.subtract(B,b.s0[1],b.c)),_&&Q<0&&(Q=Q+Math.PI,Q<0&&(Q=Q+Math.PI)),!_&&Q>0&&(Q=Q-Math.PI,Q>0&&(Q=Q-Math.PI)),Q!==0){E=Math.floor(m*(Math.abs(Q)/o));const w=Q/E,D=s.angle(s.subtract(B,b.s0[1],b.c)),k=[];for(let R=1;R<E;R++){const H=D+w*R,G=s.fromAngleRadians(s.create(),H);s.scale(G,G,u),s.add(G,G,b.c),k.push(G)}if(k.length>0){const R=b.s0[1];let H=I.findIndex(G=>s.equals(R,G));H=(H+1)%I.length,I.splice(H,0,...k)}}else{const w=b.s1[0],D=I.findIndex(k=>s.equals(w,k));I.splice(D,1)}})}return I};e.exports=A}}),KAi=yt({"node_modules/@jscad/modeling/src/operations/expansions/expandGeom2.js"(t,e){var n=ka(),o=ide(),i=(r,s)=>{const a={delta:1,corners:"edge",segments:16},{delta:A,corners:c,segments:l}=Object.assign({},a,r);if(!(c==="edge"||c==="chamfer"||c==="round"))throw new Error('corners must be "edge", "chamfer", or "round"');const h=n.toOutlines(s).map(d=>(r={delta:A,corners:c,closed:!0,segments:l},o(r,d))).reduce((d,m)=>d.concat(n.toSides(n.fromPoints(m))),[]);return n.create(h)};e.exports=i}}),VAi=yt({"node_modules/@jscad/modeling/src/operations/expansions/extrudePolygon.js"(t,e){var n=Cg(),o=Jr(),i=Pa(),r=zA(),s=(a,A)=>{o.dot(r.plane(A),a)>0&&(A=r.invert(A));const l=[A],g=r.transform(n.fromTranslation(n.create(),a),A),u=A.vertices.length;for(let h=0;h<u;h++){const d=h<u-1?h+1:0,m=r.create([A.vertices[h],g.vertices[h],g.vertices[d],A.vertices[d]]);l.push(m)}return l.push(r.invert(g)),i.create(l)};e.exports=s}}),zAi=yt({"node_modules/@jscad/modeling/src/operations/expansions/expandShell.js"(t,e){var{EPS:n,TAU:o}=Ac(),i=Cg(),r=Jr(),s=Ven(),a=Pa(),A=zA(),c=Len(),l=oq(),g=Wen(),u=VAi(),h=(_,f,I)=>{const C=f.toString();if(_.has(C))_.get(C)[1].push(I);else{const y=[f,[I]];_.set(C,y)}},d=(_,f,I)=>{const C=f[0].toString(),y=f[1].toString(),x=C<y?`${C},${y}`:`${y},${C}`;if(_.has(x))_.get(x)[1].push(I);else{const E=[f,[I]];_.set(x,E)}},m=(_,f)=>{_.findIndex(C=>C===f)<0&&_.push(f)},p=(_,f)=>{const I={delta:1,segments:12},{delta:C,segments:y}=Object.assign({},I,_);let x=a.create();const E=new Map,B=new Map,b=r.create(),Q=r.create();return a.toPolygons(f).forEach((D,k)=>{const R=r.scale(r.create(),A.plane(D),2*C),H=A.transform(i.fromTranslation(i.create(),r.scale(r.create(),R,-.5)),D),G=u(R,H);x=g(x,G);const K=D.vertices;for(let Y=0;Y<K.length;Y++){h(E,K[Y],A.plane(D));const X=(Y+1)%K.length,te=[K[Y],K[X]];d(B,te,A.plane(D))}}),B.forEach(D=>{const k=D[0],R=D[1],H=k[0],G=k[1],K=r.subtract(r.create(),G,H);r.normalize(K,K);const Y=R[0],X=r.cross(r.create(),Y,K);let te=[];for(let _e=0;_e<y;_e++)m(te,_e*o/y);for(let _e=0,ce=R.length;_e<ce;_e++){const Ie=R[_e],de=r.dot(X,Ie),Ce=r.dot(Y,Ie);let Pe=Math.atan2(de,Ce);Pe<0&&(Pe+=o),m(te,Pe),Pe=Math.atan2(-de,-Ce),Pe<0&&(Pe+=o),m(te,Pe)}te=te.sort(s);const j=te.length;let J,ie;const oe=[],ne=[],le=[];for(let _e=-1;_e<j;_e++){const ce=te[_e<0?_e+j:_e],Ie=Math.sin(ce),de=Math.cos(ce);r.scale(b,Y,de*C),r.scale(Q,X,Ie*C),r.add(b,b,Q);const Ce=r.add(r.create(),H,b),Pe=r.add(r.create(),G,b);let Qe=!1;if(_e>=0&&r.distance(Ce,J)<n&&(Qe=!0),!Qe){if(_e>=0){oe.push(Ce),ne.push(Pe);const pe=[ie,Pe,Ce,J],ve=A.create(pe);le.push(ve)}J=Ce,ie=Pe}}ne.reverse(),le.push(A.create(oe)),le.push(A.create(ne));const ge=a.create(le);x=g(x,ge)}),E.forEach(D=>{const k=D[0],R=D[1],H=R[0];let G=null,K=0;for(let j=1;j<R.length;j++){const J=R[j],ie=r.cross(b,H,J),oe=r.length(ie);oe>.05&&oe>K&&(K=oe,G=J)}G||(G=r.orthogonal(b,H));const Y=r.cross(b,H,G);r.normalize(Y,Y);const X=r.cross(Q,Y,H),te=c({center:[k[0],k[1],k[2]],radius:C,segments:y,axes:[H,Y,X]});x=g(x,te)}),l(x)};e.exports=p}}),JAi=yt({"node_modules/@jscad/modeling/src/operations/expansions/expandGeom3.js"(t,e){var n=Pa(),o=rUe(),i=zAi(),r=(s,a)=>{const A={delta:1,corners:"round",segments:12},{delta:c,corners:l,segments:g}=Object.assign({},A,s);if(l!=="round")throw new Error('corners must be "round" for 3D geometries');if(n.toPolygons(a).length===0)throw new Error("the given geometry cannot be empty");s={delta:c,corners:l,segments:g};const h=i(s,a);return o(a,h)};e.exports=r}}),WAi=yt({"node_modules/@jscad/modeling/src/operations/expansions/expandPath2.js"(t,e){var n=tde(),o=gA(),i=ka(),r=j0(),s=ide(),a=l=>{let{external:g,internal:u}=l;n(g)<0?g=g.reverse():u=u.reverse();const h=r.fromPoints({closed:!0},g),d=r.fromPoints({closed:!0},u),m=i.toSides(i.fromPoints(r.toPoints(h))),p=i.toSides(i.fromPoints(r.toPoints(d)));return m.push(...p),i.create(m)},A=(l,g,u,h)=>{const{points:d,external:m,internal:p}=l,_=Math.floor(g/2),f=[],I=[];if(u==="round"&&_>0){const y=Math.PI/_,x=d[d.length-1],E=o.angle(o.subtract(o.create(),m[m.length-1],x)),B=d[0],b=o.angle(o.subtract(o.create(),p[0],B));for(let Q=1;Q<_;Q++){let w=E+y*Q,D=o.fromAngleRadians(o.create(),w);o.scale(D,D,h),o.add(D,D,x),f.push(D),w=b+y*Q,D=o.fromAngleRadians(o.create(),w),o.scale(D,D,h),o.add(D,D,B),I.push(D)}}const C=[];return C.push(...m,...f,...p.reverse(),...I),i.fromPoints(C)},c=(l,g)=>{l=Object.assign({},{delta:1,corners:"edge",segments:16},l);const{delta:h,corners:d,segments:m}=l;if(h<=0)throw new Error("the given delta must be positive for paths");if(!(d==="edge"||d==="chamfer"||d==="round"))throw new Error('corners must be "edge", "chamfer", or "round"');const p=g.isClosed,_=r.toPoints(g);if(_.length===0)throw new Error("the given geometry cannot be empty");const f={points:_,external:s({delta:h,corners:d,segments:m,closed:p},_),internal:s({delta:-h,corners:d,segments:m,closed:p},_)};return g.isClosed?a(f):A(f,m,d,h)};e.exports=c}}),sUe=yt({"node_modules/@jscad/modeling/src/operations/expansions/expand.js"(t,e){var n=sa(),o=ka(),i=Pa(),r=j0(),s=KAi(),a=JAi(),A=WAi(),c=(l,...g)=>{if(g=n(g),g.length===0)throw new Error("wrong number of arguments");const u=g.map(h=>r.isA(h)?A(l,h):o.isA(h)?s(l,h):i.isA(h)?a(l,h):h);return u.length===1?u[0]:u};e.exports=c}}),jAi=yt({"node_modules/@jscad/modeling/src/operations/expansions/offsetGeom2.js"(t,e){var n=ka(),o=UYe(),i=ide(),r=(s,a)=>{const A={delta:1,corners:"edge",segments:0},{delta:c,corners:l,segments:g}=Object.assign({},A,s);if(!(l==="edge"||l==="chamfer"||l==="round"))throw new Error('corners must be "edge", "chamfer", or "round"');const u=n.toOutlines(a),d=u.map(m=>(s={delta:u.reduce((f,I)=>f+o.arePointsInside(m,o.create(I)),0)%2===0?c:-c,corners:l,closed:!0,segments:g},i(s,m))).reduce((m,p)=>m.concat(n.toSides(n.fromPoints(p))),[]);return n.create(d)};e.exports=r}}),XAi=yt({"node_modules/@jscad/modeling/src/operations/expansions/offsetPath2.js"(t,e){var n=j0(),o=ide(),i=(r,s)=>{const a={delta:1,corners:"edge",closed:s.isClosed,segments:16},{delta:A,corners:c,closed:l,segments:g}=Object.assign({},a,r);if(!(c==="edge"||c==="chamfer"||c==="round"))throw new Error('corners must be "edge", "chamfer", or "round"');r={delta:A,corners:c,closed:l,segments:g};const u=o(r,n.toPoints(s));return n.fromPoints({closed:l},u)};e.exports=i}}),qAi=yt({"node_modules/@jscad/modeling/src/operations/expansions/offset.js"(t,e){var n=sa(),o=ka(),i=j0(),r=jAi(),s=XAi(),a=(A,...c)=>{if(c=n(c),c.length===0)throw new Error("wrong number of arguments");const l=c.map(g=>i.isA(g)?s(A,g):o.isA(g)?r(A,g):g);return l.length===1?l[0]:l};e.exports=a}}),$en=yt({"node_modules/@jscad/modeling/src/operations/expansions/index.js"(t,e){e.exports={expand:sUe(),offset:qAi()}}}),rde=yt({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeLinearGeom2.js"(t,e){var n=Cg(),o=Jr(),i=ka(),r=PG(),s=ode(),a=(A,c)=>{const l={offset:[0,0,1],twistAngle:0,twistSteps:12,repair:!0};let{offset:g,twistAngle:u,twistSteps:h,repair:d}=Object.assign({},l,A);if(h<1)throw new Error("twistSteps must be 1 or more");u===0&&(h=1);const m=o.clone(g),p=i.toSides(c);if(p.length===0)throw new Error("the given geometry cannot be empty");const _=r.fromSides(p);m[2]<0&&r.reverse(_,_);const f=n.create(),I=(C,y,x)=>{const E=y/h*u,B=o.scale(o.create(),m,y/h);return n.multiply(f,n.fromZRotation(f,E),n.fromTranslation(n.create(),B)),r.transform(f,x)};return A={numberOfSlices:h+1,capStart:!0,capEnd:!0,repair:d,callback:I},s(A,_)};e.exports=a}}),$Ai=yt({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeLinearPath2.js"(t,e){var n=ka(),o=j0(),i=rde(),r=(s,a)=>{if(!a.isClosed)throw new Error("extruded path must be closed");const A=o.toPoints(a),c=n.fromPoints(A);return i(s,c)};e.exports=r}}),ZAi=yt({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeLinear.js"(t,e){var n=sa(),o=ka(),i=j0(),r=rde(),s=$Ai(),a=(A,...c)=>{const l={height:1,twistAngle:0,twistSteps:1,repair:!0},{height:g,twistAngle:u,twistSteps:h,repair:d}=Object.assign({},l,A);if(c=n(c),c.length===0)throw new Error("wrong number of arguments");A={offset:[0,0,g],twistAngle:u,twistSteps:h,repair:d};const m=c.map(p=>i.isA(p)?s(A,p):o.isA(p)?r(A,p):p);return m.length===1?m[0]:m};e.exports=a}}),eci=yt({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeRectangularPath2.js"(t,e){var n=j0(),o=sUe(),i=rde(),r=(s,a)=>{const A={size:1,height:1},{size:c,height:l}=Object.assign({},A,s);if(s.delta=c,s.offset=[0,0,l],n.toPoints(a).length===0)throw new Error("the given geometry cannot be empty");const u=o(s,a);return i(s,u)};e.exports=r}}),tci=yt({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeRectangularGeom2.js"(t,e){var{area:n}=$X(),o=ka(),i=j0(),r=sUe(),s=rde(),a=(A,c)=>{const l={size:1,height:1},{size:g,height:u}=Object.assign({},l,A);A.delta=g,A.offset=[0,0,u];const h=o.toOutlines(c);if(h.length===0)throw new Error("the given geometry cannot be empty");const m=h.map(_=>(n(_)<0&&_.reverse(),r(A,i.fromPoints({closed:!0},_)))).reduce((_,f)=>_.concat(o.toSides(f)),[]),p=o.create(m);return s(A,p)};e.exports=a}}),nci=yt({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeRectangular.js"(t,e){var n=sa(),o=ka(),i=j0(),r=eci(),s=tci(),a=(A,...c)=>{const l={size:1,height:1},{size:g,height:u}=Object.assign({},l,A);if(c=n(c),c.length===0)throw new Error("wrong number of arguments");if(g<=0)throw new Error("size must be positive");if(u<=0)throw new Error("height must be positive");const h=c.map(d=>i.isA(d)?r(A,d):o.isA(d)?s(A,d):d);return h.length===1?h[0]:h};e.exports=a}}),oci=yt({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeHelical.js"(t,e){var{TAU:n}=Ac(),o=Cg(),i=ka(),r=ode(),s=PG(),a=(A,c)=>{const l={angle:n,startAngle:0,pitch:10,height:0,endOffset:0,segmentsPerRotation:32};let{angle:g,startAngle:u,pitch:h,height:d,endOffset:m,segmentsPerRotation:p}=Object.assign({},l,A);if(d!=0&&(h=d/(g/n)),p<3)throw new Error("The number of segments per rotation needs to be at least 3.");const f=i.toSides(c);if(f.length===0)throw new Error("The given geometry cannot be empty");const I=f.filter(Q=>Q[0][0]>=0);let C=s.fromSides(f);I.length===0&&(C=s.reverse(C));const y=Math.round(p/n*Math.abs(g)),x=y>=2?y:2,E=o.create(),B=o.create(),b=(Q,w,D)=>{const k=u+g/x*w,R=m/x*w,H=(k-u)/n*h;return o.multiply(E,o.fromTranslation(o.create(),[R,0,H*Math.sign(g)]),o.fromXRotation(o.create(),-n/4*Math.sign(g))),o.multiply(B,o.fromZRotation(o.create(),k),E),s.transform(B,D)};return r({numberOfSlices:x+1,callback:b},C)};e.exports=a}}),ici=yt({"node_modules/@jscad/modeling/src/operations/extrusions/project.js"(t,e){var n=sa(),o=JYe(),i=e7(),r=Cg(),s=ka(),a=Pa(),A=zA(),c=bP(),l=qen(),g=(h,d)=>{const m=i.fromNormalAndPoint(i.create(),h.axis,h.origin);if(Number.isNaN(m[0])||Number.isNaN(m[1])||Number.isNaN(m[2])||Number.isNaN(m[3]))throw new Error("project: invalid axis or origin");const p=c(d),_=p*p*Math.sqrt(3)/4;if(p===0)return s.create();const f=a.toPolygons(d);let I=[];for(let y=0;y<f.length;y++){const x=f[y].vertices.map(b=>i.projectionOfPoint(m,b)),E=A.create(x),B=A.plane(E);o(m,B)&&(A.measureArea(E)<_||I.push(E))}if(!o(m,[0,0,1])){const y=r.fromVectorRotation(r.create(),m,[0,0,1]);I=I.map(x=>A.transform(y,x))}I=I.sort((y,x)=>A.measureArea(x)-A.measureArea(y));const C=I.map(y=>s.fromPoints(y.vertices));return l(C)},u=(h,...d)=>{const m={axis:[0,0,1],origin:[0,0,0]},{axis:p,origin:_}=Object.assign({},m,h);if(d=n(d),d.length===0)throw new Error("wrong number of arguments");h={axis:p,origin:_};const f=d.map(I=>a.isA(I)?g(h,I):I);return f.length===1?f[0]:f};e.exports=u}}),rq=yt({"node_modules/@jscad/modeling/src/operations/extrusions/index.js"(t,e){e.exports={extrudeFromSlices:ode(),extrudeLinear:ZAi(),extrudeRectangular:nci(),extrudeRotate:Yen(),extrudeHelical:oci(),project:ici(),slice:PG()}}}),aUe=yt({"node_modules/@jscad/modeling/src/operations/hulls/hullPoints2.js"(t,e){var n=gA(),o=s=>{let a=n.fromValues(1/0,1/0);s.forEach(l=>{(l[1]<a[1]||l[1]===a[1]&&l[0]<a[0])&&(a=l)});const A=[];s.forEach(l=>{const g=r(l[1]-a[1],l[0]-a[0]),u=n.squaredDistance(l,a);A.push({point:l,angle:g,distSq:u})}),A.sort((l,g)=>l.angle!==g.angle?l.angle-g.angle:l.distSq-g.distSq);const c=[];return A.forEach(l=>{let g=c.length;for(;g>1&&i(c[g-2],c[g-1],l.point)<=Number.EPSILON;)c.pop(),g=c.length;c.push(l.point)}),c},i=(s,a,A)=>(a[0]-s[0])*(A[1]-s[1])-(a[1]-s[1])*(A[0]-s[0]),r=(s,a)=>s===0&&a===0?-1/0:-a/s;e.exports=o}}),AUe=yt({"node_modules/@jscad/modeling/src/operations/hulls/toUniquePoints.js"(t,e){var n=ka(),o=Pa(),i=j0(),r=s=>{const a=new Set,A=[],c=l=>{const g=l.toString();a.has(g)||(A.push(l),a.add(g))};return s.forEach(l=>{n.isA(l)?n.toPoints(l).forEach(c):o.isA(l)?o.toPoints(l).forEach(g=>g.forEach(c)):i.isA(l)&&i.toPoints(l).forEach(c)}),A};e.exports=r}}),rci=yt({"node_modules/@jscad/modeling/src/operations/hulls/hullPath2.js"(t,e){var n=sa(),o=j0(),i=aUe(),r=AUe(),s=(...a)=>{a=n(a);const A=r(a),c=i(A);return o.fromPoints({closed:!0},c)};e.exports=s}}),sci=yt({"node_modules/@jscad/modeling/src/operations/hulls/hullGeom2.js"(t,e){var n=sa(),o=ka(),i=aUe(),r=AUe(),s=(...a)=>{a=n(a);const A=r(a),c=i(A);return c.length<3?o.create():o.fromPoints(c)};e.exports=s}}),aci=yt({"node_modules/@jscad/modeling/src/operations/hulls/hullGeom3.js"(t,e){var n=sa(),o=Pa(),i=AUe(),r=oUe(),s=(...a)=>{a=n(a);const A=i(a);return A.length===0?o.create():o.create(r(A))};e.exports=s}}),Zen=yt({"node_modules/@jscad/modeling/src/operations/hulls/hull.js"(t,e){var n=sa(),o=nq(),i=ka(),r=Pa(),s=j0(),a=rci(),A=sci(),c=aci(),l=(...g)=>{if(g=n(g),g.length===0)throw new Error("wrong number of arguments");if(!o(g))throw new Error("only hulls of the same type are supported");const u=g[0];return s.isA(u)?a(g):i.isA(u)?A(g):r.isA(u)?c(g):u};e.exports=l}}),Aci=yt({"node_modules/@jscad/modeling/src/operations/hulls/hullChain.js"(t,e){var n=sa(),o=rUe(),i=Zen(),r=(...s)=>{if(s=n(s),s.length<2)throw new Error("wrong number of arguments");const a=[];for(let A=1;A<s.length;A++)a.push(i(s[A-1],s[A]));return o(a)};e.exports=r}}),cci=yt({"node_modules/@jscad/modeling/src/operations/hulls/index.js"(t,e){e.exports={hull:Zen(),hullChain:Aci(),hullPoints2:aUe(),hullPoints3:oUe()}}}),lci=yt({"node_modules/@jscad/modeling/src/operations/minkowski/index.js"(t,e){e.exports={minkowskiSum:jen()}}}),etn=yt({"node_modules/@jscad/modeling/src/operations/modifiers/snapPolygons.js"(t,e){var n=Jr(),o=zA(),i=(s,a)=>{const A=Math.abs(o.measureArea(a));return Number.isFinite(A)&&A>s},r=(s,a)=>{let A=a.map(l=>{const g=l.vertices.map(d=>n.snap(n.create(),d,s)),u=[];for(let d=0;d<g.length;d++){const m=(d+1)%g.length;n.equals(g[d],g[m])||u.push(g[d])}const h=o.create(u);return l.color&&(h.color=l.color),h});const c=s*s*Math.sqrt(3)/4;return A=A.filter(l=>i(c,l)),A};e.exports=r}}),gci=yt({"node_modules/@jscad/modeling/src/operations/modifiers/mergePolygons.js"(t,e){var n=JYe(),o=Jr(),i=zA(),r=_=>{const f=i.toPoints(_),I=[];for(let C=0;C<f.length;C++){const y=(C+1)%f.length,x={v1:f[C],v2:f[y]};I.push(x)}for(let C=0;C<I.length;C++){const y=(C+1)%f.length;I[C].next=I[y],I[y].prev=I[C]}return I},s=(_,f)=>{const I=`${f.v1}:${f.v2}`;_.set(I,f)},a=(_,f)=>{const I=`${f.v1}:${f.v2}`;_.delete(I)},A=(_,f)=>{const I=`${f.v2}:${f.v1}`;return _.get(I)},c=(_,f,I)=>{let C=_.prev.v1,y=_.prev.v2,x=f.next.v2;const E=u(C,y,x,I);C=f.prev.v1,y=f.prev.v2,x=_.next.v2;const B=u(C,y,x,I);return[E,B]},l=o.create(),g=o.create(),u=(_,f,I,C)=>{const y=o.subtract(l,f,_),x=o.subtract(g,I,f);return o.cross(y,y,x),o.dot(y,C)},h=_=>{let f;const I=[];for(;_.next;){const C=_.next;I.push(_.v1),_.v1=null,_.v2=null,_.next=null,_.prev=null,_=C}return I.length>0&&(f=i.create(I)),f},d=_=>{if(_.length<2)return _;const f=_[0].plane,I=_.slice(),C=new Map;for(;I.length>0;){const x=I.shift(),E=r(x);for(let B=0;B<E.length;B++){const b=E[B],Q=A(C,b);if(Q){const w=c(b,Q,f);if(w[0]>=0&&w[1]>=0){const D=Q.next,k=b.next;b.prev.next=Q.next,b.next.prev=Q.prev,Q.prev.next=b.next,Q.next.prev=b.prev,b.v1=null,b.v2=null,b.next=null,b.prev=null,a(C,Q),Q.v1=null,Q.v2=null,Q.next=null,Q.prev=null;const R=(H,G,K)=>{const Y={v1:K.v1,v2:G.v2,next:G.next,prev:K.prev};K.prev.next=Y,G.next.prev=Y,a(H,G),G.v1=null,G.v2=null,G.next=null,G.prev=null,a(H,K),K.v1=null,K.v2=null,K.next=null,K.prev=null};w[0]===0&&R(C,D,D.prev),w[1]===0&&R(C,k,k.prev)}}else b.next&&s(C,b)}}const y=[];return C.forEach(x=>{const E=h(x);E&&y.push(E)}),C.clear(),y},m=(_,f)=>Math.abs(_[3]-f[3])<15e-8?n(_,f):!1,p=(_,f)=>{const I=[];f.forEach(y=>{const x=I.find(E=>m(E[0],i.plane(y)));x?x[1].push(y):I.push([i.plane(y),[y]])});let C=[];return I.forEach(y=>{const x=y[1],E=d(x);C=C.concat(E)}),C};e.exports=p}}),uci=yt({"node_modules/@jscad/modeling/src/operations/modifiers/insertTjunctions.js"(t,e){var n=Ac(),o=Jr(),i=zA(),r=c=>`${c}`,s=(c,l,g,u,h,d)=>{const m=r(u),p=r(h),_=`${m}/${p}`,f=`${p}/${m}`;if(c.has(f))return a(c,l,g,h,u,null),null;const I={vertex0:u,vertex1:h,polygonindex:d};return c.has(_)?c.get(_).push(I):c.set(_,[I]),l.has(m)?l.get(m).push(_):l.set(m,[_]),g.has(p)?g.get(p).push(_):g.set(p,[_]),_},a=(c,l,g,u,h,d)=>{const m=r(u),p=r(h),_=`${m}/${p}`;let f=-1;const I=c.get(_);for(let C=0;C<I.length;C++){const y=I[C];let x=r(y.vertex0);if(x===m&&(x=r(y.vertex1),x===p&&!(d!==null&&y.polygonindex!==d))){f=C;break}}I.splice(f,1),I.length===0&&c.delete(_),f=l.get(m).indexOf(_),l.get(m).splice(f,1),l.get(m).length===0&&l.delete(m),f=g.get(p).indexOf(_),g.get(p).splice(f,1),g.get(p).length===0&&g.delete(p)},A=c=>{const l=new Map;for(let g=0;g<c.length;g++){const u=c[g],h=u.vertices.length;if(h>=3){let d=u.vertices[0],m=r(d);for(let p=0;p<h;p++){let _=p+1;_===h&&(_=0);const f=u.vertices[_],I=r(f),C=`${m}/${I}`,y=`${I}/${m}`;if(l.has(y)){const x=l.get(y);x.splice(-1,1),x.length===0&&l.delete(y)}else{const x={vertex0:d,vertex1:f,polygonindex:g};l.has(C)?l.get(C).push(x):l.set(C,[x])}d=f,m=I}}else console.warn("warning: invalid polygon found during insertTjunctions")}if(l.size>0){const g=new Map,u=new Map,h=new Map;for(const[m,p]of l)h.set(m,!0),p.forEach(_=>{const f=r(_.vertex0),I=r(_.vertex1);g.has(f)?g.get(f).push(m):g.set(f,[m]),u.has(I)?u.get(I).push(m):u.set(I,[m])});const d=c.slice(0);for(;l.size!==0;){for(const p of l.keys())h.set(p,!0);let m=!1;for(;;){const p=Array.from(h.keys());if(p.length===0)break;const _=p[0];let f=!0;if(l.has(_)){const C=l.get(_)[0];for(let y=0;y<2;y++){const x=y===0?C.vertex0:C.vertex1,E=y===0?C.vertex1:C.vertex0,B=r(x),b=r(E);let Q=[];y===0?u.has(B)&&(Q=u.get(B)):g.has(B)&&(Q=g.get(B));for(let w=0;w<Q.length;w++){const D=Q[w],k=l.get(D)[0],R=y===0?k.vertex0:k.vertex1;if(y===0?k.vertex1:k.vertex0,r(R)===b){a(l,g,u,x,E,null),a(l,g,u,E,x,null),f=!1,y=2,m=!0;break}else{const G=x,K=E,Y=R,X=o.subtract(o.create(),Y,G),te=o.dot(o.subtract(o.create(),K,G),X)/o.dot(X,X);if(te>0&&te<1){const j=o.scale(o.create(),X,te);if(o.add(j,j,G),o.squaredDistance(j,K)<n.EPS*n.EPS){const ie=k.polygonindex,oe=d[ie],ne=r(k.vertex1);let le=-1;for(let de=0;de<oe.vertices.length;de++)if(r(oe.vertices[de])===ne){le=de;break}const ge=oe.vertices.slice(0);ge.splice(le,0,E);const _e=i.create(ge);d[ie]=_e,a(l,g,u,k.vertex0,k.vertex1,ie);const ce=s(l,g,u,k.vertex0,E,ie),Ie=s(l,g,u,E,k.vertex1,ie);ce!==null&&h.set(ce,!0),Ie!==null&&h.set(Ie,!0),f=!1,y=2,m=!0;break}}}}}}f&&h.delete(_)}if(!m)break}c=d}return l.clear(),c};e.exports=A}}),dci=yt({"node_modules/@jscad/modeling/src/operations/modifiers/triangulatePolygons.js"(t,e){var n=Jr(),o=zA(),i=(s,a,A)=>{const c=a.vertices.length;if(c>3){if(c>4){const u=[0,0,0];a.vertices.forEach(h=>n.add(u,u,h)),n.snap(u,n.divide(u,u,[c,c,c]),s);for(let h=0;h<c;h++){const d=o.create([u,a.vertices[h],a.vertices[(h+1)%c]]);a.color&&(d.color=a.color),A.push(d)}return}const l=o.create([a.vertices[0],a.vertices[1],a.vertices[2]]),g=o.create([a.vertices[0],a.vertices[2],a.vertices[3]]);a.color&&(l.color=a.color,g.color=a.color),A.push(l,g);return}A.push(a)},r=(s,a)=>{const A=[];return a.forEach(c=>{i(s,c,A)}),A};e.exports=r}}),hci=yt({"node_modules/@jscad/modeling/src/operations/modifiers/generalize.js"(t,e){var n=sa(),o=bP(),i=ka(),r=Pa(),s=j0(),a=etn(),A=gci(),c=uci(),l=dci(),g=(m,p)=>p,u=(m,p)=>p,h=(m,p)=>{const _={snap:!1,simplify:!1,triangulate:!1},{snap:f,simplify:I,triangulate:C}=Object.assign({},_,m),y=o(p);let x=r.toPolygons(p);f&&(x=a(y,x)),I&&(x=A(y,x)),C&&(x=c(x),x=l(y,x));const E=Object.assign({},p);return E.polygons=x,E},d=(m,...p)=>{if(p=n(p),p.length===0)throw new Error("wrong number of arguments");const _=p.map(f=>{if(s.isA(f))return g(m,f);if(i.isA(f))return u(m,f);if(r.isA(f))return h(m,f);throw new Error("invalid geometry")});return _.length===1?_[0]:_};e.exports=d}}),mci=yt({"node_modules/@jscad/modeling/src/operations/modifiers/snap.js"(t,e){var n=sa(),o=gA(),i=ka(),r=Pa(),s=j0(),a=bP(),A=etn(),c=h=>{const d=a(h),p=s.toPoints(h).map(_=>o.snap(o.create(),_,d));return s.create(p)},l=h=>{const d=a(h);let p=i.toSides(h).map(_=>[o.snap(o.create(),_[0],d),o.snap(o.create(),_[1],d)]);return p=p.filter(_=>!o.equals(_[0],_[1])),i.create(p)},g=h=>{const d=a(h),m=r.toPolygons(h),p=A(d,m);return r.create(p)},u=(...h)=>{if(h=n(h),h.length===0)throw new Error("wrong number of arguments");const d=h.map(m=>s.isA(m)?c(m):i.isA(m)?l(m):r.isA(m)?g(m):m);return d.length===1?d[0]:d};e.exports=u}}),pci=yt({"node_modules/@jscad/modeling/src/operations/modifiers/index.js"(t,e){e.exports={generalize:hci(),snap:mci(),retessellate:oq()}}}),_ci=yt({"node_modules/@jscad/modeling/src/utils/padArrayToLength.js"(t,e){var n=(o,i,r)=>{for(o=o.slice();o.length<r;)o.push(i);return o};e.exports=n}}),fci=yt({"node_modules/@jscad/modeling/src/operations/transforms/align.js"(t,e){var n=sa(),o=_ci(),i=jYe(),{translate:r}=mR(),s=l=>{if(!Array.isArray(l.modes)||l.modes.length>3)throw new Error("align(): modes must be an array of length <= 3");if(l.modes=o(l.modes,"none",3),l.modes.filter(g=>["center","max","min","none"].includes(g)).length!==3)throw new Error('align(): all modes must be one of "center", "max" or "min"');if(!Array.isArray(l.relativeTo)||l.relativeTo.length>3)throw new Error("align(): relativeTo must be an array of length <= 3");if(l.relativeTo=o(l.relativeTo,0,3),l.relativeTo.filter(g=>Number.isFinite(g)||g==null).length!==3)throw new Error("align(): all relativeTo values must be a number, or null.");if(typeof l.grouped!="boolean")throw new Error("align(): grouped must be a boolean value.");return l},a=(l,g,u)=>{for(let h=0;h<3;h++)l[h]==null&&(g[h]==="center"?l[h]=(u[0][h]+u[1][h])/2:g[h]==="max"?l[h]=u[1][h]:g[h]==="min"&&(l[h]=u[0][h]));return l},A=(l,g,u)=>{const h=i(l),d=[0,0,0];for(let m=0;m<3;m++)g[m]==="center"?d[m]=u[m]-(h[0][m]+h[1][m])/2:g[m]==="max"?d[m]=u[m]-h[1][m]:g[m]==="min"&&(d[m]=u[m]-h[0][m]);return r(d,l)},c=(l,...g)=>{l=Object.assign({},{modes:["center","center","min"],relativeTo:[0,0,0],grouped:!1},l),l=s(l);let{modes:h,relativeTo:d,grouped:m}=l;if(g=n(g),g.length===0)throw new Error("align(): No geometries were provided to act upon");if(d.filter(p=>p==null).length){const p=i(g);d=a(d,h,p)}return m?g=A(g,h,d):g=g.map(p=>A(p,h,d)),g.length===1?g[0]:g};e.exports=c}}),sde=yt({"node_modules/@jscad/modeling/src/operations/transforms/center.js"(t,e){var n=sa(),o=ka(),i=Pa(),r=j0(),s=dR(),{translate:a}=mR(),A=(h,d)=>{const m={axes:[!0,!0,!0],relativeTo:[0,0,0]},{axes:p,relativeTo:_}=Object.assign({},m,h),f=s(d),I=[0,0,0];return p[0]&&(I[0]=_[0]-(f[0][0]+(f[1][0]-f[0][0])/2)),p[1]&&(I[1]=_[1]-(f[0][1]+(f[1][1]-f[0][1])/2)),p[2]&&(I[2]=_[2]-(f[0][2]+(f[1][2]-f[0][2])/2)),a(I,d)},c=(h,...d)=>{const m={axes:[!0,!0,!0],relativeTo:[0,0,0]},{axes:p,relativeTo:_}=Object.assign({},m,h);if(d=n(d),d.length===0)throw new Error("wrong number of arguments");if(_.length!==3)throw new Error("relativeTo must be an array of length 3");h={axes:p,relativeTo:_};const f=d.map(I=>r.isA(I)||o.isA(I)||i.isA(I)?A(h,I):I);return f.length===1?f[0]:f},l=(...h)=>c({axes:[!0,!1,!1]},h),g=(...h)=>c({axes:[!1,!0,!1]},h),u=(...h)=>c({axes:[!1,!1,!0]},h);e.exports={center:c,centerX:l,centerY:g,centerZ:u}}}),ade=yt({"node_modules/@jscad/modeling/src/operations/transforms/scale.js"(t,e){var n=sa(),o=Cg(),i=ka(),r=Pa(),s=j0(),a=(g,...u)=>{if(!Array.isArray(g))throw new Error("factors must be an array");if(u=n(u),u.length===0)throw new Error("wrong number of arguments");for(g=g.slice();g.length<3;)g.push(1);if(g[0]<=0||g[1]<=0||g[2]<=0)throw new Error("factors must be positive");const h=o.fromScaling(o.create(),g),d=u.map(m=>s.isA(m)?s.transform(h,m):i.isA(m)?i.transform(h,m):r.isA(m)?r.transform(h,m):m);return d.length===1?d[0]:d},A=(g,...u)=>a([g,1,1],u),c=(g,...u)=>a([1,g,1],u),l=(g,...u)=>a([1,1,g],u);e.exports={scale:a,scaleX:A,scaleY:c,scaleZ:l}}}),Ici=yt({"node_modules/@jscad/modeling/src/operations/transforms/transform.js"(t,e){var n=sa(),o=ka(),i=Pa(),r=j0(),s=(a,...A)=>{if(A=n(A),A.length===0)throw new Error("wrong number of arguments");const c=A.map(l=>r.isA(l)?r.transform(a,l):o.isA(l)?o.transform(a,l):i.isA(l)?i.transform(a,l):l);return c.length===1?c[0]:c};e.exports=s}}),_R=yt({"node_modules/@jscad/modeling/src/operations/transforms/index.js"(t,e){e.exports={align:fci(),center:sde().center,centerX:sde().centerX,centerY:sde().centerY,centerZ:sde().centerZ,mirror:eq().mirror,mirrorX:eq().mirrorX,mirrorY:eq().mirrorY,mirrorZ:eq().mirrorZ,rotate:tq().rotate,rotateX:tq().rotateX,rotateY:tq().rotateY,rotateZ:tq().rotateZ,scale:ade().scale,scaleX:ade().scaleX,scaleY:ade().scaleY,scaleZ:ade().scaleZ,transform:Ici(),translate:mR().translate,translateX:mR().translateX,translateY:mR().translateY,translateZ:mR().translateZ}}}),Ade=yt({"node_modules/@jscad/modeling/src/index.js"(t,e){e.exports={colors:ede(),curves:dai(),geometries:KYe(),maths:Lai(),measurements:zai(),primitives:pR(),text:BAi(),utils:zen(),booleans:iq(),expansions:$en(),extrusions:rq(),hulls:cci(),minkowski:lci(),modifiers:pci(),transforms:_R()}}}),ttn=yt({"node_modules/jscad-planner/dist/index.cjs"(t,e){var n=Object.defineProperty,o=Object.getOwnPropertyDescriptor,i=Object.getOwnPropertyNames,r=Object.prototype.hasOwnProperty,s=(u,h)=>{for(var d in h)n(u,d,{get:h[d],enumerable:!0})},a=(u,h,d,m)=>{if(h&&typeof h=="object"||typeof h=="function")for(let p of i(h))!r.call(u,p)&&p!==d&&n(u,p,{get:()=>h[p],enumerable:!(m=o(h,p))||m.enumerable});return u},A=u=>a(n({},"__esModule",{value:!0}),u),c={};s(c,{executeJscadOperations:()=>g,jscadPlanner:()=>l}),e.exports=A(c);var l={booleans:{intersect:(...u)=>({type:"intersect",shapes:u}),subtract:(...u)=>({type:"subtract",shapes:u}),union:(...u)=>({type:"union",shapes:u})},hulls:{hull:(...u)=>({type:"hull",shapes:u.flat()}),hullChain:(...u)=>({type:"hullChain",shapes:u.flat()})},colors:{colorize:(u,h)=>({type:"colorize",color:u,shape:h})},primitives:{cube:u=>({type:"cube",...u}),sphere:u=>({type:"sphere",...u}),cylinder:u=>({type:"cylinder",...u}),polygon:u=>({type:"polygon",...u}),cuboid:u=>({type:"cuboid",...u}),roundedCuboid:u=>({type:"roundedCuboid",...u})},transforms:{rotate:(u,h)=>({type:"rotate",angles:u,shape:h}),scale:(u,h)=>({type:"scale",factors:u,shape:h}),translate:(u,h)=>({type:"translate",vector:u,shape:h})},extrusions:{extrudeLinear:(u,h)=>({type:"extrudeLinear",options:u,shape:h}),extrudeRotate:(u,h)=>({type:"extrudeRotate",options:u,shape:h})},maths:{vec2:{create:(u,h)=>[u,h],fromValues:(u,h)=>[u,h]},vec3:{create:(u,h,d)=>[u,h,d],fromValues:(u,h,d)=>[u,h,d]}},geometries:{geom2:{create:u=>({type:"createGeom2",points:u})},geom3:{create:u=>({type:"createGeom3",polygons:u})},path2:{create:u=>({type:"createPath2",points:u})}},measurements:{measureBoundingBox:u=>({type:"measureBoundingBox",shape:u}),measureArea:u=>({type:"measureArea",shape:u}),measureVolume:u=>({type:"measureVolume",shape:u})},utils:{degToRad:u=>u*Math.PI/180,radToDeg:u=>u*180/Math.PI}},g=(u,h)=>{if(Array.isArray(h)&&h.length===1)return g(u,h[0]);if(Array.isArray(h))throw new Error("executeJscadOperations currently doesn't support Array<JscadOperation>, try adding a root union or or executing each element individually");const d=_=>g(u,_),{type:m,...p}=h;switch(m){case"intersect":return u.booleans.intersect(...h.shapes.map(d));case"subtract":return u.booleans.subtract(...h.shapes.map(d));case"union":return u.booleans.union(...h.shapes.map(d));case"hull":return u.hulls.hull(...h.shapes.map(d));case"hullChain":return u.hulls.hullChain(...h.shapes.map(d));case"colorize":return u.colors.colorize(h.color,d(h.shape));case"cube":return u.primitives.cube(p);case"sphere":return u.primitives.sphere(p);case"cylinder":return u.primitives.cylinder(p);case"polygon":return u.primitives.polygon(p);case"cuboid":return u.primitives.cuboid(p);case"roundedCuboid":return u.primitives.roundedCuboid(p);case"rotate":return u.transforms.rotate(h.angles,d(h.shape));case"scale":return u.transforms.scale(h.factors,d(h.shape));case"translate":return u.transforms.translate(h.vector,d(h.shape));case"extrudeLinear":return u.extrusions.extrudeLinear(h.options,d(h.shape));case"extrudeRotate":return u.extrusions.extrudeRotate(h.options,d(h.shape));case"createGeom2":return u.geometries.geom2.create(h.points);case"createGeom3":return u.geometries.geom3.create(h.polygons);case"createPath2":return u.geometries.path2.create(h.points);case"measureBoundingBox":return u.measurements.measureBoundingBox(d(h.shape));case"measureArea":return u.measurements.measureArea(d(h.shape));case"measureVolume":return u.measurements.measureVolume(d(h.shape));case"degToRad":return u.utils.degToRad(h.degrees);case"radToDeg":return u.utils.radToDeg(h.radians);default:throw h.type===void 0?new Error(`Operation type is undefined. This usually means the operation object is malformed or not properly initialized. Operation: ${JSON.stringify(h,null,2).slice(0,200)}...`):new Error(`Unsupported operation type: ${h.type}. Operation: ${JSON.stringify(h,null,2)}`)}}}}),Cci=yt({"node_modules/ms/index.js"(t,e){var n=1e3,o=n*60,i=o*60,r=i*24,s=r*7,a=r*365.25;e.exports=function(u,h){h=h||{};var d=typeof u;if(d==="string"&&u.length>0)return A(u);if(d==="number"&&isFinite(u))return h.long?l(u):c(u);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(u))};function A(u){if(u=String(u),!(u.length>100)){var h=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(u);if(h){var d=parseFloat(h[1]),m=(h[2]||"ms").toLowerCase();switch(m){case"years":case"year":case"yrs":case"yr":case"y":return d*a;case"weeks":case"week":case"w":return d*s;case"days":case"day":case"d":return d*r;case"hours":case"hour":case"hrs":case"hr":case"h":return d*i;case"minutes":case"minute":case"mins":case"min":case"m":return d*o;case"seconds":case"second":case"secs":case"sec":case"s":return d*n;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return d;default:return}}}}function c(u){var h=Math.abs(u);return h>=r?Math.round(u/r)+"d":h>=i?Math.round(u/i)+"h":h>=o?Math.round(u/o)+"m":h>=n?Math.round(u/n)+"s":u+"ms"}function l(u){var h=Math.abs(u);return h>=r?g(u,h,r,"day"):h>=i?g(u,h,i,"hour"):h>=o?g(u,h,o,"minute"):h>=n?g(u,h,n,"second"):u+" ms"}function g(u,h,d,m){var p=h>=d*1.5;return Math.round(u/d)+" "+m+(p?"s":"")}}}),yci=yt({"node_modules/debug/src/common.js"(t,e){function n(o){r.debug=r,r.default=r,r.coerce=g,r.disable=c,r.enable=a,r.enabled=l,r.humanize=Cci(),r.destroy=u,Object.keys(o).forEach(h=>{r[h]=o[h]}),r.names=[],r.skips=[],r.formatters={};function i(h){let d=0;for(let m=0;m<h.length;m++)d=(d<<5)-d+h.charCodeAt(m),d|=0;return r.colors[Math.abs(d)%r.colors.length]}r.selectColor=i;function r(h){let d,m=null,p,_;function f(...I){if(!f.enabled)return;const C=f,y=Number(new Date),x=y-(d||y);C.diff=x,C.prev=d,C.curr=y,d=y,I[0]=r.coerce(I[0]),typeof I[0]!="string"&&I.unshift("%O");let E=0;I[0]=I[0].replace(/%([a-zA-Z%])/g,(b,Q)=>{if(b==="%%")return"%";E++;const w=r.formatters[Q];if(typeof w=="function"){const D=I[E];b=w.call(C,D),I.splice(E,1),E--}return b}),r.formatArgs.call(C,I),(C.log||r.log).apply(C,I)}return f.namespace=h,f.useColors=r.useColors(),f.color=r.selectColor(h),f.extend=s,f.destroy=r.destroy,Object.defineProperty(f,"enabled",{enumerable:!0,configurable:!1,get:()=>m!==null?m:(p!==r.namespaces&&(p=r.namespaces,_=r.enabled(h)),_),set:I=>{m=I}}),typeof r.init=="function"&&r.init(f),f}function s(h,d){const m=r(this.namespace+(typeof d>"u"?":":d)+h);return m.log=this.log,m}function a(h){r.save(h),r.namespaces=h,r.names=[],r.skips=[];const d=(typeof h=="string"?h:"").trim().replace(/\s+/g,",").split(",").filter(Boolean);for(const m of d)m[0]==="-"?r.skips.push(m.slice(1)):r.names.push(m)}function A(h,d){let m=0,p=0,_=-1,f=0;for(;m<h.length;)if(p<d.length&&(d[p]===h[m]||d[p]==="*"))d[p]==="*"?(_=p,f=m,p++):(m++,p++);else if(_!==-1)p=_+1,f++,m=f;else return!1;for(;p<d.length&&d[p]==="*";)p++;return p===d.length}function c(){const h=[...r.names,...r.skips.map(d=>"-"+d)].join(",");return r.enable(""),h}function l(h){for(const d of r.skips)if(A(h,d))return!1;for(const d of r.names)if(A(h,d))return!0;return!1}function g(h){return h instanceof Error?h.stack||h.message:h}function u(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return r.enable(r.load()),r}e.exports=n}}),xci=yt({"node_modules/debug/src/browser.js"(t,e){t.formatArgs=o,t.save=i,t.load=r,t.useColors=n,t.storage=s(),t.destroy=(()=>{let 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 n(){if(typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs))return!0;if(typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))return!1;let 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 o(A){if(A[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+A[0]+(this.useColors?"%c ":" ")+"+"+e.exports.humanize(this.diff),!this.useColors)return;const c="color: "+this.color;A.splice(1,0,c,"color: inherit");let l=0,g=0;A[0].replace(/%[a-zA-Z%]/g,u=>{u!=="%%"&&(l++,u==="%c"&&(g=l))}),A.splice(g,0,c)}t.log=console.debug||console.log||(()=>{});function i(A){try{A?t.storage.setItem("debug",A):t.storage.removeItem("debug")}catch{}}function r(){let A;try{A=t.storage.getItem("debug")||t.storage.getItem("DEBUG")}catch{}return!A&&typeof RYe<"u"&&"env"in RYe&&(A=RYe.env.DEBUG),A}function s(){try{return localStorage}catch{}}e.exports=yci()(t);var{formatters:a}=e.exports;a.j=function(A){try{return JSON.stringify(A)}catch(c){return"[UnexpectedJSONParseError]: "+c.message}}}}),cUe=["translucent","opaque","hidden"],Eci=t=>cUe[(cUe.indexOf(t)+1)%cUe.length],ntn={boardBody:!0,topCopper:!0,bottomCopper:!0,keepout:!0,adhesive:!1,solderPaste:!1,topSilkscreen:!0,bottomSilkscreen:!0,topMask:!0,bottomMask:!0,throughHoleModels:!0,smtModels:!0,translucentModels:!0,modelsNotInPosFile:!1,modelsMarkedDNP:!1,modelBoundingBoxes:!1,threedAxis:!1,pcbNotes:!1,backgroundStart:!0,backgroundEnd:!0,enclosure:"translucent"},otn=ee.createContext(void 0),Bci=({children:t})=>{const[e,n]=ee.useState(ntn),o=ee.useCallback((s,a)=>{n(A=>({...A,[s]:a}))},[]),i=ee.useCallback(()=>{n(ntn)},[]),r=ee.useMemo(()=>({visibility:e,setLayerVisibility:o,resetToDefaults:i}),[e,o,i]);return U.jsx(otn.Provider,{value:r,children:t})},fR=()=>{const t=ee.useContext(otn);if(!t)throw new Error("useLayerVisibility must be used within a LayerVisibilityProvider");return t},lUe=1.2;function itn(t){return ee.useMemo(()=>{if(!t)return lUe;try{return Cr(t).pcb_board.list()[0]?.thickness??lUe}catch{return lUe}},[t])}var rtn=ee.createContext(null),j1=()=>{const t=ee.useContext(rtn);if(!t)throw new Error("useThree must be used within a ThreeProvider");return t},sq=(t,e=[])=>{const{addFrameListener:n,removeFrameListener:o}=j1();Ms.useEffect(()=>(n(t),()=>o(t)),[n,o,...e])},aq={clickToInteractOverlay:100,htmlElements:95,orientationCube:95,contextMenu:90,appearanceMenu:91},stn=({children:t,position:e,style:n})=>{const{camera:o,renderer:i}=j1(),r=ee.useRef(document.createElement("div")),[s,a]=ee.useState(null);return ee.useEffect(()=>{const A=i?.domElement.parentNode;if(A)return A.style.position!=="relative"&&A.style.position!=="absolute"&&(A.style.position="relative"),A.appendChild(r.current),a(xRt.createPortal(t,r.current)),()=>{A.contains(r.current)&&A.removeChild(r.current)}},[i,t]),sq(()=>{if(!o||!r.current||!i)return;const A=new jt(...e);A.project(o);const c=i.domElement.getBoundingClientRect(),l=Math.round((A.x+1)/2*c.width),g=Math.round((-A.y+1)/2*c.height);r.current.style.position="absolute",r.current.style.left=`${l}px`,r.current.style.top=`${g}px`,r.current.style.pointerEvents="none",r.current.style.zIndex=aq.htmlElements.toString(),n&&Object.assign(r.current.style,n)},[o,i,e,n]),s},atn={in:25.4,inch:25.4,mil:.0254,mm:1,m:1e3,cm:10,ft:304.8,feet:304.8},Ja=t=>{let e=typeof t=="number"?"mm":t.replace(/^[^a-zA-Z]+/g,"").toLowerCase();e||(e="mm");const n=typeof t=="number"?t:Number.parseFloat(t.split(e)[0]);if(e in atn)return n*atn[e];throw new Error(`Unsupported unit: ${e}`)},Nh=Ja,Sci=Object.defineProperty,bci=(t,e)=>{for(var n in e)Sci(t,n,{get:e[n],enumerable:!0})},DS={};bci(DS,{axial:()=>o0i,bga:()=>rli,breakoutheaders:()=>p0i,cap:()=>Rci,dfn:()=>Fli,diode:()=>Nci,dip:()=>Pci,electrolytic:()=>udi,hc49:()=>I0i,jst:()=>Pui,led:()=>Tci,lqfp:()=>h0i,m2host:()=>Tdi,melf:()=>Fgi,micromelf:()=>Ggi,minimelf:()=>Pgi,mlp:()=>hli,mountedpcbmodule:()=>Fdi,ms012:()=>Kli,ms013:()=>zli,msop:()=>Hui,pad:()=>C0i,pinrow:()=>Hli,platedhole:()=>Sdi,potentiometer:()=>cdi,pushbutton:()=>A0i,qfn:()=>gli,qfp:()=>dli,quad:()=>MG,radial:()=>s0i,res:()=>nli,sma:()=>Vgi,smb:()=>Zgi,smbf:()=>hdi,smc:()=>oui,smf:()=>jgi,smtpad:()=>Edi,sod110:()=>Mui,sod123:()=>Zli,sod123f:()=>ngi,sod123fl:()=>sgi,sod123w:()=>k0i,sod128:()=>hgi,sod323:()=>O0i,sod323f:()=>$0i,sod323fl:()=>Vui,sod323w:()=>Gui,sod523:()=>b0i,sod723:()=>lgi,sod80:()=>D0i,sod882:()=>W0i,sod882d:()=>Ngi,sod923:()=>K0i,soic:()=>ali,solderjumper:()=>edi,son:()=>jui,sop8:()=>w0i,sot:()=>Qdi,sot223:()=>aui,sot23:()=>wli,sot23w:()=>pui,sot25:()=>Rli,sot323:()=>Idi,sot343:()=>Mdi,sot363:()=>Eli,sot457:()=>odi,sot563:()=>Yli,sot723:()=>Wli,sot886:()=>bli,sot89:()=>Bgi,sot963:()=>sdi,ssop:()=>_li,stampboard:()=>l0i,stampreceiver:()=>d0i,to220:()=>btn,to220f:()=>Qgi,to92:()=>B0i,to92l:()=>Gdi,to92s:()=>xui,tqfp:()=>uli,tssop:()=>Cli,vson:()=>qui,vssop:()=>kui});var nr=(t,e,n)=>({type:"pcb_silkscreen_text",pcb_silkscreen_text_id:"silkscreen_text_1",font:"tscircuit2024",font_size:n,pcb_component_id:"pcb_component_1",text:"{REF}",layer:"top",anchor_position:{x:t,y:e},anchor_alignment:"center"}),qi=Pt({norefdes:je().optional().describe("disable reference designator label"),invert:je().optional().describe("hint to invert the orientation of the 3D model"),faceup:je().optional().describe("The male pin header should face upwards, out of the top layer"),nosilkscreen:je().optional().describe("omit all silkscreen elements from the footprint")}),Fa=(t,e,n,o,i)=>({pcb_plated_hole_id:"",type:"pcb_plated_hole",shape:"circle",x:e,y:n,hole_diameter:Ja(o),outer_diameter:Ja(i),pcb_port_id:"",layers:["top","bottom"],port_hints:[t.toString()]}),xx=t=>{const{pn:e,x:n,y:o,holeDiameter:i,rectPadWidth:r,rectPadHeight:s,holeOffsetX:a=0,holeOffsetY:A=0,rectBorderRadius:c}=t;return{pcb_plated_hole_id:"",type:"pcb_plated_hole",shape:"circular_hole_with_rect_pad",x:n,y:o,hole_diameter:Ja(i),hole_shape:"circle",pad_shape:"rect",rect_pad_width:Ja(r),rect_pad_height:Ja(s),...c!==void 0&&{rect_border_radius:c},pcb_port_id:"",layers:["top","bottom"],port_hints:[e.toString()],hole_offset_x:a,hole_offset_y:A}},cde=Array.from({length:9},(t,e)=>Math.cos(e/8*Math.PI-Math.PI)).map(t=>({x:t,y:-Math.sqrt(1-t**2)})),ky=t=>{if(t.length<2)throw new Error("Rect union outline requires at least two bounds");for(const c of t)if(c.minX>=c.maxX||c.minY>=c.maxY)throw new Error("Each rectangle bound must have min < max on both axes");for(let c=1;c<t.length;c++){const l=t[c-1],g=t[c];if(g.minX<l.minX||g.maxX>l.maxX||g.minY>l.minY||g.maxY<l.maxY)throw new Error("Bounds must be ordered outer-to-inner with tighter X and larger Y span")}const e=()=>{const c=[];let l=t.length-1;for(c.push({x:t[l].minX,y:t[l].maxY});l>0;){const g=t[l],u=t[l-1];c.push({x:g.minX,y:u.maxY}),c.push({x:u.minX,y:u.maxY}),l-=1}return c},n=()=>{const c=[];let l=t.length-1;for(c.push({x:t[l].maxX,y:t[l].maxY});l>0;){const g=t[l],u=t[l-1];c.push({x:g.maxX,y:u.maxY}),c.push({x:u.maxX,y:u.maxY}),l-=1}return c},o=()=>{const c=[];let l=t.length-1;for(c.push({x:t[l].maxX,y:t[l].minY});l>0;){const g=t[l],u=t[l-1];c.push({x:g.maxX,y:u.minY}),c.push({x:u.maxX,y:u.minY}),l-=1}return c},i=()=>{const c=[];let l=t.length-1;for(c.push({x:t[l].minX,y:t[l].minY});l>0;){const g=t[l],u=t[l-1];c.push({x:g.minX,y:u.minY}),c.push({x:u.minX,y:u.minY}),l-=1}return c},r=e(),s=n(),a=o(),A=i();return[...r.reverse(),...s,...a.reverse(),...A]};function QP(t){return typeof t=="string"?t.trim().toLowerCase().endsWith("mil")?parseFloat(t)*.0254:parseFloat(t):Number(t)}var lde=Eo([Z(),ft()]).transform(t=>QP(t)),Qci=t=>qi.extend({fn:Z(),num_pins:ft().optional().default(6),wide:je().optional(),narrow:je().optional(),w:lde.optional(),p:lde.default(t.p??"2.54mm"),id:lde.optional(),od:lde.optional(),nosquareplating:je().optional().default(!1).describe("do not use rectangular pad for pin 1")}).transform(e=>(!e.id&&!e.od?Math.abs(e.p-1.27)<.01?(e.id=QP("0.55mm"),e.od=QP("0.95mm")):(e.id=QP("0.8mm"),e.od=QP("1.6mm")):e.id?e.od||(e.od=e.id*(1.5/1)):e.id=e.od*(1/1.5),e.w||(e.wide?e.w=QP("600mil"):e.narrow?e.w=QP("300mil"):e.w=QP(t.w??"300mil")),e)),vci=Qci({}),Atn=(t,e,n,o,i)=>{const r=t/2,s=e<=r,a=r-1,A=o,c=A*a;return s?{x:-n/2,y:c/2-(e-1)*A}:{x:n/2,y:-c/2+(e-r-1)*A}},Pci=t=>{const e=vci.parse(t),n=[];for(let _=0;_<e.num_pins;_++){const{x:f,y:I}=Atn(e.num_pins,_+1,e.w,e.p??2.54,e.nosquareplating);if(_===0&&!e.nosquareplating){n.push(xx({pn:_+1,x:f,y:I,holeDiameter:e.id??"0.8mm",rectPadWidth:e.od??"1mm",rectPadHeight:e.od??"1mm"}));continue}n.push(Fa(_+1,f,I,e.id??"0.8mm",e.od??"1mm"))}const o=(e.num_pins/2-1)*e.p+e.od,r=e.w-e.od-1,s=(e.num_pins/2-1)*e.p+e.od+.4,a={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-r/2,y:-s/2},{x:-r/2,y:s/2},...cde.map(({x:_,y:f})=>({x:_*r/6,y:f*r/6+s/2})),{x:r/2,y:s/2},{x:r/2,y:-s/2},{x:-r/2,y:-s/2}],type:"pcb_silkscreen_path",stroke_width:.1},A=[];for(let _=0;_<e.num_pins;_++){const f=_<e.num_pins/2,I=.6,{y:C}=Atn(e.num_pins,_+1,e.w,e.p??2.54,e.nosquareplating),y=f?-e.w/2-e.od/2-I:e.w/2+e.od/2+I,x=C;A.push({type:"pcb_fabrication_note_text",pcb_fabrication_note_text_id:`pin_${_+1}`,layer:"top",pcb_component_id:`pin_${_+1}`,text:`{pin${_+1}}`,anchor_position:{x:y,y:x},font_size:.3,font:"tscircuit2024",anchor_alignment:"top_left"})}const c=nr(0,s/2+.5,.4),l=e.w+e.od,g=o,u=l/2+.25,h=u,d=g/2+.72,m=d,p={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",outline:ky([{minX:-u,maxX:u,minY:-m,maxY:m},{minX:-h,maxX:h,minY:-d,maxY:d}]),layer:"top"};return{circuitJson:[...n,a,c,...A,p],parameters:e}},yi=(t,e,n,o,i,r)=>({type:"pcb_smtpad",x:e,y:n,width:o,height:i,layer:"top",shape:"rect",...r!==void 0&&{corner_radius:r},pcb_smtpad_id:"",port_hints:Array.isArray(t)?t.map(s=>s.toString()):[t.toString()]}),ctn=[{imperial:"01005",metric:"0402",p_mm_min:.5,pw_mm_min:.4,ph_mm_min:.3,w_mm_min:.58,h_mm_min:.21,courtyard_width_mm:1.2,courtyard_height_mm:.6},{imperial:"0504",metric:"1310",p_mm_min:1.1,pw_mm_min:.65,ph_mm_min:1.3,w_mm_min:.58,h_mm_min:.21},{imperial:"1812",metric:"4532",p_mm_min:4.275,pw_mm_min:1.125,ph_mm_min:3.4,w_mm_min:5.4,h_mm_min:3.4,courtyard_width_mm:5.9,courtyard_height_mm:3.9,nonpolarizedSilkscreen:{line_half_length_mm:1.386252,line_y_mm:1.71,stroke_width_mm:.12}},{imperial:"0201",metric:"0603",p_mm_min:.66,pw_mm_min:.46,ph_mm_min:.4,w_mm_min:.9,h_mm_min:.3,courtyard_width_mm:1.4,courtyard_height_mm:.7},{imperial:"0402",metric:"1005",p_mm_min:1.02,pw_mm_min:.54,ph_mm_min:.64,w_mm_min:1.56,h_mm_min:.64,courtyard_width_mm:1.86,courtyard_height_mm:.94,nonpolarizedSilkscreen:{line_half_length_mm:.153641,line_y_mm:.38,stroke_width_mm:.12}},{imperial:"0603",metric:"1608",p_mm_min:1.65,pw_mm_min:.8,ph_mm_min:.95,w_mm_min:2.45,h_mm_min:.95,courtyard_width_mm:2.96,courtyard_height_mm:1.46,nonpolarizedSilkscreen:{line_half_length_mm:.237258,line_y_mm:.5225,stroke_width_mm:.12}},{imperial:"0805",metric:"2012",p_mm_min:1.825,pw_mm_min:1.025,ph_mm_min:1.4,w_mm_min:2.8499999999999996,h_mm_min:1.4,courtyard_width_mm:3.36,courtyard_height_mm:1.9,nonpolarizedSilkscreen:{line_half_length_mm:.227064,line_y_mm:.735,stroke_width_mm:.12}},{imperial:"1206",metric:"3216",p_mm_min:2.925,pw_mm_min:1.125,ph_mm_min:1.75,w_mm_min:4.05,h_mm_min:1.75,courtyard_width_mm:4.56,courtyard_height_mm:2.26,nonpolarizedSilkscreen:{line_half_length_mm:.727064,line_y_mm:.91,stroke_width_mm:.12}},{imperial:"1210",metric:"3225",p_mm_min:2.925,pw_mm_min:1.125,ph_mm_min:2.65,w_mm_min:4.05,h_mm_min:2.65,courtyard_width_mm:4.56,courtyard_height_mm:3.16,nonpolarizedSilkscreen:{line_half_length_mm:.723737,line_y_mm:1.355,stroke_width_mm:.12}},{imperial:"2010",metric:"5025",p_mm_min:4.625,pw_mm_min:1.225,ph_mm_min:2.65,w_mm_min:5.85,h_mm_min:2.65,courtyard_width_mm:6.36,courtyard_height_mm:3.16,nonpolarizedSilkscreen:{line_half_length_mm:1.527064,line_y_mm:1.36,stroke_width_mm:.12}},{imperial:"2512",metric:"6332",p_mm_min:5.925,pw_mm_min:1.225,ph_mm_min:3.35,w_mm_min:7.15,h_mm_min:3.35,courtyard_width_mm:7.66,courtyard_height_mm:3.86,nonpolarizedSilkscreen:{line_half_length_mm:2.177064,line_y_mm:1.71,stroke_width_mm:.12}}],wci=Object.fromEntries(ctn.map(t=>[t.metric,t])),Mci=Object.fromEntries(ctn.map(t=>[t.imperial,t])),Dci=(t,e)=>({type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:0,y:0},width:t,height:e,layer:"top"});qi.extend({fn:Z().optional(),string:Z().optional(),tht:je(),p:he.optional(),pw:he.optional(),ph:he.optional(),metric:ct.optional(),imperial:ct.optional(),w:he.optional(),h:he.optional(),nonpolarized:je().optional(),textbottom:je().optional(),roundedPads:je().optional()});var gde=t=>{let{fn:e,tht:n,p:o,pw:i,ph:r,metric:s,imperial:a,w:A,h:c,nonpolarized:l,textbottom:g,roundedPads:u,string:h}=t;if(typeof A=="string"&&(A=Nh(A)),typeof c=="string"&&(c=Nh(c)),typeof o=="string"&&(o=Nh(o)),typeof i=="string"&&(i=Nh(i)),typeof r=="string"&&(r=Nh(r)),c!==void 0&&A!==void 0&&c>A)throw new Error("height cannot be greater than width (rotated footprint not yet implemented)");let d;if(s&&(d=wci[s]),a&&(d=Mci[a]),d&&(A=d.w_mm_min,c=d.h_mm_min,o=d.p_mm_min,i=d.pw_mm_min,r=d.ph_mm_min),o===void 0||i===void 0||r===void 0)throw new Error("Could not determine required pad dimensions (p, pw, ph)");let m=[];const p=e==="res"&&(l===!0||typeof h!="string"||/^res(?:\d{4}|\d{5})(?:_|$)/i.test(h))?d?.nonpolarizedSilkscreen:void 0;if(p?.stroke_width_mm){const{line_half_length_mm:y=0,line_y_mm:x=0,stroke_width_mm:E}=p;m=[{type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-y,y:x},{x:y,y:x}],stroke_width:E,pcb_silkscreen_path_id:""},{type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-y,y:-x},{x:y,y:-x}],stroke_width:E,pcb_silkscreen_path_id:""}]}else m=[{type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:o/2,y:r/2+.4},{x:-o/2-i/2-.2,y:r/2+.4},{x:-o/2-i/2-.2,y:-r/2-.4},{x:o/2,y:-r/2-.4}],stroke_width:.1,pcb_silkscreen_path_id:""}];const _=g?-r/2-.9:r/2+.9,f=nr(0,_,.2),I=d?.courtyard_width_mm&&d.courtyard_height_mm?Dci(d.courtyard_width_mm,d.courtyard_height_mm):null,C=u?Math.min(.125,Math.min(i,r)/8):void 0;return n?[Fa(1,-o/2,0,i,i*1/.8),Fa(2,o/2,0,i,i*1/.8),...m,f,...I?[I]:[]]:[yi(["1","left"],-o/2,0,i,r,C),yi(["2","right"],o/2,0,i,r,C),...m,f,...I?[I]:[]]},Nci=t=>({circuitJson:gde({...t,roundedPads:!0}),parameters:t}),Rci=t=>({circuitJson:gde(t),parameters:t}),Tci=t=>({circuitJson:gde(t).map(n=>n.type!=="pcb_silkscreen_path"?n:{...n,route:n.route.map(o=>({...o,x:-o.x}))}),parameters:t}),wG=t=>{const{padSpacing:e,padWidth:n,padHeight:o,padPitch:i,numRows:r,textbottom:s,courtyardOutline:a}=t,A=[],c=(r-1)*(i/2);for(let Q=0;Q<r;Q++)A.push(c-Q*i);const l=[];A.forEach((Q,w)=>{l.push(yi(w+1,-e/2,Q,n,o))}),A.slice().reverse().forEach((Q,w)=>{l.push(yi(w+r+1,e/2,Q,n,o))});const g=Math.max(...A)+o/2+.4,u=Math.min(...A)-o/2-.4,h=-e/2-n/2-.4,d=e/2+n/2+.4,m={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:d*.5,y:g},{x:h*.5,y:g}],stroke_width:.12,pcb_silkscreen_path_id:"silkscreen_top"},p={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:d*.5,y:u},{x:h*.5,y:u}],stroke_width:.12,pcb_silkscreen_path_id:"silkscreen_bottom"},_=-e/2,f=Math.max(...A),I=.2,C=_-n/2-.1,y=f+o/2+.1,x={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"pin1_marker",route:[{x:C,y},{x:C-I,y},{x:C,y:y+I},{x:C,y}],stroke_width:.1},E=s?u-.9:g+.9,B=nr(0,E,.2),b=a?{type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",layer:"top",outline:a}:null;return[...l,m,p,x,B,...b?[b]:[]]},kci=qi.extend({pw:he.default("0.5mm"),ph:he.default("0.4mm"),p:he.default("0.7mm"),textbottom:je().optional(),convex:je().optional(),concave:je().optional()}),Fci=1,Lci=t=>{const e=kci.parse(t);if(e.concave===!0)return[];const n=Nh(e.pw),o=Nh(e.ph),i=Nh(e.p);return wG({padSpacing:Fci,padWidth:n,padHeight:o,padPitch:i,numRows:2,textbottom:e.textbottom,convex:e.convex,concave:e.concave,courtyardOutline:[{x:-1,y:.95},{x:-1,y:-.95},{x:1,y:-.95},{x:1,y:.95}]})},Hci=qi.extend({pw:he.default("0.5mm"),ph:he.default("0.32mm"),p:he.default("0.5mm"),textbottom:je().optional(),convex:je().optional(),concave:je().optional()}),Oci=1,Gci=t=>{const e=Hci.parse(t),n=Nh(e.pw),o=Nh(e.ph),i=Nh(e.p);return wG({padSpacing:Oci,padWidth:n,padHeight:o,padPitch:i,numRows:4,textbottom:e.textbottom,convex:e.convex,concave:e.concave,courtyardOutline:[{x:-1,y:1.25},{x:-1,y:-1.25},{x:1,y:-1.25},{x:1,y:1.25}]})},Yci=qi.extend({pw:he.default("0.9mm"),ph:he.default("0.4mm"),p:he.default("0.8mm"),textbottom:je().optional(),convex:je().optional(),concave:je().optional()}),Uci=1.7,Kci=t=>{const e=Yci.parse(t),n=Nh(e.pw),o=Nh(e.ph),i=Nh(e.p);return wG({padSpacing:Uci,padWidth:n,padHeight:o,padPitch:i,numRows:2,textbottom:e.textbottom,convex:e.convex,concave:e.concave,courtyardOutline:[{x:-1.55,y:1.05},{x:-1.55,y:-1.05},{x:1.55,y:-1.05},{x:1.55,y:1.05}]})},Vci=qi.extend({pw:he.default("0.9mm"),ph:he.default("0.4mm"),p:he.default("0.8mm"),textbottom:je().optional(),convex:je().optional(),concave:je().optional()}),zci=1.7,Jci=t=>{const e=Vci.parse(t),n=Nh(e.pw),o=Nh(e.ph),i=Nh(e.p);return wG({padSpacing:zci,padWidth:n,padHeight:o,padPitch:i,numRows:4,textbottom:e.textbottom,convex:e.convex,concave:e.concave,courtyardOutline:[{x:-1.55,y:1.88},{x:-1.55,y:-1.87},{x:1.55,y:-1.87},{x:1.55,y:1.88}]})},Wci=qi.extend({pw:he.default("0.7mm"),ph:he.default("0.64mm"),p:he.default("0.94mm"),textbottom:je().optional(),convex:je().optional(),concave:je().optional()}),jci=1.4,Xci=t=>{const e=Wci.parse(t),n=Nh(e.pw),o=Nh(e.ph),i=Nh(e.p);return wG({padSpacing:jci,padWidth:n,padHeight:o,padPitch:i,numRows:2,textbottom:e.textbottom,convex:e.convex,concave:e.concave,courtyardOutline:[{x:-1.3,y:1.05},{x:-1.3,y:-1.05},{x:1.3,y:-1.05},{x:1.3,y:1.05}]})},qci=qi.extend({pw:he.default("0.9mm"),ph:he.default("0.9mm"),p:he.default("1.34mm"),textbottom:je().optional(),convex:je().optional(),concave:je().optional()}),$ci=3,Zci=t=>{const e=qci.parse(t),n=Nh(e.pw),o=Nh(e.ph),i=Nh(e.p);return wG({padSpacing:$ci,padWidth:n,padHeight:o,padPitch:i,numRows:4,textbottom:e.textbottom,convex:e.convex,concave:e.concave,courtyardOutline:[{x:-2.21,y:2.85},{x:-2.21,y:-2.85},{x:2.2,y:-2.85},{x:2.2,y:2.85}]})},eli=t=>{const e=t.array??t.x;if(typeof e=="number")return Number.isNaN(e)?void 0:e;if(typeof e=="string"){const n=Number.parseInt(e,10);return Number.isNaN(n)?void 0:n}if(typeof t.imperial=="string"){const o=t.imperial.match(/x(2|4)$/)?.[1];if(o)return Number.parseInt(o,10)}},tli=t=>t?(typeof t=="number"?`${t}`:t).split(/[_x]/)[0]:void 0,nli=t=>{const e=eli(t),n=tli(t.imperial);return e===2&&n==="0402"?{circuitJson:Lci(t),parameters:t}:e===4&&n==="0402"?{circuitJson:Gci(t),parameters:t}:e===2&&n==="0603"?{circuitJson:Kci(t),parameters:t}:e===4&&n==="0603"?{circuitJson:Jci(t),parameters:t}:e===2&&n==="0606"?{circuitJson:Xci(t),parameters:t}:e===4&&n==="1206"?{circuitJson:Zci(t),parameters:t}:{circuitJson:gde(t),parameters:t}},ltn=(t,{x:e,y:n,radius:o})=>({type:"pcb_smtpad",x:e,y:n,radius:o,layer:"top",shape:"circle",pcb_smtpad_id:"",port_hints:Array.isArray(t)?t.map(i=>i.toString()):[t.toString()]}),gtn="ABCDEFGHIJKLMNOPQRSTUVWXYZ",ude=Z().transform(t=>{const[e,n]=t.split(/[x ]/);return{x:parseFloat(e??""),y:parseFloat(n??"")}}).pipe(Pt({x:ft(),y:ft()})),oli=Z().or(dn(Ju())).transform(t=>Array.isArray(t)?t:(t.startsWith("(")&&t.endsWith(")")&&(t=t.slice(1,-1)),t.split(",").map(e=>{const n=Number(e);return isNaN(n)?e:n}))).pipe(dn(Z().or(ft()))),ili=qi.extend({fn:Z(),num_pins:ft().optional().default(64),grid:ude.optional(),p:ct.default("0.8mm"),w:he.optional(),h:he.optional(),ball:he.optional().describe("ball diameter"),pad:he.optional().describe("pad width/height"),circularpads:je().optional().describe("use circular pads"),tlorigin:je().optional(),blorigin:je().optional(),trorigin:je().optional(),brorigin:je().optional(),missing:oli.default([])}).transform(t=>{let e="tl";if(t.blorigin&&(e="bl"),t.trorigin&&(e="tr"),t.brorigin&&(e="br"),!t.grid){const o=Math.ceil(Math.sqrt(t.num_pins));t.grid={x:o,y:o}}return t.missing&&(t.missing=t.missing.map(o=>{if(typeof o=="number")return o;if(o==="center")return"center";if(o==="topleft")return"topleft";const i=o.match(/([A-Z]+)(\d+)/);if(!i)return o;const r=gtn.indexOf(i[1]),s=Number.parseInt(i[2])-1;return r*t.grid.x+s+1})),{...t,origin:e}}),rli=t=>{const e=ili.parse(t);let{num_pins:n,grid:o,p:i,w:r,h:s,ball:a,pad:A,missing:c}=e;a??=.75/1.27*i,A??=a*.8;const l=[],g=(c??[]).filter(Y=>typeof Y=="number"),u=o.x*o.y-n;if(c.length===0&&u>0&&(Math.sqrt(u)%1===0?c.push("center"):u===1&&c.push("topleft")),c?.includes("center")){const Y=Math.floor(Math.sqrt(u)),X=Math.floor((o.x-Y)/2),te=Math.floor((o.y-Y)/2);for(let j=te;j<te+Y;j++)for(let J=X;J<X+Y;J++)g.push(j*o.x+J+1)}c?.includes("topleft")&&g.push(1);const h=new Set(g);let d=0;for(let Y=0;Y<o.y;Y++)for(let X=0;X<o.x;X++){const te=(X-(o.x-1)/2)*i,j=(Y-(o.y-1)/2)*i;let J=X,ie=Y;switch(e.origin){case"bl":J=X,ie=o.y-1-Y;break;case"br":J=o.x-1-X,ie=o.y-1-Y;break;case"tr":J=o.x-1-X,ie=Y;break}let oe=ie*o.x+J+1;if(h.has(oe)){d++;continue}oe-=d;const ne=[oe,`${gtn[ie]}${J+1}`];l.push(e.circularpads?ltn(ne,{x:te,y:j,radius:A/2}):yi(ne,te,j,A,A))}const m=nr(0,o.y*i/2,.2),p=i/6;let _;const f=o.x*i/2,I=o.y*i/2;switch(e.origin){case"bl":_=[{x:-f,y:-I},{x:-f,y:-I-p},{x:-f-p,y:-I},{x:-f,y:-I}];break;case"br":_=[{x:f,y:-I},{x:f,y:-I-p},{x:f+p,y:-I},{x:f,y:-I}];break;case"tr":_=[{x:f,y:I},{x:f,y:I+p},{x:f+p,y:I},{x:f,y:I}];break;default:_=[{x:-f,y:I},{x:-f,y:I+p},{x:-f-p,y:I},{x:-f,y:I}];break}const C={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"pin1_marker",route:_,stroke_width:.05},y=(o.x-1)*i+A,x=(o.y-1)*i+A,E=r??y,B=s??x,b=Math.max(y/2,E/2),Q=Math.max(x/2,B/2),w=1.715,D=1.765,k=b+w,R=k,H=Q+D,G=H,K={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",outline:ky([{minX:-k,maxX:k,minY:-G,maxY:G},{minX:-R,maxX:R,minY:-H,maxY:H}]),layer:"top"};return{circuitJson:[...l,m,C,K],parameters:e}},dde=(t,e,n,o,i)=>({type:"pcb_smtpad",x:e,y:n,width:o,height:i,radius:i/2,layer:"top",shape:"pill",pcb_smtpad_id:"",port_hints:Array.isArray(t)?t.map(r=>r.toString()):[t.toString()]}),IR=t=>qi.extend({fn:Z(),num_pins:ft().optional().default(8),w:he.default(he.parse(t.w??"5.3mm")),p:he.default(he.parse(t.p??"1.27mm")),pw:he.default(he.parse(t.pw??"0.6mm")),pl:he.default(he.parse(t.pl??"1.0mm")),legsoutside:je().optional().default(t.legsoutside??!1),pillpads:je().optional().default(t.pillpads??!1),silkscreen_stroke_width:ft().optional().default(.1)}).transform(e=>(!e.pw&&!e.pl?(e.pw=he.parse("0.6mm"),e.pl=he.parse("1.0mm")):e.pw?e.pl||(e.pl=e.pw*(1/.6)):e.pw=e.pl*(.6/1),e)),sli=IR({}),gUe=t=>{t.widthincludeslegs!==void 0&&(t.legsoutside=!t.widthincludeslegs);const{num_pins:e,pn:n,w:o,p:i,pl:r,legsoutside:s}=t,a=e/2,A=n<=a,c=a-1,l=i,g=l*c,u=s?r/2:-r/2;return A?{x:-o/2-u,y:g/2-(n-1)*l}:{x:o/2+u,y:-g/2+(n-a-1)*l}},ali=t=>{const e=sli.parse(t);return{circuitJson:Aq(e),parameters:e}},Aq=t=>{const e=[];let n=0,o=0;for(let p=0;p<t.num_pins;p++){const{x:_,y:f}=gUe({num_pins:t.num_pins,pn:p+1,w:t.w,p:t.p,pl:t.pl,legsoutside:t.legsoutside});n=Math.max(n,Math.abs(_)+t.pl/2),o=Math.max(o,Math.abs(f)+t.pw/2),t.pillpads?e.push(dde(p+1,_,f,t.pl,t.pw)):e.push(yi(p+1,_,f,t.pl,t.pw))}const i=Math.min(1,t.p/2),r=t.w-(t.legsoutside?0:t.pl*2)-.2,s=(t.num_pins/2-1)*t.p+t.pw+i,a=nr(0,s/2+.4,s/12),A={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",stroke_width:t.silkscreen_stroke_width??.1,route:[{x:-r/2,y:-s/2},{x:-r/2,y:s/2},...cde.map(({x:p,y:_})=>({x:p*r/6,y:_*r/6+s/2})),{x:r/2,y:s/2},{x:r/2,y:-s/2},{x:-r/2,y:-s/2}]},c=t.w/2,l=s/2,g=Math.max(n,c)+.25,u=Math.min(o,l)+.25,h=Math.min(n,c)+.25,d=Math.max(o,l)+.25,m={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",layer:"top",outline:ky([{minX:-g,maxX:g,minY:-u,maxY:u},{minX:-h,maxX:h,minY:-d,maxY:d}])};return[...e,A,a,m]},utn=zn(["leftside","topside","rightside","bottomside","toppin","bottompin","leftpin","rightpin"]),Ali=({num_pins:t,cw:e,ccw:n,startingpin:o})=>{const i=[],r=t/4;let s=1;const a={};for(const A of o??[])a[A]=!0;!a.leftside&&!a.topside&&!a.rightside&&!a.bottomside&&(a.leftside=!0),!a.bottompin&&!a.leftpin&&!a.rightpin&&!a.toppin&&(a.leftside?a.toppin=!0:a.topside?a.rightpin=!0:a.rightside?a.bottompin=!0:a.bottomside&&(a.leftpin=!0)),a.leftside&&a.toppin?s=1:a.leftside&&a.bottompin?s=r:a.bottomside&&a.leftpin?s=r+1:a.bottomside&&a.rightpin?s=r*2:a.rightside&&a.bottompin?s=r*2+1:a.rightside&&a.toppin?s=r*3:a.topside&&a.rightpin?s=r*3+1:a.topside&&a.leftpin&&(s=r*4),i.push(-1);for(let A=0;A<t;A++)i[s]=A+1,n||!e?(s++,s>t&&(s=1)):(s--,s<1&&(s=t));return i},uUe=qi.extend({fn:Z(),cc:je().default(!0).optional(),ccw:je().default(!0).optional(),startingpin:Z().or(dn(utn)).transform(t=>typeof t=="string"?t.slice(1,-1).split(","):t).pipe(dn(utn)).optional(),num_pins:ft().optional().default(64),w:he.optional(),h:he.optional(),p:he.default(he.parse("0.5mm")),pw:he.optional(),pl:he.optional(),thermalpad:Eo([Xe(!0),ude]).optional(),legsoutside:je().default(!1)}),dUe=t=>{t.w&&!t.h?t.h=t.w:!t.w&&t.h&&(t.w=t.h);const e=t.num_pins/4;if(!t.p&&!t.pw&&!t.pl&&t.w){const n=e+4;t.p=t.w/n}return!t.p&&t.w&&t.h&&t.pw&&t.pl&&(t.p=(t.w-t.pl*2)/(e-1)),!t.w&&!t.h&&t.p&&(t.w=t.p*(e+4),t.h=t.w),t.p&&!t.pw&&!t.pl?(t.pw=t.p/2,t.pl=t.p/2):t.pw?t.pl||(t.pl=t.pw*(1/.6)):t.pw=t.pl*(.6/1),t},dtn=uUe.transform(dUe),cli=["left","bottom","right","top"],lli=t=>{const{pin_count:e,pn:n,w:o,h:i,p:r,pl:s,legsoutside:a}=t,A=e/4,c=cli[Math.floor((n-1)/A)],l=(n-1)%A,g=r*(A-1),u=r*(A-1),h=a?s/2:-s/2;switch(c){case"left":return{x:-o/2-h+.1,y:u/2-l*r,o:"vert"};case"bottom":return{x:-g/2+l*r,y:-i/2-h+.1,o:"horz"};case"right":return{x:o/2+h-.1,y:-u/2+l*r,o:"vert"};case"top":return{x:g/2-l*r,y:i/2+h-.1,o:"horz"};default:throw new Error("Invalid pin number")}},MG=t=>{const e=dtn.parse(t),n=[];let o=0,i=0;const r=Ali(e),s=e.num_pins/4;for(let I=0;I<e.num_pins;I++){const{x:C,y,o:x}=lli({pin_count:e.num_pins,pn:I+1,w:e.w,h:e.h,p:e.p??.5,pl:e.pl,legsoutside:e.legsoutside});let E=e.pw,B=e.pl;x==="vert"&&([E,B]=[B,E]);const b=r[I+1];o=Math.max(o,Math.abs(C)+E/2),i=Math.max(i,Math.abs(y)+B/2),n.push(yi(b,C,y,E,B))}if(e.thermalpad)if(typeof e.thermalpad=="boolean"){const I=e.p*(s-1)+e.pw,C=e.p*(s-1)+e.pw;o=Math.max(o,I/2),i=Math.max(i,C/2),n.push(yi(["thermalpad"],0,0,I,C))}else o=Math.max(o,e.thermalpad.x/2),i=Math.max(i,e.thermalpad.y/2),n.push(yi(["thermalpad"],0,0,e.thermalpad.x,e.thermalpad.y));const a=[];for(const[I,C,y]of[["top-left",-1,1],["bottom-left",-1,-1],["bottom-right",1,-1],["top-right",1,1]]){const x=e.w/2*C,E=e.h/2*y;let B="none",b=x,Q=E;const w=e.pw*2;r[1]===1&&I==="top-left"?B="in1":r[s*4]===1&&I==="top-left"||r[s*3+1]===1&&I==="top-right"?B="in2":r[s*3]===1&&I==="top-right"||r[s]===1&&I==="bottom-left"?B="in1":r[s+1]===1&&I==="bottom-left"?B="in2":r[s*2]===1&&I==="bottom-right"?B="in1":r[s*2+1]===1&&I==="bottom-right"&&(B="in2");const D=B==="in1"?1:-1;if(e.legsoutside){const k=B==="in1"?e.pl/2:e.pw/2,R=B==="in1"?e.pw/2:e.pl/2;b+=k*C*D,Q-=R*y*D}(B==="none"||e.legsoutside)&&a.push({layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:`pcb_silkscreen_path_${I}`,route:[{x:x-w*C,y:E},{x,y:E},{x,y:E-w*y}],type:"pcb_silkscreen_path",stroke_width:.1}),(B==="in1"||B==="in2")&&!e.legsoutside&&a.push({layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:`pcb_silkscreen_path_${I}_1`,route:[{x:x-w*C,y:E},{x:x-w*C/2,y:E}],type:"pcb_silkscreen_path",stroke_width:0},{layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:`pcb_silkscreen_path_${I}_2`,route:[{x,y:E-w*y/2},{x,y:E-w*y}],type:"pcb_silkscreen_path",stroke_width:.1}),(B==="in1"||B==="in2")&&a.push({layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:`pcb_silkscreen_path_${I}_3`,route:[{x:b-.2*-C,y:Q+.2*D},{x:b,y:Q},{x:b+.2*D*-C,y:Q+.2},{x:b-.2*-C,y:Q+.2*D}],type:"pcb_silkscreen_path",stroke_width:.1})}const A=nr(0,e.h/2+(e.legsoutside?e.pl*1.2:.5),.3),c=I=>Math.ceil(I/.05)*.05,l=(s-1)*e.p+e.pw,g=(s-1)*e.p+e.pw,u=l/2+.25,h=g/2+.25,d=e.w/2+.25,m=e.h/2+.25,p=Math.max(d,c(o+.25)),_=Math.max(m,c(i+.25)),f={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",layer:"top",outline:ky([{minX:-p,maxX:p,minY:-h,maxY:h},{minX:-d,maxX:d,minY:-m,maxY:m},{minX:-u,maxX:u,minY:-_,maxY:_}])};return{circuitJson:[...n,...a,A,f],parameters:e}};uUe.extend({}).transform(dUe);var gli=t=>(t.legsoutside=!1,t.pl||(t.pl=.875),t.pw||(t.pw=.25),MG(t)),uli=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 MG(t)},dli=t=>{t.legsoutside=!0;const e=dtn.parse(t);if(!t.p)switch(t.num_pins){case 44:case 64:t.p=.8;break;case 52:t.w===14?t.p=1:t.p=.65;break;case 208:t.p=.5;break}if(!t.pl)switch(t.num_pins){case 44:case 52:case 64:t.pl=2.25;break;case 208:t.pl=1.65;break;default:t.pl=e.pl*4;break}if(!t.pw)switch(t.num_pins){case 44:case 64:t.pw=.5;break;case 52:t.w===14?t.pw=.45:t.pw=.55;break;case 208:t.pw=.3;break;default:t.pw=e.pw;break}return MG(t)};uUe.extend({}).transform(dUe);var hli=t=>(t.legsoutside=!1,t.thermalpad===void 0&&(t.thermalpad=!0),MG(t)),mli=qi.extend({fn:Z(),num_pins:ft().optional().default(8),w:he.default(he.parse("3.9mm")),p:he.default(he.parse("1.27mm")),pw:he.optional(),pl:he.optional(),legsoutside:je().optional().default(!1),silkscreen_stroke_width:ft().optional().default(.1)}).transform(t=>(t.pw==null&&t.pl==null?(t.pw=he.parse("0.51mm"),t.pl=he.parse("1.1mm")):t.pw==null?t.pw=t.pl*(.51/1.1):t.pl==null&&(t.pl=t.pw*(1.1/.51)),t)),pli=t=>{const{num_pins:e,pn:n,w:o,p:i}=t,r=e/2,s=n<=r,a=r-1,A=i,c=A*a,l=o+he.parse("0.2mm"),g=(s?-1:1)*(l/2);return s?{x:g,y:c/2-(n-1)*A}:{x:g,y:-c/2+(n-r-1)*A}},_li=t=>{const e=mli.parse(t),n=[];for(let p=0;p<e.num_pins;p++){const{x:_,y:f}=pli({num_pins:e.num_pins,pn:p+1,w:e.w,p:e.p,pl:e.pl,legsoutside:e.legsoutside});n.push(yi(p+1,_,f,e.pl,e.pw))}const o=Math.min(1,e.p/2),i=e.w-(e.legsoutside?0:e.pl)-.2,r=(e.num_pins/2-1)*e.p+e.pw+o,s=nr(0,r/2+.4,r/12),a={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",stroke_width:e.silkscreen_stroke_width??.1,route:[{x:-i/2,y:-r/2},{x:-i/2,y:r/2},...cde.map(({x:p,y:_})=>({x:p*i/6,y:_*i/6+r/2})),{x:i/2,y:r/2},{x:i/2,y:-r/2},{x:-i/2,y:-r/2}]},A=(e.num_pins/2-1)*e.p+e.pw,c=e.legsoutside?e.w/2+e.pl:(e.w+.2)/2+e.pl/2,l=A/2,g=c+.25,u=g,h=l+.445,d=h,m={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",outline:ky([{minX:-g,maxX:g,minY:-d,maxY:d},{minX:-u,maxX:u,minY:-h,maxY:h}]),layer:"top"};return{circuitJson:[...n,a,s,m],parameters:e}},fli=qi.extend({fn:Z(),num_pins:ft().optional().default(8),w:he.default(he.parse("3.0mm")),p:he.default(he.parse("0.5mm")),pw:he.default(he.parse("0.30mm")),pl:he.default(he.parse("1.45mm")),legsoutside:je().optional().default(!0),silkscreen_stroke_width:ft().optional().default(.1)}),Ili=t=>{const{num_pins:e,pn:n,w:o,p:i,pl:r,legsoutside:s}=t,a=e/2,A=n<=a,c=a-1,l=i*c,g=s?r/2:-r/2;return A?{x:-o/2-g,y:l/2-(n-1)*i}:{x:o/2+g,y:-l/2+(n-a-1)*i}},Cli=t=>{const e={...t},n=e.p,o=typeof n=="string"||typeof n=="number"?he.parse(n):void 0,i=o!=null&&o<=he.parse("0.5mm"),r=fli.parse(e),s=[],a=i?r.w-he.parse("0.15mm"):r.w;for(let C=0;C<r.num_pins;C++){const{x:y,y:x}=Ili({num_pins:r.num_pins,pn:C+1,w:a,p:r.p,pl:r.pl,legsoutside:r.legsoutside});s.push(yi(C+1,y,x,r.pl,r.pw))}const A=Math.min(1,r.p/2),c=r.w-(r.legsoutside?0:r.pl*2)-.2,l=(r.num_pins/2-1)*r.p+r.pw+A,g=nr(0,l/2+.4,l/12),u={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",stroke_width:r.silkscreen_stroke_width??.1,route:[{x:-c/2,y:-l/2},{x:-c/2,y:l/2},...cde.map(({x:C,y})=>({x:C*c/6,y:y*c/6+l/2})),{x:c/2,y:l/2},{x:c/2,y:-l/2},{x:-c/2,y:-l/2}]},h=(r.num_pins/2-1)*r.p+r.pw,d=r.w/2+(r.legsoutside?r.pl:0),m=r.w/2+.25,p=d+.18,_=h/2+.25,f=_+.35,I={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",layer:"top",outline:ky([{minX:-p,maxX:p,minY:-_,maxY:_},{minX:-m,maxX:m,minY:-f,maxY:f}])};return{circuitJson:[...s,u,g,I],parameters:r}},yli=[{x:-1.45,y:.93},{x:-.73,y:.93},{x:-.73,y:1.1},{x:.73,y:1.1},{x:.73,y:.93},{x:1.45,y:.93},{x:1.45,y:-.93},{x:.73,y:-.93},{x:.73,y:-1.1},{x:-.73,y:-1.1},{x:-.73,y:-.93},{x:-1.45,y:-.93}],xli=qi.extend({fn:Z(),num_pins:Xe(6).default(6),w:Z().default("3.1mm"),h:Z().default("2.0mm"),p:Z().default("0.65mm"),pl:Z().default("1.03mm"),pw:Z().default("0.35mm"),string:Z().optional()}),Eli=t=>{const e=xli.parse({...t,fn:"sot363"}),n=he.parse(e.w),o=he.parse(e.h),i=he.parse(e.p),r=he.parse(e.pl),s=he.parse(e.pw),a=[];for(let d=0;d<6;d++){const{x:m,y:p}=htn(d+1,n,i);a.push(yi(d+1,m,p,r,s))}const A={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-n/4,y:o/2+.1},{x:n/4,y:o/2+.1}],stroke_width:.05,pcb_silkscreen_path_id:""},c={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-n/4,y:-o/2-.1},{x:n/4,y:-o/2-.1}],stroke_width:.05,pcb_silkscreen_path_id:""},l=htn(1,n,i),g={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"pin_marker_1",route:[{x:l.x-r/2-.3,y:l.y},{x:l.x-r/2-.45,y:l.y+.15},{x:l.x-r/2-.45,y:l.y-.15},{x:l.x-r/2-.3,y:l.y}],stroke_width:.05,pcb_silkscreen_path_id:"pin_marker_1"},u=nr(0,o/2+.4,.25),h={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",outline:yli,layer:"top"};return{circuitJson:[...a,A,c,u,g,h],parameters:e}},htn=(t,e,n,o)=>t<=3?{x:-.84,y:n-(t-1)*n}:{x:.84,y:-n+(t-4)*n},Bli=[{x:-.75,y:1},{x:-.75,y:-1},{x:.75,y:-1},{x:.75,y:1}],Sli=qi.extend({fn:Z(),num_pins:Xe(6).default(6),w:Z().default("1.01mm"),h:Z().default("1.45mm"),p:Z().default("0.5mm"),pl:Z().default("0.33mm"),pw:Z().default("0.27mm"),string:Z().optional()}),bli=t=>{const e=Sli.parse({...t,fn:"sot886"}),n=he.parse(e.w),o=he.parse(e.h),i=he.parse(e.p),r=he.parse(e.pl),s=he.parse(e.pw),a=[];for(let d=0;d<6;d++){const{x:m,y:p}=mtn(d+1,n,i,r);a.push(yi(d+1,m,p,r,s))}const A={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-n/2,y:o/2},{x:n/2,y:o/2}],stroke_width:.05,pcb_silkscreen_path_id:""},c={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-n/2,y:-o/2},{x:n/2,y:-o/2}],stroke_width:.05,pcb_silkscreen_path_id:""},l=mtn(1,n,i,r),g={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"pin_marker_1",route:[{x:l.x-r/2-.3,y:l.y},{x:l.x-r/2-.45,y:l.y+.15},{x:l.x-r/2-.45,y:l.y-.15},{x:l.x-r/2-.3,y:l.y}],stroke_width:.05,pcb_silkscreen_path_id:"pin_marker_1"},u=nr(0,o/2+.4,.25),h={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",outline:Bli,layer:"top"};return{circuitJson:[...a,A,c,u,g,h],parameters:e}},mtn=(t,e,n,o)=>{const i=e/2-o/2;return t<=3?{x:-i,y:n-(t-1)*n}:{x:i,y:-n+(t-4)*n}},Qli=[{x:-2.05,y:1.5},{x:-1.05,y:1.5},{x:-1.05,y:1.7},{x:1.05,y:1.7},{x:1.05,y:.55},{x:2.05,y:.55},{x:2.05,y:-.55},{x:1.05,y:-.55},{x:1.05,y:-1.7},{x:-1.05,y:-1.7},{x:-1.05,y:-1.5},{x:-2.05,y:-1.5},{x:-2.05,y:-.39},{x:-1.05,y:-.39},{x:-1.05,y:.39},{x:-2.05,y:.39}],vli=[{x:-2.05,y:1.5},{x:-1.05,y:1.5},{x:-1.05,y:1.7},{x:1.05,y:1.7},{x:1.05,y:1.5},{x:2.05,y:1.5},{x:2.05,y:.39},{x:1.05,y:.39},{x:1.05,y:-.39},{x:2.05,y:-.39},{x:2.05,y:-1.5},{x:1.05,y:-1.5},{x:1.05,y:-1.7},{x:-1.05,y:-1.7},{x:-1.05,y:-1.5},{x:-2.05,y:-1.5}],ptn=qi.extend({fn:Z(),num_pins:ft().default(3),w:Z().default("1.92mm"),h:Z().default("2.74mm"),pl:Z().default("1.325mm"),pw:Z().default("0.6mm"),p:Z().default("0.95mm"),string:Z().optional()}),Pli=IR({p:"0.95mm",w:"1.6mm",legsoutside:!0}),wli=t=>{const e=t.string?.match(/^sot23_(\d+)/),n=e?Number.parseInt(e[1],10):3;if(n===6||n===8){const i=Pli.parse({...t,num_pins:n});return{circuitJson:Aq(i),parameters:i}}const o=ptn.parse({...t,num_pins:n});if(o.num_pins===3)return{circuitJson:Dli(o),parameters:o};if(o.num_pins===5)return{circuitJson:ftn(o),parameters:o};throw new Error("Invalid number of pins")},Mli=t=>{const{pn:e,p:n}=t;return e===1?{x:-1.1375,y:n}:e===2?{x:-1.1375,y:-n}:{x:1.1375,y:0}},Dli=t=>{const e=[];for(let i=0;i<t.num_pins;i++){const{x:r,y:s}=Mli({num_pins:t.num_pins,pn:i+1,w:Number.parseFloat(t.w),h:Number.parseFloat(t.h),pl:Number.parseFloat(t.pl),p:Number.parseFloat(t.p)});e.push(yi(i+1,r,s,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}const n=nr(0,Number.parseInt(t.h),.3),o={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",outline:Qli,layer:"top"};return[...e,n,o]},_tn=t=>{const{p:e,h:n,pn:o}=t;if(o===1)return{x:-1.1375,y:e};if(o===2)return{x:-1.1375,y:0};if(o===3)return{x:-1.1375,y:-e};if(o===4)return{x:1.1375,y:-e};if(o===5)return{x:1.1375,y:e};throw new Error("Invalid pin number")},ftn=t=>{const e=[];for(let u=1;u<=t.num_pins;u++){const{x:h,y:d}=_tn({h:Number.parseFloat(t.h),p:Number.parseFloat(t.p),pn:u});e.push(yi(u,h,d,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}const n=(t.num_pins+1)/2*Number.parseFloat(t.p),o=Number.parseFloat(t.h),i={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-n/3,y:o/2+Number.parseFloat(t.p)/1.3},{x:n/3,y:o/2+Number.parseFloat(t.p)/1.3}],type:"pcb_silkscreen_path",stroke_width:.05},r={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_2",route:[{x:-n/3,y:-o/2-Number.parseFloat(t.p)/1.3},{x:n/3,y:-o/2-Number.parseFloat(t.p)/1.3}],type:"pcb_silkscreen_path",stroke_width:.05},s=nr(0,o+.3,.3),a=_tn({h:Number.parseFloat(t.h),p:Number.parseFloat(t.p),pn:1});a.x=a.x-Number.parseFloat(t.pw)*1.5;const A=.3,c=.4,l={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"pin1_indicator",route:[{x:a.x+A/2,y:a.y},{x:a.x-A/2,y:a.y+c/2},{x:a.x-A/2,y:a.y-c/2},{x:a.x+A/2,y:a.y}],stroke_width:.05},g={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",outline:vli,layer:"top"};return[...e,s,i,r,l,g]},Nli=ptn.extend({}),Rli=t=>{const e=Nli.parse({...t,num_pins:5});return{circuitJson:ftn(e),parameters:e}},Tli=[{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}],kli=IR({}),Fli=t=>{const e=kli.parse(t),n=[];for(let p=0;p<e.num_pins;p++){const{x:_,y:f}=gUe({num_pins:e.num_pins,pn:p+1,w:e.w,p:e.p??1.27,pl:e.pl,widthincludeslegs:!0});n.push(yi(p+1,_,f,e.pl??"1mm",e.pw??"0.6mm"))}const o=Math.min(1,e.p/2),i=e.w+o,r=(e.num_pins/2-1)*e.p+e.pw+o,s=[];for(const p of Tli){const{dx:_,dy:f}=p;s.push({layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"",route:[{x:_*i/2-_*e.p,y:f*r/2},{x:_*i/2,y:f*r/2},{x:_*i/2,y:f*r/2-f*e.p}],type:"pcb_silkscreen_path",stroke_width:.1})}const a=e.p/4,A=-i/2-a/2,c=r/2-e.p/2;s.push({layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"",type:"pcb_silkscreen_path",route:[{x:A,y:c},{x:A-a,y:c+a},{x:A-a,y:c-a},{x:A,y:c}],stroke_width:.1});const l=nr(0,r/2+.4,r/12),g=p=>Math.ceil(p/.05)*.05,u=(e.num_pins/2-1)*e.p+e.pw,h=g(e.w/2+.25),d=g(u/2+.45),m={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:0,y:0},width:h*2,height:d*2,layer:"top"};return{circuitJson:[...n,l,...s,m],parameters:e}},CR=({fs:t,pn:e,anchor_x:n,anchor_y:o,textalign:i="center",orthogonal:r=!1,verticallyinverted:s=!1,layer:a="top"})=>{let A=0;r&&s?A=270:s?A=180:r?A=90:A=0;let c="center";return i==="left"&&(s?c="center_right":c="center_left"),i==="right"&&(s?c="center_left":c="center_right"),a==="bottom"&&(c==="center_left"?c="center_right":c==="center_right"&&(c="center_left")),{type:"pcb_silkscreen_text",pcb_silkscreen_text_id:"silkscreen_text_1",font:"tscircuit2024",font_size:t,pcb_component_id:"pcb_component_1",text:`{PIN${e}}`,layer:a,anchor_position:{x:n,y:o},anchor_alignment:c,ccw_rotation:A}};function Itn({pinlabeltextalignleft:t,pinlabeltextalignright:e,pinlabelorthogonal:n}){let o="top";return n?o="left":o="top",t&&(n?o="bottom":o="right"),e&&(n?o="top":o="left"),o}var Lli=qi.extend({fn:Z(),num_pins:ft().optional().default(6),rows:Eo([Z(),ft()]).transform(t=>Number(t)).optional().default(1).describe("number of rows"),p:he.default("0.1in").describe("pitch"),id:he.default("1.0mm").describe("inner diameter"),od:he.default("1.5mm").describe("outer diameter"),male:je().optional().describe("for male pin headers"),female:je().optional().describe("for female pin headers"),smd:je().optional().describe("surface mount device"),surfacemount:je().optional().describe("surface mount device (verbose)"),rightangle:je().optional().describe("right angle"),pw:he.optional().default("1.0mm").describe("pad width for SMD"),pl:he.optional().default("2.0mm").describe("pad length for SMD"),pinlabeltextalignleft:je().optional().default(!1),pinlabeltextaligncenter:je().optional().default(!1),pinlabeltextalignright:je().optional().default(!1),pinlabelverticallyinverted:je().optional().default(!1),pinlabelorthogonal:je().optional().default(!1),nosquareplating:je().optional().default(!1).describe("do not use rectangular pad for pin 1"),nopinlabels:je().optional().default(!1).describe("omit silkscreen pin labels"),doublesidedpinlabel:je().optional().default(!1).describe("add silkscreen pins in top and bottom layers"),bottomsidepinlabel:je().optional().default(!1).describe("place the silkscreen reference text on the bottom layer instead of top")}).transform(t=>{const e=Itn(t);return{...t,pinlabelAnchorSide:e,male:t.male??!t.female,female:t.female??!1,smd:t.smd??t.surfacemount??!1,rightangle:t.rightangle??!1}}).superRefine((t,e)=>{t.male&&t.female&&e.addIssue({code:Ao.custom,message:"'male' and 'female' cannot both be true; it should be male or female.",path:["male","female"]})}),Hli=t=>{const e=Lli.parse(t),{p:n,id:o,od:i,rows:r,num_pins:s,pinlabelAnchorSide:a,pinlabelverticallyinverted:A,pinlabelorthogonal:c,pinlabeltextalignleft:l,pinlabeltextalignright:g,nopinlabels:u,doublesidedpinlabel:h,bottomsidepinlabel:d}=e;let m="center";l?m="left":g&&(m="right");const p=[],_=Math.ceil(s/r),f=(r-1)*n,I=f/2,C=-n,y=({xoff:te,yoff:j,od:J,anchorSide:ie,smd:oe,pw:ne,pl:le})=>{let ge=0,_e=0;if(oe){const ce=J/5;switch(ie){case"right":ge=ne/2+ce;break;case"top":_e=le/2+ce;break;case"bottom":_e=-(le/2+ce);break;case"left":ge=-(ne/2+ce);break}}else{const ce=J*.75;switch(ie){case"right":ge=ce;break;case"top":_e=ce;break;case"bottom":_e=-ce;break;case"left":ge=-ce;break}}return{anchor_x:te+ge,anchor_y:j+_e}},x=(te,j,J)=>{e.smd?p.push(yi(te,j,J,e.pw,e.pl)):te===1&&!e.nosquareplating?p.push(xx({pn:te,x:j,y:J,holeDiameter:o,rectPadWidth:i,rectPadHeight:i})):p.push(Fa(te,j,J,o,i));const{anchor_x:ie,anchor_y:oe}=y({xoff:j,yoff:J,od:i,anchorSide:a,smd:e.smd,pw:e.pw,pl:e.pl});u||(d?p.push(CR({fs:i/5,pn:te,anchor_x:ie,anchor_y:oe,textalign:m,orthogonal:c,verticallyinverted:A,layer:"bottom"})):p.push(CR({fs:i/5,pn:te,anchor_x:ie,anchor_y:oe,textalign:m,orthogonal:c,verticallyinverted:A,layer:"top"})),h&&p.push(CR({fs:i/5,pn:te,anchor_x:ie,anchor_y:oe,textalign:m,orthogonal:c,verticallyinverted:A,layer:"bottom"})))},E=new Set,B=r>2&&_>2;if(r===1){const te=-((s-1)/2)*n;for(let j=0;j<s;j++){const J=j+1,ie=te+j*n,oe=`${ie},0`;if(E.has(oe))throw new Error(`Overlap at ${oe}`);E.add(oe),x(J,ie,0)}}else if(B){const te=-((_-1)/2)*n;let j=1;for(let J=0;J<r&&j<=s;J++)for(let ie=0;ie<_&&j<=s;ie++){const oe=te+ie*n,ne=I+J*C,le=`${oe},${ne}`;if(E.has(le))throw new Error(`Overlap at ${le}`);E.add(le),x(j++,oe,ne)}}else{const te=-((_-1)/2)*n;let j=1,J=0,ie=r-1,oe=0,ne=_-1;for(;j<=s&&J<=ie&&oe<=ne;){for(let le=J;le<=ie&&j<=s;le++){const ge=te+oe*n,_e=I+le*C,ce=`${ge},${_e}`;if(E.has(ce))throw new Error(`Overlap at ${ce}`);E.add(ce),x(j++,ge,_e)}oe++;for(let le=oe;le<=ne&&j<=s;le++){const ge=te+le*n,_e=I+ie*C,ce=`${ge},${_e}`;if(E.has(ce))throw new Error(`Overlap at ${ce}`);E.add(ce),x(j++,ge,_e)}if(ie--,oe<=ne){for(let le=ie;le>=J&&j<=s;le--){const ge=te+ne*n,_e=I+le*C,ce=`${ge},${_e}`;if(E.has(ce))throw new Error(`Overlap at ${ce}`);E.add(ce),x(j++,ge,_e)}ne--}if(J<=ie){for(let le=ne;le>=oe&&j<=s;le--){const ge=te+le*n,_e=I+J*C,ce=`${ge},${_e}`;if(E.has(ce))throw new Error(`Overlap at ${ce}`);E.add(ce),x(j++,ge,_e)}J++}}if(j-1<s)throw new Error(`Missing pins: assigned ${j-1}, expected ${s}`)}const b=nr(0,f/2+n,.5),Q=e.smd?e.pw/2:i/2,w=e.smd?e.pl/2:i/2,D=(_-1)*n,k=D/2+Q,R=f/2+w,H=D/2+n/2,G=f/2+n/2,K=Math.max(k+.25,H+.5),Y=Math.max(R+.25,G+.5),X={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:0,y:0},width:2*K,height:2*Y,layer:"top"};return{circuitJson:[...p,b,X],parameters:e}},Oli=[{x:-1.2,y:.83},{x:-.75,y:.83},{x:-.75,y:.95},{x:.75,y:.95},{x:.75,y:.83},{x:1.2,y:.83},{x:1.2,y:-.83},{x:.75,y:-.83},{x:.75,y:-.95},{x:-.75,y:-.95},{x:-.75,y:-.83},{x:-1.2,y:-.83}],Gli=qi.extend({fn:Z(),num_pins:Xe(6).default(6),w:Z().default("2.1mm"),h:Z().default("2.45mm"),p:Z().default("0.5mm"),pl:Z().default("0.675mm"),pw:Z().default("0.35mm"),string:Z().optional()}),Yli=t=>{const e=Gli.parse({...t,fn:"sot563"}),n=he.parse(e.w),o=he.parse(e.h),i=he.parse(e.p),r=he.parse(e.pl),s=he.parse(e.pw),a=[];for(let d=0;d<6;d++){const{x:m,y:p}=Ctn(d+1,n,i,r);a.push(yi(d+1,m,p,r,s))}const A={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-n/2,y:o/2},{x:n/2,y:o/2}],stroke_width:.05,pcb_silkscreen_path_id:""},c={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-n/2,y:-o/2},{x:n/2,y:-o/2}],stroke_width:.05,pcb_silkscreen_path_id:""},l=Ctn(1,n,i,r),g={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"pin_marker_1",route:[{x:l.x-r/2-.3,y:l.y},{x:l.x-r/2-.45,y:l.y+.15},{x:l.x-r/2-.45,y:l.y-.15},{x:l.x-r/2-.3,y:l.y}],stroke_width:.05,pcb_silkscreen_path_id:"pin_marker_1"},u=nr(0,o/2+.4,.25),h={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",outline:Oli,layer:"top"};return{circuitJson:[...a,A,c,u,g,h],parameters:e}},Ctn=(t,e,n,o)=>{const i=e/2-o/2;return t<=3?{x:-i,y:n-(t-1)*n}:{x:i,y:-n+(t-4)*n}},Uli=IR({p:"1.27mm",w:"3.9mm",legsoutside:!0}),Kli=t=>{const e=Uli.parse({...t,num_pins:8});return{circuitJson:Aq(e),parameters:e}},Vli=IR({p:"1.27mm",w:"7.5mm",legsoutside:!0}),zli=t=>{const e=Vli.parse({...t,num_pins:16});return{circuitJson:Aq(e),parameters:e}},Jli=qi.extend({fn:Z(),num_pins:Xe(3).default(3),w:Z().default("1.2mm"),h:Z().default("1.2mm"),pw:Z().default("0.40mm"),pl:Z().default("0.45mm"),p:Z().default("0.575mm")}),Wli=t=>{const e=Jli.parse(t),n=Xli(e),o=nr(0,he.parse(e.h),.2),i=1.8,r=1.8,s={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",outline:[{x:-i/2,y:r/2},{x:i/2,y:r/2},{x:i/2,y:-r/2},{x:-i/2,y:-r/2}],layer:"top"};return{circuitJson:[...n,o,s],parameters:e}},jli=t=>{const{pn:e,p:n}=t;return e===1?{x:n,y:0}:e===2?{x:-n,y:-.4}:{x:-n,y:.4}},Xli=t=>{const e=[];for(let n=0;n<3;n++){const{x:o,y:i}=jli({num_pins:t.num_pins,pn:n+1,w:Number.parseFloat(t.w),h:Number.parseFloat(t.h),pl:Number.parseFloat(t.pl),p:Number.parseFloat(t.p)});e.push(yi(n+1,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return e},gC=t=>{const e=t.p??t.pad_spacing;if(e===void 0||t.pl===void 0||t.pw===void 0)throw new Error("Diode fabrication note requires p or pad_spacing, pl, and pw");const n=he.parse(e),o=he.parse(t.pl),i=he.parse(t.pw);return qli({minX:-n/2-o/2,maxX:n/2+o/2,minY:-i/2,maxY:i/2})},qli=t=>{const e=[],n=t.maxX-t.minX,o=t.maxY-t.minY,i=(t.minX+t.maxX)/2,r=(t.minY+t.maxY)/2,s=o*.28,a=s*2,A=n*.2,l=Math.min(A,a*1.25),g=i-l/2,u=i+l/2,h=l*.18,d=g+h,m=u-h,p=Math.max(Math.min(n,o)*.035,.01),_=Math.max(Math.min(n,o)*.25,.1);return e.push({type:"pcb_fabrication_note_path",pcb_fabrication_note_path_id:"diode_fabrication_note_anode_leg",pcb_component_id:"",layer:"top",stroke_width:p,route:[{x:g,y:r},{x:d,y:r}]},{type:"pcb_fabrication_note_path",pcb_fabrication_note_path_id:"diode_fabrication_note_triangle",pcb_component_id:"",layer:"top",stroke_width:p,route:[{x:d,y:r+s},{x:m,y:r},{x:d,y:r-s},{x:d,y:r+s}]},{type:"pcb_fabrication_note_path",pcb_fabrication_note_path_id:"diode_fabrication_note_cathode",pcb_component_id:"",layer:"top",stroke_width:p,route:[{x:m,y:r+s},{x:m,y:r-s}]},{type:"pcb_fabrication_note_path",pcb_fabrication_note_path_id:"diode_fabrication_note_cathode_leg",pcb_component_id:"",layer:"top",stroke_width:p,route:[{x:m,y:r},{x:u,y:r}]},{type:"pcb_fabrication_note_text",pcb_fabrication_note_text_id:"diode_fabrication_note_positive",pcb_component_id:"",layer:"top",font:"tscircuit2024",font_size:_,text:"+",anchor_position:{x:t.minX+n*.125,y:r},anchor_alignment:"center"},{type:"pcb_fabrication_note_text",pcb_fabrication_note_text_id:"diode_fabrication_note_negative",pcb_component_id:"",layer:"top",font:"tscircuit2024",font_size:_,text:"-",anchor_position:{x:t.maxX-n*.125,y:r},anchor_alignment:"center"}),e},$li=qi.extend({fn:Z(),num_pins:Xe(2).default(2),w:Z().default("2.36mm"),h:Z().default("1.22mm"),pl:Z().default("0.9mm"),pw:Z().default("1.2mm"),p:Z().default("3.30mm")}),Zli=t=>{const e=$li.parse(t),n=he.parse(e.h),o=nr(0,n/4+.4,.3),s={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:0,y:0},width:4.7,height:2.3,layer:"top"};return{circuitJson:t0i(e).concat(...gC(e),o,s),parameters:e}},e0i=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},t0i=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=e0i({pn:n,p:Number.parseFloat(t.p)});e.push(yi(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw),.1125))}return e},n0i=qi.extend({fn:Z(),p:he.optional().default("2.54mm"),id:he.optional().default("0.7mm"),od:he.optional().default("1.4mm")}),o0i=t=>{const e=n0i.parse(t),{p:n,id:o,od:i}=e,r=[Fa(1,-n/2,0,o,i),Fa(2,n/2,0,o,i)],s={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-n/2+i+o/2,y:0},{x:n/2-i-o/2,y:0}],stroke_width:.1,pcb_silkscreen_path_id:""},a=nr(0,1.5,.5),A=-n/2,c=n/2,l=i/2,g=i/2,u=A-l-.35,h=c+l+.26,d=g+.35,m=u,p=h,_=d,f={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",outline:ky([{minX:u,maxX:h,minY:-_,maxY:_},{minX:m,maxX:p,minY:-d,maxY:d}]),layer:"top"};return{circuitJson:[...r,s,a,f],parameters:e}},i0i=(t,e,n,o,i,r=.1)=>{const s=[],a=[],A=Math.max(1,Math.ceil(Math.PI*n/r)),c=Math.PI/A;for(let l=0;l<=A;l++){const g=l*c,u=t+Math.cos(g)*n,h=e+Math.sin(g)*n;u<t-o&&h>=e-i/2&&h<=e+i/2||s.push({x:u,y:h})}for(let l=0;l<=A;l++){const g=Math.PI+l*c,u=t+Math.cos(g)*n,h=e+Math.sin(g)*n;u<t-o&&h>=e-i/2&&h<=e+i/2||a.push({x:u,y:h})}return{topArc:s,bottomArc:a}},r0i=qi.extend({fn:Z(),p:he.optional().default("5mm"),id:he.optional().default("0.8mm"),od:he.optional().default("1.6mm"),ceramic:je().optional(),electrolytic:je().optional(),polarized:je().optional()}),s0i=t=>{const e=r0i.parse(t),{p:n,id:o,od:i}=e;o===.8&&i===1.6&&(e.id=n===5?.8:n*.25,e.od=n===5?1.6:n*.5);const r=[Fa(1,-n/2,0,e.id,e.od),Fa(2,n/2,0,e.id,e.od)],s=n+.1,{topArc:a,bottomArc:A}=i0i(0,0,s,e.od/2,e.od),c=.02*n,l={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:a,stroke_width:c,pcb_silkscreen_path_id:""},g={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:A,stroke_width:c,pcb_silkscreen_path_id:""},u={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:0,y:s},{x:0,y:-s}],stroke_width:c,pcb_silkscreen_path_id:""},h=.1*n,d=-(n+h+.04*n),m=s-h-.08*n,p={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:d-h,y:m},{x:d+h,y:m}],stroke_width:c,pcb_silkscreen_path_id:""},_={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:d,y:m-h},{x:d,y:m+h}],stroke_width:c,pcb_silkscreen_path_id:""},f=nr(0,s+.12*n,.1*n),I=[...r,l,g,u,f];(e.electrolytic===!0||e.polarized===!0)&&I.push(p,_);const y=n+.25,x={type:"pcb_courtyard_circle",pcb_courtyard_circle_id:"",pcb_component_id:"",center:{x:0,y:0},radius:y,layer:"top"};return I.push(x),{circuitJson:I,parameters:e}},yR=(t,e={})=>({type:"pcb_silkscreen_path",layer:e.layer||"top",pcb_component_id:e.pcb_component_id||"",pcb_silkscreen_path_id:e.pcb_silkscreen_path_id||"",route:t,stroke_width:e.stroke_width||.1}),a0i=qi.extend({fn:Xe("pushbutton"),w:he.default(4.5),h:he.default(6.5),id:he.default(1),od:he.default(1.2)}),A0i=t=>{const e=a0i.parse(t),n=e.w,o=e.h,i=e.id,r=[Fa(1,-n/2,o/2,i,i*1.5),Fa(2,-n/2,-o/2,i,i*1.5),Fa(3,n/2,-o/2,i,i*1.5),Fa(4,n/2,o/2,i,i*1.5)],s=[yR([{x:-n/2,y:-o/2},{x:-n/2,y:o/2}]),yR([{x:n/2,y:-o/2},{x:n/2,y:o/2}]),yR([{x:-n/2,y:0},{x:-n/5,y:0},{x:n/5*1/Math.sqrt(2),y:o/8}]),yR([{x:n/2,y:0},{x:n/5,y:0}])],a=nr(0,o/2+.4,.5),A=i*1.5/2,c=n,l=o,g=c/2+A,u=l/2+A,h=g+.5,d=u+.5,m={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:0,y:0},width:2*h,height:2*d,layer:"top"};return{circuitJson:[...r,...s,a,m],parameters:e}},ytn=qi.extend({fn:Z(),w:he.default("22.58mm"),h:he.optional(),left:he.optional().default(20),right:he.optional().default(20),top:he.optional().default(2),bottom:he.optional().default(2),p:he.default(he.parse("2.54mm")),pw:he.default(he.parse("1.6mm")),pl:he.default(he.parse("2.4mm")),innerhole:je().default(!1),innerholeedgedistance:he.default(he.parse("1.61mm")),silkscreenlabels:je().default(!1),silkscreenlabelmargin:he.default(he.parse("0.1mm"))}),c0i=t=>{const e=ytn.parse(t);return e.left&&e.right?Math.max(e.left,e.right)*e.p:e.left?e.left*e.p:e.right?e.right*e.p:51},hde=(t,e,n)=>{let o=[];return n==="right"&&(o=[{x:t+1/2,y:e},{x:t-1/2,y:e+.6/2},{x:t-1/2,y:e-.6/2},{x:t+1/2,y:e}]),n==="left"&&(o=[{x:t-1/2,y:e},{x:t+1/2,y:e+.6/2},{x:t+1/2,y:e-.6/2},{x:t-1/2,y:e}]),n==="top"&&(o=[{x:t,y:e+1/2},{x:t-.6/2,y:e-1/2},{x:t+.6/2,y:e-1/2},{x:t,y:e+1/2}]),n==="bottom"&&(o=[{x:t,y:e-1/2},{x:t-.6/2,y:e+1/2},{x:t+.6/2,y:e+1/2},{x:t,y:e-1/2}]),o},l0i=t=>{const e=ytn.parse(t),n=e.h??c0i(e),o=[],i=[],r=[];let s=[];const a=1,A=a,c=e.left+e.right+(e.bottom??0)+(e.top??0),g=`pin${c}`.length*.7/2;if(e.right){const m=-((e.right-1)/2)*e.p;for(let p=0;p<e.right;p++){if(p===0&&!e.left&&!e.bottom&&!e.silkscreenlabels&&(s=hde(e.w/2-e.pl*1.4,m+p*e.p,"right")),o.push(yi(p+1+e.left+(e.bottom??0),e.w/2-e.pl/2,m+p*e.p,e.pl,e.pw)),e.silkscreenlabels){const _=p+1+e.left+(e.bottom??0),f=`pin${_}`;r.push({type:"pcb_silkscreen_text",pcb_silkscreen_text_id:`pin_${_}`,pcb_component_id:"1",layer:"top",anchor_position:{x:e.w/2-e.pl-(g+e.silkscreenlabelmargin),y:m+p*e.p},text:f,font_size:.7,font:"tscircuit2024",anchor_alignment:"center"})}e.innerhole&&(i.push(Fa(p+1+e.left+(e.bottom??0)+c,e.w/2,m+p*e.p,a,A)),i.push(Fa(p+1+e.left+(e.bottom??0)+c*2,e.w/2-e.innerholeedgedistance,m+p*e.p,a,A)))}}if(e.left){const m=(e.left-1)/2*e.p;for(let p=0;p<e.left;p++){if(p===0&&!e.silkscreenlabels&&(s=hde(-e.w/2+e.pl*1.4,m-p*e.p,"left")),o.push(yi(p+1,-e.w/2+e.pl/2,m-p*e.p,e.pl,e.pw)),e.silkscreenlabels){const _=p+1,f=`pin${_}`;r.push({type:"pcb_silkscreen_text",pcb_silkscreen_text_id:`pin_${_}`,pcb_component_id:"1",layer:"top",anchor_position:{x:-e.w/2+e.pl+(g+e.silkscreenlabelmargin),y:m-p*e.p},text:f,font_size:.7,font:"tscircuit2024",anchor_alignment:"center"})}e.innerhole&&(i.push(Fa(p+1+c,-e.w/2,m-p*e.p,a,A)),i.push(Fa(p+1+c*2,-e.w/2+e.innerholeedgedistance,m-p*e.p,a,A)))}}if(e.top){const m=(e.top-1)/2*e.p;for(let p=0;p<e.top;p++){if(p===0&&!e.left&&!e.bottom&&!e.right&&!e.silkscreenlabels&&(s=hde(m-p*e.p,n/2-e.pl*1.4,"top")),o.push(yi(p+1+e.left+e.right+(e.bottom??0),m-p*e.p,n/2-e.pl/2,e.pw,e.pl)),e.silkscreenlabels){const _=p+1+e.left+e.right+(e.bottom??0),f=`pin${_}`;r.push({type:"pcb_silkscreen_text",pcb_silkscreen_text_id:`pin_${_}`,pcb_component_id:"1",layer:"top",anchor_position:{x:m-p*e.p,y:n/2-e.pl-(g+e.silkscreenlabelmargin)},text:f,font_size:.7,font:"tscircuit2024",anchor_alignment:"center",ccw_rotation:270})}e.innerhole&&(i.push(Fa(p+1+e.left+e.right+(e.bottom??0)+c,m-p*e.p,n/2,a,A)),i.push(Fa(p+1+e.left+e.right+(e.bottom??0)+c*2,m-p*e.p,n/2-e.innerholeedgedistance,a,A)))}}if(e.bottom){const m=-((e.bottom-1)/2)*e.p;for(let p=0;p<e.bottom;p++){if(p===0&&!e.left&&!e.silkscreenlabels&&(s=hde(m+p*e.p,-n/2+e.pl*1.4,"bottom")),o.push(yi(p+1+e.left,m+p*e.p,-n/2+e.pl/2,e.pw,e.pl)),e.silkscreenlabels){const _=p+1+e.left,f=`pin${_}`;r.push({type:"pcb_silkscreen_text",pcb_silkscreen_text_id:`pin_${_}`,pcb_component_id:"1",layer:"top",anchor_position:{x:m+p*e.p,y:-n/2+e.pl+(g+e.silkscreenlabelmargin)},text:f,font_size:.7,font:"tscircuit2024",anchor_alignment:"center",ccw_rotation:90})}e.innerhole&&(i.push(Fa(p+1+e.left+c,m+p*e.p,-n/2,a,A)),i.push(Fa(p+1+e.left+c*2,m+p*e.p,-n/2+e.innerholeedgedistance,a,A)))}}const u={type:"pcb_silkscreen_path",pcb_silkscreen_path_id:"pcb_silkscreen_triangle_1",pcb_component_id:"2",route:s,stroke_width:.1,layer:"top"},h={type:"pcb_silkscreen_path",pcb_silkscreen_path_id:"pcb_silkscreen_path_1",pcb_component_id:"1",route:[{x:-e.w/2,y:n/2},{x:e.w/2,y:n/2},{x:e.w/2,y:-n/2},{x:-e.w/2,y:-n/2},{x:-e.w/2,y:n/2}],stroke_width:.1,layer:"top"},d=nr(0,n/1.8,n/25);return{circuitJson:[...o,...i,...r,h,...e.silkscreenlabels?[]:[u],d],parameters:e}},xtn=qi.extend({fn:Z(),w:he.default("22.58mm"),h:he.optional(),left:he.optional().default(20),right:he.optional().default(20),top:he.optional().default(2),bottom:he.optional().default(2),p:he.default(he.parse("2.54mm")),pw:he.default(he.parse("1.6mm")),pl:he.default(he.parse("3.2mm")),innerhole:je().default(!1),innerholeedgedistance:he.default(he.parse("1.61mm"))}),g0i=t=>{const e=xtn.parse(t);return e.left&&e.right?Math.max(e.left,e.right)*e.p:e.left?e.left*e.p:e.right?e.right*e.p:51},u0i=(t,e,n,o=1,i=.6)=>{const r=o/2,s=i/2;return{left:[{x:t+r,y:e},{x:t-r,y:e+s},{x:t-r,y:e-s},{x:t+r,y:e}],right:[{x:t-r,y:e},{x:t+r,y:e+s},{x:t+r,y:e-s},{x:t-r,y:e}],top:[{x:t,y:e-r},{x:t-s,y:e+r},{x:t+s,y:e+r},{x:t,y:e-r}],bottom:[{x:t,y:e+r},{x:t-s,y:e-r},{x:t+s,y:e-r},{x:t,y:e+r}]}[n]},d0i=t=>{const e=xtn.parse(t),n=e.h??g0i(e),o=[],i=[],r=[],s=1,a=1.2,A=e.left+e.right+(e.bottom??0)+(e.top??0);let c=[],l=1;if(e.left){const d=(e.left-1)/2*e.p;for(let m=0;m<e.left;m++)m===0&&(c=u0i(-e.w/2-e.pl/2,d-m*e.p,"left")),o.push(yi(l,-e.w/2+e.pl/2,d-m*e.p,e.pl,e.pw)),i.push({type:"pcb_silkscreen_text",pcb_silkscreen_text_id:`pin_${l}`,pcb_component_id:"1",layer:"top",anchor_position:{x:-e.w/2+e.pl/2-4.5,y:d-m*e.p},text:`pin${l}`,font_size:.7,font:"tscircuit2024",anchor_alignment:"center"}),l++,e.innerhole&&r.push(Fa(l+A,-e.w/2+e.innerholeedgedistance,d-m*e.p,s,a))}if(e.bottom){const d=(e.bottom-1)/2*e.p;for(let m=e.bottom-1;m>=0;m--)o.push(yi(l,d-m*e.p,-n/2+e.pl/2,e.pw,e.pl)),i.push({type:"pcb_silkscreen_text",pcb_silkscreen_text_id:`pin_${l}`,pcb_component_id:"1",layer:"top",anchor_position:{x:d-m*e.p,y:-n/2+e.pl/2-3.2},text:`pin${l}`,font_size:.7,font:"tscircuit2024",anchor_alignment:"center"}),l++,e.innerhole&&r.push(Fa(l+A,d-m*e.p,-n/2+e.innerholeedgedistance,s,a))}if(e.right){const d=-((e.right-1)/2)*e.p;for(let m=0;m<e.right;m++)o.push(yi(l,e.w/2-e.pl/2,d+m*e.p,e.pl,e.pw)),i.push({type:"pcb_silkscreen_text",pcb_silkscreen_text_id:`pin_${l}`,pcb_component_id:"1",layer:"top",anchor_position:{x:e.w/2-e.pl/2+3.7,y:d+m*e.p},text:`pin${l}`,font_size:.7,font:"tscircuit2024",anchor_alignment:"center"}),l++,e.innerhole&&r.push(Fa(l+A,e.w/2-e.innerholeedgedistance,d+m*e.p,s,a))}if(e.top){const d=-((e.top-1)/2)*e.p;for(let m=e.top-1;m>=0;m--)o.push(yi(l,d+m*e.p,n/2-e.pl/2,e.pw,e.pl)),i.push({type:"pcb_silkscreen_text",pcb_silkscreen_text_id:`pin_${l}`,pcb_component_id:"1",layer:"top",anchor_position:{x:d+m*e.p,y:n/2-e.pl/2+3.2},text:`pin${l}`,font_size:.7,font:"tscircuit2024",anchor_alignment:"center"}),l++,e.innerhole&&r.push(Fa(l+A,d+m*e.p,n/2-e.innerholeedgedistance,s,a))}const g={type:"pcb_silkscreen_path",pcb_silkscreen_path_id:"1",pcb_component_id:"1",layer:"top",route:c,stroke_width:.1},u={type:"pcb_silkscreen_path",pcb_silkscreen_path_id:"pcb_silkscreen_path_1",pcb_component_id:"1",route:[{x:-e.w/2-e.pl/3,y:n/2+e.pl/3},{x:e.w/2+e.pl/3,y:n/2+e.pl/3},{x:e.w/2+e.pl/3,y:-n/2-e.pl/3},{x:-e.w/2-e.pl/3,y:-n/2-e.pl/3},{x:-e.w/2-e.pl/3,y:n/2+e.pl/3}],stroke_width:.1,layer:"top"},h=nr(0,n/1.8,n/25);return{circuitJson:[...r,...o,...i,u,g,h],parameters:e}},h0i=t=>(t.legsoutside=!0,t.pl||(t.pl=1.5),t.pw||(t.pw=.3),MG(t)),Etn=qi.extend({fn:Z(),w:he.default("10mm"),h:he.optional(),left:he.optional().default(20),right:he.optional().default(20),top:he.optional().default(0),bottom:he.optional().default(0),p:he.default(he.parse("2.54mm")),id:he.optional().default(he.parse("1mm")),od:he.optional().default(he.parse("1.5mm"))}),m0i=t=>{const e=Etn.parse(t);return e.left&&e.right?Math.max(e.left,e.right)*e.p:e.left?e.left*e.p:e.right?e.right*e.p:51},mde=(t,e,n,o=1,i=.6)=>{const r=o/2,s=i/2;return{left:[{x:t+r,y:e},{x:t-r,y:e+s},{x:t-r,y:e-s},{x:t+r,y:e}],right:[{x:t-r,y:e},{x:t+r,y:e+s},{x:t+r,y:e-s},{x:t-r,y:e}],top:[{x:t,y:e-r},{x:t-s,y:e+r},{x:t+s,y:e+r},{x:t,y:e-r}],bottom:[{x:t,y:e+r},{x:t-s,y:e-r},{x:t+s,y:e-r},{x:t,y:e+r}]}[n]},p0i=t=>{const e=Etn.parse(t),n=e.h??m0i(e),o=[],i=e.id,r=e.od;let s=[];if(e.right){const l=-((e.right-1)/2)*e.p;for(let g=0;g<e.right;g++)g===0&&!e.left&&!e.bottom&&(s=mde(e.w/2+r*1.4,l+g*e.p,"right")),o.push(Fa(g+1+e.left+(e.bottom??0),e.w/2,l+g*e.p,i,r))}if(e.left){const l=-((e.left-1)/2)*e.p;for(let g=0;g<e.left;g++)g===e.left-1&&(s=mde(-e.w/2-r*1.4,l+g*e.p,"left")),o.push(Fa(g+1,-e.w/2,l+g*e.p,i,r))}if(e.top){const l=-((e.top-1)/2)*e.p;for(let g=0;g<e.top;g++)g===e.top-1&&!e.left&&!e.bottom&&!e.right&&(s=mde(l+g*e.p,n/2+r*1.4,"top")),o.push(Fa(g+1+e.right+(e.bottom??0)+e.left,l+g*e.p,n/2,i,r))}if(e.bottom){const l=-((e.bottom-1)/2)*e.p;for(let g=0;g<e.bottom;g++)g===0&&!e.left&&(s=mde(l+g*e.p,-n/2-r*1.4,"bottom")),o.push(Fa(g+1+e.left,l+g*e.p,-n/2,i,r))}const a={type:"pcb_silkscreen_path",pcb_silkscreen_path_id:"1",pcb_component_id:"1",layer:"top",route:s,stroke_width:.1},A={type:"pcb_silkscreen_path",pcb_silkscreen_path_id:"pcb_silkscreen_path_1",pcb_component_id:"1",route:[{x:-e.w/2-r,y:n/2+r},{x:e.w/2+r,y:n/2+r},{x:e.w/2+r,y:-n/2-r},{x:-e.w/2-r,y:-n/2-r},{x:-e.w/2-r,y:n/2+r}],stroke_width:.1,layer:"top"},c=nr(0,n/1.7,n/25);return{circuitJson:[...o,A,c,a],parameters:e}},_0i=t=>{const{centerX:e,centerY:n,straightHalfLength:o,radius:i,arcSegmentCount:r=9,orientation:s="horizontal"}=t;if(o<0)throw new Error("Capsule straightHalfLength must be non-negative");if(i<=0)throw new Error("Capsule radius must be positive");if(r<2)throw new Error("Capsule arcSegmentCount must be at least 2");if(s==="horizontal"){const g=e-o,u=e+o,h=Array.from({length:r+1},(m,p)=>{const _=Math.PI/2-p*Math.PI/r;return{x:u+Math.cos(_)*i,y:n+Math.sin(_)*i}}),d=Array.from({length:r+1},(m,p)=>{const _=-Math.PI/2+p*Math.PI/r;return{x:g-Math.cos(_)*i,y:n+Math.sin(_)*i}});return[{x:g,y:n+i},{x:u,y:n+i},...h.slice(1,-1),{x:u,y:n-i},{x:g,y:n-i},...d.slice(1,-1)]}const a=n-o,A=n+o,c=Array.from({length:r+1},(g,u)=>{const h=Math.PI-u*Math.PI/r;return{x:e+Math.cos(h)*i,y:A+Math.sin(h)*i}}),l=Array.from({length:r+1},(g,u)=>{const h=u*Math.PI/r;return{x:e+Math.cos(h)*i,y:a-Math.sin(h)*i}});return[{x:e-i,y:a},{x:e-i,y:A},...c.slice(1,-1),{x:e+i,y:A},{x:e+i,y:a},...l.slice(1,-1)]},Btn=(t,e,n,o)=>Array.from({length:25},(i,r)=>{const s=r/24*Math.PI-Math.PI/2;return{x:t+(o==="right"?1:-1)*Math.cos(s)*n,y:e+Math.sin(s)*n}}),f0i=qi.extend({fn:Z(),p:he.optional().default("4.88mm"),id:he.optional().default("0.8mm"),od:he.optional().default("1.5mm"),w:he.optional().default("5.6mm"),h:he.optional().default("3.5mm")}),I0i=t=>{const e=f0i.parse(t),{p:n,id:o,od:i,w:r,h:s}=e,a=s/2,A=[Fa(1,-n/2,0,o,i),Fa(2,n/2,0,o,i)],c=Btn(-r/2,0,a,"left"),l=Btn(r/2,0,a,"right"),g={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[...c,...c.slice(1).reverse(),{x:-r/2,y:-s/2},{x:r/2,y:-s/2},...l,{x:r/2,y:s/2},{x:-r/2,y:s/2}],stroke_width:.1,pcb_silkscreen_path_id:""},u=nr(0,n/4,.5),d=n/2+i/2,m=Math.max(s/2+.25,r/2+.03),p={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",outline:_0i({centerX:0,centerY:0,straightHalfLength:d,radius:m,arcSegmentCount:9}),layer:"top"};return{circuitJson:[...A,g,u,p],parameters:e}};qi.extend({w:he,h:he});var C0i=t=>{const{w:e,h:n}=t,o=Ja(e),i=Ja(n);return{circuitJson:[yi(1,0,0,o,i),nr(0,i/2+.5,.2)],parameters:t}},vP=(t,e,n,o,i,r)=>({pcb_plated_hole_id:"",type:"pcb_plated_hole",shape:"pill",x:e,y:n,outer_width:Ja(i),outer_height:Ja(r),hole_width:Ja(o),hole_height:Ja(o),pcb_port_id:"",layers:["top","bottom"],port_hints:[t.toString()],ccw_rotation:0}),y0i=[{x:-2.73,y:3.71},{x:-2.73,y:-1.03},{x:2.73,y:-1.03},{x:2.73,y:3.71}],x0i=qi.extend({fn:Z(),num_pins:Eo([Xe(3),Xe(2)]).default(3),p:Z().default("1.27mm"),id:Z().default("0.72mm"),od:Z().default("0.95mm"),w:Z().default("4.5mm"),h:Z().default("4.5mm"),inline:je().default(!1),string:Z().optional()}),E0i=(t,e,n)=>Array.from({length:25},(o,i)=>{const r=i/24*Math.PI;return{x:t+Math.cos(r)*n,y:e+Math.sin(r)*n}}),B0i=t=>{const e=t.string?.match(/^to92_(\d+)/),n=e?Number.parseInt(e[1],10):3,o=x0i.parse({...t,num_pins:n}),{p:i,id:r,od:s,w:a,h:A,inline:c}=o,l=Number.parseFloat(A)/2,g=Number.parseFloat(i),u=Number.parseFloat(r),h=Number.parseFloat(s),d=h,m=h*(1.5/1.05);let p=[];if(o.num_pins===3)c?p=[xx({pn:1,x:-g,y:l-g,holeDiameter:u,rectPadWidth:h,rectPadHeight:m}),vP(2,0,l-g,u,d,m),vP(3,g,l-g,u,d,m)]:p=[xx({pn:1,x:-g,y:l-g,holeDiameter:u,rectPadWidth:h,rectPadHeight:h}),Fa(2,0,l,u,h),Fa(3,g,l-g,u,h)];else if(o.num_pins===2)p=[xx({pn:1,x:-g,y:l-g,holeDiameter:u,rectPadWidth:d,rectPadHeight:m}),vP(2,g,l-g,u,d,m)];else throw new Error("Invalid number of pins for TO-92");const _=Number.parseFloat(a)/2,f=E0i(0,l,_),I={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[...f,{x:-_,y:0},{x:_,y:0},f[0]],stroke_width:.1,pcb_silkscreen_path_id:""},C=nr(0,l+1,.5),y={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",outline:y0i,layer:"top"};return{circuitJson:[...p,I,C,y],parameters:o}},S0i=qi.extend({fn:Z(),num_pins:Xe(2).default(2),w:Z().default("2.15mm"),h:Z().default("0.7mm"),pl:Z().default("0.6mm"),pw:Z().default("0.7mm"),p:Z().default("1.4mm")}),b0i=t=>{const e=S0i.parse(t),n=nr(0,he.parse(e.h),.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:he.parse(e.p)/2,y:he.parse(e.h)/2+.2},{x:-he.parse(e.w)/2-.2,y:he.parse(e.h)/2+.2},{x:-he.parse(e.w)/2-.2,y:-he.parse(e.h)/2-.2},{x:he.parse(e.p)/2,y:-he.parse(e.h)/2-.2}],stroke_width:.1,pcb_silkscreen_path_id:""},s={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:0,y:0},width:2.5,height:1.4,layer:"top"};return{circuitJson:v0i(e).concat(...gC(e),o,n,s),parameters:e}},Q0i=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},v0i=t=>{const e=[],n=he.parse(t.p),o=he.parse(t.pl),i=he.parse(t.pw),r=.075;for(let s=1;s<=t.num_pins;s++){const{x:a,y:A}=Q0i({pn:s,p:n});e.push(yi(s,a,A,o,i,r))}return e},P0i=IR({w:"7.05mm",p:"1.27mm",pw:"0.65mm",pl:"1.975mm"}),w0i=t=>{const e=P0i.parse(t),n=[];for(let u=0;u<e.num_pins;u++){const{x:h,y:d}=gUe({num_pins:e.num_pins,pn:u+1,w:e.w,p:e.p??1.27,pl:e.pl,widthincludeslegs:!0});n.push(yi(u+1,h,d,e.pl??"1.5mm",e.pw??"0.6mm"))}const o=(e.num_pins/2-1)*e.p+e.pw,i=nr(0,o/2+1,o/12),r={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"",type:"pcb_silkscreen_path",route:[{x:-e.w/3,y:o/2+.4},{x:e.w/3,y:o/2+.4}],stroke_width:.1},s=(e.num_pins/2-1)*e.p+e.pw,a=e.w/2-1.395,A=e.w/2+.255,c=s/2+.25,l=s/2+.5,g={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",layer:"top",outline:ky([{minX:-A,maxX:A,minY:-c,maxY:c},{minX:-a,maxX:a,minY:-l,maxY:l}])};return{circuitJson:[...n,i,r,g],parameters:e}},M0i=qi.extend({fn:Z(),num_pins:Xe(2).default(2),w:Z().default("5.0mm"),h:Z().default("2.30mm"),pl:Z().default("1.25mm"),pw:Z().default("2mm"),p:Z().default("3.75mm")}),D0i=t=>{const e=M0i.parse(t),n=nr(0,he.parse(e.h)/2+1,.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:he.parse(e.p)/2+.5,y:he.parse(e.h)/2+.5},{x:-he.parse(e.w)/2-.5,y:he.parse(e.h)/2+.5},{x:-he.parse(e.w)/2-.5,y:-he.parse(e.h)/2-.5},{x:he.parse(e.p)/2+.5,y:-he.parse(e.h)/2-.5}],stroke_width:.1,pcb_silkscreen_path_id:""},s={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:0,y:0},width:5.1,height:2.8,layer:"top"};return{circuitJson:R0i(e).concat(...gC(e),o,n,s),parameters:e}},N0i=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},R0i=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=N0i({pn:n,p:Number.parseFloat(t.p)});e.push(yi(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return e},T0i=qi.extend({fn:Z(),num_pins:Xe(2).default(2),w:Z().default("4.4mm"),h:Z().default("1.7mm"),pl:Z().default("1.2mm"),pw:Z().default("1.2mm"),p:Z().default("2.8mm")}),k0i=t=>{const e=T0i.parse(t),n=nr(0,he.parse(e.h)-.5,.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:he.parse(e.p)/2,y:he.parse(e.h)/2},{x:-he.parse(e.w)/2-.2,y:he.parse(e.h)/2},{x:-he.parse(e.w)/2-.2,y:-he.parse(e.h)/2},{x:he.parse(e.p)/2,y:-he.parse(e.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""},s={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:0,y:0},width:4.5,height:2.2,layer:"top"};return{circuitJson:L0i(e).concat(...gC(e),o,n,s),parameters:e}},F0i=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},L0i=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=F0i({pn:n,p:Number.parseFloat(t.p)});e.push(yi(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return e},H0i=qi.extend({fn:Z(),num_pins:Xe(2).default(2),w:Z().default("3.30mm"),h:Z().default("1.80mm"),pl:Z().default("0.60mm"),pw:Z().default("0.45mm"),p:Z().default("2.1mm")}),O0i=t=>{const e=H0i.parse(t),n=nr(0,he.parse(e.h)-.5,.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:he.parse(e.p)/2,y:he.parse(e.h)/2},{x:-he.parse(e.w)/2,y:he.parse(e.h)/2},{x:-he.parse(e.w)/2,y:-he.parse(e.h)/2},{x:he.parse(e.p)/2,y:-he.parse(e.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""},s={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:0,y:0},width:3.2,height:1.9,layer:"top"};return{circuitJson:Y0i(e).concat(...gC(e),o,n,s),parameters:e}},G0i=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},Y0i=t=>{const e=[],n=he.parse(t.p),o=he.parse(t.pl),i=he.parse(t.pw),r=.05625;for(let s=1;s<=t.num_pins;s++){const{x:a,y:A}=G0i({pn:s,p:n});e.push(yi(s,a,A,o,i,r))}return e},U0i=qi.extend({fn:Z(),num_pins:Xe(2).default(2),w:Z().default("1.4mm"),h:Z().default("0.9mm"),pl:Z().default("0.36mm"),pw:Z().default("0.25mm"),p:Z().default("0.85mm")}),K0i=t=>{const e=U0i.parse(t),n=he.parse(e.w),o=he.parse(e.h),i=he.parse(e.pl),r=he.parse(e.pw),s=he.parse(e.p),a=nr(0,o,.3),A={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:s/2+.15,y:o/2},{x:-n/2-.15,y:o/2},{x:-n/2-.15,y:-o/2},{x:s/2+.15,y:-o/2}],stroke_width:.1,pcb_silkscreen_path_id:""},c=s+i,l=r,g=n/2,u=o/2,h=c/2,d=l/2,m=Math.max(g,h),p=Math.max(u,d),_=Math.min(g,h),f=Math.min(u,d),I=m+.05,C=_-.055,y=p,x=f+.155,E={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",outline:ky([{minX:-I,maxX:I,minY:-x,maxY:x},{minX:-C,maxX:C,minY:-y,maxY:y}]),layer:"top"};return{circuitJson:z0i(e).concat(...gC(e),A,a,E),parameters:e}},V0i=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},z0i=t=>{const e=[],n=he.parse(t.p),o=he.parse(t.pl),i=he.parse(t.pw),r=.03125;for(let s=1;s<=t.num_pins;s++){const{x:a,y:A}=V0i({pn:s,p:n});e.push(yi(s,a,A,o,i,r))}return e},J0i=qi.extend({fn:Z(),num_pins:Xe(2).default(2),w:Z().default("1.3mm"),h:Z().default("0.9mm"),pl:Z().default("0.4mm"),pw:Z().default("0.7mm"),p:Z().default("0.7mm")}),W0i=t=>{const e=J0i.parse(t),n=nr(0,he.parse(e.h)+.1,.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:he.parse(e.p)/2+.2,y:he.parse(e.h)/2+.2},{x:-he.parse(e.w)/2-.2,y:he.parse(e.h)/2+.2},{x:-he.parse(e.w)/2-.2,y:-he.parse(e.h)/2-.2},{x:he.parse(e.p)/2+.2,y:-he.parse(e.h)/2-.2}],stroke_width:.1,pcb_silkscreen_path_id:""},s={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:0,y:0},width:1.6,height:1.2,layer:"top"};return{circuitJson:X0i(e).concat(...gC(e),o,n,s),parameters:e}},j0i=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},X0i=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=j0i({pn:n,p:Number.parseFloat(t.p)});e.push(yi(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw),.025))}return e},q0i=qi.extend({fn:Z(),num_pins:Xe(2).default(2),w:Z().default("3.05mm"),h:Z().default("1.4mm"),pl:Z().default("0.5mm"),pw:Z().default("0.5mm"),pad_spacing:Z().default("2.2mm")}),$0i=t=>{const e=q0i.parse(t),n=nr(0,he.parse(e.h),.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:he.parse(e.pad_spacing)/2,y:he.parse(e.h)/2},{x:-he.parse(e.w)/2-.2,y:he.parse(e.h)/2},{x:-he.parse(e.w)/2-.2,y:-he.parse(e.h)/2},{x:he.parse(e.pad_spacing)/2,y:-he.parse(e.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""},s={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:0,y:0},width:3.2,height:1.9,layer:"top"};return{circuitJson:egi(e).concat(...gC(e),o,n,s),parameters:e}},Z0i=t=>{const{pn:e,pad_spacing:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},egi=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=Z0i({pn:n,pad_spacing:Number.parseFloat(t.pad_spacing)});e.push(yi(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw),.0625))}return e},tgi=qi.extend({fn:Z(),num_pins:Xe(2).default(2),w:Z().default("4.4mm"),h:Z().default("2.1mm"),pl:Z().default("1.10mm"),pw:Z().default("1.10mm"),p:Z().default("2.8mm")}),ngi=t=>{const e=tgi.parse(t),n=nr(0,he.parse(e.h),.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:he.parse(e.p)/2,y:he.parse(e.h)/2},{x:-he.parse(e.w)/2-.2,y:he.parse(e.h)/2},{x:-he.parse(e.w)/2-.2,y:-he.parse(e.h)/2},{x:he.parse(e.p)/2,y:-he.parse(e.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""},s={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:0,y:0},width:4.4,height:2.3,layer:"top"};return{circuitJson:igi(e).concat(...gC(e),o,n,s),parameters:e}},ogi=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},igi=t=>{const e=[],n=he.parse(t.p),o=he.parse(t.pl),i=he.parse(t.pw),r=.125;for(let s=1;s<=t.num_pins;s++){const{x:a,y:A}=ogi({pn:s,p:n});e.push(yi(s,a,A,o,i,r))}return e},rgi=qi.extend({fn:Z(),num_pins:Xe(2).default(2),w:Z().default("4.4mm"),h:Z().default("2.1mm"),pl:Z().default("0.91mm"),pw:Z().default("1.22mm"),p:Z().default("3.146mm")}),sgi=t=>{const e=rgi.parse(t),n=nr(0,he.parse(e.h),.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:he.parse(e.p)/2,y:he.parse(e.h)/2},{x:-he.parse(e.w)/2-.2,y:he.parse(e.h)/2},{x:-he.parse(e.w)/2-.2,y:-he.parse(e.h)/2},{x:he.parse(e.p)/2,y:-he.parse(e.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""},s={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:0,y:0},width:4.9,height:2.7,layer:"top"};return{circuitJson:Agi(e).concat(...gC(e),o,n,s),parameters:e}},agi=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},Agi=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=agi({pn:n,p:Number.parseFloat(t.p)});e.push(yi(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return e},cgi=qi.extend({fn:Z(),num_pins:Xe(2).default(2),w:Z().default("1.80mm"),h:Z().default("1.00mm"),pl:Z().default("0.66mm"),pw:Z().default("0.5mm"),p:Z().default("0.8mm")}),lgi=t=>{const e=cgi.parse(t),n=nr(0,he.parse(e.h),.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:he.parse(e.p)/2,y:he.parse(e.h)/2},{x:-he.parse(e.w)/2-.1,y:he.parse(e.h)/2},{x:-he.parse(e.w)/2-.1,y:-he.parse(e.h)/2},{x:he.parse(e.p)/2,y:-he.parse(e.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""},s={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:0,y:0},width:2.3,height:1.5,layer:"top"};return{circuitJson:ugi(e).concat(...gC(e),o,n,s),parameters:e}},ggi=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},ugi=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=ggi({pn:n,p:Number.parseFloat(t.p)});e.push(yi(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return e},dgi=qi.extend({fn:Z(),num_pins:Xe(2).default(2),w:Z().default("6.2mm"),h:Z().default("3.4mm"),pl:Z().default("1.4mm"),pw:Z().default("2.1mm"),p:Z().default("4.4mm")}),hgi=t=>{const e=dgi.parse(t),n=nr(0,he.parse(e.h)/2+.4,.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:he.parse(e.p)/2,y:he.parse(e.h)/2},{x:-he.parse(e.w)/2-.2,y:he.parse(e.h)/2},{x:-he.parse(e.w)/2-.2,y:-he.parse(e.h)/2},{x:he.parse(e.p)/2,y:-he.parse(e.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""},s={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:0,y:0},width:6.3,height:3,layer:"top"};return{circuitJson:pgi(e).concat(...gC(e),o,n,s),parameters:e}},mgi=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},pgi=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=mgi({pn:n,p:Number.parseFloat(t.p)});e.push(yi(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw),.125))}return e},Stn=(t,e)=>({type:"pcb_smtpad",points:e,layer:"top",shape:"polygon",pcb_smtpad_id:"",port_hints:Array.isArray(t)?t.map(n=>n.toString()):[t.toString()]}),_gi=[{x:-2.85,y:-2.5},{x:-2.85,y:2.5},{x:2.25,y:2.5},{x:2.25,y:-2.5}],fgi=[{x:-2.85,y:-2.5},{x:-2.85,y:2.5},{x:2.85,y:2.5},{x:2.85,y:-2.5}],Igi=[{x:.9,y:.5},{x:2.6,y:.5},{x:2.6,y:-.5},{x:.9,y:-.5},{x:.4,y:-1},{x:-.4,y:-1},{x:-.9,y:-.5},{x:-2.6,y:-.5},{x:-2.6,y:.5},{x:-.9,y:.5},{x:-.4,y:1},{x:.4,y:1}],Cgi=[{x:2,y:-.8665},{x:-1.125,y:-.8665},{x:-1.125,y:-.45},{x:-2.6,y:-.45},{x:-2.6,y:.45},{x:-1.125,y:.45},{x:-1.125,y:.8665},{x:2,y:.8665}],ygi=qi.extend({fn:Z(),num_pins:Eo([Xe(3),Xe(5)]).default(3),w:Z().default("4.20mm"),h:Z().default("4.80mm"),pl:Z().default("1.3mm"),pw:Z().default("0.9mm"),p:Z().default("1.5mm"),string:Z().optional()}),xgi=t=>{const e=Number.parseFloat(t.p),n=Number.parseFloat(t.pw),o=Number.parseFloat(t.w),i=Number.parseFloat(t.pl),r=-o/2+.15,s=o/2-1,a=Number.parseFloat(t.h)/2,A=[yi(1,r,e,i,n),Stn(2,Cgi),yi(3,r,-e,i,n)],c=nr(0,a+.5,.3),l={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-s,y:a},{x:s,y:a},{x:s,y:a/2+.5}],type:"pcb_silkscreen_path",stroke_width:.1},g={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_2",route:[{x:-s,y:-a},{x:s,y:-a},{x:s,y:-a/2-.5}],type:"pcb_silkscreen_path",stroke_width:.1},u={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",outline:_gi,layer:"top"};return[...A,l,g,c,u]},Egi=t=>{const e=[yi(1,-1.85,-1.5,1.5,.7),yi(2,-1.85,1.5,1.5,.7),Stn(3,Igi),yi(4,1.85,-1.5,1.5,.7),yi(5,1.85,1.5,1.5,.7)],n=Number.parseFloat(t.w)/2-1,o=Number.parseFloat(t.h)/2,i=nr(0,o+.5,.3),r={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-n,y:o},{x:n,y:o}],type:"pcb_silkscreen_path",stroke_width:.1},s={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_2",route:[{x:-n,y:-o},{x:n,y:-o}],type:"pcb_silkscreen_path",stroke_width:.1},a={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",outline:fgi,layer:"top"};return[...e,r,s,i,a]},Bgi=t=>{const e=t.string?.match(/^sot89_(\d+)/),n=e?Number.parseInt(e[1],10):3,o=ygi.parse({...t,num_pins:n});if(o.num_pins===3)return{circuitJson:xgi(o),parameters:o};if(o.num_pins===5)return{circuitJson:Egi(o),parameters:o};throw new Error("Invalid number of pins for SOT89")},Sgi=qi.extend({fn:Z(),p:he.optional().default("5.0mm"),id:he.optional().default("1.0mm"),od:he.optional().default("1.9mm"),w:he.optional().default("13mm"),h:he.optional().default("7mm"),num_pins:ft().optional(),string:Z().optional()}),btn=t=>{const e=Sgi.parse(t),{id:n,od:o,w:i,h:r,string:s}=e,a=e.num_pins??Number.parseInt(s?.match(/^to220(?:_|-)(\d+)/i)?.[1]??"3"),A=-1,c=i/2,l=r/2,g=2.5,u=i*.4,h=Math.max(g,u/(a-1)),d=Array.from({length:a},(H,G)=>{const K=a%2===0?(G-a/2+.5)*h:(G-Math.floor(a/2))*h;return Fa(G+1,K,A,n,o)}),m={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-c,y:-l},{x:c,y:-l},{x:c,y:l},{x:-c,y:l},{x:-c,y:-l}],stroke_width:.1,pcb_silkscreen_path_id:""},p=-l+2*r/3,_={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-c,y:p},{x:c,y:p}],stroke_width:.1,pcb_silkscreen_path_id:""},f=[{type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-i/6,y:p},{x:-i/6,y:l}],stroke_width:.1,pcb_silkscreen_path_id:""},{type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:i/6,y:p},{x:i/6,y:l}],stroke_width:.1,pcb_silkscreen_path_id:""}],I=nr(0,r/2+.6,.5),C=Math.max(...d.map(H=>Math.abs(H.x)))+o/2,y=A+o/2,x=A-o/2,E=Math.max(C+.25,c-o*.59),B=l-o*.63,b=x-(o/2+.01),Q=-E,w=E,D=Math.min(b,x-.25),k=Math.max(B,y+.25),R={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:(Q+w)/2,y:(D+k)/2},width:w-Q,height:k-D,layer:"top"};return{circuitJson:[...d,m,_,...f,I,R],parameters:{...e,p:h}}},hUe=2.54,bgi=qi.extend({fn:Z(),id:he.optional().default("1.2mm"),od:he.optional().default("1.905mm"),ph:he.optional().default("2mm"),w:he.optional().default("13mm"),h:he.optional().default("7mm"),num_pins:ft().optional(),string:Z().optional()}),Qgi=t=>{const e=bgi.parse(t),n=e.num_pins??Number.parseInt(e.string?.match(/^to220f(?:_|-)(\d+)/i)?.[1]??"3"),o=btn({...e,fn:"to220",string:e.string?.replace(/^to220f/i,"to220"),num_pins:n}),i=-1,r=Array.from({length:n},(a,A)=>{const c=n%2===0?(A-n/2+.5)*hUe:(A-Math.floor(n/2))*hUe;return A===0?xx({pn:1,x:c,y:i,holeDiameter:e.id,rectPadWidth:e.od,rectPadHeight:e.ph}):vP(A+1,c,i,Ja(e.id),Ja(e.od),Ja(e.ph))}),s=o.circuitJson.filter(a=>a.type!=="pcb_plated_hole");return{circuitJson:[...r,...s],parameters:{...e,p:hUe,num_pins:n}}},vgi=qi.extend({fn:Z(),num_pins:Xe(2).default(2),w:Z().default("5.40mm"),h:Z().default("2.30mm"),pl:Z().default("1.30mm"),pw:Z().default("1.70mm"),p:Z().default("3.5mm")}),Pgi=t=>{const e=vgi.parse(t),n=nr(0,he.parse(e.h)/2+.4,.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:he.parse(e.p)/2,y:he.parse(e.h)/2},{x:-he.parse(e.w)/2,y:he.parse(e.h)/2},{x:-he.parse(e.w)/2,y:-he.parse(e.h)/2},{x:he.parse(e.p)/2,y:-he.parse(e.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""},s={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:0,y:0},width:5.3,height:2.2,layer:"top"};return{circuitJson:Mgi(e).concat(o,n,s),parameters:e}},wgi=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},Mgi=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=wgi({pn:n,p:Number.parseFloat(t.p)});e.push(yi(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw),.125))}return e},Dgi=qi.extend({fn:Z(),num_pins:Xe(2).default(2),w:Z().default("1.90mm"),h:Z().default("1.33mm"),pl:Z().default("0.5mm"),pw:Z().default("0.7mm"),p:Z().default("0.8mm")}),Ngi=t=>{const e=Dgi.parse(t),n=nr(0,he.parse(e.h)+.1,.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:he.parse(e.p)/2+.1,y:he.parse(e.h)/2},{x:-he.parse(e.w)/2,y:he.parse(e.h)/2},{x:-he.parse(e.w)/2,y:-he.parse(e.h)/2},{x:he.parse(e.p)/2+.1,y:-he.parse(e.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""},s={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:0,y:0},width:1.8,height:1.2,layer:"top"};return{circuitJson:Tgi(e).concat(...gC(e),o,n,s),parameters:e}},Rgi=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},Tgi=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=Rgi({pn:n,p:Number.parseFloat(t.p)});e.push(yi(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw),.0625))}return e},kgi=qi.extend({fn:Z(),num_pins:Xe(2).default(2),w:Z().default("7.0mm"),h:Z().default("3.35mm"),pl:Z().default("1.50mm"),pw:Z().default("2.70mm"),p:Z().default("4.8mm")}),Fgi=t=>{const e=kgi.parse(t),n=nr(0,he.parse(e.h),.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:he.parse(e.p)/2,y:he.parse(e.h)/2},{x:-he.parse(e.w)/2,y:he.parse(e.h)/2},{x:-he.parse(e.w)/2,y:-he.parse(e.h)/2},{x:he.parse(e.p)/2,y:-he.parse(e.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""},s={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:0,y:0},width:6.8,height:3.2,layer:"top"};return{circuitJson:Hgi(e).concat(o,n,s),parameters:e}},Lgi=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},Hgi=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=Lgi({pn:n,p:Number.parseFloat(t.p)});e.push(yi(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw),.125))}return e},Ogi=qi.extend({fn:Z(),num_pins:Xe(2).default(2),w:Z().default("3.0mm"),h:Z().default("1.80mm"),pl:Z().default("0.80mm"),pw:Z().default("1.20mm"),p:Z().default("1.6mm")}),Ggi=t=>{const e=Ogi.parse(t),n=nr(0,he.parse(e.h),.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:he.parse(e.p)/2,y:he.parse(e.h)/2},{x:-he.parse(e.w)/2-.1,y:he.parse(e.h)/2},{x:-he.parse(e.w)/2-.1,y:-he.parse(e.h)/2},{x:he.parse(e.p)/2,y:-he.parse(e.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""},s={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:0,y:0},width:2.9,height:1.7,layer:"top"};return{circuitJson:Ugi(e).concat(o,n,s),parameters:e}},Ygi=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},Ugi=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=Ygi({pn:n,p:Number.parseFloat(t.p)});e.push(yi(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw),.1))}return e},Kgi=qi.extend({fn:Z(),num_pins:Xe(2).default(2),w:Z().default("7.10mm"),h:Z().default("3.40mm"),pl:Z().default("2.50mm"),pw:Z().default("1.80mm"),p:Z().default("4.00mm")}),Vgi=t=>{const e=Kgi.parse(t),n=nr(0,he.parse(e.h)/2+.5,.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:he.parse(e.p)/2,y:he.parse(e.h)/2},{x:-he.parse(e.w)/2-.5,y:he.parse(e.h)/2},{x:-he.parse(e.w)/2-.5,y:-he.parse(e.h)/2},{x:he.parse(e.p)/2,y:-he.parse(e.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""},s={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:0,y:0},width:7,height:3.5,layer:"top"};return{circuitJson:Jgi(e).concat(o,n,s),parameters:e}},zgi=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},Jgi=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=zgi({pn:n,p:Number.parseFloat(t.p)});e.push(yi(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw),.125))}return e},Wgi=qi.extend({fn:Z(),num_pins:Xe(2).default(2),w:Z().default("4.80mm"),h:Z().default("2.10mm"),pl:Z().default("1.30mm"),pw:Z().default("1.40mm"),p:Z().default("2.9mm")}),jgi=t=>{const e=Wgi.parse(t),n=nr(0,he.parse(e.h)-.5,.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:he.parse(e.p)/2,y:he.parse(e.h)/2},{x:-he.parse(e.w)/2,y:he.parse(e.h)/2},{x:-he.parse(e.w)/2,y:-he.parse(e.h)/2},{x:he.parse(e.p)/2,y:-he.parse(e.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""},s={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:0,y:0},width:4.7,height:2.3,layer:"top"};return{circuitJson:qgi(e).concat(o,n,s),parameters:e}},Xgi=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},qgi=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=Xgi({pn:n,p:Number.parseFloat(t.p)});e.push(yi(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw),.125))}return e},$gi=qi.extend({fn:Z(),num_pins:Xe(2).default(2),w:Z().default("7.30mm"),h:Z().default("4.40mm"),pl:Z().default("2.50mm"),pw:Z().default("2.30mm"),p:Z().default("4.30mm")}),Zgi=t=>{const e=$gi.parse(t),n=nr(0,he.parse(e.h)/2+.5,.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:he.parse(e.p)/2,y:he.parse(e.h)/2},{x:-he.parse(e.w)/2-.1,y:he.parse(e.h)/2},{x:-he.parse(e.w)/2-.1,y:-he.parse(e.h)/2},{x:he.parse(e.p)/2,y:-he.parse(e.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""},s={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:0,y:0},width:7.3,height:4.5,layer:"top"};return{circuitJson:tui(e).concat(o,n,s),parameters:e}},eui=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},tui=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=eui({pn:n,p:Number.parseFloat(t.p)});e.push(yi(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw),.125))}return e},nui=qi.extend({fn:Z(),num_pins:Xe(2).default(2),w:Z().default("10.70mm"),h:Z().default("6.60mm"),pl:Z().default("2.50mm"),pw:Z().default("3.30mm"),p:Z().default("6.80mm")}),oui=t=>{const e=nui.parse(t),n=nr(0,3,.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:he.parse(e.p)/2,y:he.parse(e.h)/2-.8},{x:-he.parse(e.w)/2-.8,y:he.parse(e.h)/2-.8},{x:-he.parse(e.w)/2-.8,y:-he.parse(e.h)/2+.8},{x:he.parse(e.p)/2,y:-he.parse(e.h)/2+.8}],stroke_width:.1,pcb_silkscreen_path_id:""},s={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:0,y:0},width:9.8,height:6.7,layer:"top"};return{circuitJson:rui(e).concat(o,n,s),parameters:e}},iui=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},rui=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=iui({pn:n,p:Number.parseFloat(t.p)});e.push(yi(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw),.125))}return e},sui=qi.extend({fn:Z(),num_pins:ft().default(4),w:Z().default("8.50mm"),h:Z().default("6.90mm"),pl:Z().default("2mm"),pw:Z().default("1.5mm"),p:Z().default("2.30mm"),string:Z().optional()}),aui=t=>{const e=t.string?.match(/^sot223_(\d+)/),n=e?Number.parseInt(e[1],10):4;if(n===8){const i=lui.parse({...t,num_pins:n});return{circuitJson:Aq(i),parameters:i}}const o=sui.parse({...t,num_pins:n});if(o.num_pins===4)return{circuitJson:cui(o),parameters:o};if(o.num_pins===5)return{circuitJson:uui(o),parameters:o};if(o.num_pins===6)return{circuitJson:hui(o),parameters:o};throw new Error("Invalid number of pins")},Aui=t=>{const{pn:e,w:n,p:o}=t;return e===1?{x:-n/2+1.1,y:o}:e===2?{x:-n/2+1.1,y:0}:e===3?{x:-n/2+1.1,y:-o}:{x:n/2-1.1,y:0}},cui=t=>{const e=[];let n=0,o=0;for(let d=0;d<t.num_pins;d++){const{x:m,y:p}=Aui({num_pins:t.num_pins,pn:d+1,w:Number.parseFloat(t.w),h:Number.parseFloat(t.h),pl:Number.parseFloat(t.pl),p:Number.parseFloat(t.p)}),_=d===3?3.8:Number.parseFloat(t.pw),f=Number.parseFloat(t.pl);n=Math.max(n,Math.abs(m)+f/2),o=Math.max(o,Math.abs(p)+_/2),e.push(yi(d+1,m,p,f,_))}const i=nr(0,0,.3),r=Number.parseFloat(t.w)/2-2.4,s=Number.parseFloat(t.h)/2,a={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-r,y:s},{x:r,y:s},{x:r,y:s/2+.5}],type:"pcb_silkscreen_path",stroke_width:.1},A={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_2",route:[{x:-r,y:-s},{x:r,y:-s},{x:r,y:-s/2-.5}],type:"pcb_silkscreen_path",stroke_width:.1},c=Number.parseFloat(t.w)/2,l=Number.parseFloat(t.h)/2,g=Math.max(n+.25,c+.15),u=Math.max(o+.25,l+.15),h={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:0,y:0},width:2*g,height:2*u,layer:"top"};return[...e,a,A,i,h]},lui=IR({p:"0.90mm",w:"2.8mm",legsoutside:!0}),gui=t=>{const{p:e,pn:n,w:o}=t;if(n===1)return{x:-o/2+1.2,y:e/2+e};if(n===2)return{x:-o/2+1.2,y:e/2};if(n===3)return{x:-o/2+1.2,y:-e/2};if(n===4)return{x:-o/2+1.2,y:-e/2-e};if(n===5)return{x:o/2-1,y:0};throw new Error("Invalid pin number")},uui=t=>{const e=[];let n=0,o=0;for(let d=1;d<=t.num_pins;d++){const{x:m,y:p}=gui({h:Number.parseFloat(t.h),p:1.5,pn:d,w:Number.parseFloat(t.w)});let _=Number.parseFloat(t.pw),f=Number.parseFloat(t.pl);d===5?(_=3.4,f=1.8):(_=1,f=2.2),n=Math.max(n,Math.abs(m)+f/2),o=Math.max(o,Math.abs(p)+_/2),e.push(yi(d,m,p,f,_))}const i=Number.parseFloat(t.w)/2-2.4,r=Number.parseFloat(t.h)/2,s={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-i,y:r},{x:i,y:r},{x:i,y:r/2+.5}],type:"pcb_silkscreen_path",stroke_width:.1},a={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_2",route:[{x:-i,y:-r},{x:i,y:-r},{x:i,y:-r/2-.5}],type:"pcb_silkscreen_path",stroke_width:.1},A=nr(0,0,.3),c=Number.parseFloat(t.w)/2,l=Number.parseFloat(t.h)/2,g=Math.max(n+.25,c+.15),u=Math.max(o+.25,l+.15),h={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:0,y:0},width:2*g,height:2*u,layer:"top"};return[...e,s,a,A,h]},dui=t=>{const{p:e,pn:n,w:o}=t;if(n===1)return{x:-o/2+1.2,y:2*e};if(n===2)return{x:-o/2+1.2,y:e};if(n===3)return{x:-o/2+1.2,y:0};if(n===4)return{x:-o/2+1.2,y:-e};if(n===5)return{x:-o/2+1.2,y:-2*e};if(n===6)return{x:o/2-1.175,y:0};throw new Error("Invalid pin number")},hui=t=>{const e=[];let n=0,o=0;for(let d=1;d<=t.num_pins;d++){const{x:m,y:p}=dui({h:Number.parseFloat(t.h),p:1.3,pn:d,w:8.7});let _=Number.parseFloat(t.pw),f=Number.parseFloat(t.pl);d===6?(_=3.4,f=2.15):(_=.6,f=2.2),n=Math.max(n,Math.abs(m)+f/2),o=Math.max(o,Math.abs(p)+_/2),e.push(yi(d,m,p,f,_))}const i=Number.parseFloat(t.w)/2-2.4,r=Number.parseFloat(t.h)/2,s={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-i,y:r},{x:i,y:r},{x:i,y:r/2+.5}],type:"pcb_silkscreen_path",stroke_width:.1},a={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_2",route:[{x:-i,y:-r},{x:i,y:-r},{x:i,y:-r/2-.5}],type:"pcb_silkscreen_path",stroke_width:.1},A=nr(0,0,.3),c=Number.parseFloat(t.w)/2,l=Number.parseFloat(t.h)/2,g=Math.max(n+.25,c+.15),u=Math.max(o+.25,l+.15),h={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:0,y:0},width:2*g,height:2*u,layer:"top"};return[...e,s,a,A,h]},mui=qi.extend({fn:Z(),num_pins:ft().default(3),w:Z().default("3.40mm"),h:Z().default("3.30mm"),pl:Z().default("1mm"),pw:Z().default("0.7mm"),p:Z().default("1.2mm"),string:Z().optional()}),pui=t=>{const e=t.string?.match(/^sot23w_(\d+)/),n=e?Number.parseInt(e[1],3):3,o=mui.parse({...t,num_pins:n});if(o.num_pins===3)return{circuitJson:fui(o),parameters:o};throw new Error("Invalid number of pins")},_ui=t=>{const{pn:e,p:n}=t;return e===1?{x:-n,y:.95}:e===2?{x:-n,y:-.95}:{x:n,y:0}},fui=t=>{const e=[];for(let _=0;_<t.num_pins;_++){const{x:f,y:I}=_ui({num_pins:t.num_pins,pn:_+1,w:Number.parseFloat(t.w),h:Number.parseFloat(t.h),pl:Number.parseFloat(t.pl),p:Number.parseFloat(t.p)});e.push(yi(_+1,f,I,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}const n=nr(0,Number.parseInt(t.h)/2+1,.3),o=Number.parseFloat(t.w)/2-1,i=Number.parseFloat(t.h)/2,r={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-o,y:i},{x:o+.3,y:i},{x:o+.3,y:i/2}],type:"pcb_silkscreen_path",stroke_width:.1},s={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_2",route:[{x:-o,y:-i},{x:o+.3,y:-i},{x:o+.3,y:-i/2}],type:"pcb_silkscreen_path",stroke_width:.1},a=Number.parseFloat(t.p),A=Number.parseFloat(t.pl),c=Number.parseFloat(t.pw),l=Number.parseFloat(t.h),g=a+A/2,u=.95+c/2,h=l/2,d=g+.25,m=Math.max(u+.25,h+.09),p={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:0,y:0},width:2*d,height:2*m,layer:"top"};return[...e,r,s,n,p]},Iui=qi.extend({fn:Z(),num_pins:Eo([Xe(3),Xe(2)]).default(3),p:Z().default("1.27mm"),id:Z().default("0.72mm"),od:Z().default("0.95mm"),w:Z().default("2.5mm"),h:Z().default("4.2mm"),string:Z().optional()}),Cui=t=>{const{p:e,id:n,od:o,w:i,h:r}=t,s=Number.parseFloat(r)/2,a=Number.parseFloat(e);return[Fa(1,-a,s-a,n,o),Fa(2,0,s-a,n,o),Fa(3,a,s-a,n,o)]},yui=t=>{const{p:e,id:n,od:o,h:i}=t,r=Number.parseFloat(i)/2,s=Number.parseFloat(e),a=Number.parseFloat(n),A=Number.parseFloat(o),c=A*(1.5/1.05);return[xx({pn:1,x:-s,y:r-s,holeDiameter:a,rectPadWidth:A,rectPadHeight:c}),vP(2,s,r-s,a,A,c)]},xui=t=>{const e=t.string?.match(/^to92s_(\d+)/),n=e?Number.parseInt(e[1],10):3,o=Iui.parse({...t,num_pins:n});let i=[];if(o.num_pins===3)i=Cui(o);else if(o.num_pins===2)i=yui(o);else throw new Error("Invalid number of pins for TO-92");const r=Number.parseFloat(o.h)/2,s=Number.parseFloat(o.p),a={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-r,y:r-s},{x:-1.9,y:0},{x:1.9,y:0},{x:r,y:r-s},{x:1.5,y:Number.parseFloat(o.h)/2+.5},{x:-1.5,y:Number.parseFloat(o.h)/2+.5},{x:-r,y:r-s}],stroke_width:.1,pcb_silkscreen_path_id:""},A=nr(0,r+1,.5),c=Number.parseFloat(o.od),l=r-s,g=-s-c/2,u=s+c/2,h=l-c/2,d=l+c/2,m=-r,p=r,_=0,f=r+.5,I=Math.min(g,m)-.27,C=Math.max(u,p)+.13,y=Math.min(h,_)-.42,x=Math.max(d,f)+.08,E={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:(I+C)/2,y:(y+x)/2},width:C-I,height:x-y,layer:"top"};return{circuitJson:[...i,a,A,E],parameters:o}},Eui=qi.extend({fn:Z(),p:he.optional(),id:he.optional(),pw:he.optional(),pl:he.optional(),w:he.optional(),h:he.optional(),sh:je().optional().describe('JST SH (Surface-mount) connector family. SH stands for "Super High-density".'),ph:je().optional().describe('JST PH (Through-hole) connector family. PH stands for "Pin Header".'),zh:je().optional().describe("JST ZH (Through-hole) connector family. 1.5mm pitch wire-to-board."),string:Z().optional()}),Bui=()=>({minX:Number.POSITIVE_INFINITY,maxX:Number.NEGATIVE_INFINITY,minY:Number.POSITIVE_INFINITY,maxY:Number.NEGATIVE_INFINITY}),cq=({bounds:t,centerX:e,centerY:n,width:o,height:i})=>{const r=o/2,s=i/2;t.minX=Math.min(t.minX,e-r),t.maxX=Math.max(t.maxX,e+r),t.minY=Math.min(t.minY,n-s),t.maxY=Math.max(t.maxY,n+s)},Sui={ph:{p:he.parse("2.2mm"),id:he.parse("0.70mm"),pw:he.parse("1.20mm"),pl:he.parse("1.20mm"),w:he.parse("6mm"),h:he.parse("5mm")},sh:{p:he.parse("1mm"),pw:he.parse("0.6mm"),pl:he.parse("1.55mm"),w:he.parse("5.8mm"),h:he.parse("7.8mm")},zh:{p:he.parse("1.5mm"),id:he.parse("0.73mm"),pw:he.parse("1.03mm"),pl:he.parse("1.73mm"),w:he.parse("3mm"),h:he.parse("3.5mm")}};function bui(t){return t.sh?"sh":t.ph?"ph":t.zh?"zh":"ph"}function Qui({variant:t,numPins:e,p:n,id:o,pw:i,pl:r}){const s=[],a=Bui();let A=0;if(t==="ph"){const c=-((e-1)/2)*n;for(let l=0;l<e;l++){const g=c+l*n;s.push(xx({pn:l+1,x:g,y:2,holeDiameter:o,rectPadWidth:i,rectPadHeight:r})),cq({bounds:a,centerX:g,centerY:2,width:i,height:r}),A=Math.max(A,r/2)}}else if(t==="zh"){const c=-((e-1)/2)*n;for(let l=0;l<e;l++){const g=c+l*n;l===0?s.push(xx({pn:l+1,x:g,y:0,holeDiameter:o,rectPadWidth:i,rectPadHeight:r,rectBorderRadius:.12499977})):s.push(vP(l+1,g,0,o,i,r)),cq({bounds:a,centerX:g,centerY:0,width:i,height:r}),A=Math.max(A,r/2)}}else{const c=-((e-1)/2)*n;for(let g=0;g<e;g++){const u=c+g*n;s.push(yi(g+1,u,-1.325,i,r)),cq({bounds:a,centerX:u,centerY:-1.325,width:i,height:r}),A=Math.max(A,r/2)}const l=(e-1)/2*n+1.3;s.push(yi(e+1,-l,1.22,1.2,1.8)),s.push(yi(e+2,l,1.22,1.2,1.8)),cq({bounds:a,centerX:-l,centerY:1.22,width:1.2,height:1.8}),cq({bounds:a,centerX:l,centerY:1.22,width:1.2,height:1.8}),A=Math.max(A,.9)}return{pads:s,padBounds:a,maxPadHalfY:A}}function vui({variant:t,w:e,h:n,numPins:o,p:i}){if(t==="ph")return{type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-3,y:3},{x:3,y:3},{x:3,y:-2},{x:-3,y:-2},{x:-3,y:3}],stroke_width:.1,pcb_silkscreen_path_id:""};if(t==="zh"&&o&&i){const r=(o-1)*i,s=-r/2-1.5,a=r/2+1.5,A=-n/2,c=n/2;return{type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:s,y:A},{x:a,y:A},{x:a,y:c},{x:s,y:c},{x:s,y:A}],stroke_width:.1,pcb_silkscreen_path_id:""}}else return{type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[],stroke_width:.1,pcb_silkscreen_path_id:""}}var Pui=t=>{const e=Eui.parse(t),n=bui(e),o=Sui[n],i=e.p??o.p,r=e.id??o.id,s=e.pw??o.pw,a=e.pl??o.pl,A=e.w??o.w,c=e.h??o.h;let l;const g=t.num_pins;typeof g=="number"&&(l=g);const u=typeof t.string=="string"?t.string:"",h=u.match(/(?:^|_)jst(\d+)(?:_|$)/),d=u.match(/(?:^|_)zh(\d+)(?:_|$)/);if(h&&h[1]){const te=Number.parseInt(h[1],10);Number.isNaN(te)||(l=te)}if(d&&d[1]){const te=Number.parseInt(d[1],10);Number.isNaN(te)||(l=te)}if(typeof l!="number")throw new Error(`JST requires an explicit pin count (e.g. jst6_sh or .jst(6))${e.string?`, from string "${e.string}"`:""}`);const m=Qui({variant:n,numPins:l,p:i,id:r,pw:s,pl:a}),{pads:p,padBounds:_,maxPadHalfY:f}=m,I=vui({variant:n,w:A,h:c,numPins:l,p:i}),C=nr(0,c/2+1,.5),y=I.route.map(te=>te.x),x=I.route.map(te=>te.y),E=y.length>0&&x.length>0,B=E?Math.min(_.minX,Math.min(...y)):_.minX,b=E?Math.max(_.maxX,Math.max(...y)):_.maxX,Q=E?Math.min(_.minY,Math.min(...x)):_.minY,w=E?Math.max(_.maxY,Math.max(...x)):_.maxY,D=.5,k=.05,R=f+.085,H=B-D,G=b+D,K=Q-R,Y=w+k,X={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:(H+G)/2,y:(K+Y)/2},width:G-H,height:Y-K,layer:"top"};return{circuitJson:[...p,I,C,X],parameters:{...e,p:i,id:r,pw:s,pl:a,w:A,h:c,num_pins:l,sh:n==="sh",ph:n==="ph",zh:n==="zh"}}},wui=qi.extend({fn:Z(),num_pins:Xe(2).default(2),w:Z().default("3.30mm"),h:Z().default("1.70mm"),pl:Z().default("0.80mm"),pw:Z().default("1mm"),p:Z().default("1.90mm")}),Mui=t=>{const e=wui.parse(t),n=nr(0,he.parse(e.h)/2+.5,.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:he.parse(e.p)/2,y:he.parse(e.h)/2},{x:-he.parse(e.w)/2,y:he.parse(e.h)/2},{x:-he.parse(e.w)/2,y:-he.parse(e.h)/2},{x:he.parse(e.p)/2,y:-he.parse(e.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""},s={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:0,y:0},width:3.2,height:2,layer:"top"};return{circuitJson:Nui(e).concat(...gC(e),o,n,s),parameters:e}},Dui=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},Nui=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=Dui({pn:n,p:Number.parseFloat(t.p)});e.push(yi(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw),.1))}return e},Rui=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"}}},Tui=qi.extend({fn:Z(),num_pins:Eo([Xe(8),Xe(10)]).default(8),w:Z().optional(),h:Z().optional(),p:Z().optional(),pl:Z().optional(),pw:Z().optional(),string:Z().optional()}),kui=t=>{const e=Tui.parse(t),n=Rui(e.num_pins),o=he.parse(e.w||n.w),i=he.parse(e.h||n.h),r=he.parse(e.p||n.p),s=he.parse(e.pl||n.pl),a=he.parse(e.pw||n.pw),A=[],c=e.num_pins/2;for(let B=0;B<e.num_pins;B++){const{x:b,y:Q}=Qtn(e.num_pins,B+1,o,r),w=B<c?B+1:e.num_pins-(B-c);A.push(yi(w,b,Q,s,a))}const l=o,g=i,u={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-l/2,y:g/2},{x:l/2,y:g/2}],stroke_width:.05,pcb_silkscreen_path_id:""},h={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-l/2,y:-g/2},{x:l/2,y:-g/2}],stroke_width:.05,pcb_silkscreen_path_id:""},d=Qtn(e.num_pins,1,l,r),m={x:d.x-.8,y:d.y},p={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"pin_marker_1",route:[{x:m.x-.4,y:m.y},{x:m.x-.7,y:m.y+.3},{x:m.x-.7,y:m.y-.3},{x:m.x-.4,y:m.y}],stroke_width:.05,pcb_silkscreen_path_id:"pin_marker_1"},_=nr(0,g/2+.5,.3),f=(e.num_pins/2-1)*r+a,I=o/2+.25,C=I+1.43,y=f/2+.255,x=i/2+.25,E={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",layer:"top",outline:ky([{minX:-C,maxX:C,minY:-y,maxY:y},{minX:-I,maxX:I,minY:-x,maxY:x}])};return{circuitJson:[...A,u,h,_,p,E],parameters:e}},Qtn=(t,e,n,o)=>{const i=t/2,r=(e-1)%i,s=e<=i?-1:1,a=(i-1)/2-r;return{x:s*2.11,y:a*o}},Fui=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"}}},Lui=qi.extend({fn:Z(),num_pins:Eo([Xe(8),Xe(10),Xe(12),Xe(16)]).default(8),w:Z().optional(),h:Z().optional(),p:Z().optional(),pl:Z().optional(),pw:Z().optional(),string:Z().optional()}),vtn=(t,e,n,o,i)=>{const r=t/2,s=(e-1)%r,a=e<=r?-1:1,A=(r-1)/2-s,c=he.parse("0.2mm");return{x:a*(n/2+i/2-c),y:A*o}},Hui=t=>{const e=Lui.parse(t),n=Fui(e.num_pins),o=he.parse(e.w||n.w),i=he.parse(e.h||n.h),r=he.parse(e.p||n.p),s=he.parse(e.pl||n.pl),a=he.parse(e.pw||n.pw),A=[];for(let E=0;E<e.num_pins;E++){const{x:B,y:b}=vtn(e.num_pins,E+1,o,r,s);A.push(yi(E+1,B,b,s,a))}const c=o,l=i,g={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-c/2,y:l/2},{x:c/2,y:l/2}],stroke_width:.05,pcb_silkscreen_path_id:""},u={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-c/2,y:-l/2},{x:c/2,y:-l/2}],stroke_width:.05,pcb_silkscreen_path_id:""},h=vtn(e.num_pins,1,c,r,s),d={x:h.x-.8,y:h.y},m={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"pin_marker_1",route:[{x:d.x-.4,y:d.y},{x:d.x-.7,y:d.y+.3},{x:d.x-.7,y:d.y-.3},{x:d.x-.4,y:d.y}],stroke_width:.05,pcb_silkscreen_path_id:"pin_marker_1"},p=nr(0,l/2+.5,.3),_=(e.num_pins/2-1)*r+a,f=o/2+.25,I=f+1.43,C=_/2+.255,y=i/2+.25,x={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",layer:"top",outline:ky([{minX:-I,maxX:I,minY:-C,maxY:C},{minX:-f,maxX:f,minY:-y,maxY:y}])};return{circuitJson:[...A,g,u,p,m,x],parameters:e}},Oui=qi.extend({fn:Z(),num_pins:Xe(2).default(2),w:Z().default("3.8mm"),h:Z().default("1.65mm"),pl:Z().default("1.2mm"),pw:Z().default("1.2mm"),pad_spacing:Z().default("2.6mm")}),Gui=t=>{const e=Oui.parse(t),n=nr(0,he.parse(e.h),.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:he.parse(e.pad_spacing)/2,y:he.parse(e.h)/2},{x:-he.parse(e.w)/2-.2,y:he.parse(e.h)/2},{x:-he.parse(e.w)/2-.2,y:-he.parse(e.h)/2},{x:he.parse(e.pad_spacing)/2,y:-he.parse(e.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""},s={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:0,y:0},width:4.3,height:2.15,layer:"top"};return{circuitJson:Uui(e).concat(...gC(e),o,n,s),parameters:e}},Yui=t=>{const{pn:e,pad_spacing:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},Uui=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=Yui({pn:n,pad_spacing:Number.parseFloat(t.pad_spacing)});e.push(yi(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return e},Kui=qi.extend({fn:Z(),num_pins:Xe(2).default(2),w:Z().default("3.20mm"),h:Z().default("1.65mm"),pl:Z().default("0.8mm"),pw:Z().default("0.9mm"),pad_spacing:Z().default("2.1mm")}),Vui=t=>{const e=Kui.parse(t),n=nr(0,he.parse(e.h),.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:he.parse(e.pad_spacing)/2,y:he.parse(e.h)/2},{x:-he.parse(e.w)/2-.2,y:he.parse(e.h)/2},{x:-he.parse(e.w)/2-.2,y:-he.parse(e.h)/2},{x:he.parse(e.pad_spacing)/2,y:-he.parse(e.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""},s={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:0,y:0},width:3.7,height:2.15,layer:"top"};return{circuitJson:Jui(e).concat(...gC(e),o,n,s),parameters:e}},zui=t=>{const{pn:e,pad_spacing:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},Jui=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=zui({pn:n,pad_spacing:Number.parseFloat(t.pad_spacing)});e.push(yi(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return e},Wui=qi.extend({fn:Z(),num_pins:Eo([Xe(6),Xe(8)]).default(8),w:Z().default("3mm"),h:Z().default("3mm"),p:Z().default("0.5mm"),pl:Z().default("0.52mm"),pw:Z().default("0.35mm"),epw:Z().default("1.40mm"),eph:Z().default("1.60mm"),string:Z().optional(),ep:je().default(!1)}),jui=t=>{t.string&&t.string.includes("_ep")&&(t.ep=!0);const e=t.string?.match(/^son_(\d+)/),n=e?Number.parseInt(e[1],10):t.num_pins||8,o=Wui.parse({...t,num_pins:n}),i=he.parse(o.w),r=he.parse(o.h),s=he.parse(o.p),a=he.parse(o.pl),A=he.parse(o.pw),c=he.parse(o.epw),l=he.parse(o.eph),g=[];for(let D=0;D<o.num_pins;D++){const{x:k,y:R}=mUe(o.num_pins,D+1,i,s);g.push(yi(D+1,k,R,a,A))}o.ep&&g.push(yi(o.num_pins+1,0,0,c,l));const u=i,h=r,d={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-u/2,y:h/2},{x:u/2,y:h/2}],stroke_width:.05,pcb_silkscreen_path_id:""},m={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-u/2,y:-h/2},{x:u/2,y:-h/2}],stroke_width:.05,pcb_silkscreen_path_id:""},p=mUe(o.num_pins,1,u,s),_={x:p.x-.4,y:p.y},f={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"pin_marker_1",route:[{x:_.x-.4,y:_.y},{x:_.x-.7,y:_.y+.3},{x:_.x-.7,y:_.y-.3},{x:_.x-.4,y:_.y}],stroke_width:.05,pcb_silkscreen_path_id:"pin_marker_1"},I=nr(0,h/2+.5,.3),C=Math.abs(mUe(o.num_pins,1,i,s).x),y=(o.num_pins/2-1)*s+A,x=C*2+a,E=i/2+.25,B=x/2+.25,b=y/2+.25,Q=r/2+.25,w={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",layer:"top",outline:ky([{minX:-B,maxX:B,minY:-b,maxY:b},{minX:-E,maxX:E,minY:-Q,maxY:Q}])};return{circuitJson:[...g,d,m,I,f,w],parameters:o}},mUe=(t,e,n,o)=>{const i=t/2,r=(e-1)%i,s=e<=i?-1:1,a=(i-1)/2-r;return{x:s*he.parse("1.4mm"),y:a*o}},Xui=qi.extend({fn:Z(),num_pins:ft().optional().default(8),p:ct.describe("pitch (distance between center of each pin)"),w:he.describe("width between vertical rows of pins"),grid:ude.describe("width and height of the border of the footprint"),ep:ude.default("0x0mm").describe("width and height of the central exposed thermal pad"),epx:he.default("0mm").describe("x offset of the center of the central exposed thermal pad"),pinw:he.describe("width of the pin pads"),pinh:he.describe("height of the pin pads")}),qui=t=>{const e=Xui.parse(t),{num_pins:n,p:o,w:i,grid:r,ep:s,epx:a,pinw:A,pinh:c}=e;if(n%2!==0)throw new Error("invalid number of pins");const l=[];for(let E=0;E<n;E++){const{pinX:B,pinY:b}=$ui({pinCount:n,pinIndex:E,width:i,pitch:o});l.push(yi(E+1,B,b,A,c))}s.x>0&&s.y>0&&l.push(yi(e.num_pins+1,a,0,s.x,s.y));const g=Zui(r),u=nr(0,r.y/2+o,r.y/6),h=(n/2-1)*o+c,d=i+A,m=r.x/2+.25,p=d/2+.25,_=h/2+.25,f=h/2+.45+Math.max(0,.8-o),I=Math.min(r.y/2+.25,f),C=Math.max(0,.37-Math.max(0,p-m-.38)*1.4),y=Math.max(_,I-C),x={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",layer:"top",outline:ky([{minX:-p,maxX:p,minY:-y,maxY:y},{minX:-m,maxX:m,minY:-I,maxY:I}])};return{circuitJson:[...l,...g,u,x],parameters:e}},$ui=t=>{let e=0,n=0;const o=(t.pinCount/2-1)*t.pitch/2,i=t.pinCount/2;return t.pinIndex+1<=i?(e=t.pitch*t.pinIndex-o,n=0-t.width/2):(e=t.pitch*(t.pinCount-t.pinIndex-1)-o,n=t.width/2),{pinX:n,pinY:e}},Zui=t=>{const n=t.y/30;return[{layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"",type:"pcb_silkscreen_path",route:[{x:-t.x/2-.1,y:t.y/2+.1-n},{x:-t.x/2-.1,y:t.y/2+.1},{x:t.x/2+.1,y:t.y/2+.1},{x:t.x/2+.1,y:t.y/2+.1-n}],stroke_width:t.y/30},{layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"",type:"pcb_silkscreen_path",route:[{x:-t.x/2-.1,y:-t.y/2-.1+n},{x:-t.x/2-.1,y:-t.y/2-.1},{x:t.x/2+.1,y:-t.y/2-.1},{x:t.x/2+.1,y:-t.y/2-.1+n}],stroke_width:t.y/30}]},edi=t=>{const{num_pins:e,bridged:n,p:o=2.54,pw:i=1.5,ph:r=1.5}=t,s=he.parse(o),a=he.parse(i),A=he.parse(r),c=Math.min(A/4,.5),l=[];for(let Q=0;Q<e;Q++)l.push(yi(Q+1,Q*s,0,a,A));let g=[];if(n){const Q=n.split("").map(Number);if(Q.length>1)for(let w=0;w<Q.length-1;w++){const D=Q[w],k=Q[w+1];if(typeof D=="number"&&typeof k=="number"&&!isNaN(D)&&!isNaN(k)){const R=(D-1)*s,H=(k-1)*s,G=Math.sign(H-R),K=R+G*(a/2),Y=H-G*(a/2);g.push({type:"pcb_trace",pcb_trace_id:"",route:[{start_pcb_port_id:`{PIN${D}}`,x:K,y:0,width:c,layer:"top",route_type:"wire"},{end_pcb_port_id:`{PIN${k}}`,x:Y,y:0,width:c,layer:"top",route_type:"wire"}]})}}}const u=(e-1)*s+a+.7,h=A+1,d=(e-1)*s/2,m=0,p={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"outline",route:[{x:d-u/2,y:m-h/2},{x:d+u/2,y:m-h/2},{x:d+u/2,y:m+h/2},{x:d-u/2,y:m+h/2},{x:d-u/2,y:m-h/2}],stroke_width:.15},f=m+h/2+.6,I=nr(d,f,.4),C=(e-1)*s,y=C/2+a/2,x=A/2,E=y+.5,B=x+.5,b={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:C/2,y:0},width:2*E,height:2*B,layer:"top"};return{circuitJson:[...l,...g,p,I,b],parameters:t}},Ptn={fn:Xe("sot457"),num_pins:Xe(6).default(6),pillh:Z().default("0.45mm"),pillw:Z().default("1.45mm"),pl:Z(),pw:Z(),p:Z(),wave:je().optional(),reflow:je().optional()},tdi=qi.extend({...Ptn,h:Z().default("2.5mm"),w:Z().default("2.7mm"),pl:Z().default("0.8mm"),pw:Z().default("0.55mm"),p:Z().default("0.95mm")}),ndi=qi.extend({...Ptn,h:Z().default("3mm"),w:Z().default("4mm"),pillr:Z().default("0.225mm"),pl:Z().default("1.45mm"),pw:Z().default("1.5mm"),p:Z().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)})),NS=t=>Number.parseFloat(t.replace("mm","")),wtn=({pitch:t,width:e,pinNumber:n})=>{const r={1:{x:-e/2-.1,y:t},2:{x:-e/2-.1,y:0},3:{x:-e/2-.1,y:-t},4:{x:e/2+.1,y:-t},5:{x:e/2+.1,y:0},6:{x:e/2+.1,y:t}}[n];if(!r)throw new Error(`Invalid pin number: ${n}`);return r},Mtn=t=>{const e=[],n=NS(t.p),o=NS(t.pl),i=NS(t.pw),r=NS(t.w),s=NS(t.h);if(t.wave){const m={1:({padWidth:p,padHeight:_})=>yi(1,-n,n,_,p),2:({padWidth:p,padHeight:_})=>yi(2,-n,-n,_,p),3:({padWidth:p,padHeight:_})=>dde(3,-n,0,NS(t.pillw),NS(t.pillh)),4:({padWidth:p,padHeight:_})=>dde(4,n,0,NS(t.pillw),NS(t.pillh)),5:({padWidth:p,padHeight:_})=>yi(5,n,n,_,p),6:({padWidth:p,padHeight:_})=>yi(6,n,-n,_,p)};for(let p=1;p<=t.num_pins;p++){const _=m[p];_&&e.push(_({padWidth:o,padHeight:i}))}}else for(let m=1;m<=t.num_pins;m++){const{x:p,y:_}=wtn({pitch:n,width:r,pinNumber:m});e.push(yi(m,p,_,o,i))}const a={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-r/3,y:s/2+n/1.3},{x:r/3,y:s/2+n/1.3}],stroke_width:.05},A={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_2",route:[{x:-r/3,y:-s/2-n/1.3},{x:r/3,y:-s/2-n/1.3}],stroke_width:.05},c=nr(0,s+.5,.3),l=wtn({pitch:n,width:r,pinNumber:1}),g=t.wave?1:.5,u=t.wave?.7:.3;l.x-=t.wave?i:i*1.7;const h={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"pin1_indicator",route:[{x:l.x+g/2,y:l.y},{x:l.x-g/2,y:l.y+u/2},{x:l.x-g/2,y:l.y-u/2},{x:l.x+g/2,y:l.y}],stroke_width:.05};let d;if(t.wave){const m=2*n,p=2*n,_=m/2+i/2,f=p/2+o/2,I=_+.25,C=f+.25;d={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:0,y:0},width:2*I,height:2*C,layer:"top"}}else{const p=r/2+.1+o/2,_=n+i/2,f=r/2,I=s/2,C=p+.25,y=f+.08,x=_+.25,E=Math.max(I+.45,x);d={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",outline:ky([{minX:-C,maxX:C,minY:-x,maxY:x},{minX:-y,maxX:y,minY:-E,maxY:E}]),layer:"top"}}return[c,a,A,h,...e,d]},odi=t=>{if(t.wave){const n=ndi.parse({...t,fn:"sot457"});return{circuitJson:Mtn(n),parameters:n}}const e=tdi.parse(t);return{circuitJson:Mtn(e),parameters:e}},idi=[{x:-.8,y:.75},{x:.8,y:.75},{x:.8,y:-.75},{x:-.8,y:-.75}],rdi=qi.extend({fn:Z(),num_pins:Xe(6).default(6),w:Z().default("1.1mm"),h:Z().default("1.45mm"),p:Z().default("0.35mm"),pl:Z().default("0.2mm"),pw:Z().default("0.2mm"),string:Z().optional()}),sdi=t=>{const e=rdi.parse({...t,fn:"sot963"}),n=he.parse(e.w),o=he.parse(e.h),i=he.parse(e.p),r=he.parse(e.pl),s=he.parse(e.pw),a=[];for(let d=0;d<6;d++){const{x:m,y:p}=Dtn(d+1,n,i,r);a.push(yi(d+1,m,p,r,s))}const A={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-n/2,y:o/2},{x:n/2,y:o/2}],stroke_width:.05,pcb_silkscreen_path_id:""},c={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:-n/2,y:-o/2},{x:n/2,y:-o/2}],stroke_width:.05,pcb_silkscreen_path_id:""},l=Dtn(1,n,i,r),g={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"pin_marker_1",route:[{x:l.x-r/2-.3,y:l.y},{x:l.x-r/2-.45,y:l.y+.15},{x:l.x-r/2-.45,y:l.y-.15},{x:l.x-r/2-.3,y:l.y}],stroke_width:.05,pcb_silkscreen_path_id:"pin_marker_1"},u=nr(0,o/2+.4,.25),h={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",outline:idi,layer:"top"};return{circuitJson:[...a,A,c,u,g,h],parameters:e}},Dtn=(t,e,n,o)=>{const i=e/2-o/2;return t<=3?{x:-i,y:n-(t-1)*n}:{x:i,y:-n+(t-4)*n}},adi=qi.extend({fn:Z(),num_pins:Eo([Xe(3),Xe(2)]).default(3),p:Z().default("5mm"),id:Z().default("1.25mm"),od:Z().default("2.35mm"),ca:Z().default("14mm").describe("Caliper axis (width or diameter of the potentiometer body or adjustment knob)"),w:Z().default("5.35mm"),h:Z().default("4mm"),string:Z().optional()}),Adi=t=>{const{p:e,id:n,od:o,h:i}=t,r=Number.parseFloat(i),s=Number.parseFloat(e);return[Fa(1,0,s,n,o),Fa(2,r,0,n,o),Fa(3,0,-s,n,o)]},cdi=t=>{const e=t.string?.match(/^potentiometer_(\d+)/),n=e?Number.parseInt(e[1],10):3,o=adi.parse({...t,num_pins:n});let i=[];o.num_pins===3&&(i=Adi(o));const r=Number.parseFloat(o.ca)/2+.15,s=Number.parseFloat(o.w),a=Number.parseFloat(o.od)/2+.35,A={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:0,y:r-1.75},{x:0,y:r},{x:s,y:r},{x:s,y:a}],stroke_width:.1,pcb_silkscreen_path_id:""},c={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:s,y:-a},{x:s,y:-r},{x:0,y:-r},{x:0,y:-r+1.75}],stroke_width:.1,pcb_silkscreen_path_id:""},l=Number.parseFloat(o.w)/2,g=nr(l,r+1,.5),u=Number.parseFloat(o.od)/2,h=Number.parseFloat(o.h),d=Number.parseFloat(o.ca)/2,m=-(u+.25),p=h+u+.25,_=d+.25,f={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:(m+p)/2,y:0},width:p-m,height:2*_,layer:"top"};return{circuitJson:[...i,A,c,g,f],parameters:o}},ldi=qi.extend({fn:Z(),p:he.optional().default("7.5mm"),id:he.optional().default("1mm"),od:he.optional().default("2mm"),d:he.optional().default("10.5mm")}),gdi=(t,e,n,o,i)=>{const r=[],s=[];for(let a=0;a<=50;a++){const A=a/50*Math.PI,c=t+Math.cos(A)*n,l=e+Math.sin(A)*n;c<t-o&&l>=e-i/2&&l<=e+i/2||r.push({x:c,y:l})}for(let a=0;a<=50;a++){const A=Math.PI+a/50*Math.PI,c=t+Math.cos(A)*n,l=e+Math.sin(A)*n;c<t-o&&l>=e-i/2&&l<=e+i/2||s.push({x:c,y:l})}return{topArc:r,bottomArc:s}},udi=t=>{const e=ldi.parse(t),{p:n,id:o,od:i,d:r}=e,s=[xx({pn:1,x:-n/2,y:0,holeDiameter:o,rectPadWidth:i,rectPadHeight:i}),Fa(2,n/2,0,o,i)],{topArc:a,bottomArc:A}=gdi(0,0,r/2+.1,i/2,i),c={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:a,stroke_width:.1,pcb_silkscreen_path_id:""},l={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:A,stroke_width:.1,pcb_silkscreen_path_id:""},g={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:0,y:r/2+.1},{x:0,y:-(r/2+.1)}],stroke_width:.1,pcb_silkscreen_path_id:""},u=-(r/2+.5),h=i/2+1.5,d=.5,m={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:u-d,y:h},{x:u+d,y:h}],stroke_width:.1,pcb_silkscreen_path_id:""},p={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:u,y:h-d},{x:u,y:h+d}],stroke_width:.1,pcb_silkscreen_path_id:""},_=nr(0,r/2+1,.5),f=r/2,I=n/2+i/2,y=Math.max(f,I)+.25,x={type:"pcb_courtyard_circle",pcb_courtyard_circle_id:"",pcb_component_id:"",center:{x:0,y:0},radius:y,layer:"top"};return{circuitJson:[...s,c,l,g,m,p,_,x],parameters:e}},ddi=qi.extend({fn:Z(),num_pins:Xe(2).default(2),w:Z().default("6.5mm"),h:Z().default("3mm"),pl:Z().default("1.75mm"),pw:Z().default("2.40mm"),p:Z().default("4.75mm")}),hdi=t=>{const e=ddi.parse(t),n=nr(0,he.parse(e.h)-.5,.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:he.parse(e.p)/2,y:he.parse(e.h)/2},{x:-he.parse(e.w)/2-.3,y:he.parse(e.h)/2},{x:-he.parse(e.w)/2-.3,y:-he.parse(e.h)/2},{x:he.parse(e.p)/2,y:-he.parse(e.h)/2}],stroke_width:.1,pcb_silkscreen_path_id:""},s={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:0,y:0},width:7,height:3.5,layer:"top"};return{circuitJson:pdi(e).concat(o,n,s),parameters:e}},mdi=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},pdi=t=>{const e=[],n=he.parse(t.p),o=he.parse(t.pl),i=he.parse(t.pw),r=.125;for(let s=1;s<=t.num_pins;s++){const{x:a,y:A}=mdi({pn:s,p:n});e.push(yi(s,a,A,o,i,r))}return e},_di=[{x:-1.45,y:.98},{x:-.73,y:.98},{x:-.73,y:1.1},{x:.73,y:1.1},{x:.73,y:.33},{x:1.45,y:.33},{x:1.45,y:-.33},{x:.73,y:-.33},{x:.73,y:-1.1},{x:-.73,y:-1.1},{x:-.73,y:-.98},{x:-1.45,y:-.98},{x:-1.45,y:-.32},{x:-.73,y:-.32},{x:-.73,y:.32},{x:-1.45,y:.32}],fdi=qi.extend({fn:Z(),num_pins:ft().default(3),w:Z().default("2.45mm"),h:Z().default("2.40mm"),pl:Z().default("0.92mm"),pw:Z().default("0.45mm"),p:Z().default("0.891mm"),string:Z().optional()}),Idi=t=>{const e=t.string?.match(/^sot323_(\d+)/),n=e?Number.parseInt(e[1],3):3,o=fdi.parse({...t,num_pins:n});if(o.num_pins===3)return{circuitJson:ydi(o),parameters:o};throw new Error("Invalid number of pins")},Cdi=t=>{const{pn:e,p:n}=t;return e===1?{x:-n,y:.65}:e===2?{x:-n,y:-.65}:{x:n,y:0}},ydi=t=>{const e=[];for(let A=0;A<t.num_pins;A++){const{x:c,y:l}=Cdi({num_pins:t.num_pins,pn:A+1,w:Number.parseFloat(t.w),h:Number.parseFloat(t.h),pl:Number.parseFloat(t.pl),p:Number.parseFloat(t.p)});e.push(yi(A+1,c,l,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}const n=nr(0,Number.parseInt(t.h)/2+1,.3),o=Number.parseFloat(t.w)/2-Number.parseFloat(t.pl),i=Number.parseFloat(t.h)/2,r={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-o,y:i+.3},{x:o,y:i+.3},{x:o,y:i/2}],type:"pcb_silkscreen_path",stroke_width:.1},s={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_2",route:[{x:-o,y:-i-.3},{x:o,y:-i-.3},{x:o,y:-i/2}],type:"pcb_silkscreen_path",stroke_width:.1},a={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",outline:_di,layer:"top"};return[...e,r,s,n,a]},xdi=qi.extend({fn:Z(),circle:je().optional(),rect:je().optional(),square:je().optional(),pill:je().optional(),d:he.optional(),pd:he.optional(),diameter:he.optional(),r:he.optional(),pr:he.optional(),radius:he.optional(),w:he.optional(),pw:he.optional(),width:he.optional(),h:he.optional(),ph:he.optional(),height:he.optional(),s:he.optional(),size:he.optional(),string:Z().optional()}).transform(t=>{let e="rect";t.circle&&(e="circle"),t.square&&(e="square"),t.rect&&(e="rect"),t.pill&&(e="pill");let n,o,i;return e==="circle"?t.r!==void 0?n=Ja(t.r):t.pr!==void 0?n=Ja(t.pr):t.radius!==void 0?n=Ja(t.radius):t.d!==void 0?n=Ja(t.d)/2:t.pd!==void 0?n=Ja(t.pd)/2:t.diameter!==void 0?n=Ja(t.diameter)/2:n=Ja("1mm")/2:(t.w!==void 0?o=Ja(t.w):t.pw!==void 0?o=Ja(t.pw):t.width!==void 0?o=Ja(t.width):t.s!==void 0?o=Ja(t.s):t.size!==void 0?o=Ja(t.size):o=Ja("1mm"),t.h!==void 0?i=Ja(t.h):t.ph!==void 0?i=Ja(t.ph):t.height!==void 0?i=Ja(t.height):e==="square"||e==="rect"?i=o:i=Ja("1mm")),{fn:t.fn,shape:e,radius:n,width:o,height:i}}),Edi=t=>{const e=xdi.parse(t),{shape:n,radius:o,width:i,height:r}=e;let s,a;return n==="circle"?(s=ltn(1,{x:0,y:0,radius:o}),a=o+.5):n==="pill"?(s=dde(1,0,0,i,r),a=Math.max(i,r)/2+.5):(s=yi(1,0,0,i,r),a=r/2+.5),{circuitJson:[s,nr(0,a,.2)],parameters:e}},Bdi=qi.extend({fn:Z(),d:he.optional(),hd:he.optional(),r:he.optional(),hr:he.optional(),pd:he.optional(),pr:he.optional(),squarepad:je().optional().default(!1)}).transform(t=>{let e;t.d!==void 0?e=Ja(t.d):t.hd!==void 0?e=Ja(t.hd):t.r!==void 0?e=Ja(t.r)*2:t.hr!==void 0?e=Ja(t.hr)*2:e=Ja("1mm");let n;return t.pd!==void 0?n=Ja(t.pd):t.pr!==void 0?n=Ja(t.pr)*2:n=e*(1.5/1),{fn:t.fn,d:e,pd:n,squarepad:t.squarepad??!1}}),Sdi=t=>{const e=Bdi.parse(t),{d:n,pd:o,squarepad:i}=e;return{circuitJson:[i?xx({pn:1,x:0,y:0,holeDiameter:n,rectPadWidth:o,rectPadHeight:o}):Fa(1,0,0,n,o),nr(0,o/2+.5,.2)],parameters:e}},bdi=qi.extend({fn:Z(),num_pins:Xe(6).default(6),h:Z().default("1.3mm"),pl:Z().default("1.325mm"),pw:Z().default("0.6mm"),p:Z().default("0.95mm")}),Qdi=t=>{const e=bdi.parse(t);return{circuitJson:vdi(e),parameters:e}},Ntn=t=>{const{p:e,h:n,pn:o}=t;if(o===1)return{x:-n/2-.4875,y:e};if(o===2)return{x:-n/2-.4875,y:0};if(o===3)return{x:-n/2-.4875,y:-e};if(o===4)return{x:n/2+.4875,y:-e};if(o===5)return{x:n/2+.4875,y:0};if(o===6)return{x:n/2+.4875,y:e};throw new Error("Invalid pin number")},vdi=t=>{const e=[];for(let E=1;E<=t.num_pins;E++){const{x:B,y:b}=Ntn({h:Number.parseFloat(t.h),p:Number.parseFloat(t.p),pn:E});e.push(yi(E,B,b,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}const n=t.num_pins/2*Number.parseFloat(t.p),o=Number.parseFloat(t.h),i={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_1",route:[{x:-n/3,y:o/2+Number.parseFloat(t.p)/1.3},{x:n/3,y:o/2+Number.parseFloat(t.p)/1.3}],type:"pcb_silkscreen_path",stroke_width:.05},r={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_2",route:[{x:-n/3,y:-o/2-Number.parseFloat(t.p)/1.3},{x:n/3,y:-o/2-Number.parseFloat(t.p)/1.3}],type:"pcb_silkscreen_path",stroke_width:.05},s=nr(0,o+.3,.3),a=Ntn({h:Number.parseFloat(t.h),p:Number.parseFloat(t.p),pn:1});a.x=a.x-Number.parseFloat(t.pw)*1.5;const A=.7,c=.3,l={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"pin1_indicator",route:[{x:a.x+A/2-.2,y:a.y},{x:a.x-A/2,y:a.y+c/2},{x:a.x-A/2,y:a.y-c/2},{x:a.x+A/2-.2,y:a.y}],stroke_width:.05},g=Number.parseFloat(t.h),u=Number.parseFloat(t.p),h=Number.parseFloat(t.pl),d=Number.parseFloat(t.pw),m=g/2+.4875,p=u*2+d,_=m+h/2,f=g/2+.4,I=_+.25,C=p/2+.25,y=C+.2,x={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",layer:"top",outline:ky([{minX:-I,maxX:I,minY:-C,maxY:C},{minX:-f,maxX:f,minY:-y,maxY:y}])};return[...e,s,i,r,l,x]},Pdi=[{x:-1.703,y:.98},{x:-.983,y:.98},{x:-.983,y:1.1},{x:.477,y:1.1},{x:.477,y:.98},{x:1.197,y:.98},{x:1.197,y:-.98},{x:.477,y:-.98},{x:.477,y:-1.1},{x:-.983,y:-1.1},{x:-.983,y:-.98},{x:-1.703,y:-.98}],wdi=qi.extend({fn:Z(),num_pins:ft().default(4),w:Z().default("3.2mm"),h:Z().default("2.6mm"),pl:Z().default("1.05mm"),pw:Z().default("0.45mm"),p:Z().default("0.55mm"),string:Z().optional()}),Mdi=t=>{const e=t.string?.match(/^sot343_(\d+)/),n=e?Number.parseInt(e[1],4):4,o=wdi.parse({...t,num_pins:n});if(o.num_pins===4)return{circuitJson:Ndi(o),parameters:o};throw new Error("Invalid number of pins")},Ddi=t=>{const{pn:e,p:n}=t;return e===1?{x:-n*1.92,y:-.65}:e===2?{x:-n*1.92,y:.65}:e===3?{x:n,y:.65}:e===4?{x:n,y:-.65}:{x:0,y:0}},Ndi=t=>{const e=[],n=Number.parseFloat(t.w),o=Number.parseFloat(t.h),i=Number.parseFloat(t.pl),r=Number.parseFloat(t.pw),s=Number.parseFloat(t.p);let a=1/0,A=-1/0,c=1/0,l=-1/0;for(let C=0;C<t.num_pins;C++){const{x:y,y:x}=Ddi({num_pins:t.num_pins,pn:C+1,p:s});e.push(yi(C+1,y,x,i,r)),y<a&&(a=y),y>A&&(A=y),x<c&&(c=x),x>l&&(l=x)}const g=(a+A)/2,u=l-c,h=o*.3,d=u/2+h;let m=n*.8;o<=2.6&&(m/=2);const p=nr(g,d+.5,.3),_={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_top",route:[{x:g-m/2,y:d},{x:g+m/2,y:d}],type:"pcb_silkscreen_path",stroke_width:.1},f={layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"silkscreen_path_bottom",route:[{x:g-m/2,y:-d},{x:g+m/2,y:-d}],type:"pcb_silkscreen_path",stroke_width:.1},I={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",outline:Pdi,layer:"top"};return[...e,_,f,p,I]},Rdi=qi.extend({fn:Z()}),Tdi=t=>{const e=Rdi.parse(t),n=[],o=.5-.15,i=1.5,s=.5/2,a=75,A=-37/2;for(let E=0;E<a;E++){const B=E+1;if(B>=24&&B<=31)continue;const b=A-E*s,Q=B%2===0,w=i+(Q?.25:0),k=.5-w/2,R=yi(B,k,b,w,o);R.layer=Q?"bottom":"top",n.push(R)}const c=46*.0254,l=137*.0254,g=261*.0254,u={type:"pcb_cutout",pcb_cutout_id:"",shape:"rect",center:{x:-l/2+i/2,y:A-g},width:l,height:c},h={x:-.5,y:A},d={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"pin_marker_1",route:[{x:h.x-.4,y:h.y},{x:h.x-.7,y:h.y+.3},{x:h.x-.7,y:h.y-.3},{x:h.x-.4,y:h.y}],stroke_width:.05,pcb_silkscreen_path_id:"pin_marker_1"};let m=1/0,p=-1/0,_=1/0,f=-1/0;const I=(E,B,b=0,Q=0)=>{m=Math.min(m,E-b/2),p=Math.max(p,E+b/2),_=Math.min(_,B-Q/2),f=Math.max(f,B+Q/2)};for(const E of n){const B=E;I(B.x,B.y,B.width,B.height)}I(u.center.x,u.center.y,u.width,u.height);for(const E of d.route)I(E.x,E.y);const C=(m+p)/2,y=(_+f)/2,x=E=>{typeof E.x=="number"&&(E.x-=C),typeof E.y=="number"&&(E.y-=y),E.center&&(E.center.x-=C,E.center.y-=y),Array.isArray(E.route)&&(E.route=E.route.map(B=>({x:B.x-C,y:B.y-y})))};for(const E of n)x(E);return x(u),x(d),{circuitJson:[...n,u,d],parameters:e}},kdi=qi.extend({fn:Z(),numPins:ft().optional().default(0),rows:Eo([Z(),ft()]).transform(t=>Number(t)).optional().default(1).describe("number of rows"),p:he.default("2.54mm").describe("pitch"),id:he.default("1.0mm").describe("inner diameter"),od:he.default("1.5mm").describe("outer diameter"),male:je().optional().describe("the module uses male headers"),nopin:je().optional().default(!1).describe("omit pins rendering"),female:je().optional().describe("the module uses female headers"),smd:je().optional().describe("surface mount device"),pinlabeltextalignleft:je().optional().default(!1),pinlabeltextaligncenter:je().optional().default(!1),pinlabeltextalignright:je().optional().default(!1),pinlabelverticallyinverted:je().optional().default(!1),pinlabelorthogonal:je().optional().default(!1),nopinlabels:je().optional().default(!1).describe("omit silkscreen pin labels"),doublesidedpinlabel:je().optional().default(!1).describe("add silkscreen pins in top and bottom layers"),bottomsidepinlabel:je().optional().default(!1).describe("place the silkscreen reference text on the bottom layer instead of top"),pinRowSide:zn(["left","right","top","bottom"]).optional().default("left"),pinrowleft:je().optional().default(!1),pinrowright:je().optional().default(!1),pinrowtop:je().optional().default(!1),pinrowbottom:je().optional().default(!1),pinrowleftpins:Eo([Z(),ft()]).transform(t=>Number(t)).optional(),pinrowrightpins:Eo([Z(),ft()]).transform(t=>Number(t)).optional(),pinrowtoppins:Eo([Z(),ft()]).transform(t=>Number(t)).optional(),pinrowbottompins:Eo([Z(),ft()]).transform(t=>Number(t)).optional(),width:he.optional(),height:he.optional(),pinRowHoleEdgeToEdgeDist:he.default("2mm"),holes:Eo([Z(),dn(Z())]).optional().transform(t=>!t||Array.isArray(t)?t:t.startsWith("(")&&t.endsWith(")")?t.slice(1,-1).split(",").map(e=>e.trim()):[t]),holeXDist:he.optional(),holeYDist:he.optional(),holeInset:he.default("1mm"),pinrow:Eo([Z(),ft()]).optional(),usbposition:zn(["left","right","top","bottom"]).optional().default("left"),usbleft:je().optional().default(!1),usbtop:je().optional().default(!1),usbright:je().optional().default(!1),usbbottom:je().optional().default(!1),usbtype:zn(["micro","c"]).optional(),usbmicro:je().optional().default(!1),usbc:je().optional().default(!1),screen:je().optional().default(!1).describe("add silkscreen outline for screen/display area"),screenwidth:he.optional(),screenheight:he.optional(),screencenteroffsetx:he.optional(),screencenteroffsety:he.optional()}).transform(t=>{const e=Itn(t);let n=t.pinRowSide;t.pinrowleft&&(n="left"),t.pinrowright&&(n="right"),t.pinrowtop&&(n="top"),t.pinrowbottom&&(n="bottom");let o=t.usbposition;t.usbleft&&(o="left"),t.usbtop&&(o="top"),t.usbright&&(o="right"),t.usbbottom&&(o="bottom");let i=t.usbtype;t.usbmicro&&(i="micro"),t.usbc&&(i="c"),t.pinrow!==void 0&&(t.numPins=Number(t.pinrow));const r={left:t.pinrowleftpins,right:t.pinrowrightpins,top:t.pinrowtoppins,bottom:t.pinrowbottompins},s=Object.values(r).some(C=>C!==void 0&&C>0),a=(r.left??0)>0&&(r.right??0)>0,A=(r.top??0)>0&&(r.bottom??0)>0;s&&((r.left??0)>0?n="left":(r.right??0)>0?n="right":(r.top??0)>0?n="top":(r.bottom??0)>0&&(n="bottom"),t.numPins=(r.left??0)+(r.right??0)+(r.top??0)+(r.bottom??0));const c=Math.ceil(t.numPins/t.rows),l=Math.max(r.left??0,r.right??0),g=Math.max(r.top??0,r.bottom??0);let u,h;if(s){const C=a?t.p:0,y=A?t.p:0;u=(g>0?(g-1)*t.p:0)+2*t.pinRowHoleEdgeToEdgeDist+C,h=(l>0?(l-1)*t.p:0)+2*t.pinRowHoleEdgeToEdgeDist+y}else n==="left"||n==="right"?(u=(t.rows-1)*t.p+2*t.pinRowHoleEdgeToEdgeDist,h=(c-1)*t.p+2*t.pinRowHoleEdgeToEdgeDist):(h=(t.rows-1)*t.p+2*t.pinRowHoleEdgeToEdgeDist,u=(c-1)*t.p+2*t.pinRowHoleEdgeToEdgeDist);t.numPins===0&&(u=10,h=10);const d=t.width??u,m=t.height??h,p=t.screenwidth??d*.95,_=t.screenheight??m*.95,f=t.screencenteroffsetx??0,I=t.screencenteroffsety??0;return{...t,pinlabelAnchorSide:e,pinRowSide:n,usbposition:o,usbtype:i,male:t.male??!t.female,female:t.female??!1,width:d,height:m,screenwidth:p,screenheight:_,screencenteroffsetx:f,screencenteroffsety:I,pinrowleftpins:r.left,pinrowrightpins:r.right,pinrowtoppins:r.top,pinrowbottompins:r.bottom}}).superRefine((t,e)=>{t.male&&t.female&&e.addIssue({code:Ao.custom,message:"'male' and 'female' cannot both be true; it should be male or female.",path:["male","female"]})}),Fdi=t=>{const e=kdi.parse(t),{p:n,id:o,od:i,rows:r,numPins:s,pinlabelAnchorSide:a,pinlabelverticallyinverted:A,pinlabelorthogonal:c,pinlabeltextalignleft:l,pinlabeltextalignright:g,nopinlabels:u,doublesidedpinlabel:h,bottomsidepinlabel:d,pinRowSide:m,width:p,height:_,pinRowHoleEdgeToEdgeDist:f,holes:I,holeXDist:C,holeYDist:y,holeInset:x,pinrowleftpins:E,pinrowrightpins:B,pinrowtoppins:b,pinrowbottompins:Q,usbposition:w,usbtype:D,screen:k,screenwidth:R,screenheight:H,screencenteroffsetx:G,screencenteroffsety:K}=e;let Y="center";l?Y="left":g&&(Y="right");const X=[],te={left:E,right:B,top:b,bottom:Q},j=Object.values(te).some(oe=>oe!==void 0&&oe>0),J=(oe,ne,le,ge)=>{if(e.smd?X.push(yi(oe,ne,le,e.od,e.od)):oe===1?X.push(xx({pn:oe,x:ne,y:le,holeDiameter:o,rectPadWidth:i,rectPadHeight:i})):X.push(Fa(oe,ne,le,o,i)),!u){const _e=ne+(ge==="left"?-i:ge==="right"?i:0),ce=le+(ge==="top"?i:ge==="bottom"?-i:0);d||X.push(CR({fs:i/5,pn:oe,anchor_x:_e,anchor_y:ce,textalign:Y,orthogonal:c,verticallyinverted:A,layer:"top"})),(h||d)&&X.push(CR({fs:i/5,pn:oe,anchor_x:_e,anchor_y:ce,textalign:Y,orthogonal:c,verticallyinverted:A,layer:"bottom"}))}};if(j){const oe=n;let ne=1;const le=te.left??0,ge=te.right??0,_e=te.top??0,ce=te.bottom??0,Ie=(de,Ce)=>{if(!(Ce<=0))if(de==="left"||de==="right"){const Pe=de==="left"?-p/2+f:p/2-f,Qe=(Ce-1)/2*oe;for(let pe=0;pe<Ce;pe++)J(ne,Pe,Qe-pe*oe,de),ne++}else{const Pe=de==="top"?_/2-f:-_/2+f,Qe=-((Ce-1)/2)*oe;for(let pe=0;pe<Ce;pe++)J(ne,Qe+pe*oe,Pe,de),ne++}};Ie("left",le),Ie("right",ge),Ie("top",_e),Ie("bottom",ce)}else{const oe=n;let ne=0,le=0,ge=0,_e=0,ce=0,Ie=0;const de=Math.ceil(s/r);m==="left"||m==="right"?(ne=m==="left"?-p/2+f:p/2-f,le=(de-1)/2*oe,ge=0,_e=-oe,ce=m==="left"?oe:-oe,Ie=0):(ne=-(de-1)/2*oe,le=m==="top"?_/2-f:-_/2+f,ge=oe,_e=0,ce=0,Ie=m==="top"?-oe:oe);let Ce=1;for(let Pe=0;Pe<r&&Ce<=s;Pe++)for(let Qe=0;Qe<de&&Ce<=s;Qe++){const pe=ne+Qe*ge+Pe*ce,ve=le+Qe*_e+Pe*Ie;if(e.smd?X.push(yi(Ce,pe,ve,e.od,e.od)):Ce===1?X.push(xx({pn:Ce,x:pe,y:ve,holeDiameter:o,rectPadWidth:i,rectPadHeight:i})):X.push(Fa(Ce,pe,ve,o,i)),!u){const Me=pe+(m==="left"?-i:m==="right"?i:0),we=ve+(m==="top"?i:m==="bottom"?-i:0);d||X.push(CR({fs:i/5,pn:Ce,anchor_x:Me,anchor_y:we,textalign:Y,orthogonal:c,verticallyinverted:A,layer:"top"})),(h||d)&&X.push(CR({fs:i/5,pn:Ce,anchor_x:Me,anchor_y:we,textalign:Y,orthogonal:c,verticallyinverted:A,layer:"bottom"}))}Ce++}}if(I)for(const oe of I){let ne=0,le=0;oe==="topleft"?(ne=-p/2+x,le=_/2-x):oe==="topright"?(ne=p/2-x,le=_/2-x):oe==="bottomleft"?(ne=-p/2+x,le=-_/2+x):oe==="bottomright"?(ne=p/2-x,le=-_/2+x):oe==="center"&&(ne=0,le=0),C!==void 0&&(ne+=C),y!==void 0&&(le+=y),X.push(Fa(s+I.indexOf(oe)+1,ne,le,o,i))}if(!e.nosilkscreen){const oe=[{x:-p/2,y:-_/2},{x:p/2,y:-_/2},{x:p/2,y:_/2},{x:-p/2,y:_/2},{x:-p/2,y:-_/2}];X.push(yR(oe,{stroke_width:.1,layer:"top"}))}const ie=nr(0,_/2+1,.5);if(X.push(ie),w&&D){let oe,ne;if(D==="c")oe=8,ne=3;else if(D==="micro")oe=6,ne=2;else return{circuitJson:X,parameters:e};let le;if(w==="left")le=[{x:-p/2,y:-oe/2},{x:-p/2+ne,y:-oe/2},{x:-p/2+ne,y:oe/2},{x:-p/2,y:oe/2},{x:-p/2,y:-oe/2}];else if(w==="right")le=[{x:p/2-ne,y:-oe/2},{x:p/2,y:-oe/2},{x:p/2,y:oe/2},{x:p/2-ne,y:oe/2},{x:p/2-ne,y:-oe/2}];else if(w==="top")le=[{x:-oe/2,y:_/2-ne},{x:oe/2,y:_/2-ne},{x:oe/2,y:_/2},{x:-oe/2,y:_/2},{x:-oe/2,y:_/2-ne}];else if(w==="bottom")le=[{x:-oe/2,y:-_/2},{x:oe/2,y:-_/2},{x:oe/2,y:-_/2+ne},{x:-oe/2,y:-_/2+ne},{x:-oe/2,y:-_/2}];else return{circuitJson:X,parameters:e};X.push(yR(le,{stroke_width:.1,layer:"top"}))}if(k){const oe=R/2,ne=H/2,le=G,ge=K,_e=[{x:-oe+le,y:-ne+ge},{x:oe+le,y:-ne+ge},{x:oe+le,y:ne+ge},{x:-oe+le,y:ne+ge},{x:-oe+le,y:-ne+ge}];X.push(yR(_e,{stroke_width:.05,layer:"top"}))}return{circuitJson:X,parameters:e}},Ldi=[{x:-1.45,y:2.75},{x:-1.45,y:-1.85},{x:4.05,y:-1.85},{x:4.05,y:2.75}],Hdi=[{x:-1.55,y:2.75},{x:-1.55,y:-1.85},{x:3.95,y:-1.85},{x:3.95,y:2.75}],Odi=qi.extend({fn:Z(),num_pins:ft().default(3),inline:je().default(!1),p:Z().default("1.27mm"),id:Z().default("0.75mm"),od:Z().default("1.3mm"),w:Z().default("4.8mm"),h:Z().default("4.0mm")}),Gdi=t=>{const e=Odi.parse(t),n=Number.parseFloat(e.p),o=Number.parseFloat(e.w),i=Number.parseFloat(e.h),r=e.inline?1.05:Number.parseFloat(e.od),s=e.inline?1.5:r,a=[xx({pn:1,x:0,y:0,holeDiameter:e.id,rectPadWidth:r,rectPadHeight:s}),e.inline?vP(2,n,0,Number.parseFloat(e.id),r,s):Fa(2,n,n,e.id,r),e.inline?vP(3,n*2,0,Number.parseFloat(e.id),r,s):Fa(3,n*2,0,e.id,r)],A=o/2,c=e.inline?n-.09:n,l=.2,g=l+A-i,u=Array.from({length:32},(p,_)=>{const f=Math.PI*_/31;return{x:c+A*Math.cos(f),y:l+A*Math.sin(f)}}),h={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",pcb_silkscreen_path_id:"",stroke_width:.12,route:[...u,{x:c-A,y:g},{x:c+A,y:g},u[0]]},d=nr(c,l+A+1,.5),m={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",outline:e.inline?Hdi:Ldi,layer:"top"};return{circuitJson:[...a,h,d,m],parameters:e}},Ydi=(t,e)=>{const n=t.filter(o=>o.type==="pcb_silkscreen_text");if(n.length===0)return t;for(const o of n)e.norefdes&&(o.text="");return t},Udi=(t,e)=>e.nosilkscreen?t.filter(n=>n.type!=="pcb_silkscreen_path"&&n.type!=="pcb_silkscreen_text"):t,Kdi=(t,e)=>{if(!e)return t;const n=t.filter(l=>l.type==="pcb_smtpad"||l.type==="pcb_plated_hole");if(n.length===0)return t;let o=Number.POSITIVE_INFINITY,i=Number.NEGATIVE_INFINITY,r=Number.POSITIVE_INFINITY,s=Number.NEGATIVE_INFINITY;const a=(l,g,u=0,h=0)=>{const d=l-u/2,m=l+u/2,p=g-h/2,_=g+h/2;o=Math.min(o,d),i=Math.max(i,m),r=Math.min(r,p),s=Math.max(s,_)};for(const l of n)if(l.type==="pcb_smtpad"){const g=l.shape==="circle"?l.radius*2:l.width,u=l.shape==="circle"?l.radius*2:l.height;a(l.x,l.y,g,u)}else if(l.type==="pcb_plated_hole"){const g=l.outer_diameter??l.hole_diameter;a(l.x,l.y,g,g)}let A=0,c=0;switch(e){case"center":A=(o+i)/2,c=(r+s)/2;break;case"bottomleft":A=o,c=r;break;case"bottomcenter":case"centerbottom":A=(o+i)/2,c=r;break;case"topcenter":case"centertop":A=(o+i)/2,c=s;break;case"leftcenter":case"centerleft":A=o,c=(r+s)/2;break;case"rightcenter":case"centerright":A=i,c=(r+s)/2;break;case"pin1":{const l=n.find(g=>g.port_hints?.[0]==="1")||n[0];A=l.x,c=l.y;break}}if(A===0&&c===0)return t;for(const l of t){if(typeof l.x=="number"&&(l.x-=A),typeof l.y=="number"&&(l.y-=c),l.center&&typeof l.center.x=="number"&&(l.center.x-=A,l.center.y-=c),l.type==="pcb_silkscreen_path")for(const g of l.route)g.x-=A,g.y-=c;l.type==="pcb_silkscreen_text"&&l.anchor_position&&(l.anchor_position.x-=A,l.anchor_position.y-=c)}return t};function Vdi(t){return t!=null}var zdi=t=>t.trim().replace(/^pinheader(?=[\d_]|$)/i,"pinrow").replace(/^sot23-(\d+)(?=_|$)/i,"sot23_$1").replace(/^sot-223-(\d+)(?=_|$)/i,"sot223_$1").replace(/^to-220f-(\d+)(?=_|$)/i,"to220f_$1").replace(/^jst_(ph|sh|zh)_(\d+)(?=_|$)/i,"jst$2_$1"),Jdi=t=>{let e=pde();const n=zdi(t),i=n.replace(/^((?:\d{4}|\d{5}))(?=$|_|x)/,"res$1").replace(/^zh(\d+)(?:$|_)/,"jst$1_zh").split(/_(?!metric)/).map(r=>{const s=r.match(/([a-zA-Z]+)([\(\d\.\+\?].*)?/);if(!s)return null;const[,a,A]=s;if(!a)return null;const c=a.toLowerCase();return A?.includes("?")?null:{fn:c,v:A}}).filter(Vdi);for(const{fn:r,v:s}of i)e=e[r](s);return e.setString(n),e},Wdi=()=>Object.keys(DS),pde=()=>{const t=new Proxy({},{get:(e,n)=>{if(n==="soup"||n==="circuitJson"){if("fn"in e&&DS[e.fn])return()=>{const{circuitJson:o}=DS[e.fn](e),i=Udi(o,e),r=Ydi(i,e);return Kdi(r,e.origin)};if(!DS[e.fn])throw new Error(`Invalid footprint function, got "${e.fn}"${e.string?`, from string "${e.string}"`:""}`);return()=>{throw new Error(`No function found for footprinter, make sure to specify .dip, .lr, .p, etc. Got "${n}"`)}}if(n==="json"){if(!DS[e.fn])throw new Error(`Invalid footprint function, got "${e.fn}"${e.string?`, from string "${e.string}"`:""}`);return()=>DS[e.fn](e).parameters}return n==="getFootprintNames"?()=>Object.keys(DS):n==="params"?()=>e:n==="setString"?o=>(e.string=o,t):o=>(Object.keys(e).length===0?`${n}${o}`in DS?(e[`${n}${o}`]=!0,e.fn=`${n}${o}`):(e[n]=!0,e.fn=n,n==="res"||n==="cap"||n==="led"||n==="diode"?o&&(typeof o=="string"&&o.includes("_metric")?e.metric=o.split("_metric")[0]:e.imperial=o):e.num_pins=Number.isNaN(Number.parseFloat(o))?void 0:Number.parseFloat(o)):!o&&["w","h","p"].includes(n)||(e[n]=o??!0),t)}});return t};pde.string=Jdi,pde.getFootprintNames=Wdi;var X1=pde,Rtn={in:25.4,inch:25.4,mil:.0254,mm:1,m:1e3,cm:10,ft:304.8,feet:304.8},jdi=t=>{let e=typeof t=="number"?"mm":t.replace(/^[^a-zA-Z]+/g,"").toLowerCase();e||(e="mm");const n=typeof t=="number"?t:Number.parseFloat(t.split(e)[0]);if(e in Rtn)return n*Rtn[e];throw new Error(`Unsupported unit: ${e}`)},t7=Eo([ft(),Z()]).transform((t,e)=>{try{const n=jdi(t);if(!Number.isFinite(n))throw new Error("Length is not finite");return n}catch{return e.addIssue({code:"custom",message:`Invalid model length: ${String(t)}`}),e2n}}),Yf=t7.refine(t=>t>0,"Length must be greater than zero"),n7=t7.refine(t=>t>=0,"Length cannot be negative"),Xdi=zn(["sitsFlat","sitsFlatBelowBoard","foldedToFaceAboveBoard","foldedToFaceBelowBoard","foldedToRightAngleAboveBoard","foldedToRightAngleBelowBoard"]),pUe=ft().finite().positive(),qdi=Z().refine(t=>{const e=t.split(":");if(e.length!==2)return!1;const n=Number(e[0]),o=Number(e[1]);return Number.isFinite(n)&&Number.isFinite(o)&&n>0&&o>0},'Aspect ratio must look like "16:9"').transform(t=>t),Ttn=Eo([pUe,qdi,GT([pUe,pUe])]),ktn=Pt({x:t7.optional(),y:t7.optional(),z:t7.optional()}).strict(),_Ue=Eo([ft().finite(),Z().min(1)]),Ftn=GT([_Ue,_Ue,_Ue]),$di=["sitsFlat","sitsFlatBelowBoard","foldedToFaceAboveBoard","foldedToFaceBelowBoard","foldsAboveBoard","foldsBelowBoard","foldedToRightAngleAboveBoard","foldedToRightAngleBelowBoard"],Ltn={width:Yf.optional(),height:Yf.optional(),diagonal:Yf.optional(),aspectRatio:Ttn.optional(),ratio:Ttn.optional(),defaultDiagonal:Yf.optional(),orientation:Xdi.optional(),sitsFlat:je().optional(),sitsFlatBelowBoard:je().optional(),foldedToFaceAboveBoard:je().optional(),foldedToFaceBelowBoard:je().optional(),foldsAboveBoard:je().optional(),foldsBelowBoard:je().optional(),foldedToRightAngleAboveBoard:je().optional(),foldedToRightAngleBelowBoard:je().optional(),screenThickness:Yf.optional(),bezelInset:n7.optional(),bezelDepth:Yf.optional(),activeAreaWidth:Yf.optional(),activeAreaHeight:Yf.optional(),screenColor:Z().min(1).optional(),bezelColor:Z().min(1).optional(),showScreen:je().optional(),flexCableLength:Yf.optional(),flexCableWidth:Yf.optional(),flexCableThickness:Yf.optional(),flexCableColor:Z().min(1).optional(),conductorCount:ft().int().positive().optional(),conductorPitch:Yf.optional(),conductorWidth:Yf.optional(),conductorThickness:Yf.optional(),conductorColor:Z().min(1).optional(),cableEdgeMargin:n7.optional(),exposedContactLength:n7.optional(),showConductors:je().optional(),showFlexCable:je().optional(),showStiffeners:je().optional(),stiffenerLength:n7.optional(),stiffenerThickness:Yf.optional(),stiffenerColor:Z().min(1).optional(),bendRadius:Yf.optional(),bendSegments:ft().int().min(2).optional(),rightAngleVerticalLead:n7.optional(),distanceAboveBoard:n7.optional(),distanceBelowBoard:n7.optional(),foldDistanceFromConnector:n7.optional(),foldOutset:Yf.optional(),foldSegments:ft().int().min(4).optional(),screenGap:n7.optional(),boardTopZ:t7.optional(),boardThickness:Yf.optional(),boardClearance:n7.optional(),cableStartX:t7.optional(),cableStartY:t7.optional(),cableStartZ:t7.optional(),cableLateralOffset:t7.optional(),screenOffset:ktn.optional(),screenRotation:Ftn.optional(),rotation:Ftn.optional(),offset:ktn.optional()},Htn=(t,e)=>{const n=$di.filter(o=>t[o]===!0);n.length>1&&e(n[1])};Pt(Ltn).strict().superRefine((t,e)=>{Htn(t,n=>{e.addIssue({code:"custom",message:"Only one FlexScreen orientation shortcut can be true",path:[n]})})});var Zdi=Pt({fn:Xe("flexscreen"),...Ltn}).strict().superRefine((t,e)=>{Htn(t,n=>{e.addIssue({code:"custom",message:"Only one FlexScreen orientation shortcut can be true",path:[n]})})}),Otn=t=>{const e=t.match(/^([a-zA-Z]+)([\(\d\.\+\-].*)?$/);if(e?.[1])return{fn:e[1].toLowerCase(),value:e[2]}},ehi=t=>{const e=t.trim();if(!e)throw new Error("Model string cannot be empty");const n=e.split("_"),o=n[0],i=Otn(o),r={},s=i?.fn??o.toLowerCase();if(r[s]=!0,r.fn=s,i?.value){const a=Number.parseFloat(i.value);Number.isFinite(a)&&(r.num_pins=a)}for(const a of n.slice(1)){if(!a)throw new Error("Model strings cannot contain empty tokens");const A=Otn(a);if(!A)throw new Error(`Invalid model string token "${a}"`);r[A.fn]=A.value??!0}return r.string=e,r},thi={sitsflat:"sitsFlat",sitsflatbelow:"sitsFlatBelowBoard",sitsflatbelowboard:"sitsFlatBelowBoard",foldsabove:"foldedToFaceAboveBoard",foldsaboveboard:"foldedToFaceAboveBoard",foldedtofaceaboveboard:"foldedToFaceAboveBoard",foldsbelow:"foldedToFaceBelowBoard",foldsbelowboard:"foldedToFaceBelowBoard",foldedtofacebelowboard:"foldedToFaceBelowBoard",rightangleabove:"foldedToRightAngleAboveBoard",rightangleaboveboard:"foldedToRightAngleAboveBoard",foldedtorightangleaboveboard:"foldedToRightAngleAboveBoard",rightanglebelow:"foldedToRightAngleBelowBoard",rightanglebelowboard:"foldedToRightAngleBelowBoard",foldedtorightanglebelowboard:"foldedToRightAngleBelowBoard"},nhi={width:["width","w"],height:["height","h"],diagonal:["diagonal","diag","d"],defaultDiagonal:["defaultdiagonal","defaultdiag"],screenThickness:["screenthickness"],bezelInset:["bezelinset"],bezelDepth:["bezeldepth"],activeAreaWidth:["activeareawidth","activew"],activeAreaHeight:["activeareaheight","activeh"],flexCableLength:["flexcablelength","flexlength","flex"],flexCableWidth:["flexcablewidth","flexwidth"],flexCableThickness:["flexcablethickness","flexthickness"],conductorPitch:["conductorpitch"],conductorWidth:["conductorwidth"],conductorThickness:["conductorthickness"],cableEdgeMargin:["cableedgemargin","edgemargin"],exposedContactLength:["exposedcontactlength","contactlength"],stiffenerLength:["stiffenerlength"],stiffenerThickness:["stiffenerthickness"],bendRadius:["bendradius"],rightAngleVerticalLead:["rightangleverticallead","verticallead"],distanceAboveBoard:["distanceaboveboard","distanceabove"],distanceBelowBoard:["distancebelowboard","distancebelow"],foldDistanceFromConnector:["folddistancefromconnector","folddistance","foldstart"],foldOutset:["foldoutset","outset"],screenGap:["screengap"],boardTopZ:["boardtopz"],boardThickness:["boardthickness"],boardClearance:["boardclearance"],cableStartX:["cablestartx"],cableStartY:["cablestarty"],cableStartZ:["cablestartz"],cableLateralOffset:["cablelateraloffset","lateraloffset"]},ohi=Object.fromEntries(Object.entries(nhi).flatMap(([t,e])=>e.map(n=>[n,t]))),ihi={conductorcount:"conductorCount",conductors:"conductorCount",bendsegments:"bendSegments",foldsegments:"foldSegments"},Gtn={showscreen:["showScreen",!0],hidescreen:["showScreen",!1],showflex:["showFlexCable",!0],hideflex:["showFlexCable",!1],showconductors:["showConductors",!0],hideconductors:["showConductors",!1],showstiffeners:["showStiffeners",!0],hidestiffeners:["showStiffeners",!1]},rhi={screencolor:"screenColor",bezelcolor:"bezelColor",flexcolor:"flexCableColor",conductorcolor:"conductorColor",stiffenercolor:"stiffenerColor"},shi=t=>{const e=String(t).toLowerCase().replace("x",":");if(e.includes(":")){const[o,i,r]=e.split(":"),s=Number(o),a=Number(i);if(r!==void 0||!Number.isFinite(s)||!Number.isFinite(a)||s<=0||a<=0)throw new Error(`Invalid FlexScreen aspect ratio "${String(t)}"`);return`${s}:${a}`}const n=Number(e);if(!Number.isFinite(n)||n<=0)throw new Error(`Invalid FlexScreen aspect ratio "${String(t)}"`);return n},ahi=(t,e)=>{if(typeof t!="string"||!/^\(.+\)$/.test(t))throw new Error(`FlexScreen token "${e}" requires a value in (...)`);return t.slice(1,-1)},Ytn=(t,e)=>{if(t!==!0)throw new Error(`FlexScreen token "${e}" does not accept a value`)},Ahi=t=>{if(t.fn!=="flexscreen")throw new Error(`Expected FlexScreen params, got "${t.fn}"`);const e={};let n,o;for(const[i,r]of Object.entries(t)){if(i==="fn"||i==="string"||i==="flexscreen")continue;const s=thi[i];if(s){if(Ytn(r,i),n&&n!==s)throw new Error("A FlexScreen model string can only set one orientation");n=s,e.orientation=s;continue}if(i in Gtn){Ytn(r,i);const[l,g]=Gtn[i];e[l]=g;continue}const a=rhi[i];if(a){e[a]=ahi(r,i);continue}if(i==="ratio"){e.aspectRatio=shi(r);continue}const A=ohi[i];if(A){e[A]=r;continue}if(i==="distance"){o=r;continue}const c=ihi[i];if(c){const l=Number(r);if(!Number.isInteger(l)||l<1)throw new Error(`Invalid positive integer in FlexScreen token "${i}${String(r)}"`);e[c]=l;continue}throw new Error(`Unknown FlexScreen model token "${i}${String(r)}"`)}if(o!==void 0)if(n==="foldedToFaceAboveBoard")e.distanceAboveBoard=o;else if(n==="foldedToFaceBelowBoard")e.distanceBelowBoard=o;else throw new Error('The "distance" token requires foldsabove or foldsbelow; use distanceabove or distancebelow for an explicit side');return Zdi.parse({fn:"flexscreen",...e})},Utn={flexscreen:Ahi},chi=t=>{const e=Utn[t.fn];if(e)return e(t);throw new Error(`Unsupported modelprinter function "${t.fn}"`)},lhi=t=>{const e=ehi(t);return{params:()=>e,json:()=>chi(e)}},ghi={string:lhi,getModelNames:()=>Object.keys(Utn)},fUe=ghi,Ktn=Symbol("Fragment");function IUe(t,e,...n){const o=n.length?n:e?.children!==void 0?[e.children]:[],i=[],r=(Array.isArray(o)?o:[o]).flat(1/0);for(const s of r)s==null||s===!1||(Array.isArray(s)?i.push(...s):i.push(s));return{type:t,props:(e&&e.children!==void 0?{...e,children:void 0}:e)||{},children:i}}var Xt=Symbol("Cuboid"),Vtn=Symbol("Cube"),Qs=Symbol("Cylinder"),DG=Symbol("Sphere"),Uf=Symbol("RoundedCuboid"),Fo=Symbol("Translate"),nc=Symbol("Rotate"),Jd=Symbol("Union"),Gl=Symbol("Subtract"),JA=Symbol("Hull"),zo=Symbol("Colorize"),NG=Symbol("Polygon"),RG=Symbol("ExtrudeLinear"),Fy=Symbol("RoundedCylinder"),fi=Ktn,De=(t,e,n)=>IUe(t,e),Bn=(t,e,n)=>IUe(t,e),CUe=({hole:t,isPin1:e})=>{const n=e?"#00ff00":"#b87333";if(t.shape==="circle")return De(zo,{color:n,children:De(Fo,{offset:[t.x,t.y,-.005],children:Bn(Gl,{children:[De(Qs,{radius:t.outer_diameter/2,height:.01}),De(Qs,{radius:t.hole_diameter/2,height:.01})]})})});if(t.shape==="circular_hole_with_rect_pad")return De(zo,{color:n,children:De(Fo,{offset:[t.x,t.y,0],children:Bn(Gl,{children:[De(Xt,{size:[t.rect_pad_width,t.rect_pad_height,.01],center:[0,0,0]}),De(Qs,{radius:t.hole_diameter/2,height:.01})]})})});if(t.shape==="pill"){const o=t.outer_width,i=t.outer_height,r=Math.min(o,i)/2,s=o>i,a=t.hole_width??.8,A=t.hole_height??.8;return De(zo,{color:n,children:De(Fo,{offset:[t.x,t.y,0],children:Bn(Gl,{children:[Bn(JA,{children:[De(Qs,{radius:r,height:.01,center:[s?-(o/2-r):0,s?0:-(i/2-r),0]}),De(Qs,{radius:r,height:.01,center:[s?o/2-r:0,s?0:i/2-r,0]})]}),a===A?De(Qs,{radius:a/2,height:.01}):Bn(JA,{children:[De(Qs,{radius:Math.min(a,A)/2,height:.01,center:[a>A?-(a/2-A/2):0,a>A?0:-(A/2-a/2),0]}),De(Qs,{radius:Math.min(a,A)/2,height:.01,center:[a>A?a/2-A/2:0,a>A?0:A/2-a/2,0]})]})]})})})}throw new Error("Shape not supported: "+t.shape)};function uhi(t){for(const o of["bodyWidth","bodyLength","bodyHeight","pitch","landWidth","landLength","landThickness"])if(!Number.isFinite(t[o])||t[o]<=0)throw new Error(`${o} must be finite and positive`);for(const o of["landsPerSideX","landsPerSideY"])if(!Number.isInteger(t[o])||t[o]<0)throw new Error(`${o} must be a nonnegative integer`);if(!Number.isFinite(t.edgeInset)||t.edgeInset<0||t.landThickness>=t.bodyHeight||t.landWidth>=t.pitch||t.landsPerSideX+t.landsPerSideY<1)throw new Error("Invalid land layout or thickness");const e=[{count:t.landsPerSideX,across:t.bodyWidth,along:t.bodyLength,horizontal:!0},{count:t.landsPerSideY,across:t.bodyLength,along:t.bodyWidth,horizontal:!1}];for(const o of e){if(o.count===0)continue;const i=(o.count-1)*t.pitch+t.landWidth;if(i>=o.along-2*t.edgeInset||2*(t.edgeInset+t.landLength)>=o.across)throw new Error("Lands must fit below the body without opposite-row overlap");const r=o.horizontal?t.landsPerSideY:t.landsPerSideX;if(r>0&&i>=o.along-2*(t.edgeInset+t.landLength)&&(r-1)*t.pitch+t.landWidth>=o.across-2*(t.edgeInset+t.landLength))throw new Error("Adjacent land rows overlap at corners")}const n=Math.min(t.bodyWidth,t.bodyLength)*.035;return Bn(fi,{children:[De(zo,{color:"#353535",children:Bn(Gl,{children:[De(Fo,{z:(t.bodyHeight+t.landThickness/2)/2,children:De(Xt,{size:[t.bodyWidth,t.bodyLength,t.bodyHeight-t.landThickness/2]})}),De(Fo,{offset:[-t.bodyWidth/2+2*n,t.bodyLength/2-2*n,t.bodyHeight],children:De(Qs,{radius:n,height:Math.min(.04,t.bodyHeight/10)})})]})}),De(zo,{color:"#c5b987",children:e.flatMap(o=>[-1,1].flatMap(i=>Array.from({length:o.count},(r,s)=>{const a=i*(o.across/2-t.edgeInset-t.landLength/2),A=((o.count-1)/2-s)*t.pitch;return De(Fo,{offset:[o.horizontal?a:A,o.horizontal?A:a,t.landThickness/2],children:De(Xt,{size:o.horizontal?[t.landLength,t.landWidth,t.landThickness]:[t.landWidth,t.landLength,t.landThickness]})},`${o.horizontal}-${i}-${s}`)})))})]})}function _de(t){const{pinCount:e,pitch:n,bodyWidth:o,bodyLength:i,bodyHeight:r,standoff:s,leadSpan:a,leadWidth:A,leadThickness:c,contactLength:l,taperInset:g,exposedPadWidth:u=0,exposedPadLength:h=0}=t;for(const E of["pitch","bodyWidth","bodyLength","bodyHeight","leadSpan","leadWidth","leadThickness","contactLength"])if(!Number.isFinite(t[E])||t[E]<=0)throw new Error(`${E} must be finite and positive`);for(const[E,B]of Object.entries({standoff:s,taperInset:g,exposedPadWidth:u,exposedPadLength:h}))if(!Number.isFinite(B)||B<0)throw new Error(`${E} must be finite and nonnegative`);if(!Number.isInteger(e)||e<4||e%2)throw new Error("pinCount must be even and at least 4");const d=r-s,m=(a-o)/2,p=(e/2-1)*n+A;if(d<=c*2||A>=n||p>=i-2*g||g*2>=Math.min(o,i)||l>=m)throw new Error("Invalid mold, lead spacing, or terminal reach");if(u===0!=(h===0)||u>=o-2*g||h>=i-2*g)throw new Error("Exposed pad must fit inside the bottom mold face");const _=s+d/2,f=Math.min(.002,d/100),I=Bn(JA,{children:[De(Fo,{z:s+f/2,children:De(Xt,{size:[o-2*g,i-2*g,f]})}),De(Fo,{z:_,children:De(Xt,{size:[o,i,f]})}),De(Fo,{z:r-f/2,children:De(Xt,{size:[o-2*g,i-2*g,f]})})]}),C=Math.min(o,i)*.045,y=Math.min(.04,d/10),x=(E,B)=>{const b=a/2,Q=o/2-Math.min(o/8,.15),w=b-l,D=o/2+Math.min(.08,(m-l)/4),k=[[b-f/2,c/2],[w,c/2]];for(let H=1;H<=12;H++){const G=H/12;k.push([w+(D-w)*G,c/2+(_-c/2)*G*G*(3-2*G)])}k.push([Q,_]);const R=([H,G])=>De(Fo,{offset:{x:E*H,y:B,z:G},children:De(Xt,{size:[f,A,c]})});return De(Jd,{children:k.slice(1).map((H,G)=>Bn(JA,{children:[R(k[G]),R(H)]}))})};return Bn(fi,{children:[De(zo,{color:"#353535",children:Bn(Gl,{children:[I,De(Fo,{offset:{x:-o/2+g+C*2,y:i/2-g-C*2,z:r},children:De(Qs,{radius:C,height:y*2})})]})}),De(zo,{color:"#bfc1c4",children:Array.from({length:e},(E,B)=>x(B<e/2?-1:1,((e/2-1)/2-B%(e/2))*n))}),u>0&&De(zo,{color:"#bfc1c4",children:De(Fo,{z:(s+c)/2,children:De(Xt,{size:[u,h,s+c]})})})]})}var dhi=t=>_de(t);function hhi(t){if(t.bodywidth===void 0&&t.bodyheight===void 0&&t.bodythickness===void 0)return null;if(t.fn==="ssop"){const e=t.bodywidth??t.w*.55,n=t.bodyheight??(t.num_pins/2-1)*t.p+t.pw+.4,o=t.bodythickness??1,i=Math.min(t.pw,t.p*.5),r=(t.num_pins/2-1)*t.p+i;if(n<=r)throw new Error("SSOP bodyheight must contain the lead row");const s=Math.max(t.w+.2+t.pl/2,e+t.p),a=Math.min(.1,o/10);return De(dhi,{pinCount:t.num_pins,pitch:t.p,bodyWidth:e,bodyLength:n,bodyHeight:o+a,standoff:a,leadSpan:s,leadWidth:i,leadThickness:Math.min(.15,o/4),contactLength:Math.min(t.pl/2,(s-e)/4),taperInset:Math.min(.12,(n-r)/4,e/8)})}if(t.fn==="lga"){const e=t.bodywidth??t.w,n=t.bodyheight??t.h,o=t.bodythickness??1,i=t.grid,r=Math.min(t.pw,t.p/2),s=e-((i.y-1)*t.p+r),a=n-((i.x-1)*t.p+r),A=Math.min(t.pl/2,e/8,n/8,s/4,a/4);return De(uhi,{bodyWidth:e,bodyLength:n,bodyHeight:o,landsPerSideX:i.x,landsPerSideY:i.y,pitch:t.p,landWidth:r,landLength:A,edgeInset:0,landThickness:Math.min(.015,o/10)})}return null}var Kg=({center:t,width:e,length:n,height:o,heightAboveSurface:i=.15,color:r="#555",taperRatio:s=.12,faceRatio:a=.75,straightHeightRatio:A=.5,includeNotch:c=!0,notchRadius:l,notchPosition:g,notchRotation:u=[0,0,0],notchLength:h=.5,notchWidth:d=.25,chamferSize:m=0})=>{const p=o*A,_=o-p,f=Math.min(e,n)*s,I=Math.max(e-f,e*a),C=Math.max(n-f,n*a),y=Math.min(e,n)*.12,x=l??y,E={x:0,y:n/2-x*.25,z:o},B=g??E,b=Bn(Jd,{children:[Bn(JA,{children:[De(Fo,{z:.005,children:De(Xt,{size:[I,C,.01]})}),De(Fo,{z:p,children:De(Xt,{size:[e,n,.01]})})]}),Bn(JA,{children:[De(Fo,{z:p,children:De(Xt,{size:[e,n,.01]})}),De(Fo,{z:p+_,children:De(Xt,{size:[I,C,.01]})})]})]}),Q=(D,k)=>De(Fo,{offset:{x:D,y:k,z:0},children:De(nc,{rotation:[0,0,Math.PI/4],children:De(Xt,{size:[m*Math.SQRT2,m*Math.SQRT2,o*3]})})});let w=b;if(m>0){const D=e/2,k=n/2;w=Bn(Gl,{children:[b,Q(D,k),Q(-D,k),Q(D,-k),Q(-D,-k)]})}return De(zo,{color:r,children:De(Fo,{offset:t,children:De(Fo,{offset:{x:0,y:0,z:i},children:c?Bn(Gl,{children:[w,De(Fo,{offset:B,children:De(nc,{rotation:u,children:De(Qs,{radius:x,height:d})})})]}):w})})})},mhi=t=>Array.from({length:t},(e,n)=>n);function yUe(t,e){if(t.length<2)throw new Error("Stroke must have at least two points");const n=Array.isArray(t[0])?t.map(([l,g])=>({x:l,y:g})):t,o=e/2,i=[],r=[];function s(l,g){const u=g.x-l.x,h=g.y-l.y,d=Math.sqrt(u*u+h*h);return{x:-h/d,y:u/d}}function a(l,g,u){const h={x:l.x+g.x*o*u,y:l.y+g.y*o*u};u>0?i.push(h):r.unshift(h)}const A=s(n[0],n[1]);a(n[0],A,1),a(n[0],A,-1);for(let l=1;l<n.length-1;l++){const g=n[l-1],u=n[l],h=n[l+1],d=s(g,u),m=s(u,h),p=d.x+m.x,_=d.y+m.y,f=Math.sqrt(p*p+_*_);if(f/2>2*o)a(u,d,1),a(u,m,1),a(u,d,-1),a(u,m,-1);else{const C=1/f;a(u,{x:p*C,y:_*C},1),a(u,{x:p*C,y:_*C},-1)}}const c=s(n[n.length-2],n[n.length-1]);return a(n[n.length-1],c,1),a(n[n.length-1],c,-1),[...i,...r]}var phi=t=>{const e=Math.min(...t.map(a=>a.x)),n=Math.max(...t.map(a=>a.x)),o=Math.min(...t.map(a=>a.y)),s=5.47/(Math.max(...t.map(a=>a.y))-o);return t.map(a=>({x:(a.x-e-(n-e)/2)*s,y:(a.y-o)*s}))},_hi=phi([{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}]),ztn=5.47,fde=.5,fhi=({x:t,y:e,z:n})=>{const o=t>0;return Bn(fi,{children:[De(Fo,{offset:{x:t+.25/2,y:e,z:n},children:De(nc,{rotation:["-90deg",0,"90deg"],children:De(RG,{height:.25,children:De(NG,{points:_hi.slice().reverse().map(i=>[i.x,i.y])})})})}),De(Fo,{offset:{x:t,y:e+(o?1:-1),z:n},children:De(nc,{rotation:["-90deg","90deg",o?"180deg":"0deg"],children:De(RG,{height:2,children:De(NG,{points:yUe([[0,0],[-1,0],[-1,-1]],.25).map(i=>[i.x,i.y])})})})})]})},Ihi=({numPins:t=8,pitch:e=2.54,bodyWidth:n=6.4,rowSpacing:o})=>{const i=Math.floor(t/2),r=o??(n>=7?n:n+1.22),s=n>=7?r-1.22:n;return Bn(fi,{children:[mhi(t).map(a=>{const A=a%i,c=(Math.floor(a/i)-.5)*2;return De(fhi,{x:c*r/2,y:A*e-(i-1)/2*e,z:ztn/2+fde})}),De(Kg,{width:s,length:i*e+.5,height:ztn-fde,heightAboveSurface:fde,center:{x:0,y:0,z:fde}})]})};function Chi(t,{height:e,padContactLength:n,curveLength:o,bodyDistance:i,steepness:r=10}){o||(o=i*.3);let s=i-n-o;s<0&&(o+=s,s=0);const a=n*.75,A=n+o+(i-n-o)*.25;if(t<=a)return 0;if(t>=A)return e;const c=(t-a)/(A-a);return e/(1+Math.exp(-r*(c-.5)))}var $r=t=>{const{thickness:e,width:n,padContactLength:o,bodyDistance:i,height:r,rotation:s}=t,a=15,A=Array.from({length:a}).map((l,g)=>g/(a-1)*i).map(l=>[l,Chi(l,t)]),c=yUe(A,e);return De(zo,{color:"#fff",children:De(Fo,{offset:{z:0,y:0,x:0,...t.position},children:De(nc,{rotation:["90deg",0,s??0],children:De(Fo,{offset:{x:0,y:0,z:-n/2},children:De(RG,{height:n,children:De(NG,{points:c.map(l=>[l.x,l.y])})})})})})})},yhi=({pinCount:t,leadLength:e,leadWidth:n,pitch:o,bodyWidth:i})=>{const r=Math.ceil(t/2),s=r<=4,a=(r-1)*o/2,A=o*Math.max(r-1,0)+(s?1.5:1.15),c=i-(s?.66:.58),l=.15,g=.8,u=1.22,h=e*.5,d=h+Math.max(.22,Math.min(.4,e*.65)),m=i/2+e/2,p=d*.1,_=Math.min(Math.min(c,A)*.18,1),f=Math.min(Math.min(c,A)*.12,.45);return Bn(fi,{children:[Array.from({length:r}).map((I,C)=>De($r,{position:{x:-m,y:C*o-a,z:l/2},width:n,thickness:l,padContactLength:h,bodyDistance:d,curveLength:p,height:g})),Array.from({length:r}).map((I,C)=>De($r,{rotation:Math.PI,position:{x:m,y:C*o-a,z:l/2},width:n,thickness:l,padContactLength:h,bodyDistance:d,curveLength:p,height:g})),De(Kg,{center:{x:0,y:0,z:0},width:c,length:A,height:u,notchPosition:{x:-(c/2-_-.2),y:A/2-_-.2,z:u},notchRadius:f})]})},xhi=t=>"leadSpan"in t?_de(t):yhi(t),Ehi=({pinCount:t,padContactLength:e=.4,leadWidth:n=.2,pitch:o=.65,bodyWidth:i=3})=>{const r=Math.ceil(t/2),s=(r-1)*o/2,a=.2;return Bn(fi,{children:[Array.from({length:r}).map((A,c)=>De($r,{position:{x:-i/2-e-.3,y:c*o-s,z:a/2},width:n,thickness:a,padContactLength:e,bodyDistance:e+.4,height:.6})),Array.from({length:r}).map((A,c)=>De($r,{rotation:Math.PI,position:{x:i/2+e+.3,y:c*o-s,z:a/2},width:n,thickness:a,padContactLength:e,bodyDistance:e+.4,height:.6})),De(Kg,{center:{x:0,y:0,z:a/2},width:i,length:i,height:1.1,notchRadius:.35,heightAboveSurface:.1,taperRatio:.09})]})},Bhi=t=>"leadSpan"in t?_de(t):Ehi(t),xUe=1,EUe=.5,TG=.5,lq=.2,Shi=xUe-lq*2,Jtn=({color:t="#333"})=>Bn(fi,{children:[De(Xt,{size:[Shi,EUe,TG],offset:[0,0,TG/2],color:t}),De(Xt,{size:[lq,TG,EUe],offset:[xUe/2-lq/2,0,TG/2],color:"#ccc"}),De(Xt,{size:[lq,TG,EUe],offset:[-xUe/2+lq/2,0,TG/2],color:"#ccc"})]}),BUe=1.6,bhi=BUe-.3*2,Ide=.3,SUe=.85,kG=.6,Wtn=({color:t="#333"})=>Bn(fi,{children:[De(Xt,{size:[bhi,SUe,kG],offset:[0,0,kG/2],color:t}),De(Xt,{size:[Ide,SUe,kG],offset:[BUe/2-Ide/2,0,kG/2],color:"#ccc"}),De(Xt,{size:[Ide,SUe,kG],offset:[-BUe/2+Ide/2,0,kG/2],color:"#ccc"})]}),bUe=2,QUe=1.25,FG=.55,gq=.5,Qhi=bUe-gq*2,jtn=({color:t="#333"})=>Bn(fi,{children:[De(Xt,{size:[Qhi,QUe,FG],offset:[0,0,FG/2],color:t}),De(Xt,{size:[gq,QUe,FG],offset:[bUe/2-gq/2,0,FG/2],color:"#ccc"}),De(Xt,{size:[gq,QUe,FG],offset:[-bUe/2+gq/2,0,FG/2],color:"#ccc"})]}),Xtn=({pinCount:t,pitch:e,leadWidth:n,padContactLength:o,bodyWidth:i})=>{const r=t/4;e||(e=vhi(t,i)),o||(o=Phi(t)),n||(n=whi(t,i)),i||(i=e*(r+4));const s=o,a=i,A=(r-1)*e/2,c=s*.5,l=a+2*c,g=l,u=.8,h=.15,d=c,m=c*.5,p=c*.18;return Bn(fi,{children:[Array.from({length:r}).map((_,f)=>De($r,{position:{x:-g/2,y:f*e-A,z:h/2},width:n,thickness:h,padContactLength:m,bodyDistance:d,curveLength:p,height:u})),Array.from({length:r}).map((_,f)=>De($r,{rotation:Math.PI,position:{x:g/2,y:f*e-A,z:h/2},width:n,thickness:h,padContactLength:m,bodyDistance:d,curveLength:p,height:u})),Array.from({length:r}).map((_,f)=>De($r,{rotation:Math.PI/2,position:{x:f*e-A,y:-l/2,z:h/2},width:n,thickness:h,padContactLength:m,bodyDistance:d,curveLength:p,height:u})),Array.from({length:r}).map((_,f)=>De($r,{rotation:-Math.PI/2,position:{x:f*e-A,y:l/2,z:h/2},width:n,thickness:h,padContactLength:m,bodyDistance:d,curveLength:p,height:u})),De(Kg,{center:{x:0,y:0,z:0},width:i,length:a,height:1.5,taperRatio:.03,chamferSize:.7,notchPosition:{x:-(a/2-1.5),y:i/2-1.5,z:1.5},notchRadius:1.5/2})]})},vhi=(t,e)=>{switch(t){case 44:case 64:return .8;case 52:return e===14?1:.65;case 208:return .5;default:return .5}},Phi=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}},whi=(t,e)=>{switch(t){case 44:case 64:return .5;case 52:return e===14?.45:.55;case 208:return .3;default:return .25}},LG="#c0c0c0",qtn=({x:t,y:e,pinThickness:n,shortSidePinLength:o,longSidePinLength:i,bodyHeight:r,bodyLength:s=2.54,bodyWidth:a=2.54,flipZ:A,smd:c,rightangle:l})=>Bn(fi,{children:[De(Fo,{y:l?-3:0,children:De(Xt,{color:"#222",size:[s,a,r],center:[t,e,A(r/2)]})}),De(zo,{color:LG,children:c?De($r,{rotation:-Math.PI/2,position:{x:t,y:e+1,z:n/2},thickness:n,width:n,height:n,padContactLength:2,bodyDistance:3}):Bn(JA,{children:[De(Xt,{color:LG,size:[n,n,o*.9],center:[t,e,A(r*.9+r/2)]}),De(Xt,{color:LG,size:[n/1.8,n/1.8,o],center:[t,e,A(r+r/2)]})]})}),De(zo,{color:LG,children:De(Fo,{y:l?-3.9:0,z:l?1:0,children:De(nc,{rotation:l?[-Math.PI/2,0,0]:[0,0,0],children:Bn(JA,{children:[De(Xt,{color:LG,size:[n,n,i*.9],center:[t,e,A(-i/2*.9)]}),De(Xt,{color:LG,size:[n/1.8,n/1.8,i],center:[t,e,A(-i/2)]})]})})})})]}),$tn=({numberOfPins:t,pitch:e=2.54,longSidePinLength:n=6,invert:o,rows:i=1,smd:r,rightangle:s})=>{const c=Math.ceil(t/i),l=2.54,g=3,u=-((c-1)/2)*e,d=!r&&!s?!o:!!o,m=p=>d?-p+2:p;return De(fi,{children:Array.from({length:t},(p,_)=>{const f=Math.floor(_/c),I=_%c,C=u+I*e,y=((i-1)/2-f)*l;return De(qtn,{x:C,y,pinThickness:.63,shortSidePinLength:g,longSidePinLength:n,bodyHeight:2,flipZ:m,smd:r,rightangle:s},_)})})};function Mhi(t){const{num_pins:e,bodyWidth:n,bodyLength:o,bodyHeight:i,standoff:r,terminalSpanX:s,terminalSpanY:a,terminalThickness:A,padWidth:c,padLength:l,pitch:g,exposedPadWidth:u,exposedPadLength:h}=t;for(const _ of["bodyWidth","bodyLength","bodyHeight","terminalSpanX","terminalSpanY","terminalThickness","padWidth","padLength","pitch","exposedPadWidth","exposedPadLength"])if(!Number.isFinite(t[_])||t[_]<=0)throw new Error(`${_} must be finite and positive`);if(!Number.isInteger(e)||e<8||e%4)throw new Error("num_pins must be divisible by four and at least eight");if(!Number.isFinite(r)||r<0)throw new Error("standoff must be finite and nonnegative");const d=(e/4-1)*g+c;if(A<=r||A>=i||c>=g||d>=Math.min(n,o))throw new Error("Invalid mold, terminal thickness or spacing");if(s<n||a<o||s/2-l>=n/2||a/2-l>=o/2||u>=Math.min(n,s-2*l)||h>=Math.min(o,a-2*l)||d>=Math.min(s,a)-2*l)throw new Error("Terminals must enter the mold and clear the exposed pad and corners");const m=De(Fo,{z:(i+r)/2,children:De(Xt,{size:[n,o,i-r]})}),p=Math.min(n,o)*.035;return Bn(fi,{children:[De(zo,{color:"#353535",children:Bn(Gl,{children:[m,De(Fo,{offset:{x:-n/2+p*2,y:o/2-p*2,z:i},children:De(Qs,{radius:p,height:Math.min(.06,(i-r)/5)})})]})}),De(zo,{color:"#bfc1c4",children:Array.from({length:e},(_,f)=>{const I=Math.floor(f/(e/4)),C=((e/4-1)/2-f%(e/4))*g,y=I%2===0,x=I<2?-1:1,E=((y?s:a)-l)/2*x;return De(Fo,{offset:{x:y?E:C,y:y?C:E,z:A/2},children:De(Xt,{size:y?[l,c,A]:[c,l,A]})},f)})}),De(zo,{color:"#bfc1c4",children:De(Fo,{z:A/2,children:De(Xt,{size:[u,h,A]})})})]})}var Dhi=t=>{const e=["left","bottom","right","top"],{pin_count:n,pn:o,w:i,h:r,p:s,pl:a}=t,A=n/4,c=e[Math.floor((o-1)/A)],l=(o-1)%A,g=s*(A-1),u=s*(A-1),h=-a/2;switch(c){case"left":return{x:-i/2-h,y:u/2-l*s,o:"vert"};case"bottom":return{x:-g/2+l*s,y:-r/2-h,o:"horz"};case"right":return{x:i/2+h,y:-u/2+l*s,o:"vert"};case"top":return{x:g/2-l*s,y:r/2+h,o:"horz"};default:throw new Error("Invalid pin number")}},Nhi=({num_pins:t,cw:e,ccw:n,startingpin:o})=>{const i=[],r=t/4;let s=1;const a={};for(const A of o??[])a[A]=!0;!a.leftside&&!a.topside&&!a.rightside&&!a.bottomside&&(a.leftside=!0),!a.bottompin&&!a.leftpin&&!a.rightpin&&!a.toppin&&(a.leftside?a.toppin=!0:a.topside?a.rightpin=!0:a.rightside?a.bottompin=!0:a.bottomside&&(a.leftpin=!0)),a.leftside&&a.toppin?s=1:a.leftside&&a.bottompin?s=r:a.bottomside&&a.leftpin?s=r+1:a.bottomside&&a.rightpin?s=r*2:a.rightside&&a.bottompin?s=r*2+1:a.rightside&&a.toppin?s=r*3:a.topside&&a.rightpin?s=r*3+1:a.topside&&a.leftpin&&(s=r*4),i.push(-1);for(let A=0;A<t;A++)i[s]=A+1,s++,s>t&&(s=1);return i},Rhi=({num_pins:t=16,bodyWidth:e=9,bodyLength:n=9,bodyThickness:o=.8,thermalPadSize:i,padWidth:r=.25,padLength:s=.25,pitch:a=.5,thermalPadThickness:A=.05})=>{const c=Nhi({num_pins:t,cw:!0,ccw:!0}),l=[];for(let g=0;g<t;g++){const{x:u,y:h,o:d}=Dhi({pin_count:t,pn:g+1,w:e,h:n,p:a,pl:s});let m=r,p=s;d==="vert"&&([m,p]=[p,m]);const _=c[g+1];l.push({pn:_,x:u,y:h,pw:m,pl:p})}return Bn(fi,{children:[De(zo,{color:"grey",children:De(Xt,{center:[0,0,o/2],size:[e,n,o]})}),l.map((g,u)=>De(Xt,{center:[g.x,g.y,A/2],size:[g.pw,g.pl,A]})),i?.length!==void 0&&i?.width!==void 0&&De(Xt,{center:[0,0,A/2],size:[i.width,i.length,A]})]})},Thi=t=>"bodyHeight"in t?Mhi(t):Rhi(t),Ztn=Thi,khi=()=>{const A=1.1999999999999997;return Bn(fi,{children:[De($r,{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}),De($r,{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}),De($r,{position:{x:-2.8/2-A/4,y:0,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:A,height:.95}),De($r,{position:{x:-2.8/2-A/4,y:-1,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:A,height:.95}),De($r,{position:{x:-2.8/2-A/4,y:1,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:A,height:.95}),De(Kg,{center:{x:0,y:0,z:0},width:1.6,length:2.9,height:1.2})]})},enn=khi,Fhi=({fullWidth:t=2.9,fullLength:e=2.8,color:n}={})=>{const g=(t-1.3)/2+.3;return Bn(fi,{children:[De($r,{position:{x:-t/2,y:.95,z:.075},width:.4,thickness:.15,padContactLength:.4,bodyDistance:g,height:.95}),De($r,{position:{x:-t/2,y:-.95,z:.075},width:.4,thickness:.15,padContactLength:.4,bodyDistance:g,height:.95}),De($r,{rotation:Math.PI,position:{x:t/2,y:0,z:.075},width:.4,thickness:.15,padContactLength:.4,bodyDistance:g,height:.95}),De(Kg,{center:{x:0,y:0,z:0},width:1.3,length:2.9,height:1.1,color:n})]})},Lhi=({fullWidth:t=2.9,fullLength:e=2.8})=>{const l=(t-1.92)/2+.3;return Bn(fi,{children:[De($r,{rotation:Math.PI,position:{x:t/2,y:0,z:.075},width:.4,thickness:.15,padContactLength:.25,bodyDistance:l,height:.45}),De($r,{position:{x:-t/2,y:-.95,z:.075},width:.4,thickness:.15,padContactLength:.25,bodyDistance:l,height:.45}),De($r,{position:{x:-t/2,y:.95,z:.075},width:.4,thickness:.15,padContactLength:.25,bodyDistance:l,height:.45}),De(Kg,{center:{x:0,y:0,z:0},width:1.92,length:2.9,height:1.1,straightHeightRatio:.45,heightAboveSurface:.05})]})},vUe=.6,PUe=.3,HG=.33,uq=.1,Hhi=vUe-uq*2,tnn=({color:t="#333"})=>Bn(fi,{children:[De(Xt,{size:[Hhi,PUe,HG],offset:[0,0,HG/2],color:t}),De(Xt,{size:[uq,PUe,HG],offset:[vUe/2-uq/2,0,HG/2],color:"#ccc"}),De(Xt,{size:[uq,PUe,HG],offset:[-vUe/2+uq/2,0,HG/2],color:"#ccc"})]}),wUe=.4,MUe=.2,OG=.13,dq=.07,Ohi=wUe-dq*2,nnn=({color:t="#333"})=>Bn(fi,{children:[De(Xt,{size:[Ohi,MUe,OG],offset:[0,0,OG/2],color:t}),De(Xt,{size:[dq,MUe,OG],offset:[wUe/2-dq/2,0,OG/2],color:"#ccc"}),De(Xt,{size:[dq,MUe,OG],offset:[-wUe/2+dq/2,0,OG/2],color:"#ccc"})]}),DUe=3.2,NUe=1.6,GG=.9,hq=.5,Ghi=DUe-hq*2,onn=({color:t="#333"})=>Bn(fi,{children:[De(Xt,{size:[Ghi,NUe,GG],offset:[0,0,GG/2],color:t}),De(Xt,{size:[hq,NUe,GG],offset:[DUe/2-hq/2,0,GG/2],color:"#ccc"}),De(Xt,{size:[hq,NUe,GG],offset:[-DUe/2+hq/2,0,GG/2],color:"#ccc"})]}),RUe=3.2,TUe=2.5,YG=1,mq=.6,Yhi=RUe-mq*2,inn=({color:t="#333"})=>Bn(fi,{children:[De(Xt,{size:[Yhi,TUe,YG],offset:[0,0,YG/2],color:t}),De(Xt,{size:[mq,TUe,YG],offset:[RUe/2-mq/2,0,YG/2],color:"#ccc"}),De(Xt,{size:[mq,TUe,YG],offset:[-RUe/2+mq/2,0,YG/2],color:"#ccc"})]}),kUe=5,FUe=2.5,UG=1.4,pq=.6,Uhi=kUe-pq*2,rnn=({color:t="#333"})=>Bn(fi,{children:[De(Xt,{size:[Uhi,FUe,UG],offset:[0,0,UG/2],color:t}),De(Xt,{size:[pq,FUe,UG],offset:[kUe/2-pq/2,0,UG/2],color:"#ccc"}),De(Xt,{size:[pq,FUe,UG],offset:[-kUe/2+pq/2,0,UG/2],color:"#ccc"})]}),LUe=6.3,HUe=3.2,KG=1.8,_q=.8,Khi=LUe-_q*2,snn=({color:t="#333"})=>Bn(fi,{children:[De(Xt,{size:[Khi,HUe,KG],offset:[0,0,KG/2],color:t}),De(Xt,{size:[_q,HUe,KG],offset:[LUe/2-_q/2,0,KG/2],color:"#ccc"}),De(Xt,{size:[_q,HUe,KG],offset:[-LUe/2+_q/2,0,KG/2],color:"#ccc"})]}),ann=({x:t,y:e,z:n=0,pitch:o=2.54,legsLength:i=3,innerDiameter:r=.945,bodyHeight:s=5,bodyLength:a=o,bodyWidth:A=o,flipZ:c})=>{const l=r||.945,g=l/1.5,u=l,h=u*1.8,d=Math.min(s*.18,o*.24),m=s+.1,p=c(n+m/2),_=n+s-d,f=g*1.6;return Bn(fi,{children:[De(zo,{color:"#1a1a1a",children:Bn(Gl,{children:[De(Xt,{color:"#000",size:[a,A,s],center:[t,e,c(n+s/2)]}),De(Xt,{size:[u,u,m],center:[t,e,p]}),Bn(JA,{children:[De(Xt,{size:[u,u,.01],center:[t,e,c(_)]}),De(Xt,{size:[h,h,.01],center:[t,e,c(n+s)]})]})]})}),Bn(zo,{color:"silver",children:[Bn(JA,{children:[De(Xt,{color:"silver",size:[g,g,i*.9],center:[t,e,c(n+-i/2*.9)]}),De(Xt,{color:"silver",size:[g/1.8,g/1.8,i],center:[t,e,c(n+-i/2)]})]}),De(Xt,{color:"silver",size:[f,f,f*.5],center:[t,e,c(n+f/2*.5)]})]})]})},Vhi=({numberOfPins:t,pitch:e=2.54,legsLength:n=3,innerDiameter:o=.945,rows:i=1,invert:r})=>{const a=Math.ceil(t/i),A=2.54,c=-((a-1)/2)*e,l=g=>r?-g+5:g;return De(fi,{children:Array.from({length:t},(g,u)=>{const h=Math.floor(u/a),d=u%a,m=c+d*e,p=((i-1)/2-h)*A;return De(ann,{x:m,y:p,pitch:e,legsLength:n,innerDiameter:o,flipZ:l},u)})})},zhi=({width:t,length:e,innerDiameter:n=1})=>{const o=t,i=e,r=t*.7,s=n/2.5;return Bn(fi,{children:[De(Uf,{color:"#1a1a1f",center:[0,0,r/2],size:[i,i,r],roundRadius:.3}),De(Uf,{color:"#f2f2f2",center:[0,0,r+r*.1/2.5],size:[i,i,r*.1],roundRadius:.14}),De(Qs,{color:"#1a1a1f",height:r*.8,radius:o/3,center:[0,0,r+r*.8/2]}),De(Qs,{color:"#1a1a1f",height:r*.2,radius:n/2,center:[i/3,i/3,r+r*.1/2]}),De(Qs,{color:"#1a1a1f",height:r*.2,radius:n/2,center:[-i/3,-i/3,r+r*.1/2]}),De(Qs,{color:"#1a1a1f",height:r*.2,radius:n/2,center:[-i/3,i/3,r+r*.1/2]}),De(Qs,{color:"#1a1a1f",height:r*.2,radius:n/2,center:[i/3,-i/3,r+r*.1/2]}),De(Cde,{thickness:n/3,width:s,horizontalLength:i*.8,verticalLength:r/2,position:{x:-o/2,y:-i/2,z:-r*1.2}}),De(Cde,{thickness:n/3,width:s,horizontalLength:i*.8,verticalLength:r/2,position:{x:-o/2,y:i/2,z:-r*1.2},rotation:Math.PI}),De(Cde,{thickness:n/3,width:s,horizontalLength:i*.8,verticalLength:r/2,position:{x:o/2,y:i/2,z:-r*1.2},rotation:Math.PI}),De(Cde,{thickness:n/3,width:s,horizontalLength:i*.8,verticalLength:r/2,position:{x:o/2+n/3.6,y:-i/2,z:-r*1.2}})]})},Cde=t=>{const{thickness:e,width:n,horizontalLength:o,verticalLength:i,rotation:r=0,position:s}=t,a=[[0,o],[-i/3,o/3],[-i/5,o/4],[0,0]],A=yUe(a,e);return De(zo,{color:"#f2f2f2",children:De(Fo,{offset:{x:s?.x||0,y:s?.y||0,z:s?.z||0},children:De(nc,{rotation:[0,55,r],children:De(RG,{height:n,children:De(NG,{points:A.map(c=>[c.y,c.x])})})})})})},Jhi=({pinCount:t,leadLength:e,leadWidth:n,pitch:o,bodyWidth:i})=>{const r=Math.ceil(t/2),s=(r-1)*o/2,a=.25,A=1,c=.8,l=e*0,g=o*(r-1)+n+.2,u=i*.55;return Bn(fi,{children:[Array.from({length:r}).map((h,d)=>De($r,{position:{x:-i/2-l,y:d*o-s,z:a/2},width:n,thickness:a,padContactLength:e/2,bodyDistance:e+.3,height:c})),Array.from({length:r}).map((h,d)=>De($r,{rotation:Math.PI,position:{x:i/2+l,y:d*o-s,z:a/2},width:n,thickness:a,padContactLength:e/2,bodyDistance:e+.3,height:c})),De(Kg,{center:{x:0,y:0,z:a/2},width:u,length:g,height:A})]})},Whi=t=>"leadSpan"in t?_de(t):Jhi(t),jhi=({pinCount:t,pitch:e,leadWidth:n,leadLength:o,bodyWidth:i,bodyLength:r})=>{const s=t===8?{pitch:.65,leadWidth:.3}:{pitch:.5,leadWidth:.225},a=isNaN(parseFloat(e))?s.pitch:parseFloat(e),A=isNaN(parseFloat(n))?s.leadWidth:parseFloat(n)*.8,c=isNaN(parseFloat(i))?2.6:parseFloat(i)*.8,l=isNaN(parseFloat(r))?2+Number(a)*1.4:parseFloat(r),g=t/2,u=(g-1)*a/2,h=.15,d=.8,m=4.5,p=(m-c)/2,_=p*.5;return Bn(fi,{children:[Array.from({length:g}).map((f,I)=>De($r,{position:{x:-m/2,y:u-I*a,z:h/2},width:A,thickness:h,padContactLength:_+.05,bodyDistance:p+.1,height:d})),Array.from({length:g}).map((f,I)=>De($r,{rotation:Math.PI,position:{x:m/2,y:u-I*a,z:h/2},width:A,thickness:h,padContactLength:_+.05,bodyDistance:p+.1,height:d})),De(Kg,{center:{x:0,y:0,z:h/2},width:c,length:l,height:1})]})},Xhi=()=>Bn(fi,{children:[De(Xt,{color:"#ccc",size:[.5,.6,.12],center:[-.725,0,.12/2]}),De(Xt,{color:"#ccc",size:[.5,.6,.12],center:[.725,0,.12/2]}),De(zo,{color:"#222",children:Bn(Jd,{children:[De(Fo,{z:.3/2,children:De(Xt,{size:[1.65,.8,.3]})}),Bn(JA,{children:[De(Fo,{z:.3,children:De(Xt,{size:[1.65,.8,.01]})}),De(Fo,{z:.6,children:De(Xt,{size:[1.65-.2,.8-.2,.01]})})]})]})})]}),Ann=()=>Bn(fi,{children:[De(Xt,{color:"#ccc",size:[.26,.51,.12],center:[-.325,0,.12/2]}),De(Xt,{color:"#ccc",size:[.26,.51,.12],center:[.325,0,.12/2]}),De(zo,{color:"#222",children:De(Fo,{z:.47/2+.02,children:De(Xt,{size:[.98,.58,.47]})})}),De(Xt,{color:"#ccc",size:[.98+.001,.26/2,.26/4],center:[0,.26/2,.47/4]}),De(Xt,{color:"#ccc",size:[.98+.001,.26/2,.26/4],center:[0,-.26/2,.47/4]}),De(Xt,{color:"#ccc",size:[.26/1.5,.58+.001,.26/4],center:[.65/2,0,.47/4]}),De(Xt,{color:"#ccc",size:[.26/1.5,.58+.001,.26/4],center:[-.65/2,0,.47/4]})]}),qhi=()=>{const c=De(zo,{color:"#1a1a1a",children:Bn(Jd,{children:[Bn(JA,{children:[De(Fo,{z:.13,children:De(Xt,{size:[4,3,.03]})}),De(Fo,{z:1.15,children:De(Xt,{size:[4.4,3.4,.01]})})]}),Bn(JA,{children:[De(Fo,{z:1.15,children:De(Xt,{size:[4.4,3.4,.01]})}),De(Fo,{z:2.3,children:De(Xt,{size:[4,3,.01]})})]})]})}),l=({xDir:g})=>{const d=g*1.78,m=g*(3.4/2-.2/2+1),p=g*(3.4/2-.2/2),_=Math.abs(p-m),f=(m+p)/2;return De(zo,{color:"#c0c0c0",children:Bn(Jd,{children:[De(Xt,{size:[2.3*.8,1.45,.2],center:[d,0,.2/2]}),De(Xt,{size:[.2,1.45,1.14],center:[m,0,1.14/2+.2]}),De(Xt,{size:[_,1.45,.2],center:[f,0,.2/2+1.14]})]})})};return Bn(fi,{children:[De(l,{xDir:1}),De(l,{xDir:-1}),c]})},cnn=()=>{const c=De(zo,{color:"#1a1a1a",children:Bn(Jd,{children:[Bn(JA,{children:[De(Fo,{z:.13,children:De(Xt,{size:[4.199999999999999,3.6,.03]})}),De(Fo,{z:1.15,children:De(Xt,{size:[4.6,4,.01]})})]}),Bn(JA,{children:[De(Fo,{z:1.15,children:De(Xt,{size:[4.6,4,.01]})}),De(Fo,{z:2.3,children:De(Xt,{size:[4.199999999999999,3.6,.01]})})]})]})}),l=({xDir:g})=>{const d=g*2.08,m=g*(4/2-.2/2+1),p=g*(4/2-.2/2),_=Math.abs(p-m),f=(m+p)/2;return De(zo,{color:"#c0c0c0",children:Bn(Jd,{children:[De(Xt,{size:[2.3*.8,1.45,.2],center:[d,0,.2/2]}),De(Xt,{size:[.2,1.45,1.14],center:[m,0,1.14/2+.2]}),De(Xt,{size:[_,1.45,.2],center:[f,0,.2/2+1.14]})]})})};return Bn(fi,{children:[De(l,{xDir:1}),De(l,{xDir:-1}),c]})},$hi=()=>{const c=De(zo,{color:"#1a1a1a",children:Bn(Jd,{children:[Bn(JA,{children:[De(Fo,{z:.21000000000000002,children:De(Xt,{size:[6.3999999999999995,5.6,.03]})}),De(Fo,{z:1.15,children:De(Xt,{size:[6.8,6,.01]})})]}),Bn(JA,{children:[De(Fo,{z:1.15,children:De(Xt,{size:[6.8,6,.01]})}),De(Fo,{z:2.3,children:De(Xt,{size:[6.3999999999999995,5.6,.01]})})]})]})}),l=({xDir:g})=>{const d=g*3.08,m=g*(6/2-.2/2+1),p=g*(6/2-.2/2),_=Math.abs(p-m),f=(m+p)/2;return De(zo,{color:"#c0c0c0",children:Bn(Jd,{children:[De(Xt,{size:[2.3*.8,2.95,.2],center:[d,0,.2/2]}),De(Xt,{size:[.2,2.95,1.14],center:[m,0,1.14/2+.2]}),De(Xt,{size:[_,2.95,.2],center:[f,0,.2/2+1.14]})]})})};return Bn(fi,{children:[De(l,{xDir:1}),De(l,{xDir:-1}),c]})},Zhi=()=>{const g=De(zo,{color:"#222",children:Bn(Jd,{children:[De(Fo,{z:.27,children:De(Xt,{size:[2.9,1.9,.54]})}),Bn(JA,{children:[De(Fo,{z:.54,children:De(Xt,{size:[2.9,1.9,.01]})}),De(Fo,{z:1.08,children:De(Xt,{size:[2.6999999999999997,1.7,.01]})})]})]})});return Bn(fi,{children:[De(Xt,{color:"#ccc",size:[1,1.2,.25],center:[-1.3,0,.25/2]}),De(Xt,{color:"#ccc",size:[1,1.2,.25],center:[1.3,0,.25/2]}),g]})},emi=()=>Bn(fi,{children:[De(Xt,{color:"#ccc",size:[1,.6,.12],center:[-1.3,0,.12/2]}),De(Xt,{color:"#ccc",size:[1,.6,.12],center:[1.3,0,.12/2]}),De(zo,{color:"#222",children:Bn(Jd,{children:[De(Fo,{z:.55/2,children:De(Xt,{size:[2.7,1.6,.55]})}),Bn(JA,{children:[De(Fo,{z:.55,children:De(Xt,{size:[2.7,1.6,.01]})}),De(Fo,{z:1.1,children:De(Xt,{size:[2.7-.2,1.6-.2,.01]})})]})]})})]}),tmi=()=>Bn(fi,{children:[De(Xt,{color:"#ccc",size:[1,.9,.2],center:[-1.3,0,.2/2]}),De(Xt,{color:"#ccc",size:[1,.9,.2],center:[1.3,0,.2/2]}),De(zo,{color:"#222",children:Bn(Jd,{children:[De(Fo,{z:.2/2,children:De(Xt,{size:[2.75,1.8,.2]})}),Bn(JA,{children:[De(Fo,{z:.2,children:De(Xt,{size:[2.75,1.8,.01]})}),De(Fo,{z:1,children:De(Xt,{size:[2.75-.4,1.8-.4,.01]})})]})]})}),De(Xt,{color:"#777",size:[.2,1.8-.4,.01],center:[-1.3+.4,0,1]})]}),lnn=({bodyWidth:t=2.6,bodyLength:e=1.7,bodyHeight:n=1}={})=>{const o=t,i=e*.53,r=t*.35,s=.2,a=-(o/2-.075),A=o/2-.075,c=.4,l=.1,g=n*.2;return Bn(fi,{children:[De(Xt,{color:"#ccc",size:[r,i,s],center:[a,0,s/2]}),De(Xt,{color:"#ccc",size:[r,i,s],center:[A,0,s/2]}),De(zo,{color:"#222",children:Bn(Jd,{children:[Bn(JA,{children:[De(Fo,{z:g,children:De(Xt,{size:[o-l/2,e-l/2,.01]})}),De(Fo,{z:.01,children:De(Xt,{size:[o-l,e-l,.01]})})]}),Bn(JA,{children:[De(Fo,{z:g,children:De(Xt,{size:[o,e,.01]})}),De(Fo,{z:n,children:De(Xt,{size:[o-c,e-c,.01]})})]})]})}),De(Xt,{color:"#777",size:[s*2.7,e-c,.02],center:[a+c,0,n]})]})},nmi=({fullWidth:t=3.7,fullLength:e=1.55}={})=>{const n=t-1,o=e,i=1.175,r=.1,s=i-r,a=.55,A=.12,c=.35,l=(t-n)/2,g=.25,u=.2;return Bn(fi,{children:[De($r,{position:{x:-t/2,y:0,z:A/2},width:a,thickness:A,padContactLength:g,bodyDistance:l,curveLength:u,height:c}),De($r,{rotation:Math.PI,position:{x:t/2,y:0,z:A/2},width:a,thickness:A,padContactLength:g,bodyDistance:l,curveLength:u,height:c}),De(Kg,{center:{x:0,y:0,z:0},width:n,length:o,height:s,heightAboveSurface:r,includeNotch:!1,color:"#222",taperRatio:.06,straightHeightRatio:.6}),De(Xt,{color:"#777",size:[.45,o-.15,.02],center:[-n/4,0,i]})]})},omi=()=>Bn(fi,{children:[De(Xt,{color:"#ccc",size:[.9,1.75,.2],center:[-1.825,0,.2/2]}),De(Xt,{color:"#ccc",size:[.9,1.75,.2],center:[1.825,0,.2/2]}),De(zo,{color:"#222",children:Bn(Jd,{children:[Bn(JA,{children:[De(Fo,{z:.2,children:De(Xt,{size:[3.8-.05/2,2.5-.05/2,.01]})}),De(Fo,{z:.01,children:De(Xt,{size:[3.8-.05,2.5-.05,.01]})})]}),Bn(JA,{children:[De(Fo,{z:.2,children:De(Xt,{size:[3.8,2.5,.01]})}),De(Fo,{z:1,children:De(Xt,{size:[3.8-.4,2.5-.4,.01]})})]})]})}),De(Xt,{color:"#777",size:[.2*2.7,2.5-.4,.02],center:[-1.825+.4,0,1]})]}),imi=()=>Bn(fi,{children:[De(Xt,{color:"#ccc",size:[.4,.25,.14],center:[-.4,0,.14/2]}),De(Xt,{color:"#ccc",size:[.4,.25,.14],center:[.4,0,.14/2]}),De(zo,{color:"#222",children:Bn(Jd,{children:[De(Fo,{z:.14/2,children:De(Xt,{size:[.8,.6,.14]})}),Bn(JA,{children:[De(Fo,{z:.14,children:De(Xt,{size:[.8,.6,.01]})}),De(Fo,{z:.37,children:De(Xt,{size:[.8-.1,.6-.1,.01]})})]})]})})]}),gnn=({fullWidth:t=6.6,bodyWidth:e=3.5,bodyLength:n=6.5,bodyHeight:o=1.7,leadWidth:i=.7,tabLeadWidth:r=3,padPitch:s=2.3,leadHeight:a=.75}={})=>{const A=r,c=.25,l=.5,g=t-e;return Bn(fi,{children:[De($r,{rotation:Math.PI,position:{x:t/2+g/4,y:0,z:c/2},width:A,thickness:c,padContactLength:l,bodyDistance:g,height:a}),De($r,{position:{x:-t/2-g/4,y:0,z:c/2},width:i,thickness:c,padContactLength:l,bodyDistance:g,height:a}),De($r,{position:{x:-t/2-g/4,y:-s,z:c/2},width:i,thickness:c,padContactLength:l,bodyDistance:g,height:a}),De($r,{position:{x:-t/2-g/4,y:s,z:c/2},width:i,thickness:c,padContactLength:l,bodyDistance:g,height:a}),De(Kg,{center:{x:0,y:0,z:0},width:e,length:n,height:o,includeNotch:!1,taperRatio:.06,straightHeightRatio:.45})]})},rmi=()=>Bn(fi,{children:[Array.from({length:16}).map((h,d)=>De($r,{position:{x:-10.5/2,y:d*.5-3.75,z:.25/2},width:.2,thickness:.25,padContactLength:.45,bodyDistance:.95,height:.65})),Array.from({length:16}).map((h,d)=>De($r,{rotation:Math.PI,position:{x:10.5/2,y:d*.5-3.75,z:.25/2},width:.2,thickness:.25,padContactLength:.45,bodyDistance:.95,height:.65})),Array.from({length:16}).map((h,d)=>De($r,{rotation:Math.PI/2,position:{x:d*.5-3.75,y:-10.5/2,z:.25/2},width:.2,thickness:.25,padContactLength:.45,bodyDistance:.95,height:.65})),Array.from({length:16}).map((h,d)=>De($r,{rotation:-Math.PI/2,position:{x:d*.5-3.75,y:10.5/2,z:.25/2},width:.2,thickness:.25,padContactLength:.45,bodyDistance:.95,height:.65})),De(Kg,{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})]}),smi=rmi,ami=()=>{const c=.7999999999999998;return Bn(fi,{children:[De($r,{rotation:Math.PI,position:{x:2.05/2+c/4,y:0,z:.18/2},width:.3,thickness:.18,padContactLength:.2,bodyDistance:c,height:.65}),De($r,{position:{x:-2.05/2-c/4,y:-.65,z:.18/2},width:.3,thickness:.18,padContactLength:.2,bodyDistance:c,height:.65}),De($r,{position:{x:-2.05/2-c/4,y:.65,z:.18/2},width:.3,thickness:.18,padContactLength:.2,bodyDistance:c,height:.65}),De(Kg,{center:{x:0,y:0,z:0},width:1.25,length:2,height:.9,includeNotch:!1,taperRatio:.06,straightHeightRatio:.7,heightAboveSurface:.05})]})};function Ami(t){const{pinCount:e,pitch:n,bodyWidth:o,bodyLength:i,bodyHeight:r,standoff:s,leadSpanX:a,leadSpanY:A,leadWidth:c,leadThickness:l,contactLength:g,taperInset:u}=t;for(const x of["pitch","bodyWidth","bodyLength","bodyHeight","leadSpanX","leadSpanY","leadWidth","leadThickness","contactLength"])if(!Number.isFinite(t[x])||t[x]<=0)throw new Error(`${x} must be finite and positive`);for(const[x,E]of Object.entries({standoff:s,taperInset:u}))if(!Number.isFinite(E)||E<0)throw new Error(`${x} must be finite and nonnegative`);if(!Number.isInteger(e)||e<8||e%4)throw new Error("pinCount must be divisible by four and at least eight");const h=r-s,d=Math.min(a-o,A-i)/2,m=(e/4-1)*n+c;if(h<=l*2||c>=n||m>=Math.min(o,i)-2*u||u*2>=Math.min(o,i)||g>=d)throw new Error("Invalid mold, lead spacing, or terminal reach");const p=s+h/2,_=Math.min(.002,h/100),f=Bn(JA,{children:[De(Fo,{z:s+_/2,children:De(Xt,{size:[o-2*u,i-2*u,_]})}),De(Fo,{z:p,children:De(Xt,{size:[o,i,_]})}),De(Fo,{z:r-_/2,children:De(Xt,{size:[o-2*u,i-2*u,_]})})]}),I=Math.min(o,i)*.045,C=Math.min(.04,h/10),y=(x,E)=>{const B=x%2===0,b=x<2?-1:1,Q=B?o:i,w=(B?a:A)/2,D=Q/2-Math.min(Q/8,.15),k=w-g,R=Q/2+Math.min(.08,(d-g)/4),H=[[w-_/2,l/2],[k,l/2]];for(let K=1;K<=12;K++){const Y=K/12;H.push([k+(R-k)*Y,l/2+(p-l/2)*Y*Y*(3-2*Y)])}H.push([D,p]);const G=([K,Y])=>De(Fo,{offset:{x:B?b*K:E,y:B?E:b*K,z:Y},children:De(Xt,{size:B?[_,c,l]:[c,_,l]})});return De(Jd,{children:H.slice(1).map((K,Y)=>Bn(JA,{children:[G(H[Y]),G(K)]}))})};return Bn(fi,{children:[De(zo,{color:"#353535",children:Bn(Gl,{children:[f,De(Fo,{offset:{x:-o/2+u+I*2,y:i/2-u-I*2,z:r},children:De(Qs,{radius:I,height:C*2})})]})}),De(zo,{color:"#bfc1c4",children:Array.from({length:e},(x,E)=>y(Math.floor(E/(e/4)),((e/4-1)/2-E%(e/4))*n))})]})}var cmi=({pinCount:t,pitch:e,leadWidth:n,padContactLength:o,bodyWidth:i})=>{const r=t/4;if(r!==Math.floor(r))throw new Error(`LQFP pinCount must be divisible by 4, got ${t}`);e||(e=.5),o||(o=.6),n||(n=.22),i||(i=e*(r+4));const s=i,a=(r-1)*e/2,A=s+3.3*o,c=A,l=.8,g=.2,u=(c-i)/2+.4;return Bn(fi,{children:[Array.from({length:r}).map((h,d)=>De($r,{position:{x:-c/2-.36,y:d*e-a,z:g/2},width:n,thickness:g,padContactLength:o,bodyDistance:u,height:l})),Array.from({length:r}).map((h,d)=>De($r,{rotation:Math.PI,position:{x:c/2+.36,y:d*e-a,z:g/2},width:n,thickness:g,padContactLength:o,bodyDistance:u,height:l})),Array.from({length:r}).map((h,d)=>De($r,{rotation:Math.PI/2,position:{x:d*e-a,y:-A/2-.36,z:g/2},width:n,thickness:g,padContactLength:o,bodyDistance:u,height:l})),Array.from({length:r}).map((h,d)=>De($r,{rotation:-Math.PI/2,position:{x:d*e-a,y:A/2+.36,z:g/2},width:n,thickness:g,padContactLength:o,bodyDistance:u,height:l})),De(Kg,{center:{x:0,y:0,z:0},width:i,length:s,height:1.5,heightAboveSurface:.1,taperRatio:.04,chamferSize:.7,notchPosition:{x:-(s/2-1.5),y:s/2-1.5,z:1.5},notchRadius:1.5/2})]})},lmi=t=>"leadSpanX"in t?Ami(t):cmi(t),gmi=()=>{const o=.20900000000000002,i=.1,r=.3,s=.1,a=.2;return Bn(fi,{children:[De(zo,{color:"#222",children:Bn(Jd,{children:[De(Xt,{size:[.85,1.2,o],center:[0,0,o/2]}),Bn(JA,{children:[De(Fo,{z:o,children:De(Xt,{size:[.85,1.2,.01]})}),De(Fo,{z:.38,children:De(Xt,{size:[.85-i,1.2-i,.01]})})]})]})}),De(Xt,{color:"#ccc",size:[r,.25,s],center:[.55,0,s/2]}),De(Xt,{color:"#ccc",size:[r,a,s],center:[-.55,.4,s/2]}),De(Xt,{color:"#ccc",size:[r,a,s],center:[-.55,-.4,s/2]})]})},unn=({num_pins:t,bodyWidth:e=5.3,bodyLength:n=5.3,bodyThickness:o=1,thermalPadSize:i,padWidth:r=n/5.3*.6,padLength:s=n/5.3*1,pitch:a=.5,thermalPadThickness:A=.2,bodyStyle:c="chamfered",standoff:l=0,terminalInset:g=0,terminalThickness:u=A,pin1TerminalChamfer:h=0,pin1MarkWidth:d=0})=>{if(c==="rectangular"){if(!Number.isInteger(t)||t<2||t%2!==0)throw new Error("DFN requires an even pin count of at least two");for(const f of[e,n,o,r,s,a,u])if(!Number.isFinite(f)||f<=0)throw new Error("DFN dimensions must be finite and positive");for(const f of[l,g,h,d])if(!Number.isFinite(f)||f<0)throw new Error("DFN offsets must be finite and nonnegative");if(u<=l||u>l+o||g+s>=e/2||(t/2-1)*a+r>n||t>2&&r>=a||h>=Math.min(s,r/2)||d>=e/4)throw new Error("DFN dimensions leave disconnected or overlapping terminals")}const m=[],p=Math.floor(t/2),_=a*(p-1);for(let f=0;f<t;f++){const I=f<p?"left":"right",C=f%p,y=_/2-C*a,x=s,E=r,B=I==="left"?-e/2+x/2+g:e/2-x/2-g,b=f+1;m.push({pinNumber:b,x:B,y,padSizeX:x,padSizeY:E})}if(c==="rectangular"){const f=l+o,I=Math.min(o,n)/100,C=De(Xt,{size:[d,n*.8,I],center:[-e/2+d*1.5,0,f-I/2]}),y=De(Xt,{size:[e,n,o],center:[0,0,l+o/2]});return Bn(fi,{children:[De(zo,{color:"#25272a",children:d>0?Bn(Gl,{children:[y,C]}):y}),De(zo,{color:"#c7c9cd",children:m.map(x=>x.pinNumber===1&&h>0?Bn(JA,{children:[De(Xt,{size:[s-h,r,u],center:[x.x+h/2,x.y,u/2]}),De(Xt,{size:[s,r-2*h,u],center:[x.x,x.y,u/2]})]},x.pinNumber):De(Xt,{size:[x.padSizeX,x.padSizeY,u],center:[x.x,x.y,u/2]},x.pinNumber))}),i&&De(Xt,{color:"#c7c9cd",size:[i.width,i.length,A],center:[0,0,A/2]}),d>0&&De(zo,{color:"#969997",children:C})]})}return Bn(fi,{children:[De(Kg,{center:{x:0,y:0,z:0},width:e,length:n,height:o,heightAboveSurface:0,color:"grey",chamferSize:.2,taperRatio:0,notchPosition:{x:-(e/2-s),y:n/2-s,z:o}}),m.map((f,I)=>De(Xt,{center:[f.x,f.y,A/2],size:[f.padSizeX,f.padSizeY,A]})),i?.length!==void 0&&i?.width!==void 0&&De(Xt,{center:[0,0,A/2],size:[i.width,i.length,A]})]})},umi=({bodyLength:t=10.2,bodyWidth:e=4.65,bodyHeight:n=13.46,leadSpacing:o=5,leadDiameter:i=.8,leadLength:r=12.7,color:s="#ddd",leadColor:a="#b87333"})=>{const A=t/2,c=e/2,l=A-c,g=o/2,u=.85;return Bn(fi,{children:[Bn(zo,{color:s,children:[Bn(JA,{children:[De(Fy,{height:n,roundRadius:.5,radius:c,center:[-l,0,n]}),De(Fy,{height:n,roundRadius:.5,radius:c,center:[l,0,n]})]}),Bn(JA,{children:[De(Fy,{height:u,roundRadius:.1,radius:c+.85,center:[-l,0,n/2+u/2]}),De(Fy,{height:u,roundRadius:.1,radius:c+.85,center:[l,0,n/2+u/2]})]})]}),Bn(zo,{color:a,children:[De(Qs,{height:r+n/2,radius:i/2,center:[-g+.06,0,-(r/2)+n/2]}),De(Qs,{height:r+n/2,radius:i/2,center:[g-.06,0,-(r/2)+n/2]})]})]})},dmi=({bodyLength:t=1.4,bodyDiameter:e=1.1,color:n="#3a3a3aff",contactColor:o="#c6c6c6",cathodeIdentification:i="#111"})=>Bn(fi,{children:[De(zo,{color:n,children:Bn(nc,{rotation:[0,"90deg",0],children:[De(Uf,{size:[e,e,t-.2],roundRadius:.2,center:[-e/2,0,.05]}),De(Qs,{height:.2/2,radius:e/2-.2,center:[-e/2,0,-t/2+.2/2]})]})}),De(zo,{color:i,children:De(nc,{rotation:[0,"90deg",0],children:De(Uf,{size:[e*1.01,e*1.01,t/3],roundRadius:.2,center:[-e/2,0,-t/4+.1]})})}),De(zo,{color:o,children:De(nc,{rotation:[0,"90deg",0],children:De(Fy,{height:.2,radius:e/2,roundRadius:.2/3,center:[-e/2,0,-t/2]})})}),De(zo,{color:o,children:De(nc,{rotation:[0,"90deg",0],children:De(Fy,{height:.2,radius:e/2,roundRadius:.2/3,center:[-e/2,0,t/2]})})})]}),dnn=({bodyLength:t=3.5,bodyDiameter:e=1.5,color:n="#202020",contactColor:o="#c6c6c6",bandColor:i="#f2f2f2"})=>{const s=t-.8+.04,a=(t-.4)/2,A=e/2+.02,c=.14,l=-t/2+.4+.35;return Bn(fi,{children:[De(zo,{color:n,children:De(nc,{rotation:[0,"90deg",0],children:De(Fy,{height:s,radius:e/2,roundRadius:.05,center:[-e/2,0,0]})})}),De(zo,{color:i,children:De(nc,{rotation:[0,"90deg",0],children:De(Qs,{height:c,radius:e/2+.002,center:[-e/2,0,l]})})}),De(zo,{color:o,children:De(nc,{rotation:[0,"90deg",0],children:De(Fy,{height:.4,radius:A,roundRadius:.04,center:[-e/2,0,-a]})})}),De(zo,{color:o,children:De(nc,{rotation:[0,"90deg",0],children:De(Fy,{height:.4,radius:A,roundRadius:.04,center:[-e/2,0,a]})})})]})},hmi=({bodyLength:t=3.9,bodyDiameter:e=2.5,color:n="#3a3a3aff",contactColor:o="#c6c6c6"})=>Bn(fi,{children:[De(zo,{color:n,children:De(nc,{rotation:[0,"90deg",0],children:De(Fy,{height:t,radius:e/2,roundRadius:.3,center:[-e/2,0,0]})})}),De(zo,{color:o,children:De(nc,{rotation:[0,"90deg",0],children:De(Fy,{height:.55,radius:e/2,roundRadius:.2,center:[-e/2,0,-t/2]})})}),De(zo,{color:o,children:De(nc,{rotation:[0,"90deg",0],children:De(Fy,{height:.55,radius:e/2,roundRadius:.2,center:[-e/2,0,t/2]})})})]}),mmi=({pinCount:t,padContactLength:e=.6,leadWidth:n=.41,pitch:o=1.27})=>{if(t%2!==0)throw new Error("MS012 pinCount must be even");const i=t/2,r=4.9,s=3.9,a=(i-1)*o/2,A=.2;return Bn(fi,{children:[Array.from({length:i}).map((c,l)=>De($r,{position:{x:-s/2-e-.3,y:l*o-a,z:A/2},width:n,thickness:A,padContactLength:e,bodyDistance:e+.4,height:.85})),Array.from({length:i}).map((c,l)=>De($r,{rotation:Math.PI,position:{x:s/2+e+.3,y:l*o-a,z:A/2},width:n,thickness:A,padContactLength:e,bodyDistance:e+.4,height:.85})),De(Kg,{center:{x:0,y:0,z:A/2},width:s,length:r,height:1.55,notchPosition:{x:-.95,y:r/2-1,z:1.55},heightAboveSurface:.17,taperRatio:.09})]})},pmi=({pinCount:t=16,padContactLength:e=.6,leadWidth:n=.41,pitch:o=1.27})=>{if(t!==16)throw new Error("MS013 only supports 16 pins");const i=t/2,r=7.5,s=10.3,a=(i-1)*o/2,A=.2;return Bn(fi,{children:[Array.from({length:i}).map((c,l)=>De($r,{position:{x:-r/2-e-.3,y:l*o-a,z:A/2},width:n,thickness:A,padContactLength:e,bodyDistance:e+.4,height:.85})),Array.from({length:i}).map((c,l)=>De($r,{rotation:Math.PI,position:{x:r/2+e+.3,y:l*o-a,z:A/2},width:n,thickness:A,padContactLength:e,bodyDistance:e+.4,height:.85})),De(Kg,{center:{x:0,y:0,z:A/2},width:r,length:s,height:1.1,notchPosition:{x:-2.25,y:s/2-1.5,z:1.1},heightAboveSurface:.17,taperRatio:.05})]})},_mi=[{x:-2.54,y:-1},{x:0,y:-1},{x:2.54,y:-1}],hnn=({mouldedTab:t=!1,leads:e=_mi,bodyWidth:n=10,bodyThickness:o=4.5,bodyHeight:i=9.2,tabHeight:r=6.4,tabThickness:s=1.4,mountingHoleDiameter:a=3.6,standoff:A=3,leadLength:c=3,bodyColor:l="#222",tabColor:g="#ccc",leadColor:u="#d4b106"}={})=>{const h=e.reduce((x,E)=>x+E.x,0)/e.length,d=e.reduce((x,E)=>x+E.y,0)/e.length,m=A,p=m+i,_=p+r,f=d+(o-s)/2,I=_-Math.max(a*.8,2.6),C=.8,y=.5;return Bn(fi,{children:[De(zo,{color:l,children:De(Xt,{size:[n,o,i],center:[h,d,m+i/2]})}),De(zo,{color:t?l:g,children:Bn(Gl,{children:[De(Xt,{size:[n,s,r],center:[h,f,p+r/2]}),De(nc,{rotation:["90deg",0,0],children:De(Fo,{center:[h,I,-f],children:De(Qs,{radius:a/2,height:s*3})})})]})}),e.map(x=>De(zo,{color:u,children:De(Xt,{size:[C,y,A+c],center:[x.x,x.y,(A-c)/2]})},`lead-${x.x}-${x.y}`))]})},fmi=()=>{const c=1.1999999999999997;return Bn(fi,{children:[De($r,{rotation:Math.PI,position:{x:2.8/2+c/4,y:-.95,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:c,height:.95}),De($r,{rotation:Math.PI,position:{x:2.8/2+c/4,y:0,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:c,height:.95}),De($r,{rotation:Math.PI,position:{x:2.8/2+c/4,y:.95,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:c,height:.95}),De($r,{position:{x:-2.8/2-c/4,y:0,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:c,height:.95}),De($r,{position:{x:-2.8/2-c/4,y:-.95,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:c,height:.95}),De($r,{position:{x:-2.8/2-c/4,y:.95,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:c,height:.95}),De(Kg,{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})]})},Imi=()=>Bn(fi,{children:[De(Kg,{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(c=>{const l=-.35+c*.35;return De(Xt,{center:[-.8/2+.19/2-.1,l,.12/2],size:[.19,.15,.12]})}),[0,1,2].map(c=>{const l=-.35+c*.35;return De(Xt,{center:[.8/2-.19/2+.1,l,.12/2],size:[.19,.15,.12]})})]}),Cmi=[{x:-1.27,y:.98},{x:0,y:2.25},{x:1.27,y:.98}],ymi=t=>{let e=[t[0],t[t.length-1]],n=-1;for(let o=0;o<t.length;o++)for(let i=o+1;i<t.length;i++){const r=Math.hypot(t[o].x-t[i].x,t[o].y-t[i].y);r>n&&(n=r,e=[t[o],t[i]])}return{outer:e,separation:n}},mnn=({bodyDiameter:t=4.8,bodyHeight:e=4.5,flatCut:n=1.1,leads:o=Cmi,standoff:i=1.5,leadLength:r=3,bodyColor:s="#222"}={})=>{const a=t/2,A=.4,c=.25,{outer:l,separation:g}=ymi(o),[u,h]=l,d={x:(u.x+h.x)/2,y:(u.y+h.y)/2},m=Math.max(g,.001),p={x:(h.x-u.x)/m,y:(h.y-u.y)/m},_=g/2,f=C=>{const y=(C-(o.length-1)/2)*_;return{x:d.x+p.x*y,y:d.y+p.y*y}},I=[c,A,c];return Bn(fi,{children:[De(zo,{color:s,children:Bn(Gl,{children:[De(Fo,{center:[d.x,d.y,i+e/2],children:De(Qs,{radius:a,height:e})}),De(Fo,{center:[d.x,d.y-(a-n/2),i+e/2],children:De(Xt,{size:[a*2,n,e+.2]})})]})}),o.map((C,y)=>{const x=f(y);return Bn(Fo,{center:[0,0,0],children:[Bn(JA,{children:[De(Fo,{center:[C.x,C.y,0],children:De(Xt,{size:I})}),De(Fo,{center:[x.x,x.y,i],children:De(Xt,{size:I})})]}),De(Fo,{center:[C.x,C.y,-r/2],children:De(Xt,{size:[c,A,r]})})]},`lead-${C.x}-${C.y}`)})]})},xmi=()=>Bn(fi,{children:[De($r,{rotation:Math.PI,position:{x:2/2+.75/4,y:-.65,z:.15/2},width:.25,thickness:.15,padContactLength:.3,bodyDistance:.75,height:.85}),De($r,{rotation:Math.PI,position:{x:2/2+.75/4,y:0,z:.15/2},width:.25,thickness:.15,padContactLength:.3,bodyDistance:.75,height:.85}),De($r,{rotation:Math.PI,position:{x:2/2+.75/4,y:.65,z:.15/2},width:.25,thickness:.15,padContactLength:.3,bodyDistance:.75,height:.85}),De($r,{position:{x:-2/2-.75/4,y:0,z:.15/2},width:.25,thickness:.15,padContactLength:.3,bodyDistance:.75,height:.85}),De($r,{position:{x:-2/2-.75/4,y:-.65,z:.15/2},width:.25,thickness:.15,padContactLength:.3,bodyDistance:.75,height:.85}),De($r,{position:{x:-2/2-.75/4,y:.65,z:.15/2},width:.25,thickness:.15,padContactLength:.3,bodyDistance:.75,height:.85}),De(Kg,{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})]}),Emi=xmi,Bmi=()=>Bn(fi,{children:[De(Kg,{center:{x:0,y:0,z:.05},width:1,length:1.45,height:.5,heightAboveSurface:0,color:"#1a1a1a",taperRatio:0,includeNotch:!1}),[0,1,2].map(a=>{const A=-.5+a*.5;return De(Xt,{center:[-1/2+.3/2,A,.05/2],size:[.3,.2,.05]})}),[0,1,2].map(a=>{const A=-.5+a*.5;return De(Xt,{center:[1/2-.3/2,A,.05/2],size:[.3,.2,.05]})})]}),pnn=()=>Bn(fi,{children:[De($r,{position:{x:-2.5/2,y:0,z:.175/2},width:.3,thickness:.175,padContactLength:.3,bodyDistance:.45,height:.7}),De($r,{rotation:Math.PI,position:{x:2.5/2,y:0,z:.175/2},width:.3,thickness:.175,padContactLength:.3,bodyDistance:.45,height:.7}),De(zo,{color:"#222",children:De(Kg,{center:{x:0,y:0,z:0},width:1.8,length:1.4,height:.95,includeNotch:!1,taperRatio:.06,straightHeightRatio:.7,heightAboveSurface:.05})}),De(Xt,{color:"#777",size:[1.8/3,1.4-.075,.02],center:[-.9*2/3+.035,0,.95+.05]})]}),Smi=()=>Bn(fi,{children:[De(Xt,{color:"#ccc",size:[.4,.325,.175],center:[-1.05,0,.175/2]}),De(Xt,{color:"#ccc",size:[.4,.325,.175],center:[1.05,0,.175/2]}),De(zo,{color:"#222",children:Bn(Jd,{children:[De(Fo,{z:.175/2,children:De(Xt,{size:[1.7,1.25,.175]})}),Bn(JA,{children:[De(Fo,{z:.175,children:De(Xt,{size:[1.7,1.25,.01]})}),De(Fo,{z:.725,children:De(Xt,{size:[1.7-.2,1.25-.2,.01]})})]})]})}),De(Xt,{color:"#777",size:[1.7/3,1.25-.2,.02],center:[-1.05+1.7/4.4+.2,0,.725]})]}),bmi=()=>{const s=-1.0474999999999999,a=1.775/2+.4/2-.04;return Bn(fi,{children:[De(Xt,{color:"#ccc",size:[.4,.325,.13],center:[s,0,.13/2]}),De(Xt,{color:"#ccc",size:[.4,.325,.13],center:[a,0,.13/2]}),De(zo,{color:"#222",children:De(Kg,{width:1.775,length:1.25,height:.725,center:{x:0,y:0,z:0},heightAboveSurface:0,straightHeightRatio:.7,taperRatio:.06,includeNotch:!1})}),De(Xt,{color:"#777",size:[1.775/3,1.25-.05,.02],center:[s+1.775/4.4+.2,0,.725]})]})},Qmi=({pitch:t=10})=>Bn(fi,{children:[De(Qs,{height:4,radius:.5,center:[-t/2,0,.5]}),De(DG,{radius:.5,center:[-t/2,0,2.5]}),De(Fo,{x:-2.5,y:0,z:2.5,children:Bn(nc,{rotation:[0,Math.PI/2,0],children:[De(Qs,{height:t,radius:.5,center:[0,0,2.5]}),De(zo,{color:"#d2b48c",children:De(Qs,{height:5,radius:1.3,center:[0,0,2.5]})})]})}),De(Qs,{height:4,radius:.5,center:[t/2,0,.5]}),De(DG,{radius:.5,center:[t/2,0,2.5]})]}),vmi=({bodyWidth:t=21,boardThickness:e=.5,leadWidth:n=1.6,leadLength:o=2.4,leadsPitch:i=2.54,leadsLeft:r,leadsRight:s,leadsTop:a,leadsBottom:A,innerHoles:c=!0,innerHoleEdgeDistance:l=1.61,innerHoleDiameter:g=1})=>{const u=t/2,h=e/2,d=e*1.05,m=g/2,p=Math.max(r||0,s||0,a||0,A||0)*i||51,_=[],f=[];if(s){const x=-((s-1)/2)*i;for(let E=0;E<s;E++){const B=x+E*i;_.push({x:u-o/2,y:-B,pl:o,pw:n}),c&&f.push({x:u,y:-B},{x:u-l,y:-B})}}if(r){const x=-((r-1)/2)*i;for(let E=0;E<r;E++){const B=x+E*i;_.push({x:-u+o/2,y:-B,pl:o,pw:n}),c&&f.push({x:-u,y:-B},{x:-u+l,y:-B})}}if(a){const x=-((a-1)/2)*i;for(let E=0;E<a;E++){const B=x+E*i;_.push({x:-B,y:p/2-o/2,pl:n,pw:o}),c&&f.push({x:-B,y:p/2},{x:-B,y:p/2-l})}}if(A){const x=-((A-1)/2)*i;for(let E=0;E<A;E++){const B=x+E*i;_.push({x:-B,y:-p/2+o/2,pl:n,pw:o}),c&&f.push({x:-B,y:-p/2},{x:-B,y:-p/2+l})}}const I=De(zo,{color:"#051a0a",children:Bn(Gl,{children:[De(Xt,{center:[0,0,h],size:[t,p,e]}),_.map((x,E)=>De(Xt,{center:[x.x,x.y,h],size:[x.pl+.01,x.pw+.01,d]},E))]})}),C=c&&f.map((x,E)=>De(Qs,{color:"black",center:[x.x,x.y,h],radius:m,height:e*1.07})),y=_.map((x,E)=>De(Xt,{center:[x.x,x.y,h],size:[x.pl+.01,x.pw+.01,d]}));return Bn(fi,{children:[I,De(zo,{color:"#FFD700",children:c?Bn(Gl,{children:[De(Jd,{children:_.map((x,E)=>De(Xt,{center:[x.x,x.y,h],size:[x.pl+.01,x.pw+.01,d]},E))}),C]}):y})]})},_nn=({width:t=30,height:e=22,thickness:n=1,bezelInset:o=2,bezelDepth:i=1,screenColor:r="#001414",bezelColor:s="#0f1116",screenWidth:a,screenHeight:A,offset:c})=>{const l=t,g=e,u=Math.max(n,.4),h=Math.max(Math.min(i,u),.2),d=Math.max(u-h,0),m=Math.max(o,0),p=Math.max(a??l-m*2,2),_=Math.max(A??g-m*2,2),f=Math.min(Math.max(h*.6,.2),h),I=c?.x??0,C=c?.y??0,y=c?.z??0;return Bn(Fo,{offset:{x:I,y:C,z:y},children:[d>0&&De(zo,{color:s,children:De(Xt,{size:[l,g,d],offset:[0,0,d/2]})}),De(zo,{color:s,children:Bn(Gl,{children:[De(Xt,{size:[l,g,h],offset:[0,0,d+h/2]}),De(Xt,{size:[p,_,h+.02],offset:[0,0,d+h/2]})]})}),De(zo,{color:r,children:De(Xt,{size:[p,_,f],offset:[0,0,d+f/2]})})]})},Pmi=({numPins:t=5,rows:e=1,p:n=2.54,id:o=1,od:i=1.5,boardThickness:r=1.6,width:s,height:a,pinRowSide:A="left",holes:c=[],holeInset:l=1,pinRowHoleEdgeToEdgeDist:g=2,female:u,nopin:h,screen:d,screenWidth:m,screenHeight:p,screenCenterOffsetX:_,screenCenterOffsetY:f})=>{const I=d??!1,C=r/2,y=Math.ceil(t/e);let x,E;A==="left"||A==="right"?(x=(e-1)*n+2*g,E=(y-1)*n+2*g):(E=(e-1)*n+2*g,x=(y-1)*n+2*g),t===0&&(x=10,E=10);const B=Number(s??x),b=Number(a??E),Q=[];let w=0,D=0,k=0,R=0,H=0,G=0;A==="left"||A==="right"?(w=A==="left"?-B/2+g:B/2-g,D=-((y-1)/2)*n,k=0,R=n,H=A==="left"?n:-n,G=0):(w=-((y-1)/2)*n,D=A==="top"?b/2-g:-b/2+g,k=n,R=0,H=0,G=A==="top"?-n:n);let K=0;for(let ce=0;ce<e&&K<t;ce++)for(let Ie=0;Ie<y&&K<t;Ie++){const de=w+Ie*k+ce*H,Ce=D+Ie*R+ce*G;Q.push({x:de,y:Ce}),K++}const Y=[];if(c)for(const ce of c){let Ie=0,de=0;ce==="topleft"?(Ie=-B/2+l,de=b/2-l):ce==="topright"?(Ie=B/2-l,de=b/2-l):ce==="bottomleft"?(Ie=-B/2+l,de=-b/2+l):ce==="bottomright"?(Ie=B/2-l,de=-b/2+l):ce==="center"&&(Ie=0,de=0),Y.push({x:Ie,y:de})}const X=.63,te=2,j=6,J=3,ie=h||u?0:te,oe=ie+r,ne=De(zo,{color:"#008080",children:Bn(Gl,{children:[De(Xt,{center:[0,0,C+ie],size:[B,b,r]}),Y.map((ce,Ie)=>De(Qs,{center:[ce.x,ce.y,C+ie],radius:i/2,height:r},`hole-${Ie}`)),Q.map((ce,Ie)=>De(Qs,{center:[ce.x,ce.y,C+ie],radius:i/2,height:r},`pin-hole-${Ie}`))]})}),le=Q.map((ce,Ie)=>De(zo,{color:"#FFD700",children:Bn(Gl,{children:[De(Qs,{center:[ce.x,ce.y,r/2+ie],radius:i/2,height:r}),De(Qs,{center:[ce.x,ce.y,r/2+ie],radius:o/2,height:r})]})})),ge=Q.map((ce,Ie)=>De(qtn,{x:ce.x,y:ce.y,pinThickness:X,shortSidePinLength:J,longSidePinLength:j,bodyHeight:te,flipZ:de=>de})),_e=Q.map((ce,Ie)=>De(ann,{x:ce.x,y:ce.y,flipZ:de=>-de}));return Bn(fi,{children:[ne,le,!u&&!h&&ge,u&&_e,I&&De(_nn,{width:m??B*.8,height:p??b*.6,offset:{x:_??0,y:f??0,z:oe}})]})},wmi=()=>{const s=.8999999999999999,a=-s/2+.5/2-.15,A=s/2-.5/2+.15,c=.2,l=.5*.24;return Bn(fi,{children:[De(Xt,{color:"#ccc",size:[.5,.28,.12],center:[a,0,.12/2]}),De(Xt,{color:"#ccc",size:[.5,.28,.12],center:[A,0,.12/2]}),De(zo,{color:"#222",children:Bn(Jd,{children:[De(Fo,{z:l/2,children:De(Xt,{size:[s,.6,l]})}),Bn(JA,{children:[De(Fo,{z:l,children:De(Xt,{size:[s,.6,.01]})}),De(Fo,{z:.5,children:De(Xt,{size:[s-c,.6-c,.01]})})]})]})}),De(Xt,{color:"#777",size:[1.4/6,.6-c,.02],center:[-s/4,0,.5]})]})},Mmi=wmi,Dmi=({numPins:t=7,showPins:e=!0,showFootprint:n=!0,bodyColor:o="#f5f5f5",pinColor:i="#635959"})=>{const c=3.5999999999999996,l=6,g=(t-1)*1.5+4,u=-((t-1)*1.5)/2;return Bn(fi,{children:[De(Fo,{offset:[0,0,6],children:De(nc,{angles:[Math.PI,0,0],children:De(zo,{color:o,children:Bn(Gl,{children:[De(Xt,{size:[g,3.5,6],center:[0,0,6/2]}),De(Xt,{size:[g-.5*2,3.5-.5*2,c],center:[0,0,c/2]}),De(Xt,{size:[g,3.5/3,c],center:[0,0,c/6]}),De(Xt,{size:[g-.5*2,.5/2,c],center:[0,3.5/2-.5/4,c/2]}),De(Xt,{size:[g-.5*2,.5/2,c],center:[0,-3.5/2+.5/4,c/2]}),De(Xt,{size:[1,.5+2,1],center:[-g/4,3.5/2,6/2]}),De(Xt,{size:[1,.5+3,1],center:[g/4,3.5/2,6/2]}),De(Xt,{size:[1,.5+2,1],center:[-g/4,-3.5/2,6/2]}),De(Xt,{size:[1,.5+3,1],center:[g/4,-3.5/2,6/2]})]})})})}),e&&Array.from({length:t}).map((h,d)=>De(zo,{color:i,children:De(Qs,{height:l,radius:.35,center:[u+d*1.5,0,2.5]})})),n&&Array.from({length:t}).map((h,d)=>{const m=d===0,p=m?{type:"pcb_plated_hole",pcb_plated_hole_id:`jstzh_${d}`,shape:"circular_hole_with_rect_pad",x:u+d*1.5,y:0,hole_diameter:.73,rect_pad_width:1.03,rect_pad_height:1.73,hole_shape:"circle",pad_shape:"rect",layers:["top","bottom"],port_hints:[`${d+1}`]}:{type:"pcb_plated_hole",pcb_plated_hole_id:`jstzh_${d}`,shape:"pill",x:u+d*1.5,y:0,hole_height:.73,hole_width:.73,outer_height:1.73,outer_width:1.03,layers:["top","bottom"],port_hints:[`${d+1}`]};return De(CUe,{hole:p,isPin1:m})})]})},Nmi=({numPins:t=2,showPins:e=!0,showFootprint:n=!0,bodyColor:o="#f5f5f5",pinColor:i="#635959"})=>{const c=3.5999999999999996,l=3.4,g=5.5,u=.5,h=l+g,d=(t-1)*2+3.9,m=-((t-1)*2)/2,p=1,_=1.8,f=.7,I=.8,C=.65;return Bn(fi,{children:[De(Fo,{offset:[0,0,6],children:De(nc,{angles:[Math.PI,0,0],children:De(zo,{color:o,children:Bn(Gl,{children:[De(Xt,{size:[d,4.5,6],center:[0,0,6/2]}),De(Xt,{size:[d-.5*2,4.5-.5*2,c],center:[0,0,c/2]}),De(Xt,{size:[d,4.5/3,c],center:[0,0,c/6]}),De(Xt,{size:[d-.5*2,.5/2,c],center:[0,4.5/2-.5/4,c/2]}),De(Xt,{size:[d-.5*2,.5/2,c],center:[0,-4.5/2+.5/4,c/2]}),De(Xt,{size:[p,4.5+.5,_],center:[-d/2+f,0,6/2]}),De(Xt,{size:[p,4.5+.5,_],center:[d/2-f,0,6/2]}),De(Xt,{size:[.5*3,I,C],center:[-d/2,0,C/2]}),De(Fo,{offset:[-d/2,0,C],children:De(nc,{angles:[0,Math.PI/2,0],children:De(Qs,{height:.5*3,radius:I/2})})}),De(Xt,{size:[.5*3,I,C],center:[d/2,0,C/2]}),De(Fo,{offset:[d/2,0,C],children:De(nc,{angles:[0,Math.PI/2,0],children:De(Qs,{height:.5*3,radius:I/2})})})]})})})}),e&&Array.from({length:t}).map((y,x)=>De(zo,{color:i,children:De(Xt,{size:[u,u,h],center:[m+x*2,0,(g-l)/2]})})),n&&Array.from({length:t}).map((y,x)=>{const E=x===0,B=E?{type:"pcb_plated_hole",pcb_plated_hole_id:`jstph_${x}`,shape:"circular_hole_with_rect_pad",x:m+x*2,y:0,hole_diameter:.73,rect_pad_width:1.2,rect_pad_height:1.2,hole_shape:"circle",pad_shape:"rect",layers:["top","bottom"],port_hints:[`${x+1}`]}:{type:"pcb_plated_hole",pcb_plated_hole_id:`jstph_${x}`,shape:"pill",x:m+x*2,y:0,hole_height:.73,hole_width:.73,outer_height:1.2,outer_width:1.2,layers:["top","bottom"],port_hints:[`${x+1}`]};return De(CUe,{hole:B,isPin1:E})})]})},Rmi=({numPins:t=4,showPins:e=!0,showFootprint:n=!0,bodyColor:o="#f8fafc",pinColor:i="#635959"})=>{const u=(t-1)*2.5+4.9,h=-((t-1)*2.5)/2,d=.8,m=.85+.2,p=3.5,_=u/2-1.3,f=Math.min(u-3.4,Math.max(3,(t-1)*2.5*.4+2.2)),I=2.4;return Bn(fi,{children:[De(Fo,{offset:[0,0,7/2],children:De(zo,{color:o,children:Bn(Gl,{children:[De(Xt,{size:[u,5.75,7]}),De(Fo,{offset:[0,0,(7-5.35)/2+.1],children:De(Xt,{size:[u-.85*2,5.75-.85*2,5.35+.2]})}),De(Fo,{offset:[0,-5.75/2+.85/2,7/2-I/2+.1],children:De(Xt,{size:[f,.85+.2,I+.2]})}),De(Fo,{offset:[-_,-5.75/2+.85/2,7/2-p/2+.1],children:De(Xt,{size:[d,m,p+.2]})}),De(Fo,{offset:[_,-5.75/2+.85/2,7/2-p/2+.1],children:De(Xt,{size:[d,m,p+.2]})}),Array.from({length:t}).map((C,y)=>De(Fo,{offset:[h+y*2.5,-5.75/2+.3,-7/2+.25],children:De(Xt,{size:[1,.8,.5]})},`vent_${y}`))]})})}),e&&Array.from({length:t}).map((C,y)=>De(zo,{color:i,children:De(Fo,{offset:[h+y*2.5,0,8.75/2-3.4],children:De(Xt,{size:[.64,.64,8.75]})})})),n&&(()=>{try{return X1.string(`jst${t}_xh`).circuitJson().filter(x=>x.type==="pcb_plated_hole").map((x,E)=>De(CUe,{hole:x,isPin1:E===0},`footprint_${E}`))}catch{return null}})()]})};function fnn(t){const e=X1.string(t).json();return e.fn!=="jst"?!1:!!(e.sh||e.smd&&Math.abs(Ja(e.p)-1)<.01&&Math.abs(Ja(e.mpx??0)-(e.num_pins-1+2.6))<.15&&Math.abs(Ja(e.mpy??0)-2.525)<.15)}var Tmi=({footprint:t="jst6_sh"})=>{if(!fnn(t))throw new Error("JstSh requires a named SH or matching 1mm SH top-entry footprint");const e=t.replace(/_pin1location\([^)]*\)/g,""),n=X1.string(e).json(),o=X1.string(e).circuitJson().filter(_=>_.type==="pcb_smtpad"&&_.shape==="rect"),i=X1.string(t).circuitJson().filter(_=>_.type==="pcb_smtpad"&&(_.shape==="rect"||_.shape==="rotated_rect")),r=n.num_pins;if(!Number.isInteger(r)||r<2||r>20||o.length!==r+2)throw new Error("JstSh requires 2–20 contacts and two hold-down pads");const s=o.slice(0,r),a=o.slice(r),A=Math.atan2(i[1].y-i[0].y,i[1].x-i[0].x)-Math.atan2(o[1].y-o[0].y,o[1].x-o[0].x),c=s.reduce((_,f)=>_+f.x,0)/r,l=s[0].y,g=a[0].y>l?1:-1,u=l+g*1.8,h=r+2,d=2.9,m=4.2,p=u-g*.25;return Bn(nc,{rotation:[0,0,A],children:[De(zo,{color:"#e4e1d6",children:Bn(Gl,{children:[De(Xt,{size:[h,d,m],center:[c,u,m/2+.05]}),De(Xt,{size:[h-1.3,1.8,m],center:[c,u,m/2+.8]}),a.map((_,f)=>De(Xt,{size:[.7,_.height*.8,1.5],center:[_.x,_.y,.75]},`recess-${f}`)),[-1,1].map(_=>De(Xt,{size:[.55,.6,1],center:[c+_*(h/2-.9),u+g*d/2,4]},_))]})}),Bn(zo,{color:"#c6c7c9",children:[s.map((_,f)=>{const I=_.y-g*_.height*.4;return Bn(Jd,{children:[De(Xt,{size:[.2,Math.abs(p-I)+.1,.2],center:[_.x,(p+I)/2,.1]}),De(Xt,{size:[.2,.2,3.45],center:[_.x,p,1.725]})]},f)}),a.map((_,f)=>Bn(Jd,{children:[De(Xt,{size:[.7,_.height*.75,.2],center:[_.x,_.y,.1]}),De(Xt,{size:[.2,_.height*.6,1.35],center:[_.x,_.y,.675]})]},`mount-${f}`))]})]})},kmi=([t,e],n,o,i,r)=>{const s=Math.sign(t),a=Math.sign(e),A=n/2,c=o/2,l=r?Math.min(.32,o*.36):0,g=Math.min(i,A,c),u=[[-A,-c],[A,-c],[A,c-g],[A-g,c],[-A,c]];l&&(u[0]=[-A+l,-c],u.push([-A,-c+l]));const h=u.map(([d,m])=>[t+d*s,e+m*a]);return s*a<0?h.reverse():h},OUe=({width:t,length:e,radius:n,height:o,z:i})=>{const r=t/2-n,s=e/2-n;return[[-r,-s],[r,-s],[r,s],[-r,s]].map(([a,A],c)=>De(Qs,{center:[a,A,i+o/2],height:o,radius:n}))},Fmi=({horizontalPadPitch:t=2.2,verticalPadPitch:e=1.7,padWidth:n=1.4,padHeight:o=1.2,bodyHeight:i=.7})=>{const r=t+n*.7142857142857143,s=e+o*(2/3),a=Math.min(.01,i*.02),A=n*(5/7),c=o*.75,l=i*(5/7),g=l-a,u=i*(2/35),h=r*.95,d=s*.94,m=r*.905,p=s*.9,_=r*.83,f=s*.82,I=l+u,C=Math.min(.01,i*.015),y=Math.min(.12,s*.05),x=(r-A)/2,E=(s-c)/2,B=[[-x,-E],[x,-E],[x,E],[-x,E]],b=OUe({width:h,length:d,radius:Math.min(.13,d*.08),height:u,z:l}),Q=[...OUe({width:m,length:p,radius:Math.min(.14,p*.08),height:C,z:I}),...OUe({width:_,length:f,radius:Math.min(.15,f*.09),height:C,z:i-C})];return Bn(fi,{children:[B.map((w,D)=>De(zo,{color:"#d6a258",children:De(RG,{height:a,children:De(NG,{points:kmi(w,A,c,y,D===0)})})})),De(Kg,{center:{x:0,y:0,z:a},width:r,length:s,height:g-.005,heightAboveSurface:0,color:"#34343d",taperRatio:0,straightHeightRatio:1,includeNotch:!1,chamferSize:y}),De(zo,{color:"#d2a057",children:De(JA,{children:b})}),De(zo,{color:"#b9bec2",children:De(JA,{children:Q})})]})},Lmi="#303339",yde="#1f2227",Inn="#eee8d8",Cnn="#f8f3e7",GUe="#b7bdc2",Hmi="#d2d6d9",Omi="#767d82",Gmi="#9ba1a5",Ymi=({pinCount:t=12,pitch:e=.5,padWidth:n=.3,padLength:o=1.25,staggered:i=!1,reverse:r=!1,rowPitch:s=2.4,topPadLength:a=o,bottomPadLength:A=o,mountPadPitchX:c,mountPadOffsetY:l=2.575,mountTop:g=!1,mountPadWidth:u=2,mountPadLength:h=2.5})=>{const d=Math.max((t-1)*e,e),m=-d/2,p=c??d+(i?3.5:3.38),_=l===0?0:(g?1:-1)*l,f=Array.from({length:t},(ye,Fe)=>{const Ye=i&&Fe%2===1!==r,qe=i?Ye?s/2:-s/2:0,at=Ye?a:A;return{index:Fe,x:m+Fe*e,y:qe,length:at}}),I=Math.max(...f.map(ye=>ye.y+ye.length/2)),C=Math.min(...f.map(ye=>ye.y-ye.length/2)),y=_-h/2,x=_+h/2,E=g?C:I,B=g?Math.max(x,I)+.67:Math.min(y,C)-.67,b=g?-1:1,Q=E-b*Math.max(o*.86,1.05),w=B+b*.22,D=Math.abs(Q-w),k=(Q+w)/2,R=w-b*.01,H=Math.max(d+4.9,p+u*.76),G=Math.min(H-2.3,d+1.1),K=.3,Y=1.42,X=2,te=Math.min(.92,D*.28),j=R+b*(te/2-.04),J=1.6,ie=1.1,oe=Math.max(D-.78,1.5),ne=R+b*(oe/2+.68),le=H-.72,ge=.34,_e=X-ge/2,ce=R+b*Math.min(.68,D*.22),Ie=1.48,de=Math.max(n*.82,.15),Ce=E,Pe=Math.abs(Ce-Q),Qe=(Ce+Q)/2,pe=Math.max(te*.8,.5),ve=R+b*(pe/2+.08),Me=p/2,we=.75,Oe=H/2-.04,Te=H/2-.23,Se=H/2-.32,Le=.68;return Bn(fi,{children:[[-1,1].map(ye=>De(Xt,{color:GUe,center:[ye*Me,_,.07],size:[u,h,.14]})),f.map(ye=>De(Xt,{color:GUe,center:[ye.x,Qe,.065],size:[de,Pe,.13]},`terminal:${ye.index}`)),De(Uf,{color:yde,center:[0,k,K/2],size:[H,D,K],roundRadius:.1}),De(zo,{color:Lmi,children:Bn(Gl,{children:[De(Uf,{center:[0,k,K+Y/2],size:[H-.2,D-.12,Y],roundRadius:.14}),De(Xt,{center:[0,j,ie],size:[G,te,J]}),De(Xt,{center:[0,ne,X-ge*.72],size:[le-.32,oe-.16,ge]})]})}),f.map(ye=>De(Uf,{color:Hmi,center:[ye.x,ve,K+.82],size:[de*.82,pe,.14],roundRadius:.035},`spring:${ye.index}`)),f.map(ye=>De(Xt,{color:GUe,center:[ye.x,Q-b*.03,K+.32],size:[de,.13,.62]},`terminal-rise:${ye.index}`)),De(Xt,{color:yde,center:[0,R+b*.1,K+.71],size:[G+.18,.16,.8]}),De(Uf,{color:Inn,center:[0,ne,_e],size:[le,oe,ge],roundRadius:.11}),De(Xt,{color:Cnn,center:[0,ne-b*(oe/2-.12),X-.035],size:[le-.36,.24,.07]}),[-1,1].map(ye=>De(Uf,{color:Inn,center:[ye*Se,ce,Ie],size:[Le,.92,.72],roundRadius:.1})),[-1,1].map(ye=>De(Fo,{x:ye*Se,y:ce,z:Ie,children:De(nc,{rotation:[0,Math.PI/2,0],children:De(Qs,{color:Cnn,height:Le+.12,radius:.24})})})),[-1,1].map(ye=>De(Uf,{color:Omi,center:[ye*Oe,_,we/2],size:[.17,Math.min(h*.3,.7),we],roundRadius:.04})),[-1,1].map(ye=>De(Uf,{color:Gmi,center:[ye*Te,_,we-.05],size:[.42,Math.min(h*.3,.7),.1],roundRadius:.035})),De(Xt,{color:yde,center:[0,k,.025],size:[G+.7,D*.58,.05]}),De(Xt,{color:yde,center:[0,Q-b*.06,K+.82],size:[G+.4,.15,.92]})]})},Umi=({numberOfPins:t,pitch:e=2.54,pinThickness:n=.64,bodyWidth:o=2.5,bodyHeight:i=2.54,standoffHeight:r=1.27,matingPinLength:s=5.8,tailSpan:a=5.08})=>{const A=-((t-1)*e)/2,c=r+i,l=a/2,g=n*.35;return De(fi,{children:Array.from({length:t},(u,h)=>{const d=A+h*e,m=h%2===0?1:-1,p=s-g,_=r-n/2;return Bn(Fo,{x:d,children:[De(Xt,{color:"#222",size:[e,o,i],center:[0,0,r+i/2]}),Bn(zo,{color:"#d4af37",children:[De(Xt,{size:[n,l,n],center:[0,m*(l/2),n/2]}),De(Xt,{size:[n,n,_],center:[0,0,n/2+_/2]}),De(Xt,{size:[n,n,p],center:[0,0,c+p/2]}),Bn(JA,{children:[De(Xt,{size:[n,n,.01],center:[0,0,c+p]}),De(Xt,{size:[n*.65,n*.65,.01],center:[0,0,c+s]})]})]})]})})})},fq=t=>X1.string(t).circuitJson().filter(n=>n.type==="pcb_plated_hole"&&Number.isFinite(n.x)&&Number.isFinite(n.y)).map(n=>({x:n.x,y:n.y,pin:n.port_hints?.[0]})),ynn=t=>X1.string(t).circuitJson().filter(n=>n.type==="pcb_smtpad"&&n.shape==="rect"&&Number.isFinite(n.x)&&Number.isFinite(n.y)).map(n=>({x:n.x,y:n.y,width:n.width??.4,height:n.height??.4,pin:n.port_hints?.[0]})),Kmi=({bodyWidth:t,bodyLength:e,bodyHeight:n=1,pads:o,leadThickness:i=.15,leadHeightRatio:r=.75})=>{const s=o.reduce((c,l)=>c+l.x,0)/(o.length||1),a=o.reduce((c,l)=>c+l.y,0)/(o.length||1),A=n*r;return Bn(fi,{children:[De(Kg,{center:{x:s,y:a,z:0},width:t,length:e,height:n}),o.map(c=>{const l=c.width??.4,g=c.height??.4,u=c.x>=s?1:-1,h=c.x+u*l/2,d=Math.max(Math.abs(h-s)-t/2,.1),m=Math.min(.15,t*.15);return De($r,{rotation:u>0?Math.PI:0,position:{x:h,y:c.y,z:i/2},width:g,thickness:i,padContactLength:l*.6,bodyDistance:d+m,height:A},`lead-${c.x}-${c.y}`)})]})},Vmi=({padPitch:t,padHeight:e,color:n="#333"})=>{const o=t,i=e*.85,r=i,s=o*.2,a=o-s*2;return Bn(fi,{children:[De(Xt,{size:[a,i,r],offset:[0,0,r/2],color:n}),De(Xt,{size:[s,r,i],offset:[o/2-s/2,0,r/2],color:"#ccc"}),De(Xt,{size:[s,r,i],offset:[-o/2+s/2,0,r/2],color:"#ccc"})]})},zmi=({color:t="#ffff00",bodyColor:e="#ffffff",leadColor:n="#dedede"})=>{const p=[-1.7,0,1.7],_=[-1,1];return Bn(fi,{children:[p.flatMap(f=>_.map(I=>De(Xt,{color:n,size:[1.4,1,.2],center:[I*2,f,.2/2]}))),De(zo,{color:e,children:Bn(Gl,{children:[De(Kg,{width:5,length:5,height:1.3,heightAboveSurface:.2,center:{x:0,y:0,z:0},color:e,taperRatio:.036,straightHeightRatio:.01,includeNotch:!1}),De(Qs,{radius:2,height:.25,center:[0,0,1.5-.25/2]}),De(Fo,{offset:[-5/2,5/2,1.5-.3/2+.005],children:De(nc,{rotation:[0,0,Math.PI/4],children:De(Xt,{size:[.9,.9,.3+.01]})})})]})}),De(Qs,{color:t,radius:2,height:.25,center:[0,0,1.55-.25/2]})]})},Jmi=({bodyWidth:t=3.5,bodyLength:e=2.8,bodyHeight:n=.8,color:o="#ffe08a",bodyColor:i="#f2f2f2",padColor:r="#cccccc",pad1X:s=-.9,pad1Width:a=2.2,pad2X:A=1.375,pad2Width:c=1.25,padLength:l=2.2}={})=>{const h=(s+A)/2,d=t*.55,m=e*.55;return Bn(fi,{children:[[{x:s,w:a,key:"pad-1"},{x:A,w:c,key:"pad-2"}].map(({x:p,w:_,key:f})=>De(zo,{color:r,children:De(Xt,{size:[_,l,.1],center:[p,0,.1/2]})})),De(zo,{color:i,children:De(Xt,{size:[t,e,n],center:[h,0,.1+n/2]})}),De(zo,{color:o,children:De(Xt,{size:[d,m,.15],center:[h,0,.1+n+.15/2-.05]})})]})},xnn=t=>Array.from({length:t},(e,n)=>n),Wmi=({bodyWidth:t=16.26,bodyDepth:e=15.88,bodyHeight:n=13.5,bodyCenterY:o=-.96,ledPins:i=!1,firstPinLeft:r=!1,firstPinTop:s=!1,signalPitch:a=1.02,signalRowPitch:A=1.78,signalHoleDiameter:c=.9144,shieldPinX:l=8.13,shieldPinY:g=.13,shieldHoleDiameter:u=1.8,locatorHoleX:h=6.35,locatorHoleY:d=-3.43,locatorHoleDiameter:m=3.25,ledPinX:p=4.57,ledPinPitch:_=2.29,ledPinY:f=5.7,openingDirection:I,shellColor:C="#b7bdc2",housingColor:y="#20242a",contactColor:x="#d6a928"})=>{const E=I??(o>0?1:-1),B=o+E*e/2,b=Math.min(.38,t*.024),Q=Math.max(t-2.5,t*.72),w=Math.min(n-2.4,9.6),D=1.3+w/2,k=Math.min(4.4,e*.34),R=B-E*k/2,H=B-E*(k+b*.7),G=Math.max(.22,Math.min(c*.36,.38)),K=xnn(8).map(ie=>{const oe=(3.5-ie)*a,ne=ie%2===0?-A/2:A/2;return{x:r?-oe:oe,y:s?-ne:ne}}),Y=[-p-_,-p,p,p+_],X=Q/10,te=B-E*Math.max(k*.48,1.2),j=D+w*.18,J=B+E*b*.2;return Bn(fi,{children:[Bn(zo,{color:C,children:[Bn(Gl,{children:[De(Xt,{center:[0,o,n/2],size:[t,e,n]}),De(Xt,{center:[0,R,D],size:[Q,k+b*2,w]})]}),De(Xt,{center:[0,J,.72],size:[Q+.5,b*1.25,1.05]}),[-1,1].map(ie=>De(Xt,{center:[ie*l,g,.25],size:[Math.max(u*.46,.65),Math.max(u*.72,1.1),3.4]})),[-1,1].map(ie=>De(Xt,{center:[ie*t*.24,o-E*e*.08,n+.04],size:[t*.22,e*.42,.1]}))]}),Bn(zo,{color:y,children:[Bn(Gl,{children:[De(Uf,{center:[0,R,D],size:[Q-.2,k+b*.5,w-.2],roundRadius:.22}),De(Xt,{center:[0,R-E*b*.2,D-.05],size:[Q-1.25,k+b,w-1.35]})]}),De(Xt,{center:[0,H,D],size:[Q-1.15,b,w-1.25]}),De(Uf,{center:[0,B-E*k*.28,1.55],size:[Q-2.6,k*.5,1.15],roundRadius:.16}),[-1,1].map(ie=>De(Qs,{center:[ie*h,d,-.25],radius:Math.max(m*.41,.65),height:2.7}))]}),Bn(zo,{color:x,children:[K.map(({x:ie,y:oe},ne)=>De(Qs,{center:[ie,oe,.15],radius:G,height:3.1})),xnn(8).map(ie=>De(Fo,{offset:[(ie-3.5)*X,te,j+(ie%2===0?.03:-.03)],children:De(nc,{rotation:[E*.2,0,0],children:De(Uf,{size:[Math.max(X*.28,.28),3.25,.16],roundRadius:.05})})})),i&&Y.map((ie,oe)=>De(Qs,{center:[ie,f,.15],radius:G,height:3.1}))]}),i&&Bn(fi,{children:[De(Uf,{color:"#73b744",center:[-t/2+2.05,B+E*b*.35,n-2.05],size:[2.15,b*1.55,1.45],roundRadius:.18}),De(Uf,{color:"#e0aa35",center:[t/2-2.05,B+E*b*.35,n-2.05],size:[2.15,b*1.55,1.45],roundRadius:.18})]})]})},jmi=({bodyWidth:t=6.1,bodyLength:e=6.5,bodyHeight:n=2.3,tabWidth:o=6.2,tabLength:i=5.8,span:r=6.85,pitch:s=2.29,leadWidth:a=.9,leadContactLength:A=1.5,color:c="#222",tabColor:l="#cccccc",leadColor:g="#cccccc"})=>{const h=r/2,d=-r/2,m=h+(o-t)/2,p=m-t/2,_=.5/2,f=.4;return Bn(fi,{children:[De(zo,{color:l,children:De(Xt,{size:[o,i,.5],center:[h,0,.5/2]})}),De(zo,{color:c,children:De(Xt,{size:[t,e,n],center:[m,0,.5+n/2]})}),[-1,1].map(I=>Bn(zo,{color:g,children:[De(Xt,{size:[A,a,f],center:[d+A/2,I*s,f/2]}),Bn(JA,{children:[De(Xt,{size:[.1,a,f],center:[d+A,I*s,f/2]}),De(Xt,{size:[.1,a,f],center:[p,I*s,_+.5/2]})]})]},`lead-${I}`))]})},Xmi=({diameter:t=6.3,heightToDiameterRatio:e=1.4,height:n=t*e,leadPitch:o=2.5,leadDiameter:i=.6,leadLength:r=3,sleeveColor:s="#1b2a6b",baseColor:a="#1a1a1a"})=>{const A=t/2,c=Math.min(1,t*.12),l=Math.max(n-c,.1),g=c,u=g+l,h=Math.max(t*.06,.2),d=.3;return Bn(fi,{children:[De(zo,{color:a,children:De(Qs,{radius:A-.05,height:c,center:[0,0,c/2]})}),De(zo,{color:s,children:Bn(Gl,{children:[De(Fy,{radius:A,height:l,roundRadius:Math.min(.3,A*.15),center:[0,0,g+l/2]}),De(Xt,{size:[t,h,d*2],center:[0,0,u]}),De(Xt,{size:[h,t,d*2],center:[0,0,u]})]})}),[-1,1].map(m=>De(zo,{color:"#c0c0c0",children:De(Qs,{radius:i/2,height:r+c,center:[m*o/2,0,(c-r)/2]})}))]})},qmi=({bodyWidth:t=5.35,bodyLength:e=14,bodyHeight:n=4,bodyCenterX:o=t/2,adjusterDiameter:i=Math.min(t,e)*.55,shaftDiameter:r=0,shaftHeight:s=0,leads:a=[],leadDiameter:A=.6,leadLength:c=3,bodyColor:l="#1f4fa3",adjusterColor:g="#d8d8d8"})=>{const h=n+.4,d=Math.max(i*.16,.3);return Bn(fi,{children:[De(zo,{color:l,children:De(Xt,{size:[t,e,n],center:[o,0,n/2]})}),De(zo,{color:g,children:Bn(Gl,{children:[De(Qs,{radius:i/2,height:.8,center:[o,0,h]}),De(Xt,{size:[i,d,.8*.6],center:[o,0,h+.8/2]})]})}),s>0&&r>0?De(zo,{color:g,children:De(Qs,{radius:r/2,height:s,center:[o,0,n+s/2]})}):null,a.map(m=>De(zo,{color:"#c0c0c0",children:De(Qs,{radius:A/2,height:n/2+c,center:[m.x,m.y,(n/2-c)/2]})},`lead-${m.x}-${m.y}`))]})},$mi=({bodyWidth:t=2.9,bodyLength:e=3,bodyHeight:n=1.4,actuatorDiameter:o=1.5,actuatorHeight:i=.5,padSpanX:r=4.2,padSpanY:s=2.15,padWidth:a=1.05,padLength:A=.7,bodyColor:c="#2b2b2b",actuatorColor:l="#d9d9d9",leadColor:g="#cccccc"})=>Bn(fi,{children:[De(zo,{color:c,children:De(Xt,{size:[t,e,n],center:[0,0,n/2]})}),De(zo,{color:l,children:De(Qs,{radius:o/2,height:i,center:[0,0,n+i/2]})}),[-1,1].flatMap(h=>[-1,1].map(d=>De(zo,{color:g,children:De(Xt,{size:[a,A,.15],center:[h*r/2,d*s/2,.15/2]})})))]}),Zmi=({footprint:t="smdslideswitch7",position:e=0})=>{const n=t.replace(/_pin1location\([^)]*\)/g,""),o=X1.string(n).json(),i=X1.string(n).circuitJson(),r=i.filter(u=>u.type==="pcb_smtpad"&&u.shape==="rect"),s=X1.string(t).circuitJson().filter(u=>u.type==="pcb_smtpad"&&(u.shape==="rect"||u.shape==="rotated_rect"));if(r.length<7||!Number.isFinite(o.mpx)||o.mpx<3)throw new Error("SmdSlideSwitch needs signal pads and four mounting pads");const a=Math.atan2(s[1].y-s[0].y,s[1].x-s[0].x)-Math.atan2(r[1].y-r[0].y,r[1].x-r[0].x),A=o.mpx-.5,c=2.7,l=o.mpx>6?1.5:1.4,g=o.mounty;return Bn(nc,{rotation:[0,0,a],children:[De(zo,{color:"#aeb4ba",children:Bn(Gl,{children:[De(Xt,{size:[A,c,l],center:[0,g,l/2]}),De(Xt,{size:[A-.3,c-.3,l],center:[0,g,l/2-.15]}),De(Xt,{size:[2.7,.5,.9],center:[0,g-c/2,.65]})]})}),Bn(zo,{color:"#28292c",children:[De(Xt,{size:[A-.32,c-.32,.35],center:[0,g,.175]}),De(Xt,{size:[1,2.25,.65],center:[e===0?-.5:.5,g-1.5,.65]}),i.filter(u=>u.type==="pcb_hole").map((u,h)=>"hole_diameter"in u&&"x"in u?De(Qs,{radius:u.hole_diameter*.42,height:.6,center:[u.x,u.y,-.2]}):null)]}),De(zo,{color:"#c6c7c9",children:r.map((u,h)=>{const d=h<r.length-4,m=u.y+u.height*.4,p=Math.min(u.y-u.height*.4,g+c/2-.2);return De(Xt,{size:[u.width*.8,d?m-p:u.height*.8,.18],center:[u.x,d?(m+p)/2:u.y,.09]},h)})})]})},epi=({fullWidth:t=1.94,fullLength:e=1.6})=>Bn(fi,{children:[De(nc,{rotation:[45*Math.PI,0,0],children:De(Fo,{center:[0,0,-.4],children:De(zo,{color:"grey",children:De(Xt,{size:[1.2,1.6,.55]})})})}),[-1,0,1].flatMap((l,g)=>[De(Fo,{center:[-1.2/2-.03,l*.5,.13/2],children:De(Xt,{size:[.67,.3,.13]})}),De(Fo,{center:[1.2/2+.03,l*.5,.13/2],children:De(Xt,{size:[.67,.3,.13]})})])]}),tpi=({packageWidth:t=10,packageLength:e=10,packageHeight:n=1.2,standoffHeight:o=.2,ballPitch:i=.8,ballDiameter:r=.5,ballRows:s=8,ballColumns:a=8,missingBalls:A=[],footprintString:c})=>{const l=n-o,g=o+l/2,u=Math.max(o/2,r/2),h=c?X1.string(c).circuitJson():null;return Bn(fi,{children:[De(Fo,{z:g,children:De(zo,{color:"#555",children:De(Xt,{size:[t,e,l]})})}),!c&&Array.from({length:s*a}).map((d,m)=>{if(A.includes(m+1))return null;const p=Math.floor(m/a),f=(m%a-(a-1)/2)*i,I=(p-(s-1)/2)*i;return De(Fo,{x:f,y:I,z:u,children:De(DG,{radius:r/2})})}),h&&h.map((d,m)=>d.type==="pcb_smtpad"?De(Fo,{x:d.x,y:d.y,z:u,children:De(DG,{radius:r/2})}):null)]})},Enn=({width:t,height:e,depth:n})=>De(JA,{children:[-1,1].map(o=>De(Fo,{offset:[o*(t-e)/2,0,0],children:De(nc,{rotation:[Math.PI/2,0,0],children:De(Qs,{radius:e/2,height:n})})},o))}),npi=({footprint:t="usbcmidmount16"})=>{const e=t.replace(/_pin1location\([^)]*\)/g,""),n=X1.string(e).json(),o=X1.string(e).circuitJson(),i=o.filter(C=>C.type==="pcb_smtpad"&&C.shape==="rect"),r=o.filter(C=>C.type==="pcb_plated_hole"),s=o.filter(C=>C.type==="pcb_hole"),a=X1.string(t).circuitJson().find(C=>C.type==="pcb_plated_hole"),A=r[0],c=A&&a&&"x"in a?Math.atan2(a.y,a.x)-Math.atan2(A.y,A.x):0,l=8.94,g=3.2,u=.22,h=n.rowy+.23,d=-n.bodybottom,m=h-d,p=(h+d)/2,_=1.65;if(!Number.isFinite(m)||m<3||r.length!==4)throw new Error("UsbCMidmount requires four mounting slots and a positive body depth");const f=-.9,I=_+.1;return Bn(nc,{rotation:[0,0,c],children:[De(zo,{color:"#b8bdc4",children:De(Fo,{offset:[0,p,_],children:Bn(Gl,{children:[De(Enn,{width:l,height:g,depth:m}),De(Enn,{width:l-u*2,height:g-u*2,depth:m+.2})]})})}),Bn(zo,{color:"#242529",children:[De(Xt,{size:[6.65,m-1.1,.7],center:[0,p+.3,_]}),De(Xt,{size:[7.6,1,2.45],center:[0,h-.65,_]}),s.map((C,y)=>"x"in C&&"hole_diameter"in C?De(Qs,{radius:C.hole_diameter*.42,height:.8,center:[C.x,C.y,-.3]}):null)]}),Bn(zo,{color:"#d3ad57",children:[[-1,1].flatMap(C=>[-2.75,-2.25,-1.25,-.25,.25,1.25,2.25,2.75].map(y=>De(Xt,{size:[.24,m-2,.04],center:[y,p+.1,_+C*.365]}))),i.map((C,y)=>De(Xt,{size:[Math.min(C.width*.7,.35),C.height*.8+.35,.15],center:[C.x,C.y-.175,.075]}))]}),De(zo,{color:"#b8bdc4",children:r.map((C,y)=>De(Xt,{size:[.4,"hole_height"in C?Math.max(.3,C.hole_height-.2):1,I-f],center:[C.x,C.y,(I+f)/2]},y))})]})},Bnn=t=>X1.string(t).circuitJson().filter(e=>e.type==="pcb_smtpad"&&(e.shape==="rect"||e.shape==="rotated_rect")).map(e=>({x:e.x,y:e.y,pin:e.port_hints?.[0]})),opi=({footprint:t="sot143"})=>{const e=Bnn(t);if(e.length!==4)throw new Error("SOT143 requires four signal pads");const n=Bnn("sot143"),o=X1.string(t).json(),i=n[1],r=e.find(A=>A.pin==="2"),s=o.pin1location?Math.round((Math.atan2(r.y,r.x)-Math.atan2(i.y,i.x))/(Math.PI/2))*(Math.PI/2):0,a=e.map(A=>({...A,x:A.x*Math.cos(s)+A.y*Math.sin(s),y:-A.x*Math.sin(s)+A.y*Math.cos(s)}));return Bn(nc,{rotation:[0,0,s],children:[De(Kg,{width:2.9,length:1.3,height:.95,heightAboveSurface:.05,center:{x:0,y:0,z:0},includeNotch:!1,taperRatio:.06}),a.map(A=>{const c=A.y<0?-1:1,l=A.pin==="1"?.83:.43;return De($r,{width:l,thickness:.12,height:.45,padContactLength:.3,bodyDistance:.6,rotation:c<0?Math.PI/2:-Math.PI/2,position:{x:A.x,y:c*1.15,z:.06}},A.pin)})]})},ipi=16/9,rpi=40,RS=1e-6,W_=(t,e)=>{if(!Number.isFinite(e)||e<=0)throw new Error(`${t} must be a finite number greater than zero`)},spi=t=>{if(t===void 0)return ipi;if(typeof t=="number")return W_("aspectRatio",t),t;if(typeof t!="string"){const[i,r]=t;return W_("aspectRatio width",i),W_("aspectRatio height",r),i/r}const e=t.split(":");if(e.length!==2)throw new Error('aspectRatio must look like "16:9"');const n=Number(e[0]),o=Number(e[1]);return W_("aspectRatio width",n),W_("aspectRatio height",o),n/o},api=({width:t,height:e,diagonal:n,aspectRatio:o,ratio:i,defaultDiagonal:r=rpi})=>{const s=spi(o??i);t!==void 0&&W_("width",t),e!==void 0&&W_("height",e),n!==void 0&&W_("diagonal",n),W_("defaultDiagonal",r);let a,A;if(t!==void 0&&e!==void 0)a=t,A=e;else if(n!==void 0&&t!==void 0){if(t>=n)throw new Error("width must be smaller than diagonal");a=t,A=Math.sqrt(n**2-t**2)}else if(n!==void 0&&e!==void 0){if(e>=n)throw new Error("height must be smaller than diagonal");a=Math.sqrt(n**2-e**2),A=e}else t!==void 0?(a=t,A=t/s):e!==void 0?(a=e*s,A=e):(A=(n??r)/Math.sqrt(s**2+1),a=A*s);return{width:a,height:A,diagonal:Math.hypot(a,A),aspectRatio:a/A}},Api=t=>{const e=[["sitsFlat",t.sitsFlat],["sitsFlatBelowBoard",t.sitsFlatBelowBoard],["foldedToFaceAboveBoard",t.foldedToFaceAboveBoard],["foldedToFaceBelowBoard",t.foldedToFaceBelowBoard],["foldedToFaceAboveBoard",t.foldsAboveBoard],["foldedToFaceBelowBoard",t.foldsBelowBoard],["foldedToRightAngleAboveBoard",t.foldedToRightAngleAboveBoard],["foldedToRightAngleBelowBoard",t.foldedToRightAngleBelowBoard]].filter(n=>n[1]);if(e.length>1)throw new Error("Only one FlexScreen boolean orientation shortcut can be true");return e[0]?.[0]??t.orientation??"sitsFlat"},cpi=(t,e)=>Math.hypot(e[0]-t[0],e[1]-t[1],e[2]-t[2]),lpi=(t,e,n)=>[t[0]+(e[0]-t[0])*n,t[1]+(e[1]-t[1])*n,t[2]+(e[2]-t[2])*n],YUe=t=>{const e=[0];for(let n=1;n<t.length;n+=1)e.push(e[n-1]+cpi(t[n-1],t[n]));return e},Snn=(t,e,n)=>{if(n<=0)return t[0];const o=e.at(-1);if(n>=o)return t.at(-1);for(let i=1;i<t.length;i+=1)if(e[i]>=n){const r=e[i-1],s=e[i]-r;return lpi(t[i-1],t[i],(n-r)/s)}return t.at(-1)},xde=(t,e,n)=>{const o=YUe(t),i=o.at(-1),r=Math.max(0,Math.min(e,i)),s=Math.max(r,Math.min(n,i)),a=[Snn(t,o,r)];for(let A=1;A<t.length-1;A+=1)o[A]>r&&o[A]<s&&a.push(t[A]);return a.push(Snn(t,o,s)),a},gpi=(t,e)=>[t,[t[0],t[1]+e,t[2]]],upi=({start:t,endZ:e,flexCableLength:n,foldDistanceFromConnector:o,foldOutset:i,foldSegments:r})=>{const s=[t],a=[t[0],t[1]+o,t[2]];o>RS&&s.push(a);for(let l=1;l<=r;l+=1){const g=Math.PI*l/r;s.push([t[0],a[1]+i*Math.sin(g),t[2]+(e-t[2])*(1-Math.cos(g))/2])}const A=YUe(s).at(-1);if(A>n+RS)throw new Error(`flexCableLength must be at least ${A.toFixed(2)} for this 180-degree fold`);const c=Math.max(0,n-A);if(c>RS){const l=s.at(-1);s.push([l[0],l[1]-c,l[2]])}return s},dpi=({start:t,flexCableLength:e,bendRadius:n,bendSegments:o,verticalLead:i,direction:r})=>{const s=2*o*Math.sin(Math.PI/(4*o)),a=Math.min(n,e/s),A=a*s,c=Math.max(0,e-A),l=Math.min(i,c*.45),g=c-l,u=[t];g>RS&&u.push([t[0],t[1]+g,t[2]]);for(let h=1;h<=o;h+=1){const d=Math.PI/2*h/o;u.push([t[0],t[1]+g+a*Math.sin(d),t[2]+r*a*(1-Math.cos(d))])}if(l>RS){const h=u.at(-1);u.push([h[0],h[1],h[2]+r*l])}return u},Iq=({points:t,width:e,thickness:n,color:o,acrossOffset:i=0,normalOffset:r=0,overlap:s=.03})=>De(zo,{color:o,children:t.slice(1).map((a,A)=>{const c=t[A],l=a[0]-c[0],g=a[1]-c[1],u=a[2]-c[2],h=Math.hypot(l,g,u);if(h<RS)return null;const d=Math.asin(u/h),m=Math.atan2(-l,g),p=[(c[0]+a[0])/2,(c[1]+a[1])/2,(c[2]+a[2])/2],_=Math.max(.001,Math.min(e,n,h)/2-.001);return De(Fo,{offset:p,children:De(nc,{rotation:[d,0,m],children:De(Uf,{size:[e,h+s,n],center:[i,0,r],roundRadius:_})})},`${A}:${p.join(":")}`)})}),hpi=t=>{const{width:e,height:n,diagonal:o,aspectRatio:i,ratio:r,defaultDiagonal:s,screenThickness:a=1.2,bezelInset:A=2,bezelDepth:c=.65,activeAreaWidth:l,activeAreaHeight:g,screenColor:u="#071b24",bezelColor:h="#15181d",showScreen:d=!0,flexCableLength:m=28,flexCableThickness:p=.18,flexCableColor:_="#d79528",conductorCount:f=8,conductorPitch:I,conductorWidth:C,conductorThickness:y=.035,conductorColor:x="#8c4a18",cableEdgeMargin:E=.6,exposedContactLength:B=2.4,showConductors:b=!0,showFlexCable:Q=!0,showStiffeners:w=!0,stiffenerLength:D=3,stiffenerThickness:k=.16,stiffenerColor:R="#416bb3",bendRadius:H=3,bendSegments:G=10,rightAngleVerticalLead:K=3,distanceAboveBoard:Y=7,distanceBelowBoard:X=7,foldDistanceFromConnector:te=7,foldOutset:j=4,foldSegments:J=18,screenGap:ie=.08,boardTopZ:oe=0,boardThickness:ne=1.6,boardClearance:le=.15,cableStartX:ge=0,cableStartY:_e=0,cableStartZ:ce,cableLateralOffset:Ie=0,screenOffset:de,screenRotation:Ce,rotation:Pe=[0,0,0],offset:Qe}=t,pe=api({width:e,height:n,diagonal:o,aspectRatio:i,ratio:r,defaultDiagonal:s}),ve=Api(t),Me=ve==="sitsFlatBelowBoard"||ve==="foldedToFaceBelowBoard"||ve==="foldedToRightAngleBelowBoard",we=ve==="foldedToFaceAboveBoard"||ve==="foldedToFaceBelowBoard",Oe=ve==="foldedToRightAngleAboveBoard"||ve==="foldedToRightAngleBelowBoard";if(W_("screenThickness",a),W_("flexCableLength",m),W_("flexCableThickness",p),W_("conductorThickness",y),W_("bendRadius",H),W_("foldOutset",j),W_("boardThickness",ne),w&&W_("stiffenerThickness",k),!Number.isInteger(f)||f<1)throw new Error("conductorCount must be a positive integer");if(!Number.isInteger(G)||G<2)throw new Error("bendSegments must be an integer of at least 2");if(!Number.isInteger(J)||J<4)throw new Error("foldSegments must be an integer of at least 4");if(le<0||ie<0||E<0||B<0||D<0||K<0||Y<0||X<0||te<0)throw new Error("clearances, margins, contact lengths, and lead lengths cannot be negative");const Te=t.flexCableWidth??Math.min(12,Math.max(5,pe.width*.3));W_("flexCableWidth",Te);const Se=Te-E*2;if(Se<=0)throw new Error("cableEdgeMargin leaves no usable flex cable width");const Le=I??(f===1?0:Se/f);if(f>1&&(!Number.isFinite(Le)||Le<=0))throw new Error("conductorPitch must be greater than zero");const ye=C??(f===1?Math.min(Se,Te*.45):Le*.48);if(W_("conductorWidth",ye),(f-1)*Le+ye>Se+RS)throw new Error("conductorPitch and conductorWidth do not fit inside the flex cable margins");const qe=Me&&!we?oe-ne-le-p/2:oe+le+p/2,at=[ge+Ie,_e,ce??qe],rt=Me?-1:1,We=ve==="foldedToFaceAboveBoard"?oe+Y:oe-ne-X,nt=ve==="foldedToFaceAboveBoard"?We-ie-p/2:We+ie+p/2,xt=we?upi({start:at,endZ:nt,flexCableLength:m,foldDistanceFromConnector:te,foldOutset:j,foldSegments:J}):Oe?dpi({start:at,flexCableLength:m,bendRadius:H,bendSegments:G,verticalLead:K,direction:rt}):gpi(at,m),It=YUe(xt).at(-1),Tt=Math.min(Math.max(0,B),It/2),Ft=Math.min(Math.max(0,D),It/2),Ct=xde(xt,0,Tt),Jt=xde(xt,It-Tt,It),Cn=xde(xt,0,Ft),Be=xde(xt,It-Ft,It),Ze=xt.at(-1);let _t,ut;ve==="sitsFlat"?(_t=[0,0,0],ut=[Ze[0],Ze[1]+pe.height/2,Ze[2]+p/2+ie]):ve==="sitsFlatBelowBoard"?(_t=[0,Math.PI,0],ut=[Ze[0],Ze[1]+pe.height/2,Ze[2]-p/2-ie]):ve==="foldedToFaceAboveBoard"?(_t=[0,0,0],ut=[Ze[0],Ze[1]-pe.height/2,We]):ve==="foldedToFaceBelowBoard"?(_t=[0,Math.PI,0],ut=[Ze[0],Ze[1]-pe.height/2,We]):ve==="foldedToRightAngleAboveBoard"?(_t=[Math.PI/2,0,0],ut=[Ze[0],Ze[1]-p/2-ie,Ze[2]+pe.height/2]):(_t=[-Math.PI/2,0,0],ut=[Ze[0],Ze[1]+p/2+ie,Ze[2]-pe.height/2]),ut=[ut[0]+(de?.x??0),ut[1]+(de?.y??0),ut[2]+(de?.z??0)];const $e=Array.from({length:f},(st,ht)=>f===1?0:(ht-(f-1)/2)*Le),pt=(p+y)/2,bt=-(p+k)/2,tt=Bn(fi,{children:[Q&&De(Iq,{points:xt,width:Te,thickness:p,color:_}),Q&&w&&Ft>RS&&Bn(fi,{children:[De(Iq,{points:Cn,width:Te,thickness:k,color:R,normalOffset:bt}),De(Iq,{points:Be,width:Te,thickness:k,color:R,normalOffset:bt})]}),Q&&b&&Tt>RS&&$e.map((st,ht)=>Bn(fi,{children:[De(Iq,{points:Ct,width:ye,thickness:y,color:x,acrossOffset:st,normalOffset:pt}),De(Iq,{points:Jt,width:ye,thickness:y,color:x,acrossOffset:st,normalOffset:pt})]},`conductor:${ht}`)),d&&De(Fo,{offset:ut,children:De(nc,{rotation:Ce??_t,children:De(_nn,{width:pe.width,height:pe.height,thickness:a,bezelInset:A,bezelDepth:c,screenWidth:l,screenHeight:g,screenColor:u,bezelColor:h})})})]});return De(Fo,{offset:{x:Qe?.x??0,y:Qe?.y??0,z:Qe?.z??0},children:De(Fo,{offset:at,children:De(nc,{rotation:Pe,children:De(Fo,{offset:[-at[0],-at[1],-at[2]],children:tt})})})})},mpi=({footprint:t})=>{const e=fUe.string(t.split("_",1)[0]).params().fn;if(fUe.getModelNames().includes(e)){const A=fUe.string(t).json();if(A.fn==="flexscreen"){const{fn:c,...l}=A;return De(hpi,{...l})}}let n=t;if(t.startsWith("jstzh1_5mm")){const A=t.match(/jstzh1_5mm(\d+)?/);n=`zh${A&&A[1]?A[1]:"7"}`}else if(t.startsWith("jstph2_0mm")){const A=t.match(/jstph2_0mm(\d+)?/);n=`jst${A&&A[1]?A[1]:"2"}_ph`}else if(t.startsWith("jstxh2_5mm")){const A=t.match(/jstxh2_5mm(\d+)?/);n=`jst${A&&A[1]?A[1]:"2"}_xh`}const o=X1.string(n).json(),i=t.match(/_color\(([^)]+)\)/),r=i?i[1]:void 0,s=(A,c)=>{if(A==null)return c;const l=Ja(A);return Number.isFinite(l)?l:c},a=hhi(o);if(a)return a;switch(o.fn){case"crystal":return De(Fmi,{horizontalPadPitch:o.px,verticalPadPitch:o.py,padWidth:o.pw,padHeight:o.ph});case"dip":return De(Ihi,{numPins:o.num_pins,pitch:o.p,bodyWidth:o.w});case"axial":return De(Qmi,{pitch:o.p});case"tssop":return De(xhi,{pinCount:o.num_pins,leadLength:o.pl,leadWidth:o.pw,pitch:o.p,bodyWidth:o.w});case"msop":return De(Bhi,{pinCount:o.num_pins,padContactLength:o.pl,leadWidth:o.pw,pitch:o.p,bodyWidth:o.w});case"vssop":return De(jhi,{pinCount:o.num_pins,leadLength:o.pl,leadWidth:o.pw,pitch:o.p,bodyWidth:o.w,bodyLength:o.h});case"qfp":return De(Xtn,{pinCount:o.num_pins,pitch:o.p,leadWidth:o.pw,padContactLength:o.pl,bodyWidth:o.w});case"tqfp":return De(smi,{});case"lqfp":return De(lmi,{pinCount:o.num_pins});case"qfn":{const A=typeof o.thermalpad?.x=="number"&&typeof o.thermalpad?.y=="number";return De(Ztn,{num_pins:o.num_pins,bodyWidth:o.w,bodyLength:o.h,pitch:o.p,padLength:o.pl,padWidth:o.pw,thermalPadSize:A?{width:o.thermalpad.x,length:o.thermalpad.y}:void 0})}case"dfn":{const A=typeof o.thermalpad?.x=="number"&&typeof o.thermalpad?.y=="number";return De(unn,{num_pins:o.num_pins,bodyWidth:o.w,bodyLength:o.h,pitch:o.p,padLength:o.pl,padWidth:o.pw,thermalPadSize:A?{width:o.thermalpad.x,length:o.thermalpad.y}:void 0})}case"pinrow":{const A=t.match(/_rows(\d+)/),c=A&&A[1]?parseInt(A[1],10):1;if(o.male)return De($tn,{numberOfPins:o.num_pins,pitch:o.p,invert:o.invert,rows:c,smd:o.smd||o.surface_mount,rightangle:o.rightangle});if(o.female)return De(Vhi,{numberOfPins:o.num_pins,pitch:o.p,rows:c})}case"smdpinheader":return De(Umi,{numberOfPins:o.num_pins,pitch:o.p,bodyWidth:o.bh});case"led5050":return De(zmi,{color:r});case"cap":{switch(o.imperial){case"0402":return De(Jtn,{color:"#856c4d"});case"0603":return De(Wtn,{color:"#856c4d"});case"0805":return De(jtn,{color:"#856c4d"});case"0201":return De(tnn,{color:"#856c4d"});case"01005":return De(nnn,{color:"#856c4d"});case"1206":return De(onn,{color:"#856c4d"});case"1210":return De(inn,{color:"#856c4d"});case"2010":return De(rnn,{color:"#856c4d"});case"2512":return De(snn,{color:"#856c4d"})}break}case"sot23":switch(o.num_pins){case 3:return De(Fhi,{color:r});case 5:return De(enn,{})}break;case"sot25":return De(enn,{});case"sot":case"sot343":{const A=o.fn==="sot343";return De(Kmi,{pads:ynn(n),bodyWidth:A?1.25:1.6,bodyLength:A?2:2.9,bodyHeight:A?1.1:1.3})}case"sot563":return De(epi,{});case"sot89":{const A=s(o.w,4.2);return De(gnn,{fullWidth:A,bodyWidth:A*.6,bodyLength:s(o.h,4.8)*.94,bodyHeight:1.5,leadWidth:s(o.pw,.48),tabLeadWidth:s(o.pw,.48)*2,padPitch:s(o.p,1.5),leadHeight:.66})}case"sot457":return De(fmi,{});case"smdslideswitch":return De(Zmi,{footprint:n});case"usbcmidmount":return De(npi,{footprint:n});case"sot143":return De(opi,{footprint:n});case"sot223":return De(gnn,{});case"sot23w":return De(Lhi,{});case"sot323":return De(ami,{});case"sod323f":return De(Smi,{});case"sod323fl":return De(bmi,{});case"sot363":return De(Emi,{});case"sot886":return De(Bmi,{});case"sot963":return De(Imi,{});case"pushbutton":return De(zhi,{width:o.w,length:o.h,innerDiameter:o.id});case"jst":if(fnn(n))return De(Tmi,{footprint:n});if(o.zh)return De(Dmi,{numPins:o.num_pins});if(o.ph)return De(Nmi,{numPins:o.num_pins});if(o.xh)return De(Rmi,{numPins:o.num_pins});break;case"fpc":return De(Ymi,{pinCount:o.num_pins,pitch:o.p,padWidth:o.pw,padLength:o.pl,staggered:o.staggered,reverse:o.reverse,rowPitch:o.py,topPadLength:o.toppl,bottomPadLength:o.bottompl,mountPadPitchX:o.mpx,mountPadOffsetY:o.mpy,mountTop:o.mounttop,mountPadWidth:o.mpw,mountPadLength:o.mpl});case"rj45":return De(Wmi,{bodyWidth:o.w,bodyDepth:o.h,bodyCenterY:o.bodyy,ledPins:o.ledpins||o.num_pins===14,firstPinLeft:o.firstpinleft,firstPinTop:o.firstpintop,signalPitch:o.p,signalRowPitch:o.py,signalHoleDiameter:o.id,shieldPinX:o.shieldx,shieldPinY:o.shieldy,shieldHoleDiameter:o.shieldid,locatorHoleX:o.holex,locatorHoleY:o.holey,locatorHoleDiameter:o.holed,ledPinX:o.ledx,ledPinPitch:o.ledp,ledPinY:o.ledy});case"soic":case"sop8":case"ssop":return De(Whi,{pinCount:o.num_pins,leadLength:o.pl,leadWidth:o.pw,pitch:o.p,bodyWidth:o.w});case"son":case"wson":case"vson":{const A=o.fn==="vson"?s(o.grid?.x,3):s(o.w,3),c=o.fn==="vson"?s(o.grid?.y,3):s(o.h,3),l=s(o.epw,0),g=s(o.eph,0),u=o.pl!==void 0?s(o.pl,0):void 0,h=o.pw!==void 0?s(o.pw,0):void 0,d=ynn(n).filter(f=>Number(f.pin??0)<=o.num_pins),m=f=>new Set(f.map(I=>I.toFixed(3))).size,p=d.length>2&&m(d.map(f=>f.y))===2&&m(d.map(f=>f.x))>2,_=De(unn,{num_pins:o.num_pins,bodyWidth:p?c:A,bodyLength:p?A:c,pitch:s(o.p,.5),padLength:u,padWidth:h,thermalPadSize:o.ep&&l>0&&g>0?{width:p?g:l,length:p?l:g}:void 0});return p?De(nc,{rotation:[0,0,"90deg"],children:_}):_}case"mlp":case"lga":case"quad":return o.legsoutside?De(Xtn,{pinCount:o.num_pins,pitch:s(o.p,.5),leadWidth:s(o.pw,.25),padContactLength:s(o.pl,.25),bodyWidth:s(o.w,6)}):De(Ztn,{num_pins:o.num_pins,bodyWidth:s(o.w,6),bodyLength:s(o.h,6),pitch:s(o.p,.5),padLength:s(o.pl,.25),padWidth:s(o.pw,.25)});case"bga":{const A=s(o.p,.8),c=o.grid?.x??8,l=o.grid?.y??8;return De(tpi,{ballPitch:A,ballColumns:c,ballRows:l,ballDiameter:A*.625,packageWidth:c*A,packageLength:l*A})}case"sod523":return De(Xhi,{});case"sod723":return De(Mmi,{});case"sod882":return De(Ann,{});case"sma":return De(qhi,{});case"smb":return De(cnn,{});case"smc":return De($hi,{});case"smf":return De(Zhi,{});case"sod123":return De(nmi,{});case"sod123f":return De(emi,{});case"sod123fl":return De(tmi,{});case"sod123w":return De(lnn,{});case"sod110":return De(lnn,{bodyWidth:2.1,bodyLength:1.4});case"sod128":return De(omi,{});case"sod323":return De(pnn,{});case"sod323w":return De(pnn,{});case"sod80":return De(dnn,{});case"sod882d":return De(Ann,{});case"smbf":return De(cnn,{});case"led2835":return De(Jmi,{color:r,bodyWidth:s(o.w,3.5),bodyLength:s(o.h,2.8),pad1X:s(o.p1x,-.9),pad1Width:s(o.p1w,2.2),pad2X:s(o.p2x,1.375),pad2Width:s(o.p2w,1.25),padLength:s(o.ph,2.2)});case"electrolytic":case"radial":{const A=s(o.p,2.5),c=t.match(/_d([\d.]+)/),l=o.d!==void 0?s(o.d,A*2):c?Number(c[1]):A*2;return De(Xmi,{diameter:l,leadPitch:A})}case"potentiometer":return De(qmi,{bodyWidth:s(o.w,5.35),bodyLength:s(o.ca,14),bodyHeight:s(o.h,4),leads:fq(n)});case"smdpushbutton":return De($mi,{padSpanX:s(o.px,4.2),padSpanY:s(o.py,2.15),padWidth:s(o.pw,1.05),padLength:s(o.ph,.7)});case"breakoutheaders":{const A=s(o.p,2.54),c=s(o.w,10)/2,l=[{x:-c,pins:o.left??0,key:"left"},{x:c,pins:o.right??0,key:"right"}];return De(fi,{children:l.filter(({pins:g})=>g>0).map(({x:g,pins:u,key:h})=>De(Fo,{center:[g,0,0],children:De(nc,{rotation:[0,0,"90deg"],children:De($tn,{numberOfPins:u,pitch:A})})},h))})}case"sod923":return De(imi,{});case"hc49":return De(umi,{});case"micromelf":return De(dmi,{});case"minimelf":return De(dnn,{});case"melf":return De(hmi,{});case"ms012":return De(mmi,{pinCount:o.num_pins,padContactLength:o.pl,leadWidth:o.pw,pitch:o.p});case"ms013":return De(pmi,{pinCount:o.num_pins,padContactLength:o.pl,leadWidth:o.pw,pitch:o.p});case"sot723":return De(gmi,{});case"to220":return De(hnn,{leads:fq(n)});case"to220f":return De(hnn,{mouldedTab:!0,leads:fq(n)});case"to92":return De(mnn,{leads:fq(n)});case"to92l":case"to92s":{const A=s(o.w,4.8),c=s(o.h,4),l=Math.max(A,c);return De(mnn,{bodyDiameter:l,flatCut:Math.max(l-Math.min(A,c),.4),leads:fq(n)})}case"to252":case"dpak":case"to263":case"d2pak":{const A=o.fn==="to263"||o.fn==="d2pak",c=s(o.tabw,A?8.38:6.2),l=Math.min(s(o.tabh,A?10:5.8),A?10:6.5);return De(jmi,{bodyWidth:c,bodyLength:s(o.w,A?10.1:6.6),bodyHeight:A?4.4:2.3,tabWidth:c,tabLength:l,span:s(o.span,A?10.21:6.85),pitch:s(o.p,A?2.54:2.29),leadWidth:s(o.pw,1.5),leadContactLength:s(o.pl,3)})}case"stampboard":case"stampreceiver":return De(vmi,{bodyWidth:o.w,leadsLeft:o.left,leadsRight:o.right,leadsTop:o.top,leadsBottom:o.bottom,leadsPitch:o.p,leadWidth:o.pw,leadLength:o.pl,innerHoles:o.innerhole,innerHoleEdgeDistance:o.innerholeedgedistance});case"mountedpcbmodule":{const A=o.rows??1,c=o.pinRowSide??"left",l=o.holeInset,g=o.width,u=o.height,h=o.pinrow,d=o.pinRowHoleEdgeToEdgeDist,m=Array.isArray(o.holes)?o.holes:[];return De(Pmi,{numPins:h,rows:A,p:o.p,id:o.id,od:o.od,width:g,height:u,pinRowSide:c,holes:m,holeInset:l,pinRowHoleEdgeToEdgeDist:d,nopin:o.nopin,female:o.female,screen:o.screen,screenWidth:o.screenwidth,screenHeight:o.screenheight,screenCenterOffsetX:o.screencenteroffsetx,screenCenterOffsetY:o.screencenteroffsety})}}switch(o.imperial){case"0402":return De(Jtn,{color:r});case"0603":return De(Wtn,{color:r});case"0805":return De(jtn,{color:r});case"0201":return De(tnn,{color:r});case"01005":return De(nnn,{color:r});case"1206":return De(onn,{color:r});case"1210":return De(inn,{color:r});case"2010":return De(rnn,{color:r});case"2512":return De(snn,{color:r})}if((o.fn==="res"||o.fn==="cap")&&o.p!==void 0&&o.ph!==void 0){const A=Ja(o.p),c=Ja(o.ph);if(Number.isFinite(A)&&Number.isFinite(c))return De(Vmi,{padPitch:A,padHeight:c,color:r??(o.fn==="cap"?"#856c4d":void 0)})}return null},ppi=t=>t&&typeof t=="object"&&"type"in t,VG=t=>{if(typeof t=="number")return t;if(typeof t=="string"){const e=/^(-?\d+(?:\.\d+)?)\s*deg$/i.exec(t);if(e)return parseFloat(e[1])*Math.PI/180;const n=Number(t);if(!Number.isNaN(n))return n}return 0},_pi=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 o7(t,e,n){const{jscad:{primitives:o,booleans:i,hulls:r,geometries:s,extrusions:a,transforms:A}}=n;if(t==null||t===!1)return[];if(Array.isArray(t))return t.flatMap(u=>o7(u,e,n));if(!ppi(t))return[];const{type:c,props:l,children:g}=t;if(c===Ktn)return(g??[]).flatMap(u=>o7(u,e,n));if(c===zo){const u=l?.color;return(g??[]).flatMap(h=>o7(h,u??e,n))}if(c===Fo){const u=_pi(l?.offset??l?.center??{x:l?.x,y:l?.y,z:l?.z});return(g??[]).flatMap(d=>o7(d,e,n)).map(({geom:d,color:m})=>({geom:A.translate(u,d),color:m??e}))}if(c===nc){const u=l?.angles??l?.rotation,h=Array.isArray(u)?[VG(u[0]),VG(u[1]),VG(u[2])]:[VG(l?.x??0),VG(l?.y??0),VG(l?.z??0)];return(g??[]).flatMap(m=>o7(m,e,n)).map(({geom:m,color:p})=>({geom:A.rotateZ(h[2],A.rotateY(h[1],A.rotateX(h[0],m))),color:p}))}if(c===Jd||c===Gl||c===JA){const u=(g??[]).flatMap(d=>o7(d,e,n)).map(d=>d.geom);if(u.length===0)return[];let h;return c===Jd?h=i.union(u):c===Gl?h=i.subtract(u[0],u.slice(1)):h=r.hull(u),[{geom:h,color:e}]}if(c===NG){const u=l?.points??[];return[{geom:s.geom2.fromPoints(u),color:e??l?.color}]}if(c===RG){const u=(g??[]).flatMap(p=>o7(p,e,n)).map(p=>p.geom);if(u.length===0)return[];const h=u.length>1?i.union(u):u[0],d=l?.height??l?.h??1;let m=a.extrudeLinear({height:d},h);if(m.polygons)for(const p of m.polygons)!p.plane||!p.vertices||p.vertices.length<3||p.vertices.reverse();return[{geom:m,color:e??l?.color}]}if(c===Xt||c===Vtn||c===Qs||c===DG||c===Uf||c===Fy){let u;if(c===Xt){const h=l?.size??[1,1,1],d=l?.offset,m=l?.center??(d?[d[0],d[1],d[2]]:[0,0,0]);u=o.cuboid({size:h,center:m})}else if(c===Vtn){const h=l?.size??1,d=l?.offset,m=l?.center??(d?[d[0],d[1],d[2]]:[0,0,0]);u=o.cube({size:h,center:m})}else if(c===Qs){const h=l?.height??1,d=l?.radius??1,m=l?.center??[0,0,0];u=o.cylinder({height:h,radius:d,center:m})}else if(c===DG){const h=l?.radius??1,d=l?.center??[0,0,0];u=o.sphere({radius:h,center:d})}else if(c===Fy){const h=l?.height??1,d=l?.radius??1,m=l?.roundRadius??.1,p=l?.center??[0,0,0];u=o.roundedCylinder({height:h,radius:d,roundRadius:m,center:p})}else{const h=l?.size??[1,1,1],d=l?.roundRadius??.1,m=l?.center??[0,0,0];u=o.roundedCuboid({size:h,roundRadius:d,center:m})}return[{geom:u,color:e??l?.color}]}if(typeof c=="function"){const u=c(l??{});return o7(u,e,n)}return(g??[]).flatMap(u=>o7(u,e,n))}function fpi(t,e){return{geometries:o7(t,void 0,{jscad:e})}}function bnn(t){if(t.polygons){const e=[],n=[],o=[];let i=0;for(const s of t.polygons){for(const A of s.vertices)A.index=i,e.push(A[0],A[1],A[2]),t.color&&t.color.length>=3?o.push(t.color[0],t.color[1],t.color[2]):o.push(1,1,1),i++;const a=s.vertices[0].index;for(let A=2;A<s.vertices.length;A++){const c=s.vertices[A-1].index,l=s.vertices[A].index;n.push(a,c,l)}}const r=new o0;if(r.setAttribute("position",new Ug(new Float32Array(e),3)),r.setIndex(n),o.length>0&&r.setAttribute("color",new Ug(new Float32Array(o),3)),t.transforms){const s=new xa;s.fromArray(t.transforms),r.applyMatrix4(s)}return r.computeVertexNormals(),r}if(t.sides){const e=[],n=[];for(const i of t.sides)e.push(i[0][0],i[0][1],0),t.color&&t.color.length>=3?n.push(t.color[0],t.color[1],t.color[2]):n.push(1,1,1);const o=new o0;if(o.setAttribute("position",new Ug(new Float32Array(e),3)),n.length>0&&o.setAttribute("color",new Ug(new Float32Array(n),3)),t.transforms){const i=new xa;i.fromArray(t.transforms),o.applyMatrix4(i)}return o}return console.error("Invalid CSG object: neither polygons nor sides found"),new o0}function Ipi(t,e){const n=IUe(mpi,{footprint:t});return fpi(n,e)}var Cpi=i0(Ade()),Qnn=ee.createContext(null),ypi=()=>{const t=ee.useContext(Qnn);if(!t)throw new Error("useHover must be used within a HoverProvider");return t},xpi=({children:t})=>{const{camera:e,renderer:n}=j1(),[o,i]=ee.useState([]),r=ee.useMemo(()=>new _Wo,[]),s=ee.useMemo(()=>new jo,[]),a=ee.useRef(o);a.current=o;const A=ee.useRef(null),c=ee.useCallback(d=>{i(m=>[...m,d])},[]),l=ee.useCallback(d=>{if(A.current){let m=!1,p=A.current.object;for(;p;){if(p===d){m=!0;break}p=p.parent}m&&(A.current.onUnhover(),A.current=null)}i(m=>m.filter(p=>p.object!==d))},[]),g=ee.useCallback(d=>{let m=d;for(;m;){const p=a.current.find(_=>_.object===m);if(p)return p;m=m.parent}},[]),u=ee.useCallback(d=>{if(!n.domElement)return;const m=n.domElement.getBoundingClientRect();s.x=(d.clientX-m.left)/m.width*2-1,s.y=-((d.clientY-m.top)/m.height)*2+1,r.setFromCamera(s,e);const p=a.current.map(f=>f.object);if(p.length===0){A.current&&(A.current.onUnhover(),A.current=null);return}const _=r.intersectObjects(p,!0);if(_.length>0){const f=_[0],I=g(f.object);if(I){const C={mousePosition:[f.point.x,f.point.y,f.point.z]};A.current!==I?(A.current?.onUnhover(),I.onHover(C),A.current=I):I.onHover(C)}else A.current&&(A.current.onUnhover(),A.current=null)}else A.current&&(A.current.onUnhover(),A.current=null)},[e,n,r,s,g]);ee.useEffect(()=>{const d=n.domElement;return d.addEventListener("mousemove",u),()=>{d.removeEventListener("mousemove",u)}},[n,u]);const h=ee.useMemo(()=>({addHoverable:c,removeHoverable:l}),[c,l]);return U.jsx(Qnn.Provider,{value:h,children:t})},Epi=({children:t,object:e,onHover:n,onUnhover:o,isHovered:i})=>{const{addHoverable:r,removeHoverable:s}=ypi();return ee.useEffect(()=>e?(r({object:e,onHover:n,onUnhover:o}),()=>{s(e)}):void 0,[e,n,o,r,s]),U.jsx(U.Fragment,{children:t})},Cq=Epi,vB=(t,{castShadow:e=!0,receiveShadow:n=!0}={})=>{t.traverse(o=>{o instanceof Dr&&(o.castShadow=e,o.receiveShadow=n)})},Bpi=({positionOffset:t,footprint:e,rotationOffset:n,onHover:o,onUnhover:i,isHovered:r,scale:s,isTranslucent:a=!1})=>{const{rootObject:A}=j1(),c=ee.useMemo(()=>{if(!e)return null;const{geometries:l}=Ipi(e,Cpi),g=new Mh;for(const u of l.flat(1/0)){const h=u.geom;if(!h||!h.polygons&&!h.sides)continue;const d=new Yi(u.color);d.convertLinearToSRGB();const m={...h,color:[d.r,d.g,d.b]},p=bnn(m),_=new fg({vertexColors:!0,side:G_,transparent:a,opacity:a?.5:1,depthWrite:!a}),f=new Dr(p,_);f.renderOrder=a?2:1,vB(f,{castShadow:!a,receiveShadow:!0}),g.add(f)}return g},[e,a]);return ee.useEffect(()=>{if(!(!c||!A))return A.add(c),()=>{A.remove(c)}},[A,c]),ee.useEffect(()=>{c&&(t&&c.position.fromArray(t),n&&c.rotation.fromArray(n),s!==void 0&&c.scale.setScalar(s))},[c,t?.[0],t?.[1],t?.[2],n?.[0],n?.[1],n?.[2],s]),ee.useEffect(()=>{c&&c.traverse(l=>{l instanceof Dr&&l.material instanceof fg&&(r?(l.material.emissive.setHex(255),l.material.emissiveIntensity=.2):l.material.emissiveIntensity=0)})},[r,c]),c?U.jsx(Cq,{isHovered:r,onHover:o,onUnhover:i,object:c}):null},vnn=new WeakMap,Spi=()=>{const t=new Qu;return t.name="fallback-environment-map",t.mapping=_ge,t},bpi=t=>{if(!t)return null;const e=t,n=vnn.get(e);if(n)return n;let o;if(t instanceof jge){const i=new iNe(t);o=i.fromScene(GWo(),.04).texture,i.dispose()}else o=Spi();return vnn.set(e,o),o};function Qpi(t){const e=new _x;let n=!1;t.updateWorldMatrix(!0,!1);const o=t.parent?t.parent.matrixWorld.clone().invert():new xa;return t.traverse(i=>{if(i.updateWorldMatrix(!0,!1),i instanceof Dr&&i.geometry&&(i.geometry.boundingBox||i.geometry.computeBoundingBox(),i.geometry.boundingBox)){const r=o.clone().multiply(i.matrixWorld),s=i.geometry.boundingBox.clone();s.applyMatrix4(r),n?e.union(s):(e.copy(s),n=!0)}}),n?e:null}function vpi(t){const e=Qpi(t);return e?e.getSize(new jt):new jt}function Ppi(t,e,n="contain_within_bounds"){if(!e)return[1,1,1];const o=vpi(t),i=[o.x>0?e[0]/o.x:1,o.y>0?e[1]/o.y:1,o.z>0?e[2]/o.z:1];if(n==="fill_bounds")return i;const r=Math.min(...i);return[r,r,r]}var UUe=({model:t,position:e,rotation:n,modelOffset:o=[0,0,0],modelRotation:i=[0,0,0],sourceCoordinateTransform:r,modelSize:s,modelFitMode:a="contain_within_bounds",scale:A})=>{const{rootObject:c}=j1(),l=ee.useMemo(()=>new Mh,[]),g=ee.useMemo(()=>new Mh,[]),u=ee.useMemo(()=>new Mh,[]),h=ee.useMemo(()=>new Mh,[]);return ee.useEffect(()=>(l.add(g),()=>{l.remove(g)}),[l,g]),ee.useEffect(()=>(g.add(u),()=>{g.remove(u)}),[g,u]),ee.useEffect(()=>(u.add(h),()=>{u.remove(h)}),[u,h]),ee.useEffect(()=>{for(;h.children.length>0;){const d=h.children[0];if(!d)break;h.remove(d)}t&&h.add(t)},[h,t]),ee.useEffect(()=>{if(!r){h.matrixAutoUpdate=!0,h.position.set(0,0,0),h.rotation.set(0,0,0),h.scale.set(1,1,1),h.updateMatrix();return}h.matrixAutoUpdate=!1,h.matrix.copy(r),h.matrixWorldNeedsUpdate=!0},[h,r]),ee.useEffect(()=>{if(c)return c.add(l),()=>{c.remove(l)}},[c,l]),ee.useEffect(()=>{if(e?l.position.fromArray(e):l.position.set(0,0,0),n?l.rotation.fromArray(n):l.rotation.set(0,0,0),u.position.fromArray(o),u.rotation.fromArray(i),u.scale.setScalar(A??1),!t){g.scale.set(1,1,1);return}g.scale.set(1,1,1),g.updateWorldMatrix(!0,!0);const d=Ppi(u,s,a);g.scale.set(d[0],d[1],d[2])},[l,g,t,a,o,h,u,i,s,e,n,A]),{boardTransformGroup:l}},Pnn=1.25;function wnn({gltfUrl:t,position:e,rotation:n,modelOffset:o=[0,0,0],modelRotation:i=[0,0,0],sourceCoordinateTransform:r,modelSize:s,modelFitMode:a="contain_within_bounds",onHover:A,onUnhover:c,isHovered:l,scale:g,isTranslucent:u=!1}){const{renderer:h}=j1(),[d,m]=ee.useState(null),[p,_]=ee.useState(null),{boardTransformGroup:f}=UUe({model:d,position:e,rotation:n,modelOffset:o,modelRotation:i,sourceCoordinateTransform:r,modelSize:s,modelFitMode:a,scale:g});if(ee.useEffect(()=>{if(!t)return;const I=new UWo;let C=!0;return I.load(t,y=>{if(!C)return;const x=y.scene;x.traverse(E=>{if(E instanceof Dr&&E.material){const B=b=>{b.transparent=u,b.opacity=u?.5:1,b.depthWrite=!u,b.needsUpdate=!0};Array.isArray(E.material)?E.material.forEach(B):B(E.material),E.renderOrder=u?2:1}}),vB(x,{castShadow:!u,receiveShadow:!0}),m(x)},void 0,y=>{if(!C)return;console.error(`An error happened loading ${t}`,y);const x=y instanceof Error?y:new Error(`Failed to load glTF model from ${t}`);_(x)}),()=>{C=!1}},[t,u]),ee.useEffect(()=>{if(!d||!h)return;const I=bpi(h);if(!I)return;const C=[],y=x=>{x instanceof fg&&(C.push({material:x,envMap:x.envMap??null,envMapIntensity:x.envMapIntensity??1}),x.envMap=I,(typeof x.envMapIntensity!="number"||x.envMapIntensity<Pnn)&&(x.envMapIntensity=Pnn),x.needsUpdate=!0)};return d.traverse(x=>{if(!(x instanceof Dr))return;const E=x.material;Array.isArray(E)?E.forEach(y):E&&y(E)}),()=>{C.forEach(({material:x,envMap:E,envMapIntensity:B})=>{x.envMap=E,x.envMapIntensity=B,x.needsUpdate=!0})}},[d,h]),ee.useEffect(()=>{d&&d.traverse(I=>{if(!(I instanceof Dr))return;const C=Array.isArray(I.material)?I.material:[I.material];for(const y of C)y instanceof fg&&(l?(y.emissive.setHex(255),y.emissiveIntensity=.2):y.emissiveIntensity=0)})},[l,d]),p)throw p;return d?U.jsx(Cq,{isHovered:l,onHover:A,onUnhover:c,object:f}):null}var wpi=i0(ttn()),Mpi=i0(Ade()),Dpi=({jscadPlan:t,positionOffset:e,rotationOffset:n,modelOffset:o=[0,0,0],modelRotation:i=[0,0,0],sourceCoordinateTransform:r,modelSize:s,modelFitMode:a="contain_within_bounds",onHover:A,onUnhover:c,isHovered:l,scale:g,isTranslucent:u=!1})=>{const{threeGeom:h,material:d}=ee.useMemo(()=>{const _=(0,wpi.executeJscadOperations)(Mpi.default,t);if(!_||!_.polygons&&!_.sides)return{threeGeom:null,material:null};const f=bnn(_),I=new fg({vertexColors:!0,side:G_,transparent:u,opacity:u?.5:1,depthWrite:!u});return{threeGeom:f,material:I}},[t,u]),m=ee.useMemo(()=>{if(!h)return null;const _=new Dr(h,d);return _.renderOrder=u?2:1,vB(_,{castShadow:!u,receiveShadow:!0}),_},[h,d,u]),{boardTransformGroup:p}=UUe({model:m,position:e,rotation:n,modelOffset:o,modelRotation:i,sourceCoordinateTransform:r,modelSize:s,modelFitMode:a,scale:g});return ee.useEffect(()=>{if(d)if(l){const _=new Yi(d.color.getHex());d.emissive.copy(_),d.emissive.setRGB(0,0,1),d.emissiveIntensity=.2}else d.emissiveIntensity=0},[l,d]),h?U.jsx(Cq,{isHovered:l,onHover:A,onUnhover:c,object:p}):null};function Npi(t){return t.replace(/(DEF|USE)\s+([^\s]+)/g,(e,n,o)=>`${n} ${o.replace(/-/g,"_")}`)}async function Rpi(t){const e=await fetch(t);if(!e.ok)throw new Error(`Failed to fetch "${t}": ${e.status} ${e.statusText}`);const n=await e.text();return new vjo().parse(Npi(n),t)}typeof window<"u"&&!window.TSCIRCUIT_OBJ_LOADER_CACHE&&(window.TSCIRCUIT_OBJ_LOADER_CACHE=new Map);function Tpi(t){const[e,n]=ee.useState(null);return ee.useEffect(()=>{if(!t)return;const o=t.replace(/&cachebust_origin=$/,""),i=window.TSCIRCUIT_OBJ_LOADER_CACHE;let r=!1;async function s(){try{if(o.endsWith(".wrl"))return await Rpi(o);const A=await fetch(o);if(!A.ok)throw new Error(`Failed to fetch "${o}": ${A.status} ${A.statusText}`);const c=await A.text(),l=c.match(/newmtl[\s\S]*?endmtl/g),g=new Fjo;if(l?.length){const u=l.join(`
5307
- `).replace(/^d\s+0\./gm,"d 1."),h=c.replace(/newmtl[\s\S]*?endmtl/g,"").replace(/^mtllib.*/gm,""),d=new Sjo;d.setMaterialOptions({invertTrProperty:!0});const m=d.parse(u,"embedded.mtl");return g.setMaterials(m),g.parse(h)}return g.parse(c.replace(/^mtllib.*/gm,""))}catch(A){return A}}function a(){if(i.has(o)){const c=i.get(o);return c.result?Promise.resolve(c.result.clone()):c.promise.then(l=>l instanceof Error?l:l.clone())}const A=s().then(c=>(c instanceof Error||i.set(o,{...i.get(o),result:c}),c));return i.set(o,{promise:A,result:null}),A}return a().then(A=>{r||n(A)}).catch(A=>{console.error(A)}),()=>{r=!0}},[t]),e}function kpi({url:t,position:e,rotation:n,modelOffset:o=[0,0,0],modelRotation:i=[0,0,0],sourceCoordinateTransform:r,modelSize:s,modelFitMode:a="contain_within_bounds",onHover:A,onUnhover:c,isHovered:l,scale:g,isTranslucent:u=!1}){const h=Tpi(t),d=ee.useMemo(()=>{if(h&&!(h instanceof Error))return h.traverse(_=>{if(_ instanceof Dr&&_.material){const f=I=>{I.transparent=u,I.opacity=u?.5:1,I.depthWrite=!u,I.needsUpdate=!0};Array.isArray(_.material)?_.material.forEach(f):f(_.material),_.renderOrder=u?2:1}}),vB(h,{castShadow:!u,receiveShadow:!0}),h;const p=new Dr(new Ix(.5,.5,.5),new fg({transparent:!0,color:"red",opacity:.25}));return vB(p,{castShadow:!1,receiveShadow:!0}),p},[h,u]),{boardTransformGroup:m}=UUe({model:d,position:Array.isArray(e)?e:e?[e.x,e.y,e.z]:void 0,rotation:Array.isArray(n)?n:n?[n.x,n.y,n.z]:void 0,modelOffset:o,modelRotation:i,sourceCoordinateTransform:r,modelSize:s,modelFitMode:a,scale:g});if(h instanceof Error)throw h;return U.jsx(Cq,{isHovered:l,onHover:A,onUnhover:c,object:m})}var Fpi=new Yi(.82,.82,.82),Mnn=t=>new fg({color:t?new Yi(t[0],t[1],t[2]):Fpi});function Lpi(t,e){const n=Mnn(e.color),o=e.brep_faces??[];if(o.length===0)return[n];const i=o.length>1?[...o].sort((g,u)=>g.first-u.first):o,r=[n],s=new Map,a=e.index.array.length/3;let A=0,c=0;const l=g=>{if(!g)return 0;const u=g.join(","),h=s.get(u);if(h!==void 0)return h;const d=r.length;return r.push(Mnn(g)),s.set(u,d),d};for(;A<a;){const g=i[c];let u=a,h=0;g&&(A<g.first?u=g.first:(u=g.last+1,h=l(g.color),c+=1)),u>A&&t.addGroup(A*3,(u-A)*3,h),A=u}return r}function Hpi(t){const e=new Mh;for(const n of t){const o=n.attributes.position?.array??[],i=n.index?.array??[];if(!o.length||!i.length)continue;const r=new o0;r.setAttribute("position",new Ns(o,3));const s=n.attributes.normal?.array??[];s.length?r.setAttribute("normal",new Ns(s,3)):r.computeVertexNormals(),r.setIndex(i),r.clearGroups();const a=Lpi(r,n),A=new Dr(r,a.length>1?a:a[0]);A.name=n.name,e.add(A)}return e}var KUe,Opi="https://cdn.jsdelivr.net/npm/occt-import-js@0.0.23/dist";function Gpi(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 Ypi(){if(!KUe){const t=await import("https://cdn.jsdelivr.net/npm/occt-import-js@0.0.23/+esm");KUe=Gpi(t)({locateFile:n=>`${Opi}/${n}`})}return KUe}async function Upi(t){const e=await fetch(t);if(!e.ok)throw new Error(`Failed to fetch STEP file: ${e.statusText}`);const n=await e.arrayBuffer(),i=(await Ypi()).ReadStepFile(new Uint8Array(n),null);if(!i.success||!i.meshes.length)throw new Error("occt-import-js failed to convert STEP file");const r=Hpi(i.meshes),s=new GNe;return await new Promise((A,c)=>{s.parse(r,l=>{l instanceof ArrayBuffer?A(l):c(new Error("GLTFExporter did not return binary output"))},l=>{c(l)},{binary:!0})})}var Dnn="step-glb-cache:v2:";function Kpi(t){const e=new Uint8Array(t),n=32768;let o="";for(let i=0;i<e.length;i+=n){const r=e.subarray(i,i+n);o+=String.fromCharCode(...r)}return btoa(o)}function Vpi(t){const e=atob(t),n=new Uint8Array(e.length);for(let o=0;o<e.length;o+=1)n[o]=e.charCodeAt(o);return n.buffer}function zpi(t){try{const e=localStorage.getItem(`${Dnn}${t}`);return e?Vpi(e):null}catch(e){return console.warn("Failed to read STEP GLB cache",e),null}}function Nnn(t,e){try{const n=Kpi(e);localStorage.setItem(`${Dnn}${t}`,n)}catch(n){console.warn("Failed to write STEP GLB cache",n)}}function Jpi(){const t=globalThis;return t.stepUrlToGltfModelConversions||(t.stepUrlToGltfModelConversions={inProgress:new Map,completed:new Map}),t.stepUrlToGltfModelConversions}var Wpi=({stepUrl:t,position:e,rotation:n,modelOffset:o,modelRotation:i,sourceCoordinateTransform:r,modelSize:s,modelFitMode:a,scale:A,onHover:c,onUnhover:l,isHovered:g,isTranslucent:u})=>{const[h,d]=ee.useState(null);return ee.useEffect(()=>{let m=!0,p=null,_=!0;const f=Jpi(),I=zpi(t);if(I){const x={arrayBuffer:I,blobUrl:URL.createObjectURL(new Blob([I],{type:"model/gltf-binary"}))};return f.completed.set(t,x),p=x.blobUrl,_=!1,d(x.blobUrl),()=>{m=!1,p&&_&&URL.revokeObjectURL(p)}}const C=f.completed.get(t);if(C)return p=C.blobUrl,_=!1,d(C.blobUrl),Nnn(t,C.arrayBuffer),()=>{m=!1,p&&_&&URL.revokeObjectURL(p)};let y=f.inProgress.get(t);return y||(y=Upi(t).then(x=>{const E={arrayBuffer:x,blobUrl:URL.createObjectURL(new Blob([x],{type:"model/gltf-binary"}))};return f.completed.set(t,E),f.inProgress.delete(t),E}).catch(x=>{throw f.inProgress.delete(t),x}),f.inProgress.set(t,y)),y.then(x=>{m&&(p=x.blobUrl,_=!1,d(x.blobUrl),Nnn(t,x.arrayBuffer))}).catch(x=>{console.error("Failed to convert STEP file to GLB",x),m&&d(null)}),()=>{m=!1,p&&_&&URL.revokeObjectURL(p)}},[t]),h?U.jsx(wnn,{gltfUrl:h,position:e,rotation:n,modelOffset:o,modelRotation:i,sourceCoordinateTransform:r,modelSize:s,modelFitMode:a,scale:A,onHover:c,onUnhover:l,isHovered:g,isTranslucent:u}):null};function Ede(t,e){let{x:n,y:o,z:i}=t;if(e.axisMapping){const r={x:n,y:o,z:i};e.axisMapping.x&&(n=VUe(r,e.axisMapping.x)),e.axisMapping.y&&(o=VUe(r,e.axisMapping.y)),e.axisMapping.z&&(i=VUe(r,e.axisMapping.z))}if(n*=e.flipX??1,o*=e.flipY??1,i*=e.flipZ??1,e.rotation){if(e.rotation.x){const r=e.rotation.x*Math.PI/180,s=Math.cos(r),a=Math.sin(r),A=o*s-i*a,c=o*a+i*s;o=A,i=c}if(e.rotation.y){const r=e.rotation.y*Math.PI/180,s=Math.cos(r),a=Math.sin(r),A=n*s+i*a,c=-n*a+i*s;n=A,i=c}if(e.rotation.z){const r=e.rotation.z*Math.PI/180,s=Math.cos(r),a=Math.sin(r),A=n*s-o*a,c=n*a+o*s;n=A,o=c}}return{x:n,y:o,z:i}}function VUe(t,e){switch(e){case"x":return t.x;case"y":return t.y;case"z":return t.z;case"-x":return-t.x;case"-y":return-t.y;case"-z":return-t.z;default:return 0}}var zUe={STEP_INVERTED:{axisMapping:{x:"-x",y:"z",z:"-y"}},Z_UP_TO_Y_UP_USB_FIX:{axisMapping:{x:"x",y:"-z",z:"y"},flipZ:-1},FOOTPRINTER_MODEL_TRANSFORM:{axisMapping:{x:"x",y:"-z",z:"y"},flipX:-1,rotation:{x:180,y:180}}};function jpi(t,e){if(e.coordinateTransform)return e.coordinateTransform;if(!e.usingGlbCoordinates){if(e.hasFootprinterModel)return zUe.FOOTPRINTER_MODEL_TRANSFORM;if(!e.usingObjFormat)return e.usingStepFormat?zUe.STEP_INVERTED:zUe.Z_UP_TO_Y_UP_USB_FIX}}function yq(t,e){return jpi(t,{usingGlbCoordinates:e==="gltf"||e==="glb"||e==="jscad",usingObjFormat:e==="obj"||e==="wrl",usingStepFormat:e==="step",hasFootprinterModel:e==="footprinter"})}function Bde(t){if(!t)return;const e=Ede({x:1,y:0,z:0},t),n=Ede({x:0,y:1,z:0},t),o=Ede({x:0,y:0,z:1},t);return new xa().makeBasis(new jt(e.x,e.y,e.z),new jt(n.x,n.y,n.z),new jt(o.x,o.y,o.z))}function PP(t){return t*Math.PI/180}function Xpi(t){if(t==="z+")return[0,0,0];switch(t){case"x+":return[0,PP(-90),0];case"x-":return[0,PP(90),0];case"y+":return[PP(90),0,0];case"y-":return[PP(-90),0,0];case"z-":return[PP(180),0,0];default:return[0,0,0]}}function qpi(t,e,n){if(!t.position)return;let o=t.position.z;return e==="bottom"&&t.position.z>=0&&(o=-(t.position.z+n)),[t.position.x,t.position.y,o]}function $pi(t,e){return t.rotation?[PP(t.rotation.x),PP(t.rotation.y),PP(t.rotation.z)]:e==="bottom"?[Math.PI,0,0]:[0,0,0]}function Zpi(t,e){const n=new jt(t.x,t.y,t.z),o=new Ny(e[0],e[1],e[2],"XYZ");return n.applyEuler(o),[n.x,n.y,n.z]}function e_i(t,e,n){if(!t.model_origin_position)return[0,0,0];const o=e?Ede(t.model_origin_position,e):t.model_origin_position;return Zpi(o,n)}function t_i(t,e){const n=qpi(t,e.layer,e.pcbThickness),o=$pi(t,e.layer),i=yq(t,e.modelType),r=Xpi(t.model_board_normal_direction??"z+"),s=e_i(t,i,r);return{position:n,rotation:o,modelPosition:[-s[0],-s[1],-s[2]],modelRotation:r,scale:t.model_unit_to_mm_scale_factor??void 0,fitMode:t.model_object_fit??"contain_within_bounds",size:t.size?[t.size.x,t.size.y,t.size.z]:void 0}}var n_i=t=>t.model_glb_url||t.model_gltf_url?t.model_glb_url?"glb":"gltf":t.model_obj_url||t.model_wrl_url||t.model_stl_url?t.model_wrl_url?"wrl":t.model_stl_url?"stl":"obj":t.model_jscad?"jscad":t.footprinter_string?"footprinter":t.model_step_url?"step":"unknown",o_i=t=>t==="step"?"glb":t,i_i=(t,e)=>{if(!t.model_jscad||t.model_origin_alignment!=="bottom_center_of_component")return!1;const n=e.find(o=>o.type==="pcb_component"&&o.pcb_component_id===t.pcb_component_id);return!!(n&&n.do_not_place&&n.is_allowed_to_be_off_board&&n.obstructs_within_bounds===!1)},r_i=(t,e)=>{if(t)return e?e(t):t},s_i=(...t)=>t,JUe=class extends Ms.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}},a_i=({error:t,onError:e})=>(ee.useEffect(()=>{e(t)},[t,e]),null),Rnn=({cad_component:t,circuitJson:e,resolveStaticAsset:n})=>{const o=itn(e),[i,r]=ee.useState(!1),{visibility:s}=fR(),[a,A]=ee.useState(null),c=ee.useCallback(Y=>{Y?.mousePosition?(r(!0),A(Y.mousePosition)):(r(!1),A(null))},[]),l=ee.useCallback(()=>{r(!1),A(null)},[]),g=ee.useMemo(()=>Cr(e).source_component.getUsing({source_component_id:t.source_component_id})?.name,[e,t.source_component_id]),u=ee.useMemo(()=>e.filter(X=>X.type==="pcb_plated_hole"&&X.pcb_component_id===t.pcb_component_id).length>0,[e,t.pcb_component_id]),h=ee.useCallback(Y=>r_i(Y,n),[n]),d=h(t.model_wrl_url??t.model_stl_url??t.model_obj_url),m=h(t.model_glb_url??t.model_gltf_url),p=h(t.model_step_url),[_,f]=ee.useState(0),[I,C]=ee.useState(null);ee.useEffect(()=>{f(0),C(null)},[t.cad_component_id,d,m,p]);const x=e.find(Y=>Y.type==="pcb_component"&&Y.source_component_id===t.source_component_id)?.layer??"top",E=ee.useMemo(()=>i_i(t,e),[t,e]),B=E?s.enclosure==="translucent":!!t.show_as_translucent_model,b=n_i(t),Q=o_i(b),w=t.model_glb_url?"glb":"gltf",D=t.model_wrl_url?"wrl":t.model_stl_url?"stl":"obj",k=ee.useMemo(()=>t_i(t,{layer:x,pcbThickness:o,modelType:Q}),[t,x,o,Q]),R=s_i(...k.rotation),H=k.position,G=ee.useMemo(()=>{const Y=[];return m&&Y.push(U.jsx(wnn,{gltfUrl:m,position:H,rotation:R,modelOffset:k.modelPosition,modelRotation:k.modelRotation,sourceCoordinateTransform:Bde(yq(t,w)),scale:k.scale,modelSize:k.size,modelFitMode:k.fitMode,onHover:c,onUnhover:l,isHovered:i,isTranslucent:B},`${t.cad_component_id}-gltf-${m}`)),d&&Y.push(U.jsx(kpi,{url:d,position:H,rotation:R,modelOffset:k.modelPosition,modelRotation:k.modelRotation,sourceCoordinateTransform:Bde(yq(t,D)),scale:k.scale,modelSize:k.size,modelFitMode:k.fitMode,onHover:c,onUnhover:l,isHovered:i,isTranslucent:B},`${t.cad_component_id}-mixed-${d}`)),p&&!t.model_jscad&&!t.footprinter_string&&Y.push(U.jsx(Wpi,{stepUrl:p,position:H,rotation:R,modelOffset:k.modelPosition,modelRotation:k.modelRotation,sourceCoordinateTransform:Bde(yq(t,Q)),scale:k.scale,modelSize:k.size,modelFitMode:k.fitMode,onHover:c,onUnhover:l,isHovered:i,isTranslucent:B},`${t.cad_component_id}-step-${p}`)),Y},[H,t.cad_component_id,t.footprinter_string,t.model_jscad,B,m,w,c,l,i,D,k.modelPosition,k.modelRotation,k.scale,k.fitMode,k.size,Q,R,p,d]);let K=null;if(G.length>0){if(_>=G.length){if(I)throw I;return null}K=U.jsx(JUe,{fallback:({error:Y})=>U.jsx(a_i,{error:Y,onError:X=>{C(X),f(te=>Math.max(te,_+1))}}),children:G[_]},`${t.cad_component_id}-fallback-${_}`)}else t.model_jscad?K=U.jsx(Dpi,{jscadPlan:t.model_jscad,positionOffset:H,rotationOffset:R,modelOffset:k.modelPosition,modelRotation:k.modelRotation,sourceCoordinateTransform:Bde(yq(t,"jscad")),scale:k.scale,modelSize:k.size,modelFitMode:k.fitMode,onHover:c,onUnhover:l,isHovered:i,isTranslucent:B},t.cad_component_id):t.footprinter_string&&(K=U.jsx(Bpi,{positionOffset:H,rotationOffset:R,footprint:t.footprinter_string,scale:k.scale,onHover:c,onUnhover:l,isHovered:i,isTranslucent:B}));if(E){if(s.enclosure==="hidden")return null}else if(t.show_as_translucent_model){if(!s.translucentModels)return null}else if(u&&!s.throughHoleModels||!u&&!s.smtModels)return null;return U.jsxs(U.Fragment,{children:[K,i&&a?U.jsx(stn,{position:a,style:{fontFamily:"sans-serif",transform:"translate3d(1rem, 1rem, 0)",backgroundColor:"white",padding:"5px",borderRadius:"3px",pointerEvents:"none",userSelect:"none",WebkitUserSelect:"none",MozUserSelect:"none",msUserSelect:"none"},children:g??"<unknown>"}):null]})},Tnn={version:"0.0.599"},knn="cadViewerLightingEnabled",A_i=()=>typeof window>"u"?!0:window.localStorage.getItem(knn)!=="false",Fnn=ee.createContext(void 0),c_i=({children:t})=>{const[e,n]=ee.useState(!1),[o,i]=ee.useState(!1),[r,s]=ee.useState(A_i);ee.useEffect(()=>{window.localStorage.setItem(knn,r?"true":"false")},[r]);const a=ee.useMemo(()=>({darkBackgroundEnabled:e,setDarkBackgroundEnabled:n,gridEnabled:o,setGridEnabled:i,lightingEnabled:r,setLightingEnabled:s}),[e,o,r]);return U.jsx(Fnn.Provider,{value:a,children:t})},WUe=()=>{const t=ee.useContext(Fnn);if(!t)throw new Error("useAppearance must be used within an AppearanceProvider");return t},Lnn="cadViewerCameraStateSession",Hnn=(t,e)=>{try{const n={position:t.position.toArray(),quaternion:t.quaternion.toArray(),up:t.up.toArray(),fov:t.fov??50,target:e.target.toArray()};sessionStorage.setItem(Lnn,JSON.stringify(n))}catch(n){console.warn("Failed to save camera:",n)}},jUe=(t,e)=>{try{const n=sessionStorage.getItem(Lnn);if(!n)return!1;const o=JSON.parse(n);if(t.position.fromArray(o.position),t.quaternion.fromArray(o.quaternion),t.up.fromArray(o.up),"fov"in t){const i=t;i.fov=o.fov,i.updateProjectionMatrix?.()}return e.target.fromArray(o.target),e.update(),t.updateMatrixWorld(),!0}catch(n){return console.warn("Failed to restore camera:",n),!1}},Onn=ee.createContext(void 0),l_i=({children:t,defaultTarget:e,initialCameraPosition:n,initialCameraType:o})=>{const i=ee.useRef(null),r=ee.useRef(null),[s,a]=ee.useState(null),[A,c]=ee.useState(o??"perspective"),[l,g]=ee.useState(n??null),[u,h]=ee.useState(new Ny(0,0,0)),d=ee.useMemo(()=>{const[f,I,C]=n??[5,-5,5],y=Math.hypot(f-e.x,I-e.y,C-e.z);return y>0?y:5},[n,e]),m=ee.useCallback(f=>{const I=[e.x,e.y,e.z],C=r.current,y=i.current;let x=d;switch(C&&y&&(x=C.position.distanceTo(y.target)),f){case"Top Center Angled":{const E=x/Math.sqrt(2);return{position:[e.x,e.y-E,e.z+E],target:I,up:[0,0,1]}}case"Top Down":return{position:[e.x,e.y,e.z+x],target:I,up:[0,0,1]};case"Top Left Corner":return{position:[e.x-x*.6,e.y-x*.6,e.z+x*.6],target:I,up:[0,0,1]};case"Top Right Corner":return{position:[e.x+x*.6,e.y-x*.6,e.z+x*.6],target:I,up:[0,0,1]};case"Left Sideview":return{position:[e.x-x,e.y,e.z],target:I,up:[0,0,1]};case"Right Sideview":return{position:[e.x+x,e.y,e.z],target:I,up:[0,0,1]};case"Front":return{position:[e.x,e.y-x,e.z],target:I,up:[0,0,1]};default:return null}},[d,e,r,i]),p=ee.useCallback(f=>{i.current=f},[]),_=ee.useMemo(()=>({controlsRef:i,mainCameraRef:r,defaultTarget:e,baseDistance:d,controller:s,setController:a,getPresetConfig:m,handleControlsChange:p,cameraType:A,setCameraType:c,cameraPosition:l,setCameraPosition:g,cameraRotation:u,setCameraRotation:h,saveCameraToSession:Hnn,loadCameraFromSession:jUe}),[e,d,s,m,p,A,l,u]);return U.jsx(Onn.Provider,{value:_,children:t})},TS=()=>{const t=ee.useContext(Onn);if(!t)throw new Error("useCameraController must be used within a CameraControllerProvider");return t},g_i=t=>t<.5?4*t*t*t:1-Math.pow(-2*t+2,3)/2,u_i=()=>{const{controlsRef:t,mainCameraRef:e,defaultTarget:n,setController:o,getPresetConfig:i}=TS(),r=ee.useRef(null),s=ee.useRef(new Dy),a=ee.useRef(new jt),A=ee.useRef(new jt),c=ee.useRef(new Dy),l=ee.useRef(new Dy),g=ee.useRef(new y0),u=ee.useRef(new y0),h=ee.useCallback(({position:m,target:p,up:_,durationMs:f=600})=>{if(!e.current)return;const I=t.current?.target??n,C=new jt(m[0],m[1],m[2]),y=p?new jt(p[0],p[1],p[2]):n.clone(),x=new jt(..._??[0,0,1]).normalize(),E=u.current;E.position.copy(C),E.up.copy(x),E.lookAt(y);const B=E.quaternion.clone(),b=e.current.quaternion.clone(),Q=e.current.position.clone(),w=I.clone(),D=g.current;D.up.set(0,0,1),D.position.copy(Q),D.lookAt(w);const k=D.quaternion.clone();D.up.set(0,0,1),D.position.copy(C),D.lookAt(y);const R=D.quaternion.clone(),H=k.clone().invert().multiply(b).normalize(),G=R.clone().invert().multiply(B).normalize();r.current={fromPosition:Q,toPosition:C,fromTarget:w,toTarget:y,toQuaternion:B,rollFrom:H,rollTo:G,startTime:performance.now(),duration:f}},[e,t,n]),d=ee.useCallback(m=>{if(m==="Custom")return;const p=i(m);p&&h(p)},[h,i]);return ee.useEffect(()=>e.current?(o({animateTo:h,animateToPreset:d}),()=>{o(null)}):void 0,[h,d,e,o]),sq(()=>{if(!e.current||!r.current)return;const{fromPosition:m,toPosition:p,fromTarget:_,toTarget:f,toQuaternion:I,rollFrom:C,rollTo:y,startTime:x,duration:E}=r.current,B=performance.now()-x,b=E<=0?1:Math.min(B/E,1),Q=g_i(b);e.current.position.lerpVectors(m,p,Q);const w=a.current;w.copy(_).lerp(f,Q);const D=g.current;D.up.set(0,0,1),D.position.copy(e.current.position),D.lookAt(w);const k=s.current;k.copy(D.quaternion);const R=c.current;R.copy(C);const H=l.current;H.copy(y),C.dot(y)<0&&(H.x*=-1,H.y*=-1,H.z*=-1,H.w*=-1),H.normalize(),R.slerp(H,Q),e.current.quaternion.copy(k).multiply(R).normalize();const G=A.current;G.set(0,1,0).applyQuaternion(e.current.quaternion).normalize(),e.current.up.copy(G),t.current?.target.copy(w),e.current.updateMatrixWorld(),t.current?.update(),b>=1&&(e.current.position.copy(p),e.current.quaternion.copy(I),e.current.up.set(0,0,1),e.current.updateMatrixWorld(),t.current?.target.copy(f),t.current?.update(),r.current=null)}),null},d_i=()=>{const{controlsRef:t}=TS(),e=ee.useRef(null),n=ee.useRef(!1),o=ee.useRef(null),i=ee.useCallback(s=>{e.current=s,!n.current&&t.current&&jUe(s,t.current)&&(n.current=!0)},[t]),r=ee.useCallback(()=>{if(!(!e.current||!t.current)){if(!n.current&&jUe(e.current,t.current)){n.current=!0;return}clearTimeout(o.current),o.current=setTimeout(()=>{e.current&&t.current&&Hnn(e.current,t.current)},150)}},[t]);return{handleCameraCreated:i,handleControlsChange:r}};function h_i(t){t.querySelectorAll("canvas").forEach(e=>e.remove())}var m_i=t=>{t.outputColorSpace=px,t.toneMapping=AOt,t.toneMappingExposure=1,t.shadowMap.enabled=!0,t.shadowMap.type=iOt},p_i=ee.forwardRef(({children:t,scene:e,camera:n,style:o,onCreated:i},r)=>{const{cameraType:s}=TS(),a=ee.useRef(null),[A,c]=ee.useState(null),l=ee.useRef([]),g=ee.useRef(void 0);g.current=i;const u=ee.useRef(null),h=ee.useCallback(_=>{l.current.push(_)},[]),d=ee.useCallback(_=>{l.current=l.current.filter(f=>f!==_)},[]),m=ee.useMemo(()=>new eR,[]);e?.up&&m.up.set(e.up.x,e.up.y,e.up.z);const p=ee.useRef(new y0);return ee.useImperativeHandle(r,()=>p.current),ee.useEffect(()=>{if(!a.current)return;h_i(a.current);const _=new jge({antialias:!0,alpha:!0});m_i(_),_.setSize(a.current.clientWidth,a.current.clientHeight),_.setPixelRatio(window.devicePixelRatio),a.current.appendChild(_.domElement);const f=a.current.clientWidth/a.current.clientHeight,I=s==="perspective"?new U_(75,f,.1,1e3):new oG(-10*f,10*f,10,-10,-1e3,1e3);u.current?(I.position.copy(u.current.position),I.quaternion.copy(u.current.quaternion),I.up.copy(u.current.up)):(n?.up&&I.up.set(n.up[0],n.up[1],n.up[2]),n?.position&&I.position.set(n.position[0],n.position[1],n.position[2]),I.lookAt(0,0,0)),m.add(p.current),window.__TSCIRCUIT_THREE_OBJECT=p.current,c({scene:m,camera:I,renderer:_,rootObject:p.current,addFrameListener:h,removeFrameListener:d}),g.current?.({camera:I,renderer:_});let C;const y=new aWo,x=()=>{const B=y.getElapsedTime(),b=y.getDelta();l.current.forEach(Q=>Q(B,b)),_.render(m,I),C=requestAnimationFrame(x)};x();const E=()=>{if(a.current){const B=a.current.clientWidth/a.current.clientHeight;I instanceof U_?I.aspect=B:I instanceof oG&&(I.left=-10*B,I.right=10*B,I.top=10,I.bottom=-10),I.updateProjectionMatrix(),_.setSize(a.current.clientWidth,a.current.clientHeight)}};return window.addEventListener("resize",E),()=>{u.current={position:I.position.clone(),quaternion:I.quaternion.clone(),up:I.up.clone()},window.removeEventListener("resize",E),cancelAnimationFrame(C),a.current&&_.domElement&&a.current.removeChild(_.domElement),_.dispose(),m.remove(p.current),window.__TSCIRCUIT_THREE_OBJECT===p.current&&(window.__TSCIRCUIT_THREE_OBJECT=void 0)}},[m,h,d,s]),U.jsx("div",{ref:a,style:{width:"100%",height:"100%",...o},children:A&&U.jsx(rtn.Provider,{value:A,children:U.jsx(xpi,{children:t})})})}),__i=`
5307
+ `).replace(/^d\s+0\./gm,"d 1."),h=c.replace(/newmtl[\s\S]*?endmtl/g,"").replace(/^mtllib.*/gm,""),d=new Sjo;d.setMaterialOptions({invertTrProperty:!0});const m=d.parse(u,"embedded.mtl");return g.setMaterials(m),g.parse(h)}return g.parse(c.replace(/^mtllib.*/gm,""))}catch(A){return A}}function a(){if(i.has(o)){const c=i.get(o);return c.result?Promise.resolve(c.result.clone()):c.promise.then(l=>l instanceof Error?l:l.clone())}const A=s().then(c=>(c instanceof Error||i.set(o,{...i.get(o),result:c}),c));return i.set(o,{promise:A,result:null}),A}return a().then(A=>{r||n(A)}).catch(A=>{console.error(A)}),()=>{r=!0}},[t]),e}function kpi({url:t,position:e,rotation:n,modelOffset:o=[0,0,0],modelRotation:i=[0,0,0],sourceCoordinateTransform:r,modelSize:s,modelFitMode:a="contain_within_bounds",onHover:A,onUnhover:c,isHovered:l,scale:g,isTranslucent:u=!1}){const h=Tpi(t),d=ee.useMemo(()=>{if(h&&!(h instanceof Error))return h.traverse(_=>{if(_ instanceof Dr&&_.material){const f=I=>{I.transparent=u,I.opacity=u?.5:1,I.depthWrite=!u,I.needsUpdate=!0};Array.isArray(_.material)?_.material.forEach(f):f(_.material),_.renderOrder=u?2:1}}),vB(h,{castShadow:!u,receiveShadow:!0}),h;const p=new Dr(new Ix(.5,.5,.5),new fg({transparent:!0,color:"red",opacity:.25}));return vB(p,{castShadow:!1,receiveShadow:!0}),p},[h,u]),{boardTransformGroup:m}=UUe({model:d,position:Array.isArray(e)?e:e?[e.x,e.y,e.z]:void 0,rotation:Array.isArray(n)?n:n?[n.x,n.y,n.z]:void 0,modelOffset:o,modelRotation:i,sourceCoordinateTransform:r,modelSize:s,modelFitMode:a,scale:g});if(h instanceof Error)throw h;return U.jsx(Cq,{isHovered:l,onHover:A,onUnhover:c,object:m})}var Fpi=new Yi(.82,.82,.82),Mnn=t=>new fg({color:t?new Yi(t[0],t[1],t[2]):Fpi});function Lpi(t,e){const n=Mnn(e.color),o=e.brep_faces??[];if(o.length===0)return[n];const i=o.length>1?[...o].sort((g,u)=>g.first-u.first):o,r=[n],s=new Map,a=e.index.array.length/3;let A=0,c=0;const l=g=>{if(!g)return 0;const u=g.join(","),h=s.get(u);if(h!==void 0)return h;const d=r.length;return r.push(Mnn(g)),s.set(u,d),d};for(;A<a;){const g=i[c];let u=a,h=0;g&&(A<g.first?u=g.first:(u=g.last+1,h=l(g.color),c+=1)),u>A&&t.addGroup(A*3,(u-A)*3,h),A=u}return r}function Hpi(t){const e=new Mh;for(const n of t){const o=n.attributes.position?.array??[],i=n.index?.array??[];if(!o.length||!i.length)continue;const r=new o0;r.setAttribute("position",new Ns(o,3));const s=n.attributes.normal?.array??[];s.length?r.setAttribute("normal",new Ns(s,3)):r.computeVertexNormals(),r.setIndex(i),r.clearGroups();const a=Lpi(r,n),A=new Dr(r,a.length>1?a:a[0]);A.name=n.name,e.add(A)}return e}var KUe,Opi="https://cdn.jsdelivr.net/npm/occt-import-js@0.0.23/dist";function Gpi(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 Ypi(){if(!KUe){const t=await import("https://cdn.jsdelivr.net/npm/occt-import-js@0.0.23/+esm");KUe=Gpi(t)({locateFile:n=>`${Opi}/${n}`})}return KUe}async function Upi(t){const e=await fetch(t);if(!e.ok)throw new Error(`Failed to fetch STEP file: ${e.statusText}`);const n=await e.arrayBuffer(),i=(await Ypi()).ReadStepFile(new Uint8Array(n),null);if(!i.success||!i.meshes.length)throw new Error("occt-import-js failed to convert STEP file");const r=Hpi(i.meshes),s=new GNe;return await new Promise((A,c)=>{s.parse(r,l=>{l instanceof ArrayBuffer?A(l):c(new Error("GLTFExporter did not return binary output"))},l=>{c(l)},{binary:!0})})}var Dnn="step-glb-cache:v2:";function Kpi(t){const e=new Uint8Array(t),n=32768;let o="";for(let i=0;i<e.length;i+=n){const r=e.subarray(i,i+n);o+=String.fromCharCode(...r)}return btoa(o)}function Vpi(t){const e=atob(t),n=new Uint8Array(e.length);for(let o=0;o<e.length;o+=1)n[o]=e.charCodeAt(o);return n.buffer}function zpi(t){try{const e=localStorage.getItem(`${Dnn}${t}`);return e?Vpi(e):null}catch(e){return console.warn("Failed to read STEP GLB cache",e),null}}function Nnn(t,e){try{const n=Kpi(e);localStorage.setItem(`${Dnn}${t}`,n)}catch(n){console.warn("Failed to write STEP GLB cache",n)}}function Jpi(){const t=globalThis;return t.stepUrlToGltfModelConversions||(t.stepUrlToGltfModelConversions={inProgress:new Map,completed:new Map}),t.stepUrlToGltfModelConversions}var Wpi=({stepUrl:t,position:e,rotation:n,modelOffset:o,modelRotation:i,sourceCoordinateTransform:r,modelSize:s,modelFitMode:a,scale:A,onHover:c,onUnhover:l,isHovered:g,isTranslucent:u})=>{const[h,d]=ee.useState(null);return ee.useEffect(()=>{let m=!0,p=null,_=!0;const f=Jpi(),I=zpi(t);if(I){const x={arrayBuffer:I,blobUrl:URL.createObjectURL(new Blob([I],{type:"model/gltf-binary"}))};return f.completed.set(t,x),p=x.blobUrl,_=!1,d(x.blobUrl),()=>{m=!1,p&&_&&URL.revokeObjectURL(p)}}const C=f.completed.get(t);if(C)return p=C.blobUrl,_=!1,d(C.blobUrl),Nnn(t,C.arrayBuffer),()=>{m=!1,p&&_&&URL.revokeObjectURL(p)};let y=f.inProgress.get(t);return y||(y=Upi(t).then(x=>{const E={arrayBuffer:x,blobUrl:URL.createObjectURL(new Blob([x],{type:"model/gltf-binary"}))};return f.completed.set(t,E),f.inProgress.delete(t),E}).catch(x=>{throw f.inProgress.delete(t),x}),f.inProgress.set(t,y)),y.then(x=>{m&&(p=x.blobUrl,_=!1,d(x.blobUrl),Nnn(t,x.arrayBuffer))}).catch(x=>{console.error("Failed to convert STEP file to GLB",x),m&&d(null)}),()=>{m=!1,p&&_&&URL.revokeObjectURL(p)}},[t]),h?U.jsx(wnn,{gltfUrl:h,position:e,rotation:n,modelOffset:o,modelRotation:i,sourceCoordinateTransform:r,modelSize:s,modelFitMode:a,scale:A,onHover:c,onUnhover:l,isHovered:g,isTranslucent:u}):null};function Ede(t,e){let{x:n,y:o,z:i}=t;if(e.axisMapping){const r={x:n,y:o,z:i};e.axisMapping.x&&(n=VUe(r,e.axisMapping.x)),e.axisMapping.y&&(o=VUe(r,e.axisMapping.y)),e.axisMapping.z&&(i=VUe(r,e.axisMapping.z))}if(n*=e.flipX??1,o*=e.flipY??1,i*=e.flipZ??1,e.rotation){if(e.rotation.x){const r=e.rotation.x*Math.PI/180,s=Math.cos(r),a=Math.sin(r),A=o*s-i*a,c=o*a+i*s;o=A,i=c}if(e.rotation.y){const r=e.rotation.y*Math.PI/180,s=Math.cos(r),a=Math.sin(r),A=n*s+i*a,c=-n*a+i*s;n=A,i=c}if(e.rotation.z){const r=e.rotation.z*Math.PI/180,s=Math.cos(r),a=Math.sin(r),A=n*s-o*a,c=n*a+o*s;n=A,o=c}}return{x:n,y:o,z:i}}function VUe(t,e){switch(e){case"x":return t.x;case"y":return t.y;case"z":return t.z;case"-x":return-t.x;case"-y":return-t.y;case"-z":return-t.z;default:return 0}}var zUe={STEP_INVERTED:{axisMapping:{x:"-x",y:"z",z:"-y"}},Z_UP_TO_Y_UP_USB_FIX:{axisMapping:{x:"x",y:"-z",z:"y"},flipZ:-1},FOOTPRINTER_MODEL_TRANSFORM:{axisMapping:{x:"x",y:"-z",z:"y"},flipX:-1,rotation:{x:180,y:180}}};function jpi(t,e){if(e.coordinateTransform)return e.coordinateTransform;if(!e.usingGlbCoordinates){if(e.hasFootprinterModel)return zUe.FOOTPRINTER_MODEL_TRANSFORM;if(!e.usingObjFormat)return e.usingStepFormat?zUe.STEP_INVERTED:zUe.Z_UP_TO_Y_UP_USB_FIX}}function yq(t,e){return jpi(t,{usingGlbCoordinates:e==="gltf"||e==="glb"||e==="jscad",usingObjFormat:e==="obj"||e==="wrl",usingStepFormat:e==="step",hasFootprinterModel:e==="footprinter"})}function Bde(t){if(!t)return;const e=Ede({x:1,y:0,z:0},t),n=Ede({x:0,y:1,z:0},t),o=Ede({x:0,y:0,z:1},t);return new xa().makeBasis(new jt(e.x,e.y,e.z),new jt(n.x,n.y,n.z),new jt(o.x,o.y,o.z))}function PP(t){return t*Math.PI/180}function Xpi(t){if(t==="z+")return[0,0,0];switch(t){case"x+":return[0,PP(-90),0];case"x-":return[0,PP(90),0];case"y+":return[PP(90),0,0];case"y-":return[PP(-90),0,0];case"z-":return[PP(180),0,0];default:return[0,0,0]}}function qpi(t,e,n){if(!t.position)return;let o=t.position.z;return e==="bottom"&&t.position.z>=0&&(o=-(t.position.z+n)),[t.position.x,t.position.y,o]}function $pi(t,e){return t.rotation?[PP(t.rotation.x),PP(t.rotation.y),PP(t.rotation.z)]:e==="bottom"?[Math.PI,0,0]:[0,0,0]}function Zpi(t,e){const n=new jt(t.x,t.y,t.z),o=new Ny(e[0],e[1],e[2],"XYZ");return n.applyEuler(o),[n.x,n.y,n.z]}function e_i(t,e,n){if(!t.model_origin_position)return[0,0,0];const o=e?Ede(t.model_origin_position,e):t.model_origin_position;return Zpi(o,n)}function t_i(t,e){const n=qpi(t,e.layer,e.pcbThickness),o=$pi(t,e.layer),i=yq(t,e.modelType),r=Xpi(t.model_board_normal_direction??"z+"),s=e_i(t,i,r);return{position:n,rotation:o,modelPosition:[-s[0],-s[1],-s[2]],modelRotation:r,scale:t.model_unit_to_mm_scale_factor??void 0,fitMode:t.model_object_fit??"contain_within_bounds",size:t.size?[t.size.x,t.size.y,t.size.z]:void 0}}var n_i=t=>t.model_glb_url||t.model_gltf_url?t.model_glb_url?"glb":"gltf":t.model_obj_url||t.model_wrl_url||t.model_stl_url?t.model_wrl_url?"wrl":t.model_stl_url?"stl":"obj":t.model_jscad?"jscad":t.footprinter_string?"footprinter":t.model_step_url?"step":"unknown",o_i=t=>t==="step"?"glb":t,i_i=(t,e)=>{if(!t.model_jscad||t.model_origin_alignment!=="bottom_center_of_component")return!1;const n=e.find(o=>o.type==="pcb_component"&&o.pcb_component_id===t.pcb_component_id);return!!(n&&n.do_not_place&&n.is_allowed_to_be_off_board&&n.obstructs_within_bounds===!1)},r_i=(t,e)=>{if(t)return e?e(t):t},s_i=(...t)=>t,JUe=class extends Ms.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}},a_i=({error:t,onError:e})=>(ee.useEffect(()=>{e(t)},[t,e]),null),Rnn=({cad_component:t,circuitJson:e,resolveStaticAsset:n})=>{const o=itn(e),[i,r]=ee.useState(!1),{visibility:s}=fR(),[a,A]=ee.useState(null),c=ee.useCallback(Y=>{Y?.mousePosition?(r(!0),A(Y.mousePosition)):(r(!1),A(null))},[]),l=ee.useCallback(()=>{r(!1),A(null)},[]),g=ee.useMemo(()=>Cr(e).source_component.getUsing({source_component_id:t.source_component_id})?.name,[e,t.source_component_id]),u=ee.useMemo(()=>e.filter(X=>X.type==="pcb_plated_hole"&&X.pcb_component_id===t.pcb_component_id).length>0,[e,t.pcb_component_id]),h=ee.useCallback(Y=>r_i(Y,n),[n]),d=h(t.model_wrl_url??t.model_stl_url??t.model_obj_url),m=h(t.model_glb_url??t.model_gltf_url),p=h(t.model_step_url),[_,f]=ee.useState(0),[I,C]=ee.useState(null);ee.useEffect(()=>{f(0),C(null)},[t.cad_component_id,d,m,p]);const x=e.find(Y=>Y.type==="pcb_component"&&Y.source_component_id===t.source_component_id)?.layer??"top",E=ee.useMemo(()=>i_i(t,e),[t,e]),B=E?s.enclosure==="translucent":!!t.show_as_translucent_model,b=n_i(t),Q=o_i(b),w=t.model_glb_url?"glb":"gltf",D=t.model_wrl_url?"wrl":t.model_stl_url?"stl":"obj",k=ee.useMemo(()=>t_i(t,{layer:x,pcbThickness:o,modelType:Q}),[t,x,o,Q]),R=s_i(...k.rotation),H=k.position,G=ee.useMemo(()=>{const Y=[];return m&&Y.push(U.jsx(wnn,{gltfUrl:m,position:H,rotation:R,modelOffset:k.modelPosition,modelRotation:k.modelRotation,sourceCoordinateTransform:Bde(yq(t,w)),scale:k.scale,modelSize:k.size,modelFitMode:k.fitMode,onHover:c,onUnhover:l,isHovered:i,isTranslucent:B},`${t.cad_component_id}-gltf-${m}`)),d&&Y.push(U.jsx(kpi,{url:d,position:H,rotation:R,modelOffset:k.modelPosition,modelRotation:k.modelRotation,sourceCoordinateTransform:Bde(yq(t,D)),scale:k.scale,modelSize:k.size,modelFitMode:k.fitMode,onHover:c,onUnhover:l,isHovered:i,isTranslucent:B},`${t.cad_component_id}-mixed-${d}`)),p&&!t.model_jscad&&!t.footprinter_string&&Y.push(U.jsx(Wpi,{stepUrl:p,position:H,rotation:R,modelOffset:k.modelPosition,modelRotation:k.modelRotation,sourceCoordinateTransform:Bde(yq(t,Q)),scale:k.scale,modelSize:k.size,modelFitMode:k.fitMode,onHover:c,onUnhover:l,isHovered:i,isTranslucent:B},`${t.cad_component_id}-step-${p}`)),Y},[H,t.cad_component_id,t.footprinter_string,t.model_jscad,B,m,w,c,l,i,D,k.modelPosition,k.modelRotation,k.scale,k.fitMode,k.size,Q,R,p,d]);let K=null;if(G.length>0){if(_>=G.length){if(I)throw I;return null}K=U.jsx(JUe,{fallback:({error:Y})=>U.jsx(a_i,{error:Y,onError:X=>{C(X),f(te=>Math.max(te,_+1))}}),children:G[_]},`${t.cad_component_id}-fallback-${_}`)}else t.model_jscad?K=U.jsx(Dpi,{jscadPlan:t.model_jscad,positionOffset:H,rotationOffset:R,modelOffset:k.modelPosition,modelRotation:k.modelRotation,sourceCoordinateTransform:Bde(yq(t,"jscad")),scale:k.scale,modelSize:k.size,modelFitMode:k.fitMode,onHover:c,onUnhover:l,isHovered:i,isTranslucent:B},t.cad_component_id):t.footprinter_string&&(K=U.jsx(Bpi,{positionOffset:H,rotationOffset:R,footprint:t.footprinter_string,scale:k.scale,onHover:c,onUnhover:l,isHovered:i,isTranslucent:B}));if(E){if(s.enclosure==="hidden")return null}else if(t.show_as_translucent_model){if(!s.translucentModels)return null}else if(u&&!s.throughHoleModels||!u&&!s.smtModels)return null;return U.jsxs(U.Fragment,{children:[K,i&&a?U.jsx(stn,{position:a,style:{fontFamily:"sans-serif",transform:"translate3d(1rem, 1rem, 0)",backgroundColor:"white",padding:"5px",borderRadius:"3px",pointerEvents:"none",userSelect:"none",WebkitUserSelect:"none",MozUserSelect:"none",msUserSelect:"none"},children:g??"<unknown>"}):null]})},Tnn={version:"0.0.600"},knn="cadViewerLightingEnabled",A_i=()=>typeof window>"u"?!0:window.localStorage.getItem(knn)!=="false",Fnn=ee.createContext(void 0),c_i=({children:t})=>{const[e,n]=ee.useState(!1),[o,i]=ee.useState(!1),[r,s]=ee.useState(A_i);ee.useEffect(()=>{window.localStorage.setItem(knn,r?"true":"false")},[r]);const a=ee.useMemo(()=>({darkBackgroundEnabled:e,setDarkBackgroundEnabled:n,gridEnabled:o,setGridEnabled:i,lightingEnabled:r,setLightingEnabled:s}),[e,o,r]);return U.jsx(Fnn.Provider,{value:a,children:t})},WUe=()=>{const t=ee.useContext(Fnn);if(!t)throw new Error("useAppearance must be used within an AppearanceProvider");return t},Lnn="cadViewerCameraStateSession",Hnn=(t,e)=>{try{const n={position:t.position.toArray(),quaternion:t.quaternion.toArray(),up:t.up.toArray(),fov:t.fov??50,target:e.target.toArray()};sessionStorage.setItem(Lnn,JSON.stringify(n))}catch(n){console.warn("Failed to save camera:",n)}},jUe=(t,e)=>{try{const n=sessionStorage.getItem(Lnn);if(!n)return!1;const o=JSON.parse(n);if(t.position.fromArray(o.position),t.quaternion.fromArray(o.quaternion),t.up.fromArray(o.up),"fov"in t){const i=t;i.fov=o.fov,i.updateProjectionMatrix?.()}return e.target.fromArray(o.target),e.update(),t.updateMatrixWorld(),!0}catch(n){return console.warn("Failed to restore camera:",n),!1}},Onn=ee.createContext(void 0),l_i=({children:t,defaultTarget:e,initialCameraPosition:n,initialCameraType:o})=>{const i=ee.useRef(null),r=ee.useRef(null),[s,a]=ee.useState(null),[A,c]=ee.useState(o??"perspective"),[l,g]=ee.useState(n??null),[u,h]=ee.useState(new Ny(0,0,0)),d=ee.useMemo(()=>{const[f,I,C]=n??[5,-5,5],y=Math.hypot(f-e.x,I-e.y,C-e.z);return y>0?y:5},[n,e]),m=ee.useCallback(f=>{const I=[e.x,e.y,e.z],C=r.current,y=i.current;let x=d;switch(C&&y&&(x=C.position.distanceTo(y.target)),f){case"Top Center Angled":{const E=x/Math.sqrt(2);return{position:[e.x,e.y-E,e.z+E],target:I,up:[0,0,1]}}case"Top Down":return{position:[e.x,e.y,e.z+x],target:I,up:[0,0,1]};case"Top Left Corner":return{position:[e.x-x*.6,e.y-x*.6,e.z+x*.6],target:I,up:[0,0,1]};case"Top Right Corner":return{position:[e.x+x*.6,e.y-x*.6,e.z+x*.6],target:I,up:[0,0,1]};case"Left Sideview":return{position:[e.x-x,e.y,e.z],target:I,up:[0,0,1]};case"Right Sideview":return{position:[e.x+x,e.y,e.z],target:I,up:[0,0,1]};case"Front":return{position:[e.x,e.y-x,e.z],target:I,up:[0,0,1]};default:return null}},[d,e,r,i]),p=ee.useCallback(f=>{i.current=f},[]),_=ee.useMemo(()=>({controlsRef:i,mainCameraRef:r,defaultTarget:e,baseDistance:d,controller:s,setController:a,getPresetConfig:m,handleControlsChange:p,cameraType:A,setCameraType:c,cameraPosition:l,setCameraPosition:g,cameraRotation:u,setCameraRotation:h,saveCameraToSession:Hnn,loadCameraFromSession:jUe}),[e,d,s,m,p,A,l,u]);return U.jsx(Onn.Provider,{value:_,children:t})},TS=()=>{const t=ee.useContext(Onn);if(!t)throw new Error("useCameraController must be used within a CameraControllerProvider");return t},g_i=t=>t<.5?4*t*t*t:1-Math.pow(-2*t+2,3)/2,u_i=()=>{const{controlsRef:t,mainCameraRef:e,defaultTarget:n,setController:o,getPresetConfig:i}=TS(),r=ee.useRef(null),s=ee.useRef(new Dy),a=ee.useRef(new jt),A=ee.useRef(new jt),c=ee.useRef(new Dy),l=ee.useRef(new Dy),g=ee.useRef(new y0),u=ee.useRef(new y0),h=ee.useCallback(({position:m,target:p,up:_,durationMs:f=600})=>{if(!e.current)return;const I=t.current?.target??n,C=new jt(m[0],m[1],m[2]),y=p?new jt(p[0],p[1],p[2]):n.clone(),x=new jt(..._??[0,0,1]).normalize(),E=u.current;E.position.copy(C),E.up.copy(x),E.lookAt(y);const B=E.quaternion.clone(),b=e.current.quaternion.clone(),Q=e.current.position.clone(),w=I.clone(),D=g.current;D.up.set(0,0,1),D.position.copy(Q),D.lookAt(w);const k=D.quaternion.clone();D.up.set(0,0,1),D.position.copy(C),D.lookAt(y);const R=D.quaternion.clone(),H=k.clone().invert().multiply(b).normalize(),G=R.clone().invert().multiply(B).normalize();r.current={fromPosition:Q,toPosition:C,fromTarget:w,toTarget:y,toQuaternion:B,rollFrom:H,rollTo:G,startTime:performance.now(),duration:f}},[e,t,n]),d=ee.useCallback(m=>{if(m==="Custom")return;const p=i(m);p&&h(p)},[h,i]);return ee.useEffect(()=>e.current?(o({animateTo:h,animateToPreset:d}),()=>{o(null)}):void 0,[h,d,e,o]),sq(()=>{if(!e.current||!r.current)return;const{fromPosition:m,toPosition:p,fromTarget:_,toTarget:f,toQuaternion:I,rollFrom:C,rollTo:y,startTime:x,duration:E}=r.current,B=performance.now()-x,b=E<=0?1:Math.min(B/E,1),Q=g_i(b);e.current.position.lerpVectors(m,p,Q);const w=a.current;w.copy(_).lerp(f,Q);const D=g.current;D.up.set(0,0,1),D.position.copy(e.current.position),D.lookAt(w);const k=s.current;k.copy(D.quaternion);const R=c.current;R.copy(C);const H=l.current;H.copy(y),C.dot(y)<0&&(H.x*=-1,H.y*=-1,H.z*=-1,H.w*=-1),H.normalize(),R.slerp(H,Q),e.current.quaternion.copy(k).multiply(R).normalize();const G=A.current;G.set(0,1,0).applyQuaternion(e.current.quaternion).normalize(),e.current.up.copy(G),t.current?.target.copy(w),e.current.updateMatrixWorld(),t.current?.update(),b>=1&&(e.current.position.copy(p),e.current.quaternion.copy(I),e.current.up.set(0,0,1),e.current.updateMatrixWorld(),t.current?.target.copy(f),t.current?.update(),r.current=null)}),null},d_i=()=>{const{controlsRef:t}=TS(),e=ee.useRef(null),n=ee.useRef(!1),o=ee.useRef(null),i=ee.useCallback(s=>{e.current=s,!n.current&&t.current&&jUe(s,t.current)&&(n.current=!0)},[t]),r=ee.useCallback(()=>{if(!(!e.current||!t.current)){if(!n.current&&jUe(e.current,t.current)){n.current=!0;return}clearTimeout(o.current),o.current=setTimeout(()=>{e.current&&t.current&&Hnn(e.current,t.current)},150)}},[t]);return{handleCameraCreated:i,handleControlsChange:r}};function h_i(t){t.querySelectorAll("canvas").forEach(e=>e.remove())}var m_i=t=>{t.outputColorSpace=px,t.toneMapping=AOt,t.toneMappingExposure=1,t.shadowMap.enabled=!0,t.shadowMap.type=iOt},p_i=ee.forwardRef(({children:t,scene:e,camera:n,style:o,onCreated:i},r)=>{const{cameraType:s}=TS(),a=ee.useRef(null),[A,c]=ee.useState(null),l=ee.useRef([]),g=ee.useRef(void 0);g.current=i;const u=ee.useRef(null),h=ee.useCallback(_=>{l.current.push(_)},[]),d=ee.useCallback(_=>{l.current=l.current.filter(f=>f!==_)},[]),m=ee.useMemo(()=>new eR,[]);e?.up&&m.up.set(e.up.x,e.up.y,e.up.z);const p=ee.useRef(new y0);return ee.useImperativeHandle(r,()=>p.current),ee.useEffect(()=>{if(!a.current)return;h_i(a.current);const _=new jge({antialias:!0,alpha:!0});m_i(_),_.setSize(a.current.clientWidth,a.current.clientHeight),_.setPixelRatio(window.devicePixelRatio),a.current.appendChild(_.domElement);const f=a.current.clientWidth/a.current.clientHeight,I=s==="perspective"?new U_(75,f,.1,1e3):new oG(-10*f,10*f,10,-10,-1e3,1e3);u.current?(I.position.copy(u.current.position),I.quaternion.copy(u.current.quaternion),I.up.copy(u.current.up)):(n?.up&&I.up.set(n.up[0],n.up[1],n.up[2]),n?.position&&I.position.set(n.position[0],n.position[1],n.position[2]),I.lookAt(0,0,0)),m.add(p.current),window.__TSCIRCUIT_THREE_OBJECT=p.current,c({scene:m,camera:I,renderer:_,rootObject:p.current,addFrameListener:h,removeFrameListener:d}),g.current?.({camera:I,renderer:_});let C;const y=new aWo,x=()=>{const B=y.getElapsedTime(),b=y.getDelta();l.current.forEach(Q=>Q(B,b)),_.render(m,I),C=requestAnimationFrame(x)};x();const E=()=>{if(a.current){const B=a.current.clientWidth/a.current.clientHeight;I instanceof U_?I.aspect=B:I instanceof oG&&(I.left=-10*B,I.right=10*B,I.top=10,I.bottom=-10),I.updateProjectionMatrix(),_.setSize(a.current.clientWidth,a.current.clientHeight)}};return window.addEventListener("resize",E),()=>{u.current={position:I.position.clone(),quaternion:I.quaternion.clone(),up:I.up.clone()},window.removeEventListener("resize",E),cancelAnimationFrame(C),a.current&&_.domElement&&a.current.removeChild(_.domElement),_.dispose(),m.remove(p.current),window.__TSCIRCUIT_THREE_OBJECT===p.current&&(window.__TSCIRCUIT_THREE_OBJECT=void 0)}},[m,h,d,s]),U.jsx("div",{ref:a,style:{width:"100%",height:"100%",...o},children:A&&U.jsx(rtn.Provider,{value:A,children:U.jsx(xpi,{children:t})})})}),__i=`
5308
5308
  varying vec3 worldPosition;
5309
5309
  void main() {
5310
5310
  worldPosition = (modelMatrix * vec4(position, 1.0)).xyz;
@@ -5584,7 +5584,7 @@ test("${c} should solve problem correctly", () => {
5584
5584
  // Add more specific assertions based on expected output
5585
5585
  // expect(solver.netLabelPlacementSolver!.netLabelPlacements).toMatchInlineSnapshot()
5586
5586
  })
5587
- `,g=new Blob([l],{type:"text/plain"}),u=URL.createObjectURL(g),h=document.createElement("a");h.href=u,h.download=`${c}.test.ts`,h.click(),URL.revokeObjectURL(u)}catch(A){alert(`Error generating test.ts for ${t.getSolverName()}: ${A instanceof Error?A.message:String(A)}`)}o(!1)};return U.jsxs("div",{className:`relative ${e}`,ref:i,children:[U.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>o(!n),title:`Download options for ${t.getSolverName()}`,children:t.getSolverName()}),n&&U.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:[U.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:r,children:"Download JSON"}),U.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),U.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:a,children:"Download test.ts"})]})]})},jcn=t=>t.activeSubSolver?[t,...jcn(t.activeSubSolver)]:[t],VPi=({solver:t})=>{const e=jcn(t);return U.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:e.map((n,o)=>U.jsxs("div",{className:"flex items-center",children:[o>0&&U.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),U.jsx(KPi,{solver:n})]},n.getSolverName()))})},zPi=({solver:t,triggerRender:e,animationSpeed:n=25,renderer:o,onRendererChange:i,onAnimationSpeedChange:r,onDownloadVisualization:s,onSolverStarted:a,onSolverCompleted:A})=>{const[c,l]=ee.useReducer(B=>!B,!1),g=ee.useRef(void 0),u=ee.useRef(null),h="solver-debugger-last-iteration",[d,m]=ee.useState(null),p=ee.useRef(null),_=ee.useMemo(()=>[{label:"Slow",value:250,description:"250ms"},{label:"Normal",value:100,description:"100ms"},{label:"Fast",value:10,description:"10ms"},{label:"Fast (2x)",value:5,description:"5ms"},{label:"Fast (10x)",value:1,description:"1ms"},{label:"Fast 20x",value:.5,description:"2 steps / 1ms"},{label:"Fast 100x",value:.1,description:"10 steps / 1ms"}],[]),f=()=>{const B=Math.max(1,n),b=n<1?Math.round(1/n):1;g.current=setInterval(()=>{if(t.solved||t.failed){g.current&&(clearInterval(g.current),g.current=void 0),l(),e(),A&&t.solved&&A(t);return}for(let Q=0;Q<b&&!(t.solved||t.failed);Q++)t.step();e()},B)},I=()=>{g.current&&(clearInterval(g.current),g.current=void 0)},C=()=>{!t.solved&&!t.failed&&(t.step(),e())},y=()=>{!t.solved&&!t.failed&&(a&&a(t),t.solve(),e(),A&&A(t))},x=()=>{c?(I(),l()):(l(),f())},E=()=>{if(t.solved||t.failed||c)return;u.current===null&&typeof window<"u"&&(u.current=window.localStorage.getItem(h));const B=window.prompt("Step until which iteration?",u.current??`${t.iterations}`);if(B===null)return;u.current=B,typeof window<"u"&&window.localStorage.setItem(h,B);const b=Number(B);if(!Number.isFinite(b)){window.alert("Please enter a valid number for the iteration");return}for(;t.iterations<b&&!t.solved&&!t.failed;)t.step();e(),t.solved&&A&&A(t)};return ee.useEffect(()=>()=>{I()},[]),ee.useEffect(()=>{(t.solved||t.failed)&&c&&(I(),l())},[t.solved,t.failed,c]),ee.useEffect(()=>{c&&(I(),f())},[n,c]),ee.useEffect(()=>{if(typeof document>"u")return;const B=b=>{p.current&&!p.current.contains(b.target)&&m(null)};return document.addEventListener("mousedown",B),()=>{document.removeEventListener("mousedown",B)}},[]),U.jsxs("div",{className:"space-y-2 p-2 border-b",children:[U.jsx("div",{className:"flex items-center",children:U.jsxs("div",{className:"flex items-center gap-2",ref:p,children:[U.jsxs("div",{className:"flex h-9 items-center space-x-1 rounded-md border border-slate-200 bg-white p-1 shadow-sm",children:[U.jsxs("div",{className:"relative",children:[U.jsx("button",{type:"button",onClick:()=>m(d==="renderer"?null:"renderer"),className:"flex select-none items-center rounded-sm px-3 py-1 text-sm font-medium outline-none focus:bg-slate-100 data-[state=open]:bg-slate-100","data-state":d==="renderer"?"open":"closed",children:"Renderer"}),d==="renderer"&&U.jsx("div",{className:"absolute left-0 z-50 mt-1 min-w-[10rem] rounded-md border border-slate-200 bg-white p-1 text-slate-950 shadow-md",children:["vector","canvas"].map(B=>U.jsxs("button",{type:"button",onClick:()=>{i(B),m(null)},className:"flex w-full items-center rounded-sm px-2 py-1.5 text-sm hover:bg-slate-100",children:[B==="vector"?"Vector":"Canvas",o===B&&U.jsx("span",{className:"ml-auto text-xs text-slate-500",children:"✓"})]},B))})]}),U.jsxs("div",{className:"relative",children:[U.jsx("button",{type:"button",onClick:()=>m(d==="debug"?null:"debug"),className:"flex select-none items-center rounded-sm px-3 py-1 text-sm font-medium outline-none focus:bg-slate-100 data-[state=open]:bg-slate-100","data-state":d==="debug"?"open":"closed",children:"Debug"}),d==="debug"&&U.jsx("div",{className:"absolute left-0 z-50 mt-1 min-w-[12rem] rounded-md border border-slate-200 bg-white p-1 text-slate-950 shadow-md",children:U.jsx("button",{type:"button",onClick:()=>{s(),m(null)},className:"flex w-full items-center rounded-sm px-2 py-1.5 text-sm hover:bg-slate-100",children:"Download Visualization"})})]}),U.jsxs("div",{className:"relative",children:[U.jsx("button",{type:"button",onClick:()=>m(d==="animation"?null:"animation"),className:"flex select-none items-center rounded-sm px-3 py-1 text-sm font-medium outline-none focus:bg-slate-100 data-[state=open]:bg-slate-100","data-state":d==="animation"?"open":"closed",children:"Animation"}),d==="animation"&&U.jsx("div",{className:"absolute left-0 z-50 mt-1 min-w-[12rem] rounded-md border border-slate-200 bg-white p-1 text-slate-950 shadow-md",children:_.map(B=>U.jsxs("button",{type:"button",onClick:()=>{r(B.value),m(null)},className:"flex w-full items-center rounded-sm px-2 py-1.5 text-sm hover:bg-slate-100",children:[B.label,U.jsx("span",{className:"ml-auto text-xs text-slate-500",children:B.description}),n===B.value&&U.jsx("span",{className:"ml-2 text-xs text-slate-500",children:"✓"})]},B.value))})]})]}),U.jsx(VPi,{solver:t})]})}),U.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[U.jsx("button",{onClick:C,disabled:t.solved||t.failed||c,className:"bg-blue-500 hover:bg-blue-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step"}),U.jsx("button",{onClick:y,disabled:t.solved||t.failed||c,className:"bg-green-500 hover:bg-green-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Solve"}),U.jsx("button",{onClick:x,disabled:t.solved||t.failed,className:`px-3 py-1 rounded text-white text-sm ${c?"bg-red-500 hover:bg-red-600":"bg-yellow-500 hover:bg-yellow-600"} disabled:bg-gray-300`,children:c?"Stop":"Animate"}),U.jsx("button",{onClick:E,disabled:t.solved||t.failed||c,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"}),U.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",t.iterations]}),t.timeToSolve!==void 0&&U.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(t.timeToSolve/1e3).toFixed(3),"s"]}),t.solved&&U.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),t.failed&&U.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),t.error&&U.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",t.error]})]})},JPi=t=>t!==null&&"pipelineDef"in t&&Array.isArray(t.pipelineDef),WPi=(t,e,n)=>{const o=t.currentPipelineStageIndex;return e<o?"Completed":e===o&&t.activeSubSolver?t.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},jPi=(t,e)=>{const o=t.pipelineDef[e].solverName,i=WPi(t,e),r=t[o],s=t.firstIterationOfStage?.[o]??(e===t.currentPipelineStageIndex?t.iterations:null),a=t.iterations;let A=0;if(i==="Completed"){const u=t.pipelineDef[e+1],h=u?t.firstIterationOfStage?.[u.solverName]:void 0;h!==void 0&&s!==null?A=h-s:s!==null&&(A=a-s)}else i==="In Progress"&&s!==null&&(A=a-s);const c=t.timeSpentOnStage?.[o]??0;let l=0;i==="Completed"?l=1:i==="In Progress"&&r&&(l=r.progress??0);const g=r?.stats??null;return{index:e,name:o,status:i,firstIteration:s,iterations:A,progress:l,timeSpent:c,stats:g&&Object.keys(g).length>0?g:null,solverInstance:r??null}},XPi=({status:t})=>{const e={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return U.jsx("span",{className:`font-medium ${e[t]}`,children:t})},qPi=({progress:t})=>{if(t===0)return null;const e=Math.round(t*100);return U.jsxs("div",{className:"flex items-center gap-2",children:[U.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:U.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${e}%`}})}),U.jsxs("span",{className:"text-xs text-gray-500",children:[e,"%"]})]})},Xcn=t=>{if(typeof t=="string")return t;if(typeof t=="number"||typeof t=="boolean"||typeof t=="bigint"||t==null)return String(t);if(typeof t=="object")try{return JSON.stringify(t)}catch{return String(t)}return String(t)},$Pi=t=>Object.entries(t).map(([e,n])=>`${e}: ${Xcn(n)}`).join(", "),ZPi=({stats:t})=>{if(!t||Object.keys(t).length===0)return U.jsx("span",{children:"-"});const e=Object.entries(t),n=$Pi(t);return U.jsxs("details",{className:"cursor-pointer",children:[U.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:n}),U.jsx("div",{className:"mt-1 text-xs",children:e.map(([o,i])=>U.jsxs("div",{children:[o,": ",Xcn(i)]},o))})]})},mJe=t=>{if(t===null||typeof t!="object")return t;if(Array.isArray(t))return t.map(mJe);const e={};for(const[n,o]of Object.entries(t))n.startsWith("_")||(e[n]=mJe(o));return e},ewi=(t,e)=>{try{if(typeof t.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${e}`);return}const n=mJe(t.getConstructorParams()),o=new Blob([JSON.stringify(n,null,2)],{type:"application/json"}),i=URL.createObjectURL(o),r=document.createElement("a");r.href=i,r.download=`${e}_input.json`,r.click(),URL.revokeObjectURL(i)}catch(n){alert(`Error downloading input for ${e}: ${n instanceof Error?n.message:String(n)}`)}},twi=({expanded:t})=>U.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:`w-4 h-4 transition-transform duration-200 ${t?"rotate-90":""}`,children:U.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"})}),qcn=t=>{let e=t;for(;e.activeSubSolver;)e=e.activeSubSolver;return e},$cn=({solver:t,onStepUntilPhase:e,onDownloadInput:n,isNested:o=!1,indentLevel:i=0,triggerRender:r})=>{const[s,a]=ee.useState(new Set),A=t.pipelineDef.map((p,_)=>jPi(t,_)),c=p=>{a(_=>{const f=new Set(_);return f.has(p)?f.delete(p):f.add(p),f})},l=p=>{e?.(p)},g=p=>{p.solverInstance&&(n?n(p.solverInstance,p.name):ewi(p.solverInstance,p.name))},u=p=>`${(p/1e3).toFixed(2)}s`,h=()=>{if(!t.solved&&!t.failed){const p=t.activeSubSolver;for(;!t.solved&&!t.failed&&(t.step(),!(t.activeSubSolver&&t.activeSubSolver!==p)););r?.()}},d=()=>{if(!t.solved&&!t.failed){const p=qcn(t);for(;!t.solved&&!t.failed&&(t.step(),qcn(t)===p););r?.()}},m=i*24;return U.jsxs("div",{className:o?"":"border-t border-gray-200",children:[!o&&U.jsxs("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200 flex items-center justify-between",children:[U.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Stages"}),U.jsxs("div",{className:"flex gap-2",children:[U.jsx("button",{onClick:d,disabled:t.solved||t.failed,className:"bg-indigo-500 hover:bg-indigo-600 disabled:bg-gray-300 disabled:cursor-not-allowed cursor-pointer text-white px-3 py-1 rounded text-sm",children:"Next Solver"}),U.jsx("button",{onClick:h,disabled:t.solved||t.failed,className:"bg-purple-500 hover:bg-purple-600 disabled:bg-gray-300 disabled:cursor-not-allowed cursor-pointer text-white px-3 py-1 rounded text-sm",children:"Next Stage"})]})]}),U.jsx("div",{className:"overflow-x-auto",children:U.jsxs("table",{className:"w-full text-sm",children:[!o&&U.jsx("thead",{children:U.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[U.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stage"}),U.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),U.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",U.jsx("sub",{children:"0"})]}),U.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),U.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),U.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),U.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),U.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),U.jsx("tbody",{children:A.map(p=>{const _=JPi(p.solverInstance),f=s.has(p.name);return U.jsxs(Ms.Fragment,{children:[U.jsxs("tr",{className:`border-b border-gray-100 ${p.status==="In Progress"?"bg-yellow-50":""}`,children:[U.jsx("td",{className:"px-4 py-2",children:U.jsxs("div",{className:"flex items-center gap-2",style:{paddingLeft:m},children:[_?U.jsx("button",{onClick:()=>c(p.name),className:"text-gray-500 hover:text-gray-700",title:f?"Collapse":"Expand",children:U.jsx(twi,{expanded:f})}):U.jsx("span",{className:"w-4"}),U.jsx("span",{className:"text-gray-400 w-6",children:String(p.index+1).padStart(2,"0")}),U.jsx("button",{onClick:()=>l(p.name),disabled:p.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 ${p.name} completes`,children:U.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:U.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"})})}),U.jsx("span",{className:"font-medium text-gray-900",children:p.name})]})}),U.jsx("td",{className:"px-4 py-2",children:U.jsx(XPi,{status:p.status})}),U.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:p.firstIteration!==null?p.firstIteration:""}),U.jsx("td",{className:"px-4 py-2 text-gray-600",children:p.iterations}),U.jsx("td",{className:"px-4 py-2",children:U.jsx(qPi,{progress:p.progress})}),U.jsx("td",{className:"px-4 py-2 text-gray-600",children:u(p.timeSpent)}),U.jsx("td",{className:"px-4 py-2 text-gray-500",children:U.jsx(ZPi,{stats:p.stats})}),U.jsx("td",{className:"px-4 py-2",children:p.solverInstance?U.jsxs("button",{onClick:()=>g(p),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${p.name}`,children:[U.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:U.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"})}),U.jsx("span",{children:"Input"})]}):null})]}),_&&f&&U.jsx("tr",{children:U.jsx("td",{colSpan:8,className:"p-0",children:U.jsx($cn,{solver:p.solverInstance,onStepUntilPhase:e,onDownloadInput:n,isNested:!0,indentLevel:i+1,triggerRender:r})})})]},p.name)})})]})})]})};function nwi({graphics:t}){const e=t.points??[],n=t.lines??[],o=t.rects??[],i=t.circles??[],r=t.texts??[];let s=Number.POSITIVE_INFINITY,a=Number.POSITIVE_INFINITY,A=Number.NEGATIVE_INFINITY,c=Number.NEGATIVE_INFINITY;const l=(p,_)=>{typeof p=="number"&&(p<s&&(s=p),p>A&&(A=p)),typeof _=="number"&&(_<a&&(a=_),_>c&&(c=_))};for(const p of e)l(p.x,p.y);for(const p of n){const _=p.points??[];for(const f of _)l(f.x,f.y)}for(const p of o){const _=p.x??0,f=p.y??0,I=p.width??0,C=p.height??0;l(_,f),l(_+I,f+C)}for(const p of i){const _=p.x??0,f=p.y??0,I=p.radius??1;l(_-I,f-I),l(_+I,f+I)}for(const p of r)l(p.x,p.y);(!isFinite(s)||!isFinite(a)||!isFinite(A)||!isFinite(c))&&(s=-20,a=-20,A=20,c=20);const g=10,u=s-g,h=a-g,d=Math.max(1,A-s+2*g),m=Math.max(1,c-a+2*g);return U.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${u} ${h} ${d} ${m}`,role:"img","aria-label":"Graphics fallback",children:[o.map((p,_)=>U.jsx("rect",{x:p.x??0,y:p.y??0,width:p.width??0,height:p.height??0,fill:"none",stroke:p.strokeColor??"black",strokeWidth:p.strokeWidth??1},`rect-${_}`)),n.map((p,_)=>U.jsx("polyline",{fill:"none",stroke:p.strokeColor??"black",strokeWidth:p.strokeWidth??1,points:(p.points??[]).map(f=>`${f.x??0},${f.y??0}`).join(" ")},`line-${_}`)),i.map((p,_)=>U.jsx("circle",{cx:p.x??0,cy:p.y??0,r:p.radius??1.5,fill:p.fillColor??"none",stroke:p.strokeColor??"black",strokeWidth:p.strokeWidth??1},`circle-${_}`)),e.map((p,_)=>U.jsx("circle",{cx:p.x??0,cy:p.y??0,r:p.radius??1.5,fill:p.color??"black"},`point-${_}`)),r.map((p,_)=>U.jsx("text",{x:p.x??0,y:p.y??0,fontSize:p.fontSize??10,fill:p.color??"black",children:p.text??""},`text-${_}`))]})}var owi=class extends Ms.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}},iwi=({solver:t,createSolver:e,animationSpeed:n=25,onSolverStarted:o,onSolverCompleted:i})=>{const[r,s]=ee.useReducer(f=>f+1,0),[a]=ee.useState(()=>{if(e)return e();if(!t)throw new Error("GenericSolverDebugger requires solver or createSolver");return t}),[A,c]=ee.useState(()=>typeof window>"u"?"vector":window.localStorage.getItem("solver-utils-renderer")==="canvas"?"canvas":"vector"),[l,g]=ee.useState(n),u=ee.useMemo(()=>{try{return a.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(f){return console.error("Visualization error:",f),{points:[],lines:[],rects:[],circles:[]}}},[a,r]),h=ee.useMemo(()=>(u.rects?.length||0)===0&&(u.lines?.length||0)===0&&(u.points?.length||0)===0&&(u.circles?.length||0)===0,[u]);ee.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const f=document.createElement("script");f.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(f)}},[]),ee.useEffect(()=>{g(n)},[n]);const d=a.pipelineDef!==void 0,m=f=>{const I=a;if(!a.solved&&!a.failed){for(;!a.solved&&!a.failed&&I.currentPipelineStageIndex<=I.pipelineDef.findIndex(C=>C.solverName===f);)a.step();s()}},p=()=>{const f=JSON.stringify(u,null,2),I=new Blob([f],{type:"application/json"}),C=URL.createObjectURL(I),y=document.createElement("a");y.download="visualization.json",y.href=C,document.body.appendChild(y),y.click(),document.body.removeChild(y),URL.revokeObjectURL(C)},_=f=>{c(f),typeof window<"u"&&window.localStorage.setItem("solver-utils-renderer",f)};return U.jsxs("div",{children:[U.jsx(zPi,{solver:a,triggerRender:s,animationSpeed:l,renderer:A,onRendererChange:_,onAnimationSpeedChange:g,onDownloadVisualization:p,onSolverStarted:o,onSolverCompleted:i}),h?U.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):U.jsx(owi,{fallback:U.jsx(nwi,{graphics:u}),children:A==="canvas"?U.jsx(UPi,{graphics:u}):U.jsx(OPi,{graphics:u})}),d&&U.jsx($cn,{solver:a,onStepUntilPhase:m,triggerRender:s})]})};const rwi=()=>{ee.useEffect(()=>{const t="tailwind-cdn-script";if(document.getElementById(t)||window.tailwind)return;const e=document.createElement("div");e.className="hidden",document.body.appendChild(e);const n=window.getComputedStyle(e).display==="none";if(document.body.removeChild(e),n)return;const o=document.createElement("script");o.id=t,o.src="https://cdn.tailwindcss.com",document.head.appendChild(o)},[])},swi=1e3,_E=(t,e)=>{const{fileName:n,mimeType:o="text/plain"}=e,i=t instanceof Blob?t:new Blob([t],{type:o}),r=URL.createObjectURL(i),s=document.createElement("a");s.href=r,s.download=n,s.target="_blank",s.rel="noopener noreferrer",s.style.display="none",document.body.appendChild(s),s.click(),document.body.removeChild(s),setTimeout(()=>{URL.revokeObjectURL(r)},swi)},pJe=t=>{let e=t.trim().replace(/[\\/:*?"<>|]/g,"_").replace(/[\x00-\x1f]/g,"").replace(/^\.+/,"").replace(/\.+$/,"").replace(/\s+/g," ").replace(/_+/g,"_");return/^(con|prn|aux|nul|com[0-9]|lpt[0-9])$/i.test(e)&&(e=`_${e}`),e=e.slice(0,200),e||"untitled"},awi=t=>{const e=t.solverConstructorArgs??[t.solverParams];if(t.solverName!=="AutoroutingPipelineSolver7_MultiGraph"||e.length!==1)return e;const[{input:n,options:o}]=e;return[n,o]},x7="https://github.com/tscircuit/tscircuit-autorouter/issues/new",Zcn="https://github.com/tscircuit/copper-pour-solver/issues/new",eln="https://github.com/tscircuit/calculate-packing/issues/new",Awi="https://github.com/tscircuit/matchpack/issues/new",tln="https://github.com/tscircuit/schematic-trace-solver/issues/new?template=json-bug-report.yml",cwi={PackSolver2:eln,LayoutPipelineSolver:Awi,AutoroutingPipelineSolver:x7,AssignableAutoroutingPipeline2:x7,AssignableAutoroutingPipeline3:x7,AutoroutingPipeline1_OriginalUnravel:x7,AutoroutingPipelineSolver3_HgPortPointPathing:x7,AutoroutingPipelineSolver4:x7,AutoroutingPipelineSolver5:x7,AutoroutingPipelineSolver7_MultiGraph:x7,AutoroutingPipelineSolver8:x7,CopperPourPipelineSolver:Zcn,SchematicTracePipelineSolver:tln},lwi=t=>t.toLowerCase().includes("pack")?Ern:t.toLowerCase().includes("rout")?Srn:Jxi,nln=t=>{const e=cwi[t];if(e)return e;const n=t.toLowerCase();return n.includes("autorout")?x7:n.includes("schematic")&&n.includes("trace")?tln:n.includes("copperpour")?Zcn:n.includes("pack")?eln:null},gwi=t=>`${pJe(`${t.componentName}-${t.solverName}`)}-solver-input.json`,oln=t=>{_E(JSON.stringify(t.solverParams,null,2),{fileName:gwi(t),mimeType:"application/json"})},uwi=({solverEvent:t})=>{const e=nln(t.solverName);return U.jsxs("div",{className:"rf-flex rf-items-center rf-justify-end rf-gap-2 rf-border-b rf-border-gray-200 rf-bg-gray-50 rf-px-4 rf-py-2",children:[U.jsxs(uA,{type:"button",variant:"outline",size:"sm",onClick:()=>oln(t),children:[U.jsx(Hq,{className:"rf-w-4 rf-h-4"}),"Download"]}),e?U.jsx(uA,{asChild:!0,variant:"outline",size:"sm",children:U.jsxs("a",{href:e,target:"_blank",rel:"noopener noreferrer",children:[U.jsx(dhe,{className:"rf-w-4 rf-h-4"}),"Report"]})}):U.jsxs(uA,{type:"button",variant:"outline",size:"sm",disabled:!0,title:"No report link configured for this solver",children:[U.jsx(dhe,{className:"rf-w-4 rf-h-4"}),"Report"]})]})},dwi=({solverEvent:t})=>{const e=nln(t.solverName);return e?U.jsx(uA,{asChild:!0,variant:"ghost",size:"icon",className:"rf-h-8 rf-w-8",children:U.jsx("a",{href:e,target:"_blank",rel:"noopener noreferrer",title:"Report solver bug","aria-label":"Report solver bug",children:U.jsx(dhe,{className:"rf-w-4 rf-h-4"})})}):U.jsx(uA,{type:"button",variant:"ghost",size:"icon",className:"rf-h-8 rf-w-8",disabled:!0,title:"No report link configured for this solver","aria-label":"Report solver bug",children:U.jsx(dhe,{className:"rf-w-4 rf-h-4"})})},hwi=({solverEvents:t=[]})=>{const[e,n]=ee.useState(null);rwi();const o=ee.useMemo(()=>{const a=new Map;for(const A of t){const c=`${A.componentName}-${A.solverName}`;a.set(c,A)}return a},[t]),i=ee.useMemo(()=>Array.from(o.keys()),[o]),r=e?o.get(e):null,s=ee.useMemo(()=>{if(!r)return{instance:null,error:null,classFound:!1};const a=Vve[r.solverName];if(!a)return{instance:null,error:`Solver class "${r.solverName}" not found in SOLVERS registry. Available: ${Object.keys(Vve).join(", ")}`,classFound:!1};try{return{instance:new a(...awi(r)),error:null,classFound:!0}}catch(A){const c=A instanceof Error?A.message:String(A);return console.error("Failed to reconstruct solver:",A),{instance:null,error:`Failed to instantiate solver: ${c}`,classFound:!0}}},[r]);return t.length===0?U.jsx("div",{className:"rf-p-4",children:U.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:U.jsxs("div",{className:"rf-p-4",children:[U.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),U.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."})]})})}):U.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[U.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[U.jsxs("div",{className:"rf-text-xs rf-font-semibold rf-text-gray-500 rf-px-3 rf-py-2 rf-bg-gray-50 rf-border-b rf-border-gray-200",children:[i.length," ",i.length===1?"Solver":"Solvers"]}),i.map(a=>{const A=o.get(a),c=e===a;return U.jsx("div",{className:`rf-px-3 rf-py-2 rf-cursor-pointer rf-border-b rf-border-gray-100 ${c?"rf-bg-blue-50 rf-border-l-2 rf-border-l-blue-500":"hover:rf-bg-gray-50"}`,onClick:()=>n(a),children:(()=>{const l=lwi(A.solverName);return U.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[U.jsx(l,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),U.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[U.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:A.componentName}),U.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:A.solverName})]})]})})()},a)})]}),U.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:r?s.instance?U.jsxs("div",{className:"rf-flex rf-h-full rf-flex-col rf-overflow-y-auto",children:[U.jsx(uwi,{solverEvent:r}),U.jsx("div",{className:"rf-min-h-0 rf-flex-1",children:U.jsx(rE,{fallback:U.jsx("div",{className:"rf-p-4",children:U.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[U.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),U.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",r.solverName]})]})}),children:U.jsx(iwi,{solver:s.instance})})})]}):U.jsxs("div",{className:"rf-p-4",children:[U.jsxs("div",{className:"rf-mb-4",children:[U.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:r.solverName}),U.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",r.componentName]})]}),s.error&&U.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:U.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),U.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[U.jsxs("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50 rf-flex rf-items-center rf-justify-between rf-gap-2",children:[U.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"}),U.jsxs("div",{className:"rf-flex rf-items-center rf-gap-1",children:[U.jsx(dwi,{solverEvent:r}),U.jsx(uA,{type:"button",variant:"ghost",size:"icon",className:"rf-h-8 rf-w-8","aria-label":"Download solver input JSON",title:"Download solver input JSON",onClick:()=>oln(r),children:U.jsx(Hq,{className:"rf-w-4 rf-h-4"})})]})]}),U.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:U.jsx("pre",{className:"rf-text-xs rf-font-mono rf-text-gray-600 rf-whitespace-pre-wrap rf-overflow-x-auto",children:JSON.stringify(r.solverParams,null,2)})})]})]}):U.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:U.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},mwi=["subcircuit_id","componentDisplayName","phaseName","routingPhaseIndex","phaseOrdinal","phaseCount","phaseStageIndex","phaseStageCount","connectionCount","obstacleCount","previousTraceCount","isReroutePhase","autorouterName","autorouterVersion","solverName","effort","cacheStatus"],pwi=["phaseOrdinal","routingPhaseIndex","phaseName","phaseStageIndex"];function _wi(t,e){let n=-1,o=-1;for(let i=t.length-1;i>=0;i--){const r=t[i];if(r.status!=="running"||r.subcircuit_id!==e.subcircuit_id||r.componentDisplayName!==e.componentDisplayName)continue;let s=0,a=!1;for(const A of pwi)if(!(r[A]===void 0||e[A]===void 0)){if(r[A]!==e[A]){a=!0;break}s++}!a&&s>o&&(n=i,o=s)}return n}function fwi(t,e){const n=Object.fromEntries(mwi.filter(s=>e[s]!==void 0).map(s=>[s,e[s]])),o=e.simpleRouteJson?structuredClone(e.simpleRouteJson):void 0,i=e.type==="autorouting:start"?-1:_wi(t,e),r={...i===-1?{id:`autorouting_phase_${t.length+1}`}:t[i],...n,status:e.type==="autorouting:start"?"running":e.type==="autorouting:end"?"complete":"error",...e.type==="autorouting:start"?{startSimpleRouteJson:o}:e.type==="autorouting:end"?{endSimpleRouteJson:o}:{errorSimpleRouteJson:o,error:e.error?{...e.error}:void 0}};return i===-1?[...t,r]:t.map((s,a)=>a===i?r:s)}const Iwi=new Map([["custom","Custom"],["fanout","Fanout"],["single_layer_fanout","Single layer fanout"],["tscircuit_simplify","Simplify"]]),Cwi=new Set(["tscircuit","default","auto","auto_local"]);function ywi(t){if(t==="FanoutSolver")return"Fanout";if(t==="AutoroutingPipelineSolver11_Simplification")return"Simplify";const e=t.match(/^AutoroutingPipeline(?:Solver)?(\d+)(?:_|$)/);if(e)return`Pipeline${e[1]}`;const n=t.match(/^AssignableAutoroutingPipeline(\d+)$/);return n?`Assignable${n[1]}`:t}function xwi(t){const e=t.autorouterName?.trim(),n=e?.replace(/-/g,"_"),o=n&&Iwi.get(n);if(o)return o;if(n&&!Cwi.has(n))return e;const i=t.solverName?.trim();if(i)return ywi(i);const r=t.autorouterVersion?.trim();if(r){const s=r.match(/^beta[_-]pipeline(\d+)$/);return s?`Pipeline${s[1]}`:r==="latest"?"default":r}return e?"default":"Unknown"}const _Je="#fbbf24";function Ewi(t){const e=t.endSimpleRouteJson?.traces??[],n=new Set(e.flatMap(i=>[i.pcb_trace_id,i.__replaces_pcb_trace_id].filter(r=>r!==void 0)));return[...(t.startSimpleRouteJson?.traces??[]).filter(i=>!n.has(i.pcb_trace_id)),...e]}function iln(t){const e=new Map((t.startSimpleRouteJson?.traces??[]).map(n=>[n.pcb_trace_id,n]));return(t.endSimpleRouteJson?.traces??[]).filter(n=>{const o=e.get(n.pcb_trace_id);return!o||!!n.__replaces_pcb_trace_id&&n.__replaces_pcb_trace_id!==o.__replaces_pcb_trace_id||JSON.stringify(o.route)!==JSON.stringify(n.route)}).map(n=>n.pcb_trace_id)}function Bwi(t,e){return{outer_diameter:t.via_diameter??e.minViaPadDiameter??e.min_via_pad_diameter??e.minViaDiameter??.6,hole_diameter:t.via_hole_diameter??e.minViaHoleDiameter??e.min_via_hole_diameter??.3}}function rln(t,e){const n=[];for(const a of t.route)a.route_type==="wire"?n.push({...a,layer:a.layer}):a.route_type==="via"?n.push({route_type:"via",x:a.x,y:a.y,from_layer:a.from_layer,to_layer:a.to_layer,...Bwi(a,e)}):a.route_type==="through_obstacle"&&n.push({route_type:"through_pad",start:{...a.start},end:{...a.end},width:a.width,start_layer:a.from_layer,end_layer:a.to_layer,pcb_smtpad_id:a.circuitJsonMetadata?.pcb_smtpad_id,pcb_plated_hole_id:a.circuitJsonMetadata?.pcb_plated_hole_id});const o=a=>{let A=-1,c=Number.POSITIVE_INFINITY;return n.forEach((l,g)=>{if(l.route_type!=="wire")return;const u=Math.hypot(l.x-a.x,l.y-a.y);u<c&&(c=u,A=g)}),A},i=t.route.filter(a=>a.route_type==="jumper").map(a=>[o(a.start),o(a.end)].sort((A,c)=>A-c)).filter(([a,A])=>a>=0&&A>a).sort(([a],[A])=>a-A),r=[];let s=0;for(const[a,A]of i)a>=s&&r.push(n.slice(s,a+1)),s=Math.max(s,A);return s<n.length&&r.push(n.slice(s)),r}function Swi(t){const e=[],n=[],o=t.endSimpleRouteJson;if(!o)return{lines:e,circles:n};const i=new Set(iln(t));for(const r of o.traces??[])if(i.has(r.pcb_trace_id))for(const s of rln(r,o)){let a;for(const A of s){if(A.route_type==="through_pad"){a={...A.end,layer:A.end_layer,width:A.width};continue}const c=A.route_type==="wire"?A.layer:A.from_layer;a&&a.layer===c&&(a.x!==A.x||a.y!==A.y)&&e.push({points:[{x:a.x,y:a.y},{x:A.x,y:A.y}],strokeWidth:A.route_type==="wire"?A.width:a.width,strokeColor:_Je,layer:c}),A.route_type==="via"&&n.push({center:{x:A.x,y:A.y},radius:A.outer_diameter/2,stroke:_Je,fill:"transparent"}),a={x:A.x,y:A.y,layer:A.route_type==="wire"?A.layer:A.to_layer,width:A.route_type==="wire"?A.width:a?.width??o.minTraceWidth}}}return{coordinateSystem:"cartesian",lines:e,circles:n}}function bwi(t){const e=JSON.stringify(t);let n=2166136261;for(let o=0;o<e.length;o++)n=Math.imul(n^e.charCodeAt(o),16777619);return(n>>>0).toString(36)}const Qwi=new Set(["pcb_trace","pcb_via","pcb_copper_pour","pcb_ground_plane","pcb_ground_plane_region","pcb_thermal_spoke","pcb_breakout_point"]);function vwi(t,e,n){const o=n==="input"?e.startSimpleRouteJson??e.errorSimpleRouteJson:e.endSimpleRouteJson,i=t.filter(c=>!Qwi.has(c.type)&&!c.type.endsWith("_error")&&!c.type.endsWith("_warning"));if(!o)return i;const r=n==="input"?o.traces??[]:Ewi(e),s=new Set(t.filter(c=>c.type==="source_trace").map(c=>c.source_trace_id)),a=["top",...Array.from({length:Math.max(0,o.layerCount-2)},(c,l)=>`inner${l+1}`),...o.layerCount>1?["bottom"]:[]],A=[];for(const c of r){const g=o.connections.find(h=>h.name===c.connection_name||h.source_trace_id===c.connection_name)?.source_trace_id??c.connection_name??"",u=rln(c,o);for(const[h,d]of u.entries()){const m={type:"pcb_trace",pcb_trace_id:`${e.id}_${n}_${c.pcb_trace_id}_${h}_${bwi(d)}`,subcircuit_id:e.subcircuit_id??void 0,source_trace_id:s.has(g)?g:void 0,route:d};A.push(m);for(const[p,_]of d.entries()){if(_.route_type!=="via")continue;const f=a.indexOf(_.from_layer),I=a.indexOf(_.to_layer),C={type:"pcb_via",pcb_via_id:`${m.pcb_trace_id}_via_${p}`,pcb_trace_id:m.pcb_trace_id,subcircuit_id:e.subcircuit_id??void 0,x:_.x,y:_.y,outer_diameter:_.outer_diameter,hole_diameter:_.hole_diameter,layers:f>=0&&I>=0?a.slice(Math.min(f,I),Math.max(f,I)+1):[_.from_layer,_.to_layer]};A.push(C)}}}return[...i,...A]}const fJe=(t,e)=>t.phaseName||`Phase ${t.phaseOrdinal??e+1}`,sln=t=>t.componentDisplayName?.match(/name="([^"]+)"/)?.[1]?.replace(/^\./,"")||t.componentDisplayName||t.subcircuit_id||"Board",aln=t=>t.startSimpleRouteJson??t.endSimpleRouteJson??t.errorSimpleRouteJson,Pwi={is_showing_autorouting:!0,is_showing_rats_nest:!1,is_showing_drc_errors:!1,is_showing_drc_warnings:!1,is_showing_pcb_groups:!1},wwi=({circuitJson:t,phases:e=[],isRunning:n=!1})=>{const[o,i]=ee.useState(null),[r,s]=ee.useState("output"),[a,A]=ee.useState(!0),[c,l]=ee.useState(!1),g=ee.useRef(null),[u,h]=ee.useState(480),d=o?e.findIndex(R=>R.id===o.id&&aln(R)===aln(o)):-1,m=d<0?e.length-1:d,p=e[m],_=d<0,f=!!p?.endSimpleRouteJson,I=p?.startSimpleRouteJson??p?.errorSimpleRouteJson,C=!!I,y=r==="output"&&!f?"input":r==="input"&&!C?"output":r,x=y==="input"?I:p?.endSimpleRouteJson,E=ee.useMemo(()=>!p||!x?null:vwi(t??[],p,y),[t,p,x,y]),B=ee.useMemo(()=>p&&y==="output"&&a?Swi(p):{lines:[],circles:[]},[p,y,a]);if(ee.useLayoutEffect(()=>{const R=g.current;if(!R)return;const H=()=>h(Math.max(360,R.clientHeight));H();const G=new ResizeObserver(H);return G.observe(R),()=>G.disconnect()},[!!p]),!p)return U.jsxs("div",{className:"rf-flex rf-min-h-[400px] rf-flex-col rf-items-center rf-justify-center rf-gap-3 rf-p-8 rf-text-center",children:[U.jsx(Srn,{className:"rf-h-7 rf-w-7 rf-text-blue-500"}),U.jsx("h3",{className:"rf-text-base rf-font-medium",children:n?"Waiting for autorouting":"No autorouting captures"}),U.jsx("p",{className:"rf-max-w-md rf-text-sm rf-text-gray-500",children:n?"Phases appear as the circuit routes. Each capture includes its input and output on the PCB.":"Run a circuit with autorouting enabled to inspect its phases. A circuit JSON file alone does not include routing history."})]});const b=fJe(p,m),Q=p.status==="running"&&n,w=!f,D=I?.connections.length,k=E?.filter(R=>R.type==="pcb_trace").length??0;return U.jsxs("div",{className:"rf-flex rf-h-full rf-min-h-[620px] rf-flex-col rf-bg-white md:rf-flex-row","data-testid":"autorouting-explorer",children:[U.jsxs("aside",{className:"rf-flex rf-shrink-0 rf-flex-col rf-border-b rf-border-gray-200 md:rf-w-52 md:rf-border-b-0 md:rf-border-r","aria-label":"Routing phases",children:[U.jsxs("div",{className:"rf-flex rf-items-center rf-justify-between rf-px-3 rf-py-2 rf-text-xs rf-text-gray-500",children:[U.jsx("span",{children:"Routing phases"}),U.jsx("span",{children:e.length})]}),U.jsx("div",{className:"rf-flex rf-gap-1 rf-overflow-x-auto rf-px-1.5 rf-pb-1.5 md:rf-flex-col md:rf-overflow-x-hidden md:rf-overflow-y-auto",children:e.map((R,H)=>{const G=iln(R).length,K=R.endSimpleRouteJson?`${G} ${G===1?"trace":"traces"} routed`:R.status==="error"?"Failed":R.status==="running"&&n?"Routing…":"No output";return U.jsxs("button",{type:"button","aria-pressed":H===m,title:`${sln(R)} · ${K}`,onClick:()=>i(R),className:ki("rf-flex rf-min-w-[192px] rf-items-start rf-gap-2 rf-rounded-md rf-border rf-px-2 rf-py-2 rf-text-left md:rf-min-w-0",H===m?"rf-border-blue-200 rf-bg-blue-50":"rf-border-transparent hover:rf-bg-gray-50"),children:[U.jsx("span",{className:ki("rf-flex rf-h-5 rf-w-5 rf-shrink-0 rf-items-center rf-justify-center rf-rounded-full rf-text-[11px]",H===m?"rf-bg-blue-600 rf-text-white":"rf-bg-gray-100 rf-text-gray-500"),children:H+1}),U.jsxs("span",{className:"rf-min-w-0 rf-flex-1",children:[U.jsxs("span",{className:"rf-flex rf-items-center rf-gap-1",children:[U.jsx("span",{className:"rf-min-w-0 rf-flex-1 rf-truncate rf-text-xs rf-font-medium rf-leading-5 rf-text-gray-800",title:fJe(R,H),children:fJe(R,H)}),R.status==="complete"?U.jsx(KS,{"aria-label":"Captured",className:"rf-h-3 rf-w-3 rf-shrink-0 rf-text-green-600"}):R.status==="error"?U.jsx(pVe,{"aria-label":"Failed",className:"rf-h-3 rf-w-3 rf-shrink-0 rf-text-red-500"}):n?U.jsx(sE,{"aria-label":"Routing",className:"rf-h-3 rf-w-3 rf-shrink-0 rf-animate-spin rf-text-blue-500"}):null]}),U.jsxs("span",{className:"rf-block rf-text-[11px] rf-leading-4 rf-text-gray-500",children:[xwi(R)," · ",K]})]})]},R.id)})})]}),U.jsxs("div",{className:"rf-flex rf-min-w-0 rf-flex-1 rf-flex-col",children:[U.jsxs("div",{className:"rf-flex rf-flex-wrap rf-items-center rf-gap-3 rf-border-b rf-border-gray-200 rf-px-4 rf-py-3",children:[U.jsxs("h3",{className:"rf-mr-auto rf-flex rf-items-center rf-gap-2 rf-text-sm rf-font-medium",children:[b,U.jsxs("span",{className:"rf-text-xs rf-font-normal rf-text-gray-500",children:[m+1," of ",e.length]})]}),n&&U.jsx("button",{type:"button",onClick:()=>i(null),disabled:_,className:"rf-text-xs rf-text-blue-600 disabled:rf-text-gray-500",children:_?"Following latest":"Follow latest"}),U.jsx("div",{className:"rf-flex rf-rounded-md rf-bg-gray-100 rf-p-1","aria-label":"Phase snapshot",children:["input","output"].map(R=>U.jsx("button",{type:"button","aria-pressed":y===R,disabled:R==="input"?!C:!f,onClick:()=>s(R),className:ki("rf-rounded rf-px-3 rf-py-1 rf-text-xs disabled:rf-opacity-40",y===R?"rf-bg-white rf-text-gray-900 rf-shadow-sm":"rf-text-gray-500"),children:R==="input"?"Input":"Output"},R))})]}),U.jsxs("div",{className:"rf-flex rf-flex-wrap rf-items-center rf-justify-between rf-gap-2 rf-px-4 rf-py-2 rf-text-xs rf-text-gray-600",children:[U.jsxs("label",{className:"rf-flex rf-items-center rf-gap-2",children:[U.jsx("input",{type:"checkbox",checked:a,disabled:y!=="output",onChange:R=>A(R.target.checked),className:"rf-accent-blue-600"}),U.jsx("span",{"aria-hidden":"true",className:"rf-inline-block rf-h-0.5 rf-w-3",style:{backgroundColor:_Je}}),"Highlight changes (all layers)"]}),U.jsxs("span",{children:[y==="input"?"Before this phase":"After this phase"," ","· ",k," traces"]})]}),w&&U.jsx("div",{className:ki("rf-border-y rf-px-4 rf-py-2 rf-text-xs",p.status==="error"?"rf-border-red-100 rf-bg-red-50 rf-text-red-700":"rf-border-blue-100 rf-bg-blue-50 rf-text-blue-700"),role:"status",children:p.status==="error"?`Routing failed: ${p.error?.message||"No output was captured."}`:Q?"Routing in progress. Showing captured input until output is available.":"No output was captured for this phase. Showing the available input."}),U.jsx("div",{ref:g,className:"rf-relative rf-min-h-[360px] rf-flex-1","data-testid":"autorouting-pcb",children:E?U.jsx(cJe,{circuitJson:E,height:u,allowEditing:!1,clickToInteractEnabled:!1,initialState:Pwi,debugGraphics:B}):U.jsx("div",{className:"rf-p-6 rf-text-sm rf-text-gray-500",children:"No PCB snapshot available for this capture."})}),U.jsxs("div",{className:"rf-flex rf-flex-wrap rf-items-center rf-justify-between rf-gap-2 rf-border-t rf-border-gray-200 rf-px-4 rf-py-3 rf-text-xs rf-text-gray-500",children:[U.jsxs("span",{children:[D===void 0?"Input unavailable":`${D} input connections`,` · ${sln(p)}`]}),U.jsxs("div",{className:"rf-flex rf-items-center rf-gap-4",children:[U.jsxs("button",{type:"button",disabled:!x,onClick:()=>_E(JSON.stringify(x,null,2),{fileName:`${p.id}-${y}.srj.json`,mimeType:"application/json"}),className:"rf-flex rf-items-center rf-gap-1 disabled:rf-opacity-40",children:[U.jsx(Hq,{className:"rf-h-3 rf-w-3"}),"Download SRJ"]}),U.jsxs("button",{type:"button","aria-expanded":c,onClick:()=>l(!c),className:"rf-flex rf-items-center rf-gap-1",children:[U.jsx(NR,{className:ki("rf-h-3 rf-w-3",c&&"rf-rotate-90")}),"Inspect SRJ"]})]})]}),c&&U.jsx("pre",{className:"rf-m-0 rf-max-h-64 rf-overflow-auto rf-border-t rf-border-gray-200 rf-bg-gray-50 rf-p-4 rf-text-xs","aria-label":`${b} ${y} SRJ`,children:x?JSON.stringify(x,null,2):"No snapshot captured."})]})]})},Aln=({errorMessage:t,errorStack:e,circuitJsonErrors:n})=>{ee.useEffect(()=>{if(t){const o=new Error(t);e&&(o.stack=e);try{lO.captureException(o)}catch{}}},[t,e]),ee.useEffect(()=>{if(n&&n.length>0)for(const o of n){const i=new Error(o.message||"Circuit JSON Error");o.stack&&(i.stack=o.stack);try{lO.captureException(i,{error_type:o.type})}catch{}}},[n])},cln=t=>{ee.useEffect(()=>{try{KTo(t)}catch{}},[t.source,t.component,t.isWebEmbedded,t.activeTab])},lln="0.0.2777",Mwi={version:lln},Lme=iRt()(rRt(t=>({lastRunEvalVersion:void 0,setLastRunEvalVersion:e=>{t({lastRunEvalVersion:e})}}),{name:"runframe-runner-store"})),Dwi=t=>{const[e,n]=ee.useState([]),[o,i]=ee.useState(null),[r,s]=ee.useState(""),[a,A]=OH("eval-version-selection",null),c=Lme(h=>h.setLastRunEvalVersion),l=Lme(h=>h.lastRunEvalVersion);return ee.useEffect(()=>{t&&fetch("https://data.jsdelivr.com/v1/package/npm/@tscircuit/eval").then(h=>h.json()).then(h=>{if(Array.isArray(h?.versions)){let d=[...h.versions];h.tags?.latest&&(i(h.tags.latest),d=d.filter(m=>m!==h.tags.latest)),n(d)}}).catch(()=>{})},[t]),ee.useEffect(()=>{t&&(a?(window.TSCIRCUIT_LATEST_EVAL_VERSION=a,c(a)):o&&(window.TSCIRCUIT_LATEST_EVAL_VERSION=o,c(o)))},[t,a,o]),{versions:ee.useMemo(()=>e.filter(h=>h.includes(r)).slice(0,50),[e,r]),latestVersion:o,lastRunEvalVersion:l,search:r,setSearch:s,selectVersion:h=>{A(h),s("")}}},Nwi=({snippetNames:t,onSelect:e,onCancel:n,isOpen:o})=>{const[i,r]=ee.useState(""),[s,a]=ee.useState("");if(!o)return null;const A=t.filter(g=>g.toLowerCase().includes(s.toLowerCase())),c=s&&!t.includes(s),l=g=>{g.key==="Enter"&&(A.length===1?r(A[0]):c&&r(s))};return U.jsx("div",{className:"rf-fixed rf-inset-0 rf-bg-black rf-bg-opacity-50 rf-flex rf-items-center rf-justify-center rf-z-[100]",children:U.jsxs("div",{className:"rf-bg-white rf-rounded-lg rf-p-6 rf-w-96",children:[U.jsx("h2",{className:"rf-text-lg rf-font-semibold rf-mb-4",children:"Select Snippet"}),U.jsx("input",{type:"text",className:"rf-w-full rf-px-4 rf-py-2 rf-border rf-rounded rf-mb-4",placeholder:"Search snippets or new snippet name...",value:s,onChange:g=>a(g.target.value),onKeyDown:l}),U.jsxs("div",{className:"rf-h-60 rf-overflow-y-auto",children:[A.map(g=>U.jsx("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 ${i===g?"bg-blue-50":""}`,onClick:()=>r(g),children:g},g)),c&&U.jsxs("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 text-blue-500 ${i===s?"bg-blue-50":""}`,onClick:()=>r(s),children:['Create new "',s,'"']})]}),U.jsxs("div",{className:"rf-mt-4 rf-flex rf-justify-end rf-gap-2",children:[U.jsx("button",{type:"button",className:"rf-px-4 rf-py-2 rf-text-gray-600 rf-hover:text-gray-800",onClick:n,children:"Cancel"}),U.jsx("button",{type:"button",className:"rf-px-4 rf-py-2 rf-bg-blue-500 rf-text-white rf-rounded rf-hover:bg-blue-600 rf-disabled:opacity-50",onClick:()=>i&&e(i),disabled:!i,children:i===s?`Create "${i}"`:`Save to ${i}`})]})]})})},Rwi=t=>{const e=ee.useRef(null),n=id(o=>o.recentEvents);ee.useEffect(()=>{if(n.length===0)return;const o=n[0];o.event_id!==e.current&&(t(o),e.current=o.event_id)},[n,t])};var Twi=Object.defineProperty,ZS=(t,e)=>Twi(t,"name",{value:e,configurable:!0}),kwi="AlertDialog",[Fwi,Csr]=lx(kwi,[Xsn]),eb=Xsn(),Lwi=ZS(t=>{const{__scopeAlertDialog:e,...n}=t,o=eb(e);return U.jsx(Whe,{...o,...n,modal:!0})},"AlertDialog");ee.forwardRef(ZS(function(e,n){const{__scopeAlertDialog:o,...i}=e,r=eb(o);return U.jsx(J4i,{...r,...i,ref:n})},"AlertDialogTrigger"));var Hwi=ZS(t=>{const{__scopeAlertDialog:e,...n}=t,o=eb(e);return U.jsx(jhe,{...o,...n})},"AlertDialogPortal"),Owi=ee.forwardRef(ZS(function(e,n){const{__scopeAlertDialog:o,...i}=e,r=eb(o);return U.jsx(Zq,{...r,...i,ref:n})},"AlertDialogOverlay")),Gwi="AlertDialogContent",[Ywi,Uwi]=Fwi(Gwi),Kwi=ee.forwardRef(ZS(function(e,n){const{__scopeAlertDialog:o,children:i,...r}=e,s=eb(o),a=ee.useRef(null),A=KA(n,a),c=ee.useRef(null);return U.jsx(Ywi,{scope:o,cancelRef:c,children:U.jsx(t$,{role:"alertdialog",...s,...r,ref:A,onOpenAutoFocus:sr(r.onOpenAutoFocus,l=>{l.preventDefault(),c.current?.focus({preventScroll:!0})}),onPointerDownOutside:l=>l.preventDefault(),onInteractOutside:l=>l.preventDefault(),children:i})})},"AlertDialogContent")),Vwi=ee.forwardRef(ZS(function(e,n){const{__scopeAlertDialog:o,...i}=e,r=eb(o);return U.jsx(Xhe,{...r,...i,ref:n})},"AlertDialogTitle")),zwi=ee.forwardRef(ZS(function(e,n){const{__scopeAlertDialog:o,...i}=e,r=eb(o);return U.jsx(qhe,{...r,...i,ref:n})},"AlertDialogDescription")),Jwi=ee.forwardRef(ZS(function(e,n){const{__scopeAlertDialog:o,...i}=e,r=eb(o);return U.jsx(nze,{...r,...i,ref:n})},"AlertDialogAction")),Wwi="AlertDialogCancel",jwi=ee.forwardRef(ZS(function(e,n){const{__scopeAlertDialog:o,...i}=e,{cancelRef:r}=Uwi(Wwi,o),s=eb(o),a=KA(n,r);return U.jsx(nze,{...s,...i,ref:a})},"AlertDialogCancel")),Xwi=Lwi,qwi=Hwi,gln=Owi,uln=Kwi,dln=Jwi,hln=jwi,mln=Vwi,pln=zwi;const _ln=Xwi,$wi=qwi,fln=ee.forwardRef(({className:t,...e},n)=>U.jsx(gln,{className:ki("rf-fixed rf-inset-0 rf-z-50 rf-bg-black/80 data-[state=open]:rf-animate-in data-[state=closed]:rf-animate-out data-[state=closed]:rf-fade-out-0 data-[state=open]:rf-fade-in-0",t),...e,ref:n}));fln.displayName=gln.displayName;const IJe=ee.forwardRef(({className:t,...e},n)=>U.jsxs($wi,{children:[U.jsx(fln,{}),U.jsx(uln,{ref:n,className:ki("rf-fixed rf-left-[50%] rf-top-[50%] rf-z-50 rf-grid rf-w-full rf-max-w-lg rf-translate-x-[-50%] rf-translate-y-[-50%] rf-gap-4 rf-border rf-border-zinc-200 rf-bg-white rf-p-6 rf-shadow-lg rf-duration-200 data-[state=open]:rf-animate-in data-[state=closed]:rf-animate-out data-[state=closed]:rf-fade-out-0 data-[state=open]:rf-fade-in-0 data-[state=closed]:rf-zoom-out-95 data-[state=open]:rf-zoom-in-95 data-[state=closed]:rf-slide-out-to-left-1/2 data-[state=closed]:rf-slide-out-to-top-[48%] data-[state=open]:rf-slide-in-from-left-1/2 data-[state=open]:rf-slide-in-from-top-[48%] sm:rf-rounded-lg dark:rf-border-zinc-800 dark:rf-bg-zinc-950",t),...e})]}));IJe.displayName=uln.displayName;const CJe=({className:t,...e})=>U.jsx("div",{className:ki("rf-flex rf-flex-col rf-space-y-2 rf-text-center sm:rf-text-left",t),...e});CJe.displayName="AlertDialogHeader";const yJe=({className:t,...e})=>U.jsx("div",{className:ki("rf-flex rf-flex-col-reverse sm:rf-flex-row sm:rf-justify-end sm:rf-space-x-2",t),...e});yJe.displayName="AlertDialogFooter";const xJe=ee.forwardRef(({className:t,...e},n)=>U.jsx(mln,{ref:n,className:ki("rf-text-lg rf-font-semibold",t),...e}));xJe.displayName=mln.displayName;const EJe=ee.forwardRef(({className:t,...e},n)=>U.jsx(pln,{ref:n,className:ki("rf-text-sm rf-text-zinc-500 dark:rf-text-zinc-400",t),...e}));EJe.displayName=pln.displayName;const Zwi=ee.forwardRef(({className:t,...e},n)=>U.jsx(dln,{ref:n,className:ki(sY(),t),...e}));Zwi.displayName=dln.displayName;const BJe=ee.forwardRef(({className:t,...e},n)=>U.jsx(hln,{ref:n,className:ki(sY({variant:"outline"}),"rf-mt-2 sm:rf-mt-0",t),...e}));BJe.displayName=hln.displayName;var eMi=Object.defineProperty,tb=(t,e)=>eMi(t,"name",{value:e,configurable:!0}),SJe="Checkbox",[tMi,ysr]=lx(SJe),[nMi,bJe]=tMi(SJe);function Iln(t){const{__scopeCheckbox:e,checked:n,children:o,defaultChecked:i,disabled:r,form:s,name:a,onCheckedChange:A,required:c,value:l="on",internal_do_not_use_render:g}=t,[u,h]=dB({prop:n,defaultProp:i??!1,onChange:A,caller:SJe}),[d,m]=ee.useState(null),[p,_]=ee.useState(null),f=ee.useRef(!1),[I,C]=ee.useReducer(E=>E+1,0),y=d?!!s||!!d.closest("form"):!0,x={checked:u,disabled:r,setChecked:h,control:d,setControl:m,name:a,form:s,value:l,hasConsumerStoppedPropagationRef:f,userInteractionCount:I,onUserInteraction:C,required:c,defaultChecked:nb(i)?!1:i,isFormControl:y,bubbleInput:p,setBubbleInput:_};return U.jsx(nMi,{scope:e,...x,children:yln(g)?g(x):o})}tb(Iln,"CheckboxProvider");var oMi="CheckboxTrigger",iMi=ee.forwardRef(tb(function({__scopeCheckbox:e,onKeyDown:n,onClick:o,...i},r){const{control:s,value:a,disabled:A,checked:c,required:l,setControl:g,setChecked:u,hasConsumerStoppedPropagationRef:h,onUserInteraction:d,isFormControl:m,bubbleInput:p}=bJe(oMi,e),_=KA(r,g),f=ee.useRef(c);return ee.useEffect(()=>{const I=s?.form;if(I){const C=tb(()=>u(f.current),"reset");return I.addEventListener("reset",C),()=>I.removeEventListener("reset",C)}},[s,u]),U.jsx(Qa.button,{type:"button",role:"checkbox","aria-checked":nb(c)?"mixed":c,"aria-required":l,"data-state":QJe(c),"data-disabled":A?"":void 0,disabled:A,value:a,...i,ref:_,onKeyDown:sr(n,I=>{I.key==="Enter"&&I.preventDefault()}),onClick:sr(o,I=>{d(),u(C=>nb(C)?!0:!C),p&&m&&(h.current=I.isPropagationStopped(),h.current||I.stopPropagation())})})},"CheckboxTrigger")),Cln=ee.forwardRef(tb(function(e,n){const{__scopeCheckbox:o,name:i,checked:r,defaultChecked:s,required:a,disabled:A,value:c,onCheckedChange:l,form:g,...u}=e;return U.jsx(Iln,{__scopeCheckbox:o,checked:r,defaultChecked:s,disabled:A,required:a,onCheckedChange:l,name:i,form:g,value:c,internal_do_not_use_render:({isFormControl:h})=>U.jsxs(U.Fragment,{children:[U.jsx(iMi,{...u,ref:n,__scopeCheckbox:o}),h&&U.jsx(AMi,{__scopeCheckbox:o})]})})},"Checkbox")),rMi="CheckboxIndicator",sMi=ee.forwardRef(tb(function(e,n){const{__scopeCheckbox:o,forceMount:i,...r}=e,s=bJe(rMi,o);return U.jsx(z3,{present:i||nb(s.checked)||s.checked===!0,children:U.jsx(Qa.span,{"data-state":QJe(s.checked),"data-disabled":s.disabled?"":void 0,...r,ref:n,style:{pointerEvents:"none",...e.style}})})},"CheckboxIndicator")),aMi="CheckboxBubbleInput",AMi=ee.forwardRef(tb(function({__scopeCheckbox:e,onClick:n,...o},i){const{control:r,hasConsumerStoppedPropagationRef:s,userInteractionCount:a,checked:A,defaultChecked:c,required:l,disabled:g,name:u,value:h,form:d,bubbleInput:m,setBubbleInput:p}=bJe(aMi,e),_=KA(i,p),f=HVe(r),I=ee.useRef(!1),C=ee.useRef(A),y=ee.useRef(a);ee.useEffect(()=>{const E=m;if(!E)return;const B=window.HTMLInputElement.prototype,Q=Object.getOwnPropertyDescriptor(B,"checked").set,w=a!==y.current;y.current=a;const D=C.current!==A;C.current=A;const k=!(w&&s.current);if(D&&Q){I.current=!w;const R=new Event("click",{bubbles:k});E.indeterminate=nb(A),Q.call(E,nb(A)?!1:A),E.dispatchEvent(R),I.current=!1}},[m,A,s,a]);const x=ee.useRef(nb(A)?!1:A);return U.jsx(Qa.input,{type:"checkbox","aria-hidden":!0,defaultChecked:c??x.current,required:l,disabled:g,name:u,value:h,form:d,...o,tabIndex:-1,ref:_,onClick:sr(n,E=>{I.current&&E.stopPropagation()}),style:{...o.style,...f,position:"absolute",pointerEvents:"none",opacity:0,margin:0,transform:"translateX(-100%)"}})},"CheckboxBubbleInput"));function yln(t){return typeof t=="function"}tb(yln,"isFunction");function nb(t){return t==="indeterminate"}tb(nb,"isIndeterminate");function QJe(t){return nb(t)?"indeterminate":t?"checked":"unchecked"}tb(QJe,"getState");const b$=ee.forwardRef(({className:t,...e},n)=>U.jsx(Cln,{ref:n,className:ki("rf-peer rf-h-4 rf-w-4 rf-shrink-0 rf-rounded-sm rf-border rf-border-zinc-200 rf-border-zinc-900 rf-shadow focus-visible:rf-outline-none focus-visible:rf-ring-1 focus-visible:rf-ring-zinc-950 disabled:rf-cursor-not-allowed disabled:rf-opacity-50 data-[state=checked]:rf-bg-zinc-900 data-[state=checked]:rf-text-zinc-50 dark:rf-border-zinc-800 dark:rf-border-zinc-50 dark:focus-visible:rf-ring-zinc-300 dark:data-[state=checked]:rf-bg-zinc-50 dark:data-[state=checked]:rf-text-zinc-900",t),...e,children:U.jsx(sMi,{className:ki("rf-flex rf-items-center rf-justify-center rf-text-current"),children:U.jsx(KS,{className:"rf-h-4 rf-w-4"})})}));b$.displayName=Cln.displayName;const YR=Whe,cMi=jhe,xln=ee.forwardRef(({className:t,...e},n)=>U.jsx(Zq,{className:ki("rf-fixed rf-inset-0 rf-z-50 rf-bg-black/80 data-[state=open]:rf-animate-in data-[state=closed]:rf-animate-out data-[state=closed]:rf-fade-out-0 data-[state=open]:rf-fade-in-0",t),...e,ref:n}));xln.displayName=Zq.displayName;const tw=ee.forwardRef(({className:t,children:e,showOverlay:n=!0,...o},i)=>U.jsxs(cMi,{children:[U.jsx(xln,{className:ki(n?"":"rf-hidden")}),U.jsx(t$,{ref:i,className:ki("rf-fixed rf-left-[50%] rf-top-[50%] rf-z-50 rf-grid rf-w-full rf-max-w-lg rf-translate-x-[-50%] rf-translate-y-[-50%] rf-gap-4 rf-border rf-border-zinc-200 rf-bg-white rf-p-6 rf-shadow-lg rf-duration-200 data-[state=open]:rf-animate-in data-[state=closed]:rf-animate-out data-[state=closed]:rf-fade-out-0 data-[state=open]:rf-fade-in-0 data-[state=closed]:rf-zoom-out-95 data-[state=open]:rf-zoom-in-95 data-[state=closed]:rf-slide-out-to-left-1/2 data-[state=closed]:rf-slide-out-to-top-[48%] data-[state=open]:rf-slide-in-from-left-1/2 data-[state=open]:rf-slide-in-from-top-[48%] sm:rf-rounded-lg dark:rf-border-zinc-800 dark:rf-bg-zinc-950",t),...o,children:e})]}));tw.displayName=t$.displayName;const nw=({className:t,...e})=>U.jsx("div",{className:ki("rf-flex rf-flex-col rf-space-y-2 rf-text-center sm:rf-text-left",t),...e});nw.displayName="DialogHeader";const MY=({className:t,...e})=>U.jsx("div",{className:ki("rf-flex rf-flex-col-reverse sm:rf-flex-row sm:rf-justify-end sm:rf-space-x-2",t),...e});MY.displayName="DialogFooter";const ow=ee.forwardRef(({className:t,...e},n)=>U.jsx(Xhe,{ref:n,className:ki("rf-text-lg rf-font-semibold",t),...e}));ow.displayName=Xhe.displayName;const UR=ee.forwardRef(({className:t,...e},n)=>U.jsx(qhe,{ref:n,className:ki("rf-text-sm rf-text-zinc-500 dark:rf-text-zinc-400",t),...e}));UR.displayName=qhe.displayName;const Hme={"tscircuit.com":{label:"tscircuit.com",placeholder:"Search tscircuit packages...",emptyMessage:"No packages found"},jlcpcb:{label:"JLCPCB Parts",placeholder:"Search JLCPCB parts (e.g. C14663)...",emptyMessage:"No parts found"},kicad:{label:"KiCad Footprints",placeholder:"Search KiCad footprints...",emptyMessage:"No footprints found"}},lMi="https://cdn.jsdelivr.net/npm/easyeda@latest/dist/browser/index.js";let vJe=null;const PJe=async()=>(vJe||(vJe=import(lMi)),vJe),gMi=t=>(e,n)=>{const o=new Headers(n?.headers),i={};return o.forEach((r,s)=>{i[s]=r}),fetch(`${t?.apiBase??sC}/proxy`,{...n,headers:{...i,"X-Target-Url":e.toString(),"X-Sender-Origin":i.origin??"","X-Sender-Host":i.host??"https://easyeda.com","X-Sender-Referer":i.referer??"","X-Sender-User-Agent":i["user-agent"]??"","X-Sender-Cookie":i.cookie??"",authority:i.authority??"","content-type":i["content-type"]??"",...t?.headers}})},uMi=async(t,e=10)=>{const n=encodeURIComponent(t),o=await fetch(`https://jlcsearch.tscircuit.com/api/search?limit=${e}&q=${n}`);if(!o.ok)throw new Error(`JLCPCB API error: ${o.status}`);return(await o.json()).components??[]},dMi=t=>({lcscId:t.lcsc,manufacturer:t.mfr,description:t.description,partNumber:`C${t.lcsc}`,package:t.package,price:t.price,stock:t.stock,isBasic:t.is_basic}),Eln=async(t,e)=>{const{fetchEasyEDAComponent:n}=await PJe();return n(t,{fetch:gMi(e),includeModelMetadata:e?.includeModelMetadata})},hMi=async(t,e)=>{const{convertRawEasyToTsx:n}=await PJe(),o=await Eln(t,e);return n({rawEasy:o})},mMi=async(t,e)=>{const{EasyEdaJsonSchema:n,convertEasyEdaJsonToCircuitJson:o}=await PJe(),i=await Eln(t,{...e,includeModelMetadata:!1}),r=n.parse(i);return o(r,{shouldRecenter:!0,showDesignator:!0,useModelCdn:!1})};function iw(t){return Array.isArray?Array.isArray(t):Sln(t)==="[object Array]"}function pMi(t){if(typeof t=="string")return t;if(typeof t=="bigint")return t.toString();const e=t+"";return e=="0"&&1/t==-1/0?"-0":e}function wJe(t){return t==null?"":pMi(t)}function hC(t){return typeof t=="string"}function Ome(t){return typeof t=="number"}function _Mi(t){return t===!0||t===!1||fMi(t)&&Sln(t)=="[object Boolean]"}function Bln(t){return typeof t=="object"}function fMi(t){return Bln(t)&&t!==null}function fE(t){return t!=null}function Gme(t){return!t.trim().length}function Sln(t){return t==null?t===void 0?"[object Undefined]":"[object Null]":Object.prototype.toString.call(t)}const IMi="Incorrect 'index' type",MJe="Invalid doc index: must be a non-negative integer within the bounds of the docs array",CMi=t=>`Invalid value for key ${t}`,yMi=t=>`Pattern length exceeds max of ${t}.`,xMi=t=>`Missing ${t} property in key`,EMi=t=>`Property 'weight' in key '${t}' must be a positive integer`,BMi="Fuse.match does not support useTokenSearch: token search requires corpus-level statistics (df, fieldCount) that a one-off string comparison does not have. Use new Fuse(...).search(...) instead.",bln=Object.prototype.hasOwnProperty;var SMi=class{constructor(t){this._keys=[],this._keyMap={};let e=0;t.forEach(n=>{const o=Qln(n);this._keys.push(o),this._keyMap[o.id]=o,e+=o.weight}),this._keys.forEach(n=>{n.weight/=e})}get(t){return this._keyMap[t]}keys(){return this._keys}toJSON(){return JSON.stringify(this._keys)}};function Qln(t){let e=null,n=null,o=null,i=1,r=null;if(hC(t)||iw(t))o=t,e=vln(t),n=Yme(t);else{if(!bln.call(t,"name"))throw new Error(xMi("name"));const s=t.name;if(o=s,bln.call(t,"weight")&&t.weight!==void 0&&(i=t.weight,i<=0))throw new Error(EMi(Yme(s)));e=vln(s),n=Yme(s),r=t.getFn??null}return{path:e,id:n,weight:i,src:o,getFn:r}}function vln(t){return iw(t)?t:t.split(".")}function Yme(t){return iw(t)?t.join("."):t}function bMi(t,e){const n=[];let o=!1;const i=(r,s,a,A)=>{if(fE(r))if(!s[a])n.push(A!==void 0?{v:r,i:A}:r);else{const c=r[s[a]];if(!fE(c))return;if(a===s.length-1&&(hC(c)||Ome(c)||_Mi(c)||typeof c=="bigint"))n.push(A!==void 0?{v:wJe(c),i:A}:wJe(c));else if(iw(c)){o=!0;for(let l=0,g=c.length;l<g;l+=1)i(c[l],s,a+1,l)}else s.length&&i(c,s,a+1,A)}};return i(t,hC(e)?e.split("."):e,0),o?n:n[0]}const Ea=Object.freeze({...{isCaseSensitive:!1,ignoreDiacritics:!1,includeScore:!1,keys:[],shouldSort:!0,sortFn:(t,e)=>t.score===e.score?t.idx<e.idx?-1:1:t.score<e.score?-1:1},...{includeMatches:!1,findAllMatches:!1,minMatchCharLength:1},...{location:0,threshold:.6,distance:100},...{useExtendedSearch:!1,useTokenSearch:!1,tokenize:void 0,tokenMatch:"any",getFn:bMi,ignoreLocation:!1,ignoreFieldNorm:!1,fieldNormWeight:1}});function QMi(t){return t>=9&&t<=13||t===32||t===160}function vMi(t=1,e=3){const n=new Map,o=Math.pow(10,e);return{get(i){let r=0,s=!1;for(let A=0;A<i.length;A++)QMi(i.charCodeAt(A))?s=!1:s||(r++,s=!0);if(r===0&&(r=1),n.has(r))return n.get(r);const a=Math.round(o/Math.pow(r,.5*t))/o;return n.set(r,a),a},clear(){n.clear()}}}var DJe=class{constructor({getFn:t=Ea.getFn,fieldNormWeight:e=Ea.fieldNormWeight}={}){this.norm=vMi(e,3),this.getFn=t,this.isCreated=!1,this.docs=[],this.keys=[],this._keysMap={},this.setIndexRecords()}setSources(t=[]){this.docs=t}setIndexRecords(t=[]){this.records=t}setKeys(t=[]){this.keys=t,this._keysMap={},t.forEach((e,n)=>{this._keysMap[e.id]=n})}create(){if(this.isCreated||!this.docs.length)return;this.isCreated=!0;const t=this.docs.length;this.records=new Array(t);let e=0;if(hC(this.docs[0]))for(let n=0;n<t;n++){const o=this._createStringRecord(this.docs[n],n);o&&(this.records[e++]=o)}else for(let n=0;n<t;n++)this.records[e++]=this._createObjectRecord(this.docs[n],n);this.records.length=e,this.norm.clear()}add(t,e){if(!Number.isInteger(e)||e<0)throw new Error(MJe);if(hC(t)){const o=this._createStringRecord(t,e);return o&&this.records.push(o),o}const n=this._createObjectRecord(t,e);return this.records.push(n),n}removeAt(t){if(!Number.isInteger(t)||t<0)throw new Error(MJe);for(let e=0,n=this.records.length;e<n;e+=1)if(this.records[e].i===t){this.records.splice(e,1);break}for(let e=0,n=this.records.length;e<n;e+=1)this.records[e].i>t&&(this.records[e].i-=1)}removeAll(t){const e=new Set;for(const o of t)Number.isInteger(o)&&o>=0&&e.add(o);if(e.size===0)return;this.records=this.records.filter(o=>!e.has(o.i));const n=Array.from(e).sort((o,i)=>o-i);for(const o of this.records){let i=0,r=n.length;for(;i<r;){const s=i+r>>>1;n[s]<o.i?i=s+1:r=s}o.i-=i}}getValueForItemAtKeyId(t,e){return t[this._keysMap[e]]}size(){return this.records.length}_createStringRecord(t,e){return!fE(t)||Gme(t)?null:{v:t,i:e,n:this.norm.get(t)}}_createObjectRecord(t,e){const n={i:e,$:{}};for(let o=0,i=this.keys.length;o<i;o++){const r=this.keys[o],s=r.getFn?r.getFn(t):this.getFn(t,r.path);if(fE(s)){if(iw(s)){const a=[];for(let A=0,c=s.length;A<c;A+=1){const l=s[A];if(fE(l)){if(hC(l)){if(!Gme(l)){const g={v:l,i:A,n:this.norm.get(l)};a.push(g)}}else if(fE(l.v)){const g=hC(l.v)?l.v:wJe(l.v);if(!Gme(g)){const u={v:g,i:l.i,n:this.norm.get(g)};a.push(u)}}}}n.$[o]=a}else if(hC(s)&&!Gme(s)){const a={v:s,n:this.norm.get(s)};n.$[o]=a}}}return n}toJSON(){return{keys:this.keys.map(({getFn:t,...e})=>e),records:this.records}}};function Pln(t,e,{getFn:n=Ea.getFn,fieldNormWeight:o=Ea.fieldNormWeight}={}){const i=new DJe({getFn:n,fieldNormWeight:o});return i.setKeys(t.map(Qln)),i.setSources(e),i.create(),i}function PMi(t,{getFn:e=Ea.getFn,fieldNormWeight:n=Ea.fieldNormWeight}={}){const{keys:o,records:i}=t,r=new DJe({getFn:e,fieldNormWeight:n});return r.setKeys(o),r.setIndexRecords(i),r}function wMi(t=[],e=Ea.minMatchCharLength){const n=[];let o=-1,i=-1,r=0;for(let s=t.length;r<s;r+=1){const a=t[r];a&&o===-1?o=r:!a&&o!==-1&&(i=r-1,i-o+1>=e&&n.push([o,i]),o=-1)}return t[r-1]&&r-o>=e&&n.push([o,r-1]),n}function MMi(t,e,n,{location:o=Ea.location,distance:i=Ea.distance,threshold:r=Ea.threshold,findAllMatches:s=Ea.findAllMatches,minMatchCharLength:a=Ea.minMatchCharLength,includeMatches:A=Ea.includeMatches,ignoreLocation:c=Ea.ignoreLocation}={}){if(e.length>32)throw new Error(yMi(32));const l=e.length,g=t.length,u=Math.max(0,Math.min(o,g));let h=r,d=u;const m=(b,Q)=>{const w=b/l;if(c)return w;const D=Math.abs(u-Q);return i?w+D/i:D?1:w},p=a>1||A,_=p?Array(g):[];let f;for(;(f=t.indexOf(e,d))>-1;){const b=m(0,f);if(h=Math.min(b,h),d=f+l,p){let Q=0;for(;Q<l;)_[f+Q]=1,Q+=1}}d=-1;let I=[],C=1,y=0,x=l+g;const E=1<<l-1;for(let b=0;b<l;b+=1){let Q=0,w=x;for(;Q<w;)m(b,u+w)<=h?Q=w:x=w,w=Math.floor((x-Q)/2+Q);x=w;let D=Math.max(1,u-w+1);const k=s?g:Math.min(u+w,g)+l,R=Array(k+2);R[k+1]=(1<<b)-1;for(let H=k;H>=D;H-=1){const G=H-1,K=n[t[G]];if(R[H]=(R[H+1]<<1|1)&K,b&&(R[H]|=(I[H+1]|I[H])<<1|1|I[H+1]),R[H]&E&&(C=m(b,G),C<=h)){if(h=C,d=G,y=b,d<=u)break;D=Math.max(1,2*u-d)}}if(m(b+1,u)>h)break;I=R}if(p&&d>=0){const b=Math.min(g-1,d+l-1+y);for(let Q=d;Q<=b;Q+=1)n[t[Q]]&&(_[Q]=1)}const B={isMatch:d>=0,score:Math.max(.001,C)};if(p){const b=wMi(_,a);b.length?A&&(B.indices=b):B.isMatch=!1}return B}function DMi(t){const e={};for(let n=0,o=t.length;n<o;n+=1){const i=t.charAt(n);e[i]=(e[i]||0)|1<<o-n-1}return e}function NJe(t){if(t.length<=1)return t;t.sort((n,o)=>n[0]-o[0]||n[1]-o[1]);const e=[t[0]];for(let n=1,o=t.length;n<o;n+=1){const i=e[e.length-1],r=t[n];r[0]<=i[1]+1?i[1]=Math.max(i[1],r[1]):e.push(r)}return e}const wln={ł:"l",Ł:"L",đ:"d",Đ:"D",ø:"o",Ø:"O",ħ:"h",Ħ:"H",ŧ:"t",Ŧ:"T",ı:"i",ß:"ss"},NMi=new RegExp("["+Object.keys(wln).join("")+"]","g"),Q$=typeof String.prototype.normalize=="function"?t=>t.normalize("NFD").replace(/[\u0300-\u036F\u0483-\u0489\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u0610-\u061A\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED\u0711\u0730-\u074A\u07A6-\u07B0\u07EB-\u07F3\u07FD\u0816-\u0819\u081B-\u0823\u0825-\u0827\u0829-\u082D\u0859-\u085B\u08D3-\u08E1\u08E3-\u0903\u093A-\u093C\u093E-\u094F\u0951-\u0957\u0962\u0963\u0981-\u0983\u09BC\u09BE-\u09C4\u09C7\u09C8\u09CB-\u09CD\u09D7\u09E2\u09E3\u09FE\u0A01-\u0A03\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A70\u0A71\u0A75\u0A81-\u0A83\u0ABC\u0ABE-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AE2\u0AE3\u0AFA-\u0AFF\u0B01-\u0B03\u0B3C\u0B3E-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B62\u0B63\u0B82\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD7\u0C00-\u0C04\u0C3E-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C62\u0C63\u0C81-\u0C83\u0CBC\u0CBE-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CE2\u0CE3\u0D00-\u0D03\u0D3B\u0D3C\u0D3E-\u0D44\u0D46-\u0D48\u0D4A-\u0D4D\u0D57\u0D62\u0D63\u0D82\u0D83\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DF2\u0DF3\u0E31\u0E34-\u0E3A\u0E47-\u0E4E\u0EB1\u0EB4-\u0EB9\u0EBB\u0EBC\u0EC8-\u0ECD\u0F18\u0F19\u0F35\u0F37\u0F39\u0F3E\u0F3F\u0F71-\u0F84\u0F86\u0F87\u0F8D-\u0F97\u0F99-\u0FBC\u0FC6\u102B-\u103E\u1056-\u1059\u105E-\u1060\u1062-\u1064\u1067-\u106D\u1071-\u1074\u1082-\u108D\u108F\u109A-\u109D\u135D-\u135F\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17B4-\u17D3\u17DD\u180B-\u180D\u1885\u1886\u18A9\u1920-\u192B\u1930-\u193B\u1A17-\u1A1B\u1A55-\u1A5E\u1A60-\u1A7C\u1A7F\u1AB0-\u1ABE\u1B00-\u1B04\u1B34-\u1B44\u1B6B-\u1B73\u1B80-\u1B82\u1BA1-\u1BAD\u1BE6-\u1BF3\u1C24-\u1C37\u1CD0-\u1CD2\u1CD4-\u1CE8\u1CED\u1CF2-\u1CF4\u1CF7-\u1CF9\u1DC0-\u1DF9\u1DFB-\u1DFF\u20D0-\u20F0\u2CEF-\u2CF1\u2D7F\u2DE0-\u2DFF\u302A-\u302F\u3099\u309A\uA66F-\uA672\uA674-\uA67D\uA69E\uA69F\uA6F0\uA6F1\uA802\uA806\uA80B\uA823-\uA827\uA880\uA881\uA8B4-\uA8C5\uA8E0-\uA8F1\uA8FF\uA926-\uA92D\uA947-\uA953\uA980-\uA983\uA9B3-\uA9C0\uA9E5\uAA29-\uAA36\uAA43\uAA4C\uAA4D\uAA7B-\uAA7D\uAAB0\uAAB2-\uAAB4\uAAB7\uAAB8\uAABE\uAABF\uAAC1\uAAEB-\uAAEF\uAAF5\uAAF6\uABE3-\uABEA\uABEC\uABED\uFB1E\uFE00-\uFE0F\uFE20-\uFE2F]/g,"").replace(NMi,e=>wln[e]):t=>t;var RJe=class{constructor(t,{location:e=Ea.location,threshold:n=Ea.threshold,distance:o=Ea.distance,includeMatches:i=Ea.includeMatches,findAllMatches:r=Ea.findAllMatches,minMatchCharLength:s=Ea.minMatchCharLength,isCaseSensitive:a=Ea.isCaseSensitive,ignoreDiacritics:A=Ea.ignoreDiacritics,ignoreLocation:c=Ea.ignoreLocation}={}){if(this.options={location:e,threshold:n,distance:o,includeMatches:i,findAllMatches:r,minMatchCharLength:s,isCaseSensitive:a,ignoreDiacritics:A,ignoreLocation:c},t=a?t:t.toLowerCase(),t=A?Q$(t):t,this.pattern=t,this.chunks=[],!this.pattern.length)return;const l=(u,h)=>{this.chunks.push({pattern:u,alphabet:DMi(u),startIndex:h})},g=this.pattern.length;if(g>32){let u=0;const h=g%32,d=g-h;for(;u<d;)l(this.pattern.substr(u,32),u),u+=32;if(h){const m=g-32;l(this.pattern.substr(m),m)}}else l(this.pattern,0)}searchIn(t){const{isCaseSensitive:e,ignoreDiacritics:n,includeMatches:o}=this.options;if(t=e?t:t.toLowerCase(),t=n?Q$(t):t,this.pattern===t){if(t.length<this.options.minMatchCharLength)return{isMatch:!1,score:1};const d={isMatch:!0,score:0};return o&&(d.indices=[[0,t.length-1]]),d}const{location:i,distance:r,threshold:s,findAllMatches:a,minMatchCharLength:A,ignoreLocation:c}=this.options,l=[];let g=0,u=!1;this.chunks.forEach(({pattern:d,alphabet:m,startIndex:p})=>{const{isMatch:_,score:f,indices:I}=MMi(t,d,m,{location:i+p,distance:r,threshold:s,findAllMatches:a,minMatchCharLength:A,includeMatches:o,ignoreLocation:c});_&&(u=!0),g+=f,_&&I&&l.push(...I)});const h={isMatch:u,score:u?g/this.chunks.length:1};return u&&o&&(h.indices=NJe(l)),h}};const RMi=new Set(["fuzzy","include"]);function TMi(t){return t.startsWith("inverse")}const TJe=[{type:"exact",multiRegex:/^="(.*)"$/,singleRegex:/^=(.*)$/,create:t=>({type:"exact",search(e){const n=e===t;return{isMatch:n,score:n?0:1,indices:[0,t.length-1]}}})},{type:"include",multiRegex:/^'"(.*)"$/,singleRegex:/^'(.*)$/,create:t=>({type:"include",search(e){let n=0,o;const i=[],r=t.length;for(;(o=e.indexOf(t,n))>-1;)n=o+r,i.push([o,n-1]);const s=!!i.length;return{isMatch:s,score:s?0:1,indices:i}}})},{type:"prefix-exact",multiRegex:/^\^"(.*)"$/,singleRegex:/^\^(.*)$/,create:t=>({type:"prefix-exact",search(e){const n=e.startsWith(t);return{isMatch:n,score:n?0:1,indices:[0,t.length-1]}}})},{type:"inverse-prefix-exact",multiRegex:/^!\^"(.*)"$/,singleRegex:/^!\^(.*)$/,create:t=>({type:"inverse-prefix-exact",search(e){const n=!e.startsWith(t);return{isMatch:n,score:n?0:1,indices:[0,e.length-1]}}})},{type:"inverse-suffix-exact",multiRegex:/^!"(.*)"\$$/,singleRegex:/^!(.*)\$$/,create:t=>({type:"inverse-suffix-exact",search(e){const n=!e.endsWith(t);return{isMatch:n,score:n?0:1,indices:[0,e.length-1]}}})},{type:"suffix-exact",multiRegex:/^"(.*)"\$$/,singleRegex:/^(.*)\$$/,create:t=>({type:"suffix-exact",search(e){const n=e.endsWith(t);return{isMatch:n,score:n?0:1,indices:[e.length-t.length,e.length-1]}}})},{type:"inverse-exact",multiRegex:/^!"(.*)"$/,singleRegex:/^!(.*)$/,create:t=>({type:"inverse-exact",search(e){const n=e.indexOf(t)===-1;return{isMatch:n,score:n?0:1,indices:[0,e.length-1]}}})},{type:"fuzzy",multiRegex:/^"(.*)"$/,singleRegex:/^(.*)$/,create:(t,e={})=>{const n=new RJe(t,{location:e.location??Ea.location,threshold:e.threshold??Ea.threshold,distance:e.distance??Ea.distance,includeMatches:e.includeMatches??Ea.includeMatches,findAllMatches:e.findAllMatches??Ea.findAllMatches,minMatchCharLength:e.minMatchCharLength??Ea.minMatchCharLength,isCaseSensitive:e.isCaseSensitive??Ea.isCaseSensitive,ignoreDiacritics:e.ignoreDiacritics??Ea.ignoreDiacritics,ignoreLocation:e.ignoreLocation??Ea.ignoreLocation});return{type:"fuzzy",search(o){return n.searchIn(o)}}}}],Mln=TJe.length,kMi="\0",FMi="|";function LMi(t){const e=[],n=t.length;let o=0;for(;o<n;){for(;o<n&&t[o]===" ";)o++;if(o>=n)break;let i=o;for(;i<n&&t[i]!==" "&&t[i]!=='"';)i++;if(i<n&&t[i]==='"'){for(i++;i<n;){if(t[i]==='"'){const r=i+1;if(r>=n||t[r]===" "){i++;break}if(t[r]==="$"&&(r+1>=n||t[r+1]===" ")){i+=2;break}}i++}e.push(t.substring(o,i)),o=i}else{for(;i<n&&t[i]!==" ";)i++;e.push(t.substring(o,i)),o=i}}return e}function Dln(t,e){const n=t.match(e);return n?n[1]:null}function HMi(t,e={}){return t.replace(/\\\|/g,kMi).split(FMi).map(n=>{const o=LMi(n.replace(/\u0000/g,"|").trim()).filter(r=>r&&!!r.trim()),i=[];for(let r=0,s=o.length;r<s;r+=1){const a=o[r];let A=!1,c=-1;for(;!A&&++c<Mln;){const l=TJe[c],g=Dln(a,l.multiRegex);g&&(i.push(l.create(g,e)),A=!0)}if(!A)for(c=-1;++c<Mln;){const l=TJe[c],g=Dln(a,l.singleRegex);if(g){i.push(l.create(g,e));break}}}return i})}var OMi=class{constructor(t,{isCaseSensitive:e=Ea.isCaseSensitive,ignoreDiacritics:n=Ea.ignoreDiacritics,includeMatches:o=Ea.includeMatches,minMatchCharLength:i=Ea.minMatchCharLength,ignoreLocation:r=Ea.ignoreLocation,findAllMatches:s=Ea.findAllMatches,location:a=Ea.location,threshold:A=Ea.threshold,distance:c=Ea.distance}={}){this.query=null,this.options={isCaseSensitive:e,ignoreDiacritics:n,includeMatches:o,minMatchCharLength:i,findAllMatches:s,ignoreLocation:r,location:a,threshold:A,distance:c},t=e?t:t.toLowerCase(),t=n?Q$(t):t,this.pattern=t,this.query=HMi(this.pattern,this.options)}static condition(t,e){return e.useExtendedSearch}searchIn(t){const e=this.query;if(!e)return{isMatch:!1,score:1};const{includeMatches:n,isCaseSensitive:o,ignoreDiacritics:i}=this.options;t=o?t:t.toLowerCase(),t=i?Q$(t):t;let r=0;const s=[];let a=0,A=!1;for(let c=0,l=e.length;c<l;c+=1){const g=e[c];s.length=0,r=0,A=!1;for(let u=0,h=g.length;u<h;u+=1){const d=g[u],{isMatch:m,indices:p,score:_}=d.search(t);if(m)r+=1,a+=_,TMi(d.type)&&(A=!0),n&&(RMi.has(d.type)?s.push(...p):s.push(p));else{a=0,r=0,s.length=0,A=!1;break}}if(r){const u={isMatch:!0,score:a/r};return A&&(u.hasInverse=!0),n&&(u.indices=NJe(s)),u}}return{isMatch:!1,score:1}}};const kJe=[];function FJe(...t){kJe.push(...t)}function Ume(t,e){for(let n=0,o=kJe.length;n<o;n+=1){const i=kJe[n];if(i.condition(t,e))return new i(t,e)}return new RJe(t,e)}const Kme={AND:"$and",OR:"$or"},LJe={PATH:"$path",PATTERN:"$val"},HJe=t=>!!(t[Kme.AND]||t[Kme.OR]),GMi=t=>!!t[LJe.PATH],YMi=t=>!iw(t)&&Bln(t)&&!HJe(t),Nln=t=>({[Kme.AND]:Object.keys(t).map(e=>({[e]:t[e]}))});function Rln(t,e,{auto:n=!0}={}){const o=i=>{if(hC(i)){const A={keyId:null,pattern:i};return n&&(A.searcher=Ume(i,e)),A}const r=Object.keys(i),s=GMi(i);if(!s&&r.length>1&&!HJe(i))return o(Nln(i));if(YMi(i)){const A=s?i[LJe.PATH]:r[0],c=s?i[LJe.PATTERN]:i[A];if(!hC(c))throw new Error(CMi(A));const l={keyId:Yme(A),pattern:c};return n&&(l.searcher=Ume(c,e)),l}const a={children:[],operator:r[0]};return r.forEach(A=>{const c=i[A];iw(c)&&c.forEach(l=>{a.children.push(o(l))})}),a};return HJe(t)||(t=Nln(t)),o(t)}function OJe(t,{ignoreFieldNorm:e=Ea.ignoreFieldNorm}){let n=1;return t.forEach(({key:o,norm:i,score:r})=>{const s=o?o.weight:null;n*=Math.pow(r===0&&s?Number.EPSILON:r,(s||1)*(e?1:i))}),n}function UMi(t,{ignoreFieldNorm:e=Ea.ignoreFieldNorm}){t.forEach(n=>{n.score=OJe(n.matches,{ignoreFieldNorm:e})})}var KMi=class{constructor(t,e){this.limit=t,this.heap=[],this.comparator=e}get size(){return this.heap.length}insert(t){this.size<this.limit?(this.heap.push(t),this._bubbleUp(this.size-1)):this.comparator(t,this.heap[0])<0&&(this.heap[0]=t,this._sinkDown(0))}extractSorted(){return this.heap.sort(this.comparator)}_bubbleUp(t){const e=this.heap;for(;t>0;){const n=t-1>>1;if(this.comparator(e[t],e[n])<=0)break;const o=e[t];e[t]=e[n],e[n]=o,t=n}}_sinkDown(t){const e=this.heap,n=e.length;let o=t;do{t=o;const i=2*t+1,r=2*t+2;if(i<n&&this.comparator(e[i],e[o])>0&&(o=i),r<n&&this.comparator(e[r],e[o])>0&&(o=r),o!==t){const s=e[t];e[t]=e[o],e[o]=s}}while(o!==t)}};function VMi(t){const e=[];return t.matches.forEach(n=>{if(!fE(n.indices)||!n.indices.length)return;const o={indices:n.indices,value:n.value};n.key&&(o.key=n.key.id),n.idx>-1&&(o.refIndex=n.idx),e.push(o)}),e}function zMi(t,e,{includeMatches:n=Ea.includeMatches,includeScore:o=Ea.includeScore}={}){return t.map(i=>{const{idx:r}=i,s={item:e[r],refIndex:r};return n&&(s.matches=VMi(i)),o&&(s.score=i.score),s})}const JMi=/[\p{L}\p{M}\p{N}_]+/gu,Tln=new WeakSet;function WMi(t){Tln.has(t)||(Tln.add(t),console.warn(`[Fuse] tokenize regex ${t} lacks the global flag; only the first match per text will be returned. Add the 'g' flag.`))}function jMi(t){if(typeof t=="function"){let e=!1;return n=>{const o=t(n);if(!e&&(e=!0,!Array.isArray(o)||o.some(i=>typeof i!="string")))throw new Error(`[Fuse] tokenize function must return string[]; received ${Array.isArray(o)?"array containing non-strings":typeof o}.`);return o}}return t instanceof RegExp?(t.global||WMi(t),e=>e.match(t)||[]):e=>e.match(JMi)||[]}function GJe({isCaseSensitive:t=!1,ignoreDiacritics:e=!1,tokenize:n}={}){const o=jMi(n);return{tokenize(i){return t||(i=i.toLowerCase()),e&&(i=Q$(i)),o(i)}}}var XMi=class{static condition(t,e){return e.useTokenSearch}constructor(t,e){this.options=e,this.analyzer=GJe({isCaseSensitive:e.isCaseSensitive,ignoreDiacritics:e.ignoreDiacritics,tokenize:e.tokenize});const n=this.analyzer.tokenize(t),{df:o,fieldCount:i}=e._invertedIndex;this.termSearchers=[],this.idfWeights=[];for(const r of n){this.termSearchers.push(new RJe(r,{location:e.location,threshold:e.threshold,distance:e.distance,includeMatches:e.includeMatches,findAllMatches:e.findAllMatches,minMatchCharLength:e.minMatchCharLength,isCaseSensitive:e.isCaseSensitive,ignoreDiacritics:e.ignoreDiacritics,ignoreLocation:!0}));const s=o.get(r)||0,a=Math.log(1+(i-s+.5)/(s+.5));this.idfWeights.push(a)}this.combineAll=e.tokenMatch==="all",this.numTerms=this.termSearchers.length,this.useMask=this.numTerms<=31}searchIn(t){if(!this.termSearchers.length)return{isMatch:!1,score:1};const e=[];let n=0,o=0,i=0,r=0;const s=this.combineAll&&!this.useMask?new Set:null;for(let c=0;c<this.termSearchers.length;c++){const l=this.termSearchers[c].searchIn(t),g=this.idfWeights[c];o+=g,l.isMatch&&(i++,n+=g*(1-l.score),l.indices&&e.push(...l.indices),this.combineAll&&(this.useMask?r|=1<<c:s.add(c)))}if(i===0)return{isMatch:!1,score:1};const a=o>0?1-n/o:0,A={isMatch:!0,score:Math.max(.001,a)};return this.options.includeMatches&&e.length&&(A.indices=NJe(e)),this.combineAll&&(this.useMask?A.matchedMask=r:A.matchedTerms=s,A.termCount=this.numTerms),A}};function YJe(t,e,n,o){const i=o.tokenize(e);if(!i.length)return;t.fieldCount++,t.docFieldCount.set(n,(t.docFieldCount.get(n)||0)+1);const r=new Set(i);let s=t.docTermFieldHits.get(n);s||(s=new Map,t.docTermFieldHits.set(n,s));for(const a of r)s.set(a,(s.get(a)||0)+1),t.df.set(a,(t.df.get(a)||0)+1)}function kln(t,e,n,o){const{i,v:r,$:s}=e;if(r!==void 0){YJe(t,r,i,o);return}if(s)for(let a=0;a<n;a++){const A=s[a];if(A)if(Array.isArray(A))for(const c of A)YJe(t,c.v,i,o);else YJe(t,A.v,i,o)}}function qMi(t,e,n){const o={fieldCount:0,df:new Map,docFieldCount:new Map,docTermFieldHits:new Map};for(const i of t)kln(o,i,e,n);return o}function $Mi(t,e,n,o){kln(t,e,n,o)}function ZMi(t,e){const n=t.docFieldCount.get(e);if(n===void 0)return;t.fieldCount-=n,t.docFieldCount.delete(e);const o=t.docTermFieldHits.get(e);if(o){for(const[i,r]of o){const s=(t.df.get(i)||0)-r;s<=0?t.df.delete(i):t.df.set(i,s)}t.docTermFieldHits.delete(e)}}function Fln(t,e){if(e.length===0)return;const n=Array.from(new Set(e)).sort((a,A)=>a-A);for(const a of n)ZMi(t,a);const o=a=>{let A=0,c=n.length;for(;A<c;){const l=A+c>>>1;n[l]<a?A=l+1:c=l}return a-A},i=n[0],r=new Map;for(const[a,A]of t.docFieldCount)r.set(a>i?o(a):a,A);t.docFieldCount=r;const s=new Map;for(const[a,A]of t.docTermFieldHits)s.set(a>i?o(a):a,A);t.docTermFieldHits=s}var rw=class{constructor(t,e,n){this.options={...Ea,...e},this.options.useExtendedSearch,this.options.useTokenSearch,this._keyStore=new SMi(this.options.keys),this._docs=t,this._myIndex=null,this._invertedIndex=null,this.setCollection(t,n),this._lastQuery=null,this._lastSearcher=null}_getSearcher(t){if(this._lastQuery===t)return this._lastSearcher;const e=Ume(t,this._invertedIndex?{...this.options,_invertedIndex:this._invertedIndex}:this.options);return this._lastQuery=t,this._lastSearcher=e,e}setCollection(t,e){if(this._docs=t,e&&!(e instanceof DJe))throw new Error(IMi);if(this._myIndex=e||Pln(this.options.keys,this._docs,{getFn:this.options.getFn,fieldNormWeight:this.options.fieldNormWeight}),this.options.useTokenSearch){const n=GJe({isCaseSensitive:this.options.isCaseSensitive,ignoreDiacritics:this.options.ignoreDiacritics,tokenize:this.options.tokenize});this._invertedIndex=qMi(this._myIndex.records,this._myIndex.keys.length,n)}this._invalidateSearcherCache()}add(t){if(!fE(t))return;this._docs.push(t);const e=this._myIndex.add(t,this._docs.length-1);if(this._invertedIndex&&e){const n=GJe({isCaseSensitive:this.options.isCaseSensitive,ignoreDiacritics:this.options.ignoreDiacritics,tokenize:this.options.tokenize});$Mi(this._invertedIndex,e,this._myIndex.keys.length,n)}this._invalidateSearcherCache()}remove(t=()=>!1){const e=[],n=[];for(let o=0,i=this._docs.length;o<i;o+=1)t(this._docs[o],o)&&(e.push(this._docs[o]),n.push(o));if(n.length){this._invertedIndex&&Fln(this._invertedIndex,n);const o=new Set(n);this._docs=this._docs.filter((i,r)=>!o.has(r)),this._myIndex.removeAll(n),this._invalidateSearcherCache()}return e}removeAt(t){if(!Number.isInteger(t)||t<0||t>=this._docs.length)throw new Error(MJe);this._invertedIndex&&Fln(this._invertedIndex,[t]);const e=this._docs.splice(t,1)[0];return this._myIndex.removeAt(t),this._invalidateSearcherCache(),e}_invalidateSearcherCache(){this._lastQuery=null,this._lastSearcher=null}getIndex(){return this._myIndex}_normalizedKeys(){return this._myIndex.keys.map(t=>this._keyStore.get(t.id)||t)}search(t,e){const{limit:n=-1}=e||{},{includeMatches:o,includeScore:i,shouldSort:r,sortFn:s,ignoreFieldNorm:a}=this.options;if(hC(t)&&!t.trim()){let u=this._docs.map((h,d)=>({item:h,refIndex:d}));return Ome(n)&&n>-1&&(u=u.slice(0,n)),u}const A=r&&Ome(n)&&n>0&&hC(t),c=s,l=(u,h)=>c(u,h)||u.idx-h.idx;let g;if(A){const u=new KMi(n,l);hC(this._docs[0])?this._searchStringList(t,{heap:u,ignoreFieldNorm:a}):this._searchObjectList(t,{heap:u,ignoreFieldNorm:a}),g=u.extractSorted()}else g=hC(t)?hC(this._docs[0])?this._searchStringList(t):this._searchObjectList(t):this._searchLogical(t),UMi(g,{ignoreFieldNorm:a}),r&&g.sort(hC(t)?l:c),Ome(n)&&n>-1&&(g=g.slice(0,n));return zMi(g,this._docs,{includeMatches:o,includeScore:i})}_searchStringList(t,{heap:e,ignoreFieldNorm:n}={}){const o=this._getSearcher(t),i=this.options.useTokenSearch&&this.options.tokenMatch==="all",{records:r}=this._myIndex,s=e?null:[];return r.forEach(({v:a,i:A,n:c})=>{if(!fE(a))return;const l=o.searchIn(a);if(l.isMatch){const g={score:l.score,value:a,norm:c,indices:l.indices};i&&(g.matchedMask=l.matchedMask,g.matchedTerms=l.matchedTerms,g.termCount=l.termCount);const u=[g];if(!i||this._coversAllTokens(u)){const h={item:a,idx:A,matches:u};e?(h.score=OJe(h.matches,{ignoreFieldNorm:n}),e.insert(h)):s.push(h)}}}),s}_searchLogical(t){const e=Rln(t,this.options),n=this._normalizedKeys(),o=(a,A,c)=>{if(!("children"in a)){const{keyId:h,searcher:d}=a;let m;return h===null?(m=[],n.forEach((p,_)=>{m.push(...this._findMatches({key:p,value:A[_],searcher:d}))})):m=this._findMatches({key:this._keyStore.get(h),value:this._myIndex.getValueForItemAtKeyId(A,h),searcher:d}),m&&m.length?[{idx:c,item:A,matches:m}]:[]}const{children:l,operator:g}=a,u=[];for(let h=0,d=l.length;h<d;h+=1){const m=l[h],p=o(m,A,c);if(p.length)u.push(...p);else if(g===Kme.AND)return[]}return u},i=this._myIndex.records,r=new Map,s=[];return i.forEach(({$:a,i:A})=>{if(fE(a)){const c=o(e,a,A);c.length&&(r.has(A)||(r.set(A,{idx:A,item:a,matches:[]}),s.push(r.get(A))),c.forEach(({matches:l})=>{r.get(A).matches.push(...l)}))}}),s}_searchObjectList(t,{heap:e,ignoreFieldNorm:n}={}){const o=this._getSearcher(t),i=this.options.useTokenSearch&&this.options.tokenMatch==="all",{records:r}=this._myIndex,s=this._normalizedKeys(),a=e?null:[];return r.forEach(({$:A,i:c})=>{if(!fE(A))return;const l=[];let g=!1,u=!1;if(s.forEach((h,d)=>{const m=this._findMatches({key:h,value:A[d],searcher:o});m.length?(l.push(...m),m[0].hasInverse&&(u=!0)):g=!0}),!(u&&g)&&l.length&&(!i||this._coversAllTokens(l))){const h={idx:c,item:A,matches:l};e?(h.score=OJe(h.matches,{ignoreFieldNorm:n}),e.insert(h)):a.push(h)}}),a}_findMatches({key:t,value:e,searcher:n}){if(!fE(e))return[];const o=[];if(iw(e))e.forEach(({v:i,i:r,n:s})=>{if(!fE(i))return;const a=n.searchIn(i);if(a.isMatch){const A={score:a.score,key:t,value:i,idx:r,norm:s,indices:a.indices,hasInverse:a.hasInverse};a.termCount!==void 0&&(A.matchedMask=a.matchedMask,A.matchedTerms=a.matchedTerms,A.termCount=a.termCount),o.push(A)}});else{const{v:i,n:r}=e,s=n.searchIn(i);if(s.isMatch){const a={score:s.score,key:t,value:i,norm:r,indices:s.indices,hasInverse:s.hasInverse};s.termCount!==void 0&&(a.matchedMask=s.matchedMask,a.matchedTerms=s.matchedTerms,a.termCount=s.termCount),o.push(a)}}return o}_coversAllTokens(t){const e=t.length?t[0].termCount:void 0;if(e===void 0)return!0;if(e<=31){let o=0;for(let i=0;i<t.length;i++)o|=t[i].matchedMask||0;return o===2**e-1}const n=new Set;for(let o=0;o<t.length;o++){const i=t[o].matchedTerms;if(i)for(const r of i)n.add(r)}return n.size===e}};rw.version="7.5.0",rw.createIndex=Pln,rw.parseIndex=PMi,rw.config=Ea,rw.match=function(t,e,n){if(n&&n.useTokenSearch)throw new Error(BMi);return Ume(t,{...Ea,...n}).searchIn(e)},rw.parseQuery=Rln,FJe(OMi),FJe(XMi),rw.use=function(...t){t.forEach(e=>FJe(e))};var eDi=rw;const tDi="https://kicad-mod-cache.tscircuit.com";let UJe=null,v$=null,KJe=null;const nDi=async()=>UJe||v$||(v$=fetch("https://kicad-mod-cache.tscircuit.com/kicad_files.json").then(t=>t.json()).then(t=>(UJe=t,v$=null,t)),v$),oDi=async(t,e=20)=>{const n=await nDi();return KJe||(KJe=new eDi(n)),KJe.search(t).slice(0,e).map(o=>o.item)},iDi=t=>{const e=t.replace(".pretty/","/").replace(".kicad_mod",""),n=`kicad:${e}`;return{path:t,qualifiedName:n,description:e}},rDi=t=>t.replace(/^\/+/,"").split("/").map(e=>encodeURIComponent(e)).join("/"),sDi=async t=>{const e=await fetch(`${tDi}/${rDi(t)}`);if(!e.ok)throw new Error(`KiCad footprint fetch failed: ${e.status}`);const n=await e.text(),{KicadFootprintToCircuitJsonConverter:o}=await gE("kicad-to-circuit-json"),i=new o;return i.addFile(t.split("/").pop()??"selected-footprint.kicad_mod",n),i.runUntilFinished(),i.getOutput()},Lln=t=>t?.source==="jlcpcb"||t?.source==="kicad",aDi=async(t,e)=>{if(t.source==="jlcpcb")return mMi(t.component.partNumber,e?.jlcpcb);if(t.source==="kicad")return sDi(t.footprint.path);throw new Error("Footprint preview is not available for this source")},ADi=({query:t,placeholder:e,isSearching:n,onQueryChange:o,onSubmit:i})=>{const r=ee.useCallback(s=>{s.key==="Enter"&&(s.preventDefault(),i())},[i]);return U.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2 rf-mt-4",children:[U.jsxs("div",{className:"rf-relative rf-flex-grow",children:[U.jsx(_Ve,{className:"rf-absolute rf-left-2 rf-top-2.5 rf-h-4 rf-w-4 rf-text-muted-foreground"}),U.jsx(_ze,{placeholder:e,className:"rf-pl-8",spellCheck:!1,autoComplete:"off",value:t,onChange:s=>o(s.target.value),onKeyDown:r})]}),U.jsx(uA,{onClick:i,disabled:n||t.trim().length<1,className:"sm:rf-px-4 rf-px-3",children:n?U.jsx(sE,{className:"rf-h-4 rf-w-4 rf-animate-spin"}):U.jsxs(U.Fragment,{children:[U.jsx(_Ve,{className:"rf-h-4 rf-w-4 sm:rf-hidden"}),U.jsx("span",{className:"rf-hidden sm:rf-inline",children:"Search"})]})})]})},cDi=new Intl.NumberFormat("en-US",{style:"currency",currency:"USD"}),lDi=t=>cDi.format(t),Hln=t=>{switch(t.source){case"tscircuit.com":{const e=t.package;return`tscircuit-${e.package_id??`${e.org_owner_tscircuit_handle??"unknown"}-${e.unscoped_name??e.name??"package"}`}`}case"jlcpcb":return`jlc-${t.component.lcscId}`;case"kicad":return`kicad-${t.footprint.path}`;default:return"unknown"}},gDi=t=>{switch(t.source){case"tscircuit.com":return t.package.unscoped_name;case"jlcpcb":return t.component.isDirectLookup?t.component.partNumber:t.component.manufacturer;case"kicad":return t.footprint.qualifiedName}},uDi=t=>{switch(t.source){case"tscircuit.com":return t.package.description||(t.package.org_owner_tscircuit_handle?`Component by ${t.package.org_owner_tscircuit_handle}`:void 0);case"jlcpcb":return t.component.description;case"kicad":return t.footprint.description}},dDi=t=>{switch(t.source){case"tscircuit.com":return t.package.name;case"jlcpcb":return t.component.isDirectLookup?void 0:t.component.partNumber;case"kicad":return}},hDi=({results:t,selected:e,onSelect:n,onShowDetails:o})=>{const i=e?Hln(e):null;return U.jsx("div",{className:"rf-divide-y rf-w-full rf-overflow-hidden",children:t.map(r=>{const s=Hln(r),a=i===s,A=gDi(r),c=uDi(r),l=dDi(r),g=r.source==="jlcpcb"?r.component.stock:null,u=r.source==="jlcpcb"?r.component.price:null,h=r.source==="jlcpcb"?r.component.isBasic:null,d=r.source==="jlcpcb"?r.component.isDirectLookup:!1;return U.jsxs("div",{className:`rf-p-3 rf-flex rf-flex-col sm:rf-grid sm:rf-grid-cols-[minmax(0,1fr)_auto] rf-items-start sm:rf-items-center rf-cursor-pointer hover:rf-bg-zinc-100 rf-gap-2 rf-overflow-hidden ${a?"rf-bg-zinc-100":""}`,onClick:()=>n(r),children:[U.jsxs("div",{className:"rf-min-w-0 rf-overflow-hidden rf-w-full",children:[U.jsxs("div",{className:"rf-flex rf-items-start rf-gap-2 rf-min-w-0",children:[U.jsxs("div",{className:"rf-font-medium rf-text-sm rf-truncate rf-flex-1 rf-min-w-0 rf-flex rf-items-center rf-gap-1.5",children:[A,r.source==="jlcpcb"&&h!=null&&U.jsx("span",{className:`rf-text-xs rf-px-1.5 rf-py-0.5 rf-rounded rf-font-medium rf-flex-shrink-0 ${h?"rf-bg-green-100 rf-text-green-700":"rf-bg-orange-100 rf-text-orange-700"}`,children:h?"Basic":"Extended"}),d&&U.jsx("span",{className:"rf-text-xs rf-px-1.5 rf-py-0.5 rf-rounded rf-font-medium rf-flex-shrink-0 rf-bg-blue-100 rf-text-blue-700",children:"Direct lookup"}),r.source==="tscircuit.com"&&r.package.is_private&&U.jsx(c3i,{className:"rf-ml-1 rf-h-3 rf-w-3 rf-text-zinc-400 rf-flex-shrink-0"})]}),r.source==="jlcpcb"&&g!=null?U.jsxs("div",{className:"rf-text-xs rf-text-zinc-500 rf-font-medium rf-whitespace-nowrap rf-flex-shrink-0 sm:rf-hidden",children:[g.toLocaleString()," in stock"]}):null]}),U.jsxs("div",{className:"rf-text-xs rf-text-zinc-500 rf-truncate rf-w-full",children:[l?U.jsx("span",{className:"rf-mr-2",children:l}):null,c]})]}),U.jsxs("div",{children:[r.source==="tscircuit.com"&&o?U.jsx("div",{className:"rf-flex-shrink-0 rf-w-full sm:rf-w-auto",children:U.jsx(uA,{variant:"outline",size:"sm",className:"rf-text-xs rf-w-full sm:rf-w-auto",onClick:m=>{m.stopPropagation(),o(r)},children:"See Details"})}):r.source==="jlcpcb"&&g!=null?U.jsxs("div",{className:"rf-hidden sm:rf-block rf-text-xs rf-text-zinc-500 rf-font-medium rf-whitespace-nowrap rf-flex-shrink-0",children:[g.toLocaleString()," in stock"]}):null,u!=null&&U.jsx("div",{className:"rf-hidden sm:rf-block rf-text-xs rf-text-zinc-500 rf-font-medium rf-whitespace-nowrap rf-flex-shrink-0 rf-text-right",children:lDi(u)})]})]},s)})})},mDi=({circuitJson:t,error:e,isLoading:n,height:o})=>U.jsx("section",{className:"rf-flex rf-min-w-0 rf-items-center rf-justify-center",style:{height:o},children:n?U.jsxs("div",{className:"rf-flex rf-w-full rf-items-center rf-justify-center rf-gap-2 rf-bg-zinc-950 rf-text-sm rf-text-zinc-300",style:{height:o},children:[U.jsx(sE,{className:"rf-h-4 rf-w-4 rf-animate-spin"}),"Loading preview..."]}):e?U.jsx("div",{className:"rf-flex rf-w-full rf-items-center rf-justify-center rf-bg-zinc-950 rf-p-4",style:{height:o},children:U.jsxs("div",{className:"rf-flex rf-max-w-[320px] rf-items-start rf-gap-2 rf-text-sm rf-text-zinc-300",children:[U.jsx(pVe,{className:"rf-mt-0.5 rf-h-4 rf-w-4 rf-flex-shrink-0"}),U.jsx("span",{children:e})]})}):t?U.jsx("div",{className:"rf-w-full rf-min-w-0 rf-overflow-hidden",children:U.jsx(cJe,{circuitJson:t,height:o,allowEditing:!1,clickToInteractEnabled:!1,focusOnHover:!1,disablePcbGroups:!0})}):U.jsx("div",{className:"rf-flex rf-w-full rf-items-center rf-justify-center rf-bg-zinc-950 rf-text-sm rf-text-zinc-300",style:{height:o},children:"No preview"})}),Oln={importComponentDialog:101,importComponentDetailsDialog:102},pDi=({packageResult:t,isOpen:e,onOpenChange:n,isLoading:o,details:i,previewTab:r,onPreviewTabChange:s,isSubmitting:a,onImport:A})=>{const c=t?.package??null,l=c?.latest_pcb_preview_image_url,g=c?.latest_sch_preview_image_url,u=c?.latest_cad_preview_image_url,h=c?.unscoped_name?.split("/").pop()??c?.unscoped_name,d=c?.org_owner_tscircuit_handle??void 0,m=d?`https://tscircuit.com/${d}`:void 0,p=d&&h?`https://tscircuit.com/${d}/${h}`:void 0;return U.jsx(YR,{open:e,onOpenChange:n,children:U.jsxs(tw,{showOverlay:!1,style:{width:"calc(100vw - 2rem)",zIndex:Oln.importComponentDetailsDialog},className:"rf-max-w-5xl no-scrollbar !rf-overflow-y-auto rf-max-h-[90vh] rf-overflow-hidden rf-flex rf-flex-col rf-rounded-sm",children:[U.jsx(nw,{className:"rf-pb-4 rf-border-b",children:U.jsx("div",{className:"rf-flex rf-items-start rf-justify-between rf-gap-4",children:U.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[U.jsx(ow,{className:"rf-text-xl rf-font-semibold rf-truncate",children:h}),U.jsx(UR,{children:c?.description})]})})}),U.jsxs("div",{className:"rf-flex-1 rf-overflow-y-auto rf-py-4 rf-space-y-6",children:[d?U.jsxs("div",{children:[U.jsx("span",{className:"rf-text-xs rf-font-medium rf-text-gray-500 rf-uppercase rf-tracking-wide",children:"Created by"}),U.jsx("div",{className:"rf-mt-1 rf-text-sm rf-font-medium",children:m?U.jsx("a",{href:m,target:"_blank",rel:"noopener noreferrer",className:"rf-text-black hover:rf-underline",children:d}):d})]}):null,(u||l||g)&&U.jsx(U.Fragment,{children:U.jsxs("div",{children:[U.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-mb-4",children:"Preview"}),U.jsxs(HMe,{value:r,onValueChange:_=>s(_),children:[U.jsxs(J0e,{className:"rf-inline-flex rf-h-9 rf-items-center rf-justify-center rf-rounded-lg rf-bg-zinc-100 rf-p-1 rf-text-zinc-500 dark:rf-bg-zinc-800 dark:rf-text-zinc-400",children:[l&&U.jsx(U6,{value:"pcb",children:"PCB"}),g&&U.jsx(U6,{value:"schematic",children:"Schematic"}),u&&U.jsx(U6,{value:"3d",children:"3D"})]}),U.jsxs("div",{className:"rf-mt-4",children:[U.jsx(U1,{value:"pcb",className:"rf-border rf-rounded-lg rf-overflow-hidden rf-bg-gray-50",children:l?U.jsx("img",{src:l,alt:`${h??"package"} PCB preview`,className:"rf-w-full rf-h-full rf-object-contain rf-bg-white rf-p-4"}):null}),U.jsx(U1,{value:"schematic",className:"rf-border rf-rounded-lg rf-overflow-hidden rf-bg-gray-50",children:g?U.jsx("img",{src:g,alt:`${h??"package"} schematic preview`,className:"rf-w-full rf-h-full rf-object-contain rf-bg-white rf-p-4"}):null}),U.jsx(U1,{value:"3d",className:"rf-border rf-rounded-lg rf-overflow-hidden rf-bg-gray-50",children:u?U.jsx("img",{src:u,alt:`${h??"package"} 3D preview`,className:"rf-w-full rf-h-full rf-object-contain rf-bg-white rf-p-4"}):null})]})]})]})}),i?.ai_description?U.jsxs("section",{children:[U.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-mb-3",children:"AI Description"}),U.jsx("div",{className:"rf-bg-gray-50 rf-border rf-border-gray-200 rf-rounded-lg rf-p-4",children:U.jsx("p",{className:"rf-text-sm rf-text-gray-700 rf-leading-relaxed",children:i.ai_description})})]}):null,i?.ai_usage_instructions?U.jsxs("section",{children:[U.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-mb-3",children:"Usage Instructions"}),U.jsx("div",{className:"rf-bg-gray-50 rf-border rf-border-gray-200 rf-rounded-lg rf-p-4",children:U.jsx("p",{className:"rf-text-sm rf-text-gray-700 rf-leading-relaxed rf-whitespace-pre-wrap",children:i.ai_usage_instructions})})]}):null,o?U.jsxs("div",{className:"rf-flex rf-justify-center rf-items-center rf-gap-2 rf-text-gray-500",children:[U.jsx(sE,{className:"rf-h-4 rf-w-4 rf-animate-spin"}),U.jsx("span",{className:"rf-text-sm",children:"Loading package details..."})]}):null]}),U.jsxs(MY,{className:"rf-pt-4 rf-border-t rf-flex rf-flex-col sm:rf-flex-row rf-justify-between rf-gap-2",children:[U.jsx("div",{className:"rf-flex-1",children:p?U.jsxs(uA,{variant:"outline",size:"sm",className:"rf-gap-2 rf-w-full sm:rf-w-auto",onClick:()=>window.open(p,"_blank"),children:[U.jsx(n3i,{className:"rf-h-4 rf-w-4"}),"View on tscircuit.com"]}):null}),U.jsxs("div",{className:"rf-flex rf-flex-col sm:rf-flex-row rf-gap-2",children:[U.jsx(uA,{variant:"outline",onClick:()=>n(!1),className:"rf-order-2 sm:rf-order-1",children:"Close"}),U.jsx(uA,{onClick:A,disabled:a,className:"rf-bg-blue-600 hover:rf-bg-blue-700",children:a?U.jsx(sE,{className:"rf-h-4 rf-w-4 rf-animate-spin"}):"Import Component"})]})]})]})})},_Di=()=>{const[t,e]=ee.useState(null),[n,o]=ee.useState(!1),i=ee.useCallback(async(s,a)=>{o(!0);try{const A=await fetch(`https://api.tscircuit.com/packages/get?name=${encodeURIComponent(`${s}/${a}`)}`);if(!A.ok)throw new Error(`Failed to load package details: ${A.status}`);const c=await A.json();e(c.package??null)}catch(A){console.error("Failed to fetch package details",A),e(null)}finally{o(!1)}},[]),r=ee.useCallback(()=>{e(null),o(!1)},[]);return{details:t,isLoading:n,fetchDetails:i,reset:r}},fDi=(t,e)=>{const[n,o]=ee.useState({circuitJson:null,error:null,isLoading:!1});return ee.useEffect(()=>{if(!t||!Lln(t)){o({circuitJson:null,error:null,isLoading:!1});return}let i=!1;return o({circuitJson:null,error:null,isLoading:!0}),aDi(t,e).then(r=>{i||o({circuitJson:r,error:null,isLoading:!1})}).catch(r=>{i||o({circuitJson:null,error:r instanceof Error?r.message:"Failed to load footprint preview",isLoading:!1})}),()=>{i=!0}},[t,e]),n},IDi=async(t,e)=>{const n={"Content-Type":"application/json"};e&&(n.Authorization=`Bearer ${e}`);const o=await fetch("https://registry-api.tscircuit.com/packages/search",{method:"POST",headers:n,body:JSON.stringify({query:t})});if(!o.ok)throw new Error(`tscircuit registry error: ${o.status}`);return(await o.json()).packages??[]},CDi=({sessionToken:t})=>{const[e,n]=ee.useState([]),[o,i]=ee.useState(!1),[r,s]=ee.useState(null),[a,A]=ee.useState(!1),c=ee.useCallback(async g=>{const u=g.trim();if(!u)return[];i(!0),s(null);try{const d=(await IDi(u,t)).map(m=>({source:"tscircuit.com",package:m}));return n(d),d}catch(h){return console.error("Error searching tscircuit packages",h),n([]),s(h instanceof Error?h.message:"Failed to search tscircuit packages"),[]}finally{i(!1),A(!0)}},[t]),l=ee.useCallback(()=>{n([]),i(!1),s(null),A(!1)},[]);return{results:e,isSearching:o,error:r,hasSearched:a,search:c,reset:l}},yDi=t=>{const e=/^C(\d+)$/i.exec(t.trim());if(!e)return null;const n=Number(e[1]);if(!Number.isSafeInteger(n))return null;const o=`C${e[1]}`;return{source:"jlcpcb",component:{lcscId:n,manufacturer:o,partNumber:o,description:"Import directly from EasyEDA; stock and availability are unknown",package:"",isDirectLookup:!0}}},Gln=(t,e)=>{const n=yDi(t);return n?e.some(i=>i.component.partNumber.toUpperCase()===n.component.partNumber)?e:[n,...e]:e},xDi=t=>{const e=t.trim();return/^C\d+/i.test(e)?e.replace(/^C/i,""):e},EDi=()=>{const[t,e]=ee.useState([]),[n,o]=ee.useState(!1),[i,r]=ee.useState(null),[s,a]=ee.useState(!1),A=ee.useCallback(async l=>{const g=xDi(l);if(!g)return[];o(!0),r(null);try{const u=await uMi(g,10),h=Gln(l,u.map(d=>({source:"jlcpcb",component:dMi(d)})));return e(h),h}catch(u){console.error("Error searching JLCPCB components",u);const h=Gln(l,[]);return e(h),r(h.length>0?null:u instanceof Error?u.message:"Failed to search JLCPCB components"),h}finally{o(!1),a(!0)}},[]),c=ee.useCallback(()=>{e([]),o(!1),r(null),a(!1)},[]);return{results:t,isSearching:n,error:i,hasSearched:s,search:A,reset:c}},BDi=()=>{const[t,e]=ee.useState([]),[n,o]=ee.useState(!1),[i,r]=ee.useState(null),[s,a]=ee.useState(!1),A=ee.useCallback(async l=>{const g=l.trim();if(!g)return[];o(!0),r(null);try{const h=(await oDi(g,20)).map(d=>({source:"kicad",footprint:iDi(d)}));return e(h),h}catch(u){return console.error("Error searching KiCad footprints",u),e([]),r(u instanceof Error?u.message:"Failed to search KiCad footprints"),[]}finally{o(!1),a(!0)}},[]),c=ee.useCallback(()=>{e([]),o(!1),r(null),a(!1)},[]);return{results:t,isSearching:n,error:i,hasSearched:s,search:A,reset:c}},SDi=({onTscircuitPackageSelected:t,onJlcpcbComponentTsxLoaded:e,onKicadStringSelected:n})=>{const o=[];return t&&o.push("tscircuit.com"),e&&o.push("jlcpcb"),n&&o.push("kicad"),o},bDi=({isOpen:t,onClose:e,jlcpcbProxyRequestHeaders:n,onKicadStringSelected:o,onTscircuitPackageSelected:i,onJlcpcbComponentTsxLoaded:r,jlcpcbProxyApiBase:s,tscircuitSessionToken:a})=>{E$();const A=ee.useMemo(()=>SDi({onKicadStringSelected:o,onTscircuitPackageSelected:i,onJlcpcbComponentTsxLoaded:r}),[o,i,r]),c=A.length>0,l=A.length===1,[g,u]=ee.useState(A[0]??"tscircuit.com"),[h,d]=ee.useState(""),[m,p]=ee.useState(null),{results:_,isSearching:f,error:I,hasSearched:C,search:y,reset:x}=CDi({sessionToken:a}),{results:E,isSearching:B,error:b,hasSearched:Q,search:w,reset:D}=EDi(),{results:k,isSearching:R,error:H,hasSearched:G,search:K,reset:Y}=BDi(),{details:X,isLoading:te,fetchDetails:j,reset:J}=_Di(),[ie,oe]=ee.useState(null),[ne,le]=ee.useState(!1),[ge,_e]=ee.useState("pcb"),[ce,Ie]=ee.useState(null),[de,Ce]=ee.useState(!1),Pe=ee.useMemo(()=>({jlcpcb:{headers:n,apiBase:s}}),[s,n]),{circuitJson:Qe,error:pe,isLoading:ve}=fDi(m,Pe),Me=Lln(m);ee.useEffect(()=>{Ie(null)},[m]);const we=ee.useCallback(()=>{x(),D(),Y(),p(null)},[D,Y,x]);ee.useEffect(()=>{t||(we(),d(""),le(!1),oe(null),Ie(null))},[t,we]),ee.useEffect(()=>{d(""),p(null),g==="tscircuit.com"?x():g==="jlcpcb"?D():g==="kicad"&&Y()},[g,D,Y,x]);const Oe=We=>{p(We),oe(We),_e("pcb"),le(!0),J();const nt=We.package.org_owner_tscircuit_handle,xt=We.package.unscoped_name;if(nt&&xt){const It=xt.split("/").pop()??xt;j(nt,It)}},Te=async()=>{h.trim()&&(p(null),g==="tscircuit.com"?await y(h):g==="jlcpcb"?await w(h):g==="kicad"&&await K(h))},Se=async We=>{try{if(Ie(null),Ce(!0),We.source==="kicad"){if(!o)throw new Error("KiCad handler not provided");await o({result:We,footprint:We.footprint.qualifiedName})}else if(We.source==="jlcpcb"){if(!r)throw new Error("JLCPCB handler not provided");const nt=await hMi(We.component.partNumber,{headers:n,apiBase:s});await r({result:We,tsx:nt})}else if(We.source==="tscircuit.com"){if(!i)throw new Error("tscircuit package handler not provided");const nt=We.package.org_owner_tscircuit_handle,xt=We.package.unscoped_name;if(!nt||!xt)throw new Error("Missing package metadata");const It=xt.split("/").pop()??xt,Tt=`@tsci/${nt}.${It}`;await i({result:We,fullPackageName:Tt})}return!0}catch(nt){return console.error("Failed to import component",nt),Ie(nt instanceof Error?nt.message:"Failed to import component"),!1}finally{Ce(!1)}};let Le=[],ye=!1,Fe=null,Ye=!1;g==="tscircuit.com"?(Le=_,ye=f,Fe=I,Ye=C):g==="jlcpcb"?(Le=E,ye=B,Fe=b,Ye=Q):g==="kicad"&&(Le=k,ye=R,Fe=H,Ye=G);const qe=async()=>{if(!m)return;await Se(m)&&(e(),we(),d(""))},at=We=>{We||e()},rt=We=>{le(We),We||oe(null)};return U.jsxs(YR,{open:t,onOpenChange:at,children:[U.jsxs(tw,{style:{width:"calc(100vw - 2rem)",maxWidth:Me?"min(1120px, calc(100vw - 2rem))":"min(672px, calc(100vw - 2rem))",zIndex:Oln.importComponentDialog},className:"rf-rounded-sm rf-max-h-[90vh] rf-overflow-y-auto rf-overflow-x-hidden rf-flex rf-flex-col",children:[U.jsxs(nw,{children:[U.jsxs(ow,{className:"rf-text-lg sm:rf-text-xl",children:["Import ",l?Hme[g].label:""," ","Component"]}),U.jsx(UR,{className:"rf-text-sm",children:c?"Search for components from available sources.":"Import options are disabled because no handlers were provided."})]}),c?U.jsxs(HMe,{value:g,onValueChange:We=>u(We),className:"rf-min-w-0 rf-w-full",children:[!l&&U.jsx(J0e,{className:"rf-flex rf-w-full rf-gap-2",children:A.map(We=>U.jsx(U6,{value:We,className:"rf-flex-1 rf-text-xs sm:rf-text-sm",children:Hme[We].label},We))}),U.jsxs("div",{className:"rf-min-w-0",style:Me?{display:"grid",gridTemplateColumns:"minmax(0, 1fr) minmax(360px, 0.95fr)",gap:"1.5rem",alignItems:"start"}:void 0,children:[U.jsxs("div",{className:"rf-min-w-0",children:[U.jsx(ADi,{query:h,placeholder:Hme[g].placeholder,isSearching:ye,onQueryChange:d,onSubmit:Te}),U.jsx("div",{className:"no-scrollbar rf-mt-4 rf-flex-1 rf-min-h-[200px] !rf-max-h-[40vh] !rf-overflow-y-auto rf-overflow-x-hidden rf-border rf-rounded-md rf-min-w-0",children:ye?U.jsxs("div",{className:"rf-p-8 rf-text-center rf-text-zinc-500",children:[U.jsx(sE,{className:"rf-h-8 rf-w-8 rf-animate-spin rf-mx-auto rf-mb-2"}),U.jsx("p",{children:"Searching..."})]}):Le.length>0?U.jsx(hDi,{results:Le,selected:m,onSelect:p,onShowDetails:g==="tscircuit.com"?Oe:void 0}):U.jsx("div",{className:"rf-p-8 rf-text-center rf-text-zinc-500",children:Fe?`Error: ${Fe}`:Ye?Hme[g].emptyMessage:"Enter a search term to find components"})})]}),Me?U.jsx("div",{className:"rf-mt-4",children:U.jsx(mDi,{circuitJson:Qe,error:pe,isLoading:ve,height:325})}):null]})]}):null,ce?U.jsx("div",{className:"rf-text-sm rf-text-red-600 rf-mt-2",children:ce}):null,U.jsxs(MY,{className:"rf-flex rf-flex-col sm:rf-flex-row rf-gap-2",children:[U.jsx(uA,{variant:"outline",onClick:e,className:"rf-order-2 sm:rf-order-1",children:"Cancel"}),U.jsx(uA,{onClick:qe,disabled:!m||de,className:"rf-order-1 sm:rf-order-2",children:de?U.jsx(sE,{className:"rf-h-4 rf-w-4 rf-animate-spin"}):"Import"})]})]}),U.jsx(pDi,{packageResult:ie,isOpen:ne,onOpenChange:rt,isLoading:te,details:X,previewTab:ge,onPreviewTabChange:We=>_e(We),isSubmitting:de,onImport:()=>{ie&&Se(ie).then(We=>{We&&(le(!1),e(),we(),d(""))})}})]})},QDi=t=>{const e=t.match(/export const (\w+) =/);if(!e)throw new Error("Could not determine component name from TSX contents");return e[1]},Yln=t=>{const e=id(s=>s.pushEvent),n=id(s=>s.upsertFile),o=async({result:s,fullPackageName:a})=>{const c=s.package.unscoped_name??s.package.name;await ra.promise(e({event_type:"INSTALL_PACKAGE",full_package_name:a}),{loading:`Requesting install for "${c}"`,success:`Install requested for "${c}"`,error:l=>`Failed to request install: ${l instanceof Error?l.message:String(l)}`})},i=async({footprint:s})=>{await ra.promise(navigator.clipboard.writeText(s),{loading:`Copying "${s}"`,success:`Copied "${s}" to clipboard`,error:a=>`Failed to copy footprint: ${a instanceof Error?a.message:String(a)}`})},r=async({result:s,tsx:a})=>{const c=`imports/${QDi(a)}.tsx`;await ra.promise(n(c,a),{loading:`Importing ${s.component.partNumber}`,success:`Imported to "${c}"`,error:l=>`Failed to import component: ${l instanceof Error?l.message:String(l)}`})};return U.jsx(bDi,{...t,onTscircuitPackageSelected:o,onKicadStringSelected:i,onJlcpcbComponentTsxLoaded:r})};Yln.displayName="ImportComponentDialogForCli";const vDi=async({circuitJson:t,projectName:e})=>{const{convertCircuitJsonToAltiumZip:n}=await Promise.resolve().then(()=>$nr),o=await n(t,e);return new Blob([new Uint8Array(o)],{type:"application/zip"})},PDi=async({circuitJson:t,projectName:e})=>{await ra.promise((async()=>{const n=await vDi({circuitJson:t,projectName:e});_E(n,{fileName:`${e}_altium_project.zip`})})(),{loading:"Generating Altium project...",success:"Altium project ZIP ready",error:n=>`Failed to generate Altium project: ${n instanceof Error?n.message:String(n)}`})};var VJe={exports:{}},Uln;function wDi(){return Uln||(Uln=1,(function(t,e){var n={env:{},version:""};(function(o){t.exports=o()})(function(){return(function o(i,r,s){function a(l,g){if(!r[l]){if(!i[l]){var u=typeof g8=="function"&&g8;if(!g&&u)return u(l,!0);if(A)return A(l,!0);var h=new Error("Cannot find module '"+l+"'");throw h.code="MODULE_NOT_FOUND",h}var d=r[l]={exports:{}};i[l][0].call(d.exports,function(m){var p=i[l][1][m];return a(p||m)},d,d.exports,o,i,r,s)}return r[l].exports}for(var A=typeof g8=="function"&&g8,c=0;c<s.length;c++)a(s[c]);return a})({1:[function(o,i,r){var s=o("./utils"),a=o("./support"),A="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";r.encode=function(c){for(var l,g,u,h,d,m,p,_=[],f=0,I=c.length,C=I,y=s.getTypeOf(c)!=="string";f<c.length;)C=I-f,u=y?(l=c[f++],g=f<I?c[f++]:0,f<I?c[f++]:0):(l=c.charCodeAt(f++),g=f<I?c.charCodeAt(f++):0,f<I?c.charCodeAt(f++):0),h=l>>2,d=(3&l)<<4|g>>4,m=1<C?(15&g)<<2|u>>6:64,p=2<C?63&u:64,_.push(A.charAt(h)+A.charAt(d)+A.charAt(m)+A.charAt(p));return _.join("")},r.decode=function(c){var l,g,u,h,d,m,p=0,_=0,f="data:";if(c.substr(0,f.length)===f)throw new Error("Invalid base64 input, it looks like a data url.");var I,C=3*(c=c.replace(/[^A-Za-z0-9+/=]/g,"")).length/4;if(c.charAt(c.length-1)===A.charAt(64)&&C--,c.charAt(c.length-2)===A.charAt(64)&&C--,C%1!=0)throw new Error("Invalid base64 input, bad content length.");for(I=a.uint8array?new Uint8Array(0|C):new Array(0|C);p<c.length;)l=A.indexOf(c.charAt(p++))<<2|(h=A.indexOf(c.charAt(p++)))>>4,g=(15&h)<<4|(d=A.indexOf(c.charAt(p++)))>>2,u=(3&d)<<6|(m=A.indexOf(c.charAt(p++))),I[_++]=l,d!==64&&(I[_++]=g),m!==64&&(I[_++]=u);return I}},{"./support":30,"./utils":32}],2:[function(o,i,r){var s=o("./external"),a=o("./stream/DataWorker"),A=o("./stream/Crc32Probe"),c=o("./stream/DataLengthProbe");function l(g,u,h,d,m){this.compressedSize=g,this.uncompressedSize=u,this.crc32=h,this.compression=d,this.compressedContent=m}l.prototype={getContentWorker:function(){var g=new a(s.Promise.resolve(this.compressedContent)).pipe(this.compression.uncompressWorker()).pipe(new c("data_length")),u=this;return g.on("end",function(){if(this.streamInfo.data_length!==u.uncompressedSize)throw new Error("Bug : uncompressed data size mismatch")}),g},getCompressedWorker:function(){return new a(s.Promise.resolve(this.compressedContent)).withStreamInfo("compressedSize",this.compressedSize).withStreamInfo("uncompressedSize",this.uncompressedSize).withStreamInfo("crc32",this.crc32).withStreamInfo("compression",this.compression)}},l.createWorkerFrom=function(g,u,h){return g.pipe(new A).pipe(new c("uncompressedSize")).pipe(u.compressWorker(h)).pipe(new c("compressedSize")).withStreamInfo("compression",u)},i.exports=l},{"./external":6,"./stream/Crc32Probe":25,"./stream/DataLengthProbe":26,"./stream/DataWorker":27}],3:[function(o,i,r){var s=o("./stream/GenericWorker");r.STORE={magic:"\0\0",compressWorker:function(){return new s("STORE compression")},uncompressWorker:function(){return new s("STORE decompression")}},r.DEFLATE=o("./flate")},{"./flate":7,"./stream/GenericWorker":28}],4:[function(o,i,r){var s=o("./utils"),a=(function(){for(var A,c=[],l=0;l<256;l++){A=l;for(var g=0;g<8;g++)A=1&A?3988292384^A>>>1:A>>>1;c[l]=A}return c})();i.exports=function(A,c){return A!==void 0&&A.length?s.getTypeOf(A)!=="string"?(function(l,g,u,h){var d=a,m=h+u;l^=-1;for(var p=h;p<m;p++)l=l>>>8^d[255&(l^g[p])];return-1^l})(0|c,A,A.length,0):(function(l,g,u,h){var d=a,m=h+u;l^=-1;for(var p=h;p<m;p++)l=l>>>8^d[255&(l^g.charCodeAt(p))];return-1^l})(0|c,A,A.length,0):0}},{"./utils":32}],5:[function(o,i,r){r.base64=!1,r.binary=!1,r.dir=!1,r.createFolders=!0,r.date=null,r.compression=null,r.compressionOptions=null,r.comment=null,r.unixPermissions=null,r.dosPermissions=null},{}],6:[function(o,i,r){var s=null;s=typeof Promise<"u"?Promise:o("lie"),i.exports={Promise:s}},{lie:37}],7:[function(o,i,r){var s=typeof Uint8Array<"u"&&typeof Uint16Array<"u"&&typeof Uint32Array<"u",a=o("pako"),A=o("./utils"),c=o("./stream/GenericWorker"),l=s?"uint8array":"array";function g(u,h){c.call(this,"FlateWorker/"+u),this._pako=null,this._pakoAction=u,this._pakoOptions=h,this.meta={}}r.magic="\b\0",A.inherits(g,c),g.prototype.processChunk=function(u){this.meta=u.meta,this._pako===null&&this._createPako(),this._pako.push(A.transformTo(l,u.data),!1)},g.prototype.flush=function(){c.prototype.flush.call(this),this._pako===null&&this._createPako(),this._pako.push([],!0)},g.prototype.cleanUp=function(){c.prototype.cleanUp.call(this),this._pako=null},g.prototype._createPako=function(){this._pako=new a[this._pakoAction]({raw:!0,level:this._pakoOptions.level||-1});var u=this;this._pako.onData=function(h){u.push({data:h,meta:u.meta})}},r.compressWorker=function(u){return new g("Deflate",u)},r.uncompressWorker=function(){return new g("Inflate",{})}},{"./stream/GenericWorker":28,"./utils":32,pako:38}],8:[function(o,i,r){function s(d,m){var p,_="";for(p=0;p<m;p++)_+=String.fromCharCode(255&d),d>>>=8;return _}function a(d,m,p,_,f,I){var C,y,x=d.file,E=d.compression,B=I!==l.utf8encode,b=A.transformTo("string",I(x.name)),Q=A.transformTo("string",l.utf8encode(x.name)),w=x.comment,D=A.transformTo("string",I(w)),k=A.transformTo("string",l.utf8encode(w)),R=Q.length!==x.name.length,H=k.length!==w.length,G="",K="",Y="",X=x.dir,te=x.date,j={crc32:0,compressedSize:0,uncompressedSize:0};m&&!p||(j.crc32=d.crc32,j.compressedSize=d.compressedSize,j.uncompressedSize=d.uncompressedSize);var J=0;m&&(J|=8),B||!R&&!H||(J|=2048);var ie=0,oe=0;X&&(ie|=16),f==="UNIX"?(oe=798,ie|=(function(le,ge){var _e=le;return le||(_e=ge?16893:33204),(65535&_e)<<16})(x.unixPermissions,X)):(oe=20,ie|=(function(le){return 63&(le||0)})(x.dosPermissions)),C=te.getUTCHours(),C<<=6,C|=te.getUTCMinutes(),C<<=5,C|=te.getUTCSeconds()/2,y=te.getUTCFullYear()-1980,y<<=4,y|=te.getUTCMonth()+1,y<<=5,y|=te.getUTCDate(),R&&(K=s(1,1)+s(g(b),4)+Q,G+="up"+s(K.length,2)+K),H&&(Y=s(1,1)+s(g(D),4)+k,G+="uc"+s(Y.length,2)+Y);var ne="";return ne+=`
5587
+ `,g=new Blob([l],{type:"text/plain"}),u=URL.createObjectURL(g),h=document.createElement("a");h.href=u,h.download=`${c}.test.ts`,h.click(),URL.revokeObjectURL(u)}catch(A){alert(`Error generating test.ts for ${t.getSolverName()}: ${A instanceof Error?A.message:String(A)}`)}o(!1)};return U.jsxs("div",{className:`relative ${e}`,ref:i,children:[U.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>o(!n),title:`Download options for ${t.getSolverName()}`,children:t.getSolverName()}),n&&U.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:[U.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:r,children:"Download JSON"}),U.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),U.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:a,children:"Download test.ts"})]})]})},jcn=t=>t.activeSubSolver?[t,...jcn(t.activeSubSolver)]:[t],VPi=({solver:t})=>{const e=jcn(t);return U.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:e.map((n,o)=>U.jsxs("div",{className:"flex items-center",children:[o>0&&U.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),U.jsx(KPi,{solver:n})]},n.getSolverName()))})},zPi=({solver:t,triggerRender:e,animationSpeed:n=25,renderer:o,onRendererChange:i,onAnimationSpeedChange:r,onDownloadVisualization:s,onSolverStarted:a,onSolverCompleted:A})=>{const[c,l]=ee.useReducer(B=>!B,!1),g=ee.useRef(void 0),u=ee.useRef(null),h="solver-debugger-last-iteration",[d,m]=ee.useState(null),p=ee.useRef(null),_=ee.useMemo(()=>[{label:"Slow",value:250,description:"250ms"},{label:"Normal",value:100,description:"100ms"},{label:"Fast",value:10,description:"10ms"},{label:"Fast (2x)",value:5,description:"5ms"},{label:"Fast (10x)",value:1,description:"1ms"},{label:"Fast 20x",value:.5,description:"2 steps / 1ms"},{label:"Fast 100x",value:.1,description:"10 steps / 1ms"}],[]),f=()=>{const B=Math.max(1,n),b=n<1?Math.round(1/n):1;g.current=setInterval(()=>{if(t.solved||t.failed){g.current&&(clearInterval(g.current),g.current=void 0),l(),e(),A&&t.solved&&A(t);return}for(let Q=0;Q<b&&!(t.solved||t.failed);Q++)t.step();e()},B)},I=()=>{g.current&&(clearInterval(g.current),g.current=void 0)},C=()=>{!t.solved&&!t.failed&&(t.step(),e())},y=()=>{!t.solved&&!t.failed&&(a&&a(t),t.solve(),e(),A&&A(t))},x=()=>{c?(I(),l()):(l(),f())},E=()=>{if(t.solved||t.failed||c)return;u.current===null&&typeof window<"u"&&(u.current=window.localStorage.getItem(h));const B=window.prompt("Step until which iteration?",u.current??`${t.iterations}`);if(B===null)return;u.current=B,typeof window<"u"&&window.localStorage.setItem(h,B);const b=Number(B);if(!Number.isFinite(b)){window.alert("Please enter a valid number for the iteration");return}for(;t.iterations<b&&!t.solved&&!t.failed;)t.step();e(),t.solved&&A&&A(t)};return ee.useEffect(()=>()=>{I()},[]),ee.useEffect(()=>{(t.solved||t.failed)&&c&&(I(),l())},[t.solved,t.failed,c]),ee.useEffect(()=>{c&&(I(),f())},[n,c]),ee.useEffect(()=>{if(typeof document>"u")return;const B=b=>{p.current&&!p.current.contains(b.target)&&m(null)};return document.addEventListener("mousedown",B),()=>{document.removeEventListener("mousedown",B)}},[]),U.jsxs("div",{className:"space-y-2 p-2 border-b",children:[U.jsx("div",{className:"flex items-center",children:U.jsxs("div",{className:"flex items-center gap-2",ref:p,children:[U.jsxs("div",{className:"flex h-9 items-center space-x-1 rounded-md border border-slate-200 bg-white p-1 shadow-sm",children:[U.jsxs("div",{className:"relative",children:[U.jsx("button",{type:"button",onClick:()=>m(d==="renderer"?null:"renderer"),className:"flex select-none items-center rounded-sm px-3 py-1 text-sm font-medium outline-none focus:bg-slate-100 data-[state=open]:bg-slate-100","data-state":d==="renderer"?"open":"closed",children:"Renderer"}),d==="renderer"&&U.jsx("div",{className:"absolute left-0 z-50 mt-1 min-w-[10rem] rounded-md border border-slate-200 bg-white p-1 text-slate-950 shadow-md",children:["vector","canvas"].map(B=>U.jsxs("button",{type:"button",onClick:()=>{i(B),m(null)},className:"flex w-full items-center rounded-sm px-2 py-1.5 text-sm hover:bg-slate-100",children:[B==="vector"?"Vector":"Canvas",o===B&&U.jsx("span",{className:"ml-auto text-xs text-slate-500",children:"✓"})]},B))})]}),U.jsxs("div",{className:"relative",children:[U.jsx("button",{type:"button",onClick:()=>m(d==="debug"?null:"debug"),className:"flex select-none items-center rounded-sm px-3 py-1 text-sm font-medium outline-none focus:bg-slate-100 data-[state=open]:bg-slate-100","data-state":d==="debug"?"open":"closed",children:"Debug"}),d==="debug"&&U.jsx("div",{className:"absolute left-0 z-50 mt-1 min-w-[12rem] rounded-md border border-slate-200 bg-white p-1 text-slate-950 shadow-md",children:U.jsx("button",{type:"button",onClick:()=>{s(),m(null)},className:"flex w-full items-center rounded-sm px-2 py-1.5 text-sm hover:bg-slate-100",children:"Download Visualization"})})]}),U.jsxs("div",{className:"relative",children:[U.jsx("button",{type:"button",onClick:()=>m(d==="animation"?null:"animation"),className:"flex select-none items-center rounded-sm px-3 py-1 text-sm font-medium outline-none focus:bg-slate-100 data-[state=open]:bg-slate-100","data-state":d==="animation"?"open":"closed",children:"Animation"}),d==="animation"&&U.jsx("div",{className:"absolute left-0 z-50 mt-1 min-w-[12rem] rounded-md border border-slate-200 bg-white p-1 text-slate-950 shadow-md",children:_.map(B=>U.jsxs("button",{type:"button",onClick:()=>{r(B.value),m(null)},className:"flex w-full items-center rounded-sm px-2 py-1.5 text-sm hover:bg-slate-100",children:[B.label,U.jsx("span",{className:"ml-auto text-xs text-slate-500",children:B.description}),n===B.value&&U.jsx("span",{className:"ml-2 text-xs text-slate-500",children:"✓"})]},B.value))})]})]}),U.jsx(VPi,{solver:t})]})}),U.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[U.jsx("button",{onClick:C,disabled:t.solved||t.failed||c,className:"bg-blue-500 hover:bg-blue-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step"}),U.jsx("button",{onClick:y,disabled:t.solved||t.failed||c,className:"bg-green-500 hover:bg-green-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Solve"}),U.jsx("button",{onClick:x,disabled:t.solved||t.failed,className:`px-3 py-1 rounded text-white text-sm ${c?"bg-red-500 hover:bg-red-600":"bg-yellow-500 hover:bg-yellow-600"} disabled:bg-gray-300`,children:c?"Stop":"Animate"}),U.jsx("button",{onClick:E,disabled:t.solved||t.failed||c,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"}),U.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",t.iterations]}),t.timeToSolve!==void 0&&U.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(t.timeToSolve/1e3).toFixed(3),"s"]}),t.solved&&U.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),t.failed&&U.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),t.error&&U.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",t.error]})]})},JPi=t=>t!==null&&"pipelineDef"in t&&Array.isArray(t.pipelineDef),WPi=(t,e,n)=>{const o=t.currentPipelineStageIndex;return e<o?"Completed":e===o&&t.activeSubSolver?t.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},jPi=(t,e)=>{const o=t.pipelineDef[e].solverName,i=WPi(t,e),r=t[o],s=t.firstIterationOfStage?.[o]??(e===t.currentPipelineStageIndex?t.iterations:null),a=t.iterations;let A=0;if(i==="Completed"){const u=t.pipelineDef[e+1],h=u?t.firstIterationOfStage?.[u.solverName]:void 0;h!==void 0&&s!==null?A=h-s:s!==null&&(A=a-s)}else i==="In Progress"&&s!==null&&(A=a-s);const c=t.timeSpentOnStage?.[o]??0;let l=0;i==="Completed"?l=1:i==="In Progress"&&r&&(l=r.progress??0);const g=r?.stats??null;return{index:e,name:o,status:i,firstIteration:s,iterations:A,progress:l,timeSpent:c,stats:g&&Object.keys(g).length>0?g:null,solverInstance:r??null}},XPi=({status:t})=>{const e={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return U.jsx("span",{className:`font-medium ${e[t]}`,children:t})},qPi=({progress:t})=>{if(t===0)return null;const e=Math.round(t*100);return U.jsxs("div",{className:"flex items-center gap-2",children:[U.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:U.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${e}%`}})}),U.jsxs("span",{className:"text-xs text-gray-500",children:[e,"%"]})]})},Xcn=t=>{if(typeof t=="string")return t;if(typeof t=="number"||typeof t=="boolean"||typeof t=="bigint"||t==null)return String(t);if(typeof t=="object")try{return JSON.stringify(t)}catch{return String(t)}return String(t)},$Pi=t=>Object.entries(t).map(([e,n])=>`${e}: ${Xcn(n)}`).join(", "),ZPi=({stats:t})=>{if(!t||Object.keys(t).length===0)return U.jsx("span",{children:"-"});const e=Object.entries(t),n=$Pi(t);return U.jsxs("details",{className:"cursor-pointer",children:[U.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:n}),U.jsx("div",{className:"mt-1 text-xs",children:e.map(([o,i])=>U.jsxs("div",{children:[o,": ",Xcn(i)]},o))})]})},mJe=t=>{if(t===null||typeof t!="object")return t;if(Array.isArray(t))return t.map(mJe);const e={};for(const[n,o]of Object.entries(t))n.startsWith("_")||(e[n]=mJe(o));return e},ewi=(t,e)=>{try{if(typeof t.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${e}`);return}const n=mJe(t.getConstructorParams()),o=new Blob([JSON.stringify(n,null,2)],{type:"application/json"}),i=URL.createObjectURL(o),r=document.createElement("a");r.href=i,r.download=`${e}_input.json`,r.click(),URL.revokeObjectURL(i)}catch(n){alert(`Error downloading input for ${e}: ${n instanceof Error?n.message:String(n)}`)}},twi=({expanded:t})=>U.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:`w-4 h-4 transition-transform duration-200 ${t?"rotate-90":""}`,children:U.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"})}),qcn=t=>{let e=t;for(;e.activeSubSolver;)e=e.activeSubSolver;return e},$cn=({solver:t,onStepUntilPhase:e,onDownloadInput:n,isNested:o=!1,indentLevel:i=0,triggerRender:r})=>{const[s,a]=ee.useState(new Set),A=t.pipelineDef.map((p,_)=>jPi(t,_)),c=p=>{a(_=>{const f=new Set(_);return f.has(p)?f.delete(p):f.add(p),f})},l=p=>{e?.(p)},g=p=>{p.solverInstance&&(n?n(p.solverInstance,p.name):ewi(p.solverInstance,p.name))},u=p=>`${(p/1e3).toFixed(2)}s`,h=()=>{if(!t.solved&&!t.failed){const p=t.activeSubSolver;for(;!t.solved&&!t.failed&&(t.step(),!(t.activeSubSolver&&t.activeSubSolver!==p)););r?.()}},d=()=>{if(!t.solved&&!t.failed){const p=qcn(t);for(;!t.solved&&!t.failed&&(t.step(),qcn(t)===p););r?.()}},m=i*24;return U.jsxs("div",{className:o?"":"border-t border-gray-200",children:[!o&&U.jsxs("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200 flex items-center justify-between",children:[U.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Stages"}),U.jsxs("div",{className:"flex gap-2",children:[U.jsx("button",{onClick:d,disabled:t.solved||t.failed,className:"bg-indigo-500 hover:bg-indigo-600 disabled:bg-gray-300 disabled:cursor-not-allowed cursor-pointer text-white px-3 py-1 rounded text-sm",children:"Next Solver"}),U.jsx("button",{onClick:h,disabled:t.solved||t.failed,className:"bg-purple-500 hover:bg-purple-600 disabled:bg-gray-300 disabled:cursor-not-allowed cursor-pointer text-white px-3 py-1 rounded text-sm",children:"Next Stage"})]})]}),U.jsx("div",{className:"overflow-x-auto",children:U.jsxs("table",{className:"w-full text-sm",children:[!o&&U.jsx("thead",{children:U.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[U.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stage"}),U.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),U.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",U.jsx("sub",{children:"0"})]}),U.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),U.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),U.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),U.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),U.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),U.jsx("tbody",{children:A.map(p=>{const _=JPi(p.solverInstance),f=s.has(p.name);return U.jsxs(Ms.Fragment,{children:[U.jsxs("tr",{className:`border-b border-gray-100 ${p.status==="In Progress"?"bg-yellow-50":""}`,children:[U.jsx("td",{className:"px-4 py-2",children:U.jsxs("div",{className:"flex items-center gap-2",style:{paddingLeft:m},children:[_?U.jsx("button",{onClick:()=>c(p.name),className:"text-gray-500 hover:text-gray-700",title:f?"Collapse":"Expand",children:U.jsx(twi,{expanded:f})}):U.jsx("span",{className:"w-4"}),U.jsx("span",{className:"text-gray-400 w-6",children:String(p.index+1).padStart(2,"0")}),U.jsx("button",{onClick:()=>l(p.name),disabled:p.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 ${p.name} completes`,children:U.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:U.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"})})}),U.jsx("span",{className:"font-medium text-gray-900",children:p.name})]})}),U.jsx("td",{className:"px-4 py-2",children:U.jsx(XPi,{status:p.status})}),U.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:p.firstIteration!==null?p.firstIteration:""}),U.jsx("td",{className:"px-4 py-2 text-gray-600",children:p.iterations}),U.jsx("td",{className:"px-4 py-2",children:U.jsx(qPi,{progress:p.progress})}),U.jsx("td",{className:"px-4 py-2 text-gray-600",children:u(p.timeSpent)}),U.jsx("td",{className:"px-4 py-2 text-gray-500",children:U.jsx(ZPi,{stats:p.stats})}),U.jsx("td",{className:"px-4 py-2",children:p.solverInstance?U.jsxs("button",{onClick:()=>g(p),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${p.name}`,children:[U.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:U.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"})}),U.jsx("span",{children:"Input"})]}):null})]}),_&&f&&U.jsx("tr",{children:U.jsx("td",{colSpan:8,className:"p-0",children:U.jsx($cn,{solver:p.solverInstance,onStepUntilPhase:e,onDownloadInput:n,isNested:!0,indentLevel:i+1,triggerRender:r})})})]},p.name)})})]})})]})};function nwi({graphics:t}){const e=t.points??[],n=t.lines??[],o=t.rects??[],i=t.circles??[],r=t.texts??[];let s=Number.POSITIVE_INFINITY,a=Number.POSITIVE_INFINITY,A=Number.NEGATIVE_INFINITY,c=Number.NEGATIVE_INFINITY;const l=(p,_)=>{typeof p=="number"&&(p<s&&(s=p),p>A&&(A=p)),typeof _=="number"&&(_<a&&(a=_),_>c&&(c=_))};for(const p of e)l(p.x,p.y);for(const p of n){const _=p.points??[];for(const f of _)l(f.x,f.y)}for(const p of o){const _=p.x??0,f=p.y??0,I=p.width??0,C=p.height??0;l(_,f),l(_+I,f+C)}for(const p of i){const _=p.x??0,f=p.y??0,I=p.radius??1;l(_-I,f-I),l(_+I,f+I)}for(const p of r)l(p.x,p.y);(!isFinite(s)||!isFinite(a)||!isFinite(A)||!isFinite(c))&&(s=-20,a=-20,A=20,c=20);const g=10,u=s-g,h=a-g,d=Math.max(1,A-s+2*g),m=Math.max(1,c-a+2*g);return U.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${u} ${h} ${d} ${m}`,role:"img","aria-label":"Graphics fallback",children:[o.map((p,_)=>U.jsx("rect",{x:p.x??0,y:p.y??0,width:p.width??0,height:p.height??0,fill:"none",stroke:p.strokeColor??"black",strokeWidth:p.strokeWidth??1},`rect-${_}`)),n.map((p,_)=>U.jsx("polyline",{fill:"none",stroke:p.strokeColor??"black",strokeWidth:p.strokeWidth??1,points:(p.points??[]).map(f=>`${f.x??0},${f.y??0}`).join(" ")},`line-${_}`)),i.map((p,_)=>U.jsx("circle",{cx:p.x??0,cy:p.y??0,r:p.radius??1.5,fill:p.fillColor??"none",stroke:p.strokeColor??"black",strokeWidth:p.strokeWidth??1},`circle-${_}`)),e.map((p,_)=>U.jsx("circle",{cx:p.x??0,cy:p.y??0,r:p.radius??1.5,fill:p.color??"black"},`point-${_}`)),r.map((p,_)=>U.jsx("text",{x:p.x??0,y:p.y??0,fontSize:p.fontSize??10,fill:p.color??"black",children:p.text??""},`text-${_}`))]})}var owi=class extends Ms.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}},iwi=({solver:t,createSolver:e,animationSpeed:n=25,onSolverStarted:o,onSolverCompleted:i})=>{const[r,s]=ee.useReducer(f=>f+1,0),[a]=ee.useState(()=>{if(e)return e();if(!t)throw new Error("GenericSolverDebugger requires solver or createSolver");return t}),[A,c]=ee.useState(()=>typeof window>"u"?"vector":window.localStorage.getItem("solver-utils-renderer")==="canvas"?"canvas":"vector"),[l,g]=ee.useState(n),u=ee.useMemo(()=>{try{return a.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(f){return console.error("Visualization error:",f),{points:[],lines:[],rects:[],circles:[]}}},[a,r]),h=ee.useMemo(()=>(u.rects?.length||0)===0&&(u.lines?.length||0)===0&&(u.points?.length||0)===0&&(u.circles?.length||0)===0,[u]);ee.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const f=document.createElement("script");f.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(f)}},[]),ee.useEffect(()=>{g(n)},[n]);const d=a.pipelineDef!==void 0,m=f=>{const I=a;if(!a.solved&&!a.failed){for(;!a.solved&&!a.failed&&I.currentPipelineStageIndex<=I.pipelineDef.findIndex(C=>C.solverName===f);)a.step();s()}},p=()=>{const f=JSON.stringify(u,null,2),I=new Blob([f],{type:"application/json"}),C=URL.createObjectURL(I),y=document.createElement("a");y.download="visualization.json",y.href=C,document.body.appendChild(y),y.click(),document.body.removeChild(y),URL.revokeObjectURL(C)},_=f=>{c(f),typeof window<"u"&&window.localStorage.setItem("solver-utils-renderer",f)};return U.jsxs("div",{children:[U.jsx(zPi,{solver:a,triggerRender:s,animationSpeed:l,renderer:A,onRendererChange:_,onAnimationSpeedChange:g,onDownloadVisualization:p,onSolverStarted:o,onSolverCompleted:i}),h?U.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):U.jsx(owi,{fallback:U.jsx(nwi,{graphics:u}),children:A==="canvas"?U.jsx(UPi,{graphics:u}):U.jsx(OPi,{graphics:u})}),d&&U.jsx($cn,{solver:a,onStepUntilPhase:m,triggerRender:s})]})};const rwi=()=>{ee.useEffect(()=>{const t="tailwind-cdn-script";if(document.getElementById(t)||window.tailwind)return;const e=document.createElement("div");e.className="hidden",document.body.appendChild(e);const n=window.getComputedStyle(e).display==="none";if(document.body.removeChild(e),n)return;const o=document.createElement("script");o.id=t,o.src="https://cdn.tailwindcss.com",document.head.appendChild(o)},[])},swi=1e3,_E=(t,e)=>{const{fileName:n,mimeType:o="text/plain"}=e,i=t instanceof Blob?t:new Blob([t],{type:o}),r=URL.createObjectURL(i),s=document.createElement("a");s.href=r,s.download=n,s.target="_blank",s.rel="noopener noreferrer",s.style.display="none",document.body.appendChild(s),s.click(),document.body.removeChild(s),setTimeout(()=>{URL.revokeObjectURL(r)},swi)},pJe=t=>{let e=t.trim().replace(/[\\/:*?"<>|]/g,"_").replace(/[\x00-\x1f]/g,"").replace(/^\.+/,"").replace(/\.+$/,"").replace(/\s+/g," ").replace(/_+/g,"_");return/^(con|prn|aux|nul|com[0-9]|lpt[0-9])$/i.test(e)&&(e=`_${e}`),e=e.slice(0,200),e||"untitled"},awi=t=>{const e=t.solverConstructorArgs??[t.solverParams];if(t.solverName!=="AutoroutingPipelineSolver7_MultiGraph"||e.length!==1)return e;const[{input:n,options:o}]=e;return[n,o]},x7="https://github.com/tscircuit/tscircuit-autorouter/issues/new",Zcn="https://github.com/tscircuit/copper-pour-solver/issues/new",eln="https://github.com/tscircuit/calculate-packing/issues/new",Awi="https://github.com/tscircuit/matchpack/issues/new",tln="https://github.com/tscircuit/schematic-trace-solver/issues/new?template=json-bug-report.yml",cwi={PackSolver2:eln,LayoutPipelineSolver:Awi,AutoroutingPipelineSolver:x7,AssignableAutoroutingPipeline2:x7,AssignableAutoroutingPipeline3:x7,AutoroutingPipeline1_OriginalUnravel:x7,AutoroutingPipelineSolver3_HgPortPointPathing:x7,AutoroutingPipelineSolver4:x7,AutoroutingPipelineSolver5:x7,AutoroutingPipelineSolver7_MultiGraph:x7,AutoroutingPipelineSolver8:x7,CopperPourPipelineSolver:Zcn,SchematicTracePipelineSolver:tln},lwi=t=>t.toLowerCase().includes("pack")?Ern:t.toLowerCase().includes("rout")?Srn:Jxi,nln=t=>{const e=cwi[t];if(e)return e;const n=t.toLowerCase();return n.includes("autorout")?x7:n.includes("schematic")&&n.includes("trace")?tln:n.includes("copperpour")?Zcn:n.includes("pack")?eln:null},gwi=t=>`${pJe(`${t.componentName}-${t.solverName}`)}-solver-input.json`,oln=t=>{_E(JSON.stringify(t.solverParams,null,2),{fileName:gwi(t),mimeType:"application/json"})},uwi=({solverEvent:t})=>{const e=nln(t.solverName);return U.jsxs("div",{className:"rf-flex rf-items-center rf-justify-end rf-gap-2 rf-border-b rf-border-gray-200 rf-bg-gray-50 rf-px-4 rf-py-2",children:[U.jsxs(uA,{type:"button",variant:"outline",size:"sm",onClick:()=>oln(t),children:[U.jsx(Hq,{className:"rf-w-4 rf-h-4"}),"Download"]}),e?U.jsx(uA,{asChild:!0,variant:"outline",size:"sm",children:U.jsxs("a",{href:e,target:"_blank",rel:"noopener noreferrer",children:[U.jsx(dhe,{className:"rf-w-4 rf-h-4"}),"Report"]})}):U.jsxs(uA,{type:"button",variant:"outline",size:"sm",disabled:!0,title:"No report link configured for this solver",children:[U.jsx(dhe,{className:"rf-w-4 rf-h-4"}),"Report"]})]})},dwi=({solverEvent:t})=>{const e=nln(t.solverName);return e?U.jsx(uA,{asChild:!0,variant:"ghost",size:"icon",className:"rf-h-8 rf-w-8",children:U.jsx("a",{href:e,target:"_blank",rel:"noopener noreferrer",title:"Report solver bug","aria-label":"Report solver bug",children:U.jsx(dhe,{className:"rf-w-4 rf-h-4"})})}):U.jsx(uA,{type:"button",variant:"ghost",size:"icon",className:"rf-h-8 rf-w-8",disabled:!0,title:"No report link configured for this solver","aria-label":"Report solver bug",children:U.jsx(dhe,{className:"rf-w-4 rf-h-4"})})},hwi=({solverEvents:t=[]})=>{const[e,n]=ee.useState(null);rwi();const o=ee.useMemo(()=>{const a=new Map;for(const A of t){const c=`${A.componentName}-${A.solverName}`;a.set(c,A)}return a},[t]),i=ee.useMemo(()=>Array.from(o.keys()),[o]),r=e?o.get(e):null,s=ee.useMemo(()=>{if(!r)return{instance:null,error:null,classFound:!1};const a=Vve[r.solverName];if(!a)return{instance:null,error:`Solver class "${r.solverName}" not found in SOLVERS registry. Available: ${Object.keys(Vve).join(", ")}`,classFound:!1};try{return{instance:new a(...awi(r)),error:null,classFound:!0}}catch(A){const c=A instanceof Error?A.message:String(A);return console.error("Failed to reconstruct solver:",A),{instance:null,error:`Failed to instantiate solver: ${c}`,classFound:!0}}},[r]);return t.length===0?U.jsx("div",{className:"rf-p-4",children:U.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:U.jsxs("div",{className:"rf-p-4",children:[U.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),U.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."})]})})}):U.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[U.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[U.jsxs("div",{className:"rf-text-xs rf-font-semibold rf-text-gray-500 rf-px-3 rf-py-2 rf-bg-gray-50 rf-border-b rf-border-gray-200",children:[i.length," ",i.length===1?"Solver":"Solvers"]}),i.map(a=>{const A=o.get(a),c=e===a;return U.jsx("div",{className:`rf-px-3 rf-py-2 rf-cursor-pointer rf-border-b rf-border-gray-100 ${c?"rf-bg-blue-50 rf-border-l-2 rf-border-l-blue-500":"hover:rf-bg-gray-50"}`,onClick:()=>n(a),children:(()=>{const l=lwi(A.solverName);return U.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[U.jsx(l,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),U.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[U.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:A.componentName}),U.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:A.solverName})]})]})})()},a)})]}),U.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:r?s.instance?U.jsxs("div",{className:"rf-flex rf-h-full rf-flex-col rf-overflow-y-auto",children:[U.jsx(uwi,{solverEvent:r}),U.jsx("div",{className:"rf-min-h-0 rf-flex-1",children:U.jsx(rE,{fallback:U.jsx("div",{className:"rf-p-4",children:U.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[U.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),U.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",r.solverName]})]})}),children:U.jsx(iwi,{solver:s.instance})})})]}):U.jsxs("div",{className:"rf-p-4",children:[U.jsxs("div",{className:"rf-mb-4",children:[U.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:r.solverName}),U.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",r.componentName]})]}),s.error&&U.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:U.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),U.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[U.jsxs("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50 rf-flex rf-items-center rf-justify-between rf-gap-2",children:[U.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"}),U.jsxs("div",{className:"rf-flex rf-items-center rf-gap-1",children:[U.jsx(dwi,{solverEvent:r}),U.jsx(uA,{type:"button",variant:"ghost",size:"icon",className:"rf-h-8 rf-w-8","aria-label":"Download solver input JSON",title:"Download solver input JSON",onClick:()=>oln(r),children:U.jsx(Hq,{className:"rf-w-4 rf-h-4"})})]})]}),U.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:U.jsx("pre",{className:"rf-text-xs rf-font-mono rf-text-gray-600 rf-whitespace-pre-wrap rf-overflow-x-auto",children:JSON.stringify(r.solverParams,null,2)})})]})]}):U.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:U.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},mwi=["subcircuit_id","componentDisplayName","phaseName","routingPhaseIndex","phaseOrdinal","phaseCount","phaseStageIndex","phaseStageCount","connectionCount","obstacleCount","previousTraceCount","isReroutePhase","autorouterName","autorouterVersion","solverName","effort","cacheStatus"],pwi=["phaseOrdinal","routingPhaseIndex","phaseName","phaseStageIndex"];function _wi(t,e){let n=-1,o=-1;for(let i=t.length-1;i>=0;i--){const r=t[i];if(r.status!=="running"||r.subcircuit_id!==e.subcircuit_id||r.componentDisplayName!==e.componentDisplayName)continue;let s=0,a=!1;for(const A of pwi)if(!(r[A]===void 0||e[A]===void 0)){if(r[A]!==e[A]){a=!0;break}s++}!a&&s>o&&(n=i,o=s)}return n}function fwi(t,e){const n=Object.fromEntries(mwi.filter(s=>e[s]!==void 0).map(s=>[s,e[s]])),o=e.simpleRouteJson?structuredClone(e.simpleRouteJson):void 0,i=e.type==="autorouting:start"?-1:_wi(t,e),r={...i===-1?{id:`autorouting_phase_${t.length+1}`}:t[i],...n,status:e.type==="autorouting:start"?"running":e.type==="autorouting:end"?"complete":"error",...e.type==="autorouting:start"?{startSimpleRouteJson:o}:e.type==="autorouting:end"?{endSimpleRouteJson:o}:{errorSimpleRouteJson:o,error:e.error?{...e.error}:void 0}};return i===-1?[...t,r]:t.map((s,a)=>a===i?r:s)}const Iwi=new Map([["custom","Custom"],["fanout","Fanout"],["single_layer_fanout","Single layer fanout"],["tscircuit_simplify","Simplify"]]),Cwi=new Set(["tscircuit","default","auto","auto_local"]);function ywi(t){if(t==="FanoutSolver")return"Fanout";if(t==="AutoroutingPipelineSolver11_Simplification")return"Simplify";const e=t.match(/^AutoroutingPipeline(?:Solver)?(\d+)(?:_|$)/);if(e)return`Pipeline${e[1]}`;const n=t.match(/^AssignableAutoroutingPipeline(\d+)$/);return n?`Assignable${n[1]}`:t}function xwi(t){const e=t.autorouterName?.trim(),n=e?.replace(/-/g,"_"),o=n&&Iwi.get(n);if(o)return o;if(n&&!Cwi.has(n))return e;const i=t.solverName?.trim();if(i)return ywi(i);const r=t.autorouterVersion?.trim();if(r){const s=r.match(/^beta[_-]pipeline(\d+)$/);return s?`Pipeline${s[1]}`:r==="latest"?"default":r}return e?"default":"Unknown"}const _Je="#fbbf24";function Ewi(t){const e=t.endSimpleRouteJson?.traces??[],n=new Set(e.flatMap(i=>[i.pcb_trace_id,i.__replaces_pcb_trace_id].filter(r=>r!==void 0)));return[...(t.startSimpleRouteJson?.traces??[]).filter(i=>!n.has(i.pcb_trace_id)),...e]}function iln(t){const e=new Map((t.startSimpleRouteJson?.traces??[]).map(n=>[n.pcb_trace_id,n]));return(t.endSimpleRouteJson?.traces??[]).filter(n=>{const o=e.get(n.pcb_trace_id);return!o||!!n.__replaces_pcb_trace_id&&n.__replaces_pcb_trace_id!==o.__replaces_pcb_trace_id||JSON.stringify(o.route)!==JSON.stringify(n.route)}).map(n=>n.pcb_trace_id)}function Bwi(t,e){return{outer_diameter:t.via_diameter??e.minViaPadDiameter??e.min_via_pad_diameter??e.minViaDiameter??.6,hole_diameter:t.via_hole_diameter??e.minViaHoleDiameter??e.min_via_hole_diameter??.3}}function rln(t,e){const n=[];for(const a of t.route)a.route_type==="wire"?n.push({...a,layer:a.layer}):a.route_type==="via"?n.push({route_type:"via",x:a.x,y:a.y,from_layer:a.from_layer,to_layer:a.to_layer,...Bwi(a,e)}):a.route_type==="through_obstacle"&&n.push({route_type:"through_pad",start:{...a.start},end:{...a.end},width:a.width,start_layer:a.from_layer,end_layer:a.to_layer,pcb_smtpad_id:a.circuitJsonMetadata?.pcb_smtpad_id,pcb_plated_hole_id:a.circuitJsonMetadata?.pcb_plated_hole_id});const o=a=>{let A=-1,c=Number.POSITIVE_INFINITY;return n.forEach((l,g)=>{if(l.route_type!=="wire")return;const u=Math.hypot(l.x-a.x,l.y-a.y);u<c&&(c=u,A=g)}),A},i=t.route.filter(a=>a.route_type==="jumper").map(a=>[o(a.start),o(a.end)].sort((A,c)=>A-c)).filter(([a,A])=>a>=0&&A>a).sort(([a],[A])=>a-A),r=[];let s=0;for(const[a,A]of i)a>=s&&r.push(n.slice(s,a+1)),s=Math.max(s,A);return s<n.length&&r.push(n.slice(s)),r}function Swi(t){const e=[],n=[],o=t.endSimpleRouteJson;if(!o)return{lines:e,circles:n};const i=new Set(iln(t));for(const r of o.traces??[])if(i.has(r.pcb_trace_id))for(const s of rln(r,o)){let a;for(const A of s){if(A.route_type==="through_pad"){a={...A.end,layer:A.end_layer,width:A.width};continue}const c=A.route_type==="wire"?A.layer:A.from_layer;a&&a.layer===c&&(a.x!==A.x||a.y!==A.y)&&e.push({points:[{x:a.x,y:a.y},{x:A.x,y:A.y}],strokeWidth:A.route_type==="wire"?A.width:a.width,strokeColor:_Je,layer:c}),A.route_type==="via"&&n.push({center:{x:A.x,y:A.y},radius:A.outer_diameter/2,stroke:_Je,fill:"transparent"}),a={x:A.x,y:A.y,layer:A.route_type==="wire"?A.layer:A.to_layer,width:A.route_type==="wire"?A.width:a?.width??o.minTraceWidth}}}return{coordinateSystem:"cartesian",lines:e,circles:n}}function bwi(t){const e=JSON.stringify(t);let n=2166136261;for(let o=0;o<e.length;o++)n=Math.imul(n^e.charCodeAt(o),16777619);return(n>>>0).toString(36)}const Qwi=new Set(["pcb_trace","pcb_via","pcb_copper_pour","pcb_ground_plane","pcb_ground_plane_region","pcb_thermal_spoke","pcb_breakout_point"]);function vwi(t,e,n){const o=n==="input"?e.startSimpleRouteJson??e.errorSimpleRouteJson:e.endSimpleRouteJson,i=t.filter(c=>!Qwi.has(c.type)&&!c.type.endsWith("_error")&&!c.type.endsWith("_warning"));if(!o)return i;const r=n==="input"?o.traces??[]:Ewi(e),s=new Set(t.filter(c=>c.type==="source_trace").map(c=>c.source_trace_id)),a=["top",...Array.from({length:Math.max(0,o.layerCount-2)},(c,l)=>`inner${l+1}`),...o.layerCount>1?["bottom"]:[]],A=[];for(const c of r){const g=o.connections.find(h=>h.name===c.connection_name||h.source_trace_id===c.connection_name)?.source_trace_id??c.connection_name??"",u=rln(c,o);for(const[h,d]of u.entries()){const m={type:"pcb_trace",pcb_trace_id:`${e.id}_${n}_${c.pcb_trace_id}_${h}_${bwi(d)}`,subcircuit_id:e.subcircuit_id??void 0,source_trace_id:s.has(g)?g:void 0,route:d};A.push(m);for(const[p,_]of d.entries()){if(_.route_type!=="via")continue;const f=a.indexOf(_.from_layer),I=a.indexOf(_.to_layer),C={type:"pcb_via",pcb_via_id:`${m.pcb_trace_id}_via_${p}`,pcb_trace_id:m.pcb_trace_id,subcircuit_id:e.subcircuit_id??void 0,x:_.x,y:_.y,outer_diameter:_.outer_diameter,hole_diameter:_.hole_diameter,layers:f>=0&&I>=0?a.slice(Math.min(f,I),Math.max(f,I)+1):[_.from_layer,_.to_layer]};A.push(C)}}}return[...i,...A]}const fJe=(t,e)=>t.phaseName||`Phase ${t.phaseOrdinal??e+1}`,sln=t=>t.componentDisplayName?.match(/name="([^"]+)"/)?.[1]?.replace(/^\./,"")||t.componentDisplayName||t.subcircuit_id||"Board",aln=t=>t.startSimpleRouteJson??t.endSimpleRouteJson??t.errorSimpleRouteJson,Pwi={is_showing_autorouting:!0,is_showing_rats_nest:!1,is_showing_drc_errors:!1,is_showing_drc_warnings:!1,is_showing_pcb_groups:!1},wwi=({circuitJson:t,phases:e=[],isRunning:n=!1})=>{const[o,i]=ee.useState(null),[r,s]=ee.useState("output"),[a,A]=ee.useState(!0),[c,l]=ee.useState(!1),g=ee.useRef(null),[u,h]=ee.useState(480),d=o?e.findIndex(R=>R.id===o.id&&aln(R)===aln(o)):-1,m=d<0?e.length-1:d,p=e[m],_=d<0,f=!!p?.endSimpleRouteJson,I=p?.startSimpleRouteJson??p?.errorSimpleRouteJson,C=!!I,y=r==="output"&&!f?"input":r==="input"&&!C?"output":r,x=y==="input"?I:p?.endSimpleRouteJson,E=ee.useMemo(()=>!p||!x?null:vwi(t??[],p,y),[t,p,x,y]),B=ee.useMemo(()=>p&&y==="output"&&a?Swi(p):{lines:[],circles:[]},[p,y,a]);if(ee.useLayoutEffect(()=>{const R=g.current;if(!R)return;const H=()=>h(Math.max(360,R.clientHeight));H();const G=new ResizeObserver(H);return G.observe(R),()=>G.disconnect()},[!!p]),!p)return U.jsxs("div",{className:"rf-flex rf-min-h-[400px] rf-flex-col rf-items-center rf-justify-center rf-gap-3 rf-p-8 rf-text-center",children:[U.jsx(Srn,{className:"rf-h-7 rf-w-7 rf-text-blue-500"}),U.jsx("h3",{className:"rf-text-base rf-font-medium",children:n?"Waiting for autorouting":"No autorouting captures"}),U.jsx("p",{className:"rf-max-w-md rf-text-sm rf-text-gray-500",children:n?"Phases appear as the circuit routes. Each capture includes its input and output on the PCB.":"Run a circuit with autorouting enabled to inspect its phases. A circuit JSON file alone does not include routing history."})]});const b=fJe(p,m),Q=p.status==="running"&&n,w=!f,D=I?.connections.length,k=E?.filter(R=>R.type==="pcb_trace").length??0;return U.jsxs("div",{className:"rf-flex rf-h-full rf-min-h-[620px] rf-flex-col rf-bg-white md:rf-flex-row","data-testid":"autorouting-explorer",children:[U.jsxs("aside",{className:"rf-flex rf-shrink-0 rf-flex-col rf-border-b rf-border-gray-200 md:rf-w-52 md:rf-border-b-0 md:rf-border-r","aria-label":"Routing phases",children:[U.jsxs("div",{className:"rf-flex rf-items-center rf-justify-between rf-px-3 rf-py-2 rf-text-xs rf-text-gray-500",children:[U.jsx("span",{children:"Routing phases"}),U.jsx("span",{children:e.length})]}),U.jsx("div",{className:"rf-flex rf-gap-1 rf-overflow-x-auto rf-px-1.5 rf-pb-1.5 md:rf-flex-col md:rf-overflow-x-hidden md:rf-overflow-y-auto",children:e.map((R,H)=>{const G=iln(R).length,K=R.endSimpleRouteJson?`${G} ${G===1?"trace":"traces"} routed`:R.status==="error"?"Failed":R.status==="running"&&n?"Routing…":"No output";return U.jsxs("button",{type:"button","aria-pressed":H===m,title:`${sln(R)} · ${K}`,onClick:()=>i(R),className:ki("rf-flex rf-min-w-[192px] rf-items-start rf-gap-2 rf-rounded-md rf-border rf-px-2 rf-py-2 rf-text-left md:rf-min-w-0",H===m?"rf-border-blue-200 rf-bg-blue-50":"rf-border-transparent hover:rf-bg-gray-50"),children:[U.jsx("span",{className:ki("rf-flex rf-h-5 rf-w-5 rf-shrink-0 rf-items-center rf-justify-center rf-rounded-full rf-text-[11px]",H===m?"rf-bg-blue-600 rf-text-white":"rf-bg-gray-100 rf-text-gray-500"),children:H+1}),U.jsxs("span",{className:"rf-min-w-0 rf-flex-1",children:[U.jsxs("span",{className:"rf-flex rf-items-center rf-gap-1",children:[U.jsx("span",{className:"rf-min-w-0 rf-flex-1 rf-truncate rf-text-xs rf-font-medium rf-leading-5 rf-text-gray-800",title:fJe(R,H),children:fJe(R,H)}),R.status==="complete"?U.jsx(KS,{"aria-label":"Captured",className:"rf-h-3 rf-w-3 rf-shrink-0 rf-text-green-600"}):R.status==="error"?U.jsx(pVe,{"aria-label":"Failed",className:"rf-h-3 rf-w-3 rf-shrink-0 rf-text-red-500"}):n?U.jsx(sE,{"aria-label":"Routing",className:"rf-h-3 rf-w-3 rf-shrink-0 rf-animate-spin rf-text-blue-500"}):null]}),U.jsxs("span",{className:"rf-block rf-text-[11px] rf-leading-4 rf-text-gray-500",children:[xwi(R)," · ",K]})]})]},R.id)})})]}),U.jsxs("div",{className:"rf-flex rf-min-w-0 rf-flex-1 rf-flex-col",children:[U.jsxs("div",{className:"rf-flex rf-flex-wrap rf-items-center rf-gap-3 rf-border-b rf-border-gray-200 rf-px-4 rf-py-3",children:[U.jsxs("h3",{className:"rf-mr-auto rf-flex rf-items-center rf-gap-2 rf-text-sm rf-font-medium",children:[b,U.jsxs("span",{className:"rf-text-xs rf-font-normal rf-text-gray-500",children:[m+1," of ",e.length]})]}),n&&U.jsx("button",{type:"button",onClick:()=>i(null),disabled:_,className:"rf-text-xs rf-text-blue-600 disabled:rf-text-gray-500",children:_?"Following latest":"Follow latest"}),U.jsx("div",{className:"rf-flex rf-rounded-md rf-bg-gray-100 rf-p-1","aria-label":"Phase snapshot",children:["input","output"].map(R=>U.jsx("button",{type:"button","aria-pressed":y===R,disabled:R==="input"?!C:!f,onClick:()=>s(R),className:ki("rf-rounded rf-px-3 rf-py-1 rf-text-xs disabled:rf-opacity-40",y===R?"rf-bg-white rf-text-gray-900 rf-shadow-sm":"rf-text-gray-500"),children:R==="input"?"Input":"Output"},R))})]}),U.jsxs("div",{className:"rf-flex rf-flex-wrap rf-items-center rf-justify-between rf-gap-2 rf-px-4 rf-py-2 rf-text-xs rf-text-gray-600",children:[U.jsxs("label",{className:"rf-flex rf-items-center rf-gap-2",children:[U.jsx("input",{type:"checkbox",checked:a,disabled:y!=="output",onChange:R=>A(R.target.checked),className:"rf-accent-blue-600"}),U.jsx("span",{"aria-hidden":"true",className:"rf-inline-block rf-h-0.5 rf-w-3",style:{backgroundColor:_Je}}),"Highlight changes (all layers)"]}),U.jsxs("span",{children:[y==="input"?"Before this phase":"After this phase"," ","· ",k," traces"]})]}),w&&U.jsx("div",{className:ki("rf-border-y rf-px-4 rf-py-2 rf-text-xs",p.status==="error"?"rf-border-red-100 rf-bg-red-50 rf-text-red-700":"rf-border-blue-100 rf-bg-blue-50 rf-text-blue-700"),role:"status",children:p.status==="error"?`Routing failed: ${p.error?.message||"No output was captured."}`:Q?"Routing in progress. Showing captured input until output is available.":"No output was captured for this phase. Showing the available input."}),U.jsx("div",{ref:g,className:"rf-relative rf-min-h-[360px] rf-flex-1","data-testid":"autorouting-pcb",children:E?U.jsx(cJe,{circuitJson:E,height:u,allowEditing:!1,clickToInteractEnabled:!1,initialState:Pwi,debugGraphics:B}):U.jsx("div",{className:"rf-p-6 rf-text-sm rf-text-gray-500",children:"No PCB snapshot available for this capture."})}),U.jsxs("div",{className:"rf-flex rf-flex-wrap rf-items-center rf-justify-between rf-gap-2 rf-border-t rf-border-gray-200 rf-px-4 rf-py-3 rf-text-xs rf-text-gray-500",children:[U.jsxs("span",{children:[D===void 0?"Input unavailable":`${D} input connections`,` · ${sln(p)}`]}),U.jsxs("div",{className:"rf-flex rf-items-center rf-gap-4",children:[U.jsxs("button",{type:"button",disabled:!x,onClick:()=>_E(JSON.stringify(x,null,2),{fileName:`${p.id}-${y}.srj.json`,mimeType:"application/json"}),className:"rf-flex rf-items-center rf-gap-1 disabled:rf-opacity-40",children:[U.jsx(Hq,{className:"rf-h-3 rf-w-3"}),"Download SRJ"]}),U.jsxs("button",{type:"button","aria-expanded":c,onClick:()=>l(!c),className:"rf-flex rf-items-center rf-gap-1",children:[U.jsx(NR,{className:ki("rf-h-3 rf-w-3",c&&"rf-rotate-90")}),"Inspect SRJ"]})]})]}),c&&U.jsx("pre",{className:"rf-m-0 rf-max-h-64 rf-overflow-auto rf-border-t rf-border-gray-200 rf-bg-gray-50 rf-p-4 rf-text-xs","aria-label":`${b} ${y} SRJ`,children:x?JSON.stringify(x,null,2):"No snapshot captured."})]})]})},Aln=({errorMessage:t,errorStack:e,circuitJsonErrors:n})=>{ee.useEffect(()=>{if(t){const o=new Error(t);e&&(o.stack=e);try{lO.captureException(o)}catch{}}},[t,e]),ee.useEffect(()=>{if(n&&n.length>0)for(const o of n){const i=new Error(o.message||"Circuit JSON Error");o.stack&&(i.stack=o.stack);try{lO.captureException(i,{error_type:o.type})}catch{}}},[n])},cln=t=>{ee.useEffect(()=>{try{KTo(t)}catch{}},[t.source,t.component,t.isWebEmbedded,t.activeTab])},lln="0.0.2779",Mwi={version:lln},Lme=iRt()(rRt(t=>({lastRunEvalVersion:void 0,setLastRunEvalVersion:e=>{t({lastRunEvalVersion:e})}}),{name:"runframe-runner-store"})),Dwi=t=>{const[e,n]=ee.useState([]),[o,i]=ee.useState(null),[r,s]=ee.useState(""),[a,A]=OH("eval-version-selection",null),c=Lme(h=>h.setLastRunEvalVersion),l=Lme(h=>h.lastRunEvalVersion);return ee.useEffect(()=>{t&&fetch("https://data.jsdelivr.com/v1/package/npm/@tscircuit/eval").then(h=>h.json()).then(h=>{if(Array.isArray(h?.versions)){let d=[...h.versions];h.tags?.latest&&(i(h.tags.latest),d=d.filter(m=>m!==h.tags.latest)),n(d)}}).catch(()=>{})},[t]),ee.useEffect(()=>{t&&(a?(window.TSCIRCUIT_LATEST_EVAL_VERSION=a,c(a)):o&&(window.TSCIRCUIT_LATEST_EVAL_VERSION=o,c(o)))},[t,a,o]),{versions:ee.useMemo(()=>e.filter(h=>h.includes(r)).slice(0,50),[e,r]),latestVersion:o,lastRunEvalVersion:l,search:r,setSearch:s,selectVersion:h=>{A(h),s("")}}},Nwi=({snippetNames:t,onSelect:e,onCancel:n,isOpen:o})=>{const[i,r]=ee.useState(""),[s,a]=ee.useState("");if(!o)return null;const A=t.filter(g=>g.toLowerCase().includes(s.toLowerCase())),c=s&&!t.includes(s),l=g=>{g.key==="Enter"&&(A.length===1?r(A[0]):c&&r(s))};return U.jsx("div",{className:"rf-fixed rf-inset-0 rf-bg-black rf-bg-opacity-50 rf-flex rf-items-center rf-justify-center rf-z-[100]",children:U.jsxs("div",{className:"rf-bg-white rf-rounded-lg rf-p-6 rf-w-96",children:[U.jsx("h2",{className:"rf-text-lg rf-font-semibold rf-mb-4",children:"Select Snippet"}),U.jsx("input",{type:"text",className:"rf-w-full rf-px-4 rf-py-2 rf-border rf-rounded rf-mb-4",placeholder:"Search snippets or new snippet name...",value:s,onChange:g=>a(g.target.value),onKeyDown:l}),U.jsxs("div",{className:"rf-h-60 rf-overflow-y-auto",children:[A.map(g=>U.jsx("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 ${i===g?"bg-blue-50":""}`,onClick:()=>r(g),children:g},g)),c&&U.jsxs("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 text-blue-500 ${i===s?"bg-blue-50":""}`,onClick:()=>r(s),children:['Create new "',s,'"']})]}),U.jsxs("div",{className:"rf-mt-4 rf-flex rf-justify-end rf-gap-2",children:[U.jsx("button",{type:"button",className:"rf-px-4 rf-py-2 rf-text-gray-600 rf-hover:text-gray-800",onClick:n,children:"Cancel"}),U.jsx("button",{type:"button",className:"rf-px-4 rf-py-2 rf-bg-blue-500 rf-text-white rf-rounded rf-hover:bg-blue-600 rf-disabled:opacity-50",onClick:()=>i&&e(i),disabled:!i,children:i===s?`Create "${i}"`:`Save to ${i}`})]})]})})},Rwi=t=>{const e=ee.useRef(null),n=id(o=>o.recentEvents);ee.useEffect(()=>{if(n.length===0)return;const o=n[0];o.event_id!==e.current&&(t(o),e.current=o.event_id)},[n,t])};var Twi=Object.defineProperty,ZS=(t,e)=>Twi(t,"name",{value:e,configurable:!0}),kwi="AlertDialog",[Fwi,Csr]=lx(kwi,[Xsn]),eb=Xsn(),Lwi=ZS(t=>{const{__scopeAlertDialog:e,...n}=t,o=eb(e);return U.jsx(Whe,{...o,...n,modal:!0})},"AlertDialog");ee.forwardRef(ZS(function(e,n){const{__scopeAlertDialog:o,...i}=e,r=eb(o);return U.jsx(J4i,{...r,...i,ref:n})},"AlertDialogTrigger"));var Hwi=ZS(t=>{const{__scopeAlertDialog:e,...n}=t,o=eb(e);return U.jsx(jhe,{...o,...n})},"AlertDialogPortal"),Owi=ee.forwardRef(ZS(function(e,n){const{__scopeAlertDialog:o,...i}=e,r=eb(o);return U.jsx(Zq,{...r,...i,ref:n})},"AlertDialogOverlay")),Gwi="AlertDialogContent",[Ywi,Uwi]=Fwi(Gwi),Kwi=ee.forwardRef(ZS(function(e,n){const{__scopeAlertDialog:o,children:i,...r}=e,s=eb(o),a=ee.useRef(null),A=KA(n,a),c=ee.useRef(null);return U.jsx(Ywi,{scope:o,cancelRef:c,children:U.jsx(t$,{role:"alertdialog",...s,...r,ref:A,onOpenAutoFocus:sr(r.onOpenAutoFocus,l=>{l.preventDefault(),c.current?.focus({preventScroll:!0})}),onPointerDownOutside:l=>l.preventDefault(),onInteractOutside:l=>l.preventDefault(),children:i})})},"AlertDialogContent")),Vwi=ee.forwardRef(ZS(function(e,n){const{__scopeAlertDialog:o,...i}=e,r=eb(o);return U.jsx(Xhe,{...r,...i,ref:n})},"AlertDialogTitle")),zwi=ee.forwardRef(ZS(function(e,n){const{__scopeAlertDialog:o,...i}=e,r=eb(o);return U.jsx(qhe,{...r,...i,ref:n})},"AlertDialogDescription")),Jwi=ee.forwardRef(ZS(function(e,n){const{__scopeAlertDialog:o,...i}=e,r=eb(o);return U.jsx(nze,{...r,...i,ref:n})},"AlertDialogAction")),Wwi="AlertDialogCancel",jwi=ee.forwardRef(ZS(function(e,n){const{__scopeAlertDialog:o,...i}=e,{cancelRef:r}=Uwi(Wwi,o),s=eb(o),a=KA(n,r);return U.jsx(nze,{...s,...i,ref:a})},"AlertDialogCancel")),Xwi=Lwi,qwi=Hwi,gln=Owi,uln=Kwi,dln=Jwi,hln=jwi,mln=Vwi,pln=zwi;const _ln=Xwi,$wi=qwi,fln=ee.forwardRef(({className:t,...e},n)=>U.jsx(gln,{className:ki("rf-fixed rf-inset-0 rf-z-50 rf-bg-black/80 data-[state=open]:rf-animate-in data-[state=closed]:rf-animate-out data-[state=closed]:rf-fade-out-0 data-[state=open]:rf-fade-in-0",t),...e,ref:n}));fln.displayName=gln.displayName;const IJe=ee.forwardRef(({className:t,...e},n)=>U.jsxs($wi,{children:[U.jsx(fln,{}),U.jsx(uln,{ref:n,className:ki("rf-fixed rf-left-[50%] rf-top-[50%] rf-z-50 rf-grid rf-w-full rf-max-w-lg rf-translate-x-[-50%] rf-translate-y-[-50%] rf-gap-4 rf-border rf-border-zinc-200 rf-bg-white rf-p-6 rf-shadow-lg rf-duration-200 data-[state=open]:rf-animate-in data-[state=closed]:rf-animate-out data-[state=closed]:rf-fade-out-0 data-[state=open]:rf-fade-in-0 data-[state=closed]:rf-zoom-out-95 data-[state=open]:rf-zoom-in-95 data-[state=closed]:rf-slide-out-to-left-1/2 data-[state=closed]:rf-slide-out-to-top-[48%] data-[state=open]:rf-slide-in-from-left-1/2 data-[state=open]:rf-slide-in-from-top-[48%] sm:rf-rounded-lg dark:rf-border-zinc-800 dark:rf-bg-zinc-950",t),...e})]}));IJe.displayName=uln.displayName;const CJe=({className:t,...e})=>U.jsx("div",{className:ki("rf-flex rf-flex-col rf-space-y-2 rf-text-center sm:rf-text-left",t),...e});CJe.displayName="AlertDialogHeader";const yJe=({className:t,...e})=>U.jsx("div",{className:ki("rf-flex rf-flex-col-reverse sm:rf-flex-row sm:rf-justify-end sm:rf-space-x-2",t),...e});yJe.displayName="AlertDialogFooter";const xJe=ee.forwardRef(({className:t,...e},n)=>U.jsx(mln,{ref:n,className:ki("rf-text-lg rf-font-semibold",t),...e}));xJe.displayName=mln.displayName;const EJe=ee.forwardRef(({className:t,...e},n)=>U.jsx(pln,{ref:n,className:ki("rf-text-sm rf-text-zinc-500 dark:rf-text-zinc-400",t),...e}));EJe.displayName=pln.displayName;const Zwi=ee.forwardRef(({className:t,...e},n)=>U.jsx(dln,{ref:n,className:ki(sY(),t),...e}));Zwi.displayName=dln.displayName;const BJe=ee.forwardRef(({className:t,...e},n)=>U.jsx(hln,{ref:n,className:ki(sY({variant:"outline"}),"rf-mt-2 sm:rf-mt-0",t),...e}));BJe.displayName=hln.displayName;var eMi=Object.defineProperty,tb=(t,e)=>eMi(t,"name",{value:e,configurable:!0}),SJe="Checkbox",[tMi,ysr]=lx(SJe),[nMi,bJe]=tMi(SJe);function Iln(t){const{__scopeCheckbox:e,checked:n,children:o,defaultChecked:i,disabled:r,form:s,name:a,onCheckedChange:A,required:c,value:l="on",internal_do_not_use_render:g}=t,[u,h]=dB({prop:n,defaultProp:i??!1,onChange:A,caller:SJe}),[d,m]=ee.useState(null),[p,_]=ee.useState(null),f=ee.useRef(!1),[I,C]=ee.useReducer(E=>E+1,0),y=d?!!s||!!d.closest("form"):!0,x={checked:u,disabled:r,setChecked:h,control:d,setControl:m,name:a,form:s,value:l,hasConsumerStoppedPropagationRef:f,userInteractionCount:I,onUserInteraction:C,required:c,defaultChecked:nb(i)?!1:i,isFormControl:y,bubbleInput:p,setBubbleInput:_};return U.jsx(nMi,{scope:e,...x,children:yln(g)?g(x):o})}tb(Iln,"CheckboxProvider");var oMi="CheckboxTrigger",iMi=ee.forwardRef(tb(function({__scopeCheckbox:e,onKeyDown:n,onClick:o,...i},r){const{control:s,value:a,disabled:A,checked:c,required:l,setControl:g,setChecked:u,hasConsumerStoppedPropagationRef:h,onUserInteraction:d,isFormControl:m,bubbleInput:p}=bJe(oMi,e),_=KA(r,g),f=ee.useRef(c);return ee.useEffect(()=>{const I=s?.form;if(I){const C=tb(()=>u(f.current),"reset");return I.addEventListener("reset",C),()=>I.removeEventListener("reset",C)}},[s,u]),U.jsx(Qa.button,{type:"button",role:"checkbox","aria-checked":nb(c)?"mixed":c,"aria-required":l,"data-state":QJe(c),"data-disabled":A?"":void 0,disabled:A,value:a,...i,ref:_,onKeyDown:sr(n,I=>{I.key==="Enter"&&I.preventDefault()}),onClick:sr(o,I=>{d(),u(C=>nb(C)?!0:!C),p&&m&&(h.current=I.isPropagationStopped(),h.current||I.stopPropagation())})})},"CheckboxTrigger")),Cln=ee.forwardRef(tb(function(e,n){const{__scopeCheckbox:o,name:i,checked:r,defaultChecked:s,required:a,disabled:A,value:c,onCheckedChange:l,form:g,...u}=e;return U.jsx(Iln,{__scopeCheckbox:o,checked:r,defaultChecked:s,disabled:A,required:a,onCheckedChange:l,name:i,form:g,value:c,internal_do_not_use_render:({isFormControl:h})=>U.jsxs(U.Fragment,{children:[U.jsx(iMi,{...u,ref:n,__scopeCheckbox:o}),h&&U.jsx(AMi,{__scopeCheckbox:o})]})})},"Checkbox")),rMi="CheckboxIndicator",sMi=ee.forwardRef(tb(function(e,n){const{__scopeCheckbox:o,forceMount:i,...r}=e,s=bJe(rMi,o);return U.jsx(z3,{present:i||nb(s.checked)||s.checked===!0,children:U.jsx(Qa.span,{"data-state":QJe(s.checked),"data-disabled":s.disabled?"":void 0,...r,ref:n,style:{pointerEvents:"none",...e.style}})})},"CheckboxIndicator")),aMi="CheckboxBubbleInput",AMi=ee.forwardRef(tb(function({__scopeCheckbox:e,onClick:n,...o},i){const{control:r,hasConsumerStoppedPropagationRef:s,userInteractionCount:a,checked:A,defaultChecked:c,required:l,disabled:g,name:u,value:h,form:d,bubbleInput:m,setBubbleInput:p}=bJe(aMi,e),_=KA(i,p),f=HVe(r),I=ee.useRef(!1),C=ee.useRef(A),y=ee.useRef(a);ee.useEffect(()=>{const E=m;if(!E)return;const B=window.HTMLInputElement.prototype,Q=Object.getOwnPropertyDescriptor(B,"checked").set,w=a!==y.current;y.current=a;const D=C.current!==A;C.current=A;const k=!(w&&s.current);if(D&&Q){I.current=!w;const R=new Event("click",{bubbles:k});E.indeterminate=nb(A),Q.call(E,nb(A)?!1:A),E.dispatchEvent(R),I.current=!1}},[m,A,s,a]);const x=ee.useRef(nb(A)?!1:A);return U.jsx(Qa.input,{type:"checkbox","aria-hidden":!0,defaultChecked:c??x.current,required:l,disabled:g,name:u,value:h,form:d,...o,tabIndex:-1,ref:_,onClick:sr(n,E=>{I.current&&E.stopPropagation()}),style:{...o.style,...f,position:"absolute",pointerEvents:"none",opacity:0,margin:0,transform:"translateX(-100%)"}})},"CheckboxBubbleInput"));function yln(t){return typeof t=="function"}tb(yln,"isFunction");function nb(t){return t==="indeterminate"}tb(nb,"isIndeterminate");function QJe(t){return nb(t)?"indeterminate":t?"checked":"unchecked"}tb(QJe,"getState");const b$=ee.forwardRef(({className:t,...e},n)=>U.jsx(Cln,{ref:n,className:ki("rf-peer rf-h-4 rf-w-4 rf-shrink-0 rf-rounded-sm rf-border rf-border-zinc-200 rf-border-zinc-900 rf-shadow focus-visible:rf-outline-none focus-visible:rf-ring-1 focus-visible:rf-ring-zinc-950 disabled:rf-cursor-not-allowed disabled:rf-opacity-50 data-[state=checked]:rf-bg-zinc-900 data-[state=checked]:rf-text-zinc-50 dark:rf-border-zinc-800 dark:rf-border-zinc-50 dark:focus-visible:rf-ring-zinc-300 dark:data-[state=checked]:rf-bg-zinc-50 dark:data-[state=checked]:rf-text-zinc-900",t),...e,children:U.jsx(sMi,{className:ki("rf-flex rf-items-center rf-justify-center rf-text-current"),children:U.jsx(KS,{className:"rf-h-4 rf-w-4"})})}));b$.displayName=Cln.displayName;const YR=Whe,cMi=jhe,xln=ee.forwardRef(({className:t,...e},n)=>U.jsx(Zq,{className:ki("rf-fixed rf-inset-0 rf-z-50 rf-bg-black/80 data-[state=open]:rf-animate-in data-[state=closed]:rf-animate-out data-[state=closed]:rf-fade-out-0 data-[state=open]:rf-fade-in-0",t),...e,ref:n}));xln.displayName=Zq.displayName;const tw=ee.forwardRef(({className:t,children:e,showOverlay:n=!0,...o},i)=>U.jsxs(cMi,{children:[U.jsx(xln,{className:ki(n?"":"rf-hidden")}),U.jsx(t$,{ref:i,className:ki("rf-fixed rf-left-[50%] rf-top-[50%] rf-z-50 rf-grid rf-w-full rf-max-w-lg rf-translate-x-[-50%] rf-translate-y-[-50%] rf-gap-4 rf-border rf-border-zinc-200 rf-bg-white rf-p-6 rf-shadow-lg rf-duration-200 data-[state=open]:rf-animate-in data-[state=closed]:rf-animate-out data-[state=closed]:rf-fade-out-0 data-[state=open]:rf-fade-in-0 data-[state=closed]:rf-zoom-out-95 data-[state=open]:rf-zoom-in-95 data-[state=closed]:rf-slide-out-to-left-1/2 data-[state=closed]:rf-slide-out-to-top-[48%] data-[state=open]:rf-slide-in-from-left-1/2 data-[state=open]:rf-slide-in-from-top-[48%] sm:rf-rounded-lg dark:rf-border-zinc-800 dark:rf-bg-zinc-950",t),...o,children:e})]}));tw.displayName=t$.displayName;const nw=({className:t,...e})=>U.jsx("div",{className:ki("rf-flex rf-flex-col rf-space-y-2 rf-text-center sm:rf-text-left",t),...e});nw.displayName="DialogHeader";const MY=({className:t,...e})=>U.jsx("div",{className:ki("rf-flex rf-flex-col-reverse sm:rf-flex-row sm:rf-justify-end sm:rf-space-x-2",t),...e});MY.displayName="DialogFooter";const ow=ee.forwardRef(({className:t,...e},n)=>U.jsx(Xhe,{ref:n,className:ki("rf-text-lg rf-font-semibold",t),...e}));ow.displayName=Xhe.displayName;const UR=ee.forwardRef(({className:t,...e},n)=>U.jsx(qhe,{ref:n,className:ki("rf-text-sm rf-text-zinc-500 dark:rf-text-zinc-400",t),...e}));UR.displayName=qhe.displayName;const Hme={"tscircuit.com":{label:"tscircuit.com",placeholder:"Search tscircuit packages...",emptyMessage:"No packages found"},jlcpcb:{label:"JLCPCB Parts",placeholder:"Search JLCPCB parts (e.g. C14663)...",emptyMessage:"No parts found"},kicad:{label:"KiCad Footprints",placeholder:"Search KiCad footprints...",emptyMessage:"No footprints found"}},lMi="https://cdn.jsdelivr.net/npm/easyeda@latest/dist/browser/index.js";let vJe=null;const PJe=async()=>(vJe||(vJe=import(lMi)),vJe),gMi=t=>(e,n)=>{const o=new Headers(n?.headers),i={};return o.forEach((r,s)=>{i[s]=r}),fetch(`${t?.apiBase??sC}/proxy`,{...n,headers:{...i,"X-Target-Url":e.toString(),"X-Sender-Origin":i.origin??"","X-Sender-Host":i.host??"https://easyeda.com","X-Sender-Referer":i.referer??"","X-Sender-User-Agent":i["user-agent"]??"","X-Sender-Cookie":i.cookie??"",authority:i.authority??"","content-type":i["content-type"]??"",...t?.headers}})},uMi=async(t,e=10)=>{const n=encodeURIComponent(t),o=await fetch(`https://jlcsearch.tscircuit.com/api/search?limit=${e}&q=${n}`);if(!o.ok)throw new Error(`JLCPCB API error: ${o.status}`);return(await o.json()).components??[]},dMi=t=>({lcscId:t.lcsc,manufacturer:t.mfr,description:t.description,partNumber:`C${t.lcsc}`,package:t.package,price:t.price,stock:t.stock,isBasic:t.is_basic}),Eln=async(t,e)=>{const{fetchEasyEDAComponent:n}=await PJe();return n(t,{fetch:gMi(e),includeModelMetadata:e?.includeModelMetadata})},hMi=async(t,e)=>{const{convertRawEasyToTsx:n}=await PJe(),o=await Eln(t,e);return n({rawEasy:o})},mMi=async(t,e)=>{const{EasyEdaJsonSchema:n,convertEasyEdaJsonToCircuitJson:o}=await PJe(),i=await Eln(t,{...e,includeModelMetadata:!1}),r=n.parse(i);return o(r,{shouldRecenter:!0,showDesignator:!0,useModelCdn:!1})};function iw(t){return Array.isArray?Array.isArray(t):Sln(t)==="[object Array]"}function pMi(t){if(typeof t=="string")return t;if(typeof t=="bigint")return t.toString();const e=t+"";return e=="0"&&1/t==-1/0?"-0":e}function wJe(t){return t==null?"":pMi(t)}function hC(t){return typeof t=="string"}function Ome(t){return typeof t=="number"}function _Mi(t){return t===!0||t===!1||fMi(t)&&Sln(t)=="[object Boolean]"}function Bln(t){return typeof t=="object"}function fMi(t){return Bln(t)&&t!==null}function fE(t){return t!=null}function Gme(t){return!t.trim().length}function Sln(t){return t==null?t===void 0?"[object Undefined]":"[object Null]":Object.prototype.toString.call(t)}const IMi="Incorrect 'index' type",MJe="Invalid doc index: must be a non-negative integer within the bounds of the docs array",CMi=t=>`Invalid value for key ${t}`,yMi=t=>`Pattern length exceeds max of ${t}.`,xMi=t=>`Missing ${t} property in key`,EMi=t=>`Property 'weight' in key '${t}' must be a positive integer`,BMi="Fuse.match does not support useTokenSearch: token search requires corpus-level statistics (df, fieldCount) that a one-off string comparison does not have. Use new Fuse(...).search(...) instead.",bln=Object.prototype.hasOwnProperty;var SMi=class{constructor(t){this._keys=[],this._keyMap={};let e=0;t.forEach(n=>{const o=Qln(n);this._keys.push(o),this._keyMap[o.id]=o,e+=o.weight}),this._keys.forEach(n=>{n.weight/=e})}get(t){return this._keyMap[t]}keys(){return this._keys}toJSON(){return JSON.stringify(this._keys)}};function Qln(t){let e=null,n=null,o=null,i=1,r=null;if(hC(t)||iw(t))o=t,e=vln(t),n=Yme(t);else{if(!bln.call(t,"name"))throw new Error(xMi("name"));const s=t.name;if(o=s,bln.call(t,"weight")&&t.weight!==void 0&&(i=t.weight,i<=0))throw new Error(EMi(Yme(s)));e=vln(s),n=Yme(s),r=t.getFn??null}return{path:e,id:n,weight:i,src:o,getFn:r}}function vln(t){return iw(t)?t:t.split(".")}function Yme(t){return iw(t)?t.join("."):t}function bMi(t,e){const n=[];let o=!1;const i=(r,s,a,A)=>{if(fE(r))if(!s[a])n.push(A!==void 0?{v:r,i:A}:r);else{const c=r[s[a]];if(!fE(c))return;if(a===s.length-1&&(hC(c)||Ome(c)||_Mi(c)||typeof c=="bigint"))n.push(A!==void 0?{v:wJe(c),i:A}:wJe(c));else if(iw(c)){o=!0;for(let l=0,g=c.length;l<g;l+=1)i(c[l],s,a+1,l)}else s.length&&i(c,s,a+1,A)}};return i(t,hC(e)?e.split("."):e,0),o?n:n[0]}const Ea=Object.freeze({...{isCaseSensitive:!1,ignoreDiacritics:!1,includeScore:!1,keys:[],shouldSort:!0,sortFn:(t,e)=>t.score===e.score?t.idx<e.idx?-1:1:t.score<e.score?-1:1},...{includeMatches:!1,findAllMatches:!1,minMatchCharLength:1},...{location:0,threshold:.6,distance:100},...{useExtendedSearch:!1,useTokenSearch:!1,tokenize:void 0,tokenMatch:"any",getFn:bMi,ignoreLocation:!1,ignoreFieldNorm:!1,fieldNormWeight:1}});function QMi(t){return t>=9&&t<=13||t===32||t===160}function vMi(t=1,e=3){const n=new Map,o=Math.pow(10,e);return{get(i){let r=0,s=!1;for(let A=0;A<i.length;A++)QMi(i.charCodeAt(A))?s=!1:s||(r++,s=!0);if(r===0&&(r=1),n.has(r))return n.get(r);const a=Math.round(o/Math.pow(r,.5*t))/o;return n.set(r,a),a},clear(){n.clear()}}}var DJe=class{constructor({getFn:t=Ea.getFn,fieldNormWeight:e=Ea.fieldNormWeight}={}){this.norm=vMi(e,3),this.getFn=t,this.isCreated=!1,this.docs=[],this.keys=[],this._keysMap={},this.setIndexRecords()}setSources(t=[]){this.docs=t}setIndexRecords(t=[]){this.records=t}setKeys(t=[]){this.keys=t,this._keysMap={},t.forEach((e,n)=>{this._keysMap[e.id]=n})}create(){if(this.isCreated||!this.docs.length)return;this.isCreated=!0;const t=this.docs.length;this.records=new Array(t);let e=0;if(hC(this.docs[0]))for(let n=0;n<t;n++){const o=this._createStringRecord(this.docs[n],n);o&&(this.records[e++]=o)}else for(let n=0;n<t;n++)this.records[e++]=this._createObjectRecord(this.docs[n],n);this.records.length=e,this.norm.clear()}add(t,e){if(!Number.isInteger(e)||e<0)throw new Error(MJe);if(hC(t)){const o=this._createStringRecord(t,e);return o&&this.records.push(o),o}const n=this._createObjectRecord(t,e);return this.records.push(n),n}removeAt(t){if(!Number.isInteger(t)||t<0)throw new Error(MJe);for(let e=0,n=this.records.length;e<n;e+=1)if(this.records[e].i===t){this.records.splice(e,1);break}for(let e=0,n=this.records.length;e<n;e+=1)this.records[e].i>t&&(this.records[e].i-=1)}removeAll(t){const e=new Set;for(const o of t)Number.isInteger(o)&&o>=0&&e.add(o);if(e.size===0)return;this.records=this.records.filter(o=>!e.has(o.i));const n=Array.from(e).sort((o,i)=>o-i);for(const o of this.records){let i=0,r=n.length;for(;i<r;){const s=i+r>>>1;n[s]<o.i?i=s+1:r=s}o.i-=i}}getValueForItemAtKeyId(t,e){return t[this._keysMap[e]]}size(){return this.records.length}_createStringRecord(t,e){return!fE(t)||Gme(t)?null:{v:t,i:e,n:this.norm.get(t)}}_createObjectRecord(t,e){const n={i:e,$:{}};for(let o=0,i=this.keys.length;o<i;o++){const r=this.keys[o],s=r.getFn?r.getFn(t):this.getFn(t,r.path);if(fE(s)){if(iw(s)){const a=[];for(let A=0,c=s.length;A<c;A+=1){const l=s[A];if(fE(l)){if(hC(l)){if(!Gme(l)){const g={v:l,i:A,n:this.norm.get(l)};a.push(g)}}else if(fE(l.v)){const g=hC(l.v)?l.v:wJe(l.v);if(!Gme(g)){const u={v:g,i:l.i,n:this.norm.get(g)};a.push(u)}}}}n.$[o]=a}else if(hC(s)&&!Gme(s)){const a={v:s,n:this.norm.get(s)};n.$[o]=a}}}return n}toJSON(){return{keys:this.keys.map(({getFn:t,...e})=>e),records:this.records}}};function Pln(t,e,{getFn:n=Ea.getFn,fieldNormWeight:o=Ea.fieldNormWeight}={}){const i=new DJe({getFn:n,fieldNormWeight:o});return i.setKeys(t.map(Qln)),i.setSources(e),i.create(),i}function PMi(t,{getFn:e=Ea.getFn,fieldNormWeight:n=Ea.fieldNormWeight}={}){const{keys:o,records:i}=t,r=new DJe({getFn:e,fieldNormWeight:n});return r.setKeys(o),r.setIndexRecords(i),r}function wMi(t=[],e=Ea.minMatchCharLength){const n=[];let o=-1,i=-1,r=0;for(let s=t.length;r<s;r+=1){const a=t[r];a&&o===-1?o=r:!a&&o!==-1&&(i=r-1,i-o+1>=e&&n.push([o,i]),o=-1)}return t[r-1]&&r-o>=e&&n.push([o,r-1]),n}function MMi(t,e,n,{location:o=Ea.location,distance:i=Ea.distance,threshold:r=Ea.threshold,findAllMatches:s=Ea.findAllMatches,minMatchCharLength:a=Ea.minMatchCharLength,includeMatches:A=Ea.includeMatches,ignoreLocation:c=Ea.ignoreLocation}={}){if(e.length>32)throw new Error(yMi(32));const l=e.length,g=t.length,u=Math.max(0,Math.min(o,g));let h=r,d=u;const m=(b,Q)=>{const w=b/l;if(c)return w;const D=Math.abs(u-Q);return i?w+D/i:D?1:w},p=a>1||A,_=p?Array(g):[];let f;for(;(f=t.indexOf(e,d))>-1;){const b=m(0,f);if(h=Math.min(b,h),d=f+l,p){let Q=0;for(;Q<l;)_[f+Q]=1,Q+=1}}d=-1;let I=[],C=1,y=0,x=l+g;const E=1<<l-1;for(let b=0;b<l;b+=1){let Q=0,w=x;for(;Q<w;)m(b,u+w)<=h?Q=w:x=w,w=Math.floor((x-Q)/2+Q);x=w;let D=Math.max(1,u-w+1);const k=s?g:Math.min(u+w,g)+l,R=Array(k+2);R[k+1]=(1<<b)-1;for(let H=k;H>=D;H-=1){const G=H-1,K=n[t[G]];if(R[H]=(R[H+1]<<1|1)&K,b&&(R[H]|=(I[H+1]|I[H])<<1|1|I[H+1]),R[H]&E&&(C=m(b,G),C<=h)){if(h=C,d=G,y=b,d<=u)break;D=Math.max(1,2*u-d)}}if(m(b+1,u)>h)break;I=R}if(p&&d>=0){const b=Math.min(g-1,d+l-1+y);for(let Q=d;Q<=b;Q+=1)n[t[Q]]&&(_[Q]=1)}const B={isMatch:d>=0,score:Math.max(.001,C)};if(p){const b=wMi(_,a);b.length?A&&(B.indices=b):B.isMatch=!1}return B}function DMi(t){const e={};for(let n=0,o=t.length;n<o;n+=1){const i=t.charAt(n);e[i]=(e[i]||0)|1<<o-n-1}return e}function NJe(t){if(t.length<=1)return t;t.sort((n,o)=>n[0]-o[0]||n[1]-o[1]);const e=[t[0]];for(let n=1,o=t.length;n<o;n+=1){const i=e[e.length-1],r=t[n];r[0]<=i[1]+1?i[1]=Math.max(i[1],r[1]):e.push(r)}return e}const wln={ł:"l",Ł:"L",đ:"d",Đ:"D",ø:"o",Ø:"O",ħ:"h",Ħ:"H",ŧ:"t",Ŧ:"T",ı:"i",ß:"ss"},NMi=new RegExp("["+Object.keys(wln).join("")+"]","g"),Q$=typeof String.prototype.normalize=="function"?t=>t.normalize("NFD").replace(/[\u0300-\u036F\u0483-\u0489\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u0610-\u061A\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED\u0711\u0730-\u074A\u07A6-\u07B0\u07EB-\u07F3\u07FD\u0816-\u0819\u081B-\u0823\u0825-\u0827\u0829-\u082D\u0859-\u085B\u08D3-\u08E1\u08E3-\u0903\u093A-\u093C\u093E-\u094F\u0951-\u0957\u0962\u0963\u0981-\u0983\u09BC\u09BE-\u09C4\u09C7\u09C8\u09CB-\u09CD\u09D7\u09E2\u09E3\u09FE\u0A01-\u0A03\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A70\u0A71\u0A75\u0A81-\u0A83\u0ABC\u0ABE-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AE2\u0AE3\u0AFA-\u0AFF\u0B01-\u0B03\u0B3C\u0B3E-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B62\u0B63\u0B82\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD7\u0C00-\u0C04\u0C3E-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C62\u0C63\u0C81-\u0C83\u0CBC\u0CBE-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CE2\u0CE3\u0D00-\u0D03\u0D3B\u0D3C\u0D3E-\u0D44\u0D46-\u0D48\u0D4A-\u0D4D\u0D57\u0D62\u0D63\u0D82\u0D83\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DF2\u0DF3\u0E31\u0E34-\u0E3A\u0E47-\u0E4E\u0EB1\u0EB4-\u0EB9\u0EBB\u0EBC\u0EC8-\u0ECD\u0F18\u0F19\u0F35\u0F37\u0F39\u0F3E\u0F3F\u0F71-\u0F84\u0F86\u0F87\u0F8D-\u0F97\u0F99-\u0FBC\u0FC6\u102B-\u103E\u1056-\u1059\u105E-\u1060\u1062-\u1064\u1067-\u106D\u1071-\u1074\u1082-\u108D\u108F\u109A-\u109D\u135D-\u135F\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17B4-\u17D3\u17DD\u180B-\u180D\u1885\u1886\u18A9\u1920-\u192B\u1930-\u193B\u1A17-\u1A1B\u1A55-\u1A5E\u1A60-\u1A7C\u1A7F\u1AB0-\u1ABE\u1B00-\u1B04\u1B34-\u1B44\u1B6B-\u1B73\u1B80-\u1B82\u1BA1-\u1BAD\u1BE6-\u1BF3\u1C24-\u1C37\u1CD0-\u1CD2\u1CD4-\u1CE8\u1CED\u1CF2-\u1CF4\u1CF7-\u1CF9\u1DC0-\u1DF9\u1DFB-\u1DFF\u20D0-\u20F0\u2CEF-\u2CF1\u2D7F\u2DE0-\u2DFF\u302A-\u302F\u3099\u309A\uA66F-\uA672\uA674-\uA67D\uA69E\uA69F\uA6F0\uA6F1\uA802\uA806\uA80B\uA823-\uA827\uA880\uA881\uA8B4-\uA8C5\uA8E0-\uA8F1\uA8FF\uA926-\uA92D\uA947-\uA953\uA980-\uA983\uA9B3-\uA9C0\uA9E5\uAA29-\uAA36\uAA43\uAA4C\uAA4D\uAA7B-\uAA7D\uAAB0\uAAB2-\uAAB4\uAAB7\uAAB8\uAABE\uAABF\uAAC1\uAAEB-\uAAEF\uAAF5\uAAF6\uABE3-\uABEA\uABEC\uABED\uFB1E\uFE00-\uFE0F\uFE20-\uFE2F]/g,"").replace(NMi,e=>wln[e]):t=>t;var RJe=class{constructor(t,{location:e=Ea.location,threshold:n=Ea.threshold,distance:o=Ea.distance,includeMatches:i=Ea.includeMatches,findAllMatches:r=Ea.findAllMatches,minMatchCharLength:s=Ea.minMatchCharLength,isCaseSensitive:a=Ea.isCaseSensitive,ignoreDiacritics:A=Ea.ignoreDiacritics,ignoreLocation:c=Ea.ignoreLocation}={}){if(this.options={location:e,threshold:n,distance:o,includeMatches:i,findAllMatches:r,minMatchCharLength:s,isCaseSensitive:a,ignoreDiacritics:A,ignoreLocation:c},t=a?t:t.toLowerCase(),t=A?Q$(t):t,this.pattern=t,this.chunks=[],!this.pattern.length)return;const l=(u,h)=>{this.chunks.push({pattern:u,alphabet:DMi(u),startIndex:h})},g=this.pattern.length;if(g>32){let u=0;const h=g%32,d=g-h;for(;u<d;)l(this.pattern.substr(u,32),u),u+=32;if(h){const m=g-32;l(this.pattern.substr(m),m)}}else l(this.pattern,0)}searchIn(t){const{isCaseSensitive:e,ignoreDiacritics:n,includeMatches:o}=this.options;if(t=e?t:t.toLowerCase(),t=n?Q$(t):t,this.pattern===t){if(t.length<this.options.minMatchCharLength)return{isMatch:!1,score:1};const d={isMatch:!0,score:0};return o&&(d.indices=[[0,t.length-1]]),d}const{location:i,distance:r,threshold:s,findAllMatches:a,minMatchCharLength:A,ignoreLocation:c}=this.options,l=[];let g=0,u=!1;this.chunks.forEach(({pattern:d,alphabet:m,startIndex:p})=>{const{isMatch:_,score:f,indices:I}=MMi(t,d,m,{location:i+p,distance:r,threshold:s,findAllMatches:a,minMatchCharLength:A,includeMatches:o,ignoreLocation:c});_&&(u=!0),g+=f,_&&I&&l.push(...I)});const h={isMatch:u,score:u?g/this.chunks.length:1};return u&&o&&(h.indices=NJe(l)),h}};const RMi=new Set(["fuzzy","include"]);function TMi(t){return t.startsWith("inverse")}const TJe=[{type:"exact",multiRegex:/^="(.*)"$/,singleRegex:/^=(.*)$/,create:t=>({type:"exact",search(e){const n=e===t;return{isMatch:n,score:n?0:1,indices:[0,t.length-1]}}})},{type:"include",multiRegex:/^'"(.*)"$/,singleRegex:/^'(.*)$/,create:t=>({type:"include",search(e){let n=0,o;const i=[],r=t.length;for(;(o=e.indexOf(t,n))>-1;)n=o+r,i.push([o,n-1]);const s=!!i.length;return{isMatch:s,score:s?0:1,indices:i}}})},{type:"prefix-exact",multiRegex:/^\^"(.*)"$/,singleRegex:/^\^(.*)$/,create:t=>({type:"prefix-exact",search(e){const n=e.startsWith(t);return{isMatch:n,score:n?0:1,indices:[0,t.length-1]}}})},{type:"inverse-prefix-exact",multiRegex:/^!\^"(.*)"$/,singleRegex:/^!\^(.*)$/,create:t=>({type:"inverse-prefix-exact",search(e){const n=!e.startsWith(t);return{isMatch:n,score:n?0:1,indices:[0,e.length-1]}}})},{type:"inverse-suffix-exact",multiRegex:/^!"(.*)"\$$/,singleRegex:/^!(.*)\$$/,create:t=>({type:"inverse-suffix-exact",search(e){const n=!e.endsWith(t);return{isMatch:n,score:n?0:1,indices:[0,e.length-1]}}})},{type:"suffix-exact",multiRegex:/^"(.*)"\$$/,singleRegex:/^(.*)\$$/,create:t=>({type:"suffix-exact",search(e){const n=e.endsWith(t);return{isMatch:n,score:n?0:1,indices:[e.length-t.length,e.length-1]}}})},{type:"inverse-exact",multiRegex:/^!"(.*)"$/,singleRegex:/^!(.*)$/,create:t=>({type:"inverse-exact",search(e){const n=e.indexOf(t)===-1;return{isMatch:n,score:n?0:1,indices:[0,e.length-1]}}})},{type:"fuzzy",multiRegex:/^"(.*)"$/,singleRegex:/^(.*)$/,create:(t,e={})=>{const n=new RJe(t,{location:e.location??Ea.location,threshold:e.threshold??Ea.threshold,distance:e.distance??Ea.distance,includeMatches:e.includeMatches??Ea.includeMatches,findAllMatches:e.findAllMatches??Ea.findAllMatches,minMatchCharLength:e.minMatchCharLength??Ea.minMatchCharLength,isCaseSensitive:e.isCaseSensitive??Ea.isCaseSensitive,ignoreDiacritics:e.ignoreDiacritics??Ea.ignoreDiacritics,ignoreLocation:e.ignoreLocation??Ea.ignoreLocation});return{type:"fuzzy",search(o){return n.searchIn(o)}}}}],Mln=TJe.length,kMi="\0",FMi="|";function LMi(t){const e=[],n=t.length;let o=0;for(;o<n;){for(;o<n&&t[o]===" ";)o++;if(o>=n)break;let i=o;for(;i<n&&t[i]!==" "&&t[i]!=='"';)i++;if(i<n&&t[i]==='"'){for(i++;i<n;){if(t[i]==='"'){const r=i+1;if(r>=n||t[r]===" "){i++;break}if(t[r]==="$"&&(r+1>=n||t[r+1]===" ")){i+=2;break}}i++}e.push(t.substring(o,i)),o=i}else{for(;i<n&&t[i]!==" ";)i++;e.push(t.substring(o,i)),o=i}}return e}function Dln(t,e){const n=t.match(e);return n?n[1]:null}function HMi(t,e={}){return t.replace(/\\\|/g,kMi).split(FMi).map(n=>{const o=LMi(n.replace(/\u0000/g,"|").trim()).filter(r=>r&&!!r.trim()),i=[];for(let r=0,s=o.length;r<s;r+=1){const a=o[r];let A=!1,c=-1;for(;!A&&++c<Mln;){const l=TJe[c],g=Dln(a,l.multiRegex);g&&(i.push(l.create(g,e)),A=!0)}if(!A)for(c=-1;++c<Mln;){const l=TJe[c],g=Dln(a,l.singleRegex);if(g){i.push(l.create(g,e));break}}}return i})}var OMi=class{constructor(t,{isCaseSensitive:e=Ea.isCaseSensitive,ignoreDiacritics:n=Ea.ignoreDiacritics,includeMatches:o=Ea.includeMatches,minMatchCharLength:i=Ea.minMatchCharLength,ignoreLocation:r=Ea.ignoreLocation,findAllMatches:s=Ea.findAllMatches,location:a=Ea.location,threshold:A=Ea.threshold,distance:c=Ea.distance}={}){this.query=null,this.options={isCaseSensitive:e,ignoreDiacritics:n,includeMatches:o,minMatchCharLength:i,findAllMatches:s,ignoreLocation:r,location:a,threshold:A,distance:c},t=e?t:t.toLowerCase(),t=n?Q$(t):t,this.pattern=t,this.query=HMi(this.pattern,this.options)}static condition(t,e){return e.useExtendedSearch}searchIn(t){const e=this.query;if(!e)return{isMatch:!1,score:1};const{includeMatches:n,isCaseSensitive:o,ignoreDiacritics:i}=this.options;t=o?t:t.toLowerCase(),t=i?Q$(t):t;let r=0;const s=[];let a=0,A=!1;for(let c=0,l=e.length;c<l;c+=1){const g=e[c];s.length=0,r=0,A=!1;for(let u=0,h=g.length;u<h;u+=1){const d=g[u],{isMatch:m,indices:p,score:_}=d.search(t);if(m)r+=1,a+=_,TMi(d.type)&&(A=!0),n&&(RMi.has(d.type)?s.push(...p):s.push(p));else{a=0,r=0,s.length=0,A=!1;break}}if(r){const u={isMatch:!0,score:a/r};return A&&(u.hasInverse=!0),n&&(u.indices=NJe(s)),u}}return{isMatch:!1,score:1}}};const kJe=[];function FJe(...t){kJe.push(...t)}function Ume(t,e){for(let n=0,o=kJe.length;n<o;n+=1){const i=kJe[n];if(i.condition(t,e))return new i(t,e)}return new RJe(t,e)}const Kme={AND:"$and",OR:"$or"},LJe={PATH:"$path",PATTERN:"$val"},HJe=t=>!!(t[Kme.AND]||t[Kme.OR]),GMi=t=>!!t[LJe.PATH],YMi=t=>!iw(t)&&Bln(t)&&!HJe(t),Nln=t=>({[Kme.AND]:Object.keys(t).map(e=>({[e]:t[e]}))});function Rln(t,e,{auto:n=!0}={}){const o=i=>{if(hC(i)){const A={keyId:null,pattern:i};return n&&(A.searcher=Ume(i,e)),A}const r=Object.keys(i),s=GMi(i);if(!s&&r.length>1&&!HJe(i))return o(Nln(i));if(YMi(i)){const A=s?i[LJe.PATH]:r[0],c=s?i[LJe.PATTERN]:i[A];if(!hC(c))throw new Error(CMi(A));const l={keyId:Yme(A),pattern:c};return n&&(l.searcher=Ume(c,e)),l}const a={children:[],operator:r[0]};return r.forEach(A=>{const c=i[A];iw(c)&&c.forEach(l=>{a.children.push(o(l))})}),a};return HJe(t)||(t=Nln(t)),o(t)}function OJe(t,{ignoreFieldNorm:e=Ea.ignoreFieldNorm}){let n=1;return t.forEach(({key:o,norm:i,score:r})=>{const s=o?o.weight:null;n*=Math.pow(r===0&&s?Number.EPSILON:r,(s||1)*(e?1:i))}),n}function UMi(t,{ignoreFieldNorm:e=Ea.ignoreFieldNorm}){t.forEach(n=>{n.score=OJe(n.matches,{ignoreFieldNorm:e})})}var KMi=class{constructor(t,e){this.limit=t,this.heap=[],this.comparator=e}get size(){return this.heap.length}insert(t){this.size<this.limit?(this.heap.push(t),this._bubbleUp(this.size-1)):this.comparator(t,this.heap[0])<0&&(this.heap[0]=t,this._sinkDown(0))}extractSorted(){return this.heap.sort(this.comparator)}_bubbleUp(t){const e=this.heap;for(;t>0;){const n=t-1>>1;if(this.comparator(e[t],e[n])<=0)break;const o=e[t];e[t]=e[n],e[n]=o,t=n}}_sinkDown(t){const e=this.heap,n=e.length;let o=t;do{t=o;const i=2*t+1,r=2*t+2;if(i<n&&this.comparator(e[i],e[o])>0&&(o=i),r<n&&this.comparator(e[r],e[o])>0&&(o=r),o!==t){const s=e[t];e[t]=e[o],e[o]=s}}while(o!==t)}};function VMi(t){const e=[];return t.matches.forEach(n=>{if(!fE(n.indices)||!n.indices.length)return;const o={indices:n.indices,value:n.value};n.key&&(o.key=n.key.id),n.idx>-1&&(o.refIndex=n.idx),e.push(o)}),e}function zMi(t,e,{includeMatches:n=Ea.includeMatches,includeScore:o=Ea.includeScore}={}){return t.map(i=>{const{idx:r}=i,s={item:e[r],refIndex:r};return n&&(s.matches=VMi(i)),o&&(s.score=i.score),s})}const JMi=/[\p{L}\p{M}\p{N}_]+/gu,Tln=new WeakSet;function WMi(t){Tln.has(t)||(Tln.add(t),console.warn(`[Fuse] tokenize regex ${t} lacks the global flag; only the first match per text will be returned. Add the 'g' flag.`))}function jMi(t){if(typeof t=="function"){let e=!1;return n=>{const o=t(n);if(!e&&(e=!0,!Array.isArray(o)||o.some(i=>typeof i!="string")))throw new Error(`[Fuse] tokenize function must return string[]; received ${Array.isArray(o)?"array containing non-strings":typeof o}.`);return o}}return t instanceof RegExp?(t.global||WMi(t),e=>e.match(t)||[]):e=>e.match(JMi)||[]}function GJe({isCaseSensitive:t=!1,ignoreDiacritics:e=!1,tokenize:n}={}){const o=jMi(n);return{tokenize(i){return t||(i=i.toLowerCase()),e&&(i=Q$(i)),o(i)}}}var XMi=class{static condition(t,e){return e.useTokenSearch}constructor(t,e){this.options=e,this.analyzer=GJe({isCaseSensitive:e.isCaseSensitive,ignoreDiacritics:e.ignoreDiacritics,tokenize:e.tokenize});const n=this.analyzer.tokenize(t),{df:o,fieldCount:i}=e._invertedIndex;this.termSearchers=[],this.idfWeights=[];for(const r of n){this.termSearchers.push(new RJe(r,{location:e.location,threshold:e.threshold,distance:e.distance,includeMatches:e.includeMatches,findAllMatches:e.findAllMatches,minMatchCharLength:e.minMatchCharLength,isCaseSensitive:e.isCaseSensitive,ignoreDiacritics:e.ignoreDiacritics,ignoreLocation:!0}));const s=o.get(r)||0,a=Math.log(1+(i-s+.5)/(s+.5));this.idfWeights.push(a)}this.combineAll=e.tokenMatch==="all",this.numTerms=this.termSearchers.length,this.useMask=this.numTerms<=31}searchIn(t){if(!this.termSearchers.length)return{isMatch:!1,score:1};const e=[];let n=0,o=0,i=0,r=0;const s=this.combineAll&&!this.useMask?new Set:null;for(let c=0;c<this.termSearchers.length;c++){const l=this.termSearchers[c].searchIn(t),g=this.idfWeights[c];o+=g,l.isMatch&&(i++,n+=g*(1-l.score),l.indices&&e.push(...l.indices),this.combineAll&&(this.useMask?r|=1<<c:s.add(c)))}if(i===0)return{isMatch:!1,score:1};const a=o>0?1-n/o:0,A={isMatch:!0,score:Math.max(.001,a)};return this.options.includeMatches&&e.length&&(A.indices=NJe(e)),this.combineAll&&(this.useMask?A.matchedMask=r:A.matchedTerms=s,A.termCount=this.numTerms),A}};function YJe(t,e,n,o){const i=o.tokenize(e);if(!i.length)return;t.fieldCount++,t.docFieldCount.set(n,(t.docFieldCount.get(n)||0)+1);const r=new Set(i);let s=t.docTermFieldHits.get(n);s||(s=new Map,t.docTermFieldHits.set(n,s));for(const a of r)s.set(a,(s.get(a)||0)+1),t.df.set(a,(t.df.get(a)||0)+1)}function kln(t,e,n,o){const{i,v:r,$:s}=e;if(r!==void 0){YJe(t,r,i,o);return}if(s)for(let a=0;a<n;a++){const A=s[a];if(A)if(Array.isArray(A))for(const c of A)YJe(t,c.v,i,o);else YJe(t,A.v,i,o)}}function qMi(t,e,n){const o={fieldCount:0,df:new Map,docFieldCount:new Map,docTermFieldHits:new Map};for(const i of t)kln(o,i,e,n);return o}function $Mi(t,e,n,o){kln(t,e,n,o)}function ZMi(t,e){const n=t.docFieldCount.get(e);if(n===void 0)return;t.fieldCount-=n,t.docFieldCount.delete(e);const o=t.docTermFieldHits.get(e);if(o){for(const[i,r]of o){const s=(t.df.get(i)||0)-r;s<=0?t.df.delete(i):t.df.set(i,s)}t.docTermFieldHits.delete(e)}}function Fln(t,e){if(e.length===0)return;const n=Array.from(new Set(e)).sort((a,A)=>a-A);for(const a of n)ZMi(t,a);const o=a=>{let A=0,c=n.length;for(;A<c;){const l=A+c>>>1;n[l]<a?A=l+1:c=l}return a-A},i=n[0],r=new Map;for(const[a,A]of t.docFieldCount)r.set(a>i?o(a):a,A);t.docFieldCount=r;const s=new Map;for(const[a,A]of t.docTermFieldHits)s.set(a>i?o(a):a,A);t.docTermFieldHits=s}var rw=class{constructor(t,e,n){this.options={...Ea,...e},this.options.useExtendedSearch,this.options.useTokenSearch,this._keyStore=new SMi(this.options.keys),this._docs=t,this._myIndex=null,this._invertedIndex=null,this.setCollection(t,n),this._lastQuery=null,this._lastSearcher=null}_getSearcher(t){if(this._lastQuery===t)return this._lastSearcher;const e=Ume(t,this._invertedIndex?{...this.options,_invertedIndex:this._invertedIndex}:this.options);return this._lastQuery=t,this._lastSearcher=e,e}setCollection(t,e){if(this._docs=t,e&&!(e instanceof DJe))throw new Error(IMi);if(this._myIndex=e||Pln(this.options.keys,this._docs,{getFn:this.options.getFn,fieldNormWeight:this.options.fieldNormWeight}),this.options.useTokenSearch){const n=GJe({isCaseSensitive:this.options.isCaseSensitive,ignoreDiacritics:this.options.ignoreDiacritics,tokenize:this.options.tokenize});this._invertedIndex=qMi(this._myIndex.records,this._myIndex.keys.length,n)}this._invalidateSearcherCache()}add(t){if(!fE(t))return;this._docs.push(t);const e=this._myIndex.add(t,this._docs.length-1);if(this._invertedIndex&&e){const n=GJe({isCaseSensitive:this.options.isCaseSensitive,ignoreDiacritics:this.options.ignoreDiacritics,tokenize:this.options.tokenize});$Mi(this._invertedIndex,e,this._myIndex.keys.length,n)}this._invalidateSearcherCache()}remove(t=()=>!1){const e=[],n=[];for(let o=0,i=this._docs.length;o<i;o+=1)t(this._docs[o],o)&&(e.push(this._docs[o]),n.push(o));if(n.length){this._invertedIndex&&Fln(this._invertedIndex,n);const o=new Set(n);this._docs=this._docs.filter((i,r)=>!o.has(r)),this._myIndex.removeAll(n),this._invalidateSearcherCache()}return e}removeAt(t){if(!Number.isInteger(t)||t<0||t>=this._docs.length)throw new Error(MJe);this._invertedIndex&&Fln(this._invertedIndex,[t]);const e=this._docs.splice(t,1)[0];return this._myIndex.removeAt(t),this._invalidateSearcherCache(),e}_invalidateSearcherCache(){this._lastQuery=null,this._lastSearcher=null}getIndex(){return this._myIndex}_normalizedKeys(){return this._myIndex.keys.map(t=>this._keyStore.get(t.id)||t)}search(t,e){const{limit:n=-1}=e||{},{includeMatches:o,includeScore:i,shouldSort:r,sortFn:s,ignoreFieldNorm:a}=this.options;if(hC(t)&&!t.trim()){let u=this._docs.map((h,d)=>({item:h,refIndex:d}));return Ome(n)&&n>-1&&(u=u.slice(0,n)),u}const A=r&&Ome(n)&&n>0&&hC(t),c=s,l=(u,h)=>c(u,h)||u.idx-h.idx;let g;if(A){const u=new KMi(n,l);hC(this._docs[0])?this._searchStringList(t,{heap:u,ignoreFieldNorm:a}):this._searchObjectList(t,{heap:u,ignoreFieldNorm:a}),g=u.extractSorted()}else g=hC(t)?hC(this._docs[0])?this._searchStringList(t):this._searchObjectList(t):this._searchLogical(t),UMi(g,{ignoreFieldNorm:a}),r&&g.sort(hC(t)?l:c),Ome(n)&&n>-1&&(g=g.slice(0,n));return zMi(g,this._docs,{includeMatches:o,includeScore:i})}_searchStringList(t,{heap:e,ignoreFieldNorm:n}={}){const o=this._getSearcher(t),i=this.options.useTokenSearch&&this.options.tokenMatch==="all",{records:r}=this._myIndex,s=e?null:[];return r.forEach(({v:a,i:A,n:c})=>{if(!fE(a))return;const l=o.searchIn(a);if(l.isMatch){const g={score:l.score,value:a,norm:c,indices:l.indices};i&&(g.matchedMask=l.matchedMask,g.matchedTerms=l.matchedTerms,g.termCount=l.termCount);const u=[g];if(!i||this._coversAllTokens(u)){const h={item:a,idx:A,matches:u};e?(h.score=OJe(h.matches,{ignoreFieldNorm:n}),e.insert(h)):s.push(h)}}}),s}_searchLogical(t){const e=Rln(t,this.options),n=this._normalizedKeys(),o=(a,A,c)=>{if(!("children"in a)){const{keyId:h,searcher:d}=a;let m;return h===null?(m=[],n.forEach((p,_)=>{m.push(...this._findMatches({key:p,value:A[_],searcher:d}))})):m=this._findMatches({key:this._keyStore.get(h),value:this._myIndex.getValueForItemAtKeyId(A,h),searcher:d}),m&&m.length?[{idx:c,item:A,matches:m}]:[]}const{children:l,operator:g}=a,u=[];for(let h=0,d=l.length;h<d;h+=1){const m=l[h],p=o(m,A,c);if(p.length)u.push(...p);else if(g===Kme.AND)return[]}return u},i=this._myIndex.records,r=new Map,s=[];return i.forEach(({$:a,i:A})=>{if(fE(a)){const c=o(e,a,A);c.length&&(r.has(A)||(r.set(A,{idx:A,item:a,matches:[]}),s.push(r.get(A))),c.forEach(({matches:l})=>{r.get(A).matches.push(...l)}))}}),s}_searchObjectList(t,{heap:e,ignoreFieldNorm:n}={}){const o=this._getSearcher(t),i=this.options.useTokenSearch&&this.options.tokenMatch==="all",{records:r}=this._myIndex,s=this._normalizedKeys(),a=e?null:[];return r.forEach(({$:A,i:c})=>{if(!fE(A))return;const l=[];let g=!1,u=!1;if(s.forEach((h,d)=>{const m=this._findMatches({key:h,value:A[d],searcher:o});m.length?(l.push(...m),m[0].hasInverse&&(u=!0)):g=!0}),!(u&&g)&&l.length&&(!i||this._coversAllTokens(l))){const h={idx:c,item:A,matches:l};e?(h.score=OJe(h.matches,{ignoreFieldNorm:n}),e.insert(h)):a.push(h)}}),a}_findMatches({key:t,value:e,searcher:n}){if(!fE(e))return[];const o=[];if(iw(e))e.forEach(({v:i,i:r,n:s})=>{if(!fE(i))return;const a=n.searchIn(i);if(a.isMatch){const A={score:a.score,key:t,value:i,idx:r,norm:s,indices:a.indices,hasInverse:a.hasInverse};a.termCount!==void 0&&(A.matchedMask=a.matchedMask,A.matchedTerms=a.matchedTerms,A.termCount=a.termCount),o.push(A)}});else{const{v:i,n:r}=e,s=n.searchIn(i);if(s.isMatch){const a={score:s.score,key:t,value:i,norm:r,indices:s.indices,hasInverse:s.hasInverse};s.termCount!==void 0&&(a.matchedMask=s.matchedMask,a.matchedTerms=s.matchedTerms,a.termCount=s.termCount),o.push(a)}}return o}_coversAllTokens(t){const e=t.length?t[0].termCount:void 0;if(e===void 0)return!0;if(e<=31){let o=0;for(let i=0;i<t.length;i++)o|=t[i].matchedMask||0;return o===2**e-1}const n=new Set;for(let o=0;o<t.length;o++){const i=t[o].matchedTerms;if(i)for(const r of i)n.add(r)}return n.size===e}};rw.version="7.5.0",rw.createIndex=Pln,rw.parseIndex=PMi,rw.config=Ea,rw.match=function(t,e,n){if(n&&n.useTokenSearch)throw new Error(BMi);return Ume(t,{...Ea,...n}).searchIn(e)},rw.parseQuery=Rln,FJe(OMi),FJe(XMi),rw.use=function(...t){t.forEach(e=>FJe(e))};var eDi=rw;const tDi="https://kicad-mod-cache.tscircuit.com";let UJe=null,v$=null,KJe=null;const nDi=async()=>UJe||v$||(v$=fetch("https://kicad-mod-cache.tscircuit.com/kicad_files.json").then(t=>t.json()).then(t=>(UJe=t,v$=null,t)),v$),oDi=async(t,e=20)=>{const n=await nDi();return KJe||(KJe=new eDi(n)),KJe.search(t).slice(0,e).map(o=>o.item)},iDi=t=>{const e=t.replace(".pretty/","/").replace(".kicad_mod",""),n=`kicad:${e}`;return{path:t,qualifiedName:n,description:e}},rDi=t=>t.replace(/^\/+/,"").split("/").map(e=>encodeURIComponent(e)).join("/"),sDi=async t=>{const e=await fetch(`${tDi}/${rDi(t)}`);if(!e.ok)throw new Error(`KiCad footprint fetch failed: ${e.status}`);const n=await e.text(),{KicadFootprintToCircuitJsonConverter:o}=await gE("kicad-to-circuit-json"),i=new o;return i.addFile(t.split("/").pop()??"selected-footprint.kicad_mod",n),i.runUntilFinished(),i.getOutput()},Lln=t=>t?.source==="jlcpcb"||t?.source==="kicad",aDi=async(t,e)=>{if(t.source==="jlcpcb")return mMi(t.component.partNumber,e?.jlcpcb);if(t.source==="kicad")return sDi(t.footprint.path);throw new Error("Footprint preview is not available for this source")},ADi=({query:t,placeholder:e,isSearching:n,onQueryChange:o,onSubmit:i})=>{const r=ee.useCallback(s=>{s.key==="Enter"&&(s.preventDefault(),i())},[i]);return U.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2 rf-mt-4",children:[U.jsxs("div",{className:"rf-relative rf-flex-grow",children:[U.jsx(_Ve,{className:"rf-absolute rf-left-2 rf-top-2.5 rf-h-4 rf-w-4 rf-text-muted-foreground"}),U.jsx(_ze,{placeholder:e,className:"rf-pl-8",spellCheck:!1,autoComplete:"off",value:t,onChange:s=>o(s.target.value),onKeyDown:r})]}),U.jsx(uA,{onClick:i,disabled:n||t.trim().length<1,className:"sm:rf-px-4 rf-px-3",children:n?U.jsx(sE,{className:"rf-h-4 rf-w-4 rf-animate-spin"}):U.jsxs(U.Fragment,{children:[U.jsx(_Ve,{className:"rf-h-4 rf-w-4 sm:rf-hidden"}),U.jsx("span",{className:"rf-hidden sm:rf-inline",children:"Search"})]})})]})},cDi=new Intl.NumberFormat("en-US",{style:"currency",currency:"USD"}),lDi=t=>cDi.format(t),Hln=t=>{switch(t.source){case"tscircuit.com":{const e=t.package;return`tscircuit-${e.package_id??`${e.org_owner_tscircuit_handle??"unknown"}-${e.unscoped_name??e.name??"package"}`}`}case"jlcpcb":return`jlc-${t.component.lcscId}`;case"kicad":return`kicad-${t.footprint.path}`;default:return"unknown"}},gDi=t=>{switch(t.source){case"tscircuit.com":return t.package.unscoped_name;case"jlcpcb":return t.component.isDirectLookup?t.component.partNumber:t.component.manufacturer;case"kicad":return t.footprint.qualifiedName}},uDi=t=>{switch(t.source){case"tscircuit.com":return t.package.description||(t.package.org_owner_tscircuit_handle?`Component by ${t.package.org_owner_tscircuit_handle}`:void 0);case"jlcpcb":return t.component.description;case"kicad":return t.footprint.description}},dDi=t=>{switch(t.source){case"tscircuit.com":return t.package.name;case"jlcpcb":return t.component.isDirectLookup?void 0:t.component.partNumber;case"kicad":return}},hDi=({results:t,selected:e,onSelect:n,onShowDetails:o})=>{const i=e?Hln(e):null;return U.jsx("div",{className:"rf-divide-y rf-w-full rf-overflow-hidden",children:t.map(r=>{const s=Hln(r),a=i===s,A=gDi(r),c=uDi(r),l=dDi(r),g=r.source==="jlcpcb"?r.component.stock:null,u=r.source==="jlcpcb"?r.component.price:null,h=r.source==="jlcpcb"?r.component.isBasic:null,d=r.source==="jlcpcb"?r.component.isDirectLookup:!1;return U.jsxs("div",{className:`rf-p-3 rf-flex rf-flex-col sm:rf-grid sm:rf-grid-cols-[minmax(0,1fr)_auto] rf-items-start sm:rf-items-center rf-cursor-pointer hover:rf-bg-zinc-100 rf-gap-2 rf-overflow-hidden ${a?"rf-bg-zinc-100":""}`,onClick:()=>n(r),children:[U.jsxs("div",{className:"rf-min-w-0 rf-overflow-hidden rf-w-full",children:[U.jsxs("div",{className:"rf-flex rf-items-start rf-gap-2 rf-min-w-0",children:[U.jsxs("div",{className:"rf-font-medium rf-text-sm rf-truncate rf-flex-1 rf-min-w-0 rf-flex rf-items-center rf-gap-1.5",children:[A,r.source==="jlcpcb"&&h!=null&&U.jsx("span",{className:`rf-text-xs rf-px-1.5 rf-py-0.5 rf-rounded rf-font-medium rf-flex-shrink-0 ${h?"rf-bg-green-100 rf-text-green-700":"rf-bg-orange-100 rf-text-orange-700"}`,children:h?"Basic":"Extended"}),d&&U.jsx("span",{className:"rf-text-xs rf-px-1.5 rf-py-0.5 rf-rounded rf-font-medium rf-flex-shrink-0 rf-bg-blue-100 rf-text-blue-700",children:"Direct lookup"}),r.source==="tscircuit.com"&&r.package.is_private&&U.jsx(c3i,{className:"rf-ml-1 rf-h-3 rf-w-3 rf-text-zinc-400 rf-flex-shrink-0"})]}),r.source==="jlcpcb"&&g!=null?U.jsxs("div",{className:"rf-text-xs rf-text-zinc-500 rf-font-medium rf-whitespace-nowrap rf-flex-shrink-0 sm:rf-hidden",children:[g.toLocaleString()," in stock"]}):null]}),U.jsxs("div",{className:"rf-text-xs rf-text-zinc-500 rf-truncate rf-w-full",children:[l?U.jsx("span",{className:"rf-mr-2",children:l}):null,c]})]}),U.jsxs("div",{children:[r.source==="tscircuit.com"&&o?U.jsx("div",{className:"rf-flex-shrink-0 rf-w-full sm:rf-w-auto",children:U.jsx(uA,{variant:"outline",size:"sm",className:"rf-text-xs rf-w-full sm:rf-w-auto",onClick:m=>{m.stopPropagation(),o(r)},children:"See Details"})}):r.source==="jlcpcb"&&g!=null?U.jsxs("div",{className:"rf-hidden sm:rf-block rf-text-xs rf-text-zinc-500 rf-font-medium rf-whitespace-nowrap rf-flex-shrink-0",children:[g.toLocaleString()," in stock"]}):null,u!=null&&U.jsx("div",{className:"rf-hidden sm:rf-block rf-text-xs rf-text-zinc-500 rf-font-medium rf-whitespace-nowrap rf-flex-shrink-0 rf-text-right",children:lDi(u)})]})]},s)})})},mDi=({circuitJson:t,error:e,isLoading:n,height:o})=>U.jsx("section",{className:"rf-flex rf-min-w-0 rf-items-center rf-justify-center",style:{height:o},children:n?U.jsxs("div",{className:"rf-flex rf-w-full rf-items-center rf-justify-center rf-gap-2 rf-bg-zinc-950 rf-text-sm rf-text-zinc-300",style:{height:o},children:[U.jsx(sE,{className:"rf-h-4 rf-w-4 rf-animate-spin"}),"Loading preview..."]}):e?U.jsx("div",{className:"rf-flex rf-w-full rf-items-center rf-justify-center rf-bg-zinc-950 rf-p-4",style:{height:o},children:U.jsxs("div",{className:"rf-flex rf-max-w-[320px] rf-items-start rf-gap-2 rf-text-sm rf-text-zinc-300",children:[U.jsx(pVe,{className:"rf-mt-0.5 rf-h-4 rf-w-4 rf-flex-shrink-0"}),U.jsx("span",{children:e})]})}):t?U.jsx("div",{className:"rf-w-full rf-min-w-0 rf-overflow-hidden",children:U.jsx(cJe,{circuitJson:t,height:o,allowEditing:!1,clickToInteractEnabled:!1,focusOnHover:!1,disablePcbGroups:!0})}):U.jsx("div",{className:"rf-flex rf-w-full rf-items-center rf-justify-center rf-bg-zinc-950 rf-text-sm rf-text-zinc-300",style:{height:o},children:"No preview"})}),Oln={importComponentDialog:101,importComponentDetailsDialog:102},pDi=({packageResult:t,isOpen:e,onOpenChange:n,isLoading:o,details:i,previewTab:r,onPreviewTabChange:s,isSubmitting:a,onImport:A})=>{const c=t?.package??null,l=c?.latest_pcb_preview_image_url,g=c?.latest_sch_preview_image_url,u=c?.latest_cad_preview_image_url,h=c?.unscoped_name?.split("/").pop()??c?.unscoped_name,d=c?.org_owner_tscircuit_handle??void 0,m=d?`https://tscircuit.com/${d}`:void 0,p=d&&h?`https://tscircuit.com/${d}/${h}`:void 0;return U.jsx(YR,{open:e,onOpenChange:n,children:U.jsxs(tw,{showOverlay:!1,style:{width:"calc(100vw - 2rem)",zIndex:Oln.importComponentDetailsDialog},className:"rf-max-w-5xl no-scrollbar !rf-overflow-y-auto rf-max-h-[90vh] rf-overflow-hidden rf-flex rf-flex-col rf-rounded-sm",children:[U.jsx(nw,{className:"rf-pb-4 rf-border-b",children:U.jsx("div",{className:"rf-flex rf-items-start rf-justify-between rf-gap-4",children:U.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[U.jsx(ow,{className:"rf-text-xl rf-font-semibold rf-truncate",children:h}),U.jsx(UR,{children:c?.description})]})})}),U.jsxs("div",{className:"rf-flex-1 rf-overflow-y-auto rf-py-4 rf-space-y-6",children:[d?U.jsxs("div",{children:[U.jsx("span",{className:"rf-text-xs rf-font-medium rf-text-gray-500 rf-uppercase rf-tracking-wide",children:"Created by"}),U.jsx("div",{className:"rf-mt-1 rf-text-sm rf-font-medium",children:m?U.jsx("a",{href:m,target:"_blank",rel:"noopener noreferrer",className:"rf-text-black hover:rf-underline",children:d}):d})]}):null,(u||l||g)&&U.jsx(U.Fragment,{children:U.jsxs("div",{children:[U.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-mb-4",children:"Preview"}),U.jsxs(HMe,{value:r,onValueChange:_=>s(_),children:[U.jsxs(J0e,{className:"rf-inline-flex rf-h-9 rf-items-center rf-justify-center rf-rounded-lg rf-bg-zinc-100 rf-p-1 rf-text-zinc-500 dark:rf-bg-zinc-800 dark:rf-text-zinc-400",children:[l&&U.jsx(U6,{value:"pcb",children:"PCB"}),g&&U.jsx(U6,{value:"schematic",children:"Schematic"}),u&&U.jsx(U6,{value:"3d",children:"3D"})]}),U.jsxs("div",{className:"rf-mt-4",children:[U.jsx(U1,{value:"pcb",className:"rf-border rf-rounded-lg rf-overflow-hidden rf-bg-gray-50",children:l?U.jsx("img",{src:l,alt:`${h??"package"} PCB preview`,className:"rf-w-full rf-h-full rf-object-contain rf-bg-white rf-p-4"}):null}),U.jsx(U1,{value:"schematic",className:"rf-border rf-rounded-lg rf-overflow-hidden rf-bg-gray-50",children:g?U.jsx("img",{src:g,alt:`${h??"package"} schematic preview`,className:"rf-w-full rf-h-full rf-object-contain rf-bg-white rf-p-4"}):null}),U.jsx(U1,{value:"3d",className:"rf-border rf-rounded-lg rf-overflow-hidden rf-bg-gray-50",children:u?U.jsx("img",{src:u,alt:`${h??"package"} 3D preview`,className:"rf-w-full rf-h-full rf-object-contain rf-bg-white rf-p-4"}):null})]})]})]})}),i?.ai_description?U.jsxs("section",{children:[U.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-mb-3",children:"AI Description"}),U.jsx("div",{className:"rf-bg-gray-50 rf-border rf-border-gray-200 rf-rounded-lg rf-p-4",children:U.jsx("p",{className:"rf-text-sm rf-text-gray-700 rf-leading-relaxed",children:i.ai_description})})]}):null,i?.ai_usage_instructions?U.jsxs("section",{children:[U.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-mb-3",children:"Usage Instructions"}),U.jsx("div",{className:"rf-bg-gray-50 rf-border rf-border-gray-200 rf-rounded-lg rf-p-4",children:U.jsx("p",{className:"rf-text-sm rf-text-gray-700 rf-leading-relaxed rf-whitespace-pre-wrap",children:i.ai_usage_instructions})})]}):null,o?U.jsxs("div",{className:"rf-flex rf-justify-center rf-items-center rf-gap-2 rf-text-gray-500",children:[U.jsx(sE,{className:"rf-h-4 rf-w-4 rf-animate-spin"}),U.jsx("span",{className:"rf-text-sm",children:"Loading package details..."})]}):null]}),U.jsxs(MY,{className:"rf-pt-4 rf-border-t rf-flex rf-flex-col sm:rf-flex-row rf-justify-between rf-gap-2",children:[U.jsx("div",{className:"rf-flex-1",children:p?U.jsxs(uA,{variant:"outline",size:"sm",className:"rf-gap-2 rf-w-full sm:rf-w-auto",onClick:()=>window.open(p,"_blank"),children:[U.jsx(n3i,{className:"rf-h-4 rf-w-4"}),"View on tscircuit.com"]}):null}),U.jsxs("div",{className:"rf-flex rf-flex-col sm:rf-flex-row rf-gap-2",children:[U.jsx(uA,{variant:"outline",onClick:()=>n(!1),className:"rf-order-2 sm:rf-order-1",children:"Close"}),U.jsx(uA,{onClick:A,disabled:a,className:"rf-bg-blue-600 hover:rf-bg-blue-700",children:a?U.jsx(sE,{className:"rf-h-4 rf-w-4 rf-animate-spin"}):"Import Component"})]})]})]})})},_Di=()=>{const[t,e]=ee.useState(null),[n,o]=ee.useState(!1),i=ee.useCallback(async(s,a)=>{o(!0);try{const A=await fetch(`https://api.tscircuit.com/packages/get?name=${encodeURIComponent(`${s}/${a}`)}`);if(!A.ok)throw new Error(`Failed to load package details: ${A.status}`);const c=await A.json();e(c.package??null)}catch(A){console.error("Failed to fetch package details",A),e(null)}finally{o(!1)}},[]),r=ee.useCallback(()=>{e(null),o(!1)},[]);return{details:t,isLoading:n,fetchDetails:i,reset:r}},fDi=(t,e)=>{const[n,o]=ee.useState({circuitJson:null,error:null,isLoading:!1});return ee.useEffect(()=>{if(!t||!Lln(t)){o({circuitJson:null,error:null,isLoading:!1});return}let i=!1;return o({circuitJson:null,error:null,isLoading:!0}),aDi(t,e).then(r=>{i||o({circuitJson:r,error:null,isLoading:!1})}).catch(r=>{i||o({circuitJson:null,error:r instanceof Error?r.message:"Failed to load footprint preview",isLoading:!1})}),()=>{i=!0}},[t,e]),n},IDi=async(t,e)=>{const n={"Content-Type":"application/json"};e&&(n.Authorization=`Bearer ${e}`);const o=await fetch("https://registry-api.tscircuit.com/packages/search",{method:"POST",headers:n,body:JSON.stringify({query:t})});if(!o.ok)throw new Error(`tscircuit registry error: ${o.status}`);return(await o.json()).packages??[]},CDi=({sessionToken:t})=>{const[e,n]=ee.useState([]),[o,i]=ee.useState(!1),[r,s]=ee.useState(null),[a,A]=ee.useState(!1),c=ee.useCallback(async g=>{const u=g.trim();if(!u)return[];i(!0),s(null);try{const d=(await IDi(u,t)).map(m=>({source:"tscircuit.com",package:m}));return n(d),d}catch(h){return console.error("Error searching tscircuit packages",h),n([]),s(h instanceof Error?h.message:"Failed to search tscircuit packages"),[]}finally{i(!1),A(!0)}},[t]),l=ee.useCallback(()=>{n([]),i(!1),s(null),A(!1)},[]);return{results:e,isSearching:o,error:r,hasSearched:a,search:c,reset:l}},yDi=t=>{const e=/^C(\d+)$/i.exec(t.trim());if(!e)return null;const n=Number(e[1]);if(!Number.isSafeInteger(n))return null;const o=`C${e[1]}`;return{source:"jlcpcb",component:{lcscId:n,manufacturer:o,partNumber:o,description:"Import directly from EasyEDA; stock and availability are unknown",package:"",isDirectLookup:!0}}},Gln=(t,e)=>{const n=yDi(t);return n?e.some(i=>i.component.partNumber.toUpperCase()===n.component.partNumber)?e:[n,...e]:e},xDi=t=>{const e=t.trim();return/^C\d+/i.test(e)?e.replace(/^C/i,""):e},EDi=()=>{const[t,e]=ee.useState([]),[n,o]=ee.useState(!1),[i,r]=ee.useState(null),[s,a]=ee.useState(!1),A=ee.useCallback(async l=>{const g=xDi(l);if(!g)return[];o(!0),r(null);try{const u=await uMi(g,10),h=Gln(l,u.map(d=>({source:"jlcpcb",component:dMi(d)})));return e(h),h}catch(u){console.error("Error searching JLCPCB components",u);const h=Gln(l,[]);return e(h),r(h.length>0?null:u instanceof Error?u.message:"Failed to search JLCPCB components"),h}finally{o(!1),a(!0)}},[]),c=ee.useCallback(()=>{e([]),o(!1),r(null),a(!1)},[]);return{results:t,isSearching:n,error:i,hasSearched:s,search:A,reset:c}},BDi=()=>{const[t,e]=ee.useState([]),[n,o]=ee.useState(!1),[i,r]=ee.useState(null),[s,a]=ee.useState(!1),A=ee.useCallback(async l=>{const g=l.trim();if(!g)return[];o(!0),r(null);try{const h=(await oDi(g,20)).map(d=>({source:"kicad",footprint:iDi(d)}));return e(h),h}catch(u){return console.error("Error searching KiCad footprints",u),e([]),r(u instanceof Error?u.message:"Failed to search KiCad footprints"),[]}finally{o(!1),a(!0)}},[]),c=ee.useCallback(()=>{e([]),o(!1),r(null),a(!1)},[]);return{results:t,isSearching:n,error:i,hasSearched:s,search:A,reset:c}},SDi=({onTscircuitPackageSelected:t,onJlcpcbComponentTsxLoaded:e,onKicadStringSelected:n})=>{const o=[];return t&&o.push("tscircuit.com"),e&&o.push("jlcpcb"),n&&o.push("kicad"),o},bDi=({isOpen:t,onClose:e,jlcpcbProxyRequestHeaders:n,onKicadStringSelected:o,onTscircuitPackageSelected:i,onJlcpcbComponentTsxLoaded:r,jlcpcbProxyApiBase:s,tscircuitSessionToken:a})=>{E$();const A=ee.useMemo(()=>SDi({onKicadStringSelected:o,onTscircuitPackageSelected:i,onJlcpcbComponentTsxLoaded:r}),[o,i,r]),c=A.length>0,l=A.length===1,[g,u]=ee.useState(A[0]??"tscircuit.com"),[h,d]=ee.useState(""),[m,p]=ee.useState(null),{results:_,isSearching:f,error:I,hasSearched:C,search:y,reset:x}=CDi({sessionToken:a}),{results:E,isSearching:B,error:b,hasSearched:Q,search:w,reset:D}=EDi(),{results:k,isSearching:R,error:H,hasSearched:G,search:K,reset:Y}=BDi(),{details:X,isLoading:te,fetchDetails:j,reset:J}=_Di(),[ie,oe]=ee.useState(null),[ne,le]=ee.useState(!1),[ge,_e]=ee.useState("pcb"),[ce,Ie]=ee.useState(null),[de,Ce]=ee.useState(!1),Pe=ee.useMemo(()=>({jlcpcb:{headers:n,apiBase:s}}),[s,n]),{circuitJson:Qe,error:pe,isLoading:ve}=fDi(m,Pe),Me=Lln(m);ee.useEffect(()=>{Ie(null)},[m]);const we=ee.useCallback(()=>{x(),D(),Y(),p(null)},[D,Y,x]);ee.useEffect(()=>{t||(we(),d(""),le(!1),oe(null),Ie(null))},[t,we]),ee.useEffect(()=>{d(""),p(null),g==="tscircuit.com"?x():g==="jlcpcb"?D():g==="kicad"&&Y()},[g,D,Y,x]);const Oe=We=>{p(We),oe(We),_e("pcb"),le(!0),J();const nt=We.package.org_owner_tscircuit_handle,xt=We.package.unscoped_name;if(nt&&xt){const It=xt.split("/").pop()??xt;j(nt,It)}},Te=async()=>{h.trim()&&(p(null),g==="tscircuit.com"?await y(h):g==="jlcpcb"?await w(h):g==="kicad"&&await K(h))},Se=async We=>{try{if(Ie(null),Ce(!0),We.source==="kicad"){if(!o)throw new Error("KiCad handler not provided");await o({result:We,footprint:We.footprint.qualifiedName})}else if(We.source==="jlcpcb"){if(!r)throw new Error("JLCPCB handler not provided");const nt=await hMi(We.component.partNumber,{headers:n,apiBase:s});await r({result:We,tsx:nt})}else if(We.source==="tscircuit.com"){if(!i)throw new Error("tscircuit package handler not provided");const nt=We.package.org_owner_tscircuit_handle,xt=We.package.unscoped_name;if(!nt||!xt)throw new Error("Missing package metadata");const It=xt.split("/").pop()??xt,Tt=`@tsci/${nt}.${It}`;await i({result:We,fullPackageName:Tt})}return!0}catch(nt){return console.error("Failed to import component",nt),Ie(nt instanceof Error?nt.message:"Failed to import component"),!1}finally{Ce(!1)}};let Le=[],ye=!1,Fe=null,Ye=!1;g==="tscircuit.com"?(Le=_,ye=f,Fe=I,Ye=C):g==="jlcpcb"?(Le=E,ye=B,Fe=b,Ye=Q):g==="kicad"&&(Le=k,ye=R,Fe=H,Ye=G);const qe=async()=>{if(!m)return;await Se(m)&&(e(),we(),d(""))},at=We=>{We||e()},rt=We=>{le(We),We||oe(null)};return U.jsxs(YR,{open:t,onOpenChange:at,children:[U.jsxs(tw,{style:{width:"calc(100vw - 2rem)",maxWidth:Me?"min(1120px, calc(100vw - 2rem))":"min(672px, calc(100vw - 2rem))",zIndex:Oln.importComponentDialog},className:"rf-rounded-sm rf-max-h-[90vh] rf-overflow-y-auto rf-overflow-x-hidden rf-flex rf-flex-col",children:[U.jsxs(nw,{children:[U.jsxs(ow,{className:"rf-text-lg sm:rf-text-xl",children:["Import ",l?Hme[g].label:""," ","Component"]}),U.jsx(UR,{className:"rf-text-sm",children:c?"Search for components from available sources.":"Import options are disabled because no handlers were provided."})]}),c?U.jsxs(HMe,{value:g,onValueChange:We=>u(We),className:"rf-min-w-0 rf-w-full",children:[!l&&U.jsx(J0e,{className:"rf-flex rf-w-full rf-gap-2",children:A.map(We=>U.jsx(U6,{value:We,className:"rf-flex-1 rf-text-xs sm:rf-text-sm",children:Hme[We].label},We))}),U.jsxs("div",{className:"rf-min-w-0",style:Me?{display:"grid",gridTemplateColumns:"minmax(0, 1fr) minmax(360px, 0.95fr)",gap:"1.5rem",alignItems:"start"}:void 0,children:[U.jsxs("div",{className:"rf-min-w-0",children:[U.jsx(ADi,{query:h,placeholder:Hme[g].placeholder,isSearching:ye,onQueryChange:d,onSubmit:Te}),U.jsx("div",{className:"no-scrollbar rf-mt-4 rf-flex-1 rf-min-h-[200px] !rf-max-h-[40vh] !rf-overflow-y-auto rf-overflow-x-hidden rf-border rf-rounded-md rf-min-w-0",children:ye?U.jsxs("div",{className:"rf-p-8 rf-text-center rf-text-zinc-500",children:[U.jsx(sE,{className:"rf-h-8 rf-w-8 rf-animate-spin rf-mx-auto rf-mb-2"}),U.jsx("p",{children:"Searching..."})]}):Le.length>0?U.jsx(hDi,{results:Le,selected:m,onSelect:p,onShowDetails:g==="tscircuit.com"?Oe:void 0}):U.jsx("div",{className:"rf-p-8 rf-text-center rf-text-zinc-500",children:Fe?`Error: ${Fe}`:Ye?Hme[g].emptyMessage:"Enter a search term to find components"})})]}),Me?U.jsx("div",{className:"rf-mt-4",children:U.jsx(mDi,{circuitJson:Qe,error:pe,isLoading:ve,height:325})}):null]})]}):null,ce?U.jsx("div",{className:"rf-text-sm rf-text-red-600 rf-mt-2",children:ce}):null,U.jsxs(MY,{className:"rf-flex rf-flex-col sm:rf-flex-row rf-gap-2",children:[U.jsx(uA,{variant:"outline",onClick:e,className:"rf-order-2 sm:rf-order-1",children:"Cancel"}),U.jsx(uA,{onClick:qe,disabled:!m||de,className:"rf-order-1 sm:rf-order-2",children:de?U.jsx(sE,{className:"rf-h-4 rf-w-4 rf-animate-spin"}):"Import"})]})]}),U.jsx(pDi,{packageResult:ie,isOpen:ne,onOpenChange:rt,isLoading:te,details:X,previewTab:ge,onPreviewTabChange:We=>_e(We),isSubmitting:de,onImport:()=>{ie&&Se(ie).then(We=>{We&&(le(!1),e(),we(),d(""))})}})]})},QDi=t=>{const e=t.match(/export const (\w+) =/);if(!e)throw new Error("Could not determine component name from TSX contents");return e[1]},Yln=t=>{const e=id(s=>s.pushEvent),n=id(s=>s.upsertFile),o=async({result:s,fullPackageName:a})=>{const c=s.package.unscoped_name??s.package.name;await ra.promise(e({event_type:"INSTALL_PACKAGE",full_package_name:a}),{loading:`Requesting install for "${c}"`,success:`Install requested for "${c}"`,error:l=>`Failed to request install: ${l instanceof Error?l.message:String(l)}`})},i=async({footprint:s})=>{await ra.promise(navigator.clipboard.writeText(s),{loading:`Copying "${s}"`,success:`Copied "${s}" to clipboard`,error:a=>`Failed to copy footprint: ${a instanceof Error?a.message:String(a)}`})},r=async({result:s,tsx:a})=>{const c=`imports/${QDi(a)}.tsx`;await ra.promise(n(c,a),{loading:`Importing ${s.component.partNumber}`,success:`Imported to "${c}"`,error:l=>`Failed to import component: ${l instanceof Error?l.message:String(l)}`})};return U.jsx(bDi,{...t,onTscircuitPackageSelected:o,onKicadStringSelected:i,onJlcpcbComponentTsxLoaded:r})};Yln.displayName="ImportComponentDialogForCli";const vDi=async({circuitJson:t,projectName:e})=>{const{convertCircuitJsonToAltiumZip:n}=await Promise.resolve().then(()=>$nr),o=await n(t,e);return new Blob([new Uint8Array(o)],{type:"application/zip"})},PDi=async({circuitJson:t,projectName:e})=>{await ra.promise((async()=>{const n=await vDi({circuitJson:t,projectName:e});_E(n,{fileName:`${e}_altium_project.zip`})})(),{loading:"Generating Altium project...",success:"Altium project ZIP ready",error:n=>`Failed to generate Altium project: ${n instanceof Error?n.message:String(n)}`})};var VJe={exports:{}},Uln;function wDi(){return Uln||(Uln=1,(function(t,e){var n={env:{},version:""};(function(o){t.exports=o()})(function(){return(function o(i,r,s){function a(l,g){if(!r[l]){if(!i[l]){var u=typeof g8=="function"&&g8;if(!g&&u)return u(l,!0);if(A)return A(l,!0);var h=new Error("Cannot find module '"+l+"'");throw h.code="MODULE_NOT_FOUND",h}var d=r[l]={exports:{}};i[l][0].call(d.exports,function(m){var p=i[l][1][m];return a(p||m)},d,d.exports,o,i,r,s)}return r[l].exports}for(var A=typeof g8=="function"&&g8,c=0;c<s.length;c++)a(s[c]);return a})({1:[function(o,i,r){var s=o("./utils"),a=o("./support"),A="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";r.encode=function(c){for(var l,g,u,h,d,m,p,_=[],f=0,I=c.length,C=I,y=s.getTypeOf(c)!=="string";f<c.length;)C=I-f,u=y?(l=c[f++],g=f<I?c[f++]:0,f<I?c[f++]:0):(l=c.charCodeAt(f++),g=f<I?c.charCodeAt(f++):0,f<I?c.charCodeAt(f++):0),h=l>>2,d=(3&l)<<4|g>>4,m=1<C?(15&g)<<2|u>>6:64,p=2<C?63&u:64,_.push(A.charAt(h)+A.charAt(d)+A.charAt(m)+A.charAt(p));return _.join("")},r.decode=function(c){var l,g,u,h,d,m,p=0,_=0,f="data:";if(c.substr(0,f.length)===f)throw new Error("Invalid base64 input, it looks like a data url.");var I,C=3*(c=c.replace(/[^A-Za-z0-9+/=]/g,"")).length/4;if(c.charAt(c.length-1)===A.charAt(64)&&C--,c.charAt(c.length-2)===A.charAt(64)&&C--,C%1!=0)throw new Error("Invalid base64 input, bad content length.");for(I=a.uint8array?new Uint8Array(0|C):new Array(0|C);p<c.length;)l=A.indexOf(c.charAt(p++))<<2|(h=A.indexOf(c.charAt(p++)))>>4,g=(15&h)<<4|(d=A.indexOf(c.charAt(p++)))>>2,u=(3&d)<<6|(m=A.indexOf(c.charAt(p++))),I[_++]=l,d!==64&&(I[_++]=g),m!==64&&(I[_++]=u);return I}},{"./support":30,"./utils":32}],2:[function(o,i,r){var s=o("./external"),a=o("./stream/DataWorker"),A=o("./stream/Crc32Probe"),c=o("./stream/DataLengthProbe");function l(g,u,h,d,m){this.compressedSize=g,this.uncompressedSize=u,this.crc32=h,this.compression=d,this.compressedContent=m}l.prototype={getContentWorker:function(){var g=new a(s.Promise.resolve(this.compressedContent)).pipe(this.compression.uncompressWorker()).pipe(new c("data_length")),u=this;return g.on("end",function(){if(this.streamInfo.data_length!==u.uncompressedSize)throw new Error("Bug : uncompressed data size mismatch")}),g},getCompressedWorker:function(){return new a(s.Promise.resolve(this.compressedContent)).withStreamInfo("compressedSize",this.compressedSize).withStreamInfo("uncompressedSize",this.uncompressedSize).withStreamInfo("crc32",this.crc32).withStreamInfo("compression",this.compression)}},l.createWorkerFrom=function(g,u,h){return g.pipe(new A).pipe(new c("uncompressedSize")).pipe(u.compressWorker(h)).pipe(new c("compressedSize")).withStreamInfo("compression",u)},i.exports=l},{"./external":6,"./stream/Crc32Probe":25,"./stream/DataLengthProbe":26,"./stream/DataWorker":27}],3:[function(o,i,r){var s=o("./stream/GenericWorker");r.STORE={magic:"\0\0",compressWorker:function(){return new s("STORE compression")},uncompressWorker:function(){return new s("STORE decompression")}},r.DEFLATE=o("./flate")},{"./flate":7,"./stream/GenericWorker":28}],4:[function(o,i,r){var s=o("./utils"),a=(function(){for(var A,c=[],l=0;l<256;l++){A=l;for(var g=0;g<8;g++)A=1&A?3988292384^A>>>1:A>>>1;c[l]=A}return c})();i.exports=function(A,c){return A!==void 0&&A.length?s.getTypeOf(A)!=="string"?(function(l,g,u,h){var d=a,m=h+u;l^=-1;for(var p=h;p<m;p++)l=l>>>8^d[255&(l^g[p])];return-1^l})(0|c,A,A.length,0):(function(l,g,u,h){var d=a,m=h+u;l^=-1;for(var p=h;p<m;p++)l=l>>>8^d[255&(l^g.charCodeAt(p))];return-1^l})(0|c,A,A.length,0):0}},{"./utils":32}],5:[function(o,i,r){r.base64=!1,r.binary=!1,r.dir=!1,r.createFolders=!0,r.date=null,r.compression=null,r.compressionOptions=null,r.comment=null,r.unixPermissions=null,r.dosPermissions=null},{}],6:[function(o,i,r){var s=null;s=typeof Promise<"u"?Promise:o("lie"),i.exports={Promise:s}},{lie:37}],7:[function(o,i,r){var s=typeof Uint8Array<"u"&&typeof Uint16Array<"u"&&typeof Uint32Array<"u",a=o("pako"),A=o("./utils"),c=o("./stream/GenericWorker"),l=s?"uint8array":"array";function g(u,h){c.call(this,"FlateWorker/"+u),this._pako=null,this._pakoAction=u,this._pakoOptions=h,this.meta={}}r.magic="\b\0",A.inherits(g,c),g.prototype.processChunk=function(u){this.meta=u.meta,this._pako===null&&this._createPako(),this._pako.push(A.transformTo(l,u.data),!1)},g.prototype.flush=function(){c.prototype.flush.call(this),this._pako===null&&this._createPako(),this._pako.push([],!0)},g.prototype.cleanUp=function(){c.prototype.cleanUp.call(this),this._pako=null},g.prototype._createPako=function(){this._pako=new a[this._pakoAction]({raw:!0,level:this._pakoOptions.level||-1});var u=this;this._pako.onData=function(h){u.push({data:h,meta:u.meta})}},r.compressWorker=function(u){return new g("Deflate",u)},r.uncompressWorker=function(){return new g("Inflate",{})}},{"./stream/GenericWorker":28,"./utils":32,pako:38}],8:[function(o,i,r){function s(d,m){var p,_="";for(p=0;p<m;p++)_+=String.fromCharCode(255&d),d>>>=8;return _}function a(d,m,p,_,f,I){var C,y,x=d.file,E=d.compression,B=I!==l.utf8encode,b=A.transformTo("string",I(x.name)),Q=A.transformTo("string",l.utf8encode(x.name)),w=x.comment,D=A.transformTo("string",I(w)),k=A.transformTo("string",l.utf8encode(w)),R=Q.length!==x.name.length,H=k.length!==w.length,G="",K="",Y="",X=x.dir,te=x.date,j={crc32:0,compressedSize:0,uncompressedSize:0};m&&!p||(j.crc32=d.crc32,j.compressedSize=d.compressedSize,j.uncompressedSize=d.uncompressedSize);var J=0;m&&(J|=8),B||!R&&!H||(J|=2048);var ie=0,oe=0;X&&(ie|=16),f==="UNIX"?(oe=798,ie|=(function(le,ge){var _e=le;return le||(_e=ge?16893:33204),(65535&_e)<<16})(x.unixPermissions,X)):(oe=20,ie|=(function(le){return 63&(le||0)})(x.dosPermissions)),C=te.getUTCHours(),C<<=6,C|=te.getUTCMinutes(),C<<=5,C|=te.getUTCSeconds()/2,y=te.getUTCFullYear()-1980,y<<=4,y|=te.getUTCMonth()+1,y<<=5,y|=te.getUTCDate(),R&&(K=s(1,1)+s(g(b),4)+Q,G+="up"+s(K.length,2)+K),H&&(Y=s(1,1)+s(g(D),4)+k,G+="uc"+s(Y.length,2)+Y);var ne="";return ne+=`
5588
5588
  \0`,ne+=s(J,2),ne+=E.magic,ne+=s(C,2),ne+=s(y,2),ne+=s(j.crc32,4),ne+=s(j.compressedSize,4),ne+=s(j.uncompressedSize,4),ne+=s(b.length,2),ne+=s(G.length,2),{fileRecord:u.LOCAL_FILE_HEADER+ne+b+G,dirRecord:u.CENTRAL_FILE_HEADER+s(oe,2)+ne+s(D.length,2)+"\0\0\0\0"+s(ie,4)+s(_,4)+b+G+D}}var A=o("../utils"),c=o("../stream/GenericWorker"),l=o("../utf8"),g=o("../crc32"),u=o("../signature");function h(d,m,p,_){c.call(this,"ZipFileWorker"),this.bytesWritten=0,this.zipComment=m,this.zipPlatform=p,this.encodeFileName=_,this.streamFiles=d,this.accumulate=!1,this.contentBuffer=[],this.dirRecords=[],this.currentSourceOffset=0,this.entriesCount=0,this.currentFile=null,this._sources=[]}A.inherits(h,c),h.prototype.push=function(d){var m=d.meta.percent||0,p=this.entriesCount,_=this._sources.length;this.accumulate?this.contentBuffer.push(d):(this.bytesWritten+=d.data.length,c.prototype.push.call(this,{data:d.data,meta:{currentFile:this.currentFile,percent:p?(m+100*(p-_-1))/p:100}}))},h.prototype.openedSource=function(d){this.currentSourceOffset=this.bytesWritten,this.currentFile=d.file.name;var m=this.streamFiles&&!d.file.dir;if(m){var p=a(d,m,!1,this.currentSourceOffset,this.zipPlatform,this.encodeFileName);this.push({data:p.fileRecord,meta:{percent:0}})}else this.accumulate=!0},h.prototype.closedSource=function(d){this.accumulate=!1;var m=this.streamFiles&&!d.file.dir,p=a(d,m,!0,this.currentSourceOffset,this.zipPlatform,this.encodeFileName);if(this.dirRecords.push(p.dirRecord),m)this.push({data:(function(_){return u.DATA_DESCRIPTOR+s(_.crc32,4)+s(_.compressedSize,4)+s(_.uncompressedSize,4)})(d),meta:{percent:100}});else for(this.push({data:p.fileRecord,meta:{percent:0}});this.contentBuffer.length;)this.push(this.contentBuffer.shift());this.currentFile=null},h.prototype.flush=function(){for(var d=this.bytesWritten,m=0;m<this.dirRecords.length;m++)this.push({data:this.dirRecords[m],meta:{percent:100}});var p=this.bytesWritten-d,_=(function(f,I,C,y,x){var E=A.transformTo("string",x(y));return u.CENTRAL_DIRECTORY_END+"\0\0\0\0"+s(f,2)+s(f,2)+s(I,4)+s(C,4)+s(E.length,2)+E})(this.dirRecords.length,p,d,this.zipComment,this.encodeFileName);this.push({data:_,meta:{percent:100}})},h.prototype.prepareNextSource=function(){this.previous=this._sources.shift(),this.openedSource(this.previous.streamInfo),this.isPaused?this.previous.pause():this.previous.resume()},h.prototype.registerPrevious=function(d){this._sources.push(d);var m=this;return d.on("data",function(p){m.processChunk(p)}),d.on("end",function(){m.closedSource(m.previous.streamInfo),m._sources.length?m.prepareNextSource():m.end()}),d.on("error",function(p){m.error(p)}),this},h.prototype.resume=function(){return!!c.prototype.resume.call(this)&&(!this.previous&&this._sources.length?(this.prepareNextSource(),!0):this.previous||this._sources.length||this.generatedError?void 0:(this.end(),!0))},h.prototype.error=function(d){var m=this._sources;if(!c.prototype.error.call(this,d))return!1;for(var p=0;p<m.length;p++)try{m[p].error(d)}catch{}return!0},h.prototype.lock=function(){c.prototype.lock.call(this);for(var d=this._sources,m=0;m<d.length;m++)d[m].lock()},i.exports=h},{"../crc32":4,"../signature":23,"../stream/GenericWorker":28,"../utf8":31,"../utils":32}],9:[function(o,i,r){var s=o("../compressions"),a=o("./ZipFileWorker");r.generateWorker=function(A,c,l){var g=new a(c.streamFiles,l,c.platform,c.encodeFileName),u=0;try{A.forEach(function(h,d){u++;var m=(function(I,C){var y=I||C,x=s[y];if(!x)throw new Error(y+" is not a valid compression method !");return x})(d.options.compression,c.compression),p=d.options.compressionOptions||c.compressionOptions||{},_=d.dir,f=d.date;d._compressWorker(m,p).withStreamInfo("file",{name:h,dir:_,date:f,comment:d.comment||"",unixPermissions:d.unixPermissions,dosPermissions:d.dosPermissions}).pipe(g)}),g.entriesCount=u}catch(h){g.error(h)}return g}},{"../compressions":3,"./ZipFileWorker":8}],10:[function(o,i,r){function s(){if(!(this instanceof s))return new s;if(arguments.length)throw new Error("The constructor with parameters has been removed in JSZip 3.0, please check the upgrade guide.");this.files=Object.create(null),this.comment=null,this.root="",this.clone=function(){var a=new s;for(var A in this)typeof this[A]!="function"&&(a[A]=this[A]);return a}}(s.prototype=o("./object")).loadAsync=o("./load"),s.support=o("./support"),s.defaults=o("./defaults"),s.version="3.10.1",s.loadAsync=function(a,A){return new s().loadAsync(a,A)},s.external=o("./external"),i.exports=s},{"./defaults":5,"./external":6,"./load":11,"./object":15,"./support":30}],11:[function(o,i,r){var s=o("./utils"),a=o("./external"),A=o("./utf8"),c=o("./zipEntries"),l=o("./stream/Crc32Probe"),g=o("./nodejsUtils");function u(h){return new a.Promise(function(d,m){var p=h.decompressed.getContentWorker().pipe(new l);p.on("error",function(_){m(_)}).on("end",function(){p.streamInfo.crc32!==h.decompressed.crc32?m(new Error("Corrupted zip : CRC32 mismatch")):d()}).resume()})}i.exports=function(h,d){var m=this;return d=s.extend(d||{},{base64:!1,checkCRC32:!1,optimizedBinaryString:!1,createFolders:!1,decodeFileName:A.utf8decode}),g.isNode&&g.isStream(h)?a.Promise.reject(new Error("JSZip can't accept a stream when loading a zip file.")):s.prepareContent("the loaded zip file",h,!0,d.optimizedBinaryString,d.base64).then(function(p){var _=new c(d);return _.load(p),_}).then(function(p){var _=[a.Promise.resolve(p)],f=p.files;if(d.checkCRC32)for(var I=0;I<f.length;I++)_.push(u(f[I]));return a.Promise.all(_)}).then(function(p){for(var _=p.shift(),f=_.files,I=0;I<f.length;I++){var C=f[I],y=C.fileNameStr,x=s.resolve(C.fileNameStr);m.file(x,C.decompressed,{binary:!0,optimizedBinaryString:!0,date:C.date,dir:C.dir,comment:C.fileCommentStr.length?C.fileCommentStr:null,unixPermissions:C.unixPermissions,dosPermissions:C.dosPermissions,createFolders:d.createFolders}),C.dir||(m.file(x).unsafeOriginalName=y)}return _.zipComment.length&&(m.comment=_.zipComment),m})}},{"./external":6,"./nodejsUtils":14,"./stream/Crc32Probe":25,"./utf8":31,"./utils":32,"./zipEntries":33}],12:[function(o,i,r){var s=o("../utils"),a=o("../stream/GenericWorker");function A(c,l){a.call(this,"Nodejs stream input adapter for "+c),this._upstreamEnded=!1,this._bindStream(l)}s.inherits(A,a),A.prototype._bindStream=function(c){var l=this;(this._stream=c).pause(),c.on("data",function(g){l.push({data:g,meta:{percent:0}})}).on("error",function(g){l.isPaused?this.generatedError=g:l.error(g)}).on("end",function(){l.isPaused?l._upstreamEnded=!0:l.end()})},A.prototype.pause=function(){return!!a.prototype.pause.call(this)&&(this._stream.pause(),!0)},A.prototype.resume=function(){return!!a.prototype.resume.call(this)&&(this._upstreamEnded?this.end():this._stream.resume(),!0)},i.exports=A},{"../stream/GenericWorker":28,"../utils":32}],13:[function(o,i,r){var s=o("readable-stream").Readable;function a(A,c,l){s.call(this,c),this._helper=A;var g=this;A.on("data",function(u,h){g.push(u)||g._helper.pause(),l&&l(h)}).on("error",function(u){g.emit("error",u)}).on("end",function(){g.push(null)})}o("../utils").inherits(a,s),a.prototype._read=function(){this._helper.resume()},i.exports=a},{"../utils":32,"readable-stream":16}],14:[function(o,i,r){i.exports={isNode:typeof Buffer<"u",newBufferFrom:function(s,a){if(Buffer.from&&Buffer.from!==Uint8Array.from)return Buffer.from(s,a);if(typeof s=="number")throw new Error('The "data" argument must not be a number');return new Buffer(s,a)},allocBuffer:function(s){if(Buffer.alloc)return Buffer.alloc(s);var a=new Buffer(s);return a.fill(0),a},isBuffer:function(s){return Buffer.isBuffer(s)},isStream:function(s){return s&&typeof s.on=="function"&&typeof s.pause=="function"&&typeof s.resume=="function"}}},{}],15:[function(o,i,r){function s(x,E,B){var b,Q=A.getTypeOf(E),w=A.extend(B||{},g);w.date=w.date||new Date,w.compression!==null&&(w.compression=w.compression.toUpperCase()),typeof w.unixPermissions=="string"&&(w.unixPermissions=parseInt(w.unixPermissions,8)),w.unixPermissions&&16384&w.unixPermissions&&(w.dir=!0),w.dosPermissions&&16&w.dosPermissions&&(w.dir=!0),w.dir&&(x=f(x)),w.createFolders&&(b=_(x))&&I.call(this,b,!0);var D=Q==="string"&&w.binary===!1&&w.base64===!1;B&&B.binary!==void 0||(w.binary=!D),(E instanceof u&&E.uncompressedSize===0||w.dir||!E||E.length===0)&&(w.base64=!1,w.binary=!0,E="",w.compression="STORE",Q="string");var k=null;k=E instanceof u||E instanceof c?E:m.isNode&&m.isStream(E)?new p(x,E):A.prepareContent(x,E,w.binary,w.optimizedBinaryString,w.base64);var R=new h(x,k,w);this.files[x]=R}var a=o("./utf8"),A=o("./utils"),c=o("./stream/GenericWorker"),l=o("./stream/StreamHelper"),g=o("./defaults"),u=o("./compressedObject"),h=o("./zipObject"),d=o("./generate"),m=o("./nodejsUtils"),p=o("./nodejs/NodejsStreamInputAdapter"),_=function(x){x.slice(-1)==="/"&&(x=x.substring(0,x.length-1));var E=x.lastIndexOf("/");return 0<E?x.substring(0,E):""},f=function(x){return x.slice(-1)!=="/"&&(x+="/"),x},I=function(x,E){return E=E!==void 0?E:g.createFolders,x=f(x),this.files[x]||s.call(this,x,null,{dir:!0,createFolders:E}),this.files[x]};function C(x){return Object.prototype.toString.call(x)==="[object RegExp]"}var y={load:function(){throw new Error("This method has been removed in JSZip 3.0, please check the upgrade guide.")},forEach:function(x){var E,B,b;for(E in this.files)b=this.files[E],(B=E.slice(this.root.length,E.length))&&E.slice(0,this.root.length)===this.root&&x(B,b)},filter:function(x){var E=[];return this.forEach(function(B,b){x(B,b)&&E.push(b)}),E},file:function(x,E,B){if(arguments.length!==1)return x=this.root+x,s.call(this,x,E,B),this;if(C(x)){var b=x;return this.filter(function(w,D){return!D.dir&&b.test(w)})}var Q=this.files[this.root+x];return Q&&!Q.dir?Q:null},folder:function(x){if(!x)return this;if(C(x))return this.filter(function(Q,w){return w.dir&&x.test(Q)});var E=this.root+x,B=I.call(this,E),b=this.clone();return b.root=B.name,b},remove:function(x){x=this.root+x;var E=this.files[x];if(E||(x.slice(-1)!=="/"&&(x+="/"),E=this.files[x]),E&&!E.dir)delete this.files[x];else for(var B=this.filter(function(Q,w){return w.name.slice(0,x.length)===x}),b=0;b<B.length;b++)delete this.files[B[b].name];return this},generate:function(){throw new Error("This method has been removed in JSZip 3.0, please check the upgrade guide.")},generateInternalStream:function(x){var E,B={};try{if((B=A.extend(x||{},{streamFiles:!1,compression:"STORE",compressionOptions:null,type:"",platform:"DOS",comment:null,mimeType:"application/zip",encodeFileName:a.utf8encode})).type=B.type.toLowerCase(),B.compression=B.compression.toUpperCase(),B.type==="binarystring"&&(B.type="string"),!B.type)throw new Error("No output type specified.");A.checkSupport(B.type),B.platform!=="darwin"&&B.platform!=="freebsd"&&B.platform!=="linux"&&B.platform!=="sunos"||(B.platform="UNIX"),B.platform==="win32"&&(B.platform="DOS");var b=B.comment||this.comment||"";E=d.generateWorker(this,B,b)}catch(Q){(E=new c("error")).error(Q)}return new l(E,B.type||"string",B.mimeType)},generateAsync:function(x,E){return this.generateInternalStream(x).accumulate(E)},generateNodeStream:function(x,E){return(x=x||{}).type||(x.type="nodebuffer"),this.generateInternalStream(x).toNodejsStream(E)}};i.exports=y},{"./compressedObject":2,"./defaults":5,"./generate":9,"./nodejs/NodejsStreamInputAdapter":12,"./nodejsUtils":14,"./stream/GenericWorker":28,"./stream/StreamHelper":29,"./utf8":31,"./utils":32,"./zipObject":35}],16:[function(o,i,r){i.exports=o("stream")},{stream:void 0}],17:[function(o,i,r){var s=o("./DataReader");function a(A){s.call(this,A);for(var c=0;c<this.data.length;c++)A[c]=255&A[c]}o("../utils").inherits(a,s),a.prototype.byteAt=function(A){return this.data[this.zero+A]},a.prototype.lastIndexOfSignature=function(A){for(var c=A.charCodeAt(0),l=A.charCodeAt(1),g=A.charCodeAt(2),u=A.charCodeAt(3),h=this.length-4;0<=h;--h)if(this.data[h]===c&&this.data[h+1]===l&&this.data[h+2]===g&&this.data[h+3]===u)return h-this.zero;return-1},a.prototype.readAndCheckSignature=function(A){var c=A.charCodeAt(0),l=A.charCodeAt(1),g=A.charCodeAt(2),u=A.charCodeAt(3),h=this.readData(4);return c===h[0]&&l===h[1]&&g===h[2]&&u===h[3]},a.prototype.readData=function(A){if(this.checkOffset(A),A===0)return[];var c=this.data.slice(this.zero+this.index,this.zero+this.index+A);return this.index+=A,c},i.exports=a},{"../utils":32,"./DataReader":18}],18:[function(o,i,r){var s=o("../utils");function a(A){this.data=A,this.length=A.length,this.index=0,this.zero=0}a.prototype={checkOffset:function(A){this.checkIndex(this.index+A)},checkIndex:function(A){if(this.length<this.zero+A||A<0)throw new Error("End of data reached (data length = "+this.length+", asked index = "+A+"). Corrupted zip ?")},setIndex:function(A){this.checkIndex(A),this.index=A},skip:function(A){this.setIndex(this.index+A)},byteAt:function(){},readInt:function(A){var c,l=0;for(this.checkOffset(A),c=this.index+A-1;c>=this.index;c--)l=(l<<8)+this.byteAt(c);return this.index+=A,l},readString:function(A){return s.transformTo("string",this.readData(A))},readData:function(){},lastIndexOfSignature:function(){},readAndCheckSignature:function(){},readDate:function(){var A=this.readInt(4);return new Date(Date.UTC(1980+(A>>25&127),(A>>21&15)-1,A>>16&31,A>>11&31,A>>5&63,(31&A)<<1))}},i.exports=a},{"../utils":32}],19:[function(o,i,r){var s=o("./Uint8ArrayReader");function a(A){s.call(this,A)}o("../utils").inherits(a,s),a.prototype.readData=function(A){this.checkOffset(A);var c=this.data.slice(this.zero+this.index,this.zero+this.index+A);return this.index+=A,c},i.exports=a},{"../utils":32,"./Uint8ArrayReader":21}],20:[function(o,i,r){var s=o("./DataReader");function a(A){s.call(this,A)}o("../utils").inherits(a,s),a.prototype.byteAt=function(A){return this.data.charCodeAt(this.zero+A)},a.prototype.lastIndexOfSignature=function(A){return this.data.lastIndexOf(A)-this.zero},a.prototype.readAndCheckSignature=function(A){return A===this.readData(4)},a.prototype.readData=function(A){this.checkOffset(A);var c=this.data.slice(this.zero+this.index,this.zero+this.index+A);return this.index+=A,c},i.exports=a},{"../utils":32,"./DataReader":18}],21:[function(o,i,r){var s=o("./ArrayReader");function a(A){s.call(this,A)}o("../utils").inherits(a,s),a.prototype.readData=function(A){if(this.checkOffset(A),A===0)return new Uint8Array(0);var c=this.data.subarray(this.zero+this.index,this.zero+this.index+A);return this.index+=A,c},i.exports=a},{"../utils":32,"./ArrayReader":17}],22:[function(o,i,r){var s=o("../utils"),a=o("../support"),A=o("./ArrayReader"),c=o("./StringReader"),l=o("./NodeBufferReader"),g=o("./Uint8ArrayReader");i.exports=function(u){var h=s.getTypeOf(u);return s.checkSupport(h),h!=="string"||a.uint8array?h==="nodebuffer"?new l(u):a.uint8array?new g(s.transformTo("uint8array",u)):new A(s.transformTo("array",u)):new c(u)}},{"../support":30,"../utils":32,"./ArrayReader":17,"./NodeBufferReader":19,"./StringReader":20,"./Uint8ArrayReader":21}],23:[function(o,i,r){r.LOCAL_FILE_HEADER="PK",r.CENTRAL_FILE_HEADER="PK",r.CENTRAL_DIRECTORY_END="PK",r.ZIP64_CENTRAL_DIRECTORY_LOCATOR="PK\x07",r.ZIP64_CENTRAL_DIRECTORY_END="PK",r.DATA_DESCRIPTOR="PK\x07\b"},{}],24:[function(o,i,r){var s=o("./GenericWorker"),a=o("../utils");function A(c){s.call(this,"ConvertWorker to "+c),this.destType=c}a.inherits(A,s),A.prototype.processChunk=function(c){this.push({data:a.transformTo(this.destType,c.data),meta:c.meta})},i.exports=A},{"../utils":32,"./GenericWorker":28}],25:[function(o,i,r){var s=o("./GenericWorker"),a=o("../crc32");function A(){s.call(this,"Crc32Probe"),this.withStreamInfo("crc32",0)}o("../utils").inherits(A,s),A.prototype.processChunk=function(c){this.streamInfo.crc32=a(c.data,this.streamInfo.crc32||0),this.push(c)},i.exports=A},{"../crc32":4,"../utils":32,"./GenericWorker":28}],26:[function(o,i,r){var s=o("../utils"),a=o("./GenericWorker");function A(c){a.call(this,"DataLengthProbe for "+c),this.propName=c,this.withStreamInfo(c,0)}s.inherits(A,a),A.prototype.processChunk=function(c){if(c){var l=this.streamInfo[this.propName]||0;this.streamInfo[this.propName]=l+c.data.length}a.prototype.processChunk.call(this,c)},i.exports=A},{"../utils":32,"./GenericWorker":28}],27:[function(o,i,r){var s=o("../utils"),a=o("./GenericWorker");function A(c){a.call(this,"DataWorker");var l=this;this.dataIsReady=!1,this.index=0,this.max=0,this.data=null,this.type="",this._tickScheduled=!1,c.then(function(g){l.dataIsReady=!0,l.data=g,l.max=g&&g.length||0,l.type=s.getTypeOf(g),l.isPaused||l._tickAndRepeat()},function(g){l.error(g)})}s.inherits(A,a),A.prototype.cleanUp=function(){a.prototype.cleanUp.call(this),this.data=null},A.prototype.resume=function(){return!!a.prototype.resume.call(this)&&(!this._tickScheduled&&this.dataIsReady&&(this._tickScheduled=!0,s.delay(this._tickAndRepeat,[],this)),!0)},A.prototype._tickAndRepeat=function(){this._tickScheduled=!1,this.isPaused||this.isFinished||(this._tick(),this.isFinished||(s.delay(this._tickAndRepeat,[],this),this._tickScheduled=!0))},A.prototype._tick=function(){if(this.isPaused||this.isFinished)return!1;var c=null,l=Math.min(this.max,this.index+16384);if(this.index>=this.max)return this.end();switch(this.type){case"string":c=this.data.substring(this.index,l);break;case"uint8array":c=this.data.subarray(this.index,l);break;case"array":case"nodebuffer":c=this.data.slice(this.index,l)}return this.index=l,this.push({data:c,meta:{percent:this.max?this.index/this.max*100:0}})},i.exports=A},{"../utils":32,"./GenericWorker":28}],28:[function(o,i,r){function s(a){this.name=a||"default",this.streamInfo={},this.generatedError=null,this.extraStreamInfo={},this.isPaused=!0,this.isFinished=!1,this.isLocked=!1,this._listeners={data:[],end:[],error:[]},this.previous=null}s.prototype={push:function(a){this.emit("data",a)},end:function(){if(this.isFinished)return!1;this.flush();try{this.emit("end"),this.cleanUp(),this.isFinished=!0}catch(a){this.emit("error",a)}return!0},error:function(a){return!this.isFinished&&(this.isPaused?this.generatedError=a:(this.isFinished=!0,this.emit("error",a),this.previous&&this.previous.error(a),this.cleanUp()),!0)},on:function(a,A){return this._listeners[a].push(A),this},cleanUp:function(){this.streamInfo=this.generatedError=this.extraStreamInfo=null,this._listeners=[]},emit:function(a,A){if(this._listeners[a])for(var c=0;c<this._listeners[a].length;c++)this._listeners[a][c].call(this,A)},pipe:function(a){return a.registerPrevious(this)},registerPrevious:function(a){if(this.isLocked)throw new Error("The stream '"+this+"' has already been used.");this.streamInfo=a.streamInfo,this.mergeStreamInfo(),this.previous=a;var A=this;return a.on("data",function(c){A.processChunk(c)}),a.on("end",function(){A.end()}),a.on("error",function(c){A.error(c)}),this},pause:function(){return!this.isPaused&&!this.isFinished&&(this.isPaused=!0,this.previous&&this.previous.pause(),!0)},resume:function(){if(!this.isPaused||this.isFinished)return!1;var a=this.isPaused=!1;return this.generatedError&&(this.error(this.generatedError),a=!0),this.previous&&this.previous.resume(),!a},flush:function(){},processChunk:function(a){this.push(a)},withStreamInfo:function(a,A){return this.extraStreamInfo[a]=A,this.mergeStreamInfo(),this},mergeStreamInfo:function(){for(var a in this.extraStreamInfo)Object.prototype.hasOwnProperty.call(this.extraStreamInfo,a)&&(this.streamInfo[a]=this.extraStreamInfo[a])},lock:function(){if(this.isLocked)throw new Error("The stream '"+this+"' has already been used.");this.isLocked=!0,this.previous&&this.previous.lock()},toString:function(){var a="Worker "+this.name;return this.previous?this.previous+" -> "+a:a}},i.exports=s},{}],29:[function(o,i,r){var s=o("../utils"),a=o("./ConvertWorker"),A=o("./GenericWorker"),c=o("../base64"),l=o("../support"),g=o("../external"),u=null;if(l.nodestream)try{u=o("../nodejs/NodejsStreamOutputAdapter")}catch{}function h(m,p){return new g.Promise(function(_,f){var I=[],C=m._internalType,y=m._outputType,x=m._mimeType;m.on("data",function(E,B){I.push(E),p&&p(B)}).on("error",function(E){I=[],f(E)}).on("end",function(){try{var E=(function(B,b,Q){switch(B){case"blob":return s.newBlob(s.transformTo("arraybuffer",b),Q);case"base64":return c.encode(b);default:return s.transformTo(B,b)}})(y,(function(B,b){var Q,w=0,D=null,k=0;for(Q=0;Q<b.length;Q++)k+=b[Q].length;switch(B){case"string":return b.join("");case"array":return Array.prototype.concat.apply([],b);case"uint8array":for(D=new Uint8Array(k),Q=0;Q<b.length;Q++)D.set(b[Q],w),w+=b[Q].length;return D;case"nodebuffer":return Buffer.concat(b);default:throw new Error("concat : unsupported type '"+B+"'")}})(C,I),x);_(E)}catch(B){f(B)}I=[]}).resume()})}function d(m,p,_){var f=p;switch(p){case"blob":case"arraybuffer":f="uint8array";break;case"base64":f="string"}try{this._internalType=f,this._outputType=p,this._mimeType=_,s.checkSupport(f),this._worker=m.pipe(new a(f)),m.lock()}catch(I){this._worker=new A("error"),this._worker.error(I)}}d.prototype={accumulate:function(m){return h(this,m)},on:function(m,p){var _=this;return m==="data"?this._worker.on(m,function(f){p.call(_,f.data,f.meta)}):this._worker.on(m,function(){s.delay(p,arguments,_)}),this},resume:function(){return s.delay(this._worker.resume,[],this._worker),this},pause:function(){return this._worker.pause(),this},toNodejsStream:function(m){if(s.checkSupport("nodestream"),this._outputType!=="nodebuffer")throw new Error(this._outputType+" is not supported by this method");return new u(this,{objectMode:this._outputType!=="nodebuffer"},m)}},i.exports=d},{"../base64":1,"../external":6,"../nodejs/NodejsStreamOutputAdapter":13,"../support":30,"../utils":32,"./ConvertWorker":24,"./GenericWorker":28}],30:[function(o,i,r){if(r.base64=!0,r.array=!0,r.string=!0,r.arraybuffer=typeof ArrayBuffer<"u"&&typeof Uint8Array<"u",r.nodebuffer=typeof Buffer<"u",r.uint8array=typeof Uint8Array<"u",typeof ArrayBuffer>"u")r.blob=!1;else{var s=new ArrayBuffer(0);try{r.blob=new Blob([s],{type:"application/zip"}).size===0}catch{try{var a=new(self.BlobBuilder||self.WebKitBlobBuilder||self.MozBlobBuilder||self.MSBlobBuilder);a.append(s),r.blob=a.getBlob("application/zip").size===0}catch{r.blob=!1}}}try{r.nodestream=!!o("readable-stream").Readable}catch{r.nodestream=!1}},{"readable-stream":16}],31:[function(o,i,r){for(var s=o("./utils"),a=o("./support"),A=o("./nodejsUtils"),c=o("./stream/GenericWorker"),l=new Array(256),g=0;g<256;g++)l[g]=252<=g?6:248<=g?5:240<=g?4:224<=g?3:192<=g?2:1;l[254]=l[254]=1;function u(){c.call(this,"utf-8 decode"),this.leftOver=null}function h(){c.call(this,"utf-8 encode")}r.utf8encode=function(d){return a.nodebuffer?A.newBufferFrom(d,"utf-8"):(function(m){var p,_,f,I,C,y=m.length,x=0;for(I=0;I<y;I++)(64512&(_=m.charCodeAt(I)))==55296&&I+1<y&&(64512&(f=m.charCodeAt(I+1)))==56320&&(_=65536+(_-55296<<10)+(f-56320),I++),x+=_<128?1:_<2048?2:_<65536?3:4;for(p=a.uint8array?new Uint8Array(x):new Array(x),I=C=0;C<x;I++)(64512&(_=m.charCodeAt(I)))==55296&&I+1<y&&(64512&(f=m.charCodeAt(I+1)))==56320&&(_=65536+(_-55296<<10)+(f-56320),I++),_<128?p[C++]=_:(_<2048?p[C++]=192|_>>>6:(_<65536?p[C++]=224|_>>>12:(p[C++]=240|_>>>18,p[C++]=128|_>>>12&63),p[C++]=128|_>>>6&63),p[C++]=128|63&_);return p})(d)},r.utf8decode=function(d){return a.nodebuffer?s.transformTo("nodebuffer",d).toString("utf-8"):(function(m){var p,_,f,I,C=m.length,y=new Array(2*C);for(p=_=0;p<C;)if((f=m[p++])<128)y[_++]=f;else if(4<(I=l[f]))y[_++]=65533,p+=I-1;else{for(f&=I===2?31:I===3?15:7;1<I&&p<C;)f=f<<6|63&m[p++],I--;1<I?y[_++]=65533:f<65536?y[_++]=f:(f-=65536,y[_++]=55296|f>>10&1023,y[_++]=56320|1023&f)}return y.length!==_&&(y.subarray?y=y.subarray(0,_):y.length=_),s.applyFromCharCode(y)})(d=s.transformTo(a.uint8array?"uint8array":"array",d))},s.inherits(u,c),u.prototype.processChunk=function(d){var m=s.transformTo(a.uint8array?"uint8array":"array",d.data);if(this.leftOver&&this.leftOver.length){if(a.uint8array){var p=m;(m=new Uint8Array(p.length+this.leftOver.length)).set(this.leftOver,0),m.set(p,this.leftOver.length)}else m=this.leftOver.concat(m);this.leftOver=null}var _=(function(I,C){var y;for((C=C||I.length)>I.length&&(C=I.length),y=C-1;0<=y&&(192&I[y])==128;)y--;return y<0||y===0?C:y+l[I[y]]>C?y:C})(m),f=m;_!==m.length&&(a.uint8array?(f=m.subarray(0,_),this.leftOver=m.subarray(_,m.length)):(f=m.slice(0,_),this.leftOver=m.slice(_,m.length))),this.push({data:r.utf8decode(f),meta:d.meta})},u.prototype.flush=function(){this.leftOver&&this.leftOver.length&&(this.push({data:r.utf8decode(this.leftOver),meta:{}}),this.leftOver=null)},r.Utf8DecodeWorker=u,s.inherits(h,c),h.prototype.processChunk=function(d){this.push({data:r.utf8encode(d.data),meta:d.meta})},r.Utf8EncodeWorker=h},{"./nodejsUtils":14,"./stream/GenericWorker":28,"./support":30,"./utils":32}],32:[function(o,i,r){var s=o("./support"),a=o("./base64"),A=o("./nodejsUtils"),c=o("./external");function l(p){return p}function g(p,_){for(var f=0;f<p.length;++f)_[f]=255&p.charCodeAt(f);return _}o("setimmediate"),r.newBlob=function(p,_){r.checkSupport("blob");try{return new Blob([p],{type:_})}catch{try{var f=new(self.BlobBuilder||self.WebKitBlobBuilder||self.MozBlobBuilder||self.MSBlobBuilder);return f.append(p),f.getBlob(_)}catch{throw new Error("Bug : can't construct the Blob.")}}};var u={stringifyByChunk:function(p,_,f){var I=[],C=0,y=p.length;if(y<=f)return String.fromCharCode.apply(null,p);for(;C<y;)_==="array"||_==="nodebuffer"?I.push(String.fromCharCode.apply(null,p.slice(C,Math.min(C+f,y)))):I.push(String.fromCharCode.apply(null,p.subarray(C,Math.min(C+f,y)))),C+=f;return I.join("")},stringifyByChar:function(p){for(var _="",f=0;f<p.length;f++)_+=String.fromCharCode(p[f]);return _},applyCanBeUsed:{uint8array:(function(){try{return s.uint8array&&String.fromCharCode.apply(null,new Uint8Array(1)).length===1}catch{return!1}})(),nodebuffer:(function(){try{return s.nodebuffer&&String.fromCharCode.apply(null,A.allocBuffer(1)).length===1}catch{return!1}})()}};function h(p){var _=65536,f=r.getTypeOf(p),I=!0;if(f==="uint8array"?I=u.applyCanBeUsed.uint8array:f==="nodebuffer"&&(I=u.applyCanBeUsed.nodebuffer),I)for(;1<_;)try{return u.stringifyByChunk(p,f,_)}catch{_=Math.floor(_/2)}return u.stringifyByChar(p)}function d(p,_){for(var f=0;f<p.length;f++)_[f]=p[f];return _}r.applyFromCharCode=h;var m={};m.string={string:l,array:function(p){return g(p,new Array(p.length))},arraybuffer:function(p){return m.string.uint8array(p).buffer},uint8array:function(p){return g(p,new Uint8Array(p.length))},nodebuffer:function(p){return g(p,A.allocBuffer(p.length))}},m.array={string:h,array:l,arraybuffer:function(p){return new Uint8Array(p).buffer},uint8array:function(p){return new Uint8Array(p)},nodebuffer:function(p){return A.newBufferFrom(p)}},m.arraybuffer={string:function(p){return h(new Uint8Array(p))},array:function(p){return d(new Uint8Array(p),new Array(p.byteLength))},arraybuffer:l,uint8array:function(p){return new Uint8Array(p)},nodebuffer:function(p){return A.newBufferFrom(new Uint8Array(p))}},m.uint8array={string:h,array:function(p){return d(p,new Array(p.length))},arraybuffer:function(p){return p.buffer},uint8array:l,nodebuffer:function(p){return A.newBufferFrom(p)}},m.nodebuffer={string:h,array:function(p){return d(p,new Array(p.length))},arraybuffer:function(p){return m.nodebuffer.uint8array(p).buffer},uint8array:function(p){return d(p,new Uint8Array(p.length))},nodebuffer:l},r.transformTo=function(p,_){if(_=_||"",!p)return _;r.checkSupport(p);var f=r.getTypeOf(_);return m[f][p](_)},r.resolve=function(p){for(var _=p.split("/"),f=[],I=0;I<_.length;I++){var C=_[I];C==="."||C===""&&I!==0&&I!==_.length-1||(C===".."?f.pop():f.push(C))}return f.join("/")},r.getTypeOf=function(p){return typeof p=="string"?"string":Object.prototype.toString.call(p)==="[object Array]"?"array":s.nodebuffer&&A.isBuffer(p)?"nodebuffer":s.uint8array&&p instanceof Uint8Array?"uint8array":s.arraybuffer&&p instanceof ArrayBuffer?"arraybuffer":void 0},r.checkSupport=function(p){if(!s[p.toLowerCase()])throw new Error(p+" is not supported by this platform")},r.MAX_VALUE_16BITS=65535,r.MAX_VALUE_32BITS=-1,r.pretty=function(p){var _,f,I="";for(f=0;f<(p||"").length;f++)I+="\\x"+((_=p.charCodeAt(f))<16?"0":"")+_.toString(16).toUpperCase();return I},r.delay=function(p,_,f){setImmediate(function(){p.apply(f||null,_||[])})},r.inherits=function(p,_){function f(){}f.prototype=_.prototype,p.prototype=new f},r.extend=function(){var p,_,f={};for(p=0;p<arguments.length;p++)for(_ in arguments[p])Object.prototype.hasOwnProperty.call(arguments[p],_)&&f[_]===void 0&&(f[_]=arguments[p][_]);return f},r.prepareContent=function(p,_,f,I,C){return c.Promise.resolve(_).then(function(y){return s.blob&&(y instanceof Blob||["[object File]","[object Blob]"].indexOf(Object.prototype.toString.call(y))!==-1)&&typeof FileReader<"u"?new c.Promise(function(x,E){var B=new FileReader;B.onload=function(b){x(b.target.result)},B.onerror=function(b){E(b.target.error)},B.readAsArrayBuffer(y)}):y}).then(function(y){var x=r.getTypeOf(y);return x?(x==="arraybuffer"?y=r.transformTo("uint8array",y):x==="string"&&(C?y=a.decode(y):f&&I!==!0&&(y=(function(E){return g(E,s.uint8array?new Uint8Array(E.length):new Array(E.length))})(y))),y):c.Promise.reject(new Error("Can't read the data of '"+p+"'. Is it in a supported JavaScript type (String, Blob, ArrayBuffer, etc) ?"))})}},{"./base64":1,"./external":6,"./nodejsUtils":14,"./support":30,setimmediate:54}],33:[function(o,i,r){var s=o("./reader/readerFor"),a=o("./utils"),A=o("./signature"),c=o("./zipEntry"),l=o("./support");function g(u){this.files=[],this.loadOptions=u}g.prototype={checkSignature:function(u){if(!this.reader.readAndCheckSignature(u)){this.reader.index-=4;var h=this.reader.readString(4);throw new Error("Corrupted zip or bug: unexpected signature ("+a.pretty(h)+", expected "+a.pretty(u)+")")}},isSignature:function(u,h){var d=this.reader.index;this.reader.setIndex(u);var m=this.reader.readString(4)===h;return this.reader.setIndex(d),m},readBlockEndOfCentral:function(){this.diskNumber=this.reader.readInt(2),this.diskWithCentralDirStart=this.reader.readInt(2),this.centralDirRecordsOnThisDisk=this.reader.readInt(2),this.centralDirRecords=this.reader.readInt(2),this.centralDirSize=this.reader.readInt(4),this.centralDirOffset=this.reader.readInt(4),this.zipCommentLength=this.reader.readInt(2);var u=this.reader.readData(this.zipCommentLength),h=l.uint8array?"uint8array":"array",d=a.transformTo(h,u);this.zipComment=this.loadOptions.decodeFileName(d)},readBlockZip64EndOfCentral:function(){this.zip64EndOfCentralSize=this.reader.readInt(8),this.reader.skip(4),this.diskNumber=this.reader.readInt(4),this.diskWithCentralDirStart=this.reader.readInt(4),this.centralDirRecordsOnThisDisk=this.reader.readInt(8),this.centralDirRecords=this.reader.readInt(8),this.centralDirSize=this.reader.readInt(8),this.centralDirOffset=this.reader.readInt(8),this.zip64ExtensibleData={};for(var u,h,d,m=this.zip64EndOfCentralSize-44;0<m;)u=this.reader.readInt(2),h=this.reader.readInt(4),d=this.reader.readData(h),this.zip64ExtensibleData[u]={id:u,length:h,value:d}},readBlockZip64EndOfCentralLocator:function(){if(this.diskWithZip64CentralDirStart=this.reader.readInt(4),this.relativeOffsetEndOfZip64CentralDir=this.reader.readInt(8),this.disksCount=this.reader.readInt(4),1<this.disksCount)throw new Error("Multi-volumes zip are not supported")},readLocalFiles:function(){var u,h;for(u=0;u<this.files.length;u++)h=this.files[u],this.reader.setIndex(h.localHeaderOffset),this.checkSignature(A.LOCAL_FILE_HEADER),h.readLocalPart(this.reader),h.handleUTF8(),h.processAttributes()},readCentralDir:function(){var u;for(this.reader.setIndex(this.centralDirOffset);this.reader.readAndCheckSignature(A.CENTRAL_FILE_HEADER);)(u=new c({zip64:this.zip64},this.loadOptions)).readCentralPart(this.reader),this.files.push(u);if(this.centralDirRecords!==this.files.length&&this.centralDirRecords!==0&&this.files.length===0)throw new Error("Corrupted zip or bug: expected "+this.centralDirRecords+" records in central dir, got "+this.files.length)},readEndOfCentral:function(){var u=this.reader.lastIndexOfSignature(A.CENTRAL_DIRECTORY_END);if(u<0)throw this.isSignature(0,A.LOCAL_FILE_HEADER)?new Error("Corrupted zip: can't find end of central directory"):new Error("Can't find end of central directory : is this a zip file ? If it is, see https://stuk.github.io/jszip/documentation/howto/read_zip.html");this.reader.setIndex(u);var h=u;if(this.checkSignature(A.CENTRAL_DIRECTORY_END),this.readBlockEndOfCentral(),this.diskNumber===a.MAX_VALUE_16BITS||this.diskWithCentralDirStart===a.MAX_VALUE_16BITS||this.centralDirRecordsOnThisDisk===a.MAX_VALUE_16BITS||this.centralDirRecords===a.MAX_VALUE_16BITS||this.centralDirSize===a.MAX_VALUE_32BITS||this.centralDirOffset===a.MAX_VALUE_32BITS){if(this.zip64=!0,(u=this.reader.lastIndexOfSignature(A.ZIP64_CENTRAL_DIRECTORY_LOCATOR))<0)throw new Error("Corrupted zip: can't find the ZIP64 end of central directory locator");if(this.reader.setIndex(u),this.checkSignature(A.ZIP64_CENTRAL_DIRECTORY_LOCATOR),this.readBlockZip64EndOfCentralLocator(),!this.isSignature(this.relativeOffsetEndOfZip64CentralDir,A.ZIP64_CENTRAL_DIRECTORY_END)&&(this.relativeOffsetEndOfZip64CentralDir=this.reader.lastIndexOfSignature(A.ZIP64_CENTRAL_DIRECTORY_END),this.relativeOffsetEndOfZip64CentralDir<0))throw new Error("Corrupted zip: can't find the ZIP64 end of central directory");this.reader.setIndex(this.relativeOffsetEndOfZip64CentralDir),this.checkSignature(A.ZIP64_CENTRAL_DIRECTORY_END),this.readBlockZip64EndOfCentral()}var d=this.centralDirOffset+this.centralDirSize;this.zip64&&(d+=20,d+=12+this.zip64EndOfCentralSize);var m=h-d;if(0<m)this.isSignature(h,A.CENTRAL_FILE_HEADER)||(this.reader.zero=m);else if(m<0)throw new Error("Corrupted zip: missing "+Math.abs(m)+" bytes.")},prepareReader:function(u){this.reader=s(u)},load:function(u){this.prepareReader(u),this.readEndOfCentral(),this.readCentralDir(),this.readLocalFiles()}},i.exports=g},{"./reader/readerFor":22,"./signature":23,"./support":30,"./utils":32,"./zipEntry":34}],34:[function(o,i,r){var s=o("./reader/readerFor"),a=o("./utils"),A=o("./compressedObject"),c=o("./crc32"),l=o("./utf8"),g=o("./compressions"),u=o("./support");function h(d,m){this.options=d,this.loadOptions=m}h.prototype={isEncrypted:function(){return(1&this.bitFlag)==1},useUTF8:function(){return(2048&this.bitFlag)==2048},readLocalPart:function(d){var m,p;if(d.skip(22),this.fileNameLength=d.readInt(2),p=d.readInt(2),this.fileName=d.readData(this.fileNameLength),d.skip(p),this.compressedSize===-1||this.uncompressedSize===-1)throw new Error("Bug or corrupted zip : didn't get enough information from the central directory (compressedSize === -1 || uncompressedSize === -1)");if((m=(function(_){for(var f in g)if(Object.prototype.hasOwnProperty.call(g,f)&&g[f].magic===_)return g[f];return null})(this.compressionMethod))===null)throw new Error("Corrupted zip : compression "+a.pretty(this.compressionMethod)+" unknown (inner file : "+a.transformTo("string",this.fileName)+")");this.decompressed=new A(this.compressedSize,this.uncompressedSize,this.crc32,m,d.readData(this.compressedSize))},readCentralPart:function(d){this.versionMadeBy=d.readInt(2),d.skip(2),this.bitFlag=d.readInt(2),this.compressionMethod=d.readString(2),this.date=d.readDate(),this.crc32=d.readInt(4),this.compressedSize=d.readInt(4),this.uncompressedSize=d.readInt(4);var m=d.readInt(2);if(this.extraFieldsLength=d.readInt(2),this.fileCommentLength=d.readInt(2),this.diskNumberStart=d.readInt(2),this.internalFileAttributes=d.readInt(2),this.externalFileAttributes=d.readInt(4),this.localHeaderOffset=d.readInt(4),this.isEncrypted())throw new Error("Encrypted zip are not supported");d.skip(m),this.readExtraFields(d),this.parseZIP64ExtraField(d),this.fileComment=d.readData(this.fileCommentLength)},processAttributes:function(){this.unixPermissions=null,this.dosPermissions=null;var d=this.versionMadeBy>>8;this.dir=!!(16&this.externalFileAttributes),d==0&&(this.dosPermissions=63&this.externalFileAttributes),d==3&&(this.unixPermissions=this.externalFileAttributes>>16&65535),this.dir||this.fileNameStr.slice(-1)!=="/"||(this.dir=!0)},parseZIP64ExtraField:function(){if(this.extraFields[1]){var d=s(this.extraFields[1].value);this.uncompressedSize===a.MAX_VALUE_32BITS&&(this.uncompressedSize=d.readInt(8)),this.compressedSize===a.MAX_VALUE_32BITS&&(this.compressedSize=d.readInt(8)),this.localHeaderOffset===a.MAX_VALUE_32BITS&&(this.localHeaderOffset=d.readInt(8)),this.diskNumberStart===a.MAX_VALUE_32BITS&&(this.diskNumberStart=d.readInt(4))}},readExtraFields:function(d){var m,p,_,f=d.index+this.extraFieldsLength;for(this.extraFields||(this.extraFields={});d.index+4<f;)m=d.readInt(2),p=d.readInt(2),_=d.readData(p),this.extraFields[m]={id:m,length:p,value:_};d.setIndex(f)},handleUTF8:function(){var d=u.uint8array?"uint8array":"array";if(this.useUTF8())this.fileNameStr=l.utf8decode(this.fileName),this.fileCommentStr=l.utf8decode(this.fileComment);else{var m=this.findExtraFieldUnicodePath();if(m!==null)this.fileNameStr=m;else{var p=a.transformTo(d,this.fileName);this.fileNameStr=this.loadOptions.decodeFileName(p)}var _=this.findExtraFieldUnicodeComment();if(_!==null)this.fileCommentStr=_;else{var f=a.transformTo(d,this.fileComment);this.fileCommentStr=this.loadOptions.decodeFileName(f)}}},findExtraFieldUnicodePath:function(){var d=this.extraFields[28789];if(d){var m=s(d.value);return m.readInt(1)!==1||c(this.fileName)!==m.readInt(4)?null:l.utf8decode(m.readData(d.length-5))}return null},findExtraFieldUnicodeComment:function(){var d=this.extraFields[25461];if(d){var m=s(d.value);return m.readInt(1)!==1||c(this.fileComment)!==m.readInt(4)?null:l.utf8decode(m.readData(d.length-5))}return null}},i.exports=h},{"./compressedObject":2,"./compressions":3,"./crc32":4,"./reader/readerFor":22,"./support":30,"./utf8":31,"./utils":32}],35:[function(o,i,r){function s(m,p,_){this.name=m,this.dir=_.dir,this.date=_.date,this.comment=_.comment,this.unixPermissions=_.unixPermissions,this.dosPermissions=_.dosPermissions,this._data=p,this._dataBinary=_.binary,this.options={compression:_.compression,compressionOptions:_.compressionOptions}}var a=o("./stream/StreamHelper"),A=o("./stream/DataWorker"),c=o("./utf8"),l=o("./compressedObject"),g=o("./stream/GenericWorker");s.prototype={internalStream:function(m){var p=null,_="string";try{if(!m)throw new Error("No output type specified.");var f=(_=m.toLowerCase())==="string"||_==="text";_!=="binarystring"&&_!=="text"||(_="string"),p=this._decompressWorker();var I=!this._dataBinary;I&&!f&&(p=p.pipe(new c.Utf8EncodeWorker)),!I&&f&&(p=p.pipe(new c.Utf8DecodeWorker))}catch(C){(p=new g("error")).error(C)}return new a(p,_,"")},async:function(m,p){return this.internalStream(m).accumulate(p)},nodeStream:function(m,p){return this.internalStream(m||"nodebuffer").toNodejsStream(p)},_compressWorker:function(m,p){if(this._data instanceof l&&this._data.compression.magic===m.magic)return this._data.getCompressedWorker();var _=this._decompressWorker();return this._dataBinary||(_=_.pipe(new c.Utf8EncodeWorker)),l.createWorkerFrom(_,m,p)},_decompressWorker:function(){return this._data instanceof l?this._data.getContentWorker():this._data instanceof g?this._data:new A(this._data)}};for(var u=["asText","asBinary","asNodeBuffer","asUint8Array","asArrayBuffer"],h=function(){throw new Error("This method has been removed in JSZip 3.0, please check the upgrade guide.")},d=0;d<u.length;d++)s.prototype[u[d]]=h;i.exports=s},{"./compressedObject":2,"./stream/DataWorker":27,"./stream/GenericWorker":28,"./stream/StreamHelper":29,"./utf8":31}],36:[function(o,i,r){(function(s){var a,A,c=s.MutationObserver||s.WebKitMutationObserver;if(c){var l=0,g=new c(m),u=s.document.createTextNode("");g.observe(u,{characterData:!0}),a=function(){u.data=l=++l%2}}else if(s.setImmediate||s.MessageChannel===void 0)a="document"in s&&"onreadystatechange"in s.document.createElement("script")?function(){var p=s.document.createElement("script");p.onreadystatechange=function(){m(),p.onreadystatechange=null,p.parentNode.removeChild(p),p=null},s.document.documentElement.appendChild(p)}:function(){setTimeout(m,0)};else{var h=new s.MessageChannel;h.port1.onmessage=m,a=function(){h.port2.postMessage(0)}}var d=[];function m(){var p,_;A=!0;for(var f=d.length;f;){for(_=d,d=[],p=-1;++p<f;)_[p]();f=d.length}A=!1}i.exports=function(p){d.push(p)!==1||A||a()}}).call(this,typeof jC<"u"?jC:typeof self<"u"?self:typeof window<"u"?window:{})},{}],37:[function(o,i,r){var s=o("immediate");function a(){}var A={},c=["REJECTED"],l=["FULFILLED"],g=["PENDING"];function u(f){if(typeof f!="function")throw new TypeError("resolver must be a function");this.state=g,this.queue=[],this.outcome=void 0,f!==a&&p(this,f)}function h(f,I,C){this.promise=f,typeof I=="function"&&(this.onFulfilled=I,this.callFulfilled=this.otherCallFulfilled),typeof C=="function"&&(this.onRejected=C,this.callRejected=this.otherCallRejected)}function d(f,I,C){s(function(){var y;try{y=I(C)}catch(x){return A.reject(f,x)}y===f?A.reject(f,new TypeError("Cannot resolve promise with itself")):A.resolve(f,y)})}function m(f){var I=f&&f.then;if(f&&(typeof f=="object"||typeof f=="function")&&typeof I=="function")return function(){I.apply(f,arguments)}}function p(f,I){var C=!1;function y(B){C||(C=!0,A.reject(f,B))}function x(B){C||(C=!0,A.resolve(f,B))}var E=_(function(){I(x,y)});E.status==="error"&&y(E.value)}function _(f,I){var C={};try{C.value=f(I),C.status="success"}catch(y){C.status="error",C.value=y}return C}(i.exports=u).prototype.finally=function(f){if(typeof f!="function")return this;var I=this.constructor;return this.then(function(C){return I.resolve(f()).then(function(){return C})},function(C){return I.resolve(f()).then(function(){throw C})})},u.prototype.catch=function(f){return this.then(null,f)},u.prototype.then=function(f,I){if(typeof f!="function"&&this.state===l||typeof I!="function"&&this.state===c)return this;var C=new this.constructor(a);return this.state!==g?d(C,this.state===l?f:I,this.outcome):this.queue.push(new h(C,f,I)),C},h.prototype.callFulfilled=function(f){A.resolve(this.promise,f)},h.prototype.otherCallFulfilled=function(f){d(this.promise,this.onFulfilled,f)},h.prototype.callRejected=function(f){A.reject(this.promise,f)},h.prototype.otherCallRejected=function(f){d(this.promise,this.onRejected,f)},A.resolve=function(f,I){var C=_(m,I);if(C.status==="error")return A.reject(f,C.value);var y=C.value;if(y)p(f,y);else{f.state=l,f.outcome=I;for(var x=-1,E=f.queue.length;++x<E;)f.queue[x].callFulfilled(I)}return f},A.reject=function(f,I){f.state=c,f.outcome=I;for(var C=-1,y=f.queue.length;++C<y;)f.queue[C].callRejected(I);return f},u.resolve=function(f){return f instanceof this?f:A.resolve(new this(a),f)},u.reject=function(f){var I=new this(a);return A.reject(I,f)},u.all=function(f){var I=this;if(Object.prototype.toString.call(f)!=="[object Array]")return this.reject(new TypeError("must be an array"));var C=f.length,y=!1;if(!C)return this.resolve([]);for(var x=new Array(C),E=0,B=-1,b=new this(a);++B<C;)Q(f[B],B);return b;function Q(w,D){I.resolve(w).then(function(k){x[D]=k,++E!==C||y||(y=!0,A.resolve(b,x))},function(k){y||(y=!0,A.reject(b,k))})}},u.race=function(f){var I=this;if(Object.prototype.toString.call(f)!=="[object Array]")return this.reject(new TypeError("must be an array"));var C=f.length,y=!1;if(!C)return this.resolve([]);for(var x=-1,E=new this(a);++x<C;)B=f[x],I.resolve(B).then(function(b){y||(y=!0,A.resolve(E,b))},function(b){y||(y=!0,A.reject(E,b))});var B;return E}},{immediate:36}],38:[function(o,i,r){var s={};(0,o("./lib/utils/common").assign)(s,o("./lib/deflate"),o("./lib/inflate"),o("./lib/zlib/constants")),i.exports=s},{"./lib/deflate":39,"./lib/inflate":40,"./lib/utils/common":41,"./lib/zlib/constants":44}],39:[function(o,i,r){var s=o("./zlib/deflate"),a=o("./utils/common"),A=o("./utils/strings"),c=o("./zlib/messages"),l=o("./zlib/zstream"),g=Object.prototype.toString,u=0,h=-1,d=0,m=8;function p(f){if(!(this instanceof p))return new p(f);this.options=a.assign({level:h,method:m,chunkSize:16384,windowBits:15,memLevel:8,strategy:d,to:""},f||{});var I=this.options;I.raw&&0<I.windowBits?I.windowBits=-I.windowBits:I.gzip&&0<I.windowBits&&I.windowBits<16&&(I.windowBits+=16),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new l,this.strm.avail_out=0;var C=s.deflateInit2(this.strm,I.level,I.method,I.windowBits,I.memLevel,I.strategy);if(C!==u)throw new Error(c[C]);if(I.header&&s.deflateSetHeader(this.strm,I.header),I.dictionary){var y;if(y=typeof I.dictionary=="string"?A.string2buf(I.dictionary):g.call(I.dictionary)==="[object ArrayBuffer]"?new Uint8Array(I.dictionary):I.dictionary,(C=s.deflateSetDictionary(this.strm,y))!==u)throw new Error(c[C]);this._dict_set=!0}}function _(f,I){var C=new p(I);if(C.push(f,!0),C.err)throw C.msg||c[C.err];return C.result}p.prototype.push=function(f,I){var C,y,x=this.strm,E=this.options.chunkSize;if(this.ended)return!1;y=I===~~I?I:I===!0?4:0,typeof f=="string"?x.input=A.string2buf(f):g.call(f)==="[object ArrayBuffer]"?x.input=new Uint8Array(f):x.input=f,x.next_in=0,x.avail_in=x.input.length;do{if(x.avail_out===0&&(x.output=new a.Buf8(E),x.next_out=0,x.avail_out=E),(C=s.deflate(x,y))!==1&&C!==u)return this.onEnd(C),!(this.ended=!0);x.avail_out!==0&&(x.avail_in!==0||y!==4&&y!==2)||(this.options.to==="string"?this.onData(A.buf2binstring(a.shrinkBuf(x.output,x.next_out))):this.onData(a.shrinkBuf(x.output,x.next_out)))}while((0<x.avail_in||x.avail_out===0)&&C!==1);return y===4?(C=s.deflateEnd(this.strm),this.onEnd(C),this.ended=!0,C===u):y!==2||(this.onEnd(u),!(x.avail_out=0))},p.prototype.onData=function(f){this.chunks.push(f)},p.prototype.onEnd=function(f){f===u&&(this.options.to==="string"?this.result=this.chunks.join(""):this.result=a.flattenChunks(this.chunks)),this.chunks=[],this.err=f,this.msg=this.strm.msg},r.Deflate=p,r.deflate=_,r.deflateRaw=function(f,I){return(I=I||{}).raw=!0,_(f,I)},r.gzip=function(f,I){return(I=I||{}).gzip=!0,_(f,I)}},{"./utils/common":41,"./utils/strings":42,"./zlib/deflate":46,"./zlib/messages":51,"./zlib/zstream":53}],40:[function(o,i,r){var s=o("./zlib/inflate"),a=o("./utils/common"),A=o("./utils/strings"),c=o("./zlib/constants"),l=o("./zlib/messages"),g=o("./zlib/zstream"),u=o("./zlib/gzheader"),h=Object.prototype.toString;function d(p){if(!(this instanceof d))return new d(p);this.options=a.assign({chunkSize:16384,windowBits:0,to:""},p||{});var _=this.options;_.raw&&0<=_.windowBits&&_.windowBits<16&&(_.windowBits=-_.windowBits,_.windowBits===0&&(_.windowBits=-15)),!(0<=_.windowBits&&_.windowBits<16)||p&&p.windowBits||(_.windowBits+=32),15<_.windowBits&&_.windowBits<48&&(15&_.windowBits)==0&&(_.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new g,this.strm.avail_out=0;var f=s.inflateInit2(this.strm,_.windowBits);if(f!==c.Z_OK)throw new Error(l[f]);this.header=new u,s.inflateGetHeader(this.strm,this.header)}function m(p,_){var f=new d(_);if(f.push(p,!0),f.err)throw f.msg||l[f.err];return f.result}d.prototype.push=function(p,_){var f,I,C,y,x,E,B=this.strm,b=this.options.chunkSize,Q=this.options.dictionary,w=!1;if(this.ended)return!1;I=_===~~_?_:_===!0?c.Z_FINISH:c.Z_NO_FLUSH,typeof p=="string"?B.input=A.binstring2buf(p):h.call(p)==="[object ArrayBuffer]"?B.input=new Uint8Array(p):B.input=p,B.next_in=0,B.avail_in=B.input.length;do{if(B.avail_out===0&&(B.output=new a.Buf8(b),B.next_out=0,B.avail_out=b),(f=s.inflate(B,c.Z_NO_FLUSH))===c.Z_NEED_DICT&&Q&&(E=typeof Q=="string"?A.string2buf(Q):h.call(Q)==="[object ArrayBuffer]"?new Uint8Array(Q):Q,f=s.inflateSetDictionary(this.strm,E)),f===c.Z_BUF_ERROR&&w===!0&&(f=c.Z_OK,w=!1),f!==c.Z_STREAM_END&&f!==c.Z_OK)return this.onEnd(f),!(this.ended=!0);B.next_out&&(B.avail_out!==0&&f!==c.Z_STREAM_END&&(B.avail_in!==0||I!==c.Z_FINISH&&I!==c.Z_SYNC_FLUSH)||(this.options.to==="string"?(C=A.utf8border(B.output,B.next_out),y=B.next_out-C,x=A.buf2string(B.output,C),B.next_out=y,B.avail_out=b-y,y&&a.arraySet(B.output,B.output,C,y,0),this.onData(x)):this.onData(a.shrinkBuf(B.output,B.next_out)))),B.avail_in===0&&B.avail_out===0&&(w=!0)}while((0<B.avail_in||B.avail_out===0)&&f!==c.Z_STREAM_END);return f===c.Z_STREAM_END&&(I=c.Z_FINISH),I===c.Z_FINISH?(f=s.inflateEnd(this.strm),this.onEnd(f),this.ended=!0,f===c.Z_OK):I!==c.Z_SYNC_FLUSH||(this.onEnd(c.Z_OK),!(B.avail_out=0))},d.prototype.onData=function(p){this.chunks.push(p)},d.prototype.onEnd=function(p){p===c.Z_OK&&(this.options.to==="string"?this.result=this.chunks.join(""):this.result=a.flattenChunks(this.chunks)),this.chunks=[],this.err=p,this.msg=this.strm.msg},r.Inflate=d,r.inflate=m,r.inflateRaw=function(p,_){return(_=_||{}).raw=!0,m(p,_)},r.ungzip=m},{"./utils/common":41,"./utils/strings":42,"./zlib/constants":44,"./zlib/gzheader":47,"./zlib/inflate":49,"./zlib/messages":51,"./zlib/zstream":53}],41:[function(o,i,r){var s=typeof Uint8Array<"u"&&typeof Uint16Array<"u"&&typeof Int32Array<"u";r.assign=function(c){for(var l=Array.prototype.slice.call(arguments,1);l.length;){var g=l.shift();if(g){if(typeof g!="object")throw new TypeError(g+"must be non-object");for(var u in g)g.hasOwnProperty(u)&&(c[u]=g[u])}}return c},r.shrinkBuf=function(c,l){return c.length===l?c:c.subarray?c.subarray(0,l):(c.length=l,c)};var a={arraySet:function(c,l,g,u,h){if(l.subarray&&c.subarray)c.set(l.subarray(g,g+u),h);else for(var d=0;d<u;d++)c[h+d]=l[g+d]},flattenChunks:function(c){var l,g,u,h,d,m;for(l=u=0,g=c.length;l<g;l++)u+=c[l].length;for(m=new Uint8Array(u),l=h=0,g=c.length;l<g;l++)d=c[l],m.set(d,h),h+=d.length;return m}},A={arraySet:function(c,l,g,u,h){for(var d=0;d<u;d++)c[h+d]=l[g+d]},flattenChunks:function(c){return[].concat.apply([],c)}};r.setTyped=function(c){c?(r.Buf8=Uint8Array,r.Buf16=Uint16Array,r.Buf32=Int32Array,r.assign(r,a)):(r.Buf8=Array,r.Buf16=Array,r.Buf32=Array,r.assign(r,A))},r.setTyped(s)},{}],42:[function(o,i,r){var s=o("./common"),a=!0,A=!0;try{String.fromCharCode.apply(null,[0])}catch{a=!1}try{String.fromCharCode.apply(null,new Uint8Array(1))}catch{A=!1}for(var c=new s.Buf8(256),l=0;l<256;l++)c[l]=252<=l?6:248<=l?5:240<=l?4:224<=l?3:192<=l?2:1;function g(u,h){if(h<65537&&(u.subarray&&A||!u.subarray&&a))return String.fromCharCode.apply(null,s.shrinkBuf(u,h));for(var d="",m=0;m<h;m++)d+=String.fromCharCode(u[m]);return d}c[254]=c[254]=1,r.string2buf=function(u){var h,d,m,p,_,f=u.length,I=0;for(p=0;p<f;p++)(64512&(d=u.charCodeAt(p)))==55296&&p+1<f&&(64512&(m=u.charCodeAt(p+1)))==56320&&(d=65536+(d-55296<<10)+(m-56320),p++),I+=d<128?1:d<2048?2:d<65536?3:4;for(h=new s.Buf8(I),p=_=0;_<I;p++)(64512&(d=u.charCodeAt(p)))==55296&&p+1<f&&(64512&(m=u.charCodeAt(p+1)))==56320&&(d=65536+(d-55296<<10)+(m-56320),p++),d<128?h[_++]=d:(d<2048?h[_++]=192|d>>>6:(d<65536?h[_++]=224|d>>>12:(h[_++]=240|d>>>18,h[_++]=128|d>>>12&63),h[_++]=128|d>>>6&63),h[_++]=128|63&d);return h},r.buf2binstring=function(u){return g(u,u.length)},r.binstring2buf=function(u){for(var h=new s.Buf8(u.length),d=0,m=h.length;d<m;d++)h[d]=u.charCodeAt(d);return h},r.buf2string=function(u,h){var d,m,p,_,f=h||u.length,I=new Array(2*f);for(d=m=0;d<f;)if((p=u[d++])<128)I[m++]=p;else if(4<(_=c[p]))I[m++]=65533,d+=_-1;else{for(p&=_===2?31:_===3?15:7;1<_&&d<f;)p=p<<6|63&u[d++],_--;1<_?I[m++]=65533:p<65536?I[m++]=p:(p-=65536,I[m++]=55296|p>>10&1023,I[m++]=56320|1023&p)}return g(I,m)},r.utf8border=function(u,h){var d;for((h=h||u.length)>u.length&&(h=u.length),d=h-1;0<=d&&(192&u[d])==128;)d--;return d<0||d===0?h:d+c[u[d]]>h?d:h}},{"./common":41}],43:[function(o,i,r){i.exports=function(s,a,A,c){for(var l=65535&s|0,g=s>>>16&65535|0,u=0;A!==0;){for(A-=u=2e3<A?2e3:A;g=g+(l=l+a[c++]|0)|0,--u;);l%=65521,g%=65521}return l|g<<16|0}},{}],44:[function(o,i,r){i.exports={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8}},{}],45:[function(o,i,r){var s=(function(){for(var a,A=[],c=0;c<256;c++){a=c;for(var l=0;l<8;l++)a=1&a?3988292384^a>>>1:a>>>1;A[c]=a}return A})();i.exports=function(a,A,c,l){var g=s,u=l+c;a^=-1;for(var h=l;h<u;h++)a=a>>>8^g[255&(a^A[h])];return-1^a}},{}],46:[function(o,i,r){var s,a=o("../utils/common"),A=o("./trees"),c=o("./adler32"),l=o("./crc32"),g=o("./messages"),u=0,h=4,d=0,m=-2,p=-1,_=4,f=2,I=8,C=9,y=286,x=30,E=19,B=2*y+1,b=15,Q=3,w=258,D=w+Q+1,k=42,R=113,H=1,G=2,K=3,Y=4;function X(pe,ve){return pe.msg=g[ve],ve}function te(pe){return(pe<<1)-(4<pe?9:0)}function j(pe){for(var ve=pe.length;0<=--ve;)pe[ve]=0}function J(pe){var ve=pe.state,Me=ve.pending;Me>pe.avail_out&&(Me=pe.avail_out),Me!==0&&(a.arraySet(pe.output,ve.pending_buf,ve.pending_out,Me,pe.next_out),pe.next_out+=Me,ve.pending_out+=Me,pe.total_out+=Me,pe.avail_out-=Me,ve.pending-=Me,ve.pending===0&&(ve.pending_out=0))}function ie(pe,ve){A._tr_flush_block(pe,0<=pe.block_start?pe.block_start:-1,pe.strstart-pe.block_start,ve),pe.block_start=pe.strstart,J(pe.strm)}function oe(pe,ve){pe.pending_buf[pe.pending++]=ve}function ne(pe,ve){pe.pending_buf[pe.pending++]=ve>>>8&255,pe.pending_buf[pe.pending++]=255&ve}function le(pe,ve){var Me,we,Oe=pe.max_chain_length,Te=pe.strstart,Se=pe.prev_length,Le=pe.nice_match,ye=pe.strstart>pe.w_size-D?pe.strstart-(pe.w_size-D):0,Fe=pe.window,Ye=pe.w_mask,qe=pe.prev,at=pe.strstart+w,rt=Fe[Te+Se-1],We=Fe[Te+Se];pe.prev_length>=pe.good_match&&(Oe>>=2),Le>pe.lookahead&&(Le=pe.lookahead);do if(Fe[(Me=ve)+Se]===We&&Fe[Me+Se-1]===rt&&Fe[Me]===Fe[Te]&&Fe[++Me]===Fe[Te+1]){Te+=2,Me++;do;while(Fe[++Te]===Fe[++Me]&&Fe[++Te]===Fe[++Me]&&Fe[++Te]===Fe[++Me]&&Fe[++Te]===Fe[++Me]&&Fe[++Te]===Fe[++Me]&&Fe[++Te]===Fe[++Me]&&Fe[++Te]===Fe[++Me]&&Fe[++Te]===Fe[++Me]&&Te<at);if(we=w-(at-Te),Te=at-w,Se<we){if(pe.match_start=ve,Le<=(Se=we))break;rt=Fe[Te+Se-1],We=Fe[Te+Se]}}while((ve=qe[ve&Ye])>ye&&--Oe!=0);return Se<=pe.lookahead?Se:pe.lookahead}function ge(pe){var ve,Me,we,Oe,Te,Se,Le,ye,Fe,Ye,qe=pe.w_size;do{if(Oe=pe.window_size-pe.lookahead-pe.strstart,pe.strstart>=qe+(qe-D)){for(a.arraySet(pe.window,pe.window,qe,qe,0),pe.match_start-=qe,pe.strstart-=qe,pe.block_start-=qe,ve=Me=pe.hash_size;we=pe.head[--ve],pe.head[ve]=qe<=we?we-qe:0,--Me;);for(ve=Me=qe;we=pe.prev[--ve],pe.prev[ve]=qe<=we?we-qe:0,--Me;);Oe+=qe}if(pe.strm.avail_in===0)break;if(Se=pe.strm,Le=pe.window,ye=pe.strstart+pe.lookahead,Fe=Oe,Ye=void 0,Ye=Se.avail_in,Fe<Ye&&(Ye=Fe),Me=Ye===0?0:(Se.avail_in-=Ye,a.arraySet(Le,Se.input,Se.next_in,Ye,ye),Se.state.wrap===1?Se.adler=c(Se.adler,Le,Ye,ye):Se.state.wrap===2&&(Se.adler=l(Se.adler,Le,Ye,ye)),Se.next_in+=Ye,Se.total_in+=Ye,Ye),pe.lookahead+=Me,pe.lookahead+pe.insert>=Q)for(Te=pe.strstart-pe.insert,pe.ins_h=pe.window[Te],pe.ins_h=(pe.ins_h<<pe.hash_shift^pe.window[Te+1])&pe.hash_mask;pe.insert&&(pe.ins_h=(pe.ins_h<<pe.hash_shift^pe.window[Te+Q-1])&pe.hash_mask,pe.prev[Te&pe.w_mask]=pe.head[pe.ins_h],pe.head[pe.ins_h]=Te,Te++,pe.insert--,!(pe.lookahead+pe.insert<Q)););}while(pe.lookahead<D&&pe.strm.avail_in!==0)}function _e(pe,ve){for(var Me,we;;){if(pe.lookahead<D){if(ge(pe),pe.lookahead<D&&ve===u)return H;if(pe.lookahead===0)break}if(Me=0,pe.lookahead>=Q&&(pe.ins_h=(pe.ins_h<<pe.hash_shift^pe.window[pe.strstart+Q-1])&pe.hash_mask,Me=pe.prev[pe.strstart&pe.w_mask]=pe.head[pe.ins_h],pe.head[pe.ins_h]=pe.strstart),Me!==0&&pe.strstart-Me<=pe.w_size-D&&(pe.match_length=le(pe,Me)),pe.match_length>=Q)if(we=A._tr_tally(pe,pe.strstart-pe.match_start,pe.match_length-Q),pe.lookahead-=pe.match_length,pe.match_length<=pe.max_lazy_match&&pe.lookahead>=Q){for(pe.match_length--;pe.strstart++,pe.ins_h=(pe.ins_h<<pe.hash_shift^pe.window[pe.strstart+Q-1])&pe.hash_mask,Me=pe.prev[pe.strstart&pe.w_mask]=pe.head[pe.ins_h],pe.head[pe.ins_h]=pe.strstart,--pe.match_length!=0;);pe.strstart++}else pe.strstart+=pe.match_length,pe.match_length=0,pe.ins_h=pe.window[pe.strstart],pe.ins_h=(pe.ins_h<<pe.hash_shift^pe.window[pe.strstart+1])&pe.hash_mask;else we=A._tr_tally(pe,0,pe.window[pe.strstart]),pe.lookahead--,pe.strstart++;if(we&&(ie(pe,!1),pe.strm.avail_out===0))return H}return pe.insert=pe.strstart<Q-1?pe.strstart:Q-1,ve===h?(ie(pe,!0),pe.strm.avail_out===0?K:Y):pe.last_lit&&(ie(pe,!1),pe.strm.avail_out===0)?H:G}function ce(pe,ve){for(var Me,we,Oe;;){if(pe.lookahead<D){if(ge(pe),pe.lookahead<D&&ve===u)return H;if(pe.lookahead===0)break}if(Me=0,pe.lookahead>=Q&&(pe.ins_h=(pe.ins_h<<pe.hash_shift^pe.window[pe.strstart+Q-1])&pe.hash_mask,Me=pe.prev[pe.strstart&pe.w_mask]=pe.head[pe.ins_h],pe.head[pe.ins_h]=pe.strstart),pe.prev_length=pe.match_length,pe.prev_match=pe.match_start,pe.match_length=Q-1,Me!==0&&pe.prev_length<pe.max_lazy_match&&pe.strstart-Me<=pe.w_size-D&&(pe.match_length=le(pe,Me),pe.match_length<=5&&(pe.strategy===1||pe.match_length===Q&&4096<pe.strstart-pe.match_start)&&(pe.match_length=Q-1)),pe.prev_length>=Q&&pe.match_length<=pe.prev_length){for(Oe=pe.strstart+pe.lookahead-Q,we=A._tr_tally(pe,pe.strstart-1-pe.prev_match,pe.prev_length-Q),pe.lookahead-=pe.prev_length-1,pe.prev_length-=2;++pe.strstart<=Oe&&(pe.ins_h=(pe.ins_h<<pe.hash_shift^pe.window[pe.strstart+Q-1])&pe.hash_mask,Me=pe.prev[pe.strstart&pe.w_mask]=pe.head[pe.ins_h],pe.head[pe.ins_h]=pe.strstart),--pe.prev_length!=0;);if(pe.match_available=0,pe.match_length=Q-1,pe.strstart++,we&&(ie(pe,!1),pe.strm.avail_out===0))return H}else if(pe.match_available){if((we=A._tr_tally(pe,0,pe.window[pe.strstart-1]))&&ie(pe,!1),pe.strstart++,pe.lookahead--,pe.strm.avail_out===0)return H}else pe.match_available=1,pe.strstart++,pe.lookahead--}return pe.match_available&&(we=A._tr_tally(pe,0,pe.window[pe.strstart-1]),pe.match_available=0),pe.insert=pe.strstart<Q-1?pe.strstart:Q-1,ve===h?(ie(pe,!0),pe.strm.avail_out===0?K:Y):pe.last_lit&&(ie(pe,!1),pe.strm.avail_out===0)?H:G}function Ie(pe,ve,Me,we,Oe){this.good_length=pe,this.max_lazy=ve,this.nice_length=Me,this.max_chain=we,this.func=Oe}function de(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=I,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,this.prev_length=0,this.max_chain_length=0,this.max_lazy_match=0,this.level=0,this.strategy=0,this.good_match=0,this.nice_match=0,this.dyn_ltree=new a.Buf16(2*B),this.dyn_dtree=new a.Buf16(2*(2*x+1)),this.bl_tree=new a.Buf16(2*(2*E+1)),j(this.dyn_ltree),j(this.dyn_dtree),j(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new a.Buf16(b+1),this.heap=new a.Buf16(2*y+1),j(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new a.Buf16(2*y+1),j(this.depth),this.l_buf=0,this.lit_bufsize=0,this.last_lit=0,this.d_buf=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0}function Ce(pe){var ve;return pe&&pe.state?(pe.total_in=pe.total_out=0,pe.data_type=f,(ve=pe.state).pending=0,ve.pending_out=0,ve.wrap<0&&(ve.wrap=-ve.wrap),ve.status=ve.wrap?k:R,pe.adler=ve.wrap===2?0:1,ve.last_flush=u,A._tr_init(ve),d):X(pe,m)}function Pe(pe){var ve=Ce(pe);return ve===d&&(function(Me){Me.window_size=2*Me.w_size,j(Me.head),Me.max_lazy_match=s[Me.level].max_lazy,Me.good_match=s[Me.level].good_length,Me.nice_match=s[Me.level].nice_length,Me.max_chain_length=s[Me.level].max_chain,Me.strstart=0,Me.block_start=0,Me.lookahead=0,Me.insert=0,Me.match_length=Me.prev_length=Q-1,Me.match_available=0,Me.ins_h=0})(pe.state),ve}function Qe(pe,ve,Me,we,Oe,Te){if(!pe)return m;var Se=1;if(ve===p&&(ve=6),we<0?(Se=0,we=-we):15<we&&(Se=2,we-=16),Oe<1||C<Oe||Me!==I||we<8||15<we||ve<0||9<ve||Te<0||_<Te)return X(pe,m);we===8&&(we=9);var Le=new de;return(pe.state=Le).strm=pe,Le.wrap=Se,Le.gzhead=null,Le.w_bits=we,Le.w_size=1<<Le.w_bits,Le.w_mask=Le.w_size-1,Le.hash_bits=Oe+7,Le.hash_size=1<<Le.hash_bits,Le.hash_mask=Le.hash_size-1,Le.hash_shift=~~((Le.hash_bits+Q-1)/Q),Le.window=new a.Buf8(2*Le.w_size),Le.head=new a.Buf16(Le.hash_size),Le.prev=new a.Buf16(Le.w_size),Le.lit_bufsize=1<<Oe+6,Le.pending_buf_size=4*Le.lit_bufsize,Le.pending_buf=new a.Buf8(Le.pending_buf_size),Le.d_buf=1*Le.lit_bufsize,Le.l_buf=3*Le.lit_bufsize,Le.level=ve,Le.strategy=Te,Le.method=Me,Pe(pe)}s=[new Ie(0,0,0,0,function(pe,ve){var Me=65535;for(Me>pe.pending_buf_size-5&&(Me=pe.pending_buf_size-5);;){if(pe.lookahead<=1){if(ge(pe),pe.lookahead===0&&ve===u)return H;if(pe.lookahead===0)break}pe.strstart+=pe.lookahead,pe.lookahead=0;var we=pe.block_start+Me;if((pe.strstart===0||pe.strstart>=we)&&(pe.lookahead=pe.strstart-we,pe.strstart=we,ie(pe,!1),pe.strm.avail_out===0)||pe.strstart-pe.block_start>=pe.w_size-D&&(ie(pe,!1),pe.strm.avail_out===0))return H}return pe.insert=0,ve===h?(ie(pe,!0),pe.strm.avail_out===0?K:Y):(pe.strstart>pe.block_start&&(ie(pe,!1),pe.strm.avail_out),H)}),new Ie(4,4,8,4,_e),new Ie(4,5,16,8,_e),new Ie(4,6,32,32,_e),new Ie(4,4,16,16,ce),new Ie(8,16,32,32,ce),new Ie(8,16,128,128,ce),new Ie(8,32,128,256,ce),new Ie(32,128,258,1024,ce),new Ie(32,258,258,4096,ce)],r.deflateInit=function(pe,ve){return Qe(pe,ve,I,15,8,0)},r.deflateInit2=Qe,r.deflateReset=Pe,r.deflateResetKeep=Ce,r.deflateSetHeader=function(pe,ve){return pe&&pe.state?pe.state.wrap!==2?m:(pe.state.gzhead=ve,d):m},r.deflate=function(pe,ve){var Me,we,Oe,Te;if(!pe||!pe.state||5<ve||ve<0)return pe?X(pe,m):m;if(we=pe.state,!pe.output||!pe.input&&pe.avail_in!==0||we.status===666&&ve!==h)return X(pe,pe.avail_out===0?-5:m);if(we.strm=pe,Me=we.last_flush,we.last_flush=ve,we.status===k)if(we.wrap===2)pe.adler=0,oe(we,31),oe(we,139),oe(we,8),we.gzhead?(oe(we,(we.gzhead.text?1:0)+(we.gzhead.hcrc?2:0)+(we.gzhead.extra?4:0)+(we.gzhead.name?8:0)+(we.gzhead.comment?16:0)),oe(we,255&we.gzhead.time),oe(we,we.gzhead.time>>8&255),oe(we,we.gzhead.time>>16&255),oe(we,we.gzhead.time>>24&255),oe(we,we.level===9?2:2<=we.strategy||we.level<2?4:0),oe(we,255&we.gzhead.os),we.gzhead.extra&&we.gzhead.extra.length&&(oe(we,255&we.gzhead.extra.length),oe(we,we.gzhead.extra.length>>8&255)),we.gzhead.hcrc&&(pe.adler=l(pe.adler,we.pending_buf,we.pending,0)),we.gzindex=0,we.status=69):(oe(we,0),oe(we,0),oe(we,0),oe(we,0),oe(we,0),oe(we,we.level===9?2:2<=we.strategy||we.level<2?4:0),oe(we,3),we.status=R);else{var Se=I+(we.w_bits-8<<4)<<8;Se|=(2<=we.strategy||we.level<2?0:we.level<6?1:we.level===6?2:3)<<6,we.strstart!==0&&(Se|=32),Se+=31-Se%31,we.status=R,ne(we,Se),we.strstart!==0&&(ne(we,pe.adler>>>16),ne(we,65535&pe.adler)),pe.adler=1}if(we.status===69)if(we.gzhead.extra){for(Oe=we.pending;we.gzindex<(65535&we.gzhead.extra.length)&&(we.pending!==we.pending_buf_size||(we.gzhead.hcrc&&we.pending>Oe&&(pe.adler=l(pe.adler,we.pending_buf,we.pending-Oe,Oe)),J(pe),Oe=we.pending,we.pending!==we.pending_buf_size));)oe(we,255&we.gzhead.extra[we.gzindex]),we.gzindex++;we.gzhead.hcrc&&we.pending>Oe&&(pe.adler=l(pe.adler,we.pending_buf,we.pending-Oe,Oe)),we.gzindex===we.gzhead.extra.length&&(we.gzindex=0,we.status=73)}else we.status=73;if(we.status===73)if(we.gzhead.name){Oe=we.pending;do{if(we.pending===we.pending_buf_size&&(we.gzhead.hcrc&&we.pending>Oe&&(pe.adler=l(pe.adler,we.pending_buf,we.pending-Oe,Oe)),J(pe),Oe=we.pending,we.pending===we.pending_buf_size)){Te=1;break}Te=we.gzindex<we.gzhead.name.length?255&we.gzhead.name.charCodeAt(we.gzindex++):0,oe(we,Te)}while(Te!==0);we.gzhead.hcrc&&we.pending>Oe&&(pe.adler=l(pe.adler,we.pending_buf,we.pending-Oe,Oe)),Te===0&&(we.gzindex=0,we.status=91)}else we.status=91;if(we.status===91)if(we.gzhead.comment){Oe=we.pending;do{if(we.pending===we.pending_buf_size&&(we.gzhead.hcrc&&we.pending>Oe&&(pe.adler=l(pe.adler,we.pending_buf,we.pending-Oe,Oe)),J(pe),Oe=we.pending,we.pending===we.pending_buf_size)){Te=1;break}Te=we.gzindex<we.gzhead.comment.length?255&we.gzhead.comment.charCodeAt(we.gzindex++):0,oe(we,Te)}while(Te!==0);we.gzhead.hcrc&&we.pending>Oe&&(pe.adler=l(pe.adler,we.pending_buf,we.pending-Oe,Oe)),Te===0&&(we.status=103)}else we.status=103;if(we.status===103&&(we.gzhead.hcrc?(we.pending+2>we.pending_buf_size&&J(pe),we.pending+2<=we.pending_buf_size&&(oe(we,255&pe.adler),oe(we,pe.adler>>8&255),pe.adler=0,we.status=R)):we.status=R),we.pending!==0){if(J(pe),pe.avail_out===0)return we.last_flush=-1,d}else if(pe.avail_in===0&&te(ve)<=te(Me)&&ve!==h)return X(pe,-5);if(we.status===666&&pe.avail_in!==0)return X(pe,-5);if(pe.avail_in!==0||we.lookahead!==0||ve!==u&&we.status!==666){var Le=we.strategy===2?(function(ye,Fe){for(var Ye;;){if(ye.lookahead===0&&(ge(ye),ye.lookahead===0)){if(Fe===u)return H;break}if(ye.match_length=0,Ye=A._tr_tally(ye,0,ye.window[ye.strstart]),ye.lookahead--,ye.strstart++,Ye&&(ie(ye,!1),ye.strm.avail_out===0))return H}return ye.insert=0,Fe===h?(ie(ye,!0),ye.strm.avail_out===0?K:Y):ye.last_lit&&(ie(ye,!1),ye.strm.avail_out===0)?H:G})(we,ve):we.strategy===3?(function(ye,Fe){for(var Ye,qe,at,rt,We=ye.window;;){if(ye.lookahead<=w){if(ge(ye),ye.lookahead<=w&&Fe===u)return H;if(ye.lookahead===0)break}if(ye.match_length=0,ye.lookahead>=Q&&0<ye.strstart&&(qe=We[at=ye.strstart-1])===We[++at]&&qe===We[++at]&&qe===We[++at]){rt=ye.strstart+w;do;while(qe===We[++at]&&qe===We[++at]&&qe===We[++at]&&qe===We[++at]&&qe===We[++at]&&qe===We[++at]&&qe===We[++at]&&qe===We[++at]&&at<rt);ye.match_length=w-(rt-at),ye.match_length>ye.lookahead&&(ye.match_length=ye.lookahead)}if(ye.match_length>=Q?(Ye=A._tr_tally(ye,1,ye.match_length-Q),ye.lookahead-=ye.match_length,ye.strstart+=ye.match_length,ye.match_length=0):(Ye=A._tr_tally(ye,0,ye.window[ye.strstart]),ye.lookahead--,ye.strstart++),Ye&&(ie(ye,!1),ye.strm.avail_out===0))return H}return ye.insert=0,Fe===h?(ie(ye,!0),ye.strm.avail_out===0?K:Y):ye.last_lit&&(ie(ye,!1),ye.strm.avail_out===0)?H:G})(we,ve):s[we.level].func(we,ve);if(Le!==K&&Le!==Y||(we.status=666),Le===H||Le===K)return pe.avail_out===0&&(we.last_flush=-1),d;if(Le===G&&(ve===1?A._tr_align(we):ve!==5&&(A._tr_stored_block(we,0,0,!1),ve===3&&(j(we.head),we.lookahead===0&&(we.strstart=0,we.block_start=0,we.insert=0))),J(pe),pe.avail_out===0))return we.last_flush=-1,d}return ve!==h?d:we.wrap<=0?1:(we.wrap===2?(oe(we,255&pe.adler),oe(we,pe.adler>>8&255),oe(we,pe.adler>>16&255),oe(we,pe.adler>>24&255),oe(we,255&pe.total_in),oe(we,pe.total_in>>8&255),oe(we,pe.total_in>>16&255),oe(we,pe.total_in>>24&255)):(ne(we,pe.adler>>>16),ne(we,65535&pe.adler)),J(pe),0<we.wrap&&(we.wrap=-we.wrap),we.pending!==0?d:1)},r.deflateEnd=function(pe){var ve;return pe&&pe.state?(ve=pe.state.status)!==k&&ve!==69&&ve!==73&&ve!==91&&ve!==103&&ve!==R&&ve!==666?X(pe,m):(pe.state=null,ve===R?X(pe,-3):d):m},r.deflateSetDictionary=function(pe,ve){var Me,we,Oe,Te,Se,Le,ye,Fe,Ye=ve.length;if(!pe||!pe.state||(Te=(Me=pe.state).wrap)===2||Te===1&&Me.status!==k||Me.lookahead)return m;for(Te===1&&(pe.adler=c(pe.adler,ve,Ye,0)),Me.wrap=0,Ye>=Me.w_size&&(Te===0&&(j(Me.head),Me.strstart=0,Me.block_start=0,Me.insert=0),Fe=new a.Buf8(Me.w_size),a.arraySet(Fe,ve,Ye-Me.w_size,Me.w_size,0),ve=Fe,Ye=Me.w_size),Se=pe.avail_in,Le=pe.next_in,ye=pe.input,pe.avail_in=Ye,pe.next_in=0,pe.input=ve,ge(Me);Me.lookahead>=Q;){for(we=Me.strstart,Oe=Me.lookahead-(Q-1);Me.ins_h=(Me.ins_h<<Me.hash_shift^Me.window[we+Q-1])&Me.hash_mask,Me.prev[we&Me.w_mask]=Me.head[Me.ins_h],Me.head[Me.ins_h]=we,we++,--Oe;);Me.strstart=we,Me.lookahead=Q-1,ge(Me)}return Me.strstart+=Me.lookahead,Me.block_start=Me.strstart,Me.insert=Me.lookahead,Me.lookahead=0,Me.match_length=Me.prev_length=Q-1,Me.match_available=0,pe.next_in=Le,pe.input=ye,pe.avail_in=Se,Me.wrap=Te,d},r.deflateInfo="pako deflate (from Nodeca project)"},{"../utils/common":41,"./adler32":43,"./crc32":45,"./messages":51,"./trees":52}],47:[function(o,i,r){i.exports=function(){this.text=0,this.time=0,this.xflags=0,this.os=0,this.extra=null,this.extra_len=0,this.name="",this.comment="",this.hcrc=0,this.done=!1}},{}],48:[function(o,i,r){i.exports=function(s,a){var A,c,l,g,u,h,d,m,p,_,f,I,C,y,x,E,B,b,Q,w,D,k,R,H,G;A=s.state,c=s.next_in,H=s.input,l=c+(s.avail_in-5),g=s.next_out,G=s.output,u=g-(a-s.avail_out),h=g+(s.avail_out-257),d=A.dmax,m=A.wsize,p=A.whave,_=A.wnext,f=A.window,I=A.hold,C=A.bits,y=A.lencode,x=A.distcode,E=(1<<A.lenbits)-1,B=(1<<A.distbits)-1;e:do{C<15&&(I+=H[c++]<<C,C+=8,I+=H[c++]<<C,C+=8),b=y[I&E];t:for(;;){if(I>>>=Q=b>>>24,C-=Q,(Q=b>>>16&255)===0)G[g++]=65535&b;else{if(!(16&Q)){if((64&Q)==0){b=y[(65535&b)+(I&(1<<Q)-1)];continue t}if(32&Q){A.mode=12;break e}s.msg="invalid literal/length code",A.mode=30;break e}w=65535&b,(Q&=15)&&(C<Q&&(I+=H[c++]<<C,C+=8),w+=I&(1<<Q)-1,I>>>=Q,C-=Q),C<15&&(I+=H[c++]<<C,C+=8,I+=H[c++]<<C,C+=8),b=x[I&B];n:for(;;){if(I>>>=Q=b>>>24,C-=Q,!(16&(Q=b>>>16&255))){if((64&Q)==0){b=x[(65535&b)+(I&(1<<Q)-1)];continue n}s.msg="invalid distance code",A.mode=30;break e}if(D=65535&b,C<(Q&=15)&&(I+=H[c++]<<C,(C+=8)<Q&&(I+=H[c++]<<C,C+=8)),d<(D+=I&(1<<Q)-1)){s.msg="invalid distance too far back",A.mode=30;break e}if(I>>>=Q,C-=Q,(Q=g-u)<D){if(p<(Q=D-Q)&&A.sane){s.msg="invalid distance too far back",A.mode=30;break e}if(R=f,(k=0)===_){if(k+=m-Q,Q<w){for(w-=Q;G[g++]=f[k++],--Q;);k=g-D,R=G}}else if(_<Q){if(k+=m+_-Q,(Q-=_)<w){for(w-=Q;G[g++]=f[k++],--Q;);if(k=0,_<w){for(w-=Q=_;G[g++]=f[k++],--Q;);k=g-D,R=G}}}else if(k+=_-Q,Q<w){for(w-=Q;G[g++]=f[k++],--Q;);k=g-D,R=G}for(;2<w;)G[g++]=R[k++],G[g++]=R[k++],G[g++]=R[k++],w-=3;w&&(G[g++]=R[k++],1<w&&(G[g++]=R[k++]))}else{for(k=g-D;G[g++]=G[k++],G[g++]=G[k++],G[g++]=G[k++],2<(w-=3););w&&(G[g++]=G[k++],1<w&&(G[g++]=G[k++]))}break}}break}}while(c<l&&g<h);c-=w=C>>3,I&=(1<<(C-=w<<3))-1,s.next_in=c,s.next_out=g,s.avail_in=c<l?l-c+5:5-(c-l),s.avail_out=g<h?h-g+257:257-(g-h),A.hold=I,A.bits=C}},{}],49:[function(o,i,r){var s=o("../utils/common"),a=o("./adler32"),A=o("./crc32"),c=o("./inffast"),l=o("./inftrees"),g=1,u=2,h=0,d=-2,m=1,p=852,_=592;function f(k){return(k>>>24&255)+(k>>>8&65280)+((65280&k)<<8)+((255&k)<<24)}function I(){this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new s.Buf16(320),this.work=new s.Buf16(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}function C(k){var R;return k&&k.state?(R=k.state,k.total_in=k.total_out=R.total=0,k.msg="",R.wrap&&(k.adler=1&R.wrap),R.mode=m,R.last=0,R.havedict=0,R.dmax=32768,R.head=null,R.hold=0,R.bits=0,R.lencode=R.lendyn=new s.Buf32(p),R.distcode=R.distdyn=new s.Buf32(_),R.sane=1,R.back=-1,h):d}function y(k){var R;return k&&k.state?((R=k.state).wsize=0,R.whave=0,R.wnext=0,C(k)):d}function x(k,R){var H,G;return k&&k.state?(G=k.state,R<0?(H=0,R=-R):(H=1+(R>>4),R<48&&(R&=15)),R&&(R<8||15<R)?d:(G.window!==null&&G.wbits!==R&&(G.window=null),G.wrap=H,G.wbits=R,y(k))):d}function E(k,R){var H,G;return k?(G=new I,(k.state=G).window=null,(H=x(k,R))!==h&&(k.state=null),H):d}var B,b,Q=!0;function w(k){if(Q){var R;for(B=new s.Buf32(512),b=new s.Buf32(32),R=0;R<144;)k.lens[R++]=8;for(;R<256;)k.lens[R++]=9;for(;R<280;)k.lens[R++]=7;for(;R<288;)k.lens[R++]=8;for(l(g,k.lens,0,288,B,0,k.work,{bits:9}),R=0;R<32;)k.lens[R++]=5;l(u,k.lens,0,32,b,0,k.work,{bits:5}),Q=!1}k.lencode=B,k.lenbits=9,k.distcode=b,k.distbits=5}function D(k,R,H,G){var K,Y=k.state;return Y.window===null&&(Y.wsize=1<<Y.wbits,Y.wnext=0,Y.whave=0,Y.window=new s.Buf8(Y.wsize)),G>=Y.wsize?(s.arraySet(Y.window,R,H-Y.wsize,Y.wsize,0),Y.wnext=0,Y.whave=Y.wsize):(G<(K=Y.wsize-Y.wnext)&&(K=G),s.arraySet(Y.window,R,H-G,K,Y.wnext),(G-=K)?(s.arraySet(Y.window,R,H-G,G,0),Y.wnext=G,Y.whave=Y.wsize):(Y.wnext+=K,Y.wnext===Y.wsize&&(Y.wnext=0),Y.whave<Y.wsize&&(Y.whave+=K))),0}r.inflateReset=y,r.inflateReset2=x,r.inflateResetKeep=C,r.inflateInit=function(k){return E(k,15)},r.inflateInit2=E,r.inflate=function(k,R){var H,G,K,Y,X,te,j,J,ie,oe,ne,le,ge,_e,ce,Ie,de,Ce,Pe,Qe,pe,ve,Me,we,Oe=0,Te=new s.Buf8(4),Se=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15];if(!k||!k.state||!k.output||!k.input&&k.avail_in!==0)return d;(H=k.state).mode===12&&(H.mode=13),X=k.next_out,K=k.output,j=k.avail_out,Y=k.next_in,G=k.input,te=k.avail_in,J=H.hold,ie=H.bits,oe=te,ne=j,ve=h;e:for(;;)switch(H.mode){case m:if(H.wrap===0){H.mode=13;break}for(;ie<16;){if(te===0)break e;te--,J+=G[Y++]<<ie,ie+=8}if(2&H.wrap&&J===35615){Te[H.check=0]=255&J,Te[1]=J>>>8&255,H.check=A(H.check,Te,2,0),ie=J=0,H.mode=2;break}if(H.flags=0,H.head&&(H.head.done=!1),!(1&H.wrap)||(((255&J)<<8)+(J>>8))%31){k.msg="incorrect header check",H.mode=30;break}if((15&J)!=8){k.msg="unknown compression method",H.mode=30;break}if(ie-=4,pe=8+(15&(J>>>=4)),H.wbits===0)H.wbits=pe;else if(pe>H.wbits){k.msg="invalid window size",H.mode=30;break}H.dmax=1<<pe,k.adler=H.check=1,H.mode=512&J?10:12,ie=J=0;break;case 2:for(;ie<16;){if(te===0)break e;te--,J+=G[Y++]<<ie,ie+=8}if(H.flags=J,(255&H.flags)!=8){k.msg="unknown compression method",H.mode=30;break}if(57344&H.flags){k.msg="unknown header flags set",H.mode=30;break}H.head&&(H.head.text=J>>8&1),512&H.flags&&(Te[0]=255&J,Te[1]=J>>>8&255,H.check=A(H.check,Te,2,0)),ie=J=0,H.mode=3;case 3:for(;ie<32;){if(te===0)break e;te--,J+=G[Y++]<<ie,ie+=8}H.head&&(H.head.time=J),512&H.flags&&(Te[0]=255&J,Te[1]=J>>>8&255,Te[2]=J>>>16&255,Te[3]=J>>>24&255,H.check=A(H.check,Te,4,0)),ie=J=0,H.mode=4;case 4:for(;ie<16;){if(te===0)break e;te--,J+=G[Y++]<<ie,ie+=8}H.head&&(H.head.xflags=255&J,H.head.os=J>>8),512&H.flags&&(Te[0]=255&J,Te[1]=J>>>8&255,H.check=A(H.check,Te,2,0)),ie=J=0,H.mode=5;case 5:if(1024&H.flags){for(;ie<16;){if(te===0)break e;te--,J+=G[Y++]<<ie,ie+=8}H.length=J,H.head&&(H.head.extra_len=J),512&H.flags&&(Te[0]=255&J,Te[1]=J>>>8&255,H.check=A(H.check,Te,2,0)),ie=J=0}else H.head&&(H.head.extra=null);H.mode=6;case 6:if(1024&H.flags&&(te<(le=H.length)&&(le=te),le&&(H.head&&(pe=H.head.extra_len-H.length,H.head.extra||(H.head.extra=new Array(H.head.extra_len)),s.arraySet(H.head.extra,G,Y,le,pe)),512&H.flags&&(H.check=A(H.check,G,le,Y)),te-=le,Y+=le,H.length-=le),H.length))break e;H.length=0,H.mode=7;case 7:if(2048&H.flags){if(te===0)break e;for(le=0;pe=G[Y+le++],H.head&&pe&&H.length<65536&&(H.head.name+=String.fromCharCode(pe)),pe&&le<te;);if(512&H.flags&&(H.check=A(H.check,G,le,Y)),te-=le,Y+=le,pe)break e}else H.head&&(H.head.name=null);H.length=0,H.mode=8;case 8:if(4096&H.flags){if(te===0)break e;for(le=0;pe=G[Y+le++],H.head&&pe&&H.length<65536&&(H.head.comment+=String.fromCharCode(pe)),pe&&le<te;);if(512&H.flags&&(H.check=A(H.check,G,le,Y)),te-=le,Y+=le,pe)break e}else H.head&&(H.head.comment=null);H.mode=9;case 9:if(512&H.flags){for(;ie<16;){if(te===0)break e;te--,J+=G[Y++]<<ie,ie+=8}if(J!==(65535&H.check)){k.msg="header crc mismatch",H.mode=30;break}ie=J=0}H.head&&(H.head.hcrc=H.flags>>9&1,H.head.done=!0),k.adler=H.check=0,H.mode=12;break;case 10:for(;ie<32;){if(te===0)break e;te--,J+=G[Y++]<<ie,ie+=8}k.adler=H.check=f(J),ie=J=0,H.mode=11;case 11:if(H.havedict===0)return k.next_out=X,k.avail_out=j,k.next_in=Y,k.avail_in=te,H.hold=J,H.bits=ie,2;k.adler=H.check=1,H.mode=12;case 12:if(R===5||R===6)break e;case 13:if(H.last){J>>>=7&ie,ie-=7&ie,H.mode=27;break}for(;ie<3;){if(te===0)break e;te--,J+=G[Y++]<<ie,ie+=8}switch(H.last=1&J,ie-=1,3&(J>>>=1)){case 0:H.mode=14;break;case 1:if(w(H),H.mode=20,R!==6)break;J>>>=2,ie-=2;break e;case 2:H.mode=17;break;case 3:k.msg="invalid block type",H.mode=30}J>>>=2,ie-=2;break;case 14:for(J>>>=7&ie,ie-=7&ie;ie<32;){if(te===0)break e;te--,J+=G[Y++]<<ie,ie+=8}if((65535&J)!=(J>>>16^65535)){k.msg="invalid stored block lengths",H.mode=30;break}if(H.length=65535&J,ie=J=0,H.mode=15,R===6)break e;case 15:H.mode=16;case 16:if(le=H.length){if(te<le&&(le=te),j<le&&(le=j),le===0)break e;s.arraySet(K,G,Y,le,X),te-=le,Y+=le,j-=le,X+=le,H.length-=le;break}H.mode=12;break;case 17:for(;ie<14;){if(te===0)break e;te--,J+=G[Y++]<<ie,ie+=8}if(H.nlen=257+(31&J),J>>>=5,ie-=5,H.ndist=1+(31&J),J>>>=5,ie-=5,H.ncode=4+(15&J),J>>>=4,ie-=4,286<H.nlen||30<H.ndist){k.msg="too many length or distance symbols",H.mode=30;break}H.have=0,H.mode=18;case 18:for(;H.have<H.ncode;){for(;ie<3;){if(te===0)break e;te--,J+=G[Y++]<<ie,ie+=8}H.lens[Se[H.have++]]=7&J,J>>>=3,ie-=3}for(;H.have<19;)H.lens[Se[H.have++]]=0;if(H.lencode=H.lendyn,H.lenbits=7,Me={bits:H.lenbits},ve=l(0,H.lens,0,19,H.lencode,0,H.work,Me),H.lenbits=Me.bits,ve){k.msg="invalid code lengths set",H.mode=30;break}H.have=0,H.mode=19;case 19:for(;H.have<H.nlen+H.ndist;){for(;Ie=(Oe=H.lencode[J&(1<<H.lenbits)-1])>>>16&255,de=65535&Oe,!((ce=Oe>>>24)<=ie);){if(te===0)break e;te--,J+=G[Y++]<<ie,ie+=8}if(de<16)J>>>=ce,ie-=ce,H.lens[H.have++]=de;else{if(de===16){for(we=ce+2;ie<we;){if(te===0)break e;te--,J+=G[Y++]<<ie,ie+=8}if(J>>>=ce,ie-=ce,H.have===0){k.msg="invalid bit length repeat",H.mode=30;break}pe=H.lens[H.have-1],le=3+(3&J),J>>>=2,ie-=2}else if(de===17){for(we=ce+3;ie<we;){if(te===0)break e;te--,J+=G[Y++]<<ie,ie+=8}ie-=ce,pe=0,le=3+(7&(J>>>=ce)),J>>>=3,ie-=3}else{for(we=ce+7;ie<we;){if(te===0)break e;te--,J+=G[Y++]<<ie,ie+=8}ie-=ce,pe=0,le=11+(127&(J>>>=ce)),J>>>=7,ie-=7}if(H.have+le>H.nlen+H.ndist){k.msg="invalid bit length repeat",H.mode=30;break}for(;le--;)H.lens[H.have++]=pe}}if(H.mode===30)break;if(H.lens[256]===0){k.msg="invalid code -- missing end-of-block",H.mode=30;break}if(H.lenbits=9,Me={bits:H.lenbits},ve=l(g,H.lens,0,H.nlen,H.lencode,0,H.work,Me),H.lenbits=Me.bits,ve){k.msg="invalid literal/lengths set",H.mode=30;break}if(H.distbits=6,H.distcode=H.distdyn,Me={bits:H.distbits},ve=l(u,H.lens,H.nlen,H.ndist,H.distcode,0,H.work,Me),H.distbits=Me.bits,ve){k.msg="invalid distances set",H.mode=30;break}if(H.mode=20,R===6)break e;case 20:H.mode=21;case 21:if(6<=te&&258<=j){k.next_out=X,k.avail_out=j,k.next_in=Y,k.avail_in=te,H.hold=J,H.bits=ie,c(k,ne),X=k.next_out,K=k.output,j=k.avail_out,Y=k.next_in,G=k.input,te=k.avail_in,J=H.hold,ie=H.bits,H.mode===12&&(H.back=-1);break}for(H.back=0;Ie=(Oe=H.lencode[J&(1<<H.lenbits)-1])>>>16&255,de=65535&Oe,!((ce=Oe>>>24)<=ie);){if(te===0)break e;te--,J+=G[Y++]<<ie,ie+=8}if(Ie&&(240&Ie)==0){for(Ce=ce,Pe=Ie,Qe=de;Ie=(Oe=H.lencode[Qe+((J&(1<<Ce+Pe)-1)>>Ce)])>>>16&255,de=65535&Oe,!(Ce+(ce=Oe>>>24)<=ie);){if(te===0)break e;te--,J+=G[Y++]<<ie,ie+=8}J>>>=Ce,ie-=Ce,H.back+=Ce}if(J>>>=ce,ie-=ce,H.back+=ce,H.length=de,Ie===0){H.mode=26;break}if(32&Ie){H.back=-1,H.mode=12;break}if(64&Ie){k.msg="invalid literal/length code",H.mode=30;break}H.extra=15&Ie,H.mode=22;case 22:if(H.extra){for(we=H.extra;ie<we;){if(te===0)break e;te--,J+=G[Y++]<<ie,ie+=8}H.length+=J&(1<<H.extra)-1,J>>>=H.extra,ie-=H.extra,H.back+=H.extra}H.was=H.length,H.mode=23;case 23:for(;Ie=(Oe=H.distcode[J&(1<<H.distbits)-1])>>>16&255,de=65535&Oe,!((ce=Oe>>>24)<=ie);){if(te===0)break e;te--,J+=G[Y++]<<ie,ie+=8}if((240&Ie)==0){for(Ce=ce,Pe=Ie,Qe=de;Ie=(Oe=H.distcode[Qe+((J&(1<<Ce+Pe)-1)>>Ce)])>>>16&255,de=65535&Oe,!(Ce+(ce=Oe>>>24)<=ie);){if(te===0)break e;te--,J+=G[Y++]<<ie,ie+=8}J>>>=Ce,ie-=Ce,H.back+=Ce}if(J>>>=ce,ie-=ce,H.back+=ce,64&Ie){k.msg="invalid distance code",H.mode=30;break}H.offset=de,H.extra=15&Ie,H.mode=24;case 24:if(H.extra){for(we=H.extra;ie<we;){if(te===0)break e;te--,J+=G[Y++]<<ie,ie+=8}H.offset+=J&(1<<H.extra)-1,J>>>=H.extra,ie-=H.extra,H.back+=H.extra}if(H.offset>H.dmax){k.msg="invalid distance too far back",H.mode=30;break}H.mode=25;case 25:if(j===0)break e;if(le=ne-j,H.offset>le){if((le=H.offset-le)>H.whave&&H.sane){k.msg="invalid distance too far back",H.mode=30;break}ge=le>H.wnext?(le-=H.wnext,H.wsize-le):H.wnext-le,le>H.length&&(le=H.length),_e=H.window}else _e=K,ge=X-H.offset,le=H.length;for(j<le&&(le=j),j-=le,H.length-=le;K[X++]=_e[ge++],--le;);H.length===0&&(H.mode=21);break;case 26:if(j===0)break e;K[X++]=H.length,j--,H.mode=21;break;case 27:if(H.wrap){for(;ie<32;){if(te===0)break e;te--,J|=G[Y++]<<ie,ie+=8}if(ne-=j,k.total_out+=ne,H.total+=ne,ne&&(k.adler=H.check=H.flags?A(H.check,K,ne,X-ne):a(H.check,K,ne,X-ne)),ne=j,(H.flags?J:f(J))!==H.check){k.msg="incorrect data check",H.mode=30;break}ie=J=0}H.mode=28;case 28:if(H.wrap&&H.flags){for(;ie<32;){if(te===0)break e;te--,J+=G[Y++]<<ie,ie+=8}if(J!==(4294967295&H.total)){k.msg="incorrect length check",H.mode=30;break}ie=J=0}H.mode=29;case 29:ve=1;break e;case 30:ve=-3;break e;case 31:return-4;default:return d}return k.next_out=X,k.avail_out=j,k.next_in=Y,k.avail_in=te,H.hold=J,H.bits=ie,(H.wsize||ne!==k.avail_out&&H.mode<30&&(H.mode<27||R!==4))&&D(k,k.output,k.next_out,ne-k.avail_out)?(H.mode=31,-4):(oe-=k.avail_in,ne-=k.avail_out,k.total_in+=oe,k.total_out+=ne,H.total+=ne,H.wrap&&ne&&(k.adler=H.check=H.flags?A(H.check,K,ne,k.next_out-ne):a(H.check,K,ne,k.next_out-ne)),k.data_type=H.bits+(H.last?64:0)+(H.mode===12?128:0)+(H.mode===20||H.mode===15?256:0),(oe==0&&ne===0||R===4)&&ve===h&&(ve=-5),ve)},r.inflateEnd=function(k){if(!k||!k.state)return d;var R=k.state;return R.window&&(R.window=null),k.state=null,h},r.inflateGetHeader=function(k,R){var H;return k&&k.state?(2&(H=k.state).wrap)==0?d:((H.head=R).done=!1,h):d},r.inflateSetDictionary=function(k,R){var H,G=R.length;return k&&k.state?(H=k.state).wrap!==0&&H.mode!==11?d:H.mode===11&&a(1,R,G,0)!==H.check?-3:D(k,R,G,G)?(H.mode=31,-4):(H.havedict=1,h):d},r.inflateInfo="pako inflate (from Nodeca project)"},{"../utils/common":41,"./adler32":43,"./crc32":45,"./inffast":48,"./inftrees":50}],50:[function(o,i,r){var s=o("../utils/common"),a=[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,0,0],A=[16,16,16,16,16,16,16,16,17,17,17,17,18,18,18,18,19,19,19,19,20,20,20,20,21,21,21,21,16,72,78],c=[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,0,0],l=[16,16,16,16,17,17,18,18,19,19,20,20,21,21,22,22,23,23,24,24,25,25,26,26,27,27,28,28,29,29,64,64];i.exports=function(g,u,h,d,m,p,_,f){var I,C,y,x,E,B,b,Q,w,D=f.bits,k=0,R=0,H=0,G=0,K=0,Y=0,X=0,te=0,j=0,J=0,ie=null,oe=0,ne=new s.Buf16(16),le=new s.Buf16(16),ge=null,_e=0;for(k=0;k<=15;k++)ne[k]=0;for(R=0;R<d;R++)ne[u[h+R]]++;for(K=D,G=15;1<=G&&ne[G]===0;G--);if(G<K&&(K=G),G===0)return m[p++]=20971520,m[p++]=20971520,f.bits=1,0;for(H=1;H<G&&ne[H]===0;H++);for(K<H&&(K=H),k=te=1;k<=15;k++)if(te<<=1,(te-=ne[k])<0)return-1;if(0<te&&(g===0||G!==1))return-1;for(le[1]=0,k=1;k<15;k++)le[k+1]=le[k]+ne[k];for(R=0;R<d;R++)u[h+R]!==0&&(_[le[u[h+R]]++]=R);if(B=g===0?(ie=ge=_,19):g===1?(ie=a,oe-=257,ge=A,_e-=257,256):(ie=c,ge=l,-1),k=H,E=p,X=R=J=0,y=-1,x=(j=1<<(Y=K))-1,g===1&&852<j||g===2&&592<j)return 1;for(;;){for(b=k-X,w=_[R]<B?(Q=0,_[R]):_[R]>B?(Q=ge[_e+_[R]],ie[oe+_[R]]):(Q=96,0),I=1<<k-X,H=C=1<<Y;m[E+(J>>X)+(C-=I)]=b<<24|Q<<16|w|0,C!==0;);for(I=1<<k-1;J&I;)I>>=1;if(I!==0?(J&=I-1,J+=I):J=0,R++,--ne[k]==0){if(k===G)break;k=u[h+_[R]]}if(K<k&&(J&x)!==y){for(X===0&&(X=K),E+=H,te=1<<(Y=k-X);Y+X<G&&!((te-=ne[Y+X])<=0);)Y++,te<<=1;if(j+=1<<Y,g===1&&852<j||g===2&&592<j)return 1;m[y=J&x]=K<<24|Y<<16|E-p|0}}return J!==0&&(m[E+J]=k-X<<24|64<<16|0),f.bits=K,0}},{"../utils/common":41}],51:[function(o,i,r){i.exports={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"}},{}],52:[function(o,i,r){var s=o("../utils/common"),a=0,A=1;function c(Oe){for(var Te=Oe.length;0<=--Te;)Oe[Te]=0}var l=0,g=29,u=256,h=u+1+g,d=30,m=19,p=2*h+1,_=15,f=16,I=7,C=256,y=16,x=17,E=18,B=[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0],b=[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13],Q=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7],w=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],D=new Array(2*(h+2));c(D);var k=new Array(2*d);c(k);var R=new Array(512);c(R);var H=new Array(256);c(H);var G=new Array(g);c(G);var K,Y,X,te=new Array(d);function j(Oe,Te,Se,Le,ye){this.static_tree=Oe,this.extra_bits=Te,this.extra_base=Se,this.elems=Le,this.max_length=ye,this.has_stree=Oe&&Oe.length}function J(Oe,Te){this.dyn_tree=Oe,this.max_code=0,this.stat_desc=Te}function ie(Oe){return Oe<256?R[Oe]:R[256+(Oe>>>7)]}function oe(Oe,Te){Oe.pending_buf[Oe.pending++]=255&Te,Oe.pending_buf[Oe.pending++]=Te>>>8&255}function ne(Oe,Te,Se){Oe.bi_valid>f-Se?(Oe.bi_buf|=Te<<Oe.bi_valid&65535,oe(Oe,Oe.bi_buf),Oe.bi_buf=Te>>f-Oe.bi_valid,Oe.bi_valid+=Se-f):(Oe.bi_buf|=Te<<Oe.bi_valid&65535,Oe.bi_valid+=Se)}function le(Oe,Te,Se){ne(Oe,Se[2*Te],Se[2*Te+1])}function ge(Oe,Te){for(var Se=0;Se|=1&Oe,Oe>>>=1,Se<<=1,0<--Te;);return Se>>>1}function _e(Oe,Te,Se){var Le,ye,Fe=new Array(_+1),Ye=0;for(Le=1;Le<=_;Le++)Fe[Le]=Ye=Ye+Se[Le-1]<<1;for(ye=0;ye<=Te;ye++){var qe=Oe[2*ye+1];qe!==0&&(Oe[2*ye]=ge(Fe[qe]++,qe))}}function ce(Oe){var Te;for(Te=0;Te<h;Te++)Oe.dyn_ltree[2*Te]=0;for(Te=0;Te<d;Te++)Oe.dyn_dtree[2*Te]=0;for(Te=0;Te<m;Te++)Oe.bl_tree[2*Te]=0;Oe.dyn_ltree[2*C]=1,Oe.opt_len=Oe.static_len=0,Oe.last_lit=Oe.matches=0}function Ie(Oe){8<Oe.bi_valid?oe(Oe,Oe.bi_buf):0<Oe.bi_valid&&(Oe.pending_buf[Oe.pending++]=Oe.bi_buf),Oe.bi_buf=0,Oe.bi_valid=0}function de(Oe,Te,Se,Le){var ye=2*Te,Fe=2*Se;return Oe[ye]<Oe[Fe]||Oe[ye]===Oe[Fe]&&Le[Te]<=Le[Se]}function Ce(Oe,Te,Se){for(var Le=Oe.heap[Se],ye=Se<<1;ye<=Oe.heap_len&&(ye<Oe.heap_len&&de(Te,Oe.heap[ye+1],Oe.heap[ye],Oe.depth)&&ye++,!de(Te,Le,Oe.heap[ye],Oe.depth));)Oe.heap[Se]=Oe.heap[ye],Se=ye,ye<<=1;Oe.heap[Se]=Le}function Pe(Oe,Te,Se){var Le,ye,Fe,Ye,qe=0;if(Oe.last_lit!==0)for(;Le=Oe.pending_buf[Oe.d_buf+2*qe]<<8|Oe.pending_buf[Oe.d_buf+2*qe+1],ye=Oe.pending_buf[Oe.l_buf+qe],qe++,Le===0?le(Oe,ye,Te):(le(Oe,(Fe=H[ye])+u+1,Te),(Ye=B[Fe])!==0&&ne(Oe,ye-=G[Fe],Ye),le(Oe,Fe=ie(--Le),Se),(Ye=b[Fe])!==0&&ne(Oe,Le-=te[Fe],Ye)),qe<Oe.last_lit;);le(Oe,C,Te)}function Qe(Oe,Te){var Se,Le,ye,Fe=Te.dyn_tree,Ye=Te.stat_desc.static_tree,qe=Te.stat_desc.has_stree,at=Te.stat_desc.elems,rt=-1;for(Oe.heap_len=0,Oe.heap_max=p,Se=0;Se<at;Se++)Fe[2*Se]!==0?(Oe.heap[++Oe.heap_len]=rt=Se,Oe.depth[Se]=0):Fe[2*Se+1]=0;for(;Oe.heap_len<2;)Fe[2*(ye=Oe.heap[++Oe.heap_len]=rt<2?++rt:0)]=1,Oe.depth[ye]=0,Oe.opt_len--,qe&&(Oe.static_len-=Ye[2*ye+1]);for(Te.max_code=rt,Se=Oe.heap_len>>1;1<=Se;Se--)Ce(Oe,Fe,Se);for(ye=at;Se=Oe.heap[1],Oe.heap[1]=Oe.heap[Oe.heap_len--],Ce(Oe,Fe,1),Le=Oe.heap[1],Oe.heap[--Oe.heap_max]=Se,Oe.heap[--Oe.heap_max]=Le,Fe[2*ye]=Fe[2*Se]+Fe[2*Le],Oe.depth[ye]=(Oe.depth[Se]>=Oe.depth[Le]?Oe.depth[Se]:Oe.depth[Le])+1,Fe[2*Se+1]=Fe[2*Le+1]=ye,Oe.heap[1]=ye++,Ce(Oe,Fe,1),2<=Oe.heap_len;);Oe.heap[--Oe.heap_max]=Oe.heap[1],(function(We,nt){var xt,It,Tt,Ft,Ct,Jt,Cn=nt.dyn_tree,Be=nt.max_code,Ze=nt.stat_desc.static_tree,_t=nt.stat_desc.has_stree,ut=nt.stat_desc.extra_bits,$e=nt.stat_desc.extra_base,pt=nt.stat_desc.max_length,bt=0;for(Ft=0;Ft<=_;Ft++)We.bl_count[Ft]=0;for(Cn[2*We.heap[We.heap_max]+1]=0,xt=We.heap_max+1;xt<p;xt++)pt<(Ft=Cn[2*Cn[2*(It=We.heap[xt])+1]+1]+1)&&(Ft=pt,bt++),Cn[2*It+1]=Ft,Be<It||(We.bl_count[Ft]++,Ct=0,$e<=It&&(Ct=ut[It-$e]),Jt=Cn[2*It],We.opt_len+=Jt*(Ft+Ct),_t&&(We.static_len+=Jt*(Ze[2*It+1]+Ct)));if(bt!==0){do{for(Ft=pt-1;We.bl_count[Ft]===0;)Ft--;We.bl_count[Ft]--,We.bl_count[Ft+1]+=2,We.bl_count[pt]--,bt-=2}while(0<bt);for(Ft=pt;Ft!==0;Ft--)for(It=We.bl_count[Ft];It!==0;)Be<(Tt=We.heap[--xt])||(Cn[2*Tt+1]!==Ft&&(We.opt_len+=(Ft-Cn[2*Tt+1])*Cn[2*Tt],Cn[2*Tt+1]=Ft),It--)}})(Oe,Te),_e(Fe,rt,Oe.bl_count)}function pe(Oe,Te,Se){var Le,ye,Fe=-1,Ye=Te[1],qe=0,at=7,rt=4;for(Ye===0&&(at=138,rt=3),Te[2*(Se+1)+1]=65535,Le=0;Le<=Se;Le++)ye=Ye,Ye=Te[2*(Le+1)+1],++qe<at&&ye===Ye||(qe<rt?Oe.bl_tree[2*ye]+=qe:ye!==0?(ye!==Fe&&Oe.bl_tree[2*ye]++,Oe.bl_tree[2*y]++):qe<=10?Oe.bl_tree[2*x]++:Oe.bl_tree[2*E]++,Fe=ye,rt=(qe=0)===Ye?(at=138,3):ye===Ye?(at=6,3):(at=7,4))}function ve(Oe,Te,Se){var Le,ye,Fe=-1,Ye=Te[1],qe=0,at=7,rt=4;for(Ye===0&&(at=138,rt=3),Le=0;Le<=Se;Le++)if(ye=Ye,Ye=Te[2*(Le+1)+1],!(++qe<at&&ye===Ye)){if(qe<rt)for(;le(Oe,ye,Oe.bl_tree),--qe!=0;);else ye!==0?(ye!==Fe&&(le(Oe,ye,Oe.bl_tree),qe--),le(Oe,y,Oe.bl_tree),ne(Oe,qe-3,2)):qe<=10?(le(Oe,x,Oe.bl_tree),ne(Oe,qe-3,3)):(le(Oe,E,Oe.bl_tree),ne(Oe,qe-11,7));Fe=ye,rt=(qe=0)===Ye?(at=138,3):ye===Ye?(at=6,3):(at=7,4)}}c(te);var Me=!1;function we(Oe,Te,Se,Le){ne(Oe,(l<<1)+(Le?1:0),3),(function(ye,Fe,Ye,qe){Ie(ye),oe(ye,Ye),oe(ye,~Ye),s.arraySet(ye.pending_buf,ye.window,Fe,Ye,ye.pending),ye.pending+=Ye})(Oe,Te,Se)}r._tr_init=function(Oe){Me||((function(){var Te,Se,Le,ye,Fe,Ye=new Array(_+1);for(ye=Le=0;ye<g-1;ye++)for(G[ye]=Le,Te=0;Te<1<<B[ye];Te++)H[Le++]=ye;for(H[Le-1]=ye,ye=Fe=0;ye<16;ye++)for(te[ye]=Fe,Te=0;Te<1<<b[ye];Te++)R[Fe++]=ye;for(Fe>>=7;ye<d;ye++)for(te[ye]=Fe<<7,Te=0;Te<1<<b[ye]-7;Te++)R[256+Fe++]=ye;for(Se=0;Se<=_;Se++)Ye[Se]=0;for(Te=0;Te<=143;)D[2*Te+1]=8,Te++,Ye[8]++;for(;Te<=255;)D[2*Te+1]=9,Te++,Ye[9]++;for(;Te<=279;)D[2*Te+1]=7,Te++,Ye[7]++;for(;Te<=287;)D[2*Te+1]=8,Te++,Ye[8]++;for(_e(D,h+1,Ye),Te=0;Te<d;Te++)k[2*Te+1]=5,k[2*Te]=ge(Te,5);K=new j(D,B,u+1,h,_),Y=new j(k,b,0,d,_),X=new j(new Array(0),Q,0,m,I)})(),Me=!0),Oe.l_desc=new J(Oe.dyn_ltree,K),Oe.d_desc=new J(Oe.dyn_dtree,Y),Oe.bl_desc=new J(Oe.bl_tree,X),Oe.bi_buf=0,Oe.bi_valid=0,ce(Oe)},r._tr_stored_block=we,r._tr_flush_block=function(Oe,Te,Se,Le){var ye,Fe,Ye=0;0<Oe.level?(Oe.strm.data_type===2&&(Oe.strm.data_type=(function(qe){var at,rt=4093624447;for(at=0;at<=31;at++,rt>>>=1)if(1&rt&&qe.dyn_ltree[2*at]!==0)return a;if(qe.dyn_ltree[18]!==0||qe.dyn_ltree[20]!==0||qe.dyn_ltree[26]!==0)return A;for(at=32;at<u;at++)if(qe.dyn_ltree[2*at]!==0)return A;return a})(Oe)),Qe(Oe,Oe.l_desc),Qe(Oe,Oe.d_desc),Ye=(function(qe){var at;for(pe(qe,qe.dyn_ltree,qe.l_desc.max_code),pe(qe,qe.dyn_dtree,qe.d_desc.max_code),Qe(qe,qe.bl_desc),at=m-1;3<=at&&qe.bl_tree[2*w[at]+1]===0;at--);return qe.opt_len+=3*(at+1)+5+5+4,at})(Oe),ye=Oe.opt_len+3+7>>>3,(Fe=Oe.static_len+3+7>>>3)<=ye&&(ye=Fe)):ye=Fe=Se+5,Se+4<=ye&&Te!==-1?we(Oe,Te,Se,Le):Oe.strategy===4||Fe===ye?(ne(Oe,2+(Le?1:0),3),Pe(Oe,D,k)):(ne(Oe,4+(Le?1:0),3),(function(qe,at,rt,We){var nt;for(ne(qe,at-257,5),ne(qe,rt-1,5),ne(qe,We-4,4),nt=0;nt<We;nt++)ne(qe,qe.bl_tree[2*w[nt]+1],3);ve(qe,qe.dyn_ltree,at-1),ve(qe,qe.dyn_dtree,rt-1)})(Oe,Oe.l_desc.max_code+1,Oe.d_desc.max_code+1,Ye+1),Pe(Oe,Oe.dyn_ltree,Oe.dyn_dtree)),ce(Oe),Le&&Ie(Oe)},r._tr_tally=function(Oe,Te,Se){return Oe.pending_buf[Oe.d_buf+2*Oe.last_lit]=Te>>>8&255,Oe.pending_buf[Oe.d_buf+2*Oe.last_lit+1]=255&Te,Oe.pending_buf[Oe.l_buf+Oe.last_lit]=255&Se,Oe.last_lit++,Te===0?Oe.dyn_ltree[2*Se]++:(Oe.matches++,Te--,Oe.dyn_ltree[2*(H[Se]+u+1)]++,Oe.dyn_dtree[2*ie(Te)]++),Oe.last_lit===Oe.lit_bufsize-1},r._tr_align=function(Oe){ne(Oe,2,3),le(Oe,C,D),(function(Te){Te.bi_valid===16?(oe(Te,Te.bi_buf),Te.bi_buf=0,Te.bi_valid=0):8<=Te.bi_valid&&(Te.pending_buf[Te.pending++]=255&Te.bi_buf,Te.bi_buf>>=8,Te.bi_valid-=8)})(Oe)}},{"../utils/common":41}],53:[function(o,i,r){i.exports=function(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0}},{}],54:[function(o,i,r){(function(s){(function(a,A){if(!a.setImmediate){var c,l,g,u,h=1,d={},m=!1,p=a.document,_=Object.getPrototypeOf&&Object.getPrototypeOf(a);_=_&&_.setTimeout?_:a,c={}.toString.call(a.process)==="[object process]"?function(y){n.nextTick(function(){I(y)})}:(function(){if(a.postMessage&&!a.importScripts){var y=!0,x=a.onmessage;return a.onmessage=function(){y=!1},a.postMessage("","*"),a.onmessage=x,y}})()?(u="setImmediate$"+Math.random()+"$",a.addEventListener?a.addEventListener("message",C,!1):a.attachEvent("onmessage",C),function(y){a.postMessage(u+y,"*")}):a.MessageChannel?((g=new MessageChannel).port1.onmessage=function(y){I(y.data)},function(y){g.port2.postMessage(y)}):p&&"onreadystatechange"in p.createElement("script")?(l=p.documentElement,function(y){var x=p.createElement("script");x.onreadystatechange=function(){I(y),x.onreadystatechange=null,l.removeChild(x),x=null},l.appendChild(x)}):function(y){setTimeout(I,0,y)},_.setImmediate=function(y){typeof y!="function"&&(y=new Function(""+y));for(var x=new Array(arguments.length-1),E=0;E<x.length;E++)x[E]=arguments[E+1];var B={callback:y,args:x};return d[h]=B,c(h),h++},_.clearImmediate=f}function f(y){delete d[y]}function I(y){if(m)setTimeout(I,0,y);else{var x=d[y];if(x){m=!0;try{(function(E){var B=E.callback,b=E.args;switch(b.length){case 0:B();break;case 1:B(b[0]);break;case 2:B(b[0],b[1]);break;case 3:B(b[0],b[1],b[2]);break;default:B.apply(A,b)}})(x)}finally{f(y),m=!1}}}}function C(y){y.source===a&&typeof y.data=="string"&&y.data.indexOf(u)===0&&I(+y.data.slice(u.length))}})(typeof self>"u"?s===void 0?this:s:self)}).call(this,typeof jC<"u"?jC:typeof self<"u"?self:typeof window<"u"?window:{})},{}]},{},[10])(10)})})(VJe)),VJe.exports}var MDi=wDi();const Vme=XC(MDi),DDi=async({circuitJson:t,projectName:e})=>{await ra.promise((async()=>{const n=new Vme,[o,{convertCircuitJsonToBomRows:i,convertBomRowsToCsv:r},{convertCircuitJsonToPickAndPlaceCsv:s}]=await Promise.all([gE("circuit-json-to-gerber"),gE("circuit-json-to-bom-csv"),gE("circuit-json-to-pnp-csv")]),a=t.filter(h=>!("error_type"in h)&&!("warning_type"in h)),A=o.convertCircuitJsonToGerberFiles(a,{flip_y_axis:!1});for(const[h,d]of Object.entries(A))n.file(`gerber/${h}`,d);const c=await i({circuitJson:t}),l=await r(c);n.file("bom.csv",l);const g=await s(t,{supplier:"jlcpcb"});n.file("pick_and_place.csv",g);const u=await n.generateAsync({type:"blob"});_E(u,{fileName:`${e}_fabrication_files.zip`})})(),{loading:"Generating fabrication files...",success:"Fabrication ZIP ready",error:n=>`Failed to generate fabrication files: ${n instanceof Error?n.message:String(n)}`})},NDi=async t=>{const{createFdmComponentBox:e,renderFdmComponentBoxPng:n}=await gE("circuit-json-to-fdm-component-box"),[o,i]=await Promise.all([e(t),n(t,{},{width:960,height:640})]);return{...o,previewPng:i}},RDi=async t=>{const{createFdmComponentBox:e}=await gE("circuit-json-to-fdm-component-box");return e(t)},Kln=({generatedBox:t,projectName:e})=>{const n=Uint8Array.from(t.threeMf);_E(new Blob([n.buffer],{type:"model/3mf"}),{fileName:`${pJe(e)}-component-box.3mf`})},TDi=async({circuitJson:t,projectName:e})=>{await ra.promise((async()=>{const n=await RDi(t);Kln({generatedBox:n,projectName:e})})(),{loading:"Generating component box...",success:"Component box 3MF ready",error:n=>`Failed to generate component box: ${n instanceof Error?n.message:String(n)}`})},kDi=async({circuitJson:t,projectName:e})=>{let n;try{const{convertCircuitJsonToGltf:o}=await gE("circuit-json-to-gltf");console.log("convertCircuitJsonToGltf",o);const i=await o(t,{format:"glb",boardTextureResolution:1024});if(!i||!(i instanceof ArrayBuffer))throw new Error("Invalid GLB data returned from converter");n=new Blob([i],{type:"model/gltf-binary"})}catch(o){console.error("GLB Export Error:",o);return}_E(n,{fileName:`${e}.glb`})},FDi=async({circuitJson:t,libraryName:e})=>{const{CircuitJsonToKicadLibraryConverter:n}=await gE("circuit-json-to-kicad"),o=new n(t,{libraryName:e,footprintLibraryName:e});o.runUntilFinished();const i=o.getOutput(),r=new Vme;r.file(`${e}.kicad_sym`,i.kicadSymString);for(const s of i.footprints){const a=r.folder(`${e}.pretty`);a&&a.file(`${s.footprintName}.kicad_mod`,`${s.kicadModString}
5589
5589
  `)}if(i.model3dSourcePaths.length>0){const s=r.folder(`${e}.3dshapes`);if(s)for(const a of i.model3dSourcePaths)try{const A=a.split("/").pop()||a,c=await fetch(a);if(c.ok){const l=await c.arrayBuffer();s.file(A,l)}}catch{}}return r.file("fp-lib-table",i.fpLibTableString),r.file("sym-lib-table",i.symLibTableString),r},LDi=async({circuitJson:t,projectName:e})=>{await ra.promise((async()=>{const o=await(await FDi({circuitJson:t,libraryName:e})).generateAsync({type:"blob"});_E(o,{fileName:`${e}_kicad_library.zip`})})(),{loading:"Generating KiCad library...",success:"KiCad library ZIP ready",error:n=>`Failed to generate KiCad library: ${n instanceof Error?n.message:String(n)}`})},HDi=async({circuitJson:t,projectName:e})=>{const{CircuitJsonToKicadPcbConverter:n,CircuitJsonToKicadSchConverter:o,CircuitJsonToKicadProConverter:i,resolveAndLoadKicad3dModelFiles:r}=await gE("circuit-json-to-kicad"),s=new o(t);s.runUntilFinished();const a=s.getOutputString(),A=new n(t,{includeBuiltin3dModels:!0,projectName:e});A.runUntilFinished();const c=A.getOutputString(),l=new i(t,{projectName:e,schematicFilename:`${e}.kicad_sch`,pcbFilename:`${e}.kicad_pcb`});l.runUntilFinished();const g=l.getOutputString(),u=new Vme;return u.file(`${e}.kicad_sch`,a),u.file(`${e}.kicad_pcb`,c),u.file(`${e}.kicad_pro`,g),await r({projectName:e,model3dSourcePaths:A.getModel3dSourcePaths(),fetch,onModelFile:({outputPath:h,content:d})=>{u.file(h,d)},onError:({sourcePath:h})=>{console.warn(`Failed to load 3D model from ${h}`)}}),u},ODi=async({circuitJson:t,projectName:e})=>{await ra.promise((async()=>{const o=await(await HDi({circuitJson:t,projectName:e})).generateAsync({type:"blob"});_E(o,{fileName:`${e}_kicad_project.zip`})})(),{loading:"Generating KiCad project...",success:"KiCad project ZIP ready",error:n=>`Failed to generate KiCad project: ${n instanceof Error?n.message:String(n)}`})},Vln=async({circuitJson:t,projectName:e,options:n={}})=>{try{const{convertCircuitJsonToLbrn:o}=await gE("circuit-json-to-lbrn"),r=(await o(t,{includeSilkscreen:n.includeSilkscreen??!1,includeOxidationCleaningLayer:n.includeOxidationCleaningLayer??!0})).toXml(),s=new Blob([r],{type:"application/lbrn"});_E(s,{fileName:`${e}.lbrn2`})}catch(o){const i=o instanceof Error?o.message:"Unknown error";ra.error(`Failed to export to LBRN format: ${i}`)}},GDi=async({circuitJson:t,projectName:e})=>{const{convertCircuitJsonToPinoutSvg:n}=await gE("circuit-to-svg"),o=n(t);_E(o,{fileName:`${e}-pinout.svg`,mimeType:"image/svg+xml"})},YDi=async({circuitJson:t,projectName:e})=>{const{circuitJsonToStep:n}=await gE("circuit-json-to-step"),o=t.find(c=>c.type==="pcb_board"),i=o&&"width"in o?o.width:void 0,r=o&&"height"in o?o.height:void 0,s=o&&"thickness"in o?o.thickness:void 0;if(i===void 0||r===void 0||s===void 0){ra.error("Board dimensions not found. Please add a pcb_board with width, height, and thickness to your circuit.");return}let a;try{a=await n(t,{boardWidth:i,boardHeight:r,boardThickness:s,productName:e,includeComponents:!0,includeExternalMeshes:!0})}catch(c){const l=c instanceof Error?c.message:"Unknown error";ra.error(`Failed to convert circuit to STEP format: ${l}`);return}const A=new Blob([a],{type:"application/step"});try{_E(A,{fileName:`${e}.step`})}catch(c){const l=c instanceof Error?c.message:"Unknown error";ra.error(`Failed to download STEP file: ${l}`)}},UDi=[{extension:"json",name:"Circuit JSON"},{extension:"json",name:"Simple Route JSON"},{extension:"zip",name:"Fabrication Files"},{extension:"zip",name:"KiCad Project"},{extension:"zip",name:"Altium Project"},{extension:"zip",name:"KiCad Library"},{extension:"glb",name:"GLB (Binary GLTF)"},{extension:"svg",name:"Pinout SVG"},{extension:"step",name:"STEP"},{extension:"lbrn2",name:"LightBurn"}],KDi=async({exportName:t,circuitJson:e,simpleRouteJson:n,projectName:o})=>{const i=pJe(o);if(t==="Fabrication Files"){await DDi({circuitJson:e,projectName:i});return}if(t==="KiCad Project"){await ODi({circuitJson:e,projectName:i});return}if(t==="Altium Project"){await PDi({circuitJson:e,projectName:i});return}if(t==="KiCad Library"){await LDi({circuitJson:e,projectName:i});return}if(t==="Circuit JSON"){_E(JSON.stringify(e,null,2),{fileName:`${i}.circuit.json`,mimeType:"application/json"});return}if(t==="Simple Route JSON"){if(!n)throw new Error("No Simple Route JSON available to export");_E(JSON.stringify(n,null,2),{fileName:`${i}.simple-route.json`,mimeType:"application/json"});return}if(t==="GLB (Binary GLTF)"){await kDi({circuitJson:e,projectName:i});return}if(t==="Pinout SVG"){GDi({circuitJson:e,projectName:i});return}if(t==="STEP"){await YDi({circuitJson:e,projectName:i});return}if(t==="Component Box (3MF)"){await TDi({circuitJson:e,projectName:i});return}if(t==="LightBurn"){await Vln({circuitJson:e,projectName:i});return}throw new Error(`Unsupported export type: "${t}"`)},VDi=({packageName:t,onSelectReview:e})=>{const n=id(g=>g.fsMap),o=id(g=>g.circuitJson),[i,r]=ee.useState([]),[s,a]=ee.useState(!1),[A,c]=ee.useState(!1);ee.useEffect(()=>{!t||!z0e()||(a(!0),Lj.get("ai_reviews/list",{searchParams:{package_name:t}}).json().then(g=>r(g.ai_reviews)).catch(g=>{console.error("Failed to load AI reviews",g),ra.error("Failed to load AI reviews")}).finally(()=>a(!1)))},[t]);const l=async()=>{if(!o){ra.error("Need Circuit JSON to Request AI Review");return}if(!z0e()){ra.error("Missing registry token");return}c(!0);try{const{ai_review:g}=await Lj.post("ai_reviews/create",{json:{package_name:t??"unknown",fs_map:Object.fromEntries(n),circuit_json:o}}).json();r(u=>[g,...u]),e(g),ra.success("AI review requested")}catch(g){console.error("Failed to create AI review",g),ra.error("Failed to request AI review")}finally{c(!1)}};return U.jsxs(U.Fragment,{children:[U.jsxs(nw,{children:[U.jsx(ow,{children:"AI Review"}),U.jsx(UR,{children:"Select an AI review or request a new one."})]}),U.jsx("div",{className:"rf-flex rf-gap-4 rf-mt-4",children:U.jsx("div",{className:"rf-w-48 rf-h-64 rf-overflow-y-auto rf-border rf-rounded rf-p-2 rf-flex-shrink-0",children:s?U.jsx("div",{className:"rf-text-sm",children:"Loading..."}):i.length>0?i.map(g=>U.jsx("div",{className:"rf-text-sm rf-p-2 rf-cursor-pointer rf-rounded hover:rf-bg-zinc-100",onClick:()=>e(g),children:new Date(g.created_at||"").toLocaleString()},g.ai_review_id)):U.jsx("div",{className:"rf-text-sm rf-text-muted-foreground",children:"No AI reviews found."})})}),U.jsx(MY,{className:"rf-mt-4",children:U.jsx(uA,{onClick:l,disabled:A,children:A?"Requesting...":"Review my Board"})})]})};function zJe(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var KR=zJe();function zln(t){KR=t}var P$={exec:()=>null};function E0(t,e=""){let n=typeof t=="string"?t:t.source;const o={replace:(i,r)=>{let s=typeof r=="string"?r:r.source;return s=s.replace(Uy.caret,"$1"),n=n.replace(i,s),o},getRegex:()=>new RegExp(n,e)};return o}var Uy={codeRemoveIndent:/^(?: {1,4}| {0,3}\t)/gm,outputLinkReplace:/\\([\[\]])/g,indentCodeCompensation:/^(\s+)(?:```)/,beginningSpace:/^\s+/,endingHash:/#$/,startingSpaceChar:/^ /,endingSpaceChar:/ $/,nonSpaceChar:/[^ ]/,newLineCharGlobal:/\n/g,tabCharGlobal:/\t/g,multipleSpaceGlobal:/\s+/g,blankLine:/^[ \t]*$/,doubleBlankLine:/\n[ \t]*\n[ \t]*$/,blockquoteStart:/^ {0,3}>/,blockquoteSetextReplace:/\n {0,3}((?:=+|-+) *)(?=\n|$)/g,blockquoteSetextReplace2:/^ {0,3}>[ \t]?/gm,listReplaceTabs:/^\t+/,listReplaceNesting:/^ {1,4}(?=( {4})*[^ ])/g,listIsTask:/^\[[ xX]\] /,listReplaceTask:/^\[[ xX]\] +/,anyLine:/\n.*\n/,hrefBrackets:/^<(.*)>$/,tableDelimiter:/[:|]/,tableAlignChars:/^\||\| *$/g,tableRowBlankLine:/\n[ \t]*$/,tableAlignRight:/^ *-+: *$/,tableAlignCenter:/^ *:-+: *$/,tableAlignLeft:/^ *:-+ *$/,startATag:/^<a /i,endATag:/^<\/a>/i,startPreScriptTag:/^<(pre|code|kbd|script)(\s|>)/i,endPreScriptTag:/^<\/(pre|code|kbd|script)(\s|>)/i,startAngleBracket:/^</,endAngleBracket:/>$/,pedanticHrefTitle:/^([^'"]*[^\s])\s+(['"])(.*)\2/,unicodeAlphaNumeric:/[\p{L}\p{N}]/u,escapeTest:/[&<>"']/,escapeReplace:/[&<>"']/g,escapeTestNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,escapeReplaceNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,unescapeTest:/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig,caret:/(^|[^\[])\^/g,percentDecode:/%25/g,findPipe:/\|/g,splitPipe:/ \|/,slashPipe:/\\\|/g,carriageReturn:/\r\n|\r/g,spaceLine:/^ +$/gm,notSpaceStart:/^\S*/,endingNewline:/\n$/,listItemRegex:t=>new RegExp(`^( {0,3}${t})((?:[ ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:t=>new RegExp(`^ {0,${Math.min(3,t-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`),hrRegex:t=>new RegExp(`^ {0,${Math.min(3,t-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),fencesBeginRegex:t=>new RegExp(`^ {0,${Math.min(3,t-1)}}(?:\`\`\`|~~~)`),headingBeginRegex:t=>new RegExp(`^ {0,${Math.min(3,t-1)}}#`),htmlBeginRegex:t=>new RegExp(`^ {0,${Math.min(3,t-1)}}<(?:[a-z].*>|!--)`,"i")},zDi=/^(?:[ \t]*(?:\n|$))+/,JDi=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,WDi=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,w$=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,jDi=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,JJe=/(?:[*+-]|\d{1,9}[.)])/,Jln=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,Wln=E0(Jln).replace(/bull/g,JJe).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/\|table/g,"").getRegex(),XDi=E0(Jln).replace(/bull/g,JJe).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/table/g,/ {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).getRegex(),WJe=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,qDi=/^[^\n]+/,jJe=/(?!\s*\])(?:\\.|[^\[\]\\])+/,$Di=E0(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",jJe).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),ZDi=E0(/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,JJe).getRegex(),zme="address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul",XJe=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,eNi=E0("^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|<![A-Z][\\s\\S]*?(?:>\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$))","i").replace("comment",XJe).replace("tag",zme).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),jln=E0(WJe).replace("hr",w$).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("|table","").replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",zme).getRegex(),tNi=E0(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",jln).getRegex(),qJe={blockquote:tNi,code:JDi,def:$Di,fences:WDi,heading:jDi,hr:w$,html:eNi,lheading:Wln,list:ZDi,newline:zDi,paragraph:jln,table:P$,text:qDi},Xln=E0("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",w$).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("blockquote"," {0,3}>").replace("code","(?: {4}| {0,3} )[^\\n]").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",zme).getRegex(),nNi={...qJe,lheading:XDi,table:Xln,paragraph:E0(WJe).replace("hr",w$).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",Xln).replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",zme).getRegex()},oNi={...qJe,html:E0(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",XJe).replace(/tag/g,"(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b").getRegex(),def:/^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^(#{1,6})(.*)(?:\n+|$)/,fences:P$,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:E0(WJe).replace("hr",w$).replace("heading",` *#{1,6} *[^
5590
5590
  ]`).replace("lheading",Wln).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},iNi=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,rNi=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,qln=/^( {2,}|\\)\n(?!\s*$)/,sNi=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,Jme=/[\p{P}\p{S}]/u,$Je=/[\s\p{P}\p{S}]/u,$ln=/[^\s\p{P}\p{S}]/u,aNi=E0(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,$Je).getRegex(),Zln=/(?!~)[\p{P}\p{S}]/u,ANi=/(?!~)[\s\p{P}\p{S}]/u,cNi=/(?:[^\s\p{P}\p{S}]|~)/u,lNi=/\[[^[\]]*?\]\((?:\\.|[^\\\(\)]|\((?:\\.|[^\\\(\)])*\))*\)|`[^`]*?`|<[^<>]*?>/g,e0n=/^(?:\*+(?:((?!\*)punct)|[^\s*]))|^_+(?:((?!_)punct)|([^\s_]))/,gNi=E0(e0n,"u").replace(/punct/g,Jme).getRegex(),uNi=E0(e0n,"u").replace(/punct/g,Zln).getRegex(),t0n="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",dNi=E0(t0n,"gu").replace(/notPunctSpace/g,$ln).replace(/punctSpace/g,$Je).replace(/punct/g,Jme).getRegex(),hNi=E0(t0n,"gu").replace(/notPunctSpace/g,cNi).replace(/punctSpace/g,ANi).replace(/punct/g,Zln).getRegex(),mNi=E0("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,$ln).replace(/punctSpace/g,$Je).replace(/punct/g,Jme).getRegex(),pNi=E0(/\\(punct)/,"gu").replace(/punct/g,Jme).getRegex(),_Ni=E0(/^<(scheme:[^\s\x00-\x1f<>]*|email)>/).replace("scheme",/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/).replace("email",/[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/).getRegex(),fNi=E0(XJe).replace("(?:-->|$)","-->").getRegex(),INi=E0("^comment|^</[a-zA-Z][\\w:-]*\\s*>|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>").replace("comment",fNi).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),Wme=/(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/,CNi=E0(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]*(?:\n[ \t]*)?)(title))?\s*\)/).replace("label",Wme).replace("href",/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),n0n=E0(/^!?\[(label)\]\[(ref)\]/).replace("label",Wme).replace("ref",jJe).getRegex(),o0n=E0(/^!?\[(ref)\](?:\[\])?/).replace("ref",jJe).getRegex(),yNi=E0("reflink|nolink(?!\\()","g").replace("reflink",n0n).replace("nolink",o0n).getRegex(),ZJe={_backpedal:P$,anyPunctuation:pNi,autolink:_Ni,blockSkip:lNi,br:qln,code:rNi,del:P$,emStrongLDelim:gNi,emStrongRDelimAst:dNi,emStrongRDelimUnd:mNi,escape:iNi,link:CNi,nolink:o0n,punctuation:aNi,reflink:n0n,reflinkSearch:yNi,tag:INi,text:sNi,url:P$},xNi={...ZJe,link:E0(/^!?\[(label)\]\((.*?)\)/).replace("label",Wme).getRegex(),reflink:E0(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",Wme).getRegex()},eWe={...ZJe,emStrongRDelimAst:hNi,emStrongLDelim:uNi,url:E0(/^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/,"i").replace("email",/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/).getRegex(),_backpedal:/(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,del:/^(~~?)(?=[^\s~])((?:\\.|[^\\])*?(?:\\.|[^\s~\\]))\1(?=[^~]|$)/,text:/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/},ENi={...eWe,br:E0(qln).replace("{2,}","*").getRegex(),text:E0(eWe.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},jme={normal:qJe,gfm:nNi,pedantic:oNi},M$={normal:ZJe,gfm:eWe,breaks:ENi,pedantic:xNi},BNi={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},i0n=t=>BNi[t];function E7(t,e){if(e){if(Uy.escapeTest.test(t))return t.replace(Uy.escapeReplace,i0n)}else if(Uy.escapeTestNoEncode.test(t))return t.replace(Uy.escapeReplaceNoEncode,i0n);return t}function r0n(t){try{t=encodeURI(t).replace(Uy.percentDecode,"%")}catch{return null}return t}function s0n(t,e){const n=t.replace(Uy.findPipe,(r,s,a)=>{let A=!1,c=s;for(;--c>=0&&a[c]==="\\";)A=!A;return A?"|":" |"}),o=n.split(Uy.splitPipe);let i=0;if(o[0].trim()||o.shift(),o.length>0&&!o.at(-1)?.trim()&&o.pop(),e)if(o.length>e)o.splice(e);else for(;o.length<e;)o.push("");for(;i<o.length;i++)o[i]=o[i].trim().replace(Uy.slashPipe,"|");return o}function D$(t,e,n){const o=t.length;if(o===0)return"";let i=0;for(;i<o&&t.charAt(o-i-1)===e;)i++;return t.slice(0,o-i)}function SNi(t,e){if(t.indexOf(e[1])===-1)return-1;let n=0;for(let o=0;o<t.length;o++)if(t[o]==="\\")o++;else if(t[o]===e[0])n++;else if(t[o]===e[1]&&(n--,n<0))return o;return n>0?-2:-1}function a0n(t,e,n,o,i){const r=e.href,s=e.title||null,a=t[1].replace(i.other.outputLinkReplace,"$1");o.state.inLink=!0;const A={type:t[0].charAt(0)==="!"?"image":"link",raw:n,href:r,title:s,text:a,tokens:o.inlineTokens(a)};return o.state.inLink=!1,A}function bNi(t,e,n){const o=t.match(n.other.indentCodeCompensation);if(o===null)return e;const i=o[1];return e.split(`