@tscircuit/runframe 0.0.1804 → 0.0.1806

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.
@@ -5415,7 +5415,7 @@ You passed in: '`+this.raw_options[o]+"'");return c},n.prototype._is_valid_selec
5415
5415
  `);break}}return s}}}),hjn=Ha({"node_modules/pretty/index.js"(t,e){var n=sjn(),r=djn(),i=Mut(),o={unformatted:["code","pre","em","strong","span"],indent_inner_html:!0,indent_char:" ",indent_size:2,sep:`
5416
5416
  `};e.exports=function(c,l){var u=i({},o,l);return c=n.html(c,u),u.ocd===!0?(u.newlines&&(u.sep=u.newlines),s(c,u)):c};function s(a,c){return r(a,c).replace(/^\s+/g,"").replace(/\s+$/g,`
5417
5417
  `).replace(/(\s*<!--)/g,`
5418
- $1`).replace(/>(\s*)(?=<!--\s*\/)/g,"> ")}}});function Tut(t,e,n){if(!e||!n)return;let r=t.get(e);r||(r=new Set,t.set(e,r)),r.add(n);let i=t.get(n);i||(i=new Set,t.set(n,i)),i.add(e)}function pjn(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]),c=new Map,l=new Map;for(const d of t)if(d.type==="source_group"){const h=d.source_group_id,f=d.subcircuit_id;f&&l.set(h,f);const p=d.parent_source_group_id;p&&(c.has(p)||c.set(p,[]),c.get(p).push(h))}let u;for(const[d,h]of l)if(h===e.subcircuit_id){u=d;break}if(u){const d=h=>{const f=c.get(h)||[];for(const p of f){const m=l.get(p);m&&a.add(m),d(p)}};d(u),n={...e,subcircuit_ids:Array.from(a)}}}const r=new Map;for(const a of t){const c=`${a.type}_id`,l=a[c];typeof l=="string"&&r.set(l,a)}const i=new Map;for(const a of t){const c=Object.entries(a);for(const[l,u]of c)if(l!=="parent_source_group_id"){if(l.endsWith("_id")&&typeof u=="string"){const d=r.get(u);Tut(i,a,d)}else if(l.endsWith("_ids")&&Array.isArray(u)){for(const d of u)if(typeof d=="string"){const h=r.get(d);Tut(i,a,h)}}}}const o=[],s=new Set;for(const a of t){let c=!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))&&(c=!0),c&&(o.push(a),s.add(a))}for(;o.length>0;){const a=o.shift(),c=i.get(a);if(c)for(const l of c)s.has(l)||(s.add(l),o.push(l))}return t.filter(a=>s.has(a))}var cG=(t,e={})=>{const n=t;let r=n._internal_store;if(!r){r={counts:{},editCount:0},n._internal_store=r;for(const o of n){const s=o.type,a=o[`${s}_id`];if(!a)continue;const c=Number.parseInt(a.split("_").pop());Number.isNaN(c)||(r.counts[s]=Math.max(r.counts[s]??0,c))}}const i=new Proxy({},{get:(o,s)=>{if(s==="toArray")return()=>(n.editCount=r.editCount,n);if(s==="editCount")return r.editCount;if(s==="subtree")return c=>cG(pjn(n,c),e);if(s==="insert")return c=>{const l=c.type;if(!l)throw new Error("insert requires an element with a type");r.counts[l]??=-1,r.counts[l]++;const u=r.counts[l],d={...c,type:l,[`${l}_id`]:`${l}_${u}`};return e.validateInserts&&(e_e[l]??OV).parse(d),n.push(d),r.editCount++,d};if(s==="insertAll")return c=>c.map(l=>i.insert(l));const a=s;return{get:c=>n.find(l=>l.type===a&&l[`${a}_id`]===c),getUsing:c=>{const l=Object.keys(c);if(l.length!==1)throw new Error("getUsing requires exactly one key, e.g. { pcb_component_id }");const u=l[0],d=u.replace("_id",""),h=n.find(f=>f.type===d&&f[u]===c[u]);return h?n.find(f=>f.type===a&&f[`${a}_id`]===h[`${a}_id`]):null},getWhere:c=>{const l=Object.keys(c);return n.find(u=>u.type===a&&l.every(d=>u[d]===c[d]))},list:c=>{const l=c?Object.keys(c):[];return n.filter(u=>u.type===a&&l.every(d=>u[d]===c[d]))},insert:c=>{r.counts[a]??=-1,r.counts[a]++;const l=r.counts[a],u={type:a,[`${a}_id`]:`${a}_${l}`,...c};return e.validateInserts&&(e_e[a]??OV).parse(u),n.push(u),r.editCount++,u},delete:c=>{const l=n.find(u=>u[`${a}_id`]===c);l&&(n.splice(n.indexOf(l),1),r.editCount++)},update:(c,l)=>{const u=n.find(d=>d.type===a&&d[`${a}_id`]===c);return u?(Object.assign(u,l),r.editCount++,u):null},select:c=>{if(a==="source_component")return n.find(l=>l.type==="source_component"&&l.name===c.replace(/\./g,""));if(a==="pcb_port"||a==="source_port"||a==="schematic_port"){const[l,u]=c.replace(/\./g,"").split(/[\s\>]+/),d=n.find(f=>f.type==="source_component"&&f.name===l);if(!d)return null;const h=n.find(f=>f.type==="source_port"&&f.source_component_id===d.source_component_id&&(f.name===u||(f.port_hints??[]).includes(u)));if(!h)return null;if(a==="source_port")return h;if(a==="pcb_port")return n.find(f=>f.type==="pcb_port"&&f.source_port_id===h.source_port_id);if(a==="schematic_port")return n.find(f=>f.type==="schematic_port"&&f.source_port_id===h.source_port_id)}}}}});return i};cG.unparsed=cG;var B9=cG;function D_e(t){const e=t.type;return`${e}:${t[`${e}_id`]}`}var Eut=(t,e={})=>{let n=t._internal_store_indexed;if(!n){n={counts:{},editCount:0,indexes:{}};for(const s of t){const a=s.type,c=s[`${a}_id`];if(!c)continue;const l=Number.parseInt(c.split("_").pop()||"");Number.isNaN(l)||(n.counts[a]=Math.max(n.counts[a]??0,l))}const i=e.indexConfig||{},o=n.indexes;if(i.byId&&(o.byId=new Map),i.byType&&(o.byType=new Map),i.byRelation&&(o.byRelation=new Map),i.bySubcircuit&&(o.bySubcircuit=new Map),i.byCustomField&&i.byCustomField.length>0){o.byCustomField=new Map;for(const s of i.byCustomField)o.byCustomField.set(s,new Map)}for(const s of t){if(i.byId){const a=D_e(s);o.byId.set(a,s)}if(i.byType){const a=o.byType.get(s.type)||[];a.push(s),o.byType.set(s.type,a)}if(i.byRelation){const a=Object.entries(s);for(const[c,l]of a)if(c.endsWith("_id")&&c!==`${s.type}_id`&&typeof l=="string"){const u=o.byRelation.get(c)||new Map,d=u.get(l)||[];d.push(s),u.set(l,d),o.byRelation.set(c,u)}}if(i.bySubcircuit&&"subcircuit_id"in s){const a=s.subcircuit_id;if(a&&typeof a=="string"){const c=o.bySubcircuit.get(a)||[];c.push(s),o.bySubcircuit.set(a,c)}}if(i.byCustomField&&o.byCustomField){for(const a of i.byCustomField)if(a in s){const c=s[a];if(c!==void 0&&(typeof c=="string"||typeof c=="number")){const l=String(c),u=o.byCustomField.get(a),d=u.get(l)||[];d.push(s),u.set(l,d)}}}}t._internal_store_indexed=n}return new Proxy({},{get:(i,o)=>{if(o==="toArray")return()=>(t.editCount=n.editCount,t);if(o==="editCount")return n.editCount;const s=o;return{get:a=>{const c=e.indexConfig||{};return c.byId&&n.indexes.byId?n.indexes.byId.get(`${s}:${a}`)||null:c.byType&&n.indexes.byType?(n.indexes.byType.get(s)||[]).find(u=>u[`${s}_id`]===a)||null:t.find(l=>l.type===s&&l[`${s}_id`]===a)||null},getUsing:a=>{const c=e.indexConfig||{},l=Object.keys(a);if(l.length!==1)throw new Error("getUsing requires exactly one key, e.g. { pcb_component_id }");const u=l[0],d=u.replace("_id","");if(c.byRelation&&n.indexes.byRelation){const f=n.indexes.byRelation.get(u);if(f){const m=(f.get(a[u])||[]).find(y=>y.type===d);if(!m)return null;const g=m[`${s}_id`];return c.byId&&n.indexes.byId?n.indexes.byId.get(`${s}:${g}`)||null:c.byType&&n.indexes.byType?(n.indexes.byType.get(s)||[]).find(_=>_[`${s}_id`]===g)||null:t.find(y=>y.type===s&&y[`${s}_id`]===g)||null}}const h=t.find(f=>f.type===d&&f[u]===a[u]);return h&&t.find(f=>f.type===s&&f[`${s}_id`]===h[`${s}_id`])||null},getWhere:a=>{const c=e.indexConfig||{},l=Object.keys(a);if(l.length===1&&c.byCustomField&&n.indexes.byCustomField){const u=l[0],d=n.indexes.byCustomField.get(u);if(d){const h=String(a[u]);return(d.get(h)||[]).find(p=>p.type===s)||null}}if("subcircuit_id"in a&&c.bySubcircuit&&n.indexes.bySubcircuit){const u=a.subcircuit_id;return(n.indexes.bySubcircuit.get(u)||[]).find(h=>h.type===s&&l.every(f=>h[f]===a[f]))||null}return c.byType&&n.indexes.byType?(n.indexes.byType.get(s)||[]).find(d=>l.every(h=>d[h]===a[h]))||null:t.find(u=>u.type===s&&l.every(d=>u[d]===a[d]))||null},list:a=>{const c=e.indexConfig||{},l=a?Object.keys(a):[];if(l.length===0&&c.byType&&n.indexes.byType)return n.indexes.byType.get(s)||[];if(l.length===1&&l[0]==="subcircuit_id"&&c.bySubcircuit&&n.indexes.bySubcircuit){const d=a.subcircuit_id;return(n.indexes.bySubcircuit.get(d)||[]).filter(f=>f.type===s)}let u;return c.byType&&n.indexes.byType?u=n.indexes.byType.get(s)||[]:u=t.filter(d=>d.type===s),l.length>0?u.filter(d=>l.every(h=>d[h]===a[h])):u},insert:a=>{n.counts[s]??=-1,n.counts[s]++;const c=n.counts[s],l={type:s,[`${s}_id`]:`${s}_${c}`,...a};e.validateInserts&&(e_e[s]??OV).parse(l),t.push(l),n.editCount++;const u=e.indexConfig||{};if(u.byId&&n.indexes.byId){const d=D_e(l);n.indexes.byId.set(d,l)}if(u.byType&&n.indexes.byType){const d=n.indexes.byType.get(s)||[];d.push(l),n.indexes.byType.set(s,d)}if(u.byRelation&&n.indexes.byRelation){const d=Object.entries(l);for(const[h,f]of d)if(h.endsWith("_id")&&h!==`${l.type}_id`&&typeof f=="string"){const p=n.indexes.byRelation.get(h)||new Map,m=p.get(f)||[];m.push(l),p.set(f,m),n.indexes.byRelation.set(h,p)}}if(u.bySubcircuit&&n.indexes.bySubcircuit&&"subcircuit_id"in l){const d=l.subcircuit_id;if(d&&typeof d=="string"){const h=n.indexes.bySubcircuit.get(d)||[];h.push(l),n.indexes.bySubcircuit.set(d,h)}}if(u.byCustomField&&n.indexes.byCustomField){for(const d of u.byCustomField)if(d in l){const h=l[d];if(h!==void 0&&(typeof h=="string"||typeof h=="number")){const f=String(h),p=n.indexes.byCustomField.get(d),m=p.get(f)||[];m.push(l),p.set(f,m)}}}return l},delete: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(h=>h[`${s}_id`]===a):l=t.find(d=>d[`${s}_id`]===a),!l)return;const u=t.indexOf(l);if(u>=0&&(t.splice(u,1),n.editCount++),c.byId&&n.indexes.byId){const d=D_e(l);n.indexes.byId.delete(d)}if(c.byType&&n.indexes.byType){const h=(n.indexes.byType.get(s)||[]).filter(f=>f[`${s}_id`]!==a);n.indexes.byType.set(s,h)}if(c.byRelation&&n.indexes.byRelation)for(const[d,h]of n.indexes.byRelation.entries())for(const[f,p]of h.entries()){const m=p.filter(g=>g!==l);m.length===0?h.delete(f):h.set(f,m)}if(c.bySubcircuit&&n.indexes.bySubcircuit&&"subcircuit_id"in l){const d=l.subcircuit_id;if(d){const f=(n.indexes.bySubcircuit.get(d)||[]).filter(p=>p!==l);f.length===0?n.indexes.bySubcircuit.delete(d):n.indexes.bySubcircuit.set(d,f)}}if(c.byCustomField&&n.indexes.byCustomField)for(const d of n.indexes.byCustomField.values())for(const[h,f]of d.entries()){const p=f.filter(m=>m!==l);p.length===0?d.delete(h):d.set(h,p)}},update:(a,c)=>{const l=e.indexConfig||{};let u;if(l.byId&&n.indexes.byId?u=n.indexes.byId.get(`${s}:${a}`):l.byType&&n.indexes.byType?u=(n.indexes.byType.get(s)||[]).find(h=>h[`${s}_id`]===a):u=t.find(d=>d.type===s&&d[`${s}_id`]===a),!u)return null;if(l.byRelation&&n.indexes.byRelation){const d=Object.entries(u);for(const[h,f]of d)if(h.endsWith("_id")&&h!==`${u.type}_id`&&typeof f=="string"&&h in c&&c[h]!==f){const p=n.indexes.byRelation.get(h);if(p){const g=(p.get(f)||[]).filter(y=>y!==u);g.length===0?p.delete(f):p.set(f,g)}}}if(l.bySubcircuit&&n.indexes.bySubcircuit&&"subcircuit_id"in u&&"subcircuit_id"in c){const d=u.subcircuit_id,h=c.subcircuit_id;if(d!==h){const p=(n.indexes.bySubcircuit.get(d)||[]).filter(m=>m!==u);p.length===0?n.indexes.bySubcircuit.delete(d):n.indexes.bySubcircuit.set(d,p)}}if(l.byCustomField&&n.indexes.byCustomField){for(const d of l.byCustomField)if(d in u&&d in c&&u[d]!==c[d]){const h=n.indexes.byCustomField.get(d);if(h){const f=String(u[d]),m=(h.get(f)||[]).filter(g=>g!==u);m.length===0?h.delete(f):h.set(f,m)}}}if(Object.assign(u,c),n.editCount++,l.byRelation&&n.indexes.byRelation){const d=Object.entries(u);for(const[h,f]of d)if(h.endsWith("_id")&&h!==`${u.type}_id`&&typeof f=="string"&&h in c){const p=n.indexes.byRelation.get(h)||new Map,m=p.get(f)||[];m.includes(u)||(m.push(u),p.set(f,m),n.indexes.byRelation.set(h,p))}}if(l.bySubcircuit&&n.indexes.bySubcircuit&&"subcircuit_id"in u&&"subcircuit_id"in c){const d=u.subcircuit_id;if(d&&typeof d=="string"){const h=n.indexes.bySubcircuit.get(d)||[];h.includes(u)||(h.push(u),n.indexes.bySubcircuit.set(d,h))}}if(l.byCustomField&&n.indexes.byCustomField){for(const d of l.byCustomField)if(d in u&&d in c){const h=u[d];if(h!==void 0&&(typeof h=="string"||typeof h=="number")){const f=String(h),p=n.indexes.byCustomField.get(d),m=p.get(f)||[];m.includes(u)||(m.push(u),p.set(f,m))}}}return u},select:a=>{if(s==="source_component")return t.find(c=>c.type==="source_component"&&c.name===a.replace(/\./g,""))||null;if(s==="pcb_port"||s==="source_port"||s==="schematic_port"){const[c,l]=a.replace(/\./g,"").split(/[\s\>]+/),u=t.find(h=>h.type==="source_component"&&h.name===c);if(!u)return null;const d=t.find(h=>h.type==="source_port"&&h.source_component_id===u.source_component_id&&(h.name===l||(h.port_hints??[]).includes(l)));if(!d)return null;if(s==="source_port")return d;if(s==="pcb_port")return t.find(h=>h.type==="pcb_port"&&h.source_port_id===d.source_port_id)||null;if(s==="schematic_port")return t.find(h=>h.type==="schematic_port"&&h.source_port_id===d.source_port_id)||null}return null}}}})};Eut.unparsed=Eut;var fjn=t=>{const e=t.type;return t[`${e}_id`]},Cut=(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)}),lG=(t,e,n)=>{const r=n/2;return{minX:t-r,minY:e-r,maxX:t+r,maxY:e+r}},mjn=(t,e,n,r,i)=>{const o=n/2,s=r/2,a=i*Math.PI/180,c=Math.cos(a),l=Math.sin(a),u=[{x:-o,y:-s},{x:o,y:-s},{x:o,y:s},{x:-o,y:s}].map(d=>({x:t+d.x*c-d.y*l,y:e+d.x*l+d.y*c}));return{minX:Math.min(...u.map(d=>d.x)),minY:Math.min(...u.map(d=>d.y)),maxX:Math.max(...u.map(d=>d.x)),maxY:Math.max(...u.map(d=>d.y))}},z_e=t=>{let e=Number.POSITIVE_INFINITY,n=Number.POSITIVE_INFINITY,r=Number.NEGATIVE_INFINITY,i=Number.NEGATIVE_INFINITY;for(const o of t){if(!o.type.startsWith("pcb_"))continue;if(o.type==="pcb_smtpad"&&o.shape==="polygon"&&Array.isArray(o.points)){for(const u of o.points)e=Math.min(e,u.x),n=Math.min(n,u.y),r=Math.max(r,u.x),i=Math.max(i,u.y);continue}if(o.type==="pcb_hole"&&o.hole_shape==="circle"){const u=lG(o.x,o.y,o.hole_diameter);e=Math.min(e,u.minX),n=Math.min(n,u.minY),r=Math.max(r,u.maxX),i=Math.max(i,u.maxY);continue}if(o.type==="pcb_plated_hole"){let u;if("outer_diameter"in o&&typeof o.outer_diameter=="number"?u=lG(o.x,o.y,o.outer_diameter):"hole_diameter"in o&&typeof o.hole_diameter=="number"&&(u=lG(o.x,o.y,o.hole_diameter)),"rect_pad_width"in o&&typeof o.rect_pad_width=="number"&&"rect_pad_height"in o&&typeof o.rect_pad_height=="number"){const d=mjn(o.x,o.y,o.rect_pad_width,o.rect_pad_height,"rect_ccw_rotation"in o?o.rect_ccw_rotation??0:0);u=u?Cut(u,d):d}if("hole_diameter"in o&&typeof o.hole_diameter=="number"){const d=lG(o.x+("hole_offset_x"in o?o.hole_offset_x??0:0),o.y+("hole_offset_y"in o?o.hole_offset_y??0:0),o.hole_diameter);u=u?Cut(u,d):d}if(u){e=Math.min(e,u.minX),n=Math.min(n,u.minY),r=Math.max(r,u.maxX),i=Math.max(i,u.maxY);continue}}let s,a,c,l;if("x"in o&&"y"in o&&(s=Number(o.x),a=Number(o.y)),"outer_diameter"in o&&(c=Number(o.outer_diameter),l=Number(o.outer_diameter)),"width"in o&&(c=Number(o.width)),"height"in o&&(l=Number(o.height)),"center"in o&&(s=o.center.x,a=o.center.y),s!==void 0&&a!==void 0)e=Math.min(e,s),n=Math.min(n,a),r=Math.max(r,s),i=Math.max(i,a),c!==void 0&&l!==void 0&&(e=Math.min(e,s-c/2),n=Math.min(n,a-l/2),r=Math.max(r,s+c/2),i=Math.max(i,a+l/2)),"radius"in o&&(e=Math.min(e,s-o.radius),n=Math.min(n,a-o.radius),r=Math.max(r,s+o.radius),i=Math.max(i,a+o.radius));else if(o.type==="pcb_trace")for(const u of o.route)e=Math.min(e,u.x),n=Math.min(n,u.y),r=Math.max(r,u.x),i=Math.max(i,u.y);else if(o.type==="pcb_courtyard_outline")for(const u of o.outline)e=Math.min(e,u.x),n=Math.min(n,u.y),r=Math.max(r,u.x),i=Math.max(i,u.y);else if(o.type==="pcb_courtyard_polygon")for(const u of o.points)e=Math.min(e,u.x),n=Math.min(n,u.y),r=Math.max(r,u.x),i=Math.max(i,u.y)}return{minX:e,minY:n,maxX:r,maxY:i}};function yjn(t){let e=0;if(t.length==0)return e;for(var n=0;n<t.length;n++){var r=t.charCodeAt(n);e=(e<<5)-e+r,e=e&e}return Math.abs(e)}var Put=[["#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"]],gjn=t=>{let{x:e,y:n,width:r,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,r=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(f=>f.x),c=t.points.map(f=>f.y),l=Math.min(...a),u=Math.max(...a),d=Math.min(...c),h=Math.max(...c);e=(l+u)/2,n=(d+h)/2,r=u-l,i=h-d}const o=t.text||t.name||t.source?.text||t.source?.name||"?",s=t;return e===void 0||n===void 0?null:(r===void 0&&"outer_diameter"in t&&(r=t.outer_diameter,i=t.outer_diameter),(r===void 0||i===void 0)&&(r=.1,i=.1),{x:e,y:n,width:r,height:i,title:o,content:s,bg_color:Put[yjn(t.type||o)%Put.length]?.[4]??"#f00"})},_jn=t=>!!t,xjn=t=>{const e=t.filter(l=>l.type.startsWith("pcb_")||l.type.startsWith("schematic_")).concat(t.filter(l=>l.type==="pcb_trace"||l.type==="schematic_trace").flatMap(l=>l.route)).map(l=>gjn(l)).filter(_jn);if(e.length===0)return{center:{x:0,y:0},width:0,height:0};let n=e[0].x-e[0].width/2,r=e[0].x+e[0].width/2,i=e[0].y-e[0].height/2,o=e[0].y+e[0].height/2;for(const l of e.slice(1))n=Math.min(n,l.x-l.width/2),r=Math.max(r,l.x+l.width/2),i=Math.min(i,l.y-l.height/2),o=Math.max(o,l.y+l.height/2);const s=r-n,a=o-i;return{center:{x:n+s/2,y:i+a/2},width:s,height:a}},dy={IS_SHOWING_PCB_GROUPS:"pcb_viewer_is_showing_pcb_groups",PCB_GROUP_VIEW_MODE:"pcb_viewer_group_view_mode",IS_SHOWING_COPPER_POURS:"pcb_viewer_is_showing_copper_pours",IS_SHOWING_COURTYARDS:"pcb_viewer_is_showing_courtyards",IS_SHOWING_GROUP_ANCHOR_OFFSETS:"pcb_viewer_is_showing_group_anchor_offsets",IS_SHOWING_SOLDER_MASK:"pcb_viewer_is_showing_solder_mask",IS_SHOWING_FABRICATION_NOTES:"pcb_viewer_is_showing_fabrication_notes",IS_SHOWING_SILKSCREEN:"pcb_viewer_is_showing_silkscreen"},CS=(t,e)=>{if(typeof window>"u")return e;try{const n=localStorage.getItem(t);return n!==null?JSON.parse(n):e}catch{return e}},PS=(t,e)=>{if(!(typeof window>"u"))try{localStorage.setItem(t,JSON.stringify(e))}catch{}},bjn=(t,e)=>{if(typeof window>"u")return e;try{const n=localStorage.getItem(t);return n!==null?JSON.parse(n):e}catch{return e}},vjn=(t,e)=>{if(!(typeof window>"u"))try{localStorage.setItem(t,JSON.stringify(e))}catch{}},wjn="named_only",Sjn=(t={},e=!1)=>ilt(n=>({selected_layer:"top",pcb_viewer_id:`pcb_viewer_${Math.random().toString().slice(2,10)}`,in_edit_mode:!1,in_move_footprint_mode:!1,in_draw_trace_mode:!1,is_moving_component:!1,is_drawing_trace:!1,is_mouse_over_container:!1,is_showing_multiple_traces_length:!1,is_showing_rats_nest:!1,is_showing_autorouting:!0,is_showing_drc_errors:!0,is_showing_copper_pours:CS(dy.IS_SHOWING_COPPER_POURS,!0),is_showing_courtyards:CS(dy.IS_SHOWING_COURTYARDS,!0),is_showing_pcb_groups:e?!1:CS(dy.IS_SHOWING_PCB_GROUPS,!0),is_showing_group_anchor_offsets:CS(dy.IS_SHOWING_GROUP_ANCHOR_OFFSETS,!1),is_showing_solder_mask:CS(dy.IS_SHOWING_SOLDER_MASK,!1),is_showing_silkscreen:CS(dy.IS_SHOWING_SILKSCREEN,!0),is_showing_fabrication_notes:CS(dy.IS_SHOWING_FABRICATION_NOTES,!1),pcb_group_view_mode:e?"all":bjn(dy.PCB_GROUP_VIEW_MODE,wjn),hovered_error_id:null,...t,selectLayer:r=>n({selected_layer:r}),setEditMode:r=>n({in_edit_mode:r!=="off",in_move_footprint_mode:r==="move_footprint",in_draw_trace_mode:r==="draw_trace",is_moving_component:!1,is_drawing_trace:!1}),setIsShowingRatsNest:r=>n({is_showing_rats_nest:r}),setIsMovingComponent:r=>n({is_moving_component:r}),setIsDrawingTrace:r=>n({is_drawing_trace:r}),setIsMouseOverContainer:r=>n({is_mouse_over_container:r}),setIsShowingMultipleTracesLength:r=>n({is_showing_multiple_traces_length:r}),setIsShowingAutorouting:r=>n({is_showing_autorouting:r}),setIsShowingDrcErrors:r=>n({is_showing_drc_errors:r}),setIsShowingCopperPours:r=>{PS(dy.IS_SHOWING_COPPER_POURS,r),n({is_showing_copper_pours:r})},setIsShowingCourtyards:r=>{PS(dy.IS_SHOWING_COURTYARDS,r),n({is_showing_courtyards:r})},setIsShowingPcbGroups:r=>{e||(PS(dy.IS_SHOWING_PCB_GROUPS,r),n({is_showing_pcb_groups:r}))},setIsShowingGroupAnchorOffsets:r=>{PS(dy.IS_SHOWING_GROUP_ANCHOR_OFFSETS,r),n({is_showing_group_anchor_offsets:r})},setIsShowingSolderMask:r=>{PS(dy.IS_SHOWING_SOLDER_MASK,r),n({is_showing_solder_mask:r})},setIsShowingSilkscreen:r=>{PS(dy.IS_SHOWING_SILKSCREEN,r),n({is_showing_silkscreen:r})},setIsShowingFabricationNotes:r=>{PS(dy.IS_SHOWING_FABRICATION_NOTES,r),n({is_showing_fabrication_notes:r})},setPcbGroupViewMode:r=>{e||(vjn(dy.PCB_GROUP_VIEW_MODE,r),n({pcb_group_view_mode:r}))},setHoveredErrorId:r=>n({hovered_error_id:r})})),E0=t=>{const e=te.useContext(Aut);return flt(e,t)},Aut=te.createContext(null),Mjn=({children:t,initialState:e,disablePcbGroups:n})=>{const r=te.useMemo(()=>Sjn(e,n),[n]);return G.jsx(Aut.Provider,{value:r,children:t})},Tjn=()=>{const t=E0(n=>n.pcb_viewer_id),e=(n,r)=>Tl(n,{containerId:t,...r});return e.error=(n,r)=>Tl.error(n,{containerId:t,...r}),e.promise=Tl.promise,e},Ejn=()=>{te.useEffect(()=>{m$n()},[]);const t=E0(e=>e.pcb_viewer_id);return G.jsx(f$n,{position:"top-center",containerId:t})};function Cjn(){var t=te.useRef(!1),e=te.useCallback(function(){return t.current},[]);return te.useEffect(function(){return t.current=!0,function(){t.current=!1}},[]),e}var Pjn=function(t){t===void 0&&(t={});var e=te.useState(t),n=e[0],r=e[1],i=te.useCallback(function(o){r(function(s){return Object.assign({},s,o instanceof Function?o(s):o)})},[]);return[n,i]},Ajn=Pjn,Rjn=function(){},Rut=typeof window<"u",Ijn=I_e(WBn()),Njn=function(){var t=Cjn(),e=Ajn({value:void 0,error:void 0,noUserInteraction:!0}),n=e[0],r=e[1],i=te.useCallback(function(o){if(t()){var s,a;try{if(typeof o!="string"&&typeof o!="number"){var c=new Error("Cannot copy typeof "+typeof o+" to clipboard, must be a string");console.error(c),r({value:o,error:c,noUserInteraction:!0});return}else if(o===""){var c=new Error("Cannot copy empty string to clipboard.");console.error(c),r({value:o,error:c,noUserInteraction:!0});return}a=o.toString(),s=(0,Ijn.default)(a),r({value:a,error:void 0,noUserInteraction:s})}catch(l){r({value:a,error:l,noUserInteraction:s})}}},[]);return[n,i]},kjn=Njn,Ojn=Rut?te.useLayoutEffect:te.useEffect,Ljn=Ojn,Iut={x:0,y:0,width:0,height:0,top:0,left:0,bottom:0,right:0};function Djn(){var t=te.useState(null),e=t[0],n=t[1],r=te.useState(Iut),i=r[0],o=r[1],s=te.useMemo(function(){return new window.ResizeObserver(function(a){if(a[0]){var c=a[0].contentRect,l=c.x,u=c.y,d=c.width,h=c.height,f=c.top,p=c.left,m=c.bottom,g=c.right;o({x:l,y:u,width:d,height:h,top:f,left:p,bottom:m,right:g})}})},[]);return Ljn(function(){if(e)return s.observe(e),function(){s.disconnect()}},[e]),[n,i]}var gO=Rut&&typeof window.ResizeObserver<"u"?Djn:function(){return[Rjn,Iut]},Nut=({initialTransform:t,initialTouch1:e,initialTouch2:n,finalTouch1:r,finalTouch2:i})=>{if(!r||!i)return t;const o={x:(e.x+n.x)/2,y:(e.y+n.y)/2},s={x:(r.x+i.x)/2,y:(r.y+i.y)/2},a=Math.hypot(n.x-e.x,n.y-e.y),c=Math.hypot(i.x-r.x,i.y-r.y),l=a===0?1:c/a,u=s.x-o.x,d=s.y-o.y;return di(_i(u,d),_i(o.x,o.y),Zu(l,l),_i(-o.x,-o.y),t)},zjn=(t={})=>{const e=te.useRef(null),[n,r]=te.useState(0),i=t.canvasElm??e.current,[o,s]=te.useState(t.initialTransform??el()),[a,c]=te.useState(0),[l,u]=te.useReducer(x=>x+1,0),d=te.useCallback(x=>{t.onSetTransform&&t.onSetTransform(x),t.transform||s(x)},[t.onSetTransform,s]),h=te.useCallback(x=>{d(x),u()},[d]),f=t.transform??o,p=te.useCallback(()=>{r(Date.now())},[]),m=te.useRef("none"),g=te.useRef(null),y=te.useRef(null);te.useEffect(()=>{const x=t.canvasElm??e.current;if(x&&!i){c(a+1);return}if(!x){const q=setTimeout(()=>{c(a+1)},100);return()=>clearTimeout(q)}let b=t.transform??o,w={x:0,y:0},S={x:0,y:0},T=!1;const C=q=>({x:q.pageX-x.getBoundingClientRect().left-window.scrollX,y:q.pageY-x.getBoundingClientRect().top-window.scrollY});function A(q){t.enabled!==!1&&(t.shouldDrag&&!t.shouldDrag(q)||(w=C(q),!(Date.now()-n<100)&&(T=!0,q.preventDefault())))}function R(q){if(!T||t.enabled===!1||t.shouldDrag&&!t.shouldDrag(q))return;S=C(q);const K=di(_i(S.x-w.x,S.y-w.y),b);d(K),b=K,T=!1}function L(q){if(C(q),!T||t.enabled===!1||t.shouldDrag&&!t.shouldDrag(q))return;S=C(q);const K=di(_i(S.x-w.x,S.y-w.y),b);d(K)}function O(q){if(t.enabled===!1||t.shouldDrag&&!t.shouldDrag(q))return;const K=C(q),ne=di(_i(K.x,K.y),Zu(1-q.deltaY/1e3,1-q.deltaY/1e3),_i(-K.x,-K.y),b);d(ne),b=ne,q.preventDefault()}function F(q){if(!T||t.shouldDrag&&!t.shouldDrag(q))return;if(x){const ne=x.getBoundingClientRect();if(q.clientX>=ne.left+10&&q.clientX<=ne.right-10&&q.clientY>=ne.top+10&&q.clientY<=ne.bottom-10)return}T=!1,S=C(q);const K=di(_i(S.x-w.x,S.y-w.y),b);d(K),b=K}function B(q){if(q.preventDefault(),t.enabled!==!1){if(q.touches.length===1){m.current="drag";const K=q.touches[0];g.current={initialTransform:b,initialTouch:{x:K.clientX,y:K.clientY}}}else if(q.touches.length===2){m.current="pinch";const K=q.touches[0],ne=q.touches[1];y.current={initialTransform:b,initialTouch1:{x:K.clientX,y:K.clientY},initialTouch2:{x:ne.clientX,y:ne.clientY},finalTouch1:null,finalTouch2:null}}}}function j(q){if(q.preventDefault(),t.enabled!==!1){if(m.current==="drag"&&q.touches.length===1&&g.current){const K=q.touches[0],ne={x:K.clientX,y:K.clientY},le=ne.x-g.current.initialTouch.x,ee=ne.y-g.current.initialTouch.y,ie=di(_i(le,ee),g.current.initialTransform);d(ie)}else if(m.current==="pinch"&&q.touches.length===2&&y.current){const K=q.touches[0],ne=q.touches[1];y.current.finalTouch1={x:K.clientX,y:K.clientY},y.current.finalTouch2={x:ne.clientX,y:ne.clientY};const le=Nut(y.current);d(le)}}}function V(q){q.preventDefault();const K=q.changedTouches[0];if(m.current==="drag"&&g.current&&K){const ne={x:K.clientX,y:K.clientY},le=ne.x-g.current.initialTouch.x,ee=ne.y-g.current.initialTouch.y,ie=di(_i(le,ee),g.current.initialTransform);d(ie),b=ie}else if(m.current==="pinch"&&y.current){const ne=Nut(y.current);d(ne),b=ne}m.current="none",g.current=null,y.current=null}return x.addEventListener("mousedown",A),x.addEventListener("mouseup",R),window.addEventListener("mousemove",L),x.addEventListener("mouseout",F),x.addEventListener("wheel",O),x.addEventListener("touchstart",B,{passive:!1}),x.addEventListener("touchmove",j,{passive:!1}),x.addEventListener("touchend",V,{passive:!1}),x.addEventListener("touchcancel",V,{passive:!1}),()=>{x.removeEventListener("mousedown",A),x.removeEventListener("mouseup",R),window.removeEventListener("mousemove",L),x.removeEventListener("mouseout",F),x.removeEventListener("wheel",O),x.removeEventListener("touchstart",B),x.removeEventListener("touchmove",j),x.removeEventListener("touchend",V),x.removeEventListener("touchcancel",V)}},[i,a,l,n,t.enabled,t.shouldDrag]);const _=te.useCallback(x=>mt(f,x),[f]);return{ref:e,transform:f,applyTransformToPoint:_,setTransform:h,cancelDrag:p}},$jn=zjn;function Fjn(t){const e=new Map;let n=0;function r(i){for(const[,s]of e)if(s.has(i))return s;const o=new Set;return e.set(`connectivity_net${n++}`,o),o}for(const i of t){let o=null;for(const s of i){if(!o)o=r(s);else if(!o.has(s)){const a=r(s);if(a!==o){for(const c of a)o.add(c);e.delete(Array.from(e.entries()).find(([,c])=>c===a)[0])}}o.add(s)}}return Object.fromEntries(Array.from(e.entries()).map(([i,o])=>[i,Array.from(o)]))}var Bjn=class{netMap;idToNetMap;constructor(t){this.netMap=t,this.idToNetMap={};for(const[e,n]of Object.entries(t))for(const r of n)this.idToNetMap[r]=e}addConnections(t){for(const e of t){const n=new Set;for(const i of e){const o=this.idToNetMap[i];o&&n.add(o)}let r;if(n.size===0)r=`connectivity_net${Object.keys(this.netMap).length}`,this.netMap[r]=[];else if(n.size===1)r=n.values().next().value??`connectivity_net${Object.keys(this.netMap).length}`;else{r=n.values().next().value??`connectivity_net${Object.keys(this.netMap).length}`;for(const i of n)if(i!==r){this.netMap[r].push(...this.netMap[i]),this.netMap[i]=this.netMap[r];for(const o of this.netMap[r])this.idToNetMap[o]=r}}for(const i of e)this.netMap[r].includes(i)||this.netMap[r].push(i),this.idToNetMap[i]=r}}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 r=this.getNetConnectedToId(e);return r?n===r||r===t||r===t:!1}areAllIdsConnected(t){const e=this.getNetConnectedToId(t[0]);for(const n of t){const r=this.getNetConnectedToId(n);if(r===void 0||r!==e)return!1}return!0}},kut=t=>{const e=[];for(const r of t)if(r.type==="source_trace")e.push([r.source_trace_id,...r.connected_source_port_ids??[],...r.connected_source_net_ids??[]].filter(Boolean));else if(r.type==="pcb_port"){const{pcb_port_id:i,source_port_id:o}=r;o&&i&&e.push([o,i])}else if(r.type==="pcb_smtpad"){const{pcb_smtpad_id:i,pcb_port_id:o}=r;o&&i&&e.push([i,o])}else if(r.type==="pcb_plated_hole"){const{pcb_plated_hole_id:i,pcb_port_id:o}=r;o&&i&&e.push([i,o])}else if(r.type==="pcb_trace"){const{pcb_trace_id:i,source_trace_id:o}=r,s=Array.isArray(r.route)?r.route.filter(a=>a&&a.route_type==="wire"):[];if(o&&i&&e.push([i,o]),Array.isArray(s)){const a=s.find(l=>l?.start_pcb_port_id)?.start_pcb_port_id,c=s.find(l=>l?.end_pcb_port_id)?.end_pcb_port_id;a&&i&&c&&e.push([a,i,c])}}else if(r.type==="pcb_via"){const{pcb_via_id:i,pcb_trace_id:o}=r;o&&i&&e.push([i,o])}else if(r.type==="source_component"&&r.internally_connected_source_port_ids)for(const i of r.internally_connected_source_port_ids)e.push(i);const n=Fjn(e);return new Bjn(n)};function jjn({primitivesWithoutInteractionMetadata:t,drawingObjectIdsWithMouseOver:e,primitiveIdsInMousedOverNet:n}){const r=[];for(const i of t){const o={...i};i?.layer==="drill"?(o.is_in_highlighted_net=!1,o.is_mouse_over=!1):e.has(i._pcb_drawing_object_id)?o.is_mouse_over=!0:i._element&&("pcb_trace_id"in i._element&&n.includes(i._element.pcb_trace_id)||"pcb_port_id"in i._element&&n.includes(i._element.pcb_port_id))?o.is_in_highlighted_net=!0:(o.is_in_highlighted_net=!1,o.is_mouse_over=!1),r.push(o)}return r}function Ujn(t,e){if(t.length<2)throw new Error("Stroke must have at least two points");const n=t.map(d=>Array.isArray(d)?{x:d[0],y:d[1]}:d),r=[],i=[];function o(d,h){const f=h.x-d.x,p=h.y-d.y,m=Math.sqrt(f*f+p*p);return{x:-p/m,y:f/m}}function s(d,h,f,p){const m=p/2,g={x:d.x+h.x*m*f,y:d.y+h.y*m*f};f>0?r.push(g):i.unshift(g)}const a=o(n[0],n[1]),c=n[0].trace_width??e;s(n[0],a,1,c),s(n[0],a,-1,c);for(let d=1;d<n.length-1;d++){const h=n[d-1],f=n[d],p=n[d+1],m=o(h,f),g=o(f,p),y=m.x+g.x,_=m.y+g.y,x=Math.sqrt(y*y+_*_),b=f.trace_width??e;if(x/2>2*(b/2))s(f,m,1,b),s(f,g,1,b),s(f,m,-1,b),s(f,g,-1,b);else{const S=1/x;s(f,{x:y*S,y:_*S},1,b),s(f,{x:y*S,y:_*S},-1,b)}}const l=o(n[n.length-2],n[n.length-1]),u=n[n.length-1].trace_width??e;return s(n[n.length-1],l,1,u),s(n[n.length-1],l,-1,u),[...r,...i]}var Hjn=(t,e)=>{const{x:n,y:r,width:i,height:o,layer:s,rect_border_radius:a}=t,c=t.corner_radius??a??0,l=[{_pcb_drawing_object_id:y4("rect"),pcb_drawing_type:"rect",x:n,y:r,w:i,h:o,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:c,...t.shape==="rotated_rect"&&t.ccw_rotation!==void 0?{ccw_rotation:t.ccw_rotation}:{}}];if(t.is_covered_with_solder_mask){const u=s==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",h={...{_pcb_drawing_object_id:y4("rect"),pcb_drawing_type:"rect",x:n,y:r,w:i,h:o,layer:u,_element:t,_parent_pcb_component:e._parent_pcb_component,_parent_source_component:e._parent_source_component,_source_port:e._source_port,roundness:c,...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}:{}};l.push(h)}return l},Yjn=(t,e)=>{const{x:n,y:r,radius:i,layer:o}=t,s=[{_pcb_drawing_object_id:y4("circle"),pcb_drawing_type:"circle",x:n,y:r,r:i,layer:o||"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=o==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",c={_pcb_drawing_object_id:y4("circle"),pcb_drawing_type:"circle",x:n,y:r,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(c)}return s},Xjn=(t,e)=>{const{layer:n,points:r}=t,i=[{_pcb_drawing_object_id:y4("polygon"),pcb_drawing_type:"polygon",points:$_e(r),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 o=n==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",s={_pcb_drawing_object_id:y4("polygon"),pcb_drawing_type:"polygon",points:$_e(r),layer:o,_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},Vjn=(t,e)=>{const{x:n,y:r,width:i,height:o,layer:s}=t,a=[{_pcb_drawing_object_id:y4("pill"),pcb_drawing_type:"pill",x:n,y:r,w:i,h:o,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 c=s==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",l={_pcb_drawing_object_id:y4("pill"),pcb_drawing_type:"pill",x:n,y:r,w:i,h:o,layer:c,_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(l)}return a},Gjn=(t,e)=>{const{x:n,y:r,width:i,height:o,layer:s,ccw_rotation:a}=t,c=[{_pcb_drawing_object_id:y4("pill"),pcb_drawing_type:"pill",x:n,y:r,w:i,h:o,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 l=s==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",u={_pcb_drawing_object_id:y4("pill"),pcb_drawing_type:"pill",x:n,y:r,w:i,h:o,layer:l,_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}:{}};c.push(u)}return c},o0=0,y4=t=>`${t}_${o0++}`,$_e=t=>(t??[]).map(e=>({x:gn.parse(e.x),y:gn.parse(e.y)})),qjn=(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,r=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?B9(e).pcb_port.get(t.pcb_port_id)?.source_port_id:void 0,o=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:r,_source_port:o};return t.shape==="rect"||t.shape==="rotated_rect"?Hjn(t,s):t.shape==="circle"?Yjn(t,s):t.shape==="polygon"?Xjn(t,s):t.shape==="pill"?Vjn(t,s):t.shape==="rotated_pill"?Gjn(t,s):[]}case"pcb_trace":{const s=[];if(t.route_thickness_mode==="interpolated"){const l=t.route.map(h=>({x:h.x,y:h.y,trace_width:h.route_type==="wire"?h.width:.5})),u=Ujn(l,.5),d=t.route[0].layer;return s.push({_pcb_drawing_object_id:`polygon_${o0++}`,_element:t,pcb_drawing_type:"polygon",points:u,layer:d}),t.route.forEach(h=>{h.route_type==="via"&&s.push({_pcb_drawing_object_id:`circle_${o0++}`,_element:t,pcb_drawing_type:"circle",x:h.x,y:h.y,r:h.outer_diameter/2,layer:h.from_layer})}),s}let a=null,c=null;for(const l of t.route)l.route_type==="wire"&&(a!==null&&c!==null&&s.push({_pcb_drawing_object_id:`line_${o0++}`,_element:t,pcb_drawing_type:"line",x1:a,y1:c,x2:l.x,y2:l.y,width:l.width,squareCap:!1,layer:l.layer}),a=l.x,c=l.y);return s}case"pcb_via":{const{x:s,y:a,outer_diameter:c,hole_diameter:l}=t,u=t.from_layer,d=t.to_layer,h=t.layers,f=[];u&&d?f.push(u,d):h&&Array.isArray(h)?f.push(...h):f.push("top","bottom");const p=[];for(const m of f)p.push({_pcb_drawing_object_id:`circle_${o0++}`,pcb_drawing_type:"circle",x:s,y:a,r:c/2,layer:m,_element:t,_parent_pcb_component:n,_parent_source_component:r});return p.push({_pcb_drawing_object_id:`circle_${o0++}`,pcb_drawing_type:"circle",x:s,y:a,r:l/2,layer:"drill",_element:t}),p}case"pcb_plated_hole":if(t.shape==="circle"){const{x:s,y:a,hole_diameter:c,outer_diameter:l}=t;return[{_pcb_drawing_object_id:`circle_${o0++}`,pcb_drawing_type:"circle",x:s,y:a,r:l/2,layer:"top",_element:t,_parent_pcb_component:n,_parent_source_component:r,_source_port:o},{_pcb_drawing_object_id:`circle_${o0++}`,pcb_drawing_type:"circle",x:s,y:a,r:c/2,layer:"drill",_element:t}]}else if(t.shape==="oval"){const{x:s,y:a,outer_height:c,outer_width:l,hole_height:u,hole_width:d}=t;return[{_pcb_drawing_object_id:`oval_${o0++}`,pcb_drawing_type:"oval",x:s,y:a,rX:l/2,rY:c/2,layer:"top",_element:t,_parent_pcb_component:n,_parent_source_component:r,_source_port:o},{_pcb_drawing_object_id:`oval_${o0++}`,_element:t,pcb_drawing_type:"oval",x:s,y:a,rX:d/2,rY:u/2,layer:"drill"}]}else if(t.shape==="pill"){const{x:s,y:a,outer_height:c,outer_width:l,hole_height:u,hole_width:d}=t;return[{_pcb_drawing_object_id:`pill_${o0++}`,pcb_drawing_type:"pill",x:s,y:a,w:l,h:c,layer:"top",_element:t,_parent_pcb_component:n,_parent_source_component:r,_source_port:o,ccw_rotation:t.ccw_rotation},{_pcb_drawing_object_id:`pill_${o0++}`,_element:t,pcb_drawing_type:"pill",x:s,y:a,w:d,h:u,layer:"drill",ccw_rotation:t.ccw_rotation}]}else if(t.shape==="circular_hole_with_rect_pad"){const{x:s,y:a,hole_diameter:c,rect_pad_width:l,rect_pad_height:u,rect_border_radius:d,hole_offset_x:h,hole_offset_y:f}=t,p=gn.parse(h??0),m=gn.parse(f??0);return[{_pcb_drawing_object_id:`rect_${o0++}`,pcb_drawing_type:"rect",x:s,y:a,w:l,h:u,layer:"top",_element:t,_parent_pcb_component:n,_parent_source_component:r,_source_port:o,roundness:d},{_pcb_drawing_object_id:`rect_${o0++}`,pcb_drawing_type:"rect",x:s,y:a,w:l,h:u,layer:"bottom",_element:t,_parent_pcb_component:n,_parent_source_component:r,_source_port:o,roundness:d,is_hoverable:!1},{_pcb_drawing_object_id:`circle_${o0++}`,_element:t,pcb_drawing_type:"circle",x:s+p,y:a+m,r:c/2,layer:"drill",is_hoverable:!1}]}else if(t.shape==="pill_hole_with_rect_pad"){const{x:s,y:a,hole_width:c,hole_height:l,rect_pad_width:u,rect_pad_height:d,rect_border_radius:h}=t;return[{_pcb_drawing_object_id:`rect_${o0++}`,pcb_drawing_type:"rect",x:s,y:a,w:u,h:d,layer:"top",_element:t,_parent_pcb_component:n,_parent_source_component:r,_source_port:o,roundness:h},{_pcb_drawing_object_id:`rect_${o0++}`,pcb_drawing_type:"rect",x:s,y:a,w:u,h:d,layer:"bottom",_element:t,_parent_pcb_component:n,_parent_source_component:r,_source_port:o,roundness:h,is_hoverable:!1},{_pcb_drawing_object_id:`pill_${o0++}`,_element:t,pcb_drawing_type:"pill",x:s,y:a,w:c,h:l,layer:"drill",is_hoverable:!1}]}else if(t.shape==="rotated_pill_hole_with_rect_pad"){const{x:s,y:a,hole_width:c,hole_height:l,hole_ccw_rotation:u,rect_pad_width:d,rect_pad_height:h,rect_ccw_rotation:f,rect_border_radius:p}=t;return[{_pcb_drawing_object_id:`rect_${o0++}`,pcb_drawing_type:"rect",x:s,y:a,w:d,h,layer:"top",_element:t,_parent_pcb_component:n,_parent_source_component:r,_source_port:o,ccw_rotation:f,roundness:p},{_pcb_drawing_object_id:`rect_${o0++}`,pcb_drawing_type:"rect",x:s,y:a,w:d,h,layer:"bottom",_element:t,_parent_pcb_component:n,_parent_source_component:r,_source_port:o,ccw_rotation:f,roundness:p,is_hoverable:!1},{_pcb_drawing_object_id:`pill_${o0++}`,_element:t,pcb_drawing_type:"pill",x:s,y:a,w:c,h:l,layer:"drill",ccw_rotation:u,is_hoverable:!1}]}else if(t.shape==="hole_with_polygon_pad"){const{x:s,y:a,pad_outline:c,hole_shape:l,hole_diameter:u,hole_width:d,hole_height:h,layers:f,hole_offset_x:p,hole_offset_y:m}=t,g=gn.parse(p??0),y=gn.parse(m??0),_=c,x=[];if(_&&Array.isArray(_)){const S=$_e(_).map(T=>({x:T.x+s,y:T.y+a}));for(const T of f||["top","bottom"])x.push({_pcb_drawing_object_id:`polygon_${o0++}`,pcb_drawing_type:"polygon",points:S,layer:T,_element:t,_parent_pcb_component:n,_parent_source_component:r,_source_port:o})}const b={x:s+g,y:a+y},w=[];return l==="circle"?w.push({_pcb_drawing_object_id:`circle_${o0++}`,pcb_drawing_type:"circle",x:b.x,y:b.y,r:(u??0)/2,layer:"drill",_element:t,_parent_pcb_component:n,_parent_source_component:r}):l==="oval"?w.push({_pcb_drawing_object_id:`oval_${o0++}`,pcb_drawing_type:"oval",x:b.x,y:b.y,rX:(d??0)/2,rY:(h??0)/2,layer:"drill",_element:t,_parent_pcb_component:n,_parent_source_component:r}):(l==="pill"||l==="rotated_pill")&&w.push({_pcb_drawing_object_id:`pill_${o0++}`,pcb_drawing_type:"pill",x:b.x,y:b.y,w:d??0,h:h??0,layer:"drill",_element:t,_parent_pcb_component:n,_parent_source_component:r,ccw_rotation:t.ccw_rotation}),[...x,...w]}else return[]}return[]},hi={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)"}},I_=(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)},Wl={elementOverlay:40,dimensionOverlay:40,editTraceHintOverlay:40,errorOverlay:40,pcbGroupOverlay:35,ratsNestOverlay:30,toolbarOverlay:70,warnings:30,topLayer:20,clickToInteractOverlay:100},uG={red:"red",black:"black",green:"green",board:"rgb(255, 255, 255)",other:"#eee",top:hi.board.copper.f,inner1:hi.board.copper.in1,inner2:hi.board.copper.in2,inner3:hi.board.copper.in3,inner4:hi.board.copper.in4,inner5:hi.board.copper.in5,inner6:hi.board.copper.in6,inner7:hi.board.copper.in7,inner8:hi.board.copper.in8,bottom:hi.board.copper.b,drill:hi.board.anchor,keepout:hi.board.background,tkeepout:hi.board.b_crtyd,tplace:hi.board.b_silks,top_courtyard:hi.board.f_crtyd,bottom_courtyard:hi.board.b_crtyd,top_silkscreen:hi.board.f_silks,bottom_silkscreen:hi.board.b_silks,top_fabrication:hi.board.f_fab,bottom_fabrication:hi.board.b_fab,soldermask_top:hi.board.soldermask.top,soldermask_bottom:hi.board.soldermask.bottom,soldermask_with_copper_top:hi.board.soldermaskWithCopper.top,soldermask_with_copper_bottom:hi.board.soldermaskWithCopper.bottom,bottom_notes:hi.board.user_2,top_notes:hi.board.user_2,...hi.board},Wjn=["board","inner6","inner5","inner4","inner3","inner2","inner1","bottom","soldermask_bottom","bottom_silkscreen","top","soldermask_top","bottom_courtyard","bottom_fabrication","top_courtyard","top_fabrication","edge_cuts","top_silkscreen"],Zjn=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=el(),this.transform.d*=-1,this.transform=di(this.transform,_i(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,r,i,o=45){const s=this.getLayerCtx(),[a,c]=mt(this.transform,[t,e]),[l,u]=mt(this.transform,[t+n,e+r]),d=I_(this.transform,i);s.lineWidth=1,s.strokeStyle=this.aperture.color;const h=f=>{const p=Math.sin(f),m=Math.cos(f),g=Math.sqrt((l-a)**2+(u-c)**2);for(let y=-g;y<=g;y+=d)s.beginPath(),s.moveTo(a+y*m-g*p,c+y*p+g*m),s.lineTo(a+y*m+g*p,c+y*p-g*m),s.stroke()};h(o*Math.PI/180),h((o+90)*Math.PI/180)}rect({x:t,y:e,w:n,h:r,mesh_fill:i,is_filled:o=!0,has_stroke:s,is_stroke_dashed:a,stroke_width:c,roundness:l}){const[u,d]=mt(this.transform,[t-n/2,e-r/2]),[h,f]=mt(this.transform,[t+n/2,e+r/2]);this.applyAperture();const p=this.getLayerCtx(),m=l?I_(this.transform,l):0,g=s===void 0?o===!1:s;if(i)p.save(),p.beginPath(),m>0&&p.roundRect?p.roundRect(u,d,h-u,f-d,m):p.rect(u,d,h-u,f-d),p.clip(),this.drawMeshPattern(t-n/2,e-r/2,n,r,.15),p.restore(),m>0&&p.roundRect?(p.beginPath(),p.roundRect(u,d,h-u,f-d,m),p.stroke()):p.strokeRect(u,d,h-u,f-d);else if(o!==!1&&(m>0&&p.roundRect?(p.beginPath(),p.roundRect(u,d,h-u,f-d,m),p.fill()):p.fillRect(u,d,h-u,f-d)),g){const y=p.lineWidth;if(c!==void 0&&(p.lineWidth=I_(this.transform,c)),a){let _=[];const x=Math.abs(this.transform.a);if(x>0){const w=.1*x,S=w*1.3;w>.5&&(_=[w,S])}p.setLineDash(_)}m>0&&p.roundRect?(p.beginPath(),p.roundRect(u,d,h-u,f-d,m),p.stroke()):p.strokeRect(u,d,h-u,f-d),a&&p.setLineDash([]),c!==void 0&&(p.lineWidth=y)}}rotatedRect(t,e,n,r,i,o,s){const a=this.getLayerCtx();this.applyAperture();const[c,l]=mt(this.transform,[t-n/2,e-r/2]),[u,d]=mt(this.transform,[t+n/2,e+r/2]),h=o?I_(this.transform,o):0;a.save();const[f,p]=mt(this.transform,[t,e]);a.translate(f,p);const m=360-i;i&&a.rotate(m*Math.PI/180),a.translate(-f,-p),s?(a.beginPath(),h>0&&a.roundRect?a.roundRect(c,l,u-c,d-l,h):a.rect(c,l,u-c,d-l),a.clip(),this.drawMeshPattern(t-n/2,e-r/2,n,r,.15),h>0&&a.roundRect?(a.beginPath(),a.roundRect(c,l,u-c,d-l,h),a.stroke()):a.strokeRect(c,l,u-c,d-l)):h>0&&a.roundRect?(a.beginPath(),a.roundRect(c,l,u-c,d-l,h),a.fill()):a.fillRect(c,l,u-c,d-l),a.restore()}rotatedPill(t,e,n,r,i){const o=this.getLayerCtx();this.applyAperture(),o.save();const[s,a]=mt(this.transform,[t,e]);o.translate(s,a);const c=360-i;i&&o.rotate(c*Math.PI/180),o.translate(-s,-a),this.pill(t,e,n,r),o.restore()}circle(t,e,n,r,i=!0){const o=I_(this.transform,n),[s,a]=mt(this.transform,[t,e]);this.applyAperture();const c=this.getLayerCtx();r?(c.save(),c.beginPath(),c.arc(s,a,o,0,2*Math.PI),c.clip(),this.drawMeshPattern(t-n,e-n,n*2,n*2,.15),c.restore(),c.beginPath(),c.arc(s,a,o,0,2*Math.PI),c.stroke()):(c.beginPath(),c.arc(s,a,o,0,2*Math.PI),c.fill())}oval(t,e,n,r){const i=I_(this.transform,n),o=I_(this.transform,r),[s,a]=mt(this.transform,[t,e]);this.applyAperture();const c=this.getLayerCtx();c.beginPath(),c.ellipse(s,a,i,o,0,0,2*Math.PI),c.fill(),c.closePath()}pill(t,e,n,r){const[i,o]=mt(this.transform,[t-n/2,e+r/2]),s=I_(this.transform,n),a=I_(this.transform,r),c=Math.min(s,a)/2;this.applyAperture();const l=this.getLayerCtx();l.beginPath(),l.arc(i+c,o+c,c,Math.PI,Math.PI*1.5),l.arc(i+s-c,o+c,c,Math.PI*1.5,0),l.arc(i+s-c,o+a-c,c,0,Math.PI*.5),l.arc(i+c,o+a-c,c,Math.PI*.5,Math.PI),l.fill(),l.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 r=I_(this.transform,this.aperture.size);r>0&&(e.lineWidth=r,e.stroke())}debugText(t,e,n){const[r,i]=mt(this.transform,[e,n]);this.applyAperture();const o=this.getLayerCtx();o.font="10px sans-serif",o.fillText(t,r,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,n=e==="top"?"soldermask_top":e==="bottom"?"soldermask_bottom":void 0,r=e==="top"?"top_silkscreen":e==="bottom"?"bottom_silkscreen":void 0,i=e==="top"?"top_notes":e==="bottom"?"bottom_notes":void 0,o=e==="top"?"top_fabrication":e==="bottom"?"bottom_fabrication":void 0,s=e==="top"?"top_courtyard":e==="bottom"?"bottom_courtyard":void 0,a=new Set([e,"drill","edge_cuts","other","board",...n?[n]:[],...r?[r]:[],...i?[i]:[],...o?[o]:[],...s?[s]:[]]),c=[e,"edge_cuts",...n?[n]:[],...r?[r]:[],...i?[i]:[],...o?[o]:[],...s?[s]:[]],l=e==="drill"?[]:["drill"],u=e==="drill"?["drill"]:[],d=[...Wjn.filter(h=>!c.includes(h)),...l,e,...n?[n]:[],...u,"edge_cuts",...r?[r]:[],...i?[i]:[],...o?[o]:[],...s?[s]:[]];d.forEach((h,f)=>{const p=t[h];p&&(p.style.zIndex=`${Wl.topLayer-(d.length-f)}`,p.style.opacity=a.has(h)?"1":"0.5")})}applyAperture(){const{transform:t,aperture:e}=this;let{size:n,mode:r,color:i,fontSize:o,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=I_(t,n),a.lineCap="round",r==="add"){a.globalCompositeOperation="source-over";let c=uG[i.toLowerCase()];if(!c)try{c=uc(i).rgb().toString()}catch{console.warn(`Invalid color format: '${i}'`),c="white"}a.fillStyle=c,a.strokeStyle=c}else a.globalCompositeOperation="destination-out",a.fillStyle="rgba(0,0,0,1)",a.strokeStyle="rgba(0,0,0,1)";a.font=`${I_(Bx(t),o)}px sans-serif`}moveTo(t,e){this.lastPoint={x:t,y:e}}lineTo(t,e){const[n,r]=mt(this.transform,[t,e]),{size:i,shape:o,mode:s}=this.aperture,a=I_(this.transform,i),{lastPoint:c}=this,l=mt(this.transform,c);this.applyAperture();const u=this.getLayerCtx();o==="square"&&u.fillRect(l.x-a/2,l.y-a/2,a,a),u.beginPath(),u.moveTo(l.x,l.y),u.lineTo(n,r),u.stroke(),u.closePath(),o==="square"&&u.fillRect(n-a/2,r-a/2,a,a),this.lastPoint={x:t,y:e}}polygonWithArcs(t){const e=this.getLayerCtx(),n=r=>{if(r.vertices.length===0)return;const i=r.vertices[0],o=mt(this.transform,[i.x,i.y]);e.moveTo(o[0],o[1]);for(let s=0;s<r.vertices.length;s++){const a=r.vertices[s],c=r.vertices[(s+1)%r.vertices.length];if(a.bulge&&a.bulge!==0){const l=a.bulge,u=c.x-a.x,d=c.y-a.y,h=Math.sqrt(u*u+d*d);if(h<1e-9){const O=mt(this.transform,[c.x,c.y]);e.lineTo(O[0],O[1]);continue}const f=4*Math.atan(l),p=Math.abs(h/(2*Math.sin(f/2))),m=(a.x+c.x)/2,g=(a.y+c.y)/2,y=u/h,x=-(d/h),b=y,w=Math.sqrt(Math.max(0,p*p-(h/2)**2)),S=m+w*x*Math.sign(l),T=g+w*b*Math.sign(l),C=Math.atan2(a.y-T,a.x-S);let A=Math.atan2(c.y-T,c.x-S);l>0&&A<C?A+=2*Math.PI:l<0&&A>C&&(A-=2*Math.PI);const R=mt(this.transform,[S,T]),L=I_(this.transform,p);e.arc(R[0],R[1],L,-C,-A,l>0)}else{const l=mt(this.transform,[c.x,c.y]);e.lineTo(l[0],l[1])}}e.closePath()};if(e.beginPath(),n(t.outer_ring),t.inner_rings)for(const r of t.inner_rings)n(r);e.fill("evenodd")}};function Kjn(t){return t.type==="pcb_copper_pour"}function dG({canvas:t,elements:e,layers:n,realToCanvasMat:r}){const i=e.filter(Kjn);if(i.length===0)return;const o=new Eh(t);o.realToCanvasMat=r,o.drawElements(i,{layers:n})}var Qjn={...cg,silkscreen:{top:hi.board.f_fab,bottom:hi.board.b_fab}};function Jjn(t){return t.type.includes("pcb_fabrication_note")}function Out({canvas:t,elements:e,layers:n,realToCanvasMat:r}){const i=new Eh(t);i.configure({colorOverrides:Qjn}),i.realToCanvasMat=r;const o=e.filter(Jjn);i.drawElements(o,{layers:n})}function eUn(t){return t.type==="pcb_hole"}function tUn({canvas:t,elements:e,layers:n,realToCanvasMat:r,drawSoldermask:i}){const o=new Eh(t);o.realToCanvasMat=r;const s=e.filter(eUn);o.drawElements(s,{layers:n,drawSoldermask:i})}function nUn(t){return t.type==="pcb_board"}function rUn({canvas:t,elements:e,layers:n,realToCanvasMat:r,drawSoldermask:i}){const o=new Eh(t);o.realToCanvasMat=r;const s=e.filter(nUn);for(const a of s)o.drawElements([a],{layers:n,drawSoldermask:!1,drawBoardMaterial:i??!1,minBoardOutlineStrokePx:2})}function iUn(t){return t.type==="pcb_copper_text"}function oUn({canvas:t,elements:e,layers:n,realToCanvasMat:r}){const i=e.filter(iUn);if(i.length===0)return;const o=new Eh(t);o.realToCanvasMat=r,o.drawElements(i,{layers:n})}function sUn(t){return t.type==="pcb_cutout"}function aUn({canvas:t,elements:e,layers:n,realToCanvasMat:r}){const i=new Eh(t);i.realToCanvasMat=r;const o=e.filter(sUn);i.drawElements(o,{layers:n})}function cUn(t){return t.type==="pcb_keepout"}function lUn({canvas:t,elements:e,layers:n,realToCanvasMat:r}){const i=e.filter(cUn);if(i.length===0)return;const o=new Eh(t);o.realToCanvasMat=r,o.drawElements(i,{layers:[]})}function uUn(t){return t.type.startsWith("pcb_note_")}function Lut({canvas:t,elements:e,layers:n,realToCanvasMat:r}){const i=new Eh(t);i.realToCanvasMat=r;const o=e.filter(uUn);i.drawElements(o,{layers:n})}function dUn(t){return t.type==="pcb_panel"}function hUn({canvas:t,elements:e,layers:n,realToCanvasMat:r,drawSoldermask:i}){const o=new Eh(t);o.realToCanvasMat=r;const s=e.filter(dUn);for(const a of s)o.drawElements([a],{layers:n})}var pUn={...cg,copper:{...cg.copper,top:uc(hi.board.pad_front).lighten(.5).toString(),bottom:uc(hi.board.pad_back).lighten(.5).toString(),inner1:uc(hi.board.copper.in1).lighten(.5).toString(),inner2:uc(hi.board.copper.in2).lighten(.5).toString(),inner3:uc(hi.board.copper.in3).lighten(.5).toString(),inner4:uc(hi.board.copper.in4).lighten(.5).toString(),inner5:uc(hi.board.copper.in5).lighten(.5).toString(),inner6:uc(hi.board.copper.in6).lighten(.5).toString()}};function fUn(t){return t.type==="pcb_smtpad"}function mUn({canvas:t,elements:e,layers:n,realToCanvasMat:r,primitives:i,drawSoldermask:o}){const s=e.filter(fUn).filter(u=>{const d=u.layer;return n.some(h=>h==="top_copper"&&d==="top"||h==="bottom_copper"&&d==="bottom"||h==="inner1_copper"&&d==="inner1"||h==="inner2_copper"&&d==="inner2"||h==="inner3_copper"&&d==="inner3"||h==="inner4_copper"&&d==="inner4"||h==="inner5_copper"&&d==="inner5"||h==="inner6_copper"&&d==="inner6")});if(s.length===0)return;const a=new Set;if(i)for(const u of i)(u.is_mouse_over||u.is_in_highlighted_net)&&u._element?.type==="pcb_smtpad"&&a.add(u._element.pcb_smtpad_id);const c=s.filter(u=>a.has(u.pcb_smtpad_id)),l=s.filter(u=>!a.has(u.pcb_smtpad_id));if(l.length>0){const u=new Eh(t);u.realToCanvasMat=r,u.drawElements(l,{layers:n,drawSoldermask:o})}if(c.length>0){const u=new Eh(t);u.configure({colorOverrides:pUn}),u.realToCanvasMat=r,u.drawElements(c,{layers:n,drawSoldermask:o})}}var yUn={...cg,copper:{...cg.copper,top:uc(hi.board.pad_front).lighten(.5).toString(),bottom:uc(hi.board.pad_back).lighten(.5).toString(),inner1:uc(hi.board.copper.in1).lighten(.5).toString(),inner2:uc(hi.board.copper.in2).lighten(.5).toString(),inner3:uc(hi.board.copper.in3).lighten(.5).toString(),inner4:uc(hi.board.copper.in4).lighten(.5).toString(),inner5:uc(hi.board.copper.in5).lighten(.5).toString(),inner6:uc(hi.board.copper.in6).lighten(.5).toString()}};function gUn(t){return t.type==="pcb_trace"}var _Un=t=>t.map(e=>e.endsWith("_copper")?e.replace("_copper",""):e),xUn=(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}};function bUn({canvas:t,elements:e,layers:n,realToCanvasMat:r,primitives:i}){const o=new Set(_Un(n)),s=e.filter(gUn).map(u=>xUn(u,o)).filter(u=>u!==null);if(s.length===0)return;const a=new Set;if(i)for(const u of i)(u.is_mouse_over||u.is_in_highlighted_net)&&u._element?.type==="pcb_trace"&&a.add(u._element.pcb_trace_id);const c=[],l=[];for(const u of s)a.has(u.pcb_trace_id)?c.push(u):l.push(u);if(l.length>0){const u=new Eh(t);u.realToCanvasMat=r,u.drawElements(l,{layers:n})}if(c.length>0){const u=new Eh(t);u.configure({colorOverrides:yUn}),u.realToCanvasMat=r,u.drawElements(c,{layers:n})}}var vUn={...cg,copper:{...cg.copper,top:uc(hi.board.pad_front).lighten(.5).toString(),bottom:uc(hi.board.pad_back).lighten(.5).toString()}};function wUn(t){return t.type==="pcb_plated_hole"}function Dut({canvas:t,elements:e,layers:n,realToCanvasMat:r,primitives:i,drawSoldermask:o}){const s=e.filter(wUn);if(s.length===0)return;const a=new Set;if(i)for(const u of i)(u.is_mouse_over||u.is_in_highlighted_net)&&u._element?.type==="pcb_plated_hole"&&a.add(u._element.pcb_plated_hole_id);const c=s.filter(u=>a.has(u.pcb_plated_hole_id)),l=s.filter(u=>!a.has(u.pcb_plated_hole_id));if(l.length>0){const u=new Eh(t);u.realToCanvasMat=r,u.drawElements(l,{layers:n,drawSoldermask:o})}if(c.length>0){const u=new Eh(t);u.configure({colorOverrides:vUn}),u.realToCanvasMat=r,u.drawElements(c,{layers:n,drawSoldermask:o})}}function zut(t){const{lines:e,anchorPoint:n,ccwRotation:r}=t;if(!r)return e;const i=r*Math.PI/180,o=Wf(i),s=di(_i(n.x,n.y),o,_i(-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 SUn=.6,$ut=.2,Fut=t=>{const e=t.size*.7,n=e*SUn,r=e*$ut,i=e*$ut,o=t.text.split(/\r?\n/),s=t.text.length>0&&e>0,a=s?o.length:0,c=s?o.map(d=>d.length===0?0:d.length*n+(d.length-1)*r):[],l=c.length>0?Math.max(...c):0,u=a>0?a*e+(a-1)*i:0;return{text_lines:o,line_count:a,line_widths:c,target_height:e,target_width_char:n,space_between_chars:r,space_between_lines:i,width:l,height:u}},But=t=>{const e=Fut(t);return{width:e.width,height:e.height,lineHeight:e.target_height,lineSpacing:e.space_between_lines,lineCount:e.line_count}},jut=t=>{const{text_lines:e,line_count:n,line_widths:r,target_height:i,target_width_char:o,space_between_chars:s,space_between_lines:a,width:c}=Fut(t);if(i<=0||n===0)return[];const l=i/12,u=[];for(let d=0;d<n;d++){const h=-d*(i+a),f=r[d],p=(c-f)/2;let m=t.x+p;for(let g=0;g<e[d].length;g++){const y=e[d][g],_=Yw[y]??Yw[y.toUpperCase()];if(!_){m+=o+s;continue}for(const{x1:x,y1:b,x2:w,y2:S}of _)u.push({_pcb_drawing_object_id:y4("line"),pcb_drawing_type:"line",x1:m+o*x,y1:t.y+h+i*b,x2:m+o*w,y2:t.y+h+i*S,width:l,layer:t.layer,unit:t.unit,color:t.color});m+=o+s}}return u};function ev(t){const n=t.color??uG[t.layer];let r=uc(n);return t._element?.type==="pcb_copper_pour"&&(r=r.alpha(.7)),t.is_mouse_over||t.is_in_highlighted_net?r.lighten(.5).rgb().toString():r.rgb().toString()}var Uut=(t,e)=>{t.equip({size:e.zoomIndependent?e.width/t.transform.a:e.width,shape:e.squareCap?"square":"circle",color:ev(e),layer:e.layer}),t.moveTo(e.x1,e.y1),t.lineTo(e.x2,e.y2)},MUn=(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}}},Hut=t=>t.layer==="bottom_silkscreen"||t.layer==="bottom"?t.is_mirrored!==!1:t.is_mirrored===!0,TUn=(t,e)=>{t.equip({fontSize:e.size,color:ev(e),layer:e.layer});const{width:n,height:r}=But(e),i=MUn(n,r,e.align);e.x??=0,e.y??=0;const o={x:e.x,y:e.y};let s=jut({...e,x:e.x+i.x,y:e.y+i.y});if(Hut(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:o,ccwRotation:e.ccw_rotation};s=zut(a)}for(const a of s)Uut(t,a)},EUn=(t,e)=>{const{width:n,height:r,lineHeight:i}=But(e);e.x??=0,e.y??=0;const o=e.knockout_padding??{left:e.size*.5,right:e.size*.5,top:e.size*.3,bottom:e.size*.3},s=n+o.left+o.right,a=r+o.top+o.bottom,c=n/2,l=i-r/2,u=e.x-c,d=e.y-l,h={x:e.x,y:e.y},f={_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?Xut(t,f):Yut(t,f);let p=jut({...e,x:u,y:d});if(Hut(e)&&(p=p.map(m=>({...m,x1:2*e.x-m.x1,x2:2*e.x-m.x2}))),e.ccw_rotation){const m={lines:p,anchorPoint:h,ccwRotation:e.ccw_rotation};p=zut(m)}for(const m of p)t.equip({size:m.width,shape:"circle",color:"black",layer:e.layer,mode:"subtract"}),t.moveTo(m.x1,m.y1),t.lineTo(m.x2,m.y2);t.equip({mode:"add"})},Yut=(t,e)=>{t.equip({color:ev(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})},Xut=(t,e)=>{t.equip({color:ev(e),layer:e.layer}),t.rotatedRect(e.x,e.y,e.w,e.h,e.ccw_rotation,e.roundness,e.mesh_fill)},CUn=(t,e)=>{t.equip({color:ev(e),layer:e.layer}),t.rotatedPill(e.x,e.y,e.w,e.h,e.ccw_rotation)},PUn=(t,e)=>{t.equip({color:ev(e),layer:e.layer}),t.circle(e.x,e.y,e.r,e.mesh_fill)},AUn=(t,e)=>{t.equip({color:ev(e),layer:e.layer}),t.oval(e.x,e.y,e.rX,e.rY)},RUn=(t,e)=>{t.equip({color:ev(e),layer:e.layer}),t.pill(e.x,e.y,e.w,e.h)},IUn=(t,e)=>{t.equip({color:ev(e),layer:e.layer}),t.polygon(e.points)},NUn=(t,e)=>{t.equip({color:ev(e),layer:e.layer}),t.polygonWithArcs(e.brep_shape)},kUn=(t,e)=>{switch(e.pcb_drawing_type){case"line":return Uut(t,e);case"text":return e.is_knockout?EUn(t,e):TUn(t,e);case"rect":return e.ccw_rotation?Xut(t,e):Yut(t,e);case"circle":return PUn(t,e);case"oval":return AUn(t,e);case"pill":return e.ccw_rotation?CUn(t,e):RUn(t,e);case"polygon":return IUn(t,e);case"polygon_with_arcs":return NUn(t,e)}},OUn=(t,e)=>{for(const n of e)kUn(t,n)},LUn={...cg,copper:{...cg.copper,top:uc(hi.board.pad_front).lighten(.5).toString(),bottom:uc(hi.board.pad_back).lighten(.5).toString(),inner1:uc(hi.board.copper.in1).lighten(.5).toString(),inner2:uc(hi.board.copper.in2).lighten(.5).toString(),inner3:uc(hi.board.copper.in3).lighten(.5).toString(),inner4:uc(hi.board.copper.in4).lighten(.5).toString(),inner5:uc(hi.board.copper.in5).lighten(.5).toString(),inner6:uc(hi.board.copper.in6).lighten(.5).toString()},soldermask:{...cg.soldermask,top:uc(hi.board.soldermask.top).lighten(.35).toString(),bottom:uc(hi.board.soldermask.bottom).lighten(.35).toString()}};function Vut({canvas:t,elements:e,layers:n,realToCanvasMat:r,drawSoldermaskTop:i,drawSoldermaskBottom:o,primitives:s}){const a=new Eh(t);a.realToCanvasMat=r;const c=e.filter(h=>h.type==="pcb_board");if(c.length<=1)a.drawElements(e,{layers:n,drawSoldermask:!0,drawSoldermaskTop:i,drawSoldermaskBottom:o,drawBoardMaterial:!1});else{const h=e.filter(f=>f.type!=="pcb_board");for(const f of c)a.drawElements([f,...h],{layers:n,drawSoldermask:!0,drawSoldermaskTop:i,drawSoldermaskBottom:o,drawBoardMaterial:!1})}if(!s)return;const l=new Set;for(const h of s){if(!(h.is_mouse_over||h.is_in_highlighted_net))continue;const f=h._element;f?.type==="pcb_smtpad"?l.add(f.pcb_smtpad_id):f?.type==="pcb_plated_hole"?l.add(f.pcb_plated_hole_id):f?.type==="pcb_via"&&l.add(f.pcb_via_id)}if(l.size===0)return;const u=e.filter(h=>h.type==="pcb_smtpad"?l.has(h.pcb_smtpad_id):h.type==="pcb_plated_hole"?l.has(h.pcb_plated_hole_id):h.type==="pcb_via"?l.has(h.pcb_via_id):!1);if(u.length===0)return;const d=new Eh(t);d.configure({colorOverrides:LUn}),d.realToCanvasMat=r,d.drawElements(u,{layers:n,drawSoldermask:!0,drawSoldermaskTop:i,drawSoldermaskBottom:o,drawBoardMaterial:!1})}var DUn={...cg,silkscreen:{top:hi.board.f_silks,bottom:hi.board.b_silks}};function zUn(t){return t.type.includes("pcb_silkscreen")}function Gut({canvas:t,elements:e,layers:n,realToCanvasMat:r}){const i=new Eh(t);i.configure({colorOverrides:DUn}),i.realToCanvasMat=r;const o=e.filter(zUn);i.drawElements(o,{layers:n})}var $Un={...cg,copper:{...cg.copper,top:uc(hi.board.pad_front).lighten(.5).toString(),bottom:uc(hi.board.pad_back).lighten(.5).toString()}};function FUn(t){return t.type==="pcb_via"}function qut({canvas:t,elements:e,layers:n,realToCanvasMat:r,primitives:i,drawSoldermask:o}){const s=e.filter(FUn).filter(u=>n.some(d=>d.includes("copper")));if(s.length===0)return;const a=new Set;if(i)for(const u of i)(u.is_mouse_over||u.is_in_highlighted_net)&&u._element?.type==="pcb_via"&&a.add(u._element.pcb_via_id);const c=s.filter(u=>a.has(u.pcb_via_id)),l=s.filter(u=>!a.has(u.pcb_via_id));if(l.length>0){const u=new Eh(t);u.realToCanvasMat=r,u.drawElements(l,{layers:n,drawSoldermask:o})}if(c.length>0){const u=new Eh(t);u.configure({colorOverrides:$Un}),u.realToCanvasMat=r,u.drawElements(c,{layers:n,drawSoldermask:o})}}var BUn={...cg,courtyard:{top:hi.board.f_crtyd,bottom:hi.board.b_crtyd}};function jUn(t){return t.type==="pcb_courtyard_circle"||t.type==="pcb_courtyard_rect"||t.type==="pcb_courtyard_outline"}function Wut({canvas:t,elements:e,layers:n,realToCanvasMat:r}){const i=new Eh(t);i.configure({colorOverrides:BUn}),i.realToCanvasMat=r;const o=e.filter(jUn);i.drawElements(o,{layers:n})}var UUn=["board","bottom","soldermask_bottom","bottom_silkscreen","top","soldermask_top","soldermask_with_copper_bottom","soldermask_with_copper_top","top_fabrication","bottom_fabrication","inner1","inner2","inner3","inner4","inner5","inner6","drill","edge_cuts","bottom_notes","top_notes","top_silkscreen","top_courtyard","bottom_courtyard","other"],HUn=({primitives:t,elements:e,transform:n,grid:r,width:i=500,height:o=500})=>{const s=te.useRef({}),a=E0(h=>h.selected_layer),c=E0(h=>h.is_showing_solder_mask),l=E0(h=>h.is_showing_fabrication_notes),u=E0(h=>h.is_showing_courtyards),d=E0(h=>h.is_showing_silkscreen);return te.useEffect(()=>{if(!s.current||Object.keys(s.current).length===0)return;const h=Object.fromEntries(Object.entries(s.current).filter(([m,g])=>!!g));if(Object.keys(h).length===0)return;const f=new Zjn(h);n&&(f.transform=n),f.clear(),f.foregroundLayer=a;const p=t.filter(m=>c||!m.layer?.includes("soldermask")).filter(m=>d||!m.layer?.includes("silkscreen")).filter(m=>l||!m.layer?.includes("fabrication")).filter(m=>m.layer!=="board").filter(m=>m._element?.type!=="pcb_smtpad").filter(m=>m._element?.type!=="pcb_plated_hole").filter(m=>m._element?.type!=="pcb_via").filter(m=>m._element?.type!=="pcb_trace").filter(m=>m._element?.type!=="pcb_copper_text");if(OUn(f,p),n){const m=s.current.top,g=s.current.bottom,y=s.current.inner1,_=s.current.inner2,x=s.current.inner3,b=s.current.inner4,w=s.current.inner5,S=s.current.inner6,T=[{canvas:m,copperLayer:"top_copper"},{canvas:g,copperLayer:"bottom_copper"},{canvas:y,copperLayer:"inner1_copper"},{canvas:_,copperLayer:"inner2_copper"},{canvas:x,copperLayer:"inner3_copper"},{canvas:b,copperLayer:"inner4_copper"},{canvas:w,copperLayer:"inner5_copper"},{canvas:S,copperLayer:"inner6_copper"}];for(const{canvas:B,copperLayer:j}of T)B&&bUn({canvas:B,elements:e,layers:[j],realToCanvasMat:n,primitives:t});for(const{canvas:B,copperLayer:j}of T)B&&oUn({canvas:B,elements:e,layers:[j],realToCanvasMat:n});m&&Dut({canvas:m,elements:e,layers:["top_copper"],realToCanvasMat:n,primitives:t,drawSoldermask:c}),g&&Dut({canvas:g,elements:e,layers:["bottom_copper"],realToCanvasMat:n,primitives:t,drawSoldermask:c}),m&&dG({canvas:m,elements:e,layers:["top_copper"],realToCanvasMat:n}),g&&dG({canvas:g,elements:e,layers:["bottom_copper"],realToCanvasMat:n});for(const{canvas:B,copperLayer:j}of T)B&&mUn({canvas:B,elements:e,layers:[j],realToCanvasMat:n,primitives:t,drawSoldermask:c});if(m&&qut({canvas:m,elements:e,layers:["top_copper"],realToCanvasMat:n,primitives:t,drawSoldermask:c}),g&&qut({canvas:g,elements:e,layers:["bottom_copper"],realToCanvasMat:n,primitives:t,drawSoldermask:c}),c){const B=a==="bottom"?"bottom":"top",j=B==="top",V=B==="bottom",q=s.current.soldermask_top;q&&B==="top"&&Vut({canvas:q,elements:e,layers:["top_soldermask"],realToCanvasMat:n,drawSoldermaskTop:j,drawSoldermaskBottom:V,primitives:t});const K=s.current.soldermask_bottom;K&&B==="bottom"&&Vut({canvas:K,elements:e,layers:["bottom_soldermask"],realToCanvasMat:n,drawSoldermaskTop:j,drawSoldermaskBottom:V,primitives:t})}m&&dG({canvas:m,elements:e,layers:["top_copper"],realToCanvasMat:n}),g&&dG({canvas:g,elements:e,layers:["bottom_copper"],realToCanvasMat:n});const C=s.current.drill;if(C&&tUn({canvas:C,elements:e,layers:["drill"],realToCanvasMat:n}),d){const B=s.current.top_silkscreen;B&&Gut({canvas:B,elements:e,layers:["top_silkscreen"],realToCanvasMat:n});const j=s.current.bottom_silkscreen;j&&Gut({canvas:j,elements:e,layers:["bottom_silkscreen"],realToCanvasMat:n})}if(l){const B=s.current.top_fabrication;B&&Out({canvas:B,elements:e,layers:["top_fabrication_note"],realToCanvasMat:n});const j=s.current.bottom_fabrication;j&&Out({canvas:j,elements:e,layers:["bottom_fabrication_note"],realToCanvasMat:n})}const A=s.current.bottom_notes;A&&Lut({canvas:A,elements:e,layers:["bottom_user_note"],realToCanvasMat:n});const R=s.current.top_notes;if(R&&Lut({canvas:R,elements:e,layers:["top_user_note"],realToCanvasMat:n}),u){const B=s.current.top_courtyard;B&&Wut({canvas:B,elements:e,layers:["top_courtyard"],realToCanvasMat:n});const j=s.current.bottom_courtyard;j&&Wut({canvas:j,elements:e,layers:["bottom_courtyard"],realToCanvasMat:n})}const L=s.current.board;L&&(hUn({canvas:L,elements:e,layers:[],realToCanvasMat:n,drawSoldermask:c}),rUn({canvas:L,elements:e,layers:[],realToCanvasMat:n,drawSoldermask:c}));const O=s.current.edge_cuts;O&&aUn({canvas:O,elements:e,layers:["edge_cuts"],realToCanvasMat:n});const F=[{canvas:m,layer:"top"},{canvas:g,layer:"bottom"}];for(const{canvas:B,layer:j}of F)B&&lUn({canvas:B,elements:e,layers:[j],realToCanvasMat:n})}f.orderAndFadeLayers()},[t,e,n,a,c,l,u,d]),G.jsxs("div",{style:{backgroundColor:"black",width:i,height:o,position:"relative"},children:[G.jsx(WV.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:o,transform:n,stringifyCoord:(h,f,p)=>`${WV.toMMSI(h,p)}, ${WV.toMMSI(f,p)}`}),UUn.filter(h=>!(!c&&h.includes("soldermask")||!d&&h.includes("silkscreen"))).map(h=>h.replace(/-/g,"")).map((h,f)=>G.jsx("canvas",{className:`pcb-layer-${h}`,ref:p=>{s.current??={},p?s.current[h]=p:delete s.current[h]},style:{position:"absolute",zIndex:f,left:0,top:0,pointerEvents:"none"},width:i,height:o},h))]})},YUn=.6,XUn=1;I_e(ZBn(),1),I_e(hjn(),1);var hG=["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 Zut(t,e,n,r={}){const i=r.padding??40,o=r.yFlip??!1;let s;if("center"in t){const u=t.width/2,d=t.height/2;s={minX:t.center.x-u,maxX:t.center.x+u,minY:t.center.y-d,maxY:t.center.y+d}}else s=t;const a=s.maxX-s.minX||1,c=s.maxY-s.minY||1,l=Math.min((e-2*i)/a,(n-2*i)/c);return di(_i(e/2,n/2),Zu(l,o?-l:l),_i(-(s.minX+a/2),-(s.minY+c/2)))}function VUn(t){const e=[...t.points||[],...(t.lines||[]).flatMap(n=>n.points),...(t.rects||[]).flatMap(n=>{const r=n.width/2,i=n.height/2;return[{x:n.center.x-r,y:n.center.y-i},{x:n.center.x+r,y:n.center.y-i},{x:n.center.x-r,y:n.center.y+i},{x:n.center.x+r,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 r=n.fontSize??12,i=n.text.length*r*YUn,o=r*XUn,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:-o/2},center:{dx:-i/2,dy:-o/2},center_right:{dx:-i,dy:-o/2},bottom_left:{dx:0,dy:-o},bottom_center:{dx:-i/2,dy:-o},bottom_right:{dx:-i,dy:-o}},{dx:c,dy:l}=a[s],u=n.x+c,d=n.y+l;return[{x:u,y:d},{x:u+i,y:d+o}]})];return e.length===0?{minX:-1,maxX:1,minY:-1,maxY:1}:e.reduce((n,r)=>({minX:Math.min(n.minX,r.x),maxX:Math.max(n.maxX,r.x),minY:Math.min(n.minY,r.y),maxY:Math.max(n.maxY,r.y)}),{minX:1/0,maxX:-1/0,minY:1/0,maxY:-1/0})}function GUn(t,e,n={}){const r=e instanceof HTMLCanvasElement?e.getContext("2d"):e;if(!r)throw new Error("Could not get 2D context from canvas");const i=e instanceof HTMLCanvasElement?e.width:e.canvas.width,o=e instanceof HTMLCanvasElement?e.height:e.canvas.height;let s;if(n.transform)s=n.transform;else if(n.viewbox)s=Zut(n.viewbox,i,o,{padding:n.padding,yFlip:n.yFlip});else{const a=VUn(t),c=t.coordinateSystem==="cartesian";s=Zut(a,i,o,{padding:n.padding??40,yFlip:c})}r.clearRect(0,0,i,o),r.save(),t.rects&&t.rects.length>0&&t.rects.forEach(a=>{const c=a.width/2,l=a.height/2,u=mt(s,{x:a.center.x-c,y:a.center.y-l}),d=mt(s,{x:a.center.x+c,y:a.center.y+l}),h=Math.abs(d.x-u.x),f=Math.abs(d.y-u.y);r.beginPath(),r.rect(Math.min(u.x,d.x),Math.min(u.y,d.y),h,f),a.fill&&(r.fillStyle=a.fill,r.fill()),a.stroke&&(r.strokeStyle=a.stroke,r.stroke())}),t.circles&&t.circles.length>0&&t.circles.forEach(a=>{const c=mt(s,a.center),l=a.radius*Math.abs(s.a);r.beginPath(),r.arc(c.x,c.y,l,0,2*Math.PI),a.fill&&(r.fillStyle=a.fill,r.fill()),a.stroke&&(r.strokeStyle=a.stroke??"transparent",r.stroke())}),t.lines&&t.lines.length>0&&t.lines.forEach((a,c)=>{if(a.points.length===0)return;r.beginPath();const l=mt(s,a.points[0]);r.moveTo(l.x,l.y);for(let u=1;u<a.points.length;u++){const d=mt(s,a.points[u]);r.lineTo(d.x,d.y)}if(r.strokeStyle=a.strokeColor||hG[c%hG.length],a.strokeWidth?r.lineWidth=a.strokeWidth*s.a:r.lineWidth=2,r.lineCap="round",a.strokeDash)if(typeof a.strokeDash=="string"){let u;if(a.strokeDash.includes(","))u=a.strokeDash.split(",").map(d=>parseFloat(d.trim())).filter(d=>!Number.isNaN(d));else{const d=parseFloat(a.strokeDash.trim());u=Number.isNaN(d)?[]:[d]}r.setLineDash(u)}else r.setLineDash(a.strokeDash.map(u=>u*Math.abs(s.a)));else r.setLineDash([]);r.stroke()}),t.points&&t.points.length>0&&t.points.forEach((a,c)=>{const l=mt(s,a);r.beginPath(),r.arc(l.x,l.y,3,0,2*Math.PI),r.fillStyle=a.color||hG[c%hG.length],r.fill(),a.label&&!n.disableLabels&&(r.fillStyle=a.color||"black",r.font="12px sans-serif",r.fillText(a.label,l.x+5,l.y-5))}),t.texts&&t.texts.length>0&&t.texts.forEach(a=>{const c=mt(s,{x:a.x,y:a.y});r.fillStyle=a.color||"black",r.font=`${(a.fontSize??12)*Math.abs(s.a)}px sans-serif`;const l=a.anchorSide??"center",u={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"},d={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"};r.textAlign=u[l],r.textBaseline=d[l],r.fillText(a.text,c.x,c.y)}),r.restore()}var qUn=({children:t,transform:e,debugGraphics:n})=>{const r=te.useRef(null),[i,{width:o,height:s}]=gO(),a=E0(c=>c.is_showing_autorouting);return te.useEffect(()=>{a&&r.current&&n&&o&&s&&(r.current.width=o,r.current.height=s,GUn(n,r.current,{transform:e,disableLabels:!0}))},[n,e,o,s,a]),a?G.jsxs("div",{ref:i,style:{position:"relative",width:"100%",height:"100%"},children:[t,G.jsx("canvas",{ref:r,style:{position:"absolute",top:0,left:0,opacity:.5,zIndex:100,width:"100%",height:"100%",pointerEvents:"none"}})]}):t},WUn=({children:t,transform:e=el(),elements:n=[]})=>{const[r,{width:i,height:o}]=gO(),s=te.useRef(null);return te.useEffect(()=>{const a=s.current;if(!a||!i||!o)return;a.width=i,a.height=o;const c=a.getContext("2d");if(!c)return;c.clearRect(0,0,i,o);const l=n.filter(d=>d.type==="pcb_component"),u=n.filter(d=>d.type==="pcb_manual_edit_conflict_warning");c.strokeStyle=hi.board.drc_warning,c.lineWidth=2,u.forEach(d=>{const h=l.find(V=>V.pcb_component_id===d.pcb_component_id);if(!h)return;const{width:f,height:p,center:m}=h,g=mt(e,m),y=f*Math.abs(e.a),_=p*Math.abs(e.d),x=.1*Math.abs(e.a),b=y+x*2,w=_+x*2,S=g.x-b/2,T=g.y-w/2;c.beginPath(),c.rect(S,T,b,w),c.stroke();const C="Manual Edit Conflict",A=4,R=Math.max(8,Math.min(12,10*Math.abs(e.a)));c.font=`${R}px sans-serif`;const O=c.measureText(C).width+A*2,F=R+A*2,B=S+(b-O)/2,j=T+w+5;c.fillStyle="rgba(0, 0, 0, 0.7)",c.beginPath(),c.roundRect(B,j,O,F,3),c.fill(),c.fillStyle=hi.board.drc_warning,c.textAlign="center",c.textBaseline="middle",c.fillText(C,B+O/2,j+F/2)})},[n,e,i,o]),G.jsxs("div",{ref:r,style:{position:"relative",width:"100%",height:"100%"},children:[t,G.jsx("canvas",{ref:s,style:{position:"absolute",top:0,left:0,pointerEvents:"none",zIndex:Wl.warnings}})]})},pG=(t,e,n)=>n(t,e),Kut=(t,e,n,r,i)=>{const o=i*Math.PI/180,s=Math.cos(o),a=Math.sin(o),c=t-n,l=e-r,u=c*s-l*a,d=c*a+l*s;return{x:u+n,y:d+r}},_O=t=>{if(t.length===0)return null;let e=t[0].x,n=t[0].x,r=t[0].y,i=t[0].y;for(const o of t)e=pG(e,o.x,Math.min),n=pG(n,o.x,Math.max),r=pG(r,o.y,Math.min),i=pG(i,o.y,Math.max);return{minX:e,maxX:n,minY:r,maxY:i}},ZUn=(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)}),KUn=(t,e)=>t?ZUn(t,e):e,QUn=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}],r=_O(n);return r?{minX:r.minX-e,maxX:r.maxX+e,minY:r.minY-e,maxY:r.maxY+e}:null}case"rect":{const e=t.w/2,n=t.h/2,r=[{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,o=i===0?r:r.map(s=>Kut(s.x,s.y,t.x,t.y,i));return _O(o)}case"circle":return{minX:t.x-t.r,maxX:t.x+t.r,minY:t.y-t.r,maxY:t.y+t.r};case"oval":return{minX:t.x-t.rX,maxX:t.x+t.rX,minY:t.y-t.rY,maxY:t.y+t.rY};case"pill":{const e=t.w/2,n=t.h/2,r=[{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,o=i===0?r:r.map(s=>Kut(s.x,s.y,t.x,t.y,i));return _O(o)}case"polygon":return _O(t.points);case"polygon_with_arcs":{const e=t.brep_shape.outer_ring.vertices.map(n=>({x:n.x,y:n.y}));return _O(e)}case"text":{const e=t.size??0,n=t.text?t.text.length*e*.6:0,r=e;if(n===0&&r===0)return{minX:t.x,maxX:t.x,minY:t.y,maxY:t.y};const i=n/2,o=r/2;return{minX:t.x-i,maxX:t.x+i,minY:t.y-o,maxY:t.y+o}}default:return null}};function JUn(t){const{dimensionStart:e,dimensionEnd:n,screenDimensionStart:r,screenDimensionEnd:i,flipX:o,flipY:s}=t,a=n.x-e.x,c=n.y-e.y,l=Math.sqrt(a*a+c*c),u=i.x-r.x,d=i.y-r.y,h=Math.sqrt(u*u+d*d),f=Math.atan2(d,u)*(180/Math.PI),p=Math.abs(f)%90,g=Math.min(p,90-p)>15,y=(r.x+i.x)/2,_=(r.y+i.y)/2,x=15,b=f+90;let w=Math.cos(b*Math.PI/180)*x,S=Math.sin(b*Math.PI/180)*x;const T=u>0&&d<0,C=u>0&&d>0,A=u<0&&d>0;o!==s&&!T&&(w=-w,S=-S),T&&(w+=Math.cos(b*Math.PI/180)*-45,S+=Math.sin(b*Math.PI/180)*-45),C&&(w+=Math.cos(b*Math.PI/180)+-20,S+=Math.sin(b*Math.PI/180)+-10),A&&(w+=Math.cos(b*Math.PI/180)*10,S+=Math.sin(b*Math.PI/180)*10);const R=y+w,L=_+S;return{distance:l,screenDistance:h,x:R,y:L,show:l>.01&&h>30&&g}}function eHn(t){const{dimensionStart:e,dimensionEnd:n,screenDimensionStart:r,screenDimensionEnd:i,flipX:o,flipY:s}=t;return te.useMemo(()=>JUn({dimensionStart:e,dimensionEnd:n,screenDimensionStart:r,screenDimensionEnd:i,flipX:o,flipY:s}),[e,n,r,i,o,s])}var tHn=(t,e,n)=>{const r=n*Math.PI/180,i=Math.cos(r),o=Math.sin(r),s=t.x-e.x,a=t.y-e.y,c=s*i-a*o,l=s*o+a*i;return{x:c+e.x,y:l+e.y}},Qut=(t,e,n,r)=>{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 r===0?Object.entries(i).map(([o,s])=>({anchor:o,point:s})):Object.entries(i).map(([o,s])=>({anchor:o,point:tHn(s,t,r)}))},nHn=t=>{switch(t.pcb_drawing_type){case"rect":{const e=t.ccw_rotation??0;return Qut({x:t.x,y:t.y},t.w/2,t.h/2,e)}case"pill":{const e=t.ccw_rotation??0;return Qut({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[]}},rHn=16,AS=5,Jut=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},iHn=({children:t,transform:e,focusOnHover:n=!1,primitives:r=[]})=>{e||(e=el());const[i,o]=te.useState(!1),[s,a]=te.useState(!1),[c,l]=te.useState(!1),[u,d]=te.useState({start:null,end:null}),h=E0(j=>j.is_mouse_over_container),f=te.useCallback(()=>{c&&(l(!1),window.dispatchEvent(new Event("disarm-dimension-tool")))},[c]),[p,m]=te.useState({x:0,y:0}),[g,y]=te.useState({x:0,y:0}),_=te.useRef({x:0,y:0}),x=te.useRef(null),w=x.current?.getBoundingClientRect(),S=te.useMemo(()=>{const j=new Map;for(const V of r){if(!V._element||Jut(V)||V.pcb_drawing_type==="pill"||V.pcb_drawing_type==="rect"&&V.ccw_rotation&&V.ccw_rotation!==0)continue;const q=QUn(V);if(!q)continue;const K=j.get(V._element);j.set(V._element,KUn(K??void 0,q))}return j},[r]),T=te.useMemo(()=>{const j=[];for(const V of r){if(!V._element||Jut(V))continue;const q=nHn(V);if(q.length!==0)for(const K of q)j.push({anchor:K.anchor,point:K.point,element:V._element})}return j},[r]),C=te.useMemo(()=>{const j=[];S.forEach((V,q)=>{if(!V)return;const K=(V.minX+V.maxX)/2,ne=(V.minY+V.maxY)/2,le={top_left:{x:V.minX,y:V.minY},top_center:{x:K,y:V.minY},top_right:{x:V.maxX,y:V.minY},center_left:{x:V.minX,y:ne},center:{x:K,y:ne},center_right:{x:V.maxX,y:ne},bottom_left:{x:V.minX,y:V.maxY},bottom_center:{x:K,y:V.maxY},bottom_right:{x:V.maxX,y:V.maxY}};for(const[ee,ie]of Object.entries(le))j.push({anchor:ee,point:ie,element:q})});for(const V of T)j.push(V);return j.push({anchor:"origin",point:{x:0,y:0},element:null}),j},[S,T]),A=te.useMemo(()=>C.map((j,V)=>({...j,id:`${V}-${j.anchor}`,screenPoint:mt(e,j.point)})),[C,e]),R=te.useCallback(j=>{if(A.length===0)return{point:j,id:null};const V=mt(e,j);let q=null;for(const K of A){const ne=K.screenPoint.x-V.x,le=K.screenPoint.y-V.y,ee=Math.hypot(ne,le);ee>rHn||(!q||ee<q.distance)&&(q={distance:ee,id:K.id,point:K.point})}return q?{point:q.point,id:q.id}:{point:j,id:null}},[A,e]);te.useEffect(()=>{const j=q=>{const K=q.target;if(K.tagName==="INPUT"||K.tagName==="TEXTAREA"||K.isContentEditable)return;const ne=x.current?.contains(document.activeElement)||document.activeElement===x.current;if(!(!h&&!ne)){if(q.key==="d"){const le=R({x:_.current.x,y:_.current.y});m({x:le.point.x,y:le.point.y}),y({x:le.point.x,y:le.point.y}),d({start:le.id,end:le.id}),i?(o(!1),a(!1),d({start:null,end:null})):(o(!0),a(!0)),f()}q.key==="Escape"&&(o(!1),a(!1),d({start:null,end:null}),f())}},V=()=>{l(!0)};return window.addEventListener("keydown",j),window.addEventListener("arm-dimension-tool",V),()=>{window.removeEventListener("keydown",j),window.removeEventListener("arm-dimension-tool",V),f()}},[h,i,f,R]);const L=mt(e,p),O=mt(e,g),F={left:Math.min(L.x,O.x),right:Math.max(L.x,O.x),top:Math.min(L.y,O.y),bottom:Math.max(L.y,O.y),flipX:L.x>O.x,flipY:L.y>O.y,width:0,height:0};F.width=F.right-F.left,F.height=F.bottom-F.top;const B=eHn({dimensionStart:p,dimensionEnd:g,screenDimensionStart:L,screenDimensionEnd:O,flipX:F.flipX,flipY:F.flipY});return G.jsxs("div",{ref:x,"data-pcb-viewer":!0,tabIndex:0,style:{position:"relative",outline:"none"},onMouseEnter:()=>{n&&x.current&&x.current.focus()},onMouseLeave:()=>{x.current&&x.current.blur()},onClick:()=>{x.current&&x.current.focus()},onMouseMove:j=>{const V=j.currentTarget.getBoundingClientRect(),q=j.clientX-V.left,K=j.clientY-V.top,ne=mt(Bx(e),{x:q,y:K});if(_.current.x=ne.x,_.current.y=ne.y,s){const le=R(ne);y({x:le.point.x,y:le.point.y}),d(ee=>({...ee,end:le.id}))}},onMouseDown:j=>{const V=j.currentTarget.getBoundingClientRect(),q=j.clientX-V.left,K=j.clientY-V.top,ne=mt(Bx(e),{x:q,y:K});if(c&&!i){const le=R(ne);m({x:le.point.x,y:le.point.y}),y({x:le.point.x,y:le.point.y}),d({start:le.id,end:le.id}),o(!0),a(!0),f()}else s?(a(!1),d(le=>({...le,end:null}))):i&&(o(!1),d({start:null,end:null}))},children:[t,i&&G.jsxs(G.Fragment,{children:[B.show&&G.jsx("div",{style:{position:"absolute",left:B.x,top:B.y,color:"red",mixBlendMode:"difference",pointerEvents:"none",fontSize:12,fontFamily:"sans-serif",whiteSpace:"nowrap",zIndex:Wl.dimensionOverlay},children:B.distance.toFixed(2)}),G.jsx("div",{style:{position:"absolute",left:F.left,width:F.width,textAlign:"center",top:L.y+2,color:"red",mixBlendMode:"difference",pointerEvents:"none",marginTop:F.flipY?0:-20,fontSize:12,fontFamily:"sans-serif",zIndex:Wl.dimensionOverlay},children:Math.abs(p.x-g.x).toFixed(2)}),G.jsx("div",{style:{position:"absolute",left:O.x,height:F.height,display:"flex",flexDirection:"column",justifyContent:"center",top:F.top,color:"red",pointerEvents:"none",mixBlendMode:"difference",fontSize:12,fontFamily:"sans-serif",zIndex:Wl.dimensionOverlay},children:G.jsx("div",{style:{marginLeft:F.flipX?"-100%":4,paddingRight:4},children:Math.abs(p.y-g.y).toFixed(2)})}),G.jsxs("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none",mixBlendMode:"difference",zIndex:Wl.dimensionOverlay},width:w.width,height:w.height,children:[G.jsx("defs",{children:G.jsx("marker",{id:"head",orient:"auto",markerWidth:"3",markerHeight:"4",refX:"2",refY:"2",children:G.jsx("path",{d:"M0,0 V4 L2,2 Z",fill:"red"})})}),G.jsx("line",{x1:L.x,y1:L.y,x2:O.x,y2:O.y,markerEnd:"url(#head)",strokeWidth:1.5,fill:"none",stroke:"red"}),G.jsx("line",{x1:L.x,y1:L.y,x2:O.x,y2:L.y,strokeWidth:1.5,fill:"none",strokeDasharray:"2,2",stroke:"red"}),G.jsx("line",{x1:O.x,y1:L.y,x2:O.x,y2:O.y,strokeWidth:1.5,fill:"none",strokeDasharray:"2,2",stroke:"red"})]}),s&&A.map(j=>{const V=j.id===u.start||j.id===u.end,q=AS/2;return G.jsxs("svg",{width:AS,height:AS,style:{position:"absolute",left:j.screenPoint.x-q,top:j.screenPoint.y-q,pointerEvents:"none",zIndex:Wl.dimensionOverlay},children:[G.jsx("line",{x1:0,y1:0,x2:AS,y2:AS,stroke:V?"#66ccff":"white",strokeWidth:1}),G.jsx("line",{x1:AS,y1:0,x2:0,y2:AS,stroke:V?"#66ccff":"white",strokeWidth:1})]},j.id)}),G.jsxs("div",{style:{right:0,bottom:0,position:"absolute",color:"red",fontFamily:"sans-serif",fontSize:12,margin:4},children:["(",p.x.toFixed(2),",",p.y.toFixed(2),")",G.jsx("br",{}),"(",g.x.toFixed(2),",",g.y.toFixed(2),")",G.jsx("br",{}),"dist:"," ",Math.sqrt((g.x-p.x)**2+(g.y-p.y)**2).toFixed(2)]})]})]})},oHn=(t,e,n=0)=>{const r=t.width/2,i=t.height/2,o=t.center.x-r-n,s=t.center.x+r+n,a=t.center.y-i-n,c=t.center.y+i+n;return e.x>o&&e.x<s&&e.y>a&&e.y<c},sHn=({children:t,disabled:e,transform:n,soup:r,cancelPanDrag:i,onCreateEditEvent:o,onModifyEditEvent:s})=>{n||(n=el());const a=te.useRef(null),[c,l]=te.useState(null),[u,d]=te.useState(null),h=c!==null;E0(g=>g.in_edit_mode);const f=E0(g=>g.in_move_footprint_mode),p=E0(g=>g.setIsMovingComponent),m=e||!f;return G.jsxs("div",{ref:a,style:{position:"relative",overflow:"hidden"},onMouseDown:g=>{if(m)return;const y=g.currentTarget.getBoundingClientRect(),_=g.clientX-y.left,x=g.clientY-y.top;if(Number.isNaN(_)||Number.isNaN(x))return;const b=mt(Bx(n),{x:_,y:x});let w=!1;for(const S of r)if(S.type==="pcb_component"&&oHn(S,b,10/n.a)){i(),l(S.pcb_component_id),w=!0;const T=Math.random().toString();d({dragStart:b,originalCenter:S.center,dragEnd:b,edit_event_id:T}),o({edit_event_id:T,edit_event_type:"edit_pcb_component_location",pcb_edit_event_type:"edit_component_location",pcb_component_id:S.pcb_component_id,original_center:S.center,new_center:S.center,in_progress:!0,created_at:Date.now()}),p(!0);break}if(w||l(null),w)return g.preventDefault(),!1},onMouseMove:g=>{if(!c||!u)return;const y=g.currentTarget.getBoundingClientRect(),_=g.clientX-y.left,x=g.clientY-y.top;if(Number.isNaN(_)||Number.isNaN(x))return;const b=mt(Bx(n),{x:_,y:x});d({...u,dragEnd:b}),s({edit_event_id:u.edit_event_id,new_center:{x:u.originalCenter.x+b.x-u.dragStart.x,y:u.originalCenter.y+b.y-u.dragStart.y}})},onMouseUp:g=>{c&&(l(null),p(!1),u&&(s({edit_event_id:u.edit_event_id,in_progress:!1}),d(null)))},children:[t,!m&&r.filter(g=>g.type==="pcb_component").map(g=>{if(!g?.center)return null;const y=mt(n,g.center);return G.jsx("div",{style:{position:"absolute",pointerEvents:"none",left:y.x,top:y.y,width:g.width*n.a+20,height:g.height*n.a+20,transform:"translate(-50%, -50%)",background:h&&c===g.pcb_component_id?"rgba(255, 0, 0, 0.2)":""}},g.pcb_component_id)})]})},aHn=({hotkeys:t})=>(te.useEffect(()=>{const e=n=>{t.forEach(r=>{n.key===r.key&&r.onUse()})};return window.addEventListener("keydown",e),()=>{window.removeEventListener("keydown",e)}},[t]),G.jsx("div",{className:vP`
5418
+ $1`).replace(/>(\s*)(?=<!--\s*\/)/g,"> ")}}});function Tut(t,e,n){if(!e||!n)return;let r=t.get(e);r||(r=new Set,t.set(e,r)),r.add(n);let i=t.get(n);i||(i=new Set,t.set(n,i)),i.add(e)}function pjn(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]),c=new Map,l=new Map;for(const d of t)if(d.type==="source_group"){const h=d.source_group_id,f=d.subcircuit_id;f&&l.set(h,f);const p=d.parent_source_group_id;p&&(c.has(p)||c.set(p,[]),c.get(p).push(h))}let u;for(const[d,h]of l)if(h===e.subcircuit_id){u=d;break}if(u){const d=h=>{const f=c.get(h)||[];for(const p of f){const m=l.get(p);m&&a.add(m),d(p)}};d(u),n={...e,subcircuit_ids:Array.from(a)}}}const r=new Map;for(const a of t){const c=`${a.type}_id`,l=a[c];typeof l=="string"&&r.set(l,a)}const i=new Map;for(const a of t){const c=Object.entries(a);for(const[l,u]of c)if(l!=="parent_source_group_id"){if(l.endsWith("_id")&&typeof u=="string"){const d=r.get(u);Tut(i,a,d)}else if(l.endsWith("_ids")&&Array.isArray(u)){for(const d of u)if(typeof d=="string"){const h=r.get(d);Tut(i,a,h)}}}}const o=[],s=new Set;for(const a of t){let c=!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))&&(c=!0),c&&(o.push(a),s.add(a))}for(;o.length>0;){const a=o.shift(),c=i.get(a);if(c)for(const l of c)s.has(l)||(s.add(l),o.push(l))}return t.filter(a=>s.has(a))}var cG=(t,e={})=>{const n=t;let r=n._internal_store;if(!r){r={counts:{},editCount:0},n._internal_store=r;for(const o of n){const s=o.type,a=o[`${s}_id`];if(!a)continue;const c=Number.parseInt(a.split("_").pop());Number.isNaN(c)||(r.counts[s]=Math.max(r.counts[s]??0,c))}}const i=new Proxy({},{get:(o,s)=>{if(s==="toArray")return()=>(n.editCount=r.editCount,n);if(s==="editCount")return r.editCount;if(s==="subtree")return c=>cG(pjn(n,c),e);if(s==="insert")return c=>{const l=c.type;if(!l)throw new Error("insert requires an element with a type");r.counts[l]??=-1,r.counts[l]++;const u=r.counts[l],d={...c,type:l,[`${l}_id`]:`${l}_${u}`};return e.validateInserts&&(e_e[l]??OV).parse(d),n.push(d),r.editCount++,d};if(s==="insertAll")return c=>c.map(l=>i.insert(l));const a=s;return{get:c=>n.find(l=>l.type===a&&l[`${a}_id`]===c),getUsing:c=>{const l=Object.keys(c);if(l.length!==1)throw new Error("getUsing requires exactly one key, e.g. { pcb_component_id }");const u=l[0],d=u.replace("_id",""),h=n.find(f=>f.type===d&&f[u]===c[u]);return h?n.find(f=>f.type===a&&f[`${a}_id`]===h[`${a}_id`]):null},getWhere:c=>{const l=Object.keys(c);return n.find(u=>u.type===a&&l.every(d=>u[d]===c[d]))},list:c=>{const l=c?Object.keys(c):[];return n.filter(u=>u.type===a&&l.every(d=>u[d]===c[d]))},insert:c=>{r.counts[a]??=-1,r.counts[a]++;const l=r.counts[a],u={type:a,[`${a}_id`]:`${a}_${l}`,...c};return e.validateInserts&&(e_e[a]??OV).parse(u),n.push(u),r.editCount++,u},delete:c=>{const l=n.find(u=>u[`${a}_id`]===c);l&&(n.splice(n.indexOf(l),1),r.editCount++)},update:(c,l)=>{const u=n.find(d=>d.type===a&&d[`${a}_id`]===c);return u?(Object.assign(u,l),r.editCount++,u):null},select:c=>{if(a==="source_component")return n.find(l=>l.type==="source_component"&&l.name===c.replace(/\./g,""));if(a==="pcb_port"||a==="source_port"||a==="schematic_port"){const[l,u]=c.replace(/\./g,"").split(/[\s\>]+/),d=n.find(f=>f.type==="source_component"&&f.name===l);if(!d)return null;const h=n.find(f=>f.type==="source_port"&&f.source_component_id===d.source_component_id&&(f.name===u||(f.port_hints??[]).includes(u)));if(!h)return null;if(a==="source_port")return h;if(a==="pcb_port")return n.find(f=>f.type==="pcb_port"&&f.source_port_id===h.source_port_id);if(a==="schematic_port")return n.find(f=>f.type==="schematic_port"&&f.source_port_id===h.source_port_id)}}}}});return i};cG.unparsed=cG;var B9=cG;function D_e(t){const e=t.type;return`${e}:${t[`${e}_id`]}`}var Eut=(t,e={})=>{let n=t._internal_store_indexed;if(!n){n={counts:{},editCount:0,indexes:{}};for(const s of t){const a=s.type,c=s[`${a}_id`];if(!c)continue;const l=Number.parseInt(c.split("_").pop()||"");Number.isNaN(l)||(n.counts[a]=Math.max(n.counts[a]??0,l))}const i=e.indexConfig||{},o=n.indexes;if(i.byId&&(o.byId=new Map),i.byType&&(o.byType=new Map),i.byRelation&&(o.byRelation=new Map),i.bySubcircuit&&(o.bySubcircuit=new Map),i.byCustomField&&i.byCustomField.length>0){o.byCustomField=new Map;for(const s of i.byCustomField)o.byCustomField.set(s,new Map)}for(const s of t){if(i.byId){const a=D_e(s);o.byId.set(a,s)}if(i.byType){const a=o.byType.get(s.type)||[];a.push(s),o.byType.set(s.type,a)}if(i.byRelation){const a=Object.entries(s);for(const[c,l]of a)if(c.endsWith("_id")&&c!==`${s.type}_id`&&typeof l=="string"){const u=o.byRelation.get(c)||new Map,d=u.get(l)||[];d.push(s),u.set(l,d),o.byRelation.set(c,u)}}if(i.bySubcircuit&&"subcircuit_id"in s){const a=s.subcircuit_id;if(a&&typeof a=="string"){const c=o.bySubcircuit.get(a)||[];c.push(s),o.bySubcircuit.set(a,c)}}if(i.byCustomField&&o.byCustomField){for(const a of i.byCustomField)if(a in s){const c=s[a];if(c!==void 0&&(typeof c=="string"||typeof c=="number")){const l=String(c),u=o.byCustomField.get(a),d=u.get(l)||[];d.push(s),u.set(l,d)}}}}t._internal_store_indexed=n}return new Proxy({},{get:(i,o)=>{if(o==="toArray")return()=>(t.editCount=n.editCount,t);if(o==="editCount")return n.editCount;const s=o;return{get:a=>{const c=e.indexConfig||{};return c.byId&&n.indexes.byId?n.indexes.byId.get(`${s}:${a}`)||null:c.byType&&n.indexes.byType?(n.indexes.byType.get(s)||[]).find(u=>u[`${s}_id`]===a)||null:t.find(l=>l.type===s&&l[`${s}_id`]===a)||null},getUsing:a=>{const c=e.indexConfig||{},l=Object.keys(a);if(l.length!==1)throw new Error("getUsing requires exactly one key, e.g. { pcb_component_id }");const u=l[0],d=u.replace("_id","");if(c.byRelation&&n.indexes.byRelation){const f=n.indexes.byRelation.get(u);if(f){const m=(f.get(a[u])||[]).find(y=>y.type===d);if(!m)return null;const g=m[`${s}_id`];return c.byId&&n.indexes.byId?n.indexes.byId.get(`${s}:${g}`)||null:c.byType&&n.indexes.byType?(n.indexes.byType.get(s)||[]).find(_=>_[`${s}_id`]===g)||null:t.find(y=>y.type===s&&y[`${s}_id`]===g)||null}}const h=t.find(f=>f.type===d&&f[u]===a[u]);return h&&t.find(f=>f.type===s&&f[`${s}_id`]===h[`${s}_id`])||null},getWhere:a=>{const c=e.indexConfig||{},l=Object.keys(a);if(l.length===1&&c.byCustomField&&n.indexes.byCustomField){const u=l[0],d=n.indexes.byCustomField.get(u);if(d){const h=String(a[u]);return(d.get(h)||[]).find(p=>p.type===s)||null}}if("subcircuit_id"in a&&c.bySubcircuit&&n.indexes.bySubcircuit){const u=a.subcircuit_id;return(n.indexes.bySubcircuit.get(u)||[]).find(h=>h.type===s&&l.every(f=>h[f]===a[f]))||null}return c.byType&&n.indexes.byType?(n.indexes.byType.get(s)||[]).find(d=>l.every(h=>d[h]===a[h]))||null:t.find(u=>u.type===s&&l.every(d=>u[d]===a[d]))||null},list:a=>{const c=e.indexConfig||{},l=a?Object.keys(a):[];if(l.length===0&&c.byType&&n.indexes.byType)return n.indexes.byType.get(s)||[];if(l.length===1&&l[0]==="subcircuit_id"&&c.bySubcircuit&&n.indexes.bySubcircuit){const d=a.subcircuit_id;return(n.indexes.bySubcircuit.get(d)||[]).filter(f=>f.type===s)}let u;return c.byType&&n.indexes.byType?u=n.indexes.byType.get(s)||[]:u=t.filter(d=>d.type===s),l.length>0?u.filter(d=>l.every(h=>d[h]===a[h])):u},insert:a=>{n.counts[s]??=-1,n.counts[s]++;const c=n.counts[s],l={type:s,[`${s}_id`]:`${s}_${c}`,...a};e.validateInserts&&(e_e[s]??OV).parse(l),t.push(l),n.editCount++;const u=e.indexConfig||{};if(u.byId&&n.indexes.byId){const d=D_e(l);n.indexes.byId.set(d,l)}if(u.byType&&n.indexes.byType){const d=n.indexes.byType.get(s)||[];d.push(l),n.indexes.byType.set(s,d)}if(u.byRelation&&n.indexes.byRelation){const d=Object.entries(l);for(const[h,f]of d)if(h.endsWith("_id")&&h!==`${l.type}_id`&&typeof f=="string"){const p=n.indexes.byRelation.get(h)||new Map,m=p.get(f)||[];m.push(l),p.set(f,m),n.indexes.byRelation.set(h,p)}}if(u.bySubcircuit&&n.indexes.bySubcircuit&&"subcircuit_id"in l){const d=l.subcircuit_id;if(d&&typeof d=="string"){const h=n.indexes.bySubcircuit.get(d)||[];h.push(l),n.indexes.bySubcircuit.set(d,h)}}if(u.byCustomField&&n.indexes.byCustomField){for(const d of u.byCustomField)if(d in l){const h=l[d];if(h!==void 0&&(typeof h=="string"||typeof h=="number")){const f=String(h),p=n.indexes.byCustomField.get(d),m=p.get(f)||[];m.push(l),p.set(f,m)}}}return l},delete: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(h=>h[`${s}_id`]===a):l=t.find(d=>d[`${s}_id`]===a),!l)return;const u=t.indexOf(l);if(u>=0&&(t.splice(u,1),n.editCount++),c.byId&&n.indexes.byId){const d=D_e(l);n.indexes.byId.delete(d)}if(c.byType&&n.indexes.byType){const h=(n.indexes.byType.get(s)||[]).filter(f=>f[`${s}_id`]!==a);n.indexes.byType.set(s,h)}if(c.byRelation&&n.indexes.byRelation)for(const[d,h]of n.indexes.byRelation.entries())for(const[f,p]of h.entries()){const m=p.filter(g=>g!==l);m.length===0?h.delete(f):h.set(f,m)}if(c.bySubcircuit&&n.indexes.bySubcircuit&&"subcircuit_id"in l){const d=l.subcircuit_id;if(d){const f=(n.indexes.bySubcircuit.get(d)||[]).filter(p=>p!==l);f.length===0?n.indexes.bySubcircuit.delete(d):n.indexes.bySubcircuit.set(d,f)}}if(c.byCustomField&&n.indexes.byCustomField)for(const d of n.indexes.byCustomField.values())for(const[h,f]of d.entries()){const p=f.filter(m=>m!==l);p.length===0?d.delete(h):d.set(h,p)}},update:(a,c)=>{const l=e.indexConfig||{};let u;if(l.byId&&n.indexes.byId?u=n.indexes.byId.get(`${s}:${a}`):l.byType&&n.indexes.byType?u=(n.indexes.byType.get(s)||[]).find(h=>h[`${s}_id`]===a):u=t.find(d=>d.type===s&&d[`${s}_id`]===a),!u)return null;if(l.byRelation&&n.indexes.byRelation){const d=Object.entries(u);for(const[h,f]of d)if(h.endsWith("_id")&&h!==`${u.type}_id`&&typeof f=="string"&&h in c&&c[h]!==f){const p=n.indexes.byRelation.get(h);if(p){const g=(p.get(f)||[]).filter(y=>y!==u);g.length===0?p.delete(f):p.set(f,g)}}}if(l.bySubcircuit&&n.indexes.bySubcircuit&&"subcircuit_id"in u&&"subcircuit_id"in c){const d=u.subcircuit_id,h=c.subcircuit_id;if(d!==h){const p=(n.indexes.bySubcircuit.get(d)||[]).filter(m=>m!==u);p.length===0?n.indexes.bySubcircuit.delete(d):n.indexes.bySubcircuit.set(d,p)}}if(l.byCustomField&&n.indexes.byCustomField){for(const d of l.byCustomField)if(d in u&&d in c&&u[d]!==c[d]){const h=n.indexes.byCustomField.get(d);if(h){const f=String(u[d]),m=(h.get(f)||[]).filter(g=>g!==u);m.length===0?h.delete(f):h.set(f,m)}}}if(Object.assign(u,c),n.editCount++,l.byRelation&&n.indexes.byRelation){const d=Object.entries(u);for(const[h,f]of d)if(h.endsWith("_id")&&h!==`${u.type}_id`&&typeof f=="string"&&h in c){const p=n.indexes.byRelation.get(h)||new Map,m=p.get(f)||[];m.includes(u)||(m.push(u),p.set(f,m),n.indexes.byRelation.set(h,p))}}if(l.bySubcircuit&&n.indexes.bySubcircuit&&"subcircuit_id"in u&&"subcircuit_id"in c){const d=u.subcircuit_id;if(d&&typeof d=="string"){const h=n.indexes.bySubcircuit.get(d)||[];h.includes(u)||(h.push(u),n.indexes.bySubcircuit.set(d,h))}}if(l.byCustomField&&n.indexes.byCustomField){for(const d of l.byCustomField)if(d in u&&d in c){const h=u[d];if(h!==void 0&&(typeof h=="string"||typeof h=="number")){const f=String(h),p=n.indexes.byCustomField.get(d),m=p.get(f)||[];m.includes(u)||(m.push(u),p.set(f,m))}}}return u},select:a=>{if(s==="source_component")return t.find(c=>c.type==="source_component"&&c.name===a.replace(/\./g,""))||null;if(s==="pcb_port"||s==="source_port"||s==="schematic_port"){const[c,l]=a.replace(/\./g,"").split(/[\s\>]+/),u=t.find(h=>h.type==="source_component"&&h.name===c);if(!u)return null;const d=t.find(h=>h.type==="source_port"&&h.source_component_id===u.source_component_id&&(h.name===l||(h.port_hints??[]).includes(l)));if(!d)return null;if(s==="source_port")return d;if(s==="pcb_port")return t.find(h=>h.type==="pcb_port"&&h.source_port_id===d.source_port_id)||null;if(s==="schematic_port")return t.find(h=>h.type==="schematic_port"&&h.source_port_id===d.source_port_id)||null}return null}}}})};Eut.unparsed=Eut;var fjn=t=>{const e=t.type;return t[`${e}_id`]},Cut=(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)}),lG=(t,e,n)=>{const r=n/2;return{minX:t-r,minY:e-r,maxX:t+r,maxY:e+r}},mjn=(t,e,n,r,i)=>{const o=n/2,s=r/2,a=i*Math.PI/180,c=Math.cos(a),l=Math.sin(a),u=[{x:-o,y:-s},{x:o,y:-s},{x:o,y:s},{x:-o,y:s}].map(d=>({x:t+d.x*c-d.y*l,y:e+d.x*l+d.y*c}));return{minX:Math.min(...u.map(d=>d.x)),minY:Math.min(...u.map(d=>d.y)),maxX:Math.max(...u.map(d=>d.x)),maxY:Math.max(...u.map(d=>d.y))}},z_e=t=>{let e=Number.POSITIVE_INFINITY,n=Number.POSITIVE_INFINITY,r=Number.NEGATIVE_INFINITY,i=Number.NEGATIVE_INFINITY;for(const o of t){if(!o.type.startsWith("pcb_"))continue;if(o.type==="pcb_smtpad"&&o.shape==="polygon"&&Array.isArray(o.points)){for(const u of o.points)e=Math.min(e,u.x),n=Math.min(n,u.y),r=Math.max(r,u.x),i=Math.max(i,u.y);continue}if(o.type==="pcb_hole"&&o.hole_shape==="circle"){const u=lG(o.x,o.y,o.hole_diameter);e=Math.min(e,u.minX),n=Math.min(n,u.minY),r=Math.max(r,u.maxX),i=Math.max(i,u.maxY);continue}if(o.type==="pcb_plated_hole"){let u;if("outer_diameter"in o&&typeof o.outer_diameter=="number"?u=lG(o.x,o.y,o.outer_diameter):"hole_diameter"in o&&typeof o.hole_diameter=="number"&&(u=lG(o.x,o.y,o.hole_diameter)),"rect_pad_width"in o&&typeof o.rect_pad_width=="number"&&"rect_pad_height"in o&&typeof o.rect_pad_height=="number"){const d=mjn(o.x,o.y,o.rect_pad_width,o.rect_pad_height,"rect_ccw_rotation"in o?o.rect_ccw_rotation??0:0);u=u?Cut(u,d):d}if("hole_diameter"in o&&typeof o.hole_diameter=="number"){const d=lG(o.x+("hole_offset_x"in o?o.hole_offset_x??0:0),o.y+("hole_offset_y"in o?o.hole_offset_y??0:0),o.hole_diameter);u=u?Cut(u,d):d}if(u){e=Math.min(e,u.minX),n=Math.min(n,u.minY),r=Math.max(r,u.maxX),i=Math.max(i,u.maxY);continue}}let s,a,c,l;if("x"in o&&"y"in o&&(s=Number(o.x),a=Number(o.y)),"outer_diameter"in o&&(c=Number(o.outer_diameter),l=Number(o.outer_diameter)),"width"in o&&(c=Number(o.width)),"height"in o&&(l=Number(o.height)),"center"in o&&(s=o.center.x,a=o.center.y),s!==void 0&&a!==void 0)e=Math.min(e,s),n=Math.min(n,a),r=Math.max(r,s),i=Math.max(i,a),c!==void 0&&l!==void 0&&(e=Math.min(e,s-c/2),n=Math.min(n,a-l/2),r=Math.max(r,s+c/2),i=Math.max(i,a+l/2)),"radius"in o&&(e=Math.min(e,s-o.radius),n=Math.min(n,a-o.radius),r=Math.max(r,s+o.radius),i=Math.max(i,a+o.radius));else if(o.type==="pcb_trace")for(const u of o.route)e=Math.min(e,u.x),n=Math.min(n,u.y),r=Math.max(r,u.x),i=Math.max(i,u.y);else if(o.type==="pcb_courtyard_outline")for(const u of o.outline)e=Math.min(e,u.x),n=Math.min(n,u.y),r=Math.max(r,u.x),i=Math.max(i,u.y);else if(o.type==="pcb_courtyard_polygon")for(const u of o.points)e=Math.min(e,u.x),n=Math.min(n,u.y),r=Math.max(r,u.x),i=Math.max(i,u.y)}return{minX:e,minY:n,maxX:r,maxY:i}};function yjn(t){let e=0;if(t.length==0)return e;for(var n=0;n<t.length;n++){var r=t.charCodeAt(n);e=(e<<5)-e+r,e=e&e}return Math.abs(e)}var Put=[["#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"]],gjn=t=>{let{x:e,y:n,width:r,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,r=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(f=>f.x),c=t.points.map(f=>f.y),l=Math.min(...a),u=Math.max(...a),d=Math.min(...c),h=Math.max(...c);e=(l+u)/2,n=(d+h)/2,r=u-l,i=h-d}const o=t.text||t.name||t.source?.text||t.source?.name||"?",s=t;return e===void 0||n===void 0?null:(r===void 0&&"outer_diameter"in t&&(r=t.outer_diameter,i=t.outer_diameter),(r===void 0||i===void 0)&&(r=.1,i=.1),{x:e,y:n,width:r,height:i,title:o,content:s,bg_color:Put[yjn(t.type||o)%Put.length]?.[4]??"#f00"})},_jn=t=>!!t,xjn=t=>{const e=t.filter(l=>l.type.startsWith("pcb_")||l.type.startsWith("schematic_")).concat(t.filter(l=>l.type==="pcb_trace"||l.type==="schematic_trace").flatMap(l=>l.route)).map(l=>gjn(l)).filter(_jn);if(e.length===0)return{center:{x:0,y:0},width:0,height:0};let n=e[0].x-e[0].width/2,r=e[0].x+e[0].width/2,i=e[0].y-e[0].height/2,o=e[0].y+e[0].height/2;for(const l of e.slice(1))n=Math.min(n,l.x-l.width/2),r=Math.max(r,l.x+l.width/2),i=Math.min(i,l.y-l.height/2),o=Math.max(o,l.y+l.height/2);const s=r-n,a=o-i;return{center:{x:n+s/2,y:i+a/2},width:s,height:a}},dy={IS_SHOWING_PCB_GROUPS:"pcb_viewer_is_showing_pcb_groups",PCB_GROUP_VIEW_MODE:"pcb_viewer_group_view_mode",IS_SHOWING_COPPER_POURS:"pcb_viewer_is_showing_copper_pours",IS_SHOWING_COURTYARDS:"pcb_viewer_is_showing_courtyards",IS_SHOWING_GROUP_ANCHOR_OFFSETS:"pcb_viewer_is_showing_group_anchor_offsets",IS_SHOWING_SOLDER_MASK:"pcb_viewer_is_showing_solder_mask",IS_SHOWING_FABRICATION_NOTES:"pcb_viewer_is_showing_fabrication_notes",IS_SHOWING_SILKSCREEN:"pcb_viewer_is_showing_silkscreen"},CS=(t,e)=>{if(typeof window>"u")return e;try{const n=localStorage.getItem(t);return n!==null?JSON.parse(n):e}catch{return e}},PS=(t,e)=>{if(!(typeof window>"u"))try{localStorage.setItem(t,JSON.stringify(e))}catch{}},bjn=(t,e)=>{if(typeof window>"u")return e;try{const n=localStorage.getItem(t);return n!==null?JSON.parse(n):e}catch{return e}},vjn=(t,e)=>{if(!(typeof window>"u"))try{localStorage.setItem(t,JSON.stringify(e))}catch{}},wjn="named_only",Sjn=(t={},e=!1)=>ilt(n=>({selected_layer:"top",pcb_viewer_id:`pcb_viewer_${Math.random().toString().slice(2,10)}`,in_edit_mode:!1,in_move_footprint_mode:!1,in_draw_trace_mode:!1,is_moving_component:!1,is_drawing_trace:!1,is_mouse_over_container:!1,is_showing_multiple_traces_length:!1,is_showing_rats_nest:!1,is_showing_autorouting:!0,is_showing_drc_errors:!0,is_showing_copper_pours:CS(dy.IS_SHOWING_COPPER_POURS,!0),is_showing_courtyards:CS(dy.IS_SHOWING_COURTYARDS,!0),is_showing_pcb_groups:e?!1:CS(dy.IS_SHOWING_PCB_GROUPS,!0),is_showing_group_anchor_offsets:CS(dy.IS_SHOWING_GROUP_ANCHOR_OFFSETS,!1),is_showing_solder_mask:CS(dy.IS_SHOWING_SOLDER_MASK,!1),is_showing_silkscreen:CS(dy.IS_SHOWING_SILKSCREEN,!0),is_showing_fabrication_notes:CS(dy.IS_SHOWING_FABRICATION_NOTES,!1),pcb_group_view_mode:e?"all":bjn(dy.PCB_GROUP_VIEW_MODE,wjn),hovered_error_id:null,...t,selectLayer:r=>n({selected_layer:r}),setEditMode:r=>n({in_edit_mode:r!=="off",in_move_footprint_mode:r==="move_footprint",in_draw_trace_mode:r==="draw_trace",is_moving_component:!1,is_drawing_trace:!1}),setIsShowingRatsNest:r=>n({is_showing_rats_nest:r}),setIsMovingComponent:r=>n({is_moving_component:r}),setIsDrawingTrace:r=>n({is_drawing_trace:r}),setIsMouseOverContainer:r=>n({is_mouse_over_container:r}),setIsShowingMultipleTracesLength:r=>n({is_showing_multiple_traces_length:r}),setIsShowingAutorouting:r=>n({is_showing_autorouting:r}),setIsShowingDrcErrors:r=>n({is_showing_drc_errors:r}),setIsShowingCopperPours:r=>{PS(dy.IS_SHOWING_COPPER_POURS,r),n({is_showing_copper_pours:r})},setIsShowingCourtyards:r=>{PS(dy.IS_SHOWING_COURTYARDS,r),n({is_showing_courtyards:r})},setIsShowingPcbGroups:r=>{e||(PS(dy.IS_SHOWING_PCB_GROUPS,r),n({is_showing_pcb_groups:r}))},setIsShowingGroupAnchorOffsets:r=>{PS(dy.IS_SHOWING_GROUP_ANCHOR_OFFSETS,r),n({is_showing_group_anchor_offsets:r})},setIsShowingSolderMask:r=>{PS(dy.IS_SHOWING_SOLDER_MASK,r),n({is_showing_solder_mask:r})},setIsShowingSilkscreen:r=>{PS(dy.IS_SHOWING_SILKSCREEN,r),n({is_showing_silkscreen:r})},setIsShowingFabricationNotes:r=>{PS(dy.IS_SHOWING_FABRICATION_NOTES,r),n({is_showing_fabrication_notes:r})},setPcbGroupViewMode:r=>{e||(vjn(dy.PCB_GROUP_VIEW_MODE,r),n({pcb_group_view_mode:r}))},setHoveredErrorId:r=>n({hovered_error_id:r})})),E0=t=>{const e=te.useContext(Aut);return flt(e,t)},Aut=te.createContext(null),Mjn=({children:t,initialState:e,disablePcbGroups:n})=>{const r=te.useMemo(()=>Sjn(e,n),[n]);return G.jsx(Aut.Provider,{value:r,children:t})},Tjn=()=>{const t=E0(n=>n.pcb_viewer_id),e=(n,r)=>Tl(n,{containerId:t,...r});return e.error=(n,r)=>Tl.error(n,{containerId:t,...r}),e.promise=Tl.promise,e},Ejn=()=>{te.useEffect(()=>{m$n()},[]);const t=E0(e=>e.pcb_viewer_id);return G.jsx(f$n,{position:"top-center",containerId:t})};function Cjn(){var t=te.useRef(!1),e=te.useCallback(function(){return t.current},[]);return te.useEffect(function(){return t.current=!0,function(){t.current=!1}},[]),e}var Pjn=function(t){t===void 0&&(t={});var e=te.useState(t),n=e[0],r=e[1],i=te.useCallback(function(o){r(function(s){return Object.assign({},s,o instanceof Function?o(s):o)})},[]);return[n,i]},Ajn=Pjn,Rjn=function(){},Rut=typeof window<"u",Ijn=I_e(WBn()),Njn=function(){var t=Cjn(),e=Ajn({value:void 0,error:void 0,noUserInteraction:!0}),n=e[0],r=e[1],i=te.useCallback(function(o){if(t()){var s,a;try{if(typeof o!="string"&&typeof o!="number"){var c=new Error("Cannot copy typeof "+typeof o+" to clipboard, must be a string");console.error(c),r({value:o,error:c,noUserInteraction:!0});return}else if(o===""){var c=new Error("Cannot copy empty string to clipboard.");console.error(c),r({value:o,error:c,noUserInteraction:!0});return}a=o.toString(),s=(0,Ijn.default)(a),r({value:a,error:void 0,noUserInteraction:s})}catch(l){r({value:a,error:l,noUserInteraction:s})}}},[]);return[n,i]},kjn=Njn,Ojn=Rut?te.useLayoutEffect:te.useEffect,Ljn=Ojn,Iut={x:0,y:0,width:0,height:0,top:0,left:0,bottom:0,right:0};function Djn(){var t=te.useState(null),e=t[0],n=t[1],r=te.useState(Iut),i=r[0],o=r[1],s=te.useMemo(function(){return new window.ResizeObserver(function(a){if(a[0]){var c=a[0].contentRect,l=c.x,u=c.y,d=c.width,h=c.height,f=c.top,p=c.left,m=c.bottom,g=c.right;o({x:l,y:u,width:d,height:h,top:f,left:p,bottom:m,right:g})}})},[]);return Ljn(function(){if(e)return s.observe(e),function(){s.disconnect()}},[e]),[n,i]}var gO=Rut&&typeof window.ResizeObserver<"u"?Djn:function(){return[Rjn,Iut]},Nut=({initialTransform:t,initialTouch1:e,initialTouch2:n,finalTouch1:r,finalTouch2:i})=>{if(!r||!i)return t;const o={x:(e.x+n.x)/2,y:(e.y+n.y)/2},s={x:(r.x+i.x)/2,y:(r.y+i.y)/2},a=Math.hypot(n.x-e.x,n.y-e.y),c=Math.hypot(i.x-r.x,i.y-r.y),l=a===0?1:c/a,u=s.x-o.x,d=s.y-o.y;return di(_i(u,d),_i(o.x,o.y),Zu(l,l),_i(-o.x,-o.y),t)},zjn=(t={})=>{const e=te.useRef(null),[n,r]=te.useState(0),i=t.canvasElm??e.current,[o,s]=te.useState(t.initialTransform??el()),[a,c]=te.useState(0),[l,u]=te.useReducer(x=>x+1,0),d=te.useCallback(x=>{t.onSetTransform&&t.onSetTransform(x),t.transform||s(x)},[t.onSetTransform,s]),h=te.useCallback(x=>{d(x),u()},[d]),f=t.transform??o,p=te.useCallback(()=>{r(Date.now())},[]),m=te.useRef("none"),g=te.useRef(null),y=te.useRef(null);te.useEffect(()=>{const x=t.canvasElm??e.current;if(x&&!i){c(a+1);return}if(!x){const q=setTimeout(()=>{c(a+1)},100);return()=>clearTimeout(q)}let b=t.transform??o,w={x:0,y:0},S={x:0,y:0},T=!1;const C=q=>({x:q.pageX-x.getBoundingClientRect().left-window.scrollX,y:q.pageY-x.getBoundingClientRect().top-window.scrollY});function A(q){t.enabled!==!1&&(t.shouldDrag&&!t.shouldDrag(q)||(w=C(q),!(Date.now()-n<100)&&(T=!0,q.preventDefault())))}function R(q){if(!T||t.enabled===!1||t.shouldDrag&&!t.shouldDrag(q))return;S=C(q);const K=di(_i(S.x-w.x,S.y-w.y),b);d(K),b=K,T=!1}function L(q){if(C(q),!T||t.enabled===!1||t.shouldDrag&&!t.shouldDrag(q))return;S=C(q);const K=di(_i(S.x-w.x,S.y-w.y),b);d(K)}function O(q){if(t.enabled===!1||t.shouldDrag&&!t.shouldDrag(q))return;const K=C(q),ne=di(_i(K.x,K.y),Zu(1-q.deltaY/1e3,1-q.deltaY/1e3),_i(-K.x,-K.y),b);d(ne),b=ne,q.preventDefault()}function F(q){if(!T||t.shouldDrag&&!t.shouldDrag(q))return;if(x){const ne=x.getBoundingClientRect();if(q.clientX>=ne.left+10&&q.clientX<=ne.right-10&&q.clientY>=ne.top+10&&q.clientY<=ne.bottom-10)return}T=!1,S=C(q);const K=di(_i(S.x-w.x,S.y-w.y),b);d(K),b=K}function B(q){if(q.preventDefault(),t.enabled!==!1){if(q.touches.length===1){m.current="drag";const K=q.touches[0];g.current={initialTransform:b,initialTouch:{x:K.clientX,y:K.clientY}}}else if(q.touches.length===2){m.current="pinch";const K=q.touches[0],ne=q.touches[1];y.current={initialTransform:b,initialTouch1:{x:K.clientX,y:K.clientY},initialTouch2:{x:ne.clientX,y:ne.clientY},finalTouch1:null,finalTouch2:null}}}}function j(q){if(q.preventDefault(),t.enabled!==!1){if(m.current==="drag"&&q.touches.length===1&&g.current){const K=q.touches[0],ne={x:K.clientX,y:K.clientY},le=ne.x-g.current.initialTouch.x,ee=ne.y-g.current.initialTouch.y,ie=di(_i(le,ee),g.current.initialTransform);d(ie)}else if(m.current==="pinch"&&q.touches.length===2&&y.current){const K=q.touches[0],ne=q.touches[1];y.current.finalTouch1={x:K.clientX,y:K.clientY},y.current.finalTouch2={x:ne.clientX,y:ne.clientY};const le=Nut(y.current);d(le)}}}function V(q){q.preventDefault();const K=q.changedTouches[0];if(m.current==="drag"&&g.current&&K){const ne={x:K.clientX,y:K.clientY},le=ne.x-g.current.initialTouch.x,ee=ne.y-g.current.initialTouch.y,ie=di(_i(le,ee),g.current.initialTransform);d(ie),b=ie}else if(m.current==="pinch"&&y.current){const ne=Nut(y.current);d(ne),b=ne}m.current="none",g.current=null,y.current=null}return x.addEventListener("mousedown",A),x.addEventListener("mouseup",R),window.addEventListener("mousemove",L),x.addEventListener("mouseout",F),x.addEventListener("wheel",O),x.addEventListener("touchstart",B,{passive:!1}),x.addEventListener("touchmove",j,{passive:!1}),x.addEventListener("touchend",V,{passive:!1}),x.addEventListener("touchcancel",V,{passive:!1}),()=>{x.removeEventListener("mousedown",A),x.removeEventListener("mouseup",R),window.removeEventListener("mousemove",L),x.removeEventListener("mouseout",F),x.removeEventListener("wheel",O),x.removeEventListener("touchstart",B),x.removeEventListener("touchmove",j),x.removeEventListener("touchend",V),x.removeEventListener("touchcancel",V)}},[i,a,l,n,t.enabled,t.shouldDrag]);const _=te.useCallback(x=>mt(f,x),[f]);return{ref:e,transform:f,applyTransformToPoint:_,setTransform:h,cancelDrag:p}},$jn=zjn;function Fjn(t){const e=new Map;let n=0;function r(i){for(const[,s]of e)if(s.has(i))return s;const o=new Set;return e.set(`connectivity_net${n++}`,o),o}for(const i of t){let o=null;for(const s of i){if(!o)o=r(s);else if(!o.has(s)){const a=r(s);if(a!==o){for(const c of a)o.add(c);e.delete(Array.from(e.entries()).find(([,c])=>c===a)[0])}}o.add(s)}}return Object.fromEntries(Array.from(e.entries()).map(([i,o])=>[i,Array.from(o)]))}var Bjn=class{netMap;idToNetMap;constructor(t){this.netMap=t,this.idToNetMap={};for(const[e,n]of Object.entries(t))for(const r of n)this.idToNetMap[r]=e}addConnections(t){for(const e of t){const n=new Set;for(const i of e){const o=this.idToNetMap[i];o&&n.add(o)}let r;if(n.size===0)r=`connectivity_net${Object.keys(this.netMap).length}`,this.netMap[r]=[];else if(n.size===1)r=n.values().next().value??`connectivity_net${Object.keys(this.netMap).length}`;else{r=n.values().next().value??`connectivity_net${Object.keys(this.netMap).length}`;for(const i of n)if(i!==r){this.netMap[r].push(...this.netMap[i]),this.netMap[i]=this.netMap[r];for(const o of this.netMap[r])this.idToNetMap[o]=r}}for(const i of e)this.netMap[r].includes(i)||this.netMap[r].push(i),this.idToNetMap[i]=r}}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 r=this.getNetConnectedToId(e);return r?n===r||r===t||r===t:!1}areAllIdsConnected(t){const e=this.getNetConnectedToId(t[0]);for(const n of t){const r=this.getNetConnectedToId(n);if(r===void 0||r!==e)return!1}return!0}},kut=t=>{const e=[];for(const r of t)if(r.type==="source_trace")e.push([r.source_trace_id,...r.connected_source_port_ids??[],...r.connected_source_net_ids??[]].filter(Boolean));else if(r.type==="pcb_port"){const{pcb_port_id:i,source_port_id:o}=r;o&&i&&e.push([o,i])}else if(r.type==="pcb_smtpad"){const{pcb_smtpad_id:i,pcb_port_id:o}=r;o&&i&&e.push([i,o])}else if(r.type==="pcb_plated_hole"){const{pcb_plated_hole_id:i,pcb_port_id:o}=r;o&&i&&e.push([i,o])}else if(r.type==="pcb_trace"){const{pcb_trace_id:i,source_trace_id:o}=r,s=Array.isArray(r.route)?r.route.filter(a=>a&&a.route_type==="wire"):[];if(o&&i&&e.push([i,o]),Array.isArray(s)){const a=s.find(l=>l?.start_pcb_port_id)?.start_pcb_port_id,c=s.find(l=>l?.end_pcb_port_id)?.end_pcb_port_id;a&&i&&c&&e.push([a,i,c])}}else if(r.type==="pcb_via"){const{pcb_via_id:i,pcb_trace_id:o}=r;o&&i&&e.push([i,o])}else if(r.type==="source_component"&&r.internally_connected_source_port_ids)for(const i of r.internally_connected_source_port_ids)e.push(i);const n=Fjn(e);return new Bjn(n)};function jjn({primitivesWithoutInteractionMetadata:t,drawingObjectIdsWithMouseOver:e,primitiveIdsInMousedOverNet:n}){const r=[];for(const i of t){const o={...i};i?.layer==="drill"?(o.is_in_highlighted_net=!1,o.is_mouse_over=!1):e.has(i._pcb_drawing_object_id)?o.is_mouse_over=!0:i._element&&("pcb_trace_id"in i._element&&n.includes(i._element.pcb_trace_id)||"pcb_port_id"in i._element&&n.includes(i._element.pcb_port_id))?o.is_in_highlighted_net=!0:(o.is_in_highlighted_net=!1,o.is_mouse_over=!1),r.push(o)}return r}function Ujn(t,e){if(t.length<2)throw new Error("Stroke must have at least two points");const n=t.map(d=>Array.isArray(d)?{x:d[0],y:d[1]}:d),r=[],i=[];function o(d,h){const f=h.x-d.x,p=h.y-d.y,m=Math.sqrt(f*f+p*p);return{x:-p/m,y:f/m}}function s(d,h,f,p){const m=p/2,g={x:d.x+h.x*m*f,y:d.y+h.y*m*f};f>0?r.push(g):i.unshift(g)}const a=o(n[0],n[1]),c=n[0].trace_width??e;s(n[0],a,1,c),s(n[0],a,-1,c);for(let d=1;d<n.length-1;d++){const h=n[d-1],f=n[d],p=n[d+1],m=o(h,f),g=o(f,p),y=m.x+g.x,_=m.y+g.y,x=Math.sqrt(y*y+_*_),b=f.trace_width??e;if(x/2>2*(b/2))s(f,m,1,b),s(f,g,1,b),s(f,m,-1,b),s(f,g,-1,b);else{const S=1/x;s(f,{x:y*S,y:_*S},1,b),s(f,{x:y*S,y:_*S},-1,b)}}const l=o(n[n.length-2],n[n.length-1]),u=n[n.length-1].trace_width??e;return s(n[n.length-1],l,1,u),s(n[n.length-1],l,-1,u),[...r,...i]}var Hjn=(t,e)=>{const{x:n,y:r,width:i,height:o,layer:s,rect_border_radius:a}=t,c=t.corner_radius??a??0,l=[{_pcb_drawing_object_id:y4("rect"),pcb_drawing_type:"rect",x:n,y:r,w:i,h:o,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:c,...t.shape==="rotated_rect"&&t.ccw_rotation!==void 0?{ccw_rotation:t.ccw_rotation}:{}}];if(t.is_covered_with_solder_mask){const u=s==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",h={...{_pcb_drawing_object_id:y4("rect"),pcb_drawing_type:"rect",x:n,y:r,w:i,h:o,layer:u,_element:t,_parent_pcb_component:e._parent_pcb_component,_parent_source_component:e._parent_source_component,_source_port:e._source_port,roundness:c,...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}:{}};l.push(h)}return l},Yjn=(t,e)=>{const{x:n,y:r,radius:i,layer:o}=t,s=[{_pcb_drawing_object_id:y4("circle"),pcb_drawing_type:"circle",x:n,y:r,r:i,layer:o||"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=o==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",c={_pcb_drawing_object_id:y4("circle"),pcb_drawing_type:"circle",x:n,y:r,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(c)}return s},Xjn=(t,e)=>{const{layer:n,points:r}=t,i=[{_pcb_drawing_object_id:y4("polygon"),pcb_drawing_type:"polygon",points:$_e(r),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 o=n==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",s={_pcb_drawing_object_id:y4("polygon"),pcb_drawing_type:"polygon",points:$_e(r),layer:o,_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},Vjn=(t,e)=>{const{x:n,y:r,width:i,height:o,layer:s}=t,a=[{_pcb_drawing_object_id:y4("pill"),pcb_drawing_type:"pill",x:n,y:r,w:i,h:o,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 c=s==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",l={_pcb_drawing_object_id:y4("pill"),pcb_drawing_type:"pill",x:n,y:r,w:i,h:o,layer:c,_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(l)}return a},Gjn=(t,e)=>{const{x:n,y:r,width:i,height:o,layer:s,ccw_rotation:a}=t,c=[{_pcb_drawing_object_id:y4("pill"),pcb_drawing_type:"pill",x:n,y:r,w:i,h:o,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 l=s==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",u={_pcb_drawing_object_id:y4("pill"),pcb_drawing_type:"pill",x:n,y:r,w:i,h:o,layer:l,_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}:{}};c.push(u)}return c},o0=0,y4=t=>`${t}_${o0++}`,$_e=t=>(t??[]).map(e=>({x:gn.parse(e.x),y:gn.parse(e.y)})),qjn=(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,r=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?B9(e).pcb_port.get(t.pcb_port_id)?.source_port_id:void 0,o=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:r,_source_port:o};return t.shape==="rect"||t.shape==="rotated_rect"?Hjn(t,s):t.shape==="circle"?Yjn(t,s):t.shape==="polygon"?Xjn(t,s):t.shape==="pill"?Vjn(t,s):t.shape==="rotated_pill"?Gjn(t,s):[]}case"pcb_trace":{const s=[];if(t.route_thickness_mode==="interpolated"){const l=t.route.map(h=>({x:h.x,y:h.y,trace_width:h.route_type==="wire"?h.width:.5})),u=Ujn(l,.5),d=t.route[0].layer;return s.push({_pcb_drawing_object_id:`polygon_${o0++}`,_element:t,pcb_drawing_type:"polygon",points:u,layer:d}),t.route.forEach(h=>{h.route_type==="via"&&s.push({_pcb_drawing_object_id:`circle_${o0++}`,_element:t,pcb_drawing_type:"circle",x:h.x,y:h.y,r:h.outer_diameter/2,layer:h.from_layer})}),s}let a=null,c=null;for(const l of t.route)l.route_type==="wire"&&(a!==null&&c!==null&&s.push({_pcb_drawing_object_id:`line_${o0++}`,_element:t,pcb_drawing_type:"line",x1:a,y1:c,x2:l.x,y2:l.y,width:l.width,squareCap:!1,layer:l.layer}),a=l.x,c=l.y);return s}case"pcb_via":{const{x:s,y:a,outer_diameter:c,hole_diameter:l}=t,u=t.from_layer,d=t.to_layer,h=t.layers,f=[];u&&d?f.push(u,d):h&&Array.isArray(h)?f.push(...h):f.push("top","bottom");const p=[];for(const m of f)p.push({_pcb_drawing_object_id:`circle_${o0++}`,pcb_drawing_type:"circle",x:s,y:a,r:c/2,layer:m,_element:t,_parent_pcb_component:n,_parent_source_component:r});return p.push({_pcb_drawing_object_id:`circle_${o0++}`,pcb_drawing_type:"circle",x:s,y:a,r:l/2,layer:"drill",_element:t}),p}case"pcb_plated_hole":if(t.shape==="circle"){const{x:s,y:a,hole_diameter:c,outer_diameter:l}=t;return[{_pcb_drawing_object_id:`circle_${o0++}`,pcb_drawing_type:"circle",x:s,y:a,r:l/2,layer:"top",_element:t,_parent_pcb_component:n,_parent_source_component:r,_source_port:o},{_pcb_drawing_object_id:`circle_${o0++}`,pcb_drawing_type:"circle",x:s,y:a,r:c/2,layer:"drill",_element:t}]}else if(t.shape==="oval"){const{x:s,y:a,outer_height:c,outer_width:l,hole_height:u,hole_width:d}=t;return[{_pcb_drawing_object_id:`oval_${o0++}`,pcb_drawing_type:"oval",x:s,y:a,rX:l/2,rY:c/2,layer:"top",_element:t,_parent_pcb_component:n,_parent_source_component:r,_source_port:o},{_pcb_drawing_object_id:`oval_${o0++}`,_element:t,pcb_drawing_type:"oval",x:s,y:a,rX:d/2,rY:u/2,layer:"drill"}]}else if(t.shape==="pill"){const{x:s,y:a,outer_height:c,outer_width:l,hole_height:u,hole_width:d}=t;return[{_pcb_drawing_object_id:`pill_${o0++}`,pcb_drawing_type:"pill",x:s,y:a,w:l,h:c,layer:"top",_element:t,_parent_pcb_component:n,_parent_source_component:r,_source_port:o,ccw_rotation:t.ccw_rotation},{_pcb_drawing_object_id:`pill_${o0++}`,_element:t,pcb_drawing_type:"pill",x:s,y:a,w:d,h:u,layer:"drill",ccw_rotation:t.ccw_rotation}]}else if(t.shape==="circular_hole_with_rect_pad"){const{x:s,y:a,hole_diameter:c,rect_pad_width:l,rect_pad_height:u,rect_border_radius:d,hole_offset_x:h,hole_offset_y:f}=t,p=gn.parse(h??0),m=gn.parse(f??0);return[{_pcb_drawing_object_id:`rect_${o0++}`,pcb_drawing_type:"rect",x:s,y:a,w:l,h:u,layer:"top",_element:t,_parent_pcb_component:n,_parent_source_component:r,_source_port:o,roundness:d},{_pcb_drawing_object_id:`rect_${o0++}`,pcb_drawing_type:"rect",x:s,y:a,w:l,h:u,layer:"bottom",_element:t,_parent_pcb_component:n,_parent_source_component:r,_source_port:o,roundness:d,is_hoverable:!1},{_pcb_drawing_object_id:`circle_${o0++}`,_element:t,pcb_drawing_type:"circle",x:s+p,y:a+m,r:c/2,layer:"drill",is_hoverable:!1}]}else if(t.shape==="pill_hole_with_rect_pad"){const{x:s,y:a,hole_width:c,hole_height:l,rect_pad_width:u,rect_pad_height:d,rect_border_radius:h}=t;return[{_pcb_drawing_object_id:`rect_${o0++}`,pcb_drawing_type:"rect",x:s,y:a,w:u,h:d,layer:"top",_element:t,_parent_pcb_component:n,_parent_source_component:r,_source_port:o,roundness:h},{_pcb_drawing_object_id:`rect_${o0++}`,pcb_drawing_type:"rect",x:s,y:a,w:u,h:d,layer:"bottom",_element:t,_parent_pcb_component:n,_parent_source_component:r,_source_port:o,roundness:h,is_hoverable:!1},{_pcb_drawing_object_id:`pill_${o0++}`,_element:t,pcb_drawing_type:"pill",x:s,y:a,w:c,h:l,layer:"drill",is_hoverable:!1}]}else if(t.shape==="rotated_pill_hole_with_rect_pad"){const{x:s,y:a,hole_width:c,hole_height:l,hole_ccw_rotation:u,rect_pad_width:d,rect_pad_height:h,rect_ccw_rotation:f,rect_border_radius:p}=t;return[{_pcb_drawing_object_id:`rect_${o0++}`,pcb_drawing_type:"rect",x:s,y:a,w:d,h,layer:"top",_element:t,_parent_pcb_component:n,_parent_source_component:r,_source_port:o,ccw_rotation:f,roundness:p},{_pcb_drawing_object_id:`rect_${o0++}`,pcb_drawing_type:"rect",x:s,y:a,w:d,h,layer:"bottom",_element:t,_parent_pcb_component:n,_parent_source_component:r,_source_port:o,ccw_rotation:f,roundness:p,is_hoverable:!1},{_pcb_drawing_object_id:`pill_${o0++}`,_element:t,pcb_drawing_type:"pill",x:s,y:a,w:c,h:l,layer:"drill",ccw_rotation:u,is_hoverable:!1}]}else if(t.shape==="hole_with_polygon_pad"){const{x:s,y:a,pad_outline:c,hole_shape:l,hole_diameter:u,hole_width:d,hole_height:h,layers:f,hole_offset_x:p,hole_offset_y:m}=t,g=gn.parse(p??0),y=gn.parse(m??0),_=c,x=[];if(_&&Array.isArray(_)){const S=$_e(_).map(T=>({x:T.x+s,y:T.y+a}));for(const T of f||["top","bottom"])x.push({_pcb_drawing_object_id:`polygon_${o0++}`,pcb_drawing_type:"polygon",points:S,layer:T,_element:t,_parent_pcb_component:n,_parent_source_component:r,_source_port:o})}const b={x:s+g,y:a+y},w=[];return l==="circle"?w.push({_pcb_drawing_object_id:`circle_${o0++}`,pcb_drawing_type:"circle",x:b.x,y:b.y,r:(u??0)/2,layer:"drill",_element:t,_parent_pcb_component:n,_parent_source_component:r}):l==="oval"?w.push({_pcb_drawing_object_id:`oval_${o0++}`,pcb_drawing_type:"oval",x:b.x,y:b.y,rX:(d??0)/2,rY:(h??0)/2,layer:"drill",_element:t,_parent_pcb_component:n,_parent_source_component:r}):(l==="pill"||l==="rotated_pill")&&w.push({_pcb_drawing_object_id:`pill_${o0++}`,pcb_drawing_type:"pill",x:b.x,y:b.y,w:d??0,h:h??0,layer:"drill",_element:t,_parent_pcb_component:n,_parent_source_component:r,ccw_rotation:t.ccw_rotation}),[...x,...w]}else return[]}return[]},hi={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)"}},I_=(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)},Wl={elementOverlay:40,dimensionOverlay:40,editTraceHintOverlay:40,errorOverlay:40,pcbGroupOverlay:35,ratsNestOverlay:30,toolbarOverlay:70,warnings:30,topLayer:20,clickToInteractOverlay:100},uG={red:"red",black:"black",green:"green",board:"rgb(255, 255, 255)",other:"#eee",top:hi.board.copper.f,inner1:hi.board.copper.in1,inner2:hi.board.copper.in2,inner3:hi.board.copper.in3,inner4:hi.board.copper.in4,inner5:hi.board.copper.in5,inner6:hi.board.copper.in6,inner7:hi.board.copper.in7,inner8:hi.board.copper.in8,bottom:hi.board.copper.b,drill:hi.board.anchor,keepout:hi.board.background,tkeepout:hi.board.b_crtyd,tplace:hi.board.b_silks,top_courtyard:hi.board.f_crtyd,bottom_courtyard:hi.board.b_crtyd,top_silkscreen:hi.board.f_silks,bottom_silkscreen:hi.board.b_silks,top_fabrication:hi.board.f_fab,bottom_fabrication:hi.board.b_fab,soldermask_top:hi.board.soldermask.top,soldermask_bottom:hi.board.soldermask.bottom,soldermask_with_copper_top:hi.board.soldermaskWithCopper.top,soldermask_with_copper_bottom:hi.board.soldermaskWithCopper.bottom,bottom_notes:hi.board.user_2,top_notes:hi.board.user_2,...hi.board},Wjn=["board","inner6","inner5","inner4","inner3","inner2","inner1","bottom","soldermask_bottom","bottom_silkscreen","top","soldermask_top","bottom_courtyard","bottom_fabrication","top_courtyard","top_fabrication","edge_cuts","top_silkscreen"],Zjn=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=el(),this.transform.d*=-1,this.transform=di(this.transform,_i(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,r,i,o=45){const s=this.getLayerCtx(),[a,c]=mt(this.transform,[t,e]),[l,u]=mt(this.transform,[t+n,e+r]),d=I_(this.transform,i);s.lineWidth=1,s.strokeStyle=this.aperture.color;const h=f=>{const p=Math.sin(f),m=Math.cos(f),g=Math.sqrt((l-a)**2+(u-c)**2);for(let y=-g;y<=g;y+=d)s.beginPath(),s.moveTo(a+y*m-g*p,c+y*p+g*m),s.lineTo(a+y*m+g*p,c+y*p-g*m),s.stroke()};h(o*Math.PI/180),h((o+90)*Math.PI/180)}rect({x:t,y:e,w:n,h:r,mesh_fill:i,is_filled:o=!0,has_stroke:s,is_stroke_dashed:a,stroke_width:c,roundness:l}){const[u,d]=mt(this.transform,[t-n/2,e-r/2]),[h,f]=mt(this.transform,[t+n/2,e+r/2]);this.applyAperture();const p=this.getLayerCtx(),m=l?I_(this.transform,l):0,g=s===void 0?o===!1:s;if(i)p.save(),p.beginPath(),m>0&&p.roundRect?p.roundRect(u,d,h-u,f-d,m):p.rect(u,d,h-u,f-d),p.clip(),this.drawMeshPattern(t-n/2,e-r/2,n,r,.15),p.restore(),m>0&&p.roundRect?(p.beginPath(),p.roundRect(u,d,h-u,f-d,m),p.stroke()):p.strokeRect(u,d,h-u,f-d);else if(o!==!1&&(m>0&&p.roundRect?(p.beginPath(),p.roundRect(u,d,h-u,f-d,m),p.fill()):p.fillRect(u,d,h-u,f-d)),g){const y=p.lineWidth;if(c!==void 0&&(p.lineWidth=I_(this.transform,c)),a){let _=[];const x=Math.abs(this.transform.a);if(x>0){const w=.1*x,S=w*1.3;w>.5&&(_=[w,S])}p.setLineDash(_)}m>0&&p.roundRect?(p.beginPath(),p.roundRect(u,d,h-u,f-d,m),p.stroke()):p.strokeRect(u,d,h-u,f-d),a&&p.setLineDash([]),c!==void 0&&(p.lineWidth=y)}}rotatedRect(t,e,n,r,i,o,s){const a=this.getLayerCtx();this.applyAperture();const[c,l]=mt(this.transform,[t-n/2,e-r/2]),[u,d]=mt(this.transform,[t+n/2,e+r/2]),h=o?I_(this.transform,o):0;a.save();const[f,p]=mt(this.transform,[t,e]);a.translate(f,p);const m=360-i;i&&a.rotate(m*Math.PI/180),a.translate(-f,-p),s?(a.beginPath(),h>0&&a.roundRect?a.roundRect(c,l,u-c,d-l,h):a.rect(c,l,u-c,d-l),a.clip(),this.drawMeshPattern(t-n/2,e-r/2,n,r,.15),h>0&&a.roundRect?(a.beginPath(),a.roundRect(c,l,u-c,d-l,h),a.stroke()):a.strokeRect(c,l,u-c,d-l)):h>0&&a.roundRect?(a.beginPath(),a.roundRect(c,l,u-c,d-l,h),a.fill()):a.fillRect(c,l,u-c,d-l),a.restore()}rotatedPill(t,e,n,r,i){const o=this.getLayerCtx();this.applyAperture(),o.save();const[s,a]=mt(this.transform,[t,e]);o.translate(s,a);const c=360-i;i&&o.rotate(c*Math.PI/180),o.translate(-s,-a),this.pill(t,e,n,r),o.restore()}circle(t,e,n,r,i=!0){const o=I_(this.transform,n),[s,a]=mt(this.transform,[t,e]);this.applyAperture();const c=this.getLayerCtx();r?(c.save(),c.beginPath(),c.arc(s,a,o,0,2*Math.PI),c.clip(),this.drawMeshPattern(t-n,e-n,n*2,n*2,.15),c.restore(),c.beginPath(),c.arc(s,a,o,0,2*Math.PI),c.stroke()):(c.beginPath(),c.arc(s,a,o,0,2*Math.PI),c.fill())}oval(t,e,n,r){const i=I_(this.transform,n),o=I_(this.transform,r),[s,a]=mt(this.transform,[t,e]);this.applyAperture();const c=this.getLayerCtx();c.beginPath(),c.ellipse(s,a,i,o,0,0,2*Math.PI),c.fill(),c.closePath()}pill(t,e,n,r){const[i,o]=mt(this.transform,[t-n/2,e+r/2]),s=I_(this.transform,n),a=I_(this.transform,r),c=Math.min(s,a)/2;this.applyAperture();const l=this.getLayerCtx();l.beginPath(),l.arc(i+c,o+c,c,Math.PI,Math.PI*1.5),l.arc(i+s-c,o+c,c,Math.PI*1.5,0),l.arc(i+s-c,o+a-c,c,0,Math.PI*.5),l.arc(i+c,o+a-c,c,Math.PI*.5,Math.PI),l.fill(),l.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 r=I_(this.transform,this.aperture.size);r>0&&(e.lineWidth=r,e.stroke())}debugText(t,e,n){const[r,i]=mt(this.transform,[e,n]);this.applyAperture();const o=this.getLayerCtx();o.font="10px sans-serif",o.fillText(t,r,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,n=e==="top"?"soldermask_top":e==="bottom"?"soldermask_bottom":void 0,r=e==="top"?"top_silkscreen":e==="bottom"?"bottom_silkscreen":void 0,i=e==="top"?"top_notes":e==="bottom"?"bottom_notes":void 0,o=e==="top"?"top_fabrication":e==="bottom"?"bottom_fabrication":void 0,s=e==="top"?"top_courtyard":e==="bottom"?"bottom_courtyard":void 0,a=new Set([e,"drill","edge_cuts","other","board",...n?[n]:[],...r?[r]:[],...i?[i]:[],...o?[o]:[],...s?[s]:[]]),c=[e,"edge_cuts",...n?[n]:[],...r?[r]:[],...i?[i]:[],...o?[o]:[],...s?[s]:[]],l=[...Wjn.filter(u=>!c.includes(u)),...e==="drill"?[]:[e],...n?[n]:[],"edge_cuts",...r?[r]:[],...i?[i]:[],...o?[o]:[],...s?[s]:[],"drill"];l.forEach((u,d)=>{const h=t[u];h&&(h.style.zIndex=`${Wl.topLayer-(l.length-d)}`,h.style.opacity=a.has(u)?"1":"0.5")})}applyAperture(){const{transform:t,aperture:e}=this;let{size:n,mode:r,color:i,fontSize:o,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=I_(t,n),a.lineCap="round",r==="add"){a.globalCompositeOperation="source-over";let c=uG[i.toLowerCase()];if(!c)try{c=uc(i).rgb().toString()}catch{console.warn(`Invalid color format: '${i}'`),c="white"}a.fillStyle=c,a.strokeStyle=c}else a.globalCompositeOperation="destination-out",a.fillStyle="rgba(0,0,0,1)",a.strokeStyle="rgba(0,0,0,1)";a.font=`${I_(Bx(t),o)}px sans-serif`}moveTo(t,e){this.lastPoint={x:t,y:e}}lineTo(t,e){const[n,r]=mt(this.transform,[t,e]),{size:i,shape:o,mode:s}=this.aperture,a=I_(this.transform,i),{lastPoint:c}=this,l=mt(this.transform,c);this.applyAperture();const u=this.getLayerCtx();o==="square"&&u.fillRect(l.x-a/2,l.y-a/2,a,a),u.beginPath(),u.moveTo(l.x,l.y),u.lineTo(n,r),u.stroke(),u.closePath(),o==="square"&&u.fillRect(n-a/2,r-a/2,a,a),this.lastPoint={x:t,y:e}}polygonWithArcs(t){const e=this.getLayerCtx(),n=r=>{if(r.vertices.length===0)return;const i=r.vertices[0],o=mt(this.transform,[i.x,i.y]);e.moveTo(o[0],o[1]);for(let s=0;s<r.vertices.length;s++){const a=r.vertices[s],c=r.vertices[(s+1)%r.vertices.length];if(a.bulge&&a.bulge!==0){const l=a.bulge,u=c.x-a.x,d=c.y-a.y,h=Math.sqrt(u*u+d*d);if(h<1e-9){const O=mt(this.transform,[c.x,c.y]);e.lineTo(O[0],O[1]);continue}const f=4*Math.atan(l),p=Math.abs(h/(2*Math.sin(f/2))),m=(a.x+c.x)/2,g=(a.y+c.y)/2,y=u/h,x=-(d/h),b=y,w=Math.sqrt(Math.max(0,p*p-(h/2)**2)),S=m+w*x*Math.sign(l),T=g+w*b*Math.sign(l),C=Math.atan2(a.y-T,a.x-S);let A=Math.atan2(c.y-T,c.x-S);l>0&&A<C?A+=2*Math.PI:l<0&&A>C&&(A-=2*Math.PI);const R=mt(this.transform,[S,T]),L=I_(this.transform,p);e.arc(R[0],R[1],L,-C,-A,l>0)}else{const l=mt(this.transform,[c.x,c.y]);e.lineTo(l[0],l[1])}}e.closePath()};if(e.beginPath(),n(t.outer_ring),t.inner_rings)for(const r of t.inner_rings)n(r);e.fill("evenodd")}};function Kjn(t){return t.type==="pcb_copper_pour"}function dG({canvas:t,elements:e,layers:n,realToCanvasMat:r}){const i=e.filter(Kjn);if(i.length===0)return;const o=new Eh(t);o.realToCanvasMat=r,o.drawElements(i,{layers:n})}var Qjn={...cg,silkscreen:{top:hi.board.f_fab,bottom:hi.board.b_fab}};function Jjn(t){return t.type.includes("pcb_fabrication_note")}function Out({canvas:t,elements:e,layers:n,realToCanvasMat:r}){const i=new Eh(t);i.configure({colorOverrides:Qjn}),i.realToCanvasMat=r;const o=e.filter(Jjn);i.drawElements(o,{layers:n})}function eUn(t){return t.type==="pcb_hole"}function tUn({canvas:t,elements:e,layers:n,realToCanvasMat:r,drawSoldermask:i}){const o=new Eh(t);o.realToCanvasMat=r;const s=e.filter(eUn);o.drawElements(s,{layers:n,drawSoldermask:i})}function nUn(t){return t.type==="pcb_board"}function rUn({canvas:t,elements:e,layers:n,realToCanvasMat:r,drawSoldermask:i}){const o=new Eh(t);o.realToCanvasMat=r;const s=e.filter(nUn);for(const a of s)o.drawElements([a],{layers:n,drawSoldermask:!1,drawBoardMaterial:i??!1,minBoardOutlineStrokePx:2})}function iUn(t){return t.type==="pcb_copper_text"}function oUn({canvas:t,elements:e,layers:n,realToCanvasMat:r}){const i=e.filter(iUn);if(i.length===0)return;const o=new Eh(t);o.realToCanvasMat=r,o.drawElements(i,{layers:n})}function sUn(t){return t.type==="pcb_cutout"}function aUn({canvas:t,elements:e,layers:n,realToCanvasMat:r}){const i=new Eh(t);i.realToCanvasMat=r;const o=e.filter(sUn);i.drawElements(o,{layers:n})}function cUn(t){return t.type==="pcb_keepout"}function lUn({canvas:t,elements:e,layers:n,realToCanvasMat:r}){const i=e.filter(cUn);if(i.length===0)return;const o=new Eh(t);o.realToCanvasMat=r,o.drawElements(i,{layers:[]})}function uUn(t){return t.type.startsWith("pcb_note_")}function Lut({canvas:t,elements:e,layers:n,realToCanvasMat:r}){const i=new Eh(t);i.realToCanvasMat=r;const o=e.filter(uUn);i.drawElements(o,{layers:n})}function dUn(t){return t.type==="pcb_panel"}function hUn({canvas:t,elements:e,layers:n,realToCanvasMat:r,drawSoldermask:i}){const o=new Eh(t);o.realToCanvasMat=r;const s=e.filter(dUn);for(const a of s)o.drawElements([a],{layers:n})}var pUn={...cg,copper:{...cg.copper,top:uc(hi.board.pad_front).lighten(.5).toString(),bottom:uc(hi.board.pad_back).lighten(.5).toString(),inner1:uc(hi.board.copper.in1).lighten(.5).toString(),inner2:uc(hi.board.copper.in2).lighten(.5).toString(),inner3:uc(hi.board.copper.in3).lighten(.5).toString(),inner4:uc(hi.board.copper.in4).lighten(.5).toString(),inner5:uc(hi.board.copper.in5).lighten(.5).toString(),inner6:uc(hi.board.copper.in6).lighten(.5).toString()}};function fUn(t){return t.type==="pcb_smtpad"}function mUn({canvas:t,elements:e,layers:n,realToCanvasMat:r,primitives:i,drawSoldermask:o}){const s=e.filter(fUn).filter(u=>{const d=u.layer;return n.some(h=>h==="top_copper"&&d==="top"||h==="bottom_copper"&&d==="bottom"||h==="inner1_copper"&&d==="inner1"||h==="inner2_copper"&&d==="inner2"||h==="inner3_copper"&&d==="inner3"||h==="inner4_copper"&&d==="inner4"||h==="inner5_copper"&&d==="inner5"||h==="inner6_copper"&&d==="inner6")});if(s.length===0)return;const a=new Set;if(i)for(const u of i)(u.is_mouse_over||u.is_in_highlighted_net)&&u._element?.type==="pcb_smtpad"&&a.add(u._element.pcb_smtpad_id);const c=s.filter(u=>a.has(u.pcb_smtpad_id)),l=s.filter(u=>!a.has(u.pcb_smtpad_id));if(l.length>0){const u=new Eh(t);u.realToCanvasMat=r,u.drawElements(l,{layers:n,drawSoldermask:o})}if(c.length>0){const u=new Eh(t);u.configure({colorOverrides:pUn}),u.realToCanvasMat=r,u.drawElements(c,{layers:n,drawSoldermask:o})}}var yUn={...cg,copper:{...cg.copper,top:uc(hi.board.pad_front).lighten(.5).toString(),bottom:uc(hi.board.pad_back).lighten(.5).toString(),inner1:uc(hi.board.copper.in1).lighten(.5).toString(),inner2:uc(hi.board.copper.in2).lighten(.5).toString(),inner3:uc(hi.board.copper.in3).lighten(.5).toString(),inner4:uc(hi.board.copper.in4).lighten(.5).toString(),inner5:uc(hi.board.copper.in5).lighten(.5).toString(),inner6:uc(hi.board.copper.in6).lighten(.5).toString()}};function gUn(t){return t.type==="pcb_trace"}var _Un=t=>t.map(e=>e.endsWith("_copper")?e.replace("_copper",""):e),xUn=(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}};function bUn({canvas:t,elements:e,layers:n,realToCanvasMat:r,primitives:i}){const o=new Set(_Un(n)),s=e.filter(gUn).map(u=>xUn(u,o)).filter(u=>u!==null);if(s.length===0)return;const a=new Set;if(i)for(const u of i)(u.is_mouse_over||u.is_in_highlighted_net)&&u._element?.type==="pcb_trace"&&a.add(u._element.pcb_trace_id);const c=[],l=[];for(const u of s)a.has(u.pcb_trace_id)?c.push(u):l.push(u);if(l.length>0){const u=new Eh(t);u.realToCanvasMat=r,u.drawElements(l,{layers:n})}if(c.length>0){const u=new Eh(t);u.configure({colorOverrides:yUn}),u.realToCanvasMat=r,u.drawElements(c,{layers:n})}}var vUn={...cg,copper:{...cg.copper,top:uc(hi.board.pad_front).lighten(.5).toString(),bottom:uc(hi.board.pad_back).lighten(.5).toString()}};function wUn(t){return t.type==="pcb_plated_hole"}function Dut({canvas:t,elements:e,layers:n,realToCanvasMat:r,primitives:i,drawSoldermask:o}){const s=e.filter(wUn);if(s.length===0)return;const a=new Set;if(i)for(const u of i)(u.is_mouse_over||u.is_in_highlighted_net)&&u._element?.type==="pcb_plated_hole"&&a.add(u._element.pcb_plated_hole_id);const c=s.filter(u=>a.has(u.pcb_plated_hole_id)),l=s.filter(u=>!a.has(u.pcb_plated_hole_id));if(l.length>0){const u=new Eh(t);u.realToCanvasMat=r,u.drawElements(l,{layers:n,drawSoldermask:o})}if(c.length>0){const u=new Eh(t);u.configure({colorOverrides:vUn}),u.realToCanvasMat=r,u.drawElements(c,{layers:n,drawSoldermask:o})}}function zut(t){const{lines:e,anchorPoint:n,ccwRotation:r}=t;if(!r)return e;const i=r*Math.PI/180,o=Wf(i),s=di(_i(n.x,n.y),o,_i(-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 SUn=.6,$ut=.2,Fut=t=>{const e=t.size*.7,n=e*SUn,r=e*$ut,i=e*$ut,o=t.text.split(/\r?\n/),s=t.text.length>0&&e>0,a=s?o.length:0,c=s?o.map(d=>d.length===0?0:d.length*n+(d.length-1)*r):[],l=c.length>0?Math.max(...c):0,u=a>0?a*e+(a-1)*i:0;return{text_lines:o,line_count:a,line_widths:c,target_height:e,target_width_char:n,space_between_chars:r,space_between_lines:i,width:l,height:u}},But=t=>{const e=Fut(t);return{width:e.width,height:e.height,lineHeight:e.target_height,lineSpacing:e.space_between_lines,lineCount:e.line_count}},jut=t=>{const{text_lines:e,line_count:n,line_widths:r,target_height:i,target_width_char:o,space_between_chars:s,space_between_lines:a,width:c}=Fut(t);if(i<=0||n===0)return[];const l=i/12,u=[];for(let d=0;d<n;d++){const h=-d*(i+a),f=r[d],p=(c-f)/2;let m=t.x+p;for(let g=0;g<e[d].length;g++){const y=e[d][g],_=Yw[y]??Yw[y.toUpperCase()];if(!_){m+=o+s;continue}for(const{x1:x,y1:b,x2:w,y2:S}of _)u.push({_pcb_drawing_object_id:y4("line"),pcb_drawing_type:"line",x1:m+o*x,y1:t.y+h+i*b,x2:m+o*w,y2:t.y+h+i*S,width:l,layer:t.layer,unit:t.unit,color:t.color});m+=o+s}}return u};function ev(t){const n=t.color??uG[t.layer];let r=uc(n);return t._element?.type==="pcb_copper_pour"&&(r=r.alpha(.7)),t.is_mouse_over||t.is_in_highlighted_net?r.lighten(.5).rgb().toString():r.rgb().toString()}var Uut=(t,e)=>{t.equip({size:e.zoomIndependent?e.width/t.transform.a:e.width,shape:e.squareCap?"square":"circle",color:ev(e),layer:e.layer}),t.moveTo(e.x1,e.y1),t.lineTo(e.x2,e.y2)},MUn=(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}}},Hut=t=>t.layer==="bottom_silkscreen"||t.layer==="bottom"?t.is_mirrored!==!1:t.is_mirrored===!0,TUn=(t,e)=>{t.equip({fontSize:e.size,color:ev(e),layer:e.layer});const{width:n,height:r}=But(e),i=MUn(n,r,e.align);e.x??=0,e.y??=0;const o={x:e.x,y:e.y};let s=jut({...e,x:e.x+i.x,y:e.y+i.y});if(Hut(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:o,ccwRotation:e.ccw_rotation};s=zut(a)}for(const a of s)Uut(t,a)},EUn=(t,e)=>{const{width:n,height:r,lineHeight:i}=But(e);e.x??=0,e.y??=0;const o=e.knockout_padding??{left:e.size*.5,right:e.size*.5,top:e.size*.3,bottom:e.size*.3},s=n+o.left+o.right,a=r+o.top+o.bottom,c=n/2,l=i-r/2,u=e.x-c,d=e.y-l,h={x:e.x,y:e.y},f={_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?Xut(t,f):Yut(t,f);let p=jut({...e,x:u,y:d});if(Hut(e)&&(p=p.map(m=>({...m,x1:2*e.x-m.x1,x2:2*e.x-m.x2}))),e.ccw_rotation){const m={lines:p,anchorPoint:h,ccwRotation:e.ccw_rotation};p=zut(m)}for(const m of p)t.equip({size:m.width,shape:"circle",color:"black",layer:e.layer,mode:"subtract"}),t.moveTo(m.x1,m.y1),t.lineTo(m.x2,m.y2);t.equip({mode:"add"})},Yut=(t,e)=>{t.equip({color:ev(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})},Xut=(t,e)=>{t.equip({color:ev(e),layer:e.layer}),t.rotatedRect(e.x,e.y,e.w,e.h,e.ccw_rotation,e.roundness,e.mesh_fill)},CUn=(t,e)=>{t.equip({color:ev(e),layer:e.layer}),t.rotatedPill(e.x,e.y,e.w,e.h,e.ccw_rotation)},PUn=(t,e)=>{t.equip({color:ev(e),layer:e.layer}),t.circle(e.x,e.y,e.r,e.mesh_fill)},AUn=(t,e)=>{t.equip({color:ev(e),layer:e.layer}),t.oval(e.x,e.y,e.rX,e.rY)},RUn=(t,e)=>{t.equip({color:ev(e),layer:e.layer}),t.pill(e.x,e.y,e.w,e.h)},IUn=(t,e)=>{t.equip({color:ev(e),layer:e.layer}),t.polygon(e.points)},NUn=(t,e)=>{t.equip({color:ev(e),layer:e.layer}),t.polygonWithArcs(e.brep_shape)},kUn=(t,e)=>{switch(e.pcb_drawing_type){case"line":return Uut(t,e);case"text":return e.is_knockout?EUn(t,e):TUn(t,e);case"rect":return e.ccw_rotation?Xut(t,e):Yut(t,e);case"circle":return PUn(t,e);case"oval":return AUn(t,e);case"pill":return e.ccw_rotation?CUn(t,e):RUn(t,e);case"polygon":return IUn(t,e);case"polygon_with_arcs":return NUn(t,e)}},OUn=(t,e)=>{for(const n of e)kUn(t,n)},LUn={...cg,copper:{...cg.copper,top:uc(hi.board.pad_front).lighten(.5).toString(),bottom:uc(hi.board.pad_back).lighten(.5).toString(),inner1:uc(hi.board.copper.in1).lighten(.5).toString(),inner2:uc(hi.board.copper.in2).lighten(.5).toString(),inner3:uc(hi.board.copper.in3).lighten(.5).toString(),inner4:uc(hi.board.copper.in4).lighten(.5).toString(),inner5:uc(hi.board.copper.in5).lighten(.5).toString(),inner6:uc(hi.board.copper.in6).lighten(.5).toString()},soldermask:{...cg.soldermask,top:uc(hi.board.soldermask.top).lighten(.35).toString(),bottom:uc(hi.board.soldermask.bottom).lighten(.35).toString()}};function Vut({canvas:t,elements:e,layers:n,realToCanvasMat:r,drawSoldermaskTop:i,drawSoldermaskBottom:o,primitives:s}){const a=new Eh(t);a.realToCanvasMat=r;const c=e.filter(h=>h.type==="pcb_board");if(c.length<=1)a.drawElements(e,{layers:n,drawSoldermask:!0,drawSoldermaskTop:i,drawSoldermaskBottom:o,drawBoardMaterial:!1});else{const h=e.filter(f=>f.type!=="pcb_board");for(const f of c)a.drawElements([f,...h],{layers:n,drawSoldermask:!0,drawSoldermaskTop:i,drawSoldermaskBottom:o,drawBoardMaterial:!1})}if(!s)return;const l=new Set;for(const h of s){if(!(h.is_mouse_over||h.is_in_highlighted_net))continue;const f=h._element;f?.type==="pcb_smtpad"?l.add(f.pcb_smtpad_id):f?.type==="pcb_plated_hole"?l.add(f.pcb_plated_hole_id):f?.type==="pcb_via"&&l.add(f.pcb_via_id)}if(l.size===0)return;const u=e.filter(h=>h.type==="pcb_smtpad"?l.has(h.pcb_smtpad_id):h.type==="pcb_plated_hole"?l.has(h.pcb_plated_hole_id):h.type==="pcb_via"?l.has(h.pcb_via_id):!1);if(u.length===0)return;const d=new Eh(t);d.configure({colorOverrides:LUn}),d.realToCanvasMat=r,d.drawElements(u,{layers:n,drawSoldermask:!0,drawSoldermaskTop:i,drawSoldermaskBottom:o,drawBoardMaterial:!1})}var DUn={...cg,silkscreen:{top:hi.board.f_silks,bottom:hi.board.b_silks}};function zUn(t){return t.type.includes("pcb_silkscreen")}function Gut({canvas:t,elements:e,layers:n,realToCanvasMat:r}){const i=new Eh(t);i.configure({colorOverrides:DUn}),i.realToCanvasMat=r;const o=e.filter(zUn);i.drawElements(o,{layers:n})}var $Un={...cg,copper:{...cg.copper,top:uc(hi.board.pad_front).lighten(.5).toString(),bottom:uc(hi.board.pad_back).lighten(.5).toString()}};function FUn(t){return t.type==="pcb_via"}function qut({canvas:t,elements:e,layers:n,realToCanvasMat:r,primitives:i,drawSoldermask:o}){const s=e.filter(FUn).filter(u=>n.some(d=>d.includes("copper")));if(s.length===0)return;const a=new Set;if(i)for(const u of i)(u.is_mouse_over||u.is_in_highlighted_net)&&u._element?.type==="pcb_via"&&a.add(u._element.pcb_via_id);const c=s.filter(u=>a.has(u.pcb_via_id)),l=s.filter(u=>!a.has(u.pcb_via_id));if(l.length>0){const u=new Eh(t);u.realToCanvasMat=r,u.drawElements(l,{layers:n,drawSoldermask:o})}if(c.length>0){const u=new Eh(t);u.configure({colorOverrides:$Un}),u.realToCanvasMat=r,u.drawElements(c,{layers:n,drawSoldermask:o})}}var BUn={...cg,courtyard:{top:hi.board.f_crtyd,bottom:hi.board.b_crtyd}};function jUn(t){return t.type==="pcb_courtyard_circle"||t.type==="pcb_courtyard_rect"||t.type==="pcb_courtyard_outline"}function Wut({canvas:t,elements:e,layers:n,realToCanvasMat:r}){const i=new Eh(t);i.configure({colorOverrides:BUn}),i.realToCanvasMat=r;const o=e.filter(jUn);i.drawElements(o,{layers:n})}var UUn=["board","bottom","soldermask_bottom","bottom_silkscreen","top","soldermask_top","soldermask_with_copper_bottom","soldermask_with_copper_top","top_fabrication","bottom_fabrication","inner1","inner2","inner3","inner4","inner5","inner6","drill","edge_cuts","bottom_notes","top_notes","top_silkscreen","top_courtyard","bottom_courtyard","other"],HUn=({primitives:t,elements:e,transform:n,grid:r,width:i=500,height:o=500})=>{const s=te.useRef({}),a=E0(h=>h.selected_layer),c=E0(h=>h.is_showing_solder_mask),l=E0(h=>h.is_showing_fabrication_notes),u=E0(h=>h.is_showing_courtyards),d=E0(h=>h.is_showing_silkscreen);return te.useEffect(()=>{if(!s.current||Object.keys(s.current).length===0)return;const h=Object.fromEntries(Object.entries(s.current).filter(([m,g])=>!!g));if(Object.keys(h).length===0)return;const f=new Zjn(h);n&&(f.transform=n),f.clear(),f.foregroundLayer=a;const p=t.filter(m=>c||!m.layer?.includes("soldermask")).filter(m=>d||!m.layer?.includes("silkscreen")).filter(m=>l||!m.layer?.includes("fabrication")).filter(m=>m.layer!=="board").filter(m=>m._element?.type!=="pcb_smtpad").filter(m=>m._element?.type!=="pcb_plated_hole").filter(m=>m._element?.type!=="pcb_via").filter(m=>m._element?.type!=="pcb_trace").filter(m=>m._element?.type!=="pcb_copper_text");if(OUn(f,p),n){const m=s.current.top,g=s.current.bottom,y=s.current.inner1,_=s.current.inner2,x=s.current.inner3,b=s.current.inner4,w=s.current.inner5,S=s.current.inner6,T=[{canvas:m,copperLayer:"top_copper"},{canvas:g,copperLayer:"bottom_copper"},{canvas:y,copperLayer:"inner1_copper"},{canvas:_,copperLayer:"inner2_copper"},{canvas:x,copperLayer:"inner3_copper"},{canvas:b,copperLayer:"inner4_copper"},{canvas:w,copperLayer:"inner5_copper"},{canvas:S,copperLayer:"inner6_copper"}];for(const{canvas:B,copperLayer:j}of T)B&&bUn({canvas:B,elements:e,layers:[j],realToCanvasMat:n,primitives:t});for(const{canvas:B,copperLayer:j}of T)B&&oUn({canvas:B,elements:e,layers:[j],realToCanvasMat:n});m&&Dut({canvas:m,elements:e,layers:["top_copper"],realToCanvasMat:n,primitives:t,drawSoldermask:c}),g&&Dut({canvas:g,elements:e,layers:["bottom_copper"],realToCanvasMat:n,primitives:t,drawSoldermask:c}),m&&dG({canvas:m,elements:e,layers:["top_copper"],realToCanvasMat:n}),g&&dG({canvas:g,elements:e,layers:["bottom_copper"],realToCanvasMat:n});for(const{canvas:B,copperLayer:j}of T)B&&mUn({canvas:B,elements:e,layers:[j],realToCanvasMat:n,primitives:t,drawSoldermask:c});if(m&&qut({canvas:m,elements:e,layers:["top_copper"],realToCanvasMat:n,primitives:t,drawSoldermask:c}),g&&qut({canvas:g,elements:e,layers:["bottom_copper"],realToCanvasMat:n,primitives:t,drawSoldermask:c}),c){const B=a==="bottom"?"bottom":"top",j=B==="top",V=B==="bottom",q=s.current.soldermask_top;q&&B==="top"&&Vut({canvas:q,elements:e,layers:["top_soldermask"],realToCanvasMat:n,drawSoldermaskTop:j,drawSoldermaskBottom:V,primitives:t});const K=s.current.soldermask_bottom;K&&B==="bottom"&&Vut({canvas:K,elements:e,layers:["bottom_soldermask"],realToCanvasMat:n,drawSoldermaskTop:j,drawSoldermaskBottom:V,primitives:t})}m&&dG({canvas:m,elements:e,layers:["top_copper"],realToCanvasMat:n}),g&&dG({canvas:g,elements:e,layers:["bottom_copper"],realToCanvasMat:n});const C=s.current.drill;if(C&&tUn({canvas:C,elements:e,layers:["drill"],realToCanvasMat:n}),d){const B=s.current.top_silkscreen;B&&Gut({canvas:B,elements:e,layers:["top_silkscreen"],realToCanvasMat:n});const j=s.current.bottom_silkscreen;j&&Gut({canvas:j,elements:e,layers:["bottom_silkscreen"],realToCanvasMat:n})}if(l){const B=s.current.top_fabrication;B&&Out({canvas:B,elements:e,layers:["top_fabrication_note"],realToCanvasMat:n});const j=s.current.bottom_fabrication;j&&Out({canvas:j,elements:e,layers:["bottom_fabrication_note"],realToCanvasMat:n})}const A=s.current.bottom_notes;A&&Lut({canvas:A,elements:e,layers:["bottom_user_note"],realToCanvasMat:n});const R=s.current.top_notes;if(R&&Lut({canvas:R,elements:e,layers:["top_user_note"],realToCanvasMat:n}),u){const B=s.current.top_courtyard;B&&Wut({canvas:B,elements:e,layers:["top_courtyard"],realToCanvasMat:n});const j=s.current.bottom_courtyard;j&&Wut({canvas:j,elements:e,layers:["bottom_courtyard"],realToCanvasMat:n})}const L=s.current.board;L&&(hUn({canvas:L,elements:e,layers:[],realToCanvasMat:n,drawSoldermask:c}),rUn({canvas:L,elements:e,layers:[],realToCanvasMat:n,drawSoldermask:c}));const O=s.current.edge_cuts;O&&aUn({canvas:O,elements:e,layers:["edge_cuts"],realToCanvasMat:n});const F=[{canvas:m,layer:"top"},{canvas:g,layer:"bottom"}];for(const{canvas:B,layer:j}of F)B&&lUn({canvas:B,elements:e,layers:[j],realToCanvasMat:n})}f.orderAndFadeLayers()},[t,e,n,a,c,l,u,d]),G.jsxs("div",{style:{backgroundColor:"black",width:i,height:o,position:"relative"},children:[G.jsx(WV.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:o,transform:n,stringifyCoord:(h,f,p)=>`${WV.toMMSI(h,p)}, ${WV.toMMSI(f,p)}`}),UUn.filter(h=>!(!c&&h.includes("soldermask")||!d&&h.includes("silkscreen"))).map(h=>h.replace(/-/g,"")).map((h,f)=>G.jsx("canvas",{className:`pcb-layer-${h}`,ref:p=>{s.current??={},p?s.current[h]=p:delete s.current[h]},style:{position:"absolute",zIndex:f,left:0,top:0,pointerEvents:"none"},width:i,height:o},h))]})},YUn=.6,XUn=1;I_e(ZBn(),1),I_e(hjn(),1);var hG=["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 Zut(t,e,n,r={}){const i=r.padding??40,o=r.yFlip??!1;let s;if("center"in t){const u=t.width/2,d=t.height/2;s={minX:t.center.x-u,maxX:t.center.x+u,minY:t.center.y-d,maxY:t.center.y+d}}else s=t;const a=s.maxX-s.minX||1,c=s.maxY-s.minY||1,l=Math.min((e-2*i)/a,(n-2*i)/c);return di(_i(e/2,n/2),Zu(l,o?-l:l),_i(-(s.minX+a/2),-(s.minY+c/2)))}function VUn(t){const e=[...t.points||[],...(t.lines||[]).flatMap(n=>n.points),...(t.rects||[]).flatMap(n=>{const r=n.width/2,i=n.height/2;return[{x:n.center.x-r,y:n.center.y-i},{x:n.center.x+r,y:n.center.y-i},{x:n.center.x-r,y:n.center.y+i},{x:n.center.x+r,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 r=n.fontSize??12,i=n.text.length*r*YUn,o=r*XUn,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:-o/2},center:{dx:-i/2,dy:-o/2},center_right:{dx:-i,dy:-o/2},bottom_left:{dx:0,dy:-o},bottom_center:{dx:-i/2,dy:-o},bottom_right:{dx:-i,dy:-o}},{dx:c,dy:l}=a[s],u=n.x+c,d=n.y+l;return[{x:u,y:d},{x:u+i,y:d+o}]})];return e.length===0?{minX:-1,maxX:1,minY:-1,maxY:1}:e.reduce((n,r)=>({minX:Math.min(n.minX,r.x),maxX:Math.max(n.maxX,r.x),minY:Math.min(n.minY,r.y),maxY:Math.max(n.maxY,r.y)}),{minX:1/0,maxX:-1/0,minY:1/0,maxY:-1/0})}function GUn(t,e,n={}){const r=e instanceof HTMLCanvasElement?e.getContext("2d"):e;if(!r)throw new Error("Could not get 2D context from canvas");const i=e instanceof HTMLCanvasElement?e.width:e.canvas.width,o=e instanceof HTMLCanvasElement?e.height:e.canvas.height;let s;if(n.transform)s=n.transform;else if(n.viewbox)s=Zut(n.viewbox,i,o,{padding:n.padding,yFlip:n.yFlip});else{const a=VUn(t),c=t.coordinateSystem==="cartesian";s=Zut(a,i,o,{padding:n.padding??40,yFlip:c})}r.clearRect(0,0,i,o),r.save(),t.rects&&t.rects.length>0&&t.rects.forEach(a=>{const c=a.width/2,l=a.height/2,u=mt(s,{x:a.center.x-c,y:a.center.y-l}),d=mt(s,{x:a.center.x+c,y:a.center.y+l}),h=Math.abs(d.x-u.x),f=Math.abs(d.y-u.y);r.beginPath(),r.rect(Math.min(u.x,d.x),Math.min(u.y,d.y),h,f),a.fill&&(r.fillStyle=a.fill,r.fill()),a.stroke&&(r.strokeStyle=a.stroke,r.stroke())}),t.circles&&t.circles.length>0&&t.circles.forEach(a=>{const c=mt(s,a.center),l=a.radius*Math.abs(s.a);r.beginPath(),r.arc(c.x,c.y,l,0,2*Math.PI),a.fill&&(r.fillStyle=a.fill,r.fill()),a.stroke&&(r.strokeStyle=a.stroke??"transparent",r.stroke())}),t.lines&&t.lines.length>0&&t.lines.forEach((a,c)=>{if(a.points.length===0)return;r.beginPath();const l=mt(s,a.points[0]);r.moveTo(l.x,l.y);for(let u=1;u<a.points.length;u++){const d=mt(s,a.points[u]);r.lineTo(d.x,d.y)}if(r.strokeStyle=a.strokeColor||hG[c%hG.length],a.strokeWidth?r.lineWidth=a.strokeWidth*s.a:r.lineWidth=2,r.lineCap="round",a.strokeDash)if(typeof a.strokeDash=="string"){let u;if(a.strokeDash.includes(","))u=a.strokeDash.split(",").map(d=>parseFloat(d.trim())).filter(d=>!Number.isNaN(d));else{const d=parseFloat(a.strokeDash.trim());u=Number.isNaN(d)?[]:[d]}r.setLineDash(u)}else r.setLineDash(a.strokeDash.map(u=>u*Math.abs(s.a)));else r.setLineDash([]);r.stroke()}),t.points&&t.points.length>0&&t.points.forEach((a,c)=>{const l=mt(s,a);r.beginPath(),r.arc(l.x,l.y,3,0,2*Math.PI),r.fillStyle=a.color||hG[c%hG.length],r.fill(),a.label&&!n.disableLabels&&(r.fillStyle=a.color||"black",r.font="12px sans-serif",r.fillText(a.label,l.x+5,l.y-5))}),t.texts&&t.texts.length>0&&t.texts.forEach(a=>{const c=mt(s,{x:a.x,y:a.y});r.fillStyle=a.color||"black",r.font=`${(a.fontSize??12)*Math.abs(s.a)}px sans-serif`;const l=a.anchorSide??"center",u={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"},d={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"};r.textAlign=u[l],r.textBaseline=d[l],r.fillText(a.text,c.x,c.y)}),r.restore()}var qUn=({children:t,transform:e,debugGraphics:n})=>{const r=te.useRef(null),[i,{width:o,height:s}]=gO(),a=E0(c=>c.is_showing_autorouting);return te.useEffect(()=>{a&&r.current&&n&&o&&s&&(r.current.width=o,r.current.height=s,GUn(n,r.current,{transform:e,disableLabels:!0}))},[n,e,o,s,a]),a?G.jsxs("div",{ref:i,style:{position:"relative",width:"100%",height:"100%"},children:[t,G.jsx("canvas",{ref:r,style:{position:"absolute",top:0,left:0,opacity:.5,zIndex:100,width:"100%",height:"100%",pointerEvents:"none"}})]}):t},WUn=({children:t,transform:e=el(),elements:n=[]})=>{const[r,{width:i,height:o}]=gO(),s=te.useRef(null);return te.useEffect(()=>{const a=s.current;if(!a||!i||!o)return;a.width=i,a.height=o;const c=a.getContext("2d");if(!c)return;c.clearRect(0,0,i,o);const l=n.filter(d=>d.type==="pcb_component"),u=n.filter(d=>d.type==="pcb_manual_edit_conflict_warning");c.strokeStyle=hi.board.drc_warning,c.lineWidth=2,u.forEach(d=>{const h=l.find(V=>V.pcb_component_id===d.pcb_component_id);if(!h)return;const{width:f,height:p,center:m}=h,g=mt(e,m),y=f*Math.abs(e.a),_=p*Math.abs(e.d),x=.1*Math.abs(e.a),b=y+x*2,w=_+x*2,S=g.x-b/2,T=g.y-w/2;c.beginPath(),c.rect(S,T,b,w),c.stroke();const C="Manual Edit Conflict",A=4,R=Math.max(8,Math.min(12,10*Math.abs(e.a)));c.font=`${R}px sans-serif`;const O=c.measureText(C).width+A*2,F=R+A*2,B=S+(b-O)/2,j=T+w+5;c.fillStyle="rgba(0, 0, 0, 0.7)",c.beginPath(),c.roundRect(B,j,O,F,3),c.fill(),c.fillStyle=hi.board.drc_warning,c.textAlign="center",c.textBaseline="middle",c.fillText(C,B+O/2,j+F/2)})},[n,e,i,o]),G.jsxs("div",{ref:r,style:{position:"relative",width:"100%",height:"100%"},children:[t,G.jsx("canvas",{ref:s,style:{position:"absolute",top:0,left:0,pointerEvents:"none",zIndex:Wl.warnings}})]})},pG=(t,e,n)=>n(t,e),Kut=(t,e,n,r,i)=>{const o=i*Math.PI/180,s=Math.cos(o),a=Math.sin(o),c=t-n,l=e-r,u=c*s-l*a,d=c*a+l*s;return{x:u+n,y:d+r}},_O=t=>{if(t.length===0)return null;let e=t[0].x,n=t[0].x,r=t[0].y,i=t[0].y;for(const o of t)e=pG(e,o.x,Math.min),n=pG(n,o.x,Math.max),r=pG(r,o.y,Math.min),i=pG(i,o.y,Math.max);return{minX:e,maxX:n,minY:r,maxY:i}},ZUn=(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)}),KUn=(t,e)=>t?ZUn(t,e):e,QUn=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}],r=_O(n);return r?{minX:r.minX-e,maxX:r.maxX+e,minY:r.minY-e,maxY:r.maxY+e}:null}case"rect":{const e=t.w/2,n=t.h/2,r=[{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,o=i===0?r:r.map(s=>Kut(s.x,s.y,t.x,t.y,i));return _O(o)}case"circle":return{minX:t.x-t.r,maxX:t.x+t.r,minY:t.y-t.r,maxY:t.y+t.r};case"oval":return{minX:t.x-t.rX,maxX:t.x+t.rX,minY:t.y-t.rY,maxY:t.y+t.rY};case"pill":{const e=t.w/2,n=t.h/2,r=[{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,o=i===0?r:r.map(s=>Kut(s.x,s.y,t.x,t.y,i));return _O(o)}case"polygon":return _O(t.points);case"polygon_with_arcs":{const e=t.brep_shape.outer_ring.vertices.map(n=>({x:n.x,y:n.y}));return _O(e)}case"text":{const e=t.size??0,n=t.text?t.text.length*e*.6:0,r=e;if(n===0&&r===0)return{minX:t.x,maxX:t.x,minY:t.y,maxY:t.y};const i=n/2,o=r/2;return{minX:t.x-i,maxX:t.x+i,minY:t.y-o,maxY:t.y+o}}default:return null}};function JUn(t){const{dimensionStart:e,dimensionEnd:n,screenDimensionStart:r,screenDimensionEnd:i,flipX:o,flipY:s}=t,a=n.x-e.x,c=n.y-e.y,l=Math.sqrt(a*a+c*c),u=i.x-r.x,d=i.y-r.y,h=Math.sqrt(u*u+d*d),f=Math.atan2(d,u)*(180/Math.PI),p=Math.abs(f)%90,g=Math.min(p,90-p)>15,y=(r.x+i.x)/2,_=(r.y+i.y)/2,x=15,b=f+90;let w=Math.cos(b*Math.PI/180)*x,S=Math.sin(b*Math.PI/180)*x;const T=u>0&&d<0,C=u>0&&d>0,A=u<0&&d>0;o!==s&&!T&&(w=-w,S=-S),T&&(w+=Math.cos(b*Math.PI/180)*-45,S+=Math.sin(b*Math.PI/180)*-45),C&&(w+=Math.cos(b*Math.PI/180)+-20,S+=Math.sin(b*Math.PI/180)+-10),A&&(w+=Math.cos(b*Math.PI/180)*10,S+=Math.sin(b*Math.PI/180)*10);const R=y+w,L=_+S;return{distance:l,screenDistance:h,x:R,y:L,show:l>.01&&h>30&&g}}function eHn(t){const{dimensionStart:e,dimensionEnd:n,screenDimensionStart:r,screenDimensionEnd:i,flipX:o,flipY:s}=t;return te.useMemo(()=>JUn({dimensionStart:e,dimensionEnd:n,screenDimensionStart:r,screenDimensionEnd:i,flipX:o,flipY:s}),[e,n,r,i,o,s])}var tHn=(t,e,n)=>{const r=n*Math.PI/180,i=Math.cos(r),o=Math.sin(r),s=t.x-e.x,a=t.y-e.y,c=s*i-a*o,l=s*o+a*i;return{x:c+e.x,y:l+e.y}},Qut=(t,e,n,r)=>{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 r===0?Object.entries(i).map(([o,s])=>({anchor:o,point:s})):Object.entries(i).map(([o,s])=>({anchor:o,point:tHn(s,t,r)}))},nHn=t=>{switch(t.pcb_drawing_type){case"rect":{const e=t.ccw_rotation??0;return Qut({x:t.x,y:t.y},t.w/2,t.h/2,e)}case"pill":{const e=t.ccw_rotation??0;return Qut({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[]}},rHn=16,AS=5,Jut=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},iHn=({children:t,transform:e,focusOnHover:n=!1,primitives:r=[]})=>{e||(e=el());const[i,o]=te.useState(!1),[s,a]=te.useState(!1),[c,l]=te.useState(!1),[u,d]=te.useState({start:null,end:null}),h=E0(j=>j.is_mouse_over_container),f=te.useCallback(()=>{c&&(l(!1),window.dispatchEvent(new Event("disarm-dimension-tool")))},[c]),[p,m]=te.useState({x:0,y:0}),[g,y]=te.useState({x:0,y:0}),_=te.useRef({x:0,y:0}),x=te.useRef(null),w=x.current?.getBoundingClientRect(),S=te.useMemo(()=>{const j=new Map;for(const V of r){if(!V._element||Jut(V)||V.pcb_drawing_type==="pill"||V.pcb_drawing_type==="rect"&&V.ccw_rotation&&V.ccw_rotation!==0)continue;const q=QUn(V);if(!q)continue;const K=j.get(V._element);j.set(V._element,KUn(K??void 0,q))}return j},[r]),T=te.useMemo(()=>{const j=[];for(const V of r){if(!V._element||Jut(V))continue;const q=nHn(V);if(q.length!==0)for(const K of q)j.push({anchor:K.anchor,point:K.point,element:V._element})}return j},[r]),C=te.useMemo(()=>{const j=[];S.forEach((V,q)=>{if(!V)return;const K=(V.minX+V.maxX)/2,ne=(V.minY+V.maxY)/2,le={top_left:{x:V.minX,y:V.minY},top_center:{x:K,y:V.minY},top_right:{x:V.maxX,y:V.minY},center_left:{x:V.minX,y:ne},center:{x:K,y:ne},center_right:{x:V.maxX,y:ne},bottom_left:{x:V.minX,y:V.maxY},bottom_center:{x:K,y:V.maxY},bottom_right:{x:V.maxX,y:V.maxY}};for(const[ee,ie]of Object.entries(le))j.push({anchor:ee,point:ie,element:q})});for(const V of T)j.push(V);return j.push({anchor:"origin",point:{x:0,y:0},element:null}),j},[S,T]),A=te.useMemo(()=>C.map((j,V)=>({...j,id:`${V}-${j.anchor}`,screenPoint:mt(e,j.point)})),[C,e]),R=te.useCallback(j=>{if(A.length===0)return{point:j,id:null};const V=mt(e,j);let q=null;for(const K of A){const ne=K.screenPoint.x-V.x,le=K.screenPoint.y-V.y,ee=Math.hypot(ne,le);ee>rHn||(!q||ee<q.distance)&&(q={distance:ee,id:K.id,point:K.point})}return q?{point:q.point,id:q.id}:{point:j,id:null}},[A,e]);te.useEffect(()=>{const j=q=>{const K=q.target;if(K.tagName==="INPUT"||K.tagName==="TEXTAREA"||K.isContentEditable)return;const ne=x.current?.contains(document.activeElement)||document.activeElement===x.current;if(!(!h&&!ne)){if(q.key==="d"){const le=R({x:_.current.x,y:_.current.y});m({x:le.point.x,y:le.point.y}),y({x:le.point.x,y:le.point.y}),d({start:le.id,end:le.id}),i?(o(!1),a(!1),d({start:null,end:null})):(o(!0),a(!0)),f()}q.key==="Escape"&&(o(!1),a(!1),d({start:null,end:null}),f())}},V=()=>{l(!0)};return window.addEventListener("keydown",j),window.addEventListener("arm-dimension-tool",V),()=>{window.removeEventListener("keydown",j),window.removeEventListener("arm-dimension-tool",V),f()}},[h,i,f,R]);const L=mt(e,p),O=mt(e,g),F={left:Math.min(L.x,O.x),right:Math.max(L.x,O.x),top:Math.min(L.y,O.y),bottom:Math.max(L.y,O.y),flipX:L.x>O.x,flipY:L.y>O.y,width:0,height:0};F.width=F.right-F.left,F.height=F.bottom-F.top;const B=eHn({dimensionStart:p,dimensionEnd:g,screenDimensionStart:L,screenDimensionEnd:O,flipX:F.flipX,flipY:F.flipY});return G.jsxs("div",{ref:x,"data-pcb-viewer":!0,tabIndex:0,style:{position:"relative",outline:"none"},onMouseEnter:()=>{n&&x.current&&x.current.focus()},onMouseLeave:()=>{x.current&&x.current.blur()},onClick:()=>{x.current&&x.current.focus()},onMouseMove:j=>{const V=j.currentTarget.getBoundingClientRect(),q=j.clientX-V.left,K=j.clientY-V.top,ne=mt(Bx(e),{x:q,y:K});if(_.current.x=ne.x,_.current.y=ne.y,s){const le=R(ne);y({x:le.point.x,y:le.point.y}),d(ee=>({...ee,end:le.id}))}},onMouseDown:j=>{const V=j.currentTarget.getBoundingClientRect(),q=j.clientX-V.left,K=j.clientY-V.top,ne=mt(Bx(e),{x:q,y:K});if(c&&!i){const le=R(ne);m({x:le.point.x,y:le.point.y}),y({x:le.point.x,y:le.point.y}),d({start:le.id,end:le.id}),o(!0),a(!0),f()}else s?(a(!1),d(le=>({...le,end:null}))):i&&(o(!1),d({start:null,end:null}))},children:[t,i&&G.jsxs(G.Fragment,{children:[B.show&&G.jsx("div",{style:{position:"absolute",left:B.x,top:B.y,color:"red",mixBlendMode:"difference",pointerEvents:"none",fontSize:12,fontFamily:"sans-serif",whiteSpace:"nowrap",zIndex:Wl.dimensionOverlay},children:B.distance.toFixed(2)}),G.jsx("div",{style:{position:"absolute",left:F.left,width:F.width,textAlign:"center",top:L.y+2,color:"red",mixBlendMode:"difference",pointerEvents:"none",marginTop:F.flipY?0:-20,fontSize:12,fontFamily:"sans-serif",zIndex:Wl.dimensionOverlay},children:Math.abs(p.x-g.x).toFixed(2)}),G.jsx("div",{style:{position:"absolute",left:O.x,height:F.height,display:"flex",flexDirection:"column",justifyContent:"center",top:F.top,color:"red",pointerEvents:"none",mixBlendMode:"difference",fontSize:12,fontFamily:"sans-serif",zIndex:Wl.dimensionOverlay},children:G.jsx("div",{style:{marginLeft:F.flipX?"-100%":4,paddingRight:4},children:Math.abs(p.y-g.y).toFixed(2)})}),G.jsxs("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none",mixBlendMode:"difference",zIndex:Wl.dimensionOverlay},width:w.width,height:w.height,children:[G.jsx("defs",{children:G.jsx("marker",{id:"head",orient:"auto",markerWidth:"3",markerHeight:"4",refX:"2",refY:"2",children:G.jsx("path",{d:"M0,0 V4 L2,2 Z",fill:"red"})})}),G.jsx("line",{x1:L.x,y1:L.y,x2:O.x,y2:O.y,markerEnd:"url(#head)",strokeWidth:1.5,fill:"none",stroke:"red"}),G.jsx("line",{x1:L.x,y1:L.y,x2:O.x,y2:L.y,strokeWidth:1.5,fill:"none",strokeDasharray:"2,2",stroke:"red"}),G.jsx("line",{x1:O.x,y1:L.y,x2:O.x,y2:O.y,strokeWidth:1.5,fill:"none",strokeDasharray:"2,2",stroke:"red"})]}),s&&A.map(j=>{const V=j.id===u.start||j.id===u.end,q=AS/2;return G.jsxs("svg",{width:AS,height:AS,style:{position:"absolute",left:j.screenPoint.x-q,top:j.screenPoint.y-q,pointerEvents:"none",zIndex:Wl.dimensionOverlay},children:[G.jsx("line",{x1:0,y1:0,x2:AS,y2:AS,stroke:V?"#66ccff":"white",strokeWidth:1}),G.jsx("line",{x1:AS,y1:0,x2:0,y2:AS,stroke:V?"#66ccff":"white",strokeWidth:1})]},j.id)}),G.jsxs("div",{style:{right:0,bottom:0,position:"absolute",color:"red",fontFamily:"sans-serif",fontSize:12,margin:4},children:["(",p.x.toFixed(2),",",p.y.toFixed(2),")",G.jsx("br",{}),"(",g.x.toFixed(2),",",g.y.toFixed(2),")",G.jsx("br",{}),"dist:"," ",Math.sqrt((g.x-p.x)**2+(g.y-p.y)**2).toFixed(2)]})]})]})},oHn=(t,e,n=0)=>{const r=t.width/2,i=t.height/2,o=t.center.x-r-n,s=t.center.x+r+n,a=t.center.y-i-n,c=t.center.y+i+n;return e.x>o&&e.x<s&&e.y>a&&e.y<c},sHn=({children:t,disabled:e,transform:n,soup:r,cancelPanDrag:i,onCreateEditEvent:o,onModifyEditEvent:s})=>{n||(n=el());const a=te.useRef(null),[c,l]=te.useState(null),[u,d]=te.useState(null),h=c!==null;E0(g=>g.in_edit_mode);const f=E0(g=>g.in_move_footprint_mode),p=E0(g=>g.setIsMovingComponent),m=e||!f;return G.jsxs("div",{ref:a,style:{position:"relative",overflow:"hidden"},onMouseDown:g=>{if(m)return;const y=g.currentTarget.getBoundingClientRect(),_=g.clientX-y.left,x=g.clientY-y.top;if(Number.isNaN(_)||Number.isNaN(x))return;const b=mt(Bx(n),{x:_,y:x});let w=!1;for(const S of r)if(S.type==="pcb_component"&&oHn(S,b,10/n.a)){i(),l(S.pcb_component_id),w=!0;const T=Math.random().toString();d({dragStart:b,originalCenter:S.center,dragEnd:b,edit_event_id:T}),o({edit_event_id:T,edit_event_type:"edit_pcb_component_location",pcb_edit_event_type:"edit_component_location",pcb_component_id:S.pcb_component_id,original_center:S.center,new_center:S.center,in_progress:!0,created_at:Date.now()}),p(!0);break}if(w||l(null),w)return g.preventDefault(),!1},onMouseMove:g=>{if(!c||!u)return;const y=g.currentTarget.getBoundingClientRect(),_=g.clientX-y.left,x=g.clientY-y.top;if(Number.isNaN(_)||Number.isNaN(x))return;const b=mt(Bx(n),{x:_,y:x});d({...u,dragEnd:b}),s({edit_event_id:u.edit_event_id,new_center:{x:u.originalCenter.x+b.x-u.dragStart.x,y:u.originalCenter.y+b.y-u.dragStart.y}})},onMouseUp:g=>{c&&(l(null),p(!1),u&&(s({edit_event_id:u.edit_event_id,in_progress:!1}),d(null)))},children:[t,!m&&r.filter(g=>g.type==="pcb_component").map(g=>{if(!g?.center)return null;const y=mt(n,g.center);return G.jsx("div",{style:{position:"absolute",pointerEvents:"none",left:y.x,top:y.y,width:g.width*n.a+20,height:g.height*n.a+20,transform:"translate(-50%, -50%)",background:h&&c===g.pcb_component_id?"rgba(255, 0, 0, 0.2)":""}},g.pcb_component_id)})]})},aHn=({hotkeys:t})=>(te.useEffect(()=>{const e=n=>{t.forEach(r=>{n.key===r.key&&r.onUse()})};return window.addEventListener("keydown",e),()=>{window.removeEventListener("keydown",e)}},[t]),G.jsx("div",{className:vP`
5419
5419
  display: flex;
5420
5420
  flex-direction: column;
5421
5421
  font-family: sans-serif;
@@ -5454,7 +5454,7 @@ $1`).replace(/>(\s*)(?=<!--\s*\/)/g,"> ")}}});function Tut(t,e,n){if(!e||!n)retu
5454
5454
  transition: opacity 0.2s;
5455
5455
  margin-bottom: 10px;
5456
5456
  color: red;
5457
- `,pHn=({children:t,transform:e=el(),elements:n})=>{const r=te.useRef(null),{isShowingDRCErrors:i,hoveredErrorId:o}=E0(l=>({isShowingDRCErrors:l.is_showing_drc_errors,hoveredErrorId:l.hovered_error_id}));if(!n)return G.jsx("div",{style:{position:"relative"},ref:r,children:t});const s=n.filter(l=>l.type==="pcb_trace_error"),a=n.filter(l=>l.type==="pcb_trace_error"&&l.message?.includes("Multiple components found with name")),c=new Map;return n.forEach(l=>{l.type==="pcb_port"&&c.set(l.pcb_port_id,l)}),G.jsxs("div",{style:{position:"relative"},ref:r,children:[t,s.map((l,u)=>{const{pcb_port_ids:d,pcb_trace_id:h}=l,f=d?.[0]?c.get(d[0]):void 0,p=d?.[1]?c.get(d[1]):void 0,m=n?B9(n).pcb_trace.get(h):void 0,g=l.pcb_trace_error_id||`error_${u}_${l.error_type}_${l.message?.slice(0,20)}`,y=o===g;if(f&&p){const _=mt(e,{x:f.x,y:f.y}),x=mt(e,{x:p.x,y:p.y});if(!i)return null;const b=!(isNaN(_.x)||isNaN(_.y)||isNaN(x.x)||isNaN(x.y)),w={x:(_.x+x.x)/2,y:(_.y+x.y)/2};if(isNaN(w.x)||isNaN(w.y))return null;const S=F_e(w,r);return G.jsxs(te.Fragment,{children:[G.jsx(dHn,{screenPort1:_,screenPort2:x,errorCenter:w,canLineBeDrawn:b,isHighlighted:y}),G.jsx("div",{style:{position:"absolute",left:w.x-15,top:w.y-15,width:30,height:30,zIndex:Wl.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:T=>{const C=T.currentTarget.nextElementSibling;if(C){const A=C.querySelector(".error-message");A&&(A.style.opacity="1")}},onMouseLeave:T=>{if(!y){const C=T.currentTarget.nextElementSibling;if(C){const A=C.querySelector(".error-message");A&&(A.style.opacity="0")}}}}),G.jsx("div",{style:{position:"absolute",zIndex:y?200:100,left:S.left,top:S.top,color:y?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:i||y?"flex":"none",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:S.transform},children:G.jsx("div",{className:`error-message ${B_e}`,style:{opacity:y?1:0,border:`1px solid ${y?"#ff4444":"red"}`},children:l.message})})]},g)}if(m?.route&&(i||y)){const _=m.route.map(S=>mt(e,{x:S.x,y:S.y}));if(_.some(S=>isNaN(S.x)||isNaN(S.y)))return null;const x=Math.floor(_.length/2),b=_[x],w=F_e(b,r);return G.jsxs(te.Fragment,{children:[G.jsx(hHn,{points:_,errorCenter:b,isHighlighted:y}),G.jsx("div",{style:{position:"absolute",left:b.x-15,top:b.y-15,width:30,height:30,zIndex:Wl.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:S=>{const T=S.currentTarget.nextElementSibling;if(T){const C=T.querySelector(".error-message");C&&(C.style.opacity="1")}},onMouseLeave:S=>{if(!y){const T=S.currentTarget.nextElementSibling;if(T){const C=T.querySelector(".error-message");C&&(C.style.opacity="0")}}}}),G.jsx("div",{style:{position:"absolute",zIndex:y?Wl.errorOverlay+10:Wl.errorOverlay+1,left:w.left,top:w.top,color:y?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:"flex",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:w.transform},children:G.jsx("div",{className:`error-message ${B_e}`,style:{opacity:y?1:0,border:`1px solid ${y?"#ff4444":"red"}`},children:l.message})})]},g)}return null}),a.map((l,u)=>{const d=l.component_name||l.message?.match(/name "([^"]+)"/)?.[1];if(!d)return null;const h=n?.filter(m=>m.type==="source_component"&&m.name===d||m.type==="pcb_component"&&n?.find(g=>g.type==="source_component"&&g.source_component_id===m.source_component_id&&g.name===d))||[],f=l.pcb_trace_error_id||`error_${u}_${l.error_type}_${l.message?.slice(0,20)}`,p=o===f;return!p&&!i?null:h.map((m,g)=>{let y={x:0,y:0};if(m.type==="pcb_component")y=m.center||{x:0,y:0};else if(m.type==="source_component"){const A=n?.find(R=>R.type==="pcb_component"&&R.source_component_id===m.source_component_id);A&&A.type==="pcb_component"&&(y=A.center||{x:0,y:0})}const _=mt(e,y);if(isNaN(_.x)||isNaN(_.y))return null;const x=Math.abs(e.a),T=Math.max(8,Math.min(30,.5*x)),C=F_e(_,r);return G.jsxs(te.Fragment,{children:[G.jsx("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none",mixBlendMode:"difference",zIndex:Wl.errorOverlay},width:"100%",height:"100%",children:p?G.jsx("polygon",{points:`${_.x},${_.y-T*1.25} ${_.x+T},${_.y} ${_.x},${_.y+T*1.25} ${_.x-T},${_.y}`,fill:"#ff4444"}):G.jsx("circle",{cx:_.x,cy:_.y,r:T,fill:"none",stroke:p?"#ff4444":"red",strokeWidth:p?Math.max(2,T*.15):Math.max(1,T*.1),opacity:1})}),G.jsx("div",{style:{position:"absolute",left:_.x-(T+10),top:_.y-(T+10),width:(T+10)*2,height:(T+10)*2,zIndex:Wl.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:A=>{const R=A.currentTarget.nextElementSibling;if(R){const L=R.querySelector(".error-message");L&&(L.style.opacity="1")}},onMouseLeave:A=>{if(!p){const R=A.currentTarget.nextElementSibling;if(R){const L=R.querySelector(".error-message");L&&(L.style.opacity="0")}}}}),G.jsx("div",{style:{position:"absolute",zIndex:p?Wl.errorOverlay+20:Wl.errorOverlay+10,left:C.left,top:C.top,color:p?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:i||p?"flex":"none",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:C.transform},children:G.jsx("div",{className:`error-message ${B_e}`,style:{opacity:p?1:0,border:`1px solid ${p?"#ff4444":"red"}`},children:l.message})})]},`${f}_${g}`)})})]})};function fHn(t,e){return t.size!==e.size?!1:Array.from(t).every(n=>e.has(n))}function mHn({primitiveElement:t,elements:e}){let n=t.trace_length?`${t.trace_length.toFixed(3)}`:"";const r=B9(e).source_trace.get(t?.source_trace_id);if(r?.display_name&&(r?.max_length?n+=` / ${r.max_length}mm `:n+=" mm ",n+=`(${r.display_name})`),!n)return null;const i=t.trace_length&&r?.max_length&&t.trace_length>r.max_length;return{text:n,isOverLength:i}}function yHn(t){const{primitives:e,is_showing_multiple_traces_length:n,elements:r}=t,i=e.filter(c=>c._element.type==="pcb_trace"),o=r.filter(c=>c.type==="source_trace"),s=e.filter(c=>c._element.type!=="pcb_trace"),a=i.filter(c=>o.some(l=>c._element.type==="pcb_trace"&&c._element.source_trace_id===l.source_trace_id&&l.max_length!==void 0));if(!n)return[...s,...a];if(i.length>1){const c=i.reduce((l,u)=>{const d=l._element.trace_length;return u._element.trace_length<d?u:l},i[0]);return[...s,c]}return e}var gHn={position:"absolute",left:0,top:0,pointerEvents:"none",color:"red",fontFamily:"sans-serif",fontSize:12,textShadow:"0 0 2px black"},_Hn=t=>{const{_element:e,_parent_pcb_component:n,_parent_source_component:r,_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 o=[],s=Array.from(new Set((e.port_hints??[]).concat(i?.port_hints??[]))).filter(c=>!/^[0-9]+$/.test(c)).filter(c=>!c.includes("unnamed_")).sort((c,l)=>l.localeCompare(c)),a=r&&"name"in r&&r.name&&!r.name.includes("unnamed_")?r.name:null;return s.length>0?a?o.push(...s.map(c=>`${a}.${c}`)):o.push(...s):a&&o.push(a),o.join(", ")}default:return""}},xHn={top:"red",bottom:"aqua"},bHn=({primitive:t,mousePos:e,elements:n})=>{const[r,i]=te.useState(!1),o=t._element;te.useEffect(()=>{setTimeout(()=>{i(!0)},100)},[]);const[s,a,c,l]=[t.screen_x,t.screen_y,t.screen_w,t.screen_h],u=t.same_space_index??0,d=26,h=xHn[t?._element?.layer]??"red";let f=0;if(o.type==="pcb_smtpad"&&o?.shape==="rotated_rect"?f=o?.ccw_rotation??0:(o.type==="pcb_smtpad"&&(o?.shape==="pill"||o?.shape==="rotated_pill")&&"ccw_rotation"in t||o.type==="pcb_plated_hole"&&(o?.shape==="pill"||o?.shape==="oval")&&"ccw_rotation"in t)&&(f=o.ccw_rotation??0),o.type==="pcb_trace"){const g=mHn({primitiveElement:o,elements:n});if(!g)return null;const y=e.y-35;return G.jsx("div",{style:{zIndex:Wl.elementOverlay,position:"absolute",left:e.x,top:y,color:h,pointerEvents:"none",transform:"translateX(-50%)"},children:G.jsx("div",{style:{backgroundColor:"#f2efcc",color:g.isOverLength?"red":"black",textShadow:"none",WebkitFontSmoothing:"antialiased",MozOsxFontSmoothing:"grayscale",padding:"6px 6px",borderRadius:"6px",fontSize:"14px",minWidth:"45px",textAlign:"center",whiteSpace:"nowrap"},children:g.text})})}const p=_Hn(t);return p.trim().length===0?null:G.jsx("div",{style:{zIndex:Wl.elementOverlay,position:"absolute",left:s-c/2-8,top:a-l/2-8,width:c+16,height:l+16,color:h,transform:`rotate(${-f}deg)`,transformOrigin:"center center"},children:G.jsx("div",{style:{width:r?`calc(100% + ${d*2*u}px)`:"100%",height:r?`calc(100% + ${d*2*u}px)`:"100%",marginLeft:r?`${-d*u}px`:0,marginTop:r?`${-d*u}px`:0,border:`1px solid ${h}`,opacity:r||u===0?1:0,transition:"width 0.2s, height 0.2s, margin-left 0.2s, margin-top 0.2s, opacity 0.2s"},children:G.jsx("div",{style:{position:"absolute",bottom:l+20+d*u,marginRight:r?`${-d*u}px`:0,marginBottom:r?0:-d*u,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(${f}deg)`,minWidth:"45px",textAlign:"center"},children:p})})})},vHn=({highlightedPrimitives:t,mousePos:e,elements:n})=>{const[r,i]=E0(a=>[a.is_moving_component,a.is_showing_multiple_traces_length]),o=t.some(a=>a._element.type==="pcb_smtpad")&&t.some(a=>a._element.type==="pcb_trace");let s=t;return o&&(s=s.filter(a=>a._element.type==="pcb_smtpad")),s=yHn({primitives:s,is_showing_multiple_traces_length:i,elements:n}),G.jsx("div",{style:gHn,children:!r&&s.map((a,c)=>G.jsx(bHn,{primitive:a,mousePos:e,elements:n},c))})},M8=t=>t?.type==="pcb_component",e0t=t=>t?.type==="pcb_group",wHn=t=>t?.type==="pcb_panel",j_e=t=>t?.type==="pcb_board",Cu={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},U2={OFFSET_LINE:"white",COMPONENT_MARKER_FILL:"#66ccff",COMPONENT_MARKER_STROKE:"white",LABEL_TEXT:"white"},U_e=({targets:t,transform:e,containerWidth:n,containerHeight:r})=>{if(t.length===0)return null;const i={color:U2.LABEL_TEXT,mixBlendMode:"difference",pointerEvents:"none",fontSize:Cu.LABEL_FONT_SIZE,fontFamily:"monospace",fontWeight:"bold"},o=new Map;return t.forEach(s=>{if(!o.has(s.anchor_id)){const a=mt(e,s.anchor);o.set(s.anchor_id,a)}}),G.jsx("div",{style:{position:"absolute",left:0,top:0,width:n,height:r,overflow:"hidden",pointerEvents:"none",zIndex:Wl.dimensionOverlay},children:G.jsxs("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none"},width:n,height:r,children:[t.map(s=>{const a=s.anchor,c=s.anchor_id,l=s.target,u=o.get(c),d=mt(e,l),h=l.x-a.x,f=l.y-a.y,p=Math.abs(d.x-u.x),m=Math.abs(d.y-u.y),g=d.y<u.y,y=d.x>u.x,_=g?Cu.LABEL_OFFSET_ABOVE:Cu.LABEL_OFFSET_BELOW,x=y?Cu.LABEL_OFFSET_RIGHT:Cu.LABEL_OFFSET_LEFT,b=p>Cu.MIN_LINE_LENGTH_FOR_LABEL,w=m>Cu.MIN_LINE_LENGTH_FOR_LABEL,S=`${s.display_offset_x??h.toFixed(2)}mm`,T=`${s.display_offset_y??f.toFixed(2)}mm`;return G.jsxs("g",{children:[G.jsx("line",{x1:u.x,y1:u.y,x2:d.x,y2:u.y,stroke:U2.OFFSET_LINE,strokeWidth:Cu.LINE_STROKE_WIDTH,strokeDasharray:Cu.LINE_DASH_PATTERN}),G.jsx("line",{x1:d.x,y1:u.y,x2:d.x,y2:d.y,stroke:U2.OFFSET_LINE,strokeWidth:Cu.LINE_STROKE_WIDTH,strokeDasharray:Cu.LINE_DASH_PATTERN}),s.type==="component"||s.type==="board"?G.jsx("circle",{cx:d.x,cy:d.y,r:Cu.COMPONENT_MARKER_RADIUS,fill:U2.COMPONENT_MARKER_FILL,stroke:U2.COMPONENT_MARKER_STROKE,strokeWidth:1}):G.jsxs(G.Fragment,{children:[G.jsx("line",{x1:d.x-Cu.ANCHOR_MARKER_SIZE,y1:d.y,x2:d.x+Cu.ANCHOR_MARKER_SIZE,y2:d.y,stroke:U2.OFFSET_LINE,strokeWidth:Cu.ANCHOR_MARKER_STROKE_WIDTH}),G.jsx("line",{x1:d.x,y1:d.y-Cu.ANCHOR_MARKER_SIZE,x2:d.x,y2:d.y+Cu.ANCHOR_MARKER_SIZE,stroke:U2.OFFSET_LINE,strokeWidth:Cu.ANCHOR_MARKER_STROKE_WIDTH})]}),b&&G.jsx("foreignObject",{x:Math.min(u.x,d.x),y:u.y+_,width:Math.abs(d.x-u.x),height:20,style:{overflow:"visible"},children:G.jsx("div",{style:{...i,textAlign:"center"},children:S})}),w&&G.jsx("foreignObject",{x:d.x+x,y:Math.min(u.y,d.y),width:Cu.Y_LABEL_MIN_WIDTH,height:Math.abs(d.y-u.y),style:{overflow:"visible"},children:G.jsx("div",{style:{...i,display:"flex",alignItems:"center",justifyContent:y?"flex-start":"flex-end",whiteSpace:"nowrap",padding:"0 4px",height:"100%"},children:T})})]},s.id)}),Array.from(o.entries()).map(([s,a])=>G.jsxs("g",{children:[G.jsx("line",{x1:a.x-Cu.ANCHOR_MARKER_SIZE,y1:a.y,x2:a.x+Cu.ANCHOR_MARKER_SIZE,y2:a.y,stroke:U2.OFFSET_LINE,strokeWidth:Cu.ANCHOR_MARKER_STROKE_WIDTH}),G.jsx("line",{x1:a.x,y1:a.y-Cu.ANCHOR_MARKER_SIZE,x2:a.x,y2:a.y+Cu.ANCHOR_MARKER_SIZE,stroke:U2.OFFSET_LINE,strokeWidth:Cu.ANCHOR_MARKER_STROKE_WIDTH})]},`anchor-${s}`))]})})},SHn=({elements:t,highlightedPrimitives:e,transform:n,containerWidth:r,containerHeight:i})=>{const o=t.filter(y=>j_e(y)),s=t.filter(y=>M8(y)),a=t.filter(y=>e0t(y)),c=e.map(y=>M8(y._parent_pcb_component)?y._parent_pcb_component.pcb_component_id:M8(y._element)?y._element.pcb_component_id:null).filter(y=>!!y),l=new Set;if(c.forEach(y=>{const _=s.find(x=>x.pcb_component_id===y);_?.pcb_group_id&&l.add(_.pcb_group_id)}),!E0(y=>y.is_showing_group_anchor_offsets)&&c.length===0)return null;const d=s.map(y=>{const _=y.positioned_relative_to_pcb_board_id;if(!_)return null;const x=o.find(b=>b.pcb_board_id===_);return x?{component:y,board:x,type:"component"}:null}).filter(y=>!!y),h=a.map(y=>{const _=y.positioned_relative_to_pcb_board_id;if(!_||!y.center)return null;const x=o.find(b=>b.pcb_board_id===_);return x?{group:y,board:x,type:"group"}:null}).filter(y=>!!y),f=[...d,...h];if(f.length===0)return null;const p=c.length===0,m=f.filter(y=>y.type==="component"?p||c.includes(y.component.pcb_component_id):p||l.has(y.group.pcb_group_id));if(m.length===0)return null;const g=m.map(y=>y.type==="component"?{id:`${y.board.pcb_board_id}-${y.component.pcb_component_id}-${y.type}`,anchor:y.board.center,anchor_id:y.board.pcb_board_id,target:y.component.center,type:"component",display_offset_x:y.component.display_offset_x,display_offset_y:y.component.display_offset_y}:{id:`${y.board.pcb_board_id}-${y.group.pcb_group_id}-${y.type}`,anchor:y.board.center,anchor_id:y.board.pcb_board_id,target:{x:y.group.anchor_position?.x??y.group.center.x,y:y.group.anchor_position?.y??y.group.center.y},type:"group",display_offset_x:y.group.display_offset_x,display_offset_y:y.group.display_offset_y}).filter(y=>!!y);return G.jsx(U_e,{targets:g,transform:n,containerWidth:r,containerHeight:i})},MHn=({elements:t,highlightedPrimitives:e,transform:n,containerWidth:r,containerHeight:i})=>{const o=t.filter(y=>e0t(y)),s=t.filter(y=>M8(y)),a=e.map(y=>M8(y._parent_pcb_component)?y._parent_pcb_component.pcb_component_id:M8(y._element)?y._element.pcb_component_id:null).filter(y=>!!y),c=(y,_)=>{if(_.has(y))return;_.add(y);const x=o.find(b=>b.pcb_group_id===y);x?.position_mode==="relative_to_group_anchor"&&x.positioned_relative_to_pcb_group_id&&c(x.positioned_relative_to_pcb_group_id,_)},l=new Set;if(a.forEach(y=>{const _=s.find(x=>x.pcb_component_id===y);_&&(_.position_mode==="relative_to_group_anchor"&&_.positioned_relative_to_pcb_group_id&&c(_.positioned_relative_to_pcb_group_id,l),_.pcb_group_id&&c(_.pcb_group_id,l))}),!E0(y=>y.is_showing_group_anchor_offsets)&&a.length===0)return null;const d=s.map(y=>{if(y.position_mode==="relative_to_group_anchor"&&y.positioned_relative_to_pcb_group_id){const _=o.find(x=>x.pcb_group_id===y.positioned_relative_to_pcb_group_id);return _&&_.anchor_position?{component:y,parentGroup:_,type:"component"}:null}if(y.pcb_group_id){const _=o.find(x=>x.pcb_group_id===y.pcb_group_id);return _&&_.anchor_position?{component:y,parentGroup:_,type:"component"}:null}return null}).filter(y=>!!y),h=o.map(y=>{if(y.position_mode==="relative_to_group_anchor"&&y.positioned_relative_to_pcb_group_id){const _=o.find(x=>x.pcb_group_id===y.positioned_relative_to_pcb_group_id);if(_&&_.anchor_position&&y.anchor_position)return{group:y,parentGroup:_,type:"group"}}return null}).filter(y=>!!y),f=[...d,...h];if(f.length===0)return null;const p=a.length===0,m=f.filter(y=>y.type==="component"?p||a.includes(y.component.pcb_component_id):p||l.has(y.group.pcb_group_id)||l.has(y.parentGroup.pcb_group_id));if(m.length===0)return null;const g=m.map(y=>{const _=y.parentGroup.anchor_position;return _?y.type==="component"?y.component.center?{id:`${y.parentGroup.pcb_group_id}-${y.component.pcb_component_id}-${y.type}`,anchor:_,anchor_id:y.parentGroup.pcb_group_id,target:y.component.center,type:"component",display_offset_x:y.component.display_offset_x,display_offset_y:y.component.display_offset_y}:null:y.group.anchor_position?{id:`${y.parentGroup.pcb_group_id}-${y.group.pcb_group_id}-${y.type}`,anchor:_,anchor_id:y.parentGroup.pcb_group_id,target:y.group.anchor_position,type:"group",display_offset_x:y.group.display_offset_x,display_offset_y:y.group.display_offset_y}:null:null}).filter(y=>!!y);return G.jsx(U_e,{targets:g,transform:n,containerWidth:r,containerHeight:i})},THn=(t,e)=>{const n=t.pcb_component_id,r=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 r.length===0?z_e([t]):z_e(r)},EHn=({elements:t,highlightedPrimitives:e,transform:n,containerWidth:r,containerHeight:i})=>{const o=new Map;for(const a of e)M8(a._parent_pcb_component)&&o.set(a._parent_pcb_component.pcb_component_id,a._parent_pcb_component),M8(a._element)&&o.set(a._element.pcb_component_id,a._element);if(o.size===0)return null;const s=[];for(const a of o.values()){const c=THn(a,t);if(!c)continue;const l=a.positioned_relative_to_pcb_group_id??a.pcb_group_id,u=l?B9(t).pcb_group.get(l):null;s.push({component:a,bbox:c,group:u})}return s.length===0?null:G.jsx("div",{style:{position:"absolute",left:0,top:0,width:r,height:i,overflow:"hidden",pointerEvents:"none",zIndex:Wl.dimensionOverlay},children:G.jsx("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none"},width:r,height:i,children:s.map(({component:a,bbox:c,group:l})=>{const u=mt(n,{x:c.minX,y:c.maxY}),d=mt(n,{x:c.maxX,y:c.minY}),h={x:Math.min(u.x,d.x),y:Math.min(u.y,d.y),width:Math.abs(d.x-u.x),height:Math.abs(d.y-u.y)},f=a.center??{x:(c.minX+c.maxX)/2,y:(c.minY+c.maxY)/2},p=mt(n,f);return G.jsxs("g",{children:[G.jsx("rect",{x:h.x,y:h.y,width:h.width,height:h.height,fill:"none",stroke:"white",strokeWidth:1.5,strokeDasharray:"4,4"}),G.jsx("line",{x1:p.x-6,y1:p.y,x2:p.x+6,y2:p.y,stroke:U2.COMPONENT_MARKER_STROKE,strokeWidth:1.5}),G.jsx("line",{x1:p.x,y1:p.y-6,x2:p.x,y2:p.y+6,stroke:U2.COMPONENT_MARKER_STROKE,strokeWidth:1.5}),G.jsx("circle",{cx:p.x,cy:p.y,r:Cu.COMPONENT_MARKER_RADIUS,fill:U2.COMPONENT_MARKER_FILL,stroke:U2.COMPONENT_MARKER_STROKE,strokeWidth:1})]},a.pcb_component_id)})})})},CHn=({elements:t,highlightedPrimitives:e,transform:n,containerWidth:r,containerHeight:i})=>{const o=t.filter(f=>wHn(f)),s=t.filter(f=>j_e(f)),a=e.map(f=>j_e(f._element)?f._element.pcb_board_id:null).filter(f=>!!f);if(!E0(f=>f.is_showing_group_anchor_offsets)&&a.length===0)return null;const l=s.map(f=>{const p=f.pcb_panel_id,m=f.position_mode;if(!p||m!=="relative_to_panel_anchor")return null;const g=o.find(y=>y.pcb_panel_id===p);return g?{board:f,panel:g,type:"board"}:null}).filter(f=>!!f);if(l.length===0)return null;const u=a.length===0,d=l.filter(f=>u||a.includes(f.board.pcb_board_id));if(d.length===0)return null;const h=d.map(f=>f.board.center?{id:`${f.panel.pcb_panel_id}-${f.board.pcb_board_id}-${f.type}`,anchor:f.panel.center,anchor_id:f.panel.pcb_panel_id,target:f.board.center,type:"board",display_offset_x:f.board.display_offset_x,display_offset_y:f.board.display_offset_y}:null).filter(f=>!!f);return G.jsx(U_e,{targets:h,transform:n,containerWidth:r,containerHeight:i})},fG=t=>{if(t.length===0)return null;let e=t[0].x,n=t[0].y,r=t[0].x,i=t[0].y;for(const o of t)o.x<e&&(e=o.x),o.y<n&&(n=o.y),o.x>r&&(r=o.x),o.y>i&&(i=o.y);return{center:{x:(e+r)/2,y:(n+i)/2},width:r-e,height:i-n}},t0t=(t,e)=>{if(e.length<3)return!1;let n=!1;for(let r=0,i=e.length-1;r<e.length;i=r++){const o=e[r].x,s=e[r].y,a=e[i].x,c=e[i].y;s>t.y!=c>t.y&&t.x<(a-o)*(t.y-s)/(c-s||Number.EPSILON)+o&&(n=!n)}return n},PHn=(t,e,n)=>{const r=[];for(const i of t){if(!i._element)continue;if("x1"in i&&i._element?.type==="pcb_trace"){const a=qm({x:e.x,y:e.y},{x:i.x1,y:i.y1},{x:i.x2,y:i.y2}),c=i.width||.5,l=Math.max(c*25,2)/n.a;a<l&&r.push(i);continue}if(i.pcb_drawing_type==="polygon"){const a=i.points.map(l=>({x:gn.parse(l.x),y:gn.parse(l.y)})),c=fG(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;t0t(e,a)&&r.push(i);continue}if(i.pcb_drawing_type==="polygon_with_arcs"){const a=i.brep_shape.outer_ring.vertices.map(l=>({x:gn.parse(l.x),y:gn.parse(l.y)})),c=fG(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;t0t(e,a)&&r.push(i);continue}if(!("x"in i&&"y"in i))continue;let o=0,s=0;if("w"in i&&"h"in i)o=i.w,s=i.h;else if("r"in i)o=i.r*2,s=i.r*2;else if("rX"in i&&"rY"in i)o=i.rX*2,s=i.rY*2;else continue;Math.abs(i.x-e.x)<o/2&&Math.abs(i.y-e.y)<s/2&&r.push(i)}return r},AHn=({elements:t,children:e,transform:n,primitives:r,onMouseHoverOverPrimitives:i})=>{const[o,s]=te.useState([]),[a,c]=te.useState({x:0,y:0}),[l,{width:u,height:d}]=gO(),h=te.useMemo(()=>{const p=[];for(const m of o){if(m._element?.type==="pcb_via"||m._element?.type==="pcb_component"||m?.layer==="drill"||m?.is_hoverable===!1)continue;let g=null,y=0,_=0;if(m.pcb_drawing_type==="polygon"){const S=fG(m.points);if(!S)continue;g=S.center,y=S.width,_=S.height}else if(m.pcb_drawing_type==="polygon_with_arcs"){const S=m.brep_shape.outer_ring.vertices.map(C=>({x:C.x,y:C.y})),T=fG(S);if(!T)continue;g=T.center,y=T.width,_=T.height}else"x"in m&&"y"in m&&(g={x:m.x,y:m.y},y="w"in m?m.w:"r"in m?m.r*2:"rX"in m&&"rY"in m?m.rX*2:0,_="h"in m?m.h:"r"in m?m.r*2:"rX"in m&&"rY"in m?m.rY*2:0);if(!g)continue;const x=mt(n,g),b={w:y*n.a,h:_*n.a},w=p.filter(S=>x.x===S.screen_x&&x.y===S.screen_y&&b.w===S.screen_w&&b.h===S.screen_h).length;p.push({...m,x:g.x,y:g.y,w:y,h:_,screen_x:x.x,screen_y:x.y,screen_w:b.w,screen_h:b.h,same_space_index:w})}return p},[o,n]),f=(p,m,g,y)=>{c({x:p,y:m});const _=mt(Bx(g),{x:p,y:m}),x=PHn(y,_,g);fHn(new Set(x.map(b=>b._pcb_drawing_object_id)),new Set(o.map(b=>b._pcb_drawing_object_id)))||(s(x),i(x))};return G.jsxs("div",{ref:l,style:{position:"relative",width:"100%",height:"100%"},onMouseMove:p=>{if(n){const m=p.currentTarget.getBoundingClientRect(),g=p.clientX-m.left,y=p.clientY-m.top;f(g,y,n,r)}},onTouchStart:p=>{if(n){const m=p.touches[0],g=p.currentTarget.getBoundingClientRect(),y=m.clientX-g.left,_=m.clientY-g.top;f(y,_,n,r)}},children:[e,G.jsx(vHn,{elements:t,mousePos:a,highlightedPrimitives:h}),n&&G.jsxs(G.Fragment,{children:[G.jsx(SHn,{elements:t,highlightedPrimitives:h,transform:n,containerWidth:u,containerHeight:d}),G.jsx(MHn,{elements:t,highlightedPrimitives:h,transform:n,containerWidth:u,containerHeight:d}),G.jsx(EHn,{elements:t,highlightedPrimitives:h,transform:n,containerWidth:u,containerHeight:d}),G.jsx(CHn,{elements:t,highlightedPrimitives:h,transform:n,containerWidth:u,containerHeight:d})]})]})},n0t=["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)"],RHn=({children:t,transform:e=el(),elements:n=[],hoveredComponentIds:r=[]})=>{const[i,{width:o,height:s}]=gO(),a=te.useRef(null),{is_showing_pcb_groups:c,pcb_group_view_mode:l,is_showing_group_anchor_offsets:u}=E0(d=>({is_showing_pcb_groups:d.is_showing_pcb_groups,pcb_group_view_mode:d.pcb_group_view_mode,is_showing_group_anchor_offsets:d.is_showing_group_anchor_offsets}));return te.useEffect(()=>{const d=a.current;if(!d||!o||!s)return;d.width=o,d.height=s;const h=d.getContext("2d");if(!h||(h.clearRect(0,0,o,s),!c))return;const f=n.filter(S=>S.type==="pcb_group"),p=n.filter(S=>S.type==="pcb_component"),m=n.filter(S=>S.type==="source_group"),g=new Map(m.map(S=>[S.source_group_id,S])),y=f.filter(S=>{if(S.name?.toLowerCase().includes("subpanel"))return!1;if(l==="all")return!0;if(!S.source_group_id)return!1;const T=g.get(S.source_group_id);return T?T.was_automatically_named!==!0:!1}),_=new Map;m.forEach(S=>{const T=S;if(T.parent_source_group_id){const C=_.get(T.parent_source_group_id)||[];C.push(S.source_group_id),_.set(T.parent_source_group_id,C)}});const x=S=>{const T=[],C=_.get(S)||[];for(const A of C)T.push(A),T.push(...x(A));return T},b=S=>{const T=m.find(C=>C.source_group_id===S);return T?.parent_source_group_id?1+b(T.parent_source_group_id):0},w=new Set;if(r.length>0)for(const S of p){if(!r.includes(S.pcb_component_id))continue;const T=S.positioned_relative_to_pcb_group_id??S.pcb_group_id;T&&w.add(T)}y.forEach((S,T)=>{let C=p.filter(Ne=>Ne.pcb_group_id===S.pcb_group_id);if(S.source_group_id){const Ne=x(S.source_group_id),Ue=f.filter(Ie=>Ie.source_group_id&&Ne.includes(Ie.source_group_id));for(const Ie of Ue){const we=p.filter(Ee=>Ee.pcb_group_id===Ie.pcb_group_id);C=[...C,...we]}}let A,R,L,O,F=!1;if(S.center&&S.width&&S.height){F=!0;const Ne=S.width/2,Ue=S.height/2;A=S.center.x-Ne,L=S.center.x+Ne,R=S.center.y-Ue,O=S.center.y+Ue}else if(C.length===0||(A=1/0,R=1/0,L=-1/0,O=-1/0,C.forEach(Ne=>{if(Ne.center&&typeof Ne.width=="number"&&typeof Ne.height=="number"){const Ue=Ne.center.x-Ne.width/2,Ie=Ne.center.x+Ne.width/2,we=Ne.center.y+Ne.height/2,Ee=Ne.center.y-Ne.height/2;A=Math.min(A,Ue),L=Math.max(L,Ie),R=Math.min(R,Ee),O=Math.max(O,we)}}),A===1/0||L===-1/0))return;const B=S.source_group_id?b(S.source_group_id):0,j=S.source_group_id?x(S.source_group_id).length>0:!1;if(!F){const Ie=1+(j?.5:0);A-=Ie,L+=Ie,R-=Ie,O+=Ie}const V=mt(e,{x:A,y:O}),q=mt(e,{x:L,y:O}),K=mt(e,{x:A,y:R}),ne=mt(e,{x:L,y:R}),le=n0t[T%n0t.length];h.strokeStyle=le,h.lineWidth=2;const ee=Math.max(4,Math.min(12,8*Math.abs(e.a))),ie=Math.max(2,Math.min(6,4*Math.abs(e.a))),ue=ee*(j?1.3:1),_e=ie;h.setLineDash([ue,_e]),h.beginPath(),h.moveTo(V.x,V.y),h.lineTo(q.x,q.y),h.lineTo(ne.x,ne.y),h.lineTo(K.x,K.y),h.closePath(),h.stroke();const Ce=Math.max(8,Math.min(12,10*Math.abs(e.a))),Ae=B==0||B==1?0:B*.11,ke=Ce*(1-Ae),ye=4,Me=S.name||`Group ${T+1}`;h.font=`${ke}px sans-serif`,h.setLineDash([]);const Ye=h.measureText(Me).width+ye*2,He=ke+ye*2,We=V.x-5,ge=V.y-5,Ke=3;if(h.fillStyle="rgba(0, 0, 0, 0.8)",h.beginPath(),h.roundRect(We,ge-He,Ye,He,Ke),h.fill(),h.fillStyle=le,h.textAlign="left",h.textBaseline="middle",h.fillText(Me,We+ye,ge-He/2),u&&w.has(S.pcb_group_id)&&!!S.anchor_position&&S.anchor_position){const Ne=Array.isArray(S.anchor_position)?{x:S.anchor_position[0]??0,y:S.anchor_position[1]??0}:{x:S.anchor_position.x,y:S.anchor_position.y},Ue=mt(e,Ne);h.strokeStyle="white",h.lineWidth=1.5,h.setLineDash([]);const Ie=Math.max(4,Math.min(8,6*Math.abs(e.a)));h.beginPath(),h.moveTo(Ue.x-Ie,Ue.y),h.lineTo(Ue.x+Ie,Ue.y),h.stroke(),h.beginPath(),h.moveTo(Ue.x,Ue.y-Ie),h.lineTo(Ue.x,Ue.y+Ie),h.stroke()}})},[n,e,o,s,c,l,u,r]),G.jsxs("div",{ref:i,style:{position:"relative",width:"100%",height:"100%"},children:[t,G.jsx("canvas",{ref:a,style:{position:"absolute",top:0,left:0,pointerEvents:"none",zIndex:Wl.pcbGroupOverlay,display:c?"block":"none"}})]})},IHn=({transform:t,soup:e,children:n})=>{const r=E0(a=>a.is_showing_rats_nest),{netMap:i,idToNetMap:o}=te.useMemo(()=>kut(e||[]),[e]),s=te.useMemo(()=>{if(!e||!r)return[];const a=h=>{const f=B9(e)[h.replace(/_\d+$/,"")].get(h);return f&&"x"in f&&"y"in f?{x:f.x,y:f.y}:null},c=(h,f)=>{const p=i[f]||[];let m=null,g=1/0;return p.forEach(y=>{const _=a(y);if(_){const x=Math.sqrt((h.x-_.x)**2+(h.y-_.y)**2);x<g&&x>0&&(g=x,m=_)}}),m},l=B9(e).pcb_port.list(),u=B9(e).source_trace.list(),d=[];return l.forEach((h,f)=>{const p=o[h.pcb_port_id];let m=!1;for(const _ of u)_.connected_source_port_ids.includes(h.source_port_id)&&_.connected_source_net_ids.length>0&&(m=!0);if(!p)return;const g={x:h.x,y:h.y},y=c(g,p);y&&d.push({key:`${h.pcb_port_id}-${f}`,startPoint:g,endPoint:y,isInNet:m})}),d},[e,i,o,r]);return!e||!r?n:(t||(t=el()),G.jsxs("div",{style:{position:"relative"},children:[n,G.jsx("svg",{style:{position:"absolute",left:0,top:0,width:"100%",height:"100%",pointerEvents:"none",opacity:.5,zIndex:Wl.ratsNestOverlay},children:s.map(({key:a,startPoint:c,endPoint:l,isInNet:u})=>{const d=mt(t,c),h=mt(t,l);return G.jsx("line",{x1:d.x,y1:d.y,x2:h.x,y2:h.y,stroke:"white",strokeWidth:"1",strokeDasharray:u?"6,6":void 0},a)})})]}))},NHn={version:"1.11.361"},T8=(t,e,n)=>{const r=E0(s=>s.is_mouse_over_container),i=te.useRef(r),o=te.useRef(e);te.useEffect(()=>{i.current=r},[r]),te.useEffect(()=>{o.current=e},[e]),te.useEffect(()=>{if(!t)return;const s=a=>{const c=a.target;if(c.tagName==="INPUT"||c.tagName==="TEXTAREA"||c.isContentEditable)return;const l=t.split("+"),u=l.includes("ctrl"),d=l.includes("shift"),h=l.includes("alt"),f=l.includes("meta"),p=l[l.length-1],m=n?.current?n.current.contains(document.activeElement)||document.activeElement===n.current:!1;(i.current||m)&&(!u||a.ctrlKey)&&(!d||a.shiftKey)&&(!h||a.altKey)&&(!f||a.metaKey)&&a.key.toLowerCase()===p.toLowerCase()&&(a.preventDefault(),o.current())};return window.addEventListener("keydown",s),()=>{window.removeEventListener("keydown",s)}},[t])},kHn=()=>{const[t,e]=te.useState(!1);return te.useEffect(()=>{const n=()=>{e(window.innerWidth<=768)};return n(),window.addEventListener("resize",n),()=>window.removeEventListener("resize",n)},[]),t},xO=(t,e={stopPropagation:!0})=>{const n=te.useRef(0),r=te.useCallback(s=>{e.stopPropagation&&s.stopPropagation();const a=Date.now();a-n.current<300||(n.current=a,t?.(s))},[t,e.stopPropagation]),i=te.useCallback(s=>{s.preventDefault(),r(s)},[r]);return{onClick:r,onTouchEnd:i,style:{touchAction:"manipulation"}}},RS=({children:t,isSmallScreen:e,onClick:n,...r})=>{const{style:i,...o}=xO(n);return G.jsx("div",{...r,...o,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,...r.style},children:t})},OHn=({errorId:t,errorMessage:e,copiedErrorId:n,onCopy:r})=>{const{style:i,...o}=xO(()=>r(e,t));return G.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},...o,children:n===t?G.jsx("span",{style:{color:"#4caf50",fontSize:12},children:"Copied!"}):G.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"currentColor",children:G.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"})})})},LHn=({elements:t,isOpen:e,isSmallScreen:n,onToggle:r,setHoveredErrorId:i})=>{const[o,s]=te.useState(null),[a,c]=te.useState(new Set),[l,u]=te.useState(new Set),[,d]=kjn(),h=te.useMemo(()=>t?.filter(_=>_.type.includes("error"))??[],[t]),f=h.length,p=te.useCallback((_,x)=>_.pcb_trace_error_id||`error_${x}_${_.error_type}_${_.message?.slice(0,20)}`,[]),m=te.useMemo(()=>{const _=new Map;return h.forEach((x,b)=>{const w=x.error_type||"unknown_error",S=_.get(w)||[];S.push({error:x,index:b,errorId:p(x,b)}),_.set(w,S)}),Array.from(_.entries()).map(([x,b])=>({errorType:x,errors:b}))},[h,p]),g=te.useCallback(_=>{c(x=>{const b=new Set(x);return b.has(_)?b.delete(_):b.add(_),b})},[]),y=te.useCallback(_=>{u(x=>{const b=new Set(x);return b.has(_)?b.delete(_):b.add(_),b})},[]);return G.jsxs("div",{style:{position:"relative"},children:[G.jsx(RS,{isSmallScreen:n,style:f>0?{color:"red"}:void 0,onClick:r,children:G.jsxs("div",{children:[f," errors"]})}),e&&f>0&&G.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:m.map(({errorType:_,errors:x},b)=>{const w=a.has(_);return G.jsxs("div",{style:{borderBottom:b<m.length-1?"1px solid #444":"none"},children:[G.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:S=>{S.currentTarget.style.backgroundColor="#303030"},onMouseLeave:S=>{S.currentTarget.style.backgroundColor="#232323"},onTouchStart:S=>{S.stopPropagation(),S.currentTarget.style.backgroundColor="#303030"},onTouchEnd:S=>{S.stopPropagation(),S.preventDefault(),S.currentTarget.style.backgroundColor="#232323",g(_)},onClick:S=>{S.stopPropagation(),g(_)},children:[G.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,color:"#ff6b6b"},children:[G.jsx("div",{style:{color:"#888",fontSize:"16px",transform:w?"rotate(90deg)":"rotate(0deg)",transition:"transform 0.2s ease",flexShrink:0},children:"›"}),G.jsx("div",{style:{fontWeight:"bold",fontSize:n?"12px":"13px"},children:_})]}),G.jsx("div",{style:{fontSize:n?"12px":"13px",color:"#aaa",whiteSpace:"nowrap",marginLeft:12},children:x.length})]}),!w&&x.map(({error:S,index:T,errorId:C})=>{const A=l.has(C),R=S.message??"No error message";return G.jsxs("div",{style:{borderTop:"1px solid #3a3a3a"},children:[G.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:L=>{L.currentTarget.style.backgroundColor="#333",i(C)},onMouseLeave:L=>{L.currentTarget.style.backgroundColor="#2a2a2a",i(null)},onTouchStart:L=>{L.stopPropagation(),L.currentTarget.style.backgroundColor="#333",i(C)},onTouchEnd:L=>{L.stopPropagation(),L.preventDefault(),L.currentTarget.style.backgroundColor="#2a2a2a",i(null),y(C)},onClick:L=>{L.stopPropagation(),y(C)},children:[G.jsx("div",{style:{flex:1,fontSize:n?"12px":"13px",color:"#ddd",lineHeight:1.4,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",userSelect:"text"},onMouseDown:L=>L.stopPropagation(),onClick:L=>L.stopPropagation(),children:R}),G.jsx("div",{style:{color:"#888",fontSize:"16px",transform:A?"rotate(0deg)":"rotate(90deg)",transition:"transform 0.2s ease",flexShrink:0},children:"›"})]}),A&&G.jsxs("div",{"data-error-id":T,style:{display:"block",padding:"12px 16px 12px 24px",backgroundColor:"#1a1a1a",borderTop:"1px solid #444",position:"relative"},children:[G.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:L=>L.stopPropagation(),onClick:L=>L.stopPropagation(),children:R}),G.jsx(OHn,{errorId:C,errorMessage:R,copiedErrorId:o,onCopy:(L,O)=>{d(L),s(O),setTimeout(()=>s(null),2e3)}})]})]},C)})]},_)})})]})},DHn=({name:t,selected:e,onClick:n})=>{const{style:r,...i}=xO(n);return G.jsxs("div",{className:vP`
5457
+ `,pHn=({children:t,transform:e=el(),elements:n})=>{const r=te.useRef(null),{isShowingDRCErrors:i,hoveredErrorId:o}=E0(l=>({isShowingDRCErrors:l.is_showing_drc_errors,hoveredErrorId:l.hovered_error_id}));if(!n)return G.jsx("div",{style:{position:"relative"},ref:r,children:t});const s=n.filter(l=>l.type==="pcb_trace_error"),a=n.filter(l=>l.type==="pcb_trace_error"&&l.message?.includes("Multiple components found with name")),c=new Map;return n.forEach(l=>{l.type==="pcb_port"&&c.set(l.pcb_port_id,l)}),G.jsxs("div",{style:{position:"relative"},ref:r,children:[t,s.map((l,u)=>{const{pcb_port_ids:d,pcb_trace_id:h}=l,f=d?.[0]?c.get(d[0]):void 0,p=d?.[1]?c.get(d[1]):void 0,m=n?B9(n).pcb_trace.get(h):void 0,g=l.pcb_trace_error_id||`error_${u}_${l.error_type}_${l.message?.slice(0,20)}`,y=o===g;if(f&&p){const _=mt(e,{x:f.x,y:f.y}),x=mt(e,{x:p.x,y:p.y});if(!i)return null;const b=!(isNaN(_.x)||isNaN(_.y)||isNaN(x.x)||isNaN(x.y)),w={x:(_.x+x.x)/2,y:(_.y+x.y)/2};if(isNaN(w.x)||isNaN(w.y))return null;const S=F_e(w,r);return G.jsxs(te.Fragment,{children:[G.jsx(dHn,{screenPort1:_,screenPort2:x,errorCenter:w,canLineBeDrawn:b,isHighlighted:y}),G.jsx("div",{style:{position:"absolute",left:w.x-15,top:w.y-15,width:30,height:30,zIndex:Wl.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:T=>{const C=T.currentTarget.nextElementSibling;if(C){const A=C.querySelector(".error-message");A&&(A.style.opacity="1")}},onMouseLeave:T=>{if(!y){const C=T.currentTarget.nextElementSibling;if(C){const A=C.querySelector(".error-message");A&&(A.style.opacity="0")}}}}),G.jsx("div",{style:{position:"absolute",zIndex:y?200:100,left:S.left,top:S.top,color:y?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:i||y?"flex":"none",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:S.transform},children:G.jsx("div",{className:`error-message ${B_e}`,style:{opacity:y?1:0,border:`1px solid ${y?"#ff4444":"red"}`},children:l.message})})]},g)}if(m?.route&&(i||y)){const _=m.route.map(S=>mt(e,{x:S.x,y:S.y}));if(_.some(S=>isNaN(S.x)||isNaN(S.y)))return null;const x=Math.floor(_.length/2),b=_[x],w=F_e(b,r);return G.jsxs(te.Fragment,{children:[G.jsx(hHn,{points:_,errorCenter:b,isHighlighted:y}),G.jsx("div",{style:{position:"absolute",left:b.x-15,top:b.y-15,width:30,height:30,zIndex:Wl.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:S=>{const T=S.currentTarget.nextElementSibling;if(T){const C=T.querySelector(".error-message");C&&(C.style.opacity="1")}},onMouseLeave:S=>{if(!y){const T=S.currentTarget.nextElementSibling;if(T){const C=T.querySelector(".error-message");C&&(C.style.opacity="0")}}}}),G.jsx("div",{style:{position:"absolute",zIndex:y?Wl.errorOverlay+10:Wl.errorOverlay+1,left:w.left,top:w.top,color:y?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:"flex",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:w.transform},children:G.jsx("div",{className:`error-message ${B_e}`,style:{opacity:y?1:0,border:`1px solid ${y?"#ff4444":"red"}`},children:l.message})})]},g)}return null}),a.map((l,u)=>{const d=l.component_name||l.message?.match(/name "([^"]+)"/)?.[1];if(!d)return null;const h=n?.filter(m=>m.type==="source_component"&&m.name===d||m.type==="pcb_component"&&n?.find(g=>g.type==="source_component"&&g.source_component_id===m.source_component_id&&g.name===d))||[],f=l.pcb_trace_error_id||`error_${u}_${l.error_type}_${l.message?.slice(0,20)}`,p=o===f;return!p&&!i?null:h.map((m,g)=>{let y={x:0,y:0};if(m.type==="pcb_component")y=m.center||{x:0,y:0};else if(m.type==="source_component"){const A=n?.find(R=>R.type==="pcb_component"&&R.source_component_id===m.source_component_id);A&&A.type==="pcb_component"&&(y=A.center||{x:0,y:0})}const _=mt(e,y);if(isNaN(_.x)||isNaN(_.y))return null;const x=Math.abs(e.a),T=Math.max(8,Math.min(30,.5*x)),C=F_e(_,r);return G.jsxs(te.Fragment,{children:[G.jsx("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none",mixBlendMode:"difference",zIndex:Wl.errorOverlay},width:"100%",height:"100%",children:p?G.jsx("polygon",{points:`${_.x},${_.y-T*1.25} ${_.x+T},${_.y} ${_.x},${_.y+T*1.25} ${_.x-T},${_.y}`,fill:"#ff4444"}):G.jsx("circle",{cx:_.x,cy:_.y,r:T,fill:"none",stroke:p?"#ff4444":"red",strokeWidth:p?Math.max(2,T*.15):Math.max(1,T*.1),opacity:1})}),G.jsx("div",{style:{position:"absolute",left:_.x-(T+10),top:_.y-(T+10),width:(T+10)*2,height:(T+10)*2,zIndex:Wl.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:A=>{const R=A.currentTarget.nextElementSibling;if(R){const L=R.querySelector(".error-message");L&&(L.style.opacity="1")}},onMouseLeave:A=>{if(!p){const R=A.currentTarget.nextElementSibling;if(R){const L=R.querySelector(".error-message");L&&(L.style.opacity="0")}}}}),G.jsx("div",{style:{position:"absolute",zIndex:p?Wl.errorOverlay+20:Wl.errorOverlay+10,left:C.left,top:C.top,color:p?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:i||p?"flex":"none",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:C.transform},children:G.jsx("div",{className:`error-message ${B_e}`,style:{opacity:p?1:0,border:`1px solid ${p?"#ff4444":"red"}`},children:l.message})})]},`${f}_${g}`)})})]})};function fHn(t,e){return t.size!==e.size?!1:Array.from(t).every(n=>e.has(n))}function mHn({primitiveElement:t,elements:e}){let n=t.trace_length?`${t.trace_length.toFixed(3)}`:"";const r=B9(e).source_trace.get(t?.source_trace_id);if(r?.display_name&&(r?.max_length?n+=` / ${r.max_length}mm `:n+=" mm ",n+=`(${r.display_name})`),!n)return null;const i=t.trace_length&&r?.max_length&&t.trace_length>r.max_length;return{text:n,isOverLength:i}}function yHn(t){const{primitives:e,is_showing_multiple_traces_length:n,elements:r}=t,i=e.filter(c=>c._element.type==="pcb_trace"),o=r.filter(c=>c.type==="source_trace"),s=e.filter(c=>c._element.type!=="pcb_trace"),a=i.filter(c=>o.some(l=>c._element.type==="pcb_trace"&&c._element.source_trace_id===l.source_trace_id&&l.max_length!==void 0));if(!n)return[...s,...a];if(i.length>1){const c=i.reduce((l,u)=>{const d=l._element.trace_length;return u._element.trace_length<d?u:l},i[0]);return[...s,c]}return e}var gHn={position:"absolute",left:0,top:0,pointerEvents:"none",color:"red",fontFamily:"sans-serif",fontSize:12,textShadow:"0 0 2px black"},_Hn=t=>{const{_element:e,_parent_pcb_component:n,_parent_source_component:r,_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 o=[],s=Array.from(new Set((e.port_hints??[]).concat(i?.port_hints??[]))).filter(c=>!/^[0-9]+$/.test(c)).filter(c=>!c.includes("unnamed_")).sort((c,l)=>l.localeCompare(c)),a=r&&"name"in r&&r.name&&!r.name.includes("unnamed_")?r.name:null;return s.length>0?a?o.push(...s.map(c=>`${a}.${c}`)):o.push(...s):a&&o.push(a),o.join(", ")}default:return""}},xHn={top:"red",bottom:"aqua"},bHn=({primitive:t,mousePos:e,elements:n})=>{const[r,i]=te.useState(!1),o=t._element;te.useEffect(()=>{setTimeout(()=>{i(!0)},100)},[]);const[s,a,c,l]=[t.screen_x,t.screen_y,t.screen_w,t.screen_h],u=t.same_space_index??0,d=26,h=xHn[t?._element?.layer]??"red";let f=0;if(o.type==="pcb_smtpad"&&o?.shape==="rotated_rect"?f=o?.ccw_rotation??0:(o.type==="pcb_smtpad"&&(o?.shape==="pill"||o?.shape==="rotated_pill")&&"ccw_rotation"in t||o.type==="pcb_plated_hole"&&(o?.shape==="pill"||o?.shape==="oval")&&"ccw_rotation"in t)&&(f=o.ccw_rotation??0),o.type==="pcb_trace"){const g=mHn({primitiveElement:o,elements:n});if(!g)return null;const y=e.y-35;return G.jsx("div",{style:{zIndex:Wl.elementOverlay,position:"absolute",left:e.x,top:y,color:h,pointerEvents:"none",transform:"translateX(-50%)"},children:G.jsx("div",{style:{backgroundColor:"#f2efcc",color:g.isOverLength?"red":"black",textShadow:"none",WebkitFontSmoothing:"antialiased",MozOsxFontSmoothing:"grayscale",padding:"6px 6px",borderRadius:"6px",fontSize:"14px",minWidth:"45px",textAlign:"center",whiteSpace:"nowrap"},children:g.text})})}const p=_Hn(t);return p.trim().length===0?null:G.jsx("div",{style:{zIndex:Wl.elementOverlay,position:"absolute",left:s-c/2-8,top:a-l/2-8,width:c+16,height:l+16,color:h,transform:`rotate(${-f}deg)`,transformOrigin:"center center"},children:G.jsx("div",{style:{width:r?`calc(100% + ${d*2*u}px)`:"100%",height:r?`calc(100% + ${d*2*u}px)`:"100%",marginLeft:r?`${-d*u}px`:0,marginTop:r?`${-d*u}px`:0,border:`1px solid ${h}`,opacity:r||u===0?1:0,transition:"width 0.2s, height 0.2s, margin-left 0.2s, margin-top 0.2s, opacity 0.2s"},children:G.jsx("div",{style:{position:"absolute",bottom:l+20+d*u,marginRight:r?`${-d*u}px`:0,marginBottom:r?0:-d*u,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(${f}deg)`,minWidth:"45px",textAlign:"center"},children:p})})})},vHn=({highlightedPrimitives:t,mousePos:e,elements:n})=>{const[r,i]=E0(a=>[a.is_moving_component,a.is_showing_multiple_traces_length]),o=t.some(a=>a._element.type==="pcb_smtpad")&&t.some(a=>a._element.type==="pcb_trace");let s=t;return o&&(s=s.filter(a=>a._element.type==="pcb_smtpad")),s=yHn({primitives:s,is_showing_multiple_traces_length:i,elements:n}),G.jsx("div",{style:gHn,children:!r&&s.map((a,c)=>G.jsx(bHn,{primitive:a,mousePos:e,elements:n},c))})},M8=t=>t?.type==="pcb_component",e0t=t=>t?.type==="pcb_group",wHn=t=>t?.type==="pcb_panel",j_e=t=>t?.type==="pcb_board",Cu={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},U2={OFFSET_LINE:"white",COMPONENT_MARKER_FILL:"#66ccff",COMPONENT_MARKER_STROKE:"white",LABEL_TEXT:"white"},U_e=({targets:t,transform:e,containerWidth:n,containerHeight:r})=>{if(t.length===0)return null;const i={color:U2.LABEL_TEXT,mixBlendMode:"difference",pointerEvents:"none",fontSize:Cu.LABEL_FONT_SIZE,fontFamily:"monospace",fontWeight:"bold"},o=new Map;return t.forEach(s=>{if(!o.has(s.anchor_id)){const a=mt(e,s.anchor);o.set(s.anchor_id,a)}}),G.jsx("div",{style:{position:"absolute",left:0,top:0,width:n,height:r,overflow:"hidden",pointerEvents:"none",zIndex:Wl.dimensionOverlay},children:G.jsxs("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none"},width:n,height:r,children:[t.map(s=>{const a=s.anchor,c=s.anchor_id,l=s.target,u=o.get(c),d=mt(e,l),h=l.x-a.x,f=l.y-a.y,p=Math.abs(d.x-u.x),m=Math.abs(d.y-u.y),g=d.y<u.y,y=d.x>u.x,_=g?Cu.LABEL_OFFSET_ABOVE:Cu.LABEL_OFFSET_BELOW,x=y?Cu.LABEL_OFFSET_RIGHT:Cu.LABEL_OFFSET_LEFT,b=p>Cu.MIN_LINE_LENGTH_FOR_LABEL,w=m>Cu.MIN_LINE_LENGTH_FOR_LABEL,S=`${s.display_offset_x??h.toFixed(2)}mm`,T=`${s.display_offset_y??f.toFixed(2)}mm`;return G.jsxs("g",{children:[G.jsx("line",{x1:u.x,y1:u.y,x2:d.x,y2:u.y,stroke:U2.OFFSET_LINE,strokeWidth:Cu.LINE_STROKE_WIDTH,strokeDasharray:Cu.LINE_DASH_PATTERN}),G.jsx("line",{x1:d.x,y1:u.y,x2:d.x,y2:d.y,stroke:U2.OFFSET_LINE,strokeWidth:Cu.LINE_STROKE_WIDTH,strokeDasharray:Cu.LINE_DASH_PATTERN}),s.type==="component"||s.type==="board"?G.jsx("circle",{cx:d.x,cy:d.y,r:Cu.COMPONENT_MARKER_RADIUS,fill:U2.COMPONENT_MARKER_FILL,stroke:U2.COMPONENT_MARKER_STROKE,strokeWidth:1}):G.jsxs(G.Fragment,{children:[G.jsx("line",{x1:d.x-Cu.ANCHOR_MARKER_SIZE,y1:d.y,x2:d.x+Cu.ANCHOR_MARKER_SIZE,y2:d.y,stroke:U2.OFFSET_LINE,strokeWidth:Cu.ANCHOR_MARKER_STROKE_WIDTH}),G.jsx("line",{x1:d.x,y1:d.y-Cu.ANCHOR_MARKER_SIZE,x2:d.x,y2:d.y+Cu.ANCHOR_MARKER_SIZE,stroke:U2.OFFSET_LINE,strokeWidth:Cu.ANCHOR_MARKER_STROKE_WIDTH})]}),b&&G.jsx("foreignObject",{x:Math.min(u.x,d.x),y:u.y+_,width:Math.abs(d.x-u.x),height:20,style:{overflow:"visible"},children:G.jsx("div",{style:{...i,textAlign:"center"},children:S})}),w&&G.jsx("foreignObject",{x:d.x+x,y:Math.min(u.y,d.y),width:Cu.Y_LABEL_MIN_WIDTH,height:Math.abs(d.y-u.y),style:{overflow:"visible"},children:G.jsx("div",{style:{...i,display:"flex",alignItems:"center",justifyContent:y?"flex-start":"flex-end",whiteSpace:"nowrap",padding:"0 4px",height:"100%"},children:T})})]},s.id)}),Array.from(o.entries()).map(([s,a])=>G.jsxs("g",{children:[G.jsx("line",{x1:a.x-Cu.ANCHOR_MARKER_SIZE,y1:a.y,x2:a.x+Cu.ANCHOR_MARKER_SIZE,y2:a.y,stroke:U2.OFFSET_LINE,strokeWidth:Cu.ANCHOR_MARKER_STROKE_WIDTH}),G.jsx("line",{x1:a.x,y1:a.y-Cu.ANCHOR_MARKER_SIZE,x2:a.x,y2:a.y+Cu.ANCHOR_MARKER_SIZE,stroke:U2.OFFSET_LINE,strokeWidth:Cu.ANCHOR_MARKER_STROKE_WIDTH})]},`anchor-${s}`))]})})},SHn=({elements:t,highlightedPrimitives:e,transform:n,containerWidth:r,containerHeight:i})=>{const o=t.filter(y=>j_e(y)),s=t.filter(y=>M8(y)),a=t.filter(y=>e0t(y)),c=e.map(y=>M8(y._parent_pcb_component)?y._parent_pcb_component.pcb_component_id:M8(y._element)?y._element.pcb_component_id:null).filter(y=>!!y),l=new Set;if(c.forEach(y=>{const _=s.find(x=>x.pcb_component_id===y);_?.pcb_group_id&&l.add(_.pcb_group_id)}),!E0(y=>y.is_showing_group_anchor_offsets)&&c.length===0)return null;const d=s.map(y=>{const _=y.positioned_relative_to_pcb_board_id;if(!_)return null;const x=o.find(b=>b.pcb_board_id===_);return x?{component:y,board:x,type:"component"}:null}).filter(y=>!!y),h=a.map(y=>{const _=y.positioned_relative_to_pcb_board_id;if(!_||!y.center)return null;const x=o.find(b=>b.pcb_board_id===_);return x?{group:y,board:x,type:"group"}:null}).filter(y=>!!y),f=[...d,...h];if(f.length===0)return null;const p=c.length===0,m=f.filter(y=>y.type==="component"?p||c.includes(y.component.pcb_component_id):p||l.has(y.group.pcb_group_id));if(m.length===0)return null;const g=m.map(y=>y.type==="component"?{id:`${y.board.pcb_board_id}-${y.component.pcb_component_id}-${y.type}`,anchor:y.board.center,anchor_id:y.board.pcb_board_id,target:y.component.center,type:"component",display_offset_x:y.component.display_offset_x,display_offset_y:y.component.display_offset_y}:{id:`${y.board.pcb_board_id}-${y.group.pcb_group_id}-${y.type}`,anchor:y.board.center,anchor_id:y.board.pcb_board_id,target:{x:y.group.anchor_position?.x??y.group.center.x,y:y.group.anchor_position?.y??y.group.center.y},type:"group",display_offset_x:y.group.display_offset_x,display_offset_y:y.group.display_offset_y}).filter(y=>!!y);return G.jsx(U_e,{targets:g,transform:n,containerWidth:r,containerHeight:i})},MHn=({elements:t,highlightedPrimitives:e,transform:n,containerWidth:r,containerHeight:i})=>{const o=t.filter(y=>e0t(y)),s=t.filter(y=>M8(y)),a=e.map(y=>M8(y._parent_pcb_component)?y._parent_pcb_component.pcb_component_id:M8(y._element)?y._element.pcb_component_id:null).filter(y=>!!y),c=(y,_)=>{if(_.has(y))return;_.add(y);const x=o.find(b=>b.pcb_group_id===y);x?.position_mode==="relative_to_group_anchor"&&x.positioned_relative_to_pcb_group_id&&c(x.positioned_relative_to_pcb_group_id,_)},l=new Set;if(a.forEach(y=>{const _=s.find(x=>x.pcb_component_id===y);_&&(_.position_mode==="relative_to_group_anchor"&&_.positioned_relative_to_pcb_group_id&&c(_.positioned_relative_to_pcb_group_id,l),_.pcb_group_id&&c(_.pcb_group_id,l))}),!E0(y=>y.is_showing_group_anchor_offsets)&&a.length===0)return null;const d=s.map(y=>{if(y.position_mode==="relative_to_group_anchor"&&y.positioned_relative_to_pcb_group_id){const _=o.find(x=>x.pcb_group_id===y.positioned_relative_to_pcb_group_id);return _&&_.anchor_position?{component:y,parentGroup:_,type:"component"}:null}if(y.pcb_group_id){const _=o.find(x=>x.pcb_group_id===y.pcb_group_id);return _&&_.anchor_position?{component:y,parentGroup:_,type:"component"}:null}return null}).filter(y=>!!y),h=o.map(y=>{if(y.position_mode==="relative_to_group_anchor"&&y.positioned_relative_to_pcb_group_id){const _=o.find(x=>x.pcb_group_id===y.positioned_relative_to_pcb_group_id);if(_&&_.anchor_position&&y.anchor_position)return{group:y,parentGroup:_,type:"group"}}return null}).filter(y=>!!y),f=[...d,...h];if(f.length===0)return null;const p=a.length===0,m=f.filter(y=>y.type==="component"?p||a.includes(y.component.pcb_component_id):p||l.has(y.group.pcb_group_id)||l.has(y.parentGroup.pcb_group_id));if(m.length===0)return null;const g=m.map(y=>{const _=y.parentGroup.anchor_position;return _?y.type==="component"?y.component.center?{id:`${y.parentGroup.pcb_group_id}-${y.component.pcb_component_id}-${y.type}`,anchor:_,anchor_id:y.parentGroup.pcb_group_id,target:y.component.center,type:"component",display_offset_x:y.component.display_offset_x,display_offset_y:y.component.display_offset_y}:null:y.group.anchor_position?{id:`${y.parentGroup.pcb_group_id}-${y.group.pcb_group_id}-${y.type}`,anchor:_,anchor_id:y.parentGroup.pcb_group_id,target:y.group.anchor_position,type:"group",display_offset_x:y.group.display_offset_x,display_offset_y:y.group.display_offset_y}:null:null}).filter(y=>!!y);return G.jsx(U_e,{targets:g,transform:n,containerWidth:r,containerHeight:i})},THn=(t,e)=>{const n=t.pcb_component_id,r=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 r.length===0?z_e([t]):z_e(r)},EHn=({elements:t,highlightedPrimitives:e,transform:n,containerWidth:r,containerHeight:i})=>{const o=new Map;for(const a of e)M8(a._parent_pcb_component)&&o.set(a._parent_pcb_component.pcb_component_id,a._parent_pcb_component),M8(a._element)&&o.set(a._element.pcb_component_id,a._element);if(o.size===0)return null;const s=[];for(const a of o.values()){const c=THn(a,t);if(!c)continue;const l=a.positioned_relative_to_pcb_group_id??a.pcb_group_id,u=l?B9(t).pcb_group.get(l):null;s.push({component:a,bbox:c,group:u})}return s.length===0?null:G.jsx("div",{style:{position:"absolute",left:0,top:0,width:r,height:i,overflow:"hidden",pointerEvents:"none",zIndex:Wl.dimensionOverlay},children:G.jsx("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none"},width:r,height:i,children:s.map(({component:a,bbox:c,group:l})=>{const u=mt(n,{x:c.minX,y:c.maxY}),d=mt(n,{x:c.maxX,y:c.minY}),h={x:Math.min(u.x,d.x),y:Math.min(u.y,d.y),width:Math.abs(d.x-u.x),height:Math.abs(d.y-u.y)},f=a.center??{x:(c.minX+c.maxX)/2,y:(c.minY+c.maxY)/2},p=mt(n,f);return G.jsxs("g",{children:[G.jsx("rect",{x:h.x,y:h.y,width:h.width,height:h.height,fill:"none",stroke:"white",strokeWidth:1.5,strokeDasharray:"4,4"}),G.jsx("line",{x1:p.x-6,y1:p.y,x2:p.x+6,y2:p.y,stroke:U2.COMPONENT_MARKER_STROKE,strokeWidth:1.5}),G.jsx("line",{x1:p.x,y1:p.y-6,x2:p.x,y2:p.y+6,stroke:U2.COMPONENT_MARKER_STROKE,strokeWidth:1.5}),G.jsx("circle",{cx:p.x,cy:p.y,r:Cu.COMPONENT_MARKER_RADIUS,fill:U2.COMPONENT_MARKER_FILL,stroke:U2.COMPONENT_MARKER_STROKE,strokeWidth:1})]},a.pcb_component_id)})})})},CHn=({elements:t,highlightedPrimitives:e,transform:n,containerWidth:r,containerHeight:i})=>{const o=t.filter(f=>wHn(f)),s=t.filter(f=>j_e(f)),a=e.map(f=>j_e(f._element)?f._element.pcb_board_id:null).filter(f=>!!f);if(!E0(f=>f.is_showing_group_anchor_offsets)&&a.length===0)return null;const l=s.map(f=>{const p=f.pcb_panel_id,m=f.position_mode;if(!p||m!=="relative_to_panel_anchor")return null;const g=o.find(y=>y.pcb_panel_id===p);return g?{board:f,panel:g,type:"board"}:null}).filter(f=>!!f);if(l.length===0)return null;const u=a.length===0,d=l.filter(f=>u||a.includes(f.board.pcb_board_id));if(d.length===0)return null;const h=d.map(f=>f.board.center?{id:`${f.panel.pcb_panel_id}-${f.board.pcb_board_id}-${f.type}`,anchor:f.panel.center,anchor_id:f.panel.pcb_panel_id,target:f.board.center,type:"board",display_offset_x:f.board.display_offset_x,display_offset_y:f.board.display_offset_y}:null).filter(f=>!!f);return G.jsx(U_e,{targets:h,transform:n,containerWidth:r,containerHeight:i})},fG=t=>{if(t.length===0)return null;let e=t[0].x,n=t[0].y,r=t[0].x,i=t[0].y;for(const o of t)o.x<e&&(e=o.x),o.y<n&&(n=o.y),o.x>r&&(r=o.x),o.y>i&&(i=o.y);return{center:{x:(e+r)/2,y:(n+i)/2},width:r-e,height:i-n}},t0t=(t,e)=>{if(e.length<3)return!1;let n=!1;for(let r=0,i=e.length-1;r<e.length;i=r++){const o=e[r].x,s=e[r].y,a=e[i].x,c=e[i].y;s>t.y!=c>t.y&&t.x<(a-o)*(t.y-s)/(c-s||Number.EPSILON)+o&&(n=!n)}return n},PHn=(t,e,n)=>{const r=[];for(const i of t){if(!i._element)continue;if("x1"in i&&i._element?.type==="pcb_trace"){const a=qm({x:e.x,y:e.y},{x:i.x1,y:i.y1},{x:i.x2,y:i.y2}),c=i.width||.5,l=Math.max(c*25,2)/n.a;a<l&&r.push(i);continue}if(i.pcb_drawing_type==="polygon"){const a=i.points.map(l=>({x:gn.parse(l.x),y:gn.parse(l.y)})),c=fG(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;t0t(e,a)&&r.push(i);continue}if(i.pcb_drawing_type==="polygon_with_arcs"){const a=i.brep_shape.outer_ring.vertices.map(l=>({x:gn.parse(l.x),y:gn.parse(l.y)})),c=fG(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;t0t(e,a)&&r.push(i);continue}if(!("x"in i&&"y"in i))continue;let o=0,s=0;if("w"in i&&"h"in i)o=i.w,s=i.h;else if("r"in i)o=i.r*2,s=i.r*2;else if("rX"in i&&"rY"in i)o=i.rX*2,s=i.rY*2;else continue;Math.abs(i.x-e.x)<o/2&&Math.abs(i.y-e.y)<s/2&&r.push(i)}return r},AHn=({elements:t,children:e,transform:n,primitives:r,onMouseHoverOverPrimitives:i})=>{const[o,s]=te.useState([]),[a,c]=te.useState({x:0,y:0}),[l,{width:u,height:d}]=gO(),h=te.useMemo(()=>{const p=[];for(const m of o){if(m._element?.type==="pcb_via"||m._element?.type==="pcb_component"||m?.layer==="drill"||m?.is_hoverable===!1)continue;let g=null,y=0,_=0;if(m.pcb_drawing_type==="polygon"){const S=fG(m.points);if(!S)continue;g=S.center,y=S.width,_=S.height}else if(m.pcb_drawing_type==="polygon_with_arcs"){const S=m.brep_shape.outer_ring.vertices.map(C=>({x:C.x,y:C.y})),T=fG(S);if(!T)continue;g=T.center,y=T.width,_=T.height}else"x"in m&&"y"in m&&(g={x:m.x,y:m.y},y="w"in m?m.w:"r"in m?m.r*2:"rX"in m&&"rY"in m?m.rX*2:0,_="h"in m?m.h:"r"in m?m.r*2:"rX"in m&&"rY"in m?m.rY*2:0);if(!g)continue;const x=mt(n,g),b={w:y*n.a,h:_*n.a},w=p.filter(S=>x.x===S.screen_x&&x.y===S.screen_y&&b.w===S.screen_w&&b.h===S.screen_h).length;p.push({...m,x:g.x,y:g.y,w:y,h:_,screen_x:x.x,screen_y:x.y,screen_w:b.w,screen_h:b.h,same_space_index:w})}return p},[o,n]),f=(p,m,g,y)=>{c({x:p,y:m});const _=mt(Bx(g),{x:p,y:m}),x=PHn(y,_,g);fHn(new Set(x.map(b=>b._pcb_drawing_object_id)),new Set(o.map(b=>b._pcb_drawing_object_id)))||(s(x),i(x))};return G.jsxs("div",{ref:l,style:{position:"relative",width:"100%",height:"100%"},onMouseMove:p=>{if(n){const m=p.currentTarget.getBoundingClientRect(),g=p.clientX-m.left,y=p.clientY-m.top;f(g,y,n,r)}},onTouchStart:p=>{if(n){const m=p.touches[0],g=p.currentTarget.getBoundingClientRect(),y=m.clientX-g.left,_=m.clientY-g.top;f(y,_,n,r)}},children:[e,G.jsx(vHn,{elements:t,mousePos:a,highlightedPrimitives:h}),n&&G.jsxs(G.Fragment,{children:[G.jsx(SHn,{elements:t,highlightedPrimitives:h,transform:n,containerWidth:u,containerHeight:d}),G.jsx(MHn,{elements:t,highlightedPrimitives:h,transform:n,containerWidth:u,containerHeight:d}),G.jsx(EHn,{elements:t,highlightedPrimitives:h,transform:n,containerWidth:u,containerHeight:d}),G.jsx(CHn,{elements:t,highlightedPrimitives:h,transform:n,containerWidth:u,containerHeight:d})]})]})},n0t=["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)"],RHn=({children:t,transform:e=el(),elements:n=[],hoveredComponentIds:r=[]})=>{const[i,{width:o,height:s}]=gO(),a=te.useRef(null),{is_showing_pcb_groups:c,pcb_group_view_mode:l,is_showing_group_anchor_offsets:u}=E0(d=>({is_showing_pcb_groups:d.is_showing_pcb_groups,pcb_group_view_mode:d.pcb_group_view_mode,is_showing_group_anchor_offsets:d.is_showing_group_anchor_offsets}));return te.useEffect(()=>{const d=a.current;if(!d||!o||!s)return;d.width=o,d.height=s;const h=d.getContext("2d");if(!h||(h.clearRect(0,0,o,s),!c))return;const f=n.filter(S=>S.type==="pcb_group"),p=n.filter(S=>S.type==="pcb_component"),m=n.filter(S=>S.type==="source_group"),g=new Map(m.map(S=>[S.source_group_id,S])),y=f.filter(S=>{if(S.name?.toLowerCase().includes("subpanel"))return!1;if(l==="all")return!0;if(!S.source_group_id)return!1;const T=g.get(S.source_group_id);return T?T.was_automatically_named!==!0:!1}),_=new Map;m.forEach(S=>{const T=S;if(T.parent_source_group_id){const C=_.get(T.parent_source_group_id)||[];C.push(S.source_group_id),_.set(T.parent_source_group_id,C)}});const x=S=>{const T=[],C=_.get(S)||[];for(const A of C)T.push(A),T.push(...x(A));return T},b=S=>{const T=m.find(C=>C.source_group_id===S);return T?.parent_source_group_id?1+b(T.parent_source_group_id):0},w=new Set;if(r.length>0)for(const S of p){if(!r.includes(S.pcb_component_id))continue;const T=S.positioned_relative_to_pcb_group_id??S.pcb_group_id;T&&w.add(T)}y.forEach((S,T)=>{let C=p.filter(Ne=>Ne.pcb_group_id===S.pcb_group_id);if(S.source_group_id){const Ne=x(S.source_group_id),Ue=f.filter(Ie=>Ie.source_group_id&&Ne.includes(Ie.source_group_id));for(const Ie of Ue){const we=p.filter(Ee=>Ee.pcb_group_id===Ie.pcb_group_id);C=[...C,...we]}}let A,R,L,O,F=!1;if(S.center&&S.width&&S.height){F=!0;const Ne=S.width/2,Ue=S.height/2;A=S.center.x-Ne,L=S.center.x+Ne,R=S.center.y-Ue,O=S.center.y+Ue}else if(C.length===0||(A=1/0,R=1/0,L=-1/0,O=-1/0,C.forEach(Ne=>{if(Ne.center&&typeof Ne.width=="number"&&typeof Ne.height=="number"){const Ue=Ne.center.x-Ne.width/2,Ie=Ne.center.x+Ne.width/2,we=Ne.center.y+Ne.height/2,Ee=Ne.center.y-Ne.height/2;A=Math.min(A,Ue),L=Math.max(L,Ie),R=Math.min(R,Ee),O=Math.max(O,we)}}),A===1/0||L===-1/0))return;const B=S.source_group_id?b(S.source_group_id):0,j=S.source_group_id?x(S.source_group_id).length>0:!1;if(!F){const Ie=1+(j?.5:0);A-=Ie,L+=Ie,R-=Ie,O+=Ie}const V=mt(e,{x:A,y:O}),q=mt(e,{x:L,y:O}),K=mt(e,{x:A,y:R}),ne=mt(e,{x:L,y:R}),le=n0t[T%n0t.length];h.strokeStyle=le,h.lineWidth=2;const ee=Math.max(4,Math.min(12,8*Math.abs(e.a))),ie=Math.max(2,Math.min(6,4*Math.abs(e.a))),ue=ee*(j?1.3:1),_e=ie;h.setLineDash([ue,_e]),h.beginPath(),h.moveTo(V.x,V.y),h.lineTo(q.x,q.y),h.lineTo(ne.x,ne.y),h.lineTo(K.x,K.y),h.closePath(),h.stroke();const Ce=Math.max(8,Math.min(12,10*Math.abs(e.a))),Ae=B==0||B==1?0:B*.11,ke=Ce*(1-Ae),ye=4,Me=S.name||`Group ${T+1}`;h.font=`${ke}px sans-serif`,h.setLineDash([]);const Ye=h.measureText(Me).width+ye*2,He=ke+ye*2,We=V.x-5,ge=V.y-5,Ke=3;if(h.fillStyle="rgba(0, 0, 0, 0.8)",h.beginPath(),h.roundRect(We,ge-He,Ye,He,Ke),h.fill(),h.fillStyle=le,h.textAlign="left",h.textBaseline="middle",h.fillText(Me,We+ye,ge-He/2),u&&w.has(S.pcb_group_id)&&!!S.anchor_position&&S.anchor_position){const Ne=Array.isArray(S.anchor_position)?{x:S.anchor_position[0]??0,y:S.anchor_position[1]??0}:{x:S.anchor_position.x,y:S.anchor_position.y},Ue=mt(e,Ne);h.strokeStyle="white",h.lineWidth=1.5,h.setLineDash([]);const Ie=Math.max(4,Math.min(8,6*Math.abs(e.a)));h.beginPath(),h.moveTo(Ue.x-Ie,Ue.y),h.lineTo(Ue.x+Ie,Ue.y),h.stroke(),h.beginPath(),h.moveTo(Ue.x,Ue.y-Ie),h.lineTo(Ue.x,Ue.y+Ie),h.stroke()}})},[n,e,o,s,c,l,u,r]),G.jsxs("div",{ref:i,style:{position:"relative",width:"100%",height:"100%"},children:[t,G.jsx("canvas",{ref:a,style:{position:"absolute",top:0,left:0,pointerEvents:"none",zIndex:Wl.pcbGroupOverlay,display:c?"block":"none"}})]})},IHn=({transform:t,soup:e,children:n})=>{const r=E0(a=>a.is_showing_rats_nest),{netMap:i,idToNetMap:o}=te.useMemo(()=>kut(e||[]),[e]),s=te.useMemo(()=>{if(!e||!r)return[];const a=h=>{const f=B9(e)[h.replace(/_\d+$/,"")].get(h);return f&&"x"in f&&"y"in f?{x:f.x,y:f.y}:null},c=(h,f)=>{const p=i[f]||[];let m=null,g=1/0;return p.forEach(y=>{const _=a(y);if(_){const x=Math.sqrt((h.x-_.x)**2+(h.y-_.y)**2);x<g&&x>0&&(g=x,m=_)}}),m},l=B9(e).pcb_port.list(),u=B9(e).source_trace.list(),d=[];return l.forEach((h,f)=>{const p=o[h.pcb_port_id];let m=!1;for(const _ of u)_.connected_source_port_ids.includes(h.source_port_id)&&_.connected_source_net_ids.length>0&&(m=!0);if(!p)return;const g={x:h.x,y:h.y},y=c(g,p);y&&d.push({key:`${h.pcb_port_id}-${f}`,startPoint:g,endPoint:y,isInNet:m})}),d},[e,i,o,r]);return!e||!r?n:(t||(t=el()),G.jsxs("div",{style:{position:"relative"},children:[n,G.jsx("svg",{style:{position:"absolute",left:0,top:0,width:"100%",height:"100%",pointerEvents:"none",opacity:.5,zIndex:Wl.ratsNestOverlay},children:s.map(({key:a,startPoint:c,endPoint:l,isInNet:u})=>{const d=mt(t,c),h=mt(t,l);return G.jsx("line",{x1:d.x,y1:d.y,x2:h.x,y2:h.y,stroke:"white",strokeWidth:"1",strokeDasharray:u?"6,6":void 0},a)})})]}))},NHn={version:"1.11.362"},T8=(t,e,n)=>{const r=E0(s=>s.is_mouse_over_container),i=te.useRef(r),o=te.useRef(e);te.useEffect(()=>{i.current=r},[r]),te.useEffect(()=>{o.current=e},[e]),te.useEffect(()=>{if(!t)return;const s=a=>{const c=a.target;if(c.tagName==="INPUT"||c.tagName==="TEXTAREA"||c.isContentEditable)return;const l=t.split("+"),u=l.includes("ctrl"),d=l.includes("shift"),h=l.includes("alt"),f=l.includes("meta"),p=l[l.length-1],m=n?.current?n.current.contains(document.activeElement)||document.activeElement===n.current:!1;(i.current||m)&&(!u||a.ctrlKey)&&(!d||a.shiftKey)&&(!h||a.altKey)&&(!f||a.metaKey)&&a.key.toLowerCase()===p.toLowerCase()&&(a.preventDefault(),o.current())};return window.addEventListener("keydown",s),()=>{window.removeEventListener("keydown",s)}},[t])},kHn=()=>{const[t,e]=te.useState(!1);return te.useEffect(()=>{const n=()=>{e(window.innerWidth<=768)};return n(),window.addEventListener("resize",n),()=>window.removeEventListener("resize",n)},[]),t},xO=(t,e={stopPropagation:!0})=>{const n=te.useRef(0),r=te.useCallback(s=>{e.stopPropagation&&s.stopPropagation();const a=Date.now();a-n.current<300||(n.current=a,t?.(s))},[t,e.stopPropagation]),i=te.useCallback(s=>{s.preventDefault(),r(s)},[r]);return{onClick:r,onTouchEnd:i,style:{touchAction:"manipulation"}}},RS=({children:t,isSmallScreen:e,onClick:n,...r})=>{const{style:i,...o}=xO(n);return G.jsx("div",{...r,...o,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,...r.style},children:t})},OHn=({errorId:t,errorMessage:e,copiedErrorId:n,onCopy:r})=>{const{style:i,...o}=xO(()=>r(e,t));return G.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},...o,children:n===t?G.jsx("span",{style:{color:"#4caf50",fontSize:12},children:"Copied!"}):G.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"currentColor",children:G.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"})})})},LHn=({elements:t,isOpen:e,isSmallScreen:n,onToggle:r,setHoveredErrorId:i})=>{const[o,s]=te.useState(null),[a,c]=te.useState(new Set),[l,u]=te.useState(new Set),[,d]=kjn(),h=te.useMemo(()=>t?.filter(_=>_.type.includes("error"))??[],[t]),f=h.length,p=te.useCallback((_,x)=>_.pcb_trace_error_id||`error_${x}_${_.error_type}_${_.message?.slice(0,20)}`,[]),m=te.useMemo(()=>{const _=new Map;return h.forEach((x,b)=>{const w=x.error_type||"unknown_error",S=_.get(w)||[];S.push({error:x,index:b,errorId:p(x,b)}),_.set(w,S)}),Array.from(_.entries()).map(([x,b])=>({errorType:x,errors:b}))},[h,p]),g=te.useCallback(_=>{c(x=>{const b=new Set(x);return b.has(_)?b.delete(_):b.add(_),b})},[]),y=te.useCallback(_=>{u(x=>{const b=new Set(x);return b.has(_)?b.delete(_):b.add(_),b})},[]);return G.jsxs("div",{style:{position:"relative"},children:[G.jsx(RS,{isSmallScreen:n,style:f>0?{color:"red"}:void 0,onClick:r,children:G.jsxs("div",{children:[f," errors"]})}),e&&f>0&&G.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:m.map(({errorType:_,errors:x},b)=>{const w=a.has(_);return G.jsxs("div",{style:{borderBottom:b<m.length-1?"1px solid #444":"none"},children:[G.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:S=>{S.currentTarget.style.backgroundColor="#303030"},onMouseLeave:S=>{S.currentTarget.style.backgroundColor="#232323"},onTouchStart:S=>{S.stopPropagation(),S.currentTarget.style.backgroundColor="#303030"},onTouchEnd:S=>{S.stopPropagation(),S.preventDefault(),S.currentTarget.style.backgroundColor="#232323",g(_)},onClick:S=>{S.stopPropagation(),g(_)},children:[G.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,color:"#ff6b6b"},children:[G.jsx("div",{style:{color:"#888",fontSize:"16px",transform:w?"rotate(90deg)":"rotate(0deg)",transition:"transform 0.2s ease",flexShrink:0},children:"›"}),G.jsx("div",{style:{fontWeight:"bold",fontSize:n?"12px":"13px"},children:_})]}),G.jsx("div",{style:{fontSize:n?"12px":"13px",color:"#aaa",whiteSpace:"nowrap",marginLeft:12},children:x.length})]}),!w&&x.map(({error:S,index:T,errorId:C})=>{const A=l.has(C),R=S.message??"No error message";return G.jsxs("div",{style:{borderTop:"1px solid #3a3a3a"},children:[G.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:L=>{L.currentTarget.style.backgroundColor="#333",i(C)},onMouseLeave:L=>{L.currentTarget.style.backgroundColor="#2a2a2a",i(null)},onTouchStart:L=>{L.stopPropagation(),L.currentTarget.style.backgroundColor="#333",i(C)},onTouchEnd:L=>{L.stopPropagation(),L.preventDefault(),L.currentTarget.style.backgroundColor="#2a2a2a",i(null),y(C)},onClick:L=>{L.stopPropagation(),y(C)},children:[G.jsx("div",{style:{flex:1,fontSize:n?"12px":"13px",color:"#ddd",lineHeight:1.4,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",userSelect:"text"},onMouseDown:L=>L.stopPropagation(),onClick:L=>L.stopPropagation(),children:R}),G.jsx("div",{style:{color:"#888",fontSize:"16px",transform:A?"rotate(0deg)":"rotate(90deg)",transition:"transform 0.2s ease",flexShrink:0},children:"›"})]}),A&&G.jsxs("div",{"data-error-id":T,style:{display:"block",padding:"12px 16px 12px 24px",backgroundColor:"#1a1a1a",borderTop:"1px solid #444",position:"relative"},children:[G.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:L=>L.stopPropagation(),onClick:L=>L.stopPropagation(),children:R}),G.jsx(OHn,{errorId:C,errorMessage:R,copiedErrorId:o,onCopy:(L,O)=>{d(L),s(O),setTimeout(()=>s(null),2e3)}})]})]},C)})]},_)})})]})},DHn=({name:t,selected:e,onClick:n})=>{const{style:r,...i}=xO(n);return G.jsxs("div",{className:vP`
5458
5458
  margin-top: 2px;
5459
5459
  padding: 4px;
5460
5460
  padding-left: 8px;
@@ -5671,7 +5671,7 @@ test("${l} should solve problem correctly", () => {
5671
5671
  // Add more specific assertions based on expected output
5672
5672
  // expect(solver.netLabelPlacementSolver!.netLabelPlacements).toMatchInlineSnapshot()
5673
5673
  })
5674
- `,d=new Blob([u],{type:"text/plain"}),h=URL.createObjectURL(d),f=document.createElement("a");f.href=h,f.download=`${l}.test.ts`,f.click(),URL.revokeObjectURL(h)}catch(c){alert(`Error generating test.ts for ${t.constructor.name}: ${c instanceof Error?c.message:String(c)}`)}r(!1)};return G.jsxs("div",{className:`relative ${e}`,ref:i,children:[G.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>r(!n),title:`Download options for ${t.constructor.name}`,children:t.constructor.name}),n&&G.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:[G.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:o,children:"Download JSON"}),G.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),G.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:a,children:"Download test.ts"})]})]})},f0t=t=>t.activeSubSolver?[t,...f0t(t.activeSubSolver)]:[t],mXn=({solver:t})=>{const e=f0t(t);return G.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:e.map((n,r)=>G.jsxs("div",{className:"flex items-center",children:[r>0&&G.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),G.jsx(fXn,{solver:n})]},n.constructor.name))})},yXn=({solver:t,triggerRender:e,animationSpeed:n=25,onSolverStarted:r,onSolverCompleted:i})=>{const[o,s]=te.useReducer(m=>!m,!1),a=te.useRef(void 0),c=()=>{!t.solved&&!t.failed&&(t.step(),e())},l=()=>{!t.solved&&!t.failed&&(r&&r(t),t.solve(),e(),i&&i(t))},u=()=>{o?(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))},d=()=>{const m=t;if(m.getCurrentPhase&&!t.solved&&!t.failed){const g=m.getCurrentPhase();for(;m.getCurrentPhase()===g&&!t.solved&&!t.failed;)t.step();e()}},h=()=>{if(t.solved||t.failed||o)return;const m=window.prompt("Step until which iteration?",`${t.iterations}`);if(m===null)return;const g=Number(m);if(!Number.isFinite(g)){window.alert("Please enter a valid number for the iteration");return}for(;t.iterations<g&&!t.solved&&!t.failed;)t.step();e(),t.solved&&i&&i(t)};te.useEffect(()=>()=>{a.current&&clearInterval(a.current)},[]),te.useEffect(()=>{(t.solved||t.failed)&&o&&(a.current&&(clearInterval(a.current),a.current=void 0),s())},[t.solved,t.failed,o]);const f=t.getCurrentPhase!==void 0,p=f?t.getCurrentPhase():null;return G.jsxs("div",{className:"space-y-2 p-2 border-b",children:[G.jsx("div",{className:"flex items-center",children:G.jsx(mXn,{solver:t})}),G.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[G.jsx("button",{onClick:c,disabled:t.solved||t.failed||o,className:"bg-blue-500 hover:bg-blue-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step"}),G.jsx("button",{onClick:l,disabled:t.solved||t.failed||o,className:"bg-green-500 hover:bg-green-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Solve"}),G.jsx("button",{onClick:u,disabled:t.solved||t.failed,className:`px-3 py-1 rounded text-white text-sm ${o?"bg-red-500 hover:bg-red-600":"bg-yellow-500 hover:bg-yellow-600"} disabled:bg-gray-300`,children:o?"Stop":"Animate"}),G.jsx("button",{onClick:h,disabled:t.solved||t.failed||o,className:"bg-orange-500 hover:bg-orange-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step Until Iteration"}),f&&G.jsx("button",{onClick:d,disabled:t.solved||t.failed||o,className:"bg-purple-500 hover:bg-purple-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Next Stage"}),G.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",t.iterations]}),t.timeToSolve!==void 0&&G.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(t.timeToSolve/1e3).toFixed(3),"s"]}),p&&G.jsxs("div",{className:"text-sm text-gray-600",children:["Phase: ",G.jsx("span",{className:"font-medium",children:p})]}),t.solved&&G.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),t.failed&&G.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),t.error&&G.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",t.error]})]})},gXn=(t,e,n)=>{const r=t.currentPipelineStepIndex;return e<r?"Completed":e===r&&t.activeSubSolver?t.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},_Xn=(t,e)=>{const r=t.pipelineDef[e].solverName,i=gXn(t,e),o=t[r],s=t.firstIterationOfPhase?.[r]??null,a=t.iterations;let c=0;if(i==="Completed"){const h=t.pipelineDef[e+1],f=h?t.firstIterationOfPhase?.[h.solverName]:void 0;f!==void 0&&s!==null?c=f-s:s!==null&&(c=a-s)}else i==="In Progress"&&s!==null&&(c=a-s);const l=t.timeSpentOnPhase?.[r]??0;let u=0;i==="Completed"?u=1:i==="In Progress"&&o&&(u=o.progress??0);const d=o?.stats??null;return{index:e,name:r,status:i,firstIteration:s,iterations:c,progress:u,timeSpent:l,stats:d&&Object.keys(d).length>0?d:null,solverInstance:o??null}},xXn=({status:t})=>{const e={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return G.jsx("span",{className:`font-medium ${e[t]}`,children:t})},bXn=({progress:t})=>{if(t===0)return null;const e=Math.round(t*100);return G.jsxs("div",{className:"flex items-center gap-2",children:[G.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:G.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${e}%`}})}),G.jsxs("span",{className:"text-xs text-gray-500",children:[e,"%"]})]})},vXn=t=>Object.entries(t).map(([e,n])=>`${e}: ${n}`).join(", "),wXn=({stats:t})=>{if(!t||Object.keys(t).length===0)return G.jsx("span",{children:"-"});const e=Object.entries(t),n=vXn(t);return G.jsxs("details",{className:"cursor-pointer",children:[G.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:n}),G.jsx("div",{className:"mt-1 text-xs",children:e.map(([r,i])=>G.jsxs("div",{children:[r,": ",String(i)]},r))})]})},Z_e=t=>{if(t===null||typeof t!="object")return t;if(Array.isArray(t))return t.map(Z_e);const e={};for(const[n,r]of Object.entries(t))n.startsWith("_")||(e[n]=Z_e(r));return e},SXn=(t,e)=>{try{if(typeof t.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${e}`);return}const n=Z_e(t.getConstructorParams()),r=new Blob([JSON.stringify(n,null,2)],{type:"application/json"}),i=URL.createObjectURL(r),o=document.createElement("a");o.href=i,o.download=`${e}_input.json`,o.click(),URL.revokeObjectURL(i)}catch(n){alert(`Error downloading input for ${e}: ${n instanceof Error?n.message:String(n)}`)}},MXn=({solver:t,onStepUntilPhase:e,onDownloadInput:n})=>{const r=t.pipelineDef.map((a,c)=>_Xn(t,c)),i=a=>{e?.(a)},o=a=>{a.solverInstance&&(n?n(a.solverInstance,a.name):SXn(a.solverInstance,a.name))},s=a=>`${(a/1e3).toFixed(2)}s`;return G.jsxs("div",{className:"border-t border-gray-200",children:[G.jsx("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200",children:G.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Steps"})}),G.jsx("div",{className:"overflow-x-auto",children:G.jsxs("table",{className:"w-full text-sm",children:[G.jsx("thead",{children:G.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[G.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Step"}),G.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),G.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",G.jsx("sub",{children:"0"})]}),G.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),G.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),G.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),G.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),G.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),G.jsx("tbody",{children:r.map(a=>G.jsxs("tr",{className:`border-b border-gray-100 ${a.status==="In Progress"?"bg-yellow-50":""}`,children:[G.jsx("td",{className:"px-4 py-2",children:G.jsxs("div",{className:"flex items-center gap-2",children:[G.jsx("span",{className:"text-gray-400 w-6",children:String(a.index+1).padStart(2,"0")}),G.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:G.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:G.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"})})}),G.jsx("span",{className:"font-medium text-gray-900",children:a.name})]})}),G.jsx("td",{className:"px-4 py-2",children:G.jsx(xXn,{status:a.status})}),G.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:a.firstIteration!==null?a.firstIteration:""}),G.jsx("td",{className:"px-4 py-2 text-gray-600",children:a.iterations}),G.jsx("td",{className:"px-4 py-2",children:G.jsx(bXn,{progress:a.progress})}),G.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(a.timeSpent)}),G.jsx("td",{className:"px-4 py-2 text-gray-500",children:G.jsx(wXn,{stats:a.stats})}),G.jsx("td",{className:"px-4 py-2",children:a.solverInstance?G.jsxs("button",{onClick:()=>o(a),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${a.name}`,children:[G.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:G.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"})}),G.jsx("span",{children:"Input"})]}):null})]},a.name))})]})})]})},TXn=class extends si.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 EXn({graphics:t}){const e=t.points??[],n=t.lines??[],r=t.rects??[],i=t.circles??[],o=t.texts??[];let s=Number.POSITIVE_INFINITY,a=Number.POSITIVE_INFINITY,c=Number.NEGATIVE_INFINITY,l=Number.NEGATIVE_INFINITY;const u=(g,y)=>{typeof g=="number"&&(g<s&&(s=g),g>c&&(c=g)),typeof y=="number"&&(y<a&&(a=y),y>l&&(l=y))};for(const g of e)u(g.x,g.y);for(const g of n){const y=g.points??[];for(const _ of y)u(_.x,_.y)}for(const g of r){const y=g.x??0,_=g.y??0,x=g.width??0,b=g.height??0;u(y,_),u(y+x,_+b)}for(const g of i){const y=g.x??0,_=g.y??0,x=g.radius??1;u(y-x,_-x),u(y+x,_+x)}for(const g of o)u(g.x,g.y);(!isFinite(s)||!isFinite(a)||!isFinite(c)||!isFinite(l))&&(s=-20,a=-20,c=20,l=20);const d=10,h=s-d,f=a-d,p=Math.max(1,c-s+2*d),m=Math.max(1,l-a+2*d);return G.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${h} ${f} ${p} ${m}`,role:"img","aria-label":"Graphics fallback",children:[r.map((g,y)=>G.jsx("rect",{x:g.x??0,y:g.y??0,width:g.width??0,height:g.height??0,fill:"none",stroke:g.strokeColor??"black",strokeWidth:g.strokeWidth??1},`rect-${y}`)),n.map((g,y)=>G.jsx("polyline",{fill:"none",stroke:g.strokeColor??"black",strokeWidth:g.strokeWidth??1,points:(g.points??[]).map(_=>`${_.x??0},${_.y??0}`).join(" ")},`line-${y}`)),i.map((g,y)=>G.jsx("circle",{cx:g.x??0,cy:g.y??0,r:g.radius??1.5,fill:g.fillColor??"none",stroke:g.strokeColor??"black",strokeWidth:g.strokeWidth??1},`circle-${y}`)),e.map((g,y)=>G.jsx("circle",{cx:g.x??0,cy:g.y??0,r:g.radius??1.5,fill:g.color??"black"},`point-${y}`)),o.map((g,y)=>G.jsx("text",{x:g.x??0,y:g.y??0,fontSize:g.fontSize??10,fill:g.color??"black",children:g.text??""},`text-${y}`))]})}var CXn=({solver:t,animationSpeed:e=25,onSolverStarted:n,onSolverCompleted:r})=>{const[i,o]=te.useReducer(u=>u+1,0),s=te.useMemo(()=>{try{return t.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(u){return console.error("Visualization error:",u),{points:[],lines:[],rects:[],circles:[]}}},[t,i]),a=te.useMemo(()=>(s.rects?.length||0)===0&&(s.lines?.length||0)===0&&(s.points?.length||0)===0&&(s.circles?.length||0)===0,[s]);te.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const u=document.createElement("script");u.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(u)}},[]);const c=t.pipelineDef!==void 0,l=u=>{const d=t;if(!t.solved&&!t.failed){for(;!t.solved&&!t.failed&&d.currentPipelineStepIndex<=d.pipelineDef.findIndex(h=>h.solverName===u);)t.step();o()}};return G.jsxs("div",{children:[G.jsx(yXn,{solver:t,triggerRender:o,animationSpeed:e,onSolverStarted:n,onSolverCompleted:r}),a?G.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):G.jsx(TXn,{fallback:G.jsx(EXn,{graphics:s}),children:G.jsx(pXn,{graphics:s})}),c&&G.jsx(MXn,{solver:t,onStepUntilPhase:l})]})};const PXn=()=>{te.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 r=document.createElement("script");r.id=t,r.src="https://cdn.tailwindcss.com",document.head.appendChild(r)},[])},AXn=t=>t.toLowerCase().includes("pack")?XMn:t.toLowerCase().includes("rout")?KMn:DMn,RXn=({solverEvents:t=[]})=>{const[e,n]=te.useState(null);PXn();const r=te.useMemo(()=>{const a=new Map;for(const c of t){const l=`${c.componentName}-${c.solverName}`;a.set(l,c)}return a},[t]),i=te.useMemo(()=>Array.from(r.keys()),[r]),o=e?r.get(e):null,s=te.useMemo(()=>{if(!o)return{instance:null,error:null,classFound:!1};const a=yae[o.solverName];if(!a)return{instance:null,error:`Solver class "${o.solverName}" not found in SOLVERS registry. Available: ${Object.keys(yae).join(", ")}`,classFound:!1};try{const c=o.solverParams,l=c?.input!==void 0?c.input:c;return{instance:new a(l),error:null,classFound:!0}}catch(c){const l=c instanceof Error?c.message:String(c);return console.error("Failed to reconstruct solver:",c),{instance:null,error:`Failed to instantiate solver: ${l}`,classFound:!0}}},[o]);return t.length===0?G.jsx("div",{className:"rf-p-4",children:G.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:G.jsxs("div",{className:"rf-p-4",children:[G.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),G.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."})]})})}):G.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[G.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[G.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 c=r.get(a),l=e===a;return G.jsx("div",{className:`rf-px-3 rf-py-2 rf-cursor-pointer rf-border-b rf-border-gray-100 ${l?"rf-bg-blue-50 rf-border-l-2 rf-border-l-blue-500":"hover:rf-bg-gray-50"}`,onClick:()=>n(a),children:(()=>{const u=AXn(c.solverName);return G.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[G.jsx(u,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),G.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[G.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:c.componentName}),G.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:c.solverName})]})]})})()},a)})]}),G.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:o?s.instance?G.jsx(Fb,{fallback:G.jsx("div",{className:"rf-p-4",children:G.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[G.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),G.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",o.solverName]})]})}),children:G.jsx(CXn,{solver:s.instance})}):G.jsxs("div",{className:"rf-p-4",children:[G.jsxs("div",{className:"rf-mb-4",children:[G.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:o.solverName}),G.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",o.componentName]})]}),s.error&&G.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:G.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),G.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[G.jsx("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50",children:G.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"})}),G.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:G.jsx("pre",{className:"rf-text-xs rf-font-mono rf-text-gray-600 rf-whitespace-pre-wrap rf-overflow-x-auto",children:JSON.stringify(o.solverParams,null,2)})})]})]}):G.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:G.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},m0t=({errorMessage:t,errorStack:e,circuitJsonErrors:n})=>{te.useEffect(()=>{if(t){const r=new Error(t);e&&(r.stack=e);try{iD.captureException(r)}catch{}}},[t,e]),te.useEffect(()=>{if(n&&n.length>0)for(const r of n){const i=new Error(r.message||"Circuit JSON Error");r.stack&&(i.stack=r.stack);try{iD.captureException(i,{error_type:r.type})}catch{}}},[n])},y0t="0.0.1803",IXn={version:y0t},K_e={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1},Q_e=new Map,_G=t=>{const e=Q_e.get(t);return e?Object.fromEntries(Object.entries(e.stores).map(([n,r])=>[n,r.getState()])):{}},NXn=(t,e,n)=>{if(t===void 0)return{type:"untracked",connection:e.connect(n)};const r=Q_e.get(n.name);if(r)return{type:"tracked",store:t,...r};const i={connection:e.connect(n),stores:{}};return Q_e.set(n.name,i),{type:"tracked",store:t,...i}},g0t=(t,e={})=>(n,r,i)=>{const{enabled:o,anonymousActionType:s,store:a,...c}=e;let l;try{l=(o??(K_e?"production":void 0)!=="production")&&window.__REDUX_DEVTOOLS_EXTENSION__}catch{}if(!l)return(K_e?"production":void 0)!=="production"&&o&&console.warn("[zustand devtools middleware] Please install/enable Redux devtools extension"),t(n,r,i);const{connection:u,...d}=NXn(a,l,c);let h=!0;i.setState=(m,g,y)=>{const _=n(m,g);if(!h)return _;const x=y===void 0?{type:s||"anonymous"}:typeof y=="string"?{type:y}:y;return a===void 0?(u?.send(x,r()),_):(u?.send({...x,type:`${a}/${x.type}`},{..._G(c.name),[a]:i.getState()}),_)};const f=(...m)=>{const g=h;h=!1,n(...m),h=g},p=t(i.setState,r,i);if(d.type==="untracked"?u?.init(p):(d.stores[d.store]=i,u?.init(Object.fromEntries(Object.entries(d.stores).map(([m,g])=>[m,m===d.store?p:g.getState()])))),i.dispatchFromDevtools&&typeof i.dispatch=="function"){let m=!1;const g=i.dispatch;i.dispatch=(...y)=>{(K_e?"production":void 0)!=="production"&&y[0].type==="__setState"&&!m&&(console.warn('[zustand devtools middleware] "__setState" action type is reserved to set state from the devtools. Avoid using it.'),m=!0),g(...y)}}return u.subscribe(m=>{var g;switch(m.type){case"ACTION":if(typeof m.payload!="string"){console.error("[zustand devtools middleware] Unsupported action format");return}return J_e(m.payload,y=>{if(y.type==="__setState"){if(a===void 0){f(y.state);return}Object.keys(y.state).length!==1&&console.error(`
5674
+ `,d=new Blob([u],{type:"text/plain"}),h=URL.createObjectURL(d),f=document.createElement("a");f.href=h,f.download=`${l}.test.ts`,f.click(),URL.revokeObjectURL(h)}catch(c){alert(`Error generating test.ts for ${t.constructor.name}: ${c instanceof Error?c.message:String(c)}`)}r(!1)};return G.jsxs("div",{className:`relative ${e}`,ref:i,children:[G.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>r(!n),title:`Download options for ${t.constructor.name}`,children:t.constructor.name}),n&&G.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:[G.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:o,children:"Download JSON"}),G.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),G.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:a,children:"Download test.ts"})]})]})},f0t=t=>t.activeSubSolver?[t,...f0t(t.activeSubSolver)]:[t],mXn=({solver:t})=>{const e=f0t(t);return G.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:e.map((n,r)=>G.jsxs("div",{className:"flex items-center",children:[r>0&&G.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),G.jsx(fXn,{solver:n})]},n.constructor.name))})},yXn=({solver:t,triggerRender:e,animationSpeed:n=25,onSolverStarted:r,onSolverCompleted:i})=>{const[o,s]=te.useReducer(m=>!m,!1),a=te.useRef(void 0),c=()=>{!t.solved&&!t.failed&&(t.step(),e())},l=()=>{!t.solved&&!t.failed&&(r&&r(t),t.solve(),e(),i&&i(t))},u=()=>{o?(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))},d=()=>{const m=t;if(m.getCurrentPhase&&!t.solved&&!t.failed){const g=m.getCurrentPhase();for(;m.getCurrentPhase()===g&&!t.solved&&!t.failed;)t.step();e()}},h=()=>{if(t.solved||t.failed||o)return;const m=window.prompt("Step until which iteration?",`${t.iterations}`);if(m===null)return;const g=Number(m);if(!Number.isFinite(g)){window.alert("Please enter a valid number for the iteration");return}for(;t.iterations<g&&!t.solved&&!t.failed;)t.step();e(),t.solved&&i&&i(t)};te.useEffect(()=>()=>{a.current&&clearInterval(a.current)},[]),te.useEffect(()=>{(t.solved||t.failed)&&o&&(a.current&&(clearInterval(a.current),a.current=void 0),s())},[t.solved,t.failed,o]);const f=t.getCurrentPhase!==void 0,p=f?t.getCurrentPhase():null;return G.jsxs("div",{className:"space-y-2 p-2 border-b",children:[G.jsx("div",{className:"flex items-center",children:G.jsx(mXn,{solver:t})}),G.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[G.jsx("button",{onClick:c,disabled:t.solved||t.failed||o,className:"bg-blue-500 hover:bg-blue-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step"}),G.jsx("button",{onClick:l,disabled:t.solved||t.failed||o,className:"bg-green-500 hover:bg-green-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Solve"}),G.jsx("button",{onClick:u,disabled:t.solved||t.failed,className:`px-3 py-1 rounded text-white text-sm ${o?"bg-red-500 hover:bg-red-600":"bg-yellow-500 hover:bg-yellow-600"} disabled:bg-gray-300`,children:o?"Stop":"Animate"}),G.jsx("button",{onClick:h,disabled:t.solved||t.failed||o,className:"bg-orange-500 hover:bg-orange-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step Until Iteration"}),f&&G.jsx("button",{onClick:d,disabled:t.solved||t.failed||o,className:"bg-purple-500 hover:bg-purple-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Next Stage"}),G.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",t.iterations]}),t.timeToSolve!==void 0&&G.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(t.timeToSolve/1e3).toFixed(3),"s"]}),p&&G.jsxs("div",{className:"text-sm text-gray-600",children:["Phase: ",G.jsx("span",{className:"font-medium",children:p})]}),t.solved&&G.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),t.failed&&G.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),t.error&&G.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",t.error]})]})},gXn=(t,e,n)=>{const r=t.currentPipelineStepIndex;return e<r?"Completed":e===r&&t.activeSubSolver?t.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},_Xn=(t,e)=>{const r=t.pipelineDef[e].solverName,i=gXn(t,e),o=t[r],s=t.firstIterationOfPhase?.[r]??null,a=t.iterations;let c=0;if(i==="Completed"){const h=t.pipelineDef[e+1],f=h?t.firstIterationOfPhase?.[h.solverName]:void 0;f!==void 0&&s!==null?c=f-s:s!==null&&(c=a-s)}else i==="In Progress"&&s!==null&&(c=a-s);const l=t.timeSpentOnPhase?.[r]??0;let u=0;i==="Completed"?u=1:i==="In Progress"&&o&&(u=o.progress??0);const d=o?.stats??null;return{index:e,name:r,status:i,firstIteration:s,iterations:c,progress:u,timeSpent:l,stats:d&&Object.keys(d).length>0?d:null,solverInstance:o??null}},xXn=({status:t})=>{const e={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return G.jsx("span",{className:`font-medium ${e[t]}`,children:t})},bXn=({progress:t})=>{if(t===0)return null;const e=Math.round(t*100);return G.jsxs("div",{className:"flex items-center gap-2",children:[G.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:G.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${e}%`}})}),G.jsxs("span",{className:"text-xs text-gray-500",children:[e,"%"]})]})},vXn=t=>Object.entries(t).map(([e,n])=>`${e}: ${n}`).join(", "),wXn=({stats:t})=>{if(!t||Object.keys(t).length===0)return G.jsx("span",{children:"-"});const e=Object.entries(t),n=vXn(t);return G.jsxs("details",{className:"cursor-pointer",children:[G.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:n}),G.jsx("div",{className:"mt-1 text-xs",children:e.map(([r,i])=>G.jsxs("div",{children:[r,": ",String(i)]},r))})]})},Z_e=t=>{if(t===null||typeof t!="object")return t;if(Array.isArray(t))return t.map(Z_e);const e={};for(const[n,r]of Object.entries(t))n.startsWith("_")||(e[n]=Z_e(r));return e},SXn=(t,e)=>{try{if(typeof t.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${e}`);return}const n=Z_e(t.getConstructorParams()),r=new Blob([JSON.stringify(n,null,2)],{type:"application/json"}),i=URL.createObjectURL(r),o=document.createElement("a");o.href=i,o.download=`${e}_input.json`,o.click(),URL.revokeObjectURL(i)}catch(n){alert(`Error downloading input for ${e}: ${n instanceof Error?n.message:String(n)}`)}},MXn=({solver:t,onStepUntilPhase:e,onDownloadInput:n})=>{const r=t.pipelineDef.map((a,c)=>_Xn(t,c)),i=a=>{e?.(a)},o=a=>{a.solverInstance&&(n?n(a.solverInstance,a.name):SXn(a.solverInstance,a.name))},s=a=>`${(a/1e3).toFixed(2)}s`;return G.jsxs("div",{className:"border-t border-gray-200",children:[G.jsx("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200",children:G.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Steps"})}),G.jsx("div",{className:"overflow-x-auto",children:G.jsxs("table",{className:"w-full text-sm",children:[G.jsx("thead",{children:G.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[G.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Step"}),G.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),G.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",G.jsx("sub",{children:"0"})]}),G.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),G.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),G.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),G.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),G.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),G.jsx("tbody",{children:r.map(a=>G.jsxs("tr",{className:`border-b border-gray-100 ${a.status==="In Progress"?"bg-yellow-50":""}`,children:[G.jsx("td",{className:"px-4 py-2",children:G.jsxs("div",{className:"flex items-center gap-2",children:[G.jsx("span",{className:"text-gray-400 w-6",children:String(a.index+1).padStart(2,"0")}),G.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:G.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:G.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"})})}),G.jsx("span",{className:"font-medium text-gray-900",children:a.name})]})}),G.jsx("td",{className:"px-4 py-2",children:G.jsx(xXn,{status:a.status})}),G.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:a.firstIteration!==null?a.firstIteration:""}),G.jsx("td",{className:"px-4 py-2 text-gray-600",children:a.iterations}),G.jsx("td",{className:"px-4 py-2",children:G.jsx(bXn,{progress:a.progress})}),G.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(a.timeSpent)}),G.jsx("td",{className:"px-4 py-2 text-gray-500",children:G.jsx(wXn,{stats:a.stats})}),G.jsx("td",{className:"px-4 py-2",children:a.solverInstance?G.jsxs("button",{onClick:()=>o(a),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${a.name}`,children:[G.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:G.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"})}),G.jsx("span",{children:"Input"})]}):null})]},a.name))})]})})]})},TXn=class extends si.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 EXn({graphics:t}){const e=t.points??[],n=t.lines??[],r=t.rects??[],i=t.circles??[],o=t.texts??[];let s=Number.POSITIVE_INFINITY,a=Number.POSITIVE_INFINITY,c=Number.NEGATIVE_INFINITY,l=Number.NEGATIVE_INFINITY;const u=(g,y)=>{typeof g=="number"&&(g<s&&(s=g),g>c&&(c=g)),typeof y=="number"&&(y<a&&(a=y),y>l&&(l=y))};for(const g of e)u(g.x,g.y);for(const g of n){const y=g.points??[];for(const _ of y)u(_.x,_.y)}for(const g of r){const y=g.x??0,_=g.y??0,x=g.width??0,b=g.height??0;u(y,_),u(y+x,_+b)}for(const g of i){const y=g.x??0,_=g.y??0,x=g.radius??1;u(y-x,_-x),u(y+x,_+x)}for(const g of o)u(g.x,g.y);(!isFinite(s)||!isFinite(a)||!isFinite(c)||!isFinite(l))&&(s=-20,a=-20,c=20,l=20);const d=10,h=s-d,f=a-d,p=Math.max(1,c-s+2*d),m=Math.max(1,l-a+2*d);return G.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${h} ${f} ${p} ${m}`,role:"img","aria-label":"Graphics fallback",children:[r.map((g,y)=>G.jsx("rect",{x:g.x??0,y:g.y??0,width:g.width??0,height:g.height??0,fill:"none",stroke:g.strokeColor??"black",strokeWidth:g.strokeWidth??1},`rect-${y}`)),n.map((g,y)=>G.jsx("polyline",{fill:"none",stroke:g.strokeColor??"black",strokeWidth:g.strokeWidth??1,points:(g.points??[]).map(_=>`${_.x??0},${_.y??0}`).join(" ")},`line-${y}`)),i.map((g,y)=>G.jsx("circle",{cx:g.x??0,cy:g.y??0,r:g.radius??1.5,fill:g.fillColor??"none",stroke:g.strokeColor??"black",strokeWidth:g.strokeWidth??1},`circle-${y}`)),e.map((g,y)=>G.jsx("circle",{cx:g.x??0,cy:g.y??0,r:g.radius??1.5,fill:g.color??"black"},`point-${y}`)),o.map((g,y)=>G.jsx("text",{x:g.x??0,y:g.y??0,fontSize:g.fontSize??10,fill:g.color??"black",children:g.text??""},`text-${y}`))]})}var CXn=({solver:t,animationSpeed:e=25,onSolverStarted:n,onSolverCompleted:r})=>{const[i,o]=te.useReducer(u=>u+1,0),s=te.useMemo(()=>{try{return t.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(u){return console.error("Visualization error:",u),{points:[],lines:[],rects:[],circles:[]}}},[t,i]),a=te.useMemo(()=>(s.rects?.length||0)===0&&(s.lines?.length||0)===0&&(s.points?.length||0)===0&&(s.circles?.length||0)===0,[s]);te.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const u=document.createElement("script");u.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(u)}},[]);const c=t.pipelineDef!==void 0,l=u=>{const d=t;if(!t.solved&&!t.failed){for(;!t.solved&&!t.failed&&d.currentPipelineStepIndex<=d.pipelineDef.findIndex(h=>h.solverName===u);)t.step();o()}};return G.jsxs("div",{children:[G.jsx(yXn,{solver:t,triggerRender:o,animationSpeed:e,onSolverStarted:n,onSolverCompleted:r}),a?G.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):G.jsx(TXn,{fallback:G.jsx(EXn,{graphics:s}),children:G.jsx(pXn,{graphics:s})}),c&&G.jsx(MXn,{solver:t,onStepUntilPhase:l})]})};const PXn=()=>{te.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 r=document.createElement("script");r.id=t,r.src="https://cdn.tailwindcss.com",document.head.appendChild(r)},[])},AXn=t=>t.toLowerCase().includes("pack")?XMn:t.toLowerCase().includes("rout")?KMn:DMn,RXn=({solverEvents:t=[]})=>{const[e,n]=te.useState(null);PXn();const r=te.useMemo(()=>{const a=new Map;for(const c of t){const l=`${c.componentName}-${c.solverName}`;a.set(l,c)}return a},[t]),i=te.useMemo(()=>Array.from(r.keys()),[r]),o=e?r.get(e):null,s=te.useMemo(()=>{if(!o)return{instance:null,error:null,classFound:!1};const a=yae[o.solverName];if(!a)return{instance:null,error:`Solver class "${o.solverName}" not found in SOLVERS registry. Available: ${Object.keys(yae).join(", ")}`,classFound:!1};try{const c=o.solverParams,l=c?.input!==void 0?c.input:c;return{instance:new a(l),error:null,classFound:!0}}catch(c){const l=c instanceof Error?c.message:String(c);return console.error("Failed to reconstruct solver:",c),{instance:null,error:`Failed to instantiate solver: ${l}`,classFound:!0}}},[o]);return t.length===0?G.jsx("div",{className:"rf-p-4",children:G.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:G.jsxs("div",{className:"rf-p-4",children:[G.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),G.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."})]})})}):G.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[G.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[G.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 c=r.get(a),l=e===a;return G.jsx("div",{className:`rf-px-3 rf-py-2 rf-cursor-pointer rf-border-b rf-border-gray-100 ${l?"rf-bg-blue-50 rf-border-l-2 rf-border-l-blue-500":"hover:rf-bg-gray-50"}`,onClick:()=>n(a),children:(()=>{const u=AXn(c.solverName);return G.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[G.jsx(u,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),G.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[G.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:c.componentName}),G.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:c.solverName})]})]})})()},a)})]}),G.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:o?s.instance?G.jsx(Fb,{fallback:G.jsx("div",{className:"rf-p-4",children:G.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[G.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),G.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",o.solverName]})]})}),children:G.jsx(CXn,{solver:s.instance})}):G.jsxs("div",{className:"rf-p-4",children:[G.jsxs("div",{className:"rf-mb-4",children:[G.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:o.solverName}),G.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",o.componentName]})]}),s.error&&G.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:G.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),G.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[G.jsx("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50",children:G.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"})}),G.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:G.jsx("pre",{className:"rf-text-xs rf-font-mono rf-text-gray-600 rf-whitespace-pre-wrap rf-overflow-x-auto",children:JSON.stringify(o.solverParams,null,2)})})]})]}):G.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:G.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},m0t=({errorMessage:t,errorStack:e,circuitJsonErrors:n})=>{te.useEffect(()=>{if(t){const r=new Error(t);e&&(r.stack=e);try{iD.captureException(r)}catch{}}},[t,e]),te.useEffect(()=>{if(n&&n.length>0)for(const r of n){const i=new Error(r.message||"Circuit JSON Error");r.stack&&(i.stack=r.stack);try{iD.captureException(i,{error_type:r.type})}catch{}}},[n])},y0t="0.0.1805",IXn={version:y0t},K_e={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1},Q_e=new Map,_G=t=>{const e=Q_e.get(t);return e?Object.fromEntries(Object.entries(e.stores).map(([n,r])=>[n,r.getState()])):{}},NXn=(t,e,n)=>{if(t===void 0)return{type:"untracked",connection:e.connect(n)};const r=Q_e.get(n.name);if(r)return{type:"tracked",store:t,...r};const i={connection:e.connect(n),stores:{}};return Q_e.set(n.name,i),{type:"tracked",store:t,...i}},g0t=(t,e={})=>(n,r,i)=>{const{enabled:o,anonymousActionType:s,store:a,...c}=e;let l;try{l=(o??(K_e?"production":void 0)!=="production")&&window.__REDUX_DEVTOOLS_EXTENSION__}catch{}if(!l)return(K_e?"production":void 0)!=="production"&&o&&console.warn("[zustand devtools middleware] Please install/enable Redux devtools extension"),t(n,r,i);const{connection:u,...d}=NXn(a,l,c);let h=!0;i.setState=(m,g,y)=>{const _=n(m,g);if(!h)return _;const x=y===void 0?{type:s||"anonymous"}:typeof y=="string"?{type:y}:y;return a===void 0?(u?.send(x,r()),_):(u?.send({...x,type:`${a}/${x.type}`},{..._G(c.name),[a]:i.getState()}),_)};const f=(...m)=>{const g=h;h=!1,n(...m),h=g},p=t(i.setState,r,i);if(d.type==="untracked"?u?.init(p):(d.stores[d.store]=i,u?.init(Object.fromEntries(Object.entries(d.stores).map(([m,g])=>[m,m===d.store?p:g.getState()])))),i.dispatchFromDevtools&&typeof i.dispatch=="function"){let m=!1;const g=i.dispatch;i.dispatch=(...y)=>{(K_e?"production":void 0)!=="production"&&y[0].type==="__setState"&&!m&&(console.warn('[zustand devtools middleware] "__setState" action type is reserved to set state from the devtools. Avoid using it.'),m=!0),g(...y)}}return u.subscribe(m=>{var g;switch(m.type){case"ACTION":if(typeof m.payload!="string"){console.error("[zustand devtools middleware] Unsupported action format");return}return J_e(m.payload,y=>{if(y.type==="__setState"){if(a===void 0){f(y.state);return}Object.keys(y.state).length!==1&&console.error(`
5675
5675
  [zustand devtools middleware] Unsupported __setState action format.
5676
5676
  When using 'store' option in devtools(), the 'state' should have only one key, which is a value of 'store' that was passed in devtools(),
5677
5677
  and value of this only key should be a state object. Example: { "type": "__setState", "state": { "abc123Store": { "foo": "bar" } } }