copperflow 0.3.2 → 0.3.3

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.
@@ -10,7 +10,7 @@ Error generating stack: `+e.message+`
10
10
 
11
11
  `);e>=0;e=a.indexOf(`
12
12
 
13
- `))r(a.slice(0,e)),a=a.slice(e+2)}}catch(e){if(n.signal.aborted)return;e instanceof TypeError&&t?.(!1)}await new Promise(e=>setTimeout(e,ae))}})(),()=>n.abort()}var ue=.5,de=2e3;function fe(e,t,n){return{x:(n.x-e.cx)*e.scale+t.width/2,y:-(n.y-e.cy)*e.scale+t.height/2}}function pe(e,t,n){return{x:(n.x-t.width/2)/e.scale+e.cx,y:-(n.y-t.height/2)/e.scale+e.cy}}function me(e,t,n=.12){let r=Math.max(e.maxX-e.minX,1),i=Math.max(e.maxY-e.minY,1),a=Math.min(t.width/r,t.height/i)*(1-2*n);return{cx:(e.minX+e.maxX)/2,cy:(e.minY+e.maxY)/2,scale:we(a)}}function he(e,t){return{...e,cx:t.x,cy:t.y}}function ge(e,t,n,r){let i=pe(e,t,n),a=we(e.scale*r);return{scale:a,cx:i.x-(n.x-t.width/2)/a,cy:i.y+(n.y-t.height/2)/a}}var z=e=>Math.round(e*1e4)/1e4;function _e(e,t){let n=Math.max(0,-Math.floor(Math.log10(t))+2);return Number((Math.round(e/t)*t).toFixed(n))}var ve=(e,t,n=!0)=>z(n?_e(e,t):e),ye=(e,t,n=!0)=>({x:ve(e.x,t,n),y:ve(e.y,t,n)});function be(e,t){let n=e=>(e.maxX-e.minX)*(e.maxY-e.minY);return e.filter(({box:e})=>t.x>=e.minX&&t.x<=e.maxX&&t.y>=e.minY&&t.y<=e.maxY).sort((e,t)=>n(e.box)-n(t.box))}function xe(e){if(e.length===0)return;let t=e.map(e=>e.x),n=e.map(e=>e.y);return{minX:Math.min(...t),minY:Math.min(...n),maxX:Math.max(...t),maxY:Math.max(...n)}}function Se(e){return xe(e.flatMap(e=>[{x:e.minX,y:e.minY},{x:e.maxX,y:e.maxY}]))}function Ce(e){let t=[];for(let n of e){let e=t[t.length-1];e&&e.x!==n.x&&e.y!==n.y&&t.push({x:n.x,y:e.y}),e&&e.x===n.x&&e.y===n.y||t.push(n)}return t}function we(e){return Math.min(de,Math.max(ue,e))}var Te={pcb:{position:[`pcbX`,`pcbY`],rotation:`pcbRotation`,where:``,notePrompt:`Note for the agent, e.g. route ground here`},schematic:{position:[`schX`,`schY`],rotation:`schRotation`,where:` in the schematic`,notePrompt:`Note for the agent, e.g. add a pull-up here`}},Ee={x:0,y:0};function De(e,t){let n=new Map(e.circuit.components.map(e=>[e.id,t===`pcb`?e.groupOffset.pcb:e.groupOffset.sch])),r=t===`pcb`?e.pcb.parts:e.schematic.symbols;return new Map(r.map(e=>[e.component,{origin:{x:e.x,y:e.y},group:n.get(e.component)??Ee,autoPlaced:e.autoPlaced}]))}function Oe(e,t,n,r){let i=e.model.parts.find(e=>e.name===n);if(!i)return`This part has no editable source element`;if(t.has(n))return`${n} is locked`;if(!i.editable)return`${n} is read-only (${i.readonlyReason})`;let a=Te[r].position.find(e=>i.props[e]&&!i.props[e]?.editable);return a?`${n}.${a} is an expression; change it in the code`:null}function ke(e,t,n,r=90){let i=Te[n].rotation,a=e.model.parts.find(e=>e.name===t)?.props[i]?.literal;return a!==void 0&&typeof a!=`number`?`${t}.${i} is not a number`:(((a??0)+r)%360+360)%360}function Ae(e,t,n,r){let i=e.model.parts.find(e=>e.name===t)?.props,[a,o]=Te[n].position,s=(e,t,n)=>{let r=i?.[e]?.literal;return typeof r==`number`?r:t-n};return{x:s(a,r.origin.x,r.group.x),y:s(o,r.origin.y,r.group.y)}}function je(e,t,n,r,i){let a=Ae(e,t,n,r);return[z(a.x+i.x),z(a.y+i.y)]}var Me=`Keep auto-placed positions`,Ne=`a repeated name cannot be addressed from the Studio`,Pe=e=>Math.round(e*100)/100;function Fe(e,t){let n=t===`pcb`?e.pcb.parts:e.schematic.symbols;return new Map(n.map(e=>[e.component,e.rotation]))}var Ie=(e,t,n)=>e?.model.parts.find(e=>e.name===t)?.props[Te[n].rotation]!==void 0;function Le(e,t,n=()=>null,r){let[i,a]=Te[t].position,o=Fe(e,t),s=[],c=[];for(let[l,{origin:u,group:d,autoPlaced:f}]of De(e,t)){if(!f)continue;let e=l.includes(`~`)?Ne:n(l);if(e!==null){c.push({part:l,reason:e});continue}let p=o.get(l)??0,m={[i]:Pe(u.x-d.x),[a]:Pe(u.y-d.y),...p!==0||Ie(r,l,t)?{[Te[t].rotation]:p}:{}};s.push({kind:`setProps`,part:l,props:m})}return{edits:s,skipped:c}}function Re(e,t){return t.skipped.length===0?e:`${e} Skipped ${t.skipped.map(e=>`${e.part} (${e.reason})`).join(`, `)}.`}function ze(e){let t=e.edits.length;return Re(t===0?`No auto-placed part could be kept.`:`Kept the positions of ${t} auto-placed ${t===1?`part`:`parts`}.`,e)}function Be(e,t,n,r){if(e.edits.length===0)return r.notify(n(e));r.edit(e.edits,t).then(t=>{t&&r.notify(n(e))})}function Ve(e,t,n,r,i){Be(Le(e,t,n,i),Me,ze,r)}var He=`Tidy sheet`,Ue=`Every part on the sheet has a position of its own`,We=`The schematic is not built yet`;function Ge(e,t){if(!e)return new Set;let n=t===`pcb`?e.pcb.parts:e.schematic.symbols;return new Set(n.flatMap(e=>e.autoPlaced?[e.component]:[]))}function Ke(e){return e?Ge(e,`schematic`).size>0?null:Ue:We}var qe=(e,t=()=>null,n)=>Le(e,`schematic`,t,n);function Je(e){let t=e.edits.length;return Re(t===0?`Tidied the sheet: no part Studio placed could be written.`:`Tidied the sheet: wrote the positions of ${t} ${t===1?`part`:`parts`} Studio placed.`,e)}function Ye(e,t,n,r){let i=Ke(e);if(i!==null)return n.notify(i);Be(qe(e,t,r),He,Je,n)}var Xe=/\.sheet\.tsx$/,Ze=e=>e!==void 0&&Xe.test(e),Qe=e=>(e.split(`/`).pop()??e).replace(Xe,``),$e=3;function et(e){return e.length<=1?e[0]??``:e.length>$e?`${e.slice(0,$e).join(`, `)} and ${e.length-$e} more`:`${e.slice(0,-1).join(`, `)} and ${e.at(-1)}`}var tt=e=>e.length>1?[`${e.length} wires`]:[...e],nt=e=>`by ${e}°`;function rt(e,t,n,r,i=90){let{rotation:a,where:o}=Te[n],s=[],c=[];for(let a of t){let t=r(a)??ke(e,a,n,i);typeof t==`string`?c.push(t):s.push({name:a,to:t})}let l=s.map(e=>e.name),[u]=s,d=s.length===1&&u?`rotate ${u.name}${o} to ${u.to}°`:`rotate ${et(l)}${o} ${nt(i)}`;return{edits:s.map(e=>({kind:`setProps`,part:e.name,props:{[a]:e.to}})),summary:d,parts:l,skipped:c,done:`rotated`}}function it(e,t,n,r,i,a){let[o,s]=Te[n].position,{where:c}=Te[n],l=t.flatMap(e=>a(e)??[]),u=t.filter(e=>a(e)===null),d=u.map(t=>({name:t,to:je(e,t,n,r(t),i)})),[f]=d,p=d.length===1&&f?`move ${f.name}${c} to (${f.to[0]}, ${f.to[1]})`:`move ${et(u)}${c} by (${z(i.x)}, ${z(i.y)})`;return{edits:d.map(({name:e,to:t})=>({kind:`setProps`,part:e,props:{[o]:t[0],[s]:t[1]}})),summary:p,parts:u,skipped:l,done:`moved`}}function at(e,t){return n=>e.get(n)??{origin:t.find(e=>e.name===n)?.center??Ee,group:Ee}}function ot(e,t,n,r=!0){let i=r?t:t/10;return{x:z(e.dx*i*n),y:z(e.dy*i*n)}}function st(e,t){let n=Se(e);return n?{x:_e((n.minX+n.maxX)/2,t),y:_e((n.minY+n.maxY)/2,t)}:void 0}function ct(e,t,n=90){let r=n>0?1:-1;return{x:t.x-r*(e.y-t.y),y:t.y+r*(e.x-t.x)}}function lt(e,t,n,r,i,a,o=()=>!0,s=90){if(t.length===1)return rt(e,t,n,a,s);let{rotation:c,position:l,where:u}=Te[n],d=[],f=[],p=[];for(let u of t){if(!o(u)){p.push(`${u} is not in this view`);continue}let t=a(u)??ke(e,u,n,s);if(typeof t==`string`){p.push(t);continue}let m=r(u),h=m.origin,g=ct(h,i,s),[_,v]=je(e,u,n,m,{x:g.x-h.x,y:g.y-h.y});d.push({kind:`setProps`,part:u,props:{[l[0]]:_,[l[1]]:v,[c]:t}}),f.push(u)}return{edits:d,summary:`rotate ${et(f)}${u} ${nt(s)}`,parts:f,skipped:p,done:`rotated`}}function ut(e){let t=new Set(e.boxes.map(e=>e.name));return n=>t.has(n)||e.anchors.has(n)}function dt(e,t,n,r,i,a=90){if(t.length===1)return rt(e,t,n,i,a);let o=st(r.boxes.filter(e=>t.includes(e.name)).map(e=>e.box),r.step);return o?lt(e,t,n,at(r.anchors,r.boxes),o,i,ut(r),a):{message:`None of the selected parts is in this view.`}}function ft(e,t,n,r,i,a){let o=ut(r),s=t.filter(e=>!o(e)).map(e=>`${e} is not in this view`),c=it(e,t.filter(o),n,at(r.anchors,r.boxes),i,a);return{...c,skipped:[...s,...c.skipped]}}function pt(e,t){let n=e.flatMap(e=>t(e)??[]),r=e.filter(e=>t(e)===null);return{edits:r.map(e=>({kind:`removePart`,part:e})),summary:`remove ${et(r)}`,parts:r,skipped:n,done:`removed`}}function mt(e,t=0){let n=e.length===1?`${e[0]} and its connections`:`${e.length} parts (${et(e)}) and their connections`;return t===0?`Remove ${n}?`:`Remove ${n}, and ${t} ${t===1?`wire`:`wires`}?`}function ht(e){if(e.skipped.length===0)return;let t=e.skipped.join(`; `);return e.edits.length===0?t:`Not ${e.done}: ${t}`}function gt(e,t,n,r=new Set){if(e.length===0)return{message:`Select a part first.`};let i=e.filter(e=>n?!t.has(e)||r.has(e):t.has(e));if(i.length>0)return{parts:i};let a=e.length===1?`is`:`are`;return{message:`${et(e)} ${a} ${n?`already locked`:`not locked`}.`}}async function _t(e,t){return(await vt(e,t)).ok}async function vt(e,t){let n=ht(e);if(e.edits.length===0)return n&&t.notify(n),{ok:!1};let r=t.editMarked?await t.editMarked(e.edits,e.summary):{ok:await t.edit(e.edits,e.summary)};return r.ok&&n&&t.notify(n),r}var yt={reference:.16,value:.16,"pin-name":.12,"pin-number":.1},bt=.6,xt=e=>Math.round(e*1e6)/1e6,St=(e,t)=>({x:xt(e),y:xt(t)}),Ct=(...e)=>({type:`polyline`,points:e.map(([e,t])=>St(e,t))});function wt(e,t,n,r){return{type:`text`,text:e,at:t,anchor:n,size:yt[r],role:r}}function Tt(e){let t=bt*e.size*e.text.length,n=e.anchor===`left`?e.at.x:e.anchor===`right`?e.at.x-t:e.at.x-t/2;return{minX:n,maxX:n+t,minY:e.at.y-e.size/2,maxY:e.at.y+e.size/2}}function Et(e){if(e.type===`text`)return Tt(e);if(e.type===`polyline`){let t=e.points.map(e=>e.x),n=e.points.map(e=>e.y);return{minX:Math.min(...t),maxX:Math.max(...t),minY:Math.min(...n),maxY:Math.max(...n)}}let{center:t,radius:n}=e;return{minX:t.x-n,maxX:t.x+n,minY:t.y-n,maxY:t.y+n}}function Dt(e,t){let n=[...e.map(Et),...t.map(e=>({minX:e.end.x,maxX:e.end.x,minY:e.end.y,maxY:e.end.y}))];return n.length===0?{minX:0,minY:0,maxX:0,maxY:0}:{minX:xt(Math.min(...n.map(e=>e.minX))),minY:xt(Math.min(...n.map(e=>e.minY))),maxX:xt(Math.max(...n.map(e=>e.maxX))),maxY:xt(Math.max(...n.map(e=>e.maxY)))}}var Ot=(e,t,n)=>({end:St(e,t),side:n});Ot(-.5,0,`left`),Ot(.5,0,`right`),Ot(-.5,0,`left`),Ot(.5,0,`right`),Ot(-.5,0,`left`),Ot(.3,-.5,`bottom`),Ot(.3,.5,`top`);function kt(){return[Ct([0,0],[0,-.1]),Ct([-.15,-.1],[.15,-.1]),Ct([-.1,-.15],[.1,-.15]),Ct([-.05,-.2],[.05,-.2])]}function At(e){return[Ct([0,0],[0,.1]),Ct([-.1,.1],[.1,.1]),wt(e,St(0,.2),`center`,`value`)]}var jt=.16,Mt=jt*1.5,Nt=.66,Pt={right:{x:1,y:0},left:{x:-1,y:0},top:{x:0,y:1},bottom:{x:0,y:-1}};function Ft(e){let t=Pt[e.side],n=e.text.length*jt*Nt+Mt,r=t.x===0,i={x:e.at.x+t.x*n/2,y:e.at.y+t.y*n/2},[a,o]=r?[Mt,n]:[n,Mt];return{middle:i,upright:r,box:{minX:i.x-a/2,minY:i.y-o/2,maxX:i.x+a/2,maxY:i.y+o/2}}}var It=/[\w-]+/,Lt=new RegExp(String.raw`^net\.(${It.source})$`),Rt=/^([A-Za-z_][\w-]*)\.([\w-]+)$/,zt=/^\.([A-Za-z_][\w-]*)\s*>\s*\.([\w-]+)$/;function Bt(e){let t=e.trim(),n=Lt.exec(t);if(n?.[1])return{kind:`net`,name:n[1]};let r=zt.exec(t)??Rt.exec(t);return r?.[1]&&r[2]?{kind:`pin`,part:r[1],pin:r[2]}:void 0}var Vt=/^net\.((?:[\w-]+(?:~\d+)?\/)+)([\w-]+)$/;function Ht(e){let t=Vt.exec(e.trim());return t?.[1]&&t[2]?{instance:t[1].slice(0,-1),net:t[2]}:void 0}function Ut(e,t){return`${e.instance}/${e.net} is local to instance ${e.instance}; edit ${t??`its sheet file`} and use ${e.net} there`}var Wt={schematicpath:`path`,schematicrect:`rect`,schematiccircle:`circle`,schematicarc:`arc`,schematictext:`text`,bus:`bus`,junction:`junction`},Gt=.04,Kt=[`solid`,`dashed`,`dotted`],qt=[`left`,`center`,`right`];function Jt(e){return Object.hasOwn(Wt,e)?Wt[e]:void 0}var Yt=new RegExp(String.raw`^${It.source}$`),Xt=new RegExp(String.raw`^(${It.source})\[(\d+):(\d+)\]$`);function Zt(e){if(Yt.test(e))return[e];let t=Xt.exec(e);if(!t)return;let[n,r,i]=[t[1],Number(t[2]),Number(t[3])],a=Math.abs(i-r)+1;if(a>1024)return;let o=i>=r?1:-1;return Array.from({length:a},(e,t)=>`${n}${r+t*o}`)}function Qt(e){let t=e.map(e=>e.x),n=e.map(e=>e.y);return{minX:Math.min(...t),minY:Math.min(...n),maxX:Math.max(...t),maxY:Math.max(...n)}}function $t(e,t){let n=t-e;return Math.abs(n)>=360?360:(n%360+360)%360}function en(e,t,n,r,i){let a=$t(r,i),o=[r,r+a];for(let e=Math.ceil(r/90)*90;e<r+a;e+=90)o.push(e);return Qt(o.map(r=>({x:e+n*Math.cos(r*Math.PI/180),y:t+n*Math.sin(r*Math.PI/180)})))}function tn(e,t,n,r,i){let a=bt*r*n.length,o=i===`left`?e:i===`right`?e-a:e-a/2;return{minX:o,minY:t-r/2,maxX:o+a,maxY:t+r/2}}function nn(e){switch(e.kind){case`path`:case`bus`:return Qt(e.points);case`rect`:return{minX:e.x,minY:e.y,maxX:e.x+e.width,maxY:e.y+e.height};case`circle`:return{minX:e.x-e.radius,minY:e.y-e.radius,maxX:e.x+e.radius,maxY:e.y+e.radius};case`arc`:return en(e.x,e.y,e.radius,e.startAngle,e.endAngle);case`text`:return tn(e.x,e.y,e.text,e.fontSize,e.anchor);case`junction`:return{minX:e.x-Gt,minY:e.y-Gt,maxX:e.x+Gt,maxY:e.y+Gt}}}var rn=e=>xt(e)+0;function an(e){let t=nn(e);return{minX:rn(t.minX),minY:rn(t.minY),maxX:rn(t.maxX),maxY:rn(t.maxY)}}var on=/^[A-Za-z_][\w-]*$/;function sn(e,t,n,r){let i=Ht(n);if(i)return Ut(i,void 0);let a=n.replace(/^net\./,``);return r?Zt(a)===void 0?`${e} port ${t} is a bus port and takes a bus name such as "D[0:7]", not "${n}"`:void 0:on.test(a)?void 0:`${e} port ${t} is a net port and takes a net name such as "VBUS", not "${n}"`}function cn(e,t){let n=new Set(e);for(let r of t??[]){let t=r.path.split(`/`)[0]??r.path;if(e.has(r.path)||e.has(t))for(let e of r.parts)n.add(e)}return n}var ln=e=>e?.circuit.instances??[];function un(e,t){return ln(e).find(e=>e.path===t&&!e.path.includes(`/`))}function dn(e,t){let n=e?.circuit.components.find(e=>e.id===t);if(n?.instance===void 0)return;let r=ln(e).find(e=>e.path===n.instance);if(!r)return;let i=n.instance.split(`/`)[0]??n.instance;return{part:t,localId:n.localId??t,instance:r.path,outer:i,sheet:r.sheet,file:r.file}}function fn(e,t){return[...ln(e).find(e=>e.path===t)?.parts??[]]}function pn(e,t){return ln(e).filter(e=>e.file===t).length}function mn(e,t){return t===void 0?`In ${e}; every instance of it changes with it`:`In ${e}, used ${t===1?`once`:`${t} times`}`}function hn(e,t){let n=t.flatMap(t=>{let n=un(e,t);if(n)return[n.path];let r=dn(e,t);return r?[r.outer]:[]});if(n.length!==0)return[...new Set(n)].flatMap(t=>fn(e,t))}function gn(e,t,n){let r=Object.fromEntries(Object.entries(e.connections).filter(([e])=>e!==t));return n===``?r:{...e.connections,[t]:n}}function _n(e,t){return cn(e,t?.circuit.instances)}function vn(e,t,n){let r=dn(e,n);if(r)return t.has(r.outer)?`${n} is in ${r.outer}, which is locked`:`${n} is ${r.localId} of ${r.instance}; it is placed in ${r.file}, where every instance of ${Qe(r.file)} shares it`}var yn=e=>Math.round(e*1e4)/1e4||0,bn=(e,t)=>e.x===t.x&&e.y===t.y;function xn(e,t,n){return e.x===t.x||e.y===t.y?[t]:[n?{x:e.x,y:t.y}:{x:t.x,y:e.y},t]}function Sn(e,t=[]){let n=e[0];if(!n)return[];let r=[n];for(let n=1;n<e.length;n++)r.push(...xn(e[n-1],e[n],t[n-1]===!0));return r}function Cn(e){let t=e.map(e=>({x:yn(e.x),y:yn(e.y)})),n=[];for(let e of t){let t=n[n.length-1];t&&bn(t,e)||n.push(e)}return n.filter((e,t)=>{let[r,i]=[n[t-1],n[t+1]];return!r||!i||!(r.x===e.x&&e.x===i.x||r.y===e.y&&e.y===i.y)})}function wn(e,t=[]){return Cn(Sn(e,t))}var Tn=.2,En=/^[\w-]+$/,Dn=/^[A-Za-z_][\w-]*$/,On=/^([A-Za-z_][\w-]*)\.([\w-]+)$/,kn=/^\.([A-Za-z_][\w-]*)\s*>\s*\.([\w-]+)$/;function An(e,t){let n=e.pinLabels;if(typeof n==`object`&&n)for(let[e,r]of Object.entries(n)){if(!RegExp(`^(?:pin)?${t}$`).test(e))continue;let n=(Array.isArray(r)?r:[r]).find(e=>typeof e==`string`&&e!==``);if(n!==void 0)return n}}function jn(e,t){let n=e.circuit.components.find(e=>e.id===t.component),r=An(n?.props??{},t.number),i=(n?.pins??[]).filter(e=>e.id!==t.id),a=r!==void 0&&En.test(r)&&!i.some(e=>e.names.includes(r));return`${t.component}.${a?r:`pin${t.number}`}`}function Mn(e,t){let n=t.trim(),r=On.exec(n)??kn.exec(n);return(r&&e.circuit.components.find(e=>e.id===r[1]))?.pins.find(e=>e.names.includes(r?.[2]??``))}var Nn=e=>e.circuit.components.flatMap(e=>e.pins),Pn=(e,t)=>e.circuit.nets.find(e=>e.pins.includes(t)),Fn=(e,t)=>Math.hypot(e.x-t.x,e.y-t.y);function In(e,t,n){let r=Pn(e,t.id)?.names[0],i=jn(e,t);return{selector:i,at:n,label:i,pin:t.id,...r===void 0?{}:{net:r}}}function Ln(e,t){let n=Pn(e,t);return n===void 0||n.pins.length<2&&n.names.length===0}function Rn(e,t,n){for(let r of e.circuit.instances??[]){if(r.path.includes(`/`))continue;let e=r.ports.find(e=>`${r.path}.${e.name}`===t);if(!e)continue;let i=`${r.path}.${e.name}`,a=e.members?{members:e.members}:{};return{selector:`port:${i}`,at:n,label:i,port:{instance:r.path,name:e.name,bus:e.bus===!0,...a}}}}function zn(e,t,n){let[r,i]=t.port?[t,n]:n.port?[n,t]:[];if(!r?.port||!i)return;let{port:a}=r;if(i.port)return{notice:`Connect ${r.label} and ${i.label} through a named net: wire each to a net label`};let o=(e.circuit.instances??[]).find(e=>e.path===a.instance);if(!o)return{notice:`${a.instance} is gone; wait for the build`};let s=a.bus?Vn(a,i):Bn(i);if(s===void 0){let e=a.bus?`a bus with the members ${(a.members??[]).join(`, `)}`:`the net a name first (a net label)`;return{notice:a.bus?`${r.label} is a bus pin; wire it to ${e}`:`Give ${e}, then wire ${r.label} to it`}}let c=sn(o.sheet,a.name,s,a.bus);return c===void 0?{edits:[{kind:`setConnections`,part:o.path,connections:gn(o,a.name,s)}],summary:`connect ${r.label} to ${s}`}:{notice:c}}var Bn=e=>e.members?void 0:e.selector.startsWith(`net.`)?e.selector.slice(4):e.net;function Vn(e,t){let n=e.members??[],r=t.members??[];return r.length===n.length&&n.every(e=>r.includes(e))?t.label:void 0}function Hn(e,t,n){let r;for(let i of e.schematic.symbols)for(let[e,a]of Object.entries(i.pinEnds)){let i=Fn(a,t);i<=n&&(!r||i<r.d)&&(r={pin:e,at:a,d:i})}return r&&{pin:r.pin,at:r.at}}function Un(e,t,n,r={}){let i=Hn(e,t,n),a=i&&Nn(e).find(e=>e.id===i.pin);return i&&a?In(e,a,i.at):i&&Rn(e,i.pin,i.at)||(Xn(e,t,n)??Jn(e,t,n,r)??Qn(e,t,n,r))}function Wn(e,t){let n;for(let r=1;r<e.length;r++){let[i,a]=[e[r-1],e[r]];if(!i||!a)continue;let o=er(t,i,a),s=Fn(o,t);(!n||s<n.d)&&(n={at:o,d:s,a:i,b:a})}return n}var Gn=e=>Math.round(e*1e4)/1e4||0;function Kn(e,t,n,r,i,a){let o=e=>e>=n[0]&&e<=n[1];if(i!==void 0&&Math.abs(t-i)<=r&&o(i))return i;if(!a.snap||!a.step)return e;let s=Gn(Math.round(e/a.step)*a.step);return o(s)?s:e}function qn(e,t,n,r){let{a:i,b:a,at:o}=e,s=i.y===a.y&&i.x!==a.x?`x`:i.x===a.x&&i.y!==a.y?`y`:void 0;if(!s)return o;let c=Kn(o[s],t[s],[Math.min(i[s],a[s]),Math.max(i[s],a[s])],n,r.from?.[s],r);return s===`x`?{x:c,y:i.y}:{x:i.x,y:c}}function Jn(e,t,n,r){let i;for(let r of e.schematic.drawings){if(r.kind!==`bus`)continue;let e=Wn(r.points,t);e&&e.d<=n&&(!i||e.d<i.near.d)&&(i={id:r.id,name:r.name,members:r.members,near:e})}let a=i&&qn(i.near,t,n,r);return i&&a&&{selector:`bus:${i.id}`,at:{x:Gn(a.x),y:Gn(a.y)},label:i.name,members:i.members}}function Yn(e,t){return{selector:`net.${t}`,at:e.at,label:t,net:t}}function Xn(e,t,n){let r;for(let i of e.schematic.labels){let a=e.circuit.nets.find(e=>e.id===i.net),o=a?.names.includes(i.text)?i.text:a?.names[0],s=Zn(i,t);o!==void 0&&s<=n&&(!r||s<r.d)&&(r={name:o,at:i.at,d:s})}return r&&{selector:`net.${r.name}`,at:r.at,label:r.name,net:r.name}}function Zn(e,t){if(e.style!==`label`)return Math.max(Fn(e.at,t)-Tn,0);let{box:n}=Ft(e);return Math.hypot(Math.max(n.minX-t.x,0,t.x-n.maxX),Math.max(n.minY-t.y,0,t.y-n.maxY))}function Qn(e,t,n,r){let i;for(let r of e.schematic.wires){let e=Wn(r.points,t);e&&e.d<=n&&(!i||e.d<i.near.d)&&(i={net:r.net,near:e})}return i&&$n(e,i.net,qn(i.near,t,n,r))}function $n(e,t,n){let r=e.circuit.nets.find(e=>e.id===t),i=r?.names[0];if(i!==void 0)return{selector:`net.${i}`,at:n,label:i,net:i};let a=r?.pins[0]??(t.startsWith(`net:`)?t.slice(4):void 0),o=Nn(e).find(e=>e.id===a);return o?{selector:jn(e,o),at:n,label:jn(e,o),pin:o.id}:void 0}function er(e,t,n){let r=n.x-t.x,i=n.y-t.y,a=r*r+i*i,o=a===0?0:Math.max(0,Math.min(1,((e.x-t.x)*r+(e.y-t.y)*i)/a));return{x:t.x+o*r,y:t.y+o*i}}function tr(e,t){if(t.pin!==void 0)return Pn(e,t.pin);let{selector:n}=t;if(n.startsWith(`net.`))return e.circuit.nets.find(e=>e.names.includes(n.slice(4)));let r=Nn(e).find(t=>jn(e,t)===n);return r&&Pn(e,r.id)}function nr(e,t){return e.selector===t.selector||e.pin!==void 0&&e.pin===t.pin}function rr(e,t,n){let[r,i]=[tr(e,t),tr(e,n)],[a,o]=[ir(t,r),ir(n,i)];if(r&&i&&r.id!==i.id&&a!==void 0&&o!==void 0)return[a,o]}var ir=(e,t)=>e.selector.startsWith(`net.`)?e.selector.slice(4):t?.names[0];function ar(e){let t=e.startsWith(`net.`)?void 0:e.split(`.`)[0];return t===void 0||Dn.test(t)&&!t.includes(`~`)}var or=e=>e.selector.startsWith(`net.`);function sr(e,t,n,r=[]){let i=wn([e.at,...n,t.at],r);return i.slice(+!or(e),or(t)?i.length:i.length-1)}function cr(e,t,n,r,i=[]){if(t.members||n.members||!ar(t.selector)||!ar(n.selector))return[];let[a,o]=[tr(e,t),tr(e,n)];if(nr(t,n)||a!==void 0&&a.id===o?.id)return[];let s=sr(t,n,r,i);return[{kind:`addTrace`,from:t.selector,to:n.selector,...s.length>0?{schematicRouteHints:s}:{}}]}var lr=/^net\.([\w-]+)$/,ur=new Set;function dr(e,t,n){return`pin`in n?t!==void 0&&Mn(e,t)?.id===n.pin:n.net.includes(lr.exec(t?.trim()??``)?.[1]??``)}function fr(e,t,n,r){return t.model.traces.filter(t=>dr(e,t.from,n)&&dr(e,t.to,r)||dr(e,t.from,r)&&dr(e,t.to,n))}function pr(e,t){return e[Number(/#(\d+)$/.exec(t??``)?.[1]??1)-1]??e[0]}function mr(e){if(!e.editable)return`This wire is read-only (${e.readonlyReason}); change it in the code`;if(e.props.schematicRouteHints&&!e.schematicRouteHints)return`The corners of this wire are an expression; change them in the code`}function hr(e,t,n,r){let i=[n?.from,n?.to].flatMap(t=>t===void 0?[]:[Mn(e,t)?.component??``]);return[...t,...i].find(e=>r.has(e))}function gr(e,t){return e.circuit.nets.find(e=>e.id===t)?.names??[t.replace(/^net\./,``)]}function _r(e,t){let n=e.model.traces.find(e=>e.from===t.from&&e.to===t.to||e.from===t.to&&e.to===t.from);return n!==void 0&&n.start!==t.start?`This wire repeats another between the same ends; change its corners in the code`:void 0}var vr=.1,yr=e=>Math.round(e*1e3)/1e3||0;function br(e){if(e.style===`label`)return Ft(e).box;let t=Dt(e.style===`ground`?kt():At(e.text),[]);return{minX:e.at.x+t.minX,minY:e.at.y+t.minY,maxX:e.at.x+t.maxX,maxY:e.at.y+t.maxY}}function xr(e){let t=br(e);return e.style===`label`?t:{minX:t.minX-vr,minY:t.minY-vr,maxX:t.maxX+vr,maxY:t.maxY+vr}}var Sr=(e,t)=>t.x>=e.minX&&t.x<=e.maxX&&t.y>=e.minY&&t.y<=e.maxY,Cr=e=>(e.maxX-e.minX)*(e.maxY-e.minY);function wr(e,t){return e.schematic.labels.map(e=>({label:e,box:xr(e)})).filter(({box:e})=>Sr(e,t)).sort((e,t)=>Cr(e.box)-Cr(t.box))[0]?.label}function Tr(e,t){return e.schematic.symbols.find(e=>e.pinEnds[t])?.pinEnds[t]}function Er(e,t){let n=e.schematic.labels.find(e=>e.id===t);if(!n)return;let r=e.circuit.connections.find(e=>`label:${e.id}`===n.id),i=`label:${n.net}:`,a=r?[r.from,r.to].find(e=>!e.startsWith(`net.`)):n.id.startsWith(i)?n.id.slice(i.length):void 0,o=e.circuit.components.flatMap(e=>e.pins).find(e=>e.id===a),s=o&&Tr(e,o.id);return o&&s?{label:n,pin:o,end:s,...r?{connection:r}:{}}:void 0}function Dr(e,t){let n=Er(e,t);return n&&{part:n.pin.component,...n.connection?{wire:`wire:${n.connection.id}`}:{}}}function Or(e,t){let n=Er(e,t);return n&&`${n.label.net}|${n.pin.id}`}function kr(e){return`the ${e.text} ${e.style===`label`?`label`:`flag`}`}function Ar(e){let t=e.connection?.corners??[];return e.connection?.from===e.pin.id?t:[...t].reverse()}function jr(e,t){if(e.connection&&t.x===e.end.x&&t.y===e.end.y)return[];let n=e.connection?Ar(e).slice(0,-1):[],r=n[n.length-1]??e.end;return[...n,...Ce([r,t]).slice(1)]}var Mr=(e,t)=>e.length===t.length&&e.every((e,n)=>e.x===t[n]?.x&&e.y===t[n]?.y),Nr=e=>({x:yr(e.x),y:yr(e.y)});function Pr(e,t){return e?t.x===e.x?t.y<e.y?`bottom`:`top`:t.x>e.x?`right`:`left`:`right`}function Fr(e,t,n){let r=Er(e,t);if(!r)return;let i=Nr(n),a=[r.end,...jr(r,i)];return{at:i,side:Pr(a[a.length-2],i),wire:a,...r.connection?{hideWire:`wire:${r.connection.id}`}:{}}}function Ir(e,t,n){return pr(fr(e,t,{pin:n.pin.id},{net:gr(e,n.label.net)}),n.connection?.id)}function Lr(e,t,n,r){let i=Er(e,n);if(!i)return{blocked:`This label is not attached to a pin the Studio can find`};let a=Ir(e,t,i),o=hr(e,[i.pin.component],a,r);if(o!==void 0)return{blocked:`${o} is locked`};let s=a?_r(t,a)??mr(a):void 0;return s?{blocked:s}:!a&&i.connection?{blocked:`The wire of this label is not written in a trace the Studio can find`}:!a&&!ar(jn(e,i.pin))?{blocked:`${i.pin.id} has a repeated name and cannot be wired from the Studio`}:a?{anchor:i,trace:a}:{anchor:i}}function Rr(e,t,n,r=ur){let i=Lr(e,t,n,r);return`blocked`in i?i.blocked:null}function zr(e,t){let n=gr(e,t.net);return`net.${n.includes(t.text)?t.text:n[0]??t.text}`}function Br(e,t,n,r,i=ur){let a=Lr(e,t,n,i);if(`blocked`in a)return a;let{anchor:o,trace:s}=a,c=jr(o,Nr(r)).map(Nr);if(Mr(c,o.connection?Ar(o):[]))return[];if(!s)return[{kind:`addTrace`,from:jn(e,o.pin),to:zr(e,o.label),schematicRouteHints:c}];let l=s.from!==void 0&&Mn(e,s.from)?.id===o.pin.id;return[{kind:`setTraceHints`,from:s.from??``,to:s.to??``,schematicRouteHints:l?c:[...c].reverse()}]}var Vr=new Intl.Collator(`en`,{numeric:!0});function Hr(e,t){let n=Array.from(e,e=>e.codePointAt(0)),r=Array.from(t,e=>e.codePointAt(0));for(let e=0;e<Math.min(n.length,r.length);e++){let t=n[e]-r[e];if(t!==0)return t}return n.length-r.length}function Ur(e,t){return Vr.compare(e,t)||Hr(e,t)}function Wr(e){return[...e].sort(Ur)}var Gr=4,Kr=6,qr=6;function Jr(e,t){let n=[...e].length;return n===0?0:((n-1)*qr+Gr)*t/Kr}function Yr(e){if(e.courtyard.length===0)return[{x:e.x,y:e.y}];let t=e.courtyard.map(e=>e.x),n=e.courtyard.map(e=>e.y),[r,i,a,o]=[Math.min(...t),Math.max(...t),Math.min(...n),Math.max(...n)],[s,c]=[(r+i)/2,(a+o)/2],[l,u]=[Jr(e.component,1)/2,1/2];return[{x:s,y:o+u},{x:s,y:a-u},{x:r-l,y:c},{x:i+l,y:c}]}var Xr=e=>e.nameAt??e.designatorAt??Yr(e)[0],Zr=.3,Qr=.5,$r=`"Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", sans-serif`,ei=`"Cascadia Mono", "JetBrains Mono", ui-monospace, Consolas, monospace`,ti={strong:600,regular:400},ni=(e,t,n=$r)=>`${e} ${t}px ${n}`,B={background:`#000000`,boardEdge:`#ff00ff`,topCopper:`#ff0000`,bottomCopper:`#0000ff`,inner1Copper:`#cc9933`,inner2Copper:`#9966cc`,multiLayer:`#c0c0c0`,viaRing:`#c0c0c0`,highlight:`#ffffff`,drill:`#222222`,topSilk:`#ffcc00`,bottomSilk:`#66cc33`,topAssembly:`#33cc99`,bottomAssembly:`#5555ff`,ratsnest:`#6464ff`,keepout:`#f022f0`,document:`#ffffff`,grid:`rgb(255 255 255 / 30%)`,gridFifth:`rgb(255 255 255 / 50%)`,selection:`#ffffff`,selectionFill:`rgb(255 255 255 / 50%)`,hover:`rgb(255 255 255 / 60%)`,selectionBox:`#00ffff`,selectionBoxFill:`rgb(0 255 255 / 10%)`,notePanel:`rgb(0 0 0 / 80%)`,error:`#e5534b`,warning:`#e0a63a`,ringHaloOuter:`#ffffff`,ringHaloInner:`#000000`};function ri(e){let t=e.split(`_`);return[t.includes(`top`)?`top`:t.includes(`bottom`)?`bottom`:`middle`,t.includes(`left`)?`left`:t.includes(`right`)?`right`:`center`]}var ii=[`top`,`bottom`,`topSilk`,`bottomSilk`,`topAssembly`,`bottomAssembly`,`courtyard`,`boardOutline`,`multiLayer`,`hole`,`ratline`,`keepout`],ai=[{id:`top`,name:`Top Layer`},{id:`bottom`,name:`Bottom Layer`}],oi=[{id:`top`,name:`Top Layer`,group:`copper`,color:B.topCopper},{id:`bottom`,name:`Bottom Layer`,group:`copper`,color:B.bottomCopper},{id:`topSilk`,name:`Top Silkscreen`,group:`non-copper`,color:B.topSilk},{id:`bottomSilk`,name:`Bottom Silkscreen`,group:`non-copper`,color:B.bottomSilk},{id:`topAssembly`,name:`Top Assembly`,group:`non-copper`,color:B.topAssembly},{id:`bottomAssembly`,name:`Bottom Assembly`,group:`non-copper`,color:B.bottomAssembly},{id:`courtyard`,name:`Courtyard`,group:`non-copper`,color:B.topAssembly,bottomColor:B.bottomAssembly},{id:`boardOutline`,name:`Board Outline`,group:`non-copper`,color:B.boardEdge},{id:`multiLayer`,name:`Multi-Layer`,group:`copper`,color:B.multiLayer},{id:`hole`,name:`Hole`,group:`non-copper`,color:B.drill},{id:`ratline`,name:`Ratline`,group:`non-copper`,color:B.ratsnest},{id:`keepout`,name:`Keepout`,group:`non-copper`,color:B.keepout}];function si(e,t){return oi.filter(n=>(e||n.id!==`keepout`)&&(t===`all`||n.group===t))}function ci(e){return e.bottomColor?`linear-gradient(135deg, ${e.color} 50%, ${e.bottomColor} 50%)`:e.color}var li={...Object.fromEntries(ii.map(e=>[e,!0])),topAssembly:!1,bottomAssembly:!1};function ui(e,t){let n=new Set(e);return n.delete(t)||n.add(t),n}function di(e,t,n){let r={top:`Top Layer`,bottom:`Bottom Layer`,inner1:`Inner Layer 1`,inner2:`Inner Layer 2`};return Object.keys(r).flatMap(i=>{let a=e.filter(e=>e.layer===i).map(e=>({id:e.id,net:t(e.net),layer:i,shown:!n.has(e.id)}));return a.length>0?[{layer:i,name:r[i],pours:a}]:[]})}function fi(e,t){return{...e,[t]:!e[t]}}function pi(e){return e.layers===`through`?`multiLayer`:e.layers===`bottom`?`bottom`:`top`}function mi(e){let t=e.side===`top`,n=new Set([`courtyard`]);e.fabrication.length>0&&n.add(t?`topAssembly`:`bottomAssembly`),e.silkscreen.length>0&&n.add(t?`topSilk`:`bottomSilk`);for(let t of e.pads)n.add(pi(t)),t.drill&&n.add(`hole`);return[...n]}function hi(e,t){return e.some(e=>t[e])}function gi(e,t){let n=new Map(e.map(e=>[e.component,mi(e)]));return{visible:t,of:e=>n.get(e)}}var _i={parts:!0,labels:!0,wires:!0,drawings:!0,tracks:!0,vias:!0,texts:!0,pours:!0};function vi(e,t){return{...e,[t]:!e[t]}}function yi(e,t){return e===void 0||e[t]}function bi(e){let t={kind:`parts`,label:`Parts`};return e===`schematic`?[t,{kind:`wires`,label:`Wires`},{kind:`labels`,label:`Net labels and flags`},{kind:`drawings`,label:`Drawings`},{kind:`texts`,label:`Names and values`}]:[t,{kind:`tracks`,label:`Tracks`},{kind:`vias`,label:`Vias`},{kind:`pours`,label:`Copper pours and holes`},{kind:`texts`,label:`Designators`}]}var xi={part:`parts`,label:`labels`,wire:`wires`,drawing:`drawings`,track:`tracks`,via:`vias`,text:`texts`,pour:`pours`,hole:`pours`};function Si(e,t){if(!Ci(xi[e.kind],t))return!1;let{layers:n}=t,r=e.kind===`part`?n?.of(e.name):void 0;return!n||!r||hi(r,n.visible)}function Ci(e,t){return t.armed===`note`||t.armed===`zoom`?!1:yi(t.filter,e)}function wi(e,t){return e.filter(e=>Si(e,t))}function Ti(e,t){return wi(e.map(e=>({kind:`part`,name:e})),t).map(e=>e.name)}function Ei(e,t){return wi(e.map(e=>({kind:`wire`,id:e})),t).map(e=>e.id)}function Di(e,t){return Ci(`labels`,t)?[...e]:[]}function V(e,t){return Ci(`drawings`,t)?[...e]:[]}function Oi(e,t){return wi(e.map(({kind:e,id:t})=>({kind:e,id:t})),t).map(e=>e.id)}function ki(e,t,n,r=[],i=[],a=[],o=[]){return s=>{let c={selection:s,armed:null,layers:t,filter:n};return s.all(Ti(e,c),Ei(r,c),Di(i,c),V(a,c),Oi(o,c))}}function Ai(e,t){return t.x>=e.x?`inside`:`touching`}var ji=(e,t)=>t.minX>=e.minX&&t.maxX<=e.maxX&&t.minY>=e.minY&&t.maxY<=e.maxY,Mi=(e,t)=>e.minX<=t.maxX&&t.minX<=e.maxX&&e.minY<=t.maxY&&t.minY<=e.maxY;function Ni(e,t,n,r){let i=xe([t,n]);if(!i)return[];let a=r===`inside`?e=>ji(i,e):e=>Mi(i,e);return e.filter(e=>a(e.box)).map(e=>e.id)}function Pi(e,t,n,r){return Ni(e.map(e=>({id:e.name,box:e.box})),t,n,r)}function Fi(e,t,n,r){return Ni(e,t,n,r)}var Ii=(e,t)=>t.x>=e.minX&&t.x<=e.maxX&&t.y>=e.minY&&t.y<=e.maxY;function Li(e,t,n){if(Ii(e,t)||Ii(e,n))return!0;let r=xe([t,n]);if(!r||!Mi(e,r))return!1;let i=[{x:e.minX,y:e.minY},{x:e.maxX,y:e.minY},{x:e.minX,y:e.maxY},{x:e.maxX,y:e.maxY}].map(e=>(n.x-t.x)*(e.y-t.y)-(n.y-t.y)*(e.x-t.x));return i.some(e=>e>=0)&&i.some(e=>e<=0)}function Ri(e,t,n,r){let i=xe([t,n]);if(!i)return[];let a=r===`inside`?e=>e.every(e=>Ii(i,e)):e=>e.some((t,n)=>Li(i,e[n-1]??t,t));return e.filter(e=>a(e.points)).map(e=>e.id)}function zi(e,t,n=null,r,i){return a=>{let o={selection:a,armed:n,layers:r,filter:i},[s,c,l]=[Ti(e.parts,o),Ei(e.wires??[],o),Di(e.labels??[],o)],u=V(e.drawings??[],o),d=Oi(e.copper??[],o);return t?a.add(s).addWires(c).addLabels(l).addDrawings(u).addCopper(d):a.all(s,c,l,u,d)}}var Bi=e=>[...new Set(e)],Vi=(e,t)=>e.length===t.length&&e.every((e,n)=>e===t[n]),Hi=(e,t)=>e.filter(e=>!t.includes(e)),Ui=(e,t)=>{let n=new Set(t);return e.filter(e=>n.has(e))},Wi=(e,t)=>e!==void 0&&e.x===t.x&&e.y===t.y,Gi=(e,t)=>e!==void 0&&e.id===t.id&&e.index===t.index&&Wi(e.from,t.from)&&Wi(e.to,t.to);function Ki(e,t){let[n,r]=[e.points[t],e.points[t+1]];return Number.isInteger(t)&&t>=0&&n&&r?{id:e.id,index:t,from:{x:n.x,y:n.y},to:{x:r.x,y:r.y}}:void 0}function qi(e,t){return Wi(t[e.index],e.from)&&Wi(t[e.index+1],e.to)}var Ji={names:[],wires:[],labels:[],drawings:[],copper:[],texts:[],board:[]},Yi=[`names`,`wires`,`labels`,`drawings`,`copper`,`texts`,`board`],Xi=class e{static none=new e(Ji);names;wires;labels;drawings;copper;texts;board;segment;constructor(e,t){this.names=Object.freeze([...e.names]),this.wires=Object.freeze([...e.wires]),this.labels=Object.freeze([...e.labels]),this.drawings=Object.freeze([...e.drawings]),this.copper=Object.freeze([...e.copper]),this.texts=Object.freeze([...e.texts]),this.board=Object.freeze([...e.board]),this.segment=t&&Object.freeze({id:t.id,index:t.index,from:Object.freeze({...t.from}),to:Object.freeze({...t.to})}),Object.freeze(this)}static from(t){return Yi.every(e=>t[e].length===0)?e.none:new e(t)}get lists(){return{names:this.names,wires:this.wires,labels:this.labels,drawings:this.drawings,copper:this.copper,texts:this.texts,board:this.board}}with(t){let n={...this.lists,...t};return Yi.every(e=>n[e].length===this[e].length)?this:e.from(n)}grown(t){return new e({...this.lists,...t})}get primary(){return this.names.at(-1)}get size(){return this.names.length}get wireCount(){return this.wires.length}get labelCount(){return this.labels.length}get drawingCount(){return this.drawings.length}get copperCount(){return this.copper.length}get textCount(){return this.texts.length}get boardCount(){return this.board.length}get total(){return this.names.length+this.wires.length+this.labels.length+this.drawings.length+this.copper.length+this.texts.length+this.board.length}get soleBoard(){return this.total===1?this.board[0]:void 0}get soleText(){return this.total===1?this.texts[0]:void 0}get soleCopper(){return this.total===1?this.copper[0]:void 0}get soleWire(){return this.total===1?this.wires[0]:void 0}get soleLabel(){return this.total===1?this.labels[0]:void 0}get soleDrawing(){return this.total===1?this.drawings[0]:void 0}has(e){return this.names.includes(e)}hasWire(e){return this.wires.includes(e)}hasLabel(e){return this.labels.includes(e)}hasDrawing(e){return this.drawings.includes(e)}hasCopper(e){return this.copper.includes(e)}hasText(e){return this.texts.includes(e)}hasBoard(e){return this.board.includes(e)}onlyBoard(t){return this.soleBoard===t?this:new e({...Ji,board:[t]})}toggleBoard(e){return this.hasBoard(e)?this.withoutBoard([e]):this.grown({board:[...this.board,e]})}addBoard(e){let t=Bi(e).filter(e=>!this.hasBoard(e));return t.length===0?this:this.grown({board:[...this.board,...t]})}withoutBoard(e){return this.with({board:Hi(this.board,e)})}keepBoard(e){return this.with({board:Ui(this.board,e)})}only(t){return this.total===1&&this.names[0]===t?this:new e({...Ji,names:[t]})}onlyWire(t){return this.soleWire===t?this:new e({...Ji,wires:[t]})}onlyLabel(t){return this.soleLabel===t?this:new e({...Ji,labels:[t]})}onlyDrawing(t){return this.soleDrawing===t?this:new e({...Ji,drawings:[t]})}onlyText(t){return this.soleText===t?this:new e({...Ji,texts:[t]})}onlyCopper(t){return this.soleCopper===t&&!this.segment?this:new e({...Ji,copper:[t]})}onlySegment(t){return Gi(this.segment,t)?this:new e({...Ji,copper:[t.id]},t)}toggle(e){return this.has(e)?this.without([e]):this.grown({names:[...this.names,e]})}toggleWire(e){return this.hasWire(e)?this.withoutWires([e]):this.grown({wires:[...this.wires,e]})}toggleLabel(e){return this.hasLabel(e)?this.withoutLabels([e]):this.grown({labels:[...this.labels,e]})}toggleDrawing(e){return this.hasDrawing(e)?this.withoutDrawings([e]):this.grown({drawings:[...this.drawings,e]})}toggleCopper(e){return this.hasCopper(e)?this.withoutCopper([e]):this.grown({copper:[...this.copper,e]})}toggleText(e){return this.hasText(e)?this.with({texts:Hi(this.texts,[e])}):this.grown({texts:[...this.texts,e]})}add(e){let t=Bi(e).filter(e=>!this.has(e));return t.length===0?this:this.grown({names:[...this.names,...t]})}addWires(e){let t=Bi(e).filter(e=>!this.hasWire(e));return t.length===0?this:this.grown({wires:[...this.wires,...t]})}addLabels(e){let t=Bi(e).filter(e=>!this.hasLabel(e));return t.length===0?this:this.grown({labels:[...this.labels,...t]})}addDrawings(e){let t=Bi(e).filter(e=>!this.hasDrawing(e));return t.length===0?this:this.grown({drawings:[...this.drawings,...t]})}addCopper(e){let t=Bi(e).filter(e=>!this.hasCopper(e));return t.length===0?this:this.grown({copper:[...this.copper,...t]})}clear(){return e.none}all(t,n=[],r=[],i=[],a=[]){let o={names:Bi(t),wires:Bi(n),labels:Bi(r),drawings:Bi(i),copper:Bi(a),texts:[],board:[]};return Yi.every(e=>Vi(o[e],this[e]))?this:e.from(o)}without(e){return this.with({names:Hi(this.names,e)})}withoutWires(e){return this.with({wires:Hi(this.wires,e)})}withoutLabels(e){return this.with({labels:Hi(this.labels,e)})}withoutDrawings(e){return this.with({drawings:Hi(this.drawings,e)})}withoutCopper(e){return this.with({copper:Hi(this.copper,e)})}keep(e){return this.with({names:Ui(this.names,e)})}keepWires(e){return this.with({wires:Ui(this.wires,e)})}keepLabels(e){return this.with({labels:Ui(this.labels,e)})}keepDrawings(e){return this.with({drawings:Ui(this.drawings,e)})}withoutTexts(e){return this.with({texts:Hi(this.texts,e)})}keepTexts(e){return this.with({texts:Ui(this.texts,e)})}keepCopper(e){return this.with({copper:Ui(this.copper,e)})}};function Zi(e,t){let{segment:n}=e,r=n&&t.find(e=>e.id===n.id);return n&&r&&!qi(n,r.points)?e.onlyCopper(n.id):e}function Qi(e){return e.shiftKey||e.ctrlKey||e.metaKey}function $i(e,t){let n=Qi(t);return t=>n?t.toggle(e):t.only(e)}function ea(e,t){let n=new Set(t);return e.filter(e=>!n.has(e))}var ta={error:B.error,warning:B.warning},na=6,ra=1.5,ia=3,aa=1;function oa(e,t,n,r,i,a=ta){if(n.length!==0){e.globalAlpha=1,e.setLineDash([]);for(let o of n){let n=fe(t.camera,t.size,o.at),s=o.id===r?ia:ra;i&&ca(e,n,s),e.strokeStyle=o.severity===`error`?a.error:a.warning,sa(e,n,na,s)}}}function sa(e,t,n,r){e.lineWidth=r,e.beginPath(),e.arc(t.x,t.y,n,0,Math.PI*2),e.stroke()}function ca(e,t,n){let r=(n+aa)/2;e.strokeStyle=B.ringHaloOuter,sa(e,t,na+r,aa),e.strokeStyle=B.ringHaloInner,sa(e,t,na-r,aa)}var la={background:`#FFFCF8`,grid:`#F0F0EB`,wire:`#008800`,bus:`#008800`,drawing:`#000080`,junction:`#CC0000`,symbolOutline:`#A00000`,pin:`#880000`,pinName:`#000000`,pinNumber:`#000000`,designator:`#0000FF`,netName:`#0000FF`,value:`#000080`,noConnect:`#33CC33`,selection:`#FF0000`,highlight:`#FF9933`,border:`#A00000`,titleText:`#000080`,gridDot:`#D9D9D2`,flag:`#A00000`,markerError:B.error,markerWarning:B.warning,selectionGlow:0,hover:`rgb(255 0 0 / 45%)`,handleFill:`#FFFFFF`,selectionFill:`rgb(255 0 0 / 8%)`,selectionBox:`#0000FF`,selectionBoxFill:`rgb(0 0 255 / 8%)`,lockBadge:`#4f9a6c`,lockGlyph:`#ffffff`,notePin:`#e0a46a`,notePanel:`rgb(34 38 44 / 92%)`,noteText:`#e9e6df`},ua={background:`#141619`,grid:`#2B3038`,gridDot:`#2B3038`,gridFifth:`#3A4049`,wire:`#5BD3C7`,bus:`#8AB4FF`,drawing:`#9AA1A9`,junction:`#5BD3C7`,symbolOutline:`#D9DEE5`,pin:`#D9DEE5`,pinName:`#AEB6C0`,pinNumber:`#7E8792`,designator:`#E6E8EB`,netName:`#F2C66D`,value:`#AEB6C0`,noConnect:`#5BD3C7`,selection:`#4CC9F0`,highlight:`#E89A4F`,border:`#9AA1A9`,titleText:`#9AA1A9`,flag:`#FF9E80`,markerError:`#FF6B6B`,markerWarning:`#FFC857`,selectionGlow:8,hover:`#8BE0F5`,handleFill:`#141619`,selectionFill:`rgb(76 201 240 / 10%)`,selectionBox:`#4CC9F0`,selectionBoxFill:`rgb(76 201 240 / 8%)`,lockBadge:`#4f9a6c`,lockGlyph:`#ffffff`,notePin:`#e0a46a`,notePanel:`rgb(34 38 44 / 92%)`,noteText:`#e9e6df`},da=e=>e===`dark`?ua:la,fa=la,H=()=>fa;function pa(e){fa=e}function ma(e,t,n=fa){let r=t?n.selectionGlow:0;e.shadowBlur=r,e.shadowColor=r>0?n.selection:`transparent`}var ha=.02,ga=3*ha;function _a(e){return e.kind===`bus`?ga:e.kind===`text`||e.kind===`junction`?0:e.strokeWidth}var va=(e,t)=>Math.max(e,t);function ya(e,t){return e===`dashed`?[4*t,3*t]:e===`dotted`?[0,2*t]:[]}function ba(e){return e.kind===`bus`||e.kind===`text`||e.kind===`junction`?`solid`:e.lineStyle}function xa(e){return e.kind===`bus`?H().bus:e.kind===`junction`?e.color??H().junction:e.color??H().drawing}var Sa=e=>(e.kind===`rect`||e.kind===`circle`)&&e.filled,Ca=e=>`${e}33`,wa=e=>1/e,Ta=(e,t)=>(Math.floor(e*t)+.5)/t,Ea=(e,t)=>Math.round(e*t)/t,Da=(e,t)=>Math.max(1,Math.round(e*t))/t,Oa=(e,t)=>Math.round(e*t)/t,ka=(e,t)=>e/t,Aa=(e,t)=>Math.max(1,Math.round(e*t)),ja=(e,t,n)=>n%2==1?Ta(e,t):Ea(e,t);function Ma(e,t,n,r=1){let i=e=>ja(e,n,r),a=i(Math.min(e.x,t.x)),o=i(Math.min(e.y,t.y));return{x:a,y:o,width:i(Math.max(e.x,t.x))-a,height:i(Math.max(e.y,t.y))-o}}var Na=.16;function Pa(e){return e<7?`none`:e<9?`names`:`all`}function Fa(e,t,n){if(n<5)return!1;let r=Pa(t);return e===`name`?r!==`none`:e===`pin-number`?t>=11:r===`all`}var Ia=(e,t,n)=>Math.max(1,Math.round(e*t*n)),La=(e,t)=>Ia(Na,e,t),Ra=(e,t,n)=>Ia(e,t,n)/n,za=(e,t)=>({x:Ea(e.x,t),y:Oa(e.y,t)});function Ba(e){`textRendering`in e&&(e.textRendering=`geometricPrecision`)}var Va=(e,t,n)=>t<=n||t<=0?e:Math.max(1,Math.floor(e*n/t)),U=e=>e*Math.PI/180;function Ha(e,t){if(!t||t.length===0)return e;let n=new Map(t.map(e=>[e.id,e]));return e.map(e=>n.get(e.id)??e)}function Ua(e,t){let n=t-e;return Math.abs(n)>=360?360:(n%360+360)%360}function Wa(e,t){if(e.beginPath(),t.kind===`path`||t.kind===`bus`){t.points.forEach((t,n)=>n===0?e.moveTo(t.x,t.y):e.lineTo(t.x,t.y));return}if(t.kind===`rect`){let{x:n,y:r,width:i,height:a}=t;e.moveTo(n,r),e.lineTo(n+i,r),e.lineTo(n+i,r+a),e.lineTo(n,r+a),e.closePath();return}if(t.kind===`circle`)return e.arc(t.x,t.y,t.radius,0,2*Math.PI);let n=U(t.startAngle);e.arc(t.x,t.y,t.radius,n,n+U(Ua(t.startAngle,t.endAngle)))}function Ga(e,t){return t.selected?.includes(e.id)?{color:H().selection,alpha:1}:{color:xa(e),alpha:t.dim?Zr:1}}function Ka(e,t,n,r,i){e.globalAlpha=r,e.fillStyle=n,e.beginPath(),e.arc(t.x,t.y,Gt,0,2*Math.PI),ma(e,i),e.fill(),ma(e,!1)}function qa(e,t,n,r){for(let i of t){if(i.kind===`text`)continue;let{color:t,alpha:a}=Ga(i,r);if(i.kind===`junction`){Ka(e,i,t,a,r.selected?.includes(i.id)??!1);continue}let o=va(_a(i),n);e.globalAlpha=a,e.lineWidth=o,e.strokeStyle=t,e.setLineDash(ya(r.pending?`dashed`:ba(i),o)),Wa(e,i),Sa(i)&&(e.fillStyle=Ca(t),e.fill()),ma(e,r.selected?.includes(i.id)??!1),e.stroke(),ma(e,!1),e.setLineDash([])}e.globalAlpha=1}function Ja(e,t,n,r,i,a){for(let o of t){if(o.kind!==`text`||o.text===``)continue;let t=Ia(o.fontSize,n.scale,a);if(!Fa(`detail`,La(n.scale,a),t))continue;let s=t/a,{color:c,alpha:l}=Ga(o,i),u=za(fe(n,r,o),a),[,d]=ri(o.anchor);e.globalAlpha=l,e.fillStyle=c,e.font=`${s}px ${$r}`,e.textAlign=d,e.textBaseline=`middle`,e.fillText(o.text,u.x,u.y)}e.globalAlpha=1}var Ya=.7,Xa=`…`,Za=2;function Qa(e,t,n){if(n(e)<=t)return e;for(let r=e.length-1;r>=Za;r--){let i=e.slice(0,r)+Xa;if(n(i)<=t)return i}return null}function $a(e,t,n){let r=t(e);if(r>=1)return{text:e,scale:1};if(r>=n)return{text:e,scale:r};for(let r=e.length-1;r>=Za;r--){let i=e.slice(0,r)+Xa;if(t(i)>=n)return{text:i,scale:n}}return null}function eo(e,t,n){if(t+n<=e)return t;let r=e/2;return t<=r?t:n<=r?e-n:r}var to=(e,t,n,r)=>t===`x`===e.quarter?e.size:r(n),no=e=>e.side===`left`||e.side===`right`,ro=e=>no(e)?`x`:`y`,io=e=>no(e)?`y`:`x`,ao=e=>no(e)?1:.5,oo={left:`right`,right:`left`,top:`bottom`,bottom:`top`};function so(e,t,n,r){let[i,a]=[ro(e),io(e)],o=e.side===`left`||e.side===`bottom`?1:-1,s=e=>to(e,i,e.text,n)*ao(e),c=t=>Math.abs(t.local[a]-e.local[a])<(to(e,a,e.text,n)+to(t,a,t.text,n))/2,l=t.filter(t=>t.side===oo[e.side]&&c(t)&&(t.local[i]-e.local[i])*o>0).sort((t,n)=>Math.abs(t.local[i]-e.local[i])-Math.abs(n.local[i]-e.local[i]))[0];return eo(Math.abs((l?l.local[i]:-e.local[i])-e.local[i])-r,s(e),l?s(l):0)/ao(e)}function co(e,t,n){let r=io(e),i=t.filter(t=>t!==e&&t.side===e.side).map(t=>Math.abs(t.local[r]-e.local[r]));return i.length===0?1/0:Math.min(...i)-n}function lo(e,t,n,r,i){let a=so(e,t,n,r),o=co(e,t,r);return $a(e.text,t=>Math.min(a/to(e,ro(e),t,n),o/to(e,io(e),t,n)),i)}function uo(e,t,n){let r=n(t.text)*t.scale,i=e.align===`left`?e.x:e.align===`right`?e.x-r:e.x-r/2;return{x0:i,x1:i+r,y0:e.y-e.ascent*t.scale,y1:e.y+e.descent*t.scale}}var fo=(e,t)=>e.x0<t.x1&&t.x0<e.x1&&e.y0<t.y1&&t.y0<e.y1;function po(e,t){let n=new Set;return e.forEach((r,i)=>{e.forEach((e,a)=>{a>i&&r&&e&&t(i,a)&&fo(r,e)&&n.add(i).add(a)})}),n}function mo(e,t,n,r=Ya){let i=e.map(i=>lo(i,e,t,n,r)),a=i.map((n,r)=>n===null?null:uo(e[r],n,t)),o=po(a,(t,n)=>e[t]?.side===e[n]?.side),s=po(a.map((e,t)=>o.has(t)?null:e),()=>!0);return i.map((e,t)=>o.has(t)||s.has(t)?null:e)}var ho=.25,go=.8,_o=.2,vo={top:go,middle:.6000000000000001/2,bottom:-.2},yo=(e,t,n)=>ni(e.strong?ti.strong:ti.regular,t/n,e.mono?ei:void 0);function bo(e,t,{camera:n,ratio:r}){let i=Ia(t.size,n.scale,r);return t.maxWidth===void 0?i:(e.font=yo(t,i,r),Va(i,e.measureText(t.text).width,t.maxWidth*n.scale))}function xo(e,t,n,r){e.textBaseline=n;let i=e.measureText(t),a=(vo[n]??0)*r;return{ascent:i.actualBoundingBoxAscent??go*r-a,descent:i.actualBoundingBoxDescent??_o*r+a}}function So(e,{label:t,devicePx:n},r){let i=t.pinOf;if(!i)return null;let a=n/r.ratio,o=fe(r.camera,r.size,t.at),[s,c]=ri(t.anchor),l={x:i.local.x*r.camera.scale,y:i.local.y*r.camera.scale},u=xo(e,t.text,s,a);return{text:t.text,x:o.x,y:o.y,align:c,size:a,...u,local:l,side:i.side,quarter:i.quarter}}function Co(e,t,n){let r=t[0];if(!r)return t;e.font=yo(r.label,r.devicePx,n.ratio);let i=t.map(t=>So(e,t,n)).filter(e=>e!==null);if(i.length!==t.length)return t;let a=Math.ceil(r.devicePx*Ya)/r.devicePx,o=mo(i,t=>e.measureText(t).width,r.devicePx/n.ratio*ho,a);return t.flatMap((e,t)=>{let n=o[t];if(!n)return[];let r=n.scale<1?Math.floor(e.devicePx*n.scale+1e-9):e.devicePx;return[{label:{...e.label,text:n.text},devicePx:r}]})}function wo(e,t,n){let r=La(n.camera.scale,n.ratio),i=({label:e,devicePx:t})=>Fa(e.kind,r,t),a=t.filter(e=>e.text!==``).map(t=>({label:t,devicePx:bo(e,t,n)})).filter(i),o=new Map;for(let e of a){let t=e.label.pinOf?.symbol;t!==void 0&&o.set(t,[...o.get(t)??[],e])}let s=[...o.values()].flatMap(t=>Co(e,t,n));return[...a.filter(({label:e})=>!e.pinOf),...s.filter(i)]}function To(e,{label:t,devicePx:n},r){let i=za(fe(r.camera,r.size,t.at),r.ratio),[a,o]=ri(t.anchor);e.save(),e.translate(i.x,i.y),t.rotation&&e.rotate(-t.rotation*Math.PI/180),e.globalAlpha=t.alpha??1,e.fillStyle=t.color,e.font=yo(t,n,r.ratio),e.textAlign=o,e.textBaseline=a,e.fillText(t.text,0,0),e.restore()}function Eo(e,t,n,r,i){let a={camera:n,size:r,ratio:i};Ba(e);for(let n of wo(e,t,a))To(e,n,a)}var Do=.05,Oo=.015;function ko(e){let t=Do;return[[{x:e.x-t,y:e.y-t},{x:e.x+t,y:e.y+t}],[{x:e.x-t,y:e.y+t},{x:e.x+t,y:e.y-t}]]}function Ao(e,t,n,r){if(t.length!==0){e.strokeStyle=H().noConnect,e.lineWidth=n(Oo),e.globalAlpha=r?Zr:1;for(let n of t)for(let[t,r]of ko(n.at))e.beginPath(),e.moveTo(t.x,t.y),e.lineTo(r.x,r.y),e.stroke();e.globalAlpha=1}}var jo={x:0,y:0},Mo=.02,No=1.2,Po=3.5,Fo=.06,Io=1.5,Lo=1.6,Ro=.04,zo=3,Bo=[.1,.06],Vo=.1,Ho=.07,Uo=2.5,Wo={reference:`name`,value:`detail`,"pin-name":`detail`,"pin-number":`pin-number`},Go={reference:`designator`,value:`value`,"pin-name":`pinName`,"pin-number":`pinNumber`},Ko={right:{x:1,y:0},left:{x:-1,y:0},top:{x:0,y:1},bottom:{x:0,y:-1}},qo=e=>e*Math.PI/180,Jo=e=>Math.max(ha*e,No);function Yo(e,t,n,r){let{camera:i,size:a}=n,o=1/i.scale,s=e=>Math.max(e,o/r.ratio),c=[],l=e=>r.moving?.components.includes(e.component)?r.moving.by:jo;e.save();let u=i.scale*r.ratio;e.setTransform(u,0,0,-u,(a.width/2-i.cx*i.scale)*r.ratio,(a.height/2+i.cy*i.scale)*r.ratio),e.lineCap=`round`,e.lineJoin=`round`,ss(e,t,r,o,s);let d=Ha(t.drawings,r.movingDrawings),f=r.pendingDrawings??[],p=[...d,...f],m={...r.selectedDrawings?{selected:r.selectedDrawings}:{},dim:r.highlight!==void 0};qa(e,d,o/r.ratio,m),qa(e,f,o/r.ratio,{pending:!0,dim:m.dim});for(let n of t.symbols)cs(e,n,l(n),{line:s,px:o,fade:rs(n,r.highlight)},c);for(let n of t.labels){let t=r.movingLabels?.some(e=>e.id===n.id)??!1,i=r.selectedLabels?.includes(n.id)??!1,a=i?{color:H().selection,alpha:1}:ns(n.net,r.highlight);ma(e,i),_s(e,gs(n,r),s,c,t,a),ma(e,!1)}for(let t of r.ghostLabels??[])_s(e,t,s,c,!0,ns(t.net,void 0));bs(e,t,r,o,l),Ao(e,t.noConnects??[],s,r.highlight!==void 0),e.setTransform(r.ratio,0,0,r.ratio,0,0),Eo(e,c,i,a,r.ratio),Ja(e,p,i,a,m,r.ratio),oa(e,n,r.violations??[],r.activeViolation,!1,{error:H().markerError,warning:H().markerWarning}),e.restore()}function Xo(e){return e.symbols.map(e=>{let t=Qo(e);return{name:e.component,pcbComponentId:e.component,center:{x:(t.minX+t.maxX)/2,y:(t.minY+t.maxY)/2},box:t}})}var Zo=e=>e.type===`text`&&(e.role===`reference`||e.role===`value`);function Qo(e){let{minX:t,minY:n,maxX:r,maxY:i}=Dt(e.symbol.shapes.filter(e=>!Zo(e)),e.symbol.pins),a=[{x:t,y:n},{x:r,y:n},{x:r,y:i},{x:t,y:i}].map(t=>$o(t,e)),o=a.map(e=>e.x),s=a.map(e=>e.y);return{minX:Math.min(...o),minY:Math.min(...s),maxX:Math.max(...o),maxY:Math.max(...s)}}function $o(e,t){let n=qo(t.rotation),r=Math.cos(n),i=Math.sin(n);return{x:t.x+e.x*r-e.y*i,y:t.y+e.x*i+e.y*r}}function es(e,t){e.beginPath(),t.forEach((t,n)=>n===0?e.moveTo(t.x,t.y):e.lineTo(t.x,t.y))}function ts(e,t,n){e.beginPath(),e.arc(t.x,t.y,Math.max(n,0),0,Math.PI*2)}function ns(e,t){return t?e===t.net||t.aliases?.includes(e)?{color:H().highlight,alpha:1}:{color:void 0,alpha:Zr}:{color:void 0,alpha:1}}function rs(e,t){return t?t.pins?.some(t=>t in e.pinEnds)?1:Zr:1}var is=1e-9;function as(e,t,n){let r=Math.abs((n.x-t.x)*(e.y-t.y)-(n.y-t.y)*(e.x-t.x))<is,i=(e,t,n)=>e>=Math.min(t,n)-is&&e<=Math.max(t,n)+is;return r&&i(e.x,t.x,n.x)&&i(e.y,t.y,n.y)}function os(e,t,n){return e.wires.some(e=>ns(e.net,n).color!==void 0&&e.points.some((n,r)=>r>0&&as(t,e.points[r-1]??n,n)))}function ss(e,t,n,r,i){e.lineWidth=i(ha);for(let r of t.wires){if(n.movingLabels?.some(e=>e.hideWire===r.id))continue;let t=n.selectedWires?.includes(r.id)??!1,i=t?{color:H().selection,alpha:1}:ns(r.net,n.highlight);e.strokeStyle=i.color??H().wire,e.globalAlpha=i.alpha,ma(e,t),es(e,r.points),e.stroke()}ma(e,!1);for(let i of t.junctions){let a=n.highlight!==void 0&&os(t,i,n.highlight);e.fillStyle=a?H().highlight:H().junction,e.globalAlpha=n.highlight&&!a?Zr:1,ts(e,i,Math.max(Ro,zo*r)),e.fill()}e.globalAlpha=1,e.strokeStyle=H().wire;let a=(n.pending??[]).filter(e=>e.length>=2);if(a.length!==0){e.setLineDash(Bo);for(let t of a)es(e,t),e.stroke();e.setLineDash([])}}function cs(e,t,n,r,i){let a={x:t.x+n.x,y:t.y+n.y,rotation:t.rotation},o=r.fade,s=[];e.globalAlpha=o,e.lineWidth=r.line(Mo),ds(e,t.symbol.shapes,a,H().symbolOutline,s),e.globalAlpha=1;let c=t.symbol.shapes.some(e=>e.type===`text`&&e.role===`pin-number`);t.symbol.kind!==`sheet`&&!c&&s.push(...us(t.symbol,a)),i.push(...s.map(e=>({...e,alpha:o,...ls(e,t)})))}function ls(e,t){if(e.pinOf)return{pinOf:{...e.pinOf,symbol:t.component}};if(e.role!==`reference`&&e.role!==`value`||t.symbol.pins.length!==2)return{};let[n,r]=t.symbol.pins;return n&&r?{maxWidth:Uo*Math.hypot(n.end.x-r.end.x,n.end.y-r.end.y)}:{}}function us(e,t){return e.pins.map(e=>{let n=Ko[e.side],r={x:e.end.x-n.x*Vo,y:e.end.y-n.y*Vo},i=n.x===0?{x:r.x+Ho,y:r.y}:{x:r.x,y:r.y+Ho};return{text:String(e.number),at:$o(i,t),size:.1,anchor:`center`,color:H().pinNumber,mono:!0,kind:`pin-number`}})}function ds(e,t,n,r,i){e.save(),e.translate(n.x,n.y),n.rotation&&e.rotate(qo(n.rotation)),e.strokeStyle=r,e.fillStyle=r;for(let a of t)a.type===`text`?i.push(ms(a,n,r)):a.type===`polyline`&&a.bus?fs(e,a):ps(e,a);e.restore()}function fs(e,t){let[n,r]=[e.strokeStyle,e.fillStyle];e.strokeStyle=H().bus,e.fillStyle=H().bus,es(e,t.points),e.closePath(),e.fill(),e.stroke(),e.strokeStyle=n,e.fillStyle=r}function ps(e,t){if(t.type===`polyline`)es(e,t.points),(t.closed||t.fill)&&e.closePath(),t.fill&&e.fill(),e.stroke();else if(t.type===`circle`)ts(e,t.center,t.radius),t.fill&&e.fill(),e.stroke();else{let n=t.end<t.start?t.end+360:t.end;e.beginPath(),e.arc(t.center.x,t.center.y,t.radius,qo(t.start),qo(n)),e.stroke()}}function ms(e,t,n){let r=e.anchor===`left`?1:e.anchor===`right`?-1:0,i=qo(t.rotation),a=r*Math.cos(i),o=r*Math.sin(i),s=Math.abs(a)>.5?a>0?`left`:`right`:Math.abs(o)>.5?o>0?`bottom`:`top`:`center`,c={role:e.role,kind:Wo[e.role],...e.role===`pin-name`?{pinOf:hs(e,t)}:{},...e.role===`reference`?{strong:!0}:{},...e.role===`pin-number`?{mono:!0}:{}};return{text:e.text,at:$o(e.at,t),size:e.size,anchor:s,color:H()[Go[e.role]]??n,...c}}function hs(e,t){let n=e.anchor===`left`?`left`:e.anchor===`right`?`right`:e.at.y>0?`top`:`bottom`;return{symbol:``,local:e.at,side:n,quarter:Math.abs(Math.sin(qo(t.rotation)))>.5}}function gs(e,t){let n=t.movingLabels?.find(t=>t.id===e.id);return n?{...e,at:n.at,side:n.side}:e}function _s(e,t,n,r,i,a){e.setLineDash(i?Bo:[]),e.globalAlpha=a.alpha,vs(e,t,n,r,a),e.globalAlpha=1,e.setLineDash([])}function vs(e,t,n,r,i){if(t.style!==`label`){let a=t.style===`ground`?kt():At(t.text);e.lineWidth=n(Mo);let o=r.length;ds(e,a,{x:t.at.x,y:t.at.y,rotation:0},i.color??H().flag,r);for(let e=o;e<r.length;e++)r[e]={...r[e],strong:!0,kind:`name`,color:i.color??H().netName,alpha:i.alpha};return}let{middle:a,upright:o,box:s}=Ft(t);r.push({text:t.text,at:a,size:jt,anchor:`center`,strong:!0,kind:`name`,color:i.color??H().netName,rotation:o?90:0,alpha:i.alpha}),t.port&&ys(e,t,s,n,i)}function ys(e,t,n,r,i){e.strokeStyle=i.color??H().netName,e.lineWidth=r(t.bus?Mo*3:Mo),e.beginPath(),e.moveTo(n.minX,n.minY),e.lineTo(n.maxX,n.minY),e.lineTo(n.maxX,n.maxY),e.lineTo(n.minX,n.maxY),e.closePath(),e.stroke()}function bs(e,t,n,r,i){for(let a of t.symbols){let t=i(a);for(let[i,o]of Object.entries(a.pinEnds)){let a=n.highlight?.pins?.includes(i)??!1,s=(n.activePins?.includes(i)??!1)||a;if(!s&&!n.showPins)continue;e.fillStyle=s?H().highlight:H().pin;let c=a?Math.min(Po*r,Math.max(Fo,Io*r)):(s?Lo:1)*Po*r;ts(e,{x:o.x+t.x,y:o.y+t.y},c),e.fill()}}}var xs=2;function Ss(e,t){return Math.max(e,Jo(t)/2+xs)}var Cs=e=>Ss(6,e);function ws(e,t,n){let r=n.x-t.x,i=n.y-t.y,a=r*r+i*i,o=a===0?0:Math.max(0,Math.min(1,((e.x-t.x)*r+(e.y-t.y)*i)/a));return Math.hypot(e.x-(t.x+o*r),e.y-(t.y+o*i))}function Ts(e,t){let n;for(let r=1;r<e.length;r++){let i=ws(t,e[r-1],e[r]);(!n||i<n.distance)&&(n={index:r-1,distance:i})}return n}function Es(e,t,n){let r=Ts(e,t);return r&&r.distance<=n?r.index:void 0}function Ds(e,t,n){let r;for(let i of e){let e=Ts(i.points,t);e&&e.distance<=n&&(!r||e.distance<r.distance)&&(r={id:i.id,distance:e.distance})}return r?.id}function Os(e){return e.length<2?{corners:[],ends:[...e]}:{corners:e.slice(1,-1),ends:[e[0],e[e.length-1]]}}function ks(e,t,n){let r=e.findIndex((r,i)=>i>0&&i<e.length-1&&Math.abs(r.x-t.x)<=n&&Math.abs(r.y-t.y)<=n);return r<0?void 0:r}var As=1e-9,js={x:0,y:0},Ms=(e,t)=>Math.abs(e-t)<As;function Ns(e,t){return Ms(e.y,t.y)?`horizontal`:Ms(e.x,t.x)?`vertical`:`slanted`}function Ps(e,t){return e===`horizontal`?{x:0,y:t.y}:e===`vertical`?{x:t.x,y:0}:t}function Fs(e,t){return e===`horizontal`?Ms(t.y,0):e!==`vertical`||Ms(t.x,0)}function Is(e,t){return e.map((e,n)=>{let r=[t.get(n-1),t.get(n)].filter(e=>e!==void 0);return{x:r.find(e=>!Ms(e.x,0))?.x??0,y:r.find(e=>!Ms(e.y,0))?.y??0}})}function Ls(e,t,n,r){if(t===0||t===e.length-1)return!0;let i=r.has(t)?t-1:t,[a,o]=[e[i],e[i+1]];return a!==void 0&&o!==void 0&&!Fs(Ns(a,o),n)}function Rs(e,t){let n=Is(e,t);return Cn(e.flatMap((r,i)=>{let a=n[i]??js,o={x:r.x+a.x,y:r.y+a.y},s=t.has(i-1);return s===t.has(i)||!Ls(e,i,a,t)?[o]:s?[o,r]:[r,o]}))}function zs(e,t,n){let[r,i]=[e[t],e[t+1]];return!r||!i?Cn(e):Rs(e,new Map([[t,Ps(Ns(r,i),n)]]))}function Bs(e,t,n){let[r,i,a]=[e[t-1],e[t],e[t+1]];if(!r||!i||!a)return Cn(e);let o={x:n.x-i.x,y:n.y-i.y};return Rs(e,new Map([[t-1,Ps(Ns(r,i),o)],[t,Ps(Ns(i,a),o)]]))}var Vs=(e,t)=>({x:e.x+t.x,y:e.y+t.y});function Hs(e,t,n){let[r,i,a,o]=[e[0],e[1],e[e.length-2],e[e.length-1]];if(!r||!i||!a||!o)return Cn(e);let s=n.start?[Vs(r,t)]:[r,Vs(r,Ps(Ns(r,i),t))],c=n.end?[Vs(o,t)]:[Vs(o,Ps(Ns(a,o),t)),o];return Cn([...s,...e.slice(1,-1).map(e=>Vs(e,t)),...c])}function Us(e,t){let[n,r]=[e[t-1],e[t]];if(!n||!r||t>=e.length-1)return Cn(e);let i=e.slice(0,-2).map(()=>!1);return i[t-1]=Ns(n,r)===`horizontal`,Cn(Sn(e.filter((e,n)=>n!==t),i))}var Ws=Cn,Gs=`The pin of this wire has several traces to its net; change its corners in the code`,Ks=1e-6;function qs(e,t){return e.slice(1).some((n,r)=>{let i=e[r],a=(n.x-i.x)*(t.y-i.y)-(n.y-i.y)*(t.x-i.x),o=Math.min(i.x,n.x)-Ks<=t.x&&t.x<=Math.max(i.x,n.x)+Ks&&Math.min(i.y,n.y)-Ks<=t.y&&t.y<=Math.max(i.y,n.y)+Ks;return Math.abs(a)<=Ks&&o})}function Js(e,t,n,r){return e.schematic.wires.some(e=>e.id!==t&&e.net===n&&qs(e.points,r))}function Ys(e,t,n,r){let i=fr(e,t,{pin:n.id},{net:gr(e,r)}),[a]=i;if(!a)return{};if(i.length>1||a.props.schematicRouteHints)return{blocked:Gs};let o=mr(a)??_r(t,a);return o===void 0?{trace:a}:{blocked:o}}function Xs(e,t,n,r){let i=(e.pinLast?[...r].reverse():[...r]).slice(1),{trace:a}=e;if(!a)return[{kind:`addTrace`,from:t,to:n,schematicRouteHints:i}];let o=(a.from??``).startsWith(`net.`);return[{kind:`setTraceHints`,from:a.from??``,to:a.to??``,schematicRouteHints:o?[...i].reverse():i}]}var Zs=/^wire:.+:\d+$/,Qs=e=>e.startsWith(`net.`),$s=(e,t)=>e.x===t.x&&e.y===t.y,ec=(e,t)=>e.circuit.components.flatMap(e=>e.pins).find(e=>e.id===t);function tc(e,t,n){return{id:e,points:t,fixed:{start:!0,end:!0},writer:n}}function nc(e,t,n){let r=t=>Qs(t)?{net:gr(e,t)}:{pin:t};return pr(fr(e,t,r(n.from),r(n.to)).filter(t=>dr(e,t.from,r(n.from))),n.id)}function rc(e,t,n,r,i){let a=nc(e,t,i);if(!a)return tc(n,r,{kind:`none`,reason:`The wire is not written in a trace the Studio can find`});let o=[i.from,i.to].filter(e=>!Qs(e)),s=o.map(t=>ec(e,t)?.component??``),c=o.length===1,l=_r(t,a);return tc(n,r,{kind:`trace`,trace:a,toNet:c,reversed:c&&Qs(i.from),components:s,...l?{repeat:l}:{}})}function ic(e,t,n){let r=t.find(t=>e.schematic.symbols.some(e=>e.pinEnds[t]!==void 0&&$s(e.pinEnds[t],n)));return r===void 0?void 0:ec(e,r)}var ac=(e,t)=>{let n=t.find(t=>!ar(jn(e,t)));return n?{unaddressable:`${n.id} has a repeated name and cannot be wired from the Studio`}:{}};function oc(e,t,n,r,i,a,o){let s=e.circuit.nets.find(e=>e.id===o)?.names[0],c=a?r[0]:r[r.length-1];if(s===void 0||!c||!Js(e,n,o,c))return;let l={pinLast:a,...Ys(e,t,i,o)};return tc(n,r,{kind:`engine`,from:jn(e,i),to:`net.${s}`,components:[i.component],...ac(e,[i]),onWire:l})}function sc(e,t,n,r,i){let a=e.circuit.nets.find(e=>e.id===i),[o,s]=[r[0],r[r.length-1]],[c,l]=o&&s&&a?[ic(e,a.pins,o),ic(e,a.pins,s)]:[];return(c&&!l?oc(e,t,n,r,c,!1,i):!c&&l?oc(e,t,n,r,l,!0,i):void 0)||(!c||!l?tc(n,r,{kind:`none`,reason:`The pins of this wire are not on the sheet`}):tc(n,r,{kind:`engine`,from:jn(e,c),to:jn(e,l),components:[c.component,l.component],...ac(e,[c,l])}))}function cc(e,t,n){let r=e.schematic.wires.find(e=>e.id===n);if(!r)return;let i=r.points.map(e=>({x:e.x,y:e.y})),a=e.circuit.connections.find(e=>e.id===r.connection);return a?rc(e,t,r.id,i,a):Zs.test(r.id)?sc(e,t,r.id,i,r.net):tc(r.id,i,{kind:`none`,reason:`This wire is not drawn from the code`})}function lc(e,t,n=ur){let{writer:r}=t;if(r.kind===`none`)return r.reason;let i=hr(e,r.components,r.kind===`trace`?r.trace:void 0,n);return i===void 0?r.kind===`engine`?r.unaddressable??r.onWire?.blocked??null:r.repeat??mr(r.trace)??null:`${i} is locked`}function uc(e,t){let n=e.slice(1,t.toNet?void 0:-1);return t.reversed?[...n].reverse():n}function dc(e,t){let[n,r]=[e[0],e[e.length-1]],[i,a]=[t.points[0],t.points[t.points.length-1]];return n!==void 0&&r!==void 0&&i!==void 0&&a!==void 0&&$s(n,i)&&$s(r,a)}var fc=(e,t)=>e.length===t.length&&e.every((e,n)=>$s(e,t[n]));function pc(e,t,n,r=ur,i=t.points){let a=lc(e,t,r);if(a!==null)return{blocked:a};let o=Ws(n);if(!dc(o,t))return{blocked:`The ends of a wire stay on their pins`};if(fc(o,Ws(i)))return[];let{writer:s}=t;if(s.kind===`trace`)return[{kind:`setTraceHints`,from:s.trace.from??``,to:s.trace.to??``,schematicRouteHints:uc(o,s)}];if(s.kind!==`engine`)return[];if(s.onWire)return Xs(s.onWire,s.from,s.to,o);let c=o.slice(1,-1);return[{kind:`addTrace`,from:s.from,to:s.to,...c.length>0?{schematicRouteHints:c}:{}}]}var mc=e=>({hover:e.hover,selected:e.selection,handleFill:e.handleFill});mc(la);var hc=3,gc=e=>Ss(hc,e),_c=[4,3],vc=(e,t)=>{let n=Math.hypot(t.x-e.x,t.y-e.y);return{x:(t.x-e.x)/n,y:(t.y-e.y)/n}},yc=e=>({x:-e.y,y:e.x}),bc=(e,t,n)=>({x:e.x+t.x*n,y:e.y+t.y*n});function xc(e,t,n,r,i){let a=e[n];if(n===0)return bc(bc(a,t[0],-r),yc(t[0]),r*i);if(n===e.length-1)return bc(bc(a,t[n-1],r),yc(t[n-1]),r*i);let[o,s]=[yc(t[n-1]),yc(t[n])],c=o.x*s.x+o.y*s.y;return bc(a,1+c<.1?o:{x:(o.x+s.x)/(1+c),y:(o.y+s.y)/(1+c)},r*i)}function Sc(e,t){let n=e.filter((t,n)=>n===0||t.x!==e[n-1]?.x||t.y!==e[n-1]?.y);if(n.length<2)return[];let r=n.slice(1).map((e,t)=>vc(n[t],e)),i=e=>n.map((i,a)=>xc(n,r,a,t,e));return[...i(1),...i(-1).reverse()]}function Cc(e,t,n,r,i,a){let o=Sc(r.map(e=>fe(t,n,e)),gc(t.scale));o.length!==0&&(e.save(),e.strokeStyle=i.hover,e.lineWidth=wa(a),e.setLineDash(_c),e.beginPath(),o.forEach((t,n)=>n===0?e.moveTo(t.x,t.y):e.lineTo(t.x,t.y)),e.closePath(),e.stroke(),e.restore())}function wc(e,t,n,r,i,a){let{corners:o,ends:s}=Os(r),c=Da(6,a),l=wa(a),u=(r,i)=>{let o=fe(t,n,r),[s,u]=[Ea(o.x-c/2,a),Ea(o.y-c/2,a)];i&&e.fillRect(s,u,c,c),e.strokeRect(s+l/2,u+l/2,c-l,c-l)};e.save(),e.fillStyle=i.handleFill,e.strokeStyle=i.selected,e.lineWidth=l,e.setLineDash([]);for(let e of o)u(e,!0);for(let e of s)u(e,!1);e.restore()}var Tc=e=>3/e,Ec=e=>Cs(e)/e;function Dc(e,t,n,r){let i=t===void 0?void 0:e?.points(t),a=i?ks(i,n,Tc(r)):void 0;return t===void 0||a===void 0?void 0:{id:t,index:a}}function Oc(e,t,n,r){let i=t.selection.soleWire;if(i!==void 0&&Si({kind:`wire`,id:i},t))return Dc(e,i,n,r)}function kc(e,t,n,r){if(r!==void 0)return{kind:`corner`,index:r};let i=Es(e,t,Ec(n));return i===void 0?void 0:{kind:`segment`,index:i}}function Ac(e,t,n,r){let i=e[t.index];if(!i)return Ws(e);let a={x:ve(i.x+n.x,r.step,r.snap),y:ve(i.y+n.y,r.step,r.snap)};return t.kind===`corner`?Bs(e,t.index,a):zs(e,t.index,{x:a.x-i.x,y:a.y-i.y})}function jc(e,t,n,r){let i=e?.points(t);if(e&&i)return{kind:`reshape`,wire:t,grip:n,points:i,path:i,start:r,moved:!1,blocker:e.blocker(t)}}function Mc(e,t,n,r){return e.blocker?(e.moved||r(e.blocker),{...e,moved:!0}):{...e,moved:!0,path:Ac(e.points,e.grip,t,n)}}var Nc=`The wire changed while you dragged it; try again`;function Pc(e,t,n){if(!e||!t.moved||t.blocker||fc(t.path,Ws(t.points)))return;let r=e.points(t.wire);if(!r||!fc(r,t.points))return n(Nc);e.commit(t.wire,t.path)}function Fc(e,t){return!e?.moved||e.blocker?t:[{id:e.wire,points:e.path},...t.filter(t=>t.id!==e.wire)]}function Ic(e,t){return t.length===0?e:e.map(e=>{let n=t.find(t=>t.id===e.id);return n?{...e,points:[...n.points]}:e})}var Lc=e=>e.missingLayer===void 0?{}:{missingLayer:e.missingLayer};function Rc(e,t){return e.missingLayer===void 0?e.kind===`via`?t.multiLayer:(e.layer===`top`||e.layer===`bottom`)&&t[e.layer]:t.keepout}var zc=2,Bc=(e,t)=>Math.max(6,e*t/2+zc)/t;function Vc(e,t,n,r,i){let a=e.find(e=>Rc({kind:`via`,...Lc(e)},r)&&Si({kind:`via`,id:e.id},i)&&Math.hypot(t.x-e.at.x,t.y-e.at.y)<=Bc(e.diameter,n));return a&&{kind:`via`,id:a.id}}function Hc(e,t){let n=1/0;for(let r=1;r<e.length;r++)n=Math.min(n,ws(t,e[r-1],e[r]));return n}function Uc(e,t,n,r,i){let a;for(let o of e){if(!Rc({kind:`track`,layer:o.layer,...Lc(o)},r)||!Si({kind:`track`,id:o.id},i))continue;let e=Hc(o.points,t);e<=Bc(o.width,n)&&(!a||e<a.distance)&&(a={id:o.id,distance:e})}return a&&{kind:`track`,id:a.id}}function Wc(e,t,n,r,i){return Vc(e.vias,t,n,r,i)??Uc(e.tracks,t,n,r,i)}function Gc(e,t,n,r,i){let a=Wc(e,t,n,r,i),o=a?.kind===`track`?e.tracks.find(e=>e.id===a.id):void 0,s=o&&Es(o.points,t,Bc(o.width,n));return o&&s!==void 0?Ki(o,s):void 0}function Kc(e,t,n,r,i=0){let a=r?ks(e,t,Tc(n)):void 0;if(a!==void 0)return{kind:`corner`,index:a};let o=Es(e,t,Bc(i,n));return o===void 0?void 0:{kind:`segment`,index:o}}var qc=(e,t)=>{let n=e.map(e=>e.x),r=e.map(e=>e.y),i=e=>z(e);return{minX:i(Math.min(...n)-t),minY:i(Math.min(...r)-t),maxX:i(Math.max(...n)+t),maxY:i(Math.max(...r)+t)}};function Jc(e,t){let n=e.tracks.filter(e=>Rc({kind:`track`,layer:e.layer,...Lc(e)},t)),r=e.vias.filter(e=>Rc({kind:`via`,...Lc(e)},t));return[...n.map(e=>({kind:`track`,id:e.id,box:qc(e.points,e.width/2)})),...r.map(e=>({kind:`via`,id:e.id,box:qc([e.at],e.diameter/2)}))]}function Yc(e,t,n,r){let i=new Set(Ni(e,t,n,r));return e.filter(e=>i.has(e.id)).map(({kind:e,id:t})=>({kind:e,id:t}))}var Xc=.4,Zc=.7,Qc=1.5,$c={top:B.topCopper,bottom:B.bottomCopper,inner1:B.topCopper,inner2:B.topCopper},el=e=>e.missingLayer===void 0?$c[e.layer]:B.keepout,tl=e=>e.missingLayer===void 0?B.viaRing:B.keepout,nl=(e,t)=>Rc({kind:`track`,layer:e.layer,...Lc(e)},t),rl=(e,t)=>Rc({kind:`via`,...Lc(e)},t),il=(e,t)=>e&&(t===void 0||!e.nets.includes(t))?Qr:1;function al(e,t,n,r){e.strokeStyle=n,e.lineWidth=r,e.beginPath(),t.forEach((t,n)=>n===0?e.moveTo(t.x,t.y):e.lineTo(t.x,t.y)),e.stroke()}function ol(e,t,n,r){e.fillStyle=r,e.beginPath(),e.arc(t.x,t.y,Math.max(n,0),0,Math.PI*2),e.fill()}function sl(e,t,n,r){let i=t.activeLayer??`top`,a=t.tracks.filter(e=>nl(e,n)),o=e=>e.layer===i||e.missingLayer!==void 0,s=[...a.filter(e=>!o(e)),...a.filter(o)];for(let t of s)e.globalAlpha=(o(t)?1:Xc)*il(r,t.net),al(e,t.points,el(t),t.width);e.globalAlpha=1}function cl(e,t,n,r){for(let i of t.vias.filter(e=>rl(e,n)))e.globalAlpha=il(r,i.net),ol(e,i.at,i.diameter/2,tl(i)),n.hole&&ol(e,i.at,i.drill/2,B.drill);e.globalAlpha=1}function ll(e,t,n){for(let{drawing:r,alpha:i}of t.routes??[]){e.globalAlpha=i;for(let t of r.tracks)Rc({kind:`track`,layer:t.layer},n)&&al(e,t.points,$c[t.layer],t.width);if(Rc({kind:`via`},n))for(let t of r.vias)ol(e,t.at,t.diameter/2,B.viaRing),n.hole&&ol(e,t.at,t.drill/2,B.drill)}e.globalAlpha=1}function ul(e,t,n){let{segment:r}=e;return n&&r?.id===t.id&&qi(r,t.points)?[r.from,r.to]:t.points}function dl(e,t,n,r,i,a,o){let s=t.tracks.find(e=>e.id===r);if(s&&nl(s,n)){let n=ul(t,s,a);al(e,n,i,s.width+2*Qc*o),al(e,n,el(s),s.width),a&&al(e,n,B.selectionFill,s.width);return}let c=t.vias.find(e=>e.id===r);c&&rl(c,n)&&(ol(e,c.at,c.diameter/2+Qc*o,i),ol(e,c.at,c.diameter/2,tl(c)),a&&ol(e,c.at,c.diameter/2,B.selectionFill),n.hole&&ol(e,c.at,c.drill/2,B.drill))}function fl(e,t,n,r,i){sl(e,t,n,r),cl(e,t,n,r),ll(e,t,n),t.hover!==void 0&&!t.selected.has(t.hover)&&dl(e,t,n,t.hover,B.hover,!1,i);for(let r of t.selected)dl(e,t,n,r,B.selection,!0,i)}var pl=e=>e.pcb.board?.pours??[];function ml(e,t){return e.outline??t?.outline??[]}function hl(e,t){return e.circuit.nets.find(e=>e.id===t)?.names[0]??t}var gl=(e,t)=>`pour ${hl(e,t.net)} · ${t.layer}`,_l=e=>`${Number(e.toFixed(4))} mm`,vl=e=>`hole ${_l(e.diameter)}`;function yl(e,t,n){return n.has(e.id)?!1:e.layer===`top`||e.layer===`bottom`?t[e.layer]:e.layer===`inner1`||e.layer===`inner2`}function bl(e){return e.map((t,n)=>[t,e[(n+1)%e.length]])}function xl(e,t,n,r,i){let a=6/n,o;for(let n of pl(e))if(yl(n,r,i))for(let[r,i]of bl(ml(n,e.pcb.board))){let e=ws(t,r,i);e<=a&&(!o||e<o.distance)&&(o={id:n.id,distance:e})}return o?.id}function Sl(e,t,n){let r=7/n,i=e.findIndex(e=>Math.hypot(e.x-t.x,e.y-t.y)<=r);return i===-1?void 0:i}function Cl(e,t,n,r){if(!r.hole)return;let i=3/n;return e.find(e=>Math.hypot(e.x-t.x,e.y-t.y)<=e.diameter/2+i)?.id}function wl(e,t){let n=!1;for(let[r,i]of bl(t))r.y>e.y!=i.y>e.y&&e.x<(i.x-r.x)*(e.y-r.y)/(i.y-r.y)+r.x&&(n=!n);return n}function Tl(e,t){return e.polygons.some(e=>wl(t,e.outer)&&!e.holes.some(e=>wl(t,e)))}function El(e,t,n,r,i){let a=e.pcb.pours.filter(e=>yl(e,n,r));return[...a.filter(e=>e.layer===i),...a.filter(e=>e.layer!==i)].find(e=>Tl(e,t))?.id}function Dl(e,t){let n=e.pcb.holes.find(e=>e.id===t);if(n)return{x:n.x,y:n.y};let r=pl(e).find(e=>e.id===t),i=r?ml(r,e.pcb.board):[];if(i.length===0)return;let a=i.map(e=>e.x),o=i.map(e=>e.y);return{x:(Math.min(...a)+Math.max(...a))/2,y:(Math.min(...o)+Math.max(...o))/2}}var Ol=[`solid`,`hatched`,`outline`],kl=`solid`,Al=`copperflow.pourFill`,jl=.35,W=e=>Ol.includes(e);function G(e){try{let t=e()?.getItem(Al);return W(t)?t:kl}catch{return kl}}function Ml(e,t){try{let n=e();return n?(n.setItem(Al,t),!0):!1}catch{return!1}}function Nl(e){return{pourSolid:e===`solid`,pourHatched:e===`hatched`,pourOutline:e===`outline`}}var Pl={pourSolid:`solid`,pourHatched:`hatched`,pourOutline:`outline`},Fl={top:B.topCopper,bottom:B.bottomCopper,inner1:B.inner1Copper,inner2:B.inner2Copper},Il=Fl,Ll=.5,Rl=6,zl=1,Bl=1.5;function Vl(e,t){t.forEach((t,n)=>n===0?e.moveTo(t.x,t.y):e.lineTo(t.x,t.y)),e.closePath()}function Hl(e,t){Gl()&&e instanceof Path2D||e.beginPath();for(let n of t.polygons){Vl(e,n.outer);for(let t of n.holes)Vl(e,t)}}function Ul(e,t=0){let n=e.polygons.flatMap(e=>e.outer);if(n.length===0)return[];let r=n.map(e=>e.x),i=n.map(e=>e.y),[a,o,s,c]=[Math.min(...r),Math.max(...r),Math.min(...i),Math.max(...i)],l=c-s,u=a-l,d=o-u,f=Math.max(Ll,6*t,d/399),p=Math.floor(d/f+1e-9)+1;return Array.from({length:p},(e,t)=>[{x:u+t*f,y:s},{x:u+t*f+l,y:c}])}var Wl=new WeakMap,Gl=()=>typeof Path2D==`function`;function Kl(e){let t=Wl.get(e);if(t)return t;let n={};return Wl.set(e,n),n}function ql(e){if(!Gl())return;let t=Kl(e);return t.rings||(t.rings=new Path2D,Hl(t.rings,e)),t.rings}function Jl(e,t){if(!Gl())return;let n=Kl(e);if(n.hatch?.px!==t){let r=new Path2D;for(let[n,i]of Ul(e,t))r.moveTo(n.x,n.y),r.lineTo(i.x,i.y);n.hatch={px:t,path:r}}return n.hatch.path}function Yl(e,t,n){e.lineWidth=n;let r=ql(t);if(r)return e.stroke(r);Hl(e,t),e.stroke()}function Xl(e,t,n){let r=ql(t);if(r)return n===`fill`?e.fill(r,`evenodd`):e.clip(r,`evenodd`);Hl(e,t),n===`fill`?e.fill(`evenodd`):e.clip(`evenodd`)}function Zl(e,t,n){let r=Jl(t,n);if(r)return e.stroke(r);e.beginPath();for(let[r,i]of Ul(t,n))e.moveTo(r.x,r.y),e.lineTo(i.x,i.y);e.stroke()}function Ql(e,t,n,r){let i=Il[t.layer]??B.topCopper;if(e.fillStyle=i,e.strokeStyle=i,n===`outline`)e.globalAlpha=1,Yl(e,t,zl*r);else{if(e.globalAlpha=jl,n===`solid`)return Xl(e,t,`fill`);e.save(),Xl(e,t,`clip`),e.lineWidth=zl*r,e.globalAlpha=1,Zl(e,t,r),e.restore(),e.globalAlpha=1,Yl(e,t,zl*r)}}function $l(e,t,n,r,i){let a=(t.pours??[]).filter(e=>yl(e,r,n.hidden)),o=[...a.filter(e=>e.layer!==n.activeLayer),...a.filter(e=>e.layer===n.activeLayer)];for(let t of o)Ql(e,t,n.mode,i);e.globalAlpha=1}function eu(e,t,n){let r=n/2;e.beginPath(),e.moveTo(t.x-r,t.y-r),e.lineTo(t.x+r,t.y-r),e.lineTo(t.x+r,t.y+r),e.lineTo(t.x-r,t.y+r),e.closePath()}function tu(e,t,n,r){if(e.strokeStyle=B.selection,e.lineWidth=Bl*r,e.beginPath(),Vl(e,t),e.stroke(),n){e.fillStyle=B.selection;for(let n of t)eu(e,n,Rl*r),e.fill()}}function nu(e,t,n,r,i,a){if(r.selected.has(t.id))return tu(e,n,t.outline!==void 0,i);let o=r.hover===t.id;(o||t.outline!==void 0)&&(e.strokeStyle=o?B.hover:Il[t.layer]??B.topCopper,e.lineWidth=Math.max(a,zl*i),e.setLineDash([4*i,3*i]),e.beginPath(),Vl(e,n),e.stroke(),e.setLineDash([]))}function ru(e,t,n){t.length<2||(e.strokeStyle=B.selection,e.lineWidth=zl*n,e.setLineDash([4*n,3*n]),e.beginPath(),Vl(e,t),e.stroke(),e.setLineDash([]))}function iu(e,t,n,r,i,a){for(let o of t.board?.pours??[])yl(o,r,n.hidden)&&nu(e,o,n.outlines?.get(o.id)??ml(o,t.board),n,i,a);n.preview&&ru(e,n.preview,i)}function au(e,t,n,r,i,a){if(r.hole)for(let r of t){let t=r.diameter/2;e.fillStyle=B.drill,e.beginPath(),e.arc(r.x,r.y,t,0,Math.PI*2),e.fill();let o=n.selected.has(r.id);e.strokeStyle=o?B.selection:n.hover===r.id?B.hover:B.multiLayer,e.lineWidth=o?Bl*i:a,e.stroke()}}var K=(e,t=!1)=>({action:e,preventDefault:t}),ou=new Map([[`ArrowLeft`,{action:`nudgeLeft`,dx:-1,dy:0}],[`ArrowRight`,{action:`nudgeRight`,dx:1,dy:0}],[`ArrowUp`,{action:`nudgeUp`,dx:0,dy:1}],[`ArrowDown`,{action:`nudgeDown`,dx:0,dy:-1}]]);function su(e){for(let t of ou.values())if(t.action===e)return{dx:t.dx,dy:t.dy}}function cu(e){let t=ou.get(e.key);return!t||e.onButton||e.ctrlKey||e.metaKey||e.altKey?null:{action:t.action,preventDefault:!0,steps:e.shiftKey?10:1}}var lu=`tr, [role='row'], [role='gridcell'], [role='grid'], [role='listbox'], [role='option'], [role='tree'], [role='treeitem'], [role='tablist'], [role='tab'], [role='radiogroup'], [role='menu'], [role='menubar'], [role='menuitem'], [role='menuitemcheckbox'], [data-keys='own']`,uu=`input:not([type='checkbox']):not([type='radio']), textarea, select, [contenteditable='true']`,du=`button, a[href], summary, input[type='checkbox'], input[type='radio']`,fu=`[data-keys='parts']`;function pu(e){let t=e.target instanceof HTMLElement?e.target:null;return{key:e.key,code:e.code,shiftKey:e.shiftKey,altKey:e.altKey,ctrlKey:e.ctrlKey,metaKey:e.metaKey,altGraph:e.getModifierState?.(`AltGraph`)??!1,typing:t?.closest(uu)!=null,onButton:t?.closest(du)!=null,ownsKeys:t?.closest(lu)!=null,partRows:t?.closest(fu)!=null,handled:e.defaultPrevented}}var mu=e=>e.code?.startsWith(`Key`)?e.code.slice(3).toLowerCase():e.key.toLowerCase(),hu=new Map([[`w`,`wire`],[`n`,`armNetLabel`],[`b`,`drawBus`],[`l`,`drawPolyline`],[`r`,`drawRectangle`],[`c`,`drawCircle`],[`a`,`drawArc`],[`t`,`drawText`],[`j`,`junction`]]),gu=new Map([[`w`,`route`],[`v`,`placeVia`]]);function _u(e,t){if(e.shiftKey)return null;let n=mu(e);if(n===`s`)return K(`toggleSnap`,!0);let r=(t.view===`schematic`?hu:gu).get(n);return r?K(r,!0):null}function vu(e,t,n){switch(e){case`w`:return K(n.view===`schematic`?`wire`:`route`);case`v`:return n.view===`pcb`?K(`switchLayer`,!0):null;case`r`:return K(`rotate`);case`k`:return K(`fit`);case`f`:return t.shiftKey?K(`openLibrary`,!0):K(`fit`);case`h`:return t.shiftKey?K(`clearHighlight`):K(`highlight`);case`q`:return n.view===`pcb`?K(`toggleUnit`):null;case`u`:return n.view===`pcb`?K(t.shiftKey?`straightenTracks`:`filletTracks`,!0):null;case`l`:return n.view===`pcb`&&!t.shiftKey?K(`routingCorner`,!0):null;case`x`:return n.view===`pcb`&&!t.shiftKey?K(`flip`,!0):null;default:return null}}var yu=new Map([[`[`,`toggleLeftPanel`],[`]`,`toggleRightPanel`],[`\\`,`toggleBottomPanel`]]),bu=e=>!e.metaKey&&(e.altGraph===!0||e.ctrlKey&&e.altKey||!e.ctrlKey&&!e.altKey),xu=new Map([[`z`,`undo`],[`y`,`redo`],[`o`,`openFile`],[`a`,`selectAll`],[`f`,`find`],[`c`,`copy`],[`v`,`paste`]]),Su=new Map([[`z`,`redo`],[`l`,`alignLeft`],[`h`,`distributeH`],[`f`,`findSimilar`],[`x`,`placementTransfer`]]);function Cu(e){if(e.altKey||e.altGraph)return null;let t=(e.shiftKey?Su:xu).get(e.key.toLowerCase());return t?K(t,t!==`copy`):null}function wu(e,t){return t.drawing?e.key===`Backspace`&&!e.ownsKeys?K(`removeCorner`,!0):null:K(`delete`)}var Tu=e=>e.key===`Delete`||e.key===`Backspace`,Eu=e=>e.ownsKeys===!0&&!(e.partRows===!0&&Tu(e)),Du=e=>e.key===`ContextMenu`||e.key===`F10`&&e.shiftKey&&!e.ctrlKey&&!e.altKey&&!e.metaKey;function Ou(e,t){if(e.typing)return null;if(Du(e))return K(`contextMenu`,!0);let n=yu.get(e.key);return n&&bu(e)?K(n):e.ctrlKey||e.metaKey?Cu(e):e.altKey?_u(e,t):e.handled||Eu(e)?null:cu(e)||(e.key===`Enter`?t.drawing&&!e.onButton&&!e.shiftKey?K(`finishShape`,!0):null:Tu(e)?wu(e,t):e.key===` `?e.onButton?null:K(t.drawing?`flipBend`:`rotate`,!0):vu(e.key.toLowerCase(),e,t))}function ku(e){return e.key===`Escape`&&!e.typing}var Au=e=>xt(e)+0,ju=e=>Math.round((e%360+360)%360/90)%4;function Mu(e,t){switch(ju(t)){case 1:return{x:Au(-e.y),y:Au(e.x)};case 2:return{x:Au(-e.x),y:Au(-e.y)};case 3:return{x:Au(e.y),y:Au(-e.x)};default:return{x:Au(e.x),y:Au(e.y)}}}function Nu(e,t){let n=Mu(e,t.rotation);return{x:Au(t.x+n.x),y:Au(t.y+n.y)}}var Pu={reference:`schNameAt`,value:`schValueAt`},Fu=(e,t)=>`${e}:${t}`;function q(e){let t=e.lastIndexOf(`:`);return t>0?{part:e.slice(0,t),prop:e.slice(t+1)}:void 0}function Iu(e,t,n){let r=bt*t*n/2;return{minX:e.x-r,maxX:e.x+r,minY:e.y-t/2,maxY:e.y+t/2}}function Lu(e){return e.symbol.shapes.flatMap(t=>{if(t.type!==`text`||t.role!==`reference`&&t.role!==`value`)return[];let n=Nu(t.at,e),r=Pu[t.role],i={x:Au(n.x-e.x),y:Au(n.y-e.y)};return[{id:Fu(e.component,r),part:e.component,prop:r,text:t.text,at:n,offset:i,box:Iu(n,t.size,t.text.length)}]})}var Ru=.8,zu={schematic:[`schNameAt`,`schValueAt`],pcb:[`pcbNameAt`]},Bu={schNameAt:`Name`,schValueAt:`Value`,pcbNameAt:`Designator`};function Vu(e){let t=q(e)?.prop;if(t!==void 0)return zu.schematic.includes(t)?`schematic`:zu.pcb.includes(t)?`pcb`:void 0}function Hu(e){return e.symbols.flatMap(e=>Lu(e))}function Uu(e){let t=Xr(e),n={x:t.x-e.x,y:t.y-e.y};return{id:Fu(e.component,`pcbNameAt`),part:e.component,prop:`pcbNameAt`,text:e.component,at:t,offset:n,box:Iu(t,Ru,e.component.length)}}function Wu(e){return e.parts.map(Uu)}function Gu(e,t){return e===`pcb`?Wu(t.pcb):Hu(t.schematic)}var Ku=(e,t)=>t.x>=e.minX&&t.x<=e.maxX&&t.y>=e.minY&&t.y<=e.maxY,qu=e=>(e.maxX-e.minX)*(e.maxY-e.minY);function Ju(e,t){return e.filter(e=>Ku(e.box,t)).sort((e,t)=>qu(e.box)-qu(t.box))[0]}function Yu(e,t){let n=t.x-e.at.x,r=t.y-e.at.y,{box:i}=e;return{...e,at:t,offset:{x:e.offset.x+n,y:e.offset.y+r},box:{minX:i.minX+n,maxX:i.maxX+n,minY:i.minY+r,maxY:i.maxY+r}}}function Xu(e,t){return t.length===0?[...e]:e.map(e=>{let n=t.find(t=>t.id===e.id);return n?Yu(e,n.at):e})}function Zu(e,t){let n={x:e.at.x-e.offset.x,y:e.at.y-e.offset.y},r={x:z(t.x-n.x),y:z(t.y-n.y)};return z(e.offset.x)===r.x&&z(e.offset.y)===r.y?[]:[{kind:`setProps`,part:e.part,props:{[e.prop]:r}}]}function Qu(e){let t=q(e);return t?[{kind:`setProps`,part:t.part,props:{[t.prop]:null}}]:[]}function $u(e,t){let n=q(t);return n!==void 0&&e.model.parts.find(e=>e.name===n.part)?.props[n.prop]!==void 0}function ed(e,t,n){let r=q(n),i=r&&e.model.parts.find(e=>e.name===r.part);if(!r||!i)return`This part has no editable source element`;if(t.has(i.name))return`${i.name} is locked`;if(!i.editable)return`${i.name} is read-only (${i.readonlyReason})`;let a=i.props[r.prop];return a&&!a.editable?`${i.name}.${r.prop} is an expression; change it in the code`:null}function td(e,t,n,r){let i=od(e,t,n,r);return i?i.blocker??(i.moved?null:`It is where the layout puts it`):`It is not on this sheet`}function nd(e,t,n){let r=t===`schNameAt`?`reference`:t===`schValueAt`?`value`:void 0,i=Mu({x:n.x-e.x,y:n.y-e.y},-e.rotation),a=e.symbol.shapes.map(e=>e.type===`text`&&e.role===r?{...e,at:i,anchor:`center`}:e);return{...e,symbol:{...e.symbol,shapes:a}}}function rd(e,t){if(t.length===0)return e;let n=e.symbols.map(e=>t.reduce((t,n)=>{let r=q(n.id);return r?.part===e.component?nd(t,r.prop,n.at):t},e));return{...e,symbols:n}}function id(e,t){if(t.length===0)return e;let n=e.parts.map(e=>{let n=t.find(t=>t.id===Fu(e.component,`pcbNameAt`));return n?{...e,nameAt:n.at}:e});return{...e,parts:n}}var ad=e=>String(z(e));function od(e,t,n,r){let i=Vu(n),a=i&&Gu(i,e).find(e=>e.id===n);if(!i||!a)return;let o=$u(t,n),s=i===`pcb`?` mm`:``,c=[{label:`Part`,value:a.part},{label:`Text`,value:a.text},{label:`Offset X`,value:`${ad(a.offset.x)}${s}`},{label:`Offset Y`,value:`${ad(a.offset.y)}${s}`},{label:`Position`,value:o?`Moved (${a.prop})`:`Where the layout puts it`}];return{title:Bu[a.prop]??a.prop,rows:c,moved:o,blocker:ed(t,r,n)}}function sd(e,t,n){let r=e.soleText,i=su(t.action);if(r!==void 0&&i)return{id:r,by:ot(i,n.step,t.steps??1,n.snap!==!1)}}var cd={mode:`solid`,hidden:new Set,selected:new Set,activeLayer:`top`},ld={x:0,y:0},ud=1.5,J=.35,dd=1.5,fd=.6,pd=.12,md=1.5,hd=.7,gd=.5,_d=1e-9,vd=.25,yd=.6,bd=e=>e*Math.PI/180,xd=(e,t,n)=>e[`${t.side===`top`?`top`:`bottom`}${n}`],Sd=e=>e.autoPlaced?yd:1,Cd=e=>e.side===`top`?B.topAssembly:B.bottomAssembly;function wd(e,t,n,r){let i={...li,...r.layers},{camera:a,size:o}=n,s=1/a.scale,c=ka(s,r.ratio),l=e=>r.moving?.components.includes(e.component)?r.moving.by:ld,u=n=>{for(let r of t.parts)Od(e,l(r).x,l(r).y,0,()=>{e.globalAlpha=Sd(r),n(r)});e.globalAlpha=1};e.save(),e.setTransform(...Ed(n,r.ratio)),e.lineCap=`round`,e.lineJoin=`round`,i.keepout&&Pd(e,t,s,c);let d=r.pours??cd;$l(e,t,d,i,s),Rd(e,i,r.highlight,u,s),r.copper&&fl(e,r.copper,i,r.highlight,s),i.hole&&Bd(e,u),au(e,t.holes??[],d,i,s,c),iu(e,t,d,i,s,c),u(t=>{xd(i,t,`Silk`)&&Vd(e,t.silkscreen,t.side===`top`?B.topSilk:B.bottomSilk,Math.max(pd,c),!1)}),i.courtyard&&Hd(e,u,s,c),u(t=>{xd(i,t,`Assembly`)&&Vd(e,t.fabrication,Cd(t),c,!1)}),i.boardOutline&&Nd(e,t,()=>{e.strokeStyle=B.boardEdge,e.lineWidth=md*s,e.stroke()}),r.ratsnest!==!1&&i.ratline&&Ud(e,t,r,c),e.setTransform(r.ratio,0,0,r.ratio,0,0),Ba(e);for(let n of t.parts)xd(i,n,`Silk`)&&Gd(e,n,a,o,l(n),r.ratio);oa(e,n,r.violations??[],r.activeViolation,!0),e.restore()}function Y(e,t,n,r){for(let i of e.parts){if(r&&!r(i.component))continue;let e=i.pads.find(e=>(!n||n[pi(e)])&&qd(e,t));if(e)return e}}function Td(e){return e.parts.map(e=>{let t=Dd(e);return{name:e.component,pcbComponentId:e.component,center:{x:(t.minX+t.maxX)/2,y:(t.minY+t.maxY)/2},box:t}})}function Ed({camera:e,size:t},n){let r=e.scale*n;return[r,0,0,-r,(t.width/2-e.cx*e.scale)*n,(t.height/2+e.cy*e.scale)*n]}function Dd(e){let t=e.courtyard.map(e=>e.x),n=e.courtyard.map(e=>e.y);return{minX:Math.min(...t),minY:Math.min(...n),maxX:Math.max(...t),maxY:Math.max(...n)}}function Od(e,t,n,r,i){e.save(),e.translate(t,n),r&&e.rotate(bd(r)),i(),e.restore()}function kd(e,t){e.beginPath(),t.forEach((t,n)=>n===0?e.moveTo(t.x,t.y):e.lineTo(t.x,t.y)),e.closePath()}function Ad(e,t,n,r){e.beginPath(),e.arc(t,n,Math.max(r,0),0,Math.PI*2)}function jd(e,t,n,r){let i=Math.max(0,Math.min(r,t/2,n/2)),a=-t/2,o=-n/2;e.beginPath(),e.moveTo(a+i,o),e.arcTo(a+t,o,a+t,o+n,i),e.arcTo(a+t,o+n,a,o+n,i),e.arcTo(a,o+n,a,o,i),e.arcTo(a,o,a+t,o,i),e.closePath()}var Md=(e,t,n)=>jd(e,t,n,Math.min(t,n)/2);function Nd(e,t,n){let r=t.board?.outline;!r||r.length<3||(kd(e,r),n())}function Pd(e,t,n,r){let i=t.board?.keepouts??[];if(i.length!==0){e.strokeStyle=B.keepout,e.globalAlpha=hd;for(let t of i){e.lineWidth=r,e.setLineDash([4*n,3*n]),kd(e,t.outline),e.stroke(),e.setLineDash([]),e.save(),kd(e,t.outline),e.clip();for(let[n,r]of Fd(t.outline))Wd(e,n,r);e.restore()}e.globalAlpha=1}}function Fd(e){let t=e.map(e=>e.x),n=e.map(e=>e.y),[r,i,a,o]=[Math.min(...t),Math.max(...t),Math.min(...n),Math.max(...n)];if(![r,i,a,o].every(Number.isFinite))return[];let s=o-a,c=r-s,l=i-c,u=Math.max(gd,l/399),d=Math.floor(l/u+_d)+1;return Array.from({length:d},(e,t)=>{let n=c+t*u;return[{x:n,y:a},{x:n+s,y:o}]})}function Id(e,t){Od(e,t.x,t.y,t.rotation,()=>{t.shape===`circle`?Ad(e,0,0,t.width/2):t.shape===`oval`?Md(e,t.width,t.height):jd(e,t.width,t.height,t.shape===`roundrect`?t.cornerRadius??vd*Math.min(t.width,t.height):0)})}function Ld(e){return e.layers===`through`?B.multiLayer:e.layers===`bottom`?B.bottomCopper:B.topCopper}function Rd(e,t,n,r,i){let a=[[t.bottom,e=>e.layers===`bottom`],[t.top,e=>e.layers===`top`],[t.multiLayer,e=>e.layers===`through`]];for(let[t,o]of a)t&&r(t=>{for(let r of t.pads.filter(o)){let a=n!==void 0&&r.net!==void 0&&n.nets.includes(r.net);e.globalAlpha=(n&&!a?Qr:1)*Sd(t),e.fillStyle=Ld(r),Id(e,r),e.fill(),a&&zd(e,r,i,Sd(t))}});e.globalAlpha=1}function zd(e,t,n,r){e.globalAlpha=J*r,e.fillStyle=B.highlight,Id(e,t),e.fill(),e.globalAlpha=r,e.strokeStyle=B.highlight,e.lineWidth=dd*n,e.stroke()}function Bd(e,t){e.fillStyle=B.drill,t(t=>{for(let n of t.pads){let{drill:t}=n;t&&(t.width===t.height?Ad(e,n.x,n.y,t.width/2):Od(e,n.x,n.y,n.rotation,()=>Md(e,t.width,t.height)),e.fill())}})}function Vd(e,t,n,r,i){e.strokeStyle=n,e.lineWidth=r;for(let n of t)n.length<2||(e.beginPath(),n.forEach((t,n)=>n===0?e.moveTo(t.x,t.y):e.lineTo(t.x,t.y)),i&&e.closePath(),e.stroke())}function Hd(e,t,n,r){e.setLineDash([4*n,3*n]),t(t=>{e.globalAlpha=1,Vd(e,[t.courtyard],Cd(t),t.autoPlaced?ud*n:r,!0)}),e.setLineDash([])}function Ud(e,t,n,r){let i=n.moving,a=new Set(t.parts.filter(e=>i?.components.includes(e.component)).flatMap(e=>e.pads.map(e=>e.id))),o=(e,t)=>i&&a.has(t)?{x:e.x+i.by.x,y:e.y+i.by.y}:e;e.lineWidth=r;for(let r of t.ratsnest){let t=n.highlight?.nets.includes(r.net)??!1;e.strokeStyle=t?B.highlight:B.ratsnest,e.globalAlpha=t?1:n.highlight?fd*Qr:fd,Wd(e,o(r.a,r.from),o(r.b,r.to))}e.globalAlpha=1}function Wd(e,t,n){e.beginPath(),e.moveTo(t.x,t.y),e.lineTo(n.x,n.y),e.stroke()}function Gd(e,t,n,r,i,a){let o=Ia(Ru,n.scale,a);if(!Fa(`name`,o,o))return;let s=Xr(t),c=za(fe(n,r,{x:s.x+i.x,y:s.y+i.y}),a);e.fillStyle=t.side===`top`?B.topSilk:B.bottomSilk,e.globalAlpha=Sd(t),e.font=ni(ti.strong,o/a),e.textAlign=`center`,e.textBaseline=`middle`,e.fillText(t.component,c.x,c.y),e.globalAlpha=1}function Kd(e,t,n,r){let i;for(let a of e.parts)for(let e of a.pads){if(r&&!r[pi(e)])continue;let a=Yd(e,t);a<=n&&(!i||a<i.distance)&&(i={pad:e,distance:a})}return i?.pad}var qd=(e,t)=>Yd(e,t)<=0;function Jd(e,t){let n=bd(-e.rotation),r=t.x-e.x,i=t.y-e.y;return{x:r*Math.cos(n)-i*Math.sin(n),y:r*Math.sin(n)+i*Math.cos(n)}}function Yd(e,t){let{x:n,y:r}=Jd(e,t);return e.shape===`circle`?Math.max(0,Math.hypot(n,r)-e.width/2):e.shape===`oval`?Xd(n,r,e.width,e.height):Math.hypot(Math.max(0,Math.abs(n)-e.width/2),Math.max(0,Math.abs(r)-e.height/2))}function Xd(e,t,n,r){let i=Math.min(n,r)/2,a=Math.max(n,r)/2-i,[o,s]=n>=r?[Math.max(-a,Math.min(a,e)),0]:[0,Math.max(-a,Math.min(a,t))];return Math.max(0,Math.hypot(e-o,t-s)-i)}function Zd(e,t,n){let r=Ds(e.schematic.wires,t,n);return e.schematic.wires.find(e=>e.id===r)?.net}function Qd(e,t,n){let r=Hn(e,t,n);if(r)return e.circuit.nets.find(e=>e.pins.includes(r.pin))?.id;let i=wr(e,t)?.net??Zd(e,t,n);return i===void 0?void 0:$d(e.circuit.nets,i)}function $d(e,t){if(e.some(e=>e.id===t))return t;let n=t.startsWith(`net.`)?t.slice(4):void 0;return e.find(e=>n!==void 0&&e.names.includes(n))?.id??t}var ef=[];function tf(e,t){let n=t.flatMap(t=>e.circuit.nets.filter(e=>e.id===t)),r=n[0];if(!r)return;let i=[...new Set(n.flatMap(e=>e.pins))],a=[...new Set(n.flatMap(e=>[e.id,...e.names.map(e=>`net.${e}`)]))];return{net:r.id,pins:i,aliases:a}}function nf(e,t){let n=(e.circuit.components.find(e=>e.id===t)?.pins??[]).flatMap(t=>e.circuit.nets.filter(e=>e.pins.includes(t.id)).map(e=>e.id));return[...new Set(n)]}function rf(e,t){if(e.length===0)return{message:`Point at a net and press H.`};let n=[...new Set(e.flatMap(t))];return n.length>0?{nets:n}:{message:`${et(e)} ${e.length===1?`is`:`are`} on no net.`}}function af(e,t,n,r=()=>void 0){let i=[...new Set([...e.wires.flatMap(e=>t(e)??[]),...e.labels.flatMap(e=>r(e)??[])])],a=rf(e.names,n);return`nets`in a?{nets:[...new Set([...i,...a.nets])]}:i.length>0?{nets:i}:a}function of(e,t,n){if(n.circuit.nets.some(t=>t.id===e))return e;let r=t?.circuit.nets.find(t=>t.id===e)?.pins[0];return r!==void 0&&n.circuit.nets.find(e=>e.pins.includes(r))?.id||void 0}function sf(e,t,n){let r=[...new Set(e.flatMap(e=>of(e,t,n)??[]))];return r.length===e.length&&r.every((t,n)=>t===e[n])?e:r.length===0?ef:r}function cf(e,t,n){return Y(e,t,n)?.net??void 0}var lf=e=>e.startsWith(`drawing:`)||e.includes(`~`),uf=e=>JSON.stringify({...e,source:void 0}),df=(e,t)=>e.filter(e=>e.kind===t).length,ff=(e,t)=>t.some(t=>t.id.startsWith(`${e}~`));function pf(e,t,n,r){return!lf(t.id)&&!ff(t.id,n)&&!ff(t.id,r)?!0:e.kind===t.kind?df(n,t.kind)===df(r,t.kind)||uf(e)===uf(t):!1}function mf(e,t){let n=new Map((e??[]).map(e=>[e.id,e]));return t.flatMap(r=>{let i=n.get(r.id);return!e||!i||pf(i,r,e,t)?[r.id]:[]})}function hf(e,t,n){let r=e=>n.some(t=>t.id===e.to);return{selection:t.filter(r).reduce((e,{from:t,to:n})=>e.hasDrawing(t)?e.withoutDrawings([t]).addDrawings([n]):e,e),waiting:t.filter(e=>!r(e))}}function gf(e,t,n){return e.drawingCount===0?e:e.keepDrawings(mf(t,n))}var _f=/^[ADPF]?GND\w*$|^VSS\w*$/i,vf=/^(VCC|VDD|VBUS|VIN|V\d|\+)/i,yf=new Intl.Collator(`en`,{numeric:!0});function bf(e){return _f.test(e)?`ground`:vf.test(e)?`power`:void 0}function xf(e){for(let t of e){let e=bf(t);if(e)return e}}var Sf=e=>e.find(e=>bf(e))??e[0];function Cf(e){return Sf(e.names)??`(unnamed) ${e.pins[0]??e.id}`}function wf(e){return e.circuit.nets.map(e=>{let t=Sf(e.names),n=xf(e.names);return{id:e.id,label:Cf(e),pins:e.pins.length,named:t!==void 0,...n?{badge:n}:{}}}).sort((e,t)=>Number(t.named)-Number(e.named)||yf.compare(e.label,t.label))}function Tf(e,t,n,r){let i=new Map,a=[],o=[];for(let s of t){let t=Dr(e,s);t?.wire!==void 0&&(r.includes(t.wire)||n(t.part))?i.set(t.wire,s):t&&t.wire===void 0&&n(t.part)?a.push(s):o.push(s)}return{riding:i,onPins:a,alone:o}}var Ef=(e,t)=>e.schematic.labels.find(e=>e.id===t);function Df(e,t){let n=e?kr(e):`the label`;return`${n.charAt(0).toUpperCase()}${n.slice(1)}: ${t}`}function Of(e,t,n,r,i,a){let o=Ef(e,n),s={edits:[],shown:[],names:[],notes:[]};if(!o)return s;let c={x:z(o.at.x+r.x),y:z(o.at.y+r.y)},l=Br(e,t,n,c,i);if(!Array.isArray(l))return a.includes(l.blocked)?s:{...s,notes:[Df(o,l.blocked)]};let u=l.length>0?Fr(e,n,c):void 0;return u?{edits:l,shown:[{id:n,...u}],names:[kr(o)],notes:[]}:s}function kf(e,t,n,r,i,a){let o=n.map(n=>Of(e,t,n,r,i,a));return{edits:o.flatMap(e=>e.edits),shown:o.flatMap(e=>e.shown),names:o.flatMap(e=>e.names),notes:o.flatMap(e=>e.notes)}}function Af(e,t){return t.flatMap(t=>{let n=Ef(e,t);return n?[kr(n)]:[]})}var jf=e=>e.length>1?[`${e.length} labels`]:[...e];function Mf(e,t,n,r){if(r.has(e))return e;let i=t&&Or(t,e);return i===void 0?void 0:n.schematic.labels.find(e=>Or(n,e.id)===i)?.id}function Nf(e,t,n){if(e.labelCount===0)return e;let r=new Set(n.schematic.labels.map(e=>e.id)),i=e.labels.flatMap(e=>Mf(e,t,n,r)??[]);return e.all(e.names,e.wires,i,e.drawings)}var Pf=(e,t)=>e.slice(`label:${t}:`.length);function Ff(e,t,n){let r=e.schematic.labels.find(e=>e.id===t),i=Dr(e,t);return i?.wire===void 0?i&&n.has(i.part)?{kind:`part`,label:t}:r?{kind:`skipped`,reason:Df(r,`Studio places it on ${Pf(t,r.net)} for its net; delete that pin's part or wire instead`)}:{kind:`gone`}:{kind:`wire`,label:t,wire:i.wire}}function If(e,t,n){let r=t.map(t=>Ff(e,t,n));return{withWires:r.flatMap(e=>e.kind===`wire`?[{label:e.label,wire:e.wire}]:[]),withParts:r.flatMap(e=>e.kind===`part`?[e.label]:[]),skipped:r.flatMap(e=>e.kind===`skipped`?[e.reason]:[])}}function Lf(e,t){let n=e.schematic.labels.find(e=>e.id===t);if(!n)return;let r=$d(e.circuit.nets,n.net),i=e.circuit.nets.find(e=>e.id===r),a=Dr(e,t)?.wire===void 0?`At a pin`:`Hand-drawn`;return{net:r,rows:[{label:`Net`,value:i?Cf(i):r.replace(/^net\./,``)},{label:`Text`,value:n.text},{label:`Kind`,value:a}]}}var Rf=e=>`${e.x},${e.y}`;function zf(e){let t=new Map(e.symbols.flatMap(e=>Object.entries(e.pinEnds).map(([e,t])=>[Rf(t),e])));return e.wires.map(e=>{let[n,r]=[e.points[0],e.points[e.points.length-1]],i=n&&r?[t.get(Rf(n)),t.get(Rf(r))]:[],a=i.length===2&&i.every(e=>e!==void 0);return e.connection===void 0&&a?{...e,ends:i}:e})}var Bf=(e,t)=>e.x===t.x&&e.y===t.y;function Vf(e,t){if(e.ends&&t.ends)return e.ends.length===t.ends.length&&e.ends.every(e=>t.ends?.includes(e));let[n,r,i,a]=[e.points[0],e.points[e.points.length-1],t.points[0],t.points[t.points.length-1]];return!n||!r||!i||!a?!1:Bf(n,i)&&Bf(r,a)||Bf(n,a)&&Bf(r,i)}function Hf(e,t,n){let r=n.find(t=>t.id===e),i=t?.find(t=>t.id===e);return!r||r.connection===void 0&&i!==void 0&&!Vf(i,r)}function Uf(e,t,n){return e.withoutWires(e.wires.filter(e=>Hf(e,t,n)))}function Wf(e,t){let n=t.parts?e.keep(t.parts):e,r=t.view===`schematic`,i=e=>r?e??[]:[],a=r?[]:t.copper??[],o=r?[]:t.board??[];return n.keepWires(i(t.wires)).keepLabels(i(t.labels)).keepDrawings(i(t.drawings)).keepCopper(a).keepTexts(t.texts??[]).keepBoard(o)}var Gf=[{id:`library`,label:`Library`},{id:`log`,label:`Log`},{id:`drc`,label:`DRC`},{id:`find`,label:`Find Results`}],Kf=`bottom-panel`,qf=e=>`bottom-tab-${e}`,Jf={open:!1,tab:`drc`};function Yf(e,t){return e.open&&e.tab===t?{...e,open:!1}:{open:!0,tab:t}}function Xf(e){return{...e,open:!e.open}}function Zf(e,t){return{open:!0,tab:t}}function Qf(e){return e.detail>0}var $f=`button, input[type='checkbox']`;function ep(e){e.target instanceof HTMLElement&&e.target.closest($f)?.blur()}function tp(e,t,n){return t>0||e===`checkbox`&&!n}function np(e,t,n){return e===null||e===t||(n?.contains(e)??!1)}function rp(e){let t=e.target instanceof HTMLElement?e.target.closest($f):null;t&&tp(t instanceof HTMLInputElement?`checkbox`:`button`,e.detail,t.matches(`:focus-visible`))&&t.blur()}var ip=new Set([`ArrowLeft`,`ArrowUp`]),ap=new Set([`ArrowRight`,`ArrowDown`]);function op(e,t,n){if(e.length===0)return null;if(n===`Home`)return e[0]??null;if(n===`End`)return e[e.length-1]??null;let r=ip.has(n)?-1:+!!ap.has(n);return r===0?null:e[(Math.max(0,e.indexOf(t))+r+e.length)%e.length]??null}function sp({ids:e,current:t,onSelect:n,onPointerClick:r}){return{onKeyDown:r=>{let i=op(e,t,r.key);i!==null&&(r.preventDefault(),r.stopPropagation(),n(i),r.currentTarget.querySelector(`[data-tab="${i}"]`)?.focus())},tab:e=>({"data-tab":e,tabIndex:e===t?0:-1,onClick:t=>{if(!Qf(t))return n(e);ep(t),(r??n)(e)}})}}var cp=e((e=>{var t=Symbol.for(`react.transitional.element`),n=Symbol.for(`react.fragment`);function r(e,n,r){var i=null;if(r!==void 0&&(i=``+r),n.key!==void 0&&(i=``+n.key),`key`in n)for(var a in r={},n)a!==`key`&&(r[a]=n[a]);else r=n;return n=r.ref,{$$typeof:t,type:e,key:i,ref:n===void 0?null:n,props:r}}e.Fragment=n,e.jsx=r,e.jsxs=r})),lp=e(((e,t)=>{t.exports=cp()})),X=lp(),up=Gf.map(e=>e.id);function dp({state:e,onClick:t,onOpen:n}){let r=sp({ids:up,current:e.tab,onSelect:n,onPointerClick:t});return(0,X.jsx)(`nav`,{className:`bottom-strip hairline-t`,role:`tablist`,"aria-label":`Bottom panel`,onKeyDown:r.onKeyDown,children:Gf.map(t=>{let n=e.open&&e.tab===t.id;return(0,X.jsx)(`button`,{role:`tab`,id:qf(t.id),"aria-controls":Kf,className:`bottom-tab${n?` on`:``}`,"aria-selected":n,...r.tab(t.id),children:(0,X.jsx)(`span`,{className:`bottom-tab-label`,children:t.label})},t.id)})})}function fp(e){return{"--dpr":String(Number.isFinite(e)&&e>0?e:1)}}function pp(e){let t=e.document.documentElement,n,r=()=>{for(let[n,r]of Object.entries(fp(e.devicePixelRatio)))t.style.setProperty(n,r);n?.removeEventListener(`change`,r),n=e.matchMedia(`(resolution: ${e.devicePixelRatio}dppx)`),n.addEventListener(`change`,r)};return r(),e.addEventListener(`resize`,r),()=>{e.removeEventListener(`resize`,r),n?.removeEventListener(`change`,r)}}var Z=(e,t)=>t?{tag:`path`,d:e,dash:t}:{tag:`path`,d:e},mp=(e,t,n,r)=>r?{tag:`circle`,cx:e,cy:t,r:n,fill:r}:{tag:`circle`,cx:e,cy:t,r:n},hp=(e,t,n,r,i=1,a)=>a?{tag:`rect`,x:e,y:t,width:n,height:r,rx:i,fill:a}:{tag:`rect`,x:e,y:t,width:n,height:r,rx:i},gp=Z(`M2.5 5.5v-3h3M10.5 2.5h3v3M13.5 10.5v3h-3M5.5 13.5h-3v-3`),_p=[hp(3,7,10,7,1.5),Z(`M8 10v1.5`)],vp=[4,8,12].flatMap(e=>[4,8,12].map(t=>mp(t,e,1,!0))),yp={lock:[..._p,Z(`M5.5 7V5a2.5 2.5 0 0 1 5 0v2`)],unlock:[..._p,Z(`M5.5 7V5a2.5 2.5 0 0 1 5 0`)],padlock:[hp(2.5,7,11,7.5,1.5),Z(`M5 7V5a3 3 0 0 1 6 0v2`),Z(`M8 10v2`)],padlockOpen:[hp(2.5,7,11,7.5,1.5),Z(`M11 7V4a3 3 0 0 0-6 0v.5`),Z(`M8 10v2`)],trash:[Z(`M2.5 4.5h11M6 4.5V2.5h4v2`),Z(`M4 4.5l.5 9h7l.5-9`),Z(`M6.5 7v4M9.5 7v4`)],close:[Z(`M4 4l8 8M12 4l-8 8`)],chevron:[Z(`M6 4l4 4-4 4`)],eye:[Z(`M1.5 8S4 3.5 8 3.5 14.5 8 14.5 8 12 12.5 8 12.5 1.5 8 1.5 8z`),mp(8,8,2)],eyeOff:[Z(`M1.5 8S4 3.5 8 3.5 14.5 8 14.5 8 12 12.5 8 12.5 1.5 8 1.5 8z`),mp(8,8,2),Z(`M2.5 2.5l11 11`)],undo:[Z(`M5.5 3 3 5.5 5.5 8`),Z(`M3 5.5h6.5a3.5 3.5 0 0 1 0 7h-3`)],redo:[Z(`M10.5 3 13 5.5 10.5 8`),Z(`M13 5.5H6.5a3.5 3.5 0 0 0 0 7h3`)],zoomIn:[mp(7,7,4.5),Z(`M10.5 10.5 14 14M7 5v4M5 7h4`)],zoomOut:[mp(7,7,4.5),Z(`M10.5 10.5 14 14M5 7h4`)],fit:[gp,hp(6,6,4,4,.5)],fitSelection:[gp,hp(5.5,5.5,5,5,1,!0)],fitArea:[hp(2.5,2.5,8,8,1),Z(`M7 7l6.5 6.5M13.5 9.5v4h-4`)].map(e=>e.tag===`rect`?{...e,dash:`2 2`}:e),grid:vp,snap:[Z(`M3.5 2.5V8a4.5 4.5 0 0 0 9 0V2.5h-3V8a1.5 1.5 0 0 1-3 0V2.5z`),Z(`M3.5 5h3M9.5 5h3`)],component:[hp(4.5,3,7,10,1),Z(`M2 6h2.5M2 10h2.5M11.5 6H14M11.5 10H14`)],wire:[mp(3.5,12.5,1.5),mp(12.5,3.5,1.5),Z(`M5 12.5h3.5v-9H11`)],netLabel:[Z(`M1.5 8h2`),Z(`M5.5 4.5h8v7h-8L3.5 8z`),Z(`M8 8h3`)],bus:[Z(`M2 10.5h12`,void 0),Z(`M5.5 10.5l2-4.5M9.5 10.5l2-4.5`)],polyline:[Z(`M2 13l3.5-7 4 4 4.5-7`)],arc:[Z(`M3 12a5 5 0 0 1 10 0`)],circle:[mp(8,8,5.5)],rectangle:[hp(2.5,4.5,11,7,0)],text:[Z(`M3.5 4.5V3h9v1.5M8 3v10M6 13h4`)],ground:[Z(`M8 2.5v6M3 8.5h10M5 11h6M7 13.5h2`)],power:[Z(`M8 14V5.5M3.5 5.5h9`),Z(`M3.5 5.5 8 2l4.5 3.5`)],noConnect:[Z(`M2 8h5`),Z(`M9 5.5l5 5M14 5.5l-5 5`)],via:[mp(8,8,5.5),mp(8,8,2)],boardOutline:[Z(`M2.5 3.5h8l3 3v6h-11z`)],copperArea:[hp(2.5,2.5,11,11,1),Z(`M5.5 10.5l5-5M5.5 7.5l2-2M8.5 10.5l2-2`)],singleRouting:[mp(3.5,12.5,1.5),Z(`M5 12.5h3.5L12 9V3.5`)],gerber:[Z(`M8 2.5 2.5 5 8 7.5 13.5 5z`),Z(`M2.5 8 8 10.5 13.5 8`),Z(`M2.5 11 8 13.5 13.5 11`)],rotate:[Z(`M3 8a5 5 0 1 0 5-5`),Z(`M9.5 1.5 8 3l1.5 1.5`)],rotateRight:[Z(`M13 8a5 5 0 1 1-5-5`),Z(`M6.5 1.5 8 3 6.5 4.5`)],alignLeft:[Z(`M2.5 2v12`),hp(5,3.5,8.5,3.5,1),hp(5,9,5,3.5,1)],distributeH:[Z(`M2.5 2v12M13.5 2v12`),hp(6,4,4,8,1)],check:[Z(`M8 1.5 3 3.5v4c0 3 2 5.5 5 6.5 3-1 5-3.5 5-6.5v-4z`),Z(`M5.5 8l2 2 3-3.5`)]},bp={width:16,height:16,viewBox:`0 0 16 16`,fill:`none`,stroke:`currentColor`,strokeWidth:1.5,strokeLinecap:`round`,strokeLinejoin:`round`,shapeRendering:`geometricPrecision`,"aria-hidden":!0};function xp(e,t){let{tag:n,fill:r,dash:i,...a}=e;return{key:t,...a,...r?{fill:`currentColor`,stroke:`none`}:{},...i?{strokeDasharray:i}:{}}}function Sp(e,t={}){let n=yp[e];return(0,l.createElement)(`svg`,{...bp,...t},...n.map((e,t)=>(0,l.createElement)(e.tag,xp(e,t))))}var Cp=e=>Sp(`lock`,e),wp=e=>Sp(`unlock`,e),Tp=e=>Sp(`padlock`,e),Ep=e=>Sp(`padlockOpen`,e),Dp=e=>Sp(`rotate`,e),Op=e=>Sp(`trash`,e),kp=e=>Sp(`undo`,e),Ap=e=>Sp(`close`,e),jp=e=>Sp(`chevron`,e),Mp=({off:e,...t})=>Sp(e?`eyeOff`:`eye`,t),Q=e=>t=>Sp(e,t),Np={undo:Q(`undo`),redo:Q(`redo`),zoomIn:Q(`zoomIn`),zoomOut:Q(`zoomOut`),fit:Q(`fit`),fitSelection:Q(`fitSelection`),fitArea:Q(`fitArea`),component:Q(`component`),wire:Q(`wire`),netLabel:Q(`netLabel`),ground:Q(`ground`),power:Q(`power`),rotate:Q(`rotate`),rotateRight:Q(`rotateRight`),snap:Q(`snap`),check:Q(`check`),grid:Q(`grid`),alignLeft:Q(`alignLeft`),distributeH:Q(`distributeH`),polyline:Q(`polyline`),arc:Q(`arc`),circle:Q(`circle`),rectangle:Q(`rectangle`),text:Q(`text`),bus:Q(`bus`),noConnect:Q(`noConnect`),via:Q(`via`),boardOutline:Q(`boardOutline`),copperArea:Q(`copperArea`),singleRouting:Q(`singleRouting`),gerber:Q(`gerber`)};function Pp(e){return e===`Escape`?`close`:e===`Tab`?`trap`:`hold`}function Fp(e,t,n){return t<=0?-1:e<0||e>=t?n?t-1:0:(e+(n?-1:1)+t)%t}function Ip(){let e=[];return{hold(t){return e=[...e,t],()=>{e=e.filter(e=>e!==t)}},held(){return e.length>0},dispatch(t){let n=e.at(-1);return n?(n(t),t.stopImmediatePropagation(),!0):!1}}}var Lp=Ip();function Rp(e){let t=e=>void Lp.dispatch(e);return e.addEventListener(`keydown`,t,!0),()=>e.removeEventListener(`keydown`,t,!0)}function zp(e,t){let n=(0,l.useRef)(t);(0,l.useLayoutEffect)(()=>{n.current=t}),(0,l.useEffect)(()=>e?Lp.hold(e=>n.current(e)):void 0,[e])}var Bp=[`fitSelection`,`rotateRight`,`selectInstance`,`replicateLayout`,`makeSheet`,`autorouteSelection`,`autoplaceSelection`,`autoplaceInstance`],Vp=`Select a part first`,Hp=e=>Bp.includes(e);function Up(e,t){return v(e)?b(e,t):Hp(e)&&t<1?Vp:null}var Wp=`Comes with hand routing (engine stage 4)`,$=(e,t,n)=>n?{label:e,command:t,shortcut:n}:{label:e,command:t},Gp=[{title:`File`,entries:[$(`Open circuit file`,`openFile`,`Ctrl+O`),$(`New circuit…`,`newCircuit`),`separator`,$(`Export BOM`,`exportBom`),$(`Export package`,`exportPackage`),$(`Export Gerber`,`exportFabrication`),$(`Print…`,`print`)]},{title:`Edit`,entries:[$(`Undo`,`undo`,`Ctrl+Z`),$(`Redo`,`redo`,`Ctrl+Y`),`separator`,$(`Copy`,`copy`,`Ctrl+C`),$(`Paste`,`paste`,`Ctrl+V`),$(`Delete`,`delete`,`Delete`),`separator`,$(`Select all`,`selectAll`,`Ctrl+A`),$(`Select the instance`,`selectInstance`),{label:`Make sub-sheet…`,command:`makeSheet`,only:`schematic`},$(`Find`,`find`,`Ctrl+F`),$(`Find similar objects`,`findSimilar`,`Ctrl+Shift+F`),`separator`,$(`Fillet tracks`,`filletTracks`,`U`),$(`Straighten tracks`,`straightenTracks`,`Shift+U`)]},{title:`View`,entries:[$(`Fit all`,`fit`,`K`),$(`Fit selection`,`fitSelection`),$(`Fit area`,`fitArea`),$(`Zoom in`,`zoomIn`),$(`Zoom out`,`zoomOut`),`separator`,{...$(`Unit`,`toggleUnit`,`Q`),only:`pcb`},$(`Grid style`,`gridStyle`),{...$(`Snap`,`snap`,`Alt+S`),toggle:`snap`},{...$(`Hover labels`,`hoverLabels`),toggle:`hoverLabels`},{...$(`Pour fill: Solid`,`pourSolid`),toggle:`pourSolid`},{...$(`Pour fill: Hatched`,`pourHatched`),toggle:`pourHatched`},{...$(`Pour fill: Outline only`,`pourOutline`),toggle:`pourOutline`},`separator`,$(`Left panel`,`toggleLeftPanel`,`[`),$(`Right panel`,`toggleRightPanel`,`]`),$(`Bottom panel`,`toggleBottomPanel`,`\\`),`separator`,{...$(`Theme: Light`,`themeLight`),toggle:`themeLight`},{...$(`Theme: Dark`,`themeDark`),toggle:`themeDark`}]},{title:`Place`,entries:[$(`Component`,`placeComponent`,`Shift+F`),$(`Wire`,`wire`,`Alt+W`),$(`Net label`,`netLabel`,`Alt+N`),$(`Ground flag`,`groundFlag`),$(`Power flag`,`powerFlag`),`separator`,$(`Note box`,`noteBox`),`separator`,$(`Bus`,`drawBus`,`Alt+B`),{label:`No connect flag`,command:`noConnect`,only:`schematic`},{label:`Junction`,command:`junction`,shortcut:`Alt+J`,only:`schematic`},`separator`,$(`Copper pour`,`placePour`),$(`Copper pour: Whole board`,`placePourBoard`),$(`Hole`,`placeHole`),`separator`,{label:`Autoplace`,command:`autoplace`,only:`pcb`},{label:`Autoplace selection`,command:`autoplaceSelection`,only:`pcb`},{label:`Autoplace instance`,command:`autoplaceInstance`,only:`pcb`},`separator`,$(`Polyline`,`drawPolyline`,`Alt+L`),$(`Arc`,`drawArc`,`Alt+A`),$(`Circle`,`drawCircle`,`Alt+C`),$(`Rectangle`,`drawRectangle`,`Alt+R`),$(`Text`,`drawText`,`Alt+T`)]},{title:`Design`,entries:[$(`Check DRC`,`checkDrc`),$(`Design rules`,`designRules`),`separator`,$(`Highlight net`,`highlight`,`H`),$(`Clear highlight`,`clearHighlight`,`Shift+H`),`separator`,{label:`Add page`,command:`addPage`,only:`schematic`},{label:`Rename page`,command:`renamePage`,only:`schematic`},{label:`Delete page`,command:`deletePage`,only:`schematic`},`separator`,{label:`Replicate layout`,command:`replicateLayout`,only:`pcb`},$(`Annotate designators`,`annotate`),{label:`Placement transfer`,command:`placementTransfer`,shortcut:`Ctrl+Shift+X`,only:`pcb`}]},{title:`Route`,entries:[$(`Single routing`,`singleRouting`,`Alt+W`),$(`Via`,`placeVia`,`Alt+V`),{label:`Routing corner`,command:`routingCorner`,shortcut:`L`,only:`pcb`},`separator`,$(`Autoroute`,`autoroute`),$(`Autoroute selection`,`autorouteSelection`),$(`Autoroute net`,`autorouteNet`),$(`Unroute`,`unroute`)]},{title:`Layout`,entries:[$(`Rotate`,`rotate`,`Space`),$(`Rotate right`,`rotateRight`),{label:`Flip`,command:`flip`,shortcut:`X`,only:`pcb`},`separator`,$(`Lock`,`lock`),$(`Unlock`,`unlock`),`separator`,$(`Align left`,`alignLeft`,`Ctrl+Shift+L`),$(`Align right`,`alignRight`),$(`Align top`,`alignTop`),$(`Align bottom`,`alignBottom`),$(`Align horizontal centres`,`alignHCentres`),$(`Align vertical centres`,`alignVCentres`),`separator`,$(`Distribute horizontally`,`distributeH`,`Ctrl+Shift+H`),$(`Distribute vertically`,`distributeV`),`separator`,{label:`Fit board`,command:`fitBoard`,only:`pcb`},`separator`,{label:`Tidy sheet`,command:`tidySheet`,only:`schematic`}]},{title:`Tools`,entries:[$(`History`,`history`),$(`Footprint manager…`,`footprintManager`)]},{title:`Export`,entries:[$(`BOM`,`exportBom`),$(`Package`,`exportPackage`),$(`Fabrication files (JLCPCB)`,`exportFabrication`),$(`Gerber`,`exportFabrication`),$(`Pick and place (CPL)`,`exportFabrication`),$(`PDF…`,`exportPdf`)]},{title:`Settings`,entries:[$(`System…`,`systemSettings`),$(`Hotkeys`,`keys`)]},{title:`Help`,entries:[$(`Keys`,`keys`),$(`About`,`about`)]}];Gp.map(e=>e.title);var Kp={pcb:`PCB only`,schematic:`Schematic only`};function qp(e,t,n,r={}){if(!e.command)return e.pending?{enabled:!1,reason:e.pending}:{enabled:!1};if(e.only&&e.only!==t)return{enabled:!1,reason:Kp[e.only]};let i=r[e.command];if(i!==void 0)return{enabled:!1,reason:i};let a=n===void 0?null:Up(e.command,n);return a?{enabled:!1,reason:a}:{enabled:!0}}function Jp(e){return e.entries.filter(e=>e!==`separator`)}var Yp=[{keys:`Ctrl+Shift+Z`,label:`Redo`},{keys:`W`,label:`Wire (schematic), Single routing (PCB)`},{keys:`V (PCB)`,label:`Change the active layer; while routing, a via at the last corner`},{keys:`Space (while routing)`,label:`Step the corner mode: 45°, 45° reversed, 90°, arc`},{keys:`Enter (while routing)`,label:`End the track open at its last corner (or click that corner again)`},{keys:`R`,label:`Rotate`},{keys:`Space (while drawing a wire)`,label:`Flip the bend of the leg to the pointer`},{keys:`Shift (while drawing a polyline)`,label:`Keep the leg horizontal or vertical; Space flips its bend`},{keys:`Enter (while drawing a polyline)`,label:`Finish the polyline (or double click)`},{keys:`Backspace (while drawing)`,label:`Remove the last corner`},{keys:`F`,label:`Fit all`},{keys:`Esc`,label:`Clear the selection, put tools away`},{keys:`Arrow keys`,label:`Move the selection one grid step (a tenth with Snap off)`},{keys:`Shift+Arrow keys`,label:`Move the selection ten grid steps (ten tenths with Snap off)`},{keys:`Shift+F10`,label:`Open the context menu (also the menu key)`}];function Xp(){let e=new Set,t=[];for(let n of Gp.flatMap(Jp))n.command&&n.shortcut&&!e.has(n.shortcut)&&(e.add(n.shortcut),t.push({keys:n.shortcut,label:n.label}));return[...t,...Yp.filter(t=>!e.has(t.keys))]}function Zp(e,t){switch(t.type){case`click`:return{open:e.open===t.title?null:t.title};case`hover`:return e.open===null||e.open===t.title?e:{open:t.title};case`set`:return e.open===t.title?e:{open:t.title};default:return e.open===null?e:{open:null}}}function Qp(e,t,n={}){return Gp.map(r=>r.entries.map(r=>r===`separator`?`separator`:qp(r,e,t,n).enabled?`item`:`disabled`))}var $p=`Type the LCSC part number, e.g. C7950. The part is fetched from EasyEDA, so this needs the internet.`;function em(e,t,n){let r=e.trim().toUpperCase();if(r===``)return{message:$p};if(!/^C[1-9][0-9]{0,9}$/.test(r))return{message:`"${e.trim()}" is not an LCSC part number: it looks like C7950 (C and digits).`};let i=t.trim();return{lcsc:r,replace:n,...i?{id:i}:{}}}function tm(e){let t=(e,t)=>`${e} ${t}${e===1?``:`s`}`;return`Imported ${e.lcsc} as ${e.id}: ${e.title}, ${t(e.pins,`pin`)}, ${t(e.pads,`pad`)}.`}function nm(e){return`Not verified: check every pin and pad in parts/${e.id}/verification.md against the datasheet before verifying it.`}function rm(e){if(!e)return;let t=/^lcsc (C\d+), imported (\S+)$/.exec(e);if(t)return`Imported from LCSC ${t[1]} on ${t[2]}`;let n=/^written (\S+)$/.exec(e);return n?`Written on ${n[1]}`:e}function im({result:e}){return(0,X.jsxs)(`div`,{className:`import-result`,role:`status`,children:[(0,X.jsx)(`p`,{children:(0,X.jsx)(`strong`,{children:tm(e)})}),(0,X.jsx)(`p`,{children:nm(e)}),e.notes.length>0&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`h3`,{children:`Check these too`}),(0,X.jsx)(`ul`,{children:e.notes.map(e=>(0,X.jsx)(`li`,{children:e},e))})]}),(0,X.jsx)(`h3`,{children:`Written`}),(0,X.jsx)(`ul`,{children:e.files.map(e=>(0,X.jsx)(`li`,{children:(0,X.jsx)(`code`,{children:e})},e))}),(0,X.jsx)(`p`,{children:e.terms})]})}function am({panel:e,onClose:t}){let[n,r]=(0,l.useState)(``),[i,a]=(0,l.useState)(``),[o,s]=(0,l.useState)(!1),[c,u]=(0,l.useState)(!1),[d,f]=(0,l.useState)(),[p,m]=(0,l.useState)(),h=(0,l.useId)(),g=async r=>{if(r.preventDefault(),c)return;if(p)return t();let a=em(n,i,o);if(`message`in a)return f(a.message);u(!0),f(void 0);try{m(await e.import(a))}catch(e){f(e.message)}finally{u(!1)}};return(0,X.jsxs)(`form`,{className:`rules-form import-part-form`,onSubmit:e=>void g(e),children:[(0,X.jsx)(`label`,{htmlFor:h,children:`LCSC part number`}),(0,X.jsx)(`input`,{id:h,value:n,placeholder:`C7950`,disabled:c||p!==void 0,onChange:e=>r(e.target.value),"aria-describedby":`${h}-note`,"aria-invalid":d!==void 0}),(0,X.jsx)(`label`,{htmlFor:`${h}-id`,children:`Part id`}),(0,X.jsx)(`input`,{id:`${h}-id`,value:i,placeholder:`the MPN`,disabled:c||p!==void 0,onChange:e=>a(e.target.value)}),(0,X.jsxs)(`label`,{className:`make-sheet-rename`,children:[(0,X.jsx)(`input`,{type:`checkbox`,checked:o,disabled:c||p!==void 0,onChange:e=>s(e.target.checked)}),`Replace a part with this id that is not verified`]}),(0,X.jsx)(`p`,{id:`${h}-note`,role:d?`alert`:void 0,children:c?`Fetching from EasyEDA…`:d??(p?``:`Type the LCSC part number, e.g. C7950. The part is fetched from EasyEDA, so this needs the internet.`)}),p&&(0,X.jsx)(im,{result:p}),(0,X.jsx)(`button`,{type:`submit`,disabled:c,children:p?`Close`:`Import`})]})}var om=/(?:^|[\s>])\.([A-Za-z_][\w-]*)/,sm=/^([A-Za-z_][\w-]*)\.[\w-]+$/;function cm(e){let t=new Set;for(let n of e.split(`,`)){let e=n.trim();if(e.startsWith(`net.`))continue;let r=sm.exec(e)??om.exec(e);r?.[1]&&t.add(r[1])}return[...t]}function lm(e,t){if(t.includes(`/`))return;let n=e.parts.find(e=>e.name===t)?.tag,r=e.imports.find(e=>e.local===n)?.source;if(r===void 0||!/\.sheet(\.tsx)?$/.test(r))return;let i=r.replace(/^\.\//,``);return i.endsWith(`.tsx`)?i:`${i}.tsx`}var um=class extends Error{code;constructor(e,t){super(t),this.code=e,this.name=`EditError`}};function dm(e,t){if(t.length===0)return`Select the parts to move into the sub-sheet first.`;let n=[];for(let r of new Set(t)){let t=e.parts.find(e=>e.name===r);if(!t)return`There is no part ${r} in the circuit.`;if(lm(e,r)!==void 0)return`${r} is a sub-sheet instance; a sub-sheet is made of parts only, so leave instances out of the selection.`;if(!t.editable)return`${r} cannot be moved (${t.readonlyReason??`read-only`}).`;if(t.parent===`group`)return`${r} is inside a <group>, whose offset its position adds to; ungroup it first.`;n.push(t)}if(new Set(n.map(e=>e.page??``)).size>1)return`The selected parts are on different pages; select parts of one page.`}function fm(e,t){if(!e)return{message:`Wait for the circuit to load, then try again.`};let n=dm(e,t);return n===void 0?{parts:[...new Set(t)]}:{message:n}}function pm(e){return e.ports.map(t=>({port:t.name,joins:`${t.bus?`bus`:`net`} ${e.connections[t.name]??t.name}`}))}function mm(e){return e.mapping.map(e=>({now:e.from,sheet:e.to,board:e.flat}))}var hm=e=>`${e.trim()||`PowerStage`}1`,gm=`Type the sheet's name, e.g. PowerStage: a capital letter, then letters, digits and _.`;function _m(e,t){return`Made ${e.file}: ${e.instance} (base ${e.base}) replaces ${t} part${t===1?``:`s`}`}var vm=200;function ym(e,t){let{name:n,instance:r,rename:i}=t,[a,o]=(0,l.useState)({problem:gm});return(0,l.useEffect)(()=>{if(n.trim()===``){o({problem:gm});return}let t=!0,a=window.setTimeout(()=>{e.preview({name:n.trim(),rename:i,...r?{instance:r}:{}}).then(e=>t&&o({preview:e}),e=>t&&o({problem:e.message}))},vm);return()=>{t=!1,window.clearTimeout(a)}},[e,n,r,i]),a}function bm({preview:e}){let t=pm(e);return t.length===0?(0,X.jsx)(`p`,{children:`No net crosses the selection, so the sheet has no ports.`}):(0,X.jsx)(`table`,{"aria-label":`Ports`,children:(0,X.jsx)(`tbody`,{children:t.map(e=>(0,X.jsxs)(`tr`,{children:[(0,X.jsx)(`td`,{children:e.port}),(0,X.jsx)(`td`,{children:e.joins})]},e.port))})})}function xm({preview:e}){return(0,X.jsxs)(`table`,{"aria-label":`Designators`,children:[(0,X.jsx)(`thead`,{children:(0,X.jsxs)(`tr`,{children:[(0,X.jsx)(`td`,{children:`Now`}),(0,X.jsx)(`td`,{children:`In the sheet`}),(0,X.jsx)(`td`,{children:`On the board`})]})}),(0,X.jsx)(`tbody`,{children:mm(e).map(e=>(0,X.jsxs)(`tr`,{children:[(0,X.jsx)(`td`,{children:e.now}),(0,X.jsx)(`td`,{children:e.sheet}),(0,X.jsx)(`td`,{children:e.board})]},e.now))})]})}function Sm({panel:e,onClose:t}){let[n,r]=(0,l.useState)(``),[i,a]=(0,l.useState)(``),[o,s]=(0,l.useState)(!1),c=i.trim(),u={name:n.trim(),rename:o,...c?{instance:c}:{}},{preview:d,problem:f}=ym(e,u),p=(0,l.useId)(),m=async n=>{n.preventDefault(),d&&await e.make(u)&&t()};return(0,X.jsxs)(`form`,{className:`rules-form make-sheet-form`,onSubmit:e=>void m(e),children:[(0,X.jsx)(`label`,{htmlFor:p,children:`Sheet name`}),(0,X.jsx)(`input`,{id:p,value:n,placeholder:`PowerStage`,onChange:e=>r(e.target.value),"aria-describedby":`${p}-note`,"aria-invalid":f!==void 0&&n!==``}),(0,X.jsx)(`label`,{htmlFor:`${p}-instance`,children:`Instance name`}),(0,X.jsx)(`input`,{id:`${p}-instance`,value:i,placeholder:hm(n),onChange:e=>a(e.target.value)}),(0,X.jsx)(`p`,{id:`${p}-note`,children:d?`Writes ${d.file}; ${d.instance} (base ${d.base}) takes the place of ${e.parts.length} part${e.parts.length===1?``:`s`}.`:f}),d&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`h3`,{children:`Ports`}),(0,X.jsx)(bm,{preview:d}),(0,X.jsx)(`h3`,{children:`Designators`}),(0,X.jsx)(xm,{preview:d})]}),(0,X.jsxs)(`label`,{className:`make-sheet-rename`,children:[(0,X.jsx)(`input`,{type:`checkbox`,checked:o,onChange:e=>s(e.target.checked)}),`Rename the parts to local designators (R1, C1, …)`]}),(0,X.jsx)(`button`,{type:`submit`,disabled:!d,children:`Make sub-sheet`})]})}function Cm(e){let t;return()=>(t??=e().catch(e=>{throw t=void 0,e}),t)}function wm(e){let t=Cm(e),n=()=>(0,l.lazy)(()=>t().then(e=>({default:e}))),r=n();return{component:()=>r,retry:()=>{r=n()}}}function Tm({what:e,message:t,onRetry:n}){return(0,l.createElement)(`div`,{role:`alert`},(0,l.createElement)(`p`,null,`The ${e} dialog could not open (${t}). Check that the Studio is still running, then try again; if it fails again, reload the Studio.`),(0,l.createElement)(`button`,{type:`button`,onClick:n},`Retry`))}var Em=class extends l.Component{state={};static getDerivedStateFromError(e){return{error:e instanceof Error?e:Error(String(e))}}render(){let{error:e}=this.state;return e?(0,l.createElement)(Tm,{what:this.props.what,message:e.message,onRetry:()=>{this.props.onRetry(),this.setState({error:void 0})}}):(0,l.createElement)(l.Suspense,{fallback:(0,l.createElement)(`p`,null,`Loading…`)},this.props.render())}},Dm=.0254,Om=e=>e===`mm`?`mil`:`mm`,km=(e,t)=>t===`mil`?e/Dm:e;function Am(e,t){let n=km(e,t).toFixed(t===`mil`?1:2);return/^-0(\.0+)?$/.test(n)?n.slice(1):n}function jm(e,t){return`${Number(km(e,t).toFixed(t===`mm`?4:2))} ${t}`}var Mm=(e,t)=>Math.round(e/t*100),Nm=.0254,Pm=[2*Nm,.1,5*Nm,10*Nm,.5,20*Nm,25*Nm,1,50*Nm,100*Nm].map(e=>Number(e.toFixed(4))),Fm=.5,Im=[.05,.1,.2],Lm=.1,Rm=(e,t,n)=>({...e,[t]:n});function zm(e,t){if(e===`schematic`)return Im.map(e=>({value:e,label:`${e} in`}));if(!t)throw Error(`The PCB's Grid steps need its display unit`);return Pm.map(e=>({value:e,label:jm(e,t)}))}var Bm={schematic:`lines`,pcb:`lines`},Vm=e=>e===`lines`?`dots`:`lines`,Hm=(e,t)=>({...e,[t]:Vm(e[t])}),Um=5,Wm=2;function Gm(e,t,n=1){let r=e;for(let e=0;e<=Wm;e++,r*=Um)if(r*t*n>=3)return r;return null}function Km(e,t,n,r=1){let i=Gm(n,e.scale,r);if(i===null)return null;let a=pe(e,t,{x:0,y:0}),o=pe(e,t,{x:t.width,y:t.height}),s=(e,t)=>{let n=[];for(let r=Math.floor(Math.min(e,t)/i);r<=Math.ceil(Math.max(e,t)/i);r++)n.push(r);return n};return{spacing:i,columns:s(a.x,o.x),rows:s(a.y,o.y),minor:i*e.scale*r>=6}}var qm=e=>e%5==0,Jm=e=>({...e,columns:e.columns.filter(qm),rows:e.rows.filter(qm)});function Ym(e,t,n,r,i,a){let{spacing:o}=r,s=(t,n)=>{for(let[r,a]of[[i.minor,!1],[i.fifth??i.minor,!0]]){e.strokeStyle=r,e.beginPath();for(let r of t.filter(e=>!i.fifth||qm(e)===a)){let[t,i,a,o]=n(r);e.moveTo(t,i),e.lineTo(a,o)}if(e.stroke(),!i.fifth)return}};e.lineWidth=wa(a),s(r.columns,e=>{let r=Ta(fe(t,n,{x:e*o,y:0}).x,a);return[r,0,r,n.height]}),s(r.rows,e=>{let r=Ta(fe(t,n,{x:0,y:e*o}).y,a);return[0,r,n.width,r]})}function Xm(e,t,n,r){let i=Math.floor((Math.round(n*r)-1)/2)/r;return e.map(e=>({at:Ea(t(e),r)-i,fifth:qm(e)}))}function Zm(e,t,n,r){e.fillStyle=n,e.beginPath();for(let n=0;n+1<t.length;n+=2)e.rect(t[n],t[n+1],r,r);e.fill()}function Qm(e,t,n,r,i,a){let{spacing:o}=r,s=Da(i.px,a),c=Xm(r.columns,e=>fe(t,n,{x:e*o,y:0}).x,s,a),l=Xm(r.rows,e=>fe(t,n,{x:0,y:e*o}).y,s,a),u=[];e.fillStyle=i.minor,e.beginPath();for(let t of c)for(let n of l)i.fifth&&t.fifth&&n.fifth?u.push(t.at,n.at):e.rect(t.at,n.at,s,s);e.fill(),i.fifth&&Zm(e,u,i.fifth,s)}function $m(e,t,n,r,i,a){let o=Km(t,n,r.step,a);if(!o)return;let s=o.minor?o:Jm(o);e.save(),r.style===`dots`?Qm(e,t,n,s,i.dots,a):Ym(e,t,n,s,i.lines,a),e.restore()}function eh({panel:e,onClose:t}){let[n,r]=(0,l.useState)(e.settings),i=(0,l.useId)(),a=(e,t)=>r(n=>({...n,[e]:t}));return(0,X.jsxs)(`form`,{className:`rules-form system-form`,onSubmit:r=>{r.preventDefault(),e.apply(n),t()},children:[(0,X.jsx)(`label`,{htmlFor:`${i}-theme`,children:`Theme`}),(0,X.jsxs)(`select`,{id:`${i}-theme`,value:n.theme,onChange:e=>a(`theme`,e.target.value),children:[(0,X.jsx)(`option`,{value:`light`,children:`Light`}),(0,X.jsx)(`option`,{value:`dark`,children:`Dark`})]}),(0,X.jsx)(`label`,{htmlFor:`${i}-unit`,children:`PCB unit`}),(0,X.jsxs)(`select`,{id:`${i}-unit`,value:n.unit,onChange:e=>a(`unit`,e.target.value),children:[(0,X.jsx)(`option`,{value:`mm`,children:`mm`}),(0,X.jsx)(`option`,{value:`mil`,children:`mil`})]}),(0,X.jsx)(`label`,{htmlFor:`${i}-sheet`,children:`Schematic grid`}),(0,X.jsx)(`select`,{id:`${i}-sheet`,value:n.grid.schematic,onChange:e=>a(`grid`,{...n.grid,schematic:Number(e.target.value)}),children:zm(`schematic`).map(e=>(0,X.jsx)(`option`,{value:e.value,children:e.label},e.value))}),(0,X.jsx)(`label`,{htmlFor:`${i}-pcb`,children:`PCB grid`}),(0,X.jsx)(`select`,{id:`${i}-pcb`,value:n.grid.pcb,onChange:e=>a(`grid`,{...n.grid,pcb:Number(e.target.value)}),children:zm(`pcb`,n.unit).map(e=>(0,X.jsx)(`option`,{value:e.value,children:e.label},e.value))}),(0,X.jsxs)(`label`,{children:[(0,X.jsx)(`input`,{type:`checkbox`,checked:n.hoverLabels,onChange:e=>a(`hoverLabels`,e.target.checked)}),` Hover labels`]}),(0,X.jsx)(`p`,{children:`Kept in this browser. The grid steps are where each document starts; the Grid select still changes them.`}),(0,X.jsx)(`button`,{type:`submit`,children:`Save`})]})}var th={width:30,height:20},nh=1e3,rh=/^[\w\- ]+(\/[\w\- ]+)*$/;function ih(e,t,n){let r=e.trim().replace(/\.circuit\.tsx$/,``);if(r===``)return{message:`Give the circuit a name`};if(!rh.test(r))return{message:`Use letters, digits, spaces, - and _ in the name, and / between folders`};let i=[Number(t),Number(n)];return i.some(e=>!Number.isFinite(e)||e<=0||e>nh)?{message:`The board's width and height are mm above 0 and at most ${nh}`}:{file:`${r}.circuit.tsx`,width:i[0],height:i[1]}}function ah({panel:e,onClose:t}){let[n,r]=(0,l.useState)(``),[i,a]=(0,l.useState)(String(th.width)),[o,s]=(0,l.useState)(String(th.height)),[c,u]=(0,l.useState)(),[d,f]=(0,l.useState)(!1),p=(0,l.useId)(),m=async r=>{r.preventDefault();let a=ih(n,i,o);if(`message`in a)return u(a.message);f(!0);let s=await e.create(a);f(!1),s&&t()};return(0,X.jsxs)(`form`,{className:`rules-form`,onSubmit:e=>void m(e),children:[(0,X.jsx)(`label`,{htmlFor:`${p}-name`,children:`Name`}),(0,X.jsx)(`input`,{id:`${p}-name`,value:n,placeholder:`power-board`,onChange:e=>r(e.target.value),"aria-invalid":c!==void 0}),(0,X.jsx)(`label`,{htmlFor:`${p}-w`,children:`Board width (mm)`}),(0,X.jsx)(`input`,{id:`${p}-w`,inputMode:`decimal`,value:i,onChange:e=>a(e.target.value)}),(0,X.jsx)(`label`,{htmlFor:`${p}-h`,children:`Board height (mm)`}),(0,X.jsx)(`input`,{id:`${p}-h`,inputMode:`decimal`,value:o,onChange:e=>s(e.target.value)}),(0,X.jsx)(`p`,{role:c?`alert`:void 0,children:c??`Written as <name>.circuit.tsx in the project folder; Undo removes it again.`}),(0,X.jsx)(`button`,{type:`submit`,disabled:d,children:`Create`})]})}function oh(e,t,n){if(!t)return`Not written in this file`;if(e.library)return`From library part ${e.library}; change it in the library`;if(n.has(t.name))return`Locked`;if(!t.editable)return`Read-only`;let r=t.props.footprint;return r&&r.literal===void 0?`Written as ${r.source}`:void 0}function sh({components:e,parts:t,locked:n}){return e.map(e=>{let r=oh(e,t.find(t=>t.name===e.id),n);return{name:e.id,kind:e.kind,value:e.value??``,footprint:e.footprint??``,...r?{fixed:r}:{}}})}var ch=e=>[...new Set(e.map(e=>e.footprint).filter(e=>e!==``))].sort(),lh=/^[\w.\-+:,=()]+$/;function uh(e,t){let n=e.filter(e=>t[e.name]!==void 0&&t[e.name]?.trim()!==e.footprint);if(n.length===0)return{message:`No footprint was changed.`};let r=n.find(e=>e.fixed);if(r)return{message:`${r.name}: ${r.fixed}`};let i=n.find(e=>!lh.test((t[e.name]??``).trim()));return i?{message:`${i.name}: a footprint is a name such as 0603 or soic8, without spaces`}:{edits:n.map(e=>({kind:`setProps`,part:e.name,props:{footprint:(t[e.name]??``).trim()}})),summary:`change footprints: ${n.slice(0,3).map(e=>`${e.name} → ${(t[e.name]??``).trim()}`).join(`, `)}${n.length>3?` and ${n.length-3} more`:``}`}}function dh({panel:e,onClose:t}){let n=(0,l.useMemo)(()=>e.source?sh(e.source):[],[e.source]),[r,i]=(0,l.useState)({}),[a,o]=(0,l.useState)(),s=(0,l.useId)();if(n.length===0)return(0,X.jsx)(`p`,{children:`The open circuit has no parts yet.`});let c=async i=>{i.preventDefault();let a=uh(n,r);if(`message`in a)return o(a.message);await e.write(a.edits,a.summary)&&t()};return(0,X.jsxs)(`form`,{className:`footprint-manager`,onSubmit:e=>void c(e),children:[(0,X.jsx)(`datalist`,{id:s,children:ch(n).map(e=>(0,X.jsx)(`option`,{value:e},e))}),(0,X.jsxs)(`table`,{children:[(0,X.jsx)(`thead`,{children:(0,X.jsxs)(`tr`,{children:[(0,X.jsx)(`th`,{scope:`col`,children:`Designator`}),(0,X.jsx)(`th`,{scope:`col`,children:`Kind`}),(0,X.jsx)(`th`,{scope:`col`,children:`Value`}),(0,X.jsx)(`th`,{scope:`col`,children:`Footprint`})]})}),(0,X.jsx)(`tbody`,{children:n.map(e=>(0,X.jsxs)(`tr`,{children:[(0,X.jsx)(`td`,{children:e.name}),(0,X.jsx)(`td`,{children:e.kind}),(0,X.jsx)(`td`,{children:e.value}),(0,X.jsx)(`td`,{children:(0,X.jsx)(`input`,{"aria-label":`Footprint of ${e.name}`,list:s,value:r[e.name]??e.footprint,disabled:e.fixed!==void 0,title:e.fixed,onChange:t=>i(n=>({...n,[e.name]:t.target.value}))})})]},e.name))})]}),(0,X.jsx)(`p`,{role:a?`alert`:void 0,children:a??`Changed footprints are written to the circuit file as one change; Undo takes them all back.`}),(0,X.jsx)(`button`,{type:`submit`,children:`Save`})]})}function fh(e,t,n,r,i){let a={code:e,severity:t,message:n,items:Wr(r)};return i?{...a,source:i}:a}var ph={name:`default`,trackWidth:.25,clearance:.2,via:{drill:.3,diameter:.6},patterns:[]};function mh(e){let t=[...e].map(e=>e===`*`?`.*`:e===`?`?`.`:e.replace(/[.+^${}()|[\]\\]/g,`\\$&`)).join(``);return RegExp(`^${t}$`,`s`)}function hh(e,t){if(e===`*`)return!0;let n=mh(e);return t.names.some(e=>n.test(e))}var gh=(e,t)=>e.classes.filter(e=>e.patterns.some(e=>hh(e,t))).map(e=>e.name);function _h(e,t){return gh(e,t)[0]??ph.name}function vh(e,t){let n=new Map,r=[];for(let i of t){let t=gh(e,i);if(n.set(i.id,t[0]??ph.name),t.length<2)continue;let a=`Net ${i.id.replace(/^net\./,``)} matches the net classes ${t.join(` and `)}; it uses ${t[0]}`;r.push(fh(`net-class-conflict`,`error`,a,[i.id]))}return{byNet:n,diagnostics:[...r,...yh(e,t)]}}function yh(e,t){return e.classes.flatMap(e=>e.patterns.filter(e=>!t.some(t=>hh(e,t))).map(t=>fh(`rules`,`warning`,`Net class ${e.name}: the pattern "${t}" matches no net`,[e.name])))}var bh=(e,t)=>e.classes.find(e=>e.name===t)?.clearance??ph.clearance;function xh(e,t,n){let r=e.classClearance.filter(e=>e.a===t&&e.b===n||e.a===n&&e.b===t).map(e=>e.clearance);return Math.max(bh(e,t),bh(e,n),e.fabrication.minClearance,...r)}var Sh=(e,t)=>e.classes.find(n=>n.name===_h(e,t))??ph,Ch=(e,t)=>Math.max(Sh(e,t).trackWidth,e.fabrication.minTrackWidth),wh=e=>Math.round(e*1e6)/1e6;function Th(e,t){let n=Math.max(t.drill,e.fabrication.minDrill);return{drill:n,diameter:Math.max(t.diameter,wh(n+2*e.fabrication.minAnnularRing))}}var Eh=(e,t)=>Th(e,Sh(e,t).via),Dh=e=>Th(e,ph.via),Oh=e=>e.fabrication.filletRadius??1,kh=/^([+-]?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?)\s*(mm|in|mil)?$/i,Ah={mm:1,in:25.4,mil:.0254};function jh(e){if(typeof e==`number`)return Number.isFinite(e)?e:void 0;if(typeof e!=`string`)return;let t=kh.exec(e.trim());if(!t)return;let n=Number(t[1])*(Ah[(t[2]??`mm`).toLowerCase()]??1);return Number.isFinite(n)?n:void 0}var Mh=`Fillet radius`,Nh=`Edit → Fillet tracks rounds corners with this radius. Empty is the default, 1 mm. A track's width is the floor: a smaller radius is raised to the width.`;function Ph(e){let t=e?.filletRadius;return{value:t===void 0?``:String(t),placeholder:`1 mm (default)`}}function Fh(e){if(e.trim()===``)return{radius:null};let t=jh(e);return t===void 0||t<=0||t>50?{message:`Type a length above 0 and at most 50 mm, such as 1, 0.5mm or 40mil, or leave it empty for the default.`}:{radius:Math.round(t*1e6)/1e6}}var Ih=`modulepreload`,Lh=function(e,t){return new URL(e,t).href},Rh={},zh=function(e){return e.pathname.endsWith(`.css`)},Bh=function(e,t,n){if(t in e)return e[t];let r=n();if(!r){e[t]=void 0;return}let i=r.then(()=>{e[t]=void 0},n=>{throw e[t]=void 0,n});return e[t]=i,i},Vh=function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){let e,i=document.querySelector(`meta[property=csp-nonce]`),a=i?.nonce||i?.getAttribute(`nonce`);function o(e){return Promise.all(e.map(e=>Promise.resolve(e).then(e=>({status:`fulfilled`,value:e}),e=>({status:`rejected`,reason:e}))))}function s(e){return import.meta.resolve?new URL(import.meta.resolve(e)):new URL(e,import.meta.url)}r=o(t.map(t=>{t=Lh(t,n);let r=s(t),i=zh(r);return Bh(Rh,r.href,()=>{if(e===void 0){e={all:new Set,styles:new Set};let t=document.getElementsByTagName(`link`);for(let n=t.length-1;n>=0;n--){let r=t[n];e.all.add(r.href),r.rel===`stylesheet`&&e.styles.add(r.href)}}if((i?e.styles:e.all).has(r.href))return;let t=document.createElement(`link`);if(t.rel=i?`stylesheet`:Ih,i||(t.as=`script`),t.crossOrigin=``,t.href=r.href,a&&t.setAttribute(`nonce`,a),document.head.appendChild(t),i)return new Promise((e,n)=>{t.addEventListener(`load`,e),t.addEventListener(`error`,()=>n(Error(`Unable to preload CSS for ${r}`)))})})}).filter(e=>e!==void 0))}function i(e){let t=new Event(`vite:preloadError`,{cancelable:!0});if(t.payload=e,window.dispatchEvent(t),!t.defaultPrevented)throw e}return r.then(t=>{for(let e of t||[])e.status===`rejected`&&i(e.reason);return e().catch(i)})},Hh=wm(()=>Vh(()=>import(`./NewPartDialog-Qb7NwhBb.js`).then(e=>e.NewPartForm),[],import.meta.url)),Uh=`button, [href], input, select, textarea, [tabindex]:not([tabindex='-1'])`;function Wh(e,t){zp(!0,n=>{let r=Pp(n.key);if(r===`hold`)return;if(n.preventDefault(),r===`close`)return t();let i=[...e.current?.querySelectorAll(Uh)??[]];(i[Fp(i.indexOf(document.activeElement),i.length,n.shiftKey)]??e.current)?.focus()})}function Gh({title:e,onClose:t,children:n,wide:r=!1}){let i=(0,l.useRef)(null);return(0,l.useEffect)(()=>{let e=document.activeElement;return(i.current?.querySelector(`[data-default]`)??i.current?.querySelector(Uh)??i.current)?.focus(),()=>{e instanceof HTMLElement&&e.isConnected&&e.focus()}},[]),Wh(i,t),(0,X.jsx)(`div`,{className:`dialog-backdrop`,onPointerDown:e=>e.target===e.currentTarget&&t(),children:(0,X.jsxs)(`section`,{ref:i,tabIndex:-1,className:r?`dialog wide`:`dialog`,role:`dialog`,"aria-modal":`true`,"aria-label":e,children:[(0,X.jsxs)(`header`,{className:`hairline-b`,children:[(0,X.jsx)(`h2`,{children:e}),(0,X.jsx)(`button`,{className:`icon`,"aria-label":`Close`,onClick:t,children:(0,X.jsx)(Ap,{})})]}),(0,X.jsx)(`div`,{className:`dialog-body`,children:n})]})})}function Kh(){return(0,X.jsx)(`table`,{children:(0,X.jsx)(`tbody`,{children:Xp().map(e=>(0,X.jsxs)(`tr`,{children:[(0,X.jsx)(`td`,{children:(0,X.jsx)(`kbd`,{children:e.keys})}),(0,X.jsx)(`td`,{children:e.label})]},e.keys))})})}function qh({rules:e,onClose:t}){let n=Ph(e.fabrication),[r,i]=(0,l.useState)(n.value),[a,o]=(0,l.useState)(),s=(0,l.useId)(),c=async i=>{i.preventDefault();let a=Fh(r);if(`message`in a)return o(a.message);if(r.trim()===n.value)return t();await e.save(a.radius)&&t()};return(0,X.jsxs)(`form`,{className:`rules-form`,onSubmit:e=>void c(e),children:[(0,X.jsx)(`label`,{htmlFor:s,children:Mh}),(0,X.jsx)(`input`,{id:s,value:r,placeholder:n.placeholder,onChange:e=>i(e.target.value),"aria-describedby":`${s}-note`,"aria-invalid":a!==void 0}),(0,X.jsx)(`p`,{id:`${s}-note`,children:a??Nh}),(0,X.jsx)(`p`,{children:`The rest of the design rules are in rules.yaml in the project.`}),(0,X.jsx)(`button`,{type:`submit`,children:`Save`})]})}function Jh({panel:e,onClose:t}){let n=e=>()=>{t(),e()};return(0,X.jsxs)(`div`,{className:`rules-form`,children:[(0,X.jsx)(`p`,{children:e.question}),(0,X.jsx)(`button`,{type:`button`,"data-default":!0,onClick:n(e.showChecks),children:`Show checks`}),(0,X.jsx)(`button`,{type:`button`,onClick:n(e.exportAnyway),children:`Export anyway`})]})}function Yh({name:e,onClose:t,rules:n,makeSheet:r,importPart:i,newPart:a,system:o,newCircuit:s,footprints:c,exportChecks:l}){return e===`exportChecks`?(0,X.jsx)(Gh,{title:`Fabrication files`,onClose:t,children:(0,X.jsx)(Jh,{panel:l,onClose:t})}):e===`footprints`?(0,X.jsx)(Gh,{title:`Footprint manager`,onClose:t,wide:!0,children:(0,X.jsx)(dh,{panel:c,onClose:t})}):e===`newCircuit`?(0,X.jsx)(Gh,{title:`New circuit`,onClose:t,children:(0,X.jsx)(ah,{panel:s,onClose:t})}):e===`system`?(0,X.jsx)(Gh,{title:`System settings`,onClose:t,children:(0,X.jsx)(eh,{panel:o,onClose:t})}):e===`newPart`?(0,X.jsx)(Gh,{title:`New part`,onClose:t,wide:!0,children:(0,X.jsx)(Em,{what:`New part`,onRetry:Hh.retry,render:()=>{let e=Hh.component();return(0,X.jsx)(e,{panel:a,onClose:t})}})}):e===`importPart`?(0,X.jsx)(Gh,{title:`Import by LCSC number`,onClose:t,children:(0,X.jsx)(am,{panel:i,onClose:t})}):e===`makeSheet`?(0,X.jsx)(Gh,{title:`Make sub-sheet`,onClose:t,children:(0,X.jsx)(Sm,{panel:r,onClose:t})}):e===`rules`?(0,X.jsx)(Gh,{title:`Design rules`,onClose:t,children:(0,X.jsx)(qh,{rules:n,onClose:t})}):e===`keys`?(0,X.jsx)(Gh,{title:`Keys`,onClose:t,children:(0,X.jsx)(Kh,{})}):(0,X.jsxs)(Gh,{title:`About copperflow`,onClose:t,children:[(0,X.jsxs)(`p`,{children:[(0,X.jsx)(`strong`,{children:`copperflow`}),` Studio`]}),(0,X.jsx)(`p`,{children:`Design circuits in code with a human and an AI agent editing the same files.`}),(0,X.jsx)(`p`,{children:`Apache License 2.0`})]})}function Xh(e){return`Created ${e.id}: ${e.title}, ${e.pins} pin${e.pins===1?``:`s`}, footprint ${e.footprint}. Not verified: check it in ${e.verification}.`}function Zh({label:e,shortcut:t,menu:n,index:r,enabled:i,checked:a,reason:o,onActivate:s}){return(0,X.jsxs)(`button`,{role:a===void 0?`menuitem`:`menuitemcheckbox`,"aria-checked":a,className:a?`menu-item checked`:`menu-item`,...n===void 0?{}:{"data-menu":n},"data-item":r,tabIndex:-1,"aria-disabled":!i||void 0,title:o,onClick:e=>{let t=!Qf(e);t||ep(e),i&&s(t)},children:[(0,X.jsx)(`span`,{children:e}),t&&(0,X.jsx)(`kbd`,{children:t})]})}function Qh(e,t,n){(0,l.useEffect)(()=>{if(!e)return;let r=e=>{e.target instanceof Node&&t.current?.contains(e.target)||n()};return window.addEventListener(`pointerdown`,r,!0),()=>window.removeEventListener(`pointerdown`,r,!0)},[e,t,n])}var $h=(e,t)=>(e+t)%t,eg=e=>e===`item`||e===`disabled`;function tg(e,t,n,r=eg){let i=e.length,a=t??(n===1?-1:i);for(let t=0;t<i;t++)if(a=$h(a+n,i),r(e[a]))return a;return null}var ng=e=>e?tg(e,null,1):null,rg=e=>e?tg(e,null,-1):null,ig=(e,t)=>e?tg(e,null,t,e=>e===`item`)??tg(e,null,t):null,ag=e=>ig(e,1),og=e=>ig(e,-1),sg=(e,t,n=!0)=>({open:e,focus:t,preventDefault:n}),cg=(e,t)=>sg(e,{menu:e,item:t});function lg(e,t,n,r){let i=r.length,a={ArrowLeft:$h(t-1,i),ArrowRight:$h(t+1,i),Home:0,End:i-1}[e];return a===void 0?e===`ArrowDown`?cg(t,ag(r[t])):e===`ArrowUp`?cg(t,og(r[t])):n===null?null:e===`Escape`?sg(null,{menu:t,item:null}):e===`Tab`?sg(null,`keep`,!1):null:sg(n===null?null:a,{menu:a,item:null})}function ug(e,t,n){let r=n[t.menu]??[],i=n.length,a={ArrowDown:tg(r,t.item,1),ArrowUp:tg(r,t.item,-1),Home:ng(r),End:rg(r)};if(e in a)return cg(t.menu,a[e]??null);if(e===`ArrowLeft`||e===`ArrowRight`){let r=$h(t.menu+(e===`ArrowLeft`?-1:1),i);return cg(r,ag(n[r]))}return e===`Escape`?sg(null,{menu:t.menu,item:null}):e===`Tab`?sg(null,{menu:t.menu,item:null},!1):null}function dg(e,t,n){return e===`Escape`?sg(null,`keep`):e===`Tab`?sg(null,`keep`,!1):e===`ArrowDown`||e===`Home`?cg(t,ag(n[t])):e===`ArrowUp`||e===`End`?cg(t,og(n[t])):e===`ArrowLeft`||e===`ArrowRight`?sg($h(t+(e===`ArrowLeft`?-1:1),n.length),`keep`):null}function fg(e,t,n,r,i={}){return r.length===0||(i.alt||i.ctrl||i.meta)&&e!==`Tab`?null:t===null?n===null?null:dg(e,n,r):t.item===null?lg(e,t.menu,n,r):ug(e,{menu:t.menu,item:t.item},r)}function pg(e){return ag(e)}var mg=e=>e.item===null?`[data-menu="${e.menu}"]:not([data-item])`:`[data-menu="${e.menu}"][data-item="${e.item}"]`;function hg(e,t){let n=t instanceof HTMLElement&&e?.contains(t)?t.closest(`[data-menu]`):null;if(!n)return null;let r=n.dataset.item;return{menu:Number(n.dataset.menu),item:r===void 0?null:Number(r)}}function gg(e){let t=(0,l.useRef)(null);return(0,l.useLayoutEffect)(()=>{let n=t.current;n&&(t.current=null,e.current?.querySelector(mg(n))?.focus())}),(0,l.useCallback)(n=>{let r=e.current?.querySelector(mg(n));r?r.focus():t.current=n},[e])}function _g({entry:e,menu:t,index:n,view:r,selected:i,off:a,toggles:o,onRun:s}){if(e===`separator`)return(0,X.jsx)(`li`,{className:`menu-separator`,role:`separator`});let{label:c,shortcut:l,command:u,toggle:d}=e,{enabled:f,reason:p}=qp(e,r,i,a);return(0,X.jsx)(`li`,{role:`none`,children:(0,X.jsx)(Zh,{label:c,...l?{shortcut:l}:{},...d?{checked:o[d]}:{},menu:t,index:n,enabled:f,...p?{reason:p}:{},onActivate:e=>u&&s(u,t,e)})})}function vg({menu:e,index:t,view:n,selected:r,off:i,toggles:a,onRun:o}){return(0,X.jsx)(`ul`,{className:`menu-dropdown`,role:`menu`,"aria-label":e.title,children:e.entries.map((e,s)=>(0,X.jsx)(_g,{entry:e,menu:t,index:s,view:n,selected:r,off:i,toggles:a,onRun:o},e===`separator`?`sep${s}`:e.label))})}function yg({menu:e,index:t,open:n,current:r,onPointer:i,onHover:a,onKeyboard:o,view:s,selected:c,off:l,toggles:u,onRun:d}){return(0,X.jsxs)(`div`,{className:`menu`,children:[(0,X.jsx)(`button`,{role:`menuitem`,"data-menu":t,"aria-haspopup":`menu`,"aria-expanded":n,tabIndex:r?0:-1,className:`menu-title${n?` open`:``}`,onClick:e=>{if(!Qf(e))return o({open:t,focus:{menu:t,item:pg(Qp(s,c,l)[t])},preventDefault:!0});ep(e),i(t)},onPointerEnter:()=>a(t),children:e.title}),n&&(0,X.jsx)(vg,{menu:e,index:t,view:s,selected:c,off:l,toggles:u,onRun:d})]})}function bg({run:e,view:t,selected:n,toggles:r,off:i,children:a}){let[o,s]=(0,l.useReducer)(Zp,{open:null}),[c,u]=(0,l.useState)(0),d=(0,l.useRef)(null),f=gg(d),p=o.open===null?null:Gp.findIndex(e=>e.title===o.open),m=(0,l.useMemo)(()=>Qp(t,n,i),[t,n,i]),h=e=>{s({type:`set`,title:e.open===null?null:Gp[e.open]?.title??null}),e.focus!==`keep`&&(u(e.focus.menu),f(e.focus))},g=e=>{let t=fg(e.key,hg(d.current,document.activeElement),p,m,{alt:e.altKey,ctrl:e.ctrlKey,meta:e.metaKey});return t?(t.preventDefault&&e.preventDefault(),h(t),!0):!1};zp(p!==null,e=>void g(e)),Qh(p!==null,d,(0,l.useCallback)(()=>s({type:`outside`}),[]));let _=(t,n,r)=>{r&&h({open:null,focus:{menu:n,item:null},preventDefault:!0}),s({type:`run`}),e(t)},v=e=>{u(e),s({type:`click`,title:Gp[e]?.title??``})},y=e=>s({type:`hover`,title:Gp[e]?.title??``});return(0,X.jsxs)(`header`,{className:`menubar hairline-b`,ref:d,children:[(0,X.jsx)(`span`,{className:`brand`,title:`copperflow`,children:`copperflow`}),(0,X.jsx)(`nav`,{className:`menus`,role:`menubar`,"aria-label":`Menu`,onKeyDown:e=>g(e)&&e.stopPropagation(),children:Gp.map((e,a)=>(0,X.jsx)(yg,{menu:e,index:a,open:p===a,current:c===a,onPointer:v,onHover:y,onKeyboard:h,view:t,selected:n,off:i,toggles:r,onRun:_},e.title))}),(0,X.jsx)(`div`,{className:`menubar-end`,children:a})]})}var xg=`Main`;function Sg(e){let t=e?.schematic.pages?.map(e=>e.name);return t&&t.length>0?t:[xg]}function Cg(e,t){let n=Sg(e);return n.includes(t)?t:n[0]??`Main`}function wg(e,t){let n=e.schematic.pages??[],r=n.find(e=>e.name===t);if(n.length<=1||!r)return e;let i=(e,t,n)=>{let r=new Set(t);return e.filter(e=>r.has(n(e)))},{schematic:a}=e;return{...e,schematic:{...a,symbols:i(a.symbols,r.parts,e=>e.component),wires:i(a.wires,r.wires,e=>e.id),labels:i(a.labels,r.labels,e=>e.id),drawings:i(a.drawings,r.drawings,e=>e.id),junctions:r.junctions,...a.noConnects?{noConnects:i(a.noConnects,r.parts,e=>e.component)}:{}}}}function Tg(e){for(let t=e.length+1;;t++)if(!e.includes(`Page ${t}`))return`Page ${t}`}function Eg(e,t){if(t===`Main`)return`${xg} is the first page and cannot be deleted`;let n=e?.schematic.pages?.find(e=>e.name===t)?.parts??[];if(n.length>0)return`Page ${t} still has parts (${n.join(`, `)}); move or delete them first`;let r=e?.circuit.connections.filter(e=>e.page===t)??[];if(r.length===0)return;let i=r.map(e=>`${e.from.replace(/^net\./,``)} to ${e.to.replace(/^net\./,``)}`).join(`, `);return`${t} still has ${r.length===1?`1 trace`:`${r.length} traces`}: ${i}; move or remove ${r.length===1?`it`:`them`} first`}function Dg(e){return e===`Main`?`${xg} is the first page and keeps its name`:void 0}function Og(e,t){return e.status===`building`?`Building`:e.status===`failed`?`Build failed`:e.status!==`done`||!e.design?`Not built`:t===0?`Build OK`:`${t} ${t===1?`error`:`errors`}`}function kg(e,t){return e.status===`building`?`busy`:e.status===`failed`||t>0?`bad`:e.status===`done`?`good`:`idle`}function Ag({build:e,errors:t,onOpen:n}){return(0,X.jsxs)(`button`,{className:`build ${kg(e,t)}`,onClick:e=>{rp(e),n()},title:`Show DRC`,children:[(0,X.jsx)(`span`,{className:`dot`,"aria-hidden":`true`}),(0,X.jsx)(`span`,{role:`status`,children:Og(e,t)})]})}var jg=`light`,Mg=`copperflow.theme`,Ng=()=>typeof window>`u`?void 0:window.localStorage,Pg=e=>e===`dark`||e===`light`?e:jg;function Fg(e){try{return Pg(e()?.getItem(Mg))}catch{return jg}}function Ig(e,t){try{let n=e();return n?(n.setItem(Mg,t),!0):!1}catch{return!1}}function Lg(e,t){e.setAttribute(`data-theme`,t)}var Rg=e=>({themeLight:e===`light`,themeDark:e===`dark`}),zg=e=>e===`dark`?`dots`:`lines`,Bg=(e,t,n)=>t===n?e:Vg(e,n),Vg=(e,t)=>({...e,schematic:zg(t)}),Hg=(e,t,n,r,i)=>({id:e,title:t,icon:n,command:r,group:i}),Ug=(e,t,n,r,i)=>({id:e,title:t,icon:n,pending:r,group:i}),Wg=[Hg(`undo`,`Undo (Ctrl+Z)`,`undo`,`undo`,0),Hg(`redo`,`Redo (Ctrl+Y)`,`redo`,`redo`,0)],Gg=[Hg(`zoomIn`,`Zoom in`,`zoomIn`,`zoomIn`,1),Hg(`zoomOut`,`Zoom out`,`zoomOut`,`zoomOut`,1),Hg(`fit`,`Fit all (K)`,`fit`,`fit`,1),Hg(`fitSelection`,`Fit selection`,`fitSelection`,`fitSelection`,1),Hg(`fitArea`,`Fit area`,`fitArea`,`fitArea`,1)],Kg=e=>[Hg(`rotate`,`Rotate (Space)`,`rotate`,`rotate`,e),Hg(`rotateRight`,`Rotate right`,`rotateRight`,`rotateRight`,e)],qg=e=>[Hg(`gridStyle`,`Grid style`,`grid`,`gridStyle`,e),Hg(`snap`,`Snap (Alt+S)`,`snap`,`snap`,e)],Jg=e=>[Hg(`alignLeft`,`Align left (Ctrl+Shift+L)`,`alignLeft`,`alignLeft`,e),Hg(`distributeH`,`Distribute horizontally (Ctrl+Shift+H)`,`distributeH`,`distributeH`,e)],Yg=e=>Hg(`checkDrc`,`Check DRC`,`check`,`checkDrc`,e),Xg={schematic:[...Wg,...Gg,...qg(2),Hg(`component`,`Component (Shift+F)`,`component`,`placeComponent`,3),Hg(`wire`,`Wire (Alt+W)`,`wire`,`wire`,3),Hg(`bus`,`Bus (Alt+B)`,`bus`,`drawBus`,3),Hg(`netLabel`,`Net label (Alt+N)`,`netLabel`,`netLabel`,3),Hg(`ground`,`Ground flag`,`ground`,`groundFlag`,3),Hg(`power`,`Power flag`,`power`,`powerFlag`,3),Hg(`noConnect`,`No connect flag`,`noConnect`,`noConnect`,3),Hg(`polyline`,`Polyline (Alt+L)`,`polyline`,`drawPolyline`,4),Hg(`arc`,`Arc (Alt+A)`,`arc`,`drawArc`,4),Hg(`circle`,`Circle (Alt+C)`,`circle`,`drawCircle`,4),Hg(`rectangle`,`Rectangle (Alt+R)`,`rectangle`,`drawRectangle`,4),Hg(`text`,`Text (Alt+T)`,`text`,`drawText`,4),...Kg(5),...Jg(6),Yg(7)],pcb:[...Wg,...Gg,{id:`unit`,title:`Unit (Q)`,text:`unit`,command:`toggleUnit`,group:2},...qg(2),Hg(`via`,`Via (Alt+V)`,`via`,`placeVia`,3),Ug(`boardOutline`,`Board outline`,`boardOutline`,Wp,3),Ug(`copperArea`,`Copper area`,`copperArea`,Wp,3),Yg(4),Hg(`singleRouting`,`Single routing (Alt+W)`,`singleRouting`,`singleRouting`,5),...Jg(6),...Kg(7),Hg(`gerber`,`Gerber`,`gerber`,`exportFabrication`,8)]};function Zg(e,t,n={}){if(e.pending!==void 0)return{enabled:!1,title:`${e.title}: ${e.pending}`};let r=n[e.command];if(r!==void 0)return{enabled:!1,title:`${e.title}: ${r}`};let i=Up(e.command,t);return i?{enabled:!1,title:`${e.title}: ${i}`}:{enabled:!0,title:e.title}}function Qg(e){let t=[];for(let n of Xg[e]){let e=t.at(-1);e&&e[0]?.group===n.group?e.push(n):t.push([n])}return t}var $g=new Set([`wire`,`netLabel`,`groundFlag`,`powerFlag`,`fitArea`,`singleRouting`,`placeVia`,`noConnect`,`junction`,...x]);function e_(e){return $g.has(e)}var t_={snap:`snap`};function n_(e,t,n){let r=t_[e];return r?n[r]:t===e}function r_(e){return e_(e)||e in t_}function i_(e,t){return e?`wire`:t===`label`?`netLabel`:t===`gnd`?`groundFlag`:t===`vcc`?`powerFlag`:null}function a_(e){return e?S[e]:null}var o_={active:null,stop:null},s_=o_,c_=new Set;function l_(e){if(e.active!==s_.active||e.stop!==s_.stop){s_=e;for(let e of c_)e()}}function u_(){return s_}function d_(){l_(o_)}function f_(e){return c_.add(e),()=>{c_.delete(e)}}function p_(){return(0,l.useSyncExternalStore)(f_,u_)}function m_(e,t){return t.active===e&&t.stop?`stop`:`run`}var h_=o(),g_=[`onPointerDown`,`onPointerMove`,`onPointerUp`,`onPointerCancel`,`onMouseDown`,`onMouseMove`,`onMouseUp`,`onDoubleClick`,`onWheel`,`onContextMenu`];function __(){let e=e=>e.stopPropagation();return Object.fromEntries(g_.map(t=>[t,e]))}var v_=`toolbar-view-slot`,y_=__();function b_({children:e}){let[t,n]=(0,l.useState)(null);return(0,l.useLayoutEffect)(()=>n(document.getElementById(v_)),[]),t?(0,h_.createPortal)((0,X.jsx)(`div`,{className:`canvas-tools`,...y_,onClick:rp,children:e}),t):null}function x_({item:e,unit:t}){if(e.text===`unit`)return(0,X.jsx)(X.Fragment,{children:t});let n=Np[e.icon];return(0,X.jsx)(n,{})}function S_({view:e,unit:t,selected:n,toggles:r,off:i,run:a}){let o=p_();return(0,X.jsxs)(`div`,{className:`studio-toolbar hairline-b`,role:`toolbar`,"aria-label":`Tools`,children:[Qg(e).map((e,s)=>(0,X.jsxs)(l.Fragment,{children:[s>0&&(0,X.jsx)(`span`,{className:`toolbar-separator`,role:`separator`,"aria-orientation":`vertical`}),e.map(e=>{let s=e.command!==void 0&&n_(e.command,o.active,r),c=Zg(e,n,i);return(0,X.jsx)(`button`,{className:e.text?`toolbar-button text`:`toolbar-button`,title:c.title,"aria-label":e.text===`unit`?`${e.title}, now ${t}`:c.title,"aria-disabled":!c.enabled||void 0,"aria-pressed":e.command!==void 0&&r_(e.command)?s:void 0,"data-pressed":s||void 0,onClick:t=>{rp(t),c.enabled&&e.command!==void 0&&(m_(e.command,o)===`stop`?o.stop?.():a(e.command))},children:(0,X.jsx)(x_,{item:e,unit:t})},e.id)})]},e[0]?.group)),(0,X.jsx)(`div`,{className:`toolbar-view-slot`,id:v_})]})}var C_=[`Designators`,`Quantity`,`Value`,`Footprint`,`Manufacturer`,`MPN`,`Supplier part`,`Verified`];function w_(e){return/[",\r\n]/.test(e)?`"${e.replace(/"/g,`""`)}"`:e}function T_(e){return[C_,...e.map(e=>[e.designators.join(` `),String(e.quantity),e.value||e.kind,e.footprint,e.manufacturer,e.mpn,e.supplier,e.libraryPart?e.verified?`yes`:`no`:``])].map(e=>e.map(w_).join(`,`)).join(`\r
13
+ `))r(a.slice(0,e)),a=a.slice(e+2)}}catch(e){if(n.signal.aborted)return;e instanceof TypeError&&t?.(!1)}await new Promise(e=>setTimeout(e,ae))}})(),()=>n.abort()}var ue=.5,de=2e3;function fe(e,t,n){return{x:(n.x-e.cx)*e.scale+t.width/2,y:-(n.y-e.cy)*e.scale+t.height/2}}function pe(e,t,n){return{x:(n.x-t.width/2)/e.scale+e.cx,y:-(n.y-t.height/2)/e.scale+e.cy}}function me(e,t,n=.12){let r=Math.max(e.maxX-e.minX,1),i=Math.max(e.maxY-e.minY,1),a=Math.min(t.width/r,t.height/i)*(1-2*n);return{cx:(e.minX+e.maxX)/2,cy:(e.minY+e.maxY)/2,scale:we(a)}}function he(e,t){return{...e,cx:t.x,cy:t.y}}function ge(e,t,n,r){let i=pe(e,t,n),a=we(e.scale*r);return{scale:a,cx:i.x-(n.x-t.width/2)/a,cy:i.y+(n.y-t.height/2)/a}}var z=e=>Math.round(e*1e4)/1e4;function _e(e,t){let n=Math.max(0,-Math.floor(Math.log10(t))+2);return Number((Math.round(e/t)*t).toFixed(n))}var ve=(e,t,n=!0)=>z(n?_e(e,t):e),ye=(e,t,n=!0)=>({x:ve(e.x,t,n),y:ve(e.y,t,n)});function be(e,t){let n=e=>(e.maxX-e.minX)*(e.maxY-e.minY);return e.filter(({box:e})=>t.x>=e.minX&&t.x<=e.maxX&&t.y>=e.minY&&t.y<=e.maxY).sort((e,t)=>n(e.box)-n(t.box))}function xe(e){if(e.length===0)return;let t=e.map(e=>e.x),n=e.map(e=>e.y);return{minX:Math.min(...t),minY:Math.min(...n),maxX:Math.max(...t),maxY:Math.max(...n)}}function Se(e){return xe(e.flatMap(e=>[{x:e.minX,y:e.minY},{x:e.maxX,y:e.maxY}]))}function Ce(e){let t=[];for(let n of e){let e=t[t.length-1];e&&e.x!==n.x&&e.y!==n.y&&t.push({x:n.x,y:e.y}),e&&e.x===n.x&&e.y===n.y||t.push(n)}return t}function we(e){return Math.min(de,Math.max(ue,e))}var Te={pcb:{position:[`pcbX`,`pcbY`],rotation:`pcbRotation`,where:``,notePrompt:`Note for the agent, e.g. route ground here`},schematic:{position:[`schX`,`schY`],rotation:`schRotation`,where:` in the schematic`,notePrompt:`Note for the agent, e.g. add a pull-up here`}},Ee={x:0,y:0};function De(e,t){let n=new Map(e.circuit.components.map(e=>[e.id,t===`pcb`?e.groupOffset.pcb:e.groupOffset.sch])),r=t===`pcb`?e.pcb.parts:e.schematic.symbols;return new Map(r.map(e=>[e.component,{origin:{x:e.x,y:e.y},group:n.get(e.component)??Ee,autoPlaced:e.autoPlaced}]))}function Oe(e,t,n,r){let i=e.model.parts.find(e=>e.name===n);if(!i)return`This part has no editable source element`;if(t.has(n))return`${n} is locked`;if(!i.editable)return`${n} is read-only (${i.readonlyReason})`;let a=Te[r].position.find(e=>i.props[e]&&!i.props[e]?.editable);return a?`${n}.${a} is an expression; change it in the code`:null}function ke(e,t,n,r=90){let i=Te[n].rotation,a=e.model.parts.find(e=>e.name===t)?.props[i]?.literal;return a!==void 0&&typeof a!=`number`?`${t}.${i} is not a number`:(((a??0)+r)%360+360)%360}function Ae(e,t,n,r){let i=e.model.parts.find(e=>e.name===t)?.props,[a,o]=Te[n].position,s=(e,t,n)=>{let r=i?.[e]?.literal;return typeof r==`number`?r:t-n};return{x:s(a,r.origin.x,r.group.x),y:s(o,r.origin.y,r.group.y)}}function je(e,t,n,r,i){let a=Ae(e,t,n,r);return[z(a.x+i.x),z(a.y+i.y)]}var Me=`Keep auto-placed positions`,Ne=`a repeated name cannot be addressed from the Studio`,Pe=e=>Math.round(e*100)/100;function Fe(e,t){let n=t===`pcb`?e.pcb.parts:e.schematic.symbols;return new Map(n.map(e=>[e.component,e.rotation]))}var Ie=(e,t,n)=>e?.model.parts.find(e=>e.name===t)?.props[Te[n].rotation]!==void 0;function Le(e,t,n=()=>null,r){let[i,a]=Te[t].position,o=Fe(e,t),s=[],c=[];for(let[l,{origin:u,group:d,autoPlaced:f}]of De(e,t)){if(!f)continue;let e=l.includes(`~`)?Ne:n(l);if(e!==null){c.push({part:l,reason:e});continue}let p=o.get(l)??0,m={[i]:Pe(u.x-d.x),[a]:Pe(u.y-d.y),...p!==0||Ie(r,l,t)?{[Te[t].rotation]:p}:{}};s.push({kind:`setProps`,part:l,props:m})}return{edits:s,skipped:c}}function Re(e,t){return t.skipped.length===0?e:`${e} Skipped ${t.skipped.map(e=>`${e.part} (${e.reason})`).join(`, `)}.`}function ze(e){let t=e.edits.length;return Re(t===0?`No auto-placed part could be kept.`:`Kept the positions of ${t} auto-placed ${t===1?`part`:`parts`}.`,e)}function Be(e,t,n,r){if(e.edits.length===0)return r.notify(n(e));r.edit(e.edits,t).then(t=>{t&&r.notify(n(e))})}function Ve(e,t,n,r,i){Be(Le(e,t,n,i),Me,ze,r)}var He=`Tidy sheet`,Ue=`Every part on the sheet has a position of its own`,We=`The schematic is not built yet`;function Ge(e,t){if(!e)return new Set;let n=t===`pcb`?e.pcb.parts:e.schematic.symbols;return new Set(n.flatMap(e=>e.autoPlaced?[e.component]:[]))}function Ke(e){return e?Ge(e,`schematic`).size>0?null:Ue:We}var qe=(e,t=()=>null,n)=>Le(e,`schematic`,t,n);function Je(e){let t=e.edits.length;return Re(t===0?`Tidied the sheet: no part Studio placed could be written.`:`Tidied the sheet: wrote the positions of ${t} ${t===1?`part`:`parts`} Studio placed.`,e)}function Ye(e,t,n,r){let i=Ke(e);if(i!==null)return n.notify(i);Be(qe(e,t,r),He,Je,n)}var Xe=/\.sheet\.tsx$/,Ze=e=>e!==void 0&&Xe.test(e),Qe=e=>(e.split(`/`).pop()??e).replace(Xe,``),$e=3;function et(e){return e.length<=1?e[0]??``:e.length>$e?`${e.slice(0,$e).join(`, `)} and ${e.length-$e} more`:`${e.slice(0,-1).join(`, `)} and ${e.at(-1)}`}var tt=e=>e.length>1?[`${e.length} wires`]:[...e],nt=e=>`by ${e}°`;function rt(e,t,n,r,i=90){let{rotation:a,where:o}=Te[n],s=[],c=[];for(let a of t){let t=r(a)??ke(e,a,n,i);typeof t==`string`?c.push(t):s.push({name:a,to:t})}let l=s.map(e=>e.name),[u]=s,d=s.length===1&&u?`rotate ${u.name}${o} to ${u.to}°`:`rotate ${et(l)}${o} ${nt(i)}`;return{edits:s.map(e=>({kind:`setProps`,part:e.name,props:{[a]:e.to}})),summary:d,parts:l,skipped:c,done:`rotated`}}function it(e,t,n,r,i,a){let[o,s]=Te[n].position,{where:c}=Te[n],l=t.flatMap(e=>a(e)??[]),u=t.filter(e=>a(e)===null),d=u.map(t=>({name:t,to:je(e,t,n,r(t),i)})),[f]=d,p=d.length===1&&f?`move ${f.name}${c} to (${f.to[0]}, ${f.to[1]})`:`move ${et(u)}${c} by (${z(i.x)}, ${z(i.y)})`;return{edits:d.map(({name:e,to:t})=>({kind:`setProps`,part:e,props:{[o]:t[0],[s]:t[1]}})),summary:p,parts:u,skipped:l,done:`moved`}}function at(e,t){return n=>e.get(n)??{origin:t.find(e=>e.name===n)?.center??Ee,group:Ee}}function ot(e,t,n,r=!0){let i=r?t:t/10;return{x:z(e.dx*i*n),y:z(e.dy*i*n)}}function st(e,t){let n=Se(e);return n?{x:_e((n.minX+n.maxX)/2,t),y:_e((n.minY+n.maxY)/2,t)}:void 0}function ct(e,t,n=90){let r=n>0?1:-1;return{x:t.x-r*(e.y-t.y),y:t.y+r*(e.x-t.x)}}function lt(e,t,n,r,i,a,o=()=>!0,s=90){if(t.length===1)return rt(e,t,n,a,s);let{rotation:c,position:l,where:u}=Te[n],d=[],f=[],p=[];for(let u of t){if(!o(u)){p.push(`${u} is not in this view`);continue}let t=a(u)??ke(e,u,n,s);if(typeof t==`string`){p.push(t);continue}let m=r(u),h=m.origin,g=ct(h,i,s),[_,v]=je(e,u,n,m,{x:g.x-h.x,y:g.y-h.y});d.push({kind:`setProps`,part:u,props:{[l[0]]:_,[l[1]]:v,[c]:t}}),f.push(u)}return{edits:d,summary:`rotate ${et(f)}${u} ${nt(s)}`,parts:f,skipped:p,done:`rotated`}}function ut(e){let t=new Set(e.boxes.map(e=>e.name));return n=>t.has(n)||e.anchors.has(n)}function dt(e,t,n,r,i,a=90){if(t.length===1)return rt(e,t,n,i,a);let o=st(r.boxes.filter(e=>t.includes(e.name)).map(e=>e.box),r.step);return o?lt(e,t,n,at(r.anchors,r.boxes),o,i,ut(r),a):{message:`None of the selected parts is in this view.`}}function ft(e,t,n,r,i,a){let o=ut(r),s=t.filter(e=>!o(e)).map(e=>`${e} is not in this view`),c=it(e,t.filter(o),n,at(r.anchors,r.boxes),i,a);return{...c,skipped:[...s,...c.skipped]}}function pt(e,t){let n=e.flatMap(e=>t(e)??[]),r=e.filter(e=>t(e)===null);return{edits:r.map(e=>({kind:`removePart`,part:e})),summary:`remove ${et(r)}`,parts:r,skipped:n,done:`removed`}}function mt(e,t=0){let n=e.length===1?`${e[0]} and its connections`:`${e.length} parts (${et(e)}) and their connections`;return t===0?`Remove ${n}?`:`Remove ${n}, and ${t} ${t===1?`wire`:`wires`}?`}function ht(e){if(e.skipped.length===0)return;let t=e.skipped.join(`; `);return e.edits.length===0?t:`Not ${e.done}: ${t}`}function gt(e,t,n,r=new Set){if(e.length===0)return{message:`Select a part first.`};let i=e.filter(e=>n?!t.has(e)||r.has(e):t.has(e));if(i.length>0)return{parts:i};let a=e.length===1?`is`:`are`;return{message:`${et(e)} ${a} ${n?`already locked`:`not locked`}.`}}async function _t(e,t){return(await vt(e,t)).ok}async function vt(e,t){let n=ht(e);if(e.edits.length===0)return n&&t.notify(n),{ok:!1};let r=t.editMarked?await t.editMarked(e.edits,e.summary):{ok:await t.edit(e.edits,e.summary)};return r.ok&&n&&t.notify(n),r}var yt={reference:.16,value:.16,"pin-name":.12,"pin-number":.1},bt=.6,xt=e=>Math.round(e*1e6)/1e6,St=(e,t)=>({x:xt(e),y:xt(t)}),Ct=(...e)=>({type:`polyline`,points:e.map(([e,t])=>St(e,t))});function wt(e,t,n,r){return{type:`text`,text:e,at:t,anchor:n,size:yt[r],role:r}}function Tt(e){let t=bt*e.size*e.text.length,n=e.anchor===`left`?e.at.x:e.anchor===`right`?e.at.x-t:e.at.x-t/2;return{minX:n,maxX:n+t,minY:e.at.y-e.size/2,maxY:e.at.y+e.size/2}}function Et(e){if(e.type===`text`)return Tt(e);if(e.type===`polyline`){let t=e.points.map(e=>e.x),n=e.points.map(e=>e.y);return{minX:Math.min(...t),maxX:Math.max(...t),minY:Math.min(...n),maxY:Math.max(...n)}}let{center:t,radius:n}=e;return{minX:t.x-n,maxX:t.x+n,minY:t.y-n,maxY:t.y+n}}function Dt(e,t){let n=[...e.map(Et),...t.map(e=>({minX:e.end.x,maxX:e.end.x,minY:e.end.y,maxY:e.end.y}))];return n.length===0?{minX:0,minY:0,maxX:0,maxY:0}:{minX:xt(Math.min(...n.map(e=>e.minX))),minY:xt(Math.min(...n.map(e=>e.minY))),maxX:xt(Math.max(...n.map(e=>e.maxX))),maxY:xt(Math.max(...n.map(e=>e.maxY)))}}var Ot=(e,t,n)=>({end:St(e,t),side:n});Ot(-.5,0,`left`),Ot(.5,0,`right`),Ot(-.5,0,`left`),Ot(.5,0,`right`),Ot(-.5,0,`left`),Ot(.3,-.5,`bottom`),Ot(.3,.5,`top`);function kt(){return[Ct([0,0],[0,-.1]),Ct([-.15,-.1],[.15,-.1]),Ct([-.1,-.15],[.1,-.15]),Ct([-.05,-.2],[.05,-.2])]}function At(e){return[Ct([0,0],[0,.1]),Ct([-.1,.1],[.1,.1]),wt(e,St(0,.2),`center`,`value`)]}var jt=.16,Mt=jt*1.5,Nt=.66,Pt={right:{x:1,y:0},left:{x:-1,y:0},top:{x:0,y:1},bottom:{x:0,y:-1}};function Ft(e){let t=Pt[e.side],n=e.text.length*jt*Nt+Mt,r=t.x===0,i={x:e.at.x+t.x*n/2,y:e.at.y+t.y*n/2},[a,o]=r?[Mt,n]:[n,Mt];return{middle:i,upright:r,box:{minX:i.x-a/2,minY:i.y-o/2,maxX:i.x+a/2,maxY:i.y+o/2}}}var It=/[\w-]+/,Lt=new RegExp(String.raw`^net\.(${It.source})$`),Rt=/^([A-Za-z_][\w-]*)\.([\w-]+)$/,zt=/^\.([A-Za-z_][\w-]*)\s*>\s*\.([\w-]+)$/;function Bt(e){let t=e.trim(),n=Lt.exec(t);if(n?.[1])return{kind:`net`,name:n[1]};let r=zt.exec(t)??Rt.exec(t);return r?.[1]&&r[2]?{kind:`pin`,part:r[1],pin:r[2]}:void 0}var Vt=/^net\.((?:[\w-]+(?:~\d+)?\/)+)([\w-]+)$/;function Ht(e){let t=Vt.exec(e.trim());return t?.[1]&&t[2]?{instance:t[1].slice(0,-1),net:t[2]}:void 0}function Ut(e,t){return`${e.instance}/${e.net} is local to instance ${e.instance}; edit ${t??`its sheet file`} and use ${e.net} there`}var Wt={schematicpath:`path`,schematicrect:`rect`,schematiccircle:`circle`,schematicarc:`arc`,schematictext:`text`,bus:`bus`,junction:`junction`},Gt=.04,Kt=[`solid`,`dashed`,`dotted`],qt=[`left`,`center`,`right`];function Jt(e){return Object.hasOwn(Wt,e)?Wt[e]:void 0}var Yt=new RegExp(String.raw`^${It.source}$`),Xt=new RegExp(String.raw`^(${It.source})\[(\d+):(\d+)\]$`);function Zt(e){if(Yt.test(e))return[e];let t=Xt.exec(e);if(!t)return;let[n,r,i]=[t[1],Number(t[2]),Number(t[3])],a=Math.abs(i-r)+1;if(a>1024)return;let o=i>=r?1:-1;return Array.from({length:a},(e,t)=>`${n}${r+t*o}`)}function Qt(e){let t=e.map(e=>e.x),n=e.map(e=>e.y);return{minX:Math.min(...t),minY:Math.min(...n),maxX:Math.max(...t),maxY:Math.max(...n)}}function $t(e,t){let n=t-e;return Math.abs(n)>=360?360:(n%360+360)%360}function en(e,t,n,r,i){let a=$t(r,i),o=[r,r+a];for(let e=Math.ceil(r/90)*90;e<r+a;e+=90)o.push(e);return Qt(o.map(r=>({x:e+n*Math.cos(r*Math.PI/180),y:t+n*Math.sin(r*Math.PI/180)})))}function tn(e,t,n,r,i){let a=bt*r*n.length,o=i===`left`?e:i===`right`?e-a:e-a/2;return{minX:o,minY:t-r/2,maxX:o+a,maxY:t+r/2}}function nn(e){switch(e.kind){case`path`:case`bus`:return Qt(e.points);case`rect`:return{minX:e.x,minY:e.y,maxX:e.x+e.width,maxY:e.y+e.height};case`circle`:return{minX:e.x-e.radius,minY:e.y-e.radius,maxX:e.x+e.radius,maxY:e.y+e.radius};case`arc`:return en(e.x,e.y,e.radius,e.startAngle,e.endAngle);case`text`:return tn(e.x,e.y,e.text,e.fontSize,e.anchor);case`junction`:return{minX:e.x-Gt,minY:e.y-Gt,maxX:e.x+Gt,maxY:e.y+Gt}}}var rn=e=>xt(e)+0;function an(e){let t=nn(e);return{minX:rn(t.minX),minY:rn(t.minY),maxX:rn(t.maxX),maxY:rn(t.maxY)}}var on=/^[A-Za-z_][\w-]*$/;function sn(e,t,n,r){let i=Ht(n);if(i)return Ut(i,void 0);let a=n.replace(/^net\./,``);return r?Zt(a)===void 0?`${e} port ${t} is a bus port and takes a bus name such as "D[0:7]", not "${n}"`:void 0:on.test(a)?void 0:`${e} port ${t} is a net port and takes a net name such as "VBUS", not "${n}"`}function cn(e,t){let n=new Set(e);for(let r of t??[]){let t=r.path.split(`/`)[0]??r.path;if(e.has(r.path)||e.has(t))for(let e of r.parts)n.add(e)}return n}var ln=e=>e?.circuit.instances??[];function un(e,t){return ln(e).find(e=>e.path===t&&!e.path.includes(`/`))}function dn(e,t){let n=e?.circuit.components.find(e=>e.id===t);if(n?.instance===void 0)return;let r=ln(e).find(e=>e.path===n.instance);if(!r)return;let i=n.instance.split(`/`)[0]??n.instance;return{part:t,localId:n.localId??t,instance:r.path,outer:i,sheet:r.sheet,file:r.file}}function fn(e,t){return[...ln(e).find(e=>e.path===t)?.parts??[]]}function pn(e,t){return ln(e).filter(e=>e.file===t).length}function mn(e,t){return t===void 0?`In ${e}; every instance of it changes with it`:`In ${e}, used ${t===1?`once`:`${t} times`}`}function hn(e,t){let n=t.flatMap(t=>{let n=un(e,t);if(n)return[n.path];let r=dn(e,t);return r?[r.outer]:[]});if(n.length!==0)return[...new Set(n)].flatMap(t=>fn(e,t))}function gn(e,t,n){let r=Object.fromEntries(Object.entries(e.connections).filter(([e])=>e!==t));return n===``?r:{...e.connections,[t]:n}}function _n(e,t){return cn(e,t?.circuit.instances)}function vn(e,t,n){let r=dn(e,n);if(r)return t.has(r.outer)?`${n} is in ${r.outer}, which is locked`:`${n} is ${r.localId} of ${r.instance}; it is placed in ${r.file}, where every instance of ${Qe(r.file)} shares it`}var yn=e=>Math.round(e*1e4)/1e4||0,bn=(e,t)=>e.x===t.x&&e.y===t.y;function xn(e,t,n){return e.x===t.x||e.y===t.y?[t]:[n?{x:e.x,y:t.y}:{x:t.x,y:e.y},t]}function Sn(e,t=[]){let n=e[0];if(!n)return[];let r=[n];for(let n=1;n<e.length;n++)r.push(...xn(e[n-1],e[n],t[n-1]===!0));return r}function Cn(e){let t=e.map(e=>({x:yn(e.x),y:yn(e.y)})),n=[];for(let e of t){let t=n[n.length-1];t&&bn(t,e)||n.push(e)}return n.filter((e,t)=>{let[r,i]=[n[t-1],n[t+1]];return!r||!i||!(r.x===e.x&&e.x===i.x||r.y===e.y&&e.y===i.y)})}function wn(e,t=[]){return Cn(Sn(e,t))}var Tn=.2,En=/^[\w-]+$/,Dn=/^[A-Za-z_][\w-]*$/,On=/^([A-Za-z_][\w-]*)\.([\w-]+)$/,kn=/^\.([A-Za-z_][\w-]*)\s*>\s*\.([\w-]+)$/;function An(e,t){let n=e.pinLabels;if(typeof n==`object`&&n)for(let[e,r]of Object.entries(n)){if(!RegExp(`^(?:pin)?${t}$`).test(e))continue;let n=(Array.isArray(r)?r:[r]).find(e=>typeof e==`string`&&e!==``);if(n!==void 0)return n}}function jn(e,t){let n=e.circuit.components.find(e=>e.id===t.component),r=An(n?.props??{},t.number),i=(n?.pins??[]).filter(e=>e.id!==t.id),a=r!==void 0&&En.test(r)&&!i.some(e=>e.names.includes(r));return`${t.component}.${a?r:`pin${t.number}`}`}function Mn(e,t){let n=t.trim(),r=On.exec(n)??kn.exec(n);return(r&&e.circuit.components.find(e=>e.id===r[1]))?.pins.find(e=>e.names.includes(r?.[2]??``))}var Nn=e=>e.circuit.components.flatMap(e=>e.pins),Pn=(e,t)=>e.circuit.nets.find(e=>e.pins.includes(t)),Fn=(e,t)=>Math.hypot(e.x-t.x,e.y-t.y);function In(e,t,n){let r=Pn(e,t.id)?.names[0],i=jn(e,t);return{selector:i,at:n,label:i,pin:t.id,...r===void 0?{}:{net:r}}}function Ln(e,t){let n=Pn(e,t);return n===void 0||n.pins.length<2&&n.names.length===0}function Rn(e,t,n){for(let r of e.circuit.instances??[]){if(r.path.includes(`/`))continue;let e=r.ports.find(e=>`${r.path}.${e.name}`===t);if(!e)continue;let i=`${r.path}.${e.name}`,a=e.members?{members:e.members}:{};return{selector:`port:${i}`,at:n,label:i,port:{instance:r.path,name:e.name,bus:e.bus===!0,...a}}}}function zn(e,t,n){let[r,i]=t.port?[t,n]:n.port?[n,t]:[];if(!r?.port||!i)return;let{port:a}=r;if(i.port)return{notice:`Connect ${r.label} and ${i.label} through a named net: wire each to a net label`};let o=(e.circuit.instances??[]).find(e=>e.path===a.instance);if(!o)return{notice:`${a.instance} is gone; wait for the build`};let s=a.bus?Vn(a,i):Bn(i);if(s===void 0){let e=a.bus?`a bus with the members ${(a.members??[]).join(`, `)}`:`the net a name first (a net label)`;return{notice:a.bus?`${r.label} is a bus pin; wire it to ${e}`:`Give ${e}, then wire ${r.label} to it`}}let c=sn(o.sheet,a.name,s,a.bus);return c===void 0?{edits:[{kind:`setConnections`,part:o.path,connections:gn(o,a.name,s)}],summary:`connect ${r.label} to ${s}`}:{notice:c}}var Bn=e=>e.members?void 0:e.selector.startsWith(`net.`)?e.selector.slice(4):e.net;function Vn(e,t){let n=e.members??[],r=t.members??[];return r.length===n.length&&n.every(e=>r.includes(e))?t.label:void 0}function Hn(e,t,n){let r;for(let i of e.schematic.symbols)for(let[e,a]of Object.entries(i.pinEnds)){let i=Fn(a,t);i<=n&&(!r||i<r.d)&&(r={pin:e,at:a,d:i})}return r&&{pin:r.pin,at:r.at}}function Un(e,t,n,r={}){let i=Hn(e,t,n),a=i&&Nn(e).find(e=>e.id===i.pin);return i&&a?In(e,a,i.at):i&&Rn(e,i.pin,i.at)||(Xn(e,t,n)??Jn(e,t,n,r)??Qn(e,t,n,r))}function Wn(e,t){let n;for(let r=1;r<e.length;r++){let[i,a]=[e[r-1],e[r]];if(!i||!a)continue;let o=er(t,i,a),s=Fn(o,t);(!n||s<n.d)&&(n={at:o,d:s,a:i,b:a})}return n}var Gn=e=>Math.round(e*1e4)/1e4||0;function Kn(e,t,n,r,i,a){let o=e=>e>=n[0]&&e<=n[1];if(i!==void 0&&Math.abs(t-i)<=r&&o(i))return i;if(!a.snap||!a.step)return e;let s=Gn(Math.round(e/a.step)*a.step);return o(s)?s:e}function qn(e,t,n,r){let{a:i,b:a,at:o}=e,s=i.y===a.y&&i.x!==a.x?`x`:i.x===a.x&&i.y!==a.y?`y`:void 0;if(!s)return o;let c=Kn(o[s],t[s],[Math.min(i[s],a[s]),Math.max(i[s],a[s])],n,r.from?.[s],r);return s===`x`?{x:c,y:i.y}:{x:i.x,y:c}}function Jn(e,t,n,r){let i;for(let r of e.schematic.drawings){if(r.kind!==`bus`)continue;let e=Wn(r.points,t);e&&e.d<=n&&(!i||e.d<i.near.d)&&(i={id:r.id,name:r.name,members:r.members,near:e})}let a=i&&qn(i.near,t,n,r);return i&&a&&{selector:`bus:${i.id}`,at:{x:Gn(a.x),y:Gn(a.y)},label:i.name,members:i.members}}function Yn(e,t){return{selector:`net.${t}`,at:e.at,label:t,net:t}}function Xn(e,t,n){let r;for(let i of e.schematic.labels){let a=e.circuit.nets.find(e=>e.id===i.net),o=a?.names.includes(i.text)?i.text:a?.names[0],s=Zn(i,t);o!==void 0&&s<=n&&(!r||s<r.d)&&(r={name:o,at:i.at,d:s})}return r&&{selector:`net.${r.name}`,at:r.at,label:r.name,net:r.name}}function Zn(e,t){if(e.style!==`label`)return Math.max(Fn(e.at,t)-Tn,0);let{box:n}=Ft(e);return Math.hypot(Math.max(n.minX-t.x,0,t.x-n.maxX),Math.max(n.minY-t.y,0,t.y-n.maxY))}function Qn(e,t,n,r){let i;for(let r of e.schematic.wires){let e=Wn(r.points,t);e&&e.d<=n&&(!i||e.d<i.near.d)&&(i={net:r.net,near:e})}return i&&$n(e,i.net,qn(i.near,t,n,r))}function $n(e,t,n){let r=e.circuit.nets.find(e=>e.id===t),i=r?.names[0];if(i!==void 0)return{selector:`net.${i}`,at:n,label:i,net:i};let a=r?.pins[0]??(t.startsWith(`net:`)?t.slice(4):void 0),o=Nn(e).find(e=>e.id===a);return o?{selector:jn(e,o),at:n,label:jn(e,o),pin:o.id}:void 0}function er(e,t,n){let r=n.x-t.x,i=n.y-t.y,a=r*r+i*i,o=a===0?0:Math.max(0,Math.min(1,((e.x-t.x)*r+(e.y-t.y)*i)/a));return{x:t.x+o*r,y:t.y+o*i}}function tr(e,t){if(t.pin!==void 0)return Pn(e,t.pin);let{selector:n}=t;if(n.startsWith(`net.`))return e.circuit.nets.find(e=>e.names.includes(n.slice(4)));let r=Nn(e).find(t=>jn(e,t)===n);return r&&Pn(e,r.id)}function nr(e,t){return e.selector===t.selector||e.pin!==void 0&&e.pin===t.pin}function rr(e,t,n){let[r,i]=[tr(e,t),tr(e,n)],[a,o]=[ir(t,r),ir(n,i)];if(r&&i&&r.id!==i.id&&a!==void 0&&o!==void 0)return[a,o]}var ir=(e,t)=>e.selector.startsWith(`net.`)?e.selector.slice(4):t?.names[0];function ar(e){let t=e.startsWith(`net.`)?void 0:e.split(`.`)[0];return t===void 0||Dn.test(t)&&!t.includes(`~`)}var or=e=>e.selector.startsWith(`net.`);function sr(e,t,n,r=[]){let i=wn([e.at,...n,t.at],r);return i.slice(+!or(e),or(t)?i.length:i.length-1)}function cr(e,t,n,r,i=[]){if(t.members||n.members||!ar(t.selector)||!ar(n.selector))return[];let[a,o]=[tr(e,t),tr(e,n)];if(nr(t,n)||a!==void 0&&a.id===o?.id)return[];let s=sr(t,n,r,i);return[{kind:`addTrace`,from:t.selector,to:n.selector,...s.length>0?{schematicRouteHints:s}:{}}]}var lr=/^net\.([\w-]+)$/,ur=new Set;function dr(e,t,n){return`pin`in n?t!==void 0&&Mn(e,t)?.id===n.pin:n.net.includes(lr.exec(t?.trim()??``)?.[1]??``)}function fr(e,t,n,r){return t.model.traces.filter(t=>dr(e,t.from,n)&&dr(e,t.to,r)||dr(e,t.from,r)&&dr(e,t.to,n))}function pr(e,t){return e[Number(/#(\d+)$/.exec(t??``)?.[1]??1)-1]??e[0]}function mr(e){if(!e.editable)return`This wire is read-only (${e.readonlyReason}); change it in the code`;if(e.props.schematicRouteHints&&!e.schematicRouteHints)return`The corners of this wire are an expression; change them in the code`}function hr(e,t,n,r){let i=[n?.from,n?.to].flatMap(t=>t===void 0?[]:[Mn(e,t)?.component??``]);return[...t,...i].find(e=>r.has(e))}function gr(e,t){return e.circuit.nets.find(e=>e.id===t)?.names??[t.replace(/^net\./,``)]}function _r(e,t){let n=e.model.traces.find(e=>e.from===t.from&&e.to===t.to||e.from===t.to&&e.to===t.from);return n!==void 0&&n.start!==t.start?`This wire repeats another between the same ends; change its corners in the code`:void 0}var vr=.1,yr=e=>Math.round(e*1e3)/1e3||0;function br(e){if(e.style===`label`)return Ft(e).box;let t=Dt(e.style===`ground`?kt():At(e.text),[]);return{minX:e.at.x+t.minX,minY:e.at.y+t.minY,maxX:e.at.x+t.maxX,maxY:e.at.y+t.maxY}}function xr(e){let t=br(e);return e.style===`label`?t:{minX:t.minX-vr,minY:t.minY-vr,maxX:t.maxX+vr,maxY:t.maxY+vr}}var Sr=(e,t)=>t.x>=e.minX&&t.x<=e.maxX&&t.y>=e.minY&&t.y<=e.maxY,Cr=e=>(e.maxX-e.minX)*(e.maxY-e.minY);function wr(e,t){return e.schematic.labels.map(e=>({label:e,box:xr(e)})).filter(({box:e})=>Sr(e,t)).sort((e,t)=>Cr(e.box)-Cr(t.box))[0]?.label}function Tr(e,t){return e.schematic.symbols.find(e=>e.pinEnds[t])?.pinEnds[t]}function Er(e,t){let n=e.schematic.labels.find(e=>e.id===t);if(!n)return;let r=e.circuit.connections.find(e=>`label:${e.id}`===n.id),i=`label:${n.net}:`,a=r?[r.from,r.to].find(e=>!e.startsWith(`net.`)):n.id.startsWith(i)?n.id.slice(i.length):void 0,o=e.circuit.components.flatMap(e=>e.pins).find(e=>e.id===a),s=o&&Tr(e,o.id);return o&&s?{label:n,pin:o,end:s,...r?{connection:r}:{}}:void 0}function Dr(e,t){let n=Er(e,t);return n&&{part:n.pin.component,...n.connection?{wire:`wire:${n.connection.id}`}:{}}}function Or(e,t){let n=Er(e,t);return n&&`${n.label.net}|${n.pin.id}`}function kr(e){return`the ${e.text} ${e.style===`label`?`label`:`flag`}`}function Ar(e){let t=e.connection?.corners??[];return e.connection?.from===e.pin.id?t:[...t].reverse()}function jr(e,t){if(e.connection&&t.x===e.end.x&&t.y===e.end.y)return[];let n=e.connection?Ar(e).slice(0,-1):[],r=n[n.length-1]??e.end;return[...n,...Ce([r,t]).slice(1)]}var Mr=(e,t)=>e.length===t.length&&e.every((e,n)=>e.x===t[n]?.x&&e.y===t[n]?.y),Nr=e=>({x:yr(e.x),y:yr(e.y)});function Pr(e,t){return e?t.x===e.x?t.y<e.y?`bottom`:`top`:t.x>e.x?`right`:`left`:`right`}function Fr(e,t,n){let r=Er(e,t);if(!r)return;let i=Nr(n),a=[r.end,...jr(r,i)];return{at:i,side:Pr(a[a.length-2],i),wire:a,...r.connection?{hideWire:`wire:${r.connection.id}`}:{}}}function Ir(e,t,n){return pr(fr(e,t,{pin:n.pin.id},{net:gr(e,n.label.net)}),n.connection?.id)}function Lr(e,t,n,r){let i=Er(e,n);if(!i)return{blocked:`This label is not attached to a pin the Studio can find`};let a=Ir(e,t,i),o=hr(e,[i.pin.component],a,r);if(o!==void 0)return{blocked:`${o} is locked`};let s=a?_r(t,a)??mr(a):void 0;return s?{blocked:s}:!a&&i.connection?{blocked:`The wire of this label is not written in a trace the Studio can find`}:!a&&!ar(jn(e,i.pin))?{blocked:`${i.pin.id} has a repeated name and cannot be wired from the Studio`}:a?{anchor:i,trace:a}:{anchor:i}}function Rr(e,t,n,r=ur){let i=Lr(e,t,n,r);return`blocked`in i?i.blocked:null}function zr(e,t){let n=gr(e,t.net);return`net.${n.includes(t.text)?t.text:n[0]??t.text}`}function Br(e,t,n,r,i=ur){let a=Lr(e,t,n,i);if(`blocked`in a)return a;let{anchor:o,trace:s}=a,c=jr(o,Nr(r)).map(Nr);if(Mr(c,o.connection?Ar(o):[]))return[];if(!s)return[{kind:`addTrace`,from:jn(e,o.pin),to:zr(e,o.label),schematicRouteHints:c}];let l=s.from!==void 0&&Mn(e,s.from)?.id===o.pin.id;return[{kind:`setTraceHints`,from:s.from??``,to:s.to??``,schematicRouteHints:l?c:[...c].reverse()}]}var Vr=new Intl.Collator(`en`,{numeric:!0});function Hr(e,t){let n=Array.from(e,e=>e.codePointAt(0)),r=Array.from(t,e=>e.codePointAt(0));for(let e=0;e<Math.min(n.length,r.length);e++){let t=n[e]-r[e];if(t!==0)return t}return n.length-r.length}function Ur(e,t){return Vr.compare(e,t)||Hr(e,t)}function Wr(e){return[...e].sort(Ur)}var Gr=4,Kr=6,qr=6;function Jr(e,t){let n=[...e].length;return n===0?0:((n-1)*qr+Gr)*t/Kr}function Yr(e){if(e.courtyard.length===0)return[{x:e.x,y:e.y}];let t=e.courtyard.map(e=>e.x),n=e.courtyard.map(e=>e.y),[r,i,a,o]=[Math.min(...t),Math.max(...t),Math.min(...n),Math.max(...n)],[s,c]=[(r+i)/2,(a+o)/2],[l,u]=[Jr(e.component,1)/2,1/2];return[{x:s,y:o+u},{x:s,y:a-u},{x:r-l,y:c},{x:i+l,y:c}]}var Xr=e=>e.nameAt??e.designatorAt??Yr(e)[0],Zr=.3,Qr=.5,$r=`"Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", sans-serif`,ei=`"Cascadia Mono", "JetBrains Mono", ui-monospace, Consolas, monospace`,ti={strong:600,regular:400},ni=(e,t,n=$r)=>`${e} ${t}px ${n}`,B={background:`#000000`,boardEdge:`#ff00ff`,topCopper:`#ff0000`,bottomCopper:`#0000ff`,inner1Copper:`#cc9933`,inner2Copper:`#9966cc`,multiLayer:`#c0c0c0`,viaRing:`#c0c0c0`,highlight:`#ffffff`,drill:`#222222`,topSilk:`#ffcc00`,bottomSilk:`#66cc33`,topAssembly:`#33cc99`,bottomAssembly:`#5555ff`,ratsnest:`#6464ff`,keepout:`#f022f0`,document:`#ffffff`,grid:`rgb(255 255 255 / 30%)`,gridFifth:`rgb(255 255 255 / 50%)`,selection:`#ffffff`,selectionFill:`rgb(255 255 255 / 50%)`,hover:`rgb(255 255 255 / 60%)`,selectionBox:`#00ffff`,selectionBoxFill:`rgb(0 255 255 / 10%)`,notePanel:`rgb(0 0 0 / 80%)`,error:`#e5534b`,warning:`#e0a63a`,ringHaloOuter:`#ffffff`,ringHaloInner:`#000000`};function ri(e){let t=e.split(`_`);return[t.includes(`top`)?`top`:t.includes(`bottom`)?`bottom`:`middle`,t.includes(`left`)?`left`:t.includes(`right`)?`right`:`center`]}var ii=[`top`,`bottom`,`topSilk`,`bottomSilk`,`topAssembly`,`bottomAssembly`,`courtyard`,`boardOutline`,`multiLayer`,`hole`,`ratline`,`keepout`],ai=[{id:`top`,name:`Top Layer`},{id:`bottom`,name:`Bottom Layer`}],oi=[{id:`top`,name:`Top Layer`,group:`copper`,color:B.topCopper},{id:`bottom`,name:`Bottom Layer`,group:`copper`,color:B.bottomCopper},{id:`topSilk`,name:`Top Silkscreen`,group:`non-copper`,color:B.topSilk},{id:`bottomSilk`,name:`Bottom Silkscreen`,group:`non-copper`,color:B.bottomSilk},{id:`topAssembly`,name:`Top Assembly`,group:`non-copper`,color:B.topAssembly},{id:`bottomAssembly`,name:`Bottom Assembly`,group:`non-copper`,color:B.bottomAssembly},{id:`courtyard`,name:`Courtyard`,group:`non-copper`,color:B.topAssembly,bottomColor:B.bottomAssembly},{id:`boardOutline`,name:`Board Outline`,group:`non-copper`,color:B.boardEdge},{id:`multiLayer`,name:`Multi-Layer`,group:`copper`,color:B.multiLayer},{id:`hole`,name:`Hole`,group:`non-copper`,color:B.drill},{id:`ratline`,name:`Ratline`,group:`non-copper`,color:B.ratsnest},{id:`keepout`,name:`Keepout`,group:`non-copper`,color:B.keepout}];function si(e,t){return oi.filter(n=>(e||n.id!==`keepout`)&&(t===`all`||n.group===t))}function ci(e){return e.bottomColor?`linear-gradient(135deg, ${e.color} 50%, ${e.bottomColor} 50%)`:e.color}var li={...Object.fromEntries(ii.map(e=>[e,!0])),topAssembly:!1,bottomAssembly:!1};function ui(e,t){let n=new Set(e);return n.delete(t)||n.add(t),n}function di(e,t,n){let r={top:`Top Layer`,bottom:`Bottom Layer`,inner1:`Inner Layer 1`,inner2:`Inner Layer 2`};return Object.keys(r).flatMap(i=>{let a=e.filter(e=>e.layer===i).map(e=>({id:e.id,net:t(e.net),layer:i,shown:!n.has(e.id)}));return a.length>0?[{layer:i,name:r[i],pours:a}]:[]})}function fi(e,t){return{...e,[t]:!e[t]}}function pi(e){return e.layers===`through`?`multiLayer`:e.layers===`bottom`?`bottom`:`top`}function mi(e){let t=e.side===`top`,n=new Set([`courtyard`]);e.fabrication.length>0&&n.add(t?`topAssembly`:`bottomAssembly`),e.silkscreen.length>0&&n.add(t?`topSilk`:`bottomSilk`);for(let t of e.pads)n.add(pi(t)),t.drill&&n.add(`hole`);return[...n]}function hi(e,t){return e.some(e=>t[e])}function gi(e,t){let n=new Map(e.map(e=>[e.component,mi(e)]));return{visible:t,of:e=>n.get(e)}}var _i={parts:!0,labels:!0,wires:!0,drawings:!0,tracks:!0,vias:!0,texts:!0,pours:!0};function vi(e,t){return{...e,[t]:!e[t]}}function yi(e,t){return e===void 0||e[t]}function bi(e){let t={kind:`parts`,label:`Parts`};return e===`schematic`?[t,{kind:`wires`,label:`Wires`},{kind:`labels`,label:`Net labels and flags`},{kind:`drawings`,label:`Drawings`},{kind:`texts`,label:`Names and values`}]:[t,{kind:`tracks`,label:`Tracks`},{kind:`vias`,label:`Vias`},{kind:`pours`,label:`Copper pours and holes`},{kind:`texts`,label:`Designators`}]}var xi={part:`parts`,label:`labels`,wire:`wires`,drawing:`drawings`,track:`tracks`,via:`vias`,text:`texts`,pour:`pours`,hole:`pours`};function Si(e,t){if(!Ci(xi[e.kind],t))return!1;let{layers:n}=t,r=e.kind===`part`?n?.of(e.name):void 0;return!n||!r||hi(r,n.visible)}function Ci(e,t){return t.armed===`note`||t.armed===`zoom`?!1:yi(t.filter,e)}function wi(e,t){return e.filter(e=>Si(e,t))}function Ti(e,t){return wi(e.map(e=>({kind:`part`,name:e})),t).map(e=>e.name)}function Ei(e,t){return wi(e.map(e=>({kind:`wire`,id:e})),t).map(e=>e.id)}function Di(e,t){return Ci(`labels`,t)?[...e]:[]}function V(e,t){return Ci(`drawings`,t)?[...e]:[]}function Oi(e,t){return wi(e.map(({kind:e,id:t})=>({kind:e,id:t})),t).map(e=>e.id)}function ki(e,t,n,r=[],i=[],a=[],o=[]){return s=>{let c={selection:s,armed:null,layers:t,filter:n};return s.all(Ti(e,c),Ei(r,c),Di(i,c),V(a,c),Oi(o,c))}}function Ai(e,t){return t.x>=e.x?`inside`:`touching`}var ji=(e,t)=>t.minX>=e.minX&&t.maxX<=e.maxX&&t.minY>=e.minY&&t.maxY<=e.maxY,Mi=(e,t)=>e.minX<=t.maxX&&t.minX<=e.maxX&&e.minY<=t.maxY&&t.minY<=e.maxY;function Ni(e,t,n,r){let i=xe([t,n]);if(!i)return[];let a=r===`inside`?e=>ji(i,e):e=>Mi(i,e);return e.filter(e=>a(e.box)).map(e=>e.id)}function Pi(e,t,n,r){return Ni(e.map(e=>({id:e.name,box:e.box})),t,n,r)}function Fi(e,t,n,r){return Ni(e,t,n,r)}var Ii=(e,t)=>t.x>=e.minX&&t.x<=e.maxX&&t.y>=e.minY&&t.y<=e.maxY;function Li(e,t,n){if(Ii(e,t)||Ii(e,n))return!0;let r=xe([t,n]);if(!r||!Mi(e,r))return!1;let i=[{x:e.minX,y:e.minY},{x:e.maxX,y:e.minY},{x:e.minX,y:e.maxY},{x:e.maxX,y:e.maxY}].map(e=>(n.x-t.x)*(e.y-t.y)-(n.y-t.y)*(e.x-t.x));return i.some(e=>e>=0)&&i.some(e=>e<=0)}function Ri(e,t,n,r){let i=xe([t,n]);if(!i)return[];let a=r===`inside`?e=>e.every(e=>Ii(i,e)):e=>e.some((t,n)=>Li(i,e[n-1]??t,t));return e.filter(e=>a(e.points)).map(e=>e.id)}function zi(e,t,n=null,r,i){return a=>{let o={selection:a,armed:n,layers:r,filter:i},[s,c,l]=[Ti(e.parts,o),Ei(e.wires??[],o),Di(e.labels??[],o)],u=V(e.drawings??[],o),d=Oi(e.copper??[],o);return t?a.add(s).addWires(c).addLabels(l).addDrawings(u).addCopper(d):a.all(s,c,l,u,d)}}var Bi=e=>[...new Set(e)],Vi=(e,t)=>e.length===t.length&&e.every((e,n)=>e===t[n]),Hi=(e,t)=>e.filter(e=>!t.includes(e)),Ui=(e,t)=>{let n=new Set(t);return e.filter(e=>n.has(e))},Wi=(e,t)=>e!==void 0&&e.x===t.x&&e.y===t.y,Gi=(e,t)=>e!==void 0&&e.id===t.id&&e.index===t.index&&Wi(e.from,t.from)&&Wi(e.to,t.to);function Ki(e,t){let[n,r]=[e.points[t],e.points[t+1]];return Number.isInteger(t)&&t>=0&&n&&r?{id:e.id,index:t,from:{x:n.x,y:n.y},to:{x:r.x,y:r.y}}:void 0}function qi(e,t){return Wi(t[e.index],e.from)&&Wi(t[e.index+1],e.to)}var Ji={names:[],wires:[],labels:[],drawings:[],copper:[],texts:[],board:[]},Yi=[`names`,`wires`,`labels`,`drawings`,`copper`,`texts`,`board`],Xi=class e{static none=new e(Ji);names;wires;labels;drawings;copper;texts;board;segment;constructor(e,t){this.names=Object.freeze([...e.names]),this.wires=Object.freeze([...e.wires]),this.labels=Object.freeze([...e.labels]),this.drawings=Object.freeze([...e.drawings]),this.copper=Object.freeze([...e.copper]),this.texts=Object.freeze([...e.texts]),this.board=Object.freeze([...e.board]),this.segment=t&&Object.freeze({id:t.id,index:t.index,from:Object.freeze({...t.from}),to:Object.freeze({...t.to})}),Object.freeze(this)}static from(t){return Yi.every(e=>t[e].length===0)?e.none:new e(t)}get lists(){return{names:this.names,wires:this.wires,labels:this.labels,drawings:this.drawings,copper:this.copper,texts:this.texts,board:this.board}}with(t){let n={...this.lists,...t};return Yi.every(e=>n[e].length===this[e].length)?this:e.from(n)}grown(t){return new e({...this.lists,...t})}get primary(){return this.names.at(-1)}get size(){return this.names.length}get wireCount(){return this.wires.length}get labelCount(){return this.labels.length}get drawingCount(){return this.drawings.length}get copperCount(){return this.copper.length}get textCount(){return this.texts.length}get boardCount(){return this.board.length}get total(){return this.names.length+this.wires.length+this.labels.length+this.drawings.length+this.copper.length+this.texts.length+this.board.length}get soleBoard(){return this.total===1?this.board[0]:void 0}get soleText(){return this.total===1?this.texts[0]:void 0}get soleCopper(){return this.total===1?this.copper[0]:void 0}get soleWire(){return this.total===1?this.wires[0]:void 0}get soleLabel(){return this.total===1?this.labels[0]:void 0}get soleDrawing(){return this.total===1?this.drawings[0]:void 0}has(e){return this.names.includes(e)}hasWire(e){return this.wires.includes(e)}hasLabel(e){return this.labels.includes(e)}hasDrawing(e){return this.drawings.includes(e)}hasCopper(e){return this.copper.includes(e)}hasText(e){return this.texts.includes(e)}hasBoard(e){return this.board.includes(e)}onlyBoard(t){return this.soleBoard===t?this:new e({...Ji,board:[t]})}toggleBoard(e){return this.hasBoard(e)?this.withoutBoard([e]):this.grown({board:[...this.board,e]})}addBoard(e){let t=Bi(e).filter(e=>!this.hasBoard(e));return t.length===0?this:this.grown({board:[...this.board,...t]})}withoutBoard(e){return this.with({board:Hi(this.board,e)})}keepBoard(e){return this.with({board:Ui(this.board,e)})}only(t){return this.total===1&&this.names[0]===t?this:new e({...Ji,names:[t]})}onlyWire(t){return this.soleWire===t?this:new e({...Ji,wires:[t]})}onlyLabel(t){return this.soleLabel===t?this:new e({...Ji,labels:[t]})}onlyDrawing(t){return this.soleDrawing===t?this:new e({...Ji,drawings:[t]})}onlyText(t){return this.soleText===t?this:new e({...Ji,texts:[t]})}onlyCopper(t){return this.soleCopper===t&&!this.segment?this:new e({...Ji,copper:[t]})}onlySegment(t){return Gi(this.segment,t)?this:new e({...Ji,copper:[t.id]},t)}toggle(e){return this.has(e)?this.without([e]):this.grown({names:[...this.names,e]})}toggleWire(e){return this.hasWire(e)?this.withoutWires([e]):this.grown({wires:[...this.wires,e]})}toggleLabel(e){return this.hasLabel(e)?this.withoutLabels([e]):this.grown({labels:[...this.labels,e]})}toggleDrawing(e){return this.hasDrawing(e)?this.withoutDrawings([e]):this.grown({drawings:[...this.drawings,e]})}toggleCopper(e){return this.hasCopper(e)?this.withoutCopper([e]):this.grown({copper:[...this.copper,e]})}toggleText(e){return this.hasText(e)?this.with({texts:Hi(this.texts,[e])}):this.grown({texts:[...this.texts,e]})}add(e){let t=Bi(e).filter(e=>!this.has(e));return t.length===0?this:this.grown({names:[...this.names,...t]})}addWires(e){let t=Bi(e).filter(e=>!this.hasWire(e));return t.length===0?this:this.grown({wires:[...this.wires,...t]})}addLabels(e){let t=Bi(e).filter(e=>!this.hasLabel(e));return t.length===0?this:this.grown({labels:[...this.labels,...t]})}addDrawings(e){let t=Bi(e).filter(e=>!this.hasDrawing(e));return t.length===0?this:this.grown({drawings:[...this.drawings,...t]})}addCopper(e){let t=Bi(e).filter(e=>!this.hasCopper(e));return t.length===0?this:this.grown({copper:[...this.copper,...t]})}clear(){return e.none}all(t,n=[],r=[],i=[],a=[]){let o={names:Bi(t),wires:Bi(n),labels:Bi(r),drawings:Bi(i),copper:Bi(a),texts:[],board:[]};return Yi.every(e=>Vi(o[e],this[e]))?this:e.from(o)}without(e){return this.with({names:Hi(this.names,e)})}withoutWires(e){return this.with({wires:Hi(this.wires,e)})}withoutLabels(e){return this.with({labels:Hi(this.labels,e)})}withoutDrawings(e){return this.with({drawings:Hi(this.drawings,e)})}withoutCopper(e){return this.with({copper:Hi(this.copper,e)})}keep(e){return this.with({names:Ui(this.names,e)})}keepWires(e){return this.with({wires:Ui(this.wires,e)})}keepLabels(e){return this.with({labels:Ui(this.labels,e)})}keepDrawings(e){return this.with({drawings:Ui(this.drawings,e)})}withoutTexts(e){return this.with({texts:Hi(this.texts,e)})}keepTexts(e){return this.with({texts:Ui(this.texts,e)})}keepCopper(e){return this.with({copper:Ui(this.copper,e)})}};function Zi(e,t){let{segment:n}=e,r=n&&t.find(e=>e.id===n.id);return n&&r&&!qi(n,r.points)?e.onlyCopper(n.id):e}function Qi(e){return e.shiftKey||e.ctrlKey||e.metaKey}function $i(e,t){let n=Qi(t);return t=>n?t.toggle(e):t.only(e)}function ea(e,t){let n=new Set(t);return e.filter(e=>!n.has(e))}var ta={error:B.error,warning:B.warning},na=6,ra=1.5,ia=3,aa=1;function oa(e,t,n,r,i,a=ta){if(n.length!==0){e.globalAlpha=1,e.setLineDash([]);for(let o of n){let n=fe(t.camera,t.size,o.at),s=o.id===r?ia:ra;i&&ca(e,n,s),e.strokeStyle=o.severity===`error`?a.error:a.warning,sa(e,n,na,s)}}}function sa(e,t,n,r){e.lineWidth=r,e.beginPath(),e.arc(t.x,t.y,n,0,Math.PI*2),e.stroke()}function ca(e,t,n){let r=(n+aa)/2;e.strokeStyle=B.ringHaloOuter,sa(e,t,na+r,aa),e.strokeStyle=B.ringHaloInner,sa(e,t,na-r,aa)}var la={background:`#FFFCF8`,grid:`#F0F0EB`,wire:`#008800`,bus:`#008800`,drawing:`#000080`,junction:`#CC0000`,symbolOutline:`#A00000`,pin:`#880000`,pinName:`#000000`,pinNumber:`#000000`,designator:`#0000FF`,netName:`#0000FF`,value:`#000080`,noConnect:`#33CC33`,selection:`#FF0000`,highlight:`#FF9933`,border:`#A00000`,titleText:`#000080`,gridDot:`#D9D9D2`,flag:`#A00000`,markerError:B.error,markerWarning:B.warning,selectionGlow:0,hover:`rgb(255 0 0 / 45%)`,handleFill:`#FFFFFF`,selectionFill:`rgb(255 0 0 / 8%)`,selectionBox:`#0000FF`,selectionBoxFill:`rgb(0 0 255 / 8%)`,lockBadge:`#4f9a6c`,lockGlyph:`#ffffff`,notePin:`#e0a46a`,notePanel:`rgb(34 38 44 / 92%)`,noteText:`#e9e6df`},ua={background:`#141619`,grid:`#2B3038`,gridDot:`#2B3038`,gridFifth:`#3A4049`,wire:`#5BD3C7`,bus:`#8AB4FF`,drawing:`#9AA1A9`,junction:`#5BD3C7`,symbolOutline:`#D9DEE5`,pin:`#D9DEE5`,pinName:`#AEB6C0`,pinNumber:`#7E8792`,designator:`#E6E8EB`,netName:`#F2C66D`,value:`#AEB6C0`,noConnect:`#5BD3C7`,selection:`#4CC9F0`,highlight:`#E89A4F`,border:`#9AA1A9`,titleText:`#9AA1A9`,flag:`#FF9E80`,markerError:`#FF6B6B`,markerWarning:`#FFC857`,selectionGlow:8,hover:`#8BE0F5`,handleFill:`#141619`,selectionFill:`rgb(76 201 240 / 10%)`,selectionBox:`#4CC9F0`,selectionBoxFill:`rgb(76 201 240 / 8%)`,lockBadge:`#4f9a6c`,lockGlyph:`#ffffff`,notePin:`#e0a46a`,notePanel:`rgb(34 38 44 / 92%)`,noteText:`#e9e6df`},da=e=>e===`dark`?ua:la,fa=la,H=()=>fa;function pa(e){fa=e}function ma(e,t,n=fa){let r=t?n.selectionGlow:0;e.shadowBlur=r,e.shadowColor=r>0?n.selection:`transparent`}var ha=.02,ga=3*ha;function _a(e){return e.kind===`bus`?ga:e.kind===`text`||e.kind===`junction`?0:e.strokeWidth}var va=(e,t)=>Math.max(e,t);function ya(e,t){return e===`dashed`?[4*t,3*t]:e===`dotted`?[0,2*t]:[]}function ba(e){return e.kind===`bus`||e.kind===`text`||e.kind===`junction`?`solid`:e.lineStyle}function xa(e){return e.kind===`bus`?H().bus:e.kind===`junction`?e.color??H().junction:e.color??H().drawing}var Sa=e=>(e.kind===`rect`||e.kind===`circle`)&&e.filled,Ca=e=>`${e}33`,wa=e=>1/e,Ta=(e,t)=>(Math.floor(e*t)+.5)/t,Ea=(e,t)=>Math.round(e*t)/t,Da=(e,t)=>Math.max(1,Math.round(e*t))/t,Oa=(e,t)=>Math.round(e*t)/t,ka=(e,t)=>e/t,Aa=(e,t)=>Math.max(1,Math.round(e*t)),ja=(e,t,n)=>n%2==1?Ta(e,t):Ea(e,t);function Ma(e,t,n,r=1){let i=e=>ja(e,n,r),a=i(Math.min(e.x,t.x)),o=i(Math.min(e.y,t.y));return{x:a,y:o,width:i(Math.max(e.x,t.x))-a,height:i(Math.max(e.y,t.y))-o}}var Na=.16;function Pa(e){return e<7?`none`:e<9?`names`:`all`}function Fa(e,t,n){if(n<5)return!1;let r=Pa(t);return e===`name`?r!==`none`:e===`pin-number`?t>=11:r===`all`}var Ia=(e,t,n)=>Math.max(1,Math.round(e*t*n)),La=(e,t)=>Ia(Na,e,t),Ra=(e,t,n)=>Ia(e,t,n)/n,za=(e,t)=>({x:Ea(e.x,t),y:Oa(e.y,t)});function Ba(e){`textRendering`in e&&(e.textRendering=`geometricPrecision`)}var Va=(e,t,n)=>t<=n||t<=0?e:Math.max(1,Math.floor(e*n/t)),U=e=>e*Math.PI/180;function Ha(e,t){if(!t||t.length===0)return e;let n=new Map(t.map(e=>[e.id,e]));return e.map(e=>n.get(e.id)??e)}function Ua(e,t){let n=t-e;return Math.abs(n)>=360?360:(n%360+360)%360}function Wa(e,t){if(e.beginPath(),t.kind===`path`||t.kind===`bus`){t.points.forEach((t,n)=>n===0?e.moveTo(t.x,t.y):e.lineTo(t.x,t.y));return}if(t.kind===`rect`){let{x:n,y:r,width:i,height:a}=t;e.moveTo(n,r),e.lineTo(n+i,r),e.lineTo(n+i,r+a),e.lineTo(n,r+a),e.closePath();return}if(t.kind===`circle`)return e.arc(t.x,t.y,t.radius,0,2*Math.PI);let n=U(t.startAngle);e.arc(t.x,t.y,t.radius,n,n+U(Ua(t.startAngle,t.endAngle)))}function Ga(e,t){return t.selected?.includes(e.id)?{color:H().selection,alpha:1}:{color:xa(e),alpha:t.dim?Zr:1}}function Ka(e,t,n,r,i){e.globalAlpha=r,e.fillStyle=n,e.beginPath(),e.arc(t.x,t.y,Gt,0,2*Math.PI),ma(e,i),e.fill(),ma(e,!1)}function qa(e,t,n,r){for(let i of t){if(i.kind===`text`)continue;let{color:t,alpha:a}=Ga(i,r);if(i.kind===`junction`){Ka(e,i,t,a,r.selected?.includes(i.id)??!1);continue}let o=va(_a(i),n);e.globalAlpha=a,e.lineWidth=o,e.strokeStyle=t,e.setLineDash(ya(r.pending?`dashed`:ba(i),o)),Wa(e,i),Sa(i)&&(e.fillStyle=Ca(t),e.fill()),ma(e,r.selected?.includes(i.id)??!1),e.stroke(),ma(e,!1),e.setLineDash([])}e.globalAlpha=1}function Ja(e,t,n,r,i,a){for(let o of t){if(o.kind!==`text`||o.text===``)continue;let t=Ia(o.fontSize,n.scale,a);if(!Fa(`detail`,La(n.scale,a),t))continue;let s=t/a,{color:c,alpha:l}=Ga(o,i),u=za(fe(n,r,o),a),[,d]=ri(o.anchor);e.globalAlpha=l,e.fillStyle=c,e.font=`${s}px ${$r}`,e.textAlign=d,e.textBaseline=`middle`,e.fillText(o.text,u.x,u.y)}e.globalAlpha=1}var Ya=.7,Xa=`…`,Za=2;function Qa(e,t,n){if(n(e)<=t)return e;for(let r=e.length-1;r>=Za;r--){let i=e.slice(0,r)+Xa;if(n(i)<=t)return i}return null}function $a(e,t,n){let r=t(e);if(r>=1)return{text:e,scale:1};if(r>=n)return{text:e,scale:r};for(let r=e.length-1;r>=Za;r--){let i=e.slice(0,r)+Xa;if(t(i)>=n)return{text:i,scale:n}}return null}function eo(e,t,n){if(t+n<=e)return t;let r=e/2;return t<=r?t:n<=r?e-n:r}var to=(e,t,n,r)=>t===`x`===e.quarter?e.size:r(n),no=e=>e.side===`left`||e.side===`right`,ro=e=>no(e)?`x`:`y`,io=e=>no(e)?`y`:`x`,ao=e=>no(e)?1:.5,oo={left:`right`,right:`left`,top:`bottom`,bottom:`top`};function so(e,t,n,r){let[i,a]=[ro(e),io(e)],o=e.side===`left`||e.side===`bottom`?1:-1,s=e=>to(e,i,e.text,n)*ao(e),c=t=>Math.abs(t.local[a]-e.local[a])<(to(e,a,e.text,n)+to(t,a,t.text,n))/2,l=t.filter(t=>t.side===oo[e.side]&&c(t)&&(t.local[i]-e.local[i])*o>0).sort((t,n)=>Math.abs(t.local[i]-e.local[i])-Math.abs(n.local[i]-e.local[i]))[0];return eo(Math.abs((l?l.local[i]:-e.local[i])-e.local[i])-r,s(e),l?s(l):0)/ao(e)}function co(e,t,n){let r=io(e),i=t.filter(t=>t!==e&&t.side===e.side).map(t=>Math.abs(t.local[r]-e.local[r]));return i.length===0?1/0:Math.min(...i)-n}function lo(e,t,n,r,i){let a=so(e,t,n,r),o=co(e,t,r);return $a(e.text,t=>Math.min(a/to(e,ro(e),t,n),o/to(e,io(e),t,n)),i)}function uo(e,t,n){let r=n(t.text)*t.scale,i=e.align===`left`?e.x:e.align===`right`?e.x-r:e.x-r/2;return{x0:i,x1:i+r,y0:e.y-e.ascent*t.scale,y1:e.y+e.descent*t.scale}}var fo=(e,t)=>e.x0<t.x1&&t.x0<e.x1&&e.y0<t.y1&&t.y0<e.y1;function po(e,t){let n=new Set;return e.forEach((r,i)=>{e.forEach((e,a)=>{a>i&&r&&e&&t(i,a)&&fo(r,e)&&n.add(i).add(a)})}),n}function mo(e,t,n,r=Ya){let i=e.map(i=>lo(i,e,t,n,r)),a=i.map((n,r)=>n===null?null:uo(e[r],n,t)),o=po(a,(t,n)=>e[t]?.side===e[n]?.side),s=po(a.map((e,t)=>o.has(t)?null:e),()=>!0);return i.map((e,t)=>o.has(t)||s.has(t)?null:e)}var ho=.25,go=.8,_o=.2,vo={top:go,middle:.6000000000000001/2,bottom:-.2},yo=(e,t,n)=>ni(e.strong?ti.strong:ti.regular,t/n,e.mono?ei:void 0);function bo(e,t,{camera:n,ratio:r}){let i=Ia(t.size,n.scale,r);return t.maxWidth===void 0?i:(e.font=yo(t,i,r),Va(i,e.measureText(t.text).width,t.maxWidth*n.scale))}function xo(e,t,n,r){e.textBaseline=n;let i=e.measureText(t),a=(vo[n]??0)*r;return{ascent:i.actualBoundingBoxAscent??go*r-a,descent:i.actualBoundingBoxDescent??_o*r+a}}function So(e,{label:t,devicePx:n},r){let i=t.pinOf;if(!i)return null;let a=n/r.ratio,o=fe(r.camera,r.size,t.at),[s,c]=ri(t.anchor),l={x:i.local.x*r.camera.scale,y:i.local.y*r.camera.scale},u=xo(e,t.text,s,a);return{text:t.text,x:o.x,y:o.y,align:c,size:a,...u,local:l,side:i.side,quarter:i.quarter}}function Co(e,t,n){let r=t[0];if(!r)return t;e.font=yo(r.label,r.devicePx,n.ratio);let i=t.map(t=>So(e,t,n)).filter(e=>e!==null);if(i.length!==t.length)return t;let a=Math.ceil(r.devicePx*Ya)/r.devicePx,o=mo(i,t=>e.measureText(t).width,r.devicePx/n.ratio*ho,a);return t.flatMap((e,t)=>{let n=o[t];if(!n)return[];let r=n.scale<1?Math.floor(e.devicePx*n.scale+1e-9):e.devicePx;return[{label:{...e.label,text:n.text},devicePx:r}]})}function wo(e,t,n){let r=La(n.camera.scale,n.ratio),i=({label:e,devicePx:t})=>Fa(e.kind,r,t),a=t.filter(e=>e.text!==``).map(t=>({label:t,devicePx:bo(e,t,n)})).filter(i),o=new Map;for(let e of a){let t=e.label.pinOf?.symbol;t!==void 0&&o.set(t,[...o.get(t)??[],e])}let s=[...o.values()].flatMap(t=>Co(e,t,n));return[...a.filter(({label:e})=>!e.pinOf),...s.filter(i)]}function To(e,{label:t,devicePx:n},r){let i=za(fe(r.camera,r.size,t.at),r.ratio),[a,o]=ri(t.anchor);e.save(),e.translate(i.x,i.y),t.rotation&&e.rotate(-t.rotation*Math.PI/180),e.globalAlpha=t.alpha??1,e.fillStyle=t.color,e.font=yo(t,n,r.ratio),e.textAlign=o,e.textBaseline=a,e.fillText(t.text,0,0),e.restore()}function Eo(e,t,n,r,i){let a={camera:n,size:r,ratio:i};Ba(e);for(let n of wo(e,t,a))To(e,n,a)}var Do=.05,Oo=.015;function ko(e){let t=Do;return[[{x:e.x-t,y:e.y-t},{x:e.x+t,y:e.y+t}],[{x:e.x-t,y:e.y+t},{x:e.x+t,y:e.y-t}]]}function Ao(e,t,n,r){if(t.length!==0){e.strokeStyle=H().noConnect,e.lineWidth=n(Oo),e.globalAlpha=r?Zr:1;for(let n of t)for(let[t,r]of ko(n.at))e.beginPath(),e.moveTo(t.x,t.y),e.lineTo(r.x,r.y),e.stroke();e.globalAlpha=1}}var jo={x:0,y:0},Mo=.02,No=1.2,Po=3.5,Fo=.06,Io=1.5,Lo=1.6,Ro=.04,zo=3,Bo=[.1,.06],Vo=.1,Ho=.07,Uo=2.5,Wo={reference:`name`,value:`detail`,"pin-name":`detail`,"pin-number":`pin-number`},Go={reference:`designator`,value:`value`,"pin-name":`pinName`,"pin-number":`pinNumber`},Ko={right:{x:1,y:0},left:{x:-1,y:0},top:{x:0,y:1},bottom:{x:0,y:-1}},qo=e=>e*Math.PI/180,Jo=e=>Math.max(ha*e,No);function Yo(e,t,n,r){let{camera:i,size:a}=n,o=1/i.scale,s=e=>Math.max(e,o/r.ratio),c=[],l=e=>r.moving?.components.includes(e.component)?r.moving.by:jo;e.save();let u=i.scale*r.ratio;e.setTransform(u,0,0,-u,(a.width/2-i.cx*i.scale)*r.ratio,(a.height/2+i.cy*i.scale)*r.ratio),e.lineCap=`round`,e.lineJoin=`round`,ss(e,t,r,o,s);let d=Ha(t.drawings,r.movingDrawings),f=r.pendingDrawings??[],p=[...d,...f],m={...r.selectedDrawings?{selected:r.selectedDrawings}:{},dim:r.highlight!==void 0};qa(e,d,o/r.ratio,m),qa(e,f,o/r.ratio,{pending:!0,dim:m.dim});for(let n of t.symbols)cs(e,n,l(n),{line:s,px:o,fade:rs(n,r.highlight)},c);for(let n of t.labels){let t=r.movingLabels?.some(e=>e.id===n.id)??!1,i=r.selectedLabels?.includes(n.id)??!1,a=i?{color:H().selection,alpha:1}:ns(n.net,r.highlight);ma(e,i),_s(e,gs(n,r),s,c,t,a),ma(e,!1)}for(let t of r.ghostLabels??[])_s(e,t,s,c,!0,ns(t.net,void 0));bs(e,t,r,o,l),Ao(e,t.noConnects??[],s,r.highlight!==void 0),e.setTransform(r.ratio,0,0,r.ratio,0,0),Eo(e,c,i,a,r.ratio),Ja(e,p,i,a,m,r.ratio),oa(e,n,r.violations??[],r.activeViolation,!1,{error:H().markerError,warning:H().markerWarning}),e.restore()}function Xo(e){return e.symbols.map(e=>{let t=Qo(e);return{name:e.component,pcbComponentId:e.component,center:{x:(t.minX+t.maxX)/2,y:(t.minY+t.maxY)/2},box:t}})}var Zo=e=>e.type===`text`&&(e.role===`reference`||e.role===`value`);function Qo(e){let{minX:t,minY:n,maxX:r,maxY:i}=Dt(e.symbol.shapes.filter(e=>!Zo(e)),e.symbol.pins),a=[{x:t,y:n},{x:r,y:n},{x:r,y:i},{x:t,y:i}].map(t=>$o(t,e)),o=a.map(e=>e.x),s=a.map(e=>e.y);return{minX:Math.min(...o),minY:Math.min(...s),maxX:Math.max(...o),maxY:Math.max(...s)}}function $o(e,t){let n=qo(t.rotation),r=Math.cos(n),i=Math.sin(n);return{x:t.x+e.x*r-e.y*i,y:t.y+e.x*i+e.y*r}}function es(e,t){e.beginPath(),t.forEach((t,n)=>n===0?e.moveTo(t.x,t.y):e.lineTo(t.x,t.y))}function ts(e,t,n){e.beginPath(),e.arc(t.x,t.y,Math.max(n,0),0,Math.PI*2)}function ns(e,t){return t?e===t.net||t.aliases?.includes(e)?{color:H().highlight,alpha:1}:{color:void 0,alpha:Zr}:{color:void 0,alpha:1}}function rs(e,t){return t?t.pins?.some(t=>t in e.pinEnds)?1:Zr:1}var is=1e-9;function as(e,t,n){let r=Math.abs((n.x-t.x)*(e.y-t.y)-(n.y-t.y)*(e.x-t.x))<is,i=(e,t,n)=>e>=Math.min(t,n)-is&&e<=Math.max(t,n)+is;return r&&i(e.x,t.x,n.x)&&i(e.y,t.y,n.y)}function os(e,t,n){return e.wires.some(e=>ns(e.net,n).color!==void 0&&e.points.some((n,r)=>r>0&&as(t,e.points[r-1]??n,n)))}function ss(e,t,n,r,i){e.lineWidth=i(ha);for(let r of t.wires){if(n.movingLabels?.some(e=>e.hideWire===r.id))continue;let t=n.selectedWires?.includes(r.id)??!1,i=t?{color:H().selection,alpha:1}:ns(r.net,n.highlight);e.strokeStyle=i.color??H().wire,e.globalAlpha=i.alpha,ma(e,t),es(e,r.points),e.stroke()}ma(e,!1);for(let i of t.junctions){let a=n.highlight!==void 0&&os(t,i,n.highlight);e.fillStyle=a?H().highlight:H().junction,e.globalAlpha=n.highlight&&!a?Zr:1,ts(e,i,Math.max(Ro,zo*r)),e.fill()}e.globalAlpha=1,e.strokeStyle=H().wire;let a=(n.pending??[]).filter(e=>e.length>=2);if(a.length!==0){e.setLineDash(Bo);for(let t of a)es(e,t),e.stroke();e.setLineDash([])}}function cs(e,t,n,r,i){let a={x:t.x+n.x,y:t.y+n.y,rotation:t.rotation},o=r.fade,s=[];e.globalAlpha=o,e.lineWidth=r.line(Mo),ds(e,t.symbol.shapes,a,H().symbolOutline,s),e.globalAlpha=1;let c=t.symbol.shapes.some(e=>e.type===`text`&&e.role===`pin-number`);t.symbol.kind!==`sheet`&&!c&&s.push(...us(t.symbol,a)),i.push(...s.map(e=>({...e,alpha:o,...ls(e,t)})))}function ls(e,t){if(e.pinOf)return{pinOf:{...e.pinOf,symbol:t.component}};if(e.role!==`reference`&&e.role!==`value`||t.symbol.pins.length!==2)return{};let[n,r]=t.symbol.pins;return n&&r?{maxWidth:Uo*Math.hypot(n.end.x-r.end.x,n.end.y-r.end.y)}:{}}function us(e,t){return e.pins.map(e=>{let n=Ko[e.side],r={x:e.end.x-n.x*Vo,y:e.end.y-n.y*Vo},i=n.x===0?{x:r.x+Ho,y:r.y}:{x:r.x,y:r.y+Ho};return{text:String(e.number),at:$o(i,t),size:.1,anchor:`center`,color:H().pinNumber,mono:!0,kind:`pin-number`}})}function ds(e,t,n,r,i){e.save(),e.translate(n.x,n.y),n.rotation&&e.rotate(qo(n.rotation)),e.strokeStyle=r,e.fillStyle=r;for(let a of t)a.type===`text`?i.push(ms(a,n,r)):a.type===`polyline`&&a.bus?fs(e,a):ps(e,a);e.restore()}function fs(e,t){let[n,r]=[e.strokeStyle,e.fillStyle];e.strokeStyle=H().bus,e.fillStyle=H().bus,es(e,t.points),e.closePath(),e.fill(),e.stroke(),e.strokeStyle=n,e.fillStyle=r}function ps(e,t){if(t.type===`polyline`)es(e,t.points),(t.closed||t.fill)&&e.closePath(),t.fill&&e.fill(),e.stroke();else if(t.type===`circle`)ts(e,t.center,t.radius),t.fill&&e.fill(),e.stroke();else{let n=t.end<t.start?t.end+360:t.end;e.beginPath(),e.arc(t.center.x,t.center.y,t.radius,qo(t.start),qo(n)),e.stroke()}}function ms(e,t,n){let r=e.anchor===`left`?1:e.anchor===`right`?-1:0,i=qo(t.rotation),a=r*Math.cos(i),o=r*Math.sin(i),s=Math.abs(a)>.5?a>0?`left`:`right`:Math.abs(o)>.5?o>0?`bottom`:`top`:`center`,c={role:e.role,kind:Wo[e.role],...e.role===`pin-name`?{pinOf:hs(e,t)}:{},...e.role===`reference`?{strong:!0}:{},...e.role===`pin-number`?{mono:!0}:{}};return{text:e.text,at:$o(e.at,t),size:e.size,anchor:s,color:H()[Go[e.role]]??n,...c}}function hs(e,t){let n=e.anchor===`left`?`left`:e.anchor===`right`?`right`:e.at.y>0?`top`:`bottom`;return{symbol:``,local:e.at,side:n,quarter:Math.abs(Math.sin(qo(t.rotation)))>.5}}function gs(e,t){let n=t.movingLabels?.find(t=>t.id===e.id);return n?{...e,at:n.at,side:n.side}:e}function _s(e,t,n,r,i,a){e.setLineDash(i?Bo:[]),e.globalAlpha=a.alpha,vs(e,t,n,r,a),e.globalAlpha=1,e.setLineDash([])}function vs(e,t,n,r,i){if(t.style!==`label`){let a=t.style===`ground`?kt():At(t.text);e.lineWidth=n(Mo);let o=r.length;ds(e,a,{x:t.at.x,y:t.at.y,rotation:0},i.color??H().flag,r);for(let e=o;e<r.length;e++)r[e]={...r[e],strong:!0,kind:`name`,color:i.color??H().netName,alpha:i.alpha};return}let{middle:a,upright:o,box:s}=Ft(t);r.push({text:t.text,at:a,size:jt,anchor:`center`,strong:!0,kind:`name`,color:i.color??H().netName,rotation:o?90:0,alpha:i.alpha}),t.port&&ys(e,t,s,n,i)}function ys(e,t,n,r,i){e.strokeStyle=i.color??H().netName,e.lineWidth=r(t.bus?Mo*3:Mo),e.beginPath(),e.moveTo(n.minX,n.minY),e.lineTo(n.maxX,n.minY),e.lineTo(n.maxX,n.maxY),e.lineTo(n.minX,n.maxY),e.closePath(),e.stroke()}function bs(e,t,n,r,i){for(let a of t.symbols){let t=i(a);for(let[i,o]of Object.entries(a.pinEnds)){let a=n.highlight?.pins?.includes(i)??!1,s=(n.activePins?.includes(i)??!1)||a;if(!s&&!n.showPins)continue;e.fillStyle=s?H().highlight:H().pin;let c=a?Math.min(Po*r,Math.max(Fo,Io*r)):(s?Lo:1)*Po*r;ts(e,{x:o.x+t.x,y:o.y+t.y},c),e.fill()}}}var xs=2;function Ss(e,t){return Math.max(e,Jo(t)/2+xs)}var Cs=e=>Ss(6,e);function ws(e,t,n){let r=n.x-t.x,i=n.y-t.y,a=r*r+i*i,o=a===0?0:Math.max(0,Math.min(1,((e.x-t.x)*r+(e.y-t.y)*i)/a));return Math.hypot(e.x-(t.x+o*r),e.y-(t.y+o*i))}function Ts(e,t){let n;for(let r=1;r<e.length;r++){let i=ws(t,e[r-1],e[r]);(!n||i<n.distance)&&(n={index:r-1,distance:i})}return n}function Es(e,t,n){let r=Ts(e,t);return r&&r.distance<=n?r.index:void 0}function Ds(e,t,n){let r;for(let i of e){let e=Ts(i.points,t);e&&e.distance<=n&&(!r||e.distance<r.distance)&&(r={id:i.id,distance:e.distance})}return r?.id}function Os(e){return e.length<2?{corners:[],ends:[...e]}:{corners:e.slice(1,-1),ends:[e[0],e[e.length-1]]}}function ks(e,t,n){let r=e.findIndex((r,i)=>i>0&&i<e.length-1&&Math.abs(r.x-t.x)<=n&&Math.abs(r.y-t.y)<=n);return r<0?void 0:r}var As=1e-9,js={x:0,y:0},Ms=(e,t)=>Math.abs(e-t)<As;function Ns(e,t){return Ms(e.y,t.y)?`horizontal`:Ms(e.x,t.x)?`vertical`:`slanted`}function Ps(e,t){return e===`horizontal`?{x:0,y:t.y}:e===`vertical`?{x:t.x,y:0}:t}function Fs(e,t){return e===`horizontal`?Ms(t.y,0):e!==`vertical`||Ms(t.x,0)}function Is(e,t){return e.map((e,n)=>{let r=[t.get(n-1),t.get(n)].filter(e=>e!==void 0);return{x:r.find(e=>!Ms(e.x,0))?.x??0,y:r.find(e=>!Ms(e.y,0))?.y??0}})}function Ls(e,t,n,r){if(t===0||t===e.length-1)return!0;let i=r.has(t)?t-1:t,[a,o]=[e[i],e[i+1]];return a!==void 0&&o!==void 0&&!Fs(Ns(a,o),n)}function Rs(e,t){let n=Is(e,t);return Cn(e.flatMap((r,i)=>{let a=n[i]??js,o={x:r.x+a.x,y:r.y+a.y},s=t.has(i-1);return s===t.has(i)||!Ls(e,i,a,t)?[o]:s?[o,r]:[r,o]}))}function zs(e,t,n){let[r,i]=[e[t],e[t+1]];return!r||!i?Cn(e):Rs(e,new Map([[t,Ps(Ns(r,i),n)]]))}function Bs(e,t,n){let[r,i,a]=[e[t-1],e[t],e[t+1]];if(!r||!i||!a)return Cn(e);let o={x:n.x-i.x,y:n.y-i.y};return Rs(e,new Map([[t-1,Ps(Ns(r,i),o)],[t,Ps(Ns(i,a),o)]]))}var Vs=(e,t)=>({x:e.x+t.x,y:e.y+t.y});function Hs(e,t,n){let[r,i,a,o]=[e[0],e[1],e[e.length-2],e[e.length-1]];if(!r||!i||!a||!o)return Cn(e);let s=n.start?[Vs(r,t)]:[r,Vs(r,Ps(Ns(r,i),t))],c=n.end?[Vs(o,t)]:[Vs(o,Ps(Ns(a,o),t)),o];return Cn([...s,...e.slice(1,-1).map(e=>Vs(e,t)),...c])}function Us(e,t){let[n,r]=[e[t-1],e[t]];if(!n||!r||t>=e.length-1)return Cn(e);let i=e.slice(0,-2).map(()=>!1);return i[t-1]=Ns(n,r)===`horizontal`,Cn(Sn(e.filter((e,n)=>n!==t),i))}var Ws=Cn,Gs=`The pin of this wire has several traces to its net; change its corners in the code`,Ks=1e-6;function qs(e,t){return e.slice(1).some((n,r)=>{let i=e[r],a=(n.x-i.x)*(t.y-i.y)-(n.y-i.y)*(t.x-i.x),o=Math.min(i.x,n.x)-Ks<=t.x&&t.x<=Math.max(i.x,n.x)+Ks&&Math.min(i.y,n.y)-Ks<=t.y&&t.y<=Math.max(i.y,n.y)+Ks;return Math.abs(a)<=Ks&&o})}function Js(e,t,n,r){return e.schematic.wires.some(e=>e.id!==t&&e.net===n&&qs(e.points,r))}function Ys(e,t,n,r){let i=fr(e,t,{pin:n.id},{net:gr(e,r)}),[a]=i;if(!a)return{};if(i.length>1||a.props.schematicRouteHints)return{blocked:Gs};let o=mr(a)??_r(t,a);return o===void 0?{trace:a}:{blocked:o}}function Xs(e,t,n,r){let i=(e.pinLast?[...r].reverse():[...r]).slice(1),{trace:a}=e;if(!a)return[{kind:`addTrace`,from:t,to:n,schematicRouteHints:i}];let o=(a.from??``).startsWith(`net.`);return[{kind:`setTraceHints`,from:a.from??``,to:a.to??``,schematicRouteHints:o?[...i].reverse():i}]}var Zs=/^wire:.+:\d+$/,Qs=e=>e.startsWith(`net.`),$s=(e,t)=>e.x===t.x&&e.y===t.y,ec=(e,t)=>e.circuit.components.flatMap(e=>e.pins).find(e=>e.id===t);function tc(e,t,n){return{id:e,points:t,fixed:{start:!0,end:!0},writer:n}}function nc(e,t,n){let r=t=>Qs(t)?{net:gr(e,t)}:{pin:t};return pr(fr(e,t,r(n.from),r(n.to)).filter(t=>dr(e,t.from,r(n.from))),n.id)}function rc(e,t,n,r,i){let a=nc(e,t,i);if(!a)return tc(n,r,{kind:`none`,reason:`The wire is not written in a trace the Studio can find`});let o=[i.from,i.to].filter(e=>!Qs(e)),s=o.map(t=>ec(e,t)?.component??``),c=o.length===1,l=_r(t,a);return tc(n,r,{kind:`trace`,trace:a,toNet:c,reversed:c&&Qs(i.from),components:s,...l?{repeat:l}:{}})}function ic(e,t,n){let r=t.find(t=>e.schematic.symbols.some(e=>e.pinEnds[t]!==void 0&&$s(e.pinEnds[t],n)));return r===void 0?void 0:ec(e,r)}var ac=(e,t)=>{let n=t.find(t=>!ar(jn(e,t)));return n?{unaddressable:`${n.id} has a repeated name and cannot be wired from the Studio`}:{}};function oc(e,t,n,r,i,a,o){let s=e.circuit.nets.find(e=>e.id===o)?.names[0],c=a?r[0]:r[r.length-1];if(s===void 0||!c||!Js(e,n,o,c))return;let l={pinLast:a,...Ys(e,t,i,o)};return tc(n,r,{kind:`engine`,from:jn(e,i),to:`net.${s}`,components:[i.component],...ac(e,[i]),onWire:l})}function sc(e,t,n,r,i){let a=e.circuit.nets.find(e=>e.id===i),[o,s]=[r[0],r[r.length-1]],[c,l]=o&&s&&a?[ic(e,a.pins,o),ic(e,a.pins,s)]:[];return(c&&!l?oc(e,t,n,r,c,!1,i):!c&&l?oc(e,t,n,r,l,!0,i):void 0)||(!c||!l?tc(n,r,{kind:`none`,reason:`The pins of this wire are not on the sheet`}):tc(n,r,{kind:`engine`,from:jn(e,c),to:jn(e,l),components:[c.component,l.component],...ac(e,[c,l])}))}function cc(e,t,n){let r=e.schematic.wires.find(e=>e.id===n);if(!r)return;let i=r.points.map(e=>({x:e.x,y:e.y})),a=e.circuit.connections.find(e=>e.id===r.connection);return a?rc(e,t,r.id,i,a):Zs.test(r.id)?sc(e,t,r.id,i,r.net):tc(r.id,i,{kind:`none`,reason:`This wire is not drawn from the code`})}function lc(e,t,n=ur){let{writer:r}=t;if(r.kind===`none`)return r.reason;let i=hr(e,r.components,r.kind===`trace`?r.trace:void 0,n);return i===void 0?r.kind===`engine`?r.unaddressable??r.onWire?.blocked??null:r.repeat??mr(r.trace)??null:`${i} is locked`}function uc(e,t){let n=e.slice(1,t.toNet?void 0:-1);return t.reversed?[...n].reverse():n}function dc(e,t){let[n,r]=[e[0],e[e.length-1]],[i,a]=[t.points[0],t.points[t.points.length-1]];return n!==void 0&&r!==void 0&&i!==void 0&&a!==void 0&&$s(n,i)&&$s(r,a)}var fc=(e,t)=>e.length===t.length&&e.every((e,n)=>$s(e,t[n]));function pc(e,t,n,r=ur,i=t.points){let a=lc(e,t,r);if(a!==null)return{blocked:a};let o=Ws(n);if(!dc(o,t))return{blocked:`The ends of a wire stay on their pins`};if(fc(o,Ws(i)))return[];let{writer:s}=t;if(s.kind===`trace`)return[{kind:`setTraceHints`,from:s.trace.from??``,to:s.trace.to??``,schematicRouteHints:uc(o,s)}];if(s.kind!==`engine`)return[];if(s.onWire)return Xs(s.onWire,s.from,s.to,o);let c=o.slice(1,-1);return[{kind:`addTrace`,from:s.from,to:s.to,...c.length>0?{schematicRouteHints:c}:{}}]}var mc=e=>({hover:e.hover,selected:e.selection,handleFill:e.handleFill});mc(la);var hc=3,gc=e=>Ss(hc,e),_c=[4,3],vc=(e,t)=>{let n=Math.hypot(t.x-e.x,t.y-e.y);return{x:(t.x-e.x)/n,y:(t.y-e.y)/n}},yc=e=>({x:-e.y,y:e.x}),bc=(e,t,n)=>({x:e.x+t.x*n,y:e.y+t.y*n});function xc(e,t,n,r,i){let a=e[n];if(n===0)return bc(bc(a,t[0],-r),yc(t[0]),r*i);if(n===e.length-1)return bc(bc(a,t[n-1],r),yc(t[n-1]),r*i);let[o,s]=[yc(t[n-1]),yc(t[n])],c=o.x*s.x+o.y*s.y;return bc(a,1+c<.1?o:{x:(o.x+s.x)/(1+c),y:(o.y+s.y)/(1+c)},r*i)}function Sc(e,t){let n=e.filter((t,n)=>n===0||t.x!==e[n-1]?.x||t.y!==e[n-1]?.y);if(n.length<2)return[];let r=n.slice(1).map((e,t)=>vc(n[t],e)),i=e=>n.map((i,a)=>xc(n,r,a,t,e));return[...i(1),...i(-1).reverse()]}function Cc(e,t,n,r,i,a){let o=Sc(r.map(e=>fe(t,n,e)),gc(t.scale));o.length!==0&&(e.save(),e.strokeStyle=i.hover,e.lineWidth=wa(a),e.setLineDash(_c),e.beginPath(),o.forEach((t,n)=>n===0?e.moveTo(t.x,t.y):e.lineTo(t.x,t.y)),e.closePath(),e.stroke(),e.restore())}function wc(e,t,n,r,i,a){let{corners:o,ends:s}=Os(r),c=Da(6,a),l=wa(a),u=(r,i)=>{let o=fe(t,n,r),[s,u]=[Ea(o.x-c/2,a),Ea(o.y-c/2,a)];i&&e.fillRect(s,u,c,c),e.strokeRect(s+l/2,u+l/2,c-l,c-l)};e.save(),e.fillStyle=i.handleFill,e.strokeStyle=i.selected,e.lineWidth=l,e.setLineDash([]);for(let e of o)u(e,!0);for(let e of s)u(e,!1);e.restore()}var Tc=e=>3/e,Ec=e=>Cs(e)/e;function Dc(e,t,n,r){let i=t===void 0?void 0:e?.points(t),a=i?ks(i,n,Tc(r)):void 0;return t===void 0||a===void 0?void 0:{id:t,index:a}}function Oc(e,t,n,r){let i=t.selection.soleWire;if(i!==void 0&&Si({kind:`wire`,id:i},t))return Dc(e,i,n,r)}function kc(e,t,n,r){if(r!==void 0)return{kind:`corner`,index:r};let i=Es(e,t,Ec(n));return i===void 0?void 0:{kind:`segment`,index:i}}function Ac(e,t,n,r){let i=e[t.index];if(!i)return Ws(e);let a={x:ve(i.x+n.x,r.step,r.snap),y:ve(i.y+n.y,r.step,r.snap)};return t.kind===`corner`?Bs(e,t.index,a):zs(e,t.index,{x:a.x-i.x,y:a.y-i.y})}function jc(e,t,n,r){let i=e?.points(t);if(e&&i)return{kind:`reshape`,wire:t,grip:n,points:i,path:i,start:r,moved:!1,blocker:e.blocker(t)}}function Mc(e,t,n,r){return e.blocker?(e.moved||r(e.blocker),{...e,moved:!0}):{...e,moved:!0,path:Ac(e.points,e.grip,t,n)}}var Nc=`The wire changed while you dragged it; try again`;function Pc(e,t,n){if(!e||!t.moved||t.blocker||fc(t.path,Ws(t.points)))return;let r=e.points(t.wire);if(!r||!fc(r,t.points))return n(Nc);e.commit(t.wire,t.path)}function Fc(e,t){return!e?.moved||e.blocker?t:[{id:e.wire,points:e.path},...t.filter(t=>t.id!==e.wire)]}function Ic(e,t){return t.length===0?e:e.map(e=>{let n=t.find(t=>t.id===e.id);return n?{...e,points:[...n.points]}:e})}var Lc=e=>e.missingLayer===void 0?{}:{missingLayer:e.missingLayer};function Rc(e,t){return e.missingLayer===void 0?e.kind===`via`?t.multiLayer:(e.layer===`top`||e.layer===`bottom`)&&t[e.layer]:t.keepout}var zc=2,Bc=(e,t)=>Math.max(6,e*t/2+zc)/t;function Vc(e,t,n,r,i){let a=e.find(e=>Rc({kind:`via`,...Lc(e)},r)&&Si({kind:`via`,id:e.id},i)&&Math.hypot(t.x-e.at.x,t.y-e.at.y)<=Bc(e.diameter,n));return a&&{kind:`via`,id:a.id}}function Hc(e,t){let n=1/0;for(let r=1;r<e.length;r++)n=Math.min(n,ws(t,e[r-1],e[r]));return n}function Uc(e,t,n,r,i){let a;for(let o of e){if(!Rc({kind:`track`,layer:o.layer,...Lc(o)},r)||!Si({kind:`track`,id:o.id},i))continue;let e=Hc(o.points,t);e<=Bc(o.width,n)&&(!a||e<a.distance)&&(a={id:o.id,distance:e})}return a&&{kind:`track`,id:a.id}}function Wc(e,t,n,r,i){return Vc(e.vias,t,n,r,i)??Uc(e.tracks,t,n,r,i)}function Gc(e,t,n,r,i){let a=Wc(e,t,n,r,i),o=a?.kind===`track`?e.tracks.find(e=>e.id===a.id):void 0,s=o&&Es(o.points,t,Bc(o.width,n));return o&&s!==void 0?Ki(o,s):void 0}function Kc(e,t,n,r,i=0){let a=r?ks(e,t,Tc(n)):void 0;if(a!==void 0)return{kind:`corner`,index:a};let o=Es(e,t,Bc(i,n));return o===void 0?void 0:{kind:`segment`,index:o}}var qc=(e,t)=>{let n=e.map(e=>e.x),r=e.map(e=>e.y),i=e=>z(e);return{minX:i(Math.min(...n)-t),minY:i(Math.min(...r)-t),maxX:i(Math.max(...n)+t),maxY:i(Math.max(...r)+t)}};function Jc(e,t){let n=e.tracks.filter(e=>Rc({kind:`track`,layer:e.layer,...Lc(e)},t)),r=e.vias.filter(e=>Rc({kind:`via`,...Lc(e)},t));return[...n.map(e=>({kind:`track`,id:e.id,box:qc(e.points,e.width/2)})),...r.map(e=>({kind:`via`,id:e.id,box:qc([e.at],e.diameter/2)}))]}function Yc(e,t,n,r){let i=new Set(Ni(e,t,n,r));return e.filter(e=>i.has(e.id)).map(({kind:e,id:t})=>({kind:e,id:t}))}var Xc=.4,Zc=.7,Qc=1.5,$c={top:B.topCopper,bottom:B.bottomCopper,inner1:B.topCopper,inner2:B.topCopper},el=e=>e.missingLayer===void 0?$c[e.layer]:B.keepout,tl=e=>e.missingLayer===void 0?B.viaRing:B.keepout,nl=(e,t)=>Rc({kind:`track`,layer:e.layer,...Lc(e)},t),rl=(e,t)=>Rc({kind:`via`,...Lc(e)},t),il=(e,t)=>e&&(t===void 0||!e.nets.includes(t))?Qr:1;function al(e,t,n,r){e.strokeStyle=n,e.lineWidth=r,e.beginPath(),t.forEach((t,n)=>n===0?e.moveTo(t.x,t.y):e.lineTo(t.x,t.y)),e.stroke()}function ol(e,t,n,r){e.fillStyle=r,e.beginPath(),e.arc(t.x,t.y,Math.max(n,0),0,Math.PI*2),e.fill()}function sl(e,t,n,r){let i=t.activeLayer??`top`,a=t.tracks.filter(e=>nl(e,n)),o=e=>e.layer===i||e.missingLayer!==void 0,s=[...a.filter(e=>!o(e)),...a.filter(o)];for(let t of s)e.globalAlpha=(o(t)?1:Xc)*il(r,t.net),al(e,t.points,el(t),t.width);e.globalAlpha=1}function cl(e,t,n,r){for(let i of t.vias.filter(e=>rl(e,n)))e.globalAlpha=il(r,i.net),ol(e,i.at,i.diameter/2,tl(i)),n.hole&&ol(e,i.at,i.drill/2,B.drill);e.globalAlpha=1}function ll(e,t,n){for(let{drawing:r,alpha:i}of t.routes??[]){e.globalAlpha=i;for(let t of r.tracks)Rc({kind:`track`,layer:t.layer},n)&&al(e,t.points,$c[t.layer],t.width);if(Rc({kind:`via`},n))for(let t of r.vias)ol(e,t.at,t.diameter/2,B.viaRing),n.hole&&ol(e,t.at,t.drill/2,B.drill)}e.globalAlpha=1}function ul(e,t,n){let{segment:r}=e;return n&&r?.id===t.id&&qi(r,t.points)?[r.from,r.to]:t.points}function dl(e,t,n,r,i,a,o){let s=t.tracks.find(e=>e.id===r);if(s&&nl(s,n)){let n=ul(t,s,a);al(e,n,i,s.width+2*Qc*o),al(e,n,el(s),s.width),a&&al(e,n,B.selectionFill,s.width);return}let c=t.vias.find(e=>e.id===r);c&&rl(c,n)&&(ol(e,c.at,c.diameter/2+Qc*o,i),ol(e,c.at,c.diameter/2,tl(c)),a&&ol(e,c.at,c.diameter/2,B.selectionFill),n.hole&&ol(e,c.at,c.drill/2,B.drill))}function fl(e,t,n,r,i){sl(e,t,n,r),cl(e,t,n,r),ll(e,t,n),t.hover!==void 0&&!t.selected.has(t.hover)&&dl(e,t,n,t.hover,B.hover,!1,i);for(let r of t.selected)dl(e,t,n,r,B.selection,!0,i)}var pl=e=>e.pcb.board?.pours??[];function ml(e,t){return e.outline??t?.outline??[]}function hl(e,t){return e.circuit.nets.find(e=>e.id===t)?.names[0]??t}var gl=(e,t)=>`pour ${hl(e,t.net)} · ${t.layer}`,_l=e=>`${Number(e.toFixed(4))} mm`,vl=e=>`hole ${_l(e.diameter)}`;function yl(e,t,n){return n.has(e.id)?!1:e.layer===`top`||e.layer===`bottom`?t[e.layer]:e.layer===`inner1`||e.layer===`inner2`}function bl(e){return e.map((t,n)=>[t,e[(n+1)%e.length]])}function xl(e,t,n,r,i){let a=6/n,o;for(let n of pl(e))if(yl(n,r,i))for(let[r,i]of bl(ml(n,e.pcb.board))){let e=ws(t,r,i);e<=a&&(!o||e<o.distance)&&(o={id:n.id,distance:e})}return o?.id}function Sl(e,t,n){let r=7/n,i=e.findIndex(e=>Math.hypot(e.x-t.x,e.y-t.y)<=r);return i===-1?void 0:i}function Cl(e,t,n,r){if(!r.hole)return;let i=3/n;return e.find(e=>Math.hypot(e.x-t.x,e.y-t.y)<=e.diameter/2+i)?.id}function wl(e,t){let n=!1;for(let[r,i]of bl(t))r.y>e.y!=i.y>e.y&&e.x<(i.x-r.x)*(e.y-r.y)/(i.y-r.y)+r.x&&(n=!n);return n}function Tl(e,t){return e.polygons.some(e=>wl(t,e.outer)&&!e.holes.some(e=>wl(t,e)))}function El(e,t,n,r,i){let a=e.pcb.pours.filter(e=>yl(e,n,r));return[...a.filter(e=>e.layer===i),...a.filter(e=>e.layer!==i)].find(e=>Tl(e,t))?.id}function Dl(e,t){let n=e.pcb.holes.find(e=>e.id===t);if(n)return{x:n.x,y:n.y};let r=pl(e).find(e=>e.id===t),i=r?ml(r,e.pcb.board):[];if(i.length===0)return;let a=i.map(e=>e.x),o=i.map(e=>e.y);return{x:(Math.min(...a)+Math.max(...a))/2,y:(Math.min(...o)+Math.max(...o))/2}}var Ol=[`solid`,`hatched`,`outline`],kl=`solid`,Al=`copperflow.pourFill`,jl=.35,W=e=>Ol.includes(e);function G(e){try{let t=e()?.getItem(Al);return W(t)?t:kl}catch{return kl}}function Ml(e,t){try{let n=e();return n?(n.setItem(Al,t),!0):!1}catch{return!1}}function Nl(e){return{pourSolid:e===`solid`,pourHatched:e===`hatched`,pourOutline:e===`outline`}}var Pl={pourSolid:`solid`,pourHatched:`hatched`,pourOutline:`outline`},Fl={top:B.topCopper,bottom:B.bottomCopper,inner1:B.inner1Copper,inner2:B.inner2Copper},Il=Fl,Ll=.5,Rl=6,zl=1,Bl=1.5;function Vl(e,t){t.forEach((t,n)=>n===0?e.moveTo(t.x,t.y):e.lineTo(t.x,t.y)),e.closePath()}function Hl(e,t){Gl()&&e instanceof Path2D||e.beginPath();for(let n of t.polygons){Vl(e,n.outer);for(let t of n.holes)Vl(e,t)}}function Ul(e,t=0){let n=e.polygons.flatMap(e=>e.outer);if(n.length===0)return[];let r=n.map(e=>e.x),i=n.map(e=>e.y),[a,o,s,c]=[Math.min(...r),Math.max(...r),Math.min(...i),Math.max(...i)],l=c-s,u=a-l,d=o-u,f=Math.max(Ll,6*t,d/399),p=Math.floor(d/f+1e-9)+1;return Array.from({length:p},(e,t)=>[{x:u+t*f,y:s},{x:u+t*f+l,y:c}])}var Wl=new WeakMap,Gl=()=>typeof Path2D==`function`;function Kl(e){let t=Wl.get(e);if(t)return t;let n={};return Wl.set(e,n),n}function ql(e){if(!Gl())return;let t=Kl(e);return t.rings||(t.rings=new Path2D,Hl(t.rings,e)),t.rings}function Jl(e,t){if(!Gl())return;let n=Kl(e);if(n.hatch?.px!==t){let r=new Path2D;for(let[n,i]of Ul(e,t))r.moveTo(n.x,n.y),r.lineTo(i.x,i.y);n.hatch={px:t,path:r}}return n.hatch.path}function Yl(e,t,n){e.lineWidth=n;let r=ql(t);if(r)return e.stroke(r);Hl(e,t),e.stroke()}function Xl(e,t,n){let r=ql(t);if(r)return n===`fill`?e.fill(r,`evenodd`):e.clip(r,`evenodd`);Hl(e,t),n===`fill`?e.fill(`evenodd`):e.clip(`evenodd`)}function Zl(e,t,n){let r=Jl(t,n);if(r)return e.stroke(r);e.beginPath();for(let[r,i]of Ul(t,n))e.moveTo(r.x,r.y),e.lineTo(i.x,i.y);e.stroke()}function Ql(e,t,n,r){let i=Il[t.layer]??B.topCopper;if(e.fillStyle=i,e.strokeStyle=i,n===`outline`)e.globalAlpha=1,Yl(e,t,zl*r);else{if(e.globalAlpha=jl,n===`solid`)return Xl(e,t,`fill`);e.save(),Xl(e,t,`clip`),e.lineWidth=zl*r,e.globalAlpha=1,Zl(e,t,r),e.restore(),e.globalAlpha=1,Yl(e,t,zl*r)}}function $l(e,t,n,r,i){let a=(t.pours??[]).filter(e=>yl(e,r,n.hidden)),o=[...a.filter(e=>e.layer!==n.activeLayer),...a.filter(e=>e.layer===n.activeLayer)];for(let t of o)Ql(e,t,n.mode,i);e.globalAlpha=1}function eu(e,t,n){let r=n/2;e.beginPath(),e.moveTo(t.x-r,t.y-r),e.lineTo(t.x+r,t.y-r),e.lineTo(t.x+r,t.y+r),e.lineTo(t.x-r,t.y+r),e.closePath()}function tu(e,t,n,r){if(e.strokeStyle=B.selection,e.lineWidth=Bl*r,e.beginPath(),Vl(e,t),e.stroke(),n){e.fillStyle=B.selection;for(let n of t)eu(e,n,Rl*r),e.fill()}}function nu(e,t,n,r,i,a){if(r.selected.has(t.id))return tu(e,n,t.outline!==void 0,i);let o=r.hover===t.id;(o||t.outline!==void 0)&&(e.strokeStyle=o?B.hover:Il[t.layer]??B.topCopper,e.lineWidth=Math.max(a,zl*i),e.setLineDash([4*i,3*i]),e.beginPath(),Vl(e,n),e.stroke(),e.setLineDash([]))}function ru(e,t,n){t.length<2||(e.strokeStyle=B.selection,e.lineWidth=zl*n,e.setLineDash([4*n,3*n]),e.beginPath(),Vl(e,t),e.stroke(),e.setLineDash([]))}function iu(e,t,n,r,i,a){for(let o of t.board?.pours??[])yl(o,r,n.hidden)&&nu(e,o,n.outlines?.get(o.id)??ml(o,t.board),n,i,a);n.preview&&ru(e,n.preview,i)}function au(e,t,n,r,i,a){if(r.hole)for(let r of t){let t=r.diameter/2;e.fillStyle=B.drill,e.beginPath(),e.arc(r.x,r.y,t,0,Math.PI*2),e.fill();let o=n.selected.has(r.id);e.strokeStyle=o?B.selection:n.hover===r.id?B.hover:B.multiLayer,e.lineWidth=o?Bl*i:a,e.stroke()}}var K=(e,t=!1)=>({action:e,preventDefault:t}),ou=new Map([[`ArrowLeft`,{action:`nudgeLeft`,dx:-1,dy:0}],[`ArrowRight`,{action:`nudgeRight`,dx:1,dy:0}],[`ArrowUp`,{action:`nudgeUp`,dx:0,dy:1}],[`ArrowDown`,{action:`nudgeDown`,dx:0,dy:-1}]]);function su(e){for(let t of ou.values())if(t.action===e)return{dx:t.dx,dy:t.dy}}function cu(e){let t=ou.get(e.key);return!t||e.onButton||e.ctrlKey||e.metaKey||e.altKey?null:{action:t.action,preventDefault:!0,steps:e.shiftKey?10:1}}var lu=`tr, [role='row'], [role='gridcell'], [role='grid'], [role='listbox'], [role='option'], [role='tree'], [role='treeitem'], [role='tablist'], [role='tab'], [role='radiogroup'], [role='menu'], [role='menubar'], [role='menuitem'], [role='menuitemcheckbox'], [data-keys='own']`,uu=`input:not([type='checkbox']):not([type='radio']), textarea, select, [contenteditable='true']`,du=`button, a[href], summary, input[type='checkbox'], input[type='radio']`,fu=`[data-keys='parts']`;function pu(e){let t=e.target instanceof HTMLElement?e.target:null;return{key:e.key,code:e.code,shiftKey:e.shiftKey,altKey:e.altKey,ctrlKey:e.ctrlKey,metaKey:e.metaKey,altGraph:e.getModifierState?.(`AltGraph`)??!1,typing:t?.closest(uu)!=null,onButton:t?.closest(du)!=null,ownsKeys:t?.closest(lu)!=null,partRows:t?.closest(fu)!=null,handled:e.defaultPrevented}}var mu=e=>e.code?.startsWith(`Key`)?e.code.slice(3).toLowerCase():e.key.toLowerCase(),hu=new Map([[`w`,`wire`],[`n`,`armNetLabel`],[`b`,`drawBus`],[`l`,`drawPolyline`],[`r`,`drawRectangle`],[`c`,`drawCircle`],[`a`,`drawArc`],[`t`,`drawText`],[`j`,`junction`]]),gu=new Map([[`w`,`route`],[`v`,`placeVia`]]);function _u(e,t){if(e.shiftKey)return null;let n=mu(e);if(n===`s`)return K(`toggleSnap`,!0);let r=(t.view===`schematic`?hu:gu).get(n);return r?K(r,!0):null}function vu(e,t,n){switch(e){case`w`:return K(n.view===`schematic`?`wire`:`route`);case`v`:return n.view===`pcb`?K(`switchLayer`,!0):null;case`r`:return K(`rotate`);case`k`:return K(`fit`);case`f`:return t.shiftKey?K(`openLibrary`,!0):K(`fit`);case`h`:return t.shiftKey?K(`clearHighlight`):K(`highlight`);case`q`:return n.view===`pcb`?K(`toggleUnit`):null;case`u`:return n.view===`pcb`?K(t.shiftKey?`straightenTracks`:`filletTracks`,!0):null;case`l`:return n.view===`pcb`&&!t.shiftKey?K(`routingCorner`,!0):null;case`x`:return n.view===`pcb`&&!t.shiftKey?K(`flip`,!0):null;default:return null}}var yu=new Map([[`[`,`toggleLeftPanel`],[`]`,`toggleRightPanel`],[`\\`,`toggleBottomPanel`]]),bu=e=>!e.metaKey&&(e.altGraph===!0||e.ctrlKey&&e.altKey||!e.ctrlKey&&!e.altKey),xu=new Map([[`z`,`undo`],[`y`,`redo`],[`o`,`openFile`],[`a`,`selectAll`],[`f`,`find`],[`c`,`copy`],[`v`,`paste`]]),Su=new Map([[`z`,`redo`],[`l`,`alignLeft`],[`h`,`distributeH`],[`f`,`findSimilar`],[`x`,`placementTransfer`]]);function Cu(e){if(e.altKey||e.altGraph)return null;let t=(e.shiftKey?Su:xu).get(e.key.toLowerCase());return t?K(t,t!==`copy`):null}function wu(e,t){return t.drawing?e.key===`Backspace`&&!e.ownsKeys?K(`removeCorner`,!0):null:K(`delete`)}var Tu=e=>e.key===`Delete`||e.key===`Backspace`,Eu=e=>e.ownsKeys===!0&&!(e.partRows===!0&&Tu(e)),Du=e=>e.key===`ContextMenu`||e.key===`F10`&&e.shiftKey&&!e.ctrlKey&&!e.altKey&&!e.metaKey;function Ou(e,t){if(e.typing)return null;if(Du(e))return K(`contextMenu`,!0);let n=yu.get(e.key);return n&&bu(e)?K(n):e.ctrlKey||e.metaKey?Cu(e):e.altKey?_u(e,t):e.handled||Eu(e)?null:cu(e)||(e.key===`Enter`?t.drawing&&!e.onButton&&!e.shiftKey?K(`finishShape`,!0):null:Tu(e)?wu(e,t):e.key===` `?e.onButton?null:K(t.drawing?`flipBend`:`rotate`,!0):vu(e.key.toLowerCase(),e,t))}function ku(e){return e.key===`Escape`&&!e.typing}var Au=e=>xt(e)+0,ju=e=>Math.round((e%360+360)%360/90)%4;function Mu(e,t){switch(ju(t)){case 1:return{x:Au(-e.y),y:Au(e.x)};case 2:return{x:Au(-e.x),y:Au(-e.y)};case 3:return{x:Au(e.y),y:Au(-e.x)};default:return{x:Au(e.x),y:Au(e.y)}}}function Nu(e,t){let n=Mu(e,t.rotation);return{x:Au(t.x+n.x),y:Au(t.y+n.y)}}var Pu={reference:`schNameAt`,value:`schValueAt`},Fu=(e,t)=>`${e}:${t}`;function q(e){let t=e.lastIndexOf(`:`);return t>0?{part:e.slice(0,t),prop:e.slice(t+1)}:void 0}function Iu(e,t,n){let r=bt*t*n/2;return{minX:e.x-r,maxX:e.x+r,minY:e.y-t/2,maxY:e.y+t/2}}function Lu(e){return e.symbol.shapes.flatMap(t=>{if(t.type!==`text`||t.role!==`reference`&&t.role!==`value`)return[];let n=Nu(t.at,e),r=Pu[t.role],i={x:Au(n.x-e.x),y:Au(n.y-e.y)};return[{id:Fu(e.component,r),part:e.component,prop:r,text:t.text,at:n,offset:i,box:Iu(n,t.size,t.text.length)}]})}var Ru=.8,zu={schematic:[`schNameAt`,`schValueAt`],pcb:[`pcbNameAt`]},Bu={schNameAt:`Name`,schValueAt:`Value`,pcbNameAt:`Designator`};function Vu(e){let t=q(e)?.prop;if(t!==void 0)return zu.schematic.includes(t)?`schematic`:zu.pcb.includes(t)?`pcb`:void 0}function Hu(e){return e.symbols.flatMap(e=>Lu(e))}function Uu(e){let t=Xr(e),n={x:t.x-e.x,y:t.y-e.y};return{id:Fu(e.component,`pcbNameAt`),part:e.component,prop:`pcbNameAt`,text:e.component,at:t,offset:n,box:Iu(t,Ru,e.component.length)}}function Wu(e){return e.parts.map(Uu)}function Gu(e,t){return e===`pcb`?Wu(t.pcb):Hu(t.schematic)}var Ku=(e,t)=>t.x>=e.minX&&t.x<=e.maxX&&t.y>=e.minY&&t.y<=e.maxY,qu=e=>(e.maxX-e.minX)*(e.maxY-e.minY);function Ju(e,t){return e.filter(e=>Ku(e.box,t)).sort((e,t)=>qu(e.box)-qu(t.box))[0]}function Yu(e,t){let n=t.x-e.at.x,r=t.y-e.at.y,{box:i}=e;return{...e,at:t,offset:{x:e.offset.x+n,y:e.offset.y+r},box:{minX:i.minX+n,maxX:i.maxX+n,minY:i.minY+r,maxY:i.maxY+r}}}function Xu(e,t){return t.length===0?[...e]:e.map(e=>{let n=t.find(t=>t.id===e.id);return n?Yu(e,n.at):e})}function Zu(e,t){let n={x:e.at.x-e.offset.x,y:e.at.y-e.offset.y},r={x:z(t.x-n.x),y:z(t.y-n.y)};return z(e.offset.x)===r.x&&z(e.offset.y)===r.y?[]:[{kind:`setProps`,part:e.part,props:{[e.prop]:r}}]}function Qu(e){let t=q(e);return t?[{kind:`setProps`,part:t.part,props:{[t.prop]:null}}]:[]}function $u(e,t){let n=q(t);return n!==void 0&&e.model.parts.find(e=>e.name===n.part)?.props[n.prop]!==void 0}function ed(e,t,n){let r=q(n),i=r&&e.model.parts.find(e=>e.name===r.part);if(!r||!i)return`This part has no editable source element`;if(t.has(i.name))return`${i.name} is locked`;if(!i.editable)return`${i.name} is read-only (${i.readonlyReason})`;let a=i.props[r.prop];return a&&!a.editable?`${i.name}.${r.prop} is an expression; change it in the code`:null}function td(e,t,n,r){let i=od(e,t,n,r);return i?i.blocker??(i.moved?null:`It is where the layout puts it`):`It is not on this sheet`}function nd(e,t,n){let r=t===`schNameAt`?`reference`:t===`schValueAt`?`value`:void 0,i=Mu({x:n.x-e.x,y:n.y-e.y},-e.rotation),a=e.symbol.shapes.map(e=>e.type===`text`&&e.role===r?{...e,at:i,anchor:`center`}:e);return{...e,symbol:{...e.symbol,shapes:a}}}function rd(e,t){if(t.length===0)return e;let n=e.symbols.map(e=>t.reduce((t,n)=>{let r=q(n.id);return r?.part===e.component?nd(t,r.prop,n.at):t},e));return{...e,symbols:n}}function id(e,t){if(t.length===0)return e;let n=e.parts.map(e=>{let n=t.find(t=>t.id===Fu(e.component,`pcbNameAt`));return n?{...e,nameAt:n.at}:e});return{...e,parts:n}}var ad=e=>String(z(e));function od(e,t,n,r){let i=Vu(n),a=i&&Gu(i,e).find(e=>e.id===n);if(!i||!a)return;let o=$u(t,n),s=i===`pcb`?` mm`:``,c=[{label:`Part`,value:a.part},{label:`Text`,value:a.text},{label:`Offset X`,value:`${ad(a.offset.x)}${s}`},{label:`Offset Y`,value:`${ad(a.offset.y)}${s}`},{label:`Position`,value:o?`Moved (${a.prop})`:`Where the layout puts it`}];return{title:Bu[a.prop]??a.prop,rows:c,moved:o,blocker:ed(t,r,n)}}function sd(e,t,n){let r=e.soleText,i=su(t.action);if(r!==void 0&&i)return{id:r,by:ot(i,n.step,t.steps??1,n.snap!==!1)}}var cd={mode:`solid`,hidden:new Set,selected:new Set,activeLayer:`top`},ld={x:0,y:0},ud=1.5,J=.35,dd=1.5,fd=.6,pd=.12,md=1.5,hd=.7,gd=.5,_d=1e-9,vd=.25,yd=.6,bd=e=>e*Math.PI/180,xd=(e,t,n)=>e[`${t.side===`top`?`top`:`bottom`}${n}`],Sd=e=>e.autoPlaced?yd:1,Cd=e=>e.side===`top`?B.topAssembly:B.bottomAssembly;function wd(e,t,n,r){let i={...li,...r.layers},{camera:a,size:o}=n,s=1/a.scale,c=ka(s,r.ratio),l=e=>r.moving?.components.includes(e.component)?r.moving.by:ld,u=n=>{for(let r of t.parts)Od(e,l(r).x,l(r).y,0,()=>{e.globalAlpha=Sd(r),n(r)});e.globalAlpha=1};e.save(),e.setTransform(...Ed(n,r.ratio)),e.lineCap=`round`,e.lineJoin=`round`,i.keepout&&Pd(e,t,s,c);let d=r.pours??cd;$l(e,t,d,i,s),Rd(e,i,r.highlight,u,s),r.copper&&fl(e,r.copper,i,r.highlight,s),i.hole&&Bd(e,u),au(e,t.holes??[],d,i,s,c),iu(e,t,d,i,s,c),u(t=>{xd(i,t,`Silk`)&&Vd(e,t.silkscreen,t.side===`top`?B.topSilk:B.bottomSilk,Math.max(pd,c),!1)}),i.courtyard&&Hd(e,u,s,c),u(t=>{xd(i,t,`Assembly`)&&Vd(e,t.fabrication,Cd(t),c,!1)}),i.boardOutline&&Nd(e,t,()=>{e.strokeStyle=B.boardEdge,e.lineWidth=md*s,e.stroke()}),r.ratsnest!==!1&&i.ratline&&Ud(e,t,r,c),e.setTransform(r.ratio,0,0,r.ratio,0,0),Ba(e);for(let n of t.parts)xd(i,n,`Silk`)&&Gd(e,n,a,o,l(n),r.ratio);oa(e,n,r.violations??[],r.activeViolation,!0),e.restore()}function Y(e,t,n,r){for(let i of e.parts){if(r&&!r(i.component))continue;let e=i.pads.find(e=>(!n||n[pi(e)])&&qd(e,t));if(e)return e}}function Td(e){return e.parts.map(e=>{let t=Dd(e);return{name:e.component,pcbComponentId:e.component,center:{x:(t.minX+t.maxX)/2,y:(t.minY+t.maxY)/2},box:t}})}function Ed({camera:e,size:t},n){let r=e.scale*n;return[r,0,0,-r,(t.width/2-e.cx*e.scale)*n,(t.height/2+e.cy*e.scale)*n]}function Dd(e){let t=e.courtyard.map(e=>e.x),n=e.courtyard.map(e=>e.y);return{minX:Math.min(...t),minY:Math.min(...n),maxX:Math.max(...t),maxY:Math.max(...n)}}function Od(e,t,n,r,i){e.save(),e.translate(t,n),r&&e.rotate(bd(r)),i(),e.restore()}function kd(e,t){e.beginPath(),t.forEach((t,n)=>n===0?e.moveTo(t.x,t.y):e.lineTo(t.x,t.y)),e.closePath()}function Ad(e,t,n,r){e.beginPath(),e.arc(t,n,Math.max(r,0),0,Math.PI*2)}function jd(e,t,n,r){let i=Math.max(0,Math.min(r,t/2,n/2)),a=-t/2,o=-n/2;e.beginPath(),e.moveTo(a+i,o),e.arcTo(a+t,o,a+t,o+n,i),e.arcTo(a+t,o+n,a,o+n,i),e.arcTo(a,o+n,a,o,i),e.arcTo(a,o,a+t,o,i),e.closePath()}var Md=(e,t,n)=>jd(e,t,n,Math.min(t,n)/2);function Nd(e,t,n){let r=t.board?.outline;!r||r.length<3||(kd(e,r),n())}function Pd(e,t,n,r){let i=t.board?.keepouts??[];if(i.length!==0){e.strokeStyle=B.keepout,e.globalAlpha=hd;for(let t of i){e.lineWidth=r,e.setLineDash([4*n,3*n]),kd(e,t.outline),e.stroke(),e.setLineDash([]),e.save(),kd(e,t.outline),e.clip();for(let[n,r]of Fd(t.outline))Wd(e,n,r);e.restore()}e.globalAlpha=1}}function Fd(e){let t=e.map(e=>e.x),n=e.map(e=>e.y),[r,i,a,o]=[Math.min(...t),Math.max(...t),Math.min(...n),Math.max(...n)];if(![r,i,a,o].every(Number.isFinite))return[];let s=o-a,c=r-s,l=i-c,u=Math.max(gd,l/399),d=Math.floor(l/u+_d)+1;return Array.from({length:d},(e,t)=>{let n=c+t*u;return[{x:n,y:a},{x:n+s,y:o}]})}function Id(e,t){Od(e,t.x,t.y,t.rotation,()=>{t.shape===`circle`?Ad(e,0,0,t.width/2):t.shape===`oval`?Md(e,t.width,t.height):jd(e,t.width,t.height,t.shape===`roundrect`?t.cornerRadius??vd*Math.min(t.width,t.height):0)})}function Ld(e){return e.layers===`through`?B.multiLayer:e.layers===`bottom`?B.bottomCopper:B.topCopper}function Rd(e,t,n,r,i){let a=[[t.bottom,e=>e.layers===`bottom`],[t.top,e=>e.layers===`top`],[t.multiLayer,e=>e.layers===`through`]];for(let[t,o]of a)t&&r(t=>{for(let r of t.pads.filter(o)){let a=n!==void 0&&r.net!==void 0&&n.nets.includes(r.net);e.globalAlpha=(n&&!a?Qr:1)*Sd(t),e.fillStyle=Ld(r),Id(e,r),e.fill(),a&&zd(e,r,i,Sd(t))}});e.globalAlpha=1}function zd(e,t,n,r){e.globalAlpha=J*r,e.fillStyle=B.highlight,Id(e,t),e.fill(),e.globalAlpha=r,e.strokeStyle=B.highlight,e.lineWidth=dd*n,e.stroke()}function Bd(e,t){e.fillStyle=B.drill,t(t=>{for(let n of t.pads){let{drill:t}=n;t&&(t.width===t.height?Ad(e,n.x,n.y,t.width/2):Od(e,n.x,n.y,n.rotation,()=>Md(e,t.width,t.height)),e.fill())}})}function Vd(e,t,n,r,i){e.strokeStyle=n,e.lineWidth=r;for(let n of t)n.length<2||(e.beginPath(),n.forEach((t,n)=>n===0?e.moveTo(t.x,t.y):e.lineTo(t.x,t.y)),i&&e.closePath(),e.stroke())}function Hd(e,t,n,r){e.setLineDash([4*n,3*n]),t(t=>{e.globalAlpha=1,Vd(e,[t.courtyard],Cd(t),t.autoPlaced?ud*n:r,!0)}),e.setLineDash([])}function Ud(e,t,n,r){let i=n.moving,a=new Set(t.parts.filter(e=>i?.components.includes(e.component)).flatMap(e=>e.pads.map(e=>e.id))),o=(e,t)=>i&&a.has(t)?{x:e.x+i.by.x,y:e.y+i.by.y}:e;e.lineWidth=r;for(let r of t.ratsnest){let t=n.highlight?.nets.includes(r.net)??!1;e.strokeStyle=t?B.highlight:B.ratsnest,e.globalAlpha=t?1:n.highlight?fd*Qr:fd,Wd(e,o(r.a,r.from),o(r.b,r.to))}e.globalAlpha=1}function Wd(e,t,n){e.beginPath(),e.moveTo(t.x,t.y),e.lineTo(n.x,n.y),e.stroke()}function Gd(e,t,n,r,i,a){let o=Ia(Ru,n.scale,a);if(!Fa(`name`,o,o))return;let s=Xr(t),c=za(fe(n,r,{x:s.x+i.x,y:s.y+i.y}),a);e.fillStyle=t.side===`top`?B.topSilk:B.bottomSilk,e.globalAlpha=Sd(t),e.font=ni(ti.strong,o/a),e.textAlign=`center`,e.textBaseline=`middle`,e.fillText(t.component,c.x,c.y),e.globalAlpha=1}function Kd(e,t,n,r){let i;for(let a of e.parts)for(let e of a.pads){if(r&&!r[pi(e)])continue;let a=Yd(e,t);a<=n&&(!i||a<i.distance)&&(i={pad:e,distance:a})}return i?.pad}var qd=(e,t)=>Yd(e,t)<=0;function Jd(e,t){let n=bd(-e.rotation),r=t.x-e.x,i=t.y-e.y;return{x:r*Math.cos(n)-i*Math.sin(n),y:r*Math.sin(n)+i*Math.cos(n)}}function Yd(e,t){let{x:n,y:r}=Jd(e,t);return e.shape===`circle`?Math.max(0,Math.hypot(n,r)-e.width/2):e.shape===`oval`?Xd(n,r,e.width,e.height):Math.hypot(Math.max(0,Math.abs(n)-e.width/2),Math.max(0,Math.abs(r)-e.height/2))}function Xd(e,t,n,r){let i=Math.min(n,r)/2,a=Math.max(n,r)/2-i,[o,s]=n>=r?[Math.max(-a,Math.min(a,e)),0]:[0,Math.max(-a,Math.min(a,t))];return Math.max(0,Math.hypot(e-o,t-s)-i)}function Zd(e,t,n){let r=Ds(e.schematic.wires,t,n);return e.schematic.wires.find(e=>e.id===r)?.net}function Qd(e,t,n){let r=Hn(e,t,n);if(r)return e.circuit.nets.find(e=>e.pins.includes(r.pin))?.id;let i=wr(e,t)?.net??Zd(e,t,n);return i===void 0?void 0:$d(e.circuit.nets,i)}function $d(e,t){if(e.some(e=>e.id===t))return t;let n=t.startsWith(`net.`)?t.slice(4):void 0;return e.find(e=>n!==void 0&&e.names.includes(n))?.id??t}var ef=[];function tf(e,t){let n=t.flatMap(t=>e.circuit.nets.filter(e=>e.id===t)),r=n[0];if(!r)return;let i=[...new Set(n.flatMap(e=>e.pins))],a=[...new Set(n.flatMap(e=>[e.id,...e.names.map(e=>`net.${e}`)]))];return{net:r.id,pins:i,aliases:a}}function nf(e,t){let n=(e.circuit.components.find(e=>e.id===t)?.pins??[]).flatMap(t=>e.circuit.nets.filter(e=>e.pins.includes(t.id)).map(e=>e.id));return[...new Set(n)]}function rf(e,t){if(e.length===0)return{message:`Point at a net and press H.`};let n=[...new Set(e.flatMap(t))];return n.length>0?{nets:n}:{message:`${et(e)} ${e.length===1?`is`:`are`} on no net.`}}function af(e,t,n,r=()=>void 0){let i=[...new Set([...e.wires.flatMap(e=>t(e)??[]),...e.labels.flatMap(e=>r(e)??[])])],a=rf(e.names,n);return`nets`in a?{nets:[...new Set([...i,...a.nets])]}:i.length>0?{nets:i}:a}function of(e,t,n){if(n.circuit.nets.some(t=>t.id===e))return e;let r=t?.circuit.nets.find(t=>t.id===e)?.pins[0];return r!==void 0&&n.circuit.nets.find(e=>e.pins.includes(r))?.id||void 0}function sf(e,t,n){let r=[...new Set(e.flatMap(e=>of(e,t,n)??[]))];return r.length===e.length&&r.every((t,n)=>t===e[n])?e:r.length===0?ef:r}function cf(e,t,n){return Y(e,t,n)?.net??void 0}var lf=e=>e.startsWith(`drawing:`)||e.includes(`~`),uf=e=>JSON.stringify({...e,source:void 0}),df=(e,t)=>e.filter(e=>e.kind===t).length,ff=(e,t)=>t.some(t=>t.id.startsWith(`${e}~`));function pf(e,t,n,r){return!lf(t.id)&&!ff(t.id,n)&&!ff(t.id,r)?!0:e.kind===t.kind?df(n,t.kind)===df(r,t.kind)||uf(e)===uf(t):!1}function mf(e,t){let n=new Map((e??[]).map(e=>[e.id,e]));return t.flatMap(r=>{let i=n.get(r.id);return!e||!i||pf(i,r,e,t)?[r.id]:[]})}function hf(e,t,n){let r=e=>n.some(t=>t.id===e.to);return{selection:t.filter(r).reduce((e,{from:t,to:n})=>e.hasDrawing(t)?e.withoutDrawings([t]).addDrawings([n]):e,e),waiting:t.filter(e=>!r(e))}}function gf(e,t,n){return e.drawingCount===0?e:e.keepDrawings(mf(t,n))}var _f=/^[ADPF]?GND\w*$|^VSS\w*$/i,vf=/^(VCC|VDD|VBUS|VIN|V\d|\+)/i,yf=new Intl.Collator(`en`,{numeric:!0});function bf(e){return _f.test(e)?`ground`:vf.test(e)?`power`:void 0}function xf(e){for(let t of e){let e=bf(t);if(e)return e}}var Sf=e=>e.find(e=>bf(e))??e[0];function Cf(e){return Sf(e.names)??`(unnamed) ${e.pins[0]??e.id}`}function wf(e){return e.circuit.nets.map(e=>{let t=Sf(e.names),n=xf(e.names);return{id:e.id,label:Cf(e),pins:e.pins.length,named:t!==void 0,...n?{badge:n}:{}}}).sort((e,t)=>Number(t.named)-Number(e.named)||yf.compare(e.label,t.label))}function Tf(e,t,n,r){let i=new Map,a=[],o=[];for(let s of t){let t=Dr(e,s);t?.wire!==void 0&&(r.includes(t.wire)||n(t.part))?i.set(t.wire,s):t&&t.wire===void 0&&n(t.part)?a.push(s):o.push(s)}return{riding:i,onPins:a,alone:o}}var Ef=(e,t)=>e.schematic.labels.find(e=>e.id===t);function Df(e,t){let n=e?kr(e):`the label`;return`${n.charAt(0).toUpperCase()}${n.slice(1)}: ${t}`}function Of(e,t,n,r,i,a){let o=Ef(e,n),s={edits:[],shown:[],names:[],notes:[]};if(!o)return s;let c={x:z(o.at.x+r.x),y:z(o.at.y+r.y)},l=Br(e,t,n,c,i);if(!Array.isArray(l))return a.includes(l.blocked)?s:{...s,notes:[Df(o,l.blocked)]};let u=l.length>0?Fr(e,n,c):void 0;return u?{edits:l,shown:[{id:n,...u}],names:[kr(o)],notes:[]}:s}function kf(e,t,n,r,i,a){let o=n.map(n=>Of(e,t,n,r,i,a));return{edits:o.flatMap(e=>e.edits),shown:o.flatMap(e=>e.shown),names:o.flatMap(e=>e.names),notes:o.flatMap(e=>e.notes)}}function Af(e,t){return t.flatMap(t=>{let n=Ef(e,t);return n?[kr(n)]:[]})}var jf=e=>e.length>1?[`${e.length} labels`]:[...e];function Mf(e,t,n,r){if(r.has(e))return e;let i=t&&Or(t,e);return i===void 0?void 0:n.schematic.labels.find(e=>Or(n,e.id)===i)?.id}function Nf(e,t,n){if(e.labelCount===0)return e;let r=new Set(n.schematic.labels.map(e=>e.id)),i=e.labels.flatMap(e=>Mf(e,t,n,r)??[]);return e.all(e.names,e.wires,i,e.drawings)}var Pf=(e,t)=>e.slice(`label:${t}:`.length);function Ff(e,t,n){let r=e.schematic.labels.find(e=>e.id===t),i=Dr(e,t);return i?.wire===void 0?i&&n.has(i.part)?{kind:`part`,label:t}:r?{kind:`skipped`,reason:Df(r,`Studio places it on ${Pf(t,r.net)} for its net; delete that pin's part or wire instead`)}:{kind:`gone`}:{kind:`wire`,label:t,wire:i.wire}}function If(e,t,n){let r=t.map(t=>Ff(e,t,n));return{withWires:r.flatMap(e=>e.kind===`wire`?[{label:e.label,wire:e.wire}]:[]),withParts:r.flatMap(e=>e.kind===`part`?[e.label]:[]),skipped:r.flatMap(e=>e.kind===`skipped`?[e.reason]:[])}}function Lf(e,t){let n=e.schematic.labels.find(e=>e.id===t);if(!n)return;let r=$d(e.circuit.nets,n.net),i=e.circuit.nets.find(e=>e.id===r),a=Dr(e,t)?.wire===void 0?`At a pin`:`Hand-drawn`;return{net:r,rows:[{label:`Net`,value:i?Cf(i):r.replace(/^net\./,``)},{label:`Text`,value:n.text},{label:`Kind`,value:a}]}}var Rf=e=>`${e.x},${e.y}`;function zf(e){let t=new Map(e.symbols.flatMap(e=>Object.entries(e.pinEnds).map(([e,t])=>[Rf(t),e])));return e.wires.map(e=>{let[n,r]=[e.points[0],e.points[e.points.length-1]],i=n&&r?[t.get(Rf(n)),t.get(Rf(r))]:[],a=i.length===2&&i.every(e=>e!==void 0);return e.connection===void 0&&a?{...e,ends:i}:e})}var Bf=(e,t)=>e.x===t.x&&e.y===t.y;function Vf(e,t){if(e.ends&&t.ends)return e.ends.length===t.ends.length&&e.ends.every(e=>t.ends?.includes(e));let[n,r,i,a]=[e.points[0],e.points[e.points.length-1],t.points[0],t.points[t.points.length-1]];return!n||!r||!i||!a?!1:Bf(n,i)&&Bf(r,a)||Bf(n,a)&&Bf(r,i)}function Hf(e,t,n){let r=n.find(t=>t.id===e),i=t?.find(t=>t.id===e);return!r||r.connection===void 0&&i!==void 0&&!Vf(i,r)}function Uf(e,t,n){return e.withoutWires(e.wires.filter(e=>Hf(e,t,n)))}function Wf(e,t){let n=t.parts?e.keep(t.parts):e,r=t.view===`schematic`,i=e=>r?e??[]:[],a=r?[]:t.copper??[],o=r?[]:t.board??[];return n.keepWires(i(t.wires)).keepLabels(i(t.labels)).keepDrawings(i(t.drawings)).keepCopper(a).keepTexts(t.texts??[]).keepBoard(o)}var Gf=[{id:`library`,label:`Library`},{id:`log`,label:`Log`},{id:`drc`,label:`DRC`},{id:`find`,label:`Find Results`}],Kf=`bottom-panel`,qf=e=>`bottom-tab-${e}`,Jf={open:!1,tab:`drc`};function Yf(e,t){return e.open&&e.tab===t?{...e,open:!1}:{open:!0,tab:t}}function Xf(e){return{...e,open:!e.open}}function Zf(e,t){return{open:!0,tab:t}}function Qf(e){return e.detail>0}var $f=`button, input[type='checkbox']`;function ep(e){e.target instanceof HTMLElement&&e.target.closest($f)?.blur()}function tp(e,t,n){return t>0||e===`checkbox`&&!n}function np(e,t,n){return e===null||e===t||(n?.contains(e)??!1)}function rp(e){let t=e.target instanceof HTMLElement?e.target.closest($f):null;t&&tp(t instanceof HTMLInputElement?`checkbox`:`button`,e.detail,t.matches(`:focus-visible`))&&t.blur()}var ip=new Set([`ArrowLeft`,`ArrowUp`]),ap=new Set([`ArrowRight`,`ArrowDown`]);function op(e,t,n){if(e.length===0)return null;if(n===`Home`)return e[0]??null;if(n===`End`)return e[e.length-1]??null;let r=ip.has(n)?-1:+!!ap.has(n);return r===0?null:e[(Math.max(0,e.indexOf(t))+r+e.length)%e.length]??null}function sp({ids:e,current:t,onSelect:n,onPointerClick:r}){return{onKeyDown:r=>{let i=op(e,t,r.key);i!==null&&(r.preventDefault(),r.stopPropagation(),n(i),r.currentTarget.querySelector(`[data-tab="${i}"]`)?.focus())},tab:e=>({"data-tab":e,tabIndex:e===t?0:-1,onClick:t=>{if(!Qf(t))return n(e);ep(t),(r??n)(e)}})}}var cp=e((e=>{var t=Symbol.for(`react.transitional.element`),n=Symbol.for(`react.fragment`);function r(e,n,r){var i=null;if(r!==void 0&&(i=``+r),n.key!==void 0&&(i=``+n.key),`key`in n)for(var a in r={},n)a!==`key`&&(r[a]=n[a]);else r=n;return n=r.ref,{$$typeof:t,type:e,key:i,ref:n===void 0?null:n,props:r}}e.Fragment=n,e.jsx=r,e.jsxs=r})),lp=e(((e,t)=>{t.exports=cp()})),X=lp(),up=Gf.map(e=>e.id);function dp({state:e,onClick:t,onOpen:n}){let r=sp({ids:up,current:e.tab,onSelect:n,onPointerClick:t});return(0,X.jsx)(`nav`,{className:`bottom-strip hairline-t`,role:`tablist`,"aria-label":`Bottom panel`,onKeyDown:r.onKeyDown,children:Gf.map(t=>{let n=e.open&&e.tab===t.id;return(0,X.jsx)(`button`,{role:`tab`,id:qf(t.id),"aria-controls":Kf,className:`bottom-tab${n?` on`:``}`,"aria-selected":n,...r.tab(t.id),children:(0,X.jsx)(`span`,{className:`bottom-tab-label`,children:t.label})},t.id)})})}function fp(e){return{"--dpr":String(Number.isFinite(e)&&e>0?e:1)}}function pp(e){let t=e.document.documentElement,n,r=()=>{for(let[n,r]of Object.entries(fp(e.devicePixelRatio)))t.style.setProperty(n,r);n?.removeEventListener(`change`,r),n=e.matchMedia(`(resolution: ${e.devicePixelRatio}dppx)`),n.addEventListener(`change`,r)};return r(),e.addEventListener(`resize`,r),()=>{e.removeEventListener(`resize`,r),n?.removeEventListener(`change`,r)}}var Z=(e,t)=>t?{tag:`path`,d:e,dash:t}:{tag:`path`,d:e},mp=(e,t,n,r)=>r?{tag:`circle`,cx:e,cy:t,r:n,fill:r}:{tag:`circle`,cx:e,cy:t,r:n},hp=(e,t,n,r,i=1,a)=>a?{tag:`rect`,x:e,y:t,width:n,height:r,rx:i,fill:a}:{tag:`rect`,x:e,y:t,width:n,height:r,rx:i},gp=Z(`M2.5 5.5v-3h3M10.5 2.5h3v3M13.5 10.5v3h-3M5.5 13.5h-3v-3`),_p=[hp(3,7,10,7,1.5),Z(`M8 10v1.5`)],vp=[4,8,12].flatMap(e=>[4,8,12].map(t=>mp(t,e,1,!0))),yp={lock:[..._p,Z(`M5.5 7V5a2.5 2.5 0 0 1 5 0v2`)],unlock:[..._p,Z(`M5.5 7V5a2.5 2.5 0 0 1 5 0`)],padlock:[hp(2.5,7,11,7.5,1.5),Z(`M5 7V5a3 3 0 0 1 6 0v2`),Z(`M8 10v2`)],padlockOpen:[hp(2.5,7,11,7.5,1.5),Z(`M11 7V4a3 3 0 0 0-6 0v.5`),Z(`M8 10v2`)],trash:[Z(`M2.5 4.5h11M6 4.5V2.5h4v2`),Z(`M4 4.5l.5 9h7l.5-9`),Z(`M6.5 7v4M9.5 7v4`)],close:[Z(`M4 4l8 8M12 4l-8 8`)],chevron:[Z(`M6 4l4 4-4 4`)],eye:[Z(`M1.5 8S4 3.5 8 3.5 14.5 8 14.5 8 12 12.5 8 12.5 1.5 8 1.5 8z`),mp(8,8,2)],eyeOff:[Z(`M1.5 8S4 3.5 8 3.5 14.5 8 14.5 8 12 12.5 8 12.5 1.5 8 1.5 8z`),mp(8,8,2),Z(`M2.5 2.5l11 11`)],undo:[Z(`M5.5 3 3 5.5 5.5 8`),Z(`M3 5.5h6.5a3.5 3.5 0 0 1 0 7h-3`)],redo:[Z(`M10.5 3 13 5.5 10.5 8`),Z(`M13 5.5H6.5a3.5 3.5 0 0 0 0 7h3`)],zoomIn:[mp(7,7,4.5),Z(`M10.5 10.5 14 14M7 5v4M5 7h4`)],zoomOut:[mp(7,7,4.5),Z(`M10.5 10.5 14 14M5 7h4`)],fit:[gp,hp(6,6,4,4,.5)],fitSelection:[gp,hp(5.5,5.5,5,5,1,!0)],fitArea:[hp(2.5,2.5,8,8,1),Z(`M7 7l6.5 6.5M13.5 9.5v4h-4`)].map(e=>e.tag===`rect`?{...e,dash:`2 2`}:e),grid:vp,snap:[Z(`M3.5 2.5V8a4.5 4.5 0 0 0 9 0V2.5h-3V8a1.5 1.5 0 0 1-3 0V2.5z`),Z(`M3.5 5h3M9.5 5h3`)],component:[hp(4.5,3,7,10,1),Z(`M2 6h2.5M2 10h2.5M11.5 6H14M11.5 10H14`)],wire:[mp(3.5,12.5,1.5),mp(12.5,3.5,1.5),Z(`M5 12.5h3.5v-9H11`)],netLabel:[Z(`M1.5 8h2`),Z(`M5.5 4.5h8v7h-8L3.5 8z`),Z(`M8 8h3`)],bus:[Z(`M2 10.5h12`,void 0),Z(`M5.5 10.5l2-4.5M9.5 10.5l2-4.5`)],polyline:[Z(`M2 13l3.5-7 4 4 4.5-7`)],arc:[Z(`M3 12a5 5 0 0 1 10 0`)],circle:[mp(8,8,5.5)],rectangle:[hp(2.5,4.5,11,7,0)],text:[Z(`M3.5 4.5V3h9v1.5M8 3v10M6 13h4`)],ground:[Z(`M8 2.5v6M3 8.5h10M5 11h6M7 13.5h2`)],power:[Z(`M8 14V5.5M3.5 5.5h9`),Z(`M3.5 5.5 8 2l4.5 3.5`)],noConnect:[Z(`M2 8h5`),Z(`M9 5.5l5 5M14 5.5l-5 5`)],via:[mp(8,8,5.5),mp(8,8,2)],boardOutline:[Z(`M2.5 3.5h8l3 3v6h-11z`)],copperArea:[hp(2.5,2.5,11,11,1),Z(`M5.5 10.5l5-5M5.5 7.5l2-2M8.5 10.5l2-2`)],singleRouting:[mp(3.5,12.5,1.5),Z(`M5 12.5h3.5L12 9V3.5`)],gerber:[Z(`M8 2.5 2.5 5 8 7.5 13.5 5z`),Z(`M2.5 8 8 10.5 13.5 8`),Z(`M2.5 11 8 13.5 13.5 11`)],rotate:[Z(`M3 8a5 5 0 1 0 5-5`),Z(`M9.5 1.5 8 3l1.5 1.5`)],rotateRight:[Z(`M13 8a5 5 0 1 1-5-5`),Z(`M6.5 1.5 8 3 6.5 4.5`)],alignLeft:[Z(`M2.5 2v12`),hp(5,3.5,8.5,3.5,1),hp(5,9,5,3.5,1)],distributeH:[Z(`M2.5 2v12M13.5 2v12`),hp(6,4,4,8,1)],check:[Z(`M8 1.5 3 3.5v4c0 3 2 5.5 5 6.5 3-1 5-3.5 5-6.5v-4z`),Z(`M5.5 8l2 2 3-3.5`)]},bp={width:16,height:16,viewBox:`0 0 16 16`,fill:`none`,stroke:`currentColor`,strokeWidth:1.5,strokeLinecap:`round`,strokeLinejoin:`round`,shapeRendering:`geometricPrecision`,"aria-hidden":!0};function xp(e,t){let{tag:n,fill:r,dash:i,...a}=e;return{key:t,...a,...r?{fill:`currentColor`,stroke:`none`}:{},...i?{strokeDasharray:i}:{}}}function Sp(e,t={}){let n=yp[e];return(0,l.createElement)(`svg`,{...bp,...t},...n.map((e,t)=>(0,l.createElement)(e.tag,xp(e,t))))}var Cp=e=>Sp(`lock`,e),wp=e=>Sp(`unlock`,e),Tp=e=>Sp(`padlock`,e),Ep=e=>Sp(`padlockOpen`,e),Dp=e=>Sp(`rotate`,e),Op=e=>Sp(`trash`,e),kp=e=>Sp(`undo`,e),Ap=e=>Sp(`close`,e),jp=e=>Sp(`chevron`,e),Mp=({off:e,...t})=>Sp(e?`eyeOff`:`eye`,t),Q=e=>t=>Sp(e,t),Np={undo:Q(`undo`),redo:Q(`redo`),zoomIn:Q(`zoomIn`),zoomOut:Q(`zoomOut`),fit:Q(`fit`),fitSelection:Q(`fitSelection`),fitArea:Q(`fitArea`),component:Q(`component`),wire:Q(`wire`),netLabel:Q(`netLabel`),ground:Q(`ground`),power:Q(`power`),rotate:Q(`rotate`),rotateRight:Q(`rotateRight`),snap:Q(`snap`),check:Q(`check`),grid:Q(`grid`),alignLeft:Q(`alignLeft`),distributeH:Q(`distributeH`),polyline:Q(`polyline`),arc:Q(`arc`),circle:Q(`circle`),rectangle:Q(`rectangle`),text:Q(`text`),bus:Q(`bus`),noConnect:Q(`noConnect`),via:Q(`via`),boardOutline:Q(`boardOutline`),copperArea:Q(`copperArea`),singleRouting:Q(`singleRouting`),gerber:Q(`gerber`)};function Pp(e){return e===`Escape`?`close`:e===`Tab`?`trap`:`hold`}function Fp(e,t,n){return t<=0?-1:e<0||e>=t?n?t-1:0:(e+(n?-1:1)+t)%t}function Ip(){let e=[];return{hold(t){return e=[...e,t],()=>{e=e.filter(e=>e!==t)}},held(){return e.length>0},dispatch(t){let n=e.at(-1);return n?(n(t),t.stopImmediatePropagation(),!0):!1}}}var Lp=Ip();function Rp(e){let t=e=>void Lp.dispatch(e);return e.addEventListener(`keydown`,t,!0),()=>e.removeEventListener(`keydown`,t,!0)}function zp(e,t){let n=(0,l.useRef)(t);(0,l.useLayoutEffect)(()=>{n.current=t}),(0,l.useEffect)(()=>e?Lp.hold(e=>n.current(e)):void 0,[e])}var Bp=[`fitSelection`,`rotateRight`,`selectInstance`,`replicateLayout`,`makeSheet`,`autorouteSelection`,`autoplaceSelection`,`autoplaceInstance`],Vp=`Select a part first`,Hp=e=>Bp.includes(e);function Up(e,t){return v(e)?b(e,t):Hp(e)&&t<1?Vp:null}var Wp=`Comes with hand routing (engine stage 4)`,$=(e,t,n)=>n?{label:e,command:t,shortcut:n}:{label:e,command:t},Gp=[{title:`File`,entries:[$(`Open circuit file`,`openFile`,`Ctrl+O`),$(`New circuit…`,`newCircuit`),`separator`,$(`Export BOM`,`exportBom`),$(`Export package`,`exportPackage`),$(`Export Gerber`,`exportFabrication`),$(`Print…`,`print`)]},{title:`Edit`,entries:[$(`Undo`,`undo`,`Ctrl+Z`),$(`Redo`,`redo`,`Ctrl+Y`),`separator`,$(`Copy`,`copy`,`Ctrl+C`),$(`Paste`,`paste`,`Ctrl+V`),$(`Delete`,`delete`,`Delete`),`separator`,$(`Select all`,`selectAll`,`Ctrl+A`),$(`Select the instance`,`selectInstance`),{label:`Make sub-sheet…`,command:`makeSheet`,only:`schematic`},$(`Find`,`find`,`Ctrl+F`),$(`Find similar objects`,`findSimilar`,`Ctrl+Shift+F`),`separator`,$(`Fillet tracks`,`filletTracks`,`U`),$(`Straighten tracks`,`straightenTracks`,`Shift+U`)]},{title:`View`,entries:[$(`Fit all`,`fit`,`K`),$(`Fit selection`,`fitSelection`),$(`Fit area`,`fitArea`),$(`Zoom in`,`zoomIn`),$(`Zoom out`,`zoomOut`),`separator`,{...$(`Unit`,`toggleUnit`,`Q`),only:`pcb`},$(`Grid style`,`gridStyle`),{...$(`Snap`,`snap`,`Alt+S`),toggle:`snap`},{...$(`Hover labels`,`hoverLabels`),toggle:`hoverLabels`},{...$(`Pour fill: Solid`,`pourSolid`),toggle:`pourSolid`},{...$(`Pour fill: Hatched`,`pourHatched`),toggle:`pourHatched`},{...$(`Pour fill: Outline only`,`pourOutline`),toggle:`pourOutline`},`separator`,$(`Left panel`,`toggleLeftPanel`,`[`),$(`Right panel`,`toggleRightPanel`,`]`),$(`Bottom panel`,`toggleBottomPanel`,`\\`),`separator`,{...$(`Theme: Light`,`themeLight`),toggle:`themeLight`},{...$(`Theme: Dark`,`themeDark`),toggle:`themeDark`}]},{title:`Place`,entries:[$(`Component`,`placeComponent`,`Shift+F`),$(`Wire`,`wire`,`Alt+W`),$(`Net label`,`netLabel`,`Alt+N`),$(`Ground flag`,`groundFlag`),$(`Power flag`,`powerFlag`),`separator`,$(`Note box`,`noteBox`),`separator`,$(`Bus`,`drawBus`,`Alt+B`),{label:`No connect flag`,command:`noConnect`,only:`schematic`},{label:`Junction`,command:`junction`,shortcut:`Alt+J`,only:`schematic`},`separator`,$(`Copper pour`,`placePour`),$(`Copper pour: Whole board`,`placePourBoard`),$(`Hole`,`placeHole`),`separator`,{label:`Autoplace`,command:`autoplace`,only:`pcb`},{label:`Autoplace selection`,command:`autoplaceSelection`,only:`pcb`},{label:`Autoplace instance`,command:`autoplaceInstance`,only:`pcb`},`separator`,$(`Polyline`,`drawPolyline`,`Alt+L`),$(`Arc`,`drawArc`,`Alt+A`),$(`Circle`,`drawCircle`,`Alt+C`),$(`Rectangle`,`drawRectangle`,`Alt+R`),$(`Text`,`drawText`,`Alt+T`)]},{title:`Design`,entries:[$(`Check DRC`,`checkDrc`),$(`Design rules`,`designRules`),`separator`,$(`Highlight net`,`highlight`,`H`),$(`Clear highlight`,`clearHighlight`,`Shift+H`),`separator`,{label:`Add page`,command:`addPage`,only:`schematic`},{label:`Rename page`,command:`renamePage`,only:`schematic`},{label:`Delete page`,command:`deletePage`,only:`schematic`},`separator`,{label:`Replicate layout`,command:`replicateLayout`,only:`pcb`},$(`Annotate designators`,`annotate`),{label:`Placement transfer`,command:`placementTransfer`,shortcut:`Ctrl+Shift+X`,only:`pcb`}]},{title:`Route`,entries:[$(`Single routing`,`singleRouting`,`Alt+W`),$(`Via`,`placeVia`,`Alt+V`),{label:`Routing corner`,command:`routingCorner`,shortcut:`L`,only:`pcb`},`separator`,$(`Autoroute`,`autoroute`),$(`Autoroute selection`,`autorouteSelection`),$(`Autoroute net`,`autorouteNet`),$(`Unroute`,`unroute`)]},{title:`Layout`,entries:[$(`Rotate`,`rotate`,`Space`),$(`Rotate right`,`rotateRight`),{label:`Flip`,command:`flip`,shortcut:`X`,only:`pcb`},`separator`,$(`Lock`,`lock`),$(`Unlock`,`unlock`),`separator`,$(`Align left`,`alignLeft`,`Ctrl+Shift+L`),$(`Align right`,`alignRight`),$(`Align top`,`alignTop`),$(`Align bottom`,`alignBottom`),$(`Align horizontal centres`,`alignHCentres`),$(`Align vertical centres`,`alignVCentres`),`separator`,$(`Distribute horizontally`,`distributeH`,`Ctrl+Shift+H`),$(`Distribute vertically`,`distributeV`),`separator`,{label:`Fit board`,command:`fitBoard`,only:`pcb`},`separator`,{label:`Tidy sheet`,command:`tidySheet`,only:`schematic`}]},{title:`Tools`,entries:[$(`History`,`history`),$(`Footprint manager…`,`footprintManager`)]},{title:`Export`,entries:[$(`BOM`,`exportBom`),$(`Package`,`exportPackage`),$(`Fabrication files (JLCPCB)`,`exportFabrication`),$(`Gerber`,`exportFabrication`),$(`Pick and place (CPL)`,`exportFabrication`),$(`PDF…`,`exportPdf`)]},{title:`Settings`,entries:[$(`System…`,`systemSettings`),$(`Hotkeys`,`keys`)]},{title:`Help`,entries:[$(`Keys`,`keys`),$(`About`,`about`)]}];Gp.map(e=>e.title);var Kp={pcb:`PCB only`,schematic:`Schematic only`};function qp(e,t,n,r={}){if(!e.command)return e.pending?{enabled:!1,reason:e.pending}:{enabled:!1};if(e.only&&e.only!==t)return{enabled:!1,reason:Kp[e.only]};let i=r[e.command];if(i!==void 0)return{enabled:!1,reason:i};let a=n===void 0?null:Up(e.command,n);return a?{enabled:!1,reason:a}:{enabled:!0}}function Jp(e){return e.entries.filter(e=>e!==`separator`)}var Yp=[{keys:`Ctrl+Shift+Z`,label:`Redo`},{keys:`W`,label:`Wire (schematic), Single routing (PCB)`},{keys:`V (PCB)`,label:`Change the active layer; while routing, a via at the last corner`},{keys:`Space (while routing)`,label:`Step the corner mode: 45°, 45° reversed, 90°, arc`},{keys:`Enter (while routing)`,label:`End the track open at its last corner (or click that corner again)`},{keys:`R`,label:`Rotate`},{keys:`Space (while drawing a wire)`,label:`Flip the bend of the leg to the pointer`},{keys:`Shift (while drawing a polyline)`,label:`Keep the leg horizontal or vertical; Space flips its bend`},{keys:`Enter (while drawing a polyline)`,label:`Finish the polyline (or double click)`},{keys:`Backspace (while drawing)`,label:`Remove the last corner`},{keys:`F`,label:`Fit all`},{keys:`Esc`,label:`Clear the selection, put tools away`},{keys:`Arrow keys`,label:`Move the selection one grid step (a tenth with Snap off)`},{keys:`Shift+Arrow keys`,label:`Move the selection ten grid steps (ten tenths with Snap off)`},{keys:`Shift+F10`,label:`Open the context menu (also the menu key)`}];function Xp(){let e=new Set,t=[];for(let n of Gp.flatMap(Jp))n.command&&n.shortcut&&!e.has(n.shortcut)&&(e.add(n.shortcut),t.push({keys:n.shortcut,label:n.label}));return[...t,...Yp.filter(t=>!e.has(t.keys))]}function Zp(e,t){switch(t.type){case`click`:return{open:e.open===t.title?null:t.title};case`hover`:return e.open===null||e.open===t.title?e:{open:t.title};case`set`:return e.open===t.title?e:{open:t.title};default:return e.open===null?e:{open:null}}}function Qp(e,t,n={}){return Gp.map(r=>r.entries.map(r=>r===`separator`?`separator`:qp(r,e,t,n).enabled?`item`:`disabled`))}var $p=`Type the LCSC part number, e.g. C7950. The part is fetched from EasyEDA, so this needs the internet.`;function em(e,t,n){let r=e.trim().toUpperCase();if(r===``)return{message:$p};if(!/^C[1-9][0-9]{0,9}$/.test(r))return{message:`"${e.trim()}" is not an LCSC part number: it looks like C7950 (C and digits).`};let i=t.trim();return{lcsc:r,replace:n,...i?{id:i}:{}}}function tm(e){let t=(e,t)=>`${e} ${t}${e===1?``:`s`}`;return`Imported ${e.lcsc} as ${e.id}: ${e.title}, ${t(e.pins,`pin`)}, ${t(e.pads,`pad`)}.`}function nm(e){return`Not verified: check every pin and pad in parts/${e.id}/verification.md against the datasheet before verifying it.`}function rm(e){if(!e)return;let t=/^lcsc (C\d+), imported (\S+)$/.exec(e);if(t)return`Imported from LCSC ${t[1]} on ${t[2]}`;let n=/^written (\S+)$/.exec(e);return n?`Written on ${n[1]}`:e}function im({result:e}){return(0,X.jsxs)(`div`,{className:`import-result`,role:`status`,children:[(0,X.jsx)(`p`,{children:(0,X.jsx)(`strong`,{children:tm(e)})}),(0,X.jsx)(`p`,{children:nm(e)}),e.notes.length>0&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`h3`,{children:`Check these too`}),(0,X.jsx)(`ul`,{children:e.notes.map(e=>(0,X.jsx)(`li`,{children:e},e))})]}),(0,X.jsx)(`h3`,{children:`Written`}),(0,X.jsx)(`ul`,{children:e.files.map(e=>(0,X.jsx)(`li`,{children:(0,X.jsx)(`code`,{children:e})},e))}),(0,X.jsx)(`p`,{children:e.terms})]})}function am({panel:e,onClose:t}){let[n,r]=(0,l.useState)(``),[i,a]=(0,l.useState)(``),[o,s]=(0,l.useState)(!1),[c,u]=(0,l.useState)(!1),[d,f]=(0,l.useState)(),[p,m]=(0,l.useState)(),h=(0,l.useId)(),g=async r=>{if(r.preventDefault(),c)return;if(p)return t();let a=em(n,i,o);if(`message`in a)return f(a.message);u(!0),f(void 0);try{m(await e.import(a))}catch(e){f(e.message)}finally{u(!1)}};return(0,X.jsxs)(`form`,{className:`rules-form import-part-form`,onSubmit:e=>void g(e),children:[(0,X.jsx)(`label`,{htmlFor:h,children:`LCSC part number`}),(0,X.jsx)(`input`,{id:h,value:n,placeholder:`C7950`,disabled:c||p!==void 0,onChange:e=>r(e.target.value),"aria-describedby":`${h}-note`,"aria-invalid":d!==void 0}),(0,X.jsx)(`label`,{htmlFor:`${h}-id`,children:`Part id`}),(0,X.jsx)(`input`,{id:`${h}-id`,value:i,placeholder:`the MPN`,disabled:c||p!==void 0,onChange:e=>a(e.target.value)}),(0,X.jsxs)(`label`,{className:`make-sheet-rename`,children:[(0,X.jsx)(`input`,{type:`checkbox`,checked:o,disabled:c||p!==void 0,onChange:e=>s(e.target.checked)}),`Replace a part with this id that is not verified`]}),(0,X.jsx)(`p`,{id:`${h}-note`,role:d?`alert`:void 0,children:c?`Fetching from EasyEDA…`:d??(p?``:`Type the LCSC part number, e.g. C7950. The part is fetched from EasyEDA, so this needs the internet.`)}),p&&(0,X.jsx)(im,{result:p}),(0,X.jsx)(`button`,{type:`submit`,disabled:c,children:p?`Close`:`Import`})]})}var om=/(?:^|[\s>])\.([A-Za-z_][\w-]*)/,sm=/^([A-Za-z_][\w-]*)\.[\w-]+$/;function cm(e){let t=new Set;for(let n of e.split(`,`)){let e=n.trim();if(e.startsWith(`net.`))continue;let r=sm.exec(e)??om.exec(e);r?.[1]&&t.add(r[1])}return[...t]}function lm(e,t){if(t.includes(`/`))return;let n=e.parts.find(e=>e.name===t)?.tag,r=e.imports.find(e=>e.local===n)?.source;if(r===void 0||!/\.sheet(\.tsx)?$/.test(r))return;let i=r.replace(/^\.\//,``);return i.endsWith(`.tsx`)?i:`${i}.tsx`}var um=class extends Error{code;constructor(e,t){super(t),this.code=e,this.name=`EditError`}};function dm(e,t){if(t.length===0)return`Select the parts to move into the sub-sheet first.`;let n=[];for(let r of new Set(t)){let t=e.parts.find(e=>e.name===r);if(!t)return`There is no part ${r} in the circuit.`;if(lm(e,r)!==void 0)return`${r} is a sub-sheet instance; a sub-sheet is made of parts only, so leave instances out of the selection.`;if(!t.editable)return`${r} cannot be moved (${t.readonlyReason??`read-only`}).`;if(t.parent===`group`)return`${r} is inside a <group>, whose offset its position adds to; ungroup it first.`;n.push(t)}if(new Set(n.map(e=>e.page??``)).size>1)return`The selected parts are on different pages; select parts of one page.`}function fm(e,t){if(!e)return{message:`Wait for the circuit to load, then try again.`};let n=dm(e,t);return n===void 0?{parts:[...new Set(t)]}:{message:n}}function pm(e){return e.ports.map(t=>({port:t.name,joins:`${t.bus?`bus`:`net`} ${e.connections[t.name]??t.name}`}))}function mm(e){return e.mapping.map(e=>({now:e.from,sheet:e.to,board:e.flat}))}var hm=e=>`${e.trim()||`PowerStage`}1`,gm=`Type the sheet's name, e.g. PowerStage: a capital letter, then letters, digits and _.`;function _m(e,t){return`Made ${e.file}: ${e.instance} (base ${e.base}) replaces ${t} part${t===1?``:`s`}`}var vm=200;function ym(e,t){let{name:n,instance:r,rename:i}=t,[a,o]=(0,l.useState)({problem:gm});return(0,l.useEffect)(()=>{if(n.trim()===``){o({problem:gm});return}let t=!0,a=window.setTimeout(()=>{e.preview({name:n.trim(),rename:i,...r?{instance:r}:{}}).then(e=>t&&o({preview:e}),e=>t&&o({problem:e.message}))},vm);return()=>{t=!1,window.clearTimeout(a)}},[e,n,r,i]),a}function bm({preview:e}){let t=pm(e);return t.length===0?(0,X.jsx)(`p`,{children:`No net crosses the selection, so the sheet has no ports.`}):(0,X.jsx)(`table`,{"aria-label":`Ports`,children:(0,X.jsx)(`tbody`,{children:t.map(e=>(0,X.jsxs)(`tr`,{children:[(0,X.jsx)(`td`,{children:e.port}),(0,X.jsx)(`td`,{children:e.joins})]},e.port))})})}function xm({preview:e}){return(0,X.jsxs)(`table`,{"aria-label":`Designators`,children:[(0,X.jsx)(`thead`,{children:(0,X.jsxs)(`tr`,{children:[(0,X.jsx)(`td`,{children:`Now`}),(0,X.jsx)(`td`,{children:`In the sheet`}),(0,X.jsx)(`td`,{children:`On the board`})]})}),(0,X.jsx)(`tbody`,{children:mm(e).map(e=>(0,X.jsxs)(`tr`,{children:[(0,X.jsx)(`td`,{children:e.now}),(0,X.jsx)(`td`,{children:e.sheet}),(0,X.jsx)(`td`,{children:e.board})]},e.now))})]})}function Sm({panel:e,onClose:t}){let[n,r]=(0,l.useState)(``),[i,a]=(0,l.useState)(``),[o,s]=(0,l.useState)(!1),c=i.trim(),u={name:n.trim(),rename:o,...c?{instance:c}:{}},{preview:d,problem:f}=ym(e,u),p=(0,l.useId)(),m=async n=>{n.preventDefault(),d&&await e.make(u)&&t()};return(0,X.jsxs)(`form`,{className:`rules-form make-sheet-form`,onSubmit:e=>void m(e),children:[(0,X.jsx)(`label`,{htmlFor:p,children:`Sheet name`}),(0,X.jsx)(`input`,{id:p,value:n,placeholder:`PowerStage`,onChange:e=>r(e.target.value),"aria-describedby":`${p}-note`,"aria-invalid":f!==void 0&&n!==``}),(0,X.jsx)(`label`,{htmlFor:`${p}-instance`,children:`Instance name`}),(0,X.jsx)(`input`,{id:`${p}-instance`,value:i,placeholder:hm(n),onChange:e=>a(e.target.value)}),(0,X.jsx)(`p`,{id:`${p}-note`,children:d?`Writes ${d.file}; ${d.instance} (base ${d.base}) takes the place of ${e.parts.length} part${e.parts.length===1?``:`s`}.`:f}),d&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`h3`,{children:`Ports`}),(0,X.jsx)(bm,{preview:d}),(0,X.jsx)(`h3`,{children:`Designators`}),(0,X.jsx)(xm,{preview:d})]}),(0,X.jsxs)(`label`,{className:`make-sheet-rename`,children:[(0,X.jsx)(`input`,{type:`checkbox`,checked:o,onChange:e=>s(e.target.checked)}),`Rename the parts to local designators (R1, C1, …)`]}),(0,X.jsx)(`button`,{type:`submit`,disabled:!d,children:`Make sub-sheet`})]})}function Cm(e){let t;return()=>(t??=e().catch(e=>{throw t=void 0,e}),t)}function wm(e){let t=Cm(e),n=()=>(0,l.lazy)(()=>t().then(e=>({default:e}))),r=n();return{component:()=>r,retry:()=>{r=n()}}}function Tm({what:e,message:t,onRetry:n}){return(0,l.createElement)(`div`,{role:`alert`},(0,l.createElement)(`p`,null,`The ${e} dialog could not open (${t}). Check that the Studio is still running, then try again; if it fails again, reload the Studio.`),(0,l.createElement)(`button`,{type:`button`,onClick:n},`Retry`))}var Em=class extends l.Component{state={};static getDerivedStateFromError(e){return{error:e instanceof Error?e:Error(String(e))}}render(){let{error:e}=this.state;return e?(0,l.createElement)(Tm,{what:this.props.what,message:e.message,onRetry:()=>{this.props.onRetry(),this.setState({error:void 0})}}):(0,l.createElement)(l.Suspense,{fallback:(0,l.createElement)(`p`,null,`Loading…`)},this.props.render())}},Dm=.0254,Om=e=>e===`mm`?`mil`:`mm`,km=(e,t)=>t===`mil`?e/Dm:e;function Am(e,t){let n=km(e,t).toFixed(t===`mil`?1:2);return/^-0(\.0+)?$/.test(n)?n.slice(1):n}function jm(e,t){return`${Number(km(e,t).toFixed(t===`mm`?4:2))} ${t}`}var Mm=(e,t)=>Math.round(e/t*100),Nm=.0254,Pm=[2*Nm,.1,5*Nm,10*Nm,.5,20*Nm,25*Nm,1,50*Nm,100*Nm].map(e=>Number(e.toFixed(4))),Fm=.5,Im=[.05,.1,.2],Lm=.1,Rm=(e,t,n)=>({...e,[t]:n});function zm(e,t){if(e===`schematic`)return Im.map(e=>({value:e,label:`${e} in`}));if(!t)throw Error(`The PCB's Grid steps need its display unit`);return Pm.map(e=>({value:e,label:jm(e,t)}))}var Bm={schematic:`lines`,pcb:`lines`},Vm=e=>e===`lines`?`dots`:`lines`,Hm=(e,t)=>({...e,[t]:Vm(e[t])}),Um=5,Wm=2;function Gm(e,t,n=1){let r=e;for(let e=0;e<=Wm;e++,r*=Um)if(r*t*n>=3)return r;return null}function Km(e,t,n,r=1){let i=Gm(n,e.scale,r);if(i===null)return null;let a=pe(e,t,{x:0,y:0}),o=pe(e,t,{x:t.width,y:t.height}),s=(e,t)=>{let n=[];for(let r=Math.floor(Math.min(e,t)/i);r<=Math.ceil(Math.max(e,t)/i);r++)n.push(r);return n};return{spacing:i,columns:s(a.x,o.x),rows:s(a.y,o.y),minor:i*e.scale*r>=6}}var qm=e=>e%5==0,Jm=e=>({...e,columns:e.columns.filter(qm),rows:e.rows.filter(qm)});function Ym(e,t,n,r,i,a){let{spacing:o}=r,s=(t,n)=>{for(let[r,a]of[[i.minor,!1],[i.fifth??i.minor,!0]]){e.strokeStyle=r,e.beginPath();for(let r of t.filter(e=>!i.fifth||qm(e)===a)){let[t,i,a,o]=n(r);e.moveTo(t,i),e.lineTo(a,o)}if(e.stroke(),!i.fifth)return}};e.lineWidth=wa(a),s(r.columns,e=>{let r=Ta(fe(t,n,{x:e*o,y:0}).x,a);return[r,0,r,n.height]}),s(r.rows,e=>{let r=Ta(fe(t,n,{x:0,y:e*o}).y,a);return[0,r,n.width,r]})}function Xm(e,t,n,r){let i=Math.floor((Math.round(n*r)-1)/2)/r;return e.map(e=>({at:Ea(t(e),r)-i,fifth:qm(e)}))}function Zm(e,t,n,r){e.fillStyle=n,e.beginPath();for(let n=0;n+1<t.length;n+=2)e.rect(t[n],t[n+1],r,r);e.fill()}function Qm(e,t,n,r,i,a){let{spacing:o}=r,s=Da(i.px,a),c=Xm(r.columns,e=>fe(t,n,{x:e*o,y:0}).x,s,a),l=Xm(r.rows,e=>fe(t,n,{x:0,y:e*o}).y,s,a),u=[];e.fillStyle=i.minor,e.beginPath();for(let t of c)for(let n of l)i.fifth&&t.fifth&&n.fifth?u.push(t.at,n.at):e.rect(t.at,n.at,s,s);e.fill(),i.fifth&&Zm(e,u,i.fifth,s)}function $m(e,t,n,r,i,a){let o=Km(t,n,r.step,a);if(!o)return;let s=o.minor?o:Jm(o);e.save(),r.style===`dots`?Qm(e,t,n,s,i.dots,a):Ym(e,t,n,s,i.lines,a),e.restore()}function eh({panel:e,onClose:t}){let[n,r]=(0,l.useState)(e.settings),i=(0,l.useId)(),a=(e,t)=>r(n=>({...n,[e]:t}));return(0,X.jsxs)(`form`,{className:`rules-form system-form`,onSubmit:r=>{r.preventDefault(),e.apply(n),t()},children:[(0,X.jsx)(`label`,{htmlFor:`${i}-theme`,children:`Theme`}),(0,X.jsxs)(`select`,{id:`${i}-theme`,value:n.theme,onChange:e=>a(`theme`,e.target.value),children:[(0,X.jsx)(`option`,{value:`light`,children:`Light`}),(0,X.jsx)(`option`,{value:`dark`,children:`Dark`})]}),(0,X.jsx)(`label`,{htmlFor:`${i}-unit`,children:`PCB unit`}),(0,X.jsxs)(`select`,{id:`${i}-unit`,value:n.unit,onChange:e=>a(`unit`,e.target.value),children:[(0,X.jsx)(`option`,{value:`mm`,children:`mm`}),(0,X.jsx)(`option`,{value:`mil`,children:`mil`})]}),(0,X.jsx)(`label`,{htmlFor:`${i}-sheet`,children:`Schematic grid`}),(0,X.jsx)(`select`,{id:`${i}-sheet`,value:n.grid.schematic,onChange:e=>a(`grid`,{...n.grid,schematic:Number(e.target.value)}),children:zm(`schematic`).map(e=>(0,X.jsx)(`option`,{value:e.value,children:e.label},e.value))}),(0,X.jsx)(`label`,{htmlFor:`${i}-pcb`,children:`PCB grid`}),(0,X.jsx)(`select`,{id:`${i}-pcb`,value:n.grid.pcb,onChange:e=>a(`grid`,{...n.grid,pcb:Number(e.target.value)}),children:zm(`pcb`,n.unit).map(e=>(0,X.jsx)(`option`,{value:e.value,children:e.label},e.value))}),(0,X.jsxs)(`label`,{children:[(0,X.jsx)(`input`,{type:`checkbox`,checked:n.hoverLabels,onChange:e=>a(`hoverLabels`,e.target.checked)}),` Hover labels`]}),(0,X.jsx)(`p`,{children:`Kept in this browser. The grid steps are where each document starts; the Grid select still changes them.`}),(0,X.jsx)(`button`,{type:`submit`,children:`Save`})]})}var th={width:30,height:20},nh=1e3,rh=/^[\w\- ]+(\/[\w\- ]+)*$/;function ih(e,t,n){let r=e.trim().replace(/\.circuit\.tsx$/,``);if(r===``)return{message:`Give the circuit a name`};if(!rh.test(r))return{message:`Use letters, digits, spaces, - and _ in the name, and / between folders`};let i=[Number(t),Number(n)];return i.some(e=>!Number.isFinite(e)||e<=0||e>nh)?{message:`The board's width and height are mm above 0 and at most ${nh}`}:{file:`${r}.circuit.tsx`,width:i[0],height:i[1]}}function ah({panel:e,onClose:t}){let[n,r]=(0,l.useState)(``),[i,a]=(0,l.useState)(String(th.width)),[o,s]=(0,l.useState)(String(th.height)),[c,u]=(0,l.useState)(),[d,f]=(0,l.useState)(!1),p=(0,l.useId)(),m=async r=>{r.preventDefault();let a=ih(n,i,o);if(`message`in a)return u(a.message);f(!0);let s=await e.create(a);f(!1),s&&t()};return(0,X.jsxs)(`form`,{className:`rules-form`,onSubmit:e=>void m(e),children:[(0,X.jsx)(`label`,{htmlFor:`${p}-name`,children:`Name`}),(0,X.jsx)(`input`,{id:`${p}-name`,value:n,placeholder:`power-board`,onChange:e=>r(e.target.value),"aria-invalid":c!==void 0}),(0,X.jsx)(`label`,{htmlFor:`${p}-w`,children:`Board width (mm)`}),(0,X.jsx)(`input`,{id:`${p}-w`,inputMode:`decimal`,value:i,onChange:e=>a(e.target.value)}),(0,X.jsx)(`label`,{htmlFor:`${p}-h`,children:`Board height (mm)`}),(0,X.jsx)(`input`,{id:`${p}-h`,inputMode:`decimal`,value:o,onChange:e=>s(e.target.value)}),(0,X.jsx)(`p`,{role:c?`alert`:void 0,children:c??`Written as <name>.circuit.tsx in the project folder; Undo removes it again.`}),(0,X.jsx)(`button`,{type:`submit`,disabled:d,children:`Create`})]})}function oh(e,t,n){if(!t)return`Not written in this file`;if(e.library)return`From library part ${e.library}; change it in the library`;if(n.has(t.name))return`Locked`;if(!t.editable)return`Read-only`;let r=t.props.footprint;return r&&r.literal===void 0?`Written as ${r.source}`:void 0}function sh({components:e,parts:t,locked:n}){return e.map(e=>{let r=oh(e,t.find(t=>t.name===e.id),n);return{name:e.id,kind:e.kind,value:e.value??``,footprint:e.footprint??``,...r?{fixed:r}:{}}})}var ch=e=>[...new Set(e.map(e=>e.footprint).filter(e=>e!==``))].sort(),lh=/^[\w.\-+:,=()]+$/;function uh(e,t){let n=e.filter(e=>t[e.name]!==void 0&&t[e.name]?.trim()!==e.footprint);if(n.length===0)return{message:`No footprint was changed.`};let r=n.find(e=>e.fixed);if(r)return{message:`${r.name}: ${r.fixed}`};let i=n.find(e=>!lh.test((t[e.name]??``).trim()));return i?{message:`${i.name}: a footprint is a name such as 0603 or soic8, without spaces`}:{edits:n.map(e=>({kind:`setProps`,part:e.name,props:{footprint:(t[e.name]??``).trim()}})),summary:`change footprints: ${n.slice(0,3).map(e=>`${e.name} → ${(t[e.name]??``).trim()}`).join(`, `)}${n.length>3?` and ${n.length-3} more`:``}`}}function dh({panel:e,onClose:t}){let n=(0,l.useMemo)(()=>e.source?sh(e.source):[],[e.source]),[r,i]=(0,l.useState)({}),[a,o]=(0,l.useState)(),s=(0,l.useId)();if(n.length===0)return(0,X.jsx)(`p`,{children:`The open circuit has no parts yet.`});let c=async i=>{i.preventDefault();let a=uh(n,r);if(`message`in a)return o(a.message);await e.write(a.edits,a.summary)&&t()};return(0,X.jsxs)(`form`,{className:`footprint-manager`,onSubmit:e=>void c(e),children:[(0,X.jsx)(`datalist`,{id:s,children:ch(n).map(e=>(0,X.jsx)(`option`,{value:e},e))}),(0,X.jsxs)(`table`,{children:[(0,X.jsx)(`thead`,{children:(0,X.jsxs)(`tr`,{children:[(0,X.jsx)(`th`,{scope:`col`,children:`Designator`}),(0,X.jsx)(`th`,{scope:`col`,children:`Kind`}),(0,X.jsx)(`th`,{scope:`col`,children:`Value`}),(0,X.jsx)(`th`,{scope:`col`,children:`Footprint`})]})}),(0,X.jsx)(`tbody`,{children:n.map(e=>(0,X.jsxs)(`tr`,{children:[(0,X.jsx)(`td`,{children:e.name}),(0,X.jsx)(`td`,{children:e.kind}),(0,X.jsx)(`td`,{children:e.value}),(0,X.jsx)(`td`,{children:(0,X.jsx)(`input`,{"aria-label":`Footprint of ${e.name}`,list:s,value:r[e.name]??e.footprint,disabled:e.fixed!==void 0,title:e.fixed,onChange:t=>i(n=>({...n,[e.name]:t.target.value}))})})]},e.name))})]}),(0,X.jsx)(`p`,{role:a?`alert`:void 0,children:a??`Changed footprints are written to the circuit file as one change; Undo takes them all back.`}),(0,X.jsx)(`button`,{type:`submit`,children:`Save`})]})}function fh(e,t,n,r,i){let a={code:e,severity:t,message:n,items:Wr(r)};return i?{...a,source:i}:a}var ph={name:`default`,trackWidth:.25,clearance:.2,via:{drill:.3,diameter:.6},patterns:[]};function mh(e){let t=[...e].map(e=>e===`*`?`.*`:e===`?`?`.`:e.replace(/[.+^${}()|[\]\\]/g,`\\$&`)).join(``);return RegExp(`^${t}$`,`s`)}function hh(e,t){if(e===`*`)return!0;let n=mh(e);return t.names.some(e=>n.test(e))}var gh=(e,t)=>e.classes.filter(e=>e.patterns.some(e=>hh(e,t))).map(e=>e.name);function _h(e,t){return gh(e,t)[0]??ph.name}function vh(e,t){let n=new Map,r=[];for(let i of t){let t=gh(e,i);if(n.set(i.id,t[0]??ph.name),t.length<2)continue;let a=`Net ${i.id.replace(/^net\./,``)} matches the net classes ${t.join(` and `)}; it uses ${t[0]}`;r.push(fh(`net-class-conflict`,`error`,a,[i.id]))}return{byNet:n,diagnostics:[...r,...yh(e,t)]}}function yh(e,t){return e.classes.flatMap(e=>e.patterns.filter(e=>!t.some(t=>hh(e,t))).map(t=>fh(`rules`,`warning`,`Net class ${e.name}: the pattern "${t}" matches no net`,[e.name])))}var bh=(e,t)=>e.classes.find(e=>e.name===t)?.clearance??ph.clearance;function xh(e,t,n){let r=e.classClearance.filter(e=>e.a===t&&e.b===n||e.a===n&&e.b===t).map(e=>e.clearance);return Math.max(bh(e,t),bh(e,n),e.fabrication.minClearance,...r)}var Sh=(e,t)=>e.classes.find(n=>n.name===_h(e,t))??ph,Ch=(e,t)=>Math.max(Sh(e,t).trackWidth,e.fabrication.minTrackWidth),wh=e=>Math.round(e*1e6)/1e6;function Th(e,t){let n=Math.max(t.drill,e.fabrication.minDrill);return{drill:n,diameter:Math.max(t.diameter,wh(n+2*e.fabrication.minAnnularRing))}}var Eh=(e,t)=>Th(e,Sh(e,t).via),Dh=e=>Th(e,ph.via),Oh=e=>e.fabrication.filletRadius??1,kh=/^([+-]?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?)\s*(mm|in|mil)?$/i,Ah={mm:1,in:25.4,mil:.0254};function jh(e){if(typeof e==`number`)return Number.isFinite(e)?e:void 0;if(typeof e!=`string`)return;let t=kh.exec(e.trim());if(!t)return;let n=Number(t[1])*(Ah[(t[2]??`mm`).toLowerCase()]??1);return Number.isFinite(n)?n:void 0}var Mh=`Fillet radius`,Nh=`Edit → Fillet tracks rounds corners with this radius. Empty is the default, 1 mm. A track's width is the floor: a smaller radius is raised to the width.`;function Ph(e){let t=e?.filletRadius;return{value:t===void 0?``:String(t),placeholder:`1 mm (default)`}}function Fh(e){if(e.trim()===``)return{radius:null};let t=jh(e);return t===void 0||t<=0||t>50?{message:`Type a length above 0 and at most 50 mm, such as 1, 0.5mm or 40mil, or leave it empty for the default.`}:{radius:Math.round(t*1e6)/1e6}}var Ih=`modulepreload`,Lh=function(e,t){return new URL(e,t).href},Rh={},zh=function(e){return e.pathname.endsWith(`.css`)},Bh=function(e,t,n){if(t in e)return e[t];let r=n();if(!r){e[t]=void 0;return}let i=r.then(()=>{e[t]=void 0},n=>{throw e[t]=void 0,n});return e[t]=i,i},Vh=function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){let e,i=document.querySelector(`meta[property=csp-nonce]`),a=i?.nonce||i?.getAttribute(`nonce`);function o(e){return Promise.all(e.map(e=>Promise.resolve(e).then(e=>({status:`fulfilled`,value:e}),e=>({status:`rejected`,reason:e}))))}function s(e){return import.meta.resolve?new URL(import.meta.resolve(e)):new URL(e,import.meta.url)}r=o(t.map(t=>{t=Lh(t,n);let r=s(t),i=zh(r);return Bh(Rh,r.href,()=>{if(e===void 0){e={all:new Set,styles:new Set};let t=document.getElementsByTagName(`link`);for(let n=t.length-1;n>=0;n--){let r=t[n];e.all.add(r.href),r.rel===`stylesheet`&&e.styles.add(r.href)}}if((i?e.styles:e.all).has(r.href))return;let t=document.createElement(`link`);if(t.rel=i?`stylesheet`:Ih,i||(t.as=`script`),t.crossOrigin=``,t.href=r.href,a&&t.setAttribute(`nonce`,a),document.head.appendChild(t),i)return new Promise((e,n)=>{t.addEventListener(`load`,e),t.addEventListener(`error`,()=>n(Error(`Unable to preload CSS for ${r}`)))})})}).filter(e=>e!==void 0))}function i(e){let t=new Event(`vite:preloadError`,{cancelable:!0});if(t.payload=e,window.dispatchEvent(t),!t.defaultPrevented)throw e}return r.then(t=>{for(let e of t||[])e.status===`rejected`&&i(e.reason);return e().catch(i)})},Hh=wm(()=>Vh(()=>import(`./NewPartDialog-B_cnPuI-.js`).then(e=>e.NewPartForm),[],import.meta.url)),Uh=`button, [href], input, select, textarea, [tabindex]:not([tabindex='-1'])`;function Wh(e,t){zp(!0,n=>{let r=Pp(n.key);if(r===`hold`)return;if(n.preventDefault(),r===`close`)return t();let i=[...e.current?.querySelectorAll(Uh)??[]];(i[Fp(i.indexOf(document.activeElement),i.length,n.shiftKey)]??e.current)?.focus()})}function Gh({title:e,onClose:t,children:n,wide:r=!1}){let i=(0,l.useRef)(null);return(0,l.useEffect)(()=>{let e=document.activeElement;return(i.current?.querySelector(`[data-default]`)??i.current?.querySelector(Uh)??i.current)?.focus(),()=>{e instanceof HTMLElement&&e.isConnected&&e.focus()}},[]),Wh(i,t),(0,X.jsx)(`div`,{className:`dialog-backdrop`,onPointerDown:e=>e.target===e.currentTarget&&t(),children:(0,X.jsxs)(`section`,{ref:i,tabIndex:-1,className:r?`dialog wide`:`dialog`,role:`dialog`,"aria-modal":`true`,"aria-label":e,children:[(0,X.jsxs)(`header`,{className:`hairline-b`,children:[(0,X.jsx)(`h2`,{children:e}),(0,X.jsx)(`button`,{className:`icon`,"aria-label":`Close`,onClick:t,children:(0,X.jsx)(Ap,{})})]}),(0,X.jsx)(`div`,{className:`dialog-body`,children:n})]})})}function Kh(){return(0,X.jsx)(`table`,{children:(0,X.jsx)(`tbody`,{children:Xp().map(e=>(0,X.jsxs)(`tr`,{children:[(0,X.jsx)(`td`,{children:(0,X.jsx)(`kbd`,{children:e.keys})}),(0,X.jsx)(`td`,{children:e.label})]},e.keys))})})}function qh({rules:e,onClose:t}){let n=Ph(e.fabrication),[r,i]=(0,l.useState)(n.value),[a,o]=(0,l.useState)(),s=(0,l.useId)(),c=async i=>{i.preventDefault();let a=Fh(r);if(`message`in a)return o(a.message);if(r.trim()===n.value)return t();await e.save(a.radius)&&t()};return(0,X.jsxs)(`form`,{className:`rules-form`,onSubmit:e=>void c(e),children:[(0,X.jsx)(`label`,{htmlFor:s,children:Mh}),(0,X.jsx)(`input`,{id:s,value:r,placeholder:n.placeholder,onChange:e=>i(e.target.value),"aria-describedby":`${s}-note`,"aria-invalid":a!==void 0}),(0,X.jsx)(`p`,{id:`${s}-note`,children:a??Nh}),(0,X.jsx)(`p`,{children:`The rest of the design rules are in rules.yaml in the project.`}),(0,X.jsx)(`button`,{type:`submit`,children:`Save`})]})}function Jh({panel:e,onClose:t}){let n=e=>()=>{t(),e()};return(0,X.jsxs)(`div`,{className:`rules-form`,children:[(0,X.jsx)(`p`,{children:e.question}),(0,X.jsx)(`button`,{type:`button`,"data-default":!0,onClick:n(e.showChecks),children:`Show checks`}),(0,X.jsx)(`button`,{type:`button`,onClick:n(e.exportAnyway),children:`Export anyway`})]})}function Yh({name:e,onClose:t,rules:n,makeSheet:r,importPart:i,newPart:a,system:o,newCircuit:s,footprints:c,exportChecks:l}){return e===`exportChecks`?(0,X.jsx)(Gh,{title:`Fabrication files`,onClose:t,children:(0,X.jsx)(Jh,{panel:l,onClose:t})}):e===`footprints`?(0,X.jsx)(Gh,{title:`Footprint manager`,onClose:t,wide:!0,children:(0,X.jsx)(dh,{panel:c,onClose:t})}):e===`newCircuit`?(0,X.jsx)(Gh,{title:`New circuit`,onClose:t,children:(0,X.jsx)(ah,{panel:s,onClose:t})}):e===`system`?(0,X.jsx)(Gh,{title:`System settings`,onClose:t,children:(0,X.jsx)(eh,{panel:o,onClose:t})}):e===`newPart`?(0,X.jsx)(Gh,{title:`New part`,onClose:t,wide:!0,children:(0,X.jsx)(Em,{what:`New part`,onRetry:Hh.retry,render:()=>{let e=Hh.component();return(0,X.jsx)(e,{panel:a,onClose:t})}})}):e===`importPart`?(0,X.jsx)(Gh,{title:`Import by LCSC number`,onClose:t,children:(0,X.jsx)(am,{panel:i,onClose:t})}):e===`makeSheet`?(0,X.jsx)(Gh,{title:`Make sub-sheet`,onClose:t,children:(0,X.jsx)(Sm,{panel:r,onClose:t})}):e===`rules`?(0,X.jsx)(Gh,{title:`Design rules`,onClose:t,children:(0,X.jsx)(qh,{rules:n,onClose:t})}):e===`keys`?(0,X.jsx)(Gh,{title:`Keys`,onClose:t,children:(0,X.jsx)(Kh,{})}):(0,X.jsxs)(Gh,{title:`About copperflow`,onClose:t,children:[(0,X.jsxs)(`p`,{children:[(0,X.jsx)(`strong`,{children:`copperflow`}),` Studio`]}),(0,X.jsx)(`p`,{children:`Design circuits in code with a human and an AI agent editing the same files.`}),(0,X.jsx)(`p`,{children:`Apache License 2.0`})]})}function Xh(e){return`Created ${e.id}: ${e.title}, ${e.pins} pin${e.pins===1?``:`s`}, footprint ${e.footprint}. Not verified: check it in ${e.verification}.`}function Zh({label:e,shortcut:t,menu:n,index:r,enabled:i,checked:a,reason:o,onActivate:s}){return(0,X.jsxs)(`button`,{role:a===void 0?`menuitem`:`menuitemcheckbox`,"aria-checked":a,className:a?`menu-item checked`:`menu-item`,...n===void 0?{}:{"data-menu":n},"data-item":r,tabIndex:-1,"aria-disabled":!i||void 0,title:o,onClick:e=>{let t=!Qf(e);t||ep(e),i&&s(t)},children:[(0,X.jsx)(`span`,{children:e}),t&&(0,X.jsx)(`kbd`,{children:t})]})}function Qh(e,t,n){(0,l.useEffect)(()=>{if(!e)return;let r=e=>{e.target instanceof Node&&t.current?.contains(e.target)||n()};return window.addEventListener(`pointerdown`,r,!0),()=>window.removeEventListener(`pointerdown`,r,!0)},[e,t,n])}var $h=(e,t)=>(e+t)%t,eg=e=>e===`item`||e===`disabled`;function tg(e,t,n,r=eg){let i=e.length,a=t??(n===1?-1:i);for(let t=0;t<i;t++)if(a=$h(a+n,i),r(e[a]))return a;return null}var ng=e=>e?tg(e,null,1):null,rg=e=>e?tg(e,null,-1):null,ig=(e,t)=>e?tg(e,null,t,e=>e===`item`)??tg(e,null,t):null,ag=e=>ig(e,1),og=e=>ig(e,-1),sg=(e,t,n=!0)=>({open:e,focus:t,preventDefault:n}),cg=(e,t)=>sg(e,{menu:e,item:t});function lg(e,t,n,r){let i=r.length,a={ArrowLeft:$h(t-1,i),ArrowRight:$h(t+1,i),Home:0,End:i-1}[e];return a===void 0?e===`ArrowDown`?cg(t,ag(r[t])):e===`ArrowUp`?cg(t,og(r[t])):n===null?null:e===`Escape`?sg(null,{menu:t,item:null}):e===`Tab`?sg(null,`keep`,!1):null:sg(n===null?null:a,{menu:a,item:null})}function ug(e,t,n){let r=n[t.menu]??[],i=n.length,a={ArrowDown:tg(r,t.item,1),ArrowUp:tg(r,t.item,-1),Home:ng(r),End:rg(r)};if(e in a)return cg(t.menu,a[e]??null);if(e===`ArrowLeft`||e===`ArrowRight`){let r=$h(t.menu+(e===`ArrowLeft`?-1:1),i);return cg(r,ag(n[r]))}return e===`Escape`?sg(null,{menu:t.menu,item:null}):e===`Tab`?sg(null,{menu:t.menu,item:null},!1):null}function dg(e,t,n){return e===`Escape`?sg(null,`keep`):e===`Tab`?sg(null,`keep`,!1):e===`ArrowDown`||e===`Home`?cg(t,ag(n[t])):e===`ArrowUp`||e===`End`?cg(t,og(n[t])):e===`ArrowLeft`||e===`ArrowRight`?sg($h(t+(e===`ArrowLeft`?-1:1),n.length),`keep`):null}function fg(e,t,n,r,i={}){return r.length===0||(i.alt||i.ctrl||i.meta)&&e!==`Tab`?null:t===null?n===null?null:dg(e,n,r):t.item===null?lg(e,t.menu,n,r):ug(e,{menu:t.menu,item:t.item},r)}function pg(e){return ag(e)}var mg=e=>e.item===null?`[data-menu="${e.menu}"]:not([data-item])`:`[data-menu="${e.menu}"][data-item="${e.item}"]`;function hg(e,t){let n=t instanceof HTMLElement&&e?.contains(t)?t.closest(`[data-menu]`):null;if(!n)return null;let r=n.dataset.item;return{menu:Number(n.dataset.menu),item:r===void 0?null:Number(r)}}function gg(e){let t=(0,l.useRef)(null);return(0,l.useLayoutEffect)(()=>{let n=t.current;n&&(t.current=null,e.current?.querySelector(mg(n))?.focus())}),(0,l.useCallback)(n=>{let r=e.current?.querySelector(mg(n));r?r.focus():t.current=n},[e])}function _g({entry:e,menu:t,index:n,view:r,selected:i,off:a,toggles:o,onRun:s}){if(e===`separator`)return(0,X.jsx)(`li`,{className:`menu-separator`,role:`separator`});let{label:c,shortcut:l,command:u,toggle:d}=e,{enabled:f,reason:p}=qp(e,r,i,a);return(0,X.jsx)(`li`,{role:`none`,children:(0,X.jsx)(Zh,{label:c,...l?{shortcut:l}:{},...d?{checked:o[d]}:{},menu:t,index:n,enabled:f,...p?{reason:p}:{},onActivate:e=>u&&s(u,t,e)})})}function vg({menu:e,index:t,view:n,selected:r,off:i,toggles:a,onRun:o}){return(0,X.jsx)(`ul`,{className:`menu-dropdown`,role:`menu`,"aria-label":e.title,children:e.entries.map((e,s)=>(0,X.jsx)(_g,{entry:e,menu:t,index:s,view:n,selected:r,off:i,toggles:a,onRun:o},e===`separator`?`sep${s}`:e.label))})}function yg({menu:e,index:t,open:n,current:r,onPointer:i,onHover:a,onKeyboard:o,view:s,selected:c,off:l,toggles:u,onRun:d}){return(0,X.jsxs)(`div`,{className:`menu`,children:[(0,X.jsx)(`button`,{role:`menuitem`,"data-menu":t,"aria-haspopup":`menu`,"aria-expanded":n,tabIndex:r?0:-1,className:`menu-title${n?` open`:``}`,onClick:e=>{if(!Qf(e))return o({open:t,focus:{menu:t,item:pg(Qp(s,c,l)[t])},preventDefault:!0});ep(e),i(t)},onPointerEnter:()=>a(t),children:e.title}),n&&(0,X.jsx)(vg,{menu:e,index:t,view:s,selected:c,off:l,toggles:u,onRun:d})]})}function bg({run:e,view:t,selected:n,toggles:r,off:i,children:a}){let[o,s]=(0,l.useReducer)(Zp,{open:null}),[c,u]=(0,l.useState)(0),d=(0,l.useRef)(null),f=gg(d),p=o.open===null?null:Gp.findIndex(e=>e.title===o.open),m=(0,l.useMemo)(()=>Qp(t,n,i),[t,n,i]),h=e=>{s({type:`set`,title:e.open===null?null:Gp[e.open]?.title??null}),e.focus!==`keep`&&(u(e.focus.menu),f(e.focus))},g=e=>{let t=fg(e.key,hg(d.current,document.activeElement),p,m,{alt:e.altKey,ctrl:e.ctrlKey,meta:e.metaKey});return t?(t.preventDefault&&e.preventDefault(),h(t),!0):!1};zp(p!==null,e=>void g(e)),Qh(p!==null,d,(0,l.useCallback)(()=>s({type:`outside`}),[]));let _=(t,n,r)=>{r&&h({open:null,focus:{menu:n,item:null},preventDefault:!0}),s({type:`run`}),e(t)},v=e=>{u(e),s({type:`click`,title:Gp[e]?.title??``})},y=e=>s({type:`hover`,title:Gp[e]?.title??``});return(0,X.jsxs)(`header`,{className:`menubar hairline-b`,ref:d,children:[(0,X.jsx)(`span`,{className:`brand`,title:`copperflow`,children:`copperflow`}),(0,X.jsx)(`nav`,{className:`menus`,role:`menubar`,"aria-label":`Menu`,onKeyDown:e=>g(e)&&e.stopPropagation(),children:Gp.map((e,a)=>(0,X.jsx)(yg,{menu:e,index:a,open:p===a,current:c===a,onPointer:v,onHover:y,onKeyboard:h,view:t,selected:n,off:i,toggles:r,onRun:_},e.title))}),(0,X.jsx)(`div`,{className:`menubar-end`,children:a})]})}var xg=`Main`;function Sg(e){let t=e?.schematic.pages?.map(e=>e.name);return t&&t.length>0?t:[xg]}function Cg(e,t){let n=Sg(e);return n.includes(t)?t:n[0]??`Main`}function wg(e,t){let n=e.schematic.pages??[],r=n.find(e=>e.name===t);if(n.length<=1||!r)return e;let i=(e,t,n)=>{let r=new Set(t);return e.filter(e=>r.has(n(e)))},{schematic:a}=e;return{...e,schematic:{...a,symbols:i(a.symbols,r.parts,e=>e.component),wires:i(a.wires,r.wires,e=>e.id),labels:i(a.labels,r.labels,e=>e.id),drawings:i(a.drawings,r.drawings,e=>e.id),junctions:r.junctions,...a.noConnects?{noConnects:i(a.noConnects,r.parts,e=>e.component)}:{}}}}function Tg(e){for(let t=e.length+1;;t++)if(!e.includes(`Page ${t}`))return`Page ${t}`}function Eg(e,t){if(t===`Main`)return`${xg} is the first page and cannot be deleted`;let n=e?.schematic.pages?.find(e=>e.name===t)?.parts??[];if(n.length>0)return`Page ${t} still has parts (${n.join(`, `)}); move or delete them first`;let r=e?.circuit.connections.filter(e=>e.page===t)??[];if(r.length===0)return;let i=r.map(e=>`${e.from.replace(/^net\./,``)} to ${e.to.replace(/^net\./,``)}`).join(`, `);return`${t} still has ${r.length===1?`1 trace`:`${r.length} traces`}: ${i}; move or remove ${r.length===1?`it`:`them`} first`}function Dg(e){return e===`Main`?`${xg} is the first page and keeps its name`:void 0}function Og(e,t){return e.status===`building`?`Building`:e.status===`failed`?`Build failed`:e.status!==`done`||!e.design?`Not built`:t===0?`Build OK`:`${t} ${t===1?`error`:`errors`}`}function kg(e,t){return e.status===`building`?`busy`:e.status===`failed`||t>0?`bad`:e.status===`done`?`good`:`idle`}function Ag({build:e,errors:t,onOpen:n}){return(0,X.jsxs)(`button`,{className:`build ${kg(e,t)}`,onClick:e=>{rp(e),n()},title:`Show DRC`,children:[(0,X.jsx)(`span`,{className:`dot`,"aria-hidden":`true`}),(0,X.jsx)(`span`,{role:`status`,children:Og(e,t)})]})}var jg=`light`,Mg=`copperflow.theme`,Ng=()=>typeof window>`u`?void 0:window.localStorage,Pg=e=>e===`dark`||e===`light`?e:jg;function Fg(e){try{return Pg(e()?.getItem(Mg))}catch{return jg}}function Ig(e,t){try{let n=e();return n?(n.setItem(Mg,t),!0):!1}catch{return!1}}function Lg(e,t){e.setAttribute(`data-theme`,t)}var Rg=e=>({themeLight:e===`light`,themeDark:e===`dark`}),zg=e=>e===`dark`?`dots`:`lines`,Bg=(e,t,n)=>t===n?e:Vg(e,n),Vg=(e,t)=>({...e,schematic:zg(t)}),Hg=(e,t,n,r,i)=>({id:e,title:t,icon:n,command:r,group:i}),Ug=(e,t,n,r,i)=>({id:e,title:t,icon:n,pending:r,group:i}),Wg=[Hg(`undo`,`Undo (Ctrl+Z)`,`undo`,`undo`,0),Hg(`redo`,`Redo (Ctrl+Y)`,`redo`,`redo`,0)],Gg=[Hg(`zoomIn`,`Zoom in`,`zoomIn`,`zoomIn`,1),Hg(`zoomOut`,`Zoom out`,`zoomOut`,`zoomOut`,1),Hg(`fit`,`Fit all (K)`,`fit`,`fit`,1),Hg(`fitSelection`,`Fit selection`,`fitSelection`,`fitSelection`,1),Hg(`fitArea`,`Fit area`,`fitArea`,`fitArea`,1)],Kg=e=>[Hg(`rotate`,`Rotate (Space)`,`rotate`,`rotate`,e),Hg(`rotateRight`,`Rotate right`,`rotateRight`,`rotateRight`,e)],qg=e=>[Hg(`gridStyle`,`Grid style`,`grid`,`gridStyle`,e),Hg(`snap`,`Snap (Alt+S)`,`snap`,`snap`,e)],Jg=e=>[Hg(`alignLeft`,`Align left (Ctrl+Shift+L)`,`alignLeft`,`alignLeft`,e),Hg(`distributeH`,`Distribute horizontally (Ctrl+Shift+H)`,`distributeH`,`distributeH`,e)],Yg=e=>Hg(`checkDrc`,`Check DRC`,`check`,`checkDrc`,e),Xg={schematic:[...Wg,...Gg,...qg(2),Hg(`component`,`Component (Shift+F)`,`component`,`placeComponent`,3),Hg(`wire`,`Wire (Alt+W)`,`wire`,`wire`,3),Hg(`bus`,`Bus (Alt+B)`,`bus`,`drawBus`,3),Hg(`netLabel`,`Net label (Alt+N)`,`netLabel`,`netLabel`,3),Hg(`ground`,`Ground flag`,`ground`,`groundFlag`,3),Hg(`power`,`Power flag`,`power`,`powerFlag`,3),Hg(`noConnect`,`No connect flag`,`noConnect`,`noConnect`,3),Hg(`polyline`,`Polyline (Alt+L)`,`polyline`,`drawPolyline`,4),Hg(`arc`,`Arc (Alt+A)`,`arc`,`drawArc`,4),Hg(`circle`,`Circle (Alt+C)`,`circle`,`drawCircle`,4),Hg(`rectangle`,`Rectangle (Alt+R)`,`rectangle`,`drawRectangle`,4),Hg(`text`,`Text (Alt+T)`,`text`,`drawText`,4),...Kg(5),...Jg(6),Yg(7)],pcb:[...Wg,...Gg,{id:`unit`,title:`Unit (Q)`,text:`unit`,command:`toggleUnit`,group:2},...qg(2),Hg(`via`,`Via (Alt+V)`,`via`,`placeVia`,3),Ug(`boardOutline`,`Board outline`,`boardOutline`,Wp,3),Ug(`copperArea`,`Copper area`,`copperArea`,Wp,3),Yg(4),Hg(`singleRouting`,`Single routing (Alt+W)`,`singleRouting`,`singleRouting`,5),...Jg(6),...Kg(7),Hg(`gerber`,`Gerber`,`gerber`,`exportFabrication`,8)]};function Zg(e,t,n={}){if(e.pending!==void 0)return{enabled:!1,title:`${e.title}: ${e.pending}`};let r=n[e.command];if(r!==void 0)return{enabled:!1,title:`${e.title}: ${r}`};let i=Up(e.command,t);return i?{enabled:!1,title:`${e.title}: ${i}`}:{enabled:!0,title:e.title}}function Qg(e){let t=[];for(let n of Xg[e]){let e=t.at(-1);e&&e[0]?.group===n.group?e.push(n):t.push([n])}return t}var $g=new Set([`wire`,`netLabel`,`groundFlag`,`powerFlag`,`fitArea`,`singleRouting`,`placeVia`,`noConnect`,`junction`,...x]);function e_(e){return $g.has(e)}var t_={snap:`snap`};function n_(e,t,n){let r=t_[e];return r?n[r]:t===e}function r_(e){return e_(e)||e in t_}function i_(e,t){return e?`wire`:t===`label`?`netLabel`:t===`gnd`?`groundFlag`:t===`vcc`?`powerFlag`:null}function a_(e){return e?S[e]:null}var o_={active:null,stop:null},s_=o_,c_=new Set;function l_(e){if(e.active!==s_.active||e.stop!==s_.stop){s_=e;for(let e of c_)e()}}function u_(){return s_}function d_(){l_(o_)}function f_(e){return c_.add(e),()=>{c_.delete(e)}}function p_(){return(0,l.useSyncExternalStore)(f_,u_)}function m_(e,t){return t.active===e&&t.stop?`stop`:`run`}var h_=o(),g_=[`onPointerDown`,`onPointerMove`,`onPointerUp`,`onPointerCancel`,`onMouseDown`,`onMouseMove`,`onMouseUp`,`onDoubleClick`,`onWheel`,`onContextMenu`];function __(){let e=e=>e.stopPropagation();return Object.fromEntries(g_.map(t=>[t,e]))}var v_=`toolbar-view-slot`,y_=__();function b_({children:e}){let[t,n]=(0,l.useState)(null);return(0,l.useLayoutEffect)(()=>n(document.getElementById(v_)),[]),t?(0,h_.createPortal)((0,X.jsx)(`div`,{className:`canvas-tools`,...y_,onClick:rp,children:e}),t):null}function x_({item:e,unit:t}){if(e.text===`unit`)return(0,X.jsx)(X.Fragment,{children:t});let n=Np[e.icon];return(0,X.jsx)(n,{})}function S_({view:e,unit:t,selected:n,toggles:r,off:i,run:a}){let o=p_();return(0,X.jsxs)(`div`,{className:`studio-toolbar hairline-b`,role:`toolbar`,"aria-label":`Tools`,children:[Qg(e).map((e,s)=>(0,X.jsxs)(l.Fragment,{children:[s>0&&(0,X.jsx)(`span`,{className:`toolbar-separator`,role:`separator`,"aria-orientation":`vertical`}),e.map(e=>{let s=e.command!==void 0&&n_(e.command,o.active,r),c=Zg(e,n,i);return(0,X.jsx)(`button`,{className:e.text?`toolbar-button text`:`toolbar-button`,title:c.title,"aria-label":e.text===`unit`?`${e.title}, now ${t}`:c.title,"aria-disabled":!c.enabled||void 0,"aria-pressed":e.command!==void 0&&r_(e.command)?s:void 0,"data-pressed":s||void 0,onClick:t=>{rp(t),c.enabled&&e.command!==void 0&&(m_(e.command,o)===`stop`?o.stop?.():a(e.command))},children:(0,X.jsx)(x_,{item:e,unit:t})},e.id)})]},e[0]?.group)),(0,X.jsx)(`div`,{className:`toolbar-view-slot`,id:v_})]})}var C_=[`Designators`,`Quantity`,`Value`,`Footprint`,`Manufacturer`,`MPN`,`Supplier part`,`Verified`];function w_(e){return/[",\r\n]/.test(e)?`"${e.replace(/"/g,`""`)}"`:e}function T_(e){return[C_,...e.map(e=>[e.designators.join(` `),String(e.quantity),e.value||e.kind,e.footprint,e.manufacturer,e.mpn,e.supplier,e.libraryPart?e.verified?`yes`:`no`:``])].map(e=>e.map(w_).join(`,`)).join(`\r
14
14
  `)+`\r
15
15
  `}function E_(e){return`${(e.split(/[\\/]/).at(-1)??e).replace(/\.circuit\.tsx$|\.tsx$/,``)}-bom.csv`}function D_(e,t,n){let r=(e,t)=>n.find(t=>t.endsWith(e))??t;return`upload ${e.split(`/`).pop()??e} to JLCPCB's PCB order, and ${r(`-bom.csv`,`the BOM`)} and ${r(`-pick-and-place.csv`,`the pick-and-place file`)} from ${t}/ at its assembly step (the zip holds them too)`}var O_=(e,t)=>`${e} ${t}${e===1?``:`s`}`;function k_(e){let t=`Checks: ${O_(e.errors,`error`)}, ${O_(e.warnings,`warning`)}.`;return e.errors>0?`${t} Run check_circuit (or copperflow check <file>) and fix the errors before anyone orders this board.`:t}var A_=3;function j_(e){let t=e.slice(0,A_).map(e=>`Warning: ${e}.`),n=e.length-A_;return n>0?[...t,`And ${n} more ${n===1?`warning`:`warnings`}.`]:t}function M_(e){if(!e.written)return`No fabrication files written: ${e.errors.join(`; `)}`;let t=D_(e.zip,e.folder,e.files);return[`Wrote ${e.files.length} fabrication files to ${e.folder}/ and ${e.zip}.`,`U${t.slice(1)}.`,...j_(e.warnings),k_(e.checks)].join(` `)}function N_(e){return e.errors>0}var P_=(e,t)=>`${e} ${t}${e===1?``:`s`}`;function F_(e){return`The design rule check reports ${P_(e.errors,`error`)} and ${P_(e.warnings,`warning`)}. Look at them before you order this board.`}var I_=1e-9,L_=(e,t)=>({x:e.x-t.x,y:e.y-t.y}),R_=(e,t)=>({x:e.x+t.x,y:e.y+t.y}),z_=(e,t)=>({x:e.x*t,y:e.y*t}),B_=(e,t)=>e.x*t.y-e.y*t.x,V_=(e,t)=>e.x===t.x&&e.y===t.y;function H_(e){return e.every((t,n)=>n===0||Ns(e[n-1],t)!==`slanted`)}function U_(e){let t=e.map(e=>({x:z(e.x),y:z(e.y)})),n=t.filter((e,n)=>n===0||!V_(t[n-1],e)),r=[];for(let[e,t]of n.entries()){let[i,a]=[r[r.length-1],n[e+1]];i&&a&&Math.abs(B_(L_(t,i),L_(a,t)))<I_||r.push(t)}return r}function W_(e,t,n,r){let i=B_(t,r);if(!(Math.abs(i)<I_))return R_(e,z_(t,B_(L_(n,e),r)/i))}function G_(e,t,n){let[r,i]=[e[t],e[t+1]],a=L_(i,r),o=R_(r,n),s=(r,i)=>{let s=e[r],c=e[i],l=c&&W_(c,L_(s,c),o,a);return l?[l]:r===t?[s,R_(s,n)]:[R_(s,n),s]},c=t===0?[r,o]:s(t,t-1),l=t+1===e.length-1?[R_(i,n),i]:s(t+1,t+2);return[...e.slice(0,t),...c,...l,...e.slice(t+2)]}function K_(e,t,n,r){let i={x:ve(e.x+n.x,r.step,r.snap),y:ve(e.y+n.y,r.step,r.snap)},a=L_(t,e),o=Math.hypot(a.x,a.y);if(o<I_)return{x:0,y:0};let s={x:-a.y/o,y:a.x/o};return z_(s,(i.x-e.x)*s.x+(i.y-e.y)*s.y)}function q_(e,t,n,r){let i=e[t],a={x:ve(i.x+n.x,r.step,r.snap),y:ve(i.y+n.y,r.step,r.snap)};return e.map((e,n)=>n===t?a:e)}function J_(e,t,n,r){let i=e[t.index],a=e[t.index+1];if(!i||t.kind===`segment`&&!a)return[...e];let o;o=H_(e)?Ac(e,t,n,r):t.kind===`corner`?q_(e,t.index,n,r):G_(e,t.index,K_(i,a,n,r));let s=U_(o);return s.length>=2?s:[...e]}var Y_=e=>Math.max(e.length-1,0),X_=(e,t)=>Number.isInteger(t)&&t>=0&&t<Y_(e),Z_=e=>e.map(e=>({x:e.x,y:e.y}));function Q_(e,t){let n=Y_(e.points);if(!X_(e.points,t))return{message:`${e.id} has no segment ${t}; it has ${n} (0 to ${n-1})`};if(e.locked)return{message:`${e.id} is locked`};let[r,i]=[e.points.slice(0,t+1),e.points.slice(t+1)].filter(e=>e.length>=2);if(!r)return{edits:[{kind:`removeTrack`,id:e.id}]};let a=e.net??e.carried,o=a===void 0?{}:{net:a},s={kind:`setTrack`,id:e.id,...e.net===void 0?o:{},points:Z_(r)};return i?{edits:[s,{kind:`addTrack`,...o,layer:e.layer,width:e.width,points:Z_(i)}]}:{edits:[s]}}var $_={tracks:new Map,vias:new Map},ev=(e,t)=>({x:e.x+t.x,y:e.y+t.y}),tv=(e,t)=>e.length===t.length&&e.every((e,n)=>e.x===t[n]?.x&&e.y===t[n]?.y),nv=(e,t)=>Math.hypot(t.x-e.at.x,t.y-e.at.y)<=e.diameter/2;function rv(e,t,n){return e.vias.filter(r=>{if(!t.has(r.id))return!1;if(r.locked)return void n.push(`${r.id} is locked`);let i=e=>[e.points[0],e.points.at(-1)].some(e=>e!==void 0&&nv(r,e)),a=e.tracks.find(e=>e.locked&&i(e));return!a||void n.push(`${r.id} has the locked track ${a.id} on it`)})}function iv(e,t,n,r,i){let a=t=>r.some(e=>nv(e,t))||!i(t,e.layer)&&!n.some(e=>nv(e,t)),[o,s]=[e.points[0],e.points.at(-1)];return U_(Hs(e.points,t,{start:a(o),end:a(s)}))}function av(e,t,n){let r=e.points.length-1,i=(e,t)=>(t===0||t===r)&&n.some(t=>nv(t,e));return e.points.some(i)?U_(e.points.map((e,n)=>i(e,n)?ev(e,t):e)):e.points}function ov(e,t,n,r){let i=[];if(n.x===0&&n.y===0)return{edits:[],shapes:$_,skipped:i};let a=new Set(t),o=rv(e,a,i),s=new Map;for(let t of e.tracks){a.has(t.id)&&t.locked&&i.push(`${t.id} is locked`);let c=a.has(t.id)&&!t.locked?iv(t,n,e.vias,o,r):av(t,n,o);!tv(c,t.points)&&c.length>=2&&s.set(t.id,c)}let c=new Map(o.map(e=>[e.id,ev(e.at,n)]));return{edits:[...[...c].map(([e,t])=>({kind:`setVia`,id:e,at:t})),...[...s].map(([e,t])=>({kind:`setTrack`,id:e,points:[...t]}))],shapes:{tracks:s,vias:c},skipped:i}}function sv(e,t){if(!tv(t,e.points))return e.locked?{message:`${e.id} is locked`}:{kind:`setTrack`,id:e.id,points:[...t]}}function cv(e,t){let n=new Set(t),r=[...e.tracks.map(e=>({...e,kind:`removeTrack`})),...e.vias.map(e=>({...e,kind:`removeVia`}))].filter(e=>n.has(e.id)),i=r.filter(e=>!e.locked);return{edits:i.map(e=>({kind:e.kind,id:e.id})),removed:i.map(e=>e.id),skipped:r.filter(e=>e.locked).map(e=>`${e.id} is locked`)}}function lv(e,t){if(!e)return{message:`${t.id} is gone`};if(!qi(t,e.points))return{message:`the track changed; select the segment again`};let n={...e.named===void 0?{}:{net:e.named},...e.net===void 0?{}:{carried:e.net}},r=Q_({id:e.id,...n,layer:e.layer,width:e.width,points:e.points,locked:e.locked},t.index);return`message`in r?r:{edits:r.edits,summary:`Delete segment ${t.index} of ${e.id}`}}function uv(e,t){return{tracks:new Map([...e.tracks,...t.tracks]),vias:new Map([...e.vias,...t.vias])}}function dv(e,t){return{tracks:e.tracks.map(e=>{let n=t.tracks.get(e.id);return n?{...e,points:[...n]}:e}),vias:e.vias.map(e=>{let n=t.vias.get(e.id);return n?{...e,at:n}:e})}}function fv(e,t,n){let r=new Set(t),i=e.tracks.filter(e=>r.has(e.id)&&e.locked!==n),a=e.vias.filter(e=>r.has(e.id)&&e.locked!==n),o=[...i.map(e=>({kind:`setTrack`,id:e.id,locked:n})),...a.map(e=>({kind:`setVia`,id:e.id,locked:n}))];return o.length===0?{message:`The selected copper is already ${n?`locked`:`unlocked`}.`}:{edits:o,summary:`${n?`Lock`:`Unlock`} ${et([...i,...a].map(e=>e.id))}`}}function pv(e,t){return!t&&e.copper.length>0&&e.total===e.copper.length}function mv(e){let t=e.lastIndexOf(`/`);return t>0?e.slice(0,t):void 0}var hv=e=>/(^|\/)hole:\d+$/.test(e);function gv(e,t,n){return`${e} is a ${hv(e)?`hole`:`copper pour`} inside the sub-sheet instance ${t}; edit ${n??`its sheet file`} instead`}var _v=(e,t)=>e.x===t.x&&e.y===t.y,vv=(e,t,n)=>(t.x-e.x)*(n.y-e.y)-(t.y-e.y)*(n.x-e.x);function yv(e,t,n,r){let[i,a,o,s]=[vv(n,r,e),vv(n,r,t),vv(e,t,n),vv(e,t,r)];if((i>0&&a<0||i<0&&a>0)&&(o>0&&s<0||o<0&&s>0))return!0;let c=(e,t,n)=>Math.min(e.x,t.x)<=n.x&&n.x<=Math.max(e.x,t.x)&&Math.min(e.y,t.y)<=n.y&&n.y<=Math.max(e.y,t.y);return i===0&&c(n,r,e)||a===0&&c(n,r,t)||o===0&&c(e,t,n)||s===0&&c(e,t,r)}function bv(e){let t=e.length;if(t<3)return`an outline needs at least 3 corners`;if(e.some((n,r)=>_v(n,e[(r+1)%t])))return`two corners in a row are at the same place`;for(let n=0;n<t;n++)for(let r=n+1;r<t;r++){if(r===n+1||n===0&&r===t-1)continue;let[i,a,o,s]=[e[n],e[(n+1)%t],e[r],e[(r+1)%t]];if(yv(i,a,o,s))return`two of its edges cross`}let n=e.reduce((n,r,i)=>n+vv({x:0,y:0},r,e[(i+1)%t]),0);return Math.abs(n)<1e-9?`its corners are all on one line, so it has no area`:void 0}function xv(e,t){return`${t}:${e.filter(e=>e.tag===t).length+1}`}var Sv=3.2,Cv=100,wv=e=>({tool:e,points:[]}),Tv=(e,t)=>e.x===t.x&&e.y===t.y,Ev=e=>({state:e});function Dv(e){return e.filter((t,n)=>n===0||!Tv(t,e[n-1]))}function Ov(e){let t=Dv(e.points);if(t.length>=3&&t.at(-1)&&Tv(t[0],t.at(-1))&&t.pop(),t.length<3)return Ev(e);let n=bv(t);return n?{state:e,refused:`Not closed: ${n}`}:{state:wv(e.tool),outline:t}}function kv(e,t,n){if(e.tool===`hole`)return{state:e,hole:t};if(n&&e.points.length>0)return Ov(e);let r=e.points[0];return r&&e.points.length>=3&&Tv(r,t)?Ov(e):Ev({...e,points:Dv([...e.points,t])})}function Av(e,t){switch(t.type){case`press`:return kv(e,t.at,t.double);case`finish`:return e.tool===`pour`?Ov(e):Ev(e);case`removeCorner`:return Ev({...e,points:e.points.slice(0,-1)});case`cancel`:return{state:e.points.length>0?wv(e.tool):null}}}function jv(e,t){return!e||e.tool!==`pour`||e.points.length===0?[]:t?Dv([...e.points,t]):[...e.points]}function Mv(e){let t=e.circuit.nets.flatMap(e=>e.names);return t.includes(`GND`)?`GND`:t[0]}function Nv(e,t,n){return{kind:`addPour`,net:e,layer:t,...n?{outline:[...n]}:{}}}var Pv=(e,t,n)=>`add a ${e} copper pour on the ${t} layer${n?` over the whole board`:``}`;function Fv(e,t){return{kind:`addHole`,x:e.x,y:e.y,diameter:t}}var Iv=e=>`add a ${e} mm hole`;function Lv(e){let t=Number(e.trim().replace(/\s*mm$/i,``));return e.trim()===``||!Number.isFinite(t)||t<=0||t>Cv?{message:`The diameter must be a number of mm above 0 and at most ${Cv}`}:Math.round(t*1e3)/1e3}function Rv(e,t,n,r){let i=t.map((e,t)=>t===n?{x:r.x,y:r.y}:{x:e.x,y:e.y}),a=bv(i);return a?{message:`Not moved: the outline would not be a simple polygon (${a})`}:{edit:{kind:`setPour`,id:e,props:{outline:i}},summary:`move a corner of ${e}`}}function zv(e,t,n){let r=mv(n);if(r!==void 0)return gv(n,r,lm({parts:e.parts??[],imports:e.imports??[]},r));let i=e.boardItems?.find(e=>e.id===n);return i?t.has(n)?`${n} is locked`:i.editable?null:`${n} is read-only (${i.readonlyReason})`:`${n} is not in the code yet`}var Bv=e=>Number(e.slice(e.indexOf(`:`)+1)),Vv=e=>e.tag===`hole`?`hole ${Bv(e.id)}`:`copper pour ${Bv(e.id)}`;function Hv(e,t){return n=>{let r=n.map(n=>({id:n,blocker:zv(e,t,n)})),i=r.flatMap(e=>e.blocker===null?[e.id]:[]);return{edits:[...i].sort((e,t)=>Bv(t)-Bv(e)).map(e=>hv(e)?{kind:`removeHole`,id:e}:{kind:`removePour`,id:e}),names:i.flatMap(t=>e.boardItems?.find(e=>e.id===t)??[]).map(Vv),skipped:r.flatMap(e=>e.blocker??[]),removed:i}}}var Uv=`Esc or a right click stops.`;function Wv(e){if(e)return e.tool===`hole`?`Click where the hole goes; set its diameter in the field. ${Uv}`:e.points.length===0?`Click the first corner of the copper pour. ${Uv}`:`Click for each corner; double click, Enter or a click on the first corner closes the pour. Backspace removes a corner, Esc cancels.`}var Gv=[{value:`top`,label:`Top Layer`},{value:`bottom`,label:`Bottom Layer`}],Kv=[{value:`inner1`,label:`Inner Layer 1`},{value:`inner2`,label:`Inner Layer 2`}],qv=[{value:`relief`,label:`Relief (spokes)`},{value:`solid`,label:`Solid`}],Jv=e=>String(Number(e.toFixed(4))),Yv=e=>e===void 0?`Not filled`:`${e.toFixed(2)} mm²`;function Xv(e,t){let n=e.circuit.nets.flatMap(e=>e.names[0]?[{value:e.names[0],label:e.names[0]}]:[]),r=e.pcb.pours.find(e=>e.id===t.id);return[{label:`Net`,value:hl(e,t.net),field:`net`,choices:n},{label:`Layer`,value:t.layer,field:`layer`,choices:e.pcb.board?.layers===4?[...Gv,...Kv]:Gv},{label:`Priority`,value:String(t.priority),field:`priority`},{label:`Clearance (mm)`,value:t.clearance===void 0?``:Jv(t.clearance),field:`clearance`},{label:`Min width (mm)`,value:Jv(t.minWidth),field:`minWidth`},{label:`Thermal`,value:t.thermal,field:`thermal`,choices:qv},{label:`Outline`,value:t.outline?`${t.outline.length} corners`:`Whole board`},{label:`Fill area`,value:Yv(r?.area)}]}function Zv(e){return[{label:`X (mm)`,value:Jv(e.x),field:`x`},{label:`Y (mm)`,value:Jv(e.y),field:`y`},{label:`Diameter (mm)`,value:Jv(e.diameter),field:`diameter`}]}function Qv(e,t){let n=pl(e).find(e=>e.id===t);if(n)return{kind:`pour`,title:`Copper pour`,rows:Xv(e,n)};let r=e.pcb.holes.find(e=>e.id===t);return r&&{kind:`hole`,title:`Hole`,rows:Zv(r)}}function $v(e,t,n){let r=Number(e.trim());return e.trim()===``||!Number.isFinite(r)?{message:`${t} must be a number`}:n===`whole`&&!Number.isInteger(r)?{message:`${t} must be a whole number`}:n===`positive`&&r<=0?{message:`${t} must be above 0`}:r}function ey(e,t){return e===`net`||e===`layer`||e===`thermal`?t:e===`clearance`&&t.trim()===``?null:$v(t,e,e===`priority`?`whole`:`positive`)}function ty(e,t){return e===`diameter`?Lv(t):$v(t,e,`any`)}function ny(e,t,n,r){let i=Qv(e,t)?.rows.find(e=>e.field===n);if(!i||i.value===r.trim())return;let a=hv(t),o=a?ty(n,r):ey(n,r);if(typeof o==`object`&&o)return o;let s=`set ${t} ${n}=${o===null?`the net class's`:o}`;return a?{edit:{kind:`setHole`,id:t,props:{[n]:o}},summary:s}:{edit:{kind:`setPour`,id:t,props:{[n]:o}},summary:s}}function ry(e,t){let n=hv(e)?`hole`:`copper pour`;return t.locked.has(e)?t.violated.has(e)?{command:`lock`,label:`Lock again`,pressed:!0,title:`Changed outside the editor: lock it again to accept the change`}:{command:`unlock`,label:`Locked`,pressed:!0,title:`Unlock this ${n}`}:{command:`lock`,label:`Lock`,pressed:!1,title:`Lock this ${n}, so the agent cannot change or remove it`}}function iy(e,t,n,r=new Set){return gt([...e.names,...e.board],t,n,r)}var ay=.5,oy=e=>Math.round(e*1e3)/1e3||0,sy=e=>e.pcb??{x:0,y:0,rotation:0};function cy(e,t,n){let r=[{x:e.minX,y:e.minY},{x:e.maxX,y:e.minY},{x:e.maxX,y:e.maxY},{x:e.minX,y:e.maxY}].map(e=>py(fy(e,t),n)),i=r.map(e=>e.x),a=r.map(e=>e.y);return{minX:Math.min(...i),maxX:Math.max(...i),minY:Math.min(...a),maxY:Math.max(...a)}}var ly=(e,t)=>e.minX<t.maxX&&t.minX<e.maxX&&e.minY<t.maxY&&t.minY<e.maxY;function uy(e,t,n,r){let i=[t,...n].filter(e=>!r(e.name)).map(e=>e.name);if(i.length>0)return`Place ${i.join(`, `)} on the board first (pcbX and pcbY on the instance), then replicate the layout.`;let a=gy(e,t);if(!a)return;let o=[t,...n].map(e=>({name:e.name,box:cy(a,sy(t),sy(e))}));for(let[e,t]of o.entries()){let n=o.slice(e+1).find(e=>ly(t.box,e.box));if(n)return`${t.name} and ${n.name} would overlap; place the instances apart first, then replicate the layout.`}}function dy(e,t){let n=t*Math.PI/180,[r,i]=Number.isInteger(t/90)?[[1,0],[0,1],[-1,0],[0,-1]][(t/90%4+4)%4]:[Math.cos(n),Math.sin(n)];return{x:e.x*r-e.y*i,y:e.x*i+e.y*r}}var fy=(e,t)=>dy({x:e.x-t.x,y:e.y-t.y},-t.rotation),py=(e,t)=>{let n=dy(e,t.rotation);return{x:oy(n.x+t.x),y:oy(n.y+t.y)}};function my(e,t){let n=un(e,t)?.pcb;return n!==void 0&&(n.x!==0||n.y!==0)}function hy(e,t){for(let n of t){let t=un(e,n)??un(e,dn(e,n)?.outer??``);if(t)return t}}function gy(e,t){let n=new Set(t.parts),r=e.pcb.parts.filter(e=>n.has(e.component)).flatMap(e=>e.courtyard);if(r.length===0)return;let i=r.map(e=>e.x),a=r.map(e=>e.y);return{minX:Math.min(...i)-ay,maxX:Math.max(...i)+ay,minY:Math.min(...a)-ay,maxY:Math.max(...a)+ay}}function _y(e,t,n=[]){if(t?.startsWith(`net.${e.path}/`))return!0;let r=new Set(e.parts);return n.length>0&&n.every(e=>r.has(e.split(`#`)[0]??``))}function vy(e,t,n,r,i=[]){if(n?.startsWith(`net.${t.path}/`))return!0;let a=new Set(t.parts);if(i.length>0&&i.every(e=>a.has(e.split(`#`)[0]??``)))return!0;let o=gy(e,t);return o!==void 0&&r.every(e=>e.x>=o.minX&&e.x<=o.maxX&&e.y>=o.minY&&e.y<=o.maxY)}function yy(e,t,n){let r=dn(e,t)?.localId;return e.circuit.components.find(e=>e.instance===n.path&&e.localId===r)?.id}function by(e,t,n,r){if(t===void 0)return;if(t.startsWith(`net.${n.path}/`))return`net.${r.path}/${t.slice(`net.${n.path}/`.length)}`;if(t.startsWith(`net:`)){let[n,i]=t.slice(4).split(`.`),a=n===void 0?void 0:yy(e,n,r);return a&&i?`net:${a}.${i}`:void 0}let i=t.replace(/^net\./,``),a=n.ports.find(e=>!e.bus&&e.net===i),o=a&&r.ports.find(e=>e.name===a.name);return o?`net.${o.net}`:t}function xy(e,t){let n=sy(t);return e.circuit.components.flatMap(r=>{if(r.instance!==t.path||r.localId===void 0||typeof r.props.pcbX==`number`&&typeof r.props.pcbY==`number`)return[];let i=e.pcb.parts.find(e=>e.component===r.id);if(!i)return[];let a=fy(i,n),o=((i.rotation-n.rotation)%360+360)%360,s={pcbX:oy(a.x),pcbY:oy(a.y),...o===0?{}:{pcbRotation:oy(o)}};return[{kind:`setProps`,part:r.localId,props:s}]})}function Sy(e,t,n,r){let i=t.tracks.filter(t=>vy(e,n,t.net,t.points,t.pads)),a=t.vias.filter(t=>vy(e,n,t.net,[t.at])),o=sy(n);return r.flatMap(r=>{let s=sy(r),c=e=>py(fy(e,o),s),l=t=>{let i=by(e,t,n,r);return i===void 0?{}:{net:i}},u=[...t.tracks.filter(e=>_y(r,e.net,e.pads)).map(e=>({kind:`removeTrack`,id:e.id})),...t.vias.filter(e=>_y(r,e.net)).map(e=>({kind:`removeVia`,id:e.id}))],d=[...i.map(e=>({kind:`addTrack`,...l(e.net),layer:e.layer,width:e.width,points:e.points.map(c)})),...a.map(e=>({kind:`addVia`,...l(e.net),at:c(e.at),drill:e.drill,diameter:e.diameter,layers:[...e.layers]}))];return[...u,...d]})}function Cy(e,t,n){let r=t.filter(e=>n.has(e.name)||n.has(e.path)).map(e=>e.name);if(r.length===0)return;let[i,a]=r.length===1?[`is`,`it`]:[`are`,`them`];return`${r.join(`, `)} ${i} locked; unlock ${a} to replicate the layout of ${e.name} to ${a}.`}function wy(e,t,n,r=new Set){if(!e)return{message:`Wait for the build to finish, then try again.`};let i=hy(e,t);if(!i)return{message:`Select a part of the instance whose layout to copy, or its symbol on the schematic.`};let a=(e.circuit.instances??[]).filter(e=>e.file===i.file&&e.path!==i.path&&!e.path.includes(`/`));if(a.length===0)return{message:`${i.name} is the only instance of ${i.sheet}; there is nothing to copy its layout to.`};let o=Cy(i,a,r);if(o)return{message:o};let s=uy(e,i,a,n??(t=>my(e,t)));if(s)return{message:s};let c=a.map(e=>e.name).join(`, `),l={file:i.file,edits:xy(e,i),summary:`Replicate the placement of ${i.name} in ${i.sheet}`},u={edits:Sy(e,e.pcb,i,a),summary:`Replicate the copper of ${i.name} to ${c}`};return l.edits.length===0&&u.edits.length===0?{message:`${i.name} has no placement or copper the other instances lack.`}:{source:i.name,targets:a.map(e=>e.name),sheet:l,layout:u}}var Ty={toggleUnit:`toggleUnit`,gridStyle:`toggleGridStyle`,snap:`toggleSnap`,toggleLeftPanel:`toggleLeftPanel`,toggleRightPanel:`toggleRightPanel`,toggleBottomPanel:`toggleBottomPanel`,clearHighlight:`clearHighlight`,placeComponent:`openLibrary`};[...g];var Ey=[`wire`,`netLabel`,`groundFlag`,`powerFlag`,...x],Dy=[`noConnect`,`junction`],Oy=[`singleRouting`,`placeVia`,`routingCorner`],ky=[`placePour`,`placePourBoard`,`placeHole`],Ay=[`filletTracks`,`straightenTracks`],jy=new Set;function My(e){return jy.add(e),()=>{jy.delete(e)}}function Ny(e){for(let t of jy)if(t(e))return!0;return!1}function Py(e){let t=(0,l.useRef)(e);t.current=e,(0,l.useEffect)(()=>My(e=>{let n=t.current[e];return n?(n(),!0):!1}),[])}var Fy=(e,t)=>e.by===`router`&&!e.locked&&(t===void 0||t.has(e.id)),Iy=1e-6;function Ly(e,t,n){let[r,i]=[n.x-t.x,n.y-t.y],a=r*r+i*i,o=a===0?0:Math.max(0,Math.min(1,((e.x-t.x)*r+(e.y-t.y)*i)/a));return Math.hypot(e.x-(t.x+o*r),e.y-(t.y+o*i))}function Ry(e,t){if(t.at===void 0||t.diameter===void 0)return!1;let n=t.diameter/2+(e.width??0)/2+Iy,r=t.at;return e.points.length===1?Math.hypot(e.points[0].x-r.x,e.points[0].y-r.y)<=n:e.points.some((t,i)=>i>0&&Ly(r,e.points[i-1],t)<=n)}function zy(e,t={}){let n=t.ids===void 0?void 0:new Set(t.ids),r=[],i=e.tracks.filter(e=>{if(!Fy(e,n))return!1;let i=t.lockedPart?.(e);return i!==void 0&&r.push(`${e.id} starts on the locked part ${i}`),i===void 0}),a=e.tracks.filter(e=>e.by!==`router`),o=[],s=e.vias.filter(e=>{if(!Fy(e,n))return!1;let t=a.some(t=>Ry(t,e));return t&&o.push(e.id),!t});return{edits:[...i.map(e=>({kind:`removeTrack`,id:e.id})),...s.map(e=>({kind:`removeVia`,id:e.id}))],skipped:r,kept:o}}var By=[`top`,`bottom`,`inner1`,`inner2`],Vy=Math.PI/180,Hy=1e-12;function Uy(e,t){let n=Math.cos(t.rotation*Vy),r=Math.sin(t.rotation*Vy);return{x:t.x+e.x*n-e.y*r,y:t.y+e.x*r+e.y*n}}function Wy(e,t,n){return t<=Hy&&n<=Hy?[Uy({x:0,y:0},e)]:n<=Hy?[Uy({x:-t,y:0},e),Uy({x:t,y:0},e)]:t<=Hy?[Uy({x:0,y:-n},e),Uy({x:0,y:n},e)]:[{x:-t,y:-n},{x:t,y:-n},{x:t,y:n},{x:-t,y:n}].map(t=>Uy(t,e))}function Gy(e,t,n){let r=Math.min(t,n),i=(Math.max(t,n)-r)/2;return{core:t>=n?Wy(e,i,0):Wy(e,0,i),radius:r/2}}function Ky(e){switch(e.shape){case`rect`:return{core:Wy(e,e.width/2,e.height/2),radius:0};case`roundrect`:{let t=Math.min(Math.max(e.cornerRadius??0,0),e.width/2,e.height/2);return{core:Wy(e,e.width/2-t,e.height/2-t),radius:t}}case`circle`:return{core:[Uy({x:0,y:0},e)],radius:e.width/2};case`oval`:return Gy(e,e.width,e.height);default:return}}function qy(e,t){return{x:e.x-t.x,y:e.y-t.y}}function Jy(e,t){return e.x*t.y-e.y*t.x}function Yy(e,t,n){let r=qy(n,t),i=r.x*r.x+r.y*r.y,a=i===0?0:Math.max(0,Math.min(1,((e.x-t.x)*r.x+(e.y-t.y)*r.y)/i)),o={x:t.x+r.x*a,y:t.y+r.y*a};return{distance:Math.hypot(e.x-o.x,e.y-o.y),at:o}}function Xy(e,t,n,r){let i=qy(t,e),a=qy(r,n),o=Jy(i,a);if(o===0)return;let s=Jy(qy(n,e),a)/o,c=Jy(qy(n,e),i)/o;if(!(s<0||s>1||c<0||c>1))return{x:e.x+i.x*s,y:e.y+i.y*s}}function Zy(e,t,n,r){let i=Xy(e,t,n,r);if(i!==void 0)return{distance:0,from:i,to:i};let a=[];for(let i of[e,t]){let e=Yy(i,n,r);a.push({distance:e.distance,from:i,to:e.at})}for(let i of[n,r]){let n=Yy(i,e,t);a.push({distance:n.distance,from:n.at,to:i})}return a.reduce((e,t)=>t.distance<e.distance?t:e)}function Qy(e){return e.length===1?[[e[0],e[0]]]:e.length===2?[[e[0],e[1]]]:e.map((t,n)=>[t,e[(n+1)%e.length]])}function $y(e,t){let n=!1;for(let r=0,i=t.length-1;r<t.length;i=r++){let a=t[r],o=t[i];a.y>e.y!=o.y>e.y&&e.x<(o.x-a.x)*(e.y-a.y)/(o.y-a.y)+a.x&&(n=!n)}return n}function eb(e,t){if(!(e.length<3))return t.find(t=>$y(t,e))}function tb(e,t){let n=eb(e,t)??eb(t,e);if(n!==void 0)return{distance:0,from:n,to:n};let r;for(let[n,i]of Qy(e))for(let[e,a]of Qy(t)){let t=Zy(n,i,e,a);(r===void 0||t.distance<r.distance)&&(r=t)}return r}function nb(e,t){return tb(e.core,t.core).distance-e.radius-t.radius}function rb(e,t,n){let r=Math.hypot(t.x-e.x,t.y-e.y);return r===0?e:{x:e.x+(t.x-e.x)/r*n,y:e.y+(t.y-e.y)/r*n}}function ib(e,t){let{from:n,to:r}=tb(e.core,t.core);return[rb(n,r,e.radius),rb(r,n,t.radius)]}function ab(e){let t=e.core.map(e=>e.x),n=e.core.map(e=>e.y);return{minX:Math.min(...t)-e.radius,minY:Math.min(...n)-e.radius,maxX:Math.max(...t)+e.radius,maxY:Math.max(...n)+e.radius}}var ob=({x0:e,x1:t,y0:n,y1:r})=>Math.max(0,t-e+1)*Math.max(0,r-n+1),sb=class{cell;cells=new Map;wide=[];constructor(e){if(this.cell=e,!(e>0))throw Error(`Grid cell size must be positive, got ${e}`)}insert(e,t){let n=this.rangeOf(t);ob(n)>4096?this.wide.push(e):cb(n,t=>{let n=this.cells.get(t);n===void 0?this.cells.set(t,[e]):n.push(e)})}query(e){let t=this.rangeOf(e),n=new Set(this.wide),r=e=>e?.forEach(e=>n.add(e));return ob(t)>4096?this.cells.forEach(r):cb(t,e=>r(this.cells.get(e))),[...n]}rangeOf(e){if(![e.minX,e.minY,e.maxX,e.maxY].every(Number.isFinite))throw Error(`Grid box must have finite bounds, got ${JSON.stringify(e)}`);let t=e=>Math.floor(e/this.cell);return{x0:t(e.minX),x1:t(e.maxX),y0:t(e.minY),y1:t(e.maxY)}}};function cb({x0:e,x1:t,y0:n,y1:r},i){for(let a=e;a<=t;a++)for(let e=n;e<=r;e++)i(`${a},${e}`)}var lb=[`top`,`inner1`,`inner2`,`bottom`],ub=1e-9,db=(e,t)=>e.layers===`through`||e.layers===t,fb=e=>({core:[e],radius:0});function pb(e){return e.reduce((t,n,r)=>r===0?0:t+Math.hypot(n.x-(e[r-1]?.x??n.x),n.y-(e[r-1]?.y??n.y)),0)}function mb(e){let t=e.layers.map(e=>lb.indexOf(e));return new Set(lb.slice(Math.min(...t),Math.max(...t)+1))}function hb(e,t,n){return t!==void 0&&nb(t,fb(n))<=ub}function gb(e,t,n){return e.flatMap(e=>e.pads.filter(e=>db(e,n)&&hb(e,Ky(e),t)))}function _b(e,t){return nb(e,t)<=ub}function vb(e,t){if(t.length===0)return{message:`Select parts, or a sub-sheet instance, to route their connections.`};let n=t.length===1?un(e,t[0]):void 0;if(n)return{kind:`instance`,instance:n.path};let r=new Set(t.map(t=>dn(e,t)?.outer)),[i]=r;if(r.size===1&&i!==void 0){let n=fn(e,i);if(n.length===t.length&&n.every(e=>t.includes(e)))return{kind:`instance`,instance:i}}return{kind:`parts`,parts:[...t]}}function yb(e){return e.length===0?{message:`Click a net in the Nets panel to highlight it, then Autoroute net.`}:{kind:`nets`,nets:[...e]}}function bb(e,t,n=new Set){if(!e)return{message:`Wait for the build to finish, then try again.`};let r=_n(n,e),i=t=>{let n=t.points[0];return n===void 0?void 0:gb(e.pcb.parts,n,t.layer).find(e=>r.has(e.component))?.component},a=t.length===0?void 0:t,{edits:o,skipped:s}=zy(e.pcb,{...a?{ids:a}:{},lockedPart:i});if(o.length>0)return a?{ids:[...a]}:{};let c=a?`None of the selected copper was made by the router and unlocked; Unroute removes only that`:`The board has no unlocked router copper to remove`;return{message:s.length===0?`${c}.`:`${c}: ${s.join(`; `)}.`}}function xb(e,t){if(t.length===0)return{message:`Select the parts to place first.`};let n=t.flatMap(t=>un(e,t)?.parts??[t]);return{kind:`parts`,parts:[...new Set(n)]}}function Sb(e,t){for(let n of t){let t=un(e,n)?.path??dn(e,n)?.outer;if(t!==void 0)return{kind:`instance`,instance:t}}return{message:`Select a part of a sub-sheet instance, or its symbol on the schematic, to place that instance.`}}function Cb(e,t,n){let r=e.ask(t,n)?.trim();return r===void 0||r===``?void 0:r}async function wb(e){let t=Cb(e,`Name of the new page`,Tg(Sg(e.design)));t!==void 0&&await e.edit([{kind:`addPage`,name:t}],`add page ${t}`)&&e.openPage(t)}async function Tb(e){let t=Dg(e.page);if(t)return e.notify(t);let n=Cb(e,`New name for page ${e.page}`,e.page);n!==void 0&&n!==e.page&&await e.edit([{kind:`renamePage`,from:e.page,to:n}],`rename page ${e.page} to ${n}`)&&e.openPage(n)}async function Eb(e){let t=Eg(e.design,e.page);if(t)return e.notify(t);let n=Sg(e.design).indexOf(e.page),r=Sg(e.design)[Math.max(0,n-1)]??`Main`;await e.edit([{kind:`removePage`,name:e.page}],`delete page ${e.page}`)&&e.openPage(r)}function Db(e,t){return e===`addPage`?wb(t):e===`renamePage`?Tb(t):Eb(t)}function Ob(e,t){return t===`Main`?[...e]:e.map(e=>(e.kind===`addPart`||e.kind===`addDrawing`||e.kind===`addTrace`)&&e.page===void 0?{...e,page:t}:e)}function kb(e){let t=an(e),n=`strokeWidth`in e?e.strokeWidth/2:0;return{minX:t.minX-n,minY:t.minY-n,maxX:t.maxX+n,maxY:t.maxY+n}}function Ab(e){let t=[...Xo(e).map(e=>e.box),...Hu(e).map(e=>e.box)];t.push(...e.labels.map(xr),...e.drawings.map(kb));let n=xe([...e.wires.flatMap(e=>e.points),...e.junctions]);return n&&t.push(n),Se(t)}var jb=()=>da(`light`).background,Mb={width:297,height:210,margin:10};function Nb(){return{width:(Mb.width-2*Mb.margin)*8,height:(Mb.height-2*Mb.margin-Pb)*8}}var Pb=8;function Fb(e){return e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`).replace(/'/g,`&#39;`)}function Ib(e){let t={width:Mb.width-2*Mb.margin,height:Mb.height-2*Mb.margin},n={width:t.width,height:t.height-Pb};return[`<svg xmlns="http://www.w3.org/2000/svg" width="${t.width}mm" height="${t.height}mm" viewBox="0 0 ${t.width} ${t.height}">`,`<text x="0" y="5" font-size="4" font-family="Arial, sans-serif">${Fb(e.title)}</text>`,`<image x="0" y="${Pb}" width="${n.width}" height="${n.height}" preserveAspectRatio="xMidYMid meet" href="${Fb(e.image)}" />`,`<rect x="0" y="${Pb}" width="${n.width}" height="${n.height}" fill="none" stroke="currentColor" stroke-width="0.2" />`,`</svg>`].join(``)}function Lb(e,t){let n=t.map(e=>`<section class="sheet">${Ib(e)}</section>`).join(``);return[`<!doctype html>`,`<html><head><meta charset="utf-8"><title>${Fb(e)}</title>`,`<style>`,`@page { size: A4 landscape; margin: ${Mb.margin}mm }`,`html, body { margin: 0; background: Canvas; color: CanvasText; color-scheme: light }`,`.sheet { break-after: page; page-break-after: always }`,`.sheet:last-child { break-after: auto; page-break-after: auto }`,`</style></head><body>`,n,`</body></html>`].join(``)}var Rb=.04;function zb(e,t){let n=document.createElement(`canvas`);n.width=e.width,n.height=e.height;let r=n.getContext(`2d`);if(r)return r.fillStyle=t,r.fillRect(0,0,e.width,e.height),{canvas:n,ctx:r}}function Bb(e,t,n){let r=wg(e,t).schematic,i=Ab(r),a=da(`light`),o=i&&zb(n,a.background);if(i&&o)return pa(a),Yo(o.ctx,r,{camera:me(i,n,Rb),size:n},{ratio:1}),o.canvas.toDataURL(`image/png`)}function Vb(e,t){let n=e.pcb,r=xe(n.board?.outline??[])??Se(n.parts.map(e=>({minX:e.x-1,minY:e.y-1,maxX:e.x+1,maxY:e.y+1}))),i=r&&zb(t,jb());if(!r||!i)return;let a=me(r,t,Rb);return wd(i.ctx,n,{camera:a,size:t},{ratio:1,copper:{tracks:n.tracks,vias:n.vias,selected:new Set}}),i.canvas.toDataURL(`image/png`)}function Hb(e,t,n=Pg(document.documentElement.getAttribute(`data-theme`))){let r=Nb(),i=[];try{for(let n of Sg(e)){let a=Bb(e,n,r);a&&i.push({title:`${t} · Schematic · ${n}`,image:a,...r})}}finally{pa(da(n))}let a=Vb(e,r);return a&&i.push({title:`${t} · PCB`,image:a,...r}),i}function Ub(e,t){let n=window.open(``,`_blank`);return n?(n.document.open(),n.document.write(Lb(e,t)),n.document.close(),n.focus(),n.setTimeout(()=>n.print(),0),!0):!1}var Wb=12.7,Gb=e=>Math.round(e*1e3)/1e3+0;function Kb(e,t,n){let r=t.find(t=>t.name===e);return r?n.has(e)?`locked`:r.editable?void 0:`read-only`:`inside a sub-sheet; change it in its sheet`}function qb(e,t,n){let r=[],i=[];for(let a of e){let e=Kb(a,t,n);e===void 0?r.push(a):i.push(`${a} (${e})`)}return{ok:r,skipped:i}}var Jb=e=>e.length===0?``:`; left ${e.join(`, `)}`;function Yb(e,t,n,r){let i=e.filter(e=>t.some(t=>t.component===e));if(i.length===0)return{message:`Select a part on the PCB to flip.`};let{ok:a,skipped:o}=qb(i,n,r);if(a.length===0)return{message:`Cannot flip ${o.join(`, `)}.`};let s=a.map(e=>{let r=t.find(t=>t.component===e),i=n.find(t=>t.name===e)?.props??{},a=i.pcbX||i.pcbY?{}:{pcbX:Gb(r.x),pcbY:Gb(r.y)};return{kind:`setProps`,part:e,props:{layer:r.side===`bottom`?`top`:`bottom`,...a}}}),c=new Set(a.map(e=>t.find(t=>t.component===e)?.side)),l=c.size===1?c.has(`bottom`)?` to the top`:` to the bottom`:``;return{edits:s,summary:`flip ${a.join(`, `)}${l}${Jb(o)}`,skipped:o}}var Xb=e=>({x:e.reduce((e,t)=>e+t.x,0)/e.length,y:e.reduce((e,t)=>e+t.y,0)/e.length});function Zb(e){let t=[...new Set(e.map(e=>e.page??0))].sort((e,t)=>e-t),n=new Map,r=0;for(let i of t){let t=e.filter(e=>(e.page??0)===i),a=Math.min(...t.map(e=>e.x)),o=Math.max(...t.map(e=>e.x)),s=Xb(t).y;for(let e of t)n.set(e.component,{x:r+(e.x-a)*Wb,y:(e.y-s)*Wb});r+=(o-a)*Wb+10}let i=Xb([...n.values()]);return new Map([...n].map(([e,t])=>[e,{x:t.x-i.x,y:t.y-i.y}]))}function Qb(e,t,n,r,i){let a=e.filter(e=>t.some(t=>t.component===e)&&n.some(t=>t.component===e));if(a.length===0)return{message:`No part is on both the schematic and the PCB.`};let{ok:o,skipped:s}=qb(a,r,i);if(o.length===0)return{message:`${s.join(`, `)} cannot move: locked or read-only.`};let c=o.map(e=>t.find(t=>t.component===e)),l=Zb(c),u=Xb(o.map(e=>n.find(t=>t.component===e)));return{edits:c.map(e=>{let t=l.get(e.component),n=e.rotation===void 0?{}:{pcbRotation:e.rotation};return{kind:`setProps`,part:e.component,props:{pcbX:Gb(u.x+t.x),pcbY:Gb(u.y+t.y),...n}}}),summary:`place ${o.length===1?o[0]:`${o.length} parts`} as on the schematic${Jb(s)}`,skipped:s}}var $b=(e,t)=>e.kind===t.kind&&e.footprint===t.footprint&&e.value===t.value;function ex(e,t,n,r){let i=t.find(t=>t.id===e.parts[0]);if(i){let e=t.filter(e=>$b(e,i)).map(e=>e.id),n=[i.kind,i.value,i.footprint].filter(e=>e!==void 0&&e!==``).join(`, `);return{parts:e,drawings:[],note:`Selected ${e.length} ${e.length===1?`part`:`parts`} like ${i.id} (${n})`}}let a=n.find(t=>t.id===e.drawings[0]);if(a){let e=n.filter(e=>e.kind===a.kind).map(e=>e.id);return{parts:[],drawings:e,note:`Selected ${e.length} ${a.kind} ${e.length===1?`drawing`:`drawings`}`}}let o=e.board?.[0];if(o!==void 0){let e=o.split(`:`)[0]??o,t=(r??[]).filter(t=>t.split(`:`)[0]===e);return{parts:[],drawings:[],board:t,note:`Selected ${t.length} ${e===`copperpour`?`copper pour`:e}${t.length===1?``:`s`}`}}return{message:`Select a part, a drawing, a pour or a hole first; Find similar objects selects the ones like it.`}}var tx=/^([A-Za-z_]+)(\d+)$/;function nx(e,t){return!e.at||!t.at?e.at?-1:t.at?1:e.name.localeCompare(t.name):e.at.page-t.at.page||t.at.y-e.at.y||e.at.x-t.at.x||e.name.localeCompare(t.name)}function rx(e,t){let n=new Set(t.filter(e=>!e.renamable).map(e=>Number(tx.exec(e.name)?.[2]))),r=1;return[...t].filter(e=>e.renamable).sort(nx).map(t=>{for(;n.has(r);)r++;return{from:t.name,to:`${e}${r++}`}})}function ix(e){let t=new Map;for(let n of e){let e=tx.exec(n.name)?.[1];e!==void 0&&t.set(e,[...t.get(e)??[],n])}let n=[...t].flatMap(([e,t])=>rx(e,t)).filter(e=>e.from!==e.to);if(n.length===0)return{message:`Every designator is already numbered in order.`};let r=n.slice(0,4).map(e=>`${e.from} → ${e.to}`).join(`, `);return{edit:{kind:`renameParts`,mapping:n},summary:`annotate designators: ${r}${n.length>4?` and ${n.length-4} more`:``}`}}var ax={sch:.5,pcb:2.54},ox=new Set([`name`,`pinLabels`]),sx=new Set([`from`,`to`,`schematicRouteHints`]),cx=/(pin\d+)\s*:\s*["']([A-Za-z_][\w]*)["']/g;function lx(e){if(!e)return;let t=Object.fromEntries([...e.matchAll(cx)].map(e=>[e[1],e[2]]));return Object.keys(t).length>0?t:void 0}function ux(e){let t=e===void 0?void 0:Bt(e);return t?t.kind===`net`?void 0:t.part:null}var dx=e=>e.slice(0,e.lastIndexOf(`/`)+1);function fx(e,t,n=``){let r=e.parts.filter(e=>t.includes(e.name)),i=r.filter(t=>e.imports.some(e=>e.local===t.tag&&/\.sheet(\.tsx)?$/.test(e.source))),a=r.filter(e=>!i.includes(e));if(a.length===0)return{message:i.length>0?`Sub-sheet instances are not copied; make another instance from the sheet instead.`:`Select the parts to copy first.`};let o=[],s=a.map(t=>{let n={};for(let[e,r]of Object.entries(t.props))ox.has(e)||(r.literal===void 0?o.push(`${t.name}.${e}`):n[e]=r.literal);let r=lx(t.props.pinLabels?.source);t.props.pinLabels&&!r&&o.push(`${t.name}.pinLabels`);let i=e.imports.find(e=>e.local===t.tag)?.source;return{tag:t.tag,name:t.name,props:n,...r?{pinLabels:r}:{},...i?{importFrom:i}:{}}});o.push(...i.map(e=>`${e.name} (a sub-sheet instance)`));let c=new Set(a.map(e=>e.name));return{parts:s,traces:e.traces.flatMap(e=>{let t=[ux(e.from),ux(e.to)];if(t.some(e=>e===null))return[];let n=t.filter(e=>typeof e==`string`);if(n.length===0||n.some(e=>!c.has(e)))return[];let r=Object.fromEntries(Object.entries(e.props).flatMap(([e,t])=>sx.has(e)||t.literal===void 0?[]:[[e,t.literal]]));return[{from:e.from,to:e.to,props:r,...e.schematicRouteHints?{hints:e.schematicRouteHints}:{}}]}),left:o,folder:dx(n),anchor:mx(s)}}var px=(e,t)=>t===void 0?void 0:e.startsWith(`pcb`)?jh(t):typeof t==`number`?t:void 0;function mx(e){let t=(t,n)=>{let r=e.flatMap(e=>{let[r,i]=[px(t,e.props[t]),px(n,e.props[n])];return r===void 0||i===void 0?[]:[{x:r,y:i}]});return r.length===0?void 0:{x:r.reduce((e,t)=>e+t.x,0)/r.length,y:r.reduce((e,t)=>e+t.y,0)/r.length}},n=t(`schX`,`schY`),r=t(`pcbX`,`pcbY`);return{...n?{sch:n}:{},...r?{pcb:r}:{}}}var hx=/^([A-Za-z_]+?)(\d+)$/;function gx(e,t){let n=new Set(t),r=new Map;for(let t of e){let e=hx.exec(t)?.[1]??`${t}_`,i=1;for(;n.has(`${e}${i}`);)i++;let a=`${e}${i}`;n.add(a),r.set(t,a)}return r}var _x=e=>Math.round(e*1e4)/1e4+0;function vx(e,t,n){let r=e=>({x:e*n,y:-e*n}),i={sch:r(ax.sch),pcb:r(ax.pcb)},a=t?e.anchor[t.view]:void 0;return!t||!a?i:{...i,[t.view]:{x:_x(t.at.x-a.x),y:_x(t.at.y-a.y)}}}function yx(e,t,n){let r=e===`schX`?n.sch.x:e===`schY`?n.sch.y:e===`pcbX`?n.pcb.x:e===`pcbY`?n.pcb.y:void 0;if(r===void 0)return t;let i=px(e,t);return i===void 0?t:_x(i+r)}function bx(e,t){let n=Bt(e);return n?.kind===`pin`?`${t.get(n.part)??n.part}.${n.pin}`:e}function xx(e,t,n,r){if(!e.importFrom)return;let i=r.imports.find(t=>t.local===e.tag);return i?i.source===e.importFrom?void 0:{message:`${e.tag} is imported from "${i.source}" here, not "${e.importFrom}"; paste into a file that imports it the same way`}:dx(n.file??``)===t.folder?e.importFrom:{message:`${e.name} needs "${e.importFrom}", which is relative to another folder; paste it into a circuit in that folder, or add the import first`}}function Sx(e,t,n={}){let r=[...t.parts.map(e=>e.name),...t.drawings.flatMap(e=>[e.id,e.name??``]),...n.taken??[]],i=gx(e.parts.map(e=>e.name),r),a=n.page,o=a===void 0||a===`Main`?{}:{page:a},s=n.shift??vx(e,void 0,1),c=[];for(let r of e.parts){let a=xx(r,e,n,t);if(typeof a==`object`)return a;c.push({kind:`addPart`,tag:r.tag,name:i.get(r.name),props:Object.fromEntries(Object.entries(r.props).map(([e,t])=>[e,yx(e,t,s)])),...r.pinLabels?{pinLabels:r.pinLabels}:{},...a?{importFrom:a}:{},...o})}let l=e.traces.map(e=>({kind:`addTrace`,from:bx(e.from,i),to:bx(e.to,i),...Object.keys(e.props).length>0?{props:e.props}:{},...e.hints?{schematicRouteHints:e.hints.map(e=>({x:_x(e.x+s.sch.x),y:_x(e.y+s.sch.y)}))}:{},...o})),u=[...i.values()];return{edits:[...c,...l],summary:`paste ${u.length===1?u[0]:`${u.length} parts (${u.join(`, `)})`}`,names:u}}var Cx={};function wx(e,t){t?Cx[e]=t:delete Cx[e]}function Tx(e){return Cx[e]}var Ex=e=>new Set(e?.annotations.locks.filter(e=>!e.drawing).map(e=>e.part));function Dx(e,t){if(`message`in t)return e.notify(t.message);e.edit(t.edits,t.summary)}function Ox({design:e,circuit:t,selection:n,actions:r}){e&&t&&Dx(r,Yb(n.names,e.pcb.parts,t.model.parts,Ex(t)))}function kx({design:e,circuit:t,selection:n,actions:r}){if(!e||!t)return;let i=n.names.length>0?n.names:e.pcb.parts.map(e=>e.component),a=e.schematic.pages??[],o=e=>Math.max(0,a.findIndex(t=>t.parts.includes(e)));Dx(r,Qb(i,e.schematic.symbols.map(e=>({component:e.component,x:e.x,y:e.y,page:o(e.component),rotation:e.rotation})),e.pcb.parts,t.model.parts,Ex(t)))}function Ax({design:e,circuit:t,actions:n}){if(!e||!t)return;let r=Ex(t),i=e.schematic.pages??[],a=new Set(e.circuit.components.filter(e=>e.kind===`sheet`).map(e=>e.id)),o=t.model.parts.filter(e=>!a.has(e.name)).map(t=>{let n=e.schematic.symbols.find(e=>e.component===t.name),a=Math.max(0,i.findIndex(e=>e.parts.includes(t.name)));return{name:t.name,renamable:t.editable&&!r.has(t.name),...n?{at:{page:a,x:n.x,y:n.y}}:{}}}),s=new Set(t.model.parts.map(e=>e.name)),c=e.circuit.components.filter(e=>!s.has(e.id)&&e.kind!==`sheet`).map(e=>({name:e.id,renamable:!1})),l=ix([...o,...c]);if(`message`in l)return n.notify(l.message);n.renameParts(l.edit.mapping,l.summary).then(e=>e.ok&&n.notify(`Annotated ${l.edit.mapping.length} designators`))}var jx,Mx=0;function Nx({circuit:e,selection:t,actions:n}){if(!e)return;let r=fx(e.model,t.names,e.file);if(`message`in r)return n.notify(r.message);jx=r,Mx=0;let i=r.parts.length===1?r.parts[0]?.name??``:`${r.parts.length} parts`,a=r.traces.length>0?` and ${r.traces.length} ${r.traces.length===1?`trace`:`traces`}`:``,o=r.left.length>0?`; left out ${r.left.join(`, `)}`:``;n.notify(`Copied ${i}${a}${o}`)}function Px({design:e,circuit:t,select:n,actions:r},i,a){if(!t)return;if(!jx)return r.notify(`Copy some parts first (Ctrl+C).`);let o=Tx(a),s=vx(jx,o?{view:a,at:o}:void 0,Mx+1),c=new Set(t.model.parts.map(e=>e.name)),l=(e?.circuit.components??[]).map(e=>e.id).filter(e=>!c.has(e)),u=Sx(jx,t.model,{file:t.file,...i?{page:i}:{},taken:l,shift:s});if(`message`in u)return r.notify(u.message);Mx+=1;let{edits:d,summary:f,names:p}=u;r.edit(d,f).then(e=>{e&&(n(()=>Xi.none.all(p)),r.notify(`Pasted ${p.join(`, `)}`))})}function Fx({design:e,circuit:t,selection:n,select:r,actions:i}){if(!e)return;let a=e.circuit.components.map(e=>({id:e.id,kind:e.kind,...e.footprint?{footprint:e.footprint}:{},...e.value?{value:e.value}:{}})),o=(t?.model.boardItems??[]).map(e=>e.id),s=ex({parts:n.names,drawings:n.drawings,board:n.board},a,e.schematic.drawings,o);if(`message`in s)return i.notify(s.message);r(()=>Xi.none.all(s.parts).addDrawings(s.drawings).addBoard(s.board??[])),i.notify(s.note)}var Ix=new Set([...Ey,...Dy]),Lx=new Set([...Oy,...Ay,...ky]),Rx=e=>Ix.has(e)?`schematic`:Lx.has(e)?`pcb`:void 0,zx=Ty;function Bx(e,t){if(`message`in t)return e.actions.notify(t.message);e.actions.route(t)}function Vx(e,t){if(`message`in t)return e.actions.notify(t.message);e.actions.autoplace(t)}function Hx(e){let t=new Set(e.circuit?.annotations.locks.filter(e=>!e.drawing).map(e=>e.part)),n=bb(e.design,e.selection.copper,t);if(`message`in n)return e.actions.notify(n.message);e.actions.unroute(n.ids)}function Ux(e,t){let{design:n,page:r,actions:i,openPage:a}=e;Db(t,{design:n,page:r,edit:i.edit,notify:i.notify,ask:(e,t)=>window.prompt(e,t),openPage:a})}function Wx(e,t){e&&(t.notify(`Exporting the BOM and datasheets…`),R(`/api/package`,{file:e}).then(e=>t.notify(`Exported ${e.files.length} files to ${e.outDir}`)).catch(e=>t.notify(e.message)))}function Gx(e,t){let{design:n,file:r,actions:i}=e;if(!n||!r)return i.notify(`Wait for the build to finish, then try again.`);let a=Hb(n,r);if(a.length===0)return i.notify(`Nothing to print yet: the circuit has no parts.`);let o=r.replace(/\.circuit\.tsx$/,``);if(!Ub(o,a))return i.notify(`The browser blocked the print window; allow pop-ups for Studio and try again.`);i.notify(t?`Choose "Save as PDF" in the print dialog to save ${o}.pdf (${a.length} sheets)`:`Printing ${a.length} sheets`)}function Kx(e){if(e.file){if(N_(e.checkCounts))return e.openDialog(`exportChecks`);qx(e.file,e.actions)}}function qx(e,t){e&&(t.notify(`Writing the fabrication files…`),R(`/api/export`,{file:e}).then(e=>t.notify(M_(e))).catch(e=>t.notify(e.message)))}function Jx(e,t){e&&R(`/api/bom?file=${encodeURIComponent(e)}`).then(n=>{let r=URL.createObjectURL(new Blob([T_(n)],{type:`text/csv`}));Object.assign(document.createElement(`a`),{href:r,download:E_(e)}).click(),URL.revokeObjectURL(r),t.notify(`Saved ${E_(e)}`)}).catch(e=>t.notify(e.message))}function Yx(e,t){let{copper:n}=e.selection;if(n.length>0&&e.copperRecords){let r=fv(e.copperRecords,n,t);if(`message`in r?e.actions.notify(r.message):e.actions.editLayout(r.edits,r.summary),e.selection.size+e.selection.boardCount===0)return}Xx(e,t)}function Xx(e,t){let n=new Set(e.circuit?.annotations.locks.map(e=>e.part)),r=new Set(e.circuit?.violations.map(e=>e.part)),i=iy(e.selection,n,t,r);if(`message`in i)return e.actions.notify(i.message);e.actions.lock(i.parts,t)}function Zx(e){let t=hn(e.design,e.selection.names);if(!t)return e.actions.notify(`Select a part of a sub-sheet instance, or its symbol on the schematic, first.`);let n=e.view===`schematic`?e.selection.names.flatMap(t=>un(e.design,t)?.path??dn(e.design,t)?.outer??[]):t;e.select(e=>e.all([...new Set(n)]))}async function Qx(e){let t=t=>{let n=e.circuit?.model.parts.find(e=>e.name===t)?.props;return n?.pcbX!==void 0&&n.pcbY!==void 0},n=new Set(e.circuit?.annotations.locks.map(e=>e.part)),r=wy(e.design,e.selection.names,t,n);if(`message`in r)return e.actions.notify(r.message);let{sheet:i,layout:a}=r;(a.edits.length===0?await e.actions.editFile(i.file,i.edits,i.summary):await e.actions.editLayout(a.edits,i.edits.length===0?a.summary:`${a.summary} and its placement`,i.edits.length===0?void 0:{file:i.file,edits:i.edits})).ok&&e.actions.notify(`Copied the layout of ${r.source} to ${r.targets.join(`, `)}`)}function $x(e){let t=fm(e.circuit?.model,e.selection.names);if(`message`in t)return e.actions.notify(t.message);e.openDialog(`makeSheet`)}function eS(e,t){let n=zx[t];return n?()=>e.workspace.run(n):{openFile:e.workspace.openPageTree,exportBom:()=>Jx(e.file,e.actions),exportPackage:()=>Wx(e.file,e.actions),exportFabrication:()=>Kx(e),undo:()=>void e.actions.undo(),redo:()=>void e.actions.redo(),selectAll:()=>e.select(ki(e.circuit?.model.parts.map(e=>e.name)??[],e.pickLayers,e.pickFilter,e.sheetWires,e.sheetLabels,e.sheetDrawings,e.pcbCopper)),selectInstance:()=>Zx(e),replicateLayout:()=>void Qx(e),makeSheet:()=>$x(e),find:e.openFind,checkDrc:e.openChecks,designRules:()=>e.openDialog(`rules`),autoplace:()=>Vx(e,{kind:`all`}),autoplaceSelection:()=>Vx(e,xb(e.design,e.selection.names)),autoplaceInstance:()=>Vx(e,Sb(e.design,e.selection.names)),fitBoard:()=>void e.actions.fitBoard(),autoroute:()=>Bx(e,{kind:`all`}),autorouteSelection:()=>Bx(e,vb(e.design,e.selection.names)),autorouteNet:()=>Bx(e,yb(e.highlight)),unroute:()=>Hx(e),lock:()=>Yx(e,!0),unlock:()=>Yx(e,!1),history:()=>e.workspace.openBottom(`log`),keys:()=>e.openDialog(`keys`),about:()=>e.openDialog(`about`),addPage:()=>Ux(e,`addPage`),renamePage:()=>Ux(e,`renamePage`),deletePage:()=>Ux(e,`deletePage`),themeLight:()=>e.workspace.setTheme(`light`),themeDark:()=>e.workspace.setTheme(`dark`),hoverLabels:e.workspace.toggleHoverLabels,pourSolid:()=>e.workspace.setPourFill(Pl.pourSolid),pourHatched:()=>e.workspace.setPourFill(Pl.pourHatched),pourOutline:()=>e.workspace.setPourFill(Pl.pourOutline),findSimilar:()=>Fx(e),placementTransfer:()=>kx(e),flip:()=>Ox(e),annotate:()=>Ax(e),systemSettings:()=>e.openDialog(`system`),newCircuit:()=>e.openDialog(`newCircuit`),footprintManager:()=>e.openDialog(`footprints`),print:()=>Gx(e,!1),exportPdf:()=>Gx(e,!0),copy:()=>Nx(e),paste:()=>Px(e,e.view===`schematic`?e.page:void 0,e.view===`schematic`?`sch`:`pcb`)}[t]}var tS=[`undo`,`redo`,`openFile`,`selectAll`,`find`,`findSimilar`,`placementTransfer`,`flip`,`copy`,`paste`],nS=e=>tS.includes(e??``);function rS(e,t){(0,l.useEffect)(()=>{let n=n=>{let r=Ou(pu(n),{view:t})?.action;nS(r)&&(r!==`copy`||(window.getSelection()?.toString()??``)===``)&&(n.preventDefault(),e(r))};return window.addEventListener(`keydown`,n),()=>window.removeEventListener(`keydown`,n)},[e,t])}function iS(e){let[t,n]=(0,l.useState)(null),{file:r,view:i,setView:a,selection:o,select:s,circuit:c,actions:u,pickLayers:d,pickFilter:f,sheetWires:p,sheetLabels:m,sheetDrawings:h,pcbCopper:g,copperRecords:_,openChecks:v,checkCounts:y,openFind:b,openDialog:x,design:S,page:C,openPage:w,highlight:T}=e,{run:E,openBottom:ee,openPageTree:D,setTheme:O,toggleHoverLabels:k,setPourFill:A}=e.workspace;(0,l.useEffect)(()=>{if(!t||i!==t.view)return;let e=window.setTimeout(()=>{n(null),Ny(t.command)||u.notify(`The ${t.view===`pcb`?`PCB`:`schematic`} is still building; try again in a moment.`)},0);return()=>window.clearTimeout(e)},[t,i,u]);let j=(0,l.useCallback)(e=>{let t=eS({file:r,view:i,setView:a,selection:o,select:s,circuit:c,actions:u,pickLayers:d,pickFilter:f,sheetWires:p,sheetLabels:m,sheetDrawings:h,pcbCopper:g,copperRecords:_,workspace:{run:E,openBottom:ee,openPageTree:D,setTheme:O,toggleHoverLabels:k,setPourFill:A},openChecks:v,checkCounts:y,openFind:b,openDialog:x,design:S,page:C,openPage:w,highlight:T},e);if(t)return t();let l=Rx(e);l&&i!==l?(a(l),n({command:e,view:l})):Ny(e)||u.notify(`Wait for the build to finish, then try again.`)},[r,i,a,o,s,c,u,d,f,p,m,h,g,_,E,ee,D,O,k,A,v,y,b,x,S,C,w,T]);return rS(j,i),j}function aS({file:e,buildId:t,actions:n}){let[r,i]=(0,l.useState)([]),[a,o]=(0,l.useState)(!1);(0,l.useEffect)(()=>{R(`/api/bom?file=${encodeURIComponent(e)}`).then(i).catch(e=>n.notify(e.message))},[e,t,n]);let s=r.reduce((e,t)=>e+t.quantity,0);return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`h3`,{children:[`Bill of materials `,(0,X.jsxs)(`span`,{className:`count`,children:[s,` parts`]})]}),(0,X.jsxs)(`table`,{className:`bom`,children:[(0,X.jsx)(`thead`,{children:(0,X.jsxs)(`tr`,{children:[(0,X.jsx)(`th`,{scope:`col`,children:`Parts`}),(0,X.jsx)(`th`,{scope:`col`,children:`Value`}),(0,X.jsx)(`th`,{scope:`col`,children:`Supplier`})]})}),(0,X.jsx)(`tbody`,{children:r.map(e=>(0,X.jsxs)(`tr`,{children:[(0,X.jsxs)(`td`,{children:[e.designators.join(`, `),e.libraryPart&&!e.verified&&(0,X.jsx)(`span`,{className:`badge unverified`,children:`Unverified`})]}),(0,X.jsx)(`td`,{title:e.footprint,children:e.value||e.kind}),(0,X.jsx)(`td`,{children:(0,X.jsx)(`code`,{children:e.supplier.replace(/^\w+ /,``)})})]},e.designators.join(` `)))})]}),(0,X.jsx)(`button`,{disabled:a,onClick:()=>{o(!0),R(`/api/package`,{file:e}).then(e=>n.notify(`Exported ${e.files.length} files to ${e.outDir}`)).catch(e=>n.notify(e.message)).finally(()=>o(!1))},children:a?`Exporting`:`Export BOM and datasheets`})]})}var oS=`No problems found.`,sS=e=>e===`error`?0:1,cS=e=>e.startsWith(`net.`)||e.includes(`:`);function lS(e){return e.items.find(e=>!cS(e))?.split(/[#.]/,1)[0]||void 0}function uS(e,t){let n=lS(e);return n!==void 0&&t.has(n)?n:void 0}function dS(e,t,n,r){let i=e.items.filter(e=>n.has(e)),a=e.items.filter(e=>fS(r).has(e)),o=e.at??(e.view===`pcb`?a.map(e=>Dl(r,e)).find(e=>e!==void 0):void 0);if(i.length>0||a.length>0)return{...e,...i.length>0?{copper:i}:{},...a.length>0?{board:a}:{},...o?{at:o}:{}};let s=uS(e,t);return s===void 0?e:{...e,part:s}}function fS(e){let t=e.pcb;return new Set([...t?.board?.pours??[],...t?.holes??[]].map(e=>e.id))}function pS(e){let t=e.pcb;return new Set([...t?.tracks??[],...t?.vias??[]].map(e=>e.id))}function mS(e){let t={id:e.id,severity:e.severity,code:e.code,message:e.message,items:e.items,view:e.view};return e.at?{...t,at:e.at}:t}var hS=(e,t)=>({id:`diagnostic:${t}`,severity:e.severity,code:e.code,message:e.message,items:e.items,view:`code`}),gS=(e,t)=>e<t?`${e} ${t}`:`${t} ${e}`;function _S(e,t){if(t?.state!==`done`)return[];let n=new Map(e.pcb.ratsnest.map(e=>[gS(e.from,e.to),e]));return t.unrouted.flatMap(e=>{let t=n.get(gS(e.from,e.to));if(t===void 0)return[];let r={x:(t.a.x+t.b.x)/2,y:(t.a.y+t.b.y)/2};return[{id:`route:${e.from}:${e.to}`,severity:`warning`,code:`unrouted`,message:e.reason,items:[e.from,e.to,...e.blockers],view:`pcb`,at:r}]})}function vS(e,t){let n=new Set(e.circuit.components.map(e=>e.id)),r=pS(e);return[...e.violations.map(mS),..._S(e,t),...e.diagnostics.map(hS)].map(t=>dS(t,n,r,e)).sort((e,t)=>sS(e.severity)-sS(t.severity))}function yS(e){return[...new Set(e.map(e=>e.code))].map(t=>{let n=e.filter(e=>e.code===t);return{code:t,severity:n.some(e=>e.severity===`error`)?`error`:`warning`,rows:n}})}function bS(e,t){return e.flatMap(e=>e.view===t&&e.at?[{id:e.id,at:e.at,severity:e.severity}]:[])}function xS(e){let t=e.filter(e=>e.severity===`error`).length;return{errors:t,warnings:e.length-t}}var SS=(e,t)=>`${e} ${t}${e===1?``:`s`}`;function CS({errors:e,warnings:t}){let n=[...e>0?[SS(e,`error`)]:[],...t>0?[SS(t,`warning`)]:[]];return n.length===0?oS:n.join(`, `)}var wS=`.insp-body:not([hidden]) .insp-value input:not([disabled]):not([type="checkbox"])`,TS={resistor:[[`resistance`,`10k`],[`footprint`,`0402`]],capacitor:[[`capacitance`,`100nF`],[`footprint`,`0402`]],inductor:[[`inductance`,`10uH`],[`footprint`,`0805`]],led:[[`color`,`green`],[`footprint`,`0603`]],diode:[[`footprint`,`sod123`]],fuse:[[`currentRating`,`500mA`],[`footprint`,`1206`]],crystal:[[`frequency`,`16MHz`],[`footprint`,`hc49`]],pinheader:[[`pinCount`,`4`],[`pitch`,`2.54mm`]],port:[[`side`,`left`],[`order`,`1`]]},ES=[`pcbX`,`pcbY`,`pcbRotation`,`schX`,`schY`,`schRotation`,`side`,`layer`],DS=[`schNameAt`,`schValueAt`,`pcbNameAt`],OS=`footprint`;function kS(e,t){return OS in e.props?[`prop:${OS}`]:t.includes(OS)?[`suggest:${OS}`]:[]}var AS={label:`Placement`,value:`Placed by Studio`};function jS(e,t){let n=Object.keys(e.props).filter(e=>!ES.includes(e)&&!DS.includes(e)&&e!==OS),r=(TS[e.tag]??[]).map(([e])=>e).filter(t=>!(t in e.props)),i=r.filter(e=>e!==OS),a=ES.filter(t=>t in e.props),o=DS.filter(t=>t in e.props),s=kS(e,r);return[{title:`Basic`,rows:[`name`,`kind`,...n.map(e=>`prop:${e}`),...i.map(e=>`suggest:${e}`)]},...s.length>0?[{title:`Footprint`,rows:s}]:[],{title:`Position`,rows:[...t.autoPlaced?[`placed`]:[],...a.map(e=>`prop:${e}`),...o.map(e=>`textAt:${e}`),`lock`]},{title:`Connections`,rows:[`connections`]},...t.library?[{title:`Library`,rows:[`library`]}]:[],{title:`Notes`,rows:[`notes`]}]}function MS(){return[{title:`Build`,rows:[`build`]},{title:`Notes for the agent`,rows:[`notes`]}]}function NS(e,t,n=0,r=0,i=0,a=0,o=0){let s=e+t+n+r+i+a+o;return s===0?`board`:s>1?`group`:e===1?`part`:t===1?`wire`:i===1?`copper`:a===1?`text`:o===1?`pour`:n===1?`label`:`drawing`}var PS={parts:`Parts`,wires:`Wires`,labels:`Net labels and flags`,drawings:`Drawings`,copper:`Tracks and vias`,texts:`Names and values`,pours:`Copper pours and holes`},FS=/^kind:(parts|wires|labels|drawings|copper|texts|pours):(\d+)$/;function IS(e){let t=FS.exec(e);return t?{kind:t[1],count:Number(t[2])}:void 0}function LS(e,t,n=0,r=0,i=0,a=0,o=0,s=0){let c=`Selected objects: ${e.length+n+r+i+a+o+s}`,[l]=e,u=e.map(e=>`part:${e.name}`),d=[[`parts`,e.length],[`wires`,n],[`labels`,r],[`drawings`,i],[`copper`,a],[`texts`,o],[`pours`,s]].flatMap(([e,t])=>t>0?[`kind:${e}:${t}`]:[]);return n+r+i+a+o+s>0?{header:c,sections:[{title:`Selection`,rows:[...d,...u]}]}:l?e.length===1?{header:c,sections:jS(l,t)}:{header:c,sections:[{title:`Selection`,rows:u}]}:{header:c,sections:MS()}}var RS=[{label:`Rotate`,command:`rotate`},{label:`Lock`,command:`lock`},{label:`Unlock`,command:`unlock`},{label:`Delete`,command:`delete`}];function zS(e,t,n,r=0){let i=t.map(e=>e.name);return e===`lock`||e===`unlock`?`parts`in gt(i,n.locked,e===`lock`,n.violated):e===`delete`&&r>0||t.some(e=>e.editable&&!n.locked.has(e.name))}function BS(e,t){return t.locked.has(e)?t.violated.has(e)?{command:`lock`,label:`Lock again`,pressed:!0,title:`Changed outside the editor: lock it again to accept the change`}:{command:`unlock`,label:`Locked`,pressed:!0,title:`Unlock this part`}:{command:`lock`,label:`Lock`,pressed:!1,title:`Lock this part, so the agent cannot move or change it`}}function VS({label:e,htmlFor:t,children:n}){return(0,X.jsxs)(`div`,{className:`insp-row`,children:[(0,X.jsx)(`label`,{className:`insp-label`,htmlFor:t,title:e,children:(0,X.jsx)(`span`,{children:e})}),(0,X.jsx)(`div`,{className:`insp-value`,children:n})]})}function HS({title:e,open:t,onToggle:n,children:r}){return(0,X.jsxs)(`section`,{className:t?`insp-section`:`insp-section collapsed`,children:[(0,X.jsxs)(`button`,{type:`button`,className:`insp-head hairline-t`,"aria-expanded":t,onClick:n,children:[(0,X.jsx)(jp,{className:`insp-chevron`}),(0,X.jsx)(`span`,{className:`insp-title`,children:e})]}),(0,X.jsx)(`div`,{className:`insp-body`,hidden:!t,children:r})]})}function US({name:e,prop:t,disabled:n,onCommit:r,notify:i}){let a=t.literal===void 0?t.source:String(t.literal),[o,s]=(0,l.useState)(a);return(0,l.useEffect)(()=>s(a),[a]),t.editable?(0,X.jsx)(VS,{label:e,htmlFor:`prop-${e}`,children:(0,X.jsx)(`input`,{id:`prop-${e}`,value:o,disabled:n,spellCheck:!1,onChange:e=>s(e.target.value),onBlur:()=>{if(o===a)return;let n=KS(t.literal,o);n===void 0?(i(`${e} needs ${typeof t.literal==`number`?`a number`:`true or false`}`),s(a)):r(n).then(e=>e||s(a))},onKeyDown:e=>{e.key===`Enter`&&e.currentTarget.blur(),e.key===`Escape`&&s(a)}})}):(0,X.jsx)(VS,{label:e,children:(0,X.jsx)(`code`,{className:`expr`,title:`An expression; change it in the code`,children:t.source.replace(/\s+/g,` `)})})}var WS=new Set([`pcbX`,`pcbY`,`pcbRotation`,`schX`,`schY`,`schRotation`,`pinCount`,`order`,`base`]);function GS({name:e,example:t,disabled:n,onCommit:r}){let[i,a]=(0,l.useState)(``);return(0,X.jsx)(VS,{label:e,htmlFor:`new-prop-${e}`,children:(0,X.jsx)(`input`,{id:`new-prop-${e}`,className:`new-prop`,placeholder:t,value:i,disabled:n,spellCheck:!1,onChange:e=>a(e.target.value),onBlur:()=>{let t=i.trim();t&&r(WS.has(e)&&Number.isFinite(Number(t))?Number(t):t).then(e=>e&&a(``))},onKeyDown:e=>{e.key===`Enter`&&e.currentTarget.blur()}})})}function KS(e,t){if(typeof e==`number`){let e=Number(t);return t.trim()!==``&&Number.isFinite(e)?e:void 0}return typeof e==`boolean`?t===`true`||t!==`false`&&void 0:t}function qS({label:e,onAdd:t}){let[n,r]=(0,l.useState)(``),i=(0,l.useId)();return(0,X.jsxs)(`form`,{className:`mark-form`,onSubmit:e=>{e.preventDefault(),n.trim()&&t(n.trim()).then(e=>e&&r(``))},children:[(0,X.jsx)(`label`,{htmlFor:i,children:e}),(0,X.jsxs)(`div`,{className:`inline`,children:[(0,X.jsx)(`input`,{id:i,value:n,onChange:e=>r(e.target.value),placeholder:`Route ground under this part`}),(0,X.jsx)(`button`,{type:`submit`,children:`Add`})]})]})}var JS={rotate:Dp,lock:Cp,unlock:wp,delete:Op};function YS({view:e,parts:t,others:n,locks:r,run:i,onClear:a,collapsed:o,toggle:s}){let{locked:c}=r,l=new Map(t.map(e=>[e.name,e])),u=e=>{let t=IS(e);if(t)return(0,X.jsx)(VS,{label:PS[t.kind],children:(0,X.jsx)(`span`,{className:`static`,children:t.count})},e);let n=e.slice(5),r=l.get(n);return(0,X.jsx)(VS,{label:n,children:(0,X.jsxs)(`span`,{className:`static`,children:[r?.tag,c.has(n)?`, locked`:``]})},e)};return(0,X.jsxs)(`div`,{className:`inspector`,children:[(0,X.jsxs)(`header`,{className:`insp-header`,children:[(0,X.jsx)(`span`,{children:e.header}),(0,X.jsx)(`button`,{className:`icon`,"aria-label":`Clear the selection`,onClick:a,children:(0,X.jsx)(Ap,{})})]}),(0,X.jsx)(`div`,{className:`inspector-actions`,children:RS.map(({label:e,command:a})=>{let o=JS[a];return(0,X.jsxs)(`button`,{className:a===`delete`?`danger`:void 0,disabled:!zS(a,t,r,n),onClick:()=>i(a),children:[(0,X.jsx)(o,{}),` `,e]},a)})}),e.sections.map(e=>(0,X.jsx)(HS,{title:e.title,open:!o.has(e.title),onToggle:()=>s(e.title),children:e.rows.map(u)},e.title))]})}function XS(){let e=null;return{answer(t){return e=t,()=>{e===t&&(e=null)}},send(t){return e?(e(t),!0):!1}}}var ZS=XS();function QS(e){let t=e;return{set(e){t=e},call:e=>t(e)}}var $S=`Label`;function eC({design:e,label:t,run:n,notify:r,onClear:i,collapsed:a,toggle:o}){let s=Lf(e,t);return s?(0,X.jsxs)(`div`,{className:`inspector`,children:[(0,X.jsxs)(`header`,{className:`insp-header`,children:[(0,X.jsx)(`span`,{children:`Selected objects: 1`}),(0,X.jsx)(`button`,{className:`icon`,"aria-label":`Clear the selection`,onClick:i,children:(0,X.jsx)(Ap,{})})]}),(0,X.jsxs)(`div`,{className:`inspector-actions`,children:[(0,X.jsx)(`button`,{title:`Rename this label's net`,onClick:()=>{ZS.send({kind:`renameLabel`,labelId:t})||r(`Open the schematic to rename this label.`)},children:`Rename`}),(0,X.jsx)(`button`,{title:`Light this label's net in both views`,onClick:()=>n(`highlight`),children:`Highlight net`})]}),(0,X.jsx)(HS,{title:$S,open:!a.has($S),onToggle:()=>o($S),children:s.rows.map(e=>(0,X.jsx)(VS,{label:e.label,children:(0,X.jsx)(`span`,{className:`static`,title:e.value,children:e.value})},e.label))})]}):null}var tC={path:`line`,rect:`rectangle`,circle:`circle`,arc:`arc`,text:`text`,bus:`bus`,junction:`junction`},nC=(e,t)=>({x:z(e.x+t.x),y:z(e.y+t.y)}),rC=e=>e.kind===`path`||e.kind===`bus`,iC=e=>rC(e)?[`points`]:[`x`,`y`],aC=(e,t)=>e.drawings.find(e=>e.id===t);function oC(e,t,n,r=[]){let i=aC(e,n);if(!i)return`${n} has no editable source element`;if(t.has(n))return`${n} is locked`;if(!i.editable)return`${n} is read-only (${i.readonlyReason??`not a literal element`})`;let a=r.find(e=>i.props[e]&&!i.props[e]?.editable);return a?`${n}.${a} is an expression; change it in the code`:null}var sC=(e,t,n)=>oC(e,t,n.id,iC(n));function cC(e){return e.kind===`path`||e.kind===`bus`?e.points[0]??{x:0,y:0}:{x:e.x,y:e.y}}function lC(e,t,n){let r=e.props[t]?.literal;return typeof r==`number`?r:z(n)}function uC(e,t,n){if(rC(t))return{points:(e.points??[]).map(e=>nC(e,n))};let{groupOffset:r}=t,i=cC(t);return{x:z(lC(e,`x`,i.x-r.x)+n.x),y:z(lC(e,`y`,i.y-r.y)+n.y)}}function dC(e,t){let{groupOffset:n}=e;return e.kind===`path`||e.kind===`bus`?`points`in t?{...e,points:t.points.map(e=>nC(e,n))}:e:`x`in t?{...e,x:z(t.x+n.x),y:z(t.y+n.y)}:e}function fC(e){return e.length>1?[`${e.length} drawings`]:e.map(e=>e.name??`the ${tC[e.kind]}`)}function pC(e,t,n,r,i){let a=t.find(e=>e.id===n),o=aC(e,n);if(!a)return{id:n,blocker:`${n} is not on the sheet`};let s=sC(e,i,a);return s||!o?{id:n,blocker:s??`${n} has no editable source element`}:{id:n,drawing:a,placed:uC(o,a,r)}}function mC(e,t,n,r,i){let a=n.map(n=>pC(e,t,n,r,i)),o=a.flatMap(e=>`placed`in e?[e]:[]);return{edits:o.map(({id:e,placed:t})=>({kind:`setDrawingProps`,id:e,props:{...t}})),names:fC(o.map(e=>e.drawing)),skipped:a.flatMap(e=>`blocker`in e?[e.blocker]:[]),shown:o.map(({drawing:e,placed:t})=>dC(e,t))}}function hC(e,t,n){return r=>{let i=r.map(t=>({id:t,blocker:oC(e,n,t)})),a=i.flatMap(e=>e.blocker??[]),o=i.flatMap(e=>e.blocker===null?[e.id]:[]),s=t=>aC(e,t)?.start??0,c=[...o].sort((e,t)=>s(t)-s(e)),l=o.flatMap(e=>t.find(t=>t.id===e)??[]);return{edits:c.map(e=>({kind:`removeDrawing`,id:e})),names:fC(l),skipped:a,removed:o}}}var gC=/^[A-Za-z_][A-Za-z0-9_]*$/,_C=/^G(\d+)$/;function vC(e){let t=[...e.parts.map(e=>e.name),...e.drawings.flatMap(e=>[e.id,e.name??``])];return`G${Math.max(0,...t.map(e=>Number(_C.exec(e)?.[1]??0)))+1}`}function yC(e,t,n,r){if(t===`bus`?Zt(n)===void 0:!gC.test(n))throw new um(`invalid`,`"${n}" is not a valid ${t===`bus`?`bus`:`drawing`} name; use ${t===`bus`?`a net name such as "CLK" or a range such as "D[0:7]"`:`letters, digits and _`}`);if(e.parts.some(e=>e.name===n))throw new um(`invalid`,`A part named ${n} already exists`);let i=(e,r)=>t===`bus`&&e===`bus`&&r===n;if(e.drawings.some(e=>e.id!==r&&(e.name===n||e.id===n)&&!i(e.tag,e.name)))throw new um(`invalid`,`A drawing named ${n} already exists`)}function bC(e,t){if(typeof t==`string`&&t!==``)return e!==`bus`||Zt(t)!==void 0?t:void 0}function xC(e,t){return`drawing:${e}:${t}`}function SC(e,t){let n=2;for(;e.has(`${t}~${n}`);)n++;return`${t}~${n}`}function CC(e,t){let n=new Set(t),r=new Set,i=new Map;return e.map(({kind:e,name:t})=>{let a=(i.get(e)??0)+1;i.set(e,a);let o=t??xC(e,a);if(!n.has(o))return n.add(o),e===`bus`&&r.add(o),{id:o,base:o};let s=SC(n,o);return n.add(s),{id:s,base:o,repeat:e===`bus`&&r.has(o)?`piece`:`duplicate`}})}var wC=`Name the bus, such as D[0:7] or CLK`;function TC(e,t){return new Set([...e.parts.map(e=>e.name),...e.drawings.flatMap(e=>[e.id,e.name??``]),...t])}function EC(e,t=[]){let n=TC(e,t),r=1;for(;n.has(`BUS${r}`);)r++;return`BUS${r}`}function DC(e,t,n){let r=t.trim();if(r===``)return wC;try{yC(e,`bus`,r,n);return}catch(e){return e instanceof Error?e.message:String(e)}}function OC(e,t){return e.drawings.map(e=>{let n=Jt(e.tag)??`path`;return{kind:n,name:e.id===t?.id?t.name:bC(n,e.name)}})}var kC=(e,t,n)=>CC(t,e.parts.map(e=>e.name))[n]?.id??``;function AC(e,t,n=[]){let r=n.filter(e=>e===t).map(e=>({kind:`bus`,name:e})),i=[...OC(e),...r,{kind:`bus`,name:t}];return kC(e,i,i.length-1)}function jC(e,t,n){let r=e.drawings.findIndex(e=>e.id===t);return r<0?n:kC(e,OC(e,{id:t,name:n}),r)}function MC(e){let t=`${e.length} member${e.length===1?``:`s`}`;return`${e.length>2?`${e[0]} … ${e.at(-1)}`:e.join(`, `)}, ${t}`}var NC={x:{label:`X`,field:`number`},y:{label:`Y`,field:`number`},points:{label:`Points`,field:`points`},width:{label:`Width`,field:`number`,rule:`positive`},height:{label:`Height`,field:`number`,rule:`positive`},radius:{label:`Radius`,field:`number`,rule:`positive`},startAngle:{label:`Start angle`,field:`number`},endAngle:{label:`End angle`,field:`number`},text:{label:`Text`,field:`text`},fontSize:{label:`Font size`,field:`number`,rule:`positive`},anchor:{label:`Anchor`,field:`choice`,options:qt},strokeWidth:{label:`Stroke width`,field:`number`,rule:`nonNegative`},lineStyle:{label:`Line style`,field:`choice`,options:Kt},color:{label:`Colour`,field:`color`},filled:{label:`Filled`,field:`check`}},PC=[`strokeWidth`,`lineStyle`,`color`],FC={path:[`points`,...PC],rect:[`x`,`y`,`width`,`height`,...PC,`filled`],circle:[`x`,`y`,`radius`,...PC,`filled`],arc:[`x`,`y`,`radius`,`startAngle`,`endAngle`,...PC],text:[`x`,`y`,`text`,`fontSize`,`anchor`,`color`],bus:[`points`],junction:[`x`,`y`,`color`]},IC={path:`Line`,rect:`Rectangle`,circle:`Circle`,arc:`Arc`,text:`Text`,bus:`Bus`,junction:`Junction`},LC=e=>e.map(e=>`${e.x}, ${e.y}`).join(`; `);function RC(e,t){let{groupOffset:n}=e;if((e.kind===`path`||e.kind===`bus`)&&t===`points`)return LC(e.points.map(e=>({x:z(e.x-n.x),y:z(e.y-n.y)})));let r=e[t];return t===`x`||t===`y`?String(z(r-n[t])):r===void 0?``:String(r)}function zC(e,t,n,r){let i=NC[n],a=t?.props[n],o=a!==void 0&&!a.editable,s=n===`color`?{placeholder:H().drawing}:{},c=i.options?{options:i.options}:{},l=o?a.source:RC(e,n);return{key:n,label:i.label,value:l,field:i.field,...c,...s,editable:r&&t!==void 0&&!o}}var BC=`Renames this piece of the bus only; its wires keep their nets`;function VC(e,t,n){return e.kind===`bus`?[{key:`name`,label:`Name`,value:e.name,field:`text`,editable:n&&t?.name!==void 0,hint:BC},{key:`members`,label:`Members`,value:MC(e.members),field:`static`,editable:!1}]:[{key:`name`,label:`Name`,value:e.name??`(none)`,field:`static`,editable:!1}]}function HC(e,t,n){let r=t?.line??e.source.line;return[{key:`kind`,label:`Kind`,value:`${IC[e.kind]}, line ${r}`,field:`static`,editable:!1},...VC(e,t,n),...FC[e.kind].map(r=>zC(e,t,r,n))]}var UC=/^#[0-9A-Fa-f]{6}$/,WC={any:{ok:()=>!0,says:`must be a number`},positive:{ok:e=>e>0,says:`must be a number greater than 0`},nonNegative:{ok:e=>e>=0,says:`must be a number of 0 or more`}};function GC(e){let t=e.split(`;`).map(e=>e.split(`,`).map(e=>e.trim())).map(e=>e.length===2&&e.every(e=>e!==``&&Number.isFinite(Number(e)))?{x:z(Number(e[0])),y:z(Number(e[1]))}:void 0);return t.length>=2&&t.every(e=>e!==void 0)?t:void 0}function KC(e,t){let n=t.trim();if(e.field===`number`){let t=WC[e.rule??`any`],r=Number(n);return n!==``&&Number.isFinite(r)&&t.ok(r)?r:{message:`${e.label} ${t.says}`}}return e.field===`points`?GC(n)??{message:`${e.label} needs two or more x, y pairs, such as 0, 0; 1, 0`}:e.field===`choice`?e.options?.includes(n)?n:{message:`${e.label} must be one of ${e.options?.join(`, `)}`}:e.field===`check`?n===`true`||n===`false`?n===`true`:{message:`${e.label} must be true or false`}:e.field===`color`?UC.test(n)?n:{message:`${e.label} must be a colour such as "#000080"`}:t===``?{message:`${e.label} cannot be empty`}:t}function qC(e,t,n){let r=t.trim(),i=DC(n,r,e.id);return i?{message:i}:{edit:{kind:`setDrawingProps`,id:e.id,props:{name:r}},summary:`rename the bus ${e.name} to ${r}`}}function JC(e,t,n,r){if(t===`name`&&e.kind===`bus`&&r)return qC(e,n,r);let i=NC[t];if(!i)return{message:`${t} cannot be set here`};let a=KC(i,n);if(typeof a==`object`&&!Array.isArray(a))return a;let o=e.name??`the ${tC[e.kind]}`,s=Array.isArray(a)?`set ${o} ${t}`:`set ${o} ${t}=${JSON.stringify(a)}`;return{edit:{kind:`setDrawingProps`,id:e.id,props:{[t]:a}},summary:s}}var YC=`Drawing`;function XC({design:e,circuit:t,drawing:n,locked:r,actions:i,onRename:a,run:o,onClear:s,collapsed:c,toggle:l}){let u=e.schematic.drawings.find(e=>e.id===n);if(!u)return null;let d=oC(t.model,r,n),f=HC(u,aC(t.model,n),d===null),p=(e,r)=>{let o=JC(u,e,r,t.model);if(`message`in o)return i.notify(o.message),Promise.resolve(!1);let{edit:s}=o,c=s.kind===`setDrawingProps`?s.props.name:void 0,l=typeof c==`string`?a({from:n,to:jC(t.model,n,c)}):void 0;return i.edit([s],o.summary).catch(()=>!1).then(e=>(e||l?.(),e))};return(0,X.jsxs)(`div`,{className:`inspector`,children:[(0,X.jsxs)(`header`,{className:`insp-header`,children:[(0,X.jsx)(`span`,{children:`Selected objects: 1`}),(0,X.jsx)(`button`,{className:`icon`,"aria-label":`Clear the selection`,onClick:s,children:(0,X.jsx)(Ap,{})})]}),(0,X.jsx)(`div`,{className:`inspector-actions`,children:(0,X.jsxs)(`button`,{className:`danger`,disabled:d!==null,title:d??`Delete this drawing (Delete)`,onClick:()=>o(`delete`),children:[(0,X.jsx)(Op,{}),` Delete`]})}),d&&(0,X.jsxs)(`p`,{className:`note`,children:[d,`.`]}),(0,X.jsx)(HS,{title:YC,open:!c.has(YC),onToggle:()=>l(YC),children:f.map(e=>(0,X.jsx)(ZC,{row:e,onCommit:t=>p(e.key,t)},`${u.id}:${e.key}`))})]})}function ZC({row:e,onCommit:t}){let n=(0,l.useId)();return e.field===`static`||!e.editable?(0,X.jsx)(VS,{label:e.label,children:(0,X.jsx)(`span`,{className:e.field===`static`?`static`:`expr`,title:e.value,children:e.value})}):e.field===`check`?(0,X.jsx)(VS,{label:e.label,htmlFor:n,children:(0,X.jsx)(`input`,{id:n,type:`checkbox`,checked:e.value===`true`,onChange:e=>void t(String(e.target.checked))})}):e.field===`choice`?(0,X.jsx)(VS,{label:e.label,htmlFor:n,children:(0,X.jsx)(`select`,{id:n,value:e.value,onChange:e=>void t(e.target.value),children:e.options?.map(e=>(0,X.jsx)(`option`,{value:e,children:e},e))})}):(0,X.jsx)(QC,{id:n,row:e,onCommit:t})}function QC({id:e,row:t,onCommit:n}){let[r,i]=(0,l.useState)(t.value);return(0,l.useEffect)(()=>i(t.value),[t.value]),(0,X.jsx)(VS,{label:t.label,htmlFor:e,children:(0,X.jsx)(`input`,{id:e,value:r,placeholder:t.placeholder,title:t.hint,spellCheck:!1,onChange:e=>i(e.target.value),onBlur:()=>{r!==t.value&&n(r).then(e=>e||i(t.value))},onKeyDown:e=>{e.key===`Enter`&&e.currentTarget.blur(),e.key===`Escape`&&i(t.value)}})})}var $C={top:`Top Layer`,bottom:`Bottom Layer`,inner1:`Inner Layer 1`,inner2:`Inner Layer 2`},ew={human:`You`,agent:`The agent`,router:`The router`},tw=e=>`${Math.round(e*1e3)/1e3} mm`;function nw(e,t){return t===void 0?`No net`:e.circuit.nets.find(e=>e.id===t)?.names[0]??t}function rw(e,t){return[{label:`Net`,value:nw(e,t.net)},{label:`Layer`,value:t.layer,field:`layer`},{label:`Width`,value:String(t.width),field:`width`},{label:`Length`,value:tw(pb(t.points))},{label:`Drawn by`,value:ew[t.by]},{label:`Locked`,value:String(t.locked),field:`lock`}]}function iw(e,t){let[n=`top`,r=`bottom`]=[t.layers[0],t.layers.at(-1)];return[{label:`Net`,value:nw(e,t.net)},{label:`Layers`,value:`${$C[n]} to ${$C[r]}`},{label:`Drill`,value:tw(t.drill)},{label:`Diameter`,value:tw(t.diameter)},{label:`Drawn by`,value:ew[t.by]},{label:`Locked`,value:String(t.locked),field:`lock`}]}function aw(e,t){let n=e.pcb.tracks.find(e=>e.id===t);if(n)return{kind:`track`,title:`Track`,locked:n.locked,rows:rw(e,n)};let r=e.pcb.vias.find(e=>e.id===t);return r&&{kind:`via`,title:`Via`,locked:r.locked,rows:iw(e,r)}}var ow=e=>`(${Math.round(e.x*1e3)/1e3}, ${Math.round(e.y*1e3)/1e3}) mm`;function sw(e,t){let n=e.pcb.tracks.find(e=>e.id===t.id);if(!n||!X_(n.points,t.index)||!qi(t,n.points))return;let[r,i]=[n.points[t.index],n.points[t.index+1]];return{kind:`segment`,title:`Segment`,locked:n.locked,rows:[{label:`Net`,value:nw(e,n.net)},{label:`Track`,value:n.id},{label:`Length`,value:tw(pb([r,i]))},{label:`Start`,value:ow(r)},{label:`End`,value:ow(i)}]}}function cw(e,t){let n=t===`true`;if(n!==e.locked)return{edit:{kind:e.points?`setTrack`:`setVia`,id:e.id,locked:n},summary:`${n?`Lock`:`Unlock`} ${e.id}`}}function lw(e,t,n){if(t===`lock`)return cw(e,n);if(e.locked)return{message:`${e.id} is locked`};if(t===`width`){let t=Number(n.trim());return n.trim()===``||!Number.isFinite(t)||t<=0?{message:`The width must be a number of mm above 0`}:t===e.width?void 0:{edit:{kind:`setTrack`,id:e.id,width:t},summary:`Set the width of ${e.id} to ${t} mm`}}return n!==`top`&&n!==`bottom`?{message:`The layer must be top or bottom`}:n===e.layer?void 0:{edit:{kind:`setTrack`,id:e.id,layer:n},summary:`Move ${e.id} to the ${n} layer`}}var uw=[{value:`top`,label:`Top Layer`},{value:`bottom`,label:`Bottom Layer`}];function dw({design:e,id:t,segment:n,actions:r,run:i,onClear:a,collapsed:o,toggle:s}){let c=n?.id===t?sw(e,n):void 0;if(c)return(0,X.jsx)(fw,{shown:c,id:t,run:i,onClear:a,collapsed:o,toggle:s});let l=aw(e,t),u=e.pcb.tracks.find(e=>e.id===t)??e.pcb.vias.find(e=>e.id===t);if(!l||!u)return null;let d=async(e,t)=>{let n=lw(u,e,t);return n?`message`in n?(r.notify(n.message),!1):(await r.editLayout([n.edit],n.summary)).ok:!0};return(0,X.jsxs)(`div`,{className:`inspector`,children:[(0,X.jsxs)(`header`,{className:`insp-header`,children:[(0,X.jsx)(`span`,{children:`Selected objects: 1`}),(0,X.jsx)(`button`,{className:`icon`,"aria-label":`Clear the selection`,onClick:a,children:(0,X.jsx)(Ap,{})})]}),(0,X.jsx)(`div`,{className:`inspector-actions`,children:(0,X.jsxs)(`button`,{className:`danger`,disabled:l.locked,title:l.locked?`${t} is locked`:`Delete this ${l.kind} (Delete)`,onClick:()=>i(`delete`),children:[(0,X.jsx)(Op,{}),` Delete`]})}),(0,X.jsx)(HS,{title:l.title,open:!o.has(l.title),onToggle:()=>s(l.title),children:l.rows.map(e=>(0,X.jsx)(pw,{row:e,locked:l.locked,onCommit:d},e.label))})]})}function fw({shown:e,id:t,run:n,onClear:r,collapsed:i,toggle:a}){return(0,X.jsxs)(`div`,{className:`inspector`,children:[(0,X.jsxs)(`header`,{className:`insp-header`,children:[(0,X.jsx)(`span`,{children:`Selected objects: 1`}),(0,X.jsx)(`button`,{className:`icon`,"aria-label":`Clear the selection`,onClick:r,children:(0,X.jsx)(Ap,{})})]}),(0,X.jsx)(`div`,{className:`inspector-actions`,children:(0,X.jsxs)(`button`,{className:`danger`,disabled:e.locked,title:e.locked?`${t} is locked`:`Delete this segment of the track (Delete)`,onClick:()=>n(`delete`),children:[(0,X.jsx)(Op,{}),` Delete segment`]})}),(0,X.jsx)(HS,{title:e.title,open:!i.has(e.title),onToggle:()=>a(e.title),children:e.rows.map(e=>(0,X.jsx)(VS,{label:e.label,children:(0,X.jsx)(`span`,{className:`static`,title:e.value,children:e.value})},e.label))})]})}function pw({row:e,locked:t,onCommit:n}){let r=(0,l.useId)();return e.field===`lock`?(0,X.jsx)(VS,{label:e.label,htmlFor:r,children:(0,X.jsx)(`input`,{id:r,type:`checkbox`,checked:e.value===`true`,onChange:e=>void n(`lock`,String(e.target.checked))})}):e.field===`layer`?(0,X.jsx)(VS,{label:e.label,htmlFor:r,children:(0,X.jsxs)(`select`,{id:r,value:e.value,disabled:t,onChange:e=>void n(`layer`,e.target.value),children:[uw.map(e=>(0,X.jsx)(`option`,{value:e.value,children:e.label},e.value)),!uw.some(t=>t.value===e.value)&&(0,X.jsx)(`option`,{value:e.value,disabled:!0,children:e.value===`inner1`?`Inner Layer 1`:`Inner Layer 2`})]})}):e.field===`width`?(0,X.jsx)(mw,{id:r,value:e.value,locked:t,onCommit:e=>n(`width`,e)}):(0,X.jsx)(VS,{label:e.label,children:(0,X.jsx)(`span`,{className:`static`,title:e.value,children:e.value})})}function mw({id:e,value:t,locked:n,onCommit:r}){let[i,a]=(0,l.useState)(t);return(0,l.useEffect)(()=>a(t),[t]),(0,X.jsx)(VS,{label:`Width (mm)`,htmlFor:e,children:(0,X.jsx)(`input`,{id:e,value:i,disabled:n,inputMode:`decimal`,spellCheck:!1,onChange:e=>a(e.target.value),onBlur:()=>{i!==t&&r(i).then(e=>e||a(t))},onKeyDown:e=>{e.key===`Enter`&&e.currentTarget.blur(),e.key===`Escape`&&a(t)}})})}function hw({design:e,circuit:t,id:n,locks:r,actions:i,run:a,onClear:o,collapsed:s,toggle:c}){let l=Qv(e,n);if(!l)return null;let u=zv(t.model,r.locked,n),d=ry(n,r),f=async(t,r)=>{let a=ny(e,n,t,r);return a?`message`in a?(i.notify(a.message),!1):i.edit([a.edit],a.summary):!0};return(0,X.jsxs)(`div`,{className:`inspector`,children:[(0,X.jsxs)(`header`,{className:`insp-header`,children:[(0,X.jsx)(`span`,{children:`Selected objects: 1`}),(0,X.jsx)(`button`,{className:`icon`,"aria-label":`Clear the selection`,onClick:o,children:(0,X.jsx)(Ap,{})})]}),(0,X.jsxs)(`div`,{className:`inspector-actions`,children:[(0,X.jsxs)(`button`,{className:d.pressed?`toggle on`:`toggle`,"aria-pressed":d.pressed,title:d.title,onClick:()=>a(d.command),children:[d.pressed?(0,X.jsx)(Cp,{}):(0,X.jsx)(wp,{}),d.label]}),(0,X.jsxs)(`button`,{className:`danger`,disabled:u!==null,title:u??`Delete this ${l.kind===`hole`?`hole`:`copper pour`} (Delete)`,onClick:()=>a(`delete`),children:[(0,X.jsx)(Op,{}),` Delete`]})]}),(0,X.jsx)(HS,{title:l.title,open:!s.has(l.title),onToggle:()=>c(l.title),children:l.rows.map(e=>(0,X.jsx)(gw,{row:e,disabled:u!==null,onCommit:f},e.label))})]})}function gw({row:e,disabled:t,onCommit:n}){let r=(0,l.useId)(),{field:i,choices:a}=e;return!i||t?(0,X.jsx)(VS,{label:e.label,children:(0,X.jsx)(`span`,{className:`static`,title:e.value,children:e.value===``?`Net class`:e.value})}):a?(0,X.jsx)(VS,{label:e.label,htmlFor:r,children:(0,X.jsxs)(`select`,{id:r,value:e.value,onChange:e=>void n(i,e.target.value),children:[a.map(e=>(0,X.jsx)(`option`,{value:e.value,children:e.label},e.value)),!a.some(t=>t.value===e.value)&&(0,X.jsx)(`option`,{value:e.value,disabled:!0,children:e.value})]})}):(0,X.jsx)(_w,{id:r,row:e,field:i,onCommit:n})}function _w({id:e,row:t,field:n,onCommit:r}){let[i,a]=(0,l.useState)(t.value);return(0,l.useEffect)(()=>a(t.value),[t.value]),(0,X.jsx)(VS,{label:t.label,htmlFor:e,children:(0,X.jsx)(`input`,{id:e,value:i,inputMode:`decimal`,spellCheck:!1,placeholder:n===`clearance`?`Net class`:void 0,onChange:e=>a(e.target.value),onBlur:()=>{i!==t.value&&r(n,i).then(e=>e||a(t.value))},onKeyDown:e=>{e.key===`Enter`&&e.currentTarget.blur(),e.key===`Escape`&&a(t.value)}})})}var vw=.001,yw=e=>e.flatMap(e=>e.kind===`junction`&&e.x!==void 0&&e.y!==void 0?[{id:e.id,x:e.x,y:e.y}]:[]);function bw(e,t){for(let n=1;n<t.length;n++){let[r,i]=[t[n-1],t[n]],[a,o]=[i.x-r.x,i.y-r.y],s=a*a+o*o,c=s===0?0:Math.max(0,Math.min(1,((e.x-r.x)*a+(e.y-r.y)*o)/s));if(Math.hypot(r.x+c*a-e.x,r.y+c*o-e.y)<=vw)return{segment:n-1,t:c}}}var xw=(e,t)=>t.some(t=>bw(e,t)!==void 0);function Sw(e,t){let n=t[0];for(let r=1;r<t.length;r++){let[i,a]=[t[r-1],t[r]],[o,s]=[a.x-i.x,a.y-i.y],c=o*o+s*s,l=c===0?0:Math.max(0,Math.min(1,((e.x-i.x)*o+(e.y-i.y)*s)/c)),u={x:i.x+l*o,y:i.y+l*s};Math.hypot(u.x-e.x,u.y-e.y)<Math.hypot(n.x-e.x,n.y-e.y)&&(n=u)}return n}var Cw=e=>Math.round(e*1e3)/1e3;function ww(e,t,n,r){return n.length<2?[]:e.flatMap(e=>{let i=bw(e,t);if(i===void 0||xw(e,r))return[];let a=n.length===t.length,[o,s]=[n[i.segment],n[i.segment+1]],c=a?{x:o.x+i.t*(s.x-o.x),y:o.y+i.t*(s.y-o.y)}:Sw(e,n),l={x:Cw(c.x),y:Cw(c.y)};return Math.abs(l.x-e.x)<vw&&Math.abs(l.y-e.y)<vw?[]:[{kind:`setDrawingProps`,id:e.id,props:l}]})}function Tw(e,t,n){return e.filter(e=>xw(e,t)&&!xw(e,n)).map(e=>e.id)}var Ew=`This wire is no longer on the sheet`,Dw=`This wire has no corners`,Ow=`Studio draws this wire's corner; the code has none to remove`,kw=`This wire repeats another between the same ends; delete it in the code`;function Aw(e,t){let n=e.schematic.wires.find(e=>e.id===t);return n&&$d(e.circuit.nets,n.net)}function jw(e,t){let n=Aw(e,t),r=e.circuit.nets.find(e=>e.id===n);return r?Cf(r):(n??``).replace(/^net\./,``)}var Mw=(e,t)=>`This wire has no trace of its own: Studio draws it for net ${jw(e,t)}`,Nw=e=>e.startsWith(`net.`)?`net ${e.slice(4)}`:e;function Pw(e,t){let{writer:n}=t;if(n.kind===`engine`)return[Mn(e,n.from)?.id??Nw(n.from),Mn(e,n.to)?.id??Nw(n.to)];let r=e.schematic.wires.find(e=>e.id===t.id),i=e.circuit.connections.find(e=>e.id===r?.connection);return i?[Nw(i.from),Nw(i.to)]:void 0}function Fw(e,t){let n=Pw(e,t);return n?`the wire from ${n[0]} to ${n[1]}`:`the wire`}function Iw(e,t,n){let{writer:r}=t;if(r.kind===`none`)return r.reason;if(r.kind===`engine`)return Mw(e,t.id);let i=hr(e,r.components,r.trace,n);return i===void 0?r.repeat?kw:r.trace.editable?null:`This wire is read-only (${r.trace.readonlyReason}); delete it in the code`:`${i} is locked`}function Lw(e,t,n){if(t.writer.kind!==`trace`)return Iw(e,t,n);if(t.points.length<=2)return Dw;let r=lc(e,t,n);return r===null?(t.writer.trace.schematicRouteHints?.length??0)>0?null:Ow:r}function Rw(e){let t=e.writer.kind===`trace`?e.writer.trace:void 0;return{from:t?.from??``,to:t?.to??``}}function zw(e,t,n){let r=Iw(e,t,n);return r===null?{edits:[{kind:`removeTrace`,...Rw(t)}],summary:`remove ${Fw(e,t)}`}:{blocked:r}}function Bw(e,t,n){let r=Lw(e,t,n);return r===null?{edits:[{kind:`setTraceHints`,...Rw(t),schematicRouteHints:[]}],summary:`remove the corners of ${Fw(e,t)}`}:{blocked:r}}var Vw=e=>`blocked`in e?e.blocked:null;function Hw(e,t,n){return{remove:Vw(zw(e,t,n)),removeCorners:Vw(Bw(e,t,n))}}function Uw(e,t,n){let r=t?Fw(e,t):`the wire`,i=r.charAt(0).toUpperCase()+r.slice(1);return n.startsWith(`This wire`)?`${i}${n.slice(9)}`:`${i}: ${n}`}function Ww(e,t){if(t.writer.kind!==`none`)return t.writer.components;let n=e.circuit.connections.find(n=>n.id===e.schematic.wires.find(e=>e.id===t.id)?.connection),r=n?[n.from,n.to]:[];return e.circuit.components.filter(e=>e.pins.some(e=>r.includes(e.id))).map(e=>e.id)}function Gw(e,t,n,r,i){let a=cc(e,t,n);if(a&&Ww(e,a).some(e=>r.has(e)))return{id:n,kind:`withParts`};let o=a?zw(e,a,i):{blocked:Ew};return`blocked`in o?{id:n,kind:`skipped`,reason:o.blocked,named:Uw(e,a,o.blocked),studio:a?.writer.kind===`engine`}:{id:n,kind:`removed`,edits:o.edits,name:a?Fw(e,a):`the wire`}}var Kw=e=>`${e} wires have no trace of their own: Studio draws them for their nets`;function qw(e,t){let n=e.flatMap(e=>e.kind===`skipped`&&!t.has(e.reason)?[e]:[]),r=n.filter(e=>e.studio);return[...n.filter(e=>!e.studio).map(e=>e.named),...r.length>1?[Kw(r.length)]:r.map(e=>e.named)]}function Jw(e,t,n,r,i=ur,a=new Set){let o=n.map(n=>Gw(e,t,n,r,i)),s=o.flatMap(e=>e.kind===`removed`?[e]:[]),c=o.flatMap(e=>e.kind===`withParts`?[e.id]:[]),l=new Set([...s.map(e=>e.id),...c]),u=t=>e.schematic.wires.filter(e=>l.has(e.id)!==t).map(e=>e.points);return{edits:s.flatMap(e=>e.edits),removed:s.map(e=>e.id),names:s.map(e=>e.name),withParts:c,skipped:qw(o,a),junctions:Tw(yw(e.schematic.drawings),u(!1),u(!0))}}function Yw(e,t,n,r=ur){let i=cc(e,t,n);return i?Bw(e,i,r):{blocked:Ew}}function Xw(e,t,n,r=ur){let i=cc(e,t,n);return i?Hw(e,i,r):{remove:Ew,removeCorners:Ew}}function Zw(e){return e.writer.kind===`trace`?`Trace, line ${e.writer.trace.line}`:e.writer.kind===`engine`?`Routed by Studio`:`Not found in the code`}function Qw(e,t,n,r=ur){let i=cc(e,t,n);if(!i)return;let[a,o]=Pw(e,i)??[`unknown`,`unknown`],s=[{label:`Net`,value:jw(e,n)},{label:`From`,value:a},{label:`To`,value:o},{label:`Corners`,value:String(Math.max(0,i.points.length-2))},{label:`Kind`,value:Zw(i)}];return{net:Aw(e,n),rows:s,...Hw(e,i,r)}}var $w=`Wire`;function eT({design:e,circuit:t,wire:n,locked:r,run:i,onClear:a,collapsed:o,toggle:s}){let c=Qw(e,t,n,r);return c?(0,X.jsxs)(`div`,{className:`inspector`,children:[(0,X.jsxs)(`header`,{className:`insp-header`,children:[(0,X.jsx)(`span`,{children:`Selected objects: 1`}),(0,X.jsx)(`button`,{className:`icon`,"aria-label":`Clear the selection`,onClick:a,children:(0,X.jsx)(Ap,{})})]}),(0,X.jsxs)(`div`,{className:`inspector-actions`,children:[(0,X.jsx)(`button`,{disabled:c.net===void 0,title:`Light this wire's net in both views`,onClick:()=>i(`highlight`),children:`Highlight net`}),(0,X.jsx)(`button`,{disabled:c.removeCorners!==null,title:c.removeCorners??`Let Studio draw this wire on its own, with at most one elbow`,onClick:()=>i(`removeCorners`),children:`Remove corners`}),(0,X.jsxs)(`button`,{className:`danger`,disabled:c.remove!==null,title:c.remove??`Delete this wire's trace (Delete)`,onClick:()=>i(`delete`),children:[(0,X.jsx)(Op,{}),` Delete`]})]}),c.remove&&(0,X.jsxs)(`p`,{className:`note`,children:[c.remove,`.`]}),(0,X.jsx)(HS,{title:$w,open:!o.has($w),onToggle:()=>s($w),children:c.rows.map(e=>(0,X.jsx)(VS,{label:e.label,children:(0,X.jsx)(`span`,{className:`static`,title:e.value,children:e.value})},e.label))})]}):null}function tT({design:e,circuit:t,text:n,locked:r,actions:i,onClear:a,collapsed:o,toggle:s}){let c=od(e,t,n,r);if(!c)return null;let l=td(e,t,n,r);return(0,X.jsxs)(`div`,{className:`inspector`,children:[(0,X.jsxs)(`header`,{className:`insp-header`,children:[(0,X.jsx)(`span`,{children:`Selected objects: 1`}),(0,X.jsx)(`button`,{className:`icon`,"aria-label":`Clear the selection`,onClick:a,children:(0,X.jsx)(Ap,{})})]}),(0,X.jsx)(`div`,{className:`inspector-actions`,children:(0,X.jsx)(`button`,{disabled:l!==null,title:l??`Put it back where the layout puts it`,onClick:()=>void i.edit(Qu(n),`Reset ${c.rows[0]?.value??``} ${c.title.toLowerCase()} position`),children:`Reset position`})}),c.blocker&&(0,X.jsxs)(`p`,{className:`note`,children:[c.blocker,`.`]}),(0,X.jsx)(HS,{title:c.title,open:!o.has(c.title),onToggle:()=>s(c.title),children:c.rows.map(e=>(0,X.jsx)(VS,{label:e.label,children:(0,X.jsx)(`span`,{className:`static`,title:e.value,children:e.value})},e.label))})]})}function nT({id:e,verified:t,actions:n}){let[r,i]=(0,l.useState)();if((0,l.useEffect)(()=>{R(`/api/part?id=${encodeURIComponent(e)}`).then(i).catch(e=>n.notify(e.message))},[e,t,n]),!r)return(0,X.jsx)(`p`,{className:`note`,children:`Loading…`});let{part:a}=r,o=r.checklist.split(`
16
16
  `).filter(e=>e.startsWith(`- [`));return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`dl`,{className:`facts`,children:[(0,X.jsx)(`dt`,{children:`Part`}),(0,X.jsx)(`dd`,{children:a.title}),a.manufacturer&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`dt`,{children:`Maker`}),(0,X.jsx)(`dd`,{children:a.manufacturer})]}),a.mpn&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`dt`,{children:`MPN`}),(0,X.jsx)(`dd`,{children:(0,X.jsx)(`code`,{children:a.mpn})})]}),(0,X.jsx)(`dt`,{children:`Footprint`}),(0,X.jsx)(`dd`,{children:(0,X.jsx)(`code`,{children:a.footprint})}),Object.entries(a.suppliers??{}).map(([e,t])=>(0,X.jsxs)(`span`,{className:`contents`,children:[(0,X.jsx)(`dt`,{children:e}),(0,X.jsx)(`dd`,{children:(0,X.jsx)(`code`,{children:t})})]},e)),a.datasheet?.url&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`dt`,{children:`Datasheet`}),(0,X.jsx)(`dd`,{children:(0,X.jsx)(`a`,{href:a.datasheet.url,target:`_blank`,rel:`noreferrer noopener`,children:`Open`})})]})]}),(0,X.jsxs)(`p`,{className:`hint`,children:[`These come from parts/`,e,`/part.yaml and are the same for every copy of the part.`]}),t?(0,X.jsxs)(`p`,{className:`note ok`,children:[`Verified by `,a.verified?.by,` against `,a.verified?.against,`.`]}):(0,X.jsx)(rT,{id:e,checklist:o,actions:n})]})}function rT({id:e,checklist:t,actions:n}){let[r,i]=(0,l.useState)(``),[a,o]=(0,l.useState)(``),[s,c]=(0,l.useState)(``);return(0,X.jsxs)(`form`,{className:`verify`,onSubmit:t=>{t.preventDefault(),n.verify(e,r.trim(),a.trim(),s)},children:[(0,X.jsx)(`p`,{className:`note warn`,children:`Not verified. Check each item against the datasheet:`}),(0,X.jsx)(`ul`,{className:`checklist`,children:t.map(e=>(0,X.jsx)(`li`,{children:e.replace(/^- \[ \] /,``)},e))}),(0,X.jsxs)(`label`,{children:[`Checked against`,(0,X.jsx)(`input`,{value:a,onChange:e=>o(e.target.value),placeholder:`Datasheet, revision, page`,required:!0})]}),(0,X.jsxs)(`label`,{children:[`Your name`,(0,X.jsx)(`input`,{"aria-label":`Your name`,value:r,onChange:e=>i(e.target.value),required:!0})]}),(0,X.jsxs)(`label`,{children:[`Type `,e,` to confirm`,(0,X.jsx)(`input`,{"aria-label":`Type ${e} to confirm`,value:s,onChange:e=>c(e.target.value),spellCheck:!1,required:!0})]}),(0,X.jsx)(`button`,{type:`submit`,className:`primary`,disabled:s.trim()!==e||!r.trim()||!a.trim(),children:`Mark verified`})]})}function iT({id:e,value:t,disabled:n,placeholder:r,onCommit:i}){let[a,o]=(0,l.useState)(t);return(0,l.useEffect)(()=>o(t),[t]),(0,X.jsx)(`input`,{id:e,value:a,disabled:n,placeholder:r,spellCheck:!1,onChange:e=>o(e.target.value),onBlur:()=>{a.trim()!==t&&i(a.trim()).then(e=>e||o(t))},onKeyDown:e=>{e.key===`Enter`&&e.currentTarget.blur(),e.key===`Escape`&&o(t)}})}function aT({design:e,name:t,editable:n,actions:r,onOpenSheet:i,collapsed:a,toggle:o}){let s=un(e,t),c=(0,l.useId)();if(!s)return null;let u=(e,n)=>{let i=n===``?void 0:sn(s.sheet,e,n,s.ports.find(t=>t.name===e)?.bus===!0);return i===void 0?r.edit([{kind:`setConnections`,part:t,connections:gn(s,e,n)}],`Connect ${t}.${e} to ${n===``?`nothing`:n}`):(r.notify(i),Promise.resolve(!1))};return(0,X.jsxs)(HS,{title:`Sub-sheet`,open:!a.has(`Sub-sheet`),onToggle:()=>o(`Sub-sheet`),children:[(0,X.jsx)(VS,{label:`Sheet`,children:(0,X.jsx)(`span`,{className:`static`,children:mn(s.sheet,pn(e,s.file))})}),(0,X.jsx)(`div`,{className:`inspector-actions`,children:(0,X.jsxs)(`button`,{onClick:()=>i(s.file),title:`Open ${s.file}`,children:[`Open `,s.sheet]})}),s.ports.map(e=>(0,X.jsx)(VS,{label:`${e.name}${e.bus?` (bus)`:``}`,htmlFor:`${c}-${e.name}`,children:(0,X.jsx)(iT,{id:`${c}-${e.name}`,value:s.connections[e.name]??``,placeholder:`not connected`,disabled:!n,onCommit:t=>u(e.name,t)})},e.name)),(0,X.jsx)(VS,{label:`base`,htmlFor:`${c}-base`,children:(0,X.jsx)(iT,{id:`${c}-base`,value:String(s.base),disabled:!n,onCommit:e=>{let n=Number(e);return!Number.isInteger(n)||n<=0?(r.notify(`The base is a whole number above 0, such as 300`),Promise.resolve(!1)):r.edit([{kind:`setProps`,part:t,props:{base:n}}],`Set ${t} base=${n}`)}})})]})}function oT({design:e,part:t,onSelect:n,onOpenSheet:r}){let i=dn(e,t);return i?(0,X.jsxs)(`div`,{className:`inspector`,children:[(0,X.jsx)(`header`,{className:`insp-header`,children:(0,X.jsx)(`span`,{children:t})}),(0,X.jsxs)(`p`,{className:`note`,children:[i.localId,` of instance `,i.instance,` (`,i.sheet,`). `,mn(i.sheet,pn(e,i.file)),`: change it in its sheet, and every instance changes with it.`]}),(0,X.jsxs)(`div`,{className:`inspector-actions`,children:[(0,X.jsx)(`button`,{onClick:()=>n(t=>t.all(fn(e,i.outer))),children:`Select the instance`}),(0,X.jsxs)(`button`,{onClick:()=>r(i.file),title:`Open ${i.file}`,children:[`Open `,i.sheet]})]})]}):null}function sT({file:e,parentDesign:t}){let n=t?pn(t,e):void 0;return(0,X.jsxs)(`p`,{className:`note`,children:[mn(Qe(e),n),`.`]})}function cT({part:e,editable:t,actions:n,collapsed:r,toggle:i}){let a=(0,l.useId)(),o=e.props.bus?.literal===!0,s=t=>n.edit([{kind:`renamePort`,from:e.name,to:t}],`Rename port ${e.name} to ${t}`),c=t=>n.edit([{kind:`setProps`,part:e.name,props:{bus:t}}],`${t?`Make`:`Unmake`} ${e.name} a bus port`);return(0,X.jsxs)(HS,{title:`Port`,open:!r.has(`Port`),onToggle:()=>i(`Port`),children:[(0,X.jsx)(VS,{label:`Name`,htmlFor:`${a}-name`,children:(0,X.jsx)(iT,{id:`${a}-name`,value:e.name,disabled:!t,onCommit:s})}),(0,X.jsx)(VS,{label:`Bus`,htmlFor:`${a}-bus`,children:(0,X.jsx)(`input`,{id:`${a}-bus`,type:`checkbox`,checked:o,disabled:!t,onChange:e=>void c(e.target.checked)})}),(0,X.jsx)(`p`,{className:`hint`,children:`Drag its pin on a symbol of this sheet to move it along the box or to another side.`})]})}function lT({parts:e,onPlace:t,onImport:n,onNewPart:r,focus:i,onFocused:a}){let[o,s]=(0,l.useState)(``),c=(0,l.useRef)(null);(0,l.useEffect)(()=>{i&&(c.current?.focus(),a())},[i,a]);let u=o.trim().toLowerCase(),d=(...e)=>u===``||e.some(e=>e?.toLowerCase().includes(u)),f=e.library.filter(e=>d(e.id,e.title,e.mpn,e.footprint)),p=e.builtin.filter(e=>d(e));return(0,X.jsxs)(`div`,{className:`library`,children:[(0,X.jsx)(`input`,{ref:c,className:`search`,type:`search`,placeholder:`Search parts`,"aria-label":`Search parts`,value:o,onChange:e=>s(e.target.value)}),(0,X.jsxs)(`h3`,{children:[`Project library `,(0,X.jsx)(`span`,{className:`count`,children:e.library.length})]}),(0,X.jsx)(`button`,{className:`library-import`,onClick:r,children:`New part…`}),(0,X.jsx)(`button`,{className:`library-import`,onClick:n,children:`Import by LCSC number…`}),e.library.length===0&&(0,X.jsx)(`p`,{className:`note`,children:`No parts yet. Write one from its datasheet with New part…, import one by its LCSC number, or ask the agent to create one.`}),(0,X.jsx)(`ul`,{children:f.map(e=>(0,X.jsxs)(`li`,{className:`library-item`,children:[(0,X.jsxs)(`div`,{className:`text`,children:[(0,X.jsx)(`span`,{className:`title`,children:e.title}),(0,X.jsxs)(`span`,{className:`meta`,children:[e.mpn??e.id,`, `,e.footprint]}),e.origin&&(0,X.jsx)(`span`,{className:`meta`,children:rm(e.origin)})]}),(0,X.jsx)(`span`,{className:`badge ${e.verified?`verified`:`unverified`}`,title:e.verified?`Checked by ${e.verifiedBy}`:`Not checked against the datasheet yet`,children:e.verified?`Verified`:`Unverified`}),(0,X.jsx)(`button`,{onClick:()=>t(e.id),"aria-label":`Place ${e.title}`,children:`Place`})]},e.id))}),(0,X.jsx)(`h3`,{children:`Built-in parts`}),(0,X.jsx)(`ul`,{className:`builtin`,children:p.map(e=>(0,X.jsx)(`li`,{children:(0,X.jsx)(`button`,{className:`chip-button`,onClick:()=>t(e),"aria-label":`Place a ${e}`,children:e})},e))}),(0,X.jsx)(`p`,{className:`hint`,children:`Placed parts start at the board centre; drag them into position on the PCB.`})]})}function uT({design:e,highlight:t,onHighlight:n}){let r=(0,l.useMemo)(()=>e?wf(e):[],[e]);if(r.length===0)return(0,X.jsx)(`p`,{className:`note`,children:`No nets yet.`});let i=e=>t.length===1&&t[0]===e;return(0,X.jsx)(`ul`,{className:`nets`,children:r.map(e=>(0,X.jsx)(`li`,{children:(0,X.jsxs)(`button`,{className:`row${t.includes(e.id)?` selected`:``}`,"aria-pressed":t.includes(e.id),onClick:()=>n(i(e.id)?ef:[e.id]),title:i(e.id)?`Click to clear the highlight`:`Click to highlight this net`,children:[(0,X.jsx)(`span`,{className:`name`,children:e.label}),e.badge&&(0,X.jsx)(`span`,{className:`badge ${e.badge}`,children:e.badge}),(0,X.jsx)(`span`,{className:`value`,children:e.pins===1?`1 pin`:`${e.pins} pins`})]})},e.id))})}var dT=`No PROJECT.md yet. The agent writes it with set_project and note_decision; you can also write it by hand at the project root.`,fT=e=>e.map(e=>e.trim()).filter(e=>e!==``).map(e=>e.replace(/^[-*]\s+/,``));function pT(e){if(e==null)return{kind:`missing`,note:dT};let t=e.replace(/\r\n/g,`