@tscircuit/runframe 0.0.2475 → 0.0.2476
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.
|
@@ -5681,7 +5681,7 @@ You passed in: '`+this.raw_options[r]+"'");return A},n.prototype._is_valid_selec
|
|
|
5681
5681
|
`);break}}return s}}}),RKo=hc({"node_modules/pretty/index.js"(t,e){var n=DKo(),o=NKo(),i=oLt(),r={unformatted:["code","pre","em","strong","span"],indent_inner_html:!0,indent_char:" ",indent_size:2,sep:`
|
|
5682
5682
|
`};e.exports=function(A,c){var l=i({},r,c);return A=n.html(A,l),l.ocd===!0?(l.newlines&&(l.sep=l.newlines),s(A,l)):A};function s(a,A){return o(a,A).replace(/^\s+/g,"").replace(/\s+$/g,`
|
|
5683
5683
|
`).replace(/(\s*<!--)/g,`
|
|
5684
|
-
$1`).replace(/>(\s*)(?=<!--\s*\/)/g,"> ")}}});function iLt(t,e,n){if(!e||!n)return;let o=t.get(e);o||(o=new Set,t.set(e,o)),o.add(n);let i=t.get(n);i||(i=new Set,t.set(n,i)),i.add(e)}function TKo(t,e){if(!e.subcircuit_id&&!e.source_group_id)return[...t];let n=e;if(e.subcircuit_id){const a=new Set([e.subcircuit_id]),A=new Map,c=new Map;for(const g of t)if(g.type==="source_group"){const u=g.source_group_id,h=g.subcircuit_id;h&&c.set(u,h);const d=g.parent_source_group_id;d&&(A.has(d)||A.set(d,[]),A.get(d).push(u))}let l;for(const[g,u]of c)if(u===e.subcircuit_id){l=g;break}if(l){const g=u=>{const h=A.get(u)||[];for(const d of h){const _=c.get(d);_&&a.add(_),g(d)}};g(l),n={...e,subcircuit_ids:Array.from(a)}}}const o=new Map;for(const a of t){const A=`${a.type}_id`,c=a[A];typeof c=="string"&&o.set(c,a)}const i=new Map;for(const a of t){const A=Object.entries(a);for(const[c,l]of A)if(c!=="parent_source_group_id"){if(c.endsWith("_id")&&typeof l=="string"){const g=o.get(l);iLt(i,a,g)}else if(c.endsWith("_ids")&&Array.isArray(l)){for(const g of l)if(typeof g=="string"){const u=o.get(g);iLt(i,a,u)}}}}const r=[],s=new Set;for(const a of t){let A=!1;(n.subcircuit_id&&"subcircuit_id"in a&&a.subcircuit_id===n.subcircuit_id||n.subcircuit_ids&&"subcircuit_id"in a&&a.subcircuit_id&&n.subcircuit_ids.includes(a.subcircuit_id)||n.source_group_id&&"source_group_id"in a&&a.source_group_id===n.source_group_id||n.source_group_id&&"member_source_group_ids"in a&&Array.isArray(a.member_source_group_ids)&&a.member_source_group_ids.includes(n.source_group_id))&&(A=!0),A&&(r.push(a),s.add(a))}for(;r.length>0;){const a=r.shift(),A=i.get(a);if(A)for(const c of A)s.has(c)||(s.add(c),r.push(c))}return t.filter(a=>s.has(a))}var Dse=(t,e={})=>{const n=t;let o=n._internal_store;if(!o){o={counts:{},editCount:0},n._internal_store=o;for(const r of n){const s=r.type,a=r[`${s}_id`];if(!a)continue;const A=Number.parseInt(a.split("_").pop());Number.isNaN(A)||(o.counts[s]=Math.max(o.counts[s]??0,A))}}const i=new Proxy({},{get:(r,s)=>{if(s==="toArray")return()=>(n.editCount=o.editCount,n);if(s==="editCount")return o.editCount;if(s==="subtree")return A=>Dse(TKo(n,A),e);if(s==="insert")return A=>{const c=A.type;if(!c)throw new Error("insert requires an element with a type");o.counts[c]??=-1,o.counts[c]++;const l=o.counts[c],g={...A,type:c,[`${c}_id`]:`${c}_${l}`};return e.validateInserts&&(D8e[c]??rse).parse(g),n.push(g),o.editCount++,g};if(s==="insertAll")return A=>A.map(c=>i.insert(c));const a=s;return{get:A=>n.find(c=>c.type===a&&c[`${a}_id`]===A),getUsing:A=>{const c=Object.keys(A);if(c.length!==1)throw new Error("getUsing requires exactly one key, e.g. { pcb_component_id }");const l=c[0],g=l.replace("_id",""),u=n.find(h=>h.type===g&&h[l]===A[l]);return u?n.find(h=>h.type===a&&h[`${a}_id`]===u[`${a}_id`]):null},getWhere:A=>{const c=Object.keys(A);return n.find(l=>l.type===a&&c.every(g=>l[g]===A[g]))},list:A=>{const c=A?Object.keys(A):[];return n.filter(l=>l.type===a&&c.every(g=>l[g]===A[g]))},insert:A=>{o.counts[a]??=-1,o.counts[a]++;const c=o.counts[a],l={type:a,[`${a}_id`]:`${a}_${c}`,...A};return e.validateInserts&&(D8e[a]??rse).parse(l),n.push(l),o.editCount++,l},delete:A=>{const c=n.find(l=>l[`${a}_id`]===A);c&&(n.splice(n.indexOf(c),1),o.editCount++)},update:(A,c)=>{const l=n.find(g=>g.type===a&&g[`${a}_id`]===A);return l?(Object.assign(l,c),o.editCount++,l):null},select:A=>{if(a==="source_component")return n.find(c=>c.type==="source_component"&&c.name===A.replace(/\./g,""));if(a==="pcb_port"||a==="source_port"||a==="schematic_port"){const[c,l]=A.replace(/\./g,"").split(/[\s\>]+/),g=n.find(h=>h.type==="source_component"&&h.name===c);if(!g)return null;const u=n.find(h=>h.type==="source_port"&&h.source_component_id===g.source_component_id&&(h.name===l||(h.port_hints??[]).includes(l)));if(!u)return null;if(a==="source_port")return u;if(a==="pcb_port")return n.find(h=>h.type==="pcb_port"&&h.source_port_id===u.source_port_id);if(a==="schematic_port")return n.find(h=>h.type==="schematic_port"&&h.source_port_id===u.source_port_id)}}}}});return i};Dse.unparsed=Dse;var N6=Dse;function o9e(t){const e=t.type;return`${e}:${t[`${e}_id`]}`}var rLt=(t,e={})=>{let n=t._internal_store_indexed;if(!n){n={counts:{},editCount:0,indexes:{}};for(const s of t){const a=s.type,A=s[`${a}_id`];if(!A)continue;const c=Number.parseInt(A.split("_").pop()||"");Number.isNaN(c)||(n.counts[a]=Math.max(n.counts[a]??0,c))}const i=e.indexConfig||{},r=n.indexes;if(i.byId&&(r.byId=new Map),i.byType&&(r.byType=new Map),i.byRelation&&(r.byRelation=new Map),i.bySubcircuit&&(r.bySubcircuit=new Map),i.byCustomField&&i.byCustomField.length>0){r.byCustomField=new Map;for(const s of i.byCustomField)r.byCustomField.set(s,new Map)}for(const s of t){if(i.byId){const a=o9e(s);r.byId.set(a,s)}if(i.byType){const a=r.byType.get(s.type)||[];a.push(s),r.byType.set(s.type,a)}if(i.byRelation){const a=Object.entries(s);for(const[A,c]of a)if(A.endsWith("_id")&&A!==`${s.type}_id`&&typeof c=="string"){const l=r.byRelation.get(A)||new Map,g=l.get(c)||[];g.push(s),l.set(c,g),r.byRelation.set(A,l)}}if(i.bySubcircuit&&"subcircuit_id"in s){const a=s.subcircuit_id;if(a&&typeof a=="string"){const A=r.bySubcircuit.get(a)||[];A.push(s),r.bySubcircuit.set(a,A)}}if(i.byCustomField&&r.byCustomField){for(const a of i.byCustomField)if(a in s){const A=s[a];if(A!==void 0&&(typeof A=="string"||typeof A=="number")){const c=String(A),l=r.byCustomField.get(a),g=l.get(c)||[];g.push(s),l.set(c,g)}}}}t._internal_store_indexed=n}return new Proxy({},{get:(i,r)=>{if(r==="toArray")return()=>(t.editCount=n.editCount,t);if(r==="editCount")return n.editCount;const s=r;return{get:a=>{const A=e.indexConfig||{};return A.byId&&n.indexes.byId?n.indexes.byId.get(`${s}:${a}`)||null:A.byType&&n.indexes.byType?(n.indexes.byType.get(s)||[]).find(l=>l[`${s}_id`]===a)||null:t.find(c=>c.type===s&&c[`${s}_id`]===a)||null},getUsing:a=>{const A=e.indexConfig||{},c=Object.keys(a);if(c.length!==1)throw new Error("getUsing requires exactly one key, e.g. { pcb_component_id }");const l=c[0],g=l.replace("_id","");if(A.byRelation&&n.indexes.byRelation){const h=n.indexes.byRelation.get(l);if(h){const _=(h.get(a[l])||[]).find(p=>p.type===g);if(!_)return null;const m=_[`${s}_id`];return A.byId&&n.indexes.byId?n.indexes.byId.get(`${s}:${m}`)||null:A.byType&&n.indexes.byType?(n.indexes.byType.get(s)||[]).find(I=>I[`${s}_id`]===m)||null:t.find(p=>p.type===s&&p[`${s}_id`]===m)||null}}const u=t.find(h=>h.type===g&&h[l]===a[l]);return u&&t.find(h=>h.type===s&&h[`${s}_id`]===u[`${s}_id`])||null},getWhere:a=>{const A=e.indexConfig||{},c=Object.keys(a);if(c.length===1&&A.byCustomField&&n.indexes.byCustomField){const l=c[0],g=n.indexes.byCustomField.get(l);if(g){const u=String(a[l]);return(g.get(u)||[]).find(d=>d.type===s)||null}}if("subcircuit_id"in a&&A.bySubcircuit&&n.indexes.bySubcircuit){const l=a.subcircuit_id;return(n.indexes.bySubcircuit.get(l)||[]).find(u=>u.type===s&&c.every(h=>u[h]===a[h]))||null}return A.byType&&n.indexes.byType?(n.indexes.byType.get(s)||[]).find(g=>c.every(u=>g[u]===a[u]))||null:t.find(l=>l.type===s&&c.every(g=>l[g]===a[g]))||null},list:a=>{const A=e.indexConfig||{},c=a?Object.keys(a):[];if(c.length===0&&A.byType&&n.indexes.byType)return n.indexes.byType.get(s)||[];if(c.length===1&&c[0]==="subcircuit_id"&&A.bySubcircuit&&n.indexes.bySubcircuit){const g=a.subcircuit_id;return(n.indexes.bySubcircuit.get(g)||[]).filter(h=>h.type===s)}let l;return A.byType&&n.indexes.byType?l=n.indexes.byType.get(s)||[]:l=t.filter(g=>g.type===s),c.length>0?l.filter(g=>c.every(u=>g[u]===a[u])):l},insert:a=>{n.counts[s]??=-1,n.counts[s]++;const A=n.counts[s],c={type:s,[`${s}_id`]:`${s}_${A}`,...a};e.validateInserts&&(D8e[s]??rse).parse(c),t.push(c),n.editCount++;const l=e.indexConfig||{};if(l.byId&&n.indexes.byId){const g=o9e(c);n.indexes.byId.set(g,c)}if(l.byType&&n.indexes.byType){const g=n.indexes.byType.get(s)||[];g.push(c),n.indexes.byType.set(s,g)}if(l.byRelation&&n.indexes.byRelation){const g=Object.entries(c);for(const[u,h]of g)if(u.endsWith("_id")&&u!==`${c.type}_id`&&typeof h=="string"){const d=n.indexes.byRelation.get(u)||new Map,_=d.get(h)||[];_.push(c),d.set(h,_),n.indexes.byRelation.set(u,d)}}if(l.bySubcircuit&&n.indexes.bySubcircuit&&"subcircuit_id"in c){const g=c.subcircuit_id;if(g&&typeof g=="string"){const u=n.indexes.bySubcircuit.get(g)||[];u.push(c),n.indexes.bySubcircuit.set(g,u)}}if(l.byCustomField&&n.indexes.byCustomField){for(const g of l.byCustomField)if(g in c){const u=c[g];if(u!==void 0&&(typeof u=="string"||typeof u=="number")){const h=String(u),d=n.indexes.byCustomField.get(g),_=d.get(h)||[];_.push(c),d.set(h,_)}}}return c},delete:a=>{const A=e.indexConfig||{};let c;if(A.byId&&n.indexes.byId?c=n.indexes.byId.get(`${s}:${a}`):A.byType&&n.indexes.byType?c=(n.indexes.byType.get(s)||[]).find(u=>u[`${s}_id`]===a):c=t.find(g=>g[`${s}_id`]===a),!c)return;const l=t.indexOf(c);if(l>=0&&(t.splice(l,1),n.editCount++),A.byId&&n.indexes.byId){const g=o9e(c);n.indexes.byId.delete(g)}if(A.byType&&n.indexes.byType){const u=(n.indexes.byType.get(s)||[]).filter(h=>h[`${s}_id`]!==a);n.indexes.byType.set(s,u)}if(A.byRelation&&n.indexes.byRelation)for(const[g,u]of n.indexes.byRelation.entries())for(const[h,d]of u.entries()){const _=d.filter(m=>m!==c);_.length===0?u.delete(h):u.set(h,_)}if(A.bySubcircuit&&n.indexes.bySubcircuit&&"subcircuit_id"in c){const g=c.subcircuit_id;if(g){const h=(n.indexes.bySubcircuit.get(g)||[]).filter(d=>d!==c);h.length===0?n.indexes.bySubcircuit.delete(g):n.indexes.bySubcircuit.set(g,h)}}if(A.byCustomField&&n.indexes.byCustomField)for(const g of n.indexes.byCustomField.values())for(const[u,h]of g.entries()){const d=h.filter(_=>_!==c);d.length===0?g.delete(u):g.set(u,d)}},update:(a,A)=>{const c=e.indexConfig||{};let l;if(c.byId&&n.indexes.byId?l=n.indexes.byId.get(`${s}:${a}`):c.byType&&n.indexes.byType?l=(n.indexes.byType.get(s)||[]).find(u=>u[`${s}_id`]===a):l=t.find(g=>g.type===s&&g[`${s}_id`]===a),!l)return null;if(c.byRelation&&n.indexes.byRelation){const g=Object.entries(l);for(const[u,h]of g)if(u.endsWith("_id")&&u!==`${l.type}_id`&&typeof h=="string"&&u in A&&A[u]!==h){const d=n.indexes.byRelation.get(u);if(d){const m=(d.get(h)||[]).filter(p=>p!==l);m.length===0?d.delete(h):d.set(h,m)}}}if(c.bySubcircuit&&n.indexes.bySubcircuit&&"subcircuit_id"in l&&"subcircuit_id"in A){const g=l.subcircuit_id,u=A.subcircuit_id;if(g!==u){const d=(n.indexes.bySubcircuit.get(g)||[]).filter(_=>_!==l);d.length===0?n.indexes.bySubcircuit.delete(g):n.indexes.bySubcircuit.set(g,d)}}if(c.byCustomField&&n.indexes.byCustomField){for(const g of c.byCustomField)if(g in l&&g in A&&l[g]!==A[g]){const u=n.indexes.byCustomField.get(g);if(u){const h=String(l[g]),_=(u.get(h)||[]).filter(m=>m!==l);_.length===0?u.delete(h):u.set(h,_)}}}if(Object.assign(l,A),n.editCount++,c.byRelation&&n.indexes.byRelation){const g=Object.entries(l);for(const[u,h]of g)if(u.endsWith("_id")&&u!==`${l.type}_id`&&typeof h=="string"&&u in A){const d=n.indexes.byRelation.get(u)||new Map,_=d.get(h)||[];_.includes(l)||(_.push(l),d.set(h,_),n.indexes.byRelation.set(u,d))}}if(c.bySubcircuit&&n.indexes.bySubcircuit&&"subcircuit_id"in l&&"subcircuit_id"in A){const g=l.subcircuit_id;if(g&&typeof g=="string"){const u=n.indexes.bySubcircuit.get(g)||[];u.includes(l)||(u.push(l),n.indexes.bySubcircuit.set(g,u))}}if(c.byCustomField&&n.indexes.byCustomField){for(const g of c.byCustomField)if(g in l&&g in A){const u=l[g];if(u!==void 0&&(typeof u=="string"||typeof u=="number")){const h=String(u),d=n.indexes.byCustomField.get(g),_=d.get(h)||[];_.includes(l)||(_.push(l),d.set(h,_))}}}return l},select:a=>{if(s==="source_component")return t.find(A=>A.type==="source_component"&&A.name===a.replace(/\./g,""))||null;if(s==="pcb_port"||s==="source_port"||s==="schematic_port"){const[A,c]=a.replace(/\./g,"").split(/[\s\>]+/),l=t.find(u=>u.type==="source_component"&&u.name===A);if(!l)return null;const g=t.find(u=>u.type==="source_port"&&u.source_component_id===l.source_component_id&&(u.name===c||(u.port_hints??[]).includes(c)));if(!g)return null;if(s==="source_port")return g;if(s==="pcb_port")return t.find(u=>u.type==="pcb_port"&&u.source_port_id===g.source_port_id)||null;if(s==="schematic_port")return t.find(u=>u.type==="schematic_port"&&u.source_port_id===g.source_port_id)||null}return null}}}})};rLt.unparsed=rLt;var kKo=t=>{const e=t.type;return t[`${e}_id`]},sLt=(t,e)=>({minX:Math.min(t.minX,e.minX),minY:Math.min(t.minY,e.minY),maxX:Math.max(t.maxX,e.maxX),maxY:Math.max(t.maxY,e.maxY)}),Pse=(t,e,n)=>{const o=n/2;return{minX:t-o,minY:e-o,maxX:t+o,maxY:e+o}},aLt=(t,e,n,o,i)=>{const r=n/2,s=o/2,a=i*Math.PI/180,A=Math.cos(a),c=Math.sin(a),l=[{x:-r,y:-s},{x:r,y:-s},{x:r,y:s},{x:-r,y:s}].map(g=>({x:t+g.x*A-g.y*c,y:e+g.x*c+g.y*A}));return{minX:Math.min(...l.map(g=>g.x)),minY:Math.min(...l.map(g=>g.y)),maxX:Math.max(...l.map(g=>g.x)),maxY:Math.max(...l.map(g=>g.y))}},i9e=t=>{let e=Number.POSITIVE_INFINITY,n=Number.POSITIVE_INFINITY,o=Number.NEGATIVE_INFINITY,i=Number.NEGATIVE_INFINITY;for(const r of t){if(!r.type.startsWith("pcb_"))continue;if(r.type==="pcb_smtpad"&&r.shape==="polygon"&&Array.isArray(r.points)){for(const g of r.points)e=Math.min(e,g.x),n=Math.min(n,g.y),o=Math.max(o,g.x),i=Math.max(i,g.y);continue}if(r.type==="pcb_hole"&&r.hole_shape==="circle"){const g=Pse(r.x,r.y,r.hole_diameter);e=Math.min(e,g.minX),n=Math.min(n,g.minY),o=Math.max(o,g.maxX),i=Math.max(i,g.maxY);continue}if(r.type==="pcb_plated_hole"){let g;if("outer_diameter"in r&&typeof r.outer_diameter=="number"?g=Pse(r.x,r.y,r.outer_diameter):"hole_diameter"in r&&typeof r.hole_diameter=="number"&&(g=Pse(r.x,r.y,r.hole_diameter)),"rect_pad_width"in r&&typeof r.rect_pad_width=="number"&&"rect_pad_height"in r&&typeof r.rect_pad_height=="number"){const u=aLt(r.x,r.y,r.rect_pad_width,r.rect_pad_height,"rect_ccw_rotation"in r?r.rect_ccw_rotation??0:0);g=g?sLt(g,u):u}if("hole_diameter"in r&&typeof r.hole_diameter=="number"){const u=Pse(r.x+("hole_offset_x"in r?r.hole_offset_x??0:0),r.y+("hole_offset_y"in r?r.hole_offset_y??0:0),r.hole_diameter);g=g?sLt(g,u):u}if(g){e=Math.min(e,g.minX),n=Math.min(n,g.minY),o=Math.max(o,g.maxX),i=Math.max(i,g.maxY);continue}}let s,a,A,c;"x"in r&&"y"in r&&(s=Number(r.x),a=Number(r.y)),"outer_diameter"in r&&(A=Number(r.outer_diameter),c=Number(r.outer_diameter)),"width"in r&&(A=Number(r.width)),"height"in r&&(c=Number(r.height)),"center"in r&&(s=r.center.x,a=r.center.y);const l=typeof r.rotation=="number"?r.rotation:0;if(s!==void 0&&a!==void 0){if(e=Math.min(e,s),n=Math.min(n,a),o=Math.max(o,s),i=Math.max(i,a),A!==void 0&&c!==void 0)if(l){const g=aLt(s,a,A,c,l);e=Math.min(e,g.minX),n=Math.min(n,g.minY),o=Math.max(o,g.maxX),i=Math.max(i,g.maxY)}else e=Math.min(e,s-A/2),n=Math.min(n,a-c/2),o=Math.max(o,s+A/2),i=Math.max(i,a+c/2);"radius"in r&&(e=Math.min(e,s-r.radius),n=Math.min(n,a-r.radius),o=Math.max(o,s+r.radius),i=Math.max(i,a+r.radius))}else if(r.type==="pcb_trace")for(const g of r.route)e=Math.min(e,g.x),n=Math.min(n,g.y),o=Math.max(o,g.x),i=Math.max(i,g.y);else if(r.type==="pcb_courtyard_outline")for(const g of r.outline)e=Math.min(e,g.x),n=Math.min(n,g.y),o=Math.max(o,g.x),i=Math.max(i,g.y);else if(r.type==="pcb_courtyard_polygon")for(const g of r.points)e=Math.min(e,g.x),n=Math.min(n,g.y),o=Math.max(o,g.x),i=Math.max(i,g.y)}return{minX:e,minY:n,maxX:o,maxY:i}};function FKo(t){let e=0;if(t.length==0)return e;for(var n=0;n<t.length;n++){var o=t.charCodeAt(n);e=(e<<5)-e+o,e=e&e}return Math.abs(e)}var ALt=[["#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"]],LKo=t=>{let{x:e,y:n,width:o,height:i}={...t,...t.size,...t.center,...t.position};if(t.x1!==void 0&&t.x2!==void 0&&t.y1!==void 0&&t.y2!==void 0&&(e=(t.x1+t.x2)/2,n=(t.y1+t.y2)/2,o=Math.abs(t.x1-t.x2),i=Math.abs(t.y1-t.y2)),t.points&&Array.isArray(t.points)&&t.points.length>0){const a=t.points.map(h=>h.x),A=t.points.map(h=>h.y),c=Math.min(...a),l=Math.max(...a),g=Math.min(...A),u=Math.max(...A);e=(c+l)/2,n=(g+u)/2,o=l-c,i=u-g}const r=t.text||t.name||t.source?.text||t.source?.name||"?",s=t;return e===void 0||n===void 0?null:(o===void 0&&("outer_diameter"in t?(o=t.outer_diameter,i=t.outer_diameter):"rect_pad_width"in t&&"rect_pad_height"in t?(o=t.rect_pad_width,i=t.rect_pad_height,"hole_diameter"in t&&(o=Math.max(o,t.hole_diameter),i=Math.max(i,t.hole_diameter))):"hole_diameter"in t&&(o=t.hole_diameter,i=t.hole_diameter)),(o===void 0||i===void 0)&&(o=.1,i=.1),{x:e,y:n,width:o,height:i,title:r,content:s,bg_color:ALt[FKo(t.type||r)%ALt.length]?.[4]??"#f00"})},HKo=t=>!!t,GKo=t=>{const e=t.filter(c=>c.type.startsWith("pcb_")||c.type.startsWith("schematic_")).concat(t.filter(c=>c.type==="pcb_trace"||c.type==="schematic_trace").flatMap(c=>c.route)).map(c=>LKo(c)).filter(HKo);if(e.length===0)return{center:{x:0,y:0},width:0,height:0};let n=e[0].x-e[0].width/2,o=e[0].x+e[0].width/2,i=e[0].y-e[0].height/2,r=e[0].y+e[0].height/2;for(const c of e.slice(1))n=Math.min(n,c.x-c.width/2),o=Math.max(o,c.x+c.width/2),i=Math.min(i,c.y-c.height/2),r=Math.max(r,c.y+c.height/2);const s=o-n,a=r-i;return{center:{x:n+s/2,y:i+a/2},width:s,height:a}},vp={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_PCB_NOTES:"pcb_viewer_is_showing_pcb_notes",IS_SHOWING_SILKSCREEN:"pcb_viewer_is_showing_silkscreen"},Ov=(t,e)=>{if(typeof window>"u")return e;try{const n=localStorage.getItem(t);return n!==null?JSON.parse(n):e}catch{return e}},Kv=(t,e)=>{if(!(typeof window>"u"))try{localStorage.setItem(t,JSON.stringify(e))}catch{}},OKo=(t,e)=>{if(typeof window>"u")return e;try{const n=localStorage.getItem(t);return n!==null?JSON.parse(n):e}catch{return e}},KKo=(t,e)=>{if(!(typeof window>"u"))try{localStorage.setItem(t,JSON.stringify(e))}catch{}},UKo="named_only",YKo=(t={},e=!1)=>nFt(n=>({selected_layer:"top",pcb_viewer_id:`pcb_viewer_${Math.random().toString().slice(2,10)}`,in_edit_mode:!1,in_move_footprint_mode:!1,is_moving_component:!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:Ov(vp.IS_SHOWING_COPPER_POURS,!0),is_showing_courtyards:Ov(vp.IS_SHOWING_COURTYARDS,!0),is_showing_pcb_groups:e?!1:Ov(vp.IS_SHOWING_PCB_GROUPS,!0),is_showing_group_anchor_offsets:Ov(vp.IS_SHOWING_GROUP_ANCHOR_OFFSETS,!1),is_showing_solder_mask:Ov(vp.IS_SHOWING_SOLDER_MASK,!1),is_showing_silkscreen:Ov(vp.IS_SHOWING_SILKSCREEN,!0),is_showing_fabrication_notes:Ov(vp.IS_SHOWING_FABRICATION_NOTES,!1),is_showing_pcb_notes:Ov(vp.IS_SHOWING_PCB_NOTES,!0),pcb_group_view_mode:e?"all":OKo(vp.PCB_GROUP_VIEW_MODE,UKo),hovered_error_id:null,focused_error_id:null,...t,selectLayer:o=>n({selected_layer:o}),setEditMode:o=>n({in_edit_mode:o!=="off",in_move_footprint_mode:o==="move_footprint",is_moving_component:!1}),setIsShowingRatsNest:o=>n({is_showing_rats_nest:o}),setIsMovingComponent:o=>n({is_moving_component:o}),setIsMouseOverContainer:o=>n({is_mouse_over_container:o}),setIsShowingMultipleTracesLength:o=>n({is_showing_multiple_traces_length:o}),setIsShowingAutorouting:o=>n({is_showing_autorouting:o}),setIsShowingDrcErrors:o=>n({is_showing_drc_errors:o}),setIsShowingCopperPours:o=>{Kv(vp.IS_SHOWING_COPPER_POURS,o),n({is_showing_copper_pours:o})},setIsShowingCourtyards:o=>{Kv(vp.IS_SHOWING_COURTYARDS,o),n({is_showing_courtyards:o})},setIsShowingPcbGroups:o=>{e||(Kv(vp.IS_SHOWING_PCB_GROUPS,o),n({is_showing_pcb_groups:o}))},setIsShowingGroupAnchorOffsets:o=>{Kv(vp.IS_SHOWING_GROUP_ANCHOR_OFFSETS,o),n({is_showing_group_anchor_offsets:o})},setIsShowingSolderMask:o=>{Kv(vp.IS_SHOWING_SOLDER_MASK,o),n({is_showing_solder_mask:o})},setIsShowingSilkscreen:o=>{Kv(vp.IS_SHOWING_SILKSCREEN,o),n({is_showing_silkscreen:o})},setIsShowingFabricationNotes:o=>{Kv(vp.IS_SHOWING_FABRICATION_NOTES,o),n({is_showing_fabrication_notes:o})},setIsShowingPcbNotes:o=>{Kv(vp.IS_SHOWING_PCB_NOTES,o),n({is_showing_pcb_notes:o})},setPcbGroupViewMode:o=>{e||(KKo(vp.PCB_GROUP_VIEW_MODE,o),n({pcb_group_view_mode:o}))},setHoveredErrorId:o=>n({hovered_error_id:o}),setFocusedErrorId:o=>n({focused_error_id:o})})),Cd=t=>{const e=Z.useContext(cLt);return uFt(e,t)},cLt=Z.createContext(null),zKo=({children:t,initialState:e,disablePcbGroups:n})=>{const o=Z.useMemo(()=>YKo(e,n),[n]);return W.jsx(cLt.Provider,{value:o,children:t})},VKo=()=>{Z.useEffect(()=>{_Oo()},[]);const t=Cd(e=>e.pcb_viewer_id);return W.jsx(hOo,{position:"top-center",containerId:t})};function JKo(){var t=Z.useRef(!1),e=Z.useCallback(function(){return t.current},[]);return Z.useEffect(function(){return t.current=!0,function(){t.current=!1}},[]),e}var qKo=function(t){t===void 0&&(t={});var e=Z.useState(t),n=e[0],o=e[1],i=Z.useCallback(function(r){o(function(s){return Object.assign({},s,r instanceof Function?r(s):r)})},[]);return[n,i]},WKo=qKo,jKo=function(){},lLt=typeof window<"u",XKo=$8e(pKo()),$Ko=function(){var t=JKo(),e=WKo({value:void 0,error:void 0,noUserInteraction:!0}),n=e[0],o=e[1],i=Z.useCallback(function(r){if(t()){var s,a;try{if(typeof r!="string"&&typeof r!="number"){var A=new Error("Cannot copy typeof "+typeof r+" to clipboard, must be a string");console.error(A),o({value:r,error:A,noUserInteraction:!0});return}else if(r===""){var A=new Error("Cannot copy empty string to clipboard.");console.error(A),o({value:r,error:A,noUserInteraction:!0});return}a=r.toString(),s=(0,XKo.default)(a),o({value:a,error:void 0,noUserInteraction:s})}catch(c){o({value:a,error:c,noUserInteraction:s})}}},[]);return[n,i]},ZKo=$Ko,eUo=lLt?Z.useLayoutEffect:Z.useEffect,tUo=eUo,gLt={x:0,y:0,width:0,height:0,top:0,left:0,bottom:0,right:0};function nUo(){var t=Z.useState(null),e=t[0],n=t[1],o=Z.useState(gLt),i=o[0],r=o[1],s=Z.useMemo(function(){return new window.ResizeObserver(function(a){if(a[0]){var A=a[0].contentRect,c=A.x,l=A.y,g=A.width,u=A.height,h=A.top,d=A.left,_=A.bottom,m=A.right;r({x:c,y:l,width:g,height:u,top:h,left:d,bottom:_,right:m})}})},[]);return tUo(function(){if(e)return s.observe(e),function(){s.disconnect()}},[e]),[n,i]}var pY=lLt&&typeof window.ResizeObserver<"u"?nUo:function(){return[jKo,gLt]},uLt=({initialTransform:t,initialTouch1:e,initialTouch2:n,finalTouch1:o,finalTouch2:i})=>{if(!o||!i)return t;const r={x:(e.x+n.x)/2,y:(e.y+n.y)/2},s={x:(o.x+i.x)/2,y:(o.y+i.y)/2},a=Math.hypot(n.x-e.x,n.y-e.y),A=Math.hypot(i.x-o.x,i.y-o.y),c=a===0?1:A/a,l=s.x-r.x,g=s.y-r.y;return ki(Wi(l,g),Wi(r.x,r.y),ug(c,c),Wi(-r.x,-r.y),t)},oUo=(t={})=>{const e=Z.useRef(null),[n,o]=Z.useState(0),i=t.canvasElm??e.current,[r,s]=Z.useState(t.initialTransform??Ll()),[a,A]=Z.useState(0),[c,l]=Z.useReducer(f=>f+1,0),g=Z.useCallback(f=>{t.onSetTransform&&t.onSetTransform(f),t.transform||s(f)},[t.onSetTransform,s]),u=Z.useCallback(f=>{g(f),l()},[g]),h=t.transform??r,d=Z.useCallback(()=>{o(Date.now())},[]),_=Z.useRef("none"),m=Z.useRef(null),p=Z.useRef(null);Z.useEffect(()=>{const f=t.canvasElm??e.current;if(f&&!i){A(a+1);return}if(!f){const q=setTimeout(()=>{A(a+1)},100);return()=>clearTimeout(q)}let C=t.transform??r,y={x:0,y:0},E={x:0,y:0},B=!1;const Q=q=>({x:q.pageX-f.getBoundingClientRect().left-window.scrollX,y:q.pageY-f.getBoundingClientRect().top-window.scrollY});function b(q){t.enabled!==!1&&(t.shouldDrag&&!t.shouldDrag(q)||(y=Q(q),!(Date.now()-n<100)&&(B=!0,q.preventDefault())))}function D(q){if(!B||t.enabled===!1||t.shouldDrag&&!t.shouldDrag(q))return;E=Q(q);const j=ki(Wi(E.x-y.x,E.y-y.y),C);g(j),C=j,B=!1}function R(q){if(Q(q),!B||t.enabled===!1||t.shouldDrag&&!t.shouldDrag(q))return;E=Q(q);const j=ki(Wi(E.x-y.x,E.y-y.y),C);g(j)}function w(q){if(t.enabled===!1||t.shouldDrag&&!t.shouldDrag(q))return;const j=Q(q),ne=ki(Wi(j.x,j.y),ug(1-q.deltaY/1e3,1-q.deltaY/1e3),Wi(-j.x,-j.y),C);g(ne),C=ne,q.preventDefault()}function H(q){if(!B||t.shouldDrag&&!t.shouldDrag(q))return;if(f){const ne=f.getBoundingClientRect();if(q.clientX>=ne.left+10&&q.clientX<=ne.right-10&&q.clientY>=ne.top+10&&q.clientY<=ne.bottom-10)return}B=!1,E=Q(q);const j=ki(Wi(E.x-y.x,E.y-y.y),C);g(j),C=j}function G(q){if(q.preventDefault(),t.enabled!==!1){if(q.touches.length===1){_.current="drag";const j=q.touches[0];m.current={initialTransform:C,initialTouch:{x:j.clientX,y:j.clientY}}}else if(q.touches.length===2){_.current="pinch";const j=q.touches[0],ne=q.touches[1];p.current={initialTransform:C,initialTouch1:{x:j.clientX,y:j.clientY},initialTouch2:{x:ne.clientX,y:ne.clientY},finalTouch1:null,finalTouch2:null}}}}function K(q){if(q.preventDefault(),t.enabled!==!1){if(_.current==="drag"&&q.touches.length===1&&m.current){const j=q.touches[0],ne={x:j.clientX,y:j.clientY},re=ne.x-m.current.initialTouch.x,X=ne.y-m.current.initialTouch.y,te=ki(Wi(re,X),m.current.initialTransform);g(te)}else if(_.current==="pinch"&&q.touches.length===2&&p.current){const j=q.touches[0],ne=q.touches[1];p.current.finalTouch1={x:j.clientX,y:j.clientY},p.current.finalTouch2={x:ne.clientX,y:ne.clientY};const re=uLt(p.current);g(re)}}}function U(q){q.preventDefault();const j=q.changedTouches[0];if(_.current==="drag"&&m.current&&j){const ne={x:j.clientX,y:j.clientY},re=ne.x-m.current.initialTouch.x,X=ne.y-m.current.initialTouch.y,te=ki(Wi(re,X),m.current.initialTransform);g(te),C=te}else if(_.current==="pinch"&&p.current){const ne=uLt(p.current);g(ne),C=ne}_.current="none",m.current=null,p.current=null}return f.addEventListener("mousedown",b),f.addEventListener("mouseup",D),window.addEventListener("mousemove",R),f.addEventListener("mouseout",H),f.addEventListener("wheel",w),f.addEventListener("touchstart",G,{passive:!1}),f.addEventListener("touchmove",K,{passive:!1}),f.addEventListener("touchend",U,{passive:!1}),f.addEventListener("touchcancel",U,{passive:!1}),()=>{f.removeEventListener("mousedown",b),f.removeEventListener("mouseup",D),window.removeEventListener("mousemove",R),f.removeEventListener("mouseout",H),f.removeEventListener("wheel",w),f.removeEventListener("touchstart",G),f.removeEventListener("touchmove",K),f.removeEventListener("touchend",U),f.removeEventListener("touchcancel",U)}},[i,a,c,n,t.enabled,t.shouldDrag]);const I=Z.useCallback(f=>mt(h,f),[h]);return{ref:e,transform:h,applyTransformToPoint:I,setTransform:u,cancelDrag:d}},iUo=oUo;function rUo(t){const e=new Map;let n=0;function o(i){for(const[,s]of e)if(s.has(i))return s;const r=new Set;return e.set(`connectivity_net${n++}`,r),r}for(const i of t){let r=null;for(const s of i){if(!r)r=o(s);else if(!r.has(s)){const a=o(s);if(a!==r){for(const A of a)r.add(A);e.delete(Array.from(e.entries()).find(([,A])=>A===a)[0])}}r.add(s)}}return Object.fromEntries(Array.from(e.entries()).map(([i,r])=>[i,Array.from(r)]))}var sUo=class{netMap;idToNetMap;constructor(t){this.netMap=t,this.idToNetMap={};for(const[e,n]of Object.entries(t))for(const o of n)this.idToNetMap[o]=e}addConnections(t){for(const e of t){const n=new Set;for(const i of e){const r=this.idToNetMap[i];r&&n.add(r)}let o;if(n.size===0)o=`connectivity_net${Object.keys(this.netMap).length}`,this.netMap[o]=[];else if(n.size===1)o=n.values().next().value??`connectivity_net${Object.keys(this.netMap).length}`;else{o=n.values().next().value??`connectivity_net${Object.keys(this.netMap).length}`;for(const i of n)if(i!==o){this.netMap[o].push(...this.netMap[i]),this.netMap[i]=this.netMap[o];for(const r of this.netMap[o])this.idToNetMap[r]=o}}for(const i of e)this.netMap[o].includes(i)||this.netMap[o].push(i),this.idToNetMap[i]=o}}getIdsConnectedToNet(t){return this.netMap[t]||[]}getNetConnectedToId(t){return this.idToNetMap[t]}areIdsConnected(t,e){if(t===e)return!0;const n=this.getNetConnectedToId(t);if(!n)return!1;const o=this.getNetConnectedToId(e);return o?n===o||o===t||o===t:!1}areAllIdsConnected(t){const e=this.getNetConnectedToId(t[0]);for(const n of t){const o=this.getNetConnectedToId(n);if(o===void 0||o!==e)return!1}return!0}},dLt=t=>{const e=[];for(const o of t)if(o.type==="source_trace")e.push([o.source_trace_id,...o.connected_source_port_ids??[],...o.connected_source_net_ids??[]].filter(Boolean));else if(o.type==="pcb_port"){const{pcb_port_id:i,source_port_id:r}=o;r&&i&&e.push([r,i])}else if(o.type==="pcb_smtpad"){const{pcb_smtpad_id:i,pcb_port_id:r}=o;r&&i&&e.push([i,r])}else if(o.type==="pcb_plated_hole"){const{pcb_plated_hole_id:i,pcb_port_id:r}=o;r&&i&&e.push([i,r])}else if(o.type==="pcb_trace"){const{pcb_trace_id:i,source_trace_id:r}=o,s=Array.isArray(o.route)?o.route.filter(a=>a&&a.route_type==="wire"):[];if(r&&i&&e.push([i,r]),Array.isArray(s)){const a=s.find(c=>c?.start_pcb_port_id)?.start_pcb_port_id,A=s.find(c=>c?.end_pcb_port_id)?.end_pcb_port_id;a&&i&&A&&e.push([a,i,A])}}else if(o.type==="pcb_via"){const{pcb_via_id:i,pcb_trace_id:r}=o;r&&i&&e.push([i,r])}else if(o.type==="source_component"&&o.internally_connected_source_port_ids)for(const i of o.internally_connected_source_port_ids)e.push(i);const n=rUo(e);return new sUo(n)};function aUo(t,e){if(t.length<2)throw new Error("Stroke must have at least two points");const n=t.map(g=>Array.isArray(g)?{x:g[0],y:g[1]}:g),o=[],i=[];function r(g,u){const h=u.x-g.x,d=u.y-g.y,_=Math.sqrt(h*h+d*d);return{x:-d/_,y:h/_}}function s(g,u,h,d){const _=d/2,m={x:g.x+u.x*_*h,y:g.y+u.y*_*h};h>0?o.push(m):i.unshift(m)}const a=r(n[0],n[1]),A=n[0].trace_width??e;s(n[0],a,1,A),s(n[0],a,-1,A);for(let g=1;g<n.length-1;g++){const u=n[g-1],h=n[g],d=n[g+1],_=r(u,h),m=r(h,d),p=_.x+m.x,I=_.y+m.y,f=Math.sqrt(p*p+I*I),C=h.trace_width??e;if(f/2>2*(C/2))s(h,_,1,C),s(h,m,1,C),s(h,_,-1,C),s(h,m,-1,C);else{const E=1/f;s(h,{x:p*E,y:I*E},1,C),s(h,{x:p*E,y:I*E},-1,C)}}const c=r(n[n.length-2],n[n.length-1]),l=n[n.length-1].trace_width??e;return s(n[n.length-1],c,1,l),s(n[n.length-1],c,-1,l),[...o,...i]}var AUo=(t,e)=>{const{x:n,y:o,width:i,height:r,layer:s,rect_border_radius:a}=t,A=t.corner_radius??a??0,c=[{_pcb_drawing_object_id:UB("rect"),pcb_drawing_type:"rect",x:n,y:o,w:i,h:r,layer:s||"top",_element:t,_parent_pcb_component:e._parent_pcb_component,_parent_source_component:e._parent_source_component,_source_port:e._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 l=s==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",u={...{_pcb_drawing_object_id:UB("rect"),pcb_drawing_type:"rect",x:n,y:o,w:i,h:r,layer:l,_element:t,_parent_pcb_component:e._parent_pcb_component,_parent_source_component:e._parent_source_component,_source_port:e._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}:{}};c.push(u)}return c},cUo=(t,e)=>{const{x:n,y:o,radius:i,layer:r}=t,s=[{_pcb_drawing_object_id:UB("circle"),pcb_drawing_type:"circle",x:n,y:o,r:i,layer:r||"top",_element:t,_parent_pcb_component:e._parent_pcb_component,_parent_source_component:e._parent_source_component,_source_port:e._source_port}];if(t.is_covered_with_solder_mask){const a=r==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",A={_pcb_drawing_object_id:UB("circle"),pcb_drawing_type:"circle",x:n,y:o,r:i,layer:a,_element:t,_parent_pcb_component:e._parent_pcb_component,_parent_source_component:e._parent_source_component,_source_port:e._source_port,..."solder_mask_color"in t&&t.solder_mask_color?{color:t.solder_mask_color}:{}};s.push(A)}return s},lUo=(t,e)=>{const{layer:n,points:o}=t,i=[{_pcb_drawing_object_id:UB("polygon"),pcb_drawing_type:"polygon",points:r9e(o),layer:n||"top",_element:t,_parent_pcb_component:e._parent_pcb_component,_parent_source_component:e._parent_source_component,_source_port:e._source_port}];if(t.is_covered_with_solder_mask){const r=n==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",s={_pcb_drawing_object_id:UB("polygon"),pcb_drawing_type:"polygon",points:r9e(o),layer:r,_element:t,_parent_pcb_component:e._parent_pcb_component,_parent_source_component:e._parent_source_component,_source_port:e._source_port,..."solder_mask_color"in t&&t.solder_mask_color?{color:t.solder_mask_color}:{}};i.push(s)}return i},gUo=(t,e)=>{const{x:n,y:o,width:i,height:r,layer:s}=t,a=[{_pcb_drawing_object_id:UB("pill"),pcb_drawing_type:"pill",x:n,y:o,w:i,h:r,layer:s||"top",_element:t,_parent_pcb_component:e._parent_pcb_component,_parent_source_component:e._parent_source_component,_source_port:e._source_port}];if(t.is_covered_with_solder_mask){const A=s==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",c={_pcb_drawing_object_id:UB("pill"),pcb_drawing_type:"pill",x:n,y:o,w:i,h:r,layer:A,_element:t,_parent_pcb_component:e._parent_pcb_component,_parent_source_component:e._parent_source_component,_source_port:e._source_port,..."solder_mask_color"in t&&t.solder_mask_color?{color:t.solder_mask_color}:{}};a.push(c)}return a},uUo=(t,e)=>{const{x:n,y:o,width:i,height:r,layer:s,ccw_rotation:a}=t,A=[{_pcb_drawing_object_id:UB("pill"),pcb_drawing_type:"pill",x:n,y:o,w:i,h:r,layer:s||"top",_element:t,_parent_pcb_component:e._parent_pcb_component,_parent_source_component:e._parent_source_component,_source_port:e._source_port,ccw_rotation:a}];if(t.is_covered_with_solder_mask){const c=s==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",l={_pcb_drawing_object_id:UB("pill"),pcb_drawing_type:"pill",x:n,y:o,w:i,h:r,layer:c,_element:t,_parent_pcb_component:e._parent_pcb_component,_parent_source_component:e._parent_source_component,_source_port:e._source_port,ccw_rotation:a,..."solder_mask_color"in t&&t.solder_mask_color?{color:t.solder_mask_color}:{}};A.push(l)}return A},r0=0,UB=t=>`${t}_${r0++}`,r9e=t=>(t??[]).map(e=>({x:En.parse(e.x),y:En.parse(e.y)})),dUo=(t,e)=>{const n="pcb_component_id"in t?e.find(s=>s.type==="pcb_component"&&s.pcb_component_id===t.pcb_component_id):void 0,o=n&&"source_component_id"in n?e.find(s=>s.type==="source_component"&&s.source_component_id===n.source_component_id):void 0,i="source_port_id"in t?t.source_port_id:"pcb_port_id"in t?N6(e).pcb_port.get(t.pcb_port_id)?.source_port_id:void 0,r=i?e.find(s=>s.type==="source_port"&&s.source_port_id===i):void 0;switch(t.type){case"pcb_smtpad":{const s={_parent_pcb_component:n,_parent_source_component:o,_source_port:r};return t.shape==="rect"||t.shape==="rotated_rect"?AUo(t,s):t.shape==="circle"?cUo(t,s):t.shape==="polygon"?lUo(t,s):t.shape==="pill"?gUo(t,s):t.shape==="rotated_pill"?uUo(t,s):[]}case"pcb_trace":{const s=[];if(t.route_thickness_mode==="interpolated"){const c=t.route.flatMap(u=>u.route_type==="through_pad"?[{...u.start,trace_width:u.width},{...u.end,trace_width:u.width}]:[{x:u.x,y:u.y,trace_width:u.route_type==="wire"?u.width:.5}]),l=aUo(c,.5),g=t.route[0].layer;return s.push({_pcb_drawing_object_id:`polygon_${r0++}`,_element:t,pcb_drawing_type:"polygon",points:l,layer:g}),t.route.forEach(u=>{u.route_type==="via"&&s.push({_pcb_drawing_object_id:`circle_${r0++}`,_element:t,pcb_drawing_type:"circle",x:u.x,y:u.y,r:u.outer_diameter/2,layer:u.from_layer})}),s}let a=null,A=null;for(const c of t.route)c.route_type==="wire"&&(a!==null&&A!==null&&s.push({_pcb_drawing_object_id:`line_${r0++}`,_element:t,pcb_drawing_type:"line",x1:a,y1:A,x2:c.x,y2:c.y,width:c.width,squareCap:!1,layer:c.layer}),a=c.x,A=c.y);return s}case"pcb_via":{const{x:s,y:a,outer_diameter:A,hole_diameter:c}=t,l=t.from_layer,g=t.to_layer,u=t.layers,h=[];l&&g?h.push(l,g):u&&Array.isArray(u)?h.push(...u):h.push("top","bottom");const d=[];for(const _ of h)d.push({_pcb_drawing_object_id:`circle_${r0++}`,pcb_drawing_type:"circle",x:s,y:a,r:A/2,layer:_,_element:t,_parent_pcb_component:n,_parent_source_component:o});return d.push({_pcb_drawing_object_id:`circle_${r0++}`,pcb_drawing_type:"circle",x:s,y:a,r:c/2,layer:"drill",_element:t}),d}case"pcb_plated_hole":if(t.shape==="circle"){const{x:s,y:a,hole_diameter:A,outer_diameter:c}=t;return[{_pcb_drawing_object_id:`circle_${r0++}`,pcb_drawing_type:"circle",x:s,y:a,r:c/2,layer:"top",_element:t,_parent_pcb_component:n,_parent_source_component:o,_source_port:r},{_pcb_drawing_object_id:`circle_${r0++}`,pcb_drawing_type:"circle",x:s,y:a,r:A/2,layer:"drill",_element:t}]}else if(t.shape==="oval"){const{x:s,y:a,outer_height:A,outer_width:c,hole_height:l,hole_width:g}=t;return[{_pcb_drawing_object_id:`oval_${r0++}`,pcb_drawing_type:"oval",x:s,y:a,rX:c/2,rY:A/2,layer:"top",_element:t,_parent_pcb_component:n,_parent_source_component:o,_source_port:r},{_pcb_drawing_object_id:`oval_${r0++}`,_element:t,pcb_drawing_type:"oval",x:s,y:a,rX:g/2,rY:l/2,layer:"drill"}]}else if(t.shape==="pill"){const{x:s,y:a,outer_height:A,outer_width:c,hole_height:l,hole_width:g}=t;return[{_pcb_drawing_object_id:`pill_${r0++}`,pcb_drawing_type:"pill",x:s,y:a,w:c,h:A,layer:"top",_element:t,_parent_pcb_component:n,_parent_source_component:o,_source_port:r,ccw_rotation:t.ccw_rotation},{_pcb_drawing_object_id:`pill_${r0++}`,_element:t,pcb_drawing_type:"pill",x:s,y:a,w:g,h:l,layer:"drill",ccw_rotation:t.ccw_rotation}]}else if(t.shape==="circular_hole_with_rect_pad"){const{x:s,y:a,hole_diameter:A,rect_pad_width:c,rect_pad_height:l,rect_border_radius:g,hole_offset_x:u,hole_offset_y:h}=t,d=En.parse(u??0),_=En.parse(h??0);return[{_pcb_drawing_object_id:`rect_${r0++}`,pcb_drawing_type:"rect",x:s,y:a,w:c,h:l,layer:"top",_element:t,_parent_pcb_component:n,_parent_source_component:o,_source_port:r,roundness:g},{_pcb_drawing_object_id:`rect_${r0++}`,pcb_drawing_type:"rect",x:s,y:a,w:c,h:l,layer:"bottom",_element:t,_parent_pcb_component:n,_parent_source_component:o,_source_port:r,roundness:g,is_hoverable:!1},{_pcb_drawing_object_id:`circle_${r0++}`,_element:t,pcb_drawing_type:"circle",x:s+d,y:a+_,r:A/2,layer:"drill",is_hoverable:!1}]}else if(t.shape==="pill_hole_with_rect_pad"){const{x:s,y:a,hole_width:A,hole_height:c,rect_pad_width:l,rect_pad_height:g,rect_border_radius:u}=t;return[{_pcb_drawing_object_id:`rect_${r0++}`,pcb_drawing_type:"rect",x:s,y:a,w:l,h:g,layer:"top",_element:t,_parent_pcb_component:n,_parent_source_component:o,_source_port:r,roundness:u},{_pcb_drawing_object_id:`rect_${r0++}`,pcb_drawing_type:"rect",x:s,y:a,w:l,h:g,layer:"bottom",_element:t,_parent_pcb_component:n,_parent_source_component:o,_source_port:r,roundness:u,is_hoverable:!1},{_pcb_drawing_object_id:`pill_${r0++}`,_element:t,pcb_drawing_type:"pill",x:s,y:a,w:A,h:c,layer:"drill",is_hoverable:!1}]}else if(t.shape==="rotated_pill_hole_with_rect_pad"){const{x:s,y:a,hole_width:A,hole_height:c,hole_ccw_rotation:l,rect_pad_width:g,rect_pad_height:u,rect_ccw_rotation:h,rect_border_radius:d}=t;return[{_pcb_drawing_object_id:`rect_${r0++}`,pcb_drawing_type:"rect",x:s,y:a,w:g,h:u,layer:"top",_element:t,_parent_pcb_component:n,_parent_source_component:o,_source_port:r,ccw_rotation:h,roundness:d},{_pcb_drawing_object_id:`rect_${r0++}`,pcb_drawing_type:"rect",x:s,y:a,w:g,h:u,layer:"bottom",_element:t,_parent_pcb_component:n,_parent_source_component:o,_source_port:r,ccw_rotation:h,roundness:d,is_hoverable:!1},{_pcb_drawing_object_id:`pill_${r0++}`,_element:t,pcb_drawing_type:"pill",x:s,y:a,w:A,h:c,layer:"drill",ccw_rotation:l,is_hoverable:!1}]}else if(t.shape==="hole_with_polygon_pad"){const{x:s,y:a,pad_outline:A,hole_shape:c,hole_diameter:l,hole_width:g,hole_height:u,layers:h,hole_offset_x:d,hole_offset_y:_}=t,m=En.parse(d??0),p=En.parse(_??0),I=A,f=[];if(I&&Array.isArray(I)){const E=r9e(I).map(B=>({x:B.x+s,y:B.y+a}));for(const B of h||["top","bottom"])f.push({_pcb_drawing_object_id:`polygon_${r0++}`,pcb_drawing_type:"polygon",points:E,layer:B,_element:t,_parent_pcb_component:n,_parent_source_component:o,_source_port:r})}const C={x:s+m,y:a+p},y=[];return c==="circle"?y.push({_pcb_drawing_object_id:`circle_${r0++}`,pcb_drawing_type:"circle",x:C.x,y:C.y,r:(l??0)/2,layer:"drill",_element:t,_parent_pcb_component:n,_parent_source_component:o}):c==="oval"?y.push({_pcb_drawing_object_id:`oval_${r0++}`,pcb_drawing_type:"oval",x:C.x,y:C.y,rX:(g??0)/2,rY:(u??0)/2,layer:"drill",_element:t,_parent_pcb_component:n,_parent_source_component:o}):(c==="pill"||c==="rotated_pill")&&y.push({_pcb_drawing_object_id:`pill_${r0++}`,pcb_drawing_type:"pill",x:C.x,y:C.y,w:g??0,h:u??0,layer:"drill",_element:t,_parent_pcb_component:n,_parent_source_component:o,ccw_rotation:t.ccw_rotation}),[...f,...y]}else return[]}return[]};function hUo({primitivesWithoutInteractionMetadata:t,drawingObjectIdsWithMouseOver:e,primitiveIdsInMousedOverNet:n}){const o=[];for(const i of t){const r={...i},s=i._element,a=i._parent_pcb_component;i?.layer==="drill"?(r.is_in_highlighted_net=!1,r.is_mouse_over=!1):e.has(i._pcb_drawing_object_id)?r.is_mouse_over=!0:s&&("pcb_trace_id"in s&&n.includes(s.pcb_trace_id)||"pcb_port_id"in s&&n.includes(s.pcb_port_id)||"pcb_via_id"in s&&n.includes(s.pcb_via_id)||"pcb_component_id"in s&&n.includes(s.pcb_component_id)||a&&"pcb_component_id"in a&&n.includes(a.pcb_component_id))?r.is_in_highlighted_net=!0:(r.is_in_highlighted_net=!1,r.is_mouse_over=!1),o.push(r)}return o}var hLt=t=>{const e=new Map,n=new Map,o=new Map,i=new Map,r=new Map;for(const s of t)s.type==="pcb_trace"&&s.pcb_trace_id?e.set(s.pcb_trace_id,s):s.type==="pcb_port"&&s.pcb_port_id?n.set(s.pcb_port_id,s):s.type==="pcb_via"&&s.pcb_via_id?o.set(s.pcb_via_id,s):s.type==="pcb_component"&&s.pcb_component_id?i.set(s.pcb_component_id,s):s.type==="pcb_board"&&s.pcb_board_id&&r.set(s.pcb_board_id,s);return{tracesById:e,portsById:n,viasById:o,componentsById:i,boardsById:r}},Qx=(t,e)=>e?t?{minX:Math.min(t.minX,e.minX),maxX:Math.max(t.maxX,e.maxX),minY:Math.min(t.minY,e.minY),maxY:Math.max(t.maxY,e.maxY)}:e:t,R6=(t,e=.45)=>({minX:t.x-e,maxX:t.x+e,minY:t.y-e,maxY:t.y+e}),_Uo=t=>{if(t.length===0)return null;let e=null;for(const n of t){const o=Math.max((n.width??.2)/2,.3);e=Qx(e,R6(n,o))}return e},_Lt=t=>{if(!t?.center)return null;const e=Math.max(t.width??0,1.2),n=Math.max(t.height??0,1.2);return{minX:t.center.x-e/2,maxX:t.center.x+e/2,minY:t.center.y-n/2,maxY:t.center.y+n/2}},mUo=t=>!t?.center||typeof t.width!="number"||typeof t.height!="number"?null:{minX:t.center.x-t.width/2,maxX:t.center.x+t.width/2,minY:t.center.y-t.height/2,maxY:t.center.y+t.height/2},pUo=(t,e)=>({minX:t.minX-e,maxX:t.maxX+e,minY:t.minY-e,maxY:t.maxY+e}),IUo=(t,e=.35)=>{const n=mp(t);return n?pUo(n,e):null},mLt=({error:t,tracesById:e,portsById:n,viasById:o,componentsById:i})=>{if(t.center)return t.center;if(t.pcb_center)return t.pcb_center;if(t.component_center)return t.component_center;if(t.pcb_via_ids?.length){const r=t.pcb_via_ids.map(s=>o.get(s)).filter(Boolean);if(r.length>0)return{x:r.reduce((s,a)=>s+a.x,0)/r.length,y:r.reduce((s,a)=>s+a.y,0)/r.length}}if(t.pcb_port_ids?.length){const r=t.pcb_port_ids.map(s=>n.get(s)).filter(Boolean);if(r.length>0)return{x:r.reduce((s,a)=>s+a.x,0)/r.length,y:r.reduce((s,a)=>s+a.y,0)/r.length}}if(t.pcb_trace_id){const r=e.get(t.pcb_trace_id);if(r?.route?.length){const s=Math.floor(r.route.length/2);return{x:r.route[s].x,y:r.route[s].y}}}return t.pcb_component_id?i.get(t.pcb_component_id)?.center??null:null},fUo=({error:t,indexes:e})=>mLt({error:t,...e}),CUo=({error:t,boardsById:e})=>{if(!t.component_bounds||!t.pcb_board_id)return null;const n=mUo(e.get(t.pcb_board_id));if(!n)return null;const o=t.component_bounds,i=[];return o.min_x<n.minX&&(i.push({x:n.minX,y:Math.max(o.min_y,n.minY)}),i.push({x:n.minX,y:Math.min(o.max_y,n.maxY)})),o.max_x>n.maxX&&(i.push({x:n.maxX,y:Math.max(o.min_y,n.minY)}),i.push({x:n.maxX,y:Math.min(o.max_y,n.maxY)})),o.min_y<n.minY&&(i.push({x:Math.max(o.min_x,n.minX),y:n.minY}),i.push({x:Math.min(o.max_x,n.maxX),y:n.minY})),o.max_y>n.maxY&&(i.push({x:Math.max(o.min_x,n.minX),y:n.maxY}),i.push({x:Math.min(o.max_x,n.maxX),y:n.maxY})),IUo(i,.3)},pLt=new Set(["source_failed_to_create_component_error"]),yUo=({error:t,indexes:e})=>{if(pLt.has(t.error_type)||pLt.has(t.type))return null;let n=null;const o=mLt({error:t,...e});if(o&&(n=Qx(n,R6(o,.35))),t.error_type==="pcb_component_outside_board_error"?n=Qx(n,CUo({error:t,boardsById:e.boardsById})):t.component_bounds&&!o&&(n=Qx(n,{minX:t.component_bounds.min_x,maxX:t.component_bounds.max_x,minY:t.component_bounds.min_y,maxY:t.component_bounds.max_y})),t.center&&!o&&(n=Qx(n,R6(t.center))),t.pcb_center&&!o&&(n=Qx(n,R6(t.pcb_center))),t.component_center&&!o&&(n=Qx(n,R6(t.component_center))),t.pcb_port_ids&&!o)for(const i of t.pcb_port_ids){const r=e.portsById.get(i);r&&(n=Qx(n,R6({x:r.x,y:r.y},.4)))}if(t.pcb_trace_id&&!o){const i=e.tracesById.get(t.pcb_trace_id);i?.route&&(n=Qx(n,_Uo(i.route)))}if(t.pcb_via_ids)for(const i of t.pcb_via_ids){const r=e.viasById.get(i);r&&(n=Qx(n,R6({x:r.x,y:r.y},Math.max((r.outer_diameter??.5)/2,.28))))}if(t.pcb_component_id&&!o&&(n=Qx(n,_Lt(e.componentsById.get(t.pcb_component_id)))),t.pcb_component_ids&&!o)for(const i of t.pcb_component_ids)n=Qx(n,_Lt(e.componentsById.get(i)));return n},EUo=({bounds:t,width:e,height:n})=>{const o={x:(t.minX+t.maxX)/2,y:(t.minY+t.maxY)/2},i=Math.max(t.maxX-t.minX,.8)+1.4,r=Math.max(t.maxY-t.minY,.8)+1.4,s=Math.min(e/i,n/r,240)*.92;return ki(Wi(e/2,n/2),ug(s,-s,0,0),Wi(-o.x,-o.y))},xUo=t=>{const e=new Set;t.pcb_trace_id&&e.add(t.pcb_trace_id);for(const n of t.pcb_port_ids??[])e.add(n);for(const n of t.pcb_via_ids??[])e.add(n);t.pcb_component_id&&e.add(t.pcb_component_id);for(const n of t.pcb_component_ids??[])e.add(n);return[...e]},Bk=(t,e)=>{const n=["pcb_trace_error_id","pcb_via_clearance_error_id","pcb_component_outside_board_error_id","source_failed_to_create_component_error_id","pcb_error_id"];for(const o of n)if(typeof t?.[o]=="string"&&t[o].length>0)return t[o];for(const[o,i]of Object.entries(t??{}))if(o.endsWith("_error_id")&&typeof i=="string"&&i.length>0)return i;return`error_${e}_${t?.error_type}_${t?.message?.slice(0,20)}`},ILt=(t,e)=>e?t.find((n,o)=>n.type?.includes("error")?Bk(n,o)===e:!1)??null:null,BUo=t=>1-(1-t)**3,QUo=(t,e,n)=>({a:t.a+(e.a-t.a)*n,b:t.b+(e.b-t.b)*n,c:t.c+(e.c-t.c)*n,d:t.d+(e.d-t.d)*n,e:t.e+(e.e-t.e)*n,f:t.f+(e.f-t.f)*n}),fLt=t=>{t!==null&&window.cancelAnimationFrame(t)},SUo=({startTransform:t,endTransform:e,durationMs:n,onUpdate:o,setAnimationFrameId:i,onComplete:r})=>{const s=performance.now(),a=c=>{const l=c-s,g=Math.min(1,l/n),u=BUo(g);if(o(QUo(t,e,u)),g<1){i(window.requestAnimationFrame(a));return}i(null),r?.()},A=window.requestAnimationFrame(a);return i(A),A},Fo={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)"}},My=(t,e=1)=>{if(Math.abs(t.a)!==Math.abs(t.d))throw new Error("Cannot scale non-uniformly");return e*Math.abs(t.a)},Yg={elementOverlay:40,dimensionOverlay:40,errorOverlay:40,pcbGroupOverlay:35,ratsNestOverlay:30,toolbarOverlay:70,warnings:30,topLayer:30,clickToInteractOverlay:100},vse={red:"red",black:"black",green:"green",board:"rgb(255, 255, 255)",other:"#eee",top:Fo.board.copper.f,inner1:Fo.board.copper.in1,inner2:Fo.board.copper.in2,inner3:Fo.board.copper.in3,inner4:Fo.board.copper.in4,inner5:Fo.board.copper.in5,inner6:Fo.board.copper.in6,inner7:Fo.board.copper.in7,inner8:Fo.board.copper.in8,bottom:Fo.board.copper.b,drill:Fo.board.anchor,keepout:Fo.board.background,tkeepout:Fo.board.b_crtyd,tplace:Fo.board.b_silks,top_courtyard:Fo.board.f_crtyd,bottom_courtyard:Fo.board.b_crtyd,top_silkscreen:Fo.board.f_silks,bottom_silkscreen:Fo.board.b_silks,top_fabrication:Fo.board.f_fab,bottom_fabrication:Fo.board.b_fab,soldermask_top:Fo.board.soldermask.top,soldermask_bottom:Fo.board.soldermask.bottom,soldermask_with_copper_top:Fo.board.soldermaskWithCopper.top,soldermask_with_copper_bottom:Fo.board.soldermaskWithCopper.bottom,bottom_notes:Fo.board.user_2,top_notes:Fo.board.user_2,...Fo.board},bUo=["board","bottom","soldermask_bottom","bottom_silkscreen","top","soldermask_top","bottom_courtyard","bottom_fabrication","top_courtyard","top_fabrication","edge_cuts","top_silkscreen"],DUo=class{canvasLayerMap;ctxLayerMap;aperture;transform;foregroundLayer="top";lastPoint;constructor(t){this.canvasLayerMap=t,this.ctxLayerMap=Object.fromEntries(Object.entries(t).map(([e,n])=>[e,n.getContext("2d")])),this.transform=Ll(),this.transform.d*=-1,this.transform=ki(this.transform,Wi(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,e,n,o,i,r=45){const s=this.getLayerCtx(),[a,A]=mt(this.transform,[t,e]),[c,l]=mt(this.transform,[t+n,e+o]),g=My(this.transform,i);s.lineWidth=1,s.strokeStyle=this.aperture.color;const u=h=>{const d=Math.sin(h),_=Math.cos(h),m=Math.sqrt((c-a)**2+(l-A)**2);for(let p=-m;p<=m;p+=g)s.beginPath(),s.moveTo(a+p*_-m*d,A+p*d+m*_),s.lineTo(a+p*_+m*d,A+p*d-m*_),s.stroke()};u(r*Math.PI/180),u((r+90)*Math.PI/180)}rect({x:t,y:e,w:n,h:o,mesh_fill:i,is_filled:r=!0,has_stroke:s,is_stroke_dashed:a,stroke_width:A,roundness:c}){const[l,g]=mt(this.transform,[t-n/2,e-o/2]),[u,h]=mt(this.transform,[t+n/2,e+o/2]);this.applyAperture();const d=this.getLayerCtx(),_=c?My(this.transform,c):0,m=s===void 0?r===!1:s;if(i)d.save(),d.beginPath(),_>0&&d.roundRect?d.roundRect(l,g,u-l,h-g,_):d.rect(l,g,u-l,h-g),d.clip(),this.drawMeshPattern(t-n/2,e-o/2,n,o,.15),d.restore(),_>0&&d.roundRect?(d.beginPath(),d.roundRect(l,g,u-l,h-g,_),d.stroke()):d.strokeRect(l,g,u-l,h-g);else if(r!==!1&&(_>0&&d.roundRect?(d.beginPath(),d.roundRect(l,g,u-l,h-g,_),d.fill()):d.fillRect(l,g,u-l,h-g)),m){const p=d.lineWidth;if(A!==void 0&&(d.lineWidth=My(this.transform,A)),a){let I=[];const f=Math.abs(this.transform.a);if(f>0){const y=.1*f,E=y*1.3;y>.5&&(I=[y,E])}d.setLineDash(I)}_>0&&d.roundRect?(d.beginPath(),d.roundRect(l,g,u-l,h-g,_),d.stroke()):d.strokeRect(l,g,u-l,h-g),a&&d.setLineDash([]),A!==void 0&&(d.lineWidth=p)}}rotatedRect(t,e,n,o,i,r,s){const a=this.getLayerCtx();this.applyAperture();const[A,c]=mt(this.transform,[t-n/2,e-o/2]),[l,g]=mt(this.transform,[t+n/2,e+o/2]),u=r?My(this.transform,r):0;a.save();const[h,d]=mt(this.transform,[t,e]);a.translate(h,d);const _=360-i;i&&a.rotate(_*Math.PI/180),a.translate(-h,-d),s?(a.beginPath(),u>0&&a.roundRect?a.roundRect(A,c,l-A,g-c,u):a.rect(A,c,l-A,g-c),a.clip(),this.drawMeshPattern(t-n/2,e-o/2,n,o,.15),u>0&&a.roundRect?(a.beginPath(),a.roundRect(A,c,l-A,g-c,u),a.stroke()):a.strokeRect(A,c,l-A,g-c)):u>0&&a.roundRect?(a.beginPath(),a.roundRect(A,c,l-A,g-c,u),a.fill()):a.fillRect(A,c,l-A,g-c),a.restore()}rotatedPill(t,e,n,o,i){const r=this.getLayerCtx();this.applyAperture(),r.save();const[s,a]=mt(this.transform,[t,e]);r.translate(s,a);const A=360-i;i&&r.rotate(A*Math.PI/180),r.translate(-s,-a),this.pill(t,e,n,o),r.restore()}circle(t,e,n,o,i=!0){const r=My(this.transform,n),[s,a]=mt(this.transform,[t,e]);this.applyAperture();const A=this.getLayerCtx();o?(A.save(),A.beginPath(),A.arc(s,a,r,0,2*Math.PI),A.clip(),this.drawMeshPattern(t-n,e-n,n*2,n*2,.15),A.restore(),A.beginPath(),A.arc(s,a,r,0,2*Math.PI),A.stroke()):(A.beginPath(),A.arc(s,a,r,0,2*Math.PI),A.fill())}oval(t,e,n,o){const i=My(this.transform,n),r=My(this.transform,o),[s,a]=mt(this.transform,[t,e]);this.applyAperture();const A=this.getLayerCtx();A.beginPath(),A.ellipse(s,a,i,r,0,0,2*Math.PI),A.fill(),A.closePath()}pill(t,e,n,o){const[i,r]=mt(this.transform,[t-n/2,e+o/2]),s=My(this.transform,n),a=My(this.transform,o),A=Math.min(s,a)/2;this.applyAperture();const c=this.getLayerCtx();c.beginPath(),c.arc(i+A,r+A,A,Math.PI,Math.PI*1.5),c.arc(i+s-A,r+A,A,Math.PI*1.5,0),c.arc(i+s-A,r+a-A,A,0,Math.PI*.5),c.arc(i+A,r+a-A,A,Math.PI*.5,Math.PI),c.fill(),c.closePath()}polygon(t){if(t.length<3)return;this.applyAperture();const e=this.getLayerCtx(),n=t.map(i=>mt(this.transform,[i.x,i.y]));e.beginPath(),e.moveTo(n[0][0],n[0][1]);for(let i=1;i<n.length;i++)e.lineTo(n[i][0],n[i][1]);e.closePath(),e.fill("evenodd");const o=My(this.transform,this.aperture.size);o>0&&(e.lineWidth=o,e.stroke())}debugText(t,e,n){const[o,i]=mt(this.transform,[e,n]);this.applyAperture();const r=this.getLayerCtx();r.font="10px sans-serif",r.fillText(t,o,i)}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:e}=this,o=["board",...Object.keys(t).filter(u=>/^inner\d+$/.test(u)).sort((u,h)=>Number(h.slice(5))-Number(u.slice(5))),...bUo.filter(u=>u!=="board")],i=e==="top"?"soldermask_top":e==="bottom"?"soldermask_bottom":void 0,r=e==="top"?"top_silkscreen":e==="bottom"?"bottom_silkscreen":void 0,s=e==="top"?"top_notes":e==="bottom"?"bottom_notes":void 0,a=e==="top"?"top_fabrication":e==="bottom"?"bottom_fabrication":void 0,A=e==="top"?"top_courtyard":e==="bottom"?"bottom_courtyard":void 0,c=new Set([e,"drill","edge_cuts","other","board",...i?[i]:[],...r?[r]:[],...s?[s]:[],...a?[a]:[],...A?[A]:[]]),l=[e,"edge_cuts",...i?[i]:[],...r?[r]:[],...s?[s]:[],...a?[a]:[],...A?[A]:[]],g=[...o.filter(u=>!l.includes(u)),...e==="drill"?[]:[e],...i?[i]:[],"edge_cuts",...r?[r]:[],...s?[s]:[],...a?[a]:[],...A?[A]:[],"drill"];g.forEach((u,h)=>{const d=t[u];d&&(d.style.zIndex=`${Yg.topLayer-(g.length-h)}`,d.style.opacity=c.has(u)?"1":"0.5")})}applyAperture(){const{transform:t,aperture:e}=this;let{size:n,mode:o,color:i,fontSize:r,layer:s}=e;s in this.ctxLayerMap||(this.aperture.layer="other");const a=this.getLayerCtx();if(!a)throw new Error(`No context for layer "${this.foregroundLayer}"`);if(i||(i="undefined"),a.lineWidth=My(t,n),a.lineCap="round",o==="add"){a.globalCompositeOperation="source-over";let A=vse[i.toLowerCase()];if(!A)try{A=Kr(i).rgb().toString()}catch{console.warn(`Invalid color format: '${i}'`),A="white"}a.fillStyle=A,a.strokeStyle=A}else a.globalCompositeOperation="destination-out",a.fillStyle="rgba(0,0,0,1)",a.strokeStyle="rgba(0,0,0,1)";a.font=`${My(QQ(t),r)}px sans-serif`}moveTo(t,e){this.lastPoint={x:t,y:e}}lineTo(t,e){const[n,o]=mt(this.transform,[t,e]),{size:i,shape:r,mode:s}=this.aperture,a=My(this.transform,i),{lastPoint:A}=this,c=mt(this.transform,A);this.applyAperture();const l=this.getLayerCtx();r==="square"&&l.fillRect(c.x-a/2,c.y-a/2,a,a),l.beginPath(),l.moveTo(c.x,c.y),l.lineTo(n,o),l.stroke(),l.closePath(),r==="square"&&l.fillRect(n-a/2,o-a/2,a,a),this.lastPoint={x:t,y:e}}polygonWithArcs(t){const e=this.getLayerCtx(),n=o=>{if(o.vertices.length===0)return;const i=o.vertices[0],r=mt(this.transform,[i.x,i.y]);e.moveTo(r[0],r[1]);for(let s=0;s<o.vertices.length;s++){const a=o.vertices[s],A=o.vertices[(s+1)%o.vertices.length];if(a.bulge&&a.bulge!==0){const c=a.bulge,l=A.x-a.x,g=A.y-a.y,u=Math.sqrt(l*l+g*g);if(u<1e-9){const w=mt(this.transform,[A.x,A.y]);e.lineTo(w[0],w[1]);continue}const h=4*Math.atan(c),d=Math.abs(u/(2*Math.sin(h/2))),_=(a.x+A.x)/2,m=(a.y+A.y)/2,p=l/u,f=-(g/u),C=p,y=Math.sqrt(Math.max(0,d*d-(u/2)**2)),E=_+y*f*Math.sign(c),B=m+y*C*Math.sign(c),Q=Math.atan2(a.y-B,a.x-E);let b=Math.atan2(A.y-B,A.x-E);c>0&&b<Q?b+=2*Math.PI:c<0&&b>Q&&(b-=2*Math.PI);const D=mt(this.transform,[E,B]),R=My(this.transform,d);e.arc(D[0],D[1],R,-Q,-b,c>0)}else{const c=mt(this.transform,[A.x,A.y]);e.lineTo(c[0],c[1])}}e.closePath()};if(e.beginPath(),n(t.outer_ring),t.inner_rings)for(const o of t.inner_rings)n(o);e.fill("evenodd")}},PUo=(t=2)=>{const e=Math.max(2,Math.min(10,Math.floor(t)));return["top",...Array.from({length:e-2},(n,o)=>`inner${o+1}`),"bottom"]},s9e=t=>{const e=t.find(n=>n.type==="pcb_board");return PUo(e?.num_layers??2)},vUo=t=>`${t}_copper`,CLt=t=>t.map(e=>e.endsWith("_copper")?e.slice(0,-7):e),MUo=t=>["board","bottom","soldermask_bottom","bottom_silkscreen","top","soldermask_top","soldermask_with_copper_bottom","soldermask_with_copper_top","top_fabrication","bottom_fabrication",...s9e(t).filter(n=>n.startsWith("inner")),"drill","edge_cuts","bottom_notes","top_notes","top_silkscreen","top_courtyard","bottom_courtyard","other"];function wUo(t){return t.type==="pcb_copper_pour"}function NUo({canvas:t,elements:e,layers:n,realToCanvasMat:o}){const i=e.filter(wUo);if(i.length===0)return;const r=new Pc(t);r.realToCanvasMat=o,r.drawElements(i,{layers:n})}var RUo={...jC,courtyard:{top:Fo.board.f_crtyd,bottom:Fo.board.b_crtyd}};function TUo(t){return t.type==="pcb_courtyard_circle"||t.type==="pcb_courtyard_rect"||t.type==="pcb_courtyard_outline"}function yLt({canvas:t,elements:e,layers:n,realToCanvasMat:o}){const i=new Pc(t);i.configure({colorOverrides:RUo}),i.realToCanvasMat=o;const r=e.filter(TUo);i.drawElements(r,{layers:n})}var kUo={...jC,silkscreen:{top:Fo.board.f_fab,bottom:Fo.board.b_fab}};function FUo(t){return t.type.includes("pcb_fabrication_note")}function ELt({canvas:t,elements:e,layers:n,realToCanvasMat:o}){const i=new Pc(t);i.configure({colorOverrides:kUo}),i.realToCanvasMat=o;const r=e.filter(FUo);i.drawElements(r,{layers:n})}function LUo(t){return t.type==="pcb_hole"}function HUo({canvas:t,elements:e,layers:n,realToCanvasMat:o,drawSoldermask:i}){const r=new Pc(t);r.realToCanvasMat=o;const s=e.filter(LUo);r.drawElements(s,{layers:n,drawSoldermask:i})}function GUo(t){return t.type==="pcb_board"}function OUo({canvas:t,elements:e,layers:n,realToCanvasMat:o,drawSoldermask:i}){const r=new Pc(t);r.realToCanvasMat=o;const s=e.filter(GUo);for(const a of s)r.drawElements([a],{layers:n,drawSoldermask:!1,drawBoardMaterial:i??!1,minBoardOutlineStrokePx:2})}function KUo(t){return t.type==="pcb_copper_text"}function UUo({canvas:t,elements:e,layers:n,realToCanvasMat:o}){const i=e.filter(KUo);if(i.length===0)return;const r=new Pc(t);r.realToCanvasMat=o,r.drawElements(i,{layers:n})}function YUo(t){return t.type==="pcb_cutout"}function zUo({canvas:t,elements:e,layers:n,realToCanvasMat:o}){const i=new Pc(t);i.realToCanvasMat=o;const r=e.filter(YUo);i.drawElements(r,{layers:n})}function VUo(t){return t.type==="pcb_keepout"}function JUo({canvas:t,elements:e,layers:n,realToCanvasMat:o}){const i=e.filter(VUo);if(i.length===0)return;const r=new Pc(t);r.realToCanvasMat=o,r.drawElements(i,{layers:[]})}function qUo(t){return t.type.startsWith("pcb_note_")}function xLt({canvas:t,elements:e,layers:n,realToCanvasMat:o}){const i=new Pc(t);i.realToCanvasMat=o;const r=e.filter(qUo);i.drawElements(r,{layers:n})}function WUo(t){return t.type==="pcb_panel"}function jUo({canvas:t,elements:e,layers:n,realToCanvasMat:o,drawSoldermask:i}){const r=new Pc(t);r.realToCanvasMat=o;const s=e.filter(WUo);for(const a of s)r.drawElements([a],{layers:n})}var XUo={...jC,copper:{...jC.copper,top:Kr(Fo.board.pad_front).lighten(.5).toString(),bottom:Kr(Fo.board.pad_back).lighten(.5).toString(),inner1:Kr(Fo.board.copper.in1).lighten(.5).toString(),inner2:Kr(Fo.board.copper.in2).lighten(.5).toString(),inner3:Kr(Fo.board.copper.in3).lighten(.5).toString(),inner4:Kr(Fo.board.copper.in4).lighten(.5).toString(),inner5:Kr(Fo.board.copper.in5).lighten(.5).toString(),inner6:Kr(Fo.board.copper.in6).lighten(.5).toString(),inner7:Kr(Fo.board.copper.in7).lighten(.5).toString(),inner8:Kr(Fo.board.copper.in8).lighten(.5).toString()}};function $Uo(t){return t.type==="pcb_smtpad"}function ZUo({canvas:t,elements:e,layers:n,realToCanvasMat:o,primitives:i,drawSoldermask:r}){const s=new Set(CLt(n)),a=e.filter($Uo).filter(g=>s.has(g.layer));if(a.length===0)return;const A=new Set;if(i)for(const g of i)(g.is_mouse_over||g.is_in_highlighted_net)&&g._element?.type==="pcb_smtpad"&&A.add(g._element.pcb_smtpad_id);const c=a.filter(g=>A.has(g.pcb_smtpad_id)),l=a.filter(g=>!A.has(g.pcb_smtpad_id));if(l.length>0){const g=new Pc(t);g.realToCanvasMat=o,g.drawElements(l,{layers:n,drawSoldermask:r})}if(c.length>0){const g=new Pc(t);g.configure({colorOverrides:XUo}),g.realToCanvasMat=o,g.drawElements(c,{layers:n,drawSoldermask:r})}}var eYo={...jC,copper:{...jC.copper,top:Kr(Fo.board.pad_front).lighten(.5).toString(),bottom:Kr(Fo.board.pad_back).lighten(.5).toString(),inner1:Kr(Fo.board.copper.in1).lighten(.5).toString(),inner2:Kr(Fo.board.copper.in2).lighten(.5).toString(),inner3:Kr(Fo.board.copper.in3).lighten(.5).toString(),inner4:Kr(Fo.board.copper.in4).lighten(.5).toString(),inner5:Kr(Fo.board.copper.in5).lighten(.5).toString(),inner6:Kr(Fo.board.copper.in6).lighten(.5).toString(),inner7:Kr(Fo.board.copper.in7).lighten(.5).toString(),inner8:Kr(Fo.board.copper.in8).lighten(.5).toString()}};function tYo(t){return t.type==="pcb_trace"}var nYo=(t,e)=>{const n=t.route.filter(i=>i.route_type==="wire"&&"layer"in i&&e.has(i.layer)?!0:i.route_type==="via"?e.has(i.from_layer)||e.has(i.to_layer):!1);return n.filter(i=>i.route_type==="wire").length<2?null:{...t,route:n}},oYo=t=>({...t,route:t.route.map(e=>!("is_inside_copper_pour"in e)||e.is_inside_copper_pour!==!0?e:{...e,is_inside_copper_pour:!1})}),iYo=(t,e)=>e?t:[],rYo=({primitives:t,targetLayers:e,selectedLayer:n})=>{const o=new Set;if(!e.has(n))return o;for(const i of t)(i.is_mouse_over||i.is_in_highlighted_net)&&i._element?.type==="pcb_trace"&&o.add(i._element.pcb_trace_id);return o};function sYo({canvas:t,elements:e,layers:n,selectedLayer:o,realToCanvasMat:i,primitives:r,showCopperPours:s}){const a=new Set(CLt(n)),A=e.filter(tYo).map(h=>nYo(h,a)).filter(h=>h!==null).map(h=>s?h:oYo(h));if(A.length===0)return;const c=rYo({primitives:r??[],targetLayers:a,selectedLayer:o}),l=[],g=[];for(const h of A)c.has(h.pcb_trace_id)?l.push(h):g.push(h);const u=iYo(e,s);if(g.length>0){const h=new Pc(t);h.realToCanvasMat=i,h.drawElements(g,{layers:n,clipContextElements:u})}if(l.length>0){const h=new Pc(t);h.configure({colorOverrides:eYo}),h.realToCanvasMat=i,h.drawElements(l,{layers:n,clipContextElements:u})}}var aYo={...jC,copper:{...jC.copper,top:Kr(Fo.board.pad_front).lighten(.5).toString(),bottom:Kr(Fo.board.pad_back).lighten(.5).toString(),inner1:Kr(Fo.board.copper.in1).lighten(.5).toString(),inner2:Kr(Fo.board.copper.in2).lighten(.5).toString(),inner3:Kr(Fo.board.copper.in3).lighten(.5).toString(),inner4:Kr(Fo.board.copper.in4).lighten(.5).toString(),inner5:Kr(Fo.board.copper.in5).lighten(.5).toString(),inner6:Kr(Fo.board.copper.in6).lighten(.5).toString(),inner7:Kr(Fo.board.copper.in7).lighten(.5).toString(),inner8:Kr(Fo.board.copper.in8).lighten(.5).toString()}};function AYo(t){return t.type==="pcb_plated_hole"}function cYo({canvas:t,elements:e,layers:n,realToCanvasMat:o,primitives:i,drawSoldermask:r}){const s=e.filter(AYo);if(s.length===0)return;const a=new Set;if(i)for(const l of i)(l.is_mouse_over||l.is_in_highlighted_net)&&l._element?.type==="pcb_plated_hole"&&a.add(l._element.pcb_plated_hole_id);const A=s.filter(l=>a.has(l.pcb_plated_hole_id)),c=s.filter(l=>!a.has(l.pcb_plated_hole_id));if(c.length>0){const l=new Pc(t);l.realToCanvasMat=o,l.drawElements(c,{layers:n,drawSoldermask:r})}if(A.length>0){const l=new Pc(t);l.configure({colorOverrides:aYo}),l.realToCanvasMat=o,l.drawElements(A,{layers:n,drawSoldermask:r})}}function BLt(t){const{lines:e,anchorPoint:n,ccwRotation:o}=t;if(!o)return e;const i=o*Math.PI/180,r=E_(i),s=ki(Wi(n.x,n.y),r,Wi(-n.x,-n.y));return mt(s,n),e.map(a=>({...a,x1:mt(s,{x:a.x1,y:a.y1}).x,y1:mt(s,{x:a.x1,y:a.y1}).y,x2:mt(s,{x:a.x2,y:a.y2}).x,y2:mt(s,{x:a.x2,y:a.y2}).y}))}var lYo=.6,QLt=.2,SLt=t=>{const e=t.size*.7,n=e*lYo,o=e*QLt,i=e*QLt,r=t.text.split(/\r?\n/),s=t.text.length>0&&e>0,a=s?r.length:0,A=s?r.map(g=>g.length===0?0:g.length*n+(g.length-1)*o):[],c=A.length>0?Math.max(...A):0,l=a>0?a*e+(a-1)*i:0;return{text_lines:r,line_count:a,line_widths:A,target_height:e,target_width_char:n,space_between_chars:o,space_between_lines:i,width:c,height:l}},bLt=t=>{const e=SLt(t);return{width:e.width,height:e.height,lineHeight:e.target_height,lineSpacing:e.space_between_lines,lineCount:e.line_count}},DLt=t=>{const{text_lines:e,line_count:n,line_widths:o,target_height:i,target_width_char:r,space_between_chars:s,space_between_lines:a,width:A}=SLt(t);if(i<=0||n===0)return[];const c=i/12,l=[];for(let g=0;g<n;g++){const u=-g*(i+a),h=o[g],d=(A-h)/2;let _=t.x+d;for(let m=0;m<e[g].length;m++){const p=e[g][m],I=jM[p]??jM[p.toUpperCase()];if(!I){_+=r+s;continue}for(const{x1:f,y1:C,x2:y,y2:E}of I)l.push({_pcb_drawing_object_id:UB("line"),pcb_drawing_type:"line",x1:_+r*f,y1:t.y+u+i*C,x2:_+r*y,y2:t.y+u+i*E,width:c,layer:t.layer,unit:t.unit,color:t.color});_+=r+s}}return l};function ib(t){const n=t.color??vse[t.layer];let o=Kr(n);return t._element?.type==="pcb_copper_pour"&&(o=o.alpha(.7)),t.is_mouse_over||t.is_in_highlighted_net?o.lighten(.5).rgb().toString():o.rgb().toString()}var PLt=(t,e)=>{t.equip({size:e.zoomIndependent?e.width/t.transform.a:e.width,shape:e.squareCap?"square":"circle",color:ib(e),layer:e.layer}),t.moveTo(e.x1,e.y1),t.lineTo(e.x2,e.y2)},gYo=(t,e,n)=>{switch(n){case"top_left":return{x:0,y:-e};case"top_center":return{x:-t/2,y:-e};case"top_right":return{x:-t,y:-e};case"center_left":return{x:0,y:-e/2};case"center":return{x:-t/2,y:-e/2};case"center_right":return{x:-t,y:-e/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}}},vLt=t=>t.layer==="bottom_silkscreen"||t.layer==="bottom"?t.is_mirrored!==!1:t.is_mirrored===!0,uYo=(t,e)=>{t.equip({fontSize:e.size,color:ib(e),layer:e.layer});const{width:n,height:o}=bLt(e),i=gYo(n,o,e.align);e.x??=0,e.y??=0;const r={x:e.x,y:e.y};let s=DLt({...e,x:e.x+i.x,y:e.y+i.y});if(vLt(e)&&(s=s.map(a=>({...a,x1:2*e.x-a.x1,x2:2*e.x-a.x2}))),e.ccw_rotation){const a={lines:s,anchorPoint:r,ccwRotation:e.ccw_rotation};s=BLt(a)}for(const a of s)PLt(t,a)},dYo=(t,e)=>{const{width:n,height:o,lineHeight:i}=bLt(e);e.x??=0,e.y??=0;const r=e.knockout_padding??{left:e.size*.5,right:e.size*.5,top:e.size*.3,bottom:e.size*.3},s=n+r.left+r.right,a=o+r.top+r.bottom,A=n/2,c=i-o/2,l=e.x-A,g=e.y-c,u={x:e.x,y:e.y},h={_pcb_drawing_object_id:`knockout_rect_${e._pcb_drawing_object_id}`,x:e.x,y:e.y,w:s,h:a,layer:e.layer,ccw_rotation:e.ccw_rotation};e.ccw_rotation?wLt(t,h):MLt(t,h);let d=DLt({...e,x:l,y:g});if(vLt(e)&&(d=d.map(_=>({..._,x1:2*e.x-_.x1,x2:2*e.x-_.x2}))),e.ccw_rotation){const _={lines:d,anchorPoint:u,ccwRotation:e.ccw_rotation};d=BLt(_)}for(const _ of d)t.equip({size:_.width,shape:"circle",color:"black",layer:e.layer,mode:"subtract"}),t.moveTo(_.x1,_.y1),t.lineTo(_.x2,_.y2);t.equip({mode:"add"})},MLt=(t,e)=>{t.equip({color:ib(e),layer:e.layer,size:e.stroke_width}),t.rect({x:e.x,y:e.y,w:e.w,h:e.h,mesh_fill:e.mesh_fill,is_filled:e.is_filled,has_stroke:e.has_stroke,is_stroke_dashed:e.is_stroke_dashed,stroke_width:e.stroke_width,roundness:e.roundness})},wLt=(t,e)=>{t.equip({color:ib(e),layer:e.layer}),t.rotatedRect(e.x,e.y,e.w,e.h,e.ccw_rotation,e.roundness,e.mesh_fill)},hYo=(t,e)=>{t.equip({color:ib(e),layer:e.layer}),t.rotatedPill(e.x,e.y,e.w,e.h,e.ccw_rotation)},_Yo=(t,e)=>{t.equip({color:ib(e),layer:e.layer}),t.circle(e.x,e.y,e.r,e.mesh_fill)},mYo=(t,e)=>{t.equip({color:ib(e),layer:e.layer}),t.oval(e.x,e.y,e.rX,e.rY)},pYo=(t,e)=>{t.equip({color:ib(e),layer:e.layer}),t.pill(e.x,e.y,e.w,e.h)},IYo=(t,e)=>{t.equip({color:ib(e),layer:e.layer}),t.polygon(e.points)},fYo=(t,e)=>{t.equip({color:ib(e),layer:e.layer}),t.polygonWithArcs(e.brep_shape)},CYo=(t,e)=>{switch(e.pcb_drawing_type){case"line":return PLt(t,e);case"text":return e.is_knockout?dYo(t,e):uYo(t,e);case"rect":return e.ccw_rotation?wLt(t,e):MLt(t,e);case"circle":return _Yo(t,e);case"oval":return mYo(t,e);case"pill":return e.ccw_rotation?hYo(t,e):pYo(t,e);case"polygon":return IYo(t,e);case"polygon_with_arcs":return fYo(t,e)}},yYo=(t,e)=>{for(const n of e)CYo(t,n)},EYo={...jC,silkscreen:{top:Fo.board.f_silks,bottom:Fo.board.b_silks}};function xYo(t){return t.type.includes("pcb_silkscreen")}function NLt({canvas:t,elements:e,layers:n,realToCanvasMat:o}){const i=new Pc(t);i.configure({colorOverrides:EYo}),i.realToCanvasMat=o;const r=e.filter(xYo);i.drawElements(r,{layers:n})}var BYo={...jC,copper:{...jC.copper,top:Kr(Fo.board.pad_front).lighten(.5).toString(),bottom:Kr(Fo.board.pad_back).lighten(.5).toString(),inner1:Kr(Fo.board.copper.in1).lighten(.5).toString(),inner2:Kr(Fo.board.copper.in2).lighten(.5).toString(),inner3:Kr(Fo.board.copper.in3).lighten(.5).toString(),inner4:Kr(Fo.board.copper.in4).lighten(.5).toString(),inner5:Kr(Fo.board.copper.in5).lighten(.5).toString(),inner6:Kr(Fo.board.copper.in6).lighten(.5).toString(),inner7:Kr(Fo.board.copper.in7).lighten(.5).toString(),inner8:Kr(Fo.board.copper.in8).lighten(.5).toString()},soldermask:{...jC.soldermask,top:Kr(Fo.board.soldermask.top).lighten(.35).toString(),bottom:Kr(Fo.board.soldermask.bottom).lighten(.35).toString()}};function RLt({canvas:t,elements:e,layers:n,realToCanvasMat:o,drawSoldermaskTop:i,drawSoldermaskBottom:r,primitives:s}){const a=new Pc(t);a.realToCanvasMat=o;const A=e.filter(u=>u.type==="pcb_board");if(A.length<=1)a.drawElements(e,{layers:n,drawSoldermask:!0,drawSoldermaskTop:i,drawSoldermaskBottom:r,drawBoardMaterial:!1});else{const u=e.filter(h=>h.type!=="pcb_board");for(const h of A)a.drawElements([h,...u],{layers:n,drawSoldermask:!0,drawSoldermaskTop:i,drawSoldermaskBottom:r,drawBoardMaterial:!1})}if(!s)return;const c=new Set;for(const u of s){if(!(u.is_mouse_over||u.is_in_highlighted_net))continue;const h=u._element;h?.type==="pcb_smtpad"?c.add(h.pcb_smtpad_id):h?.type==="pcb_plated_hole"?c.add(h.pcb_plated_hole_id):h?.type==="pcb_via"&&c.add(h.pcb_via_id)}if(c.size===0)return;const l=e.filter(u=>u.type==="pcb_smtpad"?c.has(u.pcb_smtpad_id):u.type==="pcb_plated_hole"?c.has(u.pcb_plated_hole_id):u.type==="pcb_via"?c.has(u.pcb_via_id):!1);if(l.length===0)return;const g=new Pc(t);g.configure({colorOverrides:BYo}),g.realToCanvasMat=o,g.drawElements(l,{layers:n,drawSoldermask:!0,drawSoldermaskTop:i,drawSoldermaskBottom:r,drawBoardMaterial:!1})}var QYo={...jC,copper:{...jC.copper,top:Kr(Fo.board.pad_front).lighten(.5).toString(),bottom:Kr(Fo.board.pad_back).lighten(.5).toString(),inner1:Kr(Fo.board.copper.in1).lighten(.5).toString(),inner2:Kr(Fo.board.copper.in2).lighten(.5).toString(),inner3:Kr(Fo.board.copper.in3).lighten(.5).toString(),inner4:Kr(Fo.board.copper.in4).lighten(.5).toString(),inner5:Kr(Fo.board.copper.in5).lighten(.5).toString(),inner6:Kr(Fo.board.copper.in6).lighten(.5).toString(),inner7:Kr(Fo.board.copper.in7).lighten(.5).toString(),inner8:Kr(Fo.board.copper.in8).lighten(.5).toString()}};function SYo(t){return t.type==="pcb_via"}function bYo({canvas:t,elements:e,layers:n,realToCanvasMat:o,primitives:i,drawSoldermask:r}){const s=e.filter(SYo).filter(l=>n.some(g=>g.includes("copper")));if(s.length===0)return;const a=new Set;if(i)for(const l of i)(l.is_mouse_over||l.is_in_highlighted_net)&&l._element?.type==="pcb_via"&&a.add(l._element.pcb_via_id);const A=s.filter(l=>a.has(l.pcb_via_id)),c=s.filter(l=>!a.has(l.pcb_via_id));if(c.length>0){const l=new Pc(t);l.realToCanvasMat=o,l.drawElements(c,{layers:n,drawSoldermask:r})}if(A.length>0){const l=new Pc(t);l.configure({colorOverrides:QYo}),l.realToCanvasMat=o,l.drawElements(A,{layers:n,drawSoldermask:r})}}var DYo=({primitives:t,elements:e,transform:n,grid:o,width:i=500,height:r=500})=>{const s=Z.useRef({}),a=Cd(d=>d.selected_layer),A=Cd(d=>d.is_showing_copper_pours),c=Cd(d=>d.is_showing_solder_mask),l=Cd(d=>d.is_showing_fabrication_notes),g=Cd(d=>d.is_showing_pcb_notes),u=Cd(d=>d.is_showing_courtyards),h=Cd(d=>d.is_showing_silkscreen);return Z.useEffect(()=>{if(!s.current||Object.keys(s.current).length===0)return;const d=Object.fromEntries(Object.entries(s.current).filter(([p,I])=>!!I));if(Object.keys(d).length===0)return;const _=new DUo(d);n&&(_.transform=n),_.clear(),_.foregroundLayer=a;const m=t.filter(p=>c||!p.layer?.includes("soldermask")).filter(p=>h||!p.layer?.includes("silkscreen")).filter(p=>l||!p.layer?.includes("fabrication")).filter(p=>p.layer!=="board").filter(p=>p._element?.type!=="pcb_smtpad").filter(p=>p._element?.type!=="pcb_plated_hole").filter(p=>p._element?.type!=="pcb_via").filter(p=>p._element?.type!=="pcb_trace").filter(p=>p._element?.type!=="pcb_copper_text");if(yYo(_,m),n){const p=s.current.top,I=s.current.bottom,f=s9e(e).map(Q=>({canvas:s.current[Q],layer:Q,copperLayer:vUo(Q)}));for(const{canvas:Q,copperLayer:b}of f)Q&&sYo({canvas:Q,elements:e,layers:[b],selectedLayer:a,realToCanvasMat:n,primitives:t,showCopperPours:A});for(const{canvas:Q,copperLayer:b}of f)Q&&UUo({canvas:Q,elements:e,layers:[b],realToCanvasMat:n});for(const{canvas:Q,copperLayer:b,layer:D}of f)Q&&cYo({canvas:Q,elements:e,layers:[b],realToCanvasMat:n,primitives:t,drawSoldermask:c&&(D==="top"||D==="bottom")});for(const{canvas:Q,copperLayer:b}of f)Q&&NUo({canvas:Q,elements:e,layers:[b],realToCanvasMat:n});for(const{canvas:Q,copperLayer:b}of f)Q&&ZUo({canvas:Q,elements:e,layers:[b],realToCanvasMat:n,primitives:t,drawSoldermask:c});for(const{canvas:Q,copperLayer:b,layer:D}of f)Q&&bYo({canvas:Q,elements:e,layers:[b],realToCanvasMat:n,primitives:t,drawSoldermask:c&&(D==="top"||D==="bottom")});if(c){const Q=a==="bottom"?"bottom":"top",b=Q==="top",D=Q==="bottom",R=s.current.soldermask_top;R&&Q==="top"&&RLt({canvas:R,elements:e,layers:["top_soldermask"],realToCanvasMat:n,drawSoldermaskTop:b,drawSoldermaskBottom:D,primitives:t});const w=s.current.soldermask_bottom;w&&Q==="bottom"&&RLt({canvas:w,elements:e,layers:["bottom_soldermask"],realToCanvasMat:n,drawSoldermaskTop:b,drawSoldermaskBottom:D,primitives:t})}const C=s.current.drill;if(C&&HUo({canvas:C,elements:e,layers:["drill"],realToCanvasMat:n}),h){const Q=s.current.top_silkscreen;Q&&NLt({canvas:Q,elements:e,layers:["top_silkscreen"],realToCanvasMat:n});const b=s.current.bottom_silkscreen;b&&NLt({canvas:b,elements:e,layers:["bottom_silkscreen"],realToCanvasMat:n})}if(l){const Q=s.current.top_fabrication;Q&&ELt({canvas:Q,elements:e,layers:["top_fabrication_note"],realToCanvasMat:n});const b=s.current.bottom_fabrication;b&&ELt({canvas:b,elements:e,layers:["bottom_fabrication_note"],realToCanvasMat:n})}if(g){const Q=s.current.bottom_notes;Q&&xLt({canvas:Q,elements:e,layers:["bottom_user_note"],realToCanvasMat:n});const b=s.current.top_notes;b&&xLt({canvas:b,elements:e,layers:["top_user_note"],realToCanvasMat:n})}if(u){const Q=s.current.top_courtyard;Q&&yLt({canvas:Q,elements:e,layers:["top_courtyard"],realToCanvasMat:n});const b=s.current.bottom_courtyard;b&&yLt({canvas:b,elements:e,layers:["bottom_courtyard"],realToCanvasMat:n})}const y=s.current.board;y&&(jUo({canvas:y,elements:e,layers:[],realToCanvasMat:n,drawSoldermask:c}),OUo({canvas:y,elements:e,layers:[],realToCanvasMat:n,drawSoldermask:c}));const E=s.current.edge_cuts;E&&zUo({canvas:E,elements:e,layers:["edge_cuts"],realToCanvasMat:n});const B=[{canvas:p,layer:"top"},{canvas:I,layer:"bottom"}];for(const{canvas:Q,layer:b}of B)Q&&JUo({canvas:Q,elements:e,layers:[b],realToCanvasMat:n})}_.orderAndFadeLayers()},[t,e,n,a,A,c,l,g,u,h]),W.jsxs("div",{style:{backgroundColor:"black",width:i,height:r,position:"relative"},children:[W.jsx(hse.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:i,height:r,transform:n,stringifyCoord:(d,_,m)=>`${hse.toMMSI(d,m)}, ${hse.toMMSI(_,m)}`}),MUo(e).filter(d=>!(!c&&d.includes("soldermask")||!h&&d.includes("silkscreen"))).map(d=>d.replace(/-/g,"")).map((d,_)=>W.jsx("canvas",{className:`pcb-layer-${d}`,ref:m=>{s.current??={},m?s.current[d]=m:delete s.current[d]},style:{position:"absolute",zIndex:_,left:0,top:0,pointerEvents:"none"},width:i,height:r},d))]})},PYo=.6,vYo=1;$8e(IKo(),1),$8e(RKo(),1);var Mse=["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 TLt(t,e,n,o={}){const i=o.padding??40,r=o.yFlip??!1;let s;if("center"in t){const l=t.width/2,g=t.height/2;s={minX:t.center.x-l,maxX:t.center.x+l,minY:t.center.y-g,maxY:t.center.y+g}}else s=t;const a=s.maxX-s.minX||1,A=s.maxY-s.minY||1,c=Math.min((e-2*i)/a,(n-2*i)/A);return ki(Wi(e/2,n/2),ug(c,r?-c:c),Wi(-(s.minX+a/2),-(s.minY+A/2)))}function MYo(t){const e=[...t.points||[],...(t.lines||[]).flatMap(n=>n.points),...(t.rects||[]).flatMap(n=>{const o=n.width/2,i=n.height/2;return[{x:n.center.x-o,y:n.center.y-i},{x:n.center.x+o,y:n.center.y-i},{x:n.center.x-o,y:n.center.y+i},{x:n.center.x+o,y:n.center.y+i}]}),...(t.circles||[]).flatMap(n=>[{x:n.center.x-n.radius,y:n.center.y},{x:n.center.x+n.radius,y:n.center.y},{x:n.center.x,y:n.center.y-n.radius},{x:n.center.x,y:n.center.y+n.radius}]),...(t.texts||[]).flatMap(n=>{const o=n.fontSize??12,i=n.text.length*o*PYo,r=o*vYo,s=n.anchorSide??"center",a={top_left:{dx:0,dy:0},top_center:{dx:-i/2,dy:0},top_right:{dx:-i,dy:0},center_left:{dx:0,dy:-r/2},center:{dx:-i/2,dy:-r/2},center_right:{dx:-i,dy:-r/2},bottom_left:{dx:0,dy:-r},bottom_center:{dx:-i/2,dy:-r},bottom_right:{dx:-i,dy:-r}},{dx:A,dy:c}=a[s],l=n.x+A,g=n.y+c;return[{x:l,y:g},{x:l+i,y:g+r}]})];return e.length===0?{minX:-1,maxX:1,minY:-1,maxY:1}:e.reduce((n,o)=>({minX:Math.min(n.minX,o.x),maxX:Math.max(n.maxX,o.x),minY:Math.min(n.minY,o.y),maxY:Math.max(n.maxY,o.y)}),{minX:1/0,maxX:-1/0,minY:1/0,maxY:-1/0})}function wYo(t,e,n={}){const o=e instanceof HTMLCanvasElement?e.getContext("2d"):e;if(!o)throw new Error("Could not get 2D context from canvas");const i=e instanceof HTMLCanvasElement?e.width:e.canvas.width,r=e instanceof HTMLCanvasElement?e.height:e.canvas.height;let s;if(n.transform)s=n.transform;else if(n.viewbox)s=TLt(n.viewbox,i,r,{padding:n.padding,yFlip:n.yFlip});else{const a=MYo(t),A=t.coordinateSystem==="cartesian";s=TLt(a,i,r,{padding:n.padding??40,yFlip:A})}o.clearRect(0,0,i,r),o.save(),t.rects&&t.rects.length>0&&t.rects.forEach(a=>{const A=a.width/2,c=a.height/2,l=mt(s,{x:a.center.x-A,y:a.center.y-c}),g=mt(s,{x:a.center.x+A,y:a.center.y+c}),u=Math.abs(g.x-l.x),h=Math.abs(g.y-l.y);o.beginPath(),o.rect(Math.min(l.x,g.x),Math.min(l.y,g.y),u,h),a.fill&&(o.fillStyle=a.fill,o.fill()),a.stroke&&(o.strokeStyle=a.stroke,o.stroke())}),t.circles&&t.circles.length>0&&t.circles.forEach(a=>{const A=mt(s,a.center),c=a.radius*Math.abs(s.a);o.beginPath(),o.arc(A.x,A.y,c,0,2*Math.PI),a.fill&&(o.fillStyle=a.fill,o.fill()),a.stroke&&(o.strokeStyle=a.stroke??"transparent",o.stroke())}),t.lines&&t.lines.length>0&&t.lines.forEach((a,A)=>{if(a.points.length===0)return;o.beginPath();const c=mt(s,a.points[0]);o.moveTo(c.x,c.y);for(let l=1;l<a.points.length;l++){const g=mt(s,a.points[l]);o.lineTo(g.x,g.y)}if(o.strokeStyle=a.strokeColor||Mse[A%Mse.length],a.strokeWidth?o.lineWidth=a.strokeWidth*s.a:o.lineWidth=2,o.lineCap="round",a.strokeDash)if(typeof a.strokeDash=="string"){let l;if(a.strokeDash.includes(","))l=a.strokeDash.split(",").map(g=>parseFloat(g.trim())).filter(g=>!Number.isNaN(g));else{const g=parseFloat(a.strokeDash.trim());l=Number.isNaN(g)?[]:[g]}o.setLineDash(l)}else o.setLineDash(a.strokeDash.map(l=>l*Math.abs(s.a)));else o.setLineDash([]);o.stroke()}),t.points&&t.points.length>0&&t.points.forEach((a,A)=>{const c=mt(s,a);o.beginPath(),o.arc(c.x,c.y,3,0,2*Math.PI),o.fillStyle=a.color||Mse[A%Mse.length],o.fill(),a.label&&!n.disableLabels&&(o.fillStyle=a.color||"black",o.font="12px sans-serif",o.fillText(a.label,c.x+5,c.y-5))}),t.texts&&t.texts.length>0&&t.texts.forEach(a=>{const A=mt(s,{x:a.x,y:a.y});o.fillStyle=a.color||"black",o.font=`${(a.fontSize??12)*Math.abs(s.a)}px sans-serif`;const c=a.anchorSide??"center",l={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"},g={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"};o.textAlign=l[c],o.textBaseline=g[c],o.fillText(a.text,A.x,A.y)}),o.restore()}var NYo=({children:t,transform:e,debugGraphics:n})=>{const o=Z.useRef(null),[i,{width:r,height:s}]=pY(),a=Cd(A=>A.is_showing_autorouting);return Z.useEffect(()=>{a&&o.current&&n&&r&&s&&(o.current.width=r,o.current.height=s,wYo(n,o.current,{transform:e,disableLabels:!0}))},[n,e,r,s,a]),a?W.jsxs("div",{ref:i,style:{position:"relative",width:"100%",height:"100%"},children:[t,W.jsx("canvas",{ref:o,style:{position:"absolute",top:0,left:0,opacity:.5,zIndex:100,width:"100%",height:"100%",pointerEvents:"none"}})]}):t},wse=(t,e,n)=>n(t,e),kLt=(t,e,n,o,i)=>{const r=i*Math.PI/180,s=Math.cos(r),a=Math.sin(r),A=t-n,c=e-o,l=A*s-c*a,g=A*a+c*s;return{x:l+n,y:g+o}},IY=t=>{if(t.length===0)return null;let e=t[0].x,n=t[0].x,o=t[0].y,i=t[0].y;for(const r of t)e=wse(e,r.x,Math.min),n=wse(n,r.x,Math.max),o=wse(o,r.y,Math.min),i=wse(i,r.y,Math.max);return{minX:e,maxX:n,minY:o,maxY:i}},RYo=(t,e)=>({minX:Math.min(t.minX,e.minX),maxX:Math.max(t.maxX,e.maxX),minY:Math.min(t.minY,e.minY),maxY:Math.max(t.maxY,e.maxY)}),TYo=(t,e)=>t?RYo(t,e):e,kYo=t=>{switch(t.pcb_drawing_type){case"line":{const e=(t.width??0)/2,n=[{x:t.x1,y:t.y1},{x:t.x2,y:t.y2}],o=IY(n);return o?{minX:o.minX-e,maxX:o.maxX+e,minY:o.minY-e,maxY:o.maxY+e}:null}case"rect":{const e=t.w/2,n=t.h/2,o=[{x:t.x-e,y:t.y-n},{x:t.x+e,y:t.y-n},{x:t.x+e,y:t.y+n},{x:t.x-e,y:t.y+n}],i=t.ccw_rotation??0,r=i===0?o:o.map(s=>kLt(s.x,s.y,t.x,t.y,i));return IY(r)}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 e=t.w/2,n=t.h/2,o=[{x:t.x-e,y:t.y-n},{x:t.x+e,y:t.y-n},{x:t.x+e,y:t.y+n},{x:t.x-e,y:t.y+n}],i=t.ccw_rotation??0,r=i===0?o:o.map(s=>kLt(s.x,s.y,t.x,t.y,i));return IY(r)}case"polygon":return IY(t.points);case"polygon_with_arcs":{const e=t.brep_shape.outer_ring.vertices.map(n=>({x:n.x,y:n.y}));return IY(e)}case"text":{const e=t.size??0,n=t.text?t.text.length*e*.6:0,o=e;if(n===0&&o===0)return{minX:t.x,maxX:t.x,minY:t.y,maxY:t.y};const i=n/2,r=o/2;return{minX:t.x-i,maxX:t.x+i,minY:t.y-r,maxY:t.y+r}}default:return null}};function FYo(t){const{dimensionStart:e,dimensionEnd:n,screenDimensionStart:o,screenDimensionEnd:i,flipX:r,flipY:s}=t,a=n.x-e.x,A=n.y-e.y,c=Math.sqrt(a*a+A*A),l=i.x-o.x,g=i.y-o.y,u=Math.sqrt(l*l+g*g),h=Math.atan2(g,l)*(180/Math.PI),d=Math.abs(h)%90,m=Math.min(d,90-d)>15,p=(o.x+i.x)/2,I=(o.y+i.y)/2,f=15,C=h+90;let y=Math.cos(C*Math.PI/180)*f,E=Math.sin(C*Math.PI/180)*f;const B=l>0&&g<0,Q=l>0&&g>0,b=l<0&&g>0;r!==s&&!B&&(y=-y,E=-E),B&&(y+=Math.cos(C*Math.PI/180)*-45,E+=Math.sin(C*Math.PI/180)*-45),Q&&(y+=Math.cos(C*Math.PI/180)+-20,E+=Math.sin(C*Math.PI/180)+-10),b&&(y+=Math.cos(C*Math.PI/180)*10,E+=Math.sin(C*Math.PI/180)*10);const D=p+y,R=I+E;return{distance:c,screenDistance:u,x:D,y:R,show:c>.01&&u>30&&m}}function LYo(t){const{dimensionStart:e,dimensionEnd:n,screenDimensionStart:o,screenDimensionEnd:i,flipX:r,flipY:s}=t;return Z.useMemo(()=>FYo({dimensionStart:e,dimensionEnd:n,screenDimensionStart:o,screenDimensionEnd:i,flipX:r,flipY:s}),[e,n,o,i,r,s])}var HYo=(t,e,n)=>{const o=n*Math.PI/180,i=Math.cos(o),r=Math.sin(o),s=t.x-e.x,a=t.y-e.y,A=s*i-a*r,c=s*r+a*i;return{x:A+e.x,y:c+e.y}},FLt=(t,e,n,o)=>{const i={top_left:{x:t.x-e,y:t.y-n},top_center:{x:t.x,y:t.y-n},top_right:{x:t.x+e,y:t.y-n},center_left:{x:t.x-e,y:t.y},center:{x:t.x,y:t.y},center_right:{x:t.x+e,y:t.y},bottom_left:{x:t.x-e,y:t.y+n},bottom_center:{x:t.x,y:t.y+n},bottom_right:{x:t.x+e,y:t.y+n}};return o===0?Object.entries(i).map(([r,s])=>({anchor:r,point:s})):Object.entries(i).map(([r,s])=>({anchor:r,point:HYo(s,t,o)}))},GYo=t=>{switch(t.pcb_drawing_type){case"rect":{const e=t.ccw_rotation??0;return FLt({x:t.x,y:t.y},t.w/2,t.h/2,e)}case"pill":{const e=t.ccw_rotation??0;return FLt({x:t.x,y:t.y},t.w/2,t.h/2,e)}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 e={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:e},{anchor:"line_end",point:{x:t.x2,y:t.y2}}]}case"polygon":return t.points.map((e,n)=>({anchor:`polygon_vertex_${n}`,point:e}));case"polygon_with_arcs":return t.brep_shape.outer_ring.vertices.map((e,n)=>({anchor:`polygon_with_arcs_vertex_${n}`,point:{x:e.x,y:e.y}}));default:return[]}},OYo=16,T6=5,LLt=t=>{if(t.pcb_drawing_type==="text")return!0;const e=t._element;if(!e||typeof e!="object")return!1;const n=typeof e.type=="string"?e.type:void 0;return n?!!(n.startsWith("pcb_silkscreen_")||n.startsWith("pcb_note_")||n==="pcb_text"||n.startsWith("pcb_fabrication_note_")&&n!=="pcb_fabrication_note_rect"):!1},KYo=({children:t,transform:e,focusOnHover:n=!1,primitives:o=[],onBoundsSelected:i,cancelPanDrag:r})=>{e||(e=Ll());const[s,a]=Z.useState(!1),[A,c]=Z.useState(!1),[l,g]=Z.useState(!1),[u,h]=Z.useState(!1),[d,_]=Z.useState(!1),[m,p]=Z.useState(!1),[I,f]=Z.useState({start:null,end:null}),C=Cd(we=>we.is_mouse_over_container),y=Z.useCallback(()=>{l&&(g(!1),window.dispatchEvent(new Event("disarm-dimension-tool")))},[l]),E=Z.useCallback(()=>{u&&(h(!1),window.dispatchEvent(new Event("disarm-bounds-tool")))},[u]),[B,Q]=Z.useState({x:0,y:0}),[b,D]=Z.useState({x:0,y:0}),[R,w]=Z.useState({x:0,y:0}),[H,G]=Z.useState({x:0,y:0}),K=Z.useRef({x:0,y:0}),U=Z.useRef(null),j=U.current?.getBoundingClientRect(),ne=Z.useMemo(()=>{const we=new Map;for(const Je of o){if(!Je._element||LLt(Je)||Je.pcb_drawing_type==="pill"||Je.pcb_drawing_type==="rect"&&Je.ccw_rotation&&Je.ccw_rotation!==0)continue;const Ie=kYo(Je);if(!Ie)continue;const We=we.get(Je._element);we.set(Je._element,TYo(We??void 0,Ie))}return we},[o]),re=Z.useMemo(()=>{const we=[];for(const Je of o){if(!Je._element||LLt(Je))continue;const Ie=GYo(Je);if(Ie.length!==0)for(const We of Ie)we.push({anchor:We.anchor,point:We.point,element:Je._element})}return we},[o]),X=Z.useMemo(()=>{const we=[];ne.forEach((Je,Ie)=>{if(!Je)return;const We=(Je.minX+Je.maxX)/2,Re=(Je.minY+Je.maxY)/2,Le={top_left:{x:Je.minX,y:Je.minY},top_center:{x:We,y:Je.minY},top_right:{x:Je.maxX,y:Je.minY},center_left:{x:Je.minX,y:Re},center:{x:We,y:Re},center_right:{x:Je.maxX,y:Re},bottom_left:{x:Je.minX,y:Je.maxY},bottom_center:{x:We,y:Je.maxY},bottom_right:{x:Je.maxX,y:Je.maxY}};for(const[Ve,Ne]of Object.entries(Le))we.push({anchor:Ve,point:Ne,element:Ie})});for(const Je of re)we.push(Je);return we.push({anchor:"origin",point:{x:0,y:0},element:null}),we},[ne,re]),te=Z.useMemo(()=>X.map((we,Je)=>({...we,id:`${Je}-${we.anchor}`,screenPoint:mt(e,we.point)})),[X,e]),se=Z.useCallback(we=>{if(te.length===0)return{point:we,id:null};const Je=mt(e,we);let Ie=null;for(const We of te){const Re=We.screenPoint.x-Je.x,Le=We.screenPoint.y-Je.y,Ve=Math.hypot(Re,Le);Ve>OYo||(!Ie||Ve<Ie.distance)&&(Ie={distance:Ve,id:We.id,point:We.point})}return Ie?{point:Ie.point,id:Ie.id}:{point:we,id:null}},[te,e]);Z.useEffect(()=>{const we=We=>{const Re=We.target;if(Re.tagName==="INPUT"||Re.tagName==="TEXTAREA"||Re.isContentEditable)return;const Le=U.current?.contains(document.activeElement)||document.activeElement===U.current;if(!(!C&&!Le)){if(We.key==="d"){const Ve=se({x:K.current.x,y:K.current.y});Q({x:Ve.point.x,y:Ve.point.y}),D({x:Ve.point.x,y:Ve.point.y}),f({start:Ve.id,end:Ve.id}),s?(a(!1),c(!1),f({start:null,end:null})):(a(!0),c(!0)),y()}We.key==="Escape"&&(a(!1),c(!1),f({start:null,end:null}),_(!1),p(!1),y(),E())}},Je=()=>{g(!0),h(!1),window.dispatchEvent(new Event("disarm-bounds-tool"))},Ie=()=>{h(!0),g(!1),a(!1),c(!1),window.dispatchEvent(new Event("disarm-dimension-tool"))};return window.addEventListener("keydown",we),window.addEventListener("arm-dimension-tool",Je),window.addEventListener("arm-bounds-tool",Ie),()=>{window.removeEventListener("keydown",we),window.removeEventListener("arm-dimension-tool",Je),window.removeEventListener("arm-bounds-tool",Ie),y(),E()}},[C,s,y,E,se]);const Ae=mt(e,B),ue=mt(e,b),Ce=mt(e,R),Ee=mt(e,H),Be={minX:Math.min(R.x,H.x),minY:Math.min(R.y,H.y),maxX:Math.max(R.x,H.x),maxY:Math.max(R.y,H.y)},he={left:Math.min(Ce.x,Ee.x),top:Math.min(Ce.y,Ee.y),width:Math.abs(Ce.x-Ee.x),height:Math.abs(Ce.y-Ee.y)},ye=Z.useCallback((we,Je)=>{const Ie={minX:Math.min(we.x,Je.x),minY:Math.min(we.y,Je.y),maxX:Math.max(we.x,Je.x),maxY:Math.max(we.y,Je.y)};i?.(Ie),window.dispatchEvent(new CustomEvent("pcb-viewer:bounds-selected",{detail:Ie}))},[i]),me={left:Math.min(Ae.x,ue.x),right:Math.max(Ae.x,ue.x),top:Math.min(Ae.y,ue.y),bottom:Math.max(Ae.y,ue.y),flipX:Ae.x>ue.x,flipY:Ae.y>ue.y,width:0,height:0};me.width=me.right-me.left,me.height=me.bottom-me.top;const Pe=LYo({dimensionStart:B,dimensionEnd:b,screenDimensionStart:Ae,screenDimensionEnd:ue,flipX:me.flipX,flipY:me.flipY});return W.jsxs("div",{ref:U,"data-pcb-viewer":!0,tabIndex:0,style:{position:"relative",outline:"none"},onMouseEnter:()=>{n&&U.current&&U.current.focus()},onMouseLeave:()=>{U.current&&U.current.blur()},onClick:()=>{U.current&&U.current.focus()},onMouseMove:we=>{const Je=we.currentTarget.getBoundingClientRect(),Ie=we.clientX-Je.left,We=we.clientY-Je.top,Re=mt(QQ(e),{x:Ie,y:We});if(K.current.x=Re.x,K.current.y=Re.y,A){const Le=se(Re);D({x:Le.point.x,y:Le.point.y}),f(Ve=>({...Ve,end:Le.id}))}m&&(r?.(),G({x:Re.x,y:Re.y}))},onMouseDown:we=>{const Je=we.currentTarget.getBoundingClientRect(),Ie=we.clientX-Je.left,We=we.clientY-Je.top,Re=mt(QQ(e),{x:Ie,y:We});if(u)we.preventDefault(),we.stopPropagation(),r?.(),w({x:Re.x,y:Re.y}),G({x:Re.x,y:Re.y}),_(!0),p(!0),E();else if(l&&!s){const Le=se(Re);Q({x:Le.point.x,y:Le.point.y}),D({x:Le.point.x,y:Le.point.y}),f({start:Le.id,end:Le.id}),a(!0),c(!0),y()}else A?(c(!1),f(Le=>({...Le,end:null}))):s&&(a(!1),f({start:null,end:null}))},onMouseUp:we=>{if(!m)return;const Je=we.currentTarget.getBoundingClientRect(),Ie=we.clientX-Je.left,We=we.clientY-Je.top,Re=mt(QQ(e),{x:Ie,y:We}),Le={x:Re.x,y:Re.y};we.preventDefault(),we.stopPropagation(),r?.(),G(Le),p(!1),ye(R,Le)},children:[t,d&&W.jsxs(W.Fragment,{children:[W.jsx("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none",mixBlendMode:"difference",zIndex:Yg.dimensionOverlay},width:j.width,height:j.height,children:W.jsx("rect",{x:he.left,y:he.top,width:he.width,height:he.height,stroke:"red",strokeWidth:1.5,strokeDasharray:"4,3",fill:"rgba(255, 0, 0, 0.12)"})}),W.jsxs("div",{style:{left:0,bottom:s?58:0,position:"absolute",color:"red",fontFamily:"sans-serif",fontSize:12,margin:4,pointerEvents:"none",mixBlendMode:"difference",zIndex:Yg.dimensionOverlay},children:["minX: ",Be.minX.toFixed(2),", minY:"," ",Be.minY.toFixed(2),W.jsx("br",{}),"maxX: ",Be.maxX.toFixed(2),", maxY:"," ",Be.maxY.toFixed(2)]})]}),s&&W.jsxs(W.Fragment,{children:[Pe.show&&W.jsx("div",{style:{position:"absolute",left:Pe.x,top:Pe.y,color:"red",mixBlendMode:"difference",pointerEvents:"none",fontSize:12,fontFamily:"sans-serif",whiteSpace:"nowrap",zIndex:Yg.dimensionOverlay},children:Pe.distance.toFixed(2)}),W.jsx("div",{style:{position:"absolute",left:me.left,width:me.width,textAlign:"center",top:Ae.y+2,color:"red",mixBlendMode:"difference",pointerEvents:"none",marginTop:me.flipY?0:-20,fontSize:12,fontFamily:"sans-serif",zIndex:Yg.dimensionOverlay},children:Math.abs(B.x-b.x).toFixed(2)}),W.jsx("div",{style:{position:"absolute",left:ue.x,height:me.height,display:"flex",flexDirection:"column",justifyContent:"center",top:me.top,color:"red",pointerEvents:"none",mixBlendMode:"difference",fontSize:12,fontFamily:"sans-serif",zIndex:Yg.dimensionOverlay},children:W.jsx("div",{style:{marginLeft:me.flipX?"-100%":4,paddingRight:4},children:Math.abs(B.y-b.y).toFixed(2)})}),W.jsxs("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none",mixBlendMode:"difference",zIndex:Yg.dimensionOverlay},width:j.width,height:j.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:Ae.x,y1:Ae.y,x2:ue.x,y2:ue.y,markerEnd:"url(#head)",strokeWidth:1.5,fill:"none",stroke:"red"}),W.jsx("line",{x1:Ae.x,y1:Ae.y,x2:ue.x,y2:Ae.y,strokeWidth:1.5,fill:"none",strokeDasharray:"2,2",stroke:"red"}),W.jsx("line",{x1:ue.x,y1:Ae.y,x2:ue.x,y2:ue.y,strokeWidth:1.5,fill:"none",strokeDasharray:"2,2",stroke:"red"})]}),A&&te.map(we=>{const Je=we.id===I.start||we.id===I.end,Ie=T6/2;return W.jsxs("svg",{width:T6,height:T6,style:{position:"absolute",left:we.screenPoint.x-Ie,top:we.screenPoint.y-Ie,pointerEvents:"none",zIndex:Yg.dimensionOverlay},children:[W.jsx("line",{x1:0,y1:0,x2:T6,y2:T6,stroke:Je?"#66ccff":"white",strokeWidth:1}),W.jsx("line",{x1:T6,y1:0,x2:0,y2:T6,stroke:Je?"#66ccff":"white",strokeWidth:1})]},we.id)}),W.jsxs("div",{style:{right:0,bottom:0,position:"absolute",color:"red",fontFamily:"sans-serif",fontSize:12,margin:4},children:["(",B.x.toFixed(2),",",B.y.toFixed(2),")",W.jsx("br",{}),"(",b.x.toFixed(2),",",b.y.toFixed(2),")",W.jsx("br",{}),"dist:"," ",Math.sqrt((b.x-B.x)**2+(b.y-B.y)**2).toFixed(2)]})]})]})},UYo=(t,e,n=0)=>{const o=t.width/2,i=t.height/2,r=t.center.x-o-n,s=t.center.x+o+n,a=t.center.y-i-n,A=t.center.y+i+n;return e.x>r&&e.x<s&&e.y>a&&e.y<A},YYo=({children:t,disabled:e,transform:n,soup:o,cancelPanDrag:i,onCreateEditEvent:r,onModifyEditEvent:s})=>{n||(n=Ll());const a=Z.useRef(null),[A,c]=Z.useState(null),[l,g]=Z.useState(null),u=A!==null;Cd(m=>m.in_edit_mode);const h=Cd(m=>m.in_move_footprint_mode),d=Cd(m=>m.setIsMovingComponent),_=e||!h;return W.jsxs("div",{ref:a,style:{position:"relative",overflow:"hidden"},onMouseDown:m=>{if(_)return;const p=m.currentTarget.getBoundingClientRect(),I=m.clientX-p.left,f=m.clientY-p.top;if(Number.isNaN(I)||Number.isNaN(f))return;const C=mt(QQ(n),{x:I,y:f});let y=!1;for(const E of o)if(E.type==="pcb_component"&&UYo(E,C,10/n.a)){i(),c(E.pcb_component_id),y=!0;const B=Math.random().toString();g({dragStart:C,originalCenter:E.center,dragEnd:C,edit_event_id:B}),r({edit_event_id:B,edit_event_type:"edit_pcb_component_location",pcb_edit_event_type:"edit_component_location",pcb_component_id:E.pcb_component_id,original_center:E.center,new_center:E.center,in_progress:!0,created_at:Date.now()}),d(!0);break}if(y||c(null),y)return m.preventDefault(),!1},onMouseMove:m=>{if(!A||!l)return;const p=m.currentTarget.getBoundingClientRect(),I=m.clientX-p.left,f=m.clientY-p.top;if(Number.isNaN(I)||Number.isNaN(f))return;const C=mt(QQ(n),{x:I,y:f});g({...l,dragEnd:C}),s({edit_event_id:l.edit_event_id,new_center:{x:l.originalCenter.x+C.x-l.dragStart.x,y:l.originalCenter.y+C.y-l.dragStart.y}})},onMouseUp:m=>{A&&(c(null),d(!1),l&&(s({edit_event_id:l.edit_event_id,in_progress:!1}),g(null)))},children:[t,!_&&o.filter(m=>m.type==="pcb_component").map(m=>{if(!m?.center)return null;const p=mt(n,m.center);return W.jsx("div",{style:{position:"absolute",pointerEvents:"none",left:p.x,top:p.y,width:m.width*n.a+20,height:m.height*n.a+20,transform:"translate(-50%, -50%)",background:u&&A===m.pcb_component_id?"rgba(255, 0, 0, 0.2)":""}},m.pcb_component_id)})]})},a9e=(t,e)=>{const n=e.current;if(!n)return{transform:"translate(-50%, -100%)",left:t.x,top:t.y};const o=n.getBoundingClientRect(),i=200,r=10,s=60;let a="-50%",A="-100%",c=t.x,l=t.y;return t.x+s+i<o.width-r?(c=t.x+s,a="0%"):t.x-s-i>r?(c=t.x-s,a="-100%"):(c=t.x,a="-50%"),{transform:`translate(${a}, ${A})`,left:c,top:l}},zYo=({center:t})=>W.jsxs("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none",mixBlendMode:"difference",zIndex:Yg.errorOverlay+30},width:"100%",height:"100%",children:[W.jsx("circle",{cx:t.x,cy:t.y,r:11,fill:"none",stroke:"#ff6b6b",strokeWidth:2.5,opacity:.95}),W.jsx("circle",{cx:t.x,cy:t.y,r:4.5,fill:"#ff6b6b",opacity:.95}),W.jsx("line",{x1:t.x-18,y1:t.y,x2:t.x-8,y2:t.y,stroke:"#ff6b6b",strokeWidth:2}),W.jsx("line",{x1:t.x+8,y1:t.y,x2:t.x+18,y2:t.y,stroke:"#ff6b6b",strokeWidth:2}),W.jsx("line",{x1:t.x,y1:t.y-18,x2:t.x,y2:t.y-8,stroke:"#ff6b6b",strokeWidth:2}),W.jsx("line",{x1:t.x,y1:t.y+8,x2:t.x,y2:t.y+18,stroke:"#ff6b6b",strokeWidth:2})]}),HLt=({errorCenter:t,isHighlighted:e=!1})=>W.jsx("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none",mixBlendMode:"difference",zIndex:Yg.errorOverlay},width:"100%",height:"100%",children:W.jsx("rect",{x:t.x-7,y:t.y-7,width:14,height:14,transform:`rotate(45 ${t.x} ${t.y})`,fill:e?"#ff4444":"transparent",stroke:e?"#ff4444":"red",strokeWidth:e?2.5:1.5})}),A9e=Bse`
|
|
5684
|
+
$1`).replace(/>(\s*)(?=<!--\s*\/)/g,"> ")}}});function iLt(t,e,n){if(!e||!n)return;let o=t.get(e);o||(o=new Set,t.set(e,o)),o.add(n);let i=t.get(n);i||(i=new Set,t.set(n,i)),i.add(e)}function TKo(t,e){if(!e.subcircuit_id&&!e.source_group_id)return[...t];let n=e;if(e.subcircuit_id){const a=new Set([e.subcircuit_id]),A=new Map,c=new Map;for(const g of t)if(g.type==="source_group"){const u=g.source_group_id,h=g.subcircuit_id;h&&c.set(u,h);const d=g.parent_source_group_id;d&&(A.has(d)||A.set(d,[]),A.get(d).push(u))}let l;for(const[g,u]of c)if(u===e.subcircuit_id){l=g;break}if(l){const g=u=>{const h=A.get(u)||[];for(const d of h){const _=c.get(d);_&&a.add(_),g(d)}};g(l),n={...e,subcircuit_ids:Array.from(a)}}}const o=new Map;for(const a of t){const A=`${a.type}_id`,c=a[A];typeof c=="string"&&o.set(c,a)}const i=new Map;for(const a of t){const A=Object.entries(a);for(const[c,l]of A)if(c!=="parent_source_group_id"){if(c.endsWith("_id")&&typeof l=="string"){const g=o.get(l);iLt(i,a,g)}else if(c.endsWith("_ids")&&Array.isArray(l)){for(const g of l)if(typeof g=="string"){const u=o.get(g);iLt(i,a,u)}}}}const r=[],s=new Set;for(const a of t){let A=!1;(n.subcircuit_id&&"subcircuit_id"in a&&a.subcircuit_id===n.subcircuit_id||n.subcircuit_ids&&"subcircuit_id"in a&&a.subcircuit_id&&n.subcircuit_ids.includes(a.subcircuit_id)||n.source_group_id&&"source_group_id"in a&&a.source_group_id===n.source_group_id||n.source_group_id&&"member_source_group_ids"in a&&Array.isArray(a.member_source_group_ids)&&a.member_source_group_ids.includes(n.source_group_id))&&(A=!0),A&&(r.push(a),s.add(a))}for(;r.length>0;){const a=r.shift(),A=i.get(a);if(A)for(const c of A)s.has(c)||(s.add(c),r.push(c))}return t.filter(a=>s.has(a))}var Dse=(t,e={})=>{const n=t;let o=n._internal_store;if(!o){o={counts:{},editCount:0},n._internal_store=o;for(const r of n){const s=r.type,a=r[`${s}_id`];if(!a)continue;const A=Number.parseInt(a.split("_").pop());Number.isNaN(A)||(o.counts[s]=Math.max(o.counts[s]??0,A))}}const i=new Proxy({},{get:(r,s)=>{if(s==="toArray")return()=>(n.editCount=o.editCount,n);if(s==="editCount")return o.editCount;if(s==="subtree")return A=>Dse(TKo(n,A),e);if(s==="insert")return A=>{const c=A.type;if(!c)throw new Error("insert requires an element with a type");o.counts[c]??=-1,o.counts[c]++;const l=o.counts[c],g={...A,type:c,[`${c}_id`]:`${c}_${l}`};return e.validateInserts&&(D8e[c]??rse).parse(g),n.push(g),o.editCount++,g};if(s==="insertAll")return A=>A.map(c=>i.insert(c));const a=s;return{get:A=>n.find(c=>c.type===a&&c[`${a}_id`]===A),getUsing:A=>{const c=Object.keys(A);if(c.length!==1)throw new Error("getUsing requires exactly one key, e.g. { pcb_component_id }");const l=c[0],g=l.replace("_id",""),u=n.find(h=>h.type===g&&h[l]===A[l]);return u?n.find(h=>h.type===a&&h[`${a}_id`]===u[`${a}_id`]):null},getWhere:A=>{const c=Object.keys(A);return n.find(l=>l.type===a&&c.every(g=>l[g]===A[g]))},list:A=>{const c=A?Object.keys(A):[];return n.filter(l=>l.type===a&&c.every(g=>l[g]===A[g]))},insert:A=>{o.counts[a]??=-1,o.counts[a]++;const c=o.counts[a],l={type:a,[`${a}_id`]:`${a}_${c}`,...A};return e.validateInserts&&(D8e[a]??rse).parse(l),n.push(l),o.editCount++,l},delete:A=>{const c=n.find(l=>l[`${a}_id`]===A);c&&(n.splice(n.indexOf(c),1),o.editCount++)},update:(A,c)=>{const l=n.find(g=>g.type===a&&g[`${a}_id`]===A);return l?(Object.assign(l,c),o.editCount++,l):null},select:A=>{if(a==="source_component")return n.find(c=>c.type==="source_component"&&c.name===A.replace(/\./g,""));if(a==="pcb_port"||a==="source_port"||a==="schematic_port"){const[c,l]=A.replace(/\./g,"").split(/[\s\>]+/),g=n.find(h=>h.type==="source_component"&&h.name===c);if(!g)return null;const u=n.find(h=>h.type==="source_port"&&h.source_component_id===g.source_component_id&&(h.name===l||(h.port_hints??[]).includes(l)));if(!u)return null;if(a==="source_port")return u;if(a==="pcb_port")return n.find(h=>h.type==="pcb_port"&&h.source_port_id===u.source_port_id);if(a==="schematic_port")return n.find(h=>h.type==="schematic_port"&&h.source_port_id===u.source_port_id)}}}}});return i};Dse.unparsed=Dse;var N6=Dse;function o9e(t){const e=t.type;return`${e}:${t[`${e}_id`]}`}var rLt=(t,e={})=>{let n=t._internal_store_indexed;if(!n){n={counts:{},editCount:0,indexes:{}};for(const s of t){const a=s.type,A=s[`${a}_id`];if(!A)continue;const c=Number.parseInt(A.split("_").pop()||"");Number.isNaN(c)||(n.counts[a]=Math.max(n.counts[a]??0,c))}const i=e.indexConfig||{},r=n.indexes;if(i.byId&&(r.byId=new Map),i.byType&&(r.byType=new Map),i.byRelation&&(r.byRelation=new Map),i.bySubcircuit&&(r.bySubcircuit=new Map),i.byCustomField&&i.byCustomField.length>0){r.byCustomField=new Map;for(const s of i.byCustomField)r.byCustomField.set(s,new Map)}for(const s of t){if(i.byId){const a=o9e(s);r.byId.set(a,s)}if(i.byType){const a=r.byType.get(s.type)||[];a.push(s),r.byType.set(s.type,a)}if(i.byRelation){const a=Object.entries(s);for(const[A,c]of a)if(A.endsWith("_id")&&A!==`${s.type}_id`&&typeof c=="string"){const l=r.byRelation.get(A)||new Map,g=l.get(c)||[];g.push(s),l.set(c,g),r.byRelation.set(A,l)}}if(i.bySubcircuit&&"subcircuit_id"in s){const a=s.subcircuit_id;if(a&&typeof a=="string"){const A=r.bySubcircuit.get(a)||[];A.push(s),r.bySubcircuit.set(a,A)}}if(i.byCustomField&&r.byCustomField){for(const a of i.byCustomField)if(a in s){const A=s[a];if(A!==void 0&&(typeof A=="string"||typeof A=="number")){const c=String(A),l=r.byCustomField.get(a),g=l.get(c)||[];g.push(s),l.set(c,g)}}}}t._internal_store_indexed=n}return new Proxy({},{get:(i,r)=>{if(r==="toArray")return()=>(t.editCount=n.editCount,t);if(r==="editCount")return n.editCount;const s=r;return{get:a=>{const A=e.indexConfig||{};return A.byId&&n.indexes.byId?n.indexes.byId.get(`${s}:${a}`)||null:A.byType&&n.indexes.byType?(n.indexes.byType.get(s)||[]).find(l=>l[`${s}_id`]===a)||null:t.find(c=>c.type===s&&c[`${s}_id`]===a)||null},getUsing:a=>{const A=e.indexConfig||{},c=Object.keys(a);if(c.length!==1)throw new Error("getUsing requires exactly one key, e.g. { pcb_component_id }");const l=c[0],g=l.replace("_id","");if(A.byRelation&&n.indexes.byRelation){const h=n.indexes.byRelation.get(l);if(h){const _=(h.get(a[l])||[]).find(p=>p.type===g);if(!_)return null;const m=_[`${s}_id`];return A.byId&&n.indexes.byId?n.indexes.byId.get(`${s}:${m}`)||null:A.byType&&n.indexes.byType?(n.indexes.byType.get(s)||[]).find(I=>I[`${s}_id`]===m)||null:t.find(p=>p.type===s&&p[`${s}_id`]===m)||null}}const u=t.find(h=>h.type===g&&h[l]===a[l]);return u&&t.find(h=>h.type===s&&h[`${s}_id`]===u[`${s}_id`])||null},getWhere:a=>{const A=e.indexConfig||{},c=Object.keys(a);if(c.length===1&&A.byCustomField&&n.indexes.byCustomField){const l=c[0],g=n.indexes.byCustomField.get(l);if(g){const u=String(a[l]);return(g.get(u)||[]).find(d=>d.type===s)||null}}if("subcircuit_id"in a&&A.bySubcircuit&&n.indexes.bySubcircuit){const l=a.subcircuit_id;return(n.indexes.bySubcircuit.get(l)||[]).find(u=>u.type===s&&c.every(h=>u[h]===a[h]))||null}return A.byType&&n.indexes.byType?(n.indexes.byType.get(s)||[]).find(g=>c.every(u=>g[u]===a[u]))||null:t.find(l=>l.type===s&&c.every(g=>l[g]===a[g]))||null},list:a=>{const A=e.indexConfig||{},c=a?Object.keys(a):[];if(c.length===0&&A.byType&&n.indexes.byType)return n.indexes.byType.get(s)||[];if(c.length===1&&c[0]==="subcircuit_id"&&A.bySubcircuit&&n.indexes.bySubcircuit){const g=a.subcircuit_id;return(n.indexes.bySubcircuit.get(g)||[]).filter(h=>h.type===s)}let l;return A.byType&&n.indexes.byType?l=n.indexes.byType.get(s)||[]:l=t.filter(g=>g.type===s),c.length>0?l.filter(g=>c.every(u=>g[u]===a[u])):l},insert:a=>{n.counts[s]??=-1,n.counts[s]++;const A=n.counts[s],c={type:s,[`${s}_id`]:`${s}_${A}`,...a};e.validateInserts&&(D8e[s]??rse).parse(c),t.push(c),n.editCount++;const l=e.indexConfig||{};if(l.byId&&n.indexes.byId){const g=o9e(c);n.indexes.byId.set(g,c)}if(l.byType&&n.indexes.byType){const g=n.indexes.byType.get(s)||[];g.push(c),n.indexes.byType.set(s,g)}if(l.byRelation&&n.indexes.byRelation){const g=Object.entries(c);for(const[u,h]of g)if(u.endsWith("_id")&&u!==`${c.type}_id`&&typeof h=="string"){const d=n.indexes.byRelation.get(u)||new Map,_=d.get(h)||[];_.push(c),d.set(h,_),n.indexes.byRelation.set(u,d)}}if(l.bySubcircuit&&n.indexes.bySubcircuit&&"subcircuit_id"in c){const g=c.subcircuit_id;if(g&&typeof g=="string"){const u=n.indexes.bySubcircuit.get(g)||[];u.push(c),n.indexes.bySubcircuit.set(g,u)}}if(l.byCustomField&&n.indexes.byCustomField){for(const g of l.byCustomField)if(g in c){const u=c[g];if(u!==void 0&&(typeof u=="string"||typeof u=="number")){const h=String(u),d=n.indexes.byCustomField.get(g),_=d.get(h)||[];_.push(c),d.set(h,_)}}}return c},delete:a=>{const A=e.indexConfig||{};let c;if(A.byId&&n.indexes.byId?c=n.indexes.byId.get(`${s}:${a}`):A.byType&&n.indexes.byType?c=(n.indexes.byType.get(s)||[]).find(u=>u[`${s}_id`]===a):c=t.find(g=>g[`${s}_id`]===a),!c)return;const l=t.indexOf(c);if(l>=0&&(t.splice(l,1),n.editCount++),A.byId&&n.indexes.byId){const g=o9e(c);n.indexes.byId.delete(g)}if(A.byType&&n.indexes.byType){const u=(n.indexes.byType.get(s)||[]).filter(h=>h[`${s}_id`]!==a);n.indexes.byType.set(s,u)}if(A.byRelation&&n.indexes.byRelation)for(const[g,u]of n.indexes.byRelation.entries())for(const[h,d]of u.entries()){const _=d.filter(m=>m!==c);_.length===0?u.delete(h):u.set(h,_)}if(A.bySubcircuit&&n.indexes.bySubcircuit&&"subcircuit_id"in c){const g=c.subcircuit_id;if(g){const h=(n.indexes.bySubcircuit.get(g)||[]).filter(d=>d!==c);h.length===0?n.indexes.bySubcircuit.delete(g):n.indexes.bySubcircuit.set(g,h)}}if(A.byCustomField&&n.indexes.byCustomField)for(const g of n.indexes.byCustomField.values())for(const[u,h]of g.entries()){const d=h.filter(_=>_!==c);d.length===0?g.delete(u):g.set(u,d)}},update:(a,A)=>{const c=e.indexConfig||{};let l;if(c.byId&&n.indexes.byId?l=n.indexes.byId.get(`${s}:${a}`):c.byType&&n.indexes.byType?l=(n.indexes.byType.get(s)||[]).find(u=>u[`${s}_id`]===a):l=t.find(g=>g.type===s&&g[`${s}_id`]===a),!l)return null;if(c.byRelation&&n.indexes.byRelation){const g=Object.entries(l);for(const[u,h]of g)if(u.endsWith("_id")&&u!==`${l.type}_id`&&typeof h=="string"&&u in A&&A[u]!==h){const d=n.indexes.byRelation.get(u);if(d){const m=(d.get(h)||[]).filter(p=>p!==l);m.length===0?d.delete(h):d.set(h,m)}}}if(c.bySubcircuit&&n.indexes.bySubcircuit&&"subcircuit_id"in l&&"subcircuit_id"in A){const g=l.subcircuit_id,u=A.subcircuit_id;if(g!==u){const d=(n.indexes.bySubcircuit.get(g)||[]).filter(_=>_!==l);d.length===0?n.indexes.bySubcircuit.delete(g):n.indexes.bySubcircuit.set(g,d)}}if(c.byCustomField&&n.indexes.byCustomField){for(const g of c.byCustomField)if(g in l&&g in A&&l[g]!==A[g]){const u=n.indexes.byCustomField.get(g);if(u){const h=String(l[g]),_=(u.get(h)||[]).filter(m=>m!==l);_.length===0?u.delete(h):u.set(h,_)}}}if(Object.assign(l,A),n.editCount++,c.byRelation&&n.indexes.byRelation){const g=Object.entries(l);for(const[u,h]of g)if(u.endsWith("_id")&&u!==`${l.type}_id`&&typeof h=="string"&&u in A){const d=n.indexes.byRelation.get(u)||new Map,_=d.get(h)||[];_.includes(l)||(_.push(l),d.set(h,_),n.indexes.byRelation.set(u,d))}}if(c.bySubcircuit&&n.indexes.bySubcircuit&&"subcircuit_id"in l&&"subcircuit_id"in A){const g=l.subcircuit_id;if(g&&typeof g=="string"){const u=n.indexes.bySubcircuit.get(g)||[];u.includes(l)||(u.push(l),n.indexes.bySubcircuit.set(g,u))}}if(c.byCustomField&&n.indexes.byCustomField){for(const g of c.byCustomField)if(g in l&&g in A){const u=l[g];if(u!==void 0&&(typeof u=="string"||typeof u=="number")){const h=String(u),d=n.indexes.byCustomField.get(g),_=d.get(h)||[];_.includes(l)||(_.push(l),d.set(h,_))}}}return l},select:a=>{if(s==="source_component")return t.find(A=>A.type==="source_component"&&A.name===a.replace(/\./g,""))||null;if(s==="pcb_port"||s==="source_port"||s==="schematic_port"){const[A,c]=a.replace(/\./g,"").split(/[\s\>]+/),l=t.find(u=>u.type==="source_component"&&u.name===A);if(!l)return null;const g=t.find(u=>u.type==="source_port"&&u.source_component_id===l.source_component_id&&(u.name===c||(u.port_hints??[]).includes(c)));if(!g)return null;if(s==="source_port")return g;if(s==="pcb_port")return t.find(u=>u.type==="pcb_port"&&u.source_port_id===g.source_port_id)||null;if(s==="schematic_port")return t.find(u=>u.type==="schematic_port"&&u.source_port_id===g.source_port_id)||null}return null}}}})};rLt.unparsed=rLt;var kKo=t=>{const e=t.type;return t[`${e}_id`]},sLt=(t,e)=>({minX:Math.min(t.minX,e.minX),minY:Math.min(t.minY,e.minY),maxX:Math.max(t.maxX,e.maxX),maxY:Math.max(t.maxY,e.maxY)}),Pse=(t,e,n)=>{const o=n/2;return{minX:t-o,minY:e-o,maxX:t+o,maxY:e+o}},aLt=(t,e,n,o,i)=>{const r=n/2,s=o/2,a=i*Math.PI/180,A=Math.cos(a),c=Math.sin(a),l=[{x:-r,y:-s},{x:r,y:-s},{x:r,y:s},{x:-r,y:s}].map(g=>({x:t+g.x*A-g.y*c,y:e+g.x*c+g.y*A}));return{minX:Math.min(...l.map(g=>g.x)),minY:Math.min(...l.map(g=>g.y)),maxX:Math.max(...l.map(g=>g.x)),maxY:Math.max(...l.map(g=>g.y))}},i9e=t=>{let e=Number.POSITIVE_INFINITY,n=Number.POSITIVE_INFINITY,o=Number.NEGATIVE_INFINITY,i=Number.NEGATIVE_INFINITY;for(const r of t){if(!r.type.startsWith("pcb_"))continue;if(r.type==="pcb_smtpad"&&r.shape==="polygon"&&Array.isArray(r.points)){for(const g of r.points)e=Math.min(e,g.x),n=Math.min(n,g.y),o=Math.max(o,g.x),i=Math.max(i,g.y);continue}if(r.type==="pcb_hole"&&r.hole_shape==="circle"){const g=Pse(r.x,r.y,r.hole_diameter);e=Math.min(e,g.minX),n=Math.min(n,g.minY),o=Math.max(o,g.maxX),i=Math.max(i,g.maxY);continue}if(r.type==="pcb_plated_hole"){let g;if("outer_diameter"in r&&typeof r.outer_diameter=="number"?g=Pse(r.x,r.y,r.outer_diameter):"hole_diameter"in r&&typeof r.hole_diameter=="number"&&(g=Pse(r.x,r.y,r.hole_diameter)),"rect_pad_width"in r&&typeof r.rect_pad_width=="number"&&"rect_pad_height"in r&&typeof r.rect_pad_height=="number"){const u=aLt(r.x,r.y,r.rect_pad_width,r.rect_pad_height,"rect_ccw_rotation"in r?r.rect_ccw_rotation??0:0);g=g?sLt(g,u):u}if("hole_diameter"in r&&typeof r.hole_diameter=="number"){const u=Pse(r.x+("hole_offset_x"in r?r.hole_offset_x??0:0),r.y+("hole_offset_y"in r?r.hole_offset_y??0:0),r.hole_diameter);g=g?sLt(g,u):u}if(g){e=Math.min(e,g.minX),n=Math.min(n,g.minY),o=Math.max(o,g.maxX),i=Math.max(i,g.maxY);continue}}let s,a,A,c;"x"in r&&"y"in r&&(s=Number(r.x),a=Number(r.y)),"outer_diameter"in r&&(A=Number(r.outer_diameter),c=Number(r.outer_diameter)),"width"in r&&(A=Number(r.width)),"height"in r&&(c=Number(r.height)),"center"in r&&(s=r.center.x,a=r.center.y);const l=typeof r.rotation=="number"?r.rotation:0;if(s!==void 0&&a!==void 0){if(e=Math.min(e,s),n=Math.min(n,a),o=Math.max(o,s),i=Math.max(i,a),A!==void 0&&c!==void 0)if(l){const g=aLt(s,a,A,c,l);e=Math.min(e,g.minX),n=Math.min(n,g.minY),o=Math.max(o,g.maxX),i=Math.max(i,g.maxY)}else e=Math.min(e,s-A/2),n=Math.min(n,a-c/2),o=Math.max(o,s+A/2),i=Math.max(i,a+c/2);"radius"in r&&(e=Math.min(e,s-r.radius),n=Math.min(n,a-r.radius),o=Math.max(o,s+r.radius),i=Math.max(i,a+r.radius))}else if(r.type==="pcb_trace")for(const g of r.route)e=Math.min(e,g.x),n=Math.min(n,g.y),o=Math.max(o,g.x),i=Math.max(i,g.y);else if(r.type==="pcb_courtyard_outline")for(const g of r.outline)e=Math.min(e,g.x),n=Math.min(n,g.y),o=Math.max(o,g.x),i=Math.max(i,g.y);else if(r.type==="pcb_courtyard_polygon")for(const g of r.points)e=Math.min(e,g.x),n=Math.min(n,g.y),o=Math.max(o,g.x),i=Math.max(i,g.y)}return{minX:e,minY:n,maxX:o,maxY:i}};function FKo(t){let e=0;if(t.length==0)return e;for(var n=0;n<t.length;n++){var o=t.charCodeAt(n);e=(e<<5)-e+o,e=e&e}return Math.abs(e)}var ALt=[["#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"]],LKo=t=>{let{x:e,y:n,width:o,height:i}={...t,...t.size,...t.center,...t.position};if(t.x1!==void 0&&t.x2!==void 0&&t.y1!==void 0&&t.y2!==void 0&&(e=(t.x1+t.x2)/2,n=(t.y1+t.y2)/2,o=Math.abs(t.x1-t.x2),i=Math.abs(t.y1-t.y2)),t.points&&Array.isArray(t.points)&&t.points.length>0){const a=t.points.map(h=>h.x),A=t.points.map(h=>h.y),c=Math.min(...a),l=Math.max(...a),g=Math.min(...A),u=Math.max(...A);e=(c+l)/2,n=(g+u)/2,o=l-c,i=u-g}const r=t.text||t.name||t.source?.text||t.source?.name||"?",s=t;return e===void 0||n===void 0?null:(o===void 0&&("outer_diameter"in t?(o=t.outer_diameter,i=t.outer_diameter):"rect_pad_width"in t&&"rect_pad_height"in t?(o=t.rect_pad_width,i=t.rect_pad_height,"hole_diameter"in t&&(o=Math.max(o,t.hole_diameter),i=Math.max(i,t.hole_diameter))):"hole_diameter"in t&&(o=t.hole_diameter,i=t.hole_diameter)),(o===void 0||i===void 0)&&(o=.1,i=.1),{x:e,y:n,width:o,height:i,title:r,content:s,bg_color:ALt[FKo(t.type||r)%ALt.length]?.[4]??"#f00"})},HKo=t=>!!t,GKo=t=>{const e=t.filter(c=>c.type.startsWith("pcb_")||c.type.startsWith("schematic_")).concat(t.filter(c=>c.type==="pcb_trace"||c.type==="schematic_trace").flatMap(c=>c.route)).map(c=>LKo(c)).filter(HKo);if(e.length===0)return{center:{x:0,y:0},width:0,height:0};let n=e[0].x-e[0].width/2,o=e[0].x+e[0].width/2,i=e[0].y-e[0].height/2,r=e[0].y+e[0].height/2;for(const c of e.slice(1))n=Math.min(n,c.x-c.width/2),o=Math.max(o,c.x+c.width/2),i=Math.min(i,c.y-c.height/2),r=Math.max(r,c.y+c.height/2);const s=o-n,a=r-i;return{center:{x:n+s/2,y:i+a/2},width:s,height:a}},vp={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_PCB_NOTES:"pcb_viewer_is_showing_pcb_notes",IS_SHOWING_SILKSCREEN:"pcb_viewer_is_showing_silkscreen"},Ov=(t,e)=>{if(typeof window>"u")return e;try{const n=localStorage.getItem(t);return n!==null?JSON.parse(n):e}catch{return e}},Kv=(t,e)=>{if(!(typeof window>"u"))try{localStorage.setItem(t,JSON.stringify(e))}catch{}},OKo=(t,e)=>{if(typeof window>"u")return e;try{const n=localStorage.getItem(t);return n!==null?JSON.parse(n):e}catch{return e}},KKo=(t,e)=>{if(!(typeof window>"u"))try{localStorage.setItem(t,JSON.stringify(e))}catch{}},UKo="named_only",YKo=(t={},e=!1)=>nFt(n=>({selected_layer:"top",pcb_viewer_id:`pcb_viewer_${Math.random().toString().slice(2,10)}`,in_edit_mode:!1,in_move_footprint_mode:!1,is_moving_component:!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:Ov(vp.IS_SHOWING_COPPER_POURS,!0),is_showing_courtyards:Ov(vp.IS_SHOWING_COURTYARDS,!0),is_showing_pcb_groups:e?!1:Ov(vp.IS_SHOWING_PCB_GROUPS,!0),is_showing_group_anchor_offsets:Ov(vp.IS_SHOWING_GROUP_ANCHOR_OFFSETS,!1),is_showing_solder_mask:Ov(vp.IS_SHOWING_SOLDER_MASK,!1),is_showing_silkscreen:Ov(vp.IS_SHOWING_SILKSCREEN,!0),is_showing_fabrication_notes:Ov(vp.IS_SHOWING_FABRICATION_NOTES,!1),is_showing_pcb_notes:Ov(vp.IS_SHOWING_PCB_NOTES,!0),pcb_group_view_mode:e?"all":OKo(vp.PCB_GROUP_VIEW_MODE,UKo),hovered_error_id:null,focused_error_id:null,...t,selectLayer:o=>n({selected_layer:o}),setEditMode:o=>n({in_edit_mode:o!=="off",in_move_footprint_mode:o==="move_footprint",is_moving_component:!1}),setIsShowingRatsNest:o=>n({is_showing_rats_nest:o}),setIsMovingComponent:o=>n({is_moving_component:o}),setIsMouseOverContainer:o=>n({is_mouse_over_container:o}),setIsShowingMultipleTracesLength:o=>n({is_showing_multiple_traces_length:o}),setIsShowingAutorouting:o=>n({is_showing_autorouting:o}),setIsShowingDrcErrors:o=>n({is_showing_drc_errors:o}),setIsShowingCopperPours:o=>{Kv(vp.IS_SHOWING_COPPER_POURS,o),n({is_showing_copper_pours:o})},setIsShowingCourtyards:o=>{Kv(vp.IS_SHOWING_COURTYARDS,o),n({is_showing_courtyards:o})},setIsShowingPcbGroups:o=>{e||(Kv(vp.IS_SHOWING_PCB_GROUPS,o),n({is_showing_pcb_groups:o}))},setIsShowingGroupAnchorOffsets:o=>{Kv(vp.IS_SHOWING_GROUP_ANCHOR_OFFSETS,o),n({is_showing_group_anchor_offsets:o})},setIsShowingSolderMask:o=>{Kv(vp.IS_SHOWING_SOLDER_MASK,o),n({is_showing_solder_mask:o})},setIsShowingSilkscreen:o=>{Kv(vp.IS_SHOWING_SILKSCREEN,o),n({is_showing_silkscreen:o})},setIsShowingFabricationNotes:o=>{Kv(vp.IS_SHOWING_FABRICATION_NOTES,o),n({is_showing_fabrication_notes:o})},setIsShowingPcbNotes:o=>{Kv(vp.IS_SHOWING_PCB_NOTES,o),n({is_showing_pcb_notes:o})},setPcbGroupViewMode:o=>{e||(KKo(vp.PCB_GROUP_VIEW_MODE,o),n({pcb_group_view_mode:o}))},setHoveredErrorId:o=>n({hovered_error_id:o}),setFocusedErrorId:o=>n({focused_error_id:o})})),Cd=t=>{const e=Z.useContext(cLt);return uFt(e,t)},cLt=Z.createContext(null),zKo=({children:t,initialState:e,disablePcbGroups:n})=>{const o=Z.useMemo(()=>YKo(e,n),[n]);return W.jsx(cLt.Provider,{value:o,children:t})},VKo=()=>{Z.useEffect(()=>{_Oo()},[]);const t=Cd(e=>e.pcb_viewer_id);return W.jsx(hOo,{position:"top-center",containerId:t})};function JKo(){var t=Z.useRef(!1),e=Z.useCallback(function(){return t.current},[]);return Z.useEffect(function(){return t.current=!0,function(){t.current=!1}},[]),e}var qKo=function(t){t===void 0&&(t={});var e=Z.useState(t),n=e[0],o=e[1],i=Z.useCallback(function(r){o(function(s){return Object.assign({},s,r instanceof Function?r(s):r)})},[]);return[n,i]},WKo=qKo,jKo=function(){},lLt=typeof window<"u",XKo=$8e(pKo()),$Ko=function(){var t=JKo(),e=WKo({value:void 0,error:void 0,noUserInteraction:!0}),n=e[0],o=e[1],i=Z.useCallback(function(r){if(t()){var s,a;try{if(typeof r!="string"&&typeof r!="number"){var A=new Error("Cannot copy typeof "+typeof r+" to clipboard, must be a string");console.error(A),o({value:r,error:A,noUserInteraction:!0});return}else if(r===""){var A=new Error("Cannot copy empty string to clipboard.");console.error(A),o({value:r,error:A,noUserInteraction:!0});return}a=r.toString(),s=(0,XKo.default)(a),o({value:a,error:void 0,noUserInteraction:s})}catch(c){o({value:a,error:c,noUserInteraction:s})}}},[]);return[n,i]},ZKo=$Ko,eUo=lLt?Z.useLayoutEffect:Z.useEffect,tUo=eUo,gLt={x:0,y:0,width:0,height:0,top:0,left:0,bottom:0,right:0};function nUo(){var t=Z.useState(null),e=t[0],n=t[1],o=Z.useState(gLt),i=o[0],r=o[1],s=Z.useMemo(function(){return new window.ResizeObserver(function(a){if(a[0]){var A=a[0].contentRect,c=A.x,l=A.y,g=A.width,u=A.height,h=A.top,d=A.left,_=A.bottom,m=A.right;r({x:c,y:l,width:g,height:u,top:h,left:d,bottom:_,right:m})}})},[]);return tUo(function(){if(e)return s.observe(e),function(){s.disconnect()}},[e]),[n,i]}var pY=lLt&&typeof window.ResizeObserver<"u"?nUo:function(){return[jKo,gLt]},uLt=({initialTransform:t,initialTouch1:e,initialTouch2:n,finalTouch1:o,finalTouch2:i})=>{if(!o||!i)return t;const r={x:(e.x+n.x)/2,y:(e.y+n.y)/2},s={x:(o.x+i.x)/2,y:(o.y+i.y)/2},a=Math.hypot(n.x-e.x,n.y-e.y),A=Math.hypot(i.x-o.x,i.y-o.y),c=a===0?1:A/a,l=s.x-r.x,g=s.y-r.y;return ki(Wi(l,g),Wi(r.x,r.y),ug(c,c),Wi(-r.x,-r.y),t)},oUo=(t={})=>{const e=Z.useRef(null),[n,o]=Z.useState(0),i=t.canvasElm??e.current,[r,s]=Z.useState(t.initialTransform??Ll()),[a,A]=Z.useState(0),[c,l]=Z.useReducer(f=>f+1,0),g=Z.useCallback(f=>{t.onSetTransform&&t.onSetTransform(f),t.transform||s(f)},[t.onSetTransform,s]),u=Z.useCallback(f=>{g(f),l()},[g]),h=t.transform??r,d=Z.useCallback(()=>{o(Date.now())},[]),_=Z.useRef("none"),m=Z.useRef(null),p=Z.useRef(null);Z.useEffect(()=>{const f=t.canvasElm??e.current;if(f&&!i){A(a+1);return}if(!f){const q=setTimeout(()=>{A(a+1)},100);return()=>clearTimeout(q)}let C=t.transform??r,y={x:0,y:0},E={x:0,y:0},B=!1;const Q=q=>({x:q.pageX-f.getBoundingClientRect().left-window.scrollX,y:q.pageY-f.getBoundingClientRect().top-window.scrollY});function b(q){t.enabled!==!1&&(t.shouldDrag&&!t.shouldDrag(q)||(y=Q(q),!(Date.now()-n<100)&&(B=!0,q.preventDefault())))}function D(q){if(!B||t.enabled===!1||t.shouldDrag&&!t.shouldDrag(q))return;E=Q(q);const j=ki(Wi(E.x-y.x,E.y-y.y),C);g(j),C=j,B=!1}function R(q){if(Q(q),!B||t.enabled===!1||t.shouldDrag&&!t.shouldDrag(q))return;E=Q(q);const j=ki(Wi(E.x-y.x,E.y-y.y),C);g(j)}function w(q){if(t.enabled===!1||t.shouldDrag&&!t.shouldDrag(q))return;const j=Q(q),ne=ki(Wi(j.x,j.y),ug(1-q.deltaY/1e3,1-q.deltaY/1e3),Wi(-j.x,-j.y),C);g(ne),C=ne,q.preventDefault()}function H(q){if(!B||t.shouldDrag&&!t.shouldDrag(q))return;if(f){const ne=f.getBoundingClientRect();if(q.clientX>=ne.left+10&&q.clientX<=ne.right-10&&q.clientY>=ne.top+10&&q.clientY<=ne.bottom-10)return}B=!1,E=Q(q);const j=ki(Wi(E.x-y.x,E.y-y.y),C);g(j),C=j}function G(q){if(q.preventDefault(),t.enabled!==!1){if(q.touches.length===1){_.current="drag";const j=q.touches[0];m.current={initialTransform:C,initialTouch:{x:j.clientX,y:j.clientY}}}else if(q.touches.length===2){_.current="pinch";const j=q.touches[0],ne=q.touches[1];p.current={initialTransform:C,initialTouch1:{x:j.clientX,y:j.clientY},initialTouch2:{x:ne.clientX,y:ne.clientY},finalTouch1:null,finalTouch2:null}}}}function K(q){if(q.preventDefault(),t.enabled!==!1){if(_.current==="drag"&&q.touches.length===1&&m.current){const j=q.touches[0],ne={x:j.clientX,y:j.clientY},re=ne.x-m.current.initialTouch.x,X=ne.y-m.current.initialTouch.y,te=ki(Wi(re,X),m.current.initialTransform);g(te)}else if(_.current==="pinch"&&q.touches.length===2&&p.current){const j=q.touches[0],ne=q.touches[1];p.current.finalTouch1={x:j.clientX,y:j.clientY},p.current.finalTouch2={x:ne.clientX,y:ne.clientY};const re=uLt(p.current);g(re)}}}function U(q){q.preventDefault();const j=q.changedTouches[0];if(_.current==="drag"&&m.current&&j){const ne={x:j.clientX,y:j.clientY},re=ne.x-m.current.initialTouch.x,X=ne.y-m.current.initialTouch.y,te=ki(Wi(re,X),m.current.initialTransform);g(te),C=te}else if(_.current==="pinch"&&p.current){const ne=uLt(p.current);g(ne),C=ne}_.current="none",m.current=null,p.current=null}return f.addEventListener("mousedown",b),f.addEventListener("mouseup",D),window.addEventListener("mousemove",R),f.addEventListener("mouseout",H),f.addEventListener("wheel",w),f.addEventListener("touchstart",G,{passive:!1}),f.addEventListener("touchmove",K,{passive:!1}),f.addEventListener("touchend",U,{passive:!1}),f.addEventListener("touchcancel",U,{passive:!1}),()=>{f.removeEventListener("mousedown",b),f.removeEventListener("mouseup",D),window.removeEventListener("mousemove",R),f.removeEventListener("mouseout",H),f.removeEventListener("wheel",w),f.removeEventListener("touchstart",G),f.removeEventListener("touchmove",K),f.removeEventListener("touchend",U),f.removeEventListener("touchcancel",U)}},[i,a,c,n,t.enabled,t.shouldDrag]);const I=Z.useCallback(f=>mt(h,f),[h]);return{ref:e,transform:h,applyTransformToPoint:I,setTransform:u,cancelDrag:d}},iUo=oUo;function rUo(t){const e=new Map;let n=0;function o(i){for(const[,s]of e)if(s.has(i))return s;const r=new Set;return e.set(`connectivity_net${n++}`,r),r}for(const i of t){let r=null;for(const s of i){if(!r)r=o(s);else if(!r.has(s)){const a=o(s);if(a!==r){for(const A of a)r.add(A);e.delete(Array.from(e.entries()).find(([,A])=>A===a)[0])}}r.add(s)}}return Object.fromEntries(Array.from(e.entries()).map(([i,r])=>[i,Array.from(r)]))}var sUo=class{netMap;idToNetMap;constructor(t){this.netMap=t,this.idToNetMap={};for(const[e,n]of Object.entries(t))for(const o of n)this.idToNetMap[o]=e}addConnections(t){for(const e of t){const n=new Set;for(const i of e){const r=this.idToNetMap[i];r&&n.add(r)}let o;if(n.size===0)o=`connectivity_net${Object.keys(this.netMap).length}`,this.netMap[o]=[];else if(n.size===1)o=n.values().next().value??`connectivity_net${Object.keys(this.netMap).length}`;else{o=n.values().next().value??`connectivity_net${Object.keys(this.netMap).length}`;for(const i of n)if(i!==o){this.netMap[o].push(...this.netMap[i]),this.netMap[i]=this.netMap[o];for(const r of this.netMap[o])this.idToNetMap[r]=o}}for(const i of e)this.netMap[o].includes(i)||this.netMap[o].push(i),this.idToNetMap[i]=o}}getIdsConnectedToNet(t){return this.netMap[t]||[]}getNetConnectedToId(t){return this.idToNetMap[t]}areIdsConnected(t,e){if(t===e)return!0;const n=this.getNetConnectedToId(t);if(!n)return!1;const o=this.getNetConnectedToId(e);return o?n===o||o===t||o===t:!1}areAllIdsConnected(t){const e=this.getNetConnectedToId(t[0]);for(const n of t){const o=this.getNetConnectedToId(n);if(o===void 0||o!==e)return!1}return!0}},dLt=t=>{const e=[];for(const o of t)if(o.type==="source_trace")e.push([o.source_trace_id,...o.connected_source_port_ids??[],...o.connected_source_net_ids??[]].filter(Boolean));else if(o.type==="pcb_port"){const{pcb_port_id:i,source_port_id:r}=o;r&&i&&e.push([r,i])}else if(o.type==="pcb_smtpad"){const{pcb_smtpad_id:i,pcb_port_id:r}=o;r&&i&&e.push([i,r])}else if(o.type==="pcb_plated_hole"){const{pcb_plated_hole_id:i,pcb_port_id:r}=o;r&&i&&e.push([i,r])}else if(o.type==="pcb_trace"){const{pcb_trace_id:i,source_trace_id:r}=o,s=Array.isArray(o.route)?o.route.filter(a=>a&&a.route_type==="wire"):[];if(r&&i&&e.push([i,r]),Array.isArray(s)){const a=s.find(c=>c?.start_pcb_port_id)?.start_pcb_port_id,A=s.find(c=>c?.end_pcb_port_id)?.end_pcb_port_id;a&&i&&A&&e.push([a,i,A])}}else if(o.type==="pcb_via"){const{pcb_via_id:i,pcb_trace_id:r}=o;r&&i&&e.push([i,r])}else if(o.type==="source_component"&&o.internally_connected_source_port_ids)for(const i of o.internally_connected_source_port_ids)e.push(i);const n=rUo(e);return new sUo(n)};function aUo(t,e){if(t.length<2)throw new Error("Stroke must have at least two points");const n=t.map(g=>Array.isArray(g)?{x:g[0],y:g[1]}:g),o=[],i=[];function r(g,u){const h=u.x-g.x,d=u.y-g.y,_=Math.sqrt(h*h+d*d);return{x:-d/_,y:h/_}}function s(g,u,h,d){const _=d/2,m={x:g.x+u.x*_*h,y:g.y+u.y*_*h};h>0?o.push(m):i.unshift(m)}const a=r(n[0],n[1]),A=n[0].trace_width??e;s(n[0],a,1,A),s(n[0],a,-1,A);for(let g=1;g<n.length-1;g++){const u=n[g-1],h=n[g],d=n[g+1],_=r(u,h),m=r(h,d),p=_.x+m.x,I=_.y+m.y,f=Math.sqrt(p*p+I*I),C=h.trace_width??e;if(f/2>2*(C/2))s(h,_,1,C),s(h,m,1,C),s(h,_,-1,C),s(h,m,-1,C);else{const E=1/f;s(h,{x:p*E,y:I*E},1,C),s(h,{x:p*E,y:I*E},-1,C)}}const c=r(n[n.length-2],n[n.length-1]),l=n[n.length-1].trace_width??e;return s(n[n.length-1],c,1,l),s(n[n.length-1],c,-1,l),[...o,...i]}var AUo=(t,e)=>{const{x:n,y:o,width:i,height:r,layer:s,rect_border_radius:a}=t,A=t.corner_radius??a??0,c=[{_pcb_drawing_object_id:UB("rect"),pcb_drawing_type:"rect",x:n,y:o,w:i,h:r,layer:s||"top",_element:t,_parent_pcb_component:e._parent_pcb_component,_parent_source_component:e._parent_source_component,_source_port:e._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 l=s==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",u={...{_pcb_drawing_object_id:UB("rect"),pcb_drawing_type:"rect",x:n,y:o,w:i,h:r,layer:l,_element:t,_parent_pcb_component:e._parent_pcb_component,_parent_source_component:e._parent_source_component,_source_port:e._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}:{}};c.push(u)}return c},cUo=(t,e)=>{const{x:n,y:o,radius:i,layer:r}=t,s=[{_pcb_drawing_object_id:UB("circle"),pcb_drawing_type:"circle",x:n,y:o,r:i,layer:r||"top",_element:t,_parent_pcb_component:e._parent_pcb_component,_parent_source_component:e._parent_source_component,_source_port:e._source_port}];if(t.is_covered_with_solder_mask){const a=r==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",A={_pcb_drawing_object_id:UB("circle"),pcb_drawing_type:"circle",x:n,y:o,r:i,layer:a,_element:t,_parent_pcb_component:e._parent_pcb_component,_parent_source_component:e._parent_source_component,_source_port:e._source_port,..."solder_mask_color"in t&&t.solder_mask_color?{color:t.solder_mask_color}:{}};s.push(A)}return s},lUo=(t,e)=>{const{layer:n,points:o}=t,i=[{_pcb_drawing_object_id:UB("polygon"),pcb_drawing_type:"polygon",points:r9e(o),layer:n||"top",_element:t,_parent_pcb_component:e._parent_pcb_component,_parent_source_component:e._parent_source_component,_source_port:e._source_port}];if(t.is_covered_with_solder_mask){const r=n==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",s={_pcb_drawing_object_id:UB("polygon"),pcb_drawing_type:"polygon",points:r9e(o),layer:r,_element:t,_parent_pcb_component:e._parent_pcb_component,_parent_source_component:e._parent_source_component,_source_port:e._source_port,..."solder_mask_color"in t&&t.solder_mask_color?{color:t.solder_mask_color}:{}};i.push(s)}return i},gUo=(t,e)=>{const{x:n,y:o,width:i,height:r,layer:s}=t,a=[{_pcb_drawing_object_id:UB("pill"),pcb_drawing_type:"pill",x:n,y:o,w:i,h:r,layer:s||"top",_element:t,_parent_pcb_component:e._parent_pcb_component,_parent_source_component:e._parent_source_component,_source_port:e._source_port}];if(t.is_covered_with_solder_mask){const A=s==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",c={_pcb_drawing_object_id:UB("pill"),pcb_drawing_type:"pill",x:n,y:o,w:i,h:r,layer:A,_element:t,_parent_pcb_component:e._parent_pcb_component,_parent_source_component:e._parent_source_component,_source_port:e._source_port,..."solder_mask_color"in t&&t.solder_mask_color?{color:t.solder_mask_color}:{}};a.push(c)}return a},uUo=(t,e)=>{const{x:n,y:o,width:i,height:r,layer:s,ccw_rotation:a}=t,A=[{_pcb_drawing_object_id:UB("pill"),pcb_drawing_type:"pill",x:n,y:o,w:i,h:r,layer:s||"top",_element:t,_parent_pcb_component:e._parent_pcb_component,_parent_source_component:e._parent_source_component,_source_port:e._source_port,ccw_rotation:a}];if(t.is_covered_with_solder_mask){const c=s==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",l={_pcb_drawing_object_id:UB("pill"),pcb_drawing_type:"pill",x:n,y:o,w:i,h:r,layer:c,_element:t,_parent_pcb_component:e._parent_pcb_component,_parent_source_component:e._parent_source_component,_source_port:e._source_port,ccw_rotation:a,..."solder_mask_color"in t&&t.solder_mask_color?{color:t.solder_mask_color}:{}};A.push(l)}return A},r0=0,UB=t=>`${t}_${r0++}`,r9e=t=>(t??[]).map(e=>({x:En.parse(e.x),y:En.parse(e.y)})),dUo=(t,e)=>{const n="pcb_component_id"in t?e.find(s=>s.type==="pcb_component"&&s.pcb_component_id===t.pcb_component_id):void 0,o=n&&"source_component_id"in n?e.find(s=>s.type==="source_component"&&s.source_component_id===n.source_component_id):void 0,i="source_port_id"in t?t.source_port_id:"pcb_port_id"in t?N6(e).pcb_port.get(t.pcb_port_id)?.source_port_id:void 0,r=i?e.find(s=>s.type==="source_port"&&s.source_port_id===i):void 0;switch(t.type){case"pcb_smtpad":{const s={_parent_pcb_component:n,_parent_source_component:o,_source_port:r};return t.shape==="rect"||t.shape==="rotated_rect"?AUo(t,s):t.shape==="circle"?cUo(t,s):t.shape==="polygon"?lUo(t,s):t.shape==="pill"?gUo(t,s):t.shape==="rotated_pill"?uUo(t,s):[]}case"pcb_trace":{const s=[];if(t.route_thickness_mode==="interpolated"){const c=t.route.flatMap(u=>u.route_type==="through_pad"?[{...u.start,trace_width:u.width},{...u.end,trace_width:u.width}]:[{x:u.x,y:u.y,trace_width:u.route_type==="wire"?u.width:.5}]),l=aUo(c,.5),g=t.route[0].layer;return s.push({_pcb_drawing_object_id:`polygon_${r0++}`,_element:t,pcb_drawing_type:"polygon",points:l,layer:g}),t.route.forEach(u=>{u.route_type==="via"&&s.push({_pcb_drawing_object_id:`circle_${r0++}`,_element:t,pcb_drawing_type:"circle",x:u.x,y:u.y,r:u.outer_diameter/2,layer:u.from_layer})}),s}let a=null,A=null;for(const c of t.route)c.route_type==="wire"&&(a!==null&&A!==null&&s.push({_pcb_drawing_object_id:`line_${r0++}`,_element:t,pcb_drawing_type:"line",x1:a,y1:A,x2:c.x,y2:c.y,width:c.width,squareCap:!1,layer:c.layer}),a=c.x,A=c.y);return s}case"pcb_via":{const{x:s,y:a,outer_diameter:A,hole_diameter:c}=t,l=t.from_layer,g=t.to_layer,u=t.layers,h=[];l&&g?h.push(l,g):u&&Array.isArray(u)?h.push(...u):h.push("top","bottom");const d=[];for(const _ of h)d.push({_pcb_drawing_object_id:`circle_${r0++}`,pcb_drawing_type:"circle",x:s,y:a,r:A/2,layer:_,_element:t,_parent_pcb_component:n,_parent_source_component:o});return d.push({_pcb_drawing_object_id:`circle_${r0++}`,pcb_drawing_type:"circle",x:s,y:a,r:c/2,layer:"drill",_element:t}),d}case"pcb_plated_hole":if(t.shape==="circle"){const{x:s,y:a,hole_diameter:A,outer_diameter:c}=t;return[{_pcb_drawing_object_id:`circle_${r0++}`,pcb_drawing_type:"circle",x:s,y:a,r:c/2,layer:"top",_element:t,_parent_pcb_component:n,_parent_source_component:o,_source_port:r},{_pcb_drawing_object_id:`circle_${r0++}`,pcb_drawing_type:"circle",x:s,y:a,r:A/2,layer:"drill",_element:t}]}else if(t.shape==="oval"){const{x:s,y:a,outer_height:A,outer_width:c,hole_height:l,hole_width:g}=t;return[{_pcb_drawing_object_id:`oval_${r0++}`,pcb_drawing_type:"oval",x:s,y:a,rX:c/2,rY:A/2,layer:"top",_element:t,_parent_pcb_component:n,_parent_source_component:o,_source_port:r},{_pcb_drawing_object_id:`oval_${r0++}`,_element:t,pcb_drawing_type:"oval",x:s,y:a,rX:g/2,rY:l/2,layer:"drill"}]}else if(t.shape==="pill"){const{x:s,y:a,outer_height:A,outer_width:c,hole_height:l,hole_width:g}=t;return[{_pcb_drawing_object_id:`pill_${r0++}`,pcb_drawing_type:"pill",x:s,y:a,w:c,h:A,layer:"top",_element:t,_parent_pcb_component:n,_parent_source_component:o,_source_port:r,ccw_rotation:t.ccw_rotation},{_pcb_drawing_object_id:`pill_${r0++}`,_element:t,pcb_drawing_type:"pill",x:s,y:a,w:g,h:l,layer:"drill",ccw_rotation:t.ccw_rotation}]}else if(t.shape==="circular_hole_with_rect_pad"){const{x:s,y:a,hole_diameter:A,rect_pad_width:c,rect_pad_height:l,rect_border_radius:g,hole_offset_x:u,hole_offset_y:h}=t,d=En.parse(u??0),_=En.parse(h??0);return[{_pcb_drawing_object_id:`rect_${r0++}`,pcb_drawing_type:"rect",x:s,y:a,w:c,h:l,layer:"top",_element:t,_parent_pcb_component:n,_parent_source_component:o,_source_port:r,roundness:g},{_pcb_drawing_object_id:`rect_${r0++}`,pcb_drawing_type:"rect",x:s,y:a,w:c,h:l,layer:"bottom",_element:t,_parent_pcb_component:n,_parent_source_component:o,_source_port:r,roundness:g,is_hoverable:!1},{_pcb_drawing_object_id:`circle_${r0++}`,_element:t,pcb_drawing_type:"circle",x:s+d,y:a+_,r:A/2,layer:"drill",is_hoverable:!1}]}else if(t.shape==="pill_hole_with_rect_pad"){const{x:s,y:a,hole_width:A,hole_height:c,rect_pad_width:l,rect_pad_height:g,rect_border_radius:u}=t;return[{_pcb_drawing_object_id:`rect_${r0++}`,pcb_drawing_type:"rect",x:s,y:a,w:l,h:g,layer:"top",_element:t,_parent_pcb_component:n,_parent_source_component:o,_source_port:r,roundness:u},{_pcb_drawing_object_id:`rect_${r0++}`,pcb_drawing_type:"rect",x:s,y:a,w:l,h:g,layer:"bottom",_element:t,_parent_pcb_component:n,_parent_source_component:o,_source_port:r,roundness:u,is_hoverable:!1},{_pcb_drawing_object_id:`pill_${r0++}`,_element:t,pcb_drawing_type:"pill",x:s,y:a,w:A,h:c,layer:"drill",is_hoverable:!1}]}else if(t.shape==="rotated_pill_hole_with_rect_pad"){const{x:s,y:a,hole_width:A,hole_height:c,hole_ccw_rotation:l,rect_pad_width:g,rect_pad_height:u,rect_ccw_rotation:h,rect_border_radius:d}=t;return[{_pcb_drawing_object_id:`rect_${r0++}`,pcb_drawing_type:"rect",x:s,y:a,w:g,h:u,layer:"top",_element:t,_parent_pcb_component:n,_parent_source_component:o,_source_port:r,ccw_rotation:h,roundness:d},{_pcb_drawing_object_id:`rect_${r0++}`,pcb_drawing_type:"rect",x:s,y:a,w:g,h:u,layer:"bottom",_element:t,_parent_pcb_component:n,_parent_source_component:o,_source_port:r,ccw_rotation:h,roundness:d,is_hoverable:!1},{_pcb_drawing_object_id:`pill_${r0++}`,_element:t,pcb_drawing_type:"pill",x:s,y:a,w:A,h:c,layer:"drill",ccw_rotation:l,is_hoverable:!1}]}else if(t.shape==="hole_with_polygon_pad"){const{x:s,y:a,pad_outline:A,hole_shape:c,hole_diameter:l,hole_width:g,hole_height:u,layers:h,hole_offset_x:d,hole_offset_y:_}=t,m=En.parse(d??0),p=En.parse(_??0),I=A,f=[];if(I&&Array.isArray(I)){const E=r9e(I).map(B=>({x:B.x+s,y:B.y+a}));for(const B of h||["top","bottom"])f.push({_pcb_drawing_object_id:`polygon_${r0++}`,pcb_drawing_type:"polygon",points:E,layer:B,_element:t,_parent_pcb_component:n,_parent_source_component:o,_source_port:r})}const C={x:s+m,y:a+p},y=[];return c==="circle"?y.push({_pcb_drawing_object_id:`circle_${r0++}`,pcb_drawing_type:"circle",x:C.x,y:C.y,r:(l??0)/2,layer:"drill",_element:t,_parent_pcb_component:n,_parent_source_component:o}):c==="oval"?y.push({_pcb_drawing_object_id:`oval_${r0++}`,pcb_drawing_type:"oval",x:C.x,y:C.y,rX:(g??0)/2,rY:(u??0)/2,layer:"drill",_element:t,_parent_pcb_component:n,_parent_source_component:o}):(c==="pill"||c==="rotated_pill")&&y.push({_pcb_drawing_object_id:`pill_${r0++}`,pcb_drawing_type:"pill",x:C.x,y:C.y,w:g??0,h:u??0,layer:"drill",_element:t,_parent_pcb_component:n,_parent_source_component:o,ccw_rotation:t.ccw_rotation}),[...f,...y]}else return[]}return[]};function hUo({primitivesWithoutInteractionMetadata:t,drawingObjectIdsWithMouseOver:e,primitiveIdsInMousedOverNet:n}){const o=[];for(const i of t){const r={...i},s=i._element,a=i._parent_pcb_component;i?.layer==="drill"?(r.is_in_highlighted_net=!1,r.is_mouse_over=!1):e.has(i._pcb_drawing_object_id)?r.is_mouse_over=!0:s&&("pcb_trace_id"in s&&n.includes(s.pcb_trace_id)||"pcb_port_id"in s&&n.includes(s.pcb_port_id)||"pcb_via_id"in s&&n.includes(s.pcb_via_id)||"pcb_component_id"in s&&n.includes(s.pcb_component_id)||a&&"pcb_component_id"in a&&n.includes(a.pcb_component_id))?r.is_in_highlighted_net=!0:(r.is_in_highlighted_net=!1,r.is_mouse_over=!1),o.push(r)}return o}var hLt=t=>{const e=new Map,n=new Map,o=new Map,i=new Map,r=new Map;for(const s of t)s.type==="pcb_trace"&&s.pcb_trace_id?e.set(s.pcb_trace_id,s):s.type==="pcb_port"&&s.pcb_port_id?n.set(s.pcb_port_id,s):s.type==="pcb_via"&&s.pcb_via_id?o.set(s.pcb_via_id,s):s.type==="pcb_component"&&s.pcb_component_id?i.set(s.pcb_component_id,s):s.type==="pcb_board"&&s.pcb_board_id&&r.set(s.pcb_board_id,s);return{tracesById:e,portsById:n,viasById:o,componentsById:i,boardsById:r}},Qx=(t,e)=>e?t?{minX:Math.min(t.minX,e.minX),maxX:Math.max(t.maxX,e.maxX),minY:Math.min(t.minY,e.minY),maxY:Math.max(t.maxY,e.maxY)}:e:t,R6=(t,e=.45)=>({minX:t.x-e,maxX:t.x+e,minY:t.y-e,maxY:t.y+e}),_Uo=t=>{if(t.length===0)return null;let e=null;for(const n of t){const o=Math.max((n.width??.2)/2,.3);e=Qx(e,R6(n,o))}return e},_Lt=t=>{if(!t?.center)return null;const e=Math.max(t.width??0,1.2),n=Math.max(t.height??0,1.2);return{minX:t.center.x-e/2,maxX:t.center.x+e/2,minY:t.center.y-n/2,maxY:t.center.y+n/2}},mUo=t=>!t?.center||typeof t.width!="number"||typeof t.height!="number"?null:{minX:t.center.x-t.width/2,maxX:t.center.x+t.width/2,minY:t.center.y-t.height/2,maxY:t.center.y+t.height/2},pUo=(t,e)=>({minX:t.minX-e,maxX:t.maxX+e,minY:t.minY-e,maxY:t.maxY+e}),IUo=(t,e=.35)=>{const n=mp(t);return n?pUo(n,e):null},mLt=({error:t,tracesById:e,portsById:n,viasById:o,componentsById:i})=>{if(t.center)return t.center;if(t.pcb_center)return t.pcb_center;if(t.component_center)return t.component_center;if(t.pcb_via_ids?.length){const r=t.pcb_via_ids.map(s=>o.get(s)).filter(Boolean);if(r.length>0)return{x:r.reduce((s,a)=>s+a.x,0)/r.length,y:r.reduce((s,a)=>s+a.y,0)/r.length}}if(t.pcb_port_ids?.length){const r=t.pcb_port_ids.map(s=>n.get(s)).filter(Boolean);if(r.length>0)return{x:r.reduce((s,a)=>s+a.x,0)/r.length,y:r.reduce((s,a)=>s+a.y,0)/r.length}}if(t.pcb_trace_id){const r=e.get(t.pcb_trace_id);if(r?.route?.length){const s=Math.floor(r.route.length/2);return{x:r.route[s].x,y:r.route[s].y}}}return t.pcb_component_id?i.get(t.pcb_component_id)?.center??null:null},fUo=({error:t,indexes:e})=>mLt({error:t,...e}),CUo=({error:t,boardsById:e})=>{if(!t.component_bounds||!t.pcb_board_id)return null;const n=mUo(e.get(t.pcb_board_id));if(!n)return null;const o=t.component_bounds,i=[];return o.min_x<n.minX&&(i.push({x:n.minX,y:Math.max(o.min_y,n.minY)}),i.push({x:n.minX,y:Math.min(o.max_y,n.maxY)})),o.max_x>n.maxX&&(i.push({x:n.maxX,y:Math.max(o.min_y,n.minY)}),i.push({x:n.maxX,y:Math.min(o.max_y,n.maxY)})),o.min_y<n.minY&&(i.push({x:Math.max(o.min_x,n.minX),y:n.minY}),i.push({x:Math.min(o.max_x,n.maxX),y:n.minY})),o.max_y>n.maxY&&(i.push({x:Math.max(o.min_x,n.minX),y:n.maxY}),i.push({x:Math.min(o.max_x,n.maxX),y:n.maxY})),IUo(i,.3)},pLt=new Set(["source_failed_to_create_component_error"]),yUo=({error:t,indexes:e})=>{if(pLt.has(t.error_type)||pLt.has(t.type))return null;let n=null;const o=mLt({error:t,...e});if(o&&(n=Qx(n,R6(o,.35))),t.error_type==="pcb_component_outside_board_error"?n=Qx(n,CUo({error:t,boardsById:e.boardsById})):t.component_bounds&&!o&&(n=Qx(n,{minX:t.component_bounds.min_x,maxX:t.component_bounds.max_x,minY:t.component_bounds.min_y,maxY:t.component_bounds.max_y})),t.center&&!o&&(n=Qx(n,R6(t.center))),t.pcb_center&&!o&&(n=Qx(n,R6(t.pcb_center))),t.component_center&&!o&&(n=Qx(n,R6(t.component_center))),t.pcb_port_ids&&!o)for(const i of t.pcb_port_ids){const r=e.portsById.get(i);r&&(n=Qx(n,R6({x:r.x,y:r.y},.4)))}if(t.pcb_trace_id&&!o){const i=e.tracesById.get(t.pcb_trace_id);i?.route&&(n=Qx(n,_Uo(i.route)))}if(t.pcb_via_ids)for(const i of t.pcb_via_ids){const r=e.viasById.get(i);r&&(n=Qx(n,R6({x:r.x,y:r.y},Math.max((r.outer_diameter??.5)/2,.28))))}if(t.pcb_component_id&&!o&&(n=Qx(n,_Lt(e.componentsById.get(t.pcb_component_id)))),t.pcb_component_ids&&!o)for(const i of t.pcb_component_ids)n=Qx(n,_Lt(e.componentsById.get(i)));return n},EUo=({bounds:t,width:e,height:n})=>{const o={x:(t.minX+t.maxX)/2,y:(t.minY+t.maxY)/2},i=Math.max(t.maxX-t.minX,.8)+1.4,r=Math.max(t.maxY-t.minY,.8)+1.4,s=Math.min(e/i,n/r,240)*.92;return ki(Wi(e/2,n/2),ug(s,-s,0,0),Wi(-o.x,-o.y))},xUo=t=>{const e=new Set;t.pcb_trace_id&&e.add(t.pcb_trace_id);for(const n of t.pcb_port_ids??[])e.add(n);for(const n of t.pcb_via_ids??[])e.add(n);t.pcb_component_id&&e.add(t.pcb_component_id);for(const n of t.pcb_component_ids??[])e.add(n);return[...e]},Bk=(t,e)=>{const n=["pcb_trace_error_id","pcb_via_clearance_error_id","pcb_component_outside_board_error_id","source_failed_to_create_component_error_id","pcb_error_id"];for(const o of n)if(typeof t?.[o]=="string"&&t[o].length>0)return t[o];for(const[o,i]of Object.entries(t??{}))if(o.endsWith("_error_id")&&typeof i=="string"&&i.length>0)return i;return`error_${e}_${t?.error_type}_${t?.message?.slice(0,20)}`},ILt=(t,e)=>e?t.find((n,o)=>n.type?.includes("error")?Bk(n,o)===e:!1)??null:null,BUo=t=>1-(1-t)**3,QUo=(t,e,n)=>({a:t.a+(e.a-t.a)*n,b:t.b+(e.b-t.b)*n,c:t.c+(e.c-t.c)*n,d:t.d+(e.d-t.d)*n,e:t.e+(e.e-t.e)*n,f:t.f+(e.f-t.f)*n}),fLt=t=>{t!==null&&window.cancelAnimationFrame(t)},SUo=({startTransform:t,endTransform:e,durationMs:n,onUpdate:o,setAnimationFrameId:i,onComplete:r})=>{const s=performance.now(),a=c=>{const l=c-s,g=Math.min(1,l/n),u=BUo(g);if(o(QUo(t,e,u)),g<1){i(window.requestAnimationFrame(a));return}i(null),r?.()},A=window.requestAnimationFrame(a);return i(A),A},Fo={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)"}},My=(t,e=1)=>{if(Math.abs(t.a)!==Math.abs(t.d))throw new Error("Cannot scale non-uniformly");return e*Math.abs(t.a)},Yg={elementOverlay:40,dimensionOverlay:40,errorOverlay:40,pcbGroupOverlay:35,ratsNestOverlay:30,toolbarOverlay:70,warnings:30,topLayer:30,clickToInteractOverlay:100},vse={red:"red",black:"black",green:"green",board:"rgb(255, 255, 255)",other:"#eee",top:Fo.board.copper.f,inner1:Fo.board.copper.in1,inner2:Fo.board.copper.in2,inner3:Fo.board.copper.in3,inner4:Fo.board.copper.in4,inner5:Fo.board.copper.in5,inner6:Fo.board.copper.in6,inner7:Fo.board.copper.in7,inner8:Fo.board.copper.in8,bottom:Fo.board.copper.b,drill:Fo.board.anchor,keepout:Fo.board.background,tkeepout:Fo.board.b_crtyd,tplace:Fo.board.b_silks,top_courtyard:Fo.board.f_crtyd,bottom_courtyard:Fo.board.b_crtyd,top_silkscreen:Fo.board.f_silks,bottom_silkscreen:Fo.board.b_silks,top_fabrication:Fo.board.f_fab,bottom_fabrication:Fo.board.b_fab,soldermask_top:Fo.board.soldermask.top,soldermask_bottom:Fo.board.soldermask.bottom,soldermask_with_copper_top:Fo.board.soldermaskWithCopper.top,soldermask_with_copper_bottom:Fo.board.soldermaskWithCopper.bottom,bottom_notes:Fo.board.user_2,top_notes:Fo.board.user_2,...Fo.board},bUo=["board","bottom","soldermask_bottom","bottom_silkscreen","top","soldermask_top","bottom_courtyard","bottom_fabrication","top_courtyard","top_fabrication","edge_cuts","top_silkscreen"],DUo=class{canvasLayerMap;ctxLayerMap;aperture;transform;foregroundLayer="top";lastPoint;constructor(t){this.canvasLayerMap=t,this.ctxLayerMap=Object.fromEntries(Object.entries(t).map(([e,n])=>[e,n.getContext("2d")])),this.transform=Ll(),this.transform.d*=-1,this.transform=ki(this.transform,Wi(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,e,n,o,i,r=45){const s=this.getLayerCtx(),[a,A]=mt(this.transform,[t,e]),[c,l]=mt(this.transform,[t+n,e+o]),g=My(this.transform,i);s.lineWidth=1,s.strokeStyle=this.aperture.color;const u=h=>{const d=Math.sin(h),_=Math.cos(h),m=Math.sqrt((c-a)**2+(l-A)**2);for(let p=-m;p<=m;p+=g)s.beginPath(),s.moveTo(a+p*_-m*d,A+p*d+m*_),s.lineTo(a+p*_+m*d,A+p*d-m*_),s.stroke()};u(r*Math.PI/180),u((r+90)*Math.PI/180)}rect({x:t,y:e,w:n,h:o,mesh_fill:i,is_filled:r=!0,has_stroke:s,is_stroke_dashed:a,stroke_width:A,roundness:c}){const[l,g]=mt(this.transform,[t-n/2,e-o/2]),[u,h]=mt(this.transform,[t+n/2,e+o/2]);this.applyAperture();const d=this.getLayerCtx(),_=c?My(this.transform,c):0,m=s===void 0?r===!1:s;if(i)d.save(),d.beginPath(),_>0&&d.roundRect?d.roundRect(l,g,u-l,h-g,_):d.rect(l,g,u-l,h-g),d.clip(),this.drawMeshPattern(t-n/2,e-o/2,n,o,.15),d.restore(),_>0&&d.roundRect?(d.beginPath(),d.roundRect(l,g,u-l,h-g,_),d.stroke()):d.strokeRect(l,g,u-l,h-g);else if(r!==!1&&(_>0&&d.roundRect?(d.beginPath(),d.roundRect(l,g,u-l,h-g,_),d.fill()):d.fillRect(l,g,u-l,h-g)),m){const p=d.lineWidth;if(A!==void 0&&(d.lineWidth=My(this.transform,A)),a){let I=[];const f=Math.abs(this.transform.a);if(f>0){const y=.1*f,E=y*1.3;y>.5&&(I=[y,E])}d.setLineDash(I)}_>0&&d.roundRect?(d.beginPath(),d.roundRect(l,g,u-l,h-g,_),d.stroke()):d.strokeRect(l,g,u-l,h-g),a&&d.setLineDash([]),A!==void 0&&(d.lineWidth=p)}}rotatedRect(t,e,n,o,i,r,s){const a=this.getLayerCtx();this.applyAperture();const[A,c]=mt(this.transform,[t-n/2,e-o/2]),[l,g]=mt(this.transform,[t+n/2,e+o/2]),u=r?My(this.transform,r):0;a.save();const[h,d]=mt(this.transform,[t,e]);a.translate(h,d);const _=360-i;i&&a.rotate(_*Math.PI/180),a.translate(-h,-d),s?(a.beginPath(),u>0&&a.roundRect?a.roundRect(A,c,l-A,g-c,u):a.rect(A,c,l-A,g-c),a.clip(),this.drawMeshPattern(t-n/2,e-o/2,n,o,.15),u>0&&a.roundRect?(a.beginPath(),a.roundRect(A,c,l-A,g-c,u),a.stroke()):a.strokeRect(A,c,l-A,g-c)):u>0&&a.roundRect?(a.beginPath(),a.roundRect(A,c,l-A,g-c,u),a.fill()):a.fillRect(A,c,l-A,g-c),a.restore()}rotatedPill(t,e,n,o,i){const r=this.getLayerCtx();this.applyAperture(),r.save();const[s,a]=mt(this.transform,[t,e]);r.translate(s,a);const A=360-i;i&&r.rotate(A*Math.PI/180),r.translate(-s,-a),this.pill(t,e,n,o),r.restore()}circle(t,e,n,o,i=!0){const r=My(this.transform,n),[s,a]=mt(this.transform,[t,e]);this.applyAperture();const A=this.getLayerCtx();o?(A.save(),A.beginPath(),A.arc(s,a,r,0,2*Math.PI),A.clip(),this.drawMeshPattern(t-n,e-n,n*2,n*2,.15),A.restore(),A.beginPath(),A.arc(s,a,r,0,2*Math.PI),A.stroke()):(A.beginPath(),A.arc(s,a,r,0,2*Math.PI),A.fill())}oval(t,e,n,o){const i=My(this.transform,n),r=My(this.transform,o),[s,a]=mt(this.transform,[t,e]);this.applyAperture();const A=this.getLayerCtx();A.beginPath(),A.ellipse(s,a,i,r,0,0,2*Math.PI),A.fill(),A.closePath()}pill(t,e,n,o){const[i,r]=mt(this.transform,[t-n/2,e+o/2]),s=My(this.transform,n),a=My(this.transform,o),A=Math.min(s,a)/2;this.applyAperture();const c=this.getLayerCtx();c.beginPath(),c.arc(i+A,r+A,A,Math.PI,Math.PI*1.5),c.arc(i+s-A,r+A,A,Math.PI*1.5,0),c.arc(i+s-A,r+a-A,A,0,Math.PI*.5),c.arc(i+A,r+a-A,A,Math.PI*.5,Math.PI),c.fill(),c.closePath()}polygon(t){if(t.length<3)return;this.applyAperture();const e=this.getLayerCtx(),n=t.map(i=>mt(this.transform,[i.x,i.y]));e.beginPath(),e.moveTo(n[0][0],n[0][1]);for(let i=1;i<n.length;i++)e.lineTo(n[i][0],n[i][1]);e.closePath(),e.fill("evenodd");const o=My(this.transform,this.aperture.size);o>0&&(e.lineWidth=o,e.stroke())}debugText(t,e,n){const[o,i]=mt(this.transform,[e,n]);this.applyAperture();const r=this.getLayerCtx();r.font="10px sans-serif",r.fillText(t,o,i)}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:e}=this,o=["board",...Object.keys(t).filter(u=>/^inner\d+$/.test(u)).sort((u,h)=>Number(h.slice(5))-Number(u.slice(5))),...bUo.filter(u=>u!=="board")],i=e==="top"?"soldermask_top":e==="bottom"?"soldermask_bottom":void 0,r=e==="top"?"top_silkscreen":e==="bottom"?"bottom_silkscreen":void 0,s=e==="top"?"top_notes":e==="bottom"?"bottom_notes":void 0,a=e==="top"?"top_fabrication":e==="bottom"?"bottom_fabrication":void 0,A=e==="top"?"top_courtyard":e==="bottom"?"bottom_courtyard":void 0,c=new Set([e,"drill","edge_cuts","other","board",...i?[i]:[],...r?[r]:[],...s?[s]:[],...a?[a]:[],...A?[A]:[]]),l=[e,"edge_cuts",...i?[i]:[],...r?[r]:[],...s?[s]:[],...a?[a]:[],...A?[A]:[]],g=[...o.filter(u=>!l.includes(u)),...e==="drill"?[]:[e],...i?[i]:[],"edge_cuts",...r?[r]:[],...s?[s]:[],...a?[a]:[],...A?[A]:[],"drill"];g.forEach((u,h)=>{const d=t[u];d&&(d.style.zIndex=`${Yg.topLayer-(g.length-h)}`,d.style.opacity=c.has(u)?"1":"0.5")})}applyAperture(){const{transform:t,aperture:e}=this;let{size:n,mode:o,color:i,fontSize:r,layer:s}=e;s in this.ctxLayerMap||(this.aperture.layer="other");const a=this.getLayerCtx();if(!a)throw new Error(`No context for layer "${this.foregroundLayer}"`);if(i||(i="undefined"),a.lineWidth=My(t,n),a.lineCap="round",o==="add"){a.globalCompositeOperation="source-over";let A=vse[i.toLowerCase()];if(!A)try{A=Kr(i).rgb().toString()}catch{console.warn(`Invalid color format: '${i}'`),A="white"}a.fillStyle=A,a.strokeStyle=A}else a.globalCompositeOperation="destination-out",a.fillStyle="rgba(0,0,0,1)",a.strokeStyle="rgba(0,0,0,1)";a.font=`${My(QQ(t),r)}px sans-serif`}moveTo(t,e){this.lastPoint={x:t,y:e}}lineTo(t,e){const[n,o]=mt(this.transform,[t,e]),{size:i,shape:r,mode:s}=this.aperture,a=My(this.transform,i),{lastPoint:A}=this,c=mt(this.transform,A);this.applyAperture();const l=this.getLayerCtx();r==="square"&&l.fillRect(c.x-a/2,c.y-a/2,a,a),l.beginPath(),l.moveTo(c.x,c.y),l.lineTo(n,o),l.stroke(),l.closePath(),r==="square"&&l.fillRect(n-a/2,o-a/2,a,a),this.lastPoint={x:t,y:e}}polygonWithArcs(t){const e=this.getLayerCtx(),n=o=>{if(o.vertices.length===0)return;const i=o.vertices[0],r=mt(this.transform,[i.x,i.y]);e.moveTo(r[0],r[1]);for(let s=0;s<o.vertices.length;s++){const a=o.vertices[s],A=o.vertices[(s+1)%o.vertices.length];if(a.bulge&&a.bulge!==0){const c=a.bulge,l=A.x-a.x,g=A.y-a.y,u=Math.sqrt(l*l+g*g);if(u<1e-9){const w=mt(this.transform,[A.x,A.y]);e.lineTo(w[0],w[1]);continue}const h=4*Math.atan(c),d=Math.abs(u/(2*Math.sin(h/2))),_=(a.x+A.x)/2,m=(a.y+A.y)/2,p=l/u,f=-(g/u),C=p,y=Math.sqrt(Math.max(0,d*d-(u/2)**2)),E=_+y*f*Math.sign(c),B=m+y*C*Math.sign(c),Q=Math.atan2(a.y-B,a.x-E);let b=Math.atan2(A.y-B,A.x-E);c>0&&b<Q?b+=2*Math.PI:c<0&&b>Q&&(b-=2*Math.PI);const D=mt(this.transform,[E,B]),R=My(this.transform,d);e.arc(D[0],D[1],R,-Q,-b,c>0)}else{const c=mt(this.transform,[A.x,A.y]);e.lineTo(c[0],c[1])}}e.closePath()};if(e.beginPath(),n(t.outer_ring),t.inner_rings)for(const o of t.inner_rings)n(o);e.fill("evenodd")}},PUo=(t=2)=>{const e=Math.max(2,Math.min(10,Math.floor(t)));return["top",...Array.from({length:e-2},(n,o)=>`inner${o+1}`),"bottom"]},s9e=t=>{const e=t.find(n=>n.type==="pcb_board");return PUo(e?.num_layers??2)},vUo=t=>`${t}_copper`,CLt=t=>t.map(e=>e.endsWith("_copper")?e.slice(0,-7):e),MUo=t=>["board","bottom","soldermask_bottom","bottom_silkscreen","top","soldermask_top","soldermask_with_copper_bottom","soldermask_with_copper_top","top_fabrication","bottom_fabrication",...s9e(t).filter(n=>n.startsWith("inner")),"drill","edge_cuts","bottom_notes","top_notes","top_silkscreen","top_courtyard","bottom_courtyard","other"];function wUo(t){return t.type==="pcb_copper_pour"}function NUo({canvas:t,elements:e,layers:n,realToCanvasMat:o}){const i=e.filter(wUo);if(i.length===0)return;const r=new Pc(t);r.realToCanvasMat=o,r.drawElements(i,{layers:n})}var RUo={...jC,courtyard:{top:Fo.board.f_crtyd,bottom:Fo.board.b_crtyd}};function TUo(t){return t.type==="pcb_courtyard_circle"||t.type==="pcb_courtyard_rect"||t.type==="pcb_courtyard_outline"}function yLt({canvas:t,elements:e,layers:n,realToCanvasMat:o}){const i=new Pc(t);i.configure({colorOverrides:RUo}),i.realToCanvasMat=o;const r=e.filter(TUo);i.drawElements(r,{layers:n})}var kUo={...jC,silkscreen:{top:Fo.board.f_fab,bottom:Fo.board.b_fab}};function FUo(t){return t.type.includes("pcb_fabrication_note")}function ELt({canvas:t,elements:e,layers:n,realToCanvasMat:o}){const i=new Pc(t);i.configure({colorOverrides:kUo}),i.realToCanvasMat=o;const r=e.filter(FUo);i.drawElements(r,{layers:n})}function LUo(t){return t.type==="pcb_hole"}function HUo({canvas:t,elements:e,layers:n,realToCanvasMat:o,drawSoldermask:i}){const r=new Pc(t);r.realToCanvasMat=o;const s=e.filter(LUo);r.drawElements(s,{layers:n,drawSoldermask:i})}function GUo(t){return t.type==="pcb_board"}function OUo({canvas:t,elements:e,layers:n,realToCanvasMat:o,drawSoldermask:i}){const r=new Pc(t);r.realToCanvasMat=o;const s=e.filter(GUo);for(const a of s)r.drawElements([a],{layers:n,drawSoldermask:!1,drawBoardMaterial:i??!1,minBoardOutlineStrokePx:2})}function KUo(t){return t.type==="pcb_copper_text"}function UUo({canvas:t,elements:e,layers:n,realToCanvasMat:o}){const i=e.filter(KUo);if(i.length===0)return;const r=new Pc(t);r.realToCanvasMat=o,r.drawElements(i,{layers:n})}function YUo(t){return t.type==="pcb_cutout"}function zUo({canvas:t,elements:e,layers:n,realToCanvasMat:o}){const i=new Pc(t);i.realToCanvasMat=o;const r=e.filter(YUo);i.drawElements(r,{layers:n})}function VUo(t){return t.type==="pcb_keepout"}function JUo({canvas:t,elements:e,layers:n,realToCanvasMat:o}){const i=e.filter(VUo);if(i.length===0)return;const r=new Pc(t);r.realToCanvasMat=o,r.drawElements(i,{layers:[]})}function qUo(t){return t.type.startsWith("pcb_note_")}function xLt({canvas:t,elements:e,layers:n,realToCanvasMat:o}){const i=new Pc(t);i.realToCanvasMat=o;const r=e.filter(qUo);i.drawElements(r,{layers:n})}function WUo(t){return t.type==="pcb_panel"}function jUo({canvas:t,elements:e,layers:n,realToCanvasMat:o,drawSoldermask:i}){const r=new Pc(t);r.realToCanvasMat=o;const s=e.filter(WUo);for(const a of s)r.drawElements([a],{layers:n})}var XUo={...jC,copper:{...jC.copper,top:Kr(Fo.board.pad_front).lighten(.5).toString(),bottom:Kr(Fo.board.pad_back).lighten(.5).toString(),inner1:Kr(Fo.board.copper.in1).lighten(.5).toString(),inner2:Kr(Fo.board.copper.in2).lighten(.5).toString(),inner3:Kr(Fo.board.copper.in3).lighten(.5).toString(),inner4:Kr(Fo.board.copper.in4).lighten(.5).toString(),inner5:Kr(Fo.board.copper.in5).lighten(.5).toString(),inner6:Kr(Fo.board.copper.in6).lighten(.5).toString(),inner7:Kr(Fo.board.copper.in7).lighten(.5).toString(),inner8:Kr(Fo.board.copper.in8).lighten(.5).toString()}};function $Uo(t){return t.type==="pcb_smtpad"}function ZUo({canvas:t,elements:e,layers:n,realToCanvasMat:o,primitives:i,drawSoldermask:r}){const s=new Set(CLt(n)),a=e.filter($Uo).filter(g=>s.has(g.layer));if(a.length===0)return;const A=new Set;if(i)for(const g of i)(g.is_mouse_over||g.is_in_highlighted_net)&&g._element?.type==="pcb_smtpad"&&A.add(g._element.pcb_smtpad_id);const c=a.filter(g=>A.has(g.pcb_smtpad_id)),l=a.filter(g=>!A.has(g.pcb_smtpad_id));if(l.length>0){const g=new Pc(t);g.realToCanvasMat=o,g.drawElements(l,{layers:n,drawSoldermask:r})}if(c.length>0){const g=new Pc(t);g.configure({colorOverrides:XUo}),g.realToCanvasMat=o,g.drawElements(c,{layers:n,drawSoldermask:r})}}var eYo={...jC,copper:{...jC.copper,top:Kr(Fo.board.pad_front).lighten(.5).toString(),bottom:Kr(Fo.board.pad_back).lighten(.5).toString(),inner1:Kr(Fo.board.copper.in1).lighten(.5).toString(),inner2:Kr(Fo.board.copper.in2).lighten(.5).toString(),inner3:Kr(Fo.board.copper.in3).lighten(.5).toString(),inner4:Kr(Fo.board.copper.in4).lighten(.5).toString(),inner5:Kr(Fo.board.copper.in5).lighten(.5).toString(),inner6:Kr(Fo.board.copper.in6).lighten(.5).toString(),inner7:Kr(Fo.board.copper.in7).lighten(.5).toString(),inner8:Kr(Fo.board.copper.in8).lighten(.5).toString()}};function tYo(t){return t.type==="pcb_trace"}var nYo=(t,e)=>{const n=t.route.filter(i=>i.route_type==="wire"&&"layer"in i&&e.has(i.layer)?!0:i.route_type==="via"?e.has(i.from_layer)||e.has(i.to_layer):!1);return n.filter(i=>i.route_type==="wire").length<2?null:{...t,route:n}},oYo=t=>({...t,route:t.route.map(e=>!("is_inside_copper_pour"in e)||e.is_inside_copper_pour!==!0?e:{...e,is_inside_copper_pour:!1})}),iYo=(t,e)=>e?t:[],rYo=({primitives:t})=>{const e=new Set;for(const n of t)(n.is_mouse_over||n.is_in_highlighted_net)&&n._element?.type==="pcb_trace"&&e.add(n._element.pcb_trace_id);return e};function sYo({canvas:t,elements:e,layers:n,realToCanvasMat:o,primitives:i,showCopperPours:r}){const s=new Set(CLt(n)),a=e.filter(tYo).map(u=>nYo(u,s)).filter(u=>u!==null).map(u=>r?u:oYo(u));if(a.length===0)return;const A=rYo({primitives:i??[]}),c=[],l=[];for(const u of a)A.has(u.pcb_trace_id)?c.push(u):l.push(u);const g=iYo(e,r);if(l.length>0){const u=new Pc(t);u.realToCanvasMat=o,u.drawElements(l,{layers:n,clipContextElements:g})}if(c.length>0){const u=new Pc(t);u.configure({colorOverrides:eYo}),u.realToCanvasMat=o,u.drawElements(c,{layers:n,clipContextElements:g})}}var aYo={...jC,copper:{...jC.copper,top:Kr(Fo.board.pad_front).lighten(.5).toString(),bottom:Kr(Fo.board.pad_back).lighten(.5).toString(),inner1:Kr(Fo.board.copper.in1).lighten(.5).toString(),inner2:Kr(Fo.board.copper.in2).lighten(.5).toString(),inner3:Kr(Fo.board.copper.in3).lighten(.5).toString(),inner4:Kr(Fo.board.copper.in4).lighten(.5).toString(),inner5:Kr(Fo.board.copper.in5).lighten(.5).toString(),inner6:Kr(Fo.board.copper.in6).lighten(.5).toString(),inner7:Kr(Fo.board.copper.in7).lighten(.5).toString(),inner8:Kr(Fo.board.copper.in8).lighten(.5).toString()}};function AYo(t){return t.type==="pcb_plated_hole"}function cYo({canvas:t,elements:e,layers:n,realToCanvasMat:o,primitives:i,drawSoldermask:r}){const s=e.filter(AYo);if(s.length===0)return;const a=new Set;if(i)for(const l of i)(l.is_mouse_over||l.is_in_highlighted_net)&&l._element?.type==="pcb_plated_hole"&&a.add(l._element.pcb_plated_hole_id);const A=s.filter(l=>a.has(l.pcb_plated_hole_id)),c=s.filter(l=>!a.has(l.pcb_plated_hole_id));if(c.length>0){const l=new Pc(t);l.realToCanvasMat=o,l.drawElements(c,{layers:n,drawSoldermask:r})}if(A.length>0){const l=new Pc(t);l.configure({colorOverrides:aYo}),l.realToCanvasMat=o,l.drawElements(A,{layers:n,drawSoldermask:r})}}function BLt(t){const{lines:e,anchorPoint:n,ccwRotation:o}=t;if(!o)return e;const i=o*Math.PI/180,r=E_(i),s=ki(Wi(n.x,n.y),r,Wi(-n.x,-n.y));return mt(s,n),e.map(a=>({...a,x1:mt(s,{x:a.x1,y:a.y1}).x,y1:mt(s,{x:a.x1,y:a.y1}).y,x2:mt(s,{x:a.x2,y:a.y2}).x,y2:mt(s,{x:a.x2,y:a.y2}).y}))}var lYo=.6,QLt=.2,SLt=t=>{const e=t.size*.7,n=e*lYo,o=e*QLt,i=e*QLt,r=t.text.split(/\r?\n/),s=t.text.length>0&&e>0,a=s?r.length:0,A=s?r.map(g=>g.length===0?0:g.length*n+(g.length-1)*o):[],c=A.length>0?Math.max(...A):0,l=a>0?a*e+(a-1)*i:0;return{text_lines:r,line_count:a,line_widths:A,target_height:e,target_width_char:n,space_between_chars:o,space_between_lines:i,width:c,height:l}},bLt=t=>{const e=SLt(t);return{width:e.width,height:e.height,lineHeight:e.target_height,lineSpacing:e.space_between_lines,lineCount:e.line_count}},DLt=t=>{const{text_lines:e,line_count:n,line_widths:o,target_height:i,target_width_char:r,space_between_chars:s,space_between_lines:a,width:A}=SLt(t);if(i<=0||n===0)return[];const c=i/12,l=[];for(let g=0;g<n;g++){const u=-g*(i+a),h=o[g],d=(A-h)/2;let _=t.x+d;for(let m=0;m<e[g].length;m++){const p=e[g][m],I=jM[p]??jM[p.toUpperCase()];if(!I){_+=r+s;continue}for(const{x1:f,y1:C,x2:y,y2:E}of I)l.push({_pcb_drawing_object_id:UB("line"),pcb_drawing_type:"line",x1:_+r*f,y1:t.y+u+i*C,x2:_+r*y,y2:t.y+u+i*E,width:c,layer:t.layer,unit:t.unit,color:t.color});_+=r+s}}return l};function ib(t){const n=t.color??vse[t.layer];let o=Kr(n);return t._element?.type==="pcb_copper_pour"&&(o=o.alpha(.7)),t.is_mouse_over||t.is_in_highlighted_net?o.lighten(.5).rgb().toString():o.rgb().toString()}var PLt=(t,e)=>{t.equip({size:e.zoomIndependent?e.width/t.transform.a:e.width,shape:e.squareCap?"square":"circle",color:ib(e),layer:e.layer}),t.moveTo(e.x1,e.y1),t.lineTo(e.x2,e.y2)},gYo=(t,e,n)=>{switch(n){case"top_left":return{x:0,y:-e};case"top_center":return{x:-t/2,y:-e};case"top_right":return{x:-t,y:-e};case"center_left":return{x:0,y:-e/2};case"center":return{x:-t/2,y:-e/2};case"center_right":return{x:-t,y:-e/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}}},vLt=t=>t.layer==="bottom_silkscreen"||t.layer==="bottom"?t.is_mirrored!==!1:t.is_mirrored===!0,uYo=(t,e)=>{t.equip({fontSize:e.size,color:ib(e),layer:e.layer});const{width:n,height:o}=bLt(e),i=gYo(n,o,e.align);e.x??=0,e.y??=0;const r={x:e.x,y:e.y};let s=DLt({...e,x:e.x+i.x,y:e.y+i.y});if(vLt(e)&&(s=s.map(a=>({...a,x1:2*e.x-a.x1,x2:2*e.x-a.x2}))),e.ccw_rotation){const a={lines:s,anchorPoint:r,ccwRotation:e.ccw_rotation};s=BLt(a)}for(const a of s)PLt(t,a)},dYo=(t,e)=>{const{width:n,height:o,lineHeight:i}=bLt(e);e.x??=0,e.y??=0;const r=e.knockout_padding??{left:e.size*.5,right:e.size*.5,top:e.size*.3,bottom:e.size*.3},s=n+r.left+r.right,a=o+r.top+r.bottom,A=n/2,c=i-o/2,l=e.x-A,g=e.y-c,u={x:e.x,y:e.y},h={_pcb_drawing_object_id:`knockout_rect_${e._pcb_drawing_object_id}`,x:e.x,y:e.y,w:s,h:a,layer:e.layer,ccw_rotation:e.ccw_rotation};e.ccw_rotation?wLt(t,h):MLt(t,h);let d=DLt({...e,x:l,y:g});if(vLt(e)&&(d=d.map(_=>({..._,x1:2*e.x-_.x1,x2:2*e.x-_.x2}))),e.ccw_rotation){const _={lines:d,anchorPoint:u,ccwRotation:e.ccw_rotation};d=BLt(_)}for(const _ of d)t.equip({size:_.width,shape:"circle",color:"black",layer:e.layer,mode:"subtract"}),t.moveTo(_.x1,_.y1),t.lineTo(_.x2,_.y2);t.equip({mode:"add"})},MLt=(t,e)=>{t.equip({color:ib(e),layer:e.layer,size:e.stroke_width}),t.rect({x:e.x,y:e.y,w:e.w,h:e.h,mesh_fill:e.mesh_fill,is_filled:e.is_filled,has_stroke:e.has_stroke,is_stroke_dashed:e.is_stroke_dashed,stroke_width:e.stroke_width,roundness:e.roundness})},wLt=(t,e)=>{t.equip({color:ib(e),layer:e.layer}),t.rotatedRect(e.x,e.y,e.w,e.h,e.ccw_rotation,e.roundness,e.mesh_fill)},hYo=(t,e)=>{t.equip({color:ib(e),layer:e.layer}),t.rotatedPill(e.x,e.y,e.w,e.h,e.ccw_rotation)},_Yo=(t,e)=>{t.equip({color:ib(e),layer:e.layer}),t.circle(e.x,e.y,e.r,e.mesh_fill)},mYo=(t,e)=>{t.equip({color:ib(e),layer:e.layer}),t.oval(e.x,e.y,e.rX,e.rY)},pYo=(t,e)=>{t.equip({color:ib(e),layer:e.layer}),t.pill(e.x,e.y,e.w,e.h)},IYo=(t,e)=>{t.equip({color:ib(e),layer:e.layer}),t.polygon(e.points)},fYo=(t,e)=>{t.equip({color:ib(e),layer:e.layer}),t.polygonWithArcs(e.brep_shape)},CYo=(t,e)=>{switch(e.pcb_drawing_type){case"line":return PLt(t,e);case"text":return e.is_knockout?dYo(t,e):uYo(t,e);case"rect":return e.ccw_rotation?wLt(t,e):MLt(t,e);case"circle":return _Yo(t,e);case"oval":return mYo(t,e);case"pill":return e.ccw_rotation?hYo(t,e):pYo(t,e);case"polygon":return IYo(t,e);case"polygon_with_arcs":return fYo(t,e)}},yYo=(t,e)=>{for(const n of e)CYo(t,n)},EYo={...jC,silkscreen:{top:Fo.board.f_silks,bottom:Fo.board.b_silks}};function xYo(t){return t.type.includes("pcb_silkscreen")}function NLt({canvas:t,elements:e,layers:n,realToCanvasMat:o}){const i=new Pc(t);i.configure({colorOverrides:EYo}),i.realToCanvasMat=o;const r=e.filter(xYo);i.drawElements(r,{layers:n})}var BYo={...jC,copper:{...jC.copper,top:Kr(Fo.board.pad_front).lighten(.5).toString(),bottom:Kr(Fo.board.pad_back).lighten(.5).toString(),inner1:Kr(Fo.board.copper.in1).lighten(.5).toString(),inner2:Kr(Fo.board.copper.in2).lighten(.5).toString(),inner3:Kr(Fo.board.copper.in3).lighten(.5).toString(),inner4:Kr(Fo.board.copper.in4).lighten(.5).toString(),inner5:Kr(Fo.board.copper.in5).lighten(.5).toString(),inner6:Kr(Fo.board.copper.in6).lighten(.5).toString(),inner7:Kr(Fo.board.copper.in7).lighten(.5).toString(),inner8:Kr(Fo.board.copper.in8).lighten(.5).toString()},soldermask:{...jC.soldermask,top:Kr(Fo.board.soldermask.top).lighten(.35).toString(),bottom:Kr(Fo.board.soldermask.bottom).lighten(.35).toString()}};function RLt({canvas:t,elements:e,layers:n,realToCanvasMat:o,drawSoldermaskTop:i,drawSoldermaskBottom:r,primitives:s}){const a=new Pc(t);a.realToCanvasMat=o;const A=e.filter(u=>u.type==="pcb_board");if(A.length<=1)a.drawElements(e,{layers:n,drawSoldermask:!0,drawSoldermaskTop:i,drawSoldermaskBottom:r,drawBoardMaterial:!1});else{const u=e.filter(h=>h.type!=="pcb_board");for(const h of A)a.drawElements([h,...u],{layers:n,drawSoldermask:!0,drawSoldermaskTop:i,drawSoldermaskBottom:r,drawBoardMaterial:!1})}if(!s)return;const c=new Set;for(const u of s){if(!(u.is_mouse_over||u.is_in_highlighted_net))continue;const h=u._element;h?.type==="pcb_smtpad"?c.add(h.pcb_smtpad_id):h?.type==="pcb_plated_hole"?c.add(h.pcb_plated_hole_id):h?.type==="pcb_via"&&c.add(h.pcb_via_id)}if(c.size===0)return;const l=e.filter(u=>u.type==="pcb_smtpad"?c.has(u.pcb_smtpad_id):u.type==="pcb_plated_hole"?c.has(u.pcb_plated_hole_id):u.type==="pcb_via"?c.has(u.pcb_via_id):!1);if(l.length===0)return;const g=new Pc(t);g.configure({colorOverrides:BYo}),g.realToCanvasMat=o,g.drawElements(l,{layers:n,drawSoldermask:!0,drawSoldermaskTop:i,drawSoldermaskBottom:r,drawBoardMaterial:!1})}var QYo={...jC,copper:{...jC.copper,top:Kr(Fo.board.pad_front).lighten(.5).toString(),bottom:Kr(Fo.board.pad_back).lighten(.5).toString(),inner1:Kr(Fo.board.copper.in1).lighten(.5).toString(),inner2:Kr(Fo.board.copper.in2).lighten(.5).toString(),inner3:Kr(Fo.board.copper.in3).lighten(.5).toString(),inner4:Kr(Fo.board.copper.in4).lighten(.5).toString(),inner5:Kr(Fo.board.copper.in5).lighten(.5).toString(),inner6:Kr(Fo.board.copper.in6).lighten(.5).toString(),inner7:Kr(Fo.board.copper.in7).lighten(.5).toString(),inner8:Kr(Fo.board.copper.in8).lighten(.5).toString()}};function SYo(t){return t.type==="pcb_via"}function bYo({canvas:t,elements:e,layers:n,realToCanvasMat:o,primitives:i,drawSoldermask:r}){const s=e.filter(SYo).filter(l=>n.some(g=>g.includes("copper")));if(s.length===0)return;const a=new Set;if(i)for(const l of i)(l.is_mouse_over||l.is_in_highlighted_net)&&l._element?.type==="pcb_via"&&a.add(l._element.pcb_via_id);const A=s.filter(l=>a.has(l.pcb_via_id)),c=s.filter(l=>!a.has(l.pcb_via_id));if(c.length>0){const l=new Pc(t);l.realToCanvasMat=o,l.drawElements(c,{layers:n,drawSoldermask:r})}if(A.length>0){const l=new Pc(t);l.configure({colorOverrides:QYo}),l.realToCanvasMat=o,l.drawElements(A,{layers:n,drawSoldermask:r})}}var DYo=({primitives:t,elements:e,transform:n,grid:o,width:i=500,height:r=500})=>{const s=Z.useRef({}),a=Cd(d=>d.selected_layer),A=Cd(d=>d.is_showing_copper_pours),c=Cd(d=>d.is_showing_solder_mask),l=Cd(d=>d.is_showing_fabrication_notes),g=Cd(d=>d.is_showing_pcb_notes),u=Cd(d=>d.is_showing_courtyards),h=Cd(d=>d.is_showing_silkscreen);return Z.useEffect(()=>{if(!s.current||Object.keys(s.current).length===0)return;const d=Object.fromEntries(Object.entries(s.current).filter(([p,I])=>!!I));if(Object.keys(d).length===0)return;const _=new DUo(d);n&&(_.transform=n),_.clear(),_.foregroundLayer=a;const m=t.filter(p=>c||!p.layer?.includes("soldermask")).filter(p=>h||!p.layer?.includes("silkscreen")).filter(p=>l||!p.layer?.includes("fabrication")).filter(p=>p.layer!=="board").filter(p=>p._element?.type!=="pcb_smtpad").filter(p=>p._element?.type!=="pcb_plated_hole").filter(p=>p._element?.type!=="pcb_via").filter(p=>p._element?.type!=="pcb_trace").filter(p=>p._element?.type!=="pcb_copper_text");if(yYo(_,m),n){const p=s.current.top,I=s.current.bottom,f=s9e(e).map(Q=>({canvas:s.current[Q],layer:Q,copperLayer:vUo(Q)}));for(const{canvas:Q,copperLayer:b}of f)Q&&sYo({canvas:Q,elements:e,layers:[b],realToCanvasMat:n,primitives:t,showCopperPours:A});for(const{canvas:Q,copperLayer:b}of f)Q&&UUo({canvas:Q,elements:e,layers:[b],realToCanvasMat:n});for(const{canvas:Q,copperLayer:b,layer:D}of f)Q&&cYo({canvas:Q,elements:e,layers:[b],realToCanvasMat:n,primitives:t,drawSoldermask:c&&(D==="top"||D==="bottom")});for(const{canvas:Q,copperLayer:b}of f)Q&&NUo({canvas:Q,elements:e,layers:[b],realToCanvasMat:n});for(const{canvas:Q,copperLayer:b}of f)Q&&ZUo({canvas:Q,elements:e,layers:[b],realToCanvasMat:n,primitives:t,drawSoldermask:c});for(const{canvas:Q,copperLayer:b,layer:D}of f)Q&&bYo({canvas:Q,elements:e,layers:[b],realToCanvasMat:n,primitives:t,drawSoldermask:c&&(D==="top"||D==="bottom")});if(c){const Q=a==="bottom"?"bottom":"top",b=Q==="top",D=Q==="bottom",R=s.current.soldermask_top;R&&Q==="top"&&RLt({canvas:R,elements:e,layers:["top_soldermask"],realToCanvasMat:n,drawSoldermaskTop:b,drawSoldermaskBottom:D,primitives:t});const w=s.current.soldermask_bottom;w&&Q==="bottom"&&RLt({canvas:w,elements:e,layers:["bottom_soldermask"],realToCanvasMat:n,drawSoldermaskTop:b,drawSoldermaskBottom:D,primitives:t})}const C=s.current.drill;if(C&&HUo({canvas:C,elements:e,layers:["drill"],realToCanvasMat:n}),h){const Q=s.current.top_silkscreen;Q&&NLt({canvas:Q,elements:e,layers:["top_silkscreen"],realToCanvasMat:n});const b=s.current.bottom_silkscreen;b&&NLt({canvas:b,elements:e,layers:["bottom_silkscreen"],realToCanvasMat:n})}if(l){const Q=s.current.top_fabrication;Q&&ELt({canvas:Q,elements:e,layers:["top_fabrication_note"],realToCanvasMat:n});const b=s.current.bottom_fabrication;b&&ELt({canvas:b,elements:e,layers:["bottom_fabrication_note"],realToCanvasMat:n})}if(g){const Q=s.current.bottom_notes;Q&&xLt({canvas:Q,elements:e,layers:["bottom_user_note"],realToCanvasMat:n});const b=s.current.top_notes;b&&xLt({canvas:b,elements:e,layers:["top_user_note"],realToCanvasMat:n})}if(u){const Q=s.current.top_courtyard;Q&&yLt({canvas:Q,elements:e,layers:["top_courtyard"],realToCanvasMat:n});const b=s.current.bottom_courtyard;b&&yLt({canvas:b,elements:e,layers:["bottom_courtyard"],realToCanvasMat:n})}const y=s.current.board;y&&(jUo({canvas:y,elements:e,layers:[],realToCanvasMat:n,drawSoldermask:c}),OUo({canvas:y,elements:e,layers:[],realToCanvasMat:n,drawSoldermask:c}));const E=s.current.edge_cuts;E&&zUo({canvas:E,elements:e,layers:["edge_cuts"],realToCanvasMat:n});const B=[{canvas:p,layer:"top"},{canvas:I,layer:"bottom"}];for(const{canvas:Q,layer:b}of B)Q&&JUo({canvas:Q,elements:e,layers:[b],realToCanvasMat:n})}_.orderAndFadeLayers()},[t,e,n,a,A,c,l,g,u,h]),W.jsxs("div",{style:{backgroundColor:"black",width:i,height:r,position:"relative"},children:[W.jsx(hse.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:i,height:r,transform:n,stringifyCoord:(d,_,m)=>`${hse.toMMSI(d,m)}, ${hse.toMMSI(_,m)}`}),MUo(e).filter(d=>!(!c&&d.includes("soldermask")||!h&&d.includes("silkscreen"))).map(d=>d.replace(/-/g,"")).map((d,_)=>W.jsx("canvas",{className:`pcb-layer-${d}`,ref:m=>{s.current??={},m?s.current[d]=m:delete s.current[d]},style:{position:"absolute",zIndex:_,left:0,top:0,pointerEvents:"none"},width:i,height:r},d))]})},PYo=.6,vYo=1;$8e(IKo(),1),$8e(RKo(),1);var Mse=["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 TLt(t,e,n,o={}){const i=o.padding??40,r=o.yFlip??!1;let s;if("center"in t){const l=t.width/2,g=t.height/2;s={minX:t.center.x-l,maxX:t.center.x+l,minY:t.center.y-g,maxY:t.center.y+g}}else s=t;const a=s.maxX-s.minX||1,A=s.maxY-s.minY||1,c=Math.min((e-2*i)/a,(n-2*i)/A);return ki(Wi(e/2,n/2),ug(c,r?-c:c),Wi(-(s.minX+a/2),-(s.minY+A/2)))}function MYo(t){const e=[...t.points||[],...(t.lines||[]).flatMap(n=>n.points),...(t.rects||[]).flatMap(n=>{const o=n.width/2,i=n.height/2;return[{x:n.center.x-o,y:n.center.y-i},{x:n.center.x+o,y:n.center.y-i},{x:n.center.x-o,y:n.center.y+i},{x:n.center.x+o,y:n.center.y+i}]}),...(t.circles||[]).flatMap(n=>[{x:n.center.x-n.radius,y:n.center.y},{x:n.center.x+n.radius,y:n.center.y},{x:n.center.x,y:n.center.y-n.radius},{x:n.center.x,y:n.center.y+n.radius}]),...(t.texts||[]).flatMap(n=>{const o=n.fontSize??12,i=n.text.length*o*PYo,r=o*vYo,s=n.anchorSide??"center",a={top_left:{dx:0,dy:0},top_center:{dx:-i/2,dy:0},top_right:{dx:-i,dy:0},center_left:{dx:0,dy:-r/2},center:{dx:-i/2,dy:-r/2},center_right:{dx:-i,dy:-r/2},bottom_left:{dx:0,dy:-r},bottom_center:{dx:-i/2,dy:-r},bottom_right:{dx:-i,dy:-r}},{dx:A,dy:c}=a[s],l=n.x+A,g=n.y+c;return[{x:l,y:g},{x:l+i,y:g+r}]})];return e.length===0?{minX:-1,maxX:1,minY:-1,maxY:1}:e.reduce((n,o)=>({minX:Math.min(n.minX,o.x),maxX:Math.max(n.maxX,o.x),minY:Math.min(n.minY,o.y),maxY:Math.max(n.maxY,o.y)}),{minX:1/0,maxX:-1/0,minY:1/0,maxY:-1/0})}function wYo(t,e,n={}){const o=e instanceof HTMLCanvasElement?e.getContext("2d"):e;if(!o)throw new Error("Could not get 2D context from canvas");const i=e instanceof HTMLCanvasElement?e.width:e.canvas.width,r=e instanceof HTMLCanvasElement?e.height:e.canvas.height;let s;if(n.transform)s=n.transform;else if(n.viewbox)s=TLt(n.viewbox,i,r,{padding:n.padding,yFlip:n.yFlip});else{const a=MYo(t),A=t.coordinateSystem==="cartesian";s=TLt(a,i,r,{padding:n.padding??40,yFlip:A})}o.clearRect(0,0,i,r),o.save(),t.rects&&t.rects.length>0&&t.rects.forEach(a=>{const A=a.width/2,c=a.height/2,l=mt(s,{x:a.center.x-A,y:a.center.y-c}),g=mt(s,{x:a.center.x+A,y:a.center.y+c}),u=Math.abs(g.x-l.x),h=Math.abs(g.y-l.y);o.beginPath(),o.rect(Math.min(l.x,g.x),Math.min(l.y,g.y),u,h),a.fill&&(o.fillStyle=a.fill,o.fill()),a.stroke&&(o.strokeStyle=a.stroke,o.stroke())}),t.circles&&t.circles.length>0&&t.circles.forEach(a=>{const A=mt(s,a.center),c=a.radius*Math.abs(s.a);o.beginPath(),o.arc(A.x,A.y,c,0,2*Math.PI),a.fill&&(o.fillStyle=a.fill,o.fill()),a.stroke&&(o.strokeStyle=a.stroke??"transparent",o.stroke())}),t.lines&&t.lines.length>0&&t.lines.forEach((a,A)=>{if(a.points.length===0)return;o.beginPath();const c=mt(s,a.points[0]);o.moveTo(c.x,c.y);for(let l=1;l<a.points.length;l++){const g=mt(s,a.points[l]);o.lineTo(g.x,g.y)}if(o.strokeStyle=a.strokeColor||Mse[A%Mse.length],a.strokeWidth?o.lineWidth=a.strokeWidth*s.a:o.lineWidth=2,o.lineCap="round",a.strokeDash)if(typeof a.strokeDash=="string"){let l;if(a.strokeDash.includes(","))l=a.strokeDash.split(",").map(g=>parseFloat(g.trim())).filter(g=>!Number.isNaN(g));else{const g=parseFloat(a.strokeDash.trim());l=Number.isNaN(g)?[]:[g]}o.setLineDash(l)}else o.setLineDash(a.strokeDash.map(l=>l*Math.abs(s.a)));else o.setLineDash([]);o.stroke()}),t.points&&t.points.length>0&&t.points.forEach((a,A)=>{const c=mt(s,a);o.beginPath(),o.arc(c.x,c.y,3,0,2*Math.PI),o.fillStyle=a.color||Mse[A%Mse.length],o.fill(),a.label&&!n.disableLabels&&(o.fillStyle=a.color||"black",o.font="12px sans-serif",o.fillText(a.label,c.x+5,c.y-5))}),t.texts&&t.texts.length>0&&t.texts.forEach(a=>{const A=mt(s,{x:a.x,y:a.y});o.fillStyle=a.color||"black",o.font=`${(a.fontSize??12)*Math.abs(s.a)}px sans-serif`;const c=a.anchorSide??"center",l={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"},g={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"};o.textAlign=l[c],o.textBaseline=g[c],o.fillText(a.text,A.x,A.y)}),o.restore()}var NYo=({children:t,transform:e,debugGraphics:n})=>{const o=Z.useRef(null),[i,{width:r,height:s}]=pY(),a=Cd(A=>A.is_showing_autorouting);return Z.useEffect(()=>{a&&o.current&&n&&r&&s&&(o.current.width=r,o.current.height=s,wYo(n,o.current,{transform:e,disableLabels:!0}))},[n,e,r,s,a]),a?W.jsxs("div",{ref:i,style:{position:"relative",width:"100%",height:"100%"},children:[t,W.jsx("canvas",{ref:o,style:{position:"absolute",top:0,left:0,opacity:.5,zIndex:100,width:"100%",height:"100%",pointerEvents:"none"}})]}):t},wse=(t,e,n)=>n(t,e),kLt=(t,e,n,o,i)=>{const r=i*Math.PI/180,s=Math.cos(r),a=Math.sin(r),A=t-n,c=e-o,l=A*s-c*a,g=A*a+c*s;return{x:l+n,y:g+o}},IY=t=>{if(t.length===0)return null;let e=t[0].x,n=t[0].x,o=t[0].y,i=t[0].y;for(const r of t)e=wse(e,r.x,Math.min),n=wse(n,r.x,Math.max),o=wse(o,r.y,Math.min),i=wse(i,r.y,Math.max);return{minX:e,maxX:n,minY:o,maxY:i}},RYo=(t,e)=>({minX:Math.min(t.minX,e.minX),maxX:Math.max(t.maxX,e.maxX),minY:Math.min(t.minY,e.minY),maxY:Math.max(t.maxY,e.maxY)}),TYo=(t,e)=>t?RYo(t,e):e,kYo=t=>{switch(t.pcb_drawing_type){case"line":{const e=(t.width??0)/2,n=[{x:t.x1,y:t.y1},{x:t.x2,y:t.y2}],o=IY(n);return o?{minX:o.minX-e,maxX:o.maxX+e,minY:o.minY-e,maxY:o.maxY+e}:null}case"rect":{const e=t.w/2,n=t.h/2,o=[{x:t.x-e,y:t.y-n},{x:t.x+e,y:t.y-n},{x:t.x+e,y:t.y+n},{x:t.x-e,y:t.y+n}],i=t.ccw_rotation??0,r=i===0?o:o.map(s=>kLt(s.x,s.y,t.x,t.y,i));return IY(r)}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 e=t.w/2,n=t.h/2,o=[{x:t.x-e,y:t.y-n},{x:t.x+e,y:t.y-n},{x:t.x+e,y:t.y+n},{x:t.x-e,y:t.y+n}],i=t.ccw_rotation??0,r=i===0?o:o.map(s=>kLt(s.x,s.y,t.x,t.y,i));return IY(r)}case"polygon":return IY(t.points);case"polygon_with_arcs":{const e=t.brep_shape.outer_ring.vertices.map(n=>({x:n.x,y:n.y}));return IY(e)}case"text":{const e=t.size??0,n=t.text?t.text.length*e*.6:0,o=e;if(n===0&&o===0)return{minX:t.x,maxX:t.x,minY:t.y,maxY:t.y};const i=n/2,r=o/2;return{minX:t.x-i,maxX:t.x+i,minY:t.y-r,maxY:t.y+r}}default:return null}};function FYo(t){const{dimensionStart:e,dimensionEnd:n,screenDimensionStart:o,screenDimensionEnd:i,flipX:r,flipY:s}=t,a=n.x-e.x,A=n.y-e.y,c=Math.sqrt(a*a+A*A),l=i.x-o.x,g=i.y-o.y,u=Math.sqrt(l*l+g*g),h=Math.atan2(g,l)*(180/Math.PI),d=Math.abs(h)%90,m=Math.min(d,90-d)>15,p=(o.x+i.x)/2,I=(o.y+i.y)/2,f=15,C=h+90;let y=Math.cos(C*Math.PI/180)*f,E=Math.sin(C*Math.PI/180)*f;const B=l>0&&g<0,Q=l>0&&g>0,b=l<0&&g>0;r!==s&&!B&&(y=-y,E=-E),B&&(y+=Math.cos(C*Math.PI/180)*-45,E+=Math.sin(C*Math.PI/180)*-45),Q&&(y+=Math.cos(C*Math.PI/180)+-20,E+=Math.sin(C*Math.PI/180)+-10),b&&(y+=Math.cos(C*Math.PI/180)*10,E+=Math.sin(C*Math.PI/180)*10);const D=p+y,R=I+E;return{distance:c,screenDistance:u,x:D,y:R,show:c>.01&&u>30&&m}}function LYo(t){const{dimensionStart:e,dimensionEnd:n,screenDimensionStart:o,screenDimensionEnd:i,flipX:r,flipY:s}=t;return Z.useMemo(()=>FYo({dimensionStart:e,dimensionEnd:n,screenDimensionStart:o,screenDimensionEnd:i,flipX:r,flipY:s}),[e,n,o,i,r,s])}var HYo=(t,e,n)=>{const o=n*Math.PI/180,i=Math.cos(o),r=Math.sin(o),s=t.x-e.x,a=t.y-e.y,A=s*i-a*r,c=s*r+a*i;return{x:A+e.x,y:c+e.y}},FLt=(t,e,n,o)=>{const i={top_left:{x:t.x-e,y:t.y-n},top_center:{x:t.x,y:t.y-n},top_right:{x:t.x+e,y:t.y-n},center_left:{x:t.x-e,y:t.y},center:{x:t.x,y:t.y},center_right:{x:t.x+e,y:t.y},bottom_left:{x:t.x-e,y:t.y+n},bottom_center:{x:t.x,y:t.y+n},bottom_right:{x:t.x+e,y:t.y+n}};return o===0?Object.entries(i).map(([r,s])=>({anchor:r,point:s})):Object.entries(i).map(([r,s])=>({anchor:r,point:HYo(s,t,o)}))},GYo=t=>{switch(t.pcb_drawing_type){case"rect":{const e=t.ccw_rotation??0;return FLt({x:t.x,y:t.y},t.w/2,t.h/2,e)}case"pill":{const e=t.ccw_rotation??0;return FLt({x:t.x,y:t.y},t.w/2,t.h/2,e)}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 e={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:e},{anchor:"line_end",point:{x:t.x2,y:t.y2}}]}case"polygon":return t.points.map((e,n)=>({anchor:`polygon_vertex_${n}`,point:e}));case"polygon_with_arcs":return t.brep_shape.outer_ring.vertices.map((e,n)=>({anchor:`polygon_with_arcs_vertex_${n}`,point:{x:e.x,y:e.y}}));default:return[]}},OYo=16,T6=5,LLt=t=>{if(t.pcb_drawing_type==="text")return!0;const e=t._element;if(!e||typeof e!="object")return!1;const n=typeof e.type=="string"?e.type:void 0;return n?!!(n.startsWith("pcb_silkscreen_")||n.startsWith("pcb_note_")||n==="pcb_text"||n.startsWith("pcb_fabrication_note_")&&n!=="pcb_fabrication_note_rect"):!1},KYo=({children:t,transform:e,focusOnHover:n=!1,primitives:o=[],onBoundsSelected:i,cancelPanDrag:r})=>{e||(e=Ll());const[s,a]=Z.useState(!1),[A,c]=Z.useState(!1),[l,g]=Z.useState(!1),[u,h]=Z.useState(!1),[d,_]=Z.useState(!1),[m,p]=Z.useState(!1),[I,f]=Z.useState({start:null,end:null}),C=Cd(we=>we.is_mouse_over_container),y=Z.useCallback(()=>{l&&(g(!1),window.dispatchEvent(new Event("disarm-dimension-tool")))},[l]),E=Z.useCallback(()=>{u&&(h(!1),window.dispatchEvent(new Event("disarm-bounds-tool")))},[u]),[B,Q]=Z.useState({x:0,y:0}),[b,D]=Z.useState({x:0,y:0}),[R,w]=Z.useState({x:0,y:0}),[H,G]=Z.useState({x:0,y:0}),K=Z.useRef({x:0,y:0}),U=Z.useRef(null),j=U.current?.getBoundingClientRect(),ne=Z.useMemo(()=>{const we=new Map;for(const Je of o){if(!Je._element||LLt(Je)||Je.pcb_drawing_type==="pill"||Je.pcb_drawing_type==="rect"&&Je.ccw_rotation&&Je.ccw_rotation!==0)continue;const Ie=kYo(Je);if(!Ie)continue;const We=we.get(Je._element);we.set(Je._element,TYo(We??void 0,Ie))}return we},[o]),re=Z.useMemo(()=>{const we=[];for(const Je of o){if(!Je._element||LLt(Je))continue;const Ie=GYo(Je);if(Ie.length!==0)for(const We of Ie)we.push({anchor:We.anchor,point:We.point,element:Je._element})}return we},[o]),X=Z.useMemo(()=>{const we=[];ne.forEach((Je,Ie)=>{if(!Je)return;const We=(Je.minX+Je.maxX)/2,Re=(Je.minY+Je.maxY)/2,Le={top_left:{x:Je.minX,y:Je.minY},top_center:{x:We,y:Je.minY},top_right:{x:Je.maxX,y:Je.minY},center_left:{x:Je.minX,y:Re},center:{x:We,y:Re},center_right:{x:Je.maxX,y:Re},bottom_left:{x:Je.minX,y:Je.maxY},bottom_center:{x:We,y:Je.maxY},bottom_right:{x:Je.maxX,y:Je.maxY}};for(const[Ve,Ne]of Object.entries(Le))we.push({anchor:Ve,point:Ne,element:Ie})});for(const Je of re)we.push(Je);return we.push({anchor:"origin",point:{x:0,y:0},element:null}),we},[ne,re]),te=Z.useMemo(()=>X.map((we,Je)=>({...we,id:`${Je}-${we.anchor}`,screenPoint:mt(e,we.point)})),[X,e]),se=Z.useCallback(we=>{if(te.length===0)return{point:we,id:null};const Je=mt(e,we);let Ie=null;for(const We of te){const Re=We.screenPoint.x-Je.x,Le=We.screenPoint.y-Je.y,Ve=Math.hypot(Re,Le);Ve>OYo||(!Ie||Ve<Ie.distance)&&(Ie={distance:Ve,id:We.id,point:We.point})}return Ie?{point:Ie.point,id:Ie.id}:{point:we,id:null}},[te,e]);Z.useEffect(()=>{const we=We=>{const Re=We.target;if(Re.tagName==="INPUT"||Re.tagName==="TEXTAREA"||Re.isContentEditable)return;const Le=U.current?.contains(document.activeElement)||document.activeElement===U.current;if(!(!C&&!Le)){if(We.key==="d"){const Ve=se({x:K.current.x,y:K.current.y});Q({x:Ve.point.x,y:Ve.point.y}),D({x:Ve.point.x,y:Ve.point.y}),f({start:Ve.id,end:Ve.id}),s?(a(!1),c(!1),f({start:null,end:null})):(a(!0),c(!0)),y()}We.key==="Escape"&&(a(!1),c(!1),f({start:null,end:null}),_(!1),p(!1),y(),E())}},Je=()=>{g(!0),h(!1),window.dispatchEvent(new Event("disarm-bounds-tool"))},Ie=()=>{h(!0),g(!1),a(!1),c(!1),window.dispatchEvent(new Event("disarm-dimension-tool"))};return window.addEventListener("keydown",we),window.addEventListener("arm-dimension-tool",Je),window.addEventListener("arm-bounds-tool",Ie),()=>{window.removeEventListener("keydown",we),window.removeEventListener("arm-dimension-tool",Je),window.removeEventListener("arm-bounds-tool",Ie),y(),E()}},[C,s,y,E,se]);const Ae=mt(e,B),ue=mt(e,b),Ce=mt(e,R),Ee=mt(e,H),Be={minX:Math.min(R.x,H.x),minY:Math.min(R.y,H.y),maxX:Math.max(R.x,H.x),maxY:Math.max(R.y,H.y)},he={left:Math.min(Ce.x,Ee.x),top:Math.min(Ce.y,Ee.y),width:Math.abs(Ce.x-Ee.x),height:Math.abs(Ce.y-Ee.y)},ye=Z.useCallback((we,Je)=>{const Ie={minX:Math.min(we.x,Je.x),minY:Math.min(we.y,Je.y),maxX:Math.max(we.x,Je.x),maxY:Math.max(we.y,Je.y)};i?.(Ie),window.dispatchEvent(new CustomEvent("pcb-viewer:bounds-selected",{detail:Ie}))},[i]),me={left:Math.min(Ae.x,ue.x),right:Math.max(Ae.x,ue.x),top:Math.min(Ae.y,ue.y),bottom:Math.max(Ae.y,ue.y),flipX:Ae.x>ue.x,flipY:Ae.y>ue.y,width:0,height:0};me.width=me.right-me.left,me.height=me.bottom-me.top;const Pe=LYo({dimensionStart:B,dimensionEnd:b,screenDimensionStart:Ae,screenDimensionEnd:ue,flipX:me.flipX,flipY:me.flipY});return W.jsxs("div",{ref:U,"data-pcb-viewer":!0,tabIndex:0,style:{position:"relative",outline:"none"},onMouseEnter:()=>{n&&U.current&&U.current.focus()},onMouseLeave:()=>{U.current&&U.current.blur()},onClick:()=>{U.current&&U.current.focus()},onMouseMove:we=>{const Je=we.currentTarget.getBoundingClientRect(),Ie=we.clientX-Je.left,We=we.clientY-Je.top,Re=mt(QQ(e),{x:Ie,y:We});if(K.current.x=Re.x,K.current.y=Re.y,A){const Le=se(Re);D({x:Le.point.x,y:Le.point.y}),f(Ve=>({...Ve,end:Le.id}))}m&&(r?.(),G({x:Re.x,y:Re.y}))},onMouseDown:we=>{const Je=we.currentTarget.getBoundingClientRect(),Ie=we.clientX-Je.left,We=we.clientY-Je.top,Re=mt(QQ(e),{x:Ie,y:We});if(u)we.preventDefault(),we.stopPropagation(),r?.(),w({x:Re.x,y:Re.y}),G({x:Re.x,y:Re.y}),_(!0),p(!0),E();else if(l&&!s){const Le=se(Re);Q({x:Le.point.x,y:Le.point.y}),D({x:Le.point.x,y:Le.point.y}),f({start:Le.id,end:Le.id}),a(!0),c(!0),y()}else A?(c(!1),f(Le=>({...Le,end:null}))):s&&(a(!1),f({start:null,end:null}))},onMouseUp:we=>{if(!m)return;const Je=we.currentTarget.getBoundingClientRect(),Ie=we.clientX-Je.left,We=we.clientY-Je.top,Re=mt(QQ(e),{x:Ie,y:We}),Le={x:Re.x,y:Re.y};we.preventDefault(),we.stopPropagation(),r?.(),G(Le),p(!1),ye(R,Le)},children:[t,d&&W.jsxs(W.Fragment,{children:[W.jsx("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none",mixBlendMode:"difference",zIndex:Yg.dimensionOverlay},width:j.width,height:j.height,children:W.jsx("rect",{x:he.left,y:he.top,width:he.width,height:he.height,stroke:"red",strokeWidth:1.5,strokeDasharray:"4,3",fill:"rgba(255, 0, 0, 0.12)"})}),W.jsxs("div",{style:{left:0,bottom:s?58:0,position:"absolute",color:"red",fontFamily:"sans-serif",fontSize:12,margin:4,pointerEvents:"none",mixBlendMode:"difference",zIndex:Yg.dimensionOverlay},children:["minX: ",Be.minX.toFixed(2),", minY:"," ",Be.minY.toFixed(2),W.jsx("br",{}),"maxX: ",Be.maxX.toFixed(2),", maxY:"," ",Be.maxY.toFixed(2)]})]}),s&&W.jsxs(W.Fragment,{children:[Pe.show&&W.jsx("div",{style:{position:"absolute",left:Pe.x,top:Pe.y,color:"red",mixBlendMode:"difference",pointerEvents:"none",fontSize:12,fontFamily:"sans-serif",whiteSpace:"nowrap",zIndex:Yg.dimensionOverlay},children:Pe.distance.toFixed(2)}),W.jsx("div",{style:{position:"absolute",left:me.left,width:me.width,textAlign:"center",top:Ae.y+2,color:"red",mixBlendMode:"difference",pointerEvents:"none",marginTop:me.flipY?0:-20,fontSize:12,fontFamily:"sans-serif",zIndex:Yg.dimensionOverlay},children:Math.abs(B.x-b.x).toFixed(2)}),W.jsx("div",{style:{position:"absolute",left:ue.x,height:me.height,display:"flex",flexDirection:"column",justifyContent:"center",top:me.top,color:"red",pointerEvents:"none",mixBlendMode:"difference",fontSize:12,fontFamily:"sans-serif",zIndex:Yg.dimensionOverlay},children:W.jsx("div",{style:{marginLeft:me.flipX?"-100%":4,paddingRight:4},children:Math.abs(B.y-b.y).toFixed(2)})}),W.jsxs("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none",mixBlendMode:"difference",zIndex:Yg.dimensionOverlay},width:j.width,height:j.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:Ae.x,y1:Ae.y,x2:ue.x,y2:ue.y,markerEnd:"url(#head)",strokeWidth:1.5,fill:"none",stroke:"red"}),W.jsx("line",{x1:Ae.x,y1:Ae.y,x2:ue.x,y2:Ae.y,strokeWidth:1.5,fill:"none",strokeDasharray:"2,2",stroke:"red"}),W.jsx("line",{x1:ue.x,y1:Ae.y,x2:ue.x,y2:ue.y,strokeWidth:1.5,fill:"none",strokeDasharray:"2,2",stroke:"red"})]}),A&&te.map(we=>{const Je=we.id===I.start||we.id===I.end,Ie=T6/2;return W.jsxs("svg",{width:T6,height:T6,style:{position:"absolute",left:we.screenPoint.x-Ie,top:we.screenPoint.y-Ie,pointerEvents:"none",zIndex:Yg.dimensionOverlay},children:[W.jsx("line",{x1:0,y1:0,x2:T6,y2:T6,stroke:Je?"#66ccff":"white",strokeWidth:1}),W.jsx("line",{x1:T6,y1:0,x2:0,y2:T6,stroke:Je?"#66ccff":"white",strokeWidth:1})]},we.id)}),W.jsxs("div",{style:{right:0,bottom:0,position:"absolute",color:"red",fontFamily:"sans-serif",fontSize:12,margin:4},children:["(",B.x.toFixed(2),",",B.y.toFixed(2),")",W.jsx("br",{}),"(",b.x.toFixed(2),",",b.y.toFixed(2),")",W.jsx("br",{}),"dist:"," ",Math.sqrt((b.x-B.x)**2+(b.y-B.y)**2).toFixed(2)]})]})]})},UYo=(t,e,n=0)=>{const o=t.width/2,i=t.height/2,r=t.center.x-o-n,s=t.center.x+o+n,a=t.center.y-i-n,A=t.center.y+i+n;return e.x>r&&e.x<s&&e.y>a&&e.y<A},YYo=({children:t,disabled:e,transform:n,soup:o,cancelPanDrag:i,onCreateEditEvent:r,onModifyEditEvent:s})=>{n||(n=Ll());const a=Z.useRef(null),[A,c]=Z.useState(null),[l,g]=Z.useState(null),u=A!==null;Cd(m=>m.in_edit_mode);const h=Cd(m=>m.in_move_footprint_mode),d=Cd(m=>m.setIsMovingComponent),_=e||!h;return W.jsxs("div",{ref:a,style:{position:"relative",overflow:"hidden"},onMouseDown:m=>{if(_)return;const p=m.currentTarget.getBoundingClientRect(),I=m.clientX-p.left,f=m.clientY-p.top;if(Number.isNaN(I)||Number.isNaN(f))return;const C=mt(QQ(n),{x:I,y:f});let y=!1;for(const E of o)if(E.type==="pcb_component"&&UYo(E,C,10/n.a)){i(),c(E.pcb_component_id),y=!0;const B=Math.random().toString();g({dragStart:C,originalCenter:E.center,dragEnd:C,edit_event_id:B}),r({edit_event_id:B,edit_event_type:"edit_pcb_component_location",pcb_edit_event_type:"edit_component_location",pcb_component_id:E.pcb_component_id,original_center:E.center,new_center:E.center,in_progress:!0,created_at:Date.now()}),d(!0);break}if(y||c(null),y)return m.preventDefault(),!1},onMouseMove:m=>{if(!A||!l)return;const p=m.currentTarget.getBoundingClientRect(),I=m.clientX-p.left,f=m.clientY-p.top;if(Number.isNaN(I)||Number.isNaN(f))return;const C=mt(QQ(n),{x:I,y:f});g({...l,dragEnd:C}),s({edit_event_id:l.edit_event_id,new_center:{x:l.originalCenter.x+C.x-l.dragStart.x,y:l.originalCenter.y+C.y-l.dragStart.y}})},onMouseUp:m=>{A&&(c(null),d(!1),l&&(s({edit_event_id:l.edit_event_id,in_progress:!1}),g(null)))},children:[t,!_&&o.filter(m=>m.type==="pcb_component").map(m=>{if(!m?.center)return null;const p=mt(n,m.center);return W.jsx("div",{style:{position:"absolute",pointerEvents:"none",left:p.x,top:p.y,width:m.width*n.a+20,height:m.height*n.a+20,transform:"translate(-50%, -50%)",background:u&&A===m.pcb_component_id?"rgba(255, 0, 0, 0.2)":""}},m.pcb_component_id)})]})},a9e=(t,e)=>{const n=e.current;if(!n)return{transform:"translate(-50%, -100%)",left:t.x,top:t.y};const o=n.getBoundingClientRect(),i=200,r=10,s=60;let a="-50%",A="-100%",c=t.x,l=t.y;return t.x+s+i<o.width-r?(c=t.x+s,a="0%"):t.x-s-i>r?(c=t.x-s,a="-100%"):(c=t.x,a="-50%"),{transform:`translate(${a}, ${A})`,left:c,top:l}},zYo=({center:t})=>W.jsxs("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none",mixBlendMode:"difference",zIndex:Yg.errorOverlay+30},width:"100%",height:"100%",children:[W.jsx("circle",{cx:t.x,cy:t.y,r:11,fill:"none",stroke:"#ff6b6b",strokeWidth:2.5,opacity:.95}),W.jsx("circle",{cx:t.x,cy:t.y,r:4.5,fill:"#ff6b6b",opacity:.95}),W.jsx("line",{x1:t.x-18,y1:t.y,x2:t.x-8,y2:t.y,stroke:"#ff6b6b",strokeWidth:2}),W.jsx("line",{x1:t.x+8,y1:t.y,x2:t.x+18,y2:t.y,stroke:"#ff6b6b",strokeWidth:2}),W.jsx("line",{x1:t.x,y1:t.y-18,x2:t.x,y2:t.y-8,stroke:"#ff6b6b",strokeWidth:2}),W.jsx("line",{x1:t.x,y1:t.y+8,x2:t.x,y2:t.y+18,stroke:"#ff6b6b",strokeWidth:2})]}),HLt=({errorCenter:t,isHighlighted:e=!1})=>W.jsx("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none",mixBlendMode:"difference",zIndex:Yg.errorOverlay},width:"100%",height:"100%",children:W.jsx("rect",{x:t.x-7,y:t.y-7,width:14,height:14,transform:`rotate(45 ${t.x} ${t.y})`,fill:e?"#ff4444":"transparent",stroke:e?"#ff4444":"red",strokeWidth:e?2.5:1.5})}),A9e=Bse`
|
|
5685
5685
|
opacity: 0;
|
|
5686
5686
|
pointer-events: none;
|
|
5687
5687
|
background-color: rgba(0, 0, 0, 0.8);
|
|
@@ -5694,7 +5694,7 @@ $1`).replace(/>(\s*)(?=<!--\s*\/)/g,"> ")}}});function iLt(t,e,n){if(!e||!n)retu
|
|
|
5694
5694
|
transition: opacity 0.2s;
|
|
5695
5695
|
margin-bottom: 10px;
|
|
5696
5696
|
color: red;
|
|
5697
|
-
`,VYo=({children:t,transform:e=Ll(),elements:n})=>{const o=Z.useRef(null),{isShowingDRCErrors:i,hoveredErrorId:r,focusedErrorId:s}=Cd(_=>({isShowingDRCErrors:_.is_showing_drc_errors,hoveredErrorId:_.hovered_error_id,focusedErrorId:_.focused_error_id})),a=s??r;if(!n)return W.jsx("div",{style:{position:"relative"},ref:o,children:t});const A=n.filter(_=>_.type==="pcb_trace_error"&&!_.message?.includes("Multiple components found with name")),c=n.filter(_=>_.type==="pcb_via_clearance_error"),l=n.filter(_=>_.type==="pcb_trace_error"&&_.message?.includes("Multiple components found with name")),g=hLt(n),u=ILt(n,a),h=_=>{const m=fUo({error:_,indexes:g});if(!m||typeof m.x!="number"||typeof m.y!="number")return null;const p=mt(e,m);return Number.isNaN(p.x)||Number.isNaN(p.y)?null:p};let d=null;return u&&(d=h(u)),W.jsxs("div",{style:{position:"relative"},ref:o,children:[t,A.map((_,m)=>{const p=Bk(_,m),I=a===p;if(!I&&!i)return null;const f=h(_);if(!f)return null;const C=a9e(f,o);return W.jsxs(Z.Fragment,{children:[W.jsx(HLt,{errorCenter:f,isHighlighted:I}),W.jsx("div",{style:{position:"absolute",left:f.x-15,top:f.y-15,width:30,height:30,zIndex:Yg.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:y=>{const E=y.currentTarget.nextElementSibling;if(E){const B=E.querySelector(".error-message");B&&(B.style.opacity="1")}},onMouseLeave:y=>{if(!I){const E=y.currentTarget.nextElementSibling;if(E){const B=E.querySelector(".error-message");B&&(B.style.opacity="0")}}}}),W.jsx("div",{style:{position:"absolute",zIndex:I?200:100,left:C.left,top:C.top,color:I?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:i||I?"flex":"none",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:C.transform},children:W.jsx("div",{className:`error-message ${A9e}`,style:{opacity:I?1:0,border:`1px solid ${I?"#ff4444":"red"}`},children:_.message})})]},p)}),c.map((_,m)=>{const p=Bk(_,m),I=a===p;if(!I&&!i)return null;const f=h(_);if(!f)return null;const C=a9e({x:f.x,y:f.y},o);return W.jsxs(Z.Fragment,{children:[W.jsx(HLt,{errorCenter:f,isHighlighted:I}),W.jsx("div",{style:{position:"absolute",left:f.x-15,top:f.y-15,width:30,height:30,zIndex:Yg.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:y=>{const E=y.currentTarget.nextElementSibling;if(E){const B=E.querySelector(".error-message");B&&(B.style.opacity="1")}},onMouseLeave:y=>{if(!I){const E=y.currentTarget.nextElementSibling;if(E){const B=E.querySelector(".error-message");B&&(B.style.opacity="0")}}}}),W.jsx("div",{style:{position:"absolute",zIndex:I?Yg.errorOverlay+10:Yg.errorOverlay+1,left:C.left,top:C.top,color:I?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:"flex",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:C.transform},children:W.jsx("div",{className:`error-message ${A9e}`,style:{opacity:I?1:0,border:`1px solid ${I?"#ff4444":"red"}`},children:_.message})})]},p)}),l.map((_,m)=>{const p=_.component_name||_.message?.match(/name "([^"]+)"/)?.[1];if(!p)return null;const I=n?.filter(y=>y.type==="source_component"&&y.name===p||y.type==="pcb_component"&&n?.find(E=>E.type==="source_component"&&E.source_component_id===y.source_component_id&&E.name===p))||[],f=Bk(_,m),C=a===f;return!C&&!i?null:I.map((y,E)=>{let B={x:0,y:0};if(y.type==="pcb_component")B=y.center||{x:0,y:0};else if(y.type==="source_component"){const K=n?.find(U=>U.type==="pcb_component"&&U.source_component_id===y.source_component_id);K&&K.type==="pcb_component"&&(B=K.center||{x:0,y:0})}const Q=mt(e,B);if(Number.isNaN(Q.x)||Number.isNaN(Q.y))return null;const b=Math.abs(e.a),H=Math.max(8,Math.min(30,.5*b)),G=a9e(Q,o);return W.jsxs(Z.Fragment,{children:[W.jsx("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none",mixBlendMode:"difference",zIndex:Yg.errorOverlay},width:"100%",height:"100%",children:C?W.jsx("polygon",{points:`${Q.x},${Q.y-H*1.25} ${Q.x+H},${Q.y} ${Q.x},${Q.y+H*1.25} ${Q.x-H},${Q.y}`,fill:"#ff4444"}):W.jsx("circle",{cx:Q.x,cy:Q.y,r:H,fill:"none",stroke:C?"#ff4444":"red",strokeWidth:C?Math.max(2,H*.15):Math.max(1,H*.1),opacity:1})}),W.jsx("div",{style:{position:"absolute",left:Q.x-(H+10),top:Q.y-(H+10),width:(H+10)*2,height:(H+10)*2,zIndex:Yg.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:K=>{const U=K.currentTarget.nextElementSibling;if(U){const q=U.querySelector(".error-message");q&&(q.style.opacity="1")}},onMouseLeave:K=>{if(!C){const U=K.currentTarget.nextElementSibling;if(U){const q=U.querySelector(".error-message");q&&(q.style.opacity="0")}}}}),W.jsx("div",{style:{position:"absolute",zIndex:C?Yg.errorOverlay+20:Yg.errorOverlay+10,left:G.left,top:G.top,color:C?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:i||C?"flex":"none",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:G.transform},children:W.jsx("div",{className:`error-message ${A9e}`,style:{opacity:C?1:0,border:`1px solid ${C?"#ff4444":"red"}`},children:_.message})})]},`${f}_${E}`)})}),d&&W.jsx(zYo,{center:d})]})};function JYo(t,e){return t.size!==e.size?!1:Array.from(t).every(n=>e.has(n))}var Uv=t=>t?.type==="pcb_component",GLt=t=>t?.type==="pcb_group",qYo=t=>t?.type==="pcb_panel",c9e=t=>t?.type==="pcb_board",yu={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},X2={OFFSET_LINE:"white",COMPONENT_MARKER_FILL:"#66ccff",COMPONENT_MARKER_STROKE:"white",LABEL_TEXT:"white"},l9e=({targets:t,transform:e,containerWidth:n,containerHeight:o})=>{if(t.length===0)return null;const i={color:X2.LABEL_TEXT,mixBlendMode:"difference",pointerEvents:"none",fontSize:yu.LABEL_FONT_SIZE,fontFamily:"monospace",fontWeight:"bold"},r=new Map;return t.forEach(s=>{if(!r.has(s.anchor_id)){const a=mt(e,s.anchor);r.set(s.anchor_id,a)}}),W.jsx("div",{style:{position:"absolute",left:0,top:0,width:n,height:o,overflow:"hidden",pointerEvents:"none",zIndex:Yg.dimensionOverlay},children:W.jsxs("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none"},width:n,height:o,children:[t.map(s=>{const a=s.anchor,A=s.anchor_id,c=s.target,l=r.get(A),g=mt(e,c),u=c.x-a.x,h=c.y-a.y,d=Math.abs(g.x-l.x),_=Math.abs(g.y-l.y),m=g.y<l.y,p=g.x>l.x,I=m?yu.LABEL_OFFSET_ABOVE:yu.LABEL_OFFSET_BELOW,f=p?yu.LABEL_OFFSET_RIGHT:yu.LABEL_OFFSET_LEFT,C=d>yu.MIN_LINE_LENGTH_FOR_LABEL,y=_>yu.MIN_LINE_LENGTH_FOR_LABEL,E=`${s.display_offset_x??u.toFixed(2)}mm`,B=`${s.display_offset_y??h.toFixed(2)}mm`;return W.jsxs("g",{children:[W.jsx("line",{x1:l.x,y1:l.y,x2:g.x,y2:l.y,stroke:X2.OFFSET_LINE,strokeWidth:yu.LINE_STROKE_WIDTH,strokeDasharray:yu.LINE_DASH_PATTERN}),W.jsx("line",{x1:g.x,y1:l.y,x2:g.x,y2:g.y,stroke:X2.OFFSET_LINE,strokeWidth:yu.LINE_STROKE_WIDTH,strokeDasharray:yu.LINE_DASH_PATTERN}),s.type==="component"||s.type==="board"?W.jsx("circle",{cx:g.x,cy:g.y,r:yu.COMPONENT_MARKER_RADIUS,fill:X2.COMPONENT_MARKER_FILL,stroke:X2.COMPONENT_MARKER_STROKE,strokeWidth:1}):W.jsxs(W.Fragment,{children:[W.jsx("line",{x1:g.x-yu.ANCHOR_MARKER_SIZE,y1:g.y,x2:g.x+yu.ANCHOR_MARKER_SIZE,y2:g.y,stroke:X2.OFFSET_LINE,strokeWidth:yu.ANCHOR_MARKER_STROKE_WIDTH}),W.jsx("line",{x1:g.x,y1:g.y-yu.ANCHOR_MARKER_SIZE,x2:g.x,y2:g.y+yu.ANCHOR_MARKER_SIZE,stroke:X2.OFFSET_LINE,strokeWidth:yu.ANCHOR_MARKER_STROKE_WIDTH})]}),C&&W.jsx("foreignObject",{x:Math.min(l.x,g.x),y:l.y+I,width:Math.abs(g.x-l.x),height:20,style:{overflow:"visible"},children:W.jsx("div",{style:{...i,textAlign:"center"},children:E})}),y&&W.jsx("foreignObject",{x:g.x+f,y:Math.min(l.y,g.y),width:yu.Y_LABEL_MIN_WIDTH,height:Math.abs(g.y-l.y),style:{overflow:"visible"},children:W.jsx("div",{style:{...i,display:"flex",alignItems:"center",justifyContent:p?"flex-start":"flex-end",whiteSpace:"nowrap",padding:"0 4px",height:"100%"},children:B})})]},s.id)}),Array.from(r.entries()).map(([s,a])=>W.jsxs("g",{children:[W.jsx("line",{x1:a.x-yu.ANCHOR_MARKER_SIZE,y1:a.y,x2:a.x+yu.ANCHOR_MARKER_SIZE,y2:a.y,stroke:X2.OFFSET_LINE,strokeWidth:yu.ANCHOR_MARKER_STROKE_WIDTH}),W.jsx("line",{x1:a.x,y1:a.y-yu.ANCHOR_MARKER_SIZE,x2:a.x,y2:a.y+yu.ANCHOR_MARKER_SIZE,stroke:X2.OFFSET_LINE,strokeWidth:yu.ANCHOR_MARKER_STROKE_WIDTH})]},`anchor-${s}`))]})})},WYo=({elements:t,highlightedPrimitives:e,transform:n,containerWidth:o,containerHeight:i})=>{const r=t.filter(p=>c9e(p)),s=t.filter(p=>Uv(p)),a=t.filter(p=>GLt(p)),A=e.map(p=>Uv(p._parent_pcb_component)?p._parent_pcb_component.pcb_component_id:Uv(p._element)?p._element.pcb_component_id:null).filter(p=>!!p),c=new Set;if(A.forEach(p=>{const I=s.find(f=>f.pcb_component_id===p);I?.pcb_group_id&&c.add(I.pcb_group_id)}),!Cd(p=>p.is_showing_group_anchor_offsets)&&A.length===0)return null;const g=s.map(p=>{const I=p.positioned_relative_to_pcb_board_id;if(!I)return null;const f=r.find(C=>C.pcb_board_id===I);return f?{component:p,board:f,type:"component"}:null}).filter(p=>!!p),u=a.map(p=>{const I=p.positioned_relative_to_pcb_board_id;if(!I||!p.center)return null;const f=r.find(C=>C.pcb_board_id===I);return f?{group:p,board:f,type:"group"}:null}).filter(p=>!!p),h=[...g,...u];if(h.length===0)return null;const d=A.length===0,_=h.filter(p=>p.type==="component"?d||A.includes(p.component.pcb_component_id):d||c.has(p.group.pcb_group_id));if(_.length===0)return null;const m=_.map(p=>p.type==="component"?{id:`${p.board.pcb_board_id}-${p.component.pcb_component_id}-${p.type}`,anchor:p.board.center,anchor_id:p.board.pcb_board_id,target:p.component.center,type:"component",display_offset_x:p.component.display_offset_x,display_offset_y:p.component.display_offset_y}:{id:`${p.board.pcb_board_id}-${p.group.pcb_group_id}-${p.type}`,anchor:p.board.center,anchor_id:p.board.pcb_board_id,target:{x:p.group.anchor_position?.x??p.group.center.x,y:p.group.anchor_position?.y??p.group.center.y},type:"group",display_offset_x:p.group.display_offset_x,display_offset_y:p.group.display_offset_y}).filter(p=>!!p);return W.jsx(l9e,{targets:m,transform:n,containerWidth:o,containerHeight:i})},jYo=({elements:t,highlightedPrimitives:e,transform:n,containerWidth:o,containerHeight:i})=>{const r=t.filter(p=>GLt(p)),s=t.filter(p=>Uv(p)),a=e.map(p=>Uv(p._parent_pcb_component)?p._parent_pcb_component.pcb_component_id:Uv(p._element)?p._element.pcb_component_id:null).filter(p=>!!p),A=(p,I)=>{if(I.has(p))return;I.add(p);const f=r.find(C=>C.pcb_group_id===p);f?.position_mode==="relative_to_group_anchor"&&f.positioned_relative_to_pcb_group_id&&A(f.positioned_relative_to_pcb_group_id,I)},c=new Set;if(a.forEach(p=>{const I=s.find(f=>f.pcb_component_id===p);I&&(I.position_mode==="relative_to_group_anchor"&&I.positioned_relative_to_pcb_group_id&&A(I.positioned_relative_to_pcb_group_id,c),I.pcb_group_id&&A(I.pcb_group_id,c))}),!Cd(p=>p.is_showing_group_anchor_offsets)&&a.length===0)return null;const g=s.map(p=>{if(p.position_mode==="relative_to_group_anchor"&&p.positioned_relative_to_pcb_group_id){const I=r.find(f=>f.pcb_group_id===p.positioned_relative_to_pcb_group_id);return I&&I.anchor_position?{component:p,parentGroup:I,type:"component"}:null}if(p.pcb_group_id){const I=r.find(f=>f.pcb_group_id===p.pcb_group_id);return I&&I.anchor_position?{component:p,parentGroup:I,type:"component"}:null}return null}).filter(p=>!!p),u=r.map(p=>{if(p.position_mode==="relative_to_group_anchor"&&p.positioned_relative_to_pcb_group_id){const I=r.find(f=>f.pcb_group_id===p.positioned_relative_to_pcb_group_id);if(I&&I.anchor_position&&p.anchor_position)return{group:p,parentGroup:I,type:"group"}}return null}).filter(p=>!!p),h=[...g,...u];if(h.length===0)return null;const d=a.length===0,_=h.filter(p=>p.type==="component"?d||a.includes(p.component.pcb_component_id):d||c.has(p.group.pcb_group_id)||c.has(p.parentGroup.pcb_group_id));if(_.length===0)return null;const m=_.map(p=>{const I=p.parentGroup.anchor_position;return I?p.type==="component"?p.component.center?{id:`${p.parentGroup.pcb_group_id}-${p.component.pcb_component_id}-${p.type}`,anchor:I,anchor_id:p.parentGroup.pcb_group_id,target:p.component.center,type:"component",display_offset_x:p.component.display_offset_x,display_offset_y:p.component.display_offset_y}:null:p.group.anchor_position?{id:`${p.parentGroup.pcb_group_id}-${p.group.pcb_group_id}-${p.type}`,anchor:I,anchor_id:p.parentGroup.pcb_group_id,target:p.group.anchor_position,type:"group",display_offset_x:p.group.display_offset_x,display_offset_y:p.group.display_offset_y}:null:null}).filter(p=>!!p);return W.jsx(l9e,{targets:m,transform:n,containerWidth:o,containerHeight:i})},XYo=(t,e)=>{const n=t.pcb_component_id,o=e.filter(i=>(i.type==="pcb_smtpad"||i.type==="pcb_plated_hole")&&i.pcb_component_id===n||i.type==="pcb_hole"&&i.pcb_component_id===n);return o.length===0?i9e([t]):i9e(o)},$Yo=({elements:t,highlightedPrimitives:e,transform:n,containerWidth:o,containerHeight:i})=>{const r=new Map;for(const a of e)Uv(a._parent_pcb_component)&&r.set(a._parent_pcb_component.pcb_component_id,a._parent_pcb_component),Uv(a._element)&&r.set(a._element.pcb_component_id,a._element);if(r.size===0)return null;const s=[];for(const a of r.values()){const A=XYo(a,t);if(!A)continue;const c=a.positioned_relative_to_pcb_group_id??a.pcb_group_id,l=c?N6(t).pcb_group.get(c):null;s.push({component:a,bbox:A,group:l})}return s.length===0?null:W.jsx("div",{style:{position:"absolute",left:0,top:0,width:o,height:i,overflow:"hidden",pointerEvents:"none",zIndex:Yg.dimensionOverlay},children:W.jsx("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none"},width:o,height:i,children:s.map(({component:a,bbox:A,group:c})=>{const l=mt(n,{x:A.minX,y:A.maxY}),g=mt(n,{x:A.maxX,y:A.minY}),u={x:Math.min(l.x,g.x),y:Math.min(l.y,g.y),width:Math.abs(g.x-l.x),height:Math.abs(g.y-l.y)},h=a.center??{x:(A.minX+A.maxX)/2,y:(A.minY+A.maxY)/2},d=mt(n,h);return W.jsxs("g",{children:[W.jsx("rect",{x:u.x,y:u.y,width:u.width,height:u.height,fill:"none",stroke:"white",strokeWidth:1.5,strokeDasharray:"4,4"}),W.jsx("line",{x1:d.x-6,y1:d.y,x2:d.x+6,y2:d.y,stroke:X2.COMPONENT_MARKER_STROKE,strokeWidth:1.5}),W.jsx("line",{x1:d.x,y1:d.y-6,x2:d.x,y2:d.y+6,stroke:X2.COMPONENT_MARKER_STROKE,strokeWidth:1.5}),W.jsx("circle",{cx:d.x,cy:d.y,r:yu.COMPONENT_MARKER_RADIUS,fill:X2.COMPONENT_MARKER_FILL,stroke:X2.COMPONENT_MARKER_STROKE,strokeWidth:1})]},a.pcb_component_id)})})})},ZYo=({elements:t,highlightedPrimitives:e,transform:n,containerWidth:o,containerHeight:i})=>{const r=t.filter(h=>qYo(h)),s=t.filter(h=>c9e(h)),a=e.map(h=>c9e(h._element)?h._element.pcb_board_id:null).filter(h=>!!h);if(!Cd(h=>h.is_showing_group_anchor_offsets)&&a.length===0)return null;const c=s.map(h=>{const d=h.pcb_panel_id,_=h.position_mode;if(!d||_!=="relative_to_panel_anchor")return null;const m=r.find(p=>p.pcb_panel_id===d);return m?{board:h,panel:m,type:"board"}:null}).filter(h=>!!h);if(c.length===0)return null;const l=a.length===0,g=c.filter(h=>l||a.includes(h.board.pcb_board_id));if(g.length===0)return null;const u=g.map(h=>h.board.center?{id:`${h.panel.pcb_panel_id}-${h.board.pcb_board_id}-${h.type}`,anchor:h.panel.center,anchor_id:h.panel.pcb_panel_id,target:h.board.center,type:"board",display_offset_x:h.board.display_offset_x,display_offset_y:h.board.display_offset_y}:null).filter(h=>!!h);return W.jsx(l9e,{targets:u,transform:n,containerWidth:o,containerHeight:i})},Nse=t=>t?.trim()||null;function OLt({primitiveElement:t,elements:e}){const n=t.source_trace_id;if(!n)return null;const o=N6(e),i=o.source_trace.get(n),r=Nse(i?.name);if(r)return r;const s=o.source_net.get(n),a=Nse(s?.name);if(a)return a;for(const A of i?.connected_source_net_ids??[]){const c=Nse(o.source_net.get(A)?.name);if(c)return c}return null}function ezo({primitiveElement:t,elements:e}){const n=N6(e).source_trace.get(t?.source_trace_id),o=t.trace_length,i=typeof o=="number",r=n?.max_length,s=i?`${o.toFixed(3)}${typeof r=="number"?` / ${r}`:""} mm`:"",a=OLt({primitiveElement:t,elements:e})??Nse(n?.display_name);if(!s&&!a)return null;const A=!!(i&&typeof r=="number"&&o>r);return{text:s,name:a,isOverLength:A}}function tzo(t){const{primitives:e,is_showing_multiple_traces_length:n,elements:o}=t,i=e.filter(A=>A._element.type==="pcb_trace"),r=o.filter(A=>A.type==="source_trace"),s=e.filter(A=>A._element.type!=="pcb_trace"),a=i.filter(A=>r.some(l=>A._element.source_trace_id===l.source_trace_id&&l.max_length!==void 0)||OLt({primitiveElement:A._element,elements:o})!==null);if(!n)return[...s,...a];if(i.length>1){const A=i.reduce((c,l)=>{const g=c._element.trace_length;return l._element.trace_length<g?l:c},i[0]);return[...s,A]}return e}var nzo={position:"absolute",left:0,top:0,pointerEvents:"none",color:"red",fontFamily:"sans-serif",fontSize:12,textShadow:"0 0 2px black"},ozo=t=>{const{_element:e,_parent_pcb_component:n,_parent_source_component:o,_source_port:i}=t;switch(e.type){case"pcb_trace":return e.trace_length?`${e.trace_length.toFixed(3)}`:"";case"pcb_smtpad":case"pcb_plated_hole":{const r=[],s=Array.from(new Set((e.port_hints??[]).concat(i?.port_hints??[]))).filter(A=>!/^[0-9]+$/.test(A)).filter(A=>!A.includes("unnamed_")).sort((A,c)=>c.localeCompare(A)),a=o&&"name"in o&&o.name&&!o.name.includes("unnamed_")?o.name:null;return s.length>0?a?r.push(...s.map(A=>`${a}.${A}`)):r.push(...s):a&&r.push(a),r.join(", ")}default:return""}},izo={top:"red",bottom:"aqua"},rzo=({primitive:t,mousePos:e,elements:n})=>{const[o,i]=Z.useState(!1),r=t._element;Z.useEffect(()=>{setTimeout(()=>{i(!0)},100)},[]);const[s,a,A,c]=[t.screen_x,t.screen_y,t.screen_w,t.screen_h],l=t.same_space_index??0,g=26,u=izo[t?._element?.layer]??"red";let h=0;if(r.type==="pcb_smtpad"&&r?.shape==="rotated_rect"?h=r?.ccw_rotation??0:(r.type==="pcb_smtpad"&&(r?.shape==="pill"||r?.shape==="rotated_pill")&&"ccw_rotation"in t||r.type==="pcb_plated_hole"&&(r?.shape==="pill"||r?.shape==="oval")&&"ccw_rotation"in t)&&(h=r.ccw_rotation??0),r.type==="pcb_trace"){const m=ezo({primitiveElement:r,elements:n});return m?W.jsx("div",{style:{zIndex:Yg.elementOverlay,position:"absolute",left:e.x+12,top:e.y+12,color:u,pointerEvents:"none"},children:W.jsxs("div",{style:{backgroundColor:"#f2efcc",color:m.isOverLength?"red":"black",textShadow:"none",WebkitFontSmoothing:"antialiased",MozOsxFontSmoothing:"grayscale",padding:"4px 6px",borderRadius:"4px",fontSize:"11px",lineHeight:1.2,textAlign:"left",whiteSpace:"nowrap"},children:[m.text&&W.jsx("div",{children:m.text}),m.name&&W.jsx("div",{style:{marginTop:m.text?"2px":0},children:m.name})]})}):null}const d=ozo(t);return d.trim().length===0?null:W.jsx("div",{style:{zIndex:Yg.elementOverlay,position:"absolute",left:s-A/2-8,top:a-c/2-8,width:A+16,height:c+16,color:u,transform:`rotate(${-h}deg)`,transformOrigin:"center center"},children:W.jsx("div",{style:{width:o?`calc(100% + ${g*2*l}px)`:"100%",height:o?`calc(100% + ${g*2*l}px)`:"100%",marginLeft:o?`${-g*l}px`:0,marginTop:o?`${-g*l}px`:0,border:`1px solid ${u}`,opacity:o||l===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:c+20+g*l,marginRight:o?`${-g*l}px`:0,marginBottom:o?0:-g*l,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(${h}deg)`,minWidth:"45px",textAlign:"center"},children:d})})})},szo=({highlightedPrimitives:t,mousePos:e,elements:n})=>{const[o,i]=Cd(a=>[a.is_moving_component,a.is_showing_multiple_traces_length]),r=t.some(a=>a._element.type==="pcb_smtpad")&&t.some(a=>a._element.type==="pcb_trace");let s=t;return r&&(s=s.filter(a=>a._element.type==="pcb_smtpad")),s=tzo({primitives:s,is_showing_multiple_traces_length:i,elements:n}),W.jsx("div",{style:nzo,children:!o&&s.map(a=>W.jsx(rzo,{primitive:a,mousePos:e,elements:n},a._pcb_drawing_object_id))})},Rse=t=>{if(t.length===0)return null;let e=t[0].x,n=t[0].y,o=t[0].x,i=t[0].y;for(const r of t)r.x<e&&(e=r.x),r.y<n&&(n=r.y),r.x>o&&(o=r.x),r.y>i&&(i=r.y);return{center:{x:(e+o)/2,y:(n+i)/2},width:o-e,height:i-n}},KLt=(t,e)=>{if(e.length<3)return!1;let n=!1;for(let o=0,i=e.length-1;o<e.length;i=o++){const r=e[o].x,s=e[o].y,a=e[i].x,A=e[i].y;s>t.y!=A>t.y&&t.x<(a-r)*(t.y-s)/(A-s||Number.EPSILON)+r&&(n=!n)}return n},azo=(t,e,n,o)=>{const i=[];for(const r of t){if(!r._element||r._element.type==="pcb_trace"&&r.layer!==o)continue;if("x1"in r&&r._element?.type==="pcb_trace"){const A=_m({x:e.x,y:e.y},{x:r.x1,y:r.y1},{x:r.x2,y:r.y2}),c=r.width||.5,l=Math.max(c*25,2)/n.a;A<l&&i.push(r);continue}if(r.pcb_drawing_type==="polygon"){const A=r.points.map(l=>({x:En.parse(l.x),y:En.parse(l.y)})),c=Rse(A);if(!c||e.x<c.center.x-c.width/2||e.x>c.center.x+c.width/2||e.y<c.center.y-c.height/2||e.y>c.center.y+c.height/2)continue;KLt(e,A)&&i.push(r);continue}if(r.pcb_drawing_type==="polygon_with_arcs"){const A=r.brep_shape.outer_ring.vertices.map(l=>({x:En.parse(l.x),y:En.parse(l.y)})),c=Rse(A);if(!c||e.x<c.center.x-c.width/2||e.x>c.center.x+c.width/2||e.y<c.center.y-c.height/2||e.y>c.center.y+c.height/2)continue;KLt(e,A)&&i.push(r);continue}if(!("x"in r&&"y"in r))continue;let s=0,a=0;if("w"in r&&"h"in r)s=r.w,a=r.h;else if("r"in r)s=r.r*2,a=r.r*2;else if("rX"in r&&"rY"in r)s=r.rX*2,a=r.rY*2;else continue;Math.abs(r.x-e.x)<s/2&&Math.abs(r.y-e.y)<a/2&&i.push(r)}return i},Azo=({elements:t,children:e,transform:n,primitives:o,selectedLayer:i,onMouseHoverOverPrimitives:r})=>{const[s,a]=Z.useState([]),[A,c]=Z.useState({x:0,y:0}),[l,{width:g,height:u}]=pY();Z.useEffect(()=>{a([]),r([])},[i,r]);const h=Z.useMemo(()=>{const _=[];for(const m of s){if(m._element?.type==="pcb_via"||m._element?.type==="pcb_component"||m?.layer==="drill"||m?.is_hoverable===!1)continue;let p=null,I=0,f=0;if(m.pcb_drawing_type==="polygon"){const B=Rse(m.points);if(!B)continue;p=B.center,I=B.width,f=B.height}else if(m.pcb_drawing_type==="polygon_with_arcs"){const B=m.brep_shape.outer_ring.vertices.map(b=>({x:b.x,y:b.y})),Q=Rse(B);if(!Q)continue;p=Q.center,I=Q.width,f=Q.height}else m.pcb_drawing_type==="line"?(p={x:(m.x1+m.x2)/2,y:(m.y1+m.y2)/2},I=Math.abs(m.x2-m.x1),f=Math.abs(m.y2-m.y1)):"x"in m&&"y"in m&&(p={x:m.x,y:m.y},I="w"in m?m.w:"r"in m?m.r*2:"rX"in m&&"rY"in m?m.rX*2:0,f="h"in m?m.h:"r"in m?m.r*2:"rX"in m&&"rY"in m?m.rY*2:0);if(!p)continue;const C=mt(n,p),y={w:I*n.a,h:f*n.a},E=_.filter(B=>C.x===B.screen_x&&C.y===B.screen_y&&y.w===B.screen_w&&y.h===B.screen_h).length;_.push({...m,x:p.x,y:p.y,w:I,h:f,screen_x:C.x,screen_y:C.y,screen_w:y.w,screen_h:y.h,same_space_index:E})}return _},[s,n]),d=(_,m,p,I)=>{c({x:_,y:m});const f=mt(QQ(p),{x:_,y:m}),C=azo(I,f,p,i);JYo(new Set(C.map(y=>y._pcb_drawing_object_id)),new Set(s.map(y=>y._pcb_drawing_object_id)))||(a(C),r(C))};return W.jsxs("div",{ref:l,style:{position:"relative",width:"100%",height:"100%"},onMouseMove:_=>{if(n){const m=_.currentTarget.getBoundingClientRect(),p=_.clientX-m.left,I=_.clientY-m.top;d(p,I,n,o)}},onTouchStart:_=>{if(n){const m=_.touches[0],p=_.currentTarget.getBoundingClientRect(),I=m.clientX-p.left,f=m.clientY-p.top;d(I,f,n,o)}},children:[e,W.jsx(szo,{elements:t,mousePos:A,highlightedPrimitives:h}),n&&W.jsxs(W.Fragment,{children:[W.jsx(WYo,{elements:t,highlightedPrimitives:h,transform:n,containerWidth:g,containerHeight:u}),W.jsx(jYo,{elements:t,highlightedPrimitives:h,transform:n,containerWidth:g,containerHeight:u}),W.jsx($Yo,{elements:t,highlightedPrimitives:h,transform:n,containerWidth:g,containerHeight:u}),W.jsx(ZYo,{elements:t,highlightedPrimitives:h,transform:n,containerWidth:g,containerHeight:u})]})]})},ULt=["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)"],czo=({children:t,transform:e=Ll(),elements:n=[],hoveredComponentIds:o=[]})=>{const[i,{width:r,height:s}]=pY(),a=Z.useRef(null),{is_showing_pcb_groups:A,pcb_group_view_mode:c,is_showing_group_anchor_offsets:l}=Cd(g=>({is_showing_pcb_groups:g.is_showing_pcb_groups,pcb_group_view_mode:g.pcb_group_view_mode,is_showing_group_anchor_offsets:g.is_showing_group_anchor_offsets}));return Z.useEffect(()=>{const g=a.current;if(!g||!r||!s)return;g.width=r,g.height=s;const u=g.getContext("2d");if(!u||(u.clearRect(0,0,r,s),!A))return;const h=n.filter(E=>E.type==="pcb_group"),d=n.filter(E=>E.type==="pcb_component"),_=n.filter(E=>E.type==="source_group"),m=new Map(_.map(E=>[E.source_group_id,E])),p=h.filter(E=>{if(E.name?.toLowerCase().includes("subpanel"))return!1;if(c==="all")return!0;if(!E.source_group_id)return!1;const B=m.get(E.source_group_id);return B?B.was_automatically_named!==!0:!1}),I=new Map;_.forEach(E=>{const B=E;if(B.parent_source_group_id){const Q=I.get(B.parent_source_group_id)||[];Q.push(E.source_group_id),I.set(B.parent_source_group_id,Q)}});const f=E=>{const B=[],Q=I.get(E)||[];for(const b of Q)B.push(b),B.push(...f(b));return B},C=E=>{const B=_.find(Q=>Q.source_group_id===E);return B?.parent_source_group_id?1+C(B.parent_source_group_id):0},y=new Set;if(o.length>0)for(const E of d){if(!o.includes(E.pcb_component_id))continue;const B=E.positioned_relative_to_pcb_group_id??E.pcb_group_id;B&&y.add(B)}p.forEach((E,B)=>{let Q=d.filter(Le=>Le.pcb_group_id===E.pcb_group_id);if(E.source_group_id){const Le=f(E.source_group_id),Ve=h.filter(Ne=>Ne.source_group_id&&Le.includes(Ne.source_group_id));for(const Ne of Ve){const be=d.filter(Oe=>Oe.pcb_group_id===Ne.pcb_group_id);Q=[...Q,...be]}}let b,D,R,w,H=!1;if(E.center&&E.width&&E.height){H=!0;const Le=E.width/2,Ve=E.height/2;b=E.center.x-Le,R=E.center.x+Le,D=E.center.y-Ve,w=E.center.y+Ve}else if(Q.length===0||(b=1/0,D=1/0,R=-1/0,w=-1/0,Q.forEach(Le=>{if(Le.center&&typeof Le.width=="number"&&typeof Le.height=="number"){const Ve=Le.center.x-Le.width/2,Ne=Le.center.x+Le.width/2,be=Le.center.y+Le.height/2,Oe=Le.center.y-Le.height/2;b=Math.min(b,Ve),R=Math.max(R,Ne),D=Math.min(D,Oe),w=Math.max(w,be)}}),b===1/0||R===-1/0))return;const G=E.source_group_id?C(E.source_group_id):0,K=E.source_group_id?f(E.source_group_id).length>0:!1;if(!H){const Ne=1+(K?.5:0);b-=Ne,R+=Ne,D-=Ne,w+=Ne}const U=mt(e,{x:b,y:w}),q=mt(e,{x:R,y:w}),j=mt(e,{x:b,y:D}),ne=mt(e,{x:R,y:D}),re=ULt[B%ULt.length];u.strokeStyle=re,u.lineWidth=2;const X=Math.max(4,Math.min(12,8*Math.abs(e.a))),te=Math.max(2,Math.min(6,4*Math.abs(e.a))),Ae=X*(K?1.3:1),ue=te;u.setLineDash([Ae,ue]),u.beginPath(),u.moveTo(U.x,U.y),u.lineTo(q.x,q.y),u.lineTo(ne.x,ne.y),u.lineTo(j.x,j.y),u.closePath(),u.stroke();const Ce=Math.max(8,Math.min(12,10*Math.abs(e.a))),Ee=G==0||G==1?0:G*.11,Be=Ce*(1-Ee),he=4,ye=E.name||`Group ${B+1}`;u.font=`${Be}px sans-serif`,u.setLineDash([]);const Pe=u.measureText(ye).width+he*2,we=Be+he*2,Je=U.x-5,Ie=U.y-5,We=3;if(u.fillStyle="rgba(0, 0, 0, 0.8)",u.beginPath(),u.roundRect(Je,Ie-we,Pe,we,We),u.fill(),u.fillStyle=re,u.textAlign="left",u.textBaseline="middle",u.fillText(ye,Je+he,Ie-we/2),l&&y.has(E.pcb_group_id)&&!!E.anchor_position&&E.anchor_position){const Le=Array.isArray(E.anchor_position)?{x:E.anchor_position[0]??0,y:E.anchor_position[1]??0}:{x:E.anchor_position.x,y:E.anchor_position.y},Ve=mt(e,Le);u.strokeStyle="white",u.lineWidth=1.5,u.setLineDash([]);const Ne=Math.max(4,Math.min(8,6*Math.abs(e.a)));u.beginPath(),u.moveTo(Ve.x-Ne,Ve.y),u.lineTo(Ve.x+Ne,Ve.y),u.stroke(),u.beginPath(),u.moveTo(Ve.x,Ve.y-Ne),u.lineTo(Ve.x,Ve.y+Ne),u.stroke()}})},[n,e,r,s,A,c,l,o]),W.jsxs("div",{ref:i,style:{position:"relative",width:"100%",height:"100%"},children:[t,W.jsx("canvas",{ref:a,style:{position:"absolute",top:0,left:0,pointerEvents:"none",zIndex:Yg.pcbGroupOverlay,display:A?"block":"none"}})]})},lzo=({transform:t,soup:e,children:n})=>{const o=Cd(a=>a.is_showing_rats_nest),{netMap:i,idToNetMap:r}=Z.useMemo(()=>dLt(e||[]),[e]),s=Z.useMemo(()=>{if(!e||!o)return[];const a=u=>{const h=N6(e)[u.replace(/_\d+$/,"")].get(u);return h&&"x"in h&&"y"in h?{x:h.x,y:h.y}:null},A=(u,h)=>{const d=i[h]||[];let _=null,m=1/0;return d.forEach(p=>{const I=a(p);if(I){const f=Math.sqrt((u.x-I.x)**2+(u.y-I.y)**2);f<m&&f>0&&(m=f,_=I)}}),_},c=N6(e).pcb_port.list(),l=N6(e).source_trace.list(),g=[];return c.forEach((u,h)=>{const d=r[u.pcb_port_id];let _=!1;for(const I of l)I.connected_source_port_ids.includes(u.source_port_id)&&I.connected_source_net_ids.length>0&&(_=!0);if(!d)return;const m={x:u.x,y:u.y},p=A(m,d);p&&g.push({key:`${u.pcb_port_id}-${h}`,startPoint:m,endPoint:p,isInNet:_})}),g},[e,i,r,o]);return!e||!o?n:(t||(t=Ll()),W.jsxs("div",{style:{position:"relative"},children:[n,W.jsx("svg",{style:{position:"absolute",left:0,top:0,width:"100%",height:"100%",pointerEvents:"none",opacity:.5,zIndex:Yg.ratsNestOverlay},children:s.map(({key:a,startPoint:A,endPoint:c,isInNet:l})=>{const g=mt(t,A),u=mt(t,c);return W.jsx("line",{x1:g.x,y1:g.y,x2:u.x,y2:u.y,stroke:"white",strokeWidth:"1",strokeDasharray:l?"6,6":void 0},a)})})]}))},gzo={version:"1.11.387"},rb=(t,e,n)=>{const o=Cd(s=>s.is_mouse_over_container),i=Z.useRef(o),r=Z.useRef(e);Z.useEffect(()=>{i.current=o},[o]),Z.useEffect(()=>{r.current=e},[e]),Z.useEffect(()=>{if(!t)return;const s=a=>{const A=a.target;if(A.tagName==="INPUT"||A.tagName==="TEXTAREA"||A.isContentEditable)return;const c=t.split("+"),l=c.includes("ctrl"),g=c.includes("shift"),u=c.includes("alt"),h=c.includes("meta"),d=c[c.length-1],_=n?.current?n.current.contains(document.activeElement)||document.activeElement===n.current:!1;(i.current||_)&&(!l||a.ctrlKey)&&(!g||a.shiftKey)&&(!u||a.altKey)&&(!h||a.metaKey)&&a.key.toLowerCase()===d.toLowerCase()&&(a.preventDefault(),r.current())};return window.addEventListener("keydown",s),()=>{window.removeEventListener("keydown",s)}},[t])},uzo=()=>{const[t,e]=Z.useState(!1);return Z.useEffect(()=>{const n=()=>{e(window.innerWidth<=768)};return n(),window.addEventListener("resize",n),()=>window.removeEventListener("resize",n)},[]),t},fY=(t,e={stopPropagation:!0})=>{const n=Z.useRef(0),o=Z.useCallback(s=>{e.stopPropagation&&s.stopPropagation();const a=Date.now();a-n.current<300||(n.current=a,t?.(s))},[t,e.stopPropagation]),i=Z.useCallback(s=>{s.preventDefault(),o(s)},[o]);return{onClick:o,onTouchEnd:i,style:{touchAction:"manipulation"}}},Qk=({children:t,isSmallScreen:e,onClick:n,...o})=>{const{style:i,...r}=fY(n);return W.jsx("div",{...o,...r,style:{backgroundColor:"#1F1F1F",border:"1px solid #666",margin:0,padding:4,paddingLeft:e?8:6,paddingRight:e?8:6,borderRadius:2,color:"#eee",cursor:"pointer",fontSize:12,height:"fit-content",userSelect:"none",whiteSpace:"nowrap",...i,...o.style},children:t})},dzo=t=>{const e=new Map;return t.forEach((n,o)=>{const i=n.error_type||"unknown_error",r=e.get(i)||[];r.push({error:n,index:o,errorId:Bk(n,o)}),e.set(i,r)}),Array.from(e.entries()).map(([n,o])=>({errorType:n,errors:o}))},hzo=({onClose:t,setHoveredErrorId:e,setFocusedErrorId:n,highlightDurationMs:o=3e3})=>{const i=Z.useRef(null),r=Z.useRef(null),s=Z.useRef(null),a=Z.useCallback(()=>{i.current!==null&&(window.clearTimeout(i.current),i.current=null),r.current!==null&&(window.cancelAnimationFrame(r.current),r.current=null)},[]);Z.useEffect(()=>a,[a]);const A=Z.useCallback(l=>{a(),s.current=l,e(l),n(null),r.current=window.requestAnimationFrame(()=>{n(l),r.current=null}),t(),i.current=window.setTimeout(()=>{s.current=null,e(null),n(null),i.current=null},o)},[a,o,t,n,e]),c=Z.useCallback(l=>s.current===l,[]);return{handleErrorSelect:A,isSelectedError:c}},_zo=({errorId:t,errorMessage:e,copiedErrorId:n,onCopy:o})=>{const{style:i,...r}=fY(()=>o(e,t));return W.jsx("button",{type:"button","aria-label":n===t?"Error message copied":"Copy error message",style:{position:"absolute",top:12,right:16,cursor:"pointer",color:"#888",fontSize:16,background:"none",border:"none",padding:0,display:"flex",alignItems:"center",...i},...r,children:n===t?W.jsx("span",{style:{color:"#4caf50",fontSize:12},children:"Copied!"}):W.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"currentColor",children:W.jsx("path",{d:"M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z"})})})},mzo=({elements:t,isOpen:e,isSmallScreen:n,onToggle:o,onClose:i,setHoveredErrorId:r,setFocusedErrorId:s})=>{const[a,A]=Z.useState(null),[c,l]=Z.useState(new Set),[g,u]=Z.useState(new Set),[,h]=ZKo(),{handleErrorSelect:d,isSelectedError:_}=hzo({onClose:i,setHoveredErrorId:r,setFocusedErrorId:s}),m=Z.useMemo(()=>t?.filter(y=>y.type.includes("error"))??[],[t]),p=m.length,I=Z.useMemo(()=>dzo(m),[m]),f=Z.useCallback(y=>{l(E=>{const B=new Set(E);return B.has(y)?B.delete(y):B.add(y),B})},[]),C=Z.useCallback(y=>{u(E=>{const B=new Set(E);return B.has(y)?B.delete(y):B.add(y),B})},[]);return W.jsxs("div",{style:{position:"relative"},children:[W.jsx(Qk,{isSmallScreen:n,style:p>0?{color:"red"}:void 0,onClick:o,children:W.jsxs("div",{children:[p," errors"]})}),e&&p>0&&W.jsx("div",{style:{position:"absolute",top:"100%",left:0,backgroundColor:"#2a2a2a",border:"1px solid #666",borderRadius:4,marginTop:4,zIndex:1e3,minWidth:n?"280px":"400px",maxWidth:n?"90vw":"600px",maxHeight:"400px",overflow:"auto",boxShadow:"0 4px 12px rgba(0, 0, 0, 0.3)"},children:I.map(({errorType:y,errors:E},B)=>{const Q=c.has(y);return W.jsxs("div",{style:{borderBottom:B<I.length-1?"1px solid #444":"none"},children:[W.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 16px",cursor:"pointer",backgroundColor:"#232323",transition:"background-color 0.2s ease",touchAction:"manipulation",position:"sticky",top:0,zIndex:1},onMouseEnter:b=>{b.currentTarget.style.backgroundColor="#303030"},onMouseLeave:b=>{b.currentTarget.style.backgroundColor="#232323"},onTouchStart:b=>{b.stopPropagation(),b.currentTarget.style.backgroundColor="#303030"},onTouchEnd:b=>{b.stopPropagation(),b.preventDefault(),b.currentTarget.style.backgroundColor="#232323",f(y)},onClick:b=>{b.stopPropagation(),f(y)},children:[W.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,color:"#ff6b6b"},children:[W.jsx("div",{style:{color:"#888",fontSize:"16px",transform:Q?"rotate(90deg)":"rotate(0deg)",transition:"transform 0.2s ease",flexShrink:0},children:"›"}),W.jsx("div",{style:{fontWeight:"bold",fontSize:n?"12px":"13px"},children:y})]}),W.jsx("div",{style:{fontSize:n?"12px":"13px",color:"#aaa",whiteSpace:"nowrap",marginLeft:12},children:E.length})]}),!Q&&E.map(({error:b,index:D,errorId:R})=>{const w=g.has(R),H=b.message??"No error message";return W.jsxs("div",{style:{borderTop:"1px solid #3a3a3a"},children:[W.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12,padding:"12px 16px 12px 24px",cursor:"pointer",backgroundColor:"#2a2a2a",transition:"background-color 0.2s ease",touchAction:"manipulation"},onMouseEnter:G=>{G.currentTarget.style.backgroundColor="#333",r(R)},onMouseLeave:G=>{G.currentTarget.style.backgroundColor="#2a2a2a",_(R)||r(null)},onTouchStart:G=>{G.stopPropagation(),G.currentTarget.style.backgroundColor="#333",r(R)},onTouchEnd:G=>{G.stopPropagation(),G.preventDefault(),G.currentTarget.style.backgroundColor="#2a2a2a",d(R)},onClick:G=>{G.stopPropagation(),d(R)},children:[W.jsx("div",{style:{flex:1,fontSize:n?"12px":"13px",color:"#ddd",lineHeight:1.4,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",userSelect:"text"},children:H}),W.jsx("button",{type:"button","aria-label":w?"Collapse error details":"Expand error details",style:{color:"#888",fontSize:"16px",transform:w?"rotate(0deg)":"rotate(90deg)",transition:"transform 0.2s ease",flexShrink:0,background:"none",border:"none",padding:0,cursor:"pointer"},onMouseDown:G=>G.stopPropagation(),onClick:G=>{G.stopPropagation(),C(R)},onTouchEnd:G=>{G.stopPropagation(),G.preventDefault(),C(R)},children:"›"})]}),w&&W.jsxs("div",{"data-error-id":D,style:{display:"block",padding:"12px 16px 12px 24px",backgroundColor:"#1a1a1a",borderTop:"1px solid #444",position:"relative"},children:[W.jsx("div",{style:{fontSize:n?"11px":"12px",color:"#ccc",lineHeight:1.5,wordWrap:"break-word",overflowWrap:"break-word",hyphens:"auto",userSelect:"text",paddingRight:30},onMouseDown:G=>G.stopPropagation(),onClick:G=>G.stopPropagation(),children:H}),W.jsx(_zo,{errorId:R,errorMessage:H,copiedErrorId:a,onCopy:(G,K)=>{h(G),A(K),setTimeout(()=>A(null),2e3)}})]})]},R)})]},y)})})]})},pzo=({name:t,selected:e,onClick:n})=>{const{style:o,...i}=fY(n);return W.jsxs("div",{className:Bse`
|
|
5697
|
+
`,VYo=({children:t,transform:e=Ll(),elements:n})=>{const o=Z.useRef(null),{isShowingDRCErrors:i,hoveredErrorId:r,focusedErrorId:s}=Cd(_=>({isShowingDRCErrors:_.is_showing_drc_errors,hoveredErrorId:_.hovered_error_id,focusedErrorId:_.focused_error_id})),a=s??r;if(!n)return W.jsx("div",{style:{position:"relative"},ref:o,children:t});const A=n.filter(_=>_.type==="pcb_trace_error"&&!_.message?.includes("Multiple components found with name")),c=n.filter(_=>_.type==="pcb_via_clearance_error"),l=n.filter(_=>_.type==="pcb_trace_error"&&_.message?.includes("Multiple components found with name")),g=hLt(n),u=ILt(n,a),h=_=>{const m=fUo({error:_,indexes:g});if(!m||typeof m.x!="number"||typeof m.y!="number")return null;const p=mt(e,m);return Number.isNaN(p.x)||Number.isNaN(p.y)?null:p};let d=null;return u&&(d=h(u)),W.jsxs("div",{style:{position:"relative"},ref:o,children:[t,A.map((_,m)=>{const p=Bk(_,m),I=a===p;if(!I&&!i)return null;const f=h(_);if(!f)return null;const C=a9e(f,o);return W.jsxs(Z.Fragment,{children:[W.jsx(HLt,{errorCenter:f,isHighlighted:I}),W.jsx("div",{style:{position:"absolute",left:f.x-15,top:f.y-15,width:30,height:30,zIndex:Yg.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:y=>{const E=y.currentTarget.nextElementSibling;if(E){const B=E.querySelector(".error-message");B&&(B.style.opacity="1")}},onMouseLeave:y=>{if(!I){const E=y.currentTarget.nextElementSibling;if(E){const B=E.querySelector(".error-message");B&&(B.style.opacity="0")}}}}),W.jsx("div",{style:{position:"absolute",zIndex:I?200:100,left:C.left,top:C.top,color:I?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:i||I?"flex":"none",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:C.transform},children:W.jsx("div",{className:`error-message ${A9e}`,style:{opacity:I?1:0,border:`1px solid ${I?"#ff4444":"red"}`},children:_.message})})]},p)}),c.map((_,m)=>{const p=Bk(_,m),I=a===p;if(!I&&!i)return null;const f=h(_);if(!f)return null;const C=a9e({x:f.x,y:f.y},o);return W.jsxs(Z.Fragment,{children:[W.jsx(HLt,{errorCenter:f,isHighlighted:I}),W.jsx("div",{style:{position:"absolute",left:f.x-15,top:f.y-15,width:30,height:30,zIndex:Yg.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:y=>{const E=y.currentTarget.nextElementSibling;if(E){const B=E.querySelector(".error-message");B&&(B.style.opacity="1")}},onMouseLeave:y=>{if(!I){const E=y.currentTarget.nextElementSibling;if(E){const B=E.querySelector(".error-message");B&&(B.style.opacity="0")}}}}),W.jsx("div",{style:{position:"absolute",zIndex:I?Yg.errorOverlay+10:Yg.errorOverlay+1,left:C.left,top:C.top,color:I?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:"flex",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:C.transform},children:W.jsx("div",{className:`error-message ${A9e}`,style:{opacity:I?1:0,border:`1px solid ${I?"#ff4444":"red"}`},children:_.message})})]},p)}),l.map((_,m)=>{const p=_.component_name||_.message?.match(/name "([^"]+)"/)?.[1];if(!p)return null;const I=n?.filter(y=>y.type==="source_component"&&y.name===p||y.type==="pcb_component"&&n?.find(E=>E.type==="source_component"&&E.source_component_id===y.source_component_id&&E.name===p))||[],f=Bk(_,m),C=a===f;return!C&&!i?null:I.map((y,E)=>{let B={x:0,y:0};if(y.type==="pcb_component")B=y.center||{x:0,y:0};else if(y.type==="source_component"){const K=n?.find(U=>U.type==="pcb_component"&&U.source_component_id===y.source_component_id);K&&K.type==="pcb_component"&&(B=K.center||{x:0,y:0})}const Q=mt(e,B);if(Number.isNaN(Q.x)||Number.isNaN(Q.y))return null;const b=Math.abs(e.a),H=Math.max(8,Math.min(30,.5*b)),G=a9e(Q,o);return W.jsxs(Z.Fragment,{children:[W.jsx("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none",mixBlendMode:"difference",zIndex:Yg.errorOverlay},width:"100%",height:"100%",children:C?W.jsx("polygon",{points:`${Q.x},${Q.y-H*1.25} ${Q.x+H},${Q.y} ${Q.x},${Q.y+H*1.25} ${Q.x-H},${Q.y}`,fill:"#ff4444"}):W.jsx("circle",{cx:Q.x,cy:Q.y,r:H,fill:"none",stroke:C?"#ff4444":"red",strokeWidth:C?Math.max(2,H*.15):Math.max(1,H*.1),opacity:1})}),W.jsx("div",{style:{position:"absolute",left:Q.x-(H+10),top:Q.y-(H+10),width:(H+10)*2,height:(H+10)*2,zIndex:Yg.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:K=>{const U=K.currentTarget.nextElementSibling;if(U){const q=U.querySelector(".error-message");q&&(q.style.opacity="1")}},onMouseLeave:K=>{if(!C){const U=K.currentTarget.nextElementSibling;if(U){const q=U.querySelector(".error-message");q&&(q.style.opacity="0")}}}}),W.jsx("div",{style:{position:"absolute",zIndex:C?Yg.errorOverlay+20:Yg.errorOverlay+10,left:G.left,top:G.top,color:C?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:i||C?"flex":"none",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:G.transform},children:W.jsx("div",{className:`error-message ${A9e}`,style:{opacity:C?1:0,border:`1px solid ${C?"#ff4444":"red"}`},children:_.message})})]},`${f}_${E}`)})}),d&&W.jsx(zYo,{center:d})]})};function JYo(t,e){return t.size!==e.size?!1:Array.from(t).every(n=>e.has(n))}var Uv=t=>t?.type==="pcb_component",GLt=t=>t?.type==="pcb_group",qYo=t=>t?.type==="pcb_panel",c9e=t=>t?.type==="pcb_board",yu={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},X2={OFFSET_LINE:"white",COMPONENT_MARKER_FILL:"#66ccff",COMPONENT_MARKER_STROKE:"white",LABEL_TEXT:"white"},l9e=({targets:t,transform:e,containerWidth:n,containerHeight:o})=>{if(t.length===0)return null;const i={color:X2.LABEL_TEXT,mixBlendMode:"difference",pointerEvents:"none",fontSize:yu.LABEL_FONT_SIZE,fontFamily:"monospace",fontWeight:"bold"},r=new Map;return t.forEach(s=>{if(!r.has(s.anchor_id)){const a=mt(e,s.anchor);r.set(s.anchor_id,a)}}),W.jsx("div",{style:{position:"absolute",left:0,top:0,width:n,height:o,overflow:"hidden",pointerEvents:"none",zIndex:Yg.dimensionOverlay},children:W.jsxs("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none"},width:n,height:o,children:[t.map(s=>{const a=s.anchor,A=s.anchor_id,c=s.target,l=r.get(A),g=mt(e,c),u=c.x-a.x,h=c.y-a.y,d=Math.abs(g.x-l.x),_=Math.abs(g.y-l.y),m=g.y<l.y,p=g.x>l.x,I=m?yu.LABEL_OFFSET_ABOVE:yu.LABEL_OFFSET_BELOW,f=p?yu.LABEL_OFFSET_RIGHT:yu.LABEL_OFFSET_LEFT,C=d>yu.MIN_LINE_LENGTH_FOR_LABEL,y=_>yu.MIN_LINE_LENGTH_FOR_LABEL,E=`${s.display_offset_x??u.toFixed(2)}mm`,B=`${s.display_offset_y??h.toFixed(2)}mm`;return W.jsxs("g",{children:[W.jsx("line",{x1:l.x,y1:l.y,x2:g.x,y2:l.y,stroke:X2.OFFSET_LINE,strokeWidth:yu.LINE_STROKE_WIDTH,strokeDasharray:yu.LINE_DASH_PATTERN}),W.jsx("line",{x1:g.x,y1:l.y,x2:g.x,y2:g.y,stroke:X2.OFFSET_LINE,strokeWidth:yu.LINE_STROKE_WIDTH,strokeDasharray:yu.LINE_DASH_PATTERN}),s.type==="component"||s.type==="board"?W.jsx("circle",{cx:g.x,cy:g.y,r:yu.COMPONENT_MARKER_RADIUS,fill:X2.COMPONENT_MARKER_FILL,stroke:X2.COMPONENT_MARKER_STROKE,strokeWidth:1}):W.jsxs(W.Fragment,{children:[W.jsx("line",{x1:g.x-yu.ANCHOR_MARKER_SIZE,y1:g.y,x2:g.x+yu.ANCHOR_MARKER_SIZE,y2:g.y,stroke:X2.OFFSET_LINE,strokeWidth:yu.ANCHOR_MARKER_STROKE_WIDTH}),W.jsx("line",{x1:g.x,y1:g.y-yu.ANCHOR_MARKER_SIZE,x2:g.x,y2:g.y+yu.ANCHOR_MARKER_SIZE,stroke:X2.OFFSET_LINE,strokeWidth:yu.ANCHOR_MARKER_STROKE_WIDTH})]}),C&&W.jsx("foreignObject",{x:Math.min(l.x,g.x),y:l.y+I,width:Math.abs(g.x-l.x),height:20,style:{overflow:"visible"},children:W.jsx("div",{style:{...i,textAlign:"center"},children:E})}),y&&W.jsx("foreignObject",{x:g.x+f,y:Math.min(l.y,g.y),width:yu.Y_LABEL_MIN_WIDTH,height:Math.abs(g.y-l.y),style:{overflow:"visible"},children:W.jsx("div",{style:{...i,display:"flex",alignItems:"center",justifyContent:p?"flex-start":"flex-end",whiteSpace:"nowrap",padding:"0 4px",height:"100%"},children:B})})]},s.id)}),Array.from(r.entries()).map(([s,a])=>W.jsxs("g",{children:[W.jsx("line",{x1:a.x-yu.ANCHOR_MARKER_SIZE,y1:a.y,x2:a.x+yu.ANCHOR_MARKER_SIZE,y2:a.y,stroke:X2.OFFSET_LINE,strokeWidth:yu.ANCHOR_MARKER_STROKE_WIDTH}),W.jsx("line",{x1:a.x,y1:a.y-yu.ANCHOR_MARKER_SIZE,x2:a.x,y2:a.y+yu.ANCHOR_MARKER_SIZE,stroke:X2.OFFSET_LINE,strokeWidth:yu.ANCHOR_MARKER_STROKE_WIDTH})]},`anchor-${s}`))]})})},WYo=({elements:t,highlightedPrimitives:e,transform:n,containerWidth:o,containerHeight:i})=>{const r=t.filter(p=>c9e(p)),s=t.filter(p=>Uv(p)),a=t.filter(p=>GLt(p)),A=e.map(p=>Uv(p._parent_pcb_component)?p._parent_pcb_component.pcb_component_id:Uv(p._element)?p._element.pcb_component_id:null).filter(p=>!!p),c=new Set;if(A.forEach(p=>{const I=s.find(f=>f.pcb_component_id===p);I?.pcb_group_id&&c.add(I.pcb_group_id)}),!Cd(p=>p.is_showing_group_anchor_offsets)&&A.length===0)return null;const g=s.map(p=>{const I=p.positioned_relative_to_pcb_board_id;if(!I)return null;const f=r.find(C=>C.pcb_board_id===I);return f?{component:p,board:f,type:"component"}:null}).filter(p=>!!p),u=a.map(p=>{const I=p.positioned_relative_to_pcb_board_id;if(!I||!p.center)return null;const f=r.find(C=>C.pcb_board_id===I);return f?{group:p,board:f,type:"group"}:null}).filter(p=>!!p),h=[...g,...u];if(h.length===0)return null;const d=A.length===0,_=h.filter(p=>p.type==="component"?d||A.includes(p.component.pcb_component_id):d||c.has(p.group.pcb_group_id));if(_.length===0)return null;const m=_.map(p=>p.type==="component"?{id:`${p.board.pcb_board_id}-${p.component.pcb_component_id}-${p.type}`,anchor:p.board.center,anchor_id:p.board.pcb_board_id,target:p.component.center,type:"component",display_offset_x:p.component.display_offset_x,display_offset_y:p.component.display_offset_y}:{id:`${p.board.pcb_board_id}-${p.group.pcb_group_id}-${p.type}`,anchor:p.board.center,anchor_id:p.board.pcb_board_id,target:{x:p.group.anchor_position?.x??p.group.center.x,y:p.group.anchor_position?.y??p.group.center.y},type:"group",display_offset_x:p.group.display_offset_x,display_offset_y:p.group.display_offset_y}).filter(p=>!!p);return W.jsx(l9e,{targets:m,transform:n,containerWidth:o,containerHeight:i})},jYo=({elements:t,highlightedPrimitives:e,transform:n,containerWidth:o,containerHeight:i})=>{const r=t.filter(p=>GLt(p)),s=t.filter(p=>Uv(p)),a=e.map(p=>Uv(p._parent_pcb_component)?p._parent_pcb_component.pcb_component_id:Uv(p._element)?p._element.pcb_component_id:null).filter(p=>!!p),A=(p,I)=>{if(I.has(p))return;I.add(p);const f=r.find(C=>C.pcb_group_id===p);f?.position_mode==="relative_to_group_anchor"&&f.positioned_relative_to_pcb_group_id&&A(f.positioned_relative_to_pcb_group_id,I)},c=new Set;if(a.forEach(p=>{const I=s.find(f=>f.pcb_component_id===p);I&&(I.position_mode==="relative_to_group_anchor"&&I.positioned_relative_to_pcb_group_id&&A(I.positioned_relative_to_pcb_group_id,c),I.pcb_group_id&&A(I.pcb_group_id,c))}),!Cd(p=>p.is_showing_group_anchor_offsets)&&a.length===0)return null;const g=s.map(p=>{if(p.position_mode==="relative_to_group_anchor"&&p.positioned_relative_to_pcb_group_id){const I=r.find(f=>f.pcb_group_id===p.positioned_relative_to_pcb_group_id);return I&&I.anchor_position?{component:p,parentGroup:I,type:"component"}:null}if(p.pcb_group_id){const I=r.find(f=>f.pcb_group_id===p.pcb_group_id);return I&&I.anchor_position?{component:p,parentGroup:I,type:"component"}:null}return null}).filter(p=>!!p),u=r.map(p=>{if(p.position_mode==="relative_to_group_anchor"&&p.positioned_relative_to_pcb_group_id){const I=r.find(f=>f.pcb_group_id===p.positioned_relative_to_pcb_group_id);if(I&&I.anchor_position&&p.anchor_position)return{group:p,parentGroup:I,type:"group"}}return null}).filter(p=>!!p),h=[...g,...u];if(h.length===0)return null;const d=a.length===0,_=h.filter(p=>p.type==="component"?d||a.includes(p.component.pcb_component_id):d||c.has(p.group.pcb_group_id)||c.has(p.parentGroup.pcb_group_id));if(_.length===0)return null;const m=_.map(p=>{const I=p.parentGroup.anchor_position;return I?p.type==="component"?p.component.center?{id:`${p.parentGroup.pcb_group_id}-${p.component.pcb_component_id}-${p.type}`,anchor:I,anchor_id:p.parentGroup.pcb_group_id,target:p.component.center,type:"component",display_offset_x:p.component.display_offset_x,display_offset_y:p.component.display_offset_y}:null:p.group.anchor_position?{id:`${p.parentGroup.pcb_group_id}-${p.group.pcb_group_id}-${p.type}`,anchor:I,anchor_id:p.parentGroup.pcb_group_id,target:p.group.anchor_position,type:"group",display_offset_x:p.group.display_offset_x,display_offset_y:p.group.display_offset_y}:null:null}).filter(p=>!!p);return W.jsx(l9e,{targets:m,transform:n,containerWidth:o,containerHeight:i})},XYo=(t,e)=>{const n=t.pcb_component_id,o=e.filter(i=>(i.type==="pcb_smtpad"||i.type==="pcb_plated_hole")&&i.pcb_component_id===n||i.type==="pcb_hole"&&i.pcb_component_id===n);return o.length===0?i9e([t]):i9e(o)},$Yo=({elements:t,highlightedPrimitives:e,transform:n,containerWidth:o,containerHeight:i})=>{const r=new Map;for(const a of e)Uv(a._parent_pcb_component)&&r.set(a._parent_pcb_component.pcb_component_id,a._parent_pcb_component),Uv(a._element)&&r.set(a._element.pcb_component_id,a._element);if(r.size===0)return null;const s=[];for(const a of r.values()){const A=XYo(a,t);if(!A)continue;const c=a.positioned_relative_to_pcb_group_id??a.pcb_group_id,l=c?N6(t).pcb_group.get(c):null;s.push({component:a,bbox:A,group:l})}return s.length===0?null:W.jsx("div",{style:{position:"absolute",left:0,top:0,width:o,height:i,overflow:"hidden",pointerEvents:"none",zIndex:Yg.dimensionOverlay},children:W.jsx("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none"},width:o,height:i,children:s.map(({component:a,bbox:A,group:c})=>{const l=mt(n,{x:A.minX,y:A.maxY}),g=mt(n,{x:A.maxX,y:A.minY}),u={x:Math.min(l.x,g.x),y:Math.min(l.y,g.y),width:Math.abs(g.x-l.x),height:Math.abs(g.y-l.y)},h=a.center??{x:(A.minX+A.maxX)/2,y:(A.minY+A.maxY)/2},d=mt(n,h);return W.jsxs("g",{children:[W.jsx("rect",{x:u.x,y:u.y,width:u.width,height:u.height,fill:"none",stroke:"white",strokeWidth:1.5,strokeDasharray:"4,4"}),W.jsx("line",{x1:d.x-6,y1:d.y,x2:d.x+6,y2:d.y,stroke:X2.COMPONENT_MARKER_STROKE,strokeWidth:1.5}),W.jsx("line",{x1:d.x,y1:d.y-6,x2:d.x,y2:d.y+6,stroke:X2.COMPONENT_MARKER_STROKE,strokeWidth:1.5}),W.jsx("circle",{cx:d.x,cy:d.y,r:yu.COMPONENT_MARKER_RADIUS,fill:X2.COMPONENT_MARKER_FILL,stroke:X2.COMPONENT_MARKER_STROKE,strokeWidth:1})]},a.pcb_component_id)})})})},ZYo=({elements:t,highlightedPrimitives:e,transform:n,containerWidth:o,containerHeight:i})=>{const r=t.filter(h=>qYo(h)),s=t.filter(h=>c9e(h)),a=e.map(h=>c9e(h._element)?h._element.pcb_board_id:null).filter(h=>!!h);if(!Cd(h=>h.is_showing_group_anchor_offsets)&&a.length===0)return null;const c=s.map(h=>{const d=h.pcb_panel_id,_=h.position_mode;if(!d||_!=="relative_to_panel_anchor")return null;const m=r.find(p=>p.pcb_panel_id===d);return m?{board:h,panel:m,type:"board"}:null}).filter(h=>!!h);if(c.length===0)return null;const l=a.length===0,g=c.filter(h=>l||a.includes(h.board.pcb_board_id));if(g.length===0)return null;const u=g.map(h=>h.board.center?{id:`${h.panel.pcb_panel_id}-${h.board.pcb_board_id}-${h.type}`,anchor:h.panel.center,anchor_id:h.panel.pcb_panel_id,target:h.board.center,type:"board",display_offset_x:h.board.display_offset_x,display_offset_y:h.board.display_offset_y}:null).filter(h=>!!h);return W.jsx(l9e,{targets:u,transform:n,containerWidth:o,containerHeight:i})},Nse=t=>t?.trim()||null;function OLt({primitiveElement:t,elements:e}){const n=t.source_trace_id;if(!n)return null;const o=N6(e),i=o.source_trace.get(n),r=Nse(i?.name);if(r)return r;const s=o.source_net.get(n),a=Nse(s?.name);if(a)return a;for(const A of i?.connected_source_net_ids??[]){const c=Nse(o.source_net.get(A)?.name);if(c)return c}return null}function ezo({primitiveElement:t,elements:e}){const n=N6(e).source_trace.get(t?.source_trace_id),o=t.trace_length,i=typeof o=="number",r=n?.max_length,s=i?`${o.toFixed(3)}${typeof r=="number"?` / ${r}`:""} mm`:"",a=OLt({primitiveElement:t,elements:e})??Nse(n?.display_name);if(!s&&!a)return null;const A=!!(i&&typeof r=="number"&&o>r);return{text:s,name:a,isOverLength:A}}function tzo(t){const{primitives:e,is_showing_multiple_traces_length:n,elements:o}=t,i=e.filter(A=>A._element.type==="pcb_trace"),r=o.filter(A=>A.type==="source_trace"),s=e.filter(A=>A._element.type!=="pcb_trace"),a=i.filter(A=>r.some(l=>A._element.source_trace_id===l.source_trace_id&&l.max_length!==void 0)||OLt({primitiveElement:A._element,elements:o})!==null);if(!n)return[...s,...a];if(i.length>1){const A=i.reduce((c,l)=>{const g=c._element.trace_length;return l._element.trace_length<g?l:c},i[0]);return[...s,A]}return e}var nzo={position:"absolute",left:0,top:0,pointerEvents:"none",color:"red",fontFamily:"sans-serif",fontSize:12,textShadow:"0 0 2px black"},ozo=t=>{const{_element:e,_parent_pcb_component:n,_parent_source_component:o,_source_port:i}=t;switch(e.type){case"pcb_trace":return e.trace_length?`${e.trace_length.toFixed(3)}`:"";case"pcb_smtpad":case"pcb_plated_hole":{const r=[],s=Array.from(new Set((e.port_hints??[]).concat(i?.port_hints??[]))).filter(A=>!/^[0-9]+$/.test(A)).filter(A=>!A.includes("unnamed_")).sort((A,c)=>c.localeCompare(A)),a=o&&"name"in o&&o.name&&!o.name.includes("unnamed_")?o.name:null;return s.length>0?a?r.push(...s.map(A=>`${a}.${A}`)):r.push(...s):a&&r.push(a),r.join(", ")}default:return""}},izo={top:"red",bottom:"aqua"},rzo=({primitive:t,mousePos:e,elements:n})=>{const[o,i]=Z.useState(!1),r=t._element;Z.useEffect(()=>{setTimeout(()=>{i(!0)},100)},[]);const[s,a,A,c]=[t.screen_x,t.screen_y,t.screen_w,t.screen_h],l=t.same_space_index??0,g=26,u=izo[t?._element?.layer]??"red";let h=0;if(r.type==="pcb_smtpad"&&r?.shape==="rotated_rect"?h=r?.ccw_rotation??0:(r.type==="pcb_smtpad"&&(r?.shape==="pill"||r?.shape==="rotated_pill")&&"ccw_rotation"in t||r.type==="pcb_plated_hole"&&(r?.shape==="pill"||r?.shape==="oval")&&"ccw_rotation"in t)&&(h=r.ccw_rotation??0),r.type==="pcb_trace"){const m=ezo({primitiveElement:r,elements:n});return m?W.jsx("div",{style:{zIndex:Yg.elementOverlay,position:"absolute",left:e.x+12,top:e.y+12,color:u,pointerEvents:"none"},children:W.jsxs("div",{style:{backgroundColor:"#f2efcc",color:m.isOverLength?"red":"black",textShadow:"none",WebkitFontSmoothing:"antialiased",MozOsxFontSmoothing:"grayscale",padding:"4px 6px",borderRadius:"4px",fontSize:"11px",lineHeight:1.2,textAlign:"left",whiteSpace:"nowrap"},children:[m.text&&W.jsx("div",{children:m.text}),m.name&&W.jsx("div",{style:{marginTop:m.text?"2px":0},children:m.name})]})}):null}const d=ozo(t);return d.trim().length===0?null:W.jsx("div",{style:{zIndex:Yg.elementOverlay,position:"absolute",left:s-A/2-8,top:a-c/2-8,width:A+16,height:c+16,color:u,transform:`rotate(${-h}deg)`,transformOrigin:"center center"},children:W.jsx("div",{style:{width:o?`calc(100% + ${g*2*l}px)`:"100%",height:o?`calc(100% + ${g*2*l}px)`:"100%",marginLeft:o?`${-g*l}px`:0,marginTop:o?`${-g*l}px`:0,border:`1px solid ${u}`,opacity:o||l===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:c+20+g*l,marginRight:o?`${-g*l}px`:0,marginBottom:o?0:-g*l,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(${h}deg)`,minWidth:"45px",textAlign:"center"},children:d})})})},szo=({highlightedPrimitives:t,mousePos:e,elements:n})=>{const[o,i]=Cd(a=>[a.is_moving_component,a.is_showing_multiple_traces_length]),r=t.some(a=>a._element.type==="pcb_smtpad")&&t.some(a=>a._element.type==="pcb_trace");let s=t;return r&&(s=s.filter(a=>a._element.type==="pcb_smtpad")),s=tzo({primitives:s,is_showing_multiple_traces_length:i,elements:n}),W.jsx("div",{style:nzo,children:!o&&s.map(a=>W.jsx(rzo,{primitive:a,mousePos:e,elements:n},a._pcb_drawing_object_id))})},Rse=t=>{if(t.length===0)return null;let e=t[0].x,n=t[0].y,o=t[0].x,i=t[0].y;for(const r of t)r.x<e&&(e=r.x),r.y<n&&(n=r.y),r.x>o&&(o=r.x),r.y>i&&(i=r.y);return{center:{x:(e+o)/2,y:(n+i)/2},width:o-e,height:i-n}},KLt=(t,e)=>{if(e.length<3)return!1;let n=!1;for(let o=0,i=e.length-1;o<e.length;i=o++){const r=e[o].x,s=e[o].y,a=e[i].x,A=e[i].y;s>t.y!=A>t.y&&t.x<(a-r)*(t.y-s)/(A-s||Number.EPSILON)+r&&(n=!n)}return n},azo=(t,e,n,o)=>{const i=[];for(const r of t){if(!r._element||r._element.type==="pcb_trace"&&r.layer!==o)continue;if("x1"in r&&r._element?.type==="pcb_trace"){const A=_m({x:e.x,y:e.y},{x:r.x1,y:r.y1},{x:r.x2,y:r.y2}),c=r.width||.5,l=Math.max(c*25,2)/n.a;A<l&&i.push(r);continue}if(r.pcb_drawing_type==="polygon"){const A=r.points.map(l=>({x:En.parse(l.x),y:En.parse(l.y)})),c=Rse(A);if(!c||e.x<c.center.x-c.width/2||e.x>c.center.x+c.width/2||e.y<c.center.y-c.height/2||e.y>c.center.y+c.height/2)continue;KLt(e,A)&&i.push(r);continue}if(r.pcb_drawing_type==="polygon_with_arcs"){const A=r.brep_shape.outer_ring.vertices.map(l=>({x:En.parse(l.x),y:En.parse(l.y)})),c=Rse(A);if(!c||e.x<c.center.x-c.width/2||e.x>c.center.x+c.width/2||e.y<c.center.y-c.height/2||e.y>c.center.y+c.height/2)continue;KLt(e,A)&&i.push(r);continue}if(!("x"in r&&"y"in r))continue;let s=0,a=0;if("w"in r&&"h"in r)s=r.w,a=r.h;else if("r"in r)s=r.r*2,a=r.r*2;else if("rX"in r&&"rY"in r)s=r.rX*2,a=r.rY*2;else continue;Math.abs(r.x-e.x)<s/2&&Math.abs(r.y-e.y)<a/2&&i.push(r)}return i},Azo=({elements:t,children:e,transform:n,primitives:o,selectedLayer:i,onMouseHoverOverPrimitives:r})=>{const[s,a]=Z.useState([]),[A,c]=Z.useState({x:0,y:0}),[l,{width:g,height:u}]=pY();Z.useEffect(()=>{a([]),r([])},[i,r]);const h=Z.useMemo(()=>{const _=[];for(const m of s){if(m._element?.type==="pcb_via"||m._element?.type==="pcb_component"||m?.layer==="drill"||m?.is_hoverable===!1)continue;let p=null,I=0,f=0;if(m.pcb_drawing_type==="polygon"){const B=Rse(m.points);if(!B)continue;p=B.center,I=B.width,f=B.height}else if(m.pcb_drawing_type==="polygon_with_arcs"){const B=m.brep_shape.outer_ring.vertices.map(b=>({x:b.x,y:b.y})),Q=Rse(B);if(!Q)continue;p=Q.center,I=Q.width,f=Q.height}else m.pcb_drawing_type==="line"?(p={x:(m.x1+m.x2)/2,y:(m.y1+m.y2)/2},I=Math.abs(m.x2-m.x1),f=Math.abs(m.y2-m.y1)):"x"in m&&"y"in m&&(p={x:m.x,y:m.y},I="w"in m?m.w:"r"in m?m.r*2:"rX"in m&&"rY"in m?m.rX*2:0,f="h"in m?m.h:"r"in m?m.r*2:"rX"in m&&"rY"in m?m.rY*2:0);if(!p)continue;const C=mt(n,p),y={w:I*n.a,h:f*n.a},E=_.filter(B=>C.x===B.screen_x&&C.y===B.screen_y&&y.w===B.screen_w&&y.h===B.screen_h).length;_.push({...m,x:p.x,y:p.y,w:I,h:f,screen_x:C.x,screen_y:C.y,screen_w:y.w,screen_h:y.h,same_space_index:E})}return _},[s,n]),d=(_,m,p,I)=>{c({x:_,y:m});const f=mt(QQ(p),{x:_,y:m}),C=azo(I,f,p,i);JYo(new Set(C.map(y=>y._pcb_drawing_object_id)),new Set(s.map(y=>y._pcb_drawing_object_id)))||(a(C),r(C))};return W.jsxs("div",{ref:l,style:{position:"relative",width:"100%",height:"100%"},onMouseMove:_=>{if(n){const m=_.currentTarget.getBoundingClientRect(),p=_.clientX-m.left,I=_.clientY-m.top;d(p,I,n,o)}},onTouchStart:_=>{if(n){const m=_.touches[0],p=_.currentTarget.getBoundingClientRect(),I=m.clientX-p.left,f=m.clientY-p.top;d(I,f,n,o)}},children:[e,W.jsx(szo,{elements:t,mousePos:A,highlightedPrimitives:h}),n&&W.jsxs(W.Fragment,{children:[W.jsx(WYo,{elements:t,highlightedPrimitives:h,transform:n,containerWidth:g,containerHeight:u}),W.jsx(jYo,{elements:t,highlightedPrimitives:h,transform:n,containerWidth:g,containerHeight:u}),W.jsx($Yo,{elements:t,highlightedPrimitives:h,transform:n,containerWidth:g,containerHeight:u}),W.jsx(ZYo,{elements:t,highlightedPrimitives:h,transform:n,containerWidth:g,containerHeight:u})]})]})},ULt=["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)"],czo=({children:t,transform:e=Ll(),elements:n=[],hoveredComponentIds:o=[]})=>{const[i,{width:r,height:s}]=pY(),a=Z.useRef(null),{is_showing_pcb_groups:A,pcb_group_view_mode:c,is_showing_group_anchor_offsets:l}=Cd(g=>({is_showing_pcb_groups:g.is_showing_pcb_groups,pcb_group_view_mode:g.pcb_group_view_mode,is_showing_group_anchor_offsets:g.is_showing_group_anchor_offsets}));return Z.useEffect(()=>{const g=a.current;if(!g||!r||!s)return;g.width=r,g.height=s;const u=g.getContext("2d");if(!u||(u.clearRect(0,0,r,s),!A))return;const h=n.filter(E=>E.type==="pcb_group"),d=n.filter(E=>E.type==="pcb_component"),_=n.filter(E=>E.type==="source_group"),m=new Map(_.map(E=>[E.source_group_id,E])),p=h.filter(E=>{if(E.name?.toLowerCase().includes("subpanel"))return!1;if(c==="all")return!0;if(!E.source_group_id)return!1;const B=m.get(E.source_group_id);return B?B.was_automatically_named!==!0:!1}),I=new Map;_.forEach(E=>{const B=E;if(B.parent_source_group_id){const Q=I.get(B.parent_source_group_id)||[];Q.push(E.source_group_id),I.set(B.parent_source_group_id,Q)}});const f=E=>{const B=[],Q=I.get(E)||[];for(const b of Q)B.push(b),B.push(...f(b));return B},C=E=>{const B=_.find(Q=>Q.source_group_id===E);return B?.parent_source_group_id?1+C(B.parent_source_group_id):0},y=new Set;if(o.length>0)for(const E of d){if(!o.includes(E.pcb_component_id))continue;const B=E.positioned_relative_to_pcb_group_id??E.pcb_group_id;B&&y.add(B)}p.forEach((E,B)=>{let Q=d.filter(Le=>Le.pcb_group_id===E.pcb_group_id);if(E.source_group_id){const Le=f(E.source_group_id),Ve=h.filter(Ne=>Ne.source_group_id&&Le.includes(Ne.source_group_id));for(const Ne of Ve){const be=d.filter(Oe=>Oe.pcb_group_id===Ne.pcb_group_id);Q=[...Q,...be]}}let b,D,R,w,H=!1;if(E.center&&E.width&&E.height){H=!0;const Le=E.width/2,Ve=E.height/2;b=E.center.x-Le,R=E.center.x+Le,D=E.center.y-Ve,w=E.center.y+Ve}else if(Q.length===0||(b=1/0,D=1/0,R=-1/0,w=-1/0,Q.forEach(Le=>{if(Le.center&&typeof Le.width=="number"&&typeof Le.height=="number"){const Ve=Le.center.x-Le.width/2,Ne=Le.center.x+Le.width/2,be=Le.center.y+Le.height/2,Oe=Le.center.y-Le.height/2;b=Math.min(b,Ve),R=Math.max(R,Ne),D=Math.min(D,Oe),w=Math.max(w,be)}}),b===1/0||R===-1/0))return;const G=E.source_group_id?C(E.source_group_id):0,K=E.source_group_id?f(E.source_group_id).length>0:!1;if(!H){const Ne=1+(K?.5:0);b-=Ne,R+=Ne,D-=Ne,w+=Ne}const U=mt(e,{x:b,y:w}),q=mt(e,{x:R,y:w}),j=mt(e,{x:b,y:D}),ne=mt(e,{x:R,y:D}),re=ULt[B%ULt.length];u.strokeStyle=re,u.lineWidth=2;const X=Math.max(4,Math.min(12,8*Math.abs(e.a))),te=Math.max(2,Math.min(6,4*Math.abs(e.a))),Ae=X*(K?1.3:1),ue=te;u.setLineDash([Ae,ue]),u.beginPath(),u.moveTo(U.x,U.y),u.lineTo(q.x,q.y),u.lineTo(ne.x,ne.y),u.lineTo(j.x,j.y),u.closePath(),u.stroke();const Ce=Math.max(8,Math.min(12,10*Math.abs(e.a))),Ee=G==0||G==1?0:G*.11,Be=Ce*(1-Ee),he=4,ye=E.name||`Group ${B+1}`;u.font=`${Be}px sans-serif`,u.setLineDash([]);const Pe=u.measureText(ye).width+he*2,we=Be+he*2,Je=U.x-5,Ie=U.y-5,We=3;if(u.fillStyle="rgba(0, 0, 0, 0.8)",u.beginPath(),u.roundRect(Je,Ie-we,Pe,we,We),u.fill(),u.fillStyle=re,u.textAlign="left",u.textBaseline="middle",u.fillText(ye,Je+he,Ie-we/2),l&&y.has(E.pcb_group_id)&&!!E.anchor_position&&E.anchor_position){const Le=Array.isArray(E.anchor_position)?{x:E.anchor_position[0]??0,y:E.anchor_position[1]??0}:{x:E.anchor_position.x,y:E.anchor_position.y},Ve=mt(e,Le);u.strokeStyle="white",u.lineWidth=1.5,u.setLineDash([]);const Ne=Math.max(4,Math.min(8,6*Math.abs(e.a)));u.beginPath(),u.moveTo(Ve.x-Ne,Ve.y),u.lineTo(Ve.x+Ne,Ve.y),u.stroke(),u.beginPath(),u.moveTo(Ve.x,Ve.y-Ne),u.lineTo(Ve.x,Ve.y+Ne),u.stroke()}})},[n,e,r,s,A,c,l,o]),W.jsxs("div",{ref:i,style:{position:"relative",width:"100%",height:"100%"},children:[t,W.jsx("canvas",{ref:a,style:{position:"absolute",top:0,left:0,pointerEvents:"none",zIndex:Yg.pcbGroupOverlay,display:A?"block":"none"}})]})},lzo=({transform:t,soup:e,children:n})=>{const o=Cd(a=>a.is_showing_rats_nest),{netMap:i,idToNetMap:r}=Z.useMemo(()=>dLt(e||[]),[e]),s=Z.useMemo(()=>{if(!e||!o)return[];const a=u=>{const h=N6(e)[u.replace(/_\d+$/,"")].get(u);return h&&"x"in h&&"y"in h?{x:h.x,y:h.y}:null},A=(u,h)=>{const d=i[h]||[];let _=null,m=1/0;return d.forEach(p=>{const I=a(p);if(I){const f=Math.sqrt((u.x-I.x)**2+(u.y-I.y)**2);f<m&&f>0&&(m=f,_=I)}}),_},c=N6(e).pcb_port.list(),l=N6(e).source_trace.list(),g=[];return c.forEach((u,h)=>{const d=r[u.pcb_port_id];let _=!1;for(const I of l)I.connected_source_port_ids.includes(u.source_port_id)&&I.connected_source_net_ids.length>0&&(_=!0);if(!d)return;const m={x:u.x,y:u.y},p=A(m,d);p&&g.push({key:`${u.pcb_port_id}-${h}`,startPoint:m,endPoint:p,isInNet:_})}),g},[e,i,r,o]);return!e||!o?n:(t||(t=Ll()),W.jsxs("div",{style:{position:"relative"},children:[n,W.jsx("svg",{style:{position:"absolute",left:0,top:0,width:"100%",height:"100%",pointerEvents:"none",opacity:.5,zIndex:Yg.ratsNestOverlay},children:s.map(({key:a,startPoint:A,endPoint:c,isInNet:l})=>{const g=mt(t,A),u=mt(t,c);return W.jsx("line",{x1:g.x,y1:g.y,x2:u.x,y2:u.y,stroke:"white",strokeWidth:"1",strokeDasharray:l?"6,6":void 0},a)})})]}))},gzo={version:"1.11.388"},rb=(t,e,n)=>{const o=Cd(s=>s.is_mouse_over_container),i=Z.useRef(o),r=Z.useRef(e);Z.useEffect(()=>{i.current=o},[o]),Z.useEffect(()=>{r.current=e},[e]),Z.useEffect(()=>{if(!t)return;const s=a=>{const A=a.target;if(A.tagName==="INPUT"||A.tagName==="TEXTAREA"||A.isContentEditable)return;const c=t.split("+"),l=c.includes("ctrl"),g=c.includes("shift"),u=c.includes("alt"),h=c.includes("meta"),d=c[c.length-1],_=n?.current?n.current.contains(document.activeElement)||document.activeElement===n.current:!1;(i.current||_)&&(!l||a.ctrlKey)&&(!g||a.shiftKey)&&(!u||a.altKey)&&(!h||a.metaKey)&&a.key.toLowerCase()===d.toLowerCase()&&(a.preventDefault(),r.current())};return window.addEventListener("keydown",s),()=>{window.removeEventListener("keydown",s)}},[t])},uzo=()=>{const[t,e]=Z.useState(!1);return Z.useEffect(()=>{const n=()=>{e(window.innerWidth<=768)};return n(),window.addEventListener("resize",n),()=>window.removeEventListener("resize",n)},[]),t},fY=(t,e={stopPropagation:!0})=>{const n=Z.useRef(0),o=Z.useCallback(s=>{e.stopPropagation&&s.stopPropagation();const a=Date.now();a-n.current<300||(n.current=a,t?.(s))},[t,e.stopPropagation]),i=Z.useCallback(s=>{s.preventDefault(),o(s)},[o]);return{onClick:o,onTouchEnd:i,style:{touchAction:"manipulation"}}},Qk=({children:t,isSmallScreen:e,onClick:n,...o})=>{const{style:i,...r}=fY(n);return W.jsx("div",{...o,...r,style:{backgroundColor:"#1F1F1F",border:"1px solid #666",margin:0,padding:4,paddingLeft:e?8:6,paddingRight:e?8:6,borderRadius:2,color:"#eee",cursor:"pointer",fontSize:12,height:"fit-content",userSelect:"none",whiteSpace:"nowrap",...i,...o.style},children:t})},dzo=t=>{const e=new Map;return t.forEach((n,o)=>{const i=n.error_type||"unknown_error",r=e.get(i)||[];r.push({error:n,index:o,errorId:Bk(n,o)}),e.set(i,r)}),Array.from(e.entries()).map(([n,o])=>({errorType:n,errors:o}))},hzo=({onClose:t,setHoveredErrorId:e,setFocusedErrorId:n,highlightDurationMs:o=3e3})=>{const i=Z.useRef(null),r=Z.useRef(null),s=Z.useRef(null),a=Z.useCallback(()=>{i.current!==null&&(window.clearTimeout(i.current),i.current=null),r.current!==null&&(window.cancelAnimationFrame(r.current),r.current=null)},[]);Z.useEffect(()=>a,[a]);const A=Z.useCallback(l=>{a(),s.current=l,e(l),n(null),r.current=window.requestAnimationFrame(()=>{n(l),r.current=null}),t(),i.current=window.setTimeout(()=>{s.current=null,e(null),n(null),i.current=null},o)},[a,o,t,n,e]),c=Z.useCallback(l=>s.current===l,[]);return{handleErrorSelect:A,isSelectedError:c}},_zo=({errorId:t,errorMessage:e,copiedErrorId:n,onCopy:o})=>{const{style:i,...r}=fY(()=>o(e,t));return W.jsx("button",{type:"button","aria-label":n===t?"Error message copied":"Copy error message",style:{position:"absolute",top:12,right:16,cursor:"pointer",color:"#888",fontSize:16,background:"none",border:"none",padding:0,display:"flex",alignItems:"center",...i},...r,children:n===t?W.jsx("span",{style:{color:"#4caf50",fontSize:12},children:"Copied!"}):W.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"currentColor",children:W.jsx("path",{d:"M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z"})})})},mzo=({elements:t,isOpen:e,isSmallScreen:n,onToggle:o,onClose:i,setHoveredErrorId:r,setFocusedErrorId:s})=>{const[a,A]=Z.useState(null),[c,l]=Z.useState(new Set),[g,u]=Z.useState(new Set),[,h]=ZKo(),{handleErrorSelect:d,isSelectedError:_}=hzo({onClose:i,setHoveredErrorId:r,setFocusedErrorId:s}),m=Z.useMemo(()=>t?.filter(y=>y.type.includes("error"))??[],[t]),p=m.length,I=Z.useMemo(()=>dzo(m),[m]),f=Z.useCallback(y=>{l(E=>{const B=new Set(E);return B.has(y)?B.delete(y):B.add(y),B})},[]),C=Z.useCallback(y=>{u(E=>{const B=new Set(E);return B.has(y)?B.delete(y):B.add(y),B})},[]);return W.jsxs("div",{style:{position:"relative"},children:[W.jsx(Qk,{isSmallScreen:n,style:p>0?{color:"red"}:void 0,onClick:o,children:W.jsxs("div",{children:[p," errors"]})}),e&&p>0&&W.jsx("div",{style:{position:"absolute",top:"100%",left:0,backgroundColor:"#2a2a2a",border:"1px solid #666",borderRadius:4,marginTop:4,zIndex:1e3,minWidth:n?"280px":"400px",maxWidth:n?"90vw":"600px",maxHeight:"400px",overflow:"auto",boxShadow:"0 4px 12px rgba(0, 0, 0, 0.3)"},children:I.map(({errorType:y,errors:E},B)=>{const Q=c.has(y);return W.jsxs("div",{style:{borderBottom:B<I.length-1?"1px solid #444":"none"},children:[W.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 16px",cursor:"pointer",backgroundColor:"#232323",transition:"background-color 0.2s ease",touchAction:"manipulation",position:"sticky",top:0,zIndex:1},onMouseEnter:b=>{b.currentTarget.style.backgroundColor="#303030"},onMouseLeave:b=>{b.currentTarget.style.backgroundColor="#232323"},onTouchStart:b=>{b.stopPropagation(),b.currentTarget.style.backgroundColor="#303030"},onTouchEnd:b=>{b.stopPropagation(),b.preventDefault(),b.currentTarget.style.backgroundColor="#232323",f(y)},onClick:b=>{b.stopPropagation(),f(y)},children:[W.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,color:"#ff6b6b"},children:[W.jsx("div",{style:{color:"#888",fontSize:"16px",transform:Q?"rotate(90deg)":"rotate(0deg)",transition:"transform 0.2s ease",flexShrink:0},children:"›"}),W.jsx("div",{style:{fontWeight:"bold",fontSize:n?"12px":"13px"},children:y})]}),W.jsx("div",{style:{fontSize:n?"12px":"13px",color:"#aaa",whiteSpace:"nowrap",marginLeft:12},children:E.length})]}),!Q&&E.map(({error:b,index:D,errorId:R})=>{const w=g.has(R),H=b.message??"No error message";return W.jsxs("div",{style:{borderTop:"1px solid #3a3a3a"},children:[W.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12,padding:"12px 16px 12px 24px",cursor:"pointer",backgroundColor:"#2a2a2a",transition:"background-color 0.2s ease",touchAction:"manipulation"},onMouseEnter:G=>{G.currentTarget.style.backgroundColor="#333",r(R)},onMouseLeave:G=>{G.currentTarget.style.backgroundColor="#2a2a2a",_(R)||r(null)},onTouchStart:G=>{G.stopPropagation(),G.currentTarget.style.backgroundColor="#333",r(R)},onTouchEnd:G=>{G.stopPropagation(),G.preventDefault(),G.currentTarget.style.backgroundColor="#2a2a2a",d(R)},onClick:G=>{G.stopPropagation(),d(R)},children:[W.jsx("div",{style:{flex:1,fontSize:n?"12px":"13px",color:"#ddd",lineHeight:1.4,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",userSelect:"text"},children:H}),W.jsx("button",{type:"button","aria-label":w?"Collapse error details":"Expand error details",style:{color:"#888",fontSize:"16px",transform:w?"rotate(0deg)":"rotate(90deg)",transition:"transform 0.2s ease",flexShrink:0,background:"none",border:"none",padding:0,cursor:"pointer"},onMouseDown:G=>G.stopPropagation(),onClick:G=>{G.stopPropagation(),C(R)},onTouchEnd:G=>{G.stopPropagation(),G.preventDefault(),C(R)},children:"›"})]}),w&&W.jsxs("div",{"data-error-id":D,style:{display:"block",padding:"12px 16px 12px 24px",backgroundColor:"#1a1a1a",borderTop:"1px solid #444",position:"relative"},children:[W.jsx("div",{style:{fontSize:n?"11px":"12px",color:"#ccc",lineHeight:1.5,wordWrap:"break-word",overflowWrap:"break-word",hyphens:"auto",userSelect:"text",paddingRight:30},onMouseDown:G=>G.stopPropagation(),onClick:G=>G.stopPropagation(),children:H}),W.jsx(_zo,{errorId:R,errorMessage:H,copiedErrorId:a,onCopy:(G,K)=>{h(G),A(K),setTimeout(()=>A(null),2e3)}})]})]},R)})]},y)})})]})},pzo=({name:t,selected:e,onClick:n})=>{const{style:o,...i}=fY(n);return W.jsxs("div",{className:Bse`
|
|
5698
5698
|
margin-top: 2px;
|
|
5699
5699
|
padding: 4px;
|
|
5700
5700
|
padding-left: 8px;
|
|
@@ -5765,7 +5765,7 @@ test("${c} should solve problem correctly", () => {
|
|
|
5765
5765
|
// Add more specific assertions based on expected output
|
|
5766
5766
|
// expect(solver.netLabelPlacementSolver!.netLabelPlacements).toMatchInlineSnapshot()
|
|
5767
5767
|
})
|
|
5768
|
-
`,g=new Blob([l],{type:"text/plain"}),u=URL.createObjectURL(g),h=document.createElement("a");h.href=u,h.download=`${c}.test.ts`,h.click(),URL.revokeObjectURL(u)}catch(A){alert(`Error generating test.ts for ${t.constructor.name}: ${A instanceof Error?A.message:String(A)}`)}o(!1)};return W.jsxs("div",{className:`relative ${e}`,ref:i,children:[W.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>o(!n),title:`Download options for ${t.constructor.name}`,children:t.constructor.name}),n&&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:r,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:a,children:"Download test.ts"})]})]})},WLt=t=>t.activeSubSolver?[t,...WLt(t.activeSubSolver)]:[t],dVo=({solver:t})=>{const e=WLt(t);return W.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:e.map((n,o)=>W.jsxs("div",{className:"flex items-center",children:[o>0&&W.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),W.jsx(uVo,{solver:n})]},n.constructor.name))})},hVo=({solver:t,triggerRender:e,animationSpeed:n=25,onSolverStarted:o,onSolverCompleted:i})=>{const[r,s]=Z.useReducer(_=>!_,!1),a=Z.useRef(void 0),A=()=>{!t.solved&&!t.failed&&(t.step(),e())},c=()=>{!t.solved&&!t.failed&&(o&&o(t),t.solve(),e(),i&&i(t))},l=()=>{r?(a.current&&(clearInterval(a.current),a.current=void 0),s()):(s(),a.current=setInterval(()=>{if(t.solved||t.failed){a.current&&(clearInterval(a.current),a.current=void 0),s(),e(),i&&t.solved&&i(t);return}t.step(),e()},n))},g=()=>{const _=t;if(_.getCurrentPhase&&!t.solved&&!t.failed){const m=_.getCurrentPhase();for(;_.getCurrentPhase()===m&&!t.solved&&!t.failed;)t.step();e()}},u=()=>{if(t.solved||t.failed||r)return;const _=window.prompt("Step until which iteration?",`${t.iterations}`);if(_===null)return;const m=Number(_);if(!Number.isFinite(m)){window.alert("Please enter a valid number for the iteration");return}for(;t.iterations<m&&!t.solved&&!t.failed;)t.step();e(),t.solved&&i&&i(t)};Z.useEffect(()=>()=>{a.current&&clearInterval(a.current)},[]),Z.useEffect(()=>{(t.solved||t.failed)&&r&&(a.current&&(clearInterval(a.current),a.current=void 0),s())},[t.solved,t.failed,r]);const h=t.getCurrentPhase!==void 0,d=h?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(dVo,{solver:t})}),W.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[W.jsx("button",{onClick:A,disabled:t.solved||t.failed||r,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:c,disabled:t.solved||t.failed||r,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:l,disabled:t.solved||t.failed,className:`px-3 py-1 rounded text-white text-sm ${r?"bg-red-500 hover:bg-red-600":"bg-yellow-500 hover:bg-yellow-600"} disabled:bg-gray-300`,children:r?"Stop":"Animate"}),W.jsx("button",{onClick:u,disabled:t.solved||t.failed||r,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"}),h&&W.jsx("button",{onClick:g,disabled:t.solved||t.failed||r,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"]}),d&&W.jsxs("div",{className:"text-sm text-gray-600",children:["Phase: ",W.jsx("span",{className:"font-medium",children:d})]}),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]})]})},_Vo=(t,e,n)=>{const o=t.currentPipelineStepIndex;return e<o?"Completed":e===o&&t.activeSubSolver?t.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},mVo=(t,e)=>{const o=t.pipelineDef[e].solverName,i=_Vo(t,e),r=t[o],s=t.firstIterationOfPhase?.[o]??null,a=t.iterations;let A=0;if(i==="Completed"){const u=t.pipelineDef[e+1],h=u?t.firstIterationOfPhase?.[u.solverName]:void 0;h!==void 0&&s!==null?A=h-s:s!==null&&(A=a-s)}else i==="In Progress"&&s!==null&&(A=a-s);const c=t.timeSpentOnPhase?.[o]??0;let l=0;i==="Completed"?l=1:i==="In Progress"&&r&&(l=r.progress??0);const g=r?.stats??null;return{index:e,name:o,status:i,firstIteration:s,iterations:A,progress:l,timeSpent:c,stats:g&&Object.keys(g).length>0?g:null,solverInstance:r??null}},pVo=({status:t})=>{const e={"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 ${e[t]}`,children:t})},IVo=({progress:t})=>{if(t===0)return null;const e=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:`${e}%`}})}),W.jsxs("span",{className:"text-xs text-gray-500",children:[e,"%"]})]})},fVo=t=>Object.entries(t).map(([e,n])=>`${e}: ${n}`).join(", "),CVo=({stats:t})=>{if(!t||Object.keys(t).length===0)return W.jsx("span",{children:"-"});const e=Object.entries(t),n=fVo(t);return W.jsxs("details",{className:"cursor-pointer",children:[W.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:n}),W.jsx("div",{className:"mt-1 text-xs",children:e.map(([o,i])=>W.jsxs("div",{children:[o,": ",String(i)]},o))})]})},d9e=t=>{if(t===null||typeof t!="object")return t;if(Array.isArray(t))return t.map(d9e);const e={};for(const[n,o]of Object.entries(t))n.startsWith("_")||(e[n]=d9e(o));return e},yVo=(t,e)=>{try{if(typeof t.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${e}`);return}const n=d9e(t.getConstructorParams()),o=new Blob([JSON.stringify(n,null,2)],{type:"application/json"}),i=URL.createObjectURL(o),r=document.createElement("a");r.href=i,r.download=`${e}_input.json`,r.click(),URL.revokeObjectURL(i)}catch(n){alert(`Error downloading input for ${e}: ${n instanceof Error?n.message:String(n)}`)}},EVo=({solver:t,onStepUntilPhase:e,onDownloadInput:n})=>{const o=t.pipelineDef.map((a,A)=>mVo(t,A)),i=a=>{e?.(a)},r=a=>{a.solverInstance&&(n?n(a.solverInstance,a.name):yVo(a.solverInstance,a.name))},s=a=>`${(a/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:o.map(a=>W.jsxs("tr",{className:`border-b border-gray-100 ${a.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(a.index+1).padStart(2,"0")}),W.jsx("button",{onClick:()=>i(a.name),disabled:a.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 ${a.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:a.name})]})}),W.jsx("td",{className:"px-4 py-2",children:W.jsx(pVo,{status:a.status})}),W.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:a.firstIteration!==null?a.firstIteration:""}),W.jsx("td",{className:"px-4 py-2 text-gray-600",children:a.iterations}),W.jsx("td",{className:"px-4 py-2",children:W.jsx(IVo,{progress:a.progress})}),W.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(a.timeSpent)}),W.jsx("td",{className:"px-4 py-2 text-gray-500",children:W.jsx(CVo,{stats:a.stats})}),W.jsx("td",{className:"px-4 py-2",children:a.solverInstance?W.jsxs("button",{onClick:()=>r(a),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${a.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})]},a.name))})]})})]})},xVo=class extends Xr.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 BVo({graphics:t}){const e=t.points??[],n=t.lines??[],o=t.rects??[],i=t.circles??[],r=t.texts??[];let s=Number.POSITIVE_INFINITY,a=Number.POSITIVE_INFINITY,A=Number.NEGATIVE_INFINITY,c=Number.NEGATIVE_INFINITY;const l=(m,p)=>{typeof m=="number"&&(m<s&&(s=m),m>A&&(A=m)),typeof p=="number"&&(p<a&&(a=p),p>c&&(c=p))};for(const m of e)l(m.x,m.y);for(const m of n){const p=m.points??[];for(const I of p)l(I.x,I.y)}for(const m of o){const p=m.x??0,I=m.y??0,f=m.width??0,C=m.height??0;l(p,I),l(p+f,I+C)}for(const m of i){const p=m.x??0,I=m.y??0,f=m.radius??1;l(p-f,I-f),l(p+f,I+f)}for(const m of r)l(m.x,m.y);(!isFinite(s)||!isFinite(a)||!isFinite(A)||!isFinite(c))&&(s=-20,a=-20,A=20,c=20);const g=10,u=s-g,h=a-g,d=Math.max(1,A-s+2*g),_=Math.max(1,c-a+2*g);return W.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${u} ${h} ${d} ${_}`,role:"img","aria-label":"Graphics fallback",children:[o.map((m,p)=>W.jsx("rect",{x:m.x??0,y:m.y??0,width:m.width??0,height:m.height??0,fill:"none",stroke:m.strokeColor??"black",strokeWidth:m.strokeWidth??1},`rect-${p}`)),n.map((m,p)=>W.jsx("polyline",{fill:"none",stroke:m.strokeColor??"black",strokeWidth:m.strokeWidth??1,points:(m.points??[]).map(I=>`${I.x??0},${I.y??0}`).join(" ")},`line-${p}`)),i.map((m,p)=>W.jsx("circle",{cx:m.x??0,cy:m.y??0,r:m.radius??1.5,fill:m.fillColor??"none",stroke:m.strokeColor??"black",strokeWidth:m.strokeWidth??1},`circle-${p}`)),e.map((m,p)=>W.jsx("circle",{cx:m.x??0,cy:m.y??0,r:m.radius??1.5,fill:m.color??"black"},`point-${p}`)),r.map((m,p)=>W.jsx("text",{x:m.x??0,y:m.y??0,fontSize:m.fontSize??10,fill:m.color??"black",children:m.text??""},`text-${p}`))]})}var QVo=({solver:t,animationSpeed:e=25,onSolverStarted:n,onSolverCompleted:o})=>{const[i,r]=Z.useReducer(l=>l+1,0),s=Z.useMemo(()=>{try{return t.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(l){return console.error("Visualization error:",l),{points:[],lines:[],rects:[],circles:[]}}},[t,i]),a=Z.useMemo(()=>(s.rects?.length||0)===0&&(s.lines?.length||0)===0&&(s.points?.length||0)===0&&(s.circles?.length||0)===0,[s]);Z.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const l=document.createElement("script");l.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(l)}},[]);const A=t.pipelineDef!==void 0,c=l=>{const g=t;if(!t.solved&&!t.failed){for(;!t.solved&&!t.failed&&g.currentPipelineStepIndex<=g.pipelineDef.findIndex(u=>u.solverName===l);)t.step();r()}};return W.jsxs("div",{children:[W.jsx(hVo,{solver:t,triggerRender:r,animationSpeed:e,onSolverStarted:n,onSolverCompleted:o}),a?W.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):W.jsx(xVo,{fallback:W.jsx(BVo,{graphics:s}),children:W.jsx(gVo,{graphics:s})}),A&&W.jsx(EVo,{solver:t,onStepUntilPhase:c})]})};const SVo=()=>{Z.useEffect(()=>{const t="tailwind-cdn-script";if(document.getElementById(t)||window.tailwind)return;const e=document.createElement("div");e.className="hidden",document.body.appendChild(e);const n=window.getComputedStyle(e).display==="none";if(document.body.removeChild(e),n)return;const o=document.createElement("script");o.id=t,o.src="https://cdn.tailwindcss.com",document.head.appendChild(o)},[])},bVo=1e3,VB=(t,e)=>{const{fileName:n,mimeType:o="text/plain"}=e,i=t instanceof Blob?t:new Blob([t],{type:o}),r=URL.createObjectURL(i),s=document.createElement("a");s.href=r,s.download=n,s.target="_blank",s.rel="noopener noreferrer",s.style.display="none",document.body.appendChild(s),s.click(),document.body.removeChild(s),setTimeout(()=>{URL.revokeObjectURL(r)},bVo)},h9e=t=>{let e=t.trim().replace(/[\\/:*?"<>|]/g,"_").replace(/[\x00-\x1f]/g,"").replace(/^\.+/,"").replace(/\.+$/,"").replace(/\s+/g," ").replace(/_+/g,"_");return/^(con|prn|aux|nul|com[0-9]|lpt[0-9])$/i.test(e)&&(e=`_${e}`),e=e.slice(0,200),e||"untitled"},sb="https://github.com/tscircuit/tscircuit-autorouter/issues/new",jLt="https://github.com/tscircuit/copper-pour-solver/issues/new",XLt="https://github.com/tscircuit/calculate-packing/issues/new",DVo="https://github.com/tscircuit/matchpack/issues/new",$Lt="https://github.com/tscircuit/schematic-trace-solver/issues/new?template=json-bug-report.yml",PVo={PackSolver2:XLt,LayoutPipelineSolver:DVo,AutoroutingPipelineSolver:sb,AssignableAutoroutingPipeline2:sb,AssignableAutoroutingPipeline3:sb,AutoroutingPipeline1_OriginalUnravel:sb,AutoroutingPipelineSolver3_HgPortPointPathing:sb,AutoroutingPipelineSolver4:sb,AutoroutingPipelineSolver5:sb,AutoroutingPipelineSolver7_MultiGraph:sb,AutoroutingPipelineSolver8:sb,CopperPourPipelineSolver:jLt,SchematicTracePipelineSolver:$Lt},vVo=t=>t.toLowerCase().includes("pack")?aTo:t.toLowerCase().includes("rout")?_To:ZRo,ZLt=t=>{const e=PVo[t];if(e)return e;const n=t.toLowerCase();return n.includes("autorout")?sb:n.includes("schematic")&&n.includes("trace")?$Lt:n.includes("copperpour")?jLt:n.includes("pack")?XLt:null},MVo=t=>`${h9e(`${t.componentName}-${t.solverName}`)}-solver-input.json`,eHt=t=>{VB(JSON.stringify(t.solverParams,null,2),{fileName:MVo(t),mimeType:"application/json"})},wVo=({solverEvent:t})=>{const e=ZLt(t.solverName);return W.jsxs("div",{className:"rf-flex rf-items-center rf-justify-end rf-gap-2 rf-border-b rf-border-gray-200 rf-bg-gray-50 rf-px-4 rf-py-2",children:[W.jsxs(qA,{type:"button",variant:"outline",size:"sm",onClick:()=>eHt(t),children:[W.jsx(fre,{className:"rf-w-4 rf-h-4"}),"Download"]}),e?W.jsx(qA,{asChild:!0,variant:"outline",size:"sm",children:W.jsxs("a",{href:e,target:"_blank",rel:"noopener noreferrer",children:[W.jsx(mre,{className:"rf-w-4 rf-h-4"}),"Report"]})}):W.jsxs(qA,{type:"button",variant:"outline",size:"sm",disabled:!0,title:"No report link configured for this solver",children:[W.jsx(mre,{className:"rf-w-4 rf-h-4"}),"Report"]})]})},NVo=({solverEvent:t})=>{const e=ZLt(t.solverName);return e?W.jsx(qA,{asChild:!0,variant:"ghost",size:"icon",className:"rf-h-8 rf-w-8",children:W.jsx("a",{href:e,target:"_blank",rel:"noopener noreferrer",title:"Report solver bug","aria-label":"Report solver bug",children:W.jsx(mre,{className:"rf-w-4 rf-h-4"})})}):W.jsx(qA,{type:"button",variant:"ghost",size:"icon",className:"rf-h-8 rf-w-8",disabled:!0,title:"No report link configured for this solver","aria-label":"Report solver bug",children:W.jsx(mre,{className:"rf-w-4 rf-h-4"})})},RVo=({solverEvents:t=[]})=>{const[e,n]=Z.useState(null);SVo();const o=Z.useMemo(()=>{const a=new Map;for(const A of t){const c=`${A.componentName}-${A.solverName}`;a.set(c,A)}return a},[t]),i=Z.useMemo(()=>Array.from(o.keys()),[o]),r=e?o.get(e):null,s=Z.useMemo(()=>{if(!r)return{instance:null,error:null,classFound:!1};const a=yBe[r.solverName];if(!a)return{instance:null,error:`Solver class "${r.solverName}" not found in SOLVERS registry. Available: ${Object.keys(yBe).join(", ")}`,classFound:!1};try{const A=r.solverParams,c=A?.input!==void 0?A.input:A;return{instance:new a(c),error:null,classFound:!0}}catch(A){const c=A instanceof Error?A.message:String(A);return console.error("Failed to reconstruct solver:",A),{instance:null,error:`Failed to instantiate solver: ${c}`,classFound:!0}}},[r]);return t.length===0?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:[i.length," ",i.length===1?"Solver":"Solvers"]}),i.map(a=>{const A=o.get(a),c=e===a;return W.jsx("div",{className:`rf-px-3 rf-py-2 rf-cursor-pointer rf-border-b rf-border-gray-100 ${c?"rf-bg-blue-50 rf-border-l-2 rf-border-l-blue-500":"hover:rf-bg-gray-50"}`,onClick:()=>n(a),children:(()=>{const l=vVo(A.solverName);return W.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[W.jsx(l,{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})]})]})})()},a)})]}),W.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:r?s.instance?W.jsxs("div",{className:"rf-flex rf-h-full rf-flex-col rf-overflow-y-auto",children:[W.jsx(wVo,{solverEvent:r}),W.jsx("div",{className:"rf-min-h-0 rf-flex-1",children:W.jsx(XS,{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"," ",r.solverName]})]})}),children:W.jsx(QVo,{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:r.solverName}),W.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",r.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.jsxs("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50 rf-flex rf-items-center rf-justify-between rf-gap-2",children:[W.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"}),W.jsxs("div",{className:"rf-flex rf-items-center rf-gap-1",children:[W.jsx(NVo,{solverEvent:r}),W.jsx(qA,{type:"button",variant:"ghost",size:"icon",className:"rf-h-8 rf-w-8","aria-label":"Download solver input JSON",title:"Download solver input JSON",onClick:()=>eHt(r),children:W.jsx(fre,{className:"rf-w-4 rf-h-4"})})]})]}),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(r.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"})})})]})},tHt=({errorMessage:t,errorStack:e,circuitJsonErrors:n})=>{Z.useEffect(()=>{if(t){const o=new Error(t);e&&(o.stack=e);try{H8.captureException(o)}catch{}}},[t,e]),Z.useEffect(()=>{if(n&&n.length>0)for(const o of n){const i=new Error(o.message||"Circuit JSON Error");o.stack&&(i.stack=o.stack);try{H8.captureException(i,{error_type:o.type})}catch{}}},[n])},TVo=t=>{Z.useEffect(()=>{try{Jqt(t)}catch{}},[t.source,t.component,t.isWebEmbedded,t.activeTab])},nHt="0.0.2474",kVo={version:nHt},_9e={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1},m9e=new Map,kse=t=>{const e=m9e.get(t);return e?Object.fromEntries(Object.entries(e.stores).map(([n,o])=>[n,o.getState()])):{}},FVo=(t,e,n)=>{if(t===void 0)return{type:"untracked",connection:e.connect(n)};const o=m9e.get(n.name);if(o)return{type:"tracked",store:t,...o};const i={connection:e.connect(n),stores:{}};return m9e.set(n.name,i),{type:"tracked",store:t,...i}},oHt=(t,e={})=>(n,o,i)=>{const{enabled:r,anonymousActionType:s,store:a,...A}=e;let c;try{c=(r??(_9e?"production":void 0)!=="production")&&window.__REDUX_DEVTOOLS_EXTENSION__}catch{}if(!c)return(_9e?"production":void 0)!=="production"&&r&&console.warn("[zustand devtools middleware] Please install/enable Redux devtools extension"),t(n,o,i);const{connection:l,...g}=FVo(a,c,A);let u=!0;i.setState=(_,m,p)=>{const I=n(_,m);if(!u)return I;const f=p===void 0?{type:s||"anonymous"}:typeof p=="string"?{type:p}:p;return a===void 0?(l?.send(f,o()),I):(l?.send({...f,type:`${a}/${f.type}`},{...kse(A.name),[a]:i.getState()}),I)};const h=(..._)=>{const m=u;u=!1,n(..._),u=m},d=t(i.setState,o,i);if(g.type==="untracked"?l?.init(d):(g.stores[g.store]=i,l?.init(Object.fromEntries(Object.entries(g.stores).map(([_,m])=>[_,_===g.store?d:m.getState()])))),i.dispatchFromDevtools&&typeof i.dispatch=="function"){let _=!1;const m=i.dispatch;i.dispatch=(...p)=>{(_9e?"production":void 0)!=="production"&&p[0].type==="__setState"&&!_&&(console.warn('[zustand devtools middleware] "__setState" action type is reserved to set state from the devtools. Avoid using it.'),_=!0),m(...p)}}return l.subscribe(_=>{var m;switch(_.type){case"ACTION":if(typeof _.payload!="string"){console.error("[zustand devtools middleware] Unsupported action format");return}return p9e(_.payload,p=>{if(p.type==="__setState"){if(a===void 0){h(p.state);return}Object.keys(p.state).length!==1&&console.error(`
|
|
5768
|
+
`,g=new Blob([l],{type:"text/plain"}),u=URL.createObjectURL(g),h=document.createElement("a");h.href=u,h.download=`${c}.test.ts`,h.click(),URL.revokeObjectURL(u)}catch(A){alert(`Error generating test.ts for ${t.constructor.name}: ${A instanceof Error?A.message:String(A)}`)}o(!1)};return W.jsxs("div",{className:`relative ${e}`,ref:i,children:[W.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>o(!n),title:`Download options for ${t.constructor.name}`,children:t.constructor.name}),n&&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:r,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:a,children:"Download test.ts"})]})]})},WLt=t=>t.activeSubSolver?[t,...WLt(t.activeSubSolver)]:[t],dVo=({solver:t})=>{const e=WLt(t);return W.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:e.map((n,o)=>W.jsxs("div",{className:"flex items-center",children:[o>0&&W.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),W.jsx(uVo,{solver:n})]},n.constructor.name))})},hVo=({solver:t,triggerRender:e,animationSpeed:n=25,onSolverStarted:o,onSolverCompleted:i})=>{const[r,s]=Z.useReducer(_=>!_,!1),a=Z.useRef(void 0),A=()=>{!t.solved&&!t.failed&&(t.step(),e())},c=()=>{!t.solved&&!t.failed&&(o&&o(t),t.solve(),e(),i&&i(t))},l=()=>{r?(a.current&&(clearInterval(a.current),a.current=void 0),s()):(s(),a.current=setInterval(()=>{if(t.solved||t.failed){a.current&&(clearInterval(a.current),a.current=void 0),s(),e(),i&&t.solved&&i(t);return}t.step(),e()},n))},g=()=>{const _=t;if(_.getCurrentPhase&&!t.solved&&!t.failed){const m=_.getCurrentPhase();for(;_.getCurrentPhase()===m&&!t.solved&&!t.failed;)t.step();e()}},u=()=>{if(t.solved||t.failed||r)return;const _=window.prompt("Step until which iteration?",`${t.iterations}`);if(_===null)return;const m=Number(_);if(!Number.isFinite(m)){window.alert("Please enter a valid number for the iteration");return}for(;t.iterations<m&&!t.solved&&!t.failed;)t.step();e(),t.solved&&i&&i(t)};Z.useEffect(()=>()=>{a.current&&clearInterval(a.current)},[]),Z.useEffect(()=>{(t.solved||t.failed)&&r&&(a.current&&(clearInterval(a.current),a.current=void 0),s())},[t.solved,t.failed,r]);const h=t.getCurrentPhase!==void 0,d=h?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(dVo,{solver:t})}),W.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[W.jsx("button",{onClick:A,disabled:t.solved||t.failed||r,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:c,disabled:t.solved||t.failed||r,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:l,disabled:t.solved||t.failed,className:`px-3 py-1 rounded text-white text-sm ${r?"bg-red-500 hover:bg-red-600":"bg-yellow-500 hover:bg-yellow-600"} disabled:bg-gray-300`,children:r?"Stop":"Animate"}),W.jsx("button",{onClick:u,disabled:t.solved||t.failed||r,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"}),h&&W.jsx("button",{onClick:g,disabled:t.solved||t.failed||r,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"]}),d&&W.jsxs("div",{className:"text-sm text-gray-600",children:["Phase: ",W.jsx("span",{className:"font-medium",children:d})]}),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]})]})},_Vo=(t,e,n)=>{const o=t.currentPipelineStepIndex;return e<o?"Completed":e===o&&t.activeSubSolver?t.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},mVo=(t,e)=>{const o=t.pipelineDef[e].solverName,i=_Vo(t,e),r=t[o],s=t.firstIterationOfPhase?.[o]??null,a=t.iterations;let A=0;if(i==="Completed"){const u=t.pipelineDef[e+1],h=u?t.firstIterationOfPhase?.[u.solverName]:void 0;h!==void 0&&s!==null?A=h-s:s!==null&&(A=a-s)}else i==="In Progress"&&s!==null&&(A=a-s);const c=t.timeSpentOnPhase?.[o]??0;let l=0;i==="Completed"?l=1:i==="In Progress"&&r&&(l=r.progress??0);const g=r?.stats??null;return{index:e,name:o,status:i,firstIteration:s,iterations:A,progress:l,timeSpent:c,stats:g&&Object.keys(g).length>0?g:null,solverInstance:r??null}},pVo=({status:t})=>{const e={"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 ${e[t]}`,children:t})},IVo=({progress:t})=>{if(t===0)return null;const e=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:`${e}%`}})}),W.jsxs("span",{className:"text-xs text-gray-500",children:[e,"%"]})]})},fVo=t=>Object.entries(t).map(([e,n])=>`${e}: ${n}`).join(", "),CVo=({stats:t})=>{if(!t||Object.keys(t).length===0)return W.jsx("span",{children:"-"});const e=Object.entries(t),n=fVo(t);return W.jsxs("details",{className:"cursor-pointer",children:[W.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:n}),W.jsx("div",{className:"mt-1 text-xs",children:e.map(([o,i])=>W.jsxs("div",{children:[o,": ",String(i)]},o))})]})},d9e=t=>{if(t===null||typeof t!="object")return t;if(Array.isArray(t))return t.map(d9e);const e={};for(const[n,o]of Object.entries(t))n.startsWith("_")||(e[n]=d9e(o));return e},yVo=(t,e)=>{try{if(typeof t.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${e}`);return}const n=d9e(t.getConstructorParams()),o=new Blob([JSON.stringify(n,null,2)],{type:"application/json"}),i=URL.createObjectURL(o),r=document.createElement("a");r.href=i,r.download=`${e}_input.json`,r.click(),URL.revokeObjectURL(i)}catch(n){alert(`Error downloading input for ${e}: ${n instanceof Error?n.message:String(n)}`)}},EVo=({solver:t,onStepUntilPhase:e,onDownloadInput:n})=>{const o=t.pipelineDef.map((a,A)=>mVo(t,A)),i=a=>{e?.(a)},r=a=>{a.solverInstance&&(n?n(a.solverInstance,a.name):yVo(a.solverInstance,a.name))},s=a=>`${(a/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:o.map(a=>W.jsxs("tr",{className:`border-b border-gray-100 ${a.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(a.index+1).padStart(2,"0")}),W.jsx("button",{onClick:()=>i(a.name),disabled:a.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 ${a.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:a.name})]})}),W.jsx("td",{className:"px-4 py-2",children:W.jsx(pVo,{status:a.status})}),W.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:a.firstIteration!==null?a.firstIteration:""}),W.jsx("td",{className:"px-4 py-2 text-gray-600",children:a.iterations}),W.jsx("td",{className:"px-4 py-2",children:W.jsx(IVo,{progress:a.progress})}),W.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(a.timeSpent)}),W.jsx("td",{className:"px-4 py-2 text-gray-500",children:W.jsx(CVo,{stats:a.stats})}),W.jsx("td",{className:"px-4 py-2",children:a.solverInstance?W.jsxs("button",{onClick:()=>r(a),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${a.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})]},a.name))})]})})]})},xVo=class extends Xr.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 BVo({graphics:t}){const e=t.points??[],n=t.lines??[],o=t.rects??[],i=t.circles??[],r=t.texts??[];let s=Number.POSITIVE_INFINITY,a=Number.POSITIVE_INFINITY,A=Number.NEGATIVE_INFINITY,c=Number.NEGATIVE_INFINITY;const l=(m,p)=>{typeof m=="number"&&(m<s&&(s=m),m>A&&(A=m)),typeof p=="number"&&(p<a&&(a=p),p>c&&(c=p))};for(const m of e)l(m.x,m.y);for(const m of n){const p=m.points??[];for(const I of p)l(I.x,I.y)}for(const m of o){const p=m.x??0,I=m.y??0,f=m.width??0,C=m.height??0;l(p,I),l(p+f,I+C)}for(const m of i){const p=m.x??0,I=m.y??0,f=m.radius??1;l(p-f,I-f),l(p+f,I+f)}for(const m of r)l(m.x,m.y);(!isFinite(s)||!isFinite(a)||!isFinite(A)||!isFinite(c))&&(s=-20,a=-20,A=20,c=20);const g=10,u=s-g,h=a-g,d=Math.max(1,A-s+2*g),_=Math.max(1,c-a+2*g);return W.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${u} ${h} ${d} ${_}`,role:"img","aria-label":"Graphics fallback",children:[o.map((m,p)=>W.jsx("rect",{x:m.x??0,y:m.y??0,width:m.width??0,height:m.height??0,fill:"none",stroke:m.strokeColor??"black",strokeWidth:m.strokeWidth??1},`rect-${p}`)),n.map((m,p)=>W.jsx("polyline",{fill:"none",stroke:m.strokeColor??"black",strokeWidth:m.strokeWidth??1,points:(m.points??[]).map(I=>`${I.x??0},${I.y??0}`).join(" ")},`line-${p}`)),i.map((m,p)=>W.jsx("circle",{cx:m.x??0,cy:m.y??0,r:m.radius??1.5,fill:m.fillColor??"none",stroke:m.strokeColor??"black",strokeWidth:m.strokeWidth??1},`circle-${p}`)),e.map((m,p)=>W.jsx("circle",{cx:m.x??0,cy:m.y??0,r:m.radius??1.5,fill:m.color??"black"},`point-${p}`)),r.map((m,p)=>W.jsx("text",{x:m.x??0,y:m.y??0,fontSize:m.fontSize??10,fill:m.color??"black",children:m.text??""},`text-${p}`))]})}var QVo=({solver:t,animationSpeed:e=25,onSolverStarted:n,onSolverCompleted:o})=>{const[i,r]=Z.useReducer(l=>l+1,0),s=Z.useMemo(()=>{try{return t.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(l){return console.error("Visualization error:",l),{points:[],lines:[],rects:[],circles:[]}}},[t,i]),a=Z.useMemo(()=>(s.rects?.length||0)===0&&(s.lines?.length||0)===0&&(s.points?.length||0)===0&&(s.circles?.length||0)===0,[s]);Z.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const l=document.createElement("script");l.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(l)}},[]);const A=t.pipelineDef!==void 0,c=l=>{const g=t;if(!t.solved&&!t.failed){for(;!t.solved&&!t.failed&&g.currentPipelineStepIndex<=g.pipelineDef.findIndex(u=>u.solverName===l);)t.step();r()}};return W.jsxs("div",{children:[W.jsx(hVo,{solver:t,triggerRender:r,animationSpeed:e,onSolverStarted:n,onSolverCompleted:o}),a?W.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):W.jsx(xVo,{fallback:W.jsx(BVo,{graphics:s}),children:W.jsx(gVo,{graphics:s})}),A&&W.jsx(EVo,{solver:t,onStepUntilPhase:c})]})};const SVo=()=>{Z.useEffect(()=>{const t="tailwind-cdn-script";if(document.getElementById(t)||window.tailwind)return;const e=document.createElement("div");e.className="hidden",document.body.appendChild(e);const n=window.getComputedStyle(e).display==="none";if(document.body.removeChild(e),n)return;const o=document.createElement("script");o.id=t,o.src="https://cdn.tailwindcss.com",document.head.appendChild(o)},[])},bVo=1e3,VB=(t,e)=>{const{fileName:n,mimeType:o="text/plain"}=e,i=t instanceof Blob?t:new Blob([t],{type:o}),r=URL.createObjectURL(i),s=document.createElement("a");s.href=r,s.download=n,s.target="_blank",s.rel="noopener noreferrer",s.style.display="none",document.body.appendChild(s),s.click(),document.body.removeChild(s),setTimeout(()=>{URL.revokeObjectURL(r)},bVo)},h9e=t=>{let e=t.trim().replace(/[\\/:*?"<>|]/g,"_").replace(/[\x00-\x1f]/g,"").replace(/^\.+/,"").replace(/\.+$/,"").replace(/\s+/g," ").replace(/_+/g,"_");return/^(con|prn|aux|nul|com[0-9]|lpt[0-9])$/i.test(e)&&(e=`_${e}`),e=e.slice(0,200),e||"untitled"},sb="https://github.com/tscircuit/tscircuit-autorouter/issues/new",jLt="https://github.com/tscircuit/copper-pour-solver/issues/new",XLt="https://github.com/tscircuit/calculate-packing/issues/new",DVo="https://github.com/tscircuit/matchpack/issues/new",$Lt="https://github.com/tscircuit/schematic-trace-solver/issues/new?template=json-bug-report.yml",PVo={PackSolver2:XLt,LayoutPipelineSolver:DVo,AutoroutingPipelineSolver:sb,AssignableAutoroutingPipeline2:sb,AssignableAutoroutingPipeline3:sb,AutoroutingPipeline1_OriginalUnravel:sb,AutoroutingPipelineSolver3_HgPortPointPathing:sb,AutoroutingPipelineSolver4:sb,AutoroutingPipelineSolver5:sb,AutoroutingPipelineSolver7_MultiGraph:sb,AutoroutingPipelineSolver8:sb,CopperPourPipelineSolver:jLt,SchematicTracePipelineSolver:$Lt},vVo=t=>t.toLowerCase().includes("pack")?aTo:t.toLowerCase().includes("rout")?_To:ZRo,ZLt=t=>{const e=PVo[t];if(e)return e;const n=t.toLowerCase();return n.includes("autorout")?sb:n.includes("schematic")&&n.includes("trace")?$Lt:n.includes("copperpour")?jLt:n.includes("pack")?XLt:null},MVo=t=>`${h9e(`${t.componentName}-${t.solverName}`)}-solver-input.json`,eHt=t=>{VB(JSON.stringify(t.solverParams,null,2),{fileName:MVo(t),mimeType:"application/json"})},wVo=({solverEvent:t})=>{const e=ZLt(t.solverName);return W.jsxs("div",{className:"rf-flex rf-items-center rf-justify-end rf-gap-2 rf-border-b rf-border-gray-200 rf-bg-gray-50 rf-px-4 rf-py-2",children:[W.jsxs(qA,{type:"button",variant:"outline",size:"sm",onClick:()=>eHt(t),children:[W.jsx(fre,{className:"rf-w-4 rf-h-4"}),"Download"]}),e?W.jsx(qA,{asChild:!0,variant:"outline",size:"sm",children:W.jsxs("a",{href:e,target:"_blank",rel:"noopener noreferrer",children:[W.jsx(mre,{className:"rf-w-4 rf-h-4"}),"Report"]})}):W.jsxs(qA,{type:"button",variant:"outline",size:"sm",disabled:!0,title:"No report link configured for this solver",children:[W.jsx(mre,{className:"rf-w-4 rf-h-4"}),"Report"]})]})},NVo=({solverEvent:t})=>{const e=ZLt(t.solverName);return e?W.jsx(qA,{asChild:!0,variant:"ghost",size:"icon",className:"rf-h-8 rf-w-8",children:W.jsx("a",{href:e,target:"_blank",rel:"noopener noreferrer",title:"Report solver bug","aria-label":"Report solver bug",children:W.jsx(mre,{className:"rf-w-4 rf-h-4"})})}):W.jsx(qA,{type:"button",variant:"ghost",size:"icon",className:"rf-h-8 rf-w-8",disabled:!0,title:"No report link configured for this solver","aria-label":"Report solver bug",children:W.jsx(mre,{className:"rf-w-4 rf-h-4"})})},RVo=({solverEvents:t=[]})=>{const[e,n]=Z.useState(null);SVo();const o=Z.useMemo(()=>{const a=new Map;for(const A of t){const c=`${A.componentName}-${A.solverName}`;a.set(c,A)}return a},[t]),i=Z.useMemo(()=>Array.from(o.keys()),[o]),r=e?o.get(e):null,s=Z.useMemo(()=>{if(!r)return{instance:null,error:null,classFound:!1};const a=yBe[r.solverName];if(!a)return{instance:null,error:`Solver class "${r.solverName}" not found in SOLVERS registry. Available: ${Object.keys(yBe).join(", ")}`,classFound:!1};try{const A=r.solverParams,c=A?.input!==void 0?A.input:A;return{instance:new a(c),error:null,classFound:!0}}catch(A){const c=A instanceof Error?A.message:String(A);return console.error("Failed to reconstruct solver:",A),{instance:null,error:`Failed to instantiate solver: ${c}`,classFound:!0}}},[r]);return t.length===0?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:[i.length," ",i.length===1?"Solver":"Solvers"]}),i.map(a=>{const A=o.get(a),c=e===a;return W.jsx("div",{className:`rf-px-3 rf-py-2 rf-cursor-pointer rf-border-b rf-border-gray-100 ${c?"rf-bg-blue-50 rf-border-l-2 rf-border-l-blue-500":"hover:rf-bg-gray-50"}`,onClick:()=>n(a),children:(()=>{const l=vVo(A.solverName);return W.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[W.jsx(l,{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})]})]})})()},a)})]}),W.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:r?s.instance?W.jsxs("div",{className:"rf-flex rf-h-full rf-flex-col rf-overflow-y-auto",children:[W.jsx(wVo,{solverEvent:r}),W.jsx("div",{className:"rf-min-h-0 rf-flex-1",children:W.jsx(XS,{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"," ",r.solverName]})]})}),children:W.jsx(QVo,{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:r.solverName}),W.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",r.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.jsxs("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50 rf-flex rf-items-center rf-justify-between rf-gap-2",children:[W.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"}),W.jsxs("div",{className:"rf-flex rf-items-center rf-gap-1",children:[W.jsx(NVo,{solverEvent:r}),W.jsx(qA,{type:"button",variant:"ghost",size:"icon",className:"rf-h-8 rf-w-8","aria-label":"Download solver input JSON",title:"Download solver input JSON",onClick:()=>eHt(r),children:W.jsx(fre,{className:"rf-w-4 rf-h-4"})})]})]}),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(r.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"})})})]})},tHt=({errorMessage:t,errorStack:e,circuitJsonErrors:n})=>{Z.useEffect(()=>{if(t){const o=new Error(t);e&&(o.stack=e);try{H8.captureException(o)}catch{}}},[t,e]),Z.useEffect(()=>{if(n&&n.length>0)for(const o of n){const i=new Error(o.message||"Circuit JSON Error");o.stack&&(i.stack=o.stack);try{H8.captureException(i,{error_type:o.type})}catch{}}},[n])},TVo=t=>{Z.useEffect(()=>{try{Jqt(t)}catch{}},[t.source,t.component,t.isWebEmbedded,t.activeTab])},nHt="0.0.2475",kVo={version:nHt},_9e={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1},m9e=new Map,kse=t=>{const e=m9e.get(t);return e?Object.fromEntries(Object.entries(e.stores).map(([n,o])=>[n,o.getState()])):{}},FVo=(t,e,n)=>{if(t===void 0)return{type:"untracked",connection:e.connect(n)};const o=m9e.get(n.name);if(o)return{type:"tracked",store:t,...o};const i={connection:e.connect(n),stores:{}};return m9e.set(n.name,i),{type:"tracked",store:t,...i}},oHt=(t,e={})=>(n,o,i)=>{const{enabled:r,anonymousActionType:s,store:a,...A}=e;let c;try{c=(r??(_9e?"production":void 0)!=="production")&&window.__REDUX_DEVTOOLS_EXTENSION__}catch{}if(!c)return(_9e?"production":void 0)!=="production"&&r&&console.warn("[zustand devtools middleware] Please install/enable Redux devtools extension"),t(n,o,i);const{connection:l,...g}=FVo(a,c,A);let u=!0;i.setState=(_,m,p)=>{const I=n(_,m);if(!u)return I;const f=p===void 0?{type:s||"anonymous"}:typeof p=="string"?{type:p}:p;return a===void 0?(l?.send(f,o()),I):(l?.send({...f,type:`${a}/${f.type}`},{...kse(A.name),[a]:i.getState()}),I)};const h=(..._)=>{const m=u;u=!1,n(..._),u=m},d=t(i.setState,o,i);if(g.type==="untracked"?l?.init(d):(g.stores[g.store]=i,l?.init(Object.fromEntries(Object.entries(g.stores).map(([_,m])=>[_,_===g.store?d:m.getState()])))),i.dispatchFromDevtools&&typeof i.dispatch=="function"){let _=!1;const m=i.dispatch;i.dispatch=(...p)=>{(_9e?"production":void 0)!=="production"&&p[0].type==="__setState"&&!_&&(console.warn('[zustand devtools middleware] "__setState" action type is reserved to set state from the devtools. Avoid using it.'),_=!0),m(...p)}}return l.subscribe(_=>{var m;switch(_.type){case"ACTION":if(typeof _.payload!="string"){console.error("[zustand devtools middleware] Unsupported action format");return}return p9e(_.payload,p=>{if(p.type==="__setState"){if(a===void 0){h(p.state);return}Object.keys(p.state).length!==1&&console.error(`
|
|
5769
5769
|
[zustand devtools middleware] Unsupported __setState action format.
|
|
5770
5770
|
When using 'store' option in devtools(), the 'state' should have only one key, which is a value of 'store' that was passed in devtools(),
|
|
5771
5771
|
and value of this only key should be a state object. Example: { "type": "__setState", "state": { "abc123Store": { "foo": "bar" } } }
|