@tscircuit/runframe 0.0.2736 → 0.0.2738
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/standalone.min.js
CHANGED
|
@@ -5480,7 +5480,7 @@ ${A.join(`
|
|
|
5480
5480
|
${m}polygon: ${d.polygon.vertices}
|
|
5481
5481
|
`:A+=`
|
|
5482
5482
|
`,d.children.length>0&&l.push(d.children)}return A}};e.exports=s}}),pAi=yt({"node_modules/@jscad/modeling/src/operations/booleans/trees/Tree.js"(t,e){var n=uAi(),o=mAi(),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}}),$Ye=yt({"node_modules/@jscad/modeling/src/operations/booleans/trees/index.js"(t,e){e.exports={Tree:pAi()}}}),_Ai=yt({"node_modules/@jscad/modeling/src/operations/booleans/intersectGeom3Sub.js"(t,e){var n=va(),o=XYe(),{Tree:i}=$Ye(),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}}),Len=yt({"node_modules/@jscad/modeling/src/operations/booleans/intersectGeom3.js"(t,e){var n=ra(),o=Zq(),i=_Ai(),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=ra(),o=va(),i=S9(),r=jYe(),s=qYe(),a=Len(),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}}),IAi=yt({"node_modules/@jscad/modeling/src/operations/booleans/intersect.js"(t,e){var n=ra(),o=$q(),i=Ta(),r=va(),s=fAi(),a=Len(),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}}),ZYe=yt({"node_modules/@jscad/modeling/src/operations/hulls/hullPoints3.js"(t,e){var n=zA(),o=UZt(),i=r=>o(r,{skipTriangulation:!0}).map(A=>{const c=A.map(l=>r[l]);return n.create(c)});e.exports=i}}),Hen=yt({"node_modules/@jscad/modeling/src/operations/booleans/unionGeom3Sub.js"(t,e){var n=va(),o=XYe(),{Tree:i}=$Ye(),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}}),eUe=yt({"node_modules/@jscad/modeling/src/operations/booleans/unionGeom3.js"(t,e){var n=ra(),o=Zq(),i=Hen(),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}}),Oen=yt({"node_modules/@jscad/modeling/src/operations/minkowski/minkowskiSum.js"(t,e){var n=ra(),o=va(),i=zA(),r=ZYe(),s=eUe(),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],T=f[D],H=f[D+1],G=l(w,k,T,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}}),CAi=yt({"node_modules/@jscad/modeling/src/operations/booleans/scissionGeom3.js"(t,e){var n=Jr(),o=S9(),i=va(),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}}),yAi=yt({"node_modules/@jscad/modeling/src/operations/booleans/scission.js"(t,e){var n=ra(),o=va(),i=CAi(),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}}),xAi=yt({"node_modules/@jscad/modeling/src/operations/booleans/subtractGeom3Sub.js"(t,e){var n=va(),o=XYe(),{Tree:i}=$Ye(),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}}),Gen=yt({"node_modules/@jscad/modeling/src/operations/booleans/subtractGeom3.js"(t,e){var n=ra(),o=Zq(),i=xAi(),r=(...s)=>{s=n(s);let a=s.shift();return s.forEach(A=>{a=i(a,A)}),a=o(a),a};e.exports=r}}),EAi=yt({"node_modules/@jscad/modeling/src/operations/booleans/subtractGeom2.js"(t,e){var n=ra(),o=va(),i=S9(),r=jYe(),s=qYe(),a=Gen(),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}}),BAi=yt({"node_modules/@jscad/modeling/src/operations/booleans/subtract.js"(t,e){var n=ra(),o=$q(),i=Ta(),r=va(),s=EAi(),a=Gen(),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}}),Yen=yt({"node_modules/@jscad/modeling/src/operations/booleans/unionGeom2.js"(t,e){var n=ra(),o=va(),i=S9(),r=jYe(),s=qYe(),a=eUe(),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}}),tUe=yt({"node_modules/@jscad/modeling/src/operations/booleans/union.js"(t,e){var n=ra(),o=$q(),i=Ta(),r=va(),s=Yen(),a=eUe(),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}}),eX=yt({"node_modules/@jscad/modeling/src/operations/booleans/index.js"(t,e){e.exports={intersect:IAi(),minkowski:Oen(),scission:yAi(),subtract:BAi(),union:tUe()}}}),the=yt({"node_modules/@jscad/modeling/src/operations/expansions/offsetFromPoints.js"(t,e){var{EPS:n,TAU:o}=sc(),i=_en(),r=KYe(),s=lA(),a=$de(),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 T=i(f[0],f[1],k[0],k[1]);T?(I.pop(),k[0]=T):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 T=1;T<E;T++){const H=D+w*T,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 T=b.s0[1];let H=I.findIndex(G=>s.equals(T,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}}),SAi=yt({"node_modules/@jscad/modeling/src/operations/expansions/expandGeom2.js"(t,e){var n=Ta(),o=the(),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}}),bAi=yt({"node_modules/@jscad/modeling/src/operations/expansions/extrudePolygon.js"(t,e){var n=fu(),o=Jr(),i=va(),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}}),QAi=yt({"node_modules/@jscad/modeling/src/operations/expansions/expandShell.js"(t,e){var{EPS:n,TAU:o}=sc(),i=fu(),r=Jr(),s=ken(),a=va(),A=zA(),c=Pen(),l=Zq(),g=Hen(),u=bAi(),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 T=r.scale(r.create(),A.plane(D),2*C),H=A.transform(i.fromTranslation(i.create(),r.scale(r.create(),T,-.5)),D),G=u(T,H);x=g(x,G);const U=D.vertices;for(let Y=0;Y<U.length;Y++){h(E,U[Y],A.plane(D));const q=(Y+1)%U.length,ee=[U[Y],U[q]];d(B,ee,A.plane(D))}}),B.forEach(D=>{const k=D[0],T=D[1],H=k[0],G=k[1],U=r.subtract(r.create(),G,H);r.normalize(U,U);const Y=T[0],q=r.cross(r.create(),Y,U);let ee=[];for(let _e=0;_e<y;_e++)m(ee,_e*o/y);for(let _e=0,ce=T.length;_e<ce;_e++){const Ie=T[_e],he=r.dot(q,Ie),Ce=r.dot(Y,Ie);let Pe=Math.atan2(he,Ce);Pe<0&&(Pe+=o),m(ee,Pe),Pe=Math.atan2(-he,-Ce),Pe<0&&(Pe+=o),m(ee,Pe)}ee=ee.sort(s);const W=ee.length;let J,ie;const oe=[],ne=[],le=[];for(let _e=-1;_e<W;_e++){const ce=ee[_e<0?_e+W:_e],Ie=Math.sin(ce),he=Math.cos(ce);r.scale(b,Y,he*C),r.scale(Q,q,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 ue=a.create(le);x=g(x,ue)}),E.forEach(D=>{const k=D[0],T=D[1],H=T[0];let G=null,U=0;for(let W=1;W<T.length;W++){const J=T[W],ie=r.cross(b,H,J),oe=r.length(ie);oe>.05&&oe>U&&(U=oe,G=J)}G||(G=r.orthogonal(b,H));const Y=r.cross(b,H,G);r.normalize(Y,Y);const q=r.cross(Q,Y,H),ee=c({center:[k[0],k[1],k[2]],radius:C,segments:y,axes:[H,Y,q]});x=g(x,ee)}),l(x)};e.exports=p}}),vAi=yt({"node_modules/@jscad/modeling/src/operations/expansions/expandGeom3.js"(t,e){var n=va(),o=tUe(),i=QAi(),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}}),PAi=yt({"node_modules/@jscad/modeling/src/operations/expansions/expandPath2.js"(t,e){var n=$de(),o=lA(),i=Ta(),r=Jg(),s=the(),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}}),nUe=yt({"node_modules/@jscad/modeling/src/operations/expansions/expand.js"(t,e){var n=ra(),o=Ta(),i=va(),r=Jg(),s=SAi(),a=vAi(),A=PAi(),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}}),wAi=yt({"node_modules/@jscad/modeling/src/operations/expansions/offsetGeom2.js"(t,e){var n=Ta(),o=HYe(),i=the(),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}}),MAi=yt({"node_modules/@jscad/modeling/src/operations/expansions/offsetPath2.js"(t,e){var n=Jg(),o=the(),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}}),DAi=yt({"node_modules/@jscad/modeling/src/operations/expansions/offset.js"(t,e){var n=ra(),o=Ta(),i=Jg(),r=wAi(),s=MAi(),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}}),Uen=yt({"node_modules/@jscad/modeling/src/operations/expansions/index.js"(t,e){e.exports={expand:nUe(),offset:DAi()}}}),nhe=yt({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeLinearGeom2.js"(t,e){var n=fu(),o=Jr(),i=Ta(),r=vG(),s=ehe(),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}}),NAi=yt({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeLinearPath2.js"(t,e){var n=Ta(),o=Jg(),i=nhe(),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}}),RAi=yt({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeLinear.js"(t,e){var n=ra(),o=Ta(),i=Jg(),r=nhe(),s=NAi(),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}}),TAi=yt({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeRectangularPath2.js"(t,e){var n=Jg(),o=nUe(),i=nhe(),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}}),kAi=yt({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeRectangularGeom2.js"(t,e){var{area:n}=Wq(),o=Ta(),i=Jg(),r=nUe(),s=nhe(),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}}),FAi=yt({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeRectangular.js"(t,e){var n=ra(),o=Ta(),i=Jg(),r=TAi(),s=kAi(),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}}),LAi=yt({"node_modules/@jscad/modeling/src/operations/extrusions/extrudeHelical.js"(t,e){var{TAU:n}=sc(),o=fu(),i=Ta(),r=ehe(),s=vG(),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,T=m/x*w,H=(k-u)/n*h;return o.multiply(E,o.fromTranslation(o.create(),[T,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}}),HAi=yt({"node_modules/@jscad/modeling/src/operations/extrusions/project.js"(t,e){var n=ra(),o=UYe(),i=$v(),r=fu(),s=Ta(),a=va(),A=zA(),c=S9(),l=Yen(),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}}),tX=yt({"node_modules/@jscad/modeling/src/operations/extrusions/index.js"(t,e){e.exports={extrudeFromSlices:ehe(),extrudeLinear:RAi(),extrudeRectangular:FAi(),extrudeRotate:Nen(),extrudeHelical:LAi(),project:HAi(),slice:vG()}}}),oUe=yt({"node_modules/@jscad/modeling/src/operations/hulls/hullPoints2.js"(t,e){var n=lA(),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}}),iUe=yt({"node_modules/@jscad/modeling/src/operations/hulls/toUniquePoints.js"(t,e){var n=Ta(),o=va(),i=Jg(),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}}),OAi=yt({"node_modules/@jscad/modeling/src/operations/hulls/hullPath2.js"(t,e){var n=ra(),o=Jg(),i=oUe(),r=iUe(),s=(...a)=>{a=n(a);const A=r(a),c=i(A);return o.fromPoints({closed:!0},c)};e.exports=s}}),GAi=yt({"node_modules/@jscad/modeling/src/operations/hulls/hullGeom2.js"(t,e){var n=ra(),o=Ta(),i=oUe(),r=iUe(),s=(...a)=>{a=n(a);const A=r(a),c=i(A);return c.length<3?o.create():o.fromPoints(c)};e.exports=s}}),YAi=yt({"node_modules/@jscad/modeling/src/operations/hulls/hullGeom3.js"(t,e){var n=ra(),o=va(),i=iUe(),r=ZYe(),s=(...a)=>{a=n(a);const A=i(a);return A.length===0?o.create():o.create(r(A))};e.exports=s}}),Ken=yt({"node_modules/@jscad/modeling/src/operations/hulls/hull.js"(t,e){var n=ra(),o=$q(),i=Ta(),r=va(),s=Jg(),a=OAi(),A=GAi(),c=YAi(),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}}),UAi=yt({"node_modules/@jscad/modeling/src/operations/hulls/hullChain.js"(t,e){var n=ra(),o=tUe(),i=Ken(),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}}),KAi=yt({"node_modules/@jscad/modeling/src/operations/hulls/index.js"(t,e){e.exports={hull:Ken(),hullChain:UAi(),hullPoints2:oUe(),hullPoints3:ZYe()}}}),VAi=yt({"node_modules/@jscad/modeling/src/operations/minkowski/index.js"(t,e){e.exports={minkowskiSum:Oen()}}}),Ven=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}}),zAi=yt({"node_modules/@jscad/modeling/src/operations/modifiers/mergePolygons.js"(t,e){var n=UYe(),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 T=(H,G,U)=>{const Y={v1:U.v1,v2:G.v2,next:G.next,prev:U.prev};U.prev.next=Y,G.next.prev=Y,a(H,G),G.v1=null,G.v2=null,G.next=null,G.prev=null,a(H,U),U.v1=null,U.v2=null,U.next=null,U.prev=null};w[0]===0&&T(C,D,D.prev),w[1]===0&&T(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}}),JAi=yt({"node_modules/@jscad/modeling/src/operations/modifiers/insertTjunctions.js"(t,e){var n=sc(),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],T=y===0?k.vertex0:k.vertex1;if(y===0?k.vertex1:k.vertex0,r(T)===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,U=E,Y=T,q=o.subtract(o.create(),Y,G),ee=o.dot(o.subtract(o.create(),U,G),q)/o.dot(q,q);if(ee>0&&ee<1){const W=o.scale(o.create(),q,ee);if(o.add(W,W,G),o.squaredDistance(W,U)<n.EPS*n.EPS){const ie=k.polygonindex,oe=d[ie],ne=r(k.vertex1);let le=-1;for(let he=0;he<oe.vertices.length;he++)if(r(oe.vertices[he])===ne){le=he;break}const ue=oe.vertices.slice(0);ue.splice(le,0,E);const _e=i.create(ue);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}}),WAi=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}}),jAi=yt({"node_modules/@jscad/modeling/src/operations/modifiers/generalize.js"(t,e){var n=ra(),o=S9(),i=Ta(),r=va(),s=Jg(),a=Ven(),A=zAi(),c=JAi(),l=WAi(),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}}),qAi=yt({"node_modules/@jscad/modeling/src/operations/modifiers/snap.js"(t,e){var n=ra(),o=lA(),i=Ta(),r=va(),s=Jg(),a=S9(),A=Ven(),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}}),XAi=yt({"node_modules/@jscad/modeling/src/operations/modifiers/index.js"(t,e){e.exports={generalize:jAi(),snap:qAi(),retessellate:Zq()}}}),$Ai=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}}),ZAi=yt({"node_modules/@jscad/modeling/src/operations/transforms/align.js"(t,e){var n=ra(),o=$Ai(),i=VYe(),{translate:r}=dR(),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}}),ohe=yt({"node_modules/@jscad/modeling/src/operations/transforms/center.js"(t,e){var n=ra(),o=Ta(),i=va(),r=Jg(),s=gR(),{translate:a}=dR(),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}}}),ihe=yt({"node_modules/@jscad/modeling/src/operations/transforms/scale.js"(t,e){var n=ra(),o=fu(),i=Ta(),r=va(),s=Jg(),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}}}),eci=yt({"node_modules/@jscad/modeling/src/operations/transforms/transform.js"(t,e){var n=ra(),o=Ta(),i=va(),r=Jg(),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}}),mR=yt({"node_modules/@jscad/modeling/src/operations/transforms/index.js"(t,e){e.exports={align:ZAi(),center:ohe().center,centerX:ohe().centerX,centerY:ohe().centerY,centerZ:ohe().centerZ,mirror:qq().mirror,mirrorX:qq().mirrorX,mirrorY:qq().mirrorY,mirrorZ:qq().mirrorZ,rotate:Xq().rotate,rotateX:Xq().rotateX,rotateY:Xq().rotateY,rotateZ:Xq().rotateZ,scale:ihe().scale,scaleX:ihe().scaleX,scaleY:ihe().scaleY,scaleZ:ihe().scaleZ,transform:eci(),translate:dR().translate,translateX:dR().translateX,translateY:dR().translateY,translateZ:dR().translateZ}}}),rhe=yt({"node_modules/@jscad/modeling/src/index.js"(t,e){e.exports={colors:Xde(),curves:Wsi(),geometries:OYe(),maths:Iai(),measurements:Qai(),primitives:hR(),text:rAi(),utils:Fen(),booleans:eX(),expansions:Uen(),extrusions:tX(),hulls:KAi(),minkowski:VAi(),modifiers:XAi(),transforms:mR()}}}),zen=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)}`)}}}}),tci=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":"")}}}),nci=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=tci(),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}}),oci=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 wYe<"u"&&"env"in wYe&&(A=wYe.env.DEBUG),A}function s(){try{return localStorage}catch{}}e.exports=nci()(t);var{formatters:a}=e.exports;a.j=function(A){try{return JSON.stringify(A)}catch(c){return"[UnexpectedJSONParseError]: "+c.message}}}}),rUe=["translucent","opaque","hidden"],ici=t=>rUe[(rUe.indexOf(t)+1)%rUe.length],Jen={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"},Wen=te.createContext(void 0),rci=({children:t})=>{const[e,n]=te.useState(Jen),o=te.useCallback((s,a)=>{n(A=>({...A,[s]:a}))},[]),i=te.useCallback(()=>{n(Jen)},[]),r=te.useMemo(()=>({visibility:e,setLayerVisibility:o,resetToDefaults:i}),[e,o,i]);return K.jsx(Wen.Provider,{value:r,children:t})},pR=()=>{const t=te.useContext(Wen);if(!t)throw new Error("useLayerVisibility must be used within a LayerVisibilityProvider");return t},sUe=1.2;function jen(t){return te.useMemo(()=>{if(!t)return sUe;try{return Cr(t).pcb_board.list()[0]?.thickness??sUe}catch{return sUe}},[t])}var qen=te.createContext(null),jI=()=>{const t=te.useContext(qen);if(!t)throw new Error("useThree must be used within a ThreeProvider");return t},nX=(t,e=[])=>{const{addFrameListener:n,removeFrameListener:o}=jI();ws.useEffect(()=>(n(t),()=>o(t)),[n,o,...e])},oX={clickToInteractOverlay:100,htmlElements:95,orientationCube:95,contextMenu:90,appearanceMenu:91},Xen=({children:t,position:e,style:n})=>{const{camera:o,renderer:i}=jI(),r=te.useRef(document.createElement("div")),[s,a]=te.useState(null);return te.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(dRt.createPortal(t,r.current)),()=>{A.contains(r.current)&&A.removeChild(r.current)}},[i,t]),nX(()=>{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=oX.htmlElements.toString(),n&&Object.assign(r.current.style,n)},[o,i,e,n]),s},$en={in:25.4,inch:25.4,mil:.0254,mm:1,m:1e3,cm:10,ft:304.8,feet:304.8},yA=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 $en)return n*$en[e];throw new Error(`Unsupported unit: ${e}`)},D0=yA,sci=Object.defineProperty,aci=(t,e)=>{for(var n in e)sci(t,n,{get:e[n],enumerable:!0})},MM={};aci(MM,{axial:()=>Lli,bga:()=>Oci,breakoutheaders:()=>Xli,cap:()=>mci,dfn:()=>fli,diode:()=>hci,dip:()=>lci,electrolytic:()=>Jdi,hc49:()=>egi,jst:()=>ldi,led:()=>pci,lqfp:()=>jli,m2host:()=>phi,melf:()=>fui,micromelf:()=>xui,minimelf:()=>lui,mlp:()=>jci,mountedpcbmodule:()=>fhi,ms012:()=>Sli,ms013:()=>Qli,msop:()=>Cdi,pad:()=>tgi,pinrow:()=>Cli,platedhole:()=>shi,potentiometer:()=>Kdi,pushbutton:()=>Uli,qfn:()=>zci,qfp:()=>Wci,quad:()=>wG,radial:()=>Gli,res:()=>Fci,sma:()=>bui,smb:()=>Rui,smbf:()=>jdi,smc:()=>Lui,smf:()=>wui,smtpad:()=>ihi,sod110:()=>udi,sod123:()=>Rli,sod123f:()=>Fgi,sod123fl:()=>Ggi,sod123w:()=>_gi,sod128:()=>jgi,sod323:()=>ygi,sod323f:()=>Ngi,sod323fl:()=>bdi,sod323w:()=>xdi,sod523:()=>agi,sod723:()=>Vgi,sod80:()=>dgi,sod882:()=>Pgi,sod882d:()=>hui,sod923:()=>Sgi,soic:()=>Yci,solderjumper:()=>Tdi,son:()=>wdi,sop8:()=>ggi,sot:()=>Ahi,sot223:()=>Yui,sot23:()=>gli,sot23w:()=>Xui,sot25:()=>mli,sot323:()=>ehi,sot343:()=>uhi,sot363:()=>ili,sot457:()=>Ldi,sot563:()=>Eli,sot723:()=>Pli,sot886:()=>ali,sot89:()=>rui,sot963:()=>Gdi,ssop:()=>$ci,stampboard:()=>Vli,stampreceiver:()=>Wli,to220:()=>_tn,to220f:()=>Aui,to92:()=>rgi,to92l:()=>xhi,to92s:()=>odi,tqfp:()=>Jci,tssop:()=>tli,vson:()=>Ddi,vssop:()=>_di});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"}),Xi=Pt({norefdes:We().optional().describe("disable reference designator label"),invert:We().optional().describe("hint to invert the orientation of the 3D model"),faceup:We().optional().describe("The male pin header should face upwards, out of the top layer"),nosilkscreen:We().optional().describe("omit all silkscreen elements from the footprint")}),ka=(t,e,n,o,i)=>({pcb_plated_hole_id:"",type:"pcb_plated_hole",shape:"circle",x:e,y:n,hole_diameter:yA(o),outer_diameter:yA(i),pcb_port_id:"",layers:["top","bottom"],port_hints:[t.toString()]}),yE=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:yA(i),hole_shape:"circle",pad_shape:"rect",rect_pad_width:yA(r),rect_pad_height:yA(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}},she=Array.from({length:9},(t,e)=>Math.cos(e/8*Math.PI-Math.PI)).map(t=>({x:t,y:-Math.sqrt(1-t**2)})),T1=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 b9(t){return typeof t=="string"?t.trim().toLowerCase().endsWith("mil")?parseFloat(t)*.0254:parseFloat(t):Number(t)}var ahe=Eo([Z(),ft()]).transform(t=>b9(t)),Aci=t=>Xi.extend({fn:Z(),num_pins:ft().optional().default(6),wide:We().optional(),narrow:We().optional(),w:ahe.optional(),p:ahe.default(t.p??"2.54mm"),id:ahe.optional(),od:ahe.optional(),nosquareplating:We().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=b9("0.55mm"),e.od=b9("0.95mm")):(e.id=b9("0.8mm"),e.od=b9("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=b9("600mil"):e.narrow?e.w=b9("300mil"):e.w=b9(t.w??"300mil")),e)),cci=Aci({}),Zen=(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}},lci=t=>{const e=cci.parse(t),n=[];for(let _=0;_<e.num_pins;_++){const{x:f,y:I}=Zen(e.num_pins,_+1,e.w,e.p??2.54,e.nosquareplating);if(_===0&&!e.nosquareplating){n.push(yE({pn:_+1,x:f,y:I,holeDiameter:e.id??"0.8mm",rectPadWidth:e.od??"1mm",rectPadHeight:e.od??"1mm"}));continue}n.push(ka(_+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},...she.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}=Zen(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:T1([{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}},Ci=(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()]}),etn=[{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}}],gci=Object.fromEntries(etn.map(t=>[t.metric,t])),uci=Object.fromEntries(etn.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"});Xi.extend({fn:Z().optional(),string:Z().optional(),tht:We(),p:de.optional(),pw:de.optional(),ph:de.optional(),metric:At.optional(),imperial:At.optional(),w:de.optional(),h:de.optional(),nonpolarized:We().optional(),textbottom:We().optional(),roundedPads:We().optional()});var Ahe=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=D0(A)),typeof c=="string"&&(c=D0(c)),typeof o=="string"&&(o=D0(o)),typeof i=="string"&&(i=D0(i)),typeof r=="string"&&(r=D0(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=gci[s]),a&&(d=uci[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?[ka(1,-o/2,0,i,i*1/.8),ka(2,o/2,0,i,i*1/.8),...m,f,...I?[I]:[]]:[Ci(["1","left"],-o/2,0,i,r,C),Ci(["2","right"],o/2,0,i,r,C),...m,f,...I?[I]:[]]},hci=t=>({circuitJson:Ahe({...t,roundedPads:!0}),parameters:t}),mci=t=>({circuitJson:Ahe(t),parameters:t}),pci=t=>({circuitJson:Ahe(t).map(n=>n.type!=="pcb_silkscreen_path"?n:{...n,route:n.route.map(o=>({...o,x:-o.x}))}),parameters:t}),PG=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(Ci(w+1,-e/2,Q,n,o))}),A.slice().reverse().forEach((Q,w)=>{l.push(Ci(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]:[]]},_ci=Xi.extend({pw:de.default("0.5mm"),ph:de.default("0.4mm"),p:de.default("0.7mm"),textbottom:We().optional(),convex:We().optional(),concave:We().optional()}),fci=1,Ici=t=>{const e=_ci.parse(t);if(e.concave===!0)return[];const n=D0(e.pw),o=D0(e.ph),i=D0(e.p);return PG({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}]})},Cci=Xi.extend({pw:de.default("0.5mm"),ph:de.default("0.32mm"),p:de.default("0.5mm"),textbottom:We().optional(),convex:We().optional(),concave:We().optional()}),yci=1,xci=t=>{const e=Cci.parse(t),n=D0(e.pw),o=D0(e.ph),i=D0(e.p);return PG({padSpacing:yci,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}]})},Eci=Xi.extend({pw:de.default("0.9mm"),ph:de.default("0.4mm"),p:de.default("0.8mm"),textbottom:We().optional(),convex:We().optional(),concave:We().optional()}),Bci=1.7,Sci=t=>{const e=Eci.parse(t),n=D0(e.pw),o=D0(e.ph),i=D0(e.p);return PG({padSpacing:Bci,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}]})},bci=Xi.extend({pw:de.default("0.9mm"),ph:de.default("0.4mm"),p:de.default("0.8mm"),textbottom:We().optional(),convex:We().optional(),concave:We().optional()}),Qci=1.7,vci=t=>{const e=bci.parse(t),n=D0(e.pw),o=D0(e.ph),i=D0(e.p);return PG({padSpacing:Qci,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}]})},Pci=Xi.extend({pw:de.default("0.7mm"),ph:de.default("0.64mm"),p:de.default("0.94mm"),textbottom:We().optional(),convex:We().optional(),concave:We().optional()}),wci=1.4,Mci=t=>{const e=Pci.parse(t),n=D0(e.pw),o=D0(e.ph),i=D0(e.p);return PG({padSpacing:wci,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}]})},Dci=Xi.extend({pw:de.default("0.9mm"),ph:de.default("0.9mm"),p:de.default("1.34mm"),textbottom:We().optional(),convex:We().optional(),concave:We().optional()}),Nci=3,Rci=t=>{const e=Dci.parse(t),n=D0(e.pw),o=D0(e.ph),i=D0(e.p);return PG({padSpacing:Nci,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}]})},Tci=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)}},kci=t=>t?(typeof t=="number"?`${t}`:t).split(/[_x]/)[0]:void 0,Fci=t=>{const e=Tci(t),n=kci(t.imperial);return e===2&&n==="0402"?{circuitJson:Ici(t),parameters:t}:e===4&&n==="0402"?{circuitJson:xci(t),parameters:t}:e===2&&n==="0603"?{circuitJson:Sci(t),parameters:t}:e===4&&n==="0603"?{circuitJson:vci(t),parameters:t}:e===2&&n==="0606"?{circuitJson:Mci(t),parameters:t}:e===4&&n==="1206"?{circuitJson:Rci(t),parameters:t}:{circuitJson:Ahe(t),parameters:t}},ttn=(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()]}),ntn="ABCDEFGHIJKLMNOPQRSTUVWXYZ",che=Z().transform(t=>{const[e,n]=t.split(/[x ]/);return{x:parseFloat(e??""),y:parseFloat(n??"")}}).pipe(Pt({x:ft(),y:ft()})),Lci=Z().or(dn(Vd())).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()))),Hci=Xi.extend({fn:Z(),num_pins:ft().optional().default(64),grid:che.optional(),p:At.default("0.8mm"),w:de.optional(),h:de.optional(),ball:de.optional().describe("ball diameter"),pad:de.optional().describe("pad width/height"),circularpads:We().optional().describe("use circular pads"),tlorigin:We().optional(),blorigin:We().optional(),trorigin:We().optional(),brorigin:We().optional(),missing:Lci.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=ntn.indexOf(i[1]),s=Number.parseInt(i[2])-1;return r*t.grid.x+s+1})),{...t,origin:e}}),Oci=t=>{const e=Hci.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)),q=Math.floor((o.x-Y)/2),ee=Math.floor((o.y-Y)/2);for(let W=ee;W<ee+Y;W++)for(let J=q;J<q+Y;J++)g.push(W*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 q=0;q<o.x;q++){const ee=(q-(o.x-1)/2)*i,W=(Y-(o.y-1)/2)*i;let J=q,ie=Y;switch(e.origin){case"bl":J=q,ie=o.y-1-Y;break;case"br":J=o.x-1-q,ie=o.y-1-Y;break;case"tr":J=o.x-1-q,ie=Y;break}let oe=ie*o.x+J+1;if(h.has(oe)){d++;continue}oe-=d;const ne=[oe,`${ntn[ie]}${J+1}`];l.push(e.circularpads?ttn(ne,{x:ee,y:W,radius:A/2}):Ci(ne,ee,W,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,T=k,H=Q+D,G=H,U={type:"pcb_courtyard_outline",pcb_courtyard_outline_id:"",pcb_component_id:"",outline:T1([{minX:-k,maxX:k,minY:-G,maxY:G},{minX:-T,maxX:T,minY:-H,maxY:H}]),layer:"top"};return{circuitJson:[...l,m,C,U],parameters:e}},lhe=(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()]}),_R=t=>Xi.extend({fn:Z(),num_pins:ft().optional().default(8),w:de.default(de.parse(t.w??"5.3mm")),p:de.default(de.parse(t.p??"1.27mm")),pw:de.default(de.parse(t.pw??"0.6mm")),pl:de.default(de.parse(t.pl??"1.0mm")),legsoutside:We().optional().default(t.legsoutside??!1),pillpads:We().optional().default(t.pillpads??!1),silkscreen_stroke_width:ft().optional().default(.1)}).transform(e=>(!e.pw&&!e.pl?(e.pw=de.parse("0.6mm"),e.pl=de.parse("1.0mm")):e.pw?e.pl||(e.pl=e.pw*(1/.6)):e.pw=e.pl*(.6/1),e)),Gci=_R({}),aUe=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}},Yci=t=>{const e=Gci.parse(t);return{circuitJson:iX(e),parameters:e}},iX=t=>{const e=[];let n=0,o=0;for(let p=0;p<t.num_pins;p++){const{x:_,y:f}=aUe({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(lhe(p+1,_,f,t.pl,t.pw)):e.push(Ci(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},...she.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:T1([{minX:-g,maxX:g,minY:-u,maxY:u},{minX:-h,maxX:h,minY:-d,maxY:d}])};return[...e,A,a,m]},otn=Vn(["leftside","topside","rightside","bottomside","toppin","bottompin","leftpin","rightpin"]),Uci=({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},AUe=Xi.extend({fn:Z(),cc:We().default(!0).optional(),ccw:We().default(!0).optional(),startingpin:Z().or(dn(otn)).transform(t=>typeof t=="string"?t.slice(1,-1).split(","):t).pipe(dn(otn)).optional(),num_pins:ft().optional().default(64),w:de.optional(),h:de.optional(),p:de.default(de.parse("0.5mm")),pw:de.optional(),pl:de.optional(),thermalpad:Eo([qe(!0),che]).optional(),legsoutside:We().default(!1)}),cUe=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},itn=AUe.transform(cUe),Kci=["left","bottom","right","top"],Vci=t=>{const{pin_count:e,pn:n,w:o,h:i,p:r,pl:s,legsoutside:a}=t,A=e/4,c=Kci[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")}},wG=t=>{const e=itn.parse(t),n=[];let o=0,i=0;const r=Uci(e),s=e.num_pins/4;for(let I=0;I<e.num_pins;I++){const{x:C,y,o:x}=Vci({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(Ci(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(Ci(["thermalpad"],0,0,I,C))}else o=Math.max(o,e.thermalpad.x/2),i=Math.max(i,e.thermalpad.y/2),n.push(Ci(["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,T=B==="in1"?e.pw/2:e.pl/2;b+=k*C*D,Q-=T*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:T1([{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}};AUe.extend({}).transform(cUe);var zci=t=>(t.legsoutside=!1,t.pl||(t.pl=.875),t.pw||(t.pw=.25),wG(t)),Jci=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 wG(t)},Wci=t=>{t.legsoutside=!0;const e=itn.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 wG(t)};AUe.extend({}).transform(cUe);var jci=t=>(t.legsoutside=!1,t.thermalpad===void 0&&(t.thermalpad=!0),wG(t)),qci=Xi.extend({fn:Z(),num_pins:ft().optional().default(8),w:de.default(de.parse("3.9mm")),p:de.default(de.parse("1.27mm")),pw:de.optional(),pl:de.optional(),legsoutside:We().optional().default(!1),silkscreen_stroke_width:ft().optional().default(.1)}).transform(t=>(t.pw==null&&t.pl==null?(t.pw=de.parse("0.51mm"),t.pl=de.parse("1.1mm")):t.pw==null?t.pw=t.pl*(.51/1.1):t.pl==null&&(t.pl=t.pw*(1.1/.51)),t)),Xci=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+de.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}},$ci=t=>{const e=qci.parse(t),n=[];for(let p=0;p<e.num_pins;p++){const{x:_,y:f}=Xci({num_pins:e.num_pins,pn:p+1,w:e.w,p:e.p,pl:e.pl,legsoutside:e.legsoutside});n.push(Ci(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},...she.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:T1([{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}},Zci=Xi.extend({fn:Z(),num_pins:ft().optional().default(8),w:de.default(de.parse("3.0mm")),p:de.default(de.parse("0.5mm")),pw:de.default(de.parse("0.30mm")),pl:de.default(de.parse("1.45mm")),legsoutside:We().optional().default(!0),silkscreen_stroke_width:ft().optional().default(.1)}),eli=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}},tli=t=>{const e={...t},n=e.p,o=typeof n=="string"||typeof n=="number"?de.parse(n):void 0,i=o!=null&&o<=de.parse("0.5mm"),r=Zci.parse(e),s=[],a=i?r.w-de.parse("0.15mm"):r.w;for(let C=0;C<r.num_pins;C++){const{x:y,y:x}=eli({num_pins:r.num_pins,pn:C+1,w:a,p:r.p,pl:r.pl,legsoutside:r.legsoutside});s.push(Ci(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},...she.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:T1([{minX:-p,maxX:p,minY:-_,maxY:_},{minX:-m,maxX:m,minY:-f,maxY:f}])};return{circuitJson:[...s,u,g,I],parameters:r}},nli=[{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}],oli=Xi.extend({fn:Z(),num_pins:qe(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()}),ili=t=>{const e=oli.parse({...t,fn:"sot363"}),n=de.parse(e.w),o=de.parse(e.h),i=de.parse(e.p),r=de.parse(e.pl),s=de.parse(e.pw),a=[];for(let d=0;d<6;d++){const{x:m,y:p}=rtn(d+1,n,i);a.push(Ci(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=rtn(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:nli,layer:"top"};return{circuitJson:[...a,A,c,u,g,h],parameters:e}},rtn=(t,e,n,o)=>t<=3?{x:-.84,y:n-(t-1)*n}:{x:.84,y:-n+(t-4)*n},rli=[{x:-.75,y:1},{x:-.75,y:-1},{x:.75,y:-1},{x:.75,y:1}],sli=Xi.extend({fn:Z(),num_pins:qe(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()}),ali=t=>{const e=sli.parse({...t,fn:"sot886"}),n=de.parse(e.w),o=de.parse(e.h),i=de.parse(e.p),r=de.parse(e.pl),s=de.parse(e.pw),a=[];for(let d=0;d<6;d++){const{x:m,y:p}=stn(d+1,n,i,r);a.push(Ci(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=stn(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:rli,layer:"top"};return{circuitJson:[...a,A,c,u,g,h],parameters:e}},stn=(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}},Ali=[{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}],cli=[{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}],atn=Xi.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()}),lli=_R({p:"0.95mm",w:"1.6mm",legsoutside:!0}),gli=t=>{const e=t.string?.match(/^sot23_(\d+)/),n=e?Number.parseInt(e[1],10):3;if(n===6||n===8){const i=lli.parse({...t,num_pins:n});return{circuitJson:iX(i),parameters:i}}const o=atn.parse({...t,num_pins:n});if(o.num_pins===3)return{circuitJson:dli(o),parameters:o};if(o.num_pins===5)return{circuitJson:ctn(o),parameters:o};throw new Error("Invalid number of pins")},uli=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}=uli({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(Ci(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:Ali,layer:"top"};return[...e,n,o]},Atn=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")},ctn=t=>{const e=[];for(let u=1;u<=t.num_pins;u++){const{x:h,y:d}=Atn({h:Number.parseFloat(t.h),p:Number.parseFloat(t.p),pn:u});e.push(Ci(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=Atn({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:cli,layer:"top"};return[...e,s,i,r,l,g]},hli=atn.extend({}),mli=t=>{const e=hli.parse({...t,num_pins:5});return{circuitJson:ctn(e),parameters:e}},pli=[{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}],_li=_R({}),fli=t=>{const e=_li.parse(t),n=[];for(let p=0;p<e.num_pins;p++){const{x:_,y:f}=aUe({num_pins:e.num_pins,pn:p+1,w:e.w,p:e.p??1.27,pl:e.pl,widthincludeslegs:!0});n.push(Ci(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 pli){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}},fR=({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 ltn({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 Ili=Xi.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:de.default("0.1in").describe("pitch"),id:de.default("1.0mm").describe("inner diameter"),od:de.default("1.5mm").describe("outer diameter"),male:We().optional().describe("for male pin headers"),female:We().optional().describe("for female pin headers"),smd:We().optional().describe("surface mount device"),surfacemount:We().optional().describe("surface mount device (verbose)"),rightangle:We().optional().describe("right angle"),pw:de.optional().default("1.0mm").describe("pad width for SMD"),pl:de.optional().default("2.0mm").describe("pad length for SMD"),pinlabeltextalignleft:We().optional().default(!1),pinlabeltextaligncenter:We().optional().default(!1),pinlabeltextalignright:We().optional().default(!1),pinlabelverticallyinverted:We().optional().default(!1),pinlabelorthogonal:We().optional().default(!1),nosquareplating:We().optional().default(!1).describe("do not use rectangular pad for pin 1"),nopinlabels:We().optional().default(!1).describe("omit silkscreen pin labels"),doublesidedpinlabel:We().optional().default(!1).describe("add silkscreen pins in top and bottom layers"),bottomsidepinlabel:We().optional().default(!1).describe("place the silkscreen reference text on the bottom layer instead of top")}).transform(t=>{const e=ltn(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"]})}),Cli=t=>{const e=Ili.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:ee,yoff:W,od:J,anchorSide:ie,smd:oe,pw:ne,pl:le})=>{let ue=0,_e=0;if(oe){const ce=J/5;switch(ie){case"right":ue=ne/2+ce;break;case"top":_e=le/2+ce;break;case"bottom":_e=-(le/2+ce);break;case"left":ue=-(ne/2+ce);break}}else{const ce=J*.75;switch(ie){case"right":ue=ce;break;case"top":_e=ce;break;case"bottom":_e=-ce;break;case"left":ue=-ce;break}}return{anchor_x:ee+ue,anchor_y:W+_e}},x=(ee,W,J)=>{e.smd?p.push(Ci(ee,W,J,e.pw,e.pl)):ee===1&&!e.nosquareplating?p.push(yE({pn:ee,x:W,y:J,holeDiameter:o,rectPadWidth:i,rectPadHeight:i})):p.push(ka(ee,W,J,o,i));const{anchor_x:ie,anchor_y:oe}=y({xoff:W,yoff:J,od:i,anchorSide:a,smd:e.smd,pw:e.pw,pl:e.pl});u||(d?p.push(fR({fs:i/5,pn:ee,anchor_x:ie,anchor_y:oe,textalign:m,orthogonal:c,verticallyinverted:A,layer:"bottom"})):p.push(fR({fs:i/5,pn:ee,anchor_x:ie,anchor_y:oe,textalign:m,orthogonal:c,verticallyinverted:A,layer:"top"})),h&&p.push(fR({fs:i/5,pn:ee,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 ee=-((s-1)/2)*n;for(let W=0;W<s;W++){const J=W+1,ie=ee+W*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 ee=-((_-1)/2)*n;let W=1;for(let J=0;J<r&&W<=s;J++)for(let ie=0;ie<_&&W<=s;ie++){const oe=ee+ie*n,ne=I+J*C,le=`${oe},${ne}`;if(E.has(le))throw new Error(`Overlap at ${le}`);E.add(le),x(W++,oe,ne)}}else{const ee=-((_-1)/2)*n;let W=1,J=0,ie=r-1,oe=0,ne=_-1;for(;W<=s&&J<=ie&&oe<=ne;){for(let le=J;le<=ie&&W<=s;le++){const ue=ee+oe*n,_e=I+le*C,ce=`${ue},${_e}`;if(E.has(ce))throw new Error(`Overlap at ${ce}`);E.add(ce),x(W++,ue,_e)}oe++;for(let le=oe;le<=ne&&W<=s;le++){const ue=ee+le*n,_e=I+ie*C,ce=`${ue},${_e}`;if(E.has(ce))throw new Error(`Overlap at ${ce}`);E.add(ce),x(W++,ue,_e)}if(ie--,oe<=ne){for(let le=ie;le>=J&&W<=s;le--){const ue=ee+ne*n,_e=I+le*C,ce=`${ue},${_e}`;if(E.has(ce))throw new Error(`Overlap at ${ce}`);E.add(ce),x(W++,ue,_e)}ne--}if(J<=ie){for(let le=ne;le>=oe&&W<=s;le--){const ue=ee+le*n,_e=I+J*C,ce=`${ue},${_e}`;if(E.has(ce))throw new Error(`Overlap at ${ce}`);E.add(ce),x(W++,ue,_e)}J++}}if(W-1<s)throw new Error(`Missing pins: assigned ${W-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,T=f/2+w,H=D/2+n/2,G=f/2+n/2,U=Math.max(k+.25,H+.5),Y=Math.max(T+.25,G+.5),q={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:0,y:0},width:2*U,height:2*Y,layer:"top"};return{circuitJson:[...p,b,q],parameters:e}},yli=[{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}],xli=Xi.extend({fn:Z(),num_pins:qe(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()}),Eli=t=>{const e=xli.parse({...t,fn:"sot563"}),n=de.parse(e.w),o=de.parse(e.h),i=de.parse(e.p),r=de.parse(e.pl),s=de.parse(e.pw),a=[];for(let d=0;d<6;d++){const{x:m,y:p}=gtn(d+1,n,i,r);a.push(Ci(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=gtn(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:yli,layer:"top"};return{circuitJson:[...a,A,c,u,g,h],parameters:e}},gtn=(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}},Bli=_R({p:"1.27mm",w:"3.9mm",legsoutside:!0}),Sli=t=>{const e=Bli.parse({...t,num_pins:8});return{circuitJson:iX(e),parameters:e}},bli=_R({p:"1.27mm",w:"7.5mm",legsoutside:!0}),Qli=t=>{const e=bli.parse({...t,num_pins:16});return{circuitJson:iX(e),parameters:e}},vli=Xi.extend({fn:Z(),num_pins:qe(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")}),Pli=t=>{const e=vli.parse(t),n=Mli(e),o=nr(0,de.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}},wli=t=>{const{pn:e,p:n}=t;return e===1?{x:n,y:0}:e===2?{x:-n,y:-.4}:{x:-n,y:.4}},Mli=t=>{const e=[];for(let n=0;n<3;n++){const{x:o,y:i}=wli({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(Ci(n+1,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return e},ly=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=de.parse(e),o=de.parse(t.pl),i=de.parse(t.pw);return Dli({minX:-n/2-o/2,maxX:n/2+o/2,minY:-i/2,maxY:i/2})},Dli=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},Nli=Xi.extend({fn:Z(),num_pins:qe(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")}),Rli=t=>{const e=Nli.parse(t),n=de.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:kli(e).concat(...ly(e),o,s),parameters:e}},Tli=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},kli=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=Tli({pn:n,p:Number.parseFloat(t.p)});e.push(Ci(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw),.1125))}return e},Fli=Xi.extend({fn:Z(),p:de.optional().default("2.54mm"),id:de.optional().default("0.7mm"),od:de.optional().default("1.4mm")}),Lli=t=>{const e=Fli.parse(t),{p:n,id:o,od:i}=e,r=[ka(1,-n/2,0,o,i),ka(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:T1([{minX:u,maxX:h,minY:-_,maxY:_},{minX:m,maxX:p,minY:-d,maxY:d}]),layer:"top"};return{circuitJson:[...r,s,a,f],parameters:e}},Hli=(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}},Oli=Xi.extend({fn:Z(),p:de.optional().default("5mm"),id:de.optional().default("0.8mm"),od:de.optional().default("1.6mm"),ceramic:We().optional(),electrolytic:We().optional(),polarized:We().optional()}),Gli=t=>{const e=Oli.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=[ka(1,-n/2,0,e.id,e.od),ka(2,n/2,0,e.id,e.od)],s=n+.1,{topArc:a,bottomArc:A}=Hli(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}},IR=(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}),Yli=Xi.extend({fn:qe("pushbutton"),w:de.default(4.5),h:de.default(6.5),id:de.default(1),od:de.default(1.2)}),Uli=t=>{const e=Yli.parse(t),n=e.w,o=e.h,i=e.id,r=[ka(1,-n/2,o/2,i,i*1.5),ka(2,-n/2,-o/2,i,i*1.5),ka(3,n/2,-o/2,i,i*1.5),ka(4,n/2,o/2,i,i*1.5)],s=[IR([{x:-n/2,y:-o/2},{x:-n/2,y:o/2}]),IR([{x:n/2,y:-o/2},{x:n/2,y:o/2}]),IR([{x:-n/2,y:0},{x:-n/5,y:0},{x:n/5*1/Math.sqrt(2),y:o/8}]),IR([{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}},utn=Xi.extend({fn:Z(),w:de.default("22.58mm"),h:de.optional(),left:de.optional().default(20),right:de.optional().default(20),top:de.optional().default(2),bottom:de.optional().default(2),p:de.default(de.parse("2.54mm")),pw:de.default(de.parse("1.6mm")),pl:de.default(de.parse("2.4mm")),innerhole:We().default(!1),innerholeedgedistance:de.default(de.parse("1.61mm")),silkscreenlabels:We().default(!1),silkscreenlabelmargin:de.default(de.parse("0.1mm"))}),Kli=t=>{const e=utn.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},ghe=(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},Vli=t=>{const e=utn.parse(t),n=e.h??Kli(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=ghe(e.w/2-e.pl*1.4,m+p*e.p,"right")),o.push(Ci(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(ka(p+1+e.left+(e.bottom??0)+c,e.w/2,m+p*e.p,a,A)),i.push(ka(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=ghe(-e.w/2+e.pl*1.4,m-p*e.p,"left")),o.push(Ci(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(ka(p+1+c,-e.w/2,m-p*e.p,a,A)),i.push(ka(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=ghe(m-p*e.p,n/2-e.pl*1.4,"top")),o.push(Ci(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(ka(p+1+e.left+e.right+(e.bottom??0)+c,m-p*e.p,n/2,a,A)),i.push(ka(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=ghe(m+p*e.p,-n/2+e.pl*1.4,"bottom")),o.push(Ci(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(ka(p+1+e.left+c,m+p*e.p,-n/2,a,A)),i.push(ka(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}},dtn=Xi.extend({fn:Z(),w:de.default("22.58mm"),h:de.optional(),left:de.optional().default(20),right:de.optional().default(20),top:de.optional().default(2),bottom:de.optional().default(2),p:de.default(de.parse("2.54mm")),pw:de.default(de.parse("1.6mm")),pl:de.default(de.parse("3.2mm")),innerhole:We().default(!1),innerholeedgedistance:de.default(de.parse("1.61mm"))}),zli=t=>{const e=dtn.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},Jli=(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]},Wli=t=>{const e=dtn.parse(t),n=e.h??zli(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=Jli(-e.w/2-e.pl/2,d-m*e.p,"left")),o.push(Ci(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(ka(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(Ci(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(ka(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(Ci(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(ka(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(Ci(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(ka(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}},jli=t=>(t.legsoutside=!0,t.pl||(t.pl=1.5),t.pw||(t.pw=.3),wG(t)),htn=Xi.extend({fn:Z(),w:de.default("10mm"),h:de.optional(),left:de.optional().default(20),right:de.optional().default(20),top:de.optional().default(0),bottom:de.optional().default(0),p:de.default(de.parse("2.54mm")),id:de.optional().default(de.parse("1mm")),od:de.optional().default(de.parse("1.5mm"))}),qli=t=>{const e=htn.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},uhe=(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]},Xli=t=>{const e=htn.parse(t),n=e.h??qli(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=uhe(e.w/2+r*1.4,l+g*e.p,"right")),o.push(ka(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=uhe(-e.w/2-r*1.4,l+g*e.p,"left")),o.push(ka(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=uhe(l+g*e.p,n/2+r*1.4,"top")),o.push(ka(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=uhe(l+g*e.p,-n/2-r*1.4,"bottom")),o.push(ka(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}},$li=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)]},mtn=(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}}),Zli=Xi.extend({fn:Z(),p:de.optional().default("4.88mm"),id:de.optional().default("0.8mm"),od:de.optional().default("1.5mm"),w:de.optional().default("5.6mm"),h:de.optional().default("3.5mm")}),egi=t=>{const e=Zli.parse(t),{p:n,id:o,od:i,w:r,h:s}=e,a=s/2,A=[ka(1,-n/2,0,o,i),ka(2,n/2,0,o,i)],c=mtn(-r/2,0,a,"left"),l=mtn(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:$li({centerX:0,centerY:0,straightHalfLength:d,radius:m,arcSegmentCount:9}),layer:"top"};return{circuitJson:[...A,g,u,p],parameters:e}};Xi.extend({w:de,h:de});var tgi=t=>{const{w:e,h:n}=t,o=yA(e),i=yA(n);return{circuitJson:[Ci(1,0,0,o,i),nr(0,i/2+.5,.2)],parameters:t}},Q9=(t,e,n,o,i,r)=>({pcb_plated_hole_id:"",type:"pcb_plated_hole",shape:"pill",x:e,y:n,outer_width:yA(i),outer_height:yA(r),hole_width:yA(o),hole_height:yA(o),pcb_port_id:"",layers:["top","bottom"],port_hints:[t.toString()],ccw_rotation:0}),ngi=[{x:-2.73,y:3.71},{x:-2.73,y:-1.03},{x:2.73,y:-1.03},{x:2.73,y:3.71}],ogi=Xi.extend({fn:Z(),num_pins:Eo([qe(3),qe(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:We().default(!1),string:Z().optional()}),igi=(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}}),rgi=t=>{const e=t.string?.match(/^to92_(\d+)/),n=e?Number.parseInt(e[1],10):3,o=ogi.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=[yE({pn:1,x:-g,y:l-g,holeDiameter:u,rectPadWidth:h,rectPadHeight:m}),Q9(2,0,l-g,u,d,m),Q9(3,g,l-g,u,d,m)]:p=[yE({pn:1,x:-g,y:l-g,holeDiameter:u,rectPadWidth:h,rectPadHeight:h}),ka(2,0,l,u,h),ka(3,g,l-g,u,h)];else if(o.num_pins===2)p=[yE({pn:1,x:-g,y:l-g,holeDiameter:u,rectPadWidth:d,rectPadHeight:m}),Q9(2,g,l-g,u,d,m)];else throw new Error("Invalid number of pins for TO-92");const _=Number.parseFloat(a)/2,f=igi(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:ngi,layer:"top"};return{circuitJson:[...p,I,C,y],parameters:o}},sgi=Xi.extend({fn:Z(),num_pins:qe(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")}),agi=t=>{const e=sgi.parse(t),n=nr(0,de.parse(e.h),.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:de.parse(e.p)/2,y:de.parse(e.h)/2+.2},{x:-de.parse(e.w)/2-.2,y:de.parse(e.h)/2+.2},{x:-de.parse(e.w)/2-.2,y:-de.parse(e.h)/2-.2},{x:de.parse(e.p)/2,y:-de.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:cgi(e).concat(...ly(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}},cgi=t=>{const e=[],n=de.parse(t.p),o=de.parse(t.pl),i=de.parse(t.pw),r=.075;for(let s=1;s<=t.num_pins;s++){const{x:a,y:A}=Agi({pn:s,p:n});e.push(Ci(s,a,A,o,i,r))}return e},lgi=_R({w:"7.05mm",p:"1.27mm",pw:"0.65mm",pl:"1.975mm"}),ggi=t=>{const e=lgi.parse(t),n=[];for(let u=0;u<e.num_pins;u++){const{x:h,y:d}=aUe({num_pins:e.num_pins,pn:u+1,w:e.w,p:e.p??1.27,pl:e.pl,widthincludeslegs:!0});n.push(Ci(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:T1([{minX:-A,maxX:A,minY:-c,maxY:c},{minX:-a,maxX:a,minY:-l,maxY:l}])};return{circuitJson:[...n,i,r,g],parameters:e}},ugi=Xi.extend({fn:Z(),num_pins:qe(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")}),dgi=t=>{const e=ugi.parse(t),n=nr(0,de.parse(e.h)/2+1,.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:de.parse(e.p)/2+.5,y:de.parse(e.h)/2+.5},{x:-de.parse(e.w)/2-.5,y:de.parse(e.h)/2+.5},{x:-de.parse(e.w)/2-.5,y:-de.parse(e.h)/2-.5},{x:de.parse(e.p)/2+.5,y:-de.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:mgi(e).concat(...ly(e),o,n,s),parameters:e}},hgi=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}=hgi({pn:n,p:Number.parseFloat(t.p)});e.push(Ci(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return e},pgi=Xi.extend({fn:Z(),num_pins:qe(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")}),_gi=t=>{const e=pgi.parse(t),n=nr(0,de.parse(e.h)-.5,.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:de.parse(e.p)/2,y:de.parse(e.h)/2},{x:-de.parse(e.w)/2-.2,y:de.parse(e.h)/2},{x:-de.parse(e.w)/2-.2,y:-de.parse(e.h)/2},{x:de.parse(e.p)/2,y:-de.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:Igi(e).concat(...ly(e),o,n,s),parameters:e}},fgi=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},Igi=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=fgi({pn:n,p:Number.parseFloat(t.p)});e.push(Ci(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return e},Cgi=Xi.extend({fn:Z(),num_pins:qe(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")}),ygi=t=>{const e=Cgi.parse(t),n=nr(0,de.parse(e.h)-.5,.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:de.parse(e.p)/2,y:de.parse(e.h)/2},{x:-de.parse(e.w)/2,y:de.parse(e.h)/2},{x:-de.parse(e.w)/2,y:-de.parse(e.h)/2},{x:de.parse(e.p)/2,y:-de.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(...ly(e),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}},Egi=t=>{const e=[],n=de.parse(t.p),o=de.parse(t.pl),i=de.parse(t.pw),r=.05625;for(let s=1;s<=t.num_pins;s++){const{x:a,y:A}=xgi({pn:s,p:n});e.push(Ci(s,a,A,o,i,r))}return e},Bgi=Xi.extend({fn:Z(),num_pins:qe(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")}),Sgi=t=>{const e=Bgi.parse(t),n=de.parse(e.w),o=de.parse(e.h),i=de.parse(e.pl),r=de.parse(e.pw),s=de.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:T1([{minX:-I,maxX:I,minY:-x,maxY:x},{minX:-C,maxX:C,minY:-y,maxY:y}]),layer:"top"};return{circuitJson:Qgi(e).concat(...ly(e),A,a,E),parameters:e}},bgi=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},Qgi=t=>{const e=[],n=de.parse(t.p),o=de.parse(t.pl),i=de.parse(t.pw),r=.03125;for(let s=1;s<=t.num_pins;s++){const{x:a,y:A}=bgi({pn:s,p:n});e.push(Ci(s,a,A,o,i,r))}return e},vgi=Xi.extend({fn:Z(),num_pins:qe(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")}),Pgi=t=>{const e=vgi.parse(t),n=nr(0,de.parse(e.h)+.1,.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:de.parse(e.p)/2+.2,y:de.parse(e.h)/2+.2},{x:-de.parse(e.w)/2-.2,y:de.parse(e.h)/2+.2},{x:-de.parse(e.w)/2-.2,y:-de.parse(e.h)/2-.2},{x:de.parse(e.p)/2+.2,y:-de.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:Mgi(e).concat(...ly(e),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(Ci(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw),.025))}return e},Dgi=Xi.extend({fn:Z(),num_pins:qe(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")}),Ngi=t=>{const e=Dgi.parse(t),n=nr(0,de.parse(e.h),.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:de.parse(e.pad_spacing)/2,y:de.parse(e.h)/2},{x:-de.parse(e.w)/2-.2,y:de.parse(e.h)/2},{x:-de.parse(e.w)/2-.2,y:-de.parse(e.h)/2},{x:de.parse(e.pad_spacing)/2,y:-de.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:Tgi(e).concat(...ly(e),o,n,s),parameters:e}},Rgi=t=>{const{pn:e,pad_spacing: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,pad_spacing:Number.parseFloat(t.pad_spacing)});e.push(Ci(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw),.0625))}return e},kgi=Xi.extend({fn:Z(),num_pins:qe(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")}),Fgi=t=>{const e=kgi.parse(t),n=nr(0,de.parse(e.h),.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:de.parse(e.p)/2,y:de.parse(e.h)/2},{x:-de.parse(e.w)/2-.2,y:de.parse(e.h)/2},{x:-de.parse(e.w)/2-.2,y:-de.parse(e.h)/2},{x:de.parse(e.p)/2,y:-de.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:Hgi(e).concat(...ly(e),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=[],n=de.parse(t.p),o=de.parse(t.pl),i=de.parse(t.pw),r=.125;for(let s=1;s<=t.num_pins;s++){const{x:a,y:A}=Lgi({pn:s,p:n});e.push(Ci(s,a,A,o,i,r))}return e},Ogi=Xi.extend({fn:Z(),num_pins:qe(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")}),Ggi=t=>{const e=Ogi.parse(t),n=nr(0,de.parse(e.h),.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:de.parse(e.p)/2,y:de.parse(e.h)/2},{x:-de.parse(e.w)/2-.2,y:de.parse(e.h)/2},{x:-de.parse(e.w)/2-.2,y:-de.parse(e.h)/2},{x:de.parse(e.p)/2,y:-de.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:Ugi(e).concat(...ly(e),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(Ci(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return e},Kgi=Xi.extend({fn:Z(),num_pins:qe(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")}),Vgi=t=>{const e=Kgi.parse(t),n=nr(0,de.parse(e.h),.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:de.parse(e.p)/2,y:de.parse(e.h)/2},{x:-de.parse(e.w)/2-.1,y:de.parse(e.h)/2},{x:-de.parse(e.w)/2-.1,y:-de.parse(e.h)/2},{x:de.parse(e.p)/2,y:-de.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:Jgi(e).concat(...ly(e),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(Ci(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return e},Wgi=Xi.extend({fn:Z(),num_pins:qe(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")}),jgi=t=>{const e=Wgi.parse(t),n=nr(0,de.parse(e.h)/2+.4,.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:de.parse(e.p)/2,y:de.parse(e.h)/2},{x:-de.parse(e.w)/2-.2,y:de.parse(e.h)/2},{x:-de.parse(e.w)/2-.2,y:-de.parse(e.h)/2},{x:de.parse(e.p)/2,y:-de.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:Xgi(e).concat(...ly(e),o,n,s),parameters:e}},qgi=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},Xgi=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=qgi({pn:n,p:Number.parseFloat(t.p)});e.push(Ci(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw),.125))}return e},ptn=(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}],Zgi=[{x:-2.85,y:-2.5},{x:-2.85,y:2.5},{x:2.85,y:2.5},{x:2.85,y:-2.5}],eui=[{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}],tui=[{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}],nui=Xi.extend({fn:Z(),num_pins:Eo([qe(3),qe(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()}),oui=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=[Ci(1,r,e,i,n),ptn(2,tui),Ci(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]},iui=t=>{const e=[Ci(1,-1.85,-1.5,1.5,.7),Ci(2,-1.85,1.5,1.5,.7),ptn(3,eui),Ci(4,1.85,-1.5,1.5,.7),Ci(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:Zgi,layer:"top"};return[...e,r,s,i,a]},rui=t=>{const e=t.string?.match(/^sot89_(\d+)/),n=e?Number.parseInt(e[1],10):3,o=nui.parse({...t,num_pins:n});if(o.num_pins===3)return{circuitJson:oui(o),parameters:o};if(o.num_pins===5)return{circuitJson:iui(o),parameters:o};throw new Error("Invalid number of pins for SOT89")},sui=Xi.extend({fn:Z(),p:de.optional().default("5.0mm"),id:de.optional().default("1.0mm"),od:de.optional().default("1.9mm"),w:de.optional().default("13mm"),h:de.optional().default("7mm"),num_pins:ft().optional(),string:Z().optional()}),_tn=t=>{const e=sui.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 U=a%2===0?(G-a/2+.5)*h:(G-Math.floor(a/2))*h;return ka(G+1,U,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),T={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,T],parameters:{...e,p:h}}},lUe=2.54,aui=Xi.extend({fn:Z(),id:de.optional().default("1.2mm"),od:de.optional().default("1.905mm"),ph:de.optional().default("2mm"),w:de.optional().default("13mm"),h:de.optional().default("7mm"),num_pins:ft().optional(),string:Z().optional()}),Aui=t=>{const e=aui.parse(t),n=e.num_pins??Number.parseInt(e.string?.match(/^to220f(?:_|-)(\d+)/i)?.[1]??"3"),o=_tn({...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)*lUe:(A-Math.floor(n/2))*lUe;return A===0?yE({pn:1,x:c,y:i,holeDiameter:e.id,rectPadWidth:e.od,rectPadHeight:e.ph}):Q9(A+1,c,i,yA(e.id),yA(e.od),yA(e.ph))}),s=o.circuitJson.filter(a=>a.type!=="pcb_plated_hole");return{circuitJson:[...r,...s],parameters:{...e,p:lUe,num_pins:n}}},cui=Xi.extend({fn:Z(),num_pins:qe(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")}),lui=t=>{const e=cui.parse(t),n=nr(0,de.parse(e.h)/2+.4,.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:de.parse(e.p)/2,y:de.parse(e.h)/2},{x:-de.parse(e.w)/2,y:de.parse(e.h)/2},{x:-de.parse(e.w)/2,y:-de.parse(e.h)/2},{x:de.parse(e.p)/2,y:-de.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:uui(e).concat(o,n,s),parameters:e}},gui=t=>{const{pn:e,p: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}=gui({pn:n,p:Number.parseFloat(t.p)});e.push(Ci(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw),.125))}return e},dui=Xi.extend({fn:Z(),num_pins:qe(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")}),hui=t=>{const e=dui.parse(t),n=nr(0,de.parse(e.h)+.1,.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:de.parse(e.p)/2+.1,y:de.parse(e.h)/2},{x:-de.parse(e.w)/2,y:de.parse(e.h)/2},{x:-de.parse(e.w)/2,y:-de.parse(e.h)/2},{x:de.parse(e.p)/2+.1,y:-de.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:pui(e).concat(...ly(e),o,n,s),parameters:e}},mui=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},pui=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=mui({pn:n,p:Number.parseFloat(t.p)});e.push(Ci(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw),.0625))}return e},_ui=Xi.extend({fn:Z(),num_pins:qe(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")}),fui=t=>{const e=_ui.parse(t),n=nr(0,de.parse(e.h),.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:de.parse(e.p)/2,y:de.parse(e.h)/2},{x:-de.parse(e.w)/2,y:de.parse(e.h)/2},{x:-de.parse(e.w)/2,y:-de.parse(e.h)/2},{x:de.parse(e.p)/2,y:-de.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:Cui(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}},Cui=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(Ci(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw),.125))}return e},yui=Xi.extend({fn:Z(),num_pins:qe(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")}),xui=t=>{const e=yui.parse(t),n=nr(0,de.parse(e.h),.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:de.parse(e.p)/2,y:de.parse(e.h)/2},{x:-de.parse(e.w)/2-.1,y:de.parse(e.h)/2},{x:-de.parse(e.w)/2-.1,y:-de.parse(e.h)/2},{x:de.parse(e.p)/2,y:-de.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:Bui(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}},Bui=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(Ci(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw),.1))}return e},Sui=Xi.extend({fn:Z(),num_pins:qe(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")}),bui=t=>{const e=Sui.parse(t),n=nr(0,de.parse(e.h)/2+.5,.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:de.parse(e.p)/2,y:de.parse(e.h)/2},{x:-de.parse(e.w)/2-.5,y:de.parse(e.h)/2},{x:-de.parse(e.w)/2-.5,y:-de.parse(e.h)/2},{x:de.parse(e.p)/2,y:-de.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:vui(e).concat(o,n,s),parameters:e}},Qui=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},vui=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=Qui({pn:n,p:Number.parseFloat(t.p)});e.push(Ci(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw),.125))}return e},Pui=Xi.extend({fn:Z(),num_pins:qe(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")}),wui=t=>{const e=Pui.parse(t),n=nr(0,de.parse(e.h)-.5,.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:de.parse(e.p)/2,y:de.parse(e.h)/2},{x:-de.parse(e.w)/2,y:de.parse(e.h)/2},{x:-de.parse(e.w)/2,y:-de.parse(e.h)/2},{x:de.parse(e.p)/2,y:-de.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:Dui(e).concat(o,n,s),parameters:e}},Mui=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},Dui=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=Mui({pn:n,p:Number.parseFloat(t.p)});e.push(Ci(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw),.125))}return e},Nui=Xi.extend({fn:Z(),num_pins:qe(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")}),Rui=t=>{const e=Nui.parse(t),n=nr(0,de.parse(e.h)/2+.5,.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:de.parse(e.p)/2,y:de.parse(e.h)/2},{x:-de.parse(e.w)/2-.1,y:de.parse(e.h)/2},{x:-de.parse(e.w)/2-.1,y:-de.parse(e.h)/2},{x:de.parse(e.p)/2,y:-de.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:kui(e).concat(o,n,s),parameters:e}},Tui=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},kui=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=Tui({pn:n,p:Number.parseFloat(t.p)});e.push(Ci(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw),.125))}return e},Fui=Xi.extend({fn:Z(),num_pins:qe(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")}),Lui=t=>{const e=Fui.parse(t),n=nr(0,3,.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:de.parse(e.p)/2,y:de.parse(e.h)/2-.8},{x:-de.parse(e.w)/2-.8,y:de.parse(e.h)/2-.8},{x:-de.parse(e.w)/2-.8,y:-de.parse(e.h)/2+.8},{x:de.parse(e.p)/2,y:-de.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:Oui(e).concat(o,n,s),parameters:e}},Hui=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},Oui=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=Hui({pn:n,p:Number.parseFloat(t.p)});e.push(Ci(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw),.125))}return e},Gui=Xi.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()}),Yui=t=>{const e=t.string?.match(/^sot223_(\d+)/),n=e?Number.parseInt(e[1],10):4;if(n===8){const i=Vui.parse({...t,num_pins:n});return{circuitJson:iX(i),parameters:i}}const o=Gui.parse({...t,num_pins:n});if(o.num_pins===4)return{circuitJson:Kui(o),parameters:o};if(o.num_pins===5)return{circuitJson:Jui(o),parameters:o};if(o.num_pins===6)return{circuitJson:jui(o),parameters:o};throw new Error("Invalid number of pins")},Uui=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}},Kui=t=>{const e=[];let n=0,o=0;for(let d=0;d<t.num_pins;d++){const{x:m,y:p}=Uui({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(Ci(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]},Vui=_R({p:"0.90mm",w:"2.8mm",legsoutside:!0}),zui=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")},Jui=t=>{const e=[];let n=0,o=0;for(let d=1;d<=t.num_pins;d++){const{x:m,y:p}=zui({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(Ci(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]},Wui=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")},jui=t=>{const e=[];let n=0,o=0;for(let d=1;d<=t.num_pins;d++){const{x:m,y:p}=Wui({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(Ci(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]},qui=Xi.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()}),Xui=t=>{const e=t.string?.match(/^sot23w_(\d+)/),n=e?Number.parseInt(e[1],3):3,o=qui.parse({...t,num_pins:n});if(o.num_pins===3)return{circuitJson:Zui(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}},Zui=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(Ci(_+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]},edi=Xi.extend({fn:Z(),num_pins:Eo([qe(3),qe(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()}),tdi=t=>{const{p:e,id:n,od:o,w:i,h:r}=t,s=Number.parseFloat(r)/2,a=Number.parseFloat(e);return[ka(1,-a,s-a,n,o),ka(2,0,s-a,n,o),ka(3,a,s-a,n,o)]},ndi=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[yE({pn:1,x:-s,y:r-s,holeDiameter:a,rectPadWidth:A,rectPadHeight:c}),Q9(2,s,r-s,a,A,c)]},odi=t=>{const e=t.string?.match(/^to92s_(\d+)/),n=e?Number.parseInt(e[1],10):3,o=edi.parse({...t,num_pins:n});let i=[];if(o.num_pins===3)i=tdi(o);else if(o.num_pins===2)i=ndi(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}},idi=Xi.extend({fn:Z(),p:de.optional(),id:de.optional(),pw:de.optional(),pl:de.optional(),w:de.optional(),h:de.optional(),sh:We().optional().describe('JST SH (Surface-mount) connector family. SH stands for "Super High-density".'),ph:We().optional().describe('JST PH (Through-hole) connector family. PH stands for "Pin Header".'),zh:We().optional().describe("JST ZH (Through-hole) connector family. 1.5mm pitch wire-to-board."),string:Z().optional()}),rdi=()=>({minX:Number.POSITIVE_INFINITY,maxX:Number.NEGATIVE_INFINITY,minY:Number.POSITIVE_INFINITY,maxY:Number.NEGATIVE_INFINITY}),rX=({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)},sdi={ph:{p:de.parse("2.2mm"),id:de.parse("0.70mm"),pw:de.parse("1.20mm"),pl:de.parse("1.20mm"),w:de.parse("6mm"),h:de.parse("5mm")},sh:{p:de.parse("1mm"),pw:de.parse("0.6mm"),pl:de.parse("1.55mm"),w:de.parse("5.8mm"),h:de.parse("7.8mm")},zh:{p:de.parse("1.5mm"),id:de.parse("0.73mm"),pw:de.parse("1.03mm"),pl:de.parse("1.73mm"),w:de.parse("3mm"),h:de.parse("3.5mm")}};function adi(t){return t.sh?"sh":t.ph?"ph":t.zh?"zh":"ph"}function Adi({variant:t,numPins:e,p:n,id:o,pw:i,pl:r}){const s=[],a=rdi();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(yE({pn:l+1,x:g,y:2,holeDiameter:o,rectPadWidth:i,rectPadHeight:r})),rX({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(yE({pn:l+1,x:g,y:0,holeDiameter:o,rectPadWidth:i,rectPadHeight:r,rectBorderRadius:.12499977})):s.push(Q9(l+1,g,0,o,i,r)),rX({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(Ci(g+1,u,-1.325,i,r)),rX({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(Ci(e+1,-l,1.22,1.2,1.8)),s.push(Ci(e+2,l,1.22,1.2,1.8)),rX({bounds:a,centerX:-l,centerY:1.22,width:1.2,height:1.8}),rX({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 cdi({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 ldi=t=>{const e=idi.parse(t),n=adi(e),o=sdi[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 ee=Number.parseInt(h[1],10);Number.isNaN(ee)||(l=ee)}if(d&&d[1]){const ee=Number.parseInt(d[1],10);Number.isNaN(ee)||(l=ee)}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=Adi({variant:n,numPins:l,p:i,id:r,pw:s,pl:a}),{pads:p,padBounds:_,maxPadHalfY:f}=m,I=cdi({variant:n,w:A,h:c,numPins:l,p:i}),C=nr(0,c/2+1,.5),y=I.route.map(ee=>ee.x),x=I.route.map(ee=>ee.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,T=f+.085,H=B-D,G=b+D,U=Q-T,Y=w+k,q={type:"pcb_courtyard_rect",pcb_courtyard_rect_id:"",pcb_component_id:"",center:{x:(H+G)/2,y:(U+Y)/2},width:G-H,height:Y-U,layer:"top"};return{circuitJson:[...p,I,C,q],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"}}},gdi=Xi.extend({fn:Z(),num_pins:qe(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")}),udi=t=>{const e=gdi.parse(t),n=nr(0,de.parse(e.h)/2+.5,.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:de.parse(e.p)/2,y:de.parse(e.h)/2},{x:-de.parse(e.w)/2,y:de.parse(e.h)/2},{x:-de.parse(e.w)/2,y:-de.parse(e.h)/2},{x:de.parse(e.p)/2,y:-de.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:hdi(e).concat(...ly(e),o,n,s),parameters:e}},ddi=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},hdi=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=ddi({pn:n,p:Number.parseFloat(t.p)});e.push(Ci(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw),.1))}return e},mdi=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"}}},pdi=Xi.extend({fn:Z(),num_pins:Eo([qe(8),qe(10)]).default(8),w:Z().optional(),h:Z().optional(),p:Z().optional(),pl:Z().optional(),pw:Z().optional(),string:Z().optional()}),_di=t=>{const e=pdi.parse(t),n=mdi(e.num_pins),o=de.parse(e.w||n.w),i=de.parse(e.h||n.h),r=de.parse(e.p||n.p),s=de.parse(e.pl||n.pl),a=de.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}=ftn(e.num_pins,B+1,o,r),w=B<c?B+1:e.num_pins-(B-c);A.push(Ci(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=ftn(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:T1([{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}},ftn=(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}},fdi=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"}}},Idi=Xi.extend({fn:Z(),num_pins:Eo([qe(8),qe(10),qe(12),qe(16)]).default(8),w:Z().optional(),h:Z().optional(),p:Z().optional(),pl:Z().optional(),pw:Z().optional(),string:Z().optional()}),Itn=(t,e,n,o,i)=>{const r=t/2,s=(e-1)%r,a=e<=r?-1:1,A=(r-1)/2-s,c=de.parse("0.2mm");return{x:a*(n/2+i/2-c),y:A*o}},Cdi=t=>{const e=Idi.parse(t),n=fdi(e.num_pins),o=de.parse(e.w||n.w),i=de.parse(e.h||n.h),r=de.parse(e.p||n.p),s=de.parse(e.pl||n.pl),a=de.parse(e.pw||n.pw),A=[];for(let E=0;E<e.num_pins;E++){const{x:B,y:b}=Itn(e.num_pins,E+1,o,r,s);A.push(Ci(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=Itn(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:T1([{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}},ydi=Xi.extend({fn:Z(),num_pins:qe(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")}),xdi=t=>{const e=ydi.parse(t),n=nr(0,de.parse(e.h),.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:de.parse(e.pad_spacing)/2,y:de.parse(e.h)/2},{x:-de.parse(e.w)/2-.2,y:de.parse(e.h)/2},{x:-de.parse(e.w)/2-.2,y:-de.parse(e.h)/2},{x:de.parse(e.pad_spacing)/2,y:-de.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:Bdi(e).concat(...ly(e),o,n,s),parameters:e}},Edi=t=>{const{pn:e,pad_spacing:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},Bdi=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=Edi({pn:n,pad_spacing:Number.parseFloat(t.pad_spacing)});e.push(Ci(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return e},Sdi=Xi.extend({fn:Z(),num_pins:qe(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")}),bdi=t=>{const e=Sdi.parse(t),n=nr(0,de.parse(e.h),.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:de.parse(e.pad_spacing)/2,y:de.parse(e.h)/2},{x:-de.parse(e.w)/2-.2,y:de.parse(e.h)/2},{x:-de.parse(e.w)/2-.2,y:-de.parse(e.h)/2},{x:de.parse(e.pad_spacing)/2,y:-de.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:vdi(e).concat(...ly(e),o,n,s),parameters:e}},Qdi=t=>{const{pn:e,pad_spacing:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},vdi=t=>{const e=[];for(let n=1;n<=t.num_pins;n++){const{x:o,y:i}=Qdi({pn:n,pad_spacing:Number.parseFloat(t.pad_spacing)});e.push(Ci(n,o,i,Number.parseFloat(t.pl),Number.parseFloat(t.pw)))}return e},Pdi=Xi.extend({fn:Z(),num_pins:Eo([qe(6),qe(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:We().default(!1)}),wdi=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=Pdi.parse({...t,num_pins:n}),i=de.parse(o.w),r=de.parse(o.h),s=de.parse(o.p),a=de.parse(o.pl),A=de.parse(o.pw),c=de.parse(o.epw),l=de.parse(o.eph),g=[];for(let D=0;D<o.num_pins;D++){const{x:k,y:T}=gUe(o.num_pins,D+1,i,s);g.push(Ci(D+1,k,T,a,A))}o.ep&&g.push(Ci(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=gUe(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(gUe(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:T1([{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}},gUe=(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*de.parse("1.4mm"),y:a*o}},Mdi=Xi.extend({fn:Z(),num_pins:ft().optional().default(8),p:At.describe("pitch (distance between center of each pin)"),w:de.describe("width between vertical rows of pins"),grid:che.describe("width and height of the border of the footprint"),ep:che.default("0x0mm").describe("width and height of the central exposed thermal pad"),epx:de.default("0mm").describe("x offset of the center of the central exposed thermal pad"),pinw:de.describe("width of the pin pads"),pinh:de.describe("height of the pin pads")}),Ddi=t=>{const e=Mdi.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}=Ndi({pinCount:n,pinIndex:E,width:i,pitch:o});l.push(Ci(E+1,B,b,A,c))}s.x>0&&s.y>0&&l.push(Ci(e.num_pins+1,a,0,s.x,s.y));const g=Rdi(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:T1([{minX:-p,maxX:p,minY:-y,maxY:y},{minX:-m,maxX:m,minY:-I,maxY:I}])};return{circuitJson:[...l,...g,u,x],parameters:e}},Ndi=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}},Rdi=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}]},Tdi=t=>{const{num_pins:e,bridged:n,p:o=2.54,pw:i=1.5,ph:r=1.5}=t,s=de.parse(o),a=de.parse(i),A=de.parse(r),c=Math.min(A/4,.5),l=[];for(let Q=0;Q<e;Q++)l.push(Ci(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 T=(D-1)*s,H=(k-1)*s,G=Math.sign(H-T),U=T+G*(a/2),Y=H-G*(a/2);g.push({type:"pcb_trace",pcb_trace_id:"",route:[{start_pcb_port_id:`{PIN${D}}`,x:U,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}},Ctn={fn:qe("sot457"),num_pins:qe(6).default(6),pillh:Z().default("0.45mm"),pillw:Z().default("1.45mm"),pl:Z(),pw:Z(),p:Z(),wave:We().optional(),reflow:We().optional()},kdi=Xi.extend({...Ctn,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")}),Fdi=Xi.extend({...Ctn,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)})),DM=t=>Number.parseFloat(t.replace("mm","")),ytn=({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},xtn=t=>{const e=[],n=DM(t.p),o=DM(t.pl),i=DM(t.pw),r=DM(t.w),s=DM(t.h);if(t.wave){const m={1:({padWidth:p,padHeight:_})=>Ci(1,-n,n,_,p),2:({padWidth:p,padHeight:_})=>Ci(2,-n,-n,_,p),3:({padWidth:p,padHeight:_})=>lhe(3,-n,0,DM(t.pillw),DM(t.pillh)),4:({padWidth:p,padHeight:_})=>lhe(4,n,0,DM(t.pillw),DM(t.pillh)),5:({padWidth:p,padHeight:_})=>Ci(5,n,n,_,p),6:({padWidth:p,padHeight:_})=>Ci(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:_}=ytn({pitch:n,width:r,pinNumber:m});e.push(Ci(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=ytn({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:T1([{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]},Ldi=t=>{if(t.wave){const n=Fdi.parse({...t,fn:"sot457"});return{circuitJson:xtn(n),parameters:n}}const e=kdi.parse(t);return{circuitJson:xtn(e),parameters:e}},Hdi=[{x:-.8,y:.75},{x:.8,y:.75},{x:.8,y:-.75},{x:-.8,y:-.75}],Odi=Xi.extend({fn:Z(),num_pins:qe(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()}),Gdi=t=>{const e=Odi.parse({...t,fn:"sot963"}),n=de.parse(e.w),o=de.parse(e.h),i=de.parse(e.p),r=de.parse(e.pl),s=de.parse(e.pw),a=[];for(let d=0;d<6;d++){const{x:m,y:p}=Etn(d+1,n,i,r);a.push(Ci(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=Etn(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:Hdi,layer:"top"};return{circuitJson:[...a,A,c,u,g,h],parameters:e}},Etn=(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}},Ydi=Xi.extend({fn:Z(),num_pins:Eo([qe(3),qe(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()}),Udi=t=>{const{p:e,id:n,od:o,h:i}=t,r=Number.parseFloat(i),s=Number.parseFloat(e);return[ka(1,0,s,n,o),ka(2,r,0,n,o),ka(3,0,-s,n,o)]},Kdi=t=>{const e=t.string?.match(/^potentiometer_(\d+)/),n=e?Number.parseInt(e[1],10):3,o=Ydi.parse({...t,num_pins:n});let i=[];o.num_pins===3&&(i=Udi(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}},Vdi=Xi.extend({fn:Z(),p:de.optional().default("7.5mm"),id:de.optional().default("1mm"),od:de.optional().default("2mm"),d:de.optional().default("10.5mm")}),zdi=(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}},Jdi=t=>{const e=Vdi.parse(t),{p:n,id:o,od:i,d:r}=e,s=[yE({pn:1,x:-n/2,y:0,holeDiameter:o,rectPadWidth:i,rectPadHeight:i}),ka(2,n/2,0,o,i)],{topArc:a,bottomArc:A}=zdi(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}},Wdi=Xi.extend({fn:Z(),num_pins:qe(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")}),jdi=t=>{const e=Wdi.parse(t),n=nr(0,de.parse(e.h)-.5,.3),o={type:"pcb_silkscreen_path",layer:"top",pcb_component_id:"",route:[{x:de.parse(e.p)/2,y:de.parse(e.h)/2},{x:-de.parse(e.w)/2-.3,y:de.parse(e.h)/2},{x:-de.parse(e.w)/2-.3,y:-de.parse(e.h)/2},{x:de.parse(e.p)/2,y:-de.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:Xdi(e).concat(o,n,s),parameters:e}},qdi=t=>{const{pn:e,p:n}=t;return e===1?{x:-n/2,y:0}:{x:n/2,y:0}},Xdi=t=>{const e=[],n=de.parse(t.p),o=de.parse(t.pl),i=de.parse(t.pw),r=.125;for(let s=1;s<=t.num_pins;s++){const{x:a,y:A}=qdi({pn:s,p:n});e.push(Ci(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}],Zdi=Xi.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()}),ehi=t=>{const e=t.string?.match(/^sot323_(\d+)/),n=e?Number.parseInt(e[1],3):3,o=Zdi.parse({...t,num_pins:n});if(o.num_pins===3)return{circuitJson:nhi(o),parameters:o};throw new Error("Invalid number of pins")},thi=t=>{const{pn:e,p:n}=t;return e===1?{x:-n,y:.65}:e===2?{x:-n,y:-.65}:{x:n,y:0}},nhi=t=>{const e=[];for(let A=0;A<t.num_pins;A++){const{x:c,y:l}=thi({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(Ci(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]},ohi=Xi.extend({fn:Z(),circle:We().optional(),rect:We().optional(),square:We().optional(),pill:We().optional(),d:de.optional(),pd:de.optional(),diameter:de.optional(),r:de.optional(),pr:de.optional(),radius:de.optional(),w:de.optional(),pw:de.optional(),width:de.optional(),h:de.optional(),ph:de.optional(),height:de.optional(),s:de.optional(),size:de.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=yA(t.r):t.pr!==void 0?n=yA(t.pr):t.radius!==void 0?n=yA(t.radius):t.d!==void 0?n=yA(t.d)/2:t.pd!==void 0?n=yA(t.pd)/2:t.diameter!==void 0?n=yA(t.diameter)/2:n=yA("1mm")/2:(t.w!==void 0?o=yA(t.w):t.pw!==void 0?o=yA(t.pw):t.width!==void 0?o=yA(t.width):t.s!==void 0?o=yA(t.s):t.size!==void 0?o=yA(t.size):o=yA("1mm"),t.h!==void 0?i=yA(t.h):t.ph!==void 0?i=yA(t.ph):t.height!==void 0?i=yA(t.height):e==="square"||e==="rect"?i=o:i=yA("1mm")),{fn:t.fn,shape:e,radius:n,width:o,height:i}}),ihi=t=>{const e=ohi.parse(t),{shape:n,radius:o,width:i,height:r}=e;let s,a;return n==="circle"?(s=ttn(1,{x:0,y:0,radius:o}),a=o+.5):n==="pill"?(s=lhe(1,0,0,i,r),a=Math.max(i,r)/2+.5):(s=Ci(1,0,0,i,r),a=r/2+.5),{circuitJson:[s,nr(0,a,.2)],parameters:e}},rhi=Xi.extend({fn:Z(),d:de.optional(),hd:de.optional(),r:de.optional(),hr:de.optional(),pd:de.optional(),pr:de.optional(),squarepad:We().optional().default(!1)}).transform(t=>{let e;t.d!==void 0?e=yA(t.d):t.hd!==void 0?e=yA(t.hd):t.r!==void 0?e=yA(t.r)*2:t.hr!==void 0?e=yA(t.hr)*2:e=yA("1mm");let n;return t.pd!==void 0?n=yA(t.pd):t.pr!==void 0?n=yA(t.pr)*2:n=e*(1.5/1),{fn:t.fn,d:e,pd:n,squarepad:t.squarepad??!1}}),shi=t=>{const e=rhi.parse(t),{d:n,pd:o,squarepad:i}=e;return{circuitJson:[i?yE({pn:1,x:0,y:0,holeDiameter:n,rectPadWidth:o,rectPadHeight:o}):ka(1,0,0,n,o),nr(0,o/2+.5,.2)],parameters:e}},ahi=Xi.extend({fn:Z(),num_pins:qe(6).default(6),h:Z().default("1.3mm"),pl:Z().default("1.325mm"),pw:Z().default("0.6mm"),p:Z().default("0.95mm")}),Ahi=t=>{const e=ahi.parse(t);return{circuitJson:chi(e),parameters:e}},Btn=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")},chi=t=>{const e=[];for(let E=1;E<=t.num_pins;E++){const{x:B,y:b}=Btn({h:Number.parseFloat(t.h),p:Number.parseFloat(t.p),pn:E});e.push(Ci(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=Btn({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:T1([{minX:-I,maxX:I,minY:-C,maxY:C},{minX:-f,maxX:f,minY:-y,maxY:y}])};return[...e,s,i,r,l,x]},lhi=[{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}],ghi=Xi.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()}),uhi=t=>{const e=t.string?.match(/^sot343_(\d+)/),n=e?Number.parseInt(e[1],4):4,o=ghi.parse({...t,num_pins:n});if(o.num_pins===4)return{circuitJson:hhi(o),parameters:o};throw new Error("Invalid number of pins")},dhi=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}},hhi=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}=dhi({num_pins:t.num_pins,pn:C+1,p:s});e.push(Ci(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:lhi,layer:"top"};return[...e,_,f,p,I]},mhi=Xi.extend({fn:Z()}),phi=t=>{const e=mhi.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,T=Ci(B,k,b,w,o);T.layer=Q?"bottom":"top",n.push(T)}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}},_hi=Xi.extend({fn:Z(),numPins:ft().optional().default(0),rows:Eo([Z(),ft()]).transform(t=>Number(t)).optional().default(1).describe("number of rows"),p:de.default("2.54mm").describe("pitch"),id:de.default("1.0mm").describe("inner diameter"),od:de.default("1.5mm").describe("outer diameter"),male:We().optional().describe("the module uses male headers"),nopin:We().optional().default(!1).describe("omit pins rendering"),female:We().optional().describe("the module uses female headers"),smd:We().optional().describe("surface mount device"),pinlabeltextalignleft:We().optional().default(!1),pinlabeltextaligncenter:We().optional().default(!1),pinlabeltextalignright:We().optional().default(!1),pinlabelverticallyinverted:We().optional().default(!1),pinlabelorthogonal:We().optional().default(!1),nopinlabels:We().optional().default(!1).describe("omit silkscreen pin labels"),doublesidedpinlabel:We().optional().default(!1).describe("add silkscreen pins in top and bottom layers"),bottomsidepinlabel:We().optional().default(!1).describe("place the silkscreen reference text on the bottom layer instead of top"),pinRowSide:Vn(["left","right","top","bottom"]).optional().default("left"),pinrowleft:We().optional().default(!1),pinrowright:We().optional().default(!1),pinrowtop:We().optional().default(!1),pinrowbottom:We().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:de.optional(),height:de.optional(),pinRowHoleEdgeToEdgeDist:de.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:de.optional(),holeYDist:de.optional(),holeInset:de.default("1mm"),pinrow:Eo([Z(),ft()]).optional(),usbposition:Vn(["left","right","top","bottom"]).optional().default("left"),usbleft:We().optional().default(!1),usbtop:We().optional().default(!1),usbright:We().optional().default(!1),usbbottom:We().optional().default(!1),usbtype:Vn(["micro","c"]).optional(),usbmicro:We().optional().default(!1),usbc:We().optional().default(!1),screen:We().optional().default(!1).describe("add silkscreen outline for screen/display area"),screenwidth:de.optional(),screenheight:de.optional(),screencenteroffsetx:de.optional(),screencenteroffsety:de.optional()}).transform(t=>{const e=ltn(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"]})}),fhi=t=>{const e=_hi.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:T,screenheight:H,screencenteroffsetx:G,screencenteroffsety:U}=e;let Y="center";l?Y="left":g&&(Y="right");const q=[],ee={left:E,right:B,top:b,bottom:Q},W=Object.values(ee).some(oe=>oe!==void 0&&oe>0),J=(oe,ne,le,ue)=>{if(e.smd?q.push(Ci(oe,ne,le,e.od,e.od)):oe===1?q.push(yE({pn:oe,x:ne,y:le,holeDiameter:o,rectPadWidth:i,rectPadHeight:i})):q.push(ka(oe,ne,le,o,i)),!u){const _e=ne+(ue==="left"?-i:ue==="right"?i:0),ce=le+(ue==="top"?i:ue==="bottom"?-i:0);d||q.push(fR({fs:i/5,pn:oe,anchor_x:_e,anchor_y:ce,textalign:Y,orthogonal:c,verticallyinverted:A,layer:"top"})),(h||d)&&q.push(fR({fs:i/5,pn:oe,anchor_x:_e,anchor_y:ce,textalign:Y,orthogonal:c,verticallyinverted:A,layer:"bottom"}))}};if(W){const oe=n;let ne=1;const le=ee.left??0,ue=ee.right??0,_e=ee.top??0,ce=ee.bottom??0,Ie=(he,Ce)=>{if(!(Ce<=0))if(he==="left"||he==="right"){const Pe=he==="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,he),ne++}else{const Pe=he==="top"?_/2-f:-_/2+f,Qe=-((Ce-1)/2)*oe;for(let pe=0;pe<Ce;pe++)J(ne,Qe+pe*oe,Pe,he),ne++}};Ie("left",le),Ie("right",ue),Ie("top",_e),Ie("bottom",ce)}else{const oe=n;let ne=0,le=0,ue=0,_e=0,ce=0,Ie=0;const he=Math.ceil(s/r);m==="left"||m==="right"?(ne=m==="left"?-p/2+f:p/2-f,le=(he-1)/2*oe,ue=0,_e=-oe,ce=m==="left"?oe:-oe,Ie=0):(ne=-(he-1)/2*oe,le=m==="top"?_/2-f:-_/2+f,ue=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<he&&Ce<=s;Qe++){const pe=ne+Qe*ue+Pe*ce,ve=le+Qe*_e+Pe*Ie;if(e.smd?q.push(Ci(Ce,pe,ve,e.od,e.od)):Ce===1?q.push(yE({pn:Ce,x:pe,y:ve,holeDiameter:o,rectPadWidth:i,rectPadHeight:i})):q.push(ka(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||q.push(fR({fs:i/5,pn:Ce,anchor_x:Me,anchor_y:we,textalign:Y,orthogonal:c,verticallyinverted:A,layer:"top"})),(h||d)&&q.push(fR({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),q.push(ka(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}];q.push(IR(oe,{stroke_width:.1,layer:"top"}))}const ie=nr(0,_/2+1,.5);if(q.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:q,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:q,parameters:e};q.push(IR(le,{stroke_width:.1,layer:"top"}))}if(k){const oe=T/2,ne=H/2,le=G,ue=U,_e=[{x:-oe+le,y:-ne+ue},{x:oe+le,y:-ne+ue},{x:oe+le,y:ne+ue},{x:-oe+le,y:ne+ue},{x:-oe+le,y:-ne+ue}];q.push(IR(_e,{stroke_width:.05,layer:"top"}))}return{circuitJson:q,parameters:e}},Ihi=[{x:-1.45,y:2.75},{x:-1.45,y:-1.85},{x:4.05,y:-1.85},{x:4.05,y:2.75}],Chi=[{x:-1.55,y:2.75},{x:-1.55,y:-1.85},{x:3.95,y:-1.85},{x:3.95,y:2.75}],yhi=Xi.extend({fn:Z(),num_pins:ft().default(3),inline:We().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")}),xhi=t=>{const e=yhi.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=[yE({pn:1,x:0,y:0,holeDiameter:e.id,rectPadWidth:r,rectPadHeight:s}),e.inline?Q9(2,n,0,Number.parseFloat(e.id),r,s):ka(2,n,n,e.id,r),e.inline?Q9(3,n*2,0,Number.parseFloat(e.id),r,s):ka(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?Chi:Ihi,layer:"top"};return{circuitJson:[...a,h,d,m],parameters:e}},Ehi=(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},Bhi=(t,e)=>e.nosilkscreen?t.filter(n=>n.type!=="pcb_silkscreen_path"&&n.type!=="pcb_silkscreen_text"):t,Shi=(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 bhi(t){return t!=null}var Qhi=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"),vhi=t=>{let e=dhe();const n=Qhi(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(bhi);for(const{fn:r,v:s}of i)e=e[r](s);return e.setString(n),e},Phi=()=>Object.keys(MM),dhe=()=>{const t=new Proxy({},{get:(e,n)=>{if(n==="soup"||n==="circuitJson"){if("fn"in e&&MM[e.fn])return()=>{const{circuitJson:o}=MM[e.fn](e),i=Bhi(o,e),r=Ehi(i,e);return Shi(r,e.origin)};if(!MM[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(!MM[e.fn])throw new Error(`Invalid footprint function, got "${e.fn}"${e.string?`, from string "${e.string}"`:""}`);return()=>MM[e.fn](e).parameters}return n==="getFootprintNames"?()=>Object.keys(MM):n==="params"?()=>e:n==="setString"?o=>(e.string=o,t):o=>(Object.keys(e).length===0?`${n}${o}`in MM?(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};dhe.string=vhi,dhe.getFootprintNames=Phi;var sX=dhe,Stn={in:25.4,inch:25.4,mil:.0254,mm:1,m:1e3,cm:10,ft:304.8,feet:304.8},whi=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 Stn)return n*Stn[e];throw new Error(`Unsupported unit: ${e}`)},Zv=Eo([ft(),Z()]).transform((t,e)=>{try{const n=whi(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)}`}),T1n}}),Gf=Zv.refine(t=>t>0,"Length must be greater than zero"),eP=Zv.refine(t=>t>=0,"Length cannot be negative"),Mhi=Vn(["sitsFlat","sitsFlatBelowBoard","foldedToFaceAboveBoard","foldedToFaceBelowBoard","foldedToRightAngleAboveBoard","foldedToRightAngleBelowBoard"]),uUe=ft().finite().positive(),Dhi=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),btn=Eo([uUe,Dhi,OT([uUe,uUe])]),Qtn=Pt({x:Zv.optional(),y:Zv.optional(),z:Zv.optional()}).strict(),dUe=Eo([ft().finite(),Z().min(1)]),vtn=OT([dUe,dUe,dUe]),Nhi=["sitsFlat","sitsFlatBelowBoard","foldedToFaceAboveBoard","foldedToFaceBelowBoard","foldsAboveBoard","foldsBelowBoard","foldedToRightAngleAboveBoard","foldedToRightAngleBelowBoard"],Ptn={width:Gf.optional(),height:Gf.optional(),diagonal:Gf.optional(),aspectRatio:btn.optional(),ratio:btn.optional(),defaultDiagonal:Gf.optional(),orientation:Mhi.optional(),sitsFlat:We().optional(),sitsFlatBelowBoard:We().optional(),foldedToFaceAboveBoard:We().optional(),foldedToFaceBelowBoard:We().optional(),foldsAboveBoard:We().optional(),foldsBelowBoard:We().optional(),foldedToRightAngleAboveBoard:We().optional(),foldedToRightAngleBelowBoard:We().optional(),screenThickness:Gf.optional(),bezelInset:eP.optional(),bezelDepth:Gf.optional(),activeAreaWidth:Gf.optional(),activeAreaHeight:Gf.optional(),screenColor:Z().min(1).optional(),bezelColor:Z().min(1).optional(),showScreen:We().optional(),flexCableLength:Gf.optional(),flexCableWidth:Gf.optional(),flexCableThickness:Gf.optional(),flexCableColor:Z().min(1).optional(),conductorCount:ft().int().positive().optional(),conductorPitch:Gf.optional(),conductorWidth:Gf.optional(),conductorThickness:Gf.optional(),conductorColor:Z().min(1).optional(),cableEdgeMargin:eP.optional(),exposedContactLength:eP.optional(),showConductors:We().optional(),showFlexCable:We().optional(),showStiffeners:We().optional(),stiffenerLength:eP.optional(),stiffenerThickness:Gf.optional(),stiffenerColor:Z().min(1).optional(),bendRadius:Gf.optional(),bendSegments:ft().int().min(2).optional(),rightAngleVerticalLead:eP.optional(),distanceAboveBoard:eP.optional(),distanceBelowBoard:eP.optional(),foldDistanceFromConnector:eP.optional(),foldOutset:Gf.optional(),foldSegments:ft().int().min(4).optional(),screenGap:eP.optional(),boardTopZ:Zv.optional(),boardThickness:Gf.optional(),boardClearance:eP.optional(),cableStartX:Zv.optional(),cableStartY:Zv.optional(),cableStartZ:Zv.optional(),cableLateralOffset:Zv.optional(),screenOffset:Qtn.optional(),screenRotation:vtn.optional(),rotation:vtn.optional(),offset:Qtn.optional()},wtn=(t,e)=>{const n=Nhi.filter(o=>t[o]===!0);n.length>1&&e(n[1])};Pt(Ptn).strict().superRefine((t,e)=>{wtn(t,n=>{e.addIssue({code:"custom",message:"Only one FlexScreen orientation shortcut can be true",path:[n]})})});var Rhi=Pt({fn:qe("flexscreen"),...Ptn}).strict().superRefine((t,e)=>{wtn(t,n=>{e.addIssue({code:"custom",message:"Only one FlexScreen orientation shortcut can be true",path:[n]})})}),Mtn=t=>{const e=t.match(/^([a-zA-Z]+)([\(\d\.\+\-].*)?$/);if(e?.[1])return{fn:e[1].toLowerCase(),value:e[2]}},Thi=t=>{const e=t.trim();if(!e)throw new Error("Model string cannot be empty");const n=e.split("_"),o=n[0],i=Mtn(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=Mtn(a);if(!A)throw new Error(`Invalid model string token "${a}"`);r[A.fn]=A.value??!0}return r.string=e,r},khi={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"},Fhi={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"]},Lhi=Object.fromEntries(Object.entries(Fhi).flatMap(([t,e])=>e.map(n=>[n,t]))),Hhi={conductorcount:"conductorCount",conductors:"conductorCount",bendsegments:"bendSegments",foldsegments:"foldSegments"},Dtn={showscreen:["showScreen",!0],hidescreen:["showScreen",!1],showflex:["showFlexCable",!0],hideflex:["showFlexCable",!1],showconductors:["showConductors",!0],hideconductors:["showConductors",!1],showstiffeners:["showStiffeners",!0],hidestiffeners:["showStiffeners",!1]},Ohi={screencolor:"screenColor",bezelcolor:"bezelColor",flexcolor:"flexCableColor",conductorcolor:"conductorColor",stiffenercolor:"stiffenerColor"},Ghi=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},Yhi=(t,e)=>{if(typeof t!="string"||!/^\(.+\)$/.test(t))throw new Error(`FlexScreen token "${e}" requires a value in (...)`);return t.slice(1,-1)},Ntn=(t,e)=>{if(t!==!0)throw new Error(`FlexScreen token "${e}" does not accept a value`)},Uhi=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=khi[i];if(s){if(Ntn(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 Dtn){Ntn(r,i);const[l,g]=Dtn[i];e[l]=g;continue}const a=Ohi[i];if(a){e[a]=Yhi(r,i);continue}if(i==="ratio"){e.aspectRatio=Ghi(r);continue}const A=Lhi[i];if(A){e[A]=r;continue}if(i==="distance"){o=r;continue}const c=Hhi[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 Rhi.parse({fn:"flexscreen",...e})},Rtn={flexscreen:Uhi},Khi=t=>{const e=Rtn[t.fn];if(e)return e(t);throw new Error(`Unsupported modelprinter function "${t.fn}"`)},Vhi=t=>{const e=Thi(t);return{params:()=>e,json:()=>Khi(e)}},zhi={string:Vhi,getModelNames:()=>Object.keys(Rtn)},hUe=zhi,Ttn=Symbol("Fragment");function mUe(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 ln=Symbol("Cuboid"),ktn=Symbol("Cube"),Fa=Symbol("Cylinder"),MG=Symbol("Sphere"),Yf=Symbol("RoundedCuboid"),ri=Symbol("Translate"),Bl=Symbol("Rotate"),Wp=Symbol("Union"),Vh=Symbol("Subtract"),cl=Symbol("Hull"),_i=Symbol("Colorize"),DG=Symbol("Polygon"),NG=Symbol("ExtrudeLinear"),k1=Symbol("RoundedCylinder"),vi=Ttn,He=(t,e,n)=>mUe(t,e),zn=(t,e,n)=>mUe(t,e),pUe=({hole:t,isPin1:e})=>{const n=e?"#00ff00":"#b87333";if(t.shape==="circle")return He(_i,{color:n,children:He(ri,{offset:[t.x,t.y,-.005],children:zn(Vh,{children:[He(Fa,{radius:t.outer_diameter/2,height:.01}),He(Fa,{radius:t.hole_diameter/2,height:.01})]})})});if(t.shape==="circular_hole_with_rect_pad")return He(_i,{color:n,children:He(ri,{offset:[t.x,t.y,0],children:zn(Vh,{children:[He(ln,{size:[t.rect_pad_width,t.rect_pad_height,.01],center:[0,0,0]}),He(Fa,{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 He(_i,{color:n,children:He(ri,{offset:[t.x,t.y,0],children:zn(Vh,{children:[zn(cl,{children:[He(Fa,{radius:r,height:.01,center:[s?-(o/2-r):0,s?0:-(i/2-r),0]}),He(Fa,{radius:r,height:.01,center:[s?o/2-r:0,s?0:i/2-r,0]})]}),a===A?He(Fa,{radius:a/2,height:.01}):zn(cl,{children:[He(Fa,{radius:Math.min(a,A)/2,height:.01,center:[a>A?-(a/2-A/2):0,a>A?0:-(A/2-a/2),0]}),He(Fa,{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)},Sd=({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=zn(Wp,{children:[zn(cl,{children:[He(ri,{z:.005,children:He(ln,{size:[I,C,.01]})}),He(ri,{z:p,children:He(ln,{size:[e,n,.01]})})]}),zn(cl,{children:[He(ri,{z:p,children:He(ln,{size:[e,n,.01]})}),He(ri,{z:p+_,children:He(ln,{size:[I,C,.01]})})]})]}),Q=(D,k)=>He(ri,{offset:{x:D,y:k,z:0},children:He(Bl,{rotation:[0,0,Math.PI/4],children:He(ln,{size:[m*Math.SQRT2,m*Math.SQRT2,o*3]})})});let w=b;if(m>0){const D=e/2,k=n/2;w=zn(Vh,{children:[b,Q(D,k),Q(-D,k),Q(D,-k),Q(-D,-k)]})}return He(_i,{color:r,children:He(ri,{offset:t,children:He(ri,{offset:{x:0,y:0,z:i},children:c?zn(Vh,{children:[w,He(ri,{offset:B,children:He(Bl,{rotation:u,children:He(Fa,{radius:x,height:d})})})]}):w})})})},Jhi=t=>Array.from({length:t},(e,n)=>n);function _Ue(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 Whi=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}))},jhi=Whi([{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}]),Ftn=5.47,hhe=.5,qhi=({x:t,y:e,z:n})=>{const o=t>0;return zn(vi,{children:[He(ri,{offset:{x:t+.25/2,y:e,z:n},children:He(Bl,{rotation:["-90deg",0,"90deg"],children:He(NG,{height:.25,children:He(DG,{points:jhi.slice().reverse().map(i=>[i.x,i.y])})})})}),He(ri,{offset:{x:t,y:e+(o?1:-1),z:n},children:He(Bl,{rotation:["-90deg","90deg",o?"180deg":"0deg"],children:He(NG,{height:2,children:He(DG,{points:_Ue([[0,0],[-1,0],[-1,-1]],.25).map(i=>[i.x,i.y])})})})})]})},Xhi=({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 zn(vi,{children:[Jhi(t).map(a=>{const A=a%i,c=(Math.floor(a/i)-.5)*2;return He(qhi,{x:c*r/2,y:A*e-(i-1)/2*e,z:Ftn/2+hhe})}),He(Sd,{width:s,length:i*e+.5,height:Ftn-hhe,heightAboveSurface:hhe,center:{x:0,y:0,z:hhe}})]})};function $hi(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 ts=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,$hi(l,t)]),c=_Ue(A,e);return He(_i,{color:"#fff",children:He(ri,{offset:{z:0,y:0,x:0,...t.position},children:He(Bl,{rotation:["90deg",0,s??0],children:He(ri,{offset:{x:0,y:0,z:-n/2},children:He(NG,{height:n,children:He(DG,{points:c.map(l=>[l.x,l.y])})})})})})})},Zhi=({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 zn(vi,{children:[Array.from({length:r}).map((I,C)=>He(ts,{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)=>He(ts,{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})),He(Sd,{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})]})},e0i=({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 zn(vi,{children:[Array.from({length:r}).map((A,c)=>He(ts,{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)=>He(ts,{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})),He(Sd,{center:{x:0,y:0,z:a/2},width:i,length:i,height:1.1,notchRadius:.35,heightAboveSurface:.1,taperRatio:.09})]})},fUe=1,IUe=.5,RG=.5,aX=.2,t0i=fUe-aX*2,Ltn=({color:t="#333"})=>zn(vi,{children:[He(ln,{size:[t0i,IUe,RG],offset:[0,0,RG/2],color:t}),He(ln,{size:[aX,RG,IUe],offset:[fUe/2-aX/2,0,RG/2],color:"#ccc"}),He(ln,{size:[aX,RG,IUe],offset:[-fUe/2+aX/2,0,RG/2],color:"#ccc"})]}),CUe=1.6,n0i=CUe-.3*2,mhe=.3,yUe=.85,TG=.6,Htn=({color:t="#333"})=>zn(vi,{children:[He(ln,{size:[n0i,yUe,TG],offset:[0,0,TG/2],color:t}),He(ln,{size:[mhe,yUe,TG],offset:[CUe/2-mhe/2,0,TG/2],color:"#ccc"}),He(ln,{size:[mhe,yUe,TG],offset:[-CUe/2+mhe/2,0,TG/2],color:"#ccc"})]}),xUe=2,EUe=1.25,kG=.55,AX=.5,o0i=xUe-AX*2,Otn=({color:t="#333"})=>zn(vi,{children:[He(ln,{size:[o0i,EUe,kG],offset:[0,0,kG/2],color:t}),He(ln,{size:[AX,EUe,kG],offset:[xUe/2-AX/2,0,kG/2],color:"#ccc"}),He(ln,{size:[AX,EUe,kG],offset:[-xUe/2+AX/2,0,kG/2],color:"#ccc"})]}),Gtn=({pinCount:t,pitch:e,leadWidth:n,padContactLength:o,bodyWidth:i})=>{const r=t/4;e||(e=i0i(t,i)),o||(o=r0i(t)),n||(n=s0i(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 zn(vi,{children:[Array.from({length:r}).map((_,f)=>He(ts,{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)=>He(ts,{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)=>He(ts,{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)=>He(ts,{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})),He(Sd,{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})]})},i0i=(t,e)=>{switch(t){case 44:case 64:return .8;case 52:return e===14?1:.65;case 208:return .5;default:return .5}},r0i=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}},s0i=(t,e)=>{switch(t){case 44:case 64:return .5;case 52:return e===14?.45:.55;case 208:return .3;default:return .25}},FG="#c0c0c0",Ytn=({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})=>zn(vi,{children:[He(ri,{y:l?-3:0,children:He(ln,{color:"#222",size:[s,a,r],center:[t,e,A(r/2)]})}),He(_i,{color:FG,children:c?He(ts,{rotation:-Math.PI/2,position:{x:t,y:e+1,z:n/2},thickness:n,width:n,height:n,padContactLength:2,bodyDistance:3}):zn(cl,{children:[He(ln,{color:FG,size:[n,n,o*.9],center:[t,e,A(r*.9+r/2)]}),He(ln,{color:FG,size:[n/1.8,n/1.8,o],center:[t,e,A(r+r/2)]})]})}),He(_i,{color:FG,children:He(ri,{y:l?-3.9:0,z:l?1:0,children:He(Bl,{rotation:l?[-Math.PI/2,0,0]:[0,0,0],children:zn(cl,{children:[He(ln,{color:FG,size:[n,n,i*.9],center:[t,e,A(-i/2*.9)]}),He(ln,{color:FG,size:[n/1.8,n/1.8,i],center:[t,e,A(-i/2)]})]})})})})]}),Utn=({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 He(vi,{children:Array.from({length:t},(p,_)=>{const f=Math.floor(_/c),I=_%c,C=u+I*e,y=((i-1)/2-f)*l;return He(Ytn,{x:C,y,pinThickness:.63,shortSidePinLength:g,longSidePinLength:n,bodyHeight:2,flipZ:m,smd:r,rightangle:s},_)})})},a0i=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")}},A0i=({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},c0i=({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=A0i({num_pins:t,cw:!0,ccw:!0}),l=[];for(let g=0;g<t;g++){const{x:u,y:h,o:d}=a0i({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 zn(vi,{children:[He(_i,{color:"grey",children:He(ln,{center:[0,0,o/2],size:[e,n,o]})}),l.map((g,u)=>He(ln,{center:[g.x,g.y,A/2],size:[g.pw,g.pl,A]})),i?.length!==void 0&&i?.width!==void 0&&He(ln,{center:[0,0,A/2],size:[i.width,i.length,A]})]})},Ktn=c0i,l0i=()=>{const A=1.1999999999999997;return zn(vi,{children:[He(ts,{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}),He(ts,{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}),He(ts,{position:{x:-2.8/2-A/4,y:0,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:A,height:.95}),He(ts,{position:{x:-2.8/2-A/4,y:-1,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:A,height:.95}),He(ts,{position:{x:-2.8/2-A/4,y:1,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:A,height:.95}),He(Sd,{center:{x:0,y:0,z:0},width:1.6,length:2.9,height:1.2})]})},Vtn=l0i,g0i=({fullWidth:t=2.9,fullLength:e=2.8,color:n}={})=>{const g=(t-1.3)/2+.3;return zn(vi,{children:[He(ts,{position:{x:-t/2,y:.95,z:.075},width:.4,thickness:.15,padContactLength:.4,bodyDistance:g,height:.95}),He(ts,{position:{x:-t/2,y:-.95,z:.075},width:.4,thickness:.15,padContactLength:.4,bodyDistance:g,height:.95}),He(ts,{rotation:Math.PI,position:{x:t/2,y:0,z:.075},width:.4,thickness:.15,padContactLength:.4,bodyDistance:g,height:.95}),He(Sd,{center:{x:0,y:0,z:0},width:1.3,length:2.9,height:1.1,color:n})]})},u0i=({fullWidth:t=2.9,fullLength:e=2.8})=>{const l=(t-1.92)/2+.3;return zn(vi,{children:[He(ts,{rotation:Math.PI,position:{x:t/2,y:0,z:.075},width:.4,thickness:.15,padContactLength:.25,bodyDistance:l,height:.45}),He(ts,{position:{x:-t/2,y:-.95,z:.075},width:.4,thickness:.15,padContactLength:.25,bodyDistance:l,height:.45}),He(ts,{position:{x:-t/2,y:.95,z:.075},width:.4,thickness:.15,padContactLength:.25,bodyDistance:l,height:.45}),He(Sd,{center:{x:0,y:0,z:0},width:1.92,length:2.9,height:1.1,straightHeightRatio:.45,heightAboveSurface:.05})]})},BUe=.6,SUe=.3,LG=.33,cX=.1,d0i=BUe-cX*2,ztn=({color:t="#333"})=>zn(vi,{children:[He(ln,{size:[d0i,SUe,LG],offset:[0,0,LG/2],color:t}),He(ln,{size:[cX,SUe,LG],offset:[BUe/2-cX/2,0,LG/2],color:"#ccc"}),He(ln,{size:[cX,SUe,LG],offset:[-BUe/2+cX/2,0,LG/2],color:"#ccc"})]}),bUe=.4,QUe=.2,HG=.13,lX=.07,h0i=bUe-lX*2,Jtn=({color:t="#333"})=>zn(vi,{children:[He(ln,{size:[h0i,QUe,HG],offset:[0,0,HG/2],color:t}),He(ln,{size:[lX,QUe,HG],offset:[bUe/2-lX/2,0,HG/2],color:"#ccc"}),He(ln,{size:[lX,QUe,HG],offset:[-bUe/2+lX/2,0,HG/2],color:"#ccc"})]}),vUe=3.2,PUe=1.6,OG=.9,gX=.5,m0i=vUe-gX*2,Wtn=({color:t="#333"})=>zn(vi,{children:[He(ln,{size:[m0i,PUe,OG],offset:[0,0,OG/2],color:t}),He(ln,{size:[gX,PUe,OG],offset:[vUe/2-gX/2,0,OG/2],color:"#ccc"}),He(ln,{size:[gX,PUe,OG],offset:[-vUe/2+gX/2,0,OG/2],color:"#ccc"})]}),wUe=3.2,MUe=2.5,GG=1,uX=.6,p0i=wUe-uX*2,jtn=({color:t="#333"})=>zn(vi,{children:[He(ln,{size:[p0i,MUe,GG],offset:[0,0,GG/2],color:t}),He(ln,{size:[uX,MUe,GG],offset:[wUe/2-uX/2,0,GG/2],color:"#ccc"}),He(ln,{size:[uX,MUe,GG],offset:[-wUe/2+uX/2,0,GG/2],color:"#ccc"})]}),DUe=5,NUe=2.5,YG=1.4,dX=.6,_0i=DUe-dX*2,qtn=({color:t="#333"})=>zn(vi,{children:[He(ln,{size:[_0i,NUe,YG],offset:[0,0,YG/2],color:t}),He(ln,{size:[dX,NUe,YG],offset:[DUe/2-dX/2,0,YG/2],color:"#ccc"}),He(ln,{size:[dX,NUe,YG],offset:[-DUe/2+dX/2,0,YG/2],color:"#ccc"})]}),RUe=6.3,TUe=3.2,UG=1.8,hX=.8,f0i=RUe-hX*2,Xtn=({color:t="#333"})=>zn(vi,{children:[He(ln,{size:[f0i,TUe,UG],offset:[0,0,UG/2],color:t}),He(ln,{size:[hX,TUe,UG],offset:[RUe/2-hX/2,0,UG/2],color:"#ccc"}),He(ln,{size:[hX,TUe,UG],offset:[-RUe/2+hX/2,0,UG/2],color:"#ccc"})]}),$tn=({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 zn(vi,{children:[He(_i,{color:"#1a1a1a",children:zn(Vh,{children:[He(ln,{color:"#000",size:[a,A,s],center:[t,e,c(n+s/2)]}),He(ln,{size:[u,u,m],center:[t,e,p]}),zn(cl,{children:[He(ln,{size:[u,u,.01],center:[t,e,c(_)]}),He(ln,{size:[h,h,.01],center:[t,e,c(n+s)]})]})]})}),zn(_i,{color:"silver",children:[zn(cl,{children:[He(ln,{color:"silver",size:[g,g,i*.9],center:[t,e,c(n+-i/2*.9)]}),He(ln,{color:"silver",size:[g/1.8,g/1.8,i],center:[t,e,c(n+-i/2)]})]}),He(ln,{color:"silver",size:[f,f,f*.5],center:[t,e,c(n+f/2*.5)]})]})]})},I0i=({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 He(vi,{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 He($tn,{x:m,y:p,pitch:e,legsLength:n,innerDiameter:o,flipZ:l},u)})})},C0i=({width:t,length:e,innerDiameter:n=1})=>{const o=t,i=e,r=t*.7,s=n/2.5;return zn(vi,{children:[He(Yf,{color:"#1a1a1f",center:[0,0,r/2],size:[i,i,r],roundRadius:.3}),He(Yf,{color:"#f2f2f2",center:[0,0,r+r*.1/2.5],size:[i,i,r*.1],roundRadius:.14}),He(Fa,{color:"#1a1a1f",height:r*.8,radius:o/3,center:[0,0,r+r*.8/2]}),He(Fa,{color:"#1a1a1f",height:r*.2,radius:n/2,center:[i/3,i/3,r+r*.1/2]}),He(Fa,{color:"#1a1a1f",height:r*.2,radius:n/2,center:[-i/3,-i/3,r+r*.1/2]}),He(Fa,{color:"#1a1a1f",height:r*.2,radius:n/2,center:[-i/3,i/3,r+r*.1/2]}),He(Fa,{color:"#1a1a1f",height:r*.2,radius:n/2,center:[i/3,-i/3,r+r*.1/2]}),He(phe,{thickness:n/3,width:s,horizontalLength:i*.8,verticalLength:r/2,position:{x:-o/2,y:-i/2,z:-r*1.2}}),He(phe,{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}),He(phe,{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}),He(phe,{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}})]})},phe=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=_Ue(a,e);return He(_i,{color:"#f2f2f2",children:He(ri,{offset:{x:s?.x||0,y:s?.y||0,z:s?.z||0},children:He(Bl,{rotation:[0,55,r],children:He(NG,{height:n,children:He(DG,{points:A.map(c=>[c.y,c.x])})})})})})},y0i=({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 zn(vi,{children:[Array.from({length:r}).map((h,d)=>He(ts,{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)=>He(ts,{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})),He(Sd,{center:{x:0,y:0,z:a/2},width:u,length:g,height:A})]})},x0i=({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 zn(vi,{children:[Array.from({length:g}).map((f,I)=>He(ts,{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)=>He(ts,{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})),He(Sd,{center:{x:0,y:0,z:h/2},width:c,length:l,height:1})]})},E0i=()=>zn(vi,{children:[He(ln,{color:"#ccc",size:[.5,.6,.12],center:[-.725,0,.12/2]}),He(ln,{color:"#ccc",size:[.5,.6,.12],center:[.725,0,.12/2]}),He(_i,{color:"#222",children:zn(Wp,{children:[He(ri,{z:.3/2,children:He(ln,{size:[1.65,.8,.3]})}),zn(cl,{children:[He(ri,{z:.3,children:He(ln,{size:[1.65,.8,.01]})}),He(ri,{z:.6,children:He(ln,{size:[1.65-.2,.8-.2,.01]})})]})]})})]}),Ztn=()=>zn(vi,{children:[He(ln,{color:"#ccc",size:[.26,.51,.12],center:[-.325,0,.12/2]}),He(ln,{color:"#ccc",size:[.26,.51,.12],center:[.325,0,.12/2]}),He(_i,{color:"#222",children:He(ri,{z:.47/2+.02,children:He(ln,{size:[.98,.58,.47]})})}),He(ln,{color:"#ccc",size:[.98+.001,.26/2,.26/4],center:[0,.26/2,.47/4]}),He(ln,{color:"#ccc",size:[.98+.001,.26/2,.26/4],center:[0,-.26/2,.47/4]}),He(ln,{color:"#ccc",size:[.26/1.5,.58+.001,.26/4],center:[.65/2,0,.47/4]}),He(ln,{color:"#ccc",size:[.26/1.5,.58+.001,.26/4],center:[-.65/2,0,.47/4]})]}),B0i=()=>{const c=He(_i,{color:"#1a1a1a",children:zn(Wp,{children:[zn(cl,{children:[He(ri,{z:.13,children:He(ln,{size:[4,3,.03]})}),He(ri,{z:1.15,children:He(ln,{size:[4.4,3.4,.01]})})]}),zn(cl,{children:[He(ri,{z:1.15,children:He(ln,{size:[4.4,3.4,.01]})}),He(ri,{z:2.3,children:He(ln,{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 He(_i,{color:"#c0c0c0",children:zn(Wp,{children:[He(ln,{size:[2.3*.8,1.45,.2],center:[d,0,.2/2]}),He(ln,{size:[.2,1.45,1.14],center:[m,0,1.14/2+.2]}),He(ln,{size:[_,1.45,.2],center:[f,0,.2/2+1.14]})]})})};return zn(vi,{children:[He(l,{xDir:1}),He(l,{xDir:-1}),c]})},enn=()=>{const c=He(_i,{color:"#1a1a1a",children:zn(Wp,{children:[zn(cl,{children:[He(ri,{z:.13,children:He(ln,{size:[4.199999999999999,3.6,.03]})}),He(ri,{z:1.15,children:He(ln,{size:[4.6,4,.01]})})]}),zn(cl,{children:[He(ri,{z:1.15,children:He(ln,{size:[4.6,4,.01]})}),He(ri,{z:2.3,children:He(ln,{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 He(_i,{color:"#c0c0c0",children:zn(Wp,{children:[He(ln,{size:[2.3*.8,1.45,.2],center:[d,0,.2/2]}),He(ln,{size:[.2,1.45,1.14],center:[m,0,1.14/2+.2]}),He(ln,{size:[_,1.45,.2],center:[f,0,.2/2+1.14]})]})})};return zn(vi,{children:[He(l,{xDir:1}),He(l,{xDir:-1}),c]})},S0i=()=>{const c=He(_i,{color:"#1a1a1a",children:zn(Wp,{children:[zn(cl,{children:[He(ri,{z:.21000000000000002,children:He(ln,{size:[6.3999999999999995,5.6,.03]})}),He(ri,{z:1.15,children:He(ln,{size:[6.8,6,.01]})})]}),zn(cl,{children:[He(ri,{z:1.15,children:He(ln,{size:[6.8,6,.01]})}),He(ri,{z:2.3,children:He(ln,{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 He(_i,{color:"#c0c0c0",children:zn(Wp,{children:[He(ln,{size:[2.3*.8,2.95,.2],center:[d,0,.2/2]}),He(ln,{size:[.2,2.95,1.14],center:[m,0,1.14/2+.2]}),He(ln,{size:[_,2.95,.2],center:[f,0,.2/2+1.14]})]})})};return zn(vi,{children:[He(l,{xDir:1}),He(l,{xDir:-1}),c]})},b0i=()=>{const g=He(_i,{color:"#222",children:zn(Wp,{children:[He(ri,{z:.27,children:He(ln,{size:[2.9,1.9,.54]})}),zn(cl,{children:[He(ri,{z:.54,children:He(ln,{size:[2.9,1.9,.01]})}),He(ri,{z:1.08,children:He(ln,{size:[2.6999999999999997,1.7,.01]})})]})]})});return zn(vi,{children:[He(ln,{color:"#ccc",size:[1,1.2,.25],center:[-1.3,0,.25/2]}),He(ln,{color:"#ccc",size:[1,1.2,.25],center:[1.3,0,.25/2]}),g]})},Q0i=()=>zn(vi,{children:[He(ln,{color:"#ccc",size:[1,.6,.12],center:[-1.3,0,.12/2]}),He(ln,{color:"#ccc",size:[1,.6,.12],center:[1.3,0,.12/2]}),He(_i,{color:"#222",children:zn(Wp,{children:[He(ri,{z:.55/2,children:He(ln,{size:[2.7,1.6,.55]})}),zn(cl,{children:[He(ri,{z:.55,children:He(ln,{size:[2.7,1.6,.01]})}),He(ri,{z:1.1,children:He(ln,{size:[2.7-.2,1.6-.2,.01]})})]})]})})]}),v0i=()=>zn(vi,{children:[He(ln,{color:"#ccc",size:[1,.9,.2],center:[-1.3,0,.2/2]}),He(ln,{color:"#ccc",size:[1,.9,.2],center:[1.3,0,.2/2]}),He(_i,{color:"#222",children:zn(Wp,{children:[He(ri,{z:.2/2,children:He(ln,{size:[2.75,1.8,.2]})}),zn(cl,{children:[He(ri,{z:.2,children:He(ln,{size:[2.75,1.8,.01]})}),He(ri,{z:1,children:He(ln,{size:[2.75-.4,1.8-.4,.01]})})]})]})}),He(ln,{color:"#777",size:[.2,1.8-.4,.01],center:[-1.3+.4,0,1]})]}),tnn=({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 zn(vi,{children:[He(ln,{color:"#ccc",size:[r,i,s],center:[a,0,s/2]}),He(ln,{color:"#ccc",size:[r,i,s],center:[A,0,s/2]}),He(_i,{color:"#222",children:zn(Wp,{children:[zn(cl,{children:[He(ri,{z:g,children:He(ln,{size:[o-l/2,e-l/2,.01]})}),He(ri,{z:.01,children:He(ln,{size:[o-l,e-l,.01]})})]}),zn(cl,{children:[He(ri,{z:g,children:He(ln,{size:[o,e,.01]})}),He(ri,{z:n,children:He(ln,{size:[o-c,e-c,.01]})})]})]})}),He(ln,{color:"#777",size:[s*2.7,e-c,.02],center:[a+c,0,n]})]})},P0i=({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 zn(vi,{children:[He(ts,{position:{x:-t/2,y:0,z:A/2},width:a,thickness:A,padContactLength:g,bodyDistance:l,curveLength:u,height:c}),He(ts,{rotation:Math.PI,position:{x:t/2,y:0,z:A/2},width:a,thickness:A,padContactLength:g,bodyDistance:l,curveLength:u,height:c}),He(Sd,{center:{x:0,y:0,z:0},width:n,length:o,height:s,heightAboveSurface:r,includeNotch:!1,color:"#222",taperRatio:.06,straightHeightRatio:.6}),He(ln,{color:"#777",size:[.45,o-.15,.02],center:[-n/4,0,i]})]})},w0i=()=>zn(vi,{children:[He(ln,{color:"#ccc",size:[.9,1.75,.2],center:[-1.825,0,.2/2]}),He(ln,{color:"#ccc",size:[.9,1.75,.2],center:[1.825,0,.2/2]}),He(_i,{color:"#222",children:zn(Wp,{children:[zn(cl,{children:[He(ri,{z:.2,children:He(ln,{size:[3.8-.05/2,2.5-.05/2,.01]})}),He(ri,{z:.01,children:He(ln,{size:[3.8-.05,2.5-.05,.01]})})]}),zn(cl,{children:[He(ri,{z:.2,children:He(ln,{size:[3.8,2.5,.01]})}),He(ri,{z:1,children:He(ln,{size:[3.8-.4,2.5-.4,.01]})})]})]})}),He(ln,{color:"#777",size:[.2*2.7,2.5-.4,.02],center:[-1.825+.4,0,1]})]}),M0i=()=>zn(vi,{children:[He(ln,{color:"#ccc",size:[.4,.25,.14],center:[-.4,0,.14/2]}),He(ln,{color:"#ccc",size:[.4,.25,.14],center:[.4,0,.14/2]}),He(_i,{color:"#222",children:zn(Wp,{children:[He(ri,{z:.14/2,children:He(ln,{size:[.8,.6,.14]})}),zn(cl,{children:[He(ri,{z:.14,children:He(ln,{size:[.8,.6,.01]})}),He(ri,{z:.37,children:He(ln,{size:[.8-.1,.6-.1,.01]})})]})]})})]}),nnn=({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 zn(vi,{children:[He(ts,{rotation:Math.PI,position:{x:t/2+g/4,y:0,z:c/2},width:A,thickness:c,padContactLength:l,bodyDistance:g,height:a}),He(ts,{position:{x:-t/2-g/4,y:0,z:c/2},width:i,thickness:c,padContactLength:l,bodyDistance:g,height:a}),He(ts,{position:{x:-t/2-g/4,y:-s,z:c/2},width:i,thickness:c,padContactLength:l,bodyDistance:g,height:a}),He(ts,{position:{x:-t/2-g/4,y:s,z:c/2},width:i,thickness:c,padContactLength:l,bodyDistance:g,height:a}),He(Sd,{center:{x:0,y:0,z:0},width:e,length:n,height:o,includeNotch:!1,taperRatio:.06,straightHeightRatio:.45})]})},D0i=()=>zn(vi,{children:[Array.from({length:16}).map((h,d)=>He(ts,{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)=>He(ts,{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)=>He(ts,{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)=>He(ts,{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})),He(Sd,{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})]}),N0i=D0i,R0i=()=>{const c=.7999999999999998;return zn(vi,{children:[He(ts,{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}),He(ts,{position:{x:-2.05/2-c/4,y:-.65,z:.18/2},width:.3,thickness:.18,padContactLength:.2,bodyDistance:c,height:.65}),He(ts,{position:{x:-2.05/2-c/4,y:.65,z:.18/2},width:.3,thickness:.18,padContactLength:.2,bodyDistance:c,height:.65}),He(Sd,{center:{x:0,y:0,z:0},width:1.25,length:2,height:.9,includeNotch:!1,taperRatio:.06,straightHeightRatio:.7,heightAboveSurface:.05})]})},T0i=({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 zn(vi,{children:[Array.from({length:r}).map((h,d)=>He(ts,{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)=>He(ts,{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)=>He(ts,{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)=>He(ts,{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})),He(Sd,{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})]})},k0i=()=>{const o=.20900000000000002,i=.1,r=.3,s=.1,a=.2;return zn(vi,{children:[He(_i,{color:"#222",children:zn(Wp,{children:[He(ln,{size:[.85,1.2,o],center:[0,0,o/2]}),zn(cl,{children:[He(ri,{z:o,children:He(ln,{size:[.85,1.2,.01]})}),He(ri,{z:.38,children:He(ln,{size:[.85-i,1.2-i,.01]})})]})]})}),He(ln,{color:"#ccc",size:[r,.25,s],center:[.55,0,s/2]}),He(ln,{color:"#ccc",size:[r,a,s],center:[-.55,.4,s/2]}),He(ln,{color:"#ccc",size:[r,a,s],center:[-.55,-.4,s/2]})]})},onn=({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})=>{const c=[],l=Math.floor(t/2),g=a*(l-1);for(let u=0;u<t;u++){const h=u<l?"left":"right",d=u%l,m=g/2-d*a,p=s,_=r,f=h==="left"?-e/2+p/2:e/2-p/2,I=u+1;c.push({pinNumber:I,x:f,y:m,padSizeX:p,padSizeY:_})}return zn(vi,{children:[He(Sd,{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}}),c.map((u,h)=>He(ln,{center:[u.x,u.y,A/2],size:[u.padSizeX,u.padSizeY,A]})),i?.length!==void 0&&i?.width!==void 0&&He(ln,{center:[0,0,A/2],size:[i.width,i.length,A]})]})},F0i=({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 zn(vi,{children:[zn(_i,{color:s,children:[zn(cl,{children:[He(k1,{height:n,roundRadius:.5,radius:c,center:[-l,0,n]}),He(k1,{height:n,roundRadius:.5,radius:c,center:[l,0,n]})]}),zn(cl,{children:[He(k1,{height:u,roundRadius:.1,radius:c+.85,center:[-l,0,n/2+u/2]}),He(k1,{height:u,roundRadius:.1,radius:c+.85,center:[l,0,n/2+u/2]})]})]}),zn(_i,{color:a,children:[He(Fa,{height:r+n/2,radius:i/2,center:[-g+.06,0,-(r/2)+n/2]}),He(Fa,{height:r+n/2,radius:i/2,center:[g-.06,0,-(r/2)+n/2]})]})]})},L0i=({bodyLength:t=1.4,bodyDiameter:e=1.1,color:n="#3a3a3aff",contactColor:o="#c6c6c6",cathodeIdentification:i="#111"})=>zn(vi,{children:[He(_i,{color:n,children:zn(Bl,{rotation:[0,"90deg",0],children:[He(Yf,{size:[e,e,t-.2],roundRadius:.2,center:[-e/2,0,.05]}),He(Fa,{height:.2/2,radius:e/2-.2,center:[-e/2,0,-t/2+.2/2]})]})}),He(_i,{color:i,children:He(Bl,{rotation:[0,"90deg",0],children:He(Yf,{size:[e*1.01,e*1.01,t/3],roundRadius:.2,center:[-e/2,0,-t/4+.1]})})}),He(_i,{color:o,children:He(Bl,{rotation:[0,"90deg",0],children:He(k1,{height:.2,radius:e/2,roundRadius:.2/3,center:[-e/2,0,-t/2]})})}),He(_i,{color:o,children:He(Bl,{rotation:[0,"90deg",0],children:He(k1,{height:.2,radius:e/2,roundRadius:.2/3,center:[-e/2,0,t/2]})})})]}),inn=({bodyLength:t=3.5,bodyDiameter:e=1.5,color:n="#3a3a3aff",contactColor:o="#c6c6c6"})=>zn(vi,{children:[He(_i,{color:n,children:He(Bl,{rotation:[0,"90deg",0],children:He(k1,{height:t,radius:e/2,roundRadius:.3,center:[-e/2,0,0]})})}),He(_i,{color:o,children:He(Bl,{rotation:[0,"90deg",0],children:He(k1,{height:.5,radius:e/2,roundRadius:.2,center:[-e/2,0,-t/2]})})}),He(_i,{color:o,children:He(Bl,{rotation:[0,"90deg",0],children:He(k1,{height:.5,radius:e/2,roundRadius:.2,center:[-e/2,0,t/2]})})})]}),H0i=({bodyLength:t=3.9,bodyDiameter:e=2.5,color:n="#3a3a3aff",contactColor:o="#c6c6c6"})=>zn(vi,{children:[He(_i,{color:n,children:He(Bl,{rotation:[0,"90deg",0],children:He(k1,{height:t,radius:e/2,roundRadius:.3,center:[-e/2,0,0]})})}),He(_i,{color:o,children:He(Bl,{rotation:[0,"90deg",0],children:He(k1,{height:.55,radius:e/2,roundRadius:.2,center:[-e/2,0,-t/2]})})}),He(_i,{color:o,children:He(Bl,{rotation:[0,"90deg",0],children:He(k1,{height:.55,radius:e/2,roundRadius:.2,center:[-e/2,0,t/2]})})})]}),O0i=({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 zn(vi,{children:[Array.from({length:i}).map((c,l)=>He(ts,{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)=>He(ts,{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})),He(Sd,{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})]})},G0i=({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 zn(vi,{children:[Array.from({length:i}).map((c,l)=>He(ts,{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)=>He(ts,{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})),He(Sd,{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})]})},Y0i=[{x:-2.54,y:-1},{x:0,y:-1},{x:2.54,y:-1}],rnn=({mouldedTab:t=!1,leads:e=Y0i,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 zn(vi,{children:[He(_i,{color:l,children:He(ln,{size:[n,o,i],center:[h,d,m+i/2]})}),He(_i,{color:t?l:g,children:zn(Vh,{children:[He(ln,{size:[n,s,r],center:[h,f,p+r/2]}),He(Bl,{rotation:["90deg",0,0],children:He(ri,{center:[h,I,-f],children:He(Fa,{radius:a/2,height:s*3})})})]})}),e.map(x=>He(_i,{color:u,children:He(ln,{size:[C,y,A+c],center:[x.x,x.y,(A-c)/2]})},`lead-${x.x}-${x.y}`))]})},U0i=()=>{const c=1.1999999999999997;return zn(vi,{children:[He(ts,{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}),He(ts,{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}),He(ts,{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}),He(ts,{position:{x:-2.8/2-c/4,y:0,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:c,height:.95}),He(ts,{position:{x:-2.8/2-c/4,y:-.95,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:c,height:.95}),He(ts,{position:{x:-2.8/2-c/4,y:.95,z:.15/2},width:.4,thickness:.15,padContactLength:.5,bodyDistance:c,height:.95}),He(Sd,{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})]})},K0i=()=>zn(vi,{children:[He(Sd,{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 He(ln,{center:[-.8/2+.19/2-.1,l,.12/2],size:[.19,.15,.12]})}),[0,1,2].map(c=>{const l=-.35+c*.35;return He(ln,{center:[.8/2-.19/2+.1,l,.12/2],size:[.19,.15,.12]})})]}),V0i=[{x:-1.27,y:.98},{x:0,y:2.25},{x:1.27,y:.98}],z0i=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}},snn=({bodyDiameter:t=4.8,bodyHeight:e=4.5,flatCut:n=1.1,leads:o=V0i,standoff:i=1.5,leadLength:r=3,bodyColor:s="#222"}={})=>{const a=t/2,A=.4,c=.25,{outer:l,separation:g}=z0i(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 zn(vi,{children:[He(_i,{color:s,children:zn(Vh,{children:[He(ri,{center:[d.x,d.y,i+e/2],children:He(Fa,{radius:a,height:e})}),He(ri,{center:[d.x,d.y-(a-n/2),i+e/2],children:He(ln,{size:[a*2,n,e+.2]})})]})}),o.map((C,y)=>{const x=f(y);return zn(ri,{center:[0,0,0],children:[zn(cl,{children:[He(ri,{center:[C.x,C.y,0],children:He(ln,{size:I})}),He(ri,{center:[x.x,x.y,i],children:He(ln,{size:I})})]}),He(ri,{center:[C.x,C.y,-r/2],children:He(ln,{size:[c,A,r]})})]},`lead-${C.x}-${C.y}`)})]})},J0i=()=>zn(vi,{children:[He(ts,{rotation:Math.PI,position:{x:2/2+.75/4,y:-.65,z:.15/2},width:.25,thickness:.15,padContactLength:.3,bodyDistance:.75,height:.85}),He(ts,{rotation:Math.PI,position:{x:2/2+.75/4,y:0,z:.15/2},width:.25,thickness:.15,padContactLength:.3,bodyDistance:.75,height:.85}),He(ts,{rotation:Math.PI,position:{x:2/2+.75/4,y:.65,z:.15/2},width:.25,thickness:.15,padContactLength:.3,bodyDistance:.75,height:.85}),He(ts,{position:{x:-2/2-.75/4,y:0,z:.15/2},width:.25,thickness:.15,padContactLength:.3,bodyDistance:.75,height:.85}),He(ts,{position:{x:-2/2-.75/4,y:-.65,z:.15/2},width:.25,thickness:.15,padContactLength:.3,bodyDistance:.75,height:.85}),He(ts,{position:{x:-2/2-.75/4,y:.65,z:.15/2},width:.25,thickness:.15,padContactLength:.3,bodyDistance:.75,height:.85}),He(Sd,{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})]}),W0i=J0i,j0i=()=>zn(vi,{children:[He(Sd,{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 He(ln,{center:[-1/2+.3/2,A,.05/2],size:[.3,.2,.05]})}),[0,1,2].map(a=>{const A=-.5+a*.5;return He(ln,{center:[1/2-.3/2,A,.05/2],size:[.3,.2,.05]})})]}),ann=()=>zn(vi,{children:[He(ts,{position:{x:-2.5/2,y:0,z:.175/2},width:.3,thickness:.175,padContactLength:.3,bodyDistance:.45,height:.7}),He(ts,{rotation:Math.PI,position:{x:2.5/2,y:0,z:.175/2},width:.3,thickness:.175,padContactLength:.3,bodyDistance:.45,height:.7}),He(_i,{color:"#222",children:He(Sd,{center:{x:0,y:0,z:0},width:1.8,length:1.4,height:.95,includeNotch:!1,taperRatio:.06,straightHeightRatio:.7,heightAboveSurface:.05})}),He(ln,{color:"#777",size:[1.8/3,1.4-.075,.02],center:[-.9*2/3+.035,0,.95+.05]})]}),q0i=()=>zn(vi,{children:[He(ln,{color:"#ccc",size:[.4,.325,.175],center:[-1.05,0,.175/2]}),He(ln,{color:"#ccc",size:[.4,.325,.175],center:[1.05,0,.175/2]}),He(_i,{color:"#222",children:zn(Wp,{children:[He(ri,{z:.175/2,children:He(ln,{size:[1.7,1.25,.175]})}),zn(cl,{children:[He(ri,{z:.175,children:He(ln,{size:[1.7,1.25,.01]})}),He(ri,{z:.725,children:He(ln,{size:[1.7-.2,1.25-.2,.01]})})]})]})}),He(ln,{color:"#777",size:[1.7/3,1.25-.2,.02],center:[-1.05+1.7/4.4+.2,0,.725]})]}),X0i=()=>{const s=-1.0474999999999999,a=1.775/2+.4/2-.04;return zn(vi,{children:[He(ln,{color:"#ccc",size:[.4,.325,.13],center:[s,0,.13/2]}),He(ln,{color:"#ccc",size:[.4,.325,.13],center:[a,0,.13/2]}),He(_i,{color:"#222",children:He(Sd,{width:1.775,length:1.25,height:.725,center:{x:0,y:0,z:0},heightAboveSurface:0,straightHeightRatio:.7,taperRatio:.06,includeNotch:!1})}),He(ln,{color:"#777",size:[1.775/3,1.25-.05,.02],center:[s+1.775/4.4+.2,0,.725]})]})},$0i=({pitch:t=10})=>zn(vi,{children:[He(Fa,{height:4,radius:.5,center:[-t/2,0,.5]}),He(MG,{radius:.5,center:[-t/2,0,2.5]}),He(ri,{x:-2.5,y:0,z:2.5,children:zn(Bl,{rotation:[0,Math.PI/2,0],children:[He(Fa,{height:t,radius:.5,center:[0,0,2.5]}),He(_i,{color:"#d2b48c",children:He(Fa,{height:5,radius:1.3,center:[0,0,2.5]})})]})}),He(Fa,{height:4,radius:.5,center:[t/2,0,.5]}),He(MG,{radius:.5,center:[t/2,0,2.5]})]}),Z0i=({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=He(_i,{color:"#051a0a",children:zn(Vh,{children:[He(ln,{center:[0,0,h],size:[t,p,e]}),_.map((x,E)=>He(ln,{center:[x.x,x.y,h],size:[x.pl+.01,x.pw+.01,d]},E))]})}),C=c&&f.map((x,E)=>He(Fa,{color:"black",center:[x.x,x.y,h],radius:m,height:e*1.07})),y=_.map((x,E)=>He(ln,{center:[x.x,x.y,h],size:[x.pl+.01,x.pw+.01,d]}));return zn(vi,{children:[I,He(_i,{color:"#FFD700",children:c?zn(Vh,{children:[He(Wp,{children:_.map((x,E)=>He(ln,{center:[x.x,x.y,h],size:[x.pl+.01,x.pw+.01,d]},E))}),C]}):y})]})},Ann=({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 zn(ri,{offset:{x:I,y:C,z:y},children:[d>0&&He(_i,{color:s,children:He(ln,{size:[l,g,d],offset:[0,0,d/2]})}),He(_i,{color:s,children:zn(Vh,{children:[He(ln,{size:[l,g,h],offset:[0,0,d+h/2]}),He(ln,{size:[p,_,h+.02],offset:[0,0,d+h/2]})]})}),He(_i,{color:r,children:He(ln,{size:[p,_,f],offset:[0,0,d+f/2]})})]})},emi=({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,T=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,T=n,H=A==="left"?n:-n,G=0):(w=-((y-1)/2)*n,D=A==="top"?b/2-g:-b/2+g,k=n,T=0,H=0,G=A==="top"?-n:n);let U=0;for(let ce=0;ce<e&&U<t;ce++)for(let Ie=0;Ie<y&&U<t;Ie++){const he=w+Ie*k+ce*H,Ce=D+Ie*T+ce*G;Q.push({x:he,y:Ce}),U++}const Y=[];if(c)for(const ce of c){let Ie=0,he=0;ce==="topleft"?(Ie=-B/2+l,he=b/2-l):ce==="topright"?(Ie=B/2-l,he=b/2-l):ce==="bottomleft"?(Ie=-B/2+l,he=-b/2+l):ce==="bottomright"?(Ie=B/2-l,he=-b/2+l):ce==="center"&&(Ie=0,he=0),Y.push({x:Ie,y:he})}const q=.63,ee=2,W=6,J=3,ie=h||u?0:ee,oe=ie+r,ne=He(_i,{color:"#008080",children:zn(Vh,{children:[He(ln,{center:[0,0,C+ie],size:[B,b,r]}),Y.map((ce,Ie)=>He(Fa,{center:[ce.x,ce.y,C+ie],radius:i/2,height:r},`hole-${Ie}`)),Q.map((ce,Ie)=>He(Fa,{center:[ce.x,ce.y,C+ie],radius:i/2,height:r},`pin-hole-${Ie}`))]})}),le=Q.map((ce,Ie)=>He(_i,{color:"#FFD700",children:zn(Vh,{children:[He(Fa,{center:[ce.x,ce.y,r/2+ie],radius:i/2,height:r}),He(Fa,{center:[ce.x,ce.y,r/2+ie],radius:o/2,height:r})]})})),ue=Q.map((ce,Ie)=>He(Ytn,{x:ce.x,y:ce.y,pinThickness:q,shortSidePinLength:J,longSidePinLength:W,bodyHeight:ee,flipZ:he=>he})),_e=Q.map((ce,Ie)=>He($tn,{x:ce.x,y:ce.y,flipZ:he=>-he}));return zn(vi,{children:[ne,le,!u&&!h&&ue,u&&_e,I&&He(Ann,{width:m??B*.8,height:p??b*.6,offset:{x:_??0,y:f??0,z:oe}})]})},tmi=()=>{const s=.8999999999999999,a=-s/2+.5/2-.15,A=s/2-.5/2+.15,c=.2,l=.5*.24;return zn(vi,{children:[He(ln,{color:"#ccc",size:[.5,.28,.12],center:[a,0,.12/2]}),He(ln,{color:"#ccc",size:[.5,.28,.12],center:[A,0,.12/2]}),He(_i,{color:"#222",children:zn(Wp,{children:[He(ri,{z:l/2,children:He(ln,{size:[s,.6,l]})}),zn(cl,{children:[He(ri,{z:l,children:He(ln,{size:[s,.6,.01]})}),He(ri,{z:.5,children:He(ln,{size:[s-c,.6-c,.01]})})]})]})}),He(ln,{color:"#777",size:[1.4/6,.6-c,.02],center:[-s/4,0,.5]})]})},nmi=tmi,omi=({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 zn(vi,{children:[He(ri,{offset:[0,0,6],children:He(Bl,{angles:[Math.PI,0,0],children:He(_i,{color:o,children:zn(Vh,{children:[He(ln,{size:[g,3.5,6],center:[0,0,6/2]}),He(ln,{size:[g-.5*2,3.5-.5*2,c],center:[0,0,c/2]}),He(ln,{size:[g,3.5/3,c],center:[0,0,c/6]}),He(ln,{size:[g-.5*2,.5/2,c],center:[0,3.5/2-.5/4,c/2]}),He(ln,{size:[g-.5*2,.5/2,c],center:[0,-3.5/2+.5/4,c/2]}),He(ln,{size:[1,.5+2,1],center:[-g/4,3.5/2,6/2]}),He(ln,{size:[1,.5+3,1],center:[g/4,3.5/2,6/2]}),He(ln,{size:[1,.5+2,1],center:[-g/4,-3.5/2,6/2]}),He(ln,{size:[1,.5+3,1],center:[g/4,-3.5/2,6/2]})]})})})}),e&&Array.from({length:t}).map((h,d)=>He(_i,{color:i,children:He(Fa,{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 He(pUe,{hole:p,isPin1:m})})]})},imi=({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 zn(vi,{children:[He(ri,{offset:[0,0,6],children:He(Bl,{angles:[Math.PI,0,0],children:He(_i,{color:o,children:zn(Vh,{children:[He(ln,{size:[d,4.5,6],center:[0,0,6/2]}),He(ln,{size:[d-.5*2,4.5-.5*2,c],center:[0,0,c/2]}),He(ln,{size:[d,4.5/3,c],center:[0,0,c/6]}),He(ln,{size:[d-.5*2,.5/2,c],center:[0,4.5/2-.5/4,c/2]}),He(ln,{size:[d-.5*2,.5/2,c],center:[0,-4.5/2+.5/4,c/2]}),He(ln,{size:[p,4.5+.5,_],center:[-d/2+f,0,6/2]}),He(ln,{size:[p,4.5+.5,_],center:[d/2-f,0,6/2]}),He(ln,{size:[.5*3,I,C],center:[-d/2,0,C/2]}),He(ri,{offset:[-d/2,0,C],children:He(Bl,{angles:[0,Math.PI/2,0],children:He(Fa,{height:.5*3,radius:I/2})})}),He(ln,{size:[.5*3,I,C],center:[d/2,0,C/2]}),He(ri,{offset:[d/2,0,C],children:He(Bl,{angles:[0,Math.PI/2,0],children:He(Fa,{height:.5*3,radius:I/2})})})]})})})}),e&&Array.from({length:t}).map((y,x)=>He(_i,{color:i,children:He(ln,{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 He(pUe,{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 zn(vi,{children:[He(ri,{offset:[0,0,7/2],children:He(_i,{color:o,children:zn(Vh,{children:[He(ln,{size:[u,5.75,7]}),He(ri,{offset:[0,0,(7-5.35)/2+.1],children:He(ln,{size:[u-.85*2,5.75-.85*2,5.35+.2]})}),He(ri,{offset:[0,-5.75/2+.85/2,7/2-I/2+.1],children:He(ln,{size:[f,.85+.2,I+.2]})}),He(ri,{offset:[-_,-5.75/2+.85/2,7/2-p/2+.1],children:He(ln,{size:[d,m,p+.2]})}),He(ri,{offset:[_,-5.75/2+.85/2,7/2-p/2+.1],children:He(ln,{size:[d,m,p+.2]})}),Array.from({length:t}).map((C,y)=>He(ri,{offset:[h+y*2.5,-5.75/2+.3,-7/2+.25],children:He(ln,{size:[1,.8,.5]})},`vent_${y}`))]})})}),e&&Array.from({length:t}).map((C,y)=>He(_i,{color:i,children:He(ri,{offset:[h+y*2.5,0,8.75/2-3.4],children:He(ln,{size:[.64,.64,8.75]})})})),n&&(()=>{try{return sX.string(`jst${t}_xh`).circuitJson().filter(x=>x.type==="pcb_plated_hole").map((x,E)=>He(pUe,{hole:x,isPin1:E===0},`footprint_${E}`))}catch{return null}})()]})},smi=([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},kUe=({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)=>He(Fa,{center:[a,A,i+o/2],height:o,radius:n}))},ami=({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=kUe({width:h,length:d,radius:Math.min(.13,d*.08),height:u,z:l}),Q=[...kUe({width:m,length:p,radius:Math.min(.14,p*.08),height:C,z:I}),...kUe({width:_,length:f,radius:Math.min(.15,f*.09),height:C,z:i-C})];return zn(vi,{children:[B.map((w,D)=>He(_i,{color:"#d6a258",children:He(NG,{height:a,children:He(DG,{points:smi(w,A,c,y,D===0)})})})),He(Sd,{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}),He(_i,{color:"#d2a057",children:He(cl,{children:b})}),He(_i,{color:"#b9bec2",children:He(cl,{children:Q})})]})},Ami="#303339",_he="#1f2227",cnn="#eee8d8",lnn="#f8f3e7",FUe="#b7bdc2",cmi="#d2d6d9",lmi="#767d82",gmi="#9ba1a5",umi=({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,ke)=>{const Ye=i&&ke%2===1!==r,$e=i?Ye?s/2:-s/2:0,st=Ye?a:A;return{index:ke,x:m+ke*e,y:$e,length:st}}),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,T=w-b*.01,H=Math.max(d+4.9,p+u*.76),G=Math.min(H-2.3,d+1.1),U=.3,Y=1.42,q=2,ee=Math.min(.92,D*.28),W=T+b*(ee/2-.04),J=1.6,ie=1.1,oe=Math.max(D-.78,1.5),ne=T+b*(oe/2+.68),le=H-.72,ue=.34,_e=q-ue/2,ce=T+b*Math.min(.68,D*.22),Ie=1.48,he=Math.max(n*.82,.15),Ce=E,Pe=Math.abs(Ce-Q),Qe=(Ce+Q)/2,pe=Math.max(ee*.8,.5),ve=T+b*(pe/2+.08),Me=p/2,we=.75,Oe=H/2-.04,Re=H/2-.23,Se=H/2-.32,Le=.68;return zn(vi,{children:[[-1,1].map(ye=>He(ln,{color:FUe,center:[ye*Me,_,.07],size:[u,h,.14]})),f.map(ye=>He(ln,{color:FUe,center:[ye.x,Qe,.065],size:[he,Pe,.13]},`terminal:${ye.index}`)),He(Yf,{color:_he,center:[0,k,U/2],size:[H,D,U],roundRadius:.1}),He(_i,{color:Ami,children:zn(Vh,{children:[He(Yf,{center:[0,k,U+Y/2],size:[H-.2,D-.12,Y],roundRadius:.14}),He(ln,{center:[0,W,ie],size:[G,ee,J]}),He(ln,{center:[0,ne,q-ue*.72],size:[le-.32,oe-.16,ue]})]})}),f.map(ye=>He(Yf,{color:cmi,center:[ye.x,ve,U+.82],size:[he*.82,pe,.14],roundRadius:.035},`spring:${ye.index}`)),f.map(ye=>He(ln,{color:FUe,center:[ye.x,Q-b*.03,U+.32],size:[he,.13,.62]},`terminal-rise:${ye.index}`)),He(ln,{color:_he,center:[0,T+b*.1,U+.71],size:[G+.18,.16,.8]}),He(Yf,{color:cnn,center:[0,ne,_e],size:[le,oe,ue],roundRadius:.11}),He(ln,{color:lnn,center:[0,ne-b*(oe/2-.12),q-.035],size:[le-.36,.24,.07]}),[-1,1].map(ye=>He(Yf,{color:cnn,center:[ye*Se,ce,Ie],size:[Le,.92,.72],roundRadius:.1})),[-1,1].map(ye=>He(ri,{x:ye*Se,y:ce,z:Ie,children:He(Bl,{rotation:[0,Math.PI/2,0],children:He(Fa,{color:lnn,height:Le+.12,radius:.24})})})),[-1,1].map(ye=>He(Yf,{color:lmi,center:[ye*Oe,_,we/2],size:[.17,Math.min(h*.3,.7),we],roundRadius:.04})),[-1,1].map(ye=>He(Yf,{color:gmi,center:[ye*Re,_,we-.05],size:[.42,Math.min(h*.3,.7),.1],roundRadius:.035})),He(ln,{color:_he,center:[0,k,.025],size:[G+.7,D*.58,.05]}),He(ln,{color:_he,center:[0,Q-b*.06,U+.82],size:[G+.4,.15,.92]})]})},dmi=({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 He(vi,{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 zn(ri,{x:d,children:[He(ln,{color:"#222",size:[e,o,i],center:[0,0,r+i/2]}),zn(_i,{color:"#d4af37",children:[He(ln,{size:[n,l,n],center:[0,m*(l/2),n/2]}),He(ln,{size:[n,n,_],center:[0,0,n/2+_/2]}),He(ln,{size:[n,n,p],center:[0,0,c+p/2]}),zn(cl,{children:[He(ln,{size:[n,n,.01],center:[0,0,c+p]}),He(ln,{size:[n*.65,n*.65,.01],center:[0,0,c+s]})]})]})]})})})},mX=t=>sX.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]})),gnn=t=>sX.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]})),hmi=({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 zn(vi,{children:[He(Sd,{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 He(ts,{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}`)})]})},mmi=({padPitch:t,padHeight:e,color:n="#333"})=>{const o=t,i=e*.85,r=i,s=o*.2,a=o-s*2;return zn(vi,{children:[He(ln,{size:[a,i,r],offset:[0,0,r/2],color:n}),He(ln,{size:[s,r,i],offset:[o/2-s/2,0,r/2],color:"#ccc"}),He(ln,{size:[s,r,i],offset:[-o/2+s/2,0,r/2],color:"#ccc"})]})},pmi=({color:t="#ffff00",bodyColor:e="#ffffff",leadColor:n="#dedede"})=>{const p=[-1.7,0,1.7],_=[-1,1];return zn(vi,{children:[p.flatMap(f=>_.map(I=>He(ln,{color:n,size:[1.4,1,.2],center:[I*2,f,.2/2]}))),He(_i,{color:e,children:zn(Vh,{children:[He(Sd,{width:5,length:5,height:1.3,heightAboveSurface:.2,center:{x:0,y:0,z:0},color:e,taperRatio:.036,straightHeightRatio:.01,includeNotch:!1}),He(Fa,{radius:2,height:.25,center:[0,0,1.5-.25/2]}),He(ri,{offset:[-5/2,5/2,1.5-.3/2+.005],children:He(Bl,{rotation:[0,0,Math.PI/4],children:He(ln,{size:[.9,.9,.3+.01]})})})]})}),He(Fa,{color:t,radius:2,height:.25,center:[0,0,1.55-.25/2]})]})},_mi=({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 zn(vi,{children:[[{x:s,w:a,key:"pad-1"},{x:A,w:c,key:"pad-2"}].map(({x:p,w:_,key:f})=>He(_i,{color:r,children:He(ln,{size:[_,l,.1],center:[p,0,.1/2]})})),He(_i,{color:i,children:He(ln,{size:[t,e,n],center:[h,0,.1+n/2]})}),He(_i,{color:o,children:He(ln,{size:[d,m,.15],center:[h,0,.1+n+.15/2-.05]})})]})},unn=t=>Array.from({length:t},(e,n)=>n),fmi=({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),T=B-E*k/2,H=B-E*(k+b*.7),G=Math.max(.22,Math.min(c*.36,.38)),U=unn(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+_],q=Q/10,ee=B-E*Math.max(k*.48,1.2),W=D+w*.18,J=B+E*b*.2;return zn(vi,{children:[zn(_i,{color:C,children:[zn(Vh,{children:[He(ln,{center:[0,o,n/2],size:[t,e,n]}),He(ln,{center:[0,T,D],size:[Q,k+b*2,w]})]}),He(ln,{center:[0,J,.72],size:[Q+.5,b*1.25,1.05]}),[-1,1].map(ie=>He(ln,{center:[ie*l,g,.25],size:[Math.max(u*.46,.65),Math.max(u*.72,1.1),3.4]})),[-1,1].map(ie=>He(ln,{center:[ie*t*.24,o-E*e*.08,n+.04],size:[t*.22,e*.42,.1]}))]}),zn(_i,{color:y,children:[zn(Vh,{children:[He(Yf,{center:[0,T,D],size:[Q-.2,k+b*.5,w-.2],roundRadius:.22}),He(ln,{center:[0,T-E*b*.2,D-.05],size:[Q-1.25,k+b,w-1.35]})]}),He(ln,{center:[0,H,D],size:[Q-1.15,b,w-1.25]}),He(Yf,{center:[0,B-E*k*.28,1.55],size:[Q-2.6,k*.5,1.15],roundRadius:.16}),[-1,1].map(ie=>He(Fa,{center:[ie*h,d,-.25],radius:Math.max(m*.41,.65),height:2.7}))]}),zn(_i,{color:x,children:[U.map(({x:ie,y:oe},ne)=>He(Fa,{center:[ie,oe,.15],radius:G,height:3.1})),unn(8).map(ie=>He(ri,{offset:[(ie-3.5)*q,ee,W+(ie%2===0?.03:-.03)],children:He(Bl,{rotation:[E*.2,0,0],children:He(Yf,{size:[Math.max(q*.28,.28),3.25,.16],roundRadius:.05})})})),i&&Y.map((ie,oe)=>He(Fa,{center:[ie,f,.15],radius:G,height:3.1}))]}),i&&zn(vi,{children:[He(Yf,{color:"#73b744",center:[-t/2+2.05,B+E*b*.35,n-2.05],size:[2.15,b*1.55,1.45],roundRadius:.18}),He(Yf,{color:"#e0aa35",center:[t/2-2.05,B+E*b*.35,n-2.05],size:[2.15,b*1.55,1.45],roundRadius:.18})]})]})},Imi=({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 zn(vi,{children:[He(_i,{color:l,children:He(ln,{size:[o,i,.5],center:[h,0,.5/2]})}),He(_i,{color:c,children:He(ln,{size:[t,e,n],center:[m,0,.5+n/2]})}),[-1,1].map(I=>zn(_i,{color:g,children:[He(ln,{size:[A,a,f],center:[d+A/2,I*s,f/2]}),zn(cl,{children:[He(ln,{size:[.1,a,f],center:[d+A,I*s,f/2]}),He(ln,{size:[.1,a,f],center:[p,I*s,_+.5/2]})]})]},`lead-${I}`))]})},Cmi=({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 zn(vi,{children:[He(_i,{color:a,children:He(Fa,{radius:A-.05,height:c,center:[0,0,c/2]})}),He(_i,{color:s,children:zn(Vh,{children:[He(k1,{radius:A,height:l,roundRadius:Math.min(.3,A*.15),center:[0,0,g+l/2]}),He(ln,{size:[t,h,d*2],center:[0,0,u]}),He(ln,{size:[h,t,d*2],center:[0,0,u]})]})}),[-1,1].map(m=>He(_i,{color:"#c0c0c0",children:He(Fa,{radius:i/2,height:r+c,center:[m*o/2,0,(c-r)/2]})}))]})},ymi=({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 zn(vi,{children:[He(_i,{color:l,children:He(ln,{size:[t,e,n],center:[o,0,n/2]})}),He(_i,{color:g,children:zn(Vh,{children:[He(Fa,{radius:i/2,height:.8,center:[o,0,h]}),He(ln,{size:[i,d,.8*.6],center:[o,0,h+.8/2]})]})}),s>0&&r>0?He(_i,{color:g,children:He(Fa,{radius:r/2,height:s,center:[o,0,n+s/2]})}):null,a.map(m=>He(_i,{color:"#c0c0c0",children:He(Fa,{radius:A/2,height:n/2+c,center:[m.x,m.y,(n/2-c)/2]})},`lead-${m.x}-${m.y}`))]})},xmi=({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"})=>zn(vi,{children:[He(_i,{color:c,children:He(ln,{size:[t,e,n],center:[0,0,n/2]})}),He(_i,{color:l,children:He(Fa,{radius:o/2,height:i,center:[0,0,n+i/2]})}),[-1,1].flatMap(h=>[-1,1].map(d=>He(_i,{color:g,children:He(ln,{size:[a,A,.15],center:[h*r/2,d*s/2,.15/2]})})))]}),Emi=({fullWidth:t=1.94,fullLength:e=1.6})=>zn(vi,{children:[He(Bl,{rotation:[45*Math.PI,0,0],children:He(ri,{center:[0,0,-.4],children:He(_i,{color:"grey",children:He(ln,{size:[1.2,1.6,.55]})})})}),[-1,0,1].flatMap((l,g)=>[He(ri,{center:[-1.2/2-.03,l*.5,.13/2],children:He(ln,{size:[.67,.3,.13]})}),He(ri,{center:[1.2/2+.03,l*.5,.13/2],children:He(ln,{size:[.67,.3,.13]})})])]}),Bmi=({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?sX.string(c).circuitJson():null;return zn(vi,{children:[He(ri,{z:g,children:He(_i,{color:"#555",children:He(ln,{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 He(ri,{x:f,y:I,z:u,children:He(MG,{radius:r/2})})}),h&&h.map((d,m)=>d.type==="pcb_smtpad"?He(ri,{x:d.x,y:d.y,z:u,children:He(MG,{radius:r/2})}):null)]})},Smi=16/9,bmi=40,NM=1e-6,J_=(t,e)=>{if(!Number.isFinite(e)||e<=0)throw new Error(`${t} must be a finite number greater than zero`)},Qmi=t=>{if(t===void 0)return Smi;if(typeof t=="number")return J_("aspectRatio",t),t;if(typeof t!="string"){const[i,r]=t;return J_("aspectRatio width",i),J_("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 J_("aspectRatio width",n),J_("aspectRatio height",o),n/o},vmi=({width:t,height:e,diagonal:n,aspectRatio:o,ratio:i,defaultDiagonal:r=bmi})=>{const s=Qmi(o??i);t!==void 0&&J_("width",t),e!==void 0&&J_("height",e),n!==void 0&&J_("diagonal",n),J_("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}},Pmi=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"},wmi=(t,e)=>Math.hypot(e[0]-t[0],e[1]-t[1],e[2]-t[2]),Mmi=(t,e,n)=>[t[0]+(e[0]-t[0])*n,t[1]+(e[1]-t[1])*n,t[2]+(e[2]-t[2])*n],LUe=t=>{const e=[0];for(let n=1;n<t.length;n+=1)e.push(e[n-1]+wmi(t[n-1],t[n]));return e},dnn=(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 Mmi(t[i-1],t[i],(n-r)/s)}return t.at(-1)},fhe=(t,e,n)=>{const o=LUe(t),i=o.at(-1),r=Math.max(0,Math.min(e,i)),s=Math.max(r,Math.min(n,i)),a=[dnn(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(dnn(t,o,s)),a},Dmi=(t,e)=>[t,[t[0],t[1]+e,t[2]]],Nmi=({start:t,endZ:e,flexCableLength:n,foldDistanceFromConnector:o,foldOutset:i,foldSegments:r})=>{const s=[t],a=[t[0],t[1]+o,t[2]];o>NM&&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=LUe(s).at(-1);if(A>n+NM)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>NM){const l=s.at(-1);s.push([l[0],l[1]-c,l[2]])}return s},Rmi=({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>NM&&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>NM){const h=u.at(-1);u.push([h[0],h[1],h[2]+r*l])}return u},pX=({points:t,width:e,thickness:n,color:o,acrossOffset:i=0,normalOffset:r=0,overlap:s=.03})=>He(_i,{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<NM)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 He(ri,{offset:p,children:He(Bl,{rotation:[d,0,m],children:He(Yf,{size:[e,h+s,n],center:[i,0,r],roundRadius:_})})},`${A}:${p.join(":")}`)})}),Tmi=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:T="#416bb3",bendRadius:H=3,bendSegments:G=10,rightAngleVerticalLead:U=3,distanceAboveBoard:Y=7,distanceBelowBoard:q=7,foldDistanceFromConnector:ee=7,foldOutset:W=4,foldSegments:J=18,screenGap:ie=.08,boardTopZ:oe=0,boardThickness:ne=1.6,boardClearance:le=.15,cableStartX:ue=0,cableStartY:_e=0,cableStartZ:ce,cableLateralOffset:Ie=0,screenOffset:he,screenRotation:Ce,rotation:Pe=[0,0,0],offset:Qe}=t,pe=vmi({width:e,height:n,diagonal:o,aspectRatio:i,ratio:r,defaultDiagonal:s}),ve=Pmi(t),Me=ve==="sitsFlatBelowBoard"||ve==="foldedToFaceBelowBoard"||ve==="foldedToRightAngleBelowBoard",we=ve==="foldedToFaceAboveBoard"||ve==="foldedToFaceBelowBoard",Oe=ve==="foldedToRightAngleAboveBoard"||ve==="foldedToRightAngleBelowBoard";if(J_("screenThickness",a),J_("flexCableLength",m),J_("flexCableThickness",p),J_("conductorThickness",y),J_("bendRadius",H),J_("foldOutset",W),J_("boardThickness",ne),w&&J_("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||U<0||Y<0||q<0||ee<0)throw new Error("clearances, margins, contact lengths, and lead lengths cannot be negative");const Re=t.flexCableWidth??Math.min(12,Math.max(5,pe.width*.3));J_("flexCableWidth",Re);const Se=Re-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,Re*.45):Le*.48);if(J_("conductorWidth",ye),(f-1)*Le+ye>Se+NM)throw new Error("conductorPitch and conductorWidth do not fit inside the flex cable margins");const $e=Me&&!we?oe-ne-le-p/2:oe+le+p/2,st=[ue+Ie,_e,ce??$e],it=Me?-1:1,je=ve==="foldedToFaceAboveBoard"?oe+Y:oe-ne-q,ht=ve==="foldedToFaceAboveBoard"?je-ie-p/2:je+ie+p/2,Bt=we?Nmi({start:st,endZ:ht,flexCableLength:m,foldDistanceFromConnector:ee,foldOutset:W,foldSegments:J}):Oe?Rmi({start:st,flexCableLength:m,bendRadius:H,bendSegments:G,verticalLead:U,direction:it}):Dmi(st,m),Ct=LUe(Bt).at(-1),Ht=Math.min(Math.max(0,B),Ct/2),Lt=Math.min(Math.max(0,D),Ct/2),It=fhe(Bt,0,Ht),Jt=fhe(Bt,Ct-Ht,Ct),Cn=fhe(Bt,0,Lt),Be=fhe(Bt,Ct-Lt,Ct),Ze=Bt.at(-1);let _t,gt;ve==="sitsFlat"?(_t=[0,0,0],gt=[Ze[0],Ze[1]+pe.height/2,Ze[2]+p/2+ie]):ve==="sitsFlatBelowBoard"?(_t=[0,Math.PI,0],gt=[Ze[0],Ze[1]+pe.height/2,Ze[2]-p/2-ie]):ve==="foldedToFaceAboveBoard"?(_t=[0,0,0],gt=[Ze[0],Ze[1]-pe.height/2,je]):ve==="foldedToFaceBelowBoard"?(_t=[0,Math.PI,0],gt=[Ze[0],Ze[1]-pe.height/2,je]):ve==="foldedToRightAngleAboveBoard"?(_t=[Math.PI/2,0,0],gt=[Ze[0],Ze[1]-p/2-ie,Ze[2]+pe.height/2]):(_t=[-Math.PI/2,0,0],gt=[Ze[0],Ze[1]+p/2+ie,Ze[2]-pe.height/2]),gt=[gt[0]+(he?.x??0),gt[1]+(he?.y??0),gt[2]+(he?.z??0)];const Xe=Array.from({length:f},(rt,dt)=>f===1?0:(dt-(f-1)/2)*Le),pt=(p+y)/2,bt=-(p+k)/2,tt=zn(vi,{children:[Q&&He(pX,{points:Bt,width:Re,thickness:p,color:_}),Q&&w&&Lt>NM&&zn(vi,{children:[He(pX,{points:Cn,width:Re,thickness:k,color:T,normalOffset:bt}),He(pX,{points:Be,width:Re,thickness:k,color:T,normalOffset:bt})]}),Q&&b&&Ht>NM&&Xe.map((rt,dt)=>zn(vi,{children:[He(pX,{points:It,width:ye,thickness:y,color:x,acrossOffset:rt,normalOffset:pt}),He(pX,{points:Jt,width:ye,thickness:y,color:x,acrossOffset:rt,normalOffset:pt})]},`conductor:${dt}`)),d&&He(ri,{offset:gt,children:He(Bl,{rotation:Ce??_t,children:He(Ann,{width:pe.width,height:pe.height,thickness:a,bezelInset:A,bezelDepth:c,screenWidth:l,screenHeight:g,screenColor:u,bezelColor:h})})})]});return He(ri,{offset:{x:Qe?.x??0,y:Qe?.y??0,z:Qe?.z??0},children:He(ri,{offset:st,children:He(Bl,{rotation:Pe,children:He(ri,{offset:[-st[0],-st[1],-st[2]],children:tt})})})})},kmi=({footprint:t})=>{const e=hUe.string(t.split("_",1)[0]).params().fn;if(hUe.getModelNames().includes(e)){const a=hUe.string(t).json();if(a.fn==="flexscreen"){const{fn:A,...c}=a;return He(Tmi,{...c})}}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=sX.string(n).json(),i=t.match(/_color\(([^)]+)\)/),r=i?i[1]:void 0,s=(a,A)=>{if(a==null)return A;const c=yA(a);return Number.isFinite(c)?c:A};switch(o.fn){case"crystal":return He(ami,{horizontalPadPitch:o.px,verticalPadPitch:o.py,padWidth:o.pw,padHeight:o.ph});case"dip":return He(Xhi,{numPins:o.num_pins,pitch:o.p,bodyWidth:o.w});case"axial":return He($0i,{pitch:o.p});case"tssop":return He(Zhi,{pinCount:o.num_pins,leadLength:o.pl,leadWidth:o.pw,pitch:o.p,bodyWidth:o.w});case"msop":return He(e0i,{pinCount:o.num_pins,padContactLength:o.pl,leadWidth:o.pw,pitch:o.p,bodyWidth:o.w});case"vssop":return He(x0i,{pinCount:o.num_pins,leadLength:o.pl,leadWidth:o.pw,pitch:o.p,bodyWidth:o.w,bodyLength:o.h});case"qfp":return He(Gtn,{pinCount:o.num_pins,pitch:o.p,leadWidth:o.pw,padContactLength:o.pl,bodyWidth:o.w});case"tqfp":return He(N0i,{});case"lqfp":return He(T0i,{pinCount:o.num_pins});case"qfn":{const a=typeof o.thermalpad?.x=="number"&&typeof o.thermalpad?.y=="number";return He(Ktn,{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 He(onn,{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+)/),A=a&&a[1]?parseInt(a[1],10):1;if(o.male)return He(Utn,{numberOfPins:o.num_pins,pitch:o.p,invert:o.invert,rows:A,smd:o.smd||o.surface_mount,rightangle:o.rightangle});if(o.female)return He(I0i,{numberOfPins:o.num_pins,pitch:o.p,rows:A})}case"smdpinheader":return He(dmi,{numberOfPins:o.num_pins,pitch:o.p,bodyWidth:o.bh});case"led5050":return He(pmi,{color:r});case"cap":{switch(o.imperial){case"0402":return He(Ltn,{color:"#856c4d"});case"0603":return He(Htn,{color:"#856c4d"});case"0805":return He(Otn,{color:"#856c4d"});case"0201":return He(ztn,{color:"#856c4d"});case"01005":return He(Jtn,{color:"#856c4d"});case"1206":return He(Wtn,{color:"#856c4d"});case"1210":return He(jtn,{color:"#856c4d"});case"2010":return He(qtn,{color:"#856c4d"});case"2512":return He(Xtn,{color:"#856c4d"})}break}case"sot23":switch(o.num_pins){case 3:return He(g0i,{color:r});case 5:return He(Vtn,{})}break;case"sot25":return He(Vtn,{});case"sot":case"sot343":{const a=o.fn==="sot343";return He(hmi,{pads:gnn(n),bodyWidth:a?1.25:1.6,bodyLength:a?2:2.9,bodyHeight:a?1.1:1.3})}case"sot563":return He(Emi,{});case"sot89":{const a=s(o.w,4.2);return He(nnn,{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 He(U0i,{});case"sot223":return He(nnn,{});case"sot23w":return He(u0i,{});case"sot323":return He(R0i,{});case"sod323f":return He(q0i,{});case"sod323fl":return He(X0i,{});case"sot363":return He(W0i,{});case"sot886":return He(j0i,{});case"sot963":return He(K0i,{});case"pushbutton":return He(C0i,{width:o.w,length:o.h,innerDiameter:o.id});case"jst":if(o.zh)return He(omi,{numPins:o.num_pins});if(o.ph)return He(imi,{numPins:o.num_pins});if(o.xh)return He(rmi,{numPins:o.num_pins});break;case"fpc":return He(umi,{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 He(fmi,{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 He(y0i,{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),A=o.fn==="vson"?s(o.grid?.y,3):s(o.h,3),c=s(o.epw,0),l=s(o.eph,0),g=o.pl!==void 0?s(o.pl,0):void 0,u=o.pw!==void 0?s(o.pw,0):void 0,h=gnn(n).filter(_=>Number(_.pin??0)<=o.num_pins),d=_=>new Set(_.map(f=>f.toFixed(3))).size,m=h.length>2&&d(h.map(_=>_.y))===2&&d(h.map(_=>_.x))>2,p=He(onn,{num_pins:o.num_pins,bodyWidth:m?A:a,bodyLength:m?a:A,pitch:s(o.p,.5),padLength:g,padWidth:u,thermalPadSize:o.ep&&c>0&&l>0?{width:m?l:c,length:m?c:l}:void 0});return m?He(Bl,{rotation:[0,0,"90deg"],children:p}):p}case"mlp":case"lga":case"quad":return o.legsoutside?He(Gtn,{pinCount:o.num_pins,pitch:s(o.p,.5),leadWidth:s(o.pw,.25),padContactLength:s(o.pl,.25),bodyWidth:s(o.w,6)}):He(Ktn,{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),A=o.grid?.x??8,c=o.grid?.y??8;return He(Bmi,{ballPitch:a,ballColumns:A,ballRows:c,ballDiameter:a*.625,packageWidth:A*a,packageLength:c*a})}case"sod523":return He(E0i,{});case"sod723":return He(nmi,{});case"sod882":return He(Ztn,{});case"sma":return He(B0i,{});case"smb":return He(enn,{});case"smc":return He(S0i,{});case"smf":return He(b0i,{});case"sod123":return He(P0i,{});case"sod123f":return He(Q0i,{});case"sod123fl":return He(v0i,{});case"sod123w":return He(tnn,{});case"sod110":return He(tnn,{bodyWidth:2.1,bodyLength:1.4});case"sod128":return He(w0i,{});case"sod323":return He(ann,{});case"sod323w":return He(ann,{});case"sod80":return He(inn,{});case"sod882d":return He(Ztn,{});case"smbf":return He(enn,{});case"led2835":return He(_mi,{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),A=t.match(/_d([\d.]+)/),c=o.d!==void 0?s(o.d,a*2):A?Number(A[1]):a*2;return He(Cmi,{diameter:c,leadPitch:a})}case"potentiometer":return He(ymi,{bodyWidth:s(o.w,5.35),bodyLength:s(o.ca,14),bodyHeight:s(o.h,4),leads:mX(n)});case"smdpushbutton":return He(xmi,{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),A=s(o.w,10)/2,c=[{x:-A,pins:o.left??0,key:"left"},{x:A,pins:o.right??0,key:"right"}];return He(vi,{children:c.filter(({pins:l})=>l>0).map(({x:l,pins:g,key:u})=>He(ri,{center:[l,0,0],children:He(Bl,{rotation:[0,0,"90deg"],children:He(Utn,{numberOfPins:g,pitch:a})})},u))})}case"sod923":return He(M0i,{});case"hc49":return He(F0i,{});case"micromelf":return He(L0i,{});case"minimelf":return He(inn,{});case"melf":return He(H0i,{});case"ms012":return He(O0i,{pinCount:o.num_pins,padContactLength:o.pl,leadWidth:o.pw,pitch:o.p});case"ms013":return He(G0i,{pinCount:o.num_pins,padContactLength:o.pl,leadWidth:o.pw,pitch:o.p});case"sot723":return He(k0i,{});case"to220":return He(rnn,{leads:mX(n)});case"to220f":return He(rnn,{mouldedTab:!0,leads:mX(n)});case"to92":return He(snn,{leads:mX(n)});case"to92l":case"to92s":{const a=s(o.w,4.8),A=s(o.h,4),c=Math.max(a,A);return He(snn,{bodyDiameter:c,flatCut:Math.max(c-Math.min(a,A),.4),leads:mX(n)})}case"to252":case"dpak":case"to263":case"d2pak":{const a=o.fn==="to263"||o.fn==="d2pak",A=s(o.tabw,a?8.38:6.2),c=Math.min(s(o.tabh,a?10:5.8),a?10:6.5);return He(Imi,{bodyWidth:A,bodyLength:s(o.w,a?10.1:6.6),bodyHeight:a?4.4:2.3,tabWidth:A,tabLength:c,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 He(Z0i,{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,A=o.pinRowSide??"left",c=o.holeInset,l=o.width,g=o.height,u=o.pinrow,h=o.pinRowHoleEdgeToEdgeDist,d=Array.isArray(o.holes)?o.holes:[];return He(emi,{numPins:u,rows:a,p:o.p,id:o.id,od:o.od,width:l,height:g,pinRowSide:A,holes:d,holeInset:c,pinRowHoleEdgeToEdgeDist:h,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 He(Ltn,{color:r});case"0603":return He(Htn,{color:r});case"0805":return He(Otn,{color:r});case"0201":return He(ztn,{color:r});case"01005":return He(Jtn,{color:r});case"1206":return He(Wtn,{color:r});case"1210":return He(jtn,{color:r});case"2010":return He(qtn,{color:r});case"2512":return He(Xtn,{color:r})}if((o.fn==="res"||o.fn==="cap")&&o.p!==void 0&&o.ph!==void 0){const a=yA(o.p),A=yA(o.ph);if(Number.isFinite(a)&&Number.isFinite(A))return He(mmi,{padPitch:a,padHeight:A,color:r??(o.fn==="cap"?"#856c4d":void 0)})}return null},Fmi=t=>t&&typeof t=="object"&&"type"in t,KG=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},Lmi=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 tP(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=>tP(u,e,n));if(!Fmi(t))return[];const{type:c,props:l,children:g}=t;if(c===Ttn)return(g??[]).flatMap(u=>tP(u,e,n));if(c===_i){const u=l?.color;return(g??[]).flatMap(h=>tP(h,u??e,n))}if(c===ri){const u=Lmi(l?.offset??l?.center??{x:l?.x,y:l?.y,z:l?.z});return(g??[]).flatMap(d=>tP(d,e,n)).map(({geom:d,color:m})=>({geom:A.translate(u,d),color:m??e}))}if(c===Bl){const u=Array.isArray(l?.rotation)?[KG(l.rotation[0]),KG(l.rotation[1]),KG(l.rotation[2])]:[KG(l?.x??0),KG(l?.y??0),KG(l?.z??0)];return(g??[]).flatMap(d=>tP(d,e,n)).map(({geom:d,color:m})=>({geom:A.rotateZ(u[2],A.rotateY(u[1],A.rotateX(u[0],d))),color:m}))}if(c===Wp||c===Vh||c===cl){const u=(g??[]).flatMap(d=>tP(d,e,n)).map(d=>d.geom);if(u.length===0)return[];let h;return c===Wp?h=i.union(u):c===Vh?h=i.subtract(u[0],u.slice(1)):h=r.hull(u),[{geom:h,color:e}]}if(c===DG){const u=l?.points??[];return[{geom:s.geom2.fromPoints(u),color:e??l?.color}]}if(c===NG){const u=(g??[]).flatMap(p=>tP(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===ln||c===ktn||c===Fa||c===MG||c===Yf||c===k1){let u;if(c===ln){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===ktn){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===Fa){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===MG){const h=l?.radius??1,d=l?.center??[0,0,0];u=o.sphere({radius:h,center:d})}else if(c===k1){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 tP(u,e,n)}return(g??[]).flatMap(u=>tP(u,e,n))}function Hmi(t,e){return{geometries:tP(t,void 0,{jscad:e})}}function hnn(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 tg;if(r.setAttribute("position",new Ou(new Float32Array(e),3)),r.setIndex(n),o.length>0&&r.setAttribute("color",new Ou(new Float32Array(o),3)),t.transforms){const s=new ya;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 tg;if(o.setAttribute("position",new Ou(new Float32Array(e),3)),n.length>0&&o.setAttribute("color",new Ou(new Float32Array(n),3)),t.transforms){const i=new ya;i.fromArray(t.transforms),o.applyMatrix4(i)}return o}return console.error("Invalid CSG object: neither polygons nor sides found"),new tg}function Omi(t,e){const n=mUe(kmi,{footprint:t});return Hmi(n,e)}var Gmi=ng(rhe()),mnn=te.createContext(null),Ymi=()=>{const t=te.useContext(mnn);if(!t)throw new Error("useHover must be used within a HoverProvider");return t},Umi=({children:t})=>{const{camera:e,renderer:n}=jI(),[o,i]=te.useState([]),r=te.useMemo(()=>new $Jo,[]),s=te.useMemo(()=>new Jo,[]),a=te.useRef(o);a.current=o;const A=te.useRef(null),c=te.useCallback(d=>{i(m=>[...m,d])},[]),l=te.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=te.useCallback(d=>{let m=d;for(;m;){const p=a.current.find(_=>_.object===m);if(p)return p;m=m.parent}},[]),u=te.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]);te.useEffect(()=>{const d=n.domElement;return d.addEventListener("mousemove",u),()=>{d.removeEventListener("mousemove",u)}},[n,u]);const h=te.useMemo(()=>({addHoverable:c,removeHoverable:l}),[c,l]);return K.jsx(mnn.Provider,{value:h,children:t})},Kmi=({children:t,object:e,onHover:n,onUnhover:o,isHovered:i})=>{const{addHoverable:r,removeHoverable:s}=Ymi();return te.useEffect(()=>e?(r({object:e,onHover:n,onUnhover:o}),()=>{s(e)}):void 0,[e,n,o,r,s]),K.jsx(K.Fragment,{children:t})},_X=Kmi,QQ=(t,{castShadow:e=!0,receiveShadow:n=!0}={})=>{t.traverse(o=>{o instanceof Dr&&(o.castShadow=e,o.receiveShadow=n)})},Vmi=({positionOffset:t,footprint:e,rotationOffset:n,onHover:o,onUnhover:i,isHovered:r,scale:s,isTranslucent:a=!1})=>{const{rootObject:A}=jI(),c=te.useMemo(()=>{if(!e)return null;const{geometries:l}=Omi(e,Gmi),g=new w0;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=hnn(m),_=new pu({vertexColors:!0,side:O_,transparent:a,opacity:a?.5:1,depthWrite:!a}),f=new Dr(p,_);f.renderOrder=a?2:1,QQ(f,{castShadow:!a,receiveShadow:!0}),g.add(f)}return g},[e,a]);return te.useEffect(()=>{if(!(!c||!A))return A.add(c),()=>{A.remove(c)}},[A,c]),te.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]),te.useEffect(()=>{c&&c.traverse(l=>{l instanceof Dr&&l.material instanceof pu&&(r?(l.material.emissive.setHex(255),l.material.emissiveIntensity=.2):l.material.emissiveIntensity=0)})},[r,c]),c?K.jsx(_X,{isHovered:r,onHover:o,onUnhover:i,object:c}):null},pnn=new WeakMap,zmi=()=>{const t=new Bd;return t.name="fallback-environment-map",t.mapping=hue,t},Jmi=t=>{if(!t)return null;const e=t,n=pnn.get(e);if(n)return n;let o;if(t instanceof zue){const i=new eNe(t);o=i.fromScene(xWo(),.04).texture,i.dispose()}else o=zmi();return pnn.set(e,o),o};function Wmi(t){const e=new pE;let n=!1;t.updateWorldMatrix(!0,!1);const o=t.parent?t.parent.matrixWorld.clone().invert():new ya;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 jmi(t){const e=Wmi(t);return e?e.getSize(new jt):new jt}function qmi(t,e,n="contain_within_bounds"){if(!e)return[1,1,1];const o=jmi(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 HUe=({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}=jI(),l=te.useMemo(()=>new w0,[]),g=te.useMemo(()=>new w0,[]),u=te.useMemo(()=>new w0,[]),h=te.useMemo(()=>new w0,[]);return te.useEffect(()=>(l.add(g),()=>{l.remove(g)}),[l,g]),te.useEffect(()=>(g.add(u),()=>{g.remove(u)}),[g,u]),te.useEffect(()=>(u.add(h),()=>{u.remove(h)}),[u,h]),te.useEffect(()=>{for(;h.children.length>0;){const d=h.children[0];if(!d)break;h.remove(d)}t&&h.add(t)},[h,t]),te.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]),te.useEffect(()=>{if(c)return c.add(l),()=>{c.remove(l)}},[c,l]),te.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=qmi(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}},_nn=1.25;function fnn({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}=jI(),[d,m]=te.useState(null),[p,_]=te.useState(null),{boardTransformGroup:f}=HUe({model:d,position:e,rotation:n,modelOffset:o,modelRotation:i,sourceCoordinateTransform:r,modelSize:s,modelFitMode:a,scale:g});if(te.useEffect(()=>{if(!t)return;const I=new BWo;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}}),QQ(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]),te.useEffect(()=>{if(!d||!h)return;const I=Jmi(h);if(!I)return;const C=[],y=x=>{x instanceof pu&&(C.push({material:x,envMap:x.envMap??null,envMapIntensity:x.envMapIntensity??1}),x.envMap=I,(typeof x.envMapIntensity!="number"||x.envMapIntensity<_nn)&&(x.envMapIntensity=_nn),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]),te.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 pu&&(l?(y.emissive.setHex(255),y.emissiveIntensity=.2):y.emissiveIntensity=0)})},[l,d]),p)throw p;return d?K.jsx(_X,{isHovered:l,onHover:A,onUnhover:c,object:f}):null}var Xmi=ng(zen()),$mi=ng(rhe()),Zmi=({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}=te.useMemo(()=>{const _=(0,Xmi.executeJscadOperations)($mi.default,t);if(!_||!_.polygons&&!_.sides)return{threeGeom:null,material:null};const f=hnn(_),I=new pu({vertexColors:!0,side:O_,transparent:u,opacity:u?.5:1,depthWrite:!u});return{threeGeom:f,material:I}},[t,u]),m=te.useMemo(()=>{if(!h)return null;const _=new Dr(h,d);return _.renderOrder=u?2:1,QQ(_,{castShadow:!u,receiveShadow:!0}),_},[h,d,u]),{boardTransformGroup:p}=HUe({model:m,position:e,rotation:n,modelOffset:o,modelRotation:i,sourceCoordinateTransform:r,modelSize:s,modelFitMode:a,scale:g});return te.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?K.jsx(_X,{isHovered:l,onHover:A,onUnhover:c,object:p}):null};function epi(t){return t.replace(/(DEF|USE)\s+([^\s]+)/g,(e,n,o)=>`${n} ${o.replace(/-/g,"_")}`)}async function tpi(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 cjo().parse(epi(n),t)}typeof window<"u"&&!window.TSCIRCUIT_OBJ_LOADER_CACHE&&(window.TSCIRCUIT_OBJ_LOADER_CACHE=new Map);function npi(t){const[e,n]=te.useState(null);return te.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 tpi(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(`
|
|
5483
|
-
`).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 opi({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=npi(t),d=te.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}}),QQ(h,{castShadow:!u,receiveShadow:!0}),h;const p=new Dr(new fE(.5,.5,.5),new pu({transparent:!0,color:"red",opacity:.25}));return QQ(p,{castShadow:!1,receiveShadow:!0}),p},[h,u]),{boardTransformGroup:m}=HUe({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 K.jsx(_X,{isHovered:l,onHover:A,onUnhover:c,object:m})}var ipi=new Yi(.82,.82,.82),Inn=t=>new pu({color:t?new Yi(t[0],t[1],t[2]):ipi});function rpi(t,e){const n=Inn(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(Inn(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 spi(t){const e=new w0;for(const n of t){const o=n.attributes.position?.array??[],i=n.index?.array??[];if(!o.length||!i.length)continue;const r=new tg;r.setAttribute("position",new Ds(o,3));const s=n.attributes.normal?.array??[];s.length?r.setAttribute("normal",new Ds(s,3)):r.computeVertexNormals(),r.setIndex(i),r.clearGroups();const a=rpi(r,n),A=new Dr(r,a.length>1?a:a[0]);A.name=n.name,e.add(A)}return e}var OUe,api="https://cdn.jsdelivr.net/npm/occt-import-js@0.0.23/dist";function Api(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 cpi(){if(!OUe){const t=await import("https://cdn.jsdelivr.net/npm/occt-import-js@0.0.23/+esm");OUe=Api(t)({locateFile:n=>`${api}/${n}`})}return OUe}async function lpi(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 cpi()).ReadStepFile(new Uint8Array(n),null);if(!i.success||!i.meshes.length)throw new Error("occt-import-js failed to convert STEP file");const r=spi(i.meshes),s=new FNe;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 Cnn="step-glb-cache:v2:";function gpi(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 upi(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 dpi(t){try{const e=localStorage.getItem(`${Cnn}${t}`);return e?upi(e):null}catch(e){return console.warn("Failed to read STEP GLB cache",e),null}}function ynn(t,e){try{const n=gpi(e);localStorage.setItem(`${Cnn}${t}`,n)}catch(n){console.warn("Failed to write STEP GLB cache",n)}}function hpi(){const t=globalThis;return t.stepUrlToGltfModelConversions||(t.stepUrlToGltfModelConversions={inProgress:new Map,completed:new Map}),t.stepUrlToGltfModelConversions}var mpi=({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]=te.useState(null);return te.useEffect(()=>{let m=!0,p=null,_=!0;const f=hpi(),I=dpi(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),ynn(t,C.arrayBuffer),()=>{m=!1,p&&_&&URL.revokeObjectURL(p)};let y=f.inProgress.get(t);return y||(y=lpi(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),ynn(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?K.jsx(fnn,{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 Ihe(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=GUe(r,e.axisMapping.x)),e.axisMapping.y&&(o=GUe(r,e.axisMapping.y)),e.axisMapping.z&&(i=GUe(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 GUe(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 YUe={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 ppi(t,e){if(e.coordinateTransform)return e.coordinateTransform;if(!e.usingGlbCoordinates){if(e.hasFootprinterModel)return YUe.FOOTPRINTER_MODEL_TRANSFORM;if(!e.usingObjFormat)return e.usingStepFormat?YUe.STEP_INVERTED:YUe.Z_UP_TO_Y_UP_USB_FIX}}function fX(t,e){return ppi(t,{usingGlbCoordinates:e==="gltf"||e==="glb"||e==="jscad",usingObjFormat:e==="obj"||e==="wrl",usingStepFormat:e==="step",hasFootprinterModel:e==="footprinter"})}function Che(t){if(!t)return;const e=Ihe({x:1,y:0,z:0},t),n=Ihe({x:0,y:1,z:0},t),o=Ihe({x:0,y:0,z:1},t);return new ya().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 v9(t){return t*Math.PI/180}function _pi(t){if(t==="z+")return[0,0,0];switch(t){case"x+":return[0,v9(-90),0];case"x-":return[0,v9(90),0];case"y+":return[v9(90),0,0];case"y-":return[v9(-90),0,0];case"z-":return[v9(180),0,0];default:return[0,0,0]}}function fpi(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 Ipi(t,e){return t.rotation?[v9(t.rotation.x),v9(t.rotation.y),v9(t.rotation.z)]:e==="bottom"?[Math.PI,0,0]:[0,0,0]}function Cpi(t,e){const n=new jt(t.x,t.y,t.z),o=new D1(e[0],e[1],e[2],"XYZ");return n.applyEuler(o),[n.x,n.y,n.z]}function ypi(t,e,n){if(!t.model_origin_position)return[0,0,0];const o=e?Ihe(t.model_origin_position,e):t.model_origin_position;return Cpi(o,n)}function xpi(t,e){const n=fpi(t,e.layer,e.pcbThickness),o=Ipi(t,e.layer),i=fX(t,e.modelType),r=_pi(t.model_board_normal_direction??"z+"),s=ypi(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 Epi=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",Bpi=t=>t==="step"?"glb":t,Spi=(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)},bpi=(t,e)=>{if(t)return e?e(t):t},Qpi=(...t)=>t,UUe=class extends ws.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}},vpi=({error:t,onError:e})=>(te.useEffect(()=>{e(t)},[t,e]),null),xnn=({cad_component:t,circuitJson:e,resolveStaticAsset:n})=>{const o=jen(e),[i,r]=te.useState(!1),{visibility:s}=pR(),[a,A]=te.useState(null),c=te.useCallback(Y=>{Y?.mousePosition?(r(!0),A(Y.mousePosition)):(r(!1),A(null))},[]),l=te.useCallback(()=>{r(!1),A(null)},[]),g=te.useMemo(()=>Cr(e).source_component.getUsing({source_component_id:t.source_component_id})?.name,[e,t.source_component_id]),u=te.useMemo(()=>e.filter(q=>q.type==="pcb_plated_hole"&&q.pcb_component_id===t.pcb_component_id).length>0,[e,t.pcb_component_id]),h=te.useCallback(Y=>bpi(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]=te.useState(0),[I,C]=te.useState(null);te.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=te.useMemo(()=>Spi(t,e),[t,e]),B=E?s.enclosure==="translucent":!!t.show_as_translucent_model,b=Epi(t),Q=Bpi(b),w=t.model_glb_url?"glb":"gltf",D=t.model_wrl_url?"wrl":t.model_stl_url?"stl":"obj",k=te.useMemo(()=>xpi(t,{layer:x,pcbThickness:o,modelType:Q}),[t,x,o,Q]),T=Qpi(...k.rotation),H=k.position,G=te.useMemo(()=>{const Y=[];return m&&Y.push(K.jsx(fnn,{gltfUrl:m,position:H,rotation:T,modelOffset:k.modelPosition,modelRotation:k.modelRotation,sourceCoordinateTransform:Che(fX(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(K.jsx(opi,{url:d,position:H,rotation:T,modelOffset:k.modelPosition,modelRotation:k.modelRotation,sourceCoordinateTransform:Che(fX(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(K.jsx(mpi,{stepUrl:p,position:H,rotation:T,modelOffset:k.modelPosition,modelRotation:k.modelRotation,sourceCoordinateTransform:Che(fX(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,T,p,d]);let U=null;if(G.length>0){if(_>=G.length){if(I)throw I;return null}U=K.jsx(UUe,{fallback:({error:Y})=>K.jsx(vpi,{error:Y,onError:q=>{C(q),f(ee=>Math.max(ee,_+1))}}),children:G[_]},`${t.cad_component_id}-fallback-${_}`)}else t.model_jscad?U=K.jsx(Zmi,{jscadPlan:t.model_jscad,positionOffset:H,rotationOffset:T,modelOffset:k.modelPosition,modelRotation:k.modelRotation,sourceCoordinateTransform:Che(fX(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&&(U=K.jsx(Vmi,{positionOffset:H,rotationOffset:T,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 K.jsxs(K.Fragment,{children:[U,i&&a?K.jsx(Xen,{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]})},Enn={version:"0.0.597"},Bnn="cadViewerLightingEnabled",Ppi=()=>typeof window>"u"?!0:window.localStorage.getItem(Bnn)!=="false",Snn=te.createContext(void 0),wpi=({children:t})=>{const[e,n]=te.useState(!1),[o,i]=te.useState(!1),[r,s]=te.useState(Ppi);te.useEffect(()=>{window.localStorage.setItem(Bnn,r?"true":"false")},[r]);const a=te.useMemo(()=>({darkBackgroundEnabled:e,setDarkBackgroundEnabled:n,gridEnabled:o,setGridEnabled:i,lightingEnabled:r,setLightingEnabled:s}),[e,o,r]);return K.jsx(Snn.Provider,{value:a,children:t})},KUe=()=>{const t=te.useContext(Snn);if(!t)throw new Error("useAppearance must be used within an AppearanceProvider");return t},bnn="cadViewerCameraStateSession",Qnn=(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(bnn,JSON.stringify(n))}catch(n){console.warn("Failed to save camera:",n)}},VUe=(t,e)=>{try{const n=sessionStorage.getItem(bnn);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}},vnn=te.createContext(void 0),Mpi=({children:t,defaultTarget:e,initialCameraPosition:n,initialCameraType:o})=>{const i=te.useRef(null),r=te.useRef(null),[s,a]=te.useState(null),[A,c]=te.useState(o??"perspective"),[l,g]=te.useState(n??null),[u,h]=te.useState(new D1(0,0,0)),d=te.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=te.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=te.useCallback(f=>{i.current=f},[]),_=te.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:Qnn,loadCameraFromSession:VUe}),[e,d,s,m,p,A,l,u]);return K.jsx(vnn.Provider,{value:_,children:t})},RM=()=>{const t=te.useContext(vnn);if(!t)throw new Error("useCameraController must be used within a CameraControllerProvider");return t},Dpi=t=>t<.5?4*t*t*t:1-Math.pow(-2*t+2,3)/2,Npi=()=>{const{controlsRef:t,mainCameraRef:e,defaultTarget:n,setController:o,getPresetConfig:i}=RM(),r=te.useRef(null),s=te.useRef(new M1),a=te.useRef(new jt),A=te.useRef(new jt),c=te.useRef(new M1),l=te.useRef(new M1),g=te.useRef(new Ig),u=te.useRef(new Ig),h=te.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 T=D.quaternion.clone(),H=k.clone().invert().multiply(b).normalize(),G=T.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=te.useCallback(m=>{if(m==="Custom")return;const p=i(m);p&&h(p)},[h,i]);return te.useEffect(()=>e.current?(o({animateTo:h,animateToPreset:d}),()=>{o(null)}):void 0,[h,d,e,o]),nX(()=>{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=Dpi(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 T=c.current;T.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(),T.slerp(H,Q),e.current.quaternion.copy(k).multiply(T).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},Rpi=()=>{const{controlsRef:t}=RM(),e=te.useRef(null),n=te.useRef(!1),o=te.useRef(null),i=te.useCallback(s=>{e.current=s,!n.current&&t.current&&VUe(s,t.current)&&(n.current=!0)},[t]),r=te.useCallback(()=>{if(!(!e.current||!t.current)){if(!n.current&&VUe(e.current,t.current)){n.current=!0;return}clearTimeout(o.current),o.current=setTimeout(()=>{e.current&&t.current&&Qnn(e.current,t.current)},150)}},[t]);return{handleCameraCreated:i,handleControlsChange:r}};function Tpi(t){t.querySelectorAll("canvas").forEach(e=>e.remove())}var kpi=t=>{t.outputColorSpace=mE,t.toneMapping=ZHt,t.toneMappingExposure=1,t.shadowMap.enabled=!0,t.shadowMap.type=jHt},Fpi=te.forwardRef(({children:t,scene:e,camera:n,style:o,onCreated:i},r)=>{const{cameraType:s}=RM(),a=te.useRef(null),[A,c]=te.useState(null),l=te.useRef([]),g=te.useRef(void 0);g.current=i;const u=te.useRef(null),h=te.useCallback(_=>{l.current.push(_)},[]),d=te.useCallback(_=>{l.current=l.current.filter(f=>f!==_)},[]),m=te.useMemo(()=>new $N,[]);e?.up&&m.up.set(e.up.x,e.up.y,e.up.z);const p=te.useRef(new Ig);return te.useImperativeHandle(r,()=>p.current),te.useEffect(()=>{if(!a.current)return;Tpi(a.current);const _=new zue({antialias:!0,alpha:!0});kpi(_),_.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 Y_(75,f,.1,1e3):new nG(-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 YJo,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 Y_?I.aspect=B:I instanceof nG&&(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]),K.jsx("div",{ref:a,style:{width:"100%",height:"100%",...o},children:A&&K.jsx(qen.Provider,{value:A,children:K.jsx(Umi,{children:t})})})}),Lpi=`
|
|
5483
|
+
`).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 opi({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=npi(t),d=te.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}}),QQ(h,{castShadow:!u,receiveShadow:!0}),h;const p=new Dr(new fE(.5,.5,.5),new pu({transparent:!0,color:"red",opacity:.25}));return QQ(p,{castShadow:!1,receiveShadow:!0}),p},[h,u]),{boardTransformGroup:m}=HUe({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 K.jsx(_X,{isHovered:l,onHover:A,onUnhover:c,object:m})}var ipi=new Yi(.82,.82,.82),Inn=t=>new pu({color:t?new Yi(t[0],t[1],t[2]):ipi});function rpi(t,e){const n=Inn(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(Inn(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 spi(t){const e=new w0;for(const n of t){const o=n.attributes.position?.array??[],i=n.index?.array??[];if(!o.length||!i.length)continue;const r=new tg;r.setAttribute("position",new Ds(o,3));const s=n.attributes.normal?.array??[];s.length?r.setAttribute("normal",new Ds(s,3)):r.computeVertexNormals(),r.setIndex(i),r.clearGroups();const a=rpi(r,n),A=new Dr(r,a.length>1?a:a[0]);A.name=n.name,e.add(A)}return e}var OUe,api="https://cdn.jsdelivr.net/npm/occt-import-js@0.0.23/dist";function Api(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 cpi(){if(!OUe){const t=await import("https://cdn.jsdelivr.net/npm/occt-import-js@0.0.23/+esm");OUe=Api(t)({locateFile:n=>`${api}/${n}`})}return OUe}async function lpi(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 cpi()).ReadStepFile(new Uint8Array(n),null);if(!i.success||!i.meshes.length)throw new Error("occt-import-js failed to convert STEP file");const r=spi(i.meshes),s=new FNe;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 Cnn="step-glb-cache:v2:";function gpi(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 upi(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 dpi(t){try{const e=localStorage.getItem(`${Cnn}${t}`);return e?upi(e):null}catch(e){return console.warn("Failed to read STEP GLB cache",e),null}}function ynn(t,e){try{const n=gpi(e);localStorage.setItem(`${Cnn}${t}`,n)}catch(n){console.warn("Failed to write STEP GLB cache",n)}}function hpi(){const t=globalThis;return t.stepUrlToGltfModelConversions||(t.stepUrlToGltfModelConversions={inProgress:new Map,completed:new Map}),t.stepUrlToGltfModelConversions}var mpi=({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]=te.useState(null);return te.useEffect(()=>{let m=!0,p=null,_=!0;const f=hpi(),I=dpi(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),ynn(t,C.arrayBuffer),()=>{m=!1,p&&_&&URL.revokeObjectURL(p)};let y=f.inProgress.get(t);return y||(y=lpi(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),ynn(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?K.jsx(fnn,{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 Ihe(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=GUe(r,e.axisMapping.x)),e.axisMapping.y&&(o=GUe(r,e.axisMapping.y)),e.axisMapping.z&&(i=GUe(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 GUe(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 YUe={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 ppi(t,e){if(e.coordinateTransform)return e.coordinateTransform;if(!e.usingGlbCoordinates){if(e.hasFootprinterModel)return YUe.FOOTPRINTER_MODEL_TRANSFORM;if(!e.usingObjFormat)return e.usingStepFormat?YUe.STEP_INVERTED:YUe.Z_UP_TO_Y_UP_USB_FIX}}function fX(t,e){return ppi(t,{usingGlbCoordinates:e==="gltf"||e==="glb"||e==="jscad",usingObjFormat:e==="obj"||e==="wrl",usingStepFormat:e==="step",hasFootprinterModel:e==="footprinter"})}function Che(t){if(!t)return;const e=Ihe({x:1,y:0,z:0},t),n=Ihe({x:0,y:1,z:0},t),o=Ihe({x:0,y:0,z:1},t);return new ya().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 v9(t){return t*Math.PI/180}function _pi(t){if(t==="z+")return[0,0,0];switch(t){case"x+":return[0,v9(-90),0];case"x-":return[0,v9(90),0];case"y+":return[v9(90),0,0];case"y-":return[v9(-90),0,0];case"z-":return[v9(180),0,0];default:return[0,0,0]}}function fpi(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 Ipi(t,e){return t.rotation?[v9(t.rotation.x),v9(t.rotation.y),v9(t.rotation.z)]:e==="bottom"?[Math.PI,0,0]:[0,0,0]}function Cpi(t,e){const n=new jt(t.x,t.y,t.z),o=new D1(e[0],e[1],e[2],"XYZ");return n.applyEuler(o),[n.x,n.y,n.z]}function ypi(t,e,n){if(!t.model_origin_position)return[0,0,0];const o=e?Ihe(t.model_origin_position,e):t.model_origin_position;return Cpi(o,n)}function xpi(t,e){const n=fpi(t,e.layer,e.pcbThickness),o=Ipi(t,e.layer),i=fX(t,e.modelType),r=_pi(t.model_board_normal_direction??"z+"),s=ypi(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 Epi=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",Bpi=t=>t==="step"?"glb":t,Spi=(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)},bpi=(t,e)=>{if(t)return e?e(t):t},Qpi=(...t)=>t,UUe=class extends ws.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}},vpi=({error:t,onError:e})=>(te.useEffect(()=>{e(t)},[t,e]),null),xnn=({cad_component:t,circuitJson:e,resolveStaticAsset:n})=>{const o=jen(e),[i,r]=te.useState(!1),{visibility:s}=pR(),[a,A]=te.useState(null),c=te.useCallback(Y=>{Y?.mousePosition?(r(!0),A(Y.mousePosition)):(r(!1),A(null))},[]),l=te.useCallback(()=>{r(!1),A(null)},[]),g=te.useMemo(()=>Cr(e).source_component.getUsing({source_component_id:t.source_component_id})?.name,[e,t.source_component_id]),u=te.useMemo(()=>e.filter(q=>q.type==="pcb_plated_hole"&&q.pcb_component_id===t.pcb_component_id).length>0,[e,t.pcb_component_id]),h=te.useCallback(Y=>bpi(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]=te.useState(0),[I,C]=te.useState(null);te.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=te.useMemo(()=>Spi(t,e),[t,e]),B=E?s.enclosure==="translucent":!!t.show_as_translucent_model,b=Epi(t),Q=Bpi(b),w=t.model_glb_url?"glb":"gltf",D=t.model_wrl_url?"wrl":t.model_stl_url?"stl":"obj",k=te.useMemo(()=>xpi(t,{layer:x,pcbThickness:o,modelType:Q}),[t,x,o,Q]),T=Qpi(...k.rotation),H=k.position,G=te.useMemo(()=>{const Y=[];return m&&Y.push(K.jsx(fnn,{gltfUrl:m,position:H,rotation:T,modelOffset:k.modelPosition,modelRotation:k.modelRotation,sourceCoordinateTransform:Che(fX(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(K.jsx(opi,{url:d,position:H,rotation:T,modelOffset:k.modelPosition,modelRotation:k.modelRotation,sourceCoordinateTransform:Che(fX(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(K.jsx(mpi,{stepUrl:p,position:H,rotation:T,modelOffset:k.modelPosition,modelRotation:k.modelRotation,sourceCoordinateTransform:Che(fX(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,T,p,d]);let U=null;if(G.length>0){if(_>=G.length){if(I)throw I;return null}U=K.jsx(UUe,{fallback:({error:Y})=>K.jsx(vpi,{error:Y,onError:q=>{C(q),f(ee=>Math.max(ee,_+1))}}),children:G[_]},`${t.cad_component_id}-fallback-${_}`)}else t.model_jscad?U=K.jsx(Zmi,{jscadPlan:t.model_jscad,positionOffset:H,rotationOffset:T,modelOffset:k.modelPosition,modelRotation:k.modelRotation,sourceCoordinateTransform:Che(fX(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&&(U=K.jsx(Vmi,{positionOffset:H,rotationOffset:T,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 K.jsxs(K.Fragment,{children:[U,i&&a?K.jsx(Xen,{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]})},Enn={version:"0.0.598"},Bnn="cadViewerLightingEnabled",Ppi=()=>typeof window>"u"?!0:window.localStorage.getItem(Bnn)!=="false",Snn=te.createContext(void 0),wpi=({children:t})=>{const[e,n]=te.useState(!1),[o,i]=te.useState(!1),[r,s]=te.useState(Ppi);te.useEffect(()=>{window.localStorage.setItem(Bnn,r?"true":"false")},[r]);const a=te.useMemo(()=>({darkBackgroundEnabled:e,setDarkBackgroundEnabled:n,gridEnabled:o,setGridEnabled:i,lightingEnabled:r,setLightingEnabled:s}),[e,o,r]);return K.jsx(Snn.Provider,{value:a,children:t})},KUe=()=>{const t=te.useContext(Snn);if(!t)throw new Error("useAppearance must be used within an AppearanceProvider");return t},bnn="cadViewerCameraStateSession",Qnn=(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(bnn,JSON.stringify(n))}catch(n){console.warn("Failed to save camera:",n)}},VUe=(t,e)=>{try{const n=sessionStorage.getItem(bnn);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}},vnn=te.createContext(void 0),Mpi=({children:t,defaultTarget:e,initialCameraPosition:n,initialCameraType:o})=>{const i=te.useRef(null),r=te.useRef(null),[s,a]=te.useState(null),[A,c]=te.useState(o??"perspective"),[l,g]=te.useState(n??null),[u,h]=te.useState(new D1(0,0,0)),d=te.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=te.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=te.useCallback(f=>{i.current=f},[]),_=te.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:Qnn,loadCameraFromSession:VUe}),[e,d,s,m,p,A,l,u]);return K.jsx(vnn.Provider,{value:_,children:t})},RM=()=>{const t=te.useContext(vnn);if(!t)throw new Error("useCameraController must be used within a CameraControllerProvider");return t},Dpi=t=>t<.5?4*t*t*t:1-Math.pow(-2*t+2,3)/2,Npi=()=>{const{controlsRef:t,mainCameraRef:e,defaultTarget:n,setController:o,getPresetConfig:i}=RM(),r=te.useRef(null),s=te.useRef(new M1),a=te.useRef(new jt),A=te.useRef(new jt),c=te.useRef(new M1),l=te.useRef(new M1),g=te.useRef(new Ig),u=te.useRef(new Ig),h=te.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 T=D.quaternion.clone(),H=k.clone().invert().multiply(b).normalize(),G=T.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=te.useCallback(m=>{if(m==="Custom")return;const p=i(m);p&&h(p)},[h,i]);return te.useEffect(()=>e.current?(o({animateTo:h,animateToPreset:d}),()=>{o(null)}):void 0,[h,d,e,o]),nX(()=>{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=Dpi(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 T=c.current;T.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(),T.slerp(H,Q),e.current.quaternion.copy(k).multiply(T).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},Rpi=()=>{const{controlsRef:t}=RM(),e=te.useRef(null),n=te.useRef(!1),o=te.useRef(null),i=te.useCallback(s=>{e.current=s,!n.current&&t.current&&VUe(s,t.current)&&(n.current=!0)},[t]),r=te.useCallback(()=>{if(!(!e.current||!t.current)){if(!n.current&&VUe(e.current,t.current)){n.current=!0;return}clearTimeout(o.current),o.current=setTimeout(()=>{e.current&&t.current&&Qnn(e.current,t.current)},150)}},[t]);return{handleCameraCreated:i,handleControlsChange:r}};function Tpi(t){t.querySelectorAll("canvas").forEach(e=>e.remove())}var kpi=t=>{t.outputColorSpace=mE,t.toneMapping=ZHt,t.toneMappingExposure=1,t.shadowMap.enabled=!0,t.shadowMap.type=jHt},Fpi=te.forwardRef(({children:t,scene:e,camera:n,style:o,onCreated:i},r)=>{const{cameraType:s}=RM(),a=te.useRef(null),[A,c]=te.useState(null),l=te.useRef([]),g=te.useRef(void 0);g.current=i;const u=te.useRef(null),h=te.useCallback(_=>{l.current.push(_)},[]),d=te.useCallback(_=>{l.current=l.current.filter(f=>f!==_)},[]),m=te.useMemo(()=>new $N,[]);e?.up&&m.up.set(e.up.x,e.up.y,e.up.z);const p=te.useRef(new Ig);return te.useImperativeHandle(r,()=>p.current),te.useEffect(()=>{if(!a.current)return;Tpi(a.current);const _=new zue({antialias:!0,alpha:!0});kpi(_),_.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 Y_(75,f,.1,1e3):new nG(-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 YJo,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 Y_?I.aspect=B:I instanceof nG&&(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]),K.jsx("div",{ref:a,style:{width:"100%",height:"100%",...o},children:A&&K.jsx(qen.Provider,{value:A,children:K.jsx(Umi,{children:t})})})}),Lpi=`
|
|
5484
5484
|
varying vec3 worldPosition;
|
|
5485
5485
|
void main() {
|
|
5486
5486
|
worldPosition = (modelMatrix * vec4(position, 1.0)).xyz;
|
|
@@ -5514,7 +5514,7 @@ ${A.join(`
|
|
|
5514
5514
|
gl_FragColor = vec4(color, max(g1, g2) * a);
|
|
5515
5515
|
if (gl_FragColor.a <= 0.0) discard;
|
|
5516
5516
|
}
|
|
5517
|
-
`,Opi=({rotation:t,infiniteGrid:e,cellSize:n=1,sectionSize:o=10})=>{const{scene:i,camera:r}=jI(),s=1e3,a=te.useMemo(()=>{const A=new BQ(s,s);A.rotateX(-Math.PI/2);const c=new Kv({vertexShader:Lpi,fragmentShader:Hpi,uniforms:{cellSize:{value:n},sectionSize:{value:o},gridColor:{value:new Yi(15658734)},sectionColor:{value:new Yi(13421823)},fadeDistance:{value:100},fadeStrength:{value:1.5}},transparent:!0,side:O_}),l=new Dr(A,c);return t&&l.rotation.fromArray(t),l},[s,n,o,t]);return nX(()=>{e&&a.position.set(r.position.x,r.position.y,0)}),te.useEffect(()=>{if(!(!i||!a))return i.add(a),()=>{i.remove(a),a.geometry.dispose(),Array.isArray(a.material)?a.material.forEach(A=>A.dispose()):a.material.dispose()}},[i,a]),null},zUe=.75,Gpi=({boardDimensions:t,boardCenter:e,darkBackgroundEnabled:n=!1,shadowsEnabled:o=!1})=>{const{scene:i}=jI(),r=te.useMemo(()=>{const s=new w0;s.name="cad-viewer-light-rig";const a=e?.x??0,A=e?.y??0,c=Math.max(t?.width??0,t?.height??0,20),l=c*.8,g=c,u=c*1.7,h=new MYt(16186360,.22);h.name="cad-viewer-soft-ambient",s.add(h);const d=new TJo(15004141,1581597,.2);d.name="cad-viewer-hemisphere",s.add(d);const m=(p,_,f,I,C=!1)=>{const y=new wYt(_,f);if(y.name=p,y.position.set(a+I[0],A+I[1],I[2]),y.target.position.set(a,A,0),y.castShadow=C,C){y.shadow.mapSize.set(2048,2048),y.shadow.bias=-2e-4,y.shadow.normalBias=.03,y.shadow.radius=5;const x=y.shadow.camera;x.left=-l,x.right=l,x.top=l,x.bottom=-l,x.near=.5,x.far=Math.max(c*4,Math.hypot(...I)+c*2),x.updateProjectionMatrix()}s.add(y),s.add(y.target)};return m("cad-viewer-key-light",16775406,1.35,[u*.68,-u*.8,u*1.08],o),m("cad-viewer-fill-light",14477554,.25,[-g*.85,g*.55,g*.75]),m("cad-viewer-rim-light",12184275,.5,[-g*.35,g*.85,g*.95]),m("cad-viewer-underside-key-light",16775406,1.35*zUe,[u*.68,-u*.8,-u*1.08]),m("cad-viewer-underside-fill-light",14477554,.25*zUe,[-g*.85,g*.55,-g*.75]),m("cad-viewer-underside-rim-light",12184275,.5*zUe,[-g*.35,g*.85,-g*.95]),s},[e,t,o]);return te.useEffect(()=>{const s=i.background,a=i.environment;return i.background=n?new Yi(1053456):null,i.environment=null,()=>{i.background=s,i.environment=a}},[n,i]),te.useEffect(()=>{if(i)return i.add(r),()=>{i.remove(r)}},[i,r]),null},Ypi=({autoRotate:t,autoRotateSpeed:e,onStart:n,panSpeed:o,rotateSpeed:i,zoomSpeed:r,enableDamping:s,dampingFactor:a,target:A,onControlsChange:c})=>{const{camera:l,renderer:g}=jI(),u=te.useMemo(()=>!l||!g?null:new Cjo(l,g.domElement),[l,g]);return te.useEffect(()=>(c?.(u??null),()=>c?.(null)),[u,c]),te.useEffect(()=>{if(!u)return;const h=()=>{c?.(u)};return u.addEventListener("change",h),()=>{u.removeEventListener("change",h)}},[u,c]),te.useEffect(()=>{u&&(u.autoRotate=t||!1,u.autoRotateSpeed=e||1,o!==void 0&&(u.panSpeed=o),i!==void 0&&(u.rotateSpeed=i),r!==void 0&&(u.zoomSpeed=r),s!==void 0&&(u.enableDamping=s),a!==void 0&&(u.dampingFactor=a),u.zoomToCursor=!0,u.mouseButtons={LEFT:o9.ROTATE,MIDDLE:o9.PAN,RIGHT:null},A&&(u.target.set(A[0],A[1],A[2]),u.update()))},[u,t,e,o,i,r,s,a,A]),te.useEffect(()=>{if(!(!u||!n))return u.addEventListener("start",n),()=>{u.removeEventListener("start",n)}},[u,n]),te.useEffect(()=>{if(u)return()=>{u.dispose()}},[u]),nX(()=>{u?.update()},[u]),null},Upi=10,VG={banana:{type:"banana",label:"Show Banana",width:190,height:60,depth:34,zCenter:17},"credit-card":{type:"credit-card",label:"Show Credit Card",width:85.6,height:53.98,depth:.76,zCenter:0},"14in-macbook":{type:"14in-macbook",label:"Show 14in Macbook",width:312.6,height:221.2,depth:15.5,zCenter:0}},Kpi=Object.values(VG),Vpi=[{type:null,label:"None"},...Kpi],zpi=(t,e)=>t===e?null:e,JUe=t=>Number.isFinite(t)?Math.max(t??0,0):0,yhe=t=>Number.isFinite(t)?t??0:0,Pnn=(t,e,n)=>{const o=VG[t],i=JUe(e?.width),r=yhe(n?.x),s=yhe(n?.y);return{x:r+i/2+Upi+o.width/2,y:s,z:0}},Jpi=(t,e,n)=>{const o=VG[t],i=JUe(e?.width),r=JUe(e?.height),s=yhe(n?.x),a=yhe(n?.y),A=Pnn(t,e,n);return{minX:Math.min(s-i/2,A.x-o.width/2),maxX:Math.max(s+i/2,A.x+o.width/2),minY:Math.min(a-r/2,A.y-o.height/2),maxY:Math.max(a+r/2,A.y+o.height/2),minZ:Math.min(0,A.z+o.zCenter-o.depth/2),maxZ:Math.max(0,A.z+o.zCenter+o.depth/2)}};function Wpi(t,e){const n=new M1().setFromEuler(new D1(t.x,t.y,t.z)),o=new jt(0,0,1);return o.applyQuaternion(n),o.multiplyScalar(e)}var jpi=()=>{const{mainCameraRef:t}=RM(),e=te.useRef(null);return te.useEffect(()=>{if(!e.current)return;const n=e.current,o=document.createElement("canvas");n.appendChild(o);const i=new zue({canvas:o,antialias:!0,alpha:!0});i.setSize(120,120),i.setPixelRatio(window.devicePixelRatio);const r=new $N,s=new Y_(75,1,.1,1e3);s.up.set(0,0,1);const a=new MYt(16777215,Math.PI/2);r.add(a);const A=new w0;A.rotation.fromArray([Math.PI/2,0,0]);const c=1,l=new Dr(new fE(c,c,c),new pu({color:"white"}));A.add(l);const g=new uq(new oJo(new fE(c,c,c)),new ZN({color:0,linewidth:2}));A.add(g),r.add(A);const u=.51,h=(x,E,B)=>{const b=new nRe;return b.text=x,b.position.fromArray(E),B&&b.rotation.fromArray(B),b.color="black",b.fontSize=.25,b.anchorX="center",b.anchorY="middle",b.depthOffset=0,b.font=null,b.sync(),b},d=h("Front",[0,0,u]),m=h("Back",[0,0,-u],[0,Math.PI,0]),p=h("Right",[u,0,0],[0,Math.PI/2,0]),_=h("Left",[-u,0,0],[0,-Math.PI/2,0]),f=h("Top",[0,u,0],[-Math.PI/2,0,0]),I=h("Bottom",[0,-u,0],[Math.PI/2,0,0]);A.add(d),A.add(m),A.add(p),A.add(_),A.add(f),A.add(I);let C=null;const y=()=>{if(t.current){const x=Wpi(t.current.rotation??new D1(0,0,0),2);x.equals(s.position)||(s.position.copy(x),s.lookAt(0,0,0))}i.render(r,s),C=requestAnimationFrame(y)};return y(),()=>{o.remove(),C!==null&&cancelAnimationFrame(C),d.dispose(),m.dispose(),p.dispose(),_.dispose(),f.dispose(),I.dispose(),l.geometry.dispose(),l.material.dispose(),g.geometry.dispose(),g.material.dispose(),r.clear(),i.dispose(),i.forceContextLoss()}},[t]),K.jsx("div",{ref:e,style:{position:"absolute",top:0,left:0,width:120,height:120,zIndex:oX.orientationCube}})},wnn=(t,e,n)=>{const o=t/2,i=e/2,r=Math.min(n,o,i),s=new mYt;return s.moveTo(-o+r,-i),s.lineTo(o-r,-i),s.quadraticCurveTo(o,-i,o,-i+r),s.lineTo(o,i-r),s.quadraticCurveTo(o,i,o-r,i),s.lineTo(-o+r,i),s.quadraticCurveTo(-o,i,-o,i-r),s.lineTo(-o,-i+r),s.quadraticCurveTo(-o,-i,-o+r,-i),s},WUe=(t,e,n,o)=>Mnn(wnn(t,e,o),n),Mnn=(t,e)=>{const n=new SNe(t,{depth:e,bevelEnabled:!1,curveSegments:24});return n.translate(0,0,-e/2),n.computeVertexNormals(),n},qpi=(t,e)=>{const n=VG[e];t.updateMatrixWorld(!0);const i=new pE().setFromObject(t).getSize(new jt);t.scale.set(n.width/i.x,n.height/i.y,n.depth/i.z),t.updateMatrixWorld(!0);const s=new pE().setFromObject(t).getCenter(new jt);t.position.set(-s.x,-s.y,n.zCenter-s.z),t.updateMatrixWorld(!0)},Xpi=()=>{const t=new cYt([new jt(-82,18,16),new jt(-67,7,15),new jt(-43,-9,14),new jt(-15,-18,14),new jt(16,-18,14),new jt(47,-8,14.5),new jt(72,8,16),new jt(84,19,17)]),e=84,n=30,o=t.computeFrenetFrames(e,!1),i=[],r=[],s=[],a=[],A=[],c=new Yi(16766023),l=new Yi(12038965);for(let u=0;u<=e;u++){const h=u/e,d=t.getPointAt(h),m=o.normals[u],p=o.binormals[u],f=3.4+12.4*Math.sin(Math.PI*h)**.48,I=Math.max(0,(h-.82)/.18)*.38,C=c.clone().lerp(l,I);for(let y=0;y<=n;y++){const x=y/n*Math.PI*2,E=Math.sin(x),B=Math.cos(x),b=1+Math.cos(x*5+.35)*.035,Q=new jt().addScaledVector(m,B).addScaledVector(p,E*.9).normalize(),w=d.clone().addScaledVector(m,B*f*b).addScaledVector(p,E*f*.9*b);i.push(w.x,w.y,w.z),r.push(Q.x,Q.y,Q.z),s.push(C.r,C.g,C.b),a.push(h,y/n)}}for(let u=1;u<=e;u++)for(let h=1;h<=n;h++){const d=n+1,m=d*(u-1)+(h-1),p=d*u+(h-1),_=d*u+h,f=d*(u-1)+h;A.push(m,f,p,p,f,_)}const g=new tg;return g.setIndex(A),g.setAttribute("position",new Ds(i,3)),g.setAttribute("normal",new Ds(r,3)),g.setAttribute("color",new Ds(s,3)),g.setAttribute("uv",new Ds(a,2)),g.computeBoundingBox(),g.computeBoundingSphere(),{geometry:g,curve:t}},$pi=()=>{const t=new w0,e=new w0,{geometry:n,curve:o}=Xpi(),i=new Dr(n,new pu({color:16777215,roughness:.72,metalness:0,vertexColors:!0}));i.name="banana-peel",e.add(i);const r=new Dr(new nR(3.4,20,12),new pu({color:6242844,roughness:.92}));r.position.copy(o.getPointAt(0)),r.scale.set(1.15,.78,.78),r.name="banana-blossom-tip",e.add(r);const s=11,a=o.getTangentAt(1).normalize(),A=new Dr(new aG(2.5,4.1,s,18),new pu({color:8483625,roughness:.82}));A.quaternion.setFromUnitVectors(new jt(0,1,0),a),A.position.copy(o.getPointAt(1)).addScaledVector(a,s/2),A.name="banana-stem",e.add(A);const c=new Dr(new nR(2.55,18,10),new pu({color:5981470,roughness:.9}));return c.position.copy(o.getPointAt(1)).addScaledVector(a,s),c.name="banana-stem-tip",e.add(c),qpi(e,"banana"),t.add(e),t},Zpi=(t,e,n,o,i)=>{const r=wnn(t,e,o),s=new CNe;return s.absarc(0,0,i,0,Math.PI*2,!0),r.holes.push(s),Mnn(r,n)},e_i=(t,e)=>{const i=new Dr(new aG(e-.15,e-.15,.25,48),new pu({color:10199202,roughness:.48,metalness:.28}));return i.rotation.x=Math.PI/2,i.position.z=t-.35-.25/2,i.name="macbook-lid-indent",i},t_i=()=>{const t=VG["credit-card"],e=new w0,n=new Dr(WUe(t.width,t.height,t.depth,3.18),new pu({color:2383272,roughness:.38,metalness:.08}));n.name="credit-card-body",e.add(n);const o=t.depth/2+.08,i=new Dr(WUe(12,9,.14,1.2),new pu({color:14003525,roughness:.3,metalness:.62}));i.position.set(-21,3,o),i.name="credit-card-chip",e.add(i);const r=new pu({color:15331061,roughness:.45,metalness:.05});for(let s=0;s<4;s++){const a=new Dr(new fE(s===3?8:12,.8,.1),r);a.position.set(-20+s*14,-14,o+.08),a.name="credit-card-detail",e.add(a)}return e},n_i=()=>{const t=VG["14in-macbook"],e=new w0,n=new pu({color:12896201,roughness:.3,metalness:.38}),o=new Dr(WUe(t.width,t.height,13.5,9),n);o.position.z=-1,o.name="macbook-body",e.add(o);const i=2,r=6.75,s=r+i/2,a=12,A=new Dr(Zpi(t.width-1.8,t.height-1.8,i,8.2,a),n.clone());A.position.z=r,A.name="macbook-lid",e.add(A);const c=new Dr(new fE(t.width-42,3.2,1.2),new pu({color:3158838,roughness:.55,metalness:.45}));c.position.set(0,t.height/2-2.4,6.15),c.name="macbook-hinge",e.add(c),e.add(e_i(s,a));const l=new Dr(new fE(54,1.2,.8),new pu({color:6712174,roughness:.45,metalness:.5}));return l.position.set(0,-221.2/2+.5,2.5),l.name="macbook-front-notch",e.add(l),e},o_i=t=>{const e=t==="banana"?$pi():t==="credit-card"?t_i():n_i();return e.name=`reference-object-${t}`,e.userData.isReferenceObject=!0,e.userData.referenceObjectType=t,QQ(e),e},i_i=t=>{const e=new Set,n=new Set;t.traverse(o=>{if(!(o instanceof Dr))return;e.add(o.geometry);const i=Array.isArray(o.material)?o.material:[o.material];for(const r of i)n.add(r)});for(const o of e)o.dispose();for(const o of n)o.dispose()},r_i=(t,e,n,o=1.18)=>{const i=Math.max(n.maxX-n.minX,0),r=Math.max(n.maxY-n.minY,0),s=Math.max(n.maxZ-n.minZ,0),a=new jt((n.minX+n.maxX)/2,(n.minY+n.maxY)/2,(n.minZ+n.maxZ)/2),A=Math.max(Math.hypot(i,r,s)/2,1),c=e?.target??new jt,l=new jt(0,-.75,.9).normalize();let g=Math.max(t.position.distanceTo(c),5);if(t instanceof Y_){const u=FO.degToRad(t.fov),h=2*Math.atan(Math.tan(u/2)*t.aspect),d=Math.min(u,h);g=A*o/Math.sin(d/2),t.far=Math.max(t.far,g+A*o*3),t.updateProjectionMatrix()}else if(t instanceof nG){const u=Math.abs(t.right-t.left)/2,h=Math.abs(t.top-t.bottom)/2;t.zoom=Math.min(u/(A*o),h/(A*o)),g=Math.max(g,A*o*2),t.updateProjectionMatrix()}return t.position.copy(a).addScaledVector(l,g),t.lookAt(a),t.updateMatrixWorld(),e&&(e.target.copy(a),e.update()),{center:a,radius:A,distance:g}},s_i=({type:t,boardDimensions:e,boardCenter:n})=>{const{scene:o}=jI(),i=te.useMemo(()=>{const r=o_i(t),s=Pnn(t,e,n);return r.position.set(s.x,s.y,s.z),r},[t,e,n]);return te.useEffect(()=>(o.add(i),()=>{o.remove(i),i_i(i)}),[o,i]),null},a_i=({bounds:t})=>{const{camera:e}=jI(),{controlsRef:n}=RM();return te.useEffect(()=>{r_i(e,n.current,t)},[t,e,n]),null},A_i=()=>{const{camera:t}=jI(),{setCameraRotation:e}=RM();return nX(()=>{t&&e(t.rotation)}),null},Dnn=te.forwardRef(({children:t,initialCameraPosition:e=[5,-5,5],autoRotateDisabled:n,clickToInteractEnabled:o=!1,boardDimensions:i,boardCenter:r,referenceObject:s,onUserInteraction:a,onCameraControllerReady:A},c)=>{const[l,g]=te.useState(!o),{mainCameraRef:u,handleControlsChange:h,controller:d}=RM(),{darkBackgroundEnabled:m,gridEnabled:p,lightingEnabled:_}=KUe(),{handleCameraCreated:f,handleControlsChange:I}=Rpi();te.useEffect(()=>{A&&A(d)},[d,A]);const C=te.useMemo(()=>{if(s)return Jpi(s,i,r)},[s,i,r]),y=te.useMemo(()=>{if(!i)return 10;const E=i.width??0,B=i.height??0;return Math.max(Math.max(E,B)*1.5,10)},[i]),x=te.useMemo(()=>{if(C)return[(C.minX+C.maxX)/2,(C.minY+C.maxY)/2,(C.minZ+C.maxZ)/2];if(r)return[r.x,r.y,0]},[r,C]);return K.jsxs("div",{style:{position:"relative",width:"100%",height:"100%"},children:[K.jsx(jpi,{}),K.jsxs(Fpi,{ref:c,scene:{up:new jt(0,0,1)},camera:{up:[0,0,1],position:e},onCreated:({camera:E})=>{u.current=E,f(E)},children:[K.jsx(Npi,{}),K.jsx(A_i,{}),l&&K.jsx(Ypi,{autoRotate:!n,autoRotateSpeed:1,onStart:a,rotateSpeed:.5,panSpeed:.75,zoomSpeed:.5,enableDamping:!0,dampingFactor:.1,target:x,onControlsChange:E=>{h(E),I()}}),K.jsx(Gpi,{boardDimensions:i,boardCenter:r,darkBackgroundEnabled:m,shadowsEnabled:_}),s&&K.jsx(s_i,{type:s,boardDimensions:i,boardCenter:r}),C&&K.jsx(a_i,{bounds:C}),p&&K.jsx(Opi,{rotation:[Math.PI/2,0,0],infiniteGrid:!0,cellSize:3,sectionSize:y}),t]}),K.jsxs("div",{style:{position:"absolute",right:24,bottom:24,fontFamily:"sans-serif",color:"white",WebkitTextStroke:"0.5px rgba(0, 0, 0, 0.5)",fontSize:11},children:["@",Enn.version]}),o&&!l&&K.jsx("button",{type:"button",onClick:()=>g(!0),onKeyDown:E=>{(E.key==="Enter"||E.key===" ")&&g(!0)},style:{position:"absolute",inset:0,cursor:"pointer",zIndex:oX.clickToInteractOverlay,display:"flex",alignItems:"center",justifyContent:"center"},children:K.jsx("div",{style:{backgroundColor:"rgba(0, 0, 0, 0.8)",color:"white",padding:"12px 24px",borderRadius:"8px",fontSize:"16px",fontFamily:"sans-serif",pointerEvents:"none"},children:"Click to Interact"})})]})}),Nnn=t=>te.useMemo(()=>{if(!t)return[];const e=new S7o;return e.add(t),e.render(),e.getCircuitJson()},[t]),c_i=t=>{const[e,n]=te.useState([]),[o,i]=te.useState(!0);return te.useEffect(()=>{if(!t)return;(async()=>{i(!0);const a=(Array.isArray(t)?t:[t]).map(async(A,c)=>{const l=fti.serialize({binary:!0},[A]),u=await new Blob(l).arrayBuffer(),d=A.layerType||(c===0?"board":void 0);return{stlData:u,color:A.color,layerType:d}});try{const A=await Promise.all(a);n(A)}catch(A){console.error("Error generating STLs:",A),n([])}finally{i(!1)}})()},[t]),{stls:e,loading:o}},l_i=ng(Xde()),g_i=ng(hR()),u_i=ng(tX()),d_i=ng(hR()),h_i=ng(mR()),m_i=ng(Uen()),Rnn=t=>{let e=0;for(let o=0;o<t.length;o++){const i=(o+1)%t.length;e+=t[o][0]*t[i][1],e-=t[i][0]*t[o][1]}return e/2<=0},jUe=(t,e=1.2,n={})=>{const{xyOutset:o=0}=n,{outline:i}=t;let r=i.map(A=>[A.x,A.y]);Rnn(r)&&(r=r.reverse());let s=(0,d_i.polygon)({points:r});o!==0&&(s=(0,m_i.expand)({delta:o,corners:"edge"},s));let a=(0,u_i.extrudeLinear)({height:e},s);return a=(0,h_i.translate)([0,0,-e/2],a),a},ms=.01,Yc={copper:[.78,.63,.39],fr4Tan:[.6,.43,.28],fr4SolderMaskGreen:[.06,.31,.19],fr4TracesWithMaskGreen:[.09,.38,.23],fr4TracesWithoutMaskTan:[.6,.43,.28],fr1Tan:[.8,.4,.2],fr1TracesWithMaskCopper:[.9,.6,.2],fr1SolderMaskGreen:[.02,.1,.04]},vQ=.001,W_=32,jS=150,xhe=.6,p_i={fr1:Yc.fr1Tan,fr4:Yc.fr4Tan},__i={fr1:Yc.fr1SolderMaskGreen,fr4:Yc.fr4SolderMaskGreen},f_i={red:"#650202",blue:"#003f7d",purple:"#4c1d69",black:"#071014",white:"#dddddd",yellow:"#dcc84a"},I_i=.875,C_i=/^#(?:[\da-f]{3}|[\da-f]{6})$/i,y_i=/^rgb\(\s*\d+\s*,\s*\d+\s*,\s*\d+\s*\)$/i,x_i=/^rgb\(\s*\d+%\s*,\s*\d+%\s*,\s*\d+%\s*\)$/i,E_i=/^hsl\(\s*\d*\.?\d+\s*,\s*\d*\.?\d+%\s*,\s*\d*\.?\d+%\s*\)$/i,B_i={blue:.96,purple:.96,black:.99,yellow:.92},Tnn=t=>{const e=t?.trim();if(!e)return null;const n=e.toLowerCase();if(n==="green"||n==="not_specified")return null;const i=f_i[n];return i?new Yi(i):Object.hasOwn(Yi.NAMES,n)||C_i.test(e)||y_i.test(e)||x_i.test(e)||E_i.test(e)?new Yi(n):null},S_i=t=>{const e=t?.trim().toLowerCase();return B_i[e]??I_i},b_i=({red:t,green:e,blue:n})=>Math.hypot(t-220,e-200,n-74)<4||Math.hypot(t-218,e-197,n-76)<4,Q_i=({soldermaskColor:t,copperColor:e,soldermaskOpacity:n})=>t.clone().multiplyScalar(n).add(e.clone().multiplyScalar(1-n)),knn=t=>{const e=t.clone().convertLinearToSRGB();return`rgb(${[Math.round(e.r*255),Math.round(e.g*255),Math.round(e.b*255)].join(",")})`},v_i=new Yi(1063462),qUe=({material:t,solder_mask_color:e})=>{const n=Tnn(e);if(n)return n;if(t==="fr4")return v_i.clone();const o=p_i[t]??Yc.fr4Tan;return new Yi(o[0],o[1],o[2])},P_i=t=>{const e=t.filter(A=>A.type==="pcb_panel"),n=Cr(t).pcb_board.list();let o,i,r=1.2;if(e.length>0)o=e[0],i=n.find(A=>A.pcb_panel_id===o.pcb_panel_id),r=i?.thickness??1.2;else{if(o=n.filter(c=>!c.pcb_panel_id)[0],!o)return console.warn("No pcb_board or pcb_panel found for simplified geometry"),[];i=o,r=o.thickness??1.2}let s;"outline"in o&&o.outline&&o.outline.length>0?s=jUe({outline:o.outline},r):s=(0,g_i.cuboid)({size:[o.width??10,o.height??10,r],center:[o.center.x,o.center.y,0]});const a=qUe({material:i?.material??"fr4",solder_mask_color:i?.solder_mask_color});return[(0,l_i.colorize)([a.r,a.g,a.b],s)]},IX=ng(Xde()),Uf=ng(eX()),XUe=ng(tX()),xE=ng(mR()),Gu=ng(hR()),P9=ng(hR()),w_i=ng(tX()),Ehe=ng(mR()),M_i=ng(eX()),D_i=64,N_i=(t,e,n)=>{const o=(0,P9.ellipse)({center:[0,0],radius:[Math.max(t/2,ms/2),Math.max(e/2,ms/2)],segments:D_i}),i=(0,w_i.extrudeLinear)({height:n},o);return(0,Ehe.translate)([0,0,-n/2],i)},R_i=(t,e,n)=>{const o=Math.max(t,ms),i=Math.max(e,ms);if(Math.abs(o-i)<1e-6)return(0,P9.cylinder)({center:[0,0,0],radius:o/2,height:n});const r=o>=i,s=r?o:i,a=r?i:o,A=Math.max(s-a,0),c=(0,P9.cuboid)({center:[0,0,0],size:r?[A,a,n]:[a,A,n]});if(A<=1e-6)return(0,P9.cylinder)({center:[0,0,0],radius:a/2,height:n});const l=A/2,g=(0,P9.cylinder)({center:r?[-l,0,0]:[0,-l,0],radius:a/2,height:n}),u=(0,P9.cylinder)({center:r?[l,0,0]:[0,l,0],radius:a/2,height:n});return(0,M_i.union)(c,g,u)},Bhe=(t,e,n={})=>{const o=t.hole_shape||"circle",i=n.sizeDelta??0,r=t.hole_offset_x||0,s=t.hole_offset_y||0,a=[t.x+r,t.y+s,0];if(o==="circle"){const h=Math.max((t.hole_diameter??0)+i,ms),d=Math.max(h/2,ms/2);return(0,P9.cylinder)({center:a,radius:d,height:e})}const A=t.hole_width??t.hole_diameter,c=t.hole_height??t.hole_diameter;if(!A||!c)return null;const l=Math.max(A+i,ms),g=Math.max(c+i,ms);if(o==="oval"){const h=N_i(l,g,e);return(0,Ehe.translate)([a[0],a[1],0],h)}if(o==="pill"||o==="rotated_pill"){let h=R_i(l,g,e);if(!h)return null;const d=t.ccw_rotation||0;return d&&(h=(0,Ehe.rotateZ)(d*Math.PI/180,h)),(0,Ehe.translate)(a,h)}const u=Math.max((t.hole_diameter??A??c??ms)+i,ms);return(0,P9.cylinder)({center:a,radius:u/2,height:e})},Uc=ng(hR()),nP=ng(Xde()),bd=ng(eX()),Fnn=ng(mR()),She=ng(tX()),EE=ng(mR()),T_i=1e-5;function Lnn(t,e,n){if(typeof n!="number"||!Number.isFinite(n)||n<=0)return 0;const o=t/2,i=e/2,r=Math.min(o,i)-2*T_i;return Math.max(0,Math.min(n,r))}function w9(t){if(!(!t||typeof t!="object"))return t.corner_radius??t.cornerRadius??t.rect_pad_border_radius??t.rectPadBorderRadius??t.rect_border_radius??t.rectBorderRadius??void 0}var k_i=.05,$Ue=64,CR=(t,e)=>e?(0,bd.intersect)(e,t):t,CX=(t,e,n={})=>{const{clipGeom:o}=n;t.shape||(t.shape="circle");const i=Math.max(e.pcbThickness*.002,ms/5),r=Math.max(e.pcbThickness*3e-4,ms/20),s=Math.max(e.pcbThickness*.0025,ms/4),a=e.pcbThickness+2*k_i+4*ms,A=Math.max(e.pcbThickness-2*(i+r+s),ms),c=Math.max(A,ms);if(t.shape==="circle"){const l=t.outer_diameter??Math.max(t.hole_diameter,0),g=A,u=(0,Uc.cylinder)({center:[t.x,t.y,0],radius:l/2,height:g}),h=CR(u,o),d=(0,Uc.cylinder)({center:[t.x,t.y,0],radius:Math.max(t.hole_diameter/2,.01),height:a});return(0,nP.colorize)(Yc.copper,(0,bd.subtract)(h,d))}if(t.shape==="oval"){const l=t.outer_width||t.hole_width||0,g=t.outer_height||t.hole_height||0,u=t.hole_width||0,h=t.hole_height||0,d=(()=>{const _=(0,Uc.cylinder)({center:[0,0,0],radius:1,height:A,segments:64}),f=(0,Fnn.scale)([l/2,g/2,1],_);return(0,EE.translate)([t.x,t.y,0],f)})(),m=CR(d,o),p=(()=>{const _=(0,Uc.cylinder)({center:[0,0,0],radius:1,height:a,segments:64}),f=(0,Fnn.scale)([Math.max(u/2,.01),Math.max(h/2,.01),1],_);return(0,EE.translate)([t.x,t.y,0],f)})();return(0,nP.colorize)(Yc.copper,(0,bd.subtract)(m,p))}if(t.shape==="circular_hole_with_rect_pad"){const l=t.hole_offset_x||0,g=t.hole_offset_y||0,u=t.rect_pad_width||t.hole_diameter,h=t.rect_pad_height||t.hole_diameter,d=w9(t),m=CR((0,bd.union)((()=>{const f=(0,Uc.roundedRectangle)({size:[u,h],roundRadius:d||0,segments:$Ue}),I=(0,She.extrudeLinear)({height:A},f);return(0,EE.translate)([t.x,t.y,-A/2],I)})(),(0,Uc.cylinder)({center:[t.x+(l||0),t.y+(g||0),0],radius:t.hole_diameter/2,height:c})),o),p=(0,Uc.cylinder)({center:[t.x+(l||0),t.y+(g||0),0],radius:Math.max(t.hole_diameter/2-ms,.01),height:a}),_=(0,bd.subtract)(m,p);return n.clipGeom?(0,nP.colorize)(Yc.copper,(0,bd.intersect)(_,n.clipGeom)):(0,nP.colorize)(Yc.copper,_)}if(t.shape==="pill"){const l=(t.ccw_rotation||0)*Math.PI/180,g=D=>{if(!l)return D;const k=(0,EE.translate)([-t.x,-t.y,0],D),T=(0,EE.rotate)([0,0,l],k);return(0,EE.translate)([t.x,t.y,0],T)},u=t.hole_height>t.hole_width,h=u?t.hole_height:t.hole_width,d=u?t.hole_width:t.hole_height,m=u?t.outer_height||d+.2:t.outer_width||h+.2,p=u?t.outer_width||h+.2:t.outer_height||d+.2,_=d/2,f=Math.abs(h-d),y=((D,k,T)=>{const H=k/2,G=Math.abs(D-k);if(G<=1e-6)return(0,Uc.cylinder)({center:[t.x,t.y,0],radius:H,height:T});const U=(0,Uc.cuboid)({center:[t.x,t.y,0],size:u?[k,G,T]:[G,k,T]}),Y=(0,Uc.cylinder)({center:u?[t.x,t.y-G/2,0]:[t.x-G/2,t.y,0],radius:H,height:T}),q=(0,Uc.cylinder)({center:u?[t.x,t.y+G/2,0]:[t.x+G/2,t.y,0],radius:H,height:T});return(0,bd.union)(U,Y,q)})(m,p,A),x=(0,Uc.cuboid)({center:[t.x,t.y,0],size:u?[d-2*ms,f,a]:[f,d-2*ms,a]}),E=(0,Uc.cylinder)({center:u?[t.x,t.y-f/2,0]:[t.x-f/2,t.y,0],radius:_-ms,height:a}),B=(0,Uc.cylinder)({center:u?[t.x,t.y+f/2,0]:[t.x+f/2,t.y,0],radius:_-ms,height:a}),b=(0,bd.union)(x,E,B),Q=CR(g(y),o),w=g(b);return(0,nP.colorize)(Yc.copper,(0,bd.subtract)(Q,w))}if(t.shape==="pill_hole_with_rect_pad"){if(t.hole_shape&&t.hole_shape!=="pill"||t.pad_shape&&t.pad_shape!=="rect")throw new Error("Invalid hole_shape or pad_shape for pill_hole_with_rect_pad");const l=t.hole_offset_x||0,g=t.hole_offset_y||0,u=t.hole_height>t.hole_width,h=u?t.hole_height:t.hole_width,d=u?t.hole_width:t.hole_height,m=d/2,p=Math.abs(h-d),_=t.rect_pad_width||h+.2,f=t.rect_pad_height||d+.2,I=w9(t),C=.03,y=(0,bd.union)((0,Uc.cuboid)({center:[t.x+l,t.y+g,0],size:u?[d+2*C,p+2*C,c]:[p+2*C,d+2*C,c]}),(0,Uc.cylinder)({center:u?[t.x+l,t.y+g-p/2,0]:[t.x+l-p/2,t.y+g,0],radius:m+C,height:c}),(0,Uc.cylinder)({center:u?[t.x+l,t.y+g+p/2,0]:[t.x+l+p/2,t.y+g,0],radius:m+C,height:c})),x=(0,bd.union)((0,Uc.cuboid)({center:[t.x+l,t.y+g,0],size:u?[d,p,a]:[p,d,a]}),(0,Uc.cylinder)({center:u?[t.x+l,t.y+g-p/2,0]:[t.x+l-p/2,t.y+g,0],radius:m,height:a}),(0,Uc.cylinder)({center:u?[t.x+l,t.y+g+p/2,0]:[t.x+l+p/2,t.y+g,0],radius:m,height:a})),E=(()=>{const D=(0,Uc.roundedRectangle)({size:[_,f],roundRadius:I||0,segments:$Ue}),k=(0,She.extrudeLinear)({height:A},D);return(0,EE.translate)([t.x,t.y,-A/2],k)})(),B=(0,bd.subtract)(E,x),b=(0,bd.union)((0,Uc.cuboid)({center:[t.x+l,t.y+g,0],size:u?[d-2*ms,p-2*ms,a]:[p-2*ms,d-2*ms,a]}),(0,Uc.cylinder)({center:u?[t.x+l,t.y+g-p/2,0]:[t.x+l-p/2,t.y+g,0],radius:m-ms,height:a}),(0,Uc.cylinder)({center:u?[t.x+l,t.y+g+p/2,0]:[t.x+l+p/2,t.y+g,0],radius:m-ms,height:a})),Q=(0,bd.subtract)(y,b),w=CR((0,bd.union)(B,Q),o);return(0,nP.colorize)(Yc.copper,w)}else if(t.shape==="rotated_pill_hole_with_rect_pad"){if(t.hole_shape&&t.hole_shape!=="rotated_pill"||t.pad_shape&&t.pad_shape!=="rect")throw new Error("Invalid hole_shape or pad_shape for rotated_pill_hole_with_rect_pad");const l=t.hole_offset_x||0,g=t.hole_offset_y||0,u=t.hole_width,h=t.hole_height,d=u>=h,m=d?u:h,p=d?h:u,_=p/2,f=Math.abs(m-p),I=t.rect_pad_width||u+.2,C=t.rect_pad_height||h+.2,y=w9(t),x=.03,E=(t.hole_ccw_rotation||0)*Math.PI/180,B=(t.rect_ccw_rotation||0)*Math.PI/180,b=Y=>{const q=l*Math.cos(E)-g*Math.sin(E),ee=l*Math.sin(E)+g*Math.cos(E),W=(0,EE.rotate)([0,0,E],Y);return(0,EE.translate)([t.x+q,t.y+ee,0],W)},Q=Y=>{if(!B)return Y;const q=(0,EE.translate)([-t.x,-t.y,0],Y),ee=(0,EE.rotate)([0,0,B],q);return(0,EE.translate)([t.x,t.y,0],ee)},w=b((0,bd.union)((0,Uc.cuboid)({center:[0,0,0],size:d?[f+2*x,p+2*x,c]:[p+2*x,f+2*x,c]}),(0,Uc.cylinder)({center:d?[-f/2,0,0]:[0,-f/2,0],radius:_+x,height:c}),(0,Uc.cylinder)({center:d?[f/2,0,0]:[0,f/2,0],radius:_+x,height:c}))),D=b((0,bd.union)((0,Uc.cuboid)({center:[0,0,0],size:d?[f,p,a]:[p,f,a]}),(0,Uc.cylinder)({center:d?[-f/2,0,0]:[0,-f/2,0],radius:_,height:a}),(0,Uc.cylinder)({center:d?[f/2,0,0]:[0,f/2,0],radius:_,height:a}))),k=Q((()=>{const Y=(0,Uc.roundedRectangle)({size:[I,C],roundRadius:y||0,segments:$Ue}),q=(0,She.extrudeLinear)({height:A},Y);return(0,EE.translate)([t.x,t.y,-A/2],q)})()),T=(0,bd.subtract)(k,D),H=b((0,bd.union)((0,Uc.cuboid)({center:[0,0,0],size:d?[f-2*ms,p-2*ms,a]:[p-2*ms,f-2*ms,a]}),(0,Uc.cylinder)({center:d?[-f/2,0,0]:[0,-f/2,0],radius:_-ms,height:a}),(0,Uc.cylinder)({center:d?[f/2,0,0]:[0,f/2,0],radius:_-ms,height:a}))),G=(0,bd.subtract)(w,H),U=CR((0,bd.union)(T,G),o);return(0,nP.colorize)(Yc.copper,U)}else if(t.shape==="hole_with_polygon_pad"){const l=t.pad_outline;if(!Array.isArray(l)||l.length<3)throw new Error(`Invalid pad_outline for plated hole at (${t.x}, ${t.y})`);const g=l.map(C=>[C.x,C.y]),u=(0,Uc.polygon)({points:g}),m=((C,y)=>{const x=Math.max(C,ms),E=(0,She.extrudeLinear)({height:x},u);return(0,EE.translate)([t.x,t.y,y-x/2],E)})(A,0),p=CR(m,o),_=Bhe(t,c);if(!_)return(0,nP.colorize)(Yc.copper,p);const f=Bhe(t,a,{sizeDelta:-2*ms})||_;let I=(0,bd.union)((0,bd.subtract)(p,_),_);return n.clipGeom?(I=(0,bd.subtract)(I,f),I=(0,bd.intersect)(I,n.clipGeom),(0,nP.colorize)(Yc.copper,I)):(0,nP.colorize)(Yc.copper,(0,bd.subtract)(I,f))}else throw new Error(`Unsupported plated hole shape: ${t.shape}`)},F_i=ng(eX()),L_i=ng(mR()),ZUe=ng(hR());function H_i({x:t,y:e,outerDiameter:n,holeDiameter:o,thickness:i}){if(n<=o)throw new Error(`Invalid via geometry: outerDiameter (${n}) must be > holeDiameter (${o})`);const r=ms,s=Math.min(n/2,o/2+r),A=(0,ZUe.cylinder)({center:[0,0,0],radius:s,height:i,segments:W_}),c=i+2*ms,l=(0,ZUe.cylinder)({center:[0,0,0],radius:o/2,height:c,segments:W_}),g=(0,F_i.subtract)(A,l);return(0,L_i.translate)([t,e,0],g)}function O_i({x:t,y:e,holeDiameter:n,thickness:o}){const i=o*1.5,r=n/2+ms;return(0,ZUe.cylinder)({center:[t,e,0],radius:r,height:i,segments:W_})}var G_i=64,Y_i=1,eKe=.05,Hnn=["initializing","processing_plated_holes","processing_holes","processing_cutouts","processing_vias","finalizing","done"],U_i=class{board;plated_holes;holes;pcb_vias;pcb_cutouts;boardGeom=null;platedHoleGeoms=[];viaGeoms=[];boardClipGeom=null;state="initializing";currentIndex=0;ctx;onCompleteCallback;finalGeoms=[];constructor(t,e){this.onCompleteCallback=e;const n=t.filter(i=>i.type==="pcb_panel"),o=Cr(t).pcb_board.list();if(n.length>0){const i=n[0],r=o.find(s=>s.pcb_panel_id===i.pcb_panel_id);this.board={type:"pcb_board",pcb_board_id:i.pcb_panel_id,center:i.center,width:i.width,height:i.height,thickness:r?.thickness??1.4,material:r?.material??"fr4",num_layers:r?.num_layers??2,solder_mask_color:r?.solder_mask_color}}else{const i=o.filter(r=>!r.pcb_panel_id);this.board=i[0]}this.plated_holes=Cr(t).pcb_plated_hole.list(),this.holes=Cr(t).pcb_hole.list(),this.pcb_vias=Cr(t).pcb_via.list(),this.pcb_cutouts=Cr(t).pcb_cutout.list(),this.ctx={pcbThickness:this.board.thickness??1.2},this.initializeBoard()}initializeBoard(){const t=this.ctx.pcbThickness+2*Y_i;this.board.outline&&this.board.outline.length>0?(this.boardGeom=jUe({outline:this.board.outline},this.ctx.pcbThickness),this.boardClipGeom=jUe({outline:this.board.outline},t,{xyOutset:eKe})):(this.boardGeom=(0,Gu.cuboid)({size:[this.board.width,this.board.height,this.ctx.pcbThickness],center:[this.board.center.x,this.board.center.y,0]}),this.boardClipGeom=(0,Gu.cuboid)({size:[this.board.width+2*eKe,this.board.height+2*eKe,t],center:[this.board.center.x,this.board.center.y,0]})),this.state="processing_plated_holes",this.currentIndex=0}goToNextState(){const t=Hnn.indexOf(this.state);t!==-1&&(this.state=Hnn[t+1],this.currentIndex=0)}step(t=1){if(this.state==="done"||!this.boardGeom)return!0;for(let e=0;e<t&&this.state!=="done";e++)switch(this.state){case"processing_plated_holes":this.currentIndex<this.plated_holes.length?(this.processPlatedHole(this.plated_holes[this.currentIndex]),this.currentIndex++):this.goToNextState();break;case"processing_holes":this.currentIndex<this.holes.length?(this.processHole(this.holes[this.currentIndex]),this.currentIndex++):this.goToNextState();break;case"processing_vias":this.currentIndex<this.pcb_vias.length?(this.processVia(this.pcb_vias[this.currentIndex]),this.currentIndex++):this.goToNextState();break;case"processing_cutouts":this.currentIndex<this.pcb_cutouts.length?(this.processCutout(this.pcb_cutouts[this.currentIndex]),this.currentIndex++):this.goToNextState();break;case"finalizing":this.finalize(),this.state="done";break}return this.state==="done"}processCutout(t){if(!this.boardGeom)return;let e=null;const n=this.ctx.pcbThickness*1.5;switch(t.shape){case"rect":{const o=Lnn(t.width,t.height,w9(t));if(o>0){const i=(0,Gu.roundedRectangle)({size:[t.width,t.height],roundRadius:o,segments:G_i});e=(0,XUe.extrudeLinear)({height:n},i),e=(0,xE.translate)([0,0,-n/2],e)}else e=(0,Gu.cuboid)({center:[0,0,0],size:[t.width,t.height,n]});if(t.rotation){const i=t.rotation*Math.PI/180;e=(0,xE.rotateZ)(i,e)}e=(0,xE.translate)([t.center.x,t.center.y,0],e);break}case"circle":e=(0,Gu.cylinder)({center:[t.center.x,t.center.y,0],radius:t.radius,height:n});break;case"polygon":{let o=t.points.map(r=>[r.x,r.y]);if(o.length<3){console.warn(`PCB Cutout [${t.pcb_cutout_id}] polygon has fewer than 3 points, skipping.`);break}Rnn(o)&&(o=o.reverse());const i=(0,Gu.polygon)({points:o});e=(0,XUe.extrudeLinear)({height:n},i),e=(0,xE.translate)([0,0,-n/2],e);break}}e&&(this.boardGeom=(0,Uf.subtract)(this.boardGeom,e))}processPlatedHole(t,e={}){if(this.boardGeom){if(t.shape==="circle"||t.shape==="circular_hole_with_rect_pad"){let n=null;if(t.shape==="circular_hole_with_rect_pad"){if(t.hole_shape&&t.hole_shape!=="circle"||t.pad_shape&&t.pad_shape!=="rect")return;n=(0,Gu.cylinder)({center:[t.x+(t.hole_offset_x||0),t.y+(t.hole_offset_y||0),0],radius:t.hole_diameter/2+ms,height:this.ctx.pcbThickness*1.5})}else n=(0,Gu.cylinder)({center:[t.x,t.y,0],radius:t.hole_diameter/2+ms,height:this.ctx.pcbThickness*1.5});e.dontCutBoard||(this.boardGeom=(0,Uf.subtract)(this.boardGeom,n));const o=CX(t,this.ctx,{clipGeom:this.boardClipGeom});this.platedHoleGeoms.push(o)}else if(t.shape==="pill"||t.shape==="oval"){const n=t.hole_height>t.hole_width,o=n?t.hole_height:t.hole_width,i=n?t.hole_width:t.hole_height,r=i/2,s=Math.abs(o-i);let a;if(a=(0,Uf.union)((0,Gu.cuboid)({center:[t.x,t.y,0],size:n?[i,s,this.ctx.pcbThickness*1.5]:[s,i,this.ctx.pcbThickness*1.5]}),(0,Gu.cylinder)({center:n?[t.x,t.y-s/2,0]:[t.x-s/2,t.y,0],radius:r,height:this.ctx.pcbThickness*1.5}),(0,Gu.cylinder)({center:n?[t.x,t.y+s/2,0]:[t.x+s/2,t.y,0],radius:r,height:this.ctx.pcbThickness*1.5})),t.ccw_rotation){const c=t.ccw_rotation*Math.PI/180;a=(0,xE.translate)([t.x,t.y,0],(0,xE.rotateZ)(c,(0,xE.translate)([-t.x,-t.y,0],a)))}e.dontCutBoard||(this.boardGeom=(0,Uf.subtract)(this.boardGeom,a));const A=CX(t,this.ctx,{clipGeom:this.boardClipGeom});this.platedHoleGeoms.push(A)}else if(t.shape==="pill_hole_with_rect_pad"){if(t.hole_shape&&t.hole_shape!=="pill"||t.pad_shape&&t.pad_shape!=="rect")return;const n=t.hole_height>t.hole_width,o=n?t.hole_height:t.hole_width,i=n?t.hole_width:t.hole_height,r=i/2,s=Math.abs(o-i);let a;a=(0,Uf.union)((0,Gu.cuboid)({center:[t.x+(t.hole_offset_x||0),t.y+(t.hole_offset_y||0),0],size:n?[i,s,this.ctx.pcbThickness*1.5]:[s,i,this.ctx.pcbThickness*1.5]}),(0,Gu.cylinder)({center:n?[t.x+(t.hole_offset_x||0),t.y+(t.hole_offset_y||0)-s/2,0]:[t.x+(t.hole_offset_x||0)-s/2,t.y+(t.hole_offset_y||0),0],radius:r,height:this.ctx.pcbThickness*1.5}),(0,Gu.cylinder)({center:n?[t.x+(t.hole_offset_x||0),t.y+(t.hole_offset_y||0)+s/2,0]:[t.x+(t.hole_offset_x||0)+s/2,t.y+(t.hole_offset_y||0),0],radius:r,height:this.ctx.pcbThickness*1.5})),e.dontCutBoard||(this.boardGeom=(0,Uf.subtract)(this.boardGeom,a));const A=CX(t,this.ctx,{clipGeom:this.boardClipGeom});this.platedHoleGeoms.push(A)}else if(t.shape==="rotated_pill_hole_with_rect_pad"){if(t.hole_shape&&t.hole_shape!=="rotated_pill"||t.pad_shape&&t.pad_shape!=="rect")return;const n=t.hole_width,o=t.hole_height,i=n>=o,r=i?n:o,s=i?o:n,a=s/2,A=Math.abs(r-s),c=t.hole_offset_x||0,l=t.hole_offset_y||0;let g=(0,Uf.union)((0,Gu.cuboid)({center:[0,0,0],size:i?[A,s,this.ctx.pcbThickness*1.5]:[s,A,this.ctx.pcbThickness*1.5]}),(0,Gu.cylinder)({center:i?[-A/2,0,0]:[0,-A/2,0],radius:a,height:this.ctx.pcbThickness*1.5}),(0,Gu.cylinder)({center:i?[A/2,0,0]:[0,A/2,0],radius:a,height:this.ctx.pcbThickness*1.5}));const u=(t.hole_ccw_rotation||0)*Math.PI/180,h=c*Math.cos(u)-l*Math.sin(u),d=c*Math.sin(u)+l*Math.cos(u);g=(0,xE.rotateZ)(u,g);const m=(0,xE.translate)([t.x+h,t.y+d,0],g);e.dontCutBoard||(this.boardGeom=(0,Uf.subtract)(this.boardGeom,m));const p=CX(t,this.ctx,{clipGeom:this.boardClipGeom});this.platedHoleGeoms.push(p)}else if(t.shape==="hole_with_polygon_pad"){const n=t.pad_outline;if(!Array.isArray(n)||n.length<3)return;const o=this.ctx.pcbThickness*1.5,i=Bhe(t,o,{sizeDelta:2*ms}),r=Bhe(t,o,{sizeDelta:-2*ms});if(!i||!r)return;e.dontCutBoard||(this.boardGeom=(0,Uf.subtract)(this.boardGeom,i)),this.platedHoleGeoms=this.platedHoleGeoms.map(a=>(0,IX.colorize)(Yc.copper,(0,Uf.subtract)(a,r)));const s=CX(t,this.ctx,{clipGeom:this.boardClipGeom});this.platedHoleGeoms.push(s)}}}processHole(t){if(!this.boardGeom)return;const e=this.ctx.pcbThickness*1.5;if(t.hole_shape==="circle"){const n=(0,Gu.cylinder)({center:[t.x,t.y,0],radius:t.hole_diameter/2+ms,height:e});this.boardGeom=(0,Uf.subtract)(this.boardGeom,n);const o=(0,Gu.cylinder)({center:[t.x,t.y,0],radius:t.hole_diameter/2+ms/2,height:e});this.platedHoleGeoms=this.platedHoleGeoms.map(i=>(0,IX.colorize)(Yc.copper,(0,Uf.subtract)(i,o)))}else if(t.hole_shape==="pill"||t.hole_shape==="rotated_pill"||t.hole_shape==="rect"||t.hole_shape==="oval"){const n=t.hole_width??t.hole_diameter,o=t.hole_height??t.hole_diameter,i=t.ccw_rotation??t.rotation??0,r=.02,s=(c,l,g,u)=>{if(c<=0||l<=0)return null;if(t.hole_shape==="rect")return(0,Gu.cuboid)({center:[0,0,0],size:[c,l,g]});if(u)return(0,xE.translate)([0,0,-g/2],(0,XUe.extrudeLinear)({height:g},(0,Gu.ellipse)({radius:[c/2,l/2]})));const h=Math.min(c,l)/2,d=Math.abs(c-l);return c>l?(0,Uf.union)((0,Gu.cuboid)({center:[0,0,0],size:[d,l,g]}),(0,Gu.cylinder)({center:[-d/2,0,0],radius:h,height:g}),(0,Gu.cylinder)({center:[d/2,0,0],radius:h,height:g})):(0,Uf.union)((0,Gu.cuboid)({center:[0,0,0],size:[c,d,g]}),(0,Gu.cylinder)({center:[0,-d/2,0],radius:h,height:g}),(0,Gu.cylinder)({center:[0,d/2,0],radius:h,height:g}))};let a=s(n,o,e,t.hole_shape==="oval"),A=s(n-2*r,o-2*r,e,t.hole_shape==="oval");if(a&&i!==0&&(a=(0,xE.rotateZ)(i*Math.PI/180,a)),A&&i!==0&&(A=(0,xE.rotateZ)(i*Math.PI/180,A)),a){const c=(0,xE.translate)([t.x,t.y,0],a);this.boardGeom=(0,Uf.subtract)(this.boardGeom,c)}if(A){const c=(0,xE.translate)([t.x,t.y,0],A);this.platedHoleGeoms=this.platedHoleGeoms.map(l=>(0,IX.colorize)(Yc.copper,(0,Uf.subtract)(l,c)))}}}processVia(t){if(this.boardGeom){if(typeof t.outer_diameter=="number"&&typeof t.hole_diameter=="number"){const e=H_i({x:t.x,y:t.y,outerDiameter:t.outer_diameter,holeDiameter:t.hole_diameter,thickness:this.ctx.pcbThickness});let n=e;this.boardClipGeom&&(n=(0,Uf.intersect)(this.boardClipGeom,e),n=(0,IX.colorize)(Yc.copper,n)),this.viaGeoms.push(n)}if(typeof t.hole_diameter=="number"){const e=O_i({x:t.x,y:t.y,holeDiameter:t.hole_diameter,thickness:this.ctx.pcbThickness});this.boardGeom=(0,Uf.subtract)(this.boardGeom,e)}}}finalize(){if(!this.boardGeom)return;const t=qUe(this.board);this.boardGeom=(0,IX.colorize)([t.r,t.g,t.b],this.boardGeom),this.finalGeoms=[this.boardGeom,...this.platedHoleGeoms,...this.viaGeoms],this.onCompleteCallback&&this.onCompleteCallback(this.finalGeoms)}getGeoms(){return this.finalGeoms}},K_i=t=>{const[e,n]=te.useState(null),o=te.useRef(!1);return te.useEffect(()=>{let i=!1;if(!t){n(null);return}if(!t.some(c=>c.type==="pcb_board"||c.type==="pcb_panel")){n(null);return}const s=P_i(t);n(s);const a=new U_i(t,c=>{});return(async()=>{if(!o.current){o.current=!0;try{let c=!1;for(;!c&&!i;)c=a.step(1),c||await new Promise(l=>setTimeout(l,0));i||n(a.getGeoms())}catch(c){console.error("Error during board geometry building:",c)}finally{o.current=!1}}})(),()=>{i=!0}},[t]),e},V_i=({children:t,parent:e,position:n,rotation:o,scale:i,color:r,fontSize:s,anchorX:a,anchorY:A,depthOffset:c})=>{const{rootObject:l}=jI(),g=te.useMemo(()=>{const u=new nRe;return u.text=t,n&&u.position.fromArray(n),o&&u.rotation.fromArray(o),i&&u.scale.fromArray(i),u.color=r||"white",u.fontSize=s||1,u.anchorX=a||"center",u.anchorY=A||"middle",u.depthOffset=c||0,u.font=null,u.sync(),u},[t,n,o,i,r,s,a,A,c]);return te.useEffect(()=>{const u=e||l;if(!(!u||!g))return u.add(g),()=>{u.remove(g),g.dispose()}},[l,e,g]),null},Onn=({error:t,cad_component:e})=>{const{rootObject:n}=jI(),[o,i]=te.useState(!1),[r,s]=te.useState(null),a=te.useCallback(g=>{g?.mousePosition?(i(!0),s(g.mousePosition)):(i(!1),s(null))},[]),A=te.useCallback(()=>{i(!1),s(null)},[]),c=te.useMemo(()=>e?.position?[e.position.x,e.position.y,e.position.z].map(u=>Number.isNaN(u)?0:u):[0,0,0],[e]),l=te.useMemo(()=>{const g=new w0;return g.position.fromArray(c),g},[c]);return te.useEffect(()=>{if(n)return n.add(l),()=>{n.remove(l)}},[n,l]),K.jsxs(K.Fragment,{children:[K.jsxs(_X,{isHovered:o,onHover:a,onUnhover:A,object:l,children:[K.jsx(z_i,{parent:l}),K.jsx(V_i,{parent:l,scale:[.1,.1,.1],color:"red",anchorX:"center",anchorY:"middle",depthOffset:-99999,children:`${t.toString().slice(0,50)}...`})]}),o&&r?K.jsx(Xen,{position:r,style:{fontFamily:"sans-serif",transform:"translate3d(-1rem, 0rem, 0)",backgroundColor:"white",padding:"6px",borderRadius:"4px",color:"red",pointerEvents:"none",userSelect:"none",WebkitUserSelect:"none",MozUserSelect:"none",msUserSelect:"none"},children:t.toString()}):null]})},z_i=({parent:t})=>{const e=te.useMemo(()=>{const n=new Dr(new fE(.5,.5,.5),new pu({depthTest:!1,transparent:!0,color:"red",opacity:.5}));return n.renderOrder=999999,n.rotation.fromArray([Math.PI/4,Math.PI/4,0]),n},[]);return te.useEffect(()=>(t.add(e),()=>{t.remove(e)}),[t,e]),null},J_i=t=>{if(t.length===0)return null;let e=t[0].x,n=t[0].y,o=t[0].x,i=t[0].y;for(let r=1;r<t.length;r++){const s=t[r];s.x<e&&(e=s.x),s.y<n&&(n=s.y),s.x>o&&(o=s.x),s.y>i&&(i=s.y)}return{minX:e,minY:n,maxX:o,maxY:i}};function gy(t){if(t.outline&&t.outline.length>=3){const s=J_i(t.outline);return{...s,width:s.maxX-s.minX,height:s.maxY-s.minY,centerX:(s.minX+s.maxX)/2,centerY:(s.minY+s.maxY)/2}}const e=t.width??0,n=t.height??0,o=t.center?.x??0,i=t.center?.y??0;return{...{minX:o-e/2,maxX:o+e/2,minY:i-n/2,maxY:i+n/2},width:e,height:n,centerX:o,centerY:i}}function W_i({layer:t,circuitJson:e,boardData:n,copperColor:o,traceTextureResolution:i}){const s=Cr(e).pcb_smtpad.list().filter(y=>y.layer===t);if(s.length===0)return null;const a=Cr(e).pcb_hole.list(),A=Cr(e).pcb_plated_hole.list().filter(y=>!Array.isArray(y.layers)||y.layers.includes(t)),c=Cr(e).pcb_via.list().filter(y=>!Array.isArray(y.layers)||y.layers.includes(t)),l=Cr(e).pcb_cutout.list(),g=[...a,...A,...c],u=t==="top"?"top_copper":"bottom_copper",h=gy(n),d=document.createElement("canvas"),m=Math.floor(h.width*i),p=Math.floor(h.height*i);d.width=m,d.height=p;const _=d.getContext("2d");if(!_)return null;t==="bottom"&&(_.translate(0,p),_.scale(1,-1));const f="rgba(0,0,0,0)",I=new WS(_);I.configure({colorOverrides:{copper:{top:o,bottom:o,inner1:o,inner2:o,inner3:o,inner4:o,inner5:o,inner6:o,inner7:o,inner8:o},copperPour:{top:f,bottom:f},drill:f,boardOutline:f,substrate:f,keepout:{top:f,bottom:f},fabricationNote:f,courtyard:{top:f,bottom:f},silkscreen:{top:f,bottom:f},soldermask:{top:f,bottom:f},soldermaskWithCopperUnderneath:{top:f,bottom:f},soldermaskOverCopper:{top:f,bottom:f}}}),I.setCameraBounds({minX:h.minX,maxX:h.maxX,minY:h.minY,maxY:h.maxY}),I.drawElements([...s,...g,...l],{layers:[u],drawSoldermask:!1,drawSoldermaskTop:!1,drawSoldermaskBottom:!1});const C=new IE(d);return C.generateMipmaps=!0,C.minFilter=$m,C.magFilter=xl,C.anisotropy=16,C.needsUpdate=!0,C}var j_i=t=>{const e=t.filter(n=>n.type==="pcb_panel");return e.length===0?null:e.length===1?e[0].pcb_panel_id:null};function q_i({layer:t,circuitJson:e,panelData:n,outlineColor:o="black",traceTextureResolution:i}){const r=j_i(e);if(!r)return null;const a=Cr(e).pcb_board.list().filter(m=>m.pcb_panel_id===r||m.position_mode==="relative_to_panel_anchor"&&!m.pcb_panel_id);if(a.length===0)return null;const A=document.createElement("canvas"),c=Math.floor(n.width*i),l=Math.floor(n.height*i);A.width=c,A.height=l;const g=A.getContext("2d");if(!g)return null;t==="bottom"&&(g.translate(0,l),g.scale(1,-1)),g.strokeStyle=o,g.lineWidth=.05*i;const u=m=>(m-n.center.x+n.width/2)*i,h=m=>(-(m-n.center.y)+n.height/2)*i;a.forEach(m=>{if(m.outline&&m.outline.length>=2)g.beginPath(),m.outline.forEach((p,_)=>{const f=u(p.x),I=h(p.y);_===0?g.moveTo(f,I):g.lineTo(f,I)}),g.closePath(),g.stroke();else{const p=m.width,_=m.height,{x:f,y:I}=m.center,C=u(f-p/2),y=h(I+_/2);g.strokeRect(C,y,p*i,_*i)}});const d=new IE(A);return d.generateMipmaps=!0,d.minFilter=$m,d.magFilter=xl,d.anisotropy=16,d.needsUpdate=!0,d}function X_i(t){return t&&t.route_type==="wire"&&typeof t.layer=="string"&&typeof t.width=="number"}function $_i(t,e){const n=[];let o=[];const i=()=>{if(o.length<2){o=[];return}n.push({...t,pcb_trace_id:`${t.pcb_trace_id}_${e}_${n.length}`,route:o}),o=[]};for(const r of t.route){if(!X_i(r)){i();continue}if(r.layer!==e){i();continue}o.push(r)}return i(),n}function Z_i({layer:t,circuitJson:e,boardData:n,traceColor:o,traceTextureResolution:i}){const r=Cr(e).pcb_trace.list(),s=Cr(e).pcb_via.list(),a=Cr(e).pcb_plated_hole.list(),A=t==="top"?"top_copper":"bottom_copper",c=r.filter(C=>ZSe(C).includes(A)).flatMap(C=>$_i(C,t));if(c.length===0)return null;const l=a.filter(C=>C.layers.includes(t)),g=[...c,...s,...l],u=gy(n),h=document.createElement("canvas"),d=Math.floor(u.width*i),m=Math.floor(u.height*i);h.width=d,h.height=m;const p=h.getContext("2d");if(!p)return null;t==="bottom"&&(p.translate(0,m),p.scale(1,-1));const _="rgba(0,0,0,0)",f=new WS(p);f.configure({colorOverrides:{copper:{top:o,bottom:o,inner1:o,inner2:o,inner3:o,inner4:o,inner5:o,inner6:o,inner7:o,inner8:o},copperPour:{top:_,bottom:_},drill:_,boardOutline:_,substrate:_,keepout:{top:_,bottom:_},fabricationNote:_,courtyard:{top:_,bottom:_},silkscreen:{top:_,bottom:_},soldermask:{top:_,bottom:_},soldermaskWithCopperUnderneath:{top:_,bottom:_},soldermaskOverCopper:{top:_,bottom:_}}}),f.setCameraBounds({minX:u.minX,maxX:u.maxX,minY:u.minY,maxY:u.maxY}),f.drawElements(g,{layers:[A],clipContextElements:e,drawSoldermask:!1,drawSoldermaskTop:!1,drawSoldermaskBottom:!1});const I=new IE(h);return I.generateMipmaps=!0,I.minFilter=$m,I.magFilter=xl,I.anisotropy=16,I.needsUpdate=!0,I}var efi=t=>{const[e=0,n=0,o=0]=t;return`rgb(${Math.round(e*255)}, ${Math.round(n*255)}, ${Math.round(o*255)})`},tfi=8;function Gnn({layer:t,circuitJson:e,boardData:n,traceTextureResolution:o=jS,copperColor:i=efi(Yc.copper),onlyCoveredBySoldermask:r=!1}){const s=e.filter(b=>b.type==="pcb_copper_pour"),a=t==="top"?"top_copper":"bottom_copper",A=s.filter(b=>b.layer===t&&(!r||b.covered_with_solder_mask!==!1));if(A.length===0)return null;const c=e.filter(b=>b.type==="pcb_hole"),l=e.filter(b=>b.type!=="pcb_plated_hole"?!1:!Array.isArray(b.layers)||b.layers.includes(t)),g=e.filter(b=>b.type!=="pcb_via"?!1:!Array.isArray(b.layers)||b.layers.includes(t)),u=[...c,...l,...g],h=gy(n),d=document.createElement("canvas"),m=Math.floor(h.width*o),p=Math.floor(h.height*o);d.width=m,d.height=p;const _=d.getContext("2d");if(!_)return null;t==="bottom"&&(_.translate(0,p),_.scale(1,-1));const f="rgba(0,0,0,0)",I=i,C=i,y=(b,Q)=>{if(b.length===0)return;const w=[...b,...u],D=new WS(_);D.configure({colorOverrides:{copper:{top:Q,bottom:Q,inner1:Q,inner2:Q,inner3:Q,inner4:Q,inner5:Q,inner6:Q,inner7:Q,inner8:Q},copperPour:{top:f,bottom:f},drill:f,boardOutline:f,substrate:f,keepout:{top:f,bottom:f},fabricationNote:f,courtyard:{top:f,bottom:f},silkscreen:{top:f,bottom:f},soldermask:{top:f,bottom:f},soldermaskWithCopperUnderneath:{top:f,bottom:f},soldermaskOverCopper:{top:f,bottom:f}}}),D.setCameraBounds({minX:h.minX,maxX:h.maxX,minY:h.minY,maxY:h.maxY}),D.drawElements(w,{layers:[a],drawSoldermask:!1,drawSoldermaskTop:!1,drawSoldermaskBottom:!1});for(let k=1;k<tfi;k+=1)D.drawElements(w,{layers:[a],drawSoldermask:!1,drawSoldermaskTop:!1,drawSoldermaskBottom:!1})},x=A.filter(b=>b.covered_with_solder_mask!==!1),E=A.filter(b=>b.covered_with_solder_mask===!1);y(x,I),r||y(E,C);const B=new IE(d);return B.generateMipmaps=!0,B.minFilter=$m,B.magFilter=xl,B.anisotropy=16,B.needsUpdate=!0,B}var Ynn=(t,e)=>{t.setCameraBounds({minX:e.minX,maxX:e.maxX,minY:e.minY,maxY:e.maxY})},nfi=({ctx:t,layer:e,bounds:n,elements:o,copperColor:i})=>{const r=e==="top"?"top_copper":"bottom_copper",s=new WS(t);s.configure({colorOverrides:{copper:{top:i,bottom:i,inner1:i,inner2:i,inner3:i,inner4:i,inner5:i,inner6:i,inner7:i,inner8:i}}}),Ynn(s,n),s.drawElements(o,{layers:[r]});const a=o.filter(g=>g.type==="pcb_copper_text"&&g.is_knockout===!0);if(a.length===0)return;const A=document.createElement("canvas");A.width=t.canvas.width,A.height=t.canvas.height;const c=A.getContext("2d");if(!c)return;const l=new WS(c);l.configure({colorOverrides:{copper:{top:"rgb(255,255,255)",bottom:"rgb(255,255,255)",inner1:"rgb(255,255,255)",inner2:"rgb(255,255,255)",inner3:"rgb(255,255,255)",inner4:"rgb(255,255,255)",inner5:"rgb(255,255,255)",inner6:"rgb(255,255,255)",inner7:"rgb(255,255,255)",inner8:"rgb(255,255,255)"}}}),Ynn(l,n),l.drawElements(a.map(g=>({...g,is_knockout:!1})),{layers:[r]}),t.save(),t.globalCompositeOperation="destination-out",t.drawImage(A,0,0),t.restore()};function ofi({layer:t,circuitJson:e,boardData:n,copperColor:o="rgb(230, 153, 51)",traceTextureResolution:i=jS}){const r=e.filter(u=>u.type==="pcb_copper_text"&&"layer"in u&&u.layer===t);if(r.length===0)return null;const s=gy(n),a=Math.floor(s.width*i),A=Math.floor(s.height*i);if(a<=0||A<=0)return null;const c=document.createElement("canvas");c.width=a,c.height=A;const l=c.getContext("2d");if(!l)return null;t==="bottom"&&(l.translate(0,A),l.scale(1,-1)),nfi({ctx:l,layer:t,bounds:s,elements:r,copperColor:o});const g=new IE(c);return g.generateMipmaps=!0,g.minFilter=$m,g.magFilter=xl,g.anisotropy=16,g.needsUpdate=!0,g}var Unn=25.4,ifi=Unn/1e3,rfi=/^\s*(-?\d*(?:\.\d+)?)(?:\s*(mm|mil|inch|in|"))?\s*$/i;function sfi(t){if(!t)return;const e=t.trim().toLowerCase();return e==='"'||e==="inch"?"in":e}function bhe(t){if(t==null)return;if(typeof t=="number")return Number.isFinite(t)?t:void 0;if(typeof t!="string")return;const e=t.trim();if(e.length===0)return;const n=e.match(rfi);if(!n){const a=Number.parseFloat(e);return Number.isFinite(a)?a:void 0}const[,o,i]=n,r=Number.parseFloat(o||"0");if(!Number.isFinite(r))return;switch(sfi(i)){case"mil":return r*ifi;case"in":return r*Unn;case"mm":case void 0:return r;default:return r}}function Cg(t,e){const n=bhe(t);return n===void 0?e:n}var afi="rgb(255,243,204)",Yu="rgba(0,0,0,0)",Afi=(t,e)=>{t.setCameraBounds({minX:e.minX,maxX:e.maxX,minY:e.minY,maxY:e.maxY})},cfi=t=>t.type==="pcb_fabrication_note_rect"?{...t,width:bhe(t.width)??0,height:bhe(t.height)??0,stroke_width:Cg(t.stroke_width,.1),corner_radius:bhe(t.corner_radius)}:t.type==="pcb_fabrication_note_path"?{...t,stroke_width:Cg(t.stroke_width,.1)}:t.type==="pcb_fabrication_note_text"?{...t,font_size:Cg(t.font_size,1)}:t.type==="pcb_fabrication_note_dimension"?{...t,font_size:Cg(t.font_size,1),arrow_size:Cg(t.arrow_size,1),offset_distance:Cg(t.offset_distance,0)}:t,lfi=({ctx:t,layer:e,bounds:n,elements:o})=>{const i=`${e}_fabrication_note`,r=o.map(cfi),s=new WS(t);s.configure({colorOverrides:{copper:{top:Yu,bottom:Yu,inner1:Yu,inner2:Yu,inner3:Yu,inner4:Yu,inner5:Yu,inner6:Yu,inner7:Yu,inner8:Yu},copperPour:{top:Yu,bottom:Yu},drill:Yu,boardOutline:Yu,substrate:Yu,keepout:{top:Yu,bottom:Yu},courtyard:{top:Yu,bottom:Yu},soldermask:{top:Yu,bottom:Yu},soldermaskWithCopperUnderneath:{top:Yu,bottom:Yu},soldermaskOverCopper:{top:Yu,bottom:Yu},silkscreen:{top:Yu,bottom:Yu},fabricationNote:afi}}),Afi(s,n),s.drawElements(r,{layers:[i]})},gfi=t=>({minX:t.center.x-t.width/2,maxX:t.center.x+t.width/2,minY:t.center.y-t.height/2,maxY:t.center.y+t.height/2,width:t.width,height:t.height,centerX:t.center.x,centerY:t.center.y}),ufi=(t,e)=>{const n=Math.min(t.minX,e.minX),o=Math.max(t.maxX,e.maxX),i=Math.min(t.minY,e.minY),r=Math.max(t.maxY,e.maxY);return{minX:n,maxX:o,minY:i,maxY:r,width:o-n,height:r-i,centerX:(n+o)/2,centerY:(i+r)/2}},Qhe=(t,e)=>{const n=t.filter(s=>s.type==="pcb_panel"),o=t.filter(s=>s.type==="pcb_board"),i=n.find(s=>s.pcb_panel_id===e.pcb_board_id)??n[0];return i&&i.width>0&&i.height>0?gfi(i):(o.length>1?o:[e]).map(s=>gy(s)).reduce((s,a)=>ufi(s,a))},dfi=(t,e)=>{if(!("layer"in t)||t.layer!==e)return!1;const n=t.type;return n.startsWith("pcb_fabrication_note_")&&n!=="pcb_fabrication_note_text"};function hfi({layer:t,circuitJson:e,boardData:n,traceTextureResolution:o=jS}){const i=e.filter(g=>dfi(g,t));if(i.length===0)return null;const r=Qhe(e,n),s=Math.floor(r.width*o),a=Math.floor(r.height*o);if(s<=0||a<=0)return null;const A=document.createElement("canvas");A.width=s,A.height=a;const c=A.getContext("2d");if(!c)return null;t==="bottom"&&(c.translate(0,a),c.scale(1,-1)),lfi({ctx:c,layer:t,bounds:r,elements:i});const l=new IE(A);return l.generateMipmaps=!0,l.minFilter=$m,l.magFilter=xl,l.anisotropy=16,l.needsUpdate=!0,l}var mfi=(t,e)=>{t.setCameraBounds({minX:e.minX,maxX:e.maxX,minY:e.minY,maxY:e.maxY})},pfi=({ctx:t,layer:e,bounds:n,elements:o,keepoutColor:i})=>{const r=e==="top"?"top_copper":"bottom_copper",s=new WS(t);s.configure({colorOverrides:{keepout:{top:i,bottom:i}}}),mfi(s,n),s.drawElements(o,{layers:[r],drawSoldermask:!1,drawSoldermaskTop:!1,drawSoldermaskBottom:!1})},_fi=(t,e)=>t.type!=="pcb_keepout"?!1:!("layers"in t)||!Array.isArray(t.layers)?!0:t.layers.includes(e);function ffi({layer:t,circuitJson:e,boardData:n,traceTextureResolution:o=jS,keepoutColor:i=t==="bottom"?"#4b72d2":"#d24b4b"}){const r=e.filter(u=>_fi(u,t));if(r.length===0)return null;const s=gy(n),a=Math.floor(s.width*o),A=Math.floor(s.height*o);if(a<=0||A<=0)return null;const c=document.createElement("canvas");c.width=a,c.height=A;const l=c.getContext("2d");if(!l)return null;t==="bottom"&&(l.translate(0,A),l.scale(1,-1)),pfi({ctx:l,layer:t,bounds:s,elements:r,keepoutColor:i});const g=new IE(c);return g.generateMipmaps=!0,g.minFilter=$m,g.magFilter=xl,g.anisotropy=16,g.needsUpdate=!0,g}var Iu="rgba(0,0,0,0)",Ifi=(t,e)=>{t.setCameraBounds({minX:e.minX,maxX:e.maxX,minY:e.minY,maxY:e.maxY})},Cfi=t=>t.type==="pcb_note_line"?{...t,x1:Cg(t.x1,0),y1:Cg(t.y1,0),x2:Cg(t.x2,0),y2:Cg(t.y2,0),stroke_width:Cg(t.stroke_width,.1)}:t.type==="pcb_note_rect"?{...t,center:{x:Cg(t.center.x,0),y:Cg(t.center.y,0)},width:Cg(t.width,0),height:Cg(t.height,0),stroke_width:Cg(t.stroke_width,.1),corner_radius:Cg(t.corner_radius,0)}:t.type==="pcb_note_text"?{...t,anchor_position:{x:Cg(t.anchor_position.x,0),y:Cg(t.anchor_position.y,0)},font_size:Cg(t.font_size,1)}:t.type==="pcb_note_path"?{...t,route:t.route.map(e=>({...e,x:Cg(e.x,0),y:Cg(e.y,0)})),stroke_width:Cg(t.stroke_width,.1)}:t.type==="pcb_note_dimension"?{...t,from:{x:Cg(t.from.x,0),y:Cg(t.from.y,0)},to:{x:Cg(t.to.x,0),y:Cg(t.to.y,0)},font_size:Cg(t.font_size,1),arrow_size:Cg(t.arrow_size,1),offset_distance:Cg(t.offset_distance,0)}:t,yfi=({ctx:t,bounds:e,elements:n})=>{const o=n.map(Cfi),i=new WS(t);i.configure({colorOverrides:{copper:{top:Iu,bottom:Iu,inner1:Iu,inner2:Iu,inner3:Iu,inner4:Iu,inner5:Iu,inner6:Iu,inner7:Iu,inner8:Iu},copperPour:{top:Iu,bottom:Iu},drill:Iu,boardOutline:Iu,substrate:Iu,keepout:{top:Iu,bottom:Iu},courtyard:{top:Iu,bottom:Iu},soldermask:{top:Iu,bottom:Iu},soldermaskWithCopperUnderneath:{top:Iu,bottom:Iu},soldermaskOverCopper:{top:Iu,bottom:Iu},silkscreen:{top:Iu,bottom:Iu},fabricationNote:Iu}}),Ifi(i,e),i.drawElements(o)},xfi=(t,e)=>!("layer"in t)||t.layer!==e?!1:t.type.startsWith("pcb_note_");function Efi({layer:t,circuitJson:e,boardData:n,traceTextureResolution:o=jS}){const i=e.filter(g=>xfi(g,t));if(i.length===0)return null;const r=Qhe(e,n),s=Math.floor(r.width*o),a=Math.floor(r.height*o);if(s<=0||a<=0)return null;const A=document.createElement("canvas");A.width=s,A.height=a;const c=A.getContext("2d");if(!c)return null;t==="bottom"&&(c.translate(0,a),c.scale(1,-1)),yfi({ctx:c,bounds:r,elements:i});const l=new IE(A);return l.generateMipmaps=!0,l.minFilter=$m,l.magFilter=xl,l.anisotropy=16,l.needsUpdate=!0,l}var Bfi="rgb(255,243,204)",Ah="rgba(0,0,0,0)",Sfi=(t,e)=>{t.setCameraBounds({minX:e.minX,maxX:e.maxX,minY:e.minY,maxY:e.maxY})},bfi=({ctx:t,layer:e,bounds:n,elements:o,apertureElements:i,silkscreenColor:r})=>{const s=e==="top"?"top_silkscreen":"bottom_silkscreen",a=new WS(t);a.configure({colorOverrides:{copper:{top:Ah,bottom:Ah,inner1:Ah,inner2:Ah,inner3:Ah,inner4:Ah,inner5:Ah,inner6:Ah,inner7:Ah,inner8:Ah},copperPour:{top:Ah,bottom:Ah},drill:Ah,boardOutline:Ah,substrate:Ah,keepout:{top:Ah,bottom:Ah},courtyard:{top:Ah,bottom:Ah},soldermask:{top:Ah,bottom:Ah},soldermaskWithCopperUnderneath:{top:Ah,bottom:Ah},soldermaskOverCopper:{top:Ah,bottom:Ah},silkscreen:{top:r,bottom:r},fabricationNote:Bfi}}),Sfi(a,n),a.drawElements([...o,...i],{layers:[s],clearDrillHoles:!0})},Qfi=(t,e)=>!("layer"in t)||t.layer!==e?!1:t.type.startsWith("pcb_silkscreen_"),vfi=(t,e)=>t.type==="pcb_cutout"?!0:t.type==="pcb_via"?!e||t.is_tented!==!0:t.type==="pcb_hole"||t.type==="pcb_plated_hole"?!e||t.is_covered_with_solder_mask!==!0:!1;function Pfi({layer:t,circuitJson:e,boardData:n,traceTextureResolution:o=jS,silkscreenColor:i="rgb(255,255,255)",soldermaskVisible:r=!0}){const s=e.filter(d=>Qfi(d,t));if(s.length===0)return null;const a=e.filter(d=>vfi(d,r)),A=Qhe(e,n),c=Math.floor(A.width*o),l=Math.floor(A.height*o);if(c<=0||l<=0)return null;const g=document.createElement("canvas");g.width=c,g.height=l;const u=g.getContext("2d");if(!u)return null;t==="bottom"&&(u.translate(0,l),u.scale(1,-1)),bfi({ctx:u,layer:t,bounds:A,elements:s,apertureElements:a,silkscreenColor:i});const h=new IE(g);return h.generateMipmaps=!0,h.minFilter=$m,h.magFilter=xl,h.anisotropy=16,h.needsUpdate=!0,h}var yX=t=>{const[e=0,n=0,o=0]=t;return`rgb(${Math.round(e*255)}, ${Math.round(n*255)}, ${Math.round(o*255)})`},wfi=t=>{const e=yX(__i[t.material]??Yc.fr4SolderMaskGreen),n=t.material==="fr1"?yX(Yc.fr1TracesWithMaskCopper):yX(Yc.fr4TracesWithMaskGreen),o=Tnn(t.solder_mask_color);if(!o)return{soldermask:e,soldermaskOverCopper:n,copper:yX(Yc.copper),transparent:"rgba(0,0,0,0)"};const i=new Yi().setRGB(Yc.copper[0],Yc.copper[1],Yc.copper[2],mE);return{soldermask:knn(o),soldermaskOverCopper:knn(Q_i({soldermaskColor:o,copperColor:i,soldermaskOpacity:S_i(t.solder_mask_color)})),copper:yX(Yc.copper),transparent:"rgba(0,0,0,0)"}},Knn=(t,e)=>{t.setCameraBounds({minX:e.minX,maxX:e.maxX,minY:e.minY,maxY:e.maxY})},Mfi=({ctx:t,layer:e,bounds:n,elements:o,boardData:i})=>{const r=wfi(i),s=e==="top"?"top_copper":"bottom_copper",a=new WS(t);a.configure({colorOverrides:{copper:{top:r.transparent,bottom:r.transparent,inner1:r.transparent,inner2:r.transparent,inner3:r.transparent,inner4:r.transparent,inner5:r.transparent,inner6:r.transparent,inner7:r.transparent,inner8:r.transparent},drill:r.transparent,boardOutline:r.transparent,substrate:r.transparent,keepout:{top:r.transparent,bottom:r.transparent},fabricationNote:r.transparent,silkscreen:{top:r.transparent,bottom:r.transparent},courtyard:{top:r.transparent,bottom:r.transparent},soldermask:{top:r.soldermask,bottom:r.soldermask},soldermaskWithCopperUnderneath:{top:r.soldermaskOverCopper,bottom:r.soldermaskOverCopper},soldermaskOverCopper:{top:r.soldermaskOverCopper,bottom:r.soldermaskOverCopper}}}),Knn(a,n);const A=o.filter(l=>l.type!=="pcb_keepout");a.drawElements(A,{layers:[s],drawSoldermask:!0,drawSoldermaskTop:e==="top",drawSoldermaskBottom:e==="bottom"});const c=A.filter(l=>l.type==="pcb_copper_pour"&&l.layer===e&&l.covered_with_solder_mask===!1);if(c.length>0){t.save(),t.globalCompositeOperation="destination-out";const l=new WS(t);l.configure({colorOverrides:{copper:{top:r.copper,bottom:r.copper,inner1:r.copper,inner2:r.copper,inner3:r.copper,inner4:r.copper,inner5:r.copper,inner6:r.copper,inner7:r.copper,inner8:r.copper}}}),Knn(l,n),l.drawElements(c,{layers:[s]}),t.restore()}};function Dfi({layer:t,circuitJson:e,boardData:n,traceTextureResolution:o=jS}){const i=Qhe(e,n),r=Math.floor(i.width*o),s=Math.floor(i.height*o);if(r<=0||s<=0)return null;const a=document.createElement("canvas");a.width=r,a.height=s;const A=a.getContext("2d");if(!A)return null;t==="bottom"&&(A.translate(0,s),A.scale(1,-1));const c=e.some(g=>g.type==="pcb_board")?e:[n,...e];Mfi({ctx:A,layer:t,bounds:i,elements:c,boardData:n});const l=new IE(a);return l.generateMipmaps=!0,l.minFilter=$m,l.magFilter=xl,l.anisotropy=16,l.needsUpdate=!0,l}var Nfi=(t,e)=>{t.setCameraBounds({minX:e.minX,maxX:e.maxX,minY:e.minY,maxY:e.maxY})},Rfi=({ctx:t,layer:e,bounds:n,elements:o,copperColor:i})=>{const r=e==="top"?"top_copper":"bottom_copper",s="rgba(0,0,0,0)",a=new WS(t);a.configure({colorOverrides:{copper:{top:i,bottom:i,inner1:i,inner2:i,inner3:i,inner4:i,inner5:i,inner6:i,inner7:i,inner8:i},drill:s,boardOutline:s,substrate:s,keepout:{top:s,bottom:s},fabricationNote:s,silkscreen:{top:s,bottom:s},courtyard:{top:s,bottom:s},soldermask:{top:s,bottom:s},soldermaskWithCopperUnderneath:{top:s,bottom:s},soldermaskOverCopper:{top:s,bottom:s}}}),Nfi(a,n),a.drawElements(o,{layers:[r]})};function Tfi({layer:t,circuitJson:e,boardData:n,copperColor:o="rgb(230, 153, 51)",traceTextureResolution:i=jS}){const r=e.filter(u=>{if(u.type==="pcb_via")return!0;if(u.type!=="pcb_plated_hole")return!1;const h=u;return!Array.isArray(h.layers)||h.layers.includes(t)});if(r.length===0)return null;const s=gy(n),a=Math.floor(s.width*i),A=Math.floor(s.height*i);if(a<=0||A<=0)return null;const c=document.createElement("canvas");c.width=a,c.height=A;const l=c.getContext("2d");if(!l)return null;t==="bottom"&&(l.translate(0,A),l.scale(1,-1)),Rfi({ctx:l,layer:t,bounds:s,elements:r,copperColor:o});const g=new IE(c);return g.generateMipmaps=!0,g.minFilter=$m,g.magFilter=xl,g.anisotropy=16,g.needsUpdate=!0,g}var Vnn=t=>{const[e=0,n=0,o=0]=t;return`rgb(${Math.round(e*255)}, ${Math.round(n*255)}, ${Math.round(o*255)})`},tKe=t=>Math.max(0,Math.min(255,t)),kfi=(t,e,n,o={})=>{const i=t.getImageData(0,0,e,n),r=i.data,s=Math.max(e-1,1),a=Math.max(n-1,1);for(let A=0;A<r.length;A+=4){if((r[A+3]??0)<16)continue;const l=r[A]??0,g=r[A+1]??0,u=r[A+2]??0,h=.2126*l+.7152*g+.0722*u;if(!(g>l*1.35&&g>u*1.15&&h<90&&l<80&&u<80))continue;const m=A/4,p=m%e,_=Math.floor(m/e),f=p/s,I=_/a,C=f*.62+(1-I)*.38,y=Math.sin((f*1.15+I*.35)*Math.PI)*.04,x=.74+C*.18+y,E=o.includeReflection?(()=>{const k=f-.36,T=I-.22,H=Math.max(0,1-Math.hypot(k,T)/.38);return H*H*.07})():0,B=(l*.9+3)*x,b=(g*1.08+15)*x,Q=(u*1.28+13)*x;r[A]=tKe(B*(1-E)+255*E),r[A+1]=tKe(b*(1-E)+255*E),r[A+2]=tKe(Q*(1-E)+255*E)}t.putImageData(i,0,0)},Ffi=({textures:t,boardData:e,traceTextureResolution:n,layer:o})=>{if(!t.some(g=>g?.image))return null;const r=gy(e),s=Math.floor(r.width*n),a=Math.floor(r.height*n);if(s<=0||a<=0)return null;const A=document.createElement("canvas");A.width=s,A.height=a+1;const c=A.getContext("2d");if(!c)return null;for(const g of t){if(!g?.image)continue;const u=g.image;c.drawImage(u,0,0,s,a)}kfi(c,s,a,{includeReflection:o==="top"});const l=new IE(A);return l.generateMipmaps=!1,l.minFilter=xl,l.magFilter=xl,l.premultiplyAlpha=!0,l.anisotropy=16,l.needsUpdate=!0,l},Lfi=({textures:t,boardData:e,traceTextureResolution:n})=>{if(!t.some(c=>c?.image))return null;const o=gy(e),i=Math.floor(o.width*n),r=Math.floor(o.height*n);if(i<=0||r<=0)return null;const s=document.createElement("canvas");s.width=i,s.height=r+1;const a=s.getContext("2d");if(!a)return null;for(const c of t)c?.image&&a.drawImage(c.image,0,0,i,r);const A=new IE(s);return A.colorSpace=Uv,A.generateMipmaps=!1,A.minFilter=xl,A.magFilter=xl,A.premultiplyAlpha=!1,A.needsUpdate=!0,A};function znn({circuitJson:t,boardData:e,traceTextureResolution:n,visibility:o}){const i=Vnn(Yc.copper),r="rgb(255,255,255)",s=Vnn(Yc.copper),a=o?.boardBody??!0,A=u=>{const h=(u==="top"?o?.topMask:o?.bottomMask)??!0,d=(u==="top"?o?.topCopper:o?.bottomCopper)??!0,m=(u==="top"?o?.topSilkscreen:o?.bottomSilkscreen)??!0,p=o?.keepout??!0,_=h?Dfi({layer:u,circuitJson:t,boardData:e,traceTextureResolution:n}):null,f=d?Z_i({layer:u,circuitJson:t,boardData:e,traceColor:i,traceTextureResolution:n}):null,I=d?Gnn({layer:u,circuitJson:t,boardData:e,traceTextureResolution:n,copperColor:s}):null,C=h&&d?Gnn({layer:u,circuitJson:t,boardData:e,traceTextureResolution:n,copperColor:s,onlyCoveredBySoldermask:!0}):null,y=d?ofi({layer:u,circuitJson:t,boardData:e,copperColor:s,traceTextureResolution:n}):null,x=d?W_i({layer:u,circuitJson:t,boardData:e,copperColor:s,traceTextureResolution:n}):null,E=d?Tfi({layer:u,circuitJson:t,boardData:e,copperColor:s,traceTextureResolution:n}):null,B=m?Pfi({layer:u,circuitJson:t,boardData:e,silkscreenColor:r,traceTextureResolution:n,soldermaskVisible:h}):null,b=m?hfi({layer:u,circuitJson:t,boardData:e,traceTextureResolution:n}):null,w=o?.pcbNotes??!1?Efi({layer:u,circuitJson:t,boardData:e,traceTextureResolution:n}):null,D=a?q_i({layer:u,circuitJson:t,panelData:e,traceTextureResolution:n}):null,k=p?ffi({layer:u,circuitJson:t,boardData:e,traceTextureResolution:n}):null,T=Ffi({textures:[I,f,x,E,_,y,B,b,w,D,k],boardData:e,traceTextureResolution:n,layer:u}),H=h&&d?Lfi({textures:[f,C],boardData:e,traceTextureResolution:n}):null;return{boardTexture:T,maskedCopperTexture:H}},c=e.num_layers??2,l=A("top"),g=c<2?null:A("bottom");return{topBoard:l.boardTexture,bottomBoard:g?.boardTexture??null,topMaskedCopper:l.maskedCopperTexture,bottomMaskedCopper:g?.maskedCopperTexture??null}}var PQ={bumpScale:.12,normalScale:.08,roughnessBias:.015,clearcoat:.08,clearcoatRoughness:.55},vhe={roughness:.42,metalness:.5,roughnessVariance:.035,detailStrength:.028},Phe=.22,Hfi=.7,Ofi=.86,Jnn={height:Phe,microSurfaceWeight:1,roughness:.7,metalness:.015,isExposedCopper:!1,isMaskedCopper:!1},Gfi={height:Hfi,microSurfaceWeight:.9,roughness:.54,metalness:.025,isExposedCopper:!1,isMaskedCopper:!0},nKe=t=>Math.max(0,Math.min(1,t)),Wnn=t=>1-t,xX=(t,e,n)=>{let o=Math.imul(t,374761393)^Math.imul(e,668265263)^n;return o=Math.imul(o^o>>>13,1274126177),((o^o>>>16)>>>0)/4294967295},jnn=t=>t*t*(3-2*t),oKe=(t,e,n)=>t+(e-t)*n,iKe=(t,e,n,o)=>{const i=t/n,r=e/n,s=Math.floor(i),a=Math.floor(r),A=jnn(i-s),c=jnn(r-a),l=oKe(xX(s,a,o),xX(s+1,a,o),A),g=oKe(xX(s,a+1,o),xX(s+1,a+1,o),A);return oKe(l,g,c)},Yfi=(t,e,n)=>{const o=(iKe(t,e,7,n+31)-.5)*.55,i=Math.sin(t*.12+iKe(t,e,44,n+37)*2)*.22;return(o+i)*vhe.detailStrength},Ufi=(t,e,n)=>{const o=(xX(t,e,n+53)-.5)*.42,i=Math.sin(t*.26+e*.06)*.2+Math.sin(e*.31-t*.04)*.12;return(o+i)*.045},Kfi=(t,e,n,o)=>o?Gfi:b_i({red:t,green:e,blue:n})?Jnn:t>120&&e>70&&n<150&&t>e*1.05&&e>n*1.15?{height:Ofi,microSurfaceWeight:.9,roughness:vhe.roughness,metalness:vhe.metalness,isExposedCopper:!0,isMaskedCopper:!1}:t>170&&e>170&&n>160?{height:Phe,microSurfaceWeight:.4,roughness:.76,metalness:0,isExposedCopper:!1,isMaskedCopper:!1}:e>t*1.25&&e>n*1.05&&t<110&&e<180&&n<130?Jnn:{height:Phe,microSurfaceWeight:.7,roughness:.58,metalness:.015,isExposedCopper:!1,isMaskedCopper:!1},whe=t=>{const e=new IE(t);return e.colorSpace=Uv,e.generateMipmaps=!1,e.minFilter=xl,e.magFilter=xl,e.wrapS=w1,e.wrapT=w1,e.needsUpdate=!0,e},qnn=(t,e)=>{const n=t.image;if(!n?.width||!n.height)return null;const o=n.getContext("2d");if(!o)return null;const i=e?.image,r=i?.getContext("2d"),s=i?.width??0,a=i?.height??0,A=r&&s&&a?r.getImageData(0,0,s,a):null,c=o.getImageData(0,0,n.width,n.height),l=c.data,g=new Float32Array(n.width*n.height),u=document.createElement("canvas"),h=document.createElement("canvas");u.width=h.width=n.width,u.height=h.height=n.height;const d=u.getContext("2d"),m=h.getContext("2d");if(!d||!m)return null;const p=d.createImageData(n.width,n.height),_=m.createImageData(n.width,n.height),f=p.data,I=_.data;for(let w=0;w<l.length;w+=4){const D=w/4,k=D%n.width,T=Math.floor(D/n.width);if((l[w+3]??0)<16){g[D]=Wnn(Phe);continue}const G=A?Math.min(s-1,Math.floor(k/n.width*s)):0,U=A?Math.min(a-1,Math.floor(T/n.height*a)):0,Y=A?A.data[(U*s+G)*4+3]??0:0,q=Kfi(l[w]??0,l[w+1]??0,l[w+2]??0,Y>=16),ee=n.width+n.height,W=q.isExposedCopper?Yfi(k,T,ee):q.isMaskedCopper?Ufi(k,T,ee):0,J=nKe(Wnn(q.height)+W*q.microSurfaceWeight);g[D]=J;const ie=J*255;l[w]=l[w+1]=l[w+2]=ie,l[w+3]=255;const ne=(q.isExposedCopper?nKe(q.roughness+W*.7+(iKe(k,T,36,ee+17)-.5)*vhe.roughnessVariance):q.isMaskedCopper?nKe(q.roughness+W+PQ.roughnessBias):q.roughness)*255;f[w]=f[w+1]=f[w+2]=ne,f[w+3]=255;const le=q.metalness*255;I[w]=I[w+1]=I[w+2]=le,I[w+3]=255}d.putImageData(p,0,0),m.putImageData(_,0,0);const C=document.createElement("canvas");C.width=n.width,C.height=n.height;const y=C.getContext("2d");if(!y)return null;y.putImageData(c,0,0);const x=document.createElement("canvas");x.width=n.width,x.height=n.height;const E=x.getContext("2d");if(!E)return null;const B=E.createImageData(n.width,n.height),b=B.data,Q=(w,D)=>g[Math.max(0,Math.min(n.height-1,D))*n.width+Math.max(0,Math.min(n.width-1,w))]??0;for(let w=0;w<n.height;w++)for(let D=0;D<n.width;D++){const k=(Q(D+1,w)-Q(D-1,w))*4,T=(Q(D,w+1)-Q(D,w-1))*4,H=new jt(-k,-T,1).normalize(),G=(w*n.width+D)*4;b[G]=(H.x*.5+.5)*255,b[G+1]=(H.y*.5+.5)*255,b[G+2]=(H.z*.5+.5)*255,b[G+3]=255}return E.putImageData(B,0,0),{bumpMap:whe(C),normalMap:whe(x),roughnessMap:whe(u),metalnessMap:whe(h)}};function Xnn(t,e){const{texture:n,maskedCopperMask:o,yOffset:i,isBottomLayer:r,usePolygonOffset:s=!1,renderOrder:a=0,isFaux:A=!1}=t;if(!n)return null;const c=gy(e),l=new BQ(c.width,c.height);n.colorSpace=mE;const g={map:n,transparent:!0,alphaTest:.08,side:q2,depthWrite:!0,polygonOffset:s,polygonOffsetFactor:s?-4:0,polygonOffsetUnits:s?-4:0,opacity:A?xhe:1},u=qnn(n,o),h=new eB({...g,bumpMap:u?.bumpMap??null,bumpScale:PQ.bumpScale,normalMap:u?.normalMap??null,normalScale:new Jo(PQ.normalScale,PQ.normalScale),roughnessMap:u?.roughnessMap??null,roughness:1,metalnessMap:u?.metalnessMap??null,metalness:1,clearcoat:PQ.clearcoat,clearcoatRoughness:PQ.clearcoatRoughness,envMapIntensity:.18}),d=new Dr(l,h);return d.position.set(c.centerX,c.centerY,i),r&&d.rotation.set(Math.PI,0,0),d.name=`${r?"bottom":"top"}-board-texture-plane`,d.renderOrder=a,QQ(d,{castShadow:!1,receiveShadow:!0}),d}function Vfi(t,e,n,o=!1){const i=[];if(!t||!e||n===null)return i;const r=.005,s=Xnn({texture:t.topBoard,maskedCopperMask:t.topMaskedCopper,yOffset:n/2+r,isBottomLayer:!1,usePolygonOffset:!0,renderOrder:1,isFaux:o},e);s&&i.push(s);const a=Xnn({texture:t.bottomBoard,maskedCopperMask:t.bottomMaskedCopper,yOffset:-n/2-r,isBottomLayer:!0,usePolygonOffset:!0,renderOrder:1,isFaux:o},e);return a&&i.push(a),i}var zfi=4e6,Jfi=4096,Wfi=1;function $nn(t,e,n={}){const{maxTexturePixels:o=zfi,maxTextureDimension:i=Jfi,minTextureResolution:r=Wfi}=n,s=gy(t);if(!Number.isFinite(s.width)||!Number.isFinite(s.height)||s.width<=0||s.height<=0)return e;const a=Math.max(s.width,s.height),A=i/a,c=Math.sqrt(o/(s.width*s.height)),l=Math.min(e,A,c);return Math.max(r,l)}function jfi({circuitJson:t,pcbThickness:e,isFaux:n=!1}){const{rootObject:o}=jI(),{visibility:i}=pR(),r=te.useMemo(()=>{const A=t.filter(g=>g.type==="pcb_panel"),c=Cr(t).pcb_board.list();if(A.length>0){const g=A[0],u=c.find(h=>h.pcb_panel_id===g.pcb_panel_id);return{type:"pcb_board",pcb_board_id:g.pcb_panel_id,center:g.center,width:g.width,height:g.height,thickness:u?.thickness??1.4,material:u?.material??"fr4",num_layers:u?.num_layers??2,solder_mask_color:u?.solder_mask_color}}const l=c.filter(g=>!g.pcb_panel_id);return l.length>0?l[0]:null},[t]),s=te.useMemo(()=>r?$nn(r,jS):jS,[r]),a=te.useMemo(()=>!r?.width||!r.height?null:znn({circuitJson:t,boardData:r,traceTextureResolution:s,visibility:i}),[t,r,s,i]);return te.useEffect(()=>{if(!o||!r||!a)return;const A=[],c=d=>{const m=["map","alphaMap","aoMap","bumpMap","displacementMap","emissiveMap","lightMap","metalnessMap","normalMap","roughnessMap","specularMap"],p=d;for(const _ of m){const f=p[_];f&&f instanceof Bd&&(f.dispose(),p[_]=null)}d.dispose()},l=({texture:d,maskedCopperMask:m,zOffset:p,isBottomLayer:_,name:f,usePolygonOffset:I=!1,depthWrite:C=!0,renderOrder:y=1})=>{if(!d)return null;const x=gy(r),E=new BQ(x.width,x.height);d.colorSpace=mE;const B={map:d,transparent:!0,alphaTest:.08,side:q2,depthWrite:C,polygonOffset:I,polygonOffsetFactor:I?-4:0,polygonOffsetUnits:I?-4:0,opacity:n?xhe:1},b=qnn(d,m),Q=new eB({...B,bumpMap:b?.bumpMap??null,bumpScale:PQ.bumpScale,normalMap:b?.normalMap??null,normalScale:new Jo(PQ.normalScale,PQ.normalScale),roughnessMap:b?.roughnessMap??null,roughness:1,metalnessMap:b?.metalnessMap??null,metalness:1,clearcoat:PQ.clearcoat,clearcoatRoughness:PQ.clearcoatRoughness,envMapIntensity:.18}),w=new Dr(E,Q);return w.position.set(x.centerX,x.centerY,p),_&&w.rotation.set(Math.PI,0,0),w.name=f,w.renderOrder=y,w.frustumCulled=!1,QQ(w,{castShadow:!1,receiveShadow:!0}),w},g=.005,u=l({texture:a.topBoard,maskedCopperMask:a.topMaskedCopper,zOffset:e/2+g,isBottomLayer:!1,name:"jscad-top-board-texture",usePolygonOffset:!0});u&&(A.push(u),o.add(u));const h=l({texture:a.bottomBoard,maskedCopperMask:a.bottomMaskedCopper,zOffset:-e/2-g,isBottomLayer:!0,name:"jscad-bottom-board-texture",usePolygonOffset:!0});return h&&(A.push(h),o.add(h)),()=>{for(const d of A)if(d.parent===o&&o.remove(d),d.geometry.dispose(),Array.isArray(d.material))for(const m of d.material)c(m);else d.material instanceof _E&&c(d.material);a.topBoard?.dispose(),a.bottomBoard?.dispose()}},[o,r,a,e]),null}function qfi({stlUrl:t,stlData:e,mtlUrl:n,color:o,opacity:i=1,layerType:r}){const{rootObject:s}=jI(),[a,A]=te.useState(null);te.useEffect(()=>{const l=new rjo;if(e){try{const g=l.parse(e);A(g)}catch(g){console.error("Failed to parse STL data",g),A(null)}return}t&&l.load(t,g=>{A(g)})},[t,e]);const c=te.useMemo(()=>{if(!a)return null;const l=r==="board",g=new pu({color:Array.isArray(o)?new Yi(o[0],o[1],o[2]):o,transparent:i!==1,opacity:i,polygonOffset:l,polygonOffsetFactor:l?6:0,polygonOffsetUnits:l?6:0}),u=new Dr(a,g);return u.renderOrder=l?-1:1,QQ(u,{castShadow:!l&&i===1,receiveShadow:!0}),u},[a,o,i,r]);return te.useEffect(()=>{if(!(!s||!c))return s.add(c),()=>{s.remove(c),c.geometry.dispose(),Array.isArray(c.material)?c.material.forEach(l=>l.dispose()):c.material.dispose()}},[s,c]),null}function Xfi({stlData:t,color:e,opacity:n=1,layerType:o}){const{visibility:i}=pR();let r=!0;return o==="board"?r=i.boardBody:o==="top-copper"?r=i.topCopper:o==="bottom-copper"?r=i.bottomCopper:o==="top-silkscreen"?r=i.topSilkscreen:o==="bottom-silkscreen"&&(r=i.bottomSilkscreen),r?K.jsx(qfi,{stlData:t,color:e,opacity:n,layerType:o}):null}function $fi(t){const e=Cr(t).cad_component.list(),n=Cr(t).pcb_smtpad.list(),o=Cr(t).pcb_hole.list(),i=Cr(t).pcb_plated_hole.list(),r=Cr(t).pcb_via.list();if(e.length===0&&n.length===0&&o.length===0&&i.length===0&&r.length===0)return null;const s=[...o,...i,...r,...n],a=rw(s);let A=a.minX,c=a.maxX,l=a.minY,g=a.maxY;for(const f of e)if(f.position){const I=f.position.x,C=f.position.y;A=Math.min(A,I),c=Math.max(c,I),l=Math.min(l,C),g=Math.max(g,C)}A===1/0&&(A=-10,c=10,l=-10,g=10);const u=2,h=Math.max(Math.abs(A),Math.abs(c))+u,d=Math.max(Math.abs(l),Math.abs(g))+u,m=Math.max(2*h,10),p=Math.max(2*d,10);return{type:"pcb_board",pcb_board_id:"faux-board",center:{x:0,y:0},width:m,height:p,thickness:1.4,material:"fr4",num_layers:2}}function Znn(t){if(Cr(t).pcb_board.list().length>0)return t;const n=$fi(t);if(!n)return t;const i=n.thickness/2;return[...t.map(s=>{if(s.type==="cad_component"){const a=s;if(a.position){const A=a.position.z??0;return{...a,position:{...a.position,z:A+i}}}}return s}),n]}var Zfi=te.forwardRef(({circuitJson:t,children:e,autoRotateDisabled:n,clickToInteractEnabled:o,onUserInteraction:i,onCameraControllerReady:r,resolveStaticAsset:s,referenceObject:a},A)=>{const c=Nnn(e),l=te.useMemo(()=>Znn(t??c),[t,c]),g=K_i(l),u=te.useMemo(()=>{if(!l)return[5,-5,5];try{const I=Cr(l).pcb_board.list()[0];if(!I)return[5,-5,5];const{width:C,height:y}=I;if(!C&&!y)return[5,-5,5];const x=5,E=Math.max(C,x),B=Math.max(y,x),b=Math.max(E,B);return[b*.4,-b*.7,b*.9]}catch(I){return console.error(I),[5,-5,5]}},[l]),h=te.useMemo(()=>{if(!l)return!1;try{const I=Cr(l).pcb_board.list()[0];return!!I&&I.pcb_board_id==="faux-board"}catch{return!1}},[l]),d=te.useMemo(()=>{if(l)try{const I=Cr(l).pcb_board.list()[0];if(!I)return;const C=gy(I);return{width:C.width,height:C.height}}catch(I){console.error(I);return}},[l]),m=te.useMemo(()=>{if(l)try{const I=Cr(l).pcb_board.list()[0];if(!I)return;const C=gy(I);return{x:C.centerX,y:C.centerY}}catch(I){console.error(I);return}},[l]),p=jen(l),{stls:_}=c_i(g),f=Cr(l).cad_component.list();return K.jsxs(Dnn,{ref:A,autoRotateDisabled:n,initialCameraPosition:u,clickToInteractEnabled:o,boardDimensions:d,boardCenter:m,referenceObject:a,onUserInteraction:i,onCameraControllerReady:r,children:[_.map(({stlData:I,color:C,layerType:y},x)=>K.jsx(Xfi,{stlData:I,color:C,opacity:x===0?h?.8:.95:1,layerType:y},`board-${x}`)),K.jsx(jfi,{circuitJson:l,pcbThickness:p,isFaux:h}),f.map(I=>K.jsx(UUe,{fallback:({error:C})=>K.jsx(Onn,{cad_component:I,error:C}),children:K.jsx(xnn,{cad_component:I,circuitJson:l,resolveStaticAsset:s},I.cad_component_id)},I.cad_component_id))]})}),eIi=t=>{let e=0;for(let o=0;o<t.length;o++){const i=(o+1)%t.length;t[o]&&t[i]&&(e+=t[o][0]*t[i][1],e-=t[i][0]*t[o][1])}return e/2<=0};function tIi(t,e,n,o,i){let r,s=null;if(n.outline&&n.outline.length>=3){let a=n.outline.map(c=>[c.x,c.y]);eIi(a)&&(a=a.reverse());const A=e.ofPolygons([a]);i.push(A),s=A,r=t.extrude(A,o,void 0,void 0,void 0,!0),i.push(r)}else n.outline&&n.outline.length>0&&console.warn("Board outline has fewer than 3 points, falling back to rectangular board."),r=t.cube([n.width,n.height,o],!0),i.push(r),r=r.translate([n.center.x,n.center.y,0]),i.push(r);return{boardOp:r,outlineCrossSection:s}}var nIi=64;function yR({Manifold:t,width:e,height:n,thickness:o,borderRadius:i}){const r=Lnn(e,n,i);if(r<=0)return t.cube([e,n,o],!0);const s=[],a=e-2*r,A=n-2*r;return a>0&&s.push(t.cube([a,n,o],!0)),A>0&&s.push(t.cube([e,A,o],!0)),[[e/2-r,n/2-r],[-e/2+r,n/2-r],[-e/2+r,-n/2+r],[e/2-r,-n/2+r]].forEach(([l,g])=>{s.push(t.cylinder(o,r,r,nIi,!0).translate([l,g,0]))}),t.union(s)}var oIi=t=>{let e=0;for(let o=0;o<t.length;o++){const i=(o+1)%t.length;t[o]&&t[i]&&(e+=t[o][0]*t[i][1],e-=t[i][0]*t[o][1])}return e/2<=0};function iIi(t,e,n,o,i){const r=[],s=Cr(n).pcb_cutout.list();for(const a of s){let A;const c=o*1.5;switch(a.shape){case"rect":{const u=w9(a);if(typeof u=="number"&&u>0?A=yR({Manifold:t,width:a.width,height:a.height,thickness:c,borderRadius:u}):A=t.cube([a.width,a.height,c],!0),i.push(A),a.rotation){const h=A.rotate([0,0,a.rotation]);i.push(h),A=h}A=A.translate([a.center.x,a.center.y,0]),i.push(A);break}case"circle":A=t.cylinder(c,a.radius,-1,W_,!0),i.push(A),A=A.translate([a.center.x,a.center.y,0]),i.push(A);break;case"polygon":if(a.points.length<3){console.warn(`PCB Cutout [${a.pcb_cutout_id}] polygon has fewer than 3 points, skipping.`);continue}let l=a.points.map(u=>[u.x,u.y]);oIi(l)&&(l=l.reverse());const g=e.ofPolygons([l]);i.push(g),A=t.extrude(g,c,0,0,[1,1],!0),i.push(A);break;default:console.warn(`Unsupported cutout shape: ${a.shape} for cutout ${a.pcb_cutout_id}`);continue}A&&r.push(A)}return{cutoutOps:r}}function eon({Manifold:t,x:e,y:n,diameter:o,thickness:i,segments:r=32}){return t.cylinder(i*1.2,o/2,o/2,r,!0).translate([e,n,0])}function ton({Manifold:t,x:e,y:n,holeDiameter:o,thickness:i,zOffset:r=.001,segments:s=32}){const a=o/2+r;return t.cylinder(i*1.2,a,a,s,!0).translate([e,n,0])}function rIi(t,e,n,o,i){const r=[],s=Cr(n).pcb_hole.list(),a=(l,g,u)=>{const h=yR({Manifold:t,width:l,height:g,thickness:u,borderRadius:Math.min(l,g)/2});return i.push(h),h},A=(l,g,u)=>{const h=t.cube([l,g,u],!0);return i.push(h),h},c=(l,g,u)=>{const h=[];for(let d=0;d<u;d++){const m=2*Math.PI*d/u;h.push([l/2*Math.cos(m),g/2*Math.sin(m)])}return h};for(const l of s){const g=l.hole_shape,u=l.x,h=l.y,d=o*1.2,m=l.ccw_rotation??l.rotation??0,p=l.hole_width??l.hole_diameter,_=l.hole_height??l.hole_diameter;let f=null;if(g==="circle"){f=eon({Manifold:t,x:u,y:h,diameter:l.hole_diameter,thickness:o,segments:W_}),r.push(f),i.push(f);continue}if(g==="pill"||g==="rotated_pill")f=a(p,_,d);else if(g==="rect")f=A(p,_,d);else if(g==="oval"){let I=c(p,_,W_),C=0;for(let x=0;x<I.length;x++){const E=(x+1)%I.length;C+=I[x][0]*I[E][1],C-=I[E][0]*I[x][1]}C<=0&&(I=I.reverse());const y=e.ofPolygons([I]);i.push(y),f=t.extrude(y,d,0,0,[1,1],!0),i.push(f)}if(f){if(m!==0){const C=f.rotate([0,0,m]);i.push(C),f=C}const I=f.translate([u,h,0]);i.push(I),r.push(I)}}return{nonPlatedHoleBoardDrills:r}}function oP(t){const e=new tg;if(e.setAttribute("position",new Ds(t.vertProperties,3)),e.setIndex(new K8e(t.triVerts,1)),t.runIndex&&t.runIndex.length>1&&t.runOriginalID)for(let n=0;n<t.runIndex.length-1;n++){const o=t.runIndex[n],i=t.runIndex[n+1]-o;e.addGroup(o,i,0)}else e.addGroup(0,t.triVerts.length,0);return e}var EX=t=>{let e=0;for(let o=0;o<t.length;o++){const i=(o+1)%t.length;t[o]&&t[i]&&(e+=t[o][0]*t[i][1],e-=t[i][0]*t[o][1])}return e/2<=0},Mhe=(t,e,n)=>{const o=[];for(let i=0;i<n;i++){const r=2*Math.PI*i/n;o.push([t/2*Math.cos(r),e/2*Math.sin(r)])}return o},xR=new Yi(...Yc.copper),Dhe=.05,BX=.003,SX=5e-4,bX=.004;function sIi(t,e,n,o,i,r){const s=[],a=Cr(n).pcb_plated_hole.list(),A=[],c=[],l=(d,m,p)=>{const _=yR({Manifold:t,width:d,height:m,thickness:p,borderRadius:Math.min(d,m)/2});return i.push(_),_},g=({padOutline:d,thickness:m})=>{if(!Array.isArray(d)||d.length<3)return null;let p=d.map(I=>[I.x,I.y]);EX(p)&&(p=p.reverse());const _=e.ofPolygons([p]);i.push(_);const f=t.extrude(_,m,0,0,[1,1],!0);return i.push(f),f},u=({ph:d,depth:m,sizeDelta:p=0})=>{if(d.shape!=="hole_with_polygon_pad")return null;const f=d.pad_outline;if(!Array.isArray(f)||f.length<3)return null;const I=d.hole_shape||"circle",C=d.hole_offset_x||0,y=d.hole_offset_y||0;let x=null;if(I==="circle"){const E=Math.max((d.hole_diameter??0)+p,ms),B=Math.max(E/2,ms/2);x=t.cylinder(m,B,B,W_,!0),i.push(x)}else{const E=d.hole_width??d.hole_diameter,B=d.hole_height??d.hole_diameter;if(!E||!B)return null;const b=Math.max(E+p,ms),Q=Math.max(B+p,ms);if(I==="oval"){let w=Mhe(b,Q,W_);EX(w)&&(w=w.reverse());const D=e.ofPolygons([w]);i.push(D),x=t.extrude(D,m,0,0,[1,1],!0),i.push(x)}else(I==="pill"||I==="rotated_pill")&&(x=yR({Manifold:t,width:b,height:Q,thickness:m,borderRadius:Math.min(b,Q)/2}),i.push(x))}if(!x)return null;if(C||y){const E=x.translate([C,y,0]);i.push(E),x=E}return x};a.forEach((d,m)=>{const p=Math.max(o-2*(BX+SX+bX),ms);if(d.shape==="circle"){const _=ton({Manifold:t,x:d.x,y:d.y,holeDiameter:d.hole_diameter*1.02,thickness:o,zOffset:vQ,segments:W_});i.push(_),s.push(_);const f=p,I=t.cylinder(f,d.outer_diameter/2,d.outer_diameter/2,W_,!0);i.push(I);const C=t.cylinder(f*1.05,d.hole_diameter/2,d.hole_diameter/2,W_,!0);i.push(C);const y=I.subtract(C);i.push(y);const x=y.translate([d.x,d.y,0]);i.push(x);let E=x;if(r){const b=t.intersection([x,r]);i.push(b),E=b}c.push(E);const B=oP(E.getMesh());A.push({key:`ph-${d.pcb_plated_hole_id||m}`,geometry:B,color:xR})}else if(d.shape==="pill"){const _=d.hole_width,f=d.hole_height,I=.4,C=d.outer_width??_+I,y=d.outer_height??f+I,x=_+2*vQ,E=f+2*vQ,B=o*1.2;let b=l(x,E,B);if(d.ccw_rotation){const Y=b.rotate([0,0,d.ccw_rotation]);i.push(Y),b=Y}const Q=b.translate([d.x,d.y,0]);i.push(Q),s.push(Q);const w=p,D=l(C,y,w),k=l(_,f,w*1.05);let T=D.subtract(k);if(i.push(T),d.ccw_rotation){const Y=T.rotate([0,0,d.ccw_rotation]);i.push(Y),T=Y}const H=T.translate([d.x,d.y,0]);i.push(H);let G=H;if(r){const Y=t.intersection([H,r]);i.push(Y),G=Y}c.push(G);const U=oP(G.getMesh());A.push({key:`ph-${d.pcb_plated_hole_id||m}`,geometry:U,color:xR})}else if(d.shape==="pill_hole_with_rect_pad"){if(d.hole_shape&&d.hole_shape!=="pill"||d.pad_shape&&d.pad_shape!=="rect")return;const _=d.hole_width,f=d.hole_height,I=d.hole_offset_x||0,C=d.hole_offset_y||0,y=d.rect_pad_width,x=d.rect_pad_height,E=w9(d),B=BX,b=_+2*vQ,Q=f+2*vQ,w=o*1.2,k=l(b,Q,w).translate([I,C,0]).translate([d.x,d.y,0]);i.push(k),s.push(k);const T=yR({Manifold:t,width:y,height:x,thickness:Math.max(o-2*(B+SX+bX),ms),borderRadius:E});i.push(T);const H=l(_,f,o*.8).translate([I,C,0]);i.push(H);const G=t.union([T,H]);i.push(G);const U=l(Math.max(_-2*Dhe,.01),Math.max(f-2*Dhe,.01),o*1.2).translate([I,C,0]);i.push(U);const Y=G.subtract(U);i.push(Y);const q=Y.translate([d.x,d.y,0]);i.push(q);let ee=q;if(r){const J=t.intersection([q,r]);i.push(J),ee=J}c.push(ee);const W=oP(ee.getMesh());A.push({key:`ph-${d.pcb_plated_hole_id||m}`,geometry:W,color:xR})}else if(d.shape==="rotated_pill_hole_with_rect_pad"){if(d.hole_shape&&d.hole_shape!=="rotated_pill"||d.pad_shape&&d.pad_shape!=="rect")return;const _=d.hole_width,f=d.hole_height,I=d.hole_offset_x||0,C=d.hole_offset_y||0,y=d.rect_pad_width,x=d.rect_pad_height,E=w9(d),B=BX,b=_+2*vQ,Q=f+2*vQ,w=o*1.2;let D=l(b,Q,w).translate([I,C,0]);if(d.hole_ccw_rotation){const J=D.rotate([0,0,d.hole_ccw_rotation]);i.push(J),D=J}const k=D.translate([d.x,d.y,0]);i.push(k),s.push(k);let T=yR({Manifold:t,width:y,height:x,thickness:Math.max(o-2*(B+SX+bX),ms),borderRadius:E});if(i.push(T),d.rect_ccw_rotation){const J=T.rotate([0,0,d.rect_ccw_rotation]);i.push(J),T=J}let H=l(_,f,o*.8).translate([I,C,0]);if(d.hole_ccw_rotation){const J=H.rotate([0,0,d.hole_ccw_rotation]);i.push(J),H=J}i.push(H);const G=t.union([T,H]);i.push(G);let U=l(Math.max(_-2*Dhe,.01),Math.max(f-2*Dhe,.01),o*1.2).translate([I,C,0]);if(d.hole_ccw_rotation){const J=U.rotate([0,0,d.hole_ccw_rotation]);i.push(J),U=J}i.push(U);const Y=G.subtract(U);i.push(Y);const q=Y.translate([d.x,d.y,0]);i.push(q);let ee=q;if(r){const J=t.intersection([q,r]);i.push(J),ee=J}c.push(ee);const W=oP(ee.getMesh());A.push({key:`ph-${d.pcb_plated_hole_id||m}`,geometry:W,color:xR})}else if(d.shape==="hole_with_polygon_pad"){const _=d.pad_outline;if(!Array.isArray(_)||_.length<3)return;const f=u({ph:d,depth:o*1.2,sizeDelta:2*ms});if(!f)return;const I=f.translate([d.x,d.y,0]);i.push(I),s.push(I);const y=Math.max(o-2*(BX+SX+bX),ms),x=g({padOutline:_,thickness:y});if(!x)return;const E=u({ph:d,depth:o*1.02});if(!E)return;const B=u({ph:d,depth:o*.8,sizeDelta:-2*ms})||E,b=t.union([x,E]);i.push(b);const Q=b.subtract(B);i.push(Q);const w=Q.translate([d.x,d.y,0]);i.push(w);let D=w;if(r){const T=t.intersection([w,r]);i.push(T),D=T}c.push(D);const k=oP(D.getMesh());A.push({key:`ph-${d.pcb_plated_hole_id||m}`,geometry:k,color:xR})}else if(d.shape==="oval"){const _=d.hole_width,f=d.hole_height,I=d.outer_width??_+.4,C=d.outer_height??f+.4,y=_+2*vQ,x=f+2*vQ,E=o*1.2;let B=Mhe(y,x,W_);EX(B)&&(B=B.reverse());const b=e.ofPolygons([B]);i.push(b);let Q=t.extrude(b,E,0,0,[1,1],!0);if(i.push(Q),d.ccw_rotation){const ie=Q.rotate([0,0,d.ccw_rotation]);i.push(ie),Q=ie}const w=Q.translate([d.x,d.y,0]);i.push(w),s.push(w);const D=p;let k=Mhe(I,C,W_);EX(k)&&(k=k.reverse());const T=e.ofPolygons([k]);i.push(T);const H=t.extrude(T,D,0,0,[1,1],!0);i.push(H);let G=Mhe(_,f,W_);EX(G)&&(G=G.reverse());const U=e.ofPolygons([G]);i.push(U);const Y=t.extrude(U,D*1.05,0,0,[1,1],!0);i.push(Y);let q=H.subtract(Y);if(i.push(q),d.ccw_rotation){const ie=q.rotate([0,0,d.ccw_rotation]);i.push(ie),q=ie}const ee=q.translate([d.x,d.y,0]);i.push(ee);let W=ee;if(r){const ie=t.intersection([ee,r]);i.push(ie),W=ie}c.push(W);const J=oP(W.getMesh());A.push({key:`ph-${d.pcb_plated_hole_id||m}`,geometry:J,color:xR})}else if(d.shape==="circular_hole_with_rect_pad"){if(d.hole_shape&&d.hole_shape!=="circle"||d.pad_shape&&d.pad_shape!=="rect")return;const _=d.hole_offset_x||0,f=d.hole_offset_y||0,I=eon({Manifold:t,x:d.x+_,y:d.y+f,diameter:d.hole_diameter,thickness:o,segments:W_});i.push(I),s.push(I);const C=d.rect_pad_width??d.hole_diameter,y=d.rect_pad_height??d.hole_diameter,x=w9(d),E=BX,B=d.hole_diameter/2,b=yR({Manifold:t,width:C,height:y,thickness:Math.max(o-2*(E+SX+bX),ms),borderRadius:x});i.push(b);const Q=t.cylinder(o*.8,B,B,W_,!0).translate([_,f,0]);i.push(Q);const w=t.union([b,Q]);i.push(w);const D=t.cylinder(o*1.2,Math.max(B-ms,.01),Math.max(B-ms,.01),W_,!0).translate([_,f,0]);i.push(D);const k=w.subtract(D);i.push(k);const T=k.translate([d.x,d.y,0]);i.push(T);let H=T;if(r){const U=t.intersection([T,r]);i.push(U),H=U}c.push(H);const G=oP(H.getMesh());A.push({key:`ph-${d.pcb_plated_hole_id||m}`,geometry:G,color:xR})}});let h;return c.length>0&&(h=t.union(c),i.push(h)),{platedHoleBoardDrills:s,platedHoleCopperGeoms:A,platedHoleSubtractOp:h}}function aIi({Manifold:t,x:e,y:n,outerDiameter:o,holeDiameter:i,thickness:r,zOffset:s=.001,segments:a=32}){const A=s;if(o<i)throw new Error(`Invalid via geometry: outerDiameter (${o}) must be >= holeDiameter (${i})`);const c=Math.min(o/2,i/2+A),g=t.cylinder(r,c,-1,a,!0),u=r+2*s,h=t.cylinder(u,i/2,-1,a,!0);return g.subtract(h).translate([e,n,0])}var AIi=new Yi(...Yc.copper);function cIi(t,e,n,o,i){const r=[],s=Cr(e).pcb_via.list(),a=[];return s.forEach((A,c)=>{if(typeof A.hole_diameter=="number"){const l=ton({Manifold:t,x:A.x,y:A.y,holeDiameter:A.hole_diameter,thickness:n,zOffset:vQ,segments:W_});o.push(l),r.push(l)}if(typeof A.outer_diameter=="number"&&typeof A.hole_diameter=="number"){const l=aIi({Manifold:t,x:A.x,y:A.y,outerDiameter:A.outer_diameter,holeDiameter:A.hole_diameter,thickness:n,zOffset:vQ,segments:W_});o.push(l);let g=l;if(i){const h=t.intersection([l,i]);o.push(h),g=h}const u=oP(g.getMesh());a.push({key:`via-${A.pcb_via_id||c}`,geometry:u,color:AIi})}}),{viaBoardDrills:r,viaCopperGeoms:a}}var lIi=(t,e,n)=>{const[o,i]=te.useState(null),[r,s]=te.useState(null),[a,A]=te.useState(null),[c,l]=te.useState(!0),g=te.useRef([]),u=te.useMemo(()=>{const p=e.filter(I=>I.type==="pcb_panel"),_=Cr(e).pcb_board.list();if(p.length>0){const I=p[0],C=_.find(y=>y.pcb_panel_id===I.pcb_panel_id);return{type:"pcb_board",pcb_board_id:I.pcb_panel_id,center:I.center,width:I.width,height:I.height,thickness:C?.thickness??1.4,material:C?.material??"fr4",num_layers:C?.num_layers??2,solder_mask_color:C?.solder_mask_color}}const f=_.filter(I=>!I.pcb_panel_id);return f.length>0?f[0]:null},[e]),h=te.useMemo(()=>{const p=Cr(e).pcb_board.list();return p.length>0&&p[0].pcb_board_id==="faux-board"},[e]),d=te.useMemo(()=>u?$nn(u,jS):jS,[u]);te.useEffect(()=>{if(!t||!u){i(null),s(null),l(!1);return}if((u.width===0||!u.width)&&(u.height===0||!u.height)&&(!u.outline||u.outline.length<3)){i({platedHoles:[],vias:[]}),s(u.thickness??0),l(!1);return}l(!0),A(null);const p=t.Manifold,_=t.CrossSection,f=y=>{if(!(!y||typeof y.delete!="function"))try{y.delete()}catch(x){(!(x instanceof Error)||!x.message?.includes("Manifold instance already deleted"))&&console.warn("Failed to delete Manifold instance",x)}};g.current.forEach(f),g.current=[];let I=null;const C={};try{const y=u.thickness||1.4;s(y);const{boardOp:x,outlineCrossSection:E}=tIi(p,_,u,y,g.current);let B=x;const Q=y+2*1;let w=null;const D=.01;if(E){let J=E;if(D>0){const oe=E.offset(D);g.current.push(oe),J=oe}const ie=p.extrude(J,Q,void 0,void 0,void 0,!0);g.current.push(ie),w=ie}else{const J=(u.width||0)+2*D,ie=(u.height||0)+2*D,oe=p.cube([J,ie,Q],!0);g.current.push(oe);const ne=oe.translate([u.center.x,u.center.y,0]);g.current.push(ne),w=ne}const k=[];let T=null;const{nonPlatedHoleBoardDrills:H}=rIi(p,_,e,y,g.current);k.push(...H);const{platedHoleBoardDrills:G,platedHoleCopperGeoms:U,platedHoleSubtractOp:Y}=sIi(p,_,e,y,g.current,w);k.push(...G),C.platedHoles=U;const{viaBoardDrills:q,viaCopperGeoms:ee}=cIi(p,e,y,g.current,w);if(k.push(...q),C.vias=ee,k.length>0){T=p.union(k),g.current.push(T);const J=Y?p.union([T,Y]):T;g.current.push(J);const ie=B.subtract(J);if(g.current.push(ie),B=ie,Y){const oe=Y.subtract(T);g.current.push(oe);const ne=oe.getMesh(),le=oP(ne);C.platedHoles=[{key:"plated-holes-union",geometry:le,color:new Yi(Yc.copper[0],Yc.copper[1],Yc.copper[2])}]}}const{cutoutOps:W}=iIi(p,_,e,y,g.current);if(W.length>0){const J=p.union(W);g.current.push(J);const ie=B.subtract(J);g.current.push(ie),B=ie}if(I=B,I){const J=I.getMesh(),ie=oP(J);C.board={geometry:ie,color:qUe(u),material:u.material,isFaux:h}}i(C)}catch(y){console.error("Error processing geometry with Manifold in hook:",y),A(y.message||"An unknown error occurred while processing geometry in hook."),i(null)}finally{l(!1)}return()=>{g.current.forEach(f),g.current=[]}},[t,e,u]);const m=te.useMemo(()=>!u||!d?null:znn({circuitJson:e,boardData:u,traceTextureResolution:d,visibility:n}),[e,u,d,n]);return{geoms:o,textures:m,pcbThickness:r,error:a,isLoading:c,boardData:u,isFauxBoard:h}},gIi=O_,uIi=({material:t,color:e,side:n=gIi,isFaux:o=!1})=>t==="fr4"?new eB({color:e,side:n,metalness:0,roughness:.48,specularIntensity:.3,ior:1.45,sheen:0,clearcoat:.16,clearcoatRoughness:.3,transparent:o,opacity:o?xhe:1,flatShading:!0,polygonOffset:!0,polygonOffsetFactor:1,polygonOffsetUnits:1}):new pu({color:e,side:n,flatShading:!0,metalness:.1,roughness:.8,transparent:!0,opacity:o?xhe:.9,polygonOffset:!0,polygonOffsetFactor:1,polygonOffsetUnits:1});function dIi(t){const e=[];if(!t)return e;if(t.board?.geometry){const o=new Dr(t.board.geometry,uIi({material:t.board.material,color:t.board.color,side:O_,isFaux:t.board.isFaux}));o.name="board-geom",QQ(o,{castShadow:!1,receiveShadow:!0}),e.push(o)}const n=o=>{if(o)for(const i of o){const r=new Dr(i.geometry,new pu({color:i.color,side:O_,flatShading:!0}));r.name=i.key,QQ(r),e.push(r)}};return n(t.platedHoles),n(t.vias),e}var hIi=({geometryMeshes:t,textureMeshes:e})=>{const{rootObject:n}=jI(),{visibility:o}=pR(),i=r=>{r.geometry.dispose();const s=Array.isArray(r.material)?r.material:[r.material];for(const a of s){if(!a)continue;const A=["map","alphaMap","aoMap","bumpMap","displacementMap","emissiveMap","lightMap","metalnessMap","normalMap","roughnessMap","specularMap"],c=a;for(const l of A){const g=c[l];g&&g instanceof Bd&&g.dispose()}a.dispose()}};return te.useEffect(()=>{if(n){for(const r of t){let s=!0;r.name==="board-geom"?s=o.boardBody:(r.name.includes("plated_hole")||r.name.includes("via"))&&(s=o.topCopper||o.bottomCopper),s&&n.add(r)}return()=>{for(const r of t)r.parent===n&&n.remove(r),i(r)}}},[n,t,o]),te.useEffect(()=>{if(n){for(const r of e)n.add(r);return()=>{for(const r of e)r.parent===n&&n.remove(r),i(r)}}},[n,e]),null},mIi="https://cdn.jsdelivr.net/npm/manifold-3d@3.2.1",pIi=({circuitJson:t,autoRotateDisabled:e,clickToInteractEnabled:n,onUserInteraction:o,children:i,onCameraControllerReady:r,resolveStaticAsset:s,referenceObject:a})=>{const A=Nnn(i),c=te.useMemo(()=>Znn(t??A),[t,A]),[l,g]=te.useState(null),[u,h]=te.useState(null),{visibility:d}=pR();te.useEffect(()=>{if(window.ManifoldModule&&typeof window.ManifoldModule=="object"&&window.ManifoldModule.setup){g(window.ManifoldModule);return}const D=async Y=>{try{const q=await Y();q.setup(),window.ManifoldModule=q,g(q)}catch(q){console.error("Failed to initialize Manifold:",q),h(`Failed to initialize Manifold: ${q instanceof Error?q.message:"Unknown error"}`)}},k=window.ManifoldModule??window.MANIFOLD??window.MANIFOLD_MODULE;if(k){window.ManifoldModule=k,D(window.ManifoldModule);return}const T="manifoldLoaded",H=()=>{const Y=window.ManifoldModule??window.MANIFOLD??window.MANIFOLD_MODULE;if(Y)window.ManifoldModule=Y,D(window.ManifoldModule);else{const q="ManifoldModule not found on window after script load.";console.error(q),h(q)}};window.addEventListener(T,H,{once:!0});const G=document.createElement("script");G.type="module",G.innerHTML=`
|
|
5517
|
+
`,Opi=({rotation:t,infiniteGrid:e,cellSize:n=1,sectionSize:o=10})=>{const{scene:i,camera:r}=jI(),s=1e3,a=te.useMemo(()=>{const A=new BQ(s,s);A.rotateX(-Math.PI/2);const c=new Kv({vertexShader:Lpi,fragmentShader:Hpi,uniforms:{cellSize:{value:n},sectionSize:{value:o},gridColor:{value:new Yi(15658734)},sectionColor:{value:new Yi(13421823)},fadeDistance:{value:100},fadeStrength:{value:1.5}},transparent:!0,side:O_}),l=new Dr(A,c);return t&&l.rotation.fromArray(t),l},[s,n,o,t]);return nX(()=>{e&&a.position.set(r.position.x,r.position.y,0)}),te.useEffect(()=>{if(!(!i||!a))return i.add(a),()=>{i.remove(a),a.geometry.dispose(),Array.isArray(a.material)?a.material.forEach(A=>A.dispose()):a.material.dispose()}},[i,a]),null},zUe=.75,Gpi=({boardDimensions:t,boardCenter:e,darkBackgroundEnabled:n=!1,shadowsEnabled:o=!1})=>{const{scene:i}=jI(),r=te.useMemo(()=>{const s=new w0;s.name="cad-viewer-light-rig";const a=e?.x??0,A=e?.y??0,c=Math.max(t?.width??0,t?.height??0,20),l=c*.8,g=c,u=c*1.7,h=new MYt(16186360,.22);h.name="cad-viewer-soft-ambient",s.add(h);const d=new TJo(15004141,1581597,.2);d.name="cad-viewer-hemisphere",s.add(d);const m=(p,_,f,I,C=!1)=>{const y=new wYt(_,f);if(y.name=p,y.position.set(a+I[0],A+I[1],I[2]),y.target.position.set(a,A,0),y.castShadow=C,C){y.shadow.mapSize.set(2048,2048),y.shadow.bias=-2e-4,y.shadow.normalBias=.03,y.shadow.radius=5;const x=y.shadow.camera;x.left=-l,x.right=l,x.top=l,x.bottom=-l,x.near=.5,x.far=Math.max(c*4,Math.hypot(...I)+c*2),x.updateProjectionMatrix()}s.add(y),s.add(y.target)};return m("cad-viewer-key-light",16775406,1.35,[u*.68,-u*.8,u*1.08],o),m("cad-viewer-fill-light",14477554,.25,[-g*.85,g*.55,g*.75]),m("cad-viewer-rim-light",12184275,.5,[-g*.35,g*.85,g*.95]),m("cad-viewer-underside-key-light",16775406,1.35*zUe,[u*.68,-u*.8,-u*1.08]),m("cad-viewer-underside-fill-light",14477554,.25*zUe,[-g*.85,g*.55,-g*.75]),m("cad-viewer-underside-rim-light",12184275,.5*zUe,[-g*.35,g*.85,-g*.95]),s},[e,t,o]);return te.useEffect(()=>{const s=i.background,a=i.environment;return i.background=n?new Yi(1053456):null,i.environment=null,()=>{i.background=s,i.environment=a}},[n,i]),te.useEffect(()=>{if(i)return i.add(r),()=>{i.remove(r)}},[i,r]),null},Ypi=({autoRotate:t,autoRotateSpeed:e,onStart:n,panSpeed:o,rotateSpeed:i,zoomSpeed:r,enableDamping:s,dampingFactor:a,target:A,onControlsChange:c})=>{const{camera:l,renderer:g}=jI(),u=te.useMemo(()=>!l||!g?null:new Cjo(l,g.domElement),[l,g]);return te.useEffect(()=>(c?.(u??null),()=>c?.(null)),[u,c]),te.useEffect(()=>{if(!u)return;const h=()=>{c?.(u)};return u.addEventListener("change",h),()=>{u.removeEventListener("change",h)}},[u,c]),te.useEffect(()=>{u&&(u.autoRotate=t||!1,u.autoRotateSpeed=e||1,o!==void 0&&(u.panSpeed=o),i!==void 0&&(u.rotateSpeed=i),r!==void 0&&(u.zoomSpeed=r),s!==void 0&&(u.enableDamping=s),a!==void 0&&(u.dampingFactor=a),u.zoomToCursor=!0,u.mouseButtons={LEFT:o9.ROTATE,MIDDLE:o9.PAN,RIGHT:null},A&&(u.target.set(A[0],A[1],A[2]),u.update()))},[u,t,e,o,i,r,s,a,A]),te.useEffect(()=>{if(!(!u||!n))return u.addEventListener("start",n),()=>{u.removeEventListener("start",n)}},[u,n]),te.useEffect(()=>{if(u)return()=>{u.dispose()}},[u]),nX(()=>{u?.update()},[u]),null},Upi=10,VG={banana:{type:"banana",label:"Show Banana",width:190,height:60,depth:34,zCenter:17},"credit-card":{type:"credit-card",label:"Show Credit Card",width:85.6,height:53.98,depth:.76,zCenter:0},"14in-macbook":{type:"14in-macbook",label:"Show 14in Macbook",width:312.6,height:221.2,depth:15.5,zCenter:0}},Kpi=Object.values(VG),Vpi=[{type:null,label:"None"},...Kpi],zpi=(t,e)=>t===e?null:e,JUe=t=>Number.isFinite(t)?Math.max(t??0,0):0,yhe=t=>Number.isFinite(t)?t??0:0,Pnn=(t,e,n)=>{const o=VG[t],i=JUe(e?.width),r=yhe(n?.x),s=yhe(n?.y);return{x:r+i/2+Upi+o.width/2,y:s,z:0}},Jpi=(t,e,n)=>{const o=VG[t],i=JUe(e?.width),r=JUe(e?.height),s=yhe(n?.x),a=yhe(n?.y),A=Pnn(t,e,n);return{minX:Math.min(s-i/2,A.x-o.width/2),maxX:Math.max(s+i/2,A.x+o.width/2),minY:Math.min(a-r/2,A.y-o.height/2),maxY:Math.max(a+r/2,A.y+o.height/2),minZ:Math.min(0,A.z+o.zCenter-o.depth/2),maxZ:Math.max(0,A.z+o.zCenter+o.depth/2)}};function Wpi(t,e){const n=new M1().setFromEuler(new D1(t.x,t.y,t.z)),o=new jt(0,0,1);return o.applyQuaternion(n),o.multiplyScalar(e)}var jpi=()=>{const{mainCameraRef:t}=RM(),e=te.useRef(null);return te.useEffect(()=>{if(!e.current)return;const n=e.current,o=document.createElement("canvas");n.appendChild(o);const i=new zue({canvas:o,antialias:!0,alpha:!0});i.setSize(120,120),i.setPixelRatio(window.devicePixelRatio);const r=new $N,s=new Y_(75,1,.1,1e3);s.up.set(0,0,1);const a=new MYt(16777215,Math.PI/2);r.add(a);const A=new w0;A.rotation.fromArray([Math.PI/2,0,0]);const c=1,l=new Dr(new fE(c,c,c),new pu({color:"white"}));A.add(l);const g=new uq(new oJo(new fE(c,c,c)),new ZN({color:0,linewidth:2}));A.add(g),r.add(A);const u=.51,h=(x,E,B)=>{const b=new nRe;return b.text=x,b.position.fromArray(E),B&&b.rotation.fromArray(B),b.color="black",b.fontSize=.25,b.anchorX="center",b.anchorY="middle",b.depthOffset=0,b.font=null,b.sync(),b},d=h("Front",[0,0,u]),m=h("Back",[0,0,-u],[0,Math.PI,0]),p=h("Right",[u,0,0],[0,Math.PI/2,0]),_=h("Left",[-u,0,0],[0,-Math.PI/2,0]),f=h("Top",[0,u,0],[-Math.PI/2,0,0]),I=h("Bottom",[0,-u,0],[Math.PI/2,0,0]);A.add(d),A.add(m),A.add(p),A.add(_),A.add(f),A.add(I);let C=null;const y=()=>{if(t.current){const x=Wpi(t.current.rotation??new D1(0,0,0),2);x.equals(s.position)||(s.position.copy(x),s.lookAt(0,0,0))}i.render(r,s),C=requestAnimationFrame(y)};return y(),()=>{o.remove(),C!==null&&cancelAnimationFrame(C),d.dispose(),m.dispose(),p.dispose(),_.dispose(),f.dispose(),I.dispose(),l.geometry.dispose(),l.material.dispose(),g.geometry.dispose(),g.material.dispose(),r.clear(),i.dispose(),i.forceContextLoss()}},[t]),K.jsx("div",{ref:e,style:{position:"absolute",top:0,left:0,width:120,height:120,zIndex:oX.orientationCube}})},wnn=(t,e,n)=>{const o=t/2,i=e/2,r=Math.min(n,o,i),s=new mYt;return s.moveTo(-o+r,-i),s.lineTo(o-r,-i),s.quadraticCurveTo(o,-i,o,-i+r),s.lineTo(o,i-r),s.quadraticCurveTo(o,i,o-r,i),s.lineTo(-o+r,i),s.quadraticCurveTo(-o,i,-o,i-r),s.lineTo(-o,-i+r),s.quadraticCurveTo(-o,-i,-o+r,-i),s},WUe=(t,e,n,o)=>Mnn(wnn(t,e,o),n),Mnn=(t,e)=>{const n=new SNe(t,{depth:e,bevelEnabled:!1,curveSegments:24});return n.translate(0,0,-e/2),n.computeVertexNormals(),n},qpi=(t,e)=>{const n=VG[e];t.updateMatrixWorld(!0);const i=new pE().setFromObject(t).getSize(new jt);t.scale.set(n.width/i.x,n.height/i.y,n.depth/i.z),t.updateMatrixWorld(!0);const s=new pE().setFromObject(t).getCenter(new jt);t.position.set(-s.x,-s.y,n.zCenter-s.z),t.updateMatrixWorld(!0)},Xpi=()=>{const t=new cYt([new jt(-82,18,16),new jt(-67,7,15),new jt(-43,-9,14),new jt(-15,-18,14),new jt(16,-18,14),new jt(47,-8,14.5),new jt(72,8,16),new jt(84,19,17)]),e=84,n=30,o=t.computeFrenetFrames(e,!1),i=[],r=[],s=[],a=[],A=[],c=new Yi(16766023),l=new Yi(12038965);for(let u=0;u<=e;u++){const h=u/e,d=t.getPointAt(h),m=o.normals[u],p=o.binormals[u],f=3.4+12.4*Math.sin(Math.PI*h)**.48,I=Math.max(0,(h-.82)/.18)*.38,C=c.clone().lerp(l,I);for(let y=0;y<=n;y++){const x=y/n*Math.PI*2,E=Math.sin(x),B=Math.cos(x),b=1+Math.cos(x*5+.35)*.035,Q=new jt().addScaledVector(m,B).addScaledVector(p,E*.9).normalize(),w=d.clone().addScaledVector(m,B*f*b).addScaledVector(p,E*f*.9*b);i.push(w.x,w.y,w.z),r.push(Q.x,Q.y,Q.z),s.push(C.r,C.g,C.b),a.push(h,y/n)}}for(let u=1;u<=e;u++)for(let h=1;h<=n;h++){const d=n+1,m=d*(u-1)+(h-1),p=d*u+(h-1),_=d*u+h,f=d*(u-1)+h;A.push(m,f,p,p,f,_)}const g=new tg;return g.setIndex(A),g.setAttribute("position",new Ds(i,3)),g.setAttribute("normal",new Ds(r,3)),g.setAttribute("color",new Ds(s,3)),g.setAttribute("uv",new Ds(a,2)),g.computeBoundingBox(),g.computeBoundingSphere(),{geometry:g,curve:t}},$pi=()=>{const t=new w0,e=new w0,{geometry:n,curve:o}=Xpi(),i=new Dr(n,new pu({color:16777215,roughness:.72,metalness:0,vertexColors:!0}));i.name="banana-peel",e.add(i);const r=new Dr(new nR(3.4,20,12),new pu({color:6242844,roughness:.92}));r.position.copy(o.getPointAt(0)),r.scale.set(1.15,.78,.78),r.name="banana-blossom-tip",e.add(r);const s=11,a=o.getTangentAt(1).normalize(),A=new Dr(new aG(2.5,4.1,s,18),new pu({color:8483625,roughness:.82}));A.quaternion.setFromUnitVectors(new jt(0,1,0),a),A.position.copy(o.getPointAt(1)).addScaledVector(a,s/2),A.name="banana-stem",e.add(A);const c=new Dr(new nR(2.55,18,10),new pu({color:5981470,roughness:.9}));return c.position.copy(o.getPointAt(1)).addScaledVector(a,s),c.name="banana-stem-tip",e.add(c),qpi(e,"banana"),t.add(e),t},Zpi=(t,e,n,o,i)=>{const r=wnn(t,e,o),s=new CNe;return s.absarc(0,0,i,0,Math.PI*2,!0),r.holes.push(s),Mnn(r,n)},e_i=(t,e)=>{const i=new Dr(new aG(e-.15,e-.15,.25,48),new pu({color:10199202,roughness:.48,metalness:.28}));return i.rotation.x=Math.PI/2,i.position.z=t-.35-.25/2,i.name="macbook-lid-indent",i},t_i=()=>{const t=VG["credit-card"],e=new w0,n=new Dr(WUe(t.width,t.height,t.depth,3.18),new pu({color:2383272,roughness:.38,metalness:.08}));n.name="credit-card-body",e.add(n);const o=t.depth/2+.08,i=new Dr(WUe(12,9,.14,1.2),new pu({color:14003525,roughness:.3,metalness:.62}));i.position.set(-21,3,o),i.name="credit-card-chip",e.add(i);const r=new pu({color:15331061,roughness:.45,metalness:.05});for(let s=0;s<4;s++){const a=new Dr(new fE(s===3?8:12,.8,.1),r);a.position.set(-20+s*14,-14,o+.08),a.name="credit-card-detail",e.add(a)}return e},n_i=()=>{const t=VG["14in-macbook"],e=new w0,n=new pu({color:12896201,roughness:.3,metalness:.38}),o=new Dr(WUe(t.width,t.height,13.5,9),n);o.position.z=-1,o.name="macbook-body",e.add(o);const i=2,r=6.75,s=r+i/2,a=12,A=new Dr(Zpi(t.width-1.8,t.height-1.8,i,8.2,a),n.clone());A.position.z=r,A.name="macbook-lid",e.add(A);const c=new Dr(new fE(t.width-42,3.2,1.2),new pu({color:3158838,roughness:.55,metalness:.45}));c.position.set(0,t.height/2-2.4,6.15),c.name="macbook-hinge",e.add(c),e.add(e_i(s,a));const l=new Dr(new fE(54,1.2,.8),new pu({color:6712174,roughness:.45,metalness:.5}));return l.position.set(0,-221.2/2+.5,2.5),l.name="macbook-front-notch",e.add(l),e},o_i=t=>{const e=t==="banana"?$pi():t==="credit-card"?t_i():n_i();return e.name=`reference-object-${t}`,e.userData.isReferenceObject=!0,e.userData.referenceObjectType=t,QQ(e),e},i_i=t=>{const e=new Set,n=new Set;t.traverse(o=>{if(!(o instanceof Dr))return;e.add(o.geometry);const i=Array.isArray(o.material)?o.material:[o.material];for(const r of i)n.add(r)});for(const o of e)o.dispose();for(const o of n)o.dispose()},r_i=(t,e,n,o=1.18)=>{const i=Math.max(n.maxX-n.minX,0),r=Math.max(n.maxY-n.minY,0),s=Math.max(n.maxZ-n.minZ,0),a=new jt((n.minX+n.maxX)/2,(n.minY+n.maxY)/2,(n.minZ+n.maxZ)/2),A=Math.max(Math.hypot(i,r,s)/2,1),c=e?.target??new jt,l=new jt(0,-.75,.9).normalize();let g=Math.max(t.position.distanceTo(c),5);if(t instanceof Y_){const u=FO.degToRad(t.fov),h=2*Math.atan(Math.tan(u/2)*t.aspect),d=Math.min(u,h);g=A*o/Math.sin(d/2),t.far=Math.max(t.far,g+A*o*3),t.updateProjectionMatrix()}else if(t instanceof nG){const u=Math.abs(t.right-t.left)/2,h=Math.abs(t.top-t.bottom)/2;t.zoom=Math.min(u/(A*o),h/(A*o)),g=Math.max(g,A*o*2),t.updateProjectionMatrix()}return t.position.copy(a).addScaledVector(l,g),t.lookAt(a),t.updateMatrixWorld(),e&&(e.target.copy(a),e.update()),{center:a,radius:A,distance:g}},s_i=({type:t,boardDimensions:e,boardCenter:n})=>{const{scene:o}=jI(),i=te.useMemo(()=>{const r=o_i(t),s=Pnn(t,e,n);return r.position.set(s.x,s.y,s.z),r},[t,e,n]);return te.useEffect(()=>(o.add(i),()=>{o.remove(i),i_i(i)}),[o,i]),null},a_i=({bounds:t})=>{const{camera:e}=jI(),{controlsRef:n}=RM();return te.useEffect(()=>{r_i(e,n.current,t)},[t,e,n]),null},A_i=()=>{const{camera:t}=jI(),{setCameraRotation:e}=RM();return nX(()=>{t&&e(t.rotation)}),null},Dnn=te.forwardRef(({children:t,initialCameraPosition:e=[5,-5,5],autoRotateDisabled:n,clickToInteractEnabled:o=!1,boardDimensions:i,boardCenter:r,referenceObject:s,onUserInteraction:a,onCameraControllerReady:A},c)=>{const[l,g]=te.useState(!o),{mainCameraRef:u,handleControlsChange:h,controller:d}=RM(),{darkBackgroundEnabled:m,gridEnabled:p,lightingEnabled:_}=KUe(),{handleCameraCreated:f,handleControlsChange:I}=Rpi();te.useEffect(()=>{A&&A(d)},[d,A]);const C=te.useMemo(()=>{if(s)return Jpi(s,i,r)},[s,i,r]),y=te.useMemo(()=>{if(!i)return 10;const E=i.width??0,B=i.height??0;return Math.max(Math.max(E,B)*1.5,10)},[i]),x=te.useMemo(()=>{if(C)return[(C.minX+C.maxX)/2,(C.minY+C.maxY)/2,(C.minZ+C.maxZ)/2];if(r)return[r.x,r.y,0]},[r,C]);return K.jsxs("div",{style:{position:"relative",width:"100%",height:"100%"},children:[K.jsx(jpi,{}),K.jsxs(Fpi,{ref:c,scene:{up:new jt(0,0,1)},camera:{up:[0,0,1],position:e},onCreated:({camera:E})=>{u.current=E,f(E)},children:[K.jsx(Npi,{}),K.jsx(A_i,{}),l&&K.jsx(Ypi,{autoRotate:!n,autoRotateSpeed:1,onStart:a,rotateSpeed:.5,panSpeed:.75,zoomSpeed:.5,enableDamping:!0,dampingFactor:.1,target:x,onControlsChange:E=>{h(E),I()}}),K.jsx(Gpi,{boardDimensions:i,boardCenter:r,darkBackgroundEnabled:m,shadowsEnabled:_}),s&&K.jsx(s_i,{type:s,boardDimensions:i,boardCenter:r}),C&&K.jsx(a_i,{bounds:C}),p&&K.jsx(Opi,{rotation:[Math.PI/2,0,0],infiniteGrid:!0,cellSize:3,sectionSize:y}),t]}),K.jsxs("div",{style:{position:"absolute",right:24,bottom:24,fontFamily:"sans-serif",color:"white",WebkitTextStroke:"0.5px rgba(0, 0, 0, 0.5)",fontSize:11},children:["@",Enn.version]}),o&&!l&&K.jsx("button",{type:"button",onClick:()=>g(!0),onKeyDown:E=>{(E.key==="Enter"||E.key===" ")&&g(!0)},style:{position:"absolute",inset:0,cursor:"pointer",zIndex:oX.clickToInteractOverlay,display:"flex",alignItems:"center",justifyContent:"center"},children:K.jsx("div",{style:{backgroundColor:"rgba(0, 0, 0, 0.8)",color:"white",padding:"12px 24px",borderRadius:"8px",fontSize:"16px",fontFamily:"sans-serif",pointerEvents:"none"},children:"Click to Interact"})})]})}),Nnn=t=>te.useMemo(()=>{if(!t)return[];const e=new S7o;return e.add(t),e.render(),e.getCircuitJson()},[t]),c_i=t=>{const[e,n]=te.useState([]),[o,i]=te.useState(!0);return te.useEffect(()=>{if(!t)return;(async()=>{i(!0);const a=(Array.isArray(t)?t:[t]).map(async(A,c)=>{const l=fti.serialize({binary:!0},[A]),u=await new Blob(l).arrayBuffer(),d=A.layerType||(c===0?"board":void 0);return{stlData:u,color:A.color,layerType:d}});try{const A=await Promise.all(a);n(A)}catch(A){console.error("Error generating STLs:",A),n([])}finally{i(!1)}})()},[t]),{stls:e,loading:o}},l_i=ng(Xde()),g_i=ng(hR()),u_i=ng(tX()),d_i=ng(hR()),h_i=ng(mR()),m_i=ng(Uen()),Rnn=t=>{let e=0;for(let o=0;o<t.length;o++){const i=(o+1)%t.length;e+=t[o][0]*t[i][1],e-=t[i][0]*t[o][1]}return e/2<=0},jUe=(t,e=1.2,n={})=>{const{xyOutset:o=0}=n,{outline:i}=t;let r=i.map(A=>[A.x,A.y]);Rnn(r)&&(r=r.reverse());let s=(0,d_i.polygon)({points:r});o!==0&&(s=(0,m_i.expand)({delta:o,corners:"edge"},s));let a=(0,u_i.extrudeLinear)({height:e},s);return a=(0,h_i.translate)([0,0,-e/2],a),a},ms=.01,Yc={copper:[.78,.63,.39],fr4Tan:[.6,.43,.28],fr4SolderMaskGreen:[.06,.31,.19],fr4TracesWithMaskGreen:[.09,.38,.23],fr4TracesWithoutMaskTan:[.6,.43,.28],fr1Tan:[.8,.4,.2],fr1TracesWithMaskCopper:[.9,.6,.2],fr1SolderMaskGreen:[.02,.1,.04]},vQ=.001,W_=32,jS=150,xhe=.6,p_i={fr1:Yc.fr1Tan,fr4:Yc.fr4Tan},__i={fr1:Yc.fr1SolderMaskGreen,fr4:Yc.fr4SolderMaskGreen},f_i={red:"#650202",blue:"#003f7d",purple:"#4c1d69",black:"#071014",white:"#dddddd",yellow:"#dcc84a"},I_i=.875,C_i=/^#(?:[\da-f]{3}|[\da-f]{6})$/i,y_i=/^rgb\(\s*\d+\s*,\s*\d+\s*,\s*\d+\s*\)$/i,x_i=/^rgb\(\s*\d+%\s*,\s*\d+%\s*,\s*\d+%\s*\)$/i,E_i=/^hsl\(\s*\d*\.?\d+\s*,\s*\d*\.?\d+%\s*,\s*\d*\.?\d+%\s*\)$/i,B_i={blue:.96,purple:.96,black:.99,yellow:.92},Tnn=t=>{const e=t?.trim();if(!e)return null;const n=e.toLowerCase();if(n==="green"||n==="not_specified")return null;const i=f_i[n];return i?new Yi(i):Object.hasOwn(Yi.NAMES,n)||C_i.test(e)||y_i.test(e)||x_i.test(e)||E_i.test(e)?new Yi(n):null},S_i=t=>{const e=t?.trim().toLowerCase();return B_i[e]??I_i},b_i=({red:t,green:e,blue:n})=>Math.hypot(t-220,e-200,n-74)<4||Math.hypot(t-218,e-197,n-76)<4,Q_i=({soldermaskColor:t,copperColor:e,soldermaskOpacity:n})=>t.clone().multiplyScalar(n).add(e.clone().multiplyScalar(1-n)),knn=t=>{const e=t.clone().convertLinearToSRGB();return`rgb(${[Math.round(e.r*255),Math.round(e.g*255),Math.round(e.b*255)].join(",")})`},v_i=new Yi(1063462),qUe=({material:t,solder_mask_color:e})=>{const n=Tnn(e);if(n)return n;if(t==="fr4")return v_i.clone();const o=p_i[t]??Yc.fr4Tan;return new Yi(o[0],o[1],o[2])},P_i=t=>{const e=t.filter(A=>A.type==="pcb_panel"),n=Cr(t).pcb_board.list();let o,i,r=1.2;if(e.length>0)o=e[0],i=n.find(A=>A.pcb_panel_id===o.pcb_panel_id),r=i?.thickness??1.2;else{if(o=n.filter(c=>!c.pcb_panel_id)[0],!o)return console.warn("No pcb_board or pcb_panel found for simplified geometry"),[];i=o,r=o.thickness??1.2}let s;"outline"in o&&o.outline&&o.outline.length>0?s=jUe({outline:o.outline},r):s=(0,g_i.cuboid)({size:[o.width??10,o.height??10,r],center:[o.center.x,o.center.y,0]});const a=qUe({material:i?.material??"fr4",solder_mask_color:i?.solder_mask_color});return[(0,l_i.colorize)([a.r,a.g,a.b],s)]},IX=ng(Xde()),Uf=ng(eX()),XUe=ng(tX()),xE=ng(mR()),Gu=ng(hR()),P9=ng(hR()),w_i=ng(tX()),Ehe=ng(mR()),M_i=ng(eX()),D_i=64,N_i=(t,e,n)=>{const o=(0,P9.ellipse)({center:[0,0],radius:[Math.max(t/2,ms/2),Math.max(e/2,ms/2)],segments:D_i}),i=(0,w_i.extrudeLinear)({height:n},o);return(0,Ehe.translate)([0,0,-n/2],i)},R_i=(t,e,n)=>{const o=Math.max(t,ms),i=Math.max(e,ms);if(Math.abs(o-i)<1e-6)return(0,P9.cylinder)({center:[0,0,0],radius:o/2,height:n});const r=o>=i,s=r?o:i,a=r?i:o,A=Math.max(s-a,0),c=(0,P9.cuboid)({center:[0,0,0],size:r?[A,a,n]:[a,A,n]});if(A<=1e-6)return(0,P9.cylinder)({center:[0,0,0],radius:a/2,height:n});const l=A/2,g=(0,P9.cylinder)({center:r?[-l,0,0]:[0,-l,0],radius:a/2,height:n}),u=(0,P9.cylinder)({center:r?[l,0,0]:[0,l,0],radius:a/2,height:n});return(0,M_i.union)(c,g,u)},Bhe=(t,e,n={})=>{const o=t.hole_shape||"circle",i=n.sizeDelta??0,r=t.hole_offset_x||0,s=t.hole_offset_y||0,a=[t.x+r,t.y+s,0];if(o==="circle"){const h=Math.max((t.hole_diameter??0)+i,ms),d=Math.max(h/2,ms/2);return(0,P9.cylinder)({center:a,radius:d,height:e})}const A=t.hole_width??t.hole_diameter,c=t.hole_height??t.hole_diameter;if(!A||!c)return null;const l=Math.max(A+i,ms),g=Math.max(c+i,ms);if(o==="oval"){const h=N_i(l,g,e);return(0,Ehe.translate)([a[0],a[1],0],h)}if(o==="pill"||o==="rotated_pill"){let h=R_i(l,g,e);if(!h)return null;const d=t.ccw_rotation||0;return d&&(h=(0,Ehe.rotateZ)(d*Math.PI/180,h)),(0,Ehe.translate)(a,h)}const u=Math.max((t.hole_diameter??A??c??ms)+i,ms);return(0,P9.cylinder)({center:a,radius:u/2,height:e})},Uc=ng(hR()),nP=ng(Xde()),bd=ng(eX()),Fnn=ng(mR()),She=ng(tX()),EE=ng(mR()),T_i=1e-5;function Lnn(t,e,n){if(typeof n!="number"||!Number.isFinite(n)||n<=0)return 0;const o=t/2,i=e/2,r=Math.min(o,i)-2*T_i;return Math.max(0,Math.min(n,r))}function w9(t){if(!(!t||typeof t!="object"))return t.corner_radius??t.cornerRadius??t.rect_pad_border_radius??t.rectPadBorderRadius??t.rect_border_radius??t.rectBorderRadius??void 0}var k_i=.05,$Ue=64,CR=(t,e)=>e?(0,bd.intersect)(e,t):t,CX=(t,e,n={})=>{const{clipGeom:o}=n;t.shape||(t.shape="circle");const i=Math.max(e.pcbThickness*.002,ms/5),r=Math.max(e.pcbThickness*3e-4,ms/20),s=Math.max(e.pcbThickness*.0025,ms/4),a=e.pcbThickness+2*k_i+4*ms,A=Math.max(e.pcbThickness-2*(i+r+s),ms),c=Math.max(A,ms);if(t.shape==="circle"){const l=t.outer_diameter??Math.max(t.hole_diameter,0),g=A,u=(0,Uc.cylinder)({center:[t.x,t.y,0],radius:l/2,height:g}),h=CR(u,o),d=(0,Uc.cylinder)({center:[t.x,t.y,0],radius:Math.max(t.hole_diameter/2,.01),height:a});return(0,nP.colorize)(Yc.copper,(0,bd.subtract)(h,d))}if(t.shape==="oval"){const l=t.outer_width||t.hole_width||0,g=t.outer_height||t.hole_height||0,u=t.hole_width||0,h=t.hole_height||0,d=(()=>{const _=(0,Uc.cylinder)({center:[0,0,0],radius:1,height:A,segments:64}),f=(0,Fnn.scale)([l/2,g/2,1],_);return(0,EE.translate)([t.x,t.y,0],f)})(),m=CR(d,o),p=(()=>{const _=(0,Uc.cylinder)({center:[0,0,0],radius:1,height:a,segments:64}),f=(0,Fnn.scale)([Math.max(u/2,.01),Math.max(h/2,.01),1],_);return(0,EE.translate)([t.x,t.y,0],f)})();return(0,nP.colorize)(Yc.copper,(0,bd.subtract)(m,p))}if(t.shape==="circular_hole_with_rect_pad"){const l=t.hole_offset_x||0,g=t.hole_offset_y||0,u=t.rect_pad_width||t.hole_diameter,h=t.rect_pad_height||t.hole_diameter,d=w9(t),m=CR((0,bd.union)((()=>{const f=(0,Uc.roundedRectangle)({size:[u,h],roundRadius:d||0,segments:$Ue}),I=(0,She.extrudeLinear)({height:A},f);return(0,EE.translate)([t.x,t.y,-A/2],I)})(),(0,Uc.cylinder)({center:[t.x+(l||0),t.y+(g||0),0],radius:t.hole_diameter/2,height:c})),o),p=(0,Uc.cylinder)({center:[t.x+(l||0),t.y+(g||0),0],radius:Math.max(t.hole_diameter/2-ms,.01),height:a}),_=(0,bd.subtract)(m,p);return n.clipGeom?(0,nP.colorize)(Yc.copper,(0,bd.intersect)(_,n.clipGeom)):(0,nP.colorize)(Yc.copper,_)}if(t.shape==="pill"){const l=(t.ccw_rotation||0)*Math.PI/180,g=D=>{if(!l)return D;const k=(0,EE.translate)([-t.x,-t.y,0],D),T=(0,EE.rotate)([0,0,l],k);return(0,EE.translate)([t.x,t.y,0],T)},u=t.hole_height>t.hole_width,h=u?t.hole_height:t.hole_width,d=u?t.hole_width:t.hole_height,m=u?t.outer_height||d+.2:t.outer_width||h+.2,p=u?t.outer_width||h+.2:t.outer_height||d+.2,_=d/2,f=Math.abs(h-d),y=((D,k,T)=>{const H=k/2,G=Math.abs(D-k);if(G<=1e-6)return(0,Uc.cylinder)({center:[t.x,t.y,0],radius:H,height:T});const U=(0,Uc.cuboid)({center:[t.x,t.y,0],size:u?[k,G,T]:[G,k,T]}),Y=(0,Uc.cylinder)({center:u?[t.x,t.y-G/2,0]:[t.x-G/2,t.y,0],radius:H,height:T}),q=(0,Uc.cylinder)({center:u?[t.x,t.y+G/2,0]:[t.x+G/2,t.y,0],radius:H,height:T});return(0,bd.union)(U,Y,q)})(m,p,A),x=(0,Uc.cuboid)({center:[t.x,t.y,0],size:u?[d-2*ms,f,a]:[f,d-2*ms,a]}),E=(0,Uc.cylinder)({center:u?[t.x,t.y-f/2,0]:[t.x-f/2,t.y,0],radius:_-ms,height:a}),B=(0,Uc.cylinder)({center:u?[t.x,t.y+f/2,0]:[t.x+f/2,t.y,0],radius:_-ms,height:a}),b=(0,bd.union)(x,E,B),Q=CR(g(y),o),w=g(b);return(0,nP.colorize)(Yc.copper,(0,bd.subtract)(Q,w))}if(t.shape==="pill_hole_with_rect_pad"){if(t.hole_shape&&t.hole_shape!=="pill"||t.pad_shape&&t.pad_shape!=="rect")throw new Error("Invalid hole_shape or pad_shape for pill_hole_with_rect_pad");const l=t.hole_offset_x||0,g=t.hole_offset_y||0,u=t.hole_height>t.hole_width,h=u?t.hole_height:t.hole_width,d=u?t.hole_width:t.hole_height,m=d/2,p=Math.abs(h-d),_=t.rect_pad_width||h+.2,f=t.rect_pad_height||d+.2,I=w9(t),C=.03,y=(0,bd.union)((0,Uc.cuboid)({center:[t.x+l,t.y+g,0],size:u?[d+2*C,p+2*C,c]:[p+2*C,d+2*C,c]}),(0,Uc.cylinder)({center:u?[t.x+l,t.y+g-p/2,0]:[t.x+l-p/2,t.y+g,0],radius:m+C,height:c}),(0,Uc.cylinder)({center:u?[t.x+l,t.y+g+p/2,0]:[t.x+l+p/2,t.y+g,0],radius:m+C,height:c})),x=(0,bd.union)((0,Uc.cuboid)({center:[t.x+l,t.y+g,0],size:u?[d,p,a]:[p,d,a]}),(0,Uc.cylinder)({center:u?[t.x+l,t.y+g-p/2,0]:[t.x+l-p/2,t.y+g,0],radius:m,height:a}),(0,Uc.cylinder)({center:u?[t.x+l,t.y+g+p/2,0]:[t.x+l+p/2,t.y+g,0],radius:m,height:a})),E=(()=>{const D=(0,Uc.roundedRectangle)({size:[_,f],roundRadius:I||0,segments:$Ue}),k=(0,She.extrudeLinear)({height:A},D);return(0,EE.translate)([t.x,t.y,-A/2],k)})(),B=(0,bd.subtract)(E,x),b=(0,bd.union)((0,Uc.cuboid)({center:[t.x+l,t.y+g,0],size:u?[d-2*ms,p-2*ms,a]:[p-2*ms,d-2*ms,a]}),(0,Uc.cylinder)({center:u?[t.x+l,t.y+g-p/2,0]:[t.x+l-p/2,t.y+g,0],radius:m-ms,height:a}),(0,Uc.cylinder)({center:u?[t.x+l,t.y+g+p/2,0]:[t.x+l+p/2,t.y+g,0],radius:m-ms,height:a})),Q=(0,bd.subtract)(y,b),w=CR((0,bd.union)(B,Q),o);return(0,nP.colorize)(Yc.copper,w)}else if(t.shape==="rotated_pill_hole_with_rect_pad"){if(t.hole_shape&&t.hole_shape!=="rotated_pill"||t.pad_shape&&t.pad_shape!=="rect")throw new Error("Invalid hole_shape or pad_shape for rotated_pill_hole_with_rect_pad");const l=t.hole_offset_x||0,g=t.hole_offset_y||0,u=t.hole_width,h=t.hole_height,d=u>=h,m=d?u:h,p=d?h:u,_=p/2,f=Math.abs(m-p),I=t.rect_pad_width||u+.2,C=t.rect_pad_height||h+.2,y=w9(t),x=.03,E=(t.hole_ccw_rotation||0)*Math.PI/180,B=(t.rect_ccw_rotation||0)*Math.PI/180,b=Y=>{const q=l*Math.cos(E)-g*Math.sin(E),ee=l*Math.sin(E)+g*Math.cos(E),W=(0,EE.rotate)([0,0,E],Y);return(0,EE.translate)([t.x+q,t.y+ee,0],W)},Q=Y=>{if(!B)return Y;const q=(0,EE.translate)([-t.x,-t.y,0],Y),ee=(0,EE.rotate)([0,0,B],q);return(0,EE.translate)([t.x,t.y,0],ee)},w=b((0,bd.union)((0,Uc.cuboid)({center:[0,0,0],size:d?[f+2*x,p+2*x,c]:[p+2*x,f+2*x,c]}),(0,Uc.cylinder)({center:d?[-f/2,0,0]:[0,-f/2,0],radius:_+x,height:c}),(0,Uc.cylinder)({center:d?[f/2,0,0]:[0,f/2,0],radius:_+x,height:c}))),D=b((0,bd.union)((0,Uc.cuboid)({center:[0,0,0],size:d?[f,p,a]:[p,f,a]}),(0,Uc.cylinder)({center:d?[-f/2,0,0]:[0,-f/2,0],radius:_,height:a}),(0,Uc.cylinder)({center:d?[f/2,0,0]:[0,f/2,0],radius:_,height:a}))),k=Q((()=>{const Y=(0,Uc.roundedRectangle)({size:[I,C],roundRadius:y||0,segments:$Ue}),q=(0,She.extrudeLinear)({height:A},Y);return(0,EE.translate)([t.x,t.y,-A/2],q)})()),T=(0,bd.subtract)(k,D),H=b((0,bd.union)((0,Uc.cuboid)({center:[0,0,0],size:d?[f-2*ms,p-2*ms,a]:[p-2*ms,f-2*ms,a]}),(0,Uc.cylinder)({center:d?[-f/2,0,0]:[0,-f/2,0],radius:_-ms,height:a}),(0,Uc.cylinder)({center:d?[f/2,0,0]:[0,f/2,0],radius:_-ms,height:a}))),G=(0,bd.subtract)(w,H),U=CR((0,bd.union)(T,G),o);return(0,nP.colorize)(Yc.copper,U)}else if(t.shape==="hole_with_polygon_pad"){const l=t.pad_outline;if(!Array.isArray(l)||l.length<3)throw new Error(`Invalid pad_outline for plated hole at (${t.x}, ${t.y})`);const g=l.map(C=>[C.x,C.y]),u=(0,Uc.polygon)({points:g}),m=((C,y)=>{const x=Math.max(C,ms),E=(0,She.extrudeLinear)({height:x},u);return(0,EE.translate)([t.x,t.y,y-x/2],E)})(A,0),p=CR(m,o),_=Bhe(t,c);if(!_)return(0,nP.colorize)(Yc.copper,p);const f=Bhe(t,a,{sizeDelta:-2*ms})||_;let I=(0,bd.union)((0,bd.subtract)(p,_),_);return n.clipGeom?(I=(0,bd.subtract)(I,f),I=(0,bd.intersect)(I,n.clipGeom),(0,nP.colorize)(Yc.copper,I)):(0,nP.colorize)(Yc.copper,(0,bd.subtract)(I,f))}else throw new Error(`Unsupported plated hole shape: ${t.shape}`)},F_i=ng(eX()),L_i=ng(mR()),ZUe=ng(hR());function H_i({x:t,y:e,outerDiameter:n,holeDiameter:o,thickness:i}){if(n<=o)throw new Error(`Invalid via geometry: outerDiameter (${n}) must be > holeDiameter (${o})`);const r=ms,s=Math.min(n/2,o/2+r),A=(0,ZUe.cylinder)({center:[0,0,0],radius:s,height:i,segments:W_}),c=i+2*ms,l=(0,ZUe.cylinder)({center:[0,0,0],radius:o/2,height:c,segments:W_}),g=(0,F_i.subtract)(A,l);return(0,L_i.translate)([t,e,0],g)}function O_i({x:t,y:e,holeDiameter:n,thickness:o}){const i=o*1.5,r=n/2+ms;return(0,ZUe.cylinder)({center:[t,e,0],radius:r,height:i,segments:W_})}var G_i=64,Y_i=1,eKe=.05,Hnn=["initializing","processing_plated_holes","processing_holes","processing_cutouts","processing_vias","finalizing","done"],U_i=class{board;plated_holes;holes;pcb_vias;pcb_cutouts;boardGeom=null;platedHoleGeoms=[];viaGeoms=[];boardClipGeom=null;state="initializing";currentIndex=0;ctx;onCompleteCallback;finalGeoms=[];constructor(t,e){this.onCompleteCallback=e;const n=t.filter(i=>i.type==="pcb_panel"),o=Cr(t).pcb_board.list();if(n.length>0){const i=n[0],r=o.find(s=>s.pcb_panel_id===i.pcb_panel_id);this.board={type:"pcb_board",pcb_board_id:i.pcb_panel_id,center:i.center,width:i.width,height:i.height,thickness:r?.thickness??1.4,material:r?.material??"fr4",num_layers:r?.num_layers??2,solder_mask_color:r?.solder_mask_color}}else{const i=o.filter(r=>!r.pcb_panel_id);this.board=i[0]}this.plated_holes=Cr(t).pcb_plated_hole.list(),this.holes=Cr(t).pcb_hole.list(),this.pcb_vias=Cr(t).pcb_via.list(),this.pcb_cutouts=Cr(t).pcb_cutout.list(),this.ctx={pcbThickness:this.board.thickness??1.2},this.initializeBoard()}initializeBoard(){const t=this.ctx.pcbThickness+2*Y_i;this.board.outline&&this.board.outline.length>0?(this.boardGeom=jUe({outline:this.board.outline},this.ctx.pcbThickness),this.boardClipGeom=jUe({outline:this.board.outline},t,{xyOutset:eKe})):(this.boardGeom=(0,Gu.cuboid)({size:[this.board.width,this.board.height,this.ctx.pcbThickness],center:[this.board.center.x,this.board.center.y,0]}),this.boardClipGeom=(0,Gu.cuboid)({size:[this.board.width+2*eKe,this.board.height+2*eKe,t],center:[this.board.center.x,this.board.center.y,0]})),this.state="processing_plated_holes",this.currentIndex=0}goToNextState(){const t=Hnn.indexOf(this.state);t!==-1&&(this.state=Hnn[t+1],this.currentIndex=0)}step(t=1){if(this.state==="done"||!this.boardGeom)return!0;for(let e=0;e<t&&this.state!=="done";e++)switch(this.state){case"processing_plated_holes":this.currentIndex<this.plated_holes.length?(this.processPlatedHole(this.plated_holes[this.currentIndex]),this.currentIndex++):this.goToNextState();break;case"processing_holes":this.currentIndex<this.holes.length?(this.processHole(this.holes[this.currentIndex]),this.currentIndex++):this.goToNextState();break;case"processing_vias":this.currentIndex<this.pcb_vias.length?(this.processVia(this.pcb_vias[this.currentIndex]),this.currentIndex++):this.goToNextState();break;case"processing_cutouts":this.currentIndex<this.pcb_cutouts.length?(this.processCutout(this.pcb_cutouts[this.currentIndex]),this.currentIndex++):this.goToNextState();break;case"finalizing":this.finalize(),this.state="done";break}return this.state==="done"}processCutout(t){if(!this.boardGeom)return;let e=null;const n=this.ctx.pcbThickness*1.5;switch(t.shape){case"rect":{const o=Lnn(t.width,t.height,w9(t));if(o>0){const i=(0,Gu.roundedRectangle)({size:[t.width,t.height],roundRadius:o,segments:G_i});e=(0,XUe.extrudeLinear)({height:n},i),e=(0,xE.translate)([0,0,-n/2],e)}else e=(0,Gu.cuboid)({center:[0,0,0],size:[t.width,t.height,n]});if(t.rotation){const i=t.rotation*Math.PI/180;e=(0,xE.rotateZ)(i,e)}e=(0,xE.translate)([t.center.x,t.center.y,0],e);break}case"circle":e=(0,Gu.cylinder)({center:[t.center.x,t.center.y,0],radius:t.radius,height:n});break;case"polygon":{let o=t.points.map(r=>[r.x,r.y]);if(o.length<3){console.warn(`PCB Cutout [${t.pcb_cutout_id}] polygon has fewer than 3 points, skipping.`);break}Rnn(o)&&(o=o.reverse());const i=(0,Gu.polygon)({points:o});e=(0,XUe.extrudeLinear)({height:n},i),e=(0,xE.translate)([0,0,-n/2],e);break}}e&&(this.boardGeom=(0,Uf.subtract)(this.boardGeom,e))}processPlatedHole(t,e={}){if(this.boardGeom){if(t.shape==="circle"||t.shape==="circular_hole_with_rect_pad"){let n=null;if(t.shape==="circular_hole_with_rect_pad"){if(t.hole_shape&&t.hole_shape!=="circle"||t.pad_shape&&t.pad_shape!=="rect")return;n=(0,Gu.cylinder)({center:[t.x+(t.hole_offset_x||0),t.y+(t.hole_offset_y||0),0],radius:t.hole_diameter/2+ms,height:this.ctx.pcbThickness*1.5})}else n=(0,Gu.cylinder)({center:[t.x,t.y,0],radius:t.hole_diameter/2+ms,height:this.ctx.pcbThickness*1.5});e.dontCutBoard||(this.boardGeom=(0,Uf.subtract)(this.boardGeom,n));const o=CX(t,this.ctx,{clipGeom:this.boardClipGeom});this.platedHoleGeoms.push(o)}else if(t.shape==="pill"||t.shape==="oval"){const n=t.hole_height>t.hole_width,o=n?t.hole_height:t.hole_width,i=n?t.hole_width:t.hole_height,r=i/2,s=Math.abs(o-i);let a;if(a=(0,Uf.union)((0,Gu.cuboid)({center:[t.x,t.y,0],size:n?[i,s,this.ctx.pcbThickness*1.5]:[s,i,this.ctx.pcbThickness*1.5]}),(0,Gu.cylinder)({center:n?[t.x,t.y-s/2,0]:[t.x-s/2,t.y,0],radius:r,height:this.ctx.pcbThickness*1.5}),(0,Gu.cylinder)({center:n?[t.x,t.y+s/2,0]:[t.x+s/2,t.y,0],radius:r,height:this.ctx.pcbThickness*1.5})),t.ccw_rotation){const c=t.ccw_rotation*Math.PI/180;a=(0,xE.translate)([t.x,t.y,0],(0,xE.rotateZ)(c,(0,xE.translate)([-t.x,-t.y,0],a)))}e.dontCutBoard||(this.boardGeom=(0,Uf.subtract)(this.boardGeom,a));const A=CX(t,this.ctx,{clipGeom:this.boardClipGeom});this.platedHoleGeoms.push(A)}else if(t.shape==="pill_hole_with_rect_pad"){if(t.hole_shape&&t.hole_shape!=="pill"||t.pad_shape&&t.pad_shape!=="rect")return;const n=t.hole_height>t.hole_width,o=n?t.hole_height:t.hole_width,i=n?t.hole_width:t.hole_height,r=i/2,s=Math.abs(o-i);let a;a=(0,Uf.union)((0,Gu.cuboid)({center:[t.x+(t.hole_offset_x||0),t.y+(t.hole_offset_y||0),0],size:n?[i,s,this.ctx.pcbThickness*1.5]:[s,i,this.ctx.pcbThickness*1.5]}),(0,Gu.cylinder)({center:n?[t.x+(t.hole_offset_x||0),t.y+(t.hole_offset_y||0)-s/2,0]:[t.x+(t.hole_offset_x||0)-s/2,t.y+(t.hole_offset_y||0),0],radius:r,height:this.ctx.pcbThickness*1.5}),(0,Gu.cylinder)({center:n?[t.x+(t.hole_offset_x||0),t.y+(t.hole_offset_y||0)+s/2,0]:[t.x+(t.hole_offset_x||0)+s/2,t.y+(t.hole_offset_y||0),0],radius:r,height:this.ctx.pcbThickness*1.5})),e.dontCutBoard||(this.boardGeom=(0,Uf.subtract)(this.boardGeom,a));const A=CX(t,this.ctx,{clipGeom:this.boardClipGeom});this.platedHoleGeoms.push(A)}else if(t.shape==="rotated_pill_hole_with_rect_pad"){if(t.hole_shape&&t.hole_shape!=="rotated_pill"||t.pad_shape&&t.pad_shape!=="rect")return;const n=t.hole_width,o=t.hole_height,i=n>=o,r=i?n:o,s=i?o:n,a=s/2,A=Math.abs(r-s),c=t.hole_offset_x||0,l=t.hole_offset_y||0;let g=(0,Uf.union)((0,Gu.cuboid)({center:[0,0,0],size:i?[A,s,this.ctx.pcbThickness*1.5]:[s,A,this.ctx.pcbThickness*1.5]}),(0,Gu.cylinder)({center:i?[-A/2,0,0]:[0,-A/2,0],radius:a,height:this.ctx.pcbThickness*1.5}),(0,Gu.cylinder)({center:i?[A/2,0,0]:[0,A/2,0],radius:a,height:this.ctx.pcbThickness*1.5}));const u=(t.hole_ccw_rotation||0)*Math.PI/180,h=c*Math.cos(u)-l*Math.sin(u),d=c*Math.sin(u)+l*Math.cos(u);g=(0,xE.rotateZ)(u,g);const m=(0,xE.translate)([t.x+h,t.y+d,0],g);e.dontCutBoard||(this.boardGeom=(0,Uf.subtract)(this.boardGeom,m));const p=CX(t,this.ctx,{clipGeom:this.boardClipGeom});this.platedHoleGeoms.push(p)}else if(t.shape==="hole_with_polygon_pad"){const n=t.pad_outline;if(!Array.isArray(n)||n.length<3)return;const o=this.ctx.pcbThickness*1.5,i=Bhe(t,o,{sizeDelta:2*ms}),r=Bhe(t,o,{sizeDelta:-2*ms});if(!i||!r)return;e.dontCutBoard||(this.boardGeom=(0,Uf.subtract)(this.boardGeom,i)),this.platedHoleGeoms=this.platedHoleGeoms.map(a=>(0,IX.colorize)(Yc.copper,(0,Uf.subtract)(a,r)));const s=CX(t,this.ctx,{clipGeom:this.boardClipGeom});this.platedHoleGeoms.push(s)}}}processHole(t){if(!this.boardGeom)return;const e=this.ctx.pcbThickness*1.5;if(t.hole_shape==="circle"){const n=(0,Gu.cylinder)({center:[t.x,t.y,0],radius:t.hole_diameter/2+ms,height:e});this.boardGeom=(0,Uf.subtract)(this.boardGeom,n);const o=(0,Gu.cylinder)({center:[t.x,t.y,0],radius:t.hole_diameter/2+ms/2,height:e});this.platedHoleGeoms=this.platedHoleGeoms.map(i=>(0,IX.colorize)(Yc.copper,(0,Uf.subtract)(i,o)))}else if(t.hole_shape==="pill"||t.hole_shape==="rotated_pill"||t.hole_shape==="rect"||t.hole_shape==="oval"){const n=t.hole_width??t.hole_diameter,o=t.hole_height??t.hole_diameter,i=t.ccw_rotation??t.rotation??0,r=.02,s=(c,l,g,u)=>{if(c<=0||l<=0)return null;if(t.hole_shape==="rect")return(0,Gu.cuboid)({center:[0,0,0],size:[c,l,g]});if(u)return(0,xE.translate)([0,0,-g/2],(0,XUe.extrudeLinear)({height:g},(0,Gu.ellipse)({radius:[c/2,l/2]})));const h=Math.min(c,l)/2,d=Math.abs(c-l);return c>l?(0,Uf.union)((0,Gu.cuboid)({center:[0,0,0],size:[d,l,g]}),(0,Gu.cylinder)({center:[-d/2,0,0],radius:h,height:g}),(0,Gu.cylinder)({center:[d/2,0,0],radius:h,height:g})):(0,Uf.union)((0,Gu.cuboid)({center:[0,0,0],size:[c,d,g]}),(0,Gu.cylinder)({center:[0,-d/2,0],radius:h,height:g}),(0,Gu.cylinder)({center:[0,d/2,0],radius:h,height:g}))};let a=s(n,o,e,t.hole_shape==="oval"),A=s(n-2*r,o-2*r,e,t.hole_shape==="oval");if(a&&i!==0&&(a=(0,xE.rotateZ)(i*Math.PI/180,a)),A&&i!==0&&(A=(0,xE.rotateZ)(i*Math.PI/180,A)),a){const c=(0,xE.translate)([t.x,t.y,0],a);this.boardGeom=(0,Uf.subtract)(this.boardGeom,c)}if(A){const c=(0,xE.translate)([t.x,t.y,0],A);this.platedHoleGeoms=this.platedHoleGeoms.map(l=>(0,IX.colorize)(Yc.copper,(0,Uf.subtract)(l,c)))}}}processVia(t){if(this.boardGeom){if(typeof t.outer_diameter=="number"&&typeof t.hole_diameter=="number"){const e=H_i({x:t.x,y:t.y,outerDiameter:t.outer_diameter,holeDiameter:t.hole_diameter,thickness:this.ctx.pcbThickness});let n=e;this.boardClipGeom&&(n=(0,Uf.intersect)(this.boardClipGeom,e),n=(0,IX.colorize)(Yc.copper,n)),this.viaGeoms.push(n)}if(typeof t.hole_diameter=="number"){const e=O_i({x:t.x,y:t.y,holeDiameter:t.hole_diameter,thickness:this.ctx.pcbThickness});this.boardGeom=(0,Uf.subtract)(this.boardGeom,e)}}}finalize(){if(!this.boardGeom)return;const t=qUe(this.board);this.boardGeom=(0,IX.colorize)([t.r,t.g,t.b],this.boardGeom),this.finalGeoms=[this.boardGeom,...this.platedHoleGeoms,...this.viaGeoms],this.onCompleteCallback&&this.onCompleteCallback(this.finalGeoms)}getGeoms(){return this.finalGeoms}},K_i=t=>{const[e,n]=te.useState(null),o=te.useRef(!1);return te.useEffect(()=>{let i=!1;if(!t){n(null);return}if(!t.some(c=>c.type==="pcb_board"||c.type==="pcb_panel")){n(null);return}const s=P_i(t);n(s);const a=new U_i(t,c=>{});return(async()=>{if(!o.current){o.current=!0;try{let c=!1;for(;!c&&!i;)c=a.step(1),c||await new Promise(l=>setTimeout(l,0));i||n(a.getGeoms())}catch(c){console.error("Error during board geometry building:",c)}finally{o.current=!1}}})(),()=>{i=!0}},[t]),e},V_i=({children:t,parent:e,position:n,rotation:o,scale:i,color:r,fontSize:s,anchorX:a,anchorY:A,depthOffset:c})=>{const{rootObject:l}=jI(),g=te.useMemo(()=>{const u=new nRe;return u.text=t,n&&u.position.fromArray(n),o&&u.rotation.fromArray(o),i&&u.scale.fromArray(i),u.color=r||"white",u.fontSize=s||1,u.anchorX=a||"center",u.anchorY=A||"middle",u.depthOffset=c||0,u.font=null,u.sync(),u},[t,n,o,i,r,s,a,A,c]);return te.useEffect(()=>{const u=e||l;if(!(!u||!g))return u.add(g),()=>{u.remove(g),g.dispose()}},[l,e,g]),null},Onn=({error:t,cad_component:e})=>{const{rootObject:n}=jI(),[o,i]=te.useState(!1),[r,s]=te.useState(null),a=te.useCallback(g=>{g?.mousePosition?(i(!0),s(g.mousePosition)):(i(!1),s(null))},[]),A=te.useCallback(()=>{i(!1),s(null)},[]),c=te.useMemo(()=>e?.position?[e.position.x,e.position.y,e.position.z].map(u=>Number.isNaN(u)?0:u):[0,0,0],[e]),l=te.useMemo(()=>{const g=new w0;return g.position.fromArray(c),g},[c]);return te.useEffect(()=>{if(n)return n.add(l),()=>{n.remove(l)}},[n,l]),K.jsxs(K.Fragment,{children:[K.jsxs(_X,{isHovered:o,onHover:a,onUnhover:A,object:l,children:[K.jsx(z_i,{parent:l}),K.jsx(V_i,{parent:l,scale:[.1,.1,.1],color:"red",anchorX:"center",anchorY:"middle",depthOffset:-99999,children:`${t.toString().slice(0,50)}...`})]}),o&&r?K.jsx(Xen,{position:r,style:{fontFamily:"sans-serif",transform:"translate3d(-1rem, 0rem, 0)",backgroundColor:"white",padding:"6px",borderRadius:"4px",color:"red",pointerEvents:"none",userSelect:"none",WebkitUserSelect:"none",MozUserSelect:"none",msUserSelect:"none"},children:t.toString()}):null]})},z_i=({parent:t})=>{const e=te.useMemo(()=>{const n=new Dr(new fE(.5,.5,.5),new pu({depthTest:!1,transparent:!0,color:"red",opacity:.5}));return n.renderOrder=999999,n.rotation.fromArray([Math.PI/4,Math.PI/4,0]),n},[]);return te.useEffect(()=>(t.add(e),()=>{t.remove(e)}),[t,e]),null},J_i=t=>{if(t.length===0)return null;let e=t[0].x,n=t[0].y,o=t[0].x,i=t[0].y;for(let r=1;r<t.length;r++){const s=t[r];s.x<e&&(e=s.x),s.y<n&&(n=s.y),s.x>o&&(o=s.x),s.y>i&&(i=s.y)}return{minX:e,minY:n,maxX:o,maxY:i}};function gy(t){if(t.outline&&t.outline.length>=3){const s=J_i(t.outline);return{...s,width:s.maxX-s.minX,height:s.maxY-s.minY,centerX:(s.minX+s.maxX)/2,centerY:(s.minY+s.maxY)/2}}const e=t.width??0,n=t.height??0,o=t.center?.x??0,i=t.center?.y??0;return{...{minX:o-e/2,maxX:o+e/2,minY:i-n/2,maxY:i+n/2},width:e,height:n,centerX:o,centerY:i}}function W_i({layer:t,circuitJson:e,boardData:n,copperColor:o,traceTextureResolution:i}){const s=Cr(e).pcb_smtpad.list().filter(y=>y.layer===t);if(s.length===0)return null;const a=Cr(e).pcb_hole.list(),A=Cr(e).pcb_plated_hole.list().filter(y=>!Array.isArray(y.layers)||y.layers.includes(t)),c=Cr(e).pcb_via.list().filter(y=>!Array.isArray(y.layers)||y.layers.includes(t)),l=Cr(e).pcb_cutout.list(),g=[...a,...A,...c],u=t==="top"?"top_copper":"bottom_copper",h=gy(n),d=document.createElement("canvas"),m=Math.floor(h.width*i),p=Math.floor(h.height*i);d.width=m,d.height=p;const _=d.getContext("2d");if(!_)return null;t==="bottom"&&(_.translate(0,p),_.scale(1,-1));const f="rgba(0,0,0,0)",I=new WS(_);I.configure({colorOverrides:{copper:{top:o,bottom:o,inner1:o,inner2:o,inner3:o,inner4:o,inner5:o,inner6:o,inner7:o,inner8:o},copperPour:{top:f,bottom:f},drill:f,boardOutline:f,substrate:f,keepout:{top:f,bottom:f},fabricationNote:f,courtyard:{top:f,bottom:f},silkscreen:{top:f,bottom:f},soldermask:{top:f,bottom:f},soldermaskWithCopperUnderneath:{top:f,bottom:f},soldermaskOverCopper:{top:f,bottom:f}}}),I.setCameraBounds({minX:h.minX,maxX:h.maxX,minY:h.minY,maxY:h.maxY}),I.drawElements([...s,...g,...l],{layers:[u],drawSoldermask:!1,drawSoldermaskTop:!1,drawSoldermaskBottom:!1});const C=new IE(d);return C.generateMipmaps=!0,C.minFilter=$m,C.magFilter=xl,C.anisotropy=16,C.needsUpdate=!0,C}var j_i=t=>{const e=t.filter(n=>n.type==="pcb_panel");return e.length===0?null:e.length===1?e[0].pcb_panel_id:null};function q_i({layer:t,circuitJson:e,panelData:n,outlineColor:o="black",traceTextureResolution:i}){const r=j_i(e);if(!r)return null;const a=Cr(e).pcb_board.list().filter(m=>m.pcb_panel_id===r||m.position_mode==="relative_to_panel_anchor"&&!m.pcb_panel_id);if(a.length===0)return null;const A=document.createElement("canvas"),c=Math.floor(n.width*i),l=Math.floor(n.height*i);A.width=c,A.height=l;const g=A.getContext("2d");if(!g)return null;t==="bottom"&&(g.translate(0,l),g.scale(1,-1)),g.strokeStyle=o,g.lineWidth=.05*i;const u=m=>(m-n.center.x+n.width/2)*i,h=m=>(-(m-n.center.y)+n.height/2)*i;a.forEach(m=>{if(m.outline&&m.outline.length>=2)g.beginPath(),m.outline.forEach((p,_)=>{const f=u(p.x),I=h(p.y);_===0?g.moveTo(f,I):g.lineTo(f,I)}),g.closePath(),g.stroke();else{const p=m.width,_=m.height,{x:f,y:I}=m.center,C=u(f-p/2),y=h(I+_/2);g.strokeRect(C,y,p*i,_*i)}});const d=new IE(A);return d.generateMipmaps=!0,d.minFilter=$m,d.magFilter=xl,d.anisotropy=16,d.needsUpdate=!0,d}function X_i(t){return t&&t.route_type==="wire"&&typeof t.layer=="string"&&typeof t.width=="number"}function $_i(t,e){const n=[];let o=[];const i=()=>{if(o.length<2){o=[];return}n.push({...t,pcb_trace_id:`${t.pcb_trace_id}_${e}_${n.length}`,route:o}),o=[]};for(const r of t.route){if(!X_i(r)){i();continue}if(r.layer!==e){i();continue}o.push(r)}return i(),n}function Z_i({layer:t,circuitJson:e,boardData:n,traceColor:o,traceTextureResolution:i}){const r=Cr(e).pcb_trace.list(),s=Cr(e).pcb_via.list(),a=Cr(e).pcb_plated_hole.list(),A=t==="top"?"top_copper":"bottom_copper",c=r.filter(C=>ZSe(C).includes(A)).flatMap(C=>$_i(C,t));if(c.length===0)return null;const l=a.filter(C=>C.layers.includes(t)),g=[...c,...s,...l],u=gy(n),h=document.createElement("canvas"),d=Math.floor(u.width*i),m=Math.floor(u.height*i);h.width=d,h.height=m;const p=h.getContext("2d");if(!p)return null;t==="bottom"&&(p.translate(0,m),p.scale(1,-1));const _="rgba(0,0,0,0)",f=new WS(p);f.configure({colorOverrides:{copper:{top:o,bottom:o,inner1:o,inner2:o,inner3:o,inner4:o,inner5:o,inner6:o,inner7:o,inner8:o},copperPour:{top:_,bottom:_},drill:_,boardOutline:_,substrate:_,keepout:{top:_,bottom:_},fabricationNote:_,courtyard:{top:_,bottom:_},silkscreen:{top:_,bottom:_},soldermask:{top:_,bottom:_},soldermaskWithCopperUnderneath:{top:_,bottom:_},soldermaskOverCopper:{top:_,bottom:_}}}),f.setCameraBounds({minX:u.minX,maxX:u.maxX,minY:u.minY,maxY:u.maxY}),f.drawElements(g,{layers:[A],clipContextElements:e,drawSoldermask:!1,drawSoldermaskTop:!1,drawSoldermaskBottom:!1});const I=new IE(h);return I.generateMipmaps=!0,I.minFilter=$m,I.magFilter=xl,I.anisotropy=16,I.needsUpdate=!0,I}var efi=t=>{const[e=0,n=0,o=0]=t;return`rgb(${Math.round(e*255)}, ${Math.round(n*255)}, ${Math.round(o*255)})`},tfi=8;function Gnn({layer:t,circuitJson:e,boardData:n,traceTextureResolution:o=jS,copperColor:i=efi(Yc.copper),onlyCoveredBySoldermask:r=!1}){const s=e.filter(b=>b.type==="pcb_copper_pour"),a=t==="top"?"top_copper":"bottom_copper",A=s.filter(b=>b.layer===t&&(!r||b.covered_with_solder_mask!==!1));if(A.length===0)return null;const c=e.filter(b=>b.type==="pcb_hole"),l=e.filter(b=>b.type!=="pcb_plated_hole"?!1:!Array.isArray(b.layers)||b.layers.includes(t)),g=e.filter(b=>b.type!=="pcb_via"?!1:!Array.isArray(b.layers)||b.layers.includes(t)),u=[...c,...l,...g],h=gy(n),d=document.createElement("canvas"),m=Math.floor(h.width*o),p=Math.floor(h.height*o);d.width=m,d.height=p;const _=d.getContext("2d");if(!_)return null;t==="bottom"&&(_.translate(0,p),_.scale(1,-1));const f="rgba(0,0,0,0)",I=i,C=i,y=(b,Q)=>{if(b.length===0)return;const w=[...b,...u],D=new WS(_);D.configure({colorOverrides:{copper:{top:Q,bottom:Q,inner1:Q,inner2:Q,inner3:Q,inner4:Q,inner5:Q,inner6:Q,inner7:Q,inner8:Q},copperPour:{top:f,bottom:f},drill:f,boardOutline:f,substrate:f,keepout:{top:f,bottom:f},fabricationNote:f,courtyard:{top:f,bottom:f},silkscreen:{top:f,bottom:f},soldermask:{top:f,bottom:f},soldermaskWithCopperUnderneath:{top:f,bottom:f},soldermaskOverCopper:{top:f,bottom:f}}}),D.setCameraBounds({minX:h.minX,maxX:h.maxX,minY:h.minY,maxY:h.maxY}),D.drawElements(w,{layers:[a],drawSoldermask:!1,drawSoldermaskTop:!1,drawSoldermaskBottom:!1});for(let k=1;k<tfi;k+=1)D.drawElements(w,{layers:[a],drawSoldermask:!1,drawSoldermaskTop:!1,drawSoldermaskBottom:!1})},x=A.filter(b=>b.covered_with_solder_mask!==!1),E=A.filter(b=>b.covered_with_solder_mask===!1);y(x,I),r||y(E,C);const B=new IE(d);return B.generateMipmaps=!0,B.minFilter=$m,B.magFilter=xl,B.anisotropy=16,B.needsUpdate=!0,B}var Ynn=(t,e)=>{t.setCameraBounds({minX:e.minX,maxX:e.maxX,minY:e.minY,maxY:e.maxY})},nfi=({ctx:t,layer:e,bounds:n,elements:o,copperColor:i})=>{const r=e==="top"?"top_copper":"bottom_copper",s=new WS(t);s.configure({colorOverrides:{copper:{top:i,bottom:i,inner1:i,inner2:i,inner3:i,inner4:i,inner5:i,inner6:i,inner7:i,inner8:i}}}),Ynn(s,n),s.drawElements(o,{layers:[r]});const a=o.filter(g=>g.type==="pcb_copper_text"&&g.is_knockout===!0);if(a.length===0)return;const A=document.createElement("canvas");A.width=t.canvas.width,A.height=t.canvas.height;const c=A.getContext("2d");if(!c)return;const l=new WS(c);l.configure({colorOverrides:{copper:{top:"rgb(255,255,255)",bottom:"rgb(255,255,255)",inner1:"rgb(255,255,255)",inner2:"rgb(255,255,255)",inner3:"rgb(255,255,255)",inner4:"rgb(255,255,255)",inner5:"rgb(255,255,255)",inner6:"rgb(255,255,255)",inner7:"rgb(255,255,255)",inner8:"rgb(255,255,255)"}}}),Ynn(l,n),l.drawElements(a.map(g=>({...g,is_knockout:!1})),{layers:[r]}),t.save(),t.globalCompositeOperation="destination-out",t.drawImage(A,0,0),t.restore()};function ofi({layer:t,circuitJson:e,boardData:n,copperColor:o="rgb(230, 153, 51)",traceTextureResolution:i=jS}){const r=e.filter(u=>u.type==="pcb_copper_text"&&"layer"in u&&u.layer===t);if(r.length===0)return null;const s=gy(n),a=Math.floor(s.width*i),A=Math.floor(s.height*i);if(a<=0||A<=0)return null;const c=document.createElement("canvas");c.width=a,c.height=A;const l=c.getContext("2d");if(!l)return null;t==="bottom"&&(l.translate(0,A),l.scale(1,-1)),nfi({ctx:l,layer:t,bounds:s,elements:r,copperColor:o});const g=new IE(c);return g.generateMipmaps=!0,g.minFilter=$m,g.magFilter=xl,g.anisotropy=16,g.needsUpdate=!0,g}var Unn=25.4,ifi=Unn/1e3,rfi=/^\s*(-?\d*(?:\.\d+)?)(?:\s*(mm|mil|inch|in|"))?\s*$/i;function sfi(t){if(!t)return;const e=t.trim().toLowerCase();return e==='"'||e==="inch"?"in":e}function bhe(t){if(t==null)return;if(typeof t=="number")return Number.isFinite(t)?t:void 0;if(typeof t!="string")return;const e=t.trim();if(e.length===0)return;const n=e.match(rfi);if(!n){const a=Number.parseFloat(e);return Number.isFinite(a)?a:void 0}const[,o,i]=n,r=Number.parseFloat(o||"0");if(!Number.isFinite(r))return;switch(sfi(i)){case"mil":return r*ifi;case"in":return r*Unn;case"mm":case void 0:return r;default:return r}}function Cg(t,e){const n=bhe(t);return n===void 0?e:n}var afi="rgb(255,243,204)",Yu="rgba(0,0,0,0)",Afi=(t,e)=>{t.setCameraBounds({minX:e.minX,maxX:e.maxX,minY:e.minY,maxY:e.maxY})},cfi=t=>t.type==="pcb_fabrication_note_rect"?{...t,width:bhe(t.width)??0,height:bhe(t.height)??0,stroke_width:Cg(t.stroke_width,.1),corner_radius:bhe(t.corner_radius)}:t.type==="pcb_fabrication_note_path"?{...t,stroke_width:Cg(t.stroke_width,.1)}:t.type==="pcb_fabrication_note_text"?{...t,font_size:Cg(t.font_size,1)}:t.type==="pcb_fabrication_note_dimension"?{...t,font_size:Cg(t.font_size,1),arrow_size:Cg(t.arrow_size,1),offset_distance:Cg(t.offset_distance,0)}:t,lfi=({ctx:t,layer:e,bounds:n,elements:o})=>{const i=`${e}_fabrication_note`,r=o.map(cfi),s=new WS(t);s.configure({colorOverrides:{copper:{top:Yu,bottom:Yu,inner1:Yu,inner2:Yu,inner3:Yu,inner4:Yu,inner5:Yu,inner6:Yu,inner7:Yu,inner8:Yu},copperPour:{top:Yu,bottom:Yu},drill:Yu,boardOutline:Yu,substrate:Yu,keepout:{top:Yu,bottom:Yu},courtyard:{top:Yu,bottom:Yu},soldermask:{top:Yu,bottom:Yu},soldermaskWithCopperUnderneath:{top:Yu,bottom:Yu},soldermaskOverCopper:{top:Yu,bottom:Yu},silkscreen:{top:Yu,bottom:Yu},fabricationNote:afi}}),Afi(s,n),s.drawElements(r,{layers:[i]})},gfi=t=>({minX:t.center.x-t.width/2,maxX:t.center.x+t.width/2,minY:t.center.y-t.height/2,maxY:t.center.y+t.height/2,width:t.width,height:t.height,centerX:t.center.x,centerY:t.center.y}),ufi=(t,e)=>{const n=Math.min(t.minX,e.minX),o=Math.max(t.maxX,e.maxX),i=Math.min(t.minY,e.minY),r=Math.max(t.maxY,e.maxY);return{minX:n,maxX:o,minY:i,maxY:r,width:o-n,height:r-i,centerX:(n+o)/2,centerY:(i+r)/2}},Qhe=(t,e)=>{const n=t.filter(s=>s.type==="pcb_panel"),o=t.filter(s=>s.type==="pcb_board"),i=n.find(s=>s.pcb_panel_id===e.pcb_board_id)??n[0];return i&&i.width>0&&i.height>0?gfi(i):(o.length>1?o:[e]).map(s=>gy(s)).reduce((s,a)=>ufi(s,a))},dfi=(t,e)=>{if(!("layer"in t)||t.layer!==e)return!1;const n=t.type;return n.startsWith("pcb_fabrication_note_")&&n!=="pcb_fabrication_note_text"};function hfi({layer:t,circuitJson:e,boardData:n,traceTextureResolution:o=jS}){const i=e.filter(g=>dfi(g,t));if(i.length===0)return null;const r=Qhe(e,n),s=Math.floor(r.width*o),a=Math.floor(r.height*o);if(s<=0||a<=0)return null;const A=document.createElement("canvas");A.width=s,A.height=a;const c=A.getContext("2d");if(!c)return null;t==="bottom"&&(c.translate(0,a),c.scale(1,-1)),lfi({ctx:c,layer:t,bounds:r,elements:i});const l=new IE(A);return l.generateMipmaps=!0,l.minFilter=$m,l.magFilter=xl,l.anisotropy=16,l.needsUpdate=!0,l}var mfi=(t,e)=>{t.setCameraBounds({minX:e.minX,maxX:e.maxX,minY:e.minY,maxY:e.maxY})},pfi=({ctx:t,layer:e,bounds:n,elements:o,keepoutColor:i})=>{const r=e==="top"?"top_copper":"bottom_copper",s=new WS(t);s.configure({colorOverrides:{keepout:{top:i,bottom:i}}}),mfi(s,n),s.drawElements(o,{layers:[r],drawSoldermask:!1,drawSoldermaskTop:!1,drawSoldermaskBottom:!1})},_fi=(t,e)=>t.type!=="pcb_keepout"?!1:!("layers"in t)||!Array.isArray(t.layers)?!0:t.layers.includes(e);function ffi({layer:t,circuitJson:e,boardData:n,traceTextureResolution:o=jS,keepoutColor:i=t==="bottom"?"#4b72d2":"#d24b4b"}){const r=e.filter(u=>_fi(u,t));if(r.length===0)return null;const s=gy(n),a=Math.floor(s.width*o),A=Math.floor(s.height*o);if(a<=0||A<=0)return null;const c=document.createElement("canvas");c.width=a,c.height=A;const l=c.getContext("2d");if(!l)return null;t==="bottom"&&(l.translate(0,A),l.scale(1,-1)),pfi({ctx:l,layer:t,bounds:s,elements:r,keepoutColor:i});const g=new IE(c);return g.generateMipmaps=!0,g.minFilter=$m,g.magFilter=xl,g.anisotropy=16,g.needsUpdate=!0,g}var Iu="rgba(0,0,0,0)",Ifi=(t,e)=>{t.setCameraBounds({minX:e.minX,maxX:e.maxX,minY:e.minY,maxY:e.maxY})},Cfi=t=>t.type==="pcb_note_line"?{...t,x1:Cg(t.x1,0),y1:Cg(t.y1,0),x2:Cg(t.x2,0),y2:Cg(t.y2,0),stroke_width:Cg(t.stroke_width,.1)}:t.type==="pcb_note_rect"?{...t,center:{x:Cg(t.center.x,0),y:Cg(t.center.y,0)},width:Cg(t.width,0),height:Cg(t.height,0),stroke_width:Cg(t.stroke_width,.1),corner_radius:Cg(t.corner_radius,0)}:t.type==="pcb_note_text"?{...t,anchor_position:{x:Cg(t.anchor_position.x,0),y:Cg(t.anchor_position.y,0)},font_size:Cg(t.font_size,1)}:t.type==="pcb_note_path"?{...t,route:t.route.map(e=>({...e,x:Cg(e.x,0),y:Cg(e.y,0)})),stroke_width:Cg(t.stroke_width,.1)}:t.type==="pcb_note_dimension"?{...t,from:{x:Cg(t.from.x,0),y:Cg(t.from.y,0)},to:{x:Cg(t.to.x,0),y:Cg(t.to.y,0)},font_size:Cg(t.font_size,1),arrow_size:Cg(t.arrow_size,1),offset_distance:Cg(t.offset_distance,0)}:t,yfi=({ctx:t,bounds:e,elements:n})=>{const o=n.map(Cfi),i=new WS(t);i.configure({colorOverrides:{copper:{top:Iu,bottom:Iu,inner1:Iu,inner2:Iu,inner3:Iu,inner4:Iu,inner5:Iu,inner6:Iu,inner7:Iu,inner8:Iu},copperPour:{top:Iu,bottom:Iu},drill:Iu,boardOutline:Iu,substrate:Iu,keepout:{top:Iu,bottom:Iu},courtyard:{top:Iu,bottom:Iu},soldermask:{top:Iu,bottom:Iu},soldermaskWithCopperUnderneath:{top:Iu,bottom:Iu},soldermaskOverCopper:{top:Iu,bottom:Iu},silkscreen:{top:Iu,bottom:Iu},fabricationNote:Iu}}),Ifi(i,e),i.drawElements(o)},xfi=(t,e)=>!("layer"in t)||t.layer!==e?!1:t.type.startsWith("pcb_note_");function Efi({layer:t,circuitJson:e,boardData:n,traceTextureResolution:o=jS}){const i=e.filter(g=>xfi(g,t));if(i.length===0)return null;const r=Qhe(e,n),s=Math.floor(r.width*o),a=Math.floor(r.height*o);if(s<=0||a<=0)return null;const A=document.createElement("canvas");A.width=s,A.height=a;const c=A.getContext("2d");if(!c)return null;t==="bottom"&&(c.translate(0,a),c.scale(1,-1)),yfi({ctx:c,bounds:r,elements:i});const l=new IE(A);return l.generateMipmaps=!0,l.minFilter=$m,l.magFilter=xl,l.anisotropy=16,l.needsUpdate=!0,l}var Bfi="rgb(255,243,204)",Ah="rgba(0,0,0,0)",Sfi=(t,e)=>{t.setCameraBounds({minX:e.minX,maxX:e.maxX,minY:e.minY,maxY:e.maxY})},bfi=({ctx:t,layer:e,bounds:n,elements:o,apertureElements:i,silkscreenColor:r})=>{const s=e==="top"?"top_silkscreen":"bottom_silkscreen",a=new WS(t);a.configure({colorOverrides:{copper:{top:Ah,bottom:Ah,inner1:Ah,inner2:Ah,inner3:Ah,inner4:Ah,inner5:Ah,inner6:Ah,inner7:Ah,inner8:Ah},copperPour:{top:Ah,bottom:Ah},drill:Ah,boardOutline:Ah,substrate:Ah,keepout:{top:Ah,bottom:Ah},courtyard:{top:Ah,bottom:Ah},soldermask:{top:Ah,bottom:Ah},soldermaskWithCopperUnderneath:{top:Ah,bottom:Ah},soldermaskOverCopper:{top:Ah,bottom:Ah},silkscreen:{top:r,bottom:r},fabricationNote:Bfi}}),Sfi(a,n),a.drawElements([...o,...i],{layers:[s],clearDrillHoles:!0})},Qfi=(t,e)=>!("layer"in t)||t.layer!==e?!1:t.type.startsWith("pcb_silkscreen_"),vfi=(t,e)=>t.type==="pcb_cutout"?!0:t.type==="pcb_via"?!e||t.is_tented!==!0:t.type==="pcb_hole"||t.type==="pcb_plated_hole"?!e||t.is_covered_with_solder_mask!==!0:!1;function Pfi({layer:t,circuitJson:e,boardData:n,traceTextureResolution:o=jS,silkscreenColor:i="rgb(255,255,255)",soldermaskVisible:r=!0}){const s=e.filter(d=>Qfi(d,t));if(s.length===0)return null;const a=e.filter(d=>vfi(d,r)),A=Qhe(e,n),c=Math.floor(A.width*o),l=Math.floor(A.height*o);if(c<=0||l<=0)return null;const g=document.createElement("canvas");g.width=c,g.height=l;const u=g.getContext("2d");if(!u)return null;t==="bottom"&&(u.translate(0,l),u.scale(1,-1)),bfi({ctx:u,layer:t,bounds:A,elements:s,apertureElements:a,silkscreenColor:i});const h=new IE(g);return h.generateMipmaps=!0,h.minFilter=$m,h.magFilter=xl,h.anisotropy=16,h.needsUpdate=!0,h}var yX=t=>{const[e=0,n=0,o=0]=t;return`rgb(${Math.round(e*255)}, ${Math.round(n*255)}, ${Math.round(o*255)})`},wfi=t=>{const e=yX(__i[t.material]??Yc.fr4SolderMaskGreen),n=t.material==="fr1"?yX(Yc.fr1TracesWithMaskCopper):yX(Yc.fr4TracesWithMaskGreen),o=Tnn(t.solder_mask_color);if(!o)return{soldermask:e,soldermaskOverCopper:n,copper:yX(Yc.copper),transparent:"rgba(0,0,0,0)"};const i=new Yi().setRGB(Yc.copper[0],Yc.copper[1],Yc.copper[2],mE);return{soldermask:knn(o),soldermaskOverCopper:knn(Q_i({soldermaskColor:o,copperColor:i,soldermaskOpacity:S_i(t.solder_mask_color)})),copper:yX(Yc.copper),transparent:"rgba(0,0,0,0)"}},Knn=(t,e)=>{t.setCameraBounds({minX:e.minX,maxX:e.maxX,minY:e.minY,maxY:e.maxY})},Mfi=({ctx:t,layer:e,bounds:n,elements:o,boardData:i})=>{const r=wfi(i),s=e==="top"?"top_copper":"bottom_copper",a=new WS(t);a.configure({colorOverrides:{copper:{top:r.transparent,bottom:r.transparent,inner1:r.transparent,inner2:r.transparent,inner3:r.transparent,inner4:r.transparent,inner5:r.transparent,inner6:r.transparent,inner7:r.transparent,inner8:r.transparent},drill:r.transparent,boardOutline:r.transparent,substrate:r.transparent,keepout:{top:r.transparent,bottom:r.transparent},fabricationNote:r.transparent,silkscreen:{top:r.transparent,bottom:r.transparent},courtyard:{top:r.transparent,bottom:r.transparent},soldermask:{top:r.soldermask,bottom:r.soldermask},soldermaskWithCopperUnderneath:{top:r.soldermaskOverCopper,bottom:r.soldermaskOverCopper},soldermaskOverCopper:{top:r.soldermaskOverCopper,bottom:r.soldermaskOverCopper}}}),Knn(a,n);const A=o.filter(l=>l.type!=="pcb_keepout");a.drawElements(A,{layers:[s],drawSoldermask:!0,drawSoldermaskTop:e==="top",drawSoldermaskBottom:e==="bottom"});const c=A.filter(l=>l.type==="pcb_copper_pour"&&l.layer===e&&l.covered_with_solder_mask===!1);if(c.length>0){t.save(),t.globalCompositeOperation="destination-out";const l=new WS(t);l.configure({colorOverrides:{copper:{top:r.copper,bottom:r.copper,inner1:r.copper,inner2:r.copper,inner3:r.copper,inner4:r.copper,inner5:r.copper,inner6:r.copper,inner7:r.copper,inner8:r.copper}}}),Knn(l,n),l.drawElements(c,{layers:[s]}),t.restore()}};function Dfi({layer:t,circuitJson:e,boardData:n,traceTextureResolution:o=jS}){const i=Qhe(e,n),r=Math.floor(i.width*o),s=Math.floor(i.height*o);if(r<=0||s<=0)return null;const a=document.createElement("canvas");a.width=r,a.height=s;const A=a.getContext("2d");if(!A)return null;t==="bottom"&&(A.translate(0,s),A.scale(1,-1));const c=e.some(g=>g.type==="pcb_board")?e:[n,...e];Mfi({ctx:A,layer:t,bounds:i,elements:c,boardData:n});const l=new IE(a);return l.generateMipmaps=!0,l.minFilter=$m,l.magFilter=xl,l.anisotropy=16,l.needsUpdate=!0,l}var Nfi=(t,e)=>{t.setCameraBounds({minX:e.minX,maxX:e.maxX,minY:e.minY,maxY:e.maxY})},Rfi=({ctx:t,layer:e,bounds:n,elements:o,copperColor:i})=>{const r=e==="top"?"top_copper":"bottom_copper",s="rgba(0,0,0,0)",a=new WS(t);a.configure({colorOverrides:{copper:{top:i,bottom:i,inner1:i,inner2:i,inner3:i,inner4:i,inner5:i,inner6:i,inner7:i,inner8:i},drill:s,boardOutline:s,substrate:s,keepout:{top:s,bottom:s},fabricationNote:s,silkscreen:{top:s,bottom:s},courtyard:{top:s,bottom:s},soldermask:{top:s,bottom:s},soldermaskWithCopperUnderneath:{top:s,bottom:s},soldermaskOverCopper:{top:s,bottom:s}}}),Nfi(a,n),a.drawElements(o,{layers:[r]})};function Tfi({layer:t,circuitJson:e,boardData:n,copperColor:o="rgb(230, 153, 51)",traceTextureResolution:i=jS}){const r=e.filter(u=>{if(u.type==="pcb_via")return!0;if(u.type!=="pcb_plated_hole")return!1;const h=u;return!Array.isArray(h.layers)||h.layers.includes(t)});if(r.length===0)return null;const s=gy(n),a=Math.floor(s.width*i),A=Math.floor(s.height*i);if(a<=0||A<=0)return null;const c=document.createElement("canvas");c.width=a,c.height=A;const l=c.getContext("2d");if(!l)return null;t==="bottom"&&(l.translate(0,A),l.scale(1,-1)),Rfi({ctx:l,layer:t,bounds:s,elements:r,copperColor:o});const g=new IE(c);return g.generateMipmaps=!0,g.minFilter=$m,g.magFilter=xl,g.anisotropy=16,g.needsUpdate=!0,g}var Vnn=t=>{const[e=0,n=0,o=0]=t;return`rgb(${Math.round(e*255)}, ${Math.round(n*255)}, ${Math.round(o*255)})`},tKe=t=>Math.max(0,Math.min(255,t)),kfi=(t,e,n,o={})=>{const i=t.getImageData(0,0,e,n),r=i.data,s=Math.max(e-1,1),a=Math.max(n-1,1);for(let A=0;A<r.length;A+=4){if((r[A+3]??0)<16)continue;const l=r[A]??0,g=r[A+1]??0,u=r[A+2]??0,h=.2126*l+.7152*g+.0722*u;if(!(g>l*1.35&&g>u*1.15&&h<90&&l<80&&u<80))continue;const m=A/4,p=m%e,_=Math.floor(m/e),f=p/s,I=_/a,C=f*.62+(1-I)*.38,y=Math.sin((f*1.15+I*.35)*Math.PI)*.04,x=.74+C*.18+y,E=o.includeReflection?(()=>{const k=f-.36,T=I-.22,H=Math.max(0,1-Math.hypot(k,T)/.38);return H*H*.07})():0,B=(l*.9+3)*x,b=(g*1.08+15)*x,Q=(u*1.28+13)*x;r[A]=tKe(B*(1-E)+255*E),r[A+1]=tKe(b*(1-E)+255*E),r[A+2]=tKe(Q*(1-E)+255*E)}t.putImageData(i,0,0)},Ffi=({textures:t,boardData:e,traceTextureResolution:n,layer:o})=>{if(!t.some(g=>g?.image))return null;const r=gy(e),s=Math.floor(r.width*n),a=Math.floor(r.height*n);if(s<=0||a<=0)return null;const A=document.createElement("canvas");A.width=s,A.height=a+1;const c=A.getContext("2d");if(!c)return null;for(const g of t){if(!g?.image)continue;const u=g.image;c.drawImage(u,0,0,s,a)}kfi(c,s,a,{includeReflection:o==="top"});const l=new IE(A);return l.generateMipmaps=!1,l.minFilter=xl,l.magFilter=xl,l.premultiplyAlpha=!0,l.anisotropy=16,l.needsUpdate=!0,l},Lfi=({textures:t,soldermaskTexture:e,boardData:n,traceTextureResolution:o})=>{if(!e?.image||!t.some(l=>l?.image))return null;const i=gy(n),r=Math.floor(i.width*o),s=Math.floor(i.height*o);if(r<=0||s<=0)return null;const a=document.createElement("canvas");a.width=r,a.height=s+1;const A=a.getContext("2d");if(!A)return null;for(const l of t)l?.image&&A.drawImage(l.image,0,0,r,s);A.globalCompositeOperation="destination-in",A.drawImage(e.image,0,0,r,s),A.globalCompositeOperation="source-over";const c=new IE(a);return c.colorSpace=Uv,c.generateMipmaps=!1,c.minFilter=xl,c.magFilter=xl,c.premultiplyAlpha=!1,c.needsUpdate=!0,c};function znn({circuitJson:t,boardData:e,traceTextureResolution:n,visibility:o}){const i=Vnn(Yc.copper),r="rgb(255,255,255)",s=Vnn(Yc.copper),a=o?.boardBody??!0,A=u=>{const h=(u==="top"?o?.topMask:o?.bottomMask)??!0,d=(u==="top"?o?.topCopper:o?.bottomCopper)??!0,m=(u==="top"?o?.topSilkscreen:o?.bottomSilkscreen)??!0,p=o?.keepout??!0,_=h?Dfi({layer:u,circuitJson:t,boardData:e,traceTextureResolution:n}):null,f=d?Z_i({layer:u,circuitJson:t,boardData:e,traceColor:i,traceTextureResolution:n}):null,I=d?Gnn({layer:u,circuitJson:t,boardData:e,traceTextureResolution:n,copperColor:s}):null,C=h&&d?Gnn({layer:u,circuitJson:t,boardData:e,traceTextureResolution:n,copperColor:s,onlyCoveredBySoldermask:!0}):null,y=d?ofi({layer:u,circuitJson:t,boardData:e,copperColor:s,traceTextureResolution:n}):null,x=d?W_i({layer:u,circuitJson:t,boardData:e,copperColor:s,traceTextureResolution:n}):null,E=d?Tfi({layer:u,circuitJson:t,boardData:e,copperColor:s,traceTextureResolution:n}):null,B=m?Pfi({layer:u,circuitJson:t,boardData:e,silkscreenColor:r,traceTextureResolution:n,soldermaskVisible:h}):null,b=m?hfi({layer:u,circuitJson:t,boardData:e,traceTextureResolution:n}):null,w=o?.pcbNotes??!1?Efi({layer:u,circuitJson:t,boardData:e,traceTextureResolution:n}):null,D=a?q_i({layer:u,circuitJson:t,panelData:e,traceTextureResolution:n}):null,k=p?ffi({layer:u,circuitJson:t,boardData:e,traceTextureResolution:n}):null,T=Ffi({textures:[I,f,x,E,_,y,B,b,w,D,k],boardData:e,traceTextureResolution:n,layer:u}),H=h&&d?Lfi({textures:[f,C],soldermaskTexture:_,boardData:e,traceTextureResolution:n}):null;return{boardTexture:T,maskedCopperTexture:H}},c=e.num_layers??2,l=A("top"),g=c<2?null:A("bottom");return{topBoard:l.boardTexture,bottomBoard:g?.boardTexture??null,topMaskedCopper:l.maskedCopperTexture,bottomMaskedCopper:g?.maskedCopperTexture??null}}var PQ={bumpScale:.12,normalScale:.08,roughnessBias:.015,clearcoat:.08,clearcoatRoughness:.55},vhe={roughness:.42,metalness:.5,roughnessVariance:.035,detailStrength:.028},Phe=.22,Hfi=.7,Ofi=.86,Jnn={height:Phe,microSurfaceWeight:1,roughness:.7,metalness:.015,isExposedCopper:!1,isMaskedCopper:!1},Gfi={height:Hfi,microSurfaceWeight:.9,roughness:.54,metalness:.025,isExposedCopper:!1,isMaskedCopper:!0},nKe=t=>Math.max(0,Math.min(1,t)),Wnn=t=>1-t,xX=(t,e,n)=>{let o=Math.imul(t,374761393)^Math.imul(e,668265263)^n;return o=Math.imul(o^o>>>13,1274126177),((o^o>>>16)>>>0)/4294967295},jnn=t=>t*t*(3-2*t),oKe=(t,e,n)=>t+(e-t)*n,iKe=(t,e,n,o)=>{const i=t/n,r=e/n,s=Math.floor(i),a=Math.floor(r),A=jnn(i-s),c=jnn(r-a),l=oKe(xX(s,a,o),xX(s+1,a,o),A),g=oKe(xX(s,a+1,o),xX(s+1,a+1,o),A);return oKe(l,g,c)},Yfi=(t,e,n)=>{const o=(iKe(t,e,7,n+31)-.5)*.55,i=Math.sin(t*.12+iKe(t,e,44,n+37)*2)*.22;return(o+i)*vhe.detailStrength},Ufi=(t,e,n)=>{const o=(xX(t,e,n+53)-.5)*.42,i=Math.sin(t*.26+e*.06)*.2+Math.sin(e*.31-t*.04)*.12;return(o+i)*.045},Kfi=(t,e,n,o)=>o?Gfi:b_i({red:t,green:e,blue:n})?Jnn:t>120&&e>70&&n<150&&t>e*1.05&&e>n*1.15?{height:Ofi,microSurfaceWeight:.9,roughness:vhe.roughness,metalness:vhe.metalness,isExposedCopper:!0,isMaskedCopper:!1}:t>170&&e>170&&n>160?{height:Phe,microSurfaceWeight:.4,roughness:.76,metalness:0,isExposedCopper:!1,isMaskedCopper:!1}:e>t*1.25&&e>n*1.05&&t<110&&e<180&&n<130?Jnn:{height:Phe,microSurfaceWeight:.7,roughness:.58,metalness:.015,isExposedCopper:!1,isMaskedCopper:!1},whe=t=>{const e=new IE(t);return e.colorSpace=Uv,e.generateMipmaps=!1,e.minFilter=xl,e.magFilter=xl,e.wrapS=w1,e.wrapT=w1,e.needsUpdate=!0,e},qnn=(t,e)=>{const n=t.image;if(!n?.width||!n.height)return null;const o=n.getContext("2d");if(!o)return null;const i=e?.image,r=i?.getContext("2d"),s=i?.width??0,a=i?.height??0,A=r&&s&&a?r.getImageData(0,0,s,a):null,c=o.getImageData(0,0,n.width,n.height),l=c.data,g=new Float32Array(n.width*n.height),u=document.createElement("canvas"),h=document.createElement("canvas");u.width=h.width=n.width,u.height=h.height=n.height;const d=u.getContext("2d"),m=h.getContext("2d");if(!d||!m)return null;const p=d.createImageData(n.width,n.height),_=m.createImageData(n.width,n.height),f=p.data,I=_.data;for(let w=0;w<l.length;w+=4){const D=w/4,k=D%n.width,T=Math.floor(D/n.width);if((l[w+3]??0)<16){g[D]=Wnn(Phe);continue}const G=A?Math.min(s-1,Math.floor(k/n.width*s)):0,U=A?Math.min(a-1,Math.floor(T/n.height*a)):0,Y=A?A.data[(U*s+G)*4+3]??0:0,q=Kfi(l[w]??0,l[w+1]??0,l[w+2]??0,Y>=16),ee=n.width+n.height,W=q.isExposedCopper?Yfi(k,T,ee):q.isMaskedCopper?Ufi(k,T,ee):0,J=nKe(Wnn(q.height)+W*q.microSurfaceWeight);g[D]=J;const ie=J*255;l[w]=l[w+1]=l[w+2]=ie,l[w+3]=255;const ne=(q.isExposedCopper?nKe(q.roughness+W*.7+(iKe(k,T,36,ee+17)-.5)*vhe.roughnessVariance):q.isMaskedCopper?nKe(q.roughness+W+PQ.roughnessBias):q.roughness)*255;f[w]=f[w+1]=f[w+2]=ne,f[w+3]=255;const le=q.metalness*255;I[w]=I[w+1]=I[w+2]=le,I[w+3]=255}d.putImageData(p,0,0),m.putImageData(_,0,0);const C=document.createElement("canvas");C.width=n.width,C.height=n.height;const y=C.getContext("2d");if(!y)return null;y.putImageData(c,0,0);const x=document.createElement("canvas");x.width=n.width,x.height=n.height;const E=x.getContext("2d");if(!E)return null;const B=E.createImageData(n.width,n.height),b=B.data,Q=(w,D)=>g[Math.max(0,Math.min(n.height-1,D))*n.width+Math.max(0,Math.min(n.width-1,w))]??0;for(let w=0;w<n.height;w++)for(let D=0;D<n.width;D++){const k=(Q(D+1,w)-Q(D-1,w))*4,T=(Q(D,w+1)-Q(D,w-1))*4,H=new jt(-k,-T,1).normalize(),G=(w*n.width+D)*4;b[G]=(H.x*.5+.5)*255,b[G+1]=(H.y*.5+.5)*255,b[G+2]=(H.z*.5+.5)*255,b[G+3]=255}return E.putImageData(B,0,0),{bumpMap:whe(C),normalMap:whe(x),roughnessMap:whe(u),metalnessMap:whe(h)}};function Xnn(t,e){const{texture:n,maskedCopperMask:o,yOffset:i,isBottomLayer:r,usePolygonOffset:s=!1,renderOrder:a=0,isFaux:A=!1}=t;if(!n)return null;const c=gy(e),l=new BQ(c.width,c.height);n.colorSpace=mE;const g={map:n,transparent:!0,alphaTest:.08,side:q2,depthWrite:!0,polygonOffset:s,polygonOffsetFactor:s?-4:0,polygonOffsetUnits:s?-4:0,opacity:A?xhe:1},u=qnn(n,o),h=new eB({...g,bumpMap:u?.bumpMap??null,bumpScale:PQ.bumpScale,normalMap:u?.normalMap??null,normalScale:new Jo(PQ.normalScale,PQ.normalScale),roughnessMap:u?.roughnessMap??null,roughness:1,metalnessMap:u?.metalnessMap??null,metalness:1,clearcoat:PQ.clearcoat,clearcoatRoughness:PQ.clearcoatRoughness,envMapIntensity:.18}),d=new Dr(l,h);return d.position.set(c.centerX,c.centerY,i),r&&d.rotation.set(Math.PI,0,0),d.name=`${r?"bottom":"top"}-board-texture-plane`,d.renderOrder=a,QQ(d,{castShadow:!1,receiveShadow:!0}),d}function Vfi(t,e,n,o=!1){const i=[];if(!t||!e||n===null)return i;const r=.005,s=Xnn({texture:t.topBoard,maskedCopperMask:t.topMaskedCopper,yOffset:n/2+r,isBottomLayer:!1,usePolygonOffset:!0,renderOrder:1,isFaux:o},e);s&&i.push(s);const a=Xnn({texture:t.bottomBoard,maskedCopperMask:t.bottomMaskedCopper,yOffset:-n/2-r,isBottomLayer:!0,usePolygonOffset:!0,renderOrder:1,isFaux:o},e);return a&&i.push(a),i}var zfi=4e6,Jfi=4096,Wfi=1;function $nn(t,e,n={}){const{maxTexturePixels:o=zfi,maxTextureDimension:i=Jfi,minTextureResolution:r=Wfi}=n,s=gy(t);if(!Number.isFinite(s.width)||!Number.isFinite(s.height)||s.width<=0||s.height<=0)return e;const a=Math.max(s.width,s.height),A=i/a,c=Math.sqrt(o/(s.width*s.height)),l=Math.min(e,A,c);return Math.max(r,l)}function jfi({circuitJson:t,pcbThickness:e,isFaux:n=!1}){const{rootObject:o}=jI(),{visibility:i}=pR(),r=te.useMemo(()=>{const A=t.filter(g=>g.type==="pcb_panel"),c=Cr(t).pcb_board.list();if(A.length>0){const g=A[0],u=c.find(h=>h.pcb_panel_id===g.pcb_panel_id);return{type:"pcb_board",pcb_board_id:g.pcb_panel_id,center:g.center,width:g.width,height:g.height,thickness:u?.thickness??1.4,material:u?.material??"fr4",num_layers:u?.num_layers??2,solder_mask_color:u?.solder_mask_color}}const l=c.filter(g=>!g.pcb_panel_id);return l.length>0?l[0]:null},[t]),s=te.useMemo(()=>r?$nn(r,jS):jS,[r]),a=te.useMemo(()=>!r?.width||!r.height?null:znn({circuitJson:t,boardData:r,traceTextureResolution:s,visibility:i}),[t,r,s,i]);return te.useEffect(()=>{if(!o||!r||!a)return;const A=[],c=d=>{const m=["map","alphaMap","aoMap","bumpMap","displacementMap","emissiveMap","lightMap","metalnessMap","normalMap","roughnessMap","specularMap"],p=d;for(const _ of m){const f=p[_];f&&f instanceof Bd&&(f.dispose(),p[_]=null)}d.dispose()},l=({texture:d,maskedCopperMask:m,zOffset:p,isBottomLayer:_,name:f,usePolygonOffset:I=!1,depthWrite:C=!0,renderOrder:y=1})=>{if(!d)return null;const x=gy(r),E=new BQ(x.width,x.height);d.colorSpace=mE;const B={map:d,transparent:!0,alphaTest:.08,side:q2,depthWrite:C,polygonOffset:I,polygonOffsetFactor:I?-4:0,polygonOffsetUnits:I?-4:0,opacity:n?xhe:1},b=qnn(d,m),Q=new eB({...B,bumpMap:b?.bumpMap??null,bumpScale:PQ.bumpScale,normalMap:b?.normalMap??null,normalScale:new Jo(PQ.normalScale,PQ.normalScale),roughnessMap:b?.roughnessMap??null,roughness:1,metalnessMap:b?.metalnessMap??null,metalness:1,clearcoat:PQ.clearcoat,clearcoatRoughness:PQ.clearcoatRoughness,envMapIntensity:.18}),w=new Dr(E,Q);return w.position.set(x.centerX,x.centerY,p),_&&w.rotation.set(Math.PI,0,0),w.name=f,w.renderOrder=y,w.frustumCulled=!1,QQ(w,{castShadow:!1,receiveShadow:!0}),w},g=.005,u=l({texture:a.topBoard,maskedCopperMask:a.topMaskedCopper,zOffset:e/2+g,isBottomLayer:!1,name:"jscad-top-board-texture",usePolygonOffset:!0});u&&(A.push(u),o.add(u));const h=l({texture:a.bottomBoard,maskedCopperMask:a.bottomMaskedCopper,zOffset:-e/2-g,isBottomLayer:!0,name:"jscad-bottom-board-texture",usePolygonOffset:!0});return h&&(A.push(h),o.add(h)),()=>{for(const d of A)if(d.parent===o&&o.remove(d),d.geometry.dispose(),Array.isArray(d.material))for(const m of d.material)c(m);else d.material instanceof _E&&c(d.material);a.topBoard?.dispose(),a.bottomBoard?.dispose()}},[o,r,a,e]),null}function qfi({stlUrl:t,stlData:e,mtlUrl:n,color:o,opacity:i=1,layerType:r}){const{rootObject:s}=jI(),[a,A]=te.useState(null);te.useEffect(()=>{const l=new rjo;if(e){try{const g=l.parse(e);A(g)}catch(g){console.error("Failed to parse STL data",g),A(null)}return}t&&l.load(t,g=>{A(g)})},[t,e]);const c=te.useMemo(()=>{if(!a)return null;const l=r==="board",g=new pu({color:Array.isArray(o)?new Yi(o[0],o[1],o[2]):o,transparent:i!==1,opacity:i,polygonOffset:l,polygonOffsetFactor:l?6:0,polygonOffsetUnits:l?6:0}),u=new Dr(a,g);return u.renderOrder=l?-1:1,QQ(u,{castShadow:!l&&i===1,receiveShadow:!0}),u},[a,o,i,r]);return te.useEffect(()=>{if(!(!s||!c))return s.add(c),()=>{s.remove(c),c.geometry.dispose(),Array.isArray(c.material)?c.material.forEach(l=>l.dispose()):c.material.dispose()}},[s,c]),null}function Xfi({stlData:t,color:e,opacity:n=1,layerType:o}){const{visibility:i}=pR();let r=!0;return o==="board"?r=i.boardBody:o==="top-copper"?r=i.topCopper:o==="bottom-copper"?r=i.bottomCopper:o==="top-silkscreen"?r=i.topSilkscreen:o==="bottom-silkscreen"&&(r=i.bottomSilkscreen),r?K.jsx(qfi,{stlData:t,color:e,opacity:n,layerType:o}):null}function $fi(t){const e=Cr(t).cad_component.list(),n=Cr(t).pcb_smtpad.list(),o=Cr(t).pcb_hole.list(),i=Cr(t).pcb_plated_hole.list(),r=Cr(t).pcb_via.list();if(e.length===0&&n.length===0&&o.length===0&&i.length===0&&r.length===0)return null;const s=[...o,...i,...r,...n],a=rw(s);let A=a.minX,c=a.maxX,l=a.minY,g=a.maxY;for(const f of e)if(f.position){const I=f.position.x,C=f.position.y;A=Math.min(A,I),c=Math.max(c,I),l=Math.min(l,C),g=Math.max(g,C)}A===1/0&&(A=-10,c=10,l=-10,g=10);const u=2,h=Math.max(Math.abs(A),Math.abs(c))+u,d=Math.max(Math.abs(l),Math.abs(g))+u,m=Math.max(2*h,10),p=Math.max(2*d,10);return{type:"pcb_board",pcb_board_id:"faux-board",center:{x:0,y:0},width:m,height:p,thickness:1.4,material:"fr4",num_layers:2}}function Znn(t){if(Cr(t).pcb_board.list().length>0)return t;const n=$fi(t);if(!n)return t;const i=n.thickness/2;return[...t.map(s=>{if(s.type==="cad_component"){const a=s;if(a.position){const A=a.position.z??0;return{...a,position:{...a.position,z:A+i}}}}return s}),n]}var Zfi=te.forwardRef(({circuitJson:t,children:e,autoRotateDisabled:n,clickToInteractEnabled:o,onUserInteraction:i,onCameraControllerReady:r,resolveStaticAsset:s,referenceObject:a},A)=>{const c=Nnn(e),l=te.useMemo(()=>Znn(t??c),[t,c]),g=K_i(l),u=te.useMemo(()=>{if(!l)return[5,-5,5];try{const I=Cr(l).pcb_board.list()[0];if(!I)return[5,-5,5];const{width:C,height:y}=I;if(!C&&!y)return[5,-5,5];const x=5,E=Math.max(C,x),B=Math.max(y,x),b=Math.max(E,B);return[b*.4,-b*.7,b*.9]}catch(I){return console.error(I),[5,-5,5]}},[l]),h=te.useMemo(()=>{if(!l)return!1;try{const I=Cr(l).pcb_board.list()[0];return!!I&&I.pcb_board_id==="faux-board"}catch{return!1}},[l]),d=te.useMemo(()=>{if(l)try{const I=Cr(l).pcb_board.list()[0];if(!I)return;const C=gy(I);return{width:C.width,height:C.height}}catch(I){console.error(I);return}},[l]),m=te.useMemo(()=>{if(l)try{const I=Cr(l).pcb_board.list()[0];if(!I)return;const C=gy(I);return{x:C.centerX,y:C.centerY}}catch(I){console.error(I);return}},[l]),p=jen(l),{stls:_}=c_i(g),f=Cr(l).cad_component.list();return K.jsxs(Dnn,{ref:A,autoRotateDisabled:n,initialCameraPosition:u,clickToInteractEnabled:o,boardDimensions:d,boardCenter:m,referenceObject:a,onUserInteraction:i,onCameraControllerReady:r,children:[_.map(({stlData:I,color:C,layerType:y},x)=>K.jsx(Xfi,{stlData:I,color:C,opacity:x===0?h?.8:.95:1,layerType:y},`board-${x}`)),K.jsx(jfi,{circuitJson:l,pcbThickness:p,isFaux:h}),f.map(I=>K.jsx(UUe,{fallback:({error:C})=>K.jsx(Onn,{cad_component:I,error:C}),children:K.jsx(xnn,{cad_component:I,circuitJson:l,resolveStaticAsset:s},I.cad_component_id)},I.cad_component_id))]})}),eIi=t=>{let e=0;for(let o=0;o<t.length;o++){const i=(o+1)%t.length;t[o]&&t[i]&&(e+=t[o][0]*t[i][1],e-=t[i][0]*t[o][1])}return e/2<=0};function tIi(t,e,n,o,i){let r,s=null;if(n.outline&&n.outline.length>=3){let a=n.outline.map(c=>[c.x,c.y]);eIi(a)&&(a=a.reverse());const A=e.ofPolygons([a]);i.push(A),s=A,r=t.extrude(A,o,void 0,void 0,void 0,!0),i.push(r)}else n.outline&&n.outline.length>0&&console.warn("Board outline has fewer than 3 points, falling back to rectangular board."),r=t.cube([n.width,n.height,o],!0),i.push(r),r=r.translate([n.center.x,n.center.y,0]),i.push(r);return{boardOp:r,outlineCrossSection:s}}var nIi=64;function yR({Manifold:t,width:e,height:n,thickness:o,borderRadius:i}){const r=Lnn(e,n,i);if(r<=0)return t.cube([e,n,o],!0);const s=[],a=e-2*r,A=n-2*r;return a>0&&s.push(t.cube([a,n,o],!0)),A>0&&s.push(t.cube([e,A,o],!0)),[[e/2-r,n/2-r],[-e/2+r,n/2-r],[-e/2+r,-n/2+r],[e/2-r,-n/2+r]].forEach(([l,g])=>{s.push(t.cylinder(o,r,r,nIi,!0).translate([l,g,0]))}),t.union(s)}var oIi=t=>{let e=0;for(let o=0;o<t.length;o++){const i=(o+1)%t.length;t[o]&&t[i]&&(e+=t[o][0]*t[i][1],e-=t[i][0]*t[o][1])}return e/2<=0};function iIi(t,e,n,o,i){const r=[],s=Cr(n).pcb_cutout.list();for(const a of s){let A;const c=o*1.5;switch(a.shape){case"rect":{const u=w9(a);if(typeof u=="number"&&u>0?A=yR({Manifold:t,width:a.width,height:a.height,thickness:c,borderRadius:u}):A=t.cube([a.width,a.height,c],!0),i.push(A),a.rotation){const h=A.rotate([0,0,a.rotation]);i.push(h),A=h}A=A.translate([a.center.x,a.center.y,0]),i.push(A);break}case"circle":A=t.cylinder(c,a.radius,-1,W_,!0),i.push(A),A=A.translate([a.center.x,a.center.y,0]),i.push(A);break;case"polygon":if(a.points.length<3){console.warn(`PCB Cutout [${a.pcb_cutout_id}] polygon has fewer than 3 points, skipping.`);continue}let l=a.points.map(u=>[u.x,u.y]);oIi(l)&&(l=l.reverse());const g=e.ofPolygons([l]);i.push(g),A=t.extrude(g,c,0,0,[1,1],!0),i.push(A);break;default:console.warn(`Unsupported cutout shape: ${a.shape} for cutout ${a.pcb_cutout_id}`);continue}A&&r.push(A)}return{cutoutOps:r}}function eon({Manifold:t,x:e,y:n,diameter:o,thickness:i,segments:r=32}){return t.cylinder(i*1.2,o/2,o/2,r,!0).translate([e,n,0])}function ton({Manifold:t,x:e,y:n,holeDiameter:o,thickness:i,zOffset:r=.001,segments:s=32}){const a=o/2+r;return t.cylinder(i*1.2,a,a,s,!0).translate([e,n,0])}function rIi(t,e,n,o,i){const r=[],s=Cr(n).pcb_hole.list(),a=(l,g,u)=>{const h=yR({Manifold:t,width:l,height:g,thickness:u,borderRadius:Math.min(l,g)/2});return i.push(h),h},A=(l,g,u)=>{const h=t.cube([l,g,u],!0);return i.push(h),h},c=(l,g,u)=>{const h=[];for(let d=0;d<u;d++){const m=2*Math.PI*d/u;h.push([l/2*Math.cos(m),g/2*Math.sin(m)])}return h};for(const l of s){const g=l.hole_shape,u=l.x,h=l.y,d=o*1.2,m=l.ccw_rotation??l.rotation??0,p=l.hole_width??l.hole_diameter,_=l.hole_height??l.hole_diameter;let f=null;if(g==="circle"){f=eon({Manifold:t,x:u,y:h,diameter:l.hole_diameter,thickness:o,segments:W_}),r.push(f),i.push(f);continue}if(g==="pill"||g==="rotated_pill")f=a(p,_,d);else if(g==="rect")f=A(p,_,d);else if(g==="oval"){let I=c(p,_,W_),C=0;for(let x=0;x<I.length;x++){const E=(x+1)%I.length;C+=I[x][0]*I[E][1],C-=I[E][0]*I[x][1]}C<=0&&(I=I.reverse());const y=e.ofPolygons([I]);i.push(y),f=t.extrude(y,d,0,0,[1,1],!0),i.push(f)}if(f){if(m!==0){const C=f.rotate([0,0,m]);i.push(C),f=C}const I=f.translate([u,h,0]);i.push(I),r.push(I)}}return{nonPlatedHoleBoardDrills:r}}function oP(t){const e=new tg;if(e.setAttribute("position",new Ds(t.vertProperties,3)),e.setIndex(new K8e(t.triVerts,1)),t.runIndex&&t.runIndex.length>1&&t.runOriginalID)for(let n=0;n<t.runIndex.length-1;n++){const o=t.runIndex[n],i=t.runIndex[n+1]-o;e.addGroup(o,i,0)}else e.addGroup(0,t.triVerts.length,0);return e}var EX=t=>{let e=0;for(let o=0;o<t.length;o++){const i=(o+1)%t.length;t[o]&&t[i]&&(e+=t[o][0]*t[i][1],e-=t[i][0]*t[o][1])}return e/2<=0},Mhe=(t,e,n)=>{const o=[];for(let i=0;i<n;i++){const r=2*Math.PI*i/n;o.push([t/2*Math.cos(r),e/2*Math.sin(r)])}return o},xR=new Yi(...Yc.copper),Dhe=.05,BX=.003,SX=5e-4,bX=.004;function sIi(t,e,n,o,i,r){const s=[],a=Cr(n).pcb_plated_hole.list(),A=[],c=[],l=(d,m,p)=>{const _=yR({Manifold:t,width:d,height:m,thickness:p,borderRadius:Math.min(d,m)/2});return i.push(_),_},g=({padOutline:d,thickness:m})=>{if(!Array.isArray(d)||d.length<3)return null;let p=d.map(I=>[I.x,I.y]);EX(p)&&(p=p.reverse());const _=e.ofPolygons([p]);i.push(_);const f=t.extrude(_,m,0,0,[1,1],!0);return i.push(f),f},u=({ph:d,depth:m,sizeDelta:p=0})=>{if(d.shape!=="hole_with_polygon_pad")return null;const f=d.pad_outline;if(!Array.isArray(f)||f.length<3)return null;const I=d.hole_shape||"circle",C=d.hole_offset_x||0,y=d.hole_offset_y||0;let x=null;if(I==="circle"){const E=Math.max((d.hole_diameter??0)+p,ms),B=Math.max(E/2,ms/2);x=t.cylinder(m,B,B,W_,!0),i.push(x)}else{const E=d.hole_width??d.hole_diameter,B=d.hole_height??d.hole_diameter;if(!E||!B)return null;const b=Math.max(E+p,ms),Q=Math.max(B+p,ms);if(I==="oval"){let w=Mhe(b,Q,W_);EX(w)&&(w=w.reverse());const D=e.ofPolygons([w]);i.push(D),x=t.extrude(D,m,0,0,[1,1],!0),i.push(x)}else(I==="pill"||I==="rotated_pill")&&(x=yR({Manifold:t,width:b,height:Q,thickness:m,borderRadius:Math.min(b,Q)/2}),i.push(x))}if(!x)return null;if(C||y){const E=x.translate([C,y,0]);i.push(E),x=E}return x};a.forEach((d,m)=>{const p=Math.max(o-2*(BX+SX+bX),ms);if(d.shape==="circle"){const _=ton({Manifold:t,x:d.x,y:d.y,holeDiameter:d.hole_diameter*1.02,thickness:o,zOffset:vQ,segments:W_});i.push(_),s.push(_);const f=p,I=t.cylinder(f,d.outer_diameter/2,d.outer_diameter/2,W_,!0);i.push(I);const C=t.cylinder(f*1.05,d.hole_diameter/2,d.hole_diameter/2,W_,!0);i.push(C);const y=I.subtract(C);i.push(y);const x=y.translate([d.x,d.y,0]);i.push(x);let E=x;if(r){const b=t.intersection([x,r]);i.push(b),E=b}c.push(E);const B=oP(E.getMesh());A.push({key:`ph-${d.pcb_plated_hole_id||m}`,geometry:B,color:xR})}else if(d.shape==="pill"){const _=d.hole_width,f=d.hole_height,I=.4,C=d.outer_width??_+I,y=d.outer_height??f+I,x=_+2*vQ,E=f+2*vQ,B=o*1.2;let b=l(x,E,B);if(d.ccw_rotation){const Y=b.rotate([0,0,d.ccw_rotation]);i.push(Y),b=Y}const Q=b.translate([d.x,d.y,0]);i.push(Q),s.push(Q);const w=p,D=l(C,y,w),k=l(_,f,w*1.05);let T=D.subtract(k);if(i.push(T),d.ccw_rotation){const Y=T.rotate([0,0,d.ccw_rotation]);i.push(Y),T=Y}const H=T.translate([d.x,d.y,0]);i.push(H);let G=H;if(r){const Y=t.intersection([H,r]);i.push(Y),G=Y}c.push(G);const U=oP(G.getMesh());A.push({key:`ph-${d.pcb_plated_hole_id||m}`,geometry:U,color:xR})}else if(d.shape==="pill_hole_with_rect_pad"){if(d.hole_shape&&d.hole_shape!=="pill"||d.pad_shape&&d.pad_shape!=="rect")return;const _=d.hole_width,f=d.hole_height,I=d.hole_offset_x||0,C=d.hole_offset_y||0,y=d.rect_pad_width,x=d.rect_pad_height,E=w9(d),B=BX,b=_+2*vQ,Q=f+2*vQ,w=o*1.2,k=l(b,Q,w).translate([I,C,0]).translate([d.x,d.y,0]);i.push(k),s.push(k);const T=yR({Manifold:t,width:y,height:x,thickness:Math.max(o-2*(B+SX+bX),ms),borderRadius:E});i.push(T);const H=l(_,f,o*.8).translate([I,C,0]);i.push(H);const G=t.union([T,H]);i.push(G);const U=l(Math.max(_-2*Dhe,.01),Math.max(f-2*Dhe,.01),o*1.2).translate([I,C,0]);i.push(U);const Y=G.subtract(U);i.push(Y);const q=Y.translate([d.x,d.y,0]);i.push(q);let ee=q;if(r){const J=t.intersection([q,r]);i.push(J),ee=J}c.push(ee);const W=oP(ee.getMesh());A.push({key:`ph-${d.pcb_plated_hole_id||m}`,geometry:W,color:xR})}else if(d.shape==="rotated_pill_hole_with_rect_pad"){if(d.hole_shape&&d.hole_shape!=="rotated_pill"||d.pad_shape&&d.pad_shape!=="rect")return;const _=d.hole_width,f=d.hole_height,I=d.hole_offset_x||0,C=d.hole_offset_y||0,y=d.rect_pad_width,x=d.rect_pad_height,E=w9(d),B=BX,b=_+2*vQ,Q=f+2*vQ,w=o*1.2;let D=l(b,Q,w).translate([I,C,0]);if(d.hole_ccw_rotation){const J=D.rotate([0,0,d.hole_ccw_rotation]);i.push(J),D=J}const k=D.translate([d.x,d.y,0]);i.push(k),s.push(k);let T=yR({Manifold:t,width:y,height:x,thickness:Math.max(o-2*(B+SX+bX),ms),borderRadius:E});if(i.push(T),d.rect_ccw_rotation){const J=T.rotate([0,0,d.rect_ccw_rotation]);i.push(J),T=J}let H=l(_,f,o*.8).translate([I,C,0]);if(d.hole_ccw_rotation){const J=H.rotate([0,0,d.hole_ccw_rotation]);i.push(J),H=J}i.push(H);const G=t.union([T,H]);i.push(G);let U=l(Math.max(_-2*Dhe,.01),Math.max(f-2*Dhe,.01),o*1.2).translate([I,C,0]);if(d.hole_ccw_rotation){const J=U.rotate([0,0,d.hole_ccw_rotation]);i.push(J),U=J}i.push(U);const Y=G.subtract(U);i.push(Y);const q=Y.translate([d.x,d.y,0]);i.push(q);let ee=q;if(r){const J=t.intersection([q,r]);i.push(J),ee=J}c.push(ee);const W=oP(ee.getMesh());A.push({key:`ph-${d.pcb_plated_hole_id||m}`,geometry:W,color:xR})}else if(d.shape==="hole_with_polygon_pad"){const _=d.pad_outline;if(!Array.isArray(_)||_.length<3)return;const f=u({ph:d,depth:o*1.2,sizeDelta:2*ms});if(!f)return;const I=f.translate([d.x,d.y,0]);i.push(I),s.push(I);const y=Math.max(o-2*(BX+SX+bX),ms),x=g({padOutline:_,thickness:y});if(!x)return;const E=u({ph:d,depth:o*1.02});if(!E)return;const B=u({ph:d,depth:o*.8,sizeDelta:-2*ms})||E,b=t.union([x,E]);i.push(b);const Q=b.subtract(B);i.push(Q);const w=Q.translate([d.x,d.y,0]);i.push(w);let D=w;if(r){const T=t.intersection([w,r]);i.push(T),D=T}c.push(D);const k=oP(D.getMesh());A.push({key:`ph-${d.pcb_plated_hole_id||m}`,geometry:k,color:xR})}else if(d.shape==="oval"){const _=d.hole_width,f=d.hole_height,I=d.outer_width??_+.4,C=d.outer_height??f+.4,y=_+2*vQ,x=f+2*vQ,E=o*1.2;let B=Mhe(y,x,W_);EX(B)&&(B=B.reverse());const b=e.ofPolygons([B]);i.push(b);let Q=t.extrude(b,E,0,0,[1,1],!0);if(i.push(Q),d.ccw_rotation){const ie=Q.rotate([0,0,d.ccw_rotation]);i.push(ie),Q=ie}const w=Q.translate([d.x,d.y,0]);i.push(w),s.push(w);const D=p;let k=Mhe(I,C,W_);EX(k)&&(k=k.reverse());const T=e.ofPolygons([k]);i.push(T);const H=t.extrude(T,D,0,0,[1,1],!0);i.push(H);let G=Mhe(_,f,W_);EX(G)&&(G=G.reverse());const U=e.ofPolygons([G]);i.push(U);const Y=t.extrude(U,D*1.05,0,0,[1,1],!0);i.push(Y);let q=H.subtract(Y);if(i.push(q),d.ccw_rotation){const ie=q.rotate([0,0,d.ccw_rotation]);i.push(ie),q=ie}const ee=q.translate([d.x,d.y,0]);i.push(ee);let W=ee;if(r){const ie=t.intersection([ee,r]);i.push(ie),W=ie}c.push(W);const J=oP(W.getMesh());A.push({key:`ph-${d.pcb_plated_hole_id||m}`,geometry:J,color:xR})}else if(d.shape==="circular_hole_with_rect_pad"){if(d.hole_shape&&d.hole_shape!=="circle"||d.pad_shape&&d.pad_shape!=="rect")return;const _=d.hole_offset_x||0,f=d.hole_offset_y||0,I=eon({Manifold:t,x:d.x+_,y:d.y+f,diameter:d.hole_diameter,thickness:o,segments:W_});i.push(I),s.push(I);const C=d.rect_pad_width??d.hole_diameter,y=d.rect_pad_height??d.hole_diameter,x=w9(d),E=BX,B=d.hole_diameter/2,b=yR({Manifold:t,width:C,height:y,thickness:Math.max(o-2*(E+SX+bX),ms),borderRadius:x});i.push(b);const Q=t.cylinder(o*.8,B,B,W_,!0).translate([_,f,0]);i.push(Q);const w=t.union([b,Q]);i.push(w);const D=t.cylinder(o*1.2,Math.max(B-ms,.01),Math.max(B-ms,.01),W_,!0).translate([_,f,0]);i.push(D);const k=w.subtract(D);i.push(k);const T=k.translate([d.x,d.y,0]);i.push(T);let H=T;if(r){const U=t.intersection([T,r]);i.push(U),H=U}c.push(H);const G=oP(H.getMesh());A.push({key:`ph-${d.pcb_plated_hole_id||m}`,geometry:G,color:xR})}});let h;return c.length>0&&(h=t.union(c),i.push(h)),{platedHoleBoardDrills:s,platedHoleCopperGeoms:A,platedHoleSubtractOp:h}}function aIi({Manifold:t,x:e,y:n,outerDiameter:o,holeDiameter:i,thickness:r,zOffset:s=.001,segments:a=32}){const A=s;if(o<i)throw new Error(`Invalid via geometry: outerDiameter (${o}) must be >= holeDiameter (${i})`);const c=Math.min(o/2,i/2+A),g=t.cylinder(r,c,-1,a,!0),u=r+2*s,h=t.cylinder(u,i/2,-1,a,!0);return g.subtract(h).translate([e,n,0])}var AIi=new Yi(...Yc.copper);function cIi(t,e,n,o,i){const r=[],s=Cr(e).pcb_via.list(),a=[];return s.forEach((A,c)=>{if(typeof A.hole_diameter=="number"){const l=ton({Manifold:t,x:A.x,y:A.y,holeDiameter:A.hole_diameter,thickness:n,zOffset:vQ,segments:W_});o.push(l),r.push(l)}if(typeof A.outer_diameter=="number"&&typeof A.hole_diameter=="number"){const l=aIi({Manifold:t,x:A.x,y:A.y,outerDiameter:A.outer_diameter,holeDiameter:A.hole_diameter,thickness:n,zOffset:vQ,segments:W_});o.push(l);let g=l;if(i){const h=t.intersection([l,i]);o.push(h),g=h}const u=oP(g.getMesh());a.push({key:`via-${A.pcb_via_id||c}`,geometry:u,color:AIi})}}),{viaBoardDrills:r,viaCopperGeoms:a}}var lIi=(t,e,n)=>{const[o,i]=te.useState(null),[r,s]=te.useState(null),[a,A]=te.useState(null),[c,l]=te.useState(!0),g=te.useRef([]),u=te.useMemo(()=>{const p=e.filter(I=>I.type==="pcb_panel"),_=Cr(e).pcb_board.list();if(p.length>0){const I=p[0],C=_.find(y=>y.pcb_panel_id===I.pcb_panel_id);return{type:"pcb_board",pcb_board_id:I.pcb_panel_id,center:I.center,width:I.width,height:I.height,thickness:C?.thickness??1.4,material:C?.material??"fr4",num_layers:C?.num_layers??2,solder_mask_color:C?.solder_mask_color}}const f=_.filter(I=>!I.pcb_panel_id);return f.length>0?f[0]:null},[e]),h=te.useMemo(()=>{const p=Cr(e).pcb_board.list();return p.length>0&&p[0].pcb_board_id==="faux-board"},[e]),d=te.useMemo(()=>u?$nn(u,jS):jS,[u]);te.useEffect(()=>{if(!t||!u){i(null),s(null),l(!1);return}if((u.width===0||!u.width)&&(u.height===0||!u.height)&&(!u.outline||u.outline.length<3)){i({platedHoles:[],vias:[]}),s(u.thickness??0),l(!1);return}l(!0),A(null);const p=t.Manifold,_=t.CrossSection,f=y=>{if(!(!y||typeof y.delete!="function"))try{y.delete()}catch(x){(!(x instanceof Error)||!x.message?.includes("Manifold instance already deleted"))&&console.warn("Failed to delete Manifold instance",x)}};g.current.forEach(f),g.current=[];let I=null;const C={};try{const y=u.thickness||1.4;s(y);const{boardOp:x,outlineCrossSection:E}=tIi(p,_,u,y,g.current);let B=x;const Q=y+2*1;let w=null;const D=.01;if(E){let J=E;if(D>0){const oe=E.offset(D);g.current.push(oe),J=oe}const ie=p.extrude(J,Q,void 0,void 0,void 0,!0);g.current.push(ie),w=ie}else{const J=(u.width||0)+2*D,ie=(u.height||0)+2*D,oe=p.cube([J,ie,Q],!0);g.current.push(oe);const ne=oe.translate([u.center.x,u.center.y,0]);g.current.push(ne),w=ne}const k=[];let T=null;const{nonPlatedHoleBoardDrills:H}=rIi(p,_,e,y,g.current);k.push(...H);const{platedHoleBoardDrills:G,platedHoleCopperGeoms:U,platedHoleSubtractOp:Y}=sIi(p,_,e,y,g.current,w);k.push(...G),C.platedHoles=U;const{viaBoardDrills:q,viaCopperGeoms:ee}=cIi(p,e,y,g.current,w);if(k.push(...q),C.vias=ee,k.length>0){T=p.union(k),g.current.push(T);const J=Y?p.union([T,Y]):T;g.current.push(J);const ie=B.subtract(J);if(g.current.push(ie),B=ie,Y){const oe=Y.subtract(T);g.current.push(oe);const ne=oe.getMesh(),le=oP(ne);C.platedHoles=[{key:"plated-holes-union",geometry:le,color:new Yi(Yc.copper[0],Yc.copper[1],Yc.copper[2])}]}}const{cutoutOps:W}=iIi(p,_,e,y,g.current);if(W.length>0){const J=p.union(W);g.current.push(J);const ie=B.subtract(J);g.current.push(ie),B=ie}if(I=B,I){const J=I.getMesh(),ie=oP(J);C.board={geometry:ie,color:qUe(u),material:u.material,isFaux:h}}i(C)}catch(y){console.error("Error processing geometry with Manifold in hook:",y),A(y.message||"An unknown error occurred while processing geometry in hook."),i(null)}finally{l(!1)}return()=>{g.current.forEach(f),g.current=[]}},[t,e,u]);const m=te.useMemo(()=>!u||!d?null:znn({circuitJson:e,boardData:u,traceTextureResolution:d,visibility:n}),[e,u,d,n]);return{geoms:o,textures:m,pcbThickness:r,error:a,isLoading:c,boardData:u,isFauxBoard:h}},gIi=O_,uIi=({material:t,color:e,side:n=gIi,isFaux:o=!1})=>t==="fr4"?new eB({color:e,side:n,metalness:0,roughness:.48,specularIntensity:.3,ior:1.45,sheen:0,clearcoat:.16,clearcoatRoughness:.3,transparent:o,opacity:o?xhe:1,flatShading:!0,polygonOffset:!0,polygonOffsetFactor:1,polygonOffsetUnits:1}):new pu({color:e,side:n,flatShading:!0,metalness:.1,roughness:.8,transparent:!0,opacity:o?xhe:.9,polygonOffset:!0,polygonOffsetFactor:1,polygonOffsetUnits:1});function dIi(t){const e=[];if(!t)return e;if(t.board?.geometry){const o=new Dr(t.board.geometry,uIi({material:t.board.material,color:t.board.color,side:O_,isFaux:t.board.isFaux}));o.name="board-geom",QQ(o,{castShadow:!1,receiveShadow:!0}),e.push(o)}const n=o=>{if(o)for(const i of o){const r=new Dr(i.geometry,new pu({color:i.color,side:O_,flatShading:!0}));r.name=i.key,QQ(r),e.push(r)}};return n(t.platedHoles),n(t.vias),e}var hIi=({geometryMeshes:t,textureMeshes:e})=>{const{rootObject:n}=jI(),{visibility:o}=pR(),i=r=>{r.geometry.dispose();const s=Array.isArray(r.material)?r.material:[r.material];for(const a of s){if(!a)continue;const A=["map","alphaMap","aoMap","bumpMap","displacementMap","emissiveMap","lightMap","metalnessMap","normalMap","roughnessMap","specularMap"],c=a;for(const l of A){const g=c[l];g&&g instanceof Bd&&g.dispose()}a.dispose()}};return te.useEffect(()=>{if(n){for(const r of t){let s=!0;r.name==="board-geom"?s=o.boardBody:(r.name.includes("plated_hole")||r.name.includes("via"))&&(s=o.topCopper||o.bottomCopper),s&&n.add(r)}return()=>{for(const r of t)r.parent===n&&n.remove(r),i(r)}}},[n,t,o]),te.useEffect(()=>{if(n){for(const r of e)n.add(r);return()=>{for(const r of e)r.parent===n&&n.remove(r),i(r)}}},[n,e]),null},mIi="https://cdn.jsdelivr.net/npm/manifold-3d@3.2.1",pIi=({circuitJson:t,autoRotateDisabled:e,clickToInteractEnabled:n,onUserInteraction:o,children:i,onCameraControllerReady:r,resolveStaticAsset:s,referenceObject:a})=>{const A=Nnn(i),c=te.useMemo(()=>Znn(t??A),[t,A]),[l,g]=te.useState(null),[u,h]=te.useState(null),{visibility:d}=pR();te.useEffect(()=>{if(window.ManifoldModule&&typeof window.ManifoldModule=="object"&&window.ManifoldModule.setup){g(window.ManifoldModule);return}const D=async Y=>{try{const q=await Y();q.setup(),window.ManifoldModule=q,g(q)}catch(q){console.error("Failed to initialize Manifold:",q),h(`Failed to initialize Manifold: ${q instanceof Error?q.message:"Unknown error"}`)}},k=window.ManifoldModule??window.MANIFOLD??window.MANIFOLD_MODULE;if(k){window.ManifoldModule=k,D(window.ManifoldModule);return}const T="manifoldLoaded",H=()=>{const Y=window.ManifoldModule??window.MANIFOLD??window.MANIFOLD_MODULE;if(Y)window.ManifoldModule=Y,D(window.ManifoldModule);else{const q="ManifoldModule not found on window after script load.";console.error(q),h(q)}};window.addEventListener(T,H,{once:!0});const G=document.createElement("script");G.type="module",G.innerHTML=`
|
|
5518
5518
|
try {
|
|
5519
5519
|
const { default: ManifoldModule } = await import('${mIi}/manifold.js');
|
|
5520
5520
|
window.ManifoldModule = ManifoldModule;
|
|
@@ -5739,7 +5739,7 @@ test("${c} should solve problem correctly", () => {
|
|
|
5739
5739
|
// Add more specific assertions based on expected output
|
|
5740
5740
|
// expect(solver.netLabelPlacementSolver!.netLabelPlacements).toMatchInlineSnapshot()
|
|
5741
5741
|
})
|
|
5742
|
-
`,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 K.jsxs("div",{className:`relative ${e}`,ref:i,children:[K.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&&K.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:[K.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:r,children:"Download JSON"}),K.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),K.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:a,children:"Download test.ts"})]})]})},wcn=t=>t.activeSubSolver?[t,...wcn(t.activeSubSolver)]:[t],X4i=({solver:t})=>{const e=wcn(t);return K.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:e.map((n,o)=>K.jsxs("div",{className:"flex items-center",children:[o>0&&K.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),K.jsx(q4i,{solver:n})]},n.getSolverName()))})},$4i=({solver:t,triggerRender:e,animationSpeed:n=25,renderer:o,onRendererChange:i,onAnimationSpeedChange:r,onDownloadVisualization:s,onSolverStarted:a,onSolverCompleted:A})=>{const[c,l]=te.useReducer(B=>!B,!1),g=te.useRef(void 0),u=te.useRef(null),h="solver-debugger-last-iteration",[d,m]=te.useState(null),p=te.useRef(null),_=te.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 te.useEffect(()=>()=>{I()},[]),te.useEffect(()=>{(t.solved||t.failed)&&c&&(I(),l())},[t.solved,t.failed,c]),te.useEffect(()=>{c&&(I(),f())},[n,c]),te.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)}},[]),K.jsxs("div",{className:"space-y-2 p-2 border-b",children:[K.jsx("div",{className:"flex items-center",children:K.jsxs("div",{className:"flex items-center gap-2",ref:p,children:[K.jsxs("div",{className:"flex h-9 items-center space-x-1 rounded-md border border-slate-200 bg-white p-1 shadow-sm",children:[K.jsxs("div",{className:"relative",children:[K.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"&&K.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=>K.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&&K.jsx("span",{className:"ml-auto text-xs text-slate-500",children:"✓"})]},B))})]}),K.jsxs("div",{className:"relative",children:[K.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"&&K.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:K.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"})})]}),K.jsxs("div",{className:"relative",children:[K.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"&&K.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=>K.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,K.jsx("span",{className:"ml-auto text-xs text-slate-500",children:B.description}),n===B.value&&K.jsx("span",{className:"ml-2 text-xs text-slate-500",children:"✓"})]},B.value))})]})]}),K.jsx(X4i,{solver:t})]})}),K.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[K.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"}),K.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"}),K.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"}),K.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"}),K.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",t.iterations]}),t.timeToSolve!==void 0&&K.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(t.timeToSolve/1e3).toFixed(3),"s"]}),t.solved&&K.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),t.failed&&K.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),t.error&&K.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",t.error]})]})},Z4i=t=>t!==null&&"pipelineDef"in t&&Array.isArray(t.pipelineDef),e9i=(t,e,n)=>{const o=t.currentPipelineStageIndex;return e<o?"Completed":e===o&&t.activeSubSolver?t.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},t9i=(t,e)=>{const o=t.pipelineDef[e].solverName,i=e9i(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}},n9i=({status:t})=>{const e={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return K.jsx("span",{className:`font-medium ${e[t]}`,children:t})},o9i=({progress:t})=>{if(t===0)return null;const e=Math.round(t*100);return K.jsxs("div",{className:"flex items-center gap-2",children:[K.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:K.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${e}%`}})}),K.jsxs("span",{className:"text-xs text-gray-500",children:[e,"%"]})]})},Mcn=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)},i9i=t=>Object.entries(t).map(([e,n])=>`${e}: ${Mcn(n)}`).join(", "),r9i=({stats:t})=>{if(!t||Object.keys(t).length===0)return K.jsx("span",{children:"-"});const e=Object.entries(t),n=i9i(t);return K.jsxs("details",{className:"cursor-pointer",children:[K.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:n}),K.jsx("div",{className:"mt-1 text-xs",children:e.map(([o,i])=>K.jsxs("div",{children:[o,": ",Mcn(i)]},o))})]})},sJe=t=>{if(t===null||typeof t!="object")return t;if(Array.isArray(t))return t.map(sJe);const e={};for(const[n,o]of Object.entries(t))n.startsWith("_")||(e[n]=sJe(o));return e},s9i=(t,e)=>{try{if(typeof t.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${e}`);return}const n=sJe(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)}`)}},a9i=({expanded:t})=>K.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:K.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"})}),Dcn=t=>{let e=t;for(;e.activeSubSolver;)e=e.activeSubSolver;return e},Ncn=({solver:t,onStepUntilPhase:e,onDownloadInput:n,isNested:o=!1,indentLevel:i=0,triggerRender:r})=>{const[s,a]=te.useState(new Set),A=t.pipelineDef.map((p,_)=>t9i(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):s9i(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=Dcn(t);for(;!t.solved&&!t.failed&&(t.step(),Dcn(t)===p););r?.()}},m=i*24;return K.jsxs("div",{className:o?"":"border-t border-gray-200",children:[!o&&K.jsxs("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200 flex items-center justify-between",children:[K.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Stages"}),K.jsxs("div",{className:"flex gap-2",children:[K.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"}),K.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"})]})]}),K.jsx("div",{className:"overflow-x-auto",children:K.jsxs("table",{className:"w-full text-sm",children:[!o&&K.jsx("thead",{children:K.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[K.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stage"}),K.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),K.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",K.jsx("sub",{children:"0"})]}),K.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),K.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),K.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),K.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),K.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),K.jsx("tbody",{children:A.map(p=>{const _=Z4i(p.solverInstance),f=s.has(p.name);return K.jsxs(ws.Fragment,{children:[K.jsxs("tr",{className:`border-b border-gray-100 ${p.status==="In Progress"?"bg-yellow-50":""}`,children:[K.jsx("td",{className:"px-4 py-2",children:K.jsxs("div",{className:"flex items-center gap-2",style:{paddingLeft:m},children:[_?K.jsx("button",{onClick:()=>c(p.name),className:"text-gray-500 hover:text-gray-700",title:f?"Collapse":"Expand",children:K.jsx(a9i,{expanded:f})}):K.jsx("span",{className:"w-4"}),K.jsx("span",{className:"text-gray-400 w-6",children:String(p.index+1).padStart(2,"0")}),K.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:K.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:K.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"})})}),K.jsx("span",{className:"font-medium text-gray-900",children:p.name})]})}),K.jsx("td",{className:"px-4 py-2",children:K.jsx(n9i,{status:p.status})}),K.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:p.firstIteration!==null?p.firstIteration:""}),K.jsx("td",{className:"px-4 py-2 text-gray-600",children:p.iterations}),K.jsx("td",{className:"px-4 py-2",children:K.jsx(o9i,{progress:p.progress})}),K.jsx("td",{className:"px-4 py-2 text-gray-600",children:u(p.timeSpent)}),K.jsx("td",{className:"px-4 py-2 text-gray-500",children:K.jsx(r9i,{stats:p.stats})}),K.jsx("td",{className:"px-4 py-2",children:p.solverInstance?K.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:[K.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:K.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"})}),K.jsx("span",{children:"Input"})]}):null})]}),_&&f&&K.jsx("tr",{children:K.jsx("td",{colSpan:8,className:"p-0",children:K.jsx(Ncn,{solver:p.solverInstance,onStepUntilPhase:e,onDownloadInput:n,isNested:!0,indentLevel:i+1,triggerRender:r})})})]},p.name)})})]})})]})};function A9i({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 K.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${u} ${h} ${d} ${m}`,role:"img","aria-label":"Graphics fallback",children:[o.map((p,_)=>K.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,_)=>K.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,_)=>K.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,_)=>K.jsx("circle",{cx:p.x??0,cy:p.y??0,r:p.radius??1.5,fill:p.color??"black"},`point-${_}`)),r.map((p,_)=>K.jsx("text",{x:p.x??0,y:p.y??0,fontSize:p.fontSize??10,fill:p.color??"black",children:p.text??""},`text-${_}`))]})}var c9i=class extends ws.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}},l9i=({solver:t,createSolver:e,animationSpeed:n=25,onSolverStarted:o,onSolverCompleted:i})=>{const[r,s]=te.useReducer(f=>f+1,0),[a]=te.useState(()=>{if(e)return e();if(!t)throw new Error("GenericSolverDebugger requires solver or createSolver");return t}),[A,c]=te.useState(()=>typeof window>"u"?"vector":window.localStorage.getItem("solver-utils-renderer")==="canvas"?"canvas":"vector"),[l,g]=te.useState(n),u=te.useMemo(()=>{try{return a.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(f){return console.error("Visualization error:",f),{points:[],lines:[],rects:[],circles:[]}}},[a,r]),h=te.useMemo(()=>(u.rects?.length||0)===0&&(u.lines?.length||0)===0&&(u.points?.length||0)===0&&(u.circles?.length||0)===0,[u]);te.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)}},[]),te.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 K.jsxs("div",{children:[K.jsx($4i,{solver:a,triggerRender:s,animationSpeed:l,renderer:A,onRendererChange:_,onAnimationSpeedChange:g,onDownloadVisualization:p,onSolverStarted:o,onSolverCompleted:i}),h?K.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):K.jsx(c9i,{fallback:K.jsx(A9i,{graphics:u}),children:A==="canvas"?K.jsx(j4i,{graphics:u}):K.jsx(z4i,{graphics:u})}),d&&K.jsx(Ncn,{solver:a,onStepUntilPhase:m,triggerRender:s})]})};const g9i=()=>{te.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)},[])},u9i=1e3,pB=(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)},u9i)},aJe=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"},d9i=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]},CP="https://github.com/tscircuit/tscircuit-autorouter/issues/new",Rcn="https://github.com/tscircuit/copper-pour-solver/issues/new",Tcn="https://github.com/tscircuit/calculate-packing/issues/new",h9i="https://github.com/tscircuit/matchpack/issues/new",kcn="https://github.com/tscircuit/schematic-trace-solver/issues/new?template=json-bug-report.yml",m9i={PackSolver2:Tcn,LayoutPipelineSolver:h9i,AutoroutingPipelineSolver:CP,AssignableAutoroutingPipeline2:CP,AssignableAutoroutingPipeline3:CP,AutoroutingPipeline1_OriginalUnravel:CP,AutoroutingPipelineSolver3_HgPortPointPathing:CP,AutoroutingPipelineSolver4:CP,AutoroutingPipelineSolver5:CP,AutoroutingPipelineSolver7_MultiGraph:CP,AutoroutingPipelineSolver8:CP,CopperPourPipelineSolver:Rcn,SchematicTracePipelineSolver:kcn},p9i=t=>t.toLowerCase().includes("pack")?grn:t.toLowerCase().includes("rout")?drn:hEi,Fcn=t=>{const e=m9i[t];if(e)return e;const n=t.toLowerCase();return n.includes("autorout")?CP:n.includes("schematic")&&n.includes("trace")?kcn:n.includes("copperpour")?Rcn:n.includes("pack")?Tcn:null},_9i=t=>`${aJe(`${t.componentName}-${t.solverName}`)}-solver-input.json`,Lcn=t=>{pB(JSON.stringify(t.solverParams,null,2),{fileName:_9i(t),mimeType:"application/json"})},f9i=({solverEvent:t})=>{const e=Fcn(t.solverName);return K.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:[K.jsxs(gA,{type:"button",variant:"outline",size:"sm",onClick:()=>Lcn(t),children:[K.jsx(kX,{className:"rf-w-4 rf-h-4"}),"Download"]}),e?K.jsx(gA,{asChild:!0,variant:"outline",size:"sm",children:K.jsxs("a",{href:e,target:"_blank",rel:"noopener noreferrer",children:[K.jsx(c0e,{className:"rf-w-4 rf-h-4"}),"Report"]})}):K.jsxs(gA,{type:"button",variant:"outline",size:"sm",disabled:!0,title:"No report link configured for this solver",children:[K.jsx(c0e,{className:"rf-w-4 rf-h-4"}),"Report"]})]})},I9i=({solverEvent:t})=>{const e=Fcn(t.solverName);return e?K.jsx(gA,{asChild:!0,variant:"ghost",size:"icon",className:"rf-h-8 rf-w-8",children:K.jsx("a",{href:e,target:"_blank",rel:"noopener noreferrer",title:"Report solver bug","aria-label":"Report solver bug",children:K.jsx(c0e,{className:"rf-w-4 rf-h-4"})})}):K.jsx(gA,{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:K.jsx(c0e,{className:"rf-w-4 rf-h-4"})})},C9i=({solverEvents:t=[]})=>{const[e,n]=te.useState(null);g9i();const o=te.useMemo(()=>{const a=new Map;for(const A of t){const c=`${A.componentName}-${A.solverName}`;a.set(c,A)}return a},[t]),i=te.useMemo(()=>Array.from(o.keys()),[o]),r=e?o.get(e):null,s=te.useMemo(()=>{if(!r)return{instance:null,error:null,classFound:!1};const a=G4e[r.solverName];if(!a)return{instance:null,error:`Solver class "${r.solverName}" not found in SOLVERS registry. Available: ${Object.keys(G4e).join(", ")}`,classFound:!1};try{return{instance:new a(...d9i(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?K.jsx("div",{className:"rf-p-4",children:K.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:K.jsxs("div",{className:"rf-p-4",children:[K.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),K.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."})]})})}):K.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[K.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[K.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 K.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=p9i(A.solverName);return K.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[K.jsx(l,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),K.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[K.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:A.componentName}),K.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:A.solverName})]})]})})()},a)})]}),K.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:r?s.instance?K.jsxs("div",{className:"rf-flex rf-h-full rf-flex-col rf-overflow-y-auto",children:[K.jsx(f9i,{solverEvent:r}),K.jsx("div",{className:"rf-min-h-0 rf-flex-1",children:K.jsx(iB,{fallback:K.jsx("div",{className:"rf-p-4",children:K.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[K.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),K.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",r.solverName]})]})}),children:K.jsx(l9i,{solver:s.instance})})})]}):K.jsxs("div",{className:"rf-p-4",children:[K.jsxs("div",{className:"rf-mb-4",children:[K.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:r.solverName}),K.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",r.componentName]})]}),s.error&&K.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:K.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),K.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[K.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:[K.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"}),K.jsxs("div",{className:"rf-flex rf-items-center rf-gap-1",children:[K.jsx(I9i,{solverEvent:r}),K.jsx(gA,{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:()=>Lcn(r),children:K.jsx(kX,{className:"rf-w-4 rf-h-4"})})]})]}),K.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:K.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)})})]})]}):K.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:K.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},y9i=["subcircuit_id","componentDisplayName","phaseName","routingPhaseIndex","phaseOrdinal","phaseCount","phaseStageIndex","phaseStageCount","connectionCount","obstacleCount","previousTraceCount","isReroutePhase","autorouterName","autorouterVersion","solverName","effort","cacheStatus"],x9i=["phaseOrdinal","routingPhaseIndex","phaseName","phaseStageIndex"];function E9i(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 x9i)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 B9i(t,e){const n=Object.fromEntries(y9i.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:E9i(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 S9i=new Map([["custom","Custom"],["fanout","Fanout"],["single_layer_fanout","Single layer fanout"],["tscircuit_simplify","Simplify"]]),b9i=new Set(["tscircuit","default","auto","auto_local"]);function Q9i(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 v9i(t){const e=t.autorouterName?.trim(),n=e?.replace(/-/g,"_"),o=n&&S9i.get(n);if(o)return o;if(n&&!b9i.has(n))return e;const i=t.solverName?.trim();if(i)return Q9i(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 AJe="#fbbf24";function P9i(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 Hcn(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 w9i(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 Ocn(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,...w9i(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 M9i(t){const e=[],n=[],o=t.endSimpleRouteJson;if(!o)return{lines:e,circles:n};const i=new Set(Hcn(t));for(const r of o.traces??[])if(i.has(r.pcb_trace_id))for(const s of Ocn(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:AJe,layer:c}),A.route_type==="via"&&n.push({center:{x:A.x,y:A.y},radius:A.outer_diameter/2,stroke:AJe,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 D9i(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 N9i=new Set(["pcb_trace","pcb_via","pcb_copper_pour","pcb_ground_plane","pcb_ground_plane_region","pcb_thermal_spoke","pcb_breakout_point"]);function R9i(t,e,n){const o=n==="input"?e.startSimpleRouteJson??e.errorSimpleRouteJson:e.endSimpleRouteJson,i=t.filter(c=>!N9i.has(c.type)&&!c.type.endsWith("_error")&&!c.type.endsWith("_warning"));if(!o)return i;const r=n==="input"?o.traces??[]:P9i(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=Ocn(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}_${D9i(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 cJe=(t,e)=>t.phaseName||`Phase ${t.phaseOrdinal??e+1}`,Gcn=t=>t.componentDisplayName?.match(/name="([^"]+)"/)?.[1]?.replace(/^\./,"")||t.componentDisplayName||t.subcircuit_id||"Board",Ycn=t=>t.startSimpleRouteJson??t.endSimpleRouteJson??t.errorSimpleRouteJson,T9i={is_showing_autorouting:!0,is_showing_rats_nest:!1,is_showing_drc_errors:!1,is_showing_drc_warnings:!1,is_showing_pcb_groups:!1},k9i=({circuitJson:t,phases:e=[],isRunning:n=!1})=>{const[o,i]=te.useState(null),[r,s]=te.useState("output"),[a,A]=te.useState(!0),[c,l]=te.useState(!1),g=te.useRef(null),[u,h]=te.useState(480),d=o?e.findIndex(T=>T.id===o.id&&Ycn(T)===Ycn(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=te.useMemo(()=>!p||!x?null:R9i(t??[],p,y),[t,p,x,y]),B=te.useMemo(()=>p&&y==="output"&&a?M9i(p):{lines:[],circles:[]},[p,y,a]);if(te.useLayoutEffect(()=>{const T=g.current;if(!T)return;const H=()=>h(Math.max(360,T.clientHeight));H();const G=new ResizeObserver(H);return G.observe(T),()=>G.disconnect()},[!!p]),!p)return K.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:[K.jsx(drn,{className:"rf-h-7 rf-w-7 rf-text-blue-500"}),K.jsx("h3",{className:"rf-text-base rf-font-medium",children:n?"Waiting for autorouting":"No autorouting captures"}),K.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=cJe(p,m),Q=p.status==="running"&&n,w=!f,D=I?.connections.length,k=E?.filter(T=>T.type==="pcb_trace").length??0;return K.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:[K.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:[K.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:[K.jsx("span",{children:"Routing phases"}),K.jsx("span",{children:e.length})]}),K.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((T,H)=>{const G=Hcn(T).length,U=T.endSimpleRouteJson?`${G} ${G===1?"trace":"traces"} routed`:T.status==="error"?"Failed":T.status==="running"&&n?"Routing…":"No output";return K.jsxs("button",{type:"button","aria-pressed":H===m,title:`${Gcn(T)} · ${U}`,onClick:()=>i(T),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:[K.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}),K.jsxs("span",{className:"rf-min-w-0 rf-flex-1",children:[K.jsxs("span",{className:"rf-flex rf-items-center rf-gap-1",children:[K.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:cJe(T,H),children:cJe(T,H)}),T.status==="complete"?K.jsx(UM,{"aria-label":"Captured",className:"rf-h-3 rf-w-3 rf-shrink-0 rf-text-green-600"}):T.status==="error"?K.jsx(uVe,{"aria-label":"Failed",className:"rf-h-3 rf-w-3 rf-shrink-0 rf-text-red-500"}):n?K.jsx(rB,{"aria-label":"Routing",className:"rf-h-3 rf-w-3 rf-shrink-0 rf-animate-spin rf-text-blue-500"}):null]}),K.jsxs("span",{className:"rf-block rf-text-[11px] rf-leading-4 rf-text-gray-500",children:[v9i(T)," · ",U]})]})]},T.id)})})]}),K.jsxs("div",{className:"rf-flex rf-min-w-0 rf-flex-1 rf-flex-col",children:[K.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:[K.jsxs("h3",{className:"rf-mr-auto rf-flex rf-items-center rf-gap-2 rf-text-sm rf-font-medium",children:[b,K.jsxs("span",{className:"rf-text-xs rf-font-normal rf-text-gray-500",children:[m+1," of ",e.length]})]}),n&&K.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"}),K.jsx("div",{className:"rf-flex rf-rounded-md rf-bg-gray-100 rf-p-1","aria-label":"Phase snapshot",children:["input","output"].map(T=>K.jsx("button",{type:"button","aria-pressed":y===T,disabled:T==="input"?!C:!f,onClick:()=>s(T),className:ki("rf-rounded rf-px-3 rf-py-1 rf-text-xs disabled:rf-opacity-40",y===T?"rf-bg-white rf-text-gray-900 rf-shadow-sm":"rf-text-gray-500"),children:T==="input"?"Input":"Output"},T))})]}),K.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:[K.jsxs("label",{className:"rf-flex rf-items-center rf-gap-2",children:[K.jsx("input",{type:"checkbox",checked:a,disabled:y!=="output",onChange:T=>A(T.target.checked),className:"rf-accent-blue-600"}),K.jsx("span",{"aria-hidden":"true",className:"rf-inline-block rf-h-0.5 rf-w-3",style:{backgroundColor:AJe}}),"Highlight changes (all layers)"]}),K.jsxs("span",{children:[y==="input"?"Before this phase":"After this phase"," ","· ",k," traces"]})]}),w&&K.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."}),K.jsx("div",{ref:g,className:"rf-relative rf-min-h-[360px] rf-flex-1","data-testid":"autorouting-pcb",children:E?K.jsx(eJe,{circuitJson:E,height:u,allowEditing:!1,clickToInteractEnabled:!1,initialState:T9i,debugGraphics:B}):K.jsx("div",{className:"rf-p-6 rf-text-sm rf-text-gray-500",children:"No PCB snapshot available for this capture."})}),K.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:[K.jsxs("span",{children:[D===void 0?"Input unavailable":`${D} input connections`,` · ${Gcn(p)}`]}),K.jsxs("div",{className:"rf-flex rf-items-center rf-gap-4",children:[K.jsxs("button",{type:"button",disabled:!x,onClick:()=>pB(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:[K.jsx(kX,{className:"rf-h-3 rf-w-3"}),"Download SRJ"]}),K.jsxs("button",{type:"button","aria-expanded":c,onClick:()=>l(!c),className:"rf-flex rf-items-center rf-gap-1",children:[K.jsx(MR,{className:ki("rf-h-3 rf-w-3",c&&"rf-rotate-90")}),"Inspect SRJ"]})]})]}),c&&K.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."})]})]})},Ucn=({errorMessage:t,errorStack:e,circuitJsonErrors:n})=>{te.useEffect(()=>{if(t){const o=new Error(t);e&&(o.stack=e);try{cO.captureException(o)}catch{}}},[t,e]),te.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{cO.captureException(i,{error_type:o.type})}catch{}}},[n])},Kcn=t=>{te.useEffect(()=>{try{STo(t)}catch{}},[t.source,t.component,t.isWebEmbedded,t.activeTab])},Vcn="0.0.2735",F9i={version:Vcn},Rme=jNt()(qNt(t=>({lastRunEvalVersion:void 0,setLastRunEvalVersion:e=>{t({lastRunEvalVersion:e})}}),{name:"runframe-runner-store"})),L9i=t=>{const[e,n]=te.useState([]),[o,i]=te.useState(null),[r,s]=te.useState(""),[a,A]=HH("eval-version-selection",null),c=Rme(h=>h.setLastRunEvalVersion),l=Rme(h=>h.lastRunEvalVersion);return te.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]),te.useEffect(()=>{t&&(a?(window.TSCIRCUIT_LATEST_EVAL_VERSION=a,c(a)):o&&(window.TSCIRCUIT_LATEST_EVAL_VERSION=o,c(o)))},[t,a,o]),{versions:te.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("")}}},H9i=({snippetNames:t,onSelect:e,onCancel:n,isOpen:o})=>{const[i,r]=te.useState(""),[s,a]=te.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 K.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:K.jsxs("div",{className:"rf-bg-white rf-rounded-lg rf-p-6 rf-w-96",children:[K.jsx("h2",{className:"rf-text-lg rf-font-semibold rf-mb-4",children:"Select Snippet"}),K.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}),K.jsxs("div",{className:"rf-h-60 rf-overflow-y-auto",children:[A.map(g=>K.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&&K.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,'"']})]}),K.jsxs("div",{className:"rf-mt-4 rf-flex rf-justify-end rf-gap-2",children:[K.jsx("button",{type:"button",className:"rf-px-4 rf-py-2 rf-text-gray-600 rf-hover:text-gray-800",onClick:n,children:"Cancel"}),K.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}`})]})]})})},O9i=t=>{const e=te.useRef(null),n=nh(o=>o.recentEvents);te.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 G9i=Object.defineProperty,$M=(t,e)=>G9i(t,"name",{value:e,configurable:!0}),Y9i="AlertDialog",[U9i,brr]=cE(Y9i,[Lsn]),ZM=Lsn(),K9i=$M(t=>{const{__scopeAlertDialog:e,...n}=t,o=ZM(e);return K.jsx(K0e,{...o,...n,modal:!0})},"AlertDialog");te.forwardRef($M(function(e,n){const{__scopeAlertDialog:o,...i}=e,r=ZM(o);return K.jsx(hbi,{...r,...i,ref:n})},"AlertDialogTrigger"));var V9i=$M(t=>{const{__scopeAlertDialog:e,...n}=t,o=ZM(e);return K.jsx(V0e,{...o,...n})},"AlertDialogPortal"),z9i=te.forwardRef($M(function(e,n){const{__scopeAlertDialog:o,...i}=e,r=ZM(o);return K.jsx(qX,{...r,...i,ref:n})},"AlertDialogOverlay")),J9i="AlertDialogContent",[W9i,j9i]=U9i(J9i),q9i=te.forwardRef($M(function(e,n){const{__scopeAlertDialog:o,children:i,...r}=e,s=ZM(o),a=te.useRef(null),A=KA(n,a),c=te.useRef(null);return K.jsx(W9i,{scope:o,cancelRef:c,children:K.jsx($X,{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")),X9i=te.forwardRef($M(function(e,n){const{__scopeAlertDialog:o,...i}=e,r=ZM(o);return K.jsx(z0e,{...r,...i,ref:n})},"AlertDialogTitle")),$9i=te.forwardRef($M(function(e,n){const{__scopeAlertDialog:o,...i}=e,r=ZM(o);return K.jsx(J0e,{...r,...i,ref:n})},"AlertDialogDescription")),Z9i=te.forwardRef($M(function(e,n){const{__scopeAlertDialog:o,...i}=e,r=ZM(o);return K.jsx($Ve,{...r,...i,ref:n})},"AlertDialogAction")),e7i="AlertDialogCancel",t7i=te.forwardRef($M(function(e,n){const{__scopeAlertDialog:o,...i}=e,{cancelRef:r}=j9i(e7i,o),s=ZM(o),a=KA(n,r);return K.jsx($Ve,{...s,...i,ref:a})},"AlertDialogCancel")),n7i=K9i,o7i=V9i,zcn=z9i,Jcn=q9i,Wcn=Z9i,jcn=t7i,qcn=X9i,Xcn=$9i;const $cn=n7i,i7i=o7i,Zcn=te.forwardRef(({className:t,...e},n)=>K.jsx(zcn,{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}));Zcn.displayName=zcn.displayName;const lJe=te.forwardRef(({className:t,...e},n)=>K.jsxs(i7i,{children:[K.jsx(Zcn,{}),K.jsx(Jcn,{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})]}));lJe.displayName=Jcn.displayName;const gJe=({className:t,...e})=>K.jsx("div",{className:ki("rf-flex rf-flex-col rf-space-y-2 rf-text-center sm:rf-text-left",t),...e});gJe.displayName="AlertDialogHeader";const uJe=({className:t,...e})=>K.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});uJe.displayName="AlertDialogFooter";const dJe=te.forwardRef(({className:t,...e},n)=>K.jsx(qcn,{ref:n,className:ki("rf-text-lg rf-font-semibold",t),...e}));dJe.displayName=qcn.displayName;const hJe=te.forwardRef(({className:t,...e},n)=>K.jsx(Xcn,{ref:n,className:ki("rf-text-sm rf-text-zinc-500 dark:rf-text-zinc-400",t),...e}));hJe.displayName=Xcn.displayName;const r7i=te.forwardRef(({className:t,...e},n)=>K.jsx(Wcn,{ref:n,className:ki(rY(),t),...e}));r7i.displayName=Wcn.displayName;const mJe=te.forwardRef(({className:t,...e},n)=>K.jsx(jcn,{ref:n,className:ki(rY({variant:"outline"}),"rf-mt-2 sm:rf-mt-0",t),...e}));mJe.displayName=jcn.displayName;var s7i=Object.defineProperty,eD=(t,e)=>s7i(t,"name",{value:e,configurable:!0}),pJe="Checkbox",[a7i,Qrr]=cE(pJe),[A7i,_Je]=a7i(pJe);function eln(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]=uQ({prop:n,defaultProp:i??!1,onChange:A,caller:pJe}),[d,m]=te.useState(null),[p,_]=te.useState(null),f=te.useRef(!1),[I,C]=te.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:tD(i)?!1:i,isFormControl:y,bubbleInput:p,setBubbleInput:_};return K.jsx(A7i,{scope:e,...x,children:nln(g)?g(x):o})}eD(eln,"CheckboxProvider");var c7i="CheckboxTrigger",l7i=te.forwardRef(eD(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}=_Je(c7i,e),_=KA(r,g),f=te.useRef(c);return te.useEffect(()=>{const I=s?.form;if(I){const C=eD(()=>u(f.current),"reset");return I.addEventListener("reset",C),()=>I.removeEventListener("reset",C)}},[s,u]),K.jsx(ba.button,{type:"button",role:"checkbox","aria-checked":tD(c)?"mixed":c,"aria-required":l,"data-state":fJe(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=>tD(C)?!0:!C),p&&m&&(h.current=I.isPropagationStopped(),h.current||I.stopPropagation())})})},"CheckboxTrigger")),tln=te.forwardRef(eD(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 K.jsx(eln,{__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})=>K.jsxs(K.Fragment,{children:[K.jsx(l7i,{...u,ref:n,__scopeCheckbox:o}),h&&K.jsx(h7i,{__scopeCheckbox:o})]})})},"Checkbox")),g7i="CheckboxIndicator",u7i=te.forwardRef(eD(function(e,n){const{__scopeCheckbox:o,forceMount:i,...r}=e,s=_Je(g7i,o);return K.jsx(V2,{present:i||tD(s.checked)||s.checked===!0,children:K.jsx(ba.span,{"data-state":fJe(s.checked),"data-disabled":s.disabled?"":void 0,...r,ref:n,style:{pointerEvents:"none",...e.style}})})},"CheckboxIndicator")),d7i="CheckboxBubbleInput",h7i=te.forwardRef(eD(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}=_Je(d7i,e),_=KA(i,p),f=TVe(r),I=te.useRef(!1),C=te.useRef(A),y=te.useRef(a);te.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 T=new Event("click",{bubbles:k});E.indeterminate=tD(A),Q.call(E,tD(A)?!1:A),E.dispatchEvent(T),I.current=!1}},[m,A,s,a]);const x=te.useRef(tD(A)?!1:A);return K.jsx(ba.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 nln(t){return typeof t=="function"}eD(nln,"isFunction");function tD(t){return t==="indeterminate"}eD(tD,"isIndeterminate");function fJe(t){return tD(t)?"indeterminate":t?"checked":"unchecked"}eD(fJe,"getState");const E$=te.forwardRef(({className:t,...e},n)=>K.jsx(tln,{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:K.jsx(u7i,{className:ki("rf-flex rf-items-center rf-justify-center rf-text-current"),children:K.jsx(UM,{className:"rf-h-4 rf-w-4"})})}));E$.displayName=tln.displayName;const GR=K0e,m7i=V0e,oln=te.forwardRef(({className:t,...e},n)=>K.jsx(qX,{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}));oln.displayName=qX.displayName;const Z9=te.forwardRef(({className:t,children:e,showOverlay:n=!0,...o},i)=>K.jsxs(m7i,{children:[K.jsx(oln,{className:ki(n?"":"rf-hidden")}),K.jsx($X,{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})]}));Z9.displayName=$X.displayName;const e7=({className:t,...e})=>K.jsx("div",{className:ki("rf-flex rf-flex-col rf-space-y-2 rf-text-center sm:rf-text-left",t),...e});e7.displayName="DialogHeader";const QY=({className:t,...e})=>K.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});QY.displayName="DialogFooter";const t7=te.forwardRef(({className:t,...e},n)=>K.jsx(z0e,{ref:n,className:ki("rf-text-lg rf-font-semibold",t),...e}));t7.displayName=z0e.displayName;const YR=te.forwardRef(({className:t,...e},n)=>K.jsx(J0e,{ref:n,className:ki("rf-text-sm rf-text-zinc-500 dark:rf-text-zinc-400",t),...e}));YR.displayName=J0e.displayName;const Tme={"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"}},p7i="https://cdn.jsdelivr.net/npm/easyeda@latest/dist/browser/index.js";let IJe=null;const CJe=async()=>(IJe||(IJe=import(p7i)),IJe),_7i=t=>(e,n)=>{const o=new Headers(n?.headers),i={};return o.forEach((r,s)=>{i[s]=r}),fetch(`${t?.apiBase??ry}/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}})},f7i=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??[]},I7i=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}),iln=async(t,e)=>{const{fetchEasyEDAComponent:n}=await CJe();return n(t,{fetch:_7i(e),includeModelMetadata:e?.includeModelMetadata})},C7i=async(t,e)=>{const{convertRawEasyToTsx:n}=await CJe(),o=await iln(t,e);return n({rawEasy:o})},y7i=async(t,e)=>{const{EasyEdaJsonSchema:n,convertEasyEdaJsonToCircuitJson:o}=await CJe(),i=await iln(t,{...e,includeModelMetadata:!1}),r=n.parse(i);return o(r,{shouldRecenter:!0,showDesignator:!0,useModelCdn:!1})};function n7(t){return Array.isArray?Array.isArray(t):sln(t)==="[object Array]"}function x7i(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 yJe(t){return t==null?"":x7i(t)}function dy(t){return typeof t=="string"}function kme(t){return typeof t=="number"}function E7i(t){return t===!0||t===!1||B7i(t)&&sln(t)=="[object Boolean]"}function rln(t){return typeof t=="object"}function B7i(t){return rln(t)&&t!==null}function _B(t){return t!=null}function Fme(t){return!t.trim().length}function sln(t){return t==null?t===void 0?"[object Undefined]":"[object Null]":Object.prototype.toString.call(t)}const S7i="Incorrect 'index' type",xJe="Invalid doc index: must be a non-negative integer within the bounds of the docs array",b7i=t=>`Invalid value for key ${t}`,Q7i=t=>`Pattern length exceeds max of ${t}.`,v7i=t=>`Missing ${t} property in key`,P7i=t=>`Property 'weight' in key '${t}' must be a positive integer`,w7i="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.",aln=Object.prototype.hasOwnProperty;var M7i=class{constructor(t){this._keys=[],this._keyMap={};let e=0;t.forEach(n=>{const o=Aln(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 Aln(t){let e=null,n=null,o=null,i=1,r=null;if(dy(t)||n7(t))o=t,e=cln(t),n=Lme(t);else{if(!aln.call(t,"name"))throw new Error(v7i("name"));const s=t.name;if(o=s,aln.call(t,"weight")&&t.weight!==void 0&&(i=t.weight,i<=0))throw new Error(P7i(Lme(s)));e=cln(s),n=Lme(s),r=t.getFn??null}return{path:e,id:n,weight:i,src:o,getFn:r}}function cln(t){return n7(t)?t:t.split(".")}function Lme(t){return n7(t)?t.join("."):t}function D7i(t,e){const n=[];let o=!1;const i=(r,s,a,A)=>{if(_B(r))if(!s[a])n.push(A!==void 0?{v:r,i:A}:r);else{const c=r[s[a]];if(!_B(c))return;if(a===s.length-1&&(dy(c)||kme(c)||E7i(c)||typeof c=="bigint"))n.push(A!==void 0?{v:yJe(c),i:A}:yJe(c));else if(n7(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,dy(e)?e.split("."):e,0),o?n:n[0]}const xa=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:D7i,ignoreLocation:!1,ignoreFieldNorm:!1,fieldNormWeight:1}});function N7i(t){return t>=9&&t<=13||t===32||t===160}function R7i(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++)N7i(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 EJe=class{constructor({getFn:t=xa.getFn,fieldNormWeight:e=xa.fieldNormWeight}={}){this.norm=R7i(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(dy(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(xJe);if(dy(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(xJe);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!_B(t)||Fme(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(_B(s)){if(n7(s)){const a=[];for(let A=0,c=s.length;A<c;A+=1){const l=s[A];if(_B(l)){if(dy(l)){if(!Fme(l)){const g={v:l,i:A,n:this.norm.get(l)};a.push(g)}}else if(_B(l.v)){const g=dy(l.v)?l.v:yJe(l.v);if(!Fme(g)){const u={v:g,i:l.i,n:this.norm.get(g)};a.push(u)}}}}n.$[o]=a}else if(dy(s)&&!Fme(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 lln(t,e,{getFn:n=xa.getFn,fieldNormWeight:o=xa.fieldNormWeight}={}){const i=new EJe({getFn:n,fieldNormWeight:o});return i.setKeys(t.map(Aln)),i.setSources(e),i.create(),i}function T7i(t,{getFn:e=xa.getFn,fieldNormWeight:n=xa.fieldNormWeight}={}){const{keys:o,records:i}=t,r=new EJe({getFn:e,fieldNormWeight:n});return r.setKeys(o),r.setIndexRecords(i),r}function k7i(t=[],e=xa.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 F7i(t,e,n,{location:o=xa.location,distance:i=xa.distance,threshold:r=xa.threshold,findAllMatches:s=xa.findAllMatches,minMatchCharLength:a=xa.minMatchCharLength,includeMatches:A=xa.includeMatches,ignoreLocation:c=xa.ignoreLocation}={}){if(e.length>32)throw new Error(Q7i(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,T=Array(k+2);T[k+1]=(1<<b)-1;for(let H=k;H>=D;H-=1){const G=H-1,U=n[t[G]];if(T[H]=(T[H+1]<<1|1)&U,b&&(T[H]|=(I[H+1]|I[H])<<1|1|I[H+1]),T[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=T}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=k7i(_,a);b.length?A&&(B.indices=b):B.isMatch=!1}return B}function L7i(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 BJe(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 gln={ł:"l",Ł:"L",đ:"d",Đ:"D",ø:"o",Ø:"O",ħ:"h",Ħ:"H",ŧ:"t",Ŧ:"T",ı:"i",ß:"ss"},H7i=new RegExp("["+Object.keys(gln).join("")+"]","g"),B$=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(H7i,e=>gln[e]):t=>t;var SJe=class{constructor(t,{location:e=xa.location,threshold:n=xa.threshold,distance:o=xa.distance,includeMatches:i=xa.includeMatches,findAllMatches:r=xa.findAllMatches,minMatchCharLength:s=xa.minMatchCharLength,isCaseSensitive:a=xa.isCaseSensitive,ignoreDiacritics:A=xa.ignoreDiacritics,ignoreLocation:c=xa.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?B$(t):t,this.pattern=t,this.chunks=[],!this.pattern.length)return;const l=(u,h)=>{this.chunks.push({pattern:u,alphabet:L7i(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?B$(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}=F7i(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=BJe(l)),h}};const O7i=new Set(["fuzzy","include"]);function G7i(t){return t.startsWith("inverse")}const bJe=[{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 SJe(t,{location:e.location??xa.location,threshold:e.threshold??xa.threshold,distance:e.distance??xa.distance,includeMatches:e.includeMatches??xa.includeMatches,findAllMatches:e.findAllMatches??xa.findAllMatches,minMatchCharLength:e.minMatchCharLength??xa.minMatchCharLength,isCaseSensitive:e.isCaseSensitive??xa.isCaseSensitive,ignoreDiacritics:e.ignoreDiacritics??xa.ignoreDiacritics,ignoreLocation:e.ignoreLocation??xa.ignoreLocation});return{type:"fuzzy",search(o){return n.searchIn(o)}}}}],uln=bJe.length,Y7i="\0",U7i="|";function K7i(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 V7i(t,e={}){return t.replace(/\\\|/g,Y7i).split(U7i).map(n=>{const o=K7i(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<uln;){const l=bJe[c],g=dln(a,l.multiRegex);g&&(i.push(l.create(g,e)),A=!0)}if(!A)for(c=-1;++c<uln;){const l=bJe[c],g=dln(a,l.singleRegex);if(g){i.push(l.create(g,e));break}}}return i})}var z7i=class{constructor(t,{isCaseSensitive:e=xa.isCaseSensitive,ignoreDiacritics:n=xa.ignoreDiacritics,includeMatches:o=xa.includeMatches,minMatchCharLength:i=xa.minMatchCharLength,ignoreLocation:r=xa.ignoreLocation,findAllMatches:s=xa.findAllMatches,location:a=xa.location,threshold:A=xa.threshold,distance:c=xa.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?B$(t):t,this.pattern=t,this.query=V7i(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?B$(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+=_,G7i(d.type)&&(A=!0),n&&(O7i.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=BJe(s)),u}}return{isMatch:!1,score:1}}};const QJe=[];function vJe(...t){QJe.push(...t)}function Hme(t,e){for(let n=0,o=QJe.length;n<o;n+=1){const i=QJe[n];if(i.condition(t,e))return new i(t,e)}return new SJe(t,e)}const Ome={AND:"$and",OR:"$or"},PJe={PATH:"$path",PATTERN:"$val"},wJe=t=>!!(t[Ome.AND]||t[Ome.OR]),J7i=t=>!!t[PJe.PATH],W7i=t=>!n7(t)&&rln(t)&&!wJe(t),hln=t=>({[Ome.AND]:Object.keys(t).map(e=>({[e]:t[e]}))});function mln(t,e,{auto:n=!0}={}){const o=i=>{if(dy(i)){const A={keyId:null,pattern:i};return n&&(A.searcher=Hme(i,e)),A}const r=Object.keys(i),s=J7i(i);if(!s&&r.length>1&&!wJe(i))return o(hln(i));if(W7i(i)){const A=s?i[PJe.PATH]:r[0],c=s?i[PJe.PATTERN]:i[A];if(!dy(c))throw new Error(b7i(A));const l={keyId:Lme(A),pattern:c};return n&&(l.searcher=Hme(c,e)),l}const a={children:[],operator:r[0]};return r.forEach(A=>{const c=i[A];n7(c)&&c.forEach(l=>{a.children.push(o(l))})}),a};return wJe(t)||(t=hln(t)),o(t)}function MJe(t,{ignoreFieldNorm:e=xa.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 j7i(t,{ignoreFieldNorm:e=xa.ignoreFieldNorm}){t.forEach(n=>{n.score=MJe(n.matches,{ignoreFieldNorm:e})})}var q7i=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 X7i(t){const e=[];return t.matches.forEach(n=>{if(!_B(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 $7i(t,e,{includeMatches:n=xa.includeMatches,includeScore:o=xa.includeScore}={}){return t.map(i=>{const{idx:r}=i,s={item:e[r],refIndex:r};return n&&(s.matches=X7i(i)),o&&(s.score=i.score),s})}const Z7i=/[\p{L}\p{M}\p{N}_]+/gu,pln=new WeakSet;function e6i(t){pln.has(t)||(pln.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 t6i(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||e6i(t),e=>e.match(t)||[]):e=>e.match(Z7i)||[]}function DJe({isCaseSensitive:t=!1,ignoreDiacritics:e=!1,tokenize:n}={}){const o=t6i(n);return{tokenize(i){return t||(i=i.toLowerCase()),e&&(i=B$(i)),o(i)}}}var n6i=class{static condition(t,e){return e.useTokenSearch}constructor(t,e){this.options=e,this.analyzer=DJe({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 SJe(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=BJe(e)),this.combineAll&&(this.useMask?A.matchedMask=r:A.matchedTerms=s,A.termCount=this.numTerms),A}};function NJe(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 _ln(t,e,n,o){const{i,v:r,$:s}=e;if(r!==void 0){NJe(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)NJe(t,c.v,i,o);else NJe(t,A.v,i,o)}}function o6i(t,e,n){const o={fieldCount:0,df:new Map,docFieldCount:new Map,docTermFieldHits:new Map};for(const i of t)_ln(o,i,e,n);return o}function i6i(t,e,n,o){_ln(t,e,n,o)}function r6i(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)r6i(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 o7=class{constructor(t,e,n){this.options={...xa,...e},this.options.useExtendedSearch,this.options.useTokenSearch,this._keyStore=new M7i(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=Hme(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 EJe))throw new Error(S7i);if(this._myIndex=e||lln(this.options.keys,this._docs,{getFn:this.options.getFn,fieldNormWeight:this.options.fieldNormWeight}),this.options.useTokenSearch){const n=DJe({isCaseSensitive:this.options.isCaseSensitive,ignoreDiacritics:this.options.ignoreDiacritics,tokenize:this.options.tokenize});this._invertedIndex=o6i(this._myIndex.records,this._myIndex.keys.length,n)}this._invalidateSearcherCache()}add(t){if(!_B(t))return;this._docs.push(t);const e=this._myIndex.add(t,this._docs.length-1);if(this._invertedIndex&&e){const n=DJe({isCaseSensitive:this.options.isCaseSensitive,ignoreDiacritics:this.options.ignoreDiacritics,tokenize:this.options.tokenize});i6i(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(xJe);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(dy(t)&&!t.trim()){let u=this._docs.map((h,d)=>({item:h,refIndex:d}));return kme(n)&&n>-1&&(u=u.slice(0,n)),u}const A=r&&kme(n)&&n>0&&dy(t),c=s,l=(u,h)=>c(u,h)||u.idx-h.idx;let g;if(A){const u=new q7i(n,l);dy(this._docs[0])?this._searchStringList(t,{heap:u,ignoreFieldNorm:a}):this._searchObjectList(t,{heap:u,ignoreFieldNorm:a}),g=u.extractSorted()}else g=dy(t)?dy(this._docs[0])?this._searchStringList(t):this._searchObjectList(t):this._searchLogical(t),j7i(g,{ignoreFieldNorm:a}),r&&g.sort(dy(t)?l:c),kme(n)&&n>-1&&(g=g.slice(0,n));return $7i(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(!_B(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=MJe(h.matches,{ignoreFieldNorm:n}),e.insert(h)):s.push(h)}}}),s}_searchLogical(t){const e=mln(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===Ome.AND)return[]}return u},i=this._myIndex.records,r=new Map,s=[];return i.forEach(({$:a,i:A})=>{if(_B(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(!_B(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=MJe(h.matches,{ignoreFieldNorm:n}),e.insert(h)):a.push(h)}}),a}_findMatches({key:t,value:e,searcher:n}){if(!_B(e))return[];const o=[];if(n7(e))e.forEach(({v:i,i:r,n:s})=>{if(!_B(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}};o7.version="7.5.0",o7.createIndex=lln,o7.parseIndex=T7i,o7.config=xa,o7.match=function(t,e,n){if(n&&n.useTokenSearch)throw new Error(w7i);return Hme(t,{...xa,...n}).searchIn(e)},o7.parseQuery=mln,vJe(z7i),vJe(n6i),o7.use=function(...t){t.forEach(e=>vJe(e))};var s6i=o7;const a6i="https://kicad-mod-cache.tscircuit.com";let RJe=null,S$=null,TJe=null;const A6i=async()=>RJe||S$||(S$=fetch("https://kicad-mod-cache.tscircuit.com/kicad_files.json").then(t=>t.json()).then(t=>(RJe=t,S$=null,t)),S$),c6i=async(t,e=20)=>{const n=await A6i();return TJe||(TJe=new s6i(n)),TJe.search(t).slice(0,e).map(o=>o.item)},l6i=t=>{const e=t.replace(".pretty/","/").replace(".kicad_mod",""),n=`kicad:${e}`;return{path:t,qualifiedName:n,description:e}},g6i=t=>t.replace(/^\/+/,"").split("/").map(e=>encodeURIComponent(e)).join("/"),u6i=async t=>{const e=await fetch(`${a6i}/${g6i(t)}`);if(!e.ok)throw new Error(`KiCad footprint fetch failed: ${e.status}`);const n=await e.text(),{KicadFootprintToCircuitJsonConverter:o}=await lB("kicad-to-circuit-json"),i=new o;return i.addFile(t.split("/").pop()??"selected-footprint.kicad_mod",n),i.runUntilFinished(),i.getOutput()},Iln=t=>t?.source==="jlcpcb"||t?.source==="kicad",d6i=async(t,e)=>{if(t.source==="jlcpcb")return y7i(t.component.partNumber,e?.jlcpcb);if(t.source==="kicad")return u6i(t.footprint.path);throw new Error("Footprint preview is not available for this source")},h6i=({query:t,placeholder:e,isSearching:n,onQueryChange:o,onSubmit:i})=>{const r=te.useCallback(s=>{s.key==="Enter"&&(s.preventDefault(),i())},[i]);return K.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2 rf-mt-4",children:[K.jsxs("div",{className:"rf-relative rf-flex-grow",children:[K.jsx(dVe,{className:"rf-absolute rf-left-2 rf-top-2.5 rf-h-4 rf-w-4 rf-text-muted-foreground"}),K.jsx(dze,{placeholder:e,className:"rf-pl-8",spellCheck:!1,autoComplete:"off",value:t,onChange:s=>o(s.target.value),onKeyDown:r})]}),K.jsx(gA,{onClick:i,disabled:n||t.trim().length<1,className:"sm:rf-px-4 rf-px-3",children:n?K.jsx(rB,{className:"rf-h-4 rf-w-4 rf-animate-spin"}):K.jsxs(K.Fragment,{children:[K.jsx(dVe,{className:"rf-h-4 rf-w-4 sm:rf-hidden"}),K.jsx("span",{className:"rf-hidden sm:rf-inline",children:"Search"})]})})]})},m6i=new Intl.NumberFormat("en-US",{style:"currency",currency:"USD"}),p6i=t=>m6i.format(t),Cln=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"}},_6i=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}},f6i=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}},I6i=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}},C6i=({results:t,selected:e,onSelect:n,onShowDetails:o})=>{const i=e?Cln(e):null;return K.jsx("div",{className:"rf-divide-y rf-w-full rf-overflow-hidden",children:t.map(r=>{const s=Cln(r),a=i===s,A=_6i(r),c=f6i(r),l=I6i(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 K.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:[K.jsxs("div",{className:"rf-min-w-0 rf-overflow-hidden rf-w-full",children:[K.jsxs("div",{className:"rf-flex rf-items-start rf-gap-2 rf-min-w-0",children:[K.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&&K.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&&K.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&&K.jsx(wEi,{className:"rf-ml-1 rf-h-3 rf-w-3 rf-text-zinc-400 rf-flex-shrink-0"})]}),r.source==="jlcpcb"&&g!=null?K.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]}),K.jsxs("div",{className:"rf-text-xs rf-text-zinc-500 rf-truncate rf-w-full",children:[l?K.jsx("span",{className:"rf-mr-2",children:l}):null,c]})]}),K.jsxs("div",{children:[r.source==="tscircuit.com"&&o?K.jsx("div",{className:"rf-flex-shrink-0 rf-w-full sm:rf-w-auto",children:K.jsx(gA,{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?K.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&&K.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:p6i(u)})]})]},s)})})},y6i=({circuitJson:t,error:e,isLoading:n,height:o})=>K.jsx("section",{className:"rf-flex rf-min-w-0 rf-items-center rf-justify-center",style:{height:o},children:n?K.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:[K.jsx(rB,{className:"rf-h-4 rf-w-4 rf-animate-spin"}),"Loading preview..."]}):e?K.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:K.jsxs("div",{className:"rf-flex rf-max-w-[320px] rf-items-start rf-gap-2 rf-text-sm rf-text-zinc-300",children:[K.jsx(uVe,{className:"rf-mt-0.5 rf-h-4 rf-w-4 rf-flex-shrink-0"}),K.jsx("span",{children:e})]})}):t?K.jsx("div",{className:"rf-w-full rf-min-w-0 rf-overflow-hidden",children:K.jsx(eJe,{circuitJson:t,height:o,allowEditing:!1,clickToInteractEnabled:!1,focusOnHover:!1,disablePcbGroups:!0})}):K.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"})}),yln={importComponentDialog:101,importComponentDetailsDialog:102},x6i=({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 K.jsx(GR,{open:e,onOpenChange:n,children:K.jsxs(Z9,{showOverlay:!1,style:{width:"calc(100vw - 2rem)",zIndex:yln.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:[K.jsx(e7,{className:"rf-pb-4 rf-border-b",children:K.jsx("div",{className:"rf-flex rf-items-start rf-justify-between rf-gap-4",children:K.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[K.jsx(t7,{className:"rf-text-xl rf-font-semibold rf-truncate",children:h}),K.jsx(YR,{children:c?.description})]})})}),K.jsxs("div",{className:"rf-flex-1 rf-overflow-y-auto rf-py-4 rf-space-y-6",children:[d?K.jsxs("div",{children:[K.jsx("span",{className:"rf-text-xs rf-font-medium rf-text-gray-500 rf-uppercase rf-tracking-wide",children:"Created by"}),K.jsx("div",{className:"rf-mt-1 rf-text-sm rf-font-medium",children:m?K.jsx("a",{href:m,target:"_blank",rel:"noopener noreferrer",className:"rf-text-black hover:rf-underline",children:d}):d})]}):null,(u||l||g)&&K.jsx(K.Fragment,{children:K.jsxs("div",{children:[K.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-mb-4",children:"Preview"}),K.jsxs(T6e,{value:r,onValueChange:_=>s(_),children:[K.jsxs(Kge,{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&&K.jsx(Gv,{value:"pcb",children:"PCB"}),g&&K.jsx(Gv,{value:"schematic",children:"Schematic"}),u&&K.jsx(Gv,{value:"3d",children:"3D"})]}),K.jsxs("div",{className:"rf-mt-4",children:[K.jsx(UI,{value:"pcb",className:"rf-border rf-rounded-lg rf-overflow-hidden rf-bg-gray-50",children:l?K.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}),K.jsx(UI,{value:"schematic",className:"rf-border rf-rounded-lg rf-overflow-hidden rf-bg-gray-50",children:g?K.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}),K.jsx(UI,{value:"3d",className:"rf-border rf-rounded-lg rf-overflow-hidden rf-bg-gray-50",children:u?K.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?K.jsxs("section",{children:[K.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-mb-3",children:"AI Description"}),K.jsx("div",{className:"rf-bg-gray-50 rf-border rf-border-gray-200 rf-rounded-lg rf-p-4",children:K.jsx("p",{className:"rf-text-sm rf-text-gray-700 rf-leading-relaxed",children:i.ai_description})})]}):null,i?.ai_usage_instructions?K.jsxs("section",{children:[K.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-mb-3",children:"Usage Instructions"}),K.jsx("div",{className:"rf-bg-gray-50 rf-border rf-border-gray-200 rf-rounded-lg rf-p-4",children:K.jsx("p",{className:"rf-text-sm rf-text-gray-700 rf-leading-relaxed rf-whitespace-pre-wrap",children:i.ai_usage_instructions})})]}):null,o?K.jsxs("div",{className:"rf-flex rf-justify-center rf-items-center rf-gap-2 rf-text-gray-500",children:[K.jsx(rB,{className:"rf-h-4 rf-w-4 rf-animate-spin"}),K.jsx("span",{className:"rf-text-sm",children:"Loading package details..."})]}):null]}),K.jsxs(QY,{className:"rf-pt-4 rf-border-t rf-flex rf-flex-col sm:rf-flex-row rf-justify-between rf-gap-2",children:[K.jsx("div",{className:"rf-flex-1",children:p?K.jsxs(gA,{variant:"outline",size:"sm",className:"rf-gap-2 rf-w-full sm:rf-w-auto",onClick:()=>window.open(p,"_blank"),children:[K.jsx(EEi,{className:"rf-h-4 rf-w-4"}),"View on tscircuit.com"]}):null}),K.jsxs("div",{className:"rf-flex rf-flex-col sm:rf-flex-row rf-gap-2",children:[K.jsx(gA,{variant:"outline",onClick:()=>n(!1),className:"rf-order-2 sm:rf-order-1",children:"Close"}),K.jsx(gA,{onClick:A,disabled:a,className:"rf-bg-blue-600 hover:rf-bg-blue-700",children:a?K.jsx(rB,{className:"rf-h-4 rf-w-4 rf-animate-spin"}):"Import Component"})]})]})]})})},E6i=()=>{const[t,e]=te.useState(null),[n,o]=te.useState(!1),i=te.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=te.useCallback(()=>{e(null),o(!1)},[]);return{details:t,isLoading:n,fetchDetails:i,reset:r}},B6i=(t,e)=>{const[n,o]=te.useState({circuitJson:null,error:null,isLoading:!1});return te.useEffect(()=>{if(!t||!Iln(t)){o({circuitJson:null,error:null,isLoading:!1});return}let i=!1;return o({circuitJson:null,error:null,isLoading:!0}),d6i(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},S6i=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??[]},b6i=({sessionToken:t})=>{const[e,n]=te.useState([]),[o,i]=te.useState(!1),[r,s]=te.useState(null),[a,A]=te.useState(!1),c=te.useCallback(async g=>{const u=g.trim();if(!u)return[];i(!0),s(null);try{const d=(await S6i(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=te.useCallback(()=>{n([]),i(!1),s(null),A(!1)},[]);return{results:e,isSearching:o,error:r,hasSearched:a,search:c,reset:l}},Q6i=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}}},xln=(t,e)=>{const n=Q6i(t);return n?e.some(i=>i.component.partNumber.toUpperCase()===n.component.partNumber)?e:[n,...e]:e},v6i=t=>{const e=t.trim();return/^C\d+/i.test(e)?e.replace(/^C/i,""):e},P6i=()=>{const[t,e]=te.useState([]),[n,o]=te.useState(!1),[i,r]=te.useState(null),[s,a]=te.useState(!1),A=te.useCallback(async l=>{const g=v6i(l);if(!g)return[];o(!0),r(null);try{const u=await f7i(g,10),h=xln(l,u.map(d=>({source:"jlcpcb",component:I7i(d)})));return e(h),h}catch(u){console.error("Error searching JLCPCB components",u);const h=xln(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=te.useCallback(()=>{e([]),o(!1),r(null),a(!1)},[]);return{results:t,isSearching:n,error:i,hasSearched:s,search:A,reset:c}},w6i=()=>{const[t,e]=te.useState([]),[n,o]=te.useState(!1),[i,r]=te.useState(null),[s,a]=te.useState(!1),A=te.useCallback(async l=>{const g=l.trim();if(!g)return[];o(!0),r(null);try{const h=(await c6i(g,20)).map(d=>({source:"kicad",footprint:l6i(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=te.useCallback(()=>{e([]),o(!1),r(null),a(!1)},[]);return{results:t,isSearching:n,error:i,hasSearched:s,search:A,reset:c}},M6i=({onTscircuitPackageSelected:t,onJlcpcbComponentTsxLoaded:e,onKicadStringSelected:n})=>{const o=[];return t&&o.push("tscircuit.com"),e&&o.push("jlcpcb"),n&&o.push("kicad"),o},D6i=({isOpen:t,onClose:e,jlcpcbProxyRequestHeaders:n,onKicadStringSelected:o,onTscircuitPackageSelected:i,onJlcpcbComponentTsxLoaded:r,jlcpcbProxyApiBase:s,tscircuitSessionToken:a})=>{C$();const A=te.useMemo(()=>M6i({onKicadStringSelected:o,onTscircuitPackageSelected:i,onJlcpcbComponentTsxLoaded:r}),[o,i,r]),c=A.length>0,l=A.length===1,[g,u]=te.useState(A[0]??"tscircuit.com"),[h,d]=te.useState(""),[m,p]=te.useState(null),{results:_,isSearching:f,error:I,hasSearched:C,search:y,reset:x}=b6i({sessionToken:a}),{results:E,isSearching:B,error:b,hasSearched:Q,search:w,reset:D}=P6i(),{results:k,isSearching:T,error:H,hasSearched:G,search:U,reset:Y}=w6i(),{details:q,isLoading:ee,fetchDetails:W,reset:J}=E6i(),[ie,oe]=te.useState(null),[ne,le]=te.useState(!1),[ue,_e]=te.useState("pcb"),[ce,Ie]=te.useState(null),[he,Ce]=te.useState(!1),Pe=te.useMemo(()=>({jlcpcb:{headers:n,apiBase:s}}),[s,n]),{circuitJson:Qe,error:pe,isLoading:ve}=B6i(m,Pe),Me=Iln(m);te.useEffect(()=>{Ie(null)},[m]);const we=te.useCallback(()=>{x(),D(),Y(),p(null)},[D,Y,x]);te.useEffect(()=>{t||(we(),d(""),le(!1),oe(null),Ie(null))},[t,we]),te.useEffect(()=>{d(""),p(null),g==="tscircuit.com"?x():g==="jlcpcb"?D():g==="kicad"&&Y()},[g,D,Y,x]);const Oe=je=>{p(je),oe(je),_e("pcb"),le(!0),J();const ht=je.package.org_owner_tscircuit_handle,Bt=je.package.unscoped_name;if(ht&&Bt){const Ct=Bt.split("/").pop()??Bt;W(ht,Ct)}},Re=async()=>{h.trim()&&(p(null),g==="tscircuit.com"?await y(h):g==="jlcpcb"?await w(h):g==="kicad"&&await U(h))},Se=async je=>{try{if(Ie(null),Ce(!0),je.source==="kicad"){if(!o)throw new Error("KiCad handler not provided");await o({result:je,footprint:je.footprint.qualifiedName})}else if(je.source==="jlcpcb"){if(!r)throw new Error("JLCPCB handler not provided");const ht=await C7i(je.component.partNumber,{headers:n,apiBase:s});await r({result:je,tsx:ht})}else if(je.source==="tscircuit.com"){if(!i)throw new Error("tscircuit package handler not provided");const ht=je.package.org_owner_tscircuit_handle,Bt=je.package.unscoped_name;if(!ht||!Bt)throw new Error("Missing package metadata");const Ct=Bt.split("/").pop()??Bt,Ht=`@tsci/${ht}.${Ct}`;await i({result:je,fullPackageName:Ht})}return!0}catch(ht){return console.error("Failed to import component",ht),Ie(ht instanceof Error?ht.message:"Failed to import component"),!1}finally{Ce(!1)}};let Le=[],ye=!1,ke=null,Ye=!1;g==="tscircuit.com"?(Le=_,ye=f,ke=I,Ye=C):g==="jlcpcb"?(Le=E,ye=B,ke=b,Ye=Q):g==="kicad"&&(Le=k,ye=T,ke=H,Ye=G);const $e=async()=>{if(!m)return;await Se(m)&&(e(),we(),d(""))},st=je=>{je||e()},it=je=>{le(je),je||oe(null)};return K.jsxs(GR,{open:t,onOpenChange:st,children:[K.jsxs(Z9,{style:{width:"calc(100vw - 2rem)",maxWidth:Me?"min(1120px, calc(100vw - 2rem))":"min(672px, calc(100vw - 2rem))",zIndex:yln.importComponentDialog},className:"rf-rounded-sm rf-max-h-[90vh] rf-overflow-y-auto rf-overflow-x-hidden rf-flex rf-flex-col",children:[K.jsxs(e7,{children:[K.jsxs(t7,{className:"rf-text-lg sm:rf-text-xl",children:["Import ",l?Tme[g].label:""," ","Component"]}),K.jsx(YR,{className:"rf-text-sm",children:c?"Search for components from available sources.":"Import options are disabled because no handlers were provided."})]}),c?K.jsxs(T6e,{value:g,onValueChange:je=>u(je),className:"rf-min-w-0 rf-w-full",children:[!l&&K.jsx(Kge,{className:"rf-flex rf-w-full rf-gap-2",children:A.map(je=>K.jsx(Gv,{value:je,className:"rf-flex-1 rf-text-xs sm:rf-text-sm",children:Tme[je].label},je))}),K.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:[K.jsxs("div",{className:"rf-min-w-0",children:[K.jsx(h6i,{query:h,placeholder:Tme[g].placeholder,isSearching:ye,onQueryChange:d,onSubmit:Re}),K.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?K.jsxs("div",{className:"rf-p-8 rf-text-center rf-text-zinc-500",children:[K.jsx(rB,{className:"rf-h-8 rf-w-8 rf-animate-spin rf-mx-auto rf-mb-2"}),K.jsx("p",{children:"Searching..."})]}):Le.length>0?K.jsx(C6i,{results:Le,selected:m,onSelect:p,onShowDetails:g==="tscircuit.com"?Oe:void 0}):K.jsx("div",{className:"rf-p-8 rf-text-center rf-text-zinc-500",children:ke?`Error: ${ke}`:Ye?Tme[g].emptyMessage:"Enter a search term to find components"})})]}),Me?K.jsx("div",{className:"rf-mt-4",children:K.jsx(y6i,{circuitJson:Qe,error:pe,isLoading:ve,height:325})}):null]})]}):null,ce?K.jsx("div",{className:"rf-text-sm rf-text-red-600 rf-mt-2",children:ce}):null,K.jsxs(QY,{className:"rf-flex rf-flex-col sm:rf-flex-row rf-gap-2",children:[K.jsx(gA,{variant:"outline",onClick:e,className:"rf-order-2 sm:rf-order-1",children:"Cancel"}),K.jsx(gA,{onClick:$e,disabled:!m||he,className:"rf-order-1 sm:rf-order-2",children:he?K.jsx(rB,{className:"rf-h-4 rf-w-4 rf-animate-spin"}):"Import"})]})]}),K.jsx(x6i,{packageResult:ie,isOpen:ne,onOpenChange:it,isLoading:ee,details:q,previewTab:ue,onPreviewTabChange:je=>_e(je),isSubmitting:he,onImport:()=>{ie&&Se(ie).then(je=>{je&&(le(!1),e(),we(),d(""))})}})]})},N6i=t=>{const e=t.match(/export const (\w+) =/);if(!e)throw new Error("Could not determine component name from TSX contents");return e[1]},Eln=t=>{const e=nh(s=>s.pushEvent),n=nh(s=>s.upsertFile),o=async({result:s,fullPackageName:a})=>{const c=s.package.unscoped_name??s.package.name;await ia.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 ia.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/${N6i(a)}.tsx`;await ia.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 K.jsx(D6i,{...t,onTscircuitPackageSelected:o,onKicadStringSelected:i,onJlcpcbComponentTsxLoaded:r})};Eln.displayName="ImportComponentDialogForCli";const R6i=async({circuitJson:t,projectName:e})=>{const{convertCircuitJsonToAltiumZip:n}=await Promise.resolve().then(()=>inr),o=await n(t,e);return new Blob([new Uint8Array(o)],{type:"application/zip"})},T6i=async({circuitJson:t,projectName:e})=>{await ia.promise((async()=>{const n=await R6i({circuitJson:t,projectName:e});pB(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 kJe={exports:{}},Bln;function k6i(){return Bln||(Bln=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 cw=="function"&&cw;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 cw=="function"&&cw,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)),T=Q.length!==x.name.length,H=k.length!==w.length,G="",U="",Y="",q=x.dir,ee=x.date,W={crc32:0,compressedSize:0,uncompressedSize:0};m&&!p||(W.crc32=d.crc32,W.compressedSize=d.compressedSize,W.uncompressedSize=d.uncompressedSize);var J=0;m&&(J|=8),B||!T&&!H||(J|=2048);var ie=0,oe=0;q&&(ie|=16),f==="UNIX"?(oe=798,ie|=(function(le,ue){var _e=le;return le||(_e=ue?16893:33204),(65535&_e)<<16})(x.unixPermissions,q)):(oe=20,ie|=(function(le){return 63&(le||0)})(x.dosPermissions)),C=ee.getUTCHours(),C<<=6,C|=ee.getUTCMinutes(),C<<=5,C|=ee.getUTCSeconds()/2,y=ee.getUTCFullYear()-1980,y<<=4,y|=ee.getUTCMonth()+1,y<<=5,y|=ee.getUTCDate(),T&&(U=s(1,1)+s(g(b),4)+Q,G+="up"+s(U.length,2)+U),H&&(Y=s(1,1)+s(g(D),4)+k,G+="uc"+s(Y.length,2)+Y);var ne="";return ne+=`
|
|
5742
|
+
`,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 K.jsxs("div",{className:`relative ${e}`,ref:i,children:[K.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&&K.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:[K.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:r,children:"Download JSON"}),K.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),K.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:a,children:"Download test.ts"})]})]})},wcn=t=>t.activeSubSolver?[t,...wcn(t.activeSubSolver)]:[t],X4i=({solver:t})=>{const e=wcn(t);return K.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:e.map((n,o)=>K.jsxs("div",{className:"flex items-center",children:[o>0&&K.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),K.jsx(q4i,{solver:n})]},n.getSolverName()))})},$4i=({solver:t,triggerRender:e,animationSpeed:n=25,renderer:o,onRendererChange:i,onAnimationSpeedChange:r,onDownloadVisualization:s,onSolverStarted:a,onSolverCompleted:A})=>{const[c,l]=te.useReducer(B=>!B,!1),g=te.useRef(void 0),u=te.useRef(null),h="solver-debugger-last-iteration",[d,m]=te.useState(null),p=te.useRef(null),_=te.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 te.useEffect(()=>()=>{I()},[]),te.useEffect(()=>{(t.solved||t.failed)&&c&&(I(),l())},[t.solved,t.failed,c]),te.useEffect(()=>{c&&(I(),f())},[n,c]),te.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)}},[]),K.jsxs("div",{className:"space-y-2 p-2 border-b",children:[K.jsx("div",{className:"flex items-center",children:K.jsxs("div",{className:"flex items-center gap-2",ref:p,children:[K.jsxs("div",{className:"flex h-9 items-center space-x-1 rounded-md border border-slate-200 bg-white p-1 shadow-sm",children:[K.jsxs("div",{className:"relative",children:[K.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"&&K.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=>K.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&&K.jsx("span",{className:"ml-auto text-xs text-slate-500",children:"✓"})]},B))})]}),K.jsxs("div",{className:"relative",children:[K.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"&&K.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:K.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"})})]}),K.jsxs("div",{className:"relative",children:[K.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"&&K.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=>K.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,K.jsx("span",{className:"ml-auto text-xs text-slate-500",children:B.description}),n===B.value&&K.jsx("span",{className:"ml-2 text-xs text-slate-500",children:"✓"})]},B.value))})]})]}),K.jsx(X4i,{solver:t})]})}),K.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[K.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"}),K.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"}),K.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"}),K.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"}),K.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",t.iterations]}),t.timeToSolve!==void 0&&K.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(t.timeToSolve/1e3).toFixed(3),"s"]}),t.solved&&K.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),t.failed&&K.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),t.error&&K.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",t.error]})]})},Z4i=t=>t!==null&&"pipelineDef"in t&&Array.isArray(t.pipelineDef),e9i=(t,e,n)=>{const o=t.currentPipelineStageIndex;return e<o?"Completed":e===o&&t.activeSubSolver?t.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},t9i=(t,e)=>{const o=t.pipelineDef[e].solverName,i=e9i(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}},n9i=({status:t})=>{const e={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return K.jsx("span",{className:`font-medium ${e[t]}`,children:t})},o9i=({progress:t})=>{if(t===0)return null;const e=Math.round(t*100);return K.jsxs("div",{className:"flex items-center gap-2",children:[K.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:K.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${e}%`}})}),K.jsxs("span",{className:"text-xs text-gray-500",children:[e,"%"]})]})},Mcn=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)},i9i=t=>Object.entries(t).map(([e,n])=>`${e}: ${Mcn(n)}`).join(", "),r9i=({stats:t})=>{if(!t||Object.keys(t).length===0)return K.jsx("span",{children:"-"});const e=Object.entries(t),n=i9i(t);return K.jsxs("details",{className:"cursor-pointer",children:[K.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:n}),K.jsx("div",{className:"mt-1 text-xs",children:e.map(([o,i])=>K.jsxs("div",{children:[o,": ",Mcn(i)]},o))})]})},sJe=t=>{if(t===null||typeof t!="object")return t;if(Array.isArray(t))return t.map(sJe);const e={};for(const[n,o]of Object.entries(t))n.startsWith("_")||(e[n]=sJe(o));return e},s9i=(t,e)=>{try{if(typeof t.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${e}`);return}const n=sJe(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)}`)}},a9i=({expanded:t})=>K.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:K.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"})}),Dcn=t=>{let e=t;for(;e.activeSubSolver;)e=e.activeSubSolver;return e},Ncn=({solver:t,onStepUntilPhase:e,onDownloadInput:n,isNested:o=!1,indentLevel:i=0,triggerRender:r})=>{const[s,a]=te.useState(new Set),A=t.pipelineDef.map((p,_)=>t9i(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):s9i(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=Dcn(t);for(;!t.solved&&!t.failed&&(t.step(),Dcn(t)===p););r?.()}},m=i*24;return K.jsxs("div",{className:o?"":"border-t border-gray-200",children:[!o&&K.jsxs("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200 flex items-center justify-between",children:[K.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Stages"}),K.jsxs("div",{className:"flex gap-2",children:[K.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"}),K.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"})]})]}),K.jsx("div",{className:"overflow-x-auto",children:K.jsxs("table",{className:"w-full text-sm",children:[!o&&K.jsx("thead",{children:K.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[K.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stage"}),K.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),K.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",K.jsx("sub",{children:"0"})]}),K.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),K.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),K.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),K.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),K.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),K.jsx("tbody",{children:A.map(p=>{const _=Z4i(p.solverInstance),f=s.has(p.name);return K.jsxs(ws.Fragment,{children:[K.jsxs("tr",{className:`border-b border-gray-100 ${p.status==="In Progress"?"bg-yellow-50":""}`,children:[K.jsx("td",{className:"px-4 py-2",children:K.jsxs("div",{className:"flex items-center gap-2",style:{paddingLeft:m},children:[_?K.jsx("button",{onClick:()=>c(p.name),className:"text-gray-500 hover:text-gray-700",title:f?"Collapse":"Expand",children:K.jsx(a9i,{expanded:f})}):K.jsx("span",{className:"w-4"}),K.jsx("span",{className:"text-gray-400 w-6",children:String(p.index+1).padStart(2,"0")}),K.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:K.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:K.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"})})}),K.jsx("span",{className:"font-medium text-gray-900",children:p.name})]})}),K.jsx("td",{className:"px-4 py-2",children:K.jsx(n9i,{status:p.status})}),K.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:p.firstIteration!==null?p.firstIteration:""}),K.jsx("td",{className:"px-4 py-2 text-gray-600",children:p.iterations}),K.jsx("td",{className:"px-4 py-2",children:K.jsx(o9i,{progress:p.progress})}),K.jsx("td",{className:"px-4 py-2 text-gray-600",children:u(p.timeSpent)}),K.jsx("td",{className:"px-4 py-2 text-gray-500",children:K.jsx(r9i,{stats:p.stats})}),K.jsx("td",{className:"px-4 py-2",children:p.solverInstance?K.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:[K.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:K.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"})}),K.jsx("span",{children:"Input"})]}):null})]}),_&&f&&K.jsx("tr",{children:K.jsx("td",{colSpan:8,className:"p-0",children:K.jsx(Ncn,{solver:p.solverInstance,onStepUntilPhase:e,onDownloadInput:n,isNested:!0,indentLevel:i+1,triggerRender:r})})})]},p.name)})})]})})]})};function A9i({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 K.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${u} ${h} ${d} ${m}`,role:"img","aria-label":"Graphics fallback",children:[o.map((p,_)=>K.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,_)=>K.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,_)=>K.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,_)=>K.jsx("circle",{cx:p.x??0,cy:p.y??0,r:p.radius??1.5,fill:p.color??"black"},`point-${_}`)),r.map((p,_)=>K.jsx("text",{x:p.x??0,y:p.y??0,fontSize:p.fontSize??10,fill:p.color??"black",children:p.text??""},`text-${_}`))]})}var c9i=class extends ws.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}},l9i=({solver:t,createSolver:e,animationSpeed:n=25,onSolverStarted:o,onSolverCompleted:i})=>{const[r,s]=te.useReducer(f=>f+1,0),[a]=te.useState(()=>{if(e)return e();if(!t)throw new Error("GenericSolverDebugger requires solver or createSolver");return t}),[A,c]=te.useState(()=>typeof window>"u"?"vector":window.localStorage.getItem("solver-utils-renderer")==="canvas"?"canvas":"vector"),[l,g]=te.useState(n),u=te.useMemo(()=>{try{return a.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(f){return console.error("Visualization error:",f),{points:[],lines:[],rects:[],circles:[]}}},[a,r]),h=te.useMemo(()=>(u.rects?.length||0)===0&&(u.lines?.length||0)===0&&(u.points?.length||0)===0&&(u.circles?.length||0)===0,[u]);te.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)}},[]),te.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 K.jsxs("div",{children:[K.jsx($4i,{solver:a,triggerRender:s,animationSpeed:l,renderer:A,onRendererChange:_,onAnimationSpeedChange:g,onDownloadVisualization:p,onSolverStarted:o,onSolverCompleted:i}),h?K.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):K.jsx(c9i,{fallback:K.jsx(A9i,{graphics:u}),children:A==="canvas"?K.jsx(j4i,{graphics:u}):K.jsx(z4i,{graphics:u})}),d&&K.jsx(Ncn,{solver:a,onStepUntilPhase:m,triggerRender:s})]})};const g9i=()=>{te.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)},[])},u9i=1e3,pB=(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)},u9i)},aJe=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"},d9i=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]},CP="https://github.com/tscircuit/tscircuit-autorouter/issues/new",Rcn="https://github.com/tscircuit/copper-pour-solver/issues/new",Tcn="https://github.com/tscircuit/calculate-packing/issues/new",h9i="https://github.com/tscircuit/matchpack/issues/new",kcn="https://github.com/tscircuit/schematic-trace-solver/issues/new?template=json-bug-report.yml",m9i={PackSolver2:Tcn,LayoutPipelineSolver:h9i,AutoroutingPipelineSolver:CP,AssignableAutoroutingPipeline2:CP,AssignableAutoroutingPipeline3:CP,AutoroutingPipeline1_OriginalUnravel:CP,AutoroutingPipelineSolver3_HgPortPointPathing:CP,AutoroutingPipelineSolver4:CP,AutoroutingPipelineSolver5:CP,AutoroutingPipelineSolver7_MultiGraph:CP,AutoroutingPipelineSolver8:CP,CopperPourPipelineSolver:Rcn,SchematicTracePipelineSolver:kcn},p9i=t=>t.toLowerCase().includes("pack")?grn:t.toLowerCase().includes("rout")?drn:hEi,Fcn=t=>{const e=m9i[t];if(e)return e;const n=t.toLowerCase();return n.includes("autorout")?CP:n.includes("schematic")&&n.includes("trace")?kcn:n.includes("copperpour")?Rcn:n.includes("pack")?Tcn:null},_9i=t=>`${aJe(`${t.componentName}-${t.solverName}`)}-solver-input.json`,Lcn=t=>{pB(JSON.stringify(t.solverParams,null,2),{fileName:_9i(t),mimeType:"application/json"})},f9i=({solverEvent:t})=>{const e=Fcn(t.solverName);return K.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:[K.jsxs(gA,{type:"button",variant:"outline",size:"sm",onClick:()=>Lcn(t),children:[K.jsx(kX,{className:"rf-w-4 rf-h-4"}),"Download"]}),e?K.jsx(gA,{asChild:!0,variant:"outline",size:"sm",children:K.jsxs("a",{href:e,target:"_blank",rel:"noopener noreferrer",children:[K.jsx(c0e,{className:"rf-w-4 rf-h-4"}),"Report"]})}):K.jsxs(gA,{type:"button",variant:"outline",size:"sm",disabled:!0,title:"No report link configured for this solver",children:[K.jsx(c0e,{className:"rf-w-4 rf-h-4"}),"Report"]})]})},I9i=({solverEvent:t})=>{const e=Fcn(t.solverName);return e?K.jsx(gA,{asChild:!0,variant:"ghost",size:"icon",className:"rf-h-8 rf-w-8",children:K.jsx("a",{href:e,target:"_blank",rel:"noopener noreferrer",title:"Report solver bug","aria-label":"Report solver bug",children:K.jsx(c0e,{className:"rf-w-4 rf-h-4"})})}):K.jsx(gA,{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:K.jsx(c0e,{className:"rf-w-4 rf-h-4"})})},C9i=({solverEvents:t=[]})=>{const[e,n]=te.useState(null);g9i();const o=te.useMemo(()=>{const a=new Map;for(const A of t){const c=`${A.componentName}-${A.solverName}`;a.set(c,A)}return a},[t]),i=te.useMemo(()=>Array.from(o.keys()),[o]),r=e?o.get(e):null,s=te.useMemo(()=>{if(!r)return{instance:null,error:null,classFound:!1};const a=G4e[r.solverName];if(!a)return{instance:null,error:`Solver class "${r.solverName}" not found in SOLVERS registry. Available: ${Object.keys(G4e).join(", ")}`,classFound:!1};try{return{instance:new a(...d9i(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?K.jsx("div",{className:"rf-p-4",children:K.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:K.jsxs("div",{className:"rf-p-4",children:[K.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),K.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."})]})})}):K.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[K.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[K.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 K.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=p9i(A.solverName);return K.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[K.jsx(l,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),K.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[K.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:A.componentName}),K.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:A.solverName})]})]})})()},a)})]}),K.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:r?s.instance?K.jsxs("div",{className:"rf-flex rf-h-full rf-flex-col rf-overflow-y-auto",children:[K.jsx(f9i,{solverEvent:r}),K.jsx("div",{className:"rf-min-h-0 rf-flex-1",children:K.jsx(iB,{fallback:K.jsx("div",{className:"rf-p-4",children:K.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[K.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),K.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",r.solverName]})]})}),children:K.jsx(l9i,{solver:s.instance})})})]}):K.jsxs("div",{className:"rf-p-4",children:[K.jsxs("div",{className:"rf-mb-4",children:[K.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:r.solverName}),K.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",r.componentName]})]}),s.error&&K.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:K.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),K.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[K.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:[K.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"}),K.jsxs("div",{className:"rf-flex rf-items-center rf-gap-1",children:[K.jsx(I9i,{solverEvent:r}),K.jsx(gA,{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:()=>Lcn(r),children:K.jsx(kX,{className:"rf-w-4 rf-h-4"})})]})]}),K.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:K.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)})})]})]}):K.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:K.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},y9i=["subcircuit_id","componentDisplayName","phaseName","routingPhaseIndex","phaseOrdinal","phaseCount","phaseStageIndex","phaseStageCount","connectionCount","obstacleCount","previousTraceCount","isReroutePhase","autorouterName","autorouterVersion","solverName","effort","cacheStatus"],x9i=["phaseOrdinal","routingPhaseIndex","phaseName","phaseStageIndex"];function E9i(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 x9i)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 B9i(t,e){const n=Object.fromEntries(y9i.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:E9i(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 S9i=new Map([["custom","Custom"],["fanout","Fanout"],["single_layer_fanout","Single layer fanout"],["tscircuit_simplify","Simplify"]]),b9i=new Set(["tscircuit","default","auto","auto_local"]);function Q9i(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 v9i(t){const e=t.autorouterName?.trim(),n=e?.replace(/-/g,"_"),o=n&&S9i.get(n);if(o)return o;if(n&&!b9i.has(n))return e;const i=t.solverName?.trim();if(i)return Q9i(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 AJe="#fbbf24";function P9i(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 Hcn(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 w9i(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 Ocn(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,...w9i(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 M9i(t){const e=[],n=[],o=t.endSimpleRouteJson;if(!o)return{lines:e,circles:n};const i=new Set(Hcn(t));for(const r of o.traces??[])if(i.has(r.pcb_trace_id))for(const s of Ocn(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:AJe,layer:c}),A.route_type==="via"&&n.push({center:{x:A.x,y:A.y},radius:A.outer_diameter/2,stroke:AJe,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 D9i(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 N9i=new Set(["pcb_trace","pcb_via","pcb_copper_pour","pcb_ground_plane","pcb_ground_plane_region","pcb_thermal_spoke","pcb_breakout_point"]);function R9i(t,e,n){const o=n==="input"?e.startSimpleRouteJson??e.errorSimpleRouteJson:e.endSimpleRouteJson,i=t.filter(c=>!N9i.has(c.type)&&!c.type.endsWith("_error")&&!c.type.endsWith("_warning"));if(!o)return i;const r=n==="input"?o.traces??[]:P9i(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=Ocn(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}_${D9i(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 cJe=(t,e)=>t.phaseName||`Phase ${t.phaseOrdinal??e+1}`,Gcn=t=>t.componentDisplayName?.match(/name="([^"]+)"/)?.[1]?.replace(/^\./,"")||t.componentDisplayName||t.subcircuit_id||"Board",Ycn=t=>t.startSimpleRouteJson??t.endSimpleRouteJson??t.errorSimpleRouteJson,T9i={is_showing_autorouting:!0,is_showing_rats_nest:!1,is_showing_drc_errors:!1,is_showing_drc_warnings:!1,is_showing_pcb_groups:!1},k9i=({circuitJson:t,phases:e=[],isRunning:n=!1})=>{const[o,i]=te.useState(null),[r,s]=te.useState("output"),[a,A]=te.useState(!0),[c,l]=te.useState(!1),g=te.useRef(null),[u,h]=te.useState(480),d=o?e.findIndex(T=>T.id===o.id&&Ycn(T)===Ycn(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=te.useMemo(()=>!p||!x?null:R9i(t??[],p,y),[t,p,x,y]),B=te.useMemo(()=>p&&y==="output"&&a?M9i(p):{lines:[],circles:[]},[p,y,a]);if(te.useLayoutEffect(()=>{const T=g.current;if(!T)return;const H=()=>h(Math.max(360,T.clientHeight));H();const G=new ResizeObserver(H);return G.observe(T),()=>G.disconnect()},[!!p]),!p)return K.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:[K.jsx(drn,{className:"rf-h-7 rf-w-7 rf-text-blue-500"}),K.jsx("h3",{className:"rf-text-base rf-font-medium",children:n?"Waiting for autorouting":"No autorouting captures"}),K.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=cJe(p,m),Q=p.status==="running"&&n,w=!f,D=I?.connections.length,k=E?.filter(T=>T.type==="pcb_trace").length??0;return K.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:[K.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:[K.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:[K.jsx("span",{children:"Routing phases"}),K.jsx("span",{children:e.length})]}),K.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((T,H)=>{const G=Hcn(T).length,U=T.endSimpleRouteJson?`${G} ${G===1?"trace":"traces"} routed`:T.status==="error"?"Failed":T.status==="running"&&n?"Routing…":"No output";return K.jsxs("button",{type:"button","aria-pressed":H===m,title:`${Gcn(T)} · ${U}`,onClick:()=>i(T),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:[K.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}),K.jsxs("span",{className:"rf-min-w-0 rf-flex-1",children:[K.jsxs("span",{className:"rf-flex rf-items-center rf-gap-1",children:[K.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:cJe(T,H),children:cJe(T,H)}),T.status==="complete"?K.jsx(UM,{"aria-label":"Captured",className:"rf-h-3 rf-w-3 rf-shrink-0 rf-text-green-600"}):T.status==="error"?K.jsx(uVe,{"aria-label":"Failed",className:"rf-h-3 rf-w-3 rf-shrink-0 rf-text-red-500"}):n?K.jsx(rB,{"aria-label":"Routing",className:"rf-h-3 rf-w-3 rf-shrink-0 rf-animate-spin rf-text-blue-500"}):null]}),K.jsxs("span",{className:"rf-block rf-text-[11px] rf-leading-4 rf-text-gray-500",children:[v9i(T)," · ",U]})]})]},T.id)})})]}),K.jsxs("div",{className:"rf-flex rf-min-w-0 rf-flex-1 rf-flex-col",children:[K.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:[K.jsxs("h3",{className:"rf-mr-auto rf-flex rf-items-center rf-gap-2 rf-text-sm rf-font-medium",children:[b,K.jsxs("span",{className:"rf-text-xs rf-font-normal rf-text-gray-500",children:[m+1," of ",e.length]})]}),n&&K.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"}),K.jsx("div",{className:"rf-flex rf-rounded-md rf-bg-gray-100 rf-p-1","aria-label":"Phase snapshot",children:["input","output"].map(T=>K.jsx("button",{type:"button","aria-pressed":y===T,disabled:T==="input"?!C:!f,onClick:()=>s(T),className:ki("rf-rounded rf-px-3 rf-py-1 rf-text-xs disabled:rf-opacity-40",y===T?"rf-bg-white rf-text-gray-900 rf-shadow-sm":"rf-text-gray-500"),children:T==="input"?"Input":"Output"},T))})]}),K.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:[K.jsxs("label",{className:"rf-flex rf-items-center rf-gap-2",children:[K.jsx("input",{type:"checkbox",checked:a,disabled:y!=="output",onChange:T=>A(T.target.checked),className:"rf-accent-blue-600"}),K.jsx("span",{"aria-hidden":"true",className:"rf-inline-block rf-h-0.5 rf-w-3",style:{backgroundColor:AJe}}),"Highlight changes (all layers)"]}),K.jsxs("span",{children:[y==="input"?"Before this phase":"After this phase"," ","· ",k," traces"]})]}),w&&K.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."}),K.jsx("div",{ref:g,className:"rf-relative rf-min-h-[360px] rf-flex-1","data-testid":"autorouting-pcb",children:E?K.jsx(eJe,{circuitJson:E,height:u,allowEditing:!1,clickToInteractEnabled:!1,initialState:T9i,debugGraphics:B}):K.jsx("div",{className:"rf-p-6 rf-text-sm rf-text-gray-500",children:"No PCB snapshot available for this capture."})}),K.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:[K.jsxs("span",{children:[D===void 0?"Input unavailable":`${D} input connections`,` · ${Gcn(p)}`]}),K.jsxs("div",{className:"rf-flex rf-items-center rf-gap-4",children:[K.jsxs("button",{type:"button",disabled:!x,onClick:()=>pB(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:[K.jsx(kX,{className:"rf-h-3 rf-w-3"}),"Download SRJ"]}),K.jsxs("button",{type:"button","aria-expanded":c,onClick:()=>l(!c),className:"rf-flex rf-items-center rf-gap-1",children:[K.jsx(MR,{className:ki("rf-h-3 rf-w-3",c&&"rf-rotate-90")}),"Inspect SRJ"]})]})]}),c&&K.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."})]})]})},Ucn=({errorMessage:t,errorStack:e,circuitJsonErrors:n})=>{te.useEffect(()=>{if(t){const o=new Error(t);e&&(o.stack=e);try{cO.captureException(o)}catch{}}},[t,e]),te.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{cO.captureException(i,{error_type:o.type})}catch{}}},[n])},Kcn=t=>{te.useEffect(()=>{try{STo(t)}catch{}},[t.source,t.component,t.isWebEmbedded,t.activeTab])},Vcn="0.0.2737",F9i={version:Vcn},Rme=jNt()(qNt(t=>({lastRunEvalVersion:void 0,setLastRunEvalVersion:e=>{t({lastRunEvalVersion:e})}}),{name:"runframe-runner-store"})),L9i=t=>{const[e,n]=te.useState([]),[o,i]=te.useState(null),[r,s]=te.useState(""),[a,A]=HH("eval-version-selection",null),c=Rme(h=>h.setLastRunEvalVersion),l=Rme(h=>h.lastRunEvalVersion);return te.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]),te.useEffect(()=>{t&&(a?(window.TSCIRCUIT_LATEST_EVAL_VERSION=a,c(a)):o&&(window.TSCIRCUIT_LATEST_EVAL_VERSION=o,c(o)))},[t,a,o]),{versions:te.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("")}}},H9i=({snippetNames:t,onSelect:e,onCancel:n,isOpen:o})=>{const[i,r]=te.useState(""),[s,a]=te.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 K.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:K.jsxs("div",{className:"rf-bg-white rf-rounded-lg rf-p-6 rf-w-96",children:[K.jsx("h2",{className:"rf-text-lg rf-font-semibold rf-mb-4",children:"Select Snippet"}),K.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}),K.jsxs("div",{className:"rf-h-60 rf-overflow-y-auto",children:[A.map(g=>K.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&&K.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,'"']})]}),K.jsxs("div",{className:"rf-mt-4 rf-flex rf-justify-end rf-gap-2",children:[K.jsx("button",{type:"button",className:"rf-px-4 rf-py-2 rf-text-gray-600 rf-hover:text-gray-800",onClick:n,children:"Cancel"}),K.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}`})]})]})})},O9i=t=>{const e=te.useRef(null),n=nh(o=>o.recentEvents);te.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 G9i=Object.defineProperty,$M=(t,e)=>G9i(t,"name",{value:e,configurable:!0}),Y9i="AlertDialog",[U9i,brr]=cE(Y9i,[Lsn]),ZM=Lsn(),K9i=$M(t=>{const{__scopeAlertDialog:e,...n}=t,o=ZM(e);return K.jsx(K0e,{...o,...n,modal:!0})},"AlertDialog");te.forwardRef($M(function(e,n){const{__scopeAlertDialog:o,...i}=e,r=ZM(o);return K.jsx(hbi,{...r,...i,ref:n})},"AlertDialogTrigger"));var V9i=$M(t=>{const{__scopeAlertDialog:e,...n}=t,o=ZM(e);return K.jsx(V0e,{...o,...n})},"AlertDialogPortal"),z9i=te.forwardRef($M(function(e,n){const{__scopeAlertDialog:o,...i}=e,r=ZM(o);return K.jsx(qX,{...r,...i,ref:n})},"AlertDialogOverlay")),J9i="AlertDialogContent",[W9i,j9i]=U9i(J9i),q9i=te.forwardRef($M(function(e,n){const{__scopeAlertDialog:o,children:i,...r}=e,s=ZM(o),a=te.useRef(null),A=KA(n,a),c=te.useRef(null);return K.jsx(W9i,{scope:o,cancelRef:c,children:K.jsx($X,{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")),X9i=te.forwardRef($M(function(e,n){const{__scopeAlertDialog:o,...i}=e,r=ZM(o);return K.jsx(z0e,{...r,...i,ref:n})},"AlertDialogTitle")),$9i=te.forwardRef($M(function(e,n){const{__scopeAlertDialog:o,...i}=e,r=ZM(o);return K.jsx(J0e,{...r,...i,ref:n})},"AlertDialogDescription")),Z9i=te.forwardRef($M(function(e,n){const{__scopeAlertDialog:o,...i}=e,r=ZM(o);return K.jsx($Ve,{...r,...i,ref:n})},"AlertDialogAction")),e7i="AlertDialogCancel",t7i=te.forwardRef($M(function(e,n){const{__scopeAlertDialog:o,...i}=e,{cancelRef:r}=j9i(e7i,o),s=ZM(o),a=KA(n,r);return K.jsx($Ve,{...s,...i,ref:a})},"AlertDialogCancel")),n7i=K9i,o7i=V9i,zcn=z9i,Jcn=q9i,Wcn=Z9i,jcn=t7i,qcn=X9i,Xcn=$9i;const $cn=n7i,i7i=o7i,Zcn=te.forwardRef(({className:t,...e},n)=>K.jsx(zcn,{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}));Zcn.displayName=zcn.displayName;const lJe=te.forwardRef(({className:t,...e},n)=>K.jsxs(i7i,{children:[K.jsx(Zcn,{}),K.jsx(Jcn,{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})]}));lJe.displayName=Jcn.displayName;const gJe=({className:t,...e})=>K.jsx("div",{className:ki("rf-flex rf-flex-col rf-space-y-2 rf-text-center sm:rf-text-left",t),...e});gJe.displayName="AlertDialogHeader";const uJe=({className:t,...e})=>K.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});uJe.displayName="AlertDialogFooter";const dJe=te.forwardRef(({className:t,...e},n)=>K.jsx(qcn,{ref:n,className:ki("rf-text-lg rf-font-semibold",t),...e}));dJe.displayName=qcn.displayName;const hJe=te.forwardRef(({className:t,...e},n)=>K.jsx(Xcn,{ref:n,className:ki("rf-text-sm rf-text-zinc-500 dark:rf-text-zinc-400",t),...e}));hJe.displayName=Xcn.displayName;const r7i=te.forwardRef(({className:t,...e},n)=>K.jsx(Wcn,{ref:n,className:ki(rY(),t),...e}));r7i.displayName=Wcn.displayName;const mJe=te.forwardRef(({className:t,...e},n)=>K.jsx(jcn,{ref:n,className:ki(rY({variant:"outline"}),"rf-mt-2 sm:rf-mt-0",t),...e}));mJe.displayName=jcn.displayName;var s7i=Object.defineProperty,eD=(t,e)=>s7i(t,"name",{value:e,configurable:!0}),pJe="Checkbox",[a7i,Qrr]=cE(pJe),[A7i,_Je]=a7i(pJe);function eln(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]=uQ({prop:n,defaultProp:i??!1,onChange:A,caller:pJe}),[d,m]=te.useState(null),[p,_]=te.useState(null),f=te.useRef(!1),[I,C]=te.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:tD(i)?!1:i,isFormControl:y,bubbleInput:p,setBubbleInput:_};return K.jsx(A7i,{scope:e,...x,children:nln(g)?g(x):o})}eD(eln,"CheckboxProvider");var c7i="CheckboxTrigger",l7i=te.forwardRef(eD(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}=_Je(c7i,e),_=KA(r,g),f=te.useRef(c);return te.useEffect(()=>{const I=s?.form;if(I){const C=eD(()=>u(f.current),"reset");return I.addEventListener("reset",C),()=>I.removeEventListener("reset",C)}},[s,u]),K.jsx(ba.button,{type:"button",role:"checkbox","aria-checked":tD(c)?"mixed":c,"aria-required":l,"data-state":fJe(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=>tD(C)?!0:!C),p&&m&&(h.current=I.isPropagationStopped(),h.current||I.stopPropagation())})})},"CheckboxTrigger")),tln=te.forwardRef(eD(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 K.jsx(eln,{__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})=>K.jsxs(K.Fragment,{children:[K.jsx(l7i,{...u,ref:n,__scopeCheckbox:o}),h&&K.jsx(h7i,{__scopeCheckbox:o})]})})},"Checkbox")),g7i="CheckboxIndicator",u7i=te.forwardRef(eD(function(e,n){const{__scopeCheckbox:o,forceMount:i,...r}=e,s=_Je(g7i,o);return K.jsx(V2,{present:i||tD(s.checked)||s.checked===!0,children:K.jsx(ba.span,{"data-state":fJe(s.checked),"data-disabled":s.disabled?"":void 0,...r,ref:n,style:{pointerEvents:"none",...e.style}})})},"CheckboxIndicator")),d7i="CheckboxBubbleInput",h7i=te.forwardRef(eD(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}=_Je(d7i,e),_=KA(i,p),f=TVe(r),I=te.useRef(!1),C=te.useRef(A),y=te.useRef(a);te.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 T=new Event("click",{bubbles:k});E.indeterminate=tD(A),Q.call(E,tD(A)?!1:A),E.dispatchEvent(T),I.current=!1}},[m,A,s,a]);const x=te.useRef(tD(A)?!1:A);return K.jsx(ba.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 nln(t){return typeof t=="function"}eD(nln,"isFunction");function tD(t){return t==="indeterminate"}eD(tD,"isIndeterminate");function fJe(t){return tD(t)?"indeterminate":t?"checked":"unchecked"}eD(fJe,"getState");const E$=te.forwardRef(({className:t,...e},n)=>K.jsx(tln,{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:K.jsx(u7i,{className:ki("rf-flex rf-items-center rf-justify-center rf-text-current"),children:K.jsx(UM,{className:"rf-h-4 rf-w-4"})})}));E$.displayName=tln.displayName;const GR=K0e,m7i=V0e,oln=te.forwardRef(({className:t,...e},n)=>K.jsx(qX,{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}));oln.displayName=qX.displayName;const Z9=te.forwardRef(({className:t,children:e,showOverlay:n=!0,...o},i)=>K.jsxs(m7i,{children:[K.jsx(oln,{className:ki(n?"":"rf-hidden")}),K.jsx($X,{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})]}));Z9.displayName=$X.displayName;const e7=({className:t,...e})=>K.jsx("div",{className:ki("rf-flex rf-flex-col rf-space-y-2 rf-text-center sm:rf-text-left",t),...e});e7.displayName="DialogHeader";const QY=({className:t,...e})=>K.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});QY.displayName="DialogFooter";const t7=te.forwardRef(({className:t,...e},n)=>K.jsx(z0e,{ref:n,className:ki("rf-text-lg rf-font-semibold",t),...e}));t7.displayName=z0e.displayName;const YR=te.forwardRef(({className:t,...e},n)=>K.jsx(J0e,{ref:n,className:ki("rf-text-sm rf-text-zinc-500 dark:rf-text-zinc-400",t),...e}));YR.displayName=J0e.displayName;const Tme={"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"}},p7i="https://cdn.jsdelivr.net/npm/easyeda@latest/dist/browser/index.js";let IJe=null;const CJe=async()=>(IJe||(IJe=import(p7i)),IJe),_7i=t=>(e,n)=>{const o=new Headers(n?.headers),i={};return o.forEach((r,s)=>{i[s]=r}),fetch(`${t?.apiBase??ry}/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}})},f7i=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??[]},I7i=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}),iln=async(t,e)=>{const{fetchEasyEDAComponent:n}=await CJe();return n(t,{fetch:_7i(e),includeModelMetadata:e?.includeModelMetadata})},C7i=async(t,e)=>{const{convertRawEasyToTsx:n}=await CJe(),o=await iln(t,e);return n({rawEasy:o})},y7i=async(t,e)=>{const{EasyEdaJsonSchema:n,convertEasyEdaJsonToCircuitJson:o}=await CJe(),i=await iln(t,{...e,includeModelMetadata:!1}),r=n.parse(i);return o(r,{shouldRecenter:!0,showDesignator:!0,useModelCdn:!1})};function n7(t){return Array.isArray?Array.isArray(t):sln(t)==="[object Array]"}function x7i(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 yJe(t){return t==null?"":x7i(t)}function dy(t){return typeof t=="string"}function kme(t){return typeof t=="number"}function E7i(t){return t===!0||t===!1||B7i(t)&&sln(t)=="[object Boolean]"}function rln(t){return typeof t=="object"}function B7i(t){return rln(t)&&t!==null}function _B(t){return t!=null}function Fme(t){return!t.trim().length}function sln(t){return t==null?t===void 0?"[object Undefined]":"[object Null]":Object.prototype.toString.call(t)}const S7i="Incorrect 'index' type",xJe="Invalid doc index: must be a non-negative integer within the bounds of the docs array",b7i=t=>`Invalid value for key ${t}`,Q7i=t=>`Pattern length exceeds max of ${t}.`,v7i=t=>`Missing ${t} property in key`,P7i=t=>`Property 'weight' in key '${t}' must be a positive integer`,w7i="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.",aln=Object.prototype.hasOwnProperty;var M7i=class{constructor(t){this._keys=[],this._keyMap={};let e=0;t.forEach(n=>{const o=Aln(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 Aln(t){let e=null,n=null,o=null,i=1,r=null;if(dy(t)||n7(t))o=t,e=cln(t),n=Lme(t);else{if(!aln.call(t,"name"))throw new Error(v7i("name"));const s=t.name;if(o=s,aln.call(t,"weight")&&t.weight!==void 0&&(i=t.weight,i<=0))throw new Error(P7i(Lme(s)));e=cln(s),n=Lme(s),r=t.getFn??null}return{path:e,id:n,weight:i,src:o,getFn:r}}function cln(t){return n7(t)?t:t.split(".")}function Lme(t){return n7(t)?t.join("."):t}function D7i(t,e){const n=[];let o=!1;const i=(r,s,a,A)=>{if(_B(r))if(!s[a])n.push(A!==void 0?{v:r,i:A}:r);else{const c=r[s[a]];if(!_B(c))return;if(a===s.length-1&&(dy(c)||kme(c)||E7i(c)||typeof c=="bigint"))n.push(A!==void 0?{v:yJe(c),i:A}:yJe(c));else if(n7(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,dy(e)?e.split("."):e,0),o?n:n[0]}const xa=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:D7i,ignoreLocation:!1,ignoreFieldNorm:!1,fieldNormWeight:1}});function N7i(t){return t>=9&&t<=13||t===32||t===160}function R7i(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++)N7i(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 EJe=class{constructor({getFn:t=xa.getFn,fieldNormWeight:e=xa.fieldNormWeight}={}){this.norm=R7i(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(dy(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(xJe);if(dy(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(xJe);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!_B(t)||Fme(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(_B(s)){if(n7(s)){const a=[];for(let A=0,c=s.length;A<c;A+=1){const l=s[A];if(_B(l)){if(dy(l)){if(!Fme(l)){const g={v:l,i:A,n:this.norm.get(l)};a.push(g)}}else if(_B(l.v)){const g=dy(l.v)?l.v:yJe(l.v);if(!Fme(g)){const u={v:g,i:l.i,n:this.norm.get(g)};a.push(u)}}}}n.$[o]=a}else if(dy(s)&&!Fme(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 lln(t,e,{getFn:n=xa.getFn,fieldNormWeight:o=xa.fieldNormWeight}={}){const i=new EJe({getFn:n,fieldNormWeight:o});return i.setKeys(t.map(Aln)),i.setSources(e),i.create(),i}function T7i(t,{getFn:e=xa.getFn,fieldNormWeight:n=xa.fieldNormWeight}={}){const{keys:o,records:i}=t,r=new EJe({getFn:e,fieldNormWeight:n});return r.setKeys(o),r.setIndexRecords(i),r}function k7i(t=[],e=xa.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 F7i(t,e,n,{location:o=xa.location,distance:i=xa.distance,threshold:r=xa.threshold,findAllMatches:s=xa.findAllMatches,minMatchCharLength:a=xa.minMatchCharLength,includeMatches:A=xa.includeMatches,ignoreLocation:c=xa.ignoreLocation}={}){if(e.length>32)throw new Error(Q7i(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,T=Array(k+2);T[k+1]=(1<<b)-1;for(let H=k;H>=D;H-=1){const G=H-1,U=n[t[G]];if(T[H]=(T[H+1]<<1|1)&U,b&&(T[H]|=(I[H+1]|I[H])<<1|1|I[H+1]),T[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=T}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=k7i(_,a);b.length?A&&(B.indices=b):B.isMatch=!1}return B}function L7i(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 BJe(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 gln={ł:"l",Ł:"L",đ:"d",Đ:"D",ø:"o",Ø:"O",ħ:"h",Ħ:"H",ŧ:"t",Ŧ:"T",ı:"i",ß:"ss"},H7i=new RegExp("["+Object.keys(gln).join("")+"]","g"),B$=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(H7i,e=>gln[e]):t=>t;var SJe=class{constructor(t,{location:e=xa.location,threshold:n=xa.threshold,distance:o=xa.distance,includeMatches:i=xa.includeMatches,findAllMatches:r=xa.findAllMatches,minMatchCharLength:s=xa.minMatchCharLength,isCaseSensitive:a=xa.isCaseSensitive,ignoreDiacritics:A=xa.ignoreDiacritics,ignoreLocation:c=xa.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?B$(t):t,this.pattern=t,this.chunks=[],!this.pattern.length)return;const l=(u,h)=>{this.chunks.push({pattern:u,alphabet:L7i(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?B$(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}=F7i(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=BJe(l)),h}};const O7i=new Set(["fuzzy","include"]);function G7i(t){return t.startsWith("inverse")}const bJe=[{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 SJe(t,{location:e.location??xa.location,threshold:e.threshold??xa.threshold,distance:e.distance??xa.distance,includeMatches:e.includeMatches??xa.includeMatches,findAllMatches:e.findAllMatches??xa.findAllMatches,minMatchCharLength:e.minMatchCharLength??xa.minMatchCharLength,isCaseSensitive:e.isCaseSensitive??xa.isCaseSensitive,ignoreDiacritics:e.ignoreDiacritics??xa.ignoreDiacritics,ignoreLocation:e.ignoreLocation??xa.ignoreLocation});return{type:"fuzzy",search(o){return n.searchIn(o)}}}}],uln=bJe.length,Y7i="\0",U7i="|";function K7i(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 V7i(t,e={}){return t.replace(/\\\|/g,Y7i).split(U7i).map(n=>{const o=K7i(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<uln;){const l=bJe[c],g=dln(a,l.multiRegex);g&&(i.push(l.create(g,e)),A=!0)}if(!A)for(c=-1;++c<uln;){const l=bJe[c],g=dln(a,l.singleRegex);if(g){i.push(l.create(g,e));break}}}return i})}var z7i=class{constructor(t,{isCaseSensitive:e=xa.isCaseSensitive,ignoreDiacritics:n=xa.ignoreDiacritics,includeMatches:o=xa.includeMatches,minMatchCharLength:i=xa.minMatchCharLength,ignoreLocation:r=xa.ignoreLocation,findAllMatches:s=xa.findAllMatches,location:a=xa.location,threshold:A=xa.threshold,distance:c=xa.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?B$(t):t,this.pattern=t,this.query=V7i(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?B$(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+=_,G7i(d.type)&&(A=!0),n&&(O7i.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=BJe(s)),u}}return{isMatch:!1,score:1}}};const QJe=[];function vJe(...t){QJe.push(...t)}function Hme(t,e){for(let n=0,o=QJe.length;n<o;n+=1){const i=QJe[n];if(i.condition(t,e))return new i(t,e)}return new SJe(t,e)}const Ome={AND:"$and",OR:"$or"},PJe={PATH:"$path",PATTERN:"$val"},wJe=t=>!!(t[Ome.AND]||t[Ome.OR]),J7i=t=>!!t[PJe.PATH],W7i=t=>!n7(t)&&rln(t)&&!wJe(t),hln=t=>({[Ome.AND]:Object.keys(t).map(e=>({[e]:t[e]}))});function mln(t,e,{auto:n=!0}={}){const o=i=>{if(dy(i)){const A={keyId:null,pattern:i};return n&&(A.searcher=Hme(i,e)),A}const r=Object.keys(i),s=J7i(i);if(!s&&r.length>1&&!wJe(i))return o(hln(i));if(W7i(i)){const A=s?i[PJe.PATH]:r[0],c=s?i[PJe.PATTERN]:i[A];if(!dy(c))throw new Error(b7i(A));const l={keyId:Lme(A),pattern:c};return n&&(l.searcher=Hme(c,e)),l}const a={children:[],operator:r[0]};return r.forEach(A=>{const c=i[A];n7(c)&&c.forEach(l=>{a.children.push(o(l))})}),a};return wJe(t)||(t=hln(t)),o(t)}function MJe(t,{ignoreFieldNorm:e=xa.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 j7i(t,{ignoreFieldNorm:e=xa.ignoreFieldNorm}){t.forEach(n=>{n.score=MJe(n.matches,{ignoreFieldNorm:e})})}var q7i=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 X7i(t){const e=[];return t.matches.forEach(n=>{if(!_B(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 $7i(t,e,{includeMatches:n=xa.includeMatches,includeScore:o=xa.includeScore}={}){return t.map(i=>{const{idx:r}=i,s={item:e[r],refIndex:r};return n&&(s.matches=X7i(i)),o&&(s.score=i.score),s})}const Z7i=/[\p{L}\p{M}\p{N}_]+/gu,pln=new WeakSet;function e6i(t){pln.has(t)||(pln.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 t6i(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||e6i(t),e=>e.match(t)||[]):e=>e.match(Z7i)||[]}function DJe({isCaseSensitive:t=!1,ignoreDiacritics:e=!1,tokenize:n}={}){const o=t6i(n);return{tokenize(i){return t||(i=i.toLowerCase()),e&&(i=B$(i)),o(i)}}}var n6i=class{static condition(t,e){return e.useTokenSearch}constructor(t,e){this.options=e,this.analyzer=DJe({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 SJe(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=BJe(e)),this.combineAll&&(this.useMask?A.matchedMask=r:A.matchedTerms=s,A.termCount=this.numTerms),A}};function NJe(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 _ln(t,e,n,o){const{i,v:r,$:s}=e;if(r!==void 0){NJe(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)NJe(t,c.v,i,o);else NJe(t,A.v,i,o)}}function o6i(t,e,n){const o={fieldCount:0,df:new Map,docFieldCount:new Map,docTermFieldHits:new Map};for(const i of t)_ln(o,i,e,n);return o}function i6i(t,e,n,o){_ln(t,e,n,o)}function r6i(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)r6i(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 o7=class{constructor(t,e,n){this.options={...xa,...e},this.options.useExtendedSearch,this.options.useTokenSearch,this._keyStore=new M7i(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=Hme(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 EJe))throw new Error(S7i);if(this._myIndex=e||lln(this.options.keys,this._docs,{getFn:this.options.getFn,fieldNormWeight:this.options.fieldNormWeight}),this.options.useTokenSearch){const n=DJe({isCaseSensitive:this.options.isCaseSensitive,ignoreDiacritics:this.options.ignoreDiacritics,tokenize:this.options.tokenize});this._invertedIndex=o6i(this._myIndex.records,this._myIndex.keys.length,n)}this._invalidateSearcherCache()}add(t){if(!_B(t))return;this._docs.push(t);const e=this._myIndex.add(t,this._docs.length-1);if(this._invertedIndex&&e){const n=DJe({isCaseSensitive:this.options.isCaseSensitive,ignoreDiacritics:this.options.ignoreDiacritics,tokenize:this.options.tokenize});i6i(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(xJe);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(dy(t)&&!t.trim()){let u=this._docs.map((h,d)=>({item:h,refIndex:d}));return kme(n)&&n>-1&&(u=u.slice(0,n)),u}const A=r&&kme(n)&&n>0&&dy(t),c=s,l=(u,h)=>c(u,h)||u.idx-h.idx;let g;if(A){const u=new q7i(n,l);dy(this._docs[0])?this._searchStringList(t,{heap:u,ignoreFieldNorm:a}):this._searchObjectList(t,{heap:u,ignoreFieldNorm:a}),g=u.extractSorted()}else g=dy(t)?dy(this._docs[0])?this._searchStringList(t):this._searchObjectList(t):this._searchLogical(t),j7i(g,{ignoreFieldNorm:a}),r&&g.sort(dy(t)?l:c),kme(n)&&n>-1&&(g=g.slice(0,n));return $7i(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(!_B(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=MJe(h.matches,{ignoreFieldNorm:n}),e.insert(h)):s.push(h)}}}),s}_searchLogical(t){const e=mln(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===Ome.AND)return[]}return u},i=this._myIndex.records,r=new Map,s=[];return i.forEach(({$:a,i:A})=>{if(_B(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(!_B(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=MJe(h.matches,{ignoreFieldNorm:n}),e.insert(h)):a.push(h)}}),a}_findMatches({key:t,value:e,searcher:n}){if(!_B(e))return[];const o=[];if(n7(e))e.forEach(({v:i,i:r,n:s})=>{if(!_B(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}};o7.version="7.5.0",o7.createIndex=lln,o7.parseIndex=T7i,o7.config=xa,o7.match=function(t,e,n){if(n&&n.useTokenSearch)throw new Error(w7i);return Hme(t,{...xa,...n}).searchIn(e)},o7.parseQuery=mln,vJe(z7i),vJe(n6i),o7.use=function(...t){t.forEach(e=>vJe(e))};var s6i=o7;const a6i="https://kicad-mod-cache.tscircuit.com";let RJe=null,S$=null,TJe=null;const A6i=async()=>RJe||S$||(S$=fetch("https://kicad-mod-cache.tscircuit.com/kicad_files.json").then(t=>t.json()).then(t=>(RJe=t,S$=null,t)),S$),c6i=async(t,e=20)=>{const n=await A6i();return TJe||(TJe=new s6i(n)),TJe.search(t).slice(0,e).map(o=>o.item)},l6i=t=>{const e=t.replace(".pretty/","/").replace(".kicad_mod",""),n=`kicad:${e}`;return{path:t,qualifiedName:n,description:e}},g6i=t=>t.replace(/^\/+/,"").split("/").map(e=>encodeURIComponent(e)).join("/"),u6i=async t=>{const e=await fetch(`${a6i}/${g6i(t)}`);if(!e.ok)throw new Error(`KiCad footprint fetch failed: ${e.status}`);const n=await e.text(),{KicadFootprintToCircuitJsonConverter:o}=await lB("kicad-to-circuit-json"),i=new o;return i.addFile(t.split("/").pop()??"selected-footprint.kicad_mod",n),i.runUntilFinished(),i.getOutput()},Iln=t=>t?.source==="jlcpcb"||t?.source==="kicad",d6i=async(t,e)=>{if(t.source==="jlcpcb")return y7i(t.component.partNumber,e?.jlcpcb);if(t.source==="kicad")return u6i(t.footprint.path);throw new Error("Footprint preview is not available for this source")},h6i=({query:t,placeholder:e,isSearching:n,onQueryChange:o,onSubmit:i})=>{const r=te.useCallback(s=>{s.key==="Enter"&&(s.preventDefault(),i())},[i]);return K.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2 rf-mt-4",children:[K.jsxs("div",{className:"rf-relative rf-flex-grow",children:[K.jsx(dVe,{className:"rf-absolute rf-left-2 rf-top-2.5 rf-h-4 rf-w-4 rf-text-muted-foreground"}),K.jsx(dze,{placeholder:e,className:"rf-pl-8",spellCheck:!1,autoComplete:"off",value:t,onChange:s=>o(s.target.value),onKeyDown:r})]}),K.jsx(gA,{onClick:i,disabled:n||t.trim().length<1,className:"sm:rf-px-4 rf-px-3",children:n?K.jsx(rB,{className:"rf-h-4 rf-w-4 rf-animate-spin"}):K.jsxs(K.Fragment,{children:[K.jsx(dVe,{className:"rf-h-4 rf-w-4 sm:rf-hidden"}),K.jsx("span",{className:"rf-hidden sm:rf-inline",children:"Search"})]})})]})},m6i=new Intl.NumberFormat("en-US",{style:"currency",currency:"USD"}),p6i=t=>m6i.format(t),Cln=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"}},_6i=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}},f6i=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}},I6i=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}},C6i=({results:t,selected:e,onSelect:n,onShowDetails:o})=>{const i=e?Cln(e):null;return K.jsx("div",{className:"rf-divide-y rf-w-full rf-overflow-hidden",children:t.map(r=>{const s=Cln(r),a=i===s,A=_6i(r),c=f6i(r),l=I6i(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 K.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:[K.jsxs("div",{className:"rf-min-w-0 rf-overflow-hidden rf-w-full",children:[K.jsxs("div",{className:"rf-flex rf-items-start rf-gap-2 rf-min-w-0",children:[K.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&&K.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&&K.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&&K.jsx(wEi,{className:"rf-ml-1 rf-h-3 rf-w-3 rf-text-zinc-400 rf-flex-shrink-0"})]}),r.source==="jlcpcb"&&g!=null?K.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]}),K.jsxs("div",{className:"rf-text-xs rf-text-zinc-500 rf-truncate rf-w-full",children:[l?K.jsx("span",{className:"rf-mr-2",children:l}):null,c]})]}),K.jsxs("div",{children:[r.source==="tscircuit.com"&&o?K.jsx("div",{className:"rf-flex-shrink-0 rf-w-full sm:rf-w-auto",children:K.jsx(gA,{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?K.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&&K.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:p6i(u)})]})]},s)})})},y6i=({circuitJson:t,error:e,isLoading:n,height:o})=>K.jsx("section",{className:"rf-flex rf-min-w-0 rf-items-center rf-justify-center",style:{height:o},children:n?K.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:[K.jsx(rB,{className:"rf-h-4 rf-w-4 rf-animate-spin"}),"Loading preview..."]}):e?K.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:K.jsxs("div",{className:"rf-flex rf-max-w-[320px] rf-items-start rf-gap-2 rf-text-sm rf-text-zinc-300",children:[K.jsx(uVe,{className:"rf-mt-0.5 rf-h-4 rf-w-4 rf-flex-shrink-0"}),K.jsx("span",{children:e})]})}):t?K.jsx("div",{className:"rf-w-full rf-min-w-0 rf-overflow-hidden",children:K.jsx(eJe,{circuitJson:t,height:o,allowEditing:!1,clickToInteractEnabled:!1,focusOnHover:!1,disablePcbGroups:!0})}):K.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"})}),yln={importComponentDialog:101,importComponentDetailsDialog:102},x6i=({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 K.jsx(GR,{open:e,onOpenChange:n,children:K.jsxs(Z9,{showOverlay:!1,style:{width:"calc(100vw - 2rem)",zIndex:yln.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:[K.jsx(e7,{className:"rf-pb-4 rf-border-b",children:K.jsx("div",{className:"rf-flex rf-items-start rf-justify-between rf-gap-4",children:K.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[K.jsx(t7,{className:"rf-text-xl rf-font-semibold rf-truncate",children:h}),K.jsx(YR,{children:c?.description})]})})}),K.jsxs("div",{className:"rf-flex-1 rf-overflow-y-auto rf-py-4 rf-space-y-6",children:[d?K.jsxs("div",{children:[K.jsx("span",{className:"rf-text-xs rf-font-medium rf-text-gray-500 rf-uppercase rf-tracking-wide",children:"Created by"}),K.jsx("div",{className:"rf-mt-1 rf-text-sm rf-font-medium",children:m?K.jsx("a",{href:m,target:"_blank",rel:"noopener noreferrer",className:"rf-text-black hover:rf-underline",children:d}):d})]}):null,(u||l||g)&&K.jsx(K.Fragment,{children:K.jsxs("div",{children:[K.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-mb-4",children:"Preview"}),K.jsxs(T6e,{value:r,onValueChange:_=>s(_),children:[K.jsxs(Kge,{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&&K.jsx(Gv,{value:"pcb",children:"PCB"}),g&&K.jsx(Gv,{value:"schematic",children:"Schematic"}),u&&K.jsx(Gv,{value:"3d",children:"3D"})]}),K.jsxs("div",{className:"rf-mt-4",children:[K.jsx(UI,{value:"pcb",className:"rf-border rf-rounded-lg rf-overflow-hidden rf-bg-gray-50",children:l?K.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}),K.jsx(UI,{value:"schematic",className:"rf-border rf-rounded-lg rf-overflow-hidden rf-bg-gray-50",children:g?K.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}),K.jsx(UI,{value:"3d",className:"rf-border rf-rounded-lg rf-overflow-hidden rf-bg-gray-50",children:u?K.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?K.jsxs("section",{children:[K.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-mb-3",children:"AI Description"}),K.jsx("div",{className:"rf-bg-gray-50 rf-border rf-border-gray-200 rf-rounded-lg rf-p-4",children:K.jsx("p",{className:"rf-text-sm rf-text-gray-700 rf-leading-relaxed",children:i.ai_description})})]}):null,i?.ai_usage_instructions?K.jsxs("section",{children:[K.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-mb-3",children:"Usage Instructions"}),K.jsx("div",{className:"rf-bg-gray-50 rf-border rf-border-gray-200 rf-rounded-lg rf-p-4",children:K.jsx("p",{className:"rf-text-sm rf-text-gray-700 rf-leading-relaxed rf-whitespace-pre-wrap",children:i.ai_usage_instructions})})]}):null,o?K.jsxs("div",{className:"rf-flex rf-justify-center rf-items-center rf-gap-2 rf-text-gray-500",children:[K.jsx(rB,{className:"rf-h-4 rf-w-4 rf-animate-spin"}),K.jsx("span",{className:"rf-text-sm",children:"Loading package details..."})]}):null]}),K.jsxs(QY,{className:"rf-pt-4 rf-border-t rf-flex rf-flex-col sm:rf-flex-row rf-justify-between rf-gap-2",children:[K.jsx("div",{className:"rf-flex-1",children:p?K.jsxs(gA,{variant:"outline",size:"sm",className:"rf-gap-2 rf-w-full sm:rf-w-auto",onClick:()=>window.open(p,"_blank"),children:[K.jsx(EEi,{className:"rf-h-4 rf-w-4"}),"View on tscircuit.com"]}):null}),K.jsxs("div",{className:"rf-flex rf-flex-col sm:rf-flex-row rf-gap-2",children:[K.jsx(gA,{variant:"outline",onClick:()=>n(!1),className:"rf-order-2 sm:rf-order-1",children:"Close"}),K.jsx(gA,{onClick:A,disabled:a,className:"rf-bg-blue-600 hover:rf-bg-blue-700",children:a?K.jsx(rB,{className:"rf-h-4 rf-w-4 rf-animate-spin"}):"Import Component"})]})]})]})})},E6i=()=>{const[t,e]=te.useState(null),[n,o]=te.useState(!1),i=te.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=te.useCallback(()=>{e(null),o(!1)},[]);return{details:t,isLoading:n,fetchDetails:i,reset:r}},B6i=(t,e)=>{const[n,o]=te.useState({circuitJson:null,error:null,isLoading:!1});return te.useEffect(()=>{if(!t||!Iln(t)){o({circuitJson:null,error:null,isLoading:!1});return}let i=!1;return o({circuitJson:null,error:null,isLoading:!0}),d6i(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},S6i=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??[]},b6i=({sessionToken:t})=>{const[e,n]=te.useState([]),[o,i]=te.useState(!1),[r,s]=te.useState(null),[a,A]=te.useState(!1),c=te.useCallback(async g=>{const u=g.trim();if(!u)return[];i(!0),s(null);try{const d=(await S6i(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=te.useCallback(()=>{n([]),i(!1),s(null),A(!1)},[]);return{results:e,isSearching:o,error:r,hasSearched:a,search:c,reset:l}},Q6i=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}}},xln=(t,e)=>{const n=Q6i(t);return n?e.some(i=>i.component.partNumber.toUpperCase()===n.component.partNumber)?e:[n,...e]:e},v6i=t=>{const e=t.trim();return/^C\d+/i.test(e)?e.replace(/^C/i,""):e},P6i=()=>{const[t,e]=te.useState([]),[n,o]=te.useState(!1),[i,r]=te.useState(null),[s,a]=te.useState(!1),A=te.useCallback(async l=>{const g=v6i(l);if(!g)return[];o(!0),r(null);try{const u=await f7i(g,10),h=xln(l,u.map(d=>({source:"jlcpcb",component:I7i(d)})));return e(h),h}catch(u){console.error("Error searching JLCPCB components",u);const h=xln(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=te.useCallback(()=>{e([]),o(!1),r(null),a(!1)},[]);return{results:t,isSearching:n,error:i,hasSearched:s,search:A,reset:c}},w6i=()=>{const[t,e]=te.useState([]),[n,o]=te.useState(!1),[i,r]=te.useState(null),[s,a]=te.useState(!1),A=te.useCallback(async l=>{const g=l.trim();if(!g)return[];o(!0),r(null);try{const h=(await c6i(g,20)).map(d=>({source:"kicad",footprint:l6i(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=te.useCallback(()=>{e([]),o(!1),r(null),a(!1)},[]);return{results:t,isSearching:n,error:i,hasSearched:s,search:A,reset:c}},M6i=({onTscircuitPackageSelected:t,onJlcpcbComponentTsxLoaded:e,onKicadStringSelected:n})=>{const o=[];return t&&o.push("tscircuit.com"),e&&o.push("jlcpcb"),n&&o.push("kicad"),o},D6i=({isOpen:t,onClose:e,jlcpcbProxyRequestHeaders:n,onKicadStringSelected:o,onTscircuitPackageSelected:i,onJlcpcbComponentTsxLoaded:r,jlcpcbProxyApiBase:s,tscircuitSessionToken:a})=>{C$();const A=te.useMemo(()=>M6i({onKicadStringSelected:o,onTscircuitPackageSelected:i,onJlcpcbComponentTsxLoaded:r}),[o,i,r]),c=A.length>0,l=A.length===1,[g,u]=te.useState(A[0]??"tscircuit.com"),[h,d]=te.useState(""),[m,p]=te.useState(null),{results:_,isSearching:f,error:I,hasSearched:C,search:y,reset:x}=b6i({sessionToken:a}),{results:E,isSearching:B,error:b,hasSearched:Q,search:w,reset:D}=P6i(),{results:k,isSearching:T,error:H,hasSearched:G,search:U,reset:Y}=w6i(),{details:q,isLoading:ee,fetchDetails:W,reset:J}=E6i(),[ie,oe]=te.useState(null),[ne,le]=te.useState(!1),[ue,_e]=te.useState("pcb"),[ce,Ie]=te.useState(null),[he,Ce]=te.useState(!1),Pe=te.useMemo(()=>({jlcpcb:{headers:n,apiBase:s}}),[s,n]),{circuitJson:Qe,error:pe,isLoading:ve}=B6i(m,Pe),Me=Iln(m);te.useEffect(()=>{Ie(null)},[m]);const we=te.useCallback(()=>{x(),D(),Y(),p(null)},[D,Y,x]);te.useEffect(()=>{t||(we(),d(""),le(!1),oe(null),Ie(null))},[t,we]),te.useEffect(()=>{d(""),p(null),g==="tscircuit.com"?x():g==="jlcpcb"?D():g==="kicad"&&Y()},[g,D,Y,x]);const Oe=je=>{p(je),oe(je),_e("pcb"),le(!0),J();const ht=je.package.org_owner_tscircuit_handle,Bt=je.package.unscoped_name;if(ht&&Bt){const Ct=Bt.split("/").pop()??Bt;W(ht,Ct)}},Re=async()=>{h.trim()&&(p(null),g==="tscircuit.com"?await y(h):g==="jlcpcb"?await w(h):g==="kicad"&&await U(h))},Se=async je=>{try{if(Ie(null),Ce(!0),je.source==="kicad"){if(!o)throw new Error("KiCad handler not provided");await o({result:je,footprint:je.footprint.qualifiedName})}else if(je.source==="jlcpcb"){if(!r)throw new Error("JLCPCB handler not provided");const ht=await C7i(je.component.partNumber,{headers:n,apiBase:s});await r({result:je,tsx:ht})}else if(je.source==="tscircuit.com"){if(!i)throw new Error("tscircuit package handler not provided");const ht=je.package.org_owner_tscircuit_handle,Bt=je.package.unscoped_name;if(!ht||!Bt)throw new Error("Missing package metadata");const Ct=Bt.split("/").pop()??Bt,Ht=`@tsci/${ht}.${Ct}`;await i({result:je,fullPackageName:Ht})}return!0}catch(ht){return console.error("Failed to import component",ht),Ie(ht instanceof Error?ht.message:"Failed to import component"),!1}finally{Ce(!1)}};let Le=[],ye=!1,ke=null,Ye=!1;g==="tscircuit.com"?(Le=_,ye=f,ke=I,Ye=C):g==="jlcpcb"?(Le=E,ye=B,ke=b,Ye=Q):g==="kicad"&&(Le=k,ye=T,ke=H,Ye=G);const $e=async()=>{if(!m)return;await Se(m)&&(e(),we(),d(""))},st=je=>{je||e()},it=je=>{le(je),je||oe(null)};return K.jsxs(GR,{open:t,onOpenChange:st,children:[K.jsxs(Z9,{style:{width:"calc(100vw - 2rem)",maxWidth:Me?"min(1120px, calc(100vw - 2rem))":"min(672px, calc(100vw - 2rem))",zIndex:yln.importComponentDialog},className:"rf-rounded-sm rf-max-h-[90vh] rf-overflow-y-auto rf-overflow-x-hidden rf-flex rf-flex-col",children:[K.jsxs(e7,{children:[K.jsxs(t7,{className:"rf-text-lg sm:rf-text-xl",children:["Import ",l?Tme[g].label:""," ","Component"]}),K.jsx(YR,{className:"rf-text-sm",children:c?"Search for components from available sources.":"Import options are disabled because no handlers were provided."})]}),c?K.jsxs(T6e,{value:g,onValueChange:je=>u(je),className:"rf-min-w-0 rf-w-full",children:[!l&&K.jsx(Kge,{className:"rf-flex rf-w-full rf-gap-2",children:A.map(je=>K.jsx(Gv,{value:je,className:"rf-flex-1 rf-text-xs sm:rf-text-sm",children:Tme[je].label},je))}),K.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:[K.jsxs("div",{className:"rf-min-w-0",children:[K.jsx(h6i,{query:h,placeholder:Tme[g].placeholder,isSearching:ye,onQueryChange:d,onSubmit:Re}),K.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?K.jsxs("div",{className:"rf-p-8 rf-text-center rf-text-zinc-500",children:[K.jsx(rB,{className:"rf-h-8 rf-w-8 rf-animate-spin rf-mx-auto rf-mb-2"}),K.jsx("p",{children:"Searching..."})]}):Le.length>0?K.jsx(C6i,{results:Le,selected:m,onSelect:p,onShowDetails:g==="tscircuit.com"?Oe:void 0}):K.jsx("div",{className:"rf-p-8 rf-text-center rf-text-zinc-500",children:ke?`Error: ${ke}`:Ye?Tme[g].emptyMessage:"Enter a search term to find components"})})]}),Me?K.jsx("div",{className:"rf-mt-4",children:K.jsx(y6i,{circuitJson:Qe,error:pe,isLoading:ve,height:325})}):null]})]}):null,ce?K.jsx("div",{className:"rf-text-sm rf-text-red-600 rf-mt-2",children:ce}):null,K.jsxs(QY,{className:"rf-flex rf-flex-col sm:rf-flex-row rf-gap-2",children:[K.jsx(gA,{variant:"outline",onClick:e,className:"rf-order-2 sm:rf-order-1",children:"Cancel"}),K.jsx(gA,{onClick:$e,disabled:!m||he,className:"rf-order-1 sm:rf-order-2",children:he?K.jsx(rB,{className:"rf-h-4 rf-w-4 rf-animate-spin"}):"Import"})]})]}),K.jsx(x6i,{packageResult:ie,isOpen:ne,onOpenChange:it,isLoading:ee,details:q,previewTab:ue,onPreviewTabChange:je=>_e(je),isSubmitting:he,onImport:()=>{ie&&Se(ie).then(je=>{je&&(le(!1),e(),we(),d(""))})}})]})},N6i=t=>{const e=t.match(/export const (\w+) =/);if(!e)throw new Error("Could not determine component name from TSX contents");return e[1]},Eln=t=>{const e=nh(s=>s.pushEvent),n=nh(s=>s.upsertFile),o=async({result:s,fullPackageName:a})=>{const c=s.package.unscoped_name??s.package.name;await ia.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 ia.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/${N6i(a)}.tsx`;await ia.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 K.jsx(D6i,{...t,onTscircuitPackageSelected:o,onKicadStringSelected:i,onJlcpcbComponentTsxLoaded:r})};Eln.displayName="ImportComponentDialogForCli";const R6i=async({circuitJson:t,projectName:e})=>{const{convertCircuitJsonToAltiumZip:n}=await Promise.resolve().then(()=>inr),o=await n(t,e);return new Blob([new Uint8Array(o)],{type:"application/zip"})},T6i=async({circuitJson:t,projectName:e})=>{await ia.promise((async()=>{const n=await R6i({circuitJson:t,projectName:e});pB(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 kJe={exports:{}},Bln;function k6i(){return Bln||(Bln=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 cw=="function"&&cw;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 cw=="function"&&cw,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)),T=Q.length!==x.name.length,H=k.length!==w.length,G="",U="",Y="",q=x.dir,ee=x.date,W={crc32:0,compressedSize:0,uncompressedSize:0};m&&!p||(W.crc32=d.crc32,W.compressedSize=d.compressedSize,W.uncompressedSize=d.uncompressedSize);var J=0;m&&(J|=8),B||!T&&!H||(J|=2048);var ie=0,oe=0;q&&(ie|=16),f==="UNIX"?(oe=798,ie|=(function(le,ue){var _e=le;return le||(_e=ue?16893:33204),(65535&_e)<<16})(x.unixPermissions,q)):(oe=20,ie|=(function(le){return 63&(le||0)})(x.dosPermissions)),C=ee.getUTCHours(),C<<=6,C|=ee.getUTCMinutes(),C<<=5,C|=ee.getUTCSeconds()/2,y=ee.getUTCFullYear()-1980,y<<=4,y|=ee.getUTCMonth()+1,y<<=5,y|=ee.getUTCDate(),T&&(U=s(1,1)+s(g(b),4)+Q,G+="up"+s(U.length,2)+U),H&&(Y=s(1,1)+s(g(D),4)+k,G+="uc"+s(Y.length,2)+Y);var ne="";return ne+=`
|
|
5743
5743
|
\0`,ne+=s(J,2),ne+=E.magic,ne+=s(C,2),ne+=s(y,2),ne+=s(W.crc32,4),ne+=s(W.compressedSize,4),ne+=s(W.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 T=new h(x,k,w);this.files[x]=T}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 Wy<"u"?Wy: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,T=113,H=1,G=2,U=3,Y=4;function q(pe,ve){return pe.msg=g[ve],ve}function ee(pe){return(pe<<1)-(4<pe?9:0)}function W(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,Re=pe.strstart,Se=pe.prev_length,Le=pe.nice_match,ye=pe.strstart>pe.w_size-D?pe.strstart-(pe.w_size-D):0,ke=pe.window,Ye=pe.w_mask,$e=pe.prev,st=pe.strstart+w,it=ke[Re+Se-1],je=ke[Re+Se];pe.prev_length>=pe.good_match&&(Oe>>=2),Le>pe.lookahead&&(Le=pe.lookahead);do if(ke[(Me=ve)+Se]===je&&ke[Me+Se-1]===it&&ke[Me]===ke[Re]&&ke[++Me]===ke[Re+1]){Re+=2,Me++;do;while(ke[++Re]===ke[++Me]&&ke[++Re]===ke[++Me]&&ke[++Re]===ke[++Me]&&ke[++Re]===ke[++Me]&&ke[++Re]===ke[++Me]&&ke[++Re]===ke[++Me]&&ke[++Re]===ke[++Me]&&ke[++Re]===ke[++Me]&&Re<st);if(we=w-(st-Re),Re=st-w,Se<we){if(pe.match_start=ve,Le<=(Se=we))break;it=ke[Re+Se-1],je=ke[Re+Se]}}while((ve=$e[ve&Ye])>ye&&--Oe!=0);return Se<=pe.lookahead?Se:pe.lookahead}function ue(pe){var ve,Me,we,Oe,Re,Se,Le,ye,ke,Ye,$e=pe.w_size;do{if(Oe=pe.window_size-pe.lookahead-pe.strstart,pe.strstart>=$e+($e-D)){for(a.arraySet(pe.window,pe.window,$e,$e,0),pe.match_start-=$e,pe.strstart-=$e,pe.block_start-=$e,ve=Me=pe.hash_size;we=pe.head[--ve],pe.head[ve]=$e<=we?we-$e:0,--Me;);for(ve=Me=$e;we=pe.prev[--ve],pe.prev[ve]=$e<=we?we-$e:0,--Me;);Oe+=$e}if(pe.strm.avail_in===0)break;if(Se=pe.strm,Le=pe.window,ye=pe.strstart+pe.lookahead,ke=Oe,Ye=void 0,Ye=Se.avail_in,ke<Ye&&(Ye=ke),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(Re=pe.strstart-pe.insert,pe.ins_h=pe.window[Re],pe.ins_h=(pe.ins_h<<pe.hash_shift^pe.window[Re+1])&pe.hash_mask;pe.insert&&(pe.ins_h=(pe.ins_h<<pe.hash_shift^pe.window[Re+Q-1])&pe.hash_mask,pe.prev[Re&pe.w_mask]=pe.head[pe.ins_h],pe.head[pe.ins_h]=Re,Re++,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(ue(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?U: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(ue(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?U: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 he(){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)),W(this.dyn_ltree),W(this.dyn_dtree),W(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),W(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new a.Buf16(2*y+1),W(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:T,pe.adler=ve.wrap===2?0:1,ve.last_flush=u,A._tr_init(ve),d):q(pe,m)}function Pe(pe){var ve=Ce(pe);return ve===d&&(function(Me){Me.window_size=2*Me.w_size,W(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,Re){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||Re<0||_<Re)return q(pe,m);we===8&&(we=9);var Le=new he;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=Re,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(ue(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?U: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,Re;if(!pe||!pe.state||5<ve||ve<0)return pe?q(pe,m):m;if(we=pe.state,!pe.output||!pe.input&&pe.avail_in!==0||we.status===666&&ve!==h)return q(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=T);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=T,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)){Re=1;break}Re=we.gzindex<we.gzhead.name.length?255&we.gzhead.name.charCodeAt(we.gzindex++):0,oe(we,Re)}while(Re!==0);we.gzhead.hcrc&&we.pending>Oe&&(pe.adler=l(pe.adler,we.pending_buf,we.pending-Oe,Oe)),Re===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)){Re=1;break}Re=we.gzindex<we.gzhead.comment.length?255&we.gzhead.comment.charCodeAt(we.gzindex++):0,oe(we,Re)}while(Re!==0);we.gzhead.hcrc&&we.pending>Oe&&(pe.adler=l(pe.adler,we.pending_buf,we.pending-Oe,Oe)),Re===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=T)):we.status=T),we.pending!==0){if(J(pe),pe.avail_out===0)return we.last_flush=-1,d}else if(pe.avail_in===0&&ee(ve)<=ee(Me)&&ve!==h)return q(pe,-5);if(we.status===666&&pe.avail_in!==0)return q(pe,-5);if(pe.avail_in!==0||we.lookahead!==0||ve!==u&&we.status!==666){var Le=we.strategy===2?(function(ye,ke){for(var Ye;;){if(ye.lookahead===0&&(ue(ye),ye.lookahead===0)){if(ke===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,ke===h?(ie(ye,!0),ye.strm.avail_out===0?U:Y):ye.last_lit&&(ie(ye,!1),ye.strm.avail_out===0)?H:G})(we,ve):we.strategy===3?(function(ye,ke){for(var Ye,$e,st,it,je=ye.window;;){if(ye.lookahead<=w){if(ue(ye),ye.lookahead<=w&&ke===u)return H;if(ye.lookahead===0)break}if(ye.match_length=0,ye.lookahead>=Q&&0<ye.strstart&&($e=je[st=ye.strstart-1])===je[++st]&&$e===je[++st]&&$e===je[++st]){it=ye.strstart+w;do;while($e===je[++st]&&$e===je[++st]&&$e===je[++st]&&$e===je[++st]&&$e===je[++st]&&$e===je[++st]&&$e===je[++st]&&$e===je[++st]&&st<it);ye.match_length=w-(it-st),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,ke===h?(ie(ye,!0),ye.strm.avail_out===0?U:Y):ye.last_lit&&(ie(ye,!1),ye.strm.avail_out===0)?H:G})(we,ve):s[we.level].func(we,ve);if(Le!==U&&Le!==Y||(we.status=666),Le===H||Le===U)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&&(W(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!==T&&ve!==666?q(pe,m):(pe.state=null,ve===T?q(pe,-3):d):m},r.deflateSetDictionary=function(pe,ve){var Me,we,Oe,Re,Se,Le,ye,ke,Ye=ve.length;if(!pe||!pe.state||(Re=(Me=pe.state).wrap)===2||Re===1&&Me.status!==k||Me.lookahead)return m;for(Re===1&&(pe.adler=c(pe.adler,ve,Ye,0)),Me.wrap=0,Ye>=Me.w_size&&(Re===0&&(W(Me.head),Me.strstart=0,Me.block_start=0,Me.insert=0),ke=new a.Buf8(Me.w_size),a.arraySet(ke,ve,Ye-Me.w_size,Me.w_size,0),ve=ke,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,ue(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,ue(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=Re,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,T,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(T=f,(k=0)===_){if(k+=m-Q,Q<w){for(w-=Q;G[g++]=f[k++],--Q;);k=g-D,T=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,T=G}}}else if(k+=_-Q,Q<w){for(w-=Q;G[g++]=f[k++],--Q;);k=g-D,T=G}for(;2<w;)G[g++]=T[k++],G[g++]=T[k++],G[g++]=T[k++],w-=3;w&&(G[g++]=T[k++],1<w&&(G[g++]=T[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 T;return k&&k.state?(T=k.state,k.total_in=k.total_out=T.total=0,k.msg="",T.wrap&&(k.adler=1&T.wrap),T.mode=m,T.last=0,T.havedict=0,T.dmax=32768,T.head=null,T.hold=0,T.bits=0,T.lencode=T.lendyn=new s.Buf32(p),T.distcode=T.distdyn=new s.Buf32(_),T.sane=1,T.back=-1,h):d}function y(k){var T;return k&&k.state?((T=k.state).wsize=0,T.whave=0,T.wnext=0,C(k)):d}function x(k,T){var H,G;return k&&k.state?(G=k.state,T<0?(H=0,T=-T):(H=1+(T>>4),T<48&&(T&=15)),T&&(T<8||15<T)?d:(G.window!==null&&G.wbits!==T&&(G.window=null),G.wrap=H,G.wbits=T,y(k))):d}function E(k,T){var H,G;return k?(G=new I,(k.state=G).window=null,(H=x(k,T))!==h&&(k.state=null),H):d}var B,b,Q=!0;function w(k){if(Q){var T;for(B=new s.Buf32(512),b=new s.Buf32(32),T=0;T<144;)k.lens[T++]=8;for(;T<256;)k.lens[T++]=9;for(;T<280;)k.lens[T++]=7;for(;T<288;)k.lens[T++]=8;for(l(g,k.lens,0,288,B,0,k.work,{bits:9}),T=0;T<32;)k.lens[T++]=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,T,H,G){var U,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,T,H-Y.wsize,Y.wsize,0),Y.wnext=0,Y.whave=Y.wsize):(G<(U=Y.wsize-Y.wnext)&&(U=G),s.arraySet(Y.window,T,H-G,U,Y.wnext),(G-=U)?(s.arraySet(Y.window,T,H-G,G,0),Y.wnext=G,Y.whave=Y.wsize):(Y.wnext+=U,Y.wnext===Y.wsize&&(Y.wnext=0),Y.whave<Y.wsize&&(Y.whave+=U))),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,T){var H,G,U,Y,q,ee,W,J,ie,oe,ne,le,ue,_e,ce,Ie,he,Ce,Pe,Qe,pe,ve,Me,we,Oe=0,Re=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),q=k.next_out,U=k.output,W=k.avail_out,Y=k.next_in,G=k.input,ee=k.avail_in,J=H.hold,ie=H.bits,oe=ee,ne=W,ve=h;e:for(;;)switch(H.mode){case m:if(H.wrap===0){H.mode=13;break}for(;ie<16;){if(ee===0)break e;ee--,J+=G[Y++]<<ie,ie+=8}if(2&H.wrap&&J===35615){Re[H.check=0]=255&J,Re[1]=J>>>8&255,H.check=A(H.check,Re,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(ee===0)break e;ee--,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&&(Re[0]=255&J,Re[1]=J>>>8&255,H.check=A(H.check,Re,2,0)),ie=J=0,H.mode=3;case 3:for(;ie<32;){if(ee===0)break e;ee--,J+=G[Y++]<<ie,ie+=8}H.head&&(H.head.time=J),512&H.flags&&(Re[0]=255&J,Re[1]=J>>>8&255,Re[2]=J>>>16&255,Re[3]=J>>>24&255,H.check=A(H.check,Re,4,0)),ie=J=0,H.mode=4;case 4:for(;ie<16;){if(ee===0)break e;ee--,J+=G[Y++]<<ie,ie+=8}H.head&&(H.head.xflags=255&J,H.head.os=J>>8),512&H.flags&&(Re[0]=255&J,Re[1]=J>>>8&255,H.check=A(H.check,Re,2,0)),ie=J=0,H.mode=5;case 5:if(1024&H.flags){for(;ie<16;){if(ee===0)break e;ee--,J+=G[Y++]<<ie,ie+=8}H.length=J,H.head&&(H.head.extra_len=J),512&H.flags&&(Re[0]=255&J,Re[1]=J>>>8&255,H.check=A(H.check,Re,2,0)),ie=J=0}else H.head&&(H.head.extra=null);H.mode=6;case 6:if(1024&H.flags&&(ee<(le=H.length)&&(le=ee),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)),ee-=le,Y+=le,H.length-=le),H.length))break e;H.length=0,H.mode=7;case 7:if(2048&H.flags){if(ee===0)break e;for(le=0;pe=G[Y+le++],H.head&&pe&&H.length<65536&&(H.head.name+=String.fromCharCode(pe)),pe&&le<ee;);if(512&H.flags&&(H.check=A(H.check,G,le,Y)),ee-=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(ee===0)break e;for(le=0;pe=G[Y+le++],H.head&&pe&&H.length<65536&&(H.head.comment+=String.fromCharCode(pe)),pe&&le<ee;);if(512&H.flags&&(H.check=A(H.check,G,le,Y)),ee-=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(ee===0)break e;ee--,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(ee===0)break e;ee--,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=q,k.avail_out=W,k.next_in=Y,k.avail_in=ee,H.hold=J,H.bits=ie,2;k.adler=H.check=1,H.mode=12;case 12:if(T===5||T===6)break e;case 13:if(H.last){J>>>=7&ie,ie-=7&ie,H.mode=27;break}for(;ie<3;){if(ee===0)break e;ee--,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,T!==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(ee===0)break e;ee--,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,T===6)break e;case 15:H.mode=16;case 16:if(le=H.length){if(ee<le&&(le=ee),W<le&&(le=W),le===0)break e;s.arraySet(U,G,Y,le,q),ee-=le,Y+=le,W-=le,q+=le,H.length-=le;break}H.mode=12;break;case 17:for(;ie<14;){if(ee===0)break e;ee--,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(ee===0)break e;ee--,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,he=65535&Oe,!((ce=Oe>>>24)<=ie);){if(ee===0)break e;ee--,J+=G[Y++]<<ie,ie+=8}if(he<16)J>>>=ce,ie-=ce,H.lens[H.have++]=he;else{if(he===16){for(we=ce+2;ie<we;){if(ee===0)break e;ee--,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(he===17){for(we=ce+3;ie<we;){if(ee===0)break e;ee--,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(ee===0)break e;ee--,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,T===6)break e;case 20:H.mode=21;case 21:if(6<=ee&&258<=W){k.next_out=q,k.avail_out=W,k.next_in=Y,k.avail_in=ee,H.hold=J,H.bits=ie,c(k,ne),q=k.next_out,U=k.output,W=k.avail_out,Y=k.next_in,G=k.input,ee=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,he=65535&Oe,!((ce=Oe>>>24)<=ie);){if(ee===0)break e;ee--,J+=G[Y++]<<ie,ie+=8}if(Ie&&(240&Ie)==0){for(Ce=ce,Pe=Ie,Qe=he;Ie=(Oe=H.lencode[Qe+((J&(1<<Ce+Pe)-1)>>Ce)])>>>16&255,he=65535&Oe,!(Ce+(ce=Oe>>>24)<=ie);){if(ee===0)break e;ee--,J+=G[Y++]<<ie,ie+=8}J>>>=Ce,ie-=Ce,H.back+=Ce}if(J>>>=ce,ie-=ce,H.back+=ce,H.length=he,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(ee===0)break e;ee--,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,he=65535&Oe,!((ce=Oe>>>24)<=ie);){if(ee===0)break e;ee--,J+=G[Y++]<<ie,ie+=8}if((240&Ie)==0){for(Ce=ce,Pe=Ie,Qe=he;Ie=(Oe=H.distcode[Qe+((J&(1<<Ce+Pe)-1)>>Ce)])>>>16&255,he=65535&Oe,!(Ce+(ce=Oe>>>24)<=ie);){if(ee===0)break e;ee--,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=he,H.extra=15&Ie,H.mode=24;case 24:if(H.extra){for(we=H.extra;ie<we;){if(ee===0)break e;ee--,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(W===0)break e;if(le=ne-W,H.offset>le){if((le=H.offset-le)>H.whave&&H.sane){k.msg="invalid distance too far back",H.mode=30;break}ue=le>H.wnext?(le-=H.wnext,H.wsize-le):H.wnext-le,le>H.length&&(le=H.length),_e=H.window}else _e=U,ue=q-H.offset,le=H.length;for(W<le&&(le=W),W-=le,H.length-=le;U[q++]=_e[ue++],--le;);H.length===0&&(H.mode=21);break;case 26:if(W===0)break e;U[q++]=H.length,W--,H.mode=21;break;case 27:if(H.wrap){for(;ie<32;){if(ee===0)break e;ee--,J|=G[Y++]<<ie,ie+=8}if(ne-=W,k.total_out+=ne,H.total+=ne,ne&&(k.adler=H.check=H.flags?A(H.check,U,ne,q-ne):a(H.check,U,ne,q-ne)),ne=W,(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(ee===0)break e;ee--,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=q,k.avail_out=W,k.next_in=Y,k.avail_in=ee,H.hold=J,H.bits=ie,(H.wsize||ne!==k.avail_out&&H.mode<30&&(H.mode<27||T!==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,U,ne,k.next_out-ne):a(H.check,U,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||T===4)&&ve===h&&(ve=-5),ve)},r.inflateEnd=function(k){if(!k||!k.state)return d;var T=k.state;return T.window&&(T.window=null),k.state=null,h},r.inflateGetHeader=function(k,T){var H;return k&&k.state?(2&(H=k.state).wrap)==0?d:((H.head=T).done=!1,h):d},r.inflateSetDictionary=function(k,T){var H,G=T.length;return k&&k.state?(H=k.state).wrap!==0&&H.mode!==11?d:H.mode===11&&a(1,T,G,0)!==H.check?-3:D(k,T,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,T=0,H=0,G=0,U=0,Y=0,q=0,ee=0,W=0,J=0,ie=null,oe=0,ne=new s.Buf16(16),le=new s.Buf16(16),ue=null,_e=0;for(k=0;k<=15;k++)ne[k]=0;for(T=0;T<d;T++)ne[u[h+T]]++;for(U=D,G=15;1<=G&&ne[G]===0;G--);if(G<U&&(U=G),G===0)return m[p++]=20971520,m[p++]=20971520,f.bits=1,0;for(H=1;H<G&&ne[H]===0;H++);for(U<H&&(U=H),k=ee=1;k<=15;k++)if(ee<<=1,(ee-=ne[k])<0)return-1;if(0<ee&&(g===0||G!==1))return-1;for(le[1]=0,k=1;k<15;k++)le[k+1]=le[k]+ne[k];for(T=0;T<d;T++)u[h+T]!==0&&(_[le[u[h+T]]++]=T);if(B=g===0?(ie=ue=_,19):g===1?(ie=a,oe-=257,ue=A,_e-=257,256):(ie=c,ue=l,-1),k=H,E=p,q=T=J=0,y=-1,x=(W=1<<(Y=U))-1,g===1&&852<W||g===2&&592<W)return 1;for(;;){for(b=k-q,w=_[T]<B?(Q=0,_[T]):_[T]>B?(Q=ue[_e+_[T]],ie[oe+_[T]]):(Q=96,0),I=1<<k-q,H=C=1<<Y;m[E+(J>>q)+(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,T++,--ne[k]==0){if(k===G)break;k=u[h+_[T]]}if(U<k&&(J&x)!==y){for(q===0&&(q=U),E+=H,ee=1<<(Y=k-q);Y+q<G&&!((ee-=ne[Y+q])<=0);)Y++,ee<<=1;if(W+=1<<Y,g===1&&852<W||g===2&&592<W)return 1;m[y=J&x]=U<<24|Y<<16|E-p|0}}return J!==0&&(m[E+J]=k-q<<24|64<<16|0),f.bits=U,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 Re=Oe.length;0<=--Re;)Oe[Re]=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 T=new Array(512);c(T);var H=new Array(256);c(H);var G=new Array(g);c(G);var U,Y,q,ee=new Array(d);function W(Oe,Re,Se,Le,ye){this.static_tree=Oe,this.extra_bits=Re,this.extra_base=Se,this.elems=Le,this.max_length=ye,this.has_stree=Oe&&Oe.length}function J(Oe,Re){this.dyn_tree=Oe,this.max_code=0,this.stat_desc=Re}function ie(Oe){return Oe<256?T[Oe]:T[256+(Oe>>>7)]}function oe(Oe,Re){Oe.pending_buf[Oe.pending++]=255&Re,Oe.pending_buf[Oe.pending++]=Re>>>8&255}function ne(Oe,Re,Se){Oe.bi_valid>f-Se?(Oe.bi_buf|=Re<<Oe.bi_valid&65535,oe(Oe,Oe.bi_buf),Oe.bi_buf=Re>>f-Oe.bi_valid,Oe.bi_valid+=Se-f):(Oe.bi_buf|=Re<<Oe.bi_valid&65535,Oe.bi_valid+=Se)}function le(Oe,Re,Se){ne(Oe,Se[2*Re],Se[2*Re+1])}function ue(Oe,Re){for(var Se=0;Se|=1&Oe,Oe>>>=1,Se<<=1,0<--Re;);return Se>>>1}function _e(Oe,Re,Se){var Le,ye,ke=new Array(_+1),Ye=0;for(Le=1;Le<=_;Le++)ke[Le]=Ye=Ye+Se[Le-1]<<1;for(ye=0;ye<=Re;ye++){var $e=Oe[2*ye+1];$e!==0&&(Oe[2*ye]=ue(ke[$e]++,$e))}}function ce(Oe){var Re;for(Re=0;Re<h;Re++)Oe.dyn_ltree[2*Re]=0;for(Re=0;Re<d;Re++)Oe.dyn_dtree[2*Re]=0;for(Re=0;Re<m;Re++)Oe.bl_tree[2*Re]=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 he(Oe,Re,Se,Le){var ye=2*Re,ke=2*Se;return Oe[ye]<Oe[ke]||Oe[ye]===Oe[ke]&&Le[Re]<=Le[Se]}function Ce(Oe,Re,Se){for(var Le=Oe.heap[Se],ye=Se<<1;ye<=Oe.heap_len&&(ye<Oe.heap_len&&he(Re,Oe.heap[ye+1],Oe.heap[ye],Oe.depth)&&ye++,!he(Re,Le,Oe.heap[ye],Oe.depth));)Oe.heap[Se]=Oe.heap[ye],Se=ye,ye<<=1;Oe.heap[Se]=Le}function Pe(Oe,Re,Se){var Le,ye,ke,Ye,$e=0;if(Oe.last_lit!==0)for(;Le=Oe.pending_buf[Oe.d_buf+2*$e]<<8|Oe.pending_buf[Oe.d_buf+2*$e+1],ye=Oe.pending_buf[Oe.l_buf+$e],$e++,Le===0?le(Oe,ye,Re):(le(Oe,(ke=H[ye])+u+1,Re),(Ye=B[ke])!==0&&ne(Oe,ye-=G[ke],Ye),le(Oe,ke=ie(--Le),Se),(Ye=b[ke])!==0&&ne(Oe,Le-=ee[ke],Ye)),$e<Oe.last_lit;);le(Oe,C,Re)}function Qe(Oe,Re){var Se,Le,ye,ke=Re.dyn_tree,Ye=Re.stat_desc.static_tree,$e=Re.stat_desc.has_stree,st=Re.stat_desc.elems,it=-1;for(Oe.heap_len=0,Oe.heap_max=p,Se=0;Se<st;Se++)ke[2*Se]!==0?(Oe.heap[++Oe.heap_len]=it=Se,Oe.depth[Se]=0):ke[2*Se+1]=0;for(;Oe.heap_len<2;)ke[2*(ye=Oe.heap[++Oe.heap_len]=it<2?++it:0)]=1,Oe.depth[ye]=0,Oe.opt_len--,$e&&(Oe.static_len-=Ye[2*ye+1]);for(Re.max_code=it,Se=Oe.heap_len>>1;1<=Se;Se--)Ce(Oe,ke,Se);for(ye=st;Se=Oe.heap[1],Oe.heap[1]=Oe.heap[Oe.heap_len--],Ce(Oe,ke,1),Le=Oe.heap[1],Oe.heap[--Oe.heap_max]=Se,Oe.heap[--Oe.heap_max]=Le,ke[2*ye]=ke[2*Se]+ke[2*Le],Oe.depth[ye]=(Oe.depth[Se]>=Oe.depth[Le]?Oe.depth[Se]:Oe.depth[Le])+1,ke[2*Se+1]=ke[2*Le+1]=ye,Oe.heap[1]=ye++,Ce(Oe,ke,1),2<=Oe.heap_len;);Oe.heap[--Oe.heap_max]=Oe.heap[1],(function(je,ht){var Bt,Ct,Ht,Lt,It,Jt,Cn=ht.dyn_tree,Be=ht.max_code,Ze=ht.stat_desc.static_tree,_t=ht.stat_desc.has_stree,gt=ht.stat_desc.extra_bits,Xe=ht.stat_desc.extra_base,pt=ht.stat_desc.max_length,bt=0;for(Lt=0;Lt<=_;Lt++)je.bl_count[Lt]=0;for(Cn[2*je.heap[je.heap_max]+1]=0,Bt=je.heap_max+1;Bt<p;Bt++)pt<(Lt=Cn[2*Cn[2*(Ct=je.heap[Bt])+1]+1]+1)&&(Lt=pt,bt++),Cn[2*Ct+1]=Lt,Be<Ct||(je.bl_count[Lt]++,It=0,Xe<=Ct&&(It=gt[Ct-Xe]),Jt=Cn[2*Ct],je.opt_len+=Jt*(Lt+It),_t&&(je.static_len+=Jt*(Ze[2*Ct+1]+It)));if(bt!==0){do{for(Lt=pt-1;je.bl_count[Lt]===0;)Lt--;je.bl_count[Lt]--,je.bl_count[Lt+1]+=2,je.bl_count[pt]--,bt-=2}while(0<bt);for(Lt=pt;Lt!==0;Lt--)for(Ct=je.bl_count[Lt];Ct!==0;)Be<(Ht=je.heap[--Bt])||(Cn[2*Ht+1]!==Lt&&(je.opt_len+=(Lt-Cn[2*Ht+1])*Cn[2*Ht],Cn[2*Ht+1]=Lt),Ct--)}})(Oe,Re),_e(ke,it,Oe.bl_count)}function pe(Oe,Re,Se){var Le,ye,ke=-1,Ye=Re[1],$e=0,st=7,it=4;for(Ye===0&&(st=138,it=3),Re[2*(Se+1)+1]=65535,Le=0;Le<=Se;Le++)ye=Ye,Ye=Re[2*(Le+1)+1],++$e<st&&ye===Ye||($e<it?Oe.bl_tree[2*ye]+=$e:ye!==0?(ye!==ke&&Oe.bl_tree[2*ye]++,Oe.bl_tree[2*y]++):$e<=10?Oe.bl_tree[2*x]++:Oe.bl_tree[2*E]++,ke=ye,it=($e=0)===Ye?(st=138,3):ye===Ye?(st=6,3):(st=7,4))}function ve(Oe,Re,Se){var Le,ye,ke=-1,Ye=Re[1],$e=0,st=7,it=4;for(Ye===0&&(st=138,it=3),Le=0;Le<=Se;Le++)if(ye=Ye,Ye=Re[2*(Le+1)+1],!(++$e<st&&ye===Ye)){if($e<it)for(;le(Oe,ye,Oe.bl_tree),--$e!=0;);else ye!==0?(ye!==ke&&(le(Oe,ye,Oe.bl_tree),$e--),le(Oe,y,Oe.bl_tree),ne(Oe,$e-3,2)):$e<=10?(le(Oe,x,Oe.bl_tree),ne(Oe,$e-3,3)):(le(Oe,E,Oe.bl_tree),ne(Oe,$e-11,7));ke=ye,it=($e=0)===Ye?(st=138,3):ye===Ye?(st=6,3):(st=7,4)}}c(ee);var Me=!1;function we(Oe,Re,Se,Le){ne(Oe,(l<<1)+(Le?1:0),3),(function(ye,ke,Ye,$e){Ie(ye),oe(ye,Ye),oe(ye,~Ye),s.arraySet(ye.pending_buf,ye.window,ke,Ye,ye.pending),ye.pending+=Ye})(Oe,Re,Se)}r._tr_init=function(Oe){Me||((function(){var Re,Se,Le,ye,ke,Ye=new Array(_+1);for(ye=Le=0;ye<g-1;ye++)for(G[ye]=Le,Re=0;Re<1<<B[ye];Re++)H[Le++]=ye;for(H[Le-1]=ye,ye=ke=0;ye<16;ye++)for(ee[ye]=ke,Re=0;Re<1<<b[ye];Re++)T[ke++]=ye;for(ke>>=7;ye<d;ye++)for(ee[ye]=ke<<7,Re=0;Re<1<<b[ye]-7;Re++)T[256+ke++]=ye;for(Se=0;Se<=_;Se++)Ye[Se]=0;for(Re=0;Re<=143;)D[2*Re+1]=8,Re++,Ye[8]++;for(;Re<=255;)D[2*Re+1]=9,Re++,Ye[9]++;for(;Re<=279;)D[2*Re+1]=7,Re++,Ye[7]++;for(;Re<=287;)D[2*Re+1]=8,Re++,Ye[8]++;for(_e(D,h+1,Ye),Re=0;Re<d;Re++)k[2*Re+1]=5,k[2*Re]=ue(Re,5);U=new W(D,B,u+1,h,_),Y=new W(k,b,0,d,_),q=new W(new Array(0),Q,0,m,I)})(),Me=!0),Oe.l_desc=new J(Oe.dyn_ltree,U),Oe.d_desc=new J(Oe.dyn_dtree,Y),Oe.bl_desc=new J(Oe.bl_tree,q),Oe.bi_buf=0,Oe.bi_valid=0,ce(Oe)},r._tr_stored_block=we,r._tr_flush_block=function(Oe,Re,Se,Le){var ye,ke,Ye=0;0<Oe.level?(Oe.strm.data_type===2&&(Oe.strm.data_type=(function($e){var st,it=4093624447;for(st=0;st<=31;st++,it>>>=1)if(1&it&&$e.dyn_ltree[2*st]!==0)return a;if($e.dyn_ltree[18]!==0||$e.dyn_ltree[20]!==0||$e.dyn_ltree[26]!==0)return A;for(st=32;st<u;st++)if($e.dyn_ltree[2*st]!==0)return A;return a})(Oe)),Qe(Oe,Oe.l_desc),Qe(Oe,Oe.d_desc),Ye=(function($e){var st;for(pe($e,$e.dyn_ltree,$e.l_desc.max_code),pe($e,$e.dyn_dtree,$e.d_desc.max_code),Qe($e,$e.bl_desc),st=m-1;3<=st&&$e.bl_tree[2*w[st]+1]===0;st--);return $e.opt_len+=3*(st+1)+5+5+4,st})(Oe),ye=Oe.opt_len+3+7>>>3,(ke=Oe.static_len+3+7>>>3)<=ye&&(ye=ke)):ye=ke=Se+5,Se+4<=ye&&Re!==-1?we(Oe,Re,Se,Le):Oe.strategy===4||ke===ye?(ne(Oe,2+(Le?1:0),3),Pe(Oe,D,k)):(ne(Oe,4+(Le?1:0),3),(function($e,st,it,je){var ht;for(ne($e,st-257,5),ne($e,it-1,5),ne($e,je-4,4),ht=0;ht<je;ht++)ne($e,$e.bl_tree[2*w[ht]+1],3);ve($e,$e.dyn_ltree,st-1),ve($e,$e.dyn_dtree,it-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,Re,Se){return Oe.pending_buf[Oe.d_buf+2*Oe.last_lit]=Re>>>8&255,Oe.pending_buf[Oe.d_buf+2*Oe.last_lit+1]=255&Re,Oe.pending_buf[Oe.l_buf+Oe.last_lit]=255&Se,Oe.last_lit++,Re===0?Oe.dyn_ltree[2*Se]++:(Oe.matches++,Re--,Oe.dyn_ltree[2*(H[Se]+u+1)]++,Oe.dyn_dtree[2*ie(Re)]++),Oe.last_lit===Oe.lit_bufsize-1},r._tr_align=function(Oe){ne(Oe,2,3),le(Oe,C,D),(function(Re){Re.bi_valid===16?(oe(Re,Re.bi_buf),Re.bi_buf=0,Re.bi_valid=0):8<=Re.bi_valid&&(Re.pending_buf[Re.pending++]=255&Re.bi_buf,Re.bi_buf>>=8,Re.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 Wy<"u"?Wy:typeof self<"u"?self:typeof window<"u"?window:{})},{}]},{},[10])(10)})})(kJe)),kJe.exports}var F6i=k6i();const Gme=jy(F6i),L6i=async({circuitJson:t,projectName:e})=>{await ia.promise((async()=>{const n=new Gme,[o,{convertCircuitJsonToBomRows:i,convertBomRowsToCsv:r},{convertCircuitJsonToPickAndPlaceCsv:s}]=await Promise.all([lB("circuit-json-to-gerber"),lB("circuit-json-to-bom-csv"),lB("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"});pB(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)}`})},H6i=async t=>{const{createFdmComponentBox:e,renderFdmComponentBoxPng:n}=await lB("circuit-json-to-fdm-component-box"),[o,i]=await Promise.all([e(t),n(t,{},{width:960,height:640})]);return{...o,previewPng:i}},O6i=async t=>{const{createFdmComponentBox:e}=await lB("circuit-json-to-fdm-component-box");return e(t)},Sln=({generatedBox:t,projectName:e})=>{const n=Uint8Array.from(t.threeMf);pB(new Blob([n.buffer],{type:"model/3mf"}),{fileName:`${aJe(e)}-component-box.3mf`})},G6i=async({circuitJson:t,projectName:e})=>{await ia.promise((async()=>{const n=await O6i(t);Sln({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)}`})},Y6i=async({circuitJson:t,projectName:e})=>{let n;try{const{convertCircuitJsonToGltf:o}=await lB("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}pB(n,{fileName:`${e}.glb`})},U6i=async({circuitJson:t,libraryName:e})=>{const{CircuitJsonToKicadLibraryConverter:n}=await lB("circuit-json-to-kicad"),o=new n(t,{libraryName:e,footprintLibraryName:e});o.runUntilFinished();const i=o.getOutput(),r=new Gme;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}
|
|
5744
5744
|
`)}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},K6i=async({circuitJson:t,projectName:e})=>{await ia.promise((async()=>{const o=await(await U6i({circuitJson:t,libraryName:e})).generateAsync({type:"blob"});pB(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)}`})},V6i=async({circuitJson:t,projectName:e})=>{const{CircuitJsonToKicadPcbConverter:n,CircuitJsonToKicadSchConverter:o,CircuitJsonToKicadProConverter:i,resolveAndLoadKicad3dModelFiles:r}=await lB("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 Gme;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},z6i=async({circuitJson:t,projectName:e})=>{await ia.promise((async()=>{const o=await(await V6i({circuitJson:t,projectName:e})).generateAsync({type:"blob"});pB(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)}`})},bln=async({circuitJson:t,projectName:e,options:n={}})=>{try{const{convertCircuitJsonToLbrn:o}=await lB("circuit-json-to-lbrn"),r=(await o(t,{includeSilkscreen:n.includeSilkscreen??!1,includeOxidationCleaningLayer:n.includeOxidationCleaningLayer??!0})).toXml(),s=new Blob([r],{type:"application/lbrn"});pB(s,{fileName:`${e}.lbrn2`})}catch(o){const i=o instanceof Error?o.message:"Unknown error";ia.error(`Failed to export to LBRN format: ${i}`)}},J6i=async({circuitJson:t,projectName:e})=>{const{convertCircuitJsonToPinoutSvg:n}=await lB("circuit-to-svg"),o=n(t);pB(o,{fileName:`${e}-pinout.svg`,mimeType:"image/svg+xml"})},W6i=async({circuitJson:t,projectName:e})=>{const{circuitJsonToStep:n}=await lB("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){ia.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";ia.error(`Failed to convert circuit to STEP format: ${l}`);return}const A=new Blob([a],{type:"application/step"});try{pB(A,{fileName:`${e}.step`})}catch(c){const l=c instanceof Error?c.message:"Unknown error";ia.error(`Failed to download STEP file: ${l}`)}},j6i=[{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"}],q6i=async({exportName:t,circuitJson:e,simpleRouteJson:n,projectName:o})=>{const i=aJe(o);if(t==="Fabrication Files"){await L6i({circuitJson:e,projectName:i});return}if(t==="KiCad Project"){await z6i({circuitJson:e,projectName:i});return}if(t==="Altium Project"){await T6i({circuitJson:e,projectName:i});return}if(t==="KiCad Library"){await K6i({circuitJson:e,projectName:i});return}if(t==="Circuit JSON"){pB(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");pB(JSON.stringify(n,null,2),{fileName:`${i}.simple-route.json`,mimeType:"application/json"});return}if(t==="GLB (Binary GLTF)"){await Y6i({circuitJson:e,projectName:i});return}if(t==="Pinout SVG"){J6i({circuitJson:e,projectName:i});return}if(t==="STEP"){await W6i({circuitJson:e,projectName:i});return}if(t==="Component Box (3MF)"){await G6i({circuitJson:e,projectName:i});return}if(t==="LightBurn"){await bln({circuitJson:e,projectName:i});return}throw new Error(`Unsupported export type: "${t}"`)},X6i=({packageName:t,onSelectReview:e})=>{const n=nh(g=>g.fsMap),o=nh(g=>g.circuitJson),[i,r]=te.useState([]),[s,a]=te.useState(!1),[A,c]=te.useState(!1);te.useEffect(()=>{!t||!Uge()||(a(!0),Rj.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),ia.error("Failed to load AI reviews")}).finally(()=>a(!1)))},[t]);const l=async()=>{if(!o){ia.error("Need Circuit JSON to Request AI Review");return}if(!Uge()){ia.error("Missing registry token");return}c(!0);try{const{ai_review:g}=await Rj.post("ai_reviews/create",{json:{package_name:t??"unknown",fs_map:Object.fromEntries(n),circuit_json:o}}).json();r(u=>[g,...u]),e(g),ia.success("AI review requested")}catch(g){console.error("Failed to create AI review",g),ia.error("Failed to request AI review")}finally{c(!1)}};return K.jsxs(K.Fragment,{children:[K.jsxs(e7,{children:[K.jsx(t7,{children:"AI Review"}),K.jsx(YR,{children:"Select an AI review or request a new one."})]}),K.jsx("div",{className:"rf-flex rf-gap-4 rf-mt-4",children:K.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?K.jsx("div",{className:"rf-text-sm",children:"Loading..."}):i.length>0?i.map(g=>K.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)):K.jsx("div",{className:"rf-text-sm rf-text-muted-foreground",children:"No AI reviews found."})})}),K.jsx(QY,{className:"rf-mt-4",children:K.jsx(gA,{onClick:l,disabled:A,children:A?"Requesting...":"Review my Board"})})]})};function FJe(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var UR=FJe();function Qln(t){UR=t}var b$={exec:()=>null};function yg(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(Y1.caret,"$1"),n=n.replace(i,s),o},getRegex:()=>new RegExp(n,e)};return o}var Y1={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")},$6i=/^(?:[ \t]*(?:\n|$))+/,Z6i=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,e8i=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,Q$=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,t8i=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,LJe=/(?:[*+-]|\d{1,9}[.)])/,vln=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,Pln=yg(vln).replace(/bull/g,LJe).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(),n8i=yg(vln).replace(/bull/g,LJe).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(),HJe=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,o8i=/^[^\n]+/,OJe=/(?!\s*\])(?:\\.|[^\[\]\\])+/,i8i=yg(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",OJe).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),r8i=yg(/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,LJe).getRegex(),Yme="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",GJe=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,s8i=yg("^ {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",GJe).replace("tag",Yme).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),wln=yg(HJe).replace("hr",Q$).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",Yme).getRegex(),a8i=yg(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",wln).getRegex(),YJe={blockquote:a8i,code:Z6i,def:i8i,fences:e8i,heading:t8i,hr:Q$,html:s8i,lheading:Pln,list:r8i,newline:$6i,paragraph:wln,table:b$,text:o8i},Mln=yg("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",Q$).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",Yme).getRegex(),A8i={...YJe,lheading:n8i,table:Mln,paragraph:yg(HJe).replace("hr",Q$).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",Mln).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",Yme).getRegex()},c8i={...YJe,html:yg(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",GJe).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:b$,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:yg(HJe).replace("hr",Q$).replace("heading",` *#{1,6} *[^
|
|
5745
5745
|
]`).replace("lheading",Pln).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},l8i=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,g8i=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,Dln=/^( {2,}|\\)\n(?!\s*$)/,u8i=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,Ume=/[\p{P}\p{S}]/u,UJe=/[\s\p{P}\p{S}]/u,Nln=/[^\s\p{P}\p{S}]/u,d8i=yg(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,UJe).getRegex(),Rln=/(?!~)[\p{P}\p{S}]/u,h8i=/(?!~)[\s\p{P}\p{S}]/u,m8i=/(?:[^\s\p{P}\p{S}]|~)/u,p8i=/\[[^[\]]*?\]\((?:\\.|[^\\\(\)]|\((?:\\.|[^\\\(\)])*\))*\)|`[^`]*?`|<[^<>]*?>/g,Tln=/^(?:\*+(?:((?!\*)punct)|[^\s*]))|^_+(?:((?!_)punct)|([^\s_]))/,_8i=yg(Tln,"u").replace(/punct/g,Ume).getRegex(),f8i=yg(Tln,"u").replace(/punct/g,Rln).getRegex(),kln="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",I8i=yg(kln,"gu").replace(/notPunctSpace/g,Nln).replace(/punctSpace/g,UJe).replace(/punct/g,Ume).getRegex(),C8i=yg(kln,"gu").replace(/notPunctSpace/g,m8i).replace(/punctSpace/g,h8i).replace(/punct/g,Rln).getRegex(),y8i=yg("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,Nln).replace(/punctSpace/g,UJe).replace(/punct/g,Ume).getRegex(),x8i=yg(/\\(punct)/,"gu").replace(/punct/g,Ume).getRegex(),E8i=yg(/^<(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(),B8i=yg(GJe).replace("(?:-->|$)","-->").getRegex(),S8i=yg("^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",B8i).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),Kme=/(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/,b8i=yg(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]*(?:\n[ \t]*)?)(title))?\s*\)/).replace("label",Kme).replace("href",/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),Fln=yg(/^!?\[(label)\]\[(ref)\]/).replace("label",Kme).replace("ref",OJe).getRegex(),Lln=yg(/^!?\[(ref)\](?:\[\])?/).replace("ref",OJe).getRegex(),Q8i=yg("reflink|nolink(?!\\()","g").replace("reflink",Fln).replace("nolink",Lln).getRegex(),KJe={_backpedal:b$,anyPunctuation:x8i,autolink:E8i,blockSkip:p8i,br:Dln,code:g8i,del:b$,emStrongLDelim:_8i,emStrongRDelimAst:I8i,emStrongRDelimUnd:y8i,escape:l8i,link:b8i,nolink:Lln,punctuation:d8i,reflink:Fln,reflinkSearch:Q8i,tag:S8i,text:u8i,url:b$},v8i={...KJe,link:yg(/^!?\[(label)\]\((.*?)\)/).replace("label",Kme).getRegex(),reflink:yg(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",Kme).getRegex()},VJe={...KJe,emStrongRDelimAst:C8i,emStrongLDelim:f8i,url:yg(/^((?: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.!#$%&'*+\/=?_`{\|}~-]+@)))/},P8i={...VJe,br:yg(Dln).replace("{2,}","*").getRegex(),text:yg(VJe.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},Vme={normal:YJe,gfm:A8i,pedantic:c8i},v$={normal:KJe,gfm:VJe,breaks:P8i,pedantic:v8i},w8i={"&":"&","<":"<",">":">",'"':""","'":"'"},Hln=t=>w8i[t];function yP(t,e){if(e){if(Y1.escapeTest.test(t))return t.replace(Y1.escapeReplace,Hln)}else if(Y1.escapeTestNoEncode.test(t))return t.replace(Y1.escapeReplaceNoEncode,Hln);return t}function Oln(t){try{t=encodeURI(t).replace(Y1.percentDecode,"%")}catch{return null}return t}function Gln(t,e){const n=t.replace(Y1.findPipe,(r,s,a)=>{let A=!1,c=s;for(;--c>=0&&a[c]==="\\";)A=!A;return A?"|":" |"}),o=n.split(Y1.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(Y1.slashPipe,"|");return o}function P$(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 M8i(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 Yln(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 D8i(t,e,n){const o=t.match(n.other.indentCodeCompensation);if(o===null)return e;const i=o[1];return e.split(`
|