@tscircuit/runframe 0.0.1763 → 0.0.1765
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.
|
@@ -5429,7 +5429,7 @@ You passed in: '`+this.raw_options[o]+"'");return a},t.prototype._is_valid_selec
|
|
|
5429
5429
|
`);break}}return s}}}),oXe=Qa({"node_modules/pretty/index.js"(e,A){var t=$ze(),i=nXe(),n=mQt(),o={unformatted:["code","pre","em","strong","span"],indent_inner_html:!0,indent_char:" ",indent_size:2,sep:`
|
|
5430
5430
|
`};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,`
|
|
5431
5431
|
`).replace(/(\s*<!--)/g,`
|
|
5432
|
-
$1`).replace(/>(\s*)(?=<!--\s*\/)/g,"> ")}}});function wQt(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 sXe(e,A){if(!A.subcircuit_id&&!A.source_group_id)return[...e];let t=A;if(A.subcircuit_id){const r=new Set([A.subcircuit_id]),a=new Map,g=new Map;for(const I of e)if(I.type==="source_group"){const l=I.source_group_id,B=I.subcircuit_id;B&&g.set(l,B);const C=I.parent_source_group_id;C&&(a.has(C)||a.set(C,[]),a.get(C).push(l))}let c;for(const[I,l]of g)if(l===A.subcircuit_id){c=I;break}if(c){const I=l=>{const B=a.get(l)||[];for(const C of B){const Q=g.get(C);Q&&r.add(Q),I(C)}};I(c),t={...A,subcircuit_ids:Array.from(r)}}}const i=new Map;for(const r of e){const a=`${r.type}_id`,g=r[a];typeof g=="string"&&i.set(g,r)}const n=new Map;for(const r of e){const a=Object.entries(r);for(const[g,c]of a)if(g!=="parent_source_group_id"){if(g.endsWith("_id")&&typeof c=="string"){const I=i.get(c);wQt(n,r,I)}else if(g.endsWith("_ids")&&Array.isArray(c)){for(const I of c)if(typeof I=="string"){const l=i.get(I);wQt(n,r,l)}}}}const o=[],s=new Set;for(const r of e){let a=!1;(t.subcircuit_id&&"subcircuit_id"in r&&r.subcircuit_id===t.subcircuit_id||t.subcircuit_ids&&"subcircuit_id"in r&&r.subcircuit_id&&t.subcircuit_ids.includes(r.subcircuit_id)||t.source_group_id&&"source_group_id"in r&&r.source_group_id===t.source_group_id||t.source_group_id&&"member_source_group_ids"in r&&Array.isArray(r.member_source_group_ids)&&r.member_source_group_ids.includes(t.source_group_id))&&(a=!0),a&&(o.push(r),s.add(r))}for(;o.length>0;){const r=o.shift(),a=n.get(r);if(a)for(const g of a)s.has(g)||(s.add(g),o.push(g))}return e.filter(r=>s.has(r))}var OZ=(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))}}const n=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=>OZ(sXe(t,a),A);if(s==="insert")return a=>{const g=a.type;if(!g)throw new Error("insert requires an element with a type");i.counts[g]??=-1,i.counts[g]++;const c=i.counts[g],I={...a,type:g,[`${g}_id`]:`${g}_${c}`};return A.validateInserts&&(HfA[g]??uZ).parse(I),t.push(I),i.editCount++,I};if(s==="insertAll")return a=>a.map(g=>n.insert(g));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&&(HfA[r]??uZ).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)}}}}});return n};OZ.unparsed=OZ;var X2=OZ;function fyA(e){const A=e.type;return`${A}:${e[`${A}_id`]}`}var DQt=(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=fyA(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 Q=(B.get(r[c])||[]).find(E=>E.type===I);if(!Q)return null;const h=Q[`${s}_id`];return a.byId&&t.indexes.byId?t.indexes.byId.get(`${s}:${h}`)||null:a.byType&&t.indexes.byType?(t.indexes.byType.get(s)||[]).find(u=>u[`${s}_id`]===h)||null:e.find(E=>E.type===s&&E[`${s}_id`]===h)||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&&(HfA[s]??uZ).parse(g),e.push(g),t.editCount++;const c=A.indexConfig||{};if(c.byId&&t.indexes.byId){const I=fyA(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,Q=C.get(B)||[];Q.push(g),C.set(B,Q),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),Q=C.get(B)||[];Q.push(g),C.set(B,Q)}}}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=fyA(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 Q=C.filter(h=>h!==g);Q.length===0?l.delete(B):l.set(B,Q)}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(Q=>Q!==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 h=(C.get(B)||[]).filter(E=>E!==c);h.length===0?C.delete(B):C.set(B,h)}}}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(Q=>Q!==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]),Q=(l.get(B)||[]).filter(h=>h!==c);Q.length===0?l.delete(B):l.set(B,Q)}}}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,Q=C.get(B)||[];Q.includes(c)||(Q.push(c),C.set(B,Q),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),Q=C.get(B)||[];Q.includes(c)||(Q.push(c),C.set(B,Q))}}}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}}}})};DQt.unparsed=DQt;var rXe=e=>{const A=e.type;return e[`${A}_id`]},xQt=(e,A)=>({minX:Math.min(e.minX,A.minX),minY:Math.min(e.minY,A.minY),maxX:Math.max(e.maxX,A.maxX),maxY:Math.max(e.maxY,A.maxY)}),WZ=(e,A,t)=>{const i=t/2;return{minX:e-i,minY:A-i,maxX:e+i,maxY:A+i}},aXe=(e,A,t,i,n)=>{const o=t/2,s=i/2,r=n*Math.PI/180,a=Math.cos(r),g=Math.sin(r),c=[{x:-o,y:-s},{x:o,y:-s},{x:o,y:s},{x:-o,y:s}].map(I=>({x:e+I.x*a-I.y*g,y:A+I.x*g+I.y*a}));return{minX:Math.min(...c.map(I=>I.x)),minY:Math.min(...c.map(I=>I.y)),maxX:Math.max(...c.map(I=>I.x)),maxY:Math.max(...c.map(I=>I.y))}},yyA=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}if(o.type==="pcb_hole"&&o.hole_shape==="circle"){const c=WZ(o.x,o.y,o.hole_diameter);A=Math.min(A,c.minX),t=Math.min(t,c.minY),i=Math.max(i,c.maxX),n=Math.max(n,c.maxY);continue}if(o.type==="pcb_plated_hole"){let c;if("outer_diameter"in o&&typeof o.outer_diameter=="number"?c=WZ(o.x,o.y,o.outer_diameter):"hole_diameter"in o&&typeof o.hole_diameter=="number"&&(c=WZ(o.x,o.y,o.hole_diameter)),"rect_pad_width"in o&&typeof o.rect_pad_width=="number"&&"rect_pad_height"in o&&typeof o.rect_pad_height=="number"){const I=aXe(o.x,o.y,o.rect_pad_width,o.rect_pad_height,"rect_ccw_rotation"in o?o.rect_ccw_rotation??0:0);c=c?xQt(c,I):I}if("hole_diameter"in o&&typeof o.hole_diameter=="number"){const I=WZ(o.x+("hole_offset_x"in o?o.hole_offset_x??0:0),o.y+("hole_offset_y"in o?o.hole_offset_y??0:0),o.hole_diameter);c=c?xQt(c,I):I}if(c){A=Math.min(A,c.minX),t=Math.min(t,c.minY),i=Math.max(i,c.maxX),n=Math.max(n,c.maxY);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);else if(o.type==="pcb_courtyard_outline")for(const c of o.outline)A=Math.min(A,c.x),t=Math.min(t,c.y),i=Math.max(i,c.x),n=Math.max(n,c.y);else if(o.type==="pcb_courtyard_polygon")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)}return{minX:A,minY:t,maxX:i,maxY:n}};function gXe(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 SQt=[["#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"]],cXe=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:SQt[gXe(e.type||o)%SQt.length]?.[4]??"#f00"})},IXe=e=>!!e,lXe=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=>cXe(g)).filter(IXe);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}},Iu={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_COURTYARDS:"pcb_viewer_is_showing_courtyards",IS_SHOWING_GROUP_ANCHOR_OFFSETS:"pcb_viewer_is_showing_group_anchor_offsets",IS_SHOWING_SOLDER_MASK:"pcb_viewer_is_showing_solder_mask",IS_SHOWING_FABRICATION_NOTES:"pcb_viewer_is_showing_fabrication_notes",IS_SHOWING_SILKSCREEN:"pcb_viewer_is_showing_silkscreen"},w3=(e,A)=>{if(typeof window>"u")return A;try{const t=localStorage.getItem(e);return t!==null?JSON.parse(t):A}catch{return A}},D3=(e,A)=>{if(!(typeof window>"u"))try{localStorage.setItem(e,JSON.stringify(A))}catch{}},BXe=(e,A)=>{if(typeof window>"u")return A;try{const t=localStorage.getItem(e);return t!==null?JSON.parse(t):A}catch{return A}},CXe=(e,A)=>{if(!(typeof window>"u"))try{localStorage.setItem(e,JSON.stringify(A))}catch{}},QXe="named_only",hXe=(e={},A=!1)=>iCt(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:w3(Iu.IS_SHOWING_COPPER_POURS,!0),is_showing_courtyards:w3(Iu.IS_SHOWING_COURTYARDS,!0),is_showing_pcb_groups:A?!1:w3(Iu.IS_SHOWING_PCB_GROUPS,!0),is_showing_group_anchor_offsets:w3(Iu.IS_SHOWING_GROUP_ANCHOR_OFFSETS,!1),is_showing_solder_mask:w3(Iu.IS_SHOWING_SOLDER_MASK,!1),is_showing_silkscreen:w3(Iu.IS_SHOWING_SILKSCREEN,!0),is_showing_fabrication_notes:w3(Iu.IS_SHOWING_FABRICATION_NOTES,!1),pcb_group_view_mode:A?"all":BXe(Iu.PCB_GROUP_VIEW_MODE,QXe),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=>{D3(Iu.IS_SHOWING_COPPER_POURS,i),t({is_showing_copper_pours:i})},setIsShowingCourtyards:i=>{D3(Iu.IS_SHOWING_COURTYARDS,i),t({is_showing_courtyards:i})},setIsShowingPcbGroups:i=>{A||(D3(Iu.IS_SHOWING_PCB_GROUPS,i),t({is_showing_pcb_groups:i}))},setIsShowingGroupAnchorOffsets:i=>{D3(Iu.IS_SHOWING_GROUP_ANCHOR_OFFSETS,i),t({is_showing_group_anchor_offsets:i})},setIsShowingSolderMask:i=>{D3(Iu.IS_SHOWING_SOLDER_MASK,i),t({is_showing_solder_mask:i})},setIsShowingSilkscreen:i=>{D3(Iu.IS_SHOWING_SILKSCREEN,i),t({is_showing_silkscreen:i})},setIsShowingFabricationNotes:i=>{D3(Iu.IS_SHOWING_FABRICATION_NOTES,i),t({is_showing_fabrication_notes:i})},setPcbGroupViewMode:i=>{A||(CXe(Iu.PCB_GROUP_VIEW_MODE,i),t({pcb_group_view_mode:i}))},setHoveredErrorId:i=>t({hovered_error_id:i})})),rl=e=>{const A=AA.useContext(bQt);return BCt(A,e)},bQt=AA.createContext(null),EXe=({children:e,initialState:A,disablePcbGroups:t})=>{const i=AA.useMemo(()=>hXe(A,t),[t]);return Z.jsx(bQt.Provider,{value:i,children:e})},uXe=()=>{const e=rl(t=>t.pcb_viewer_id),A=(t,i)=>ic(t,{containerId:e,...i});return A.error=(t,i)=>ic.error(t,{containerId:e,...i}),A.promise=ic.promise,A},dXe=()=>{AA.useEffect(()=>{sVe()},[]);const e=rl(A=>A.pcb_viewer_id);return Z.jsx(oVe,{position:"top-center",containerId:e})};function pXe(){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 fXe=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]},yXe=fXe,mXe=function(){},_Qt=typeof window<"u",wXe=hyA(Tze()),DXe=function(){var e=pXe(),A=yXe({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,wXe.default)(r),i({value:r,error:void 0,noUserInteraction:s})}catch(g){i({value:r,error:g,noUserInteraction:s})}}},[]);return[t,n]},xXe=DXe,SXe=_Qt?AA.useLayoutEffect:AA.useEffect,bXe=SXe,kQt={x:0,y:0,width:0,height:0,top:0,left:0,bottom:0,right:0};function _Xe(){var e=AA.useState(null),A=e[0],t=e[1],i=AA.useState(kQt),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,Q=a.bottom,h=a.right;o({x:g,y:c,width:I,height:l,top:B,left:C,bottom:Q,right:h})}})},[]);return bXe(function(){if(A)return s.observe(A),function(){s.disconnect()}},[A]),[t,n]}var xL=_Qt&&typeof window.ResizeObserver<"u"?_Xe:function(){return[mXe,kQt]},vQt=({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 tn(sn(c,I),sn(o.x,o.y),za(g,g),sn(-o.x,-o.y),e)},kXe=(e={})=>{const A=AA.useRef(null),[t,i]=AA.useState(0),n=e.canvasElm??A.current,[o,s]=AA.useState(e.initialTransform??Sa()),[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())},[]),Q=AA.useRef("none"),h=AA.useRef(null),E=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 x=W=>({x:W.pageX-d.getBoundingClientRect().left-window.scrollX,y:W.pageY-d.getBoundingClientRect().top-window.scrollY});function _(W){e.enabled!==!1&&(e.shouldDrag&&!e.shouldDrag(W)||(m=x(W),!(Date.now()-t<100)&&(D=!0,W.preventDefault())))}function b(W){if(!D||e.enabled===!1||e.shouldDrag&&!e.shouldDrag(W))return;w=x(W);const z=tn(sn(w.x-m.x,w.y-m.y),f);I(z),f=z,D=!1}function R(W){if(x(W),!D||e.enabled===!1||e.shouldDrag&&!e.shouldDrag(W))return;w=x(W);const z=tn(sn(w.x-m.x,w.y-m.y),f);I(z)}function F(W){if(e.enabled===!1||e.shouldDrag&&!e.shouldDrag(W))return;const z=x(W),tA=tn(sn(z.x,z.y),za(1-W.deltaY/1e3,1-W.deltaY/1e3),sn(-z.x,-z.y),f);I(tA),f=tA,W.preventDefault()}function H(W){if(!D||e.shouldDrag&&!e.shouldDrag(W))return;if(d){const tA=d.getBoundingClientRect();if(W.clientX>=tA.left+10&&W.clientX<=tA.right-10&&W.clientY>=tA.top+10&&W.clientY<=tA.bottom-10)return}D=!1,w=x(W);const z=tn(sn(w.x-m.x,w.y-m.y),f);I(z),f=z}function Y(W){if(W.preventDefault(),e.enabled!==!1){if(W.touches.length===1){Q.current="drag";const z=W.touches[0];h.current={initialTransform:f,initialTouch:{x:z.clientX,y:z.clientY}}}else if(W.touches.length===2){Q.current="pinch";const z=W.touches[0],tA=W.touches[1];E.current={initialTransform:f,initialTouch1:{x:z.clientX,y:z.clientY},initialTouch2:{x:tA.clientX,y:tA.clientY},finalTouch1:null,finalTouch2:null}}}}function J(W){if(W.preventDefault(),e.enabled!==!1){if(Q.current==="drag"&&W.touches.length===1&&h.current){const z=W.touches[0],tA={x:z.clientX,y:z.clientY},aA=tA.x-h.current.initialTouch.x,eA=tA.y-h.current.initialTouch.y,oA=tn(sn(aA,eA),h.current.initialTransform);I(oA)}else if(Q.current==="pinch"&&W.touches.length===2&&E.current){const z=W.touches[0],tA=W.touches[1];E.current.finalTouch1={x:z.clientX,y:z.clientY},E.current.finalTouch2={x:tA.clientX,y:tA.clientY};const aA=vQt(E.current);I(aA)}}}function O(W){W.preventDefault();const z=W.changedTouches[0];if(Q.current==="drag"&&h.current&&z){const tA={x:z.clientX,y:z.clientY},aA=tA.x-h.current.initialTouch.x,eA=tA.y-h.current.initialTouch.y,oA=tn(sn(aA,eA),h.current.initialTransform);I(oA),f=oA}else if(Q.current==="pinch"&&E.current){const tA=vQt(E.current);I(tA),f=tA}Q.current="none",h.current=null,E.current=null}return d.addEventListener("mousedown",_),d.addEventListener("mouseup",b),window.addEventListener("mousemove",R),d.addEventListener("mouseout",H),d.addEventListener("wheel",F),d.addEventListener("touchstart",Y,{passive:!1}),d.addEventListener("touchmove",J,{passive:!1}),d.addEventListener("touchend",O,{passive:!1}),d.addEventListener("touchcancel",O,{passive:!1}),()=>{d.removeEventListener("mousedown",_),d.removeEventListener("mouseup",b),window.removeEventListener("mousemove",R),d.removeEventListener("mouseout",H),d.removeEventListener("wheel",F),d.removeEventListener("touchstart",Y),d.removeEventListener("touchmove",J),d.removeEventListener("touchend",O),d.removeEventListener("touchcancel",O)}},[n,r,g,t,e.enabled,e.shouldDrag]);const u=AA.useCallback(d=>Ct(B,d),[B]);return{ref:A,transform:B,applyTransformToPoint:u,setTransform:l,cancelDrag:C}},vXe=kXe;function FXe(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 MXe=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}},FQt=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=FXe(A);return new MXe(t)};function GXe({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 RXe(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,Q=Math.sqrt(B*B+C*C);return{x:-C/Q,y:B/Q}}function s(I,l,B,C){const Q=C/2,h={x:I.x+l.x*Q*B,y:I.y+l.y*Q*B};B>0?i.push(h):n.unshift(h)}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],Q=o(l,B),h=o(B,C),E=Q.x+h.x,u=Q.y+h.y,d=Math.sqrt(E*E+u*u),f=B.trace_width??A;if(d/2>2*(f/2))s(B,Q,1,f),s(B,h,1,f),s(B,Q,-1,f),s(B,h,-1,f);else{const w=1/d;s(B,{x:E*w,y:u*w},1,f),s(B,{x:E*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 NXe=(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:Fw("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:Fw("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},LXe=(e,A)=>{const{x:t,y:i,radius:n,layer:o}=e,s=[{_pcb_drawing_object_id:Fw("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:Fw("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},UXe=(e,A)=>{const{layer:t,points:i}=e,n=[{_pcb_drawing_object_id:Fw("polygon"),pcb_drawing_type:"polygon",points:myA(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:Fw("polygon"),pcb_drawing_type:"polygon",points:myA(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},HXe=(e,A)=>{const{x:t,y:i,width:n,height:o,layer:s}=e,r=[{_pcb_drawing_object_id:Fw("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:Fw("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},YXe=(e,A)=>{const{x:t,y:i,width:n,height:o,layer:s,ccw_rotation:r}=e,a=[{_pcb_drawing_object_id:Fw("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:Fw("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},HI=0,Fw=e=>`${e}_${HI++}`,myA=e=>(e??[]).map(A=>({x:pe.parse(A.x),y:pe.parse(A.y)})),JXe=(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?X2(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"?NXe(e,s):e.shape==="circle"?LXe(e,s):e.shape==="polygon"?UXe(e,s):e.shape==="pill"?HXe(e,s):e.shape==="rotated_pill"?YXe(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=RXe(g,.5),I=e.route[0].layer;return s.push({_pcb_drawing_object_id:`polygon_${HI++}`,_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_${HI++}`,_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_${HI++}`,_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 Q of B)C.push({_pcb_drawing_object_id:`circle_${HI++}`,pcb_drawing_type:"circle",x:s,y:r,r:a/2,layer:Q,_element:e,_parent_pcb_component:t,_parent_source_component:i});return C.push({_pcb_drawing_object_id:`circle_${HI++}`,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_${HI++}`,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_${HI++}`,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_${HI++}`,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_${HI++}`,_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_${HI++}`,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_${HI++}`,_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=pe.parse(l??0),Q=pe.parse(B??0);return[{_pcb_drawing_object_id:`rect_${HI++}`,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_${HI++}`,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,is_hoverable:!1},{_pcb_drawing_object_id:`circle_${HI++}`,_element:e,pcb_drawing_type:"circle",x:s+C,y:r+Q,r:a/2,layer:"drill",is_hoverable:!1}]}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_${HI++}`,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_${HI++}`,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,is_hoverable:!1},{_pcb_drawing_object_id:`pill_${HI++}`,_element:e,pcb_drawing_type:"pill",x:s,y:r,w:a,h:g,layer:"drill",is_hoverable:!1}]}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_${HI++}`,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_${HI++}`,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,is_hoverable:!1},{_pcb_drawing_object_id:`pill_${HI++}`,_element:e,pcb_drawing_type:"pill",x:s,y:r,w:a,h:g,layer:"drill",ccw_rotation:c,is_hoverable:!1}]}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:Q}=e,h=pe.parse(C??0),E=pe.parse(Q??0),u=a,d=[];if(u&&Array.isArray(u)){const w=myA(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_${HI++}`,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+h,y:r+E},m=[];return g==="circle"?m.push({_pcb_drawing_object_id:`circle_${HI++}`,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_${HI++}`,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_${HI++}`,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[]}return[]},pn={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)"}},Lp=(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)},_c={elementOverlay:40,dimensionOverlay:40,editTraceHintOverlay:40,errorOverlay:40,pcbGroupOverlay:35,ratsNestOverlay:30,toolbarOverlay:70,warnings:30,topLayer:20,clickToInteractOverlay:100},ZZ={red:"red",black:"black",green:"green",board:"rgb(255, 255, 255)",other:"#eee",top:pn.board.copper.f,inner1:pn.board.copper.in1,inner2:pn.board.copper.in2,inner3:pn.board.copper.in3,inner4:pn.board.copper.in4,inner5:pn.board.copper.in5,inner6:pn.board.copper.in6,inner7:pn.board.copper.in7,inner8:pn.board.copper.in8,bottom:pn.board.copper.b,drill:pn.board.anchor,keepout:pn.board.background,tkeepout:pn.board.b_crtyd,tplace:pn.board.b_silks,top_courtyard:pn.board.f_crtyd,bottom_courtyard:pn.board.b_crtyd,top_silkscreen:pn.board.f_silks,bottom_silkscreen:pn.board.b_silks,top_fabrication:pn.board.f_fab,bottom_fabrication:pn.board.b_fab,soldermask_top:pn.board.soldermask.top,soldermask_bottom:pn.board.soldermask.bottom,soldermask_with_copper_top:pn.board.soldermaskWithCopper.top,soldermask_with_copper_bottom:pn.board.soldermaskWithCopper.bottom,bottom_notes:pn.board.user_2,top_notes:pn.board.user_2,...pn.board},TXe=["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"],PXe=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=Sa(),this.transform.d*=-1,this.transform=tn(this.transform,sn(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]=Ct(this.transform,[e,A]),[g,c]=Ct(this.transform,[e+t,A+i]),I=Lp(this.transform,n);s.lineWidth=1,s.strokeStyle=this.aperture.color;const l=B=>{const C=Math.sin(B),Q=Math.cos(B),h=Math.sqrt((g-r)**2+(c-a)**2);for(let E=-h;E<=h;E+=I)s.beginPath(),s.moveTo(r+E*Q-h*C,a+E*C+h*Q),s.lineTo(r+E*Q+h*C,a+E*C-h*Q),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]=Ct(this.transform,[e-t/2,A-i/2]),[l,B]=Ct(this.transform,[e+t/2,A+i/2]);this.applyAperture();const C=this.getLayerCtx(),Q=g?Lp(this.transform,g):0,h=s===void 0?o===!1:s;if(n)C.save(),C.beginPath(),Q>0&&C.roundRect?C.roundRect(c,I,l-c,B-I,Q):C.rect(c,I,l-c,B-I),C.clip(),this.drawMeshPattern(e-t/2,A-i/2,t,i,.15),C.restore(),Q>0&&C.roundRect?(C.beginPath(),C.roundRect(c,I,l-c,B-I,Q),C.stroke()):C.strokeRect(c,I,l-c,B-I);else if(o!==!1&&(Q>0&&C.roundRect?(C.beginPath(),C.roundRect(c,I,l-c,B-I,Q),C.fill()):C.fillRect(c,I,l-c,B-I)),h){const E=C.lineWidth;if(a!==void 0&&(C.lineWidth=Lp(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)}Q>0&&C.roundRect?(C.beginPath(),C.roundRect(c,I,l-c,B-I,Q),C.stroke()):C.strokeRect(c,I,l-c,B-I),r&&C.setLineDash([]),a!==void 0&&(C.lineWidth=E)}}rotatedRect(e,A,t,i,n,o,s){const r=this.getLayerCtx();this.applyAperture();const[a,g]=Ct(this.transform,[e-t/2,A-i/2]),[c,I]=Ct(this.transform,[e+t/2,A+i/2]),l=o?Lp(this.transform,o):0;r.save();const[B,C]=Ct(this.transform,[e,A]);r.translate(B,C);const Q=360-n;n&&r.rotate(Q*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]=Ct(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=Lp(this.transform,t),[s,r]=Ct(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=Lp(this.transform,t),o=Lp(this.transform,i),[s,r]=Ct(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]=Ct(this.transform,[e-t/2,A+i/2]),s=Lp(this.transform,t),r=Lp(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=>Ct(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=Lp(this.transform,this.aperture.size);i>0&&(A.lineWidth=i,A.stroke())}debugText(e,A,t){const[i,n]=Ct(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=A==="top"?"top_courtyard":A==="bottom"?"bottom_courtyard":void 0,r=new Set([A,"drill","edge_cuts","other","board",...t?[t]:[],...i?[i]:[],...n?[n]:[],...o?[o]:[],...s?[s]:[]]),a=[A,"edge_cuts",...t?[t]:[],...i?[i]:[],...n?[n]:[],...o?[o]:[],...s?[s]:[]],g=A==="drill"?[]:["drill"],c=A==="drill"?["drill"]:[],I=[...TXe.filter(l=>!a.includes(l)),...g,A,...t?[t]:[],...c,"edge_cuts",...i?[i]:[],...n?[n]:[],...o?[o]:[],...s?[s]:[]];I.forEach((l,B)=>{const C=e[l];C&&(C.style.zIndex=`${_c.topLayer-(I.length-B)}`,C.style.opacity=r.has(l)?"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=Lp(e,t),r.lineCap="round",i==="add"){r.globalCompositeOperation="source-over";let a=ZZ[n.toLowerCase()];if(!a)try{a=Ha(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=`${Lp($y(e),o)}px sans-serif`}moveTo(e,A){this.lastPoint={x:e,y:A}}lineTo(e,A){const[t,i]=Ct(this.transform,[e,A]),{size:n,shape:o,mode:s}=this.aperture,r=Lp(this.transform,n),{lastPoint:a}=this,g=Ct(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=Ct(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 F=Ct(this.transform,[a.x,a.y]);A.lineTo(F[0],F[1]);continue}const B=4*Math.atan(g),C=Math.abs(l/(2*Math.sin(B/2))),Q=(r.x+a.x)/2,h=(r.y+a.y)/2,E=c/l,d=-(I/l),f=E,m=Math.sqrt(Math.max(0,C*C-(l/2)**2)),w=Q+m*d*Math.sign(g),D=h+m*f*Math.sign(g),x=Math.atan2(r.y-D,r.x-w);let _=Math.atan2(a.y-D,a.x-w);g>0&&_<x?_+=2*Math.PI:g<0&&_>x&&(_-=2*Math.PI);const b=Ct(this.transform,[w,D]),R=Lp(this.transform,C);A.arc(b[0],b[1],R,-x,-_,g>0)}else{const g=Ct(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 KXe(e){return e.type==="pcb_copper_pour"}function VZ({canvas:e,elements:A,layers:t,realToCanvasMat:i}){const n=A.filter(KXe);if(n.length===0)return;const o=new cC(e);o.realToCanvasMat=i,o.drawElements(n,{layers:t})}var qXe={...ad,silkscreen:{top:pn.board.f_fab,bottom:pn.board.b_fab}};function OXe(e){return e.type.includes("pcb_fabrication_note")}function MQt({canvas:e,elements:A,layers:t,realToCanvasMat:i}){const n=new cC(e);n.configure({colorOverrides:qXe}),n.realToCanvasMat=i;const o=A.filter(OXe);n.drawElements(o,{layers:t})}function WXe(e){return e.type==="pcb_hole"}function ZXe({canvas:e,elements:A,layers:t,realToCanvasMat:i,drawSoldermask:n}){const o=new cC(e);o.realToCanvasMat=i;const s=A.filter(WXe);o.drawElements(s,{layers:t,drawSoldermask:n})}function VXe(e){return e.type==="pcb_board"}function jXe({canvas:e,elements:A,layers:t,realToCanvasMat:i,drawSoldermask:n}){const o=new cC(e);o.realToCanvasMat=i;const s=A.filter(VXe);for(const r of s)o.drawElements([r],{layers:t,drawSoldermask:!1,drawBoardMaterial:n??!1,minBoardOutlineStrokePx:2})}function zXe(e){return e.type==="pcb_copper_text"}function XXe({canvas:e,elements:A,layers:t,realToCanvasMat:i}){const n=A.filter(zXe);if(n.length===0)return;const o=new cC(e);o.realToCanvasMat=i,o.drawElements(n,{layers:t})}function $Xe(e){return e.type==="pcb_cutout"}function A$e({canvas:e,elements:A,layers:t,realToCanvasMat:i}){const n=new cC(e);n.realToCanvasMat=i;const o=A.filter($Xe);n.drawElements(o,{layers:t})}function t$e(e){return e.type==="pcb_keepout"}function e$e({canvas:e,elements:A,layers:t,realToCanvasMat:i}){const n=A.filter(t$e);if(n.length===0)return;const o=new cC(e);o.realToCanvasMat=i,o.drawElements(n,{layers:[]})}function i$e(e){return e.type.startsWith("pcb_note_")}function GQt({canvas:e,elements:A,layers:t,realToCanvasMat:i}){const n=new cC(e);n.realToCanvasMat=i;const o=A.filter(i$e);n.drawElements(o,{layers:t})}function n$e(e){return e.type==="pcb_panel"}function o$e({canvas:e,elements:A,layers:t,realToCanvasMat:i,drawSoldermask:n}){const o=new cC(e);o.realToCanvasMat=i;const s=A.filter(n$e);for(const r of s)o.drawElements([r],{layers:t})}var s$e={...ad,copper:{...ad.copper,top:Ha(pn.board.pad_front).lighten(.5).toString(),bottom:Ha(pn.board.pad_back).lighten(.5).toString(),inner1:Ha(pn.board.copper.in1).lighten(.5).toString(),inner2:Ha(pn.board.copper.in2).lighten(.5).toString(),inner3:Ha(pn.board.copper.in3).lighten(.5).toString(),inner4:Ha(pn.board.copper.in4).lighten(.5).toString(),inner5:Ha(pn.board.copper.in5).lighten(.5).toString(),inner6:Ha(pn.board.copper.in6).lighten(.5).toString()}};function r$e(e){return e.type==="pcb_smtpad"}function a$e({canvas:e,elements:A,layers:t,realToCanvasMat:i,primitives:n,drawSoldermask:o}){const s=A.filter(r$e).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 cC(e);c.realToCanvasMat=i,c.drawElements(g,{layers:t,drawSoldermask:o})}if(a.length>0){const c=new cC(e);c.configure({colorOverrides:s$e}),c.realToCanvasMat=i,c.drawElements(a,{layers:t,drawSoldermask:o})}}var g$e={...ad,copper:{...ad.copper,top:Ha(pn.board.pad_front).lighten(.5).toString(),bottom:Ha(pn.board.pad_back).lighten(.5).toString(),inner1:Ha(pn.board.copper.in1).lighten(.5).toString(),inner2:Ha(pn.board.copper.in2).lighten(.5).toString(),inner3:Ha(pn.board.copper.in3).lighten(.5).toString(),inner4:Ha(pn.board.copper.in4).lighten(.5).toString(),inner5:Ha(pn.board.copper.in5).lighten(.5).toString(),inner6:Ha(pn.board.copper.in6).lighten(.5).toString()}};function c$e(e){return e.type==="pcb_trace"}var I$e=e=>e.map(A=>A.endsWith("_copper")?A.replace("_copper",""):A),l$e=(e,A)=>{const t=e.route.filter(i=>i.route_type==="wire"&&"layer"in i&&A.has(i.layer));return t.length===0?null:{...e,route:t}};function B$e({canvas:e,elements:A,layers:t,realToCanvasMat:i,primitives:n}){const o=new Set(I$e(t)),s=A.filter(c$e).map(c=>l$e(c,o)).filter(c=>c!==null);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=[],g=[];for(const c of s)r.has(c.pcb_trace_id)?a.push(c):g.push(c);if(g.length>0){const c=new cC(e);c.realToCanvasMat=i,c.drawElements(g,{layers:t})}if(a.length>0){const c=new cC(e);c.configure({colorOverrides:g$e}),c.realToCanvasMat=i,c.drawElements(a,{layers:t})}}var C$e={...ad,copper:{...ad.copper,top:Ha(pn.board.pad_front).lighten(.5).toString(),bottom:Ha(pn.board.pad_back).lighten(.5).toString()}};function Q$e(e){return e.type==="pcb_plated_hole"}function RQt({canvas:e,elements:A,layers:t,realToCanvasMat:i,primitives:n,drawSoldermask:o}){const s=A.filter(Q$e);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 cC(e);c.realToCanvasMat=i,c.drawElements(g,{layers:t,drawSoldermask:o})}if(a.length>0){const c=new cC(e);c.configure({colorOverrides:C$e}),c.realToCanvasMat=i,c.drawElements(a,{layers:t,drawSoldermask:o})}}function NQt(e){const{lines:A,anchorPoint:t,ccwRotation:i}=e;if(!i)return A;const n=i*Math.PI/180,o=Jl(n),s=tn(sn(t.x,t.y),o,sn(-t.x,-t.y));return Ct(s,t),A.map(r=>({...r,x1:Ct(s,{x:r.x1,y:r.y1}).x,y1:Ct(s,{x:r.x1,y:r.y1}).y,x2:Ct(s,{x:r.x2,y:r.y2}).x,y2:Ct(s,{x:r.x2,y:r.y2}).y}))}var h$e=.6,LQt=.2,UQt=e=>{const A=e.size*.7,t=A*h$e,i=A*LQt,n=A*LQt,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}},HQt=e=>{const A=UQt(e);return{width:A.width,height:A.height,lineHeight:A.target_height,lineSpacing:A.space_between_lines,lineCount:A.line_count}},YQt=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}=UQt(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 Q=e.x+C;for(let h=0;h<A[I].length;h++){const E=A[I][h],u=J4[E]??J4[E.toUpperCase()];if(!u){Q+=o+s;continue}for(const{x1:d,y1:f,x2:m,y2:w}of u)c.push({_pcb_drawing_object_id:Fw("line"),pcb_drawing_type:"line",x1:Q+o*d,y1:e.y+l+n*f,x2:Q+o*m,y2:e.y+l+n*w,width:g,layer:e.layer,unit:e.unit,color:e.color});Q+=o+s}}return c};function l1(e){const t=e.color??ZZ[e.layer];let i=Ha(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 JQt=(e,A)=>{e.equip({size:A.zoomIndependent?A.width/e.transform.a:A.width,shape:A.squareCap?"square":"circle",color:l1(A),layer:A.layer}),e.moveTo(A.x1,A.y1),e.lineTo(A.x2,A.y2)},E$e=(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}}},TQt=e=>e.layer==="bottom_silkscreen"||e.layer==="bottom"?e.is_mirrored!==!1:e.is_mirrored===!0,u$e=(e,A)=>{e.equip({fontSize:A.size,color:l1(A),layer:A.layer});const{width:t,height:i}=HQt(A),n=E$e(t,i,A.align);A.x??=0,A.y??=0;const o={x:A.x,y:A.y};let s=YQt({...A,x:A.x+n.x,y:A.y+n.y});if(TQt(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=NQt(r)}for(const r of s)JQt(e,r)},d$e=(e,A)=>{const{width:t,height:i,lineHeight:n}=HQt(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?KQt(e,B):PQt(e,B);let C=YQt({...A,x:c,y:I});if(TQt(A)&&(C=C.map(Q=>({...Q,x1:2*A.x-Q.x1,x2:2*A.x-Q.x2}))),A.ccw_rotation){const Q={lines:C,anchorPoint:l,ccwRotation:A.ccw_rotation};C=NQt(Q)}for(const Q of C)e.equip({size:Q.width,shape:"circle",color:"black",layer:A.layer,mode:"subtract"}),e.moveTo(Q.x1,Q.y1),e.lineTo(Q.x2,Q.y2);e.equip({mode:"add"})},PQt=(e,A)=>{e.equip({color:l1(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})},KQt=(e,A)=>{e.equip({color:l1(A),layer:A.layer}),e.rotatedRect(A.x,A.y,A.w,A.h,A.ccw_rotation,A.roundness,A.mesh_fill)},p$e=(e,A)=>{e.equip({color:l1(A),layer:A.layer}),e.rotatedPill(A.x,A.y,A.w,A.h,A.ccw_rotation)},f$e=(e,A)=>{e.equip({color:l1(A),layer:A.layer}),e.circle(A.x,A.y,A.r,A.mesh_fill)},y$e=(e,A)=>{e.equip({color:l1(A),layer:A.layer}),e.oval(A.x,A.y,A.rX,A.rY)},m$e=(e,A)=>{e.equip({color:l1(A),layer:A.layer}),e.pill(A.x,A.y,A.w,A.h)},w$e=(e,A)=>{e.equip({color:l1(A),layer:A.layer}),e.polygon(A.points)},D$e=(e,A)=>{e.equip({color:l1(A),layer:A.layer}),e.polygonWithArcs(A.brep_shape)},x$e=(e,A)=>{switch(A.pcb_drawing_type){case"line":return JQt(e,A);case"text":return A.is_knockout?d$e(e,A):u$e(e,A);case"rect":return A.ccw_rotation?KQt(e,A):PQt(e,A);case"circle":return f$e(e,A);case"oval":return y$e(e,A);case"pill":return A.ccw_rotation?p$e(e,A):m$e(e,A);case"polygon":return w$e(e,A);case"polygon_with_arcs":return D$e(e,A)}},S$e=(e,A)=>{for(const t of A)x$e(e,t)},b$e={...ad,copper:{...ad.copper,top:Ha(pn.board.pad_front).lighten(.5).toString(),bottom:Ha(pn.board.pad_back).lighten(.5).toString(),inner1:Ha(pn.board.copper.in1).lighten(.5).toString(),inner2:Ha(pn.board.copper.in2).lighten(.5).toString(),inner3:Ha(pn.board.copper.in3).lighten(.5).toString(),inner4:Ha(pn.board.copper.in4).lighten(.5).toString(),inner5:Ha(pn.board.copper.in5).lighten(.5).toString(),inner6:Ha(pn.board.copper.in6).lighten(.5).toString()},soldermask:{...ad.soldermask,top:Ha(pn.board.soldermask.top).lighten(.35).toString(),bottom:Ha(pn.board.soldermask.bottom).lighten(.35).toString()}};function qQt({canvas:e,elements:A,layers:t,realToCanvasMat:i,drawSoldermaskTop:n,drawSoldermaskBottom:o,primitives:s}){const r=new cC(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 cC(e);I.configure({colorOverrides:b$e}),I.realToCanvasMat=i,I.drawElements(c,{layers:t,drawSoldermask:!0,drawSoldermaskTop:n,drawSoldermaskBottom:o,drawBoardMaterial:!1})}var _$e={...ad,silkscreen:{top:pn.board.f_silks,bottom:pn.board.b_silks}};function k$e(e){return e.type.includes("pcb_silkscreen")}function OQt({canvas:e,elements:A,layers:t,realToCanvasMat:i}){const n=new cC(e);n.configure({colorOverrides:_$e}),n.realToCanvasMat=i;const o=A.filter(k$e);n.drawElements(o,{layers:t})}var v$e={...ad,copper:{...ad.copper,top:Ha(pn.board.pad_front).lighten(.5).toString(),bottom:Ha(pn.board.pad_back).lighten(.5).toString()}};function F$e(e){return e.type==="pcb_via"}function WQt({canvas:e,elements:A,layers:t,realToCanvasMat:i,primitives:n,drawSoldermask:o}){const s=A.filter(F$e).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 cC(e);c.realToCanvasMat=i,c.drawElements(g,{layers:t,drawSoldermask:o})}if(a.length>0){const c=new cC(e);c.configure({colorOverrides:v$e}),c.realToCanvasMat=i,c.drawElements(a,{layers:t,drawSoldermask:o})}}var M$e={...ad,courtyard:{top:pn.board.f_crtyd,bottom:pn.board.b_crtyd}};function G$e(e){return e.type==="pcb_courtyard_circle"||e.type==="pcb_courtyard_rect"||e.type==="pcb_courtyard_outline"}function ZQt({canvas:e,elements:A,layers:t,realToCanvasMat:i}){const n=new cC(e);n.configure({colorOverrides:M$e}),n.realToCanvasMat=i;const o=A.filter(G$e);n.drawElements(o,{layers:t})}var R$e=["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"],N$e=({primitives:e,elements:A,transform:t,grid:i,width:n=500,height:o=500})=>{const s=AA.useRef({}),r=rl(l=>l.selected_layer),a=rl(l=>l.is_showing_solder_mask),g=rl(l=>l.is_showing_fabrication_notes),c=rl(l=>l.is_showing_courtyards),I=rl(l=>l.is_showing_silkscreen);return AA.useEffect(()=>{if(!s.current||Object.keys(s.current).length===0)return;const l=Object.fromEntries(Object.entries(s.current).filter(([Q,h])=>!!h));if(Object.keys(l).length===0)return;const B=new PXe(l);t&&(B.transform=t),B.clear(),B.foregroundLayer=r;const C=e.filter(Q=>a||!Q.layer?.includes("soldermask")).filter(Q=>I||!Q.layer?.includes("silkscreen")).filter(Q=>g||!Q.layer?.includes("fabrication")).filter(Q=>Q.layer!=="board").filter(Q=>Q._element?.type!=="pcb_smtpad").filter(Q=>Q._element?.type!=="pcb_plated_hole").filter(Q=>Q._element?.type!=="pcb_via").filter(Q=>Q._element?.type!=="pcb_trace").filter(Q=>Q._element?.type!=="pcb_copper_text");if(S$e(B,C),t){const Q=s.current.top,h=s.current.bottom,E=s.current.inner1,u=s.current.inner2,d=s.current.inner3,f=s.current.inner4,m=s.current.inner5,w=s.current.inner6,D=[{canvas:Q,copperLayer:"top_copper"},{canvas:h,copperLayer:"bottom_copper"},{canvas:E,copperLayer:"inner1_copper"},{canvas:u,copperLayer:"inner2_copper"},{canvas:d,copperLayer:"inner3_copper"},{canvas:f,copperLayer:"inner4_copper"},{canvas:m,copperLayer:"inner5_copper"},{canvas:w,copperLayer:"inner6_copper"}];for(const{canvas:Y,copperLayer:J}of D)Y&&B$e({canvas:Y,elements:A,layers:[J],realToCanvasMat:t,primitives:e});for(const{canvas:Y,copperLayer:J}of D)Y&&XXe({canvas:Y,elements:A,layers:[J],realToCanvasMat:t});Q&&RQt({canvas:Q,elements:A,layers:["top_copper"],realToCanvasMat:t,primitives:e,drawSoldermask:a}),h&&RQt({canvas:h,elements:A,layers:["bottom_copper"],realToCanvasMat:t,primitives:e,drawSoldermask:a}),Q&&VZ({canvas:Q,elements:A,layers:["top_copper"],realToCanvasMat:t}),h&&VZ({canvas:h,elements:A,layers:["bottom_copper"],realToCanvasMat:t});for(const{canvas:Y,copperLayer:J}of D)Y&&a$e({canvas:Y,elements:A,layers:[J],realToCanvasMat:t,primitives:e,drawSoldermask:a});if(Q&&WQt({canvas:Q,elements:A,layers:["top_copper"],realToCanvasMat:t,primitives:e,drawSoldermask:a}),h&&WQt({canvas:h,elements:A,layers:["bottom_copper"],realToCanvasMat:t,primitives:e,drawSoldermask:a}),a){const Y=r==="bottom"?"bottom":"top",J=Y==="top",O=Y==="bottom",W=s.current.soldermask_top;W&&Y==="top"&&qQt({canvas:W,elements:A,layers:["top_soldermask"],realToCanvasMat:t,drawSoldermaskTop:J,drawSoldermaskBottom:O,primitives:e});const z=s.current.soldermask_bottom;z&&Y==="bottom"&&qQt({canvas:z,elements:A,layers:["bottom_soldermask"],realToCanvasMat:t,drawSoldermaskTop:J,drawSoldermaskBottom:O,primitives:e})}Q&&VZ({canvas:Q,elements:A,layers:["top_copper"],realToCanvasMat:t}),h&&VZ({canvas:h,elements:A,layers:["bottom_copper"],realToCanvasMat:t});const x=s.current.drill;if(x&&ZXe({canvas:x,elements:A,layers:["drill"],realToCanvasMat:t}),I){const Y=s.current.top_silkscreen;Y&&OQt({canvas:Y,elements:A,layers:["top_silkscreen"],realToCanvasMat:t});const J=s.current.bottom_silkscreen;J&&OQt({canvas:J,elements:A,layers:["bottom_silkscreen"],realToCanvasMat:t})}if(g){const Y=s.current.top_fabrication;Y&&MQt({canvas:Y,elements:A,layers:["top_fabrication_note"],realToCanvasMat:t});const J=s.current.bottom_fabrication;J&&MQt({canvas:J,elements:A,layers:["bottom_fabrication_note"],realToCanvasMat:t})}const _=s.current.bottom_notes;_&&GQt({canvas:_,elements:A,layers:["bottom_user_note"],realToCanvasMat:t});const b=s.current.top_notes;if(b&&GQt({canvas:b,elements:A,layers:["top_user_note"],realToCanvasMat:t}),c){const Y=s.current.top_courtyard;Y&&ZQt({canvas:Y,elements:A,layers:["top_courtyard"],realToCanvasMat:t});const J=s.current.bottom_courtyard;J&&ZQt({canvas:J,elements:A,layers:["bottom_courtyard"],realToCanvasMat:t})}const R=s.current.board;R&&(o$e({canvas:R,elements:A,layers:[],realToCanvasMat:t,drawSoldermask:a}),jXe({canvas:R,elements:A,layers:[],realToCanvasMat:t,drawSoldermask:a}));const F=s.current.edge_cuts;F&&A$e({canvas:F,elements:A,layers:["edge_cuts"],realToCanvasMat:t});const H=[{canvas:Q,layer:"top"},{canvas:h,layer:"bottom"}];for(const{canvas:Y,layer:J}of H)Y&&e$e({canvas:Y,elements:A,layers:[J],realToCanvasMat:t})}B.orderAndFadeLayers()},[e,A,t,r,a,g,c,I]),Z.jsxs("div",{style:{backgroundColor:"black",width:n,height:o,position:"relative"},children:[Z.jsx(MZ.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:(l,B,C)=>`${MZ.toMMSI(l,C)}, ${MZ.toMMSI(B,C)}`}),R$e.filter(l=>!(!a&&l.includes("soldermask")||!I&&l.includes("silkscreen"))).map(l=>l.replace(/-/g,"")).map((l,B)=>Z.jsx("canvas",{className:`pcb-layer-${l}`,ref:C=>{s.current??={},C?s.current[l]=C:delete s.current[l]},style:{position:"absolute",zIndex:B,left:0,top:0,pointerEvents:"none"},width:n,height:o},l))]})},L$e=.6,U$e=1;hyA(Pze(),1),hyA(oXe(),1);var jZ=["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 VQt(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 tn(sn(A/2,t/2),za(g,o?-g:g),sn(-(s.minX+r/2),-(s.minY+a/2)))}function H$e(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*L$e,o=i*U$e,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 Y$e(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=VQt(t.viewbox,n,o,{padding:t.padding,yFlip:t.yFlip});else{const r=H$e(e),a=e.coordinateSystem==="cartesian";s=VQt(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=Ct(s,{x:r.center.x-a,y:r.center.y-g}),I=Ct(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=Ct(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=Ct(s,r.points[0]);i.moveTo(g.x,g.y);for(let c=1;c<r.points.length;c++){const I=Ct(s,r.points[c]);i.lineTo(I.x,I.y)}if(i.strokeStyle=r.strokeColor||jZ[a%jZ.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=Ct(s,r);i.beginPath(),i.arc(g.x,g.y,3,0,2*Math.PI),i.fillStyle=r.color||jZ[a%jZ.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=Ct(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 J$e=({children:e,transform:A,debugGraphics:t})=>{const i=AA.useRef(null),[n,{width:o,height:s}]=xL(),r=rl(a=>a.is_showing_autorouting);return AA.useEffect(()=>{r&&i.current&&t&&o&&s&&(i.current.width=o,i.current.height=s,Y$e(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},T$e=({children:e,transform:A=Sa(),elements:t=[]})=>{const[i,{width:n,height:o}]=xL(),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=pn.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:Q}=l,h=Ct(A,Q),E=B*Math.abs(A.a),u=C*Math.abs(A.d),d=.1*Math.abs(A.a),f=E+d*2,m=u+d*2,w=h.x-f/2,D=h.y-m/2;a.beginPath(),a.rect(w,D,f,m),a.stroke();const x="Manual Edit Conflict",_=4,b=Math.max(8,Math.min(12,10*Math.abs(A.a)));a.font=`${b}px sans-serif`;const F=a.measureText(x).width+_*2,H=b+_*2,Y=w+(f-F)/2,J=D+m+5;a.fillStyle="rgba(0, 0, 0, 0.7)",a.beginPath(),a.roundRect(Y,J,F,H,3),a.fill(),a.fillStyle=pn.board.drc_warning,a.textAlign="center",a.textBaseline="middle",a.fillText(x,Y+F/2,J+H/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:_c.warnings}})]})},zZ=(e,A,t)=>t(e,A),jQt=(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}},SL=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=zZ(A,o.x,Math.min),t=zZ(t,o.x,Math.max),i=zZ(i,o.y,Math.min),n=zZ(n,o.y,Math.max);return{minX:A,maxX:t,minY:i,maxY:n}},P$e=(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)}),K$e=(e,A)=>e?P$e(e,A):A,q$e=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=SL(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=>jQt(s.x,s.y,e.x,e.y,n));return SL(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=>jQt(s.x,s.y,e.x,e.y,n));return SL(o)}case"polygon":return SL(e.points);case"polygon_with_arcs":{const A=e.brep_shape.outer_ring.vertices.map(t=>({x:t.x,y:t.y}));return SL(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 O$e(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,h=Math.min(C,90-C)>15,E=(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,x=c>0&&I>0,_=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),x&&(m+=Math.cos(f*Math.PI/180)+-20,w+=Math.sin(f*Math.PI/180)+-10),_&&(m+=Math.cos(f*Math.PI/180)*10,w+=Math.sin(f*Math.PI/180)*10);const b=E+m,R=u+w;return{distance:g,screenDistance:l,x:b,y:R,show:g>.01&&l>30&&h}}function W$e(e){const{dimensionStart:A,dimensionEnd:t,screenDimensionStart:i,screenDimensionEnd:n,flipX:o,flipY:s}=e;return AA.useMemo(()=>O$e({dimensionStart:A,dimensionEnd:t,screenDimensionStart:i,screenDimensionEnd:n,flipX:o,flipY:s}),[A,t,i,n,o,s])}var Z$e=(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}},zQt=(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:Z$e(s,e,i)}))},V$e=e=>{switch(e.pcb_drawing_type){case"rect":{const A=e.ccw_rotation??0;return zQt({x:e.x,y:e.y},e.w/2,e.h/2,A)}case"pill":{const A=e.ccw_rotation??0;return zQt({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[]}},j$e=16,x3=5,XQt=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},z$e=({children:e,transform:A,focusOnHover:t=!1,primitives:i=[]})=>{A||(A=Sa());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=rl(J=>J.is_mouse_over_container),B=AA.useCallback(()=>{a&&(g(!1),window.dispatchEvent(new Event("disarm-dimension-tool")))},[a]),[C,Q]=AA.useState({x:0,y:0}),[h,E]=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 J=new Map;for(const O of i){if(!O._element||XQt(O)||O.pcb_drawing_type==="pill"||O.pcb_drawing_type==="rect"&&O.ccw_rotation&&O.ccw_rotation!==0)continue;const W=q$e(O);if(!W)continue;const z=J.get(O._element);J.set(O._element,K$e(z??void 0,W))}return J},[i]),D=AA.useMemo(()=>{const J=[];for(const O of i){if(!O._element||XQt(O))continue;const W=V$e(O);if(W.length!==0)for(const z of W)J.push({anchor:z.anchor,point:z.point,element:O._element})}return J},[i]),x=AA.useMemo(()=>{const J=[];w.forEach((O,W)=>{if(!O)return;const z=(O.minX+O.maxX)/2,tA=(O.minY+O.maxY)/2,aA={top_left:{x:O.minX,y:O.minY},top_center:{x:z,y:O.minY},top_right:{x:O.maxX,y:O.minY},center_left:{x:O.minX,y:tA},center:{x:z,y:tA},center_right:{x:O.maxX,y:tA},bottom_left:{x:O.minX,y:O.maxY},bottom_center:{x:z,y:O.maxY},bottom_right:{x:O.maxX,y:O.maxY}};for(const[eA,oA]of Object.entries(aA))J.push({anchor:eA,point:oA,element:W})});for(const O of D)J.push(O);return J.push({anchor:"origin",point:{x:0,y:0},element:null}),J},[w,D]),_=AA.useMemo(()=>x.map((J,O)=>({...J,id:`${O}-${J.anchor}`,screenPoint:Ct(A,J.point)})),[x,A]),b=AA.useCallback(J=>{if(_.length===0)return{point:J,id:null};const O=Ct(A,J);let W=null;for(const z of _){const tA=z.screenPoint.x-O.x,aA=z.screenPoint.y-O.y,eA=Math.hypot(tA,aA);eA>j$e||(!W||eA<W.distance)&&(W={distance:eA,id:z.id,point:z.point})}return W?{point:W.point,id:W.id}:{point:J,id:null}},[_,A]);AA.useEffect(()=>{const J=W=>{const z=W.target;if(z.tagName==="INPUT"||z.tagName==="TEXTAREA"||z.isContentEditable)return;const tA=d.current?.contains(document.activeElement)||document.activeElement===d.current;if(!(!l&&!tA)){if(W.key==="d"){const aA=b({x:u.current.x,y:u.current.y});Q({x:aA.point.x,y:aA.point.y}),E({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",J),window.addEventListener("arm-dimension-tool",O),()=>{window.removeEventListener("keydown",J),window.removeEventListener("arm-dimension-tool",O),B()}},[l,n,B,b]);const R=Ct(A,C),F=Ct(A,h),H={left:Math.min(R.x,F.x),right:Math.max(R.x,F.x),top:Math.min(R.y,F.y),bottom:Math.max(R.y,F.y),flipX:R.x>F.x,flipY:R.y>F.y,width:0,height:0};H.width=H.right-H.left,H.height=H.bottom-H.top;const Y=W$e({dimensionStart:C,dimensionEnd:h,screenDimensionStart:R,screenDimensionEnd:F,flipX:H.flipX,flipY:H.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:J=>{const O=J.currentTarget.getBoundingClientRect(),W=J.clientX-O.left,z=J.clientY-O.top,tA=Ct($y(A),{x:W,y:z});if(u.current.x=tA.x,u.current.y=tA.y,s){const aA=b(tA);E({x:aA.point.x,y:aA.point.y}),I(eA=>({...eA,end:aA.id}))}},onMouseDown:J=>{const O=J.currentTarget.getBoundingClientRect(),W=J.clientX-O.left,z=J.clientY-O.top,tA=Ct($y(A),{x:W,y:z});if(a&&!n){const aA=b(tA);Q({x:aA.point.x,y:aA.point.y}),E({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:[Y.show&&Z.jsx("div",{style:{position:"absolute",left:Y.x,top:Y.y,color:"red",mixBlendMode:"difference",pointerEvents:"none",fontSize:12,fontFamily:"sans-serif",whiteSpace:"nowrap",zIndex:_c.dimensionOverlay},children:Y.distance.toFixed(2)}),Z.jsx("div",{style:{position:"absolute",left:H.left,width:H.width,textAlign:"center",top:R.y+2,color:"red",mixBlendMode:"difference",pointerEvents:"none",marginTop:H.flipY?0:-20,fontSize:12,fontFamily:"sans-serif",zIndex:_c.dimensionOverlay},children:Math.abs(C.x-h.x).toFixed(2)}),Z.jsx("div",{style:{position:"absolute",left:F.x,height:H.height,display:"flex",flexDirection:"column",justifyContent:"center",top:H.top,color:"red",pointerEvents:"none",mixBlendMode:"difference",fontSize:12,fontFamily:"sans-serif",zIndex:_c.dimensionOverlay},children:Z.jsx("div",{style:{marginLeft:H.flipX?"-100%":4,paddingRight:4},children:Math.abs(C.y-h.y).toFixed(2)})}),Z.jsxs("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none",mixBlendMode:"difference",zIndex:_c.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:R.x,y1:R.y,x2:F.x,y2:F.y,markerEnd:"url(#head)",strokeWidth:1.5,fill:"none",stroke:"red"}),Z.jsx("line",{x1:R.x,y1:R.y,x2:F.x,y2:R.y,strokeWidth:1.5,fill:"none",strokeDasharray:"2,2",stroke:"red"}),Z.jsx("line",{x1:F.x,y1:R.y,x2:F.x,y2:F.y,strokeWidth:1.5,fill:"none",strokeDasharray:"2,2",stroke:"red"})]}),s&&_.map(J=>{const O=J.id===c.start||J.id===c.end,W=x3/2;return Z.jsxs("svg",{width:x3,height:x3,style:{position:"absolute",left:J.screenPoint.x-W,top:J.screenPoint.y-W,pointerEvents:"none",zIndex:_c.dimensionOverlay},children:[Z.jsx("line",{x1:0,y1:0,x2:x3,y2:x3,stroke:O?"#66ccff":"white",strokeWidth:1}),Z.jsx("line",{x1:x3,y1:0,x2:0,y2:x3,stroke:O?"#66ccff":"white",strokeWidth:1})]},J.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",{}),"(",h.x.toFixed(2),",",h.y.toFixed(2),")",Z.jsx("br",{}),"dist:"," ",Math.sqrt((h.x-C.x)**2+(h.y-C.y)**2).toFixed(2)]})]})]})},X$e=(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},$$e=({children:e,disabled:A,transform:t,soup:i,cancelPanDrag:n,onCreateEditEvent:o,onModifyEditEvent:s})=>{t||(t=Sa());const r=AA.useRef(null),[a,g]=AA.useState(null),[c,I]=AA.useState(null),l=a!==null;rl(h=>h.in_edit_mode);const B=rl(h=>h.in_move_footprint_mode),C=rl(h=>h.setIsMovingComponent),Q=A||!B;return Z.jsxs("div",{ref:r,style:{position:"relative",overflow:"hidden"},onMouseDown:h=>{if(Q)return;const E=h.currentTarget.getBoundingClientRect(),u=h.clientX-E.left,d=h.clientY-E.top;if(Number.isNaN(u)||Number.isNaN(d))return;const f=Ct($y(t),{x:u,y:d});let m=!1;for(const w of i)if(w.type==="pcb_component"&&X$e(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 h.preventDefault(),!1},onMouseMove:h=>{if(!a||!c)return;const E=h.currentTarget.getBoundingClientRect(),u=h.clientX-E.left,d=h.clientY-E.top;if(Number.isNaN(u)||Number.isNaN(d))return;const f=Ct($y(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:h=>{a&&(g(null),C(!1),c&&(s({edit_event_id:c.edit_event_id,in_progress:!1}),I(null)))},children:[e,!Q&&i.filter(h=>h.type==="pcb_component").map(h=>{if(!h?.center)return null;const E=Ct(t,h.center);return Z.jsx("div",{style:{position:"absolute",pointerEvents:"none",left:E.x,top:E.y,width:h.width*t.a+20,height:h.height*t.a+20,transform:"translate(-50%, -50%)",background:l&&a===h.pcb_component_id?"rgba(255, 0, 0, 0.2)":""}},h.pcb_component_id)})]})},AAi=({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:gM`
|
|
5432
|
+
$1`).replace(/>(\s*)(?=<!--\s*\/)/g,"> ")}}});function wQt(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 sXe(e,A){if(!A.subcircuit_id&&!A.source_group_id)return[...e];let t=A;if(A.subcircuit_id){const r=new Set([A.subcircuit_id]),a=new Map,g=new Map;for(const I of e)if(I.type==="source_group"){const l=I.source_group_id,B=I.subcircuit_id;B&&g.set(l,B);const C=I.parent_source_group_id;C&&(a.has(C)||a.set(C,[]),a.get(C).push(l))}let c;for(const[I,l]of g)if(l===A.subcircuit_id){c=I;break}if(c){const I=l=>{const B=a.get(l)||[];for(const C of B){const Q=g.get(C);Q&&r.add(Q),I(C)}};I(c),t={...A,subcircuit_ids:Array.from(r)}}}const i=new Map;for(const r of e){const a=`${r.type}_id`,g=r[a];typeof g=="string"&&i.set(g,r)}const n=new Map;for(const r of e){const a=Object.entries(r);for(const[g,c]of a)if(g!=="parent_source_group_id"){if(g.endsWith("_id")&&typeof c=="string"){const I=i.get(c);wQt(n,r,I)}else if(g.endsWith("_ids")&&Array.isArray(c)){for(const I of c)if(typeof I=="string"){const l=i.get(I);wQt(n,r,l)}}}}const o=[],s=new Set;for(const r of e){let a=!1;(t.subcircuit_id&&"subcircuit_id"in r&&r.subcircuit_id===t.subcircuit_id||t.subcircuit_ids&&"subcircuit_id"in r&&r.subcircuit_id&&t.subcircuit_ids.includes(r.subcircuit_id)||t.source_group_id&&"source_group_id"in r&&r.source_group_id===t.source_group_id||t.source_group_id&&"member_source_group_ids"in r&&Array.isArray(r.member_source_group_ids)&&r.member_source_group_ids.includes(t.source_group_id))&&(a=!0),a&&(o.push(r),s.add(r))}for(;o.length>0;){const r=o.shift(),a=n.get(r);if(a)for(const g of a)s.has(g)||(s.add(g),o.push(g))}return e.filter(r=>s.has(r))}var OZ=(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))}}const n=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=>OZ(sXe(t,a),A);if(s==="insert")return a=>{const g=a.type;if(!g)throw new Error("insert requires an element with a type");i.counts[g]??=-1,i.counts[g]++;const c=i.counts[g],I={...a,type:g,[`${g}_id`]:`${g}_${c}`};return A.validateInserts&&(HfA[g]??uZ).parse(I),t.push(I),i.editCount++,I};if(s==="insertAll")return a=>a.map(g=>n.insert(g));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&&(HfA[r]??uZ).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)}}}}});return n};OZ.unparsed=OZ;var X2=OZ;function fyA(e){const A=e.type;return`${A}:${e[`${A}_id`]}`}var DQt=(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=fyA(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 Q=(B.get(r[c])||[]).find(E=>E.type===I);if(!Q)return null;const h=Q[`${s}_id`];return a.byId&&t.indexes.byId?t.indexes.byId.get(`${s}:${h}`)||null:a.byType&&t.indexes.byType?(t.indexes.byType.get(s)||[]).find(u=>u[`${s}_id`]===h)||null:e.find(E=>E.type===s&&E[`${s}_id`]===h)||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&&(HfA[s]??uZ).parse(g),e.push(g),t.editCount++;const c=A.indexConfig||{};if(c.byId&&t.indexes.byId){const I=fyA(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,Q=C.get(B)||[];Q.push(g),C.set(B,Q),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),Q=C.get(B)||[];Q.push(g),C.set(B,Q)}}}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=fyA(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 Q=C.filter(h=>h!==g);Q.length===0?l.delete(B):l.set(B,Q)}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(Q=>Q!==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 h=(C.get(B)||[]).filter(E=>E!==c);h.length===0?C.delete(B):C.set(B,h)}}}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(Q=>Q!==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]),Q=(l.get(B)||[]).filter(h=>h!==c);Q.length===0?l.delete(B):l.set(B,Q)}}}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,Q=C.get(B)||[];Q.includes(c)||(Q.push(c),C.set(B,Q),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),Q=C.get(B)||[];Q.includes(c)||(Q.push(c),C.set(B,Q))}}}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}}}})};DQt.unparsed=DQt;var rXe=e=>{const A=e.type;return e[`${A}_id`]},xQt=(e,A)=>({minX:Math.min(e.minX,A.minX),minY:Math.min(e.minY,A.minY),maxX:Math.max(e.maxX,A.maxX),maxY:Math.max(e.maxY,A.maxY)}),WZ=(e,A,t)=>{const i=t/2;return{minX:e-i,minY:A-i,maxX:e+i,maxY:A+i}},aXe=(e,A,t,i,n)=>{const o=t/2,s=i/2,r=n*Math.PI/180,a=Math.cos(r),g=Math.sin(r),c=[{x:-o,y:-s},{x:o,y:-s},{x:o,y:s},{x:-o,y:s}].map(I=>({x:e+I.x*a-I.y*g,y:A+I.x*g+I.y*a}));return{minX:Math.min(...c.map(I=>I.x)),minY:Math.min(...c.map(I=>I.y)),maxX:Math.max(...c.map(I=>I.x)),maxY:Math.max(...c.map(I=>I.y))}},yyA=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}if(o.type==="pcb_hole"&&o.hole_shape==="circle"){const c=WZ(o.x,o.y,o.hole_diameter);A=Math.min(A,c.minX),t=Math.min(t,c.minY),i=Math.max(i,c.maxX),n=Math.max(n,c.maxY);continue}if(o.type==="pcb_plated_hole"){let c;if("outer_diameter"in o&&typeof o.outer_diameter=="number"?c=WZ(o.x,o.y,o.outer_diameter):"hole_diameter"in o&&typeof o.hole_diameter=="number"&&(c=WZ(o.x,o.y,o.hole_diameter)),"rect_pad_width"in o&&typeof o.rect_pad_width=="number"&&"rect_pad_height"in o&&typeof o.rect_pad_height=="number"){const I=aXe(o.x,o.y,o.rect_pad_width,o.rect_pad_height,"rect_ccw_rotation"in o?o.rect_ccw_rotation??0:0);c=c?xQt(c,I):I}if("hole_diameter"in o&&typeof o.hole_diameter=="number"){const I=WZ(o.x+("hole_offset_x"in o?o.hole_offset_x??0:0),o.y+("hole_offset_y"in o?o.hole_offset_y??0:0),o.hole_diameter);c=c?xQt(c,I):I}if(c){A=Math.min(A,c.minX),t=Math.min(t,c.minY),i=Math.max(i,c.maxX),n=Math.max(n,c.maxY);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);else if(o.type==="pcb_courtyard_outline")for(const c of o.outline)A=Math.min(A,c.x),t=Math.min(t,c.y),i=Math.max(i,c.x),n=Math.max(n,c.y);else if(o.type==="pcb_courtyard_polygon")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)}return{minX:A,minY:t,maxX:i,maxY:n}};function gXe(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 SQt=[["#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"]],cXe=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:SQt[gXe(e.type||o)%SQt.length]?.[4]??"#f00"})},IXe=e=>!!e,lXe=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=>cXe(g)).filter(IXe);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}},Iu={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_COURTYARDS:"pcb_viewer_is_showing_courtyards",IS_SHOWING_GROUP_ANCHOR_OFFSETS:"pcb_viewer_is_showing_group_anchor_offsets",IS_SHOWING_SOLDER_MASK:"pcb_viewer_is_showing_solder_mask",IS_SHOWING_FABRICATION_NOTES:"pcb_viewer_is_showing_fabrication_notes",IS_SHOWING_SILKSCREEN:"pcb_viewer_is_showing_silkscreen"},w3=(e,A)=>{if(typeof window>"u")return A;try{const t=localStorage.getItem(e);return t!==null?JSON.parse(t):A}catch{return A}},D3=(e,A)=>{if(!(typeof window>"u"))try{localStorage.setItem(e,JSON.stringify(A))}catch{}},BXe=(e,A)=>{if(typeof window>"u")return A;try{const t=localStorage.getItem(e);return t!==null?JSON.parse(t):A}catch{return A}},CXe=(e,A)=>{if(!(typeof window>"u"))try{localStorage.setItem(e,JSON.stringify(A))}catch{}},QXe="named_only",hXe=(e={},A=!1)=>iCt(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:w3(Iu.IS_SHOWING_COPPER_POURS,!0),is_showing_courtyards:w3(Iu.IS_SHOWING_COURTYARDS,!0),is_showing_pcb_groups:A?!1:w3(Iu.IS_SHOWING_PCB_GROUPS,!0),is_showing_group_anchor_offsets:w3(Iu.IS_SHOWING_GROUP_ANCHOR_OFFSETS,!1),is_showing_solder_mask:w3(Iu.IS_SHOWING_SOLDER_MASK,!1),is_showing_silkscreen:w3(Iu.IS_SHOWING_SILKSCREEN,!0),is_showing_fabrication_notes:w3(Iu.IS_SHOWING_FABRICATION_NOTES,!1),pcb_group_view_mode:A?"all":BXe(Iu.PCB_GROUP_VIEW_MODE,QXe),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=>{D3(Iu.IS_SHOWING_COPPER_POURS,i),t({is_showing_copper_pours:i})},setIsShowingCourtyards:i=>{D3(Iu.IS_SHOWING_COURTYARDS,i),t({is_showing_courtyards:i})},setIsShowingPcbGroups:i=>{A||(D3(Iu.IS_SHOWING_PCB_GROUPS,i),t({is_showing_pcb_groups:i}))},setIsShowingGroupAnchorOffsets:i=>{D3(Iu.IS_SHOWING_GROUP_ANCHOR_OFFSETS,i),t({is_showing_group_anchor_offsets:i})},setIsShowingSolderMask:i=>{D3(Iu.IS_SHOWING_SOLDER_MASK,i),t({is_showing_solder_mask:i})},setIsShowingSilkscreen:i=>{D3(Iu.IS_SHOWING_SILKSCREEN,i),t({is_showing_silkscreen:i})},setIsShowingFabricationNotes:i=>{D3(Iu.IS_SHOWING_FABRICATION_NOTES,i),t({is_showing_fabrication_notes:i})},setPcbGroupViewMode:i=>{A||(CXe(Iu.PCB_GROUP_VIEW_MODE,i),t({pcb_group_view_mode:i}))},setHoveredErrorId:i=>t({hovered_error_id:i})})),rl=e=>{const A=AA.useContext(bQt);return BCt(A,e)},bQt=AA.createContext(null),EXe=({children:e,initialState:A,disablePcbGroups:t})=>{const i=AA.useMemo(()=>hXe(A,t),[t]);return Z.jsx(bQt.Provider,{value:i,children:e})},uXe=()=>{const e=rl(t=>t.pcb_viewer_id),A=(t,i)=>ic(t,{containerId:e,...i});return A.error=(t,i)=>ic.error(t,{containerId:e,...i}),A.promise=ic.promise,A},dXe=()=>{AA.useEffect(()=>{sVe()},[]);const e=rl(A=>A.pcb_viewer_id);return Z.jsx(oVe,{position:"top-center",containerId:e})};function pXe(){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 fXe=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]},yXe=fXe,mXe=function(){},_Qt=typeof window<"u",wXe=hyA(Tze()),DXe=function(){var e=pXe(),A=yXe({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,wXe.default)(r),i({value:r,error:void 0,noUserInteraction:s})}catch(g){i({value:r,error:g,noUserInteraction:s})}}},[]);return[t,n]},xXe=DXe,SXe=_Qt?AA.useLayoutEffect:AA.useEffect,bXe=SXe,kQt={x:0,y:0,width:0,height:0,top:0,left:0,bottom:0,right:0};function _Xe(){var e=AA.useState(null),A=e[0],t=e[1],i=AA.useState(kQt),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,Q=a.bottom,h=a.right;o({x:g,y:c,width:I,height:l,top:B,left:C,bottom:Q,right:h})}})},[]);return bXe(function(){if(A)return s.observe(A),function(){s.disconnect()}},[A]),[t,n]}var xL=_Qt&&typeof window.ResizeObserver<"u"?_Xe:function(){return[mXe,kQt]},vQt=({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 tn(sn(c,I),sn(o.x,o.y),za(g,g),sn(-o.x,-o.y),e)},kXe=(e={})=>{const A=AA.useRef(null),[t,i]=AA.useState(0),n=e.canvasElm??A.current,[o,s]=AA.useState(e.initialTransform??Sa()),[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())},[]),Q=AA.useRef("none"),h=AA.useRef(null),E=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 x=W=>({x:W.pageX-d.getBoundingClientRect().left-window.scrollX,y:W.pageY-d.getBoundingClientRect().top-window.scrollY});function _(W){e.enabled!==!1&&(e.shouldDrag&&!e.shouldDrag(W)||(m=x(W),!(Date.now()-t<100)&&(D=!0,W.preventDefault())))}function b(W){if(!D||e.enabled===!1||e.shouldDrag&&!e.shouldDrag(W))return;w=x(W);const z=tn(sn(w.x-m.x,w.y-m.y),f);I(z),f=z,D=!1}function R(W){if(x(W),!D||e.enabled===!1||e.shouldDrag&&!e.shouldDrag(W))return;w=x(W);const z=tn(sn(w.x-m.x,w.y-m.y),f);I(z)}function F(W){if(e.enabled===!1||e.shouldDrag&&!e.shouldDrag(W))return;const z=x(W),tA=tn(sn(z.x,z.y),za(1-W.deltaY/1e3,1-W.deltaY/1e3),sn(-z.x,-z.y),f);I(tA),f=tA,W.preventDefault()}function H(W){if(!D||e.shouldDrag&&!e.shouldDrag(W))return;if(d){const tA=d.getBoundingClientRect();if(W.clientX>=tA.left+10&&W.clientX<=tA.right-10&&W.clientY>=tA.top+10&&W.clientY<=tA.bottom-10)return}D=!1,w=x(W);const z=tn(sn(w.x-m.x,w.y-m.y),f);I(z),f=z}function Y(W){if(W.preventDefault(),e.enabled!==!1){if(W.touches.length===1){Q.current="drag";const z=W.touches[0];h.current={initialTransform:f,initialTouch:{x:z.clientX,y:z.clientY}}}else if(W.touches.length===2){Q.current="pinch";const z=W.touches[0],tA=W.touches[1];E.current={initialTransform:f,initialTouch1:{x:z.clientX,y:z.clientY},initialTouch2:{x:tA.clientX,y:tA.clientY},finalTouch1:null,finalTouch2:null}}}}function J(W){if(W.preventDefault(),e.enabled!==!1){if(Q.current==="drag"&&W.touches.length===1&&h.current){const z=W.touches[0],tA={x:z.clientX,y:z.clientY},aA=tA.x-h.current.initialTouch.x,eA=tA.y-h.current.initialTouch.y,oA=tn(sn(aA,eA),h.current.initialTransform);I(oA)}else if(Q.current==="pinch"&&W.touches.length===2&&E.current){const z=W.touches[0],tA=W.touches[1];E.current.finalTouch1={x:z.clientX,y:z.clientY},E.current.finalTouch2={x:tA.clientX,y:tA.clientY};const aA=vQt(E.current);I(aA)}}}function O(W){W.preventDefault();const z=W.changedTouches[0];if(Q.current==="drag"&&h.current&&z){const tA={x:z.clientX,y:z.clientY},aA=tA.x-h.current.initialTouch.x,eA=tA.y-h.current.initialTouch.y,oA=tn(sn(aA,eA),h.current.initialTransform);I(oA),f=oA}else if(Q.current==="pinch"&&E.current){const tA=vQt(E.current);I(tA),f=tA}Q.current="none",h.current=null,E.current=null}return d.addEventListener("mousedown",_),d.addEventListener("mouseup",b),window.addEventListener("mousemove",R),d.addEventListener("mouseout",H),d.addEventListener("wheel",F),d.addEventListener("touchstart",Y,{passive:!1}),d.addEventListener("touchmove",J,{passive:!1}),d.addEventListener("touchend",O,{passive:!1}),d.addEventListener("touchcancel",O,{passive:!1}),()=>{d.removeEventListener("mousedown",_),d.removeEventListener("mouseup",b),window.removeEventListener("mousemove",R),d.removeEventListener("mouseout",H),d.removeEventListener("wheel",F),d.removeEventListener("touchstart",Y),d.removeEventListener("touchmove",J),d.removeEventListener("touchend",O),d.removeEventListener("touchcancel",O)}},[n,r,g,t,e.enabled,e.shouldDrag]);const u=AA.useCallback(d=>Ct(B,d),[B]);return{ref:A,transform:B,applyTransformToPoint:u,setTransform:l,cancelDrag:C}},vXe=kXe;function FXe(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 MXe=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}},FQt=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=FXe(A);return new MXe(t)};function GXe({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 RXe(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,Q=Math.sqrt(B*B+C*C);return{x:-C/Q,y:B/Q}}function s(I,l,B,C){const Q=C/2,h={x:I.x+l.x*Q*B,y:I.y+l.y*Q*B};B>0?i.push(h):n.unshift(h)}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],Q=o(l,B),h=o(B,C),E=Q.x+h.x,u=Q.y+h.y,d=Math.sqrt(E*E+u*u),f=B.trace_width??A;if(d/2>2*(f/2))s(B,Q,1,f),s(B,h,1,f),s(B,Q,-1,f),s(B,h,-1,f);else{const w=1/d;s(B,{x:E*w,y:u*w},1,f),s(B,{x:E*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 NXe=(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:Fw("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:Fw("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},LXe=(e,A)=>{const{x:t,y:i,radius:n,layer:o}=e,s=[{_pcb_drawing_object_id:Fw("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:Fw("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},UXe=(e,A)=>{const{layer:t,points:i}=e,n=[{_pcb_drawing_object_id:Fw("polygon"),pcb_drawing_type:"polygon",points:myA(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:Fw("polygon"),pcb_drawing_type:"polygon",points:myA(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},HXe=(e,A)=>{const{x:t,y:i,width:n,height:o,layer:s}=e,r=[{_pcb_drawing_object_id:Fw("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:Fw("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},YXe=(e,A)=>{const{x:t,y:i,width:n,height:o,layer:s,ccw_rotation:r}=e,a=[{_pcb_drawing_object_id:Fw("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:Fw("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},HI=0,Fw=e=>`${e}_${HI++}`,myA=e=>(e??[]).map(A=>({x:pe.parse(A.x),y:pe.parse(A.y)})),JXe=(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?X2(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"?NXe(e,s):e.shape==="circle"?LXe(e,s):e.shape==="polygon"?UXe(e,s):e.shape==="pill"?HXe(e,s):e.shape==="rotated_pill"?YXe(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=RXe(g,.5),I=e.route[0].layer;return s.push({_pcb_drawing_object_id:`polygon_${HI++}`,_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_${HI++}`,_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_${HI++}`,_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 Q of B)C.push({_pcb_drawing_object_id:`circle_${HI++}`,pcb_drawing_type:"circle",x:s,y:r,r:a/2,layer:Q,_element:e,_parent_pcb_component:t,_parent_source_component:i});return C.push({_pcb_drawing_object_id:`circle_${HI++}`,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_${HI++}`,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_${HI++}`,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_${HI++}`,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_${HI++}`,_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_${HI++}`,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_${HI++}`,_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=pe.parse(l??0),Q=pe.parse(B??0);return[{_pcb_drawing_object_id:`rect_${HI++}`,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_${HI++}`,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,is_hoverable:!1},{_pcb_drawing_object_id:`circle_${HI++}`,_element:e,pcb_drawing_type:"circle",x:s+C,y:r+Q,r:a/2,layer:"drill",is_hoverable:!1}]}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_${HI++}`,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_${HI++}`,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,is_hoverable:!1},{_pcb_drawing_object_id:`pill_${HI++}`,_element:e,pcb_drawing_type:"pill",x:s,y:r,w:a,h:g,layer:"drill",is_hoverable:!1}]}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_${HI++}`,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_${HI++}`,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,is_hoverable:!1},{_pcb_drawing_object_id:`pill_${HI++}`,_element:e,pcb_drawing_type:"pill",x:s,y:r,w:a,h:g,layer:"drill",ccw_rotation:c,is_hoverable:!1}]}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:Q}=e,h=pe.parse(C??0),E=pe.parse(Q??0),u=a,d=[];if(u&&Array.isArray(u)){const w=myA(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_${HI++}`,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+h,y:r+E},m=[];return g==="circle"?m.push({_pcb_drawing_object_id:`circle_${HI++}`,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_${HI++}`,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_${HI++}`,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[]}return[]},pn={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)"}},Lp=(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)},_c={elementOverlay:40,dimensionOverlay:40,editTraceHintOverlay:40,errorOverlay:40,pcbGroupOverlay:35,ratsNestOverlay:30,toolbarOverlay:70,warnings:30,topLayer:20,clickToInteractOverlay:100},ZZ={red:"red",black:"black",green:"green",board:"rgb(255, 255, 255)",other:"#eee",top:pn.board.copper.f,inner1:pn.board.copper.in1,inner2:pn.board.copper.in2,inner3:pn.board.copper.in3,inner4:pn.board.copper.in4,inner5:pn.board.copper.in5,inner6:pn.board.copper.in6,inner7:pn.board.copper.in7,inner8:pn.board.copper.in8,bottom:pn.board.copper.b,drill:pn.board.anchor,keepout:pn.board.background,tkeepout:pn.board.b_crtyd,tplace:pn.board.b_silks,top_courtyard:pn.board.f_crtyd,bottom_courtyard:pn.board.b_crtyd,top_silkscreen:pn.board.f_silks,bottom_silkscreen:pn.board.b_silks,top_fabrication:pn.board.f_fab,bottom_fabrication:pn.board.b_fab,soldermask_top:pn.board.soldermask.top,soldermask_bottom:pn.board.soldermask.bottom,soldermask_with_copper_top:pn.board.soldermaskWithCopper.top,soldermask_with_copper_bottom:pn.board.soldermaskWithCopper.bottom,bottom_notes:pn.board.user_2,top_notes:pn.board.user_2,...pn.board},TXe=["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"],PXe=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=Sa(),this.transform.d*=-1,this.transform=tn(this.transform,sn(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]=Ct(this.transform,[e,A]),[g,c]=Ct(this.transform,[e+t,A+i]),I=Lp(this.transform,n);s.lineWidth=1,s.strokeStyle=this.aperture.color;const l=B=>{const C=Math.sin(B),Q=Math.cos(B),h=Math.sqrt((g-r)**2+(c-a)**2);for(let E=-h;E<=h;E+=I)s.beginPath(),s.moveTo(r+E*Q-h*C,a+E*C+h*Q),s.lineTo(r+E*Q+h*C,a+E*C-h*Q),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]=Ct(this.transform,[e-t/2,A-i/2]),[l,B]=Ct(this.transform,[e+t/2,A+i/2]);this.applyAperture();const C=this.getLayerCtx(),Q=g?Lp(this.transform,g):0,h=s===void 0?o===!1:s;if(n)C.save(),C.beginPath(),Q>0&&C.roundRect?C.roundRect(c,I,l-c,B-I,Q):C.rect(c,I,l-c,B-I),C.clip(),this.drawMeshPattern(e-t/2,A-i/2,t,i,.15),C.restore(),Q>0&&C.roundRect?(C.beginPath(),C.roundRect(c,I,l-c,B-I,Q),C.stroke()):C.strokeRect(c,I,l-c,B-I);else if(o!==!1&&(Q>0&&C.roundRect?(C.beginPath(),C.roundRect(c,I,l-c,B-I,Q),C.fill()):C.fillRect(c,I,l-c,B-I)),h){const E=C.lineWidth;if(a!==void 0&&(C.lineWidth=Lp(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)}Q>0&&C.roundRect?(C.beginPath(),C.roundRect(c,I,l-c,B-I,Q),C.stroke()):C.strokeRect(c,I,l-c,B-I),r&&C.setLineDash([]),a!==void 0&&(C.lineWidth=E)}}rotatedRect(e,A,t,i,n,o,s){const r=this.getLayerCtx();this.applyAperture();const[a,g]=Ct(this.transform,[e-t/2,A-i/2]),[c,I]=Ct(this.transform,[e+t/2,A+i/2]),l=o?Lp(this.transform,o):0;r.save();const[B,C]=Ct(this.transform,[e,A]);r.translate(B,C);const Q=360-n;n&&r.rotate(Q*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]=Ct(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=Lp(this.transform,t),[s,r]=Ct(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=Lp(this.transform,t),o=Lp(this.transform,i),[s,r]=Ct(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]=Ct(this.transform,[e-t/2,A+i/2]),s=Lp(this.transform,t),r=Lp(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=>Ct(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=Lp(this.transform,this.aperture.size);i>0&&(A.lineWidth=i,A.stroke())}debugText(e,A,t){const[i,n]=Ct(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=A==="top"?"top_courtyard":A==="bottom"?"bottom_courtyard":void 0,r=new Set([A,"drill","edge_cuts","other","board",...t?[t]:[],...i?[i]:[],...n?[n]:[],...o?[o]:[],...s?[s]:[]]),a=[A,"edge_cuts",...t?[t]:[],...i?[i]:[],...n?[n]:[],...o?[o]:[],...s?[s]:[]],g=A==="drill"?[]:["drill"],c=A==="drill"?["drill"]:[],I=[...TXe.filter(l=>!a.includes(l)),...g,A,...t?[t]:[],...c,"edge_cuts",...i?[i]:[],...n?[n]:[],...o?[o]:[],...s?[s]:[]];I.forEach((l,B)=>{const C=e[l];C&&(C.style.zIndex=`${_c.topLayer-(I.length-B)}`,C.style.opacity=r.has(l)?"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=Lp(e,t),r.lineCap="round",i==="add"){r.globalCompositeOperation="source-over";let a=ZZ[n.toLowerCase()];if(!a)try{a=Ha(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=`${Lp($y(e),o)}px sans-serif`}moveTo(e,A){this.lastPoint={x:e,y:A}}lineTo(e,A){const[t,i]=Ct(this.transform,[e,A]),{size:n,shape:o,mode:s}=this.aperture,r=Lp(this.transform,n),{lastPoint:a}=this,g=Ct(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=Ct(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 F=Ct(this.transform,[a.x,a.y]);A.lineTo(F[0],F[1]);continue}const B=4*Math.atan(g),C=Math.abs(l/(2*Math.sin(B/2))),Q=(r.x+a.x)/2,h=(r.y+a.y)/2,E=c/l,d=-(I/l),f=E,m=Math.sqrt(Math.max(0,C*C-(l/2)**2)),w=Q+m*d*Math.sign(g),D=h+m*f*Math.sign(g),x=Math.atan2(r.y-D,r.x-w);let _=Math.atan2(a.y-D,a.x-w);g>0&&_<x?_+=2*Math.PI:g<0&&_>x&&(_-=2*Math.PI);const b=Ct(this.transform,[w,D]),R=Lp(this.transform,C);A.arc(b[0],b[1],R,-x,-_,g>0)}else{const g=Ct(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 KXe(e){return e.type==="pcb_copper_pour"}function VZ({canvas:e,elements:A,layers:t,realToCanvasMat:i}){const n=A.filter(KXe);if(n.length===0)return;const o=new cC(e);o.realToCanvasMat=i,o.drawElements(n,{layers:t})}var qXe={...ad,silkscreen:{top:pn.board.f_fab,bottom:pn.board.b_fab}};function OXe(e){return e.type.includes("pcb_fabrication_note")}function MQt({canvas:e,elements:A,layers:t,realToCanvasMat:i}){const n=new cC(e);n.configure({colorOverrides:qXe}),n.realToCanvasMat=i;const o=A.filter(OXe);n.drawElements(o,{layers:t})}function WXe(e){return e.type==="pcb_hole"}function ZXe({canvas:e,elements:A,layers:t,realToCanvasMat:i,drawSoldermask:n}){const o=new cC(e);o.realToCanvasMat=i;const s=A.filter(WXe);o.drawElements(s,{layers:t,drawSoldermask:n})}function VXe(e){return e.type==="pcb_board"}function jXe({canvas:e,elements:A,layers:t,realToCanvasMat:i,drawSoldermask:n}){const o=new cC(e);o.realToCanvasMat=i;const s=A.filter(VXe);for(const r of s)o.drawElements([r],{layers:t,drawSoldermask:!1,drawBoardMaterial:n??!1,minBoardOutlineStrokePx:2})}function zXe(e){return e.type==="pcb_copper_text"}function XXe({canvas:e,elements:A,layers:t,realToCanvasMat:i}){const n=A.filter(zXe);if(n.length===0)return;const o=new cC(e);o.realToCanvasMat=i,o.drawElements(n,{layers:t})}function $Xe(e){return e.type==="pcb_cutout"}function A$e({canvas:e,elements:A,layers:t,realToCanvasMat:i}){const n=new cC(e);n.realToCanvasMat=i;const o=A.filter($Xe);n.drawElements(o,{layers:t})}function t$e(e){return e.type==="pcb_keepout"}function e$e({canvas:e,elements:A,layers:t,realToCanvasMat:i}){const n=A.filter(t$e);if(n.length===0)return;const o=new cC(e);o.realToCanvasMat=i,o.drawElements(n,{layers:[]})}function i$e(e){return e.type.startsWith("pcb_note_")}function GQt({canvas:e,elements:A,layers:t,realToCanvasMat:i}){const n=new cC(e);n.realToCanvasMat=i;const o=A.filter(i$e);n.drawElements(o,{layers:t})}function n$e(e){return e.type==="pcb_panel"}function o$e({canvas:e,elements:A,layers:t,realToCanvasMat:i,drawSoldermask:n}){const o=new cC(e);o.realToCanvasMat=i;const s=A.filter(n$e);for(const r of s)o.drawElements([r],{layers:t})}var s$e={...ad,copper:{...ad.copper,top:Ha(pn.board.pad_front).lighten(.5).toString(),bottom:Ha(pn.board.pad_back).lighten(.5).toString(),inner1:Ha(pn.board.copper.in1).lighten(.5).toString(),inner2:Ha(pn.board.copper.in2).lighten(.5).toString(),inner3:Ha(pn.board.copper.in3).lighten(.5).toString(),inner4:Ha(pn.board.copper.in4).lighten(.5).toString(),inner5:Ha(pn.board.copper.in5).lighten(.5).toString(),inner6:Ha(pn.board.copper.in6).lighten(.5).toString()}};function r$e(e){return e.type==="pcb_smtpad"}function a$e({canvas:e,elements:A,layers:t,realToCanvasMat:i,primitives:n,drawSoldermask:o}){const s=A.filter(r$e).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 cC(e);c.realToCanvasMat=i,c.drawElements(g,{layers:t,drawSoldermask:o})}if(a.length>0){const c=new cC(e);c.configure({colorOverrides:s$e}),c.realToCanvasMat=i,c.drawElements(a,{layers:t,drawSoldermask:o})}}var g$e={...ad,copper:{...ad.copper,top:Ha(pn.board.pad_front).lighten(.5).toString(),bottom:Ha(pn.board.pad_back).lighten(.5).toString(),inner1:Ha(pn.board.copper.in1).lighten(.5).toString(),inner2:Ha(pn.board.copper.in2).lighten(.5).toString(),inner3:Ha(pn.board.copper.in3).lighten(.5).toString(),inner4:Ha(pn.board.copper.in4).lighten(.5).toString(),inner5:Ha(pn.board.copper.in5).lighten(.5).toString(),inner6:Ha(pn.board.copper.in6).lighten(.5).toString()}};function c$e(e){return e.type==="pcb_trace"}var I$e=e=>e.map(A=>A.endsWith("_copper")?A.replace("_copper",""):A),l$e=(e,A)=>{const t=e.route.filter(n=>n.route_type==="wire"&&"layer"in n&&A.has(n.layer)?!0:n.route_type==="via"?A.has(n.from_layer)||A.has(n.to_layer):!1);return t.filter(n=>n.route_type==="wire").length<2?null:{...e,route:t}};function B$e({canvas:e,elements:A,layers:t,realToCanvasMat:i,primitives:n}){const o=new Set(I$e(t)),s=A.filter(c$e).map(c=>l$e(c,o)).filter(c=>c!==null);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=[],g=[];for(const c of s)r.has(c.pcb_trace_id)?a.push(c):g.push(c);if(g.length>0){const c=new cC(e);c.realToCanvasMat=i,c.drawElements(g,{layers:t})}if(a.length>0){const c=new cC(e);c.configure({colorOverrides:g$e}),c.realToCanvasMat=i,c.drawElements(a,{layers:t})}}var C$e={...ad,copper:{...ad.copper,top:Ha(pn.board.pad_front).lighten(.5).toString(),bottom:Ha(pn.board.pad_back).lighten(.5).toString()}};function Q$e(e){return e.type==="pcb_plated_hole"}function RQt({canvas:e,elements:A,layers:t,realToCanvasMat:i,primitives:n,drawSoldermask:o}){const s=A.filter(Q$e);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 cC(e);c.realToCanvasMat=i,c.drawElements(g,{layers:t,drawSoldermask:o})}if(a.length>0){const c=new cC(e);c.configure({colorOverrides:C$e}),c.realToCanvasMat=i,c.drawElements(a,{layers:t,drawSoldermask:o})}}function NQt(e){const{lines:A,anchorPoint:t,ccwRotation:i}=e;if(!i)return A;const n=i*Math.PI/180,o=Jl(n),s=tn(sn(t.x,t.y),o,sn(-t.x,-t.y));return Ct(s,t),A.map(r=>({...r,x1:Ct(s,{x:r.x1,y:r.y1}).x,y1:Ct(s,{x:r.x1,y:r.y1}).y,x2:Ct(s,{x:r.x2,y:r.y2}).x,y2:Ct(s,{x:r.x2,y:r.y2}).y}))}var h$e=.6,LQt=.2,UQt=e=>{const A=e.size*.7,t=A*h$e,i=A*LQt,n=A*LQt,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}},HQt=e=>{const A=UQt(e);return{width:A.width,height:A.height,lineHeight:A.target_height,lineSpacing:A.space_between_lines,lineCount:A.line_count}},YQt=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}=UQt(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 Q=e.x+C;for(let h=0;h<A[I].length;h++){const E=A[I][h],u=J4[E]??J4[E.toUpperCase()];if(!u){Q+=o+s;continue}for(const{x1:d,y1:f,x2:m,y2:w}of u)c.push({_pcb_drawing_object_id:Fw("line"),pcb_drawing_type:"line",x1:Q+o*d,y1:e.y+l+n*f,x2:Q+o*m,y2:e.y+l+n*w,width:g,layer:e.layer,unit:e.unit,color:e.color});Q+=o+s}}return c};function l1(e){const t=e.color??ZZ[e.layer];let i=Ha(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 JQt=(e,A)=>{e.equip({size:A.zoomIndependent?A.width/e.transform.a:A.width,shape:A.squareCap?"square":"circle",color:l1(A),layer:A.layer}),e.moveTo(A.x1,A.y1),e.lineTo(A.x2,A.y2)},E$e=(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}}},TQt=e=>e.layer==="bottom_silkscreen"||e.layer==="bottom"?e.is_mirrored!==!1:e.is_mirrored===!0,u$e=(e,A)=>{e.equip({fontSize:A.size,color:l1(A),layer:A.layer});const{width:t,height:i}=HQt(A),n=E$e(t,i,A.align);A.x??=0,A.y??=0;const o={x:A.x,y:A.y};let s=YQt({...A,x:A.x+n.x,y:A.y+n.y});if(TQt(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=NQt(r)}for(const r of s)JQt(e,r)},d$e=(e,A)=>{const{width:t,height:i,lineHeight:n}=HQt(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?KQt(e,B):PQt(e,B);let C=YQt({...A,x:c,y:I});if(TQt(A)&&(C=C.map(Q=>({...Q,x1:2*A.x-Q.x1,x2:2*A.x-Q.x2}))),A.ccw_rotation){const Q={lines:C,anchorPoint:l,ccwRotation:A.ccw_rotation};C=NQt(Q)}for(const Q of C)e.equip({size:Q.width,shape:"circle",color:"black",layer:A.layer,mode:"subtract"}),e.moveTo(Q.x1,Q.y1),e.lineTo(Q.x2,Q.y2);e.equip({mode:"add"})},PQt=(e,A)=>{e.equip({color:l1(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})},KQt=(e,A)=>{e.equip({color:l1(A),layer:A.layer}),e.rotatedRect(A.x,A.y,A.w,A.h,A.ccw_rotation,A.roundness,A.mesh_fill)},p$e=(e,A)=>{e.equip({color:l1(A),layer:A.layer}),e.rotatedPill(A.x,A.y,A.w,A.h,A.ccw_rotation)},f$e=(e,A)=>{e.equip({color:l1(A),layer:A.layer}),e.circle(A.x,A.y,A.r,A.mesh_fill)},y$e=(e,A)=>{e.equip({color:l1(A),layer:A.layer}),e.oval(A.x,A.y,A.rX,A.rY)},m$e=(e,A)=>{e.equip({color:l1(A),layer:A.layer}),e.pill(A.x,A.y,A.w,A.h)},w$e=(e,A)=>{e.equip({color:l1(A),layer:A.layer}),e.polygon(A.points)},D$e=(e,A)=>{e.equip({color:l1(A),layer:A.layer}),e.polygonWithArcs(A.brep_shape)},x$e=(e,A)=>{switch(A.pcb_drawing_type){case"line":return JQt(e,A);case"text":return A.is_knockout?d$e(e,A):u$e(e,A);case"rect":return A.ccw_rotation?KQt(e,A):PQt(e,A);case"circle":return f$e(e,A);case"oval":return y$e(e,A);case"pill":return A.ccw_rotation?p$e(e,A):m$e(e,A);case"polygon":return w$e(e,A);case"polygon_with_arcs":return D$e(e,A)}},S$e=(e,A)=>{for(const t of A)x$e(e,t)},b$e={...ad,copper:{...ad.copper,top:Ha(pn.board.pad_front).lighten(.5).toString(),bottom:Ha(pn.board.pad_back).lighten(.5).toString(),inner1:Ha(pn.board.copper.in1).lighten(.5).toString(),inner2:Ha(pn.board.copper.in2).lighten(.5).toString(),inner3:Ha(pn.board.copper.in3).lighten(.5).toString(),inner4:Ha(pn.board.copper.in4).lighten(.5).toString(),inner5:Ha(pn.board.copper.in5).lighten(.5).toString(),inner6:Ha(pn.board.copper.in6).lighten(.5).toString()},soldermask:{...ad.soldermask,top:Ha(pn.board.soldermask.top).lighten(.35).toString(),bottom:Ha(pn.board.soldermask.bottom).lighten(.35).toString()}};function qQt({canvas:e,elements:A,layers:t,realToCanvasMat:i,drawSoldermaskTop:n,drawSoldermaskBottom:o,primitives:s}){const r=new cC(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 cC(e);I.configure({colorOverrides:b$e}),I.realToCanvasMat=i,I.drawElements(c,{layers:t,drawSoldermask:!0,drawSoldermaskTop:n,drawSoldermaskBottom:o,drawBoardMaterial:!1})}var _$e={...ad,silkscreen:{top:pn.board.f_silks,bottom:pn.board.b_silks}};function k$e(e){return e.type.includes("pcb_silkscreen")}function OQt({canvas:e,elements:A,layers:t,realToCanvasMat:i}){const n=new cC(e);n.configure({colorOverrides:_$e}),n.realToCanvasMat=i;const o=A.filter(k$e);n.drawElements(o,{layers:t})}var v$e={...ad,copper:{...ad.copper,top:Ha(pn.board.pad_front).lighten(.5).toString(),bottom:Ha(pn.board.pad_back).lighten(.5).toString()}};function F$e(e){return e.type==="pcb_via"}function WQt({canvas:e,elements:A,layers:t,realToCanvasMat:i,primitives:n,drawSoldermask:o}){const s=A.filter(F$e).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 cC(e);c.realToCanvasMat=i,c.drawElements(g,{layers:t,drawSoldermask:o})}if(a.length>0){const c=new cC(e);c.configure({colorOverrides:v$e}),c.realToCanvasMat=i,c.drawElements(a,{layers:t,drawSoldermask:o})}}var M$e={...ad,courtyard:{top:pn.board.f_crtyd,bottom:pn.board.b_crtyd}};function G$e(e){return e.type==="pcb_courtyard_circle"||e.type==="pcb_courtyard_rect"||e.type==="pcb_courtyard_outline"}function ZQt({canvas:e,elements:A,layers:t,realToCanvasMat:i}){const n=new cC(e);n.configure({colorOverrides:M$e}),n.realToCanvasMat=i;const o=A.filter(G$e);n.drawElements(o,{layers:t})}var R$e=["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"],N$e=({primitives:e,elements:A,transform:t,grid:i,width:n=500,height:o=500})=>{const s=AA.useRef({}),r=rl(l=>l.selected_layer),a=rl(l=>l.is_showing_solder_mask),g=rl(l=>l.is_showing_fabrication_notes),c=rl(l=>l.is_showing_courtyards),I=rl(l=>l.is_showing_silkscreen);return AA.useEffect(()=>{if(!s.current||Object.keys(s.current).length===0)return;const l=Object.fromEntries(Object.entries(s.current).filter(([Q,h])=>!!h));if(Object.keys(l).length===0)return;const B=new PXe(l);t&&(B.transform=t),B.clear(),B.foregroundLayer=r;const C=e.filter(Q=>a||!Q.layer?.includes("soldermask")).filter(Q=>I||!Q.layer?.includes("silkscreen")).filter(Q=>g||!Q.layer?.includes("fabrication")).filter(Q=>Q.layer!=="board").filter(Q=>Q._element?.type!=="pcb_smtpad").filter(Q=>Q._element?.type!=="pcb_plated_hole").filter(Q=>Q._element?.type!=="pcb_via").filter(Q=>Q._element?.type!=="pcb_trace").filter(Q=>Q._element?.type!=="pcb_copper_text");if(S$e(B,C),t){const Q=s.current.top,h=s.current.bottom,E=s.current.inner1,u=s.current.inner2,d=s.current.inner3,f=s.current.inner4,m=s.current.inner5,w=s.current.inner6,D=[{canvas:Q,copperLayer:"top_copper"},{canvas:h,copperLayer:"bottom_copper"},{canvas:E,copperLayer:"inner1_copper"},{canvas:u,copperLayer:"inner2_copper"},{canvas:d,copperLayer:"inner3_copper"},{canvas:f,copperLayer:"inner4_copper"},{canvas:m,copperLayer:"inner5_copper"},{canvas:w,copperLayer:"inner6_copper"}];for(const{canvas:Y,copperLayer:J}of D)Y&&B$e({canvas:Y,elements:A,layers:[J],realToCanvasMat:t,primitives:e});for(const{canvas:Y,copperLayer:J}of D)Y&&XXe({canvas:Y,elements:A,layers:[J],realToCanvasMat:t});Q&&RQt({canvas:Q,elements:A,layers:["top_copper"],realToCanvasMat:t,primitives:e,drawSoldermask:a}),h&&RQt({canvas:h,elements:A,layers:["bottom_copper"],realToCanvasMat:t,primitives:e,drawSoldermask:a}),Q&&VZ({canvas:Q,elements:A,layers:["top_copper"],realToCanvasMat:t}),h&&VZ({canvas:h,elements:A,layers:["bottom_copper"],realToCanvasMat:t});for(const{canvas:Y,copperLayer:J}of D)Y&&a$e({canvas:Y,elements:A,layers:[J],realToCanvasMat:t,primitives:e,drawSoldermask:a});if(Q&&WQt({canvas:Q,elements:A,layers:["top_copper"],realToCanvasMat:t,primitives:e,drawSoldermask:a}),h&&WQt({canvas:h,elements:A,layers:["bottom_copper"],realToCanvasMat:t,primitives:e,drawSoldermask:a}),a){const Y=r==="bottom"?"bottom":"top",J=Y==="top",O=Y==="bottom",W=s.current.soldermask_top;W&&Y==="top"&&qQt({canvas:W,elements:A,layers:["top_soldermask"],realToCanvasMat:t,drawSoldermaskTop:J,drawSoldermaskBottom:O,primitives:e});const z=s.current.soldermask_bottom;z&&Y==="bottom"&&qQt({canvas:z,elements:A,layers:["bottom_soldermask"],realToCanvasMat:t,drawSoldermaskTop:J,drawSoldermaskBottom:O,primitives:e})}Q&&VZ({canvas:Q,elements:A,layers:["top_copper"],realToCanvasMat:t}),h&&VZ({canvas:h,elements:A,layers:["bottom_copper"],realToCanvasMat:t});const x=s.current.drill;if(x&&ZXe({canvas:x,elements:A,layers:["drill"],realToCanvasMat:t}),I){const Y=s.current.top_silkscreen;Y&&OQt({canvas:Y,elements:A,layers:["top_silkscreen"],realToCanvasMat:t});const J=s.current.bottom_silkscreen;J&&OQt({canvas:J,elements:A,layers:["bottom_silkscreen"],realToCanvasMat:t})}if(g){const Y=s.current.top_fabrication;Y&&MQt({canvas:Y,elements:A,layers:["top_fabrication_note"],realToCanvasMat:t});const J=s.current.bottom_fabrication;J&&MQt({canvas:J,elements:A,layers:["bottom_fabrication_note"],realToCanvasMat:t})}const _=s.current.bottom_notes;_&&GQt({canvas:_,elements:A,layers:["bottom_user_note"],realToCanvasMat:t});const b=s.current.top_notes;if(b&&GQt({canvas:b,elements:A,layers:["top_user_note"],realToCanvasMat:t}),c){const Y=s.current.top_courtyard;Y&&ZQt({canvas:Y,elements:A,layers:["top_courtyard"],realToCanvasMat:t});const J=s.current.bottom_courtyard;J&&ZQt({canvas:J,elements:A,layers:["bottom_courtyard"],realToCanvasMat:t})}const R=s.current.board;R&&(o$e({canvas:R,elements:A,layers:[],realToCanvasMat:t,drawSoldermask:a}),jXe({canvas:R,elements:A,layers:[],realToCanvasMat:t,drawSoldermask:a}));const F=s.current.edge_cuts;F&&A$e({canvas:F,elements:A,layers:["edge_cuts"],realToCanvasMat:t});const H=[{canvas:Q,layer:"top"},{canvas:h,layer:"bottom"}];for(const{canvas:Y,layer:J}of H)Y&&e$e({canvas:Y,elements:A,layers:[J],realToCanvasMat:t})}B.orderAndFadeLayers()},[e,A,t,r,a,g,c,I]),Z.jsxs("div",{style:{backgroundColor:"black",width:n,height:o,position:"relative"},children:[Z.jsx(MZ.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:(l,B,C)=>`${MZ.toMMSI(l,C)}, ${MZ.toMMSI(B,C)}`}),R$e.filter(l=>!(!a&&l.includes("soldermask")||!I&&l.includes("silkscreen"))).map(l=>l.replace(/-/g,"")).map((l,B)=>Z.jsx("canvas",{className:`pcb-layer-${l}`,ref:C=>{s.current??={},C?s.current[l]=C:delete s.current[l]},style:{position:"absolute",zIndex:B,left:0,top:0,pointerEvents:"none"},width:n,height:o},l))]})},L$e=.6,U$e=1;hyA(Pze(),1),hyA(oXe(),1);var jZ=["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 VQt(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 tn(sn(A/2,t/2),za(g,o?-g:g),sn(-(s.minX+r/2),-(s.minY+a/2)))}function H$e(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*L$e,o=i*U$e,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 Y$e(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=VQt(t.viewbox,n,o,{padding:t.padding,yFlip:t.yFlip});else{const r=H$e(e),a=e.coordinateSystem==="cartesian";s=VQt(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=Ct(s,{x:r.center.x-a,y:r.center.y-g}),I=Ct(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=Ct(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=Ct(s,r.points[0]);i.moveTo(g.x,g.y);for(let c=1;c<r.points.length;c++){const I=Ct(s,r.points[c]);i.lineTo(I.x,I.y)}if(i.strokeStyle=r.strokeColor||jZ[a%jZ.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=Ct(s,r);i.beginPath(),i.arc(g.x,g.y,3,0,2*Math.PI),i.fillStyle=r.color||jZ[a%jZ.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=Ct(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 J$e=({children:e,transform:A,debugGraphics:t})=>{const i=AA.useRef(null),[n,{width:o,height:s}]=xL(),r=rl(a=>a.is_showing_autorouting);return AA.useEffect(()=>{r&&i.current&&t&&o&&s&&(i.current.width=o,i.current.height=s,Y$e(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},T$e=({children:e,transform:A=Sa(),elements:t=[]})=>{const[i,{width:n,height:o}]=xL(),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=pn.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:Q}=l,h=Ct(A,Q),E=B*Math.abs(A.a),u=C*Math.abs(A.d),d=.1*Math.abs(A.a),f=E+d*2,m=u+d*2,w=h.x-f/2,D=h.y-m/2;a.beginPath(),a.rect(w,D,f,m),a.stroke();const x="Manual Edit Conflict",_=4,b=Math.max(8,Math.min(12,10*Math.abs(A.a)));a.font=`${b}px sans-serif`;const F=a.measureText(x).width+_*2,H=b+_*2,Y=w+(f-F)/2,J=D+m+5;a.fillStyle="rgba(0, 0, 0, 0.7)",a.beginPath(),a.roundRect(Y,J,F,H,3),a.fill(),a.fillStyle=pn.board.drc_warning,a.textAlign="center",a.textBaseline="middle",a.fillText(x,Y+F/2,J+H/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:_c.warnings}})]})},zZ=(e,A,t)=>t(e,A),jQt=(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}},SL=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=zZ(A,o.x,Math.min),t=zZ(t,o.x,Math.max),i=zZ(i,o.y,Math.min),n=zZ(n,o.y,Math.max);return{minX:A,maxX:t,minY:i,maxY:n}},P$e=(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)}),K$e=(e,A)=>e?P$e(e,A):A,q$e=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=SL(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=>jQt(s.x,s.y,e.x,e.y,n));return SL(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=>jQt(s.x,s.y,e.x,e.y,n));return SL(o)}case"polygon":return SL(e.points);case"polygon_with_arcs":{const A=e.brep_shape.outer_ring.vertices.map(t=>({x:t.x,y:t.y}));return SL(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 O$e(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,h=Math.min(C,90-C)>15,E=(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,x=c>0&&I>0,_=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),x&&(m+=Math.cos(f*Math.PI/180)+-20,w+=Math.sin(f*Math.PI/180)+-10),_&&(m+=Math.cos(f*Math.PI/180)*10,w+=Math.sin(f*Math.PI/180)*10);const b=E+m,R=u+w;return{distance:g,screenDistance:l,x:b,y:R,show:g>.01&&l>30&&h}}function W$e(e){const{dimensionStart:A,dimensionEnd:t,screenDimensionStart:i,screenDimensionEnd:n,flipX:o,flipY:s}=e;return AA.useMemo(()=>O$e({dimensionStart:A,dimensionEnd:t,screenDimensionStart:i,screenDimensionEnd:n,flipX:o,flipY:s}),[A,t,i,n,o,s])}var Z$e=(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}},zQt=(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:Z$e(s,e,i)}))},V$e=e=>{switch(e.pcb_drawing_type){case"rect":{const A=e.ccw_rotation??0;return zQt({x:e.x,y:e.y},e.w/2,e.h/2,A)}case"pill":{const A=e.ccw_rotation??0;return zQt({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[]}},j$e=16,x3=5,XQt=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},z$e=({children:e,transform:A,focusOnHover:t=!1,primitives:i=[]})=>{A||(A=Sa());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=rl(J=>J.is_mouse_over_container),B=AA.useCallback(()=>{a&&(g(!1),window.dispatchEvent(new Event("disarm-dimension-tool")))},[a]),[C,Q]=AA.useState({x:0,y:0}),[h,E]=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 J=new Map;for(const O of i){if(!O._element||XQt(O)||O.pcb_drawing_type==="pill"||O.pcb_drawing_type==="rect"&&O.ccw_rotation&&O.ccw_rotation!==0)continue;const W=q$e(O);if(!W)continue;const z=J.get(O._element);J.set(O._element,K$e(z??void 0,W))}return J},[i]),D=AA.useMemo(()=>{const J=[];for(const O of i){if(!O._element||XQt(O))continue;const W=V$e(O);if(W.length!==0)for(const z of W)J.push({anchor:z.anchor,point:z.point,element:O._element})}return J},[i]),x=AA.useMemo(()=>{const J=[];w.forEach((O,W)=>{if(!O)return;const z=(O.minX+O.maxX)/2,tA=(O.minY+O.maxY)/2,aA={top_left:{x:O.minX,y:O.minY},top_center:{x:z,y:O.minY},top_right:{x:O.maxX,y:O.minY},center_left:{x:O.minX,y:tA},center:{x:z,y:tA},center_right:{x:O.maxX,y:tA},bottom_left:{x:O.minX,y:O.maxY},bottom_center:{x:z,y:O.maxY},bottom_right:{x:O.maxX,y:O.maxY}};for(const[eA,oA]of Object.entries(aA))J.push({anchor:eA,point:oA,element:W})});for(const O of D)J.push(O);return J.push({anchor:"origin",point:{x:0,y:0},element:null}),J},[w,D]),_=AA.useMemo(()=>x.map((J,O)=>({...J,id:`${O}-${J.anchor}`,screenPoint:Ct(A,J.point)})),[x,A]),b=AA.useCallback(J=>{if(_.length===0)return{point:J,id:null};const O=Ct(A,J);let W=null;for(const z of _){const tA=z.screenPoint.x-O.x,aA=z.screenPoint.y-O.y,eA=Math.hypot(tA,aA);eA>j$e||(!W||eA<W.distance)&&(W={distance:eA,id:z.id,point:z.point})}return W?{point:W.point,id:W.id}:{point:J,id:null}},[_,A]);AA.useEffect(()=>{const J=W=>{const z=W.target;if(z.tagName==="INPUT"||z.tagName==="TEXTAREA"||z.isContentEditable)return;const tA=d.current?.contains(document.activeElement)||document.activeElement===d.current;if(!(!l&&!tA)){if(W.key==="d"){const aA=b({x:u.current.x,y:u.current.y});Q({x:aA.point.x,y:aA.point.y}),E({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",J),window.addEventListener("arm-dimension-tool",O),()=>{window.removeEventListener("keydown",J),window.removeEventListener("arm-dimension-tool",O),B()}},[l,n,B,b]);const R=Ct(A,C),F=Ct(A,h),H={left:Math.min(R.x,F.x),right:Math.max(R.x,F.x),top:Math.min(R.y,F.y),bottom:Math.max(R.y,F.y),flipX:R.x>F.x,flipY:R.y>F.y,width:0,height:0};H.width=H.right-H.left,H.height=H.bottom-H.top;const Y=W$e({dimensionStart:C,dimensionEnd:h,screenDimensionStart:R,screenDimensionEnd:F,flipX:H.flipX,flipY:H.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:J=>{const O=J.currentTarget.getBoundingClientRect(),W=J.clientX-O.left,z=J.clientY-O.top,tA=Ct($y(A),{x:W,y:z});if(u.current.x=tA.x,u.current.y=tA.y,s){const aA=b(tA);E({x:aA.point.x,y:aA.point.y}),I(eA=>({...eA,end:aA.id}))}},onMouseDown:J=>{const O=J.currentTarget.getBoundingClientRect(),W=J.clientX-O.left,z=J.clientY-O.top,tA=Ct($y(A),{x:W,y:z});if(a&&!n){const aA=b(tA);Q({x:aA.point.x,y:aA.point.y}),E({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:[Y.show&&Z.jsx("div",{style:{position:"absolute",left:Y.x,top:Y.y,color:"red",mixBlendMode:"difference",pointerEvents:"none",fontSize:12,fontFamily:"sans-serif",whiteSpace:"nowrap",zIndex:_c.dimensionOverlay},children:Y.distance.toFixed(2)}),Z.jsx("div",{style:{position:"absolute",left:H.left,width:H.width,textAlign:"center",top:R.y+2,color:"red",mixBlendMode:"difference",pointerEvents:"none",marginTop:H.flipY?0:-20,fontSize:12,fontFamily:"sans-serif",zIndex:_c.dimensionOverlay},children:Math.abs(C.x-h.x).toFixed(2)}),Z.jsx("div",{style:{position:"absolute",left:F.x,height:H.height,display:"flex",flexDirection:"column",justifyContent:"center",top:H.top,color:"red",pointerEvents:"none",mixBlendMode:"difference",fontSize:12,fontFamily:"sans-serif",zIndex:_c.dimensionOverlay},children:Z.jsx("div",{style:{marginLeft:H.flipX?"-100%":4,paddingRight:4},children:Math.abs(C.y-h.y).toFixed(2)})}),Z.jsxs("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none",mixBlendMode:"difference",zIndex:_c.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:R.x,y1:R.y,x2:F.x,y2:F.y,markerEnd:"url(#head)",strokeWidth:1.5,fill:"none",stroke:"red"}),Z.jsx("line",{x1:R.x,y1:R.y,x2:F.x,y2:R.y,strokeWidth:1.5,fill:"none",strokeDasharray:"2,2",stroke:"red"}),Z.jsx("line",{x1:F.x,y1:R.y,x2:F.x,y2:F.y,strokeWidth:1.5,fill:"none",strokeDasharray:"2,2",stroke:"red"})]}),s&&_.map(J=>{const O=J.id===c.start||J.id===c.end,W=x3/2;return Z.jsxs("svg",{width:x3,height:x3,style:{position:"absolute",left:J.screenPoint.x-W,top:J.screenPoint.y-W,pointerEvents:"none",zIndex:_c.dimensionOverlay},children:[Z.jsx("line",{x1:0,y1:0,x2:x3,y2:x3,stroke:O?"#66ccff":"white",strokeWidth:1}),Z.jsx("line",{x1:x3,y1:0,x2:0,y2:x3,stroke:O?"#66ccff":"white",strokeWidth:1})]},J.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",{}),"(",h.x.toFixed(2),",",h.y.toFixed(2),")",Z.jsx("br",{}),"dist:"," ",Math.sqrt((h.x-C.x)**2+(h.y-C.y)**2).toFixed(2)]})]})]})},X$e=(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},$$e=({children:e,disabled:A,transform:t,soup:i,cancelPanDrag:n,onCreateEditEvent:o,onModifyEditEvent:s})=>{t||(t=Sa());const r=AA.useRef(null),[a,g]=AA.useState(null),[c,I]=AA.useState(null),l=a!==null;rl(h=>h.in_edit_mode);const B=rl(h=>h.in_move_footprint_mode),C=rl(h=>h.setIsMovingComponent),Q=A||!B;return Z.jsxs("div",{ref:r,style:{position:"relative",overflow:"hidden"},onMouseDown:h=>{if(Q)return;const E=h.currentTarget.getBoundingClientRect(),u=h.clientX-E.left,d=h.clientY-E.top;if(Number.isNaN(u)||Number.isNaN(d))return;const f=Ct($y(t),{x:u,y:d});let m=!1;for(const w of i)if(w.type==="pcb_component"&&X$e(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 h.preventDefault(),!1},onMouseMove:h=>{if(!a||!c)return;const E=h.currentTarget.getBoundingClientRect(),u=h.clientX-E.left,d=h.clientY-E.top;if(Number.isNaN(u)||Number.isNaN(d))return;const f=Ct($y(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:h=>{a&&(g(null),C(!1),c&&(s({edit_event_id:c.edit_event_id,in_progress:!1}),I(null)))},children:[e,!Q&&i.filter(h=>h.type==="pcb_component").map(h=>{if(!h?.center)return null;const E=Ct(t,h.center);return Z.jsx("div",{style:{position:"absolute",pointerEvents:"none",left:E.x,top:E.y,width:h.width*t.a+20,height:h.height*t.a+20,transform:"translate(-50%, -50%)",background:l&&a===h.pcb_component_id?"rgba(255, 0, 0, 0.2)":""}},h.pcb_component_id)})]})},AAi=({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:gM`
|
|
5433
5433
|
display: flex;
|
|
5434
5434
|
flex-direction: column;
|
|
5435
5435
|
font-family: sans-serif;
|
|
@@ -5468,7 +5468,7 @@ $1`).replace(/>(\s*)(?=<!--\s*\/)/g,"> ")}}});function wQt(e,A,t){if(!A||!t)retu
|
|
|
5468
5468
|
transition: opacity 0.2s;
|
|
5469
5469
|
margin-bottom: 10px;
|
|
5470
5470
|
color: red;
|
|
5471
|
-
`,sAi=({children:e,transform:A=Sa(),elements:t})=>{const i=AA.useRef(null),{isShowingDRCErrors:n,hoveredErrorId:o}=rl(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,Q=t?X2(t).pcb_trace.get(l):void 0,h=g.pcb_trace_error_id||`error_${c}_${g.error_type}_${g.message?.slice(0,20)}`,E=o===h;if(B&&C){const u=Ct(A,{x:B.x,y:B.y}),d=Ct(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=wyA(m,i);return Z.jsxs(AA.Fragment,{children:[Z.jsx(nAi,{screenPort1:u,screenPort2:d,errorCenter:m,canLineBeDrawn:f,isHighlighted:E}),Z.jsx("div",{style:{position:"absolute",left:m.x-15,top:m.y-15,width:30,height:30,zIndex:_c.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:D=>{const x=D.currentTarget.nextElementSibling;if(x){const _=x.querySelector(".error-message");_&&(_.style.opacity="1")}},onMouseLeave:D=>{if(!E){const x=D.currentTarget.nextElementSibling;if(x){const _=x.querySelector(".error-message");_&&(_.style.opacity="0")}}}}),Z.jsx("div",{style:{position:"absolute",zIndex:E?200:100,left:w.left,top:w.top,color:E?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:n||E?"flex":"none",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:w.transform},children:Z.jsx("div",{className:`error-message ${DyA}`,style:{opacity:E?1:0,border:`1px solid ${E?"#ff4444":"red"}`},children:g.message})})]},h)}if(Q?.route&&(n||E)){const u=Q.route.map(w=>Ct(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=wyA(f,i);return Z.jsxs(AA.Fragment,{children:[Z.jsx(oAi,{points:u,errorCenter:f,isHighlighted:E}),Z.jsx("div",{style:{position:"absolute",left:f.x-15,top:f.y-15,width:30,height:30,zIndex:_c.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:w=>{const D=w.currentTarget.nextElementSibling;if(D){const x=D.querySelector(".error-message");x&&(x.style.opacity="1")}},onMouseLeave:w=>{if(!E){const D=w.currentTarget.nextElementSibling;if(D){const x=D.querySelector(".error-message");x&&(x.style.opacity="0")}}}}),Z.jsx("div",{style:{position:"absolute",zIndex:E?_c.errorOverlay+10:_c.errorOverlay+1,left:m.left,top:m.top,color:E?"#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 ${DyA}`,style:{opacity:E?1:0,border:`1px solid ${E?"#ff4444":"red"}`},children:g.message})})]},h)}return null}),r.map((g,c)=>{const I=g.component_name||g.message?.match(/name "([^"]+)"/)?.[1];if(!I)return null;const l=t?.filter(Q=>Q.type==="source_component"&&Q.name===I||Q.type==="pcb_component"&&t?.find(h=>h.type==="source_component"&&h.source_component_id===Q.source_component_id&&h.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((Q,h)=>{let E={x:0,y:0};if(Q.type==="pcb_component")E=Q.center||{x:0,y:0};else if(Q.type==="source_component"){const _=t?.find(b=>b.type==="pcb_component"&&b.source_component_id===Q.source_component_id);_&&_.type==="pcb_component"&&(E=_.center||{x:0,y:0})}const u=Ct(A,E);if(isNaN(u.x)||isNaN(u.y))return null;const d=Math.abs(A.a),D=Math.max(8,Math.min(30,.5*d)),x=wyA(u,i);return Z.jsxs(AA.Fragment,{children:[Z.jsx("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none",mixBlendMode:"difference",zIndex:_c.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:_c.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:_=>{const b=_.currentTarget.nextElementSibling;if(b){const R=b.querySelector(".error-message");R&&(R.style.opacity="1")}},onMouseLeave:_=>{if(!C){const b=_.currentTarget.nextElementSibling;if(b){const R=b.querySelector(".error-message");R&&(R.style.opacity="0")}}}}),Z.jsx("div",{style:{position:"absolute",zIndex:C?_c.errorOverlay+20:_c.errorOverlay+10,left:x.left,top:x.top,color:C?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:n||C?"flex":"none",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:x.transform},children:Z.jsx("div",{className:`error-message ${DyA}`,style:{opacity:C?1:0,border:`1px solid ${C?"#ff4444":"red"}`},children:g.message})})]},`${B}_${h}`)})})]})};function rAi(e,A){return e.size!==A.size?!1:Array.from(e).every(t=>A.has(t))}function aAi({primitiveElement:e,elements:A}){let t=e.trace_length?`${e.trace_length.toFixed(3)}`:"";const i=X2(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 gAi(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 cAi={position:"absolute",left:0,top:0,pointerEvents:"none",color:"red",fontFamily:"sans-serif",fontSize:12,textShadow:"0 0 2px black"},IAi=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""}},lAi={top:"red",bottom:"aqua"},BAi=({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=lAi[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 h=aAi({primitiveElement:o,elements:t});if(!h)return null;const E=A.y-35;return Z.jsx("div",{style:{zIndex:_c.elementOverlay,position:"absolute",left:A.x,top:E,color:l,pointerEvents:"none",transform:"translateX(-50%)"},children:Z.jsx("div",{style:{backgroundColor:"#f2efcc",color:h.isOverLength?"red":"black",textShadow:"none",WebkitFontSmoothing:"antialiased",MozOsxFontSmoothing:"grayscale",padding:"6px 6px",borderRadius:"6px",fontSize:"14px",minWidth:"45px",textAlign:"center",whiteSpace:"nowrap"},children:h.text})})}const C=IAi(e);return C.trim().length===0?null:Z.jsx("div",{style:{zIndex:_c.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})})})},CAi=({highlightedPrimitives:e,mousePos:A,elements:t})=>{const[i,n]=rl(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=gAi({primitives:s,is_showing_multiple_traces_length:n,elements:t}),Z.jsx("div",{style:cAi,children:!i&&s.map((r,a)=>Z.jsx(BAi,{primitive:r,mousePos:A,elements:t},a))})},Nb=e=>e?.type==="pcb_component",$Qt=e=>e?.type==="pcb_group",QAi=e=>e?.type==="pcb_panel",xyA=e=>e?.type==="pcb_board",aI={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},ey={OFFSET_LINE:"white",COMPONENT_MARKER_FILL:"#66ccff",COMPONENT_MARKER_STROKE:"white",LABEL_TEXT:"white"},SyA=({targets:e,transform:A,containerWidth:t,containerHeight:i})=>{if(e.length===0)return null;const n={color:ey.LABEL_TEXT,mixBlendMode:"difference",pointerEvents:"none",fontSize:aI.LABEL_FONT_SIZE,fontFamily:"monospace",fontWeight:"bold"},o=new Map;return e.forEach(s=>{if(!o.has(s.anchor_id)){const r=Ct(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:_c.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=Ct(A,g),l=g.x-r.x,B=g.y-r.y,C=Math.abs(I.x-c.x),Q=Math.abs(I.y-c.y),h=I.y<c.y,E=I.x>c.x,u=h?aI.LABEL_OFFSET_ABOVE:aI.LABEL_OFFSET_BELOW,d=E?aI.LABEL_OFFSET_RIGHT:aI.LABEL_OFFSET_LEFT,f=C>aI.MIN_LINE_LENGTH_FOR_LABEL,m=Q>aI.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:ey.OFFSET_LINE,strokeWidth:aI.LINE_STROKE_WIDTH,strokeDasharray:aI.LINE_DASH_PATTERN}),Z.jsx("line",{x1:I.x,y1:c.y,x2:I.x,y2:I.y,stroke:ey.OFFSET_LINE,strokeWidth:aI.LINE_STROKE_WIDTH,strokeDasharray:aI.LINE_DASH_PATTERN}),s.type==="component"||s.type==="board"?Z.jsx("circle",{cx:I.x,cy:I.y,r:aI.COMPONENT_MARKER_RADIUS,fill:ey.COMPONENT_MARKER_FILL,stroke:ey.COMPONENT_MARKER_STROKE,strokeWidth:1}):Z.jsxs(Z.Fragment,{children:[Z.jsx("line",{x1:I.x-aI.ANCHOR_MARKER_SIZE,y1:I.y,x2:I.x+aI.ANCHOR_MARKER_SIZE,y2:I.y,stroke:ey.OFFSET_LINE,strokeWidth:aI.ANCHOR_MARKER_STROKE_WIDTH}),Z.jsx("line",{x1:I.x,y1:I.y-aI.ANCHOR_MARKER_SIZE,x2:I.x,y2:I.y+aI.ANCHOR_MARKER_SIZE,stroke:ey.OFFSET_LINE,strokeWidth:aI.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:aI.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:E?"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-aI.ANCHOR_MARKER_SIZE,y1:r.y,x2:r.x+aI.ANCHOR_MARKER_SIZE,y2:r.y,stroke:ey.OFFSET_LINE,strokeWidth:aI.ANCHOR_MARKER_STROKE_WIDTH}),Z.jsx("line",{x1:r.x,y1:r.y-aI.ANCHOR_MARKER_SIZE,x2:r.x,y2:r.y+aI.ANCHOR_MARKER_SIZE,stroke:ey.OFFSET_LINE,strokeWidth:aI.ANCHOR_MARKER_STROKE_WIDTH})]},`anchor-${s}`))]})})},hAi=({elements:e,highlightedPrimitives:A,transform:t,containerWidth:i,containerHeight:n})=>{const o=e.filter(E=>xyA(E)),s=e.filter(E=>Nb(E)),r=e.filter(E=>$Qt(E)),a=A.map(E=>Nb(E._parent_pcb_component)?E._parent_pcb_component.pcb_component_id:Nb(E._element)?E._element.pcb_component_id:null).filter(E=>!!E),g=new Set;if(a.forEach(E=>{const u=s.find(d=>d.pcb_component_id===E);u?.pcb_group_id&&g.add(u.pcb_group_id)}),!rl(E=>E.is_showing_group_anchor_offsets)&&a.length===0)return null;const I=s.map(E=>{const u=E.positioned_relative_to_pcb_board_id;if(!u)return null;const d=o.find(f=>f.pcb_board_id===u);return d?{component:E,board:d,type:"component"}:null}).filter(E=>!!E),l=r.map(E=>{const u=E.positioned_relative_to_pcb_board_id;if(!u||!E.center)return null;const d=o.find(f=>f.pcb_board_id===u);return d?{group:E,board:d,type:"group"}:null}).filter(E=>!!E),B=[...I,...l];if(B.length===0)return null;const C=a.length===0,Q=B.filter(E=>E.type==="component"?C||a.includes(E.component.pcb_component_id):C||g.has(E.group.pcb_group_id));if(Q.length===0)return null;const h=Q.map(E=>E.type==="component"?{id:`${E.board.pcb_board_id}-${E.component.pcb_component_id}-${E.type}`,anchor:E.board.center,anchor_id:E.board.pcb_board_id,target:E.component.center,type:"component",display_offset_x:E.component.display_offset_x,display_offset_y:E.component.display_offset_y}:{id:`${E.board.pcb_board_id}-${E.group.pcb_group_id}-${E.type}`,anchor:E.board.center,anchor_id:E.board.pcb_board_id,target:{x:E.group.anchor_position?.x??E.group.center.x,y:E.group.anchor_position?.y??E.group.center.y},type:"group",display_offset_x:E.group.display_offset_x,display_offset_y:E.group.display_offset_y}).filter(E=>!!E);return Z.jsx(SyA,{targets:h,transform:t,containerWidth:i,containerHeight:n})},EAi=({elements:e,highlightedPrimitives:A,transform:t,containerWidth:i,containerHeight:n})=>{const o=e.filter(E=>$Qt(E)),s=e.filter(E=>Nb(E)),r=A.map(E=>Nb(E._parent_pcb_component)?E._parent_pcb_component.pcb_component_id:Nb(E._element)?E._element.pcb_component_id:null).filter(E=>!!E),a=(E,u)=>{if(u.has(E))return;u.add(E);const d=o.find(f=>f.pcb_group_id===E);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(E=>{const u=s.find(d=>d.pcb_component_id===E);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))}),!rl(E=>E.is_showing_group_anchor_offsets)&&r.length===0)return null;const I=s.map(E=>{if(E.position_mode==="relative_to_group_anchor"&&E.positioned_relative_to_pcb_group_id){const u=o.find(d=>d.pcb_group_id===E.positioned_relative_to_pcb_group_id);return u&&u.anchor_position?{component:E,parentGroup:u,type:"component"}:null}if(E.pcb_group_id){const u=o.find(d=>d.pcb_group_id===E.pcb_group_id);return u&&u.anchor_position?{component:E,parentGroup:u,type:"component"}:null}return null}).filter(E=>!!E),l=o.map(E=>{if(E.position_mode==="relative_to_group_anchor"&&E.positioned_relative_to_pcb_group_id){const u=o.find(d=>d.pcb_group_id===E.positioned_relative_to_pcb_group_id);if(u&&u.anchor_position&&E.anchor_position)return{group:E,parentGroup:u,type:"group"}}return null}).filter(E=>!!E),B=[...I,...l];if(B.length===0)return null;const C=r.length===0,Q=B.filter(E=>E.type==="component"?C||r.includes(E.component.pcb_component_id):C||g.has(E.group.pcb_group_id)||g.has(E.parentGroup.pcb_group_id));if(Q.length===0)return null;const h=Q.map(E=>{const u=E.parentGroup.anchor_position;return u?E.type==="component"?E.component.center?{id:`${E.parentGroup.pcb_group_id}-${E.component.pcb_component_id}-${E.type}`,anchor:u,anchor_id:E.parentGroup.pcb_group_id,target:E.component.center,type:"component",display_offset_x:E.component.display_offset_x,display_offset_y:E.component.display_offset_y}:null:E.group.anchor_position?{id:`${E.parentGroup.pcb_group_id}-${E.group.pcb_group_id}-${E.type}`,anchor:u,anchor_id:E.parentGroup.pcb_group_id,target:E.group.anchor_position,type:"group",display_offset_x:E.group.display_offset_x,display_offset_y:E.group.display_offset_y}:null:null}).filter(E=>!!E);return Z.jsx(SyA,{targets:h,transform:t,containerWidth:i,containerHeight:n})},uAi=(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?yyA([e]):yyA(i)},dAi=({elements:e,highlightedPrimitives:A,transform:t,containerWidth:i,containerHeight:n})=>{const o=new Map;for(const r of A)Nb(r._parent_pcb_component)&&o.set(r._parent_pcb_component.pcb_component_id,r._parent_pcb_component),Nb(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=uAi(r,e);if(!a)continue;const g=r.positioned_relative_to_pcb_group_id??r.pcb_group_id,c=g?X2(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:_c.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=Ct(t,{x:a.minX,y:a.maxY}),I=Ct(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=Ct(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:ey.COMPONENT_MARKER_STROKE,strokeWidth:1.5}),Z.jsx("line",{x1:C.x,y1:C.y-6,x2:C.x,y2:C.y+6,stroke:ey.COMPONENT_MARKER_STROKE,strokeWidth:1.5}),Z.jsx("circle",{cx:C.x,cy:C.y,r:aI.COMPONENT_MARKER_RADIUS,fill:ey.COMPONENT_MARKER_FILL,stroke:ey.COMPONENT_MARKER_STROKE,strokeWidth:1})]},r.pcb_component_id)})})})},pAi=({elements:e,highlightedPrimitives:A,transform:t,containerWidth:i,containerHeight:n})=>{const o=e.filter(B=>QAi(B)),s=e.filter(B=>xyA(B)),r=A.map(B=>xyA(B._element)?B._element.pcb_board_id:null).filter(B=>!!B);if(!rl(B=>B.is_showing_group_anchor_offsets)&&r.length===0)return null;const g=s.map(B=>{const C=B.pcb_panel_id,Q=B.position_mode;if(!C||Q!=="relative_to_panel_anchor")return null;const h=o.find(E=>E.pcb_panel_id===C);return h?{board:B,panel:h,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(SyA,{targets:l,transform:t,containerWidth:i,containerHeight:n})},XZ=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}},Aht=(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},fAi=(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=O0({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:pe.parse(g.x),y:pe.parse(g.y)})),a=XZ(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;Aht(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:pe.parse(g.x),y:pe.parse(g.y)})),a=XZ(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;Aht(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},yAi=({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}]=xL(),l=AA.useMemo(()=>{const C=[];for(const Q of o){if(Q._element?.type==="pcb_via"||Q._element?.type==="pcb_component"||Q?.layer==="drill"||Q?.is_hoverable===!1)continue;let h=null,E=0,u=0;if(Q.pcb_drawing_type==="polygon"){const w=XZ(Q.points);if(!w)continue;h=w.center,E=w.width,u=w.height}else if(Q.pcb_drawing_type==="polygon_with_arcs"){const w=Q.brep_shape.outer_ring.vertices.map(x=>({x:x.x,y:x.y})),D=XZ(w);if(!D)continue;h=D.center,E=D.width,u=D.height}else"x"in Q&&"y"in Q&&(h={x:Q.x,y:Q.y},E="w"in Q?Q.w:"r"in Q?Q.r*2:"rX"in Q&&"rY"in Q?Q.rX*2:0,u="h"in Q?Q.h:"r"in Q?Q.r*2:"rX"in Q&&"rY"in Q?Q.rY*2:0);if(!h)continue;const d=Ct(t,h),f={w:E*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({...Q,x:h.x,y:h.y,w:E,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,Q,h,E)=>{a({x:C,y:Q});const u=Ct($y(h),{x:C,y:Q}),d=fAi(E,u,h);rAi(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 Q=C.currentTarget.getBoundingClientRect(),h=C.clientX-Q.left,E=C.clientY-Q.top;B(h,E,t,i)}},onTouchStart:C=>{if(t){const Q=C.touches[0],h=C.currentTarget.getBoundingClientRect(),E=Q.clientX-h.left,u=Q.clientY-h.top;B(E,u,t,i)}},children:[A,Z.jsx(CAi,{elements:e,mousePos:r,highlightedPrimitives:l}),t&&Z.jsxs(Z.Fragment,{children:[Z.jsx(hAi,{elements:e,highlightedPrimitives:l,transform:t,containerWidth:c,containerHeight:I}),Z.jsx(EAi,{elements:e,highlightedPrimitives:l,transform:t,containerWidth:c,containerHeight:I}),Z.jsx(dAi,{elements:e,highlightedPrimitives:l,transform:t,containerWidth:c,containerHeight:I}),Z.jsx(pAi,{elements:e,highlightedPrimitives:l,transform:t,containerWidth:c,containerHeight:I})]})]})},tht=["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)"],mAi=({children:e,transform:A=Sa(),elements:t=[],hoveredComponentIds:i=[]})=>{const[n,{width:o,height:s}]=xL(),r=AA.useRef(null),{is_showing_pcb_groups:a,pcb_group_view_mode:g,is_showing_group_anchor_offsets:c}=rl(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"),Q=t.filter(w=>w.type==="source_group"),h=new Map(Q.map(w=>[w.source_group_id,w])),E=B.filter(w=>{if(w.name?.toLowerCase().includes("subpanel"))return!1;if(g==="all")return!0;if(!w.source_group_id)return!1;const D=h.get(w.source_group_id);return D?D.was_automatically_named!==!0:!1}),u=new Map;Q.forEach(w=>{const D=w;if(D.parent_source_group_id){const x=u.get(D.parent_source_group_id)||[];x.push(w.source_group_id),u.set(D.parent_source_group_id,x)}});const d=w=>{const D=[],x=u.get(w)||[];for(const _ of x)D.push(_),D.push(...d(_));return D},f=w=>{const D=Q.find(x=>x.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)}E.forEach((w,D)=>{let x=C.filter(TA=>TA.pcb_group_id===w.pcb_group_id);if(w.source_group_id){const TA=d(w.source_group_id),OA=B.filter(_A=>_A.source_group_id&&TA.includes(_A.source_group_id));for(const _A of OA){const DA=C.filter(NA=>NA.pcb_group_id===_A.pcb_group_id);x=[...x,...DA]}}let _,b,R,F,H=!1;if(w.center&&w.width&&w.height){H=!0;const TA=w.width/2,OA=w.height/2;_=w.center.x-TA,R=w.center.x+TA,b=w.center.y-OA,F=w.center.y+OA}else if(x.length===0||(_=1/0,b=1/0,R=-1/0,F=-1/0,x.forEach(TA=>{if(TA.center&&typeof TA.width=="number"&&typeof TA.height=="number"){const OA=TA.center.x-TA.width/2,_A=TA.center.x+TA.width/2,DA=TA.center.y+TA.height/2,NA=TA.center.y-TA.height/2;_=Math.min(_,OA),R=Math.max(R,_A),b=Math.min(b,NA),F=Math.max(F,DA)}}),_===1/0||R===-1/0))return;const Y=w.source_group_id?f(w.source_group_id):0,J=w.source_group_id?d(w.source_group_id).length>0:!1;if(!H){const _A=1+(J?.5:0);_-=_A,R+=_A,b-=_A,F+=_A}const O=Ct(A,{x:_,y:F}),W=Ct(A,{x:R,y:F}),z=Ct(A,{x:_,y:b}),tA=Ct(A,{x:R,y:b}),aA=tht[D%tht.length];l.strokeStyle=aA,l.lineWidth=2;const eA=Math.max(4,Math.min(12,8*Math.abs(A.a))),oA=Math.max(2,Math.min(6,4*Math.abs(A.a))),lA=eA*(J?1.3:1),pA=oA;l.setLineDash([lA,pA]),l.beginPath(),l.moveTo(O.x,O.y),l.lineTo(W.x,W.y),l.lineTo(tA.x,tA.y),l.lineTo(z.x,z.y),l.closePath(),l.stroke();const kA=Math.max(8,Math.min(12,10*Math.abs(A.a))),MA=Y==0||Y==1?0:Y*.11,JA=kA*(1-MA),EA=4,bA=w.name||`Group ${D+1}`;l.font=`${JA}px sans-serif`,l.setLineDash([]);const WA=l.measureText(bA).width+EA*2,jA=JA+EA*2,It=O.x-5,mA=O.y-5,gt=3;if(l.fillStyle="rgba(0, 0, 0, 0.8)",l.beginPath(),l.roundRect(It,mA-jA,WA,jA,gt),l.fill(),l.fillStyle=aA,l.textAlign="left",l.textBaseline="middle",l.fillText(bA,It+EA,mA-jA/2),c&&m.has(w.pcb_group_id)&&!!w.anchor_position&&w.anchor_position){const TA=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},OA=Ct(A,TA);l.strokeStyle="white",l.lineWidth=1.5,l.setLineDash([]);const _A=Math.max(4,Math.min(8,6*Math.abs(A.a)));l.beginPath(),l.moveTo(OA.x-_A,OA.y),l.lineTo(OA.x+_A,OA.y),l.stroke(),l.beginPath(),l.moveTo(OA.x,OA.y-_A),l.lineTo(OA.x,OA.y+_A),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:_c.pcbGroupOverlay,display:a?"block":"none"}})]})},wAi=({transform:e,soup:A,children:t})=>{const i=rl(r=>r.is_showing_rats_nest),{netMap:n,idToNetMap:o}=AA.useMemo(()=>FQt(A||[]),[A]),s=AA.useMemo(()=>{if(!A||!i)return[];const r=l=>{const B=X2(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 Q=null,h=1/0;return C.forEach(E=>{const u=r(E);if(u){const d=Math.sqrt((l.x-u.x)**2+(l.y-u.y)**2);d<h&&d>0&&(h=d,Q=u)}}),Q},g=X2(A).pcb_port.list(),c=X2(A).source_trace.list(),I=[];return g.forEach((l,B)=>{const C=o[l.pcb_port_id];let Q=!1;for(const u of c)u.connected_source_port_ids.includes(l.source_port_id)&&u.connected_source_net_ids.length>0&&(Q=!0);if(!C)return;const h={x:l.x,y:l.y},E=a(h,C);E&&I.push({key:`${l.pcb_port_id}-${B}`,startPoint:h,endPoint:E,isInNet:Q})}),I},[A,n,o,i]);return!A||!i?t:(e||(e=Sa()),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:_c.ratsNestOverlay},children:s.map(({key:r,startPoint:a,endPoint:g,isInNet:c})=>{const I=Ct(e,a),l=Ct(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)})})]}))},DAi={version:"1.11.357"},Lb=(e,A,t)=>{const i=rl(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],Q=t?.current?t.current.contains(document.activeElement)||document.activeElement===t.current:!1;(n.current||Q)&&(!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])},xAi=()=>{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},bL=(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"}}},SAi=({name:e,selected:A,onClick:t})=>{const{style:i,...n}=bL(t);return Z.jsxs("div",{className:gM`
|
|
5471
|
+
`,sAi=({children:e,transform:A=Sa(),elements:t})=>{const i=AA.useRef(null),{isShowingDRCErrors:n,hoveredErrorId:o}=rl(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,Q=t?X2(t).pcb_trace.get(l):void 0,h=g.pcb_trace_error_id||`error_${c}_${g.error_type}_${g.message?.slice(0,20)}`,E=o===h;if(B&&C){const u=Ct(A,{x:B.x,y:B.y}),d=Ct(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=wyA(m,i);return Z.jsxs(AA.Fragment,{children:[Z.jsx(nAi,{screenPort1:u,screenPort2:d,errorCenter:m,canLineBeDrawn:f,isHighlighted:E}),Z.jsx("div",{style:{position:"absolute",left:m.x-15,top:m.y-15,width:30,height:30,zIndex:_c.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:D=>{const x=D.currentTarget.nextElementSibling;if(x){const _=x.querySelector(".error-message");_&&(_.style.opacity="1")}},onMouseLeave:D=>{if(!E){const x=D.currentTarget.nextElementSibling;if(x){const _=x.querySelector(".error-message");_&&(_.style.opacity="0")}}}}),Z.jsx("div",{style:{position:"absolute",zIndex:E?200:100,left:w.left,top:w.top,color:E?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:n||E?"flex":"none",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:w.transform},children:Z.jsx("div",{className:`error-message ${DyA}`,style:{opacity:E?1:0,border:`1px solid ${E?"#ff4444":"red"}`},children:g.message})})]},h)}if(Q?.route&&(n||E)){const u=Q.route.map(w=>Ct(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=wyA(f,i);return Z.jsxs(AA.Fragment,{children:[Z.jsx(oAi,{points:u,errorCenter:f,isHighlighted:E}),Z.jsx("div",{style:{position:"absolute",left:f.x-15,top:f.y-15,width:30,height:30,zIndex:_c.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:w=>{const D=w.currentTarget.nextElementSibling;if(D){const x=D.querySelector(".error-message");x&&(x.style.opacity="1")}},onMouseLeave:w=>{if(!E){const D=w.currentTarget.nextElementSibling;if(D){const x=D.querySelector(".error-message");x&&(x.style.opacity="0")}}}}),Z.jsx("div",{style:{position:"absolute",zIndex:E?_c.errorOverlay+10:_c.errorOverlay+1,left:m.left,top:m.top,color:E?"#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 ${DyA}`,style:{opacity:E?1:0,border:`1px solid ${E?"#ff4444":"red"}`},children:g.message})})]},h)}return null}),r.map((g,c)=>{const I=g.component_name||g.message?.match(/name "([^"]+)"/)?.[1];if(!I)return null;const l=t?.filter(Q=>Q.type==="source_component"&&Q.name===I||Q.type==="pcb_component"&&t?.find(h=>h.type==="source_component"&&h.source_component_id===Q.source_component_id&&h.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((Q,h)=>{let E={x:0,y:0};if(Q.type==="pcb_component")E=Q.center||{x:0,y:0};else if(Q.type==="source_component"){const _=t?.find(b=>b.type==="pcb_component"&&b.source_component_id===Q.source_component_id);_&&_.type==="pcb_component"&&(E=_.center||{x:0,y:0})}const u=Ct(A,E);if(isNaN(u.x)||isNaN(u.y))return null;const d=Math.abs(A.a),D=Math.max(8,Math.min(30,.5*d)),x=wyA(u,i);return Z.jsxs(AA.Fragment,{children:[Z.jsx("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none",mixBlendMode:"difference",zIndex:_c.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:_c.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:_=>{const b=_.currentTarget.nextElementSibling;if(b){const R=b.querySelector(".error-message");R&&(R.style.opacity="1")}},onMouseLeave:_=>{if(!C){const b=_.currentTarget.nextElementSibling;if(b){const R=b.querySelector(".error-message");R&&(R.style.opacity="0")}}}}),Z.jsx("div",{style:{position:"absolute",zIndex:C?_c.errorOverlay+20:_c.errorOverlay+10,left:x.left,top:x.top,color:C?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:n||C?"flex":"none",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:x.transform},children:Z.jsx("div",{className:`error-message ${DyA}`,style:{opacity:C?1:0,border:`1px solid ${C?"#ff4444":"red"}`},children:g.message})})]},`${B}_${h}`)})})]})};function rAi(e,A){return e.size!==A.size?!1:Array.from(e).every(t=>A.has(t))}function aAi({primitiveElement:e,elements:A}){let t=e.trace_length?`${e.trace_length.toFixed(3)}`:"";const i=X2(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 gAi(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 cAi={position:"absolute",left:0,top:0,pointerEvents:"none",color:"red",fontFamily:"sans-serif",fontSize:12,textShadow:"0 0 2px black"},IAi=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""}},lAi={top:"red",bottom:"aqua"},BAi=({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=lAi[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 h=aAi({primitiveElement:o,elements:t});if(!h)return null;const E=A.y-35;return Z.jsx("div",{style:{zIndex:_c.elementOverlay,position:"absolute",left:A.x,top:E,color:l,pointerEvents:"none",transform:"translateX(-50%)"},children:Z.jsx("div",{style:{backgroundColor:"#f2efcc",color:h.isOverLength?"red":"black",textShadow:"none",WebkitFontSmoothing:"antialiased",MozOsxFontSmoothing:"grayscale",padding:"6px 6px",borderRadius:"6px",fontSize:"14px",minWidth:"45px",textAlign:"center",whiteSpace:"nowrap"},children:h.text})})}const C=IAi(e);return C.trim().length===0?null:Z.jsx("div",{style:{zIndex:_c.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})})})},CAi=({highlightedPrimitives:e,mousePos:A,elements:t})=>{const[i,n]=rl(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=gAi({primitives:s,is_showing_multiple_traces_length:n,elements:t}),Z.jsx("div",{style:cAi,children:!i&&s.map((r,a)=>Z.jsx(BAi,{primitive:r,mousePos:A,elements:t},a))})},Nb=e=>e?.type==="pcb_component",$Qt=e=>e?.type==="pcb_group",QAi=e=>e?.type==="pcb_panel",xyA=e=>e?.type==="pcb_board",aI={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},ey={OFFSET_LINE:"white",COMPONENT_MARKER_FILL:"#66ccff",COMPONENT_MARKER_STROKE:"white",LABEL_TEXT:"white"},SyA=({targets:e,transform:A,containerWidth:t,containerHeight:i})=>{if(e.length===0)return null;const n={color:ey.LABEL_TEXT,mixBlendMode:"difference",pointerEvents:"none",fontSize:aI.LABEL_FONT_SIZE,fontFamily:"monospace",fontWeight:"bold"},o=new Map;return e.forEach(s=>{if(!o.has(s.anchor_id)){const r=Ct(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:_c.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=Ct(A,g),l=g.x-r.x,B=g.y-r.y,C=Math.abs(I.x-c.x),Q=Math.abs(I.y-c.y),h=I.y<c.y,E=I.x>c.x,u=h?aI.LABEL_OFFSET_ABOVE:aI.LABEL_OFFSET_BELOW,d=E?aI.LABEL_OFFSET_RIGHT:aI.LABEL_OFFSET_LEFT,f=C>aI.MIN_LINE_LENGTH_FOR_LABEL,m=Q>aI.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:ey.OFFSET_LINE,strokeWidth:aI.LINE_STROKE_WIDTH,strokeDasharray:aI.LINE_DASH_PATTERN}),Z.jsx("line",{x1:I.x,y1:c.y,x2:I.x,y2:I.y,stroke:ey.OFFSET_LINE,strokeWidth:aI.LINE_STROKE_WIDTH,strokeDasharray:aI.LINE_DASH_PATTERN}),s.type==="component"||s.type==="board"?Z.jsx("circle",{cx:I.x,cy:I.y,r:aI.COMPONENT_MARKER_RADIUS,fill:ey.COMPONENT_MARKER_FILL,stroke:ey.COMPONENT_MARKER_STROKE,strokeWidth:1}):Z.jsxs(Z.Fragment,{children:[Z.jsx("line",{x1:I.x-aI.ANCHOR_MARKER_SIZE,y1:I.y,x2:I.x+aI.ANCHOR_MARKER_SIZE,y2:I.y,stroke:ey.OFFSET_LINE,strokeWidth:aI.ANCHOR_MARKER_STROKE_WIDTH}),Z.jsx("line",{x1:I.x,y1:I.y-aI.ANCHOR_MARKER_SIZE,x2:I.x,y2:I.y+aI.ANCHOR_MARKER_SIZE,stroke:ey.OFFSET_LINE,strokeWidth:aI.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:aI.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:E?"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-aI.ANCHOR_MARKER_SIZE,y1:r.y,x2:r.x+aI.ANCHOR_MARKER_SIZE,y2:r.y,stroke:ey.OFFSET_LINE,strokeWidth:aI.ANCHOR_MARKER_STROKE_WIDTH}),Z.jsx("line",{x1:r.x,y1:r.y-aI.ANCHOR_MARKER_SIZE,x2:r.x,y2:r.y+aI.ANCHOR_MARKER_SIZE,stroke:ey.OFFSET_LINE,strokeWidth:aI.ANCHOR_MARKER_STROKE_WIDTH})]},`anchor-${s}`))]})})},hAi=({elements:e,highlightedPrimitives:A,transform:t,containerWidth:i,containerHeight:n})=>{const o=e.filter(E=>xyA(E)),s=e.filter(E=>Nb(E)),r=e.filter(E=>$Qt(E)),a=A.map(E=>Nb(E._parent_pcb_component)?E._parent_pcb_component.pcb_component_id:Nb(E._element)?E._element.pcb_component_id:null).filter(E=>!!E),g=new Set;if(a.forEach(E=>{const u=s.find(d=>d.pcb_component_id===E);u?.pcb_group_id&&g.add(u.pcb_group_id)}),!rl(E=>E.is_showing_group_anchor_offsets)&&a.length===0)return null;const I=s.map(E=>{const u=E.positioned_relative_to_pcb_board_id;if(!u)return null;const d=o.find(f=>f.pcb_board_id===u);return d?{component:E,board:d,type:"component"}:null}).filter(E=>!!E),l=r.map(E=>{const u=E.positioned_relative_to_pcb_board_id;if(!u||!E.center)return null;const d=o.find(f=>f.pcb_board_id===u);return d?{group:E,board:d,type:"group"}:null}).filter(E=>!!E),B=[...I,...l];if(B.length===0)return null;const C=a.length===0,Q=B.filter(E=>E.type==="component"?C||a.includes(E.component.pcb_component_id):C||g.has(E.group.pcb_group_id));if(Q.length===0)return null;const h=Q.map(E=>E.type==="component"?{id:`${E.board.pcb_board_id}-${E.component.pcb_component_id}-${E.type}`,anchor:E.board.center,anchor_id:E.board.pcb_board_id,target:E.component.center,type:"component",display_offset_x:E.component.display_offset_x,display_offset_y:E.component.display_offset_y}:{id:`${E.board.pcb_board_id}-${E.group.pcb_group_id}-${E.type}`,anchor:E.board.center,anchor_id:E.board.pcb_board_id,target:{x:E.group.anchor_position?.x??E.group.center.x,y:E.group.anchor_position?.y??E.group.center.y},type:"group",display_offset_x:E.group.display_offset_x,display_offset_y:E.group.display_offset_y}).filter(E=>!!E);return Z.jsx(SyA,{targets:h,transform:t,containerWidth:i,containerHeight:n})},EAi=({elements:e,highlightedPrimitives:A,transform:t,containerWidth:i,containerHeight:n})=>{const o=e.filter(E=>$Qt(E)),s=e.filter(E=>Nb(E)),r=A.map(E=>Nb(E._parent_pcb_component)?E._parent_pcb_component.pcb_component_id:Nb(E._element)?E._element.pcb_component_id:null).filter(E=>!!E),a=(E,u)=>{if(u.has(E))return;u.add(E);const d=o.find(f=>f.pcb_group_id===E);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(E=>{const u=s.find(d=>d.pcb_component_id===E);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))}),!rl(E=>E.is_showing_group_anchor_offsets)&&r.length===0)return null;const I=s.map(E=>{if(E.position_mode==="relative_to_group_anchor"&&E.positioned_relative_to_pcb_group_id){const u=o.find(d=>d.pcb_group_id===E.positioned_relative_to_pcb_group_id);return u&&u.anchor_position?{component:E,parentGroup:u,type:"component"}:null}if(E.pcb_group_id){const u=o.find(d=>d.pcb_group_id===E.pcb_group_id);return u&&u.anchor_position?{component:E,parentGroup:u,type:"component"}:null}return null}).filter(E=>!!E),l=o.map(E=>{if(E.position_mode==="relative_to_group_anchor"&&E.positioned_relative_to_pcb_group_id){const u=o.find(d=>d.pcb_group_id===E.positioned_relative_to_pcb_group_id);if(u&&u.anchor_position&&E.anchor_position)return{group:E,parentGroup:u,type:"group"}}return null}).filter(E=>!!E),B=[...I,...l];if(B.length===0)return null;const C=r.length===0,Q=B.filter(E=>E.type==="component"?C||r.includes(E.component.pcb_component_id):C||g.has(E.group.pcb_group_id)||g.has(E.parentGroup.pcb_group_id));if(Q.length===0)return null;const h=Q.map(E=>{const u=E.parentGroup.anchor_position;return u?E.type==="component"?E.component.center?{id:`${E.parentGroup.pcb_group_id}-${E.component.pcb_component_id}-${E.type}`,anchor:u,anchor_id:E.parentGroup.pcb_group_id,target:E.component.center,type:"component",display_offset_x:E.component.display_offset_x,display_offset_y:E.component.display_offset_y}:null:E.group.anchor_position?{id:`${E.parentGroup.pcb_group_id}-${E.group.pcb_group_id}-${E.type}`,anchor:u,anchor_id:E.parentGroup.pcb_group_id,target:E.group.anchor_position,type:"group",display_offset_x:E.group.display_offset_x,display_offset_y:E.group.display_offset_y}:null:null}).filter(E=>!!E);return Z.jsx(SyA,{targets:h,transform:t,containerWidth:i,containerHeight:n})},uAi=(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?yyA([e]):yyA(i)},dAi=({elements:e,highlightedPrimitives:A,transform:t,containerWidth:i,containerHeight:n})=>{const o=new Map;for(const r of A)Nb(r._parent_pcb_component)&&o.set(r._parent_pcb_component.pcb_component_id,r._parent_pcb_component),Nb(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=uAi(r,e);if(!a)continue;const g=r.positioned_relative_to_pcb_group_id??r.pcb_group_id,c=g?X2(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:_c.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=Ct(t,{x:a.minX,y:a.maxY}),I=Ct(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=Ct(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:ey.COMPONENT_MARKER_STROKE,strokeWidth:1.5}),Z.jsx("line",{x1:C.x,y1:C.y-6,x2:C.x,y2:C.y+6,stroke:ey.COMPONENT_MARKER_STROKE,strokeWidth:1.5}),Z.jsx("circle",{cx:C.x,cy:C.y,r:aI.COMPONENT_MARKER_RADIUS,fill:ey.COMPONENT_MARKER_FILL,stroke:ey.COMPONENT_MARKER_STROKE,strokeWidth:1})]},r.pcb_component_id)})})})},pAi=({elements:e,highlightedPrimitives:A,transform:t,containerWidth:i,containerHeight:n})=>{const o=e.filter(B=>QAi(B)),s=e.filter(B=>xyA(B)),r=A.map(B=>xyA(B._element)?B._element.pcb_board_id:null).filter(B=>!!B);if(!rl(B=>B.is_showing_group_anchor_offsets)&&r.length===0)return null;const g=s.map(B=>{const C=B.pcb_panel_id,Q=B.position_mode;if(!C||Q!=="relative_to_panel_anchor")return null;const h=o.find(E=>E.pcb_panel_id===C);return h?{board:B,panel:h,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(SyA,{targets:l,transform:t,containerWidth:i,containerHeight:n})},XZ=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}},Aht=(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},fAi=(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=O0({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:pe.parse(g.x),y:pe.parse(g.y)})),a=XZ(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;Aht(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:pe.parse(g.x),y:pe.parse(g.y)})),a=XZ(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;Aht(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},yAi=({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}]=xL(),l=AA.useMemo(()=>{const C=[];for(const Q of o){if(Q._element?.type==="pcb_via"||Q._element?.type==="pcb_component"||Q?.layer==="drill"||Q?.is_hoverable===!1)continue;let h=null,E=0,u=0;if(Q.pcb_drawing_type==="polygon"){const w=XZ(Q.points);if(!w)continue;h=w.center,E=w.width,u=w.height}else if(Q.pcb_drawing_type==="polygon_with_arcs"){const w=Q.brep_shape.outer_ring.vertices.map(x=>({x:x.x,y:x.y})),D=XZ(w);if(!D)continue;h=D.center,E=D.width,u=D.height}else"x"in Q&&"y"in Q&&(h={x:Q.x,y:Q.y},E="w"in Q?Q.w:"r"in Q?Q.r*2:"rX"in Q&&"rY"in Q?Q.rX*2:0,u="h"in Q?Q.h:"r"in Q?Q.r*2:"rX"in Q&&"rY"in Q?Q.rY*2:0);if(!h)continue;const d=Ct(t,h),f={w:E*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({...Q,x:h.x,y:h.y,w:E,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,Q,h,E)=>{a({x:C,y:Q});const u=Ct($y(h),{x:C,y:Q}),d=fAi(E,u,h);rAi(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 Q=C.currentTarget.getBoundingClientRect(),h=C.clientX-Q.left,E=C.clientY-Q.top;B(h,E,t,i)}},onTouchStart:C=>{if(t){const Q=C.touches[0],h=C.currentTarget.getBoundingClientRect(),E=Q.clientX-h.left,u=Q.clientY-h.top;B(E,u,t,i)}},children:[A,Z.jsx(CAi,{elements:e,mousePos:r,highlightedPrimitives:l}),t&&Z.jsxs(Z.Fragment,{children:[Z.jsx(hAi,{elements:e,highlightedPrimitives:l,transform:t,containerWidth:c,containerHeight:I}),Z.jsx(EAi,{elements:e,highlightedPrimitives:l,transform:t,containerWidth:c,containerHeight:I}),Z.jsx(dAi,{elements:e,highlightedPrimitives:l,transform:t,containerWidth:c,containerHeight:I}),Z.jsx(pAi,{elements:e,highlightedPrimitives:l,transform:t,containerWidth:c,containerHeight:I})]})]})},tht=["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)"],mAi=({children:e,transform:A=Sa(),elements:t=[],hoveredComponentIds:i=[]})=>{const[n,{width:o,height:s}]=xL(),r=AA.useRef(null),{is_showing_pcb_groups:a,pcb_group_view_mode:g,is_showing_group_anchor_offsets:c}=rl(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"),Q=t.filter(w=>w.type==="source_group"),h=new Map(Q.map(w=>[w.source_group_id,w])),E=B.filter(w=>{if(w.name?.toLowerCase().includes("subpanel"))return!1;if(g==="all")return!0;if(!w.source_group_id)return!1;const D=h.get(w.source_group_id);return D?D.was_automatically_named!==!0:!1}),u=new Map;Q.forEach(w=>{const D=w;if(D.parent_source_group_id){const x=u.get(D.parent_source_group_id)||[];x.push(w.source_group_id),u.set(D.parent_source_group_id,x)}});const d=w=>{const D=[],x=u.get(w)||[];for(const _ of x)D.push(_),D.push(...d(_));return D},f=w=>{const D=Q.find(x=>x.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)}E.forEach((w,D)=>{let x=C.filter(TA=>TA.pcb_group_id===w.pcb_group_id);if(w.source_group_id){const TA=d(w.source_group_id),OA=B.filter(_A=>_A.source_group_id&&TA.includes(_A.source_group_id));for(const _A of OA){const DA=C.filter(NA=>NA.pcb_group_id===_A.pcb_group_id);x=[...x,...DA]}}let _,b,R,F,H=!1;if(w.center&&w.width&&w.height){H=!0;const TA=w.width/2,OA=w.height/2;_=w.center.x-TA,R=w.center.x+TA,b=w.center.y-OA,F=w.center.y+OA}else if(x.length===0||(_=1/0,b=1/0,R=-1/0,F=-1/0,x.forEach(TA=>{if(TA.center&&typeof TA.width=="number"&&typeof TA.height=="number"){const OA=TA.center.x-TA.width/2,_A=TA.center.x+TA.width/2,DA=TA.center.y+TA.height/2,NA=TA.center.y-TA.height/2;_=Math.min(_,OA),R=Math.max(R,_A),b=Math.min(b,NA),F=Math.max(F,DA)}}),_===1/0||R===-1/0))return;const Y=w.source_group_id?f(w.source_group_id):0,J=w.source_group_id?d(w.source_group_id).length>0:!1;if(!H){const _A=1+(J?.5:0);_-=_A,R+=_A,b-=_A,F+=_A}const O=Ct(A,{x:_,y:F}),W=Ct(A,{x:R,y:F}),z=Ct(A,{x:_,y:b}),tA=Ct(A,{x:R,y:b}),aA=tht[D%tht.length];l.strokeStyle=aA,l.lineWidth=2;const eA=Math.max(4,Math.min(12,8*Math.abs(A.a))),oA=Math.max(2,Math.min(6,4*Math.abs(A.a))),lA=eA*(J?1.3:1),pA=oA;l.setLineDash([lA,pA]),l.beginPath(),l.moveTo(O.x,O.y),l.lineTo(W.x,W.y),l.lineTo(tA.x,tA.y),l.lineTo(z.x,z.y),l.closePath(),l.stroke();const kA=Math.max(8,Math.min(12,10*Math.abs(A.a))),MA=Y==0||Y==1?0:Y*.11,JA=kA*(1-MA),EA=4,bA=w.name||`Group ${D+1}`;l.font=`${JA}px sans-serif`,l.setLineDash([]);const WA=l.measureText(bA).width+EA*2,jA=JA+EA*2,It=O.x-5,mA=O.y-5,gt=3;if(l.fillStyle="rgba(0, 0, 0, 0.8)",l.beginPath(),l.roundRect(It,mA-jA,WA,jA,gt),l.fill(),l.fillStyle=aA,l.textAlign="left",l.textBaseline="middle",l.fillText(bA,It+EA,mA-jA/2),c&&m.has(w.pcb_group_id)&&!!w.anchor_position&&w.anchor_position){const TA=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},OA=Ct(A,TA);l.strokeStyle="white",l.lineWidth=1.5,l.setLineDash([]);const _A=Math.max(4,Math.min(8,6*Math.abs(A.a)));l.beginPath(),l.moveTo(OA.x-_A,OA.y),l.lineTo(OA.x+_A,OA.y),l.stroke(),l.beginPath(),l.moveTo(OA.x,OA.y-_A),l.lineTo(OA.x,OA.y+_A),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:_c.pcbGroupOverlay,display:a?"block":"none"}})]})},wAi=({transform:e,soup:A,children:t})=>{const i=rl(r=>r.is_showing_rats_nest),{netMap:n,idToNetMap:o}=AA.useMemo(()=>FQt(A||[]),[A]),s=AA.useMemo(()=>{if(!A||!i)return[];const r=l=>{const B=X2(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 Q=null,h=1/0;return C.forEach(E=>{const u=r(E);if(u){const d=Math.sqrt((l.x-u.x)**2+(l.y-u.y)**2);d<h&&d>0&&(h=d,Q=u)}}),Q},g=X2(A).pcb_port.list(),c=X2(A).source_trace.list(),I=[];return g.forEach((l,B)=>{const C=o[l.pcb_port_id];let Q=!1;for(const u of c)u.connected_source_port_ids.includes(l.source_port_id)&&u.connected_source_net_ids.length>0&&(Q=!0);if(!C)return;const h={x:l.x,y:l.y},E=a(h,C);E&&I.push({key:`${l.pcb_port_id}-${B}`,startPoint:h,endPoint:E,isInNet:Q})}),I},[A,n,o,i]);return!A||!i?t:(e||(e=Sa()),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:_c.ratsNestOverlay},children:s.map(({key:r,startPoint:a,endPoint:g,isInNet:c})=>{const I=Ct(e,a),l=Ct(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)})})]}))},DAi={version:"1.11.358"},Lb=(e,A,t)=>{const i=rl(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],Q=t?.current?t.current.contains(document.activeElement)||document.activeElement===t.current:!1;(n.current||Q)&&(!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])},xAi=()=>{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},bL=(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"}}},SAi=({name:e,selected:A,onClick:t})=>{const{style:i,...n}=bL(t);return Z.jsxs("div",{className:gM`
|
|
5472
5472
|
margin-top: 2px;
|
|
5473
5473
|
padding: 4px;
|
|
5474
5474
|
padding-left: 8px;
|
|
@@ -5685,7 +5685,7 @@ test("${g} should solve problem correctly", () => {
|
|
|
5685
5685
|
// Add more specific assertions based on expected output
|
|
5686
5686
|
// expect(solver.netLabelPlacementSolver!.netLabelPlacements).toMatchInlineSnapshot()
|
|
5687
5687
|
})
|
|
5688
|
-
`,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"})]})]})},lht=e=>e.activeSubSolver?[e,...lht(e.activeSubSolver)]:[e],Aei=({solver:e})=>{const A=lht(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($ti,{solver:t})]},t.constructor.name))})},tei=({solver:e,triggerRender:A,animationSpeed:t=25,onSolverStarted:i,onSolverCompleted:n})=>{const[o,s]=AA.useReducer(Q=>!Q,!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 Q=e;if(Q.getCurrentPhase&&!e.solved&&!e.failed){const h=Q.getCurrentPhase();for(;Q.getCurrentPhase()===h&&!e.solved&&!e.failed;)e.step();A()}},l=()=>{if(e.solved||e.failed||o)return;const Q=window.prompt("Step until which iteration?",`${e.iterations}`);if(Q===null)return;const h=Number(Q);if(!Number.isFinite(h)){window.alert("Please enter a valid number for the iteration");return}for(;e.iterations<h&&!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(Aei,{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]})]})},eei=(e,A,t)=>{const i=e.currentPipelineStepIndex;return A<i?"Completed":A===i&&e.activeSubSolver?e.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},iei=(e,A)=>{const i=e.pipelineDef[A].solverName,n=eei(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}},nei=({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})},oei=({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,"%"]})]})},sei=e=>Object.entries(e).map(([A,t])=>`${A}: ${t}`).join(", "),rei=({stats:e})=>{if(!e||Object.keys(e).length===0)return Z.jsx("span",{children:"-"});const A=Object.entries(e),t=sei(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))})]})},RyA=e=>{if(e===null||typeof e!="object")return e;if(Array.isArray(e))return e.map(RyA);const A={};for(const[t,i]of Object.entries(e))t.startsWith("_")||(A[t]=RyA(i));return A},aei=(e,A)=>{try{if(typeof e.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${A}`);return}const t=RyA(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)}`)}},gei=({solver:e,onStepUntilPhase:A,onDownloadInput:t})=>{const i=e.pipelineDef.map((r,a)=>iei(e,a)),n=r=>{A?.(r)},o=r=>{r.solverInstance&&(t?t(r.solverInstance,r.name):aei(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(nei,{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(oei,{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(rei,{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))})]})})]})},cei=class extends Qn.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 Iei({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=(h,E)=>{typeof h=="number"&&(h<s&&(s=h),h>a&&(a=h)),typeof E=="number"&&(E<r&&(r=E),E>g&&(g=E))};for(const h of A)c(h.x,h.y);for(const h of t){const E=h.points??[];for(const u of E)c(u.x,u.y)}for(const h of i){const E=h.x??0,u=h.y??0,d=h.width??0,f=h.height??0;c(E,u),c(E+d,u+f)}for(const h of n){const E=h.x??0,u=h.y??0,d=h.radius??1;c(E-d,u-d),c(E+d,u+d)}for(const h of o)c(h.x,h.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),Q=Math.max(1,g-r+2*I);return Z.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${l} ${B} ${C} ${Q}`,role:"img","aria-label":"Graphics fallback",children:[i.map((h,E)=>Z.jsx("rect",{x:h.x??0,y:h.y??0,width:h.width??0,height:h.height??0,fill:"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1},`rect-${E}`)),t.map((h,E)=>Z.jsx("polyline",{fill:"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1,points:(h.points??[]).map(u=>`${u.x??0},${u.y??0}`).join(" ")},`line-${E}`)),n.map((h,E)=>Z.jsx("circle",{cx:h.x??0,cy:h.y??0,r:h.radius??1.5,fill:h.fillColor??"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1},`circle-${E}`)),A.map((h,E)=>Z.jsx("circle",{cx:h.x??0,cy:h.y??0,r:h.radius??1.5,fill:h.color??"black"},`point-${E}`)),o.map((h,E)=>Z.jsx("text",{x:h.x??0,y:h.y??0,fontSize:h.fontSize??10,fill:h.color??"black",children:h.text??""},`text-${E}`))]})}var lei=({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(tei,{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(cei,{fallback:Z.jsx(Iei,{graphics:s}),children:Z.jsx(Xti,{graphics:s})}),a&&Z.jsx(gei,{solver:e,onStepUntilPhase:g})]})};const Bei=()=>{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)},[])},Cei=e=>e.toLowerCase().includes("pack")?NLe:e.toLowerCase().includes("rout")?TLe:SLe,Qei=({solverEvents:e=[]})=>{const[A,t]=AA.useState(null);Bei();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=AcA[o.solverName];if(!r)return{instance:null,error:`Solver class "${o.solverName}" not found in SOLVERS registry. Available: ${Object.keys(AcA).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=Cei(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(zD,{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(lei,{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"})})})]})},Bht=({errorMessage:e,errorStack:A,circuitJsonErrors:t})=>{AA.useEffect(()=>{if(e){const i=new Error(e);A&&(i.stack=A);try{hH.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{hH.captureException(n,{error_type:i.type})}catch{}}},[t])},Cht="0.0.1762",hei={version:Cht},NyA={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1},LyA=new Map,iV=e=>{const A=LyA.get(e);return A?Object.fromEntries(Object.entries(A.stores).map(([t,i])=>[t,i.getState()])):{}},Eei=(e,A,t)=>{if(e===void 0)return{type:"untracked",connection:A.connect(t)};const i=LyA.get(t.name);if(i)return{type:"tracked",store:e,...i};const n={connection:A.connect(t),stores:{}};return LyA.set(t.name,n),{type:"tracked",store:e,...n}},Qht=(e,A={})=>(t,i,n)=>{const{enabled:o,anonymousActionType:s,store:r,...a}=A;let g;try{g=(o??(NyA?"production":void 0)!=="production")&&window.__REDUX_DEVTOOLS_EXTENSION__}catch{}if(!g)return(NyA?"production":void 0)!=="production"&&o&&console.warn("[zustand devtools middleware] Please install/enable Redux devtools extension"),e(t,i,n);const{connection:c,...I}=Eei(r,g,a);let l=!0;n.setState=(Q,h,E)=>{const u=t(Q,h);if(!l)return u;const d=E===void 0?{type:s||"anonymous"}:typeof E=="string"?{type:E}:E;return r===void 0?(c?.send(d,i()),u):(c?.send({...d,type:`${r}/${d.type}`},{...iV(a.name),[r]:n.getState()}),u)};const B=(...Q)=>{const h=l;l=!1,t(...Q),l=h},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(([Q,h])=>[Q,Q===I.store?C:h.getState()])))),n.dispatchFromDevtools&&typeof n.dispatch=="function"){let Q=!1;const h=n.dispatch;n.dispatch=(...E)=>{(NyA?"production":void 0)!=="production"&&E[0].type==="__setState"&&!Q&&(console.warn('[zustand devtools middleware] "__setState" action type is reserved to set state from the devtools. Avoid using it.'),Q=!0),h(...E)}}return c.subscribe(Q=>{var h;switch(Q.type){case"ACTION":if(typeof Q.payload!="string"){console.error("[zustand devtools middleware] Unsupported action format");return}return UyA(Q.payload,E=>{if(E.type==="__setState"){if(r===void 0){B(E.state);return}Object.keys(E.state).length!==1&&console.error(`
|
|
5688
|
+
`,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"})]})]})},lht=e=>e.activeSubSolver?[e,...lht(e.activeSubSolver)]:[e],Aei=({solver:e})=>{const A=lht(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($ti,{solver:t})]},t.constructor.name))})},tei=({solver:e,triggerRender:A,animationSpeed:t=25,onSolverStarted:i,onSolverCompleted:n})=>{const[o,s]=AA.useReducer(Q=>!Q,!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 Q=e;if(Q.getCurrentPhase&&!e.solved&&!e.failed){const h=Q.getCurrentPhase();for(;Q.getCurrentPhase()===h&&!e.solved&&!e.failed;)e.step();A()}},l=()=>{if(e.solved||e.failed||o)return;const Q=window.prompt("Step until which iteration?",`${e.iterations}`);if(Q===null)return;const h=Number(Q);if(!Number.isFinite(h)){window.alert("Please enter a valid number for the iteration");return}for(;e.iterations<h&&!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(Aei,{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]})]})},eei=(e,A,t)=>{const i=e.currentPipelineStepIndex;return A<i?"Completed":A===i&&e.activeSubSolver?e.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},iei=(e,A)=>{const i=e.pipelineDef[A].solverName,n=eei(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}},nei=({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})},oei=({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,"%"]})]})},sei=e=>Object.entries(e).map(([A,t])=>`${A}: ${t}`).join(", "),rei=({stats:e})=>{if(!e||Object.keys(e).length===0)return Z.jsx("span",{children:"-"});const A=Object.entries(e),t=sei(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))})]})},RyA=e=>{if(e===null||typeof e!="object")return e;if(Array.isArray(e))return e.map(RyA);const A={};for(const[t,i]of Object.entries(e))t.startsWith("_")||(A[t]=RyA(i));return A},aei=(e,A)=>{try{if(typeof e.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${A}`);return}const t=RyA(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)}`)}},gei=({solver:e,onStepUntilPhase:A,onDownloadInput:t})=>{const i=e.pipelineDef.map((r,a)=>iei(e,a)),n=r=>{A?.(r)},o=r=>{r.solverInstance&&(t?t(r.solverInstance,r.name):aei(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(nei,{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(oei,{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(rei,{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))})]})})]})},cei=class extends Qn.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 Iei({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=(h,E)=>{typeof h=="number"&&(h<s&&(s=h),h>a&&(a=h)),typeof E=="number"&&(E<r&&(r=E),E>g&&(g=E))};for(const h of A)c(h.x,h.y);for(const h of t){const E=h.points??[];for(const u of E)c(u.x,u.y)}for(const h of i){const E=h.x??0,u=h.y??0,d=h.width??0,f=h.height??0;c(E,u),c(E+d,u+f)}for(const h of n){const E=h.x??0,u=h.y??0,d=h.radius??1;c(E-d,u-d),c(E+d,u+d)}for(const h of o)c(h.x,h.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),Q=Math.max(1,g-r+2*I);return Z.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${l} ${B} ${C} ${Q}`,role:"img","aria-label":"Graphics fallback",children:[i.map((h,E)=>Z.jsx("rect",{x:h.x??0,y:h.y??0,width:h.width??0,height:h.height??0,fill:"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1},`rect-${E}`)),t.map((h,E)=>Z.jsx("polyline",{fill:"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1,points:(h.points??[]).map(u=>`${u.x??0},${u.y??0}`).join(" ")},`line-${E}`)),n.map((h,E)=>Z.jsx("circle",{cx:h.x??0,cy:h.y??0,r:h.radius??1.5,fill:h.fillColor??"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1},`circle-${E}`)),A.map((h,E)=>Z.jsx("circle",{cx:h.x??0,cy:h.y??0,r:h.radius??1.5,fill:h.color??"black"},`point-${E}`)),o.map((h,E)=>Z.jsx("text",{x:h.x??0,y:h.y??0,fontSize:h.fontSize??10,fill:h.color??"black",children:h.text??""},`text-${E}`))]})}var lei=({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(tei,{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(cei,{fallback:Z.jsx(Iei,{graphics:s}),children:Z.jsx(Xti,{graphics:s})}),a&&Z.jsx(gei,{solver:e,onStepUntilPhase:g})]})};const Bei=()=>{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)},[])},Cei=e=>e.toLowerCase().includes("pack")?NLe:e.toLowerCase().includes("rout")?TLe:SLe,Qei=({solverEvents:e=[]})=>{const[A,t]=AA.useState(null);Bei();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=AcA[o.solverName];if(!r)return{instance:null,error:`Solver class "${o.solverName}" not found in SOLVERS registry. Available: ${Object.keys(AcA).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=Cei(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(zD,{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(lei,{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"})})})]})},Bht=({errorMessage:e,errorStack:A,circuitJsonErrors:t})=>{AA.useEffect(()=>{if(e){const i=new Error(e);A&&(i.stack=A);try{hH.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{hH.captureException(n,{error_type:i.type})}catch{}}},[t])},Cht="0.0.1764",hei={version:Cht},NyA={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1},LyA=new Map,iV=e=>{const A=LyA.get(e);return A?Object.fromEntries(Object.entries(A.stores).map(([t,i])=>[t,i.getState()])):{}},Eei=(e,A,t)=>{if(e===void 0)return{type:"untracked",connection:A.connect(t)};const i=LyA.get(t.name);if(i)return{type:"tracked",store:e,...i};const n={connection:A.connect(t),stores:{}};return LyA.set(t.name,n),{type:"tracked",store:e,...n}},Qht=(e,A={})=>(t,i,n)=>{const{enabled:o,anonymousActionType:s,store:r,...a}=A;let g;try{g=(o??(NyA?"production":void 0)!=="production")&&window.__REDUX_DEVTOOLS_EXTENSION__}catch{}if(!g)return(NyA?"production":void 0)!=="production"&&o&&console.warn("[zustand devtools middleware] Please install/enable Redux devtools extension"),e(t,i,n);const{connection:c,...I}=Eei(r,g,a);let l=!0;n.setState=(Q,h,E)=>{const u=t(Q,h);if(!l)return u;const d=E===void 0?{type:s||"anonymous"}:typeof E=="string"?{type:E}:E;return r===void 0?(c?.send(d,i()),u):(c?.send({...d,type:`${r}/${d.type}`},{...iV(a.name),[r]:n.getState()}),u)};const B=(...Q)=>{const h=l;l=!1,t(...Q),l=h},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(([Q,h])=>[Q,Q===I.store?C:h.getState()])))),n.dispatchFromDevtools&&typeof n.dispatch=="function"){let Q=!1;const h=n.dispatch;n.dispatch=(...E)=>{(NyA?"production":void 0)!=="production"&&E[0].type==="__setState"&&!Q&&(console.warn('[zustand devtools middleware] "__setState" action type is reserved to set state from the devtools. Avoid using it.'),Q=!0),h(...E)}}return c.subscribe(Q=>{var h;switch(Q.type){case"ACTION":if(typeof Q.payload!="string"){console.error("[zustand devtools middleware] Unsupported action format");return}return UyA(Q.payload,E=>{if(E.type==="__setState"){if(r===void 0){B(E.state);return}Object.keys(E.state).length!==1&&console.error(`
|
|
5689
5689
|
[zustand devtools middleware] Unsupported __setState action format.
|
|
5690
5690
|
When using 'store' option in devtools(), the 'state' should have only one key, which is a value of 'store' that was passed in devtools(),
|
|
5691
5691
|
and value of this only key should be a state object. Example: { "type": "__setState", "state": { "abc123Store": { "foo": "bar" } } }
|
|
@@ -5826,7 +5826,7 @@ ${a.join(`
|
|
|
5826
5826
|
`)}};LA.register(GCi);var ift=class ASA extends LA{static token="locked";static parentToken="group";token="locked";value;constructor(A){super(),this.value=A}static fromSexprPrimitives(A){if(A.length===0)return new ASA(!0);const t=Di(A[0]);return new ASA(t==="yes")}getString(){return this.value?"(locked yes)":"(locked no)"}};LA.register(ift);var nft=class cxt extends LA{static token="members";static parentToken="group";token="members";members;constructor(A){super(),this.members=A}static fromSexprPrimitives(A){const t=[];for(const i of A){const n=Di(i);n&&t.push(n)}return new cxt(t)}getString(){return this.members.length===0?"(members)":`(members ${this.members.map(t=>`"${t}"`).join(" ")})`}};LA.register(nft);var S1A=class Ixt extends LA{static token="end";static parentToken="segment";token="end";_x;_y;constructor(A,t){super(),this._x=A,this._y=t}static fromSexprPrimitives(A){const[t,i]=A,n=Ci(t),o=Ci(i);if(n===void 0||o===void 0)throw new Error("end expects two numeric arguments");return new Ixt(n,o)}get x(){return this._x}set x(A){this._x=A}get y(){return this._y}set y(A){this._y=A}toObject(){return{x:this._x,y:this._y}}getChildren(){return[]}getString(){return`(end ${this._x} ${this._y})`}};LA.register(S1A);var RCi=new Set(["true","yes","1"]),oft=class Hz extends Wl{static token="locked";static parentToken="segment";token="locked";constructor(A){super(A)}static fromSexprPrimitives(A){const[t]=A;return typeof t=="boolean"?new Hz(t):typeof t=="string"?new Hz(RCi.has(t.toLowerCase())):new Hz(!1)}getString(){return`(locked ${this.value?"yes":"no"})`}};LA.register(oft);var rj=class lxt extends LA{static token="net";static parentToken="segment";token="net";_id;_name;constructor(A,t){super(),this._id=A,this._name=t}static fromSexprPrimitives(A){const[t,i]=A,n=Ci(t);if(n===void 0)throw new Error("net expects a numeric identifier");const o=i===void 0?void 0:Di(i);return new lxt(n,o??void 0)}get id(){return this._id}set id(A){this._id=A}get name(){return this._name}set name(A){this._name=A===""?void 0:A}toObject(){return this._name===void 0?{id:this._id}:{id:this._id,name:this._name}}getChildren(){return[]}getString(){const A=this._name?` ${mn(this._name)}`:"";return`(net ${this._id}${A})`}};LA.register(rj);var b1A=class Bxt extends LA{static token="start";static parentToken="segment";token="start";_x;_y;constructor(A,t){super(),this._x=A,this._y=t}static fromSexprPrimitives(A){const[t,i]=A,n=Ci(t),o=Ci(i);if(n===void 0||o===void 0)throw new Error("start expects two numeric arguments");return new Bxt(n,o)}get x(){return this._x}set x(A){this._x=A}get y(){return this._y}set y(A){this._y=A}toObject(){return{x:this._x,y:this._y}}getChildren(){return[]}getString(){return`(start ${this._x} ${this._y})`}};LA.register(b1A);var sft=new Set(["start","end","width","layer","net","tstamp","uuid","locked"]),_1A=class Cxt extends LA{static token="segment";token="segment";_sxStart;_sxEnd;_sxWidth;_sxLayer;_sxNet;_sxTstamp;_sxUuid;_sxLocked;constructor(A={}){super(),A.start!==void 0&&(this.start=A.start),A.end!==void 0&&(this.end=A.end),A.width!==void 0&&(this.width=A.width),A.layer!==void 0&&(this.layer=A.layer),A.net!==void 0&&(this.net=A.net),A.tstamp!==void 0&&(this.tstamp=A.tstamp),A.uuid!==void 0&&(this.uuid=A.uuid),A.locked!==void 0&&(this.locked=A.locked)}static fromSexprPrimitives(A){const t=new Cxt,{propertyMap:i,arrayPropertyMap:n}=LA.parsePrimitivesToClassProperties(A,this.token),o=Object.keys(i).filter(r=>!sft.has(r));if(o.length>0)throw new Error(`Unsupported child tokens inside segment expression: ${o.join(", ")}`);for(const[r,a]of Object.entries(n)){if(!sft.has(r))throw new Error(`Unsupported child tokens inside segment expression: ${r}`);if(a.length>1)throw new Error(`Segment does not support repeated child tokens: ${r}`)}t._sxStart=n.start?.[0]??i.start,t._sxEnd=n.end?.[0]??i.end,t._sxWidth=n.width?.[0]??i.width,t._sxLayer=n.layer?.[0]??i.layer,t._sxNet=n.net?.[0]??i.net;const s=n.locked?.[0]??i.locked;return t._sxLocked=s&&s.value?s:void 0,t._sxTstamp=n.tstamp?.[0]??i.tstamp,t._sxUuid=n.uuid?.[0]??i.uuid,t}get start(){return this._sxStart}set start(A){this._sxStart=this.normalizeStart(A)}get end(){return this._sxEnd}set end(A){this._sxEnd=this.normalizeEnd(A)}get startPoint(){return this._sxStart?.toObject()}get endPoint(){return this._sxEnd?.toObject()}get width(){return this._sxWidth?.value}set width(A){if(A===void 0){this._sxWidth=void 0;return}this._sxWidth=A instanceof Jr?A:new Jr(A)}get widthClass(){return this._sxWidth}set widthClass(A){this._sxWidth=A}get layer(){return this._sxLayer}set layer(A){if(A===void 0){this._sxLayer=void 0;return}if(A instanceof kr){this._sxLayer=A;return}const t=Array.isArray(A)?A:[A];this._sxLayer=new kr(t)}get net(){return this._sxNet}set net(A){if(A===void 0){this._sxNet=void 0;return}if(A instanceof rj){this._sxNet=A;return}this._sxNet=new rj(A.id,A.name)}get tstamp(){return this._sxTstamp}set tstamp(A){if(A===void 0){this._sxTstamp=void 0;return}this._sxTstamp=A instanceof sc?A:new sc(A)}get uuid(){return this._sxUuid}set uuid(A){if(A===void 0){this._sxUuid=void 0;return}this._sxUuid=A instanceof qi?A:new qi(A)}get locked(){return this._sxLocked?.value??!1}set locked(A){this._sxLocked=A?new oft(!0):void 0}getChildren(){const A=[];return this._sxStart&&A.push(this._sxStart),this._sxEnd&&A.push(this._sxEnd),this._sxWidth&&A.push(this._sxWidth),this._sxLayer&&A.push(this._sxLayer),this._sxNet&&A.push(this._sxNet),this._sxLocked&&A.push(this._sxLocked),this._sxTstamp&&A.push(this._sxTstamp),this._sxUuid&&A.push(this._sxUuid),A}normalizeStart(A){if(A!==void 0)return A instanceof b1A?A:new b1A(A.x,A.y)}normalizeEnd(A){if(A!==void 0)return A instanceof S1A?A:new S1A(A.x,A.y)}};LA.register(_1A);var rft=class Qxt extends LA{static token="zone";token="zone";_rawChildren=[];static fromSexprPrimitives(A){const t=new Qxt;return t._rawChildren=[...A],t}get rawChildren(){return[...this._rawChildren]}set rawChildren(A){this._rawChildren=[...A]}getChildren(){return[]}getString(){const A=["(zone"];for(const t of this._rawChildren)A.push(` ${A0(t)}`);return A.push(")"),A.join(`
|
|
5827
5827
|
`)}};LA.register(rft);var aj=class hxt extends LA{static token="layers";token="layers";_names=[];constructor(A=[]){super(),this.names=A}static fromSexprPrimitives(A){const t=A.map(i=>typeof i=="string"||typeof i=="number"?String(i):A0(i));return new hxt(t)}get names(){return[...this._names]}set names(A){this._names=A.map(t=>String(t))}getString(){return`(layers ${this._names.map(t=>/^[^\s()"]+$/u.test(t)&&!["nil","#t","#f"].includes(t)?t:mn(t)).join(" ")})`}};LA.register(aj);var B6=class extends LA{_value;quoteStringValue=!1;constructor(e){super(),this._value=e}static fromSexprPrimitives(e){const[A]=e,t=this.parsePrimitiveValue(A),i=this;return new i(t)}static parsePrimitiveValue(e){const A=Di(e);if(A===void 0)throw new Error(`${this.name} expects a primitive value`);return A}get value(){return this._value}set value(e){this._value=e}getChildren(){return[]}formatValue(){return typeof this._value=="string"?this.quoteStringValue?mn(this._value):this._value:`${this._value}`}getString(){return`(${this.token} ${this.formatValue()})`}},NCi=class extends LA{_values;constructor(e){super(),this._values=e}static fromSexprPrimitives(e){const A=e.map(i=>{const n=Ci(i);if(n===void 0)throw new Error(`${this.name} expects numeric primitives but received ${i}`);return n}),t=this;return new t(A)}get values(){return[...this._values]}set values(e){this._values=[...e]}getChildren(){return[]}getString(){return`(${this.token} ${this._values.join(" ")})`}},LCi=class extends LA{_x;_y;constructor(e,A){super(),this._x=e,this._y=A}static fromSexprPrimitives(e){const[A,t]=e,i=Ci(A),n=Ci(t);if(i===void 0||n===void 0)throw new Error(`${this.name} expects two numeric values`);const o=this;return new o(i,n)}get x(){return this._x}set x(e){this._x=e}get y(){return this._y}set y(e){this._y=e}getChildren(){return[]}getString(){return`(${this.token} ${this._x} ${this._y})`}},vr=class extends B6{static parentToken="pcbplotparams"},Sm=class extends vr{static parsePrimitiveValue(e){const A=Ci(e);if(A===void 0)throw new Error(`pcbplotparams ${this.token} expects a numeric value`);return A}},aft=class extends vr{static token="layerselection";token="layerselection"};LA.register(aft);var gft=class extends vr{static token="plot_on_all_layers_selection";token="plot_on_all_layers_selection"};LA.register(gft);var cft=class extends Sm{static token="dashed_line_dash_ratio";token="dashed_line_dash_ratio"};LA.register(cft);var Ift=class extends Sm{static token="dashed_line_gap_ratio";token="dashed_line_gap_ratio"};LA.register(Ift);var lft=class extends Sm{static token="svgprecision";token="svgprecision"};LA.register(lft);var Bft=class extends Sm{static token="linewidth";token="linewidth"};LA.register(Bft);var Cft=class extends Sm{static token="mode";token="mode"};LA.register(Cft);var Qft=class extends Sm{static token="hpglpennumber";token="hpglpennumber"};LA.register(Qft);var hft=class extends Sm{static token="hpglpenspeed";token="hpglpenspeed"};LA.register(hft);var Eft=class extends Sm{static token="hpglpendiameter";token="hpglpendiameter"};LA.register(Eft);var uft=class extends Sm{static token="hpglpenoverlay";token="hpglpenoverlay"};LA.register(uft);var dft=class extends Sm{static token="outputformat";token="outputformat"};LA.register(dft);var pft=class extends Sm{static token="drillshape";token="drillshape"};LA.register(pft);var fft=class extends Sm{static token="scaleselection";token="scaleselection"};LA.register(fft);var yft=class extends vr{static token="disableapertmacros";token="disableapertmacros"};LA.register(yft);var mft=class extends vr{static token="usegerberextensions";token="usegerberextensions"};LA.register(mft);var wft=class extends vr{static token="usegerberattributes";token="usegerberattributes"};LA.register(wft);var Dft=class extends vr{static token="usegerberadvancedattributes";token="usegerberadvancedattributes"};LA.register(Dft);var xft=class extends vr{static token="creategerberjobfile";token="creategerberjobfile"};LA.register(xft);var Sft=class extends vr{static token="excludeedgelayer";token="excludeedgelayer"};LA.register(Sft);var bft=class extends vr{static token="plotframeref";token="plotframeref"};LA.register(bft);var _ft=class extends vr{static token="viasonmask";token="viasonmask"};LA.register(_ft);var kft=class extends vr{static token="useauxorigin";token="useauxorigin"};LA.register(kft);var vft=class extends vr{static token="pdf_front_fp_property_popups";token="pdf_front_fp_property_popups"};LA.register(vft);var Fft=class extends vr{static token="pdf_back_fp_property_popups";token="pdf_back_fp_property_popups"};LA.register(Fft);var Mft=class extends vr{static token="pdf_metadata";token="pdf_metadata"};LA.register(Mft);var Gft=class extends vr{static token="pdf_single_document";token="pdf_single_document"};LA.register(Gft);var Rft=class extends vr{static token="dxfpolygonmode";token="dxfpolygonmode"};LA.register(Rft);var Nft=class extends vr{static token="dxfimperialunits";token="dxfimperialunits"};LA.register(Nft);var Lft=class extends vr{static token="dxfusepcbnewfont";token="dxfusepcbnewfont"};LA.register(Lft);var Uft=class extends vr{static token="psnegative";token="psnegative"};LA.register(Uft);var Hft=class extends vr{static token="psa4output";token="psa4output"};LA.register(Hft);var Yft=class extends vr{static token="plotreference";token="plotreference"};LA.register(Yft);var Jft=class extends vr{static token="plotvalue";token="plotvalue"};LA.register(Jft);var Tft=class extends vr{static token="plotothertext";token="plotothertext"};LA.register(Tft);var Pft=class extends vr{static token="plotinvisibletext";token="plotinvisibletext"};LA.register(Pft);var Kft=class extends vr{static token="padsonsilk";token="padsonsilk"};LA.register(Kft);var qft=class extends vr{static token="sketchpadsonfab";token="sketchpadsonfab"};LA.register(qft);var Oft=class extends vr{static token="plotpadnumbers";token="plotpadnumbers"};LA.register(Oft);var Wft=class extends vr{static token="hidednponfab";token="hidednponfab"};LA.register(Wft);var Zft=class extends vr{static token="sketchdnponfab";token="sketchdnponfab"};LA.register(Zft);var Vft=class extends vr{static token="crossoutdnponfab";token="crossoutdnponfab"};LA.register(Vft);var jft=class extends vr{static token="subtractmaskfromsilk";token="subtractmaskfromsilk"};LA.register(jft);var zft=class extends vr{static token="plot_black_and_white";token="plot_black_and_white"};LA.register(zft);var Xft=class extends vr{static token="mirror";token="mirror"};LA.register(Xft);var $ft=class extends vr{static token="outputdirectory";token="outputdirectory";quoteStringValue=!0};LA.register($ft);var Ayt=class extends vr{static token="plot_on_all_layers";token="plot_on_all_layers"};LA.register(Ayt);var tyt=class extends vr{static token="plotinvisible";token="plotinvisible"};LA.register(tyt);var UCi={layerselection:"layerselection",plot_on_all_layers_selection:"plot_on_all_layers_selection",disableapertmacros:"disableapertmacros",usegerberextensions:"usegerberextensions",usegerberattributes:"usegerberattributes",usegerberadvancedattributes:"usegerberadvancedattributes",creategerberjobfile:"creategerberjobfile",excludeedgelayer:"excludeedgelayer",dashed_line_dash_ratio:"dashed_line_dash_ratio",dashed_line_gap_ratio:"dashed_line_gap_ratio",svgprecision:"svgprecision",linewidth:"linewidth",plotframeref:"plotframeref",plotreference:"plotreference",plotvalue:"plotvalue",plotothertext:"plotothertext",plotinvisibletext:"plotinvisibletext",padsonsilk:"padsonsilk",sketchpadsonfab:"sketchpadsonfab",plotpadnumbers:"plotpadnumbers",hidednponfab:"hidednponfab",sketchdnponfab:"sketchdnponfab",crossoutdnponfab:"crossoutdnponfab",subtractmaskfromsilk:"subtractmaskfromsilk",plot_black_and_white:"plot_black_and_white",plot_on_all_layers:"plot_on_all_layers",plotinvisible:"plotinvisible",mode:"mode",useauxorigin:"useauxorigin",viasonmask:"viasonmask",hpglpennumber:"hpglpennumber",hpglpenspeed:"hpglpenspeed",hpglpendiameter:"hpglpendiameter",hpglpenoverlay:"hpglpenoverlay",pdf_front_fp_property_popups:"pdf_front_fp_property_popups",pdf_back_fp_property_popups:"pdf_back_fp_property_popups",pdf_metadata:"pdf_metadata",pdf_single_document:"pdf_single_document",dxfpolygonmode:"dxfpolygonmode",dxfimperialunits:"dxfimperialunits",dxfusepcbnewfont:"dxfusepcbnewfont",psnegative:"psnegative",psa4output:"psa4output",mirror:"mirror",outputformat:"outputformat",drillshape:"drillshape",scaleselection:"scaleselection",outputdirectory:"outputdirectory"},HCi=["layerselection","plot_on_all_layers_selection","disableapertmacros","usegerberextensions","usegerberattributes","usegerberadvancedattributes","creategerberjobfile","excludeedgelayer","dashed_line_dash_ratio","dashed_line_gap_ratio","svgprecision","linewidth","plotframeref","plotreference","plotvalue","plotothertext","mode","useauxorigin","viasonmask","hpglpennumber","hpglpenspeed","hpglpendiameter","hpglpenoverlay","pdf_front_fp_property_popups","pdf_back_fp_property_popups","pdf_metadata","pdf_single_document","dxfpolygonmode","dxfimperialunits","dxfusepcbnewfont","psnegative","psa4output","plot_black_and_white","plot_on_all_layers","plotinvisible","plotinvisibletext","padsonsilk","sketchpadsonfab","plotpadnumbers","hidednponfab","sketchdnponfab","crossoutdnponfab","subtractmaskfromsilk","outputformat","mirror","drillshape","scaleselection","outputdirectory"],k1A=class Ext extends LA{static token="pcbplotparams";static parentToken="setup";token="pcbplotparams";_properties={};static fromSexprPrimitives(A){const t=new Ext,{propertyMap:i}=LA.parsePrimitivesToClassProperties(A,this.token);for(const[n,o]of Object.entries(i)){const s=UCi[n];if(!s)throw new Error(`Unsupported pcbplotparams token: ${n}`);t._properties[s]=o}return t}getChildren(){const A=[];for(const t of HCi){const i=this._properties[t];i&&A.push(i)}return A}clearProperty(A){delete this._properties[A]}setStringProperty(A,t,i){if(t===void 0){this.clearProperty(A);return}this._properties[A]=new i(t)}setNumberProperty(A,t,i){if(t===void 0){this.clearProperty(A);return}this._properties[A]=new i(t)}setStringOrNumberProperty(A,t,i){if(t===void 0){this.clearProperty(A);return}this._properties[A]=new i(t)}get layerselection(){return this._properties.layerselection?.value}set layerselection(A){this.setStringOrNumberProperty("layerselection",A,aft)}get plot_on_all_layers_selection(){return this._properties.plot_on_all_layers_selection?.value}set plot_on_all_layers_selection(A){this.setStringOrNumberProperty("plot_on_all_layers_selection",A,gft)}get disableapertmacros(){return this._properties.disableapertmacros?.value}set disableapertmacros(A){this.setStringProperty("disableapertmacros",A,yft)}get usegerberextensions(){return this._properties.usegerberextensions?.value}set usegerberextensions(A){this.setStringProperty("usegerberextensions",A,mft)}get usegerberattributes(){return this._properties.usegerberattributes?.value}set usegerberattributes(A){this.setStringProperty("usegerberattributes",A,wft)}get usegerberadvancedattributes(){return this._properties.usegerberadvancedattributes?.value}set usegerberadvancedattributes(A){this.setStringProperty("usegerberadvancedattributes",A,Dft)}get creategerberjobfile(){return this._properties.creategerberjobfile?.value}set creategerberjobfile(A){this.setStringProperty("creategerberjobfile",A,xft)}get excludeedgelayer(){return this._properties.excludeedgelayer?.value}set excludeedgelayer(A){this.setStringProperty("excludeedgelayer",A,Sft)}get dashed_line_dash_ratio(){return this._properties.dashed_line_dash_ratio?.value}set dashed_line_dash_ratio(A){this.setNumberProperty("dashed_line_dash_ratio",A,cft)}get dashed_line_gap_ratio(){return this._properties.dashed_line_gap_ratio?.value}set dashed_line_gap_ratio(A){this.setNumberProperty("dashed_line_gap_ratio",A,Ift)}get svgprecision(){return this._properties.svgprecision?.value}set svgprecision(A){this.setNumberProperty("svgprecision",A,lft)}get linewidth(){return this._properties.linewidth?.value}set linewidth(A){this.setNumberProperty("linewidth",A,Bft)}get plotframeref(){return this._properties.plotframeref?.value}set plotframeref(A){this.setStringProperty("plotframeref",A,bft)}get plotreference(){return this._properties.plotreference?.value}set plotreference(A){this.setStringProperty("plotreference",A,Yft)}get plotvalue(){return this._properties.plotvalue?.value}set plotvalue(A){this.setStringProperty("plotvalue",A,Jft)}get plotothertext(){return this._properties.plotothertext?.value}set plotothertext(A){this.setStringProperty("plotothertext",A,Tft)}get plotinvisibletext(){return this._properties.plotinvisibletext?.value}set plotinvisibletext(A){this.setStringProperty("plotinvisibletext",A,Pft)}get padsonsilk(){return this._properties.padsonsilk?.value}set padsonsilk(A){this.setStringProperty("padsonsilk",A,Kft)}get plotpadnumbers(){return this._properties.plotpadnumbers?.value}set plotpadnumbers(A){this.setStringProperty("plotpadnumbers",A,Oft)}get sketchpadsonfab(){return this._properties.sketchpadsonfab?.value}set sketchpadsonfab(A){this.setStringProperty("sketchpadsonfab",A,qft)}get hidednponfab(){return this._properties.hidednponfab?.value}set hidednponfab(A){this.setStringProperty("hidednponfab",A,Wft)}get sketchdnponfab(){return this._properties.sketchdnponfab?.value}set sketchdnponfab(A){this.setStringProperty("sketchdnponfab",A,Zft)}get crossoutdnponfab(){return this._properties.crossoutdnponfab?.value}set crossoutdnponfab(A){this.setStringProperty("crossoutdnponfab",A,Vft)}get subtractmaskfromsilk(){return this._properties.subtractmaskfromsilk?.value}set subtractmaskfromsilk(A){this.setStringProperty("subtractmaskfromsilk",A,jft)}get plot_black_and_white(){return this._properties.plot_black_and_white?.value}set plot_black_and_white(A){this.setStringProperty("plot_black_and_white",A,zft)}get plot_on_all_layers(){return this._properties.plot_on_all_layers?.value}set plot_on_all_layers(A){this.setStringProperty("plot_on_all_layers",A,Ayt)}get plotinvisible(){return this._properties.plotinvisible?.value}set plotinvisible(A){this.setStringProperty("plotinvisible",A,tyt)}get mode(){return this._properties.mode?.value}set mode(A){this.setNumberProperty("mode",A,Cft)}get useauxorigin(){return this._properties.useauxorigin?.value}set useauxorigin(A){this.setStringProperty("useauxorigin",A,kft)}get viasonmask(){return this._properties.viasonmask?.value}set viasonmask(A){this.setStringProperty("viasonmask",A,_ft)}get hpglpennumber(){return this._properties.hpglpennumber?.value}set hpglpennumber(A){this.setNumberProperty("hpglpennumber",A,Qft)}get hpglpenspeed(){return this._properties.hpglpenspeed?.value}set hpglpenspeed(A){this.setNumberProperty("hpglpenspeed",A,hft)}get hpglpendiameter(){return this._properties.hpglpendiameter?.value}set hpglpendiameter(A){this.setNumberProperty("hpglpendiameter",A,Eft)}get hpglpenoverlay(){return this._properties.hpglpenoverlay?.value}set hpglpenoverlay(A){this.setNumberProperty("hpglpenoverlay",A,uft)}get pdf_front_fp_property_popups(){return this._properties.pdf_front_fp_property_popups?.value}set pdf_front_fp_property_popups(A){this.setStringProperty("pdf_front_fp_property_popups",A,vft)}get pdf_back_fp_property_popups(){return this._properties.pdf_back_fp_property_popups?.value}set pdf_back_fp_property_popups(A){this.setStringProperty("pdf_back_fp_property_popups",A,Fft)}get pdf_metadata(){return this._properties.pdf_metadata?.value}set pdf_metadata(A){this.setStringProperty("pdf_metadata",A,Mft)}get pdf_single_document(){return this._properties.pdf_single_document?.value}set pdf_single_document(A){this.setStringProperty("pdf_single_document",A,Gft)}get dxfpolygonmode(){return this._properties.dxfpolygonmode?.value}set dxfpolygonmode(A){this.setStringProperty("dxfpolygonmode",A,Rft)}get dxfimperialunits(){return this._properties.dxfimperialunits?.value}set dxfimperialunits(A){this.setStringProperty("dxfimperialunits",A,Nft)}get dxfusepcbnewfont(){return this._properties.dxfusepcbnewfont?.value}set dxfusepcbnewfont(A){this.setStringProperty("dxfusepcbnewfont",A,Lft)}get psnegative(){return this._properties.psnegative?.value}set psnegative(A){this.setStringProperty("psnegative",A,Uft)}get psa4output(){return this._properties.psa4output?.value}set psa4output(A){this.setStringProperty("psa4output",A,Hft)}get mirror(){return this._properties.mirror?.value}set mirror(A){this.setStringProperty("mirror",A,Xft)}get outputformat(){return this._properties.outputformat?.value}set outputformat(A){this.setNumberProperty("outputformat",A,dft)}get drillshape(){return this._properties.drillshape?.value}set drillshape(A){this.setNumberProperty("drillshape",A,pft)}get scaleselection(){return this._properties.scaleselection?.value}set scaleselection(A){this.setNumberProperty("scaleselection",A,fft)}get outputdirectory(){return this._properties.outputdirectory?.value}set outputdirectory(A){this.setStringProperty("outputdirectory",A,$ft)}};LA.register(k1A);var gj=class extends B6{static parentToken="setup"},v1A=class extends gj{static token="zone_45_only";token="zone_45_only"};LA.register(v1A);var F1A=class extends gj{static token="allow_soldermask_bridges_in_footprints";token="allow_soldermask_bridges_in_footprints"};LA.register(F1A);var M1A=class extends gj{static token="visible_elements";token="visible_elements"};LA.register(M1A);var G1A=class extends gj{static token="uvias_allowed";token="uvias_allowed"};LA.register(G1A);var R1A=class uxt extends LA{static token="tenting";static parentToken="setup";token="tenting";_sides=[];constructor(A=[]){super(),this.sides=A}static fromSexprPrimitives(A){const t=A.map(i=>Di(i)).filter(i=>i!==void 0);return new uxt(t)}get sides(){return[...this._sides]}set sides(A){this._sides=A.map(t=>String(t))}getChildren(){return[]}getString(){return this._sides.length===0?"(tenting)":`(tenting ${this._sides.join(" ")})`}};LA.register(R1A);var C6=class extends NCi{static parentToken="setup"},eyt=class extends LCi{static parentToken="setup"},N1A=class extends C6{static token="pcb_text_size";token="pcb_text_size"};LA.register(N1A);var L1A=class extends C6{static token="mod_text_size";token="mod_text_size"};LA.register(L1A);var U1A=class extends C6{static token="pad_size";token="pad_size"};LA.register(U1A);var H1A=class extends C6{static token="pad_to_paste_clearance_values";token="pad_to_paste_clearance_values"};LA.register(H1A);var Y1A=class extends C6{static token="trace_width";token="trace_width"};LA.register(Y1A);var J1A=class extends eyt{static token="aux_axis_origin";token="aux_axis_origin"};LA.register(J1A);var T1A=class extends eyt{static token="grid_origin";token="grid_origin"};LA.register(T1A);var mB=class extends B6{static parentToken="setup";static parsePrimitiveValue(e){const A=Ci(e);if(A===void 0)throw new Error(`${this.name} expects a numeric value`);return A}},P1A=class extends mB{static token="pad_to_mask_clearance";token="pad_to_mask_clearance"};LA.register(P1A);var K1A=class extends mB{static token="solder_mask_min_width";token="solder_mask_min_width"};LA.register(K1A);var q1A=class extends mB{static token="pad_to_paste_clearance";token="pad_to_paste_clearance"};LA.register(q1A);var O1A=class extends mB{static token="pad_to_paste_clearance_ratio";token="pad_to_paste_clearance_ratio"};LA.register(O1A);var W1A=class extends mB{static token="last_trace_width";token="last_trace_width"};LA.register(W1A);var Z1A=class extends mB{static token="trace_clearance";token="trace_clearance"};LA.register(Z1A);var V1A=class extends mB{static token="zone_clearance";token="zone_clearance"};LA.register(V1A);var j1A=class extends mB{static token="trace_min";token="trace_min"};LA.register(j1A);var z1A=class extends mB{static token="segment_width";token="segment_width"};LA.register(z1A);var X1A=class extends mB{static token="edge_width";token="edge_width"};LA.register(X1A);var $1A=class extends mB{static token="via_size";token="via_size"};LA.register($1A);var A2A=class extends mB{static token="via_drill";token="via_drill"};LA.register(A2A);var t2A=class extends mB{static token="via_min_size";token="via_min_size"};LA.register(t2A);var e2A=class extends mB{static token="via_min_drill";token="via_min_drill"};LA.register(e2A);var i2A=class extends mB{static token="uvia_size";token="uvia_size"};LA.register(i2A);var n2A=class extends mB{static token="uvia_drill";token="uvia_drill"};LA.register(n2A);var o2A=class extends mB{static token="uvia_min_size";token="uvia_min_size"};LA.register(o2A);var s2A=class extends mB{static token="uvia_min_drill";token="uvia_min_drill"};LA.register(s2A);var r2A=class extends mB{static token="pcb_text_width";token="pcb_text_width"};LA.register(r2A);var a2A=class extends mB{static token="mod_edge_width";token="mod_edge_width"};LA.register(a2A);var g2A=class extends mB{static token="mod_text_width";token="mod_text_width"};LA.register(g2A);var c2A=class extends mB{static token="pad_drill";token="pad_drill"};LA.register(c2A);var Q6=class extends B6{static parentToken="stackup"},iyt=class extends Q6{static token="copper_finish";token="copper_finish";quoteStringValue=!0};LA.register(iyt);var nyt=class extends Q6{static token="dielectric_constraints";token="dielectric_constraints"};LA.register(nyt);var oyt=class extends Q6{static token="edge_connector";token="edge_connector"};LA.register(oyt);var syt=class extends Q6{static token="castellated_pads";token="castellated_pads"};LA.register(syt);var ryt=class extends Q6{static token="edge_plating";token="edge_plating"};LA.register(ryt);var HM=class extends B6{static parentToken="layer"},I2A=class extends HM{static token="type";token="type";quoteStringValue=!0};LA.register(I2A);var l2A=class extends HM{static token="color";token="color";quoteStringValue=!0};LA.register(l2A);var B2A=class extends HM{static token="thickness";token="thickness";static parsePrimitiveValue(e){const A=Ci(e);if(A===void 0)throw new Error("Stackup layer thickness expects a numeric value");return A}};LA.register(B2A);var C2A=class extends HM{static token="material";token="material";quoteStringValue=!0};LA.register(C2A);var Q2A=class extends HM{static token="epsilon_r";token="epsilon_r";static parsePrimitiveValue(e){const A=Ci(e);if(A===void 0)throw new Error("Stackup layer epsilon_r expects a numeric value");return A}};LA.register(Q2A);var h2A=class extends HM{static token="loss_tangent";token="loss_tangent";static parsePrimitiveValue(e){const A=Ci(e);if(A===void 0)throw new Error("Stackup layer loss_tangent expects a numeric value");return A}};LA.register(h2A);var ayt=class dxt extends LA{static token="layer";static parentToken="stackup";token="layer";_name;_number;_sxType;_sxColor;_sxThickness;_sxMaterial;_sxEpsilonR;_sxLossTangent;constructor(A,t={}){super(),this._name=A,this._number=t.number,this._sxType=t.type,this._sxColor=t.color,this._sxThickness=t.thickness,this._sxMaterial=t.material,this._sxEpsilonR=t.epsilonR,this._sxLossTangent=t.lossTangent}static fromSexprPrimitives(A){if(A.length===0)throw new Error("Stackup layer requires at least a name");const t=Di(A[0]);if(t===void 0)throw new Error("Stackup layer name must be a string");let i=1,n;const o=A[i],s=Ci(o);s!==void 0&&(n=s,i+=1);const r=A.slice(i),{propertyMap:a}=LA.parsePrimitivesToClassProperties(r,this.token);return new dxt(t,{number:n,type:a.type,color:a.color,thickness:a.thickness,material:a.material,epsilonR:a.epsilon_r,lossTangent:a.loss_tangent})}get name(){return this._name}set name(A){const t=Di(A);if(t===void 0)throw new Error("Stackup layer name must be a string");this._name=t}get number(){return this._number}set number(A){if(A===void 0){this._number=void 0;return}const t=Ci(A);if(t===void 0)throw new Error("Stackup layer number must be numeric");this._number=t}get type(){return this._sxType?.value}set type(A){if(A===void 0){this._sxType=void 0;return}this._sxType=A instanceof I2A?A:new I2A(A)}get color(){return this._sxColor?.value}set color(A){if(A===void 0){this._sxColor=void 0;return}this._sxColor=A instanceof l2A?A:new l2A(A)}get thickness(){return this._sxThickness?.value}set thickness(A){if(A===void 0){this._sxThickness=void 0;return}this._sxThickness=A instanceof B2A?A:new B2A(A)}get material(){return this._sxMaterial?.value}set material(A){if(A===void 0){this._sxMaterial=void 0;return}this._sxMaterial=A instanceof C2A?A:new C2A(A)}get epsilonR(){return this._sxEpsilonR?.value}set epsilonR(A){if(A===void 0){this._sxEpsilonR=void 0;return}this._sxEpsilonR=A instanceof Q2A?A:new Q2A(A)}get lossTangent(){return this._sxLossTangent?.value}set lossTangent(A){if(A===void 0){this._sxLossTangent=void 0;return}this._sxLossTangent=A instanceof h2A?A:new h2A(A)}getChildren(){const A=[];return this._sxType&&A.push(this._sxType),this._sxColor&&A.push(this._sxColor),this._sxThickness&&A.push(this._sxThickness),this._sxMaterial&&A.push(this._sxMaterial),this._sxEpsilonR&&A.push(this._sxEpsilonR),this._sxLossTangent&&A.push(this._sxLossTangent),A}getString(){const A=`(layer ${mn(this._name)}${this._number!==void 0?` ${this._number}`:""}`,t=this.getChildren();if(t.length===0)return`${A})`;const i=[A];for(const n of t)i.push(n.getStringIndented());return i.push(")"),i.join(`
|
|
5828
5828
|
`)}};LA.register(ayt);var E2A=class pxt extends LA{static token="stackup";static parentToken="setup";token="stackup";_layers=[];_sxCopperFinish;_sxDielectricConstraints;_sxEdgeConnector;_sxCastellatedPads;_sxEdgePlating;constructor(A={}){super(),this.layers=A.layers??[],this._sxCopperFinish=A.copperFinish,this._sxDielectricConstraints=A.dielectricConstraints,this._sxEdgeConnector=A.edgeConnector,this._sxCastellatedPads=A.castellatedPads,this._sxEdgePlating=A.edgePlating}static fromSexprPrimitives(A){const{propertyMap:t,arrayPropertyMap:i}=LA.parsePrimitivesToClassProperties(A,this.token);return new pxt({layers:i.layer??[],copperFinish:t.copper_finish,dielectricConstraints:t.dielectric_constraints,edgeConnector:t.edge_connector,castellatedPads:t.castellated_pads,edgePlating:t.edge_plating})}get layers(){return[...this._layers]}set layers(A){this._layers=A.map(t=>{if(!(t instanceof ayt))throw new Error("Stackup layers must be StackupLayer instances");return t})}get copperFinish(){return this._sxCopperFinish?.value}set copperFinish(A){this._sxCopperFinish=A?new iyt(A):void 0}get dielectricConstraints(){return this._sxDielectricConstraints?.value}set dielectricConstraints(A){this._sxDielectricConstraints=A?new nyt(A):void 0}get edgeConnector(){return this._sxEdgeConnector?.value}set edgeConnector(A){this._sxEdgeConnector=A?new oyt(A):void 0}get castellatedPads(){return this._sxCastellatedPads?.value}set castellatedPads(A){this._sxCastellatedPads=A?new syt(A):void 0}get edgePlating(){return this._sxEdgePlating?.value}set edgePlating(A){this._sxEdgePlating=A?new ryt(A):void 0}getChildren(){const A=[...this._layers],t=[this._sxCopperFinish,this._sxDielectricConstraints,this._sxEdgeConnector,this._sxCastellatedPads,this._sxEdgePlating];for(const i of t)i&&A.push(i);return A}};LA.register(E2A);var YCi={stackup:"stackup",pcbplotparams:"pcbPlotParams",pad_to_mask_clearance:"padToMaskClearance",solder_mask_min_width:"solderMaskMinWidth",pad_to_paste_clearance:"padToPasteClearance",pad_to_paste_clearance_ratio:"padToPasteClearanceRatio",last_trace_width:"lastTraceWidth",trace_clearance:"traceClearance",zone_clearance:"zoneClearance",zone_45_only:"zone45Only",trace_min:"traceMin",segment_width:"segmentWidth",edge_width:"edgeWidth",via_size:"viaSize",via_drill:"viaDrill",via_min_size:"viaMinSize",via_min_drill:"viaMinDrill",uvias_allowed:"uviasAllowed",uvia_size:"uviaSize",uvia_drill:"uviaDrill",uvia_min_size:"uviaMinSize",uvia_min_drill:"uviaMinDrill",pcb_text_width:"pcbTextWidth",pcb_text_size:"pcbTextSize",mod_edge_width:"modEdgeWidth",mod_text_size:"modTextSize",mod_text_width:"modTextWidth",pad_size:"padSize",pad_drill:"padDrill",allow_soldermask_bridges_in_footprints:"allowSoldermaskBridgesInFootprints",tenting:"tenting",aux_axis_origin:"auxAxisOrigin",grid_origin:"gridOrigin",visible_elements:"visibleElements",pad_to_paste_clearance_values:"padToPasteClearanceValues",trace_width:"traceWidth"},JCi=["stackup","padToMaskClearance","solderMaskMinWidth","padToPasteClearance","padToPasteClearanceRatio","lastTraceWidth","traceClearance","zoneClearance","zone45Only","traceMin","segmentWidth","edgeWidth","viaSize","viaDrill","viaMinSize","viaMinDrill","uviaSize","uviaDrill","uviasAllowed","uviaMinSize","uviaMinDrill","pcbTextWidth","pcbTextSize","modEdgeWidth","modTextSize","modTextWidth","padSize","padDrill","allowSoldermaskBridgesInFootprints","tenting","auxAxisOrigin","gridOrigin","visibleElements","padToPasteClearanceValues","traceWidth","pcbPlotParams"],u2A=class fxt extends LA{static token="setup";token="setup";_properties={};static fromSexprPrimitives(A){const t=new fxt,{propertyMap:i}=LA.parsePrimitivesToClassProperties(A,this.token);for(const[n,o]of Object.entries(i)){const s=YCi[n];if(!s)throw new Error(`Unsupported setup property token: ${n}`);t._properties[s]=o}return t}getChildren(){const A=[];for(const t of JCi){const i=this._properties[t];i&&A.push(i)}return A}setProperty(A,t){if(t){this._properties[A]=t;return}delete this._properties[A]}setNumberProperty(A,t,i){if(t===void 0){delete this._properties[A];return}this._properties[A]=new i(t)}getPropertyInstance(A,t){const i=this._properties[A];return i instanceof t?i:void 0}get stackup(){return this.getPropertyInstance("stackup",E2A)}set stackup(A){if(A!==void 0&&!(A instanceof E2A))throw new Error("stackup must be a Stackup instance");this.setProperty("stackup",A)}get pcbPlotParams(){return this.getPropertyInstance("pcbPlotParams",k1A)}set pcbPlotParams(A){if(A!==void 0&&!(A instanceof k1A))throw new Error("pcbPlotParams must be a PcbPlotParams instance");this.setProperty("pcbPlotParams",A)}get padToMaskClearance(){return this.getPropertyInstance("padToMaskClearance",P1A)?.value}set padToMaskClearance(A){this.setNumberProperty("padToMaskClearance",A,P1A)}get solderMaskMinWidth(){return this.getPropertyInstance("solderMaskMinWidth",K1A)?.value}set solderMaskMinWidth(A){this.setNumberProperty("solderMaskMinWidth",A,K1A)}get padToPasteClearance(){return this.getPropertyInstance("padToPasteClearance",q1A)?.value}set padToPasteClearance(A){this.setNumberProperty("padToPasteClearance",A,q1A)}get padToPasteClearanceRatio(){return this.getPropertyInstance("padToPasteClearanceRatio",O1A)?.value}set padToPasteClearanceRatio(A){this.setNumberProperty("padToPasteClearanceRatio",A,O1A)}get lastTraceWidth(){return this.getPropertyInstance("lastTraceWidth",W1A)?.value}set lastTraceWidth(A){this.setNumberProperty("lastTraceWidth",A,W1A)}get traceClearance(){return this.getPropertyInstance("traceClearance",Z1A)?.value}set traceClearance(A){this.setNumberProperty("traceClearance",A,Z1A)}get zoneClearance(){return this.getPropertyInstance("zoneClearance",V1A)?.value}set zoneClearance(A){this.setNumberProperty("zoneClearance",A,V1A)}get zone45Only(){return this.getPropertyInstance("zone45Only",v1A)?.value}set zone45Only(A){this.setProperty("zone45Only",A===void 0?void 0:new v1A(A))}get traceMin(){return this.getPropertyInstance("traceMin",j1A)?.value}set traceMin(A){this.setNumberProperty("traceMin",A,j1A)}get segmentWidth(){return this.getPropertyInstance("segmentWidth",z1A)?.value}set segmentWidth(A){this.setNumberProperty("segmentWidth",A,z1A)}get edgeWidth(){return this.getPropertyInstance("edgeWidth",X1A)?.value}set edgeWidth(A){this.setNumberProperty("edgeWidth",A,X1A)}get viaSize(){return this.getPropertyInstance("viaSize",$1A)?.value}set viaSize(A){this.setNumberProperty("viaSize",A,$1A)}get viaDrill(){return this.getPropertyInstance("viaDrill",A2A)?.value}set viaDrill(A){this.setNumberProperty("viaDrill",A,A2A)}get viaMinSize(){return this.getPropertyInstance("viaMinSize",t2A)?.value}set viaMinSize(A){this.setNumberProperty("viaMinSize",A,t2A)}get viaMinDrill(){return this.getPropertyInstance("viaMinDrill",e2A)?.value}set viaMinDrill(A){this.setNumberProperty("viaMinDrill",A,e2A)}get uviasAllowed(){return this.getPropertyInstance("uviasAllowed",G1A)?.value}set uviasAllowed(A){this.setProperty("uviasAllowed",A===void 0?void 0:new G1A(A))}get uviaSize(){return this.getPropertyInstance("uviaSize",i2A)?.value}set uviaSize(A){this.setNumberProperty("uviaSize",A,i2A)}get uviaDrill(){return this.getPropertyInstance("uviaDrill",n2A)?.value}set uviaDrill(A){this.setNumberProperty("uviaDrill",A,n2A)}get uviaMinSize(){return this.getPropertyInstance("uviaMinSize",o2A)?.value}set uviaMinSize(A){this.setNumberProperty("uviaMinSize",A,o2A)}get uviaMinDrill(){return this.getPropertyInstance("uviaMinDrill",s2A)?.value}set uviaMinDrill(A){this.setNumberProperty("uviaMinDrill",A,s2A)}get pcbTextWidth(){return this.getPropertyInstance("pcbTextWidth",r2A)?.value}set pcbTextWidth(A){this.setNumberProperty("pcbTextWidth",A,r2A)}get pcbTextSize(){return this.getPropertyInstance("pcbTextSize",N1A)?.values}set pcbTextSize(A){if(A===void 0){delete this._properties.pcbTextSize;return}this.setProperty("pcbTextSize",new N1A(A))}get modEdgeWidth(){return this.getPropertyInstance("modEdgeWidth",a2A)?.value}set modEdgeWidth(A){this.setNumberProperty("modEdgeWidth",A,a2A)}get modTextSize(){return this.getPropertyInstance("modTextSize",L1A)?.values}set modTextSize(A){if(A===void 0){delete this._properties.modTextSize;return}this.setProperty("modTextSize",new L1A(A))}get modTextWidth(){return this.getPropertyInstance("modTextWidth",g2A)?.value}set modTextWidth(A){this.setNumberProperty("modTextWidth",A,g2A)}get padSize(){return this.getPropertyInstance("padSize",U1A)?.values}set padSize(A){if(A===void 0){delete this._properties.padSize;return}this.setProperty("padSize",new U1A(A))}get padDrill(){return this.getPropertyInstance("padDrill",c2A)?.value}set padDrill(A){this.setNumberProperty("padDrill",A,c2A)}get allowSoldermaskBridgesInFootprints(){return this.getPropertyInstance("allowSoldermaskBridgesInFootprints",F1A)?.value}set allowSoldermaskBridgesInFootprints(A){this.setProperty("allowSoldermaskBridgesInFootprints",A===void 0?void 0:new F1A(A))}get tenting(){return this.getPropertyInstance("tenting",R1A)?.sides}set tenting(A){if(A===void 0){delete this._properties.tenting;return}this.setProperty("tenting",new R1A(A))}get auxAxisOrigin(){const A=this.getPropertyInstance("auxAxisOrigin",J1A);if(A)return{x:A.x,y:A.y}}set auxAxisOrigin(A){if(!A){delete this._properties.auxAxisOrigin;return}this.setProperty("auxAxisOrigin",new J1A(A.x,A.y))}get gridOrigin(){const A=this.getPropertyInstance("gridOrigin",T1A);if(A)return{x:A.x,y:A.y}}set gridOrigin(A){if(!A){delete this._properties.gridOrigin;return}this.setProperty("gridOrigin",new T1A(A.x,A.y))}get visibleElements(){return this.getPropertyInstance("visibleElements",M1A)?.value}set visibleElements(A){this.setProperty("visibleElements",A===void 0?void 0:new M1A(A))}get padToPasteClearanceValues(){return this.getPropertyInstance("padToPasteClearanceValues",H1A)?.values}set padToPasteClearanceValues(A){if(A===void 0){delete this._properties.padToPasteClearanceValues;return}this.setProperty("padToPasteClearanceValues",new H1A(A))}get traceWidth(){return this.getPropertyInstance("traceWidth",Y1A)?.values}set traceWidth(A){if(A===void 0){delete this._properties.traceWidth;return}this.setProperty("traceWidth",new Y1A(A))}};LA.register(u2A);var gyt=class extends ha{static token="thickness";static parentToken="general";token="thickness"};LA.register(gyt);var cyt=class yxt extends LA{static token="legacy_teardrops";static parentToken="general";token="legacy_teardrops";_enabled;constructor(A){super(),this._enabled=A}static fromSexprPrimitives(A){const t=Di(A[0]);if(t===void 0)throw new Error("legacy_teardrops expects a string value");const i=/^(yes|true)$/iu.test(t);return new yxt(i)}get enabled(){return this._enabled}set enabled(A){this._enabled=A}getChildren(){return[]}getString(){return`(legacy_teardrops ${this._enabled?"yes":"no"})`}};LA.register(cyt);var Iyt=new Set(["thickness","legacy_teardrops"]),d2A=class mxt extends LA{static token="general";static parentToken="kicad_pcb";token="general";_sxThickness;_sxLegacyTeardrops;static fromSexprPrimitives(A){const t=new mxt,{propertyMap:i,arrayPropertyMap:n}=LA.parsePrimitivesToClassProperties(A,this.token);for(const o of Object.keys(i))if(!Iyt.has(o))throw new Error(`general encountered unsupported child token "${o}"`);for(const[o,s]of Object.entries(n)){if(!Iyt.has(o))throw new Error(`general encountered unsupported child token "${o}"`);if(s.length>1)throw new Error(`general encountered repeated child token "${o}"`)}return t._sxThickness=n.thickness?.[0]??i.thickness,t._sxLegacyTeardrops=n.legacy_teardrops?.[0]??i.legacy_teardrops,t}get thickness(){return this._sxThickness?.value}set thickness(A){this._sxThickness=A===void 0?void 0:new gyt(A)}get legacyTeardrops(){return this._sxLegacyTeardrops?.enabled}set legacyTeardrops(A){if(A===void 0){this._sxLegacyTeardrops=void 0;return}this._sxLegacyTeardrops=new cyt(A)}getChildren(){const A=[];return this._sxThickness&&A.push(this._sxThickness),this._sxLegacyTeardrops&&A.push(this._sxLegacyTeardrops),A}};LA.register(d2A);var Zl=class wxt extends LA{static token="__pcb_layer_definition__";static parentToken="layers";token="__pcb_layer_definition__";_index;_name;_type;_userName;constructor(A){super(),this._index=A.index,this._name=A.name,this._type=A.type,this._userName=A.userName}static fromPrimitive(A){if(!Array.isArray(A)||A.length<3)throw new Error(`layers entry must be an array with at least index, name, and type: ${JSON.stringify(A)}`);const[t,i,n,o]=A,s=Ci(t),r=Di(i),a=Di(n),g=o===void 0?void 0:Di(o);if(s===void 0||r===void 0||a===void 0)throw new Error(`layers entry is missing required values: ${JSON.stringify(A)}`);return new wxt({index:s,name:r,type:a,userName:g})}get index(){return this._index}set index(A){this._index=A}get name(){return this._name}set name(A){this._name=A}get type(){return this._type}set type(A){this._type=A}get userName(){return this._userName}set userName(A){this._userName=A}getChildren(){return[]}getString(){if(this._index===void 0||this._name===void 0||this._type===void 0)return"()";const A=[String(this._index),mn(this._name),this._type];return this._userName!==void 0&&A.push(mn(this._userName)),`(${A.join(" ")})`}};LA.register(Zl);var p2A=class Dxt extends LA{static token="layers";static parentToken="kicad_pcb";token="layers";_definitions=[];static fromSexprPrimitives(A){const t=new Dxt;return t._definitions=A.map(i=>Zl.fromPrimitive(i)),t}get definitions(){return[...this._definitions]}set definitions(A){this._definitions=[...A]}getChildren(){return[...this._definitions]}};LA.register(p2A);var cj=class xxt extends LA{static token="net";static parentToken="kicad_pcb";token="net";_id;_name;constructor(A,t){super(),this._id=A,this._name=t}static fromSexprPrimitives(A){const t=Ci(A[0]),i=Di(A[1]);if(t===void 0||i===void 0)throw new Error("net requires numeric id and string name");return new xxt(t,i)}get id(){return this._id}set id(A){this._id=A}get name(){return this._name}set name(A){this._name=A}getChildren(){return[]}getString(){return`(net ${this._id} ${mn(this._name)})`}};LA.register(cj);var f2A=class extends ha{static token="version";static parentToken="kicad_pcb";token="version"};LA.register(f2A);var TCi=e=>/^[A-Za-z0-9._-]+$/.test(e),y2A=class extends xm{static token="generator";static parentToken="kicad_pcb";token="generator";getString(){return`(generator ${TCi(this.value)?this.value:mn(this.value)})`}};LA.register(y2A);var PCi=e=>/^[A-Za-z0-9._-]+$/.test(e),m2A=class extends xm{static token="generator_version";static parentToken="kicad_pcb";token="generator_version";getString(){return`(generator_version ${PCi(this.value)?this.value:mn(this.value)})`}};LA.register(m2A);var w2A=class Sxt extends LA{static token="net";static parentToken="via";token="net";_id;_name;constructor(A,t){super(),this._id=A,this._name=t}static fromSexprPrimitives(A){const t=Ci(A[0]);if(t===void 0)throw new Error("via net requires a numeric id");const i=A.length>1?Di(A[1]):void 0;return new Sxt(t,i)}get id(){return this._id}set id(A){this._id=A}get name(){return this._name}set name(A){this._name=A}getChildren(){return[]}getString(){return this._name!==void 0?`(net ${this._id} ${mn(this._name)})`:`(net ${this._id})`}};LA.register(w2A);var KCi=new Set(["locked","free","remove_unused_layers","keep_end_layers"]),D2A=class bxt extends LA{static token="via";token="via";_type;_locked=!1;_free=!1;_removeUnusedLayers=!1;_keepEndLayers=!1;_sxAt;_size;_drill;_sxLayers;_sxNet;_sxUuid;_sxTstamp;_sxTeardrops;constructor(A={}){super(),A.type!==void 0&&(this.type=A.type),A.locked!==void 0&&(this.locked=A.locked),A.free!==void 0&&(this.free=A.free),A.removeUnusedLayers!==void 0&&(this.removeUnusedLayers=A.removeUnusedLayers),A.keepEndLayers!==void 0&&(this.keepEndLayers=A.keepEndLayers),A.at!==void 0&&(this.at=A.at),A.size!==void 0&&(this.size=A.size),A.drill!==void 0&&(this.drill=A.drill),A.layers!==void 0&&(this.layers=A.layers),A.net!==void 0&&(this.net=A.net),A.uuid!==void 0&&(this.uuid=A.uuid),A.tstamp!==void 0&&(this.tstamp=A.tstamp),A.teardrops!==void 0&&(this.teardrops=A.teardrops)}static fromSexprPrimitives(A){const t=new bxt;for(const i of A){if(typeof i=="string"){t.consumeBareToken(i);continue}if(!Array.isArray(i)||i.length===0)throw new Error(`via encountered unsupported primitive child: ${JSON.stringify(i)}`);const[n,...o]=i;if(typeof n!="string")throw new Error(`via encountered child with non-string token: ${JSON.stringify(i)}`);t.consumeNode(n,o)}return t}consumeBareToken(A){if(A==="blind"||A==="micro"){this._type=A;return}if(!KCi.has(A))throw new Error(`via encountered unsupported flag "${A}"`);switch(A){case"locked":this._locked=!0;break;case"free":this._free=!0;break;case"remove_unused_layers":this._removeUnusedLayers=!0;break;case"keep_end_layers":this._keepEndLayers=!0;break}}consumeNode(A,t){switch(A){case"type":{const i=Di(t[0]);if(i===void 0)throw new Error("via type expects a string value");this._type=i;return}case"locked":this._locked=this.parseYesNo(t);return;case"free":this._free=this.parseYesNo(t);return;case"remove_unused_layers":this._removeUnusedLayers=this.parseYesNo(t);return;case"keep_end_layers":this._keepEndLayers=this.parseYesNo(t);return;case"at":{const i=LA.parsePrimitiveSexpr(["at",...t],{parentToken:this.token});if(!(i instanceof oc))throw new Error("via failed to parse at child");this._sxAt=i;return}case"size":{const i=Ci(t[0]);if(i===void 0)throw new Error("via size expects a numeric value");this._size=i;return}case"drill":{const i=Ci(t[0]);if(i===void 0)throw new Error("via drill expects a numeric value");this._drill=i;return}case"layers":{this._sxLayers=aj.fromSexprPrimitives(t);return}case"net":{this._sxNet=w2A.fromSexprPrimitives(t);return}case"teardrops":{this._sxTeardrops=Gpt.fromSexprPrimitives(t);return}case"uuid":{const i=Di(t[0]);if(i===void 0)throw new Error("via uuid expects a string value");this._sxUuid=new qi(i);return}case"tstamp":{const i=Di(t[0]);if(i===void 0)throw new Error("via tstamp expects a string value");this._sxTstamp=new sc(i);return}default:throw new Error(`via encountered unsupported child token "${A}"`)}}parseYesNo(A){if(A.length===0)return!0;const t=Di(A[0]);if(t===void 0)throw new Error("Expected string when parsing via boolean child");return/^(yes|true)$/iu.test(t)}get type(){return this._type}set type(A){this._type=A}get locked(){return this._locked}set locked(A){this._locked=A}get free(){return this._free}set free(A){this._free=A}get removeUnusedLayers(){return this._removeUnusedLayers}set removeUnusedLayers(A){this._removeUnusedLayers=A}get keepEndLayers(){return this._keepEndLayers}set keepEndLayers(A){this._keepEndLayers=A}get at(){return this._sxAt}set at(A){this._sxAt=A!==void 0?oc.from(A):void 0}get size(){return this._size}set size(A){this._size=A}get drill(){return this._drill}set drill(A){this._drill=A}get layers(){return this._sxLayers}set layers(A){if(A===void 0){this._sxLayers=void 0;return}this._sxLayers=A instanceof aj?A:new aj(A)}get net(){return this._sxNet}set net(A){this._sxNet=A}get uuid(){return this._sxUuid}set uuid(A){if(A===void 0){this._sxUuid=void 0;return}this._sxUuid=A instanceof qi?A:new qi(A)}get teardrops(){return this._sxTeardrops}set teardrops(A){this._sxTeardrops=A}get tstamp(){return this._sxTstamp}set tstamp(A){if(A===void 0){this._sxTstamp=void 0;return}this._sxTstamp=A instanceof sc?A:new sc(A)}getChildren(){const A=[];return this._sxAt&&A.push(this._sxAt),this._sxLayers&&A.push(this._sxLayers),this._sxNet&&A.push(this._sxNet),this._sxUuid&&A.push(this._sxUuid),this._sxTstamp&&A.push(this._sxTstamp),this._sxTeardrops&&A.push(this._sxTeardrops),A}getString(){const A=["(via"];return this._type!==void 0&&A.push(` (type ${this._type})`),this._locked&&A.push(" (locked)"),this._free&&A.push(" (free)"),this._removeUnusedLayers&&A.push(" (remove_unused_layers)"),this._keepEndLayers&&A.push(" (keep_end_layers)"),this._sxAt&&A.push(this._sxAt.getStringIndented()),this._size!==void 0&&A.push(` (size ${this._size})`),this._drill!==void 0&&A.push(` (drill ${this._drill})`),this._sxLayers&&A.push(this._sxLayers.getStringIndented()),this._sxNet&&A.push(this._sxNet.getStringIndented()),this._sxUuid&&A.push(this._sxUuid.getStringIndented()),this._sxTstamp&&A.push(this._sxTstamp.getStringIndented()),this._sxTeardrops&&A.push(this._sxTeardrops.getStringIndented()),A.push(")"),A.join(`
|
|
5829
|
-
`)}};LA.register(D2A);var x2A=class _xt extends LA{static token="kicad_pcb";token="kicad_pcb";_sxVersion;_sxGenerator;_sxGeneratorVersion;_sxGeneral;_sxPaper;_sxTitleBlock;_sxLayers;_sxSetup;_properties=[];_nets=[];_footprints=[];_images=[];_segments=[];_grLines=[];_grTexts=[];_grPolys=[];_grRects=[];_vias=[];_zones=[];_otherChildren=[];constructor(A={}){super(),A.version!==void 0&&(this.version=A.version),A.generator!==void 0&&(this.generator=A.generator),A.generatorVersion!==void 0&&(this.generatorVersion=A.generatorVersion),A.general!==void 0&&(this.general=A.general),A.paper!==void 0&&(this.paper=A.paper),A.titleBlock!==void 0&&(this.titleBlock=A.titleBlock),A.layers!==void 0&&(this.layers=A.layers),A.setup!==void 0&&(this.setup=A.setup),A.properties!==void 0&&(this.properties=A.properties),A.nets!==void 0&&(this.nets=A.nets),A.footprints!==void 0&&(this.footprints=A.footprints),A.images!==void 0&&(this.images=A.images),A.segments!==void 0&&(this.segments=A.segments),A.graphicLines!==void 0&&(this.graphicLines=A.graphicLines),A.graphicTexts!==void 0&&(this.graphicTexts=A.graphicTexts),A.graphicPolys!==void 0&&(this.graphicPolys=A.graphicPolys),A.graphicRects!==void 0&&(this.graphicRects=A.graphicRects),A.vias!==void 0&&(this.vias=A.vias),A.zones!==void 0&&(this.zones=A.zones),A.otherChildren!==void 0&&(this.otherChildren=A.otherChildren)}static fromSexprPrimitives(A){const t=new _xt;for(const i of A){if(!Array.isArray(i)||i.length===0)throw new Error(`kicad_pcb encountered unsupported primitive child: ${JSON.stringify(i)}`);const n=LA.parsePrimitiveSexpr(i,{parentToken:this.token});if(!(n instanceof LA))throw new Error(`kicad_pcb expected SxClass child, received ${JSON.stringify(i)}`);t.consumeChild(n)}return t}consumeChild(A){if(A instanceof f2A){this._sxVersion=A;return}if(A instanceof y2A){this._sxGenerator=A;return}if(A instanceof m2A){this._sxGeneratorVersion=A;return}if(A instanceof d2A){this._sxGeneral=A;return}if(A instanceof OV){this._sxPaper=A;return}if(A instanceof cdt){this._sxTitleBlock=A;return}if(A instanceof p2A){this._sxLayers=A;return}if(A instanceof u2A){this._sxSetup=A;return}if(A instanceof y1){this._properties.push(A);return}if(A instanceof cj){this._nets.push(A);return}if(A instanceof nj){this._footprints.push(A);return}if(A instanceof ldt){this._images.push(A);return}if(A instanceof _1A){this._segments.push(A);return}if(A instanceof oj){this._grLines.push(A);return}if(A instanceof sj){this._grTexts.push(A);return}if(A instanceof tft){this._grPolys.push(A);return}if(A instanceof Xpt){this._grRects.push(A);return}if(A instanceof D2A){this._vias.push(A);return}if(A instanceof rft){this._zones.push(A);return}this._otherChildren.push(A)}get version(){return this._sxVersion?.value}set version(A){this._sxVersion=A===void 0?void 0:new f2A(A)}get generator(){return this._sxGenerator?.value}set generator(A){this._sxGenerator=A===void 0?void 0:new y2A(A)}get generatorVersion(){return this._sxGeneratorVersion?.value}set generatorVersion(A){this._sxGeneratorVersion=A===void 0?void 0:new m2A(A)}get general(){return this._sxGeneral}set general(A){this._sxGeneral=A}get paper(){return this._sxPaper}set paper(A){this._sxPaper=A}get titleBlock(){return this._sxTitleBlock}set titleBlock(A){this._sxTitleBlock=A}get layers(){return this._sxLayers}set layers(A){this._sxLayers=A}get setup(){return this._sxSetup}set setup(A){this._sxSetup=A}get properties(){return[...this._properties]}set properties(A){this._properties=[...A]}get nets(){return[...this._nets]}set nets(A){this._nets=[...A]}get footprints(){return[...this._footprints]}set footprints(A){this._footprints=[...A]}get images(){return[...this._images]}set images(A){this._images=[...A]}get segments(){return[...this._segments]}set segments(A){this._segments=[...A]}get graphicLines(){return[...this._grLines]}set graphicLines(A){this._grLines=[...A]}get graphicTexts(){return[...this._grTexts]}set graphicTexts(A){this._grTexts=[...A]}get graphicPolys(){return[...this._grPolys]}set graphicPolys(A){this._grPolys=[...A]}get graphicRects(){return[...this._grRects]}set graphicRects(A){this._grRects=[...A]}get vias(){return[...this._vias]}set vias(A){this._vias=[...A]}get zones(){return[...this._zones]}set zones(A){this._zones=[...A]}get otherChildren(){return[...this._otherChildren]}set otherChildren(A){this._otherChildren=[...A]}getChildren(){const A=[];return this._sxVersion&&A.push(this._sxVersion),this._sxGenerator&&A.push(this._sxGenerator),this._sxGeneratorVersion&&A.push(this._sxGeneratorVersion),this._sxGeneral&&A.push(this._sxGeneral),this._sxPaper&&A.push(this._sxPaper),this._sxTitleBlock&&A.push(this._sxTitleBlock),this._sxLayers&&A.push(this._sxLayers),this._sxSetup&&A.push(this._sxSetup),A.push(...this._properties),A.push(...this._nets),A.push(...this._footprints),A.push(...this._images),A.push(...this._segments),A.push(...this._grLines),A.push(...this._grTexts),A.push(...this._grPolys),A.push(...this._grRects),A.push(...this._vias),A.push(...this._zones),A.push(...this._otherChildren),A}};LA.register(x2A);var lyt=e=>LA.parse(e),t0=class{MAX_ITERATIONS=1e3;iteration=0;finished=!1;input;ctx;constructor(e,A){this.input=e,this.ctx=A}step(){if(this.iteration++,this.iteration>this.MAX_ITERATIONS)throw new Error("Max iterations reached");this._step()}_step(){throw new Error("Not implemented")}runUntilFinished(){for(;!this.finished;)this.step()}getOutput(){throw new Error("Not implemented")}},qCi=class extends t0{_step(){const{kicadSch:e,schematicPaperSize:A}=this.ctx;if(!e)throw new Error("KicadSch instance not initialized in context");e.version=20250114;const t=new OV;t.size=A?.name??"A4",e.paper=t,e.uuid=new qi(crypto.randomUUID()),this.finished=!0}getOutput(){return this.ctx.kicadSch}};function U3(e,A){if(e.manufacturer_part_number)return S2A(e.manufacturer_part_number);const t=OCi(e.ftype),i=A?.footprinter_string;return S2A(i?`${t}_${i}`:t)}function OCi(e){if(!e)return"component";let A=e.replace(/^simple_/,"");return A||"component"}function S2A(e){return e.replace(/[\\\/:\s]+/g,"_").replace(/_+/g,"_").replace(/^_|_$/g,"").trim()||"component"}function Byt(e){return e?e.match(/^([A-Za-z]+)/)?.[1]?.toUpperCase()??"U":"U"}var Cyt={simple_resistor:"R",simple_capacitor:"C",simple_inductor:"L",simple_diode:"D",simple_led:"D",simple_chip:"U",simple_transistor:"Q",simple_mosfet:"Q",simple_fuse:"F",simple_switch:"SW",simple_push_button:"SW",simple_potentiometer:"RV",simple_crystal:"Y",simple_resonator:"Y",simple_pin_header:"J",simple_pinout:"J",simple_test_point:"TP",simple_battery:"BT"},WCi=/^[A-Za-z]+\d+$/;function Qyt(e){return e?WCi.test(e.trim()):!1}function Ij(e){const A=e?.ftype;if(A&&Cyt[A])return Cyt[A];const t=e?.name;return Qyt(t),Byt(t)}function ZCi(e){const A=e?.name;return Qyt(A)?A.trim():`${Ij(e)}?`}function hyt(e){return e in qQ}function Eyt(e,A,t,i){if(i)return`Custom:${i}`;if(e.type!=="source_component")return A.symbol_name?hyt(A.symbol_name)?`Device:${A.symbol_name}`:`Custom:${A.symbol_name}`:"Device:Component";if(A.symbol_name)return hyt(A.symbol_name)?`Device:${A.symbol_name}`:`Custom:${A.symbol_name}`;const n=U3(e,t);return`Device:${Ij(e)}_${n}`}function VCi(e){const{circuitJson:A,schematicSymbolId:t,schematicSymbol:i,schematicComponentId:n}=e,o=A.filter(Q=>Q.type==="schematic_circle"&&Q.schematic_symbol_id===t),s=A.filter(Q=>Q.type==="schematic_line"&&Q.schematic_symbol_id===t),r=n?A.filter(Q=>Q.type==="schematic_line"&&Q.schematic_component_id===n&&!Q.schematic_symbol_id):[],a=[...s,...r],g=A.filter(Q=>Q.type==="schematic_path"&&Q.schematic_symbol_id===t),c=A.filter(Q=>Q.type==="schematic_text"&&Q.schematic_symbol_id===t);let I=A.filter(Q=>Q.type==="schematic_port"&&"schematic_symbol_id"in Q&&Q.schematic_symbol_id===t);if(I.length===0&&n){const Q=A.filter(E=>E.type==="schematic_port"&&E.schematic_component_id===n&&E.display_pin_label!==void 0),h=new Map;for(const E of Q)E.display_pin_label&&h.set(E.display_pin_label,E);if(I=h.size>0?Array.from(h.values()):Q,I.length===0){const E=A.filter(d=>d.type==="schematic_port"&&d.schematic_component_id===n),u=new Set;I=E.filter(d=>{const f=d.pin_number;if(f!==void 0){if(u.has(f))return!1;u.add(f)}return!0})}}const l=[];for(const Q of o)l.push({type:"circle",x:Q.center?.x??0,y:Q.center?.y??0,radius:Q.radius??.5,fill:Q.is_filled??!1,fillColor:Q.fill_color});for(const Q of a)l.push({type:"path",points:[{x:Q.x1??0,y:Q.y1??0},{x:Q.x2??0,y:Q.y2??0}]});for(const Q of g)Q.points&&Q.points.length>0&&l.push({type:"path",points:Q.points,fill:Q.is_filled??!1,fillColor:Q.fill_color});const B=c.map(Q=>({text:Q.text??"",x:Q.position?.x??0,y:Q.position?.y??0,fontSize:Q.font_size??.2,anchor:Q.anchor??"center"})),C=I.map((Q,h)=>({x:Q.center?.x??0,y:Q.center?.y??0,labels:[Q.display_pin_label||`${Q.pin_number||h+1}`],pinNumber:Q.pin_number||h+1,facingDirection:Q.facing_direction}));return C.sort((Q,h)=>Q.pinNumber-h.pinNumber),{center:i.center||{x:0,y:0},size:i.size||{width:1,height:1},primitives:l,texts:B,ports:C}}function jCi({points:e,transform:A,fillType:t}){const i=new Cdt,n=e.map(a=>{const g=Ct(A,a);return new oh(g.x,g.y)}),o=new oQ(n);i.points=o;const s=new f1;s.width=.254,s.type="default",i.stroke=s;const r=new fdt;return r.type=t,i.fill=r,i}function zCi({primitive:e,transform:A,scale:t}){const i=new wdt,n=Ct(A,{x:e.x,y:e.y}),o=i;o._sxCenter=new ddt(n.x,n.y),o._sxRadius=new pdt(e.radius*t);const s=new f1;s.width=.254,s.type="default",o._sxStroke=s;const r=new ydt;return r.type=e.fill?"background":"none",o._sxFill=r,i}function XCi({schText:e,transform:A,scale:t}){const i=new Ddt,n=Ct(A,{x:e.x,y:e.y});i.value=e.text,i.at=[n.x,n.y,0];const o=e.fontSize*t,s=new Tp;return s.size={height:o,width:o},i.effects=new Jp({font:s}),i}function $Ci({libId:e,symbolData:A,isChip:t,c2kMatSchScale:i}){const n=new NM({libraryId:`${e.split(":")[1]}_0_1`}),o=i,s=A.center?.x??0,r=A.center?.y??0,a=tn(za(o,o),sn(-s,-r));for(const c of A.primitives||[])if(c.type==="path"&&c.points){const I=t||c.fill?"background":"none",l=jCi({points:c.points,transform:a,fillType:I});n.polylines.push(l)}else if(c.type==="circle"){const I=zCi({primitive:c,transform:a,scale:o});n.circles.push(I)}const g=Array.isArray(A.texts)?A.texts:[];for(const c of g){const I=XCi({schText:c,transform:a,scale:o});n.texts.push(I)}return n}function AQi(e,A){const t=A.schematic_port.list().filter(r=>r.schematic_component_id===e.schematic_component_id).sort((r,a)=>(r.pin_number||0)-(a.pin_number||0)),i=e.size?.width||1.5,n=e.size?.height||1,o={type:"path",points:[{x:-i/2,y:-n/2},{x:i/2,y:-n/2},{x:i/2,y:n/2},{x:-i/2,y:n/2},{x:-i/2,y:-n/2}]},s=t.map(r=>{const a=r.center.x-e.center.x,g=r.center.y-e.center.y;return{x:a,y:g,labels:[r.display_pin_label||`${r.pin_number||1}`],pinNumber:r.pin_number||1}});return{center:{x:0,y:0},primitives:[o],ports:s,size:{width:i,height:n}}}function tQi(e,A){const t=new Tp;return t.size={height:e,width:e},new Jp({font:t,hiddenText:A})}function eQi({symbol:e,libId:A,description:t,keywords:i,fpFilters:n,footprintRef:o="",referencePrefix:s}){const r=s||A.split(":")[1]?.[0]||"U",a=[{key:"Reference",value:r,id:0,at:[2.032,0,90],hide:!1},{key:"Value",value:r,id:1,at:[0,0,90],hide:!1},{key:"Footprint",value:o,id:2,at:[-1.778,0,90],hide:!0},{key:"Datasheet",value:"~",id:3,at:[0,0,0],hide:!0},{key:"Description",value:t,id:4,at:[0,0,0],hide:!0},{key:"ki_keywords",value:i,id:5,at:[0,0,0],hide:!0},{key:"ki_fp_filters",value:n,id:6,at:[0,0,0],hide:!0}];for(const g of a)e.properties.push(new Pp({key:g.key,value:g.value,id:g.id,at:g.at,effects:tQi(1.27,g.hide)}))}function iQi({port:e,center:A,size:t,isChip:i,portIndex:n,schematicComponent:o,schematicPorts:s,c2kMatSchScale:r}){const a=r;let g=e.x??0,c=e.y??0,I=!1;if(i&&n!==void 0&&o){const m=s.filter(w=>w.schematic_component_id===o.schematic_component_id).sort((w,D)=>(w.pin_number||0)-(D.pin_number||0));if(m[n]){const w=m[n];g=w.center.x-o.center.x,c=w.center.y-o.center.y,I=!0}}let l,B;if(I)l=g,B=c;else{const m=A?.x??0,w=A?.y??0;l=g-m,B=c-w}const C=za(a,a),Q=Ct(C,{x:l,y:B});let h;if(i&&t){const m=t.width/2,w=t.height/2,D=Math.abs(l)/m,x=Math.abs(B)/w;h=D>x}else h=Math.abs(l)>Math.abs(B);let E=Q.x,u=Q.y;const d=6;if(i&&t){const m=t.width/2*a,w=t.height/2*a;h?(E=l>0?m:-m,u=B*a):(E=l*a,u=B>0?w:-w)}let f=0;return h?l>0?(f=180,i&&(E=E+d)):(f=0,i&&(E=E-d)):B>0?(f=270,i&&(u=u+d)):(f=90,i&&(u=u-d)),{x:E,y:u,angle:f}}function nQi({libId:e,symbolData:A,isChip:t,schematicComponent:i,schematicPorts:n,c2kMatSchScale:o}){const s=new NM({libraryId:`${e.split(":")[1]}_1_1`}),r=6,a=2.54;for(let g=0;g<(A.ports?.length||0);g++){const c=A.ports[g],I=new jV;I.pinElectricalType="passive",I.pinGraphicStyle="line";const{x:l,y:B,angle:C}=iQi({port:c,center:A.center,size:A.size,isChip:t,portIndex:g,schematicComponent:i,schematicPorts:n,c2kMatSchScale:o});I.at=[l,B,C],I.length=t?r:a;const Q=new Tp;Q.size={height:1.27,width:1.27};const h=new Jp({font:Q}),E=c.labels?.[0]||"~";I._sxName=new rDA({value:E,effects:h});const u=new Tp;u.size={height:1.27,width:1.27};const d=new Jp({font:u}),f=c.pinNumber?.toString()||`${g+1}`;I._sxNumber=new Sdt({value:f,effects:d}),s.pins.push(I)}return s}var oQi=class extends t0{processedSymbolNames=new Set;_step(){const{kicadSch:e,db:A}=this.ctx,t=new Gdt,i=[];this.processedSymbolNames=new Set;const n=A.schematic_component.list();for(const s of n){const r=this.createLibrarySymbolForComponent(s);r&&i.push(r)}const o=A.schematic_net_label?.list?.()||[];for(const s of o)if(s.symbol_name){const r=s.source_net_id?A.source_net.get(s.source_net_id)?.is_power:!1,a=s.source_net_id?A.source_net.get(s.source_net_id)?.is_ground:!1;if(r||a){const c=this.createLibrarySymbolForNetLabel({netLabel:s,isPower:r??!1,isGround:a??!1});c&&i.push(c)}}t.symbols=i,e&&(e.libSymbols=t),this.finished=!0}createLibrarySymbolForComponent(e){const{db:A}=this.ctx,t=e.source_component_id?A.source_component.get(e.source_component_id):null;if(!t)return null;const i=A.cad_component?.list()?.find(c=>c.source_component_id===t.source_component_id);let n=e.schematic_symbol_id;if(!n){const c=this.ctx.circuitJson.find(I=>(I.type==="schematic_line"||I.type==="schematic_circle"||I.type==="schematic_path")&&I.schematic_component_id===e.schematic_component_id&&I.schematic_symbol_id);c&&(n=c.schematic_symbol_id)}if(n)return this.createLibrarySymbolFromSchematicSymbol(e,t,i,n);const o=e.symbol_name||(t.ftype==="simple_chip"?`generic_chip_${e.source_component_id}`:null);if(!o)return null;const s=this.getSymbolData(o,e);if(!s)return null;const r=Eyt(t,e,i),a=t.ftype==="simple_chip",g=U3(t,i);return this.createLibrarySymbol({libId:r,symbolData:s,isChip:a,schematicComponent:e,description:this.getDescription(t),keywords:this.getKeywords(t),fpFilters:this.getFpFilters(t),footprintRef:g?`tscircuit:${g}`:"",referencePrefix:Ij(t)})}createLibrarySymbolFromSchematicSymbol(e,A,t,i){const{db:n}=this.ctx,o=this.ctx.circuitJson.find(c=>c.type==="schematic_symbol"&&c.schematic_symbol_id===i);if(!o)return null;let s;if(o.name)s=o.name;else{const c=U3(A,t);c?s=c:s=`custom_${A.ftype||"component"}_${i}`}const r=`Custom:${s}`;if(this.processedSymbolNames.has(r))return null;this.processedSymbolNames.add(r);const a=VCi({circuitJson:this.ctx.circuitJson,schematicSymbolId:i,schematicSymbol:o,schematicComponentId:e.schematic_component_id}),g=U3(A,t);return this.createLibrarySymbol({libId:r,symbolData:a,isChip:!1,schematicComponent:e,description:this.getDescription(A),keywords:this.getKeywords(A),fpFilters:this.getFpFilters(A,o.name),footprintRef:g?`tscircuit:${g}`:"",referencePrefix:Ij(A),symbolScale:1})}createLibrarySymbolForNetLabel({netLabel:e,isPower:A,isGround:t}){const i=e.symbol_name;if(!i)return null;const n=qQ[i];if(!n)return null;const o=`Custom:${i}`;return this.createLibrarySymbol({libId:o,symbolData:n,isChip:!1,schematicComponent:void 0,description:A?"Power net label":t?"Ground net label":"Net symbol",keywords:A?"power net":t?"ground net":"net",fpFilters:"",referencePrefix:o.split(":")[1]?.[0]||"U"})}getSymbolData(e,A){return e.startsWith("generic_chip_")?AQi(A,this.ctx.db):qQ[e]||null}createLibrarySymbol({libId:e,symbolData:A,isChip:t,schematicComponent:i,description:n,keywords:o,fpFilters:s,footprintRef:r="",referencePrefix:a,symbolScale:g}){const I=g??this.ctx.c2kMatSch?.a??15,l=new NM({libraryId:e,excludeFromSim:!1,inBom:!0,onBoard:!0}),B=new nDA;B.hide=!t,l._sxPinNumbers=B;const C=new sDA;C.offset=t?1.27:0,l._sxPinNames=C,eQi({symbol:l,libId:e,description:n,keywords:o,fpFilters:s,footprintRef:r,referencePrefix:a});const Q=$Ci({libId:e,symbolData:A,isChip:t,c2kMatSchScale:I});l.subSymbols.push(Q);const h=nQi({libId:e,symbolData:A,isChip:t,schematicComponent:i,schematicPorts:this.ctx.db.schematic_port.list(),c2kMatSchScale:I});return l.subSymbols.push(h),l._sxEmbeddedFonts=new GM(!1),l}getDescription(e){return e?.ftype==="simple_resistor"?"Resistor":e?.ftype==="simple_capacitor"?"Capacitor":e?.ftype==="simple_chip"?"Integrated Circuit":"Component"}getKeywords(e){return e?.ftype==="simple_resistor"?"R res resistor":e?.ftype==="simple_capacitor"?"C cap capacitor":e?.ftype==="simple_chip"?"U IC chip":""}getFpFilters(e,A){return A?`${A}*`:e?.ftype==="simple_resistor"?"R_*":e?.ftype==="simple_capacitor"?"C_*":(e?.ftype==="simple_chip","*")}getOutput(){if(!this.ctx.kicadSch)throw new Error("kicadSch is not initialized");return this.ctx.kicadSch}},sQi=class extends t0{_step(){const{kicadSch:e,db:A}=this.ctx,t=A.schematic_component.list();if(t.length===0){this.finished=!0;return}const i=[];for(const n of t){const o=n.source_component_id?A.source_component.get(n.source_component_id):null;if(!o||!this.ctx.c2kMatSch)continue;const{x:s,y:r}=Ct(this.ctx.c2kMatSch,{x:n.center.x,y:n.center.y}),a=crypto.randomUUID(),g=new NM({at:[s,r,0],unit:1,excludeFromSim:!1,inBom:!0,onBoard:!0,dnp:!1,uuid:a,fieldsAutoplaced:!0}),c=A.cad_component?.list()?.find(oA=>oA.source_component_id===o.source_component_id);let I,l=n.schematic_symbol_id;if(!l){const oA=this.ctx.circuitJson.find(rA=>(rA.type==="schematic_line"||rA.type==="schematic_circle"||rA.type==="schematic_path")&&rA.schematic_component_id===n.schematic_component_id&&rA.schematic_symbol_id);oA&&(l=oA.schematic_symbol_id)}if(l){const oA=this.ctx.circuitJson.find(rA=>rA.type==="schematic_symbol"&&rA.schematic_symbol_id===l);if(oA?.name)I=oA.name;else{const rA=U3(o,c);rA?I=rA:I=`custom_${o.ftype||"component"}_${l}`}}const B=Eyt(o,n,c,I),C=new eDA(B);g._sxLibId=C;const{reference:Q,value:h,description:E}=this.getComponentMetadata(o),{refTextPos:u,valTextPos:d}=this.getTextPositions(n,{x:s,y:r});let f;if(l){const oA=this.ctx.circuitJson.find(rA=>rA.type==="schematic_symbol"&&rA.schematic_symbol_id===l);oA&&oA.type==="schematic_symbol"&&(f=oA.metadata?.kicad_symbol)}const m=f?.properties?.Reference,w=new Pp({key:"Reference",value:m?.value??Q,id:0,at:[u.x,u.y,0],effects:this.createTextEffects(Number(m?.effects?.font?.size?.x??1.27),m?.effects?.hide??!1)}),D=o.ftype==="simple_chip",x=f?.properties?.Value,_=new Pp({key:"Value",value:x?.value??h,id:1,at:[d.x,d.y,0],effects:this.createTextEffects(Number(x?.effects?.font?.size?.x??1.27),x?.effects?.hide??D)}),b=f?.properties?.Footprint,R=new Pp({key:"Footprint",value:b?.value??"",id:2,at:[s-1.778,r,90],effects:this.createTextEffects(1.27,b?.effects?.hide??!0)}),F=f?.properties?.Datasheet,H=new Pp({key:"Datasheet",value:F?.value??"~",id:3,at:[s,r,0],effects:this.createTextEffects(1.27,F?.effects?.hide??!0)}),Y=f?.properties?.Description,J=new Pp({key:"Description",value:Y?.value??E,id:4,at:[s,r,0],effects:this.createTextEffects(1.27,Y?.effects?.hide??!0)});g.properties.push(w,_,R,H,J);const O=f?.properties?.ki_keywords;if(O?.value){const oA=new Pp({key:"ki_keywords",value:O.value,id:5,at:[s,r,0],effects:this.createTextEffects(1.27,O.effects?.hide??!0)});g.properties.push(oA)}const W=f?.properties?.ki_fp_filters;if(W?.value){const oA=new Pp({key:"ki_fp_filters",value:W.value,id:6,at:[s,r,0],effects:this.createTextEffects(1.27,W.effects?.hide??!0)});g.properties.push(oA)}if(f){if(f.inBom!==void 0&&(g.inBom=f.inBom),f.onBoard!==void 0&&(g.onBoard=f.onBoard),f.excludeFromSim!==void 0&&(g.excludeFromSim=f.excludeFromSim),f.pinNames){const oA=new sDA;f.pinNames.offset!==void 0&&(oA.offset=Number(f.pinNames.offset)),f.pinNames.hide!==void 0&&(oA.hide=f.pinNames.hide),g.pinNames=oA}if(f.pinNumbers){const oA=new nDA;f.pinNumbers.hide!==void 0&&(oA.hide=f.pinNumbers.hide),g.pinNumbers=oA}f.embeddedFonts!==void 0&&(g._sxEmbeddedFonts=new GM(f.embeddedFonts))}let z=A.schematic_port.list().filter(oA=>oA.schematic_component_id===n.schematic_component_id);if(l){const oA=z.filter(rA=>rA.display_pin_label);oA.length>0&&(z=oA)}z.sort((oA,rA)=>(oA.pin_number||0)-(rA.pin_number||0));for(let oA=0;oA<z.length;oA++){const rA=z[oA];if(!rA)continue;const lA=new jV;lA.numberString=`${rA.pin_number||oA+1}`,lA.uuid=crypto.randomUUID(),g.pins.push(lA)}const tA=new aDA,aA=new cDA(""),eA=new IDA(`/${e?.uuid?.value||""}`);eA.reference=Q,eA.unit=1,aA.paths.push(eA),tA.projects.push(aA),g._sxInstances=tA,i.push(g)}e&&(e.symbols=i),this.finished=!0}getTextPositions(e,A){const i=(this.ctx.db.schematic_text?.list?.()?.filter(B=>B.schematic_component_id===e.schematic_component_id)||[]).find(B=>B.text&&B.text.length>0);if(i&&this.ctx.c2kMatSch){const B=Ct(this.ctx.c2kMatSch,{x:i.position.x,y:i.position.y}),C={x:A.x,y:A.y+6};return{refTextPos:B,valTextPos:C}}const n=e.symbol_name,o=qQ[n];if(!o)return{refTextPos:{x:A.x,y:A.y-6},valTextPos:{x:A.x,y:A.y+6}};let s=null,r=null;for(const B of o.primitives)B.type==="text"&&(B.text==="{REF}"?s=B:B.text==="{VAL}"&&(r=B));const a=o.center||{x:0,y:0},c=n.includes("_down")||n.includes("_up")?.15:0,I=s&&this.ctx.c2kMatSch?Ct(this.ctx.c2kMatSch,{x:e.center.x+(s.x-a.x)+c,y:e.center.y+(s.y-a.y)}):{x:A.x,y:A.y-6},l=r&&this.ctx.c2kMatSch?Ct(this.ctx.c2kMatSch,{x:e.center.x+(r.x-a.x)+c,y:e.center.y+(r.y-a.y)}):{x:A.x,y:A.y+6};return{refTextPos:I,valTextPos:l}}getComponentMetadata(e){const A=e.name||"?",t=ZCi(e);return e.ftype==="simple_resistor"?{reference:t,value:e.display_resistance||"R",description:"Resistor"}:e.ftype==="simple_capacitor"?{reference:t,value:e.display_capacitance||"C",description:"Capacitor"}:e.ftype==="simple_inductor"?{reference:t,value:e.display_inductance||"L",description:"Inductor"}:e.ftype==="simple_diode"?{reference:t,value:"D",description:"Diode"}:e.ftype==="simple_chip"?{reference:t,value:A,description:"Integrated Circuit"}:e.ftype==="simple_led"?{reference:t,value:e.manufacturer_part_number||"",description:"LED"}:e.ftype==="simple_switch"?{reference:t,value:e.manufacturer_part_number||"",description:"Switch"}:e.ftype==="simple_potentiometer"?{reference:t,value:e.display_max_resistance||"",description:"Potentiometer"}:{reference:t,value:A,description:"Component"}}createTextEffects(e,A=!1,t){const i=new Tp;i.size={height:e,width:e};const n=t?new a6({horizontal:t}):void 0;return new Jp({font:i,hiddenText:A,justify:n})}getOutput(){if(!this.ctx.kicadSch)throw new Error("kicadSch is not initialized");return this.ctx.kicadSch}},rQi=class extends t0{_step(){const{kicadSch:e,db:A}=this.ctx,t=A.schematic_net_label?.list?.()||[];if(t.length===0){this.finished=!0;return}if(!this.ctx.c2kMatSch){this.finished=!0;return}const i=[],n=[];for(const o of t){const s=o.text||"",r=o.symbol_name;if(r){const a=this.createSymbolFromNetLabel(o,s,r);a&&i.push(a)}else{const a=this.createGlobalLabel(o,s);a&&n.push(a)}}if(e&&i.length>0){const o=e.symbols||[];e.symbols=[...o,...i]}e&&n.length>0&&(e.globalLabels=[...e.globalLabels||[],...n]),this.finished=!0}createSymbolFromNetLabel(e,A,t){if(!this.ctx.c2kMatSch)return null;const{x:i,y:n}=Ct(this.ctx.c2kMatSch,{x:e.anchor_position?.x??e.center?.x??0,y:e.anchor_position?.y??e.center?.y??0}),o=crypto.randomUUID(),s=new NM({at:[i,n,0],unit:1,excludeFromSim:!1,inBom:!0,onBoard:!0,dnp:!1,uuid:o,fieldsAutoplaced:!0}),r=`Custom:${t}`,a=new eDA(r);s._sxLibId=a;const g=t.includes("_up")||t.toLowerCase().includes("vcc"),c=g?-4:4,I=g?-6:6,l=new Pp({key:"Reference",value:A,id:0,at:[i,n+c,0],effects:this.createTextEffects(1.27,!1)}),B=new Pp({key:"Value",value:A,id:1,at:[i,n+I,0],effects:this.createTextEffects(1.27,!0)}),C=new Pp({key:"Footprint",value:"",id:2,at:[i-1.778,n,90],effects:this.createTextEffects(1.27,!0)}),Q=new Pp({key:"Datasheet",value:"~",id:3,at:[i,n,0],effects:this.createTextEffects(1.27,!0)}),h=new Pp({key:"Description",value:`Power/Net symbol: ${A}`,id:4,at:[i,n,0],effects:this.createTextEffects(1.27,!0)});s.properties.push(l,B,C,Q,h);const E=new jV;E.numberString="1",E.uuid=crypto.randomUUID(),s.pins.push(E);const{kicadSch:u}=this.ctx,d=new aDA,f=new cDA(""),m=new IDA(`/${u?.uuid?.value||""}`);return m.reference=A,m.unit=1,f.paths.push(m),d.projects.push(f),s._sxInstances=d,s}createGlobalLabel(e,A){if(!this.ctx.c2kMatSch||!this.ctx.kicadSch)return null;const{x:t,y:i}=Ct(this.ctx.c2kMatSch,{x:e.anchor_position?.x??e.center?.x??0,y:e.anchor_position?.y??e.center?.y??0}),n=e.anchor_side||"left",s={left:0,right:180,top:270,bottom:90}[n]||0,a={left:{horizontal:"left"},right:{horizontal:"right"},top:{vertical:"top"},bottom:{vertical:"bottom"}}[n]||{},g=this.createTextEffects(1.27,!1);return Object.keys(a).length>0&&(g.justify=new a6(a)),new Pdt({value:A,at:[t,i,s],effects:g,uuid:crypto.randomUUID(),fieldsAutoplaced:!0})}createTextEffects(e,A=!1){const t=new Tp;return t.size={height:e,width:e},new Jp({font:t,hiddenText:A})}getOutput(){if(!this.ctx.kicadSch)throw new Error("kicadSch is not initialized");return this.ctx.kicadSch}},aQi=class extends t0{_step(){const{kicadSch:e,db:A}=this.ctx;if(!e)throw new Error("KicadSch instance not initialized in context");const t=A.schematic_trace.list();if(t.length===0){this.finished=!0;return}const i=[],n=[];for(const o of t){for(const s of o.edges){const r=this.createWireFromEdge(s);i.push(r)}for(const s of o.junctions){const r=this.createJunction(s);n.push(r)}}e.wires=i,e.junctions=n,this.finished=!0}createWireFromEdge(e){const A=new Ndt;if(!this.ctx.c2kMatSch)throw new Error("Schematic transformation matrix not initialized in context");const t=Ct(this.ctx.c2kMatSch,{x:e.from.x,y:e.from.y}),i=Ct(this.ctx.c2kMatSch,{x:e.to.x,y:e.to.y}),n=t.x,o=t.y,s=i.x,r=i.y,a=new oQ([new oh(n,o),new oh(s,r)]);A.points=a;const g=new f1;return g.width=0,g.type="default",A.stroke=g,A.uuid=crypto.randomUUID(),A}createJunction(e){if(!this.ctx.c2kMatSch)throw new Error("Schematic transformation matrix not initialized in context");const{x:A,y:t}=Ct(this.ctx.c2kMatSch,{x:e.x,y:e.y}),i=new Ldt({at:[A,t],diameter:0});return i.uuid=crypto.randomUUID(),i}getOutput(){return this.ctx.kicadSch}},gQi=class extends t0{_step(){const{kicadSch:e}=this.ctx;if(!e)throw new Error("KicadSch instance not initialized in context");const A=new QDA,t=new Odt;t.value="/";const i=new Wdt("1");t.pages=[i],A.paths=[t],e.sheetInstances=A,e.embeddedFonts=new GM(!1),this.finished=!0}getOutput(){return this.ctx.kicadSch}};function cQi(e){const A=e.schematic_component.list(),t=e.schematic_trace.list();let i=1/0,n=1/0,o=-1/0,s=-1/0;for(const g of A){const c=g.size?.width??0,I=g.size?.height??0;i=Math.min(i,g.center.x-c/2),n=Math.min(n,g.center.y-I/2),o=Math.max(o,g.center.x+c/2),s=Math.max(s,g.center.y+I/2)}for(const g of t)for(const c of g.edges)i=Math.min(i,c.from.x,c.to.x),n=Math.min(n,c.from.y,c.to.y),o=Math.max(o,c.from.x,c.to.x),s=Math.max(s,c.from.y,c.to.y);i===1/0&&(i=0,n=0,o=0,s=0);const r=(i+o)/2,a=(n+s)/2;return{center:{x:r,y:a},bounds:{minX:i,minY:n,maxX:o,maxY:s}}}var lj=[{name:"A4",width:297,height:210},{name:"A3",width:420,height:297},{name:"A2",width:594,height:420},{name:"A1",width:841,height:594},{name:"A0",width:1189,height:841}];function IQi(e,A,t=20){const i=e+2*t,n=A+2*t;for(let o=0;o<lj.length;o++){const s=lj[o];if(i<=s.width&&n<=s.height)return s}return lj[lj.length-1]}var uyt=class{ctx;pipeline;currentStageIndex=0;finished=!1;get currentStage(){return this.pipeline[this.currentStageIndex]}constructor(e){const t=Na(e),{center:i,bounds:n}=cQi(t),o=(n.maxX-n.minX)*15,s=(n.maxY-n.minY)*15,r=IQi(o,s),a=r.width/2,g=r.height/2;this.ctx={db:t,circuitJson:e,kicadSch:new EDA({generator:"circuit-json-to-kicad",generatorVersion:"0.0.1"}),schematicPaperSize:r,c2kMatSch:tn(sn(a,g),za(15,-15),sn(-i.x,-i.y))},this.pipeline=[new qCi(e,this.ctx),new oQi(e,this.ctx),new sQi(e,this.ctx),new rQi(e,this.ctx),new aQi(e,this.ctx),new gQi(e,this.ctx)]}step(){if(!this.currentStage){this.finished=!0;return}this.currentStage.step(),this.currentStage.finished&&this.currentStageIndex++}runUntilFinished(){for(;!this.finished;)this.step()}getOutput(){return this.ctx.kicadSch}getOutputString(){return this.ctx.kicadSch.getString()}},lQi=class extends t0{_step(){const{kicadPcb:e,db:A}=this.ctx;if(!e)throw new Error("KicadPcb instance not initialized in context");const i=A.pcb_board?.list()?.[0]?.num_layers??2;this.ctx.numLayers=i,e.version=20241229;const n=new OV;n.size="A4",e.paper=n;const o=new d2A;o.thickness=1.6,e.general=o;const s=new u2A;s.padToMaskClearance=0,e.setup=s;const r=new p2A,a=[new Zl({index:0,name:"F.Cu",type:"signal"})];for(let g=1;g<i-1;g++)a.push(new Zl({index:g,name:`In${g}.Cu`,type:"signal"}));a.push(new Zl({index:31,name:"B.Cu",type:"signal"})),a.push(new Zl({index:32,name:"B.Adhes",type:"user"}),new Zl({index:33,name:"F.Adhes",type:"user"}),new Zl({index:34,name:"B.Paste",type:"user"}),new Zl({index:35,name:"F.Paste",type:"user"}),new Zl({index:36,name:"B.SilkS",type:"user"}),new Zl({index:37,name:"F.SilkS",type:"user"}),new Zl({index:38,name:"B.Mask",type:"user"}),new Zl({index:39,name:"F.Mask",type:"user"}),new Zl({index:40,name:"Dwgs.User",type:"user"}),new Zl({index:41,name:"Cmts.User",type:"user"}),new Zl({index:42,name:"Eco1.User",type:"user"}),new Zl({index:43,name:"Eco2.User",type:"user"}),new Zl({index:44,name:"Edge.Cuts",type:"user"}),new Zl({index:45,name:"Margin",type:"user"}),new Zl({index:46,name:"B.CrtYd",type:"user"}),new Zl({index:47,name:"F.CrtYd",type:"user"}),new Zl({index:48,name:"B.Fab",type:"user"}),new Zl({index:49,name:"F.Fab",type:"user"})),r.definitions=a,e.layers=r,this.finished=!0}getOutput(){return this.ctx.kicadPcb}},BQi=class extends t0{_step(){const{kicadPcb:e}=this.ctx;if(!e)throw new Error("KicadPcb instance not initialized in context");this.ctx.pcbNetMap=new Map;const A=new Map,t=this.ctx.db.source_net?.list()??[];for(const r of t){const a=r.subcircuit_connectivity_map_key||r.source_net_id;if(!a)continue;const g=r.name||r.source_net_id||"",c=g&&g.trim().length>0?g:a;A.set(a,c)}const i=this.ctx.db.source_trace?.list()??[];for(const r of i){let a=r.subcircuit_connectivity_map_key;if(!a&&r.connected_source_net_ids?.length)for(const g of r.connected_source_net_ids){const c=this.ctx.db.source_net?.get(g);if(c?.subcircuit_connectivity_map_key&&c.subcircuit_connectivity_map_key.length>0){a=c.subcircuit_connectivity_map_key;break}}if(a&&!A.has(a)){const g=r.display_name||r.source_trace_id||"",c=g&&g.trim().length>0?g:a;A.set(a,c)}}const n=Array.from(A.entries()).sort((r,a)=>r[0].localeCompare(a[0])),o=[];o.push(new cj(0,""));let s=1;for(const[r,a]of n){const g=new cj(s,a);o.push(g);const c={id:s,name:a};this.ctx.pcbNetMap.set(r,c),s++}e.nets=o,this.finished=!0}getOutput(){return this.ctx.kicadPcb}};function CQi(e){let A=0;for(let i=0;i<e.length;i++){const n=e.charCodeAt(i);A=(A<<5)-A+n,A=A&A}let t="";for(let i=0;i<4;i++){let n=A;for(let o=0;o<e.length;o++)n=(n<<5)-n+e.charCodeAt(o)+i*31,n=n&n;t+=Math.abs(n).toString(16).padStart(8,"0")}return t}function cd(e){const A=CQi(e);return`${A.slice(0,8)}-${A.slice(8,12)}-${A.slice(12,16)}-${A.slice(16,20)}-${A.slice(20,32)}`}var dyt="https://modelcdn.tscircuit.com/jscad_models",QQi=20240108,hQi="pcbnew",EQi="8.0";function b2A(e){const A=e.split(/[/\\]/),t=A[A.length-1]||e;return t.split("?")[0]||t}var uQi=class extends t0{classifyFootprints(){const e=new Set,A=new Map,t=this.ctx.db.cad_component?.list()??[],i=this.ctx.db.source_component;for(const n of t){const o=n.source_component_id?i?.get(n.source_component_id):null;if(!o)continue;const s=U3(o,n);if(n.footprinter_string)A.set(s,n.footprinter_string);else{e.add(s);const r=this.ctx.circuitJson.find(a=>a.type==="pcb_component"&&a.source_component_id===n.source_component_id);r&&r.type==="pcb_component"&&r.metadata?.kicad_footprint?.footprintName&&e.add(r.metadata.kicad_footprint.footprintName)}}return{customFootprintNames:e,footprinterStrings:A}}_step(){const e=this.ctx.kicadPcbString,A=this.ctx.fpLibraryName??"tscircuit";if(!e)throw new Error("PCB content not available. Run GenerateKicadSchAndPcbStage first.");const{customFootprintNames:t,footprinterStrings:i}=this.classifyFootprints(),n=new Map;try{const s=lyt(e).find(a=>a instanceof x2A);if(!s){this.ctx.footprintEntries=[],this.finished=!0;return}const r=s.footprints??[];for(const a of r){const g=this.sanitizeFootprint({footprint:a,fpLibraryName:A,customFootprintNames:t,footprinterStrings:i});n.has(g.footprintName)||n.set(g.footprintName,g)}}catch(o){console.warn("Failed to parse PCB for footprint extraction:",o)}this.ctx.footprintEntries=Array.from(n.values()),this.finished=!0}sanitizeFootprint({footprint:e,fpLibraryName:A,customFootprintNames:t,footprinterStrings:i}){const o=(e.libraryLink??"footprint").split(":"),s=(o.length>1?o[1]:o[0])?.replace(/[\\\/]/g,"-").trim()||"footprint",r=!t.has(s);if(e.libraryLink=s,e.position=oc.from([0,0,0]),e.locked=!1,e.placed=!1,e.version=QQi,e.generator=hQi,e.generatorVersion=EQi,e.descr||(e.descr=""),e.tags||(e.tags=""),e.embeddedFonts||(e.embeddedFonts=new GM(!1)),!e.attr){const f=new uDA,m=(e.fpPads??[]).map(w=>w.padType);m.some(w=>w.includes("thru_hole"))?f.type="through_hole":m.some(w=>w.includes("smd"))&&(f.type="smd"),e.attr=f}e.uuid=void 0,e.path=void 0,e.sheetfile=void 0,e.sheetname=void 0;const a=new Tp;a.size={width:1.27,height:1.27},a.thickness=.15;const g=new Jp({font:a}),c=e.fpPads??[];let I=0,l=0;for(const f of c){const m=f.at,w=f.size;if(m&&w){const D=m.y??0,x=w.height??0,_=D-x/2,b=D+x/2;I=Math.min(I,_),l=Math.max(l,b)}}const B=I-.5,C=l+.5;e.properties=[new y1({key:"Reference",value:"REF**",position:[0,B,0],layer:"F.SilkS",uuid:cd(`${s}-property-Reference`),effects:g}),new y1({key:"Value",value:"Val**",position:[0,C,0],layer:"F.Fab",uuid:cd(`${s}-property-Value`),effects:g}),new y1({key:"Datasheet",value:"",position:[0,0,0],layer:"F.Fab",hidden:!0,uuid:cd(`${s}-property-Datasheet`),effects:g}),new y1({key:"Description",value:"",position:[0,0,0],layer:"F.Fab",hidden:!0,uuid:cd(`${s}-property-Description`),effects:g})];const Q=e.fpTexts??[];for(const f of Q)f.uuid=void 0,f.type==="reference"?f.text="REF**":f.type==="value"&&f.text.trim().length===0&&(f.text=s);e.fpTexts=Q;const h=e.fpPads??[];for(let f=0;f<h.length;f++){const m=h[f];m&&(m.uuid=cd(`${s}-pad-${m.number??f}`),m.net=void 0)}e.fpPads=h;const E=e.models??[],u=[],d=[];for(const f of E)if(f.path){const m=b2A(f.path),x=`../../3dmodels/${f.path.startsWith("http://modelcdn.tscircuit.com")||f.path.startsWith("https://modelcdn.tscircuit.com")?"tscircuit_builtin":A}.3dshapes/${m}`,_=new L3(x);f.offset&&(_.offset=f.offset),f.scale&&(_.scale=f.scale),f.rotate&&(_.rotate=f.rotate),u.push(_),d.push(f.path.split("?")[0]??f.path)}if(u.length===0){const f=i.get(s);if(f){const m=`${dyt}/${f}.step`,D=`../../3dmodels/tscircuit_builtin.3dshapes/${b2A(m)}`;u.push(new L3(D)),d.push(m)}}return e.models=u,{footprintName:s,kicadModString:e.getString(),model3dSourcePaths:d,isBuiltin:r}}getOutput(){return this.ctx.libraryOutput}};function Bj(e){const A=new Tp;return e?.font?.size?A.size={width:Number(e.font.size.x),height:Number(e.font.size.y)}:A.size={width:1.27,height:1.27},e?.font?.thickness!==void 0?A.thickness=Number(e.font.thickness):A.thickness=.15,new Jp({font:A})}function dQi(e,A,t){if(A.properties){const i=[],n=A.properties.Reference;i.push(new y1({key:"Reference",value:n?.value??t,position:n?.at?[Number(n.at.x),Number(n.at.y),Number(n.at.rotation??0)]:[0,-3,0],layer:n?.layer??"F.SilkS",uuid:cd(`${t}-property-Reference`),effects:Bj(n?.effects),hidden:n?.hide}));const o=A.properties.Value,s=o?.value??A.footprintName??"";i.push(new y1({key:"Value",value:s,position:o?.at?[Number(o.at.x),Number(o.at.y),Number(o.at.rotation??0)]:[0,3,0],layer:o?.layer??"F.Fab",uuid:cd(`${t}-property-Value`),effects:Bj(o?.effects),hidden:o?.hide}));const r=A.properties.Datasheet;i.push(new y1({key:"Datasheet",value:r?.value??"",position:r?.at?[Number(r.at.x),Number(r.at.y),Number(r.at.rotation??0)]:[0,0,0],layer:r?.layer??"F.Fab",uuid:cd(`${t}-property-Datasheet`),effects:Bj(r?.effects),hidden:r?.hide??!0}));const a=A.properties.Description;i.push(new y1({key:"Description",value:a?.value??"",position:a?.at?[Number(a.at.x),Number(a.at.y),Number(a.at.rotation??0)]:[0,0,0],layer:a?.layer??"F.Fab",uuid:cd(`${t}-property-Description`),effects:Bj(a?.effects),hidden:a?.hide??!0})),e.properties=i}if(A.attributes&&(e.attr||(e.attr=new uDA),A.attributes.through_hole?e.attr.type="through_hole":A.attributes.smd&&(e.attr.type="smd"),A.attributes.exclude_from_pos_files!==void 0&&(e.attr.excludeFromPosFiles=A.attributes.exclude_from_pos_files),A.attributes.exclude_from_bom!==void 0&&(e.attr.excludeFromBom=A.attributes.exclude_from_bom)),A.footprintName&&(e.libraryLink=A.footprintName),A.layer&&(e.layer=A.layer),A.embeddedFonts!==void 0&&(e.embeddedFonts=new GM(A.embeddedFonts)),A.model){const i=new L3(A.model.path);A.model.offset&&(i.offset={x:Number(A.model.offset.x),y:Number(A.model.offset.y),z:Number(A.model.offset.z)}),A.model.scale&&(i.scale={x:Number(A.model.scale.x),y:Number(A.model.scale.y),z:Number(A.model.scale.z)}),A.model.rotate&&(i.rotate={x:Number(A.model.rotate.x),y:Number(A.model.rotate.y),z:Number(A.model.rotate.z)});const n=e.models||[];e.models=[i,...n]}}function pQi(e,A){const t=[];for(const i of e){const n=i.center.x-A.x,o=-(i.center.y-A.y),r={top:"F.SilkS",bottom:"B.SilkS"}[i.layer]||i.layer||"F.SilkS",a=new t1A({center:{x:n,y:o},end:{x:n+i.radius,y:o},layer:r,stroke:new f1,fill:!1});a.stroke&&(a.stroke.width=i.stroke_width||.05,a.stroke.type="default"),t.push(a)}return t}function fQi(e,A){const t=[];for(const i of e){const n=i.center.x-A.x,o=-(i.center.y-A.y),r={top:"F.CrtYd",bottom:"B.CrtYd"}[i.layer]||"F.CrtYd",a=new t1A({center:{x:n,y:o},end:{x:n+i.radius,y:o},layer:r,stroke:new f1,fill:!1});a.stroke&&(a.stroke.width=.05,a.stroke.type="default"),t.push(a)}return t}function yQi(e,A){const t=[];for(const i of e){const n=i.center.x-A.x,o=-(i.center.y-A.y),s=i.width/2,r=i.height/2,g={top:"F.Fab",bottom:"B.Fab"}[i.layer]||i.layer||"F.Fab",c=new Aj({start:{x:n-s,y:o-r},end:{x:n+s,y:o+r},layer:g,stroke:new f1,fill:!1});c.stroke&&(c.stroke.width=i.stroke_width||.1,c.stroke.type="default"),t.push(c)}return t}function mQi(e,A){const t=[];for(const i of e){const n=i.center.x-A.x,o=-(i.center.y-A.y),s=i.width/2,r=i.height/2,a="F.Fab",g=new Aj({start:{x:n-s,y:o-r},end:{x:n+s,y:o+r},layer:a,stroke:new f1,fill:!1});g.stroke&&(g.stroke.width=i.stroke_width||.1,g.stroke.type="default"),t.push(g)}return t}function wQi(e,A){const t=[];for(const i of e){const n=i.center.x-A.x,o=-(i.center.y-A.y),s=i.width/2,r=i.height/2,g={top:"F.CrtYd",bottom:"B.CrtYd"}[i.layer]||"F.CrtYd",c=new Aj({start:{x:n-s,y:o-r},end:{x:n+s,y:o+r},layer:g,stroke:new f1,fill:!1});c.stroke&&(c.stroke.width=.05,c.stroke.type="default"),t.push(c)}return t}function DQi(e,A){const t=[];for(const i of e){if(!i.outline||i.outline.length<2)continue;const o={top:"F.CrtYd",bottom:"B.CrtYd"}[i.layer]||"F.CrtYd",s=i.outline.map(g=>{const c=g.x-A.x,I=-(g.y-A.y);return new oh(c,I)}),r=new Hpt;r.points=new oQ(s),r.layer=o,r.fill=!1;const a=new f1;a.width=.05,a.type="default",r.stroke=a,t.push(r)}return t}function xQi({textElement:e,componentCenter:A,componentRotation:t=0}){if(!e.text||!e.anchor_position)return null;const i=e.anchor_position.x-A.x,n=-(e.anchor_position.y-A.y),o=t!==0?Jl(t*Math.PI/180):Sa(),s=Ct(o,{x:i,y:n}),r={x:s.x,y:s.y},g={top:"F.SilkS",bottom:"B.SilkS"}[e.layer]||e.layer||"F.SilkS",c=(e.font_size||1)/1.5,I=new Tp;I.size={width:c,height:c};const l=new Jp({font:I}),B=e.ccw_rotation||0;return new qDA({type:"user",text:e.text,position:{x:r.x,y:r.y,angle:B},layer:g,effects:l})}function SQi(e,A,t,i){const n=[];for(const o of e){const s=xQi({textElement:o,componentCenter:A,componentRotation:t});s&&(i&&o.text===i&&(s.type="reference"),n.push(s))}return n}function bQi(e,A,t){const i=[];for(const n of e){const o=n.anchor_position.x-A.x,s=-(n.anchor_position.y-A.y),r=t!==0?Jl(t*Math.PI/180):Sa(),a=Ct(r,{x:o,y:s}),g=n.font_size||1,c=new Tp;c.size={width:g,height:g};const I=new Jp({font:c}),l=new qDA({type:"user",text:n.text,position:{x:a.x,y:a.y,angle:0},layer:"F.Fab",effects:I});i.push(l)}return i}function _Qi(e,A,t){const i=[],n=e.model_step_url||e.model_wrl_url;if(!n)return i;const o=new L3(n);if(e.position){const s=t?.boardLayerZOffset??0;o.offset={x:(e.position.x||0)-A.x,y:-((e.position.y||0)-A.y),z:(e.position.z||0)-s}}if(e.rotation&&(o.rotate={x:e.rotation.x||0,y:e.rotation.y||0,z:e.rotation.z||0}),e.model_unit_to_mm_scale_factor){const s=e.model_unit_to_mm_scale_factor;o.scale={x:s,y:s,z:s}}return i.push(o),i}function kQi({pcbPad:e,componentCenter:A,padNumber:t,componentRotation:i=0,netInfo:n,componentId:o}){let s,r;if("x"in e&&"y"in e)s=e.x,r=e.y;else if("points"in e&&Array.isArray(e.points)){const u=e.points;s=u.reduce((d,f)=>d+f.x,0)/u.length,r=u.reduce((d,f)=>d+f.y,0)/u.length}else throw new Error("Pad must have either x/y coordinates or points array");const a=tn(i!==0?Jl(i*Math.PI/180):{a:1,b:0,c:0,d:1,e:0,f:0},za(1,-1),sn(-A.x,-A.y)),g=Ct(a,{x:s,y:r}),I={top:"F.Cu",bottom:"B.Cu"}[e.layer]||"F.Cu";let l,B,C,Q;if(e.shape==="circle")l="circle",B=["radius"in e?e.radius*2:.5,"radius"in e?e.radius*2:.5];else if(e.shape==="polygon"&&"points"in e){const u=e.points,d=tn(za(1,-1),sn(-s,-r)),f=u.map(w=>{const D=Ct(d,{x:w.x,y:w.y});return new oh(D.x,D.y)}),m=new YDA;m.contours=[new oQ(f)],m.width=0,m.filled=!0,Q=new ypt,Q.addGraphic(m),l="custom",C=new opt,C.anchor="circle",B=[.2,.2]}else l="rect",B=["width"in e?e.width:.5,"height"in e?e.height:.5];const h=`pad:${o}:${t}:${g.x},${g.y}`,E=new $V({number:String(t),padType:"smd",shape:l,at:[g.x,g.y,0],size:B,layers:[`${I}`,`${I==="F.Cu"?"F":"B"}.Paste`,`${I==="F.Cu"?"F":"B"}.Mask`],uuid:cd(h)});return C&&(E.options=C),Q&&(E.primitives=Q),n&&(E.net=new GDA(n.id,n.name)),E}function vQi(e,A,t,i,n,o){const s=[];let r=n;for(const a of e){const g=o(a.pcb_port_id),c=kQi({pcbPad:a,componentCenter:A,padNumber:r,componentRotation:t,netInfo:g,componentId:i});s.push(c),r++}return{pads:s,nextPadNumber:r}}function FQi({platedHole:e,componentCenter:A,padNumber:t,componentRotation:i=0,netInfo:n,componentId:o}){if(!("x"in e&&"y"in e))return null;const s=e.x-A.x,r=-(e.y-A.y),a=i!==0?Jl(i*Math.PI/180):Sa(),g=Ct(a,{x:s,y:r});let c="circle",I,l,B=0;const C="hole_offset_x"in e||"hole_offset_y"in e;let Q;if(C){const u={x:e.hole_offset_x??0,y:e.hole_offset_y??0};(u.x!==0||u.y!==0)&&(Q=Ct(a,{x:-u.x,y:u.y}))}e.shape==="circle"?(c="circle",I=[e.outer_diameter,e.outer_diameter],l=new m1({diameter:e.hole_diameter,offset:Q})):e.shape==="pill"||e.shape==="oval"?(c="oval",I=[e.outer_width,e.outer_height],l=new m1({oval:!0,diameter:e.hole_width,width:e.hole_height,offset:Q})):e.shape==="pill_hole_with_rect_pad"?(c="rect",I=[e.rect_pad_width,e.rect_pad_height],l=new m1({oval:!0,diameter:e.hole_width,width:e.hole_height,offset:Q})):e.shape==="circular_hole_with_rect_pad"?(c="rect",I=[e.rect_pad_width,e.rect_pad_height],l=new m1({diameter:e.hole_diameter,offset:Q})):e.shape==="rotated_pill_hole_with_rect_pad"?(c="rect",I=[e.rect_pad_width,e.rect_pad_height],l=new m1({oval:!0,diameter:e.hole_width,width:e.hole_height,offset:Q}),B=e.rect_ccw_rotation||0):(c="circle",I=[1.6,1.6],l=new m1({diameter:.8,offset:Q}));const h=`thruhole:${o}:${t}:${g.x},${g.y}`,E=new $V({number:String(t),padType:"thru_hole",shape:c,at:[g.x,g.y,B],size:I,drill:l,layers:["*.Cu","*.Mask"],removeUnusedLayers:!1,uuid:cd(h)});return n&&(E.net=new GDA(n.id,n.name)),E}function MQi(e,A,t,i,n,o){const s=[];let r=n;for(const a of e){const g=o(a.pcb_port_id),c=FQi({platedHole:a,componentCenter:A,padNumber:r,componentRotation:t,netInfo:g,componentId:i});c&&(s.push(c),r++)}return{pads:s,nextPadNumber:r}}function GQi({pcbHole:e,componentCenter:A,componentRotation:t=0}){if(!("x"in e&&"y"in e))return null;const i=e.x-A.x,n=-(e.y-A.y),o=t!==0?Jl(t*Math.PI/180):Sa(),s=Ct(o,{x:i,y:n});let r="circle",a,g;if(e.hole_shape==="circle"){r="circle";const c=e.hole_diameter;a=[c,c],g=new m1({diameter:c})}else if(e.hole_shape==="oval"){r="oval";const c=e.hole_width,I=e.hole_height;a=[c,I],g=new m1({oval:!0,diameter:c,width:I})}else{r="circle";const c="hole_diameter"in e?e.hole_diameter:1;a=[c,c],g=new m1({diameter:c})}return new $V({number:"",padType:"np_thru_hole",shape:r,at:[s.x,s.y,0],size:a,drill:g,layers:["*.Cu","*.Mask"],removeUnusedLayers:!1,uuid:crypto.randomUUID()})}function pyt(e,A,t){const i=[];for(const n of e){const o=GQi({pcbHole:n,componentCenter:A,componentRotation:t});o&&i.push(o)}return i}var RQi=class extends t0{componentsProcessed=0;pcbComponents=[];includeBuiltin3dModels;getNetInfoForPcbPort(e){if(!e)return;const A=this.ctx.db.pcb_port?.get(e);if(!A)return;const t=A.source_port_id;if(!t)return;const i=this.ctx.db.source_port?.get(t);if(!i)return;const n=i.subcircuit_connectivity_map_key;if(n)return this.ctx.pcbNetMap?.get(n)}getCadComponentForPcbComponent(e){return(this.ctx.db.cad_component?.list()||[]).find(t=>t.pcb_component_id===e)}constructor(e,A,t){super(e,A),this.pcbComponents=this.ctx.db.pcb_component.list(),this.includeBuiltin3dModels=t?.includeBuiltin3dModels??!1}_step(){const{kicadPcb:e,c2kMatPcb:A}=this.ctx;if(!e)throw new Error("KicadPcb instance not initialized in context");if(!A)throw new Error("PCB transformation matrix not initialized in context");if(this.componentsProcessed>=this.pcbComponents.length){this.finished=!0;return}const t=this.pcbComponents[this.componentsProcessed],i=t.source_component_id?this.ctx.db.source_component.get(t.source_component_id):null,n=this.getCadComponentForPcbComponent(t.pcb_component_id),o=i?U3(i,n):"Unknown",s=Ct(A,{x:t.center.x,y:t.center.y}),r=`footprint:${t.pcb_component_id}:${s.x},${s.y}`,a=new nj({libraryLink:`tscircuit:${o}`,layer:"F.Cu",at:[s.x,s.y,t.rotation||0],uuid:cd(r)}),g=a.fpTexts,c=this.ctx.db.pcb_silkscreen_text?.list().filter(O=>O.pcb_component_id===t.pcb_component_id)||[];g.push(...SQi(c,t.center,t.rotation||0,i?.name));const I=this.ctx.db.pcb_note_text?.list().filter(O=>O.pcb_component_id===t.pcb_component_id)||[];g.push(...bQi(I,t.center,t.rotation||0)),a.fpTexts=g;const l=a.fpPads,B=O=>this.getNetInfoForPcbPort(O),C=this.ctx.db.pcb_smtpad?.list().filter(O=>O.pcb_component_id===t.pcb_component_id)||[],{pads:Q,nextPadNumber:h}=vQi(C,t.center,t.rotation||0,t.pcb_component_id,1,B);l.push(...Q);const E=this.ctx.db.pcb_plated_hole?.list().filter(O=>O.pcb_component_id===t.pcb_component_id)||[],{pads:u}=MQi(E,t.center,t.rotation||0,t.pcb_component_id,h,B);l.push(...u);const d=this.ctx.db.pcb_hole?.list().filter(O=>O.pcb_component_id===t.pcb_component_id)||[],f=pyt(d,t.center,t.rotation||0);l.push(...f),a.fpPads=l;const m=this.ctx.db.pcb_silkscreen_circle?.list().filter(O=>O.pcb_component_id===t.pcb_component_id)||[],w=a.fpCircles??[];w.push(...pQi(m,t.center));const D=this.ctx.db.pcb_courtyard_circle?.list().filter(O=>O.pcb_component_id===t.pcb_component_id)||[];w.push(...fQi(D,t.center)),a.fpCircles=w;const x=this.ctx.db.pcb_fabrication_note_rect?.list().filter(O=>O.pcb_component_id===t.pcb_component_id)||[],_=a.fpRects??[];_.push(...yQi(x,t.center));const b=this.ctx.db.pcb_note_rect?.list().filter(O=>O.pcb_component_id===t.pcb_component_id)||[];_.push(...mQi(b,t.center));const R=this.ctx.db.pcb_courtyard_rect?.list().filter(O=>O.pcb_component_id===t.pcb_component_id)||[];_.push(...wQi(R,t.center)),a.fpRects=_;const F=this.ctx.db.pcb_courtyard_outline?.list().filter(O=>O.pcb_component_id===t.pcb_component_id)||[],H=DQi(F,t.center);if(H.length>0&&(a.fpPolys=H),n){const W=this.ctx.db.pcb_board?.list()[0]?.thickness??0,z=t.layer==="bottom"?-(W/2):W/2,tA=_Qi(n,t.center,{boardLayerZOffset:z}),aA="${KIPRJMOD}/3dmodels";if(tA.length>0)this.includeBuiltin3dModels?a.models=tA.map(eA=>{if(!eA.path)return eA;const oA=b2A(eA.path),lA=eA.path.startsWith("http://modelcdn.tscircuit.com")||eA.path.startsWith("https://modelcdn.tscircuit.com")?"tscircuit_builtin":this.ctx.projectName??oA.replace(/\.[^.]+$/,""),pA=new L3(`${aA}/${lA}.3dshapes/${oA}`);eA.offset&&(pA.offset=eA.offset),eA.scale&&(pA.scale=eA.scale),eA.rotate&&(pA.rotate=eA.rotate);const kA=eA.path?.split("?")[0];return kA&&!this.ctx.pcbModel3dSourcePaths?.includes(kA)&&this.ctx.pcbModel3dSourcePaths?.push(kA),pA}):a.models=tA;else if(n.footprinter_string&&this.includeBuiltin3dModels){const{footprinter_string:eA}=n,oA=`${aA}/tscircuit_builtin.3dshapes/${eA}.step`;a.models=[new L3(oA)];const rA=`${dyt}/${eA}.step`;this.ctx.pcbModel3dSourcePaths?.includes(rA)||this.ctx.pcbModel3dSourcePaths?.push(rA)}}const Y=t.metadata?.kicad_footprint;Y&&i?.name&&dQi(a,Y,i.name);const J=e.footprints;J.push(a),e.footprints=J,this.componentsProcessed++}getOutput(){return this.ctx.kicadPcb}},NQi={top:"F.Cu",bottom:"B.Cu",inner1:"In1.Cu",inner2:"In2.Cu",inner3:"In3.Cu",inner4:"In4.Cu",inner5:"In5.Cu",inner6:"In6.Cu"};function LQi(e){return e&&(NQi[e]||e)||"F.Cu"}function UQi(e){const A=["F.Cu"];for(let t=1;t<e-1;t++)A.push(`In${t}.Cu`);return A.push("B.Cu"),A}var HQi=class extends t0{tracesProcessed=0;pcbTraces=[];constructor(e,A){super(e,A),this.pcbTraces=this.ctx.db.pcb_trace.list()}_step(){const{kicadPcb:e,c2kMatPcb:A,pcbNetMap:t}=this.ctx;if(!e)throw new Error("KicadPcb instance not initialized in context");if(!A)throw new Error("PCB transformation matrix not initialized in context");if(this.tracesProcessed>=this.pcbTraces.length){this.finished=!0;return}const i=this.pcbTraces[this.tracesProcessed];if(!i.route||i.route.length<2){this.tracesProcessed++;return}let n=i.route[0]?.layer;for(let o=0;o<i.route.length-1;o++){const s=i.route[o],r=i.route[o+1],a=Ct(A,{x:s.x,y:s.y}),g=Ct(A,{x:r.x,y:r.y});let c;if(t){let h=i.subcircuit_connectivity_map_key;if(!h&&i.source_trace_id){const E=this.ctx.db.source_trace?.get(i.source_trace_id);if(E&&(h=E.subcircuit_connectivity_map_key,!h&&E.connected_source_net_ids?.length))for(const u of E.connected_source_net_ids){const d=this.ctx.db.source_net?.get(u);if(d?.subcircuit_connectivity_map_key){h=d.subcircuit_connectivity_map_key;break}}}if(!h&&typeof i.connection_name=="string"){const E=this.ctx.db.source_net?.get(i.connection_name);E?.subcircuit_connectivity_map_key&&(h=E.subcircuit_connectivity_map_key)}h&&(c=t.get(h))}const I=s.layer??r.layer??n,l=LQi(I),B=`segment:${a.x},${a.y}:${g.x},${g.y}:${l}:${c?.id??0}`,C=new _1A({start:{x:a.x,y:a.y},end:{x:g.x,y:g.y},layer:l,width:i.width||.25,net:new rj(c?.id??0),uuid:cd(B)}),Q=e.segments;Q.push(C),e.segments=Q,s.layer&&(n=s.layer),r.layer&&(n=r.layer)}this.tracesProcessed++}getOutput(){return this.ctx.kicadPcb}},YQi=class extends t0{viasProcessed=0;pcbVias=[];constructor(e,A){super(e,A),this.pcbVias=this.ctx.db.pcb_via?.list()||[]}_step(){const{kicadPcb:e,c2kMatPcb:A,pcbNetMap:t}=this.ctx;if(!e)throw new Error("KicadPcb instance not initialized in context");if(!A)throw new Error("PCB transformation matrix not initialized in context");if(this.viasProcessed>=this.pcbVias.length){this.finished=!0;return}const i=this.pcbVias[this.viasProcessed],n=Ct(A,{x:i.x,y:i.y});let o;if(t){let I=i.subcircuit_connectivity_map_key;if(!I&&i.pcb_trace_id){const l=this.ctx.db.pcb_trace?.get(i.pcb_trace_id);if(l&&("subcircuit_connectivity_map_key"in l&&(I=l.subcircuit_connectivity_map_key),!I&&l.source_trace_id)){const B=this.ctx.db.source_trace?.get(l.source_trace_id);if(B&&("subcircuit_connectivity_map_key"in B&&(I=B.subcircuit_connectivity_map_key),!I&&B.connected_source_net_ids?.length))for(const C of B.connected_source_net_ids){const Q=this.ctx.db.source_net?.get(C);if(Q?.subcircuit_connectivity_map_key){I=Q.subcircuit_connectivity_map_key;break}}}}if(!I&&i.connection_name){const l=this.ctx.db.source_net?.get(i.connection_name);l?.subcircuit_connectivity_map_key&&(I=l.subcircuit_connectivity_map_key)}I&&(o=t.get(I))}const s=this.ctx.numLayers??2,r=i.layers?i.layers.map(I=>I==="top"?"F.Cu":I==="bottom"?"B.Cu":`In${I.replace("inner","")}.Cu`):UQi(s),a=`via:${n.x},${n.y}:${i.outer_diameter||.8}:${i.hole_diameter||.4}:${o?.id??0}`,g=new D2A({at:[n.x,n.y],size:i.outer_diameter||.8,drill:i.hole_diameter||.4,layers:r,net:new w2A(o?.id??0),uuid:cd(a)}),c=e.vias;c.push(g),e.vias=c,this.viasProcessed++}getOutput(){return this.ctx.kicadPcb}},JQi=class extends t0{holesProcessed=0;standaloneHoles=[];constructor(e,A){super(e,A),this.standaloneHoles=this.ctx.db.pcb_hole.list().filter(t=>!t.pcb_component_id)}_step(){const{kicadPcb:e,c2kMatPcb:A}=this.ctx;if(!e)throw new Error("KicadPcb instance not initialized in context");if(!A)throw new Error("PCB transformation matrix not initialized in context");if(this.holesProcessed>=this.standaloneHoles.length){this.finished=!0;return}const t=this.standaloneHoles[this.holesProcessed];if(!t){this.holesProcessed++;return}const i=Ct(A,{x:0,y:0}),n=`standalone_hole:${t.pcb_hole_id}:${t.x},${t.y}`,o=new nj({libraryLink:"tscircuit:MountingHole",layer:"F.Cu",at:[i.x,i.y,0],uuid:cd(n)}),r=pyt([t],{x:0,y:0},0);if(r.length>0){o.fpPads=r;const a=e.footprints;a.push(o),e.footprints=a}this.holesProcessed++}getOutput(){return this.ctx.kicadPcb}};function TQi({textElement:e,c2kMatPcb:A}){if(!e.text||!e.anchor_position)return null;const t=Ct(A,{x:e.anchor_position.x,y:e.anchor_position.y}),n={top:"F.Fab",bottom:"B.Fab"}[e.layer]||e.layer||"F.Fab",o=(e.font_size||1)/1.5,s=new Tp;s.size={width:o,height:o};const r=new a6,a=e.anchor_alignment||"center";switch(a){case"top_left":r.horizontal="left",r.vertical="top";break;case"top_right":r.horizontal="right",r.vertical="top";break;case"bottom_left":r.horizontal="left",r.vertical="bottom";break;case"bottom_right":r.horizontal="right",r.vertical="bottom";break}const g=new Jp({font:s});a!=="center"&&(g.justify=r);const c=new oc([t.x,t.y,0]),I=new sj({text:e.text,layer:n,effects:g});return I.position=c,I}function PQi({textElement:e,c2kMatPcb:A}){if(!e.text||!e.anchor_position)return null;const t=Ct(A,{x:e.anchor_position.x,y:e.anchor_position.y}),n={top:"F.SilkS",bottom:"B.SilkS"}[e.layer]||e.layer||"F.SilkS",o=(e.font_size||1)/1.5,s=new Tp;s.size={width:o,height:o};const r=new a6,a=e.anchor_alignment||"center";switch(a){case"top_left":r.horizontal="left",r.vertical="top";break;case"top_right":r.horizontal="right",r.vertical="top";break;case"bottom_left":r.horizontal="left",r.vertical="bottom";break;case"bottom_right":r.horizontal="right",r.vertical="bottom";break}const g=new Jp({font:s});a!=="center"&&(g.justify=r);const c=e.ccw_rotation||0,I=new oc([t.x,t.y,c]),l=new sj({text:e.text,layer:n,effects:g});return l.position=I,l}var KQi=class extends t0{_step(){const{kicadPcb:e,c2kMatPcb:A}=this.ctx;if(!e)throw new Error("KicadPcb instance not initialized in context");if(!A)throw new Error("PCB transformation matrix not initialized in context");const t=this.ctx.db.pcb_silkscreen_path?.list()||[];for(const s of t)if(!(!s.route||s.route.length<2))for(let r=0;r<s.route.length-1;r++){const a=s.route[r],g=s.route[r+1];if(!a||!g)continue;const c=Ct(A,{x:a.x,y:a.y}),I=Ct(A,{x:g.x,y:g.y}),B={top:"F.SilkS",bottom:"B.SilkS"}[s.layer]||s.layer||"F.SilkS",C=new oj({start:{x:c.x,y:c.y},end:{x:I.x,y:I.y},layer:B,width:s.stroke_width||.15}),Q=e.graphicLines;Q.push(C),e.graphicLines=Q}const i=this.ctx.db.pcb_silkscreen_text?.list().filter(s=>!s.pcb_component_id)||[];for(const s of i){const r=PQi({textElement:s,c2kMatPcb:A});if(r){const a=e.graphicTexts;a.push(r),e.graphicTexts=a}}const n=this.ctx.db.pcb_fabrication_note_text?.list()||[];for(const s of n){const r=TQi({textElement:s,c2kMatPcb:A});if(r){const a=e.graphicTexts;a.push(r),e.graphicTexts=a}}const o=this.ctx.db.pcb_board?.list()||[];if(o.length>0){const s=o[0];if(!s){this.finished=!0;return}let r;if(s.outline&&s.outline.length>0)r=s.outline;else{const g=s.width?s.width/2:0,c=s.height?s.height/2:0;r=[{x:s.center.x-g,y:s.center.y-c},{x:s.center.x+g,y:s.center.y-c},{x:s.center.x+g,y:s.center.y+c},{x:s.center.x-g,y:s.center.y+c}]}const a=r.map(g=>Ct(A,g));for(let g=0;g<a.length;g++){const c=a[g],I=a[(g+1)%a.length];if(!c||!I)continue;const l=new oj({start:{x:c.x,y:c.y},end:{x:I.x,y:I.y},layer:"Edge.Cuts",width:.1}),B=e.graphicLines;B.push(l),e.graphicLines=B}}this.finished=!0}getOutput(){return this.ctx.kicadPcb}},fyt=class{ctx;pipeline;currentStageIndex=0;finished=!1;get currentStage(){return this.pipeline[this.currentStageIndex]}constructor(e,A){this.ctx={db:Na(e),circuitJson:e,kicadPcb:new x2A({generator:"circuit-json-to-kicad",generatorVersion:"0.0.1"}),c2kMatPcb:tn(sn(100,100),za(1,-1)),projectName:A?.projectName,pcbModel3dSourcePaths:[]},this.pipeline=[new lQi(e,this.ctx),new BQi(e,this.ctx),new RQi(e,this.ctx,{includeBuiltin3dModels:A?.includeBuiltin3dModels}),new HQi(e,this.ctx),new YQi(e,this.ctx),new JQi(e,this.ctx),new KQi(e,this.ctx)]}step(){if(!this.currentStage){this.finished=!0;return}this.currentStage.step(),this.currentStage.finished&&this.currentStageIndex++}runUntilFinished(){for(;!this.finished;)this.step()}getOutput(){return this.ctx.kicadPcb}getOutputString(){return this.ctx.kicadPcb.getString()}getModel3dSourcePaths(){return this.ctx.pcbModel3dSourcePaths??[]}},qQi=class{ctx;project;constructor(e,A={}){const t=A.projectName??e?.project?.name??"circuit-json-project",i=A.schematicFilename??`${t}.kicad_sch`,n=A.pcbFilename??`${t}.kicad_pcb`,o=new Date().toISOString();this.ctx={db:Na(e),circuitJson:e},this.project={version:1,head:{generator:"circuit-json-to-kicad",generator_version:"0.0.1",project_name:t,created:o,modified:o},meta:{version:1},text_variables:{},libraries:{pinned_symbol_libs:[],pinned_footprint_libs:[]},boards:[],cvpcb:{meta:{version:0}},erc:{meta:{version:0},erc_exclusions:[]},net_settings:{meta:{version:1},last_net_id:0,classes:[]},pcbnew:{page_layout_descr_file:"",last_paths:{}},schematic:{meta:{version:1},page_layout_descr_file:"",last_opened_files:[i]},board:{meta:{version:1},last_opened_board:n},sheets:[[Math.random().toString(36).substring(2,15),"Root"]]}}runUntilFinished(){}getOutput(){return this.project}getOutputString(){return`${JSON.stringify(this.project,null,2)}
|
|
5829
|
+
`)}};LA.register(D2A);var x2A=class _xt extends LA{static token="kicad_pcb";token="kicad_pcb";_sxVersion;_sxGenerator;_sxGeneratorVersion;_sxGeneral;_sxPaper;_sxTitleBlock;_sxLayers;_sxSetup;_properties=[];_nets=[];_footprints=[];_images=[];_segments=[];_grLines=[];_grTexts=[];_grPolys=[];_grRects=[];_vias=[];_zones=[];_otherChildren=[];constructor(A={}){super(),A.version!==void 0&&(this.version=A.version),A.generator!==void 0&&(this.generator=A.generator),A.generatorVersion!==void 0&&(this.generatorVersion=A.generatorVersion),A.general!==void 0&&(this.general=A.general),A.paper!==void 0&&(this.paper=A.paper),A.titleBlock!==void 0&&(this.titleBlock=A.titleBlock),A.layers!==void 0&&(this.layers=A.layers),A.setup!==void 0&&(this.setup=A.setup),A.properties!==void 0&&(this.properties=A.properties),A.nets!==void 0&&(this.nets=A.nets),A.footprints!==void 0&&(this.footprints=A.footprints),A.images!==void 0&&(this.images=A.images),A.segments!==void 0&&(this.segments=A.segments),A.graphicLines!==void 0&&(this.graphicLines=A.graphicLines),A.graphicTexts!==void 0&&(this.graphicTexts=A.graphicTexts),A.graphicPolys!==void 0&&(this.graphicPolys=A.graphicPolys),A.graphicRects!==void 0&&(this.graphicRects=A.graphicRects),A.vias!==void 0&&(this.vias=A.vias),A.zones!==void 0&&(this.zones=A.zones),A.otherChildren!==void 0&&(this.otherChildren=A.otherChildren)}static fromSexprPrimitives(A){const t=new _xt;for(const i of A){if(!Array.isArray(i)||i.length===0)throw new Error(`kicad_pcb encountered unsupported primitive child: ${JSON.stringify(i)}`);const n=LA.parsePrimitiveSexpr(i,{parentToken:this.token});if(!(n instanceof LA))throw new Error(`kicad_pcb expected SxClass child, received ${JSON.stringify(i)}`);t.consumeChild(n)}return t}consumeChild(A){if(A instanceof f2A){this._sxVersion=A;return}if(A instanceof y2A){this._sxGenerator=A;return}if(A instanceof m2A){this._sxGeneratorVersion=A;return}if(A instanceof d2A){this._sxGeneral=A;return}if(A instanceof OV){this._sxPaper=A;return}if(A instanceof cdt){this._sxTitleBlock=A;return}if(A instanceof p2A){this._sxLayers=A;return}if(A instanceof u2A){this._sxSetup=A;return}if(A instanceof y1){this._properties.push(A);return}if(A instanceof cj){this._nets.push(A);return}if(A instanceof nj){this._footprints.push(A);return}if(A instanceof ldt){this._images.push(A);return}if(A instanceof _1A){this._segments.push(A);return}if(A instanceof oj){this._grLines.push(A);return}if(A instanceof sj){this._grTexts.push(A);return}if(A instanceof tft){this._grPolys.push(A);return}if(A instanceof Xpt){this._grRects.push(A);return}if(A instanceof D2A){this._vias.push(A);return}if(A instanceof rft){this._zones.push(A);return}this._otherChildren.push(A)}get version(){return this._sxVersion?.value}set version(A){this._sxVersion=A===void 0?void 0:new f2A(A)}get generator(){return this._sxGenerator?.value}set generator(A){this._sxGenerator=A===void 0?void 0:new y2A(A)}get generatorVersion(){return this._sxGeneratorVersion?.value}set generatorVersion(A){this._sxGeneratorVersion=A===void 0?void 0:new m2A(A)}get general(){return this._sxGeneral}set general(A){this._sxGeneral=A}get paper(){return this._sxPaper}set paper(A){this._sxPaper=A}get titleBlock(){return this._sxTitleBlock}set titleBlock(A){this._sxTitleBlock=A}get layers(){return this._sxLayers}set layers(A){this._sxLayers=A}get setup(){return this._sxSetup}set setup(A){this._sxSetup=A}get properties(){return[...this._properties]}set properties(A){this._properties=[...A]}get nets(){return[...this._nets]}set nets(A){this._nets=[...A]}get footprints(){return[...this._footprints]}set footprints(A){this._footprints=[...A]}get images(){return[...this._images]}set images(A){this._images=[...A]}get segments(){return[...this._segments]}set segments(A){this._segments=[...A]}get graphicLines(){return[...this._grLines]}set graphicLines(A){this._grLines=[...A]}get graphicTexts(){return[...this._grTexts]}set graphicTexts(A){this._grTexts=[...A]}get graphicPolys(){return[...this._grPolys]}set graphicPolys(A){this._grPolys=[...A]}get graphicRects(){return[...this._grRects]}set graphicRects(A){this._grRects=[...A]}get vias(){return[...this._vias]}set vias(A){this._vias=[...A]}get zones(){return[...this._zones]}set zones(A){this._zones=[...A]}get otherChildren(){return[...this._otherChildren]}set otherChildren(A){this._otherChildren=[...A]}getChildren(){const A=[];return this._sxVersion&&A.push(this._sxVersion),this._sxGenerator&&A.push(this._sxGenerator),this._sxGeneratorVersion&&A.push(this._sxGeneratorVersion),this._sxGeneral&&A.push(this._sxGeneral),this._sxPaper&&A.push(this._sxPaper),this._sxTitleBlock&&A.push(this._sxTitleBlock),this._sxLayers&&A.push(this._sxLayers),this._sxSetup&&A.push(this._sxSetup),A.push(...this._properties),A.push(...this._nets),A.push(...this._footprints),A.push(...this._images),A.push(...this._segments),A.push(...this._grLines),A.push(...this._grTexts),A.push(...this._grPolys),A.push(...this._grRects),A.push(...this._vias),A.push(...this._zones),A.push(...this._otherChildren),A}};LA.register(x2A);var lyt=e=>LA.parse(e),t0=class{MAX_ITERATIONS=1e3;iteration=0;finished=!1;input;ctx;constructor(e,A){this.input=e,this.ctx=A}step(){if(this.iteration++,this.iteration>this.MAX_ITERATIONS)throw new Error("Max iterations reached");this._step()}_step(){throw new Error("Not implemented")}runUntilFinished(){for(;!this.finished;)this.step()}getOutput(){throw new Error("Not implemented")}},qCi=class extends t0{_step(){const{kicadSch:e,schematicPaperSize:A}=this.ctx;if(!e)throw new Error("KicadSch instance not initialized in context");e.version=20250114;const t=new OV;t.size=A?.name??"A4",e.paper=t,e.uuid=new qi(crypto.randomUUID()),this.finished=!0}getOutput(){return this.ctx.kicadSch}};function U3(e,A){if(e.manufacturer_part_number)return S2A(e.manufacturer_part_number);const t=OCi(e.ftype),i=A?.footprinter_string;return S2A(i?`${t}_${i}`:t)}function OCi(e){if(!e)return"component";let A=e.replace(/^simple_/,"");return A||"component"}function S2A(e){return e.replace(/[\\\/:\s]+/g,"_").replace(/_+/g,"_").replace(/^_|_$/g,"").trim()||"component"}function Byt(e){return e?e.match(/^([A-Za-z]+)/)?.[1]?.toUpperCase()??"U":"U"}var Cyt={simple_resistor:"R",simple_capacitor:"C",simple_inductor:"L",simple_diode:"D",simple_led:"D",simple_chip:"U",simple_transistor:"Q",simple_mosfet:"Q",simple_fuse:"F",simple_switch:"SW",simple_push_button:"SW",simple_potentiometer:"RV",simple_crystal:"Y",simple_resonator:"Y",simple_pin_header:"J",simple_pinout:"J",simple_test_point:"TP",simple_battery:"BT"},WCi=/^[A-Za-z]+\d+$/;function Qyt(e){return e?WCi.test(e.trim()):!1}function Ij(e){const A=e?.ftype;if(A&&Cyt[A])return Cyt[A];const t=e?.name;return Qyt(t),Byt(t)}function ZCi(e){const A=e?.name;return Qyt(A)?A.trim():`${Ij(e)}?`}function hyt(e){return e in qQ}function Eyt(e,A,t,i){if(i)return`Custom:${i}`;if(e.type!=="source_component")return A.symbol_name?hyt(A.symbol_name)?`Device:${A.symbol_name}`:`Custom:${A.symbol_name}`:"Device:Component";if(A.symbol_name)return hyt(A.symbol_name)?`Device:${A.symbol_name}`:`Custom:${A.symbol_name}`;const n=U3(e,t);return`Device:${Ij(e)}_${n}`}function VCi(e){const{circuitJson:A,schematicSymbolId:t,schematicSymbol:i,schematicComponentId:n}=e,o=A.filter(Q=>Q.type==="schematic_circle"&&Q.schematic_symbol_id===t),s=A.filter(Q=>Q.type==="schematic_line"&&Q.schematic_symbol_id===t),r=n?A.filter(Q=>Q.type==="schematic_line"&&Q.schematic_component_id===n&&!Q.schematic_symbol_id):[],a=[...s,...r],g=A.filter(Q=>Q.type==="schematic_path"&&Q.schematic_symbol_id===t),c=A.filter(Q=>Q.type==="schematic_text"&&Q.schematic_symbol_id===t);let I=A.filter(Q=>Q.type==="schematic_port"&&"schematic_symbol_id"in Q&&Q.schematic_symbol_id===t);if(I.length===0&&n){const Q=A.filter(E=>E.type==="schematic_port"&&E.schematic_component_id===n&&E.display_pin_label!==void 0),h=new Map;for(const E of Q)E.display_pin_label&&h.set(E.display_pin_label,E);if(I=h.size>0?Array.from(h.values()):Q,I.length===0){const E=A.filter(d=>d.type==="schematic_port"&&d.schematic_component_id===n),u=new Set;I=E.filter(d=>{const f=d.pin_number;if(f!==void 0){if(u.has(f))return!1;u.add(f)}return!0})}}const l=[];for(const Q of o)l.push({type:"circle",x:Q.center?.x??0,y:Q.center?.y??0,radius:Q.radius??.5,fill:Q.is_filled??!1,fillColor:Q.fill_color});for(const Q of a)l.push({type:"path",points:[{x:Q.x1??0,y:Q.y1??0},{x:Q.x2??0,y:Q.y2??0}]});for(const Q of g)Q.points&&Q.points.length>0&&l.push({type:"path",points:Q.points,fill:Q.is_filled??!1,fillColor:Q.fill_color});const B=c.map(Q=>({text:Q.text??"",x:Q.position?.x??0,y:Q.position?.y??0,fontSize:Q.font_size??.2,anchor:Q.anchor??"center"})),C=I.map((Q,h)=>({x:Q.center?.x??0,y:Q.center?.y??0,labels:[Q.display_pin_label||`${Q.pin_number||h+1}`],pinNumber:Q.pin_number||h+1,facingDirection:Q.facing_direction}));return C.sort((Q,h)=>Q.pinNumber-h.pinNumber),{center:i.center||{x:0,y:0},size:i.size||{width:1,height:1},primitives:l,texts:B,ports:C}}function jCi({points:e,transform:A,fillType:t}){const i=new Cdt,n=e.map(a=>{const g=Ct(A,a);return new oh(g.x,g.y)}),o=new oQ(n);i.points=o;const s=new f1;s.width=.254,s.type="default",i.stroke=s;const r=new fdt;return r.type=t,i.fill=r,i}function zCi({primitive:e,transform:A,scale:t}){const i=new wdt,n=Ct(A,{x:e.x,y:e.y}),o=i;o._sxCenter=new ddt(n.x,n.y),o._sxRadius=new pdt(e.radius*t);const s=new f1;s.width=.254,s.type="default",o._sxStroke=s;const r=new ydt;return r.type=e.fill?"background":"none",o._sxFill=r,i}function XCi({schText:e,transform:A,scale:t}){const i=new Ddt,n=Ct(A,{x:e.x,y:e.y});i.value=e.text,i.at=[n.x,n.y,0];const o=e.fontSize*t,s=new Tp;return s.size={height:o,width:o},i.effects=new Jp({font:s}),i}function $Ci({libId:e,symbolData:A,isChip:t,c2kMatSchScale:i}){const n=new NM({libraryId:`${e.split(":")[1]}_0_1`}),o=i,s=A.center?.x??0,r=A.center?.y??0,a=tn(za(o,o),sn(-s,-r));for(const c of A.primitives||[])if(c.type==="path"&&c.points){const I=t||c.fill?"background":"none",l=jCi({points:c.points,transform:a,fillType:I});n.polylines.push(l)}else if(c.type==="circle"){const I=zCi({primitive:c,transform:a,scale:o});n.circles.push(I)}const g=Array.isArray(A.texts)?A.texts:[];for(const c of g){const I=XCi({schText:c,transform:a,scale:o});n.texts.push(I)}return n}function AQi(e,A){const t=A.schematic_port.list().filter(r=>r.schematic_component_id===e.schematic_component_id).sort((r,a)=>(r.pin_number||0)-(a.pin_number||0)),i=e.size?.width||1.5,n=e.size?.height||1,o={type:"path",points:[{x:-i/2,y:-n/2},{x:i/2,y:-n/2},{x:i/2,y:n/2},{x:-i/2,y:n/2},{x:-i/2,y:-n/2}]},s=t.map(r=>{const a=r.center.x-e.center.x,g=r.center.y-e.center.y;return{x:a,y:g,labels:[r.display_pin_label||`${r.pin_number||1}`],pinNumber:r.pin_number||1}});return{center:{x:0,y:0},primitives:[o],ports:s,size:{width:i,height:n}}}function tQi(e,A){const t=new Tp;return t.size={height:e,width:e},new Jp({font:t,hiddenText:A})}function eQi({symbol:e,libId:A,description:t,keywords:i,fpFilters:n,footprintRef:o="",referencePrefix:s}){const r=s||A.split(":")[1]?.[0]||"U",a=[{key:"Reference",value:r,id:0,at:[2.032,0,90],hide:!1},{key:"Value",value:r,id:1,at:[0,0,90],hide:!1},{key:"Footprint",value:o,id:2,at:[-1.778,0,90],hide:!0},{key:"Datasheet",value:"~",id:3,at:[0,0,0],hide:!0},{key:"Description",value:t,id:4,at:[0,0,0],hide:!0},{key:"ki_keywords",value:i,id:5,at:[0,0,0],hide:!0},{key:"ki_fp_filters",value:n,id:6,at:[0,0,0],hide:!0}];for(const g of a)e.properties.push(new Pp({key:g.key,value:g.value,id:g.id,at:g.at,effects:tQi(1.27,g.hide)}))}function iQi({port:e,center:A,size:t,isChip:i,portIndex:n,schematicComponent:o,schematicPorts:s,c2kMatSchScale:r}){const a=r;let g=e.x??0,c=e.y??0,I=!1;if(i&&n!==void 0&&o){const m=s.filter(w=>w.schematic_component_id===o.schematic_component_id).sort((w,D)=>(w.pin_number||0)-(D.pin_number||0));if(m[n]){const w=m[n];g=w.center.x-o.center.x,c=w.center.y-o.center.y,I=!0}}let l,B;if(I)l=g,B=c;else{const m=A?.x??0,w=A?.y??0;l=g-m,B=c-w}const C=za(a,a),Q=Ct(C,{x:l,y:B});let h;if(i&&t){const m=t.width/2,w=t.height/2,D=Math.abs(l)/m,x=Math.abs(B)/w;h=D>x}else h=Math.abs(l)>Math.abs(B);let E=Q.x,u=Q.y;const d=6;if(i&&t){const m=t.width/2*a,w=t.height/2*a;h?(E=l>0?m:-m,u=B*a):(E=l*a,u=B>0?w:-w)}let f=0;return h?l>0?(f=180,i&&(E=E+d)):(f=0,i&&(E=E-d)):B>0?(f=270,i&&(u=u+d)):(f=90,i&&(u=u-d)),{x:E,y:u,angle:f}}function nQi({libId:e,symbolData:A,isChip:t,schematicComponent:i,schematicPorts:n,c2kMatSchScale:o}){const s=new NM({libraryId:`${e.split(":")[1]}_1_1`}),r=6,a=2.54;for(let g=0;g<(A.ports?.length||0);g++){const c=A.ports[g],I=new jV;I.pinElectricalType="passive",I.pinGraphicStyle="line";const{x:l,y:B,angle:C}=iQi({port:c,center:A.center,size:A.size,isChip:t,portIndex:g,schematicComponent:i,schematicPorts:n,c2kMatSchScale:o});I.at=[l,B,C],I.length=t?r:a;const Q=new Tp;Q.size={height:1.27,width:1.27};const h=new Jp({font:Q}),E=c.labels?.[0]||"~";I._sxName=new rDA({value:E,effects:h});const u=new Tp;u.size={height:1.27,width:1.27};const d=new Jp({font:u}),f=c.pinNumber?.toString()||`${g+1}`;I._sxNumber=new Sdt({value:f,effects:d}),s.pins.push(I)}return s}var oQi=class extends t0{processedSymbolNames=new Set;_step(){const{kicadSch:e,db:A}=this.ctx,t=new Gdt,i=[];this.processedSymbolNames=new Set;const n=A.schematic_component.list();for(const s of n){const r=this.createLibrarySymbolForComponent(s);r&&i.push(r)}const o=A.schematic_net_label?.list?.()||[];for(const s of o)if(s.symbol_name){const r=s.source_net_id?A.source_net.get(s.source_net_id)?.is_power:!1,a=s.source_net_id?A.source_net.get(s.source_net_id)?.is_ground:!1;if(r||a){const c=this.createLibrarySymbolForNetLabel({netLabel:s,isPower:r??!1,isGround:a??!1});c&&i.push(c)}}t.symbols=i,e&&(e.libSymbols=t),this.finished=!0}createLibrarySymbolForComponent(e){const{db:A}=this.ctx,t=e.source_component_id?A.source_component.get(e.source_component_id):null;if(!t)return null;const i=A.cad_component?.list()?.find(c=>c.source_component_id===t.source_component_id);let n=e.schematic_symbol_id;if(!n){const c=this.ctx.circuitJson.find(I=>(I.type==="schematic_line"||I.type==="schematic_circle"||I.type==="schematic_path")&&I.schematic_component_id===e.schematic_component_id&&I.schematic_symbol_id);c&&(n=c.schematic_symbol_id)}if(n)return this.createLibrarySymbolFromSchematicSymbol(e,t,i,n);const o=e.symbol_name||(t.ftype==="simple_chip"?`generic_chip_${e.source_component_id}`:null);if(!o)return null;const s=this.getSymbolData(o,e);if(!s)return null;const r=Eyt(t,e,i),a=t.ftype==="simple_chip",g=U3(t,i);return this.createLibrarySymbol({libId:r,symbolData:s,isChip:a,schematicComponent:e,description:this.getDescription(t),keywords:this.getKeywords(t),fpFilters:this.getFpFilters(t),footprintRef:g?`tscircuit:${g}`:"",referencePrefix:Ij(t)})}createLibrarySymbolFromSchematicSymbol(e,A,t,i){const{db:n}=this.ctx,o=this.ctx.circuitJson.find(c=>c.type==="schematic_symbol"&&c.schematic_symbol_id===i);if(!o)return null;let s;if(o.name)s=o.name;else{const c=U3(A,t);c?s=c:s=`custom_${A.ftype||"component"}_${i}`}const r=`Custom:${s}`;if(this.processedSymbolNames.has(r))return null;this.processedSymbolNames.add(r);const a=VCi({circuitJson:this.ctx.circuitJson,schematicSymbolId:i,schematicSymbol:o,schematicComponentId:e.schematic_component_id}),g=U3(A,t);return this.createLibrarySymbol({libId:r,symbolData:a,isChip:!1,schematicComponent:e,description:this.getDescription(A),keywords:this.getKeywords(A),fpFilters:this.getFpFilters(A,o.name),footprintRef:g?`tscircuit:${g}`:"",referencePrefix:Ij(A),symbolScale:1})}createLibrarySymbolForNetLabel({netLabel:e,isPower:A,isGround:t}){const i=e.symbol_name;if(!i)return null;const n=qQ[i];if(!n)return null;const o=`Custom:${i}`;return this.createLibrarySymbol({libId:o,symbolData:n,isChip:!1,schematicComponent:void 0,description:A?"Power net label":t?"Ground net label":"Net symbol",keywords:A?"power net":t?"ground net":"net",fpFilters:"",referencePrefix:o.split(":")[1]?.[0]||"U"})}getSymbolData(e,A){return e.startsWith("generic_chip_")?AQi(A,this.ctx.db):qQ[e]||null}createLibrarySymbol({libId:e,symbolData:A,isChip:t,schematicComponent:i,description:n,keywords:o,fpFilters:s,footprintRef:r="",referencePrefix:a,symbolScale:g}){const I=g??this.ctx.c2kMatSch?.a??15,l=new NM({libraryId:e,excludeFromSim:!1,inBom:!0,onBoard:!0}),B=new nDA;B.hide=!t,l._sxPinNumbers=B;const C=new sDA;C.offset=t?1.27:0,l._sxPinNames=C,eQi({symbol:l,libId:e,description:n,keywords:o,fpFilters:s,footprintRef:r,referencePrefix:a});const Q=$Ci({libId:e,symbolData:A,isChip:t,c2kMatSchScale:I});l.subSymbols.push(Q);const h=nQi({libId:e,symbolData:A,isChip:t,schematicComponent:i,schematicPorts:this.ctx.db.schematic_port.list(),c2kMatSchScale:I});return l.subSymbols.push(h),l._sxEmbeddedFonts=new GM(!1),l}getDescription(e){return e?.ftype==="simple_resistor"?"Resistor":e?.ftype==="simple_capacitor"?"Capacitor":e?.ftype==="simple_chip"?"Integrated Circuit":"Component"}getKeywords(e){return e?.ftype==="simple_resistor"?"R res resistor":e?.ftype==="simple_capacitor"?"C cap capacitor":e?.ftype==="simple_chip"?"U IC chip":""}getFpFilters(e,A){return A?`${A}*`:e?.ftype==="simple_resistor"?"R_*":e?.ftype==="simple_capacitor"?"C_*":(e?.ftype==="simple_chip","*")}getOutput(){if(!this.ctx.kicadSch)throw new Error("kicadSch is not initialized");return this.ctx.kicadSch}},sQi=class extends t0{_step(){const{kicadSch:e,db:A}=this.ctx,t=A.schematic_component.list();if(t.length===0){this.finished=!0;return}const i=[];for(const n of t){const o=n.source_component_id?A.source_component.get(n.source_component_id):null;if(!o||!this.ctx.c2kMatSch)continue;const{x:s,y:r}=Ct(this.ctx.c2kMatSch,{x:n.center.x,y:n.center.y}),a=crypto.randomUUID(),g=new NM({at:[s,r,0],unit:1,excludeFromSim:!1,inBom:!0,onBoard:!0,dnp:!1,uuid:a,fieldsAutoplaced:!0}),c=A.cad_component?.list()?.find(oA=>oA.source_component_id===o.source_component_id);let I,l=n.schematic_symbol_id;if(!l){const oA=this.ctx.circuitJson.find(rA=>(rA.type==="schematic_line"||rA.type==="schematic_circle"||rA.type==="schematic_path")&&rA.schematic_component_id===n.schematic_component_id&&rA.schematic_symbol_id);oA&&(l=oA.schematic_symbol_id)}if(l){const oA=this.ctx.circuitJson.find(rA=>rA.type==="schematic_symbol"&&rA.schematic_symbol_id===l);if(oA?.name)I=oA.name;else{const rA=U3(o,c);rA?I=rA:I=`custom_${o.ftype||"component"}_${l}`}}const B=Eyt(o,n,c,I),C=new eDA(B);g._sxLibId=C;const{reference:Q,value:h,description:E}=this.getComponentMetadata(o),{refTextPos:u,valTextPos:d}=this.getTextPositions(n,{x:s,y:r});let f;if(l){const oA=this.ctx.circuitJson.find(rA=>rA.type==="schematic_symbol"&&rA.schematic_symbol_id===l);oA&&oA.type==="schematic_symbol"&&(f=oA.metadata?.kicad_symbol)}const m=f?.properties?.Reference,w=new Pp({key:"Reference",value:m?.value??Q,id:0,at:[u.x,u.y,0],effects:this.createTextEffects(Number(m?.effects?.font?.size?.x??1.27),m?.effects?.hide??!1)}),D=o.ftype==="simple_chip",x=f?.properties?.Value,_=new Pp({key:"Value",value:x?.value??h,id:1,at:[d.x,d.y,0],effects:this.createTextEffects(Number(x?.effects?.font?.size?.x??1.27),x?.effects?.hide??D)}),b=f?.properties?.Footprint,R=new Pp({key:"Footprint",value:b?.value??"",id:2,at:[s-1.778,r,90],effects:this.createTextEffects(1.27,b?.effects?.hide??!0)}),F=f?.properties?.Datasheet,H=new Pp({key:"Datasheet",value:F?.value??"~",id:3,at:[s,r,0],effects:this.createTextEffects(1.27,F?.effects?.hide??!0)}),Y=f?.properties?.Description,J=new Pp({key:"Description",value:Y?.value??E,id:4,at:[s,r,0],effects:this.createTextEffects(1.27,Y?.effects?.hide??!0)});g.properties.push(w,_,R,H,J);const O=f?.properties?.ki_keywords;if(O?.value){const oA=new Pp({key:"ki_keywords",value:O.value,id:5,at:[s,r,0],effects:this.createTextEffects(1.27,O.effects?.hide??!0)});g.properties.push(oA)}const W=f?.properties?.ki_fp_filters;if(W?.value){const oA=new Pp({key:"ki_fp_filters",value:W.value,id:6,at:[s,r,0],effects:this.createTextEffects(1.27,W.effects?.hide??!0)});g.properties.push(oA)}if(f){if(f.inBom!==void 0&&(g.inBom=f.inBom),f.onBoard!==void 0&&(g.onBoard=f.onBoard),f.excludeFromSim!==void 0&&(g.excludeFromSim=f.excludeFromSim),f.pinNames){const oA=new sDA;f.pinNames.offset!==void 0&&(oA.offset=Number(f.pinNames.offset)),f.pinNames.hide!==void 0&&(oA.hide=f.pinNames.hide),g.pinNames=oA}if(f.pinNumbers){const oA=new nDA;f.pinNumbers.hide!==void 0&&(oA.hide=f.pinNumbers.hide),g.pinNumbers=oA}f.embeddedFonts!==void 0&&(g._sxEmbeddedFonts=new GM(f.embeddedFonts))}let z=A.schematic_port.list().filter(oA=>oA.schematic_component_id===n.schematic_component_id);if(l){const oA=z.filter(rA=>rA.display_pin_label);oA.length>0&&(z=oA)}z.sort((oA,rA)=>(oA.pin_number||0)-(rA.pin_number||0));for(let oA=0;oA<z.length;oA++){const rA=z[oA];if(!rA)continue;const lA=new jV;lA.numberString=`${rA.pin_number||oA+1}`,lA.uuid=crypto.randomUUID(),g.pins.push(lA)}const tA=new aDA,aA=new cDA(""),eA=new IDA(`/${e?.uuid?.value||""}`);eA.reference=Q,eA.unit=1,aA.paths.push(eA),tA.projects.push(aA),g._sxInstances=tA,i.push(g)}e&&(e.symbols=i),this.finished=!0}getTextPositions(e,A){const i=(this.ctx.db.schematic_text?.list?.()?.filter(B=>B.schematic_component_id===e.schematic_component_id)||[]).find(B=>B.text&&B.text.length>0);if(i&&this.ctx.c2kMatSch){const B=Ct(this.ctx.c2kMatSch,{x:i.position.x,y:i.position.y}),C={x:A.x,y:A.y+6};return{refTextPos:B,valTextPos:C}}const n=e.symbol_name,o=qQ[n];if(!o)return{refTextPos:{x:A.x,y:A.y-6},valTextPos:{x:A.x,y:A.y+6}};let s=null,r=null;for(const B of o.primitives)B.type==="text"&&(B.text==="{REF}"?s=B:B.text==="{VAL}"&&(r=B));const a=o.center||{x:0,y:0},c=n.includes("_down")||n.includes("_up")?.15:0,I=s&&this.ctx.c2kMatSch?Ct(this.ctx.c2kMatSch,{x:e.center.x+(s.x-a.x)+c,y:e.center.y+(s.y-a.y)}):{x:A.x,y:A.y-6},l=r&&this.ctx.c2kMatSch?Ct(this.ctx.c2kMatSch,{x:e.center.x+(r.x-a.x)+c,y:e.center.y+(r.y-a.y)}):{x:A.x,y:A.y+6};return{refTextPos:I,valTextPos:l}}getComponentMetadata(e){const A=e.name||"?",t=ZCi(e);return e.ftype==="simple_resistor"?{reference:t,value:e.display_resistance||"R",description:"Resistor"}:e.ftype==="simple_capacitor"?{reference:t,value:e.display_capacitance||"C",description:"Capacitor"}:e.ftype==="simple_inductor"?{reference:t,value:e.display_inductance||"L",description:"Inductor"}:e.ftype==="simple_diode"?{reference:t,value:"D",description:"Diode"}:e.ftype==="simple_chip"?{reference:t,value:A,description:"Integrated Circuit"}:e.ftype==="simple_led"?{reference:t,value:e.manufacturer_part_number||"",description:"LED"}:e.ftype==="simple_switch"?{reference:t,value:e.manufacturer_part_number||"",description:"Switch"}:e.ftype==="simple_potentiometer"?{reference:t,value:e.display_max_resistance||"",description:"Potentiometer"}:{reference:t,value:A,description:"Component"}}createTextEffects(e,A=!1,t){const i=new Tp;i.size={height:e,width:e};const n=t?new a6({horizontal:t}):void 0;return new Jp({font:i,hiddenText:A,justify:n})}getOutput(){if(!this.ctx.kicadSch)throw new Error("kicadSch is not initialized");return this.ctx.kicadSch}},rQi=class extends t0{_step(){const{kicadSch:e,db:A}=this.ctx,t=A.schematic_net_label?.list?.()||[];if(t.length===0){this.finished=!0;return}if(!this.ctx.c2kMatSch){this.finished=!0;return}const i=[],n=[];for(const o of t){const s=o.text||"",r=o.symbol_name;if(r){const a=this.createSymbolFromNetLabel(o,s,r);a&&i.push(a)}else{const a=this.createGlobalLabel(o,s);a&&n.push(a)}}if(e&&i.length>0){const o=e.symbols||[];e.symbols=[...o,...i]}e&&n.length>0&&(e.globalLabels=[...e.globalLabels||[],...n]),this.finished=!0}createSymbolFromNetLabel(e,A,t){if(!this.ctx.c2kMatSch)return null;const{x:i,y:n}=Ct(this.ctx.c2kMatSch,{x:e.anchor_position?.x??e.center?.x??0,y:e.anchor_position?.y??e.center?.y??0}),o=crypto.randomUUID(),s=new NM({at:[i,n,0],unit:1,excludeFromSim:!1,inBom:!0,onBoard:!0,dnp:!1,uuid:o,fieldsAutoplaced:!0}),r=`Custom:${t}`,a=new eDA(r);s._sxLibId=a;const g=t.includes("_up")||t.toLowerCase().includes("vcc"),c=g?-4:4,I=g?-6:6,l=new Pp({key:"Reference",value:A,id:0,at:[i,n+c,0],effects:this.createTextEffects(1.27,!1)}),B=new Pp({key:"Value",value:A,id:1,at:[i,n+I,0],effects:this.createTextEffects(1.27,!0)}),C=new Pp({key:"Footprint",value:"",id:2,at:[i-1.778,n,90],effects:this.createTextEffects(1.27,!0)}),Q=new Pp({key:"Datasheet",value:"~",id:3,at:[i,n,0],effects:this.createTextEffects(1.27,!0)}),h=new Pp({key:"Description",value:`Power/Net symbol: ${A}`,id:4,at:[i,n,0],effects:this.createTextEffects(1.27,!0)});s.properties.push(l,B,C,Q,h);const E=new jV;E.numberString="1",E.uuid=crypto.randomUUID(),s.pins.push(E);const{kicadSch:u}=this.ctx,d=new aDA,f=new cDA(""),m=new IDA(`/${u?.uuid?.value||""}`);return m.reference=A,m.unit=1,f.paths.push(m),d.projects.push(f),s._sxInstances=d,s}createGlobalLabel(e,A){if(!this.ctx.c2kMatSch||!this.ctx.kicadSch)return null;const{x:t,y:i}=Ct(this.ctx.c2kMatSch,{x:e.anchor_position?.x??e.center?.x??0,y:e.anchor_position?.y??e.center?.y??0}),n=e.anchor_side||"left",s={left:0,right:180,top:270,bottom:90}[n]||0,a={left:{horizontal:"left"},right:{horizontal:"right"},top:{vertical:"top"},bottom:{vertical:"bottom"}}[n]||{},g=this.createTextEffects(1.27,!1);return Object.keys(a).length>0&&(g.justify=new a6(a)),new Pdt({value:A,at:[t,i,s],effects:g,uuid:crypto.randomUUID(),fieldsAutoplaced:!0})}createTextEffects(e,A=!1){const t=new Tp;return t.size={height:e,width:e},new Jp({font:t,hiddenText:A})}getOutput(){if(!this.ctx.kicadSch)throw new Error("kicadSch is not initialized");return this.ctx.kicadSch}},aQi=class extends t0{_step(){const{kicadSch:e,db:A}=this.ctx;if(!e)throw new Error("KicadSch instance not initialized in context");const t=A.schematic_trace.list();if(t.length===0){this.finished=!0;return}const i=[],n=[];for(const o of t){for(const s of o.edges){const r=this.createWireFromEdge(s);i.push(r)}for(const s of o.junctions){const r=this.createJunction(s);n.push(r)}}e.wires=i,e.junctions=n,this.finished=!0}createWireFromEdge(e){const A=new Ndt;if(!this.ctx.c2kMatSch)throw new Error("Schematic transformation matrix not initialized in context");const t=Ct(this.ctx.c2kMatSch,{x:e.from.x,y:e.from.y}),i=Ct(this.ctx.c2kMatSch,{x:e.to.x,y:e.to.y}),n=t.x,o=t.y,s=i.x,r=i.y,a=new oQ([new oh(n,o),new oh(s,r)]);A.points=a;const g=new f1;return g.width=0,g.type="default",A.stroke=g,A.uuid=crypto.randomUUID(),A}createJunction(e){if(!this.ctx.c2kMatSch)throw new Error("Schematic transformation matrix not initialized in context");const{x:A,y:t}=Ct(this.ctx.c2kMatSch,{x:e.x,y:e.y}),i=new Ldt({at:[A,t],diameter:0});return i.uuid=crypto.randomUUID(),i}getOutput(){return this.ctx.kicadSch}},gQi=class extends t0{_step(){const{kicadSch:e}=this.ctx;if(!e)throw new Error("KicadSch instance not initialized in context");const A=new QDA,t=new Odt;t.value="/";const i=new Wdt("1");t.pages=[i],A.paths=[t],e.sheetInstances=A,e.embeddedFonts=new GM(!1),this.finished=!0}getOutput(){return this.ctx.kicadSch}};function cQi(e){const A=e.schematic_component.list(),t=e.schematic_trace.list();let i=1/0,n=1/0,o=-1/0,s=-1/0;for(const g of A){const c=g.size?.width??0,I=g.size?.height??0;i=Math.min(i,g.center.x-c/2),n=Math.min(n,g.center.y-I/2),o=Math.max(o,g.center.x+c/2),s=Math.max(s,g.center.y+I/2)}for(const g of t)for(const c of g.edges)i=Math.min(i,c.from.x,c.to.x),n=Math.min(n,c.from.y,c.to.y),o=Math.max(o,c.from.x,c.to.x),s=Math.max(s,c.from.y,c.to.y);i===1/0&&(i=0,n=0,o=0,s=0);const r=(i+o)/2,a=(n+s)/2;return{center:{x:r,y:a},bounds:{minX:i,minY:n,maxX:o,maxY:s}}}var lj=[{name:"A4",width:297,height:210},{name:"A3",width:420,height:297},{name:"A2",width:594,height:420},{name:"A1",width:841,height:594},{name:"A0",width:1189,height:841}];function IQi(e,A,t=20){const i=e+2*t,n=A+2*t;for(let o=0;o<lj.length;o++){const s=lj[o];if(i<=s.width&&n<=s.height)return s}return lj[lj.length-1]}var uyt=class{ctx;pipeline;currentStageIndex=0;finished=!1;get currentStage(){return this.pipeline[this.currentStageIndex]}constructor(e){const t=Na(e),{center:i,bounds:n}=cQi(t),o=(n.maxX-n.minX)*15,s=(n.maxY-n.minY)*15,r=IQi(o,s),a=r.width/2,g=r.height/2;this.ctx={db:t,circuitJson:e,kicadSch:new EDA({generator:"circuit-json-to-kicad",generatorVersion:"0.0.1"}),schematicPaperSize:r,c2kMatSch:tn(sn(a,g),za(15,-15),sn(-i.x,-i.y))},this.pipeline=[new qCi(e,this.ctx),new oQi(e,this.ctx),new sQi(e,this.ctx),new rQi(e,this.ctx),new aQi(e,this.ctx),new gQi(e,this.ctx)]}step(){if(!this.currentStage){this.finished=!0;return}this.currentStage.step(),this.currentStage.finished&&this.currentStageIndex++}runUntilFinished(){for(;!this.finished;)this.step()}getOutput(){return this.ctx.kicadSch}getOutputString(){return this.ctx.kicadSch.getString()}},lQi=class extends t0{_step(){const{kicadPcb:e,db:A}=this.ctx;if(!e)throw new Error("KicadPcb instance not initialized in context");const i=A.pcb_board?.list()?.[0]?.num_layers??2;this.ctx.numLayers=i,e.version=20241229;const n=new OV;n.size="A4",e.paper=n;const o=new d2A;o.thickness=1.6,e.general=o;const s=new u2A;s.padToMaskClearance=0,e.setup=s;const r=new p2A,a=[new Zl({index:0,name:"F.Cu",type:"signal"})];for(let g=1;g<i-1;g++)a.push(new Zl({index:g,name:`In${g}.Cu`,type:"signal"}));a.push(new Zl({index:31,name:"B.Cu",type:"signal"})),a.push(new Zl({index:32,name:"B.Adhes",type:"user"}),new Zl({index:33,name:"F.Adhes",type:"user"}),new Zl({index:34,name:"B.Paste",type:"user"}),new Zl({index:35,name:"F.Paste",type:"user"}),new Zl({index:36,name:"B.SilkS",type:"user"}),new Zl({index:37,name:"F.SilkS",type:"user"}),new Zl({index:38,name:"B.Mask",type:"user"}),new Zl({index:39,name:"F.Mask",type:"user"}),new Zl({index:40,name:"Dwgs.User",type:"user"}),new Zl({index:41,name:"Cmts.User",type:"user"}),new Zl({index:42,name:"Eco1.User",type:"user"}),new Zl({index:43,name:"Eco2.User",type:"user"}),new Zl({index:44,name:"Edge.Cuts",type:"user"}),new Zl({index:45,name:"Margin",type:"user"}),new Zl({index:46,name:"B.CrtYd",type:"user"}),new Zl({index:47,name:"F.CrtYd",type:"user"}),new Zl({index:48,name:"B.Fab",type:"user"}),new Zl({index:49,name:"F.Fab",type:"user"})),r.definitions=a,e.layers=r,this.finished=!0}getOutput(){return this.ctx.kicadPcb}},BQi=class extends t0{_step(){const{kicadPcb:e}=this.ctx;if(!e)throw new Error("KicadPcb instance not initialized in context");this.ctx.pcbNetMap=new Map;const A=new Map,t=this.ctx.db.source_net?.list()??[];for(const r of t){const a=r.subcircuit_connectivity_map_key||r.source_net_id;if(!a)continue;const g=r.name||r.source_net_id||"",c=g&&g.trim().length>0?g:a;A.set(a,c)}const i=this.ctx.db.source_trace?.list()??[];for(const r of i){let a=r.subcircuit_connectivity_map_key;if(!a&&r.connected_source_net_ids?.length)for(const g of r.connected_source_net_ids){const c=this.ctx.db.source_net?.get(g);if(c?.subcircuit_connectivity_map_key&&c.subcircuit_connectivity_map_key.length>0){a=c.subcircuit_connectivity_map_key;break}}if(a&&!A.has(a)){const g=r.display_name||r.source_trace_id||"",c=g&&g.trim().length>0?g:a;A.set(a,c)}}const n=Array.from(A.entries()).sort((r,a)=>r[0].localeCompare(a[0])),o=[];o.push(new cj(0,""));let s=1;for(const[r,a]of n){const g=new cj(s,a);o.push(g);const c={id:s,name:a};this.ctx.pcbNetMap.set(r,c),s++}e.nets=o,this.finished=!0}getOutput(){return this.ctx.kicadPcb}};function CQi(e){let A=0;for(let i=0;i<e.length;i++){const n=e.charCodeAt(i);A=(A<<5)-A+n,A=A&A}let t="";for(let i=0;i<4;i++){let n=A;for(let o=0;o<e.length;o++)n=(n<<5)-n+e.charCodeAt(o)+i*31,n=n&n;t+=Math.abs(n).toString(16).padStart(8,"0")}return t}function cd(e){const A=CQi(e);return`${A.slice(0,8)}-${A.slice(8,12)}-${A.slice(12,16)}-${A.slice(16,20)}-${A.slice(20,32)}`}var dyt="https://modelcdn.tscircuit.com/jscad_models",QQi=20240108,hQi="pcbnew",EQi="8.0";function b2A(e){const A=e.split(/[/\\]/),t=A[A.length-1]||e;return t.split("?")[0]||t}var uQi=class extends t0{classifyFootprints(){const e=new Set,A=new Map,t=this.ctx.db.cad_component?.list()??[],i=this.ctx.db.source_component;for(const n of t){const o=n.source_component_id?i?.get(n.source_component_id):null;if(!o)continue;const s=U3(o,n);if(n.footprinter_string)A.set(s,n.footprinter_string);else{e.add(s);const r=this.ctx.circuitJson.find(a=>a.type==="pcb_component"&&a.source_component_id===n.source_component_id);r&&r.type==="pcb_component"&&r.metadata?.kicad_footprint?.footprintName&&e.add(r.metadata.kicad_footprint.footprintName)}}return{customFootprintNames:e,footprinterStrings:A}}_step(){const e=this.ctx.kicadPcbString,A=this.ctx.fpLibraryName??"tscircuit";if(!e)throw new Error("PCB content not available. Run GenerateKicadSchAndPcbStage first.");const{customFootprintNames:t,footprinterStrings:i}=this.classifyFootprints(),n=new Map;try{const s=lyt(e).find(a=>a instanceof x2A);if(!s){this.ctx.footprintEntries=[],this.finished=!0;return}const r=s.footprints??[];for(const a of r){const g=this.sanitizeFootprint({footprint:a,fpLibraryName:A,customFootprintNames:t,footprinterStrings:i});n.has(g.footprintName)||n.set(g.footprintName,g)}}catch(o){console.warn("Failed to parse PCB for footprint extraction:",o)}this.ctx.footprintEntries=Array.from(n.values()),this.finished=!0}sanitizeFootprint({footprint:e,fpLibraryName:A,customFootprintNames:t,footprinterStrings:i}){const o=(e.libraryLink??"footprint").split(":"),s=(o.length>1?o[1]:o[0])?.replace(/[\\\/]/g,"-").trim()||"footprint",r=!t.has(s);if(e.libraryLink=s,e.position=oc.from([0,0,0]),e.locked=!1,e.placed=!1,e.version=QQi,e.generator=hQi,e.generatorVersion=EQi,e.descr||(e.descr=""),e.tags||(e.tags=""),e.embeddedFonts||(e.embeddedFonts=new GM(!1)),!e.attr){const f=new uDA,m=(e.fpPads??[]).map(w=>w.padType);m.some(w=>w.includes("thru_hole"))?f.type="through_hole":m.some(w=>w.includes("smd"))&&(f.type="smd"),e.attr=f}e.uuid=void 0,e.path=void 0,e.sheetfile=void 0,e.sheetname=void 0;const a=new Tp;a.size={width:1.27,height:1.27},a.thickness=.15;const g=new Jp({font:a}),c=e.fpPads??[];let I=0,l=0;for(const f of c){const m=f.at,w=f.size;if(m&&w){const D=m.y??0,x=w.height??0,_=D-x/2,b=D+x/2;I=Math.min(I,_),l=Math.max(l,b)}}const B=I-.5,C=l+.5;e.properties=[new y1({key:"Reference",value:"REF**",position:[0,B,0],layer:"F.SilkS",uuid:cd(`${s}-property-Reference`),effects:g}),new y1({key:"Value",value:"Val**",position:[0,C,0],layer:"F.Fab",uuid:cd(`${s}-property-Value`),effects:g}),new y1({key:"Datasheet",value:"",position:[0,0,0],layer:"F.Fab",hidden:!0,uuid:cd(`${s}-property-Datasheet`),effects:g}),new y1({key:"Description",value:"",position:[0,0,0],layer:"F.Fab",hidden:!0,uuid:cd(`${s}-property-Description`),effects:g})];const Q=e.fpTexts??[];for(const f of Q)f.uuid=void 0,f.type==="reference"?f.text="REF**":f.type==="value"&&f.text.trim().length===0&&(f.text=s);e.fpTexts=Q;const h=e.fpPads??[];for(let f=0;f<h.length;f++){const m=h[f];m&&(m.uuid=cd(`${s}-pad-${m.number??f}`),m.net=void 0)}e.fpPads=h;const E=e.models??[],u=[],d=[];for(const f of E)if(f.path){const m=b2A(f.path),x=`../../3dmodels/${f.path.startsWith("http://modelcdn.tscircuit.com")||f.path.startsWith("https://modelcdn.tscircuit.com")?"tscircuit_builtin":A}.3dshapes/${m}`,_=new L3(x);f.offset&&(_.offset=f.offset),f.scale&&(_.scale=f.scale),f.rotate&&(_.rotate=f.rotate),u.push(_),d.push(f.path.split("?")[0]??f.path)}if(u.length===0){const f=i.get(s);if(f){const m=`${dyt}/${f}.step`,D=`../../3dmodels/tscircuit_builtin.3dshapes/${b2A(m)}`;u.push(new L3(D)),d.push(m)}}return e.models=u,{footprintName:s,kicadModString:e.getString(),model3dSourcePaths:d,isBuiltin:r}}getOutput(){return this.ctx.libraryOutput}};function Bj(e){const A=new Tp;return e?.font?.size?A.size={width:Number(e.font.size.x),height:Number(e.font.size.y)}:A.size={width:1.27,height:1.27},e?.font?.thickness!==void 0?A.thickness=Number(e.font.thickness):A.thickness=.15,new Jp({font:A})}function dQi(e,A,t){if(A.properties){const i=[],n=A.properties.Reference;i.push(new y1({key:"Reference",value:n?.value??t,position:n?.at?[Number(n.at.x),Number(n.at.y),Number(n.at.rotation??0)]:[0,-3,0],layer:n?.layer??"F.SilkS",uuid:cd(`${t}-property-Reference`),effects:Bj(n?.effects),hidden:n?.hide}));const o=A.properties.Value,s=o?.value??A.footprintName??"";i.push(new y1({key:"Value",value:s,position:o?.at?[Number(o.at.x),Number(o.at.y),Number(o.at.rotation??0)]:[0,3,0],layer:o?.layer??"F.Fab",uuid:cd(`${t}-property-Value`),effects:Bj(o?.effects),hidden:o?.hide}));const r=A.properties.Datasheet;i.push(new y1({key:"Datasheet",value:r?.value??"",position:r?.at?[Number(r.at.x),Number(r.at.y),Number(r.at.rotation??0)]:[0,0,0],layer:r?.layer??"F.Fab",uuid:cd(`${t}-property-Datasheet`),effects:Bj(r?.effects),hidden:r?.hide??!0}));const a=A.properties.Description;i.push(new y1({key:"Description",value:a?.value??"",position:a?.at?[Number(a.at.x),Number(a.at.y),Number(a.at.rotation??0)]:[0,0,0],layer:a?.layer??"F.Fab",uuid:cd(`${t}-property-Description`),effects:Bj(a?.effects),hidden:a?.hide??!0})),e.properties=i}if(A.attributes&&(e.attr||(e.attr=new uDA),A.attributes.through_hole?e.attr.type="through_hole":A.attributes.smd&&(e.attr.type="smd"),A.attributes.exclude_from_pos_files!==void 0&&(e.attr.excludeFromPosFiles=A.attributes.exclude_from_pos_files),A.attributes.exclude_from_bom!==void 0&&(e.attr.excludeFromBom=A.attributes.exclude_from_bom)),A.footprintName&&(e.libraryLink=A.footprintName),A.layer&&(e.layer=A.layer),A.embeddedFonts!==void 0&&(e.embeddedFonts=new GM(A.embeddedFonts)),A.model){const i=new L3(A.model.path);A.model.offset&&(i.offset={x:Number(A.model.offset.x),y:Number(A.model.offset.y),z:Number(A.model.offset.z)}),A.model.scale&&(i.scale={x:Number(A.model.scale.x),y:Number(A.model.scale.y),z:Number(A.model.scale.z)}),A.model.rotate&&(i.rotate={x:Number(A.model.rotate.x),y:Number(A.model.rotate.y),z:Number(A.model.rotate.z)});const n=e.models||[];e.models=[i,...n]}}function pQi(e,A){const t=[];for(const i of e){const n=i.center.x-A.x,o=-(i.center.y-A.y),r={top:"F.SilkS",bottom:"B.SilkS"}[i.layer]||i.layer||"F.SilkS",a=new t1A({center:{x:n,y:o},end:{x:n+i.radius,y:o},layer:r,stroke:new f1,fill:!1});a.stroke&&(a.stroke.width=i.stroke_width||.05,a.stroke.type="default"),t.push(a)}return t}function fQi(e,A){const t=[];for(const i of e){const n=i.center.x-A.x,o=-(i.center.y-A.y),r={top:"F.CrtYd",bottom:"B.CrtYd"}[i.layer]||"F.CrtYd",a=new t1A({center:{x:n,y:o},end:{x:n+i.radius,y:o},layer:r,stroke:new f1,fill:!1});a.stroke&&(a.stroke.width=.05,a.stroke.type="default"),t.push(a)}return t}function yQi(e,A){const t=[];for(const i of e){const n=i.center.x-A.x,o=-(i.center.y-A.y),s=i.width/2,r=i.height/2,g={top:"F.Fab",bottom:"B.Fab"}[i.layer]||i.layer||"F.Fab",c=new Aj({start:{x:n-s,y:o-r},end:{x:n+s,y:o+r},layer:g,stroke:new f1,fill:!1});c.stroke&&(c.stroke.width=i.stroke_width||.1,c.stroke.type="default"),t.push(c)}return t}function mQi(e,A){const t=[];for(const i of e){const n=i.center.x-A.x,o=-(i.center.y-A.y),s=i.width/2,r=i.height/2,a="F.Fab",g=new Aj({start:{x:n-s,y:o-r},end:{x:n+s,y:o+r},layer:a,stroke:new f1,fill:!1});g.stroke&&(g.stroke.width=i.stroke_width||.1,g.stroke.type="default"),t.push(g)}return t}function wQi(e,A){const t=[];for(const i of e){const n=i.center.x-A.x,o=-(i.center.y-A.y),s=i.width/2,r=i.height/2,g={top:"F.CrtYd",bottom:"B.CrtYd"}[i.layer]||"F.CrtYd",c=new Aj({start:{x:n-s,y:o-r},end:{x:n+s,y:o+r},layer:g,stroke:new f1,fill:!1});c.stroke&&(c.stroke.width=.05,c.stroke.type="default"),t.push(c)}return t}function DQi(e,A){const t=[];for(const i of e){if(!i.outline||i.outline.length<2)continue;const o={top:"F.CrtYd",bottom:"B.CrtYd"}[i.layer]||"F.CrtYd",s=i.outline.map(g=>{const c=g.x-A.x,I=-(g.y-A.y);return new oh(c,I)}),r=new Hpt;r.points=new oQ(s),r.layer=o,r.fill=!1;const a=new f1;a.width=.05,a.type="default",r.stroke=a,t.push(r)}return t}function xQi({textElement:e,componentCenter:A,componentRotation:t=0}){if(!e.text||!e.anchor_position)return null;const i=e.anchor_position.x-A.x,n=-(e.anchor_position.y-A.y),o=t!==0?Jl(t*Math.PI/180):Sa(),s=Ct(o,{x:i,y:n}),r={x:s.x,y:s.y},g={top:"F.SilkS",bottom:"B.SilkS"}[e.layer]||e.layer||"F.SilkS",c=(e.font_size||1)/1.5,I=new Tp;I.size={width:c,height:c};const l=new Jp({font:I}),B=e.ccw_rotation||0;return new qDA({type:"user",text:e.text,position:{x:r.x,y:r.y,angle:B},layer:g,effects:l})}function SQi(e,A,t,i){const n=[];for(const o of e){const s=xQi({textElement:o,componentCenter:A,componentRotation:t});s&&(i&&o.text===i&&(s.type="reference"),n.push(s))}return n}function bQi(e,A,t){const i=[];for(const n of e){const o=n.anchor_position.x-A.x,s=-(n.anchor_position.y-A.y),r=t!==0?Jl(t*Math.PI/180):Sa(),a=Ct(r,{x:o,y:s}),g=n.font_size||1,c=new Tp;c.size={width:g,height:g};const I=new Jp({font:c}),l=new qDA({type:"user",text:n.text,position:{x:a.x,y:a.y,angle:0},layer:"F.Fab",effects:I});i.push(l)}return i}function _Qi(e,A,t){const i=[],n=e.model_step_url||e.model_wrl_url;if(!n)return i;const o=new L3(n);if(e.position){const s=t?.boardLayerZOffset??0;o.offset={x:(e.position.x||0)-A.x,y:(e.position.y||0)-A.y,z:(e.position.z||0)-s}}if(e.rotation&&(o.rotate={x:e.rotation.x||0,y:e.rotation.y||0,z:e.rotation.z||0}),e.model_unit_to_mm_scale_factor){const s=e.model_unit_to_mm_scale_factor;o.scale={x:s,y:s,z:s}}return i.push(o),i}function kQi({pcbPad:e,componentCenter:A,padNumber:t,componentRotation:i=0,netInfo:n,componentId:o}){let s,r;if("x"in e&&"y"in e)s=e.x,r=e.y;else if("points"in e&&Array.isArray(e.points)){const u=e.points;s=u.reduce((d,f)=>d+f.x,0)/u.length,r=u.reduce((d,f)=>d+f.y,0)/u.length}else throw new Error("Pad must have either x/y coordinates or points array");const a=tn(i!==0?Jl(i*Math.PI/180):{a:1,b:0,c:0,d:1,e:0,f:0},za(1,-1),sn(-A.x,-A.y)),g=Ct(a,{x:s,y:r}),I={top:"F.Cu",bottom:"B.Cu"}[e.layer]||"F.Cu";let l,B,C,Q;if(e.shape==="circle")l="circle",B=["radius"in e?e.radius*2:.5,"radius"in e?e.radius*2:.5];else if(e.shape==="polygon"&&"points"in e){const u=e.points,d=tn(za(1,-1),sn(-s,-r)),f=u.map(w=>{const D=Ct(d,{x:w.x,y:w.y});return new oh(D.x,D.y)}),m=new YDA;m.contours=[new oQ(f)],m.width=0,m.filled=!0,Q=new ypt,Q.addGraphic(m),l="custom",C=new opt,C.anchor="circle",B=[.2,.2]}else l="rect",B=["width"in e?e.width:.5,"height"in e?e.height:.5];const h=`pad:${o}:${t}:${g.x},${g.y}`,E=new $V({number:String(t),padType:"smd",shape:l,at:[g.x,g.y,0],size:B,layers:[`${I}`,`${I==="F.Cu"?"F":"B"}.Paste`,`${I==="F.Cu"?"F":"B"}.Mask`],uuid:cd(h)});return C&&(E.options=C),Q&&(E.primitives=Q),n&&(E.net=new GDA(n.id,n.name)),E}function vQi(e,A,t,i,n,o){const s=[];let r=n;for(const a of e){const g=o(a.pcb_port_id),c=kQi({pcbPad:a,componentCenter:A,padNumber:r,componentRotation:t,netInfo:g,componentId:i});s.push(c),r++}return{pads:s,nextPadNumber:r}}function FQi({platedHole:e,componentCenter:A,padNumber:t,componentRotation:i=0,netInfo:n,componentId:o}){if(!("x"in e&&"y"in e))return null;const s=e.x-A.x,r=-(e.y-A.y),a=i!==0?Jl(i*Math.PI/180):Sa(),g=Ct(a,{x:s,y:r});let c="circle",I,l,B=0;const C="hole_offset_x"in e||"hole_offset_y"in e;let Q;if(C){const u={x:e.hole_offset_x??0,y:e.hole_offset_y??0};(u.x!==0||u.y!==0)&&(Q=Ct(a,{x:-u.x,y:u.y}))}e.shape==="circle"?(c="circle",I=[e.outer_diameter,e.outer_diameter],l=new m1({diameter:e.hole_diameter,offset:Q})):e.shape==="pill"||e.shape==="oval"?(c="oval",I=[e.outer_width,e.outer_height],l=new m1({oval:!0,diameter:e.hole_width,width:e.hole_height,offset:Q})):e.shape==="pill_hole_with_rect_pad"?(c="rect",I=[e.rect_pad_width,e.rect_pad_height],l=new m1({oval:!0,diameter:e.hole_width,width:e.hole_height,offset:Q})):e.shape==="circular_hole_with_rect_pad"?(c="rect",I=[e.rect_pad_width,e.rect_pad_height],l=new m1({diameter:e.hole_diameter,offset:Q})):e.shape==="rotated_pill_hole_with_rect_pad"?(c="rect",I=[e.rect_pad_width,e.rect_pad_height],l=new m1({oval:!0,diameter:e.hole_width,width:e.hole_height,offset:Q}),B=e.rect_ccw_rotation||0):(c="circle",I=[1.6,1.6],l=new m1({diameter:.8,offset:Q}));const h=`thruhole:${o}:${t}:${g.x},${g.y}`,E=new $V({number:String(t),padType:"thru_hole",shape:c,at:[g.x,g.y,B],size:I,drill:l,layers:["*.Cu","*.Mask"],removeUnusedLayers:!1,uuid:cd(h)});return n&&(E.net=new GDA(n.id,n.name)),E}function MQi(e,A,t,i,n,o){const s=[];let r=n;for(const a of e){const g=o(a.pcb_port_id),c=FQi({platedHole:a,componentCenter:A,padNumber:r,componentRotation:t,netInfo:g,componentId:i});c&&(s.push(c),r++)}return{pads:s,nextPadNumber:r}}function GQi({pcbHole:e,componentCenter:A,componentRotation:t=0}){if(!("x"in e&&"y"in e))return null;const i=e.x-A.x,n=-(e.y-A.y),o=t!==0?Jl(t*Math.PI/180):Sa(),s=Ct(o,{x:i,y:n});let r="circle",a,g;if(e.hole_shape==="circle"){r="circle";const c=e.hole_diameter;a=[c,c],g=new m1({diameter:c})}else if(e.hole_shape==="oval"){r="oval";const c=e.hole_width,I=e.hole_height;a=[c,I],g=new m1({oval:!0,diameter:c,width:I})}else{r="circle";const c="hole_diameter"in e?e.hole_diameter:1;a=[c,c],g=new m1({diameter:c})}return new $V({number:"",padType:"np_thru_hole",shape:r,at:[s.x,s.y,0],size:a,drill:g,layers:["*.Cu","*.Mask"],removeUnusedLayers:!1,uuid:crypto.randomUUID()})}function pyt(e,A,t){const i=[];for(const n of e){const o=GQi({pcbHole:n,componentCenter:A,componentRotation:t});o&&i.push(o)}return i}var RQi=class extends t0{componentsProcessed=0;pcbComponents=[];includeBuiltin3dModels;getNetInfoForPcbPort(e){if(!e)return;const A=this.ctx.db.pcb_port?.get(e);if(!A)return;const t=A.source_port_id;if(!t)return;const i=this.ctx.db.source_port?.get(t);if(!i)return;const n=i.subcircuit_connectivity_map_key;if(n)return this.ctx.pcbNetMap?.get(n)}getCadComponentForPcbComponent(e){return(this.ctx.db.cad_component?.list()||[]).find(t=>t.pcb_component_id===e)}constructor(e,A,t){super(e,A),this.pcbComponents=this.ctx.db.pcb_component.list(),this.includeBuiltin3dModels=t?.includeBuiltin3dModels??!1}_step(){const{kicadPcb:e,c2kMatPcb:A}=this.ctx;if(!e)throw new Error("KicadPcb instance not initialized in context");if(!A)throw new Error("PCB transformation matrix not initialized in context");if(this.componentsProcessed>=this.pcbComponents.length){this.finished=!0;return}const t=this.pcbComponents[this.componentsProcessed],i=t.source_component_id?this.ctx.db.source_component.get(t.source_component_id):null,n=this.getCadComponentForPcbComponent(t.pcb_component_id),o=i?U3(i,n):"Unknown",s=Ct(A,{x:t.center.x,y:t.center.y}),r=`footprint:${t.pcb_component_id}:${s.x},${s.y}`,a=new nj({libraryLink:`tscircuit:${o}`,layer:"F.Cu",at:[s.x,s.y,t.rotation||0],uuid:cd(r)}),g=a.fpTexts,c=this.ctx.db.pcb_silkscreen_text?.list().filter(O=>O.pcb_component_id===t.pcb_component_id)||[];g.push(...SQi(c,t.center,t.rotation||0,i?.name));const I=this.ctx.db.pcb_note_text?.list().filter(O=>O.pcb_component_id===t.pcb_component_id)||[];g.push(...bQi(I,t.center,t.rotation||0)),a.fpTexts=g;const l=a.fpPads,B=O=>this.getNetInfoForPcbPort(O),C=this.ctx.db.pcb_smtpad?.list().filter(O=>O.pcb_component_id===t.pcb_component_id)||[],{pads:Q,nextPadNumber:h}=vQi(C,t.center,t.rotation||0,t.pcb_component_id,1,B);l.push(...Q);const E=this.ctx.db.pcb_plated_hole?.list().filter(O=>O.pcb_component_id===t.pcb_component_id)||[],{pads:u}=MQi(E,t.center,t.rotation||0,t.pcb_component_id,h,B);l.push(...u);const d=this.ctx.db.pcb_hole?.list().filter(O=>O.pcb_component_id===t.pcb_component_id)||[],f=pyt(d,t.center,t.rotation||0);l.push(...f),a.fpPads=l;const m=this.ctx.db.pcb_silkscreen_circle?.list().filter(O=>O.pcb_component_id===t.pcb_component_id)||[],w=a.fpCircles??[];w.push(...pQi(m,t.center));const D=this.ctx.db.pcb_courtyard_circle?.list().filter(O=>O.pcb_component_id===t.pcb_component_id)||[];w.push(...fQi(D,t.center)),a.fpCircles=w;const x=this.ctx.db.pcb_fabrication_note_rect?.list().filter(O=>O.pcb_component_id===t.pcb_component_id)||[],_=a.fpRects??[];_.push(...yQi(x,t.center));const b=this.ctx.db.pcb_note_rect?.list().filter(O=>O.pcb_component_id===t.pcb_component_id)||[];_.push(...mQi(b,t.center));const R=this.ctx.db.pcb_courtyard_rect?.list().filter(O=>O.pcb_component_id===t.pcb_component_id)||[];_.push(...wQi(R,t.center)),a.fpRects=_;const F=this.ctx.db.pcb_courtyard_outline?.list().filter(O=>O.pcb_component_id===t.pcb_component_id)||[],H=DQi(F,t.center);if(H.length>0&&(a.fpPolys=H),n){const W=this.ctx.db.pcb_board?.list()[0]?.thickness??0,z=t.layer==="bottom"?-(W/2):W/2,tA=_Qi(n,t.center,{boardLayerZOffset:z}),aA="${KIPRJMOD}/3dmodels";if(tA.length>0)this.includeBuiltin3dModels?a.models=tA.map(eA=>{if(!eA.path)return eA;const oA=b2A(eA.path),lA=eA.path.startsWith("http://modelcdn.tscircuit.com")||eA.path.startsWith("https://modelcdn.tscircuit.com")?"tscircuit_builtin":this.ctx.projectName??oA.replace(/\.[^.]+$/,""),pA=new L3(`${aA}/${lA}.3dshapes/${oA}`);eA.offset&&(pA.offset=eA.offset),eA.scale&&(pA.scale=eA.scale),eA.rotate&&(pA.rotate=eA.rotate);const kA=eA.path?.split("?")[0];return kA&&!this.ctx.pcbModel3dSourcePaths?.includes(kA)&&this.ctx.pcbModel3dSourcePaths?.push(kA),pA}):a.models=tA;else if(n.footprinter_string&&this.includeBuiltin3dModels){const{footprinter_string:eA}=n,oA=`${aA}/tscircuit_builtin.3dshapes/${eA}.step`;a.models=[new L3(oA)];const rA=`${dyt}/${eA}.step`;this.ctx.pcbModel3dSourcePaths?.includes(rA)||this.ctx.pcbModel3dSourcePaths?.push(rA)}}const Y=t.metadata?.kicad_footprint;Y&&i?.name&&dQi(a,Y,i.name);const J=e.footprints;J.push(a),e.footprints=J,this.componentsProcessed++}getOutput(){return this.ctx.kicadPcb}},NQi={top:"F.Cu",bottom:"B.Cu",inner1:"In1.Cu",inner2:"In2.Cu",inner3:"In3.Cu",inner4:"In4.Cu",inner5:"In5.Cu",inner6:"In6.Cu"};function LQi(e){return e&&(NQi[e]||e)||"F.Cu"}function UQi(e){const A=["F.Cu"];for(let t=1;t<e-1;t++)A.push(`In${t}.Cu`);return A.push("B.Cu"),A}var HQi=class extends t0{tracesProcessed=0;pcbTraces=[];constructor(e,A){super(e,A),this.pcbTraces=this.ctx.db.pcb_trace.list()}_step(){const{kicadPcb:e,c2kMatPcb:A,pcbNetMap:t}=this.ctx;if(!e)throw new Error("KicadPcb instance not initialized in context");if(!A)throw new Error("PCB transformation matrix not initialized in context");if(this.tracesProcessed>=this.pcbTraces.length){this.finished=!0;return}const i=this.pcbTraces[this.tracesProcessed];if(!i.route||i.route.length<2){this.tracesProcessed++;return}let n=i.route[0]?.layer;for(let o=0;o<i.route.length-1;o++){const s=i.route[o],r=i.route[o+1],a=Ct(A,{x:s.x,y:s.y}),g=Ct(A,{x:r.x,y:r.y});let c;if(t){let h=i.subcircuit_connectivity_map_key;if(!h&&i.source_trace_id){const E=this.ctx.db.source_trace?.get(i.source_trace_id);if(E&&(h=E.subcircuit_connectivity_map_key,!h&&E.connected_source_net_ids?.length))for(const u of E.connected_source_net_ids){const d=this.ctx.db.source_net?.get(u);if(d?.subcircuit_connectivity_map_key){h=d.subcircuit_connectivity_map_key;break}}}if(!h&&typeof i.connection_name=="string"){const E=this.ctx.db.source_net?.get(i.connection_name);E?.subcircuit_connectivity_map_key&&(h=E.subcircuit_connectivity_map_key)}h&&(c=t.get(h))}const I=s.layer??r.layer??n,l=LQi(I),B=`segment:${a.x},${a.y}:${g.x},${g.y}:${l}:${c?.id??0}`,C=new _1A({start:{x:a.x,y:a.y},end:{x:g.x,y:g.y},layer:l,width:i.width||.25,net:new rj(c?.id??0),uuid:cd(B)}),Q=e.segments;Q.push(C),e.segments=Q,s.layer&&(n=s.layer),r.layer&&(n=r.layer)}this.tracesProcessed++}getOutput(){return this.ctx.kicadPcb}},YQi=class extends t0{viasProcessed=0;pcbVias=[];constructor(e,A){super(e,A),this.pcbVias=this.ctx.db.pcb_via?.list()||[]}_step(){const{kicadPcb:e,c2kMatPcb:A,pcbNetMap:t}=this.ctx;if(!e)throw new Error("KicadPcb instance not initialized in context");if(!A)throw new Error("PCB transformation matrix not initialized in context");if(this.viasProcessed>=this.pcbVias.length){this.finished=!0;return}const i=this.pcbVias[this.viasProcessed],n=Ct(A,{x:i.x,y:i.y});let o;if(t){let I=i.subcircuit_connectivity_map_key;if(!I&&i.pcb_trace_id){const l=this.ctx.db.pcb_trace?.get(i.pcb_trace_id);if(l&&("subcircuit_connectivity_map_key"in l&&(I=l.subcircuit_connectivity_map_key),!I&&l.source_trace_id)){const B=this.ctx.db.source_trace?.get(l.source_trace_id);if(B&&("subcircuit_connectivity_map_key"in B&&(I=B.subcircuit_connectivity_map_key),!I&&B.connected_source_net_ids?.length))for(const C of B.connected_source_net_ids){const Q=this.ctx.db.source_net?.get(C);if(Q?.subcircuit_connectivity_map_key){I=Q.subcircuit_connectivity_map_key;break}}}}if(!I&&i.connection_name){const l=this.ctx.db.source_net?.get(i.connection_name);l?.subcircuit_connectivity_map_key&&(I=l.subcircuit_connectivity_map_key)}I&&(o=t.get(I))}const s=this.ctx.numLayers??2,r=i.layers?i.layers.map(I=>I==="top"?"F.Cu":I==="bottom"?"B.Cu":`In${I.replace("inner","")}.Cu`):UQi(s),a=`via:${n.x},${n.y}:${i.outer_diameter||.8}:${i.hole_diameter||.4}:${o?.id??0}`,g=new D2A({at:[n.x,n.y],size:i.outer_diameter||.8,drill:i.hole_diameter||.4,layers:r,net:new w2A(o?.id??0),uuid:cd(a)}),c=e.vias;c.push(g),e.vias=c,this.viasProcessed++}getOutput(){return this.ctx.kicadPcb}},JQi=class extends t0{holesProcessed=0;standaloneHoles=[];constructor(e,A){super(e,A),this.standaloneHoles=this.ctx.db.pcb_hole.list().filter(t=>!t.pcb_component_id)}_step(){const{kicadPcb:e,c2kMatPcb:A}=this.ctx;if(!e)throw new Error("KicadPcb instance not initialized in context");if(!A)throw new Error("PCB transformation matrix not initialized in context");if(this.holesProcessed>=this.standaloneHoles.length){this.finished=!0;return}const t=this.standaloneHoles[this.holesProcessed];if(!t){this.holesProcessed++;return}const i=Ct(A,{x:0,y:0}),n=`standalone_hole:${t.pcb_hole_id}:${t.x},${t.y}`,o=new nj({libraryLink:"tscircuit:MountingHole",layer:"F.Cu",at:[i.x,i.y,0],uuid:cd(n)}),r=pyt([t],{x:0,y:0},0);if(r.length>0){o.fpPads=r;const a=e.footprints;a.push(o),e.footprints=a}this.holesProcessed++}getOutput(){return this.ctx.kicadPcb}};function TQi({textElement:e,c2kMatPcb:A}){if(!e.text||!e.anchor_position)return null;const t=Ct(A,{x:e.anchor_position.x,y:e.anchor_position.y}),n={top:"F.Fab",bottom:"B.Fab"}[e.layer]||e.layer||"F.Fab",o=(e.font_size||1)/1.5,s=new Tp;s.size={width:o,height:o};const r=new a6,a=e.anchor_alignment||"center";switch(a){case"top_left":r.horizontal="left",r.vertical="top";break;case"top_right":r.horizontal="right",r.vertical="top";break;case"bottom_left":r.horizontal="left",r.vertical="bottom";break;case"bottom_right":r.horizontal="right",r.vertical="bottom";break}const g=new Jp({font:s});a!=="center"&&(g.justify=r);const c=new oc([t.x,t.y,0]),I=new sj({text:e.text,layer:n,effects:g});return I.position=c,I}function PQi({textElement:e,c2kMatPcb:A}){if(!e.text||!e.anchor_position)return null;const t=Ct(A,{x:e.anchor_position.x,y:e.anchor_position.y}),n={top:"F.SilkS",bottom:"B.SilkS"}[e.layer]||e.layer||"F.SilkS",o=(e.font_size||1)/1.5,s=new Tp;s.size={width:o,height:o};const r=new a6,a=e.anchor_alignment||"center";switch(a){case"top_left":r.horizontal="left",r.vertical="top";break;case"top_right":r.horizontal="right",r.vertical="top";break;case"bottom_left":r.horizontal="left",r.vertical="bottom";break;case"bottom_right":r.horizontal="right",r.vertical="bottom";break}const g=new Jp({font:s});a!=="center"&&(g.justify=r);const c=e.ccw_rotation||0,I=new oc([t.x,t.y,c]),l=new sj({text:e.text,layer:n,effects:g});return l.position=I,l}var KQi=class extends t0{_step(){const{kicadPcb:e,c2kMatPcb:A}=this.ctx;if(!e)throw new Error("KicadPcb instance not initialized in context");if(!A)throw new Error("PCB transformation matrix not initialized in context");const t=this.ctx.db.pcb_silkscreen_path?.list()||[];for(const s of t)if(!(!s.route||s.route.length<2))for(let r=0;r<s.route.length-1;r++){const a=s.route[r],g=s.route[r+1];if(!a||!g)continue;const c=Ct(A,{x:a.x,y:a.y}),I=Ct(A,{x:g.x,y:g.y}),B={top:"F.SilkS",bottom:"B.SilkS"}[s.layer]||s.layer||"F.SilkS",C=new oj({start:{x:c.x,y:c.y},end:{x:I.x,y:I.y},layer:B,width:s.stroke_width||.15}),Q=e.graphicLines;Q.push(C),e.graphicLines=Q}const i=this.ctx.db.pcb_silkscreen_text?.list().filter(s=>!s.pcb_component_id)||[];for(const s of i){const r=PQi({textElement:s,c2kMatPcb:A});if(r){const a=e.graphicTexts;a.push(r),e.graphicTexts=a}}const n=this.ctx.db.pcb_fabrication_note_text?.list()||[];for(const s of n){const r=TQi({textElement:s,c2kMatPcb:A});if(r){const a=e.graphicTexts;a.push(r),e.graphicTexts=a}}const o=this.ctx.db.pcb_board?.list()||[];if(o.length>0){const s=o[0];if(!s){this.finished=!0;return}let r;if(s.outline&&s.outline.length>0)r=s.outline;else{const g=s.width?s.width/2:0,c=s.height?s.height/2:0;r=[{x:s.center.x-g,y:s.center.y-c},{x:s.center.x+g,y:s.center.y-c},{x:s.center.x+g,y:s.center.y+c},{x:s.center.x-g,y:s.center.y+c}]}const a=r.map(g=>Ct(A,g));for(let g=0;g<a.length;g++){const c=a[g],I=a[(g+1)%a.length];if(!c||!I)continue;const l=new oj({start:{x:c.x,y:c.y},end:{x:I.x,y:I.y},layer:"Edge.Cuts",width:.1}),B=e.graphicLines;B.push(l),e.graphicLines=B}}this.finished=!0}getOutput(){return this.ctx.kicadPcb}},fyt=class{ctx;pipeline;currentStageIndex=0;finished=!1;get currentStage(){return this.pipeline[this.currentStageIndex]}constructor(e,A){this.ctx={db:Na(e),circuitJson:e,kicadPcb:new x2A({generator:"circuit-json-to-kicad",generatorVersion:"0.0.1"}),c2kMatPcb:tn(sn(100,100),za(1,-1)),projectName:A?.projectName,pcbModel3dSourcePaths:[]},this.pipeline=[new lQi(e,this.ctx),new BQi(e,this.ctx),new RQi(e,this.ctx,{includeBuiltin3dModels:A?.includeBuiltin3dModels}),new HQi(e,this.ctx),new YQi(e,this.ctx),new JQi(e,this.ctx),new KQi(e,this.ctx)]}step(){if(!this.currentStage){this.finished=!0;return}this.currentStage.step(),this.currentStage.finished&&this.currentStageIndex++}runUntilFinished(){for(;!this.finished;)this.step()}getOutput(){return this.ctx.kicadPcb}getOutputString(){return this.ctx.kicadPcb.getString()}getModel3dSourcePaths(){return this.ctx.pcbModel3dSourcePaths??[]}},qQi=class{ctx;project;constructor(e,A={}){const t=A.projectName??e?.project?.name??"circuit-json-project",i=A.schematicFilename??`${t}.kicad_sch`,n=A.pcbFilename??`${t}.kicad_pcb`,o=new Date().toISOString();this.ctx={db:Na(e),circuitJson:e},this.project={version:1,head:{generator:"circuit-json-to-kicad",generator_version:"0.0.1",project_name:t,created:o,modified:o},meta:{version:1},text_variables:{},libraries:{pinned_symbol_libs:[],pinned_footprint_libs:[]},boards:[],cvpcb:{meta:{version:0}},erc:{meta:{version:0},erc_exclusions:[]},net_settings:{meta:{version:1},last_net_id:0,classes:[]},pcbnew:{page_layout_descr_file:"",last_paths:{}},schematic:{meta:{version:1},page_layout_descr_file:"",last_opened_files:[i]},board:{meta:{version:1},last_opened_board:n},sheets:[[Math.random().toString(36).substring(2,15),"Root"]]}}runUntilFinished(){}getOutput(){return this.project}getOutputString(){return`${JSON.stringify(this.project,null,2)}
|
|
5830
5830
|
`}},OQi=class extends t0{_step(){const e=new uyt(this.ctx.circuitJson);e.runUntilFinished(),this.ctx.kicadSchString=e.getOutputString();const A=new fyt(this.ctx.circuitJson);A.runUntilFinished(),this.ctx.kicadPcbString=A.getOutputString(),this.finished=!0}getOutput(){return this.ctx.libraryOutput}},WQi=class extends t0{isCustomSymbol(e){return e?.startsWith("Custom:")??!1}_step(){const e=this.ctx.kicadSchString,A=this.ctx.fpLibraryName??"tscircuit";if(!e)throw new Error("Schematic content not available. Run GenerateKicadSchAndPcbStage first.");const t=new Map;try{const n=lyt(e).find(r=>r instanceof EDA);if(!n){this.ctx.symbolEntries=[],this.finished=!0;return}const o=n.libSymbols;if(!o){this.ctx.symbolEntries=[],this.finished=!0;return}const s=o.symbols??[];for(const r of s){const a=this.isCustomSymbol(r.libraryId),g=this.sanitizeSymbolName(r.libraryId);t.has(g)||(r.libraryId=g,this.updateFootprintProperty(r,A),a||this.snapPinPositionsToGrid(r),t.set(g,{symbolName:g,symbol:r,isBuiltin:!a}))}}catch(i){console.warn("Failed to parse schematic for symbol extraction:",i)}this.ctx.symbolEntries=Array.from(t.values()),this.finished=!0}updateFootprintProperty(e,A){const t=e.properties??[];for(const i of t)if(i.key==="Footprint"&&i.value){const n=i.value.split(":");n.length>1?i.value=`${A}:${n[1]}`:i.value.trim()&&(i.value=`${A}:${i.value}`)}}sanitizeSymbolName(e){if(!e)return"symbol";const A=e.split(":");return(A.length>1?A[1]:A[0])?.replace(/[\\\/]/g,"-").trim()||"symbol"}snapPinPositionsToGrid(e){for(const t of e.subSymbols??[]){for(const i of t.pins??[])i.at&&(i.at.x=Math.round(i.at.x/1.27)*1.27,i.at.y=Math.round(i.at.y/1.27)*1.27);for(const i of t.polylines??[])if(i.points?.points)for(const n of i.points.points)"x"in n&&"y"in n&&(n.x=Math.round(n.x/1.27)*1.27,n.y=Math.round(n.y/1.27)*1.27)}}getOutput(){return this.ctx.libraryOutput}},ZQi=20211014,VQi="circuit-json-to-kicad",jQi=class extends t0{_step(){const e=this.ctx.symbolEntries??[],A=this.generateSymbolLibrary(e);this.ctx.libraryOutput||(this.ctx.libraryOutput={kicadSymString:"",symbols:[],footprints:[],fpLibTableString:"",symLibTableString:"",model3dSourcePaths:[]}),this.ctx.libraryOutput.kicadSymString=A,this.finished=!0}generateSymbolLibrary(e){return new Fdt({version:ZQi,generator:VQi,symbols:e.map(t=>t.symbol)}).getString()}getOutput(){return this.ctx.libraryOutput}},zQi=class extends t0{_step(){const e=this.ctx.libraryName??"tscircuit",A=this.ctx.fpLibraryName??"tscircuit",t=this.ctx.footprintEntries??[],i=this.ctx.symbolEntries??[],n=new Set;for(const r of t)for(const a of r.model3dSourcePaths)n.add(a);const o=this.generateFpLibTable(A),s=this.generateSymLibTable(e);this.ctx.libraryOutput||(this.ctx.libraryOutput={kicadSymString:"",symbols:[],footprints:[],fpLibTableString:"",symLibTableString:"",model3dSourcePaths:[]}),this.ctx.libraryOutput.symbols=i,this.ctx.libraryOutput.footprints=t,this.ctx.libraryOutput.fpLibTableString=o,this.ctx.libraryOutput.symLibTableString=s,this.ctx.libraryOutput.model3dSourcePaths=Array.from(n),this.finished=!0}generateFpLibTable(e){return`(fp_lib_table
|
|
5831
5831
|
(version 7)
|
|
5832
5832
|
(lib (name "${e}") (type "KiCad") (uri "\${KIPRJMOD}/${e}.pretty") (options "") (descr "Generated by circuit-json-to-kicad"))
|