@tscircuit/runframe 0.0.1630 → 0.0.1631

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.
@@ -5428,7 +5428,7 @@ You passed in: '`+this.raw_options[o]+"'");return a},t.prototype._is_valid_selec
5428
5428
  `);break}}return s}}}),LOe=ra({"node_modules/pretty/index.js"(e,A){var t=FOe(),i=vOe(),n=kgt(),o={unformatted:["code","pre","em","strong","span"],indent_inner_html:!0,indent_char:" ",indent_size:2,sep:`
5429
5429
  `};A.exports=function(a,g){var c=n({},o,g);return a=t.html(a,c),c.ocd===!0?(c.newlines&&(c.sep=c.newlines),s(a,c)):a};function s(r,a){return i(r,a).replace(/^\s+/g,"").replace(/\s+$/g,`
5430
5430
  `).replace(/(\s*<!--)/g,`
5431
- $1`).replace(/>(\s*)(?=<!--\s*\/)/g,"> ")}}});function Fgt(e,A,t){if(!A||!t)return;let i=e.get(A);i||(i=new Set,e.set(A,i)),i.add(t);let n=e.get(t);n||(n=new Set,e.set(t,n)),n.add(A)}function UOe(e,A){if(!A.subcircuit_id&&!A.source_group_id)return[...e];const t=new Map;for(const s of e){const r=s[`${s.type}_id`];typeof r=="string"&&t.set(r,s)}const i=new Map;for(const s of e){const r=Object.entries(s);for(const[a,g]of r)if(a!=="parent_source_group_id"){if(a.endsWith("_id")&&typeof g=="string"){const c=t.get(g);Fgt(i,s,c)}else if(a.endsWith("_ids")&&Array.isArray(g)){for(const c of g)if(typeof c=="string"){const I=t.get(c);Fgt(i,s,I)}}}}const n=[],o=new Set;for(const s of e)(A.subcircuit_id&&s.subcircuit_id===A.subcircuit_id||A.source_group_id&&(s.source_group_id===A.source_group_id||Array.isArray(s.member_source_group_ids)&&s.member_source_group_ids.includes(A.source_group_id)))&&(n.push(s),o.add(s));for(;n.length>0;){const s=n.shift(),r=i.get(s);if(r)for(const a of r)o.has(a)||(o.add(a),n.push(a))}return e.filter(s=>o.has(s))}var A9=(e,A={})=>{const t=e;let i=t._internal_store;if(!i){i={counts:{},editCount:0},t._internal_store=i;for(const o of t){const s=o.type,r=o[`${s}_id`];if(!r)continue;const a=Number.parseInt(r.split("_").pop());Number.isNaN(a)||(i.counts[s]=Math.max(i.counts[s]??0,a))}}return new Proxy({},{get:(o,s)=>{if(s==="toArray")return()=>(t.editCount=i.editCount,t);if(s==="editCount")return i.editCount;if(s==="subtree")return a=>A9(UOe(t,a),A);const r=s;return{get:a=>t.find(g=>g.type===r&&g[`${r}_id`]===a),getUsing:a=>{const g=Object.keys(a);if(g.length!==1)throw new Error("getUsing requires exactly one key, e.g. { pcb_component_id }");const c=g[0],I=c.replace("_id",""),l=t.find(B=>B.type===I&&B[c]===a[c]);return l?t.find(B=>B.type===r&&B[`${r}_id`]===l[`${r}_id`]):null},getWhere:a=>{const g=Object.keys(a);return t.find(c=>c.type===r&&g.every(I=>c[I]===a[I]))},list:a=>{const g=a?Object.keys(a):[];return t.filter(c=>c.type===r&&g.every(I=>c[I]===a[I]))},insert:a=>{i.counts[r]??=-1,i.counts[r]++;const g=i.counts[r],c={type:r,[`${r}_id`]:`${r}_${g}`,...a};return A.validateInserts&&(Bat[r]??XdA).parse(c),t.push(c),i.editCount++,c},delete:a=>{const g=t.find(c=>c[`${r}_id`]===a);g&&(t.splice(t.indexOf(g),1),i.editCount++)},update:(a,g)=>{const c=t.find(I=>I.type===r&&I[`${r}_id`]===a);return c?(Object.assign(c,g),i.editCount++,c):null},select:a=>{if(r==="source_component")return t.find(g=>g.type==="source_component"&&g.name===a.replace(/\./g,""));if(r==="pcb_port"||r==="source_port"||r==="schematic_port"){const[g,c]=a.replace(/\./g,"").split(/[\s\>]+/),I=t.find(B=>B.type==="source_component"&&B.name===g);if(!I)return null;const l=t.find(B=>B.type==="source_port"&&B.source_component_id===I.source_component_id&&(B.name===c||(B.port_hints??[]).includes(c)));if(!l)return null;if(r==="source_port")return l;if(r==="pcb_port")return t.find(B=>B.type==="pcb_port"&&B.source_port_id===l.source_port_id);if(r==="schematic_port")return t.find(B=>B.type==="schematic_port"&&B.source_port_id===l.source_port_id)}}}}})};A9.unparsed=A9;var Db=A9;function LpA(e){const A=e.type;return`${A}:${e[`${A}_id`]}`}var Ggt=(e,A={})=>{let t=e._internal_store_indexed;if(!t){t={counts:{},editCount:0,indexes:{}};for(const s of e){const r=s.type,a=s[`${r}_id`];if(!a)continue;const g=Number.parseInt(a.split("_").pop()||"");Number.isNaN(g)||(t.counts[r]=Math.max(t.counts[r]??0,g))}const n=A.indexConfig||{},o=t.indexes;if(n.byId&&(o.byId=new Map),n.byType&&(o.byType=new Map),n.byRelation&&(o.byRelation=new Map),n.bySubcircuit&&(o.bySubcircuit=new Map),n.byCustomField&&n.byCustomField.length>0){o.byCustomField=new Map;for(const s of n.byCustomField)o.byCustomField.set(s,new Map)}for(const s of e){if(n.byId){const r=LpA(s);o.byId.set(r,s)}if(n.byType){const r=o.byType.get(s.type)||[];r.push(s),o.byType.set(s.type,r)}if(n.byRelation){const r=Object.entries(s);for(const[a,g]of r)if(a.endsWith("_id")&&a!==`${s.type}_id`&&typeof g=="string"){const c=o.byRelation.get(a)||new Map,I=c.get(g)||[];I.push(s),c.set(g,I),o.byRelation.set(a,c)}}if(n.bySubcircuit&&"subcircuit_id"in s){const r=s.subcircuit_id;if(r&&typeof r=="string"){const a=o.bySubcircuit.get(r)||[];a.push(s),o.bySubcircuit.set(r,a)}}if(n.byCustomField&&o.byCustomField){for(const r of n.byCustomField)if(r in s){const a=s[r];if(a!==void 0&&(typeof a=="string"||typeof a=="number")){const g=String(a),c=o.byCustomField.get(r),I=c.get(g)||[];I.push(s),c.set(g,I)}}}}e._internal_store_indexed=t}return new Proxy({},{get:(n,o)=>{if(o==="toArray")return()=>(e.editCount=t.editCount,e);if(o==="editCount")return t.editCount;const s=o;return{get:r=>{const a=A.indexConfig||{};return a.byId&&t.indexes.byId?t.indexes.byId.get(`${s}:${r}`)||null:a.byType&&t.indexes.byType?(t.indexes.byType.get(s)||[]).find(c=>c[`${s}_id`]===r)||null:e.find(g=>g.type===s&&g[`${s}_id`]===r)||null},getUsing:r=>{const a=A.indexConfig||{},g=Object.keys(r);if(g.length!==1)throw new Error("getUsing requires exactly one key, e.g. { pcb_component_id }");const c=g[0],I=c.replace("_id","");if(a.byRelation&&t.indexes.byRelation){const B=t.indexes.byRelation.get(c);if(B){const E=(B.get(r[c])||[]).find(h=>h.type===I);if(!E)return null;const Q=E[`${s}_id`];return a.byId&&t.indexes.byId?t.indexes.byId.get(`${s}:${Q}`)||null:a.byType&&t.indexes.byType?(t.indexes.byType.get(s)||[]).find(u=>u[`${s}_id`]===Q)||null:e.find(h=>h.type===s&&h[`${s}_id`]===Q)||null}}const l=e.find(B=>B.type===I&&B[c]===r[c]);return l&&e.find(B=>B.type===s&&B[`${s}_id`]===l[`${s}_id`])||null},getWhere:r=>{const a=A.indexConfig||{},g=Object.keys(r);if(g.length===1&&a.byCustomField&&t.indexes.byCustomField){const c=g[0],I=t.indexes.byCustomField.get(c);if(I){const l=String(r[c]);return(I.get(l)||[]).find(C=>C.type===s)||null}}if("subcircuit_id"in r&&a.bySubcircuit&&t.indexes.bySubcircuit){const c=r.subcircuit_id;return(t.indexes.bySubcircuit.get(c)||[]).find(l=>l.type===s&&g.every(B=>l[B]===r[B]))||null}return a.byType&&t.indexes.byType?(t.indexes.byType.get(s)||[]).find(I=>g.every(l=>I[l]===r[l]))||null:e.find(c=>c.type===s&&g.every(I=>c[I]===r[I]))||null},list:r=>{const a=A.indexConfig||{},g=r?Object.keys(r):[];if(g.length===0&&a.byType&&t.indexes.byType)return t.indexes.byType.get(s)||[];if(g.length===1&&g[0]==="subcircuit_id"&&a.bySubcircuit&&t.indexes.bySubcircuit){const I=r.subcircuit_id;return(t.indexes.bySubcircuit.get(I)||[]).filter(B=>B.type===s)}let c;return a.byType&&t.indexes.byType?c=t.indexes.byType.get(s)||[]:c=e.filter(I=>I.type===s),g.length>0?c.filter(I=>g.every(l=>I[l]===r[l])):c},insert:r=>{t.counts[s]??=-1,t.counts[s]++;const a=t.counts[s],g={type:s,[`${s}_id`]:`${s}_${a}`,...r};A.validateInserts&&(Bat[s]??XdA).parse(g),e.push(g),t.editCount++;const c=A.indexConfig||{};if(c.byId&&t.indexes.byId){const I=LpA(g);t.indexes.byId.set(I,g)}if(c.byType&&t.indexes.byType){const I=t.indexes.byType.get(s)||[];I.push(g),t.indexes.byType.set(s,I)}if(c.byRelation&&t.indexes.byRelation){const I=Object.entries(g);for(const[l,B]of I)if(l.endsWith("_id")&&l!==`${g.type}_id`&&typeof B=="string"){const C=t.indexes.byRelation.get(l)||new Map,E=C.get(B)||[];E.push(g),C.set(B,E),t.indexes.byRelation.set(l,C)}}if(c.bySubcircuit&&t.indexes.bySubcircuit&&"subcircuit_id"in g){const I=g.subcircuit_id;if(I&&typeof I=="string"){const l=t.indexes.bySubcircuit.get(I)||[];l.push(g),t.indexes.bySubcircuit.set(I,l)}}if(c.byCustomField&&t.indexes.byCustomField){for(const I of c.byCustomField)if(I in g){const l=g[I];if(l!==void 0&&(typeof l=="string"||typeof l=="number")){const B=String(l),C=t.indexes.byCustomField.get(I),E=C.get(B)||[];E.push(g),C.set(B,E)}}}return g},delete:r=>{const a=A.indexConfig||{};let g;if(a.byId&&t.indexes.byId?g=t.indexes.byId.get(`${s}:${r}`):a.byType&&t.indexes.byType?g=(t.indexes.byType.get(s)||[]).find(l=>l[`${s}_id`]===r):g=e.find(I=>I[`${s}_id`]===r),!g)return;const c=e.indexOf(g);if(c>=0&&(e.splice(c,1),t.editCount++),a.byId&&t.indexes.byId){const I=LpA(g);t.indexes.byId.delete(I)}if(a.byType&&t.indexes.byType){const l=(t.indexes.byType.get(s)||[]).filter(B=>B[`${s}_id`]!==r);t.indexes.byType.set(s,l)}if(a.byRelation&&t.indexes.byRelation)for(const[I,l]of t.indexes.byRelation.entries())for(const[B,C]of l.entries()){const E=C.filter(Q=>Q!==g);E.length===0?l.delete(B):l.set(B,E)}if(a.bySubcircuit&&t.indexes.bySubcircuit&&"subcircuit_id"in g){const I=g.subcircuit_id;if(I){const B=(t.indexes.bySubcircuit.get(I)||[]).filter(C=>C!==g);B.length===0?t.indexes.bySubcircuit.delete(I):t.indexes.bySubcircuit.set(I,B)}}if(a.byCustomField&&t.indexes.byCustomField)for(const I of t.indexes.byCustomField.values())for(const[l,B]of I.entries()){const C=B.filter(E=>E!==g);C.length===0?I.delete(l):I.set(l,C)}},update:(r,a)=>{const g=A.indexConfig||{};let c;if(g.byId&&t.indexes.byId?c=t.indexes.byId.get(`${s}:${r}`):g.byType&&t.indexes.byType?c=(t.indexes.byType.get(s)||[]).find(l=>l[`${s}_id`]===r):c=e.find(I=>I.type===s&&I[`${s}_id`]===r),!c)return null;if(g.byRelation&&t.indexes.byRelation){const I=Object.entries(c);for(const[l,B]of I)if(l.endsWith("_id")&&l!==`${c.type}_id`&&typeof B=="string"&&l in a&&a[l]!==B){const C=t.indexes.byRelation.get(l);if(C){const Q=(C.get(B)||[]).filter(h=>h!==c);Q.length===0?C.delete(B):C.set(B,Q)}}}if(g.bySubcircuit&&t.indexes.bySubcircuit&&"subcircuit_id"in c&&"subcircuit_id"in a){const I=c.subcircuit_id,l=a.subcircuit_id;if(I!==l){const C=(t.indexes.bySubcircuit.get(I)||[]).filter(E=>E!==c);C.length===0?t.indexes.bySubcircuit.delete(I):t.indexes.bySubcircuit.set(I,C)}}if(g.byCustomField&&t.indexes.byCustomField){for(const I of g.byCustomField)if(I in c&&I in a&&c[I]!==a[I]){const l=t.indexes.byCustomField.get(I);if(l){const B=String(c[I]),E=(l.get(B)||[]).filter(Q=>Q!==c);E.length===0?l.delete(B):l.set(B,E)}}}if(Object.assign(c,a),t.editCount++,g.byRelation&&t.indexes.byRelation){const I=Object.entries(c);for(const[l,B]of I)if(l.endsWith("_id")&&l!==`${c.type}_id`&&typeof B=="string"&&l in a){const C=t.indexes.byRelation.get(l)||new Map,E=C.get(B)||[];E.includes(c)||(E.push(c),C.set(B,E),t.indexes.byRelation.set(l,C))}}if(g.bySubcircuit&&t.indexes.bySubcircuit&&"subcircuit_id"in c&&"subcircuit_id"in a){const I=c.subcircuit_id;if(I&&typeof I=="string"){const l=t.indexes.bySubcircuit.get(I)||[];l.includes(c)||(l.push(c),t.indexes.bySubcircuit.set(I,l))}}if(g.byCustomField&&t.indexes.byCustomField){for(const I of g.byCustomField)if(I in c&&I in a){const l=c[I];if(l!==void 0&&(typeof l=="string"||typeof l=="number")){const B=String(l),C=t.indexes.byCustomField.get(I),E=C.get(B)||[];E.includes(c)||(E.push(c),C.set(B,E))}}}return c},select:r=>{if(s==="source_component")return e.find(a=>a.type==="source_component"&&a.name===r.replace(/\./g,""))||null;if(s==="pcb_port"||s==="source_port"||s==="schematic_port"){const[a,g]=r.replace(/\./g,"").split(/[\s\>]+/),c=e.find(l=>l.type==="source_component"&&l.name===a);if(!c)return null;const I=e.find(l=>l.type==="source_port"&&l.source_component_id===c.source_component_id&&(l.name===g||(l.port_hints??[]).includes(g)));if(!I)return null;if(s==="source_port")return I;if(s==="pcb_port")return e.find(l=>l.type==="pcb_port"&&l.source_port_id===I.source_port_id)||null;if(s==="schematic_port")return e.find(l=>l.type==="schematic_port"&&l.source_port_id===I.source_port_id)||null}return null}}}})};Ggt.unparsed=Ggt;var HOe=e=>{const A=e.type;return e[`${A}_id`]},UpA=e=>{let A=Number.POSITIVE_INFINITY,t=Number.POSITIVE_INFINITY,i=Number.NEGATIVE_INFINITY,n=Number.NEGATIVE_INFINITY;for(const o of e){if(!o.type.startsWith("pcb_"))continue;if(o.type==="pcb_smtpad"&&o.shape==="polygon"&&Array.isArray(o.points)){for(const c of o.points)A=Math.min(A,c.x),t=Math.min(t,c.y),i=Math.max(i,c.x),n=Math.max(n,c.y);continue}let s,r,a,g;if("x"in o&&"y"in o&&(s=Number(o.x),r=Number(o.y)),"outer_diameter"in o&&(a=Number(o.outer_diameter),g=Number(o.outer_diameter)),"width"in o&&(a=Number(o.width)),"height"in o&&(g=Number(o.height)),"center"in o&&(s=o.center.x,r=o.center.y),s!==void 0&&r!==void 0)A=Math.min(A,s),t=Math.min(t,r),i=Math.max(i,s),n=Math.max(n,r),a!==void 0&&g!==void 0&&(A=Math.min(A,s-a/2),t=Math.min(t,r-g/2),i=Math.max(i,s+a/2),n=Math.max(n,r+g/2)),"radius"in o&&(A=Math.min(A,s-o.radius),t=Math.min(t,r-o.radius),i=Math.max(i,s+o.radius),n=Math.max(n,r+o.radius));else if(o.type==="pcb_trace")for(const c of o.route)A=Math.min(A,c.x),t=Math.min(t,c.y),i=Math.max(i,c.x),n=Math.max(n,c.y)}return{minX:A,minY:t,maxX:i,maxY:n}};function YOe(e){let A=0;if(e.length==0)return A;for(var t=0;t<e.length;t++){var i=e.charCodeAt(t);A=(A<<5)-A+i,A=A&A}return Math.abs(A)}var Mgt=[["#69d2e7","#a7dbd8","#e0e4cc","#f38630","#fa6900"],["#fe4365","#fc9d9a","#f9cdad","#c8c8a9","#83af9b"],["#ecd078","#d95b43","#c02942","#542437","#53777a"],["#556270","#4ecdc4","#c7f464","#ff6b6b","#c44d58"],["#774f38","#e08e79","#f1d4af","#ece5ce","#c5e0dc"],["#e8ddcb","#cdb380","#036564","#033649","#031634"],["#490a3d","#bd1550","#e97f02","#f8ca00","#8a9b0f"],["#594f4f","#547980","#45ada8","#9de0ad","#e5fcc2"],["#00a0b0","#6a4a3c","#cc333f","#eb6841","#edc951"],["#e94e77","#d68189","#c6a49a","#c6e5d9","#f4ead5"],["#3fb8af","#7fc7af","#dad8a7","#ff9e9d","#ff3d7f"],["#d9ceb2","#948c75","#d5ded9","#7a6a53","#99b2b7"],["#ffffff","#cbe86b","#f2e9e1","#1c140d","#cbe86b"],["#efffcd","#dce9be","#555152","#2e2633","#99173c"],["#343838","#005f6b","#008c9e","#00b4cc","#00dffc"],["#413e4a","#73626e","#b38184","#f0b49e","#f7e4be"],["#ff4e50","#fc913a","#f9d423","#ede574","#e1f5c4"],["#99b898","#fecea8","#ff847c","#e84a5f","#2a363b"],["#655643","#80bca3","#f6f7bd","#e6ac27","#bf4d28"],["#00a8c6","#40c0cb","#f9f2e7","#aee239","#8fbe00"],["#351330","#424254","#64908a","#e8caa4","#cc2a41"],["#554236","#f77825","#d3ce3d","#f1efa5","#60b99a"],["#5d4157","#838689","#a8caba","#cad7b2","#ebe3aa"],["#8c2318","#5e8c6a","#88a65e","#bfb35a","#f2c45a"],["#fad089","#ff9c5b","#f5634a","#ed303c","#3b8183"],["#ff4242","#f4fad2","#d4ee5e","#e1edb9","#f0f2eb"],["#f8b195","#f67280","#c06c84","#6c5b7b","#355c7d"],["#d1e751","#ffffff","#000000","#4dbce9","#26ade4"],["#1b676b","#519548","#88c425","#bef202","#eafde6"],["#5e412f","#fcebb6","#78c0a8","#f07818","#f0a830"],["#bcbdac","#cfbe27","#f27435","#f02475","#3b2d38"],["#452632","#91204d","#e4844a","#e8bf56","#e2f7ce"],["#eee6ab","#c5bc8e","#696758","#45484b","#36393b"],["#f0d8a8","#3d1c00","#86b8b1","#f2d694","#fa2a00"],["#2a044a","#0b2e59","#0d6759","#7ab317","#a0c55f"],["#f04155","#ff823a","#f2f26f","#fff7bd","#95cfb7"],["#b9d7d9","#668284","#2a2829","#493736","#7b3b3b"],["#bbbb88","#ccc68d","#eedd99","#eec290","#eeaa88"],["#b3cc57","#ecf081","#ffbe40","#ef746f","#ab3e5b"],["#a3a948","#edb92e","#f85931","#ce1836","#009989"],["#300030","#480048","#601848","#c04848","#f07241"],["#67917a","#170409","#b8af03","#ccbf82","#e33258"],["#aab3ab","#c4cbb7","#ebefc9","#eee0b7","#e8caaf"],["#e8d5b7","#0e2430","#fc3a51","#f5b349","#e8d5b9"],["#ab526b","#bca297","#c5ceae","#f0e2a4","#f4ebc3"],["#607848","#789048","#c0d860","#f0f0d8","#604848"],["#b6d8c0","#c8d9bf","#dadabd","#ecdbbc","#fedcba"],["#a8e6ce","#dcedc2","#ffd3b5","#ffaaa6","#ff8c94"],["#3e4147","#fffedf","#dfba69","#5a2e2e","#2a2c31"],["#fc354c","#29221f","#13747d","#0abfbc","#fcf7c5"],["#cc0c39","#e6781e","#c8cf02","#f8fcc1","#1693a7"],["#1c2130","#028f76","#b3e099","#ffeaad","#d14334"],["#a7c5bd","#e5ddcb","#eb7b59","#cf4647","#524656"],["#dad6ca","#1bb0ce","#4f8699","#6a5e72","#563444"],["#5c323e","#a82743","#e15e32","#c0d23e","#e5f04c"],["#edebe6","#d6e1c7","#94c7b6","#403b33","#d3643b"],["#fdf1cc","#c6d6b8","#987f69","#e3ad40","#fcd036"],["#230f2b","#f21d41","#ebebbc","#bce3c5","#82b3ae"],["#b9d3b0","#81bda4","#b28774","#f88f79","#f6aa93"],["#3a111c","#574951","#83988e","#bcdea5","#e6f9bc"],["#5e3929","#cd8c52","#b7d1a3","#dee8be","#fcf7d3"],["#1c0113","#6b0103","#a30006","#c21a01","#f03c02"],["#000000","#9f111b","#b11623","#292c37","#cccccc"],["#382f32","#ffeaf2","#fcd9e5","#fbc5d8","#f1396d"],["#e3dfba","#c8d6bf","#93ccc6","#6cbdb5","#1a1f1e"],["#f6f6f6","#e8e8e8","#333333","#990100","#b90504"],["#1b325f","#9cc4e4","#e9f2f9","#3a89c9","#f26c4f"],["#a1dbb2","#fee5ad","#faca66","#f7a541","#f45d4c"],["#c1b398","#605951","#fbeec2","#61a6ab","#accec0"],["#5e9fa3","#dcd1b4","#fab87f","#f87e7b","#b05574"],["#951f2b","#f5f4d7","#e0dfb1","#a5a36c","#535233"],["#8dccad","#988864","#fea6a2","#f9d6ac","#ffe9af"],["#2d2d29","#215a6d","#3ca2a2","#92c7a3","#dfece6"],["#413d3d","#040004","#c8ff00","#fa023c","#4b000f"],["#eff3cd","#b2d5ba","#61ada0","#248f8d","#605063"],["#ffefd3","#fffee4","#d0ecea","#9fd6d2","#8b7a5e"],["#cfffdd","#b4dec1","#5c5863","#a85163","#ff1f4c"],["#9dc9ac","#fffec7","#f56218","#ff9d2e","#919167"],["#4e395d","#827085","#8ebe94","#ccfc8e","#dc5b3e"],["#a8a7a7","#cc527a","#e8175d","#474747","#363636"],["#f8edd1","#d88a8a","#474843","#9d9d93","#c5cfc6"],["#046d8b","#309292","#2fb8ac","#93a42a","#ecbe13"],["#f38a8a","#55443d","#a0cab5","#cde9ca","#f1edd0"],["#a70267","#f10c49","#fb6b41","#f6d86b","#339194"],["#ff003c","#ff8a00","#fabe28","#88c100","#00c176"],["#ffedbf","#f7803c","#f54828","#2e0d23","#f8e4c1"],["#4e4d4a","#353432","#94ba65","#2790b0","#2b4e72"],["#0ca5b0","#4e3f30","#fefeeb","#f8f4e4","#a5b3aa"],["#4d3b3b","#de6262","#ffb88c","#ffd0b3","#f5e0d3"],["#fffbb7","#a6f6af","#66b6ab","#5b7c8d","#4f2958"],["#edf6ee","#d1c089","#b3204d","#412e28","#151101"],["#9d7e79","#ccac95","#9a947c","#748b83","#5b756c"],["#fcfef5","#e9ffe1","#cdcfb7","#d6e6c3","#fafbe3"],["#9cddc8","#bfd8ad","#ddd9ab","#f7af63","#633d2e"],["#30261c","#403831","#36544f","#1f5f61","#0b8185"],["#aaff00","#ffaa00","#ff00aa","#aa00ff","#00aaff"],["#d1313d","#e5625c","#f9bf76","#8eb2c5","#615375"],["#ffe181","#eee9e5","#fad3b2","#ffba7f","#ff9c97"],["#73c8a9","#dee1b6","#e1b866","#bd5532","#373b44"],["#805841","#dcf7f3","#fffcdd","#ffd8d8","#f5a2a2"]],JOe=e=>{let{x:A,y:t,width:i,height:n}={...e,...e.size,...e.center,...e.position};if(e.x1!==void 0&&e.x2!==void 0&&e.y1!==void 0&&e.y2!==void 0&&(A=(e.x1+e.x2)/2,t=(e.y1+e.y2)/2,i=Math.abs(e.x1-e.x2),n=Math.abs(e.y1-e.y2)),e.points&&Array.isArray(e.points)&&e.points.length>0){const r=e.points.map(B=>B.x),a=e.points.map(B=>B.y),g=Math.min(...r),c=Math.max(...r),I=Math.min(...a),l=Math.max(...a);A=(g+c)/2,t=(I+l)/2,i=c-g,n=l-I}const o=e.text||e.name||e.source?.text||e.source?.name||"?",s=e;return A===void 0||t===void 0?null:(i===void 0&&"outer_diameter"in e&&(i=e.outer_diameter,n=e.outer_diameter),(i===void 0||n===void 0)&&(i=.1,n=.1),{x:A,y:t,width:i,height:n,title:o,content:s,bg_color:Mgt[YOe(e.type||o)%Mgt.length]?.[4]??"#f00"})},TOe=e=>!!e,KOe=e=>{const A=e.filter(g=>g.type.startsWith("pcb_")||g.type.startsWith("schematic_")).concat(e.filter(g=>g.type==="pcb_trace"||g.type==="schematic_trace").flatMap(g=>g.route)).map(g=>JOe(g)).filter(TOe);if(A.length===0)return{center:{x:0,y:0},width:0,height:0};let t=A[0].x-A[0].width/2,i=A[0].x+A[0].width/2,n=A[0].y-A[0].height/2,o=A[0].y+A[0].height/2;for(const g of A.slice(1))t=Math.min(t,g.x-g.width/2),i=Math.max(i,g.x+g.width/2),n=Math.min(n,g.y-g.height/2),o=Math.max(o,g.y+g.height/2);const s=i-t,r=o-n;return{center:{x:t+s/2,y:n+r/2},width:s,height:r}},vD={IS_SHOWING_PCB_GROUPS:"pcb_viewer_is_showing_pcb_groups",PCB_GROUP_VIEW_MODE:"pcb_viewer_group_view_mode",IS_SHOWING_COPPER_POURS:"pcb_viewer_is_showing_copper_pours",IS_SHOWING_GROUP_ANCHOR_OFFSETS:"pcb_viewer_is_showing_group_anchor_offsets",IS_SHOWING_SOLDER_MASK:"pcb_viewer_is_showing_solder_mask"},t9=(e,A)=>{if(typeof window>"u")return A;try{const t=localStorage.getItem(e);return t!==null?JSON.parse(t):A}catch{return A}},e9=(e,A)=>{if(!(typeof window>"u"))try{localStorage.setItem(e,JSON.stringify(A))}catch{}},POe=(e,A)=>{if(typeof window>"u")return A;try{const t=localStorage.getItem(e);return t!==null?JSON.parse(t):A}catch{return A}},qOe=(e,A)=>{if(!(typeof window>"u"))try{localStorage.setItem(e,JSON.stringify(A))}catch{}},OOe="named_only",WOe=(e={},A=!1)=>Qat(t=>({selected_layer:"top",pcb_viewer_id:`pcb_viewer_${Math.random().toString().slice(2,10)}`,in_edit_mode:!1,in_move_footprint_mode:!1,in_draw_trace_mode:!1,is_moving_component:!1,is_drawing_trace:!1,is_mouse_over_container:!1,is_showing_multiple_traces_length:!1,is_showing_rats_nest:!1,is_showing_autorouting:!0,is_showing_drc_errors:!0,is_showing_copper_pours:t9(vD.IS_SHOWING_COPPER_POURS,!0),is_showing_pcb_groups:A?!1:t9(vD.IS_SHOWING_PCB_GROUPS,!0),is_showing_group_anchor_offsets:t9(vD.IS_SHOWING_GROUP_ANCHOR_OFFSETS,!0),is_showing_solder_mask:t9(vD.IS_SHOWING_SOLDER_MASK,!1),pcb_group_view_mode:A?"all":POe(vD.PCB_GROUP_VIEW_MODE,OOe),hovered_error_id:null,...e,selectLayer:i=>t({selected_layer:i}),setEditMode:i=>t({in_edit_mode:i!=="off",in_move_footprint_mode:i==="move_footprint",in_draw_trace_mode:i==="draw_trace",is_moving_component:!1,is_drawing_trace:!1}),setIsShowingRatsNest:i=>t({is_showing_rats_nest:i}),setIsMovingComponent:i=>t({is_moving_component:i}),setIsDrawingTrace:i=>t({is_drawing_trace:i}),setIsMouseOverContainer:i=>t({is_mouse_over_container:i}),setIsShowingMultipleTracesLength:i=>t({is_showing_multiple_traces_length:i}),setIsShowingAutorouting:i=>t({is_showing_autorouting:i}),setIsShowingDrcErrors:i=>t({is_showing_drc_errors:i}),setIsShowingCopperPours:i=>{e9(vD.IS_SHOWING_COPPER_POURS,i),t({is_showing_copper_pours:i})},setIsShowingPcbGroups:i=>{A||(e9(vD.IS_SHOWING_PCB_GROUPS,i),t({is_showing_pcb_groups:i}))},setIsShowingGroupAnchorOffsets:i=>{e9(vD.IS_SHOWING_GROUP_ANCHOR_OFFSETS,i),t({is_showing_group_anchor_offsets:i})},setIsShowingSolderMask:i=>{e9(vD.IS_SHOWING_SOLDER_MASK,i),t({is_showing_solder_mask:i})},setPcbGroupViewMode:i=>{A||(qOe(vD.PCB_GROUP_VIEW_MODE,i),t({pcb_group_view_mode:i}))},setHoveredErrorId:i=>t({hovered_error_id:i})})),zB=e=>{const A=AA.useContext(Rgt);return Dat(A,e)},Rgt=AA.createContext(null),ZOe=({children:e,initialState:A,disablePcbGroups:t})=>{const i=AA.useMemo(()=>WOe(A,t),[t]);return Z.jsx(Rgt.Provider,{value:i,children:e})},VOe=()=>{const e=zB(t=>t.pcb_viewer_id),A=(t,i)=>qg(t,{containerId:e,...i});return A.error=(t,i)=>qg.error(t,{containerId:e,...i}),A.promise=qg.promise,A},jOe=()=>{AA.useEffect(()=>{Oqe()},[]);const e=zB(A=>A.pcb_viewer_id);return Z.jsx(qqe,{position:"top-center",containerId:e})};function zOe(){var e=AA.useRef(!1),A=AA.useCallback(function(){return e.current},[]);return AA.useEffect(function(){return e.current=!0,function(){e.current=!1}},[]),A}var XOe=function(e){e===void 0&&(e={});var A=AA.useState(e),t=A[0],i=A[1],n=AA.useCallback(function(o){i(function(s){return Object.assign({},s,o instanceof Function?o(s):o)})},[]);return[t,n]},$Oe=XOe,A5e=function(){},Ngt=typeof window<"u",t5e=GpA(pOe()),e5e=function(){var e=zOe(),A=$Oe({value:void 0,error:void 0,noUserInteraction:!0}),t=A[0],i=A[1],n=AA.useCallback(function(o){if(e()){var s,r;try{if(typeof o!="string"&&typeof o!="number"){var a=new Error("Cannot copy typeof "+typeof o+" to clipboard, must be a string");console.error(a),i({value:o,error:a,noUserInteraction:!0});return}else if(o===""){var a=new Error("Cannot copy empty string to clipboard.");console.error(a),i({value:o,error:a,noUserInteraction:!0});return}r=o.toString(),s=(0,t5e.default)(r),i({value:r,error:void 0,noUserInteraction:s})}catch(g){i({value:r,error:g,noUserInteraction:s})}}},[]);return[t,n]},i5e=e5e,n5e=Ngt?AA.useLayoutEffect:AA.useEffect,o5e=n5e,vgt={x:0,y:0,width:0,height:0,top:0,left:0,bottom:0,right:0};function s5e(){var e=AA.useState(null),A=e[0],t=e[1],i=AA.useState(vgt),n=i[0],o=i[1],s=AA.useMemo(function(){return new window.ResizeObserver(function(r){if(r[0]){var a=r[0].contentRect,g=a.x,c=a.y,I=a.width,l=a.height,B=a.top,C=a.left,E=a.bottom,Q=a.right;o({x:g,y:c,width:I,height:l,top:B,left:C,bottom:E,right:Q})}})},[]);return o5e(function(){if(A)return s.observe(A),function(){s.disconnect()}},[A]),[t,n]}var zY=Ngt&&typeof window.ResizeObserver<"u"?s5e:function(){return[A5e,vgt]},Lgt=({initialTransform:e,initialTouch1:A,initialTouch2:t,finalTouch1:i,finalTouch2:n})=>{if(!i||!n)return e;const o={x:(A.x+t.x)/2,y:(A.y+t.y)/2},s={x:(i.x+n.x)/2,y:(i.y+n.y)/2},r=Math.hypot(t.x-A.x,t.y-A.y),a=Math.hypot(n.x-i.x,n.y-i.y),g=r===0?1:a/r,c=s.x-o.x,I=s.y-o.y;return Oy(rB(c,I),rB(o.x,o.y),JY(g,g),rB(-o.x,-o.y),e)},r5e=(e={})=>{const A=AA.useRef(null),[t,i]=AA.useState(0),n=e.canvasElm??A.current,[o,s]=AA.useState(e.initialTransform??yb()),[r,a]=AA.useState(0),[g,c]=AA.useReducer(d=>d+1,0),I=AA.useCallback(d=>{e.onSetTransform&&e.onSetTransform(d),e.transform||s(d)},[e.onSetTransform,s]),l=AA.useCallback(d=>{I(d),c()},[I]),B=e.transform??o,C=AA.useCallback(()=>{i(Date.now())},[]),E=AA.useRef("none"),Q=AA.useRef(null),h=AA.useRef(null);AA.useEffect(()=>{const d=e.canvasElm??A.current;if(d&&!n){a(r+1);return}if(!d){const W=setTimeout(()=>{a(r+1)},100);return()=>clearTimeout(W)}let f=e.transform??o,m={x:0,y:0},w={x:0,y:0},D=!1;const b=W=>({x:W.pageX-d.getBoundingClientRect().left-window.scrollX,y:W.pageY-d.getBoundingClientRect().top-window.scrollY});function k(W){e.enabled!==!1&&(e.shouldDrag&&!e.shouldDrag(W)||(m=b(W),!(Date.now()-t<100)&&(D=!0,W.preventDefault())))}function x(W){if(!D||e.enabled===!1||e.shouldDrag&&!e.shouldDrag(W))return;w=b(W);const X=Oy(rB(w.x-m.x,w.y-m.y),f);I(X),f=X,D=!1}function N(W){if(b(W),!D||e.enabled===!1||e.shouldDrag&&!e.shouldDrag(W))return;w=b(W);const X=Oy(rB(w.x-m.x,w.y-m.y),f);I(X)}function R(W){if(e.enabled===!1||e.shouldDrag&&!e.shouldDrag(W))return;const X=b(W),iA=Oy(rB(X.x,X.y),JY(1-W.deltaY/1e3,1-W.deltaY/1e3),rB(-X.x,-X.y),f);I(iA),f=iA,W.preventDefault()}function U(W){if(!D||e.shouldDrag&&!e.shouldDrag(W))return;if(d){const iA=d.getBoundingClientRect();if(W.clientX>=iA.left+10&&W.clientX<=iA.right-10&&W.clientY>=iA.top+10&&W.clientY<=iA.bottom-10)return}D=!1,w=b(W);const X=Oy(rB(w.x-m.x,w.y-m.y),f);I(X),f=X}function T(W){if(W.preventDefault(),e.enabled!==!1){if(W.touches.length===1){E.current="drag";const X=W.touches[0];Q.current={initialTransform:f,initialTouch:{x:X.clientX,y:X.clientY}}}else if(W.touches.length===2){E.current="pinch";const X=W.touches[0],iA=W.touches[1];h.current={initialTransform:f,initialTouch1:{x:X.clientX,y:X.clientY},initialTouch2:{x:iA.clientX,y:iA.clientY},finalTouch1:null,finalTouch2:null}}}}function H(W){if(W.preventDefault(),e.enabled!==!1){if(E.current==="drag"&&W.touches.length===1&&Q.current){const X=W.touches[0],iA={x:X.clientX,y:X.clientY},aA=iA.x-Q.current.initialTouch.x,tA=iA.y-Q.current.initialTouch.y,oA=Oy(rB(aA,tA),Q.current.initialTransform);I(oA)}else if(E.current==="pinch"&&W.touches.length===2&&h.current){const X=W.touches[0],iA=W.touches[1];h.current.finalTouch1={x:X.clientX,y:X.clientY},h.current.finalTouch2={x:iA.clientX,y:iA.clientY};const aA=Lgt(h.current);I(aA)}}}function O(W){W.preventDefault();const X=W.changedTouches[0];if(E.current==="drag"&&Q.current&&X){const iA={x:X.clientX,y:X.clientY},aA=iA.x-Q.current.initialTouch.x,tA=iA.y-Q.current.initialTouch.y,oA=Oy(rB(aA,tA),Q.current.initialTransform);I(oA),f=oA}else if(E.current==="pinch"&&h.current){const iA=Lgt(h.current);I(iA),f=iA}E.current="none",Q.current=null,h.current=null}return d.addEventListener("mousedown",k),d.addEventListener("mouseup",x),window.addEventListener("mousemove",N),d.addEventListener("mouseout",U),d.addEventListener("wheel",R),d.addEventListener("touchstart",T,{passive:!1}),d.addEventListener("touchmove",H,{passive:!1}),d.addEventListener("touchend",O,{passive:!1}),d.addEventListener("touchcancel",O,{passive:!1}),()=>{d.removeEventListener("mousedown",k),d.removeEventListener("mouseup",x),window.removeEventListener("mousemove",N),d.removeEventListener("mouseout",U),d.removeEventListener("wheel",R),d.removeEventListener("touchstart",T),d.removeEventListener("touchmove",H),d.removeEventListener("touchend",O),d.removeEventListener("touchcancel",O)}},[n,r,g,t,e.enabled,e.shouldDrag]);const u=AA.useCallback(d=>qi(B,d),[B]);return{ref:A,transform:B,applyTransformToPoint:u,setTransform:l,cancelDrag:C}},a5e=r5e;function g5e(e){const A=new Map;let t=0;function i(n){for(const[,s]of A)if(s.has(n))return s;const o=new Set;return A.set(`connectivity_net${t++}`,o),o}for(const n of e){let o=null;for(const s of n){if(!o)o=i(s);else if(!o.has(s)){const r=i(s);if(r!==o){for(const a of r)o.add(a);A.delete(Array.from(A.entries()).find(([,a])=>a===r)[0])}}o.add(s)}}return Object.fromEntries(Array.from(A.entries()).map(([n,o])=>[n,Array.from(o)]))}var c5e=class{netMap;idToNetMap;constructor(e){this.netMap=e,this.idToNetMap={};for(const[A,t]of Object.entries(e))for(const i of t)this.idToNetMap[i]=A}addConnections(e){for(const A of e){const t=new Set;for(const n of A){const o=this.idToNetMap[n];o&&t.add(o)}let i;if(t.size===0)i=`connectivity_net${Object.keys(this.netMap).length}`,this.netMap[i]=[];else if(t.size===1)i=t.values().next().value??`connectivity_net${Object.keys(this.netMap).length}`;else{i=t.values().next().value??`connectivity_net${Object.keys(this.netMap).length}`;for(const n of t)if(n!==i){this.netMap[i].push(...this.netMap[n]),this.netMap[n]=this.netMap[i];for(const o of this.netMap[i])this.idToNetMap[o]=i}}for(const n of A)this.netMap[i].includes(n)||this.netMap[i].push(n),this.idToNetMap[n]=i}}getIdsConnectedToNet(e){return this.netMap[e]||[]}getNetConnectedToId(e){return this.idToNetMap[e]}areIdsConnected(e,A){if(e===A)return!0;const t=this.getNetConnectedToId(e);if(!t)return!1;const i=this.getNetConnectedToId(A);return i?t===i||i===e||i===e:!1}areAllIdsConnected(e){const A=this.getNetConnectedToId(e[0]);for(const t of e){const i=this.getNetConnectedToId(t);if(i===void 0||i!==A)return!1}return!0}},Ugt=e=>{const A=[];for(const i of e)if(i.type==="source_trace")A.push([i.source_trace_id,...i.connected_source_port_ids??[],...i.connected_source_net_ids??[]].filter(Boolean));else if(i.type==="pcb_port"){const{pcb_port_id:n,source_port_id:o}=i;o&&n&&A.push([o,n])}else if(i.type==="pcb_smtpad"){const{pcb_smtpad_id:n,pcb_port_id:o}=i;o&&n&&A.push([n,o])}else if(i.type==="pcb_plated_hole"){const{pcb_plated_hole_id:n,pcb_port_id:o}=i;o&&n&&A.push([n,o])}else if(i.type==="pcb_trace"){const{pcb_trace_id:n,source_trace_id:o}=i,s=Array.isArray(i.route)?i.route.filter(r=>r&&r.route_type==="wire"):[];if(o&&n&&A.push([n,o]),Array.isArray(s)){const r=s.find(g=>g?.start_pcb_port_id)?.start_pcb_port_id,a=s.find(g=>g?.end_pcb_port_id)?.end_pcb_port_id;r&&n&&a&&A.push([r,n,a])}}else if(i.type==="pcb_via"){const{pcb_via_id:n,pcb_trace_id:o}=i;o&&n&&A.push([n,o])}else if(i.type==="source_component"&&i.internally_connected_source_port_ids)for(const n of i.internally_connected_source_port_ids)A.push(n);const t=g5e(A);return new c5e(t)};function I5e({primitivesWithoutInteractionMetadata:e,drawingObjectIdsWithMouseOver:A,primitiveIdsInMousedOverNet:t}){const i=[];for(const n of e){const o={...n};n?.layer==="drill"?(o.is_in_highlighted_net=!1,o.is_mouse_over=!1):A.has(n._pcb_drawing_object_id)?o.is_mouse_over=!0:n._element&&("pcb_trace_id"in n._element&&t.includes(n._element.pcb_trace_id)||"pcb_port_id"in n._element&&t.includes(n._element.pcb_port_id))?o.is_in_highlighted_net=!0:(o.is_in_highlighted_net=!1,o.is_mouse_over=!1),i.push(o)}return i}function l5e(e,A){if(e.length<2)throw new Error("Stroke must have at least two points");const t=e.map(I=>Array.isArray(I)?{x:I[0],y:I[1]}:I),i=[],n=[];function o(I,l){const B=l.x-I.x,C=l.y-I.y,E=Math.sqrt(B*B+C*C);return{x:-C/E,y:B/E}}function s(I,l,B,C){const E=C/2,Q={x:I.x+l.x*E*B,y:I.y+l.y*E*B};B>0?i.push(Q):n.unshift(Q)}const r=o(t[0],t[1]),a=t[0].trace_width??A;s(t[0],r,1,a),s(t[0],r,-1,a);for(let I=1;I<t.length-1;I++){const l=t[I-1],B=t[I],C=t[I+1],E=o(l,B),Q=o(B,C),h=E.x+Q.x,u=E.y+Q.y,d=Math.sqrt(h*h+u*u),f=B.trace_width??A;if(d/2>2*(f/2))s(B,E,1,f),s(B,Q,1,f),s(B,E,-1,f),s(B,Q,-1,f);else{const w=1/d;s(B,{x:h*w,y:u*w},1,f),s(B,{x:h*w,y:u*w},-1,f)}}const g=o(t[t.length-2],t[t.length-1]),c=t[t.length-1].trace_width??A;return s(t[t.length-1],g,1,c),s(t[t.length-1],g,-1,c),[...i,...n]}var B5e=(e,A)=>{const{x:t,y:i,width:n,height:o,layer:s,rect_border_radius:r}=e,a=e.corner_radius??r??0,g=[{_pcb_drawing_object_id:Wy("rect"),pcb_drawing_type:"rect",x:t,y:i,w:n,h:o,layer:s||"top",_element:e,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,roundness:a,...e.shape==="rotated_rect"&&e.ccw_rotation!==void 0?{ccw_rotation:e.ccw_rotation}:{}}];if(e.is_covered_with_solder_mask){const c=s==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",l={...{_pcb_drawing_object_id:Wy("rect"),pcb_drawing_type:"rect",x:t,y:i,w:n,h:o,layer:c,_element:e,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,roundness:a,...e.shape==="rotated_rect"&&e.ccw_rotation!==void 0?{ccw_rotation:e.ccw_rotation}:{}},..."solder_mask_color"in e&&e.solder_mask_color?{color:e.solder_mask_color}:{}};g.push(l)}return g},C5e=(e,A)=>{const{x:t,y:i,radius:n,layer:o}=e,s=[{_pcb_drawing_object_id:Wy("circle"),pcb_drawing_type:"circle",x:t,y:i,r:n,layer:o||"top",_element:e,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port}];if(e.is_covered_with_solder_mask){const r=o==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",a={_pcb_drawing_object_id:Wy("circle"),pcb_drawing_type:"circle",x:t,y:i,r:n,layer:r,_element:e,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,..."solder_mask_color"in e&&e.solder_mask_color?{color:e.solder_mask_color}:{}};s.push(a)}return s},Q5e=(e,A)=>{const{layer:t,points:i}=e,n=[{_pcb_drawing_object_id:Wy("polygon"),pcb_drawing_type:"polygon",points:HpA(i),layer:t||"top",_element:e,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port}];if(e.is_covered_with_solder_mask){const o=t==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",s={_pcb_drawing_object_id:Wy("polygon"),pcb_drawing_type:"polygon",points:HpA(i),layer:o,_element:e,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,..."solder_mask_color"in e&&e.solder_mask_color?{color:e.solder_mask_color}:{}};n.push(s)}return n},E5e=(e,A)=>{const{x:t,y:i,width:n,height:o,layer:s}=e,r=[{_pcb_drawing_object_id:Wy("pill"),pcb_drawing_type:"pill",x:t,y:i,w:n,h:o,layer:s||"top",_element:e,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port}];if(e.is_covered_with_solder_mask){const a=s==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",g={_pcb_drawing_object_id:Wy("pill"),pcb_drawing_type:"pill",x:t,y:i,w:n,h:o,layer:a,_element:e,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,..."solder_mask_color"in e&&e.solder_mask_color?{color:e.solder_mask_color}:{}};r.push(g)}return r},h5e=(e,A)=>{const{x:t,y:i,width:n,height:o,layer:s,ccw_rotation:r}=e,a=[{_pcb_drawing_object_id:Wy("pill"),pcb_drawing_type:"pill",x:t,y:i,w:n,h:o,layer:s||"top",_element:e,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,ccw_rotation:r}];if(e.is_covered_with_solder_mask){const g=s==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",c={_pcb_drawing_object_id:Wy("pill"),pcb_drawing_type:"pill",x:t,y:i,w:n,h:o,layer:g,_element:e,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,ccw_rotation:r,..."solder_mask_color"in e&&e.solder_mask_color?{color:e.solder_mask_color}:{}};a.push(c)}return a},u5e=(e,A)=>{const{_parent_pcb_component:t,_parent_source_component:i}=A,n=e,o=typeof n.font_size=="string"?he.parse(n.font_size):n.font_size??.2;let s;return n.knockout_padding&&(s={left:typeof n.knockout_padding.left=="string"?he.parse(n.knockout_padding.left):n.knockout_padding.left,top:typeof n.knockout_padding.top=="string"?he.parse(n.knockout_padding.top):n.knockout_padding.top,bottom:typeof n.knockout_padding.bottom=="string"?he.parse(n.knockout_padding.bottom):n.knockout_padding.bottom,right:typeof n.knockout_padding.right=="string"?he.parse(n.knockout_padding.right):n.knockout_padding.right}),[{_pcb_drawing_object_id:Wy("text"),pcb_drawing_type:"text",x:n.anchor_position.x,y:n.anchor_position.y,layer:n.layer,align:n.anchor_alignment??"center",text:n.text,size:o,ccw_rotation:n.ccw_rotation,is_mirrored:n.is_mirrored,is_knockout:n.is_knockout,knockout_padding:s,_element:e,_parent_pcb_component:t,_parent_source_component:i}]},SI=0,Wy=e=>`${e}_${SI++}`,HpA=e=>(e??[]).map(A=>({x:he.parse(A.x),y:he.parse(A.y)})),d5e=(e,A)=>{const t="pcb_component_id"in e?A.find(s=>s.type==="pcb_component"&&s.pcb_component_id===e.pcb_component_id):void 0,i=t&&"source_component_id"in t?A.find(s=>s.type==="source_component"&&s.source_component_id===t.source_component_id):void 0,n="source_port_id"in e?e.source_port_id:"pcb_port_id"in e?Db(A).pcb_port.get(e.pcb_port_id)?.source_port_id:void 0,o=n?A.find(s=>s.type==="source_port"&&s.source_port_id===n):void 0;switch(e.type){case"pcb_smtpad":{const s={_parent_pcb_component:t,_parent_source_component:i,_source_port:o};return e.shape==="rect"||e.shape==="rotated_rect"?B5e(e,s):e.shape==="circle"?C5e(e,s):e.shape==="polygon"?Q5e(e,s):e.shape==="pill"?E5e(e,s):e.shape==="rotated_pill"?h5e(e,s):[]}case"pcb_trace":{const s=[];if(e.route_thickness_mode==="interpolated"){const g=e.route.map(l=>({x:l.x,y:l.y,trace_width:l.route_type==="wire"?l.width:.5})),c=l5e(g,.5),I=e.route[0].layer;return s.push({_pcb_drawing_object_id:`polygon_${SI++}`,_element:e,pcb_drawing_type:"polygon",points:c,layer:I}),e.route.forEach(l=>{l.route_type==="via"&&s.push({_pcb_drawing_object_id:`circle_${SI++}`,_element:e,pcb_drawing_type:"circle",x:l.x,y:l.y,r:l.outer_diameter/2,layer:l.from_layer})}),s}let r=null,a=null;for(const g of e.route)g.route_type==="wire"&&(r!==null&&a!==null&&s.push({_pcb_drawing_object_id:`line_${SI++}`,_element:e,pcb_drawing_type:"line",x1:r,y1:a,x2:g.x,y2:g.y,width:g.width,squareCap:!1,layer:g.layer}),r=g.x,a=g.y);return s}case"pcb_via":{const{x:s,y:r,outer_diameter:a,hole_diameter:g}=e,c=e.from_layer,I=e.to_layer,l=e.layers,B=[];c&&I?B.push(c,I):l&&Array.isArray(l)?B.push(...l):B.push("top","bottom");const C=[];for(const E of B)C.push({_pcb_drawing_object_id:`circle_${SI++}`,pcb_drawing_type:"circle",x:s,y:r,r:a/2,layer:E,_element:e,_parent_pcb_component:t,_parent_source_component:i});return C.push({_pcb_drawing_object_id:`circle_${SI++}`,pcb_drawing_type:"circle",x:s,y:r,r:g/2,layer:"drill",_element:e}),C}case"pcb_plated_hole":if(e.shape==="circle"){const{x:s,y:r,hole_diameter:a,outer_diameter:g}=e;return[{_pcb_drawing_object_id:`circle_${SI++}`,pcb_drawing_type:"circle",x:s,y:r,r:g/2,layer:"top",_element:e,_parent_pcb_component:t,_parent_source_component:i,_source_port:o},{_pcb_drawing_object_id:`circle_${SI++}`,pcb_drawing_type:"circle",x:s,y:r,r:a/2,layer:"drill",_element:e}]}else if(e.shape==="oval"){const{x:s,y:r,outer_height:a,outer_width:g,hole_height:c,hole_width:I}=e;return[{_pcb_drawing_object_id:`oval_${SI++}`,pcb_drawing_type:"oval",x:s,y:r,rX:g/2,rY:a/2,layer:"top",_element:e,_parent_pcb_component:t,_parent_source_component:i,_source_port:o},{_pcb_drawing_object_id:`oval_${SI++}`,_element:e,pcb_drawing_type:"oval",x:s,y:r,rX:I/2,rY:c/2,layer:"drill"}]}else if(e.shape==="pill"){const{x:s,y:r,outer_height:a,outer_width:g,hole_height:c,hole_width:I}=e;return[{_pcb_drawing_object_id:`pill_${SI++}`,pcb_drawing_type:"pill",x:s,y:r,w:g,h:a,layer:"top",_element:e,_parent_pcb_component:t,_parent_source_component:i,_source_port:o,ccw_rotation:e.ccw_rotation},{_pcb_drawing_object_id:`pill_${SI++}`,_element:e,pcb_drawing_type:"pill",x:s,y:r,w:I,h:c,layer:"drill",ccw_rotation:e.ccw_rotation}]}else if(e.shape==="circular_hole_with_rect_pad"){const{x:s,y:r,hole_diameter:a,rect_pad_width:g,rect_pad_height:c,rect_border_radius:I,hole_offset_x:l,hole_offset_y:B}=e,C=he.parse(l??0),E=he.parse(B??0);return[{_pcb_drawing_object_id:`rect_${SI++}`,pcb_drawing_type:"rect",x:s,y:r,w:g,h:c,layer:"top",_element:e,_parent_pcb_component:t,_parent_source_component:i,_source_port:o,roundness:I},{_pcb_drawing_object_id:`rect_${SI++}`,pcb_drawing_type:"rect",x:s,y:r,w:g,h:c,layer:"bottom",_element:e,_parent_pcb_component:t,_parent_source_component:i,_source_port:o,roundness:I},{_pcb_drawing_object_id:`circle_${SI++}`,_element:e,pcb_drawing_type:"circle",x:s+C,y:r+E,r:a/2,layer:"drill"}]}else if(e.shape==="pill_hole_with_rect_pad"){const{x:s,y:r,hole_width:a,hole_height:g,rect_pad_width:c,rect_pad_height:I,rect_border_radius:l}=e;return[{_pcb_drawing_object_id:`rect_${SI++}`,pcb_drawing_type:"rect",x:s,y:r,w:c,h:I,layer:"top",_element:e,_parent_pcb_component:t,_parent_source_component:i,_source_port:o,roundness:l},{_pcb_drawing_object_id:`rect_${SI++}`,pcb_drawing_type:"rect",x:s,y:r,w:c,h:I,layer:"bottom",_element:e,_parent_pcb_component:t,_parent_source_component:i,_source_port:o,roundness:l},{_pcb_drawing_object_id:`pill_${SI++}`,_element:e,pcb_drawing_type:"pill",x:s,y:r,w:a,h:g,layer:"drill"}]}else if(e.shape==="rotated_pill_hole_with_rect_pad"){const{x:s,y:r,hole_width:a,hole_height:g,hole_ccw_rotation:c,rect_pad_width:I,rect_pad_height:l,rect_ccw_rotation:B,rect_border_radius:C}=e;return[{_pcb_drawing_object_id:`rect_${SI++}`,pcb_drawing_type:"rect",x:s,y:r,w:I,h:l,layer:"top",_element:e,_parent_pcb_component:t,_parent_source_component:i,_source_port:o,ccw_rotation:B,roundness:C},{_pcb_drawing_object_id:`rect_${SI++}`,pcb_drawing_type:"rect",x:s,y:r,w:I,h:l,layer:"bottom",_element:e,_parent_pcb_component:t,_parent_source_component:i,_source_port:o,ccw_rotation:B,roundness:C},{_pcb_drawing_object_id:`pill_${SI++}`,_element:e,pcb_drawing_type:"pill",x:s,y:r,w:a,h:g,layer:"drill",ccw_rotation:c}]}else if(e.shape==="hole_with_polygon_pad"){const{x:s,y:r,pad_outline:a,hole_shape:g,hole_diameter:c,hole_width:I,hole_height:l,layers:B,hole_offset_x:C,hole_offset_y:E}=e,Q=he.parse(C??0),h=he.parse(E??0),u=a,d=[];if(u&&Array.isArray(u)){const w=HpA(u).map(D=>({x:D.x+s,y:D.y+r}));for(const D of B||["top","bottom"])d.push({_pcb_drawing_object_id:`polygon_${SI++}`,pcb_drawing_type:"polygon",points:w,layer:D,_element:e,_parent_pcb_component:t,_parent_source_component:i,_source_port:o})}const f={x:s+Q,y:r+h},m=[];return g==="circle"?m.push({_pcb_drawing_object_id:`circle_${SI++}`,pcb_drawing_type:"circle",x:f.x,y:f.y,r:(c??0)/2,layer:"drill",_element:e,_parent_pcb_component:t,_parent_source_component:i}):g==="oval"?m.push({_pcb_drawing_object_id:`oval_${SI++}`,pcb_drawing_type:"oval",x:f.x,y:f.y,rX:(I??0)/2,rY:(l??0)/2,layer:"drill",_element:e,_parent_pcb_component:t,_parent_source_component:i}):(g==="pill"||g==="rotated_pill")&&m.push({_pcb_drawing_object_id:`pill_${SI++}`,pcb_drawing_type:"pill",x:f.x,y:f.y,w:I??0,h:l??0,layer:"drill",_element:e,_parent_pcb_component:t,_parent_source_component:i,ccw_rotation:e.ccw_rotation}),[...d,...m]}else return[];case"pcb_copper_text":return u5e(e,{_parent_pcb_component:t,_parent_source_component:i})}return[]},In={board:{anchor:"rgb(255, 38, 226)",aux_items:"rgb(255, 255, 255)",b_adhes:"rgb(0, 0, 132)",b_crtyd:"rgb(38, 233, 255)",b_fab:"rgb(88, 93, 132)",b_mask:"rgba(2, 255, 238, 0.400)",b_paste:"rgb(0, 194, 194)",b_silks:"rgb(242, 237, 161)",background:"rgb(0, 16, 35)",cmts_user:"rgb(89, 148, 220)",copper:{b:"rgb(77, 127, 196)",f:"rgb(200, 52, 52)",in1:"rgb(127, 200, 127)",in10:"rgb(237, 124, 51)",in11:"rgb(91, 195, 235)",in12:"rgb(247, 111, 142)",in13:"rgb(167, 165, 198)",in14:"rgb(40, 204, 217)",in15:"rgb(232, 178, 167)",in16:"rgb(242, 237, 161)",in17:"rgb(237, 124, 51)",in18:"rgb(91, 195, 235)",in19:"rgb(247, 111, 142)",in2:"rgb(206, 125, 44)",in20:"rgb(167, 165, 198)",in21:"rgb(40, 204, 217)",in22:"rgb(232, 178, 167)",in23:"rgb(242, 237, 161)",in24:"rgb(237, 124, 51)",in25:"rgb(91, 195, 235)",in26:"rgb(247, 111, 142)",in27:"rgb(167, 165, 198)",in28:"rgb(40, 204, 217)",in29:"rgb(232, 178, 167)",in3:"rgb(79, 203, 203)",in30:"rgb(242, 237, 161)",in4:"rgb(219, 98, 139)",in5:"rgb(167, 165, 198)",in6:"rgb(40, 204, 217)",in7:"rgb(232, 178, 167)",in8:"rgb(242, 237, 161)",in9:"rgb(141, 203, 129)"},cursor:"rgb(255, 255, 255)",drc:"rgb(194, 194, 194)",drc_error:"rgba(215, 91, 107, 0.800)",drc_exclusion:"rgb(255, 255, 255)",drc_warning:"rgba(255, 208, 66, 0.902)",dwgs_user:"rgb(194, 194, 194)",eco1_user:"rgb(180, 219, 210)",eco2_user:"rgb(216, 200, 82)",edge_cuts:"rgb(208, 210, 205)",f_adhes:"rgb(132, 0, 132)",f_crtyd:"rgb(255, 0, 245)",f_fab:"rgb(175, 175, 175)",f_mask:"rgba(216, 100, 255, 0.400)",f_paste:"rgba(180, 160, 154, 0.902)",f_silks:"rgb(242, 237, 161)",footprint_text_back:"rgb(0, 0, 132)",footprint_text_front:"rgb(194, 194, 194)",footprint_text_invisible:"rgb(132, 132, 132)",grid:"rgb(132, 132, 132)",grid_axes:"rgb(194, 194, 194)",margin:"rgb(255, 38, 226)",microvia:"rgb(0, 132, 132)",no_connect:"rgb(0, 0, 132)",pad_back:"rgb(77, 127, 196)",pad_front:"rgb(200, 52, 52)",pad_plated_hole:"rgb(194, 194, 0)",pad_through_hole:"rgb(227, 183, 46)",plated_hole:"rgb(26, 196, 210)",ratsnest:"rgba(245, 255, 213, 0.702)",select_overlay:"rgb(4, 255, 67)",soldermaskWithCopper:{top:"rgb(18, 82, 50)",bottom:"rgb(77, 127, 196)"},soldermask:{top:"rgb(12, 55, 33)",bottom:"rgb(12, 55, 33)"},through_via:"rgb(236, 236, 236)",user_1:"rgb(194, 194, 194)",user_2:"rgb(89, 148, 220)",user_3:"rgb(180, 219, 210)",user_4:"rgb(216, 200, 82)",user_5:"rgb(194, 194, 194)",user_6:"rgb(89, 148, 220)",user_7:"rgb(180, 219, 210)",user_8:"rgb(216, 200, 82)",user_9:"rgb(232, 178, 167)",via_blind_buried:"rgb(187, 151, 38)",via_hole:"rgb(227, 183, 46)",via_micro:"rgb(0, 132, 132)",via_through:"rgb(236, 236, 236)",worksheet:"rgb(200, 114, 171)"}},Cf=(e,A=1)=>{if(Math.abs(e.a)!==Math.abs(e.d))throw new Error("Cannot scale non-uniformly");return A*Math.abs(e.a)},Qc={elementOverlay:40,dimensionOverlay:40,editTraceHintOverlay:40,errorOverlay:40,pcbGroupOverlay:35,ratsNestOverlay:30,toolbarOverlay:70,warnings:30,topLayer:20,clickToInteractOverlay:100},i9={red:"red",black:"black",green:"green",board:"rgb(255, 255, 255)",other:"#eee",top:In.board.copper.f,inner1:In.board.copper.in1,inner2:In.board.copper.in2,inner3:In.board.copper.in3,inner4:In.board.copper.in4,inner5:In.board.copper.in5,inner6:In.board.copper.in6,inner7:In.board.copper.in7,inner8:In.board.copper.in8,bottom:In.board.copper.b,drill:In.board.anchor,keepout:In.board.background,tkeepout:In.board.b_crtyd,tplace:In.board.b_silks,top_courtyard:In.board.f_crtyd,bottom_courtyard:In.board.b_crtyd,top_silkscreen:In.board.f_silks,bottom_silkscreen:In.board.b_silks,top_fabrication:In.board.f_fab,bottom_fabrication:In.board.b_fab,soldermask_top:In.board.soldermask.top,soldermask_bottom:In.board.soldermask.bottom,soldermask_with_copper_top:In.board.soldermaskWithCopper.top,soldermask_with_copper_bottom:In.board.soldermaskWithCopper.bottom,bottom_notes:In.board.user_2,top_notes:In.board.user_2,...In.board},p5e=["board","inner6","inner5","inner4","inner3","inner2","inner1","bottom","soldermask_bottom","bottom_silkscreen","top","soldermask_top","bottom_courtyard","bottom_fabrication","top_courtyard","top_fabrication","edge_cuts","top_silkscreen"],f5e=class{canvasLayerMap;ctxLayerMap;aperture;transform;foregroundLayer="top";lastPoint;constructor(e){this.canvasLayerMap=e,this.ctxLayerMap=Object.fromEntries(Object.entries(e).map(([A,t])=>[A,t.getContext("2d")])),this.transform=yb(),this.transform.d*=-1,this.transform=Oy(this.transform,rB(0,-500)),this.lastPoint={x:0,y:0},this.equip({})}clear(){for(const e of Object.values(this.ctxLayerMap))e.clearRect(0,0,e.canvas.width,e.canvas.height)}equip(e){this.aperture={fontSize:0,shape:"circle",mode:"add",size:0,color:"red",layer:"top",opacity:this.foregroundLayer===e.color?1:.5,...e}}drawMeshPattern(e,A,t,i,n,o=45){const s=this.getLayerCtx(),[r,a]=qi(this.transform,[e,A]),[g,c]=qi(this.transform,[e+t,A+i]),I=Cf(this.transform,n);s.lineWidth=1,s.strokeStyle=this.aperture.color;const l=B=>{const C=Math.sin(B),E=Math.cos(B),Q=Math.sqrt((g-r)**2+(c-a)**2);for(let h=-Q;h<=Q;h+=I)s.beginPath(),s.moveTo(r+h*E-Q*C,a+h*C+Q*E),s.lineTo(r+h*E+Q*C,a+h*C-Q*E),s.stroke()};l(o*Math.PI/180),l((o+90)*Math.PI/180)}rect({x:e,y:A,w:t,h:i,mesh_fill:n,is_filled:o=!0,has_stroke:s,is_stroke_dashed:r,stroke_width:a,roundness:g}){const[c,I]=qi(this.transform,[e-t/2,A-i/2]),[l,B]=qi(this.transform,[e+t/2,A+i/2]);this.applyAperture();const C=this.getLayerCtx(),E=g?Cf(this.transform,g):0,Q=s===void 0?o===!1:s;if(n)C.save(),C.beginPath(),E>0&&C.roundRect?C.roundRect(c,I,l-c,B-I,E):C.rect(c,I,l-c,B-I),C.clip(),this.drawMeshPattern(e-t/2,A-i/2,t,i,.15),C.restore(),E>0&&C.roundRect?(C.beginPath(),C.roundRect(c,I,l-c,B-I,E),C.stroke()):C.strokeRect(c,I,l-c,B-I);else if(o!==!1&&(E>0&&C.roundRect?(C.beginPath(),C.roundRect(c,I,l-c,B-I,E),C.fill()):C.fillRect(c,I,l-c,B-I)),Q){const h=C.lineWidth;if(a!==void 0&&(C.lineWidth=Cf(this.transform,a)),r){let u=[];const d=Math.abs(this.transform.a);if(d>0){const m=.1*d,w=m*1.3;m>.5&&(u=[m,w])}C.setLineDash(u)}E>0&&C.roundRect?(C.beginPath(),C.roundRect(c,I,l-c,B-I,E),C.stroke()):C.strokeRect(c,I,l-c,B-I),r&&C.setLineDash([]),a!==void 0&&(C.lineWidth=h)}}rotatedRect(e,A,t,i,n,o,s){const r=this.getLayerCtx();this.applyAperture();const[a,g]=qi(this.transform,[e-t/2,A-i/2]),[c,I]=qi(this.transform,[e+t/2,A+i/2]),l=o?Cf(this.transform,o):0;r.save();const[B,C]=qi(this.transform,[e,A]);r.translate(B,C);const E=360-n;n&&r.rotate(E*Math.PI/180),r.translate(-B,-C),s?(r.beginPath(),l>0&&r.roundRect?r.roundRect(a,g,c-a,I-g,l):r.rect(a,g,c-a,I-g),r.clip(),this.drawMeshPattern(e-t/2,A-i/2,t,i,.15),l>0&&r.roundRect?(r.beginPath(),r.roundRect(a,g,c-a,I-g,l),r.stroke()):r.strokeRect(a,g,c-a,I-g)):l>0&&r.roundRect?(r.beginPath(),r.roundRect(a,g,c-a,I-g,l),r.fill()):r.fillRect(a,g,c-a,I-g),r.restore()}rotatedPill(e,A,t,i,n){const o=this.getLayerCtx();this.applyAperture(),o.save();const[s,r]=qi(this.transform,[e,A]);o.translate(s,r);const a=360-n;n&&o.rotate(a*Math.PI/180),o.translate(-s,-r),this.pill(e,A,t,i),o.restore()}circle(e,A,t,i,n=!0){const o=Cf(this.transform,t),[s,r]=qi(this.transform,[e,A]);this.applyAperture();const a=this.getLayerCtx();i?(a.save(),a.beginPath(),a.arc(s,r,o,0,2*Math.PI),a.clip(),this.drawMeshPattern(e-t,A-t,t*2,t*2,.15),a.restore(),a.beginPath(),a.arc(s,r,o,0,2*Math.PI),a.stroke()):(a.beginPath(),a.arc(s,r,o,0,2*Math.PI),a.fill())}oval(e,A,t,i){const n=Cf(this.transform,t),o=Cf(this.transform,i),[s,r]=qi(this.transform,[e,A]);this.applyAperture();const a=this.getLayerCtx();a.beginPath(),a.ellipse(s,r,n,o,0,0,2*Math.PI),a.fill(),a.closePath()}pill(e,A,t,i){const[n,o]=qi(this.transform,[e-t/2,A+i/2]),s=Cf(this.transform,t),r=Cf(this.transform,i),a=Math.min(s,r)/2;this.applyAperture();const g=this.getLayerCtx();g.beginPath(),g.arc(n+a,o+a,a,Math.PI,Math.PI*1.5),g.arc(n+s-a,o+a,a,Math.PI*1.5,0),g.arc(n+s-a,o+r-a,a,0,Math.PI*.5),g.arc(n+a,o+r-a,a,Math.PI*.5,Math.PI),g.fill(),g.closePath()}polygon(e){if(e.length<3)return;this.applyAperture();const A=this.getLayerCtx(),t=e.map(n=>qi(this.transform,[n.x,n.y]));A.beginPath(),A.moveTo(t[0][0],t[0][1]);for(let n=1;n<t.length;n++)A.lineTo(t[n][0],t[n][1]);A.closePath(),A.fill("evenodd");const i=Cf(this.transform,this.aperture.size);i>0&&(A.lineWidth=i,A.stroke())}debugText(e,A,t){const[i,n]=qi(this.transform,[A,t]);this.applyAperture();const o=this.getLayerCtx();o.font="10px sans-serif",o.fillText(e,i,n)}getLayerCtx(){const e=this.ctxLayerMap[this.aperture.layer];if(!e)throw new Error(`No context for layer "${this.aperture.layer}"`);return e}orderAndFadeLayers(){const{canvasLayerMap:e,foregroundLayer:A}=this,t=A==="top"?"soldermask_top":A==="bottom"?"soldermask_bottom":void 0,i=A==="top"?"top_silkscreen":A==="bottom"?"bottom_silkscreen":void 0,n=A==="top"?"top_notes":A==="bottom"?"bottom_notes":void 0,o=A==="top"?"top_fabrication":A==="bottom"?"bottom_fabrication":void 0,s=new Set([A,"drill","edge_cuts","other","board",...t?[t]:[],...i?[i]:[],...n?[n]:[],...o?[o]:[]]),r=[A,"edge_cuts",...t?[t]:[],...i?[i]:[],...n?[n]:[],...o?[o]:[]],a=A==="drill"?[]:["drill"],g=A==="drill"?["drill"]:[],c=[...p5e.filter(I=>!r.includes(I)),...a,A,...t?[t]:[],...g,"edge_cuts",...i?[i]:[],...n?[n]:[],...o?[o]:[]];c.forEach((I,l)=>{const B=e[I];B&&(B.style.zIndex=`${Qc.topLayer-(c.length-l)}`,B.style.opacity=s.has(I)?"1":"0.5")})}applyAperture(){const{transform:e,aperture:A}=this;let{size:t,mode:i,color:n,fontSize:o,layer:s}=A;s in this.ctxLayerMap||(this.aperture.layer="other");const r=this.getLayerCtx();if(!r)throw new Error(`No context for layer "${this.foregroundLayer}"`);if(n||(n="undefined"),r.lineWidth=Cf(e,t),r.lineCap="round",i==="add"){r.globalCompositeOperation="source-over";let a=i9[n.toLowerCase()];if(!a)try{a=Ga(n).rgb().toString()}catch{console.warn(`Invalid color format: '${n}'`),a="white"}r.fillStyle=a,r.strokeStyle=a}else r.globalCompositeOperation="destination-out",r.fillStyle="rgba(0,0,0,1)",r.strokeStyle="rgba(0,0,0,1)";r.font=`${Cf(mb(e),o)}px sans-serif`}moveTo(e,A){this.lastPoint={x:e,y:A}}lineTo(e,A){const[t,i]=qi(this.transform,[e,A]),{size:n,shape:o,mode:s}=this.aperture,r=Cf(this.transform,n),{lastPoint:a}=this,g=qi(this.transform,a);this.applyAperture();const c=this.getLayerCtx();o==="square"&&c.fillRect(g.x-r/2,g.y-r/2,r,r),c.beginPath(),c.moveTo(g.x,g.y),c.lineTo(t,i),c.stroke(),c.closePath(),o==="square"&&c.fillRect(t-r/2,i-r/2,r,r),this.lastPoint={x:e,y:A}}polygonWithArcs(e){const A=this.getLayerCtx(),t=i=>{if(i.vertices.length===0)return;const n=i.vertices[0],o=qi(this.transform,[n.x,n.y]);A.moveTo(o[0],o[1]);for(let s=0;s<i.vertices.length;s++){const r=i.vertices[s],a=i.vertices[(s+1)%i.vertices.length];if(r.bulge&&r.bulge!==0){const g=r.bulge,c=a.x-r.x,I=a.y-r.y,l=Math.sqrt(c*c+I*I);if(l<1e-9){const R=qi(this.transform,[a.x,a.y]);A.lineTo(R[0],R[1]);continue}const B=4*Math.atan(g),C=Math.abs(l/(2*Math.sin(B/2))),E=(r.x+a.x)/2,Q=(r.y+a.y)/2,h=c/l,d=-(I/l),f=h,m=Math.sqrt(Math.max(0,C*C-(l/2)**2)),w=E+m*d*Math.sign(g),D=Q+m*f*Math.sign(g),b=Math.atan2(r.y-D,r.x-w);let k=Math.atan2(a.y-D,a.x-w);g>0&&k<b?k+=2*Math.PI:g<0&&k>b&&(k-=2*Math.PI);const x=qi(this.transform,[w,D]),N=Cf(this.transform,C);A.arc(x[0],x[1],N,-b,-k,g>0)}else{const g=qi(this.transform,[a.x,a.y]);A.lineTo(g[0],g[1])}}A.closePath()};if(A.beginPath(),t(e.outer_ring),e.inner_rings)for(const i of e.inner_rings)t(i);A.fill("evenodd")}};function y5e(e){return e.type==="pcb_copper_pour"}function n9({canvas:e,elements:A,layers:t,realToCanvasMat:i}){const n=A.filter(y5e);if(n.length===0)return;const o=new LC(e);o.realToCanvasMat=i,o.drawElements(n,{layers:t})}var m5e={...Ud,silkscreen:{top:In.board.f_fab,bottom:In.board.b_fab}};function w5e(e){return e.type.includes("pcb_fabrication_note")}function Hgt({canvas:e,elements:A,layers:t,realToCanvasMat:i}){const n=new LC(e);n.configure({colorOverrides:m5e}),n.realToCanvasMat=i;const o=A.filter(w5e);n.drawElements(o,{layers:t})}function D5e(e){return e.type==="pcb_hole"}function S5e({canvas:e,elements:A,layers:t,realToCanvasMat:i,drawSoldermask:n}){const o=new LC(e);o.realToCanvasMat=i;const s=A.filter(D5e);o.drawElements(s,{layers:t,drawSoldermask:n})}function b5e(e){return e.type==="pcb_board"}function x5e({canvas:e,elements:A,layers:t,realToCanvasMat:i,drawSoldermask:n}){const o=new LC(e);o.realToCanvasMat=i;const s=A.filter(b5e);for(const r of s)o.drawElements([r],{layers:t,drawSoldermask:!1,drawBoardMaterial:n??!1,minBoardOutlineStrokePx:2})}function _5e(e){return e.type==="pcb_cutout"}function k5e({canvas:e,elements:A,layers:t,realToCanvasMat:i}){const n=new LC(e);n.realToCanvasMat=i;const o=A.filter(_5e);n.drawElements(o,{layers:t})}function F5e(e){return e.type==="pcb_keepout"}function G5e({canvas:e,elements:A,layers:t,realToCanvasMat:i}){const n=A.filter(F5e);if(n.length===0)return;const o=new LC(e);o.realToCanvasMat=i,o.drawElements(n,{layers:[]})}function M5e(e){return e.type.startsWith("pcb_note_")}function Ygt({canvas:e,elements:A,layers:t,realToCanvasMat:i}){const n=new LC(e);n.realToCanvasMat=i;const o=A.filter(M5e);n.drawElements(o,{layers:t})}function R5e(e){return e.type==="pcb_panel"}function N5e({canvas:e,elements:A,layers:t,realToCanvasMat:i,drawSoldermask:n}){const o=new LC(e);o.realToCanvasMat=i;const s=A.filter(R5e);for(const r of s)o.drawElements([r],{layers:t})}var v5e={...Ud,copper:{...Ud.copper,top:Ga(In.board.pad_front).lighten(.5).toString(),bottom:Ga(In.board.pad_back).lighten(.5).toString(),inner1:Ga(In.board.copper.in1).lighten(.5).toString(),inner2:Ga(In.board.copper.in2).lighten(.5).toString(),inner3:Ga(In.board.copper.in3).lighten(.5).toString(),inner4:Ga(In.board.copper.in4).lighten(.5).toString(),inner5:Ga(In.board.copper.in5).lighten(.5).toString(),inner6:Ga(In.board.copper.in6).lighten(.5).toString()}};function L5e(e){return e.type==="pcb_smtpad"}function U5e({canvas:e,elements:A,layers:t,realToCanvasMat:i,primitives:n,drawSoldermask:o}){const s=A.filter(L5e).filter(c=>{const I=c.layer;return t.some(l=>l==="top_copper"&&I==="top"||l==="bottom_copper"&&I==="bottom"||l==="inner1_copper"&&I==="inner1"||l==="inner2_copper"&&I==="inner2"||l==="inner3_copper"&&I==="inner3"||l==="inner4_copper"&&I==="inner4"||l==="inner5_copper"&&I==="inner5"||l==="inner6_copper"&&I==="inner6")});if(s.length===0)return;const r=new Set;if(n)for(const c of n)(c.is_mouse_over||c.is_in_highlighted_net)&&c._element?.type==="pcb_smtpad"&&r.add(c._element.pcb_smtpad_id);const a=s.filter(c=>r.has(c.pcb_smtpad_id)),g=s.filter(c=>!r.has(c.pcb_smtpad_id));if(g.length>0){const c=new LC(e);c.realToCanvasMat=i,c.drawElements(g,{layers:t,drawSoldermask:o})}if(a.length>0){const c=new LC(e);c.configure({colorOverrides:v5e}),c.realToCanvasMat=i,c.drawElements(a,{layers:t,drawSoldermask:o})}}var H5e={...Ud,copper:{...Ud.copper,top:Ga(In.board.pad_front).lighten(.5).toString(),bottom:Ga(In.board.pad_back).lighten(.5).toString(),inner1:Ga(In.board.copper.in1).lighten(.5).toString(),inner2:Ga(In.board.copper.in2).lighten(.5).toString(),inner3:Ga(In.board.copper.in3).lighten(.5).toString(),inner4:Ga(In.board.copper.in4).lighten(.5).toString(),inner5:Ga(In.board.copper.in5).lighten(.5).toString(),inner6:Ga(In.board.copper.in6).lighten(.5).toString()}};function Y5e(e){return e.type==="pcb_trace"}var J5e=e=>e.map(A=>A.endsWith("_copper")?A.replace("_copper",""):A);function T5e({canvas:e,elements:A,layers:t,realToCanvasMat:i,primitives:n}){const o=new Set(J5e(t)),s=A.filter(Y5e).filter(c=>c.route.some(I=>I.route_type==="wire"&&"layer"in I&&o.has(I.layer)));if(s.length===0)return;const r=new Set;if(n)for(const c of n)(c.is_mouse_over||c.is_in_highlighted_net)&&c._element?.type==="pcb_trace"&&r.add(c._element.pcb_trace_id);const a=s.filter(c=>r.has(c.pcb_trace_id)),g=s.filter(c=>!r.has(c.pcb_trace_id));if(g.length>0){const c=new LC(e);c.realToCanvasMat=i,c.drawElements(g,{layers:t})}if(a.length>0){const c=new LC(e);c.configure({colorOverrides:H5e}),c.realToCanvasMat=i,c.drawElements(a,{layers:t})}}var K5e={...Ud,copper:{...Ud.copper,top:Ga(In.board.pad_front).lighten(.5).toString(),bottom:Ga(In.board.pad_back).lighten(.5).toString()}};function P5e(e){return e.type==="pcb_plated_hole"}function Jgt({canvas:e,elements:A,layers:t,realToCanvasMat:i,primitives:n,drawSoldermask:o}){const s=A.filter(P5e);if(s.length===0)return;const r=new Set;if(n)for(const c of n)(c.is_mouse_over||c.is_in_highlighted_net)&&c._element?.type==="pcb_plated_hole"&&r.add(c._element.pcb_plated_hole_id);const a=s.filter(c=>r.has(c.pcb_plated_hole_id)),g=s.filter(c=>!r.has(c.pcb_plated_hole_id));if(g.length>0){const c=new LC(e);c.realToCanvasMat=i,c.drawElements(g,{layers:t,drawSoldermask:o})}if(a.length>0){const c=new LC(e);c.configure({colorOverrides:K5e}),c.realToCanvasMat=i,c.drawElements(a,{layers:t,drawSoldermask:o})}}function Tgt(e){const{lines:A,anchorPoint:t,ccwRotation:i}=e;if(!i)return A;const n=i*Math.PI/180,o=pqe(n),s=Oy(rB(t.x,t.y),o,rB(-t.x,-t.y));return qi(s,t),A.map(r=>({...r,x1:qi(s,{x:r.x1,y:r.y1}).x,y1:qi(s,{x:r.x1,y:r.y1}).y,x2:qi(s,{x:r.x2,y:r.y2}).x,y2:qi(s,{x:r.x2,y:r.y2}).y}))}var q5e=.6,Kgt=.2,Pgt=e=>{const A=e.size*.7,t=A*q5e,i=A*Kgt,n=A*Kgt,o=e.text.split(/\r?\n/),s=e.text.length>0&&A>0,r=s?o.length:0,a=s?o.map(I=>I.length===0?0:I.length*t+(I.length-1)*i):[],g=a.length>0?Math.max(...a):0,c=r>0?r*A+(r-1)*n:0;return{text_lines:o,line_count:r,line_widths:a,target_height:A,target_width_char:t,space_between_chars:i,space_between_lines:n,width:g,height:c}},qgt=e=>{const A=Pgt(e);return{width:A.width,height:A.height,lineHeight:A.target_height,lineSpacing:A.space_between_lines,lineCount:A.line_count}},Ogt=e=>{const{text_lines:A,line_count:t,line_widths:i,target_height:n,target_width_char:o,space_between_chars:s,space_between_lines:r,width:a}=Pgt(e);if(n<=0||t===0)return[];const g=n/12,c=[];for(let I=0;I<t;I++){const l=-I*(n+r),B=i[I],C=(a-B)/2;let E=e.x+C;for(let Q=0;Q<A[I].length;Q++){const h=A[I][Q],u=iD[h]??iD[h.toUpperCase()];if(!u){E+=o+s;continue}for(const{x1:d,y1:f,x2:m,y2:w}of u)c.push({_pcb_drawing_object_id:Wy("line"),pcb_drawing_type:"line",x1:E+o*d,y1:e.y+l+n*f,x2:E+o*m,y2:e.y+l+n*w,width:g,layer:e.layer,unit:e.unit,color:e.color});E+=o+s}}return c};function LD(e){const t=e.color??i9[e.layer];let i=Ga(t);return e._element?.type==="pcb_copper_pour"&&(i=i.alpha(.7)),e.is_mouse_over||e.is_in_highlighted_net?i.lighten(.5).rgb().toString():i.rgb().toString()}var Wgt=(e,A)=>{e.equip({size:A.zoomIndependent?A.width/e.transform.a:A.width,shape:A.squareCap?"square":"circle",color:LD(A),layer:A.layer}),e.moveTo(A.x1,A.y1),e.lineTo(A.x2,A.y2)},O5e=(e,A,t)=>{switch(t){case"top_left":return{x:0,y:-A};case"top_center":return{x:-e/2,y:-A};case"top_right":return{x:-e,y:-A};case"center_left":return{x:0,y:-A/2};case"center":return{x:-e/2,y:-A/2};case"center_right":return{x:-e,y:-A/2};case"bottom_left":return{x:0,y:0};case"bottom_center":return{x:-e/2,y:0};case"bottom_right":return{x:-e,y:0};default:return{x:0,y:0}}},Zgt=e=>e.layer==="bottom_silkscreen"||e.layer==="bottom"?e.is_mirrored!==!1:e.is_mirrored===!0,W5e=(e,A)=>{e.equip({fontSize:A.size,color:LD(A),layer:A.layer});const{width:t,height:i}=qgt(A),n=O5e(t,i,A.align);A.x??=0,A.y??=0;const o={x:A.x,y:A.y};let s=Ogt({...A,x:A.x+n.x,y:A.y+n.y});if(Zgt(A)&&(s=s.map(r=>({...r,x1:2*A.x-r.x1,x2:2*A.x-r.x2}))),A.ccw_rotation){const r={lines:s,anchorPoint:o,ccwRotation:A.ccw_rotation};s=Tgt(r)}for(const r of s)Wgt(e,r)},Z5e=(e,A)=>{const{width:t,height:i,lineHeight:n}=qgt(A);A.x??=0,A.y??=0;const o=A.knockout_padding??{left:A.size*.5,right:A.size*.5,top:A.size*.3,bottom:A.size*.3},s=t+o.left+o.right,r=i+o.top+o.bottom,a=t/2,g=n-i/2,c=A.x-a,I=A.y-g,l={x:A.x,y:A.y},B={_pcb_drawing_object_id:`knockout_rect_${A._pcb_drawing_object_id}`,x:A.x,y:A.y,w:s,h:r,layer:A.layer,ccw_rotation:A.ccw_rotation};A.ccw_rotation?jgt(e,B):Vgt(e,B);let C=Ogt({...A,x:c,y:I});if(Zgt(A)&&(C=C.map(E=>({...E,x1:2*A.x-E.x1,x2:2*A.x-E.x2}))),A.ccw_rotation){const E={lines:C,anchorPoint:l,ccwRotation:A.ccw_rotation};C=Tgt(E)}for(const E of C)e.equip({size:E.width,shape:"circle",color:"black",layer:A.layer,mode:"subtract"}),e.moveTo(E.x1,E.y1),e.lineTo(E.x2,E.y2);e.equip({mode:"add"})},Vgt=(e,A)=>{e.equip({color:LD(A),layer:A.layer,size:A.stroke_width}),e.rect({x:A.x,y:A.y,w:A.w,h:A.h,mesh_fill:A.mesh_fill,is_filled:A.is_filled,has_stroke:A.has_stroke,is_stroke_dashed:A.is_stroke_dashed,stroke_width:A.stroke_width,roundness:A.roundness})},jgt=(e,A)=>{e.equip({color:LD(A),layer:A.layer}),e.rotatedRect(A.x,A.y,A.w,A.h,A.ccw_rotation,A.roundness,A.mesh_fill)},V5e=(e,A)=>{e.equip({color:LD(A),layer:A.layer}),e.rotatedPill(A.x,A.y,A.w,A.h,A.ccw_rotation)},j5e=(e,A)=>{e.equip({color:LD(A),layer:A.layer}),e.circle(A.x,A.y,A.r,A.mesh_fill)},z5e=(e,A)=>{e.equip({color:LD(A),layer:A.layer}),e.oval(A.x,A.y,A.rX,A.rY)},X5e=(e,A)=>{e.equip({color:LD(A),layer:A.layer}),e.pill(A.x,A.y,A.w,A.h)},$5e=(e,A)=>{e.equip({color:LD(A),layer:A.layer}),e.polygon(A.points)},A8e=(e,A)=>{e.equip({color:LD(A),layer:A.layer}),e.polygonWithArcs(A.brep_shape)},t8e=(e,A)=>{switch(A.pcb_drawing_type){case"line":return Wgt(e,A);case"text":return A.is_knockout?Z5e(e,A):W5e(e,A);case"rect":return A.ccw_rotation?jgt(e,A):Vgt(e,A);case"circle":return j5e(e,A);case"oval":return z5e(e,A);case"pill":return A.ccw_rotation?V5e(e,A):X5e(e,A);case"polygon":return $5e(e,A);case"polygon_with_arcs":return A8e(e,A)}},e8e=(e,A)=>{for(const t of A)t8e(e,t)},i8e={...Ud,copper:{...Ud.copper,top:Ga(In.board.pad_front).lighten(.5).toString(),bottom:Ga(In.board.pad_back).lighten(.5).toString(),inner1:Ga(In.board.copper.in1).lighten(.5).toString(),inner2:Ga(In.board.copper.in2).lighten(.5).toString(),inner3:Ga(In.board.copper.in3).lighten(.5).toString(),inner4:Ga(In.board.copper.in4).lighten(.5).toString(),inner5:Ga(In.board.copper.in5).lighten(.5).toString(),inner6:Ga(In.board.copper.in6).lighten(.5).toString()},soldermask:{...Ud.soldermask,top:Ga(In.board.soldermask.top).lighten(.35).toString(),bottom:Ga(In.board.soldermask.bottom).lighten(.35).toString()}};function zgt({canvas:e,elements:A,layers:t,realToCanvasMat:i,drawSoldermaskTop:n,drawSoldermaskBottom:o,primitives:s}){const r=new LC(e);r.realToCanvasMat=i;const a=A.filter(l=>l.type==="pcb_board");if(a.length<=1)r.drawElements(A,{layers:t,drawSoldermask:!0,drawSoldermaskTop:n,drawSoldermaskBottom:o,drawBoardMaterial:!1});else{const l=A.filter(B=>B.type!=="pcb_board");for(const B of a)r.drawElements([B,...l],{layers:t,drawSoldermask:!0,drawSoldermaskTop:n,drawSoldermaskBottom:o,drawBoardMaterial:!1})}if(!s)return;const g=new Set;for(const l of s){if(!(l.is_mouse_over||l.is_in_highlighted_net))continue;const B=l._element;B?.type==="pcb_smtpad"?g.add(B.pcb_smtpad_id):B?.type==="pcb_plated_hole"?g.add(B.pcb_plated_hole_id):B?.type==="pcb_via"&&g.add(B.pcb_via_id)}if(g.size===0)return;const c=A.filter(l=>l.type==="pcb_smtpad"?g.has(l.pcb_smtpad_id):l.type==="pcb_plated_hole"?g.has(l.pcb_plated_hole_id):l.type==="pcb_via"?g.has(l.pcb_via_id):!1);if(c.length===0)return;const I=new LC(e);I.configure({colorOverrides:i8e}),I.realToCanvasMat=i,I.drawElements(c,{layers:t,drawSoldermask:!0,drawSoldermaskTop:n,drawSoldermaskBottom:o,drawBoardMaterial:!1})}var n8e={...Ud,silkscreen:{top:In.board.f_silks,bottom:In.board.b_silks}};function o8e(e){return e.type.includes("pcb_silkscreen")}function Xgt({canvas:e,elements:A,layers:t,realToCanvasMat:i}){const n=new LC(e);n.configure({colorOverrides:n8e}),n.realToCanvasMat=i;const o=A.filter(o8e);n.drawElements(o,{layers:t})}var s8e={...Ud,copper:{...Ud.copper,top:Ga(In.board.pad_front).lighten(.5).toString(),bottom:Ga(In.board.pad_back).lighten(.5).toString()}};function r8e(e){return e.type==="pcb_via"}function $gt({canvas:e,elements:A,layers:t,realToCanvasMat:i,primitives:n,drawSoldermask:o}){const s=A.filter(r8e).filter(c=>t.some(I=>I.includes("copper")));if(s.length===0)return;const r=new Set;if(n)for(const c of n)(c.is_mouse_over||c.is_in_highlighted_net)&&c._element?.type==="pcb_via"&&r.add(c._element.pcb_via_id);const a=s.filter(c=>r.has(c.pcb_via_id)),g=s.filter(c=>!r.has(c.pcb_via_id));if(g.length>0){const c=new LC(e);c.realToCanvasMat=i,c.drawElements(g,{layers:t,drawSoldermask:o})}if(a.length>0){const c=new LC(e);c.configure({colorOverrides:s8e}),c.realToCanvasMat=i,c.drawElements(a,{layers:t,drawSoldermask:o})}}var a8e={...Ud,courtyard:{top:In.board.f_crtyd,bottom:In.board.b_crtyd}};function g8e(e){return e.type==="pcb_courtyard_circle"||e.type==="pcb_courtyard_rect"||e.type==="pcb_courtyard_outline"}function Act({canvas:e,elements:A,layers:t,realToCanvasMat:i}){const n=new LC(e);n.configure({colorOverrides:a8e}),n.realToCanvasMat=i;const o=A.filter(g8e);n.drawElements(o,{layers:t})}var c8e=["board","bottom","soldermask_bottom","bottom_silkscreen","top","soldermask_top","soldermask_with_copper_bottom","soldermask_with_copper_top","top_fabrication","bottom_fabrication","inner1","inner2","inner3","inner4","inner5","inner6","drill","edge_cuts","bottom_notes","top_notes","top_silkscreen","bottom_silkscreen","top_courtyard","bottom_courtyard","other"],I8e=({primitives:e,elements:A,transform:t,grid:i,width:n=500,height:o=500})=>{const s=AA.useRef({}),r=zB(g=>g.selected_layer),a=zB(g=>g.is_showing_solder_mask);return AA.useEffect(()=>{if(!s.current||Object.keys(s.current).length===0)return;const g=Object.fromEntries(Object.entries(s.current).filter(([l,B])=>!(!B||!a&&l.includes("soldermask"))));if(Object.keys(g).length===0)return;const c=new f5e(g);t&&(c.transform=t),c.clear(),c.foregroundLayer=r;const I=e.filter(l=>a||!l.layer?.includes("soldermask")).filter(l=>l.layer!=="board").filter(l=>l._element?.type!=="pcb_smtpad").filter(l=>l._element?.type!=="pcb_plated_hole").filter(l=>l._element?.type!=="pcb_via").filter(l=>l._element?.type!=="pcb_trace");if(e8e(c,I),t){const l=s.current.top,B=s.current.bottom,C=s.current.inner1,E=s.current.inner2,Q=s.current.inner3,h=s.current.inner4,u=s.current.inner5,d=s.current.inner6,f=[{canvas:l,copperLayer:"top_copper"},{canvas:B,copperLayer:"bottom_copper"},{canvas:C,copperLayer:"inner1_copper"},{canvas:E,copperLayer:"inner2_copper"},{canvas:Q,copperLayer:"inner3_copper"},{canvas:h,copperLayer:"inner4_copper"},{canvas:u,copperLayer:"inner5_copper"},{canvas:d,copperLayer:"inner6_copper"}];for(const{canvas:W,copperLayer:X}of f)W&&T5e({canvas:W,elements:A,layers:[X],realToCanvasMat:t,primitives:e});l&&Jgt({canvas:l,elements:A,layers:["top_copper"],realToCanvasMat:t,primitives:e,drawSoldermask:a}),B&&Jgt({canvas:B,elements:A,layers:["bottom_copper"],realToCanvasMat:t,primitives:e,drawSoldermask:a}),l&&n9({canvas:l,elements:A,layers:["top_copper"],realToCanvasMat:t}),B&&n9({canvas:B,elements:A,layers:["bottom_copper"],realToCanvasMat:t});for(const{canvas:W,copperLayer:X}of f)W&&U5e({canvas:W,elements:A,layers:[X],realToCanvasMat:t,primitives:e,drawSoldermask:a});if(l&&$gt({canvas:l,elements:A,layers:["top_copper"],realToCanvasMat:t,primitives:e,drawSoldermask:a}),B&&$gt({canvas:B,elements:A,layers:["bottom_copper"],realToCanvasMat:t,primitives:e,drawSoldermask:a}),a){const W=r==="bottom"?"bottom":"top",X=W==="top",iA=W==="bottom",aA=s.current.soldermask_top;aA&&W==="top"&&zgt({canvas:aA,elements:A,layers:["top_soldermask"],realToCanvasMat:t,drawSoldermaskTop:X,drawSoldermaskBottom:iA,primitives:e});const tA=s.current.soldermask_bottom;tA&&W==="bottom"&&zgt({canvas:tA,elements:A,layers:["bottom_soldermask"],realToCanvasMat:t,drawSoldermaskTop:X,drawSoldermaskBottom:iA,primitives:e})}l&&n9({canvas:l,elements:A,layers:["top_copper"],realToCanvasMat:t}),B&&n9({canvas:B,elements:A,layers:["bottom_copper"],realToCanvasMat:t});const m=s.current.drill;m&&S5e({canvas:m,elements:A,layers:["drill"],realToCanvasMat:t});const w=s.current.top_silkscreen;w&&Xgt({canvas:w,elements:A,layers:["top_silkscreen"],realToCanvasMat:t});const D=s.current.bottom_silkscreen;D&&Xgt({canvas:D,elements:A,layers:["bottom_silkscreen"],realToCanvasMat:t});const b=s.current.top_fabrication;b&&Hgt({canvas:b,elements:A,layers:["top_fabrication_note"],realToCanvasMat:t});const k=s.current.bottom_fabrication;k&&Hgt({canvas:k,elements:A,layers:["bottom_fabrication_note"],realToCanvasMat:t});const x=s.current.bottom_notes;x&&Ygt({canvas:x,elements:A,layers:["bottom_user_note"],realToCanvasMat:t});const N=s.current.top_notes;N&&Ygt({canvas:N,elements:A,layers:["top_user_note"],realToCanvasMat:t});const R=s.current.top_courtyard;R&&Act({canvas:R,elements:A,layers:["top_courtyard"],realToCanvasMat:t});const U=s.current.bottom_courtyard;U&&Act({canvas:U,elements:A,layers:["bottom_courtyard"],realToCanvasMat:t});const T=s.current.board;T&&(N5e({canvas:T,elements:A,layers:[],realToCanvasMat:t,drawSoldermask:a}),x5e({canvas:T,elements:A,layers:[],realToCanvasMat:t,drawSoldermask:a}));const H=s.current.edge_cuts;H&&k5e({canvas:H,elements:A,layers:["edge_cuts"],realToCanvasMat:t});const O=[{canvas:l,layer:"top"},{canvas:B,layer:"bottom"}];for(const{canvas:W,layer:X}of O)W&&G5e({canvas:W,elements:A,layers:[X],realToCanvasMat:t})}c.orderAndFadeLayers()},[e,A,t,r,a]),Z.jsxs("div",{style:{backgroundColor:"black",width:n,height:o,position:"relative"},children:[Z.jsx(JV.SuperGrid,{textColor:"rgba(0,255,0,0.8)",majorColor:"rgba(0,255,0,0.4)",minorColor:"rgba(0,255,0,0.2)",screenSpaceCellSize:200,width:n,height:o,transform:t,stringifyCoord:(g,c,I)=>`${JV.toMMSI(g,I)}, ${JV.toMMSI(c,I)}`}),c8e.filter(g=>a?!0:!g.includes("soldermask")).map(g=>g.replace(/-/g,"")).map((g,c)=>Z.jsx("canvas",{className:`pcb-layer-${g}`,ref:I=>{s.current??={},I?s.current[g]=I:delete s.current[g]},style:{position:"absolute",zIndex:c,left:0,top:0,pointerEvents:"none"},width:n,height:o},g))]})},l8e=.6,B8e=1;GpA(fOe(),1),GpA(LOe(),1);var o9=["rgba(239, 68, 68, 0.8)","rgba(249, 115, 22, 0.8)","rgba(245, 158, 11, 0.8)","rgba(234, 179, 8, 0.8)","rgba(132, 204, 22, 0.8)","rgba(34, 197, 94, 0.8)","rgba(16, 185, 129, 0.8)","rgba(20, 184, 166, 0.8)","rgba(6, 182, 212, 0.8)","rgba(14, 165, 233, 0.8)","rgba(59, 130, 246, 0.8)","rgba(99, 102, 241, 0.8)","rgba(139, 92, 246, 0.8)","rgba(168, 85, 247, 0.8)","rgba(217, 70, 239, 0.8)","rgba(236, 72, 153, 0.8)","rgba(249, 168, 212, 0.8)","rgba(161, 161, 170, 0.8)"];function tct(e,A,t,i={}){const n=i.padding??40,o=i.yFlip??!1;let s;if("center"in e){const c=e.width/2,I=e.height/2;s={minX:e.center.x-c,maxX:e.center.x+c,minY:e.center.y-I,maxY:e.center.y+I}}else s=e;const r=s.maxX-s.minX||1,a=s.maxY-s.minY||1,g=Math.min((A-2*n)/r,(t-2*n)/a);return Oy(rB(A/2,t/2),JY(g,o?-g:g),rB(-(s.minX+r/2),-(s.minY+a/2)))}function C8e(e){const A=[...e.points||[],...(e.lines||[]).flatMap(t=>t.points),...(e.rects||[]).flatMap(t=>{const i=t.width/2,n=t.height/2;return[{x:t.center.x-i,y:t.center.y-n},{x:t.center.x+i,y:t.center.y-n},{x:t.center.x-i,y:t.center.y+n},{x:t.center.x+i,y:t.center.y+n}]}),...(e.circles||[]).flatMap(t=>[{x:t.center.x-t.radius,y:t.center.y},{x:t.center.x+t.radius,y:t.center.y},{x:t.center.x,y:t.center.y-t.radius},{x:t.center.x,y:t.center.y+t.radius}]),...(e.texts||[]).flatMap(t=>{const i=t.fontSize??12,n=t.text.length*i*l8e,o=i*B8e,s=t.anchorSide??"center",r={top_left:{dx:0,dy:0},top_center:{dx:-n/2,dy:0},top_right:{dx:-n,dy:0},center_left:{dx:0,dy:-o/2},center:{dx:-n/2,dy:-o/2},center_right:{dx:-n,dy:-o/2},bottom_left:{dx:0,dy:-o},bottom_center:{dx:-n/2,dy:-o},bottom_right:{dx:-n,dy:-o}},{dx:a,dy:g}=r[s],c=t.x+a,I=t.y+g;return[{x:c,y:I},{x:c+n,y:I+o}]})];return A.length===0?{minX:-1,maxX:1,minY:-1,maxY:1}:A.reduce((t,i)=>({minX:Math.min(t.minX,i.x),maxX:Math.max(t.maxX,i.x),minY:Math.min(t.minY,i.y),maxY:Math.max(t.maxY,i.y)}),{minX:1/0,maxX:-1/0,minY:1/0,maxY:-1/0})}function Q8e(e,A,t={}){const i=A instanceof HTMLCanvasElement?A.getContext("2d"):A;if(!i)throw new Error("Could not get 2D context from canvas");const n=A instanceof HTMLCanvasElement?A.width:A.canvas.width,o=A instanceof HTMLCanvasElement?A.height:A.canvas.height;let s;if(t.transform)s=t.transform;else if(t.viewbox)s=tct(t.viewbox,n,o,{padding:t.padding,yFlip:t.yFlip});else{const r=C8e(e),a=e.coordinateSystem==="cartesian";s=tct(r,n,o,{padding:t.padding??40,yFlip:a})}i.clearRect(0,0,n,o),i.save(),e.rects&&e.rects.length>0&&e.rects.forEach(r=>{const a=r.width/2,g=r.height/2,c=qi(s,{x:r.center.x-a,y:r.center.y-g}),I=qi(s,{x:r.center.x+a,y:r.center.y+g}),l=Math.abs(I.x-c.x),B=Math.abs(I.y-c.y);i.beginPath(),i.rect(Math.min(c.x,I.x),Math.min(c.y,I.y),l,B),r.fill&&(i.fillStyle=r.fill,i.fill()),r.stroke&&(i.strokeStyle=r.stroke,i.stroke())}),e.circles&&e.circles.length>0&&e.circles.forEach(r=>{const a=qi(s,r.center),g=r.radius*Math.abs(s.a);i.beginPath(),i.arc(a.x,a.y,g,0,2*Math.PI),r.fill&&(i.fillStyle=r.fill,i.fill()),r.stroke&&(i.strokeStyle=r.stroke??"transparent",i.stroke())}),e.lines&&e.lines.length>0&&e.lines.forEach((r,a)=>{if(r.points.length===0)return;i.beginPath();const g=qi(s,r.points[0]);i.moveTo(g.x,g.y);for(let c=1;c<r.points.length;c++){const I=qi(s,r.points[c]);i.lineTo(I.x,I.y)}if(i.strokeStyle=r.strokeColor||o9[a%o9.length],r.strokeWidth?i.lineWidth=r.strokeWidth*s.a:i.lineWidth=2,i.lineCap="round",r.strokeDash)if(typeof r.strokeDash=="string"){let c;if(r.strokeDash.includes(","))c=r.strokeDash.split(",").map(I=>parseFloat(I.trim())).filter(I=>!Number.isNaN(I));else{const I=parseFloat(r.strokeDash.trim());c=Number.isNaN(I)?[]:[I]}i.setLineDash(c)}else i.setLineDash(r.strokeDash.map(c=>c*Math.abs(s.a)));else i.setLineDash([]);i.stroke()}),e.points&&e.points.length>0&&e.points.forEach((r,a)=>{const g=qi(s,r);i.beginPath(),i.arc(g.x,g.y,3,0,2*Math.PI),i.fillStyle=r.color||o9[a%o9.length],i.fill(),r.label&&!t.disableLabels&&(i.fillStyle=r.color||"black",i.font="12px sans-serif",i.fillText(r.label,g.x+5,g.y-5))}),e.texts&&e.texts.length>0&&e.texts.forEach(r=>{const a=qi(s,{x:r.x,y:r.y});i.fillStyle=r.color||"black",i.font=`${(r.fontSize??12)*Math.abs(s.a)}px sans-serif`;const g=r.anchorSide??"center",c={top_left:"left",center_left:"left",bottom_left:"left",top_center:"center",center:"center",bottom_center:"center",top_right:"right",center_right:"right",bottom_right:"right"},I={top_left:"top",top_center:"top",top_right:"top",center_left:"middle",center:"middle",center_right:"middle",bottom_left:"bottom",bottom_center:"bottom",bottom_right:"bottom"};i.textAlign=c[g],i.textBaseline=I[g],i.fillText(r.text,a.x,a.y)}),i.restore()}var E8e=({children:e,transform:A,debugGraphics:t})=>{const i=AA.useRef(null),[n,{width:o,height:s}]=zY(),r=zB(a=>a.is_showing_autorouting);return AA.useEffect(()=>{r&&i.current&&t&&o&&s&&(i.current.width=o,i.current.height=s,Q8e(t,i.current,{transform:A,disableLabels:!0}))},[t,A,o,s,r]),r?Z.jsxs("div",{ref:n,style:{position:"relative",width:"100%",height:"100%"},children:[e,Z.jsx("canvas",{ref:i,style:{position:"absolute",top:0,left:0,opacity:.5,zIndex:100,width:"100%",height:"100%",pointerEvents:"none"}})]}):e},h8e=({children:e,transform:A=yb(),elements:t=[]})=>{const[i,{width:n,height:o}]=zY(),s=AA.useRef(null);return AA.useEffect(()=>{const r=s.current;if(!r||!n||!o)return;r.width=n,r.height=o;const a=r.getContext("2d");if(!a)return;a.clearRect(0,0,n,o);const g=t.filter(I=>I.type==="pcb_component"),c=t.filter(I=>I.type==="pcb_manual_edit_conflict_warning");a.strokeStyle=In.board.drc_warning,a.lineWidth=2,c.forEach(I=>{const l=g.find(O=>O.pcb_component_id===I.pcb_component_id);if(!l)return;const{width:B,height:C,center:E}=l,Q=qi(A,E),h=B*Math.abs(A.a),u=C*Math.abs(A.d),d=.1*Math.abs(A.a),f=h+d*2,m=u+d*2,w=Q.x-f/2,D=Q.y-m/2;a.beginPath(),a.rect(w,D,f,m),a.stroke();const b="Manual Edit Conflict",k=4,x=Math.max(8,Math.min(12,10*Math.abs(A.a)));a.font=`${x}px sans-serif`;const R=a.measureText(b).width+k*2,U=x+k*2,T=w+(f-R)/2,H=D+m+5;a.fillStyle="rgba(0, 0, 0, 0.7)",a.beginPath(),a.roundRect(T,H,R,U,3),a.fill(),a.fillStyle=In.board.drc_warning,a.textAlign="center",a.textBaseline="middle",a.fillText(b,T+R/2,H+U/2)})},[t,A,n,o]),Z.jsxs("div",{ref:i,style:{position:"relative",width:"100%",height:"100%"},children:[e,Z.jsx("canvas",{ref:s,style:{position:"absolute",top:0,left:0,pointerEvents:"none",zIndex:Qc.warnings}})]})},s9=(e,A,t)=>t(e,A),ect=(e,A,t,i,n)=>{const o=n*Math.PI/180,s=Math.cos(o),r=Math.sin(o),a=e-t,g=A-i,c=a*s-g*r,I=a*r+g*s;return{x:c+t,y:I+i}},XY=e=>{if(e.length===0)return null;let A=e[0].x,t=e[0].x,i=e[0].y,n=e[0].y;for(const o of e)A=s9(A,o.x,Math.min),t=s9(t,o.x,Math.max),i=s9(i,o.y,Math.min),n=s9(n,o.y,Math.max);return{minX:A,maxX:t,minY:i,maxY:n}},u8e=(e,A)=>({minX:Math.min(e.minX,A.minX),maxX:Math.max(e.maxX,A.maxX),minY:Math.min(e.minY,A.minY),maxY:Math.max(e.maxY,A.maxY)}),d8e=(e,A)=>e?u8e(e,A):A,p8e=e=>{switch(e.pcb_drawing_type){case"line":{const A=(e.width??0)/2,t=[{x:e.x1,y:e.y1},{x:e.x2,y:e.y2}],i=XY(t);return i?{minX:i.minX-A,maxX:i.maxX+A,minY:i.minY-A,maxY:i.maxY+A}:null}case"rect":{const A=e.w/2,t=e.h/2,i=[{x:e.x-A,y:e.y-t},{x:e.x+A,y:e.y-t},{x:e.x+A,y:e.y+t},{x:e.x-A,y:e.y+t}],n=e.ccw_rotation??0,o=n===0?i:i.map(s=>ect(s.x,s.y,e.x,e.y,n));return XY(o)}case"circle":return{minX:e.x-e.r,maxX:e.x+e.r,minY:e.y-e.r,maxY:e.y+e.r};case"oval":return{minX:e.x-e.rX,maxX:e.x+e.rX,minY:e.y-e.rY,maxY:e.y+e.rY};case"pill":{const A=e.w/2,t=e.h/2,i=[{x:e.x-A,y:e.y-t},{x:e.x+A,y:e.y-t},{x:e.x+A,y:e.y+t},{x:e.x-A,y:e.y+t}],n=e.ccw_rotation??0,o=n===0?i:i.map(s=>ect(s.x,s.y,e.x,e.y,n));return XY(o)}case"polygon":return XY(e.points);case"polygon_with_arcs":{const A=e.brep_shape.outer_ring.vertices.map(t=>({x:t.x,y:t.y}));return XY(A)}case"text":{const A=e.size??0,t=e.text?e.text.length*A*.6:0,i=A;if(t===0&&i===0)return{minX:e.x,maxX:e.x,minY:e.y,maxY:e.y};const n=t/2,o=i/2;return{minX:e.x-n,maxX:e.x+n,minY:e.y-o,maxY:e.y+o}}default:return null}};function f8e(e){const{dimensionStart:A,dimensionEnd:t,screenDimensionStart:i,screenDimensionEnd:n,flipX:o,flipY:s}=e,r=t.x-A.x,a=t.y-A.y,g=Math.sqrt(r*r+a*a),c=n.x-i.x,I=n.y-i.y,l=Math.sqrt(c*c+I*I),B=Math.atan2(I,c)*(180/Math.PI),C=Math.abs(B)%90,Q=Math.min(C,90-C)>15,h=(i.x+n.x)/2,u=(i.y+n.y)/2,d=15,f=B+90;let m=Math.cos(f*Math.PI/180)*d,w=Math.sin(f*Math.PI/180)*d;const D=c>0&&I<0,b=c>0&&I>0,k=c<0&&I>0;o!==s&&!D&&(m=-m,w=-w),D&&(m+=Math.cos(f*Math.PI/180)*-45,w+=Math.sin(f*Math.PI/180)*-45),b&&(m+=Math.cos(f*Math.PI/180)+-20,w+=Math.sin(f*Math.PI/180)+-10),k&&(m+=Math.cos(f*Math.PI/180)*10,w+=Math.sin(f*Math.PI/180)*10);const x=h+m,N=u+w;return{distance:g,screenDistance:l,x,y:N,show:g>.01&&l>30&&Q}}function y8e(e){const{dimensionStart:A,dimensionEnd:t,screenDimensionStart:i,screenDimensionEnd:n,flipX:o,flipY:s}=e;return AA.useMemo(()=>f8e({dimensionStart:A,dimensionEnd:t,screenDimensionStart:i,screenDimensionEnd:n,flipX:o,flipY:s}),[A,t,i,n,o,s])}var m8e=(e,A,t)=>{const i=t*Math.PI/180,n=Math.cos(i),o=Math.sin(i),s=e.x-A.x,r=e.y-A.y,a=s*n-r*o,g=s*o+r*n;return{x:a+A.x,y:g+A.y}},ict=(e,A,t,i)=>{const n={top_left:{x:e.x-A,y:e.y-t},top_center:{x:e.x,y:e.y-t},top_right:{x:e.x+A,y:e.y-t},center_left:{x:e.x-A,y:e.y},center:{x:e.x,y:e.y},center_right:{x:e.x+A,y:e.y},bottom_left:{x:e.x-A,y:e.y+t},bottom_center:{x:e.x,y:e.y+t},bottom_right:{x:e.x+A,y:e.y+t}};return i===0?Object.entries(n).map(([o,s])=>({anchor:o,point:s})):Object.entries(n).map(([o,s])=>({anchor:o,point:m8e(s,e,i)}))},w8e=e=>{switch(e.pcb_drawing_type){case"rect":{const A=e.ccw_rotation??0;return ict({x:e.x,y:e.y},e.w/2,e.h/2,A)}case"pill":{const A=e.ccw_rotation??0;return ict({x:e.x,y:e.y},e.w/2,e.h/2,A)}case"circle":return[{anchor:"circle_center",point:{x:e.x,y:e.y}},{anchor:"circle_right",point:{x:e.x+e.r,y:e.y}},{anchor:"circle_left",point:{x:e.x-e.r,y:e.y}},{anchor:"circle_top",point:{x:e.x,y:e.y-e.r}},{anchor:"circle_bottom",point:{x:e.x,y:e.y+e.r}}];case"oval":return[{anchor:"oval_center",point:{x:e.x,y:e.y}},{anchor:"oval_right",point:{x:e.x+e.rX,y:e.y}},{anchor:"oval_left",point:{x:e.x-e.rX,y:e.y}},{anchor:"oval_top",point:{x:e.x,y:e.y-e.rY}},{anchor:"oval_bottom",point:{x:e.x,y:e.y+e.rY}}];case"line":{const A={x:(e.x1+e.x2)/2,y:(e.y1+e.y2)/2};return[{anchor:"line_start",point:{x:e.x1,y:e.y1}},{anchor:"line_mid",point:A},{anchor:"line_end",point:{x:e.x2,y:e.y2}}]}case"polygon":return e.points.map((A,t)=>({anchor:`polygon_vertex_${t}`,point:A}));case"polygon_with_arcs":return e.brep_shape.outer_ring.vertices.map((A,t)=>({anchor:`polygon_with_arcs_vertex_${t}`,point:{x:A.x,y:A.y}}));default:return[]}},D8e=16,fG=5,nct=e=>{if(e.pcb_drawing_type==="text")return!0;const A=e._element;if(!A||typeof A!="object")return!1;const t=typeof A.type=="string"?A.type:void 0;return t?!!(t.startsWith("pcb_silkscreen_")||t.startsWith("pcb_note_")||t==="pcb_text"||t.startsWith("pcb_fabrication_note_")&&t!=="pcb_fabrication_note_rect"):!1},S8e=({children:e,transform:A,focusOnHover:t=!1,primitives:i=[]})=>{A||(A=yb());const[n,o]=AA.useState(!1),[s,r]=AA.useState(!1),[a,g]=AA.useState(!1),[c,I]=AA.useState({start:null,end:null}),l=zB(H=>H.is_mouse_over_container),B=AA.useCallback(()=>{a&&(g(!1),window.dispatchEvent(new Event("disarm-dimension-tool")))},[a]),[C,E]=AA.useState({x:0,y:0}),[Q,h]=AA.useState({x:0,y:0}),u=AA.useRef({x:0,y:0}),d=AA.useRef(null),m=d.current?.getBoundingClientRect(),w=AA.useMemo(()=>{const H=new Map;for(const O of i){if(!O._element||nct(O)||O.pcb_drawing_type==="pill"||O.pcb_drawing_type==="rect"&&O.ccw_rotation&&O.ccw_rotation!==0)continue;const W=p8e(O);if(!W)continue;const X=H.get(O._element);H.set(O._element,d8e(X??void 0,W))}return H},[i]),D=AA.useMemo(()=>{const H=[];for(const O of i){if(!O._element||nct(O))continue;const W=w8e(O);if(W.length!==0)for(const X of W)H.push({anchor:X.anchor,point:X.point,element:O._element})}return H},[i]),b=AA.useMemo(()=>{const H=[];w.forEach((O,W)=>{if(!O)return;const X=(O.minX+O.maxX)/2,iA=(O.minY+O.maxY)/2,aA={top_left:{x:O.minX,y:O.minY},top_center:{x:X,y:O.minY},top_right:{x:O.maxX,y:O.minY},center_left:{x:O.minX,y:iA},center:{x:X,y:iA},center_right:{x:O.maxX,y:iA},bottom_left:{x:O.minX,y:O.maxY},bottom_center:{x:X,y:O.maxY},bottom_right:{x:O.maxX,y:O.maxY}};for(const[tA,oA]of Object.entries(aA))H.push({anchor:tA,point:oA,element:W})});for(const O of D)H.push(O);return H.push({anchor:"origin",point:{x:0,y:0},element:null}),H},[w,D]),k=AA.useMemo(()=>b.map((H,O)=>({...H,id:`${O}-${H.anchor}`,screenPoint:qi(A,H.point)})),[b,A]),x=AA.useCallback(H=>{if(k.length===0)return{point:H,id:null};const O=qi(A,H);let W=null;for(const X of k){const iA=X.screenPoint.x-O.x,aA=X.screenPoint.y-O.y,tA=Math.hypot(iA,aA);tA>D8e||(!W||tA<W.distance)&&(W={distance:tA,id:X.id,point:X.point})}return W?{point:W.point,id:W.id}:{point:H,id:null}},[k,A]);AA.useEffect(()=>{const H=W=>{const X=W.target;if(X.tagName==="INPUT"||X.tagName==="TEXTAREA"||X.isContentEditable)return;const iA=d.current?.contains(document.activeElement)||document.activeElement===d.current;if(!(!l&&!iA)){if(W.key==="d"){const aA=x({x:u.current.x,y:u.current.y});E({x:aA.point.x,y:aA.point.y}),h({x:aA.point.x,y:aA.point.y}),I({start:aA.id,end:aA.id}),n?(o(!1),r(!1),I({start:null,end:null})):(o(!0),r(!0)),B()}W.key==="Escape"&&(o(!1),r(!1),I({start:null,end:null}),B())}},O=()=>{g(!0)};return window.addEventListener("keydown",H),window.addEventListener("arm-dimension-tool",O),()=>{window.removeEventListener("keydown",H),window.removeEventListener("arm-dimension-tool",O),B()}},[l,n,B,x]);const N=qi(A,C),R=qi(A,Q),U={left:Math.min(N.x,R.x),right:Math.max(N.x,R.x),top:Math.min(N.y,R.y),bottom:Math.max(N.y,R.y),flipX:N.x>R.x,flipY:N.y>R.y,width:0,height:0};U.width=U.right-U.left,U.height=U.bottom-U.top;const T=y8e({dimensionStart:C,dimensionEnd:Q,screenDimensionStart:N,screenDimensionEnd:R,flipX:U.flipX,flipY:U.flipY});return Z.jsxs("div",{ref:d,"data-pcb-viewer":!0,tabIndex:0,style:{position:"relative",outline:"none"},onMouseEnter:()=>{t&&d.current&&d.current.focus()},onMouseLeave:()=>{d.current&&d.current.blur()},onClick:()=>{d.current&&d.current.focus()},onMouseMove:H=>{const O=H.currentTarget.getBoundingClientRect(),W=H.clientX-O.left,X=H.clientY-O.top,iA=qi(mb(A),{x:W,y:X});if(u.current.x=iA.x,u.current.y=iA.y,s){const aA=x(iA);h({x:aA.point.x,y:aA.point.y}),I(tA=>({...tA,end:aA.id}))}},onMouseDown:H=>{const O=H.currentTarget.getBoundingClientRect(),W=H.clientX-O.left,X=H.clientY-O.top,iA=qi(mb(A),{x:W,y:X});if(a&&!n){const aA=x(iA);E({x:aA.point.x,y:aA.point.y}),h({x:aA.point.x,y:aA.point.y}),I({start:aA.id,end:aA.id}),o(!0),r(!0),B()}else s?(r(!1),I(aA=>({...aA,end:null}))):n&&(o(!1),I({start:null,end:null}))},children:[e,n&&Z.jsxs(Z.Fragment,{children:[T.show&&Z.jsx("div",{style:{position:"absolute",left:T.x,top:T.y,color:"red",mixBlendMode:"difference",pointerEvents:"none",fontSize:12,fontFamily:"sans-serif",whiteSpace:"nowrap",zIndex:Qc.dimensionOverlay},children:T.distance.toFixed(2)}),Z.jsx("div",{style:{position:"absolute",left:U.left,width:U.width,textAlign:"center",top:N.y+2,color:"red",mixBlendMode:"difference",pointerEvents:"none",marginTop:U.flipY?0:-20,fontSize:12,fontFamily:"sans-serif",zIndex:Qc.dimensionOverlay},children:Math.abs(C.x-Q.x).toFixed(2)}),Z.jsx("div",{style:{position:"absolute",left:R.x,height:U.height,display:"flex",flexDirection:"column",justifyContent:"center",top:U.top,color:"red",pointerEvents:"none",mixBlendMode:"difference",fontSize:12,fontFamily:"sans-serif",zIndex:Qc.dimensionOverlay},children:Z.jsx("div",{style:{marginLeft:U.flipX?"-100%":4,paddingRight:4},children:Math.abs(C.y-Q.y).toFixed(2)})}),Z.jsxs("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none",mixBlendMode:"difference",zIndex:Qc.dimensionOverlay},width:m.width,height:m.height,children:[Z.jsx("defs",{children:Z.jsx("marker",{id:"head",orient:"auto",markerWidth:"3",markerHeight:"4",refX:"2",refY:"2",children:Z.jsx("path",{d:"M0,0 V4 L2,2 Z",fill:"red"})})}),Z.jsx("line",{x1:N.x,y1:N.y,x2:R.x,y2:R.y,markerEnd:"url(#head)",strokeWidth:1.5,fill:"none",stroke:"red"}),Z.jsx("line",{x1:N.x,y1:N.y,x2:R.x,y2:N.y,strokeWidth:1.5,fill:"none",strokeDasharray:"2,2",stroke:"red"}),Z.jsx("line",{x1:R.x,y1:N.y,x2:R.x,y2:R.y,strokeWidth:1.5,fill:"none",strokeDasharray:"2,2",stroke:"red"})]}),s&&k.map(H=>{const O=H.id===c.start||H.id===c.end,W=fG/2;return Z.jsxs("svg",{width:fG,height:fG,style:{position:"absolute",left:H.screenPoint.x-W,top:H.screenPoint.y-W,pointerEvents:"none",zIndex:Qc.dimensionOverlay},children:[Z.jsx("line",{x1:0,y1:0,x2:fG,y2:fG,stroke:O?"#66ccff":"white",strokeWidth:1}),Z.jsx("line",{x1:fG,y1:0,x2:0,y2:fG,stroke:O?"#66ccff":"white",strokeWidth:1})]},H.id)}),Z.jsxs("div",{style:{right:0,bottom:0,position:"absolute",color:"red",fontFamily:"sans-serif",fontSize:12,margin:4},children:["(",C.x.toFixed(2),",",C.y.toFixed(2),")",Z.jsx("br",{}),"(",Q.x.toFixed(2),",",Q.y.toFixed(2),")",Z.jsx("br",{}),"dist:"," ",Math.sqrt((Q.x-C.x)**2+(Q.y-C.y)**2).toFixed(2)]})]})]})},b8e=(e,A,t=0)=>{const i=e.width/2,n=e.height/2,o=e.center.x-i-t,s=e.center.x+i+t,r=e.center.y-n-t,a=e.center.y+n+t;return A.x>o&&A.x<s&&A.y>r&&A.y<a},x8e=({children:e,disabled:A,transform:t,soup:i,cancelPanDrag:n,onCreateEditEvent:o,onModifyEditEvent:s})=>{t||(t=yb());const r=AA.useRef(null),[a,g]=AA.useState(null),[c,I]=AA.useState(null),l=a!==null;zB(Q=>Q.in_edit_mode);const B=zB(Q=>Q.in_move_footprint_mode),C=zB(Q=>Q.setIsMovingComponent),E=A||!B;return Z.jsxs("div",{ref:r,style:{position:"relative",overflow:"hidden"},onMouseDown:Q=>{if(E)return;const h=Q.currentTarget.getBoundingClientRect(),u=Q.clientX-h.left,d=Q.clientY-h.top;if(Number.isNaN(u)||Number.isNaN(d))return;const f=qi(mb(t),{x:u,y:d});let m=!1;for(const w of i)if(w.type==="pcb_component"&&b8e(w,f,10/t.a)){n(),g(w.pcb_component_id),m=!0;const D=Math.random().toString();I({dragStart:f,originalCenter:w.center,dragEnd:f,edit_event_id:D}),o({edit_event_id:D,edit_event_type:"edit_pcb_component_location",pcb_edit_event_type:"edit_component_location",pcb_component_id:w.pcb_component_id,original_center:w.center,new_center:w.center,in_progress:!0,created_at:Date.now()}),C(!0);break}if(m||g(null),m)return Q.preventDefault(),!1},onMouseMove:Q=>{if(!a||!c)return;const h=Q.currentTarget.getBoundingClientRect(),u=Q.clientX-h.left,d=Q.clientY-h.top;if(Number.isNaN(u)||Number.isNaN(d))return;const f=qi(mb(t),{x:u,y:d});I({...c,dragEnd:f}),s({edit_event_id:c.edit_event_id,new_center:{x:c.originalCenter.x+f.x-c.dragStart.x,y:c.originalCenter.y+f.y-c.dragStart.y}})},onMouseUp:Q=>{a&&(g(null),C(!1),c&&(s({edit_event_id:c.edit_event_id,in_progress:!1}),I(null)))},children:[e,!E&&i.filter(Q=>Q.type==="pcb_component").map(Q=>{if(!Q?.center)return null;const h=qi(t,Q.center);return Z.jsx("div",{style:{position:"absolute",pointerEvents:"none",left:h.x,top:h.y,width:Q.width*t.a+20,height:Q.height*t.a+20,transform:"translate(-50%, -50%)",background:l&&a===Q.pcb_component_id?"rgba(255, 0, 0, 0.2)":""}},Q.pcb_component_id)})]})},_8e=({hotkeys:e})=>(AA.useEffect(()=>{const A=t=>{e.forEach(i=>{t.key===i.key&&i.onUse()})};return window.addEventListener("keydown",A),()=>{window.removeEventListener("keydown",A)}},[e]),Z.jsx("div",{className:jv`
5431
+ $1`).replace(/>(\s*)(?=<!--\s*\/)/g,"> ")}}});function Fgt(e,A,t){if(!A||!t)return;let i=e.get(A);i||(i=new Set,e.set(A,i)),i.add(t);let n=e.get(t);n||(n=new Set,e.set(t,n)),n.add(A)}function UOe(e,A){if(!A.subcircuit_id&&!A.source_group_id)return[...e];const t=new Map;for(const s of e){const r=s[`${s.type}_id`];typeof r=="string"&&t.set(r,s)}const i=new Map;for(const s of e){const r=Object.entries(s);for(const[a,g]of r)if(a!=="parent_source_group_id"){if(a.endsWith("_id")&&typeof g=="string"){const c=t.get(g);Fgt(i,s,c)}else if(a.endsWith("_ids")&&Array.isArray(g)){for(const c of g)if(typeof c=="string"){const I=t.get(c);Fgt(i,s,I)}}}}const n=[],o=new Set;for(const s of e)(A.subcircuit_id&&s.subcircuit_id===A.subcircuit_id||A.source_group_id&&(s.source_group_id===A.source_group_id||Array.isArray(s.member_source_group_ids)&&s.member_source_group_ids.includes(A.source_group_id)))&&(n.push(s),o.add(s));for(;n.length>0;){const s=n.shift(),r=i.get(s);if(r)for(const a of r)o.has(a)||(o.add(a),n.push(a))}return e.filter(s=>o.has(s))}var A9=(e,A={})=>{const t=e;let i=t._internal_store;if(!i){i={counts:{},editCount:0},t._internal_store=i;for(const o of t){const s=o.type,r=o[`${s}_id`];if(!r)continue;const a=Number.parseInt(r.split("_").pop());Number.isNaN(a)||(i.counts[s]=Math.max(i.counts[s]??0,a))}}return new Proxy({},{get:(o,s)=>{if(s==="toArray")return()=>(t.editCount=i.editCount,t);if(s==="editCount")return i.editCount;if(s==="subtree")return a=>A9(UOe(t,a),A);const r=s;return{get:a=>t.find(g=>g.type===r&&g[`${r}_id`]===a),getUsing:a=>{const g=Object.keys(a);if(g.length!==1)throw new Error("getUsing requires exactly one key, e.g. { pcb_component_id }");const c=g[0],I=c.replace("_id",""),l=t.find(B=>B.type===I&&B[c]===a[c]);return l?t.find(B=>B.type===r&&B[`${r}_id`]===l[`${r}_id`]):null},getWhere:a=>{const g=Object.keys(a);return t.find(c=>c.type===r&&g.every(I=>c[I]===a[I]))},list:a=>{const g=a?Object.keys(a):[];return t.filter(c=>c.type===r&&g.every(I=>c[I]===a[I]))},insert:a=>{i.counts[r]??=-1,i.counts[r]++;const g=i.counts[r],c={type:r,[`${r}_id`]:`${r}_${g}`,...a};return A.validateInserts&&(Bat[r]??XdA).parse(c),t.push(c),i.editCount++,c},delete:a=>{const g=t.find(c=>c[`${r}_id`]===a);g&&(t.splice(t.indexOf(g),1),i.editCount++)},update:(a,g)=>{const c=t.find(I=>I.type===r&&I[`${r}_id`]===a);return c?(Object.assign(c,g),i.editCount++,c):null},select:a=>{if(r==="source_component")return t.find(g=>g.type==="source_component"&&g.name===a.replace(/\./g,""));if(r==="pcb_port"||r==="source_port"||r==="schematic_port"){const[g,c]=a.replace(/\./g,"").split(/[\s\>]+/),I=t.find(B=>B.type==="source_component"&&B.name===g);if(!I)return null;const l=t.find(B=>B.type==="source_port"&&B.source_component_id===I.source_component_id&&(B.name===c||(B.port_hints??[]).includes(c)));if(!l)return null;if(r==="source_port")return l;if(r==="pcb_port")return t.find(B=>B.type==="pcb_port"&&B.source_port_id===l.source_port_id);if(r==="schematic_port")return t.find(B=>B.type==="schematic_port"&&B.source_port_id===l.source_port_id)}}}}})};A9.unparsed=A9;var Db=A9;function LpA(e){const A=e.type;return`${A}:${e[`${A}_id`]}`}var Ggt=(e,A={})=>{let t=e._internal_store_indexed;if(!t){t={counts:{},editCount:0,indexes:{}};for(const s of e){const r=s.type,a=s[`${r}_id`];if(!a)continue;const g=Number.parseInt(a.split("_").pop()||"");Number.isNaN(g)||(t.counts[r]=Math.max(t.counts[r]??0,g))}const n=A.indexConfig||{},o=t.indexes;if(n.byId&&(o.byId=new Map),n.byType&&(o.byType=new Map),n.byRelation&&(o.byRelation=new Map),n.bySubcircuit&&(o.bySubcircuit=new Map),n.byCustomField&&n.byCustomField.length>0){o.byCustomField=new Map;for(const s of n.byCustomField)o.byCustomField.set(s,new Map)}for(const s of e){if(n.byId){const r=LpA(s);o.byId.set(r,s)}if(n.byType){const r=o.byType.get(s.type)||[];r.push(s),o.byType.set(s.type,r)}if(n.byRelation){const r=Object.entries(s);for(const[a,g]of r)if(a.endsWith("_id")&&a!==`${s.type}_id`&&typeof g=="string"){const c=o.byRelation.get(a)||new Map,I=c.get(g)||[];I.push(s),c.set(g,I),o.byRelation.set(a,c)}}if(n.bySubcircuit&&"subcircuit_id"in s){const r=s.subcircuit_id;if(r&&typeof r=="string"){const a=o.bySubcircuit.get(r)||[];a.push(s),o.bySubcircuit.set(r,a)}}if(n.byCustomField&&o.byCustomField){for(const r of n.byCustomField)if(r in s){const a=s[r];if(a!==void 0&&(typeof a=="string"||typeof a=="number")){const g=String(a),c=o.byCustomField.get(r),I=c.get(g)||[];I.push(s),c.set(g,I)}}}}e._internal_store_indexed=t}return new Proxy({},{get:(n,o)=>{if(o==="toArray")return()=>(e.editCount=t.editCount,e);if(o==="editCount")return t.editCount;const s=o;return{get:r=>{const a=A.indexConfig||{};return a.byId&&t.indexes.byId?t.indexes.byId.get(`${s}:${r}`)||null:a.byType&&t.indexes.byType?(t.indexes.byType.get(s)||[]).find(c=>c[`${s}_id`]===r)||null:e.find(g=>g.type===s&&g[`${s}_id`]===r)||null},getUsing:r=>{const a=A.indexConfig||{},g=Object.keys(r);if(g.length!==1)throw new Error("getUsing requires exactly one key, e.g. { pcb_component_id }");const c=g[0],I=c.replace("_id","");if(a.byRelation&&t.indexes.byRelation){const B=t.indexes.byRelation.get(c);if(B){const E=(B.get(r[c])||[]).find(h=>h.type===I);if(!E)return null;const Q=E[`${s}_id`];return a.byId&&t.indexes.byId?t.indexes.byId.get(`${s}:${Q}`)||null:a.byType&&t.indexes.byType?(t.indexes.byType.get(s)||[]).find(u=>u[`${s}_id`]===Q)||null:e.find(h=>h.type===s&&h[`${s}_id`]===Q)||null}}const l=e.find(B=>B.type===I&&B[c]===r[c]);return l&&e.find(B=>B.type===s&&B[`${s}_id`]===l[`${s}_id`])||null},getWhere:r=>{const a=A.indexConfig||{},g=Object.keys(r);if(g.length===1&&a.byCustomField&&t.indexes.byCustomField){const c=g[0],I=t.indexes.byCustomField.get(c);if(I){const l=String(r[c]);return(I.get(l)||[]).find(C=>C.type===s)||null}}if("subcircuit_id"in r&&a.bySubcircuit&&t.indexes.bySubcircuit){const c=r.subcircuit_id;return(t.indexes.bySubcircuit.get(c)||[]).find(l=>l.type===s&&g.every(B=>l[B]===r[B]))||null}return a.byType&&t.indexes.byType?(t.indexes.byType.get(s)||[]).find(I=>g.every(l=>I[l]===r[l]))||null:e.find(c=>c.type===s&&g.every(I=>c[I]===r[I]))||null},list:r=>{const a=A.indexConfig||{},g=r?Object.keys(r):[];if(g.length===0&&a.byType&&t.indexes.byType)return t.indexes.byType.get(s)||[];if(g.length===1&&g[0]==="subcircuit_id"&&a.bySubcircuit&&t.indexes.bySubcircuit){const I=r.subcircuit_id;return(t.indexes.bySubcircuit.get(I)||[]).filter(B=>B.type===s)}let c;return a.byType&&t.indexes.byType?c=t.indexes.byType.get(s)||[]:c=e.filter(I=>I.type===s),g.length>0?c.filter(I=>g.every(l=>I[l]===r[l])):c},insert:r=>{t.counts[s]??=-1,t.counts[s]++;const a=t.counts[s],g={type:s,[`${s}_id`]:`${s}_${a}`,...r};A.validateInserts&&(Bat[s]??XdA).parse(g),e.push(g),t.editCount++;const c=A.indexConfig||{};if(c.byId&&t.indexes.byId){const I=LpA(g);t.indexes.byId.set(I,g)}if(c.byType&&t.indexes.byType){const I=t.indexes.byType.get(s)||[];I.push(g),t.indexes.byType.set(s,I)}if(c.byRelation&&t.indexes.byRelation){const I=Object.entries(g);for(const[l,B]of I)if(l.endsWith("_id")&&l!==`${g.type}_id`&&typeof B=="string"){const C=t.indexes.byRelation.get(l)||new Map,E=C.get(B)||[];E.push(g),C.set(B,E),t.indexes.byRelation.set(l,C)}}if(c.bySubcircuit&&t.indexes.bySubcircuit&&"subcircuit_id"in g){const I=g.subcircuit_id;if(I&&typeof I=="string"){const l=t.indexes.bySubcircuit.get(I)||[];l.push(g),t.indexes.bySubcircuit.set(I,l)}}if(c.byCustomField&&t.indexes.byCustomField){for(const I of c.byCustomField)if(I in g){const l=g[I];if(l!==void 0&&(typeof l=="string"||typeof l=="number")){const B=String(l),C=t.indexes.byCustomField.get(I),E=C.get(B)||[];E.push(g),C.set(B,E)}}}return g},delete:r=>{const a=A.indexConfig||{};let g;if(a.byId&&t.indexes.byId?g=t.indexes.byId.get(`${s}:${r}`):a.byType&&t.indexes.byType?g=(t.indexes.byType.get(s)||[]).find(l=>l[`${s}_id`]===r):g=e.find(I=>I[`${s}_id`]===r),!g)return;const c=e.indexOf(g);if(c>=0&&(e.splice(c,1),t.editCount++),a.byId&&t.indexes.byId){const I=LpA(g);t.indexes.byId.delete(I)}if(a.byType&&t.indexes.byType){const l=(t.indexes.byType.get(s)||[]).filter(B=>B[`${s}_id`]!==r);t.indexes.byType.set(s,l)}if(a.byRelation&&t.indexes.byRelation)for(const[I,l]of t.indexes.byRelation.entries())for(const[B,C]of l.entries()){const E=C.filter(Q=>Q!==g);E.length===0?l.delete(B):l.set(B,E)}if(a.bySubcircuit&&t.indexes.bySubcircuit&&"subcircuit_id"in g){const I=g.subcircuit_id;if(I){const B=(t.indexes.bySubcircuit.get(I)||[]).filter(C=>C!==g);B.length===0?t.indexes.bySubcircuit.delete(I):t.indexes.bySubcircuit.set(I,B)}}if(a.byCustomField&&t.indexes.byCustomField)for(const I of t.indexes.byCustomField.values())for(const[l,B]of I.entries()){const C=B.filter(E=>E!==g);C.length===0?I.delete(l):I.set(l,C)}},update:(r,a)=>{const g=A.indexConfig||{};let c;if(g.byId&&t.indexes.byId?c=t.indexes.byId.get(`${s}:${r}`):g.byType&&t.indexes.byType?c=(t.indexes.byType.get(s)||[]).find(l=>l[`${s}_id`]===r):c=e.find(I=>I.type===s&&I[`${s}_id`]===r),!c)return null;if(g.byRelation&&t.indexes.byRelation){const I=Object.entries(c);for(const[l,B]of I)if(l.endsWith("_id")&&l!==`${c.type}_id`&&typeof B=="string"&&l in a&&a[l]!==B){const C=t.indexes.byRelation.get(l);if(C){const Q=(C.get(B)||[]).filter(h=>h!==c);Q.length===0?C.delete(B):C.set(B,Q)}}}if(g.bySubcircuit&&t.indexes.bySubcircuit&&"subcircuit_id"in c&&"subcircuit_id"in a){const I=c.subcircuit_id,l=a.subcircuit_id;if(I!==l){const C=(t.indexes.bySubcircuit.get(I)||[]).filter(E=>E!==c);C.length===0?t.indexes.bySubcircuit.delete(I):t.indexes.bySubcircuit.set(I,C)}}if(g.byCustomField&&t.indexes.byCustomField){for(const I of g.byCustomField)if(I in c&&I in a&&c[I]!==a[I]){const l=t.indexes.byCustomField.get(I);if(l){const B=String(c[I]),E=(l.get(B)||[]).filter(Q=>Q!==c);E.length===0?l.delete(B):l.set(B,E)}}}if(Object.assign(c,a),t.editCount++,g.byRelation&&t.indexes.byRelation){const I=Object.entries(c);for(const[l,B]of I)if(l.endsWith("_id")&&l!==`${c.type}_id`&&typeof B=="string"&&l in a){const C=t.indexes.byRelation.get(l)||new Map,E=C.get(B)||[];E.includes(c)||(E.push(c),C.set(B,E),t.indexes.byRelation.set(l,C))}}if(g.bySubcircuit&&t.indexes.bySubcircuit&&"subcircuit_id"in c&&"subcircuit_id"in a){const I=c.subcircuit_id;if(I&&typeof I=="string"){const l=t.indexes.bySubcircuit.get(I)||[];l.includes(c)||(l.push(c),t.indexes.bySubcircuit.set(I,l))}}if(g.byCustomField&&t.indexes.byCustomField){for(const I of g.byCustomField)if(I in c&&I in a){const l=c[I];if(l!==void 0&&(typeof l=="string"||typeof l=="number")){const B=String(l),C=t.indexes.byCustomField.get(I),E=C.get(B)||[];E.includes(c)||(E.push(c),C.set(B,E))}}}return c},select:r=>{if(s==="source_component")return e.find(a=>a.type==="source_component"&&a.name===r.replace(/\./g,""))||null;if(s==="pcb_port"||s==="source_port"||s==="schematic_port"){const[a,g]=r.replace(/\./g,"").split(/[\s\>]+/),c=e.find(l=>l.type==="source_component"&&l.name===a);if(!c)return null;const I=e.find(l=>l.type==="source_port"&&l.source_component_id===c.source_component_id&&(l.name===g||(l.port_hints??[]).includes(g)));if(!I)return null;if(s==="source_port")return I;if(s==="pcb_port")return e.find(l=>l.type==="pcb_port"&&l.source_port_id===I.source_port_id)||null;if(s==="schematic_port")return e.find(l=>l.type==="schematic_port"&&l.source_port_id===I.source_port_id)||null}return null}}}})};Ggt.unparsed=Ggt;var HOe=e=>{const A=e.type;return e[`${A}_id`]},UpA=e=>{let A=Number.POSITIVE_INFINITY,t=Number.POSITIVE_INFINITY,i=Number.NEGATIVE_INFINITY,n=Number.NEGATIVE_INFINITY;for(const o of e){if(!o.type.startsWith("pcb_"))continue;if(o.type==="pcb_smtpad"&&o.shape==="polygon"&&Array.isArray(o.points)){for(const c of o.points)A=Math.min(A,c.x),t=Math.min(t,c.y),i=Math.max(i,c.x),n=Math.max(n,c.y);continue}let s,r,a,g;if("x"in o&&"y"in o&&(s=Number(o.x),r=Number(o.y)),"outer_diameter"in o&&(a=Number(o.outer_diameter),g=Number(o.outer_diameter)),"width"in o&&(a=Number(o.width)),"height"in o&&(g=Number(o.height)),"center"in o&&(s=o.center.x,r=o.center.y),s!==void 0&&r!==void 0)A=Math.min(A,s),t=Math.min(t,r),i=Math.max(i,s),n=Math.max(n,r),a!==void 0&&g!==void 0&&(A=Math.min(A,s-a/2),t=Math.min(t,r-g/2),i=Math.max(i,s+a/2),n=Math.max(n,r+g/2)),"radius"in o&&(A=Math.min(A,s-o.radius),t=Math.min(t,r-o.radius),i=Math.max(i,s+o.radius),n=Math.max(n,r+o.radius));else if(o.type==="pcb_trace")for(const c of o.route)A=Math.min(A,c.x),t=Math.min(t,c.y),i=Math.max(i,c.x),n=Math.max(n,c.y)}return{minX:A,minY:t,maxX:i,maxY:n}};function YOe(e){let A=0;if(e.length==0)return A;for(var t=0;t<e.length;t++){var i=e.charCodeAt(t);A=(A<<5)-A+i,A=A&A}return Math.abs(A)}var Mgt=[["#69d2e7","#a7dbd8","#e0e4cc","#f38630","#fa6900"],["#fe4365","#fc9d9a","#f9cdad","#c8c8a9","#83af9b"],["#ecd078","#d95b43","#c02942","#542437","#53777a"],["#556270","#4ecdc4","#c7f464","#ff6b6b","#c44d58"],["#774f38","#e08e79","#f1d4af","#ece5ce","#c5e0dc"],["#e8ddcb","#cdb380","#036564","#033649","#031634"],["#490a3d","#bd1550","#e97f02","#f8ca00","#8a9b0f"],["#594f4f","#547980","#45ada8","#9de0ad","#e5fcc2"],["#00a0b0","#6a4a3c","#cc333f","#eb6841","#edc951"],["#e94e77","#d68189","#c6a49a","#c6e5d9","#f4ead5"],["#3fb8af","#7fc7af","#dad8a7","#ff9e9d","#ff3d7f"],["#d9ceb2","#948c75","#d5ded9","#7a6a53","#99b2b7"],["#ffffff","#cbe86b","#f2e9e1","#1c140d","#cbe86b"],["#efffcd","#dce9be","#555152","#2e2633","#99173c"],["#343838","#005f6b","#008c9e","#00b4cc","#00dffc"],["#413e4a","#73626e","#b38184","#f0b49e","#f7e4be"],["#ff4e50","#fc913a","#f9d423","#ede574","#e1f5c4"],["#99b898","#fecea8","#ff847c","#e84a5f","#2a363b"],["#655643","#80bca3","#f6f7bd","#e6ac27","#bf4d28"],["#00a8c6","#40c0cb","#f9f2e7","#aee239","#8fbe00"],["#351330","#424254","#64908a","#e8caa4","#cc2a41"],["#554236","#f77825","#d3ce3d","#f1efa5","#60b99a"],["#5d4157","#838689","#a8caba","#cad7b2","#ebe3aa"],["#8c2318","#5e8c6a","#88a65e","#bfb35a","#f2c45a"],["#fad089","#ff9c5b","#f5634a","#ed303c","#3b8183"],["#ff4242","#f4fad2","#d4ee5e","#e1edb9","#f0f2eb"],["#f8b195","#f67280","#c06c84","#6c5b7b","#355c7d"],["#d1e751","#ffffff","#000000","#4dbce9","#26ade4"],["#1b676b","#519548","#88c425","#bef202","#eafde6"],["#5e412f","#fcebb6","#78c0a8","#f07818","#f0a830"],["#bcbdac","#cfbe27","#f27435","#f02475","#3b2d38"],["#452632","#91204d","#e4844a","#e8bf56","#e2f7ce"],["#eee6ab","#c5bc8e","#696758","#45484b","#36393b"],["#f0d8a8","#3d1c00","#86b8b1","#f2d694","#fa2a00"],["#2a044a","#0b2e59","#0d6759","#7ab317","#a0c55f"],["#f04155","#ff823a","#f2f26f","#fff7bd","#95cfb7"],["#b9d7d9","#668284","#2a2829","#493736","#7b3b3b"],["#bbbb88","#ccc68d","#eedd99","#eec290","#eeaa88"],["#b3cc57","#ecf081","#ffbe40","#ef746f","#ab3e5b"],["#a3a948","#edb92e","#f85931","#ce1836","#009989"],["#300030","#480048","#601848","#c04848","#f07241"],["#67917a","#170409","#b8af03","#ccbf82","#e33258"],["#aab3ab","#c4cbb7","#ebefc9","#eee0b7","#e8caaf"],["#e8d5b7","#0e2430","#fc3a51","#f5b349","#e8d5b9"],["#ab526b","#bca297","#c5ceae","#f0e2a4","#f4ebc3"],["#607848","#789048","#c0d860","#f0f0d8","#604848"],["#b6d8c0","#c8d9bf","#dadabd","#ecdbbc","#fedcba"],["#a8e6ce","#dcedc2","#ffd3b5","#ffaaa6","#ff8c94"],["#3e4147","#fffedf","#dfba69","#5a2e2e","#2a2c31"],["#fc354c","#29221f","#13747d","#0abfbc","#fcf7c5"],["#cc0c39","#e6781e","#c8cf02","#f8fcc1","#1693a7"],["#1c2130","#028f76","#b3e099","#ffeaad","#d14334"],["#a7c5bd","#e5ddcb","#eb7b59","#cf4647","#524656"],["#dad6ca","#1bb0ce","#4f8699","#6a5e72","#563444"],["#5c323e","#a82743","#e15e32","#c0d23e","#e5f04c"],["#edebe6","#d6e1c7","#94c7b6","#403b33","#d3643b"],["#fdf1cc","#c6d6b8","#987f69","#e3ad40","#fcd036"],["#230f2b","#f21d41","#ebebbc","#bce3c5","#82b3ae"],["#b9d3b0","#81bda4","#b28774","#f88f79","#f6aa93"],["#3a111c","#574951","#83988e","#bcdea5","#e6f9bc"],["#5e3929","#cd8c52","#b7d1a3","#dee8be","#fcf7d3"],["#1c0113","#6b0103","#a30006","#c21a01","#f03c02"],["#000000","#9f111b","#b11623","#292c37","#cccccc"],["#382f32","#ffeaf2","#fcd9e5","#fbc5d8","#f1396d"],["#e3dfba","#c8d6bf","#93ccc6","#6cbdb5","#1a1f1e"],["#f6f6f6","#e8e8e8","#333333","#990100","#b90504"],["#1b325f","#9cc4e4","#e9f2f9","#3a89c9","#f26c4f"],["#a1dbb2","#fee5ad","#faca66","#f7a541","#f45d4c"],["#c1b398","#605951","#fbeec2","#61a6ab","#accec0"],["#5e9fa3","#dcd1b4","#fab87f","#f87e7b","#b05574"],["#951f2b","#f5f4d7","#e0dfb1","#a5a36c","#535233"],["#8dccad","#988864","#fea6a2","#f9d6ac","#ffe9af"],["#2d2d29","#215a6d","#3ca2a2","#92c7a3","#dfece6"],["#413d3d","#040004","#c8ff00","#fa023c","#4b000f"],["#eff3cd","#b2d5ba","#61ada0","#248f8d","#605063"],["#ffefd3","#fffee4","#d0ecea","#9fd6d2","#8b7a5e"],["#cfffdd","#b4dec1","#5c5863","#a85163","#ff1f4c"],["#9dc9ac","#fffec7","#f56218","#ff9d2e","#919167"],["#4e395d","#827085","#8ebe94","#ccfc8e","#dc5b3e"],["#a8a7a7","#cc527a","#e8175d","#474747","#363636"],["#f8edd1","#d88a8a","#474843","#9d9d93","#c5cfc6"],["#046d8b","#309292","#2fb8ac","#93a42a","#ecbe13"],["#f38a8a","#55443d","#a0cab5","#cde9ca","#f1edd0"],["#a70267","#f10c49","#fb6b41","#f6d86b","#339194"],["#ff003c","#ff8a00","#fabe28","#88c100","#00c176"],["#ffedbf","#f7803c","#f54828","#2e0d23","#f8e4c1"],["#4e4d4a","#353432","#94ba65","#2790b0","#2b4e72"],["#0ca5b0","#4e3f30","#fefeeb","#f8f4e4","#a5b3aa"],["#4d3b3b","#de6262","#ffb88c","#ffd0b3","#f5e0d3"],["#fffbb7","#a6f6af","#66b6ab","#5b7c8d","#4f2958"],["#edf6ee","#d1c089","#b3204d","#412e28","#151101"],["#9d7e79","#ccac95","#9a947c","#748b83","#5b756c"],["#fcfef5","#e9ffe1","#cdcfb7","#d6e6c3","#fafbe3"],["#9cddc8","#bfd8ad","#ddd9ab","#f7af63","#633d2e"],["#30261c","#403831","#36544f","#1f5f61","#0b8185"],["#aaff00","#ffaa00","#ff00aa","#aa00ff","#00aaff"],["#d1313d","#e5625c","#f9bf76","#8eb2c5","#615375"],["#ffe181","#eee9e5","#fad3b2","#ffba7f","#ff9c97"],["#73c8a9","#dee1b6","#e1b866","#bd5532","#373b44"],["#805841","#dcf7f3","#fffcdd","#ffd8d8","#f5a2a2"]],JOe=e=>{let{x:A,y:t,width:i,height:n}={...e,...e.size,...e.center,...e.position};if(e.x1!==void 0&&e.x2!==void 0&&e.y1!==void 0&&e.y2!==void 0&&(A=(e.x1+e.x2)/2,t=(e.y1+e.y2)/2,i=Math.abs(e.x1-e.x2),n=Math.abs(e.y1-e.y2)),e.points&&Array.isArray(e.points)&&e.points.length>0){const r=e.points.map(B=>B.x),a=e.points.map(B=>B.y),g=Math.min(...r),c=Math.max(...r),I=Math.min(...a),l=Math.max(...a);A=(g+c)/2,t=(I+l)/2,i=c-g,n=l-I}const o=e.text||e.name||e.source?.text||e.source?.name||"?",s=e;return A===void 0||t===void 0?null:(i===void 0&&"outer_diameter"in e&&(i=e.outer_diameter,n=e.outer_diameter),(i===void 0||n===void 0)&&(i=.1,n=.1),{x:A,y:t,width:i,height:n,title:o,content:s,bg_color:Mgt[YOe(e.type||o)%Mgt.length]?.[4]??"#f00"})},TOe=e=>!!e,KOe=e=>{const A=e.filter(g=>g.type.startsWith("pcb_")||g.type.startsWith("schematic_")).concat(e.filter(g=>g.type==="pcb_trace"||g.type==="schematic_trace").flatMap(g=>g.route)).map(g=>JOe(g)).filter(TOe);if(A.length===0)return{center:{x:0,y:0},width:0,height:0};let t=A[0].x-A[0].width/2,i=A[0].x+A[0].width/2,n=A[0].y-A[0].height/2,o=A[0].y+A[0].height/2;for(const g of A.slice(1))t=Math.min(t,g.x-g.width/2),i=Math.max(i,g.x+g.width/2),n=Math.min(n,g.y-g.height/2),o=Math.max(o,g.y+g.height/2);const s=i-t,r=o-n;return{center:{x:t+s/2,y:n+r/2},width:s,height:r}},vD={IS_SHOWING_PCB_GROUPS:"pcb_viewer_is_showing_pcb_groups",PCB_GROUP_VIEW_MODE:"pcb_viewer_group_view_mode",IS_SHOWING_COPPER_POURS:"pcb_viewer_is_showing_copper_pours",IS_SHOWING_GROUP_ANCHOR_OFFSETS:"pcb_viewer_is_showing_group_anchor_offsets",IS_SHOWING_SOLDER_MASK:"pcb_viewer_is_showing_solder_mask"},t9=(e,A)=>{if(typeof window>"u")return A;try{const t=localStorage.getItem(e);return t!==null?JSON.parse(t):A}catch{return A}},e9=(e,A)=>{if(!(typeof window>"u"))try{localStorage.setItem(e,JSON.stringify(A))}catch{}},POe=(e,A)=>{if(typeof window>"u")return A;try{const t=localStorage.getItem(e);return t!==null?JSON.parse(t):A}catch{return A}},qOe=(e,A)=>{if(!(typeof window>"u"))try{localStorage.setItem(e,JSON.stringify(A))}catch{}},OOe="named_only",WOe=(e={},A=!1)=>Qat(t=>({selected_layer:"top",pcb_viewer_id:`pcb_viewer_${Math.random().toString().slice(2,10)}`,in_edit_mode:!1,in_move_footprint_mode:!1,in_draw_trace_mode:!1,is_moving_component:!1,is_drawing_trace:!1,is_mouse_over_container:!1,is_showing_multiple_traces_length:!1,is_showing_rats_nest:!1,is_showing_autorouting:!0,is_showing_drc_errors:!0,is_showing_copper_pours:t9(vD.IS_SHOWING_COPPER_POURS,!0),is_showing_pcb_groups:A?!1:t9(vD.IS_SHOWING_PCB_GROUPS,!0),is_showing_group_anchor_offsets:t9(vD.IS_SHOWING_GROUP_ANCHOR_OFFSETS,!0),is_showing_solder_mask:t9(vD.IS_SHOWING_SOLDER_MASK,!1),pcb_group_view_mode:A?"all":POe(vD.PCB_GROUP_VIEW_MODE,OOe),hovered_error_id:null,...e,selectLayer:i=>t({selected_layer:i}),setEditMode:i=>t({in_edit_mode:i!=="off",in_move_footprint_mode:i==="move_footprint",in_draw_trace_mode:i==="draw_trace",is_moving_component:!1,is_drawing_trace:!1}),setIsShowingRatsNest:i=>t({is_showing_rats_nest:i}),setIsMovingComponent:i=>t({is_moving_component:i}),setIsDrawingTrace:i=>t({is_drawing_trace:i}),setIsMouseOverContainer:i=>t({is_mouse_over_container:i}),setIsShowingMultipleTracesLength:i=>t({is_showing_multiple_traces_length:i}),setIsShowingAutorouting:i=>t({is_showing_autorouting:i}),setIsShowingDrcErrors:i=>t({is_showing_drc_errors:i}),setIsShowingCopperPours:i=>{e9(vD.IS_SHOWING_COPPER_POURS,i),t({is_showing_copper_pours:i})},setIsShowingPcbGroups:i=>{A||(e9(vD.IS_SHOWING_PCB_GROUPS,i),t({is_showing_pcb_groups:i}))},setIsShowingGroupAnchorOffsets:i=>{e9(vD.IS_SHOWING_GROUP_ANCHOR_OFFSETS,i),t({is_showing_group_anchor_offsets:i})},setIsShowingSolderMask:i=>{e9(vD.IS_SHOWING_SOLDER_MASK,i),t({is_showing_solder_mask:i})},setPcbGroupViewMode:i=>{A||(qOe(vD.PCB_GROUP_VIEW_MODE,i),t({pcb_group_view_mode:i}))},setHoveredErrorId:i=>t({hovered_error_id:i})})),zB=e=>{const A=AA.useContext(Rgt);return Dat(A,e)},Rgt=AA.createContext(null),ZOe=({children:e,initialState:A,disablePcbGroups:t})=>{const i=AA.useMemo(()=>WOe(A,t),[t]);return Z.jsx(Rgt.Provider,{value:i,children:e})},VOe=()=>{const e=zB(t=>t.pcb_viewer_id),A=(t,i)=>qg(t,{containerId:e,...i});return A.error=(t,i)=>qg.error(t,{containerId:e,...i}),A.promise=qg.promise,A},jOe=()=>{AA.useEffect(()=>{Oqe()},[]);const e=zB(A=>A.pcb_viewer_id);return Z.jsx(qqe,{position:"top-center",containerId:e})};function zOe(){var e=AA.useRef(!1),A=AA.useCallback(function(){return e.current},[]);return AA.useEffect(function(){return e.current=!0,function(){e.current=!1}},[]),A}var XOe=function(e){e===void 0&&(e={});var A=AA.useState(e),t=A[0],i=A[1],n=AA.useCallback(function(o){i(function(s){return Object.assign({},s,o instanceof Function?o(s):o)})},[]);return[t,n]},$Oe=XOe,A5e=function(){},Ngt=typeof window<"u",t5e=GpA(pOe()),e5e=function(){var e=zOe(),A=$Oe({value:void 0,error:void 0,noUserInteraction:!0}),t=A[0],i=A[1],n=AA.useCallback(function(o){if(e()){var s,r;try{if(typeof o!="string"&&typeof o!="number"){var a=new Error("Cannot copy typeof "+typeof o+" to clipboard, must be a string");console.error(a),i({value:o,error:a,noUserInteraction:!0});return}else if(o===""){var a=new Error("Cannot copy empty string to clipboard.");console.error(a),i({value:o,error:a,noUserInteraction:!0});return}r=o.toString(),s=(0,t5e.default)(r),i({value:r,error:void 0,noUserInteraction:s})}catch(g){i({value:r,error:g,noUserInteraction:s})}}},[]);return[t,n]},i5e=e5e,n5e=Ngt?AA.useLayoutEffect:AA.useEffect,o5e=n5e,vgt={x:0,y:0,width:0,height:0,top:0,left:0,bottom:0,right:0};function s5e(){var e=AA.useState(null),A=e[0],t=e[1],i=AA.useState(vgt),n=i[0],o=i[1],s=AA.useMemo(function(){return new window.ResizeObserver(function(r){if(r[0]){var a=r[0].contentRect,g=a.x,c=a.y,I=a.width,l=a.height,B=a.top,C=a.left,E=a.bottom,Q=a.right;o({x:g,y:c,width:I,height:l,top:B,left:C,bottom:E,right:Q})}})},[]);return o5e(function(){if(A)return s.observe(A),function(){s.disconnect()}},[A]),[t,n]}var zY=Ngt&&typeof window.ResizeObserver<"u"?s5e:function(){return[A5e,vgt]},Lgt=({initialTransform:e,initialTouch1:A,initialTouch2:t,finalTouch1:i,finalTouch2:n})=>{if(!i||!n)return e;const o={x:(A.x+t.x)/2,y:(A.y+t.y)/2},s={x:(i.x+n.x)/2,y:(i.y+n.y)/2},r=Math.hypot(t.x-A.x,t.y-A.y),a=Math.hypot(n.x-i.x,n.y-i.y),g=r===0?1:a/r,c=s.x-o.x,I=s.y-o.y;return Oy(rB(c,I),rB(o.x,o.y),JY(g,g),rB(-o.x,-o.y),e)},r5e=(e={})=>{const A=AA.useRef(null),[t,i]=AA.useState(0),n=e.canvasElm??A.current,[o,s]=AA.useState(e.initialTransform??yb()),[r,a]=AA.useState(0),[g,c]=AA.useReducer(d=>d+1,0),I=AA.useCallback(d=>{e.onSetTransform&&e.onSetTransform(d),e.transform||s(d)},[e.onSetTransform,s]),l=AA.useCallback(d=>{I(d),c()},[I]),B=e.transform??o,C=AA.useCallback(()=>{i(Date.now())},[]),E=AA.useRef("none"),Q=AA.useRef(null),h=AA.useRef(null);AA.useEffect(()=>{const d=e.canvasElm??A.current;if(d&&!n){a(r+1);return}if(!d){const W=setTimeout(()=>{a(r+1)},100);return()=>clearTimeout(W)}let f=e.transform??o,m={x:0,y:0},w={x:0,y:0},D=!1;const b=W=>({x:W.pageX-d.getBoundingClientRect().left-window.scrollX,y:W.pageY-d.getBoundingClientRect().top-window.scrollY});function k(W){e.enabled!==!1&&(e.shouldDrag&&!e.shouldDrag(W)||(m=b(W),!(Date.now()-t<100)&&(D=!0,W.preventDefault())))}function x(W){if(!D||e.enabled===!1||e.shouldDrag&&!e.shouldDrag(W))return;w=b(W);const X=Oy(rB(w.x-m.x,w.y-m.y),f);I(X),f=X,D=!1}function N(W){if(b(W),!D||e.enabled===!1||e.shouldDrag&&!e.shouldDrag(W))return;w=b(W);const X=Oy(rB(w.x-m.x,w.y-m.y),f);I(X)}function R(W){if(e.enabled===!1||e.shouldDrag&&!e.shouldDrag(W))return;const X=b(W),iA=Oy(rB(X.x,X.y),JY(1-W.deltaY/1e3,1-W.deltaY/1e3),rB(-X.x,-X.y),f);I(iA),f=iA,W.preventDefault()}function U(W){if(!D||e.shouldDrag&&!e.shouldDrag(W))return;if(d){const iA=d.getBoundingClientRect();if(W.clientX>=iA.left+10&&W.clientX<=iA.right-10&&W.clientY>=iA.top+10&&W.clientY<=iA.bottom-10)return}D=!1,w=b(W);const X=Oy(rB(w.x-m.x,w.y-m.y),f);I(X),f=X}function T(W){if(W.preventDefault(),e.enabled!==!1){if(W.touches.length===1){E.current="drag";const X=W.touches[0];Q.current={initialTransform:f,initialTouch:{x:X.clientX,y:X.clientY}}}else if(W.touches.length===2){E.current="pinch";const X=W.touches[0],iA=W.touches[1];h.current={initialTransform:f,initialTouch1:{x:X.clientX,y:X.clientY},initialTouch2:{x:iA.clientX,y:iA.clientY},finalTouch1:null,finalTouch2:null}}}}function H(W){if(W.preventDefault(),e.enabled!==!1){if(E.current==="drag"&&W.touches.length===1&&Q.current){const X=W.touches[0],iA={x:X.clientX,y:X.clientY},aA=iA.x-Q.current.initialTouch.x,tA=iA.y-Q.current.initialTouch.y,oA=Oy(rB(aA,tA),Q.current.initialTransform);I(oA)}else if(E.current==="pinch"&&W.touches.length===2&&h.current){const X=W.touches[0],iA=W.touches[1];h.current.finalTouch1={x:X.clientX,y:X.clientY},h.current.finalTouch2={x:iA.clientX,y:iA.clientY};const aA=Lgt(h.current);I(aA)}}}function O(W){W.preventDefault();const X=W.changedTouches[0];if(E.current==="drag"&&Q.current&&X){const iA={x:X.clientX,y:X.clientY},aA=iA.x-Q.current.initialTouch.x,tA=iA.y-Q.current.initialTouch.y,oA=Oy(rB(aA,tA),Q.current.initialTransform);I(oA),f=oA}else if(E.current==="pinch"&&h.current){const iA=Lgt(h.current);I(iA),f=iA}E.current="none",Q.current=null,h.current=null}return d.addEventListener("mousedown",k),d.addEventListener("mouseup",x),window.addEventListener("mousemove",N),d.addEventListener("mouseout",U),d.addEventListener("wheel",R),d.addEventListener("touchstart",T,{passive:!1}),d.addEventListener("touchmove",H,{passive:!1}),d.addEventListener("touchend",O,{passive:!1}),d.addEventListener("touchcancel",O,{passive:!1}),()=>{d.removeEventListener("mousedown",k),d.removeEventListener("mouseup",x),window.removeEventListener("mousemove",N),d.removeEventListener("mouseout",U),d.removeEventListener("wheel",R),d.removeEventListener("touchstart",T),d.removeEventListener("touchmove",H),d.removeEventListener("touchend",O),d.removeEventListener("touchcancel",O)}},[n,r,g,t,e.enabled,e.shouldDrag]);const u=AA.useCallback(d=>qi(B,d),[B]);return{ref:A,transform:B,applyTransformToPoint:u,setTransform:l,cancelDrag:C}},a5e=r5e;function g5e(e){const A=new Map;let t=0;function i(n){for(const[,s]of A)if(s.has(n))return s;const o=new Set;return A.set(`connectivity_net${t++}`,o),o}for(const n of e){let o=null;for(const s of n){if(!o)o=i(s);else if(!o.has(s)){const r=i(s);if(r!==o){for(const a of r)o.add(a);A.delete(Array.from(A.entries()).find(([,a])=>a===r)[0])}}o.add(s)}}return Object.fromEntries(Array.from(A.entries()).map(([n,o])=>[n,Array.from(o)]))}var c5e=class{netMap;idToNetMap;constructor(e){this.netMap=e,this.idToNetMap={};for(const[A,t]of Object.entries(e))for(const i of t)this.idToNetMap[i]=A}addConnections(e){for(const A of e){const t=new Set;for(const n of A){const o=this.idToNetMap[n];o&&t.add(o)}let i;if(t.size===0)i=`connectivity_net${Object.keys(this.netMap).length}`,this.netMap[i]=[];else if(t.size===1)i=t.values().next().value??`connectivity_net${Object.keys(this.netMap).length}`;else{i=t.values().next().value??`connectivity_net${Object.keys(this.netMap).length}`;for(const n of t)if(n!==i){this.netMap[i].push(...this.netMap[n]),this.netMap[n]=this.netMap[i];for(const o of this.netMap[i])this.idToNetMap[o]=i}}for(const n of A)this.netMap[i].includes(n)||this.netMap[i].push(n),this.idToNetMap[n]=i}}getIdsConnectedToNet(e){return this.netMap[e]||[]}getNetConnectedToId(e){return this.idToNetMap[e]}areIdsConnected(e,A){if(e===A)return!0;const t=this.getNetConnectedToId(e);if(!t)return!1;const i=this.getNetConnectedToId(A);return i?t===i||i===e||i===e:!1}areAllIdsConnected(e){const A=this.getNetConnectedToId(e[0]);for(const t of e){const i=this.getNetConnectedToId(t);if(i===void 0||i!==A)return!1}return!0}},Ugt=e=>{const A=[];for(const i of e)if(i.type==="source_trace")A.push([i.source_trace_id,...i.connected_source_port_ids??[],...i.connected_source_net_ids??[]].filter(Boolean));else if(i.type==="pcb_port"){const{pcb_port_id:n,source_port_id:o}=i;o&&n&&A.push([o,n])}else if(i.type==="pcb_smtpad"){const{pcb_smtpad_id:n,pcb_port_id:o}=i;o&&n&&A.push([n,o])}else if(i.type==="pcb_plated_hole"){const{pcb_plated_hole_id:n,pcb_port_id:o}=i;o&&n&&A.push([n,o])}else if(i.type==="pcb_trace"){const{pcb_trace_id:n,source_trace_id:o}=i,s=Array.isArray(i.route)?i.route.filter(r=>r&&r.route_type==="wire"):[];if(o&&n&&A.push([n,o]),Array.isArray(s)){const r=s.find(g=>g?.start_pcb_port_id)?.start_pcb_port_id,a=s.find(g=>g?.end_pcb_port_id)?.end_pcb_port_id;r&&n&&a&&A.push([r,n,a])}}else if(i.type==="pcb_via"){const{pcb_via_id:n,pcb_trace_id:o}=i;o&&n&&A.push([n,o])}else if(i.type==="source_component"&&i.internally_connected_source_port_ids)for(const n of i.internally_connected_source_port_ids)A.push(n);const t=g5e(A);return new c5e(t)};function I5e({primitivesWithoutInteractionMetadata:e,drawingObjectIdsWithMouseOver:A,primitiveIdsInMousedOverNet:t}){const i=[];for(const n of e){const o={...n};n?.layer==="drill"?(o.is_in_highlighted_net=!1,o.is_mouse_over=!1):A.has(n._pcb_drawing_object_id)?o.is_mouse_over=!0:n._element&&("pcb_trace_id"in n._element&&t.includes(n._element.pcb_trace_id)||"pcb_port_id"in n._element&&t.includes(n._element.pcb_port_id))?o.is_in_highlighted_net=!0:(o.is_in_highlighted_net=!1,o.is_mouse_over=!1),i.push(o)}return i}function l5e(e,A){if(e.length<2)throw new Error("Stroke must have at least two points");const t=e.map(I=>Array.isArray(I)?{x:I[0],y:I[1]}:I),i=[],n=[];function o(I,l){const B=l.x-I.x,C=l.y-I.y,E=Math.sqrt(B*B+C*C);return{x:-C/E,y:B/E}}function s(I,l,B,C){const E=C/2,Q={x:I.x+l.x*E*B,y:I.y+l.y*E*B};B>0?i.push(Q):n.unshift(Q)}const r=o(t[0],t[1]),a=t[0].trace_width??A;s(t[0],r,1,a),s(t[0],r,-1,a);for(let I=1;I<t.length-1;I++){const l=t[I-1],B=t[I],C=t[I+1],E=o(l,B),Q=o(B,C),h=E.x+Q.x,u=E.y+Q.y,d=Math.sqrt(h*h+u*u),f=B.trace_width??A;if(d/2>2*(f/2))s(B,E,1,f),s(B,Q,1,f),s(B,E,-1,f),s(B,Q,-1,f);else{const w=1/d;s(B,{x:h*w,y:u*w},1,f),s(B,{x:h*w,y:u*w},-1,f)}}const g=o(t[t.length-2],t[t.length-1]),c=t[t.length-1].trace_width??A;return s(t[t.length-1],g,1,c),s(t[t.length-1],g,-1,c),[...i,...n]}var B5e=(e,A)=>{const{x:t,y:i,width:n,height:o,layer:s,rect_border_radius:r}=e,a=e.corner_radius??r??0,g=[{_pcb_drawing_object_id:Wy("rect"),pcb_drawing_type:"rect",x:t,y:i,w:n,h:o,layer:s||"top",_element:e,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,roundness:a,...e.shape==="rotated_rect"&&e.ccw_rotation!==void 0?{ccw_rotation:e.ccw_rotation}:{}}];if(e.is_covered_with_solder_mask){const c=s==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",l={...{_pcb_drawing_object_id:Wy("rect"),pcb_drawing_type:"rect",x:t,y:i,w:n,h:o,layer:c,_element:e,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,roundness:a,...e.shape==="rotated_rect"&&e.ccw_rotation!==void 0?{ccw_rotation:e.ccw_rotation}:{}},..."solder_mask_color"in e&&e.solder_mask_color?{color:e.solder_mask_color}:{}};g.push(l)}return g},C5e=(e,A)=>{const{x:t,y:i,radius:n,layer:o}=e,s=[{_pcb_drawing_object_id:Wy("circle"),pcb_drawing_type:"circle",x:t,y:i,r:n,layer:o||"top",_element:e,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port}];if(e.is_covered_with_solder_mask){const r=o==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",a={_pcb_drawing_object_id:Wy("circle"),pcb_drawing_type:"circle",x:t,y:i,r:n,layer:r,_element:e,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,..."solder_mask_color"in e&&e.solder_mask_color?{color:e.solder_mask_color}:{}};s.push(a)}return s},Q5e=(e,A)=>{const{layer:t,points:i}=e,n=[{_pcb_drawing_object_id:Wy("polygon"),pcb_drawing_type:"polygon",points:HpA(i),layer:t||"top",_element:e,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port}];if(e.is_covered_with_solder_mask){const o=t==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",s={_pcb_drawing_object_id:Wy("polygon"),pcb_drawing_type:"polygon",points:HpA(i),layer:o,_element:e,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,..."solder_mask_color"in e&&e.solder_mask_color?{color:e.solder_mask_color}:{}};n.push(s)}return n},E5e=(e,A)=>{const{x:t,y:i,width:n,height:o,layer:s}=e,r=[{_pcb_drawing_object_id:Wy("pill"),pcb_drawing_type:"pill",x:t,y:i,w:n,h:o,layer:s||"top",_element:e,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port}];if(e.is_covered_with_solder_mask){const a=s==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",g={_pcb_drawing_object_id:Wy("pill"),pcb_drawing_type:"pill",x:t,y:i,w:n,h:o,layer:a,_element:e,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,..."solder_mask_color"in e&&e.solder_mask_color?{color:e.solder_mask_color}:{}};r.push(g)}return r},h5e=(e,A)=>{const{x:t,y:i,width:n,height:o,layer:s,ccw_rotation:r}=e,a=[{_pcb_drawing_object_id:Wy("pill"),pcb_drawing_type:"pill",x:t,y:i,w:n,h:o,layer:s||"top",_element:e,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,ccw_rotation:r}];if(e.is_covered_with_solder_mask){const g=s==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",c={_pcb_drawing_object_id:Wy("pill"),pcb_drawing_type:"pill",x:t,y:i,w:n,h:o,layer:g,_element:e,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,ccw_rotation:r,..."solder_mask_color"in e&&e.solder_mask_color?{color:e.solder_mask_color}:{}};a.push(c)}return a},u5e=(e,A)=>{const{_parent_pcb_component:t,_parent_source_component:i}=A,n=e,o=typeof n.font_size=="string"?he.parse(n.font_size):n.font_size??.2;let s;return n.knockout_padding&&(s={left:typeof n.knockout_padding.left=="string"?he.parse(n.knockout_padding.left):n.knockout_padding.left,top:typeof n.knockout_padding.top=="string"?he.parse(n.knockout_padding.top):n.knockout_padding.top,bottom:typeof n.knockout_padding.bottom=="string"?he.parse(n.knockout_padding.bottom):n.knockout_padding.bottom,right:typeof n.knockout_padding.right=="string"?he.parse(n.knockout_padding.right):n.knockout_padding.right}),[{_pcb_drawing_object_id:Wy("text"),pcb_drawing_type:"text",x:n.anchor_position.x,y:n.anchor_position.y,layer:n.layer,align:n.anchor_alignment??"center",text:n.text,size:o,ccw_rotation:n.ccw_rotation,is_mirrored:n.is_mirrored,is_knockout:n.is_knockout,knockout_padding:s,_element:e,_parent_pcb_component:t,_parent_source_component:i}]},SI=0,Wy=e=>`${e}_${SI++}`,HpA=e=>(e??[]).map(A=>({x:he.parse(A.x),y:he.parse(A.y)})),d5e=(e,A)=>{const t="pcb_component_id"in e?A.find(s=>s.type==="pcb_component"&&s.pcb_component_id===e.pcb_component_id):void 0,i=t&&"source_component_id"in t?A.find(s=>s.type==="source_component"&&s.source_component_id===t.source_component_id):void 0,n="source_port_id"in e?e.source_port_id:"pcb_port_id"in e?Db(A).pcb_port.get(e.pcb_port_id)?.source_port_id:void 0,o=n?A.find(s=>s.type==="source_port"&&s.source_port_id===n):void 0;switch(e.type){case"pcb_smtpad":{const s={_parent_pcb_component:t,_parent_source_component:i,_source_port:o};return e.shape==="rect"||e.shape==="rotated_rect"?B5e(e,s):e.shape==="circle"?C5e(e,s):e.shape==="polygon"?Q5e(e,s):e.shape==="pill"?E5e(e,s):e.shape==="rotated_pill"?h5e(e,s):[]}case"pcb_trace":{const s=[];if(e.route_thickness_mode==="interpolated"){const g=e.route.map(l=>({x:l.x,y:l.y,trace_width:l.route_type==="wire"?l.width:.5})),c=l5e(g,.5),I=e.route[0].layer;return s.push({_pcb_drawing_object_id:`polygon_${SI++}`,_element:e,pcb_drawing_type:"polygon",points:c,layer:I}),e.route.forEach(l=>{l.route_type==="via"&&s.push({_pcb_drawing_object_id:`circle_${SI++}`,_element:e,pcb_drawing_type:"circle",x:l.x,y:l.y,r:l.outer_diameter/2,layer:l.from_layer})}),s}let r=null,a=null;for(const g of e.route)g.route_type==="wire"&&(r!==null&&a!==null&&s.push({_pcb_drawing_object_id:`line_${SI++}`,_element:e,pcb_drawing_type:"line",x1:r,y1:a,x2:g.x,y2:g.y,width:g.width,squareCap:!1,layer:g.layer}),r=g.x,a=g.y);return s}case"pcb_via":{const{x:s,y:r,outer_diameter:a,hole_diameter:g}=e,c=e.from_layer,I=e.to_layer,l=e.layers,B=[];c&&I?B.push(c,I):l&&Array.isArray(l)?B.push(...l):B.push("top","bottom");const C=[];for(const E of B)C.push({_pcb_drawing_object_id:`circle_${SI++}`,pcb_drawing_type:"circle",x:s,y:r,r:a/2,layer:E,_element:e,_parent_pcb_component:t,_parent_source_component:i});return C.push({_pcb_drawing_object_id:`circle_${SI++}`,pcb_drawing_type:"circle",x:s,y:r,r:g/2,layer:"drill",_element:e}),C}case"pcb_plated_hole":if(e.shape==="circle"){const{x:s,y:r,hole_diameter:a,outer_diameter:g}=e;return[{_pcb_drawing_object_id:`circle_${SI++}`,pcb_drawing_type:"circle",x:s,y:r,r:g/2,layer:"top",_element:e,_parent_pcb_component:t,_parent_source_component:i,_source_port:o},{_pcb_drawing_object_id:`circle_${SI++}`,pcb_drawing_type:"circle",x:s,y:r,r:a/2,layer:"drill",_element:e}]}else if(e.shape==="oval"){const{x:s,y:r,outer_height:a,outer_width:g,hole_height:c,hole_width:I}=e;return[{_pcb_drawing_object_id:`oval_${SI++}`,pcb_drawing_type:"oval",x:s,y:r,rX:g/2,rY:a/2,layer:"top",_element:e,_parent_pcb_component:t,_parent_source_component:i,_source_port:o},{_pcb_drawing_object_id:`oval_${SI++}`,_element:e,pcb_drawing_type:"oval",x:s,y:r,rX:I/2,rY:c/2,layer:"drill"}]}else if(e.shape==="pill"){const{x:s,y:r,outer_height:a,outer_width:g,hole_height:c,hole_width:I}=e;return[{_pcb_drawing_object_id:`pill_${SI++}`,pcb_drawing_type:"pill",x:s,y:r,w:g,h:a,layer:"top",_element:e,_parent_pcb_component:t,_parent_source_component:i,_source_port:o,ccw_rotation:e.ccw_rotation},{_pcb_drawing_object_id:`pill_${SI++}`,_element:e,pcb_drawing_type:"pill",x:s,y:r,w:I,h:c,layer:"drill",ccw_rotation:e.ccw_rotation}]}else if(e.shape==="circular_hole_with_rect_pad"){const{x:s,y:r,hole_diameter:a,rect_pad_width:g,rect_pad_height:c,rect_border_radius:I,hole_offset_x:l,hole_offset_y:B}=e,C=he.parse(l??0),E=he.parse(B??0);return[{_pcb_drawing_object_id:`rect_${SI++}`,pcb_drawing_type:"rect",x:s,y:r,w:g,h:c,layer:"top",_element:e,_parent_pcb_component:t,_parent_source_component:i,_source_port:o,roundness:I},{_pcb_drawing_object_id:`rect_${SI++}`,pcb_drawing_type:"rect",x:s,y:r,w:g,h:c,layer:"bottom",_element:e,_parent_pcb_component:t,_parent_source_component:i,_source_port:o,roundness:I},{_pcb_drawing_object_id:`circle_${SI++}`,_element:e,pcb_drawing_type:"circle",x:s+C,y:r+E,r:a/2,layer:"drill"}]}else if(e.shape==="pill_hole_with_rect_pad"){const{x:s,y:r,hole_width:a,hole_height:g,rect_pad_width:c,rect_pad_height:I,rect_border_radius:l}=e;return[{_pcb_drawing_object_id:`rect_${SI++}`,pcb_drawing_type:"rect",x:s,y:r,w:c,h:I,layer:"top",_element:e,_parent_pcb_component:t,_parent_source_component:i,_source_port:o,roundness:l},{_pcb_drawing_object_id:`rect_${SI++}`,pcb_drawing_type:"rect",x:s,y:r,w:c,h:I,layer:"bottom",_element:e,_parent_pcb_component:t,_parent_source_component:i,_source_port:o,roundness:l},{_pcb_drawing_object_id:`pill_${SI++}`,_element:e,pcb_drawing_type:"pill",x:s,y:r,w:a,h:g,layer:"drill"}]}else if(e.shape==="rotated_pill_hole_with_rect_pad"){const{x:s,y:r,hole_width:a,hole_height:g,hole_ccw_rotation:c,rect_pad_width:I,rect_pad_height:l,rect_ccw_rotation:B,rect_border_radius:C}=e;return[{_pcb_drawing_object_id:`rect_${SI++}`,pcb_drawing_type:"rect",x:s,y:r,w:I,h:l,layer:"top",_element:e,_parent_pcb_component:t,_parent_source_component:i,_source_port:o,ccw_rotation:B,roundness:C},{_pcb_drawing_object_id:`rect_${SI++}`,pcb_drawing_type:"rect",x:s,y:r,w:I,h:l,layer:"bottom",_element:e,_parent_pcb_component:t,_parent_source_component:i,_source_port:o,ccw_rotation:B,roundness:C},{_pcb_drawing_object_id:`pill_${SI++}`,_element:e,pcb_drawing_type:"pill",x:s,y:r,w:a,h:g,layer:"drill",ccw_rotation:c}]}else if(e.shape==="hole_with_polygon_pad"){const{x:s,y:r,pad_outline:a,hole_shape:g,hole_diameter:c,hole_width:I,hole_height:l,layers:B,hole_offset_x:C,hole_offset_y:E}=e,Q=he.parse(C??0),h=he.parse(E??0),u=a,d=[];if(u&&Array.isArray(u)){const w=HpA(u).map(D=>({x:D.x+s,y:D.y+r}));for(const D of B||["top","bottom"])d.push({_pcb_drawing_object_id:`polygon_${SI++}`,pcb_drawing_type:"polygon",points:w,layer:D,_element:e,_parent_pcb_component:t,_parent_source_component:i,_source_port:o})}const f={x:s+Q,y:r+h},m=[];return g==="circle"?m.push({_pcb_drawing_object_id:`circle_${SI++}`,pcb_drawing_type:"circle",x:f.x,y:f.y,r:(c??0)/2,layer:"drill",_element:e,_parent_pcb_component:t,_parent_source_component:i}):g==="oval"?m.push({_pcb_drawing_object_id:`oval_${SI++}`,pcb_drawing_type:"oval",x:f.x,y:f.y,rX:(I??0)/2,rY:(l??0)/2,layer:"drill",_element:e,_parent_pcb_component:t,_parent_source_component:i}):(g==="pill"||g==="rotated_pill")&&m.push({_pcb_drawing_object_id:`pill_${SI++}`,pcb_drawing_type:"pill",x:f.x,y:f.y,w:I??0,h:l??0,layer:"drill",_element:e,_parent_pcb_component:t,_parent_source_component:i,ccw_rotation:e.ccw_rotation}),[...d,...m]}else return[];case"pcb_copper_text":return u5e(e,{_parent_pcb_component:t,_parent_source_component:i})}return[]},In={board:{anchor:"rgb(255, 38, 226)",aux_items:"rgb(255, 255, 255)",b_adhes:"rgb(0, 0, 132)",b_crtyd:"rgb(38, 233, 255)",b_fab:"rgb(88, 93, 132)",b_mask:"rgba(2, 255, 238, 0.400)",b_paste:"rgb(0, 194, 194)",b_silks:"rgb(242, 237, 161)",background:"rgb(0, 16, 35)",cmts_user:"rgb(89, 148, 220)",copper:{b:"rgb(77, 127, 196)",f:"rgb(200, 52, 52)",in1:"rgb(127, 200, 127)",in10:"rgb(237, 124, 51)",in11:"rgb(91, 195, 235)",in12:"rgb(247, 111, 142)",in13:"rgb(167, 165, 198)",in14:"rgb(40, 204, 217)",in15:"rgb(232, 178, 167)",in16:"rgb(242, 237, 161)",in17:"rgb(237, 124, 51)",in18:"rgb(91, 195, 235)",in19:"rgb(247, 111, 142)",in2:"rgb(206, 125, 44)",in20:"rgb(167, 165, 198)",in21:"rgb(40, 204, 217)",in22:"rgb(232, 178, 167)",in23:"rgb(242, 237, 161)",in24:"rgb(237, 124, 51)",in25:"rgb(91, 195, 235)",in26:"rgb(247, 111, 142)",in27:"rgb(167, 165, 198)",in28:"rgb(40, 204, 217)",in29:"rgb(232, 178, 167)",in3:"rgb(79, 203, 203)",in30:"rgb(242, 237, 161)",in4:"rgb(219, 98, 139)",in5:"rgb(167, 165, 198)",in6:"rgb(40, 204, 217)",in7:"rgb(232, 178, 167)",in8:"rgb(242, 237, 161)",in9:"rgb(141, 203, 129)"},cursor:"rgb(255, 255, 255)",drc:"rgb(194, 194, 194)",drc_error:"rgba(215, 91, 107, 0.800)",drc_exclusion:"rgb(255, 255, 255)",drc_warning:"rgba(255, 208, 66, 0.902)",dwgs_user:"rgb(194, 194, 194)",eco1_user:"rgb(180, 219, 210)",eco2_user:"rgb(216, 200, 82)",edge_cuts:"rgb(208, 210, 205)",f_adhes:"rgb(132, 0, 132)",f_crtyd:"rgb(255, 0, 245)",f_fab:"rgb(175, 175, 175)",f_mask:"rgba(216, 100, 255, 0.400)",f_paste:"rgba(180, 160, 154, 0.902)",f_silks:"rgb(242, 237, 161)",footprint_text_back:"rgb(0, 0, 132)",footprint_text_front:"rgb(194, 194, 194)",footprint_text_invisible:"rgb(132, 132, 132)",grid:"rgb(132, 132, 132)",grid_axes:"rgb(194, 194, 194)",margin:"rgb(255, 38, 226)",microvia:"rgb(0, 132, 132)",no_connect:"rgb(0, 0, 132)",pad_back:"rgb(77, 127, 196)",pad_front:"rgb(200, 52, 52)",pad_plated_hole:"rgb(194, 194, 0)",pad_through_hole:"rgb(227, 183, 46)",plated_hole:"rgb(26, 196, 210)",ratsnest:"rgba(245, 255, 213, 0.702)",select_overlay:"rgb(4, 255, 67)",soldermaskWithCopper:{top:"rgb(18, 82, 50)",bottom:"rgb(77, 127, 196)"},soldermask:{top:"rgb(12, 55, 33)",bottom:"rgb(12, 55, 33)"},through_via:"rgb(236, 236, 236)",user_1:"rgb(194, 194, 194)",user_2:"rgb(89, 148, 220)",user_3:"rgb(180, 219, 210)",user_4:"rgb(216, 200, 82)",user_5:"rgb(194, 194, 194)",user_6:"rgb(89, 148, 220)",user_7:"rgb(180, 219, 210)",user_8:"rgb(216, 200, 82)",user_9:"rgb(232, 178, 167)",via_blind_buried:"rgb(187, 151, 38)",via_hole:"rgb(227, 183, 46)",via_micro:"rgb(0, 132, 132)",via_through:"rgb(236, 236, 236)",worksheet:"rgb(200, 114, 171)"}},Cf=(e,A=1)=>{if(Math.abs(e.a)!==Math.abs(e.d))throw new Error("Cannot scale non-uniformly");return A*Math.abs(e.a)},Qc={elementOverlay:40,dimensionOverlay:40,editTraceHintOverlay:40,errorOverlay:40,pcbGroupOverlay:35,ratsNestOverlay:30,toolbarOverlay:70,warnings:30,topLayer:20,clickToInteractOverlay:100},i9={red:"red",black:"black",green:"green",board:"rgb(255, 255, 255)",other:"#eee",top:In.board.copper.f,inner1:In.board.copper.in1,inner2:In.board.copper.in2,inner3:In.board.copper.in3,inner4:In.board.copper.in4,inner5:In.board.copper.in5,inner6:In.board.copper.in6,inner7:In.board.copper.in7,inner8:In.board.copper.in8,bottom:In.board.copper.b,drill:In.board.anchor,keepout:In.board.background,tkeepout:In.board.b_crtyd,tplace:In.board.b_silks,top_courtyard:In.board.f_crtyd,bottom_courtyard:In.board.b_crtyd,top_silkscreen:In.board.f_silks,bottom_silkscreen:In.board.b_silks,top_fabrication:In.board.f_fab,bottom_fabrication:In.board.b_fab,soldermask_top:In.board.soldermask.top,soldermask_bottom:In.board.soldermask.bottom,soldermask_with_copper_top:In.board.soldermaskWithCopper.top,soldermask_with_copper_bottom:In.board.soldermaskWithCopper.bottom,bottom_notes:In.board.user_2,top_notes:In.board.user_2,...In.board},p5e=["board","inner6","inner5","inner4","inner3","inner2","inner1","bottom","soldermask_bottom","bottom_silkscreen","top","soldermask_top","bottom_courtyard","bottom_fabrication","top_courtyard","top_fabrication","edge_cuts","top_silkscreen"],f5e=class{canvasLayerMap;ctxLayerMap;aperture;transform;foregroundLayer="top";lastPoint;constructor(e){this.canvasLayerMap=e,this.ctxLayerMap=Object.fromEntries(Object.entries(e).map(([A,t])=>[A,t.getContext("2d")])),this.transform=yb(),this.transform.d*=-1,this.transform=Oy(this.transform,rB(0,-500)),this.lastPoint={x:0,y:0},this.equip({})}clear(){for(const e of Object.values(this.ctxLayerMap))e.clearRect(0,0,e.canvas.width,e.canvas.height)}equip(e){this.aperture={fontSize:0,shape:"circle",mode:"add",size:0,color:"red",layer:"top",opacity:this.foregroundLayer===e.color?1:.5,...e}}drawMeshPattern(e,A,t,i,n,o=45){const s=this.getLayerCtx(),[r,a]=qi(this.transform,[e,A]),[g,c]=qi(this.transform,[e+t,A+i]),I=Cf(this.transform,n);s.lineWidth=1,s.strokeStyle=this.aperture.color;const l=B=>{const C=Math.sin(B),E=Math.cos(B),Q=Math.sqrt((g-r)**2+(c-a)**2);for(let h=-Q;h<=Q;h+=I)s.beginPath(),s.moveTo(r+h*E-Q*C,a+h*C+Q*E),s.lineTo(r+h*E+Q*C,a+h*C-Q*E),s.stroke()};l(o*Math.PI/180),l((o+90)*Math.PI/180)}rect({x:e,y:A,w:t,h:i,mesh_fill:n,is_filled:o=!0,has_stroke:s,is_stroke_dashed:r,stroke_width:a,roundness:g}){const[c,I]=qi(this.transform,[e-t/2,A-i/2]),[l,B]=qi(this.transform,[e+t/2,A+i/2]);this.applyAperture();const C=this.getLayerCtx(),E=g?Cf(this.transform,g):0,Q=s===void 0?o===!1:s;if(n)C.save(),C.beginPath(),E>0&&C.roundRect?C.roundRect(c,I,l-c,B-I,E):C.rect(c,I,l-c,B-I),C.clip(),this.drawMeshPattern(e-t/2,A-i/2,t,i,.15),C.restore(),E>0&&C.roundRect?(C.beginPath(),C.roundRect(c,I,l-c,B-I,E),C.stroke()):C.strokeRect(c,I,l-c,B-I);else if(o!==!1&&(E>0&&C.roundRect?(C.beginPath(),C.roundRect(c,I,l-c,B-I,E),C.fill()):C.fillRect(c,I,l-c,B-I)),Q){const h=C.lineWidth;if(a!==void 0&&(C.lineWidth=Cf(this.transform,a)),r){let u=[];const d=Math.abs(this.transform.a);if(d>0){const m=.1*d,w=m*1.3;m>.5&&(u=[m,w])}C.setLineDash(u)}E>0&&C.roundRect?(C.beginPath(),C.roundRect(c,I,l-c,B-I,E),C.stroke()):C.strokeRect(c,I,l-c,B-I),r&&C.setLineDash([]),a!==void 0&&(C.lineWidth=h)}}rotatedRect(e,A,t,i,n,o,s){const r=this.getLayerCtx();this.applyAperture();const[a,g]=qi(this.transform,[e-t/2,A-i/2]),[c,I]=qi(this.transform,[e+t/2,A+i/2]),l=o?Cf(this.transform,o):0;r.save();const[B,C]=qi(this.transform,[e,A]);r.translate(B,C);const E=360-n;n&&r.rotate(E*Math.PI/180),r.translate(-B,-C),s?(r.beginPath(),l>0&&r.roundRect?r.roundRect(a,g,c-a,I-g,l):r.rect(a,g,c-a,I-g),r.clip(),this.drawMeshPattern(e-t/2,A-i/2,t,i,.15),l>0&&r.roundRect?(r.beginPath(),r.roundRect(a,g,c-a,I-g,l),r.stroke()):r.strokeRect(a,g,c-a,I-g)):l>0&&r.roundRect?(r.beginPath(),r.roundRect(a,g,c-a,I-g,l),r.fill()):r.fillRect(a,g,c-a,I-g),r.restore()}rotatedPill(e,A,t,i,n){const o=this.getLayerCtx();this.applyAperture(),o.save();const[s,r]=qi(this.transform,[e,A]);o.translate(s,r);const a=360-n;n&&o.rotate(a*Math.PI/180),o.translate(-s,-r),this.pill(e,A,t,i),o.restore()}circle(e,A,t,i,n=!0){const o=Cf(this.transform,t),[s,r]=qi(this.transform,[e,A]);this.applyAperture();const a=this.getLayerCtx();i?(a.save(),a.beginPath(),a.arc(s,r,o,0,2*Math.PI),a.clip(),this.drawMeshPattern(e-t,A-t,t*2,t*2,.15),a.restore(),a.beginPath(),a.arc(s,r,o,0,2*Math.PI),a.stroke()):(a.beginPath(),a.arc(s,r,o,0,2*Math.PI),a.fill())}oval(e,A,t,i){const n=Cf(this.transform,t),o=Cf(this.transform,i),[s,r]=qi(this.transform,[e,A]);this.applyAperture();const a=this.getLayerCtx();a.beginPath(),a.ellipse(s,r,n,o,0,0,2*Math.PI),a.fill(),a.closePath()}pill(e,A,t,i){const[n,o]=qi(this.transform,[e-t/2,A+i/2]),s=Cf(this.transform,t),r=Cf(this.transform,i),a=Math.min(s,r)/2;this.applyAperture();const g=this.getLayerCtx();g.beginPath(),g.arc(n+a,o+a,a,Math.PI,Math.PI*1.5),g.arc(n+s-a,o+a,a,Math.PI*1.5,0),g.arc(n+s-a,o+r-a,a,0,Math.PI*.5),g.arc(n+a,o+r-a,a,Math.PI*.5,Math.PI),g.fill(),g.closePath()}polygon(e){if(e.length<3)return;this.applyAperture();const A=this.getLayerCtx(),t=e.map(n=>qi(this.transform,[n.x,n.y]));A.beginPath(),A.moveTo(t[0][0],t[0][1]);for(let n=1;n<t.length;n++)A.lineTo(t[n][0],t[n][1]);A.closePath(),A.fill("evenodd");const i=Cf(this.transform,this.aperture.size);i>0&&(A.lineWidth=i,A.stroke())}debugText(e,A,t){const[i,n]=qi(this.transform,[A,t]);this.applyAperture();const o=this.getLayerCtx();o.font="10px sans-serif",o.fillText(e,i,n)}getLayerCtx(){const e=this.ctxLayerMap[this.aperture.layer];if(!e)throw new Error(`No context for layer "${this.aperture.layer}"`);return e}orderAndFadeLayers(){const{canvasLayerMap:e,foregroundLayer:A}=this,t=A==="top"?"soldermask_top":A==="bottom"?"soldermask_bottom":void 0,i=A==="top"?"top_silkscreen":A==="bottom"?"bottom_silkscreen":void 0,n=A==="top"?"top_notes":A==="bottom"?"bottom_notes":void 0,o=A==="top"?"top_fabrication":A==="bottom"?"bottom_fabrication":void 0,s=new Set([A,"drill","edge_cuts","other","board",...t?[t]:[],...i?[i]:[],...n?[n]:[],...o?[o]:[]]),r=[A,"edge_cuts",...t?[t]:[],...i?[i]:[],...n?[n]:[],...o?[o]:[]],a=A==="drill"?[]:["drill"],g=A==="drill"?["drill"]:[],c=[...p5e.filter(I=>!r.includes(I)),...a,A,...t?[t]:[],...g,"edge_cuts",...i?[i]:[],...n?[n]:[],...o?[o]:[]];c.forEach((I,l)=>{const B=e[I];B&&(B.style.zIndex=`${Qc.topLayer-(c.length-l)}`,B.style.opacity=s.has(I)?"1":"0.5")})}applyAperture(){const{transform:e,aperture:A}=this;let{size:t,mode:i,color:n,fontSize:o,layer:s}=A;s in this.ctxLayerMap||(this.aperture.layer="other");const r=this.getLayerCtx();if(!r)throw new Error(`No context for layer "${this.foregroundLayer}"`);if(n||(n="undefined"),r.lineWidth=Cf(e,t),r.lineCap="round",i==="add"){r.globalCompositeOperation="source-over";let a=i9[n.toLowerCase()];if(!a)try{a=Ga(n).rgb().toString()}catch{console.warn(`Invalid color format: '${n}'`),a="white"}r.fillStyle=a,r.strokeStyle=a}else r.globalCompositeOperation="destination-out",r.fillStyle="rgba(0,0,0,1)",r.strokeStyle="rgba(0,0,0,1)";r.font=`${Cf(mb(e),o)}px sans-serif`}moveTo(e,A){this.lastPoint={x:e,y:A}}lineTo(e,A){const[t,i]=qi(this.transform,[e,A]),{size:n,shape:o,mode:s}=this.aperture,r=Cf(this.transform,n),{lastPoint:a}=this,g=qi(this.transform,a);this.applyAperture();const c=this.getLayerCtx();o==="square"&&c.fillRect(g.x-r/2,g.y-r/2,r,r),c.beginPath(),c.moveTo(g.x,g.y),c.lineTo(t,i),c.stroke(),c.closePath(),o==="square"&&c.fillRect(t-r/2,i-r/2,r,r),this.lastPoint={x:e,y:A}}polygonWithArcs(e){const A=this.getLayerCtx(),t=i=>{if(i.vertices.length===0)return;const n=i.vertices[0],o=qi(this.transform,[n.x,n.y]);A.moveTo(o[0],o[1]);for(let s=0;s<i.vertices.length;s++){const r=i.vertices[s],a=i.vertices[(s+1)%i.vertices.length];if(r.bulge&&r.bulge!==0){const g=r.bulge,c=a.x-r.x,I=a.y-r.y,l=Math.sqrt(c*c+I*I);if(l<1e-9){const R=qi(this.transform,[a.x,a.y]);A.lineTo(R[0],R[1]);continue}const B=4*Math.atan(g),C=Math.abs(l/(2*Math.sin(B/2))),E=(r.x+a.x)/2,Q=(r.y+a.y)/2,h=c/l,d=-(I/l),f=h,m=Math.sqrt(Math.max(0,C*C-(l/2)**2)),w=E+m*d*Math.sign(g),D=Q+m*f*Math.sign(g),b=Math.atan2(r.y-D,r.x-w);let k=Math.atan2(a.y-D,a.x-w);g>0&&k<b?k+=2*Math.PI:g<0&&k>b&&(k-=2*Math.PI);const x=qi(this.transform,[w,D]),N=Cf(this.transform,C);A.arc(x[0],x[1],N,-b,-k,g>0)}else{const g=qi(this.transform,[a.x,a.y]);A.lineTo(g[0],g[1])}}A.closePath()};if(A.beginPath(),t(e.outer_ring),e.inner_rings)for(const i of e.inner_rings)t(i);A.fill("evenodd")}};function y5e(e){return e.type==="pcb_copper_pour"}function n9({canvas:e,elements:A,layers:t,realToCanvasMat:i}){const n=A.filter(y5e);if(n.length===0)return;const o=new LC(e);o.realToCanvasMat=i,o.drawElements(n,{layers:t})}var m5e={...Ud,silkscreen:{top:In.board.f_fab,bottom:In.board.b_fab}};function w5e(e){return e.type.includes("pcb_fabrication_note")}function Hgt({canvas:e,elements:A,layers:t,realToCanvasMat:i}){const n=new LC(e);n.configure({colorOverrides:m5e}),n.realToCanvasMat=i;const o=A.filter(w5e);n.drawElements(o,{layers:t})}function D5e(e){return e.type==="pcb_hole"}function S5e({canvas:e,elements:A,layers:t,realToCanvasMat:i,drawSoldermask:n}){const o=new LC(e);o.realToCanvasMat=i;const s=A.filter(D5e);o.drawElements(s,{layers:t,drawSoldermask:n})}function b5e(e){return e.type==="pcb_board"}function x5e({canvas:e,elements:A,layers:t,realToCanvasMat:i,drawSoldermask:n}){const o=new LC(e);o.realToCanvasMat=i;const s=A.filter(b5e);for(const r of s)o.drawElements([r],{layers:t,drawSoldermask:!1,drawBoardMaterial:n??!1,minBoardOutlineStrokePx:2})}function _5e(e){return e.type==="pcb_cutout"}function k5e({canvas:e,elements:A,layers:t,realToCanvasMat:i}){const n=new LC(e);n.realToCanvasMat=i;const o=A.filter(_5e);n.drawElements(o,{layers:t})}function F5e(e){return e.type==="pcb_keepout"}function G5e({canvas:e,elements:A,layers:t,realToCanvasMat:i}){const n=A.filter(F5e);if(n.length===0)return;const o=new LC(e);o.realToCanvasMat=i,o.drawElements(n,{layers:[]})}function M5e(e){return e.type.startsWith("pcb_note_")}function Ygt({canvas:e,elements:A,layers:t,realToCanvasMat:i}){const n=new LC(e);n.realToCanvasMat=i;const o=A.filter(M5e);n.drawElements(o,{layers:t})}function R5e(e){return e.type==="pcb_panel"}function N5e({canvas:e,elements:A,layers:t,realToCanvasMat:i,drawSoldermask:n}){const o=new LC(e);o.realToCanvasMat=i;const s=A.filter(R5e);for(const r of s)o.drawElements([r],{layers:t})}var v5e={...Ud,copper:{...Ud.copper,top:Ga(In.board.pad_front).lighten(.5).toString(),bottom:Ga(In.board.pad_back).lighten(.5).toString(),inner1:Ga(In.board.copper.in1).lighten(.5).toString(),inner2:Ga(In.board.copper.in2).lighten(.5).toString(),inner3:Ga(In.board.copper.in3).lighten(.5).toString(),inner4:Ga(In.board.copper.in4).lighten(.5).toString(),inner5:Ga(In.board.copper.in5).lighten(.5).toString(),inner6:Ga(In.board.copper.in6).lighten(.5).toString()}};function L5e(e){return e.type==="pcb_smtpad"}function U5e({canvas:e,elements:A,layers:t,realToCanvasMat:i,primitives:n,drawSoldermask:o}){const s=A.filter(L5e).filter(c=>{const I=c.layer;return t.some(l=>l==="top_copper"&&I==="top"||l==="bottom_copper"&&I==="bottom"||l==="inner1_copper"&&I==="inner1"||l==="inner2_copper"&&I==="inner2"||l==="inner3_copper"&&I==="inner3"||l==="inner4_copper"&&I==="inner4"||l==="inner5_copper"&&I==="inner5"||l==="inner6_copper"&&I==="inner6")});if(s.length===0)return;const r=new Set;if(n)for(const c of n)(c.is_mouse_over||c.is_in_highlighted_net)&&c._element?.type==="pcb_smtpad"&&r.add(c._element.pcb_smtpad_id);const a=s.filter(c=>r.has(c.pcb_smtpad_id)),g=s.filter(c=>!r.has(c.pcb_smtpad_id));if(g.length>0){const c=new LC(e);c.realToCanvasMat=i,c.drawElements(g,{layers:t,drawSoldermask:o})}if(a.length>0){const c=new LC(e);c.configure({colorOverrides:v5e}),c.realToCanvasMat=i,c.drawElements(a,{layers:t,drawSoldermask:o})}}var H5e={...Ud,copper:{...Ud.copper,top:Ga(In.board.pad_front).lighten(.5).toString(),bottom:Ga(In.board.pad_back).lighten(.5).toString(),inner1:Ga(In.board.copper.in1).lighten(.5).toString(),inner2:Ga(In.board.copper.in2).lighten(.5).toString(),inner3:Ga(In.board.copper.in3).lighten(.5).toString(),inner4:Ga(In.board.copper.in4).lighten(.5).toString(),inner5:Ga(In.board.copper.in5).lighten(.5).toString(),inner6:Ga(In.board.copper.in6).lighten(.5).toString()}};function Y5e(e){return e.type==="pcb_trace"}var J5e=e=>e.map(A=>A.endsWith("_copper")?A.replace("_copper",""):A);function T5e({canvas:e,elements:A,layers:t,realToCanvasMat:i,primitives:n}){const o=new Set(J5e(t)),s=A.filter(Y5e).filter(c=>c.route.some(I=>I.route_type==="wire"&&"layer"in I&&o.has(I.layer)));if(s.length===0)return;const r=new Set;if(n)for(const c of n)(c.is_mouse_over||c.is_in_highlighted_net)&&c._element?.type==="pcb_trace"&&r.add(c._element.pcb_trace_id);const a=s.filter(c=>r.has(c.pcb_trace_id)),g=s.filter(c=>!r.has(c.pcb_trace_id));if(g.length>0){const c=new LC(e);c.realToCanvasMat=i,c.drawElements(g,{layers:t})}if(a.length>0){const c=new LC(e);c.configure({colorOverrides:H5e}),c.realToCanvasMat=i,c.drawElements(a,{layers:t})}}var K5e={...Ud,copper:{...Ud.copper,top:Ga(In.board.pad_front).lighten(.5).toString(),bottom:Ga(In.board.pad_back).lighten(.5).toString()}};function P5e(e){return e.type==="pcb_plated_hole"}function Jgt({canvas:e,elements:A,layers:t,realToCanvasMat:i,primitives:n,drawSoldermask:o}){const s=A.filter(P5e);if(s.length===0)return;const r=new Set;if(n)for(const c of n)(c.is_mouse_over||c.is_in_highlighted_net)&&c._element?.type==="pcb_plated_hole"&&r.add(c._element.pcb_plated_hole_id);const a=s.filter(c=>r.has(c.pcb_plated_hole_id)),g=s.filter(c=>!r.has(c.pcb_plated_hole_id));if(g.length>0){const c=new LC(e);c.realToCanvasMat=i,c.drawElements(g,{layers:t,drawSoldermask:o})}if(a.length>0){const c=new LC(e);c.configure({colorOverrides:K5e}),c.realToCanvasMat=i,c.drawElements(a,{layers:t,drawSoldermask:o})}}function Tgt(e){const{lines:A,anchorPoint:t,ccwRotation:i}=e;if(!i)return A;const n=i*Math.PI/180,o=pqe(n),s=Oy(rB(t.x,t.y),o,rB(-t.x,-t.y));return qi(s,t),A.map(r=>({...r,x1:qi(s,{x:r.x1,y:r.y1}).x,y1:qi(s,{x:r.x1,y:r.y1}).y,x2:qi(s,{x:r.x2,y:r.y2}).x,y2:qi(s,{x:r.x2,y:r.y2}).y}))}var q5e=.6,Kgt=.2,Pgt=e=>{const A=e.size*.7,t=A*q5e,i=A*Kgt,n=A*Kgt,o=e.text.split(/\r?\n/),s=e.text.length>0&&A>0,r=s?o.length:0,a=s?o.map(I=>I.length===0?0:I.length*t+(I.length-1)*i):[],g=a.length>0?Math.max(...a):0,c=r>0?r*A+(r-1)*n:0;return{text_lines:o,line_count:r,line_widths:a,target_height:A,target_width_char:t,space_between_chars:i,space_between_lines:n,width:g,height:c}},qgt=e=>{const A=Pgt(e);return{width:A.width,height:A.height,lineHeight:A.target_height,lineSpacing:A.space_between_lines,lineCount:A.line_count}},Ogt=e=>{const{text_lines:A,line_count:t,line_widths:i,target_height:n,target_width_char:o,space_between_chars:s,space_between_lines:r,width:a}=Pgt(e);if(n<=0||t===0)return[];const g=n/12,c=[];for(let I=0;I<t;I++){const l=-I*(n+r),B=i[I],C=(a-B)/2;let E=e.x+C;for(let Q=0;Q<A[I].length;Q++){const h=A[I][Q],u=iD[h]??iD[h.toUpperCase()];if(!u){E+=o+s;continue}for(const{x1:d,y1:f,x2:m,y2:w}of u)c.push({_pcb_drawing_object_id:Wy("line"),pcb_drawing_type:"line",x1:E+o*d,y1:e.y+l+n*f,x2:E+o*m,y2:e.y+l+n*w,width:g,layer:e.layer,unit:e.unit,color:e.color});E+=o+s}}return c};function LD(e){const t=e.color??i9[e.layer];let i=Ga(t);return e._element?.type==="pcb_copper_pour"&&(i=i.alpha(.7)),e.is_mouse_over||e.is_in_highlighted_net?i.lighten(.5).rgb().toString():i.rgb().toString()}var Wgt=(e,A)=>{e.equip({size:A.zoomIndependent?A.width/e.transform.a:A.width,shape:A.squareCap?"square":"circle",color:LD(A),layer:A.layer}),e.moveTo(A.x1,A.y1),e.lineTo(A.x2,A.y2)},O5e=(e,A,t)=>{switch(t){case"top_left":return{x:0,y:-A};case"top_center":return{x:-e/2,y:-A};case"top_right":return{x:-e,y:-A};case"center_left":return{x:0,y:-A/2};case"center":return{x:-e/2,y:-A/2};case"center_right":return{x:-e,y:-A/2};case"bottom_left":return{x:0,y:0};case"bottom_center":return{x:-e/2,y:0};case"bottom_right":return{x:-e,y:0};default:return{x:0,y:0}}},Zgt=e=>e.layer==="bottom_silkscreen"||e.layer==="bottom"?e.is_mirrored!==!1:e.is_mirrored===!0,W5e=(e,A)=>{e.equip({fontSize:A.size,color:LD(A),layer:A.layer});const{width:t,height:i}=qgt(A),n=O5e(t,i,A.align);A.x??=0,A.y??=0;const o={x:A.x,y:A.y};let s=Ogt({...A,x:A.x+n.x,y:A.y+n.y});if(Zgt(A)&&(s=s.map(r=>({...r,x1:2*A.x-r.x1,x2:2*A.x-r.x2}))),A.ccw_rotation){const r={lines:s,anchorPoint:o,ccwRotation:A.ccw_rotation};s=Tgt(r)}for(const r of s)Wgt(e,r)},Z5e=(e,A)=>{const{width:t,height:i,lineHeight:n}=qgt(A);A.x??=0,A.y??=0;const o=A.knockout_padding??{left:A.size*.5,right:A.size*.5,top:A.size*.3,bottom:A.size*.3},s=t+o.left+o.right,r=i+o.top+o.bottom,a=t/2,g=n-i/2,c=A.x-a,I=A.y-g,l={x:A.x,y:A.y},B={_pcb_drawing_object_id:`knockout_rect_${A._pcb_drawing_object_id}`,x:A.x,y:A.y,w:s,h:r,layer:A.layer,ccw_rotation:A.ccw_rotation};A.ccw_rotation?jgt(e,B):Vgt(e,B);let C=Ogt({...A,x:c,y:I});if(Zgt(A)&&(C=C.map(E=>({...E,x1:2*A.x-E.x1,x2:2*A.x-E.x2}))),A.ccw_rotation){const E={lines:C,anchorPoint:l,ccwRotation:A.ccw_rotation};C=Tgt(E)}for(const E of C)e.equip({size:E.width,shape:"circle",color:"black",layer:A.layer,mode:"subtract"}),e.moveTo(E.x1,E.y1),e.lineTo(E.x2,E.y2);e.equip({mode:"add"})},Vgt=(e,A)=>{e.equip({color:LD(A),layer:A.layer,size:A.stroke_width}),e.rect({x:A.x,y:A.y,w:A.w,h:A.h,mesh_fill:A.mesh_fill,is_filled:A.is_filled,has_stroke:A.has_stroke,is_stroke_dashed:A.is_stroke_dashed,stroke_width:A.stroke_width,roundness:A.roundness})},jgt=(e,A)=>{e.equip({color:LD(A),layer:A.layer}),e.rotatedRect(A.x,A.y,A.w,A.h,A.ccw_rotation,A.roundness,A.mesh_fill)},V5e=(e,A)=>{e.equip({color:LD(A),layer:A.layer}),e.rotatedPill(A.x,A.y,A.w,A.h,A.ccw_rotation)},j5e=(e,A)=>{e.equip({color:LD(A),layer:A.layer}),e.circle(A.x,A.y,A.r,A.mesh_fill)},z5e=(e,A)=>{e.equip({color:LD(A),layer:A.layer}),e.oval(A.x,A.y,A.rX,A.rY)},X5e=(e,A)=>{e.equip({color:LD(A),layer:A.layer}),e.pill(A.x,A.y,A.w,A.h)},$5e=(e,A)=>{e.equip({color:LD(A),layer:A.layer}),e.polygon(A.points)},A8e=(e,A)=>{e.equip({color:LD(A),layer:A.layer}),e.polygonWithArcs(A.brep_shape)},t8e=(e,A)=>{switch(A.pcb_drawing_type){case"line":return Wgt(e,A);case"text":return A.is_knockout?Z5e(e,A):W5e(e,A);case"rect":return A.ccw_rotation?jgt(e,A):Vgt(e,A);case"circle":return j5e(e,A);case"oval":return z5e(e,A);case"pill":return A.ccw_rotation?V5e(e,A):X5e(e,A);case"polygon":return $5e(e,A);case"polygon_with_arcs":return A8e(e,A)}},e8e=(e,A)=>{for(const t of A)t8e(e,t)},i8e={...Ud,copper:{...Ud.copper,top:Ga(In.board.pad_front).lighten(.5).toString(),bottom:Ga(In.board.pad_back).lighten(.5).toString(),inner1:Ga(In.board.copper.in1).lighten(.5).toString(),inner2:Ga(In.board.copper.in2).lighten(.5).toString(),inner3:Ga(In.board.copper.in3).lighten(.5).toString(),inner4:Ga(In.board.copper.in4).lighten(.5).toString(),inner5:Ga(In.board.copper.in5).lighten(.5).toString(),inner6:Ga(In.board.copper.in6).lighten(.5).toString()},soldermask:{...Ud.soldermask,top:Ga(In.board.soldermask.top).lighten(.35).toString(),bottom:Ga(In.board.soldermask.bottom).lighten(.35).toString()}};function zgt({canvas:e,elements:A,layers:t,realToCanvasMat:i,drawSoldermaskTop:n,drawSoldermaskBottom:o,primitives:s}){const r=new LC(e);r.realToCanvasMat=i;const a=A.filter(l=>l.type==="pcb_board");if(a.length<=1)r.drawElements(A,{layers:t,drawSoldermask:!0,drawSoldermaskTop:n,drawSoldermaskBottom:o,drawBoardMaterial:!1});else{const l=A.filter(B=>B.type!=="pcb_board");for(const B of a)r.drawElements([B,...l],{layers:t,drawSoldermask:!0,drawSoldermaskTop:n,drawSoldermaskBottom:o,drawBoardMaterial:!1})}if(!s)return;const g=new Set;for(const l of s){if(!(l.is_mouse_over||l.is_in_highlighted_net))continue;const B=l._element;B?.type==="pcb_smtpad"?g.add(B.pcb_smtpad_id):B?.type==="pcb_plated_hole"?g.add(B.pcb_plated_hole_id):B?.type==="pcb_via"&&g.add(B.pcb_via_id)}if(g.size===0)return;const c=A.filter(l=>l.type==="pcb_smtpad"?g.has(l.pcb_smtpad_id):l.type==="pcb_plated_hole"?g.has(l.pcb_plated_hole_id):l.type==="pcb_via"?g.has(l.pcb_via_id):!1);if(c.length===0)return;const I=new LC(e);I.configure({colorOverrides:i8e}),I.realToCanvasMat=i,I.drawElements(c,{layers:t,drawSoldermask:!0,drawSoldermaskTop:n,drawSoldermaskBottom:o,drawBoardMaterial:!1})}var n8e={...Ud,silkscreen:{top:In.board.f_silks,bottom:In.board.b_silks}};function o8e(e){return e.type.includes("pcb_silkscreen")}function Xgt({canvas:e,elements:A,layers:t,realToCanvasMat:i}){const n=new LC(e);n.configure({colorOverrides:n8e}),n.realToCanvasMat=i;const o=A.filter(o8e);n.drawElements(o,{layers:t})}var s8e={...Ud,copper:{...Ud.copper,top:Ga(In.board.pad_front).lighten(.5).toString(),bottom:Ga(In.board.pad_back).lighten(.5).toString()}};function r8e(e){return e.type==="pcb_via"}function $gt({canvas:e,elements:A,layers:t,realToCanvasMat:i,primitives:n,drawSoldermask:o}){const s=A.filter(r8e).filter(c=>t.some(I=>I.includes("copper")));if(s.length===0)return;const r=new Set;if(n)for(const c of n)(c.is_mouse_over||c.is_in_highlighted_net)&&c._element?.type==="pcb_via"&&r.add(c._element.pcb_via_id);const a=s.filter(c=>r.has(c.pcb_via_id)),g=s.filter(c=>!r.has(c.pcb_via_id));if(g.length>0){const c=new LC(e);c.realToCanvasMat=i,c.drawElements(g,{layers:t,drawSoldermask:o})}if(a.length>0){const c=new LC(e);c.configure({colorOverrides:s8e}),c.realToCanvasMat=i,c.drawElements(a,{layers:t,drawSoldermask:o})}}var a8e={...Ud,courtyard:{top:In.board.f_crtyd,bottom:In.board.b_crtyd}};function g8e(e){return e.type==="pcb_courtyard_circle"||e.type==="pcb_courtyard_rect"||e.type==="pcb_courtyard_outline"}function Act({canvas:e,elements:A,layers:t,realToCanvasMat:i}){const n=new LC(e);n.configure({colorOverrides:a8e}),n.realToCanvasMat=i;const o=A.filter(g8e);n.drawElements(o,{layers:t})}var c8e=["board","bottom","soldermask_bottom","bottom_silkscreen","top","soldermask_top","soldermask_with_copper_bottom","soldermask_with_copper_top","top_fabrication","bottom_fabrication","inner1","inner2","inner3","inner4","inner5","inner6","drill","edge_cuts","bottom_notes","top_notes","top_silkscreen","top_courtyard","bottom_courtyard","other"],I8e=({primitives:e,elements:A,transform:t,grid:i,width:n=500,height:o=500})=>{const s=AA.useRef({}),r=zB(g=>g.selected_layer),a=zB(g=>g.is_showing_solder_mask);return AA.useEffect(()=>{if(!s.current||Object.keys(s.current).length===0)return;const g=Object.fromEntries(Object.entries(s.current).filter(([l,B])=>!(!B||!a&&l.includes("soldermask"))));if(Object.keys(g).length===0)return;const c=new f5e(g);t&&(c.transform=t),c.clear(),c.foregroundLayer=r;const I=e.filter(l=>a||!l.layer?.includes("soldermask")).filter(l=>l.layer!=="board").filter(l=>l._element?.type!=="pcb_smtpad").filter(l=>l._element?.type!=="pcb_plated_hole").filter(l=>l._element?.type!=="pcb_via").filter(l=>l._element?.type!=="pcb_trace");if(e8e(c,I),t){const l=s.current.top,B=s.current.bottom,C=s.current.inner1,E=s.current.inner2,Q=s.current.inner3,h=s.current.inner4,u=s.current.inner5,d=s.current.inner6,f=[{canvas:l,copperLayer:"top_copper"},{canvas:B,copperLayer:"bottom_copper"},{canvas:C,copperLayer:"inner1_copper"},{canvas:E,copperLayer:"inner2_copper"},{canvas:Q,copperLayer:"inner3_copper"},{canvas:h,copperLayer:"inner4_copper"},{canvas:u,copperLayer:"inner5_copper"},{canvas:d,copperLayer:"inner6_copper"}];for(const{canvas:W,copperLayer:X}of f)W&&T5e({canvas:W,elements:A,layers:[X],realToCanvasMat:t,primitives:e});l&&Jgt({canvas:l,elements:A,layers:["top_copper"],realToCanvasMat:t,primitives:e,drawSoldermask:a}),B&&Jgt({canvas:B,elements:A,layers:["bottom_copper"],realToCanvasMat:t,primitives:e,drawSoldermask:a}),l&&n9({canvas:l,elements:A,layers:["top_copper"],realToCanvasMat:t}),B&&n9({canvas:B,elements:A,layers:["bottom_copper"],realToCanvasMat:t});for(const{canvas:W,copperLayer:X}of f)W&&U5e({canvas:W,elements:A,layers:[X],realToCanvasMat:t,primitives:e,drawSoldermask:a});if(l&&$gt({canvas:l,elements:A,layers:["top_copper"],realToCanvasMat:t,primitives:e,drawSoldermask:a}),B&&$gt({canvas:B,elements:A,layers:["bottom_copper"],realToCanvasMat:t,primitives:e,drawSoldermask:a}),a){const W=r==="bottom"?"bottom":"top",X=W==="top",iA=W==="bottom",aA=s.current.soldermask_top;aA&&W==="top"&&zgt({canvas:aA,elements:A,layers:["top_soldermask"],realToCanvasMat:t,drawSoldermaskTop:X,drawSoldermaskBottom:iA,primitives:e});const tA=s.current.soldermask_bottom;tA&&W==="bottom"&&zgt({canvas:tA,elements:A,layers:["bottom_soldermask"],realToCanvasMat:t,drawSoldermaskTop:X,drawSoldermaskBottom:iA,primitives:e})}l&&n9({canvas:l,elements:A,layers:["top_copper"],realToCanvasMat:t}),B&&n9({canvas:B,elements:A,layers:["bottom_copper"],realToCanvasMat:t});const m=s.current.drill;m&&S5e({canvas:m,elements:A,layers:["drill"],realToCanvasMat:t});const w=s.current.top_silkscreen;w&&Xgt({canvas:w,elements:A,layers:["top_silkscreen"],realToCanvasMat:t});const D=s.current.bottom_silkscreen;D&&Xgt({canvas:D,elements:A,layers:["bottom_silkscreen"],realToCanvasMat:t});const b=s.current.top_fabrication;b&&Hgt({canvas:b,elements:A,layers:["top_fabrication_note"],realToCanvasMat:t});const k=s.current.bottom_fabrication;k&&Hgt({canvas:k,elements:A,layers:["bottom_fabrication_note"],realToCanvasMat:t});const x=s.current.bottom_notes;x&&Ygt({canvas:x,elements:A,layers:["bottom_user_note"],realToCanvasMat:t});const N=s.current.top_notes;N&&Ygt({canvas:N,elements:A,layers:["top_user_note"],realToCanvasMat:t});const R=s.current.top_courtyard;R&&Act({canvas:R,elements:A,layers:["top_courtyard"],realToCanvasMat:t});const U=s.current.bottom_courtyard;U&&Act({canvas:U,elements:A,layers:["bottom_courtyard"],realToCanvasMat:t});const T=s.current.board;T&&(N5e({canvas:T,elements:A,layers:[],realToCanvasMat:t,drawSoldermask:a}),x5e({canvas:T,elements:A,layers:[],realToCanvasMat:t,drawSoldermask:a}));const H=s.current.edge_cuts;H&&k5e({canvas:H,elements:A,layers:["edge_cuts"],realToCanvasMat:t});const O=[{canvas:l,layer:"top"},{canvas:B,layer:"bottom"}];for(const{canvas:W,layer:X}of O)W&&G5e({canvas:W,elements:A,layers:[X],realToCanvasMat:t})}c.orderAndFadeLayers()},[e,A,t,r,a]),Z.jsxs("div",{style:{backgroundColor:"black",width:n,height:o,position:"relative"},children:[Z.jsx(JV.SuperGrid,{textColor:"rgba(0,255,0,0.8)",majorColor:"rgba(0,255,0,0.4)",minorColor:"rgba(0,255,0,0.2)",screenSpaceCellSize:200,width:n,height:o,transform:t,stringifyCoord:(g,c,I)=>`${JV.toMMSI(g,I)}, ${JV.toMMSI(c,I)}`}),c8e.filter(g=>a?!0:!g.includes("soldermask")).map(g=>g.replace(/-/g,"")).map((g,c)=>Z.jsx("canvas",{className:`pcb-layer-${g}`,ref:I=>{s.current??={},I?s.current[g]=I:delete s.current[g]},style:{position:"absolute",zIndex:c,left:0,top:0,pointerEvents:"none"},width:n,height:o},g))]})},l8e=.6,B8e=1;GpA(fOe(),1),GpA(LOe(),1);var o9=["rgba(239, 68, 68, 0.8)","rgba(249, 115, 22, 0.8)","rgba(245, 158, 11, 0.8)","rgba(234, 179, 8, 0.8)","rgba(132, 204, 22, 0.8)","rgba(34, 197, 94, 0.8)","rgba(16, 185, 129, 0.8)","rgba(20, 184, 166, 0.8)","rgba(6, 182, 212, 0.8)","rgba(14, 165, 233, 0.8)","rgba(59, 130, 246, 0.8)","rgba(99, 102, 241, 0.8)","rgba(139, 92, 246, 0.8)","rgba(168, 85, 247, 0.8)","rgba(217, 70, 239, 0.8)","rgba(236, 72, 153, 0.8)","rgba(249, 168, 212, 0.8)","rgba(161, 161, 170, 0.8)"];function tct(e,A,t,i={}){const n=i.padding??40,o=i.yFlip??!1;let s;if("center"in e){const c=e.width/2,I=e.height/2;s={minX:e.center.x-c,maxX:e.center.x+c,minY:e.center.y-I,maxY:e.center.y+I}}else s=e;const r=s.maxX-s.minX||1,a=s.maxY-s.minY||1,g=Math.min((A-2*n)/r,(t-2*n)/a);return Oy(rB(A/2,t/2),JY(g,o?-g:g),rB(-(s.minX+r/2),-(s.minY+a/2)))}function C8e(e){const A=[...e.points||[],...(e.lines||[]).flatMap(t=>t.points),...(e.rects||[]).flatMap(t=>{const i=t.width/2,n=t.height/2;return[{x:t.center.x-i,y:t.center.y-n},{x:t.center.x+i,y:t.center.y-n},{x:t.center.x-i,y:t.center.y+n},{x:t.center.x+i,y:t.center.y+n}]}),...(e.circles||[]).flatMap(t=>[{x:t.center.x-t.radius,y:t.center.y},{x:t.center.x+t.radius,y:t.center.y},{x:t.center.x,y:t.center.y-t.radius},{x:t.center.x,y:t.center.y+t.radius}]),...(e.texts||[]).flatMap(t=>{const i=t.fontSize??12,n=t.text.length*i*l8e,o=i*B8e,s=t.anchorSide??"center",r={top_left:{dx:0,dy:0},top_center:{dx:-n/2,dy:0},top_right:{dx:-n,dy:0},center_left:{dx:0,dy:-o/2},center:{dx:-n/2,dy:-o/2},center_right:{dx:-n,dy:-o/2},bottom_left:{dx:0,dy:-o},bottom_center:{dx:-n/2,dy:-o},bottom_right:{dx:-n,dy:-o}},{dx:a,dy:g}=r[s],c=t.x+a,I=t.y+g;return[{x:c,y:I},{x:c+n,y:I+o}]})];return A.length===0?{minX:-1,maxX:1,minY:-1,maxY:1}:A.reduce((t,i)=>({minX:Math.min(t.minX,i.x),maxX:Math.max(t.maxX,i.x),minY:Math.min(t.minY,i.y),maxY:Math.max(t.maxY,i.y)}),{minX:1/0,maxX:-1/0,minY:1/0,maxY:-1/0})}function Q8e(e,A,t={}){const i=A instanceof HTMLCanvasElement?A.getContext("2d"):A;if(!i)throw new Error("Could not get 2D context from canvas");const n=A instanceof HTMLCanvasElement?A.width:A.canvas.width,o=A instanceof HTMLCanvasElement?A.height:A.canvas.height;let s;if(t.transform)s=t.transform;else if(t.viewbox)s=tct(t.viewbox,n,o,{padding:t.padding,yFlip:t.yFlip});else{const r=C8e(e),a=e.coordinateSystem==="cartesian";s=tct(r,n,o,{padding:t.padding??40,yFlip:a})}i.clearRect(0,0,n,o),i.save(),e.rects&&e.rects.length>0&&e.rects.forEach(r=>{const a=r.width/2,g=r.height/2,c=qi(s,{x:r.center.x-a,y:r.center.y-g}),I=qi(s,{x:r.center.x+a,y:r.center.y+g}),l=Math.abs(I.x-c.x),B=Math.abs(I.y-c.y);i.beginPath(),i.rect(Math.min(c.x,I.x),Math.min(c.y,I.y),l,B),r.fill&&(i.fillStyle=r.fill,i.fill()),r.stroke&&(i.strokeStyle=r.stroke,i.stroke())}),e.circles&&e.circles.length>0&&e.circles.forEach(r=>{const a=qi(s,r.center),g=r.radius*Math.abs(s.a);i.beginPath(),i.arc(a.x,a.y,g,0,2*Math.PI),r.fill&&(i.fillStyle=r.fill,i.fill()),r.stroke&&(i.strokeStyle=r.stroke??"transparent",i.stroke())}),e.lines&&e.lines.length>0&&e.lines.forEach((r,a)=>{if(r.points.length===0)return;i.beginPath();const g=qi(s,r.points[0]);i.moveTo(g.x,g.y);for(let c=1;c<r.points.length;c++){const I=qi(s,r.points[c]);i.lineTo(I.x,I.y)}if(i.strokeStyle=r.strokeColor||o9[a%o9.length],r.strokeWidth?i.lineWidth=r.strokeWidth*s.a:i.lineWidth=2,i.lineCap="round",r.strokeDash)if(typeof r.strokeDash=="string"){let c;if(r.strokeDash.includes(","))c=r.strokeDash.split(",").map(I=>parseFloat(I.trim())).filter(I=>!Number.isNaN(I));else{const I=parseFloat(r.strokeDash.trim());c=Number.isNaN(I)?[]:[I]}i.setLineDash(c)}else i.setLineDash(r.strokeDash.map(c=>c*Math.abs(s.a)));else i.setLineDash([]);i.stroke()}),e.points&&e.points.length>0&&e.points.forEach((r,a)=>{const g=qi(s,r);i.beginPath(),i.arc(g.x,g.y,3,0,2*Math.PI),i.fillStyle=r.color||o9[a%o9.length],i.fill(),r.label&&!t.disableLabels&&(i.fillStyle=r.color||"black",i.font="12px sans-serif",i.fillText(r.label,g.x+5,g.y-5))}),e.texts&&e.texts.length>0&&e.texts.forEach(r=>{const a=qi(s,{x:r.x,y:r.y});i.fillStyle=r.color||"black",i.font=`${(r.fontSize??12)*Math.abs(s.a)}px sans-serif`;const g=r.anchorSide??"center",c={top_left:"left",center_left:"left",bottom_left:"left",top_center:"center",center:"center",bottom_center:"center",top_right:"right",center_right:"right",bottom_right:"right"},I={top_left:"top",top_center:"top",top_right:"top",center_left:"middle",center:"middle",center_right:"middle",bottom_left:"bottom",bottom_center:"bottom",bottom_right:"bottom"};i.textAlign=c[g],i.textBaseline=I[g],i.fillText(r.text,a.x,a.y)}),i.restore()}var E8e=({children:e,transform:A,debugGraphics:t})=>{const i=AA.useRef(null),[n,{width:o,height:s}]=zY(),r=zB(a=>a.is_showing_autorouting);return AA.useEffect(()=>{r&&i.current&&t&&o&&s&&(i.current.width=o,i.current.height=s,Q8e(t,i.current,{transform:A,disableLabels:!0}))},[t,A,o,s,r]),r?Z.jsxs("div",{ref:n,style:{position:"relative",width:"100%",height:"100%"},children:[e,Z.jsx("canvas",{ref:i,style:{position:"absolute",top:0,left:0,opacity:.5,zIndex:100,width:"100%",height:"100%",pointerEvents:"none"}})]}):e},h8e=({children:e,transform:A=yb(),elements:t=[]})=>{const[i,{width:n,height:o}]=zY(),s=AA.useRef(null);return AA.useEffect(()=>{const r=s.current;if(!r||!n||!o)return;r.width=n,r.height=o;const a=r.getContext("2d");if(!a)return;a.clearRect(0,0,n,o);const g=t.filter(I=>I.type==="pcb_component"),c=t.filter(I=>I.type==="pcb_manual_edit_conflict_warning");a.strokeStyle=In.board.drc_warning,a.lineWidth=2,c.forEach(I=>{const l=g.find(O=>O.pcb_component_id===I.pcb_component_id);if(!l)return;const{width:B,height:C,center:E}=l,Q=qi(A,E),h=B*Math.abs(A.a),u=C*Math.abs(A.d),d=.1*Math.abs(A.a),f=h+d*2,m=u+d*2,w=Q.x-f/2,D=Q.y-m/2;a.beginPath(),a.rect(w,D,f,m),a.stroke();const b="Manual Edit Conflict",k=4,x=Math.max(8,Math.min(12,10*Math.abs(A.a)));a.font=`${x}px sans-serif`;const R=a.measureText(b).width+k*2,U=x+k*2,T=w+(f-R)/2,H=D+m+5;a.fillStyle="rgba(0, 0, 0, 0.7)",a.beginPath(),a.roundRect(T,H,R,U,3),a.fill(),a.fillStyle=In.board.drc_warning,a.textAlign="center",a.textBaseline="middle",a.fillText(b,T+R/2,H+U/2)})},[t,A,n,o]),Z.jsxs("div",{ref:i,style:{position:"relative",width:"100%",height:"100%"},children:[e,Z.jsx("canvas",{ref:s,style:{position:"absolute",top:0,left:0,pointerEvents:"none",zIndex:Qc.warnings}})]})},s9=(e,A,t)=>t(e,A),ect=(e,A,t,i,n)=>{const o=n*Math.PI/180,s=Math.cos(o),r=Math.sin(o),a=e-t,g=A-i,c=a*s-g*r,I=a*r+g*s;return{x:c+t,y:I+i}},XY=e=>{if(e.length===0)return null;let A=e[0].x,t=e[0].x,i=e[0].y,n=e[0].y;for(const o of e)A=s9(A,o.x,Math.min),t=s9(t,o.x,Math.max),i=s9(i,o.y,Math.min),n=s9(n,o.y,Math.max);return{minX:A,maxX:t,minY:i,maxY:n}},u8e=(e,A)=>({minX:Math.min(e.minX,A.minX),maxX:Math.max(e.maxX,A.maxX),minY:Math.min(e.minY,A.minY),maxY:Math.max(e.maxY,A.maxY)}),d8e=(e,A)=>e?u8e(e,A):A,p8e=e=>{switch(e.pcb_drawing_type){case"line":{const A=(e.width??0)/2,t=[{x:e.x1,y:e.y1},{x:e.x2,y:e.y2}],i=XY(t);return i?{minX:i.minX-A,maxX:i.maxX+A,minY:i.minY-A,maxY:i.maxY+A}:null}case"rect":{const A=e.w/2,t=e.h/2,i=[{x:e.x-A,y:e.y-t},{x:e.x+A,y:e.y-t},{x:e.x+A,y:e.y+t},{x:e.x-A,y:e.y+t}],n=e.ccw_rotation??0,o=n===0?i:i.map(s=>ect(s.x,s.y,e.x,e.y,n));return XY(o)}case"circle":return{minX:e.x-e.r,maxX:e.x+e.r,minY:e.y-e.r,maxY:e.y+e.r};case"oval":return{minX:e.x-e.rX,maxX:e.x+e.rX,minY:e.y-e.rY,maxY:e.y+e.rY};case"pill":{const A=e.w/2,t=e.h/2,i=[{x:e.x-A,y:e.y-t},{x:e.x+A,y:e.y-t},{x:e.x+A,y:e.y+t},{x:e.x-A,y:e.y+t}],n=e.ccw_rotation??0,o=n===0?i:i.map(s=>ect(s.x,s.y,e.x,e.y,n));return XY(o)}case"polygon":return XY(e.points);case"polygon_with_arcs":{const A=e.brep_shape.outer_ring.vertices.map(t=>({x:t.x,y:t.y}));return XY(A)}case"text":{const A=e.size??0,t=e.text?e.text.length*A*.6:0,i=A;if(t===0&&i===0)return{minX:e.x,maxX:e.x,minY:e.y,maxY:e.y};const n=t/2,o=i/2;return{minX:e.x-n,maxX:e.x+n,minY:e.y-o,maxY:e.y+o}}default:return null}};function f8e(e){const{dimensionStart:A,dimensionEnd:t,screenDimensionStart:i,screenDimensionEnd:n,flipX:o,flipY:s}=e,r=t.x-A.x,a=t.y-A.y,g=Math.sqrt(r*r+a*a),c=n.x-i.x,I=n.y-i.y,l=Math.sqrt(c*c+I*I),B=Math.atan2(I,c)*(180/Math.PI),C=Math.abs(B)%90,Q=Math.min(C,90-C)>15,h=(i.x+n.x)/2,u=(i.y+n.y)/2,d=15,f=B+90;let m=Math.cos(f*Math.PI/180)*d,w=Math.sin(f*Math.PI/180)*d;const D=c>0&&I<0,b=c>0&&I>0,k=c<0&&I>0;o!==s&&!D&&(m=-m,w=-w),D&&(m+=Math.cos(f*Math.PI/180)*-45,w+=Math.sin(f*Math.PI/180)*-45),b&&(m+=Math.cos(f*Math.PI/180)+-20,w+=Math.sin(f*Math.PI/180)+-10),k&&(m+=Math.cos(f*Math.PI/180)*10,w+=Math.sin(f*Math.PI/180)*10);const x=h+m,N=u+w;return{distance:g,screenDistance:l,x,y:N,show:g>.01&&l>30&&Q}}function y8e(e){const{dimensionStart:A,dimensionEnd:t,screenDimensionStart:i,screenDimensionEnd:n,flipX:o,flipY:s}=e;return AA.useMemo(()=>f8e({dimensionStart:A,dimensionEnd:t,screenDimensionStart:i,screenDimensionEnd:n,flipX:o,flipY:s}),[A,t,i,n,o,s])}var m8e=(e,A,t)=>{const i=t*Math.PI/180,n=Math.cos(i),o=Math.sin(i),s=e.x-A.x,r=e.y-A.y,a=s*n-r*o,g=s*o+r*n;return{x:a+A.x,y:g+A.y}},ict=(e,A,t,i)=>{const n={top_left:{x:e.x-A,y:e.y-t},top_center:{x:e.x,y:e.y-t},top_right:{x:e.x+A,y:e.y-t},center_left:{x:e.x-A,y:e.y},center:{x:e.x,y:e.y},center_right:{x:e.x+A,y:e.y},bottom_left:{x:e.x-A,y:e.y+t},bottom_center:{x:e.x,y:e.y+t},bottom_right:{x:e.x+A,y:e.y+t}};return i===0?Object.entries(n).map(([o,s])=>({anchor:o,point:s})):Object.entries(n).map(([o,s])=>({anchor:o,point:m8e(s,e,i)}))},w8e=e=>{switch(e.pcb_drawing_type){case"rect":{const A=e.ccw_rotation??0;return ict({x:e.x,y:e.y},e.w/2,e.h/2,A)}case"pill":{const A=e.ccw_rotation??0;return ict({x:e.x,y:e.y},e.w/2,e.h/2,A)}case"circle":return[{anchor:"circle_center",point:{x:e.x,y:e.y}},{anchor:"circle_right",point:{x:e.x+e.r,y:e.y}},{anchor:"circle_left",point:{x:e.x-e.r,y:e.y}},{anchor:"circle_top",point:{x:e.x,y:e.y-e.r}},{anchor:"circle_bottom",point:{x:e.x,y:e.y+e.r}}];case"oval":return[{anchor:"oval_center",point:{x:e.x,y:e.y}},{anchor:"oval_right",point:{x:e.x+e.rX,y:e.y}},{anchor:"oval_left",point:{x:e.x-e.rX,y:e.y}},{anchor:"oval_top",point:{x:e.x,y:e.y-e.rY}},{anchor:"oval_bottom",point:{x:e.x,y:e.y+e.rY}}];case"line":{const A={x:(e.x1+e.x2)/2,y:(e.y1+e.y2)/2};return[{anchor:"line_start",point:{x:e.x1,y:e.y1}},{anchor:"line_mid",point:A},{anchor:"line_end",point:{x:e.x2,y:e.y2}}]}case"polygon":return e.points.map((A,t)=>({anchor:`polygon_vertex_${t}`,point:A}));case"polygon_with_arcs":return e.brep_shape.outer_ring.vertices.map((A,t)=>({anchor:`polygon_with_arcs_vertex_${t}`,point:{x:A.x,y:A.y}}));default:return[]}},D8e=16,fG=5,nct=e=>{if(e.pcb_drawing_type==="text")return!0;const A=e._element;if(!A||typeof A!="object")return!1;const t=typeof A.type=="string"?A.type:void 0;return t?!!(t.startsWith("pcb_silkscreen_")||t.startsWith("pcb_note_")||t==="pcb_text"||t.startsWith("pcb_fabrication_note_")&&t!=="pcb_fabrication_note_rect"):!1},S8e=({children:e,transform:A,focusOnHover:t=!1,primitives:i=[]})=>{A||(A=yb());const[n,o]=AA.useState(!1),[s,r]=AA.useState(!1),[a,g]=AA.useState(!1),[c,I]=AA.useState({start:null,end:null}),l=zB(H=>H.is_mouse_over_container),B=AA.useCallback(()=>{a&&(g(!1),window.dispatchEvent(new Event("disarm-dimension-tool")))},[a]),[C,E]=AA.useState({x:0,y:0}),[Q,h]=AA.useState({x:0,y:0}),u=AA.useRef({x:0,y:0}),d=AA.useRef(null),m=d.current?.getBoundingClientRect(),w=AA.useMemo(()=>{const H=new Map;for(const O of i){if(!O._element||nct(O)||O.pcb_drawing_type==="pill"||O.pcb_drawing_type==="rect"&&O.ccw_rotation&&O.ccw_rotation!==0)continue;const W=p8e(O);if(!W)continue;const X=H.get(O._element);H.set(O._element,d8e(X??void 0,W))}return H},[i]),D=AA.useMemo(()=>{const H=[];for(const O of i){if(!O._element||nct(O))continue;const W=w8e(O);if(W.length!==0)for(const X of W)H.push({anchor:X.anchor,point:X.point,element:O._element})}return H},[i]),b=AA.useMemo(()=>{const H=[];w.forEach((O,W)=>{if(!O)return;const X=(O.minX+O.maxX)/2,iA=(O.minY+O.maxY)/2,aA={top_left:{x:O.minX,y:O.minY},top_center:{x:X,y:O.minY},top_right:{x:O.maxX,y:O.minY},center_left:{x:O.minX,y:iA},center:{x:X,y:iA},center_right:{x:O.maxX,y:iA},bottom_left:{x:O.minX,y:O.maxY},bottom_center:{x:X,y:O.maxY},bottom_right:{x:O.maxX,y:O.maxY}};for(const[tA,oA]of Object.entries(aA))H.push({anchor:tA,point:oA,element:W})});for(const O of D)H.push(O);return H.push({anchor:"origin",point:{x:0,y:0},element:null}),H},[w,D]),k=AA.useMemo(()=>b.map((H,O)=>({...H,id:`${O}-${H.anchor}`,screenPoint:qi(A,H.point)})),[b,A]),x=AA.useCallback(H=>{if(k.length===0)return{point:H,id:null};const O=qi(A,H);let W=null;for(const X of k){const iA=X.screenPoint.x-O.x,aA=X.screenPoint.y-O.y,tA=Math.hypot(iA,aA);tA>D8e||(!W||tA<W.distance)&&(W={distance:tA,id:X.id,point:X.point})}return W?{point:W.point,id:W.id}:{point:H,id:null}},[k,A]);AA.useEffect(()=>{const H=W=>{const X=W.target;if(X.tagName==="INPUT"||X.tagName==="TEXTAREA"||X.isContentEditable)return;const iA=d.current?.contains(document.activeElement)||document.activeElement===d.current;if(!(!l&&!iA)){if(W.key==="d"){const aA=x({x:u.current.x,y:u.current.y});E({x:aA.point.x,y:aA.point.y}),h({x:aA.point.x,y:aA.point.y}),I({start:aA.id,end:aA.id}),n?(o(!1),r(!1),I({start:null,end:null})):(o(!0),r(!0)),B()}W.key==="Escape"&&(o(!1),r(!1),I({start:null,end:null}),B())}},O=()=>{g(!0)};return window.addEventListener("keydown",H),window.addEventListener("arm-dimension-tool",O),()=>{window.removeEventListener("keydown",H),window.removeEventListener("arm-dimension-tool",O),B()}},[l,n,B,x]);const N=qi(A,C),R=qi(A,Q),U={left:Math.min(N.x,R.x),right:Math.max(N.x,R.x),top:Math.min(N.y,R.y),bottom:Math.max(N.y,R.y),flipX:N.x>R.x,flipY:N.y>R.y,width:0,height:0};U.width=U.right-U.left,U.height=U.bottom-U.top;const T=y8e({dimensionStart:C,dimensionEnd:Q,screenDimensionStart:N,screenDimensionEnd:R,flipX:U.flipX,flipY:U.flipY});return Z.jsxs("div",{ref:d,"data-pcb-viewer":!0,tabIndex:0,style:{position:"relative",outline:"none"},onMouseEnter:()=>{t&&d.current&&d.current.focus()},onMouseLeave:()=>{d.current&&d.current.blur()},onClick:()=>{d.current&&d.current.focus()},onMouseMove:H=>{const O=H.currentTarget.getBoundingClientRect(),W=H.clientX-O.left,X=H.clientY-O.top,iA=qi(mb(A),{x:W,y:X});if(u.current.x=iA.x,u.current.y=iA.y,s){const aA=x(iA);h({x:aA.point.x,y:aA.point.y}),I(tA=>({...tA,end:aA.id}))}},onMouseDown:H=>{const O=H.currentTarget.getBoundingClientRect(),W=H.clientX-O.left,X=H.clientY-O.top,iA=qi(mb(A),{x:W,y:X});if(a&&!n){const aA=x(iA);E({x:aA.point.x,y:aA.point.y}),h({x:aA.point.x,y:aA.point.y}),I({start:aA.id,end:aA.id}),o(!0),r(!0),B()}else s?(r(!1),I(aA=>({...aA,end:null}))):n&&(o(!1),I({start:null,end:null}))},children:[e,n&&Z.jsxs(Z.Fragment,{children:[T.show&&Z.jsx("div",{style:{position:"absolute",left:T.x,top:T.y,color:"red",mixBlendMode:"difference",pointerEvents:"none",fontSize:12,fontFamily:"sans-serif",whiteSpace:"nowrap",zIndex:Qc.dimensionOverlay},children:T.distance.toFixed(2)}),Z.jsx("div",{style:{position:"absolute",left:U.left,width:U.width,textAlign:"center",top:N.y+2,color:"red",mixBlendMode:"difference",pointerEvents:"none",marginTop:U.flipY?0:-20,fontSize:12,fontFamily:"sans-serif",zIndex:Qc.dimensionOverlay},children:Math.abs(C.x-Q.x).toFixed(2)}),Z.jsx("div",{style:{position:"absolute",left:R.x,height:U.height,display:"flex",flexDirection:"column",justifyContent:"center",top:U.top,color:"red",pointerEvents:"none",mixBlendMode:"difference",fontSize:12,fontFamily:"sans-serif",zIndex:Qc.dimensionOverlay},children:Z.jsx("div",{style:{marginLeft:U.flipX?"-100%":4,paddingRight:4},children:Math.abs(C.y-Q.y).toFixed(2)})}),Z.jsxs("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none",mixBlendMode:"difference",zIndex:Qc.dimensionOverlay},width:m.width,height:m.height,children:[Z.jsx("defs",{children:Z.jsx("marker",{id:"head",orient:"auto",markerWidth:"3",markerHeight:"4",refX:"2",refY:"2",children:Z.jsx("path",{d:"M0,0 V4 L2,2 Z",fill:"red"})})}),Z.jsx("line",{x1:N.x,y1:N.y,x2:R.x,y2:R.y,markerEnd:"url(#head)",strokeWidth:1.5,fill:"none",stroke:"red"}),Z.jsx("line",{x1:N.x,y1:N.y,x2:R.x,y2:N.y,strokeWidth:1.5,fill:"none",strokeDasharray:"2,2",stroke:"red"}),Z.jsx("line",{x1:R.x,y1:N.y,x2:R.x,y2:R.y,strokeWidth:1.5,fill:"none",strokeDasharray:"2,2",stroke:"red"})]}),s&&k.map(H=>{const O=H.id===c.start||H.id===c.end,W=fG/2;return Z.jsxs("svg",{width:fG,height:fG,style:{position:"absolute",left:H.screenPoint.x-W,top:H.screenPoint.y-W,pointerEvents:"none",zIndex:Qc.dimensionOverlay},children:[Z.jsx("line",{x1:0,y1:0,x2:fG,y2:fG,stroke:O?"#66ccff":"white",strokeWidth:1}),Z.jsx("line",{x1:fG,y1:0,x2:0,y2:fG,stroke:O?"#66ccff":"white",strokeWidth:1})]},H.id)}),Z.jsxs("div",{style:{right:0,bottom:0,position:"absolute",color:"red",fontFamily:"sans-serif",fontSize:12,margin:4},children:["(",C.x.toFixed(2),",",C.y.toFixed(2),")",Z.jsx("br",{}),"(",Q.x.toFixed(2),",",Q.y.toFixed(2),")",Z.jsx("br",{}),"dist:"," ",Math.sqrt((Q.x-C.x)**2+(Q.y-C.y)**2).toFixed(2)]})]})]})},b8e=(e,A,t=0)=>{const i=e.width/2,n=e.height/2,o=e.center.x-i-t,s=e.center.x+i+t,r=e.center.y-n-t,a=e.center.y+n+t;return A.x>o&&A.x<s&&A.y>r&&A.y<a},x8e=({children:e,disabled:A,transform:t,soup:i,cancelPanDrag:n,onCreateEditEvent:o,onModifyEditEvent:s})=>{t||(t=yb());const r=AA.useRef(null),[a,g]=AA.useState(null),[c,I]=AA.useState(null),l=a!==null;zB(Q=>Q.in_edit_mode);const B=zB(Q=>Q.in_move_footprint_mode),C=zB(Q=>Q.setIsMovingComponent),E=A||!B;return Z.jsxs("div",{ref:r,style:{position:"relative",overflow:"hidden"},onMouseDown:Q=>{if(E)return;const h=Q.currentTarget.getBoundingClientRect(),u=Q.clientX-h.left,d=Q.clientY-h.top;if(Number.isNaN(u)||Number.isNaN(d))return;const f=qi(mb(t),{x:u,y:d});let m=!1;for(const w of i)if(w.type==="pcb_component"&&b8e(w,f,10/t.a)){n(),g(w.pcb_component_id),m=!0;const D=Math.random().toString();I({dragStart:f,originalCenter:w.center,dragEnd:f,edit_event_id:D}),o({edit_event_id:D,edit_event_type:"edit_pcb_component_location",pcb_edit_event_type:"edit_component_location",pcb_component_id:w.pcb_component_id,original_center:w.center,new_center:w.center,in_progress:!0,created_at:Date.now()}),C(!0);break}if(m||g(null),m)return Q.preventDefault(),!1},onMouseMove:Q=>{if(!a||!c)return;const h=Q.currentTarget.getBoundingClientRect(),u=Q.clientX-h.left,d=Q.clientY-h.top;if(Number.isNaN(u)||Number.isNaN(d))return;const f=qi(mb(t),{x:u,y:d});I({...c,dragEnd:f}),s({edit_event_id:c.edit_event_id,new_center:{x:c.originalCenter.x+f.x-c.dragStart.x,y:c.originalCenter.y+f.y-c.dragStart.y}})},onMouseUp:Q=>{a&&(g(null),C(!1),c&&(s({edit_event_id:c.edit_event_id,in_progress:!1}),I(null)))},children:[e,!E&&i.filter(Q=>Q.type==="pcb_component").map(Q=>{if(!Q?.center)return null;const h=qi(t,Q.center);return Z.jsx("div",{style:{position:"absolute",pointerEvents:"none",left:h.x,top:h.y,width:Q.width*t.a+20,height:Q.height*t.a+20,transform:"translate(-50%, -50%)",background:l&&a===Q.pcb_component_id?"rgba(255, 0, 0, 0.2)":""}},Q.pcb_component_id)})]})},_8e=({hotkeys:e})=>(AA.useEffect(()=>{const A=t=>{e.forEach(i=>{t.key===i.key&&i.onUse()})};return window.addEventListener("keydown",A),()=>{window.removeEventListener("keydown",A)}},[e]),Z.jsx("div",{className:jv`
5432
5432
  display: flex;
5433
5433
  flex-direction: column;
5434
5434
  font-family: sans-serif;
@@ -5467,7 +5467,7 @@ $1`).replace(/>(\s*)(?=<!--\s*\/)/g,"> ")}}});function Fgt(e,A,t){if(!A||!t)retu
5467
5467
  transition: opacity 0.2s;
5468
5468
  margin-bottom: 10px;
5469
5469
  color: red;
5470
- `,N8e=({children:e,transform:A=yb(),elements:t})=>{const i=AA.useRef(null),{isShowingDRCErrors:n,hoveredErrorId:o}=zB(g=>({isShowingDRCErrors:g.is_showing_drc_errors,hoveredErrorId:g.hovered_error_id}));if(!t)return Z.jsx("div",{style:{position:"relative"},ref:i,children:e});const s=t.filter(g=>g.type==="pcb_trace_error"),r=t.filter(g=>g.type==="pcb_trace_error"&&g.message?.includes("Multiple components found with name")),a=new Map;return t.forEach(g=>{g.type==="pcb_port"&&a.set(g.pcb_port_id,g)}),Z.jsxs("div",{style:{position:"relative"},ref:i,children:[e,s.map((g,c)=>{const{pcb_port_ids:I,pcb_trace_id:l}=g,B=I?.[0]?a.get(I[0]):void 0,C=I?.[1]?a.get(I[1]):void 0,E=t?Db(t).pcb_trace.get(l):void 0,Q=g.pcb_trace_error_id||`error_${c}_${g.error_type}_${g.message?.slice(0,20)}`,h=o===Q;if(B&&C){const u=qi(A,{x:B.x,y:B.y}),d=qi(A,{x:C.x,y:C.y});if(!n)return null;const f=!(isNaN(u.x)||isNaN(u.y)||isNaN(d.x)||isNaN(d.y)),m={x:(u.x+d.x)/2,y:(u.y+d.y)/2};if(isNaN(m.x)||isNaN(m.y))return null;const w=YpA(m,i);return Z.jsxs(AA.Fragment,{children:[Z.jsx(M8e,{screenPort1:u,screenPort2:d,errorCenter:m,canLineBeDrawn:f,isHighlighted:h}),Z.jsx("div",{style:{position:"absolute",left:m.x-15,top:m.y-15,width:30,height:30,zIndex:Qc.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:D=>{const b=D.currentTarget.nextElementSibling;if(b){const k=b.querySelector(".error-message");k&&(k.style.opacity="1")}},onMouseLeave:D=>{if(!h){const b=D.currentTarget.nextElementSibling;if(b){const k=b.querySelector(".error-message");k&&(k.style.opacity="0")}}}}),Z.jsx("div",{style:{position:"absolute",zIndex:h?200:100,left:w.left,top:w.top,color:h?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:n||h?"flex":"none",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:w.transform},children:Z.jsx("div",{className:`error-message ${JpA}`,style:{opacity:h?1:0,border:`1px solid ${h?"#ff4444":"red"}`},children:g.message})})]},Q)}if(E?.route&&(n||h)){const u=E.route.map(w=>qi(A,{x:w.x,y:w.y}));if(u.some(w=>isNaN(w.x)||isNaN(w.y)))return null;const d=Math.floor(u.length/2),f=u[d],m=YpA(f,i);return Z.jsxs(AA.Fragment,{children:[Z.jsx(R8e,{points:u,errorCenter:f,isHighlighted:h}),Z.jsx("div",{style:{position:"absolute",left:f.x-15,top:f.y-15,width:30,height:30,zIndex:Qc.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:w=>{const D=w.currentTarget.nextElementSibling;if(D){const b=D.querySelector(".error-message");b&&(b.style.opacity="1")}},onMouseLeave:w=>{if(!h){const D=w.currentTarget.nextElementSibling;if(D){const b=D.querySelector(".error-message");b&&(b.style.opacity="0")}}}}),Z.jsx("div",{style:{position:"absolute",zIndex:h?Qc.errorOverlay+10:Qc.errorOverlay+1,left:m.left,top:m.top,color:h?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:"flex",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:m.transform},children:Z.jsx("div",{className:`error-message ${JpA}`,style:{opacity:h?1:0,border:`1px solid ${h?"#ff4444":"red"}`},children:g.message})})]},Q)}return null}),r.map((g,c)=>{const I=g.component_name||g.message?.match(/name "([^"]+)"/)?.[1];if(!I)return null;const l=t?.filter(E=>E.type==="source_component"&&E.name===I||E.type==="pcb_component"&&t?.find(Q=>Q.type==="source_component"&&Q.source_component_id===E.source_component_id&&Q.name===I))||[],B=g.pcb_trace_error_id||`error_${c}_${g.error_type}_${g.message?.slice(0,20)}`,C=o===B;return!C&&!n?null:l.map((E,Q)=>{let h={x:0,y:0};if(E.type==="pcb_component")h=E.center||{x:0,y:0};else if(E.type==="source_component"){const k=t?.find(x=>x.type==="pcb_component"&&x.source_component_id===E.source_component_id);k&&k.type==="pcb_component"&&(h=k.center||{x:0,y:0})}const u=qi(A,h);if(isNaN(u.x)||isNaN(u.y))return null;const d=Math.abs(A.a),D=Math.max(8,Math.min(30,.5*d)),b=YpA(u,i);return Z.jsxs(AA.Fragment,{children:[Z.jsx("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none",mixBlendMode:"difference",zIndex:Qc.errorOverlay},width:"100%",height:"100%",children:C?Z.jsx("polygon",{points:`${u.x},${u.y-D*1.25} ${u.x+D},${u.y} ${u.x},${u.y+D*1.25} ${u.x-D},${u.y}`,fill:"#ff4444"}):Z.jsx("circle",{cx:u.x,cy:u.y,r:D,fill:"none",stroke:C?"#ff4444":"red",strokeWidth:C?Math.max(2,D*.15):Math.max(1,D*.1),opacity:1})}),Z.jsx("div",{style:{position:"absolute",left:u.x-(D+10),top:u.y-(D+10),width:(D+10)*2,height:(D+10)*2,zIndex:Qc.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:k=>{const x=k.currentTarget.nextElementSibling;if(x){const N=x.querySelector(".error-message");N&&(N.style.opacity="1")}},onMouseLeave:k=>{if(!C){const x=k.currentTarget.nextElementSibling;if(x){const N=x.querySelector(".error-message");N&&(N.style.opacity="0")}}}}),Z.jsx("div",{style:{position:"absolute",zIndex:C?Qc.errorOverlay+20:Qc.errorOverlay+10,left:b.left,top:b.top,color:C?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:n||C?"flex":"none",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:b.transform},children:Z.jsx("div",{className:`error-message ${JpA}`,style:{opacity:C?1:0,border:`1px solid ${C?"#ff4444":"red"}`},children:g.message})})]},`${B}_${Q}`)})})]})};function v8e(e,A){return e.size!==A.size?!1:Array.from(e).every(t=>A.has(t))}function L8e({primitiveElement:e,elements:A}){let t=e.trace_length?`${e.trace_length.toFixed(3)}`:"";const i=Db(A).source_trace.get(e?.source_trace_id);if(i?.display_name&&(i?.max_length?t+=` / ${i.max_length}mm `:t+=" mm ",t+=`(${i.display_name})`),!t)return null;const n=e.trace_length&&i?.max_length&&e.trace_length>i.max_length;return{text:t,isOverLength:n}}function U8e(e){const{primitives:A,is_showing_multiple_traces_length:t,elements:i}=e,n=A.filter(a=>a._element.type==="pcb_trace"),o=i.filter(a=>a.type==="source_trace"),s=A.filter(a=>a._element.type!=="pcb_trace"),r=n.filter(a=>o.some(g=>a._element.type==="pcb_trace"&&a._element.source_trace_id===g.source_trace_id&&g.max_length!==void 0));if(!t)return[...s,...r];if(n.length>1){const a=n.reduce((g,c)=>{const I=g._element.trace_length;return c._element.trace_length<I?c:g},n[0]);return[...s,a]}return A}var H8e={position:"absolute",left:0,top:0,pointerEvents:"none",color:"red",fontFamily:"sans-serif",fontSize:12,textShadow:"0 0 2px black"},Y8e=e=>{const{_element:A,_parent_pcb_component:t,_parent_source_component:i,_source_port:n}=e;switch(A.type){case"pcb_trace":return A.trace_length?`${A.trace_length.toFixed(3)}`:"";case"pcb_smtpad":case"pcb_plated_hole":{const o=[],s=Array.from(new Set((A.port_hints??[]).concat(n?.port_hints??[]))).filter(a=>!/^[0-9]+$/.test(a)).filter(a=>!a.includes("unnamed_")).sort((a,g)=>g.localeCompare(a)),r=i&&"name"in i&&i.name&&!i.name.includes("unnamed_")?i.name:null;return s.length>0?r?o.push(...s.map(a=>`${r}.${a}`)):o.push(...s):r&&o.push(r),o.join(", ")}default:return""}},J8e={top:"red",bottom:"aqua"},T8e=({primitive:e,mousePos:A,elements:t})=>{const[i,n]=AA.useState(!1),o=e._element;AA.useEffect(()=>{setTimeout(()=>{n(!0)},100)},[]);const[s,r,a,g]=[e.screen_x,e.screen_y,e.screen_w,e.screen_h],c=e.same_space_index??0,I=26,l=J8e[e?._element?.layer]??"red";let B=0;if(o.type==="pcb_smtpad"&&o?.shape==="rotated_rect"?B=o?.ccw_rotation??0:(o.type==="pcb_smtpad"&&(o?.shape==="pill"||o?.shape==="rotated_pill")&&"ccw_rotation"in e||o.type==="pcb_plated_hole"&&(o?.shape==="pill"||o?.shape==="oval")&&"ccw_rotation"in e)&&(B=o.ccw_rotation??0),o.type==="pcb_trace"){const Q=L8e({primitiveElement:o,elements:t});if(!Q)return null;const h=A.y-35;return Z.jsx("div",{style:{zIndex:Qc.elementOverlay,position:"absolute",left:A.x,top:h,color:l,pointerEvents:"none",transform:"translateX(-50%)"},children:Z.jsx("div",{style:{backgroundColor:"#f2efcc",color:Q.isOverLength?"red":"black",textShadow:"none",WebkitFontSmoothing:"antialiased",MozOsxFontSmoothing:"grayscale",padding:"6px 6px",borderRadius:"6px",fontSize:"14px",minWidth:"45px",textAlign:"center",whiteSpace:"nowrap"},children:Q.text})})}const C=Y8e(e);return C.trim().length===0?null:Z.jsx("div",{style:{zIndex:Qc.elementOverlay,position:"absolute",left:s-a/2-8,top:r-g/2-8,width:a+16,height:g+16,color:l,transform:`rotate(${-B}deg)`,transformOrigin:"center center"},children:Z.jsx("div",{style:{width:i?`calc(100% + ${I*2*c}px)`:"100%",height:i?`calc(100% + ${I*2*c}px)`:"100%",marginLeft:i?`${-I*c}px`:0,marginTop:i?`${-I*c}px`:0,border:`1px solid ${l}`,opacity:i||c===0?1:0,transition:"width 0.2s, height 0.2s, margin-left 0.2s, margin-top 0.2s, opacity 0.2s"},children:Z.jsx("div",{style:{position:"absolute",bottom:g+20+I*c,marginRight:i?`${-I*c}px`:0,marginBottom:i?0:-I*c,transition:"margin-right 0.2s, margin-bottom 0.2s",backgroundColor:"#f2efcc",color:"black",textShadow:"none",WebkitFontSmoothing:"antialiased",MozOsxFontSmoothing:"grayscale",padding:"6px 6px",borderRadius:"6px",fontSize:"14px",transform:`rotate(${B}deg)`,minWidth:"45px",textAlign:"center"},children:C})})})},K8e=({highlightedPrimitives:e,mousePos:A,elements:t})=>{const[i,n]=zB(r=>[r.is_moving_component,r.is_showing_multiple_traces_length]),o=e.some(r=>r._element.type==="pcb_smtpad")&&e.some(r=>r._element.type==="pcb_trace");let s=e;return o&&(s=s.filter(r=>r._element.type==="pcb_smtpad")),s=U8e({primitives:s,is_showing_multiple_traces_length:n,elements:t}),Z.jsx("div",{style:H8e,children:!i&&s.map((r,a)=>Z.jsx(T8e,{primitive:r,mousePos:A,elements:t},a))})},z_=e=>e?.type==="pcb_component",oct=e=>e?.type==="pcb_group",P8e=e=>e?.type==="pcb_panel",TpA=e=>e?.type==="pcb_board",Zc={MIN_LINE_LENGTH_FOR_LABEL:40,LABEL_OFFSET_ABOVE:2,LABEL_OFFSET_BELOW:-18,LABEL_OFFSET_RIGHT:8,LABEL_OFFSET_LEFT:-120,Y_LABEL_MIN_WIDTH:110,LINE_STROKE_WIDTH:1.5,LINE_DASH_PATTERN:"4,4",COMPONENT_MARKER_RADIUS:3,LABEL_FONT_SIZE:11,ANCHOR_MARKER_SIZE:6,ANCHOR_MARKER_STROKE_WIDTH:1.5},x0={OFFSET_LINE:"white",COMPONENT_MARKER_FILL:"#66ccff",COMPONENT_MARKER_STROKE:"white",LABEL_TEXT:"white"},KpA=({targets:e,transform:A,containerWidth:t,containerHeight:i})=>{if(e.length===0)return null;const n={color:x0.LABEL_TEXT,mixBlendMode:"difference",pointerEvents:"none",fontSize:Zc.LABEL_FONT_SIZE,fontFamily:"monospace",fontWeight:"bold"},o=new Map;return e.forEach(s=>{if(!o.has(s.anchor_id)){const r=qi(A,s.anchor);o.set(s.anchor_id,r)}}),Z.jsx("div",{style:{position:"absolute",left:0,top:0,width:t,height:i,overflow:"hidden",pointerEvents:"none",zIndex:Qc.dimensionOverlay},children:Z.jsxs("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none"},width:t,height:i,children:[e.map(s=>{const r=s.anchor,a=s.anchor_id,g=s.target,c=o.get(a),I=qi(A,g),l=g.x-r.x,B=g.y-r.y,C=Math.abs(I.x-c.x),E=Math.abs(I.y-c.y),Q=I.y<c.y,h=I.x>c.x,u=Q?Zc.LABEL_OFFSET_ABOVE:Zc.LABEL_OFFSET_BELOW,d=h?Zc.LABEL_OFFSET_RIGHT:Zc.LABEL_OFFSET_LEFT,f=C>Zc.MIN_LINE_LENGTH_FOR_LABEL,m=E>Zc.MIN_LINE_LENGTH_FOR_LABEL,w=`${s.display_offset_x??l.toFixed(2)}mm`,D=`${s.display_offset_y??B.toFixed(2)}mm`;return Z.jsxs("g",{children:[Z.jsx("line",{x1:c.x,y1:c.y,x2:I.x,y2:c.y,stroke:x0.OFFSET_LINE,strokeWidth:Zc.LINE_STROKE_WIDTH,strokeDasharray:Zc.LINE_DASH_PATTERN}),Z.jsx("line",{x1:I.x,y1:c.y,x2:I.x,y2:I.y,stroke:x0.OFFSET_LINE,strokeWidth:Zc.LINE_STROKE_WIDTH,strokeDasharray:Zc.LINE_DASH_PATTERN}),s.type==="component"||s.type==="board"?Z.jsx("circle",{cx:I.x,cy:I.y,r:Zc.COMPONENT_MARKER_RADIUS,fill:x0.COMPONENT_MARKER_FILL,stroke:x0.COMPONENT_MARKER_STROKE,strokeWidth:1}):Z.jsxs(Z.Fragment,{children:[Z.jsx("line",{x1:I.x-Zc.ANCHOR_MARKER_SIZE,y1:I.y,x2:I.x+Zc.ANCHOR_MARKER_SIZE,y2:I.y,stroke:x0.OFFSET_LINE,strokeWidth:Zc.ANCHOR_MARKER_STROKE_WIDTH}),Z.jsx("line",{x1:I.x,y1:I.y-Zc.ANCHOR_MARKER_SIZE,x2:I.x,y2:I.y+Zc.ANCHOR_MARKER_SIZE,stroke:x0.OFFSET_LINE,strokeWidth:Zc.ANCHOR_MARKER_STROKE_WIDTH})]}),f&&Z.jsx("foreignObject",{x:Math.min(c.x,I.x),y:c.y+u,width:Math.abs(I.x-c.x),height:20,style:{overflow:"visible"},children:Z.jsx("div",{style:{...n,textAlign:"center"},children:w})}),m&&Z.jsx("foreignObject",{x:I.x+d,y:Math.min(c.y,I.y),width:Zc.Y_LABEL_MIN_WIDTH,height:Math.abs(I.y-c.y),style:{overflow:"visible"},children:Z.jsx("div",{style:{...n,display:"flex",alignItems:"center",justifyContent:h?"flex-start":"flex-end",whiteSpace:"nowrap",padding:"0 4px",height:"100%"},children:D})})]},s.id)}),Array.from(o.entries()).map(([s,r])=>Z.jsxs("g",{children:[Z.jsx("line",{x1:r.x-Zc.ANCHOR_MARKER_SIZE,y1:r.y,x2:r.x+Zc.ANCHOR_MARKER_SIZE,y2:r.y,stroke:x0.OFFSET_LINE,strokeWidth:Zc.ANCHOR_MARKER_STROKE_WIDTH}),Z.jsx("line",{x1:r.x,y1:r.y-Zc.ANCHOR_MARKER_SIZE,x2:r.x,y2:r.y+Zc.ANCHOR_MARKER_SIZE,stroke:x0.OFFSET_LINE,strokeWidth:Zc.ANCHOR_MARKER_STROKE_WIDTH})]},`anchor-${s}`))]})})},q8e=({elements:e,highlightedPrimitives:A,transform:t,containerWidth:i,containerHeight:n})=>{const o=e.filter(h=>TpA(h)),s=e.filter(h=>z_(h)),r=e.filter(h=>oct(h)),a=A.map(h=>z_(h._parent_pcb_component)?h._parent_pcb_component.pcb_component_id:z_(h._element)?h._element.pcb_component_id:null).filter(h=>!!h),g=new Set;if(a.forEach(h=>{const u=s.find(d=>d.pcb_component_id===h);u?.pcb_group_id&&g.add(u.pcb_group_id)}),!zB(h=>h.is_showing_group_anchor_offsets)&&a.length===0)return null;const I=s.map(h=>{const u=h.positioned_relative_to_pcb_board_id;if(!u)return null;const d=o.find(f=>f.pcb_board_id===u);return d?{component:h,board:d,type:"component"}:null}).filter(h=>!!h),l=r.map(h=>{const u=h.positioned_relative_to_pcb_board_id;if(!u||!h.center)return null;const d=o.find(f=>f.pcb_board_id===u);return d?{group:h,board:d,type:"group"}:null}).filter(h=>!!h),B=[...I,...l];if(B.length===0)return null;const C=a.length===0,E=B.filter(h=>h.type==="component"?C||a.includes(h.component.pcb_component_id):C||g.has(h.group.pcb_group_id));if(E.length===0)return null;const Q=E.map(h=>h.type==="component"?{id:`${h.board.pcb_board_id}-${h.component.pcb_component_id}-${h.type}`,anchor:h.board.center,anchor_id:h.board.pcb_board_id,target:h.component.center,type:"component",display_offset_x:h.component.display_offset_x,display_offset_y:h.component.display_offset_y}:{id:`${h.board.pcb_board_id}-${h.group.pcb_group_id}-${h.type}`,anchor:h.board.center,anchor_id:h.board.pcb_board_id,target:{x:h.group.anchor_position?.x??h.group.center.x,y:h.group.anchor_position?.y??h.group.center.y},type:"group",display_offset_x:h.group.display_offset_x,display_offset_y:h.group.display_offset_y}).filter(h=>!!h);return Z.jsx(KpA,{targets:Q,transform:t,containerWidth:i,containerHeight:n})},O8e=({elements:e,highlightedPrimitives:A,transform:t,containerWidth:i,containerHeight:n})=>{const o=e.filter(h=>oct(h)),s=e.filter(h=>z_(h)),r=A.map(h=>z_(h._parent_pcb_component)?h._parent_pcb_component.pcb_component_id:z_(h._element)?h._element.pcb_component_id:null).filter(h=>!!h),a=(h,u)=>{if(u.has(h))return;u.add(h);const d=o.find(f=>f.pcb_group_id===h);d?.position_mode==="relative_to_group_anchor"&&d.positioned_relative_to_pcb_group_id&&a(d.positioned_relative_to_pcb_group_id,u)},g=new Set;if(r.forEach(h=>{const u=s.find(d=>d.pcb_component_id===h);u&&(u.position_mode==="relative_to_group_anchor"&&u.positioned_relative_to_pcb_group_id&&a(u.positioned_relative_to_pcb_group_id,g),u.pcb_group_id&&a(u.pcb_group_id,g))}),!zB(h=>h.is_showing_group_anchor_offsets)&&r.length===0)return null;const I=s.map(h=>{if(h.position_mode==="relative_to_group_anchor"&&h.positioned_relative_to_pcb_group_id){const u=o.find(d=>d.pcb_group_id===h.positioned_relative_to_pcb_group_id);return u&&u.anchor_position?{component:h,parentGroup:u,type:"component"}:null}if(h.pcb_group_id){const u=o.find(d=>d.pcb_group_id===h.pcb_group_id);return u&&u.anchor_position?{component:h,parentGroup:u,type:"component"}:null}return null}).filter(h=>!!h),l=o.map(h=>{if(h.position_mode==="relative_to_group_anchor"&&h.positioned_relative_to_pcb_group_id){const u=o.find(d=>d.pcb_group_id===h.positioned_relative_to_pcb_group_id);if(u&&u.anchor_position&&h.anchor_position)return{group:h,parentGroup:u,type:"group"}}return null}).filter(h=>!!h),B=[...I,...l];if(B.length===0)return null;const C=r.length===0,E=B.filter(h=>h.type==="component"?C||r.includes(h.component.pcb_component_id):C||g.has(h.group.pcb_group_id)||g.has(h.parentGroup.pcb_group_id));if(E.length===0)return null;const Q=E.map(h=>{const u=h.parentGroup.anchor_position;return u?h.type==="component"?h.component.center?{id:`${h.parentGroup.pcb_group_id}-${h.component.pcb_component_id}-${h.type}`,anchor:u,anchor_id:h.parentGroup.pcb_group_id,target:h.component.center,type:"component",display_offset_x:h.component.display_offset_x,display_offset_y:h.component.display_offset_y}:null:h.group.anchor_position?{id:`${h.parentGroup.pcb_group_id}-${h.group.pcb_group_id}-${h.type}`,anchor:u,anchor_id:h.parentGroup.pcb_group_id,target:h.group.anchor_position,type:"group",display_offset_x:h.group.display_offset_x,display_offset_y:h.group.display_offset_y}:null:null}).filter(h=>!!h);return Z.jsx(KpA,{targets:Q,transform:t,containerWidth:i,containerHeight:n})},W8e=(e,A)=>{const t=e.pcb_component_id,i=A.filter(n=>(n.type==="pcb_smtpad"||n.type==="pcb_plated_hole")&&n.pcb_component_id===t||n.type==="pcb_hole"&&n.pcb_component_id===t);return i.length===0?UpA([e]):UpA(i)},Z8e=({elements:e,highlightedPrimitives:A,transform:t,containerWidth:i,containerHeight:n})=>{const o=new Map;for(const r of A)z_(r._parent_pcb_component)&&o.set(r._parent_pcb_component.pcb_component_id,r._parent_pcb_component),z_(r._element)&&o.set(r._element.pcb_component_id,r._element);if(o.size===0)return null;const s=[];for(const r of o.values()){const a=W8e(r,e);if(!a)continue;const g=r.positioned_relative_to_pcb_group_id??r.pcb_group_id,c=g?Db(e).pcb_group.get(g):null;s.push({component:r,bbox:a,group:c})}return s.length===0?null:Z.jsx("div",{style:{position:"absolute",left:0,top:0,width:i,height:n,overflow:"hidden",pointerEvents:"none",zIndex:Qc.dimensionOverlay},children:Z.jsx("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none"},width:i,height:n,children:s.map(({component:r,bbox:a,group:g})=>{const c=qi(t,{x:a.minX,y:a.maxY}),I=qi(t,{x:a.maxX,y:a.minY}),l={x:Math.min(c.x,I.x),y:Math.min(c.y,I.y),width:Math.abs(I.x-c.x),height:Math.abs(I.y-c.y)},B=r.center??{x:(a.minX+a.maxX)/2,y:(a.minY+a.maxY)/2},C=qi(t,B);return Z.jsxs("g",{children:[Z.jsx("rect",{x:l.x,y:l.y,width:l.width,height:l.height,fill:"none",stroke:"white",strokeWidth:1.5,strokeDasharray:"4,4"}),Z.jsx("line",{x1:C.x-6,y1:C.y,x2:C.x+6,y2:C.y,stroke:x0.COMPONENT_MARKER_STROKE,strokeWidth:1.5}),Z.jsx("line",{x1:C.x,y1:C.y-6,x2:C.x,y2:C.y+6,stroke:x0.COMPONENT_MARKER_STROKE,strokeWidth:1.5}),Z.jsx("circle",{cx:C.x,cy:C.y,r:Zc.COMPONENT_MARKER_RADIUS,fill:x0.COMPONENT_MARKER_FILL,stroke:x0.COMPONENT_MARKER_STROKE,strokeWidth:1})]},r.pcb_component_id)})})})},V8e=({elements:e,highlightedPrimitives:A,transform:t,containerWidth:i,containerHeight:n})=>{const o=e.filter(B=>P8e(B)),s=e.filter(B=>TpA(B)),r=A.map(B=>TpA(B._element)?B._element.pcb_board_id:null).filter(B=>!!B);if(!zB(B=>B.is_showing_group_anchor_offsets)&&r.length===0)return null;const g=s.map(B=>{const C=B.pcb_panel_id,E=B.position_mode;if(!C||E!=="relative_to_panel_anchor")return null;const Q=o.find(h=>h.pcb_panel_id===C);return Q?{board:B,panel:Q,type:"board"}:null}).filter(B=>!!B);if(g.length===0)return null;const c=r.length===0,I=g.filter(B=>c||r.includes(B.board.pcb_board_id));if(I.length===0)return null;const l=I.map(B=>B.board.center?{id:`${B.panel.pcb_panel_id}-${B.board.pcb_board_id}-${B.type}`,anchor:B.panel.center,anchor_id:B.panel.pcb_panel_id,target:B.board.center,type:"board",display_offset_x:B.board.display_offset_x,display_offset_y:B.board.display_offset_y}:null).filter(B=>!!B);return Z.jsx(KpA,{targets:l,transform:t,containerWidth:i,containerHeight:n})},r9=e=>{if(e.length===0)return null;let A=e[0].x,t=e[0].y,i=e[0].x,n=e[0].y;for(const o of e)o.x<A&&(A=o.x),o.y<t&&(t=o.y),o.x>i&&(i=o.x),o.y>n&&(n=o.y);return{center:{x:(A+i)/2,y:(t+n)/2},width:i-A,height:n-t}},sct=(e,A)=>{if(A.length<3)return!1;let t=!1;for(let i=0,n=A.length-1;i<A.length;n=i++){const o=A[i].x,s=A[i].y,r=A[n].x,a=A[n].y;s>e.y!=a>e.y&&e.x<(r-o)*(e.y-s)/(a-s||Number.EPSILON)+o&&(t=!t)}return t},j8e=(e,A,t)=>{const i=[];for(const n of e){if(!n._element)continue;if("x1"in n&&n._element?.type==="pcb_trace"){const r=Dh({x:A.x,y:A.y},{x:n.x1,y:n.y1},{x:n.x2,y:n.y2}),a=n.width||.5,g=Math.max(a*25,2)/t.a;r<g&&i.push(n);continue}if(n.pcb_drawing_type==="polygon"){const r=n.points.map(g=>({x:he.parse(g.x),y:he.parse(g.y)})),a=r9(r);if(!a||A.x<a.center.x-a.width/2||A.x>a.center.x+a.width/2||A.y<a.center.y-a.height/2||A.y>a.center.y+a.height/2)continue;sct(A,r)&&i.push(n);continue}if(n.pcb_drawing_type==="polygon_with_arcs"){const r=n.brep_shape.outer_ring.vertices.map(g=>({x:he.parse(g.x),y:he.parse(g.y)})),a=r9(r);if(!a||A.x<a.center.x-a.width/2||A.x>a.center.x+a.width/2||A.y<a.center.y-a.height/2||A.y>a.center.y+a.height/2)continue;sct(A,r)&&i.push(n);continue}if(!("x"in n&&"y"in n))continue;let o=0,s=0;if("w"in n&&"h"in n)o=n.w,s=n.h;else if("r"in n)o=n.r*2,s=n.r*2;else if("rX"in n&&"rY"in n)o=n.rX*2,s=n.rY*2;else continue;Math.abs(n.x-A.x)<o/2&&Math.abs(n.y-A.y)<s/2&&i.push(n)}return i},z8e=({elements:e,children:A,transform:t,primitives:i,onMouseHoverOverPrimitives:n})=>{const[o,s]=AA.useState([]),[r,a]=AA.useState({x:0,y:0}),[g,{width:c,height:I}]=zY(),l=AA.useMemo(()=>{const C=[];for(const E of o){if(E._element?.type==="pcb_via"||E._element?.type==="pcb_component"||E?.layer==="drill")continue;let Q=null,h=0,u=0;if(E.pcb_drawing_type==="polygon"){const w=r9(E.points);if(!w)continue;Q=w.center,h=w.width,u=w.height}else if(E.pcb_drawing_type==="polygon_with_arcs"){const w=E.brep_shape.outer_ring.vertices.map(b=>({x:b.x,y:b.y})),D=r9(w);if(!D)continue;Q=D.center,h=D.width,u=D.height}else"x"in E&&"y"in E&&(Q={x:E.x,y:E.y},h="w"in E?E.w:"r"in E?E.r*2:"rX"in E&&"rY"in E?E.rX*2:0,u="h"in E?E.h:"r"in E?E.r*2:"rX"in E&&"rY"in E?E.rY*2:0);if(!Q)continue;const d=qi(t,Q),f={w:h*t.a,h:u*t.a},m=C.filter(w=>d.x===w.screen_x&&d.y===w.screen_y&&f.w===w.screen_w&&f.h===w.screen_h).length;C.push({...E,x:Q.x,y:Q.y,w:h,h:u,screen_x:d.x,screen_y:d.y,screen_w:f.w,screen_h:f.h,same_space_index:m})}return C},[o,t]),B=(C,E,Q,h)=>{a({x:C,y:E});const u=qi(mb(Q),{x:C,y:E}),d=j8e(h,u,Q);v8e(new Set(d.map(f=>f._pcb_drawing_object_id)),new Set(o.map(f=>f._pcb_drawing_object_id)))||(s(d),n(d))};return Z.jsxs("div",{ref:g,style:{position:"relative",width:"100%",height:"100%"},onMouseMove:C=>{if(t){const E=C.currentTarget.getBoundingClientRect(),Q=C.clientX-E.left,h=C.clientY-E.top;B(Q,h,t,i)}},onTouchStart:C=>{if(t){const E=C.touches[0],Q=C.currentTarget.getBoundingClientRect(),h=E.clientX-Q.left,u=E.clientY-Q.top;B(h,u,t,i)}},children:[A,Z.jsx(K8e,{elements:e,mousePos:r,highlightedPrimitives:l}),t&&Z.jsxs(Z.Fragment,{children:[Z.jsx(q8e,{elements:e,highlightedPrimitives:l,transform:t,containerWidth:c,containerHeight:I}),Z.jsx(O8e,{elements:e,highlightedPrimitives:l,transform:t,containerWidth:c,containerHeight:I}),Z.jsx(Z8e,{elements:e,highlightedPrimitives:l,transform:t,containerWidth:c,containerHeight:I}),Z.jsx(V8e,{elements:e,highlightedPrimitives:l,transform:t,containerWidth:c,containerHeight:I})]})]})},rct=["rgb(255, 100, 100)","rgb(100, 255, 100)","rgb(100, 100, 255)","rgb(255, 255, 100)","rgb(255, 100, 255)","rgb(100, 255, 255)","rgb(255, 150, 100)","rgb(150, 100, 255)","rgb(100, 255, 150)","rgb(255, 100, 150)"],X8e=({children:e,transform:A=yb(),elements:t=[],hoveredComponentIds:i=[]})=>{const[n,{width:o,height:s}]=zY(),r=AA.useRef(null),{is_showing_pcb_groups:a,pcb_group_view_mode:g,is_showing_group_anchor_offsets:c}=zB(I=>({is_showing_pcb_groups:I.is_showing_pcb_groups,pcb_group_view_mode:I.pcb_group_view_mode,is_showing_group_anchor_offsets:I.is_showing_group_anchor_offsets}));return AA.useEffect(()=>{const I=r.current;if(!I||!o||!s)return;I.width=o,I.height=s;const l=I.getContext("2d");if(!l||(l.clearRect(0,0,o,s),!a))return;const B=t.filter(w=>w.type==="pcb_group"),C=t.filter(w=>w.type==="pcb_component"),E=t.filter(w=>w.type==="source_group"),Q=new Map(E.map(w=>[w.source_group_id,w])),h=B.filter(w=>{if(g==="all")return!0;if(!w.source_group_id)return!1;const D=Q.get(w.source_group_id);return D?D.was_automatically_named!==!0:!1}),u=new Map;E.forEach(w=>{const D=w;if(D.parent_source_group_id){const b=u.get(D.parent_source_group_id)||[];b.push(w.source_group_id),u.set(D.parent_source_group_id,b)}});const d=w=>{const D=[],b=u.get(w)||[];for(const k of b)D.push(k),D.push(...d(k));return D},f=w=>{const D=E.find(b=>b.source_group_id===w);return D?.parent_source_group_id?1+f(D.parent_source_group_id):0},m=new Set;if(i.length>0)for(const w of C){if(!i.includes(w.pcb_component_id))continue;const D=w.positioned_relative_to_pcb_group_id??w.pcb_group_id;D&&m.add(D)}h.forEach((w,D)=>{let b=C.filter(HA=>HA.pcb_group_id===w.pcb_group_id);if(w.source_group_id){const HA=d(w.source_group_id),PA=B.filter(bA=>bA.source_group_id&&HA.includes(bA.source_group_id));for(const bA of PA){const wA=C.filter(LA=>LA.pcb_group_id===bA.pcb_group_id);b=[...b,...wA]}}let k,x,N,R,U=!1;if(w.center&&w.width&&w.height){U=!0;const HA=w.width/2,PA=w.height/2;k=w.center.x-HA,N=w.center.x+HA,x=w.center.y-PA,R=w.center.y+PA}else if(b.length===0||(k=1/0,x=1/0,N=-1/0,R=-1/0,b.forEach(HA=>{if(HA.center&&typeof HA.width=="number"&&typeof HA.height=="number"){const PA=HA.center.x-HA.width/2,bA=HA.center.x+HA.width/2,wA=HA.center.y+HA.height/2,LA=HA.center.y-HA.height/2;k=Math.min(k,PA),N=Math.max(N,bA),x=Math.min(x,LA),R=Math.max(R,wA)}}),k===1/0||N===-1/0))return;const T=w.source_group_id?f(w.source_group_id):0,H=w.source_group_id?d(w.source_group_id).length>0:!1;if(!U){const bA=1+(H?.5:0);k-=bA,N+=bA,x-=bA,R+=bA}const O=qi(A,{x:k,y:R}),W=qi(A,{x:N,y:R}),X=qi(A,{x:k,y:x}),iA=qi(A,{x:N,y:x}),aA=rct[D%rct.length];l.strokeStyle=aA,l.lineWidth=2;const tA=Math.max(4,Math.min(12,8*Math.abs(A.a))),oA=Math.max(2,Math.min(6,4*Math.abs(A.a))),CA=tA*(H?1.3:1),SA=oA;l.setLineDash([CA,SA]),l.beginPath(),l.moveTo(O.x,O.y),l.lineTo(W.x,W.y),l.lineTo(iA.x,iA.y),l.lineTo(X.x,X.y),l.closePath(),l.stroke();const MA=Math.max(8,Math.min(12,10*Math.abs(A.a))),GA=T==0||T==1?0:T*.11,TA=MA*(1-GA),hA=4,kA=w.name||`Group ${D+1}`;l.font=`${TA}px sans-serif`,l.setLineDash([]);const qA=l.measureText(kA).width+hA*2,ZA=TA+hA*2,rt=O.x-5,yA=O.y-5,$A=3;if(l.fillStyle="rgba(0, 0, 0, 0.8)",l.beginPath(),l.roundRect(rt,yA-ZA,qA,ZA,$A),l.fill(),l.fillStyle=aA,l.textAlign="left",l.textBaseline="middle",l.fillText(kA,rt+hA,yA-ZA/2),c&&m.has(w.pcb_group_id)&&!!w.anchor_position&&w.anchor_position){const HA=Array.isArray(w.anchor_position)?{x:w.anchor_position[0]??0,y:w.anchor_position[1]??0}:{x:w.anchor_position.x,y:w.anchor_position.y},PA=qi(A,HA);l.strokeStyle="white",l.lineWidth=1.5,l.setLineDash([]);const bA=Math.max(4,Math.min(8,6*Math.abs(A.a)));l.beginPath(),l.moveTo(PA.x-bA,PA.y),l.lineTo(PA.x+bA,PA.y),l.stroke(),l.beginPath(),l.moveTo(PA.x,PA.y-bA),l.lineTo(PA.x,PA.y+bA),l.stroke()}})},[t,A,o,s,a,g,c,i]),Z.jsxs("div",{ref:n,style:{position:"relative",width:"100%",height:"100%"},children:[e,Z.jsx("canvas",{ref:r,style:{position:"absolute",top:0,left:0,pointerEvents:"none",zIndex:Qc.pcbGroupOverlay,display:a?"block":"none"}})]})},$8e=({transform:e,soup:A,children:t})=>{const i=zB(r=>r.is_showing_rats_nest),{netMap:n,idToNetMap:o}=AA.useMemo(()=>Ugt(A||[]),[A]),s=AA.useMemo(()=>{if(!A||!i)return[];const r=l=>{const B=Db(A)[l.replace(/_\d+$/,"")].get(l);return B&&"x"in B&&"y"in B?{x:B.x,y:B.y}:null},a=(l,B)=>{const C=n[B]||[];let E=null,Q=1/0;return C.forEach(h=>{const u=r(h);if(u){const d=Math.sqrt((l.x-u.x)**2+(l.y-u.y)**2);d<Q&&d>0&&(Q=d,E=u)}}),E},g=Db(A).pcb_port.list(),c=Db(A).source_trace.list(),I=[];return g.forEach((l,B)=>{const C=o[l.pcb_port_id];let E=!1;for(const u of c)u.connected_source_port_ids.includes(l.source_port_id)&&u.connected_source_net_ids.length>0&&(E=!0);if(!C)return;const Q={x:l.x,y:l.y},h=a(Q,C);h&&I.push({key:`${l.pcb_port_id}-${B}`,startPoint:Q,endPoint:h,isInNet:E})}),I},[A,n,o,i]);return!A||!i?t:(e||(e=yb()),Z.jsxs("div",{style:{position:"relative"},children:[t,Z.jsx("svg",{style:{position:"absolute",left:0,top:0,width:"100%",height:"100%",pointerEvents:"none",opacity:.5,zIndex:Qc.ratsNestOverlay},children:s.map(({key:r,startPoint:a,endPoint:g,isInNet:c})=>{const I=qi(e,a),l=qi(e,g);return Z.jsx("line",{x1:I.x,y1:I.y,x2:l.x,y2:l.y,stroke:"white",strokeWidth:"1",strokeDasharray:c?"6,6":void 0},r)})})]}))},AWe={version:"1.11.339"},X_=(e,A,t)=>{const i=zB(s=>s.is_mouse_over_container),n=AA.useRef(i),o=AA.useRef(A);AA.useEffect(()=>{n.current=i},[i]),AA.useEffect(()=>{o.current=A},[A]),AA.useEffect(()=>{if(!e)return;const s=r=>{const a=r.target;if(a.tagName==="INPUT"||a.tagName==="TEXTAREA"||a.isContentEditable)return;const g=e.split("+"),c=g.includes("ctrl"),I=g.includes("shift"),l=g.includes("alt"),B=g.includes("meta"),C=g[g.length-1],E=t?.current?t.current.contains(document.activeElement)||document.activeElement===t.current:!1;(n.current||E)&&(!c||r.ctrlKey)&&(!I||r.shiftKey)&&(!l||r.altKey)&&(!B||r.metaKey)&&r.key.toLowerCase()===C.toLowerCase()&&(r.preventDefault(),o.current())};return window.addEventListener("keydown",s),()=>{window.removeEventListener("keydown",s)}},[e])},tWe=()=>{const[e,A]=AA.useState(!1);return AA.useEffect(()=>{const t=()=>{A(window.innerWidth<=768)};return t(),window.addEventListener("resize",t),()=>window.removeEventListener("resize",t)},[]),e},$Y=(e,A={stopPropagation:!0})=>{const t=AA.useRef(0),i=AA.useCallback(s=>{A.stopPropagation&&s.stopPropagation();const r=Date.now();r-t.current<300||(t.current=r,e?.(s))},[e,A.stopPropagation]),n=AA.useCallback(s=>{s.preventDefault(),i(s)},[i]);return{onClick:i,onTouchEnd:n,style:{touchAction:"manipulation"}}},eWe=({name:e,selected:A,onClick:t})=>{const{style:i,...n}=$Y(t);return Z.jsxs("div",{className:jv`
5470
+ `,N8e=({children:e,transform:A=yb(),elements:t})=>{const i=AA.useRef(null),{isShowingDRCErrors:n,hoveredErrorId:o}=zB(g=>({isShowingDRCErrors:g.is_showing_drc_errors,hoveredErrorId:g.hovered_error_id}));if(!t)return Z.jsx("div",{style:{position:"relative"},ref:i,children:e});const s=t.filter(g=>g.type==="pcb_trace_error"),r=t.filter(g=>g.type==="pcb_trace_error"&&g.message?.includes("Multiple components found with name")),a=new Map;return t.forEach(g=>{g.type==="pcb_port"&&a.set(g.pcb_port_id,g)}),Z.jsxs("div",{style:{position:"relative"},ref:i,children:[e,s.map((g,c)=>{const{pcb_port_ids:I,pcb_trace_id:l}=g,B=I?.[0]?a.get(I[0]):void 0,C=I?.[1]?a.get(I[1]):void 0,E=t?Db(t).pcb_trace.get(l):void 0,Q=g.pcb_trace_error_id||`error_${c}_${g.error_type}_${g.message?.slice(0,20)}`,h=o===Q;if(B&&C){const u=qi(A,{x:B.x,y:B.y}),d=qi(A,{x:C.x,y:C.y});if(!n)return null;const f=!(isNaN(u.x)||isNaN(u.y)||isNaN(d.x)||isNaN(d.y)),m={x:(u.x+d.x)/2,y:(u.y+d.y)/2};if(isNaN(m.x)||isNaN(m.y))return null;const w=YpA(m,i);return Z.jsxs(AA.Fragment,{children:[Z.jsx(M8e,{screenPort1:u,screenPort2:d,errorCenter:m,canLineBeDrawn:f,isHighlighted:h}),Z.jsx("div",{style:{position:"absolute",left:m.x-15,top:m.y-15,width:30,height:30,zIndex:Qc.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:D=>{const b=D.currentTarget.nextElementSibling;if(b){const k=b.querySelector(".error-message");k&&(k.style.opacity="1")}},onMouseLeave:D=>{if(!h){const b=D.currentTarget.nextElementSibling;if(b){const k=b.querySelector(".error-message");k&&(k.style.opacity="0")}}}}),Z.jsx("div",{style:{position:"absolute",zIndex:h?200:100,left:w.left,top:w.top,color:h?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:n||h?"flex":"none",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:w.transform},children:Z.jsx("div",{className:`error-message ${JpA}`,style:{opacity:h?1:0,border:`1px solid ${h?"#ff4444":"red"}`},children:g.message})})]},Q)}if(E?.route&&(n||h)){const u=E.route.map(w=>qi(A,{x:w.x,y:w.y}));if(u.some(w=>isNaN(w.x)||isNaN(w.y)))return null;const d=Math.floor(u.length/2),f=u[d],m=YpA(f,i);return Z.jsxs(AA.Fragment,{children:[Z.jsx(R8e,{points:u,errorCenter:f,isHighlighted:h}),Z.jsx("div",{style:{position:"absolute",left:f.x-15,top:f.y-15,width:30,height:30,zIndex:Qc.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:w=>{const D=w.currentTarget.nextElementSibling;if(D){const b=D.querySelector(".error-message");b&&(b.style.opacity="1")}},onMouseLeave:w=>{if(!h){const D=w.currentTarget.nextElementSibling;if(D){const b=D.querySelector(".error-message");b&&(b.style.opacity="0")}}}}),Z.jsx("div",{style:{position:"absolute",zIndex:h?Qc.errorOverlay+10:Qc.errorOverlay+1,left:m.left,top:m.top,color:h?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:"flex",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:m.transform},children:Z.jsx("div",{className:`error-message ${JpA}`,style:{opacity:h?1:0,border:`1px solid ${h?"#ff4444":"red"}`},children:g.message})})]},Q)}return null}),r.map((g,c)=>{const I=g.component_name||g.message?.match(/name "([^"]+)"/)?.[1];if(!I)return null;const l=t?.filter(E=>E.type==="source_component"&&E.name===I||E.type==="pcb_component"&&t?.find(Q=>Q.type==="source_component"&&Q.source_component_id===E.source_component_id&&Q.name===I))||[],B=g.pcb_trace_error_id||`error_${c}_${g.error_type}_${g.message?.slice(0,20)}`,C=o===B;return!C&&!n?null:l.map((E,Q)=>{let h={x:0,y:0};if(E.type==="pcb_component")h=E.center||{x:0,y:0};else if(E.type==="source_component"){const k=t?.find(x=>x.type==="pcb_component"&&x.source_component_id===E.source_component_id);k&&k.type==="pcb_component"&&(h=k.center||{x:0,y:0})}const u=qi(A,h);if(isNaN(u.x)||isNaN(u.y))return null;const d=Math.abs(A.a),D=Math.max(8,Math.min(30,.5*d)),b=YpA(u,i);return Z.jsxs(AA.Fragment,{children:[Z.jsx("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none",mixBlendMode:"difference",zIndex:Qc.errorOverlay},width:"100%",height:"100%",children:C?Z.jsx("polygon",{points:`${u.x},${u.y-D*1.25} ${u.x+D},${u.y} ${u.x},${u.y+D*1.25} ${u.x-D},${u.y}`,fill:"#ff4444"}):Z.jsx("circle",{cx:u.x,cy:u.y,r:D,fill:"none",stroke:C?"#ff4444":"red",strokeWidth:C?Math.max(2,D*.15):Math.max(1,D*.1),opacity:1})}),Z.jsx("div",{style:{position:"absolute",left:u.x-(D+10),top:u.y-(D+10),width:(D+10)*2,height:(D+10)*2,zIndex:Qc.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:k=>{const x=k.currentTarget.nextElementSibling;if(x){const N=x.querySelector(".error-message");N&&(N.style.opacity="1")}},onMouseLeave:k=>{if(!C){const x=k.currentTarget.nextElementSibling;if(x){const N=x.querySelector(".error-message");N&&(N.style.opacity="0")}}}}),Z.jsx("div",{style:{position:"absolute",zIndex:C?Qc.errorOverlay+20:Qc.errorOverlay+10,left:b.left,top:b.top,color:C?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:n||C?"flex":"none",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:b.transform},children:Z.jsx("div",{className:`error-message ${JpA}`,style:{opacity:C?1:0,border:`1px solid ${C?"#ff4444":"red"}`},children:g.message})})]},`${B}_${Q}`)})})]})};function v8e(e,A){return e.size!==A.size?!1:Array.from(e).every(t=>A.has(t))}function L8e({primitiveElement:e,elements:A}){let t=e.trace_length?`${e.trace_length.toFixed(3)}`:"";const i=Db(A).source_trace.get(e?.source_trace_id);if(i?.display_name&&(i?.max_length?t+=` / ${i.max_length}mm `:t+=" mm ",t+=`(${i.display_name})`),!t)return null;const n=e.trace_length&&i?.max_length&&e.trace_length>i.max_length;return{text:t,isOverLength:n}}function U8e(e){const{primitives:A,is_showing_multiple_traces_length:t,elements:i}=e,n=A.filter(a=>a._element.type==="pcb_trace"),o=i.filter(a=>a.type==="source_trace"),s=A.filter(a=>a._element.type!=="pcb_trace"),r=n.filter(a=>o.some(g=>a._element.type==="pcb_trace"&&a._element.source_trace_id===g.source_trace_id&&g.max_length!==void 0));if(!t)return[...s,...r];if(n.length>1){const a=n.reduce((g,c)=>{const I=g._element.trace_length;return c._element.trace_length<I?c:g},n[0]);return[...s,a]}return A}var H8e={position:"absolute",left:0,top:0,pointerEvents:"none",color:"red",fontFamily:"sans-serif",fontSize:12,textShadow:"0 0 2px black"},Y8e=e=>{const{_element:A,_parent_pcb_component:t,_parent_source_component:i,_source_port:n}=e;switch(A.type){case"pcb_trace":return A.trace_length?`${A.trace_length.toFixed(3)}`:"";case"pcb_smtpad":case"pcb_plated_hole":{const o=[],s=Array.from(new Set((A.port_hints??[]).concat(n?.port_hints??[]))).filter(a=>!/^[0-9]+$/.test(a)).filter(a=>!a.includes("unnamed_")).sort((a,g)=>g.localeCompare(a)),r=i&&"name"in i&&i.name&&!i.name.includes("unnamed_")?i.name:null;return s.length>0?r?o.push(...s.map(a=>`${r}.${a}`)):o.push(...s):r&&o.push(r),o.join(", ")}default:return""}},J8e={top:"red",bottom:"aqua"},T8e=({primitive:e,mousePos:A,elements:t})=>{const[i,n]=AA.useState(!1),o=e._element;AA.useEffect(()=>{setTimeout(()=>{n(!0)},100)},[]);const[s,r,a,g]=[e.screen_x,e.screen_y,e.screen_w,e.screen_h],c=e.same_space_index??0,I=26,l=J8e[e?._element?.layer]??"red";let B=0;if(o.type==="pcb_smtpad"&&o?.shape==="rotated_rect"?B=o?.ccw_rotation??0:(o.type==="pcb_smtpad"&&(o?.shape==="pill"||o?.shape==="rotated_pill")&&"ccw_rotation"in e||o.type==="pcb_plated_hole"&&(o?.shape==="pill"||o?.shape==="oval")&&"ccw_rotation"in e)&&(B=o.ccw_rotation??0),o.type==="pcb_trace"){const Q=L8e({primitiveElement:o,elements:t});if(!Q)return null;const h=A.y-35;return Z.jsx("div",{style:{zIndex:Qc.elementOverlay,position:"absolute",left:A.x,top:h,color:l,pointerEvents:"none",transform:"translateX(-50%)"},children:Z.jsx("div",{style:{backgroundColor:"#f2efcc",color:Q.isOverLength?"red":"black",textShadow:"none",WebkitFontSmoothing:"antialiased",MozOsxFontSmoothing:"grayscale",padding:"6px 6px",borderRadius:"6px",fontSize:"14px",minWidth:"45px",textAlign:"center",whiteSpace:"nowrap"},children:Q.text})})}const C=Y8e(e);return C.trim().length===0?null:Z.jsx("div",{style:{zIndex:Qc.elementOverlay,position:"absolute",left:s-a/2-8,top:r-g/2-8,width:a+16,height:g+16,color:l,transform:`rotate(${-B}deg)`,transformOrigin:"center center"},children:Z.jsx("div",{style:{width:i?`calc(100% + ${I*2*c}px)`:"100%",height:i?`calc(100% + ${I*2*c}px)`:"100%",marginLeft:i?`${-I*c}px`:0,marginTop:i?`${-I*c}px`:0,border:`1px solid ${l}`,opacity:i||c===0?1:0,transition:"width 0.2s, height 0.2s, margin-left 0.2s, margin-top 0.2s, opacity 0.2s"},children:Z.jsx("div",{style:{position:"absolute",bottom:g+20+I*c,marginRight:i?`${-I*c}px`:0,marginBottom:i?0:-I*c,transition:"margin-right 0.2s, margin-bottom 0.2s",backgroundColor:"#f2efcc",color:"black",textShadow:"none",WebkitFontSmoothing:"antialiased",MozOsxFontSmoothing:"grayscale",padding:"6px 6px",borderRadius:"6px",fontSize:"14px",transform:`rotate(${B}deg)`,minWidth:"45px",textAlign:"center"},children:C})})})},K8e=({highlightedPrimitives:e,mousePos:A,elements:t})=>{const[i,n]=zB(r=>[r.is_moving_component,r.is_showing_multiple_traces_length]),o=e.some(r=>r._element.type==="pcb_smtpad")&&e.some(r=>r._element.type==="pcb_trace");let s=e;return o&&(s=s.filter(r=>r._element.type==="pcb_smtpad")),s=U8e({primitives:s,is_showing_multiple_traces_length:n,elements:t}),Z.jsx("div",{style:H8e,children:!i&&s.map((r,a)=>Z.jsx(T8e,{primitive:r,mousePos:A,elements:t},a))})},z_=e=>e?.type==="pcb_component",oct=e=>e?.type==="pcb_group",P8e=e=>e?.type==="pcb_panel",TpA=e=>e?.type==="pcb_board",Zc={MIN_LINE_LENGTH_FOR_LABEL:40,LABEL_OFFSET_ABOVE:2,LABEL_OFFSET_BELOW:-18,LABEL_OFFSET_RIGHT:8,LABEL_OFFSET_LEFT:-120,Y_LABEL_MIN_WIDTH:110,LINE_STROKE_WIDTH:1.5,LINE_DASH_PATTERN:"4,4",COMPONENT_MARKER_RADIUS:3,LABEL_FONT_SIZE:11,ANCHOR_MARKER_SIZE:6,ANCHOR_MARKER_STROKE_WIDTH:1.5},x0={OFFSET_LINE:"white",COMPONENT_MARKER_FILL:"#66ccff",COMPONENT_MARKER_STROKE:"white",LABEL_TEXT:"white"},KpA=({targets:e,transform:A,containerWidth:t,containerHeight:i})=>{if(e.length===0)return null;const n={color:x0.LABEL_TEXT,mixBlendMode:"difference",pointerEvents:"none",fontSize:Zc.LABEL_FONT_SIZE,fontFamily:"monospace",fontWeight:"bold"},o=new Map;return e.forEach(s=>{if(!o.has(s.anchor_id)){const r=qi(A,s.anchor);o.set(s.anchor_id,r)}}),Z.jsx("div",{style:{position:"absolute",left:0,top:0,width:t,height:i,overflow:"hidden",pointerEvents:"none",zIndex:Qc.dimensionOverlay},children:Z.jsxs("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none"},width:t,height:i,children:[e.map(s=>{const r=s.anchor,a=s.anchor_id,g=s.target,c=o.get(a),I=qi(A,g),l=g.x-r.x,B=g.y-r.y,C=Math.abs(I.x-c.x),E=Math.abs(I.y-c.y),Q=I.y<c.y,h=I.x>c.x,u=Q?Zc.LABEL_OFFSET_ABOVE:Zc.LABEL_OFFSET_BELOW,d=h?Zc.LABEL_OFFSET_RIGHT:Zc.LABEL_OFFSET_LEFT,f=C>Zc.MIN_LINE_LENGTH_FOR_LABEL,m=E>Zc.MIN_LINE_LENGTH_FOR_LABEL,w=`${s.display_offset_x??l.toFixed(2)}mm`,D=`${s.display_offset_y??B.toFixed(2)}mm`;return Z.jsxs("g",{children:[Z.jsx("line",{x1:c.x,y1:c.y,x2:I.x,y2:c.y,stroke:x0.OFFSET_LINE,strokeWidth:Zc.LINE_STROKE_WIDTH,strokeDasharray:Zc.LINE_DASH_PATTERN}),Z.jsx("line",{x1:I.x,y1:c.y,x2:I.x,y2:I.y,stroke:x0.OFFSET_LINE,strokeWidth:Zc.LINE_STROKE_WIDTH,strokeDasharray:Zc.LINE_DASH_PATTERN}),s.type==="component"||s.type==="board"?Z.jsx("circle",{cx:I.x,cy:I.y,r:Zc.COMPONENT_MARKER_RADIUS,fill:x0.COMPONENT_MARKER_FILL,stroke:x0.COMPONENT_MARKER_STROKE,strokeWidth:1}):Z.jsxs(Z.Fragment,{children:[Z.jsx("line",{x1:I.x-Zc.ANCHOR_MARKER_SIZE,y1:I.y,x2:I.x+Zc.ANCHOR_MARKER_SIZE,y2:I.y,stroke:x0.OFFSET_LINE,strokeWidth:Zc.ANCHOR_MARKER_STROKE_WIDTH}),Z.jsx("line",{x1:I.x,y1:I.y-Zc.ANCHOR_MARKER_SIZE,x2:I.x,y2:I.y+Zc.ANCHOR_MARKER_SIZE,stroke:x0.OFFSET_LINE,strokeWidth:Zc.ANCHOR_MARKER_STROKE_WIDTH})]}),f&&Z.jsx("foreignObject",{x:Math.min(c.x,I.x),y:c.y+u,width:Math.abs(I.x-c.x),height:20,style:{overflow:"visible"},children:Z.jsx("div",{style:{...n,textAlign:"center"},children:w})}),m&&Z.jsx("foreignObject",{x:I.x+d,y:Math.min(c.y,I.y),width:Zc.Y_LABEL_MIN_WIDTH,height:Math.abs(I.y-c.y),style:{overflow:"visible"},children:Z.jsx("div",{style:{...n,display:"flex",alignItems:"center",justifyContent:h?"flex-start":"flex-end",whiteSpace:"nowrap",padding:"0 4px",height:"100%"},children:D})})]},s.id)}),Array.from(o.entries()).map(([s,r])=>Z.jsxs("g",{children:[Z.jsx("line",{x1:r.x-Zc.ANCHOR_MARKER_SIZE,y1:r.y,x2:r.x+Zc.ANCHOR_MARKER_SIZE,y2:r.y,stroke:x0.OFFSET_LINE,strokeWidth:Zc.ANCHOR_MARKER_STROKE_WIDTH}),Z.jsx("line",{x1:r.x,y1:r.y-Zc.ANCHOR_MARKER_SIZE,x2:r.x,y2:r.y+Zc.ANCHOR_MARKER_SIZE,stroke:x0.OFFSET_LINE,strokeWidth:Zc.ANCHOR_MARKER_STROKE_WIDTH})]},`anchor-${s}`))]})})},q8e=({elements:e,highlightedPrimitives:A,transform:t,containerWidth:i,containerHeight:n})=>{const o=e.filter(h=>TpA(h)),s=e.filter(h=>z_(h)),r=e.filter(h=>oct(h)),a=A.map(h=>z_(h._parent_pcb_component)?h._parent_pcb_component.pcb_component_id:z_(h._element)?h._element.pcb_component_id:null).filter(h=>!!h),g=new Set;if(a.forEach(h=>{const u=s.find(d=>d.pcb_component_id===h);u?.pcb_group_id&&g.add(u.pcb_group_id)}),!zB(h=>h.is_showing_group_anchor_offsets)&&a.length===0)return null;const I=s.map(h=>{const u=h.positioned_relative_to_pcb_board_id;if(!u)return null;const d=o.find(f=>f.pcb_board_id===u);return d?{component:h,board:d,type:"component"}:null}).filter(h=>!!h),l=r.map(h=>{const u=h.positioned_relative_to_pcb_board_id;if(!u||!h.center)return null;const d=o.find(f=>f.pcb_board_id===u);return d?{group:h,board:d,type:"group"}:null}).filter(h=>!!h),B=[...I,...l];if(B.length===0)return null;const C=a.length===0,E=B.filter(h=>h.type==="component"?C||a.includes(h.component.pcb_component_id):C||g.has(h.group.pcb_group_id));if(E.length===0)return null;const Q=E.map(h=>h.type==="component"?{id:`${h.board.pcb_board_id}-${h.component.pcb_component_id}-${h.type}`,anchor:h.board.center,anchor_id:h.board.pcb_board_id,target:h.component.center,type:"component",display_offset_x:h.component.display_offset_x,display_offset_y:h.component.display_offset_y}:{id:`${h.board.pcb_board_id}-${h.group.pcb_group_id}-${h.type}`,anchor:h.board.center,anchor_id:h.board.pcb_board_id,target:{x:h.group.anchor_position?.x??h.group.center.x,y:h.group.anchor_position?.y??h.group.center.y},type:"group",display_offset_x:h.group.display_offset_x,display_offset_y:h.group.display_offset_y}).filter(h=>!!h);return Z.jsx(KpA,{targets:Q,transform:t,containerWidth:i,containerHeight:n})},O8e=({elements:e,highlightedPrimitives:A,transform:t,containerWidth:i,containerHeight:n})=>{const o=e.filter(h=>oct(h)),s=e.filter(h=>z_(h)),r=A.map(h=>z_(h._parent_pcb_component)?h._parent_pcb_component.pcb_component_id:z_(h._element)?h._element.pcb_component_id:null).filter(h=>!!h),a=(h,u)=>{if(u.has(h))return;u.add(h);const d=o.find(f=>f.pcb_group_id===h);d?.position_mode==="relative_to_group_anchor"&&d.positioned_relative_to_pcb_group_id&&a(d.positioned_relative_to_pcb_group_id,u)},g=new Set;if(r.forEach(h=>{const u=s.find(d=>d.pcb_component_id===h);u&&(u.position_mode==="relative_to_group_anchor"&&u.positioned_relative_to_pcb_group_id&&a(u.positioned_relative_to_pcb_group_id,g),u.pcb_group_id&&a(u.pcb_group_id,g))}),!zB(h=>h.is_showing_group_anchor_offsets)&&r.length===0)return null;const I=s.map(h=>{if(h.position_mode==="relative_to_group_anchor"&&h.positioned_relative_to_pcb_group_id){const u=o.find(d=>d.pcb_group_id===h.positioned_relative_to_pcb_group_id);return u&&u.anchor_position?{component:h,parentGroup:u,type:"component"}:null}if(h.pcb_group_id){const u=o.find(d=>d.pcb_group_id===h.pcb_group_id);return u&&u.anchor_position?{component:h,parentGroup:u,type:"component"}:null}return null}).filter(h=>!!h),l=o.map(h=>{if(h.position_mode==="relative_to_group_anchor"&&h.positioned_relative_to_pcb_group_id){const u=o.find(d=>d.pcb_group_id===h.positioned_relative_to_pcb_group_id);if(u&&u.anchor_position&&h.anchor_position)return{group:h,parentGroup:u,type:"group"}}return null}).filter(h=>!!h),B=[...I,...l];if(B.length===0)return null;const C=r.length===0,E=B.filter(h=>h.type==="component"?C||r.includes(h.component.pcb_component_id):C||g.has(h.group.pcb_group_id)||g.has(h.parentGroup.pcb_group_id));if(E.length===0)return null;const Q=E.map(h=>{const u=h.parentGroup.anchor_position;return u?h.type==="component"?h.component.center?{id:`${h.parentGroup.pcb_group_id}-${h.component.pcb_component_id}-${h.type}`,anchor:u,anchor_id:h.parentGroup.pcb_group_id,target:h.component.center,type:"component",display_offset_x:h.component.display_offset_x,display_offset_y:h.component.display_offset_y}:null:h.group.anchor_position?{id:`${h.parentGroup.pcb_group_id}-${h.group.pcb_group_id}-${h.type}`,anchor:u,anchor_id:h.parentGroup.pcb_group_id,target:h.group.anchor_position,type:"group",display_offset_x:h.group.display_offset_x,display_offset_y:h.group.display_offset_y}:null:null}).filter(h=>!!h);return Z.jsx(KpA,{targets:Q,transform:t,containerWidth:i,containerHeight:n})},W8e=(e,A)=>{const t=e.pcb_component_id,i=A.filter(n=>(n.type==="pcb_smtpad"||n.type==="pcb_plated_hole")&&n.pcb_component_id===t||n.type==="pcb_hole"&&n.pcb_component_id===t);return i.length===0?UpA([e]):UpA(i)},Z8e=({elements:e,highlightedPrimitives:A,transform:t,containerWidth:i,containerHeight:n})=>{const o=new Map;for(const r of A)z_(r._parent_pcb_component)&&o.set(r._parent_pcb_component.pcb_component_id,r._parent_pcb_component),z_(r._element)&&o.set(r._element.pcb_component_id,r._element);if(o.size===0)return null;const s=[];for(const r of o.values()){const a=W8e(r,e);if(!a)continue;const g=r.positioned_relative_to_pcb_group_id??r.pcb_group_id,c=g?Db(e).pcb_group.get(g):null;s.push({component:r,bbox:a,group:c})}return s.length===0?null:Z.jsx("div",{style:{position:"absolute",left:0,top:0,width:i,height:n,overflow:"hidden",pointerEvents:"none",zIndex:Qc.dimensionOverlay},children:Z.jsx("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none"},width:i,height:n,children:s.map(({component:r,bbox:a,group:g})=>{const c=qi(t,{x:a.minX,y:a.maxY}),I=qi(t,{x:a.maxX,y:a.minY}),l={x:Math.min(c.x,I.x),y:Math.min(c.y,I.y),width:Math.abs(I.x-c.x),height:Math.abs(I.y-c.y)},B=r.center??{x:(a.minX+a.maxX)/2,y:(a.minY+a.maxY)/2},C=qi(t,B);return Z.jsxs("g",{children:[Z.jsx("rect",{x:l.x,y:l.y,width:l.width,height:l.height,fill:"none",stroke:"white",strokeWidth:1.5,strokeDasharray:"4,4"}),Z.jsx("line",{x1:C.x-6,y1:C.y,x2:C.x+6,y2:C.y,stroke:x0.COMPONENT_MARKER_STROKE,strokeWidth:1.5}),Z.jsx("line",{x1:C.x,y1:C.y-6,x2:C.x,y2:C.y+6,stroke:x0.COMPONENT_MARKER_STROKE,strokeWidth:1.5}),Z.jsx("circle",{cx:C.x,cy:C.y,r:Zc.COMPONENT_MARKER_RADIUS,fill:x0.COMPONENT_MARKER_FILL,stroke:x0.COMPONENT_MARKER_STROKE,strokeWidth:1})]},r.pcb_component_id)})})})},V8e=({elements:e,highlightedPrimitives:A,transform:t,containerWidth:i,containerHeight:n})=>{const o=e.filter(B=>P8e(B)),s=e.filter(B=>TpA(B)),r=A.map(B=>TpA(B._element)?B._element.pcb_board_id:null).filter(B=>!!B);if(!zB(B=>B.is_showing_group_anchor_offsets)&&r.length===0)return null;const g=s.map(B=>{const C=B.pcb_panel_id,E=B.position_mode;if(!C||E!=="relative_to_panel_anchor")return null;const Q=o.find(h=>h.pcb_panel_id===C);return Q?{board:B,panel:Q,type:"board"}:null}).filter(B=>!!B);if(g.length===0)return null;const c=r.length===0,I=g.filter(B=>c||r.includes(B.board.pcb_board_id));if(I.length===0)return null;const l=I.map(B=>B.board.center?{id:`${B.panel.pcb_panel_id}-${B.board.pcb_board_id}-${B.type}`,anchor:B.panel.center,anchor_id:B.panel.pcb_panel_id,target:B.board.center,type:"board",display_offset_x:B.board.display_offset_x,display_offset_y:B.board.display_offset_y}:null).filter(B=>!!B);return Z.jsx(KpA,{targets:l,transform:t,containerWidth:i,containerHeight:n})},r9=e=>{if(e.length===0)return null;let A=e[0].x,t=e[0].y,i=e[0].x,n=e[0].y;for(const o of e)o.x<A&&(A=o.x),o.y<t&&(t=o.y),o.x>i&&(i=o.x),o.y>n&&(n=o.y);return{center:{x:(A+i)/2,y:(t+n)/2},width:i-A,height:n-t}},sct=(e,A)=>{if(A.length<3)return!1;let t=!1;for(let i=0,n=A.length-1;i<A.length;n=i++){const o=A[i].x,s=A[i].y,r=A[n].x,a=A[n].y;s>e.y!=a>e.y&&e.x<(r-o)*(e.y-s)/(a-s||Number.EPSILON)+o&&(t=!t)}return t},j8e=(e,A,t)=>{const i=[];for(const n of e){if(!n._element)continue;if("x1"in n&&n._element?.type==="pcb_trace"){const r=Dh({x:A.x,y:A.y},{x:n.x1,y:n.y1},{x:n.x2,y:n.y2}),a=n.width||.5,g=Math.max(a*25,2)/t.a;r<g&&i.push(n);continue}if(n.pcb_drawing_type==="polygon"){const r=n.points.map(g=>({x:he.parse(g.x),y:he.parse(g.y)})),a=r9(r);if(!a||A.x<a.center.x-a.width/2||A.x>a.center.x+a.width/2||A.y<a.center.y-a.height/2||A.y>a.center.y+a.height/2)continue;sct(A,r)&&i.push(n);continue}if(n.pcb_drawing_type==="polygon_with_arcs"){const r=n.brep_shape.outer_ring.vertices.map(g=>({x:he.parse(g.x),y:he.parse(g.y)})),a=r9(r);if(!a||A.x<a.center.x-a.width/2||A.x>a.center.x+a.width/2||A.y<a.center.y-a.height/2||A.y>a.center.y+a.height/2)continue;sct(A,r)&&i.push(n);continue}if(!("x"in n&&"y"in n))continue;let o=0,s=0;if("w"in n&&"h"in n)o=n.w,s=n.h;else if("r"in n)o=n.r*2,s=n.r*2;else if("rX"in n&&"rY"in n)o=n.rX*2,s=n.rY*2;else continue;Math.abs(n.x-A.x)<o/2&&Math.abs(n.y-A.y)<s/2&&i.push(n)}return i},z8e=({elements:e,children:A,transform:t,primitives:i,onMouseHoverOverPrimitives:n})=>{const[o,s]=AA.useState([]),[r,a]=AA.useState({x:0,y:0}),[g,{width:c,height:I}]=zY(),l=AA.useMemo(()=>{const C=[];for(const E of o){if(E._element?.type==="pcb_via"||E._element?.type==="pcb_component"||E?.layer==="drill")continue;let Q=null,h=0,u=0;if(E.pcb_drawing_type==="polygon"){const w=r9(E.points);if(!w)continue;Q=w.center,h=w.width,u=w.height}else if(E.pcb_drawing_type==="polygon_with_arcs"){const w=E.brep_shape.outer_ring.vertices.map(b=>({x:b.x,y:b.y})),D=r9(w);if(!D)continue;Q=D.center,h=D.width,u=D.height}else"x"in E&&"y"in E&&(Q={x:E.x,y:E.y},h="w"in E?E.w:"r"in E?E.r*2:"rX"in E&&"rY"in E?E.rX*2:0,u="h"in E?E.h:"r"in E?E.r*2:"rX"in E&&"rY"in E?E.rY*2:0);if(!Q)continue;const d=qi(t,Q),f={w:h*t.a,h:u*t.a},m=C.filter(w=>d.x===w.screen_x&&d.y===w.screen_y&&f.w===w.screen_w&&f.h===w.screen_h).length;C.push({...E,x:Q.x,y:Q.y,w:h,h:u,screen_x:d.x,screen_y:d.y,screen_w:f.w,screen_h:f.h,same_space_index:m})}return C},[o,t]),B=(C,E,Q,h)=>{a({x:C,y:E});const u=qi(mb(Q),{x:C,y:E}),d=j8e(h,u,Q);v8e(new Set(d.map(f=>f._pcb_drawing_object_id)),new Set(o.map(f=>f._pcb_drawing_object_id)))||(s(d),n(d))};return Z.jsxs("div",{ref:g,style:{position:"relative",width:"100%",height:"100%"},onMouseMove:C=>{if(t){const E=C.currentTarget.getBoundingClientRect(),Q=C.clientX-E.left,h=C.clientY-E.top;B(Q,h,t,i)}},onTouchStart:C=>{if(t){const E=C.touches[0],Q=C.currentTarget.getBoundingClientRect(),h=E.clientX-Q.left,u=E.clientY-Q.top;B(h,u,t,i)}},children:[A,Z.jsx(K8e,{elements:e,mousePos:r,highlightedPrimitives:l}),t&&Z.jsxs(Z.Fragment,{children:[Z.jsx(q8e,{elements:e,highlightedPrimitives:l,transform:t,containerWidth:c,containerHeight:I}),Z.jsx(O8e,{elements:e,highlightedPrimitives:l,transform:t,containerWidth:c,containerHeight:I}),Z.jsx(Z8e,{elements:e,highlightedPrimitives:l,transform:t,containerWidth:c,containerHeight:I}),Z.jsx(V8e,{elements:e,highlightedPrimitives:l,transform:t,containerWidth:c,containerHeight:I})]})]})},rct=["rgb(255, 100, 100)","rgb(100, 255, 100)","rgb(100, 100, 255)","rgb(255, 255, 100)","rgb(255, 100, 255)","rgb(100, 255, 255)","rgb(255, 150, 100)","rgb(150, 100, 255)","rgb(100, 255, 150)","rgb(255, 100, 150)"],X8e=({children:e,transform:A=yb(),elements:t=[],hoveredComponentIds:i=[]})=>{const[n,{width:o,height:s}]=zY(),r=AA.useRef(null),{is_showing_pcb_groups:a,pcb_group_view_mode:g,is_showing_group_anchor_offsets:c}=zB(I=>({is_showing_pcb_groups:I.is_showing_pcb_groups,pcb_group_view_mode:I.pcb_group_view_mode,is_showing_group_anchor_offsets:I.is_showing_group_anchor_offsets}));return AA.useEffect(()=>{const I=r.current;if(!I||!o||!s)return;I.width=o,I.height=s;const l=I.getContext("2d");if(!l||(l.clearRect(0,0,o,s),!a))return;const B=t.filter(w=>w.type==="pcb_group"),C=t.filter(w=>w.type==="pcb_component"),E=t.filter(w=>w.type==="source_group"),Q=new Map(E.map(w=>[w.source_group_id,w])),h=B.filter(w=>{if(g==="all")return!0;if(!w.source_group_id)return!1;const D=Q.get(w.source_group_id);return D?D.was_automatically_named!==!0:!1}),u=new Map;E.forEach(w=>{const D=w;if(D.parent_source_group_id){const b=u.get(D.parent_source_group_id)||[];b.push(w.source_group_id),u.set(D.parent_source_group_id,b)}});const d=w=>{const D=[],b=u.get(w)||[];for(const k of b)D.push(k),D.push(...d(k));return D},f=w=>{const D=E.find(b=>b.source_group_id===w);return D?.parent_source_group_id?1+f(D.parent_source_group_id):0},m=new Set;if(i.length>0)for(const w of C){if(!i.includes(w.pcb_component_id))continue;const D=w.positioned_relative_to_pcb_group_id??w.pcb_group_id;D&&m.add(D)}h.forEach((w,D)=>{let b=C.filter(HA=>HA.pcb_group_id===w.pcb_group_id);if(w.source_group_id){const HA=d(w.source_group_id),PA=B.filter(bA=>bA.source_group_id&&HA.includes(bA.source_group_id));for(const bA of PA){const wA=C.filter(LA=>LA.pcb_group_id===bA.pcb_group_id);b=[...b,...wA]}}let k,x,N,R,U=!1;if(w.center&&w.width&&w.height){U=!0;const HA=w.width/2,PA=w.height/2;k=w.center.x-HA,N=w.center.x+HA,x=w.center.y-PA,R=w.center.y+PA}else if(b.length===0||(k=1/0,x=1/0,N=-1/0,R=-1/0,b.forEach(HA=>{if(HA.center&&typeof HA.width=="number"&&typeof HA.height=="number"){const PA=HA.center.x-HA.width/2,bA=HA.center.x+HA.width/2,wA=HA.center.y+HA.height/2,LA=HA.center.y-HA.height/2;k=Math.min(k,PA),N=Math.max(N,bA),x=Math.min(x,LA),R=Math.max(R,wA)}}),k===1/0||N===-1/0))return;const T=w.source_group_id?f(w.source_group_id):0,H=w.source_group_id?d(w.source_group_id).length>0:!1;if(!U){const bA=1+(H?.5:0);k-=bA,N+=bA,x-=bA,R+=bA}const O=qi(A,{x:k,y:R}),W=qi(A,{x:N,y:R}),X=qi(A,{x:k,y:x}),iA=qi(A,{x:N,y:x}),aA=rct[D%rct.length];l.strokeStyle=aA,l.lineWidth=2;const tA=Math.max(4,Math.min(12,8*Math.abs(A.a))),oA=Math.max(2,Math.min(6,4*Math.abs(A.a))),CA=tA*(H?1.3:1),SA=oA;l.setLineDash([CA,SA]),l.beginPath(),l.moveTo(O.x,O.y),l.lineTo(W.x,W.y),l.lineTo(iA.x,iA.y),l.lineTo(X.x,X.y),l.closePath(),l.stroke();const MA=Math.max(8,Math.min(12,10*Math.abs(A.a))),GA=T==0||T==1?0:T*.11,TA=MA*(1-GA),hA=4,kA=w.name||`Group ${D+1}`;l.font=`${TA}px sans-serif`,l.setLineDash([]);const qA=l.measureText(kA).width+hA*2,ZA=TA+hA*2,rt=O.x-5,yA=O.y-5,$A=3;if(l.fillStyle="rgba(0, 0, 0, 0.8)",l.beginPath(),l.roundRect(rt,yA-ZA,qA,ZA,$A),l.fill(),l.fillStyle=aA,l.textAlign="left",l.textBaseline="middle",l.fillText(kA,rt+hA,yA-ZA/2),c&&m.has(w.pcb_group_id)&&!!w.anchor_position&&w.anchor_position){const HA=Array.isArray(w.anchor_position)?{x:w.anchor_position[0]??0,y:w.anchor_position[1]??0}:{x:w.anchor_position.x,y:w.anchor_position.y},PA=qi(A,HA);l.strokeStyle="white",l.lineWidth=1.5,l.setLineDash([]);const bA=Math.max(4,Math.min(8,6*Math.abs(A.a)));l.beginPath(),l.moveTo(PA.x-bA,PA.y),l.lineTo(PA.x+bA,PA.y),l.stroke(),l.beginPath(),l.moveTo(PA.x,PA.y-bA),l.lineTo(PA.x,PA.y+bA),l.stroke()}})},[t,A,o,s,a,g,c,i]),Z.jsxs("div",{ref:n,style:{position:"relative",width:"100%",height:"100%"},children:[e,Z.jsx("canvas",{ref:r,style:{position:"absolute",top:0,left:0,pointerEvents:"none",zIndex:Qc.pcbGroupOverlay,display:a?"block":"none"}})]})},$8e=({transform:e,soup:A,children:t})=>{const i=zB(r=>r.is_showing_rats_nest),{netMap:n,idToNetMap:o}=AA.useMemo(()=>Ugt(A||[]),[A]),s=AA.useMemo(()=>{if(!A||!i)return[];const r=l=>{const B=Db(A)[l.replace(/_\d+$/,"")].get(l);return B&&"x"in B&&"y"in B?{x:B.x,y:B.y}:null},a=(l,B)=>{const C=n[B]||[];let E=null,Q=1/0;return C.forEach(h=>{const u=r(h);if(u){const d=Math.sqrt((l.x-u.x)**2+(l.y-u.y)**2);d<Q&&d>0&&(Q=d,E=u)}}),E},g=Db(A).pcb_port.list(),c=Db(A).source_trace.list(),I=[];return g.forEach((l,B)=>{const C=o[l.pcb_port_id];let E=!1;for(const u of c)u.connected_source_port_ids.includes(l.source_port_id)&&u.connected_source_net_ids.length>0&&(E=!0);if(!C)return;const Q={x:l.x,y:l.y},h=a(Q,C);h&&I.push({key:`${l.pcb_port_id}-${B}`,startPoint:Q,endPoint:h,isInNet:E})}),I},[A,n,o,i]);return!A||!i?t:(e||(e=yb()),Z.jsxs("div",{style:{position:"relative"},children:[t,Z.jsx("svg",{style:{position:"absolute",left:0,top:0,width:"100%",height:"100%",pointerEvents:"none",opacity:.5,zIndex:Qc.ratsNestOverlay},children:s.map(({key:r,startPoint:a,endPoint:g,isInNet:c})=>{const I=qi(e,a),l=qi(e,g);return Z.jsx("line",{x1:I.x,y1:I.y,x2:l.x,y2:l.y,stroke:"white",strokeWidth:"1",strokeDasharray:c?"6,6":void 0},r)})})]}))},AWe={version:"1.11.340"},X_=(e,A,t)=>{const i=zB(s=>s.is_mouse_over_container),n=AA.useRef(i),o=AA.useRef(A);AA.useEffect(()=>{n.current=i},[i]),AA.useEffect(()=>{o.current=A},[A]),AA.useEffect(()=>{if(!e)return;const s=r=>{const a=r.target;if(a.tagName==="INPUT"||a.tagName==="TEXTAREA"||a.isContentEditable)return;const g=e.split("+"),c=g.includes("ctrl"),I=g.includes("shift"),l=g.includes("alt"),B=g.includes("meta"),C=g[g.length-1],E=t?.current?t.current.contains(document.activeElement)||document.activeElement===t.current:!1;(n.current||E)&&(!c||r.ctrlKey)&&(!I||r.shiftKey)&&(!l||r.altKey)&&(!B||r.metaKey)&&r.key.toLowerCase()===C.toLowerCase()&&(r.preventDefault(),o.current())};return window.addEventListener("keydown",s),()=>{window.removeEventListener("keydown",s)}},[e])},tWe=()=>{const[e,A]=AA.useState(!1);return AA.useEffect(()=>{const t=()=>{A(window.innerWidth<=768)};return t(),window.addEventListener("resize",t),()=>window.removeEventListener("resize",t)},[]),e},$Y=(e,A={stopPropagation:!0})=>{const t=AA.useRef(0),i=AA.useCallback(s=>{A.stopPropagation&&s.stopPropagation();const r=Date.now();r-t.current<300||(t.current=r,e?.(s))},[e,A.stopPropagation]),n=AA.useCallback(s=>{s.preventDefault(),i(s)},[i]);return{onClick:i,onTouchEnd:n,style:{touchAction:"manipulation"}}},eWe=({name:e,selected:A,onClick:t})=>{const{style:i,...n}=$Y(t);return Z.jsxs("div",{className:jv`
5471
5471
  margin-top: 2px;
5472
5472
  padding: 4px;
5473
5473
  padding-left: 8px;
@@ -5684,7 +5684,7 @@ test("${g} should solve problem correctly", () => {
5684
5684
  // Add more specific assertions based on expected output
5685
5685
  // expect(solver.netLabelPlacementSolver!.netLabelPlacements).toMatchInlineSnapshot()
5686
5686
  })
5687
- `,I=new Blob([c],{type:"text/plain"}),l=URL.createObjectURL(I),B=document.createElement("a");B.href=l,B.download=`${g}.test.ts`,B.click(),URL.revokeObjectURL(l)}catch(a){alert(`Error generating test.ts for ${e.constructor.name}: ${a instanceof Error?a.message:String(a)}`)}i(!1)};return Z.jsxs("div",{className:`relative ${A}`,ref:n,children:[Z.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>i(!t),title:`Download options for ${e.constructor.name}`,children:e.constructor.name}),t&&Z.jsxs("div",{className:"absolute top-full left-0 mt-1 bg-white border border-gray-300 rounded shadow-lg z-10 min-w-[150px]",children:[Z.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:o,children:"Download JSON"}),Z.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),Z.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:r,children:"Download test.ts"})]})]})},uct=e=>e.activeSubSolver?[e,...uct(e.activeSubSolver)]:[e],_Ze=({solver:e})=>{const A=uct(e);return Z.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:A.map((t,i)=>Z.jsxs("div",{className:"flex items-center",children:[i>0&&Z.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),Z.jsx(xZe,{solver:t})]},t.constructor.name))})},kZe=({solver:e,triggerRender:A,animationSpeed:t=25,onSolverStarted:i,onSolverCompleted:n})=>{const[o,s]=AA.useReducer(E=>!E,!1),r=AA.useRef(void 0),a=()=>{!e.solved&&!e.failed&&(e.step(),A())},g=()=>{!e.solved&&!e.failed&&(i&&i(e),e.solve(),A(),n&&n(e))},c=()=>{o?(r.current&&(clearInterval(r.current),r.current=void 0),s()):(s(),r.current=setInterval(()=>{if(e.solved||e.failed){r.current&&(clearInterval(r.current),r.current=void 0),s(),A(),n&&e.solved&&n(e);return}e.step(),A()},t))},I=()=>{const E=e;if(E.getCurrentPhase&&!e.solved&&!e.failed){const Q=E.getCurrentPhase();for(;E.getCurrentPhase()===Q&&!e.solved&&!e.failed;)e.step();A()}},l=()=>{if(e.solved||e.failed||o)return;const E=window.prompt("Step until which iteration?",`${e.iterations}`);if(E===null)return;const Q=Number(E);if(!Number.isFinite(Q)){window.alert("Please enter a valid number for the iteration");return}for(;e.iterations<Q&&!e.solved&&!e.failed;)e.step();A(),e.solved&&n&&n(e)};AA.useEffect(()=>()=>{r.current&&clearInterval(r.current)},[]),AA.useEffect(()=>{(e.solved||e.failed)&&o&&(r.current&&(clearInterval(r.current),r.current=void 0),s())},[e.solved,e.failed,o]);const B=e.getCurrentPhase!==void 0,C=B?e.getCurrentPhase():null;return Z.jsxs("div",{className:"space-y-2 p-2 border-b",children:[Z.jsx("div",{className:"flex items-center",children:Z.jsx(_Ze,{solver:e})}),Z.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[Z.jsx("button",{onClick:a,disabled:e.solved||e.failed||o,className:"bg-blue-500 hover:bg-blue-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step"}),Z.jsx("button",{onClick:g,disabled:e.solved||e.failed||o,className:"bg-green-500 hover:bg-green-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Solve"}),Z.jsx("button",{onClick:c,disabled:e.solved||e.failed,className:`px-3 py-1 rounded text-white text-sm ${o?"bg-red-500 hover:bg-red-600":"bg-yellow-500 hover:bg-yellow-600"} disabled:bg-gray-300`,children:o?"Stop":"Animate"}),Z.jsx("button",{onClick:l,disabled:e.solved||e.failed||o,className:"bg-orange-500 hover:bg-orange-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step Until Iteration"}),B&&Z.jsx("button",{onClick:I,disabled:e.solved||e.failed||o,className:"bg-purple-500 hover:bg-purple-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Next Stage"}),Z.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",e.iterations]}),e.timeToSolve!==void 0&&Z.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(e.timeToSolve/1e3).toFixed(3),"s"]}),C&&Z.jsxs("div",{className:"text-sm text-gray-600",children:["Phase: ",Z.jsx("span",{className:"font-medium",children:C})]}),e.solved&&Z.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),e.failed&&Z.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),e.error&&Z.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",e.error]})]})},FZe=(e,A,t)=>{const i=e.currentPipelineStepIndex;return A<i?"Completed":A===i&&e.activeSubSolver?e.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},GZe=(e,A)=>{const i=e.pipelineDef[A].solverName,n=FZe(e,A),o=e[i],s=e.firstIterationOfPhase?.[i]??null,r=e.iterations;let a=0;if(n==="Completed"){const l=e.pipelineDef[A+1],B=l?e.firstIterationOfPhase?.[l.solverName]:void 0;B!==void 0&&s!==null?a=B-s:s!==null&&(a=r-s)}else n==="In Progress"&&s!==null&&(a=r-s);const g=e.timeSpentOnPhase?.[i]??0;let c=0;n==="Completed"?c=1:n==="In Progress"&&o&&(c=o.progress??0);const I=o?.stats??null;return{index:A,name:i,status:n,firstIteration:s,iterations:a,progress:c,timeSpent:g,stats:I&&Object.keys(I).length>0?I:null,solverInstance:o??null}},MZe=({status:e})=>{const A={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return Z.jsx("span",{className:`font-medium ${A[e]}`,children:e})},RZe=({progress:e})=>{if(e===0)return null;const A=Math.round(e*100);return Z.jsxs("div",{className:"flex items-center gap-2",children:[Z.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:Z.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${A}%`}})}),Z.jsxs("span",{className:"text-xs text-gray-500",children:[A,"%"]})]})},NZe=e=>Object.entries(e).map(([A,t])=>`${A}: ${t}`).join(", "),vZe=({stats:e})=>{if(!e||Object.keys(e).length===0)return Z.jsx("span",{children:"-"});const A=Object.entries(e),t=NZe(e);return Z.jsxs("details",{className:"cursor-pointer",children:[Z.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:t}),Z.jsx("div",{className:"mt-1 text-xs",children:A.map(([i,n])=>Z.jsxs("div",{children:[i,": ",String(n)]},i))})]})},zpA=e=>{if(e===null||typeof e!="object")return e;if(Array.isArray(e))return e.map(zpA);const A={};for(const[t,i]of Object.entries(e))t.startsWith("_")||(A[t]=zpA(i));return A},LZe=(e,A)=>{try{if(typeof e.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${A}`);return}const t=zpA(e.getConstructorParams()),i=new Blob([JSON.stringify(t,null,2)],{type:"application/json"}),n=URL.createObjectURL(i),o=document.createElement("a");o.href=n,o.download=`${A}_input.json`,o.click(),URL.revokeObjectURL(n)}catch(t){alert(`Error downloading input for ${A}: ${t instanceof Error?t.message:String(t)}`)}},UZe=({solver:e,onStepUntilPhase:A,onDownloadInput:t})=>{const i=e.pipelineDef.map((r,a)=>GZe(e,a)),n=r=>{A?.(r)},o=r=>{r.solverInstance&&(t?t(r.solverInstance,r.name):LZe(r.solverInstance,r.name))},s=r=>`${(r/1e3).toFixed(2)}s`;return Z.jsxs("div",{className:"border-t border-gray-200",children:[Z.jsx("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200",children:Z.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Steps"})}),Z.jsx("div",{className:"overflow-x-auto",children:Z.jsxs("table",{className:"w-full text-sm",children:[Z.jsx("thead",{children:Z.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Step"}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),Z.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",Z.jsx("sub",{children:"0"})]}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),Z.jsx("tbody",{children:i.map(r=>Z.jsxs("tr",{className:`border-b border-gray-100 ${r.status==="In Progress"?"bg-yellow-50":""}`,children:[Z.jsx("td",{className:"px-4 py-2",children:Z.jsxs("div",{className:"flex items-center gap-2",children:[Z.jsx("span",{className:"text-gray-400 w-6",children:String(r.index+1).padStart(2,"0")}),Z.jsx("button",{onClick:()=>n(r.name),disabled:r.status==="Completed"||e.solved||e.failed,className:"text-blue-500 hover:text-blue-700 disabled:text-gray-300 disabled:cursor-not-allowed",title:`Step until ${r.name} completes`,children:Z.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:Z.jsx("path",{fillRule:"evenodd",d:"M4.5 5.653c0-1.426 1.529-2.33 2.779-1.643l11.54 6.348c1.295.712 1.295 2.573 0 3.285L7.28 19.991c-1.25.687-2.779-.217-2.779-1.643V5.653z",clipRule:"evenodd"})})}),Z.jsx("span",{className:"font-medium text-gray-900",children:r.name})]})}),Z.jsx("td",{className:"px-4 py-2",children:Z.jsx(MZe,{status:r.status})}),Z.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:r.firstIteration!==null?r.firstIteration:""}),Z.jsx("td",{className:"px-4 py-2 text-gray-600",children:r.iterations}),Z.jsx("td",{className:"px-4 py-2",children:Z.jsx(RZe,{progress:r.progress})}),Z.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(r.timeSpent)}),Z.jsx("td",{className:"px-4 py-2 text-gray-500",children:Z.jsx(vZe,{stats:r.stats})}),Z.jsx("td",{className:"px-4 py-2",children:r.solverInstance?Z.jsxs("button",{onClick:()=>o(r),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${r.name}`,children:[Z.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:Z.jsx("path",{fillRule:"evenodd",d:"M12 2.25a.75.75 0 01.75.75v11.69l3.22-3.22a.75.75 0 111.06 1.06l-4.5 4.5a.75.75 0 01-1.06 0l-4.5-4.5a.75.75 0 111.06-1.06l3.22 3.22V3a.75.75 0 01.75-.75zm-9 13.5a.75.75 0 01.75.75v2.25a1.5 1.5 0 001.5 1.5h13.5a1.5 1.5 0 001.5-1.5V16.5a.75.75 0 011.5 0v2.25a3 3 0 01-3 3H5.25a3 3 0 01-3-3V16.5a.75.75 0 01.75-.75z",clipRule:"evenodd"})}),Z.jsx("span",{children:"Input"})]}):null})]},r.name))})]})})]})},HZe=class extends nn.Component{constructor(e){super(e),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(e){console.error("InteractiveGraphics render error:",e)}render(){return this.state.hasError?this.props.fallback:this.props.children}};function YZe({graphics:e}){const A=e.points??[],t=e.lines??[],i=e.rects??[],n=e.circles??[],o=e.texts??[];let s=Number.POSITIVE_INFINITY,r=Number.POSITIVE_INFINITY,a=Number.NEGATIVE_INFINITY,g=Number.NEGATIVE_INFINITY;const c=(Q,h)=>{typeof Q=="number"&&(Q<s&&(s=Q),Q>a&&(a=Q)),typeof h=="number"&&(h<r&&(r=h),h>g&&(g=h))};for(const Q of A)c(Q.x,Q.y);for(const Q of t){const h=Q.points??[];for(const u of h)c(u.x,u.y)}for(const Q of i){const h=Q.x??0,u=Q.y??0,d=Q.width??0,f=Q.height??0;c(h,u),c(h+d,u+f)}for(const Q of n){const h=Q.x??0,u=Q.y??0,d=Q.radius??1;c(h-d,u-d),c(h+d,u+d)}for(const Q of o)c(Q.x,Q.y);(!isFinite(s)||!isFinite(r)||!isFinite(a)||!isFinite(g))&&(s=-20,r=-20,a=20,g=20);const I=10,l=s-I,B=r-I,C=Math.max(1,a-s+2*I),E=Math.max(1,g-r+2*I);return Z.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${l} ${B} ${C} ${E}`,role:"img","aria-label":"Graphics fallback",children:[i.map((Q,h)=>Z.jsx("rect",{x:Q.x??0,y:Q.y??0,width:Q.width??0,height:Q.height??0,fill:"none",stroke:Q.strokeColor??"black",strokeWidth:Q.strokeWidth??1},`rect-${h}`)),t.map((Q,h)=>Z.jsx("polyline",{fill:"none",stroke:Q.strokeColor??"black",strokeWidth:Q.strokeWidth??1,points:(Q.points??[]).map(u=>`${u.x??0},${u.y??0}`).join(" ")},`line-${h}`)),n.map((Q,h)=>Z.jsx("circle",{cx:Q.x??0,cy:Q.y??0,r:Q.radius??1.5,fill:Q.fillColor??"none",stroke:Q.strokeColor??"black",strokeWidth:Q.strokeWidth??1},`circle-${h}`)),A.map((Q,h)=>Z.jsx("circle",{cx:Q.x??0,cy:Q.y??0,r:Q.radius??1.5,fill:Q.color??"black"},`point-${h}`)),o.map((Q,h)=>Z.jsx("text",{x:Q.x??0,y:Q.y??0,fontSize:Q.fontSize??10,fill:Q.color??"black",children:Q.text??""},`text-${h}`))]})}var JZe=({solver:e,animationSpeed:A=25,onSolverStarted:t,onSolverCompleted:i})=>{const[n,o]=AA.useReducer(c=>c+1,0),s=AA.useMemo(()=>{try{return e.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(c){return console.error("Visualization error:",c),{points:[],lines:[],rects:[],circles:[]}}},[e,n]),r=AA.useMemo(()=>(s.rects?.length||0)===0&&(s.lines?.length||0)===0&&(s.points?.length||0)===0&&(s.circles?.length||0)===0,[s]);AA.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const c=document.createElement("script");c.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(c)}},[]);const a=e.pipelineDef!==void 0,g=c=>{const I=e;if(!e.solved&&!e.failed){for(;!e.solved&&!e.failed&&I.currentPipelineStepIndex<=I.pipelineDef.findIndex(l=>l.solverName===c);)e.step();o()}};return Z.jsxs("div",{children:[Z.jsx(kZe,{solver:e,triggerRender:o,animationSpeed:A,onSolverStarted:t,onSolverCompleted:i}),r?Z.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):Z.jsx(HZe,{fallback:Z.jsx(YZe,{graphics:s}),children:Z.jsx(bZe,{graphics:s})}),a&&Z.jsx(UZe,{solver:e,onStepUntilPhase:g})]})};const TZe=()=>{AA.useEffect(()=>{const e="tailwind-cdn-script";if(document.getElementById(e)||window.tailwind)return;const A=document.createElement("div");A.className="hidden",document.body.appendChild(A);const t=window.getComputedStyle(A).display==="none";if(document.body.removeChild(A),t)return;const i=document.createElement("script");i.id=e,i.src="https://cdn.tailwindcss.com",document.head.appendChild(i)},[])},KZe=e=>e.toLowerCase().includes("pack")?bGe:e.toLowerCase().includes("rout")?MGe:uGe,PZe=({solverEvents:e=[]})=>{const[A,t]=AA.useState(null);TZe();const i=AA.useMemo(()=>{const r=new Map;for(const a of e){const g=`${a.componentName}-${a.solverName}`;r.set(g,a)}return r},[e]),n=AA.useMemo(()=>Array.from(i.keys()),[i]),o=A?i.get(A):null,s=AA.useMemo(()=>{if(!o)return{instance:null,error:null,classFound:!1};const r=rrA[o.solverName];if(!r)return{instance:null,error:`Solver class "${o.solverName}" not found in SOLVERS registry. Available: ${Object.keys(rrA).join(", ")}`,classFound:!1};try{const a=o.solverParams,g=a?.input!==void 0?a.input:a;return{instance:new r(g),error:null,classFound:!0}}catch(a){const g=a instanceof Error?a.message:String(a);return console.error("Failed to reconstruct solver:",a),{instance:null,error:`Failed to instantiate solver: ${g}`,classFound:!0}}},[o]);return e.length===0?Z.jsx("div",{className:"rf-p-4",children:Z.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:Z.jsxs("div",{className:"rf-p-4",children:[Z.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),Z.jsx("p",{className:"rf-text-sm rf-text-gray-600",children:"Solvers will appear here when the circuit runs. Solvers are used for tasks like component packing and autorouting."})]})})}):Z.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[Z.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[Z.jsxs("div",{className:"rf-text-xs rf-font-semibold rf-text-gray-500 rf-px-3 rf-py-2 rf-bg-gray-50 rf-border-b rf-border-gray-200",children:[n.length," ",n.length===1?"Solver":"Solvers"]}),n.map(r=>{const a=i.get(r),g=A===r;return Z.jsx("div",{className:`rf-px-3 rf-py-2 rf-cursor-pointer rf-border-b rf-border-gray-100 ${g?"rf-bg-blue-50 rf-border-l-2 rf-border-l-blue-500":"hover:rf-bg-gray-50"}`,onClick:()=>t(r),children:(()=>{const c=KZe(a.solverName);return Z.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[Z.jsx(c,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),Z.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[Z.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:a.componentName}),Z.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:a.solverName})]})]})})()},r)})]}),Z.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:o?s.instance?Z.jsx(pD,{fallback:Z.jsx("div",{className:"rf-p-4",children:Z.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[Z.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),Z.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",o.solverName]})]})}),children:Z.jsx(JZe,{solver:s.instance})}):Z.jsxs("div",{className:"rf-p-4",children:[Z.jsxs("div",{className:"rf-mb-4",children:[Z.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:o.solverName}),Z.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",o.componentName]})]}),s.error&&Z.jsx("div",{className:`rf-rounded-md rf-border rf-p-4 rf-mb-4 ${s.classFound?"rf-bg-red-50 rf-border-red-200":"rf-bg-yellow-50 rf-border-yellow-200"}`,children:Z.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),Z.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[Z.jsx("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50",children:Z.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"})}),Z.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:Z.jsx("pre",{className:"rf-text-xs rf-font-mono rf-text-gray-600 rf-whitespace-pre-wrap rf-overflow-x-auto",children:JSON.stringify(o.solverParams,null,2)})})]})]}):Z.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:Z.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},dct=({errorMessage:e,errorStack:A,circuitJsonErrors:t})=>{AA.useEffect(()=>{if(e){const i=new Error(e);A&&(i.stack=A);try{LK.captureException(i)}catch{}}},[e,A]),AA.useEffect(()=>{if(t&&t.length>0)for(const i of t){const n=new Error(i.message||"Circuit JSON Error");i.stack&&(n.stack=i.stack);try{LK.captureException(n,{error_type:i.type})}catch{}}},[t])},pct="0.0.1629",qZe={version:pct},XpA={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1},$pA=new Map,l9=e=>{const A=$pA.get(e);return A?Object.fromEntries(Object.entries(A.stores).map(([t,i])=>[t,i.getState()])):{}},OZe=(e,A,t)=>{if(e===void 0)return{type:"untracked",connection:A.connect(t)};const i=$pA.get(t.name);if(i)return{type:"tracked",store:e,...i};const n={connection:A.connect(t),stores:{}};return $pA.set(t.name,n),{type:"tracked",store:e,...n}},fct=(e,A={})=>(t,i,n)=>{const{enabled:o,anonymousActionType:s,store:r,...a}=A;let g;try{g=(o??(XpA?"production":void 0)!=="production")&&window.__REDUX_DEVTOOLS_EXTENSION__}catch{}if(!g)return(XpA?"production":void 0)!=="production"&&o&&console.warn("[zustand devtools middleware] Please install/enable Redux devtools extension"),e(t,i,n);const{connection:c,...I}=OZe(r,g,a);let l=!0;n.setState=(E,Q,h)=>{const u=t(E,Q);if(!l)return u;const d=h===void 0?{type:s||"anonymous"}:typeof h=="string"?{type:h}:h;return r===void 0?(c?.send(d,i()),u):(c?.send({...d,type:`${r}/${d.type}`},{...l9(a.name),[r]:n.getState()}),u)};const B=(...E)=>{const Q=l;l=!1,t(...E),l=Q},C=e(n.setState,i,n);if(I.type==="untracked"?c?.init(C):(I.stores[I.store]=n,c?.init(Object.fromEntries(Object.entries(I.stores).map(([E,Q])=>[E,E===I.store?C:Q.getState()])))),n.dispatchFromDevtools&&typeof n.dispatch=="function"){let E=!1;const Q=n.dispatch;n.dispatch=(...h)=>{(XpA?"production":void 0)!=="production"&&h[0].type==="__setState"&&!E&&(console.warn('[zustand devtools middleware] "__setState" action type is reserved to set state from the devtools. Avoid using it.'),E=!0),Q(...h)}}return c.subscribe(E=>{var Q;switch(E.type){case"ACTION":if(typeof E.payload!="string"){console.error("[zustand devtools middleware] Unsupported action format");return}return AfA(E.payload,h=>{if(h.type==="__setState"){if(r===void 0){B(h.state);return}Object.keys(h.state).length!==1&&console.error(`
5687
+ `,I=new Blob([c],{type:"text/plain"}),l=URL.createObjectURL(I),B=document.createElement("a");B.href=l,B.download=`${g}.test.ts`,B.click(),URL.revokeObjectURL(l)}catch(a){alert(`Error generating test.ts for ${e.constructor.name}: ${a instanceof Error?a.message:String(a)}`)}i(!1)};return Z.jsxs("div",{className:`relative ${A}`,ref:n,children:[Z.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>i(!t),title:`Download options for ${e.constructor.name}`,children:e.constructor.name}),t&&Z.jsxs("div",{className:"absolute top-full left-0 mt-1 bg-white border border-gray-300 rounded shadow-lg z-10 min-w-[150px]",children:[Z.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:o,children:"Download JSON"}),Z.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),Z.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:r,children:"Download test.ts"})]})]})},uct=e=>e.activeSubSolver?[e,...uct(e.activeSubSolver)]:[e],_Ze=({solver:e})=>{const A=uct(e);return Z.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:A.map((t,i)=>Z.jsxs("div",{className:"flex items-center",children:[i>0&&Z.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),Z.jsx(xZe,{solver:t})]},t.constructor.name))})},kZe=({solver:e,triggerRender:A,animationSpeed:t=25,onSolverStarted:i,onSolverCompleted:n})=>{const[o,s]=AA.useReducer(E=>!E,!1),r=AA.useRef(void 0),a=()=>{!e.solved&&!e.failed&&(e.step(),A())},g=()=>{!e.solved&&!e.failed&&(i&&i(e),e.solve(),A(),n&&n(e))},c=()=>{o?(r.current&&(clearInterval(r.current),r.current=void 0),s()):(s(),r.current=setInterval(()=>{if(e.solved||e.failed){r.current&&(clearInterval(r.current),r.current=void 0),s(),A(),n&&e.solved&&n(e);return}e.step(),A()},t))},I=()=>{const E=e;if(E.getCurrentPhase&&!e.solved&&!e.failed){const Q=E.getCurrentPhase();for(;E.getCurrentPhase()===Q&&!e.solved&&!e.failed;)e.step();A()}},l=()=>{if(e.solved||e.failed||o)return;const E=window.prompt("Step until which iteration?",`${e.iterations}`);if(E===null)return;const Q=Number(E);if(!Number.isFinite(Q)){window.alert("Please enter a valid number for the iteration");return}for(;e.iterations<Q&&!e.solved&&!e.failed;)e.step();A(),e.solved&&n&&n(e)};AA.useEffect(()=>()=>{r.current&&clearInterval(r.current)},[]),AA.useEffect(()=>{(e.solved||e.failed)&&o&&(r.current&&(clearInterval(r.current),r.current=void 0),s())},[e.solved,e.failed,o]);const B=e.getCurrentPhase!==void 0,C=B?e.getCurrentPhase():null;return Z.jsxs("div",{className:"space-y-2 p-2 border-b",children:[Z.jsx("div",{className:"flex items-center",children:Z.jsx(_Ze,{solver:e})}),Z.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[Z.jsx("button",{onClick:a,disabled:e.solved||e.failed||o,className:"bg-blue-500 hover:bg-blue-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step"}),Z.jsx("button",{onClick:g,disabled:e.solved||e.failed||o,className:"bg-green-500 hover:bg-green-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Solve"}),Z.jsx("button",{onClick:c,disabled:e.solved||e.failed,className:`px-3 py-1 rounded text-white text-sm ${o?"bg-red-500 hover:bg-red-600":"bg-yellow-500 hover:bg-yellow-600"} disabled:bg-gray-300`,children:o?"Stop":"Animate"}),Z.jsx("button",{onClick:l,disabled:e.solved||e.failed||o,className:"bg-orange-500 hover:bg-orange-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step Until Iteration"}),B&&Z.jsx("button",{onClick:I,disabled:e.solved||e.failed||o,className:"bg-purple-500 hover:bg-purple-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Next Stage"}),Z.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",e.iterations]}),e.timeToSolve!==void 0&&Z.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(e.timeToSolve/1e3).toFixed(3),"s"]}),C&&Z.jsxs("div",{className:"text-sm text-gray-600",children:["Phase: ",Z.jsx("span",{className:"font-medium",children:C})]}),e.solved&&Z.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),e.failed&&Z.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),e.error&&Z.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",e.error]})]})},FZe=(e,A,t)=>{const i=e.currentPipelineStepIndex;return A<i?"Completed":A===i&&e.activeSubSolver?e.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},GZe=(e,A)=>{const i=e.pipelineDef[A].solverName,n=FZe(e,A),o=e[i],s=e.firstIterationOfPhase?.[i]??null,r=e.iterations;let a=0;if(n==="Completed"){const l=e.pipelineDef[A+1],B=l?e.firstIterationOfPhase?.[l.solverName]:void 0;B!==void 0&&s!==null?a=B-s:s!==null&&(a=r-s)}else n==="In Progress"&&s!==null&&(a=r-s);const g=e.timeSpentOnPhase?.[i]??0;let c=0;n==="Completed"?c=1:n==="In Progress"&&o&&(c=o.progress??0);const I=o?.stats??null;return{index:A,name:i,status:n,firstIteration:s,iterations:a,progress:c,timeSpent:g,stats:I&&Object.keys(I).length>0?I:null,solverInstance:o??null}},MZe=({status:e})=>{const A={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return Z.jsx("span",{className:`font-medium ${A[e]}`,children:e})},RZe=({progress:e})=>{if(e===0)return null;const A=Math.round(e*100);return Z.jsxs("div",{className:"flex items-center gap-2",children:[Z.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:Z.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${A}%`}})}),Z.jsxs("span",{className:"text-xs text-gray-500",children:[A,"%"]})]})},NZe=e=>Object.entries(e).map(([A,t])=>`${A}: ${t}`).join(", "),vZe=({stats:e})=>{if(!e||Object.keys(e).length===0)return Z.jsx("span",{children:"-"});const A=Object.entries(e),t=NZe(e);return Z.jsxs("details",{className:"cursor-pointer",children:[Z.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:t}),Z.jsx("div",{className:"mt-1 text-xs",children:A.map(([i,n])=>Z.jsxs("div",{children:[i,": ",String(n)]},i))})]})},zpA=e=>{if(e===null||typeof e!="object")return e;if(Array.isArray(e))return e.map(zpA);const A={};for(const[t,i]of Object.entries(e))t.startsWith("_")||(A[t]=zpA(i));return A},LZe=(e,A)=>{try{if(typeof e.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${A}`);return}const t=zpA(e.getConstructorParams()),i=new Blob([JSON.stringify(t,null,2)],{type:"application/json"}),n=URL.createObjectURL(i),o=document.createElement("a");o.href=n,o.download=`${A}_input.json`,o.click(),URL.revokeObjectURL(n)}catch(t){alert(`Error downloading input for ${A}: ${t instanceof Error?t.message:String(t)}`)}},UZe=({solver:e,onStepUntilPhase:A,onDownloadInput:t})=>{const i=e.pipelineDef.map((r,a)=>GZe(e,a)),n=r=>{A?.(r)},o=r=>{r.solverInstance&&(t?t(r.solverInstance,r.name):LZe(r.solverInstance,r.name))},s=r=>`${(r/1e3).toFixed(2)}s`;return Z.jsxs("div",{className:"border-t border-gray-200",children:[Z.jsx("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200",children:Z.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Steps"})}),Z.jsx("div",{className:"overflow-x-auto",children:Z.jsxs("table",{className:"w-full text-sm",children:[Z.jsx("thead",{children:Z.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Step"}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),Z.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",Z.jsx("sub",{children:"0"})]}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),Z.jsx("tbody",{children:i.map(r=>Z.jsxs("tr",{className:`border-b border-gray-100 ${r.status==="In Progress"?"bg-yellow-50":""}`,children:[Z.jsx("td",{className:"px-4 py-2",children:Z.jsxs("div",{className:"flex items-center gap-2",children:[Z.jsx("span",{className:"text-gray-400 w-6",children:String(r.index+1).padStart(2,"0")}),Z.jsx("button",{onClick:()=>n(r.name),disabled:r.status==="Completed"||e.solved||e.failed,className:"text-blue-500 hover:text-blue-700 disabled:text-gray-300 disabled:cursor-not-allowed",title:`Step until ${r.name} completes`,children:Z.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:Z.jsx("path",{fillRule:"evenodd",d:"M4.5 5.653c0-1.426 1.529-2.33 2.779-1.643l11.54 6.348c1.295.712 1.295 2.573 0 3.285L7.28 19.991c-1.25.687-2.779-.217-2.779-1.643V5.653z",clipRule:"evenodd"})})}),Z.jsx("span",{className:"font-medium text-gray-900",children:r.name})]})}),Z.jsx("td",{className:"px-4 py-2",children:Z.jsx(MZe,{status:r.status})}),Z.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:r.firstIteration!==null?r.firstIteration:""}),Z.jsx("td",{className:"px-4 py-2 text-gray-600",children:r.iterations}),Z.jsx("td",{className:"px-4 py-2",children:Z.jsx(RZe,{progress:r.progress})}),Z.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(r.timeSpent)}),Z.jsx("td",{className:"px-4 py-2 text-gray-500",children:Z.jsx(vZe,{stats:r.stats})}),Z.jsx("td",{className:"px-4 py-2",children:r.solverInstance?Z.jsxs("button",{onClick:()=>o(r),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${r.name}`,children:[Z.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:Z.jsx("path",{fillRule:"evenodd",d:"M12 2.25a.75.75 0 01.75.75v11.69l3.22-3.22a.75.75 0 111.06 1.06l-4.5 4.5a.75.75 0 01-1.06 0l-4.5-4.5a.75.75 0 111.06-1.06l3.22 3.22V3a.75.75 0 01.75-.75zm-9 13.5a.75.75 0 01.75.75v2.25a1.5 1.5 0 001.5 1.5h13.5a1.5 1.5 0 001.5-1.5V16.5a.75.75 0 011.5 0v2.25a3 3 0 01-3 3H5.25a3 3 0 01-3-3V16.5a.75.75 0 01.75-.75z",clipRule:"evenodd"})}),Z.jsx("span",{children:"Input"})]}):null})]},r.name))})]})})]})},HZe=class extends nn.Component{constructor(e){super(e),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(e){console.error("InteractiveGraphics render error:",e)}render(){return this.state.hasError?this.props.fallback:this.props.children}};function YZe({graphics:e}){const A=e.points??[],t=e.lines??[],i=e.rects??[],n=e.circles??[],o=e.texts??[];let s=Number.POSITIVE_INFINITY,r=Number.POSITIVE_INFINITY,a=Number.NEGATIVE_INFINITY,g=Number.NEGATIVE_INFINITY;const c=(Q,h)=>{typeof Q=="number"&&(Q<s&&(s=Q),Q>a&&(a=Q)),typeof h=="number"&&(h<r&&(r=h),h>g&&(g=h))};for(const Q of A)c(Q.x,Q.y);for(const Q of t){const h=Q.points??[];for(const u of h)c(u.x,u.y)}for(const Q of i){const h=Q.x??0,u=Q.y??0,d=Q.width??0,f=Q.height??0;c(h,u),c(h+d,u+f)}for(const Q of n){const h=Q.x??0,u=Q.y??0,d=Q.radius??1;c(h-d,u-d),c(h+d,u+d)}for(const Q of o)c(Q.x,Q.y);(!isFinite(s)||!isFinite(r)||!isFinite(a)||!isFinite(g))&&(s=-20,r=-20,a=20,g=20);const I=10,l=s-I,B=r-I,C=Math.max(1,a-s+2*I),E=Math.max(1,g-r+2*I);return Z.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${l} ${B} ${C} ${E}`,role:"img","aria-label":"Graphics fallback",children:[i.map((Q,h)=>Z.jsx("rect",{x:Q.x??0,y:Q.y??0,width:Q.width??0,height:Q.height??0,fill:"none",stroke:Q.strokeColor??"black",strokeWidth:Q.strokeWidth??1},`rect-${h}`)),t.map((Q,h)=>Z.jsx("polyline",{fill:"none",stroke:Q.strokeColor??"black",strokeWidth:Q.strokeWidth??1,points:(Q.points??[]).map(u=>`${u.x??0},${u.y??0}`).join(" ")},`line-${h}`)),n.map((Q,h)=>Z.jsx("circle",{cx:Q.x??0,cy:Q.y??0,r:Q.radius??1.5,fill:Q.fillColor??"none",stroke:Q.strokeColor??"black",strokeWidth:Q.strokeWidth??1},`circle-${h}`)),A.map((Q,h)=>Z.jsx("circle",{cx:Q.x??0,cy:Q.y??0,r:Q.radius??1.5,fill:Q.color??"black"},`point-${h}`)),o.map((Q,h)=>Z.jsx("text",{x:Q.x??0,y:Q.y??0,fontSize:Q.fontSize??10,fill:Q.color??"black",children:Q.text??""},`text-${h}`))]})}var JZe=({solver:e,animationSpeed:A=25,onSolverStarted:t,onSolverCompleted:i})=>{const[n,o]=AA.useReducer(c=>c+1,0),s=AA.useMemo(()=>{try{return e.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(c){return console.error("Visualization error:",c),{points:[],lines:[],rects:[],circles:[]}}},[e,n]),r=AA.useMemo(()=>(s.rects?.length||0)===0&&(s.lines?.length||0)===0&&(s.points?.length||0)===0&&(s.circles?.length||0)===0,[s]);AA.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const c=document.createElement("script");c.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(c)}},[]);const a=e.pipelineDef!==void 0,g=c=>{const I=e;if(!e.solved&&!e.failed){for(;!e.solved&&!e.failed&&I.currentPipelineStepIndex<=I.pipelineDef.findIndex(l=>l.solverName===c);)e.step();o()}};return Z.jsxs("div",{children:[Z.jsx(kZe,{solver:e,triggerRender:o,animationSpeed:A,onSolverStarted:t,onSolverCompleted:i}),r?Z.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):Z.jsx(HZe,{fallback:Z.jsx(YZe,{graphics:s}),children:Z.jsx(bZe,{graphics:s})}),a&&Z.jsx(UZe,{solver:e,onStepUntilPhase:g})]})};const TZe=()=>{AA.useEffect(()=>{const e="tailwind-cdn-script";if(document.getElementById(e)||window.tailwind)return;const A=document.createElement("div");A.className="hidden",document.body.appendChild(A);const t=window.getComputedStyle(A).display==="none";if(document.body.removeChild(A),t)return;const i=document.createElement("script");i.id=e,i.src="https://cdn.tailwindcss.com",document.head.appendChild(i)},[])},KZe=e=>e.toLowerCase().includes("pack")?bGe:e.toLowerCase().includes("rout")?MGe:uGe,PZe=({solverEvents:e=[]})=>{const[A,t]=AA.useState(null);TZe();const i=AA.useMemo(()=>{const r=new Map;for(const a of e){const g=`${a.componentName}-${a.solverName}`;r.set(g,a)}return r},[e]),n=AA.useMemo(()=>Array.from(i.keys()),[i]),o=A?i.get(A):null,s=AA.useMemo(()=>{if(!o)return{instance:null,error:null,classFound:!1};const r=rrA[o.solverName];if(!r)return{instance:null,error:`Solver class "${o.solverName}" not found in SOLVERS registry. Available: ${Object.keys(rrA).join(", ")}`,classFound:!1};try{const a=o.solverParams,g=a?.input!==void 0?a.input:a;return{instance:new r(g),error:null,classFound:!0}}catch(a){const g=a instanceof Error?a.message:String(a);return console.error("Failed to reconstruct solver:",a),{instance:null,error:`Failed to instantiate solver: ${g}`,classFound:!0}}},[o]);return e.length===0?Z.jsx("div",{className:"rf-p-4",children:Z.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:Z.jsxs("div",{className:"rf-p-4",children:[Z.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),Z.jsx("p",{className:"rf-text-sm rf-text-gray-600",children:"Solvers will appear here when the circuit runs. Solvers are used for tasks like component packing and autorouting."})]})})}):Z.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[Z.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[Z.jsxs("div",{className:"rf-text-xs rf-font-semibold rf-text-gray-500 rf-px-3 rf-py-2 rf-bg-gray-50 rf-border-b rf-border-gray-200",children:[n.length," ",n.length===1?"Solver":"Solvers"]}),n.map(r=>{const a=i.get(r),g=A===r;return Z.jsx("div",{className:`rf-px-3 rf-py-2 rf-cursor-pointer rf-border-b rf-border-gray-100 ${g?"rf-bg-blue-50 rf-border-l-2 rf-border-l-blue-500":"hover:rf-bg-gray-50"}`,onClick:()=>t(r),children:(()=>{const c=KZe(a.solverName);return Z.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[Z.jsx(c,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),Z.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[Z.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:a.componentName}),Z.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:a.solverName})]})]})})()},r)})]}),Z.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:o?s.instance?Z.jsx(pD,{fallback:Z.jsx("div",{className:"rf-p-4",children:Z.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[Z.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),Z.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",o.solverName]})]})}),children:Z.jsx(JZe,{solver:s.instance})}):Z.jsxs("div",{className:"rf-p-4",children:[Z.jsxs("div",{className:"rf-mb-4",children:[Z.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:o.solverName}),Z.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",o.componentName]})]}),s.error&&Z.jsx("div",{className:`rf-rounded-md rf-border rf-p-4 rf-mb-4 ${s.classFound?"rf-bg-red-50 rf-border-red-200":"rf-bg-yellow-50 rf-border-yellow-200"}`,children:Z.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),Z.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[Z.jsx("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50",children:Z.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"})}),Z.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:Z.jsx("pre",{className:"rf-text-xs rf-font-mono rf-text-gray-600 rf-whitespace-pre-wrap rf-overflow-x-auto",children:JSON.stringify(o.solverParams,null,2)})})]})]}):Z.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:Z.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},dct=({errorMessage:e,errorStack:A,circuitJsonErrors:t})=>{AA.useEffect(()=>{if(e){const i=new Error(e);A&&(i.stack=A);try{LK.captureException(i)}catch{}}},[e,A]),AA.useEffect(()=>{if(t&&t.length>0)for(const i of t){const n=new Error(i.message||"Circuit JSON Error");i.stack&&(n.stack=i.stack);try{LK.captureException(n,{error_type:i.type})}catch{}}},[t])},pct="0.0.1630",qZe={version:pct},XpA={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1},$pA=new Map,l9=e=>{const A=$pA.get(e);return A?Object.fromEntries(Object.entries(A.stores).map(([t,i])=>[t,i.getState()])):{}},OZe=(e,A,t)=>{if(e===void 0)return{type:"untracked",connection:A.connect(t)};const i=$pA.get(t.name);if(i)return{type:"tracked",store:e,...i};const n={connection:A.connect(t),stores:{}};return $pA.set(t.name,n),{type:"tracked",store:e,...n}},fct=(e,A={})=>(t,i,n)=>{const{enabled:o,anonymousActionType:s,store:r,...a}=A;let g;try{g=(o??(XpA?"production":void 0)!=="production")&&window.__REDUX_DEVTOOLS_EXTENSION__}catch{}if(!g)return(XpA?"production":void 0)!=="production"&&o&&console.warn("[zustand devtools middleware] Please install/enable Redux devtools extension"),e(t,i,n);const{connection:c,...I}=OZe(r,g,a);let l=!0;n.setState=(E,Q,h)=>{const u=t(E,Q);if(!l)return u;const d=h===void 0?{type:s||"anonymous"}:typeof h=="string"?{type:h}:h;return r===void 0?(c?.send(d,i()),u):(c?.send({...d,type:`${r}/${d.type}`},{...l9(a.name),[r]:n.getState()}),u)};const B=(...E)=>{const Q=l;l=!1,t(...E),l=Q},C=e(n.setState,i,n);if(I.type==="untracked"?c?.init(C):(I.stores[I.store]=n,c?.init(Object.fromEntries(Object.entries(I.stores).map(([E,Q])=>[E,E===I.store?C:Q.getState()])))),n.dispatchFromDevtools&&typeof n.dispatch=="function"){let E=!1;const Q=n.dispatch;n.dispatch=(...h)=>{(XpA?"production":void 0)!=="production"&&h[0].type==="__setState"&&!E&&(console.warn('[zustand devtools middleware] "__setState" action type is reserved to set state from the devtools. Avoid using it.'),E=!0),Q(...h)}}return c.subscribe(E=>{var Q;switch(E.type){case"ACTION":if(typeof E.payload!="string"){console.error("[zustand devtools middleware] Unsupported action format");return}return AfA(E.payload,h=>{if(h.type==="__setState"){if(r===void 0){B(h.state);return}Object.keys(h.state).length!==1&&console.error(`
5688
5688
  [zustand devtools middleware] Unsupported __setState action format.
5689
5689
  When using 'store' option in devtools(), the 'state' should have only one key, which is a value of 'store' that was passed in devtools(),
5690
5690
  and value of this only key should be a state object. Example: { "type": "__setState", "state": { "abc123Store": { "foo": "bar" } } }