@tscircuit/runframe 0.0.1764 → 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.
package/dist/standalone.min.js
CHANGED
|
@@ -5433,7 +5433,7 @@ You passed in: '`+this.raw_options[o]+"'");return a},e.prototype._is_valid_selec
|
|
|
5433
5433
|
`);break}}return s}}}),oei=ha({"node_modules/pretty/index.js"(t,A){var e=$Ai(),i=nei(),n=Ohe(),o={unformatted:["code","pre","em","strong","span"],indent_inner_html:!0,indent_char:" ",indent_size:2,sep:`
|
|
5434
5434
|
`};A.exports=function(a,g){var c=n({},o,g);return a=e.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,`
|
|
5435
5435
|
`).replace(/(\s*<!--)/g,`
|
|
5436
|
-
$1`).replace(/>(\s*)(?=<!--\s*\/)/g,"> ")}}});function Whe(t,A,e){if(!A||!e)return;let i=t.get(A);i||(i=new Set,t.set(A,i)),i.add(e);let n=t.get(e);n||(n=new Set,t.set(e,n)),n.add(A)}function sei(t,A){if(!A.subcircuit_id&&!A.source_group_id)return[...t];let e=A;if(A.subcircuit_id){const r=new Set([A.subcircuit_id]),a=new Map,g=new Map;for(const I of t)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),e={...A,subcircuit_ids:Array.from(r)}}}const i=new Map;for(const r of t){const a=`${r.type}_id`,g=r[a];typeof g=="string"&&i.set(g,r)}const n=new Map;for(const r of t){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);Whe(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);Whe(n,r,l)}}}}const o=[],s=new Set;for(const r of t){let a=!1;(e.subcircuit_id&&"subcircuit_id"in r&&r.subcircuit_id===e.subcircuit_id||e.subcircuit_ids&&"subcircuit_id"in r&&r.subcircuit_id&&e.subcircuit_ids.includes(r.subcircuit_id)||e.source_group_id&&"source_group_id"in r&&r.source_group_id===e.source_group_id||e.source_group_id&&"member_source_group_ids"in r&&Array.isArray(r.member_source_group_ids)&&r.member_source_group_ids.includes(e.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 t.filter(r=>s.has(r))}var MV=(t,A={})=>{const e=t;let i=e._internal_store;if(!i){i={counts:{},editCount:0},e._internal_store=i;for(const o of e){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()=>(e.editCount=i.editCount,e);if(s==="editCount")return i.editCount;if(s==="subtree")return a=>MV(sei(e,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&&(jyA[g]??rV).parse(I),e.push(I),i.editCount++,I};if(s==="insertAll")return a=>a.map(g=>n.insert(g));const r=s;return{get:a=>e.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=e.find(B=>B.type===I&&B[c]===a[c]);return l?e.find(B=>B.type===r&&B[`${r}_id`]===l[`${r}_id`]):null},getWhere:a=>{const g=Object.keys(a);return e.find(c=>c.type===r&&g.every(I=>c[I]===a[I]))},list:a=>{const g=a?Object.keys(a):[];return e.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&&(jyA[r]??rV).parse(c),e.push(c),i.editCount++,c},delete:a=>{const g=e.find(c=>c[`${r}_id`]===a);g&&(e.splice(e.indexOf(g),1),i.editCount++)},update:(a,g)=>{const c=e.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 e.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=e.find(B=>B.type==="source_component"&&B.name===g);if(!I)return null;const l=e.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 e.find(B=>B.type==="pcb_port"&&B.source_port_id===l.source_port_id);if(r==="schematic_port")return e.find(B=>B.type==="schematic_port"&&B.source_port_id===l.source_port_id)}}}}});return n};MV.unparsed=MV;var rx=MV;function bmA(t){const A=t.type;return`${A}:${t[`${A}_id`]}`}var Zhe=(t,A={})=>{let e=t._internal_store_indexed;if(!e){e={counts:{},editCount:0,indexes:{}};for(const s of t){const r=s.type,a=s[`${r}_id`];if(!a)continue;const g=Number.parseInt(a.split("_").pop()||"");Number.isNaN(g)||(e.counts[r]=Math.max(e.counts[r]??0,g))}const n=A.indexConfig||{},o=e.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 t){if(n.byId){const r=bmA(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)}}}}t._internal_store_indexed=e}return new Proxy({},{get:(n,o)=>{if(o==="toArray")return()=>(t.editCount=e.editCount,t);if(o==="editCount")return e.editCount;const s=o;return{get:r=>{const a=A.indexConfig||{};return a.byId&&e.indexes.byId?e.indexes.byId.get(`${s}:${r}`)||null:a.byType&&e.indexes.byType?(e.indexes.byType.get(s)||[]).find(c=>c[`${s}_id`]===r)||null:t.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&&e.indexes.byRelation){const B=e.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&&e.indexes.byId?e.indexes.byId.get(`${s}:${h}`)||null:a.byType&&e.indexes.byType?(e.indexes.byType.get(s)||[]).find(u=>u[`${s}_id`]===h)||null:t.find(E=>E.type===s&&E[`${s}_id`]===h)||null}}const l=t.find(B=>B.type===I&&B[c]===r[c]);return l&&t.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&&e.indexes.byCustomField){const c=g[0],I=e.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&&e.indexes.bySubcircuit){const c=r.subcircuit_id;return(e.indexes.bySubcircuit.get(c)||[]).find(l=>l.type===s&&g.every(B=>l[B]===r[B]))||null}return a.byType&&e.indexes.byType?(e.indexes.byType.get(s)||[]).find(I=>g.every(l=>I[l]===r[l]))||null:t.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&&e.indexes.byType)return e.indexes.byType.get(s)||[];if(g.length===1&&g[0]==="subcircuit_id"&&a.bySubcircuit&&e.indexes.bySubcircuit){const I=r.subcircuit_id;return(e.indexes.bySubcircuit.get(I)||[]).filter(B=>B.type===s)}let c;return a.byType&&e.indexes.byType?c=e.indexes.byType.get(s)||[]:c=t.filter(I=>I.type===s),g.length>0?c.filter(I=>g.every(l=>I[l]===r[l])):c},insert:r=>{e.counts[s]??=-1,e.counts[s]++;const a=e.counts[s],g={type:s,[`${s}_id`]:`${s}_${a}`,...r};A.validateInserts&&(jyA[s]??rV).parse(g),t.push(g),e.editCount++;const c=A.indexConfig||{};if(c.byId&&e.indexes.byId){const I=bmA(g);e.indexes.byId.set(I,g)}if(c.byType&&e.indexes.byType){const I=e.indexes.byType.get(s)||[];I.push(g),e.indexes.byType.set(s,I)}if(c.byRelation&&e.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=e.indexes.byRelation.get(l)||new Map,Q=C.get(B)||[];Q.push(g),C.set(B,Q),e.indexes.byRelation.set(l,C)}}if(c.bySubcircuit&&e.indexes.bySubcircuit&&"subcircuit_id"in g){const I=g.subcircuit_id;if(I&&typeof I=="string"){const l=e.indexes.bySubcircuit.get(I)||[];l.push(g),e.indexes.bySubcircuit.set(I,l)}}if(c.byCustomField&&e.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=e.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&&e.indexes.byId?g=e.indexes.byId.get(`${s}:${r}`):a.byType&&e.indexes.byType?g=(e.indexes.byType.get(s)||[]).find(l=>l[`${s}_id`]===r):g=t.find(I=>I[`${s}_id`]===r),!g)return;const c=t.indexOf(g);if(c>=0&&(t.splice(c,1),e.editCount++),a.byId&&e.indexes.byId){const I=bmA(g);e.indexes.byId.delete(I)}if(a.byType&&e.indexes.byType){const l=(e.indexes.byType.get(s)||[]).filter(B=>B[`${s}_id`]!==r);e.indexes.byType.set(s,l)}if(a.byRelation&&e.indexes.byRelation)for(const[I,l]of e.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&&e.indexes.bySubcircuit&&"subcircuit_id"in g){const I=g.subcircuit_id;if(I){const B=(e.indexes.bySubcircuit.get(I)||[]).filter(C=>C!==g);B.length===0?e.indexes.bySubcircuit.delete(I):e.indexes.bySubcircuit.set(I,B)}}if(a.byCustomField&&e.indexes.byCustomField)for(const I of e.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&&e.indexes.byId?c=e.indexes.byId.get(`${s}:${r}`):g.byType&&e.indexes.byType?c=(e.indexes.byType.get(s)||[]).find(l=>l[`${s}_id`]===r):c=t.find(I=>I.type===s&&I[`${s}_id`]===r),!c)return null;if(g.byRelation&&e.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=e.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&&e.indexes.bySubcircuit&&"subcircuit_id"in c&&"subcircuit_id"in a){const I=c.subcircuit_id,l=a.subcircuit_id;if(I!==l){const C=(e.indexes.bySubcircuit.get(I)||[]).filter(Q=>Q!==c);C.length===0?e.indexes.bySubcircuit.delete(I):e.indexes.bySubcircuit.set(I,C)}}if(g.byCustomField&&e.indexes.byCustomField){for(const I of g.byCustomField)if(I in c&&I in a&&c[I]!==a[I]){const l=e.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),e.editCount++,g.byRelation&&e.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=e.indexes.byRelation.get(l)||new Map,Q=C.get(B)||[];Q.includes(c)||(Q.push(c),C.set(B,Q),e.indexes.byRelation.set(l,C))}}if(g.bySubcircuit&&e.indexes.bySubcircuit&&"subcircuit_id"in c&&"subcircuit_id"in a){const I=c.subcircuit_id;if(I&&typeof I=="string"){const l=e.indexes.bySubcircuit.get(I)||[];l.includes(c)||(l.push(c),e.indexes.bySubcircuit.set(I,l))}}if(g.byCustomField&&e.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=e.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 t.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=t.find(l=>l.type==="source_component"&&l.name===a);if(!c)return null;const I=t.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 t.find(l=>l.type==="pcb_port"&&l.source_port_id===I.source_port_id)||null;if(s==="schematic_port")return t.find(l=>l.type==="schematic_port"&&l.source_port_id===I.source_port_id)||null}return null}}}})};Zhe.unparsed=Zhe;var rei=t=>{const A=t.type;return t[`${A}_id`]},Vhe=(t,A)=>({minX:Math.min(t.minX,A.minX),minY:Math.min(t.minY,A.minY),maxX:Math.max(t.maxX,A.maxX),maxY:Math.max(t.maxY,A.maxY)}),RV=(t,A,e)=>{const i=e/2;return{minX:t-i,minY:A-i,maxX:t+i,maxY:A+i}},aei=(t,A,e,i,n)=>{const o=e/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:t+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))}},_mA=t=>{let A=Number.POSITIVE_INFINITY,e=Number.POSITIVE_INFINITY,i=Number.NEGATIVE_INFINITY,n=Number.NEGATIVE_INFINITY;for(const o of t){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),e=Math.min(e,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=RV(o.x,o.y,o.hole_diameter);A=Math.min(A,c.minX),e=Math.min(e,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=RV(o.x,o.y,o.outer_diameter):"hole_diameter"in o&&typeof o.hole_diameter=="number"&&(c=RV(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=aei(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?Vhe(c,I):I}if("hole_diameter"in o&&typeof o.hole_diameter=="number"){const I=RV(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?Vhe(c,I):I}if(c){A=Math.min(A,c.minX),e=Math.min(e,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),e=Math.min(e,r),i=Math.max(i,s),n=Math.max(n,r),a!==void 0&&g!==void 0&&(A=Math.min(A,s-a/2),e=Math.min(e,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),e=Math.min(e,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),e=Math.min(e,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),e=Math.min(e,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),e=Math.min(e,c.y),i=Math.max(i,c.x),n=Math.max(n,c.y)}return{minX:A,minY:e,maxX:i,maxY:n}};function gei(t){let A=0;if(t.length==0)return A;for(var e=0;e<t.length;e++){var i=t.charCodeAt(e);A=(A<<5)-A+i,A=A&A}return Math.abs(A)}var jhe=[["#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"]],cei=t=>{let{x:A,y:e,width:i,height:n}={...t,...t.size,...t.center,...t.position};if(t.x1!==void 0&&t.x2!==void 0&&t.y1!==void 0&&t.y2!==void 0&&(A=(t.x1+t.x2)/2,e=(t.y1+t.y2)/2,i=Math.abs(t.x1-t.x2),n=Math.abs(t.y1-t.y2)),t.points&&Array.isArray(t.points)&&t.points.length>0){const r=t.points.map(B=>B.x),a=t.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,e=(I+l)/2,i=c-g,n=l-I}const o=t.text||t.name||t.source?.text||t.source?.name||"?",s=t;return A===void 0||e===void 0?null:(i===void 0&&"outer_diameter"in t&&(i=t.outer_diameter,n=t.outer_diameter),(i===void 0||n===void 0)&&(i=.1,n=.1),{x:A,y:e,width:i,height:n,title:o,content:s,bg_color:jhe[gei(t.type||o)%jhe.length]?.[4]??"#f00"})},Iei=t=>!!t,lei=t=>{const A=t.filter(g=>g.type.startsWith("pcb_")||g.type.startsWith("schematic_")).concat(t.filter(g=>g.type==="pcb_trace"||g.type==="schematic_trace").flatMap(g=>g.route)).map(g=>cei(g)).filter(Iei);if(A.length===0)return{center:{x:0,y:0},width:0,height:0};let e=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))e=Math.min(e,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-e,r=o-n;return{center:{x:e+s/2,y:n+r/2},width:s,height:r}},Cu={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"},L3=(t,A)=>{if(typeof window>"u")return A;try{const e=localStorage.getItem(t);return e!==null?JSON.parse(e):A}catch{return A}},U3=(t,A)=>{if(!(typeof window>"u"))try{localStorage.setItem(t,JSON.stringify(A))}catch{}},Bei=(t,A)=>{if(typeof window>"u")return A;try{const e=localStorage.getItem(t);return e!==null?JSON.parse(e):A}catch{return A}},Cei=(t,A)=>{if(!(typeof window>"u"))try{localStorage.setItem(t,JSON.stringify(A))}catch{}},Qei="named_only",hei=(t={},A=!1)=>UYA(e=>({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:L3(Cu.IS_SHOWING_COPPER_POURS,!0),is_showing_courtyards:L3(Cu.IS_SHOWING_COURTYARDS,!0),is_showing_pcb_groups:A?!1:L3(Cu.IS_SHOWING_PCB_GROUPS,!0),is_showing_group_anchor_offsets:L3(Cu.IS_SHOWING_GROUP_ANCHOR_OFFSETS,!1),is_showing_solder_mask:L3(Cu.IS_SHOWING_SOLDER_MASK,!1),is_showing_silkscreen:L3(Cu.IS_SHOWING_SILKSCREEN,!0),is_showing_fabrication_notes:L3(Cu.IS_SHOWING_FABRICATION_NOTES,!1),pcb_group_view_mode:A?"all":Bei(Cu.PCB_GROUP_VIEW_MODE,Qei),hovered_error_id:null,...t,selectLayer:i=>e({selected_layer:i}),setEditMode:i=>e({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=>e({is_showing_rats_nest:i}),setIsMovingComponent:i=>e({is_moving_component:i}),setIsDrawingTrace:i=>e({is_drawing_trace:i}),setIsMouseOverContainer:i=>e({is_mouse_over_container:i}),setIsShowingMultipleTracesLength:i=>e({is_showing_multiple_traces_length:i}),setIsShowingAutorouting:i=>e({is_showing_autorouting:i}),setIsShowingDrcErrors:i=>e({is_showing_drc_errors:i}),setIsShowingCopperPours:i=>{U3(Cu.IS_SHOWING_COPPER_POURS,i),e({is_showing_copper_pours:i})},setIsShowingCourtyards:i=>{U3(Cu.IS_SHOWING_COURTYARDS,i),e({is_showing_courtyards:i})},setIsShowingPcbGroups:i=>{A||(U3(Cu.IS_SHOWING_PCB_GROUPS,i),e({is_showing_pcb_groups:i}))},setIsShowingGroupAnchorOffsets:i=>{U3(Cu.IS_SHOWING_GROUP_ANCHOR_OFFSETS,i),e({is_showing_group_anchor_offsets:i})},setIsShowingSolderMask:i=>{U3(Cu.IS_SHOWING_SOLDER_MASK,i),e({is_showing_solder_mask:i})},setIsShowingSilkscreen:i=>{U3(Cu.IS_SHOWING_SILKSCREEN,i),e({is_showing_silkscreen:i})},setIsShowingFabricationNotes:i=>{U3(Cu.IS_SHOWING_FABRICATION_NOTES,i),e({is_showing_fabrication_notes:i})},setPcbGroupViewMode:i=>{A||(Cei(Cu.PCB_GROUP_VIEW_MODE,i),e({pcb_group_view_mode:i}))},setHoveredErrorId:i=>e({hovered_error_id:i})})),gl=t=>{const A=V.useContext(zhe);return ZYA(A,t)},zhe=V.createContext(null),Eei=({children:t,initialState:A,disablePcbGroups:e})=>{const i=V.useMemo(()=>hei(A,e),[e]);return W.jsx(zhe.Provider,{value:i,children:t})},uei=()=>{const t=gl(e=>e.pcb_viewer_id),A=(e,i)=>rc(e,{containerId:t,...i});return A.error=(e,i)=>rc.error(e,{containerId:t,...i}),A.promise=rc.promise,A},dei=()=>{V.useEffect(()=>{sXt()},[]);const t=gl(A=>A.pcb_viewer_id);return W.jsx(oXt,{position:"top-center",containerId:t})};function pei(){var t=V.useRef(!1),A=V.useCallback(function(){return t.current},[]);return V.useEffect(function(){return t.current=!0,function(){t.current=!1}},[]),A}var fei=function(t){t===void 0&&(t={});var A=V.useState(t),e=A[0],i=A[1],n=V.useCallback(function(o){i(function(s){return Object.assign({},s,o instanceof Function?o(s):o)})},[]);return[e,n]},yei=fei,mei=function(){},Xhe=typeof window<"u",wei=mmA(TAi()),Dei=function(){var t=pei(),A=yei({value:void 0,error:void 0,noUserInteraction:!0}),e=A[0],i=A[1],n=V.useCallback(function(o){if(t()){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,wei.default)(r),i({value:r,error:void 0,noUserInteraction:s})}catch(g){i({value:r,error:g,noUserInteraction:s})}}},[]);return[e,n]},xei=Dei,Sei=Xhe?V.useLayoutEffect:V.useEffect,bei=Sei,$he={x:0,y:0,width:0,height:0,top:0,left:0,bottom:0,right:0};function _ei(){var t=V.useState(null),A=t[0],e=t[1],i=V.useState($he),n=i[0],o=i[1],s=V.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 bei(function(){if(A)return s.observe(A),function(){s.disconnect()}},[A]),[e,n]}var VL=Xhe&&typeof window.ResizeObserver<"u"?_ei:function(){return[mei,$he]},A0e=({initialTransform:t,initialTouch1:A,initialTouch2:e,finalTouch1:i,finalTouch2:n})=>{if(!i||!n)return t;const o={x:(A.x+e.x)/2,y:(A.y+e.y)/2},s={x:(i.x+n.x)/2,y:(i.y+n.y)/2},r=Math.hypot(e.x-A.x,e.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 An(on(c,I),on(o.x,o.y),$a(g,g),on(-o.x,-o.y),t)},kei=(t={})=>{const A=V.useRef(null),[e,i]=V.useState(0),n=t.canvasElm??A.current,[o,s]=V.useState(t.initialTransform??ba()),[r,a]=V.useState(0),[g,c]=V.useReducer(d=>d+1,0),I=V.useCallback(d=>{t.onSetTransform&&t.onSetTransform(d),t.transform||s(d)},[t.onSetTransform,s]),l=V.useCallback(d=>{I(d),c()},[I]),B=t.transform??o,C=V.useCallback(()=>{i(Date.now())},[]),Q=V.useRef("none"),h=V.useRef(null),E=V.useRef(null);V.useEffect(()=>{const d=t.canvasElm??A.current;if(d&&!n){a(r+1);return}if(!d){const Z=setTimeout(()=>{a(r+1)},100);return()=>clearTimeout(Z)}let p=t.transform??o,y={x:0,y:0},w={x:0,y:0},D=!1;const x=Z=>({x:Z.pageX-d.getBoundingClientRect().left-window.scrollX,y:Z.pageY-d.getBoundingClientRect().top-window.scrollY});function _(Z){t.enabled!==!1&&(t.shouldDrag&&!t.shouldDrag(Z)||(y=x(Z),!(Date.now()-e<100)&&(D=!0,Z.preventDefault())))}function S(Z){if(!D||t.enabled===!1||t.shouldDrag&&!t.shouldDrag(Z))return;w=x(Z);const X=An(on(w.x-y.x,w.y-y.y),p);I(X),p=X,D=!1}function N(Z){if(x(Z),!D||t.enabled===!1||t.shouldDrag&&!t.shouldDrag(Z))return;w=x(Z);const X=An(on(w.x-y.x,w.y-y.y),p);I(X)}function F(Z){if(t.enabled===!1||t.shouldDrag&&!t.shouldDrag(Z))return;const X=x(Z),eA=An(on(X.x,X.y),$a(1-Z.deltaY/1e3,1-Z.deltaY/1e3),on(-X.x,-X.y),p);I(eA),p=eA,Z.preventDefault()}function L(Z){if(!D||t.shouldDrag&&!t.shouldDrag(Z))return;if(d){const eA=d.getBoundingClientRect();if(Z.clientX>=eA.left+10&&Z.clientX<=eA.right-10&&Z.clientY>=eA.top+10&&Z.clientY<=eA.bottom-10)return}D=!1,w=x(Z);const X=An(on(w.x-y.x,w.y-y.y),p);I(X),p=X}function Y(Z){if(Z.preventDefault(),t.enabled!==!1){if(Z.touches.length===1){Q.current="drag";const X=Z.touches[0];h.current={initialTransform:p,initialTouch:{x:X.clientX,y:X.clientY}}}else if(Z.touches.length===2){Q.current="pinch";const X=Z.touches[0],eA=Z.touches[1];E.current={initialTransform:p,initialTouch1:{x:X.clientX,y:X.clientY},initialTouch2:{x:eA.clientX,y:eA.clientY},finalTouch1:null,finalTouch2:null}}}}function J(Z){if(Z.preventDefault(),t.enabled!==!1){if(Q.current==="drag"&&Z.touches.length===1&&h.current){const X=Z.touches[0],eA={x:X.clientX,y:X.clientY},gA=eA.x-h.current.initialTouch.x,tA=eA.y-h.current.initialTouch.y,iA=An(on(gA,tA),h.current.initialTransform);I(iA)}else if(Q.current==="pinch"&&Z.touches.length===2&&E.current){const X=Z.touches[0],eA=Z.touches[1];E.current.finalTouch1={x:X.clientX,y:X.clientY},E.current.finalTouch2={x:eA.clientX,y:eA.clientY};const gA=A0e(E.current);I(gA)}}}function q(Z){Z.preventDefault();const X=Z.changedTouches[0];if(Q.current==="drag"&&h.current&&X){const eA={x:X.clientX,y:X.clientY},gA=eA.x-h.current.initialTouch.x,tA=eA.y-h.current.initialTouch.y,iA=An(on(gA,tA),h.current.initialTransform);I(iA),p=iA}else if(Q.current==="pinch"&&E.current){const eA=A0e(E.current);I(eA),p=eA}Q.current="none",h.current=null,E.current=null}return d.addEventListener("mousedown",_),d.addEventListener("mouseup",S),window.addEventListener("mousemove",N),d.addEventListener("mouseout",L),d.addEventListener("wheel",F),d.addEventListener("touchstart",Y,{passive:!1}),d.addEventListener("touchmove",J,{passive:!1}),d.addEventListener("touchend",q,{passive:!1}),d.addEventListener("touchcancel",q,{passive:!1}),()=>{d.removeEventListener("mousedown",_),d.removeEventListener("mouseup",S),window.removeEventListener("mousemove",N),d.removeEventListener("mouseout",L),d.removeEventListener("wheel",F),d.removeEventListener("touchstart",Y),d.removeEventListener("touchmove",J),d.removeEventListener("touchend",q),d.removeEventListener("touchcancel",q)}},[n,r,g,e,t.enabled,t.shouldDrag]);const u=V.useCallback(d=>Ce(B,d),[B]);return{ref:A,transform:B,applyTransformToPoint:u,setTransform:l,cancelDrag:C}},vei=kei;function Fei(t){const A=new Map;let e=0;function i(n){for(const[,s]of A)if(s.has(n))return s;const o=new Set;return A.set(`connectivity_net${e++}`,o),o}for(const n of t){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 Mei=class{netMap;idToNetMap;constructor(t){this.netMap=t,this.idToNetMap={};for(const[A,e]of Object.entries(t))for(const i of e)this.idToNetMap[i]=A}addConnections(t){for(const A of t){const e=new Set;for(const n of A){const o=this.idToNetMap[n];o&&e.add(o)}let i;if(e.size===0)i=`connectivity_net${Object.keys(this.netMap).length}`,this.netMap[i]=[];else if(e.size===1)i=e.values().next().value??`connectivity_net${Object.keys(this.netMap).length}`;else{i=e.values().next().value??`connectivity_net${Object.keys(this.netMap).length}`;for(const n of e)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(t){return this.netMap[t]||[]}getNetConnectedToId(t){return this.idToNetMap[t]}areIdsConnected(t,A){if(t===A)return!0;const e=this.getNetConnectedToId(t);if(!e)return!1;const i=this.getNetConnectedToId(A);return i?e===i||i===t||i===t:!1}areAllIdsConnected(t){const A=this.getNetConnectedToId(t[0]);for(const e of t){const i=this.getNetConnectedToId(e);if(i===void 0||i!==A)return!1}return!0}},e0e=t=>{const A=[];for(const i of t)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 e=Fei(A);return new Mei(e)};function Rei({primitivesWithoutInteractionMetadata:t,drawingObjectIdsWithMouseOver:A,primitiveIdsInMousedOverNet:e}){const i=[];for(const n of t){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&&e.includes(n._element.pcb_trace_id)||"pcb_port_id"in n._element&&e.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 Nei(t,A){if(t.length<2)throw new Error("Stroke must have at least two points");const e=t.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(e[0],e[1]),a=e[0].trace_width??A;s(e[0],r,1,a),s(e[0],r,-1,a);for(let I=1;I<e.length-1;I++){const l=e[I-1],B=e[I],C=e[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),p=B.trace_width??A;if(d/2>2*(p/2))s(B,Q,1,p),s(B,h,1,p),s(B,Q,-1,p),s(B,h,-1,p);else{const w=1/d;s(B,{x:E*w,y:u*w},1,p),s(B,{x:E*w,y:u*w},-1,p)}}const g=o(e[e.length-2],e[e.length-1]),c=e[e.length-1].trace_width??A;return s(e[e.length-1],g,1,c),s(e[e.length-1],g,-1,c),[...i,...n]}var Gei=(t,A)=>{const{x:e,y:i,width:n,height:o,layer:s,rect_border_radius:r}=t,a=t.corner_radius??r??0,g=[{_pcb_drawing_object_id:qw("rect"),pcb_drawing_type:"rect",x:e,y:i,w:n,h:o,layer:s||"top",_element:t,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,roundness:a,...t.shape==="rotated_rect"&&t.ccw_rotation!==void 0?{ccw_rotation:t.ccw_rotation}:{}}];if(t.is_covered_with_solder_mask){const c=s==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",l={...{_pcb_drawing_object_id:qw("rect"),pcb_drawing_type:"rect",x:e,y:i,w:n,h:o,layer:c,_element:t,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,roundness:a,...t.shape==="rotated_rect"&&t.ccw_rotation!==void 0?{ccw_rotation:t.ccw_rotation}:{}},..."solder_mask_color"in t&&t.solder_mask_color?{color:t.solder_mask_color}:{}};g.push(l)}return g},Lei=(t,A)=>{const{x:e,y:i,radius:n,layer:o}=t,s=[{_pcb_drawing_object_id:qw("circle"),pcb_drawing_type:"circle",x:e,y:i,r:n,layer:o||"top",_element:t,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port}];if(t.is_covered_with_solder_mask){const r=o==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",a={_pcb_drawing_object_id:qw("circle"),pcb_drawing_type:"circle",x:e,y:i,r:n,layer:r,_element:t,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,..."solder_mask_color"in t&&t.solder_mask_color?{color:t.solder_mask_color}:{}};s.push(a)}return s},Uei=(t,A)=>{const{layer:e,points:i}=t,n=[{_pcb_drawing_object_id:qw("polygon"),pcb_drawing_type:"polygon",points:kmA(i),layer:e||"top",_element:t,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port}];if(t.is_covered_with_solder_mask){const o=e==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",s={_pcb_drawing_object_id:qw("polygon"),pcb_drawing_type:"polygon",points:kmA(i),layer:o,_element:t,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,..."solder_mask_color"in t&&t.solder_mask_color?{color:t.solder_mask_color}:{}};n.push(s)}return n},Hei=(t,A)=>{const{x:e,y:i,width:n,height:o,layer:s}=t,r=[{_pcb_drawing_object_id:qw("pill"),pcb_drawing_type:"pill",x:e,y:i,w:n,h:o,layer:s||"top",_element:t,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port}];if(t.is_covered_with_solder_mask){const a=s==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",g={_pcb_drawing_object_id:qw("pill"),pcb_drawing_type:"pill",x:e,y:i,w:n,h:o,layer:a,_element:t,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,..."solder_mask_color"in t&&t.solder_mask_color?{color:t.solder_mask_color}:{}};r.push(g)}return r},Yei=(t,A)=>{const{x:e,y:i,width:n,height:o,layer:s,ccw_rotation:r}=t,a=[{_pcb_drawing_object_id:qw("pill"),pcb_drawing_type:"pill",x:e,y:i,w:n,h:o,layer:s||"top",_element:t,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,ccw_rotation:r}];if(t.is_covered_with_solder_mask){const g=s==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",c={_pcb_drawing_object_id:qw("pill"),pcb_drawing_type:"pill",x:e,y:i,w:n,h:o,layer:g,_element:t,_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 t&&t.solder_mask_color?{color:t.solder_mask_color}:{}};a.push(c)}return a},TI=0,qw=t=>`${t}_${TI++}`,kmA=t=>(t??[]).map(A=>({x:pt.parse(A.x),y:pt.parse(A.y)})),Jei=(t,A)=>{const e="pcb_component_id"in t?A.find(s=>s.type==="pcb_component"&&s.pcb_component_id===t.pcb_component_id):void 0,i=e&&"source_component_id"in e?A.find(s=>s.type==="source_component"&&s.source_component_id===e.source_component_id):void 0,n="source_port_id"in t?t.source_port_id:"pcb_port_id"in t?rx(A).pcb_port.get(t.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(t.type){case"pcb_smtpad":{const s={_parent_pcb_component:e,_parent_source_component:i,_source_port:o};return t.shape==="rect"||t.shape==="rotated_rect"?Gei(t,s):t.shape==="circle"?Lei(t,s):t.shape==="polygon"?Uei(t,s):t.shape==="pill"?Hei(t,s):t.shape==="rotated_pill"?Yei(t,s):[]}case"pcb_trace":{const s=[];if(t.route_thickness_mode==="interpolated"){const g=t.route.map(l=>({x:l.x,y:l.y,trace_width:l.route_type==="wire"?l.width:.5})),c=Nei(g,.5),I=t.route[0].layer;return s.push({_pcb_drawing_object_id:`polygon_${TI++}`,_element:t,pcb_drawing_type:"polygon",points:c,layer:I}),t.route.forEach(l=>{l.route_type==="via"&&s.push({_pcb_drawing_object_id:`circle_${TI++}`,_element:t,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 t.route)g.route_type==="wire"&&(r!==null&&a!==null&&s.push({_pcb_drawing_object_id:`line_${TI++}`,_element:t,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}=t,c=t.from_layer,I=t.to_layer,l=t.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_${TI++}`,pcb_drawing_type:"circle",x:s,y:r,r:a/2,layer:Q,_element:t,_parent_pcb_component:e,_parent_source_component:i});return C.push({_pcb_drawing_object_id:`circle_${TI++}`,pcb_drawing_type:"circle",x:s,y:r,r:g/2,layer:"drill",_element:t}),C}case"pcb_plated_hole":if(t.shape==="circle"){const{x:s,y:r,hole_diameter:a,outer_diameter:g}=t;return[{_pcb_drawing_object_id:`circle_${TI++}`,pcb_drawing_type:"circle",x:s,y:r,r:g/2,layer:"top",_element:t,_parent_pcb_component:e,_parent_source_component:i,_source_port:o},{_pcb_drawing_object_id:`circle_${TI++}`,pcb_drawing_type:"circle",x:s,y:r,r:a/2,layer:"drill",_element:t}]}else if(t.shape==="oval"){const{x:s,y:r,outer_height:a,outer_width:g,hole_height:c,hole_width:I}=t;return[{_pcb_drawing_object_id:`oval_${TI++}`,pcb_drawing_type:"oval",x:s,y:r,rX:g/2,rY:a/2,layer:"top",_element:t,_parent_pcb_component:e,_parent_source_component:i,_source_port:o},{_pcb_drawing_object_id:`oval_${TI++}`,_element:t,pcb_drawing_type:"oval",x:s,y:r,rX:I/2,rY:c/2,layer:"drill"}]}else if(t.shape==="pill"){const{x:s,y:r,outer_height:a,outer_width:g,hole_height:c,hole_width:I}=t;return[{_pcb_drawing_object_id:`pill_${TI++}`,pcb_drawing_type:"pill",x:s,y:r,w:g,h:a,layer:"top",_element:t,_parent_pcb_component:e,_parent_source_component:i,_source_port:o,ccw_rotation:t.ccw_rotation},{_pcb_drawing_object_id:`pill_${TI++}`,_element:t,pcb_drawing_type:"pill",x:s,y:r,w:I,h:c,layer:"drill",ccw_rotation:t.ccw_rotation}]}else if(t.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}=t,C=pt.parse(l??0),Q=pt.parse(B??0);return[{_pcb_drawing_object_id:`rect_${TI++}`,pcb_drawing_type:"rect",x:s,y:r,w:g,h:c,layer:"top",_element:t,_parent_pcb_component:e,_parent_source_component:i,_source_port:o,roundness:I},{_pcb_drawing_object_id:`rect_${TI++}`,pcb_drawing_type:"rect",x:s,y:r,w:g,h:c,layer:"bottom",_element:t,_parent_pcb_component:e,_parent_source_component:i,_source_port:o,roundness:I,is_hoverable:!1},{_pcb_drawing_object_id:`circle_${TI++}`,_element:t,pcb_drawing_type:"circle",x:s+C,y:r+Q,r:a/2,layer:"drill",is_hoverable:!1}]}else if(t.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}=t;return[{_pcb_drawing_object_id:`rect_${TI++}`,pcb_drawing_type:"rect",x:s,y:r,w:c,h:I,layer:"top",_element:t,_parent_pcb_component:e,_parent_source_component:i,_source_port:o,roundness:l},{_pcb_drawing_object_id:`rect_${TI++}`,pcb_drawing_type:"rect",x:s,y:r,w:c,h:I,layer:"bottom",_element:t,_parent_pcb_component:e,_parent_source_component:i,_source_port:o,roundness:l,is_hoverable:!1},{_pcb_drawing_object_id:`pill_${TI++}`,_element:t,pcb_drawing_type:"pill",x:s,y:r,w:a,h:g,layer:"drill",is_hoverable:!1}]}else if(t.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}=t;return[{_pcb_drawing_object_id:`rect_${TI++}`,pcb_drawing_type:"rect",x:s,y:r,w:I,h:l,layer:"top",_element:t,_parent_pcb_component:e,_parent_source_component:i,_source_port:o,ccw_rotation:B,roundness:C},{_pcb_drawing_object_id:`rect_${TI++}`,pcb_drawing_type:"rect",x:s,y:r,w:I,h:l,layer:"bottom",_element:t,_parent_pcb_component:e,_parent_source_component:i,_source_port:o,ccw_rotation:B,roundness:C,is_hoverable:!1},{_pcb_drawing_object_id:`pill_${TI++}`,_element:t,pcb_drawing_type:"pill",x:s,y:r,w:a,h:g,layer:"drill",ccw_rotation:c,is_hoverable:!1}]}else if(t.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}=t,h=pt.parse(C??0),E=pt.parse(Q??0),u=a,d=[];if(u&&Array.isArray(u)){const w=kmA(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_${TI++}`,pcb_drawing_type:"polygon",points:w,layer:D,_element:t,_parent_pcb_component:e,_parent_source_component:i,_source_port:o})}const p={x:s+h,y:r+E},y=[];return g==="circle"?y.push({_pcb_drawing_object_id:`circle_${TI++}`,pcb_drawing_type:"circle",x:p.x,y:p.y,r:(c??0)/2,layer:"drill",_element:t,_parent_pcb_component:e,_parent_source_component:i}):g==="oval"?y.push({_pcb_drawing_object_id:`oval_${TI++}`,pcb_drawing_type:"oval",x:p.x,y:p.y,rX:(I??0)/2,rY:(l??0)/2,layer:"drill",_element:t,_parent_pcb_component:e,_parent_source_component:i}):(g==="pill"||g==="rotated_pill")&&y.push({_pcb_drawing_object_id:`pill_${TI++}`,pcb_drawing_type:"pill",x:p.x,y:p.y,w:I??0,h:l??0,layer:"drill",_element:t,_parent_pcb_component:e,_parent_source_component:i,ccw_rotation:t.ccw_rotation}),[...d,...y]}else return[]}return[]},yn={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)"}},Pp=(t,A=1)=>{if(Math.abs(t.a)!==Math.abs(t.d))throw new Error("Cannot scale non-uniformly");return A*Math.abs(t.a)},vc={elementOverlay:40,dimensionOverlay:40,editTraceHintOverlay:40,errorOverlay:40,pcbGroupOverlay:35,ratsNestOverlay:30,toolbarOverlay:70,warnings:30,topLayer:20,clickToInteractOverlay:100},NV={red:"red",black:"black",green:"green",board:"rgb(255, 255, 255)",other:"#eee",top:yn.board.copper.f,inner1:yn.board.copper.in1,inner2:yn.board.copper.in2,inner3:yn.board.copper.in3,inner4:yn.board.copper.in4,inner5:yn.board.copper.in5,inner6:yn.board.copper.in6,inner7:yn.board.copper.in7,inner8:yn.board.copper.in8,bottom:yn.board.copper.b,drill:yn.board.anchor,keepout:yn.board.background,tkeepout:yn.board.b_crtyd,tplace:yn.board.b_silks,top_courtyard:yn.board.f_crtyd,bottom_courtyard:yn.board.b_crtyd,top_silkscreen:yn.board.f_silks,bottom_silkscreen:yn.board.b_silks,top_fabrication:yn.board.f_fab,bottom_fabrication:yn.board.b_fab,soldermask_top:yn.board.soldermask.top,soldermask_bottom:yn.board.soldermask.bottom,soldermask_with_copper_top:yn.board.soldermaskWithCopper.top,soldermask_with_copper_bottom:yn.board.soldermaskWithCopper.bottom,bottom_notes:yn.board.user_2,top_notes:yn.board.user_2,...yn.board},Tei=["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"],Pei=class{canvasLayerMap;ctxLayerMap;aperture;transform;foregroundLayer="top";lastPoint;constructor(t){this.canvasLayerMap=t,this.ctxLayerMap=Object.fromEntries(Object.entries(t).map(([A,e])=>[A,e.getContext("2d")])),this.transform=ba(),this.transform.d*=-1,this.transform=An(this.transform,on(0,-500)),this.lastPoint={x:0,y:0},this.equip({})}clear(){for(const t of Object.values(this.ctxLayerMap))t.clearRect(0,0,t.canvas.width,t.canvas.height)}equip(t){this.aperture={fontSize:0,shape:"circle",mode:"add",size:0,color:"red",layer:"top",opacity:this.foregroundLayer===t.color?1:.5,...t}}drawMeshPattern(t,A,e,i,n,o=45){const s=this.getLayerCtx(),[r,a]=Ce(this.transform,[t,A]),[g,c]=Ce(this.transform,[t+e,A+i]),I=Pp(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:t,y:A,w:e,h:i,mesh_fill:n,is_filled:o=!0,has_stroke:s,is_stroke_dashed:r,stroke_width:a,roundness:g}){const[c,I]=Ce(this.transform,[t-e/2,A-i/2]),[l,B]=Ce(this.transform,[t+e/2,A+i/2]);this.applyAperture();const C=this.getLayerCtx(),Q=g?Pp(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(t-e/2,A-i/2,e,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=Pp(this.transform,a)),r){let u=[];const d=Math.abs(this.transform.a);if(d>0){const y=.1*d,w=y*1.3;y>.5&&(u=[y,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(t,A,e,i,n,o,s){const r=this.getLayerCtx();this.applyAperture();const[a,g]=Ce(this.transform,[t-e/2,A-i/2]),[c,I]=Ce(this.transform,[t+e/2,A+i/2]),l=o?Pp(this.transform,o):0;r.save();const[B,C]=Ce(this.transform,[t,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(t-e/2,A-i/2,e,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(t,A,e,i,n){const o=this.getLayerCtx();this.applyAperture(),o.save();const[s,r]=Ce(this.transform,[t,A]);o.translate(s,r);const a=360-n;n&&o.rotate(a*Math.PI/180),o.translate(-s,-r),this.pill(t,A,e,i),o.restore()}circle(t,A,e,i,n=!0){const o=Pp(this.transform,e),[s,r]=Ce(this.transform,[t,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(t-e,A-e,e*2,e*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(t,A,e,i){const n=Pp(this.transform,e),o=Pp(this.transform,i),[s,r]=Ce(this.transform,[t,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(t,A,e,i){const[n,o]=Ce(this.transform,[t-e/2,A+i/2]),s=Pp(this.transform,e),r=Pp(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(t){if(t.length<3)return;this.applyAperture();const A=this.getLayerCtx(),e=t.map(n=>Ce(this.transform,[n.x,n.y]));A.beginPath(),A.moveTo(e[0][0],e[0][1]);for(let n=1;n<e.length;n++)A.lineTo(e[n][0],e[n][1]);A.closePath(),A.fill("evenodd");const i=Pp(this.transform,this.aperture.size);i>0&&(A.lineWidth=i,A.stroke())}debugText(t,A,e){const[i,n]=Ce(this.transform,[A,e]);this.applyAperture();const o=this.getLayerCtx();o.font="10px sans-serif",o.fillText(t,i,n)}getLayerCtx(){const t=this.ctxLayerMap[this.aperture.layer];if(!t)throw new Error(`No context for layer "${this.aperture.layer}"`);return t}orderAndFadeLayers(){const{canvasLayerMap:t,foregroundLayer:A}=this,e=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",...e?[e]:[],...i?[i]:[],...n?[n]:[],...o?[o]:[],...s?[s]:[]]),a=[A,"edge_cuts",...e?[e]:[],...i?[i]:[],...n?[n]:[],...o?[o]:[],...s?[s]:[]],g=A==="drill"?[]:["drill"],c=A==="drill"?["drill"]:[],I=[...Tei.filter(l=>!a.includes(l)),...g,A,...e?[e]:[],...c,"edge_cuts",...i?[i]:[],...n?[n]:[],...o?[o]:[],...s?[s]:[]];I.forEach((l,B)=>{const C=t[l];C&&(C.style.zIndex=`${vc.topLayer-(I.length-B)}`,C.style.opacity=r.has(l)?"1":"0.5")})}applyAperture(){const{transform:t,aperture:A}=this;let{size:e,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=Pp(t,e),r.lineCap="round",i==="add"){r.globalCompositeOperation="source-over";let a=NV[n.toLowerCase()];if(!a)try{a=Ta(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=`${Pp(tm(t),o)}px sans-serif`}moveTo(t,A){this.lastPoint={x:t,y:A}}lineTo(t,A){const[e,i]=Ce(this.transform,[t,A]),{size:n,shape:o,mode:s}=this.aperture,r=Pp(this.transform,n),{lastPoint:a}=this,g=Ce(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(e,i),c.stroke(),c.closePath(),o==="square"&&c.fillRect(e-r/2,i-r/2,r,r),this.lastPoint={x:t,y:A}}polygonWithArcs(t){const A=this.getLayerCtx(),e=i=>{if(i.vertices.length===0)return;const n=i.vertices[0],o=Ce(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=Ce(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),p=E,y=Math.sqrt(Math.max(0,C*C-(l/2)**2)),w=Q+y*d*Math.sign(g),D=h+y*p*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 S=Ce(this.transform,[w,D]),N=Pp(this.transform,C);A.arc(S[0],S[1],N,-x,-_,g>0)}else{const g=Ce(this.transform,[a.x,a.y]);A.lineTo(g[0],g[1])}}A.closePath()};if(A.beginPath(),e(t.outer_ring),t.inner_rings)for(const i of t.inner_rings)e(i);A.fill("evenodd")}};function Kei(t){return t.type==="pcb_copper_pour"}function GV({canvas:t,elements:A,layers:e,realToCanvasMat:i}){const n=A.filter(Kei);if(n.length===0)return;const o=new IC(t);o.realToCanvasMat=i,o.drawElements(n,{layers:e})}var qei={...Id,silkscreen:{top:yn.board.f_fab,bottom:yn.board.b_fab}};function Oei(t){return t.type.includes("pcb_fabrication_note")}function t0e({canvas:t,elements:A,layers:e,realToCanvasMat:i}){const n=new IC(t);n.configure({colorOverrides:qei}),n.realToCanvasMat=i;const o=A.filter(Oei);n.drawElements(o,{layers:e})}function Wei(t){return t.type==="pcb_hole"}function Zei({canvas:t,elements:A,layers:e,realToCanvasMat:i,drawSoldermask:n}){const o=new IC(t);o.realToCanvasMat=i;const s=A.filter(Wei);o.drawElements(s,{layers:e,drawSoldermask:n})}function Vei(t){return t.type==="pcb_board"}function jei({canvas:t,elements:A,layers:e,realToCanvasMat:i,drawSoldermask:n}){const o=new IC(t);o.realToCanvasMat=i;const s=A.filter(Vei);for(const r of s)o.drawElements([r],{layers:e,drawSoldermask:!1,drawBoardMaterial:n??!1,minBoardOutlineStrokePx:2})}function zei(t){return t.type==="pcb_copper_text"}function Xei({canvas:t,elements:A,layers:e,realToCanvasMat:i}){const n=A.filter(zei);if(n.length===0)return;const o=new IC(t);o.realToCanvasMat=i,o.drawElements(n,{layers:e})}function $ei(t){return t.type==="pcb_cutout"}function Ati({canvas:t,elements:A,layers:e,realToCanvasMat:i}){const n=new IC(t);n.realToCanvasMat=i;const o=A.filter($ei);n.drawElements(o,{layers:e})}function eti(t){return t.type==="pcb_keepout"}function tti({canvas:t,elements:A,layers:e,realToCanvasMat:i}){const n=A.filter(eti);if(n.length===0)return;const o=new IC(t);o.realToCanvasMat=i,o.drawElements(n,{layers:[]})}function iti(t){return t.type.startsWith("pcb_note_")}function i0e({canvas:t,elements:A,layers:e,realToCanvasMat:i}){const n=new IC(t);n.realToCanvasMat=i;const o=A.filter(iti);n.drawElements(o,{layers:e})}function nti(t){return t.type==="pcb_panel"}function oti({canvas:t,elements:A,layers:e,realToCanvasMat:i,drawSoldermask:n}){const o=new IC(t);o.realToCanvasMat=i;const s=A.filter(nti);for(const r of s)o.drawElements([r],{layers:e})}var sti={...Id,copper:{...Id.copper,top:Ta(yn.board.pad_front).lighten(.5).toString(),bottom:Ta(yn.board.pad_back).lighten(.5).toString(),inner1:Ta(yn.board.copper.in1).lighten(.5).toString(),inner2:Ta(yn.board.copper.in2).lighten(.5).toString(),inner3:Ta(yn.board.copper.in3).lighten(.5).toString(),inner4:Ta(yn.board.copper.in4).lighten(.5).toString(),inner5:Ta(yn.board.copper.in5).lighten(.5).toString(),inner6:Ta(yn.board.copper.in6).lighten(.5).toString()}};function rti(t){return t.type==="pcb_smtpad"}function ati({canvas:t,elements:A,layers:e,realToCanvasMat:i,primitives:n,drawSoldermask:o}){const s=A.filter(rti).filter(c=>{const I=c.layer;return e.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 IC(t);c.realToCanvasMat=i,c.drawElements(g,{layers:e,drawSoldermask:o})}if(a.length>0){const c=new IC(t);c.configure({colorOverrides:sti}),c.realToCanvasMat=i,c.drawElements(a,{layers:e,drawSoldermask:o})}}var gti={...Id,copper:{...Id.copper,top:Ta(yn.board.pad_front).lighten(.5).toString(),bottom:Ta(yn.board.pad_back).lighten(.5).toString(),inner1:Ta(yn.board.copper.in1).lighten(.5).toString(),inner2:Ta(yn.board.copper.in2).lighten(.5).toString(),inner3:Ta(yn.board.copper.in3).lighten(.5).toString(),inner4:Ta(yn.board.copper.in4).lighten(.5).toString(),inner5:Ta(yn.board.copper.in5).lighten(.5).toString(),inner6:Ta(yn.board.copper.in6).lighten(.5).toString()}};function cti(t){return t.type==="pcb_trace"}var Iti=t=>t.map(A=>A.endsWith("_copper")?A.replace("_copper",""):A),lti=(t,A)=>{const e=t.route.filter(i=>i.route_type==="wire"&&"layer"in i&&A.has(i.layer));return e.length===0?null:{...t,route:e}};function Bti({canvas:t,elements:A,layers:e,realToCanvasMat:i,primitives:n}){const o=new Set(Iti(e)),s=A.filter(cti).map(c=>lti(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 IC(t);c.realToCanvasMat=i,c.drawElements(g,{layers:e})}if(a.length>0){const c=new IC(t);c.configure({colorOverrides:gti}),c.realToCanvasMat=i,c.drawElements(a,{layers:e})}}var Cti={...Id,copper:{...Id.copper,top:Ta(yn.board.pad_front).lighten(.5).toString(),bottom:Ta(yn.board.pad_back).lighten(.5).toString()}};function Qti(t){return t.type==="pcb_plated_hole"}function n0e({canvas:t,elements:A,layers:e,realToCanvasMat:i,primitives:n,drawSoldermask:o}){const s=A.filter(Qti);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 IC(t);c.realToCanvasMat=i,c.drawElements(g,{layers:e,drawSoldermask:o})}if(a.length>0){const c=new IC(t);c.configure({colorOverrides:Cti}),c.realToCanvasMat=i,c.drawElements(a,{layers:e,drawSoldermask:o})}}function o0e(t){const{lines:A,anchorPoint:e,ccwRotation:i}=t;if(!i)return A;const n=i*Math.PI/180,o=Tl(n),s=An(on(e.x,e.y),o,on(-e.x,-e.y));return Ce(s,e),A.map(r=>({...r,x1:Ce(s,{x:r.x1,y:r.y1}).x,y1:Ce(s,{x:r.x1,y:r.y1}).y,x2:Ce(s,{x:r.x2,y:r.y2}).x,y2:Ce(s,{x:r.x2,y:r.y2}).y}))}var hti=.6,s0e=.2,r0e=t=>{const A=t.size*.7,e=A*hti,i=A*s0e,n=A*s0e,o=t.text.split(/\r?\n/),s=t.text.length>0&&A>0,r=s?o.length:0,a=s?o.map(I=>I.length===0?0:I.length*e+(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:e,space_between_chars:i,space_between_lines:n,width:g,height:c}},a0e=t=>{const A=r0e(t);return{width:A.width,height:A.height,lineHeight:A.target_height,lineSpacing:A.space_between_lines,lineCount:A.line_count}},g0e=t=>{const{text_lines:A,line_count:e,line_widths:i,target_height:n,target_width_char:o,space_between_chars:s,space_between_lines:r,width:a}=r0e(t);if(n<=0||e===0)return[];const g=n/12,c=[];for(let I=0;I<e;I++){const l=-I*(n+r),B=i[I],C=(a-B)/2;let Q=t.x+C;for(let h=0;h<A[I].length;h++){const E=A[I][h],u=$4[E]??$4[E.toUpperCase()];if(!u){Q+=o+s;continue}for(const{x1:d,y1:p,x2:y,y2:w}of u)c.push({_pcb_drawing_object_id:qw("line"),pcb_drawing_type:"line",x1:Q+o*d,y1:t.y+l+n*p,x2:Q+o*y,y2:t.y+l+n*w,width:g,layer:t.layer,unit:t.unit,color:t.color});Q+=o+s}}return c};function m1(t){const e=t.color??NV[t.layer];let i=Ta(e);return t._element?.type==="pcb_copper_pour"&&(i=i.alpha(.7)),t.is_mouse_over||t.is_in_highlighted_net?i.lighten(.5).rgb().toString():i.rgb().toString()}var c0e=(t,A)=>{t.equip({size:A.zoomIndependent?A.width/t.transform.a:A.width,shape:A.squareCap?"square":"circle",color:m1(A),layer:A.layer}),t.moveTo(A.x1,A.y1),t.lineTo(A.x2,A.y2)},Eti=(t,A,e)=>{switch(e){case"top_left":return{x:0,y:-A};case"top_center":return{x:-t/2,y:-A};case"top_right":return{x:-t,y:-A};case"center_left":return{x:0,y:-A/2};case"center":return{x:-t/2,y:-A/2};case"center_right":return{x:-t,y:-A/2};case"bottom_left":return{x:0,y:0};case"bottom_center":return{x:-t/2,y:0};case"bottom_right":return{x:-t,y:0};default:return{x:0,y:0}}},I0e=t=>t.layer==="bottom_silkscreen"||t.layer==="bottom"?t.is_mirrored!==!1:t.is_mirrored===!0,uti=(t,A)=>{t.equip({fontSize:A.size,color:m1(A),layer:A.layer});const{width:e,height:i}=a0e(A),n=Eti(e,i,A.align);A.x??=0,A.y??=0;const o={x:A.x,y:A.y};let s=g0e({...A,x:A.x+n.x,y:A.y+n.y});if(I0e(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=o0e(r)}for(const r of s)c0e(t,r)},dti=(t,A)=>{const{width:e,height:i,lineHeight:n}=a0e(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=e+o.left+o.right,r=i+o.top+o.bottom,a=e/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?B0e(t,B):l0e(t,B);let C=g0e({...A,x:c,y:I});if(I0e(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=o0e(Q)}for(const Q of C)t.equip({size:Q.width,shape:"circle",color:"black",layer:A.layer,mode:"subtract"}),t.moveTo(Q.x1,Q.y1),t.lineTo(Q.x2,Q.y2);t.equip({mode:"add"})},l0e=(t,A)=>{t.equip({color:m1(A),layer:A.layer,size:A.stroke_width}),t.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})},B0e=(t,A)=>{t.equip({color:m1(A),layer:A.layer}),t.rotatedRect(A.x,A.y,A.w,A.h,A.ccw_rotation,A.roundness,A.mesh_fill)},pti=(t,A)=>{t.equip({color:m1(A),layer:A.layer}),t.rotatedPill(A.x,A.y,A.w,A.h,A.ccw_rotation)},fti=(t,A)=>{t.equip({color:m1(A),layer:A.layer}),t.circle(A.x,A.y,A.r,A.mesh_fill)},yti=(t,A)=>{t.equip({color:m1(A),layer:A.layer}),t.oval(A.x,A.y,A.rX,A.rY)},mti=(t,A)=>{t.equip({color:m1(A),layer:A.layer}),t.pill(A.x,A.y,A.w,A.h)},wti=(t,A)=>{t.equip({color:m1(A),layer:A.layer}),t.polygon(A.points)},Dti=(t,A)=>{t.equip({color:m1(A),layer:A.layer}),t.polygonWithArcs(A.brep_shape)},xti=(t,A)=>{switch(A.pcb_drawing_type){case"line":return c0e(t,A);case"text":return A.is_knockout?dti(t,A):uti(t,A);case"rect":return A.ccw_rotation?B0e(t,A):l0e(t,A);case"circle":return fti(t,A);case"oval":return yti(t,A);case"pill":return A.ccw_rotation?pti(t,A):mti(t,A);case"polygon":return wti(t,A);case"polygon_with_arcs":return Dti(t,A)}},Sti=(t,A)=>{for(const e of A)xti(t,e)},bti={...Id,copper:{...Id.copper,top:Ta(yn.board.pad_front).lighten(.5).toString(),bottom:Ta(yn.board.pad_back).lighten(.5).toString(),inner1:Ta(yn.board.copper.in1).lighten(.5).toString(),inner2:Ta(yn.board.copper.in2).lighten(.5).toString(),inner3:Ta(yn.board.copper.in3).lighten(.5).toString(),inner4:Ta(yn.board.copper.in4).lighten(.5).toString(),inner5:Ta(yn.board.copper.in5).lighten(.5).toString(),inner6:Ta(yn.board.copper.in6).lighten(.5).toString()},soldermask:{...Id.soldermask,top:Ta(yn.board.soldermask.top).lighten(.35).toString(),bottom:Ta(yn.board.soldermask.bottom).lighten(.35).toString()}};function C0e({canvas:t,elements:A,layers:e,realToCanvasMat:i,drawSoldermaskTop:n,drawSoldermaskBottom:o,primitives:s}){const r=new IC(t);r.realToCanvasMat=i;const a=A.filter(l=>l.type==="pcb_board");if(a.length<=1)r.drawElements(A,{layers:e,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:e,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 IC(t);I.configure({colorOverrides:bti}),I.realToCanvasMat=i,I.drawElements(c,{layers:e,drawSoldermask:!0,drawSoldermaskTop:n,drawSoldermaskBottom:o,drawBoardMaterial:!1})}var _ti={...Id,silkscreen:{top:yn.board.f_silks,bottom:yn.board.b_silks}};function kti(t){return t.type.includes("pcb_silkscreen")}function Q0e({canvas:t,elements:A,layers:e,realToCanvasMat:i}){const n=new IC(t);n.configure({colorOverrides:_ti}),n.realToCanvasMat=i;const o=A.filter(kti);n.drawElements(o,{layers:e})}var vti={...Id,copper:{...Id.copper,top:Ta(yn.board.pad_front).lighten(.5).toString(),bottom:Ta(yn.board.pad_back).lighten(.5).toString()}};function Fti(t){return t.type==="pcb_via"}function h0e({canvas:t,elements:A,layers:e,realToCanvasMat:i,primitives:n,drawSoldermask:o}){const s=A.filter(Fti).filter(c=>e.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 IC(t);c.realToCanvasMat=i,c.drawElements(g,{layers:e,drawSoldermask:o})}if(a.length>0){const c=new IC(t);c.configure({colorOverrides:vti}),c.realToCanvasMat=i,c.drawElements(a,{layers:e,drawSoldermask:o})}}var Mti={...Id,courtyard:{top:yn.board.f_crtyd,bottom:yn.board.b_crtyd}};function Rti(t){return t.type==="pcb_courtyard_circle"||t.type==="pcb_courtyard_rect"||t.type==="pcb_courtyard_outline"}function E0e({canvas:t,elements:A,layers:e,realToCanvasMat:i}){const n=new IC(t);n.configure({colorOverrides:Mti}),n.realToCanvasMat=i;const o=A.filter(Rti);n.drawElements(o,{layers:e})}var Nti=["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"],Gti=({primitives:t,elements:A,transform:e,grid:i,width:n=500,height:o=500})=>{const s=V.useRef({}),r=gl(l=>l.selected_layer),a=gl(l=>l.is_showing_solder_mask),g=gl(l=>l.is_showing_fabrication_notes),c=gl(l=>l.is_showing_courtyards),I=gl(l=>l.is_showing_silkscreen);return V.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 Pei(l);e&&(B.transform=e),B.clear(),B.foregroundLayer=r;const C=t.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(Sti(B,C),e){const Q=s.current.top,h=s.current.bottom,E=s.current.inner1,u=s.current.inner2,d=s.current.inner3,p=s.current.inner4,y=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:p,copperLayer:"inner4_copper"},{canvas:y,copperLayer:"inner5_copper"},{canvas:w,copperLayer:"inner6_copper"}];for(const{canvas:Y,copperLayer:J}of D)Y&&Bti({canvas:Y,elements:A,layers:[J],realToCanvasMat:e,primitives:t});for(const{canvas:Y,copperLayer:J}of D)Y&&Xei({canvas:Y,elements:A,layers:[J],realToCanvasMat:e});Q&&n0e({canvas:Q,elements:A,layers:["top_copper"],realToCanvasMat:e,primitives:t,drawSoldermask:a}),h&&n0e({canvas:h,elements:A,layers:["bottom_copper"],realToCanvasMat:e,primitives:t,drawSoldermask:a}),Q&&GV({canvas:Q,elements:A,layers:["top_copper"],realToCanvasMat:e}),h&&GV({canvas:h,elements:A,layers:["bottom_copper"],realToCanvasMat:e});for(const{canvas:Y,copperLayer:J}of D)Y&&ati({canvas:Y,elements:A,layers:[J],realToCanvasMat:e,primitives:t,drawSoldermask:a});if(Q&&h0e({canvas:Q,elements:A,layers:["top_copper"],realToCanvasMat:e,primitives:t,drawSoldermask:a}),h&&h0e({canvas:h,elements:A,layers:["bottom_copper"],realToCanvasMat:e,primitives:t,drawSoldermask:a}),a){const Y=r==="bottom"?"bottom":"top",J=Y==="top",q=Y==="bottom",Z=s.current.soldermask_top;Z&&Y==="top"&&C0e({canvas:Z,elements:A,layers:["top_soldermask"],realToCanvasMat:e,drawSoldermaskTop:J,drawSoldermaskBottom:q,primitives:t});const X=s.current.soldermask_bottom;X&&Y==="bottom"&&C0e({canvas:X,elements:A,layers:["bottom_soldermask"],realToCanvasMat:e,drawSoldermaskTop:J,drawSoldermaskBottom:q,primitives:t})}Q&&GV({canvas:Q,elements:A,layers:["top_copper"],realToCanvasMat:e}),h&&GV({canvas:h,elements:A,layers:["bottom_copper"],realToCanvasMat:e});const x=s.current.drill;if(x&&Zei({canvas:x,elements:A,layers:["drill"],realToCanvasMat:e}),I){const Y=s.current.top_silkscreen;Y&&Q0e({canvas:Y,elements:A,layers:["top_silkscreen"],realToCanvasMat:e});const J=s.current.bottom_silkscreen;J&&Q0e({canvas:J,elements:A,layers:["bottom_silkscreen"],realToCanvasMat:e})}if(g){const Y=s.current.top_fabrication;Y&&t0e({canvas:Y,elements:A,layers:["top_fabrication_note"],realToCanvasMat:e});const J=s.current.bottom_fabrication;J&&t0e({canvas:J,elements:A,layers:["bottom_fabrication_note"],realToCanvasMat:e})}const _=s.current.bottom_notes;_&&i0e({canvas:_,elements:A,layers:["bottom_user_note"],realToCanvasMat:e});const S=s.current.top_notes;if(S&&i0e({canvas:S,elements:A,layers:["top_user_note"],realToCanvasMat:e}),c){const Y=s.current.top_courtyard;Y&&E0e({canvas:Y,elements:A,layers:["top_courtyard"],realToCanvasMat:e});const J=s.current.bottom_courtyard;J&&E0e({canvas:J,elements:A,layers:["bottom_courtyard"],realToCanvasMat:e})}const N=s.current.board;N&&(oti({canvas:N,elements:A,layers:[],realToCanvasMat:e,drawSoldermask:a}),jei({canvas:N,elements:A,layers:[],realToCanvasMat:e,drawSoldermask:a}));const F=s.current.edge_cuts;F&&Ati({canvas:F,elements:A,layers:["edge_cuts"],realToCanvasMat:e});const L=[{canvas:Q,layer:"top"},{canvas:h,layer:"bottom"}];for(const{canvas:Y,layer:J}of L)Y&&tti({canvas:Y,elements:A,layers:[J],realToCanvasMat:e})}B.orderAndFadeLayers()},[t,A,e,r,a,g,c,I]),W.jsxs("div",{style:{backgroundColor:"black",width:n,height:o,position:"relative"},children:[W.jsx(pV.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:e,stringifyCoord:(l,B,C)=>`${pV.toMMSI(l,C)}, ${pV.toMMSI(B,C)}`}),Nti.filter(l=>!(!a&&l.includes("soldermask")||!I&&l.includes("silkscreen"))).map(l=>l.replace(/-/g,"")).map((l,B)=>W.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))]})},Lti=.6,Uti=1;mmA(PAi(),1),mmA(oei(),1);var LV=["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 u0e(t,A,e,i={}){const n=i.padding??40,o=i.yFlip??!1;let s;if("center"in t){const c=t.width/2,I=t.height/2;s={minX:t.center.x-c,maxX:t.center.x+c,minY:t.center.y-I,maxY:t.center.y+I}}else s=t;const r=s.maxX-s.minX||1,a=s.maxY-s.minY||1,g=Math.min((A-2*n)/r,(e-2*n)/a);return An(on(A/2,e/2),$a(g,o?-g:g),on(-(s.minX+r/2),-(s.minY+a/2)))}function Hti(t){const A=[...t.points||[],...(t.lines||[]).flatMap(e=>e.points),...(t.rects||[]).flatMap(e=>{const i=e.width/2,n=e.height/2;return[{x:e.center.x-i,y:e.center.y-n},{x:e.center.x+i,y:e.center.y-n},{x:e.center.x-i,y:e.center.y+n},{x:e.center.x+i,y:e.center.y+n}]}),...(t.circles||[]).flatMap(e=>[{x:e.center.x-e.radius,y:e.center.y},{x:e.center.x+e.radius,y:e.center.y},{x:e.center.x,y:e.center.y-e.radius},{x:e.center.x,y:e.center.y+e.radius}]),...(t.texts||[]).flatMap(e=>{const i=e.fontSize??12,n=e.text.length*i*Lti,o=i*Uti,s=e.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=e.x+a,I=e.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((e,i)=>({minX:Math.min(e.minX,i.x),maxX:Math.max(e.maxX,i.x),minY:Math.min(e.minY,i.y),maxY:Math.max(e.maxY,i.y)}),{minX:1/0,maxX:-1/0,minY:1/0,maxY:-1/0})}function Yti(t,A,e={}){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(e.transform)s=e.transform;else if(e.viewbox)s=u0e(e.viewbox,n,o,{padding:e.padding,yFlip:e.yFlip});else{const r=Hti(t),a=t.coordinateSystem==="cartesian";s=u0e(r,n,o,{padding:e.padding??40,yFlip:a})}i.clearRect(0,0,n,o),i.save(),t.rects&&t.rects.length>0&&t.rects.forEach(r=>{const a=r.width/2,g=r.height/2,c=Ce(s,{x:r.center.x-a,y:r.center.y-g}),I=Ce(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())}),t.circles&&t.circles.length>0&&t.circles.forEach(r=>{const a=Ce(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())}),t.lines&&t.lines.length>0&&t.lines.forEach((r,a)=>{if(r.points.length===0)return;i.beginPath();const g=Ce(s,r.points[0]);i.moveTo(g.x,g.y);for(let c=1;c<r.points.length;c++){const I=Ce(s,r.points[c]);i.lineTo(I.x,I.y)}if(i.strokeStyle=r.strokeColor||LV[a%LV.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()}),t.points&&t.points.length>0&&t.points.forEach((r,a)=>{const g=Ce(s,r);i.beginPath(),i.arc(g.x,g.y,3,0,2*Math.PI),i.fillStyle=r.color||LV[a%LV.length],i.fill(),r.label&&!e.disableLabels&&(i.fillStyle=r.color||"black",i.font="12px sans-serif",i.fillText(r.label,g.x+5,g.y-5))}),t.texts&&t.texts.length>0&&t.texts.forEach(r=>{const a=Ce(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 Jti=({children:t,transform:A,debugGraphics:e})=>{const i=V.useRef(null),[n,{width:o,height:s}]=VL(),r=gl(a=>a.is_showing_autorouting);return V.useEffect(()=>{r&&i.current&&e&&o&&s&&(i.current.width=o,i.current.height=s,Yti(e,i.current,{transform:A,disableLabels:!0}))},[e,A,o,s,r]),r?W.jsxs("div",{ref:n,style:{position:"relative",width:"100%",height:"100%"},children:[t,W.jsx("canvas",{ref:i,style:{position:"absolute",top:0,left:0,opacity:.5,zIndex:100,width:"100%",height:"100%",pointerEvents:"none"}})]}):t},Tti=({children:t,transform:A=ba(),elements:e=[]})=>{const[i,{width:n,height:o}]=VL(),s=V.useRef(null);return V.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=e.filter(I=>I.type==="pcb_component"),c=e.filter(I=>I.type==="pcb_manual_edit_conflict_warning");a.strokeStyle=yn.board.drc_warning,a.lineWidth=2,c.forEach(I=>{const l=g.find(q=>q.pcb_component_id===I.pcb_component_id);if(!l)return;const{width:B,height:C,center:Q}=l,h=Ce(A,Q),E=B*Math.abs(A.a),u=C*Math.abs(A.d),d=.1*Math.abs(A.a),p=E+d*2,y=u+d*2,w=h.x-p/2,D=h.y-y/2;a.beginPath(),a.rect(w,D,p,y),a.stroke();const x="Manual Edit Conflict",_=4,S=Math.max(8,Math.min(12,10*Math.abs(A.a)));a.font=`${S}px sans-serif`;const F=a.measureText(x).width+_*2,L=S+_*2,Y=w+(p-F)/2,J=D+y+5;a.fillStyle="rgba(0, 0, 0, 0.7)",a.beginPath(),a.roundRect(Y,J,F,L,3),a.fill(),a.fillStyle=yn.board.drc_warning,a.textAlign="center",a.textBaseline="middle",a.fillText(x,Y+F/2,J+L/2)})},[e,A,n,o]),W.jsxs("div",{ref:i,style:{position:"relative",width:"100%",height:"100%"},children:[t,W.jsx("canvas",{ref:s,style:{position:"absolute",top:0,left:0,pointerEvents:"none",zIndex:vc.warnings}})]})},UV=(t,A,e)=>e(t,A),d0e=(t,A,e,i,n)=>{const o=n*Math.PI/180,s=Math.cos(o),r=Math.sin(o),a=t-e,g=A-i,c=a*s-g*r,I=a*r+g*s;return{x:c+e,y:I+i}},jL=t=>{if(t.length===0)return null;let A=t[0].x,e=t[0].x,i=t[0].y,n=t[0].y;for(const o of t)A=UV(A,o.x,Math.min),e=UV(e,o.x,Math.max),i=UV(i,o.y,Math.min),n=UV(n,o.y,Math.max);return{minX:A,maxX:e,minY:i,maxY:n}},Pti=(t,A)=>({minX:Math.min(t.minX,A.minX),maxX:Math.max(t.maxX,A.maxX),minY:Math.min(t.minY,A.minY),maxY:Math.max(t.maxY,A.maxY)}),Kti=(t,A)=>t?Pti(t,A):A,qti=t=>{switch(t.pcb_drawing_type){case"line":{const A=(t.width??0)/2,e=[{x:t.x1,y:t.y1},{x:t.x2,y:t.y2}],i=jL(e);return i?{minX:i.minX-A,maxX:i.maxX+A,minY:i.minY-A,maxY:i.maxY+A}:null}case"rect":{const A=t.w/2,e=t.h/2,i=[{x:t.x-A,y:t.y-e},{x:t.x+A,y:t.y-e},{x:t.x+A,y:t.y+e},{x:t.x-A,y:t.y+e}],n=t.ccw_rotation??0,o=n===0?i:i.map(s=>d0e(s.x,s.y,t.x,t.y,n));return jL(o)}case"circle":return{minX:t.x-t.r,maxX:t.x+t.r,minY:t.y-t.r,maxY:t.y+t.r};case"oval":return{minX:t.x-t.rX,maxX:t.x+t.rX,minY:t.y-t.rY,maxY:t.y+t.rY};case"pill":{const A=t.w/2,e=t.h/2,i=[{x:t.x-A,y:t.y-e},{x:t.x+A,y:t.y-e},{x:t.x+A,y:t.y+e},{x:t.x-A,y:t.y+e}],n=t.ccw_rotation??0,o=n===0?i:i.map(s=>d0e(s.x,s.y,t.x,t.y,n));return jL(o)}case"polygon":return jL(t.points);case"polygon_with_arcs":{const A=t.brep_shape.outer_ring.vertices.map(e=>({x:e.x,y:e.y}));return jL(A)}case"text":{const A=t.size??0,e=t.text?t.text.length*A*.6:0,i=A;if(e===0&&i===0)return{minX:t.x,maxX:t.x,minY:t.y,maxY:t.y};const n=e/2,o=i/2;return{minX:t.x-n,maxX:t.x+n,minY:t.y-o,maxY:t.y+o}}default:return null}};function Oti(t){const{dimensionStart:A,dimensionEnd:e,screenDimensionStart:i,screenDimensionEnd:n,flipX:o,flipY:s}=t,r=e.x-A.x,a=e.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,p=B+90;let y=Math.cos(p*Math.PI/180)*d,w=Math.sin(p*Math.PI/180)*d;const D=c>0&&I<0,x=c>0&&I>0,_=c<0&&I>0;o!==s&&!D&&(y=-y,w=-w),D&&(y+=Math.cos(p*Math.PI/180)*-45,w+=Math.sin(p*Math.PI/180)*-45),x&&(y+=Math.cos(p*Math.PI/180)+-20,w+=Math.sin(p*Math.PI/180)+-10),_&&(y+=Math.cos(p*Math.PI/180)*10,w+=Math.sin(p*Math.PI/180)*10);const S=E+y,N=u+w;return{distance:g,screenDistance:l,x:S,y:N,show:g>.01&&l>30&&h}}function Wti(t){const{dimensionStart:A,dimensionEnd:e,screenDimensionStart:i,screenDimensionEnd:n,flipX:o,flipY:s}=t;return V.useMemo(()=>Oti({dimensionStart:A,dimensionEnd:e,screenDimensionStart:i,screenDimensionEnd:n,flipX:o,flipY:s}),[A,e,i,n,o,s])}var Zti=(t,A,e)=>{const i=e*Math.PI/180,n=Math.cos(i),o=Math.sin(i),s=t.x-A.x,r=t.y-A.y,a=s*n-r*o,g=s*o+r*n;return{x:a+A.x,y:g+A.y}},p0e=(t,A,e,i)=>{const n={top_left:{x:t.x-A,y:t.y-e},top_center:{x:t.x,y:t.y-e},top_right:{x:t.x+A,y:t.y-e},center_left:{x:t.x-A,y:t.y},center:{x:t.x,y:t.y},center_right:{x:t.x+A,y:t.y},bottom_left:{x:t.x-A,y:t.y+e},bottom_center:{x:t.x,y:t.y+e},bottom_right:{x:t.x+A,y:t.y+e}};return i===0?Object.entries(n).map(([o,s])=>({anchor:o,point:s})):Object.entries(n).map(([o,s])=>({anchor:o,point:Zti(s,t,i)}))},Vti=t=>{switch(t.pcb_drawing_type){case"rect":{const A=t.ccw_rotation??0;return p0e({x:t.x,y:t.y},t.w/2,t.h/2,A)}case"pill":{const A=t.ccw_rotation??0;return p0e({x:t.x,y:t.y},t.w/2,t.h/2,A)}case"circle":return[{anchor:"circle_center",point:{x:t.x,y:t.y}},{anchor:"circle_right",point:{x:t.x+t.r,y:t.y}},{anchor:"circle_left",point:{x:t.x-t.r,y:t.y}},{anchor:"circle_top",point:{x:t.x,y:t.y-t.r}},{anchor:"circle_bottom",point:{x:t.x,y:t.y+t.r}}];case"oval":return[{anchor:"oval_center",point:{x:t.x,y:t.y}},{anchor:"oval_right",point:{x:t.x+t.rX,y:t.y}},{anchor:"oval_left",point:{x:t.x-t.rX,y:t.y}},{anchor:"oval_top",point:{x:t.x,y:t.y-t.rY}},{anchor:"oval_bottom",point:{x:t.x,y:t.y+t.rY}}];case"line":{const A={x:(t.x1+t.x2)/2,y:(t.y1+t.y2)/2};return[{anchor:"line_start",point:{x:t.x1,y:t.y1}},{anchor:"line_mid",point:A},{anchor:"line_end",point:{x:t.x2,y:t.y2}}]}case"polygon":return t.points.map((A,e)=>({anchor:`polygon_vertex_${e}`,point:A}));case"polygon_with_arcs":return t.brep_shape.outer_ring.vertices.map((A,e)=>({anchor:`polygon_with_arcs_vertex_${e}`,point:{x:A.x,y:A.y}}));default:return[]}},jti=16,H3=5,f0e=t=>{if(t.pcb_drawing_type==="text")return!0;const A=t._element;if(!A||typeof A!="object")return!1;const e=typeof A.type=="string"?A.type:void 0;return e?!!(e.startsWith("pcb_silkscreen_")||e.startsWith("pcb_note_")||e==="pcb_text"||e.startsWith("pcb_fabrication_note_")&&e!=="pcb_fabrication_note_rect"):!1},zti=({children:t,transform:A,focusOnHover:e=!1,primitives:i=[]})=>{A||(A=ba());const[n,o]=V.useState(!1),[s,r]=V.useState(!1),[a,g]=V.useState(!1),[c,I]=V.useState({start:null,end:null}),l=gl(J=>J.is_mouse_over_container),B=V.useCallback(()=>{a&&(g(!1),window.dispatchEvent(new Event("disarm-dimension-tool")))},[a]),[C,Q]=V.useState({x:0,y:0}),[h,E]=V.useState({x:0,y:0}),u=V.useRef({x:0,y:0}),d=V.useRef(null),y=d.current?.getBoundingClientRect(),w=V.useMemo(()=>{const J=new Map;for(const q of i){if(!q._element||f0e(q)||q.pcb_drawing_type==="pill"||q.pcb_drawing_type==="rect"&&q.ccw_rotation&&q.ccw_rotation!==0)continue;const Z=qti(q);if(!Z)continue;const X=J.get(q._element);J.set(q._element,Kti(X??void 0,Z))}return J},[i]),D=V.useMemo(()=>{const J=[];for(const q of i){if(!q._element||f0e(q))continue;const Z=Vti(q);if(Z.length!==0)for(const X of Z)J.push({anchor:X.anchor,point:X.point,element:q._element})}return J},[i]),x=V.useMemo(()=>{const J=[];w.forEach((q,Z)=>{if(!q)return;const X=(q.minX+q.maxX)/2,eA=(q.minY+q.maxY)/2,gA={top_left:{x:q.minX,y:q.minY},top_center:{x:X,y:q.minY},top_right:{x:q.maxX,y:q.minY},center_left:{x:q.minX,y:eA},center:{x:X,y:eA},center_right:{x:q.maxX,y:eA},bottom_left:{x:q.minX,y:q.maxY},bottom_center:{x:X,y:q.maxY},bottom_right:{x:q.maxX,y:q.maxY}};for(const[tA,iA]of Object.entries(gA))J.push({anchor:tA,point:iA,element:Z})});for(const q of D)J.push(q);return J.push({anchor:"origin",point:{x:0,y:0},element:null}),J},[w,D]),_=V.useMemo(()=>x.map((J,q)=>({...J,id:`${q}-${J.anchor}`,screenPoint:Ce(A,J.point)})),[x,A]),S=V.useCallback(J=>{if(_.length===0)return{point:J,id:null};const q=Ce(A,J);let Z=null;for(const X of _){const eA=X.screenPoint.x-q.x,gA=X.screenPoint.y-q.y,tA=Math.hypot(eA,gA);tA>jti||(!Z||tA<Z.distance)&&(Z={distance:tA,id:X.id,point:X.point})}return Z?{point:Z.point,id:Z.id}:{point:J,id:null}},[_,A]);V.useEffect(()=>{const J=Z=>{const X=Z.target;if(X.tagName==="INPUT"||X.tagName==="TEXTAREA"||X.isContentEditable)return;const eA=d.current?.contains(document.activeElement)||document.activeElement===d.current;if(!(!l&&!eA)){if(Z.key==="d"){const gA=S({x:u.current.x,y:u.current.y});Q({x:gA.point.x,y:gA.point.y}),E({x:gA.point.x,y:gA.point.y}),I({start:gA.id,end:gA.id}),n?(o(!1),r(!1),I({start:null,end:null})):(o(!0),r(!0)),B()}Z.key==="Escape"&&(o(!1),r(!1),I({start:null,end:null}),B())}},q=()=>{g(!0)};return window.addEventListener("keydown",J),window.addEventListener("arm-dimension-tool",q),()=>{window.removeEventListener("keydown",J),window.removeEventListener("arm-dimension-tool",q),B()}},[l,n,B,S]);const N=Ce(A,C),F=Ce(A,h),L={left:Math.min(N.x,F.x),right:Math.max(N.x,F.x),top:Math.min(N.y,F.y),bottom:Math.max(N.y,F.y),flipX:N.x>F.x,flipY:N.y>F.y,width:0,height:0};L.width=L.right-L.left,L.height=L.bottom-L.top;const Y=Wti({dimensionStart:C,dimensionEnd:h,screenDimensionStart:N,screenDimensionEnd:F,flipX:L.flipX,flipY:L.flipY});return W.jsxs("div",{ref:d,"data-pcb-viewer":!0,tabIndex:0,style:{position:"relative",outline:"none"},onMouseEnter:()=>{e&&d.current&&d.current.focus()},onMouseLeave:()=>{d.current&&d.current.blur()},onClick:()=>{d.current&&d.current.focus()},onMouseMove:J=>{const q=J.currentTarget.getBoundingClientRect(),Z=J.clientX-q.left,X=J.clientY-q.top,eA=Ce(tm(A),{x:Z,y:X});if(u.current.x=eA.x,u.current.y=eA.y,s){const gA=S(eA);E({x:gA.point.x,y:gA.point.y}),I(tA=>({...tA,end:gA.id}))}},onMouseDown:J=>{const q=J.currentTarget.getBoundingClientRect(),Z=J.clientX-q.left,X=J.clientY-q.top,eA=Ce(tm(A),{x:Z,y:X});if(a&&!n){const gA=S(eA);Q({x:gA.point.x,y:gA.point.y}),E({x:gA.point.x,y:gA.point.y}),I({start:gA.id,end:gA.id}),o(!0),r(!0),B()}else s?(r(!1),I(gA=>({...gA,end:null}))):n&&(o(!1),I({start:null,end:null}))},children:[t,n&&W.jsxs(W.Fragment,{children:[Y.show&&W.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:vc.dimensionOverlay},children:Y.distance.toFixed(2)}),W.jsx("div",{style:{position:"absolute",left:L.left,width:L.width,textAlign:"center",top:N.y+2,color:"red",mixBlendMode:"difference",pointerEvents:"none",marginTop:L.flipY?0:-20,fontSize:12,fontFamily:"sans-serif",zIndex:vc.dimensionOverlay},children:Math.abs(C.x-h.x).toFixed(2)}),W.jsx("div",{style:{position:"absolute",left:F.x,height:L.height,display:"flex",flexDirection:"column",justifyContent:"center",top:L.top,color:"red",pointerEvents:"none",mixBlendMode:"difference",fontSize:12,fontFamily:"sans-serif",zIndex:vc.dimensionOverlay},children:W.jsx("div",{style:{marginLeft:L.flipX?"-100%":4,paddingRight:4},children:Math.abs(C.y-h.y).toFixed(2)})}),W.jsxs("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none",mixBlendMode:"difference",zIndex:vc.dimensionOverlay},width:y.width,height:y.height,children:[W.jsx("defs",{children:W.jsx("marker",{id:"head",orient:"auto",markerWidth:"3",markerHeight:"4",refX:"2",refY:"2",children:W.jsx("path",{d:"M0,0 V4 L2,2 Z",fill:"red"})})}),W.jsx("line",{x1:N.x,y1:N.y,x2:F.x,y2:F.y,markerEnd:"url(#head)",strokeWidth:1.5,fill:"none",stroke:"red"}),W.jsx("line",{x1:N.x,y1:N.y,x2:F.x,y2:N.y,strokeWidth:1.5,fill:"none",strokeDasharray:"2,2",stroke:"red"}),W.jsx("line",{x1:F.x,y1:N.y,x2:F.x,y2:F.y,strokeWidth:1.5,fill:"none",strokeDasharray:"2,2",stroke:"red"})]}),s&&_.map(J=>{const q=J.id===c.start||J.id===c.end,Z=H3/2;return W.jsxs("svg",{width:H3,height:H3,style:{position:"absolute",left:J.screenPoint.x-Z,top:J.screenPoint.y-Z,pointerEvents:"none",zIndex:vc.dimensionOverlay},children:[W.jsx("line",{x1:0,y1:0,x2:H3,y2:H3,stroke:q?"#66ccff":"white",strokeWidth:1}),W.jsx("line",{x1:H3,y1:0,x2:0,y2:H3,stroke:q?"#66ccff":"white",strokeWidth:1})]},J.id)}),W.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),")",W.jsx("br",{}),"(",h.x.toFixed(2),",",h.y.toFixed(2),")",W.jsx("br",{}),"dist:"," ",Math.sqrt((h.x-C.x)**2+(h.y-C.y)**2).toFixed(2)]})]})]})},Xti=(t,A,e=0)=>{const i=t.width/2,n=t.height/2,o=t.center.x-i-e,s=t.center.x+i+e,r=t.center.y-n-e,a=t.center.y+n+e;return A.x>o&&A.x<s&&A.y>r&&A.y<a},$ti=({children:t,disabled:A,transform:e,soup:i,cancelPanDrag:n,onCreateEditEvent:o,onModifyEditEvent:s})=>{e||(e=ba());const r=V.useRef(null),[a,g]=V.useState(null),[c,I]=V.useState(null),l=a!==null;gl(h=>h.in_edit_mode);const B=gl(h=>h.in_move_footprint_mode),C=gl(h=>h.setIsMovingComponent),Q=A||!B;return W.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 p=Ce(tm(e),{x:u,y:d});let y=!1;for(const w of i)if(w.type==="pcb_component"&&Xti(w,p,10/e.a)){n(),g(w.pcb_component_id),y=!0;const D=Math.random().toString();I({dragStart:p,originalCenter:w.center,dragEnd:p,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(y||g(null),y)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 p=Ce(tm(e),{x:u,y:d});I({...c,dragEnd:p}),s({edit_event_id:c.edit_event_id,new_center:{x:c.originalCenter.x+p.x-c.dragStart.x,y:c.originalCenter.y+p.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:[t,!Q&&i.filter(h=>h.type==="pcb_component").map(h=>{if(!h?.center)return null;const E=Ce(e,h.center);return W.jsx("div",{style:{position:"absolute",pointerEvents:"none",left:E.x,top:E.y,width:h.width*e.a+20,height:h.height*e.a+20,transform:"translate(-50%, -50%)",background:l&&a===h.pcb_component_id?"rgba(255, 0, 0, 0.2)":""}},h.pcb_component_id)})]})},Aii=({hotkeys:t})=>(V.useEffect(()=>{const A=e=>{t.forEach(i=>{e.key===i.key&&i.onUse()})};return window.addEventListener("keydown",A),()=>{window.removeEventListener("keydown",A)}},[t]),W.jsx("div",{className:xM`
|
|
5436
|
+
$1`).replace(/>(\s*)(?=<!--\s*\/)/g,"> ")}}});function Whe(t,A,e){if(!A||!e)return;let i=t.get(A);i||(i=new Set,t.set(A,i)),i.add(e);let n=t.get(e);n||(n=new Set,t.set(e,n)),n.add(A)}function sei(t,A){if(!A.subcircuit_id&&!A.source_group_id)return[...t];let e=A;if(A.subcircuit_id){const r=new Set([A.subcircuit_id]),a=new Map,g=new Map;for(const I of t)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),e={...A,subcircuit_ids:Array.from(r)}}}const i=new Map;for(const r of t){const a=`${r.type}_id`,g=r[a];typeof g=="string"&&i.set(g,r)}const n=new Map;for(const r of t){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);Whe(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);Whe(n,r,l)}}}}const o=[],s=new Set;for(const r of t){let a=!1;(e.subcircuit_id&&"subcircuit_id"in r&&r.subcircuit_id===e.subcircuit_id||e.subcircuit_ids&&"subcircuit_id"in r&&r.subcircuit_id&&e.subcircuit_ids.includes(r.subcircuit_id)||e.source_group_id&&"source_group_id"in r&&r.source_group_id===e.source_group_id||e.source_group_id&&"member_source_group_ids"in r&&Array.isArray(r.member_source_group_ids)&&r.member_source_group_ids.includes(e.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 t.filter(r=>s.has(r))}var MV=(t,A={})=>{const e=t;let i=e._internal_store;if(!i){i={counts:{},editCount:0},e._internal_store=i;for(const o of e){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()=>(e.editCount=i.editCount,e);if(s==="editCount")return i.editCount;if(s==="subtree")return a=>MV(sei(e,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&&(jyA[g]??rV).parse(I),e.push(I),i.editCount++,I};if(s==="insertAll")return a=>a.map(g=>n.insert(g));const r=s;return{get:a=>e.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=e.find(B=>B.type===I&&B[c]===a[c]);return l?e.find(B=>B.type===r&&B[`${r}_id`]===l[`${r}_id`]):null},getWhere:a=>{const g=Object.keys(a);return e.find(c=>c.type===r&&g.every(I=>c[I]===a[I]))},list:a=>{const g=a?Object.keys(a):[];return e.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&&(jyA[r]??rV).parse(c),e.push(c),i.editCount++,c},delete:a=>{const g=e.find(c=>c[`${r}_id`]===a);g&&(e.splice(e.indexOf(g),1),i.editCount++)},update:(a,g)=>{const c=e.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 e.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=e.find(B=>B.type==="source_component"&&B.name===g);if(!I)return null;const l=e.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 e.find(B=>B.type==="pcb_port"&&B.source_port_id===l.source_port_id);if(r==="schematic_port")return e.find(B=>B.type==="schematic_port"&&B.source_port_id===l.source_port_id)}}}}});return n};MV.unparsed=MV;var rx=MV;function bmA(t){const A=t.type;return`${A}:${t[`${A}_id`]}`}var Zhe=(t,A={})=>{let e=t._internal_store_indexed;if(!e){e={counts:{},editCount:0,indexes:{}};for(const s of t){const r=s.type,a=s[`${r}_id`];if(!a)continue;const g=Number.parseInt(a.split("_").pop()||"");Number.isNaN(g)||(e.counts[r]=Math.max(e.counts[r]??0,g))}const n=A.indexConfig||{},o=e.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 t){if(n.byId){const r=bmA(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)}}}}t._internal_store_indexed=e}return new Proxy({},{get:(n,o)=>{if(o==="toArray")return()=>(t.editCount=e.editCount,t);if(o==="editCount")return e.editCount;const s=o;return{get:r=>{const a=A.indexConfig||{};return a.byId&&e.indexes.byId?e.indexes.byId.get(`${s}:${r}`)||null:a.byType&&e.indexes.byType?(e.indexes.byType.get(s)||[]).find(c=>c[`${s}_id`]===r)||null:t.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&&e.indexes.byRelation){const B=e.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&&e.indexes.byId?e.indexes.byId.get(`${s}:${h}`)||null:a.byType&&e.indexes.byType?(e.indexes.byType.get(s)||[]).find(u=>u[`${s}_id`]===h)||null:t.find(E=>E.type===s&&E[`${s}_id`]===h)||null}}const l=t.find(B=>B.type===I&&B[c]===r[c]);return l&&t.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&&e.indexes.byCustomField){const c=g[0],I=e.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&&e.indexes.bySubcircuit){const c=r.subcircuit_id;return(e.indexes.bySubcircuit.get(c)||[]).find(l=>l.type===s&&g.every(B=>l[B]===r[B]))||null}return a.byType&&e.indexes.byType?(e.indexes.byType.get(s)||[]).find(I=>g.every(l=>I[l]===r[l]))||null:t.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&&e.indexes.byType)return e.indexes.byType.get(s)||[];if(g.length===1&&g[0]==="subcircuit_id"&&a.bySubcircuit&&e.indexes.bySubcircuit){const I=r.subcircuit_id;return(e.indexes.bySubcircuit.get(I)||[]).filter(B=>B.type===s)}let c;return a.byType&&e.indexes.byType?c=e.indexes.byType.get(s)||[]:c=t.filter(I=>I.type===s),g.length>0?c.filter(I=>g.every(l=>I[l]===r[l])):c},insert:r=>{e.counts[s]??=-1,e.counts[s]++;const a=e.counts[s],g={type:s,[`${s}_id`]:`${s}_${a}`,...r};A.validateInserts&&(jyA[s]??rV).parse(g),t.push(g),e.editCount++;const c=A.indexConfig||{};if(c.byId&&e.indexes.byId){const I=bmA(g);e.indexes.byId.set(I,g)}if(c.byType&&e.indexes.byType){const I=e.indexes.byType.get(s)||[];I.push(g),e.indexes.byType.set(s,I)}if(c.byRelation&&e.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=e.indexes.byRelation.get(l)||new Map,Q=C.get(B)||[];Q.push(g),C.set(B,Q),e.indexes.byRelation.set(l,C)}}if(c.bySubcircuit&&e.indexes.bySubcircuit&&"subcircuit_id"in g){const I=g.subcircuit_id;if(I&&typeof I=="string"){const l=e.indexes.bySubcircuit.get(I)||[];l.push(g),e.indexes.bySubcircuit.set(I,l)}}if(c.byCustomField&&e.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=e.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&&e.indexes.byId?g=e.indexes.byId.get(`${s}:${r}`):a.byType&&e.indexes.byType?g=(e.indexes.byType.get(s)||[]).find(l=>l[`${s}_id`]===r):g=t.find(I=>I[`${s}_id`]===r),!g)return;const c=t.indexOf(g);if(c>=0&&(t.splice(c,1),e.editCount++),a.byId&&e.indexes.byId){const I=bmA(g);e.indexes.byId.delete(I)}if(a.byType&&e.indexes.byType){const l=(e.indexes.byType.get(s)||[]).filter(B=>B[`${s}_id`]!==r);e.indexes.byType.set(s,l)}if(a.byRelation&&e.indexes.byRelation)for(const[I,l]of e.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&&e.indexes.bySubcircuit&&"subcircuit_id"in g){const I=g.subcircuit_id;if(I){const B=(e.indexes.bySubcircuit.get(I)||[]).filter(C=>C!==g);B.length===0?e.indexes.bySubcircuit.delete(I):e.indexes.bySubcircuit.set(I,B)}}if(a.byCustomField&&e.indexes.byCustomField)for(const I of e.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&&e.indexes.byId?c=e.indexes.byId.get(`${s}:${r}`):g.byType&&e.indexes.byType?c=(e.indexes.byType.get(s)||[]).find(l=>l[`${s}_id`]===r):c=t.find(I=>I.type===s&&I[`${s}_id`]===r),!c)return null;if(g.byRelation&&e.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=e.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&&e.indexes.bySubcircuit&&"subcircuit_id"in c&&"subcircuit_id"in a){const I=c.subcircuit_id,l=a.subcircuit_id;if(I!==l){const C=(e.indexes.bySubcircuit.get(I)||[]).filter(Q=>Q!==c);C.length===0?e.indexes.bySubcircuit.delete(I):e.indexes.bySubcircuit.set(I,C)}}if(g.byCustomField&&e.indexes.byCustomField){for(const I of g.byCustomField)if(I in c&&I in a&&c[I]!==a[I]){const l=e.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),e.editCount++,g.byRelation&&e.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=e.indexes.byRelation.get(l)||new Map,Q=C.get(B)||[];Q.includes(c)||(Q.push(c),C.set(B,Q),e.indexes.byRelation.set(l,C))}}if(g.bySubcircuit&&e.indexes.bySubcircuit&&"subcircuit_id"in c&&"subcircuit_id"in a){const I=c.subcircuit_id;if(I&&typeof I=="string"){const l=e.indexes.bySubcircuit.get(I)||[];l.includes(c)||(l.push(c),e.indexes.bySubcircuit.set(I,l))}}if(g.byCustomField&&e.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=e.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 t.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=t.find(l=>l.type==="source_component"&&l.name===a);if(!c)return null;const I=t.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 t.find(l=>l.type==="pcb_port"&&l.source_port_id===I.source_port_id)||null;if(s==="schematic_port")return t.find(l=>l.type==="schematic_port"&&l.source_port_id===I.source_port_id)||null}return null}}}})};Zhe.unparsed=Zhe;var rei=t=>{const A=t.type;return t[`${A}_id`]},Vhe=(t,A)=>({minX:Math.min(t.minX,A.minX),minY:Math.min(t.minY,A.minY),maxX:Math.max(t.maxX,A.maxX),maxY:Math.max(t.maxY,A.maxY)}),RV=(t,A,e)=>{const i=e/2;return{minX:t-i,minY:A-i,maxX:t+i,maxY:A+i}},aei=(t,A,e,i,n)=>{const o=e/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:t+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))}},_mA=t=>{let A=Number.POSITIVE_INFINITY,e=Number.POSITIVE_INFINITY,i=Number.NEGATIVE_INFINITY,n=Number.NEGATIVE_INFINITY;for(const o of t){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),e=Math.min(e,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=RV(o.x,o.y,o.hole_diameter);A=Math.min(A,c.minX),e=Math.min(e,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=RV(o.x,o.y,o.outer_diameter):"hole_diameter"in o&&typeof o.hole_diameter=="number"&&(c=RV(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=aei(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?Vhe(c,I):I}if("hole_diameter"in o&&typeof o.hole_diameter=="number"){const I=RV(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?Vhe(c,I):I}if(c){A=Math.min(A,c.minX),e=Math.min(e,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),e=Math.min(e,r),i=Math.max(i,s),n=Math.max(n,r),a!==void 0&&g!==void 0&&(A=Math.min(A,s-a/2),e=Math.min(e,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),e=Math.min(e,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),e=Math.min(e,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),e=Math.min(e,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),e=Math.min(e,c.y),i=Math.max(i,c.x),n=Math.max(n,c.y)}return{minX:A,minY:e,maxX:i,maxY:n}};function gei(t){let A=0;if(t.length==0)return A;for(var e=0;e<t.length;e++){var i=t.charCodeAt(e);A=(A<<5)-A+i,A=A&A}return Math.abs(A)}var jhe=[["#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"]],cei=t=>{let{x:A,y:e,width:i,height:n}={...t,...t.size,...t.center,...t.position};if(t.x1!==void 0&&t.x2!==void 0&&t.y1!==void 0&&t.y2!==void 0&&(A=(t.x1+t.x2)/2,e=(t.y1+t.y2)/2,i=Math.abs(t.x1-t.x2),n=Math.abs(t.y1-t.y2)),t.points&&Array.isArray(t.points)&&t.points.length>0){const r=t.points.map(B=>B.x),a=t.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,e=(I+l)/2,i=c-g,n=l-I}const o=t.text||t.name||t.source?.text||t.source?.name||"?",s=t;return A===void 0||e===void 0?null:(i===void 0&&"outer_diameter"in t&&(i=t.outer_diameter,n=t.outer_diameter),(i===void 0||n===void 0)&&(i=.1,n=.1),{x:A,y:e,width:i,height:n,title:o,content:s,bg_color:jhe[gei(t.type||o)%jhe.length]?.[4]??"#f00"})},Iei=t=>!!t,lei=t=>{const A=t.filter(g=>g.type.startsWith("pcb_")||g.type.startsWith("schematic_")).concat(t.filter(g=>g.type==="pcb_trace"||g.type==="schematic_trace").flatMap(g=>g.route)).map(g=>cei(g)).filter(Iei);if(A.length===0)return{center:{x:0,y:0},width:0,height:0};let e=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))e=Math.min(e,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-e,r=o-n;return{center:{x:e+s/2,y:n+r/2},width:s,height:r}},Cu={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"},L3=(t,A)=>{if(typeof window>"u")return A;try{const e=localStorage.getItem(t);return e!==null?JSON.parse(e):A}catch{return A}},U3=(t,A)=>{if(!(typeof window>"u"))try{localStorage.setItem(t,JSON.stringify(A))}catch{}},Bei=(t,A)=>{if(typeof window>"u")return A;try{const e=localStorage.getItem(t);return e!==null?JSON.parse(e):A}catch{return A}},Cei=(t,A)=>{if(!(typeof window>"u"))try{localStorage.setItem(t,JSON.stringify(A))}catch{}},Qei="named_only",hei=(t={},A=!1)=>UYA(e=>({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:L3(Cu.IS_SHOWING_COPPER_POURS,!0),is_showing_courtyards:L3(Cu.IS_SHOWING_COURTYARDS,!0),is_showing_pcb_groups:A?!1:L3(Cu.IS_SHOWING_PCB_GROUPS,!0),is_showing_group_anchor_offsets:L3(Cu.IS_SHOWING_GROUP_ANCHOR_OFFSETS,!1),is_showing_solder_mask:L3(Cu.IS_SHOWING_SOLDER_MASK,!1),is_showing_silkscreen:L3(Cu.IS_SHOWING_SILKSCREEN,!0),is_showing_fabrication_notes:L3(Cu.IS_SHOWING_FABRICATION_NOTES,!1),pcb_group_view_mode:A?"all":Bei(Cu.PCB_GROUP_VIEW_MODE,Qei),hovered_error_id:null,...t,selectLayer:i=>e({selected_layer:i}),setEditMode:i=>e({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=>e({is_showing_rats_nest:i}),setIsMovingComponent:i=>e({is_moving_component:i}),setIsDrawingTrace:i=>e({is_drawing_trace:i}),setIsMouseOverContainer:i=>e({is_mouse_over_container:i}),setIsShowingMultipleTracesLength:i=>e({is_showing_multiple_traces_length:i}),setIsShowingAutorouting:i=>e({is_showing_autorouting:i}),setIsShowingDrcErrors:i=>e({is_showing_drc_errors:i}),setIsShowingCopperPours:i=>{U3(Cu.IS_SHOWING_COPPER_POURS,i),e({is_showing_copper_pours:i})},setIsShowingCourtyards:i=>{U3(Cu.IS_SHOWING_COURTYARDS,i),e({is_showing_courtyards:i})},setIsShowingPcbGroups:i=>{A||(U3(Cu.IS_SHOWING_PCB_GROUPS,i),e({is_showing_pcb_groups:i}))},setIsShowingGroupAnchorOffsets:i=>{U3(Cu.IS_SHOWING_GROUP_ANCHOR_OFFSETS,i),e({is_showing_group_anchor_offsets:i})},setIsShowingSolderMask:i=>{U3(Cu.IS_SHOWING_SOLDER_MASK,i),e({is_showing_solder_mask:i})},setIsShowingSilkscreen:i=>{U3(Cu.IS_SHOWING_SILKSCREEN,i),e({is_showing_silkscreen:i})},setIsShowingFabricationNotes:i=>{U3(Cu.IS_SHOWING_FABRICATION_NOTES,i),e({is_showing_fabrication_notes:i})},setPcbGroupViewMode:i=>{A||(Cei(Cu.PCB_GROUP_VIEW_MODE,i),e({pcb_group_view_mode:i}))},setHoveredErrorId:i=>e({hovered_error_id:i})})),gl=t=>{const A=V.useContext(zhe);return ZYA(A,t)},zhe=V.createContext(null),Eei=({children:t,initialState:A,disablePcbGroups:e})=>{const i=V.useMemo(()=>hei(A,e),[e]);return W.jsx(zhe.Provider,{value:i,children:t})},uei=()=>{const t=gl(e=>e.pcb_viewer_id),A=(e,i)=>rc(e,{containerId:t,...i});return A.error=(e,i)=>rc.error(e,{containerId:t,...i}),A.promise=rc.promise,A},dei=()=>{V.useEffect(()=>{sXt()},[]);const t=gl(A=>A.pcb_viewer_id);return W.jsx(oXt,{position:"top-center",containerId:t})};function pei(){var t=V.useRef(!1),A=V.useCallback(function(){return t.current},[]);return V.useEffect(function(){return t.current=!0,function(){t.current=!1}},[]),A}var fei=function(t){t===void 0&&(t={});var A=V.useState(t),e=A[0],i=A[1],n=V.useCallback(function(o){i(function(s){return Object.assign({},s,o instanceof Function?o(s):o)})},[]);return[e,n]},yei=fei,mei=function(){},Xhe=typeof window<"u",wei=mmA(TAi()),Dei=function(){var t=pei(),A=yei({value:void 0,error:void 0,noUserInteraction:!0}),e=A[0],i=A[1],n=V.useCallback(function(o){if(t()){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,wei.default)(r),i({value:r,error:void 0,noUserInteraction:s})}catch(g){i({value:r,error:g,noUserInteraction:s})}}},[]);return[e,n]},xei=Dei,Sei=Xhe?V.useLayoutEffect:V.useEffect,bei=Sei,$he={x:0,y:0,width:0,height:0,top:0,left:0,bottom:0,right:0};function _ei(){var t=V.useState(null),A=t[0],e=t[1],i=V.useState($he),n=i[0],o=i[1],s=V.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 bei(function(){if(A)return s.observe(A),function(){s.disconnect()}},[A]),[e,n]}var VL=Xhe&&typeof window.ResizeObserver<"u"?_ei:function(){return[mei,$he]},A0e=({initialTransform:t,initialTouch1:A,initialTouch2:e,finalTouch1:i,finalTouch2:n})=>{if(!i||!n)return t;const o={x:(A.x+e.x)/2,y:(A.y+e.y)/2},s={x:(i.x+n.x)/2,y:(i.y+n.y)/2},r=Math.hypot(e.x-A.x,e.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 An(on(c,I),on(o.x,o.y),$a(g,g),on(-o.x,-o.y),t)},kei=(t={})=>{const A=V.useRef(null),[e,i]=V.useState(0),n=t.canvasElm??A.current,[o,s]=V.useState(t.initialTransform??ba()),[r,a]=V.useState(0),[g,c]=V.useReducer(d=>d+1,0),I=V.useCallback(d=>{t.onSetTransform&&t.onSetTransform(d),t.transform||s(d)},[t.onSetTransform,s]),l=V.useCallback(d=>{I(d),c()},[I]),B=t.transform??o,C=V.useCallback(()=>{i(Date.now())},[]),Q=V.useRef("none"),h=V.useRef(null),E=V.useRef(null);V.useEffect(()=>{const d=t.canvasElm??A.current;if(d&&!n){a(r+1);return}if(!d){const Z=setTimeout(()=>{a(r+1)},100);return()=>clearTimeout(Z)}let p=t.transform??o,y={x:0,y:0},w={x:0,y:0},D=!1;const x=Z=>({x:Z.pageX-d.getBoundingClientRect().left-window.scrollX,y:Z.pageY-d.getBoundingClientRect().top-window.scrollY});function _(Z){t.enabled!==!1&&(t.shouldDrag&&!t.shouldDrag(Z)||(y=x(Z),!(Date.now()-e<100)&&(D=!0,Z.preventDefault())))}function S(Z){if(!D||t.enabled===!1||t.shouldDrag&&!t.shouldDrag(Z))return;w=x(Z);const X=An(on(w.x-y.x,w.y-y.y),p);I(X),p=X,D=!1}function N(Z){if(x(Z),!D||t.enabled===!1||t.shouldDrag&&!t.shouldDrag(Z))return;w=x(Z);const X=An(on(w.x-y.x,w.y-y.y),p);I(X)}function F(Z){if(t.enabled===!1||t.shouldDrag&&!t.shouldDrag(Z))return;const X=x(Z),eA=An(on(X.x,X.y),$a(1-Z.deltaY/1e3,1-Z.deltaY/1e3),on(-X.x,-X.y),p);I(eA),p=eA,Z.preventDefault()}function L(Z){if(!D||t.shouldDrag&&!t.shouldDrag(Z))return;if(d){const eA=d.getBoundingClientRect();if(Z.clientX>=eA.left+10&&Z.clientX<=eA.right-10&&Z.clientY>=eA.top+10&&Z.clientY<=eA.bottom-10)return}D=!1,w=x(Z);const X=An(on(w.x-y.x,w.y-y.y),p);I(X),p=X}function Y(Z){if(Z.preventDefault(),t.enabled!==!1){if(Z.touches.length===1){Q.current="drag";const X=Z.touches[0];h.current={initialTransform:p,initialTouch:{x:X.clientX,y:X.clientY}}}else if(Z.touches.length===2){Q.current="pinch";const X=Z.touches[0],eA=Z.touches[1];E.current={initialTransform:p,initialTouch1:{x:X.clientX,y:X.clientY},initialTouch2:{x:eA.clientX,y:eA.clientY},finalTouch1:null,finalTouch2:null}}}}function J(Z){if(Z.preventDefault(),t.enabled!==!1){if(Q.current==="drag"&&Z.touches.length===1&&h.current){const X=Z.touches[0],eA={x:X.clientX,y:X.clientY},gA=eA.x-h.current.initialTouch.x,tA=eA.y-h.current.initialTouch.y,iA=An(on(gA,tA),h.current.initialTransform);I(iA)}else if(Q.current==="pinch"&&Z.touches.length===2&&E.current){const X=Z.touches[0],eA=Z.touches[1];E.current.finalTouch1={x:X.clientX,y:X.clientY},E.current.finalTouch2={x:eA.clientX,y:eA.clientY};const gA=A0e(E.current);I(gA)}}}function q(Z){Z.preventDefault();const X=Z.changedTouches[0];if(Q.current==="drag"&&h.current&&X){const eA={x:X.clientX,y:X.clientY},gA=eA.x-h.current.initialTouch.x,tA=eA.y-h.current.initialTouch.y,iA=An(on(gA,tA),h.current.initialTransform);I(iA),p=iA}else if(Q.current==="pinch"&&E.current){const eA=A0e(E.current);I(eA),p=eA}Q.current="none",h.current=null,E.current=null}return d.addEventListener("mousedown",_),d.addEventListener("mouseup",S),window.addEventListener("mousemove",N),d.addEventListener("mouseout",L),d.addEventListener("wheel",F),d.addEventListener("touchstart",Y,{passive:!1}),d.addEventListener("touchmove",J,{passive:!1}),d.addEventListener("touchend",q,{passive:!1}),d.addEventListener("touchcancel",q,{passive:!1}),()=>{d.removeEventListener("mousedown",_),d.removeEventListener("mouseup",S),window.removeEventListener("mousemove",N),d.removeEventListener("mouseout",L),d.removeEventListener("wheel",F),d.removeEventListener("touchstart",Y),d.removeEventListener("touchmove",J),d.removeEventListener("touchend",q),d.removeEventListener("touchcancel",q)}},[n,r,g,e,t.enabled,t.shouldDrag]);const u=V.useCallback(d=>Ce(B,d),[B]);return{ref:A,transform:B,applyTransformToPoint:u,setTransform:l,cancelDrag:C}},vei=kei;function Fei(t){const A=new Map;let e=0;function i(n){for(const[,s]of A)if(s.has(n))return s;const o=new Set;return A.set(`connectivity_net${e++}`,o),o}for(const n of t){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 Mei=class{netMap;idToNetMap;constructor(t){this.netMap=t,this.idToNetMap={};for(const[A,e]of Object.entries(t))for(const i of e)this.idToNetMap[i]=A}addConnections(t){for(const A of t){const e=new Set;for(const n of A){const o=this.idToNetMap[n];o&&e.add(o)}let i;if(e.size===0)i=`connectivity_net${Object.keys(this.netMap).length}`,this.netMap[i]=[];else if(e.size===1)i=e.values().next().value??`connectivity_net${Object.keys(this.netMap).length}`;else{i=e.values().next().value??`connectivity_net${Object.keys(this.netMap).length}`;for(const n of e)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(t){return this.netMap[t]||[]}getNetConnectedToId(t){return this.idToNetMap[t]}areIdsConnected(t,A){if(t===A)return!0;const e=this.getNetConnectedToId(t);if(!e)return!1;const i=this.getNetConnectedToId(A);return i?e===i||i===t||i===t:!1}areAllIdsConnected(t){const A=this.getNetConnectedToId(t[0]);for(const e of t){const i=this.getNetConnectedToId(e);if(i===void 0||i!==A)return!1}return!0}},e0e=t=>{const A=[];for(const i of t)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 e=Fei(A);return new Mei(e)};function Rei({primitivesWithoutInteractionMetadata:t,drawingObjectIdsWithMouseOver:A,primitiveIdsInMousedOverNet:e}){const i=[];for(const n of t){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&&e.includes(n._element.pcb_trace_id)||"pcb_port_id"in n._element&&e.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 Nei(t,A){if(t.length<2)throw new Error("Stroke must have at least two points");const e=t.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(e[0],e[1]),a=e[0].trace_width??A;s(e[0],r,1,a),s(e[0],r,-1,a);for(let I=1;I<e.length-1;I++){const l=e[I-1],B=e[I],C=e[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),p=B.trace_width??A;if(d/2>2*(p/2))s(B,Q,1,p),s(B,h,1,p),s(B,Q,-1,p),s(B,h,-1,p);else{const w=1/d;s(B,{x:E*w,y:u*w},1,p),s(B,{x:E*w,y:u*w},-1,p)}}const g=o(e[e.length-2],e[e.length-1]),c=e[e.length-1].trace_width??A;return s(e[e.length-1],g,1,c),s(e[e.length-1],g,-1,c),[...i,...n]}var Gei=(t,A)=>{const{x:e,y:i,width:n,height:o,layer:s,rect_border_radius:r}=t,a=t.corner_radius??r??0,g=[{_pcb_drawing_object_id:qw("rect"),pcb_drawing_type:"rect",x:e,y:i,w:n,h:o,layer:s||"top",_element:t,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,roundness:a,...t.shape==="rotated_rect"&&t.ccw_rotation!==void 0?{ccw_rotation:t.ccw_rotation}:{}}];if(t.is_covered_with_solder_mask){const c=s==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",l={...{_pcb_drawing_object_id:qw("rect"),pcb_drawing_type:"rect",x:e,y:i,w:n,h:o,layer:c,_element:t,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,roundness:a,...t.shape==="rotated_rect"&&t.ccw_rotation!==void 0?{ccw_rotation:t.ccw_rotation}:{}},..."solder_mask_color"in t&&t.solder_mask_color?{color:t.solder_mask_color}:{}};g.push(l)}return g},Lei=(t,A)=>{const{x:e,y:i,radius:n,layer:o}=t,s=[{_pcb_drawing_object_id:qw("circle"),pcb_drawing_type:"circle",x:e,y:i,r:n,layer:o||"top",_element:t,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port}];if(t.is_covered_with_solder_mask){const r=o==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",a={_pcb_drawing_object_id:qw("circle"),pcb_drawing_type:"circle",x:e,y:i,r:n,layer:r,_element:t,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,..."solder_mask_color"in t&&t.solder_mask_color?{color:t.solder_mask_color}:{}};s.push(a)}return s},Uei=(t,A)=>{const{layer:e,points:i}=t,n=[{_pcb_drawing_object_id:qw("polygon"),pcb_drawing_type:"polygon",points:kmA(i),layer:e||"top",_element:t,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port}];if(t.is_covered_with_solder_mask){const o=e==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",s={_pcb_drawing_object_id:qw("polygon"),pcb_drawing_type:"polygon",points:kmA(i),layer:o,_element:t,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,..."solder_mask_color"in t&&t.solder_mask_color?{color:t.solder_mask_color}:{}};n.push(s)}return n},Hei=(t,A)=>{const{x:e,y:i,width:n,height:o,layer:s}=t,r=[{_pcb_drawing_object_id:qw("pill"),pcb_drawing_type:"pill",x:e,y:i,w:n,h:o,layer:s||"top",_element:t,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port}];if(t.is_covered_with_solder_mask){const a=s==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",g={_pcb_drawing_object_id:qw("pill"),pcb_drawing_type:"pill",x:e,y:i,w:n,h:o,layer:a,_element:t,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,..."solder_mask_color"in t&&t.solder_mask_color?{color:t.solder_mask_color}:{}};r.push(g)}return r},Yei=(t,A)=>{const{x:e,y:i,width:n,height:o,layer:s,ccw_rotation:r}=t,a=[{_pcb_drawing_object_id:qw("pill"),pcb_drawing_type:"pill",x:e,y:i,w:n,h:o,layer:s||"top",_element:t,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,ccw_rotation:r}];if(t.is_covered_with_solder_mask){const g=s==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",c={_pcb_drawing_object_id:qw("pill"),pcb_drawing_type:"pill",x:e,y:i,w:n,h:o,layer:g,_element:t,_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 t&&t.solder_mask_color?{color:t.solder_mask_color}:{}};a.push(c)}return a},TI=0,qw=t=>`${t}_${TI++}`,kmA=t=>(t??[]).map(A=>({x:pt.parse(A.x),y:pt.parse(A.y)})),Jei=(t,A)=>{const e="pcb_component_id"in t?A.find(s=>s.type==="pcb_component"&&s.pcb_component_id===t.pcb_component_id):void 0,i=e&&"source_component_id"in e?A.find(s=>s.type==="source_component"&&s.source_component_id===e.source_component_id):void 0,n="source_port_id"in t?t.source_port_id:"pcb_port_id"in t?rx(A).pcb_port.get(t.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(t.type){case"pcb_smtpad":{const s={_parent_pcb_component:e,_parent_source_component:i,_source_port:o};return t.shape==="rect"||t.shape==="rotated_rect"?Gei(t,s):t.shape==="circle"?Lei(t,s):t.shape==="polygon"?Uei(t,s):t.shape==="pill"?Hei(t,s):t.shape==="rotated_pill"?Yei(t,s):[]}case"pcb_trace":{const s=[];if(t.route_thickness_mode==="interpolated"){const g=t.route.map(l=>({x:l.x,y:l.y,trace_width:l.route_type==="wire"?l.width:.5})),c=Nei(g,.5),I=t.route[0].layer;return s.push({_pcb_drawing_object_id:`polygon_${TI++}`,_element:t,pcb_drawing_type:"polygon",points:c,layer:I}),t.route.forEach(l=>{l.route_type==="via"&&s.push({_pcb_drawing_object_id:`circle_${TI++}`,_element:t,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 t.route)g.route_type==="wire"&&(r!==null&&a!==null&&s.push({_pcb_drawing_object_id:`line_${TI++}`,_element:t,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}=t,c=t.from_layer,I=t.to_layer,l=t.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_${TI++}`,pcb_drawing_type:"circle",x:s,y:r,r:a/2,layer:Q,_element:t,_parent_pcb_component:e,_parent_source_component:i});return C.push({_pcb_drawing_object_id:`circle_${TI++}`,pcb_drawing_type:"circle",x:s,y:r,r:g/2,layer:"drill",_element:t}),C}case"pcb_plated_hole":if(t.shape==="circle"){const{x:s,y:r,hole_diameter:a,outer_diameter:g}=t;return[{_pcb_drawing_object_id:`circle_${TI++}`,pcb_drawing_type:"circle",x:s,y:r,r:g/2,layer:"top",_element:t,_parent_pcb_component:e,_parent_source_component:i,_source_port:o},{_pcb_drawing_object_id:`circle_${TI++}`,pcb_drawing_type:"circle",x:s,y:r,r:a/2,layer:"drill",_element:t}]}else if(t.shape==="oval"){const{x:s,y:r,outer_height:a,outer_width:g,hole_height:c,hole_width:I}=t;return[{_pcb_drawing_object_id:`oval_${TI++}`,pcb_drawing_type:"oval",x:s,y:r,rX:g/2,rY:a/2,layer:"top",_element:t,_parent_pcb_component:e,_parent_source_component:i,_source_port:o},{_pcb_drawing_object_id:`oval_${TI++}`,_element:t,pcb_drawing_type:"oval",x:s,y:r,rX:I/2,rY:c/2,layer:"drill"}]}else if(t.shape==="pill"){const{x:s,y:r,outer_height:a,outer_width:g,hole_height:c,hole_width:I}=t;return[{_pcb_drawing_object_id:`pill_${TI++}`,pcb_drawing_type:"pill",x:s,y:r,w:g,h:a,layer:"top",_element:t,_parent_pcb_component:e,_parent_source_component:i,_source_port:o,ccw_rotation:t.ccw_rotation},{_pcb_drawing_object_id:`pill_${TI++}`,_element:t,pcb_drawing_type:"pill",x:s,y:r,w:I,h:c,layer:"drill",ccw_rotation:t.ccw_rotation}]}else if(t.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}=t,C=pt.parse(l??0),Q=pt.parse(B??0);return[{_pcb_drawing_object_id:`rect_${TI++}`,pcb_drawing_type:"rect",x:s,y:r,w:g,h:c,layer:"top",_element:t,_parent_pcb_component:e,_parent_source_component:i,_source_port:o,roundness:I},{_pcb_drawing_object_id:`rect_${TI++}`,pcb_drawing_type:"rect",x:s,y:r,w:g,h:c,layer:"bottom",_element:t,_parent_pcb_component:e,_parent_source_component:i,_source_port:o,roundness:I,is_hoverable:!1},{_pcb_drawing_object_id:`circle_${TI++}`,_element:t,pcb_drawing_type:"circle",x:s+C,y:r+Q,r:a/2,layer:"drill",is_hoverable:!1}]}else if(t.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}=t;return[{_pcb_drawing_object_id:`rect_${TI++}`,pcb_drawing_type:"rect",x:s,y:r,w:c,h:I,layer:"top",_element:t,_parent_pcb_component:e,_parent_source_component:i,_source_port:o,roundness:l},{_pcb_drawing_object_id:`rect_${TI++}`,pcb_drawing_type:"rect",x:s,y:r,w:c,h:I,layer:"bottom",_element:t,_parent_pcb_component:e,_parent_source_component:i,_source_port:o,roundness:l,is_hoverable:!1},{_pcb_drawing_object_id:`pill_${TI++}`,_element:t,pcb_drawing_type:"pill",x:s,y:r,w:a,h:g,layer:"drill",is_hoverable:!1}]}else if(t.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}=t;return[{_pcb_drawing_object_id:`rect_${TI++}`,pcb_drawing_type:"rect",x:s,y:r,w:I,h:l,layer:"top",_element:t,_parent_pcb_component:e,_parent_source_component:i,_source_port:o,ccw_rotation:B,roundness:C},{_pcb_drawing_object_id:`rect_${TI++}`,pcb_drawing_type:"rect",x:s,y:r,w:I,h:l,layer:"bottom",_element:t,_parent_pcb_component:e,_parent_source_component:i,_source_port:o,ccw_rotation:B,roundness:C,is_hoverable:!1},{_pcb_drawing_object_id:`pill_${TI++}`,_element:t,pcb_drawing_type:"pill",x:s,y:r,w:a,h:g,layer:"drill",ccw_rotation:c,is_hoverable:!1}]}else if(t.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}=t,h=pt.parse(C??0),E=pt.parse(Q??0),u=a,d=[];if(u&&Array.isArray(u)){const w=kmA(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_${TI++}`,pcb_drawing_type:"polygon",points:w,layer:D,_element:t,_parent_pcb_component:e,_parent_source_component:i,_source_port:o})}const p={x:s+h,y:r+E},y=[];return g==="circle"?y.push({_pcb_drawing_object_id:`circle_${TI++}`,pcb_drawing_type:"circle",x:p.x,y:p.y,r:(c??0)/2,layer:"drill",_element:t,_parent_pcb_component:e,_parent_source_component:i}):g==="oval"?y.push({_pcb_drawing_object_id:`oval_${TI++}`,pcb_drawing_type:"oval",x:p.x,y:p.y,rX:(I??0)/2,rY:(l??0)/2,layer:"drill",_element:t,_parent_pcb_component:e,_parent_source_component:i}):(g==="pill"||g==="rotated_pill")&&y.push({_pcb_drawing_object_id:`pill_${TI++}`,pcb_drawing_type:"pill",x:p.x,y:p.y,w:I??0,h:l??0,layer:"drill",_element:t,_parent_pcb_component:e,_parent_source_component:i,ccw_rotation:t.ccw_rotation}),[...d,...y]}else return[]}return[]},yn={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)"}},Pp=(t,A=1)=>{if(Math.abs(t.a)!==Math.abs(t.d))throw new Error("Cannot scale non-uniformly");return A*Math.abs(t.a)},vc={elementOverlay:40,dimensionOverlay:40,editTraceHintOverlay:40,errorOverlay:40,pcbGroupOverlay:35,ratsNestOverlay:30,toolbarOverlay:70,warnings:30,topLayer:20,clickToInteractOverlay:100},NV={red:"red",black:"black",green:"green",board:"rgb(255, 255, 255)",other:"#eee",top:yn.board.copper.f,inner1:yn.board.copper.in1,inner2:yn.board.copper.in2,inner3:yn.board.copper.in3,inner4:yn.board.copper.in4,inner5:yn.board.copper.in5,inner6:yn.board.copper.in6,inner7:yn.board.copper.in7,inner8:yn.board.copper.in8,bottom:yn.board.copper.b,drill:yn.board.anchor,keepout:yn.board.background,tkeepout:yn.board.b_crtyd,tplace:yn.board.b_silks,top_courtyard:yn.board.f_crtyd,bottom_courtyard:yn.board.b_crtyd,top_silkscreen:yn.board.f_silks,bottom_silkscreen:yn.board.b_silks,top_fabrication:yn.board.f_fab,bottom_fabrication:yn.board.b_fab,soldermask_top:yn.board.soldermask.top,soldermask_bottom:yn.board.soldermask.bottom,soldermask_with_copper_top:yn.board.soldermaskWithCopper.top,soldermask_with_copper_bottom:yn.board.soldermaskWithCopper.bottom,bottom_notes:yn.board.user_2,top_notes:yn.board.user_2,...yn.board},Tei=["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"],Pei=class{canvasLayerMap;ctxLayerMap;aperture;transform;foregroundLayer="top";lastPoint;constructor(t){this.canvasLayerMap=t,this.ctxLayerMap=Object.fromEntries(Object.entries(t).map(([A,e])=>[A,e.getContext("2d")])),this.transform=ba(),this.transform.d*=-1,this.transform=An(this.transform,on(0,-500)),this.lastPoint={x:0,y:0},this.equip({})}clear(){for(const t of Object.values(this.ctxLayerMap))t.clearRect(0,0,t.canvas.width,t.canvas.height)}equip(t){this.aperture={fontSize:0,shape:"circle",mode:"add",size:0,color:"red",layer:"top",opacity:this.foregroundLayer===t.color?1:.5,...t}}drawMeshPattern(t,A,e,i,n,o=45){const s=this.getLayerCtx(),[r,a]=Ce(this.transform,[t,A]),[g,c]=Ce(this.transform,[t+e,A+i]),I=Pp(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:t,y:A,w:e,h:i,mesh_fill:n,is_filled:o=!0,has_stroke:s,is_stroke_dashed:r,stroke_width:a,roundness:g}){const[c,I]=Ce(this.transform,[t-e/2,A-i/2]),[l,B]=Ce(this.transform,[t+e/2,A+i/2]);this.applyAperture();const C=this.getLayerCtx(),Q=g?Pp(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(t-e/2,A-i/2,e,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=Pp(this.transform,a)),r){let u=[];const d=Math.abs(this.transform.a);if(d>0){const y=.1*d,w=y*1.3;y>.5&&(u=[y,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(t,A,e,i,n,o,s){const r=this.getLayerCtx();this.applyAperture();const[a,g]=Ce(this.transform,[t-e/2,A-i/2]),[c,I]=Ce(this.transform,[t+e/2,A+i/2]),l=o?Pp(this.transform,o):0;r.save();const[B,C]=Ce(this.transform,[t,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(t-e/2,A-i/2,e,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(t,A,e,i,n){const o=this.getLayerCtx();this.applyAperture(),o.save();const[s,r]=Ce(this.transform,[t,A]);o.translate(s,r);const a=360-n;n&&o.rotate(a*Math.PI/180),o.translate(-s,-r),this.pill(t,A,e,i),o.restore()}circle(t,A,e,i,n=!0){const o=Pp(this.transform,e),[s,r]=Ce(this.transform,[t,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(t-e,A-e,e*2,e*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(t,A,e,i){const n=Pp(this.transform,e),o=Pp(this.transform,i),[s,r]=Ce(this.transform,[t,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(t,A,e,i){const[n,o]=Ce(this.transform,[t-e/2,A+i/2]),s=Pp(this.transform,e),r=Pp(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(t){if(t.length<3)return;this.applyAperture();const A=this.getLayerCtx(),e=t.map(n=>Ce(this.transform,[n.x,n.y]));A.beginPath(),A.moveTo(e[0][0],e[0][1]);for(let n=1;n<e.length;n++)A.lineTo(e[n][0],e[n][1]);A.closePath(),A.fill("evenodd");const i=Pp(this.transform,this.aperture.size);i>0&&(A.lineWidth=i,A.stroke())}debugText(t,A,e){const[i,n]=Ce(this.transform,[A,e]);this.applyAperture();const o=this.getLayerCtx();o.font="10px sans-serif",o.fillText(t,i,n)}getLayerCtx(){const t=this.ctxLayerMap[this.aperture.layer];if(!t)throw new Error(`No context for layer "${this.aperture.layer}"`);return t}orderAndFadeLayers(){const{canvasLayerMap:t,foregroundLayer:A}=this,e=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",...e?[e]:[],...i?[i]:[],...n?[n]:[],...o?[o]:[],...s?[s]:[]]),a=[A,"edge_cuts",...e?[e]:[],...i?[i]:[],...n?[n]:[],...o?[o]:[],...s?[s]:[]],g=A==="drill"?[]:["drill"],c=A==="drill"?["drill"]:[],I=[...Tei.filter(l=>!a.includes(l)),...g,A,...e?[e]:[],...c,"edge_cuts",...i?[i]:[],...n?[n]:[],...o?[o]:[],...s?[s]:[]];I.forEach((l,B)=>{const C=t[l];C&&(C.style.zIndex=`${vc.topLayer-(I.length-B)}`,C.style.opacity=r.has(l)?"1":"0.5")})}applyAperture(){const{transform:t,aperture:A}=this;let{size:e,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=Pp(t,e),r.lineCap="round",i==="add"){r.globalCompositeOperation="source-over";let a=NV[n.toLowerCase()];if(!a)try{a=Ta(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=`${Pp(tm(t),o)}px sans-serif`}moveTo(t,A){this.lastPoint={x:t,y:A}}lineTo(t,A){const[e,i]=Ce(this.transform,[t,A]),{size:n,shape:o,mode:s}=this.aperture,r=Pp(this.transform,n),{lastPoint:a}=this,g=Ce(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(e,i),c.stroke(),c.closePath(),o==="square"&&c.fillRect(e-r/2,i-r/2,r,r),this.lastPoint={x:t,y:A}}polygonWithArcs(t){const A=this.getLayerCtx(),e=i=>{if(i.vertices.length===0)return;const n=i.vertices[0],o=Ce(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=Ce(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),p=E,y=Math.sqrt(Math.max(0,C*C-(l/2)**2)),w=Q+y*d*Math.sign(g),D=h+y*p*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 S=Ce(this.transform,[w,D]),N=Pp(this.transform,C);A.arc(S[0],S[1],N,-x,-_,g>0)}else{const g=Ce(this.transform,[a.x,a.y]);A.lineTo(g[0],g[1])}}A.closePath()};if(A.beginPath(),e(t.outer_ring),t.inner_rings)for(const i of t.inner_rings)e(i);A.fill("evenodd")}};function Kei(t){return t.type==="pcb_copper_pour"}function GV({canvas:t,elements:A,layers:e,realToCanvasMat:i}){const n=A.filter(Kei);if(n.length===0)return;const o=new IC(t);o.realToCanvasMat=i,o.drawElements(n,{layers:e})}var qei={...Id,silkscreen:{top:yn.board.f_fab,bottom:yn.board.b_fab}};function Oei(t){return t.type.includes("pcb_fabrication_note")}function t0e({canvas:t,elements:A,layers:e,realToCanvasMat:i}){const n=new IC(t);n.configure({colorOverrides:qei}),n.realToCanvasMat=i;const o=A.filter(Oei);n.drawElements(o,{layers:e})}function Wei(t){return t.type==="pcb_hole"}function Zei({canvas:t,elements:A,layers:e,realToCanvasMat:i,drawSoldermask:n}){const o=new IC(t);o.realToCanvasMat=i;const s=A.filter(Wei);o.drawElements(s,{layers:e,drawSoldermask:n})}function Vei(t){return t.type==="pcb_board"}function jei({canvas:t,elements:A,layers:e,realToCanvasMat:i,drawSoldermask:n}){const o=new IC(t);o.realToCanvasMat=i;const s=A.filter(Vei);for(const r of s)o.drawElements([r],{layers:e,drawSoldermask:!1,drawBoardMaterial:n??!1,minBoardOutlineStrokePx:2})}function zei(t){return t.type==="pcb_copper_text"}function Xei({canvas:t,elements:A,layers:e,realToCanvasMat:i}){const n=A.filter(zei);if(n.length===0)return;const o=new IC(t);o.realToCanvasMat=i,o.drawElements(n,{layers:e})}function $ei(t){return t.type==="pcb_cutout"}function Ati({canvas:t,elements:A,layers:e,realToCanvasMat:i}){const n=new IC(t);n.realToCanvasMat=i;const o=A.filter($ei);n.drawElements(o,{layers:e})}function eti(t){return t.type==="pcb_keepout"}function tti({canvas:t,elements:A,layers:e,realToCanvasMat:i}){const n=A.filter(eti);if(n.length===0)return;const o=new IC(t);o.realToCanvasMat=i,o.drawElements(n,{layers:[]})}function iti(t){return t.type.startsWith("pcb_note_")}function i0e({canvas:t,elements:A,layers:e,realToCanvasMat:i}){const n=new IC(t);n.realToCanvasMat=i;const o=A.filter(iti);n.drawElements(o,{layers:e})}function nti(t){return t.type==="pcb_panel"}function oti({canvas:t,elements:A,layers:e,realToCanvasMat:i,drawSoldermask:n}){const o=new IC(t);o.realToCanvasMat=i;const s=A.filter(nti);for(const r of s)o.drawElements([r],{layers:e})}var sti={...Id,copper:{...Id.copper,top:Ta(yn.board.pad_front).lighten(.5).toString(),bottom:Ta(yn.board.pad_back).lighten(.5).toString(),inner1:Ta(yn.board.copper.in1).lighten(.5).toString(),inner2:Ta(yn.board.copper.in2).lighten(.5).toString(),inner3:Ta(yn.board.copper.in3).lighten(.5).toString(),inner4:Ta(yn.board.copper.in4).lighten(.5).toString(),inner5:Ta(yn.board.copper.in5).lighten(.5).toString(),inner6:Ta(yn.board.copper.in6).lighten(.5).toString()}};function rti(t){return t.type==="pcb_smtpad"}function ati({canvas:t,elements:A,layers:e,realToCanvasMat:i,primitives:n,drawSoldermask:o}){const s=A.filter(rti).filter(c=>{const I=c.layer;return e.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 IC(t);c.realToCanvasMat=i,c.drawElements(g,{layers:e,drawSoldermask:o})}if(a.length>0){const c=new IC(t);c.configure({colorOverrides:sti}),c.realToCanvasMat=i,c.drawElements(a,{layers:e,drawSoldermask:o})}}var gti={...Id,copper:{...Id.copper,top:Ta(yn.board.pad_front).lighten(.5).toString(),bottom:Ta(yn.board.pad_back).lighten(.5).toString(),inner1:Ta(yn.board.copper.in1).lighten(.5).toString(),inner2:Ta(yn.board.copper.in2).lighten(.5).toString(),inner3:Ta(yn.board.copper.in3).lighten(.5).toString(),inner4:Ta(yn.board.copper.in4).lighten(.5).toString(),inner5:Ta(yn.board.copper.in5).lighten(.5).toString(),inner6:Ta(yn.board.copper.in6).lighten(.5).toString()}};function cti(t){return t.type==="pcb_trace"}var Iti=t=>t.map(A=>A.endsWith("_copper")?A.replace("_copper",""):A),lti=(t,A)=>{const e=t.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 e.filter(n=>n.route_type==="wire").length<2?null:{...t,route:e}};function Bti({canvas:t,elements:A,layers:e,realToCanvasMat:i,primitives:n}){const o=new Set(Iti(e)),s=A.filter(cti).map(c=>lti(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 IC(t);c.realToCanvasMat=i,c.drawElements(g,{layers:e})}if(a.length>0){const c=new IC(t);c.configure({colorOverrides:gti}),c.realToCanvasMat=i,c.drawElements(a,{layers:e})}}var Cti={...Id,copper:{...Id.copper,top:Ta(yn.board.pad_front).lighten(.5).toString(),bottom:Ta(yn.board.pad_back).lighten(.5).toString()}};function Qti(t){return t.type==="pcb_plated_hole"}function n0e({canvas:t,elements:A,layers:e,realToCanvasMat:i,primitives:n,drawSoldermask:o}){const s=A.filter(Qti);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 IC(t);c.realToCanvasMat=i,c.drawElements(g,{layers:e,drawSoldermask:o})}if(a.length>0){const c=new IC(t);c.configure({colorOverrides:Cti}),c.realToCanvasMat=i,c.drawElements(a,{layers:e,drawSoldermask:o})}}function o0e(t){const{lines:A,anchorPoint:e,ccwRotation:i}=t;if(!i)return A;const n=i*Math.PI/180,o=Tl(n),s=An(on(e.x,e.y),o,on(-e.x,-e.y));return Ce(s,e),A.map(r=>({...r,x1:Ce(s,{x:r.x1,y:r.y1}).x,y1:Ce(s,{x:r.x1,y:r.y1}).y,x2:Ce(s,{x:r.x2,y:r.y2}).x,y2:Ce(s,{x:r.x2,y:r.y2}).y}))}var hti=.6,s0e=.2,r0e=t=>{const A=t.size*.7,e=A*hti,i=A*s0e,n=A*s0e,o=t.text.split(/\r?\n/),s=t.text.length>0&&A>0,r=s?o.length:0,a=s?o.map(I=>I.length===0?0:I.length*e+(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:e,space_between_chars:i,space_between_lines:n,width:g,height:c}},a0e=t=>{const A=r0e(t);return{width:A.width,height:A.height,lineHeight:A.target_height,lineSpacing:A.space_between_lines,lineCount:A.line_count}},g0e=t=>{const{text_lines:A,line_count:e,line_widths:i,target_height:n,target_width_char:o,space_between_chars:s,space_between_lines:r,width:a}=r0e(t);if(n<=0||e===0)return[];const g=n/12,c=[];for(let I=0;I<e;I++){const l=-I*(n+r),B=i[I],C=(a-B)/2;let Q=t.x+C;for(let h=0;h<A[I].length;h++){const E=A[I][h],u=$4[E]??$4[E.toUpperCase()];if(!u){Q+=o+s;continue}for(const{x1:d,y1:p,x2:y,y2:w}of u)c.push({_pcb_drawing_object_id:qw("line"),pcb_drawing_type:"line",x1:Q+o*d,y1:t.y+l+n*p,x2:Q+o*y,y2:t.y+l+n*w,width:g,layer:t.layer,unit:t.unit,color:t.color});Q+=o+s}}return c};function m1(t){const e=t.color??NV[t.layer];let i=Ta(e);return t._element?.type==="pcb_copper_pour"&&(i=i.alpha(.7)),t.is_mouse_over||t.is_in_highlighted_net?i.lighten(.5).rgb().toString():i.rgb().toString()}var c0e=(t,A)=>{t.equip({size:A.zoomIndependent?A.width/t.transform.a:A.width,shape:A.squareCap?"square":"circle",color:m1(A),layer:A.layer}),t.moveTo(A.x1,A.y1),t.lineTo(A.x2,A.y2)},Eti=(t,A,e)=>{switch(e){case"top_left":return{x:0,y:-A};case"top_center":return{x:-t/2,y:-A};case"top_right":return{x:-t,y:-A};case"center_left":return{x:0,y:-A/2};case"center":return{x:-t/2,y:-A/2};case"center_right":return{x:-t,y:-A/2};case"bottom_left":return{x:0,y:0};case"bottom_center":return{x:-t/2,y:0};case"bottom_right":return{x:-t,y:0};default:return{x:0,y:0}}},I0e=t=>t.layer==="bottom_silkscreen"||t.layer==="bottom"?t.is_mirrored!==!1:t.is_mirrored===!0,uti=(t,A)=>{t.equip({fontSize:A.size,color:m1(A),layer:A.layer});const{width:e,height:i}=a0e(A),n=Eti(e,i,A.align);A.x??=0,A.y??=0;const o={x:A.x,y:A.y};let s=g0e({...A,x:A.x+n.x,y:A.y+n.y});if(I0e(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=o0e(r)}for(const r of s)c0e(t,r)},dti=(t,A)=>{const{width:e,height:i,lineHeight:n}=a0e(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=e+o.left+o.right,r=i+o.top+o.bottom,a=e/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?B0e(t,B):l0e(t,B);let C=g0e({...A,x:c,y:I});if(I0e(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=o0e(Q)}for(const Q of C)t.equip({size:Q.width,shape:"circle",color:"black",layer:A.layer,mode:"subtract"}),t.moveTo(Q.x1,Q.y1),t.lineTo(Q.x2,Q.y2);t.equip({mode:"add"})},l0e=(t,A)=>{t.equip({color:m1(A),layer:A.layer,size:A.stroke_width}),t.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})},B0e=(t,A)=>{t.equip({color:m1(A),layer:A.layer}),t.rotatedRect(A.x,A.y,A.w,A.h,A.ccw_rotation,A.roundness,A.mesh_fill)},pti=(t,A)=>{t.equip({color:m1(A),layer:A.layer}),t.rotatedPill(A.x,A.y,A.w,A.h,A.ccw_rotation)},fti=(t,A)=>{t.equip({color:m1(A),layer:A.layer}),t.circle(A.x,A.y,A.r,A.mesh_fill)},yti=(t,A)=>{t.equip({color:m1(A),layer:A.layer}),t.oval(A.x,A.y,A.rX,A.rY)},mti=(t,A)=>{t.equip({color:m1(A),layer:A.layer}),t.pill(A.x,A.y,A.w,A.h)},wti=(t,A)=>{t.equip({color:m1(A),layer:A.layer}),t.polygon(A.points)},Dti=(t,A)=>{t.equip({color:m1(A),layer:A.layer}),t.polygonWithArcs(A.brep_shape)},xti=(t,A)=>{switch(A.pcb_drawing_type){case"line":return c0e(t,A);case"text":return A.is_knockout?dti(t,A):uti(t,A);case"rect":return A.ccw_rotation?B0e(t,A):l0e(t,A);case"circle":return fti(t,A);case"oval":return yti(t,A);case"pill":return A.ccw_rotation?pti(t,A):mti(t,A);case"polygon":return wti(t,A);case"polygon_with_arcs":return Dti(t,A)}},Sti=(t,A)=>{for(const e of A)xti(t,e)},bti={...Id,copper:{...Id.copper,top:Ta(yn.board.pad_front).lighten(.5).toString(),bottom:Ta(yn.board.pad_back).lighten(.5).toString(),inner1:Ta(yn.board.copper.in1).lighten(.5).toString(),inner2:Ta(yn.board.copper.in2).lighten(.5).toString(),inner3:Ta(yn.board.copper.in3).lighten(.5).toString(),inner4:Ta(yn.board.copper.in4).lighten(.5).toString(),inner5:Ta(yn.board.copper.in5).lighten(.5).toString(),inner6:Ta(yn.board.copper.in6).lighten(.5).toString()},soldermask:{...Id.soldermask,top:Ta(yn.board.soldermask.top).lighten(.35).toString(),bottom:Ta(yn.board.soldermask.bottom).lighten(.35).toString()}};function C0e({canvas:t,elements:A,layers:e,realToCanvasMat:i,drawSoldermaskTop:n,drawSoldermaskBottom:o,primitives:s}){const r=new IC(t);r.realToCanvasMat=i;const a=A.filter(l=>l.type==="pcb_board");if(a.length<=1)r.drawElements(A,{layers:e,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:e,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 IC(t);I.configure({colorOverrides:bti}),I.realToCanvasMat=i,I.drawElements(c,{layers:e,drawSoldermask:!0,drawSoldermaskTop:n,drawSoldermaskBottom:o,drawBoardMaterial:!1})}var _ti={...Id,silkscreen:{top:yn.board.f_silks,bottom:yn.board.b_silks}};function kti(t){return t.type.includes("pcb_silkscreen")}function Q0e({canvas:t,elements:A,layers:e,realToCanvasMat:i}){const n=new IC(t);n.configure({colorOverrides:_ti}),n.realToCanvasMat=i;const o=A.filter(kti);n.drawElements(o,{layers:e})}var vti={...Id,copper:{...Id.copper,top:Ta(yn.board.pad_front).lighten(.5).toString(),bottom:Ta(yn.board.pad_back).lighten(.5).toString()}};function Fti(t){return t.type==="pcb_via"}function h0e({canvas:t,elements:A,layers:e,realToCanvasMat:i,primitives:n,drawSoldermask:o}){const s=A.filter(Fti).filter(c=>e.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 IC(t);c.realToCanvasMat=i,c.drawElements(g,{layers:e,drawSoldermask:o})}if(a.length>0){const c=new IC(t);c.configure({colorOverrides:vti}),c.realToCanvasMat=i,c.drawElements(a,{layers:e,drawSoldermask:o})}}var Mti={...Id,courtyard:{top:yn.board.f_crtyd,bottom:yn.board.b_crtyd}};function Rti(t){return t.type==="pcb_courtyard_circle"||t.type==="pcb_courtyard_rect"||t.type==="pcb_courtyard_outline"}function E0e({canvas:t,elements:A,layers:e,realToCanvasMat:i}){const n=new IC(t);n.configure({colorOverrides:Mti}),n.realToCanvasMat=i;const o=A.filter(Rti);n.drawElements(o,{layers:e})}var Nti=["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"],Gti=({primitives:t,elements:A,transform:e,grid:i,width:n=500,height:o=500})=>{const s=V.useRef({}),r=gl(l=>l.selected_layer),a=gl(l=>l.is_showing_solder_mask),g=gl(l=>l.is_showing_fabrication_notes),c=gl(l=>l.is_showing_courtyards),I=gl(l=>l.is_showing_silkscreen);return V.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 Pei(l);e&&(B.transform=e),B.clear(),B.foregroundLayer=r;const C=t.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(Sti(B,C),e){const Q=s.current.top,h=s.current.bottom,E=s.current.inner1,u=s.current.inner2,d=s.current.inner3,p=s.current.inner4,y=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:p,copperLayer:"inner4_copper"},{canvas:y,copperLayer:"inner5_copper"},{canvas:w,copperLayer:"inner6_copper"}];for(const{canvas:Y,copperLayer:J}of D)Y&&Bti({canvas:Y,elements:A,layers:[J],realToCanvasMat:e,primitives:t});for(const{canvas:Y,copperLayer:J}of D)Y&&Xei({canvas:Y,elements:A,layers:[J],realToCanvasMat:e});Q&&n0e({canvas:Q,elements:A,layers:["top_copper"],realToCanvasMat:e,primitives:t,drawSoldermask:a}),h&&n0e({canvas:h,elements:A,layers:["bottom_copper"],realToCanvasMat:e,primitives:t,drawSoldermask:a}),Q&&GV({canvas:Q,elements:A,layers:["top_copper"],realToCanvasMat:e}),h&&GV({canvas:h,elements:A,layers:["bottom_copper"],realToCanvasMat:e});for(const{canvas:Y,copperLayer:J}of D)Y&&ati({canvas:Y,elements:A,layers:[J],realToCanvasMat:e,primitives:t,drawSoldermask:a});if(Q&&h0e({canvas:Q,elements:A,layers:["top_copper"],realToCanvasMat:e,primitives:t,drawSoldermask:a}),h&&h0e({canvas:h,elements:A,layers:["bottom_copper"],realToCanvasMat:e,primitives:t,drawSoldermask:a}),a){const Y=r==="bottom"?"bottom":"top",J=Y==="top",q=Y==="bottom",Z=s.current.soldermask_top;Z&&Y==="top"&&C0e({canvas:Z,elements:A,layers:["top_soldermask"],realToCanvasMat:e,drawSoldermaskTop:J,drawSoldermaskBottom:q,primitives:t});const X=s.current.soldermask_bottom;X&&Y==="bottom"&&C0e({canvas:X,elements:A,layers:["bottom_soldermask"],realToCanvasMat:e,drawSoldermaskTop:J,drawSoldermaskBottom:q,primitives:t})}Q&&GV({canvas:Q,elements:A,layers:["top_copper"],realToCanvasMat:e}),h&&GV({canvas:h,elements:A,layers:["bottom_copper"],realToCanvasMat:e});const x=s.current.drill;if(x&&Zei({canvas:x,elements:A,layers:["drill"],realToCanvasMat:e}),I){const Y=s.current.top_silkscreen;Y&&Q0e({canvas:Y,elements:A,layers:["top_silkscreen"],realToCanvasMat:e});const J=s.current.bottom_silkscreen;J&&Q0e({canvas:J,elements:A,layers:["bottom_silkscreen"],realToCanvasMat:e})}if(g){const Y=s.current.top_fabrication;Y&&t0e({canvas:Y,elements:A,layers:["top_fabrication_note"],realToCanvasMat:e});const J=s.current.bottom_fabrication;J&&t0e({canvas:J,elements:A,layers:["bottom_fabrication_note"],realToCanvasMat:e})}const _=s.current.bottom_notes;_&&i0e({canvas:_,elements:A,layers:["bottom_user_note"],realToCanvasMat:e});const S=s.current.top_notes;if(S&&i0e({canvas:S,elements:A,layers:["top_user_note"],realToCanvasMat:e}),c){const Y=s.current.top_courtyard;Y&&E0e({canvas:Y,elements:A,layers:["top_courtyard"],realToCanvasMat:e});const J=s.current.bottom_courtyard;J&&E0e({canvas:J,elements:A,layers:["bottom_courtyard"],realToCanvasMat:e})}const N=s.current.board;N&&(oti({canvas:N,elements:A,layers:[],realToCanvasMat:e,drawSoldermask:a}),jei({canvas:N,elements:A,layers:[],realToCanvasMat:e,drawSoldermask:a}));const F=s.current.edge_cuts;F&&Ati({canvas:F,elements:A,layers:["edge_cuts"],realToCanvasMat:e});const L=[{canvas:Q,layer:"top"},{canvas:h,layer:"bottom"}];for(const{canvas:Y,layer:J}of L)Y&&tti({canvas:Y,elements:A,layers:[J],realToCanvasMat:e})}B.orderAndFadeLayers()},[t,A,e,r,a,g,c,I]),W.jsxs("div",{style:{backgroundColor:"black",width:n,height:o,position:"relative"},children:[W.jsx(pV.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:e,stringifyCoord:(l,B,C)=>`${pV.toMMSI(l,C)}, ${pV.toMMSI(B,C)}`}),Nti.filter(l=>!(!a&&l.includes("soldermask")||!I&&l.includes("silkscreen"))).map(l=>l.replace(/-/g,"")).map((l,B)=>W.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))]})},Lti=.6,Uti=1;mmA(PAi(),1),mmA(oei(),1);var LV=["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 u0e(t,A,e,i={}){const n=i.padding??40,o=i.yFlip??!1;let s;if("center"in t){const c=t.width/2,I=t.height/2;s={minX:t.center.x-c,maxX:t.center.x+c,minY:t.center.y-I,maxY:t.center.y+I}}else s=t;const r=s.maxX-s.minX||1,a=s.maxY-s.minY||1,g=Math.min((A-2*n)/r,(e-2*n)/a);return An(on(A/2,e/2),$a(g,o?-g:g),on(-(s.minX+r/2),-(s.minY+a/2)))}function Hti(t){const A=[...t.points||[],...(t.lines||[]).flatMap(e=>e.points),...(t.rects||[]).flatMap(e=>{const i=e.width/2,n=e.height/2;return[{x:e.center.x-i,y:e.center.y-n},{x:e.center.x+i,y:e.center.y-n},{x:e.center.x-i,y:e.center.y+n},{x:e.center.x+i,y:e.center.y+n}]}),...(t.circles||[]).flatMap(e=>[{x:e.center.x-e.radius,y:e.center.y},{x:e.center.x+e.radius,y:e.center.y},{x:e.center.x,y:e.center.y-e.radius},{x:e.center.x,y:e.center.y+e.radius}]),...(t.texts||[]).flatMap(e=>{const i=e.fontSize??12,n=e.text.length*i*Lti,o=i*Uti,s=e.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=e.x+a,I=e.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((e,i)=>({minX:Math.min(e.minX,i.x),maxX:Math.max(e.maxX,i.x),minY:Math.min(e.minY,i.y),maxY:Math.max(e.maxY,i.y)}),{minX:1/0,maxX:-1/0,minY:1/0,maxY:-1/0})}function Yti(t,A,e={}){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(e.transform)s=e.transform;else if(e.viewbox)s=u0e(e.viewbox,n,o,{padding:e.padding,yFlip:e.yFlip});else{const r=Hti(t),a=t.coordinateSystem==="cartesian";s=u0e(r,n,o,{padding:e.padding??40,yFlip:a})}i.clearRect(0,0,n,o),i.save(),t.rects&&t.rects.length>0&&t.rects.forEach(r=>{const a=r.width/2,g=r.height/2,c=Ce(s,{x:r.center.x-a,y:r.center.y-g}),I=Ce(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())}),t.circles&&t.circles.length>0&&t.circles.forEach(r=>{const a=Ce(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())}),t.lines&&t.lines.length>0&&t.lines.forEach((r,a)=>{if(r.points.length===0)return;i.beginPath();const g=Ce(s,r.points[0]);i.moveTo(g.x,g.y);for(let c=1;c<r.points.length;c++){const I=Ce(s,r.points[c]);i.lineTo(I.x,I.y)}if(i.strokeStyle=r.strokeColor||LV[a%LV.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()}),t.points&&t.points.length>0&&t.points.forEach((r,a)=>{const g=Ce(s,r);i.beginPath(),i.arc(g.x,g.y,3,0,2*Math.PI),i.fillStyle=r.color||LV[a%LV.length],i.fill(),r.label&&!e.disableLabels&&(i.fillStyle=r.color||"black",i.font="12px sans-serif",i.fillText(r.label,g.x+5,g.y-5))}),t.texts&&t.texts.length>0&&t.texts.forEach(r=>{const a=Ce(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 Jti=({children:t,transform:A,debugGraphics:e})=>{const i=V.useRef(null),[n,{width:o,height:s}]=VL(),r=gl(a=>a.is_showing_autorouting);return V.useEffect(()=>{r&&i.current&&e&&o&&s&&(i.current.width=o,i.current.height=s,Yti(e,i.current,{transform:A,disableLabels:!0}))},[e,A,o,s,r]),r?W.jsxs("div",{ref:n,style:{position:"relative",width:"100%",height:"100%"},children:[t,W.jsx("canvas",{ref:i,style:{position:"absolute",top:0,left:0,opacity:.5,zIndex:100,width:"100%",height:"100%",pointerEvents:"none"}})]}):t},Tti=({children:t,transform:A=ba(),elements:e=[]})=>{const[i,{width:n,height:o}]=VL(),s=V.useRef(null);return V.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=e.filter(I=>I.type==="pcb_component"),c=e.filter(I=>I.type==="pcb_manual_edit_conflict_warning");a.strokeStyle=yn.board.drc_warning,a.lineWidth=2,c.forEach(I=>{const l=g.find(q=>q.pcb_component_id===I.pcb_component_id);if(!l)return;const{width:B,height:C,center:Q}=l,h=Ce(A,Q),E=B*Math.abs(A.a),u=C*Math.abs(A.d),d=.1*Math.abs(A.a),p=E+d*2,y=u+d*2,w=h.x-p/2,D=h.y-y/2;a.beginPath(),a.rect(w,D,p,y),a.stroke();const x="Manual Edit Conflict",_=4,S=Math.max(8,Math.min(12,10*Math.abs(A.a)));a.font=`${S}px sans-serif`;const F=a.measureText(x).width+_*2,L=S+_*2,Y=w+(p-F)/2,J=D+y+5;a.fillStyle="rgba(0, 0, 0, 0.7)",a.beginPath(),a.roundRect(Y,J,F,L,3),a.fill(),a.fillStyle=yn.board.drc_warning,a.textAlign="center",a.textBaseline="middle",a.fillText(x,Y+F/2,J+L/2)})},[e,A,n,o]),W.jsxs("div",{ref:i,style:{position:"relative",width:"100%",height:"100%"},children:[t,W.jsx("canvas",{ref:s,style:{position:"absolute",top:0,left:0,pointerEvents:"none",zIndex:vc.warnings}})]})},UV=(t,A,e)=>e(t,A),d0e=(t,A,e,i,n)=>{const o=n*Math.PI/180,s=Math.cos(o),r=Math.sin(o),a=t-e,g=A-i,c=a*s-g*r,I=a*r+g*s;return{x:c+e,y:I+i}},jL=t=>{if(t.length===0)return null;let A=t[0].x,e=t[0].x,i=t[0].y,n=t[0].y;for(const o of t)A=UV(A,o.x,Math.min),e=UV(e,o.x,Math.max),i=UV(i,o.y,Math.min),n=UV(n,o.y,Math.max);return{minX:A,maxX:e,minY:i,maxY:n}},Pti=(t,A)=>({minX:Math.min(t.minX,A.minX),maxX:Math.max(t.maxX,A.maxX),minY:Math.min(t.minY,A.minY),maxY:Math.max(t.maxY,A.maxY)}),Kti=(t,A)=>t?Pti(t,A):A,qti=t=>{switch(t.pcb_drawing_type){case"line":{const A=(t.width??0)/2,e=[{x:t.x1,y:t.y1},{x:t.x2,y:t.y2}],i=jL(e);return i?{minX:i.minX-A,maxX:i.maxX+A,minY:i.minY-A,maxY:i.maxY+A}:null}case"rect":{const A=t.w/2,e=t.h/2,i=[{x:t.x-A,y:t.y-e},{x:t.x+A,y:t.y-e},{x:t.x+A,y:t.y+e},{x:t.x-A,y:t.y+e}],n=t.ccw_rotation??0,o=n===0?i:i.map(s=>d0e(s.x,s.y,t.x,t.y,n));return jL(o)}case"circle":return{minX:t.x-t.r,maxX:t.x+t.r,minY:t.y-t.r,maxY:t.y+t.r};case"oval":return{minX:t.x-t.rX,maxX:t.x+t.rX,minY:t.y-t.rY,maxY:t.y+t.rY};case"pill":{const A=t.w/2,e=t.h/2,i=[{x:t.x-A,y:t.y-e},{x:t.x+A,y:t.y-e},{x:t.x+A,y:t.y+e},{x:t.x-A,y:t.y+e}],n=t.ccw_rotation??0,o=n===0?i:i.map(s=>d0e(s.x,s.y,t.x,t.y,n));return jL(o)}case"polygon":return jL(t.points);case"polygon_with_arcs":{const A=t.brep_shape.outer_ring.vertices.map(e=>({x:e.x,y:e.y}));return jL(A)}case"text":{const A=t.size??0,e=t.text?t.text.length*A*.6:0,i=A;if(e===0&&i===0)return{minX:t.x,maxX:t.x,minY:t.y,maxY:t.y};const n=e/2,o=i/2;return{minX:t.x-n,maxX:t.x+n,minY:t.y-o,maxY:t.y+o}}default:return null}};function Oti(t){const{dimensionStart:A,dimensionEnd:e,screenDimensionStart:i,screenDimensionEnd:n,flipX:o,flipY:s}=t,r=e.x-A.x,a=e.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,p=B+90;let y=Math.cos(p*Math.PI/180)*d,w=Math.sin(p*Math.PI/180)*d;const D=c>0&&I<0,x=c>0&&I>0,_=c<0&&I>0;o!==s&&!D&&(y=-y,w=-w),D&&(y+=Math.cos(p*Math.PI/180)*-45,w+=Math.sin(p*Math.PI/180)*-45),x&&(y+=Math.cos(p*Math.PI/180)+-20,w+=Math.sin(p*Math.PI/180)+-10),_&&(y+=Math.cos(p*Math.PI/180)*10,w+=Math.sin(p*Math.PI/180)*10);const S=E+y,N=u+w;return{distance:g,screenDistance:l,x:S,y:N,show:g>.01&&l>30&&h}}function Wti(t){const{dimensionStart:A,dimensionEnd:e,screenDimensionStart:i,screenDimensionEnd:n,flipX:o,flipY:s}=t;return V.useMemo(()=>Oti({dimensionStart:A,dimensionEnd:e,screenDimensionStart:i,screenDimensionEnd:n,flipX:o,flipY:s}),[A,e,i,n,o,s])}var Zti=(t,A,e)=>{const i=e*Math.PI/180,n=Math.cos(i),o=Math.sin(i),s=t.x-A.x,r=t.y-A.y,a=s*n-r*o,g=s*o+r*n;return{x:a+A.x,y:g+A.y}},p0e=(t,A,e,i)=>{const n={top_left:{x:t.x-A,y:t.y-e},top_center:{x:t.x,y:t.y-e},top_right:{x:t.x+A,y:t.y-e},center_left:{x:t.x-A,y:t.y},center:{x:t.x,y:t.y},center_right:{x:t.x+A,y:t.y},bottom_left:{x:t.x-A,y:t.y+e},bottom_center:{x:t.x,y:t.y+e},bottom_right:{x:t.x+A,y:t.y+e}};return i===0?Object.entries(n).map(([o,s])=>({anchor:o,point:s})):Object.entries(n).map(([o,s])=>({anchor:o,point:Zti(s,t,i)}))},Vti=t=>{switch(t.pcb_drawing_type){case"rect":{const A=t.ccw_rotation??0;return p0e({x:t.x,y:t.y},t.w/2,t.h/2,A)}case"pill":{const A=t.ccw_rotation??0;return p0e({x:t.x,y:t.y},t.w/2,t.h/2,A)}case"circle":return[{anchor:"circle_center",point:{x:t.x,y:t.y}},{anchor:"circle_right",point:{x:t.x+t.r,y:t.y}},{anchor:"circle_left",point:{x:t.x-t.r,y:t.y}},{anchor:"circle_top",point:{x:t.x,y:t.y-t.r}},{anchor:"circle_bottom",point:{x:t.x,y:t.y+t.r}}];case"oval":return[{anchor:"oval_center",point:{x:t.x,y:t.y}},{anchor:"oval_right",point:{x:t.x+t.rX,y:t.y}},{anchor:"oval_left",point:{x:t.x-t.rX,y:t.y}},{anchor:"oval_top",point:{x:t.x,y:t.y-t.rY}},{anchor:"oval_bottom",point:{x:t.x,y:t.y+t.rY}}];case"line":{const A={x:(t.x1+t.x2)/2,y:(t.y1+t.y2)/2};return[{anchor:"line_start",point:{x:t.x1,y:t.y1}},{anchor:"line_mid",point:A},{anchor:"line_end",point:{x:t.x2,y:t.y2}}]}case"polygon":return t.points.map((A,e)=>({anchor:`polygon_vertex_${e}`,point:A}));case"polygon_with_arcs":return t.brep_shape.outer_ring.vertices.map((A,e)=>({anchor:`polygon_with_arcs_vertex_${e}`,point:{x:A.x,y:A.y}}));default:return[]}},jti=16,H3=5,f0e=t=>{if(t.pcb_drawing_type==="text")return!0;const A=t._element;if(!A||typeof A!="object")return!1;const e=typeof A.type=="string"?A.type:void 0;return e?!!(e.startsWith("pcb_silkscreen_")||e.startsWith("pcb_note_")||e==="pcb_text"||e.startsWith("pcb_fabrication_note_")&&e!=="pcb_fabrication_note_rect"):!1},zti=({children:t,transform:A,focusOnHover:e=!1,primitives:i=[]})=>{A||(A=ba());const[n,o]=V.useState(!1),[s,r]=V.useState(!1),[a,g]=V.useState(!1),[c,I]=V.useState({start:null,end:null}),l=gl(J=>J.is_mouse_over_container),B=V.useCallback(()=>{a&&(g(!1),window.dispatchEvent(new Event("disarm-dimension-tool")))},[a]),[C,Q]=V.useState({x:0,y:0}),[h,E]=V.useState({x:0,y:0}),u=V.useRef({x:0,y:0}),d=V.useRef(null),y=d.current?.getBoundingClientRect(),w=V.useMemo(()=>{const J=new Map;for(const q of i){if(!q._element||f0e(q)||q.pcb_drawing_type==="pill"||q.pcb_drawing_type==="rect"&&q.ccw_rotation&&q.ccw_rotation!==0)continue;const Z=qti(q);if(!Z)continue;const X=J.get(q._element);J.set(q._element,Kti(X??void 0,Z))}return J},[i]),D=V.useMemo(()=>{const J=[];for(const q of i){if(!q._element||f0e(q))continue;const Z=Vti(q);if(Z.length!==0)for(const X of Z)J.push({anchor:X.anchor,point:X.point,element:q._element})}return J},[i]),x=V.useMemo(()=>{const J=[];w.forEach((q,Z)=>{if(!q)return;const X=(q.minX+q.maxX)/2,eA=(q.minY+q.maxY)/2,gA={top_left:{x:q.minX,y:q.minY},top_center:{x:X,y:q.minY},top_right:{x:q.maxX,y:q.minY},center_left:{x:q.minX,y:eA},center:{x:X,y:eA},center_right:{x:q.maxX,y:eA},bottom_left:{x:q.minX,y:q.maxY},bottom_center:{x:X,y:q.maxY},bottom_right:{x:q.maxX,y:q.maxY}};for(const[tA,iA]of Object.entries(gA))J.push({anchor:tA,point:iA,element:Z})});for(const q of D)J.push(q);return J.push({anchor:"origin",point:{x:0,y:0},element:null}),J},[w,D]),_=V.useMemo(()=>x.map((J,q)=>({...J,id:`${q}-${J.anchor}`,screenPoint:Ce(A,J.point)})),[x,A]),S=V.useCallback(J=>{if(_.length===0)return{point:J,id:null};const q=Ce(A,J);let Z=null;for(const X of _){const eA=X.screenPoint.x-q.x,gA=X.screenPoint.y-q.y,tA=Math.hypot(eA,gA);tA>jti||(!Z||tA<Z.distance)&&(Z={distance:tA,id:X.id,point:X.point})}return Z?{point:Z.point,id:Z.id}:{point:J,id:null}},[_,A]);V.useEffect(()=>{const J=Z=>{const X=Z.target;if(X.tagName==="INPUT"||X.tagName==="TEXTAREA"||X.isContentEditable)return;const eA=d.current?.contains(document.activeElement)||document.activeElement===d.current;if(!(!l&&!eA)){if(Z.key==="d"){const gA=S({x:u.current.x,y:u.current.y});Q({x:gA.point.x,y:gA.point.y}),E({x:gA.point.x,y:gA.point.y}),I({start:gA.id,end:gA.id}),n?(o(!1),r(!1),I({start:null,end:null})):(o(!0),r(!0)),B()}Z.key==="Escape"&&(o(!1),r(!1),I({start:null,end:null}),B())}},q=()=>{g(!0)};return window.addEventListener("keydown",J),window.addEventListener("arm-dimension-tool",q),()=>{window.removeEventListener("keydown",J),window.removeEventListener("arm-dimension-tool",q),B()}},[l,n,B,S]);const N=Ce(A,C),F=Ce(A,h),L={left:Math.min(N.x,F.x),right:Math.max(N.x,F.x),top:Math.min(N.y,F.y),bottom:Math.max(N.y,F.y),flipX:N.x>F.x,flipY:N.y>F.y,width:0,height:0};L.width=L.right-L.left,L.height=L.bottom-L.top;const Y=Wti({dimensionStart:C,dimensionEnd:h,screenDimensionStart:N,screenDimensionEnd:F,flipX:L.flipX,flipY:L.flipY});return W.jsxs("div",{ref:d,"data-pcb-viewer":!0,tabIndex:0,style:{position:"relative",outline:"none"},onMouseEnter:()=>{e&&d.current&&d.current.focus()},onMouseLeave:()=>{d.current&&d.current.blur()},onClick:()=>{d.current&&d.current.focus()},onMouseMove:J=>{const q=J.currentTarget.getBoundingClientRect(),Z=J.clientX-q.left,X=J.clientY-q.top,eA=Ce(tm(A),{x:Z,y:X});if(u.current.x=eA.x,u.current.y=eA.y,s){const gA=S(eA);E({x:gA.point.x,y:gA.point.y}),I(tA=>({...tA,end:gA.id}))}},onMouseDown:J=>{const q=J.currentTarget.getBoundingClientRect(),Z=J.clientX-q.left,X=J.clientY-q.top,eA=Ce(tm(A),{x:Z,y:X});if(a&&!n){const gA=S(eA);Q({x:gA.point.x,y:gA.point.y}),E({x:gA.point.x,y:gA.point.y}),I({start:gA.id,end:gA.id}),o(!0),r(!0),B()}else s?(r(!1),I(gA=>({...gA,end:null}))):n&&(o(!1),I({start:null,end:null}))},children:[t,n&&W.jsxs(W.Fragment,{children:[Y.show&&W.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:vc.dimensionOverlay},children:Y.distance.toFixed(2)}),W.jsx("div",{style:{position:"absolute",left:L.left,width:L.width,textAlign:"center",top:N.y+2,color:"red",mixBlendMode:"difference",pointerEvents:"none",marginTop:L.flipY?0:-20,fontSize:12,fontFamily:"sans-serif",zIndex:vc.dimensionOverlay},children:Math.abs(C.x-h.x).toFixed(2)}),W.jsx("div",{style:{position:"absolute",left:F.x,height:L.height,display:"flex",flexDirection:"column",justifyContent:"center",top:L.top,color:"red",pointerEvents:"none",mixBlendMode:"difference",fontSize:12,fontFamily:"sans-serif",zIndex:vc.dimensionOverlay},children:W.jsx("div",{style:{marginLeft:L.flipX?"-100%":4,paddingRight:4},children:Math.abs(C.y-h.y).toFixed(2)})}),W.jsxs("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none",mixBlendMode:"difference",zIndex:vc.dimensionOverlay},width:y.width,height:y.height,children:[W.jsx("defs",{children:W.jsx("marker",{id:"head",orient:"auto",markerWidth:"3",markerHeight:"4",refX:"2",refY:"2",children:W.jsx("path",{d:"M0,0 V4 L2,2 Z",fill:"red"})})}),W.jsx("line",{x1:N.x,y1:N.y,x2:F.x,y2:F.y,markerEnd:"url(#head)",strokeWidth:1.5,fill:"none",stroke:"red"}),W.jsx("line",{x1:N.x,y1:N.y,x2:F.x,y2:N.y,strokeWidth:1.5,fill:"none",strokeDasharray:"2,2",stroke:"red"}),W.jsx("line",{x1:F.x,y1:N.y,x2:F.x,y2:F.y,strokeWidth:1.5,fill:"none",strokeDasharray:"2,2",stroke:"red"})]}),s&&_.map(J=>{const q=J.id===c.start||J.id===c.end,Z=H3/2;return W.jsxs("svg",{width:H3,height:H3,style:{position:"absolute",left:J.screenPoint.x-Z,top:J.screenPoint.y-Z,pointerEvents:"none",zIndex:vc.dimensionOverlay},children:[W.jsx("line",{x1:0,y1:0,x2:H3,y2:H3,stroke:q?"#66ccff":"white",strokeWidth:1}),W.jsx("line",{x1:H3,y1:0,x2:0,y2:H3,stroke:q?"#66ccff":"white",strokeWidth:1})]},J.id)}),W.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),")",W.jsx("br",{}),"(",h.x.toFixed(2),",",h.y.toFixed(2),")",W.jsx("br",{}),"dist:"," ",Math.sqrt((h.x-C.x)**2+(h.y-C.y)**2).toFixed(2)]})]})]})},Xti=(t,A,e=0)=>{const i=t.width/2,n=t.height/2,o=t.center.x-i-e,s=t.center.x+i+e,r=t.center.y-n-e,a=t.center.y+n+e;return A.x>o&&A.x<s&&A.y>r&&A.y<a},$ti=({children:t,disabled:A,transform:e,soup:i,cancelPanDrag:n,onCreateEditEvent:o,onModifyEditEvent:s})=>{e||(e=ba());const r=V.useRef(null),[a,g]=V.useState(null),[c,I]=V.useState(null),l=a!==null;gl(h=>h.in_edit_mode);const B=gl(h=>h.in_move_footprint_mode),C=gl(h=>h.setIsMovingComponent),Q=A||!B;return W.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 p=Ce(tm(e),{x:u,y:d});let y=!1;for(const w of i)if(w.type==="pcb_component"&&Xti(w,p,10/e.a)){n(),g(w.pcb_component_id),y=!0;const D=Math.random().toString();I({dragStart:p,originalCenter:w.center,dragEnd:p,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(y||g(null),y)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 p=Ce(tm(e),{x:u,y:d});I({...c,dragEnd:p}),s({edit_event_id:c.edit_event_id,new_center:{x:c.originalCenter.x+p.x-c.dragStart.x,y:c.originalCenter.y+p.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:[t,!Q&&i.filter(h=>h.type==="pcb_component").map(h=>{if(!h?.center)return null;const E=Ce(e,h.center);return W.jsx("div",{style:{position:"absolute",pointerEvents:"none",left:E.x,top:E.y,width:h.width*e.a+20,height:h.height*e.a+20,transform:"translate(-50%, -50%)",background:l&&a===h.pcb_component_id?"rgba(255, 0, 0, 0.2)":""}},h.pcb_component_id)})]})},Aii=({hotkeys:t})=>(V.useEffect(()=>{const A=e=>{t.forEach(i=>{e.key===i.key&&i.onUse()})};return window.addEventListener("keydown",A),()=>{window.removeEventListener("keydown",A)}},[t]),W.jsx("div",{className:xM`
|
|
5437
5437
|
display: flex;
|
|
5438
5438
|
flex-direction: column;
|
|
5439
5439
|
font-family: sans-serif;
|
|
@@ -5472,7 +5472,7 @@ $1`).replace(/>(\s*)(?=<!--\s*\/)/g,"> ")}}});function Whe(t,A,e){if(!A||!e)retu
|
|
|
5472
5472
|
transition: opacity 0.2s;
|
|
5473
5473
|
margin-bottom: 10px;
|
|
5474
5474
|
color: red;
|
|
5475
|
-
`,sii=({children:t,transform:A=ba(),elements:e})=>{const i=V.useRef(null),{isShowingDRCErrors:n,hoveredErrorId:o}=gl(g=>({isShowingDRCErrors:g.is_showing_drc_errors,hoveredErrorId:g.hovered_error_id}));if(!e)return W.jsx("div",{style:{position:"relative"},ref:i,children:t});const s=e.filter(g=>g.type==="pcb_trace_error"),r=e.filter(g=>g.type==="pcb_trace_error"&&g.message?.includes("Multiple components found with name")),a=new Map;return e.forEach(g=>{g.type==="pcb_port"&&a.set(g.pcb_port_id,g)}),W.jsxs("div",{style:{position:"relative"},ref:i,children:[t,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=e?rx(e).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=Ce(A,{x:B.x,y:B.y}),d=Ce(A,{x:C.x,y:C.y});if(!n)return null;const p=!(isNaN(u.x)||isNaN(u.y)||isNaN(d.x)||isNaN(d.y)),y={x:(u.x+d.x)/2,y:(u.y+d.y)/2};if(isNaN(y.x)||isNaN(y.y))return null;const w=vmA(y,i);return W.jsxs(V.Fragment,{children:[W.jsx(nii,{screenPort1:u,screenPort2:d,errorCenter:y,canLineBeDrawn:p,isHighlighted:E}),W.jsx("div",{style:{position:"absolute",left:y.x-15,top:y.y-15,width:30,height:30,zIndex:vc.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")}}}}),W.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:W.jsx("div",{className:`error-message ${FmA}`,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=>Ce(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),p=u[d],y=vmA(p,i);return W.jsxs(V.Fragment,{children:[W.jsx(oii,{points:u,errorCenter:p,isHighlighted:E}),W.jsx("div",{style:{position:"absolute",left:p.x-15,top:p.y-15,width:30,height:30,zIndex:vc.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")}}}}),W.jsx("div",{style:{position:"absolute",zIndex:E?vc.errorOverlay+10:vc.errorOverlay+1,left:y.left,top:y.top,color:E?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:"flex",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:y.transform},children:W.jsx("div",{className:`error-message ${FmA}`,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=e?.filter(Q=>Q.type==="source_component"&&Q.name===I||Q.type==="pcb_component"&&e?.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 _=e?.find(S=>S.type==="pcb_component"&&S.source_component_id===Q.source_component_id);_&&_.type==="pcb_component"&&(E=_.center||{x:0,y:0})}const u=Ce(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=vmA(u,i);return W.jsxs(V.Fragment,{children:[W.jsx("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none",mixBlendMode:"difference",zIndex:vc.errorOverlay},width:"100%",height:"100%",children:C?W.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"}):W.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})}),W.jsx("div",{style:{position:"absolute",left:u.x-(D+10),top:u.y-(D+10),width:(D+10)*2,height:(D+10)*2,zIndex:vc.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:_=>{const S=_.currentTarget.nextElementSibling;if(S){const N=S.querySelector(".error-message");N&&(N.style.opacity="1")}},onMouseLeave:_=>{if(!C){const S=_.currentTarget.nextElementSibling;if(S){const N=S.querySelector(".error-message");N&&(N.style.opacity="0")}}}}),W.jsx("div",{style:{position:"absolute",zIndex:C?vc.errorOverlay+20:vc.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:W.jsx("div",{className:`error-message ${FmA}`,style:{opacity:C?1:0,border:`1px solid ${C?"#ff4444":"red"}`},children:g.message})})]},`${B}_${h}`)})})]})};function rii(t,A){return t.size!==A.size?!1:Array.from(t).every(e=>A.has(e))}function aii({primitiveElement:t,elements:A}){let e=t.trace_length?`${t.trace_length.toFixed(3)}`:"";const i=rx(A).source_trace.get(t?.source_trace_id);if(i?.display_name&&(i?.max_length?e+=` / ${i.max_length}mm `:e+=" mm ",e+=`(${i.display_name})`),!e)return null;const n=t.trace_length&&i?.max_length&&t.trace_length>i.max_length;return{text:e,isOverLength:n}}function gii(t){const{primitives:A,is_showing_multiple_traces_length:e,elements:i}=t,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(!e)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 cii={position:"absolute",left:0,top:0,pointerEvents:"none",color:"red",fontFamily:"sans-serif",fontSize:12,textShadow:"0 0 2px black"},Iii=t=>{const{_element:A,_parent_pcb_component:e,_parent_source_component:i,_source_port:n}=t;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""}},lii={top:"red",bottom:"aqua"},Bii=({primitive:t,mousePos:A,elements:e})=>{const[i,n]=V.useState(!1),o=t._element;V.useEffect(()=>{setTimeout(()=>{n(!0)},100)},[]);const[s,r,a,g]=[t.screen_x,t.screen_y,t.screen_w,t.screen_h],c=t.same_space_index??0,I=26,l=lii[t?._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 t||o.type==="pcb_plated_hole"&&(o?.shape==="pill"||o?.shape==="oval")&&"ccw_rotation"in t)&&(B=o.ccw_rotation??0),o.type==="pcb_trace"){const h=aii({primitiveElement:o,elements:e});if(!h)return null;const E=A.y-35;return W.jsx("div",{style:{zIndex:vc.elementOverlay,position:"absolute",left:A.x,top:E,color:l,pointerEvents:"none",transform:"translateX(-50%)"},children:W.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=Iii(t);return C.trim().length===0?null:W.jsx("div",{style:{zIndex:vc.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:W.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:W.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})})})},Cii=({highlightedPrimitives:t,mousePos:A,elements:e})=>{const[i,n]=gl(r=>[r.is_moving_component,r.is_showing_multiple_traces_length]),o=t.some(r=>r._element.type==="pcb_smtpad")&&t.some(r=>r._element.type==="pcb_trace");let s=t;return o&&(s=s.filter(r=>r._element.type==="pcb_smtpad")),s=gii({primitives:s,is_showing_multiple_traces_length:n,elements:e}),W.jsx("div",{style:cii,children:!i&&s.map((r,a)=>W.jsx(Bii,{primitive:r,mousePos:A,elements:e},a))})},Pb=t=>t?.type==="pcb_component",y0e=t=>t?.type==="pcb_group",Qii=t=>t?.type==="pcb_panel",MmA=t=>t?.type==="pcb_board",gI={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},ly={OFFSET_LINE:"white",COMPONENT_MARKER_FILL:"#66ccff",COMPONENT_MARKER_STROKE:"white",LABEL_TEXT:"white"},RmA=({targets:t,transform:A,containerWidth:e,containerHeight:i})=>{if(t.length===0)return null;const n={color:ly.LABEL_TEXT,mixBlendMode:"difference",pointerEvents:"none",fontSize:gI.LABEL_FONT_SIZE,fontFamily:"monospace",fontWeight:"bold"},o=new Map;return t.forEach(s=>{if(!o.has(s.anchor_id)){const r=Ce(A,s.anchor);o.set(s.anchor_id,r)}}),W.jsx("div",{style:{position:"absolute",left:0,top:0,width:e,height:i,overflow:"hidden",pointerEvents:"none",zIndex:vc.dimensionOverlay},children:W.jsxs("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none"},width:e,height:i,children:[t.map(s=>{const r=s.anchor,a=s.anchor_id,g=s.target,c=o.get(a),I=Ce(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?gI.LABEL_OFFSET_ABOVE:gI.LABEL_OFFSET_BELOW,d=E?gI.LABEL_OFFSET_RIGHT:gI.LABEL_OFFSET_LEFT,p=C>gI.MIN_LINE_LENGTH_FOR_LABEL,y=Q>gI.MIN_LINE_LENGTH_FOR_LABEL,w=`${s.display_offset_x??l.toFixed(2)}mm`,D=`${s.display_offset_y??B.toFixed(2)}mm`;return W.jsxs("g",{children:[W.jsx("line",{x1:c.x,y1:c.y,x2:I.x,y2:c.y,stroke:ly.OFFSET_LINE,strokeWidth:gI.LINE_STROKE_WIDTH,strokeDasharray:gI.LINE_DASH_PATTERN}),W.jsx("line",{x1:I.x,y1:c.y,x2:I.x,y2:I.y,stroke:ly.OFFSET_LINE,strokeWidth:gI.LINE_STROKE_WIDTH,strokeDasharray:gI.LINE_DASH_PATTERN}),s.type==="component"||s.type==="board"?W.jsx("circle",{cx:I.x,cy:I.y,r:gI.COMPONENT_MARKER_RADIUS,fill:ly.COMPONENT_MARKER_FILL,stroke:ly.COMPONENT_MARKER_STROKE,strokeWidth:1}):W.jsxs(W.Fragment,{children:[W.jsx("line",{x1:I.x-gI.ANCHOR_MARKER_SIZE,y1:I.y,x2:I.x+gI.ANCHOR_MARKER_SIZE,y2:I.y,stroke:ly.OFFSET_LINE,strokeWidth:gI.ANCHOR_MARKER_STROKE_WIDTH}),W.jsx("line",{x1:I.x,y1:I.y-gI.ANCHOR_MARKER_SIZE,x2:I.x,y2:I.y+gI.ANCHOR_MARKER_SIZE,stroke:ly.OFFSET_LINE,strokeWidth:gI.ANCHOR_MARKER_STROKE_WIDTH})]}),p&&W.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:W.jsx("div",{style:{...n,textAlign:"center"},children:w})}),y&&W.jsx("foreignObject",{x:I.x+d,y:Math.min(c.y,I.y),width:gI.Y_LABEL_MIN_WIDTH,height:Math.abs(I.y-c.y),style:{overflow:"visible"},children:W.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])=>W.jsxs("g",{children:[W.jsx("line",{x1:r.x-gI.ANCHOR_MARKER_SIZE,y1:r.y,x2:r.x+gI.ANCHOR_MARKER_SIZE,y2:r.y,stroke:ly.OFFSET_LINE,strokeWidth:gI.ANCHOR_MARKER_STROKE_WIDTH}),W.jsx("line",{x1:r.x,y1:r.y-gI.ANCHOR_MARKER_SIZE,x2:r.x,y2:r.y+gI.ANCHOR_MARKER_SIZE,stroke:ly.OFFSET_LINE,strokeWidth:gI.ANCHOR_MARKER_STROKE_WIDTH})]},`anchor-${s}`))]})})},hii=({elements:t,highlightedPrimitives:A,transform:e,containerWidth:i,containerHeight:n})=>{const o=t.filter(E=>MmA(E)),s=t.filter(E=>Pb(E)),r=t.filter(E=>y0e(E)),a=A.map(E=>Pb(E._parent_pcb_component)?E._parent_pcb_component.pcb_component_id:Pb(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)}),!gl(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(p=>p.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(p=>p.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 W.jsx(RmA,{targets:h,transform:e,containerWidth:i,containerHeight:n})},Eii=({elements:t,highlightedPrimitives:A,transform:e,containerWidth:i,containerHeight:n})=>{const o=t.filter(E=>y0e(E)),s=t.filter(E=>Pb(E)),r=A.map(E=>Pb(E._parent_pcb_component)?E._parent_pcb_component.pcb_component_id:Pb(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(p=>p.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))}),!gl(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 W.jsx(RmA,{targets:h,transform:e,containerWidth:i,containerHeight:n})},uii=(t,A)=>{const e=t.pcb_component_id,i=A.filter(n=>(n.type==="pcb_smtpad"||n.type==="pcb_plated_hole")&&n.pcb_component_id===e||n.type==="pcb_hole"&&n.pcb_component_id===e);return i.length===0?_mA([t]):_mA(i)},dii=({elements:t,highlightedPrimitives:A,transform:e,containerWidth:i,containerHeight:n})=>{const o=new Map;for(const r of A)Pb(r._parent_pcb_component)&&o.set(r._parent_pcb_component.pcb_component_id,r._parent_pcb_component),Pb(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=uii(r,t);if(!a)continue;const g=r.positioned_relative_to_pcb_group_id??r.pcb_group_id,c=g?rx(t).pcb_group.get(g):null;s.push({component:r,bbox:a,group:c})}return s.length===0?null:W.jsx("div",{style:{position:"absolute",left:0,top:0,width:i,height:n,overflow:"hidden",pointerEvents:"none",zIndex:vc.dimensionOverlay},children:W.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=Ce(e,{x:a.minX,y:a.maxY}),I=Ce(e,{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=Ce(e,B);return W.jsxs("g",{children:[W.jsx("rect",{x:l.x,y:l.y,width:l.width,height:l.height,fill:"none",stroke:"white",strokeWidth:1.5,strokeDasharray:"4,4"}),W.jsx("line",{x1:C.x-6,y1:C.y,x2:C.x+6,y2:C.y,stroke:ly.COMPONENT_MARKER_STROKE,strokeWidth:1.5}),W.jsx("line",{x1:C.x,y1:C.y-6,x2:C.x,y2:C.y+6,stroke:ly.COMPONENT_MARKER_STROKE,strokeWidth:1.5}),W.jsx("circle",{cx:C.x,cy:C.y,r:gI.COMPONENT_MARKER_RADIUS,fill:ly.COMPONENT_MARKER_FILL,stroke:ly.COMPONENT_MARKER_STROKE,strokeWidth:1})]},r.pcb_component_id)})})})},pii=({elements:t,highlightedPrimitives:A,transform:e,containerWidth:i,containerHeight:n})=>{const o=t.filter(B=>Qii(B)),s=t.filter(B=>MmA(B)),r=A.map(B=>MmA(B._element)?B._element.pcb_board_id:null).filter(B=>!!B);if(!gl(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 W.jsx(RmA,{targets:l,transform:e,containerWidth:i,containerHeight:n})},HV=t=>{if(t.length===0)return null;let A=t[0].x,e=t[0].y,i=t[0].x,n=t[0].y;for(const o of t)o.x<A&&(A=o.x),o.y<e&&(e=o.y),o.x>i&&(i=o.x),o.y>n&&(n=o.y);return{center:{x:(A+i)/2,y:(e+n)/2},width:i-A,height:n-e}},m0e=(t,A)=>{if(A.length<3)return!1;let e=!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>t.y!=a>t.y&&t.x<(r-o)*(t.y-s)/(a-s||Number.EPSILON)+o&&(e=!e)}return e},fii=(t,A,e)=>{const i=[];for(const n of t){if(!n._element)continue;if("x1"in n&&n._element?.type==="pcb_trace"){const r=J0({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)/e.a;r<g&&i.push(n);continue}if(n.pcb_drawing_type==="polygon"){const r=n.points.map(g=>({x:pt.parse(g.x),y:pt.parse(g.y)})),a=HV(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;m0e(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:pt.parse(g.x),y:pt.parse(g.y)})),a=HV(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;m0e(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},yii=({elements:t,children:A,transform:e,primitives:i,onMouseHoverOverPrimitives:n})=>{const[o,s]=V.useState([]),[r,a]=V.useState({x:0,y:0}),[g,{width:c,height:I}]=VL(),l=V.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=HV(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=HV(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=Ce(e,h),p={w:E*e.a,h:u*e.a},y=C.filter(w=>d.x===w.screen_x&&d.y===w.screen_y&&p.w===w.screen_w&&p.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:p.w,screen_h:p.h,same_space_index:y})}return C},[o,e]),B=(C,Q,h,E)=>{a({x:C,y:Q});const u=Ce(tm(h),{x:C,y:Q}),d=fii(E,u,h);rii(new Set(d.map(p=>p._pcb_drawing_object_id)),new Set(o.map(p=>p._pcb_drawing_object_id)))||(s(d),n(d))};return W.jsxs("div",{ref:g,style:{position:"relative",width:"100%",height:"100%"},onMouseMove:C=>{if(e){const Q=C.currentTarget.getBoundingClientRect(),h=C.clientX-Q.left,E=C.clientY-Q.top;B(h,E,e,i)}},onTouchStart:C=>{if(e){const Q=C.touches[0],h=C.currentTarget.getBoundingClientRect(),E=Q.clientX-h.left,u=Q.clientY-h.top;B(E,u,e,i)}},children:[A,W.jsx(Cii,{elements:t,mousePos:r,highlightedPrimitives:l}),e&&W.jsxs(W.Fragment,{children:[W.jsx(hii,{elements:t,highlightedPrimitives:l,transform:e,containerWidth:c,containerHeight:I}),W.jsx(Eii,{elements:t,highlightedPrimitives:l,transform:e,containerWidth:c,containerHeight:I}),W.jsx(dii,{elements:t,highlightedPrimitives:l,transform:e,containerWidth:c,containerHeight:I}),W.jsx(pii,{elements:t,highlightedPrimitives:l,transform:e,containerWidth:c,containerHeight:I})]})]})},w0e=["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)"],mii=({children:t,transform:A=ba(),elements:e=[],hoveredComponentIds:i=[]})=>{const[n,{width:o,height:s}]=VL(),r=V.useRef(null),{is_showing_pcb_groups:a,pcb_group_view_mode:g,is_showing_group_anchor_offsets:c}=gl(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 V.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=e.filter(w=>w.type==="pcb_group"),C=e.filter(w=>w.type==="pcb_component"),Q=e.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},p=w=>{const D=Q.find(x=>x.source_group_id===w);return D?.parent_source_group_id?1+p(D.parent_source_group_id):0},y=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&&y.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),WA=B.filter(vA=>vA.source_group_id&&TA.includes(vA.source_group_id));for(const vA of WA){const wA=C.filter(RA=>RA.pcb_group_id===vA.pcb_group_id);x=[...x,...wA]}}let _,S,N,F,L=!1;if(w.center&&w.width&&w.height){L=!0;const TA=w.width/2,WA=w.height/2;_=w.center.x-TA,N=w.center.x+TA,S=w.center.y-WA,F=w.center.y+WA}else if(x.length===0||(_=1/0,S=1/0,N=-1/0,F=-1/0,x.forEach(TA=>{if(TA.center&&typeof TA.width=="number"&&typeof TA.height=="number"){const WA=TA.center.x-TA.width/2,vA=TA.center.x+TA.width/2,wA=TA.center.y+TA.height/2,RA=TA.center.y-TA.height/2;_=Math.min(_,WA),N=Math.max(N,vA),S=Math.min(S,RA),F=Math.max(F,wA)}}),_===1/0||N===-1/0))return;const Y=w.source_group_id?p(w.source_group_id):0,J=w.source_group_id?d(w.source_group_id).length>0:!1;if(!L){const vA=1+(J?.5:0);_-=vA,N+=vA,S-=vA,F+=vA}const q=Ce(A,{x:_,y:F}),Z=Ce(A,{x:N,y:F}),X=Ce(A,{x:_,y:S}),eA=Ce(A,{x:N,y:S}),gA=w0e[D%w0e.length];l.strokeStyle=gA,l.lineWidth=2;const tA=Math.max(4,Math.min(12,8*Math.abs(A.a))),iA=Math.max(2,Math.min(6,4*Math.abs(A.a))),aA=tA*(J?1.3:1),EA=iA;l.setLineDash([aA,EA]),l.beginPath(),l.moveTo(q.x,q.y),l.lineTo(Z.x,Z.y),l.lineTo(eA.x,eA.y),l.lineTo(X.x,X.y),l.closePath(),l.stroke();const SA=Math.max(8,Math.min(12,10*Math.abs(A.a))),_A=Y==0||Y==1?0:Y*.11,LA=SA*(1-_A),QA=4,kA=w.name||`Group ${D+1}`;l.font=`${LA}px sans-serif`,l.setLineDash([]);const qA=l.measureText(kA).width+QA*2,VA=LA+QA*2,ce=q.x-5,fA=q.y-5,ge=3;if(l.fillStyle="rgba(0, 0, 0, 0.8)",l.beginPath(),l.roundRect(ce,fA-VA,qA,VA,ge),l.fill(),l.fillStyle=gA,l.textAlign="left",l.textBaseline="middle",l.fillText(kA,ce+QA,fA-VA/2),c&&y.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},WA=Ce(A,TA);l.strokeStyle="white",l.lineWidth=1.5,l.setLineDash([]);const vA=Math.max(4,Math.min(8,6*Math.abs(A.a)));l.beginPath(),l.moveTo(WA.x-vA,WA.y),l.lineTo(WA.x+vA,WA.y),l.stroke(),l.beginPath(),l.moveTo(WA.x,WA.y-vA),l.lineTo(WA.x,WA.y+vA),l.stroke()}})},[e,A,o,s,a,g,c,i]),W.jsxs("div",{ref:n,style:{position:"relative",width:"100%",height:"100%"},children:[t,W.jsx("canvas",{ref:r,style:{position:"absolute",top:0,left:0,pointerEvents:"none",zIndex:vc.pcbGroupOverlay,display:a?"block":"none"}})]})},wii=({transform:t,soup:A,children:e})=>{const i=gl(r=>r.is_showing_rats_nest),{netMap:n,idToNetMap:o}=V.useMemo(()=>e0e(A||[]),[A]),s=V.useMemo(()=>{if(!A||!i)return[];const r=l=>{const B=rx(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=rx(A).pcb_port.list(),c=rx(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?e:(t||(t=ba()),W.jsxs("div",{style:{position:"relative"},children:[e,W.jsx("svg",{style:{position:"absolute",left:0,top:0,width:"100%",height:"100%",pointerEvents:"none",opacity:.5,zIndex:vc.ratsNestOverlay},children:s.map(({key:r,startPoint:a,endPoint:g,isInNet:c})=>{const I=Ce(t,a),l=Ce(t,g);return W.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)})})]}))},Dii={version:"1.11.357"},Kb=(t,A,e)=>{const i=gl(s=>s.is_mouse_over_container),n=V.useRef(i),o=V.useRef(A);V.useEffect(()=>{n.current=i},[i]),V.useEffect(()=>{o.current=A},[A]),V.useEffect(()=>{if(!t)return;const s=r=>{const a=r.target;if(a.tagName==="INPUT"||a.tagName==="TEXTAREA"||a.isContentEditable)return;const g=t.split("+"),c=g.includes("ctrl"),I=g.includes("shift"),l=g.includes("alt"),B=g.includes("meta"),C=g[g.length-1],Q=e?.current?e.current.contains(document.activeElement)||document.activeElement===e.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)}},[t])},xii=()=>{const[t,A]=V.useState(!1);return V.useEffect(()=>{const e=()=>{A(window.innerWidth<=768)};return e(),window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[]),t},zL=(t,A={stopPropagation:!0})=>{const e=V.useRef(0),i=V.useCallback(s=>{A.stopPropagation&&s.stopPropagation();const r=Date.now();r-e.current<300||(e.current=r,t?.(s))},[t,A.stopPropagation]),n=V.useCallback(s=>{s.preventDefault(),i(s)},[i]);return{onClick:i,onTouchEnd:n,style:{touchAction:"manipulation"}}},Sii=({name:t,selected:A,onClick:e})=>{const{style:i,...n}=zL(e);return W.jsxs("div",{className:xM`
|
|
5475
|
+
`,sii=({children:t,transform:A=ba(),elements:e})=>{const i=V.useRef(null),{isShowingDRCErrors:n,hoveredErrorId:o}=gl(g=>({isShowingDRCErrors:g.is_showing_drc_errors,hoveredErrorId:g.hovered_error_id}));if(!e)return W.jsx("div",{style:{position:"relative"},ref:i,children:t});const s=e.filter(g=>g.type==="pcb_trace_error"),r=e.filter(g=>g.type==="pcb_trace_error"&&g.message?.includes("Multiple components found with name")),a=new Map;return e.forEach(g=>{g.type==="pcb_port"&&a.set(g.pcb_port_id,g)}),W.jsxs("div",{style:{position:"relative"},ref:i,children:[t,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=e?rx(e).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=Ce(A,{x:B.x,y:B.y}),d=Ce(A,{x:C.x,y:C.y});if(!n)return null;const p=!(isNaN(u.x)||isNaN(u.y)||isNaN(d.x)||isNaN(d.y)),y={x:(u.x+d.x)/2,y:(u.y+d.y)/2};if(isNaN(y.x)||isNaN(y.y))return null;const w=vmA(y,i);return W.jsxs(V.Fragment,{children:[W.jsx(nii,{screenPort1:u,screenPort2:d,errorCenter:y,canLineBeDrawn:p,isHighlighted:E}),W.jsx("div",{style:{position:"absolute",left:y.x-15,top:y.y-15,width:30,height:30,zIndex:vc.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")}}}}),W.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:W.jsx("div",{className:`error-message ${FmA}`,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=>Ce(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),p=u[d],y=vmA(p,i);return W.jsxs(V.Fragment,{children:[W.jsx(oii,{points:u,errorCenter:p,isHighlighted:E}),W.jsx("div",{style:{position:"absolute",left:p.x-15,top:p.y-15,width:30,height:30,zIndex:vc.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")}}}}),W.jsx("div",{style:{position:"absolute",zIndex:E?vc.errorOverlay+10:vc.errorOverlay+1,left:y.left,top:y.top,color:E?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:"flex",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:y.transform},children:W.jsx("div",{className:`error-message ${FmA}`,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=e?.filter(Q=>Q.type==="source_component"&&Q.name===I||Q.type==="pcb_component"&&e?.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 _=e?.find(S=>S.type==="pcb_component"&&S.source_component_id===Q.source_component_id);_&&_.type==="pcb_component"&&(E=_.center||{x:0,y:0})}const u=Ce(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=vmA(u,i);return W.jsxs(V.Fragment,{children:[W.jsx("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none",mixBlendMode:"difference",zIndex:vc.errorOverlay},width:"100%",height:"100%",children:C?W.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"}):W.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})}),W.jsx("div",{style:{position:"absolute",left:u.x-(D+10),top:u.y-(D+10),width:(D+10)*2,height:(D+10)*2,zIndex:vc.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:_=>{const S=_.currentTarget.nextElementSibling;if(S){const N=S.querySelector(".error-message");N&&(N.style.opacity="1")}},onMouseLeave:_=>{if(!C){const S=_.currentTarget.nextElementSibling;if(S){const N=S.querySelector(".error-message");N&&(N.style.opacity="0")}}}}),W.jsx("div",{style:{position:"absolute",zIndex:C?vc.errorOverlay+20:vc.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:W.jsx("div",{className:`error-message ${FmA}`,style:{opacity:C?1:0,border:`1px solid ${C?"#ff4444":"red"}`},children:g.message})})]},`${B}_${h}`)})})]})};function rii(t,A){return t.size!==A.size?!1:Array.from(t).every(e=>A.has(e))}function aii({primitiveElement:t,elements:A}){let e=t.trace_length?`${t.trace_length.toFixed(3)}`:"";const i=rx(A).source_trace.get(t?.source_trace_id);if(i?.display_name&&(i?.max_length?e+=` / ${i.max_length}mm `:e+=" mm ",e+=`(${i.display_name})`),!e)return null;const n=t.trace_length&&i?.max_length&&t.trace_length>i.max_length;return{text:e,isOverLength:n}}function gii(t){const{primitives:A,is_showing_multiple_traces_length:e,elements:i}=t,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(!e)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 cii={position:"absolute",left:0,top:0,pointerEvents:"none",color:"red",fontFamily:"sans-serif",fontSize:12,textShadow:"0 0 2px black"},Iii=t=>{const{_element:A,_parent_pcb_component:e,_parent_source_component:i,_source_port:n}=t;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""}},lii={top:"red",bottom:"aqua"},Bii=({primitive:t,mousePos:A,elements:e})=>{const[i,n]=V.useState(!1),o=t._element;V.useEffect(()=>{setTimeout(()=>{n(!0)},100)},[]);const[s,r,a,g]=[t.screen_x,t.screen_y,t.screen_w,t.screen_h],c=t.same_space_index??0,I=26,l=lii[t?._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 t||o.type==="pcb_plated_hole"&&(o?.shape==="pill"||o?.shape==="oval")&&"ccw_rotation"in t)&&(B=o.ccw_rotation??0),o.type==="pcb_trace"){const h=aii({primitiveElement:o,elements:e});if(!h)return null;const E=A.y-35;return W.jsx("div",{style:{zIndex:vc.elementOverlay,position:"absolute",left:A.x,top:E,color:l,pointerEvents:"none",transform:"translateX(-50%)"},children:W.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=Iii(t);return C.trim().length===0?null:W.jsx("div",{style:{zIndex:vc.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:W.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:W.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})})})},Cii=({highlightedPrimitives:t,mousePos:A,elements:e})=>{const[i,n]=gl(r=>[r.is_moving_component,r.is_showing_multiple_traces_length]),o=t.some(r=>r._element.type==="pcb_smtpad")&&t.some(r=>r._element.type==="pcb_trace");let s=t;return o&&(s=s.filter(r=>r._element.type==="pcb_smtpad")),s=gii({primitives:s,is_showing_multiple_traces_length:n,elements:e}),W.jsx("div",{style:cii,children:!i&&s.map((r,a)=>W.jsx(Bii,{primitive:r,mousePos:A,elements:e},a))})},Pb=t=>t?.type==="pcb_component",y0e=t=>t?.type==="pcb_group",Qii=t=>t?.type==="pcb_panel",MmA=t=>t?.type==="pcb_board",gI={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},ly={OFFSET_LINE:"white",COMPONENT_MARKER_FILL:"#66ccff",COMPONENT_MARKER_STROKE:"white",LABEL_TEXT:"white"},RmA=({targets:t,transform:A,containerWidth:e,containerHeight:i})=>{if(t.length===0)return null;const n={color:ly.LABEL_TEXT,mixBlendMode:"difference",pointerEvents:"none",fontSize:gI.LABEL_FONT_SIZE,fontFamily:"monospace",fontWeight:"bold"},o=new Map;return t.forEach(s=>{if(!o.has(s.anchor_id)){const r=Ce(A,s.anchor);o.set(s.anchor_id,r)}}),W.jsx("div",{style:{position:"absolute",left:0,top:0,width:e,height:i,overflow:"hidden",pointerEvents:"none",zIndex:vc.dimensionOverlay},children:W.jsxs("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none"},width:e,height:i,children:[t.map(s=>{const r=s.anchor,a=s.anchor_id,g=s.target,c=o.get(a),I=Ce(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?gI.LABEL_OFFSET_ABOVE:gI.LABEL_OFFSET_BELOW,d=E?gI.LABEL_OFFSET_RIGHT:gI.LABEL_OFFSET_LEFT,p=C>gI.MIN_LINE_LENGTH_FOR_LABEL,y=Q>gI.MIN_LINE_LENGTH_FOR_LABEL,w=`${s.display_offset_x??l.toFixed(2)}mm`,D=`${s.display_offset_y??B.toFixed(2)}mm`;return W.jsxs("g",{children:[W.jsx("line",{x1:c.x,y1:c.y,x2:I.x,y2:c.y,stroke:ly.OFFSET_LINE,strokeWidth:gI.LINE_STROKE_WIDTH,strokeDasharray:gI.LINE_DASH_PATTERN}),W.jsx("line",{x1:I.x,y1:c.y,x2:I.x,y2:I.y,stroke:ly.OFFSET_LINE,strokeWidth:gI.LINE_STROKE_WIDTH,strokeDasharray:gI.LINE_DASH_PATTERN}),s.type==="component"||s.type==="board"?W.jsx("circle",{cx:I.x,cy:I.y,r:gI.COMPONENT_MARKER_RADIUS,fill:ly.COMPONENT_MARKER_FILL,stroke:ly.COMPONENT_MARKER_STROKE,strokeWidth:1}):W.jsxs(W.Fragment,{children:[W.jsx("line",{x1:I.x-gI.ANCHOR_MARKER_SIZE,y1:I.y,x2:I.x+gI.ANCHOR_MARKER_SIZE,y2:I.y,stroke:ly.OFFSET_LINE,strokeWidth:gI.ANCHOR_MARKER_STROKE_WIDTH}),W.jsx("line",{x1:I.x,y1:I.y-gI.ANCHOR_MARKER_SIZE,x2:I.x,y2:I.y+gI.ANCHOR_MARKER_SIZE,stroke:ly.OFFSET_LINE,strokeWidth:gI.ANCHOR_MARKER_STROKE_WIDTH})]}),p&&W.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:W.jsx("div",{style:{...n,textAlign:"center"},children:w})}),y&&W.jsx("foreignObject",{x:I.x+d,y:Math.min(c.y,I.y),width:gI.Y_LABEL_MIN_WIDTH,height:Math.abs(I.y-c.y),style:{overflow:"visible"},children:W.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])=>W.jsxs("g",{children:[W.jsx("line",{x1:r.x-gI.ANCHOR_MARKER_SIZE,y1:r.y,x2:r.x+gI.ANCHOR_MARKER_SIZE,y2:r.y,stroke:ly.OFFSET_LINE,strokeWidth:gI.ANCHOR_MARKER_STROKE_WIDTH}),W.jsx("line",{x1:r.x,y1:r.y-gI.ANCHOR_MARKER_SIZE,x2:r.x,y2:r.y+gI.ANCHOR_MARKER_SIZE,stroke:ly.OFFSET_LINE,strokeWidth:gI.ANCHOR_MARKER_STROKE_WIDTH})]},`anchor-${s}`))]})})},hii=({elements:t,highlightedPrimitives:A,transform:e,containerWidth:i,containerHeight:n})=>{const o=t.filter(E=>MmA(E)),s=t.filter(E=>Pb(E)),r=t.filter(E=>y0e(E)),a=A.map(E=>Pb(E._parent_pcb_component)?E._parent_pcb_component.pcb_component_id:Pb(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)}),!gl(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(p=>p.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(p=>p.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 W.jsx(RmA,{targets:h,transform:e,containerWidth:i,containerHeight:n})},Eii=({elements:t,highlightedPrimitives:A,transform:e,containerWidth:i,containerHeight:n})=>{const o=t.filter(E=>y0e(E)),s=t.filter(E=>Pb(E)),r=A.map(E=>Pb(E._parent_pcb_component)?E._parent_pcb_component.pcb_component_id:Pb(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(p=>p.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))}),!gl(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 W.jsx(RmA,{targets:h,transform:e,containerWidth:i,containerHeight:n})},uii=(t,A)=>{const e=t.pcb_component_id,i=A.filter(n=>(n.type==="pcb_smtpad"||n.type==="pcb_plated_hole")&&n.pcb_component_id===e||n.type==="pcb_hole"&&n.pcb_component_id===e);return i.length===0?_mA([t]):_mA(i)},dii=({elements:t,highlightedPrimitives:A,transform:e,containerWidth:i,containerHeight:n})=>{const o=new Map;for(const r of A)Pb(r._parent_pcb_component)&&o.set(r._parent_pcb_component.pcb_component_id,r._parent_pcb_component),Pb(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=uii(r,t);if(!a)continue;const g=r.positioned_relative_to_pcb_group_id??r.pcb_group_id,c=g?rx(t).pcb_group.get(g):null;s.push({component:r,bbox:a,group:c})}return s.length===0?null:W.jsx("div",{style:{position:"absolute",left:0,top:0,width:i,height:n,overflow:"hidden",pointerEvents:"none",zIndex:vc.dimensionOverlay},children:W.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=Ce(e,{x:a.minX,y:a.maxY}),I=Ce(e,{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=Ce(e,B);return W.jsxs("g",{children:[W.jsx("rect",{x:l.x,y:l.y,width:l.width,height:l.height,fill:"none",stroke:"white",strokeWidth:1.5,strokeDasharray:"4,4"}),W.jsx("line",{x1:C.x-6,y1:C.y,x2:C.x+6,y2:C.y,stroke:ly.COMPONENT_MARKER_STROKE,strokeWidth:1.5}),W.jsx("line",{x1:C.x,y1:C.y-6,x2:C.x,y2:C.y+6,stroke:ly.COMPONENT_MARKER_STROKE,strokeWidth:1.5}),W.jsx("circle",{cx:C.x,cy:C.y,r:gI.COMPONENT_MARKER_RADIUS,fill:ly.COMPONENT_MARKER_FILL,stroke:ly.COMPONENT_MARKER_STROKE,strokeWidth:1})]},r.pcb_component_id)})})})},pii=({elements:t,highlightedPrimitives:A,transform:e,containerWidth:i,containerHeight:n})=>{const o=t.filter(B=>Qii(B)),s=t.filter(B=>MmA(B)),r=A.map(B=>MmA(B._element)?B._element.pcb_board_id:null).filter(B=>!!B);if(!gl(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 W.jsx(RmA,{targets:l,transform:e,containerWidth:i,containerHeight:n})},HV=t=>{if(t.length===0)return null;let A=t[0].x,e=t[0].y,i=t[0].x,n=t[0].y;for(const o of t)o.x<A&&(A=o.x),o.y<e&&(e=o.y),o.x>i&&(i=o.x),o.y>n&&(n=o.y);return{center:{x:(A+i)/2,y:(e+n)/2},width:i-A,height:n-e}},m0e=(t,A)=>{if(A.length<3)return!1;let e=!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>t.y!=a>t.y&&t.x<(r-o)*(t.y-s)/(a-s||Number.EPSILON)+o&&(e=!e)}return e},fii=(t,A,e)=>{const i=[];for(const n of t){if(!n._element)continue;if("x1"in n&&n._element?.type==="pcb_trace"){const r=J0({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)/e.a;r<g&&i.push(n);continue}if(n.pcb_drawing_type==="polygon"){const r=n.points.map(g=>({x:pt.parse(g.x),y:pt.parse(g.y)})),a=HV(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;m0e(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:pt.parse(g.x),y:pt.parse(g.y)})),a=HV(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;m0e(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},yii=({elements:t,children:A,transform:e,primitives:i,onMouseHoverOverPrimitives:n})=>{const[o,s]=V.useState([]),[r,a]=V.useState({x:0,y:0}),[g,{width:c,height:I}]=VL(),l=V.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=HV(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=HV(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=Ce(e,h),p={w:E*e.a,h:u*e.a},y=C.filter(w=>d.x===w.screen_x&&d.y===w.screen_y&&p.w===w.screen_w&&p.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:p.w,screen_h:p.h,same_space_index:y})}return C},[o,e]),B=(C,Q,h,E)=>{a({x:C,y:Q});const u=Ce(tm(h),{x:C,y:Q}),d=fii(E,u,h);rii(new Set(d.map(p=>p._pcb_drawing_object_id)),new Set(o.map(p=>p._pcb_drawing_object_id)))||(s(d),n(d))};return W.jsxs("div",{ref:g,style:{position:"relative",width:"100%",height:"100%"},onMouseMove:C=>{if(e){const Q=C.currentTarget.getBoundingClientRect(),h=C.clientX-Q.left,E=C.clientY-Q.top;B(h,E,e,i)}},onTouchStart:C=>{if(e){const Q=C.touches[0],h=C.currentTarget.getBoundingClientRect(),E=Q.clientX-h.left,u=Q.clientY-h.top;B(E,u,e,i)}},children:[A,W.jsx(Cii,{elements:t,mousePos:r,highlightedPrimitives:l}),e&&W.jsxs(W.Fragment,{children:[W.jsx(hii,{elements:t,highlightedPrimitives:l,transform:e,containerWidth:c,containerHeight:I}),W.jsx(Eii,{elements:t,highlightedPrimitives:l,transform:e,containerWidth:c,containerHeight:I}),W.jsx(dii,{elements:t,highlightedPrimitives:l,transform:e,containerWidth:c,containerHeight:I}),W.jsx(pii,{elements:t,highlightedPrimitives:l,transform:e,containerWidth:c,containerHeight:I})]})]})},w0e=["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)"],mii=({children:t,transform:A=ba(),elements:e=[],hoveredComponentIds:i=[]})=>{const[n,{width:o,height:s}]=VL(),r=V.useRef(null),{is_showing_pcb_groups:a,pcb_group_view_mode:g,is_showing_group_anchor_offsets:c}=gl(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 V.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=e.filter(w=>w.type==="pcb_group"),C=e.filter(w=>w.type==="pcb_component"),Q=e.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},p=w=>{const D=Q.find(x=>x.source_group_id===w);return D?.parent_source_group_id?1+p(D.parent_source_group_id):0},y=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&&y.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),WA=B.filter(vA=>vA.source_group_id&&TA.includes(vA.source_group_id));for(const vA of WA){const wA=C.filter(RA=>RA.pcb_group_id===vA.pcb_group_id);x=[...x,...wA]}}let _,S,N,F,L=!1;if(w.center&&w.width&&w.height){L=!0;const TA=w.width/2,WA=w.height/2;_=w.center.x-TA,N=w.center.x+TA,S=w.center.y-WA,F=w.center.y+WA}else if(x.length===0||(_=1/0,S=1/0,N=-1/0,F=-1/0,x.forEach(TA=>{if(TA.center&&typeof TA.width=="number"&&typeof TA.height=="number"){const WA=TA.center.x-TA.width/2,vA=TA.center.x+TA.width/2,wA=TA.center.y+TA.height/2,RA=TA.center.y-TA.height/2;_=Math.min(_,WA),N=Math.max(N,vA),S=Math.min(S,RA),F=Math.max(F,wA)}}),_===1/0||N===-1/0))return;const Y=w.source_group_id?p(w.source_group_id):0,J=w.source_group_id?d(w.source_group_id).length>0:!1;if(!L){const vA=1+(J?.5:0);_-=vA,N+=vA,S-=vA,F+=vA}const q=Ce(A,{x:_,y:F}),Z=Ce(A,{x:N,y:F}),X=Ce(A,{x:_,y:S}),eA=Ce(A,{x:N,y:S}),gA=w0e[D%w0e.length];l.strokeStyle=gA,l.lineWidth=2;const tA=Math.max(4,Math.min(12,8*Math.abs(A.a))),iA=Math.max(2,Math.min(6,4*Math.abs(A.a))),aA=tA*(J?1.3:1),EA=iA;l.setLineDash([aA,EA]),l.beginPath(),l.moveTo(q.x,q.y),l.lineTo(Z.x,Z.y),l.lineTo(eA.x,eA.y),l.lineTo(X.x,X.y),l.closePath(),l.stroke();const SA=Math.max(8,Math.min(12,10*Math.abs(A.a))),_A=Y==0||Y==1?0:Y*.11,LA=SA*(1-_A),QA=4,kA=w.name||`Group ${D+1}`;l.font=`${LA}px sans-serif`,l.setLineDash([]);const qA=l.measureText(kA).width+QA*2,VA=LA+QA*2,ce=q.x-5,fA=q.y-5,ge=3;if(l.fillStyle="rgba(0, 0, 0, 0.8)",l.beginPath(),l.roundRect(ce,fA-VA,qA,VA,ge),l.fill(),l.fillStyle=gA,l.textAlign="left",l.textBaseline="middle",l.fillText(kA,ce+QA,fA-VA/2),c&&y.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},WA=Ce(A,TA);l.strokeStyle="white",l.lineWidth=1.5,l.setLineDash([]);const vA=Math.max(4,Math.min(8,6*Math.abs(A.a)));l.beginPath(),l.moveTo(WA.x-vA,WA.y),l.lineTo(WA.x+vA,WA.y),l.stroke(),l.beginPath(),l.moveTo(WA.x,WA.y-vA),l.lineTo(WA.x,WA.y+vA),l.stroke()}})},[e,A,o,s,a,g,c,i]),W.jsxs("div",{ref:n,style:{position:"relative",width:"100%",height:"100%"},children:[t,W.jsx("canvas",{ref:r,style:{position:"absolute",top:0,left:0,pointerEvents:"none",zIndex:vc.pcbGroupOverlay,display:a?"block":"none"}})]})},wii=({transform:t,soup:A,children:e})=>{const i=gl(r=>r.is_showing_rats_nest),{netMap:n,idToNetMap:o}=V.useMemo(()=>e0e(A||[]),[A]),s=V.useMemo(()=>{if(!A||!i)return[];const r=l=>{const B=rx(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=rx(A).pcb_port.list(),c=rx(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?e:(t||(t=ba()),W.jsxs("div",{style:{position:"relative"},children:[e,W.jsx("svg",{style:{position:"absolute",left:0,top:0,width:"100%",height:"100%",pointerEvents:"none",opacity:.5,zIndex:vc.ratsNestOverlay},children:s.map(({key:r,startPoint:a,endPoint:g,isInNet:c})=>{const I=Ce(t,a),l=Ce(t,g);return W.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)})})]}))},Dii={version:"1.11.358"},Kb=(t,A,e)=>{const i=gl(s=>s.is_mouse_over_container),n=V.useRef(i),o=V.useRef(A);V.useEffect(()=>{n.current=i},[i]),V.useEffect(()=>{o.current=A},[A]),V.useEffect(()=>{if(!t)return;const s=r=>{const a=r.target;if(a.tagName==="INPUT"||a.tagName==="TEXTAREA"||a.isContentEditable)return;const g=t.split("+"),c=g.includes("ctrl"),I=g.includes("shift"),l=g.includes("alt"),B=g.includes("meta"),C=g[g.length-1],Q=e?.current?e.current.contains(document.activeElement)||document.activeElement===e.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)}},[t])},xii=()=>{const[t,A]=V.useState(!1);return V.useEffect(()=>{const e=()=>{A(window.innerWidth<=768)};return e(),window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[]),t},zL=(t,A={stopPropagation:!0})=>{const e=V.useRef(0),i=V.useCallback(s=>{A.stopPropagation&&s.stopPropagation();const r=Date.now();r-e.current<300||(e.current=r,t?.(s))},[t,A.stopPropagation]),n=V.useCallback(s=>{s.preventDefault(),i(s)},[i]);return{onClick:i,onTouchEnd:n,style:{touchAction:"manipulation"}}},Sii=({name:t,selected:A,onClick:e})=>{const{style:i,...n}=zL(e);return W.jsxs("div",{className:xM`
|
|
5476
5476
|
margin-top: 2px;
|
|
5477
5477
|
padding: 4px;
|
|
5478
5478
|
padding-left: 8px;
|
|
@@ -5689,7 +5689,7 @@ test("${g} should solve problem correctly", () => {
|
|
|
5689
5689
|
// Add more specific assertions based on expected output
|
|
5690
5690
|
// expect(solver.netLabelPlacementSolver!.netLabelPlacements).toMatchInlineSnapshot()
|
|
5691
5691
|
})
|
|
5692
|
-
`,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 ${t.constructor.name}: ${a instanceof Error?a.message:String(a)}`)}i(!1)};return W.jsxs("div",{className:`relative ${A}`,ref:n,children:[W.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>i(!e),title:`Download options for ${t.constructor.name}`,children:t.constructor.name}),e&&W.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:[W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:o,children:"Download JSON"}),W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:r,children:"Download test.ts"})]})]})},M0e=t=>t.activeSubSolver?[t,...M0e(t.activeSubSolver)]:[t],Aoi=({solver:t})=>{const A=M0e(t);return W.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:A.map((e,i)=>W.jsxs("div",{className:"flex items-center",children:[i>0&&W.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),W.jsx($ni,{solver:e})]},e.constructor.name))})},eoi=({solver:t,triggerRender:A,animationSpeed:e=25,onSolverStarted:i,onSolverCompleted:n})=>{const[o,s]=V.useReducer(Q=>!Q,!1),r=V.useRef(void 0),a=()=>{!t.solved&&!t.failed&&(t.step(),A())},g=()=>{!t.solved&&!t.failed&&(i&&i(t),t.solve(),A(),n&&n(t))},c=()=>{o?(r.current&&(clearInterval(r.current),r.current=void 0),s()):(s(),r.current=setInterval(()=>{if(t.solved||t.failed){r.current&&(clearInterval(r.current),r.current=void 0),s(),A(),n&&t.solved&&n(t);return}t.step(),A()},e))},I=()=>{const Q=t;if(Q.getCurrentPhase&&!t.solved&&!t.failed){const h=Q.getCurrentPhase();for(;Q.getCurrentPhase()===h&&!t.solved&&!t.failed;)t.step();A()}},l=()=>{if(t.solved||t.failed||o)return;const Q=window.prompt("Step until which iteration?",`${t.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(;t.iterations<h&&!t.solved&&!t.failed;)t.step();A(),t.solved&&n&&n(t)};V.useEffect(()=>()=>{r.current&&clearInterval(r.current)},[]),V.useEffect(()=>{(t.solved||t.failed)&&o&&(r.current&&(clearInterval(r.current),r.current=void 0),s())},[t.solved,t.failed,o]);const B=t.getCurrentPhase!==void 0,C=B?t.getCurrentPhase():null;return W.jsxs("div",{className:"space-y-2 p-2 border-b",children:[W.jsx("div",{className:"flex items-center",children:W.jsx(Aoi,{solver:t})}),W.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[W.jsx("button",{onClick:a,disabled:t.solved||t.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"}),W.jsx("button",{onClick:g,disabled:t.solved||t.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"}),W.jsx("button",{onClick:c,disabled:t.solved||t.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"}),W.jsx("button",{onClick:l,disabled:t.solved||t.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&&W.jsx("button",{onClick:I,disabled:t.solved||t.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"}),W.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",t.iterations]}),t.timeToSolve!==void 0&&W.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(t.timeToSolve/1e3).toFixed(3),"s"]}),C&&W.jsxs("div",{className:"text-sm text-gray-600",children:["Phase: ",W.jsx("span",{className:"font-medium",children:C})]}),t.solved&&W.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),t.failed&&W.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),t.error&&W.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",t.error]})]})},toi=(t,A,e)=>{const i=t.currentPipelineStepIndex;return A<i?"Completed":A===i&&t.activeSubSolver?t.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},ioi=(t,A)=>{const i=t.pipelineDef[A].solverName,n=toi(t,A),o=t[i],s=t.firstIterationOfPhase?.[i]??null,r=t.iterations;let a=0;if(n==="Completed"){const l=t.pipelineDef[A+1],B=l?t.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=t.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}},noi=({status:t})=>{const A={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return W.jsx("span",{className:`font-medium ${A[t]}`,children:t})},ooi=({progress:t})=>{if(t===0)return null;const A=Math.round(t*100);return W.jsxs("div",{className:"flex items-center gap-2",children:[W.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:W.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${A}%`}})}),W.jsxs("span",{className:"text-xs text-gray-500",children:[A,"%"]})]})},soi=t=>Object.entries(t).map(([A,e])=>`${A}: ${e}`).join(", "),roi=({stats:t})=>{if(!t||Object.keys(t).length===0)return W.jsx("span",{children:"-"});const A=Object.entries(t),e=soi(t);return W.jsxs("details",{className:"cursor-pointer",children:[W.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:e}),W.jsx("div",{className:"mt-1 text-xs",children:A.map(([i,n])=>W.jsxs("div",{children:[i,": ",String(n)]},i))})]})},TmA=t=>{if(t===null||typeof t!="object")return t;if(Array.isArray(t))return t.map(TmA);const A={};for(const[e,i]of Object.entries(t))e.startsWith("_")||(A[e]=TmA(i));return A},aoi=(t,A)=>{try{if(typeof t.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${A}`);return}const e=TmA(t.getConstructorParams()),i=new Blob([JSON.stringify(e,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(e){alert(`Error downloading input for ${A}: ${e instanceof Error?e.message:String(e)}`)}},goi=({solver:t,onStepUntilPhase:A,onDownloadInput:e})=>{const i=t.pipelineDef.map((r,a)=>ioi(t,a)),n=r=>{A?.(r)},o=r=>{r.solverInstance&&(e?e(r.solverInstance,r.name):aoi(r.solverInstance,r.name))},s=r=>`${(r/1e3).toFixed(2)}s`;return W.jsxs("div",{className:"border-t border-gray-200",children:[W.jsx("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200",children:W.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Steps"})}),W.jsx("div",{className:"overflow-x-auto",children:W.jsxs("table",{className:"w-full text-sm",children:[W.jsx("thead",{children:W.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Step"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),W.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",W.jsx("sub",{children:"0"})]}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),W.jsx("tbody",{children:i.map(r=>W.jsxs("tr",{className:`border-b border-gray-100 ${r.status==="In Progress"?"bg-yellow-50":""}`,children:[W.jsx("td",{className:"px-4 py-2",children:W.jsxs("div",{className:"flex items-center gap-2",children:[W.jsx("span",{className:"text-gray-400 w-6",children:String(r.index+1).padStart(2,"0")}),W.jsx("button",{onClick:()=>n(r.name),disabled:r.status==="Completed"||t.solved||t.failed,className:"text-blue-500 hover:text-blue-700 disabled:text-gray-300 disabled:cursor-not-allowed",title:`Step until ${r.name} completes`,children:W.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:W.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"})})}),W.jsx("span",{className:"font-medium text-gray-900",children:r.name})]})}),W.jsx("td",{className:"px-4 py-2",children:W.jsx(noi,{status:r.status})}),W.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:r.firstIteration!==null?r.firstIteration:""}),W.jsx("td",{className:"px-4 py-2 text-gray-600",children:r.iterations}),W.jsx("td",{className:"px-4 py-2",children:W.jsx(ooi,{progress:r.progress})}),W.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(r.timeSpent)}),W.jsx("td",{className:"px-4 py-2 text-gray-500",children:W.jsx(roi,{stats:r.stats})}),W.jsx("td",{className:"px-4 py-2",children:r.solverInstance?W.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:[W.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:W.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"})}),W.jsx("span",{children:"Input"})]}):null})]},r.name))})]})})]})},coi=class extends Qn.Component{constructor(t){super(t),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(t){console.error("InteractiveGraphics render error:",t)}render(){return this.state.hasError?this.props.fallback:this.props.children}};function Ioi({graphics:t}){const A=t.points??[],e=t.lines??[],i=t.rects??[],n=t.circles??[],o=t.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 e){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,p=h.height??0;c(E,u),c(E+d,u+p)}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 W.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)=>W.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}`)),e.map((h,E)=>W.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)=>W.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)=>W.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)=>W.jsx("text",{x:h.x??0,y:h.y??0,fontSize:h.fontSize??10,fill:h.color??"black",children:h.text??""},`text-${E}`))]})}var loi=({solver:t,animationSpeed:A=25,onSolverStarted:e,onSolverCompleted:i})=>{const[n,o]=V.useReducer(c=>c+1,0),s=V.useMemo(()=>{try{return t.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(c){return console.error("Visualization error:",c),{points:[],lines:[],rects:[],circles:[]}}},[t,n]),r=V.useMemo(()=>(s.rects?.length||0)===0&&(s.lines?.length||0)===0&&(s.points?.length||0)===0&&(s.circles?.length||0)===0,[s]);V.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=t.pipelineDef!==void 0,g=c=>{const I=t;if(!t.solved&&!t.failed){for(;!t.solved&&!t.failed&&I.currentPipelineStepIndex<=I.pipelineDef.findIndex(l=>l.solverName===c);)t.step();o()}};return W.jsxs("div",{children:[W.jsx(eoi,{solver:t,triggerRender:o,animationSpeed:A,onSolverStarted:e,onSolverCompleted:i}),r?W.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):W.jsx(coi,{fallback:W.jsx(Ioi,{graphics:s}),children:W.jsx(Xni,{graphics:s})}),a&&W.jsx(goi,{solver:t,onStepUntilPhase:g})]})};const Boi=()=>{V.useEffect(()=>{const t="tailwind-cdn-script";if(document.getElementById(t)||window.tailwind)return;const A=document.createElement("div");A.className="hidden",document.body.appendChild(A);const e=window.getComputedStyle(A).display==="none";if(document.body.removeChild(A),e)return;const i=document.createElement("script");i.id=t,i.src="https://cdn.tailwindcss.com",document.head.appendChild(i)},[])},Coi=t=>t.toLowerCase().includes("pack")?VHt:t.toLowerCase().includes("rout")?AYt:RHt,Qoi=({solverEvents:t=[]})=>{const[A,e]=V.useState(null);Boi();const i=V.useMemo(()=>{const r=new Map;for(const a of t){const g=`${a.componentName}-${a.solverName}`;r.set(g,a)}return r},[t]),n=V.useMemo(()=>Array.from(i.keys()),[i]),o=A?i.get(A):null,s=V.useMemo(()=>{if(!o)return{instance:null,error:null,classFound:!1};const r=$rA[o.solverName];if(!r)return{instance:null,error:`Solver class "${o.solverName}" not found in SOLVERS registry. Available: ${Object.keys($rA).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 t.length===0?W.jsx("div",{className:"rf-p-4",children:W.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:W.jsxs("div",{className:"rf-p-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),W.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."})]})})}):W.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[W.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[W.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 W.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:()=>e(r),children:(()=>{const c=Coi(a.solverName);return W.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[W.jsx(c,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),W.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[W.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:a.componentName}),W.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:a.solverName})]})]})})()},r)})]}),W.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:o?s.instance?W.jsx(xm,{fallback:W.jsx("div",{className:"rf-p-4",children:W.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),W.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",o.solverName]})]})}),children:W.jsx(loi,{solver:s.instance})}):W.jsxs("div",{className:"rf-p-4",children:[W.jsxs("div",{className:"rf-mb-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:o.solverName}),W.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",o.componentName]})]}),s.error&&W.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:W.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),W.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[W.jsx("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50",children:W.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"})}),W.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:W.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)})})]})]}):W.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:W.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},R0e=({errorMessage:t,errorStack:A,circuitJsonErrors:e})=>{V.useEffect(()=>{if(t){const i=new Error(t);A&&(i.stack=A);try{ZK.captureException(i)}catch{}}},[t,A]),V.useEffect(()=>{if(e&&e.length>0)for(const i of e){const n=new Error(i.message||"Circuit JSON Error");i.stack&&(n.stack=i.stack);try{ZK.captureException(n,{error_type:i.type})}catch{}}},[e])},N0e="0.0.1762",hoi={version:N0e},qV=VYA()(jYA(t=>({lastRunEvalVersion:void 0,setLastRunEvalVersion:A=>{t({lastRunEvalVersion:A})}}),{name:"runframe-runner-store"})),Eoi=t=>{const[A,e]=V.useState([]),[i,n]=V.useState(null),[o,s]=V.useState(""),[r,a]=Iv("eval-version-selection",null),g=qV(B=>B.setLastRunEvalVersion),c=qV(B=>B.lastRunEvalVersion);return V.useEffect(()=>{t&&fetch("https://data.jsdelivr.com/v1/package/npm/@tscircuit/eval").then(B=>B.json()).then(B=>{if(Array.isArray(B?.versions)){let C=[...B.versions];B.tags?.latest&&(n(B.tags.latest),C=C.filter(Q=>Q!==B.tags.latest)),e(C)}}).catch(()=>{})},[t]),V.useEffect(()=>{t&&(r?(window.TSCIRCUIT_LATEST_EVAL_VERSION=r,g(r)):i&&(window.TSCIRCUIT_LATEST_EVAL_VERSION=i,g(i)))},[t,r,i]),{versions:V.useMemo(()=>A.filter(B=>B.includes(o)).slice(0,50),[A,o]),latestVersion:i,lastRunEvalVersion:c,search:o,setSearch:s,selectVersion:B=>{a(B),s("")}}},uoi=({snippetNames:t,onSelect:A,onCancel:e,isOpen:i})=>{const[n,o]=V.useState(""),[s,r]=V.useState("");if(!i)return null;const a=t.filter(I=>I.toLowerCase().includes(s.toLowerCase())),g=s&&!t.includes(s),c=I=>{I.key==="Enter"&&(a.length===1?o(a[0]):g&&o(s))};return W.jsx("div",{className:"rf-fixed rf-inset-0 rf-bg-black rf-bg-opacity-50 rf-flex rf-items-center rf-justify-center rf-z-[100]",children:W.jsxs("div",{className:"rf-bg-white rf-rounded-lg rf-p-6 rf-w-96",children:[W.jsx("h2",{className:"rf-text-lg rf-font-semibold rf-mb-4",children:"Select Snippet"}),W.jsx("input",{type:"text",className:"rf-w-full rf-px-4 rf-py-2 rf-border rf-rounded rf-mb-4",placeholder:"Search snippets or new snippet name...",value:s,onChange:I=>r(I.target.value),onKeyDown:c}),W.jsxs("div",{className:"rf-h-60 rf-overflow-y-auto",children:[a.map(I=>W.jsx("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 ${n===I?"bg-blue-50":""}`,onClick:()=>o(I),children:I},I)),g&&W.jsxs("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 text-blue-500 ${n===s?"bg-blue-50":""}`,onClick:()=>o(s),children:['Create new "',s,'"']})]}),W.jsxs("div",{className:"rf-mt-4 rf-flex rf-justify-end rf-gap-2",children:[W.jsx("button",{type:"button",className:"rf-px-4 rf-py-2 rf-text-gray-600 rf-hover:text-gray-800",onClick:e,children:"Cancel"}),W.jsx("button",{type:"button",className:"rf-px-4 rf-py-2 rf-bg-blue-500 rf-text-white rf-rounded rf-hover:bg-blue-600 rf-disabled:opacity-50",onClick:()=>n&&A(n),disabled:!n,children:n===s?`Create "${n}"`:`Save to ${n}`})]})]})})},doi=t=>{const A=V.useRef(null),e=MI(i=>i.recentEvents);V.useEffect(()=>{if(e.length===0)return;const i=e[0];i.event_id!==A.current&&(t(i),A.current=i.event_id)},[e,t])};function poi(t){const A=foi(t),e=V.forwardRef((i,n)=>{const{children:o,...s}=i,r=V.Children.toArray(o),a=r.find(moi);if(a){const g=a.props.children,c=r.map(I=>I===a?V.Children.count(g)>1?V.Children.only(null):V.isValidElement(g)?g.props.children:null:I);return W.jsx(A,{...s,ref:n,children:V.isValidElement(g)?V.cloneElement(g,void 0,c):null})}return W.jsx(A,{...s,ref:n,children:o})});return e.displayName=`${t}.Slot`,e}function foi(t){const A=V.forwardRef((e,i)=>{const{children:n,...o}=e;if(V.isValidElement(n)){const s=Doi(n),r=woi(o,n.props);return n.type!==V.Fragment&&(r.ref=i?vp(i,s):s),V.cloneElement(n,r)}return V.Children.count(n)>1?V.Children.only(null):null});return A.displayName=`${t}.SlotClone`,A}var yoi=Symbol("radix.slottable");function moi(t){return V.isValidElement(t)&&typeof t.type=="function"&&"__radixId"in t.type&&t.type.__radixId===yoi}function woi(t,A){const e={...A};for(const i in A){const n=t[i],o=A[i];/^on[A-Z]/.test(i)?n&&o?e[i]=(...r)=>{const a=o(...r);return n(...r),a}:n&&(e[i]=n):i==="style"?e[i]={...n,...o}:i==="className"&&(e[i]=[n,o].filter(Boolean).join(" "))}return{...t,...e}}function Doi(t){let A=Object.getOwnPropertyDescriptor(t.props,"ref")?.get,e=A&&"isReactWarning"in A&&A.isReactWarning;return e?t.ref:(A=Object.getOwnPropertyDescriptor(t,"ref")?.get,e=A&&"isReactWarning"in A&&A.isReactWarning,e?t.props.ref:t.props.ref||t.ref)}var OV="Dialog",[G0e,L0e]=dw(OV),[xoi,Ow]=G0e(OV),U0e=t=>{const{__scopeDialog:A,children:e,open:i,defaultOpen:n,onOpenChange:o,modal:s=!0}=t,r=V.useRef(null),a=V.useRef(null),[g,c]=GS({prop:i,defaultProp:n??!1,onChange:o,caller:OV});return W.jsx(xoi,{scope:A,triggerRef:r,contentRef:a,contentId:W0(),titleId:W0(),descriptionId:W0(),open:g,onOpenChange:c,onOpenToggle:V.useCallback(()=>c(I=>!I),[c]),modal:s,children:e})};U0e.displayName=OV;var H0e="DialogTrigger",Y0e=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,n=Ow(H0e,e),o=RI(A,n.triggerRef);return W.jsx(Ag.button,{type:"button","aria-haspopup":"dialog","aria-expanded":n.open,"aria-controls":n.contentId,"data-state":qmA(n.open),...i,ref:o,onClick:Vn(t.onClick,n.onOpenToggle)})});Y0e.displayName=H0e;var PmA="DialogPortal",[Soi,J0e]=G0e(PmA,{forceMount:void 0}),T0e=t=>{const{__scopeDialog:A,forceMount:e,children:i,container:n}=t,o=Ow(PmA,A);return W.jsx(Soi,{scope:A,forceMount:e,children:V.Children.map(i,s=>W.jsx(qf,{present:e||o.open,children:W.jsx(nZ,{asChild:!0,container:n,children:s})}))})};T0e.displayName=PmA;var WV="DialogOverlay",P0e=V.forwardRef((t,A)=>{const e=J0e(WV,t.__scopeDialog),{forceMount:i=e.forceMount,...n}=t,o=Ow(WV,t.__scopeDialog);return o.modal?W.jsx(qf,{present:i||o.open,children:W.jsx(_oi,{...n,ref:A})}):null});P0e.displayName=WV;var boi=poi("DialogOverlay.RemoveScroll"),_oi=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,n=Ow(WV,e);return W.jsx(lZ,{as:boi,allowPinchZoom:!0,shards:[n.contentRef],children:W.jsx(Ag.div,{"data-state":qmA(n.open),...i,ref:A,style:{pointerEvents:"auto",...i.style}})})}),K3="DialogContent",K0e=V.forwardRef((t,A)=>{const e=J0e(K3,t.__scopeDialog),{forceMount:i=e.forceMount,...n}=t,o=Ow(K3,t.__scopeDialog);return W.jsx(qf,{present:i||o.open,children:o.modal?W.jsx(koi,{...n,ref:A}):W.jsx(voi,{...n,ref:A})})});K0e.displayName=K3;var koi=V.forwardRef((t,A)=>{const e=Ow(K3,t.__scopeDialog),i=V.useRef(null),n=RI(A,e.contentRef,i);return V.useEffect(()=>{const o=i.current;if(o)return ofA(o)},[]),W.jsx(q0e,{...t,ref:n,trapFocus:e.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:Vn(t.onCloseAutoFocus,o=>{o.preventDefault(),e.triggerRef.current?.focus()}),onPointerDownOutside:Vn(t.onPointerDownOutside,o=>{const s=o.detail.originalEvent,r=s.button===0&&s.ctrlKey===!0;(s.button===2||r)&&o.preventDefault()}),onFocusOutside:Vn(t.onFocusOutside,o=>o.preventDefault())})}),voi=V.forwardRef((t,A)=>{const e=Ow(K3,t.__scopeDialog),i=V.useRef(!1),n=V.useRef(!1);return W.jsx(q0e,{...t,ref:A,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:o=>{t.onCloseAutoFocus?.(o),o.defaultPrevented||(i.current||e.triggerRef.current?.focus(),o.preventDefault()),i.current=!1,n.current=!1},onInteractOutside:o=>{t.onInteractOutside?.(o),o.defaultPrevented||(i.current=!0,o.detail.originalEvent.type==="pointerdown"&&(n.current=!0));const s=o.target;e.triggerRef.current?.contains(s)&&o.preventDefault(),o.detail.originalEvent.type==="focusin"&&n.current&&o.preventDefault()}})}),q0e=V.forwardRef((t,A)=>{const{__scopeDialog:e,trapFocus:i,onOpenAutoFocus:n,onCloseAutoFocus:o,...s}=t,r=Ow(K3,e),a=V.useRef(null),g=RI(A,a);return YpA(),W.jsxs(W.Fragment,{children:[W.jsx(qW,{asChild:!0,loop:!0,trapped:i,onMountAutoFocus:n,onUnmountAutoFocus:o,children:W.jsx(Z9,{role:"dialog",id:r.contentId,"aria-describedby":r.descriptionId,"aria-labelledby":r.titleId,"data-state":qmA(r.open),...s,ref:g,onDismiss:()=>r.onOpenChange(!1)})}),W.jsxs(W.Fragment,{children:[W.jsx(Moi,{titleId:r.titleId}),W.jsx(Noi,{contentRef:a,descriptionId:r.descriptionId})]})]})}),KmA="DialogTitle",O0e=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,n=Ow(KmA,e);return W.jsx(Ag.h2,{id:n.titleId,...i,ref:A})});O0e.displayName=KmA;var W0e="DialogDescription",Z0e=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,n=Ow(W0e,e);return W.jsx(Ag.p,{id:n.descriptionId,...i,ref:A})});Z0e.displayName=W0e;var V0e="DialogClose",j0e=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,n=Ow(V0e,e);return W.jsx(Ag.button,{type:"button",...i,ref:A,onClick:Vn(t.onClick,()=>n.onOpenChange(!1))})});j0e.displayName=V0e;function qmA(t){return t?"open":"closed"}var z0e="DialogTitleWarning",[Foi,X0e]=ngt(z0e,{contentName:K3,titleName:KmA,docsSlug:"dialog"}),Moi=({titleId:t})=>{const A=X0e(z0e),e=`\`${A.contentName}\` requires a \`${A.titleName}\` for the component to be accessible for screen reader users.
|
|
5692
|
+
`,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 ${t.constructor.name}: ${a instanceof Error?a.message:String(a)}`)}i(!1)};return W.jsxs("div",{className:`relative ${A}`,ref:n,children:[W.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>i(!e),title:`Download options for ${t.constructor.name}`,children:t.constructor.name}),e&&W.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:[W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:o,children:"Download JSON"}),W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:r,children:"Download test.ts"})]})]})},M0e=t=>t.activeSubSolver?[t,...M0e(t.activeSubSolver)]:[t],Aoi=({solver:t})=>{const A=M0e(t);return W.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:A.map((e,i)=>W.jsxs("div",{className:"flex items-center",children:[i>0&&W.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),W.jsx($ni,{solver:e})]},e.constructor.name))})},eoi=({solver:t,triggerRender:A,animationSpeed:e=25,onSolverStarted:i,onSolverCompleted:n})=>{const[o,s]=V.useReducer(Q=>!Q,!1),r=V.useRef(void 0),a=()=>{!t.solved&&!t.failed&&(t.step(),A())},g=()=>{!t.solved&&!t.failed&&(i&&i(t),t.solve(),A(),n&&n(t))},c=()=>{o?(r.current&&(clearInterval(r.current),r.current=void 0),s()):(s(),r.current=setInterval(()=>{if(t.solved||t.failed){r.current&&(clearInterval(r.current),r.current=void 0),s(),A(),n&&t.solved&&n(t);return}t.step(),A()},e))},I=()=>{const Q=t;if(Q.getCurrentPhase&&!t.solved&&!t.failed){const h=Q.getCurrentPhase();for(;Q.getCurrentPhase()===h&&!t.solved&&!t.failed;)t.step();A()}},l=()=>{if(t.solved||t.failed||o)return;const Q=window.prompt("Step until which iteration?",`${t.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(;t.iterations<h&&!t.solved&&!t.failed;)t.step();A(),t.solved&&n&&n(t)};V.useEffect(()=>()=>{r.current&&clearInterval(r.current)},[]),V.useEffect(()=>{(t.solved||t.failed)&&o&&(r.current&&(clearInterval(r.current),r.current=void 0),s())},[t.solved,t.failed,o]);const B=t.getCurrentPhase!==void 0,C=B?t.getCurrentPhase():null;return W.jsxs("div",{className:"space-y-2 p-2 border-b",children:[W.jsx("div",{className:"flex items-center",children:W.jsx(Aoi,{solver:t})}),W.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[W.jsx("button",{onClick:a,disabled:t.solved||t.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"}),W.jsx("button",{onClick:g,disabled:t.solved||t.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"}),W.jsx("button",{onClick:c,disabled:t.solved||t.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"}),W.jsx("button",{onClick:l,disabled:t.solved||t.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&&W.jsx("button",{onClick:I,disabled:t.solved||t.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"}),W.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",t.iterations]}),t.timeToSolve!==void 0&&W.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(t.timeToSolve/1e3).toFixed(3),"s"]}),C&&W.jsxs("div",{className:"text-sm text-gray-600",children:["Phase: ",W.jsx("span",{className:"font-medium",children:C})]}),t.solved&&W.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),t.failed&&W.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),t.error&&W.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",t.error]})]})},toi=(t,A,e)=>{const i=t.currentPipelineStepIndex;return A<i?"Completed":A===i&&t.activeSubSolver?t.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},ioi=(t,A)=>{const i=t.pipelineDef[A].solverName,n=toi(t,A),o=t[i],s=t.firstIterationOfPhase?.[i]??null,r=t.iterations;let a=0;if(n==="Completed"){const l=t.pipelineDef[A+1],B=l?t.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=t.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}},noi=({status:t})=>{const A={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return W.jsx("span",{className:`font-medium ${A[t]}`,children:t})},ooi=({progress:t})=>{if(t===0)return null;const A=Math.round(t*100);return W.jsxs("div",{className:"flex items-center gap-2",children:[W.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:W.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${A}%`}})}),W.jsxs("span",{className:"text-xs text-gray-500",children:[A,"%"]})]})},soi=t=>Object.entries(t).map(([A,e])=>`${A}: ${e}`).join(", "),roi=({stats:t})=>{if(!t||Object.keys(t).length===0)return W.jsx("span",{children:"-"});const A=Object.entries(t),e=soi(t);return W.jsxs("details",{className:"cursor-pointer",children:[W.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:e}),W.jsx("div",{className:"mt-1 text-xs",children:A.map(([i,n])=>W.jsxs("div",{children:[i,": ",String(n)]},i))})]})},TmA=t=>{if(t===null||typeof t!="object")return t;if(Array.isArray(t))return t.map(TmA);const A={};for(const[e,i]of Object.entries(t))e.startsWith("_")||(A[e]=TmA(i));return A},aoi=(t,A)=>{try{if(typeof t.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${A}`);return}const e=TmA(t.getConstructorParams()),i=new Blob([JSON.stringify(e,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(e){alert(`Error downloading input for ${A}: ${e instanceof Error?e.message:String(e)}`)}},goi=({solver:t,onStepUntilPhase:A,onDownloadInput:e})=>{const i=t.pipelineDef.map((r,a)=>ioi(t,a)),n=r=>{A?.(r)},o=r=>{r.solverInstance&&(e?e(r.solverInstance,r.name):aoi(r.solverInstance,r.name))},s=r=>`${(r/1e3).toFixed(2)}s`;return W.jsxs("div",{className:"border-t border-gray-200",children:[W.jsx("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200",children:W.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Steps"})}),W.jsx("div",{className:"overflow-x-auto",children:W.jsxs("table",{className:"w-full text-sm",children:[W.jsx("thead",{children:W.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Step"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),W.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",W.jsx("sub",{children:"0"})]}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),W.jsx("tbody",{children:i.map(r=>W.jsxs("tr",{className:`border-b border-gray-100 ${r.status==="In Progress"?"bg-yellow-50":""}`,children:[W.jsx("td",{className:"px-4 py-2",children:W.jsxs("div",{className:"flex items-center gap-2",children:[W.jsx("span",{className:"text-gray-400 w-6",children:String(r.index+1).padStart(2,"0")}),W.jsx("button",{onClick:()=>n(r.name),disabled:r.status==="Completed"||t.solved||t.failed,className:"text-blue-500 hover:text-blue-700 disabled:text-gray-300 disabled:cursor-not-allowed",title:`Step until ${r.name} completes`,children:W.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:W.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"})})}),W.jsx("span",{className:"font-medium text-gray-900",children:r.name})]})}),W.jsx("td",{className:"px-4 py-2",children:W.jsx(noi,{status:r.status})}),W.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:r.firstIteration!==null?r.firstIteration:""}),W.jsx("td",{className:"px-4 py-2 text-gray-600",children:r.iterations}),W.jsx("td",{className:"px-4 py-2",children:W.jsx(ooi,{progress:r.progress})}),W.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(r.timeSpent)}),W.jsx("td",{className:"px-4 py-2 text-gray-500",children:W.jsx(roi,{stats:r.stats})}),W.jsx("td",{className:"px-4 py-2",children:r.solverInstance?W.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:[W.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:W.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"})}),W.jsx("span",{children:"Input"})]}):null})]},r.name))})]})})]})},coi=class extends Qn.Component{constructor(t){super(t),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(t){console.error("InteractiveGraphics render error:",t)}render(){return this.state.hasError?this.props.fallback:this.props.children}};function Ioi({graphics:t}){const A=t.points??[],e=t.lines??[],i=t.rects??[],n=t.circles??[],o=t.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 e){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,p=h.height??0;c(E,u),c(E+d,u+p)}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 W.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)=>W.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}`)),e.map((h,E)=>W.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)=>W.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)=>W.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)=>W.jsx("text",{x:h.x??0,y:h.y??0,fontSize:h.fontSize??10,fill:h.color??"black",children:h.text??""},`text-${E}`))]})}var loi=({solver:t,animationSpeed:A=25,onSolverStarted:e,onSolverCompleted:i})=>{const[n,o]=V.useReducer(c=>c+1,0),s=V.useMemo(()=>{try{return t.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(c){return console.error("Visualization error:",c),{points:[],lines:[],rects:[],circles:[]}}},[t,n]),r=V.useMemo(()=>(s.rects?.length||0)===0&&(s.lines?.length||0)===0&&(s.points?.length||0)===0&&(s.circles?.length||0)===0,[s]);V.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=t.pipelineDef!==void 0,g=c=>{const I=t;if(!t.solved&&!t.failed){for(;!t.solved&&!t.failed&&I.currentPipelineStepIndex<=I.pipelineDef.findIndex(l=>l.solverName===c);)t.step();o()}};return W.jsxs("div",{children:[W.jsx(eoi,{solver:t,triggerRender:o,animationSpeed:A,onSolverStarted:e,onSolverCompleted:i}),r?W.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):W.jsx(coi,{fallback:W.jsx(Ioi,{graphics:s}),children:W.jsx(Xni,{graphics:s})}),a&&W.jsx(goi,{solver:t,onStepUntilPhase:g})]})};const Boi=()=>{V.useEffect(()=>{const t="tailwind-cdn-script";if(document.getElementById(t)||window.tailwind)return;const A=document.createElement("div");A.className="hidden",document.body.appendChild(A);const e=window.getComputedStyle(A).display==="none";if(document.body.removeChild(A),e)return;const i=document.createElement("script");i.id=t,i.src="https://cdn.tailwindcss.com",document.head.appendChild(i)},[])},Coi=t=>t.toLowerCase().includes("pack")?VHt:t.toLowerCase().includes("rout")?AYt:RHt,Qoi=({solverEvents:t=[]})=>{const[A,e]=V.useState(null);Boi();const i=V.useMemo(()=>{const r=new Map;for(const a of t){const g=`${a.componentName}-${a.solverName}`;r.set(g,a)}return r},[t]),n=V.useMemo(()=>Array.from(i.keys()),[i]),o=A?i.get(A):null,s=V.useMemo(()=>{if(!o)return{instance:null,error:null,classFound:!1};const r=$rA[o.solverName];if(!r)return{instance:null,error:`Solver class "${o.solverName}" not found in SOLVERS registry. Available: ${Object.keys($rA).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 t.length===0?W.jsx("div",{className:"rf-p-4",children:W.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:W.jsxs("div",{className:"rf-p-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),W.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."})]})})}):W.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[W.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[W.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 W.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:()=>e(r),children:(()=>{const c=Coi(a.solverName);return W.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[W.jsx(c,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),W.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[W.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:a.componentName}),W.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:a.solverName})]})]})})()},r)})]}),W.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:o?s.instance?W.jsx(xm,{fallback:W.jsx("div",{className:"rf-p-4",children:W.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),W.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",o.solverName]})]})}),children:W.jsx(loi,{solver:s.instance})}):W.jsxs("div",{className:"rf-p-4",children:[W.jsxs("div",{className:"rf-mb-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:o.solverName}),W.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",o.componentName]})]}),s.error&&W.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:W.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),W.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[W.jsx("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50",children:W.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"})}),W.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:W.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)})})]})]}):W.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:W.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},R0e=({errorMessage:t,errorStack:A,circuitJsonErrors:e})=>{V.useEffect(()=>{if(t){const i=new Error(t);A&&(i.stack=A);try{ZK.captureException(i)}catch{}}},[t,A]),V.useEffect(()=>{if(e&&e.length>0)for(const i of e){const n=new Error(i.message||"Circuit JSON Error");i.stack&&(n.stack=i.stack);try{ZK.captureException(n,{error_type:i.type})}catch{}}},[e])},N0e="0.0.1764",hoi={version:N0e},qV=VYA()(jYA(t=>({lastRunEvalVersion:void 0,setLastRunEvalVersion:A=>{t({lastRunEvalVersion:A})}}),{name:"runframe-runner-store"})),Eoi=t=>{const[A,e]=V.useState([]),[i,n]=V.useState(null),[o,s]=V.useState(""),[r,a]=Iv("eval-version-selection",null),g=qV(B=>B.setLastRunEvalVersion),c=qV(B=>B.lastRunEvalVersion);return V.useEffect(()=>{t&&fetch("https://data.jsdelivr.com/v1/package/npm/@tscircuit/eval").then(B=>B.json()).then(B=>{if(Array.isArray(B?.versions)){let C=[...B.versions];B.tags?.latest&&(n(B.tags.latest),C=C.filter(Q=>Q!==B.tags.latest)),e(C)}}).catch(()=>{})},[t]),V.useEffect(()=>{t&&(r?(window.TSCIRCUIT_LATEST_EVAL_VERSION=r,g(r)):i&&(window.TSCIRCUIT_LATEST_EVAL_VERSION=i,g(i)))},[t,r,i]),{versions:V.useMemo(()=>A.filter(B=>B.includes(o)).slice(0,50),[A,o]),latestVersion:i,lastRunEvalVersion:c,search:o,setSearch:s,selectVersion:B=>{a(B),s("")}}},uoi=({snippetNames:t,onSelect:A,onCancel:e,isOpen:i})=>{const[n,o]=V.useState(""),[s,r]=V.useState("");if(!i)return null;const a=t.filter(I=>I.toLowerCase().includes(s.toLowerCase())),g=s&&!t.includes(s),c=I=>{I.key==="Enter"&&(a.length===1?o(a[0]):g&&o(s))};return W.jsx("div",{className:"rf-fixed rf-inset-0 rf-bg-black rf-bg-opacity-50 rf-flex rf-items-center rf-justify-center rf-z-[100]",children:W.jsxs("div",{className:"rf-bg-white rf-rounded-lg rf-p-6 rf-w-96",children:[W.jsx("h2",{className:"rf-text-lg rf-font-semibold rf-mb-4",children:"Select Snippet"}),W.jsx("input",{type:"text",className:"rf-w-full rf-px-4 rf-py-2 rf-border rf-rounded rf-mb-4",placeholder:"Search snippets or new snippet name...",value:s,onChange:I=>r(I.target.value),onKeyDown:c}),W.jsxs("div",{className:"rf-h-60 rf-overflow-y-auto",children:[a.map(I=>W.jsx("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 ${n===I?"bg-blue-50":""}`,onClick:()=>o(I),children:I},I)),g&&W.jsxs("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 text-blue-500 ${n===s?"bg-blue-50":""}`,onClick:()=>o(s),children:['Create new "',s,'"']})]}),W.jsxs("div",{className:"rf-mt-4 rf-flex rf-justify-end rf-gap-2",children:[W.jsx("button",{type:"button",className:"rf-px-4 rf-py-2 rf-text-gray-600 rf-hover:text-gray-800",onClick:e,children:"Cancel"}),W.jsx("button",{type:"button",className:"rf-px-4 rf-py-2 rf-bg-blue-500 rf-text-white rf-rounded rf-hover:bg-blue-600 rf-disabled:opacity-50",onClick:()=>n&&A(n),disabled:!n,children:n===s?`Create "${n}"`:`Save to ${n}`})]})]})})},doi=t=>{const A=V.useRef(null),e=MI(i=>i.recentEvents);V.useEffect(()=>{if(e.length===0)return;const i=e[0];i.event_id!==A.current&&(t(i),A.current=i.event_id)},[e,t])};function poi(t){const A=foi(t),e=V.forwardRef((i,n)=>{const{children:o,...s}=i,r=V.Children.toArray(o),a=r.find(moi);if(a){const g=a.props.children,c=r.map(I=>I===a?V.Children.count(g)>1?V.Children.only(null):V.isValidElement(g)?g.props.children:null:I);return W.jsx(A,{...s,ref:n,children:V.isValidElement(g)?V.cloneElement(g,void 0,c):null})}return W.jsx(A,{...s,ref:n,children:o})});return e.displayName=`${t}.Slot`,e}function foi(t){const A=V.forwardRef((e,i)=>{const{children:n,...o}=e;if(V.isValidElement(n)){const s=Doi(n),r=woi(o,n.props);return n.type!==V.Fragment&&(r.ref=i?vp(i,s):s),V.cloneElement(n,r)}return V.Children.count(n)>1?V.Children.only(null):null});return A.displayName=`${t}.SlotClone`,A}var yoi=Symbol("radix.slottable");function moi(t){return V.isValidElement(t)&&typeof t.type=="function"&&"__radixId"in t.type&&t.type.__radixId===yoi}function woi(t,A){const e={...A};for(const i in A){const n=t[i],o=A[i];/^on[A-Z]/.test(i)?n&&o?e[i]=(...r)=>{const a=o(...r);return n(...r),a}:n&&(e[i]=n):i==="style"?e[i]={...n,...o}:i==="className"&&(e[i]=[n,o].filter(Boolean).join(" "))}return{...t,...e}}function Doi(t){let A=Object.getOwnPropertyDescriptor(t.props,"ref")?.get,e=A&&"isReactWarning"in A&&A.isReactWarning;return e?t.ref:(A=Object.getOwnPropertyDescriptor(t,"ref")?.get,e=A&&"isReactWarning"in A&&A.isReactWarning,e?t.props.ref:t.props.ref||t.ref)}var OV="Dialog",[G0e,L0e]=dw(OV),[xoi,Ow]=G0e(OV),U0e=t=>{const{__scopeDialog:A,children:e,open:i,defaultOpen:n,onOpenChange:o,modal:s=!0}=t,r=V.useRef(null),a=V.useRef(null),[g,c]=GS({prop:i,defaultProp:n??!1,onChange:o,caller:OV});return W.jsx(xoi,{scope:A,triggerRef:r,contentRef:a,contentId:W0(),titleId:W0(),descriptionId:W0(),open:g,onOpenChange:c,onOpenToggle:V.useCallback(()=>c(I=>!I),[c]),modal:s,children:e})};U0e.displayName=OV;var H0e="DialogTrigger",Y0e=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,n=Ow(H0e,e),o=RI(A,n.triggerRef);return W.jsx(Ag.button,{type:"button","aria-haspopup":"dialog","aria-expanded":n.open,"aria-controls":n.contentId,"data-state":qmA(n.open),...i,ref:o,onClick:Vn(t.onClick,n.onOpenToggle)})});Y0e.displayName=H0e;var PmA="DialogPortal",[Soi,J0e]=G0e(PmA,{forceMount:void 0}),T0e=t=>{const{__scopeDialog:A,forceMount:e,children:i,container:n}=t,o=Ow(PmA,A);return W.jsx(Soi,{scope:A,forceMount:e,children:V.Children.map(i,s=>W.jsx(qf,{present:e||o.open,children:W.jsx(nZ,{asChild:!0,container:n,children:s})}))})};T0e.displayName=PmA;var WV="DialogOverlay",P0e=V.forwardRef((t,A)=>{const e=J0e(WV,t.__scopeDialog),{forceMount:i=e.forceMount,...n}=t,o=Ow(WV,t.__scopeDialog);return o.modal?W.jsx(qf,{present:i||o.open,children:W.jsx(_oi,{...n,ref:A})}):null});P0e.displayName=WV;var boi=poi("DialogOverlay.RemoveScroll"),_oi=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,n=Ow(WV,e);return W.jsx(lZ,{as:boi,allowPinchZoom:!0,shards:[n.contentRef],children:W.jsx(Ag.div,{"data-state":qmA(n.open),...i,ref:A,style:{pointerEvents:"auto",...i.style}})})}),K3="DialogContent",K0e=V.forwardRef((t,A)=>{const e=J0e(K3,t.__scopeDialog),{forceMount:i=e.forceMount,...n}=t,o=Ow(K3,t.__scopeDialog);return W.jsx(qf,{present:i||o.open,children:o.modal?W.jsx(koi,{...n,ref:A}):W.jsx(voi,{...n,ref:A})})});K0e.displayName=K3;var koi=V.forwardRef((t,A)=>{const e=Ow(K3,t.__scopeDialog),i=V.useRef(null),n=RI(A,e.contentRef,i);return V.useEffect(()=>{const o=i.current;if(o)return ofA(o)},[]),W.jsx(q0e,{...t,ref:n,trapFocus:e.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:Vn(t.onCloseAutoFocus,o=>{o.preventDefault(),e.triggerRef.current?.focus()}),onPointerDownOutside:Vn(t.onPointerDownOutside,o=>{const s=o.detail.originalEvent,r=s.button===0&&s.ctrlKey===!0;(s.button===2||r)&&o.preventDefault()}),onFocusOutside:Vn(t.onFocusOutside,o=>o.preventDefault())})}),voi=V.forwardRef((t,A)=>{const e=Ow(K3,t.__scopeDialog),i=V.useRef(!1),n=V.useRef(!1);return W.jsx(q0e,{...t,ref:A,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:o=>{t.onCloseAutoFocus?.(o),o.defaultPrevented||(i.current||e.triggerRef.current?.focus(),o.preventDefault()),i.current=!1,n.current=!1},onInteractOutside:o=>{t.onInteractOutside?.(o),o.defaultPrevented||(i.current=!0,o.detail.originalEvent.type==="pointerdown"&&(n.current=!0));const s=o.target;e.triggerRef.current?.contains(s)&&o.preventDefault(),o.detail.originalEvent.type==="focusin"&&n.current&&o.preventDefault()}})}),q0e=V.forwardRef((t,A)=>{const{__scopeDialog:e,trapFocus:i,onOpenAutoFocus:n,onCloseAutoFocus:o,...s}=t,r=Ow(K3,e),a=V.useRef(null),g=RI(A,a);return YpA(),W.jsxs(W.Fragment,{children:[W.jsx(qW,{asChild:!0,loop:!0,trapped:i,onMountAutoFocus:n,onUnmountAutoFocus:o,children:W.jsx(Z9,{role:"dialog",id:r.contentId,"aria-describedby":r.descriptionId,"aria-labelledby":r.titleId,"data-state":qmA(r.open),...s,ref:g,onDismiss:()=>r.onOpenChange(!1)})}),W.jsxs(W.Fragment,{children:[W.jsx(Moi,{titleId:r.titleId}),W.jsx(Noi,{contentRef:a,descriptionId:r.descriptionId})]})]})}),KmA="DialogTitle",O0e=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,n=Ow(KmA,e);return W.jsx(Ag.h2,{id:n.titleId,...i,ref:A})});O0e.displayName=KmA;var W0e="DialogDescription",Z0e=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,n=Ow(W0e,e);return W.jsx(Ag.p,{id:n.descriptionId,...i,ref:A})});Z0e.displayName=W0e;var V0e="DialogClose",j0e=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,n=Ow(V0e,e);return W.jsx(Ag.button,{type:"button",...i,ref:A,onClick:Vn(t.onClick,()=>n.onOpenChange(!1))})});j0e.displayName=V0e;function qmA(t){return t?"open":"closed"}var z0e="DialogTitleWarning",[Foi,X0e]=ngt(z0e,{contentName:K3,titleName:KmA,docsSlug:"dialog"}),Moi=({titleId:t})=>{const A=X0e(z0e),e=`\`${A.contentName}\` requires a \`${A.titleName}\` for the component to be accessible for screen reader users.
|
|
5693
5693
|
|
|
5694
5694
|
If you want to hide the \`${A.titleName}\`, you can wrap it with our VisuallyHidden component.
|
|
5695
5695
|
|